@finueva/auth 0.18.1 → 0.20.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/dist/index.js CHANGED
@@ -2537,6 +2537,11 @@ const messages = {
2537
2537
  invalid_credentials: "The credentials are invalid.",
2538
2538
  invalid_auth_input: "The authentication input is invalid.",
2539
2539
  account_conflict: "The account is not available.",
2540
+ google_recovery_in_progress: "A Google connection is already being completed. Return to that sign-in, or wait up to ten minutes and restart.",
2541
+ google_recovery_not_required: "Google account recovery is not required.",
2542
+ google_recovery_invalid: "The Google account recovery request is invalid.",
2543
+ google_recovery_expired: "Google account recovery has expired. Start Google sign-in again.",
2544
+ google_recovery_account_mismatch: "Sign in to the existing account associated with this Google identity.",
2540
2545
  password_reset_invalid: "The password reset request is invalid.",
2541
2546
  authentication_required: "Authentication is required.",
2542
2547
  request_origin_denied: "The request origin is not allowed.",
@@ -2557,7 +2562,18 @@ const messages = {
2557
2562
  platform_target_unavailable: "The platform administration target is unavailable.",
2558
2563
  platform_quorum_unavailable: "Platform administration quorum is unavailable.",
2559
2564
  platform_recovery_required: "Platform administration requires separate recovery.",
2560
- identity_authority_unavailable: "Authentication is temporarily unavailable."
2565
+ identity_authority_unavailable: "Authentication is temporarily unavailable.",
2566
+ two_factor_required: "A second authentication factor is required.",
2567
+ two_factor_code_invalid: "The verification code is invalid.",
2568
+ two_factor_challenge_expired: "The second-factor challenge has ended. Sign in again.",
2569
+ two_factor_locked: "Second-factor verification is temporarily locked.",
2570
+ recent_sign_in_required: "A recent sign-in is required.",
2571
+ enterprise_recovery_required: "Enterprise administration evidence requires operator recovery.",
2572
+ recent_authentication_required: "A ready recent-authentication action is required.",
2573
+ organization_closure_confirmation_mismatch: "The confirmation does not match the organization.",
2574
+ organization_closure_cancellation_ended: "The closure cancellation period has ended.",
2575
+ ceremony_return_refused: "The return address is not registered for this application.",
2576
+ password_sign_in_required: "A password sign-in method is required for this passkey change."
2561
2577
  };
2562
2578
  var AuthError = class extends Error {
2563
2579
  code;
@@ -2965,7 +2981,7 @@ function normalizeIdInput(value) {
2965
2981
  return value;
2966
2982
  }
2967
2983
  function normalizeOrganization(value) {
2968
- exact(value, [
2984
+ exact$3(value, [
2969
2985
  "capabilities",
2970
2986
  "id",
2971
2987
  "lifecycle",
@@ -2975,7 +2991,7 @@ function normalizeOrganization(value) {
2975
2991
  "slug"
2976
2992
  ]);
2977
2993
  if (!isId(value.id) || !boundedString(value.name, 255) || !boundedString(value.slug, 255) || value.lifecycle !== "ordinary" && value.lifecycle !== "managed" || !role(value.role) || !isObject(value.capabilities)) throw authorityUnavailable();
2978
- exact(value.capabilities, [
2994
+ exact$3(value.capabilities, [
2979
2995
  "readInvitations",
2980
2996
  "readMembers",
2981
2997
  "readTeams"
@@ -3037,7 +3053,7 @@ function normalizeOrganizationCreationInput(name, slug, idempotencyKey) {
3037
3053
  };
3038
3054
  }
3039
3055
  function normalizeCreatedOrganization(value) {
3040
- exact(value, [
3056
+ exact$3(value, [
3041
3057
  "id",
3042
3058
  "name",
3043
3059
  "slug"
@@ -3057,7 +3073,7 @@ function normalizeOrganizationTeamCreationInput(name, idempotencyKey) {
3057
3073
  };
3058
3074
  }
3059
3075
  function normalizeCreatedOrganizationTeam(value) {
3060
- exact(value, ["id", "name"]);
3076
+ exact$3(value, ["id", "name"]);
3061
3077
  if (!isId(value.id) || !boundedString(value.name, 255)) throw authorityUnavailable();
3062
3078
  return {
3063
3079
  id: value.id,
@@ -3084,7 +3100,7 @@ function normalizeOrganizationMemberInvitationCreationInput(value) {
3084
3100
  };
3085
3101
  }
3086
3102
  function normalizeCreatedOrganizationMemberInvitation(value) {
3087
- exact(value, ["expiresAt", "id"]);
3103
+ exact$3(value, ["expiresAt", "id"]);
3088
3104
  if (!isId(value.id)) throw authorityUnavailable();
3089
3105
  return {
3090
3106
  id: value.id,
@@ -3101,7 +3117,7 @@ function normalizeOrganizationInvitationAdministrationInput(idempotencyKey) {
3101
3117
  return { idempotencyKey };
3102
3118
  }
3103
3119
  function normalizeCanceledOrganizationInvitation(value) {
3104
- exact(value, ["status"]);
3120
+ exact$3(value, ["status"]);
3105
3121
  if (value.status !== "canceled") throw authorityUnavailable();
3106
3122
  return { status: "canceled" };
3107
3123
  }
@@ -3110,17 +3126,106 @@ function normalizeOrganizationMembershipRemovalInput(idempotencyKey) {
3110
3126
  return { idempotencyKey };
3111
3127
  }
3112
3128
  function normalizeRemovedOrganizationMember(value) {
3113
- exact(value, ["status"]);
3129
+ exact$3(value, ["status"]);
3114
3130
  if (value.status !== "removed") throw authorityUnavailable();
3115
3131
  return { status: "removed" };
3116
3132
  }
3133
+ function normalizeSuspendedOrganizationMemberStatus(value) {
3134
+ exact$3(value, ["status"]);
3135
+ if (value.status !== "suspended") throw authorityUnavailable();
3136
+ return { status: "suspended" };
3137
+ }
3138
+ function normalizeRestoredOrganizationMember(value) {
3139
+ exact$3(value, ["memberId", "status"]);
3140
+ if (value.status !== "restored" || !isId(value.memberId)) throw authorityUnavailable();
3141
+ return {
3142
+ status: "restored",
3143
+ memberId: value.memberId
3144
+ };
3145
+ }
3146
+ const suspensionIdPattern = /^organization_membership_suspension_v1_[A-Za-z0-9_-]{43}$/;
3147
+ function normalizeSuspendedOrganizationMembers(value) {
3148
+ exact$3(value, ["members", "nextCursor"]);
3149
+ if (!Array.isArray(value.members) || value.members.length > 100) throw authorityUnavailable();
3150
+ return {
3151
+ members: unique(value.members.map((member) => {
3152
+ exact$3(member, [
3153
+ "email",
3154
+ "id",
3155
+ "image",
3156
+ "name",
3157
+ "role",
3158
+ "suspendedAt",
3159
+ "teamIds",
3160
+ "userId"
3161
+ ]);
3162
+ if (typeof member.id !== "string" || !suspensionIdPattern.test(member.id) || !isId(member.userId) || !boundedString(member.name, 255) || typeof member.email !== "string" || member.email.length > 320 || !email.test(member.email) || member.role !== "admin" && member.role !== "member" || !Array.isArray(member.teamIds) || member.teamIds.length > 100) throw authorityUnavailable();
3163
+ return {
3164
+ id: member.id,
3165
+ userId: member.userId,
3166
+ name: member.name,
3167
+ email: member.email,
3168
+ image: nullableHttpsUrl(member.image),
3169
+ role: member.role,
3170
+ teamIds: unique(member.teamIds.map((teamId) => normalizeResponseId(teamId)), (item) => item),
3171
+ suspendedAt: responseDate(member.suspendedAt)
3172
+ };
3173
+ }), (item) => item.id),
3174
+ nextCursor: nullableCursor(value.nextCursor)
3175
+ };
3176
+ }
3177
+ function normalizeDepartedOrganizationMembers(value) {
3178
+ exact$3(value, ["members", "nextCursor"]);
3179
+ if (!Array.isArray(value.members) || value.members.length > 100) throw authorityUnavailable();
3180
+ return {
3181
+ members: unique(value.members.map((member) => {
3182
+ exact$3(member, [
3183
+ "departedAt",
3184
+ "departure",
3185
+ "email",
3186
+ "image",
3187
+ "name",
3188
+ "userId"
3189
+ ]);
3190
+ if (!isId(member.userId) || !boundedString(member.name, 255) || typeof member.email !== "string" || member.email.length > 320 || !email.test(member.email) || member.departure !== "removed" && member.departure !== "left") throw authorityUnavailable();
3191
+ return {
3192
+ userId: member.userId,
3193
+ name: member.name,
3194
+ email: member.email,
3195
+ image: nullableHttpsUrl(member.image),
3196
+ departure: member.departure,
3197
+ departedAt: responseDate(member.departedAt)
3198
+ };
3199
+ }), (item) => item.userId),
3200
+ nextCursor: nullableCursor(value.nextCursor)
3201
+ };
3202
+ }
3117
3203
  function normalizeOrganizationDeparture(value) {
3118
- exact(value, ["status"]);
3204
+ exact$3(value, ["status"]);
3119
3205
  if (value.status !== "left") throw authorityUnavailable();
3120
3206
  return { status: "left" };
3121
3207
  }
3208
+ function normalizeOrganizationTeamMembershipInput(idempotencyKey) {
3209
+ if (!boundedString(idempotencyKey, 255)) throw new AuthError("invalid_request", 400);
3210
+ return { idempotencyKey };
3211
+ }
3212
+ function normalizeAddedOrganizationTeamMember(value) {
3213
+ exact$3(value, ["status"]);
3214
+ if (value.status !== "added") throw authorityUnavailable();
3215
+ return { status: "added" };
3216
+ }
3217
+ function normalizeRemovedOrganizationTeamMember(value) {
3218
+ exact$3(value, ["status"]);
3219
+ if (value.status !== "removed") throw authorityUnavailable();
3220
+ return { status: "removed" };
3221
+ }
3222
+ function normalizeDeletedOrganizationTeam(value) {
3223
+ exact$3(value, ["status"]);
3224
+ if (value.status !== "deleted") throw authorityUnavailable();
3225
+ return { status: "deleted" };
3226
+ }
3122
3227
  function normalizeOrganizations(value) {
3123
- exact(value, ["nextCursor", "organizations"]);
3228
+ exact$3(value, ["nextCursor", "organizations"]);
3124
3229
  if (!Array.isArray(value.organizations) || value.organizations.length > 100) throw authorityUnavailable();
3125
3230
  return {
3126
3231
  organizations: unique(value.organizations.map(normalizeOrganization), (item) => item.id),
@@ -3128,11 +3233,11 @@ function normalizeOrganizations(value) {
3128
3233
  };
3129
3234
  }
3130
3235
  function normalizeOrganizationMembers(value) {
3131
- exact(value, ["members", "nextCursor"]);
3236
+ exact$3(value, ["members", "nextCursor"]);
3132
3237
  if (!Array.isArray(value.members) || value.members.length > 100) throw authorityUnavailable();
3133
3238
  return {
3134
3239
  members: unique(value.members.map((member) => {
3135
- exact(member, [
3240
+ exact$3(member, [
3136
3241
  "email",
3137
3242
  "id",
3138
3243
  "image",
@@ -3161,11 +3266,11 @@ function normalizeOrganizationMembers(value) {
3161
3266
  };
3162
3267
  }
3163
3268
  function normalizeOrganizationTeams(value) {
3164
- exact(value, ["nextCursor", "teams"]);
3269
+ exact$3(value, ["nextCursor", "teams"]);
3165
3270
  if (!Array.isArray(value.teams) || value.teams.length > 100) throw authorityUnavailable();
3166
3271
  return {
3167
3272
  teams: unique(value.teams.map((team) => {
3168
- exact(team, [
3273
+ exact$3(team, [
3169
3274
  "category",
3170
3275
  "createdAt",
3171
3276
  "id",
@@ -3183,7 +3288,7 @@ function normalizeOrganizationTeams(value) {
3183
3288
  };
3184
3289
  }
3185
3290
  function normalizeOrganizationTeamMembers(value) {
3186
- exact(value, ["memberIds", "nextCursor"]);
3291
+ exact$3(value, ["memberIds", "nextCursor"]);
3187
3292
  if (!Array.isArray(value.memberIds) || value.memberIds.length > 100) throw authorityUnavailable();
3188
3293
  return {
3189
3294
  memberIds: unique(value.memberIds.map((item) => normalizeResponseId(item)), (item) => item),
@@ -3191,7 +3296,7 @@ function normalizeOrganizationTeamMembers(value) {
3191
3296
  };
3192
3297
  }
3193
3298
  function normalizeOrganizationInvitation(value) {
3194
- exact(value, [
3299
+ exact$3(value, [
3195
3300
  "createdAt",
3196
3301
  "email",
3197
3302
  "expiresAt",
@@ -3202,7 +3307,7 @@ function normalizeOrganizationInvitation(value) {
3202
3307
  "teamIds"
3203
3308
  ]);
3204
3309
  if (!isId(value.id) || typeof value.email !== "string" || value.email.length > 320 || !email.test(value.email) || !role(value.role) || value.status !== "pending" || !Array.isArray(value.teamIds) || value.teamIds.length > 100 || !isObject(value.inviter)) throw authorityUnavailable();
3205
- exact(value.inviter, ["membershipId", "name"]);
3310
+ exact$3(value.inviter, ["membershipId", "name"]);
3206
3311
  if (!isId(value.inviter.membershipId) || !boundedString(value.inviter.name, 255)) throw authorityUnavailable();
3207
3312
  return {
3208
3313
  id: value.id,
@@ -3219,7 +3324,7 @@ function normalizeOrganizationInvitation(value) {
3219
3324
  };
3220
3325
  }
3221
3326
  function normalizeOrganizationInvitations(value) {
3222
- exact(value, ["invitations", "nextCursor"]);
3327
+ exact$3(value, ["invitations", "nextCursor"]);
3223
3328
  if (!Array.isArray(value.invitations) || value.invitations.length > 100) throw authorityUnavailable();
3224
3329
  return {
3225
3330
  invitations: unique(value.invitations.map(normalizeOrganizationInvitation), (item) => item.id),
@@ -3227,7 +3332,7 @@ function normalizeOrganizationInvitations(value) {
3227
3332
  };
3228
3333
  }
3229
3334
  function normalizeReceivedInvitation(value) {
3230
- exact(value, [
3335
+ exact$3(value, [
3231
3336
  "expiresAt",
3232
3337
  "id",
3233
3338
  "inviterName",
@@ -3236,7 +3341,7 @@ function normalizeReceivedInvitation(value) {
3236
3341
  "teams"
3237
3342
  ]);
3238
3343
  if (!isId(value.id) || !boundedString(value.inviterName, 255) || !role(value.role) || !Array.isArray(value.teams) || value.teams.length > 100 || !isObject(value.organization)) throw authorityUnavailable();
3239
- exact(value.organization, [
3344
+ exact$3(value.organization, [
3240
3345
  "id",
3241
3346
  "logo",
3242
3347
  "name",
@@ -3253,7 +3358,7 @@ function normalizeReceivedInvitation(value) {
3253
3358
  },
3254
3359
  role: value.role,
3255
3360
  teams: unique(value.teams.map((team) => {
3256
- exact(team, ["id", "name"]);
3361
+ exact$3(team, ["id", "name"]);
3257
3362
  if (!isId(team.id) || !boundedString(team.name, 255)) throw authorityUnavailable();
3258
3363
  return {
3259
3364
  id: team.id,
@@ -3265,7 +3370,7 @@ function normalizeReceivedInvitation(value) {
3265
3370
  };
3266
3371
  }
3267
3372
  function normalizeReceivedInvitations(value) {
3268
- exact(value, ["invitations", "nextCursor"]);
3373
+ exact$3(value, ["invitations", "nextCursor"]);
3269
3374
  if (!Array.isArray(value.invitations) || value.invitations.length > 100) throw authorityUnavailable();
3270
3375
  return {
3271
3376
  invitations: unique(value.invitations.map(normalizeReceivedInvitation), (item) => item.id),
@@ -3294,6 +3399,10 @@ function normalizeInvitationAcceptance(value, invitationId) {
3294
3399
  if (!isObject(value) || !isObject(value.invitation) || !isObject(value.member) || value.invitation.id !== invitationId || value.invitation.status !== "accepted" || !isId(value.invitation.organizationId) || value.member.organizationId !== value.invitation.organizationId) throw authorityUnavailable();
3295
3400
  return { organizationId: value.invitation.organizationId };
3296
3401
  }
3402
+ function normalizeInvitationDecline(value, invitationId) {
3403
+ if (!isObject(value) || !isObject(value.invitation) || value.invitation.id !== invitationId || value.invitation.status !== "rejected" || value.member !== null) throw authorityUnavailable();
3404
+ return { status: "declined" };
3405
+ }
3297
3406
  function normalizeWorkspaceSelection(value) {
3298
3407
  if (!isObject(value)) throw new AuthError("invalid_workspace_selection", 422);
3299
3408
  const keys = Object.keys(value);
@@ -3358,6 +3467,73 @@ function fromOrganizationMembershipRemovalError(value, status, retryAfter) {
3358
3467
  if (status === 422 && isObject(value) && value.code === "RECOVERY_REQUIRED") return new AuthError("membership_removal_recovery_required", 422);
3359
3468
  return fromOrganizationMutationAuthorityError(value, status, retryAfter);
3360
3469
  }
3470
+ function fromOrganizationClosureError(value, status, retryAfter) {
3471
+ const code = isObject(value) && typeof value.code === "string" ? value.code : void 0;
3472
+ if (status === 409 && code === "CONFIRMATION_MISMATCH") return new AuthError("organization_closure_confirmation_mismatch", 409);
3473
+ if (status === 409 && code === "RECENT_AUTHENTICATION_REQUIRED") return new AuthError("recent_authentication_required", 409);
3474
+ if (status === 409 && code === "CANCELLATION_WINDOW_ENDED") return new AuthError("organization_closure_cancellation_ended", 409);
3475
+ return fromOrganizationMutationAuthorityError(value, status, retryAfter);
3476
+ }
3477
+ function normalizeOrganizationClosureStartInput(value) {
3478
+ if (!isObject(value) || Object.keys(value).sort().join(",") !== "confirmationName,idempotencyKey") throw new TypeError("organization closure input is invalid");
3479
+ if (!boundedString(value.confirmationName, 255)) throw new TypeError("confirmationName is invalid");
3480
+ return {
3481
+ confirmationName: value.confirmationName,
3482
+ idempotencyKey: normalizeAuthorityIdempotencyKey(value.idempotencyKey)
3483
+ };
3484
+ }
3485
+ function normalizeOrganizationClosureCancelInput(value) {
3486
+ if (!isObject(value) || Object.keys(value).join(",") !== "idempotencyKey") throw new TypeError("organization closure cancellation input is invalid");
3487
+ return { idempotencyKey: normalizeAuthorityIdempotencyKey(value.idempotencyKey) };
3488
+ }
3489
+ function closureWindow(value) {
3490
+ const startedAt = responseDate(value.startedAt);
3491
+ const cancelUntil = responseDate(value.cancelUntil);
3492
+ if (cancelUntil.getTime() - startedAt.getTime() !== 720 * 60 * 60 * 1e3 || typeof value.canCancel !== "boolean") throw authorityUnavailable();
3493
+ return {
3494
+ startedAt: startedAt.toISOString(),
3495
+ cancelUntil: cancelUntil.toISOString(),
3496
+ canCancel: value.canCancel
3497
+ };
3498
+ }
3499
+ function normalizeOrganizationClosure(value) {
3500
+ exact$3(value, [
3501
+ "cancelUntil",
3502
+ "canCancel",
3503
+ "organizationId",
3504
+ "startedAt",
3505
+ "state"
3506
+ ]);
3507
+ if (!isId(value.organizationId) || value.state !== "closing" && value.state !== "cancelled") throw authorityUnavailable();
3508
+ const window = closureWindow(value);
3509
+ if (value.state === "cancelled" && window.canCancel) throw authorityUnavailable();
3510
+ return {
3511
+ organizationId: value.organizationId,
3512
+ state: value.state,
3513
+ ...window
3514
+ };
3515
+ }
3516
+ function normalizeClosingOrganizations(value) {
3517
+ exact$3(value, ["organizations"]);
3518
+ if (!Array.isArray(value.organizations) || value.organizations.length > 20) throw authorityUnavailable();
3519
+ return { organizations: unique(value.organizations.map((item) => {
3520
+ exact$3(item, [
3521
+ "cancelUntil",
3522
+ "canCancel",
3523
+ "id",
3524
+ "name",
3525
+ "slug",
3526
+ "startedAt"
3527
+ ]);
3528
+ if (!isId(item.id) || !boundedString(item.name, 255) || item.slug !== null && !boundedString(item.slug, 255)) throw authorityUnavailable();
3529
+ return {
3530
+ id: item.id,
3531
+ name: item.name,
3532
+ slug: item.slug,
3533
+ ...closureWindow(item)
3534
+ };
3535
+ }), (item) => item.id) };
3536
+ }
3361
3537
  function normalizePlatformRoleChangeRecentAuthenticationInput(value) {
3362
3538
  if (!isObject(value) || Object.keys(value).sort().join(",") !== "changeReference,expectedGlobalRevision,expectedTargetRevision,idempotencyKey,reasonCategory,requestedRoles,targetUserId") throw new TypeError("recent authentication input is invalid");
3363
3539
  if (!isId(value.targetUserId)) throw new TypeError("targetUserId is invalid");
@@ -3410,7 +3586,7 @@ function normalizeOrganizationOwnershipTransferInput(value) {
3410
3586
  };
3411
3587
  }
3412
3588
  function normalizeOrganizationManualRoleChangeResult(value) {
3413
- exact(value, [
3589
+ exact$3(value, [
3414
3590
  "status",
3415
3591
  "memberId",
3416
3592
  "manualRole",
@@ -3424,7 +3600,7 @@ function normalizeOrganizationManualRoleChangeResult(value) {
3424
3600
  };
3425
3601
  }
3426
3602
  function normalizeOrganizationMemberAuthority(value, organizationId, memberId) {
3427
- exact(value, [
3603
+ exact$3(value, [
3428
3604
  "organizationId",
3429
3605
  "actor",
3430
3606
  "target"
@@ -3442,7 +3618,7 @@ function normalizeOrganizationMemberAuthority(value, organizationId, memberId) {
3442
3618
  };
3443
3619
  }
3444
3620
  function normalizeOrganizationOwnershipTransferResult(value) {
3445
- exact(value, [
3621
+ exact$3(value, [
3446
3622
  "status",
3447
3623
  "outgoingOwner",
3448
3624
  "successor"
@@ -3455,7 +3631,7 @@ function normalizeOrganizationOwnershipTransferResult(value) {
3455
3631
  };
3456
3632
  }
3457
3633
  function normalizeOrganizationAuthorityMemberOutcome(value, includesStatus = false) {
3458
- exact(value, [
3634
+ exact$3(value, [
3459
3635
  "memberId",
3460
3636
  "manualRole",
3461
3637
  "role",
@@ -3488,7 +3664,7 @@ function normalizePlatformBootstrapRoleChangeInput(value) {
3488
3664
  return request;
3489
3665
  }
3490
3666
  function normalizePlatformRoleApproval(value) {
3491
- exact(value, [
3667
+ exact$3(value, [
3492
3668
  "status",
3493
3669
  "targetUserId",
3494
3670
  "targetRevision",
@@ -3515,7 +3691,7 @@ function normalizePlatformRoleApproval(value) {
3515
3691
  };
3516
3692
  }
3517
3693
  function normalizePlatformStatus(value) {
3518
- exact(value, [
3694
+ exact$3(value, [
3519
3695
  "eligible",
3520
3696
  "globalRevision",
3521
3697
  "roles"
@@ -3530,7 +3706,7 @@ function normalizePlatformStatus(value) {
3530
3706
  };
3531
3707
  }
3532
3708
  function normalizeRecentAuthenticationStatus(value) {
3533
- exact(value, ["status"]);
3709
+ exact$3(value, ["status"]);
3534
3710
  if (value.status !== "pending" && value.status !== "ready") throw authorityUnavailable();
3535
3711
  return { status: value.status };
3536
3712
  }
@@ -3643,7 +3819,7 @@ function normalizeProfileImage(value) {
3643
3819
  function isId(value) {
3644
3820
  return typeof value === "string" && id.test(value);
3645
3821
  }
3646
- function exact(value, keys) {
3822
+ function exact$3(value, keys) {
3647
3823
  if (!isObject(value) || Object.keys(value).sort().join(",") !== [...keys].sort().join(",")) throw authorityUnavailable();
3648
3824
  }
3649
3825
  function boundedString(value, maximum) {
@@ -4508,6 +4684,406 @@ function byteLength(value) {
4508
4684
  return new TextEncoder().encode(value).byteLength;
4509
4685
  }
4510
4686
  //#endregion
4687
+ //#region src/sessions.ts
4688
+ const idPattern$2 = /^[A-Za-z0-9_-]{1,128}$(?![\s\S])/;
4689
+ const MAX_SESSIONS = 50;
4690
+ const itemKeys$1 = [
4691
+ "createdAt",
4692
+ "current",
4693
+ "expiresAt",
4694
+ "id",
4695
+ "ipAddress",
4696
+ "updatedAt",
4697
+ "userAgent"
4698
+ ];
4699
+ function exact$2(value, keys) {
4700
+ return isObject(value) && Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
4701
+ }
4702
+ function date$2(value) {
4703
+ if (typeof value !== "string") throw authorityUnavailable();
4704
+ const parsed = new Date(value);
4705
+ if (!Number.isFinite(parsed.getTime()) || parsed.toISOString() !== value) throw authorityUnavailable();
4706
+ return parsed;
4707
+ }
4708
+ function text(value, maximum) {
4709
+ if (value === null) return null;
4710
+ if (typeof value !== "string" || value.length === 0 || value.length > maximum || /[^\x20-\x7e]/.test(value)) throw authorityUnavailable();
4711
+ return value;
4712
+ }
4713
+ function normalizeSessionId(value) {
4714
+ if (typeof value !== "string" || !idPattern$2.test(value)) throw new TypeError("sessionId is invalid");
4715
+ return value;
4716
+ }
4717
+ function normalizeSessionSummary(value) {
4718
+ if (!exact$2(value, itemKeys$1) || typeof value.id !== "string" || !idPattern$2.test(value.id)) throw authorityUnavailable();
4719
+ if (typeof value.current !== "boolean") throw authorityUnavailable();
4720
+ return {
4721
+ id: value.id,
4722
+ current: value.current,
4723
+ createdAt: date$2(value.createdAt),
4724
+ updatedAt: date$2(value.updatedAt),
4725
+ expiresAt: date$2(value.expiresAt),
4726
+ userAgent: text(value.userAgent, 512),
4727
+ ipAddress: text(value.ipAddress, 64)
4728
+ };
4729
+ }
4730
+ function normalizeSessionInventory(value) {
4731
+ if (!exact$2(value, ["sessions", "truncated"]) || !Array.isArray(value.sessions) || value.sessions.length > MAX_SESSIONS || typeof value.truncated !== "boolean") throw authorityUnavailable();
4732
+ const sessions = value.sessions.map(normalizeSessionSummary);
4733
+ if (new Set(sessions.map((session) => session.id)).size !== sessions.length) throw authorityUnavailable();
4734
+ if (sessions.filter((session) => session.current).length !== 1) throw authorityUnavailable();
4735
+ return {
4736
+ sessions,
4737
+ truncated: value.truncated
4738
+ };
4739
+ }
4740
+ function normalizeSessionRevocation(value) {
4741
+ if (!exact$2(value, ["status"]) || value.status !== "revoked") throw authorityUnavailable();
4742
+ }
4743
+ function normalizeOtherSessionRevocation(value) {
4744
+ if (!exact$2(value, ["revoked"]) || !Number.isSafeInteger(value.revoked) || value.revoked < 0) throw authorityUnavailable();
4745
+ return { revoked: value.revoked };
4746
+ }
4747
+ function fromSessionInventoryError(_value, status, retryAfter) {
4748
+ if (status === 400) return new AuthError("invalid_request", 400);
4749
+ if (status === 401) return new AuthError("authentication_required", 401);
4750
+ if (status === 403) return new AuthError("request_origin_denied", 403);
4751
+ if (status === 404 || status === 409) return new AuthError("state_conflict", 409);
4752
+ if (status === 429) return new AuthError("auth_request_rate_limited", 429, parseRetryAfter(retryAfter));
4753
+ return authorityUnavailable();
4754
+ }
4755
+ //#endregion
4756
+ //#region src/passkeys.ts
4757
+ const idPattern$1 = /^[A-Za-z0-9_-]{1,128}$(?![\s\S])/;
4758
+ const MAX_PASSKEYS = 50;
4759
+ const MAX_RETURN_BYTES = 2048;
4760
+ const PASSKEY_NAME_MAX_LENGTH = 64;
4761
+ const itemKeys = [
4762
+ "backedUp",
4763
+ "createdAt",
4764
+ "deviceType",
4765
+ "id",
4766
+ "name"
4767
+ ];
4768
+ function exact$1(value, keys) {
4769
+ return isObject(value) && Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
4770
+ }
4771
+ function date$1(value) {
4772
+ if (typeof value !== "string") throw authorityUnavailable();
4773
+ const parsed = new Date(value);
4774
+ if (!Number.isFinite(parsed.getTime()) || parsed.toISOString() !== value) throw authorityUnavailable();
4775
+ return parsed;
4776
+ }
4777
+ function returnInput(value) {
4778
+ if (!isObject(value)) throw new TypeError("ceremony input is invalid");
4779
+ const { applicationId, returnTo } = value;
4780
+ if (typeof applicationId !== "string" || !idPattern$1.test(applicationId)) throw new TypeError("applicationId is invalid");
4781
+ if (typeof returnTo !== "string" || new TextEncoder().encode(returnTo).byteLength > MAX_RETURN_BYTES || !URL.canParse(returnTo) || new URL(returnTo).toString() !== returnTo) throw new TypeError("returnTo is invalid");
4782
+ return {
4783
+ applicationId,
4784
+ returnTo
4785
+ };
4786
+ }
4787
+ function normalizeCeremonyHandoffInput(value) {
4788
+ const base = returnInput(value);
4789
+ const input = value;
4790
+ switch (input.purpose) {
4791
+ case "passkey_enrollment": return {
4792
+ purpose: input.purpose,
4793
+ ...base
4794
+ };
4795
+ case "passkey_removal": return {
4796
+ purpose: input.purpose,
4797
+ ...base,
4798
+ passkeyId: normalizePasskeyId(input.passkeyId)
4799
+ };
4800
+ case "recent_authentication": {
4801
+ const request = input.request;
4802
+ if (!isObject(request)) throw new TypeError("request is invalid");
4803
+ const organizationId = normalizeIdInput(request.organizationId);
4804
+ if (request.action === "organization_ownership_transfer") {
4805
+ const { action: _action, organizationId: _organizationId, ...transfer } = request;
4806
+ return {
4807
+ purpose: input.purpose,
4808
+ ...base,
4809
+ request: {
4810
+ action: request.action,
4811
+ organizationId,
4812
+ ...normalizeOrganizationOwnershipTransferInput(transfer)
4813
+ }
4814
+ };
4815
+ }
4816
+ if (request.action === "organization_closure_start") {
4817
+ const { action: _action, organizationId: _organizationId, ...closure } = request;
4818
+ return {
4819
+ purpose: input.purpose,
4820
+ ...base,
4821
+ request: {
4822
+ action: request.action,
4823
+ organizationId,
4824
+ ...normalizeOrganizationClosureStartInput(closure)
4825
+ }
4826
+ };
4827
+ }
4828
+ if (request.action === "organization_closure_cancel") {
4829
+ const { action: _action, organizationId: _organizationId, ...closure } = request;
4830
+ return {
4831
+ purpose: input.purpose,
4832
+ ...base,
4833
+ request: {
4834
+ action: request.action,
4835
+ organizationId,
4836
+ ...normalizeOrganizationClosureCancelInput(closure)
4837
+ }
4838
+ };
4839
+ }
4840
+ throw new TypeError("request action is invalid");
4841
+ }
4842
+ default: throw new TypeError("purpose is invalid");
4843
+ }
4844
+ }
4845
+ function normalizeCeremonyHandoff(value) {
4846
+ if (!exact$1(value, ["expiresAt", "url"]) || typeof value.url !== "string") throw authorityUnavailable();
4847
+ let url;
4848
+ try {
4849
+ url = new URL(value.url);
4850
+ } catch {
4851
+ throw authorityUnavailable();
4852
+ }
4853
+ const local = url.hostname === "localhost" || url.hostname.endsWith(".localhost");
4854
+ if (url.protocol !== "https:" && !(local && url.protocol === "http:") || url.username || url.password || url.pathname !== "/api/v1/auth/ceremony/start" || url.search || !/^#code=[A-Za-z0-9_-]{43}$/.test(url.hash)) throw authorityUnavailable();
4855
+ return {
4856
+ url: url.toString(),
4857
+ expiresAt: date$1(value.expiresAt)
4858
+ };
4859
+ }
4860
+ function normalizePasskeyId(value) {
4861
+ if (typeof value !== "string" || !idPattern$1.test(value)) throw new TypeError("passkeyId is invalid");
4862
+ return value;
4863
+ }
4864
+ function normalizePasskeyName(value) {
4865
+ if (typeof value !== "string") throw new TypeError("name is invalid");
4866
+ const name = value.trim();
4867
+ if (!name || name.length > PASSKEY_NAME_MAX_LENGTH || /[\p{Cc}\p{Cf}]/u.test(name)) throw new TypeError("name is invalid");
4868
+ return name;
4869
+ }
4870
+ function normalizePasskeySummary(value) {
4871
+ if (!exact$1(value, itemKeys) || typeof value.id !== "string" || !idPattern$1.test(value.id)) throw authorityUnavailable();
4872
+ if (value.name !== null && (typeof value.name !== "string" || value.name.length > PASSKEY_NAME_MAX_LENGTH)) throw authorityUnavailable();
4873
+ if (value.deviceType !== "singleDevice" && value.deviceType !== "multiDevice") throw authorityUnavailable();
4874
+ if (typeof value.backedUp !== "boolean") throw authorityUnavailable();
4875
+ return {
4876
+ id: value.id,
4877
+ name: value.name,
4878
+ createdAt: value.createdAt === null ? null : date$1(value.createdAt),
4879
+ deviceType: value.deviceType,
4880
+ backedUp: value.backedUp
4881
+ };
4882
+ }
4883
+ function normalizePasskeyInventory(value) {
4884
+ if (!exact$1(value, ["passkeys", "truncated"]) || !Array.isArray(value.passkeys) || value.passkeys.length > MAX_PASSKEYS || typeof value.truncated !== "boolean") throw authorityUnavailable();
4885
+ const passkeys = value.passkeys.map(normalizePasskeySummary);
4886
+ if (new Set(passkeys.map((passkey) => passkey.id)).size !== passkeys.length) throw authorityUnavailable();
4887
+ return {
4888
+ passkeys,
4889
+ truncated: value.truncated
4890
+ };
4891
+ }
4892
+ function normalizePasskeyRename(value) {
4893
+ if (!exact$1(value, ["status"]) || value.status !== "renamed") throw authorityUnavailable();
4894
+ }
4895
+ function fromCeremonyHandoffError(value, status, retryAfter) {
4896
+ const code = isObject(value) ? value.code : void 0;
4897
+ if (status === 400 && code === "RETURN_ADDRESS_REFUSED") return new AuthError("ceremony_return_refused", 400);
4898
+ if (status === 400) return new AuthError("invalid_request", 400);
4899
+ if (status === 401) return new AuthError("authentication_required", 401);
4900
+ if (status === 403) return new AuthError("request_origin_denied", 403);
4901
+ if (status === 404) return new AuthError("state_conflict", 409);
4902
+ if (status === 409 && code === "PASSWORD_REQUIRED") return new AuthError("password_sign_in_required", 409);
4903
+ if (status === 409) return new AuthError("state_conflict", 409);
4904
+ if (status === 429) return new AuthError("auth_request_rate_limited", 429, parseRetryAfter(retryAfter));
4905
+ return authorityUnavailable();
4906
+ }
4907
+ //#endregion
4908
+ //#region src/two-factor.ts
4909
+ const totpCode = /^[0-9]{6}$(?![\s\S])/;
4910
+ const backupCode = /^[A-Za-z0-9]{5}-[A-Za-z0-9]{5}$(?![\s\S])/;
4911
+ const base32Secret = /^[A-Z2-7]{16,128}=*$(?![\s\S])/;
4912
+ const BACKUP_CODE_COUNT = 10;
4913
+ const MAX_TOTP_URI_LENGTH = 1024;
4914
+ function normalizeTwoFactorCode(value, name = "code") {
4915
+ if (typeof value !== "string" || value.length > 32) throw new TypeError(`${name} is invalid`);
4916
+ const code = value.replace(/\s+/g, "");
4917
+ if (totpCode.test(code)) return {
4918
+ route: "two-factor/verify-totp",
4919
+ code
4920
+ };
4921
+ if (backupCode.test(code)) return {
4922
+ route: "two-factor/verify-backup-code",
4923
+ code
4924
+ };
4925
+ throw new TypeError(`${name} is invalid`);
4926
+ }
4927
+ function normalizeTotpCode(value) {
4928
+ const normalized = normalizeTwoFactorCode(value);
4929
+ if (normalized.route !== "two-factor/verify-totp") throw new TypeError("code is invalid");
4930
+ return normalized.code;
4931
+ }
4932
+ function normalizeTwoFactorStepUp(value) {
4933
+ if (!isObject(value)) throw new TypeError("two-factor step-up input is invalid");
4934
+ const keys = Object.keys(value);
4935
+ if (keys.length !== 2 || !keys.includes("password") || !keys.includes("code")) throw new TypeError("two-factor step-up input is invalid");
4936
+ const input = value;
4937
+ return {
4938
+ password: normalizePassword(input.password),
4939
+ code: normalizeTwoFactorCode(input.code).code
4940
+ };
4941
+ }
4942
+ function isTwoFactorChallenge(value) {
4943
+ return isObject(value) && value.twoFactorRedirect === true;
4944
+ }
4945
+ function normalizeBackupCodes(value) {
4946
+ if (!Array.isArray(value) || value.length !== BACKUP_CODE_COUNT || value.some((code) => typeof code !== "string" || !backupCode.test(code)) || new Set(value).size !== value.length) throw authorityUnavailable();
4947
+ return [...value];
4948
+ }
4949
+ function normalizeRegeneratedBackupCodes(value) {
4950
+ if (!isObject(value) || value.status !== true) throw authorityUnavailable();
4951
+ return normalizeBackupCodes(value.backupCodes);
4952
+ }
4953
+ function normalizeTwoFactorEnrollment(value) {
4954
+ if (!isObject(value) || typeof value.totpURI !== "string" || value.totpURI.length > MAX_TOTP_URI_LENGTH) throw authorityUnavailable();
4955
+ let uri;
4956
+ try {
4957
+ uri = new URL(value.totpURI);
4958
+ } catch {
4959
+ throw authorityUnavailable();
4960
+ }
4961
+ const secret = uri.searchParams.get("secret");
4962
+ if (uri.protocol !== "otpauth:" || uri.host !== "totp" || !secret || !base32Secret.test(secret) || (uri.searchParams.get("digits") ?? "6") !== "6" || (uri.searchParams.get("period") ?? "30") !== "30") throw authorityUnavailable();
4963
+ return {
4964
+ totpUri: uri.toString(),
4965
+ secret,
4966
+ backupCodes: normalizeBackupCodes(value.backupCodes)
4967
+ };
4968
+ }
4969
+ function normalizeTwoFactorStatus(value) {
4970
+ if (value === null) throw new AuthError("authentication_required", 401);
4971
+ if (!isObject(value) || !isObject(value.user) || typeof value.user.twoFactorEnabled !== "boolean") throw authorityUnavailable();
4972
+ return { enabled: value.user.twoFactorEnabled };
4973
+ }
4974
+ function fromTwoFactorAuthorityError(value, status, retryAfter) {
4975
+ const code = isObject(value) && typeof value.code === "string" ? value.code : void 0;
4976
+ if (code === "INVALID_CODE" || code === "INVALID_BACKUP_CODE") return new AuthError("two_factor_code_invalid", 401);
4977
+ if (code === "INVALID_TWO_FACTOR_COOKIE" || code === "TOO_MANY_ATTEMPTS_REQUEST_NEW_CODE") return new AuthError("two_factor_challenge_expired", 401);
4978
+ if (code === "ACCOUNT_TEMPORARILY_LOCKED") return new AuthError("two_factor_locked", 429, parseRetryAfter(retryAfter));
4979
+ if (code === "SESSION_NOT_FRESH") return new AuthError("recent_sign_in_required", 403);
4980
+ if (code === "TWO_FACTOR_ALREADY_ENABLED" || code === "TWO_FACTOR_NOT_ENABLED" || code === "TOTP_NOT_ENABLED" || code === "TWO_FACTOR_SIGN_IN_ONLY") return new AuthError("state_conflict", 409);
4981
+ if (status === 413) return new AuthError("invalid_auth_input", 422);
4982
+ return fromAccountAuthorityError(value, status, retryAfter);
4983
+ }
4984
+ //#endregion
4985
+ //#region src/enterprise.ts
4986
+ const idPattern = /^[A-Za-z0-9_-]{1,128}$(?![\s\S])/;
4987
+ const credentialPattern = /^[A-Za-z0-9_-]{16,64}\.[A-Za-z0-9_-]{43}$(?![\s\S])/;
4988
+ const connectionKeys = [
4989
+ "capability",
4990
+ "clientId",
4991
+ "domainVerified",
4992
+ "enabled",
4993
+ "id",
4994
+ "issuer",
4995
+ "memberJit",
4996
+ "requireVerifiedEmail",
4997
+ "roleMappingConfigured",
4998
+ "updatedAt",
4999
+ "validatedAt"
5000
+ ];
5001
+ const stateKeys = [
5002
+ "currentCredentialId",
5003
+ "retiringExpiresAt",
5004
+ "revision",
5005
+ "revokedAt",
5006
+ "status"
5007
+ ];
5008
+ function exact(value, keys) {
5009
+ return isObject(value) && Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
5010
+ }
5011
+ function date(value, nullable) {
5012
+ if (value === null && nullable) return null;
5013
+ if (typeof value !== "string") throw authorityUnavailable();
5014
+ const parsed = new Date(value);
5015
+ if (!Number.isFinite(parsed.getTime())) throw authorityUnavailable();
5016
+ return parsed;
5017
+ }
5018
+ function bool(value) {
5019
+ if (typeof value !== "boolean") throw authorityUnavailable();
5020
+ return value;
5021
+ }
5022
+ function normalizeEnterpriseConnections(value) {
5023
+ if (!exact(value, ["connections"]) || !Array.isArray(value.connections) || value.connections.length > 10) throw authorityUnavailable();
5024
+ return value.connections.map((item) => {
5025
+ if (!exact(item, connectionKeys)) throw authorityUnavailable();
5026
+ if (typeof item.id !== "string" || !idPattern.test(item.id) || typeof item.issuer !== "string" || !item.issuer.startsWith("https://") || item.issuer.length > 2048 || typeof item.clientId !== "string" || item.clientId.length === 0 || item.clientId.length > 256 || item.capability !== "federated_sign_in" && item.capability !== "managed_lifecycle") throw authorityUnavailable();
5027
+ return {
5028
+ id: item.id,
5029
+ issuer: item.issuer,
5030
+ clientId: item.clientId,
5031
+ capability: item.capability,
5032
+ enabled: bool(item.enabled),
5033
+ domainVerified: bool(item.domainVerified),
5034
+ validatedAt: date(item.validatedAt, true),
5035
+ memberJit: bool(item.memberJit),
5036
+ requireVerifiedEmail: bool(item.requireVerifiedEmail),
5037
+ roleMappingConfigured: bool(item.roleMappingConfigured),
5038
+ updatedAt: date(item.updatedAt, false)
5039
+ };
5040
+ });
5041
+ }
5042
+ function normalizeScimCredentialState(value, extraKeys = []) {
5043
+ if (!exact(value, [...stateKeys, ...extraKeys])) throw authorityUnavailable();
5044
+ const status = value.status;
5045
+ if (status !== "active" && status !== "revoked" && status !== "unissued") throw authorityUnavailable();
5046
+ const revision = value.revision;
5047
+ if (revision !== null && (!Number.isSafeInteger(revision) || revision < 0)) throw authorityUnavailable();
5048
+ const currentCredentialId = value.currentCredentialId;
5049
+ if (currentCredentialId !== null && (typeof currentCredentialId !== "string" || !idPattern.test(currentCredentialId))) throw authorityUnavailable();
5050
+ if (status === "unissued" !== (revision === null)) throw authorityUnavailable();
5051
+ return {
5052
+ status,
5053
+ revision,
5054
+ currentCredentialId,
5055
+ retiringExpiresAt: date(value.retiringExpiresAt, true),
5056
+ revokedAt: date(value.revokedAt, true)
5057
+ };
5058
+ }
5059
+ function normalizeScimCredentialIssuance(value) {
5060
+ const state = normalizeScimCredentialState(value, ["credential"]);
5061
+ const credential = value.credential;
5062
+ if (state.status !== "active" || typeof credential !== "string" || !credentialPattern.test(credential)) throw authorityUnavailable();
5063
+ return {
5064
+ ...state,
5065
+ credential
5066
+ };
5067
+ }
5068
+ function normalizeRevision(value) {
5069
+ if (!Number.isSafeInteger(value) || value < 0) throw new TypeError("expectedRevision is invalid");
5070
+ return value;
5071
+ }
5072
+ function normalizeOverlapSeconds(value) {
5073
+ if (!Number.isSafeInteger(value) || value < 0 || value > 86400) throw new TypeError("overlapSeconds is invalid");
5074
+ return value;
5075
+ }
5076
+ function fromEnterpriseAdministrationError(value, status, retryAfter) {
5077
+ const code = isObject(value) && typeof value.code === "string" ? value.code : void 0;
5078
+ if (status === 401) return new AuthError("authentication_required", 401);
5079
+ if (status === 403) return new AuthError("access_denied", 403);
5080
+ if (status === 409) return new AuthError("state_conflict", 409);
5081
+ if (status === 422 || code === "RECOVERY_REQUIRED") return new AuthError("enterprise_recovery_required", 422);
5082
+ if (status === 400 || status === 413 || status === 415) return new AuthError("invalid_request", 400);
5083
+ if (status === 429) return new AuthError("auth_request_rate_limited", 429, parseRetryAfter(retryAfter));
5084
+ return authorityUnavailable();
5085
+ }
5086
+ //#endregion
4511
5087
  //#region src/user-api/credential.ts
4512
5088
  function userApiApplication(input) {
4513
5089
  if (!input || typeof input.applicationId !== "string" || !/^[A-Za-z0-9_-]{1,128}$(?![\s\S])/.test(input.applicationId) || input.forceRefresh !== void 0 && typeof input.forceRefresh !== "boolean") throw new TypeError("User API credential input is invalid");
@@ -4909,6 +5485,39 @@ function createAuthClient(options) {
4909
5485
  mapError
4910
5486
  })).value;
4911
5487
  }
5488
+ async function resolveSuspension(organizationId, suspensionId, idempotencyKey, resolution) {
5489
+ const organization = normalizeIdInput(organizationId);
5490
+ const suspension = normalizeIdInput(suspensionId);
5491
+ const body = normalizeOrganizationMembershipRemovalInput(idempotencyKey);
5492
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
5493
+ const generation = authorityGeneration;
5494
+ const value = await requestJson(joinURL(authOrigin, "api/v1/auth/organizations", organization, "suspended-members", suspension, resolution), {
5495
+ fetch: fetchImpl,
5496
+ timeoutMs,
5497
+ method: "POST",
5498
+ headers: { "content-type": "application/json" },
5499
+ body,
5500
+ mapError: fromOrganizationMembershipRemovalError
5501
+ });
5502
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
5503
+ return value;
5504
+ }
5505
+ async function teamMembershipMutation(ids, idempotencyKey, url) {
5506
+ const [organization, team, member] = ids.map(normalizeIdInput);
5507
+ const body = normalizeOrganizationTeamMembershipInput(idempotencyKey);
5508
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
5509
+ const generation = authorityGeneration;
5510
+ const value = await requestJson(url(organization, team, member), {
5511
+ fetch: fetchImpl,
5512
+ timeoutMs,
5513
+ method: "POST",
5514
+ headers: { "content-type": "application/json" },
5515
+ body,
5516
+ mapError: fromOrganizationMutationAuthorityError
5517
+ });
5518
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
5519
+ return value;
5520
+ }
4912
5521
  async function organizationRead(path, input, normalize) {
4913
5522
  if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
4914
5523
  const generation = authorityGeneration;
@@ -4928,6 +5537,71 @@ function createAuthClient(options) {
4928
5537
  throw error;
4929
5538
  }
4930
5539
  }
5540
+ async function sessionInventoryRequest(method, path, normalize) {
5541
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
5542
+ const generation = authorityGeneration;
5543
+ const value = await requestJson(joinURL(authOrigin, "api/v1/auth/sessions", path), {
5544
+ fetch: fetchImpl,
5545
+ timeoutMs,
5546
+ method,
5547
+ ...method === "POST" ? {
5548
+ headers: { "content-type": "application/json; charset=utf-8" },
5549
+ body: {}
5550
+ } : {},
5551
+ mapError: fromSessionInventoryError
5552
+ });
5553
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
5554
+ return normalize(value);
5555
+ }
5556
+ async function ceremonyRequest(method, path, body, normalize) {
5557
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
5558
+ const generation = authorityGeneration;
5559
+ const value = await requestJson(joinURL(authOrigin, "api/v1/auth", path), {
5560
+ fetch: fetchImpl,
5561
+ timeoutMs,
5562
+ method,
5563
+ ...body ? {
5564
+ headers: { "content-type": "application/json" },
5565
+ body
5566
+ } : {},
5567
+ mapError: fromCeremonyHandoffError
5568
+ });
5569
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
5570
+ return normalize(value);
5571
+ }
5572
+ function scimCredentialPath(organizationId, connectionId) {
5573
+ return `${normalizeIdInput(organizationId)}/connections/${normalizeIdInput(connectionId)}/scim-credential`;
5574
+ }
5575
+ async function enterpriseRequest(method, path, body, normalize) {
5576
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
5577
+ const generation = authorityGeneration;
5578
+ const value = await requestJson(joinURL(authOrigin, "api/v1/auth/enterprise/organizations", path), {
5579
+ fetch: fetchImpl,
5580
+ timeoutMs,
5581
+ method,
5582
+ ...body ? {
5583
+ headers: { "content-type": "application/json" },
5584
+ body
5585
+ } : {},
5586
+ mapError: fromEnterpriseAdministrationError
5587
+ });
5588
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
5589
+ return normalize(value);
5590
+ }
5591
+ async function closureMutation(organizationId, operation, body) {
5592
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
5593
+ const generation = authorityGeneration;
5594
+ const value = await requestJson(joinURL(authOrigin, "api/v1/auth/organizations", organizationId, "closure", operation), {
5595
+ fetch: fetchImpl,
5596
+ timeoutMs,
5597
+ method: "POST",
5598
+ headers: { "content-type": "application/json" },
5599
+ body,
5600
+ mapError: fromOrganizationClosureError
5601
+ });
5602
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
5603
+ return normalizeOrganizationClosure(value);
5604
+ }
4931
5605
  function assertRecentAuthenticationOrigin() {
4932
5606
  if (appOrigin !== authOrigin) throw new TypeError("recent authentication requires the exact Auth Origin");
4933
5607
  }
@@ -5015,6 +5689,20 @@ function createAuthClient(options) {
5015
5689
  ...normalizeOrganizationOwnershipTransferInput(input)
5016
5690
  });
5017
5691
  },
5692
+ async startOrganizationClosureRecentAuthentication(organizationId, input) {
5693
+ return startRecentAuthentication({
5694
+ action: "organization_closure_start",
5695
+ organizationId: normalizeIdInput(organizationId),
5696
+ ...normalizeOrganizationClosureStartInput(input)
5697
+ });
5698
+ },
5699
+ async startOrganizationClosureCancellationRecentAuthentication(organizationId, input) {
5700
+ return startRecentAuthentication({
5701
+ action: "organization_closure_cancel",
5702
+ organizationId: normalizeIdInput(organizationId),
5703
+ ...normalizeOrganizationClosureCancelInput(input)
5704
+ });
5705
+ },
5018
5706
  async approveBootstrapPlatformRoleChange(input) {
5019
5707
  assertRecentAuthenticationOrigin();
5020
5708
  if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
@@ -5098,6 +5786,26 @@ function createAuthClient(options) {
5098
5786
  invitationRequest = request;
5099
5787
  return request;
5100
5788
  },
5789
+ async declineInvitation(input) {
5790
+ const invitation = normalizeInvitationInput(input);
5791
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest || recentAuthenticationStartRequest) throw new AuthError("state_conflict", 409);
5792
+ const generation = authorityGeneration;
5793
+ try {
5794
+ const value = await requestJson(joinURL(authOrigin, "api/v1/auth/organization/reject-invitation"), {
5795
+ fetch: fetchImpl,
5796
+ timeoutMs,
5797
+ method: "POST",
5798
+ headers: { "content-type": "application/json; charset=utf-8" },
5799
+ body: invitation,
5800
+ mapError: fromInvitationAuthorityError
5801
+ });
5802
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
5803
+ return normalizeInvitationDecline(value, invitation.invitationId);
5804
+ } catch (error) {
5805
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
5806
+ throw fromInvitationError(error);
5807
+ }
5808
+ },
5101
5809
  getSession,
5102
5810
  async listOrganizations(input) {
5103
5811
  try {
@@ -5212,6 +5920,35 @@ function createAuthClient(options) {
5212
5920
  if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
5213
5921
  return normalizeRemovedOrganizationMember(value);
5214
5922
  },
5923
+ async suspendOrganizationMember(organizationId, memberId, idempotencyKey) {
5924
+ const organization = normalizeIdInput(organizationId);
5925
+ const member = normalizeIdInput(memberId);
5926
+ const body = normalizeOrganizationMembershipRemovalInput(idempotencyKey);
5927
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
5928
+ const generation = authorityGeneration;
5929
+ const value = await requestJson(joinURL(authOrigin, "api/v1/auth/organizations", organization, "members", member, "suspend"), {
5930
+ fetch: fetchImpl,
5931
+ timeoutMs,
5932
+ method: "POST",
5933
+ headers: { "content-type": "application/json" },
5934
+ body,
5935
+ mapError: fromOrganizationMembershipRemovalError
5936
+ });
5937
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
5938
+ return normalizeSuspendedOrganizationMemberStatus(value);
5939
+ },
5940
+ async listSuspendedOrganizationMembers(organizationId, input) {
5941
+ return organizationRead(`${normalizeIdInput(organizationId)}/suspended-members`, input, normalizeSuspendedOrganizationMembers);
5942
+ },
5943
+ async listRemovedOrganizationMembers(organizationId, input) {
5944
+ return organizationRead(`${normalizeIdInput(organizationId)}/removed-members`, input, normalizeDepartedOrganizationMembers);
5945
+ },
5946
+ async restoreSuspendedOrganizationMember(organizationId, suspensionId, idempotencyKey) {
5947
+ return normalizeRestoredOrganizationMember(await resolveSuspension(organizationId, suspensionId, idempotencyKey, "restore"));
5948
+ },
5949
+ async removeSuspendedOrganizationMember(organizationId, suspensionId, idempotencyKey) {
5950
+ return normalizeRemovedOrganizationMember(await resolveSuspension(organizationId, suspensionId, idempotencyKey, "remove"));
5951
+ },
5215
5952
  async leaveOrganization(organizationId, idempotencyKey) {
5216
5953
  const organization = normalizeIdInput(organizationId);
5217
5954
  const body = normalizeOrganizationMembershipRemovalInput(idempotencyKey);
@@ -5228,6 +5965,23 @@ function createAuthClient(options) {
5228
5965
  if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
5229
5966
  return normalizeOrganizationDeparture(value);
5230
5967
  },
5968
+ async addOrganizationTeamMember(organizationId, teamId, memberId, idempotencyKey) {
5969
+ return normalizeAddedOrganizationTeamMember(await teamMembershipMutation([
5970
+ organizationId,
5971
+ teamId,
5972
+ memberId
5973
+ ], idempotencyKey, (organization, team, member) => joinURL(authOrigin, "api/v1/auth/organizations", organization, "teams", team, "members", member, "add")));
5974
+ },
5975
+ async removeOrganizationTeamMember(organizationId, teamId, memberId, idempotencyKey) {
5976
+ return normalizeRemovedOrganizationTeamMember(await teamMembershipMutation([
5977
+ organizationId,
5978
+ teamId,
5979
+ memberId
5980
+ ], idempotencyKey, (organization, team, member) => joinURL(authOrigin, "api/v1/auth/organizations", organization, "teams", team, "members", member, "remove")));
5981
+ },
5982
+ async deleteOrganizationTeam(organizationId, teamId, idempotencyKey) {
5983
+ return normalizeDeletedOrganizationTeam(await teamMembershipMutation([organizationId, teamId], idempotencyKey, (organization, team) => joinURL(authOrigin, "api/v1/auth/organizations", organization, "teams", team, "delete")));
5984
+ },
5231
5985
  async updateOrganizationDisplay(organizationId, input) {
5232
5986
  const id = normalizeIdInput(organizationId);
5233
5987
  const desired = normalizeOrganizationDisplayInput(input);
@@ -5294,6 +6048,18 @@ function createAuthClient(options) {
5294
6048
  if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
5295
6049
  return normalizeOrganizationOwnershipTransferResult(value);
5296
6050
  },
6051
+ async startOrganizationClosure(organizationId, input) {
6052
+ return closureMutation(normalizeIdInput(organizationId), "", normalizeOrganizationClosureStartInput(input));
6053
+ },
6054
+ async cancelOrganizationClosure(organizationId, input) {
6055
+ return closureMutation(normalizeIdInput(organizationId), "cancel", normalizeOrganizationClosureCancelInput(input));
6056
+ },
6057
+ async getOrganizationClosure(organizationId) {
6058
+ return organizationRead(`${normalizeIdInput(organizationId)}/closure`, void 0, normalizeOrganizationClosure);
6059
+ },
6060
+ async listClosingOrganizations() {
6061
+ return organizationRead("closing", void 0, normalizeClosingOrganizations);
6062
+ },
5297
6063
  async listOrganizationMembers(organizationId, input) {
5298
6064
  return organizationRead(`${normalizeIdInput(organizationId)}/members`, input, normalizeOrganizationMembers);
5299
6065
  },
@@ -5315,15 +6081,105 @@ function createAuthClient(options) {
5315
6081
  async getReceivedInvitation(invitationId) {
5316
6082
  return organizationRead(`received-invitations/${normalizeIdInput(invitationId)}`, void 0, normalizeReceivedInvitation);
5317
6083
  },
6084
+ async listEnterpriseConnections(organizationId) {
6085
+ return enterpriseRequest("GET", `${normalizeIdInput(organizationId)}/connections`, void 0, normalizeEnterpriseConnections);
6086
+ },
6087
+ async getScimCredential(organizationId, connectionId) {
6088
+ return enterpriseRequest("GET", scimCredentialPath(organizationId, connectionId), void 0, (value) => normalizeScimCredentialState(value));
6089
+ },
6090
+ async issueScimCredential(organizationId, connectionId) {
6091
+ return enterpriseRequest("POST", scimCredentialPath(organizationId, connectionId), {}, normalizeScimCredentialIssuance);
6092
+ },
6093
+ async rotateScimCredential(organizationId, connectionId, input) {
6094
+ const body = {
6095
+ expectedRevision: normalizeRevision(input?.expectedRevision),
6096
+ overlapSeconds: normalizeOverlapSeconds(input?.overlapSeconds)
6097
+ };
6098
+ return enterpriseRequest("POST", `${scimCredentialPath(organizationId, connectionId)}/rotate`, body, normalizeScimCredentialIssuance);
6099
+ },
6100
+ async revokeScimCredential(organizationId, connectionId, input) {
6101
+ const body = { expectedRevision: normalizeRevision(input?.expectedRevision) };
6102
+ return enterpriseRequest("POST", `${scimCredentialPath(organizationId, connectionId)}/revoke`, body, (value) => normalizeScimCredentialState(value));
6103
+ },
5318
6104
  async signIn(input) {
5319
6105
  const body = {
5320
6106
  email: normalizeEmail(input?.email),
5321
6107
  password: normalizePassword(input?.password)
5322
6108
  };
5323
- const result = await runAccountMutation(() => accountRequest("sign-in/email", body));
6109
+ const result = await runAccountMutation(async () => {
6110
+ const value = await accountRequest("sign-in/email", body);
6111
+ if (isTwoFactorChallenge(value)) throw new AuthError("two_factor_required", 401);
6112
+ return value;
6113
+ });
6114
+ if (!result.session) throw new AuthError("authentication_required", 401);
6115
+ return result.session;
6116
+ },
6117
+ async verifyTwoFactor(code) {
6118
+ const normalized = normalizeTwoFactorCode(code);
6119
+ const result = await runAccountMutation(() => accountRequest(normalized.route, { code: normalized.code }, fromTwoFactorAuthorityError));
5324
6120
  if (!result.session) throw new AuthError("authentication_required", 401);
5325
6121
  return result.session;
5326
6122
  },
6123
+ async getTwoFactorStatus() {
6124
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
6125
+ const generation = authorityGeneration;
6126
+ const value = await requestJson(joinURL(authOrigin, "api/v1/auth/get-session"), {
6127
+ fetch: fetchImpl,
6128
+ timeoutMs,
6129
+ method: "GET",
6130
+ headers: { "cache-control": "no-store" }
6131
+ });
6132
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
6133
+ return normalizeTwoFactorStatus(value);
6134
+ },
6135
+ async startTwoFactorEnrollment(password) {
6136
+ const body = { password: normalizePassword(password) };
6137
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
6138
+ const generation = authorityGeneration;
6139
+ const value = await accountRequest("two-factor/enable", body, fromTwoFactorAuthorityError);
6140
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
6141
+ return normalizeTwoFactorEnrollment(value);
6142
+ },
6143
+ async confirmTwoFactorEnrollment(code) {
6144
+ const body = { code: normalizeTotpCode(code) };
6145
+ const result = await runAccountMutation(() => accountRequest("two-factor/verify-totp", body, fromTwoFactorAuthorityError));
6146
+ if (!result.session) throw new AuthError("authentication_required", 401);
6147
+ return result.session;
6148
+ },
6149
+ async disableTwoFactor(input) {
6150
+ const body = normalizeTwoFactorStepUp(input);
6151
+ const result = await runAccountMutation(() => accountRequest("two-factor/disable", body, fromTwoFactorAuthorityError));
6152
+ if (!result.session) throw new AuthError("authentication_required", 401);
6153
+ return result.session;
6154
+ },
6155
+ async regenerateTwoFactorBackupCodes(input) {
6156
+ const body = normalizeTwoFactorStepUp(input);
6157
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
6158
+ const generation = authorityGeneration;
6159
+ const value = await accountRequest("two-factor/generate-backup-codes", body, fromTwoFactorAuthorityError);
6160
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
6161
+ return normalizeRegeneratedBackupCodes(value);
6162
+ },
6163
+ async listSessions() {
6164
+ return sessionInventoryRequest("GET", "", normalizeSessionInventory);
6165
+ },
6166
+ async revokeSession(sessionId) {
6167
+ await sessionInventoryRequest("POST", `${normalizeSessionId(sessionId)}/revoke`, normalizeSessionRevocation);
6168
+ },
6169
+ async revokeOtherSessions() {
6170
+ return sessionInventoryRequest("POST", "revoke-others", normalizeOtherSessionRevocation);
6171
+ },
6172
+ async createCeremonyHandoff(input) {
6173
+ return ceremonyRequest("POST", "ceremony-handoffs", normalizeCeremonyHandoffInput(input), normalizeCeremonyHandoff);
6174
+ },
6175
+ async listPasskeys() {
6176
+ return ceremonyRequest("GET", "passkeys", void 0, normalizePasskeyInventory);
6177
+ },
6178
+ async renamePasskey(passkeyId, name) {
6179
+ const id = normalizePasskeyId(passkeyId);
6180
+ const body = { name: normalizePasskeyName(name) };
6181
+ await ceremonyRequest("POST", `passkeys/${id}/name`, body, normalizePasskeyRename);
6182
+ },
5327
6183
  async signInWithSocialIdToken(input) {
5328
6184
  const body = socialIdTokenRequest(normalizeSocialIdTokenInput(input));
5329
6185
  const result = await runAccountMutation(() => accountRequest("sign-in/social", body, fromSocialIdTokenAuthorityError));