@workos-inc/node 2.8.0 → 2.8.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
|
-
|
|
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.
|
|
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;
|
package/lib/workos.d.ts
CHANGED
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.
|
|
28
|
+
const VERSION = '2.8.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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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;
|
package/lib/workos.spec.js
CHANGED
|
@@ -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
|
|
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(
|
|
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