@workos-inc/node 7.30.0 → 7.31.0-beta.actions1

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 (63) hide show
  1. package/lib/actions/actions.d.ts +19 -0
  2. package/lib/actions/actions.js +53 -0
  3. package/lib/actions/actions.spec.d.ts +1 -0
  4. package/lib/actions/actions.spec.js +78 -0
  5. package/lib/actions/fixtures/action-context.json +39 -0
  6. package/lib/actions/interfaces/response-payload.d.ts +23 -0
  7. package/lib/actions/interfaces/response-payload.js +2 -0
  8. package/lib/common/crypto/CryptoProvider.d.ts +32 -0
  9. package/lib/common/crypto/CryptoProvider.js +13 -0
  10. package/lib/common/crypto/CryptoProvider.spec.d.ts +1 -0
  11. package/lib/common/crypto/CryptoProvider.spec.js +57 -0
  12. package/lib/common/crypto/NodeCryptoProvider.d.ts +12 -0
  13. package/lib/common/crypto/NodeCryptoProvider.js +73 -0
  14. package/lib/common/crypto/SignatureProvider.d.ts +13 -0
  15. package/lib/common/crypto/SignatureProvider.js +53 -0
  16. package/lib/common/crypto/SignatureProvider.spec.d.ts +1 -0
  17. package/lib/common/crypto/SignatureProvider.spec.js +66 -0
  18. package/lib/common/crypto/SubtleCryptoProvider.d.ts +15 -0
  19. package/lib/common/crypto/SubtleCryptoProvider.js +75 -0
  20. package/lib/common/crypto/index.d.ts +4 -0
  21. package/lib/common/crypto/index.js +20 -0
  22. package/lib/common/net/fetch-client.spec.d.ts +1 -0
  23. package/lib/common/net/fetch-client.spec.js +140 -0
  24. package/lib/common/net/index.d.ts +5 -0
  25. package/lib/common/net/index.js +31 -0
  26. package/lib/common/net/node-client.js +1 -0
  27. package/lib/common/net/node-client.spec.d.ts +1 -0
  28. package/lib/common/net/node-client.spec.js +140 -0
  29. package/lib/common/utils/unreachable.d.ts +10 -0
  30. package/lib/common/utils/unreachable.js +18 -0
  31. package/lib/fga/fga.spec.js +0 -609
  32. package/lib/index.d.ts +3 -0
  33. package/lib/index.js +12 -0
  34. package/lib/index.worker.d.ts +3 -0
  35. package/lib/index.worker.js +6 -0
  36. package/lib/organizations/fixtures/clear-stripe-customer-id.json +13 -0
  37. package/lib/organizations/fixtures/set-stripe-customer-id-disabled.json +4 -0
  38. package/lib/organizations/fixtures/set-stripe-customer-id.json +14 -0
  39. package/lib/organizations/interfaces/organization.interface.d.ts +2 -0
  40. package/lib/organizations/interfaces/update-organization-options.interface.d.ts +2 -0
  41. package/lib/organizations/organizations.spec.js +39 -0
  42. package/lib/organizations/serializers/organization.serializer.js +3 -9
  43. package/lib/organizations/serializers/update-organization-options.serializer.js +1 -0
  44. package/lib/user-management/interfaces/authenticate-with-session-cookie.interface.d.ts +2 -0
  45. package/lib/user-management/session.js +2 -1
  46. package/lib/user-management/session.spec.js +2 -1
  47. package/lib/user-management/user-management.js +2 -1
  48. package/lib/user-management/user-management.spec.js +2 -1
  49. package/lib/webhooks/webhooks.d.ts +9 -9
  50. package/lib/webhooks/webhooks.js +11 -36
  51. package/lib/webhooks/webhooks.spec.js +23 -46
  52. package/lib/widgets/fixtures/get-token-error.json +5 -0
  53. package/lib/widgets/fixtures/token.json +3 -0
  54. package/lib/widgets/interfaces/get-token.d.ts +19 -0
  55. package/lib/widgets/interfaces/get-token.js +13 -0
  56. package/lib/widgets/widgets.d.ts +7 -0
  57. package/lib/widgets/widgets.js +25 -0
  58. package/lib/widgets/widgets.spec.d.ts +1 -0
  59. package/lib/widgets/widgets.spec.js +49 -0
  60. package/lib/workos.d.ts +5 -0
  61. package/lib/workos.js +9 -2
  62. package/lib/workos.spec.js +5 -1
  63. package/package.json +2 -1
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./NodeCryptoProvider"), exports);
18
+ __exportStar(require("./SubtleCryptoProvider"), exports);
19
+ __exportStar(require("./CryptoProvider"), exports);
20
+ __exportStar(require("./SignatureProvider"), exports);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
16
+ const test_utils_1 = require("../../common/utils/test-utils");
17
+ const fetch_client_1 = require("./fetch-client");
18
+ const fetchClient = new fetch_client_1.FetchHttpClient('https://test.workos.com', {
19
+ headers: {
20
+ Authorization: `Bearer sk_test`,
21
+ 'User-Agent': 'test-fetch-client',
22
+ },
23
+ });
24
+ describe('Fetch client', () => {
25
+ beforeEach(() => jest_fetch_mock_1.default.resetMocks());
26
+ describe('fetchRequestWithRetry', () => {
27
+ it('get for FGA path should call fetchRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
28
+ (0, test_utils_1.fetchOnce)({ data: 'response' });
29
+ const mockFetchRequestWithRetry = jest.spyOn(fetch_client_1.FetchHttpClient.prototype, 'fetchRequestWithRetry');
30
+ const response = yield fetchClient.get('/fga/v1/resources', {});
31
+ expect(mockFetchRequestWithRetry).toHaveBeenCalledTimes(1);
32
+ expect((0, test_utils_1.fetchURL)()).toBe('https://test.workos.com/fga/v1/resources');
33
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
34
+ }));
35
+ it('post for FGA path should call fetchRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
36
+ (0, test_utils_1.fetchOnce)({ data: 'response' });
37
+ const mockFetchRequestWithRetry = jest.spyOn(fetch_client_1.FetchHttpClient.prototype, 'fetchRequestWithRetry');
38
+ const response = yield fetchClient.post('/fga/v1/resources', {}, {});
39
+ expect(mockFetchRequestWithRetry).toHaveBeenCalledTimes(1);
40
+ expect((0, test_utils_1.fetchURL)()).toBe('https://test.workos.com/fga/v1/resources');
41
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
42
+ }));
43
+ it('put for FGA path should call fetchRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
44
+ (0, test_utils_1.fetchOnce)({ data: 'response' });
45
+ const mockFetchRequestWithRetry = jest.spyOn(fetch_client_1.FetchHttpClient.prototype, 'fetchRequestWithRetry');
46
+ const response = yield fetchClient.put('/fga/v1/resources/user/user-1', {}, {});
47
+ expect(mockFetchRequestWithRetry).toHaveBeenCalledTimes(1);
48
+ expect((0, test_utils_1.fetchURL)()).toBe('https://test.workos.com/fga/v1/resources/user/user-1');
49
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
50
+ }));
51
+ it('delete for FGA path should call fetchRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
52
+ (0, test_utils_1.fetchOnce)({ data: 'response' });
53
+ const mockFetchRequestWithRetry = jest.spyOn(fetch_client_1.FetchHttpClient.prototype, 'fetchRequestWithRetry');
54
+ const response = yield fetchClient.delete('/fga/v1/resources/user/user-1', {});
55
+ expect(mockFetchRequestWithRetry).toHaveBeenCalledTimes(1);
56
+ expect((0, test_utils_1.fetchURL)()).toBe('https://test.workos.com/fga/v1/resources/user/user-1');
57
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
58
+ }));
59
+ it('should retry request on 500 status code', () => __awaiter(void 0, void 0, void 0, function* () {
60
+ (0, test_utils_1.fetchOnce)({}, {
61
+ status: 500,
62
+ });
63
+ (0, test_utils_1.fetchOnce)({ data: 'response' });
64
+ const mockShouldRetryRequest = jest.spyOn(fetch_client_1.FetchHttpClient.prototype, 'shouldRetryRequest');
65
+ const mockSleep = jest.spyOn(fetchClient, 'sleep');
66
+ mockSleep.mockImplementation(() => Promise.resolve());
67
+ const response = yield fetchClient.get('/fga/v1/resources', {});
68
+ expect(mockShouldRetryRequest).toHaveBeenCalledTimes(2);
69
+ expect(mockSleep).toHaveBeenCalledTimes(1);
70
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
71
+ }));
72
+ it('should retry request on 502 status code', () => __awaiter(void 0, void 0, void 0, function* () {
73
+ (0, test_utils_1.fetchOnce)({}, {
74
+ status: 502,
75
+ });
76
+ (0, test_utils_1.fetchOnce)({ data: 'response' });
77
+ const mockShouldRetryRequest = jest.spyOn(fetch_client_1.FetchHttpClient.prototype, 'shouldRetryRequest');
78
+ const mockSleep = jest.spyOn(fetchClient, 'sleep');
79
+ mockSleep.mockImplementation(() => Promise.resolve());
80
+ const response = yield fetchClient.get('/fga/v1/resources', {});
81
+ expect(mockShouldRetryRequest).toHaveBeenCalledTimes(2);
82
+ expect(mockSleep).toHaveBeenCalledTimes(1);
83
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
84
+ }));
85
+ it('should retry request on 504 status code', () => __awaiter(void 0, void 0, void 0, function* () {
86
+ (0, test_utils_1.fetchOnce)({}, {
87
+ status: 504,
88
+ });
89
+ (0, test_utils_1.fetchOnce)({ data: 'response' });
90
+ const mockShouldRetryRequest = jest.spyOn(fetch_client_1.FetchHttpClient.prototype, 'shouldRetryRequest');
91
+ const mockSleep = jest.spyOn(fetchClient, 'sleep');
92
+ mockSleep.mockImplementation(() => Promise.resolve());
93
+ const response = yield fetchClient.get('/fga/v1/resources', {});
94
+ expect(mockShouldRetryRequest).toHaveBeenCalledTimes(2);
95
+ expect(mockSleep).toHaveBeenCalledTimes(1);
96
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
97
+ }));
98
+ it('should retry request up to 3 times on retryable status code', () => __awaiter(void 0, void 0, void 0, function* () {
99
+ (0, test_utils_1.fetchOnce)({}, {
100
+ status: 500,
101
+ });
102
+ (0, test_utils_1.fetchOnce)({}, {
103
+ status: 502,
104
+ });
105
+ (0, test_utils_1.fetchOnce)({}, {
106
+ status: 504,
107
+ });
108
+ (0, test_utils_1.fetchOnce)({}, {
109
+ status: 504,
110
+ });
111
+ const mockShouldRetryRequest = jest.spyOn(fetch_client_1.FetchHttpClient.prototype, 'shouldRetryRequest');
112
+ const mockSleep = jest.spyOn(fetchClient, 'sleep');
113
+ mockSleep.mockImplementation(() => Promise.resolve());
114
+ yield expect(fetchClient.get('/fga/v1/resources', {})).rejects.toThrowError('Gateway Timeout');
115
+ expect(mockShouldRetryRequest).toHaveBeenCalledTimes(4);
116
+ expect(mockSleep).toHaveBeenCalledTimes(3);
117
+ }));
118
+ it('should not retry requests and throw error with non-retryable status code', () => __awaiter(void 0, void 0, void 0, function* () {
119
+ (0, test_utils_1.fetchOnce)({}, {
120
+ status: 400,
121
+ });
122
+ const mockShouldRetryRequest = jest.spyOn(fetch_client_1.FetchHttpClient.prototype, 'shouldRetryRequest');
123
+ yield expect(fetchClient.get('/fga/v1/resources', {})).rejects.toThrowError('Bad Request');
124
+ expect(mockShouldRetryRequest).toHaveBeenCalledTimes(1);
125
+ }));
126
+ it('should retry request on TypeError', () => __awaiter(void 0, void 0, void 0, function* () {
127
+ (0, test_utils_1.fetchOnce)({ data: 'response' });
128
+ const mockFetchRequest = jest.spyOn(fetch_client_1.FetchHttpClient.prototype, 'fetchRequest');
129
+ mockFetchRequest.mockImplementationOnce(() => {
130
+ throw new TypeError('Network request failed');
131
+ });
132
+ const mockSleep = jest.spyOn(fetchClient, 'sleep');
133
+ mockSleep.mockImplementation(() => Promise.resolve());
134
+ const response = yield fetchClient.get('/fga/v1/resources', {});
135
+ expect(mockFetchRequest).toHaveBeenCalledTimes(2);
136
+ expect(mockSleep).toHaveBeenCalledTimes(1);
137
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
138
+ }));
139
+ });
140
+ });
@@ -0,0 +1,5 @@
1
+ import { HttpClient } from './http-client';
2
+ export declare function createHttpClient(baseURL: string, options: RequestInit, fetchFn?: typeof fetch): HttpClient;
3
+ export * from './fetch-client';
4
+ export * from './node-client';
5
+ export * from './http-client';
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.createHttpClient = void 0;
18
+ const fetch_client_1 = require("./fetch-client");
19
+ const node_client_1 = require("./node-client");
20
+ function createHttpClient(baseURL, options, fetchFn) {
21
+ if (typeof fetch !== 'undefined' || typeof fetchFn !== 'undefined') {
22
+ return new fetch_client_1.FetchHttpClient(baseURL, options, fetchFn);
23
+ }
24
+ else {
25
+ return new node_client_1.NodeHttpClient(baseURL, options);
26
+ }
27
+ }
28
+ exports.createHttpClient = createHttpClient;
29
+ __exportStar(require("./fetch-client"), exports);
30
+ __exportStar(require("./node-client"), exports);
31
+ __exportStar(require("./http-client"), exports);
@@ -187,6 +187,7 @@ class NodeHttpClient extends http_client_1.HttpClient {
187
187
  yield this.sleep(retryAttempts);
188
188
  return makeRequest().then(resolve).catch(reject);
189
189
  }
190
+ reject(new Error(err.message));
190
191
  }));
191
192
  if (body) {
192
193
  req.setHeader('Content-Length', Buffer.byteLength(body));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const nock_1 = __importDefault(require("nock"));
16
+ const node_client_1 = require("./node-client");
17
+ const nodeClient = new node_client_1.NodeHttpClient('https://test.workos.com', {
18
+ headers: {
19
+ Authorization: `Bearer sk_test`,
20
+ 'User-Agent': 'test-node-client',
21
+ },
22
+ });
23
+ describe('Node client', () => {
24
+ beforeEach(() => nock_1.default.cleanAll());
25
+ it('get for FGA path should call nodeRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ (0, nock_1.default)('https://test.workos.com')
27
+ .get('/fga/v1/resources')
28
+ .reply(200, { data: 'response' });
29
+ const mockNodeRequestWithRetry = jest.spyOn(node_client_1.NodeHttpClient.prototype, 'nodeRequestWithRetry');
30
+ const response = yield nodeClient.get('/fga/v1/resources', {});
31
+ expect(mockNodeRequestWithRetry).toHaveBeenCalledTimes(1);
32
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
33
+ }));
34
+ it('post for FGA path should call nodeRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
35
+ (0, nock_1.default)('https://test.workos.com')
36
+ .post('/fga/v1/resources')
37
+ .reply(200, { data: 'response' });
38
+ const mockNodeRequestWithRetry = jest.spyOn(node_client_1.NodeHttpClient.prototype, 'nodeRequestWithRetry');
39
+ const response = yield nodeClient.post('/fga/v1/resources', {}, {});
40
+ expect(mockNodeRequestWithRetry).toHaveBeenCalledTimes(1);
41
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
42
+ }));
43
+ it('put for FGA path should call nodeRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
44
+ (0, nock_1.default)('https://test.workos.com')
45
+ .put('/fga/v1/resources/user/user-1')
46
+ .reply(200, { data: 'response' });
47
+ const mockNodeRequestWithRetry = jest.spyOn(node_client_1.NodeHttpClient.prototype, 'nodeRequestWithRetry');
48
+ const response = yield nodeClient.put('/fga/v1/resources/user/user-1', {}, {});
49
+ expect(mockNodeRequestWithRetry).toHaveBeenCalledTimes(1);
50
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
51
+ }));
52
+ it('delete for FGA path should call nodeRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
53
+ (0, nock_1.default)('https://test.workos.com')
54
+ .delete('/fga/v1/resources/user/user-1')
55
+ .reply(200, { data: 'response' });
56
+ const mockNodeRequestWithRetry = jest.spyOn(node_client_1.NodeHttpClient.prototype, 'nodeRequestWithRetry');
57
+ const response = yield nodeClient.delete('/fga/v1/resources/user/user-1', {});
58
+ expect(mockNodeRequestWithRetry).toHaveBeenCalledTimes(1);
59
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
60
+ }));
61
+ it('should retry request on 500 status code', () => __awaiter(void 0, void 0, void 0, function* () {
62
+ (0, nock_1.default)('https://test.workos.com')
63
+ .get('/fga/v1/resources')
64
+ .reply(500)
65
+ .get('/fga/v1/resources')
66
+ .reply(200, { data: 'response' });
67
+ const mockShouldRetryRequest = jest.spyOn(node_client_1.NodeHttpClient.prototype, 'shouldRetryRequest');
68
+ const mockSleep = jest.spyOn(nodeClient, 'sleep');
69
+ mockSleep.mockImplementation(() => Promise.resolve());
70
+ const response = yield nodeClient.get('/fga/v1/resources', {});
71
+ expect(mockShouldRetryRequest).toHaveBeenCalledTimes(2);
72
+ expect(mockSleep).toHaveBeenCalledTimes(1);
73
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
74
+ }));
75
+ it('should retry request on 502 status code', () => __awaiter(void 0, void 0, void 0, function* () {
76
+ (0, nock_1.default)('https://test.workos.com')
77
+ .get('/fga/v1/resources')
78
+ .reply(502)
79
+ .get('/fga/v1/resources')
80
+ .reply(200, { data: 'response' });
81
+ const mockShouldRetryRequest = jest.spyOn(node_client_1.NodeHttpClient.prototype, 'shouldRetryRequest');
82
+ const mockSleep = jest.spyOn(nodeClient, 'sleep');
83
+ mockSleep.mockImplementation(() => Promise.resolve());
84
+ const response = yield nodeClient.get('/fga/v1/resources', {});
85
+ expect(mockShouldRetryRequest).toHaveBeenCalledTimes(2);
86
+ expect(mockSleep).toHaveBeenCalledTimes(1);
87
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
88
+ }));
89
+ it('should retry request on 504 status code', () => __awaiter(void 0, void 0, void 0, function* () {
90
+ (0, nock_1.default)('https://test.workos.com')
91
+ .get('/fga/v1/resources')
92
+ .reply(504)
93
+ .get('/fga/v1/resources')
94
+ .reply(200, { data: 'response' });
95
+ const mockShouldRetryRequest = jest.spyOn(node_client_1.NodeHttpClient.prototype, 'shouldRetryRequest');
96
+ const mockSleep = jest.spyOn(nodeClient, 'sleep');
97
+ mockSleep.mockImplementation(() => Promise.resolve());
98
+ const response = yield nodeClient.get('/fga/v1/resources', {});
99
+ expect(mockShouldRetryRequest).toHaveBeenCalledTimes(2);
100
+ expect(mockSleep).toHaveBeenCalledTimes(1);
101
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
102
+ }));
103
+ it('should retry request up to 3 times on retryable status code', () => __awaiter(void 0, void 0, void 0, function* () {
104
+ (0, nock_1.default)('https://test.workos.com')
105
+ .get('/fga/v1/resources')
106
+ .reply(504)
107
+ .get('/fga/v1/resources')
108
+ .reply(502)
109
+ .get('/fga/v1/resources')
110
+ .reply(500)
111
+ .get('/fga/v1/resources')
112
+ .reply(500);
113
+ const mockShouldRetryRequest = jest.spyOn(node_client_1.NodeHttpClient.prototype, 'shouldRetryRequest');
114
+ const mockSleep = jest.spyOn(nodeClient, 'sleep');
115
+ mockSleep.mockImplementation(() => Promise.resolve());
116
+ yield expect(nodeClient.get('/fga/v1/resources', {})).rejects.toThrowError();
117
+ expect(mockShouldRetryRequest).toHaveBeenCalledTimes(4);
118
+ expect(mockSleep).toHaveBeenCalledTimes(3);
119
+ }));
120
+ it('should not retry request on non-retryable status code', () => __awaiter(void 0, void 0, void 0, function* () {
121
+ (0, nock_1.default)('https://test.workos.com').get('/fga/v1/resources').reply(400);
122
+ const mockShouldRetryRequest = jest.spyOn(node_client_1.NodeHttpClient.prototype, 'shouldRetryRequest');
123
+ yield expect(nodeClient.get('/fga/v1/resources', {})).rejects.toThrowError();
124
+ expect(mockShouldRetryRequest).toHaveBeenCalledTimes(1);
125
+ }));
126
+ it('should retry request on TypeError', () => __awaiter(void 0, void 0, void 0, function* () {
127
+ (0, nock_1.default)('https://test.workos.com')
128
+ .get('/fga/v1/resources')
129
+ .replyWithError(new TypeError('Network request failed'))
130
+ .get('/fga/v1/resources')
131
+ .reply(200, { data: 'response' });
132
+ const mockShouldRetryRequest = jest.spyOn(node_client_1.NodeHttpClient.prototype, 'shouldRetryRequest');
133
+ const mockSleep = jest.spyOn(nodeClient, 'sleep');
134
+ mockSleep.mockImplementation(() => Promise.resolve());
135
+ const response = yield nodeClient.get('/fga/v1/resources', {});
136
+ expect(mockShouldRetryRequest).toHaveBeenCalledTimes(1);
137
+ expect(mockSleep).toHaveBeenCalledTimes(1);
138
+ expect(yield response.toJSON()).toEqual({ data: 'response' });
139
+ }));
140
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Indicates that code is unreachable.
3
+ *
4
+ * This can be used for exhaustiveness checks in situations where the compiler
5
+ * would not otherwise check for exhaustiveness.
6
+ *
7
+ * If the determination that the code is unreachable proves incorrect, an
8
+ * exception is thrown.
9
+ */
10
+ export declare const unreachable: (condition: never, message?: string) => never;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unreachable = void 0;
4
+ /**
5
+ * Indicates that code is unreachable.
6
+ *
7
+ * This can be used for exhaustiveness checks in situations where the compiler
8
+ * would not otherwise check for exhaustiveness.
9
+ *
10
+ * If the determination that the code is unreachable proves incorrect, an
11
+ * exception is thrown.
12
+ */
13
+ const unreachable = (condition,
14
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
15
+ message = `Entered unreachable code. Received '${condition}'.`) => {
16
+ throw new TypeError(message);
17
+ };
18
+ exports.unreachable = unreachable;