@workos-inc/node 3.5.0 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/lib/common/exceptions/generic-server.exception.d.ts +1 -1
  2. package/lib/common/exceptions/generic-server.exception.js +1 -1
  3. package/lib/common/exceptions/oauth.exception.d.ts +2 -1
  4. package/lib/common/exceptions/oauth.exception.js +2 -1
  5. package/lib/users/interfaces/authenticate-user-with-magic-auth-options.interface.d.ts +0 -2
  6. package/lib/users/interfaces/authenticate-user-with-password-options.interface.d.ts +0 -2
  7. package/lib/users/interfaces/authenticate-user-with-token-options.interface.d.ts +0 -2
  8. package/lib/users/interfaces/authentication-response.interface.d.ts +0 -3
  9. package/lib/users/interfaces/index.d.ts +0 -1
  10. package/lib/users/interfaces/index.js +0 -1
  11. package/lib/users/serializers/authenticate-user-with-code-options.serializer.js +0 -1
  12. package/lib/users/serializers/authenticate-user-with-magic-auth-options.serializer.js +0 -1
  13. package/lib/users/serializers/authenticate-user-with-password-options.serializer.js +0 -1
  14. package/lib/users/serializers/authentication-response.serializer.js +0 -2
  15. package/lib/users/serializers/index.d.ts +0 -1
  16. package/lib/users/serializers/index.js +0 -1
  17. package/lib/users/users.js +3 -3
  18. package/lib/users/users.spec.js +6 -24
  19. package/lib/workos.js +2 -2
  20. package/lib/workos.spec.js +1 -1
  21. package/package.json +1 -1
  22. package/lib/users/fixtures/session.json +0 -8
  23. package/lib/users/interfaces/session.interface.d.ts +0 -41
  24. package/lib/users/interfaces/session.interface.js +0 -2
  25. package/lib/users/serializers/session.serializer.d.ts +0 -4
  26. package/lib/users/serializers/session.serializer.js +0 -22
@@ -1,8 +1,8 @@
1
1
  export declare class GenericServerException extends Error {
2
2
  readonly status: number;
3
+ readonly rawData: unknown;
3
4
  readonly requestID: string;
4
5
  readonly name: string;
5
- readonly rawData: unknown;
6
6
  readonly message: string;
7
7
  constructor(status: number, message: string | undefined, rawData: unknown, requestID: string);
8
8
  }
@@ -5,12 +5,12 @@ class GenericServerException extends Error {
5
5
  constructor(status, message, rawData, requestID) {
6
6
  super();
7
7
  this.status = status;
8
+ this.rawData = rawData;
8
9
  this.requestID = requestID;
9
10
  this.name = 'GenericServerException';
10
11
  this.message = 'The request could not be completed.';
11
12
  if (message) {
12
13
  this.message = message;
13
- this.rawData = rawData;
14
14
  }
15
15
  }
16
16
  }
@@ -3,6 +3,7 @@ export declare class OauthException extends Error {
3
3
  readonly requestID: string;
4
4
  readonly error: string | undefined;
5
5
  readonly errorDescription: string | undefined;
6
+ readonly rawData: unknown;
6
7
  readonly name: string;
7
- constructor(status: number, requestID: string, error: string | undefined, errorDescription: string | undefined);
8
+ constructor(status: number, requestID: string, error: string | undefined, errorDescription: string | undefined, rawData: unknown);
8
9
  }
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OauthException = void 0;
4
4
  class OauthException extends Error {
5
- constructor(status, requestID, error, errorDescription) {
5
+ constructor(status, requestID, error, errorDescription, rawData) {
6
6
  super();
7
7
  this.status = status;
8
8
  this.requestID = requestID;
9
9
  this.error = error;
10
10
  this.errorDescription = errorDescription;
11
+ this.rawData = rawData;
11
12
  this.name = 'OauthException';
12
13
  if (error && errorDescription) {
13
14
  this.message = `Error: ${error}\nError Description: ${errorDescription}`;
@@ -4,7 +4,6 @@ export interface AuthenticateUserWithMagicAuthOptions {
4
4
  magicAuthChallengeId: string;
5
5
  ipAddress?: string;
6
6
  userAgent?: string;
7
- expiresIn?: number;
8
7
  }
9
8
  export interface AuthenticateUserWithMagicAuthCredentials {
10
9
  clientSecret: string | undefined;
@@ -17,5 +16,4 @@ export interface SerializedAuthenticateUserWithMagicAuthOptions {
17
16
  magic_auth_challenge_id: string;
18
17
  ip_address?: string;
19
18
  user_agent?: string;
20
- expires_in?: number;
21
19
  }
@@ -4,7 +4,6 @@ export interface AuthenticateUserWithPasswordOptions {
4
4
  password: string;
5
5
  ipAddress?: string;
6
6
  userAgent?: string;
7
- expiresIn?: number;
8
7
  }
9
8
  export interface AuthenticateUserWithPasswordCredentials {
10
9
  clientSecret: string | undefined;
@@ -17,5 +16,4 @@ export interface SerializedAuthenticateUserWithPasswordOptions {
17
16
  password: string;
18
17
  ip_address?: string;
19
18
  user_agent?: string;
20
- expires_in?: number;
21
19
  }
@@ -1,7 +1,6 @@
1
1
  export interface AuthenticateUserWithCodeOptions {
2
2
  clientId: string;
3
3
  code: string;
4
- expiresIn?: number;
5
4
  }
6
5
  export interface AuthenticateUserWithCodeCredentials {
7
6
  clientSecret: string | undefined;
@@ -11,5 +10,4 @@ export interface SerializedAuthenticateUserWithCodeOptions {
11
10
  client_id: string;
12
11
  client_secret: string | undefined;
13
12
  code: string;
14
- expires_in?: number;
15
13
  }
@@ -1,10 +1,7 @@
1
1
  import { User, UserResponse } from './user.interface';
2
- import { Session, SessionResponse } from './session.interface';
3
2
  export interface AuthenticationResponse {
4
- session: Session;
5
3
  user: User;
6
4
  }
7
5
  export interface AuthenticationResponseResponse {
8
- session: SessionResponse;
9
6
  user: UserResponse;
10
7
  }
@@ -13,7 +13,6 @@ export * from './magic-auth-challenge.interface';
13
13
  export * from './remove-user-from-organization-options.interface';
14
14
  export * from './send-magic-auth-code-options.interface';
15
15
  export * from './send-verification-email-options';
16
- export * from './session.interface';
17
16
  export * from './update-user-options.interface';
18
17
  export * from './update-user-password-options.interface';
19
18
  export * from './user.interface';
@@ -29,7 +29,6 @@ __exportStar(require("./magic-auth-challenge.interface"), exports);
29
29
  __exportStar(require("./remove-user-from-organization-options.interface"), exports);
30
30
  __exportStar(require("./send-magic-auth-code-options.interface"), exports);
31
31
  __exportStar(require("./send-verification-email-options"), exports);
32
- __exportStar(require("./session.interface"), exports);
33
32
  __exportStar(require("./update-user-options.interface"), exports);
34
33
  __exportStar(require("./update-user-password-options.interface"), exports);
35
34
  __exportStar(require("./user.interface"), exports);
@@ -6,6 +6,5 @@ const serializeAuthenticateUserWithCodeOptions = (options) => ({
6
6
  client_id: options.clientId,
7
7
  client_secret: options.clientSecret,
8
8
  code: options.code,
9
- expires_in: options.expiresIn,
10
9
  });
11
10
  exports.serializeAuthenticateUserWithCodeOptions = serializeAuthenticateUserWithCodeOptions;
@@ -9,6 +9,5 @@ const serializeAuthenticateUserWithMagicAuthOptions = (options) => ({
9
9
  magic_auth_challenge_id: options.magicAuthChallengeId,
10
10
  ip_address: options.ipAddress,
11
11
  user_agent: options.userAgent,
12
- expires_in: options.expiresIn,
13
12
  });
14
13
  exports.serializeAuthenticateUserWithMagicAuthOptions = serializeAuthenticateUserWithMagicAuthOptions;
@@ -9,6 +9,5 @@ const serializeAuthenticateUserWithPasswordOptions = (options) => ({
9
9
  password: options.password,
10
10
  ip_address: options.ipAddress,
11
11
  user_agent: options.userAgent,
12
- expires_in: options.expiresIn,
13
12
  });
14
13
  exports.serializeAuthenticateUserWithPasswordOptions = serializeAuthenticateUserWithPasswordOptions;
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deserializeAuthenticationResponse = void 0;
4
- const session_serializer_1 = require("./session.serializer");
5
4
  const user_serializer_1 = require("./user.serializer");
6
5
  const deserializeAuthenticationResponse = (authenticationResponse) => ({
7
- session: (0, session_serializer_1.deserializeSession)(authenticationResponse.session),
8
6
  user: (0, user_serializer_1.deserializeUser)(authenticationResponse.user),
9
7
  });
10
8
  exports.deserializeAuthenticationResponse = deserializeAuthenticationResponse;
@@ -6,7 +6,6 @@ export * from './complete-password-reset-options.serializer';
6
6
  export * from './create-password-reset-challenge.serializer';
7
7
  export * from './create-user-options.serializer';
8
8
  export * from './send-magic-auth-code-options.serializer';
9
- export * from './session.serializer';
10
9
  export * from './update-user-options.serializer';
11
10
  export * from './update-user-password-options.serializer';
12
11
  export * from './user.serializer';
@@ -22,7 +22,6 @@ __exportStar(require("./complete-password-reset-options.serializer"), exports);
22
22
  __exportStar(require("./create-password-reset-challenge.serializer"), exports);
23
23
  __exportStar(require("./create-user-options.serializer"), exports);
24
24
  __exportStar(require("./send-magic-auth-code-options.serializer"), exports);
25
- __exportStar(require("./session.serializer"), exports);
26
25
  __exportStar(require("./update-user-options.serializer"), exports);
27
26
  __exportStar(require("./update-user-password-options.serializer"), exports);
28
27
  __exportStar(require("./user.serializer"), exports);
@@ -38,19 +38,19 @@ class Users {
38
38
  }
39
39
  authenticateUserWithMagicAuth(payload) {
40
40
  return __awaiter(this, void 0, void 0, function* () {
41
- const { data } = yield this.workos.post('/users/sessions/token', (0, serializers_1.serializeAuthenticateUserWithMagicAuthOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
41
+ const { data } = yield this.workos.post('/users/authenticate', (0, serializers_1.serializeAuthenticateUserWithMagicAuthOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
42
42
  return (0, serializers_1.deserializeAuthenticationResponse)(data);
43
43
  });
44
44
  }
45
45
  authenticateUserWithPassword(payload) {
46
46
  return __awaiter(this, void 0, void 0, function* () {
47
- const { data } = yield this.workos.post('/users/sessions/token', (0, serializers_1.serializeAuthenticateUserWithPasswordOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
47
+ const { data } = yield this.workos.post('/users/authenticate', (0, serializers_1.serializeAuthenticateUserWithPasswordOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
48
48
  return (0, serializers_1.deserializeAuthenticationResponse)(data);
49
49
  });
50
50
  }
51
51
  authenticateUserWithCode(payload) {
52
52
  return __awaiter(this, void 0, void 0, function* () {
53
- const { data } = yield this.workos.post('/users/sessions/token', (0, serializers_1.serializeAuthenticateUserWithCodeOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
53
+ const { data } = yield this.workos.post('/users/authenticate', (0, serializers_1.serializeAuthenticateUserWithCodeOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
54
54
  return (0, serializers_1.deserializeAuthenticationResponse)(data);
55
55
  });
56
56
  }
@@ -17,7 +17,6 @@ const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
17
17
  const workos_1 = require("../workos");
18
18
  const user_json_1 = __importDefault(require("./fixtures/user.json"));
19
19
  const list_users_json_1 = __importDefault(require("./fixtures/list-users.json"));
20
- const session_json_1 = __importDefault(require("./fixtures/session.json"));
21
20
  const mock = new axios_mock_adapter_1.default(axios_1.default);
22
21
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
23
22
  const userId = 'user_01H5JQDV7R7ATEYZDEG0W5PRYS';
@@ -98,61 +97,48 @@ describe('UserManagement', () => {
98
97
  });
99
98
  describe('authenticateUserWithMagicAuth', () => {
100
99
  it('sends a magic auth authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
101
- mock.onPost('/users/sessions/token').reply(200, {
100
+ mock.onPost('/users/authenticate').reply(200, {
102
101
  user: user_json_1.default,
103
- session: session_json_1.default,
104
102
  });
105
103
  const resp = yield workos.users.authenticateUserWithMagicAuth({
106
104
  clientId: 'proj_whatever',
107
105
  code: '123456',
108
106
  magicAuthChallengeId: 'auth_challenge_123',
109
107
  });
110
- expect(mock.history.post[0].url).toEqual('/users/sessions/token');
108
+ expect(mock.history.post[0].url).toEqual('/users/authenticate');
111
109
  expect(resp).toMatchObject({
112
110
  user: {
113
111
  email: 'test01@example.com',
114
112
  },
115
- session: {
116
- id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
117
- token: 'really-long-token',
118
- },
119
113
  });
120
114
  }));
121
115
  });
122
116
  describe('authenticateUserWithPassword', () => {
123
117
  it('sends an password authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
124
- mock.onPost('/users/sessions/token').reply(200, {
118
+ mock.onPost('/users/authenticate').reply(200, {
125
119
  user: user_json_1.default,
126
- session: session_json_1.default,
127
120
  });
128
121
  const resp = yield workos.users.authenticateUserWithPassword({
129
122
  clientId: 'proj_whatever',
130
123
  email: 'test01@example.com',
131
124
  password: 'extra-secure',
132
125
  });
133
- expect(mock.history.post[0].url).toEqual('/users/sessions/token');
126
+ expect(mock.history.post[0].url).toEqual('/users/authenticate');
134
127
  expect(resp).toMatchObject({
135
128
  user: {
136
129
  email: 'test01@example.com',
137
130
  },
138
- session: {
139
- id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
140
- token: 'really-long-token',
141
- },
142
131
  });
143
132
  }));
144
133
  });
145
134
  describe('authenticateUserWithCode', () => {
146
135
  it('sends a token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
147
- mock
148
- .onPost('/users/sessions/token')
149
- .reply(200, { user: user_json_1.default, session: session_json_1.default });
136
+ mock.onPost('/users/authenticate').reply(200, { user: user_json_1.default });
150
137
  const resp = yield workos.users.authenticateUserWithCode({
151
138
  clientId: 'proj_whatever',
152
139
  code: 'or this',
153
- expiresIn: 15,
154
140
  });
155
- expect(mock.history.post[0].url).toEqual('/users/sessions/token');
141
+ expect(mock.history.post[0].url).toEqual('/users/authenticate');
156
142
  expect(JSON.parse(mock.history.post[0].data)).toMatchObject({
157
143
  client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
158
144
  grant_type: 'authorization_code',
@@ -161,10 +147,6 @@ describe('UserManagement', () => {
161
147
  user: {
162
148
  email: 'test01@example.com',
163
149
  },
164
- session: {
165
- id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
166
- token: 'really-long-token',
167
- },
168
150
  });
169
151
  }));
170
152
  });
package/lib/workos.js CHANGED
@@ -27,7 +27,7 @@ const mfa_1 = require("./mfa/mfa");
27
27
  const audit_logs_1 = require("./audit-logs/audit-logs");
28
28
  const users_1 = require("./users/users");
29
29
  const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
30
- const VERSION = '3.5.0';
30
+ const VERSION = '3.6.0';
31
31
  const DEFAULT_HOSTNAME = 'api.workos.com';
32
32
  class WorkOS {
33
33
  constructor(key, options = {}) {
@@ -170,7 +170,7 @@ class WorkOS {
170
170
  }
171
171
  default: {
172
172
  if (error || errorDescription) {
173
- throw new exceptions_1.OauthException(status, requestID, error, errorDescription);
173
+ throw new exceptions_1.OauthException(status, requestID, error, errorDescription, data);
174
174
  }
175
175
  else if (code && errors) {
176
176
  // Note: ideally this should be mapped directly with a `400` status code.
@@ -149,7 +149,7 @@ describe('WorkOS', () => {
149
149
  'X-Request-ID': 'a-request-id',
150
150
  });
151
151
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
152
- yield expect(workos.post('/path', {})).rejects.toStrictEqual(new exceptions_1.OauthException(400, 'a-request-id', 'error', 'error description'));
152
+ yield expect(workos.post('/path', {})).rejects.toStrictEqual(new exceptions_1.OauthException(400, 'a-request-id', 'error', 'error description', { error: 'error', error_description: 'error description' }));
153
153
  }));
154
154
  });
155
155
  });
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.5.0",
2
+ "version": "3.6.0",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",
@@ -1,8 +0,0 @@
1
- {
2
- "id": "session_01H5K05VP5CPCXJA5Z7G191GS4",
3
- "created_at": "2023-07-18T04:40:14.954Z",
4
- "expires_at": "2023-07-18T22:40:15.555Z",
5
- "authorized_organizations": [],
6
- "unauthorized_organizations": [],
7
- "token": "really-long-token"
8
- }
@@ -1,41 +0,0 @@
1
- export interface Session {
2
- id: string;
3
- createdAt: string;
4
- expiresAt: string;
5
- authorizedOrganizations: AuthorizedOrganization[];
6
- unauthorizedOrganizations: UnauthorizedOrganization[];
7
- token: string;
8
- }
9
- interface OrganizationSummary {
10
- id: string;
11
- name: string;
12
- }
13
- interface AuthorizedOrganization {
14
- organization: OrganizationSummary;
15
- }
16
- type SessionAuthenticationMethod = 'GoogleOauth' | 'MagicAuth' | 'MicrosoftOauth' | 'Password';
17
- export type UnauthorizedOrganizationReason = {
18
- type: 'authentication_method_required';
19
- allowedAuthenticationMethods: SessionAuthenticationMethod[];
20
- };
21
- export type UnauthorizedOrganizationReasonResponse = {
22
- type: 'authentication_method_required';
23
- allowed_authentication_methods: SessionAuthenticationMethod[];
24
- };
25
- export interface UnauthorizedOrganization {
26
- organization: OrganizationSummary;
27
- reasons: UnauthorizedOrganizationReason[];
28
- }
29
- export interface UnauthorizedOrganizationResponse {
30
- organization: OrganizationSummary;
31
- reasons: UnauthorizedOrganizationReasonResponse[];
32
- }
33
- export interface SessionResponse {
34
- id: string;
35
- created_at: string;
36
- expires_at: string;
37
- authorized_organizations: AuthorizedOrganization[];
38
- unauthorized_organizations: UnauthorizedOrganizationResponse[];
39
- token: string;
40
- }
41
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +0,0 @@
1
- import { Session, SessionResponse, UnauthorizedOrganization, UnauthorizedOrganizationReason, UnauthorizedOrganizationReasonResponse, UnauthorizedOrganizationResponse } from '../interfaces/session.interface';
2
- export declare const deserializeSession: (session: SessionResponse) => Session;
3
- export declare const deserializeUnauthorizedOrganization: (unauthorizedOrganization: UnauthorizedOrganizationResponse) => UnauthorizedOrganization;
4
- export declare const deserializeUnauthorizedOrganizationReason: (unauthorizedOrganizationReason: UnauthorizedOrganizationReasonResponse) => UnauthorizedOrganizationReason;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deserializeUnauthorizedOrganizationReason = exports.deserializeUnauthorizedOrganization = exports.deserializeSession = void 0;
4
- const deserializeSession = (session) => ({
5
- id: session.id,
6
- createdAt: session.created_at,
7
- expiresAt: session.expires_at,
8
- authorizedOrganizations: session.authorized_organizations,
9
- unauthorizedOrganizations: session.unauthorized_organizations.map(exports.deserializeUnauthorizedOrganization),
10
- token: session.token,
11
- });
12
- exports.deserializeSession = deserializeSession;
13
- const deserializeUnauthorizedOrganization = (unauthorizedOrganization) => ({
14
- organization: unauthorizedOrganization.organization,
15
- reasons: unauthorizedOrganization.reasons.map(exports.deserializeUnauthorizedOrganizationReason),
16
- });
17
- exports.deserializeUnauthorizedOrganization = deserializeUnauthorizedOrganization;
18
- const deserializeUnauthorizedOrganizationReason = (unauthorizedOrganizationReason) => ({
19
- type: unauthorizedOrganizationReason.type,
20
- allowedAuthenticationMethods: unauthorizedOrganizationReason.allowed_authentication_methods,
21
- });
22
- exports.deserializeUnauthorizedOrganizationReason = deserializeUnauthorizedOrganizationReason;