@noodleseed/one 0.63.0 → 0.64.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/auth-discovery.d.ts +17 -0
- package/dist/auth-discovery.d.ts.map +1 -0
- package/dist/auth-discovery.js +54 -0
- package/dist/auth-discovery.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/catalog-data-platform-auth.d.ts +7 -0
- package/dist/commands/catalog-data-platform-auth.d.ts.map +1 -0
- package/dist/commands/catalog-data-platform-auth.js +47 -0
- package/dist/commands/catalog-data-platform-auth.js.map +1 -0
- package/dist/commands/catalog.d.ts.map +1 -1
- package/dist/commands/catalog.js +6 -3
- package/dist/commands/catalog.js.map +1 -1
- package/dist/commands/docs-mcp.d.ts +3 -3
- package/dist/commands/docs-mcp.js +3 -3
- package/dist/commands/platform-auth-finalization-args.d.ts +13 -0
- package/dist/commands/platform-auth-finalization-args.d.ts.map +1 -0
- package/dist/commands/platform-auth-finalization-args.js +29 -0
- package/dist/commands/platform-auth-finalization-args.js.map +1 -0
- package/dist/commands/platform-auth-migration-args.d.ts +71 -0
- package/dist/commands/platform-auth-migration-args.d.ts.map +1 -0
- package/dist/commands/platform-auth-migration-args.js +320 -0
- package/dist/commands/platform-auth-migration-args.js.map +1 -0
- package/dist/commands/platform-auth-migration-ops.d.ts +3 -0
- package/dist/commands/platform-auth-migration-ops.d.ts.map +1 -0
- package/dist/commands/platform-auth-migration-ops.js +369 -0
- package/dist/commands/platform-auth-migration-ops.js.map +1 -0
- package/dist/commands/project-setup.js +1 -1
- package/dist/commands/project-setup.js.map +1 -1
- package/dist/config.d.ts +4 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/control-plane.d.ts +0 -11
- package/dist/control-plane.d.ts.map +1 -1
- package/dist/control-plane.js +1 -8
- package/dist/control-plane.js.map +1 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +3 -5
- package/dist/doctor.js.map +1 -1
- package/node_modules/@noodle-borg/agent-kit/dist/curated/command-groups.d.ts.map +1 -1
- package/node_modules/@noodle-borg/agent-kit/dist/curated/command-groups.js +4 -0
- package/node_modules/@noodle-borg/agent-kit/dist/curated/command-groups.js.map +1 -1
- package/node_modules/@noodle-borg/agent-kit/dist/generated/surface.d.ts.map +1 -1
- package/node_modules/@noodle-borg/agent-kit/dist/generated/surface.js +1 -0
- package/node_modules/@noodle-borg/agent-kit/dist/generated/surface.js.map +1 -1
- package/node_modules/@noodle-borg/auth/dist/jwt-issuer.d.ts +2 -2
- package/node_modules/@noodle-borg/auth/dist/jwt-issuer.d.ts.map +1 -1
- package/node_modules/@noodle-borg/auth/dist/jwt-issuer.js +1 -1
- package/node_modules/@noodle-borg/auth/dist/verify.d.ts +1 -1
- package/node_modules/@noodle-borg/auth/dist/verify.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/auth/deploy-gate.d.ts +26 -0
- package/node_modules/@noodle-borg/service/dist/auth/deploy-gate.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/auth/deploy-gate.js +105 -1
- package/node_modules/@noodle-borg/service/dist/auth/deploy-gate.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/control-plane-auth-bootstrap.d.ts +25 -0
- package/node_modules/@noodle-borg/service/dist/control-plane-auth-bootstrap.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/control-plane-auth-bootstrap.js +99 -0
- package/node_modules/@noodle-borg/service/dist/control-plane-auth-bootstrap.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/index.d.ts +15 -0
- package/node_modules/@noodle-borg/service/dist/index.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/index.js +15 -0
- package/node_modules/@noodle-borg/service/dist/index.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/main.js +112 -19
- package/node_modules/@noodle-borg/service/dist/main.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/app.d.ts +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/app.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/app.js +9 -1
- package/node_modules/@noodle-borg/service/dist/oauth/app.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/authorization-initiation.d.ts +24 -0
- package/node_modules/@noodle-borg/service/dist/oauth/authorization-initiation.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/authorization-initiation.js +88 -0
- package/node_modules/@noodle-borg/service/dist/oauth/authorization-initiation.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/branding.d.ts +2 -0
- package/node_modules/@noodle-borg/service/dist/oauth/branding.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/branding.js +3 -2
- package/node_modules/@noodle-borg/service/dist/oauth/branding.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/consent-claims.d.ts +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/consent-claims.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/consent-token.d.ts +5 -0
- package/node_modules/@noodle-borg/service/dist/oauth/consent-token.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/consent-token.js +19 -0
- package/node_modules/@noodle-borg/service/dist/oauth/consent-token.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/consent.js +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/developer-grant-page.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/developer-grant-page.js +216 -28
- package/node_modules/@noodle-borg/service/dist/oauth/developer-grant-page.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/first-party-client.d.ts +13 -0
- package/node_modules/@noodle-borg/service/dist/oauth/first-party-client.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/first-party-client.js +62 -0
- package/node_modules/@noodle-borg/service/dist/oauth/first-party-client.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/metadata.d.ts +4 -0
- package/node_modules/@noodle-borg/service/dist/oauth/metadata.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/metadata.js +20 -0
- package/node_modules/@noodle-borg/service/dist/oauth/metadata.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/paths.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/paths.js +2 -0
- package/node_modules/@noodle-borg/service/dist/oauth/paths.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/platform-principal-guard.d.ts +15 -0
- package/node_modules/@noodle-borg/service/dist/oauth/platform-principal-guard.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/platform-principal-guard.js +58 -0
- package/node_modules/@noodle-borg/service/dist/oauth/platform-principal-guard.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/platform-principal-postgres.d.ts +8 -0
- package/node_modules/@noodle-borg/service/dist/oauth/platform-principal-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/platform-principal-postgres.js +49 -0
- package/node_modules/@noodle-borg/service/dist/oauth/platform-principal-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/postgres-time.d.ts +3 -0
- package/node_modules/@noodle-borg/service/dist/oauth/postgres-time.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/postgres-time.js +7 -0
- package/node_modules/@noodle-borg/service/dist/oauth/postgres-time.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/provider.d.ts +20 -25
- package/node_modules/@noodle-borg/service/dist/oauth/provider.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/provider.js +105 -196
- package/node_modules/@noodle-borg/service/dist/oauth/provider.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/service-bootstrap.d.ts +36 -0
- package/node_modules/@noodle-borg/service/dist/oauth/service-bootstrap.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/service-bootstrap.js +157 -0
- package/node_modules/@noodle-borg/service/dist/oauth/service-bootstrap.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/store-postgres-schema.d.ts +4 -0
- package/node_modules/@noodle-borg/service/dist/oauth/store-postgres-schema.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/store-postgres-schema.js +110 -0
- package/node_modules/@noodle-borg/service/dist/oauth/store-postgres-schema.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/store-postgres.d.ts +7 -4
- package/node_modules/@noodle-borg/service/dist/oauth/store-postgres.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/store-postgres.js +63 -120
- package/node_modules/@noodle-borg/service/dist/oauth/store-postgres.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/store.d.ts +19 -6
- package/node_modules/@noodle-borg/service/dist/oauth/store.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/store.js +24 -2
- package/node_modules/@noodle-borg/service/dist/oauth/store.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/tokens.d.ts +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/tokens.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/tokens.js +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/tokens.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-callback-availability.d.ts +4 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-callback-availability.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-callback-availability.js +8 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-callback-availability.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-callback-handler.d.ts +34 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-callback-handler.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-callback-handler.js +109 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-callback-handler.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-callback-support.d.ts +22 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-callback-support.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-callback-support.js +30 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-callback-support.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-consent.d.ts +21 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-consent.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-consent.js +56 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-consent.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-federation.d.ts +30 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-federation.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-federation.js +94 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-federation.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-human.d.ts +33 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-human.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-human.js +27 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-human.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-provider-choice.d.ts +13 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-provider-choice.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-provider-choice.js +63 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-provider-choice.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-rollout-store.d.ts +20 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-rollout-store.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-rollout-store.js +40 -0
- package/node_modules/@noodle-borg/service/dist/oauth/upstream-rollout-store.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/workos-events.d.ts +115 -0
- package/node_modules/@noodle-borg/service/dist/oauth/workos-events.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/workos-events.js +310 -0
- package/node_modules/@noodle-borg/service/dist/oauth/workos-events.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/workos.d.ts +65 -0
- package/node_modules/@noodle-borg/service/dist/oauth/workos.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/workos.js +85 -0
- package/node_modules/@noodle-borg/service/dist/oauth/workos.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/options.d.ts +11 -2
- package/node_modules/@noodle-borg/service/dist/options.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/personal-workspace.d.ts +2 -0
- package/node_modules/@noodle-borg/service/dist/personal-workspace.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/personal-workspace.js +8 -2
- package/node_modules/@noodle-borg/service/dist/personal-workspace.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/platform-auth-configuration.d.ts +67 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-configuration.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-configuration.js +54 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-configuration.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-frozen-candidate-postgres.d.ts +25 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-frozen-candidate-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-frozen-candidate-postgres.js +61 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-frozen-candidate-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-legacy-sources-postgres.d.ts +32 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-legacy-sources-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-legacy-sources-postgres.js +231 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-legacy-sources-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-local-postgres.d.ts +29 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-local-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-local-postgres.js +350 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-local-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-local-subjects-postgres.d.ts +50 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-local-subjects-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-local-subjects-postgres.js +239 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-local-subjects-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-paging.d.ts +66 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-paging.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-paging.js +77 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-paging.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-postgres.d.ts +40 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-postgres.js +355 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-progress-postgres.d.ts +41 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-progress-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-progress-postgres.js +230 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-progress-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-source-fence-postgres.d.ts +20 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-source-fence-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-source-fence-postgres.js +126 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-source-fence-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-sources.d.ts +8 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-sources.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-sources.js +86 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-inventory-sources.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration-postgres.d.ts +42 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration-postgres.js +368 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration-runs-postgres.d.ts +86 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration-runs-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration-runs-postgres.js +474 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration-runs-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration-schema.d.ts +17 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration-schema.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration-schema.js +435 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration-schema.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration.d.ts +202 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration.js +313 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-migration.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-batches.d.ts +48 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-batches.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-batches.js +158 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-batches.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-effects.d.ts +43 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-effects.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-effects.js +92 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-effects.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-operation-postgres.d.ts +31 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-operation-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-operation-postgres.js +94 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-operation-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-ports.d.ts +102 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-ports.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-ports.js +2 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-ports.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-postgres.d.ts +17 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-postgres.js +367 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-remote-status.d.ts +10 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-remote-status.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-remote-status.js +37 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-remote-status.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-rollout.d.ts +36 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-rollout.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-rollout.js +156 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-rollout.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-schema.d.ts +4 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-schema.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-schema.js +162 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-schema.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-state-postgres.d.ts +92 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-state-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-state-postgres.js +271 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-state-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-state-support.d.ts +13 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-state-support.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-state-support.js +67 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-state-support.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-support.d.ts +15 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-support.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-support.js +47 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator-support.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator.d.ts +1569 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator.js +274 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-operator.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification-postgres-support.d.ts +41 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification-postgres-support.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification-postgres-support.js +163 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification-postgres-support.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification-postgres.d.ts +34 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification-postgres.js +274 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification-schema.d.ts +3 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification-schema.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification-schema.js +120 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification-schema.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification.d.ts +79 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification.js +88 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-remote-verification.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollback-guard.d.ts +6 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollback-guard.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollback-guard.js +38 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollback-guard.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollout-postgres.d.ts +61 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollout-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollout-postgres.js +292 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollout-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollout-readiness-postgres.d.ts +19 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollout-readiness-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollout-readiness-postgres.js +121 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollout-readiness-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollout-support.d.ts +119 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollout-support.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollout-support.js +194 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-rollout-support.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-runtime.d.ts +36 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-runtime.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-runtime.js +93 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-runtime.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-service-bootstrap.d.ts +32 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-service-bootstrap.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-service-bootstrap.js +68 -0
- package/node_modules/@noodle-borg/service/dist/platform-auth-service-bootstrap.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-maintenance.d.ts +36 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-maintenance.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-maintenance.js +92 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-maintenance.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-postgres.d.ts +23 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-postgres.js +231 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-schema-postgres.d.ts +13 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-schema-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-schema-postgres.js +399 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-schema-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-enqueue.d.ts +18 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-enqueue.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-enqueue.js +25 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-enqueue.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-evidence-postgres.d.ts +15 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-evidence-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-evidence-postgres.js +74 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-evidence-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-postgres.d.ts +19 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-postgres.js +249 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-recovery-postgres.d.ts +34 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-recovery-postgres.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-recovery-postgres.js +275 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync-recovery-postgres.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync.d.ts +98 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync.js +179 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity-sync.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity.d.ts +110 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity.js +312 -0
- package/node_modules/@noodle-borg/service/dist/platform-identity.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/routes/auth-discovery.d.ts +6 -0
- package/node_modules/@noodle-borg/service/dist/routes/auth-discovery.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/routes/auth-discovery.js +36 -0
- package/node_modules/@noodle-borg/service/dist/routes/auth-discovery.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/routes/billing-read.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/routes/billing-read.js +3 -9
- package/node_modules/@noodle-borg/service/dist/routes/billing-read.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/routes/billing-stripe.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/routes/billing-stripe.js +3 -3
- package/node_modules/@noodle-borg/service/dist/routes/billing-stripe.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/routes/github-run-claim.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/routes/github-run-claim.js +3 -1
- package/node_modules/@noodle-borg/service/dist/routes/github-run-claim.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/routes/platform-auth-migration-dispatch.d.ts +8 -0
- package/node_modules/@noodle-borg/service/dist/routes/platform-auth-migration-dispatch.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/routes/platform-auth-migration-dispatch.js +40 -0
- package/node_modules/@noodle-borg/service/dist/routes/platform-auth-migration-dispatch.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/routes/platform-auth-migration.d.ts +13 -0
- package/node_modules/@noodle-borg/service/dist/routes/platform-auth-migration.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/routes/platform-auth-migration.js +158 -0
- package/node_modules/@noodle-borg/service/dist/routes/platform-auth-migration.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/serve-options.d.ts +21 -3
- package/node_modules/@noodle-borg/service/dist/serve-options.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/serve.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/serve.js +61 -146
- package/node_modules/@noodle-borg/service/dist/serve.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/service-resource-cleanup.d.ts +1 -0
- package/node_modules/@noodle-borg/service/dist/service-resource-cleanup.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/service-resource-cleanup.js +3 -0
- package/node_modules/@noodle-borg/service/dist/service-resource-cleanup.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/service.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/service.js +17 -29
- package/node_modules/@noodle-borg/service/dist/service.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/store/control-plane.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/store/control-plane.js +60 -19
- package/node_modules/@noodle-borg/service/dist/store/control-plane.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/store/postgres-control-plane.d.ts +1 -2
- package/node_modules/@noodle-borg/service/dist/store/postgres-control-plane.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/store/postgres-control-plane.js +0 -40
- package/node_modules/@noodle-borg/service/dist/store/postgres-control-plane.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/store/postgres-personal-workspace.d.ts +5 -0
- package/node_modules/@noodle-borg/service/dist/store/postgres-personal-workspace.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/store/postgres-personal-workspace.js +176 -0
- package/node_modules/@noodle-borg/service/dist/store/postgres-personal-workspace.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/store/postgres-schema.d.ts +2 -0
- package/node_modules/@noodle-borg/service/dist/store/postgres-schema.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/store/postgres-schema.js +43 -1
- package/node_modules/@noodle-borg/service/dist/store/postgres-schema.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/store/postgres-signup.js +2 -1
- package/node_modules/@noodle-borg/service/dist/store/postgres-signup.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/workos-directory.d.ts +71 -0
- package/node_modules/@noodle-borg/service/dist/workos-directory.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/workos-directory.js +175 -0
- package/node_modules/@noodle-borg/service/dist/workos-directory.js.map +1 -0
- package/node_modules/@noodle-borg/service/package.json +1 -0
- package/node_modules/@workos-inc/node/LICENSE +21 -0
- package/node_modules/@workos-inc/node/README.md +140 -0
- package/node_modules/@workos-inc/node/lib/factory-B8vTFojy.d.cts +9727 -0
- package/node_modules/@workos-inc/node/lib/factory-B8vTFojy.d.mts +9727 -0
- package/node_modules/@workos-inc/node/lib/factory-CoKXdPX2.cjs +8426 -0
- package/node_modules/@workos-inc/node/lib/factory-CoKXdPX2.cjs.map +1 -0
- package/node_modules/@workos-inc/node/lib/factory-MKPb5Egh.mjs +8241 -0
- package/node_modules/@workos-inc/node/lib/factory-MKPb5Egh.mjs.map +1 -0
- package/node_modules/@workos-inc/node/lib/index.cjs +449 -0
- package/node_modules/@workos-inc/node/lib/index.cjs.map +1 -0
- package/node_modules/@workos-inc/node/lib/index.d.cts +478 -0
- package/node_modules/@workos-inc/node/lib/index.d.mts +478 -0
- package/node_modules/@workos-inc/node/lib/index.mjs +394 -0
- package/node_modules/@workos-inc/node/lib/index.mjs.map +1 -0
- package/node_modules/@workos-inc/node/lib/index.worker.cjs +60 -0
- package/node_modules/@workos-inc/node/lib/index.worker.cjs.map +1 -0
- package/node_modules/@workos-inc/node/lib/index.worker.d.cts +16 -0
- package/node_modules/@workos-inc/node/lib/index.worker.d.mts +16 -0
- package/node_modules/@workos-inc/node/lib/index.worker.mjs +35 -0
- package/node_modules/@workos-inc/node/lib/index.worker.mjs.map +1 -0
- package/node_modules/@workos-inc/node/lib/webapi-BgpV54gi.mjs +3224 -0
- package/node_modules/@workos-inc/node/lib/webapi-BgpV54gi.mjs.map +1 -0
- package/node_modules/@workos-inc/node/lib/webapi-BzGFatFp.cjs +3271 -0
- package/node_modules/@workos-inc/node/lib/webapi-BzGFatFp.cjs.map +1 -0
- package/node_modules/@workos-inc/node/package.json +96 -0
- package/package.json +2 -1
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { PlatformIdentitySyncError } from './platform-identity-sync.js';
|
|
3
|
+
import { isValidPlatformIdentitySyncEvidence, loadPlatformIdentitySyncEvidence, platformIdentitySyncEmail, } from './platform-identity-sync-evidence-postgres.js';
|
|
4
|
+
import { ensurePlatformIdentitySyncRecoverySchema } from './platform-identity-sync-recovery-postgres.js';
|
|
5
|
+
const GOOGLE_REALM = 'accounts.google.com';
|
|
6
|
+
/** Additive upgrade kept separate so the already-large canonical identity schema stays reviewable. */
|
|
7
|
+
export async function ensurePlatformIdentitySyncOutboxSchema(pool) {
|
|
8
|
+
await pool.query('ALTER TABLE platform_identity_sync_outbox ADD COLUMN IF NOT EXISTS lease_token text, ADD COLUMN IF NOT EXISTS lease_expires_at timestamptz, ADD COLUMN IF NOT EXISTS next_attempt_at timestamptz, ADD COLUMN IF NOT EXISTS failed_at timestamptz, ADD COLUMN IF NOT EXISTS outcome_code text, ADD COLUMN IF NOT EXISTS remote_user_id text');
|
|
9
|
+
await pool.query('UPDATE platform_identity_sync_outbox SET next_attempt_at = created_at WHERE next_attempt_at IS NULL');
|
|
10
|
+
await pool.query('ALTER TABLE platform_identity_sync_outbox ALTER COLUMN next_attempt_at SET DEFAULT now(), ALTER COLUMN next_attempt_at SET NOT NULL');
|
|
11
|
+
await pool.query('ALTER TABLE platform_identity_sync_outbox DROP CONSTRAINT IF EXISTS platform_identity_sync_outbox_event_type_check');
|
|
12
|
+
await pool.query("ALTER TABLE platform_identity_sync_outbox ADD CONSTRAINT platform_identity_sync_outbox_event_type_check CHECK (event_type IN ('google_identity_upsert', 'verified_email_changed', 'workos_external_id_reconcile')) NOT VALID");
|
|
13
|
+
await pool.query('ALTER TABLE platform_identity_sync_outbox VALIDATE CONSTRAINT platform_identity_sync_outbox_event_type_check');
|
|
14
|
+
await pool.query(`
|
|
15
|
+
CREATE INDEX IF NOT EXISTS platform_identity_sync_outbox_claim_idx
|
|
16
|
+
ON platform_identity_sync_outbox (next_attempt_at, created_at)
|
|
17
|
+
WHERE delivered_at IS NULL AND failed_at IS NULL
|
|
18
|
+
`);
|
|
19
|
+
await pool.query(`
|
|
20
|
+
CREATE TABLE IF NOT EXISTS platform_identity_sync_attempt_evidence (
|
|
21
|
+
id bigserial PRIMARY KEY,
|
|
22
|
+
idempotency_key_fingerprint text NOT NULL,
|
|
23
|
+
principal_fingerprint text NOT NULL,
|
|
24
|
+
attempt integer NOT NULL CHECK (attempt >= 1),
|
|
25
|
+
outcome_code text NOT NULL,
|
|
26
|
+
remote_user_fingerprint text,
|
|
27
|
+
retry_at timestamptz,
|
|
28
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
29
|
+
)
|
|
30
|
+
`);
|
|
31
|
+
await pool.query(`
|
|
32
|
+
CREATE OR REPLACE FUNCTION platform_identity_sync_attempt_evidence_append_only()
|
|
33
|
+
RETURNS trigger AS $$
|
|
34
|
+
BEGIN
|
|
35
|
+
RAISE EXCEPTION 'platform identity sync attempt evidence is append-only';
|
|
36
|
+
END;
|
|
37
|
+
$$ LANGUAGE plpgsql
|
|
38
|
+
`);
|
|
39
|
+
await pool.query(`
|
|
40
|
+
DO $platform_identity_sync_evidence_triggers$
|
|
41
|
+
BEGIN
|
|
42
|
+
IF NOT EXISTS (
|
|
43
|
+
SELECT 1 FROM pg_trigger
|
|
44
|
+
WHERE tgname = 'platform_identity_sync_attempt_evidence_update_trigger'
|
|
45
|
+
AND tgrelid = 'platform_identity_sync_attempt_evidence'::regclass AND NOT tgisinternal
|
|
46
|
+
) THEN
|
|
47
|
+
CREATE TRIGGER platform_identity_sync_attempt_evidence_update_trigger
|
|
48
|
+
BEFORE UPDATE ON platform_identity_sync_attempt_evidence
|
|
49
|
+
FOR EACH ROW EXECUTE FUNCTION platform_identity_sync_attempt_evidence_append_only();
|
|
50
|
+
END IF;
|
|
51
|
+
IF NOT EXISTS (
|
|
52
|
+
SELECT 1 FROM pg_trigger
|
|
53
|
+
WHERE tgname = 'platform_identity_sync_attempt_evidence_delete_trigger'
|
|
54
|
+
AND tgrelid = 'platform_identity_sync_attempt_evidence'::regclass AND NOT tgisinternal
|
|
55
|
+
) THEN
|
|
56
|
+
CREATE TRIGGER platform_identity_sync_attempt_evidence_delete_trigger
|
|
57
|
+
BEFORE DELETE ON platform_identity_sync_attempt_evidence
|
|
58
|
+
FOR EACH ROW EXECUTE FUNCTION platform_identity_sync_attempt_evidence_append_only();
|
|
59
|
+
END IF;
|
|
60
|
+
EXCEPTION WHEN duplicate_object THEN NULL;
|
|
61
|
+
END
|
|
62
|
+
$platform_identity_sync_evidence_triggers$
|
|
63
|
+
`);
|
|
64
|
+
await ensurePlatformIdentitySyncRecoverySchema(pool);
|
|
65
|
+
}
|
|
66
|
+
/** Durable, lease-fenced outbox adapter. Remote calls occur only after the claim transaction commits. */
|
|
67
|
+
export class PostgresPlatformIdentitySyncStore {
|
|
68
|
+
#pool;
|
|
69
|
+
#workosRealm;
|
|
70
|
+
#googleRealm;
|
|
71
|
+
constructor(pool, input) {
|
|
72
|
+
this.#pool = pool;
|
|
73
|
+
this.#workosRealm = bounded(input.workosRealm, 'WorkOS realm');
|
|
74
|
+
this.#googleRealm = bounded(input.googleRealm ?? GOOGLE_REALM, 'Google realm');
|
|
75
|
+
}
|
|
76
|
+
async claimBatch(input) {
|
|
77
|
+
if (!Number.isInteger(input.limit) || input.limit < 1 || input.limit > 100)
|
|
78
|
+
throw new Error('identity sync batch size must be between 1 and 100');
|
|
79
|
+
if (!Number.isInteger(input.leaseSeconds) ||
|
|
80
|
+
input.leaseSeconds < 10 ||
|
|
81
|
+
input.leaseSeconds > 300)
|
|
82
|
+
throw new Error('identity sync lease must be between 10 and 300 seconds');
|
|
83
|
+
const client = await this.#pool.connect();
|
|
84
|
+
try {
|
|
85
|
+
await client.query('BEGIN');
|
|
86
|
+
const candidates = await client.query(`SELECT idempotency_key, principal_id, event_type, attempt_count
|
|
87
|
+
FROM platform_identity_sync_outbox
|
|
88
|
+
WHERE delivered_at IS NULL AND failed_at IS NULL
|
|
89
|
+
AND next_attempt_at <= now()
|
|
90
|
+
AND (lease_token IS NULL OR lease_expires_at <= now())
|
|
91
|
+
ORDER BY next_attempt_at, created_at, idempotency_key
|
|
92
|
+
FOR UPDATE SKIP LOCKED LIMIT $1`, [input.limit]);
|
|
93
|
+
const leases = [];
|
|
94
|
+
for (const candidate of candidates.rows) {
|
|
95
|
+
const evidence = await loadPlatformIdentitySyncEvidence(client, candidate.principal_id, this.#googleRealm, this.#workosRealm);
|
|
96
|
+
const normalizedEmail = platformIdentitySyncEmail(candidate.event_type, evidence);
|
|
97
|
+
if (normalizedEmail === undefined ||
|
|
98
|
+
!isValidPlatformIdentitySyncEvidence(candidate.event_type, evidence)) {
|
|
99
|
+
await markLocalEvidenceConflict(client, candidate);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const leaseToken = randomUUID();
|
|
103
|
+
const claimed = await client.query(`UPDATE platform_identity_sync_outbox
|
|
104
|
+
SET lease_token = $2,
|
|
105
|
+
lease_expires_at = now() + ($3 * interval '1 second'),
|
|
106
|
+
attempt_count = attempt_count + 1
|
|
107
|
+
WHERE idempotency_key = $1 AND delivered_at IS NULL AND failed_at IS NULL
|
|
108
|
+
RETURNING attempt_count`, [candidate.idempotency_key, leaseToken, input.leaseSeconds]);
|
|
109
|
+
const attempt = claimed.rows[0]?.attempt_count;
|
|
110
|
+
if (attempt === undefined)
|
|
111
|
+
continue;
|
|
112
|
+
leases.push({
|
|
113
|
+
idempotencyKey: candidate.idempotency_key,
|
|
114
|
+
principalId: candidate.principal_id,
|
|
115
|
+
eventType: candidate.event_type,
|
|
116
|
+
normalizedEmail,
|
|
117
|
+
workosUserId: evidence.workosUserIds[0],
|
|
118
|
+
leaseToken,
|
|
119
|
+
attempt,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
await client.query('COMMIT');
|
|
123
|
+
return leases;
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
await client.query('ROLLBACK').catch(() => undefined);
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
client.release();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async finish(lease, result) {
|
|
134
|
+
const client = await this.#pool.connect();
|
|
135
|
+
try {
|
|
136
|
+
await client.query('BEGIN');
|
|
137
|
+
const row = await client.query(`SELECT idempotency_key, principal_id, event_type, attempt_count, lease_token
|
|
138
|
+
FROM platform_identity_sync_outbox WHERE idempotency_key = $1 FOR UPDATE`, [lease.idempotencyKey]);
|
|
139
|
+
const current = row.rows[0];
|
|
140
|
+
if (current === undefined ||
|
|
141
|
+
current.lease_token !== lease.leaseToken ||
|
|
142
|
+
current.attempt_count !== lease.attempt ||
|
|
143
|
+
current.principal_id !== lease.principalId ||
|
|
144
|
+
current.event_type !== lease.eventType)
|
|
145
|
+
throw new PlatformIdentitySyncError('stale_lease');
|
|
146
|
+
const evidence = await loadPlatformIdentitySyncEvidence(client, lease.principalId, this.#googleRealm, this.#workosRealm);
|
|
147
|
+
const normalizedEmail = platformIdentitySyncEmail(lease.eventType, evidence);
|
|
148
|
+
if (normalizedEmail === undefined ||
|
|
149
|
+
!isValidPlatformIdentitySyncEvidence(lease.eventType, evidence) ||
|
|
150
|
+
normalizedEmail !== lease.normalizedEmail ||
|
|
151
|
+
!workosEvidenceStillMatches(lease, result, evidence))
|
|
152
|
+
throw new PlatformIdentitySyncError('identity_sync_drift');
|
|
153
|
+
if (result.state === 'delivered') {
|
|
154
|
+
await linkWorkOSIdentity(client, this.#workosRealm, lease.principalId, result.remoteUserId);
|
|
155
|
+
await client.query(`UPDATE platform_identity_sync_outbox
|
|
156
|
+
SET delivered_at = now(), failed_at = NULL, outcome_code = $3,
|
|
157
|
+
remote_user_id = $4, lease_token = NULL, lease_expires_at = NULL
|
|
158
|
+
WHERE idempotency_key = $1 AND lease_token = $2`, [lease.idempotencyKey, lease.leaseToken, result.outcomeCode, result.remoteUserId]);
|
|
159
|
+
}
|
|
160
|
+
else if (result.state === 'retry') {
|
|
161
|
+
const retryAt = new Date(result.retryAt);
|
|
162
|
+
if (Number.isNaN(retryAt.getTime()) || retryAt.getTime() <= Date.now())
|
|
163
|
+
throw new Error('identity sync retry must be in the future');
|
|
164
|
+
await client.query(`UPDATE platform_identity_sync_outbox
|
|
165
|
+
SET next_attempt_at = $3::timestamptz, outcome_code = $4,
|
|
166
|
+
lease_token = NULL, lease_expires_at = NULL
|
|
167
|
+
WHERE idempotency_key = $1 AND lease_token = $2`, [lease.idempotencyKey, lease.leaseToken, result.retryAt, result.outcomeCode]);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
await client.query(`UPDATE platform_identity_sync_outbox
|
|
171
|
+
SET failed_at = now(), outcome_code = $3,
|
|
172
|
+
lease_token = NULL, lease_expires_at = NULL
|
|
173
|
+
WHERE idempotency_key = $1 AND lease_token = $2`, [lease.idempotencyKey, lease.leaseToken, result.outcomeCode]);
|
|
174
|
+
}
|
|
175
|
+
await recordEvidence(client, lease, result);
|
|
176
|
+
await client.query('COMMIT');
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
await client.query('ROLLBACK').catch(() => undefined);
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
client.release();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function workosEvidenceStillMatches(lease, result, evidence) {
|
|
188
|
+
if (lease.workosUserId !== undefined)
|
|
189
|
+
return evidence.workosUserIds[0] === lease.workosUserId;
|
|
190
|
+
if (evidence.workosUserIds.length === 0)
|
|
191
|
+
return true;
|
|
192
|
+
return result.state === 'delivered' && evidence.workosUserIds[0] === result.remoteUserId;
|
|
193
|
+
}
|
|
194
|
+
async function linkWorkOSIdentity(client, realm, principalId, remoteUserId) {
|
|
195
|
+
await client.query(`INSERT INTO platform_identity_links (provider, realm, external_id, principal_id)
|
|
196
|
+
VALUES ('workos', $1, $2, $3) ON CONFLICT (provider, realm, external_id) DO NOTHING`, [realm, remoteUserId, principalId]);
|
|
197
|
+
const exact = await client.query(`SELECT principal_id FROM platform_identity_links
|
|
198
|
+
WHERE provider = 'workos' AND realm = $1 AND external_id = $2 AND disabled_at IS NULL`, [realm, remoteUserId]);
|
|
199
|
+
const principal = await client.query(`SELECT external_id FROM platform_identity_links
|
|
200
|
+
WHERE provider = 'workos' AND realm = $1 AND principal_id = $2 AND disabled_at IS NULL`, [realm, principalId]);
|
|
201
|
+
if (exact.rows[0]?.principal_id !== principalId ||
|
|
202
|
+
principal.rows[0]?.external_id !== remoteUserId)
|
|
203
|
+
throw new PlatformIdentitySyncError('identity_sync_drift');
|
|
204
|
+
}
|
|
205
|
+
async function markLocalEvidenceConflict(client, row) {
|
|
206
|
+
await client.query(`UPDATE platform_identity_sync_outbox
|
|
207
|
+
SET failed_at = now(), outcome_code = 'local_evidence_conflict',
|
|
208
|
+
lease_token = NULL, lease_expires_at = NULL
|
|
209
|
+
WHERE idempotency_key = $1`, [row.idempotency_key]);
|
|
210
|
+
await client.query(`INSERT INTO platform_identity_sync_attempt_evidence
|
|
211
|
+
(idempotency_key_fingerprint, principal_fingerprint, attempt, outcome_code)
|
|
212
|
+
VALUES ($1, $2, $3, 'local_evidence_conflict')`, [fingerprint(row.idempotency_key), fingerprint(row.principal_id), row.attempt_count + 1]);
|
|
213
|
+
}
|
|
214
|
+
async function recordEvidence(client, lease, result) {
|
|
215
|
+
const remoteUserId = result.state === 'delivered' ? result.remoteUserId : undefined;
|
|
216
|
+
const retryAt = result.state === 'retry' ? result.retryAt : undefined;
|
|
217
|
+
await client.query(`INSERT INTO platform_identity_sync_attempt_evidence
|
|
218
|
+
(idempotency_key_fingerprint, principal_fingerprint, attempt, outcome_code,
|
|
219
|
+
remote_user_fingerprint, retry_at)
|
|
220
|
+
VALUES ($1, $2, $3, $4, $5, $6::timestamptz)`, [
|
|
221
|
+
fingerprint(lease.idempotencyKey),
|
|
222
|
+
fingerprint(lease.principalId),
|
|
223
|
+
lease.attempt,
|
|
224
|
+
result.outcomeCode,
|
|
225
|
+
remoteUserId === undefined ? null : fingerprint(remoteUserId),
|
|
226
|
+
retryAt ?? null,
|
|
227
|
+
]);
|
|
228
|
+
}
|
|
229
|
+
function fingerprint(value) {
|
|
230
|
+
return createHash('sha256').update(value).digest('hex');
|
|
231
|
+
}
|
|
232
|
+
function bounded(value, name) {
|
|
233
|
+
const normalized = value.trim();
|
|
234
|
+
if (normalized.length === 0 || normalized.length > 512)
|
|
235
|
+
throw new Error(`${name} is invalid`);
|
|
236
|
+
return normalized;
|
|
237
|
+
}
|
|
238
|
+
// Compile-time assertion that every persisted processor outcome remains intentionally enumerated.
|
|
239
|
+
const _outcomes = [
|
|
240
|
+
'delivered',
|
|
241
|
+
'remote_identity_conflict',
|
|
242
|
+
'provider_conflict',
|
|
243
|
+
'provider_rate_limited',
|
|
244
|
+
'provider_transient',
|
|
245
|
+
'provider_permanent',
|
|
246
|
+
'provider_unauthorized',
|
|
247
|
+
];
|
|
248
|
+
void _outcomes;
|
|
249
|
+
//# sourceMappingURL=platform-identity-sync-postgres.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-identity-sync-postgres.js","sourceRoot":"","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
|
|
|
1
|
+
import type { Pool } from 'pg';
|
|
2
|
+
import type { PlatformIdentityQueryable } from './platform-identity-postgres.js';
|
|
3
|
+
import { type PlatformIdentitySyncRecoveryResult, type PlatformIdentitySyncRecoveryStore } from './platform-identity-sync.js';
|
|
4
|
+
export declare function ensurePlatformIdentitySyncRecoverySchema(pool: PlatformIdentityQueryable): Promise<void>;
|
|
5
|
+
/** Dangerous operator-only capability kept separate from the ordinary leased worker adapter. */
|
|
6
|
+
export declare class PostgresPlatformIdentitySyncRecoveryStore implements PlatformIdentitySyncRecoveryStore {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(pool: Pool, input: {
|
|
9
|
+
readonly workosRealm: string;
|
|
10
|
+
readonly googleRealm?: string;
|
|
11
|
+
});
|
|
12
|
+
previewTerminalRecovery(input: {
|
|
13
|
+
readonly limit: number;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
readonly terminal: number;
|
|
16
|
+
readonly checksum: string;
|
|
17
|
+
}>;
|
|
18
|
+
replayTerminalRecovery(input: {
|
|
19
|
+
readonly limit: number;
|
|
20
|
+
readonly operationFingerprint: string;
|
|
21
|
+
readonly requestFingerprint: string;
|
|
22
|
+
readonly actorFingerprint: string;
|
|
23
|
+
readonly reasonFingerprint: string;
|
|
24
|
+
}): Promise<PlatformIdentitySyncRecoveryResult | undefined>;
|
|
25
|
+
recoverTerminal(input: {
|
|
26
|
+
readonly limit: number;
|
|
27
|
+
readonly expectedChecksum: string;
|
|
28
|
+
readonly operationFingerprint: string;
|
|
29
|
+
readonly requestFingerprint: string;
|
|
30
|
+
readonly actorFingerprint: string;
|
|
31
|
+
readonly reasonFingerprint: string;
|
|
32
|
+
}): Promise<PlatformIdentitySyncRecoveryResult>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=platform-identity-sync-recovery-postgres.d.ts.map
|
package/node_modules/@noodle-borg/service/dist/platform-identity-sync-recovery-postgres.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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EAAE,MAAM,CAAC;QACtC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;QACpC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;QAClC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;KACpC,GAAG,OAAO,CAAC,kCAAkC,CAAC;CAyFhD"}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { PlatformIdentitySyncError, } from './platform-identity-sync.js';
|
|
3
|
+
import { isValidPlatformIdentitySyncEvidence, loadPlatformIdentitySyncEvidence, } from './platform-identity-sync-evidence-postgres.js';
|
|
4
|
+
const GOOGLE_REALM = 'accounts.google.com';
|
|
5
|
+
export async function ensurePlatformIdentitySyncRecoverySchema(pool) {
|
|
6
|
+
await pool.query(`
|
|
7
|
+
CREATE TABLE IF NOT EXISTS platform_identity_sync_recovery_operations (
|
|
8
|
+
operation_fingerprint text PRIMARY KEY CHECK (operation_fingerprint ~ '^[0-9a-f]{64}$'),
|
|
9
|
+
request_fingerprint text NOT NULL CHECK (request_fingerprint ~ '^[0-9a-f]{64}$'),
|
|
10
|
+
actor_fingerprint text NOT NULL CHECK (actor_fingerprint ~ '^[0-9a-f]{64}$'),
|
|
11
|
+
reason_fingerprint text NOT NULL CHECK (reason_fingerprint ~ '^[0-9a-f]{64}$'),
|
|
12
|
+
expected_checksum text NOT NULL CHECK (expected_checksum ~ '^[0-9a-f]{64}$'),
|
|
13
|
+
batch_limit integer NOT NULL CHECK (batch_limit BETWEEN 1 AND 100),
|
|
14
|
+
attempted integer NOT NULL CHECK (attempted >= 0),
|
|
15
|
+
recovered integer NOT NULL CHECK (recovered >= 0),
|
|
16
|
+
rejected integer NOT NULL CHECK (rejected >= 0),
|
|
17
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
18
|
+
CHECK (attempted = recovered + rejected)
|
|
19
|
+
)
|
|
20
|
+
`);
|
|
21
|
+
await pool.query(`
|
|
22
|
+
CREATE TABLE IF NOT EXISTS platform_identity_sync_recovery_attempt_evidence (
|
|
23
|
+
id bigserial PRIMARY KEY,
|
|
24
|
+
operation_fingerprint text NOT NULL
|
|
25
|
+
REFERENCES platform_identity_sync_recovery_operations(operation_fingerprint)
|
|
26
|
+
DEFERRABLE INITIALLY DEFERRED,
|
|
27
|
+
idempotency_key_fingerprint text NOT NULL CHECK (idempotency_key_fingerprint ~ '^[0-9a-f]{64}$'),
|
|
28
|
+
principal_fingerprint text NOT NULL CHECK (principal_fingerprint ~ '^[0-9a-f]{64}$'),
|
|
29
|
+
actor_fingerprint text NOT NULL CHECK (actor_fingerprint ~ '^[0-9a-f]{64}$'),
|
|
30
|
+
attempt integer NOT NULL CHECK (attempt >= 1),
|
|
31
|
+
result_code text NOT NULL CHECK (result_code IN ('recovered', 'evidence_rejected')),
|
|
32
|
+
evidence_fingerprint text NOT NULL CHECK (evidence_fingerprint ~ '^[0-9a-f]{64}$'),
|
|
33
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
34
|
+
)
|
|
35
|
+
`);
|
|
36
|
+
await pool.query(`
|
|
37
|
+
CREATE OR REPLACE FUNCTION platform_identity_sync_recovery_evidence_append_only()
|
|
38
|
+
RETURNS trigger AS $$
|
|
39
|
+
BEGIN
|
|
40
|
+
RAISE EXCEPTION 'platform identity sync recovery evidence is append-only';
|
|
41
|
+
END;
|
|
42
|
+
$$ LANGUAGE plpgsql
|
|
43
|
+
`);
|
|
44
|
+
await pool.query(`
|
|
45
|
+
DO $platform_identity_sync_recovery_triggers$
|
|
46
|
+
BEGIN
|
|
47
|
+
IF NOT EXISTS (
|
|
48
|
+
SELECT 1 FROM pg_trigger
|
|
49
|
+
WHERE tgname = 'platform_identity_sync_recovery_operations_guard'
|
|
50
|
+
AND tgrelid = 'platform_identity_sync_recovery_operations'::regclass
|
|
51
|
+
AND NOT tgisinternal
|
|
52
|
+
) THEN
|
|
53
|
+
CREATE TRIGGER platform_identity_sync_recovery_operations_guard
|
|
54
|
+
BEFORE UPDATE OR DELETE ON platform_identity_sync_recovery_operations
|
|
55
|
+
FOR EACH ROW EXECUTE FUNCTION platform_identity_sync_recovery_evidence_append_only();
|
|
56
|
+
END IF;
|
|
57
|
+
IF NOT EXISTS (
|
|
58
|
+
SELECT 1 FROM pg_trigger
|
|
59
|
+
WHERE tgname = 'platform_identity_sync_recovery_attempts_guard'
|
|
60
|
+
AND tgrelid = 'platform_identity_sync_recovery_attempt_evidence'::regclass
|
|
61
|
+
AND NOT tgisinternal
|
|
62
|
+
) THEN
|
|
63
|
+
CREATE TRIGGER platform_identity_sync_recovery_attempts_guard
|
|
64
|
+
BEFORE UPDATE OR DELETE ON platform_identity_sync_recovery_attempt_evidence
|
|
65
|
+
FOR EACH ROW EXECUTE FUNCTION platform_identity_sync_recovery_evidence_append_only();
|
|
66
|
+
END IF;
|
|
67
|
+
EXCEPTION WHEN duplicate_object THEN NULL;
|
|
68
|
+
END
|
|
69
|
+
$platform_identity_sync_recovery_triggers$
|
|
70
|
+
`);
|
|
71
|
+
}
|
|
72
|
+
/** Dangerous operator-only capability kept separate from the ordinary leased worker adapter. */
|
|
73
|
+
export class PostgresPlatformIdentitySyncRecoveryStore {
|
|
74
|
+
#pool;
|
|
75
|
+
#workosRealm;
|
|
76
|
+
#googleRealm;
|
|
77
|
+
constructor(pool, input) {
|
|
78
|
+
this.#pool = pool;
|
|
79
|
+
this.#workosRealm = bounded(input.workosRealm, 'WorkOS realm');
|
|
80
|
+
this.#googleRealm = bounded(input.googleRealm ?? GOOGLE_REALM, 'Google realm');
|
|
81
|
+
}
|
|
82
|
+
async previewTerminalRecovery(input) {
|
|
83
|
+
validateRecoveryLimit(input.limit);
|
|
84
|
+
const client = await this.#pool.connect();
|
|
85
|
+
try {
|
|
86
|
+
await client.query('BEGIN ISOLATION LEVEL REPEATABLE READ');
|
|
87
|
+
const entries = await terminalRecoveryEntries(client, input.limit, this.#googleRealm, this.#workosRealm, false);
|
|
88
|
+
await client.query('COMMIT');
|
|
89
|
+
return { terminal: entries.length, checksum: recoveryChecksum(entries) };
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
await client.query('ROLLBACK').catch(() => undefined);
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
client.release();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async replayTerminalRecovery(input) {
|
|
100
|
+
validateRecoveryReplayInput(input);
|
|
101
|
+
const client = await this.#pool.connect();
|
|
102
|
+
try {
|
|
103
|
+
const replay = await recoveryReplay(client, input);
|
|
104
|
+
return replay === undefined ? undefined : { ...replay, replayed: true };
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
client.release();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async recoverTerminal(input) {
|
|
111
|
+
validateRecoveryInput(input);
|
|
112
|
+
const client = await this.#pool.connect();
|
|
113
|
+
try {
|
|
114
|
+
await client.query('BEGIN ISOLATION LEVEL SERIALIZABLE');
|
|
115
|
+
await client.query('SELECT pg_advisory_xact_lock(hashtextextended($1, 0))', [
|
|
116
|
+
`platform-identity-sync-recovery:${input.operationFingerprint}`,
|
|
117
|
+
]);
|
|
118
|
+
const replay = await recoveryReplay(client, input);
|
|
119
|
+
if (replay !== undefined) {
|
|
120
|
+
await client.query('COMMIT');
|
|
121
|
+
return { ...replay, replayed: true };
|
|
122
|
+
}
|
|
123
|
+
await client.query('LOCK TABLE platform_principals, platform_identity_links, platform_verified_emails IN SHARE MODE');
|
|
124
|
+
const entries = await terminalRecoveryEntries(client, input.limit, this.#googleRealm, this.#workosRealm, true);
|
|
125
|
+
if (recoveryChecksum(entries) !== input.expectedChecksum)
|
|
126
|
+
throw new PlatformIdentitySyncError('identity_sync_recovery_drift');
|
|
127
|
+
const outcomes = [];
|
|
128
|
+
for (const entry of entries) {
|
|
129
|
+
const outcome = isValidPlatformIdentitySyncEvidence(entry.row.event_type, entry.evidence)
|
|
130
|
+
? 'recovered'
|
|
131
|
+
: 'evidence_rejected';
|
|
132
|
+
if (outcome === 'recovered') {
|
|
133
|
+
const recovered = await client.query(`UPDATE platform_identity_sync_outbox
|
|
134
|
+
SET failed_at = NULL, outcome_code = 'operator_recovered',
|
|
135
|
+
next_attempt_at = now(), lease_token = NULL, lease_expires_at = NULL
|
|
136
|
+
WHERE idempotency_key = $1 AND delivered_at IS NULL AND failed_at IS NOT NULL
|
|
137
|
+
RETURNING idempotency_key`, [entry.row.idempotency_key]);
|
|
138
|
+
if (recovered.rows[0] === undefined)
|
|
139
|
+
throw new PlatformIdentitySyncError('identity_sync_recovery_drift');
|
|
140
|
+
}
|
|
141
|
+
outcomes.push(outcome);
|
|
142
|
+
}
|
|
143
|
+
const recovered = outcomes.filter((outcome) => outcome === 'recovered').length;
|
|
144
|
+
const rejected = outcomes.length - recovered;
|
|
145
|
+
await client.query(`INSERT INTO platform_identity_sync_recovery_operations
|
|
146
|
+
(operation_fingerprint, request_fingerprint, actor_fingerprint, reason_fingerprint,
|
|
147
|
+
expected_checksum, batch_limit, attempted, recovered, rejected)
|
|
148
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`, [
|
|
149
|
+
input.operationFingerprint,
|
|
150
|
+
input.requestFingerprint,
|
|
151
|
+
input.actorFingerprint,
|
|
152
|
+
input.reasonFingerprint,
|
|
153
|
+
input.expectedChecksum,
|
|
154
|
+
input.limit,
|
|
155
|
+
outcomes.length,
|
|
156
|
+
recovered,
|
|
157
|
+
rejected,
|
|
158
|
+
]);
|
|
159
|
+
for (const [index, entry] of entries.entries()) {
|
|
160
|
+
await client.query(`INSERT INTO platform_identity_sync_recovery_attempt_evidence
|
|
161
|
+
(operation_fingerprint, idempotency_key_fingerprint, principal_fingerprint,
|
|
162
|
+
actor_fingerprint, attempt, result_code, evidence_fingerprint)
|
|
163
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7)`, [
|
|
164
|
+
input.operationFingerprint,
|
|
165
|
+
fingerprint(entry.row.idempotency_key),
|
|
166
|
+
fingerprint(entry.row.principal_id),
|
|
167
|
+
input.actorFingerprint,
|
|
168
|
+
entry.row.attempt_count + 1,
|
|
169
|
+
outcomes[index],
|
|
170
|
+
evidenceFingerprint(entry),
|
|
171
|
+
]);
|
|
172
|
+
}
|
|
173
|
+
await client.query('COMMIT');
|
|
174
|
+
return { attempted: outcomes.length, recovered, rejected, replayed: false };
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
await client.query('ROLLBACK').catch(() => undefined);
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
client.release();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async function terminalRecoveryEntries(client, limit, googleRealm, workosRealm, lock) {
|
|
186
|
+
const rows = await client.query(`SELECT idempotency_key, principal_id, event_type, attempt_count, outcome_code,
|
|
187
|
+
lease_token, lease_expires_at
|
|
188
|
+
FROM platform_identity_sync_outbox
|
|
189
|
+
WHERE delivered_at IS NULL AND failed_at IS NOT NULL
|
|
190
|
+
ORDER BY created_at, idempotency_key
|
|
191
|
+
LIMIT $1 ${lock ? 'FOR UPDATE' : ''}`, [limit]);
|
|
192
|
+
const entries = [];
|
|
193
|
+
for (const row of rows.rows) {
|
|
194
|
+
entries.push({
|
|
195
|
+
row,
|
|
196
|
+
evidence: await loadPlatformIdentitySyncEvidence(client, row.principal_id, googleRealm, workosRealm, lock),
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return entries;
|
|
200
|
+
}
|
|
201
|
+
function recoveryChecksum(entries) {
|
|
202
|
+
return fingerprint(JSON.stringify(entries.map((entry) => ({
|
|
203
|
+
idempotencyKeyFingerprint: fingerprint(entry.row.idempotency_key),
|
|
204
|
+
principalFingerprint: fingerprint(entry.row.principal_id),
|
|
205
|
+
eventType: entry.row.event_type,
|
|
206
|
+
attempt: entry.row.attempt_count,
|
|
207
|
+
outcomeFingerprint: fingerprint(entry.row.outcome_code ?? ''),
|
|
208
|
+
leaseFingerprint: fingerprint(entry.row.lease_token ?? ''),
|
|
209
|
+
leaseExpiresAt: entry.row.lease_expires_at?.toISOString() ?? null,
|
|
210
|
+
evidenceFingerprint: evidenceFingerprint(entry),
|
|
211
|
+
}))));
|
|
212
|
+
}
|
|
213
|
+
function evidenceFingerprint(entry) {
|
|
214
|
+
return fingerprint(JSON.stringify({
|
|
215
|
+
status: entry.evidence.status,
|
|
216
|
+
googleEmailFingerprints: entry.evidence.googleEmails.map(fingerprint),
|
|
217
|
+
workosEmailFingerprints: entry.evidence.workosEmails.map(fingerprint),
|
|
218
|
+
sharedGoogleEmailPrincipalCount: entry.evidence.sharedGoogleEmailPrincipalCount,
|
|
219
|
+
sharedWorkosEmailPrincipalCount: entry.evidence.sharedWorkosEmailPrincipalCount,
|
|
220
|
+
googleLinkCount: entry.evidence.googleLinkCount,
|
|
221
|
+
workosUserFingerprints: entry.evidence.workosUserIds.map(fingerprint),
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
async function recoveryReplay(client, input) {
|
|
225
|
+
const prior = await client.query(`SELECT request_fingerprint, actor_fingerprint, reason_fingerprint, expected_checksum,
|
|
226
|
+
batch_limit, attempted, recovered, rejected
|
|
227
|
+
FROM platform_identity_sync_recovery_operations WHERE operation_fingerprint = $1`, [input.operationFingerprint]);
|
|
228
|
+
const row = prior.rows[0];
|
|
229
|
+
if (row === undefined)
|
|
230
|
+
return undefined;
|
|
231
|
+
if (row.request_fingerprint !== input.requestFingerprint ||
|
|
232
|
+
row.actor_fingerprint !== input.actorFingerprint ||
|
|
233
|
+
row.reason_fingerprint !== input.reasonFingerprint ||
|
|
234
|
+
(input.expectedChecksum !== undefined && row.expected_checksum !== input.expectedChecksum) ||
|
|
235
|
+
row.batch_limit !== input.limit)
|
|
236
|
+
throw new PlatformIdentitySyncError('identity_sync_recovery_conflict');
|
|
237
|
+
return { attempted: row.attempted, recovered: row.recovered, rejected: row.rejected };
|
|
238
|
+
}
|
|
239
|
+
function validateRecoveryReplayInput(input) {
|
|
240
|
+
validateRecoveryLimit(input.limit);
|
|
241
|
+
validateFingerprints([
|
|
242
|
+
input.operationFingerprint,
|
|
243
|
+
input.requestFingerprint,
|
|
244
|
+
input.actorFingerprint,
|
|
245
|
+
input.reasonFingerprint,
|
|
246
|
+
]);
|
|
247
|
+
}
|
|
248
|
+
function validateRecoveryInput(input) {
|
|
249
|
+
validateRecoveryLimit(input.limit);
|
|
250
|
+
validateFingerprints([
|
|
251
|
+
input.expectedChecksum,
|
|
252
|
+
input.operationFingerprint,
|
|
253
|
+
input.requestFingerprint,
|
|
254
|
+
input.actorFingerprint,
|
|
255
|
+
input.reasonFingerprint,
|
|
256
|
+
]);
|
|
257
|
+
}
|
|
258
|
+
function validateRecoveryLimit(limit) {
|
|
259
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 100)
|
|
260
|
+
throw new Error('identity sync recovery batch size must be between 1 and 100');
|
|
261
|
+
}
|
|
262
|
+
function validateFingerprints(values) {
|
|
263
|
+
if (values.some((value) => !/^[0-9a-f]{64}$/.test(value)))
|
|
264
|
+
throw new Error('identity sync recovery evidence is invalid');
|
|
265
|
+
}
|
|
266
|
+
function fingerprint(value) {
|
|
267
|
+
return createHash('sha256').update(value).digest('hex');
|
|
268
|
+
}
|
|
269
|
+
function bounded(value, name) {
|
|
270
|
+
const normalized = value.trim();
|
|
271
|
+
if (normalized.length === 0 || normalized.length > 512)
|
|
272
|
+
throw new Error(`${name} is invalid`);
|
|
273
|
+
return normalized;
|
|
274
|
+
}
|
|
275
|
+
//# sourceMappingURL=platform-identity-sync-recovery-postgres.js.map
|
package/node_modules/@noodle-borg/service/dist/platform-identity-sync-recovery-postgres.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-identity-sync-recovery-postgres.js","sourceRoot":"","sources":["../src/platform-identity-sync-recovery-postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MA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