@workos-inc/node 2.8.0 → 2.9.1

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.
@@ -1,7 +1,13 @@
1
1
  export declare class NotFoundException extends Error {
2
- readonly requestID: string;
3
2
  readonly status: number;
4
3
  readonly name: string;
5
4
  readonly message: string;
6
- constructor(path: string, requestID: string);
5
+ readonly code?: string;
6
+ readonly requestID: string;
7
+ constructor({ code, message, path, requestID, }: {
8
+ code?: string;
9
+ message?: string;
10
+ path: string;
11
+ requestID: string;
12
+ });
7
13
  }
@@ -2,12 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NotFoundException = void 0;
4
4
  class NotFoundException extends Error {
5
- constructor(path, requestID) {
5
+ constructor({ code, message, path, requestID, }) {
6
6
  super();
7
- this.requestID = requestID;
8
7
  this.status = 404;
9
8
  this.name = 'NotFoundException';
10
- this.message = `The requested path '${path}' could not be found.`;
9
+ this.code = code;
10
+ this.message =
11
+ message !== null && message !== void 0 ? message : `The requested path '${path}' could not be found.`;
12
+ this.requestID = requestID;
11
13
  }
12
14
  }
13
15
  exports.NotFoundException = NotFoundException;
@@ -35,6 +35,7 @@ describe('DirectorySync', () => {
35
35
  id: 'dir_grp_123',
36
36
  idp_id: '123',
37
37
  directory_id: 'dir_123',
38
+ organization_id: 'org_123',
38
39
  name: 'Foo Group',
39
40
  created_at: `2021-10-27 15:21:50.640958`,
40
41
  updated_at: '2021-10-27 15:21:50.640959',
@@ -48,6 +49,7 @@ describe('DirectorySync', () => {
48
49
  custom: true,
49
50
  },
50
51
  directory_id: 'dir_123',
52
+ organization_id: 'org_123',
51
53
  emails: [
52
54
  {
53
55
  primary: true,
@@ -2,6 +2,7 @@ export interface Group {
2
2
  id: string;
3
3
  idp_id: string;
4
4
  directory_id: string;
5
+ organization_id: string | null;
5
6
  name: string;
6
7
  created_at: string;
7
8
  updated_at: string;
@@ -3,6 +3,7 @@ export declare type DefaultCustomAttributes = Record<string, unknown>;
3
3
  export interface User<TCustomAttributes extends object = DefaultCustomAttributes, TRawAttributes = any> {
4
4
  id: string;
5
5
  directory_id: string;
6
+ organization_id: string | null;
6
7
  raw_attributes: TRawAttributes;
7
8
  custom_attributes: TCustomAttributes;
8
9
  idp_id: string;
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { WorkOS } from './workos';
2
+ export * from './audit-logs/interfaces';
2
3
  export * from './audit-trail/interfaces';
3
4
  export * from './common/exceptions';
4
5
  export * from './common/interfaces';
package/lib/index.js CHANGED
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.WorkOS = void 0;
18
18
  const workos_1 = require("./workos");
19
19
  Object.defineProperty(exports, "WorkOS", { enumerable: true, get: function () { return workos_1.WorkOS; } });
20
+ __exportStar(require("./audit-logs/interfaces"), exports);
20
21
  __exportStar(require("./audit-trail/interfaces"), exports);
21
22
  __exportStar(require("./common/exceptions"), exports);
22
23
  __exportStar(require("./common/interfaces"), exports);
@@ -2,6 +2,7 @@ export interface WebhookDirectoryGroup<TRawAttributes = any> {
2
2
  id: string;
3
3
  idp_id: string;
4
4
  directory_id: string;
5
+ organization_id: string | null;
5
6
  name: string;
6
7
  created_at: string;
7
8
  updated_at: string;
package/lib/workos.d.ts CHANGED
@@ -29,4 +29,5 @@ export declare class WorkOS {
29
29
  put(path: string, entity: any, options?: PutOptions): Promise<AxiosResponse>;
30
30
  delete(path: string, query?: any): Promise<AxiosResponse>;
31
31
  emitWarning(warning: string): void;
32
+ private handleAxiosError;
32
33
  }
package/lib/workos.js CHANGED
@@ -25,7 +25,7 @@ const webhooks_1 = require("./webhooks/webhooks");
25
25
  const mfa_1 = require("./mfa/mfa");
26
26
  const audit_logs_1 = require("./audit-logs/audit-logs");
27
27
  const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
28
- const VERSION = '2.8.0';
28
+ const VERSION = '2.9.1';
29
29
  const DEFAULT_HOSTNAME = 'api.workos.com';
30
30
  class WorkOS {
31
31
  constructor(key, options = {}) {
@@ -77,47 +77,7 @@ class WorkOS {
77
77
  });
78
78
  }
79
79
  catch (error) {
80
- const { response } = error;
81
- if (response) {
82
- const { status, data, headers } = response;
83
- const requestID = headers['X-Request-ID'];
84
- const { code, error_description: errorDescription, error, errors, message, } = data;
85
- switch (status) {
86
- case 401: {
87
- throw new exceptions_1.UnauthorizedException(requestID);
88
- }
89
- case 422: {
90
- const { errors } = data;
91
- throw new exceptions_1.UnprocessableEntityException({
92
- code,
93
- errors,
94
- message,
95
- requestID,
96
- });
97
- }
98
- case 404: {
99
- throw new exceptions_1.NotFoundException(path, requestID);
100
- }
101
- default: {
102
- if (error || errorDescription) {
103
- throw new exceptions_1.OauthException(status, requestID, error, errorDescription);
104
- }
105
- else if (code && errors) {
106
- // Note: ideally this should be mapped directly with a `400` status code.
107
- // However, this would break existing logic for the `OauthException` exception.
108
- throw new bad_request_exception_1.BadRequestException({
109
- code,
110
- errors,
111
- message,
112
- requestID,
113
- });
114
- }
115
- else {
116
- throw new exceptions_1.GenericServerException(status, data.message, requestID);
117
- }
118
- }
119
- }
120
- }
80
+ this.handleAxiosError({ path, error });
121
81
  throw error;
122
82
  }
123
83
  });
@@ -136,37 +96,7 @@ class WorkOS {
136
96
  });
137
97
  }
138
98
  catch (error) {
139
- const { response } = error;
140
- if (response) {
141
- const { status, data, headers } = response;
142
- const requestID = headers['X-Request-ID'];
143
- const { code, error_description: errorDescription, error, message, } = data;
144
- switch (status) {
145
- case 401: {
146
- throw new exceptions_1.UnauthorizedException(requestID);
147
- }
148
- case 422: {
149
- const { errors } = data;
150
- throw new exceptions_1.UnprocessableEntityException({
151
- code,
152
- errors,
153
- message,
154
- requestID,
155
- });
156
- }
157
- case 404: {
158
- throw new exceptions_1.NotFoundException(path, requestID);
159
- }
160
- default: {
161
- if (error || errorDescription) {
162
- throw new exceptions_1.OauthException(status, requestID, error, errorDescription);
163
- }
164
- else {
165
- throw new exceptions_1.GenericServerException(status, data.message, requestID);
166
- }
167
- }
168
- }
169
- }
99
+ this.handleAxiosError({ path, error });
170
100
  throw error;
171
101
  }
172
102
  });
@@ -184,37 +114,7 @@ class WorkOS {
184
114
  });
185
115
  }
186
116
  catch (error) {
187
- const { response } = error;
188
- if (response) {
189
- const { status, data, headers } = response;
190
- const requestID = headers['X-Request-ID'];
191
- const { code, error_description: errorDescription, error, message, } = data;
192
- switch (status) {
193
- case 401: {
194
- throw new exceptions_1.UnauthorizedException(requestID);
195
- }
196
- case 422: {
197
- const { errors } = data;
198
- throw new exceptions_1.UnprocessableEntityException({
199
- code,
200
- errors,
201
- message,
202
- requestID,
203
- });
204
- }
205
- case 404: {
206
- throw new exceptions_1.NotFoundException(path, requestID);
207
- }
208
- default: {
209
- if (error || errorDescription) {
210
- throw new exceptions_1.OauthException(status, requestID, error, errorDescription);
211
- }
212
- else {
213
- throw new exceptions_1.GenericServerException(status, data.message, requestID);
214
- }
215
- }
216
- }
217
- }
117
+ this.handleAxiosError({ path, error });
218
118
  throw error;
219
119
  }
220
120
  });
@@ -227,37 +127,7 @@ class WorkOS {
227
127
  });
228
128
  }
229
129
  catch (error) {
230
- const { response } = error;
231
- if (response) {
232
- const { status, data, headers } = response;
233
- const requestID = headers['X-Request-ID'];
234
- const { code, error_description: errorDescription, error, message, } = data;
235
- switch (status) {
236
- case 401: {
237
- throw new exceptions_1.UnauthorizedException(requestID);
238
- }
239
- case 422: {
240
- const { errors } = data;
241
- throw new exceptions_1.UnprocessableEntityException({
242
- code,
243
- errors,
244
- message,
245
- requestID,
246
- });
247
- }
248
- case 404: {
249
- throw new exceptions_1.NotFoundException(path, requestID);
250
- }
251
- default: {
252
- if (error || errorDescription) {
253
- throw new exceptions_1.OauthException(status, requestID, error, errorDescription);
254
- }
255
- else {
256
- throw new exceptions_1.GenericServerException(status, data.message, requestID);
257
- }
258
- }
259
- }
260
- }
130
+ this.handleAxiosError({ path, error });
261
131
  throw error;
262
132
  }
263
133
  });
@@ -269,5 +139,53 @@ class WorkOS {
269
139
  }
270
140
  return process.emitWarning(warning, 'WorkOS');
271
141
  }
142
+ handleAxiosError({ path, error }) {
143
+ const { response } = error;
144
+ if (response) {
145
+ const { status, data, headers } = response;
146
+ const requestID = headers['X-Request-ID'];
147
+ const { code, error_description: errorDescription, error, errors, message, } = data;
148
+ switch (status) {
149
+ case 401: {
150
+ throw new exceptions_1.UnauthorizedException(requestID);
151
+ }
152
+ case 422: {
153
+ const { errors } = data;
154
+ throw new exceptions_1.UnprocessableEntityException({
155
+ code,
156
+ errors,
157
+ message,
158
+ requestID,
159
+ });
160
+ }
161
+ case 404: {
162
+ throw new exceptions_1.NotFoundException({
163
+ code,
164
+ message,
165
+ path,
166
+ requestID,
167
+ });
168
+ }
169
+ default: {
170
+ if (error || errorDescription) {
171
+ throw new exceptions_1.OauthException(status, requestID, error, errorDescription);
172
+ }
173
+ else if (code && errors) {
174
+ // Note: ideally this should be mapped directly with a `400` status code.
175
+ // However, this would break existing logic for the `OauthException` exception.
176
+ throw new bad_request_exception_1.BadRequestException({
177
+ code,
178
+ errors,
179
+ message,
180
+ requestID,
181
+ });
182
+ }
183
+ else {
184
+ throw new exceptions_1.GenericServerException(status, data.message, requestID);
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }
272
190
  }
273
191
  exports.WorkOS = WorkOS;
@@ -69,11 +69,43 @@ describe('WorkOS', () => {
69
69
  describe('post', () => {
70
70
  describe('when the api responds with a 404', () => {
71
71
  it('throws a NotFoundException', () => __awaiter(void 0, void 0, void 0, function* () {
72
+ const message = 'Not Found';
72
73
  mock.onPost().reply(404, {
73
- message: 'Not Found',
74
+ message,
74
75
  }, { 'X-Request-ID': 'a-request-id' });
75
76
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
76
- yield expect(workos.post('/path', {})).rejects.toStrictEqual(new exceptions_1.NotFoundException('/path', 'a-request-id'));
77
+ yield expect(workos.post('/path', {})).rejects.toStrictEqual(new exceptions_1.NotFoundException({
78
+ message,
79
+ path: '/path',
80
+ requestID: 'a-request-id',
81
+ }));
82
+ }));
83
+ it('preserves the error code, status, and message from the underlying response', () => __awaiter(void 0, void 0, void 0, function* () {
84
+ const message = 'The thing you are looking for is not here.';
85
+ const code = 'thing-not-found';
86
+ mock.onPost().reply(404, {
87
+ code,
88
+ message,
89
+ }, { 'X-Request-ID': 'a-request-id' });
90
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
91
+ yield expect(workos.post('/path', {})).rejects.toMatchObject({
92
+ code,
93
+ message,
94
+ status: 404,
95
+ });
96
+ }));
97
+ it('includes the path in the message if there is no message in the response', () => __awaiter(void 0, void 0, void 0, function* () {
98
+ const code = 'thing-not-found';
99
+ const path = '/path/to/thing/that-aint-there';
100
+ mock.onPost().reply(404, {
101
+ code,
102
+ }, { 'X-Request-ID': 'a-request-id' });
103
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
104
+ yield expect(workos.post(path, {})).rejects.toMatchObject({
105
+ code,
106
+ message: `The requested path '${path}' could not be found.`,
107
+ status: 404,
108
+ });
77
109
  }));
78
110
  });
79
111
  describe('when the api responds with a 500 and no error/error_description', () => {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.8.0",
2
+ "version": "2.9.1",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/jest": "27.5.2",
43
- "@types/node": "14.18.21",
43
+ "@types/node": "14.18.22",
44
44
  "@types/pluralize": "0.0.29",
45
45
  "axios-mock-adapter": "1.21.1",
46
46
  "jest": "27.5.1",