@finueva/auth 0.30.0 → 0.31.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/server.d.ts CHANGED
@@ -505,6 +505,73 @@ interface FinuevaUserDirectoryAuth {
505
505
  /** Server-only service assertions. This client has no session authority and performs no automatic retry. */
506
506
  declare function createUserDirectoryAuth(options: UserDirectoryAuthOptions): FinuevaUserDirectoryAuth;
507
507
  //#endregion
508
+ //#region src/organization-role-events/index.d.ts
509
+ type Role = "owner" | "admin" | "member";
510
+ type OrganizationRoleEventReason = "manual_role_change" | "ownership_transferred_out" | "ownership_transferred_in";
511
+ interface OrganizationRoleEventRoles {
512
+ manualRole: Role;
513
+ effectiveRole: Role;
514
+ }
515
+ /** The application-scoped pseudonymous pair of the User Directory. It is not the canonical Auth User ID. */
516
+ interface OrganizationRoleEventUser {
517
+ userId: string;
518
+ userGeneration: string;
519
+ }
520
+ interface OrganizationRoleEvent {
521
+ /** Immutable. A consumer applies each event identifier once. */
522
+ eventId: string;
523
+ /** Decimal commit order within the feed. Gaps are normal. Compare as numbers. */
524
+ sequence: string;
525
+ occurredAt: number;
526
+ organization: {
527
+ id: string;
528
+ generation: string;
529
+ name: string;
530
+ };
531
+ reason: OrganizationRoleEventReason;
532
+ /** Equal on the two events of one ownership transfer. */
533
+ correlationId: string;
534
+ subject: OrganizationRoleEventUser;
535
+ /** Null when the actor can no longer be addressed. */
536
+ actor: OrganizationRoleEventUser | null;
537
+ before: OrganizationRoleEventRoles;
538
+ after: OrganizationRoleEventRoles;
539
+ }
540
+ interface OrganizationRoleEventsInput {
541
+ applicationId: string;
542
+ /** The last checkpoint the consumer stored. Omit it to start at the retained beginning. */
543
+ after?: string;
544
+ limit?: number;
545
+ }
546
+ interface OrganizationRoleEventsPage {
547
+ version: 1;
548
+ applicationId: string;
549
+ events: OrganizationRoleEvent[];
550
+ /** The highest sequence Auth examined. Store it, even when `events` is empty. */
551
+ checkpoint: string;
552
+ /** Only `false` means the feed reached its head. */
553
+ hasMore: boolean;
554
+ }
555
+ interface OrganizationRoleEventsAuthOptions {
556
+ authOrigin: string;
557
+ fetch?: typeof globalThis.fetch;
558
+ timeoutMs?: number;
559
+ }
560
+ interface FinuevaOrganizationRoleEventsAuth {
561
+ listRoleEvents(input: OrganizationRoleEventsInput, assertion: string): Promise<OrganizationRoleEventsPage>;
562
+ }
563
+ /** The stored checkpoint is older than the history Auth retains. Events between it and `earliest` are gone. */
564
+ declare class OrganizationRoleEventCheckpointExpiredError extends AuthError {
565
+ readonly earliest: string;
566
+ constructor(earliest: string);
567
+ }
568
+ /**
569
+ * Server-only service assertions. The client has no session authority and performs no automatic retry.
570
+ * Each page is checked against the request: the application, an ordered and unique event list, and a checkpoint
571
+ * that never moves backwards.
572
+ */
573
+ declare function createOrganizationRoleEventsAuth(options: OrganizationRoleEventsAuthOptions): FinuevaOrganizationRoleEventsAuth;
574
+ //#endregion
508
575
  //#region src/server.d.ts
509
576
  interface ServerAuthOptions {
510
577
  authOrigin: string;
@@ -569,4 +636,4 @@ interface FinuevaServerAuth {
569
636
  }
570
637
  declare function createServerAuth(options: ServerAuthOptions): FinuevaServerAuth;
571
638
  //#endregion
572
- export { type AcceptInvitationInput, type AccountProductOperationAuthOptions, type AccountProductOperationConsumer, type AccountProductOperationInput, type AccountProductOperationPhase, type AccountProductOperationProof, type AccountProductOperationReceipt, type AccountProductOperationSnapshot, type AccountProductOperationSnapshotInput, type AddedOrganizationTeamMember, type AmendOrganizationAdmissionInput, type AttestOrganizationAdmissionInput, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type AuthSession, type AuthUser, type CanceledOrganizationInvitation, type CompleteGoogleAccountRecoveryInput, type CreateOrganizationMemberInvitationInput, type CreatedOrganization, type CreatedOrganizationMemberInvitation, type CreatedOrganizationTeam, type CurrentOrganizationAdmissionInput, type DeclineInvitationInput, type DeletedOrganizationTeam, type DriveCredential, type DriveCredentialInput, type DriveProvisioningAuthOptions, type DriveProvisioningCredential, type DriveRecipient, type DriveRecipientAuthOptions, type FinalizeOrganizationAdmissionInput, type FinalizedOrganizationAdmission, type FinuevaDriveProvisioningAuth, type FinuevaDriveRecipientAuth, type FinuevaIdentityResolverAuth, type FinuevaMembershipResolverAuth, type FinuevaOrganizationAdmissionAuth, type FinuevaOrganizationAdmissionBillingAuth, type FinuevaOrganizationAdmissionDirectoryAuth, type FinuevaOrganizationDirectoryAuth, FinuevaServerAuth, type FinuevaUserDirectoryAuth, type GoogleAccountRecovery, type GoogleAccountRecoveryInput, type IdentityResolverAuthOptions, type InvitationAcceptance, type InvitationDecline, type MembershipResolverAuthOptions, type OrganizationAdmission, type OrganizationAdmissionActorOperation, type OrganizationAdmissionActorProof, type OrganizationAdmissionAuthOptions, type OrganizationAdmissionBillingSetup, type OrganizationAdmissionCreator, type OrganizationAdmissionIdentity, type OrganizationAdmissionIdentityInput, type OrganizationAdmissionInputs, type OrganizationAdmissionOperation, type OrganizationAdmissionPage, type OrganizationAdmissionPageInput, type OrganizationAdmissionReceipt, type OrganizationAdmissionSelection, type OrganizationAdmissionSetup, type OrganizationAdmissionSetupInput, type OrganizationApplicationRegistration, type OrganizationDeparture, type OrganizationDirectoryAuthOptions, type OrganizationDirectoryEntry, type OrganizationDirectoryLookupInput, type OrganizationDirectoryPage, type OrganizationDirectorySearchInput, type OrganizationDisplay, type OrganizationInvitation, type OrganizationInvitationPage, type OrganizationMember, type OrganizationMemberApplicationAccess, type OrganizationMemberApplicationAccessInput, type OrganizationMemberAuthority, type OrganizationMemberPage, type OrganizationMemberPageInput, type OrganizationPage, type OrganizationPageInput, type OrganizationPresenceAuthorization, type OrganizationPresenceInput, type OrganizationTeam, type OrganizationTeamDisplay, type OrganizationTeamMemberPage, type OrganizationTeamPage, type OrganizationWorkspaceSelection, type PersonalWorkspaceSelection, type ReceivedOrganizationInvitation, type ReceivedOrganizationInvitationPage, type RegisterOrganizationApplicationInput, type RegisteredOrganizationApplication, type RemovedOrganizationMember, type RemovedOrganizationTeamMember, type ResentOrganizationInvitation, type ReserveOrganizationAdmissionInput, type ResolveDriveRecipientInput, type ResolveIdentityInput, type ResolveMembershipBatchInput, type ResolveMembershipInput, type ResolvedIdentity, type ResolvedMembership, type ResolvedMembershipBatch, type ResolvedMembershipRole, ServerAuthOptions, ServerInvitationAcceptance, ServerSignOutResult, ServerSocialIdTokenSession, type SocialIdTokenInput, type SocialIdTokenProvider, type UpdateOrganizationDisplayInput, type UpdateOrganizationTeamDisplayInput, type UserApiCredential, type UserApiCredentialInput, type UserApiIdentity, type UserApiVerifierOptions, type UserDirectoryAuthOptions, type UserDirectoryBinding, type UserDirectoryEntry, type UserDirectoryListInput, type UserDirectoryLookupInput, type UserDirectoryMember, type UserDirectoryMembersInput, type UserDirectoryMembersPage, type UserDirectoryPage, type UserDirectoryResolveInput, type WithdrawOrganizationAdmissionInput, type WorkspaceSelection, createAccountProductOperationAuth, createDriveProvisioningAuth, createDriveRecipientAuth, createIdentityResolverAuth, createMembershipResolverAuth, createOrganizationAdmissionAuth, createOrganizationAdmissionBillingAuth, createOrganizationAdmissionDirectoryAuth, createOrganizationDirectoryAuth, createServerAuth, createUserApiVerifier, createUserDirectoryAuth, organizationAdmissionBodyDigest };
639
+ export { type AcceptInvitationInput, type AccountProductOperationAuthOptions, type AccountProductOperationConsumer, type AccountProductOperationInput, type AccountProductOperationPhase, type AccountProductOperationProof, type AccountProductOperationReceipt, type AccountProductOperationSnapshot, type AccountProductOperationSnapshotInput, type AddedOrganizationTeamMember, type AmendOrganizationAdmissionInput, type AttestOrganizationAdmissionInput, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type AuthSession, type AuthUser, type CanceledOrganizationInvitation, type CompleteGoogleAccountRecoveryInput, type CreateOrganizationMemberInvitationInput, type CreatedOrganization, type CreatedOrganizationMemberInvitation, type CreatedOrganizationTeam, type CurrentOrganizationAdmissionInput, type DeclineInvitationInput, type DeletedOrganizationTeam, type DriveCredential, type DriveCredentialInput, type DriveProvisioningAuthOptions, type DriveProvisioningCredential, type DriveRecipient, type DriveRecipientAuthOptions, type FinalizeOrganizationAdmissionInput, type FinalizedOrganizationAdmission, type FinuevaDriveProvisioningAuth, type FinuevaDriveRecipientAuth, type FinuevaIdentityResolverAuth, type FinuevaMembershipResolverAuth, type FinuevaOrganizationAdmissionAuth, type FinuevaOrganizationAdmissionBillingAuth, type FinuevaOrganizationAdmissionDirectoryAuth, type FinuevaOrganizationDirectoryAuth, type FinuevaOrganizationRoleEventsAuth, FinuevaServerAuth, type FinuevaUserDirectoryAuth, type GoogleAccountRecovery, type GoogleAccountRecoveryInput, type IdentityResolverAuthOptions, type InvitationAcceptance, type InvitationDecline, type MembershipResolverAuthOptions, type OrganizationAdmission, type OrganizationAdmissionActorOperation, type OrganizationAdmissionActorProof, type OrganizationAdmissionAuthOptions, type OrganizationAdmissionBillingSetup, type OrganizationAdmissionCreator, type OrganizationAdmissionIdentity, type OrganizationAdmissionIdentityInput, type OrganizationAdmissionInputs, type OrganizationAdmissionOperation, type OrganizationAdmissionPage, type OrganizationAdmissionPageInput, type OrganizationAdmissionReceipt, type OrganizationAdmissionSelection, type OrganizationAdmissionSetup, type OrganizationAdmissionSetupInput, type OrganizationApplicationRegistration, type OrganizationDeparture, type OrganizationDirectoryAuthOptions, type OrganizationDirectoryEntry, type OrganizationDirectoryLookupInput, type OrganizationDirectoryPage, type OrganizationDirectorySearchInput, type OrganizationDisplay, type OrganizationInvitation, type OrganizationInvitationPage, type OrganizationMember, type OrganizationMemberApplicationAccess, type OrganizationMemberApplicationAccessInput, type OrganizationMemberAuthority, type OrganizationMemberPage, type OrganizationMemberPageInput, type OrganizationPage, type OrganizationPageInput, type OrganizationPresenceAuthorization, type OrganizationPresenceInput, type OrganizationRoleEvent, OrganizationRoleEventCheckpointExpiredError, type OrganizationRoleEventReason, type OrganizationRoleEventRoles, type OrganizationRoleEventUser, type OrganizationRoleEventsAuthOptions, type OrganizationRoleEventsInput, type OrganizationRoleEventsPage, type OrganizationTeam, type OrganizationTeamDisplay, type OrganizationTeamMemberPage, type OrganizationTeamPage, type OrganizationWorkspaceSelection, type PersonalWorkspaceSelection, type ReceivedOrganizationInvitation, type ReceivedOrganizationInvitationPage, type RegisterOrganizationApplicationInput, type RegisteredOrganizationApplication, type RemovedOrganizationMember, type RemovedOrganizationTeamMember, type ResentOrganizationInvitation, type ReserveOrganizationAdmissionInput, type ResolveDriveRecipientInput, type ResolveIdentityInput, type ResolveMembershipBatchInput, type ResolveMembershipInput, type ResolvedIdentity, type ResolvedMembership, type ResolvedMembershipBatch, type ResolvedMembershipRole, ServerAuthOptions, ServerInvitationAcceptance, ServerSignOutResult, ServerSocialIdTokenSession, type SocialIdTokenInput, type SocialIdTokenProvider, type UpdateOrganizationDisplayInput, type UpdateOrganizationTeamDisplayInput, type UserApiCredential, type UserApiCredentialInput, type UserApiIdentity, type UserApiVerifierOptions, type UserDirectoryAuthOptions, type UserDirectoryBinding, type UserDirectoryEntry, type UserDirectoryListInput, type UserDirectoryLookupInput, type UserDirectoryMember, type UserDirectoryMembersInput, type UserDirectoryMembersPage, type UserDirectoryPage, type UserDirectoryResolveInput, type WithdrawOrganizationAdmissionInput, type WorkspaceSelection, createAccountProductOperationAuth, createDriveProvisioningAuth, createDriveRecipientAuth, createIdentityResolverAuth, createMembershipResolverAuth, createOrganizationAdmissionAuth, createOrganizationAdmissionBillingAuth, createOrganizationAdmissionDirectoryAuth, createOrganizationDirectoryAuth, createOrganizationRoleEventsAuth, createServerAuth, createUserApiVerifier, createUserDirectoryAuth, organizationAdmissionBodyDigest };
package/dist/server.js CHANGED
@@ -517,7 +517,7 @@ function normalizeWorkspaceSelection(value) {
517
517
  throw new AuthError("invalid_workspace_selection", 422);
518
518
  }
519
519
  function fromAuthorityError(value, fallbackStatus, retryAfter) {
520
- const mapped = mapError(isObject$1(value) && typeof value.code === "string" ? value.code : void 0, fallbackStatus);
520
+ const mapped = mapError$1(isObject$1(value) && typeof value.code === "string" ? value.code : void 0, fallbackStatus);
521
521
  return new AuthError(mapped.code, mapped.status, parseRetryAfter(retryAfter));
522
522
  }
523
523
  function fromAccountAuthorityError(value, status, retryAfter) {
@@ -626,7 +626,7 @@ function fromInvitationAuthorityError(value, status) {
626
626
  function fromInvitationError(error) {
627
627
  return error instanceof AuthError ? error : authorityUnavailable();
628
628
  }
629
- function mapError(code, status) {
629
+ function mapError$1(code, status) {
630
630
  if (code === "authentication_required") return {
631
631
  code,
632
632
  status: 401
@@ -3443,7 +3443,7 @@ function createIdentityResolverAuth(options) {
3443
3443
  //#region src/membership-resolution.ts
3444
3444
  const idPattern = /^[A-Za-z0-9_-]{1,128}$(?![\s\S])/;
3445
3445
  const isoPattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$(?![\s\S])/;
3446
- const roles = [
3446
+ const roles$1 = [
3447
3447
  "admin",
3448
3448
  "member",
3449
3449
  "owner"
@@ -3465,7 +3465,7 @@ function parseMembership(value, organizationId, userId) {
3465
3465
  if (!exact$1(value, ["membership"])) throw authorityUnavailable();
3466
3466
  if (value.membership === null) return null;
3467
3467
  const membership = value.membership;
3468
- if (!exact$1(membership, membershipKeys) || typeof membership.checkedAt !== "string" || !isoPattern.test(membership.checkedAt) || Number.isNaN(Date.parse(membership.checkedAt)) || typeof membership.manualRole !== "string" || !roles.includes(membership.manualRole) || typeof membership.role !== "string" || !roles.includes(membership.role) || typeof membership.memberCount !== "number" || !Number.isSafeInteger(membership.memberCount) || membership.memberCount < 0 || typeof membership.memberId !== "string" || !idPattern.test(membership.memberId) || typeof membership.owner !== "boolean" || membership.organizationId !== organizationId || membership.userId !== userId) throw authorityUnavailable();
3468
+ if (!exact$1(membership, membershipKeys) || typeof membership.checkedAt !== "string" || !isoPattern.test(membership.checkedAt) || Number.isNaN(Date.parse(membership.checkedAt)) || typeof membership.manualRole !== "string" || !roles$1.includes(membership.manualRole) || typeof membership.role !== "string" || !roles$1.includes(membership.role) || typeof membership.memberCount !== "number" || !Number.isSafeInteger(membership.memberCount) || membership.memberCount < 0 || typeof membership.memberId !== "string" || !idPattern.test(membership.memberId) || typeof membership.owner !== "boolean" || membership.organizationId !== organizationId || membership.userId !== userId) throw authorityUnavailable();
3469
3469
  return {
3470
3470
  checkedAt: membership.checkedAt,
3471
3471
  manualRole: membership.manualRole,
@@ -3870,7 +3870,7 @@ function createDriveProvisioningAuth(options) {
3870
3870
  }
3871
3871
  //#endregion
3872
3872
  //#region src/user-directory.ts
3873
- function user(value, applicationId) {
3873
+ function user$1(value, applicationId) {
3874
3874
  if (!exact$6(value, [
3875
3875
  "applicationId",
3876
3876
  "userId",
@@ -3908,7 +3908,7 @@ function nextCursor(value) {
3908
3908
  return value;
3909
3909
  }
3910
3910
  function selectedUser(value, input) {
3911
- const normalized = user(value, input.applicationId);
3911
+ const normalized = user$1(value, input.applicationId);
3912
3912
  if (normalized.userId !== input.userId || normalized.userGeneration !== input.userGeneration) throw authorityUnavailable();
3913
3913
  return normalized;
3914
3914
  }
@@ -3961,7 +3961,7 @@ function createUserDirectoryAuth(options) {
3961
3961
  pageInput(input);
3962
3962
  const value = await exchange("list", input, assertion);
3963
3963
  if (!exact$6(value, ["users", "nextCursor"]) || !Array.isArray(value.users) || value.users.length > (input.limit ?? 50)) throw authorityUnavailable();
3964
- const users = value.users.map((item) => user(item, input.applicationId));
3964
+ const users = value.users.map((item) => user$1(item, input.applicationId));
3965
3965
  if (users.some((item) => item.lifecycle === "deleted") || new Set(users.map((item) => item.userId)).size !== users.length) throw authorityUnavailable();
3966
3966
  return {
3967
3967
  users,
@@ -3990,7 +3990,7 @@ function createUserDirectoryAuth(options) {
3990
3990
  "role",
3991
3991
  "membershipStatus"
3992
3992
  ]) || item.role !== "owner" && item.role !== "admin" && item.role !== "member" || item.membershipStatus !== "active" && item.membershipStatus !== "suspended") throw authorityUnavailable();
3993
- const normalized = user(item.user, input.applicationId);
3993
+ const normalized = user$1(item.user, input.applicationId);
3994
3994
  if (normalized.lifecycle === "deleted") throw authorityUnavailable();
3995
3995
  return {
3996
3996
  user: normalized,
@@ -4011,7 +4011,7 @@ function createUserDirectoryAuth(options) {
4011
4011
  if (!exact$6(input, ["applicationId", "authUserId"]) || !directoryId(input.applicationId) || !directoryId(input.authUserId)) throw new AuthError("invalid_request", 400);
4012
4012
  const value = await exchange("resolve", input, assertion);
4013
4013
  if (!exact$6(value, ["user"])) throw authorityUnavailable();
4014
- const result = value.user === null ? null : user(value.user, input.applicationId);
4014
+ const result = value.user === null ? null : user$1(value.user, input.applicationId);
4015
4015
  if (result?.lifecycle === "deleted") throw authorityUnavailable();
4016
4016
  return result;
4017
4017
  },
@@ -4031,6 +4031,169 @@ function createUserDirectoryAuth(options) {
4031
4031
  };
4032
4032
  }
4033
4033
  //#endregion
4034
+ //#region src/organization-role-events/index.ts
4035
+ var OrganizationRoleEventCheckpointExpiredError = class extends AuthError {
4036
+ earliest;
4037
+ constructor(earliest) {
4038
+ super("state_conflict", 409);
4039
+ this.name = "OrganizationRoleEventCheckpointExpiredError";
4040
+ this.earliest = earliest;
4041
+ }
4042
+ };
4043
+ const checkpointPattern = /^(?:0|[1-9][0-9]{0,15})$(?![\s\S])/;
4044
+ const roles = new Set([
4045
+ "owner",
4046
+ "admin",
4047
+ "member"
4048
+ ]);
4049
+ const reasons = new Set([
4050
+ "manual_role_change",
4051
+ "ownership_transferred_out",
4052
+ "ownership_transferred_in"
4053
+ ]);
4054
+ function checkpoint(value) {
4055
+ return typeof value === "string" && checkpointPattern.test(value) && Number.isSafeInteger(Number(value));
4056
+ }
4057
+ function user(value) {
4058
+ if (!exact$6(value, ["userId", "userGeneration"]) || !directoryGeneration(value.userId) || !directoryGeneration(value.userGeneration)) throw authorityUnavailable();
4059
+ return {
4060
+ userId: value.userId,
4061
+ userGeneration: value.userGeneration
4062
+ };
4063
+ }
4064
+ function roleSet(value) {
4065
+ if (!exact$6(value, ["manualRole", "effectiveRole"]) || !roles.has(value.manualRole) || !roles.has(value.effectiveRole)) throw authorityUnavailable();
4066
+ return {
4067
+ manualRole: value.manualRole,
4068
+ effectiveRole: value.effectiveRole
4069
+ };
4070
+ }
4071
+ function event(value) {
4072
+ if (!exact$6(value, [
4073
+ "eventId",
4074
+ "sequence",
4075
+ "occurredAt",
4076
+ "organization",
4077
+ "reason",
4078
+ "correlationId",
4079
+ "subject",
4080
+ "actor",
4081
+ "before",
4082
+ "after"
4083
+ ]) || typeof value.eventId !== "string" || !/^rle_[a-f0-9]{32}$(?![\s\S])/.test(value.eventId) || !checkpoint(value.sequence) || value.sequence === "0" || !Number.isSafeInteger(value.occurredAt) || value.occurredAt < 0 || typeof value.correlationId !== "string" || !/^[A-Za-z0-9_-]{43}$(?![\s\S])/.test(value.correlationId) || !reasons.has(value.reason) || !exact$6(value.organization, [
4084
+ "id",
4085
+ "generation",
4086
+ "name"
4087
+ ]) || !directoryId(value.organization.id) || !directoryGeneration(value.organization.generation) || typeof value.organization.name !== "string" || value.organization.name.length < 1 || new TextEncoder().encode(value.organization.name).byteLength > 255) throw authorityUnavailable();
4088
+ const organization = value.organization;
4089
+ return {
4090
+ eventId: value.eventId,
4091
+ sequence: value.sequence,
4092
+ occurredAt: value.occurredAt,
4093
+ organization: {
4094
+ id: organization.id,
4095
+ generation: organization.generation,
4096
+ name: organization.name
4097
+ },
4098
+ reason: value.reason,
4099
+ correlationId: value.correlationId,
4100
+ subject: user(value.subject),
4101
+ actor: value.actor === null ? null : user(value.actor),
4102
+ before: roleSet(value.before),
4103
+ after: roleSet(value.after)
4104
+ };
4105
+ }
4106
+ function listInput(input) {
4107
+ if (!record$1(input) || Object.keys(input).some((key) => ![
4108
+ "applicationId",
4109
+ "after",
4110
+ "limit"
4111
+ ].includes(key)) || !directoryId(input.applicationId) || input.after !== void 0 && !checkpoint(input.after) || input.limit !== void 0 && (!Number.isInteger(input.limit) || input.limit < 1 || input.limit > 100)) throw new AuthError("invalid_request", 400);
4112
+ }
4113
+ function mapError(value, status, retryAfter) {
4114
+ if (status === 409 && exact$6(value, [
4115
+ "code",
4116
+ "message",
4117
+ "earliest"
4118
+ ]) && value.code === "CHECKPOINT_EXPIRED" && checkpoint(value.earliest)) return new OrganizationRoleEventCheckpointExpiredError(value.earliest);
4119
+ return fromAuthorityError(value, status, retryAfter);
4120
+ }
4121
+ function createOrganizationRoleEventsAuth(options) {
4122
+ const origin = normalizeOrigin(options.authOrigin, "authOrigin");
4123
+ const fetchImpl = options.fetch ?? globalThis.fetch?.bind(globalThis);
4124
+ if (typeof fetchImpl !== "function") throw new TypeError("fetch is required");
4125
+ const timeoutMs = normalizeTimeout(options.timeoutMs);
4126
+ let inFlight = 0;
4127
+ async function exchange(body, assertion) {
4128
+ if (typeof assertion !== "string" || assertion.length > 16 * 1024 || !/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$(?![\s\S])/.test(assertion)) throw new AuthError("invalid_request", 400);
4129
+ if (inFlight >= 4) throw new AuthError("state_conflict", 409);
4130
+ inFlight += 1;
4131
+ const controller = new AbortController();
4132
+ let timer;
4133
+ const deadline = new Promise((_, reject) => {
4134
+ timer = setTimeout(() => {
4135
+ reject(authorityUnavailable());
4136
+ controller.abort();
4137
+ }, timeoutMs);
4138
+ });
4139
+ try {
4140
+ return await Promise.race([requestJson(joinURL(origin, "api/v1/auth/organization-role-events/list"), {
4141
+ fetch: fetchImpl,
4142
+ timeoutMs,
4143
+ method: "POST",
4144
+ credentials: "omit",
4145
+ cache: "no-store",
4146
+ headers: {
4147
+ "x-finueva-service-assertion": assertion,
4148
+ "content-type": "application/json",
4149
+ accept: "application/json"
4150
+ },
4151
+ body,
4152
+ maxResponseBytes: 256 * 1024,
4153
+ signal: controller.signal,
4154
+ mapError
4155
+ }).finally(() => {
4156
+ inFlight -= 1;
4157
+ }), deadline]);
4158
+ } catch (cause) {
4159
+ if (cause instanceof AuthError) throw cause;
4160
+ throw authorityUnavailable();
4161
+ } finally {
4162
+ clearTimeout(timer);
4163
+ controller.abort();
4164
+ }
4165
+ }
4166
+ return { async listRoleEvents(input, assertion) {
4167
+ listInput(input);
4168
+ const value = await exchange(input, assertion);
4169
+ if (!exact$6(value, [
4170
+ "version",
4171
+ "applicationId",
4172
+ "events",
4173
+ "checkpoint",
4174
+ "hasMore"
4175
+ ]) || value.version !== 1 || value.applicationId !== input.applicationId || !Array.isArray(value.events) || value.events.length > (input.limit ?? 50) || !checkpoint(value.checkpoint) || typeof value.hasMore !== "boolean") throw authorityUnavailable();
4176
+ const events = value.events.map(event);
4177
+ const floor = Number(input.after ?? "0");
4178
+ let previous = floor;
4179
+ const seen = new Set();
4180
+ for (const item of events) {
4181
+ const sequence = Number(item.sequence);
4182
+ if (sequence <= previous || sequence > Number(value.checkpoint) || seen.has(item.eventId)) throw authorityUnavailable();
4183
+ previous = sequence;
4184
+ seen.add(item.eventId);
4185
+ }
4186
+ if (Number(value.checkpoint) < floor || value.hasMore && Number(value.checkpoint) <= floor) throw authorityUnavailable();
4187
+ return {
4188
+ version: 1,
4189
+ applicationId: input.applicationId,
4190
+ events,
4191
+ checkpoint: value.checkpoint,
4192
+ hasMore: value.hasMore
4193
+ };
4194
+ } };
4195
+ }
4196
+ //#endregion
4034
4197
  //#region src/server.ts
4035
4198
  const MAX_AUTHORIZATION_BYTES = 16 * 1024;
4036
4199
  function createServerAuth(options) {
@@ -4591,4 +4754,4 @@ function authAuthorizationHeader(value) {
4591
4754
  return value;
4592
4755
  }
4593
4756
  //#endregion
4594
- export { AuthError, createAccountProductOperationAuth, createDriveProvisioningAuth, createDriveRecipientAuth, createIdentityResolverAuth, createMembershipResolverAuth, createOrganizationAdmissionAuth, createOrganizationAdmissionBillingAuth, createOrganizationAdmissionDirectoryAuth, createOrganizationDirectoryAuth, createServerAuth, createUserApiVerifier, createUserDirectoryAuth, organizationAdmissionBodyDigest };
4757
+ export { AuthError, OrganizationRoleEventCheckpointExpiredError, createAccountProductOperationAuth, createDriveProvisioningAuth, createDriveRecipientAuth, createIdentityResolverAuth, createMembershipResolverAuth, createOrganizationAdmissionAuth, createOrganizationAdmissionBillingAuth, createOrganizationAdmissionDirectoryAuth, createOrganizationDirectoryAuth, createOrganizationRoleEventsAuth, createServerAuth, createUserApiVerifier, createUserDirectoryAuth, organizationAdmissionBodyDigest };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finueva/auth",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
4
4
  "description": "Public browser and server SDK for Finueva Auth",
5
5
  "type": "module",
6
6
  "sideEffects": false,