@workos-inc/node 7.3.0 → 7.4.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.
@@ -1,6 +1,7 @@
1
- export declare class BadRequestException extends Error {
2
- readonly status: number;
3
- readonly name: string;
1
+ import { RequestException } from '../interfaces/request-exception.interface';
2
+ export declare class BadRequestException extends Error implements RequestException {
3
+ readonly status = 400;
4
+ readonly name = "BadRequestException";
4
5
  readonly message: string;
5
6
  readonly code?: string;
6
7
  readonly errors?: unknown[];
@@ -1,4 +1,5 @@
1
- export declare class GenericServerException extends Error {
1
+ import { RequestException } from '../interfaces/request-exception.interface';
2
+ export declare class GenericServerException extends Error implements RequestException {
2
3
  readonly status: number;
3
4
  readonly rawData: unknown;
4
5
  readonly requestID: string;
@@ -3,6 +3,7 @@ export * from './bad-request.exception';
3
3
  export * from './no-api-key-provided.exception';
4
4
  export * from './not-found.exception';
5
5
  export * from './oauth.exception';
6
+ export * from './rate-limit-exceeded.exception';
6
7
  export * from './signature-verification.exception';
7
8
  export * from './unauthorized.exception';
8
9
  export * from './unprocessable-entity.exception';
@@ -19,6 +19,7 @@ __exportStar(require("./bad-request.exception"), exports);
19
19
  __exportStar(require("./no-api-key-provided.exception"), exports);
20
20
  __exportStar(require("./not-found.exception"), exports);
21
21
  __exportStar(require("./oauth.exception"), exports);
22
+ __exportStar(require("./rate-limit-exceeded.exception"), exports);
22
23
  __exportStar(require("./signature-verification.exception"), exports);
23
24
  __exportStar(require("./unauthorized.exception"), exports);
24
25
  __exportStar(require("./unprocessable-entity.exception"), exports);
@@ -1,5 +1,5 @@
1
1
  export declare class NoApiKeyProvidedException extends Error {
2
- readonly status: number;
3
- readonly name: string;
2
+ readonly status = 500;
3
+ readonly name = "NoApiKeyProvidedException";
4
4
  readonly message: string;
5
5
  }
@@ -1,6 +1,7 @@
1
- export declare class NotFoundException extends Error {
2
- readonly status: number;
3
- readonly name: string;
1
+ import { RequestException } from '../interfaces/request-exception.interface';
2
+ export declare class NotFoundException extends Error implements RequestException {
3
+ readonly status = 404;
4
+ readonly name = "NotFoundException";
4
5
  readonly message: string;
5
6
  readonly code?: string;
6
7
  readonly requestID: string;
@@ -1,9 +1,10 @@
1
- export declare class OauthException extends Error {
1
+ import { RequestException } from '../interfaces/request-exception.interface';
2
+ export declare class OauthException extends Error implements RequestException {
2
3
  readonly status: number;
3
4
  readonly requestID: string;
4
5
  readonly error: string | undefined;
5
6
  readonly errorDescription: string | undefined;
6
7
  readonly rawData: unknown;
7
- readonly name: string;
8
+ readonly name = "OauthException";
8
9
  constructor(status: number, requestID: string, error: string | undefined, errorDescription: string | undefined, rawData: unknown);
9
10
  }
@@ -0,0 +1,13 @@
1
+ import { GenericServerException } from './generic-server.exception';
2
+ export declare class RateLimitExceededException extends GenericServerException {
3
+ /**
4
+ * The number of seconds to wait before retrying the request.
5
+ */
6
+ readonly retryAfter: number | null;
7
+ readonly name = "RateLimitExceededException";
8
+ constructor(message: string, requestID: string,
9
+ /**
10
+ * The number of seconds to wait before retrying the request.
11
+ */
12
+ retryAfter: number | null);
13
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RateLimitExceededException = void 0;
4
+ const generic_server_exception_1 = require("./generic-server.exception");
5
+ // Inheriting from `GenericServerException` in order to maintain backwards
6
+ // compatibility with what 429 errors would have previously been thrown as.
7
+ //
8
+ // TODO: Consider making it the base class for all request errors.
9
+ class RateLimitExceededException extends generic_server_exception_1.GenericServerException {
10
+ constructor(message, requestID,
11
+ /**
12
+ * The number of seconds to wait before retrying the request.
13
+ */
14
+ retryAfter) {
15
+ super(429, message, {}, requestID);
16
+ this.retryAfter = retryAfter;
17
+ this.name = 'RateLimitExceededException';
18
+ }
19
+ }
20
+ exports.RateLimitExceededException = RateLimitExceededException;
@@ -1,4 +1,4 @@
1
1
  export declare class SignatureVerificationException extends Error {
2
- readonly name: string;
2
+ readonly name = "SignatureVerificationException";
3
3
  constructor(message: string);
4
4
  }
@@ -1,7 +1,8 @@
1
- export declare class UnauthorizedException extends Error {
1
+ import { RequestException } from '../interfaces/request-exception.interface';
2
+ export declare class UnauthorizedException extends Error implements RequestException {
2
3
  readonly requestID: string;
3
- readonly status: number;
4
- readonly name: string;
4
+ readonly status = 401;
5
+ readonly name = "UnauthorizedException";
5
6
  readonly message: string;
6
7
  constructor(requestID: string);
7
8
  }
@@ -1,7 +1,8 @@
1
1
  import { UnprocessableEntityError } from '../interfaces';
2
- export declare class UnprocessableEntityException extends Error {
3
- readonly status: number;
4
- readonly name: string;
2
+ import { RequestException } from '../interfaces/request-exception.interface';
3
+ export declare class UnprocessableEntityException extends Error implements RequestException {
4
+ readonly status = 422;
5
+ readonly name = "UnprocessableEntityException";
5
6
  readonly message: string;
6
7
  readonly code?: string;
7
8
  readonly requestID: string;
@@ -0,0 +1,5 @@
1
+ export interface RequestException {
2
+ readonly status: number;
3
+ readonly message: string;
4
+ readonly requestID: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -7,6 +7,7 @@
7
7
  "revoked_at": "2023-07-18T02:07:19.911Z",
8
8
  "expires_at": "2023-07-18T02:07:19.911Z",
9
9
  "organization_id": "org_01H5JQDV7R7ATEYZDEG0W5PRYS",
10
+ "inviter_user_id": null,
10
11
  "token": "Z1uX3RbwcIl5fIGJJJCXXisdI",
11
12
  "accept_invitation_url": "https://myauthkit.com/invite?invitation_token=Z1uX3RbwcIl5fIGJJJCXXisdI",
12
13
  "created_at": "2023-07-18T02:07:19.911Z",
@@ -10,6 +10,7 @@
10
10
  "revoked_at": "2023-07-18T02:07:19.911Z",
11
11
  "expires_at": "2023-07-18T02:07:19.911Z",
12
12
  "organization_id": "org_01H5JQDV7R7ATEYZDEG0W5PRYS",
13
+ "inviter_user_id": null,
13
14
  "token": "Z1uX3RbwcIl5fIGJJJCXXisdI",
14
15
  "accept_invitation_url": "https://myauthkit.com/invite?invitation_token=Z1uX3RbwcIl5fIGJJJCXXisdI",
15
16
  "created_at": "2023-07-18T02:07:19.911Z",
@@ -7,6 +7,7 @@ export interface Invitation {
7
7
  revokedAt: string | null;
8
8
  expiresAt: string;
9
9
  organizationId: string | null;
10
+ inviterUserId: string | null;
10
11
  token: string;
11
12
  acceptInvitationUrl: string;
12
13
  createdAt: string;
@@ -21,6 +22,7 @@ export interface InvitationEvent {
21
22
  revokedAt: string | null;
22
23
  expiresAt: string;
23
24
  organizationId: string | null;
25
+ inviterUserId: string | null;
24
26
  createdAt: string;
25
27
  updatedAt: string;
26
28
  }
@@ -33,6 +35,7 @@ export interface InvitationResponse {
33
35
  revoked_at: string | null;
34
36
  expires_at: string;
35
37
  organization_id: string | null;
38
+ inviter_user_id: string | null;
36
39
  token: string;
37
40
  accept_invitation_url: string;
38
41
  created_at: string;
@@ -47,6 +50,7 @@ export interface InvitationEventResponse {
47
50
  revoked_at: string | null;
48
51
  expires_at: string;
49
52
  organization_id: string | null;
53
+ inviter_user_id: string | null;
50
54
  created_at: string;
51
55
  updated_at: string;
52
56
  }
@@ -10,6 +10,7 @@ const deserializeInvitation = (invitation) => ({
10
10
  revokedAt: invitation.revoked_at,
11
11
  expiresAt: invitation.expires_at,
12
12
  organizationId: invitation.organization_id,
13
+ inviterUserId: invitation.inviter_user_id,
13
14
  token: invitation.token,
14
15
  acceptInvitationUrl: invitation.accept_invitation_url,
15
16
  createdAt: invitation.created_at,
@@ -25,6 +26,7 @@ const deserializeInvitationEvent = (invitation) => ({
25
26
  revokedAt: invitation.revoked_at,
26
27
  expiresAt: invitation.expires_at,
27
28
  organizationId: invitation.organization_id,
29
+ inviterUserId: invitation.inviter_user_id,
28
30
  createdAt: invitation.created_at,
29
31
  updatedAt: invitation.updated_at,
30
32
  });
package/lib/workos.js CHANGED
@@ -24,7 +24,7 @@ const audit_logs_1 = require("./audit-logs/audit-logs");
24
24
  const user_management_1 = require("./user-management/user-management");
25
25
  const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
26
26
  const fetch_client_1 = require("./common/utils/fetch-client");
27
- const VERSION = '7.3.0';
27
+ const VERSION = '7.4.0';
28
28
  const DEFAULT_HOSTNAME = 'api.workos.com';
29
29
  class WorkOS {
30
30
  constructor(key, options = {}) {
@@ -170,6 +170,10 @@ class WorkOS {
170
170
  requestID,
171
171
  });
172
172
  }
173
+ case 429: {
174
+ const retryAfter = headers.get('Retry-After');
175
+ throw new exceptions_1.RateLimitExceededException(data.message, requestID, retryAfter ? Number(retryAfter) : null);
176
+ }
173
177
  default: {
174
178
  if (error || errorDescription) {
175
179
  throw new exceptions_1.OauthException(status, requestID, error, errorDescription, data);
@@ -17,6 +17,7 @@ const test_utils_1 = require("./common/utils/test-utils");
17
17
  const promises_1 = __importDefault(require("fs/promises"));
18
18
  const exceptions_1 = require("./common/exceptions");
19
19
  const workos_1 = require("./workos");
20
+ const rate_limit_exceeded_exception_1 = require("./common/exceptions/rate-limit-exceeded.exception");
20
21
  describe('WorkOS', () => {
21
22
  beforeEach(() => jest_fetch_mock_1.default.resetMocks());
22
23
  describe('constructor', () => {
@@ -163,6 +164,18 @@ describe('WorkOS', () => {
163
164
  yield expect(workos.post('/path', {})).rejects.toStrictEqual(new exceptions_1.OauthException(400, 'a-request-id', 'error', 'error description', { error: 'error', error_description: 'error description' }));
164
165
  }));
165
166
  });
167
+ describe('when the api responses with a 429', () => {
168
+ it('throws a RateLimitExceededException', () => __awaiter(void 0, void 0, void 0, function* () {
169
+ (0, test_utils_1.fetchOnce)({
170
+ message: 'Too many requests',
171
+ }, {
172
+ status: 429,
173
+ headers: { 'X-Request-ID': 'a-request-id', 'Retry-After': '10' },
174
+ });
175
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
176
+ yield expect(workos.get('/path')).rejects.toStrictEqual(new rate_limit_exceeded_exception_1.RateLimitExceededException('Too many requests', 'a-request-id', 10));
177
+ }));
178
+ });
166
179
  describe('when the entity is null', () => {
167
180
  it('sends a null body', () => __awaiter(void 0, void 0, void 0, function* () {
168
181
  (0, test_utils_1.fetchOnce)();
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.3.0",
2
+ "version": "7.4.0",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",