@workos-inc/node
Advanced tools
Comparing version 0.10.3 to 1.0.0
{ | ||
"version": "0.10.3", | ||
"version": "1.0.0", | ||
"name": "@workos-inc/node", | ||
@@ -12,3 +12,3 @@ "author": "WorkOS", | ||
"volta": { | ||
"node": "14.16.1", | ||
"node": "14.17.0", | ||
"yarn": "1.22.10" | ||
@@ -47,3 +47,3 @@ }, | ||
"jest": "26.6.3", | ||
"prettier": "2.2.1", | ||
"prettier": "2.3.0", | ||
"supertest": "6.1.3", | ||
@@ -50,0 +50,0 @@ "ts-jest": "26.5.6", |
export { UnprocessableEntityError } from './unprocessable-entity-error.interface'; | ||
export { WorkOSOptions } from './workos-options.interface'; | ||
export { PostOptions } from './post-options.interface'; | ||
export { PutOptions } from './put-options.interface'; |
export { GeneratePortalLinkIntent } from './generate-portal-link-intent.interface'; | ||
export { ListOrganizationsOptions } from './list-organizations-options.interface'; | ||
export { OrganizationDomain } from './organization-domain.interface'; | ||
export { Organization } from './organization.interface'; |
@@ -1,13 +0,6 @@ | ||
import { List } from '../common/interfaces/list.interface'; | ||
import { WorkOS } from '../workos'; | ||
import { GeneratePortalLinkIntent } from './interfaces/generate-portal-link-intent.interface'; | ||
import { ListOrganizationsOptions } from './interfaces/list-organizations-options.interface'; | ||
import { Organization } from './interfaces/organization.interface'; | ||
export declare class Portal { | ||
private readonly workos; | ||
constructor(workos: WorkOS); | ||
createOrganization({ domains, name, }: { | ||
domains?: string[]; | ||
name: string; | ||
}): Promise<Organization>; | ||
generateLink({ intent, organization, returnUrl, }: { | ||
@@ -20,3 +13,2 @@ intent: GeneratePortalLinkIntent; | ||
}>; | ||
listOrganizations(options?: ListOrganizationsOptions): Promise<List<Organization>>; | ||
} |
@@ -17,11 +17,2 @@ "use strict"; | ||
} | ||
createOrganization({ domains, name, }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield this.workos.post('/organizations', { | ||
domains, | ||
name, | ||
}); | ||
return data; | ||
}); | ||
} | ||
generateLink({ intent, organization, returnUrl, }) { | ||
@@ -37,9 +28,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
listOrganizations(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield this.workos.get('/organizations', options); | ||
return data; | ||
}); | ||
} | ||
} | ||
exports.Portal = Portal; |
@@ -1,2 +0,3 @@ | ||
export interface CommonAuthorizationURLOptions { | ||
export interface AuthorizationURLOptions { | ||
clientID: string; | ||
connection?: string; | ||
@@ -8,11 +9,1 @@ domain?: string; | ||
} | ||
export declare type AuthorizationURLOptions = ({ | ||
clientID: string; | ||
projectID?: never; | ||
} & CommonAuthorizationURLOptions) | ({ | ||
clientID?: never; | ||
/** | ||
* @deprecated The projectID parameter has been deprecated. Please use clientID. | ||
*/ | ||
projectID: string; | ||
} & CommonAuthorizationURLOptions); |
@@ -10,2 +10,5 @@ import { ConnectionType } from './connection-type.enum'; | ||
id: string; | ||
organization_id: string; | ||
name: string; | ||
connection_type: ConnectionType; | ||
state: 'draft' | 'active' | 'inactive'; | ||
@@ -16,12 +19,3 @@ /** | ||
status: 'linked' | 'unlinked'; | ||
name: string; | ||
connection_type: ConnectionType; | ||
oauth_uid: string; | ||
oauth_secret: string; | ||
oauth_redirect_uri: string; | ||
saml_entity_id: string; | ||
saml_idp_url: string; | ||
saml_relying_party_trust_cert: string; | ||
saml_x509_certs: string; | ||
domains: ConnectionDomain[]; | ||
} |
@@ -1,7 +0,5 @@ | ||
export { AuthorizationURLOptions } from './authorization-url-options.interface'; | ||
export { ConnectionType } from './connection-type.enum'; | ||
export { Connection } from './connection.interface'; | ||
export { CreateConnectionOptions } from './create-connection-options.interface'; | ||
export { GetProfileOptions } from './get-profile-options.interface'; | ||
export { Profile } from './profile.interface'; | ||
export { PromoteDraftConnectionOptions } from './promote-draft-connection-options.interface'; | ||
export * from './authorization-url-options.interface'; | ||
export * from './connection-type.enum'; | ||
export * from './connection.interface'; | ||
export * from './get-profile-and-token-options.interface'; | ||
export * from './profile.interface'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ConnectionType = void 0; | ||
var connection_type_enum_1 = require("./connection-type.enum"); | ||
Object.defineProperty(exports, "ConnectionType", { enumerable: true, get: function () { return connection_type_enum_1.ConnectionType; } }); | ||
__exportStar(require("./authorization-url-options.interface"), exports); | ||
__exportStar(require("./connection-type.enum"), exports); | ||
__exportStar(require("./connection.interface"), exports); | ||
__exportStar(require("./get-profile-and-token-options.interface"), exports); | ||
__exportStar(require("./profile.interface"), exports); |
@@ -0,20 +1,16 @@ | ||
import { List } from '../common/interfaces/list.interface'; | ||
import { WorkOS } from '../workos'; | ||
import { AuthorizationURLOptions } from './interfaces/authorization-url-options.interface'; | ||
import { Connection } from './interfaces/connection.interface'; | ||
import { CreateConnectionOptions } from './interfaces/create-connection-options.interface'; | ||
import { GetProfileOptions } from './interfaces/get-profile-options.interface'; | ||
import { List } from '../common/interfaces/list.interface'; | ||
import { GetProfileAndTokenOptions } from './interfaces/get-profile-and-token-options.interface'; | ||
import { ListConnectionsOptions } from './interfaces/list-connections-options.interface'; | ||
import { Profile } from './interfaces/profile.interface'; | ||
import { PromoteDraftConnectionOptions } from './interfaces/promote-draft-connection-options.interface'; | ||
import { WorkOS } from '../workos'; | ||
import { ProfileAndToken } from './interfaces/profile-and-token.interface'; | ||
export declare class SSO { | ||
private readonly workos; | ||
constructor(workos: WorkOS); | ||
createConnection({ source, }: CreateConnectionOptions): Promise<Connection>; | ||
deleteConnection(id: string): Promise<void>; | ||
getAuthorizationURL({ connection, clientID, domain, provider, projectID, redirectURI, state, }: AuthorizationURLOptions): string; | ||
getAuthorizationURL({ connection, clientID, domain, provider, redirectURI, state, }: AuthorizationURLOptions): string; | ||
getConnection(id: string): Promise<Connection>; | ||
getProfile({ code, clientID, projectID, }: GetProfileOptions): Promise<Profile>; | ||
getProfileAndToken({ code, clientID, }: GetProfileAndTokenOptions): Promise<ProfileAndToken>; | ||
listConnections(options?: ListConnectionsOptions): Promise<List<Connection>>; | ||
promoteDraftConnection({ token }: PromoteDraftConnectionOptions): Promise<void>; | ||
} |
@@ -21,8 +21,2 @@ "use strict"; | ||
} | ||
createConnection({ source, }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield this.workos.post('/connections', { source }); | ||
return data; | ||
}); | ||
} | ||
deleteConnection(id) { | ||
@@ -33,3 +27,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
getAuthorizationURL({ connection, clientID, domain, provider, projectID, redirectURI, state, }) { | ||
getAuthorizationURL({ connection, clientID, domain, provider, redirectURI, state, }) { | ||
if (!domain && !provider && !connection) { | ||
@@ -42,3 +36,3 @@ throw new Error(`Incomplete arguments. Need to specify either a 'connection', 'domain', or 'provider'.`); | ||
provider, | ||
client_id: clientID !== null && clientID !== void 0 ? clientID : projectID, | ||
client_id: clientID, | ||
redirect_uri: redirectURI, | ||
@@ -56,16 +50,12 @@ response_type: 'code', | ||
} | ||
getProfile({ code, clientID, projectID, }) { | ||
getProfileAndToken({ code, clientID, }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const form = new URLSearchParams(); | ||
if (clientID) { | ||
form.set('client_id', clientID); | ||
} | ||
else if (projectID) { | ||
form.set('client_id', projectID); | ||
} | ||
form.set('client_secret', this.workos.key); | ||
form.set('grant_type', 'authorization_code'); | ||
form.set('code', code); | ||
const form = new URLSearchParams({ | ||
client_id: clientID, | ||
client_secret: this.workos.key, | ||
grant_type: 'authorization_code', | ||
code, | ||
}); | ||
const { data } = yield this.workos.post('/sso/token', form); | ||
return data.profile; | ||
return data; | ||
}); | ||
@@ -79,10 +69,3 @@ } | ||
} | ||
promoteDraftConnection({ token }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.workos.emitWarning('[Deprecated] sso.promoteDraftConnection({ token }) is deprecated. Use sso.createConnection({ source }) instead.'); | ||
const endpoint = `/draft_connections/${token}/activate`; | ||
yield this.workos.post(endpoint, null); | ||
}); | ||
} | ||
} | ||
exports.SSO = SSO; |
import { AxiosResponse } from 'axios'; | ||
import { AuditTrail } from './audit-trail/audit-trail'; | ||
import { PostOptions, PutOptions, WorkOSOptions } from './common/interfaces'; | ||
import { DirectorySync } from './directory-sync/directory-sync'; | ||
import { Organizations } from './organizations/organizations'; | ||
import { Passwordless } from './passwordless/passwordless'; | ||
import { Portal } from './portal/portal'; | ||
import { SSO } from './sso/sso'; | ||
import { WorkOSOptions, PostOptions } from './common/interfaces'; | ||
export declare class WorkOS { | ||
@@ -15,2 +16,3 @@ readonly key?: string | undefined; | ||
readonly directorySync: DirectorySync; | ||
readonly organizations: Organizations; | ||
readonly passwordless: Passwordless; | ||
@@ -22,4 +24,5 @@ readonly portal: Portal; | ||
get(path: string, query?: any): Promise<AxiosResponse>; | ||
put(path: string, entity: any, options?: PutOptions): Promise<AxiosResponse>; | ||
delete(path: string, query?: any): Promise<AxiosResponse>; | ||
emitWarning(warning: string): void; | ||
} |
@@ -17,9 +17,10 @@ "use strict"; | ||
const axios_1 = __importDefault(require("axios")); | ||
const package_json_1 = require("../package.json"); | ||
const audit_trail_1 = require("./audit-trail/audit-trail"); | ||
const exceptions_1 = require("./common/exceptions"); | ||
const directory_sync_1 = require("./directory-sync/directory-sync"); | ||
const exceptions_1 = require("./common/exceptions"); | ||
const organizations_1 = require("./organizations/organizations"); | ||
const passwordless_1 = require("./passwordless/passwordless"); | ||
const portal_1 = require("./portal/portal"); | ||
const sso_1 = require("./sso/sso"); | ||
const package_json_1 = require("../package.json"); | ||
const DEFAULT_HOSTNAME = 'api.workos.com'; | ||
@@ -32,2 +33,3 @@ class WorkOS { | ||
this.directorySync = new directory_sync_1.DirectorySync(this); | ||
this.organizations = new organizations_1.Organizations(this); | ||
this.passwordless = new passwordless_1.Passwordless(this); | ||
@@ -129,2 +131,39 @@ this.portal = new portal_1.Portal(this); | ||
} | ||
put(path, entity, options = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const requestHeaders = {}; | ||
if (options.idempotencyKey) { | ||
requestHeaders['Idempotency-Key'] = options.idempotencyKey; | ||
} | ||
try { | ||
return yield this.client.put(path, entity, { | ||
params: options.query, | ||
headers: requestHeaders, | ||
}); | ||
} | ||
catch (error) { | ||
const { response } = error; | ||
if (response) { | ||
const { status, data, headers } = response; | ||
const requestID = headers['X-Request-ID']; | ||
switch (status) { | ||
case 401: { | ||
throw new exceptions_1.UnauthorizedException(requestID); | ||
} | ||
case 422: { | ||
const { errors } = data; | ||
throw new exceptions_1.UnprocessableEntityException(errors, requestID); | ||
} | ||
case 404: { | ||
throw new exceptions_1.NotFoundException(path, requestID); | ||
} | ||
default: { | ||
throw new exceptions_1.GenericServerException(status, data.message, requestID); | ||
} | ||
} | ||
} | ||
throw error; | ||
} | ||
}); | ||
} | ||
delete(path, query) { | ||
@@ -131,0 +170,0 @@ return __awaiter(this, void 0, void 0, function* () { |
{ | ||
"version": "0.10.3", | ||
"version": "1.0.0", | ||
"name": "@workos-inc/node", | ||
@@ -12,3 +12,3 @@ "author": "WorkOS", | ||
"volta": { | ||
"node": "14.16.1", | ||
"node": "14.17.0", | ||
"yarn": "1.22.10" | ||
@@ -47,3 +47,3 @@ }, | ||
"jest": "26.6.3", | ||
"prettier": "2.2.1", | ||
"prettier": "2.3.0", | ||
"supertest": "6.1.3", | ||
@@ -50,0 +50,0 @@ "ts-jest": "26.5.6", |
# WorkOS Node.js Library | ||
![npm](https://img.shields.io/npm/v/@workos-inc/node) | ||
[![Build Status](https://workos.semaphoreci.com/badges/workos-node/branches/master.svg?style=shields)](https://workos.semaphoreci.com/projects/workos-node) | ||
The WorkOS library for Node.js provides convenient access to the WorkOS API from applications written in server-side JavaScript. | ||
@@ -35,5 +38,5 @@ | ||
* [Single Sign-On Guide](https://workos.com/docs/sso/guide) | ||
* [Directory Sync Guide](https://workos.com/docs/directory-sync/guide) | ||
* [Admin Portal Guide](https://workos.com/docs/admin-portal/guide) | ||
* [Magic Link Guide](https://workos.com/docs/magic-link/guide) | ||
- [Single Sign-On Guide](https://workos.com/docs/sso/guide) | ||
- [Directory Sync Guide](https://workos.com/docs/directory-sync/guide) | ||
- [Admin Portal Guide](https://workos.com/docs/admin-portal/guide) | ||
- [Magic Link Guide](https://workos.com/docs/magic-link/guide) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
51865
108
1148
0
42