@workos-inc/node 7.69.1 → 7.70.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.
@@ -7,4 +7,5 @@ export interface WorkOSOptions {
7
7
  appInfo?: AppInfo;
8
8
  fetchFn?: typeof fetch;
9
9
  clientId?: string;
10
+ timeout?: number;
10
11
  }
@@ -1,10 +1,13 @@
1
1
  import { HttpClientInterface, HttpClientResponseInterface, RequestOptions, ResponseHeaders } from '../interfaces/http-client.interface';
2
2
  import { HttpClient, HttpClientResponse } from './http-client';
3
+ interface FetchHttpClientOptions extends RequestInit {
4
+ timeout?: number;
5
+ }
3
6
  export declare class FetchHttpClient extends HttpClient implements HttpClientInterface {
4
7
  readonly baseURL: string;
5
- readonly options?: RequestInit | undefined;
8
+ readonly options?: FetchHttpClientOptions | undefined;
6
9
  private readonly _fetchFn;
7
- constructor(baseURL: string, options?: RequestInit | undefined, fetchFn?: typeof fetch);
10
+ constructor(baseURL: string, options?: FetchHttpClientOptions | undefined, fetchFn?: typeof fetch);
8
11
  /** @override */
9
12
  getClientName(): string;
10
13
  get(path: string, options: RequestOptions): Promise<HttpClientResponseInterface>;
@@ -22,3 +25,4 @@ export declare class FetchHttpClientResponse extends HttpClientResponse implemen
22
25
  toJSON(): Promise<any> | null;
23
26
  static _transformHeadersToObject(headers: Headers): ResponseHeaders;
24
27
  }
28
+ export {};
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.FetchHttpClientResponse = exports.FetchHttpClient = void 0;
13
13
  const http_client_1 = require("./http-client");
14
14
  const parse_error_1 = require("../exceptions/parse-error");
15
+ const DEFAULT_FETCH_TIMEOUT = 60000; // 60 seconds
15
16
  class FetchHttpClient extends http_client_1.HttpClient {
16
17
  constructor(baseURL, options, fetchFn) {
17
18
  super(baseURL, options);
@@ -75,47 +76,82 @@ class FetchHttpClient extends http_client_1.HttpClient {
75
76
  });
76
77
  }
77
78
  fetchRequest(url, method, body, headers) {
78
- var _a, _b, _c;
79
+ var _a, _b, _c, _d, _e;
79
80
  return __awaiter(this, void 0, void 0, function* () {
80
81
  // For methods which expect payloads, we should always pass a body value
81
82
  // even when it is empty. Without this, some JS runtimes (eg. Deno) will
82
83
  // inject a second Content-Length header.
83
84
  const methodHasPayload = method === 'POST' || method === 'PUT' || method === 'PATCH';
84
85
  const requestBody = body || (methodHasPayload ? '' : undefined);
85
- const { 'User-Agent': userAgent } = (_a = this.options) === null || _a === void 0 ? void 0 : _a.headers;
86
- const res = yield this._fetchFn(url, {
87
- method,
88
- headers: Object.assign(Object.assign(Object.assign({ Accept: 'application/json, text/plain, */*', 'Content-Type': 'application/json' }, (_b = this.options) === null || _b === void 0 ? void 0 : _b.headers), headers), { 'User-Agent': this.addClientToUserAgent(userAgent.toString()) }),
89
- body: requestBody,
90
- });
91
- if (!res.ok) {
92
- const requestID = (_c = res.headers.get('X-Request-ID')) !== null && _c !== void 0 ? _c : '';
93
- const rawBody = yield res.text();
94
- let responseJson;
95
- try {
96
- responseJson = JSON.parse(rawBody);
86
+ const { 'User-Agent': userAgent } = (((_a = this.options) === null || _a === void 0 ? void 0 : _a.headers) ||
87
+ {});
88
+ // Create AbortController for timeout if configured
89
+ let abortController;
90
+ let timeoutId;
91
+ // Access timeout from the options with default of 60 seconds
92
+ const timeout = (_c = (_b = this.options) === null || _b === void 0 ? void 0 : _b.timeout) !== null && _c !== void 0 ? _c : DEFAULT_FETCH_TIMEOUT; // Default 60 seconds
93
+ abortController = new AbortController();
94
+ timeoutId = setTimeout(() => {
95
+ abortController === null || abortController === void 0 ? void 0 : abortController.abort();
96
+ }, timeout);
97
+ try {
98
+ const res = yield this._fetchFn(url, {
99
+ method,
100
+ headers: Object.assign(Object.assign(Object.assign({ Accept: 'application/json, text/plain, */*', 'Content-Type': 'application/json' }, (_d = this.options) === null || _d === void 0 ? void 0 : _d.headers), headers), { 'User-Agent': this.addClientToUserAgent((userAgent || 'workos-node').toString()) }),
101
+ body: requestBody,
102
+ signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal,
103
+ });
104
+ // Clear timeout if request completed successfully
105
+ if (timeoutId) {
106
+ clearTimeout(timeoutId);
97
107
  }
98
- catch (error) {
99
- if (error instanceof SyntaxError) {
100
- throw new parse_error_1.ParseError({
101
- message: error.message,
102
- rawBody,
103
- requestID,
104
- rawStatus: res.status,
105
- });
108
+ if (!res.ok) {
109
+ const requestID = (_e = res.headers.get('X-Request-ID')) !== null && _e !== void 0 ? _e : '';
110
+ const rawBody = yield res.text();
111
+ let responseJson;
112
+ try {
113
+ responseJson = JSON.parse(rawBody);
114
+ }
115
+ catch (error) {
116
+ if (error instanceof SyntaxError) {
117
+ throw new parse_error_1.ParseError({
118
+ message: error.message,
119
+ rawBody,
120
+ requestID,
121
+ rawStatus: res.status,
122
+ });
123
+ }
124
+ throw error;
106
125
  }
107
- throw error;
126
+ throw new http_client_1.HttpClientError({
127
+ message: res.statusText,
128
+ response: {
129
+ status: res.status,
130
+ headers: res.headers,
131
+ data: responseJson,
132
+ },
133
+ });
108
134
  }
109
- throw new http_client_1.HttpClientError({
110
- message: res.statusText,
111
- response: {
112
- status: res.status,
113
- headers: res.headers,
114
- data: responseJson,
115
- },
116
- });
135
+ return new FetchHttpClientResponse(res);
136
+ }
137
+ catch (error) {
138
+ // Clear timeout if request failed
139
+ if (timeoutId) {
140
+ clearTimeout(timeoutId);
141
+ }
142
+ // Handle timeout errors
143
+ if (error instanceof Error && error.name === 'AbortError') {
144
+ throw new http_client_1.HttpClientError({
145
+ message: `Request timeout after ${timeout}ms`,
146
+ response: {
147
+ status: 408,
148
+ headers: {},
149
+ data: { error: 'Request timeout' },
150
+ },
151
+ });
152
+ }
153
+ throw error;
117
154
  }
118
- return new FetchHttpClientResponse(res);
119
155
  });
120
156
  }
121
157
  fetchRequestWithRetry(url, method, body, headers) {
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
16
16
  const test_utils_1 = require("../../common/utils/test-utils");
17
17
  const fetch_client_1 = require("./fetch-client");
18
+ const http_client_1 = require("./http-client");
18
19
  const parse_error_1 = require("../exceptions/parse-error");
19
20
  const fetchClient = new fetch_client_1.FetchHttpClient('https://test.workos.com', {
20
21
  headers: {
@@ -205,3 +206,73 @@ describe('Fetch client', () => {
205
206
  }));
206
207
  });
207
208
  });
209
+ describe('FetchHttpClient with timeout', () => {
210
+ let client;
211
+ let mockFetch;
212
+ beforeEach(() => {
213
+ mockFetch = jest.fn();
214
+ client = new fetch_client_1.FetchHttpClient('https://api.example.com', { timeout: 100 }, mockFetch);
215
+ });
216
+ it('should timeout requests that take too long', () => __awaiter(void 0, void 0, void 0, function* () {
217
+ // Mock a fetch that respects AbortController
218
+ mockFetch.mockImplementation((_, options) => {
219
+ return new Promise((_, reject) => {
220
+ if (options.signal) {
221
+ options.signal.addEventListener('abort', () => {
222
+ const error = new Error('AbortError');
223
+ error.name = 'AbortError';
224
+ reject(error);
225
+ });
226
+ }
227
+ // Never resolve - let the timeout trigger
228
+ });
229
+ });
230
+ yield expect(client.post('/test', { data: 'test' }, {})).rejects.toThrow(http_client_1.HttpClientError);
231
+ // Reset the mock for the second test
232
+ mockFetch.mockClear();
233
+ mockFetch.mockImplementation((_, options) => {
234
+ return new Promise((_, reject) => {
235
+ if (options.signal) {
236
+ options.signal.addEventListener('abort', () => {
237
+ const error = new Error('AbortError');
238
+ error.name = 'AbortError';
239
+ reject(error);
240
+ });
241
+ }
242
+ // Never resolve - let the timeout trigger
243
+ });
244
+ });
245
+ yield expect(client.post('/test', { data: 'test' }, {})).rejects.toMatchObject({
246
+ message: 'Request timeout after 100ms',
247
+ response: {
248
+ status: 408,
249
+ data: { error: 'Request timeout' },
250
+ },
251
+ });
252
+ }));
253
+ it('should not timeout requests that complete quickly', () => __awaiter(void 0, void 0, void 0, function* () {
254
+ const mockResponse = {
255
+ ok: true,
256
+ status: 200,
257
+ headers: new Map(),
258
+ json: () => Promise.resolve({ success: true }),
259
+ text: () => Promise.resolve('{"success": true}'),
260
+ };
261
+ mockFetch.mockResolvedValue(mockResponse);
262
+ const result = yield client.post('/test', { data: 'test' }, {});
263
+ expect(result).toBeDefined();
264
+ }));
265
+ it('should work without timeout configured', () => __awaiter(void 0, void 0, void 0, function* () {
266
+ const clientWithoutTimeout = new fetch_client_1.FetchHttpClient('https://api.example.com', {}, mockFetch);
267
+ const mockResponse = {
268
+ ok: true,
269
+ status: 200,
270
+ headers: new Map(),
271
+ json: () => Promise.resolve({ success: true }),
272
+ text: () => Promise.resolve('{"success": true}'),
273
+ };
274
+ mockFetch.mockResolvedValue(mockResponse);
275
+ const result = yield clientWithoutTimeout.post('/test', { data: 'test' }, {});
276
+ expect(result).toBeDefined();
277
+ }));
278
+ });
package/lib/index.js CHANGED
@@ -43,7 +43,7 @@ class WorkOSNode extends workos_1.WorkOS {
43
43
  /** @override */
44
44
  createHttpClient(options, userAgent) {
45
45
  var _a;
46
- const opts = Object.assign(Object.assign({}, options.config), { headers: Object.assign(Object.assign({}, (_a = options.config) === null || _a === void 0 ? void 0 : _a.headers), { Authorization: `Bearer ${this.key}`, 'User-Agent': userAgent }) });
46
+ const opts = Object.assign(Object.assign({}, options.config), { timeout: options.timeout, headers: Object.assign(Object.assign({}, (_a = options.config) === null || _a === void 0 ? void 0 : _a.headers), { Authorization: `Bearer ${this.key}`, 'User-Agent': userAgent }) });
47
47
  if (typeof fetch !== 'undefined' ||
48
48
  typeof options.fetchFn !== 'undefined') {
49
49
  return new fetch_client_1.FetchHttpClient(this.baseURL, opts, options.fetchFn);
@@ -9,6 +9,7 @@ export interface AccessToken {
9
9
  sid: string;
10
10
  org_id?: string;
11
11
  role?: string;
12
+ roles?: string[];
12
13
  permissions?: string[];
13
14
  entitlements?: string[];
14
15
  feature_flags?: string[];
@@ -28,6 +29,7 @@ export type AuthenticateWithSessionCookieSuccessResponse = {
28
29
  sessionId: string;
29
30
  organizationId?: string;
30
31
  role?: string;
32
+ roles?: string[];
31
33
  permissions?: string[];
32
34
  entitlements?: string[];
33
35
  featureFlags?: string[];
@@ -2,9 +2,11 @@ export interface CreateOrganizationMembershipOptions {
2
2
  organizationId: string;
3
3
  userId: string;
4
4
  roleSlug?: string;
5
+ roleSlugs?: string[];
5
6
  }
6
7
  export interface SerializedCreateOrganizationMembershipOptions {
7
8
  organization_id: string;
8
9
  user_id: string;
9
10
  role_slug?: string;
11
+ role_slugs?: string[];
10
12
  }
@@ -10,6 +10,7 @@ export interface OrganizationMembership {
10
10
  createdAt: string;
11
11
  updatedAt: string;
12
12
  role: RoleResponse;
13
+ roles?: RoleResponse[];
13
14
  }
14
15
  export interface OrganizationMembershipResponse {
15
16
  object: 'organization_membership';
@@ -21,4 +22,5 @@ export interface OrganizationMembershipResponse {
21
22
  created_at: string;
22
23
  updated_at: string;
23
24
  role: RoleResponse;
25
+ roles?: RoleResponse[];
24
26
  }
@@ -1,6 +1,8 @@
1
1
  export interface UpdateOrganizationMembershipOptions {
2
2
  roleSlug?: string;
3
+ roleSlugs?: string[];
3
4
  }
4
5
  export interface SerializedUpdateOrganizationMembershipOptions {
5
6
  role_slug?: string;
7
+ role_slugs?: string[];
6
8
  }
@@ -5,5 +5,6 @@ const serializeCreateOrganizationMembershipOptions = (options) => ({
5
5
  organization_id: options.organizationId,
6
6
  user_id: options.userId,
7
7
  role_slug: options.roleSlug,
8
+ role_slugs: options.roleSlugs,
8
9
  });
9
10
  exports.serializeCreateOrganizationMembershipOptions = serializeCreateOrganizationMembershipOptions;
@@ -1,15 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deserializeOrganizationMembership = void 0;
4
- const deserializeOrganizationMembership = (organizationMembership) => ({
5
- object: organizationMembership.object,
6
- id: organizationMembership.id,
7
- userId: organizationMembership.user_id,
8
- organizationId: organizationMembership.organization_id,
9
- organizationName: organizationMembership.organization_name,
10
- status: organizationMembership.status,
11
- createdAt: organizationMembership.created_at,
12
- updatedAt: organizationMembership.updated_at,
13
- role: organizationMembership.role,
14
- });
4
+ const deserializeOrganizationMembership = (organizationMembership) => (Object.assign({ object: organizationMembership.object, id: organizationMembership.id, userId: organizationMembership.user_id, organizationId: organizationMembership.organization_id, organizationName: organizationMembership.organization_name, status: organizationMembership.status, createdAt: organizationMembership.created_at, updatedAt: organizationMembership.updated_at, role: organizationMembership.role }, (organizationMembership.roles && { roles: organizationMembership.roles })));
15
5
  exports.deserializeOrganizationMembership = deserializeOrganizationMembership;
@@ -3,5 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.serializeUpdateOrganizationMembershipOptions = void 0;
4
4
  const serializeUpdateOrganizationMembershipOptions = (options) => ({
5
5
  role_slug: options.roleSlug,
6
+ role_slugs: options.roleSlugs,
6
7
  });
7
8
  exports.serializeUpdateOrganizationMembershipOptions = serializeUpdateOrganizationMembershipOptions;
@@ -61,12 +61,13 @@ class CookieSession {
61
61
  reason: interfaces_1.AuthenticateWithSessionCookieFailureReason.INVALID_JWT,
62
62
  };
63
63
  }
64
- const { sid: sessionId, org_id: organizationId, role, permissions, entitlements, feature_flags: featureFlags, } = (0, jose_1.decodeJwt)(session.accessToken);
64
+ const { sid: sessionId, org_id: organizationId, role, roles, permissions, entitlements, feature_flags: featureFlags, } = (0, jose_1.decodeJwt)(session.accessToken);
65
65
  return {
66
66
  authenticated: true,
67
67
  sessionId,
68
68
  organizationId,
69
69
  role,
70
+ roles,
70
71
  permissions,
71
72
  entitlements,
72
73
  featureFlags,
@@ -114,7 +115,7 @@ class CookieSession {
114
115
  this.cookiePassword = options.cookiePassword;
115
116
  }
116
117
  this.sessionData = authenticationResponse.sealedSession;
117
- const { sid: sessionId, org_id: organizationId, role, permissions, entitlements, feature_flags: featureFlags, } = (0, jose_1.decodeJwt)(authenticationResponse.accessToken);
118
+ const { sid: sessionId, org_id: organizationId, role, roles, permissions, entitlements, feature_flags: featureFlags, } = (0, jose_1.decodeJwt)(authenticationResponse.accessToken);
118
119
  // TODO: Returning `session` here means there's some duplicated data.
119
120
  // Slim down the return type in a future major version.
120
121
  return {
@@ -124,6 +125,7 @@ class CookieSession {
124
125
  sessionId,
125
126
  organizationId,
126
127
  role,
128
+ roles,
127
129
  permissions,
128
130
  entitlements,
129
131
  featureFlags,
@@ -119,7 +119,7 @@ describe('Session', () => {
119
119
  .spyOn(jose, 'jwtVerify')
120
120
  .mockResolvedValue({});
121
121
  const cookiePassword = 'alongcookiesecretmadefortestingsessions';
122
- const accessToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdXRoZW50aWNhdGVkIjp0cnVlLCJpbXBlcnNvbmF0b3IiOnsiZW1haWwiOiJhZG1pbkBleGFtcGxlLmNvbSIsInJlYXNvbiI6InRlc3QifSwic2lkIjoic2Vzc2lvbl8xMjMiLCJvcmdfaWQiOiJvcmdfMTIzIiwicm9sZSI6Im1lbWJlciIsInBlcm1pc3Npb25zIjpbInBvc3RzOmNyZWF0ZSIsInBvc3RzOmRlbGV0ZSJdLCJlbnRpdGxlbWVudHMiOlsiYXVkaXQtbG9ncyJdLCJmZWF0dXJlX2ZsYWdzIjpbImRhcmstbW9kZSIsImJldGEtZmVhdHVyZXMiXSwidXNlciI6eyJvYmplY3QiOiJ1c2VyIiwiaWQiOiJ1c2VyXzAxSDVKUURWN1I3QVRFWVpERUcwVzVQUllTIiwiZW1haWwiOiJ0ZXN0QGV4YW1wbGUuY29tIn19.YVNjR8S2xGn2jAoLuEcBQNJ1_xY3OzjRE1-BK0zjfQE';
122
+ const accessToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdXRoZW50aWNhdGVkIjp0cnVlLCJpbXBlcnNvbmF0b3IiOnsiZW1haWwiOiJhZG1pbkBleGFtcGxlLmNvbSIsInJlYXNvbiI6InRlc3QifSwic2lkIjoic2Vzc2lvbl8xMjMiLCJvcmdfaWQiOiJvcmdfMTIzIiwicm9sZSI6Im1lbWJlciIsInJvbGVzIjpbIm1lbWJlciIsImFkbWluIl0sInBlcm1pc3Npb25zIjpbInBvc3RzOmNyZWF0ZSIsInBvc3RzOmRlbGV0ZSJdLCJlbnRpdGxlbWVudHMiOlsiYXVkaXQtbG9ncyJdLCJmZWF0dXJlX2ZsYWdzIjpbImRhcmstbW9kZSIsImJldGEtZmVhdHVyZXMiXSwidXNlciI6eyJvYmplY3QiOiJ1c2VyIiwiaWQiOiJ1c2VyXzAxSDVKUURWN1I3QVRFWVpERUcwVzVQUllTIiwiZW1haWwiOiJ0ZXN0QGV4YW1wbGUuY29tIn19.TNUzJYn6lzLWFFsiWiKEgIshyUs-bKJQf1VxwNr1cGI';
123
123
  const sessionData = yield (0, iron_session_1.sealData)({
124
124
  accessToken,
125
125
  refreshToken: 'def456',
@@ -146,6 +146,7 @@ describe('Session', () => {
146
146
  sessionId: 'session_123',
147
147
  organizationId: 'org_123',
148
148
  role: 'member',
149
+ roles: ['member', 'admin'],
149
150
  permissions: ['posts:create', 'posts:delete'],
150
151
  entitlements: ['audit-logs'],
151
152
  featureFlags: ['dark-mode', 'beta-features'],
@@ -173,7 +174,7 @@ describe('Session', () => {
173
174
  }));
174
175
  describe('when the session data is valid', () => {
175
176
  it('returns a successful response with a sealed and unsealed session', () => __awaiter(void 0, void 0, void 0, function* () {
176
- const accessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ewogICJzdWIiOiAiMTIzNDU2Nzg5MCIsCiAgIm5hbWUiOiAiSm9obiBEb2UiLAogICJpYXQiOiAxNTE2MjM5MDIyLAogICJzaWQiOiAic2Vzc2lvbl8xMjMiLAogICJvcmdfaWQiOiAib3JnXzEyMyIsCiAgInJvbGUiOiAibWVtYmVyIiwKICAicGVybWlzc2lvbnMiOiBbInBvc3RzOmNyZWF0ZSIsICJwb3N0czpkZWxldGUiXQp9.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
177
+ const accessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJzaWQiOiJzZXNzaW9uXzEyMyIsIm9yZ19pZCI6Im9yZ18xMjMiLCJyb2xlIjoibWVtYmVyIiwicm9sZXMiOlsibWVtYmVyIiwiYWRtaW4iXSwicGVybWlzc2lvbnMiOlsicG9zdHM6Y3JlYXRlIiwicG9zdHM6ZGVsZXRlIl19.N5zveP149QhRR5zNvzGJPiCX098uXaN8VM1_lwsMg4A';
177
178
  const refreshToken = 'def456';
178
179
  (0, test_utils_1.fetchOnce)({
179
180
  user: user_json_1.default,
@@ -216,6 +217,7 @@ describe('Session', () => {
216
217
  entitlements: undefined,
217
218
  permissions: ['posts:create', 'posts:delete'],
218
219
  role: 'member',
220
+ roles: ['member', 'admin'],
219
221
  sessionId: 'session_123',
220
222
  user: expect.objectContaining({
221
223
  email: 'test01@example.com',
@@ -217,12 +217,13 @@ class UserManagement {
217
217
  reason: authenticate_with_session_cookie_interface_1.AuthenticateWithSessionCookieFailureReason.INVALID_JWT,
218
218
  };
219
219
  }
220
- const { sid: sessionId, org_id: organizationId, role, permissions, entitlements, feature_flags: featureFlags, } = (0, jose_1.decodeJwt)(session.accessToken);
220
+ const { sid: sessionId, org_id: organizationId, role, roles, permissions, entitlements, feature_flags: featureFlags, } = (0, jose_1.decodeJwt)(session.accessToken);
221
221
  return {
222
222
  authenticated: true,
223
223
  sessionId,
224
224
  organizationId,
225
225
  role,
226
+ roles,
226
227
  user: session.user,
227
228
  permissions,
228
229
  entitlements,
@@ -889,6 +889,39 @@ describe('UserManagement', () => {
889
889
  accessToken,
890
890
  });
891
891
  }));
892
+ it('returns the JWT claims when provided a valid JWT with multiple roles', () => __awaiter(void 0, void 0, void 0, function* () {
893
+ jest
894
+ .spyOn(jose, 'jwtVerify')
895
+ .mockResolvedValue({});
896
+ const cookiePassword = 'alongcookiesecretmadefortestingsessions';
897
+ const accessToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdXRoZW50aWNhdGVkIjp0cnVlLCJpbXBlcnNvbmF0b3IiOnsiZW1haWwiOiJhZG1pbkBleGFtcGxlLmNvbSIsInJlYXNvbiI6InRlc3QifSwic2lkIjoic2Vzc2lvbl8xMjMiLCJvcmdfaWQiOiJvcmdfMTIzIiwicm9sZSI6ImFkbWluIiwicm9sZXMiOlsiYWRtaW4iLCJtZW1iZXIiXSwicGVybWlzc2lvbnMiOlsicG9zdHM6Y3JlYXRlIiwicG9zdHM6ZGVsZXRlIl0sImVudGl0bGVtZW50cyI6WyJhdWRpdC1sb2dzIl0sImZlYXR1cmVfZmxhZ3MiOlsiZGFyay1tb2RlIiwiYmV0YS1mZWF0dXJlcyJdLCJ1c2VyIjp7Im9iamVjdCI6InVzZXIiLCJpZCI6InVzZXJfMDFINUpRRFY3UjdBVEVZWkRFRzBXNVBSWVMiLCJlbWFpbCI6InRlc3RAZXhhbXBsZS5jb20ifX0.hsMptIB7PmbF5pxxtgTtCdUyOAhA11ZIAP-JY5zU5fE';
898
+ const sessionData = yield (0, iron_session_1.sealData)({
899
+ accessToken,
900
+ refreshToken: 'def456',
901
+ user: {
902
+ object: 'user',
903
+ id: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
904
+ email: 'test@example.com',
905
+ },
906
+ }, { password: cookiePassword });
907
+ yield expect(workos.userManagement.authenticateWithSessionCookie({
908
+ sessionData,
909
+ cookiePassword,
910
+ })).resolves.toEqual({
911
+ authenticated: true,
912
+ sessionId: 'session_123',
913
+ organizationId: 'org_123',
914
+ role: 'admin',
915
+ roles: ['admin', 'member'],
916
+ permissions: ['posts:create', 'posts:delete'],
917
+ entitlements: ['audit-logs'],
918
+ featureFlags: ['dark-mode', 'beta-features'],
919
+ user: expect.objectContaining({
920
+ email: 'test@example.com',
921
+ }),
922
+ accessToken,
923
+ });
924
+ }));
892
925
  });
893
926
  describe('refreshAndSealSessionData', () => {
894
927
  it('throws an error when the cookie password is undefined', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -2,12 +2,12 @@ export type WidgetScope = 'widgets:users-table:manage' | 'widgets:sso:manage' |
2
2
  export interface GetTokenOptions {
3
3
  organizationId: string;
4
4
  userId?: string;
5
- scopes?: [WidgetScope];
5
+ scopes?: WidgetScope[];
6
6
  }
7
7
  export interface SerializedGetTokenOptions {
8
8
  organization_id: string;
9
9
  user_id?: string;
10
- scopes?: [WidgetScope];
10
+ scopes?: WidgetScope[];
11
11
  }
12
12
  export declare const serializeGetTokenOptions: (options: GetTokenOptions) => SerializedGetTokenOptions;
13
13
  export interface GetTokenResponse {
package/lib/workos.js CHANGED
@@ -32,7 +32,7 @@ const actions_1 = require("./actions/actions");
32
32
  const vault_1 = require("./vault/vault");
33
33
  const conflict_exception_1 = require("./common/exceptions/conflict.exception");
34
34
  const parse_error_1 = require("./common/exceptions/parse-error");
35
- const VERSION = '7.69.1';
35
+ const VERSION = '7.70.0';
36
36
  const DEFAULT_HOSTNAME = 'api.workos.com';
37
37
  const HEADER_AUTHORIZATION = 'Authorization';
38
38
  const HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';
@@ -99,7 +99,7 @@ class WorkOS {
99
99
  }
100
100
  createHttpClient(options, userAgent) {
101
101
  var _a;
102
- return new fetch_client_1.FetchHttpClient(this.baseURL, Object.assign(Object.assign({}, options.config), { headers: Object.assign(Object.assign({}, (_a = options.config) === null || _a === void 0 ? void 0 : _a.headers), { Authorization: `Bearer ${this.key}`, 'User-Agent': userAgent }) }));
102
+ return new fetch_client_1.FetchHttpClient(this.baseURL, Object.assign(Object.assign({}, options.config), { timeout: options.timeout, headers: Object.assign(Object.assign({}, (_a = options.config) === null || _a === void 0 ? void 0 : _a.headers), { Authorization: `Bearer ${this.key}`, 'User-Agent': userAgent }) }));
103
103
  }
104
104
  createIronSessionProvider() {
105
105
  throw new Error('IronSessionProvider not implemented. Use WorkOSNode or WorkOSWorker instead.');
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.69.1",
2
+ "version": "7.70.0",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",