@workos-inc/node 10.0.0 → 10.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.
@@ -411,6 +411,8 @@ const AUTHENTICATION_ERROR_CODES = new Set([
411
411
  "mfa_enrollment",
412
412
  "mfa_challenge",
413
413
  "mfa_verification",
414
+ "radar_email_challenge",
415
+ "radar_sms_challenge",
414
416
  "sso_required"
415
417
  ]);
416
418
  function parseAuthenticationErrorCode(value) {
@@ -429,12 +431,14 @@ var AuthenticationException = class extends GenericServerException {
429
431
  name = "AuthenticationException";
430
432
  code;
431
433
  pendingAuthenticationToken;
434
+ radarChallengeId;
432
435
  constructor(status, rawData, requestID) {
433
436
  const code = getAuthenticationErrorCode(rawData);
434
437
  super(status, rawData.message ?? rawData.error_description, rawData, requestID);
435
438
  this.rawData = rawData;
436
439
  this.code = code;
437
440
  this.pendingAuthenticationToken = rawData.pending_authentication_token;
441
+ this.radarChallengeId = rawData.radar_challenge_id;
438
442
  }
439
443
  };
440
444
  //#endregion
@@ -667,6 +671,32 @@ const serializeAuthenticateWithMagicAuthOptions = (options) => ({
667
671
  invitation_token: options.invitationToken,
668
672
  link_authorization_code: options.linkAuthorizationCode,
669
673
  ip_address: options.ipAddress,
674
+ user_agent: options.userAgent,
675
+ radar_auth_attempt_id: options.radarAuthAttemptId
676
+ });
677
+ //#endregion
678
+ //#region src/user-management/serializers/authenticate-with-radar-email-challenge-options.serializer.ts
679
+ const serializeAuthenticateWithRadarEmailChallengeOptions = (options) => ({
680
+ grant_type: "urn:workos:oauth:grant-type:radar-email-challenge:code",
681
+ client_id: options.clientId,
682
+ client_secret: options.clientSecret,
683
+ code: options.code,
684
+ radar_challenge_id: options.radarChallengeId,
685
+ pending_authentication_token: options.pendingAuthenticationToken,
686
+ ip_address: options.ipAddress,
687
+ user_agent: options.userAgent
688
+ });
689
+ //#endregion
690
+ //#region src/user-management/serializers/authenticate-with-radar-sms-challenge-options.serializer.ts
691
+ const serializeAuthenticateWithRadarSmsChallengeOptions = (options) => ({
692
+ grant_type: "urn:workos:oauth:grant-type:radar-sms-challenge:code",
693
+ client_id: options.clientId,
694
+ client_secret: options.clientSecret,
695
+ code: options.code,
696
+ verification_id: options.verificationId,
697
+ phone_number: options.phoneNumber,
698
+ pending_authentication_token: options.pendingAuthenticationToken,
699
+ ip_address: options.ipAddress,
670
700
  user_agent: options.userAgent
671
701
  });
672
702
  //#endregion
@@ -679,7 +709,8 @@ const serializeAuthenticateWithPasswordOptions = (options) => ({
679
709
  password: options.password,
680
710
  invitation_token: options.invitationToken,
681
711
  ip_address: options.ipAddress,
682
- user_agent: options.userAgent
712
+ user_agent: options.userAgent,
713
+ radar_auth_attempt_id: options.radarAuthAttemptId
683
714
  });
684
715
  //#endregion
685
716
  //#region src/user-management/serializers/authenticate-with-refresh-token.options.serializer.ts
@@ -783,6 +814,7 @@ const deserializeUser = (user) => ({
783
814
  id: user.id,
784
815
  email: user.email,
785
816
  emailVerified: user.email_verified,
817
+ name: user.name ?? null,
786
818
  firstName: user.first_name,
787
819
  profilePictureUrl: user.profile_picture_url,
788
820
  lastName: user.last_name,
@@ -812,7 +844,10 @@ const deserializeAuthenticationResponse = (authenticationResponse) => {
812
844
  //#region src/user-management/serializers/create-magic-auth-options.serializer.ts
813
845
  const serializeCreateMagicAuthOptions = (options) => ({
814
846
  email: options.email,
815
- invitation_token: options.invitationToken
847
+ invitation_token: options.invitationToken,
848
+ ip_address: options.ipAddress,
849
+ user_agent: options.userAgent,
850
+ radar_auth_attempt_id: options.radarAuthAttemptId
816
851
  });
817
852
  //#endregion
818
853
  //#region src/user-management/serializers/create-password-reset-options.serializer.ts
@@ -954,17 +989,30 @@ const serializeCreateUserOptions = (options) => ({
954
989
  password: options.password,
955
990
  password_hash: options.passwordHash,
956
991
  password_hash_type: options.passwordHashType,
992
+ name: options.name,
957
993
  first_name: options.firstName,
958
994
  last_name: options.lastName,
959
995
  email_verified: options.emailVerified,
960
996
  external_id: options.externalId,
961
- metadata: options.metadata
997
+ metadata: options.metadata,
998
+ ip_address: options.ipAddress,
999
+ user_agent: options.userAgent
1000
+ });
1001
+ //#endregion
1002
+ //#region src/user-management/serializers/send-radar-sms-challenge-options.serializer.ts
1003
+ const serializeSendRadarSmsChallengeOptions = (options) => ({
1004
+ user_id: options.userId,
1005
+ pending_authentication_token: options.pendingAuthenticationToken,
1006
+ phone_number: options.phoneNumber,
1007
+ ip_address: options.ipAddress,
1008
+ user_agent: options.userAgent
962
1009
  });
963
1010
  //#endregion
964
1011
  //#region src/user-management/serializers/update-user-options.serializer.ts
965
1012
  const serializeUpdateUserOptions = (options) => ({
966
1013
  email: options.email,
967
1014
  email_verified: options.emailVerified,
1015
+ name: options.name,
968
1016
  first_name: options.firstName,
969
1017
  last_name: options.lastName,
970
1018
  password: options.password,
@@ -1007,6 +1055,7 @@ const deserializeUserData = (userData) => {
1007
1055
  return {
1008
1056
  object: userData.object,
1009
1057
  email: userData.email,
1058
+ name: userData.name ?? null,
1010
1059
  firstName: userData.first_name,
1011
1060
  lastName: userData.last_name
1012
1061
  };
@@ -1287,6 +1336,7 @@ const deserializeProfile = (profile) => ({
1287
1336
  connectionId: profile.connection_id,
1288
1337
  connectionType: profile.connection_type,
1289
1338
  email: profile.email,
1339
+ ...profile.name !== void 0 && { name: profile.name },
1290
1340
  ...profile.first_name !== void 0 && { firstName: profile.first_name },
1291
1341
  ...profile.last_name !== void 0 && { lastName: profile.last_name },
1292
1342
  ...profile.role !== void 0 && { role: profile.role },
@@ -2232,8 +2282,7 @@ var Connect = class {
2232
2282
  * @throws {UnprocessableEntityException} 422
2233
2283
  */
2234
2284
  async listApplications(options) {
2235
- const paginationOptions = options;
2236
- return new AutoPaginatable(await fetchAndDeserialize(this.workos, "/connect/applications", deserializeConnectApplication, options ? serializeListApplicationsOptions(options) : void 0), (params) => fetchAndDeserialize(this.workos, "/connect/applications", deserializeConnectApplication, params), paginationOptions);
2285
+ return new AutoPaginatable(await fetchAndDeserialize(this.workos, "/connect/applications", deserializeConnectApplication, options ? serializeListApplicationsOptions(options) : void 0), (params) => fetchAndDeserialize(this.workos, "/connect/applications", deserializeConnectApplication, params), options ? serializeListApplicationsOptions(options) : void 0);
2237
2286
  }
2238
2287
  /**
2239
2288
  * Create a Connect Application
@@ -4139,14 +4188,18 @@ var UserManagement = class {
4139
4188
  *
4140
4189
  * Create a new user in the current environment.
4141
4190
  * @param payload - Object containing email.
4142
- * @returns {Promise<User>}
4191
+ * @returns {Promise<CreateUserResponse>}
4143
4192
  * @throws {BadRequestException} 400
4144
4193
  * @throws {NotFoundException} 404
4145
4194
  * @throws {UnprocessableEntityException} 422
4146
4195
  */
4147
4196
  async createUser(payload) {
4148
4197
  const { data } = await this.workos.post("/user_management/users", serializeCreateUserOptions(payload));
4149
- return deserializeUser(data);
4198
+ const { radar_auth_attempt_id, ...userResponse } = data;
4199
+ return {
4200
+ ...deserializeUser(userResponse),
4201
+ ...radar_auth_attempt_id ? { radarAuthAttemptId: radar_auth_attempt_id } : void 0
4202
+ };
4150
4203
  }
4151
4204
  /** Authenticate with magic auth. */
4152
4205
  async authenticateWithMagicAuth(payload) {
@@ -4292,6 +4345,42 @@ var UserManagement = class {
4292
4345
  session
4293
4346
  });
4294
4347
  }
4348
+ /** Send a Radar SMS challenge. */
4349
+ async sendRadarSmsChallenge(payload) {
4350
+ const { data } = await this.workos.post("/user_management/radar_challenges", serializeSendRadarSmsChallengeOptions(payload));
4351
+ return {
4352
+ verificationId: data.verification_id,
4353
+ phoneNumber: data.phone_number
4354
+ };
4355
+ }
4356
+ /** Authenticate with Radar SMS challenge. */
4357
+ async authenticateWithRadarSmsChallenge(payload) {
4358
+ const { session, clientId, ...remainingPayload } = payload;
4359
+ const resolvedClientId = this.resolveClientId(clientId);
4360
+ const { data } = await this.workos.post("/user_management/authenticate", serializeAuthenticateWithRadarSmsChallengeOptions({
4361
+ ...remainingPayload,
4362
+ clientId: resolvedClientId,
4363
+ clientSecret: this.workos.key
4364
+ }));
4365
+ return this.prepareAuthenticationResponse({
4366
+ authenticationResponse: deserializeAuthenticationResponse(data),
4367
+ session
4368
+ });
4369
+ }
4370
+ /** Authenticate with Radar email challenge. */
4371
+ async authenticateWithRadarEmailChallenge(payload) {
4372
+ const { session, clientId, ...remainingPayload } = payload;
4373
+ const resolvedClientId = this.resolveClientId(clientId);
4374
+ const { data } = await this.workos.post("/user_management/authenticate", serializeAuthenticateWithRadarEmailChallengeOptions({
4375
+ ...remainingPayload,
4376
+ clientId: resolvedClientId,
4377
+ clientSecret: this.workos.key
4378
+ }));
4379
+ return this.prepareAuthenticationResponse({
4380
+ authenticationResponse: deserializeAuthenticationResponse(data),
4381
+ session
4382
+ });
4383
+ }
4295
4384
  async authenticateWithSessionCookie({ sessionData, cookiePassword = getEnv("WORKOS_COOKIE_PASSWORD") }) {
4296
4385
  if (!cookiePassword) throw new Error("Cookie password is required");
4297
4386
  if (!await this.getJWKS()) throw new Error("Must provide clientId to initialize JWKS");
@@ -4406,14 +4495,18 @@ var UserManagement = class {
4406
4495
  *
4407
4496
  * Creates a one-time authentication code that can be sent to the user's email address. The code expires in 10 minutes. To verify the code, [authenticate the user with Magic Auth](https://workos.com/docs/reference/authkit/authentication/magic-auth).
4408
4497
  * @param options - Object containing email.
4409
- * @returns {Promise<MagicAuth>}
4498
+ * @returns {Promise<CreateMagicAuthResponse>}
4410
4499
  * @throws {BadRequestException} 400
4411
4500
  * @throws {UnprocessableEntityException} 422
4412
4501
  * @throws {RateLimitExceededException} 429
4413
4502
  */
4414
4503
  async createMagicAuth(options) {
4415
4504
  const { data } = await this.workos.post("/user_management/magic_auth", serializeCreateMagicAuthOptions({ ...options }));
4416
- return deserializeMagicAuth(data);
4505
+ const { radar_auth_attempt_id, ...magicAuthResponse } = data;
4506
+ return {
4507
+ ...deserializeMagicAuth(magicAuthResponse),
4508
+ ...radar_auth_attempt_id ? { radarAuthAttemptId: radar_auth_attempt_id } : void 0
4509
+ };
4417
4510
  }
4418
4511
  /**
4419
4512
  * Verify email
@@ -5345,13 +5438,15 @@ var Groups = class {
5345
5438
  }
5346
5439
  };
5347
5440
  //#endregion
5348
- //#region src/widgets/interfaces/get-token.ts
5349
- const serializeGetTokenOptions = (options) => ({
5350
- organization_id: options.organizationId,
5351
- user_id: options.userId,
5352
- scopes: options.scopes
5441
+ //#region src/widgets/serializers/widget-session-token-response.serializer.ts
5442
+ const deserializeWidgetSessionTokenResponse = (response) => ({ token: response.token });
5443
+ //#endregion
5444
+ //#region src/widgets/serializers/widget-session-token.serializer.ts
5445
+ const serializeGetTokenOptions = (model) => ({
5446
+ organization_id: model.organizationId,
5447
+ user_id: model.userId,
5448
+ scopes: model.scopes
5353
5449
  });
5354
- const deserializeGetTokenResponse = (data) => ({ token: data.token });
5355
5450
  //#endregion
5356
5451
  //#region src/widgets/widgets.ts
5357
5452
  var Widgets = class {
@@ -5363,15 +5458,16 @@ var Widgets = class {
5363
5458
  * Generate a widget token
5364
5459
  *
5365
5460
  * Generate a widget token scoped to an organization and user with the specified scopes.
5366
- * @param payload - Object containing organizationId.
5367
- * @returns {Promise<GetTokenResponse>}
5461
+ * @param options - The request options.
5462
+ * @returns {Promise<WidgetSessionTokenResponse>}
5368
5463
  * @throws {BadRequestException} 400
5369
5464
  * @throws {NotFoundException} 404
5370
5465
  * @throws {UnprocessableEntityException} 422
5371
5466
  */
5372
- async createToken(payload) {
5467
+ async createToken(options) {
5468
+ const payload = options;
5373
5469
  const { data } = await this.workos.post("/widgets/token", serializeGetTokenOptions(payload));
5374
- return deserializeGetTokenResponse(data);
5470
+ return deserializeWidgetSessionTokenResponse(data);
5375
5471
  }
5376
5472
  };
5377
5473
  //#endregion
@@ -6809,7 +6905,7 @@ var Vault = class {
6809
6905
  };
6810
6906
  //#endregion
6811
6907
  //#region package.json
6812
- var version = "10.0.0";
6908
+ var version = "10.2.0";
6813
6909
  //#endregion
6814
6910
  //#region src/workos.ts
6815
6911
  const DEFAULT_HOSTNAME = "api.workos.com";
@@ -7187,6 +7283,6 @@ function createWorkOS(options) {
7187
7283
  return new WorkOS(options);
7188
7284
  }
7189
7285
  //#endregion
7190
- export { GenericServerException as A, OauthException as C, BadRequestException as D, ConflictException as E, FetchHttpClient as M, SubtleCryptoProvider as N, AuthenticationException as O, RateLimitExceededException as S, NoApiKeyProvidedException as T, AutoPaginatable as _, DomainDataState as a, UnauthorizedException as b, deserializeGetTokenResponse as c, CookieSession as d, RefreshSessionFailureReason as f, Webhooks as g, PKCE as h, OrganizationDomainVerificationStrategy as i, ApiKeyRequiredException as j, isAuthenticationErrorData as k, serializeGetTokenOptions as l, AuthenticateWithSessionCookieFailureReason as m, ConnectionType as n, GenerateLinkIntent as o, serializeRevokeSessionOptions as p, OrganizationDomainState as r, WorkOS as s, createWorkOS as t, FeatureFlagsRuntimeClient as u, Actions as v, NotFoundException as w, SignatureVerificationException as x, UnprocessableEntityException as y };
7286
+ export { FetchHttpClient as A, NoApiKeyProvidedException as C, isAuthenticationErrorData as D, AuthenticationException as E, GenericServerException as O, NotFoundException as S, BadRequestException as T, UnprocessableEntityException as _, DomainDataState as a, RateLimitExceededException as b, FeatureFlagsRuntimeClient as c, serializeRevokeSessionOptions as d, AuthenticateWithSessionCookieFailureReason as f, Actions as g, AutoPaginatable as h, OrganizationDomainVerificationStrategy as i, SubtleCryptoProvider as j, ApiKeyRequiredException as k, CookieSession as l, Webhooks as m, ConnectionType as n, GenerateLinkIntent as o, PKCE as p, OrganizationDomainState as r, WorkOS as s, createWorkOS as t, RefreshSessionFailureReason as u, UnauthorizedException as v, ConflictException as w, OauthException as x, SignatureVerificationException as y };
7191
7287
 
7192
- //# sourceMappingURL=factory-fIHNXxrd.mjs.map
7288
+ //# sourceMappingURL=factory-CenLS49y.mjs.map