@tokenoftrust/storefront-runner 7.3.2 → 7.5.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/agency-kit/tools/lib/catalog-model/files.mjs +11 -4
- package/agency-kit/tools/lib/catalog-model/model.mjs +5 -1
- package/agency-kit/tools/lib/redirect-shadows.mjs +261 -0
- package/apps/storefront/astro.config.mjs +8 -2
- package/apps/storefront/package.json +1 -2
- package/apps/storefront/src/components/catalog/storefront/ProductCard.astro +20 -6
- package/apps/storefront/src/components/catalog/storefront/islands/ImageGallery.tsx +17 -6
- package/apps/storefront/src/components/compliance/storefront/islands/CheckoutComplianceGate.tsx +1 -32
- package/apps/storefront/src/config/compliance/rulesets.ts +1 -1
- package/apps/storefront/src/layouts/Layout.astro +17 -0
- package/apps/storefront/src/lib/access/auth/agentRoles.ts +20 -0
- package/apps/storefront/src/lib/access/auth/agentSessionGate.ts +32 -8
- package/apps/storefront/src/lib/access/auth/brokerAssertion.ts +16 -2
- package/apps/storefront/src/lib/access/auth/contactReaderAuthority.ts +39 -0
- package/apps/storefront/src/lib/access/auth/loginGate.ts +15 -17
- package/apps/storefront/src/lib/access/dashboard/staffAdmission.ts +5 -0
- package/apps/storefront/src/lib/access/dashboard/tenantSelection.ts +2 -0
- package/apps/storefront/src/lib/access/shared/capability.ts +14 -6
- package/apps/storefront/src/lib/access/shared/generated/capabilityCatalog.generated.ts +161 -0
- package/apps/storefront/src/lib/activity/activityScope.ts +36 -0
- package/apps/storefront/src/lib/activity/recordActivity.ts +23 -1
- package/apps/storefront/src/lib/activity/serverFanOut.ts +31 -0
- package/apps/storefront/src/lib/activity/store.ts +9 -3
- package/apps/storefront/src/lib/checkout/commerce/cardCartForm.ts +2 -0
- package/apps/storefront/src/lib/checkout/commerce/cartSession.ts +109 -12
- package/apps/storefront/src/lib/checkout/commerce/checkoutHandoffRoute.ts +53 -25
- package/apps/storefront/src/lib/checkout/commerce/finalCartAuthorization.ts +48 -6
- package/apps/storefront/src/lib/checkout/proposal/cartProposal.ts +388 -0
- package/apps/storefront/src/lib/checkout/proposal/listMatcher.ts +149 -0
- package/apps/storefront/src/lib/checkout/proposal/proposalRoutes.ts +447 -0
- package/apps/storefront/src/lib/checkout/proposal/reviewHtml.ts +100 -0
- package/apps/storefront/src/lib/compliance/browser/checkoutVerificationFlow.ts +26 -2
- package/apps/storefront/src/lib/content/shared/redirects.ts +21 -4
- package/apps/storefront/src/lib/publication/shared/edgeCache.ts +5 -2
- package/apps/storefront/src/lib/publication/shared/previewAnnotations/renderDecorator.ts +15 -8
- package/apps/storefront/src/lib/publication/shared/runtimeEnv.ts +1 -1
- package/apps/storefront/src/middleware/controlPlane.ts +15 -1
- package/apps/storefront/src/middleware/index.ts +7 -3
- package/apps/storefront/src/middleware/renderChain.ts +46 -33
- package/apps/storefront/src/pages/api/cart-proposal/confirm.ts +12 -0
- package/apps/storefront/src/pages/api/cart-proposal/review.ts +26 -0
- package/apps/storefront/src/pages/api/commerce/final-cart-authorization.ts +29 -6
- package/apps/storefront/src/pages/api/compliance/preflight.ts +25 -1
- package/apps/storefront/src/pages/products/[handle].astro +2 -15
- package/apps/storefront/tsconfig.astro.json +11 -0
- package/package.json +1 -1
- package/packages/public-runtime/src/activity/README.md +12 -0
- package/packages/public-runtime/src/activity/catalog.ts +7 -0
- package/packages/public-runtime/src/activity/event.ts +19 -0
- package/packages/public-runtime/src/activity/redaction.ts +31 -2
- package/packages/public-runtime/src/catalog-files.ts +3 -2
- package/packages/public-runtime/src/checkout-orders.ts +18 -19
- package/packages/public-runtime/src/checkout.ts +70 -0
- package/packages/public-runtime/src/compliance/evaluate.ts +60 -1
- package/packages/public-runtime/src/compliance/index.ts +1 -1
- package/packages/public-runtime/src/compliance/pact-report.ts +184 -3
- package/packages/public-runtime/src/compliance/profile.ts +268 -20
- package/packages/public-runtime/src/compliance/ruleset.ts +42 -0
- package/packages/public-runtime/src/customization-runtime.ts +1 -1
- package/packages/public-runtime/src/product.ts +9 -1
- package/packages/public-runtime/src/publication-content-redirects.ts +16 -3
- package/packages/public-runtime/tests/fixtures/compliance-decisions.golden.json +252 -52
- package/pnpm-lock.runner.yaml +0 -15
- package/scripts/tenant/materialize-tenant-content.mjs +3 -0
- package/scripts/tenant/validate.mjs +128 -0
- package/apps/storefront/dev-plugins/dev-publish.mjs +0 -55
- package/apps/storefront/drizzle.config.apps.ts +0 -13
- package/apps/storefront/integrations/preview-annotations-client-bundle.mjs +0 -80
- package/apps/storefront/migrations-apps/0000_fast_millenium_guard.sql +0 -129
- package/apps/storefront/migrations-apps/0001_woozy_lyja.sql +0 -22
- package/apps/storefront/migrations-apps/0002_good_switch.sql +0 -26
- package/apps/storefront/migrations-apps/0003_mute_marauders.sql +0 -12
- package/apps/storefront/migrations-apps/0004_deep_morph.sql +0 -36
- package/apps/storefront/migrations-apps/0005_common_mystique.sql +0 -23
- package/apps/storefront/migrations-apps/0006_broad_microchip.sql +0 -16
- package/apps/storefront/migrations-apps/0007_brave_outlaw_kid.sql +0 -15
- package/apps/storefront/migrations-apps/0008_blue_dazzler.sql +0 -11
- package/apps/storefront/migrations-apps/0009_bored_shinobi_shaw.sql +0 -15
- package/apps/storefront/migrations-apps/0010_ws4_verified_provider_measurement.sql +0 -35
- package/apps/storefront/migrations-apps/0011_dt_tracking_tenant_databases.sql +0 -23
- package/apps/storefront/migrations-apps/0012_test_destinations.sql +0 -29
- package/apps/storefront/migrations-apps/0013_publication_space_editorial.sql +0 -64
- package/apps/storefront/migrations-apps/0014_retire_candidate_ledger.sql +0 -12
- package/apps/storefront/migrations-apps/0015_merchant_calculation_settings.sql +0 -31
- package/apps/storefront/migrations-apps/0016_scrappy_commerce_contract.sql +0 -166
- package/apps/storefront/migrations-apps/0017_commerce_durable_projection.sql +0 -28
- package/apps/storefront/migrations-apps/0018_commerce_provider_cart_identity.sql +0 -13
- package/apps/storefront/migrations-apps/0019_commerce_source_authority.sql +0 -23
- package/apps/storefront/migrations-apps/0020_contact_messages.sql +0 -18
- package/apps/storefront/migrations-apps/0021_contact_vault.sql +0 -166
- package/apps/storefront/migrations-apps/0022_contact_vault_fields.sql +0 -342
- package/apps/storefront/migrations-apps/0023_principal_grant_contacts.sql +0 -15
- package/apps/storefront/migrations-apps/0024_order_contact_erasure_state.sql +0 -22
- package/apps/storefront/migrations-apps/0025_shipment_audit_order_lookup.sql +0 -2
- package/apps/storefront/migrations-apps/0026_fulfillment_assignment.sql +0 -44
- package/apps/storefront/migrations-apps/0027_app_contact_authority.sql +0 -70
- package/apps/storefront/migrations-apps/0028_app_jwk_and_candidates.sql +0 -133
- package/apps/storefront/migrations-apps/0029_inventory_locations_wms.sql +0 -38
- package/apps/storefront/migrations-apps/0030_assignment_split_shipments.sql +0 -149
- package/apps/storefront/migrations-apps/meta/0000_snapshot.json +0 -843
- package/apps/storefront/migrations-apps/meta/0001_snapshot.json +0 -990
- package/apps/storefront/migrations-apps/meta/0002_snapshot.json +0 -1160
- package/apps/storefront/migrations-apps/meta/0003_snapshot.json +0 -1235
- package/apps/storefront/migrations-apps/meta/0004_snapshot.json +0 -1474
- package/apps/storefront/migrations-apps/meta/0005_snapshot.json +0 -1617
- package/apps/storefront/migrations-apps/meta/0006_snapshot.json +0 -1716
- package/apps/storefront/migrations-apps/meta/0007_snapshot.json +0 -1812
- package/apps/storefront/migrations-apps/meta/0008_snapshot.json +0 -1881
- package/apps/storefront/migrations-apps/meta/0009_snapshot.json +0 -1979
- package/apps/storefront/migrations-apps/meta/_journal.json +0 -76
- package/apps/storefront/perf/README.md +0 -64
- package/apps/storefront/perf/assert-budgets.ts +0 -159
- package/apps/storefront/platform-reconcile-tenants.json +0 -3
- package/apps/storefront/playwright.config.ts +0 -23
- package/apps/storefront/public/js/dashboard-access-banner.js +0 -53
- package/apps/storefront/public/js/dashboard-apps.js +0 -183
- package/apps/storefront/public/js/dashboard-contact-capture.js +0 -52
- package/apps/storefront/public/js/dashboard-delegate.js +0 -167
- package/apps/storefront/public/js/dashboard-team.js +0 -356
- package/apps/storefront/public/js/dashboard-vendor-search.js +0 -115
- package/apps/storefront/src/components/content/storefront/AsyncStylesheet.astro +0 -26
- package/apps/storefront/src/components/integrations/storefront/WidgetFrame.astro +0 -34
- package/apps/storefront/src/config/adminTenantLookup.ts +0 -35
- package/apps/storefront/src/config/evidenceTenantRoster.ts +0 -25
- package/apps/storefront/src/config/staffProvisionProjection.ts +0 -24
- package/apps/storefront/src/config/storeName.ts +0 -34
- package/apps/storefront/src/lib/access/admin/README.md +0 -122
- package/apps/storefront/src/lib/access/admin/adminShell.ts +0 -281
- package/apps/storefront/src/lib/access/admin/envelope.ts +0 -9
- package/apps/storefront/src/lib/access/admin/viewmodels/settings.ts +0 -64
- package/apps/storefront/src/lib/access/auth/adminApiGuard.ts +0 -66
- package/apps/storefront/src/lib/access/auth/adminEntry.ts +0 -126
- package/apps/storefront/src/lib/access/auth/mcpClientAssertion.ts +0 -217
- package/apps/storefront/src/lib/access/auth/operatorSession.ts +0 -120
- package/apps/storefront/src/lib/access/dashboard/agentStoreEntry.ts +0 -253
- package/apps/storefront/src/lib/access/dashboard/delegateGate.ts +0 -130
- package/apps/storefront/src/lib/access/dashboard/staffStoreEntry.ts +0 -153
- package/apps/storefront/src/lib/access/dashboard/staffVendorAccess.ts +0 -474
- package/apps/storefront/src/lib/access/dashboard/vendorQuery.ts +0 -61
- package/apps/storefront/src/lib/access/fixtures/settings.ts +0 -67
- package/apps/storefront/src/lib/access/fixtures/tenants.ts +0 -29
- package/apps/storefront/src/lib/access/notifications/magicLinkInviteEmail.ts +0 -62
- package/apps/storefront/src/lib/access/shared/grantContactLookup.ts +0 -97
- package/apps/storefront/src/lib/access/shared/principalGrants.ts +0 -775
- package/apps/storefront/src/lib/activity/alerts.ts +0 -426
- package/apps/storefront/src/lib/activity/candidateSubmitLease.ts +0 -87
- package/apps/storefront/src/lib/activity/changeActorAttribution.ts +0 -181
- package/apps/storefront/src/lib/activity/evidence/evidenceReference.ts +0 -32
- package/apps/storefront/src/lib/activity/fixtures/evidence.ts +0 -99
- package/apps/storefront/src/lib/activity/query.ts +0 -403
- package/apps/storefront/src/lib/activity/uiActor.ts +0 -152
- package/apps/storefront/src/lib/admin/services/mock/index.ts +0 -12
- package/apps/storefront/src/lib/assets/addons/catalog.ts +0 -60
- package/apps/storefront/src/lib/assets/addons/storeEntitlements.ts +0 -260
- package/apps/storefront/src/lib/assets/durableAssetsRoute.ts +0 -65
- package/apps/storefront/src/lib/assets/durableR2.ts +0 -473
- package/apps/storefront/src/lib/assets/durableR2Bindings.ts +0 -33
- package/apps/storefront/src/lib/automation/admin/viewmodels/aiWorkflows.ts +0 -65
- package/apps/storefront/src/lib/automation/ai/approvalMode.ts +0 -20
- package/apps/storefront/src/lib/automation/ai/askEnvelope.ts +0 -47
- package/apps/storefront/src/lib/automation/ai/audit.ts +0 -12
- package/apps/storefront/src/lib/automation/ai/operationalRuns.ts +0 -155
- package/apps/storefront/src/lib/automation/ai/recommendation.ts +0 -20
- package/apps/storefront/src/lib/automation/fixtures/aiWorkflows.ts +0 -59
- package/apps/storefront/src/lib/catalog/admin/catalogSettingsClient.ts +0 -250
- package/apps/storefront/src/lib/catalog/admin/catalogSettingsFields.ts +0 -134
- package/apps/storefront/src/lib/catalog/admin/catalogSettingsPreview.ts +0 -37
- package/apps/storefront/src/lib/catalog/admin/catalogSettingsPricingView.ts +0 -39
- package/apps/storefront/src/lib/catalog/admin/catalogSettingsRuleView.ts +0 -44
- package/apps/storefront/src/lib/catalog/admin/catalogSettingsSkuView.ts +0 -21
- package/apps/storefront/src/lib/catalog/admin/catalogSettingsState.ts +0 -132
- package/apps/storefront/src/lib/catalog/admin/productSetupPhoto.ts +0 -23
- package/apps/storefront/src/lib/catalog/admin/productsTabClient.ts +0 -193
- package/apps/storefront/src/lib/catalog/admin/services/catalogProducts.ts +0 -32
- package/apps/storefront/src/lib/catalog/admin/viewmodels/catalogProducts.ts +0 -164
- package/apps/storefront/src/lib/catalog/admin/viewmodels/products.ts +0 -267
- package/apps/storefront/src/lib/catalog/fixtures/products.ts +0 -105
- package/apps/storefront/src/lib/catalog/tot/syncState.ts +0 -111
- package/apps/storefront/src/lib/checkout/admin/checkoutStyleInput.ts +0 -172
- package/apps/storefront/src/lib/checkout/admin/checkoutStyleTarget.ts +0 -65
- package/apps/storefront/src/lib/checkout/browser/checkoutExciseForm.ts +0 -152
- package/apps/storefront/src/lib/checkout/browser/checkoutRequirementsForm.ts +0 -72
- package/apps/storefront/src/lib/checkout/browser/checkoutStyleForm.ts +0 -110
- package/apps/storefront/src/lib/checkout/browser/settingDraftActions.ts +0 -367
- package/apps/storefront/src/lib/checkout/commerce/checkoutSettings.ts +0 -246
- package/apps/storefront/src/lib/checkout/fixtures/checkoutSettings.ts +0 -77
- package/apps/storefront/src/lib/content/blog/markdown.ts +0 -174
- package/apps/storefront/src/lib/content/chrome/examples/tokenoftrust.chrome-assignments.example.json +0 -6
- package/apps/storefront/src/lib/content/chrome/examples/tokenoftrust.chrome.example.json +0 -79
- package/apps/storefront/src/lib/content/index.ts +0 -27
- package/apps/storefront/src/lib/content/the-build/readingTime.ts +0 -35
- package/apps/storefront/src/lib/content/the-build/toc.ts +0 -95
- package/apps/storefront/src/lib/customers/admin/viewmodels/customers.ts +0 -56
- package/apps/storefront/src/lib/customers/contactVault/blindIndex.ts +0 -28
- package/apps/storefront/src/lib/customers/contactVault/contactAudit.ts +0 -149
- package/apps/storefront/src/lib/customers/contactVault/dataKeys.ts +0 -283
- package/apps/storefront/src/lib/customers/contactVault/fieldEnvelope.ts +0 -88
- package/apps/storefront/src/lib/customers/contactVault/isolateMetrics.ts +0 -37
- package/apps/storefront/src/lib/customers/contactVault/kms.ts +0 -292
- package/apps/storefront/src/lib/customers/contactVault/retention.ts +0 -302
- package/apps/storefront/src/lib/customers/contactVault/retentionPolicy.ts +0 -290
- package/apps/storefront/src/lib/customers/contactVault/zip3.ts +0 -24
- package/apps/storefront/src/lib/customers/fixtures/customers.ts +0 -86
- package/apps/storefront/src/lib/developer-experience/admin/memoizeByEnvelope.ts +0 -27
- package/apps/storefront/src/lib/developer-experience/admin/seed.ts +0 -54
- package/apps/storefront/src/lib/developer-experience/dev/activityIngestToken.ts +0 -85
- package/apps/storefront/src/lib/developer-experience/dev/activityStore.ts +0 -82
- package/apps/storefront/src/lib/developer-experience/dev/agentGrantAttestation.ts +0 -74
- package/apps/storefront/src/lib/developer-experience/dev/ai-widget-client.js +0 -308
- package/apps/storefront/src/lib/developer-experience/dev/apiBase.ts +0 -17
- package/apps/storefront/src/lib/developer-experience/dev/cliSignInCode.ts +0 -124
- package/apps/storefront/src/lib/developer-experience/dev/cockpit/ask.ts +0 -49
- package/apps/storefront/src/lib/developer-experience/dev/cockpit/clickToSource.ts +0 -71
- package/apps/storefront/src/lib/developer-experience/dev/cockpit/copyCommand.ts +0 -227
- package/apps/storefront/src/lib/developer-experience/dev/cockpit/files.ts +0 -249
- package/apps/storefront/src/lib/developer-experience/dev/cockpit/hostedActivity.ts +0 -500
- package/apps/storefront/src/lib/developer-experience/dev/cockpit/infoPopover.ts +0 -12
- package/apps/storefront/src/lib/developer-experience/dev/cockpit/mcpCopy.ts +0 -34
- package/apps/storefront/src/lib/developer-experience/dev/cockpit/monitor.ts +0 -107
- package/apps/storefront/src/lib/developer-experience/dev/cockpit/stepper.ts +0 -116
- package/apps/storefront/src/lib/developer-experience/dev/cockpit/themeToggle.ts +0 -23
- package/apps/storefront/src/lib/developer-experience/dev/livePreview.ts +0 -77
- package/apps/storefront/src/lib/developer-experience/dev/obstacleStore.ts +0 -214
- package/apps/storefront/src/lib/developer-experience/dev/previewStatus.ts +0 -87
- package/apps/storefront/src/lib/developer-experience/dev/rendezvousBroker.ts +0 -226
- package/apps/storefront/src/lib/developer-experience/dev/runtimeStore.ts +0 -291
- package/apps/storefront/src/lib/developer-experience/dev/storeStatus.ts +0 -142
- package/apps/storefront/src/lib/developer-experience/dev/subjectReissue.ts +0 -67
- package/apps/storefront/src/lib/developer-experience/fixtures/regulated-commerce-truth/index.ts +0 -540
- package/apps/storefront/src/lib/developer-experience/fixtures/ws3-readonly-clone-preflight/index.ts +0 -495
- package/apps/storefront/src/lib/engagement/contact/contactMessages.ts +0 -671
- package/apps/storefront/src/lib/engagement/contact/messagesTabClient.ts +0 -175
- package/apps/storefront/src/lib/engagement/contact/submission.ts +0 -112
- package/apps/storefront/src/lib/engagement/messaging/messagesClient.ts +0 -149
- package/apps/storefront/src/lib/engagement/newsletter/digest.ts +0 -117
- package/apps/storefront/src/lib/engagement/newsletter/resendClient.ts +0 -79
- package/apps/storefront/src/lib/engagement/newsletter/send.ts +0 -265
- package/apps/storefront/src/lib/engagement/social/golive.ts +0 -212
- package/apps/storefront/src/lib/engagement/social/notify.ts +0 -32
- package/apps/storefront/src/lib/engagement/social/tokenStore.ts +0 -171
- package/apps/storefront/src/lib/fulfillment/admin/commerceDesk.ts +0 -180
- package/apps/storefront/src/lib/fulfillment/admin/commerceDeskRouting.ts +0 -45
- package/apps/storefront/src/lib/fulfillment/admin/viewmodels/fulfillment.ts +0 -1071
- package/apps/storefront/src/lib/fulfillment/appShipmentEvidence.ts +0 -271
- package/apps/storefront/src/lib/fulfillment/carrierEvidence.ts +0 -105
- package/apps/storefront/src/lib/fulfillment/commerceProjection.ts +0 -157
- package/apps/storefront/src/lib/fulfillment/commerceReadback.ts +0 -60
- package/apps/storefront/src/lib/fulfillment/commerceRecovery.ts +0 -84
- package/apps/storefront/src/lib/fulfillment/commerceRuntime.ts +0 -41
- package/apps/storefront/src/lib/fulfillment/fulfillmentService.ts +0 -2842
- package/apps/storefront/src/lib/fulfillment/readiness.ts +0 -217
- package/apps/storefront/src/lib/fulfillment/splitShipments.ts +0 -388
- package/apps/storefront/src/lib/fulfillment/syntheticPreviewOrders.ts +0 -292
- package/apps/storefront/src/lib/integrations/apps/appContactAuthority.ts +0 -27
- package/apps/storefront/src/lib/integrations/apps/appContactConsents.ts +0 -118
- package/apps/storefront/src/lib/integrations/apps/appInstallEnv.ts +0 -28
- package/apps/storefront/src/lib/integrations/apps/gtmMigrationDraft.ts +0 -103
- package/apps/storefront/src/lib/integrations/apps/inventoryWrite.ts +0 -906
- package/apps/storefront/src/lib/integrations/apps/orders/customerHash.ts +0 -28
- package/apps/storefront/src/lib/integrations/apps/orders/idempotency.ts +0 -100
- package/apps/storefront/src/lib/integrations/apps/reports/salesVelocityReport.ts +0 -96
- package/apps/storefront/src/lib/integrations/apps/routeParams.ts +0 -45
- package/apps/storefront/src/lib/integrations/webhooks/cloudflareQueueDispatcher.ts +0 -82
- package/apps/storefront/src/lib/integrations/webhooks/commercePayloads.ts +0 -159
- package/apps/storefront/src/lib/integrations/webhooks/deliveryEngine.ts +0 -379
- package/apps/storefront/src/lib/integrations/webhooks/deliveryMapper.ts +0 -34
- package/apps/storefront/src/lib/integrations/webhooks/deliveryStore.ts +0 -903
- package/apps/storefront/src/lib/integrations/webhooks/dispatcher.ts +0 -168
- package/apps/storefront/src/lib/integrations/webhooks/emit.ts +0 -245
- package/apps/storefront/src/lib/integrations/webhooks/events.ts +0 -105
- package/apps/storefront/src/lib/integrations/webhooks/getDispatcher.ts +0 -77
- package/apps/storefront/src/lib/integrations/webhooks/orderFulfilledClaim.ts +0 -75
- package/apps/storefront/src/lib/measurement/admin/analyticsRegionPolicy.ts +0 -151
- package/apps/storefront/src/lib/measurement/admin/analyticsRegionsClient.ts +0 -84
- package/apps/storefront/src/lib/measurement/admin/consentSettingsClient.ts +0 -113
- package/apps/storefront/src/lib/measurement/analytics/index.ts +0 -44
- package/apps/storefront/src/lib/measurement/attribution/attributionService.ts +0 -206
- package/apps/storefront/src/lib/measurement/attribution/orderConversionD1.ts +0 -150
- package/apps/storefront/src/lib/measurement/attribution/verifiedProviderMeasurement.ts +0 -118
- package/apps/storefront/src/lib/measurement/tracking/interactionCollector.ts +0 -205
- package/apps/storefront/src/lib/measurement/tracking/pruneRollup.ts +0 -260
- package/apps/storefront/src/lib/measurement/tracking/tenantReadAccess.ts +0 -138
- package/apps/storefront/src/lib/measurement/tracking-writeback/rewriteTrackingIds.ts +0 -175
- package/apps/storefront/src/lib/measurement/tracking-writeback/writebackCandidate.ts +0 -110
- package/apps/storefront/src/lib/observability/diag/capture.ts +0 -162
- package/apps/storefront/src/lib/observability/diag/consoleLine.ts +0 -76
- package/apps/storefront/src/lib/observability/diag/debugConsole.ts +0 -118
- package/apps/storefront/src/lib/observability/diag/debugMode.ts +0 -163
- package/apps/storefront/src/lib/observability/diag/debugWindow.ts +0 -111
- package/apps/storefront/src/lib/observability/diag/redact.ts +0 -17
- package/apps/storefront/src/lib/observability/diag/reference.ts +0 -148
- package/apps/storefront/src/lib/observability/diag/referenceStore.ts +0 -113
- package/apps/storefront/src/lib/observability/diag/report.ts +0 -110
- package/apps/storefront/src/lib/observability/diag/serverResponseTime.ts +0 -91
- package/apps/storefront/src/lib/observability/diag/session.ts +0 -93
- package/apps/storefront/src/lib/observability/monitoring/manifest.ts +0 -301
- package/apps/storefront/src/lib/observability/performance/lighthouseReport.ts +0 -109
- package/apps/storefront/src/lib/observability/performance/rumAlert.ts +0 -179
- package/apps/storefront/src/lib/orders/admin/orderActions.ts +0 -556
- package/apps/storefront/src/lib/orders/admin/orderClient.ts +0 -248
- package/apps/storefront/src/lib/orders/admin/orderSource.ts +0 -410
- package/apps/storefront/src/lib/orders/admin/services/orders.ts +0 -922
- package/apps/storefront/src/lib/orders/admin/viewmodels/orders.ts +0 -135
- package/apps/storefront/src/lib/orders/data/commerceCallerConfig.ts +0 -37
- package/apps/storefront/src/lib/orders/data/ledgerContractOrders.ts +0 -148
- package/apps/storefront/src/lib/orders/data/orderForwardReceiver.ts +0 -532
- package/apps/storefront/src/lib/orders/data/orderMapper.ts +0 -454
- package/apps/storefront/src/lib/orders/data/ordersStore.ts +0 -623
- package/apps/storefront/src/lib/orders/data/sourceAuthorityContract.ts +0 -380
- package/apps/storefront/src/lib/orders/data/sourceAuthorityStore.ts +0 -830
- package/apps/storefront/src/lib/orders/fixtures/orders.ts +0 -186
- package/apps/storefront/src/lib/orders/providers/foxyOrderClient.ts +0 -207
- package/apps/storefront/src/lib/orders/vault/appRecipientRead.ts +0 -222
- package/apps/storefront/src/lib/orders/vault/contactIntake.ts +0 -63
- package/apps/storefront/src/lib/orders/vault/contactRoutes.ts +0 -110
- package/apps/storefront/src/lib/orders/vault/kmsEnv.ts +0 -11
- package/apps/storefront/src/lib/orders/vault/orderContact.ts +0 -96
- package/apps/storefront/src/lib/orders/vault/orderContactVault.ts +0 -1427
- package/apps/storefront/src/lib/orders/vault/vault-test-support.ts +0 -258
- package/apps/storefront/src/lib/publication/d1/schema-apps.ts +0 -808
- package/apps/storefront/src/lib/publication/notifications/candidateConflictEmail.ts +0 -80
- package/apps/storefront/src/lib/publication/servingMode.ts +0 -52
- package/apps/storefront/src/lib/publication/shared/previewAnnotations/moduleAsset.ts +0 -65
- package/apps/storefront/src/lib/publication/shared/routedApiParam.ts +0 -38
- package/apps/storefront/src/lib/reporting/admin/viewmodels/reporting.ts +0 -34
- package/apps/storefront/src/lib/reporting/fixtures/reporting.ts +0 -51
- package/apps/storefront/src/lib/subscriptions/admin/viewmodels/subscriptions.ts +0 -106
- package/apps/storefront/src/lib/subscriptions/fixtures/subscriptions.ts +0 -398
- package/apps/storefront/src/pages/api/admin/activity-alerts.ts +0 -58
- package/apps/storefront/src/pages/api/admin/commerce-readiness.ts +0 -172
- package/apps/storefront/src/pages/api/admin/fulfillment/batches.ts +0 -59
- package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id]/address.ts +0 -66
- package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id].ts +0 -118
- package/apps/storefront/src/pages/api/admin/fulfillment/orders/contact-search.ts +0 -26
- package/apps/storefront/src/pages/api/admin/fulfillment/orders/contacts.ts +0 -22
- package/apps/storefront/src/pages/api/admin/interaction-insights.ts +0 -101
- package/apps/storefront/src/pages/api/admin/orders/[id].ts +0 -63
- package/apps/storefront/src/pages/api/admin/orders.ts +0 -65
- package/apps/storefront/src/pages/api/contact.ts +0 -144
- package/apps/storefront/src/scheduled/contactVaultSweep.ts +0 -113
- package/apps/storefront/src/styles/admin.css +0 -1161
- package/apps/storefront/test/pipeline/fake-preview-services.ts +0 -288
- package/apps/storefront/test/pipeline/harness.ts +0 -209
- package/apps/storefront/test/pipeline/intake-worker.mjs +0 -14
- package/apps/storefront/test/pipeline/matrix-faults.ts +0 -366
- package/apps/storefront/test/pipeline/pipeline-host.ts +0 -418
- package/apps/storefront/test/pipeline/pool-config.cjs +0 -85
- package/apps/storefront/test/pipeline/publish-kinds.ts +0 -279
- package/apps/storefront/test/pipeline/synthetic-job.ts +0 -303
- package/apps/storefront/test/pipeline-faults/matrix-lib.ts +0 -696
- package/apps/storefront/vitest.config.cts +0 -44
- package/apps/storefront/vitest.faults.config.cts +0 -13
- package/apps/storefront/vitest.workers.config.cts +0 -7
- package/packages/feedback/fixtures/v1/expected-findings.json +0 -16
- package/packages/feedback/fixtures/v1/feedback-action/invalid/carries-transport-credential.json +0 -14
- package/packages/feedback/fixtures/v1/feedback-action/invalid/control-char-in-description.json +0 -13
- package/packages/feedback/fixtures/v1/feedback-action/invalid/legacy-schema-version.json +0 -13
- package/packages/feedback/fixtures/v1/feedback-action/invalid/page-path-with-query.json +0 -14
- package/packages/feedback/fixtures/v1/feedback-action/invalid/title-too-short.json +0 -13
- package/packages/feedback/fixtures/v1/feedback-action/valid/element-problem.json +0 -33
- package/packages/feedback/fixtures/v1/feedback-action/valid/page-comment.json +0 -20
- package/packages/feedback/fixtures/v1/feedback-action/valid/region-improvement.json +0 -24
- package/packages/feedback/fixtures/v1/feedback-action/valid/text-selection-feature.json +0 -30
- package/packages/feedback/fixtures/v1/submission-receipt/invalid/accepted-at-not-utc.json +0 -9
- package/packages/feedback/fixtures/v1/submission-receipt/invalid/bad-feedback-id.json +0 -9
- package/packages/feedback/fixtures/v1/submission-receipt/invalid/legacy-contract-version.json +0 -9
- package/packages/feedback/fixtures/v1/submission-receipt/invalid/missing-replayed.json +0 -8
- package/packages/feedback/fixtures/v1/submission-receipt/valid/accepted.json +0 -9
- package/packages/feedback/fixtures/v1/submission-receipt/valid/fractional-seconds.json +0 -9
- package/packages/feedback/fixtures/v1/submission-receipt/valid/replayed.json +0 -9
- package/packages/feedback/fixtures/v1/target-evidence/invalid/page-kind-claims-structure.json +0 -6
- package/packages/feedback/fixtures/v1/target-evidence/invalid/path-too-deep.json +0 -17
- package/packages/feedback/fixtures/v1/target-evidence/invalid/relative-region-out-of-range.json +0 -11
- package/packages/feedback/fixtures/v1/target-evidence/invalid/selector-uses-class.json +0 -7
- package/packages/feedback/fixtures/v1/target-evidence/invalid/source-precision-without-anchor.json +0 -6
- package/packages/feedback/fixtures/v1/target-evidence/valid/element-structure.json +0 -21
- package/packages/feedback/fixtures/v1/target-evidence/valid/host-iframe.json +0 -14
- package/packages/feedback/fixtures/v1/target-evidence/valid/source-anchor.json +0 -12
- package/packages/feedback/fixtures/v1/target-evidence/valid/text-selection.json +0 -26
- package/packages/feedback/package.json +0 -35
- package/packages/feedback/scripts/build-player.mjs +0 -28
- package/packages/feedback/src/index.ts +0 -1
- package/packages/feedback/src/primitives/composer.ts +0 -639
- package/packages/feedback/src/primitives/dialog.ts +0 -263
- package/packages/feedback/src/primitives/hostAdapter.ts +0 -116
- package/packages/feedback/src/primitives/index.ts +0 -10
- package/packages/feedback/src/primitives/launcher.ts +0 -200
- package/packages/feedback/src/primitives/picker.ts +0 -663
- package/packages/feedback/src/primitives/redaction.ts +0 -204
- package/packages/feedback/src/primitives/selection.ts +0 -49
- package/packages/feedback/src/primitives/shiftAccelerator.ts +0 -160
- package/packages/feedback/src/primitives/styles.ts +0 -77
- package/packages/feedback/src/primitives/surface.ts +0 -124
- package/packages/feedback/src/primitives/target.ts +0 -293
- package/packages/feedback/src/tour/canonical.ts +0 -27
- package/packages/feedback/src/tour/index.ts +0 -3
- package/packages/feedback/src/tour/player/browser.ts +0 -5
- package/packages/feedback/src/tour/player/host.ts +0 -12
- package/packages/feedback/src/tour/player/index.ts +0 -205
- package/packages/feedback/src/tour/player/manifest.ts +0 -76
- package/packages/feedback/src/tour/player/player.css +0 -130
- package/packages/feedback/src/tour/player/resolver.ts +0 -12
- package/packages/feedback/src/tour/player/surface.ts +0 -295
- package/packages/feedback/src/tour/player/types.ts +0 -8
- package/packages/feedback/src/tour/resolve/core.ts +0 -267
- package/packages/feedback/src/tour/resolve/dom.ts +0 -115
- package/packages/feedback/src/tour/resolve/index.ts +0 -29
- package/packages/feedback/src/tour/sanitize.ts +0 -76
- package/packages/feedback/src/tour/schema.ts +0 -362
- package/packages/feedback/src/v1/guards.ts +0 -335
- package/packages/feedback/src/v1/index.ts +0 -3
- package/packages/feedback/src/v1/protectedSurfaces.ts +0 -32
- package/packages/feedback/src/v1/types.ts +0 -177
- package/packages/feedback/tsconfig.json +0 -9
- package/packages/feedback/vitest.config.cts +0 -21
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AWS KMS client for the contact vault: GenerateDataKey and Decrypt over fetch, signed with SigV4
|
|
3
|
-
* through Web Crypto (no SDK). Every call carries the EncryptionContext {tenantId, stage, purpose}
|
|
4
|
-
* the environment key's IAM policy requires, and Decrypt pins KeyId to the ARN recorded with the
|
|
5
|
-
* wrapped key.
|
|
6
|
-
*
|
|
7
|
-
* The credential is the `CONTACT_VAULT_KMS` Worker secret: JSON
|
|
8
|
-
* `{ accessKeyId, secretAccessKey, sessionToken?, region, keyArn }`. Any non-2xx answer, timeout,
|
|
9
|
-
* network error or malformed response throws {@link VaultKeyUnavailableError}. Errors carry the
|
|
10
|
-
* fixed code only — never a credential, key byte, blob or response body.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export type DataKeyPurpose = "order-contact" | "contact-message" | "blind-index";
|
|
14
|
-
export type VaultStage = "preview" | "publication";
|
|
15
|
-
|
|
16
|
-
export interface EncryptionContext {
|
|
17
|
-
tenantId: string;
|
|
18
|
-
stage: VaultStage;
|
|
19
|
-
purpose: DataKeyPurpose;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface KmsCredential {
|
|
23
|
-
accessKeyId: string;
|
|
24
|
-
secretAccessKey: string;
|
|
25
|
-
sessionToken?: string;
|
|
26
|
-
region: string;
|
|
27
|
-
keyArn: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface GeneratedDataKey {
|
|
31
|
-
/** 32 plaintext key bytes. The caller imports and then zeroes them. */
|
|
32
|
-
plaintext: Uint8Array;
|
|
33
|
-
/** Base64 CiphertextBlob: the only form that is stored. */
|
|
34
|
-
ciphertextBlob: string;
|
|
35
|
-
keyArn: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface KmsClient {
|
|
39
|
-
generateDataKey(ctx: EncryptionContext): Promise<GeneratedDataKey>;
|
|
40
|
-
decrypt(ciphertextBlob: string, ctx: EncryptionContext, keyArn: string): Promise<Uint8Array>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export class VaultKeyUnavailableError extends Error {
|
|
44
|
-
readonly code = "vault-key-unavailable";
|
|
45
|
-
constructor() {
|
|
46
|
-
super("vault-key-unavailable");
|
|
47
|
-
this.name = "VaultKeyUnavailableError";
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const PURPOSES: ReadonlySet<string> = new Set(["order-contact", "contact-message", "blind-index"]);
|
|
52
|
-
const STAGES: ReadonlySet<string> = new Set(["preview", "publication"]);
|
|
53
|
-
const CREDENTIAL_KEYS: ReadonlySet<string> = new Set(["accessKeyId", "secretAccessKey", "sessionToken", "region", "keyArn"]);
|
|
54
|
-
const ACCESS_KEY_ID = /^[A-Z0-9]{16,128}$/;
|
|
55
|
-
const SECRET = /^[\x21-\x7e]{16,256}$/;
|
|
56
|
-
const SESSION_TOKEN = /^[\x21-\x7e]{16,4096}$/;
|
|
57
|
-
const REGION = /^[a-z]{2}(-[a-z]+)+-\d{1,2}$/;
|
|
58
|
-
const KEY_ARN = /^arn:aws(-[a-z]+)*:kms:([a-z]{2}(-[a-z]+)+-\d{1,2}):\d{12}:key\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|mrk-[0-9a-f]{32})$/;
|
|
59
|
-
const BASE64 = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
60
|
-
const DATA_KEY_BYTES = 32;
|
|
61
|
-
const encoder = new TextEncoder();
|
|
62
|
-
|
|
63
|
-
export function base64ToBytes(value: string): Uint8Array | null {
|
|
64
|
-
if (value.length % 4 !== 0 || !BASE64.test(value)) return null;
|
|
65
|
-
let binary: string;
|
|
66
|
-
try {
|
|
67
|
-
binary = atob(value);
|
|
68
|
-
} catch (error) {
|
|
69
|
-
if (error instanceof DOMException && error.name === "InvalidCharacterError") return null;
|
|
70
|
-
throw error;
|
|
71
|
-
}
|
|
72
|
-
const out = new Uint8Array(binary.length);
|
|
73
|
-
for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
|
|
74
|
-
return out;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function bytesToBase64(bytes: Uint8Array): string {
|
|
78
|
-
let binary = "";
|
|
79
|
-
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
80
|
-
return btoa(binary);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function hex(bytes: ArrayBuffer | Uint8Array): string {
|
|
84
|
-
return [...new Uint8Array(bytes)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** Lowercase hex SHA-256 of a UTF-8 string. */
|
|
88
|
-
export async function sha256Hex(value: string): Promise<string> {
|
|
89
|
-
return hex(await crypto.subtle.digest("SHA-256", encoder.encode(value) as BufferSource));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async function hmac(key: Uint8Array, data: string): Promise<Uint8Array> {
|
|
93
|
-
const imported = await crypto.subtle.importKey("raw", key as BufferSource, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
94
|
-
return new Uint8Array(await crypto.subtle.sign("HMAC", imported, encoder.encode(data) as BufferSource));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** The KMS key's region, read from its ARN, or null when the ARN is not a KMS key ARN. */
|
|
98
|
-
function keyArnRegion(arn: string): string | null {
|
|
99
|
-
const match = KEY_ARN.exec(arn);
|
|
100
|
-
return match ? match[2] ?? null : null;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** Parse the credential secret, or null when it is absent or malformed in any way. */
|
|
104
|
-
export function parseKmsCredential(raw: string | undefined | null): KmsCredential | null {
|
|
105
|
-
if (typeof raw !== "string" || raw.trim() === "") return null;
|
|
106
|
-
let parsed: unknown;
|
|
107
|
-
try {
|
|
108
|
-
parsed = JSON.parse(raw);
|
|
109
|
-
} catch (error) {
|
|
110
|
-
if (error instanceof SyntaxError) return null;
|
|
111
|
-
throw error;
|
|
112
|
-
}
|
|
113
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
114
|
-
const record = parsed as Record<string, unknown>;
|
|
115
|
-
if (Object.keys(record).some((key) => !CREDENTIAL_KEYS.has(key))) return null;
|
|
116
|
-
const { accessKeyId, secretAccessKey, sessionToken, region, keyArn } = record;
|
|
117
|
-
if (typeof accessKeyId !== "string" || !ACCESS_KEY_ID.test(accessKeyId)) return null;
|
|
118
|
-
if (typeof secretAccessKey !== "string" || !SECRET.test(secretAccessKey)) return null;
|
|
119
|
-
if (sessionToken !== undefined && (typeof sessionToken !== "string" || !SESSION_TOKEN.test(sessionToken))) return null;
|
|
120
|
-
if (typeof region !== "string" || !REGION.test(region)) return null;
|
|
121
|
-
if (typeof keyArn !== "string" || keyArnRegion(keyArn) !== region) return null;
|
|
122
|
-
return {
|
|
123
|
-
accessKeyId,
|
|
124
|
-
secretAccessKey,
|
|
125
|
-
...(sessionToken === undefined ? {} : { sessionToken }),
|
|
126
|
-
region,
|
|
127
|
-
keyArn,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface SignatureV4Input {
|
|
132
|
-
method: string;
|
|
133
|
-
/** Absolute URL. Its path must already be in canonical form (KMS always uses "/"). */
|
|
134
|
-
url: string;
|
|
135
|
-
/** Headers to sign; `host` is derived from the URL. Names are matched case-insensitively. */
|
|
136
|
-
headers: Readonly<Record<string, string>>;
|
|
137
|
-
body: string;
|
|
138
|
-
region: string;
|
|
139
|
-
service: string;
|
|
140
|
-
accessKeyId: string;
|
|
141
|
-
secretAccessKey: string;
|
|
142
|
-
sessionToken?: string;
|
|
143
|
-
/** ISO basic UTC timestamp, `YYYYMMDDTHHMMSSZ`. */
|
|
144
|
-
amzDate: string;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export interface SignatureV4Result {
|
|
148
|
-
/** Every signed header (lowercase names), `host` included, plus `authorization`. */
|
|
149
|
-
headers: Record<string, string>;
|
|
150
|
-
canonicalRequest: string;
|
|
151
|
-
stringToSign: string;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function rfc3986(value: string): string {
|
|
155
|
-
return encodeURIComponent(value).replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/** Pure SigV4 signer (AWS Signature Version 4, header form). */
|
|
159
|
-
export async function signRequestV4(input: SignatureV4Input): Promise<SignatureV4Result> {
|
|
160
|
-
const url = new URL(input.url);
|
|
161
|
-
const date = input.amzDate.slice(0, 8);
|
|
162
|
-
const headers: Record<string, string> = {};
|
|
163
|
-
for (const [name, value] of Object.entries(input.headers)) headers[name.toLowerCase()] = value.trim().replace(/\s+/g, " ");
|
|
164
|
-
headers.host = url.host;
|
|
165
|
-
headers["x-amz-date"] = input.amzDate;
|
|
166
|
-
if (input.sessionToken !== undefined) headers["x-amz-security-token"] = input.sessionToken;
|
|
167
|
-
const names = Object.keys(headers).sort();
|
|
168
|
-
const signedHeaders = names.join(";");
|
|
169
|
-
const query = [...url.searchParams.entries()]
|
|
170
|
-
.map(([name, value]) => [rfc3986(name), rfc3986(value)] as const)
|
|
171
|
-
.sort(([a, av], [b, bv]) => (a < b ? -1 : a > b ? 1 : av < bv ? -1 : av > bv ? 1 : 0))
|
|
172
|
-
.map(([name, value]) => `${name}=${value}`)
|
|
173
|
-
.join("&");
|
|
174
|
-
const canonicalRequest = [
|
|
175
|
-
input.method.toUpperCase(),
|
|
176
|
-
url.pathname || "/",
|
|
177
|
-
query,
|
|
178
|
-
names.map((name) => `${name}:${headers[name]}\n`).join(""),
|
|
179
|
-
signedHeaders,
|
|
180
|
-
await sha256Hex(input.body),
|
|
181
|
-
].join("\n");
|
|
182
|
-
const scope = `${date}/${input.region}/${input.service}/aws4_request`;
|
|
183
|
-
const stringToSign = ["AWS4-HMAC-SHA256", input.amzDate, scope, await sha256Hex(canonicalRequest)].join("\n");
|
|
184
|
-
const kDate = await hmac(encoder.encode(`AWS4${input.secretAccessKey}`), date);
|
|
185
|
-
const kRegion = await hmac(kDate, input.region);
|
|
186
|
-
const kService = await hmac(kRegion, input.service);
|
|
187
|
-
const kSigning = await hmac(kService, "aws4_request");
|
|
188
|
-
const signature = hex(await hmac(kSigning, stringToSign));
|
|
189
|
-
headers.authorization = `AWS4-HMAC-SHA256 Credential=${input.accessKeyId}/${scope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;
|
|
190
|
-
return { headers, canonicalRequest, stringToSign };
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function amzDate(now: Date): string {
|
|
194
|
-
return now.toISOString().replace(/[-:]/g, "").replace(/\.\d{3}/, "");
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function validContext(ctx: EncryptionContext): boolean {
|
|
198
|
-
return typeof ctx.tenantId === "string" && ctx.tenantId !== ""
|
|
199
|
-
&& STAGES.has(ctx.stage) && PURPOSES.has(ctx.purpose);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/** Decode a response's Plaintext as exactly one 32-byte data key, or throw. */
|
|
203
|
-
function dataKeyBytes(value: unknown): Uint8Array {
|
|
204
|
-
const bytes = typeof value === "string" ? base64ToBytes(value) : null;
|
|
205
|
-
if (!bytes || bytes.length !== DATA_KEY_BYTES) {
|
|
206
|
-
bytes?.fill(0);
|
|
207
|
-
throw new VaultKeyUnavailableError();
|
|
208
|
-
}
|
|
209
|
-
return bytes;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* A KMS client bound to one credential. `now` is injectable so tests can pin the signing date.
|
|
214
|
-
*/
|
|
215
|
-
export function createKmsClient(
|
|
216
|
-
cred: KmsCredential | null,
|
|
217
|
-
fetchImpl: typeof fetch = fetch,
|
|
218
|
-
timeoutMs = 3000,
|
|
219
|
-
now: () => Date = () => new Date(),
|
|
220
|
-
): KmsClient {
|
|
221
|
-
async function call(target: "GenerateDataKey" | "Decrypt", payload: Record<string, unknown>): Promise<Record<string, unknown>> {
|
|
222
|
-
if (!cred) throw new VaultKeyUnavailableError();
|
|
223
|
-
const url = `https://kms.${cred.region}.amazonaws.com/`;
|
|
224
|
-
const body = JSON.stringify(payload);
|
|
225
|
-
const signed = await signRequestV4({
|
|
226
|
-
method: "POST",
|
|
227
|
-
url,
|
|
228
|
-
headers: { "content-type": "application/x-amz-json-1.1", "x-amz-target": `TrentService.${target}` },
|
|
229
|
-
body,
|
|
230
|
-
region: cred.region,
|
|
231
|
-
service: "kms",
|
|
232
|
-
accessKeyId: cred.accessKeyId,
|
|
233
|
-
secretAccessKey: cred.secretAccessKey,
|
|
234
|
-
...(cred.sessionToken === undefined ? {} : { sessionToken: cred.sessionToken }),
|
|
235
|
-
amzDate: amzDate(now()),
|
|
236
|
-
});
|
|
237
|
-
// fetch derives Host from the URL; it was signed with that same value.
|
|
238
|
-
const sendHeaders = { ...signed.headers };
|
|
239
|
-
delete sendHeaders.host;
|
|
240
|
-
const controller = new AbortController();
|
|
241
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
242
|
-
try {
|
|
243
|
-
const response = await fetchImpl(url, { method: "POST", headers: sendHeaders, body, signal: controller.signal });
|
|
244
|
-
if (!response.ok) {
|
|
245
|
-
await response.body?.cancel();
|
|
246
|
-
throw new VaultKeyUnavailableError();
|
|
247
|
-
}
|
|
248
|
-
const parsed: unknown = JSON.parse(await response.text());
|
|
249
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new VaultKeyUnavailableError();
|
|
250
|
-
return parsed as Record<string, unknown>;
|
|
251
|
-
} catch {
|
|
252
|
-
// Network failure, abort, unreadable body or malformed JSON: one fixed code, no detail.
|
|
253
|
-
throw new VaultKeyUnavailableError();
|
|
254
|
-
} finally {
|
|
255
|
-
clearTimeout(timer);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
return {
|
|
260
|
-
async generateDataKey(ctx) {
|
|
261
|
-
if (!cred || !validContext(ctx)) throw new VaultKeyUnavailableError();
|
|
262
|
-
const result = await call("GenerateDataKey", {
|
|
263
|
-
KeyId: cred.keyArn,
|
|
264
|
-
KeySpec: "AES_256",
|
|
265
|
-
EncryptionContext: { tenantId: ctx.tenantId, stage: ctx.stage, purpose: ctx.purpose },
|
|
266
|
-
});
|
|
267
|
-
const plaintext = dataKeyBytes(result.Plaintext);
|
|
268
|
-
const blob = result.CiphertextBlob;
|
|
269
|
-
if (typeof blob !== "string" || !base64ToBytes(blob) || result.KeyId !== cred.keyArn) {
|
|
270
|
-
plaintext.fill(0);
|
|
271
|
-
throw new VaultKeyUnavailableError();
|
|
272
|
-
}
|
|
273
|
-
return { plaintext, ciphertextBlob: blob, keyArn: cred.keyArn };
|
|
274
|
-
},
|
|
275
|
-
async decrypt(ciphertextBlob, ctx, keyArn) {
|
|
276
|
-
if (!cred || !validContext(ctx) || keyArnRegion(keyArn) !== cred.region ||!base64ToBytes(ciphertextBlob)) {
|
|
277
|
-
throw new VaultKeyUnavailableError();
|
|
278
|
-
}
|
|
279
|
-
const result = await call("Decrypt", {
|
|
280
|
-
CiphertextBlob: ciphertextBlob,
|
|
281
|
-
KeyId: keyArn,
|
|
282
|
-
EncryptionContext: { tenantId: ctx.tenantId, stage: ctx.stage, purpose: ctx.purpose },
|
|
283
|
-
});
|
|
284
|
-
const plaintext = dataKeyBytes(result.Plaintext);
|
|
285
|
-
if (result.KeyId !== keyArn) {
|
|
286
|
-
plaintext.fill(0);
|
|
287
|
-
throw new VaultKeyUnavailableError();
|
|
288
|
-
}
|
|
289
|
-
return plaintext;
|
|
290
|
-
},
|
|
291
|
-
};
|
|
292
|
-
}
|
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Contact vault retention arithmetic over the declared rule table (retentionPolicy.ts).
|
|
3
|
-
*
|
|
4
|
-
* Every sealed order carries, per field group:
|
|
5
|
-
* - `ceiling`: the latest instant any applicable rule could require (the terminal-relative
|
|
6
|
-
* fulfillment rule counted at its cap). Immutable while the group is sealed; bound into the AAD.
|
|
7
|
-
* - `expiresAt`: the effective expiry. Starts at the value derived from the current terminal time
|
|
8
|
-
* and only ever shrinks, never above the ceiling and never below `floorUntil`.
|
|
9
|
-
* - `floorUntil`: the latest end of the floor rules that applied at seal, or null. Immutable.
|
|
10
|
-
* - `rule`: the id of the rule that set the seal-time expiry.
|
|
11
|
-
*
|
|
12
|
-
* Preview rows run the same rules on a compressed clock: every rule's offset is divided by the
|
|
13
|
-
* policy's `previewTimeScale` (rounded down), and every preview ceiling is clamped to the anchor
|
|
14
|
-
* plus `previewCutoffDays`, past which nothing is admitted. The anchor is placed_at for orders and
|
|
15
|
-
* received_at for messages. A terminal-relative rule measures from the observed terminal instant,
|
|
16
|
-
* which on preview already lies on the compressed clock, so only its duration and cap are scaled.
|
|
17
|
-
*
|
|
18
|
-
* All functions are pure; `now` is always passed in.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
GROUPS,
|
|
23
|
-
RETENTION_POLICY,
|
|
24
|
-
applicableRules,
|
|
25
|
-
ruleVersion,
|
|
26
|
-
type Group,
|
|
27
|
-
type RetentionPolicy,
|
|
28
|
-
type Rule,
|
|
29
|
-
} from "./retentionPolicy.js";
|
|
30
|
-
|
|
31
|
-
export type RetentionStage = "preview" | "publication";
|
|
32
|
-
|
|
33
|
-
const DAY_MS = 86_400_000;
|
|
34
|
-
|
|
35
|
-
const ISO_INSTANT = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:?\d{2})$/;
|
|
36
|
-
|
|
37
|
-
/** A strict ISO instant with an explicit zone and real calendar fields, or null. */
|
|
38
|
-
export function readInstant(value: unknown): Date | null {
|
|
39
|
-
if (typeof value !== "string") return null;
|
|
40
|
-
const match = ISO_INSTANT.exec(value);
|
|
41
|
-
if (!match) return null;
|
|
42
|
-
const [year, month, day, hour, minute, second] = match.slice(1, 7).map((part) => Number(part ?? 0));
|
|
43
|
-
const calendar = new Date(Date.UTC(year!, month! - 1, day!));
|
|
44
|
-
if (calendar.getUTCMonth() !== month! - 1 || calendar.getUTCDate() !== day! || hour! > 23 || minute! > 59 || second! > 59) return null;
|
|
45
|
-
const parsed = new Date(value);
|
|
46
|
-
return Number.isNaN(parsed.getTime()) ? null : parsed;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const STAMP_SUFFIX = /#\d{6,}$/;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* A shipment-audit stamp (`<ISO>#NNNNNN`, the sequence suffix written by the fulfillment service)
|
|
53
|
-
* or a bare ISO instant, read strictly; null otherwise.
|
|
54
|
-
*/
|
|
55
|
-
export function readStampInstant(value: unknown): Date | null {
|
|
56
|
-
if (typeof value !== "string") return null;
|
|
57
|
-
return readInstant(value.replace(STAMP_SUFFIX, ""));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* The order's terminal time (handed off, or a confirmed pending-cancel): the earliest matching
|
|
62
|
-
* shipment-audit stamp with its `#NNNNNN` suffix removed. Bind tenant_id, stage, order_id; read
|
|
63
|
-
* the `at` column with `readStampInstant`.
|
|
64
|
-
*/
|
|
65
|
-
export const TERMINAL_AT_SQL = `SELECT MIN(substr(at, 1, instr(at || '#', '#') - 1)) AS at FROM scrappy_shipment_audit
|
|
66
|
-
WHERE tenant_id = ? AND stage = ? AND order_id = ?
|
|
67
|
-
AND ((kind = 'transition' AND to_state = 'handed_off') OR (kind = 'pending-cancel' AND to_state = 'confirmed'))`;
|
|
68
|
-
|
|
69
|
-
export interface GroupRetention {
|
|
70
|
-
ceiling: string;
|
|
71
|
-
expiresAt: string;
|
|
72
|
-
floorUntil: string | null;
|
|
73
|
-
rule: string;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export type SealRetentionResult =
|
|
77
|
-
| { kind: "refused"; reason: "contact-expired" | "order-time-unreadable" }
|
|
78
|
-
| { kind: "ok"; timeScale: number; ruleVersion: string; groups: Record<Group, GroupRetention> };
|
|
79
|
-
|
|
80
|
-
export interface SealRetentionInput {
|
|
81
|
-
stage: RetentionStage;
|
|
82
|
-
placedAt: Date;
|
|
83
|
-
terminalAt: Date | null;
|
|
84
|
-
shipCountry: string | null;
|
|
85
|
-
shipRegion: string | null;
|
|
86
|
-
regulated: boolean;
|
|
87
|
-
tenantId: string;
|
|
88
|
-
now: Date;
|
|
89
|
-
policy?: RetentionPolicy;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function validDate(value: unknown): value is Date {
|
|
93
|
-
return value instanceof Date && !Number.isNaN(value.getTime());
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function timeScaleFor(stage: RetentionStage, policy: RetentionPolicy): number {
|
|
97
|
-
return stage === "preview" ? policy.previewTimeScale : 1;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function scaled(ms: number, scale: number): number {
|
|
101
|
-
return Math.floor(ms / scale);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function previewCutoffMs(anchorMs: number, policy: RetentionPolicy): number {
|
|
105
|
-
return anchorMs + policy.previewCutoffDays * DAY_MS;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** End of a rule (ms) given the terminal time; `terminalMs` null means not yet terminal. */
|
|
109
|
-
function ruleEnd(rule: Rule, placedMs: number, terminalMs: number | null, scale: number): number {
|
|
110
|
-
const d = rule.duration;
|
|
111
|
-
switch (d.kind) {
|
|
112
|
-
case "days-from-placed":
|
|
113
|
-
return placedMs + scaled(d.days * DAY_MS, scale);
|
|
114
|
-
case "days-after-terminal": {
|
|
115
|
-
const cap = placedMs + scaled(d.capDaysFromPlaced * DAY_MS, scale);
|
|
116
|
-
if (terminalMs === null) return cap;
|
|
117
|
-
return Math.min(terminalMs + scaled(d.days * DAY_MS, scale), cap);
|
|
118
|
-
}
|
|
119
|
-
case "through-nth-full-calendar-year-after-placed": {
|
|
120
|
-
const end = Date.UTC(new Date(placedMs).getUTCFullYear() + d.n + 1, 0, 1);
|
|
121
|
-
return placedMs + scaled(end - placedMs, scale);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/** The latest end a rule could ever require: a terminal-relative rule counts at its cap. */
|
|
127
|
-
function ruleCeiling(rule: Rule, placedMs: number, scale: number): number {
|
|
128
|
-
return ruleEnd(rule, placedMs, null, scale);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function fulfillmentRule(policy: RetentionPolicy): Rule {
|
|
132
|
-
const rule = policy.rules.find((r) => r.groups.length === GROUPS.length && r.duration.kind === "days-after-terminal");
|
|
133
|
-
if (!rule) throw new Error("retention policy has no terminal-relative rule covering every group");
|
|
134
|
-
return rule;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function rulesForGroup(group: Group, rules: readonly Rule[], policy: RetentionPolicy): Rule[] {
|
|
138
|
-
const covering = rules.filter((rule) => rule.groups.includes(group));
|
|
139
|
-
return covering.length > 0 ? covering : [fulfillmentRule(policy)];
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function iso(ms: number): string {
|
|
143
|
-
return new Date(ms).toISOString();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Seal-time retention for every group of an order. Refuses when the inputs are not real instants,
|
|
148
|
-
* when a preview order is at or past its cutoff, or when every group's expiry has already passed.
|
|
149
|
-
*/
|
|
150
|
-
export async function sealRetention(input: SealRetentionInput): Promise<SealRetentionResult> {
|
|
151
|
-
const policy = input.policy ?? RETENTION_POLICY;
|
|
152
|
-
if (!validDate(input.placedAt) || !validDate(input.now) || (input.terminalAt !== null && !validDate(input.terminalAt))) {
|
|
153
|
-
return { kind: "refused", reason: "order-time-unreadable" };
|
|
154
|
-
}
|
|
155
|
-
const nowMs = input.now.getTime();
|
|
156
|
-
const placedMs = input.placedAt.getTime();
|
|
157
|
-
const terminalMs = input.terminalAt ? input.terminalAt.getTime() : null;
|
|
158
|
-
const scale = timeScaleFor(input.stage, policy);
|
|
159
|
-
const cutoff = input.stage === "preview" ? previewCutoffMs(placedMs, policy) : Infinity;
|
|
160
|
-
if (nowMs >= cutoff) return { kind: "refused", reason: "contact-expired" };
|
|
161
|
-
|
|
162
|
-
const rules = applicableRules(
|
|
163
|
-
input.tenantId,
|
|
164
|
-
{ shipCountry: input.shipCountry, shipRegion: input.shipRegion, regulated: input.regulated },
|
|
165
|
-
policy,
|
|
166
|
-
);
|
|
167
|
-
const groups = {} as Record<Group, GroupRetention>;
|
|
168
|
-
let anyLive = false;
|
|
169
|
-
for (const group of GROUPS) {
|
|
170
|
-
const covering = rulesForGroup(group, rules, policy);
|
|
171
|
-
const ceiling = Math.min(cutoff, Math.max(...covering.map((rule) => ruleCeiling(rule, placedMs, scale))));
|
|
172
|
-
const ends = covering.map((rule) => ({ rule, end: ruleEnd(rule, placedMs, terminalMs, scale) }));
|
|
173
|
-
const latest = Math.max(...ends.map((entry) => entry.end));
|
|
174
|
-
const binding = ends.find((entry) => entry.end === latest && entry.rule.floor) ?? ends.find((entry) => entry.end === latest)!;
|
|
175
|
-
const expiresAt = Math.min(latest, ceiling);
|
|
176
|
-
const floors = ends.filter((entry) => entry.rule.floor).map((entry) => entry.end);
|
|
177
|
-
const floorUntil = floors.length > 0 ? Math.min(Math.max(...floors), ceiling) : null;
|
|
178
|
-
if (expiresAt > nowMs) anyLive = true;
|
|
179
|
-
groups[group] = {
|
|
180
|
-
ceiling: iso(ceiling),
|
|
181
|
-
expiresAt: iso(expiresAt),
|
|
182
|
-
floorUntil: floorUntil === null ? null : iso(floorUntil),
|
|
183
|
-
rule: binding.rule.id,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
if (!anyLive) return { kind: "refused", reason: "contact-expired" };
|
|
187
|
-
return { kind: "ok", timeScale: scale, ruleVersion: await ruleVersion(policy), groups };
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export interface RederiveGroupInput {
|
|
191
|
-
group: Group;
|
|
192
|
-
ceiling: string;
|
|
193
|
-
expiresAt: string;
|
|
194
|
-
floorUntil: string | null;
|
|
195
|
-
/** The time scale recorded on the row at seal. */
|
|
196
|
-
timeScale: number;
|
|
197
|
-
stage: RetentionStage;
|
|
198
|
-
placedAt: Date;
|
|
199
|
-
terminalAt: Date | null;
|
|
200
|
-
/** The rules from the current table that apply to this order (`applicableRules`). */
|
|
201
|
-
rules: readonly Rule[];
|
|
202
|
-
policy?: RetentionPolicy;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* The group's new effective expiry under the current table and terminal time: the latest current
|
|
207
|
-
* non-floor rule, raised to the recorded floor, and never above the ceiling or the current expiry.
|
|
208
|
-
* Null when a recorded value is unreadable, so the caller leaves the row unchanged.
|
|
209
|
-
*/
|
|
210
|
-
export function rederiveGroup(input: RederiveGroupInput): string | null {
|
|
211
|
-
const policy = input.policy ?? RETENTION_POLICY;
|
|
212
|
-
const ceiling = readInstant(input.ceiling);
|
|
213
|
-
const current = readInstant(input.expiresAt);
|
|
214
|
-
const floor = input.floorUntil === null ? null : readInstant(input.floorUntil);
|
|
215
|
-
if (!ceiling || !current || (input.floorUntil !== null && !floor)) return null;
|
|
216
|
-
if (!validDate(input.placedAt) || (input.terminalAt !== null && !validDate(input.terminalAt))) return null;
|
|
217
|
-
if (!Number.isInteger(input.timeScale) || input.timeScale < 1) return null;
|
|
218
|
-
const placedMs = input.placedAt.getTime();
|
|
219
|
-
const terminalMs = input.terminalAt ? input.terminalAt.getTime() : null;
|
|
220
|
-
const nonFloor = input.rules.filter((rule) => !rule.floor && rule.groups.includes(input.group));
|
|
221
|
-
const covering = nonFloor.length > 0 ? nonFloor : [fulfillmentRule(policy)];
|
|
222
|
-
let next = Math.max(...covering.map((rule) => ruleEnd(rule, placedMs, terminalMs, input.timeScale)));
|
|
223
|
-
if (floor) next = Math.max(next, floor.getTime());
|
|
224
|
-
next = Math.min(next, ceiling.getTime(), current.getTime());
|
|
225
|
-
if (input.stage === "preview") next = Math.min(next, previewCutoffMs(placedMs, policy));
|
|
226
|
-
return iso(next);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export type MessageRetentionResult =
|
|
230
|
-
| { kind: "refused"; reason: "contact-expired" | "message-time-unreadable" }
|
|
231
|
-
| {
|
|
232
|
-
kind: "ok";
|
|
233
|
-
timeScale: number;
|
|
234
|
-
ruleVersion: string;
|
|
235
|
-
rule: string;
|
|
236
|
-
ceiling: string;
|
|
237
|
-
expiresAt: string;
|
|
238
|
-
/** Preview only: when the whole row is deleted. */
|
|
239
|
-
deleteAt: string | null;
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
export async function messageRetention(input: {
|
|
243
|
-
stage: RetentionStage;
|
|
244
|
-
receivedAt: Date;
|
|
245
|
-
now: Date;
|
|
246
|
-
policy?: RetentionPolicy;
|
|
247
|
-
}): Promise<MessageRetentionResult> {
|
|
248
|
-
const policy = input.policy ?? RETENTION_POLICY;
|
|
249
|
-
if (!validDate(input.receivedAt) || !validDate(input.now)) return { kind: "refused", reason: "message-time-unreadable" };
|
|
250
|
-
const receivedMs = input.receivedAt.getTime();
|
|
251
|
-
const scale = timeScaleFor(input.stage, policy);
|
|
252
|
-
const deleteAt = input.stage === "preview" ? previewCutoffMs(receivedMs, policy) : null;
|
|
253
|
-
const ceiling = Math.min(receivedMs + scaled(policy.message.daysFromReceived * DAY_MS, scale), deleteAt ?? Infinity);
|
|
254
|
-
const nowMs = input.now.getTime();
|
|
255
|
-
if (nowMs >= ceiling || (deleteAt !== null && nowMs >= deleteAt)) return { kind: "refused", reason: "contact-expired" };
|
|
256
|
-
return {
|
|
257
|
-
kind: "ok",
|
|
258
|
-
timeScale: scale,
|
|
259
|
-
ruleVersion: await ruleVersion(policy),
|
|
260
|
-
rule: policy.message.id,
|
|
261
|
-
ceiling: iso(ceiling),
|
|
262
|
-
expiresAt: iso(ceiling),
|
|
263
|
-
deleteAt: deleteAt === null ? null : iso(deleteAt),
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/** True while a group may be read: strictly before both its expiry and its ceiling. */
|
|
268
|
-
export function isGroupReadable(now: Date, expiresAt: string | null, ceiling: string | null): boolean {
|
|
269
|
-
if (!validDate(now)) return false;
|
|
270
|
-
const expires = readInstant(expiresAt);
|
|
271
|
-
const cap = readInstant(ceiling);
|
|
272
|
-
if (!expires || !cap) return false;
|
|
273
|
-
const nowMs = now.getTime();
|
|
274
|
-
return nowMs < expires.getTime() && nowMs < cap.getTime();
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/** When a preview order's row, facts and marker are deleted whole. */
|
|
278
|
-
export function previewDeleteAt(placedAt: Date, policy: RetentionPolicy = RETENTION_POLICY): string {
|
|
279
|
-
return iso(previewCutoffMs(placedAt.getTime(), policy));
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const LEGACY_CONTACT_RETENTION_DAYS = 365;
|
|
283
|
-
const LEGACY_TERMINAL_RETENTION_DAYS = 180;
|
|
284
|
-
|
|
285
|
-
export function notAfterFrom(start: Date): string {
|
|
286
|
-
return iso(start.getTime() + LEGACY_CONTACT_RETENTION_DAYS * DAY_MS);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
export function expiresAtFor(notAfter: string, terminalAt: Date | null): string {
|
|
290
|
-
if (!terminalAt) return notAfter;
|
|
291
|
-
const terminal = terminalExpiryFrom(terminalAt);
|
|
292
|
-
return terminal < notAfter ? terminal : notAfter;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
export function isReadable(now: Date, expiresAt: string, notAfter: string): boolean {
|
|
296
|
-
const at = now.toISOString();
|
|
297
|
-
return at < expiresAt && at < notAfter;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
export function terminalExpiryFrom(at: Date): string {
|
|
301
|
-
return iso(at.getTime() + LEGACY_TERMINAL_RETENTION_DAYS * DAY_MS);
|
|
302
|
-
}
|