@workos-inc/node 7.72.0 → 7.72.2
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.
- package/lib/common/net/fetch-client.js +4 -4
- package/lib/common/net/fetch-client.spec.js +32 -0
- package/lib/common/net/http-client.d.ts +1 -0
- package/lib/common/net/http-client.js +4 -1
- package/lib/common/net/node-client.js +4 -4
- package/lib/common/net/node-client.spec.js +36 -0
- package/lib/widgets/interfaces/get-token.d.ts +1 -1
- package/lib/workos.js +1 -1
- package/package.json +1 -1
|
@@ -34,7 +34,7 @@ class FetchHttpClient extends http_client_1.HttpClient {
|
|
|
34
34
|
get(path, options) {
|
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
36
|
const resourceURL = http_client_1.HttpClient.getResourceURL(this.baseURL, path, options.params);
|
|
37
|
-
if (
|
|
37
|
+
if (http_client_1.HttpClient.isPathRetryable(path)) {
|
|
38
38
|
return yield this.fetchRequestWithRetry(resourceURL, 'GET', null, options.headers);
|
|
39
39
|
}
|
|
40
40
|
else {
|
|
@@ -45,7 +45,7 @@ class FetchHttpClient extends http_client_1.HttpClient {
|
|
|
45
45
|
post(path, entity, options) {
|
|
46
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
47
|
const resourceURL = http_client_1.HttpClient.getResourceURL(this.baseURL, path, options.params);
|
|
48
|
-
if (
|
|
48
|
+
if (http_client_1.HttpClient.isPathRetryable(path)) {
|
|
49
49
|
return yield this.fetchRequestWithRetry(resourceURL, 'POST', http_client_1.HttpClient.getBody(entity), Object.assign(Object.assign({}, http_client_1.HttpClient.getContentTypeHeader(entity)), options.headers));
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
@@ -56,7 +56,7 @@ class FetchHttpClient extends http_client_1.HttpClient {
|
|
|
56
56
|
put(path, entity, options) {
|
|
57
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
58
|
const resourceURL = http_client_1.HttpClient.getResourceURL(this.baseURL, path, options.params);
|
|
59
|
-
if (
|
|
59
|
+
if (http_client_1.HttpClient.isPathRetryable(path)) {
|
|
60
60
|
return yield this.fetchRequestWithRetry(resourceURL, 'PUT', http_client_1.HttpClient.getBody(entity), Object.assign(Object.assign({}, http_client_1.HttpClient.getContentTypeHeader(entity)), options.headers));
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
@@ -67,7 +67,7 @@ class FetchHttpClient extends http_client_1.HttpClient {
|
|
|
67
67
|
delete(path, options) {
|
|
68
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
69
|
const resourceURL = http_client_1.HttpClient.getResourceURL(this.baseURL, path, options.params);
|
|
70
|
-
if (
|
|
70
|
+
if (http_client_1.HttpClient.isPathRetryable(path)) {
|
|
71
71
|
return yield this.fetchRequestWithRetry(resourceURL, 'DELETE', null, options.headers);
|
|
72
72
|
}
|
|
73
73
|
else {
|
|
@@ -58,6 +58,38 @@ describe('Fetch client', () => {
|
|
|
58
58
|
expect((0, test_utils_1.fetchURL)()).toBe('https://test.workos.com/fga/v1/resources/user/user-1');
|
|
59
59
|
expect(yield response.toJSON()).toEqual({ data: 'response' });
|
|
60
60
|
}));
|
|
61
|
+
it('get for Vault path should call fetchRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
(0, test_utils_1.fetchOnce)({ data: 'response' });
|
|
63
|
+
const mockFetchRequestWithRetry = jest.spyOn(fetch_client_1.FetchHttpClient.prototype, 'fetchRequestWithRetry');
|
|
64
|
+
const response = yield fetchClient.get('/vault/v1/kv', {});
|
|
65
|
+
expect(mockFetchRequestWithRetry).toHaveBeenCalledTimes(1);
|
|
66
|
+
expect((0, test_utils_1.fetchURL)()).toBe('https://test.workos.com/vault/v1/kv');
|
|
67
|
+
expect(yield response.toJSON()).toEqual({ data: 'response' });
|
|
68
|
+
}));
|
|
69
|
+
it('post for Vault path should call fetchRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
(0, test_utils_1.fetchOnce)({ data: 'response' });
|
|
71
|
+
const mockFetchRequestWithRetry = jest.spyOn(fetch_client_1.FetchHttpClient.prototype, 'fetchRequestWithRetry');
|
|
72
|
+
const response = yield fetchClient.post('/vault/v1/kv', {}, {});
|
|
73
|
+
expect(mockFetchRequestWithRetry).toHaveBeenCalledTimes(1);
|
|
74
|
+
expect((0, test_utils_1.fetchURL)()).toBe('https://test.workos.com/vault/v1/kv');
|
|
75
|
+
expect(yield response.toJSON()).toEqual({ data: 'response' });
|
|
76
|
+
}));
|
|
77
|
+
it('put for Vault path should call fetchRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
(0, test_utils_1.fetchOnce)({ data: 'response' });
|
|
79
|
+
const mockFetchRequestWithRetry = jest.spyOn(fetch_client_1.FetchHttpClient.prototype, 'fetchRequestWithRetry');
|
|
80
|
+
const response = yield fetchClient.put('/vault/v1/kv/secret', {}, {});
|
|
81
|
+
expect(mockFetchRequestWithRetry).toHaveBeenCalledTimes(1);
|
|
82
|
+
expect((0, test_utils_1.fetchURL)()).toBe('https://test.workos.com/vault/v1/kv/secret');
|
|
83
|
+
expect(yield response.toJSON()).toEqual({ data: 'response' });
|
|
84
|
+
}));
|
|
85
|
+
it('delete for Vault path should call fetchRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
+
(0, test_utils_1.fetchOnce)({ data: 'response' });
|
|
87
|
+
const mockFetchRequestWithRetry = jest.spyOn(fetch_client_1.FetchHttpClient.prototype, 'fetchRequestWithRetry');
|
|
88
|
+
const response = yield fetchClient.delete('/vault/v1/kv/secret', {});
|
|
89
|
+
expect(mockFetchRequestWithRetry).toHaveBeenCalledTimes(1);
|
|
90
|
+
expect((0, test_utils_1.fetchURL)()).toBe('https://test.workos.com/vault/v1/kv/secret');
|
|
91
|
+
expect(yield response.toJSON()).toEqual({ data: 'response' });
|
|
92
|
+
}));
|
|
61
93
|
it('should retry request on 500 status code', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
94
|
(0, test_utils_1.fetchOnce)({}, {
|
|
63
95
|
status: 500,
|
|
@@ -18,6 +18,7 @@ export declare abstract class HttpClient implements HttpClientInterface {
|
|
|
18
18
|
static getQueryString(queryObj?: Record<string, any>): string | undefined;
|
|
19
19
|
static getContentTypeHeader(entity: any): RequestHeaders | undefined;
|
|
20
20
|
static getBody(entity: any): BodyInit | null | undefined;
|
|
21
|
+
static isPathRetryable(path: string): boolean;
|
|
21
22
|
private getSleepTimeInMilliseconds;
|
|
22
23
|
sleep: (retryAttempt: number) => Promise<unknown>;
|
|
23
24
|
}
|
|
@@ -8,7 +8,7 @@ class HttpClient {
|
|
|
8
8
|
this.MAX_RETRY_ATTEMPTS = 3;
|
|
9
9
|
this.BACKOFF_MULTIPLIER = 1.5;
|
|
10
10
|
this.MINIMUM_SLEEP_TIME_IN_MILLISECONDS = 500;
|
|
11
|
-
this.RETRY_STATUS_CODES = [500, 502, 504];
|
|
11
|
+
this.RETRY_STATUS_CODES = [408, 500, 502, 504];
|
|
12
12
|
this.sleep = (retryAttempt) => new Promise((resolve) => setTimeout(resolve, this.getSleepTimeInMilliseconds(retryAttempt)));
|
|
13
13
|
}
|
|
14
14
|
/** The HTTP client name used for diagnostics */
|
|
@@ -52,6 +52,9 @@ class HttpClient {
|
|
|
52
52
|
}
|
|
53
53
|
return JSON.stringify(entity);
|
|
54
54
|
}
|
|
55
|
+
static isPathRetryable(path) {
|
|
56
|
+
return path.startsWith('/fga/') || path.startsWith('/vault/');
|
|
57
|
+
}
|
|
55
58
|
getSleepTimeInMilliseconds(retryAttempt) {
|
|
56
59
|
const sleepTime = this.MINIMUM_SLEEP_TIME_IN_MILLISECONDS *
|
|
57
60
|
Math.pow(this.BACKOFF_MULTIPLIER, retryAttempt);
|
|
@@ -67,7 +67,7 @@ class NodeHttpClient extends http_client_1.HttpClient {
|
|
|
67
67
|
get(path, options) {
|
|
68
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
69
|
const resourceURL = http_client_1.HttpClient.getResourceURL(this.baseURL, path, options.params);
|
|
70
|
-
if (
|
|
70
|
+
if (http_client_1.HttpClient.isPathRetryable(path)) {
|
|
71
71
|
return yield this.nodeRequestWithRetry(resourceURL, 'GET', null, options.headers);
|
|
72
72
|
}
|
|
73
73
|
else {
|
|
@@ -78,7 +78,7 @@ class NodeHttpClient extends http_client_1.HttpClient {
|
|
|
78
78
|
post(path, entity, options) {
|
|
79
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
80
|
const resourceURL = http_client_1.HttpClient.getResourceURL(this.baseURL, path, options.params);
|
|
81
|
-
if (
|
|
81
|
+
if (http_client_1.HttpClient.isPathRetryable(path)) {
|
|
82
82
|
return yield this.nodeRequestWithRetry(resourceURL, 'POST', NodeHttpClient.getBody(entity), Object.assign(Object.assign({}, http_client_1.HttpClient.getContentTypeHeader(entity)), options.headers));
|
|
83
83
|
}
|
|
84
84
|
else {
|
|
@@ -89,7 +89,7 @@ class NodeHttpClient extends http_client_1.HttpClient {
|
|
|
89
89
|
put(path, entity, options) {
|
|
90
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
91
|
const resourceURL = http_client_1.HttpClient.getResourceURL(this.baseURL, path, options.params);
|
|
92
|
-
if (
|
|
92
|
+
if (http_client_1.HttpClient.isPathRetryable(path)) {
|
|
93
93
|
return yield this.nodeRequestWithRetry(resourceURL, 'PUT', NodeHttpClient.getBody(entity), Object.assign(Object.assign({}, http_client_1.HttpClient.getContentTypeHeader(entity)), options.headers));
|
|
94
94
|
}
|
|
95
95
|
else {
|
|
@@ -100,7 +100,7 @@ class NodeHttpClient extends http_client_1.HttpClient {
|
|
|
100
100
|
delete(path, options) {
|
|
101
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
102
|
const resourceURL = http_client_1.HttpClient.getResourceURL(this.baseURL, path, options.params);
|
|
103
|
-
if (
|
|
103
|
+
if (http_client_1.HttpClient.isPathRetryable(path)) {
|
|
104
104
|
return yield this.nodeRequestWithRetry(resourceURL, 'DELETE', null, options.headers);
|
|
105
105
|
}
|
|
106
106
|
else {
|
|
@@ -58,6 +58,42 @@ describe('Node client', () => {
|
|
|
58
58
|
expect(mockNodeRequestWithRetry).toHaveBeenCalledTimes(1);
|
|
59
59
|
expect(yield response.toJSON()).toEqual({ data: 'response' });
|
|
60
60
|
}));
|
|
61
|
+
it('get for Vault path should call nodeRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
(0, nock_1.default)('https://test.workos.com')
|
|
63
|
+
.get('/vault/v1/kv')
|
|
64
|
+
.reply(200, { data: 'response' });
|
|
65
|
+
const mockNodeRequestWithRetry = jest.spyOn(node_client_1.NodeHttpClient.prototype, 'nodeRequestWithRetry');
|
|
66
|
+
const response = yield nodeClient.get('/vault/v1/kv', {});
|
|
67
|
+
expect(mockNodeRequestWithRetry).toHaveBeenCalledTimes(1);
|
|
68
|
+
expect(yield response.toJSON()).toEqual({ data: 'response' });
|
|
69
|
+
}));
|
|
70
|
+
it('post for Vault path should call nodeRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
(0, nock_1.default)('https://test.workos.com')
|
|
72
|
+
.post('/vault/v1/kv')
|
|
73
|
+
.reply(200, { data: 'response' });
|
|
74
|
+
const mockNodeRequestWithRetry = jest.spyOn(node_client_1.NodeHttpClient.prototype, 'nodeRequestWithRetry');
|
|
75
|
+
const response = yield nodeClient.post('/vault/v1/kv', {}, {});
|
|
76
|
+
expect(mockNodeRequestWithRetry).toHaveBeenCalledTimes(1);
|
|
77
|
+
expect(yield response.toJSON()).toEqual({ data: 'response' });
|
|
78
|
+
}));
|
|
79
|
+
it('put for Vault path should call nodeRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
(0, nock_1.default)('https://test.workos.com')
|
|
81
|
+
.put('/vault/v1/kv/secret')
|
|
82
|
+
.reply(200, { data: 'response' });
|
|
83
|
+
const mockNodeRequestWithRetry = jest.spyOn(node_client_1.NodeHttpClient.prototype, 'nodeRequestWithRetry');
|
|
84
|
+
const response = yield nodeClient.put('/vault/v1/kv/secret', {}, {});
|
|
85
|
+
expect(mockNodeRequestWithRetry).toHaveBeenCalledTimes(1);
|
|
86
|
+
expect(yield response.toJSON()).toEqual({ data: 'response' });
|
|
87
|
+
}));
|
|
88
|
+
it('delete for Vault path should call nodeRequestWithRetry and return response', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
(0, nock_1.default)('https://test.workos.com')
|
|
90
|
+
.delete('/vault/v1/kv/secret')
|
|
91
|
+
.reply(200, { data: 'response' });
|
|
92
|
+
const mockNodeRequestWithRetry = jest.spyOn(node_client_1.NodeHttpClient.prototype, 'nodeRequestWithRetry');
|
|
93
|
+
const response = yield nodeClient.delete('/vault/v1/kv/secret', {});
|
|
94
|
+
expect(mockNodeRequestWithRetry).toHaveBeenCalledTimes(1);
|
|
95
|
+
expect(yield response.toJSON()).toEqual({ data: 'response' });
|
|
96
|
+
}));
|
|
61
97
|
it('should retry request on 500 status code', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
98
|
(0, nock_1.default)('https://test.workos.com')
|
|
63
99
|
.get('/fga/v1/resources')
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type WidgetScope = 'widgets:users-table:manage' | 'widgets:sso:manage' | 'widgets:domain-verification:manage';
|
|
1
|
+
export type WidgetScope = 'widgets:users-table:manage' | 'widgets:sso:manage' | 'widgets:domain-verification:manage' | 'widgets:api-keys:manage';
|
|
2
2
|
export interface GetTokenOptions {
|
|
3
3
|
organizationId: string;
|
|
4
4
|
userId?: string;
|
package/lib/workos.js
CHANGED
|
@@ -33,7 +33,7 @@ const actions_1 = require("./actions/actions");
|
|
|
33
33
|
const vault_1 = require("./vault/vault");
|
|
34
34
|
const conflict_exception_1 = require("./common/exceptions/conflict.exception");
|
|
35
35
|
const parse_error_1 = require("./common/exceptions/parse-error");
|
|
36
|
-
const VERSION = '7.72.
|
|
36
|
+
const VERSION = '7.72.2';
|
|
37
37
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
38
38
|
const HEADER_AUTHORIZATION = 'Authorization';
|
|
39
39
|
const HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';
|
package/package.json
CHANGED