@workos-inc/node 12.1.0 → 12.3.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.
- package/README.md +130 -0
- package/lib/{factory-Dagoc4rv.cjs → factory-BurShrC1.cjs} +599 -123
- package/lib/factory-BurShrC1.cjs.map +1 -0
- package/lib/{factory-99SwwalC.mjs → factory-ND4UZ76L.mjs} +594 -124
- package/lib/factory-ND4UZ76L.mjs.map +1 -0
- package/lib/{factory-2iQbHj6d.d.cts → factory-xvKEp07N.d.cts} +4889 -4359
- package/lib/{factory-2iQbHj6d.d.mts → factory-xvKEp07N.d.mts} +4889 -4359
- package/lib/index.cjs +2 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +39 -39
- package/lib/index.d.mts +39 -39
- package/lib/index.mjs +2 -2
- package/lib/index.mjs.map +1 -1
- package/lib/index.worker.cjs +2 -13
- package/lib/index.worker.cjs.map +1 -1
- package/lib/index.worker.d.cts +2 -4
- package/lib/index.worker.d.mts +2 -4
- package/lib/index.worker.mjs +2 -14
- package/lib/index.worker.mjs.map +1 -1
- package/package.json +1 -1
- package/lib/factory-99SwwalC.mjs.map +0 -1
- package/lib/factory-Dagoc4rv.cjs.map +0 -1
|
@@ -256,41 +256,42 @@ var FetchHttpClient = class FetchHttpClient extends HttpClient {
|
|
|
256
256
|
}
|
|
257
257
|
async get(path, options) {
|
|
258
258
|
const resourceURL = HttpClient.getResourceURL(this.baseURL, path, options.params);
|
|
259
|
-
return await this.fetchRequestWithRetry(resourceURL, "GET", null, options.headers, options.maxRetries);
|
|
259
|
+
return await this.fetchRequestWithRetry(resourceURL, "GET", null, options.headers, options.maxRetries, options.signal);
|
|
260
260
|
}
|
|
261
261
|
async post(path, entity, options) {
|
|
262
262
|
const resourceURL = HttpClient.getResourceURL(this.baseURL, path, options.params);
|
|
263
263
|
return await this.fetchRequestWithRetry(resourceURL, "POST", HttpClient.getBody(entity), {
|
|
264
264
|
...HttpClient.getContentTypeHeader(entity),
|
|
265
265
|
...options.headers
|
|
266
|
-
}, options.maxRetries);
|
|
266
|
+
}, options.maxRetries, options.signal);
|
|
267
267
|
}
|
|
268
268
|
async put(path, entity, options) {
|
|
269
269
|
const resourceURL = HttpClient.getResourceURL(this.baseURL, path, options.params);
|
|
270
270
|
return await this.fetchRequestWithRetry(resourceURL, "PUT", HttpClient.getBody(entity), {
|
|
271
271
|
...HttpClient.getContentTypeHeader(entity),
|
|
272
272
|
...options.headers
|
|
273
|
-
}, options.maxRetries);
|
|
273
|
+
}, options.maxRetries, options.signal);
|
|
274
274
|
}
|
|
275
275
|
async patch(path, entity, options) {
|
|
276
276
|
const resourceURL = HttpClient.getResourceURL(this.baseURL, path, options.params);
|
|
277
277
|
return await this.fetchRequestWithRetry(resourceURL, "PATCH", HttpClient.getBody(entity), {
|
|
278
278
|
...HttpClient.getContentTypeHeader(entity),
|
|
279
279
|
...options.headers
|
|
280
|
-
}, options.maxRetries);
|
|
280
|
+
}, options.maxRetries, options.signal);
|
|
281
281
|
}
|
|
282
282
|
async delete(path, options) {
|
|
283
283
|
const resourceURL = HttpClient.getResourceURL(this.baseURL, path, options.params);
|
|
284
|
-
return await this.fetchRequestWithRetry(resourceURL, "DELETE", null, options.headers, options.maxRetries);
|
|
284
|
+
return await this.fetchRequestWithRetry(resourceURL, "DELETE", null, options.headers, options.maxRetries, options.signal);
|
|
285
285
|
}
|
|
286
286
|
async deleteWithBody(path, entity, options) {
|
|
287
287
|
const resourceURL = HttpClient.getResourceURL(this.baseURL, path, options.params);
|
|
288
288
|
return await this.fetchRequestWithRetry(resourceURL, "DELETE", HttpClient.getBody(entity), {
|
|
289
289
|
...HttpClient.getContentTypeHeader(entity),
|
|
290
290
|
...options.headers
|
|
291
|
-
}, options.maxRetries);
|
|
291
|
+
}, options.maxRetries, options.signal);
|
|
292
292
|
}
|
|
293
|
-
async fetchRequest(url, method, body, headers) {
|
|
293
|
+
async fetchRequest(url, method, body, headers, signal) {
|
|
294
|
+
signal?.throwIfAborted();
|
|
294
295
|
const requestBody = body || (method === "POST" || method === "PUT" || method === "PATCH" ? "" : void 0);
|
|
295
296
|
const { "User-Agent": userAgent } = this.options?.headers || {};
|
|
296
297
|
const timeout = this.options?.timeout ?? DEFAULT_FETCH_TIMEOUT;
|
|
@@ -298,7 +299,13 @@ var FetchHttpClient = class FetchHttpClient extends HttpClient {
|
|
|
298
299
|
const timeoutId = setTimeout(() => {
|
|
299
300
|
abortController.abort();
|
|
300
301
|
}, timeout);
|
|
301
|
-
const
|
|
302
|
+
const abortRequest = () => abortController.abort();
|
|
303
|
+
signal?.addEventListener("abort", abortRequest, { once: true });
|
|
304
|
+
const release = () => {
|
|
305
|
+
clearTimeout(timeoutId);
|
|
306
|
+
signal?.removeEventListener("abort", abortRequest);
|
|
307
|
+
};
|
|
308
|
+
const abortError = (responseHeaders) => signal?.aborted ? signal.reason : new HttpClientError({
|
|
302
309
|
message: `Request timeout after ${timeout}ms`,
|
|
303
310
|
response: {
|
|
304
311
|
status: 408,
|
|
@@ -307,6 +314,7 @@ var FetchHttpClient = class FetchHttpClient extends HttpClient {
|
|
|
307
314
|
}
|
|
308
315
|
});
|
|
309
316
|
let res;
|
|
317
|
+
let redirected = false;
|
|
310
318
|
try {
|
|
311
319
|
res = await this._fetchFn(url, {
|
|
312
320
|
method,
|
|
@@ -318,12 +326,27 @@ var FetchHttpClient = class FetchHttpClient extends HttpClient {
|
|
|
318
326
|
"User-Agent": (userAgent || "workos-node").toString()
|
|
319
327
|
},
|
|
320
328
|
body: requestBody,
|
|
321
|
-
signal: abortController.signal
|
|
329
|
+
signal: abortController.signal,
|
|
330
|
+
redirect: "manual"
|
|
322
331
|
});
|
|
332
|
+
if (res.status >= 300 && res.status < 400 || res.type === "opaqueredirect") {
|
|
333
|
+
clearTimeout(timeoutId);
|
|
334
|
+
redirected = true;
|
|
335
|
+
const location = res.headers.get("Location");
|
|
336
|
+
const message = `WorkOS API responded with ${res.type === "opaqueredirect" ? "an opaque redirect" : `a redirect (${res.status}${location ? ` to ${location}` : ""})`}. Redirects are not followed; check the apiHostname, port and https options.`;
|
|
337
|
+
throw new HttpClientError({
|
|
338
|
+
message,
|
|
339
|
+
response: {
|
|
340
|
+
status: res.status,
|
|
341
|
+
headers: res.headers,
|
|
342
|
+
data: { message }
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
}
|
|
323
346
|
if (!res.ok) {
|
|
324
347
|
const requestID = res.headers.get("X-Request-ID") ?? "";
|
|
325
348
|
const rawBody = await res.text();
|
|
326
|
-
|
|
349
|
+
release();
|
|
327
350
|
let responseJson;
|
|
328
351
|
try {
|
|
329
352
|
responseJson = JSON.parse(rawBody);
|
|
@@ -351,37 +374,41 @@ var FetchHttpClient = class FetchHttpClient extends HttpClient {
|
|
|
351
374
|
try {
|
|
352
375
|
return await response.text();
|
|
353
376
|
} catch (error) {
|
|
354
|
-
throw abortController.signal.aborted ?
|
|
377
|
+
throw abortController.signal.aborted ? abortError(response.headers) : error;
|
|
355
378
|
} finally {
|
|
356
|
-
|
|
379
|
+
release();
|
|
357
380
|
}
|
|
358
381
|
})();
|
|
359
382
|
rawBody.catch(() => void 0);
|
|
360
383
|
return new FetchHttpClientResponse(res, rawBody);
|
|
361
384
|
} catch (error) {
|
|
362
|
-
|
|
363
|
-
if (abortController.signal.aborted) throw
|
|
385
|
+
release();
|
|
386
|
+
if (abortController.signal.aborted) throw abortError(res?.headers);
|
|
364
387
|
throw error;
|
|
388
|
+
} finally {
|
|
389
|
+
if (redirected) abortController.abort();
|
|
365
390
|
}
|
|
366
391
|
}
|
|
367
|
-
async fetchRequestWithRetry(url, method, body, headers, maxRetries) {
|
|
392
|
+
async fetchRequestWithRetry(url, method, body, headers, maxRetries, signal) {
|
|
368
393
|
const maxRetryAttempts = maxRetries ?? this.MAX_RETRY_ATTEMPTS;
|
|
369
394
|
const requestHeaders = FetchHttpClient.withIdempotencyKey(method, headers, maxRetryAttempts);
|
|
370
395
|
let response;
|
|
371
396
|
let retryAttempts = 1;
|
|
372
397
|
const makeRequest = async () => {
|
|
373
398
|
let requestError = null;
|
|
399
|
+
let failed = false;
|
|
374
400
|
try {
|
|
375
|
-
response = await this.fetchRequest(url, method, body, requestHeaders);
|
|
401
|
+
response = await this.fetchRequest(url, method, body, requestHeaders, signal);
|
|
376
402
|
} catch (e) {
|
|
377
403
|
requestError = e;
|
|
404
|
+
failed = true;
|
|
378
405
|
}
|
|
379
|
-
if (this.shouldRetryRequest(requestError, retryAttempts, maxRetryAttempts)) {
|
|
406
|
+
if (!signal?.aborted && this.shouldRetryRequest(requestError, retryAttempts, maxRetryAttempts)) {
|
|
380
407
|
retryAttempts++;
|
|
381
408
|
await this.sleep(retryAttempts, FetchHttpClient.getRetryAfterMs(requestError));
|
|
382
409
|
return makeRequest();
|
|
383
410
|
}
|
|
384
|
-
if (
|
|
411
|
+
if (failed) throw requestError;
|
|
385
412
|
return response;
|
|
386
413
|
};
|
|
387
414
|
return makeRequest();
|
|
@@ -944,6 +971,56 @@ const deserializeAuthenticationResponse = (authenticationResponse) => {
|
|
|
944
971
|
};
|
|
945
972
|
};
|
|
946
973
|
//#endregion
|
|
974
|
+
//#region src/connect/serializers/connect-application-redirect-uri.serializer.ts
|
|
975
|
+
const deserializeConnectApplicationRedirectUri = (response) => ({
|
|
976
|
+
uri: response.uri,
|
|
977
|
+
default: response.default
|
|
978
|
+
});
|
|
979
|
+
//#endregion
|
|
980
|
+
//#region src/connect/serializers/connect-application.serializer.ts
|
|
981
|
+
const deserializeConnectApplication = (response) => {
|
|
982
|
+
switch (response.application_type) {
|
|
983
|
+
case "oauth": return {
|
|
984
|
+
object: response.object,
|
|
985
|
+
id: response.id,
|
|
986
|
+
clientId: response.client_id,
|
|
987
|
+
description: response.description,
|
|
988
|
+
name: response.name,
|
|
989
|
+
scopes: response.scopes,
|
|
990
|
+
createdAt: new Date(response.created_at),
|
|
991
|
+
updatedAt: new Date(response.updated_at),
|
|
992
|
+
applicationType: "oauth",
|
|
993
|
+
redirectUris: response.redirect_uris.map(deserializeConnectApplicationRedirectUri),
|
|
994
|
+
usesPkce: response.uses_pkce,
|
|
995
|
+
isFirstParty: response.is_first_party,
|
|
996
|
+
wasDynamicallyRegistered: response.was_dynamically_registered,
|
|
997
|
+
organizationId: response.organization_id
|
|
998
|
+
};
|
|
999
|
+
case "m2m": return {
|
|
1000
|
+
object: response.object,
|
|
1001
|
+
id: response.id,
|
|
1002
|
+
clientId: response.client_id,
|
|
1003
|
+
description: response.description,
|
|
1004
|
+
name: response.name,
|
|
1005
|
+
scopes: response.scopes,
|
|
1006
|
+
createdAt: new Date(response.created_at),
|
|
1007
|
+
updatedAt: new Date(response.updated_at),
|
|
1008
|
+
applicationType: "m2m",
|
|
1009
|
+
organizationId: response.organization_id
|
|
1010
|
+
};
|
|
1011
|
+
default: throw new Error(`Unknown application_type: ${response.application_type}`);
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
//#endregion
|
|
1015
|
+
//#region src/user-management/serializers/authorized-connect-application.serializer.ts
|
|
1016
|
+
const deserializeAuthorizedConnectApplication = (response) => ({
|
|
1017
|
+
object: response.object,
|
|
1018
|
+
id: response.id,
|
|
1019
|
+
grantedScopes: response.granted_scopes,
|
|
1020
|
+
oauthResource: response.oauth_resource,
|
|
1021
|
+
application: deserializeConnectApplication(response.application)
|
|
1022
|
+
});
|
|
1023
|
+
//#endregion
|
|
947
1024
|
//#region src/user-management/serializers/create-magic-auth-options.serializer.ts
|
|
948
1025
|
const serializeCreateMagicAuthOptions = (options) => ({
|
|
949
1026
|
email: options.email,
|
|
@@ -1340,18 +1417,17 @@ var AutoPaginatable = class {
|
|
|
1340
1417
|
get listMetadata() {
|
|
1341
1418
|
return this.list.listMetadata;
|
|
1342
1419
|
}
|
|
1343
|
-
async *generatePages(
|
|
1420
|
+
async *generatePages(after) {
|
|
1344
1421
|
const { before, ...options } = this.options;
|
|
1345
1422
|
const result = await this.apiCall({
|
|
1346
1423
|
...options,
|
|
1347
1424
|
limit: 100,
|
|
1348
|
-
|
|
1349
|
-
after: params.after
|
|
1425
|
+
after
|
|
1350
1426
|
});
|
|
1351
1427
|
yield result.data;
|
|
1352
1428
|
if (result.listMetadata.after) {
|
|
1353
1429
|
await new Promise((resolve) => setTimeout(resolve, 350));
|
|
1354
|
-
yield* this.generatePages(
|
|
1430
|
+
yield* this.generatePages(result.listMetadata.after);
|
|
1355
1431
|
}
|
|
1356
1432
|
}
|
|
1357
1433
|
/**
|
|
@@ -1359,12 +1435,9 @@ var AutoPaginatable = class {
|
|
|
1359
1435
|
* Returns the first result if `options.limit` is passed to the first request.
|
|
1360
1436
|
*/
|
|
1361
1437
|
async autoPagination() {
|
|
1362
|
-
if (this.options.limit) return this.data;
|
|
1363
|
-
const results = [];
|
|
1364
|
-
for await (const page of this.generatePages(
|
|
1365
|
-
before: this.options.before,
|
|
1366
|
-
after: this.options.after
|
|
1367
|
-
})) results.push(...page);
|
|
1438
|
+
if (this.options.limit || !this.listMetadata.after) return this.data;
|
|
1439
|
+
const results = [...this.data];
|
|
1440
|
+
for await (const page of this.generatePages(this.listMetadata.after)) results.push(...page);
|
|
1368
1441
|
return results;
|
|
1369
1442
|
}
|
|
1370
1443
|
};
|
|
@@ -1874,6 +1947,92 @@ const deserializeFeatureFlag = (featureFlag) => ({
|
|
|
1874
1947
|
updatedAt: new Date(featureFlag.updated_at)
|
|
1875
1948
|
});
|
|
1876
1949
|
//#endregion
|
|
1950
|
+
//#region src/feature-flags/serializers/flag-rule.serializer.ts
|
|
1951
|
+
const deserializeFlagRule = (rule) => ({
|
|
1952
|
+
object: rule.object,
|
|
1953
|
+
id: rule.id,
|
|
1954
|
+
flagId: rule.flag_id,
|
|
1955
|
+
flagSlug: rule.flag_slug,
|
|
1956
|
+
environmentId: rule.environment_id,
|
|
1957
|
+
targetType: rule.target_type,
|
|
1958
|
+
position: rule.position,
|
|
1959
|
+
valueType: rule.value_type,
|
|
1960
|
+
value: rule.value,
|
|
1961
|
+
createdAt: new Date(rule.created_at),
|
|
1962
|
+
updatedAt: new Date(rule.updated_at)
|
|
1963
|
+
});
|
|
1964
|
+
//#endregion
|
|
1965
|
+
//#region src/feature-flags/serializers/flag-target.serializer.ts
|
|
1966
|
+
const deserializeTargetFields = (target) => ({
|
|
1967
|
+
object: target.object,
|
|
1968
|
+
id: target.id,
|
|
1969
|
+
flagId: target.flag_id,
|
|
1970
|
+
flagSlug: target.flag_slug,
|
|
1971
|
+
environmentId: target.environment_id,
|
|
1972
|
+
targetType: target.target_type,
|
|
1973
|
+
targetId: target.target_id,
|
|
1974
|
+
createdAt: new Date(target.created_at),
|
|
1975
|
+
updatedAt: new Date(target.updated_at)
|
|
1976
|
+
});
|
|
1977
|
+
const deserializeFlagTarget = (target) => ({
|
|
1978
|
+
...deserializeTargetFields(target),
|
|
1979
|
+
ruleId: target.rule_id
|
|
1980
|
+
});
|
|
1981
|
+
const deserializeFlagTargetResource = (target) => "rule_id" in target ? deserializeFlagTarget(target) : {
|
|
1982
|
+
...deserializeTargetFields(target),
|
|
1983
|
+
valueType: target.value_type,
|
|
1984
|
+
value: target.value
|
|
1985
|
+
};
|
|
1986
|
+
//#endregion
|
|
1987
|
+
//#region src/common/serializers/feature-flag-event.serializer.ts
|
|
1988
|
+
const deserializeFeatureFlagOwner = (owner) => owner === null ? null : {
|
|
1989
|
+
email: owner.email,
|
|
1990
|
+
firstName: owner.first_name,
|
|
1991
|
+
lastName: owner.last_name
|
|
1992
|
+
};
|
|
1993
|
+
const deserializeFeatureFlagEventData = (flag) => ({
|
|
1994
|
+
object: flag.object,
|
|
1995
|
+
id: flag.id,
|
|
1996
|
+
environmentId: flag.environment_id,
|
|
1997
|
+
slug: flag.slug,
|
|
1998
|
+
name: flag.name,
|
|
1999
|
+
description: flag.description,
|
|
2000
|
+
owner: deserializeFeatureFlagOwner(flag.owner),
|
|
2001
|
+
tags: flag.tags,
|
|
2002
|
+
enabled: flag.enabled,
|
|
2003
|
+
defaultValue: flag.default_value,
|
|
2004
|
+
createdAt: new Date(flag.created_at),
|
|
2005
|
+
updatedAt: new Date(flag.updated_at)
|
|
2006
|
+
});
|
|
2007
|
+
const deserializeFeatureFlagRuleContext = (context) => ({
|
|
2008
|
+
clientId: context.client_id,
|
|
2009
|
+
...context.actor === void 0 ? {} : { actor: context.actor }
|
|
2010
|
+
});
|
|
2011
|
+
const deserializeFeatureFlagRuleUpdatedContext = (context) => {
|
|
2012
|
+
const previous = context.previous_attributes;
|
|
2013
|
+
const data = previous?.data;
|
|
2014
|
+
return {
|
|
2015
|
+
...deserializeFeatureFlagRuleContext(context),
|
|
2016
|
+
...previous === void 0 ? {} : { previousAttributes: { ...data === void 0 ? {} : { data: data.value === void 0 ? {} : { value: data.value } } } }
|
|
2017
|
+
};
|
|
2018
|
+
};
|
|
2019
|
+
const deserializeFeatureFlagUpdatedContext = (context) => {
|
|
2020
|
+
const previous = context.previous_attributes;
|
|
2021
|
+
const data = previous?.data;
|
|
2022
|
+
return {
|
|
2023
|
+
clientId: context.client_id,
|
|
2024
|
+
actor: context.actor,
|
|
2025
|
+
...previous === void 0 ? {} : { previousAttributes: { ...data === void 0 ? {} : { data: {
|
|
2026
|
+
...data.name === void 0 ? {} : { name: data.name },
|
|
2027
|
+
...data.description === void 0 ? {} : { description: data.description },
|
|
2028
|
+
...data.tags === void 0 ? {} : { tags: data.tags },
|
|
2029
|
+
...data.owner === void 0 ? {} : { owner: deserializeFeatureFlagOwner(data.owner) },
|
|
2030
|
+
...data.enabled === void 0 ? {} : { enabled: data.enabled },
|
|
2031
|
+
...data.default_value === void 0 ? {} : { defaultValue: data.default_value }
|
|
2032
|
+
} } } }
|
|
2033
|
+
};
|
|
2034
|
+
};
|
|
2035
|
+
//#endregion
|
|
1877
2036
|
//#region src/groups/serializers/create-group.serializer.ts
|
|
1878
2037
|
const serializeCreateGroup = (model) => ({
|
|
1879
2038
|
name: model.name,
|
|
@@ -2062,7 +2221,8 @@ const deserializeEvent = (event) => {
|
|
|
2062
2221
|
return {
|
|
2063
2222
|
...eventBase,
|
|
2064
2223
|
event: unknownEvent.event,
|
|
2065
|
-
data: unknownEvent.data
|
|
2224
|
+
data: unknownEvent.data,
|
|
2225
|
+
context: unknownEvent.context
|
|
2066
2226
|
};
|
|
2067
2227
|
};
|
|
2068
2228
|
function deserializeKnownEvent(event, eventBase) {
|
|
@@ -2293,6 +2453,45 @@ function deserializeKnownEvent(event, eventBase) {
|
|
|
2293
2453
|
event: event.event,
|
|
2294
2454
|
data: deserializeApiKey(event.data)
|
|
2295
2455
|
};
|
|
2456
|
+
case "feature_flags.flag.created":
|
|
2457
|
+
case "feature_flags.flag.deleted": return {
|
|
2458
|
+
...eventBase,
|
|
2459
|
+
event: event.event,
|
|
2460
|
+
data: deserializeFeatureFlagEventData(event.data),
|
|
2461
|
+
context: {
|
|
2462
|
+
clientId: event.context.client_id,
|
|
2463
|
+
actor: event.context.actor
|
|
2464
|
+
}
|
|
2465
|
+
};
|
|
2466
|
+
case "feature_flags.flag.updated": return {
|
|
2467
|
+
...eventBase,
|
|
2468
|
+
event: event.event,
|
|
2469
|
+
data: deserializeFeatureFlagEventData(event.data),
|
|
2470
|
+
context: deserializeFeatureFlagUpdatedContext(event.context)
|
|
2471
|
+
};
|
|
2472
|
+
case "feature_flags.flag_rule.created":
|
|
2473
|
+
case "feature_flags.flag_rule.deleted": return {
|
|
2474
|
+
...eventBase,
|
|
2475
|
+
event: event.event,
|
|
2476
|
+
data: deserializeFlagRule(event.data),
|
|
2477
|
+
context: deserializeFeatureFlagRuleContext(event.context)
|
|
2478
|
+
};
|
|
2479
|
+
case "feature_flags.flag_rule.updated": return {
|
|
2480
|
+
...eventBase,
|
|
2481
|
+
event: event.event,
|
|
2482
|
+
data: deserializeFlagRule(event.data),
|
|
2483
|
+
context: deserializeFeatureFlagRuleUpdatedContext(event.context)
|
|
2484
|
+
};
|
|
2485
|
+
case "feature_flags.flag_target.created":
|
|
2486
|
+
case "feature_flags.flag_target.deleted": return {
|
|
2487
|
+
...eventBase,
|
|
2488
|
+
event: event.event,
|
|
2489
|
+
data: deserializeFlagTargetResource(event.data),
|
|
2490
|
+
context: {
|
|
2491
|
+
clientId: event.context.client_id,
|
|
2492
|
+
actor: event.context.actor
|
|
2493
|
+
}
|
|
2494
|
+
};
|
|
2296
2495
|
case "flag.created":
|
|
2297
2496
|
case "flag.updated":
|
|
2298
2497
|
case "flag.deleted":
|
|
@@ -3156,7 +3355,8 @@ var Agents = class {
|
|
|
3156
3355
|
function serializeCreateOrganizationApiKeyOptions(options) {
|
|
3157
3356
|
return {
|
|
3158
3357
|
name: options.name,
|
|
3159
|
-
permissions: options.permissions
|
|
3358
|
+
permissions: options.permissions,
|
|
3359
|
+
expires_at: options.expiresAt?.toISOString()
|
|
3160
3360
|
};
|
|
3161
3361
|
}
|
|
3162
3362
|
//#endregion
|
|
@@ -3245,7 +3445,7 @@ var ApiKeys = class {
|
|
|
3245
3445
|
* @example
|
|
3246
3446
|
* "org_01EHZNVPK3SFK441A1RGBFSHRT"
|
|
3247
3447
|
*
|
|
3248
|
-
* @param options - Object containing name.
|
|
3448
|
+
* @param options - Object containing name, permissions, and expiresAt.
|
|
3249
3449
|
* @returns {Promise<ApiKeyWithValue>}
|
|
3250
3450
|
* @throws {NotFoundException} 404
|
|
3251
3451
|
* @throws {UnprocessableEntityException} 422
|
|
@@ -3260,47 +3460,15 @@ var ApiKeys = class {
|
|
|
3260
3460
|
//#region src/connect/serializers/external-auth-complete-response.serializer.ts
|
|
3261
3461
|
const deserializeExternalAuthCompleteResponse = (response) => ({ redirectUri: response.redirect_uri });
|
|
3262
3462
|
//#endregion
|
|
3263
|
-
//#region src/connect/serializers/
|
|
3264
|
-
const
|
|
3265
|
-
|
|
3266
|
-
|
|
3463
|
+
//#region src/connect/serializers/token-exchange-response.serializer.ts
|
|
3464
|
+
const deserializeTokenExchangeResponse = (response) => ({
|
|
3465
|
+
accessToken: response.access_token,
|
|
3466
|
+
issuedTokenType: response.issued_token_type,
|
|
3467
|
+
tokenType: response.token_type,
|
|
3468
|
+
expiresIn: response.expires_in,
|
|
3469
|
+
...response.scope !== void 0 && { scope: response.scope }
|
|
3267
3470
|
});
|
|
3268
3471
|
//#endregion
|
|
3269
|
-
//#region src/connect/serializers/connect-application.serializer.ts
|
|
3270
|
-
const deserializeConnectApplication = (response) => {
|
|
3271
|
-
switch (response.application_type) {
|
|
3272
|
-
case "oauth": return {
|
|
3273
|
-
object: response.object,
|
|
3274
|
-
id: response.id,
|
|
3275
|
-
clientId: response.client_id,
|
|
3276
|
-
description: response.description,
|
|
3277
|
-
name: response.name,
|
|
3278
|
-
scopes: response.scopes,
|
|
3279
|
-
createdAt: new Date(response.created_at),
|
|
3280
|
-
updatedAt: new Date(response.updated_at),
|
|
3281
|
-
applicationType: "oauth",
|
|
3282
|
-
redirectUris: response.redirect_uris.map(deserializeConnectApplicationRedirectUri),
|
|
3283
|
-
usesPkce: response.uses_pkce,
|
|
3284
|
-
isFirstParty: response.is_first_party,
|
|
3285
|
-
wasDynamicallyRegistered: response.was_dynamically_registered,
|
|
3286
|
-
organizationId: response.organization_id
|
|
3287
|
-
};
|
|
3288
|
-
case "m2m": return {
|
|
3289
|
-
object: response.object,
|
|
3290
|
-
id: response.id,
|
|
3291
|
-
clientId: response.client_id,
|
|
3292
|
-
description: response.description,
|
|
3293
|
-
name: response.name,
|
|
3294
|
-
scopes: response.scopes,
|
|
3295
|
-
createdAt: new Date(response.created_at),
|
|
3296
|
-
updatedAt: new Date(response.updated_at),
|
|
3297
|
-
applicationType: "m2m",
|
|
3298
|
-
organizationId: response.organization_id
|
|
3299
|
-
};
|
|
3300
|
-
default: throw new Error(`Unknown application_type: ${response.application_type}`);
|
|
3301
|
-
}
|
|
3302
|
-
};
|
|
3303
|
-
//#endregion
|
|
3304
3472
|
//#region src/connect/serializers/application-credentials-list-item.serializer.ts
|
|
3305
3473
|
const deserializeApplicationCredentialsListItem = (response) => ({
|
|
3306
3474
|
object: response.object,
|
|
@@ -3435,6 +3603,73 @@ var Connect = class {
|
|
|
3435
3603
|
return deserializeExternalAuthCompleteResponse(data);
|
|
3436
3604
|
}
|
|
3437
3605
|
/**
|
|
3606
|
+
* Exchange an access token for one issued to another Resource Indicator
|
|
3607
|
+
*
|
|
3608
|
+
* Performs an [RFC 8693](https://datatracker.ietf.org/doc/html/rfc8693) token exchange against the environment's
|
|
3609
|
+
* `/oauth2/token` endpoint, authenticating as a first-party Connect Application with its client ID and client
|
|
3610
|
+
* secret. The issued access token keeps the subject token's user and consent and is audienced to `resource`.
|
|
3611
|
+
*
|
|
3612
|
+
* Unlike other SDK methods this does not call the WorkOS API with your API key: the request goes to the
|
|
3613
|
+
* environment's issuer (AuthKit domain) using the Connect Application's credentials. The client's `fetchFn`,
|
|
3614
|
+
* `timeout`, `maxRetries` and `config` options still apply.
|
|
3615
|
+
* @param options - Object containing issuer, clientId, clientSecret, subjectToken, resource, scope.
|
|
3616
|
+
* @returns {Promise<TokenExchangeResponse>}
|
|
3617
|
+
* @throws {OauthException} `invalid_client`, `unauthorized_client`, `invalid_grant`, `invalid_target`,
|
|
3618
|
+
* `invalid_scope`, `unsupported_grant_type`
|
|
3619
|
+
*/
|
|
3620
|
+
async exchangeToken(options) {
|
|
3621
|
+
const { issuer, clientId, clientSecret, subjectToken, resource, scope } = options;
|
|
3622
|
+
const path = "/oauth2/token";
|
|
3623
|
+
const client = this.createIssuerHttpClient(issuer);
|
|
3624
|
+
const body = new URLSearchParams({
|
|
3625
|
+
client_id: clientId,
|
|
3626
|
+
client_secret: clientSecret,
|
|
3627
|
+
grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
|
|
3628
|
+
subject_token: subjectToken,
|
|
3629
|
+
subject_token_type: "urn:ietf:params:oauth:token-type:access_token",
|
|
3630
|
+
requested_token_type: "urn:ietf:params:oauth:token-type:access_token",
|
|
3631
|
+
resource,
|
|
3632
|
+
...scope !== void 0 && { scope }
|
|
3633
|
+
});
|
|
3634
|
+
let res;
|
|
3635
|
+
try {
|
|
3636
|
+
res = await client.post(path, body, {});
|
|
3637
|
+
} catch (error) {
|
|
3638
|
+
this.throwOauthErrorFromTokenEndpoint(error);
|
|
3639
|
+
this.workos.handleHttpError({
|
|
3640
|
+
path,
|
|
3641
|
+
error
|
|
3642
|
+
});
|
|
3643
|
+
throw error;
|
|
3644
|
+
}
|
|
3645
|
+
const data = await this.workos.readResponseJSON(path, res);
|
|
3646
|
+
return deserializeTokenExchangeResponse(data);
|
|
3647
|
+
}
|
|
3648
|
+
/**
|
|
3649
|
+
* Builds an HTTP client for the environment's issuer that carries the SDK's
|
|
3650
|
+
* transport settings (`fetchFn`, `timeout`, `maxRetries`, `config`) but not
|
|
3651
|
+
* the WorkOS API key.
|
|
3652
|
+
*/
|
|
3653
|
+
createIssuerHttpClient(issuer) {
|
|
3654
|
+
const { config, timeout, maxRetries, fetchFn } = this.workos.options;
|
|
3655
|
+
return new FetchHttpClient(issuer, {
|
|
3656
|
+
...config,
|
|
3657
|
+
timeout,
|
|
3658
|
+
maxRetries,
|
|
3659
|
+
headers: { "User-Agent": `workos-node/${this.workos.version}` }
|
|
3660
|
+
}, fetchFn);
|
|
3661
|
+
}
|
|
3662
|
+
/**
|
|
3663
|
+
* The token endpoint reports client authentication failures as a 401 with
|
|
3664
|
+
* an RFC 6749 error body; surface that as an `OauthException` instead of the
|
|
3665
|
+
* generic `UnauthorizedException` used for API-key failures.
|
|
3666
|
+
*/
|
|
3667
|
+
throwOauthErrorFromTokenEndpoint(error) {
|
|
3668
|
+
if (!(error instanceof HttpClientError) || !error.response) return;
|
|
3669
|
+
const { status, data, headers } = error.response;
|
|
3670
|
+
if (status === 401 && (data.error || data.error_description)) throw new OauthException(status, headers.get("X-Request-ID") ?? "", data.error, data.error_description, data);
|
|
3671
|
+
}
|
|
3672
|
+
/**
|
|
3438
3673
|
* List Connect Applications
|
|
3439
3674
|
*
|
|
3440
3675
|
* List all Connect Applications in the current environment with optional filtering.
|
|
@@ -3621,6 +3856,18 @@ const serializeListDirectoriesOptions = (options) => {
|
|
|
3621
3856
|
if (options.search !== void 0) wire.search = options.search;
|
|
3622
3857
|
return wire;
|
|
3623
3858
|
};
|
|
3859
|
+
const serializeListUsersInDirectoryOptions = (options) => {
|
|
3860
|
+
const wire = {
|
|
3861
|
+
limit: options.limit,
|
|
3862
|
+
before: options.before,
|
|
3863
|
+
after: options.after,
|
|
3864
|
+
order: options.order,
|
|
3865
|
+
group: options.group,
|
|
3866
|
+
email: options.email
|
|
3867
|
+
};
|
|
3868
|
+
if (options.idpId !== void 0) wire.idp_id = options.idpId;
|
|
3869
|
+
return wire;
|
|
3870
|
+
};
|
|
3624
3871
|
var DirectorySync = class {
|
|
3625
3872
|
workos;
|
|
3626
3873
|
constructor(workos) {
|
|
@@ -3677,6 +3924,7 @@ var DirectorySync = class {
|
|
|
3677
3924
|
* @throws {AuthorizationException} 403
|
|
3678
3925
|
* @throws {NotFoundException} 404
|
|
3679
3926
|
* @throws {UnprocessableEntityException} 422
|
|
3927
|
+
* @deprecated Use {@link DirectorySync.listDirectoryGroups} instead.
|
|
3680
3928
|
*/
|
|
3681
3929
|
async listGroups(options) {
|
|
3682
3930
|
const paginationOptions = options;
|
|
@@ -3692,6 +3940,7 @@ var DirectorySync = class {
|
|
|
3692
3940
|
* @returns {Promise<DirectoryGroup>}
|
|
3693
3941
|
* @throws {AuthorizationException} 403
|
|
3694
3942
|
* @throws {NotFoundException} 404
|
|
3943
|
+
* @deprecated Use {@link DirectorySync.getDirectoryGroup} instead.
|
|
3695
3944
|
*/
|
|
3696
3945
|
async getGroup(options) {
|
|
3697
3946
|
const { id } = options;
|
|
@@ -3708,6 +3957,7 @@ var DirectorySync = class {
|
|
|
3708
3957
|
* @throws {NotFoundException} 404
|
|
3709
3958
|
* @throws {UnprocessableEntityException} 422
|
|
3710
3959
|
* @throws {RateLimitExceededException} 429
|
|
3960
|
+
* @deprecated Use {@link DirectorySync.listDirectoryUsers} instead.
|
|
3711
3961
|
*/
|
|
3712
3962
|
async listUsers(options) {
|
|
3713
3963
|
return new AutoPaginatable(await fetchAndDeserialize(this.workos, "/directory_users", deserializeDirectoryUserWithGroups, options), (params) => fetchAndDeserialize(this.workos, "/directory_users", deserializeDirectoryUserWithGroups, params), options);
|
|
@@ -3722,12 +3972,92 @@ var DirectorySync = class {
|
|
|
3722
3972
|
* @returns {Promise<DirectoryUserWithGroups<TCustomAttributes>>}
|
|
3723
3973
|
* @throws {AuthorizationException} 403
|
|
3724
3974
|
* @throws {NotFoundException} 404
|
|
3975
|
+
* @deprecated Use {@link DirectorySync.getDirectoryUser} instead.
|
|
3725
3976
|
*/
|
|
3726
3977
|
async getUser(options) {
|
|
3727
3978
|
const { id } = options;
|
|
3728
3979
|
const { data } = await this.workos.get(`/directory_users/${encodeURIComponent(id)}`);
|
|
3729
3980
|
return deserializeDirectoryUserWithGroups(data);
|
|
3730
3981
|
}
|
|
3982
|
+
/**
|
|
3983
|
+
* List Users for a Directory
|
|
3984
|
+
*
|
|
3985
|
+
* Get a list of the Directory Users in a Directory, optionally filtered to the members of a Directory Group.
|
|
3986
|
+
* @param options - Pagination and filter options.
|
|
3987
|
+
* @param options.directoryId - Unique identifier of the Directory.
|
|
3988
|
+
* @example "directory_01ECAZ4NV9QMV47GW873HDCX74"
|
|
3989
|
+
* @param options.group - Filter Directory Users to the members of this Directory Group.
|
|
3990
|
+
* @example "directory_group_01E64QTDNS0EGJ0FMCVY9BWGZT"
|
|
3991
|
+
* @param options.idpId - Filter Directory Users by the identity provider's unique identifier.
|
|
3992
|
+
* @example "2836"
|
|
3993
|
+
* @param options.email - Filter Directory Users by their primary email address.
|
|
3994
|
+
* @example "jane.doe@example.com"
|
|
3995
|
+
* @returns {Promise<AutoPaginatable<DirectoryUser<TCustomAttributes>, PaginationOptions>>}
|
|
3996
|
+
* @throws {AuthorizationException} 403
|
|
3997
|
+
* @throws {NotFoundException} 404
|
|
3998
|
+
* @throws {UnprocessableEntityException} 422
|
|
3999
|
+
*/
|
|
4000
|
+
async listDirectoryUsers(options) {
|
|
4001
|
+
const { directoryId, ...rest } = options;
|
|
4002
|
+
const endpoint = `/directories/${encodeURIComponent(directoryId)}/users`;
|
|
4003
|
+
const wire = serializeListUsersInDirectoryOptions(rest);
|
|
4004
|
+
return new AutoPaginatable(await fetchAndDeserialize(this.workos, endpoint, deserializeDirectoryUser, wire), (params) => fetchAndDeserialize(this.workos, endpoint, deserializeDirectoryUser, params), wire);
|
|
4005
|
+
}
|
|
4006
|
+
/**
|
|
4007
|
+
* Get a User for a Directory
|
|
4008
|
+
*
|
|
4009
|
+
* Get the details of a Directory User in a Directory.
|
|
4010
|
+
* @param options - The request options.
|
|
4011
|
+
* @param options.directoryId - Unique identifier of the Directory.
|
|
4012
|
+
* @example "directory_01ECAZ4NV9QMV47GW873HDCX74"
|
|
4013
|
+
* @param options.userId - Unique identifier for the Directory User.
|
|
4014
|
+
* @example "directory_user_01E1JG7J09H96KYP8HM9B0G5SJ"
|
|
4015
|
+
* @returns {Promise<DirectoryUser<TCustomAttributes>>}
|
|
4016
|
+
* @throws {AuthorizationException} 403
|
|
4017
|
+
* @throws {NotFoundException} 404
|
|
4018
|
+
*/
|
|
4019
|
+
async getDirectoryUser(options) {
|
|
4020
|
+
const { directoryId, userId } = options;
|
|
4021
|
+
const { data } = await this.workos.get(`/directories/${encodeURIComponent(directoryId)}/users/${encodeURIComponent(userId)}`);
|
|
4022
|
+
return deserializeDirectoryUser(data);
|
|
4023
|
+
}
|
|
4024
|
+
/**
|
|
4025
|
+
* List Groups for a Directory
|
|
4026
|
+
*
|
|
4027
|
+
* Get a list of the Directory Groups in a Directory, optionally filtered to the groups a Directory User belongs to.
|
|
4028
|
+
* @param options - Pagination and filter options.
|
|
4029
|
+
* @param options.directoryId - Unique identifier of the Directory.
|
|
4030
|
+
* @example "directory_01ECAZ4NV9QMV47GW873HDCX74"
|
|
4031
|
+
* @param options.user - Filter Directory Groups to those this Directory User belongs to.
|
|
4032
|
+
* @example "directory_user_01E1JG7J09H96KYP8HM9B0G5SJ"
|
|
4033
|
+
* @returns {Promise<AutoPaginatable<DirectoryGroup, PaginationOptions>>}
|
|
4034
|
+
* @throws {AuthorizationException} 403
|
|
4035
|
+
* @throws {NotFoundException} 404
|
|
4036
|
+
* @throws {UnprocessableEntityException} 422
|
|
4037
|
+
*/
|
|
4038
|
+
async listDirectoryGroups(options) {
|
|
4039
|
+
const { directoryId, ...wire } = options;
|
|
4040
|
+
const endpoint = `/directories/${encodeURIComponent(directoryId)}/groups`;
|
|
4041
|
+
return new AutoPaginatable(await fetchAndDeserialize(this.workos, endpoint, deserializeDirectoryGroup, wire), (params) => fetchAndDeserialize(this.workos, endpoint, deserializeDirectoryGroup, params), wire);
|
|
4042
|
+
}
|
|
4043
|
+
/**
|
|
4044
|
+
* Get a Group for a Directory
|
|
4045
|
+
*
|
|
4046
|
+
* Get the details of a Directory Group in a Directory.
|
|
4047
|
+
* @param options - The request options.
|
|
4048
|
+
* @param options.directoryId - Unique identifier of the Directory.
|
|
4049
|
+
* @example "directory_01ECAZ4NV9QMV47GW873HDCX74"
|
|
4050
|
+
* @param options.groupId - Unique identifier for the Directory Group.
|
|
4051
|
+
* @example "directory_group_01E1JJS84MFPPQ3G655FHTKX6Z"
|
|
4052
|
+
* @returns {Promise<DirectoryGroup>}
|
|
4053
|
+
* @throws {AuthorizationException} 403
|
|
4054
|
+
* @throws {NotFoundException} 404
|
|
4055
|
+
*/
|
|
4056
|
+
async getDirectoryGroup(options) {
|
|
4057
|
+
const { directoryId, groupId } = options;
|
|
4058
|
+
const { data } = await this.workos.get(`/directories/${encodeURIComponent(directoryId)}/groups/${encodeURIComponent(groupId)}`);
|
|
4059
|
+
return deserializeDirectoryGroup(data);
|
|
4060
|
+
}
|
|
3731
4061
|
};
|
|
3732
4062
|
//#endregion
|
|
3733
4063
|
//#region src/events/serializers/list-event-options.serializer.ts
|
|
@@ -3737,8 +4067,7 @@ const serializeListEventOptions = (options) => ({
|
|
|
3737
4067
|
range_start: options.rangeStart,
|
|
3738
4068
|
range_end: options.rangeEnd,
|
|
3739
4069
|
limit: options.limit,
|
|
3740
|
-
after: options.after
|
|
3741
|
-
order: options.order
|
|
4070
|
+
after: options.after
|
|
3742
4071
|
});
|
|
3743
4072
|
//#endregion
|
|
3744
4073
|
//#region src/events/events.ts
|
|
@@ -4169,6 +4498,7 @@ const deserializeDataIntegrationFinishConnectionResponse = (response) => ({ conn
|
|
|
4169
4498
|
//#region src/pipes/serializers/data-integration-authorize-url-response.serializer.ts
|
|
4170
4499
|
const deserializeDataIntegrationAuthorizeUrlResponse = (response) => ({
|
|
4171
4500
|
url: response.url,
|
|
4501
|
+
state: response.state ?? "",
|
|
4172
4502
|
completion: response.completion
|
|
4173
4503
|
});
|
|
4174
4504
|
//#endregion
|
|
@@ -5367,14 +5697,16 @@ var AdminPortal = class {
|
|
|
5367
5697
|
* Generate a Portal Link
|
|
5368
5698
|
*
|
|
5369
5699
|
* Generate a Portal Link scoped to an Organization.
|
|
5370
|
-
* @param payload - Object containing organization.
|
|
5700
|
+
* @param payload - Object containing organization. Pass `externalUserId`
|
|
5701
|
+
* for every admin you may later need to deprovision; only links generated
|
|
5702
|
+
* with one can be revoked via `revokeLink`.
|
|
5371
5703
|
* @returns {Promise<{ link: string; }>}
|
|
5372
5704
|
* @throws {BadRequestException} 400
|
|
5373
5705
|
* @throws 403 response from the API.
|
|
5374
5706
|
* @throws {NotFoundException} 404
|
|
5375
5707
|
* @throws {UnprocessableEntityException} 422
|
|
5376
5708
|
*/
|
|
5377
|
-
async generateLink({ intent, organization, returnUrl, successUrl, intentOptions, itContactEmails }) {
|
|
5709
|
+
async generateLink({ intent, organization, returnUrl, successUrl, intentOptions, itContactEmails, externalUserId }) {
|
|
5378
5710
|
const { data } = await this.workos.post("/portal/generate_link", {
|
|
5379
5711
|
intent,
|
|
5380
5712
|
organization,
|
|
@@ -5384,10 +5716,31 @@ var AdminPortal = class {
|
|
|
5384
5716
|
bookmark_slug: intentOptions.sso.bookmarkSlug,
|
|
5385
5717
|
provider_type: intentOptions.sso.providerType
|
|
5386
5718
|
} } : void 0,
|
|
5387
|
-
it_contact_emails: itContactEmails
|
|
5719
|
+
it_contact_emails: itContactEmails,
|
|
5720
|
+
external_user_id: externalUserId
|
|
5388
5721
|
});
|
|
5389
5722
|
return data;
|
|
5390
5723
|
}
|
|
5724
|
+
/**
|
|
5725
|
+
* Revoke Portal Links
|
|
5726
|
+
*
|
|
5727
|
+
* Revokes every Portal Link generated for the given organization with the
|
|
5728
|
+
* given `externalUserId`, and immediately ends any Admin Portal sessions that
|
|
5729
|
+
* were started from those links. Use this when an admin is deprovisioned from
|
|
5730
|
+
* your application: unopened links stop working, and their already-open
|
|
5731
|
+
* portal sessions are ended. Only links that were generated with an
|
|
5732
|
+
* `externalUserId` can be revoked, so pass one to `generateLink` for every
|
|
5733
|
+
* admin you may later need to deprovision.
|
|
5734
|
+
* @param payload - Object containing organization and externalUserId.
|
|
5735
|
+
* @throws {NotFoundException} 404
|
|
5736
|
+
* @throws {UnprocessableEntityException} 422
|
|
5737
|
+
*/
|
|
5738
|
+
async revokeLink({ organization, externalUserId }) {
|
|
5739
|
+
await this.workos.post("/portal/revoke_link", {
|
|
5740
|
+
organization,
|
|
5741
|
+
external_user_id: externalUserId
|
|
5742
|
+
});
|
|
5743
|
+
}
|
|
5391
5744
|
};
|
|
5392
5745
|
//#endregion
|
|
5393
5746
|
//#region src/common/utils/query-string.ts
|
|
@@ -6466,12 +6819,12 @@ var CookieSession = class {
|
|
|
6466
6819
|
authenticated: false,
|
|
6467
6820
|
reason: "invalid_session_cookie"
|
|
6468
6821
|
};
|
|
6469
|
-
|
|
6822
|
+
const claims = await this.userManagement.verifyAccessToken(session.accessToken);
|
|
6823
|
+
if (!claims) return {
|
|
6470
6824
|
authenticated: false,
|
|
6471
6825
|
reason: "invalid_jwt"
|
|
6472
6826
|
};
|
|
6473
|
-
const {
|
|
6474
|
-
const { sid: sessionId, org_id: organizationId, role, roles, permissions, entitlements, feature_flags: featureFlags } = decodeJwt(session.accessToken);
|
|
6827
|
+
const { sid: sessionId, org_id: organizationId, role, roles, permissions, entitlements, feature_flags: featureFlags } = claims;
|
|
6475
6828
|
return {
|
|
6476
6829
|
authenticated: true,
|
|
6477
6830
|
sessionId,
|
|
@@ -6548,32 +6901,23 @@ var CookieSession = class {
|
|
|
6548
6901
|
/**
|
|
6549
6902
|
* Gets the URL to redirect the user to for logging out.
|
|
6550
6903
|
*
|
|
6904
|
+
* Works for sessions whose access token has expired. The sealed cookie is
|
|
6905
|
+
* already authenticated by its encryption, so the session ID is read from
|
|
6906
|
+
* the access token without verifying it.
|
|
6907
|
+
*
|
|
6551
6908
|
* @returns The URL to redirect the user to for logging out.
|
|
6552
6909
|
*/
|
|
6553
6910
|
async getLogoutUrl({ returnTo } = {}) {
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
}
|
|
6911
|
+
if (!this.sessionData) throw new Error(`Failed to extract session ID for logout URL: no_session_cookie_provided`);
|
|
6912
|
+
const { accessToken } = await unsealData(this.sessionData, { password: this.cookiePassword });
|
|
6913
|
+
if (!accessToken) throw new Error(`Failed to extract session ID for logout URL: invalid_session_cookie`);
|
|
6914
|
+
const { decodeJwt } = await getJose();
|
|
6915
|
+
const { sid: sessionId } = decodeJwt(accessToken);
|
|
6559
6916
|
return this.userManagement.getLogoutUrl({
|
|
6560
|
-
sessionId
|
|
6917
|
+
sessionId,
|
|
6561
6918
|
returnTo
|
|
6562
6919
|
});
|
|
6563
6920
|
}
|
|
6564
|
-
async isValidJwt(accessToken) {
|
|
6565
|
-
const { jwtVerify } = await getJose();
|
|
6566
|
-
const jwks = await this.userManagement.getJWKS();
|
|
6567
|
-
if (!jwks) throw new Error("Missing client ID. Did you provide it when initializing WorkOS?");
|
|
6568
|
-
const { issuer } = this.userManagement;
|
|
6569
|
-
try {
|
|
6570
|
-
await jwtVerify(accessToken, jwks, issuer ? { issuer } : void 0);
|
|
6571
|
-
return true;
|
|
6572
|
-
} catch (e) {
|
|
6573
|
-
if (e instanceof Error && "code" in e && typeof e.code === "string" && (e.code.startsWith("ERR_JWT_") || e.code.startsWith("ERR_JWS_"))) return false;
|
|
6574
|
-
throw e;
|
|
6575
|
-
}
|
|
6576
|
-
}
|
|
6577
6921
|
};
|
|
6578
6922
|
/**
|
|
6579
6923
|
* Classifies an error thrown while refreshing as a terminal authentication
|
|
@@ -6908,8 +7252,6 @@ var UserManagement = class UserManagement {
|
|
|
6908
7252
|
}
|
|
6909
7253
|
async authenticateWithSessionCookie({ sessionData, cookiePassword = getEnv("WORKOS_COOKIE_PASSWORD") }) {
|
|
6910
7254
|
if (!cookiePassword) throw new Error("Cookie password is required");
|
|
6911
|
-
if (!await this.getJWKS()) throw new Error("Must provide clientId to initialize JWKS");
|
|
6912
|
-
const { decodeJwt } = await getJose();
|
|
6913
7255
|
if (!sessionData) return {
|
|
6914
7256
|
authenticated: false,
|
|
6915
7257
|
reason: "no_session_cookie_provided"
|
|
@@ -6919,11 +7261,12 @@ var UserManagement = class UserManagement {
|
|
|
6919
7261
|
authenticated: false,
|
|
6920
7262
|
reason: "invalid_session_cookie"
|
|
6921
7263
|
};
|
|
6922
|
-
|
|
7264
|
+
const claims = await this.verifyAccessToken(session.accessToken);
|
|
7265
|
+
if (!claims) return {
|
|
6923
7266
|
authenticated: false,
|
|
6924
7267
|
reason: "invalid_jwt"
|
|
6925
7268
|
};
|
|
6926
|
-
const { sid: sessionId, org_id: organizationId, role, roles, permissions, entitlements, feature_flags: featureFlags } =
|
|
7269
|
+
const { sid: sessionId, org_id: organizationId, role, roles, permissions, entitlements, feature_flags: featureFlags } = claims;
|
|
6927
7270
|
return {
|
|
6928
7271
|
authenticated: true,
|
|
6929
7272
|
sessionId,
|
|
@@ -7003,9 +7346,6 @@ var UserManagement = class UserManagement {
|
|
|
7003
7346
|
if (!(e instanceof Error) || !("code" in e) || typeof e.code !== "string") return false;
|
|
7004
7347
|
return e.code.startsWith("ERR_JWT_") || e.code.startsWith("ERR_JWS_") || e.code === "ERR_JWKS_NO_MATCHING_KEY" || e.code === "ERR_JWKS_MULTIPLE_MATCHING_KEYS" || e.code === "ERR_JOSE_NOT_SUPPORTED" || e.code === "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
7005
7348
|
}
|
|
7006
|
-
async isValidJwt(accessToken) {
|
|
7007
|
-
return await this.verifyJwt(accessToken) !== null;
|
|
7008
|
-
}
|
|
7009
7349
|
async prepareAuthenticationResponse({ authenticationResponse, session }) {
|
|
7010
7350
|
if (session?.sealSession) {
|
|
7011
7351
|
if (!this.workos.key) throw new Error("Session sealing requires server-side usage with an API key. Public clients should store tokens directly (e.g., secure storage on mobile, keychain on desktop).");
|
|
@@ -7161,6 +7501,32 @@ var UserManagement = class UserManagement {
|
|
|
7161
7501
|
return new AutoPaginatable(await fetchAndDeserialize(this.workos, `/user_management/users/${encodePathParameter(userId)}/sessions`, deserializeSession, options ? serializeListSessionsOptions(options) : void 0), (params) => fetchAndDeserialize(this.workos, `/user_management/users/${encodePathParameter(userId)}/sessions`, deserializeSession, params), options ? serializeListSessionsOptions(options) : void 0);
|
|
7162
7502
|
}
|
|
7163
7503
|
/**
|
|
7504
|
+
* List authorized applications
|
|
7505
|
+
*
|
|
7506
|
+
* Get a list of Connect applications that the user has authorized.
|
|
7507
|
+
* @param userId - The ID of the user.
|
|
7508
|
+
* @param options - Pagination options.
|
|
7509
|
+
* @returns {Promise<AutoPaginatable<AuthorizedConnectApplication>>}
|
|
7510
|
+
* @throws {NotFoundException} 404
|
|
7511
|
+
* @throws {UnprocessableEntityException} 422
|
|
7512
|
+
*/
|
|
7513
|
+
async listAuthorizedApplications(userId, options) {
|
|
7514
|
+
const path = `/user_management/users/${encodePathParameter(userId)}/authorized_applications`;
|
|
7515
|
+
return new AutoPaginatable(await fetchAndDeserialize(this.workos, path, deserializeAuthorizedConnectApplication, options), (params) => fetchAndDeserialize(this.workos, path, deserializeAuthorizedConnectApplication, params), options);
|
|
7516
|
+
}
|
|
7517
|
+
/**
|
|
7518
|
+
* Delete an authorized application
|
|
7519
|
+
*
|
|
7520
|
+
* Removes a user's authorization without deleting the Connect application.
|
|
7521
|
+
* @param userId - The ID of the user.
|
|
7522
|
+
* @param applicationId - The ID or client ID of the application.
|
|
7523
|
+
* @returns {Promise<void>}
|
|
7524
|
+
* @throws {NotFoundException} 404
|
|
7525
|
+
*/
|
|
7526
|
+
async deleteAuthorizedApplication(userId, applicationId) {
|
|
7527
|
+
await this.workos.delete(`/user_management/users/${encodePathParameter(userId)}/authorized_applications/${encodePathParameter(applicationId)}`);
|
|
7528
|
+
}
|
|
7529
|
+
/**
|
|
7164
7530
|
* Delete a user
|
|
7165
7531
|
*
|
|
7166
7532
|
* Permanently deletes a user in the current environment. It cannot be undone.
|
|
@@ -7620,6 +7986,21 @@ var UserManagement = class UserManagement {
|
|
|
7620
7986
|
}
|
|
7621
7987
|
};
|
|
7622
7988
|
//#endregion
|
|
7989
|
+
//#region src/feature-flags/create-rule-with-targets-error.ts
|
|
7990
|
+
/** A rule was created, but adding one of its targets failed. */
|
|
7991
|
+
var CreateRuleWithTargetsError = class extends Error {
|
|
7992
|
+
rule;
|
|
7993
|
+
targets;
|
|
7994
|
+
failedTargetId;
|
|
7995
|
+
name = "CreateRuleWithTargetsError";
|
|
7996
|
+
constructor(rule, targets, failedTargetId, cause) {
|
|
7997
|
+
super("The rule was created, but adding a target failed.", { cause });
|
|
7998
|
+
this.rule = rule;
|
|
7999
|
+
this.targets = targets;
|
|
8000
|
+
this.failedTargetId = failedTargetId;
|
|
8001
|
+
}
|
|
8002
|
+
};
|
|
8003
|
+
//#endregion
|
|
7623
8004
|
//#region src/feature-flags/event-emitter.ts
|
|
7624
8005
|
/**
|
|
7625
8006
|
* Minimal, runtime-agnostic, typed event emitter.
|
|
@@ -7971,26 +8352,18 @@ var FeatureFlagsRuntimeClient = class extends EventEmitter {
|
|
|
7971
8352
|
async fetchWithTimeout() {
|
|
7972
8353
|
this.pollAbortController = new AbortController();
|
|
7973
8354
|
const { signal } = this.pollAbortController;
|
|
7974
|
-
|
|
7975
|
-
|
|
7976
|
-
|
|
7977
|
-
|
|
7978
|
-
this.pollAbortController?.abort();
|
|
7979
|
-
reject(/* @__PURE__ */ new Error("Request timed out"));
|
|
7980
|
-
}, this.requestTimeoutMs);
|
|
7981
|
-
});
|
|
8355
|
+
const timeoutId = setTimeout(() => {
|
|
8356
|
+
this.pollAbortController?.abort(/* @__PURE__ */ new Error("Request timed out"));
|
|
8357
|
+
}, this.requestTimeoutMs);
|
|
8358
|
+
const fetchPromise = this.workos.get("/sdk/feature-flags?payload_version=2", { signal }).then(({ data }) => data);
|
|
7982
8359
|
const abortPromise = new Promise((_, reject) => {
|
|
7983
8360
|
if (signal.aborted) {
|
|
7984
|
-
reject(
|
|
8361
|
+
reject(signal.reason);
|
|
7985
8362
|
return;
|
|
7986
8363
|
}
|
|
7987
|
-
signal.addEventListener("abort", () => reject(
|
|
8364
|
+
signal.addEventListener("abort", () => reject(signal.reason), { once: true });
|
|
7988
8365
|
});
|
|
7989
|
-
return Promise.race([
|
|
7990
|
-
fetchPromise,
|
|
7991
|
-
timeoutPromise,
|
|
7992
|
-
abortPromise
|
|
7993
|
-
]).finally(() => {
|
|
8366
|
+
return Promise.race([fetchPromise, abortPromise]).finally(() => {
|
|
7994
8367
|
clearTimeout(timeoutId);
|
|
7995
8368
|
});
|
|
7996
8369
|
}
|
|
@@ -8045,6 +8418,93 @@ var FeatureFlags = class {
|
|
|
8045
8418
|
constructor(workos) {
|
|
8046
8419
|
this.workos = workos;
|
|
8047
8420
|
}
|
|
8421
|
+
/** Append an empty rule to a flag. Duplicate target type/value pairs return 409. */
|
|
8422
|
+
async createFlagRule(options) {
|
|
8423
|
+
const { data } = await this.workos.post("/flag_rules", {
|
|
8424
|
+
flag_slug: options.flagSlug,
|
|
8425
|
+
target_type: options.targetType,
|
|
8426
|
+
value: options.value
|
|
8427
|
+
});
|
|
8428
|
+
return deserializeFlagRule(data);
|
|
8429
|
+
}
|
|
8430
|
+
/** List a flag's rules in evaluation order. */
|
|
8431
|
+
async listFlagRules(options) {
|
|
8432
|
+
const fetchPage = async ({ limit, before, after }) => {
|
|
8433
|
+
const { data } = await this.workos.get("/flag_rules", { query: {
|
|
8434
|
+
flag_slug: options.flagSlug,
|
|
8435
|
+
limit,
|
|
8436
|
+
before,
|
|
8437
|
+
after
|
|
8438
|
+
} });
|
|
8439
|
+
return deserializeList(data, deserializeFlagRule);
|
|
8440
|
+
};
|
|
8441
|
+
return new AutoPaginatable(await fetchPage(options), fetchPage, options);
|
|
8442
|
+
}
|
|
8443
|
+
/** Get a rule in the current environment. */
|
|
8444
|
+
async getFlagRule(id) {
|
|
8445
|
+
const { data } = await this.workos.get(`/flag_rules/${encodePathParameter(id)}`);
|
|
8446
|
+
return deserializeFlagRule(data);
|
|
8447
|
+
}
|
|
8448
|
+
/** Delete a rule and all its target memberships. */
|
|
8449
|
+
async deleteFlagRule(id) {
|
|
8450
|
+
await this.workos.delete(`/flag_rules/${encodePathParameter(id)}`);
|
|
8451
|
+
}
|
|
8452
|
+
/** Add a membership to a rule. The rule supplies the target type and value. */
|
|
8453
|
+
async createFlagTarget(options) {
|
|
8454
|
+
const { data } = await this.workos.post("/flag_targets", {
|
|
8455
|
+
rule_id: options.ruleId,
|
|
8456
|
+
target_id: options.targetId
|
|
8457
|
+
});
|
|
8458
|
+
return deserializeFlagTarget(data);
|
|
8459
|
+
}
|
|
8460
|
+
/** Get a membership, or a legacy target while the compatibility contract is enabled. */
|
|
8461
|
+
async getFlagTarget(id) {
|
|
8462
|
+
const { data } = await this.workos.get(`/flag_targets/${encodePathParameter(id)}`);
|
|
8463
|
+
return deserializeFlagTargetResource(data);
|
|
8464
|
+
}
|
|
8465
|
+
/** List targets with combined filters; the team's contract selects their shape. */
|
|
8466
|
+
async listFlagTargets(options = {}) {
|
|
8467
|
+
const fetchPage = async ({ limit, before, after }) => {
|
|
8468
|
+
const { data } = await this.workos.get("/flag_targets", { query: {
|
|
8469
|
+
rule_id: options.ruleId,
|
|
8470
|
+
flag_slug: options.flagSlug,
|
|
8471
|
+
target_type: options.targetType,
|
|
8472
|
+
target_id: options.targetId,
|
|
8473
|
+
order: options.order ?? "desc",
|
|
8474
|
+
limit,
|
|
8475
|
+
before,
|
|
8476
|
+
after
|
|
8477
|
+
} });
|
|
8478
|
+
return deserializeList(data, deserializeFlagTargetResource);
|
|
8479
|
+
};
|
|
8480
|
+
return new AutoPaginatable(await fetchPage(options), fetchPage, options);
|
|
8481
|
+
}
|
|
8482
|
+
/** Delete a membership by its flag_target ID, not the targeted entity's ID. */
|
|
8483
|
+
async deleteFlagTarget(id) {
|
|
8484
|
+
await this.workos.delete(`/flag_targets/${encodePathParameter(id)}`);
|
|
8485
|
+
}
|
|
8486
|
+
/**
|
|
8487
|
+
* Create a rule, then add its targets sequentially in input order.
|
|
8488
|
+
* This is not atomic: on failure, the rule and completed memberships remain.
|
|
8489
|
+
* A CreateRuleWithTargetsError exposes the rule, confirmed targets, failed
|
|
8490
|
+
* target ID, and original error. No later targets are attempted.
|
|
8491
|
+
*/
|
|
8492
|
+
async createRuleWithTargets(options) {
|
|
8493
|
+
const rule = await this.createFlagRule(options);
|
|
8494
|
+
const targets = [];
|
|
8495
|
+
for (const targetId of options.targetIds) try {
|
|
8496
|
+
targets.push(await this.createFlagTarget({
|
|
8497
|
+
ruleId: rule.id,
|
|
8498
|
+
targetId
|
|
8499
|
+
}));
|
|
8500
|
+
} catch (cause) {
|
|
8501
|
+
throw new CreateRuleWithTargetsError(rule, targets, targetId, cause);
|
|
8502
|
+
}
|
|
8503
|
+
return {
|
|
8504
|
+
rule,
|
|
8505
|
+
targets
|
|
8506
|
+
};
|
|
8507
|
+
}
|
|
8048
8508
|
/**
|
|
8049
8509
|
* List feature flags
|
|
8050
8510
|
*
|
|
@@ -8109,6 +8569,9 @@ var FeatureFlags = class {
|
|
|
8109
8569
|
/**
|
|
8110
8570
|
* Add a feature flag target
|
|
8111
8571
|
*
|
|
8572
|
+
* @deprecated For rule-based targeting, use createFlagRule and createFlagTarget.
|
|
8573
|
+
* This compatibility helper remains supported.
|
|
8574
|
+
*
|
|
8112
8575
|
* Enables a feature flag for a specific target in the current environment. Currently, supported targets include users and organizations.
|
|
8113
8576
|
* @params options - Object containing slug and targetId.
|
|
8114
8577
|
* @returns {Promise<void>}
|
|
@@ -8123,6 +8586,9 @@ var FeatureFlags = class {
|
|
|
8123
8586
|
/**
|
|
8124
8587
|
* Remove a feature flag target
|
|
8125
8588
|
*
|
|
8589
|
+
* @deprecated For rule-based targeting, use deleteFlagTarget with a membership ID.
|
|
8590
|
+
* This compatibility helper remains supported.
|
|
8591
|
+
*
|
|
8126
8592
|
* Removes a target from the feature flag's target list in the current environment. Currently, supported targets include users and organizations.
|
|
8127
8593
|
* @params options - Object containing slug and targetId.
|
|
8128
8594
|
* @returns {Promise<void>}
|
|
@@ -9951,7 +10417,7 @@ var Vault = class {
|
|
|
9951
10417
|
};
|
|
9952
10418
|
//#endregion
|
|
9953
10419
|
//#region package.json
|
|
9954
|
-
var version = "12.
|
|
10420
|
+
var version = "12.3.0";
|
|
9955
10421
|
//#endregion
|
|
9956
10422
|
//#region src/workos.ts
|
|
9957
10423
|
const DEFAULT_HOSTNAME = "api.workos.com";
|
|
@@ -10055,7 +10521,7 @@ var WorkOS = class {
|
|
|
10055
10521
|
timeout: options.timeout,
|
|
10056
10522
|
maxRetries: options.maxRetries,
|
|
10057
10523
|
headers
|
|
10058
|
-
});
|
|
10524
|
+
}, options.fetchFn);
|
|
10059
10525
|
}
|
|
10060
10526
|
get version() {
|
|
10061
10527
|
return version;
|
|
@@ -10099,9 +10565,11 @@ var WorkOS = class {
|
|
|
10099
10565
|
res = await this.client.get(path, {
|
|
10100
10566
|
params: options.query,
|
|
10101
10567
|
headers: requestHeaders,
|
|
10102
|
-
maxRetries: options.maxRetries
|
|
10568
|
+
maxRetries: options.maxRetries,
|
|
10569
|
+
signal: options.signal
|
|
10103
10570
|
});
|
|
10104
10571
|
} catch (error) {
|
|
10572
|
+
options.signal?.throwIfAborted();
|
|
10105
10573
|
this.handleHttpError({
|
|
10106
10574
|
path,
|
|
10107
10575
|
error
|
|
@@ -10181,6 +10649,7 @@ var WorkOS = class {
|
|
|
10181
10649
|
* Everything else (a `ParseError` for malformed JSON, a network failure
|
|
10182
10650
|
* mid-body) propagates unchanged.
|
|
10183
10651
|
*/
|
|
10652
|
+
/** @internal */
|
|
10184
10653
|
async readResponseJSON(path, response) {
|
|
10185
10654
|
try {
|
|
10186
10655
|
return await response.toJSON();
|
|
@@ -10195,6 +10664,7 @@ var WorkOS = class {
|
|
|
10195
10664
|
emitWarning(warning) {
|
|
10196
10665
|
console.warn(`WorkOS: ${warning}`);
|
|
10197
10666
|
}
|
|
10667
|
+
/** @internal */
|
|
10198
10668
|
handleHttpError({ path, error }) {
|
|
10199
10669
|
if (!(error instanceof HttpClientError)) throw new Error(`Unexpected error: ${error}`, { cause: error });
|
|
10200
10670
|
const { response } = error;
|
|
@@ -10362,6 +10832,6 @@ function createWorkOS(options) {
|
|
|
10362
10832
|
return new WorkOS(options);
|
|
10363
10833
|
}
|
|
10364
10834
|
//#endregion
|
|
10365
|
-
export {
|
|
10835
|
+
export { AuthenticationException as A, SignatureVerificationException as C, NoApiKeyProvidedException as D, NotFoundException as E, SubtleCryptoProvider as F, GenericServerException as M, ApiKeyRequiredException as N, ConflictException as O, FetchHttpClient as P, UnauthorizedException as S, OauthException as T, PKCE as _, ItContactIntent as a, Actions as b, GenerateLinkIntent as c, FeatureFlagsRuntimeClient as d, CreateRuleWithTargetsError as f, AuthenticateWithSessionCookieFailureReason as g, serializeRevokeSessionOptions as h, OrganizationDomainVerificationStrategy as i, isAuthenticationErrorData as j, BadRequestException as k, UpdateAuditLogsRetentionRetentionPeriod as l, RefreshSessionFailureReason as m, ConnectionType as n, DomainDataState as o, CookieSession as p, OrganizationDomainState as r, DirectoryUserWithGroupsState as s, createWorkOS as t, WorkOS as u, Webhooks as v, RateLimitExceededException as w, UnprocessableEntityException as x, AutoPaginatable as y };
|
|
10366
10836
|
|
|
10367
|
-
//# sourceMappingURL=factory-
|
|
10837
|
+
//# sourceMappingURL=factory-ND4UZ76L.mjs.map
|