@opengeni/db 3.4.0-canary.2 → 3.6.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.
Files changed (67) hide show
  1. package/dist/canonical-human-identities.d.ts +20 -0
  2. package/dist/canonical-human-identities.js +7 -3
  3. package/dist/{chunk-ZWRIPCTR.js → chunk-2NT476HD.js} +2 -2
  4. package/dist/{chunk-PYMY3AJW.js → chunk-744DFC65.js} +202 -7
  5. package/dist/chunk-744DFC65.js.map +1 -0
  6. package/dist/{chunk-O6FTELKH.js → chunk-CDMMSUWJ.js} +3 -3
  7. package/dist/chunk-G3732M3T.js +299 -0
  8. package/dist/chunk-G3732M3T.js.map +1 -0
  9. package/dist/{chunk-TRBOWUG3.js → chunk-IW6O6G7R.js} +2 -2
  10. package/dist/{chunk-HY3F5Q4E.js → chunk-Q5YUGQVK.js} +3 -3
  11. package/dist/{chunk-V3TRUXFJ.js → chunk-UGDVSQ6U.js} +72 -19
  12. package/dist/chunk-UGDVSQ6U.js.map +1 -0
  13. package/dist/{chunk-C2AFP7SB.js → chunk-UJ2EW3QI.js} +6664 -6051
  14. package/dist/chunk-UJ2EW3QI.js.map +1 -0
  15. package/dist/{chunk-H7MXYG7R.js → chunk-WW7AJ5IC.js} +2 -2
  16. package/dist/editable-artifact-durable-export.js +2 -2
  17. package/dist/editable-artifacts.js +3 -3
  18. package/dist/index.d.ts +44 -6
  19. package/dist/index.js +2914 -1535
  20. package/dist/index.js.map +1 -1
  21. package/dist/managed-auth-session-set-schema.d.ts +1399 -0
  22. package/dist/managed-auth-session-sets.d.ts +145 -0
  23. package/dist/managed-auth-session-sets.js +50 -0
  24. package/dist/managed-auth-session-sets.js.map +1 -0
  25. package/dist/organization-recovery-schema.d.ts +2144 -0
  26. package/dist/organization-recovery.d.ts +186 -0
  27. package/dist/provision-roles.js +1 -1
  28. package/dist/runtime-posture.d.ts +7 -4
  29. package/dist/schema.d.ts +9 -6
  30. package/dist/schema.js +43 -1
  31. package/dist/session-background-commands.js +3 -3
  32. package/dist/session-control.d.ts +5 -3
  33. package/dist/session-queue-commands.d.ts +2 -0
  34. package/dist/session-tenancy.js +3 -3
  35. package/dist/video-generation.js +3 -3
  36. package/dist/work-claims-schema.d.ts +975 -0
  37. package/dist/work-claims.d.ts +83 -0
  38. package/drizzle/0362_managed_auth_session_sets.sql +2347 -0
  39. package/drizzle/0363_organization_recovery_custody.sql +2418 -0
  40. package/drizzle/0364_workspace_learning_policy_snapshot_lock_order.sql +221 -0
  41. package/drizzle/0365_permission_scoped_work_claims.sql +1306 -0
  42. package/drizzle/0366_session_discovery_title_search_index.sql +5 -0
  43. package/drizzle/0367_session_discovery_goal_search_index.sql +5 -0
  44. package/drizzle/0368_session_discovery_claim_search_index.sql +6 -0
  45. package/package.json +10 -6
  46. package/src/canonical-human-identities.ts +105 -27
  47. package/src/index.ts +1471 -433
  48. package/src/managed-auth-session-set-schema.ts +176 -0
  49. package/src/managed-auth-session-sets.ts +430 -0
  50. package/src/organization-recovery-schema.ts +277 -0
  51. package/src/organization-recovery.ts +424 -0
  52. package/src/provision-roles.ts +67 -0
  53. package/src/runtime-posture.ts +144 -6
  54. package/src/schema.ts +3 -0
  55. package/src/session-control.ts +255 -16
  56. package/src/session-queue-commands.ts +10 -1
  57. package/src/session-tool-call-settlement.ts +6 -1
  58. package/src/work-claims-schema.ts +148 -0
  59. package/src/work-claims.ts +200 -0
  60. package/dist/chunk-C2AFP7SB.js.map +0 -1
  61. package/dist/chunk-PYMY3AJW.js.map +0 -1
  62. package/dist/chunk-V3TRUXFJ.js.map +0 -1
  63. /package/dist/{chunk-ZWRIPCTR.js.map → chunk-2NT476HD.js.map} +0 -0
  64. /package/dist/{chunk-O6FTELKH.js.map → chunk-CDMMSUWJ.js.map} +0 -0
  65. /package/dist/{chunk-TRBOWUG3.js.map → chunk-IW6O6G7R.js.map} +0 -0
  66. /package/dist/{chunk-HY3F5Q4E.js.map → chunk-Q5YUGQVK.js.map} +0 -0
  67. /package/dist/{chunk-H7MXYG7R.js.map → chunk-WW7AJ5IC.js.map} +0 -0
@@ -6,6 +6,16 @@ export type CanonicalHumanSessionAuthority = {
6
6
  authRevision: number;
7
7
  identityStatus: "active" | "recovery_required" | "disputed" | "disabled";
8
8
  };
9
+ export type CanonicalHumanExactLoginBinding = {
10
+ id: string;
11
+ identityId: string;
12
+ revision: number;
13
+ status: "active" | "recovery_pending" | "stale" | "disputed" | "revoked";
14
+ };
15
+ export declare function getCanonicalHumanExactLoginBindingForAuthUser(db: Database, input: {
16
+ authUserId: string;
17
+ providerId: string;
18
+ }): Promise<CanonicalHumanExactLoginBinding>;
9
19
  export declare class CanonicalHumanIdentityConflictError extends Error {
10
20
  readonly name = "CanonicalHumanIdentityConflictError";
11
21
  readonly code = "CANONICAL_HUMAN_IDENTITY_CONFLICT";
@@ -16,6 +26,11 @@ export declare class CanonicalHumanIdentityOperationReuseError extends Error {
16
26
  readonly code = "CANONICAL_HUMAN_IDENTITY_OPERATION_REUSED";
17
27
  constructor();
18
28
  }
29
+ export declare class CanonicalHumanIdentityMutationInFlightError extends Error {
30
+ readonly name = "CanonicalHumanIdentityMutationInFlightError";
31
+ readonly code = "CANONICAL_HUMAN_IDENTITY_MUTATION_IN_FLIGHT";
32
+ constructor();
33
+ }
19
34
  export declare class CanonicalHumanIdentityNotFoundError extends Error {
20
35
  readonly name = "CanonicalHumanIdentityNotFoundError";
21
36
  constructor(message?: string);
@@ -44,5 +59,10 @@ export type ApplyCanonicalHumanIdentityOperationInput = {
44
59
  providerId?: string | null;
45
60
  providerAccountId?: string | null;
46
61
  reason: string;
62
+ actorFence?: {
63
+ authorityHash: string;
64
+ actorEpoch: string;
65
+ requestId: string;
66
+ };
47
67
  };
48
68
  export declare function applyCanonicalHumanIdentityOperation(db: Database, input: ApplyCanonicalHumanIdentityOperationInput): Promise<CanonicalHumanIdentityMutationResponseType>;
@@ -1,26 +1,30 @@
1
1
  import {
2
2
  CanonicalHumanIdentityAuthorityError,
3
3
  CanonicalHumanIdentityConflictError,
4
+ CanonicalHumanIdentityMutationInFlightError,
4
5
  CanonicalHumanIdentityNotFoundError,
5
6
  CanonicalHumanIdentityOperationReuseError,
6
7
  applyCanonicalHumanIdentityOperation,
7
8
  ensureCanonicalHumanIdentity,
8
9
  ensureCanonicalHumanIdentityForAuthUser,
10
+ getCanonicalHumanExactLoginBindingForAuthUser,
9
11
  getCanonicalHumanIdentityProjection,
10
12
  synchronizeCanonicalHumanLoginBindings,
11
13
  validateCanonicalHumanSession
12
- } from "./chunk-V3TRUXFJ.js";
13
- import "./chunk-H7MXYG7R.js";
14
- import "./chunk-C2AFP7SB.js";
14
+ } from "./chunk-UGDVSQ6U.js";
15
+ import "./chunk-WW7AJ5IC.js";
16
+ import "./chunk-UJ2EW3QI.js";
15
17
  import "./chunk-PZ5AY32C.js";
16
18
  export {
17
19
  CanonicalHumanIdentityAuthorityError,
18
20
  CanonicalHumanIdentityConflictError,
21
+ CanonicalHumanIdentityMutationInFlightError,
19
22
  CanonicalHumanIdentityNotFoundError,
20
23
  CanonicalHumanIdentityOperationReuseError,
21
24
  applyCanonicalHumanIdentityOperation,
22
25
  ensureCanonicalHumanIdentity,
23
26
  ensureCanonicalHumanIdentityForAuthUser,
27
+ getCanonicalHumanExactLoginBindingForAuthUser,
24
28
  getCanonicalHumanIdentityProjection,
25
29
  synchronizeCanonicalHumanLoginBindings,
26
30
  validateCanonicalHumanSession
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  rawRows,
3
3
  withRlsContext
4
- } from "./chunk-H7MXYG7R.js";
4
+ } from "./chunk-WW7AJ5IC.js";
5
5
 
6
6
  // src/editable-artifacts.ts
7
7
  import { createHash } from "crypto";
@@ -3540,4 +3540,4 @@ export {
3540
3540
  PostgresEditableArtifactStore,
3541
3541
  PostgresEditableArtifactLiveReadStore
3542
3542
  };
3543
- //# sourceMappingURL=chunk-ZWRIPCTR.js.map
3543
+ //# sourceMappingURL=chunk-2NT476HD.js.map
@@ -381,6 +381,49 @@ var CANONICAL_HUMAN_IDENTITY_AUTHORITY_TABLES = [
381
381
  "canonical_human_login_bindings",
382
382
  "canonical_human_identity_operations"
383
383
  ];
384
+ var MANAGED_AUTH_SESSION_SET_ROUTINES = [
385
+ "get_canonical_human_exact_login_binding(text, text)",
386
+ "managed_auth_session_set_authority_state(text)",
387
+ "managed_auth_session_set_snapshot(text, text, boolean, boolean, boolean)",
388
+ "managed_auth_session_set_bootstrap(text, text, text, text, uuid, text, bigint, bigint)",
389
+ "managed_auth_session_set_begin_transaction(text, text, text, uuid, text, bigint, uuid, bigint, text, text, uuid, uuid, text, timestamp with time zone)",
390
+ "managed_auth_session_set_complete_transaction(text, text, uuid, text, bigint, bigint, uuid, text, text, text)",
391
+ "managed_auth_session_set_mutate(text, text, uuid, text, bigint, bigint, text, uuid, uuid, uuid, text, text)",
392
+ "managed_auth_actor_mutation_fence(text, bigint, uuid)",
393
+ "managed_auth_actor_mutation_lease_acquire(text, bigint, uuid, integer)",
394
+ "managed_auth_actor_mutation_lease_release(text, uuid)",
395
+ "managed_auth_actor_mutation_lease_validate(text, bigint, uuid)",
396
+ "managed_auth_adopted_session_snapshot(text)",
397
+ "managed_auth_isolated_session_reap(integer)",
398
+ "managed_auth_expired_session_set_reap(integer)",
399
+ "managed_auth_session_set_operation_receipt(text, uuid, text, text)"
400
+ ];
401
+ var MANAGED_AUTH_SESSION_SET_AUTHORITY_TABLES = [
402
+ "managed_auth_actor_mutation_leases",
403
+ "managed_auth_browser_installations",
404
+ "managed_auth_session_sets",
405
+ "managed_auth_login_slots",
406
+ "managed_auth_login_return_intents",
407
+ "managed_auth_login_transaction_rate_limits",
408
+ "managed_auth_login_transactions",
409
+ "managed_auth_session_set_operations"
410
+ ];
411
+ var ORGANIZATION_RECOVERY_ROUTINES = [
412
+ "get_organization_recovery_overview(uuid, text, jsonb, text, text)",
413
+ "organization_recovery_command(jsonb)"
414
+ ];
415
+ var ORGANIZATION_RECOVERY_AUTHORITY_TABLES = [
416
+ "organization_recovery_approvals",
417
+ "organization_recovery_command_receipts",
418
+ "organization_recovery_custodian_acceptances",
419
+ "organization_recovery_custodians",
420
+ "organization_recovery_events",
421
+ "organization_recovery_notification_attempts",
422
+ "organization_recovery_notification_outbox",
423
+ "organization_recovery_operations",
424
+ "organization_recovery_policies",
425
+ "organization_recovery_policy_heads"
426
+ ];
384
427
  var SESSION_PRIVATE_ACTOR_VISIBLE_ROUTINE = "session_private_actor_visible(uuid, uuid, uuid, text)";
385
428
  var SESSION_REFERENCE_VISIBLE_ROUTINE = "session_reference_visible(uuid, uuid, uuid)";
386
429
  var TASK_NOTE_CAPABILITY_ROUTINES = [
@@ -390,6 +433,10 @@ var TASK_NOTE_CAPABILITY_ROUTINES = [
390
433
  "replace_task_note_for_attempt(uuid, uuid, uuid, uuid, uuid, integer, uuid, uuid, uuid, uuid, integer, text, text, integer, text)",
391
434
  "resolve_task_note_knowledge_promotion_source(uuid, uuid, uuid, uuid, uuid, integer, uuid, integer, text, text, text)"
392
435
  ];
436
+ var WORK_CLAIM_CAPABILITY_ROUTINES = [
437
+ "upsert_session_work_claim_for_attempt(uuid, uuid, uuid, uuid, uuid, integer, uuid, integer, text, text, text, text, text, text, text)",
438
+ "release_session_work_claim_for_attempt(uuid, uuid, uuid, uuid, uuid, integer, uuid, uuid, integer, text)"
439
+ ];
393
440
  var COMPANY_BRAIN_CONTEXT_SELECTION_ROUTINE = "company_brain_context_get_or_create_selection(uuid, uuid, uuid, uuid, uuid, integer)";
394
441
  var COMPANY_BRAIN_CONTEXT_INSPECTION_ROUTINE = "company_brain_inspect_context_receipts(uuid, uuid, text, uuid, timestamp with time zone, uuid, integer)";
395
442
  var GOVERNED_LEARNING_EVALUATION_ROUTINE = "evaluate_governed_learning_proposal(uuid, uuid, uuid, uuid, uuid, integer, uuid, uuid, uuid, uuid, uuid)";
@@ -502,6 +549,7 @@ var SESSION_AUTHORITY_ROUTINES = /* @__PURE__ */ new Set([
502
549
  ...PRIVATE_SESSION_CREATE_CAPABILITY_ROUTINES,
503
550
  TRANSITION_SESSION_VISIBILITY_ROUTINE,
504
551
  ...TASK_NOTE_CAPABILITY_ROUTINES,
552
+ ...WORK_CLAIM_CAPABILITY_ROUTINES,
505
553
  COMPANY_BRAIN_CONTEXT_SELECTION_ROUTINE,
506
554
  COMPANY_BRAIN_CONTEXT_INSPECTION_ROUTINE
507
555
  ]);
@@ -551,7 +599,10 @@ var RUNTIME_TARGET_SCHEMA_CAPABILITY_ROUTINES = [
551
599
  ...SCOPED_COMPUTE_AUTHORITY_ROUTINES,
552
600
  ...SCHEDULED_PERSONAL_RESOURCE_ROUTINES,
553
601
  ...CANONICAL_HUMAN_IDENTITY_ROUTINES,
602
+ ...MANAGED_AUTH_SESSION_SET_ROUTINES,
603
+ ...ORGANIZATION_RECOVERY_ROUTINES,
554
604
  ...TASK_NOTE_CAPABILITY_ROUTINES,
605
+ ...WORK_CLAIM_CAPABILITY_ROUTINES,
555
606
  SESSION_PRIVATE_ACTOR_VISIBLE_ROUTINE,
556
607
  SESSION_REFERENCE_VISIBLE_ROUTINE,
557
608
  SESSION_VISIBILITY_LIFECYCLE_CAPABILITY_ROUTINE,
@@ -726,6 +777,14 @@ var FORCE_RLS_TABLES = [
726
777
  "machine_metrics_latest",
727
778
  "machine_metrics_series",
728
779
  "machine_removal_operations",
780
+ "managed_auth_actor_mutation_leases",
781
+ "managed_auth_browser_installations",
782
+ "managed_auth_login_return_intents",
783
+ "managed_auth_login_slots",
784
+ "managed_auth_login_transaction_rate_limits",
785
+ "managed_auth_login_transactions",
786
+ "managed_auth_session_set_operations",
787
+ "managed_auth_session_sets",
729
788
  "memory_slack_publication_configurations",
730
789
  "memory_slack_publication_receipts",
731
790
  "memory_slack_publications",
@@ -740,6 +799,16 @@ var FORCE_RLS_TABLES = [
740
799
  "organization_private_session_setting_events",
741
800
  "organization_private_session_settings",
742
801
  "organization_profile_events",
802
+ "organization_recovery_approvals",
803
+ "organization_recovery_command_receipts",
804
+ "organization_recovery_custodian_acceptances",
805
+ "organization_recovery_custodians",
806
+ "organization_recovery_events",
807
+ "organization_recovery_notification_attempts",
808
+ "organization_recovery_notification_outbox",
809
+ "organization_recovery_operations",
810
+ "organization_recovery_policies",
811
+ "organization_recovery_policy_heads",
743
812
  "organization_shared_workspace_administration_capabilities",
744
813
  "organization_user_resource_authorities",
745
814
  "organization_user_resource_grants",
@@ -829,6 +898,9 @@ var FORCE_RLS_TABLES = [
829
898
  "session_turns",
830
899
  "session_variable_set_attachments",
831
900
  "session_visibility_write_capabilities",
901
+ "session_work_claim_revisions",
902
+ "session_work_claim_write_capabilities",
903
+ "session_work_claims",
832
904
  "session_workflow_wake_outbox",
833
905
  "sessions",
834
906
  "site_auth_connections",
@@ -1083,6 +1155,7 @@ var RUNTIME_READ_ONLY_TABLES = [
1083
1155
  "preference_registry_events",
1084
1156
  "preference_registry_snapshots",
1085
1157
  "session_tenancy_activations",
1158
+ "session_work_claims",
1086
1159
  "slack_installation_bindings",
1087
1160
  "slack_task_policy_activation_events",
1088
1161
  "slack_task_policy_heads",
@@ -1201,6 +1274,14 @@ var PROTECTED_NO_DIRECT_DML_TABLES = [
1201
1274
  "host_export_cursor_state",
1202
1275
  "host_export_dead_letters",
1203
1276
  "host_export_outbox",
1277
+ "managed_auth_actor_mutation_leases",
1278
+ "managed_auth_browser_installations",
1279
+ "managed_auth_login_return_intents",
1280
+ "managed_auth_login_slots",
1281
+ "managed_auth_login_transaction_rate_limits",
1282
+ "managed_auth_login_transactions",
1283
+ "managed_auth_session_set_operations",
1284
+ "managed_auth_session_sets",
1204
1285
  "organization_invitation_binding_events",
1205
1286
  "organization_membership_invitations",
1206
1287
  "organization_membership_lifecycle_events",
@@ -1209,6 +1290,16 @@ var PROTECTED_NO_DIRECT_DML_TABLES = [
1209
1290
  "organization_private_session_setting_events",
1210
1291
  "organization_private_session_settings",
1211
1292
  "organization_profile_events",
1293
+ "organization_recovery_approvals",
1294
+ "organization_recovery_command_receipts",
1295
+ "organization_recovery_custodian_acceptances",
1296
+ "organization_recovery_custodians",
1297
+ "organization_recovery_events",
1298
+ "organization_recovery_notification_attempts",
1299
+ "organization_recovery_notification_outbox",
1300
+ "organization_recovery_operations",
1301
+ "organization_recovery_policies",
1302
+ "organization_recovery_policy_heads",
1212
1303
  "organization_shared_workspace_administration_capabilities",
1213
1304
  "organization_user_resource_authorities",
1214
1305
  "organization_user_resource_grants",
@@ -1248,6 +1339,8 @@ var PROTECTED_NO_DIRECT_DML_TABLES = [
1248
1339
  "session_tenancy_greenfield_activation_evidence",
1249
1340
  "session_variable_set_attachments",
1250
1341
  "session_visibility_write_capabilities",
1342
+ "session_work_claim_revisions",
1343
+ "session_work_claim_write_capabilities",
1251
1344
  "task_note_events",
1252
1345
  "task_note_knowledge_promotion_capabilities",
1253
1346
  "task_note_replacement_receipts",
@@ -1308,6 +1401,8 @@ function difference(left, right) {
1308
1401
  }
1309
1402
  async function inspectRuntimeDatabasePosture(db, options) {
1310
1403
  const targetSchema = options.targetSchema?.trim() || "public";
1404
+ const targetSchemaCapabilityRoutines = options.targetSchemaCapabilityRoutines ?? RUNTIME_TARGET_SCHEMA_CAPABILITY_ROUTINES;
1405
+ const targetSchemaForbiddenRoutines = options.targetSchemaForbiddenRoutines ?? RUNTIME_TARGET_SCHEMA_FORBIDDEN_ROUTINES;
1311
1406
  return await db.transaction(
1312
1407
  async (tx) => {
1313
1408
  const identityRows = resultRows(
@@ -1525,10 +1620,9 @@ async function inspectRuntimeDatabasePosture(db, options) {
1525
1620
  and (p.proname || '(' || pg_catalog.oidvectortypes(p.proargtypes) || ')') = any(
1526
1621
  array[
1527
1622
  ${sql.join(
1528
- [
1529
- ...RUNTIME_TARGET_SCHEMA_CAPABILITY_ROUTINES,
1530
- ...RUNTIME_TARGET_SCHEMA_FORBIDDEN_ROUTINES
1531
- ].map((name) => sql`${name}`),
1623
+ [...targetSchemaCapabilityRoutines, ...targetSchemaForbiddenRoutines].map(
1624
+ (name) => sql`${name}`
1625
+ ),
1532
1626
  sql`, `
1533
1627
  )}
1534
1628
  ]::text[]
@@ -1617,6 +1711,8 @@ function evaluateRuntimeDatabasePosture(posture, options) {
1617
1711
  const protectedNoDirectDmlTables = new Set(
1618
1712
  options.protectedNoDirectDmlTables ?? (options.protectedTables ? [] : PROTECTED_NO_DIRECT_DML_TABLES)
1619
1713
  );
1714
+ const targetSchemaCapabilityRoutines = options.targetSchemaCapabilityRoutines ?? RUNTIME_TARGET_SCHEMA_CAPABILITY_ROUTINES;
1715
+ const targetSchemaForbiddenRoutines = options.targetSchemaForbiddenRoutines ?? RUNTIME_TARGET_SCHEMA_FORBIDDEN_ROUTINES;
1620
1716
  if (identity.currentUser !== expectedRole || identity.sessionUser !== expectedRole) {
1621
1717
  violations.push(
1622
1718
  `runtime identity must be ${expectedRole} (current_user=${identity.currentUser}, session_user=${identity.sessionUser})`
@@ -1737,7 +1833,7 @@ function evaluateRuntimeDatabasePosture(posture, options) {
1737
1833
  if (table.policyCount < 1) violations.push(`table ${tableName} has no RLS policy`);
1738
1834
  }
1739
1835
  const targetSchemaOwner = posture.schemas.find((schema) => schema.name === targetSchema)?.owner;
1740
- for (const forbiddenRoutine of RUNTIME_TARGET_SCHEMA_FORBIDDEN_ROUTINES) {
1836
+ for (const forbiddenRoutine of targetSchemaForbiddenRoutines) {
1741
1837
  const matches = posture.targetRoutines.filter((routine2) => routine2.name === forbiddenRoutine);
1742
1838
  if (matches.length !== 1) {
1743
1839
  violations.push(
@@ -1764,7 +1860,7 @@ function evaluateRuntimeDatabasePosture(posture, options) {
1764
1860
  violations.push(`PUBLIC has forbidden owner-internal helper ${routine.name}`);
1765
1861
  }
1766
1862
  }
1767
- for (const expectedRoutine of RUNTIME_TARGET_SCHEMA_CAPABILITY_ROUTINES) {
1863
+ for (const expectedRoutine of targetSchemaCapabilityRoutines) {
1768
1864
  const matches = posture.targetRoutines.filter((routine2) => routine2.name === expectedRoutine);
1769
1865
  if (matches.length !== 1) {
1770
1866
  violations.push(
@@ -2017,6 +2113,42 @@ function evaluateRuntimeDatabasePosture(posture, options) {
2017
2113
  );
2018
2114
  }
2019
2115
  }
2116
+ } else if (ORGANIZATION_RECOVERY_ROUTINES.includes(routine.name)) {
2117
+ const authorityTables = ORGANIZATION_RECOVERY_AUTHORITY_TABLES.filter(
2118
+ (tableName) => tableByName.has(tableName)
2119
+ ).map((tableName) => tableByName.get(tableName));
2120
+ const authorityOwners = new Set(authorityTables.map((table) => table.owner));
2121
+ if (authorityTables.length !== ORGANIZATION_RECOVERY_AUTHORITY_TABLES.length) {
2122
+ violations.push(
2123
+ `target-schema runtime capability ${routine.name} organization recovery authority tables are missing`
2124
+ );
2125
+ } else if (authorityOwners.size !== 1) {
2126
+ violations.push(
2127
+ `target-schema runtime capability ${routine.name} authority table owners do not match: ${authorityTables.map((table) => `${table.name}=${table.owner}`).join(", ")}`
2128
+ );
2129
+ } else if (routine.owner !== authorityTables[0].owner) {
2130
+ violations.push(
2131
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match authority table owner ${authorityTables[0].owner}`
2132
+ );
2133
+ }
2134
+ } else if (MANAGED_AUTH_SESSION_SET_ROUTINES.includes(routine.name)) {
2135
+ const authorityTables = MANAGED_AUTH_SESSION_SET_AUTHORITY_TABLES.filter(
2136
+ (tableName) => tableByName.has(tableName)
2137
+ ).map((tableName) => tableByName.get(tableName));
2138
+ const authorityOwners = new Set(authorityTables.map((table) => table.owner));
2139
+ if (authorityTables.length !== MANAGED_AUTH_SESSION_SET_AUTHORITY_TABLES.length) {
2140
+ violations.push(
2141
+ `target-schema runtime capability ${routine.name} managed auth session-set authority tables are missing`
2142
+ );
2143
+ } else if (authorityOwners.size !== 1) {
2144
+ violations.push(
2145
+ `target-schema runtime capability ${routine.name} authority table owners do not match: ${authorityTables.map((table) => `${table.name}=${table.owner}`).join(", ")}`
2146
+ );
2147
+ } else if (routine.owner !== authorityTables[0].owner) {
2148
+ violations.push(
2149
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match authority table owner ${authorityTables[0].owner}`
2150
+ );
2151
+ }
2020
2152
  } else if (CANONICAL_HUMAN_IDENTITY_ROUTINES.includes(routine.name)) {
2021
2153
  const authorityTables = CANONICAL_HUMAN_IDENTITY_AUTHORITY_TABLES.filter(
2022
2154
  (tableName) => tableByName.has(tableName)
@@ -3134,6 +3266,7 @@ async function grantAppRoleIfSchemaExists(sql2, role, schema) {
3134
3266
  const runtimeReadUpdateTables = `ARRAY[${RUNTIME_READ_UPDATE_TABLES.map(literal).join(", ")}]`;
3135
3267
  const runtimeReadInsertTables = `ARRAY[${RUNTIME_READ_INSERT_TABLES.map(literal).join(", ")}]`;
3136
3268
  const runtimeReadInsertUpdateTables = `ARRAY[${RUNTIME_READ_INSERT_UPDATE_TABLES.map(literal).join(", ")}]`;
3269
+ const workClaimCapabilityRoutines = `ARRAY[${WORK_CLAIM_CAPABILITY_ROUTINES.map(literal).join(", ")}]`;
3137
3270
  const organizationMembershipLifecycleRoutines = `ARRAY[${[
3138
3271
  "list_self_organization_memberships(text)",
3139
3272
  "list_self_organization_invitations(text)",
@@ -3183,6 +3316,27 @@ async function grantAppRoleIfSchemaExists(sql2, role, schema) {
3183
3316
  "finalize_organization_retention_deletion(uuid,uuid,uuid,text)",
3184
3317
  "complete_organization_retention_deletion(uuid,uuid,uuid,text)"
3185
3318
  ].map(literal).join(", ")}]`;
3319
+ const managedAuthSessionSetRoutines = `ARRAY[${[
3320
+ "get_canonical_human_exact_login_binding(text,text)",
3321
+ "managed_auth_session_set_authority_state(text)",
3322
+ "managed_auth_session_set_snapshot(text,text,boolean,boolean,boolean)",
3323
+ "managed_auth_session_set_bootstrap(text,text,text,text,uuid,text,bigint,bigint)",
3324
+ "managed_auth_session_set_begin_transaction(text,text,text,uuid,text,bigint,uuid,bigint,text,text,uuid,uuid,text,timestamp with time zone)",
3325
+ "managed_auth_session_set_complete_transaction(text,text,uuid,text,bigint,bigint,uuid,text,text,text)",
3326
+ "managed_auth_session_set_mutate(text,text,uuid,text,bigint,bigint,text,uuid,uuid,uuid,text,text)",
3327
+ "managed_auth_actor_mutation_fence(text,bigint,uuid)",
3328
+ "managed_auth_actor_mutation_lease_acquire(text,bigint,uuid,integer)",
3329
+ "managed_auth_actor_mutation_lease_release(text,uuid)",
3330
+ "managed_auth_actor_mutation_lease_validate(text,bigint,uuid)",
3331
+ "managed_auth_adopted_session_snapshot(text)",
3332
+ "managed_auth_isolated_session_reap(integer)",
3333
+ "managed_auth_expired_session_set_reap(integer)",
3334
+ "managed_auth_session_set_operation_receipt(text,uuid,text,text)"
3335
+ ].map(literal).join(", ")}]`;
3336
+ const organizationRecoveryRoutines = `ARRAY[${[
3337
+ "get_organization_recovery_overview(uuid,text,jsonb,text,text)",
3338
+ "organization_recovery_command(jsonb)"
3339
+ ].map(literal).join(", ")}]`;
3186
3340
  await sql2.unsafe(`
3187
3341
  DO $$
3188
3342
  DECLARE
@@ -3622,6 +3776,22 @@ BEGIN
3622
3776
  ${literal(role)}
3623
3777
  );
3624
3778
  END IF;
3779
+ -- Migration 0365 creates the advisory work-claim mutation capabilities
3780
+ -- before a custom runtime role may exist. Re-converge their exact grants
3781
+ -- for migrate-then-provision installs without exposing claim history or
3782
+ -- the write-capability ledger to direct runtime DML.
3783
+ FOREACH routine_signature IN ARRAY ${workClaimCapabilityRoutines} LOOP
3784
+ IF to_regprocedure(format('%I.%s', ${literal(schema)}, routine_signature)) IS NOT NULL THEN
3785
+ EXECUTE format(
3786
+ 'REVOKE ALL ON FUNCTION %I.%s FROM PUBLIC',
3787
+ ${literal(schema)}, routine_signature
3788
+ );
3789
+ EXECUTE format(
3790
+ 'GRANT EXECUTE ON FUNCTION %I.%s TO %I',
3791
+ ${literal(schema)}, routine_signature, ${literal(role)}
3792
+ );
3793
+ END IF;
3794
+ END LOOP;
3625
3795
  IF to_regprocedure(
3626
3796
  format(
3627
3797
  '%I.workspace_instruction_policy_get_or_create_snapshot(uuid,uuid,uuid,uuid,uuid,integer)',
@@ -3876,6 +4046,30 @@ BEGIN
3876
4046
  ${literal(role)}
3877
4047
  );
3878
4048
  END IF;
4049
+ FOREACH routine_signature IN ARRAY ${managedAuthSessionSetRoutines} LOOP
4050
+ IF to_regprocedure(format('%I.%s', ${literal(schema)}, routine_signature)) IS NOT NULL THEN
4051
+ EXECUTE format(
4052
+ 'REVOKE ALL ON FUNCTION %I.%s FROM PUBLIC',
4053
+ ${literal(schema)}, routine_signature
4054
+ );
4055
+ EXECUTE format(
4056
+ 'GRANT EXECUTE ON FUNCTION %I.%s TO %I',
4057
+ ${literal(schema)}, routine_signature, ${literal(role)}
4058
+ );
4059
+ END IF;
4060
+ END LOOP;
4061
+ FOREACH routine_signature IN ARRAY ${organizationRecoveryRoutines} LOOP
4062
+ IF to_regprocedure(format('%I.%s', ${literal(schema)}, routine_signature)) IS NOT NULL THEN
4063
+ EXECUTE format(
4064
+ 'REVOKE ALL ON FUNCTION %I.%s FROM PUBLIC',
4065
+ ${literal(schema)}, routine_signature
4066
+ );
4067
+ EXECUTE format(
4068
+ 'GRANT EXECUTE ON FUNCTION %I.%s TO %I',
4069
+ ${literal(schema)}, routine_signature, ${literal(role)}
4070
+ );
4071
+ END IF;
4072
+ END LOOP;
3879
4073
  -- Migration 0225 creates these target-schema-local session visibility
3880
4074
  -- capabilities before opengeni_app may exist. Re-converge their exact
3881
4075
  -- EXECUTE grants for migrate-then-provision installs without granting
@@ -4800,6 +4994,7 @@ if (import.meta.main) {
4800
4994
  }
4801
4995
 
4802
4996
  export {
4997
+ WORK_CLAIM_CAPABILITY_ROUTINES,
4803
4998
  RUNTIME_TARGET_SCHEMA_CAPABILITY_ROUTINES,
4804
4999
  RUNTIME_TARGET_SCHEMA_PUBLIC_POLICY_PREDICATE_ROUTINES,
4805
5000
  RUNTIME_TARGET_SCHEMA_FORBIDDEN_ROUTINES,
@@ -4821,4 +5016,4 @@ export {
4821
5016
  runtimeDatabaseReadyCheck,
4822
5017
  provisionRoles
4823
5018
  };
4824
- //# sourceMappingURL=chunk-PYMY3AJW.js.map
5019
+ //# sourceMappingURL=chunk-744DFC65.js.map