@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,808 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Drizzle schema — the source of truth for `STOREFRONT_APPS_DB` *migration
|
|
3
|
-
* generation*. `schema.ts` covers the catalog + customization tables on
|
|
4
|
-
* `CATALOG_DB`; these tables are the storefront-apps registry/webhooks/orders
|
|
5
|
-
* spine and belong to a DEDICATED D1, never the catalog.
|
|
6
|
-
*
|
|
7
|
-
* `drizzle-kit generate --config drizzle.config.apps.ts` diffs this into
|
|
8
|
-
* numbered SQL under `migrations-apps/`, applied by `wrangler d1 migrations
|
|
9
|
-
* apply STOREFRONT_APPS_DB`.
|
|
10
|
-
*/
|
|
11
|
-
import { sqliteTable, text, integer, real, index, uniqueIndex, primaryKey } from "drizzle-orm/sqlite-core";
|
|
12
|
-
|
|
13
|
-
// --- Private Apps registry --------------------------------------------------
|
|
14
|
-
// One install per (app, tenant, env). `installId` is the JWT `sub`.
|
|
15
|
-
// Append-only `app_audit_log` is never pruned by the service layer.
|
|
16
|
-
export const appInstalls = sqliteTable(
|
|
17
|
-
"app_installs",
|
|
18
|
-
{
|
|
19
|
-
installId: text("install_id").primaryKey(),
|
|
20
|
-
appId: text("app_id").notNull(),
|
|
21
|
-
appVersion: text("app_version").notNull(),
|
|
22
|
-
tenantId: text("tenant_id").notNull(),
|
|
23
|
-
env: text("env").notNull(),
|
|
24
|
-
status: text("status").notNull().default("active"),
|
|
25
|
-
scopes: text("scopes").notNull().default("[]"),
|
|
26
|
-
manifest: text("manifest").notNull(),
|
|
27
|
-
webhookEndpoint: text("webhook_endpoint"),
|
|
28
|
-
widgetPlacements: text("widget_placements").notNull().default("[]"),
|
|
29
|
-
installActor: text("install_actor").notNull(),
|
|
30
|
-
// Nullable discriminator keeps the managed-analytics v1 lifecycle on the
|
|
31
|
-
// canonical install row instead of creating a second install authority.
|
|
32
|
-
managedKind: text("managed_kind"),
|
|
33
|
-
managedRevision: integer("managed_revision").notNull().default(0),
|
|
34
|
-
managedActiveRevisionId: text("managed_active_revision_id"),
|
|
35
|
-
// Validated non-live candidate only. Live effects remain in manifest and
|
|
36
|
-
// app_version_snapshots, the registry's established serving authorities.
|
|
37
|
-
managedCandidate: text("managed_candidate"),
|
|
38
|
-
createdAt: text("created_at").notNull(),
|
|
39
|
-
updatedAt: text("updated_at").notNull(),
|
|
40
|
-
},
|
|
41
|
-
(t) => ({
|
|
42
|
-
uqAppInstallsTenantEnv: uniqueIndex("uq_app_installs_app_tenant_env").on(
|
|
43
|
-
t.appId,
|
|
44
|
-
t.tenantId,
|
|
45
|
-
t.env,
|
|
46
|
-
),
|
|
47
|
-
idxAppInstallsTenant: index("idx_app_installs_tenant").on(t.tenantId),
|
|
48
|
-
}),
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
// Server-issued client-credentials for one install. The secret is never stored
|
|
52
|
-
// in plaintext — only its sha256 hash (@tot/public-runtime's `sha256Hex`).
|
|
53
|
-
export const appCredentials = sqliteTable("app_credentials", {
|
|
54
|
-
installId: text("install_id").primaryKey(),
|
|
55
|
-
clientId: text("client_id").notNull().unique(),
|
|
56
|
-
secretHash: text("secret_hash").notNull(),
|
|
57
|
-
secretCreatedAt: text("secret_created_at").notNull(),
|
|
58
|
-
rotatedAt: text("rotated_at"),
|
|
59
|
-
jwksKid: text("jwks_kid").notNull(),
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// Append-only audit trail. `actor` is an opaque id — never email/PII — and
|
|
63
|
-
// `detail` is redacted JSON (never secret material).
|
|
64
|
-
export const appAuditLog = sqliteTable(
|
|
65
|
-
"app_audit_log",
|
|
66
|
-
{
|
|
67
|
-
id: text("id").primaryKey(),
|
|
68
|
-
installId: text("install_id").notNull(),
|
|
69
|
-
tenantId: text("tenant_id").notNull(),
|
|
70
|
-
event: text("event").notNull(),
|
|
71
|
-
actor: text("actor").notNull(),
|
|
72
|
-
traceId: text("trace_id"),
|
|
73
|
-
detail: text("detail").notNull().default("{}"),
|
|
74
|
-
at: text("at").notNull(),
|
|
75
|
-
},
|
|
76
|
-
(t) => ({
|
|
77
|
-
idxAppAuditInstall: index("idx_app_audit_install").on(t.installId),
|
|
78
|
-
}),
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
// Inert reviewed migration suggestions. This is deliberately NOT an install,
|
|
82
|
-
// live effect, revision, or publish authority; conversion requires a separate
|
|
83
|
-
// canonical `app_installs` mutation and drafts can never be enabled.
|
|
84
|
-
export const integrationMigrationDrafts = sqliteTable(
|
|
85
|
-
"integration_migration_drafts",
|
|
86
|
-
{
|
|
87
|
-
draftId: text("draft_id").primaryKey(),
|
|
88
|
-
tenantId: text("tenant_id").notNull(),
|
|
89
|
-
revision: integer("revision").notNull(),
|
|
90
|
-
state: text("state").notNull().default("open"),
|
|
91
|
-
record: text("record").notNull(),
|
|
92
|
-
createdAt: text("created_at").notNull(),
|
|
93
|
-
updatedAt: text("updated_at").notNull(),
|
|
94
|
-
},
|
|
95
|
-
(t) => ({ idxIntegrationMigrationDraftsTenant: index("idx_integration_migration_drafts_tenant").on(t.tenantId, t.createdAt) }),
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
// --- Operational activity timeline ------------------------------------------
|
|
99
|
-
// The low-volume / high-value LIFECYCLE cohort of the actor×action telemetry
|
|
100
|
-
// spine (DECISIONS.md §8). Only actions whose catalog `spec.sinks` include
|
|
101
|
-
// "timeline" land here; the high-volume cohort goes to Cloudflare Analytics
|
|
102
|
-
// Engine (binding `ACTIVITY_ANALYTICS`), and EVERY action also goes to Workers
|
|
103
|
-
// Logs. Reuses the EXISTING STOREFRONT_APPS_DB (precedent: `app_audit_log`
|
|
104
|
-
// above) rather than a new binding — the cohort is small (~50k rows/month at
|
|
105
|
-
// 10× pilot) and the timeline query UI needs point queries + joins + arbitrary
|
|
106
|
-
// retention that Analytics Engine cannot give.
|
|
107
|
-
//
|
|
108
|
-
// `id` is the emitter-minted event UUID and the PRIMARY KEY, so a retried/
|
|
109
|
-
// replayed ingest is idempotent (INSERT OR IGNORE). `tenant_id` is written from
|
|
110
|
-
// the AUTHENTICATED ingest identity, never the client-supplied `scope.tenantId`
|
|
111
|
-
// (see api/activity.ts) — that is the multi-tenant isolation boundary. `payload`
|
|
112
|
-
// is the SERVER-redacted JSON (default-deny allowlist + canary scan re-applied
|
|
113
|
-
// at ingest, never trusting client-side redaction alone). The core columns
|
|
114
|
-
// mirror the `ActivityEvent` envelope's non-payload zone (packages/public-
|
|
115
|
-
// runtime/src/activity/event.ts), flattened for SQL point queries.
|
|
116
|
-
export const activityEvents = sqliteTable(
|
|
117
|
-
"activity_events",
|
|
118
|
-
{
|
|
119
|
-
id: text("id").primaryKey(),
|
|
120
|
-
tenantId: text("tenant_id").notNull(),
|
|
121
|
-
action: text("action").notNull(),
|
|
122
|
-
actorKind: text("actor_kind").notNull(),
|
|
123
|
-
// Opaque, pseudonymized actor id — NEVER raw email/PII (emitter's contract).
|
|
124
|
-
actorId: text("actor_id").notNull(),
|
|
125
|
-
actorRef: text("actor_ref"),
|
|
126
|
-
source: text("source").notNull(),
|
|
127
|
-
status: text("status").notNull(),
|
|
128
|
-
// Low-cardinality error CLASS, never a raw exception message.
|
|
129
|
-
errorClass: text("error_class"),
|
|
130
|
-
durationMs: integer("duration_ms"),
|
|
131
|
-
changeId: text("change_id"),
|
|
132
|
-
traceId: text("trace_id"),
|
|
133
|
-
// Server-redacted payload JSON (args + rendered lanes), default "{}".
|
|
134
|
-
payload: text("payload").notNull().default("{}"),
|
|
135
|
-
// Envelope contract version (ACTIVITY_SCHEMA_VERSION) so a reader can migrate.
|
|
136
|
-
schemaVersion: integer("schema_version").notNull(),
|
|
137
|
-
// Emit-clock ISO-8601 (the event's `at`).
|
|
138
|
-
at: text("at").notNull(),
|
|
139
|
-
// Server receive-clock ISO-8601 (when ingest stored it).
|
|
140
|
-
ingestedAt: text("ingested_at").notNull(),
|
|
141
|
-
},
|
|
142
|
-
(t) => ({
|
|
143
|
-
// The timeline query: a tenant's events newest-first.
|
|
144
|
-
idxActivityTenantAt: index("idx_activity_tenant_at").on(t.tenantId, t.at),
|
|
145
|
-
// Filter a tenant's timeline by action family (dashboards glob the prefix).
|
|
146
|
-
idxActivityTenantAction: index("idx_activity_tenant_action").on(t.tenantId, t.action),
|
|
147
|
-
// Join a change's whole lifecycle span across actions.
|
|
148
|
-
idxActivityChange: index("idx_activity_change").on(t.changeId),
|
|
149
|
-
}),
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
// --- Per-tenant raw-interaction store directory ------------------------------
|
|
153
|
-
// The DIRECTORY of per-tenant D1 databases that hold raw declarative-tracking
|
|
154
|
-
// interaction rows — one database per tenant (`lib/measurement/tracking/interactionSchema.ts`
|
|
155
|
-
// is that database's schema). This table holds NO interaction data: only the
|
|
156
|
-
// `tenant_id → (database_name, database_uuid)` mapping the Worker needs to
|
|
157
|
-
// address a tenant's own database over the D1 REST API, since Worker bindings
|
|
158
|
-
// are static and cannot be created per tenant at runtime.
|
|
159
|
-
//
|
|
160
|
-
// It lives in the SHARED STOREFRONT_APPS_DB on purpose: a directory of tenants
|
|
161
|
-
// is inherently cross-tenant, and keeping it here means the isolation boundary
|
|
162
|
-
// stays exactly one hop — a lookup returns ONE tenant's database handle, and
|
|
163
|
-
// that database contains nothing else. `tenant_id` is the primary key, so one
|
|
164
|
-
// tenant can never map to two databases (and two tenants can never share one).
|
|
165
|
-
//
|
|
166
|
-
// This is the seam the follow-on units read:
|
|
167
|
-
// • `dt-tenant-isolation` — resolves the caller's authorized tenant to
|
|
168
|
-
// exactly one `database_uuid`; a merchant read
|
|
169
|
-
// that is not in their own row cannot be built.
|
|
170
|
-
// • `dt-prune-and-rollup` — ENUMERATES this table to sweep every tenant's
|
|
171
|
-
// 90-day window (`last_pruned_at` / `pruned_rows`
|
|
172
|
-
// are its bookkeeping), and uses `size_bytes` /
|
|
173
|
-
// `size_checked_at` to surface a tenant nearing
|
|
174
|
-
// D1's 10GB per-database ceiling.
|
|
175
|
-
export const trackingTenantDatabases = sqliteTable(
|
|
176
|
-
"tracking_tenant_databases",
|
|
177
|
-
{
|
|
178
|
-
tenantId: text("tenant_id").primaryKey(),
|
|
179
|
-
// The Cloudflare D1 database name, derived deterministically from the tenant
|
|
180
|
-
// id (`lib/measurement/tracking/tenantD1Registry.ts`) — recorded so an operator can find
|
|
181
|
-
// it in the dashboard without re-deriving.
|
|
182
|
-
databaseName: text("database_name").notNull(),
|
|
183
|
-
// The D1 UUID — what the REST data plane actually addresses.
|
|
184
|
-
databaseUuid: text("database_uuid").notNull(),
|
|
185
|
-
// Applied `INTERACTION_SCHEMA_VERSION`; a bump re-applies the DDL per tenant.
|
|
186
|
-
schemaVersion: integer("schema_version").notNull(),
|
|
187
|
-
createdAt: text("created_at").notNull(),
|
|
188
|
-
updatedAt: text("updated_at").notNull(),
|
|
189
|
-
// Bookkeeping for the scheduled prune (written by `dt-prune-and-rollup`).
|
|
190
|
-
lastPrunedAt: text("last_pruned_at"),
|
|
191
|
-
prunedRows: integer("pruned_rows").notNull().default(0),
|
|
192
|
-
// Last observed database size + when, for the 10GB-ceiling warning.
|
|
193
|
-
sizeBytes: integer("size_bytes"),
|
|
194
|
-
sizeCheckedAt: text("size_checked_at"),
|
|
195
|
-
},
|
|
196
|
-
(t) => ({
|
|
197
|
-
// Two tenants sharing one database would defeat the whole structural-
|
|
198
|
-
// isolation claim, so make it impossible at the schema level.
|
|
199
|
-
uqTrackingTenantDatabasesUuid: uniqueIndex("uq_tracking_tenant_databases_uuid").on(
|
|
200
|
-
t.databaseUuid,
|
|
201
|
-
),
|
|
202
|
-
// The prune sweep's work queue: oldest-pruned first.
|
|
203
|
-
idxTrackingTenantDatabasesPruned: index("idx_tracking_tenant_databases_pruned").on(
|
|
204
|
-
t.lastPrunedAt,
|
|
205
|
-
),
|
|
206
|
-
}),
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
// --- Managed-analytics test destinations -------------------------------------
|
|
210
|
-
// A tenant-owned, NON-LIVE-ONLY destination a developer registers to prove
|
|
211
|
-
// exactly-once delivery for a new marketing action before wiring a real vendor
|
|
212
|
-
// adapter (GA4/Meta/Amplitude fire directly to the vendor with no server-side
|
|
213
|
-
// readback). `environment` is never `live` — enforced by the managed-analytics
|
|
214
|
-
// service, not by this table. Deliberately its OWN table, not `app_installs` —
|
|
215
|
-
// this is not an integration install (no adapter, no manifest, no CSP/consent
|
|
216
|
-
// plan); it is a disposable proving fixture for the action registry.
|
|
217
|
-
export const testDestinations = sqliteTable(
|
|
218
|
-
"test_destinations",
|
|
219
|
-
{
|
|
220
|
-
destinationId: text("destination_id").primaryKey(),
|
|
221
|
-
tenantId: text("tenant_id").notNull(),
|
|
222
|
-
environment: text("environment").notNull(),
|
|
223
|
-
createdAt: text("created_at").notNull(),
|
|
224
|
-
},
|
|
225
|
-
(t) => ({
|
|
226
|
-
idxTestDestinationsTenant: index(
|
|
227
|
-
"idx_test_destinations_tenant",
|
|
228
|
-
).on(t.tenantId),
|
|
229
|
-
}),
|
|
230
|
-
);
|
|
231
|
-
|
|
232
|
-
// The delivered-event ledger a test destination reads back. Keyed by
|
|
233
|
-
// (destination_id, event_id): a retried/duplicate delivery of the same event id
|
|
234
|
-
// is `INSERT OR IGNORE`, so the row a caller reads back always reflects the
|
|
235
|
-
// FIRST delivery only — the proof that delivery landed exactly once.
|
|
236
|
-
export const testDestinationDeliveries = sqliteTable(
|
|
237
|
-
"test_destination_deliveries",
|
|
238
|
-
{
|
|
239
|
-
destinationId: text("destination_id").notNull(),
|
|
240
|
-
eventId: text("event_id").notNull(),
|
|
241
|
-
tenantId: text("tenant_id").notNull(),
|
|
242
|
-
actionName: text("action_name").notNull(),
|
|
243
|
-
deliveredAt: text("delivered_at").notNull(),
|
|
244
|
-
},
|
|
245
|
-
(t) => ({
|
|
246
|
-
pk: primaryKey({ columns: [t.destinationId, t.eventId] }),
|
|
247
|
-
idxTestDestinationDeliveriesTenant: index(
|
|
248
|
-
"idx_test_destination_deliveries_tenant",
|
|
249
|
-
).on(t.tenantId),
|
|
250
|
-
}),
|
|
251
|
-
);
|
|
252
|
-
|
|
253
|
-
// --- Publication-space editorial control -----------------------------------
|
|
254
|
-
// Immutable reviewed versions plus one CAS pointer/audit chain per space. The
|
|
255
|
-
// API always derives tenant+space from its authenticated route; the composite
|
|
256
|
-
// keys make cross-tenant aliases impossible in persistence.
|
|
257
|
-
export const publicationSpaceVersions = sqliteTable(
|
|
258
|
-
"publication_space_versions",
|
|
259
|
-
{
|
|
260
|
-
tenantId: text("tenant_id").notNull(),
|
|
261
|
-
spaceId: text("space_id").notNull(),
|
|
262
|
-
versionId: text("version_id").notNull(),
|
|
263
|
-
record: text("record").notNull(),
|
|
264
|
-
},
|
|
265
|
-
(t) => ({ pk: primaryKey({ columns: [t.tenantId, t.spaceId, t.versionId] }) }),
|
|
266
|
-
);
|
|
267
|
-
|
|
268
|
-
export const publicationSpaceReviews = sqliteTable(
|
|
269
|
-
"publication_space_reviews",
|
|
270
|
-
{
|
|
271
|
-
tenantId: text("tenant_id").notNull(),
|
|
272
|
-
spaceId: text("space_id").notNull(),
|
|
273
|
-
versionId: text("version_id").notNull(),
|
|
274
|
-
record: text("record").notNull(),
|
|
275
|
-
},
|
|
276
|
-
(t) => ({
|
|
277
|
-
pk: primaryKey({ columns: [t.tenantId, t.spaceId, t.versionId] }),
|
|
278
|
-
idxTenant: index("idx_publication_space_reviews_tenant").on(t.tenantId, t.spaceId),
|
|
279
|
-
}),
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
export const publicationSpacePointers = sqliteTable(
|
|
283
|
-
"publication_space_pointers",
|
|
284
|
-
{
|
|
285
|
-
tenantId: text("tenant_id").notNull(),
|
|
286
|
-
spaceId: text("space_id").notNull(),
|
|
287
|
-
channel: text("channel").notNull(),
|
|
288
|
-
revision: integer("revision").notNull(),
|
|
289
|
-
record: text("record").notNull(),
|
|
290
|
-
},
|
|
291
|
-
(t) => ({ pk: primaryKey({ columns: [t.tenantId, t.spaceId, t.channel] }) }),
|
|
292
|
-
);
|
|
293
|
-
|
|
294
|
-
export const publicationSpaceTransitions = sqliteTable(
|
|
295
|
-
"publication_space_transitions",
|
|
296
|
-
{
|
|
297
|
-
tenantId: text("tenant_id").notNull(),
|
|
298
|
-
spaceId: text("space_id").notNull(),
|
|
299
|
-
transitionId: text("transition_id").notNull(),
|
|
300
|
-
channel: text("channel").notNull(),
|
|
301
|
-
revision: integer("revision").notNull(),
|
|
302
|
-
record: text("record").notNull(),
|
|
303
|
-
},
|
|
304
|
-
(t) => ({
|
|
305
|
-
pk: primaryKey({ columns: [t.tenantId, t.spaceId, t.transitionId] }),
|
|
306
|
-
uqRevision: uniqueIndex("uq_publication_space_transition_revision").on(
|
|
307
|
-
t.tenantId,
|
|
308
|
-
t.spaceId,
|
|
309
|
-
t.channel,
|
|
310
|
-
t.revision,
|
|
311
|
-
),
|
|
312
|
-
idxTenant: index("idx_publication_space_transitions_tenant").on(
|
|
313
|
-
t.tenantId,
|
|
314
|
-
t.spaceId,
|
|
315
|
-
t.channel,
|
|
316
|
-
),
|
|
317
|
-
}),
|
|
318
|
-
);
|
|
319
|
-
|
|
320
|
-
export const publicationSpaceProjections = sqliteTable(
|
|
321
|
-
"publication_space_projections",
|
|
322
|
-
{
|
|
323
|
-
tenantId: text("tenant_id").notNull(),
|
|
324
|
-
spaceId: text("space_id").notNull(),
|
|
325
|
-
channel: text("channel").notNull(),
|
|
326
|
-
revision: integer("revision").notNull(),
|
|
327
|
-
transitionId: text("transition_id").notNull(),
|
|
328
|
-
operation: text("operation").notNull(),
|
|
329
|
-
provider: text("provider").notNull(),
|
|
330
|
-
status: text("status").notNull().default("pending"),
|
|
331
|
-
attempts: integer("attempts").notNull().default(0),
|
|
332
|
-
lastError: text("last_error"),
|
|
333
|
-
record: text("record").notNull(),
|
|
334
|
-
},
|
|
335
|
-
(t) => ({
|
|
336
|
-
pk: primaryKey({ columns: [t.tenantId, t.spaceId, t.channel, t.revision] }),
|
|
337
|
-
uqTransition: uniqueIndex("uq_publication_space_projection_transition").on(
|
|
338
|
-
t.tenantId, t.spaceId, t.transitionId,
|
|
339
|
-
),
|
|
340
|
-
idxPending: index("idx_publication_space_projections_pending").on(
|
|
341
|
-
t.tenantId, t.status, t.revision,
|
|
342
|
-
),
|
|
343
|
-
}),
|
|
344
|
-
);
|
|
345
|
-
|
|
346
|
-
// --- Webhook event spine ----------------------------------------------------
|
|
347
|
-
// Immutable event log. `id` is the semantic event id we mint — distinct from
|
|
348
|
-
// any per-delivery wire envelope id (see `webhookDeliveries.deliveryId` below).
|
|
349
|
-
export const webhookEvents = sqliteTable("webhook_events", {
|
|
350
|
-
id: text("id").primaryKey(),
|
|
351
|
-
tenantId: text("tenant_id").notNull(),
|
|
352
|
-
topic: text("topic").notNull(),
|
|
353
|
-
dataschemaVersion: text("dataschema_version").notNull(),
|
|
354
|
-
payload: text("payload").notNull(),
|
|
355
|
-
createdAt: text("created_at").notNull(),
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
// One row per (event × target install). `deliveryId` is the on-wire
|
|
359
|
-
// CloudEvents `id` — stable across retries/replays so receivers can dedupe —
|
|
360
|
-
// which is why it, not `eventId`, is the primary key here.
|
|
361
|
-
export const webhookDeliveries = sqliteTable(
|
|
362
|
-
"webhook_deliveries",
|
|
363
|
-
{
|
|
364
|
-
deliveryId: text("delivery_id").primaryKey(),
|
|
365
|
-
// FK to webhookEvents.id, enforced in code only (no SQL FK — repo convention).
|
|
366
|
-
eventId: text("event_id").notNull(),
|
|
367
|
-
installId: text("install_id").notNull(),
|
|
368
|
-
tenantId: text("tenant_id").notNull(),
|
|
369
|
-
topic: text("topic").notNull(),
|
|
370
|
-
state: text("state").notNull().default("pending"),
|
|
371
|
-
attempts: integer("attempts").notNull().default(0),
|
|
372
|
-
lastStatus: integer("last_status"),
|
|
373
|
-
lastErrorClass: text("last_error_class"),
|
|
374
|
-
lastTraceId: text("last_trace_id"),
|
|
375
|
-
nextAttemptAt: text("next_attempt_at"),
|
|
376
|
-
createdAt: text("created_at").notNull(),
|
|
377
|
-
updatedAt: text("updated_at").notNull(),
|
|
378
|
-
},
|
|
379
|
-
(t) => ({
|
|
380
|
-
idxWebhookDeliveriesInstall: index("idx_webhook_deliveries_install").on(t.installId),
|
|
381
|
-
idxWebhookDeliveriesDue: index("idx_webhook_deliveries_due").on(t.state, t.nextAttemptAt),
|
|
382
|
-
}),
|
|
383
|
-
);
|
|
384
|
-
|
|
385
|
-
// Append-only per-HTTP-attempt log, never pruned by the service layer.
|
|
386
|
-
export const webhookDeliveryAttempts = sqliteTable(
|
|
387
|
-
"webhook_delivery_attempts",
|
|
388
|
-
{
|
|
389
|
-
id: text("id").primaryKey(),
|
|
390
|
-
deliveryId: text("delivery_id").notNull(),
|
|
391
|
-
attemptNo: integer("attempt_no").notNull(),
|
|
392
|
-
startedAt: text("started_at").notNull(),
|
|
393
|
-
durationMs: integer("duration_ms"),
|
|
394
|
-
httpStatus: integer("http_status"),
|
|
395
|
-
errorClass: text("error_class"),
|
|
396
|
-
traceId: text("trace_id"),
|
|
397
|
-
},
|
|
398
|
-
(t) => ({
|
|
399
|
-
idxWebhookDeliveryAttemptsDelivery: index("idx_webhook_delivery_attempts_delivery").on(t.deliveryId),
|
|
400
|
-
}),
|
|
401
|
-
);
|
|
402
|
-
|
|
403
|
-
// Rollup, one row per install — mirrors the openapi `InstallHealth` shape.
|
|
404
|
-
// `recentTraceIds` is a capped (~10) JSON array, newest first.
|
|
405
|
-
export const webhookInstallHealth = sqliteTable("webhook_install_health", {
|
|
406
|
-
installId: text("install_id").primaryKey(),
|
|
407
|
-
lastSuccessAt: text("last_success_at"),
|
|
408
|
-
failureStreak: integer("failure_streak").notNull().default(0),
|
|
409
|
-
dlqCount: integer("dlq_count").notNull().default(0),
|
|
410
|
-
lastStatus: integer("last_status"),
|
|
411
|
-
lastErrorClass: text("last_error_class"),
|
|
412
|
-
recentTraceIds: text("recent_trace_ids").notNull().default("[]"),
|
|
413
|
-
updatedAt: text("updated_at").notNull(),
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
// --- Order ingestion --------------------------------------------------------
|
|
417
|
-
// The read-model `ordersStore.ts` diffs incoming Foxy orders against (created
|
|
418
|
-
// → fulfilled transitions, for event emission) and that the
|
|
419
|
-
// attribution route reads from for its cross-tenant ownership
|
|
420
|
-
// check. `(tenantId, externalOrderId)` is the composite PK — same "no
|
|
421
|
-
// synthetic id, the natural key IS the key" style as `customizationVersions`
|
|
422
|
-
// (schema.ts) — no SQL FK to `appAttributions.orderId` (repo convention — code-only).
|
|
423
|
-
export const orders = sqliteTable(
|
|
424
|
-
"orders",
|
|
425
|
-
{
|
|
426
|
-
tenantId: text("tenant_id").notNull(),
|
|
427
|
-
// Foxy's own transaction id — never generated here.
|
|
428
|
-
externalOrderId: text("external_order_id").notNull(),
|
|
429
|
-
env: text("env").notNull(),
|
|
430
|
-
status: text("status").notNull(),
|
|
431
|
-
currency: text("currency").notNull(),
|
|
432
|
-
total: real("total").notNull().default(0),
|
|
433
|
-
subtotal: real("subtotal"),
|
|
434
|
-
// Opaque, stable per (tenant, app-install) — see `orders/customerHash.ts`. Never raw PII.
|
|
435
|
-
customerHash: text("customer_hash"),
|
|
436
|
-
lineItems: text("line_items").notNull().default("[]"),
|
|
437
|
-
createdAt: text("created_at").notNull(),
|
|
438
|
-
updatedAt: text("updated_at").notNull(),
|
|
439
|
-
},
|
|
440
|
-
(t) => ({
|
|
441
|
-
pk: primaryKey({ columns: [t.tenantId, t.externalOrderId] }),
|
|
442
|
-
idxOrdersTenant: index("idx_orders_tenant").on(t.tenantId),
|
|
443
|
-
}),
|
|
444
|
-
);
|
|
445
|
-
|
|
446
|
-
// The idempotency ledger — keyed per
|
|
447
|
-
// `(installId, idempotencyKey)` so a retried write (e.g. attribution POST)
|
|
448
|
-
// replays the stored `responseBody` instead of re-applying the mutation.
|
|
449
|
-
// `bodyHash` (sha256 of the canonical request body) lets a caller re-sending
|
|
450
|
-
// the SAME key with a DIFFERENT body be rejected rather than silently replayed.
|
|
451
|
-
export const idempotencyKeys = sqliteTable(
|
|
452
|
-
"idempotency_keys",
|
|
453
|
-
{
|
|
454
|
-
installId: text("install_id").notNull(),
|
|
455
|
-
idempotencyKey: text("idempotency_key").notNull(),
|
|
456
|
-
bodyHash: text("body_hash").notNull(),
|
|
457
|
-
responseBody: text("response_body").notNull(),
|
|
458
|
-
createdAt: text("created_at").notNull(),
|
|
459
|
-
},
|
|
460
|
-
(t) => ({ pk: primaryKey({ columns: [t.installId, t.idempotencyKey] }) }),
|
|
461
|
-
);
|
|
462
|
-
|
|
463
|
-
// --- Encrypted outbound social OAuth tokens ---------------------------------
|
|
464
|
-
// The ONLY retrievable secret store in this codebase: per-`(tenant, network)`
|
|
465
|
-
// OAuth access/refresh tokens we must REPLAY to X/LinkedIn, so — unlike the
|
|
466
|
-
// one-way-hashed `app_credentials` above — they are stored ENCRYPTED-AT-REST,
|
|
467
|
-
// not hashed. `ciphertext` is AES-GCM(base64) over the JSON token payload and
|
|
468
|
-
// `iv` its per-write 96-bit nonce (base64); the key-encryption-key (KEK) is a
|
|
469
|
-
// Worker env binding (`SOCIAL_TOKEN_KEK`), NEVER a column here — mirroring how
|
|
470
|
-
// every other real secret in this codebase is an env binding, not row data.
|
|
471
|
-
// Composite PK `(tenant_id, network)` is the natural key (same "the natural key
|
|
472
|
-
// IS the key" style as `orders`); a rotate is an INSERT OR REPLACE overwrite.
|
|
473
|
-
// `expires_at` is the token's own OAuth expiry (nullable — long-lived manual
|
|
474
|
-
// creds have none), distinct from the row's `updated_at` bookkeeping clock.
|
|
475
|
-
export const socialTokens = sqliteTable(
|
|
476
|
-
"social_tokens",
|
|
477
|
-
{
|
|
478
|
-
tenantId: text("tenant_id").notNull(),
|
|
479
|
-
network: text("network").notNull(),
|
|
480
|
-
ciphertext: text("ciphertext").notNull(),
|
|
481
|
-
iv: text("iv").notNull(),
|
|
482
|
-
expiresAt: text("expires_at"),
|
|
483
|
-
createdAt: text("created_at").notNull(),
|
|
484
|
-
updatedAt: text("updated_at").notNull(),
|
|
485
|
-
},
|
|
486
|
-
(t) => ({
|
|
487
|
-
pk: primaryKey({ columns: [t.tenantId, t.network] }),
|
|
488
|
-
idxSocialTokensTenant: index("idx_social_tokens_tenant").on(t.tenantId),
|
|
489
|
-
}),
|
|
490
|
-
);
|
|
491
|
-
|
|
492
|
-
// App-owned attribution/commission records (`attribution:write`). `orderId`
|
|
493
|
-
// references `orders.externalOrderId` in code
|
|
494
|
-
// only (no SQL FK, repo convention); the route enforces the cross-tenant
|
|
495
|
-
// ownership check the contract requires before ever writing a row here.
|
|
496
|
-
export const appAttributions = sqliteTable(
|
|
497
|
-
"app_attributions",
|
|
498
|
-
{
|
|
499
|
-
installId: text("install_id").notNull(),
|
|
500
|
-
attributionId: text("attribution_id").notNull(),
|
|
501
|
-
tenantId: text("tenant_id").notNull(),
|
|
502
|
-
orderId: text("order_id").notNull(),
|
|
503
|
-
campaign: text("campaign"),
|
|
504
|
-
referralCode: text("referral_code"),
|
|
505
|
-
commissionAmount: real("commission_amount"),
|
|
506
|
-
commissionCurrency: text("commission_currency"),
|
|
507
|
-
customerHash: text("customer_hash"),
|
|
508
|
-
recordedAt: text("recorded_at").notNull(),
|
|
509
|
-
},
|
|
510
|
-
(t) => ({
|
|
511
|
-
pk: primaryKey({ columns: [t.installId, t.attributionId] }),
|
|
512
|
-
idxAppAttributionsTenantOrder: index("idx_app_attributions_tenant_order").on(t.tenantId, t.orderId),
|
|
513
|
-
}),
|
|
514
|
-
);
|
|
515
|
-
|
|
516
|
-
// --- Newsletter subscribers -------------------------------------------------
|
|
517
|
-
// First-party audience for the blog/newsletter digest, kept in OUR D1 (not a
|
|
518
|
-
// vendor list) so the per-tenant isolation + GDPR data-control invariants stay
|
|
519
|
-
// under our control.
|
|
520
|
-
// `tenantId` is the isolation boundary, written from the resolved host/session
|
|
521
|
-
// — NEVER a client body. Keyed on `(tenant_id, collection, email)` so a tenant
|
|
522
|
-
// with multiple collections (e.g. `blog` + `the-build`) runs independent lists.
|
|
523
|
-
// `token` is an opaque random used for both confirm + one-click unsubscribe
|
|
524
|
-
// links; `consentIpHash` is sha256(ip+salt) — never a raw IP (PII). Timestamps
|
|
525
|
-
// are ISO-8601 text. `status`: pending | confirmed | unsubscribed | bounced.
|
|
526
|
-
export const newsletterSubscribers = sqliteTable(
|
|
527
|
-
"newsletter_subscribers",
|
|
528
|
-
{
|
|
529
|
-
tenantId: text("tenant_id").notNull(),
|
|
530
|
-
collection: text("collection").notNull(),
|
|
531
|
-
email: text("email").notNull(),
|
|
532
|
-
status: text("status").notNull().default("pending"),
|
|
533
|
-
token: text("token").notNull(),
|
|
534
|
-
consentSource: text("consent_source"),
|
|
535
|
-
consentIpHash: text("consent_ip_hash"),
|
|
536
|
-
subscribedAt: text("subscribed_at").notNull(),
|
|
537
|
-
confirmedAt: text("confirmed_at"),
|
|
538
|
-
unsubscribedAt: text("unsubscribed_at"),
|
|
539
|
-
lastSentAt: text("last_sent_at"),
|
|
540
|
-
},
|
|
541
|
-
(t) => ({
|
|
542
|
-
pk: primaryKey({ columns: [t.tenantId, t.collection, t.email] }),
|
|
543
|
-
idxNewsletterTenantCollStatus: index("idx_newsletter_tenant_coll_status").on(
|
|
544
|
-
t.tenantId,
|
|
545
|
-
t.collection,
|
|
546
|
-
t.status,
|
|
547
|
-
),
|
|
548
|
-
}),
|
|
549
|
-
);
|
|
550
|
-
|
|
551
|
-
// --- Contact messages -------------------------------------------------------
|
|
552
|
-
// Visitor messages from a store's contact form, written here FIRST so a message is
|
|
553
|
-
// never lost to a mail failure. `tenantId` comes from the routed tenant and `stage`
|
|
554
|
-
// (preview | publication) from the routed customization environment, never a client
|
|
555
|
-
// body; every read and write is scoped by both. The visitor's name, email, phone and
|
|
556
|
-
// message exist only as a contact vault envelope (`keyId`, `nonce`, `ciphertext`;
|
|
557
|
-
// lib/customers/contactVault/envelope.ts) whose AAD binds tenant, stage, id and `notAfter`.
|
|
558
|
-
// `legacy*` hold plaintext only on rows from before migrations-apps/0021 until they
|
|
559
|
-
// are sealed; triggers refuse writing any of them. `status`: unread | read.
|
|
560
|
-
// `notifyStatus` (pending | sent | failed) and `notifyAttempts` belong to the
|
|
561
|
-
// owner-notification sender. Rows are unreadable and purged at `expiresAt`
|
|
562
|
-
// (`purgeExpiredContactMessages`). Timestamps are ISO-8601 text.
|
|
563
|
-
export const contactMessages = sqliteTable(
|
|
564
|
-
"contact_messages",
|
|
565
|
-
{
|
|
566
|
-
id: text("id").primaryKey(),
|
|
567
|
-
tenantId: text("tenant_id").notNull(),
|
|
568
|
-
stage: text("stage").notNull(),
|
|
569
|
-
keyId: text("key_id"),
|
|
570
|
-
nonce: text("nonce"),
|
|
571
|
-
ciphertext: text("ciphertext"),
|
|
572
|
-
notAfter: text("not_after").notNull(),
|
|
573
|
-
expiresAt: text("expires_at").notNull(),
|
|
574
|
-
pagePath: text("page_path"),
|
|
575
|
-
status: text("status").notNull().default("unread"),
|
|
576
|
-
createdAt: text("created_at").notNull(),
|
|
577
|
-
readAt: text("read_at"),
|
|
578
|
-
notifyStatus: text("notify_status").notNull().default("pending"),
|
|
579
|
-
notifyAttempts: integer("notify_attempts").notNull().default(0),
|
|
580
|
-
legacyName: text("legacy_name"),
|
|
581
|
-
legacyEmail: text("legacy_email"),
|
|
582
|
-
legacyPhone: text("legacy_phone"),
|
|
583
|
-
legacyMessage: text("legacy_message"),
|
|
584
|
-
},
|
|
585
|
-
(t) => ({
|
|
586
|
-
idxContactTenantStageCreated: index("idx_contact_messages_tenant_stage_created").on(t.tenantId, t.stage, t.createdAt),
|
|
587
|
-
idxContactTenantStageStatus: index("idx_contact_messages_tenant_stage_status").on(t.tenantId, t.stage, t.status),
|
|
588
|
-
idxContactExpires: index("idx_contact_messages_expires").on(t.expiresAt),
|
|
589
|
-
}),
|
|
590
|
-
);
|
|
591
|
-
|
|
592
|
-
// Idempotent per-digest send log so a re-triggered digest can't double-send.
|
|
593
|
-
// Keyed on `(tenant_id, collection, digest_id)` (e.g. `the-build-2026-W34`);
|
|
594
|
-
// `postSlugs` is a JSON array of the slugs included in that digest.
|
|
595
|
-
export const newsletterSends = sqliteTable(
|
|
596
|
-
"newsletter_sends",
|
|
597
|
-
{
|
|
598
|
-
tenantId: text("tenant_id").notNull(),
|
|
599
|
-
collection: text("collection").notNull(),
|
|
600
|
-
digestId: text("digest_id").notNull(),
|
|
601
|
-
postSlugs: text("post_slugs").notNull().default("[]"),
|
|
602
|
-
recipientCount: integer("recipient_count").notNull().default(0),
|
|
603
|
-
sentAt: text("sent_at").notNull(),
|
|
604
|
-
},
|
|
605
|
-
(t) => ({ pk: primaryKey({ columns: [t.tenantId, t.collection, t.digestId] }) }),
|
|
606
|
-
);
|
|
607
|
-
|
|
608
|
-
// One active submit per tenant/change. This serializes identity authorization,
|
|
609
|
-
// the Gitea mutation, and audit finalization so a verified callback cannot
|
|
610
|
-
// become stale between its forge read and its KV writes. `expires_at` is
|
|
611
|
-
// diagnostic only; recovery is explicit so a slow live submit cannot be
|
|
612
|
-
// time-fenced incorrectly.
|
|
613
|
-
export const candidateSubmitLeases = sqliteTable(
|
|
614
|
-
"candidate_submit_leases",
|
|
615
|
-
{
|
|
616
|
-
tenantId: text("tenant_id").notNull(),
|
|
617
|
-
changeId: text("change_id").notNull(),
|
|
618
|
-
authorizationId: text("authorization_id").notNull(),
|
|
619
|
-
status: text("status").notNull().default("active"),
|
|
620
|
-
acquiredAt: text("acquired_at").notNull(),
|
|
621
|
-
expiresAt: text("expires_at").notNull(),
|
|
622
|
-
},
|
|
623
|
-
(t) => ({
|
|
624
|
-
pk: primaryKey({ columns: [t.tenantId, t.changeId] }),
|
|
625
|
-
idxExpires: index("idx_candidate_submit_leases_expires").on(t.expiresAt),
|
|
626
|
-
}),
|
|
627
|
-
);
|
|
628
|
-
|
|
629
|
-
// --- Merchant consent configuration -----------------------------------------
|
|
630
|
-
// APPEND-ONLY revision history of a tenant's consent configuration (the
|
|
631
|
-
// ext-admin-03 surface that feeds the ext-policy-03 broker). Each save is a NEW
|
|
632
|
-
// immutable row — the current config is `MAX(revision)` per tenant — so the table
|
|
633
|
-
// IS the audit trail (actor + timestamp per revision, never mutated in place) and
|
|
634
|
-
// a revert is a forward-only new revision that copies a prior `config` and records
|
|
635
|
-
// `reverted_from`. `config` is the JSON `TenantConsentConfig` (never secret-bearing
|
|
636
|
-
// — consent config carries no secrets). `tenant_id` is the isolation boundary,
|
|
637
|
-
// written from the resolved session, never a client body. UNIQUE
|
|
638
|
-
// `(tenant_id, revision)` makes the monotonic revision a schema invariant.
|
|
639
|
-
export const consentConfigRevisions = sqliteTable(
|
|
640
|
-
"consent_config_revisions",
|
|
641
|
-
{
|
|
642
|
-
id: text("id").primaryKey(),
|
|
643
|
-
tenantId: text("tenant_id").notNull(),
|
|
644
|
-
// Monotonic per tenant (1, 2, 3…) — the latest revision is the current config.
|
|
645
|
-
revision: integer("revision").notNull(),
|
|
646
|
-
// The JSON-serialized validated `TenantConsentConfig`.
|
|
647
|
-
config: text("config").notNull(),
|
|
648
|
-
// Opaque actor id — never email/PII (matches `app_audit_log`).
|
|
649
|
-
actor: text("actor").notNull(),
|
|
650
|
-
// Human-legible note (e.g. the reason, or "revert to revision N").
|
|
651
|
-
note: text("note"),
|
|
652
|
-
// When this revision copies an earlier one, the source revision — else null.
|
|
653
|
-
revertedFrom: integer("reverted_from"),
|
|
654
|
-
createdAt: text("created_at").notNull(),
|
|
655
|
-
},
|
|
656
|
-
(t) => ({
|
|
657
|
-
uqConsentConfigTenantRevision: uniqueIndex("uq_consent_config_tenant_revision").on(
|
|
658
|
-
t.tenantId,
|
|
659
|
-
t.revision,
|
|
660
|
-
),
|
|
661
|
-
idxConsentConfigTenant: index("idx_consent_config_tenant").on(t.tenantId),
|
|
662
|
-
}),
|
|
663
|
-
);
|
|
664
|
-
|
|
665
|
-
// Demonstrated CMP demand — one row per `(tenant, adapter)` demand signal. The set
|
|
666
|
-
// of SELECTABLE CMP adapters is DERIVED from these rows (distinct-tenant count over
|
|
667
|
-
// a threshold), never a hardcoded catalog: the first CMP Storefront adapts is
|
|
668
|
-
// whichever real demand first proves (ADR 0014 P2 / 0025). UNIQUE
|
|
669
|
-
// `(tenant_id, adapter_id)` makes demand a per-tenant fact (a tenant re-asking does
|
|
670
|
-
// not inflate the count); the `adapter_id` index serves the per-adapter rollup.
|
|
671
|
-
export const consentCmpDemand = sqliteTable(
|
|
672
|
-
"consent_cmp_demand",
|
|
673
|
-
{
|
|
674
|
-
id: text("id").primaryKey(),
|
|
675
|
-
tenantId: text("tenant_id").notNull(),
|
|
676
|
-
adapterId: text("adapter_id").notNull(),
|
|
677
|
-
// Where the demand came from (a merchant request, a support ticket), for the record.
|
|
678
|
-
source: text("source"),
|
|
679
|
-
at: text("at").notNull(),
|
|
680
|
-
},
|
|
681
|
-
(t) => ({
|
|
682
|
-
uqConsentCmpDemandTenantAdapter: uniqueIndex("uq_consent_cmp_demand_tenant_adapter").on(
|
|
683
|
-
t.tenantId,
|
|
684
|
-
t.adapterId,
|
|
685
|
-
),
|
|
686
|
-
idxConsentCmpDemandAdapter: index("idx_consent_cmp_demand_adapter").on(t.adapterId),
|
|
687
|
-
}),
|
|
688
|
-
);
|
|
689
|
-
|
|
690
|
-
// --- Commerce conversion attribution (ext-commerce-04) -----------------------
|
|
691
|
-
// The single-use ledger for the signed checkout-correlation token's `jti`
|
|
692
|
-
// (`packages/public-runtime/src/integration/correlation-token.ts`). The order join
|
|
693
|
-
// consumes a token EXACTLY once: a replay of a consumed `jti` is refused. `jti` is
|
|
694
|
-
// the natural key (the token's own 96-bit nonce); `expires_at` is the token's Unix-
|
|
695
|
-
// seconds `exp` so a consumed row can be pruned once the token is already `expired`
|
|
696
|
-
// (a past-`exp` token is rejected before the guard is even reached). Carries no PII
|
|
697
|
-
// and no secret — the `jti` is an opaque nonce, never the token or the signing key.
|
|
698
|
-
export const correlationReplay = sqliteTable("correlation_replay", {
|
|
699
|
-
jti: text("jti").primaryKey(),
|
|
700
|
-
expiresAt: integer("expires_at").notNull(),
|
|
701
|
-
consumedAt: text("consumed_at").notNull(),
|
|
702
|
-
});
|
|
703
|
-
|
|
704
|
-
// --- Retained managed-app version facets (ext-apps-02) -----------------------
|
|
705
|
-
// APPEND-ONLY retention of every activated managed-app VERSION's COMPLETE
|
|
706
|
-
// restorable facet set, and the atomic-rollback spine over it. One row per
|
|
707
|
-
// activation of an install; the CURRENT active version is `MAX(seq)` per install
|
|
708
|
-
// (same "the latest row is current" model as `consent_config_revisions`). The
|
|
709
|
-
// whole restorable facet set (code ref/digest, entry module, public config,
|
|
710
|
-
// contributions, granted scopes, consent declaration, CSP origins) is one JSON
|
|
711
|
-
// blob in `facets` — so retaining a version and rolling one back are each a
|
|
712
|
-
// SINGLE-ROW insert: the restore is atomic by construction (you get the whole
|
|
713
|
-
// prior facet set or nothing — never a partial/mixed activation). A rollback is
|
|
714
|
-
// forward-only: it appends a NEW activation copying a retained version's facets
|
|
715
|
-
// and records `restored_from_seq`, so history is never rewritten and the rollback
|
|
716
|
-
// is itself an audited row. `tenant_id` is the isolation boundary, denormalized
|
|
717
|
-
// for tenant-scoped reads (no SQL FK — repo convention). `facets` carries no
|
|
718
|
-
// secret material (proved by the ext-kernel-01 secret scan before insert). UNIQUE
|
|
719
|
-
// `(install_id, seq)` makes the monotonic sequence a schema invariant.
|
|
720
|
-
export const appVersionSnapshots = sqliteTable(
|
|
721
|
-
"app_version_snapshots",
|
|
722
|
-
{
|
|
723
|
-
id: text("id").primaryKey(),
|
|
724
|
-
installId: text("install_id").notNull(),
|
|
725
|
-
tenantId: text("tenant_id").notNull(),
|
|
726
|
-
// Monotonic per install (1, 2, 3…); the largest is the active version.
|
|
727
|
-
seq: integer("seq").notNull(),
|
|
728
|
-
// The app package version this activation serves (mirror of facets.appVersion).
|
|
729
|
-
appVersion: text("app_version").notNull(),
|
|
730
|
-
// The complete restorable facet set as one JSON blob (AppVersionFacets).
|
|
731
|
-
facets: text("facets").notNull(),
|
|
732
|
-
// Opaque actor id — never email/PII (matches `app_audit_log`).
|
|
733
|
-
actor: text("actor").notNull(),
|
|
734
|
-
// Human-legible note (e.g. the reason, or "rollback to version N").
|
|
735
|
-
note: text("note"),
|
|
736
|
-
// When this activation restores an earlier one, its source `seq` — else null.
|
|
737
|
-
restoredFromSeq: integer("restored_from_seq"),
|
|
738
|
-
createdAt: text("created_at").notNull(),
|
|
739
|
-
},
|
|
740
|
-
(t) => ({
|
|
741
|
-
uqAppVersionSnapshotsInstallSeq: uniqueIndex("uq_app_version_snapshots_install_seq").on(
|
|
742
|
-
t.installId,
|
|
743
|
-
t.seq,
|
|
744
|
-
),
|
|
745
|
-
idxAppVersionSnapshotsInstall: index("idx_app_version_snapshots_install").on(t.installId),
|
|
746
|
-
}),
|
|
747
|
-
);
|
|
748
|
-
|
|
749
|
-
// The per-`(tenant, external_order_id)` attribution ledger. An order's attribution is
|
|
750
|
-
// decided ONCE (on its first `order.created`/`order.fulfilled` conversion) and reused
|
|
751
|
-
// for every later lifecycle conversion, so the correlation `jti` is consumed once per
|
|
752
|
-
// order — not once per lifecycle event — and a duplicate/replayed/out-of-order webhook
|
|
753
|
-
// reproduces the same outcome. `attributed` is 0/1; when attributed, `correlation_id`
|
|
754
|
-
// + `correlation_expires_at` hold the shared thread; when not, `reason` records why
|
|
755
|
-
// (missing/expired/context_mismatch/replay/…). Never customer identity — only the
|
|
756
|
-
// opaque correlation handle. `(tenant_id, external_order_id)` is the natural key.
|
|
757
|
-
export const orderAttribution = sqliteTable(
|
|
758
|
-
"order_attribution",
|
|
759
|
-
{
|
|
760
|
-
tenantId: text("tenant_id").notNull(),
|
|
761
|
-
externalOrderId: text("external_order_id").notNull(),
|
|
762
|
-
attributed: integer("attributed").notNull().default(0),
|
|
763
|
-
correlationId: text("correlation_id"),
|
|
764
|
-
correlationExpiresAt: text("correlation_expires_at"),
|
|
765
|
-
reason: text("reason"),
|
|
766
|
-
recordedAt: text("recorded_at").notNull(),
|
|
767
|
-
},
|
|
768
|
-
(t) => ({ pk: primaryKey({ columns: [t.tenantId, t.externalOrderId] }) }),
|
|
769
|
-
);
|
|
770
|
-
|
|
771
|
-
// Merchant pricing and SKU defaults. One current row per tenant is the
|
|
772
|
-
// compare-and-swap target (`revision` must still be the caller's expected
|
|
773
|
-
// value). `merchant_calculation_settings_revisions` is the append-only copy of
|
|
774
|
-
// each accepted save: tenant_id is the isolation boundary, actor is an opaque
|
|
775
|
-
// id, and rows are never updated. Absence of a current row means the merchant
|
|
776
|
-
// has not saved defaults.
|
|
777
|
-
export const merchantCalculationSettings = sqliteTable("merchant_calculation_settings", {
|
|
778
|
-
tenantId: text("tenant_id").primaryKey(),
|
|
779
|
-
revision: integer("revision").notNull(),
|
|
780
|
-
currency: text("currency").notNull(),
|
|
781
|
-
engineVersion: text("engine_version").notNull(),
|
|
782
|
-
pricingJson: text("pricing_json").notNull(),
|
|
783
|
-
skuJson: text("sku_json").notNull(),
|
|
784
|
-
});
|
|
785
|
-
|
|
786
|
-
export const merchantCalculationSettingsRevisions = sqliteTable(
|
|
787
|
-
"merchant_calculation_settings_revisions",
|
|
788
|
-
{
|
|
789
|
-
id: text("id").primaryKey(),
|
|
790
|
-
tenantId: text("tenant_id").notNull(),
|
|
791
|
-
revision: integer("revision").notNull(),
|
|
792
|
-
currency: text("currency").notNull(),
|
|
793
|
-
engineVersion: text("engine_version").notNull(),
|
|
794
|
-
pricingJson: text("pricing_json").notNull(),
|
|
795
|
-
skuJson: text("sku_json").notNull(),
|
|
796
|
-
actor: text("actor").notNull(),
|
|
797
|
-
savedAt: text("saved_at").notNull(),
|
|
798
|
-
},
|
|
799
|
-
(t) => ({
|
|
800
|
-
uqMerchantCalculationSettingsRevision: uniqueIndex("uq_merchant_calculation_settings_revision").on(
|
|
801
|
-
t.tenantId,
|
|
802
|
-
t.revision,
|
|
803
|
-
),
|
|
804
|
-
idxMerchantCalculationSettingsRevisionsTenant: index("idx_merchant_calculation_settings_revisions_tenant").on(
|
|
805
|
-
t.tenantId,
|
|
806
|
-
),
|
|
807
|
-
}),
|
|
808
|
-
);
|