@finueva/auth 0.31.0 → 0.32.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.js CHANGED
@@ -168,7 +168,7 @@ function normalizeIdInput(value) {
168
168
  return value;
169
169
  }
170
170
  function normalizeOrganization(value) {
171
- exact$7(value, [
171
+ exact$8(value, [
172
172
  "capabilities",
173
173
  "id",
174
174
  "lifecycle",
@@ -178,7 +178,7 @@ function normalizeOrganization(value) {
178
178
  "slug"
179
179
  ]);
180
180
  if (!isId(value.id) || !boundedString(value.name, 255) || !boundedString(value.slug, 255) || value.lifecycle !== "ordinary" && value.lifecycle !== "managed" || !role(value.role) || !isObject$1(value.capabilities)) throw authorityUnavailable();
181
- exact$7(value.capabilities, [
181
+ exact$8(value.capabilities, [
182
182
  "readInvitations",
183
183
  "readMembers",
184
184
  "readTeams"
@@ -240,7 +240,7 @@ function normalizeOrganizationCreationInput(name, slug, idempotencyKey) {
240
240
  };
241
241
  }
242
242
  function normalizeCreatedOrganization(value) {
243
- exact$7(value, [
243
+ exact$8(value, [
244
244
  "id",
245
245
  "name",
246
246
  "slug"
@@ -260,7 +260,7 @@ function normalizeOrganizationTeamCreationInput(name, idempotencyKey) {
260
260
  };
261
261
  }
262
262
  function normalizeCreatedOrganizationTeam(value) {
263
- exact$7(value, ["id", "name"]);
263
+ exact$8(value, ["id", "name"]);
264
264
  if (!isId(value.id) || !boundedString(value.name, 255)) throw authorityUnavailable();
265
265
  return {
266
266
  id: value.id,
@@ -287,7 +287,7 @@ function normalizeOrganizationMemberInvitationCreationInput(value) {
287
287
  };
288
288
  }
289
289
  function normalizeCreatedOrganizationMemberInvitation(value) {
290
- exact$7(value, ["expiresAt", "id"]);
290
+ exact$8(value, ["expiresAt", "id"]);
291
291
  if (!isId(value.id)) throw authorityUnavailable();
292
292
  return {
293
293
  id: value.id,
@@ -304,7 +304,7 @@ function normalizeOrganizationInvitationAdministrationInput(idempotencyKey) {
304
304
  return { idempotencyKey };
305
305
  }
306
306
  function normalizeCanceledOrganizationInvitation(value) {
307
- exact$7(value, ["status"]);
307
+ exact$8(value, ["status"]);
308
308
  if (value.status !== "canceled") throw authorityUnavailable();
309
309
  return { status: "canceled" };
310
310
  }
@@ -313,12 +313,12 @@ function normalizeOrganizationMembershipRemovalInput(idempotencyKey) {
313
313
  return { idempotencyKey };
314
314
  }
315
315
  function normalizeRemovedOrganizationMember(value) {
316
- exact$7(value, ["status"]);
316
+ exact$8(value, ["status"]);
317
317
  if (value.status !== "removed") throw authorityUnavailable();
318
318
  return { status: "removed" };
319
319
  }
320
320
  function normalizeOrganizationDeparture(value) {
321
- exact$7(value, ["status"]);
321
+ exact$8(value, ["status"]);
322
322
  if (value.status !== "left") throw authorityUnavailable();
323
323
  return { status: "left" };
324
324
  }
@@ -327,22 +327,22 @@ function normalizeOrganizationTeamMembershipInput(idempotencyKey) {
327
327
  return { idempotencyKey };
328
328
  }
329
329
  function normalizeAddedOrganizationTeamMember(value) {
330
- exact$7(value, ["status"]);
330
+ exact$8(value, ["status"]);
331
331
  if (value.status !== "added") throw authorityUnavailable();
332
332
  return { status: "added" };
333
333
  }
334
334
  function normalizeRemovedOrganizationTeamMember(value) {
335
- exact$7(value, ["status"]);
335
+ exact$8(value, ["status"]);
336
336
  if (value.status !== "removed") throw authorityUnavailable();
337
337
  return { status: "removed" };
338
338
  }
339
339
  function normalizeDeletedOrganizationTeam(value) {
340
- exact$7(value, ["status"]);
340
+ exact$8(value, ["status"]);
341
341
  if (value.status !== "deleted") throw authorityUnavailable();
342
342
  return { status: "deleted" };
343
343
  }
344
344
  function normalizeOrganizations(value) {
345
- exact$7(value, ["nextCursor", "organizations"]);
345
+ exact$8(value, ["nextCursor", "organizations"]);
346
346
  if (!Array.isArray(value.organizations) || value.organizations.length > 100) throw authorityUnavailable();
347
347
  return {
348
348
  organizations: unique(value.organizations.map(normalizeOrganization), (item) => item.id),
@@ -350,11 +350,11 @@ function normalizeOrganizations(value) {
350
350
  };
351
351
  }
352
352
  function normalizeOrganizationMembers(value) {
353
- exact$7(value, ["members", "nextCursor"]);
353
+ exact$8(value, ["members", "nextCursor"]);
354
354
  if (!Array.isArray(value.members) || value.members.length > 100) throw authorityUnavailable();
355
355
  return {
356
356
  members: unique(value.members.map((member) => {
357
- exact$7(member, [
357
+ exact$8(member, [
358
358
  "email",
359
359
  "id",
360
360
  "image",
@@ -383,11 +383,11 @@ function normalizeOrganizationMembers(value) {
383
383
  };
384
384
  }
385
385
  function normalizeOrganizationTeams(value) {
386
- exact$7(value, ["nextCursor", "teams"]);
386
+ exact$8(value, ["nextCursor", "teams"]);
387
387
  if (!Array.isArray(value.teams) || value.teams.length > 100) throw authorityUnavailable();
388
388
  return {
389
389
  teams: unique(value.teams.map((team) => {
390
- exact$7(team, [
390
+ exact$8(team, [
391
391
  "category",
392
392
  "createdAt",
393
393
  "id",
@@ -405,7 +405,7 @@ function normalizeOrganizationTeams(value) {
405
405
  };
406
406
  }
407
407
  function normalizeOrganizationTeamMembers(value) {
408
- exact$7(value, ["memberIds", "nextCursor"]);
408
+ exact$8(value, ["memberIds", "nextCursor"]);
409
409
  if (!Array.isArray(value.memberIds) || value.memberIds.length > 100) throw authorityUnavailable();
410
410
  return {
411
411
  memberIds: unique(value.memberIds.map((item) => normalizeResponseId(item)), (item) => item),
@@ -413,7 +413,7 @@ function normalizeOrganizationTeamMembers(value) {
413
413
  };
414
414
  }
415
415
  function normalizeOrganizationInvitation(value) {
416
- exact$7(value, [
416
+ exact$8(value, [
417
417
  "createdAt",
418
418
  "email",
419
419
  "expiresAt",
@@ -424,7 +424,7 @@ function normalizeOrganizationInvitation(value) {
424
424
  "teamIds"
425
425
  ]);
426
426
  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$1(value.inviter)) throw authorityUnavailable();
427
- exact$7(value.inviter, ["membershipId", "name"]);
427
+ exact$8(value.inviter, ["membershipId", "name"]);
428
428
  if (!isId(value.inviter.membershipId) || !boundedString(value.inviter.name, 255)) throw authorityUnavailable();
429
429
  return {
430
430
  id: value.id,
@@ -441,7 +441,7 @@ function normalizeOrganizationInvitation(value) {
441
441
  };
442
442
  }
443
443
  function normalizeOrganizationInvitations(value) {
444
- exact$7(value, ["invitations", "nextCursor"]);
444
+ exact$8(value, ["invitations", "nextCursor"]);
445
445
  if (!Array.isArray(value.invitations) || value.invitations.length > 100) throw authorityUnavailable();
446
446
  return {
447
447
  invitations: unique(value.invitations.map(normalizeOrganizationInvitation), (item) => item.id),
@@ -449,7 +449,7 @@ function normalizeOrganizationInvitations(value) {
449
449
  };
450
450
  }
451
451
  function normalizeReceivedInvitation(value) {
452
- exact$7(value, [
452
+ exact$8(value, [
453
453
  "expiresAt",
454
454
  "id",
455
455
  "inviterName",
@@ -458,7 +458,7 @@ function normalizeReceivedInvitation(value) {
458
458
  "teams"
459
459
  ]);
460
460
  if (!isId(value.id) || !boundedString(value.inviterName, 255) || !role(value.role) || !Array.isArray(value.teams) || value.teams.length > 100 || !isObject$1(value.organization)) throw authorityUnavailable();
461
- exact$7(value.organization, [
461
+ exact$8(value.organization, [
462
462
  "id",
463
463
  "logo",
464
464
  "name",
@@ -475,7 +475,7 @@ function normalizeReceivedInvitation(value) {
475
475
  },
476
476
  role: value.role,
477
477
  teams: unique(value.teams.map((team) => {
478
- exact$7(team, ["id", "name"]);
478
+ exact$8(team, ["id", "name"]);
479
479
  if (!isId(team.id) || !boundedString(team.name, 255)) throw authorityUnavailable();
480
480
  return {
481
481
  id: team.id,
@@ -487,7 +487,7 @@ function normalizeReceivedInvitation(value) {
487
487
  };
488
488
  }
489
489
  function normalizeReceivedInvitations(value) {
490
- exact$7(value, ["invitations", "nextCursor"]);
490
+ exact$8(value, ["invitations", "nextCursor"]);
491
491
  if (!Array.isArray(value.invitations) || value.invitations.length > 100) throw authorityUnavailable();
492
492
  return {
493
493
  invitations: unique(value.invitations.map(normalizeReceivedInvitation), (item) => item.id),
@@ -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$1(isObject$1(value) && typeof value.code === "string" ? value.code : void 0, fallbackStatus);
520
+ const mapped = mapError$2(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) {
@@ -577,7 +577,7 @@ function fromOrganizationMembershipRemovalError(value, status, retryAfter) {
577
577
  return fromOrganizationMutationAuthorityError(value, status, retryAfter);
578
578
  }
579
579
  function normalizeOrganizationMemberAuthority(value, organizationId, memberId) {
580
- exact$7(value, [
580
+ exact$8(value, [
581
581
  "organizationId",
582
582
  "actor",
583
583
  "target"
@@ -594,8 +594,45 @@ function normalizeOrganizationMemberAuthority(value, organizationId, memberId) {
594
594
  target
595
595
  };
596
596
  }
597
+ function normalizeOrganizationMemberAuthorityV2(value, organizationId, memberId) {
598
+ exact$8(value, [
599
+ "version",
600
+ "organizationId",
601
+ "actor",
602
+ "target"
603
+ ]);
604
+ if (value.version !== 2 || value.organizationId !== organizationId || !isId(value.organizationId)) throw authorityUnavailable();
605
+ const target = value.target;
606
+ exact$8(target, [
607
+ "memberId",
608
+ "manualRole",
609
+ "role",
610
+ "authorityRevision"
611
+ ]);
612
+ if (target.manualRole !== null) return {
613
+ version: 2,
614
+ ...normalizeOrganizationMemberAuthority({
615
+ organizationId: value.organizationId,
616
+ actor: value.actor,
617
+ target
618
+ }, organizationId, memberId)
619
+ };
620
+ const actor = normalizeOrganizationAuthorityMemberOutcome(value.actor);
621
+ if (actor.manualRole !== "owner" && actor.manualRole !== "admin" || actor.role !== actor.manualRole || !isId(target.memberId) || target.memberId !== memberId || target.memberId === actor.memberId || target.role !== "member" && target.role !== "admin") throw authorityUnavailable();
622
+ return {
623
+ version: 2,
624
+ organizationId: value.organizationId,
625
+ actor,
626
+ target: {
627
+ memberId: target.memberId,
628
+ manualRole: null,
629
+ role: target.role,
630
+ authorityRevision: normalizeAuthorityResultRevision(target.authorityRevision)
631
+ }
632
+ };
633
+ }
597
634
  function normalizeOrganizationAuthorityMemberOutcome(value, includesStatus = false) {
598
- exact$7(value, [
635
+ exact$8(value, [
599
636
  "memberId",
600
637
  "manualRole",
601
638
  "role",
@@ -626,7 +663,7 @@ function fromInvitationAuthorityError(value, status) {
626
663
  function fromInvitationError(error) {
627
664
  return error instanceof AuthError ? error : authorityUnavailable();
628
665
  }
629
- function mapError$1(code, status) {
666
+ function mapError$2(code, status) {
630
667
  if (code === "authentication_required") return {
631
668
  code,
632
669
  status: 401
@@ -688,7 +725,7 @@ function toDate(value) {
688
725
  function isId(value) {
689
726
  return typeof value === "string" && id$3.test(value);
690
727
  }
691
- function exact$7(value, keys) {
728
+ function exact$8(value, keys) {
692
729
  if (!isObject$1(value) || Object.keys(value).sort().join(",") !== [...keys].sort().join(",")) throw authorityUnavailable();
693
730
  }
694
731
  function boundedString(value, maximum) {
@@ -736,7 +773,7 @@ function isObject$1(value) {
736
773
  function record$1(value) {
737
774
  return value !== null && typeof value === "object" && !Array.isArray(value);
738
775
  }
739
- function exact$6(value, keys) {
776
+ function exact$7(value, keys) {
740
777
  return record$1(value) && Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
741
778
  }
742
779
  function directoryId(value) {
@@ -746,7 +783,7 @@ function directoryGeneration(value) {
746
783
  return typeof value === "string" && /^[a-f0-9]{32}$(?![\s\S])/.test(value);
747
784
  }
748
785
  function normalizeDirectoryEntry(value, applicationId) {
749
- if (!exact$6(value, [
786
+ if (!exact$7(value, [
750
787
  "organizationId",
751
788
  "applicationId",
752
789
  "organizationGeneration",
@@ -770,14 +807,14 @@ function registrationTarget(organizationId, applicationId) {
770
807
  return `${organizationId}/applications/${applicationId}/registration`;
771
808
  }
772
809
  function registrationInput(input) {
773
- if (!exact$6(input, ["organizationGeneration", "idempotencyKey"]) || !directoryGeneration(input.organizationGeneration) || typeof input.idempotencyKey !== "string" || !/^[A-Za-z0-9_-]{16,128}$(?![\s\S])/.test(input.idempotencyKey)) throw new AuthError("invalid_request", 400);
810
+ if (!exact$7(input, ["organizationGeneration", "idempotencyKey"]) || !directoryGeneration(input.organizationGeneration) || typeof input.idempotencyKey !== "string" || !/^[A-Za-z0-9_-]{16,128}$(?![\s\S])/.test(input.idempotencyKey)) throw new AuthError("invalid_request", 400);
774
811
  return {
775
812
  organizationGeneration: input.organizationGeneration,
776
813
  idempotencyKey: input.idempotencyKey
777
814
  };
778
815
  }
779
816
  function normalizeOrganizationApplicationRegistration(value, organizationId, applicationId) {
780
- if (!exact$6(value, [
817
+ if (!exact$7(value, [
781
818
  "organizationId",
782
819
  "applicationId",
783
820
  "organizationGeneration",
@@ -793,7 +830,7 @@ function normalizeOrganizationApplicationRegistration(value, organizationId, app
793
830
  };
794
831
  }
795
832
  function normalizeRegisteredOrganizationApplication(value, organizationId, applicationId, generation) {
796
- if (!exact$6(value, ["organization", "outcome"]) || value.outcome !== "registered" && value.outcome !== "replayed") throw authorityUnavailable();
833
+ if (!exact$7(value, ["organization", "outcome"]) || value.outcome !== "registered" && value.outcome !== "replayed") throw authorityUnavailable();
797
834
  const organization = normalizeDirectoryEntry(value.organization, applicationId);
798
835
  if (organization.organizationId !== organizationId || organization.organizationGeneration !== generation || organization.lifecycle !== "active") throw authorityUnavailable();
799
836
  return {
@@ -1365,13 +1402,13 @@ function createOrganizationDirectoryAuth(options) {
1365
1402
  }
1366
1403
  return {
1367
1404
  async lookupOrganization(input, assertion) {
1368
- if (!exact$6(input, [
1405
+ if (!exact$7(input, [
1369
1406
  "organizationId",
1370
1407
  "applicationId",
1371
1408
  "organizationGeneration"
1372
1409
  ]) || !directoryId(input.organizationId) || !directoryId(input.applicationId) || !directoryGeneration(input.organizationGeneration)) throw new AuthError("invalid_request", 400);
1373
1410
  const value = await exchange("lookup", input, assertion);
1374
- if (!exact$6(value, ["organization"])) throw authorityUnavailable();
1411
+ if (!exact$7(value, ["organization"])) throw authorityUnavailable();
1375
1412
  if (value.organization === null) return null;
1376
1413
  const organization = normalizeDirectoryEntry(value.organization, input.applicationId);
1377
1414
  if (organization.organizationId !== input.organizationId || organization.organizationGeneration !== input.organizationGeneration) throw authorityUnavailable();
@@ -1386,7 +1423,7 @@ function createOrganizationDirectoryAuth(options) {
1386
1423
  ].includes(key)) || !directoryId(input.applicationId) || input.query !== void 0 && (typeof input.query !== "string" || input.query.length < 1 || input.query.length > 128 || Array.from(input.query).some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127)) || input.limit !== void 0 && (!Number.isInteger(input.limit) || input.limit < 1 || input.limit > 100) || input.cursor !== void 0 && (typeof input.cursor !== "string" || input.cursor.length > 2048)) throw new AuthError("invalid_request", 400);
1387
1424
  const limit = input.limit ?? 50;
1388
1425
  const value = await exchange("search", input, assertion);
1389
- if (!exact$6(value, ["organizations", "nextCursor"]) || !Array.isArray(value.organizations) || value.organizations.length > limit || value.nextCursor !== null && (typeof value.nextCursor !== "string" || !value.nextCursor.length || value.nextCursor.length > 2048)) throw authorityUnavailable();
1426
+ if (!exact$7(value, ["organizations", "nextCursor"]) || !Array.isArray(value.organizations) || value.organizations.length > limit || value.nextCursor !== null && (typeof value.nextCursor !== "string" || !value.nextCursor.length || value.nextCursor.length > 2048)) throw authorityUnavailable();
1390
1427
  const organizations = value.organizations.map((item) => normalizeDirectoryEntry(item, input.applicationId));
1391
1428
  if (organizations.some((organization) => organization.lifecycle === "deleted") || new Set(organizations.map((organization) => `${organization.organizationId}:${organization.organizationGeneration}`)).size !== organizations.length) throw authorityUnavailable();
1392
1429
  return {
@@ -1405,7 +1442,7 @@ const digest$2 = (value) => typeof value === "string" && /^[a-f0-9]{64}$(?![\s\S
1405
1442
  const text = (value) => typeof value === "string" && value.length > 0 && new TextEncoder().encode(value).byteLength <= 255;
1406
1443
  const slug = (value) => typeof value === "string" && /^[a-z0-9-]{1,128}$(?![\s\S])/.test(value);
1407
1444
  function setupInput(input, additional = []) {
1408
- if (!exact$6(input, [
1445
+ if (!exact$7(input, [
1409
1446
  "applicationId",
1410
1447
  "setupId",
1411
1448
  ...additional
@@ -1433,7 +1470,7 @@ const setupKeys = [
1433
1470
  "amendable"
1434
1471
  ];
1435
1472
  function setup(value, applicationId, setupId) {
1436
- if (!exact$6(value, setupKeys) || !directoryGeneration(value.setupId) || setupId !== void 0 && value.setupId !== setupId || value.applicationId !== applicationId || !directoryId(value.organizationId) || !directoryGeneration(value.organizationGeneration) || value.kind !== "new" && value.kind !== "existing" || ![
1473
+ if (!exact$7(value, setupKeys) || !directoryGeneration(value.setupId) || setupId !== void 0 && value.setupId !== setupId || value.applicationId !== applicationId || !directoryId(value.organizationId) || !directoryGeneration(value.organizationGeneration) || value.kind !== "new" && value.kind !== "existing" || ![
1437
1474
  "reserved",
1438
1475
  "activating",
1439
1476
  "activated",
@@ -1455,7 +1492,7 @@ function setup(value, applicationId, setupId) {
1455
1492
  };
1456
1493
  }
1457
1494
  function billingSetup(value, applicationId, setupId) {
1458
- if (!exact$6(value, [...setupKeys, "creator"]) || !exact$6(value.creator, ["userId", "userGeneration"]) || !directoryGeneration(value.creator.userId) || !directoryGeneration(value.creator.userGeneration)) throw authorityUnavailable();
1495
+ if (!exact$7(value, [...setupKeys, "creator"]) || !exact$7(value.creator, ["userId", "userGeneration"]) || !directoryGeneration(value.creator.userId) || !directoryGeneration(value.creator.userGeneration)) throw authorityUnavailable();
1459
1496
  const { creator: _creator, ...projection } = value;
1460
1497
  return {
1461
1498
  ...setup(projection, applicationId, setupId),
@@ -1466,7 +1503,7 @@ function billingSetup(value, applicationId, setupId) {
1466
1503
  };
1467
1504
  }
1468
1505
  function page(value, input, pending = false) {
1469
- if (!exact$6(value, ["setups", "nextCursor"]) || !Array.isArray(value.setups) || value.setups.length > (input.limit ?? 25) || value.nextCursor !== null && (typeof value.nextCursor !== "string" || !value.nextCursor.length || value.nextCursor.length > 2048 || value.nextCursor === input.cursor)) throw authorityUnavailable();
1506
+ if (!exact$7(value, ["setups", "nextCursor"]) || !Array.isArray(value.setups) || value.setups.length > (input.limit ?? 25) || value.nextCursor !== null && (typeof value.nextCursor !== "string" || !value.nextCursor.length || value.nextCursor.length > 2048 || value.nextCursor === input.cursor)) throw authorityUnavailable();
1470
1507
  const setups = value.setups.map((item) => setup(item, input.applicationId));
1471
1508
  if (new Set(setups.map((item) => item.setupId)).size !== setups.length || pending && setups.some((item) => item.status === "activated")) throw authorityUnavailable();
1472
1509
  return {
@@ -1475,7 +1512,7 @@ function page(value, input, pending = false) {
1475
1512
  };
1476
1513
  }
1477
1514
  function admission(value, applicationId, organizationId, generation) {
1478
- if (!exact$6(value, [
1515
+ if (!exact$7(value, [
1479
1516
  "applicationId",
1480
1517
  "organizationId",
1481
1518
  "organizationGeneration",
@@ -1495,7 +1532,7 @@ function admission(value, applicationId, organizationId, generation) {
1495
1532
  //#endregion
1496
1533
  //#region src/organization-admission/transport.ts
1497
1534
  function actorHeaders(proof) {
1498
- if (!exact$6(proof, [
1535
+ if (!exact$7(proof, [
1499
1536
  "serviceAssertion",
1500
1537
  "request",
1501
1538
  "appOrigin"
@@ -1583,17 +1620,17 @@ function transport(options, operations) {
1583
1620
  //#region src/organization-admission/index.ts
1584
1621
  function validate(operation, input) {
1585
1622
  if (operation === "reserve") {
1586
- if (!exact$6(input, [
1623
+ if (!exact$7(input, [
1587
1624
  "applicationId",
1588
1625
  "idempotencyKey",
1589
1626
  "target"
1590
1627
  ]) || !directoryId(input.applicationId) || typeof input.idempotencyKey !== "string" || !/^[A-Za-z0-9_-]{16,128}$(?![\s\S])/.test(input.idempotencyKey) || !record$1(input.target)) throw invalid$1();
1591
1628
  const target = input.target;
1592
- if (target.kind === "new" ? !exact$6(target, [
1629
+ if (target.kind === "new" ? !exact$7(target, [
1593
1630
  "kind",
1594
1631
  "name",
1595
1632
  "slug"
1596
- ]) || !text(target.name) || !slug(target.slug) : target.kind !== "existing" || !exact$6(target, [
1633
+ ]) || !text(target.name) || !slug(target.slug) : target.kind !== "existing" || !exact$7(target, [
1597
1634
  "kind",
1598
1635
  "organizationId",
1599
1636
  "organizationGeneration"
@@ -1605,7 +1642,7 @@ function validate(operation, input) {
1605
1642
  limit: input.limit ?? 25
1606
1643
  };
1607
1644
  } else if (operation === "identity") {
1608
- if (!exact$6(input, ["applicationId", "organizationId"]) || !directoryId(input.applicationId) || !directoryId(input.organizationId)) throw invalid$1();
1645
+ if (!exact$7(input, ["applicationId", "organizationId"]) || !directoryId(input.applicationId) || !directoryId(input.organizationId)) throw invalid$1();
1609
1646
  } else if (operation === "current") {
1610
1647
  if (!record$1(input) || Object.keys(input).some((key) => ![
1611
1648
  "applicationId",
@@ -1636,13 +1673,13 @@ function validate(operation, input) {
1636
1673
  "receipt"
1637
1674
  ]);
1638
1675
  const { creator, selection, receipt } = input;
1639
- if (!directoryId(input.organizationId) || !directoryGeneration(input.organizationGeneration) || !exact$6(creator, ["userId", "userGeneration"]) || !directoryGeneration(creator.userId) || !directoryGeneration(creator.userGeneration) || !exact$6(selection, [
1676
+ if (!directoryId(input.organizationId) || !directoryGeneration(input.organizationGeneration) || !exact$7(creator, ["userId", "userGeneration"]) || !directoryGeneration(creator.userId) || !directoryGeneration(creator.userGeneration) || !exact$7(selection, [
1640
1677
  "revision",
1641
1678
  "digest",
1642
1679
  "planId",
1643
1680
  "priceId",
1644
1681
  "seats"
1645
- ]) || !positive(selection.revision) || !digest$2(selection.digest) || !directoryId(selection.planId) || !directoryId(selection.priceId) || !positive(selection.seats) || selection.seats > 1e4 || !exact$6(receipt, [
1682
+ ]) || !positive(selection.revision) || !digest$2(selection.digest) || !directoryId(selection.planId) || !directoryId(selection.priceId) || !positive(selection.seats) || selection.seats > 1e4 || !exact$7(receipt, [
1646
1683
  "id",
1647
1684
  "revision",
1648
1685
  "source",
@@ -1681,9 +1718,9 @@ function createOrganizationAdmissionAuth(options) {
1681
1718
  audience,
1682
1719
  async getOrganizationIdentity(input, assertion) {
1683
1720
  const value = await exchange("identity", validate("identity", input), assertion);
1684
- if (!exact$6(value, ["organization"])) throw authorityUnavailable();
1721
+ if (!exact$7(value, ["organization"])) throw authorityUnavailable();
1685
1722
  if (value.organization === null) return null;
1686
- if (!exact$6(value.organization, ["organizationId", "organizationGeneration"]) || value.organization.organizationId !== input.organizationId || !directoryGeneration(value.organization.organizationGeneration)) throw authorityUnavailable();
1723
+ if (!exact$7(value.organization, ["organizationId", "organizationGeneration"]) || value.organization.organizationId !== input.organizationId || !directoryGeneration(value.organization.organizationGeneration)) throw authorityUnavailable();
1687
1724
  return {
1688
1725
  organizationId: input.organizationId,
1689
1726
  organizationGeneration: value.organization.organizationGeneration
@@ -1691,7 +1728,7 @@ function createOrganizationAdmissionAuth(options) {
1691
1728
  },
1692
1729
  async amendSetup(input, proof) {
1693
1730
  const value = await exchange("amend", validate("amend", input), proof.serviceAssertion, proof);
1694
- if (!exact$6(value, ["setup"])) throw authorityUnavailable();
1731
+ if (!exact$7(value, ["setup"])) throw authorityUnavailable();
1695
1732
  const result = setup(value.setup, input.applicationId, input.setupId);
1696
1733
  if (result.kind !== "new" || result.name !== input.name || result.slug !== input.slug || result.displayRevision !== input.expectedDisplayRevision + 1) throw authorityUnavailable();
1697
1734
  return result;
@@ -1699,14 +1736,14 @@ function createOrganizationAdmissionAuth(options) {
1699
1736
  async reserveSetup(input, proof) {
1700
1737
  const body = validate("reserve", input);
1701
1738
  const value = await exchange("reserve", body, proof.serviceAssertion, proof);
1702
- if (!exact$6(value, ["setup"])) throw authorityUnavailable();
1739
+ if (!exact$7(value, ["setup"])) throw authorityUnavailable();
1703
1740
  const result = setup(value.setup, input.applicationId);
1704
1741
  if (result.kind !== input.target.kind || (input.target.kind === "new" ? result.displayRevision === 1 && (result.name !== input.target.name || result.slug !== input.target.slug) : result.organizationId !== input.target.organizationId || result.organizationGeneration !== input.target.organizationGeneration)) throw authorityUnavailable();
1705
1742
  return result;
1706
1743
  },
1707
1744
  async readSetup(input, proof) {
1708
1745
  const value = await exchange("read", validate("read", input), proof.serviceAssertion, proof);
1709
- if (!exact$6(value, ["setup"])) throw authorityUnavailable();
1746
+ if (!exact$7(value, ["setup"])) throw authorityUnavailable();
1710
1747
  return value.setup === null ? null : setup(value.setup, input.applicationId, input.setupId);
1711
1748
  },
1712
1749
  async listSetups(input, proof) {
@@ -1714,12 +1751,12 @@ function createOrganizationAdmissionAuth(options) {
1714
1751
  },
1715
1752
  async getCurrentAdmission(input, assertion) {
1716
1753
  const value = await exchange("current", validate("current", input), assertion);
1717
- if (!exact$6(value, ["admission"])) throw authorityUnavailable();
1754
+ if (!exact$7(value, ["admission"])) throw authorityUnavailable();
1718
1755
  return value.admission === null ? null : admission(value.admission, input.applicationId, input.organizationId, input.organizationGeneration);
1719
1756
  },
1720
1757
  async finalizeSetup(input, proof) {
1721
1758
  const value = await exchange("finalize", validate("finalize", input), proof.serviceAssertion, proof);
1722
- if (!exact$6(value, ["setup", "admission"])) throw authorityUnavailable();
1759
+ if (!exact$7(value, ["setup", "admission"])) throw authorityUnavailable();
1723
1760
  const result = setup(value.setup, input.applicationId, input.setupId);
1724
1761
  const active = admission(value.admission, input.applicationId, result.organizationId, result.organizationGeneration);
1725
1762
  if (result.status !== "activated" || active.state !== "active" || active.basis !== "coverage") throw authorityUnavailable();
@@ -1744,12 +1781,12 @@ function createOrganizationAdmissionBillingAuth(options) {
1744
1781
  audience,
1745
1782
  async lookupSetup(input, assertion) {
1746
1783
  const value = await exchange("lookup", validate("lookup", input), assertion);
1747
- if (!exact$6(value, ["setup"])) throw authorityUnavailable();
1784
+ if (!exact$7(value, ["setup"])) throw authorityUnavailable();
1748
1785
  return value.setup === null ? null : billingSetup(value.setup, input.applicationId, input.setupId);
1749
1786
  },
1750
1787
  async attestCoverage(input, assertion) {
1751
1788
  const value = await exchange("attest", validate("attest", input), assertion);
1752
- if (!exact$6(value, ["setup", "receipt"]) || !exact$6(value.receipt, [
1789
+ if (!exact$7(value, ["setup", "receipt"]) || !exact$7(value.receipt, [
1753
1790
  "id",
1754
1791
  "revision",
1755
1792
  "state"
@@ -1771,7 +1808,7 @@ function createOrganizationAdmissionBillingAuth(options) {
1771
1808
  },
1772
1809
  async withdrawCoverage(input, assertion) {
1773
1810
  const value = await exchange("withdraw", validate("withdraw", input), assertion);
1774
- if (!exact$6(value, ["setup", "outcome"]) || value.outcome !== "withdrawn" && value.outcome !== "already_activated") throw authorityUnavailable();
1811
+ if (!exact$7(value, ["setup", "outcome"]) || value.outcome !== "withdrawn" && value.outcome !== "already_activated") throw authorityUnavailable();
1775
1812
  const result = setup(value.setup, input.applicationId, input.setupId);
1776
1813
  if (value.outcome === "already_activated" !== (result.status === "activated")) throw authorityUnavailable();
1777
1814
  return {
@@ -1795,7 +1832,7 @@ function createOrganizationAdmissionDirectoryAuth(options) {
1795
1832
  const id$2 = /^[A-Za-z0-9_-]{1,128}$(?![\s\S])/;
1796
1833
  const digest$1 = /^[a-f0-9]{64}$(?![\s\S])/;
1797
1834
  const credential = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$(?![\s\S])/;
1798
- function exact$5(value, keys) {
1835
+ function exact$6(value, keys) {
1799
1836
  return value !== null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
1800
1837
  }
1801
1838
  function identifier(value) {
@@ -1805,7 +1842,7 @@ function timestamp(value) {
1805
1842
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && value <= 864e13;
1806
1843
  }
1807
1844
  function operationProof(value) {
1808
- if (!exact$5(value, [
1845
+ if (!exact$6(value, [
1809
1846
  "applicationCredential",
1810
1847
  "serviceAssertion",
1811
1848
  "actorUserId",
@@ -1828,14 +1865,14 @@ function operationProof(value) {
1828
1865
  };
1829
1866
  }
1830
1867
  function snapshotInput(value) {
1831
- if (!exact$5(value, ["applicationId", "participantUserUids"]) || !identifier(value.applicationId) || !Array.isArray(value.participantUserUids) || value.participantUserUids.length < 1 || value.participantUserUids.length > 100 || !value.participantUserUids.every((uid, index, all) => identifier(uid) && (index === 0 || all[index - 1] < uid))) throw new AuthError("invalid_request", 400);
1868
+ if (!exact$6(value, ["applicationId", "participantUserUids"]) || !identifier(value.applicationId) || !Array.isArray(value.participantUserUids) || value.participantUserUids.length < 1 || value.participantUserUids.length > 100 || !value.participantUserUids.every((uid, index, all) => identifier(uid) && (index === 0 || all[index - 1] < uid))) throw new AuthError("invalid_request", 400);
1832
1869
  return {
1833
1870
  applicationId: value.applicationId,
1834
1871
  participantUserUids: [...value.participantUserUids]
1835
1872
  };
1836
1873
  }
1837
1874
  function operationInput(value) {
1838
- if (!exact$5(value, [
1875
+ if (!exact$6(value, [
1839
1876
  "applicationId",
1840
1877
  "snapshotId",
1841
1878
  "operationHash",
@@ -1866,13 +1903,13 @@ function snapshotFields(value) {
1866
1903
  };
1867
1904
  }
1868
1905
  function snapshotOutput(value, participants, proof) {
1869
- if (!exact$5(value, snapshotKeys)) throw authorityUnavailable();
1906
+ if (!exact$6(value, snapshotKeys)) throw authorityUnavailable();
1870
1907
  const result = snapshotFields(value);
1871
1908
  if (!participants.includes(result.actorUserId) || result.actorUserId !== proof.actorUserId || result.actorSessionId !== proof.actorSessionId) throw authorityUnavailable();
1872
1909
  return result;
1873
1910
  }
1874
1911
  function receiptOutput(value, input, proof, phase) {
1875
- if (!exact$5(value, [
1912
+ if (!exact$6(value, [
1876
1913
  ...snapshotKeys,
1877
1914
  "serviceId",
1878
1915
  "applicationId",
@@ -1970,7 +2007,7 @@ function createAccountProductOperationAuth(options) {
1970
2007
  const expected = operationProof(proof);
1971
2008
  const { applicationId, ...body } = validated;
1972
2009
  const value = await exchange("consume", applicationId, body, expected);
1973
- if (!exact$5(value, ["receipt", "replayed"]) || typeof value.replayed !== "boolean") throw authorityUnavailable();
2010
+ if (!exact$6(value, ["receipt", "replayed"]) || typeof value.replayed !== "boolean") throw authorityUnavailable();
1974
2011
  return {
1975
2012
  receipt: receiptOutput(value.receipt, validated, expected, "consume"),
1976
2013
  replayed: value.replayed
@@ -3054,17 +3091,17 @@ function presenceProofActor(token, applicationId) {
3054
3091
  throw new TypeError("Organization presence credential is invalid");
3055
3092
  }
3056
3093
  }
3057
- function exact$4(value, keys) {
3094
+ function exact$5(value, keys) {
3058
3095
  return !!value && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
3059
3096
  }
3060
3097
  function normalizePresence(value, organizationId, input, actor) {
3061
- if (!exact$4(value, [
3098
+ if (!exact$5(value, [
3062
3099
  "organizationId",
3063
3100
  "applicationId",
3064
3101
  "actor",
3065
3102
  "userIds",
3066
3103
  "checkedAt"
3067
- ]) || value.organizationId !== organizationId || value.applicationId !== input.applicationId || !exact$4(value.actor, ["userId", "sessionId"]) || value.actor.userId !== actor.userId || value.actor.sessionId !== actor.sessionId || !Array.isArray(value.userIds) || value.userIds.length !== input.userIds.length || value.userIds.some((userId, index) => userId !== input.userIds[index]) || typeof value.checkedAt !== "string" || !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$(?![\s\S])/.test(value.checkedAt) || Number.isNaN(Date.parse(value.checkedAt)) || new Date(value.checkedAt).toISOString() !== value.checkedAt) throw new AuthError("identity_authority_unavailable", 503);
3104
+ ]) || value.organizationId !== organizationId || value.applicationId !== input.applicationId || !exact$5(value.actor, ["userId", "sessionId"]) || value.actor.userId !== actor.userId || value.actor.sessionId !== actor.sessionId || !Array.isArray(value.userIds) || value.userIds.length !== input.userIds.length || value.userIds.some((userId, index) => userId !== input.userIds[index]) || typeof value.checkedAt !== "string" || !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$(?![\s\S])/.test(value.checkedAt) || Number.isNaN(Date.parse(value.checkedAt)) || new Date(value.checkedAt).toISOString() !== value.checkedAt) throw new AuthError("identity_authority_unavailable", 503);
3068
3105
  return {
3069
3106
  organizationId,
3070
3107
  applicationId: input.applicationId,
@@ -3074,6 +3111,34 @@ function normalizePresence(value, organizationId, input, actor) {
3074
3111
  };
3075
3112
  }
3076
3113
  //#endregion
3114
+ //#region src/enterprise.ts
3115
+ const idPattern$1 = /^[A-Za-z0-9_-]{1,128}$(?![\s\S])/;
3116
+ function exact$4(value, keys) {
3117
+ return isObject$1(value) && Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
3118
+ }
3119
+ function normalizeOrganizationSignInState(value) {
3120
+ if (exact$4(value, ["status", "mode"]) && value.status === "available" && (value.mode === "membership" || value.mode === "provider")) return {
3121
+ status: value.status,
3122
+ mode: value.mode
3123
+ };
3124
+ if (exact$4(value, ["status", "connectionId"]) && value.status === "sign_in_required" && typeof value.connectionId === "string" && idPattern$1.test(value.connectionId)) return {
3125
+ status: value.status,
3126
+ connectionId: value.connectionId
3127
+ };
3128
+ throw authorityUnavailable();
3129
+ }
3130
+ function normalizeOrganizationSignInStates(value, requestedIds) {
3131
+ if (!exact$4(value, ["organizations"]) || !Array.isArray(value.organizations) || value.organizations.length !== requestedIds.length) throw authorityUnavailable();
3132
+ return { organizations: value.organizations.map((entry, index) => {
3133
+ if (!exact$4(entry, ["organizationId", "state"]) || entry.organizationId !== requestedIds[index]) throw authorityUnavailable();
3134
+ const state = exact$4(entry.state, ["status"]) && entry.state.status === "forbidden" ? { status: "forbidden" } : normalizeOrganizationSignInState(entry.state);
3135
+ return {
3136
+ organizationId: entry.organizationId,
3137
+ state
3138
+ };
3139
+ }) };
3140
+ }
3141
+ //#endregion
3077
3142
  //#region src/application-access.ts
3078
3143
  const id = /^[A-Za-z0-9_-]{1,128}$(?![\s\S])/;
3079
3144
  function applicationAccessInput(input) {
@@ -3871,7 +3936,7 @@ function createDriveProvisioningAuth(options) {
3871
3936
  //#endregion
3872
3937
  //#region src/user-directory.ts
3873
3938
  function user$1(value, applicationId) {
3874
- if (!exact$6(value, [
3939
+ if (!exact$7(value, [
3875
3940
  "applicationId",
3876
3941
  "userId",
3877
3942
  "userGeneration",
@@ -3889,7 +3954,7 @@ function user$1(value, applicationId) {
3889
3954
  };
3890
3955
  }
3891
3956
  function exactInput(input) {
3892
- if (!exact$6(input, [
3957
+ if (!exact$7(input, [
3893
3958
  "applicationId",
3894
3959
  "userId",
3895
3960
  "userGeneration"
@@ -3960,7 +4025,7 @@ function createUserDirectoryAuth(options) {
3960
4025
  async listUsers(input, assertion) {
3961
4026
  pageInput(input);
3962
4027
  const value = await exchange("list", input, assertion);
3963
- if (!exact$6(value, ["users", "nextCursor"]) || !Array.isArray(value.users) || value.users.length > (input.limit ?? 50)) throw authorityUnavailable();
4028
+ if (!exact$7(value, ["users", "nextCursor"]) || !Array.isArray(value.users) || value.users.length > (input.limit ?? 50)) throw authorityUnavailable();
3964
4029
  const users = value.users.map((item) => user$1(item, input.applicationId));
3965
4030
  if (users.some((item) => item.lifecycle === "deleted") || new Set(users.map((item) => item.userId)).size !== users.length) throw authorityUnavailable();
3966
4031
  return {
@@ -3971,13 +4036,13 @@ function createUserDirectoryAuth(options) {
3971
4036
  async lookupUser(input, assertion) {
3972
4037
  exactInput(input);
3973
4038
  const value = await exchange("lookup", input, assertion);
3974
- if (!exact$6(value, ["user"])) throw authorityUnavailable();
4039
+ if (!exact$7(value, ["user"])) throw authorityUnavailable();
3975
4040
  return value.user === null ? null : selectedUser(value.user, input);
3976
4041
  },
3977
4042
  async listOrganizationMembers(input, assertion) {
3978
4043
  pageInput(input, true);
3979
4044
  const value = await exchange("members", input, assertion);
3980
- if (!exact$6(value, [
4045
+ if (!exact$7(value, [
3981
4046
  "applicationId",
3982
4047
  "organizationId",
3983
4048
  "organizationGeneration",
@@ -3985,7 +4050,7 @@ function createUserDirectoryAuth(options) {
3985
4050
  "nextCursor"
3986
4051
  ]) || value.applicationId !== input.applicationId || value.organizationId !== input.organizationId || value.organizationGeneration !== input.organizationGeneration || !Array.isArray(value.members) || value.members.length > (input.limit ?? 50)) throw authorityUnavailable();
3987
4052
  const members = value.members.map((item) => {
3988
- if (!exact$6(item, [
4053
+ if (!exact$7(item, [
3989
4054
  "user",
3990
4055
  "role",
3991
4056
  "membershipStatus"
@@ -4008,9 +4073,9 @@ function createUserDirectoryAuth(options) {
4008
4073
  };
4009
4074
  },
4010
4075
  async resolveUser(input, assertion) {
4011
- if (!exact$6(input, ["applicationId", "authUserId"]) || !directoryId(input.applicationId) || !directoryId(input.authUserId)) throw new AuthError("invalid_request", 400);
4076
+ if (!exact$7(input, ["applicationId", "authUserId"]) || !directoryId(input.applicationId) || !directoryId(input.authUserId)) throw new AuthError("invalid_request", 400);
4012
4077
  const value = await exchange("resolve", input, assertion);
4013
- if (!exact$6(value, ["user"])) throw authorityUnavailable();
4078
+ if (!exact$7(value, ["user"])) throw authorityUnavailable();
4014
4079
  const result = value.user === null ? null : user$1(value.user, input.applicationId);
4015
4080
  if (result?.lifecycle === "deleted") throw authorityUnavailable();
4016
4081
  return result;
@@ -4018,9 +4083,9 @@ function createUserDirectoryAuth(options) {
4018
4083
  async resolveUserBinding(input, assertion) {
4019
4084
  exactInput(input);
4020
4085
  const value = await exchange("binding", input, assertion);
4021
- if (!exact$6(value, ["binding"])) throw authorityUnavailable();
4086
+ if (!exact$7(value, ["binding"])) throw authorityUnavailable();
4022
4087
  if (value.binding === null) return null;
4023
- if (!exact$6(value.binding, ["user", "authUserId"]) || !directoryId(value.binding.authUserId)) throw authorityUnavailable();
4088
+ if (!exact$7(value.binding, ["user", "authUserId"]) || !directoryId(value.binding.authUserId)) throw authorityUnavailable();
4024
4089
  const result = selectedUser(value.binding.user, input);
4025
4090
  if (result.lifecycle === "deleted") throw authorityUnavailable();
4026
4091
  return {
@@ -4055,21 +4120,28 @@ function checkpoint(value) {
4055
4120
  return typeof value === "string" && checkpointPattern.test(value) && Number.isSafeInteger(Number(value));
4056
4121
  }
4057
4122
  function user(value) {
4058
- if (!exact$6(value, ["userId", "userGeneration"]) || !directoryGeneration(value.userId) || !directoryGeneration(value.userGeneration)) throw authorityUnavailable();
4123
+ if (!exact$7(value, ["userId", "userGeneration"]) || !directoryGeneration(value.userId) || !directoryGeneration(value.userGeneration)) throw authorityUnavailable();
4059
4124
  return {
4060
4125
  userId: value.userId,
4061
4126
  userGeneration: value.userGeneration
4062
4127
  };
4063
4128
  }
4064
4129
  function roleSet(value) {
4065
- if (!exact$6(value, ["manualRole", "effectiveRole"]) || !roles.has(value.manualRole) || !roles.has(value.effectiveRole)) throw authorityUnavailable();
4130
+ if (!exact$7(value, ["manualRole", "effectiveRole"]) || !roles.has(value.manualRole) || !roles.has(value.effectiveRole)) throw authorityUnavailable();
4066
4131
  return {
4067
4132
  manualRole: value.manualRole,
4068
4133
  effectiveRole: value.effectiveRole
4069
4134
  };
4070
4135
  }
4071
- function event(value) {
4072
- if (!exact$6(value, [
4136
+ function priorRoleSet(value) {
4137
+ if (!exact$7(value, ["manualRole", "effectiveRole"]) || value.manualRole !== null && !roles.has(value.manualRole) || !roles.has(value.effectiveRole) || value.manualRole === null && value.effectiveRole === "owner") throw authorityUnavailable();
4138
+ return {
4139
+ manualRole: value.manualRole,
4140
+ effectiveRole: value.effectiveRole
4141
+ };
4142
+ }
4143
+ function event(value, version) {
4144
+ if (!exact$7(value, [
4073
4145
  "eventId",
4074
4146
  "sequence",
4075
4147
  "occurredAt",
@@ -4080,12 +4152,15 @@ function event(value) {
4080
4152
  "actor",
4081
4153
  "before",
4082
4154
  "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, [
4155
+ ]) || 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$7(value.organization, [
4084
4156
  "id",
4085
4157
  "generation",
4086
4158
  "name"
4087
4159
  ]) || !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
4160
  const organization = value.organization;
4161
+ const before = version === 2 ? priorRoleSet(value.before) : roleSet(value.before);
4162
+ const after = roleSet(value.after);
4163
+ if (before.manualRole === null && (value.reason === "ownership_transferred_out" || value.reason === "ownership_transferred_in" && (after.manualRole !== "owner" || after.effectiveRole !== "owner"))) throw authorityUnavailable();
4089
4164
  return {
4090
4165
  eventId: value.eventId,
4091
4166
  sequence: value.sequence,
@@ -4099,8 +4174,8 @@ function event(value) {
4099
4174
  correlationId: value.correlationId,
4100
4175
  subject: user(value.subject),
4101
4176
  actor: value.actor === null ? null : user(value.actor),
4102
- before: roleSet(value.before),
4103
- after: roleSet(value.after)
4177
+ before,
4178
+ after
4104
4179
  };
4105
4180
  }
4106
4181
  function listInput(input) {
@@ -4110,8 +4185,8 @@ function listInput(input) {
4110
4185
  "limit"
4111
4186
  ].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
4187
  }
4113
- function mapError(value, status, retryAfter) {
4114
- if (status === 409 && exact$6(value, [
4188
+ function mapError$1(value, status, retryAfter) {
4189
+ if (status === 409 && exact$7(value, [
4115
4190
  "code",
4116
4191
  "message",
4117
4192
  "earliest"
@@ -4119,6 +4194,12 @@ function mapError(value, status, retryAfter) {
4119
4194
  return fromAuthorityError(value, status, retryAfter);
4120
4195
  }
4121
4196
  function createOrganizationRoleEventsAuth(options) {
4197
+ return createRoleEventsClient(options, 1, (value) => event(value, 1));
4198
+ }
4199
+ function createOrganizationRoleEventsV2Auth(options) {
4200
+ return createRoleEventsClient(options, 2, (value) => event(value, 2));
4201
+ }
4202
+ function createRoleEventsClient(options, version, normalizeEvent) {
4122
4203
  const origin = normalizeOrigin(options.authOrigin, "authOrigin");
4123
4204
  const fetchImpl = options.fetch ?? globalThis.fetch?.bind(globalThis);
4124
4205
  if (typeof fetchImpl !== "function") throw new TypeError("fetch is required");
@@ -4151,7 +4232,7 @@ function createOrganizationRoleEventsAuth(options) {
4151
4232
  body,
4152
4233
  maxResponseBytes: 256 * 1024,
4153
4234
  signal: controller.signal,
4154
- mapError
4235
+ mapError: mapError$1
4155
4236
  }).finally(() => {
4156
4237
  inFlight -= 1;
4157
4238
  }), deadline]);
@@ -4165,15 +4246,18 @@ function createOrganizationRoleEventsAuth(options) {
4165
4246
  }
4166
4247
  return { async listRoleEvents(input, assertion) {
4167
4248
  listInput(input);
4168
- const value = await exchange(input, assertion);
4169
- if (!exact$6(value, [
4249
+ const value = await exchange(version === 2 ? {
4250
+ ...input,
4251
+ version: 2
4252
+ } : input, assertion);
4253
+ if (!exact$7(value, [
4170
4254
  "version",
4171
4255
  "applicationId",
4172
4256
  "events",
4173
4257
  "checkpoint",
4174
4258
  "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);
4259
+ ]) || value.version !== version || value.applicationId !== input.applicationId || !Array.isArray(value.events) || value.events.length > (input.limit ?? 50) || !checkpoint(value.checkpoint) || typeof value.hasMore !== "boolean") throw authorityUnavailable();
4260
+ const events = value.events.map(normalizeEvent);
4177
4261
  const floor = Number(input.after ?? "0");
4178
4262
  let previous = floor;
4179
4263
  const seen = new Set();
@@ -4185,7 +4269,7 @@ function createOrganizationRoleEventsAuth(options) {
4185
4269
  }
4186
4270
  if (Number(value.checkpoint) < floor || value.hasMore && Number(value.checkpoint) <= floor) throw authorityUnavailable();
4187
4271
  return {
4188
- version: 1,
4272
+ version,
4189
4273
  applicationId: input.applicationId,
4190
4274
  events,
4191
4275
  checkpoint: value.checkpoint,
@@ -4194,6 +4278,175 @@ function createOrganizationRoleEventsAuth(options) {
4194
4278
  } };
4195
4279
  }
4196
4280
  //#endregion
4281
+ //#region src/organization-lifecycle/index.ts
4282
+ const keyPattern = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$(?![\s\S])/;
4283
+ const timePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$(?![\s\S])/;
4284
+ function closureInput(input) {
4285
+ if (!exact$7(input, [
4286
+ "applicationId",
4287
+ "organizationId",
4288
+ "organizationGeneration",
4289
+ "reason",
4290
+ "idempotencyKey"
4291
+ ]) || !directoryId(input.applicationId) || !directoryId(input.organizationId) || !directoryGeneration(input.organizationGeneration) || input.reason !== "plan_lapsed_retention_expired" || typeof input.idempotencyKey !== "string" || !keyPattern.test(input.idempotencyKey)) throw new AuthError("invalid_request", 400);
4292
+ return {
4293
+ applicationId: input.applicationId,
4294
+ organizationId: input.organizationId,
4295
+ organizationGeneration: input.organizationGeneration,
4296
+ reason: input.reason,
4297
+ idempotencyKey: input.idempotencyKey
4298
+ };
4299
+ }
4300
+ function contactsInput(input) {
4301
+ if (!exact$7(input, [
4302
+ "applicationId",
4303
+ "organizationId",
4304
+ "organizationGeneration"
4305
+ ]) || !directoryId(input.applicationId) || !directoryId(input.organizationId) || !directoryGeneration(input.organizationGeneration)) throw new AuthError("invalid_request", 400);
4306
+ return {
4307
+ applicationId: input.applicationId,
4308
+ organizationId: input.organizationId,
4309
+ organizationGeneration: input.organizationGeneration
4310
+ };
4311
+ }
4312
+ async function organizationServiceClosureBodyDigest(input) {
4313
+ const bytes = new TextEncoder().encode(canonical(closureInput(input)));
4314
+ return Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", bytes)), (byte) => byte.toString(16).padStart(2, "0")).join("");
4315
+ }
4316
+ var Outcome = class extends Error {
4317
+ outcome;
4318
+ constructor(outcome) {
4319
+ super(outcome);
4320
+ this.outcome = outcome;
4321
+ }
4322
+ };
4323
+ function mapError(value, status, retryAfter) {
4324
+ const code = exact$7(value, ["code", "message"]) ? value.code : void 0;
4325
+ if (status === 404 && code === "NOT_FOUND") return new Outcome("not_found");
4326
+ if (status === 412 && code === "PRECONDITION_FAILED") return new Outcome("not_eligible");
4327
+ if (status === 400) return new AuthError("invalid_request", 400);
4328
+ if (status === 403) return new AuthError("access_denied", 403);
4329
+ if (status === 409) return new AuthError("state_conflict", 409);
4330
+ if (status === 429) return new AuthError("auth_request_rate_limited", 429, parseRetryAfter(retryAfter));
4331
+ return authorityUnavailable();
4332
+ }
4333
+ function createOrganizationLifecycleAuth(options) {
4334
+ const origin = normalizeOrigin(options.authOrigin, "authOrigin");
4335
+ const fetchImpl = options.fetch ?? globalThis.fetch?.bind(globalThis);
4336
+ if (typeof fetchImpl !== "function") throw new TypeError("fetch is required");
4337
+ const timeoutMs = normalizeTimeout(options.timeoutMs);
4338
+ let inFlight = 0;
4339
+ async function exchange(operation, body, assertion) {
4340
+ 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);
4341
+ if (inFlight >= 4) throw new AuthError("state_conflict", 409);
4342
+ inFlight += 1;
4343
+ const controller = new AbortController();
4344
+ let timer;
4345
+ const deadline = new Promise((_, reject) => {
4346
+ timer = setTimeout(() => {
4347
+ reject(authorityUnavailable());
4348
+ controller.abort();
4349
+ }, timeoutMs);
4350
+ });
4351
+ try {
4352
+ return await Promise.race([requestJson(joinURL(origin, "api/v1/auth/organization-lifecycle", operation), {
4353
+ fetch: fetchImpl,
4354
+ timeoutMs,
4355
+ method: "POST",
4356
+ credentials: "omit",
4357
+ cache: "no-store",
4358
+ headers: {
4359
+ "x-finueva-service-assertion": assertion,
4360
+ "content-type": "application/json",
4361
+ accept: "application/json"
4362
+ },
4363
+ body,
4364
+ maxResponseBytes: 128 * 1024,
4365
+ signal: controller.signal,
4366
+ mapError
4367
+ }).finally(() => {
4368
+ inFlight -= 1;
4369
+ }), deadline]);
4370
+ } catch (cause) {
4371
+ if (cause instanceof AuthError || cause instanceof Outcome) throw cause;
4372
+ throw authorityUnavailable();
4373
+ } finally {
4374
+ clearTimeout(timer);
4375
+ controller.abort();
4376
+ }
4377
+ }
4378
+ return {
4379
+ async closeOrganization(input, assertion) {
4380
+ const selected = closureInput(input);
4381
+ let value;
4382
+ try {
4383
+ value = await exchange("close", selected, assertion);
4384
+ } catch (cause) {
4385
+ if (cause instanceof Outcome) return { outcome: cause.outcome };
4386
+ throw cause;
4387
+ }
4388
+ if (!exact$7(value, [
4389
+ "organizationId",
4390
+ "organizationGeneration",
4391
+ "closure",
4392
+ "state",
4393
+ "startedAt",
4394
+ "cancelUntil",
4395
+ "canCancel"
4396
+ ]) || value.organizationId !== selected.organizationId || value.organizationGeneration !== selected.organizationGeneration || value.closure !== "started" && value.closure !== "already_closing" || value.state !== "closing" && value.state !== "cancelled" || typeof value.startedAt !== "string" || !timePattern.test(value.startedAt) || typeof value.cancelUntil !== "string" || !timePattern.test(value.cancelUntil) || Date.parse(value.cancelUntil) <= Date.parse(value.startedAt) || typeof value.canCancel !== "boolean") throw authorityUnavailable();
4397
+ return {
4398
+ outcome: value.closure,
4399
+ organizationId: selected.organizationId,
4400
+ organizationGeneration: selected.organizationGeneration,
4401
+ state: value.state,
4402
+ startedAt: value.startedAt,
4403
+ cancelUntil: value.cancelUntil,
4404
+ canCancel: value.canCancel
4405
+ };
4406
+ },
4407
+ async listAdminContacts(input, assertion) {
4408
+ const selected = contactsInput(input);
4409
+ let value;
4410
+ try {
4411
+ value = await exchange("admin-contacts", selected, assertion);
4412
+ } catch (cause) {
4413
+ if (cause instanceof Outcome) {
4414
+ if (cause.outcome === "not_found") return null;
4415
+ throw authorityUnavailable();
4416
+ }
4417
+ throw cause;
4418
+ }
4419
+ if (!exact$7(value, [
4420
+ "applicationId",
4421
+ "organizationId",
4422
+ "organizationGeneration",
4423
+ "contacts",
4424
+ "complete"
4425
+ ]) || value.applicationId !== selected.applicationId || value.organizationId !== selected.organizationId || value.organizationGeneration !== selected.organizationGeneration || !Array.isArray(value.contacts) || value.contacts.length > 100 || typeof value.complete !== "boolean") throw authorityUnavailable();
4426
+ const contacts = value.contacts.map((item) => {
4427
+ if (!exact$7(item, [
4428
+ "userId",
4429
+ "role",
4430
+ "email",
4431
+ "name"
4432
+ ]) || !directoryId(item.userId) || item.role !== "owner" && item.role !== "admin" || typeof item.email !== "string" || item.email.length < 3 || item.email.length > 320 || !item.email.includes("@") || typeof item.name !== "string" || item.name.length > 1024) throw authorityUnavailable();
4433
+ return {
4434
+ userId: item.userId,
4435
+ role: item.role,
4436
+ email: item.email,
4437
+ name: item.name
4438
+ };
4439
+ });
4440
+ if (new Set(contacts.map((contact) => contact.userId)).size !== contacts.length) throw authorityUnavailable();
4441
+ return {
4442
+ ...selected,
4443
+ contacts,
4444
+ complete: value.complete
4445
+ };
4446
+ }
4447
+ };
4448
+ }
4449
+ //#endregion
4197
4450
  //#region src/server.ts
4198
4451
  const MAX_AUTHORIZATION_BYTES = 16 * 1024;
4199
4452
  function createServerAuth(options) {
@@ -4305,6 +4558,14 @@ function createServerAuth(options) {
4305
4558
  getOrganization(organizationId) {
4306
4559
  return organizationRead(normalizeIdInput(organizationId), void 0, normalizeOrganization);
4307
4560
  },
4561
+ getOrganizationSignInState(organizationId) {
4562
+ return organizationRead(`${normalizeIdInput(organizationId)}/sign-in-state`, void 0, normalizeOrganizationSignInState);
4563
+ },
4564
+ getOrganizationSignInStates(organizationIds) {
4565
+ if (!Array.isArray(organizationIds) || !organizationIds.length || organizationIds.length > 50 || new Set(organizationIds).size !== organizationIds.length) throw new AuthError("invalid_request", 400);
4566
+ const ids = organizationIds.map(normalizeIdInput);
4567
+ return organizationRead("sign-in-states", void 0, (value) => normalizeOrganizationSignInStates(value, ids), () => new URLSearchParams({ organizationIds: ids.join(",") }));
4568
+ },
4308
4569
  async authorizeOrganizationPresence(organizationId, input, serviceAssertion, options) {
4309
4570
  if (typeof serviceAssertion !== "string" || serviceAssertion.length > 16 * 1024 || !/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$(?![\s\S])/.test(serviceAssertion)) throw new TypeError("Organization presence service assertion is invalid");
4310
4571
  const organization = normalizeIdInput(organizationId);
@@ -4389,6 +4650,11 @@ function createServerAuth(options) {
4389
4650
  const member = normalizeIdInput(memberId);
4390
4651
  return organizationRead(`${organization}/members/${member}/authority`, void 0, (value) => normalizeOrganizationMemberAuthority(value, organization, member));
4391
4652
  },
4653
+ async getOrganizationMemberAuthorityV2(organizationId, memberId) {
4654
+ const organization = normalizeIdInput(organizationId);
4655
+ const member = normalizeIdInput(memberId);
4656
+ return organizationRead(`${organization}/members/${member}/authority`, void 0, (value) => normalizeOrganizationMemberAuthorityV2(value, organization, member), () => new URLSearchParams({ version: "2" }));
4657
+ },
4392
4658
  async getOrganizationApplicationRegistration(organizationId, applicationId) {
4393
4659
  if (authorization) throw new AuthError("state_conflict", 409);
4394
4660
  const path = registrationTarget(organizationId, applicationId);
@@ -4754,4 +5020,4 @@ function authAuthorizationHeader(value) {
4754
5020
  return value;
4755
5021
  }
4756
5022
  //#endregion
4757
- export { AuthError, OrganizationRoleEventCheckpointExpiredError, createAccountProductOperationAuth, createDriveProvisioningAuth, createDriveRecipientAuth, createIdentityResolverAuth, createMembershipResolverAuth, createOrganizationAdmissionAuth, createOrganizationAdmissionBillingAuth, createOrganizationAdmissionDirectoryAuth, createOrganizationDirectoryAuth, createOrganizationRoleEventsAuth, createServerAuth, createUserApiVerifier, createUserDirectoryAuth, organizationAdmissionBodyDigest };
5023
+ export { AuthError, OrganizationRoleEventCheckpointExpiredError, createAccountProductOperationAuth, createDriveProvisioningAuth, createDriveRecipientAuth, createIdentityResolverAuth, createMembershipResolverAuth, createOrganizationAdmissionAuth, createOrganizationAdmissionBillingAuth, createOrganizationAdmissionDirectoryAuth, createOrganizationDirectoryAuth, createOrganizationLifecycleAuth, createOrganizationRoleEventsAuth, createOrganizationRoleEventsV2Auth, createServerAuth, createUserApiVerifier, createUserDirectoryAuth, organizationAdmissionBodyDigest, organizationServiceClosureBodyDigest };