@workos-inc/node 12.1.0 → 12.2.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/lib/{factory-2iQbHj6d.d.cts → factory-BnDIhZYD.d.cts} +74 -8
- package/lib/{factory-2iQbHj6d.d.mts → factory-BnDIhZYD.d.mts} +74 -8
- package/lib/{factory-Dagoc4rv.cjs → factory-CEEOW8zX.cjs} +94 -37
- package/lib/factory-CEEOW8zX.cjs.map +1 -0
- package/lib/{factory-99SwwalC.mjs → factory-lX3X15SU.mjs} +94 -37
- package/lib/factory-lX3X15SU.mjs.map +1 -0
- package/lib/index.cjs +1 -1
- package/lib/index.d.cts +2 -2
- package/lib/index.d.mts +2 -2
- package/lib/index.mjs +1 -1
- package/lib/index.worker.cjs +1 -1
- package/lib/index.worker.d.cts +1 -1
- package/lib/index.worker.d.mts +1 -1
- package/lib/index.worker.mjs +1 -1
- package/package.json +1 -1
- package/lib/factory-99SwwalC.mjs.map +0 -1
- package/lib/factory-Dagoc4rv.cjs.map +0 -1
|
@@ -1340,18 +1340,17 @@ var AutoPaginatable = class {
|
|
|
1340
1340
|
get listMetadata() {
|
|
1341
1341
|
return this.list.listMetadata;
|
|
1342
1342
|
}
|
|
1343
|
-
async *generatePages(
|
|
1343
|
+
async *generatePages(after) {
|
|
1344
1344
|
const { before, ...options } = this.options;
|
|
1345
1345
|
const result = await this.apiCall({
|
|
1346
1346
|
...options,
|
|
1347
1347
|
limit: 100,
|
|
1348
|
-
|
|
1349
|
-
after: params.after
|
|
1348
|
+
after
|
|
1350
1349
|
});
|
|
1351
1350
|
yield result.data;
|
|
1352
1351
|
if (result.listMetadata.after) {
|
|
1353
1352
|
await new Promise((resolve) => setTimeout(resolve, 350));
|
|
1354
|
-
yield* this.generatePages(
|
|
1353
|
+
yield* this.generatePages(result.listMetadata.after);
|
|
1355
1354
|
}
|
|
1356
1355
|
}
|
|
1357
1356
|
/**
|
|
@@ -1359,12 +1358,9 @@ var AutoPaginatable = class {
|
|
|
1359
1358
|
* Returns the first result if `options.limit` is passed to the first request.
|
|
1360
1359
|
*/
|
|
1361
1360
|
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);
|
|
1361
|
+
if (this.options.limit || !this.listMetadata.after) return this.data;
|
|
1362
|
+
const results = [...this.data];
|
|
1363
|
+
for await (const page of this.generatePages(this.listMetadata.after)) results.push(...page);
|
|
1368
1364
|
return results;
|
|
1369
1365
|
}
|
|
1370
1366
|
};
|
|
@@ -3260,6 +3256,15 @@ var ApiKeys = class {
|
|
|
3260
3256
|
//#region src/connect/serializers/external-auth-complete-response.serializer.ts
|
|
3261
3257
|
const deserializeExternalAuthCompleteResponse = (response) => ({ redirectUri: response.redirect_uri });
|
|
3262
3258
|
//#endregion
|
|
3259
|
+
//#region src/connect/serializers/token-exchange-response.serializer.ts
|
|
3260
|
+
const deserializeTokenExchangeResponse = (response) => ({
|
|
3261
|
+
accessToken: response.access_token,
|
|
3262
|
+
issuedTokenType: response.issued_token_type,
|
|
3263
|
+
tokenType: response.token_type,
|
|
3264
|
+
expiresIn: response.expires_in,
|
|
3265
|
+
...response.scope !== void 0 && { scope: response.scope }
|
|
3266
|
+
});
|
|
3267
|
+
//#endregion
|
|
3263
3268
|
//#region src/connect/serializers/connect-application-redirect-uri.serializer.ts
|
|
3264
3269
|
const deserializeConnectApplicationRedirectUri = (response) => ({
|
|
3265
3270
|
uri: response.uri,
|
|
@@ -3435,6 +3440,73 @@ var Connect = class {
|
|
|
3435
3440
|
return deserializeExternalAuthCompleteResponse(data);
|
|
3436
3441
|
}
|
|
3437
3442
|
/**
|
|
3443
|
+
* Exchange an access token for one issued to another Resource Indicator
|
|
3444
|
+
*
|
|
3445
|
+
* Performs an [RFC 8693](https://datatracker.ietf.org/doc/html/rfc8693) token exchange against the environment's
|
|
3446
|
+
* `/oauth2/token` endpoint, authenticating as a first-party Connect Application with its client ID and client
|
|
3447
|
+
* secret. The issued access token keeps the subject token's user and consent and is audienced to `resource`.
|
|
3448
|
+
*
|
|
3449
|
+
* Unlike other SDK methods this does not call the WorkOS API with your API key: the request goes to the
|
|
3450
|
+
* environment's issuer (AuthKit domain) using the Connect Application's credentials. The client's `fetchFn`,
|
|
3451
|
+
* `timeout`, `maxRetries` and `config` options still apply.
|
|
3452
|
+
* @param options - Object containing issuer, clientId, clientSecret, subjectToken, resource, scope.
|
|
3453
|
+
* @returns {Promise<TokenExchangeResponse>}
|
|
3454
|
+
* @throws {OauthException} `invalid_client`, `unauthorized_client`, `invalid_grant`, `invalid_target`,
|
|
3455
|
+
* `invalid_scope`, `unsupported_grant_type`
|
|
3456
|
+
*/
|
|
3457
|
+
async exchangeToken(options) {
|
|
3458
|
+
const { issuer, clientId, clientSecret, subjectToken, resource, scope } = options;
|
|
3459
|
+
const path = "/oauth2/token";
|
|
3460
|
+
const client = this.createIssuerHttpClient(issuer);
|
|
3461
|
+
const body = new URLSearchParams({
|
|
3462
|
+
client_id: clientId,
|
|
3463
|
+
client_secret: clientSecret,
|
|
3464
|
+
grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
|
|
3465
|
+
subject_token: subjectToken,
|
|
3466
|
+
subject_token_type: "urn:ietf:params:oauth:token-type:access_token",
|
|
3467
|
+
requested_token_type: "urn:ietf:params:oauth:token-type:access_token",
|
|
3468
|
+
resource,
|
|
3469
|
+
...scope !== void 0 && { scope }
|
|
3470
|
+
});
|
|
3471
|
+
let res;
|
|
3472
|
+
try {
|
|
3473
|
+
res = await client.post(path, body, {});
|
|
3474
|
+
} catch (error) {
|
|
3475
|
+
this.throwOauthErrorFromTokenEndpoint(error);
|
|
3476
|
+
this.workos.handleHttpError({
|
|
3477
|
+
path,
|
|
3478
|
+
error
|
|
3479
|
+
});
|
|
3480
|
+
throw error;
|
|
3481
|
+
}
|
|
3482
|
+
const data = await this.workos.readResponseJSON(path, res);
|
|
3483
|
+
return deserializeTokenExchangeResponse(data);
|
|
3484
|
+
}
|
|
3485
|
+
/**
|
|
3486
|
+
* Builds an HTTP client for the environment's issuer that carries the SDK's
|
|
3487
|
+
* transport settings (`fetchFn`, `timeout`, `maxRetries`, `config`) but not
|
|
3488
|
+
* the WorkOS API key.
|
|
3489
|
+
*/
|
|
3490
|
+
createIssuerHttpClient(issuer) {
|
|
3491
|
+
const { config, timeout, maxRetries, fetchFn } = this.workos.options;
|
|
3492
|
+
return new FetchHttpClient(issuer, {
|
|
3493
|
+
...config,
|
|
3494
|
+
timeout,
|
|
3495
|
+
maxRetries,
|
|
3496
|
+
headers: { "User-Agent": `workos-node/${this.workos.version}` }
|
|
3497
|
+
}, fetchFn);
|
|
3498
|
+
}
|
|
3499
|
+
/**
|
|
3500
|
+
* The token endpoint reports client authentication failures as a 401 with
|
|
3501
|
+
* an RFC 6749 error body; surface that as an `OauthException` instead of the
|
|
3502
|
+
* generic `UnauthorizedException` used for API-key failures.
|
|
3503
|
+
*/
|
|
3504
|
+
throwOauthErrorFromTokenEndpoint(error) {
|
|
3505
|
+
if (!(error instanceof HttpClientError) || !error.response) return;
|
|
3506
|
+
const { status, data, headers } = error.response;
|
|
3507
|
+
if (status === 401 && (data.error || data.error_description)) throw new OauthException(status, headers.get("X-Request-ID") ?? "", data.error, data.error_description, data);
|
|
3508
|
+
}
|
|
3509
|
+
/**
|
|
3438
3510
|
* List Connect Applications
|
|
3439
3511
|
*
|
|
3440
3512
|
* List all Connect Applications in the current environment with optional filtering.
|
|
@@ -3737,8 +3809,7 @@ const serializeListEventOptions = (options) => ({
|
|
|
3737
3809
|
range_start: options.rangeStart,
|
|
3738
3810
|
range_end: options.rangeEnd,
|
|
3739
3811
|
limit: options.limit,
|
|
3740
|
-
after: options.after
|
|
3741
|
-
order: options.order
|
|
3812
|
+
after: options.after
|
|
3742
3813
|
});
|
|
3743
3814
|
//#endregion
|
|
3744
3815
|
//#region src/events/events.ts
|
|
@@ -4169,6 +4240,7 @@ const deserializeDataIntegrationFinishConnectionResponse = (response) => ({ conn
|
|
|
4169
4240
|
//#region src/pipes/serializers/data-integration-authorize-url-response.serializer.ts
|
|
4170
4241
|
const deserializeDataIntegrationAuthorizeUrlResponse = (response) => ({
|
|
4171
4242
|
url: response.url,
|
|
4243
|
+
state: response.state ?? "",
|
|
4172
4244
|
completion: response.completion
|
|
4173
4245
|
});
|
|
4174
4246
|
//#endregion
|
|
@@ -6466,12 +6538,12 @@ var CookieSession = class {
|
|
|
6466
6538
|
authenticated: false,
|
|
6467
6539
|
reason: "invalid_session_cookie"
|
|
6468
6540
|
};
|
|
6469
|
-
|
|
6541
|
+
const claims = await this.userManagement.verifyAccessToken(session.accessToken);
|
|
6542
|
+
if (!claims) return {
|
|
6470
6543
|
authenticated: false,
|
|
6471
6544
|
reason: "invalid_jwt"
|
|
6472
6545
|
};
|
|
6473
|
-
const {
|
|
6474
|
-
const { sid: sessionId, org_id: organizationId, role, roles, permissions, entitlements, feature_flags: featureFlags } = decodeJwt(session.accessToken);
|
|
6546
|
+
const { sid: sessionId, org_id: organizationId, role, roles, permissions, entitlements, feature_flags: featureFlags } = claims;
|
|
6475
6547
|
return {
|
|
6476
6548
|
authenticated: true,
|
|
6477
6549
|
sessionId,
|
|
@@ -6561,19 +6633,6 @@ var CookieSession = class {
|
|
|
6561
6633
|
returnTo
|
|
6562
6634
|
});
|
|
6563
6635
|
}
|
|
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
6636
|
};
|
|
6578
6637
|
/**
|
|
6579
6638
|
* Classifies an error thrown while refreshing as a terminal authentication
|
|
@@ -6908,8 +6967,6 @@ var UserManagement = class UserManagement {
|
|
|
6908
6967
|
}
|
|
6909
6968
|
async authenticateWithSessionCookie({ sessionData, cookiePassword = getEnv("WORKOS_COOKIE_PASSWORD") }) {
|
|
6910
6969
|
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
6970
|
if (!sessionData) return {
|
|
6914
6971
|
authenticated: false,
|
|
6915
6972
|
reason: "no_session_cookie_provided"
|
|
@@ -6919,11 +6976,12 @@ var UserManagement = class UserManagement {
|
|
|
6919
6976
|
authenticated: false,
|
|
6920
6977
|
reason: "invalid_session_cookie"
|
|
6921
6978
|
};
|
|
6922
|
-
|
|
6979
|
+
const claims = await this.verifyAccessToken(session.accessToken);
|
|
6980
|
+
if (!claims) return {
|
|
6923
6981
|
authenticated: false,
|
|
6924
6982
|
reason: "invalid_jwt"
|
|
6925
6983
|
};
|
|
6926
|
-
const { sid: sessionId, org_id: organizationId, role, roles, permissions, entitlements, feature_flags: featureFlags } =
|
|
6984
|
+
const { sid: sessionId, org_id: organizationId, role, roles, permissions, entitlements, feature_flags: featureFlags } = claims;
|
|
6927
6985
|
return {
|
|
6928
6986
|
authenticated: true,
|
|
6929
6987
|
sessionId,
|
|
@@ -7003,9 +7061,6 @@ var UserManagement = class UserManagement {
|
|
|
7003
7061
|
if (!(e instanceof Error) || !("code" in e) || typeof e.code !== "string") return false;
|
|
7004
7062
|
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
7063
|
}
|
|
7006
|
-
async isValidJwt(accessToken) {
|
|
7007
|
-
return await this.verifyJwt(accessToken) !== null;
|
|
7008
|
-
}
|
|
7009
7064
|
async prepareAuthenticationResponse({ authenticationResponse, session }) {
|
|
7010
7065
|
if (session?.sealSession) {
|
|
7011
7066
|
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).");
|
|
@@ -9951,7 +10006,7 @@ var Vault = class {
|
|
|
9951
10006
|
};
|
|
9952
10007
|
//#endregion
|
|
9953
10008
|
//#region package.json
|
|
9954
|
-
var version = "12.
|
|
10009
|
+
var version = "12.2.0";
|
|
9955
10010
|
//#endregion
|
|
9956
10011
|
//#region src/workos.ts
|
|
9957
10012
|
const DEFAULT_HOSTNAME = "api.workos.com";
|
|
@@ -10181,6 +10236,7 @@ var WorkOS = class {
|
|
|
10181
10236
|
* Everything else (a `ParseError` for malformed JSON, a network failure
|
|
10182
10237
|
* mid-body) propagates unchanged.
|
|
10183
10238
|
*/
|
|
10239
|
+
/** @internal */
|
|
10184
10240
|
async readResponseJSON(path, response) {
|
|
10185
10241
|
try {
|
|
10186
10242
|
return await response.toJSON();
|
|
@@ -10195,6 +10251,7 @@ var WorkOS = class {
|
|
|
10195
10251
|
emitWarning(warning) {
|
|
10196
10252
|
console.warn(`WorkOS: ${warning}`);
|
|
10197
10253
|
}
|
|
10254
|
+
/** @internal */
|
|
10198
10255
|
handleHttpError({ path, error }) {
|
|
10199
10256
|
if (!(error instanceof HttpClientError)) throw new Error(`Unexpected error: ${error}`, { cause: error });
|
|
10200
10257
|
const { response } = error;
|
|
@@ -10364,4 +10421,4 @@ function createWorkOS(options) {
|
|
|
10364
10421
|
//#endregion
|
|
10365
10422
|
export { isAuthenticationErrorData as A, RateLimitExceededException as C, ConflictException as D, NoApiKeyProvidedException as E, ApiKeyRequiredException as M, FetchHttpClient as N, BadRequestException as O, SubtleCryptoProvider as P, SignatureVerificationException as S, NotFoundException as T, Webhooks as _, ItContactIntent as a, UnprocessableEntityException as b, GenerateLinkIntent as c, FeatureFlagsRuntimeClient as d, CookieSession as f, PKCE as g, AuthenticateWithSessionCookieFailureReason as h, OrganizationDomainVerificationStrategy as i, GenericServerException as j, AuthenticationException as k, UpdateAuditLogsRetentionRetentionPeriod as l, serializeRevokeSessionOptions as m, ConnectionType as n, DomainDataState as o, RefreshSessionFailureReason as p, OrganizationDomainState as r, DirectoryUserWithGroupsState as s, createWorkOS as t, WorkOS as u, AutoPaginatable as v, OauthException as w, UnauthorizedException as x, Actions as y };
|
|
10366
10423
|
|
|
10367
|
-
//# sourceMappingURL=factory-
|
|
10424
|
+
//# sourceMappingURL=factory-lX3X15SU.mjs.map
|