@workos-inc/node 7.30.1 → 7.31.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.
@@ -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 @@
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
+ });
@@ -16,7 +16,6 @@ const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
16
16
  const test_utils_1 = require("../common/utils/test-utils");
17
17
  const workos_1 = require("../workos");
18
18
  const interfaces_1 = require("./interfaces");
19
- const exceptions_1 = require("../common/exceptions");
20
19
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
21
20
  describe('FGA', () => {
22
21
  beforeEach(() => jest_fetch_mock_1.default.resetMocks());
@@ -47,60 +46,6 @@ describe('FGA', () => {
47
46
  isImplicit: false,
48
47
  });
49
48
  }));
50
- it('makes check request after one retry', () => __awaiter(void 0, void 0, void 0, function* () {
51
- (0, test_utils_1.fetchOnce)({}, {
52
- status: 500,
53
- });
54
- (0, test_utils_1.fetchOnce)({
55
- result: 'authorized',
56
- is_implicit: false,
57
- });
58
- const checkResult = yield workos.fga.check({
59
- checks: [
60
- {
61
- resource: {
62
- resourceType: 'role',
63
- resourceId: 'admin',
64
- },
65
- relation: 'member',
66
- subject: {
67
- resourceType: 'user',
68
- resourceId: 'user_123',
69
- },
70
- },
71
- ],
72
- });
73
- expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/check');
74
- expect(checkResult).toMatchObject({
75
- result: 'authorized',
76
- isImplicit: false,
77
- });
78
- }));
79
- it('fails check request after max retries', () => __awaiter(void 0, void 0, void 0, function* () {
80
- jest_fetch_mock_1.default.mockResponse(JSON.stringify({
81
- message: 'Internal Server Error',
82
- }), { status: 500 });
83
- try {
84
- yield workos.fga.check({
85
- checks: [
86
- {
87
- resource: {
88
- resourceType: 'role',
89
- resourceId: 'admin',
90
- },
91
- relation: 'member',
92
- subject: {
93
- resourceType: 'user',
94
- resourceId: 'user_123',
95
- },
96
- },
97
- ],
98
- });
99
- }
100
- catch (e) {
101
- expect(e).toBeInstanceOf(exceptions_1.GenericServerException);
102
- }
103
- }), 8000);
104
49
  });
105
50
  describe('createResource', () => {
106
51
  it('creates resource', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -120,42 +65,6 @@ describe('FGA', () => {
120
65
  resourceId: 'admin',
121
66
  });
122
67
  }));
123
- it('creates resource after one retry', () => __awaiter(void 0, void 0, void 0, function* () {
124
- (0, test_utils_1.fetchOnce)({}, {
125
- status: 502,
126
- });
127
- (0, test_utils_1.fetchOnce)({
128
- resource_type: 'role',
129
- resource_id: 'admin',
130
- });
131
- const resource = yield workos.fga.createResource({
132
- resource: {
133
- resourceType: 'role',
134
- resourceId: 'admin',
135
- },
136
- });
137
- expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/resources');
138
- expect(resource).toMatchObject({
139
- resourceType: 'role',
140
- resourceId: 'admin',
141
- });
142
- }));
143
- it('fails to creates resource after max retries', () => __awaiter(void 0, void 0, void 0, function* () {
144
- jest_fetch_mock_1.default.mockResponse(JSON.stringify({
145
- message: 'Internal Server Error',
146
- }), { status: 500 });
147
- try {
148
- yield workos.fga.createResource({
149
- resource: {
150
- resourceType: 'role',
151
- resourceId: 'admin',
152
- },
153
- });
154
- }
155
- catch (e) {
156
- expect(e).toBeInstanceOf(exceptions_1.GenericServerException);
157
- }
158
- }), 8000);
159
68
  it('creates resource with metadata', () => __awaiter(void 0, void 0, void 0, function* () {
160
69
  (0, test_utils_1.fetchOnce)({
161
70
  resource_type: 'role',
@@ -199,38 +108,6 @@ describe('FGA', () => {
199
108
  resourceId: 'admin',
200
109
  });
201
110
  }));
202
- it('gets resource after one retry', () => __awaiter(void 0, void 0, void 0, function* () {
203
- (0, test_utils_1.fetchOnce)({}, {
204
- status: 504,
205
- });
206
- (0, test_utils_1.fetchOnce)({
207
- resource_type: 'role',
208
- resource_id: 'admin',
209
- });
210
- const resource = yield workos.fga.getResource({
211
- resourceType: 'role',
212
- resourceId: 'admin',
213
- });
214
- expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/resources/role/admin');
215
- expect(resource).toMatchObject({
216
- resourceType: 'role',
217
- resourceId: 'admin',
218
- });
219
- }));
220
- it('fails to get resource after max retries', () => __awaiter(void 0, void 0, void 0, function* () {
221
- jest_fetch_mock_1.default.mockResponse(JSON.stringify({
222
- message: 'Internal Server Error',
223
- }), { status: 500 });
224
- try {
225
- yield workos.fga.getResource({
226
- resourceType: 'role',
227
- resourceId: 'admin',
228
- });
229
- }
230
- catch (e) {
231
- expect(e).toBeInstanceOf(exceptions_1.GenericServerException);
232
- }
233
- }), 8000);
234
111
  });
235
112
  describe('listResources', () => {
236
113
  it('lists resources', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -263,53 +140,6 @@ describe('FGA', () => {
263
140
  },
264
141
  ]);
265
142
  }));
266
- it('lists resources after two retries', () => __awaiter(void 0, void 0, void 0, function* () {
267
- (0, test_utils_1.fetchOnce)({}, {
268
- status: 502,
269
- });
270
- (0, test_utils_1.fetchOnce)({}, {
271
- status: 500,
272
- });
273
- (0, test_utils_1.fetchOnce)({
274
- data: [
275
- {
276
- resource_type: 'role',
277
- resource_id: 'admin',
278
- },
279
- {
280
- resource_type: 'role',
281
- resource_id: 'manager',
282
- },
283
- ],
284
- list_metadata: {
285
- before: null,
286
- after: null,
287
- },
288
- });
289
- const { data: resources } = yield workos.fga.listResources();
290
- expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/resources');
291
- expect(resources).toMatchObject([
292
- {
293
- resourceType: 'role',
294
- resourceId: 'admin',
295
- },
296
- {
297
- resourceType: 'role',
298
- resourceId: 'manager',
299
- },
300
- ]);
301
- }));
302
- it('fails to list resources after max retries', () => __awaiter(void 0, void 0, void 0, function* () {
303
- jest_fetch_mock_1.default.mockResponse(JSON.stringify({
304
- message: 'Internal Server Error',
305
- }), { status: 500 });
306
- try {
307
- yield workos.fga.listResources();
308
- }
309
- catch (e) {
310
- expect(e).toBeInstanceOf(exceptions_1.GenericServerException);
311
- }
312
- }), 8000);
313
143
  it('sends correct params when filtering', () => __awaiter(void 0, void 0, void 0, function* () {
314
144
  (0, test_utils_1.fetchOnce)({
315
145
  data: [
@@ -347,32 +177,6 @@ describe('FGA', () => {
347
177
  expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/resources/role/admin');
348
178
  expect(response).toBeUndefined();
349
179
  }));
350
- it('should delete resource after one retry', () => __awaiter(void 0, void 0, void 0, function* () {
351
- (0, test_utils_1.fetchOnce)({}, {
352
- status: 500,
353
- });
354
- (0, test_utils_1.fetchOnce)();
355
- const response = yield workos.fga.deleteResource({
356
- resourceType: 'role',
357
- resourceId: 'admin',
358
- });
359
- expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/resources/role/admin');
360
- expect(response).toBeUndefined();
361
- }));
362
- it('fails to delete resource after max retries', () => __awaiter(void 0, void 0, void 0, function* () {
363
- jest_fetch_mock_1.default.mockResponse(JSON.stringify({
364
- message: 'Internal Server Error',
365
- }), { status: 500 });
366
- try {
367
- yield workos.fga.deleteResource({
368
- resourceType: 'role',
369
- resourceId: 'admin',
370
- });
371
- }
372
- catch (e) {
373
- expect(e).toBeInstanceOf(exceptions_1.GenericServerException);
374
- }
375
- }), 8000);
376
180
  });
377
181
  describe('batchWriteResources', () => {
378
182
  it('batch create resources', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -440,110 +244,6 @@ describe('FGA', () => {
440
244
  },
441
245
  ]);
442
246
  }));
443
- it('batch create resources after one retry', () => __awaiter(void 0, void 0, void 0, function* () {
444
- (0, test_utils_1.fetchOnce)({}, {
445
- status: 500,
446
- });
447
- (0, test_utils_1.fetchOnce)({
448
- data: [
449
- {
450
- resource_type: 'role',
451
- resource_id: 'admin',
452
- meta: {
453
- description: 'The admin role',
454
- },
455
- },
456
- {
457
- resource_type: 'role',
458
- resource_id: 'manager',
459
- },
460
- {
461
- resource_type: 'role',
462
- resource_id: 'employee',
463
- },
464
- ],
465
- });
466
- const createdResources = yield workos.fga.batchWriteResources({
467
- op: interfaces_1.ResourceOp.Create,
468
- resources: [
469
- {
470
- resource: {
471
- resourceType: 'role',
472
- resourceId: 'admin',
473
- },
474
- meta: {
475
- description: 'The admin role',
476
- },
477
- },
478
- {
479
- resource: {
480
- resourceType: 'role',
481
- resourceId: 'manager',
482
- },
483
- },
484
- {
485
- resource: {
486
- resourceType: 'role',
487
- resourceId: 'employee',
488
- },
489
- },
490
- ],
491
- });
492
- expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/resources/batch');
493
- expect(createdResources).toMatchObject([
494
- {
495
- resourceType: 'role',
496
- resourceId: 'admin',
497
- meta: {
498
- description: 'The admin role',
499
- },
500
- },
501
- {
502
- resourceType: 'role',
503
- resourceId: 'manager',
504
- },
505
- {
506
- resourceType: 'role',
507
- resourceId: 'employee',
508
- },
509
- ]);
510
- }));
511
- it('fails to batch create resources after max retries', () => __awaiter(void 0, void 0, void 0, function* () {
512
- jest_fetch_mock_1.default.mockResponse(JSON.stringify({
513
- message: 'Internal Server Error',
514
- }), { status: 500 });
515
- try {
516
- yield workos.fga.batchWriteResources({
517
- op: interfaces_1.ResourceOp.Create,
518
- resources: [
519
- {
520
- resource: {
521
- resourceType: 'role',
522
- resourceId: 'admin',
523
- },
524
- meta: {
525
- description: 'The admin role',
526
- },
527
- },
528
- {
529
- resource: {
530
- resourceType: 'role',
531
- resourceId: 'manager',
532
- },
533
- },
534
- {
535
- resource: {
536
- resourceType: 'role',
537
- resourceId: 'employee',
538
- },
539
- },
540
- ],
541
- });
542
- }
543
- catch (e) {
544
- expect(e).toBeInstanceOf(exceptions_1.GenericServerException);
545
- }
546
- }), 8000);
547
247
  it('batch delete resources', () => __awaiter(void 0, void 0, void 0, function* () {
548
248
  (0, test_utils_1.fetchOnce)({
549
249
  data: [
@@ -665,62 +365,6 @@ describe('FGA', () => {
665
365
  warrantToken: 'some_token',
666
366
  });
667
367
  }));
668
- it('should create warrant after one retry', () => __awaiter(void 0, void 0, void 0, function* () {
669
- (0, test_utils_1.fetchOnce)({}, {
670
- status: 500,
671
- });
672
- (0, test_utils_1.fetchOnce)({
673
- warrant_token: 'some_token',
674
- });
675
- const warrantToken = yield workos.fga.writeWarrant({
676
- op: interfaces_1.WarrantOp.Create,
677
- resource: {
678
- resourceType: 'role',
679
- resourceId: 'admin',
680
- },
681
- relation: 'member',
682
- subject: {
683
- resourceType: 'user',
684
- resourceId: 'user_123',
685
- },
686
- });
687
- expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/warrants');
688
- expect((0, test_utils_1.fetchBody)()).toEqual({
689
- op: 'create',
690
- resource_type: 'role',
691
- resource_id: 'admin',
692
- relation: 'member',
693
- subject: {
694
- resource_type: 'user',
695
- resource_id: 'user_123',
696
- },
697
- });
698
- expect(warrantToken).toMatchObject({
699
- warrantToken: 'some_token',
700
- });
701
- }));
702
- it('fails to create warrant after max retries', () => __awaiter(void 0, void 0, void 0, function* () {
703
- jest_fetch_mock_1.default.mockResponse(JSON.stringify({
704
- message: 'Internal Server Error',
705
- }), { status: 500 });
706
- try {
707
- yield workos.fga.writeWarrant({
708
- op: interfaces_1.WarrantOp.Create,
709
- resource: {
710
- resourceType: 'role',
711
- resourceId: 'admin',
712
- },
713
- relation: 'member',
714
- subject: {
715
- resourceType: 'user',
716
- resourceId: 'user_123',
717
- },
718
- });
719
- }
720
- catch (e) {
721
- expect(e).toBeInstanceOf(exceptions_1.GenericServerException);
722
- }
723
- }), 8000);
724
368
  it('should delete warrant with delete op', () => __awaiter(void 0, void 0, void 0, function* () {
725
369
  (0, test_utils_1.fetchOnce)({
726
370
  warrant_token: 'some_token',
@@ -831,133 +475,6 @@ describe('FGA', () => {
831
475
  warrantToken: 'some_token',
832
476
  });
833
477
  }));
834
- it('should batch write warrants after one retry', () => __awaiter(void 0, void 0, void 0, function* () {
835
- (0, test_utils_1.fetchOnce)({}, {
836
- status: 500,
837
- });
838
- (0, test_utils_1.fetchOnce)({
839
- warrant_token: 'some_token',
840
- });
841
- const warrantToken = yield workos.fga.batchWriteWarrants([
842
- {
843
- resource: {
844
- resourceType: 'role',
845
- resourceId: 'admin',
846
- },
847
- relation: 'member',
848
- subject: {
849
- resourceType: 'user',
850
- resourceId: 'user_123',
851
- },
852
- },
853
- {
854
- op: interfaces_1.WarrantOp.Create,
855
- resource: {
856
- resourceType: 'role',
857
- resourceId: 'admin',
858
- },
859
- relation: 'member',
860
- subject: {
861
- resourceType: 'user',
862
- resourceId: 'user_124',
863
- },
864
- },
865
- {
866
- op: interfaces_1.WarrantOp.Delete,
867
- resource: {
868
- resourceType: 'role',
869
- resourceId: 'admin',
870
- },
871
- relation: 'member',
872
- subject: {
873
- resourceType: 'user',
874
- resourceId: 'user_125',
875
- },
876
- },
877
- ]);
878
- expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/warrants');
879
- expect((0, test_utils_1.fetchBody)()).toEqual([
880
- {
881
- resource_type: 'role',
882
- resource_id: 'admin',
883
- relation: 'member',
884
- subject: {
885
- resource_type: 'user',
886
- resource_id: 'user_123',
887
- },
888
- },
889
- {
890
- op: 'create',
891
- resource_type: 'role',
892
- resource_id: 'admin',
893
- relation: 'member',
894
- subject: {
895
- resource_type: 'user',
896
- resource_id: 'user_124',
897
- },
898
- },
899
- {
900
- op: 'delete',
901
- resource_type: 'role',
902
- resource_id: 'admin',
903
- relation: 'member',
904
- subject: {
905
- resource_type: 'user',
906
- resource_id: 'user_125',
907
- },
908
- },
909
- ]);
910
- expect(warrantToken).toMatchObject({
911
- warrantToken: 'some_token',
912
- });
913
- }));
914
- it('fails to batch write warrants after max retries', () => __awaiter(void 0, void 0, void 0, function* () {
915
- jest_fetch_mock_1.default.mockResponse(JSON.stringify({
916
- message: 'Internal Server Error',
917
- }), { status: 500 });
918
- try {
919
- yield workos.fga.batchWriteWarrants([
920
- {
921
- resource: {
922
- resourceType: 'role',
923
- resourceId: 'admin',
924
- },
925
- relation: 'member',
926
- subject: {
927
- resourceType: 'user',
928
- resourceId: 'user_123',
929
- },
930
- },
931
- {
932
- op: interfaces_1.WarrantOp.Create,
933
- resource: {
934
- resourceType: 'role',
935
- resourceId: 'admin',
936
- },
937
- relation: 'member',
938
- subject: {
939
- resourceType: 'user',
940
- resourceId: 'user_124',
941
- },
942
- },
943
- {
944
- op: interfaces_1.WarrantOp.Delete,
945
- resource: {
946
- resourceType: 'role',
947
- resourceId: 'admin',
948
- },
949
- relation: 'member',
950
- subject: {
951
- resourceType: 'user',
952
- resourceId: 'user_125',
953
- },
954
- },
955
- ]);
956
- }
957
- catch (e) {
958
- expect(e).toBeInstanceOf(exceptions_1.GenericServerException);
959
- }
960
- }), 8000);
961
478
  });
962
479
  describe('listWarrants', () => {
963
480
  it('should list warrants', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -1012,72 +529,6 @@ describe('FGA', () => {
1012
529
  },
1013
530
  ]);
1014
531
  }));
1015
- it('should list warrants after one retry', () => __awaiter(void 0, void 0, void 0, function* () {
1016
- (0, test_utils_1.fetchOnce)({}, {
1017
- status: 500,
1018
- });
1019
- (0, test_utils_1.fetchOnce)({
1020
- data: [
1021
- {
1022
- resource_type: 'role',
1023
- resource_id: 'admin',
1024
- relation: 'member',
1025
- subject: {
1026
- resource_type: 'user',
1027
- resource_id: 'user_123',
1028
- },
1029
- },
1030
- {
1031
- resource_type: 'role',
1032
- resource_id: 'admin',
1033
- relation: 'member',
1034
- subject: {
1035
- resource_type: 'user',
1036
- resource_id: 'user_124',
1037
- },
1038
- policy: 'region == "us"',
1039
- },
1040
- ],
1041
- list_metadata: {
1042
- before: null,
1043
- after: null,
1044
- },
1045
- });
1046
- const { data: warrants } = yield workos.fga.listWarrants();
1047
- expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/warrants');
1048
- expect(warrants).toMatchObject([
1049
- {
1050
- resourceType: 'role',
1051
- resourceId: 'admin',
1052
- relation: 'member',
1053
- subject: {
1054
- resourceType: 'user',
1055
- resourceId: 'user_123',
1056
- },
1057
- },
1058
- {
1059
- resourceType: 'role',
1060
- resourceId: 'admin',
1061
- relation: 'member',
1062
- subject: {
1063
- resourceType: 'user',
1064
- resourceId: 'user_124',
1065
- },
1066
- policy: 'region == "us"',
1067
- },
1068
- ]);
1069
- }));
1070
- it('fails to list warrants after max retries', () => __awaiter(void 0, void 0, void 0, function* () {
1071
- jest_fetch_mock_1.default.mockResponse(JSON.stringify({
1072
- message: 'Internal Server Error',
1073
- }), { status: 500 });
1074
- try {
1075
- yield workos.fga.listWarrants();
1076
- }
1077
- catch (e) {
1078
- expect(e).toBeInstanceOf(exceptions_1.GenericServerException);
1079
- }
1080
- }), 8000);
1081
532
  it('sends correct params when filtering', () => __awaiter(void 0, void 0, void 0, function* () {
1082
533
  (0, test_utils_1.fetchOnce)({
1083
534
  data: [
@@ -1153,66 +604,6 @@ describe('FGA', () => {
1153
604
  },
1154
605
  ]);
1155
606
  }));
1156
- it('makes query request after one retry', () => __awaiter(void 0, void 0, void 0, function* () {
1157
- (0, test_utils_1.fetchOnce)({}, {
1158
- status: 500,
1159
- });
1160
- (0, test_utils_1.fetchOnce)({
1161
- data: [
1162
- {
1163
- resource_type: 'role',
1164
- resource_id: 'admin',
1165
- warrant: {
1166
- resource_type: 'role',
1167
- resource_id: 'admin',
1168
- relation: 'member',
1169
- subject: {
1170
- resource_type: 'user',
1171
- resource_id: 'user_123',
1172
- },
1173
- },
1174
- is_implicit: false,
1175
- },
1176
- ],
1177
- list_metadata: {
1178
- before: null,
1179
- after: null,
1180
- },
1181
- });
1182
- const { data: queryResults } = yield workos.fga.query({
1183
- q: 'select role where user:user_123 is member',
1184
- });
1185
- expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/query');
1186
- expect(queryResults).toMatchObject([
1187
- {
1188
- resourceType: 'role',
1189
- resourceId: 'admin',
1190
- warrant: {
1191
- resourceType: 'role',
1192
- resourceId: 'admin',
1193
- relation: 'member',
1194
- subject: {
1195
- resourceType: 'user',
1196
- resourceId: 'user_123',
1197
- },
1198
- },
1199
- isImplicit: false,
1200
- },
1201
- ]);
1202
- }));
1203
- it('fails to make query after max retries', () => __awaiter(void 0, void 0, void 0, function* () {
1204
- jest_fetch_mock_1.default.mockResponse(JSON.stringify({
1205
- message: 'Internal Server Error',
1206
- }), { status: 500 });
1207
- try {
1208
- yield workos.fga.query({
1209
- q: 'select role where user:user_123 is member',
1210
- });
1211
- }
1212
- catch (e) {
1213
- expect(e).toBeInstanceOf(exceptions_1.GenericServerException);
1214
- }
1215
- }), 8000);
1216
607
  it('sends correct params and options', () => __awaiter(void 0, void 0, void 0, function* () {
1217
608
  (0, test_utils_1.fetchOnce)({
1218
609
  data: [
@@ -1,7 +1,6 @@
1
1
  import { AutoPaginatable } from '../common/utils/pagination';
2
2
  import { WorkOS } from '../workos';
3
3
  import { CreateOrganizationOptions, CreateOrganizationRequestOptions, ListOrganizationsOptions, Organization, UpdateOrganizationOptions } from './interfaces';
4
- import { SetStripeCustomerIdOptions } from './interfaces/set-stripe-customer-id-options.interface';
5
4
  export declare class Organizations {
6
5
  private readonly workos;
7
6
  constructor(workos: WorkOS);
@@ -10,6 +9,4 @@ export declare class Organizations {
10
9
  deleteOrganization(id: string): Promise<void>;
11
10
  getOrganization(id: string): Promise<Organization>;
12
11
  updateOrganization(options: UpdateOrganizationOptions): Promise<Organization>;
13
- setStripeCustomerId(options: SetStripeCustomerIdOptions): Promise<string | undefined>;
14
- getStripeCustomerId(id: string): Promise<string | undefined>;
15
12
  }
@@ -57,17 +57,5 @@ class Organizations {
57
57
  return (0, serializers_1.deserializeOrganization)(data);
58
58
  });
59
59
  }
60
- setStripeCustomerId(options) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- const updatedOrganization = yield this.updateOrganization(options);
63
- return updatedOrganization.stripeCustomerId;
64
- });
65
- }
66
- getStripeCustomerId(id) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const organization = yield this.getOrganization(id);
69
- return organization.stripeCustomerId;
70
- });
71
- }
72
60
  }
73
61
  exports.Organizations = Organizations;
@@ -19,7 +19,6 @@ const clear_stripe_customer_id_json_1 = __importDefault(require("./fixtures/clea
19
19
  const create_organization_invalid_json_1 = __importDefault(require("./fixtures/create-organization-invalid.json"));
20
20
  const create_organization_json_1 = __importDefault(require("./fixtures/create-organization.json"));
21
21
  const get_organization_json_1 = __importDefault(require("./fixtures/get-organization.json"));
22
- const get_stripe_customer_id_json_1 = __importDefault(require("./fixtures/get-stripe-customer-id.json"));
23
22
  const list_organizations_json_1 = __importDefault(require("./fixtures/list-organizations.json"));
24
23
  const update_organization_json_1 = __importDefault(require("./fixtures/update-organization.json"));
25
24
  const set_stripe_customer_id_json_1 = __importDefault(require("./fixtures/set-stripe-customer-id.json"));
@@ -239,33 +238,7 @@ describe('Organizations', () => {
239
238
  }));
240
239
  });
241
240
  });
242
- });
243
- describe('setStripeCustomerId', () => {
244
- describe('with a valid payload', () => {
245
- it('updates the organization’s Stripe customer ID', () => __awaiter(void 0, void 0, void 0, function* () {
246
- (0, test_utils_1.fetchOnce)(set_stripe_customer_id_json_1.default);
247
- const subject = yield workos.organizations.setStripeCustomerId({
248
- organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
249
- stripeCustomerId: 'cus_MX8J9nfK4lP2Yw',
250
- });
251
- expect((0, test_utils_1.fetchBody)()).toEqual({
252
- stripe_customer_id: 'cus_MX8J9nfK4lP2Yw',
253
- });
254
- expect(subject).toBe('cus_MX8J9nfK4lP2Yw');
255
- }));
256
- it('clears the organization’s Stripe customer ID with a `null` value', () => __awaiter(void 0, void 0, void 0, function* () {
257
- (0, test_utils_1.fetchOnce)(clear_stripe_customer_id_json_1.default);
258
- const subject = yield workos.organizations.setStripeCustomerId({
259
- organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
260
- stripeCustomerId: null,
261
- });
262
- expect((0, test_utils_1.fetchBody)()).toEqual({
263
- stripe_customer_id: null,
264
- });
265
- expect(subject).toBeUndefined();
266
- }));
267
- });
268
- describe('when set via `updateOrganization`', () => {
241
+ describe('when given `stripeCustomerId`', () => {
269
242
  it('updates the organization’s Stripe customer ID', () => __awaiter(void 0, void 0, void 0, function* () {
270
243
  (0, test_utils_1.fetchOnce)(set_stripe_customer_id_json_1.default);
271
244
  const subject = yield workos.organizations.updateOrganization({
@@ -288,29 +261,18 @@ describe('Organizations', () => {
288
261
  });
289
262
  expect(subject.stripeCustomerId).toBeUndefined();
290
263
  }));
291
- });
292
- describe('when the feature is not enabled', () => {
293
- it('returns an error', () => __awaiter(void 0, void 0, void 0, function* () {
294
- (0, test_utils_1.fetchOnce)(set_stripe_customer_id_disabled_json_1.default, { status: 422 });
295
- yield expect(workos.organizations.setStripeCustomerId({
296
- organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
297
- stripeCustomerId: 'cus_MX8J9nfK4lP2Yw',
298
- })).rejects.toThrowError('stripe_customer_id is not enabled for this environment');
299
- expect((0, test_utils_1.fetchBody)()).toEqual({
300
- stripe_customer_id: 'cus_MX8J9nfK4lP2Yw',
301
- });
302
- }));
303
- });
304
- });
305
- describe('getStripeCustomerId', () => {
306
- it('returns the organization’s Stripe customer ID', () => __awaiter(void 0, void 0, void 0, function* () {
307
- (0, test_utils_1.fetchOnce)(get_stripe_customer_id_json_1.default);
308
- const subject = yield workos.organizations.setStripeCustomerId({
309
- organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
310
- stripeCustomerId: null,
264
+ describe('when the feature is not enabled', () => {
265
+ it('returns an error', () => __awaiter(void 0, void 0, void 0, function* () {
266
+ (0, test_utils_1.fetchOnce)(set_stripe_customer_id_disabled_json_1.default, { status: 422 });
267
+ yield expect(workos.organizations.updateOrganization({
268
+ organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
269
+ stripeCustomerId: 'cus_MX8J9nfK4lP2Yw',
270
+ })).rejects.toThrowError('stripe_customer_id is not enabled for this environment');
271
+ expect((0, test_utils_1.fetchBody)()).toEqual({
272
+ stripe_customer_id: 'cus_MX8J9nfK4lP2Yw',
273
+ });
274
+ }));
311
275
  });
312
- expect((0, test_utils_1.fetchURL)()).toContain('/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T');
313
- expect(subject).toEqual('cus_MX8J9nfK4lP2Yw');
314
- }));
276
+ });
315
277
  });
316
278
  });
@@ -1,4 +1,5 @@
1
1
  import { Impersonator, ImpersonatorResponse } from './impersonator.interface';
2
+ import { OauthTokens, OauthTokensResponse } from './oauth-tokens.interface';
2
3
  import { User, UserResponse } from './user.interface';
3
4
  type AuthenticationMethod = 'SSO' | 'Password' | 'AppleOAuth' | 'GitHubOAuth' | 'GoogleOAuth' | 'MicrosoftOAuth' | 'MagicAuth' | 'Impersonation';
4
5
  export interface AuthenticationResponse {
@@ -9,6 +10,7 @@ export interface AuthenticationResponse {
9
10
  impersonator?: Impersonator;
10
11
  authenticationMethod?: AuthenticationMethod;
11
12
  sealedSession?: string;
13
+ oauthTokens?: OauthTokens;
12
14
  }
13
15
  export interface AuthenticationResponseResponse {
14
16
  user: UserResponse;
@@ -17,5 +19,6 @@ export interface AuthenticationResponseResponse {
17
19
  refresh_token: string;
18
20
  impersonator?: ImpersonatorResponse;
19
21
  authentication_method?: AuthenticationMethod;
22
+ oauth_tokens?: OauthTokensResponse;
20
23
  }
21
24
  export {};
@@ -1,6 +1,3 @@
1
- export * from './authentication-event.interface';
2
- export * from './authenticate-with-magic-auth-options.interface';
3
- export * from './authenticate-with-password-options.interface';
4
1
  export * from './authenticate-with-code-options.interface';
5
2
  export * from './authenticate-with-email-verification-options.interface';
6
3
  export * from './authenticate-with-magic-auth-options.interface';
@@ -10,6 +7,7 @@ export * from './authenticate-with-password-options.interface';
10
7
  export * from './authenticate-with-refresh-token-options.interface';
11
8
  export * from './authenticate-with-session-cookie.interface';
12
9
  export * from './authenticate-with-totp-options.interface';
10
+ export * from './authentication-event.interface';
13
11
  export * from './authentication-response.interface';
14
12
  export * from './create-magic-auth-options.interface';
15
13
  export * from './create-organization-membership-options.interface';
@@ -25,6 +23,7 @@ export * from './list-invitations-options.interface';
25
23
  export * from './list-organization-memberships-options.interface';
26
24
  export * from './list-users-options.interface';
27
25
  export * from './magic-auth.interface';
26
+ export * from './oauth-tokens.interface';
28
27
  export * from './organization-membership.interface';
29
28
  export * from './password-reset.interface';
30
29
  export * from './refresh-and-seal-session-data.interface';
@@ -14,9 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./authentication-event.interface"), exports);
18
- __exportStar(require("./authenticate-with-magic-auth-options.interface"), exports);
19
- __exportStar(require("./authenticate-with-password-options.interface"), exports);
20
17
  __exportStar(require("./authenticate-with-code-options.interface"), exports);
21
18
  __exportStar(require("./authenticate-with-email-verification-options.interface"), exports);
22
19
  __exportStar(require("./authenticate-with-magic-auth-options.interface"), exports);
@@ -26,6 +23,7 @@ __exportStar(require("./authenticate-with-password-options.interface"), exports)
26
23
  __exportStar(require("./authenticate-with-refresh-token-options.interface"), exports);
27
24
  __exportStar(require("./authenticate-with-session-cookie.interface"), exports);
28
25
  __exportStar(require("./authenticate-with-totp-options.interface"), exports);
26
+ __exportStar(require("./authentication-event.interface"), exports);
29
27
  __exportStar(require("./authentication-response.interface"), exports);
30
28
  __exportStar(require("./create-magic-auth-options.interface"), exports);
31
29
  __exportStar(require("./create-organization-membership-options.interface"), exports);
@@ -41,6 +39,7 @@ __exportStar(require("./list-invitations-options.interface"), exports);
41
39
  __exportStar(require("./list-organization-memberships-options.interface"), exports);
42
40
  __exportStar(require("./list-users-options.interface"), exports);
43
41
  __exportStar(require("./magic-auth.interface"), exports);
42
+ __exportStar(require("./oauth-tokens.interface"), exports);
44
43
  __exportStar(require("./organization-membership.interface"), exports);
45
44
  __exportStar(require("./password-reset.interface"), exports);
46
45
  __exportStar(require("./refresh-and-seal-session-data.interface"), exports);
@@ -0,0 +1,12 @@
1
+ export interface OauthTokens {
2
+ accessToken: string;
3
+ refreshToken: string;
4
+ expiresAt: number;
5
+ scopes: string[];
6
+ }
7
+ export interface OauthTokensResponse {
8
+ access_token: string;
9
+ refresh_token: string;
10
+ expires_at: number;
11
+ scopes: string[];
12
+ }
@@ -12,9 +12,10 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.deserializeAuthenticationResponse = void 0;
15
+ const oauth_tokens_serializer_1 = require("./oauth-tokens.serializer");
15
16
  const user_serializer_1 = require("./user.serializer");
16
17
  const deserializeAuthenticationResponse = (authenticationResponse) => {
17
- const { user, organization_id, access_token, refresh_token, authentication_method, impersonator } = authenticationResponse, rest = __rest(authenticationResponse, ["user", "organization_id", "access_token", "refresh_token", "authentication_method", "impersonator"]);
18
- return Object.assign({ user: (0, user_serializer_1.deserializeUser)(user), organizationId: organization_id, accessToken: access_token, refreshToken: refresh_token, impersonator, authenticationMethod: authentication_method }, rest);
18
+ const { user, organization_id, access_token, refresh_token, authentication_method, impersonator, oauth_tokens } = authenticationResponse, rest = __rest(authenticationResponse, ["user", "organization_id", "access_token", "refresh_token", "authentication_method", "impersonator", "oauth_tokens"]);
19
+ return Object.assign({ user: (0, user_serializer_1.deserializeUser)(user), organizationId: organization_id, accessToken: access_token, refreshToken: refresh_token, impersonator, authenticationMethod: authentication_method, oauthTokens: (0, oauth_tokens_serializer_1.deserializeOauthTokens)(oauth_tokens) }, rest);
19
20
  };
20
21
  exports.deserializeAuthenticationResponse = deserializeAuthenticationResponse;
@@ -0,0 +1,2 @@
1
+ import { OauthTokensResponse, OauthTokens } from '../interfaces';
2
+ export declare const deserializeOauthTokens: (oauthTokens?: OauthTokensResponse) => OauthTokens | undefined;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeOauthTokens = void 0;
4
+ const deserializeOauthTokens = (oauthTokens) => oauthTokens
5
+ ? {
6
+ accessToken: oauthTokens.access_token,
7
+ refreshToken: oauthTokens.refresh_token,
8
+ expiresAt: oauthTokens.expires_at,
9
+ scopes: oauthTokens.scopes,
10
+ }
11
+ : undefined;
12
+ exports.deserializeOauthTokens = deserializeOauthTokens;
@@ -374,6 +374,34 @@ describe('UserManagement', () => {
374
374
  }));
375
375
  });
376
376
  });
377
+ describe('when oauth_tokens is present', () => {
378
+ it('deserializes oauth_tokens', () => __awaiter(void 0, void 0, void 0, function* () {
379
+ (0, test_utils_1.fetchOnce)({
380
+ user: user_json_1.default,
381
+ oauth_tokens: {
382
+ access_token: 'access_token',
383
+ refresh_token: 'refresh',
384
+ expires_at: 123,
385
+ scopes: ['read:users'],
386
+ },
387
+ });
388
+ const resp = yield workos.userManagement.authenticateWithCode({
389
+ clientId: 'proj_whatever',
390
+ code: 'or this',
391
+ });
392
+ expect(resp).toMatchObject({
393
+ user: {
394
+ email: 'test01@example.com',
395
+ },
396
+ oauthTokens: {
397
+ accessToken: 'access_token',
398
+ refreshToken: 'refresh',
399
+ expiresAt: 123,
400
+ scopes: ['read:users'],
401
+ },
402
+ });
403
+ }));
404
+ });
377
405
  });
378
406
  describe('authenticateWithRefreshToken', () => {
379
407
  it('sends a refresh_token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
package/lib/workos.js CHANGED
@@ -28,7 +28,7 @@ const http_client_1 = require("./common/net/http-client");
28
28
  const subtle_crypto_provider_1 = require("./common/crypto/subtle-crypto-provider");
29
29
  const fetch_client_1 = require("./common/net/fetch-client");
30
30
  const widgets_1 = require("./widgets/widgets");
31
- const VERSION = '7.30.1';
31
+ const VERSION = '7.31.0';
32
32
  const DEFAULT_HOSTNAME = 'api.workos.com';
33
33
  const HEADER_AUTHORIZATION = 'Authorization';
34
34
  const HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.30.1",
2
+ "version": "7.31.0",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",
@@ -50,6 +50,7 @@
50
50
  "jest": "29.6.2",
51
51
  "jest-environment-miniflare": "^2.14.2",
52
52
  "jest-fetch-mock": "^3.0.3",
53
+ "nock": "^13.5.5",
53
54
  "prettier": "2.8.8",
54
55
  "supertest": "6.3.3",
55
56
  "ts-jest": "29.1.3",
@@ -1,17 +0,0 @@
1
- {
2
- "name": "Test Organization 3",
3
- "object": "organization",
4
- "id": "org_01EHT88Z8J8795GZNQ4ZP1J81T",
5
- "allow_profiles_outside_organization": false,
6
- "domains": [
7
- {
8
- "domain": "example.com",
9
- "object": "organization_domain",
10
- "id": "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8",
11
- "state": "verified",
12
- "verification_strategy": "dns",
13
- "verification_token": "xB8SeACdKJQP9DP4CahU4YuQZ"
14
- }
15
- ],
16
- "stripe_customer_id": "cus_MX8J9nfK4lP2Yw"
17
- }
@@ -1,4 +0,0 @@
1
- export interface SetStripeCustomerIdOptions {
2
- organization: string;
3
- stripeCustomerId: string | null;
4
- }