@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,217 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Release and hand-off gates for whole-order fulfillment.
|
|
3
|
-
*
|
|
4
|
-
* Evidence, payment, stock, refund, and cancel are rechecked from stored source
|
|
5
|
-
* truth. Compliance `fresh` is not evidence. A carrier account is tenant
|
|
6
|
-
* configuration: its absence is not a hold, and this module does not select a vendor.
|
|
7
|
-
*/
|
|
8
|
-
import {
|
|
9
|
-
decideCommerceCommand,
|
|
10
|
-
paymentIsCaptured,
|
|
11
|
-
type CommerceEvidence,
|
|
12
|
-
type ComplianceRuleProfile,
|
|
13
|
-
type EvidenceState,
|
|
14
|
-
type FulfillmentState,
|
|
15
|
-
type LabelState,
|
|
16
|
-
type PaymentState,
|
|
17
|
-
type ProviderOutcome,
|
|
18
|
-
type StockState,
|
|
19
|
-
type OrderContactState,
|
|
20
|
-
} from "@tot/public-runtime";
|
|
21
|
-
import type { SourceReadiness } from "../orders/data/sourceAuthorityStore.js";
|
|
22
|
-
import { COMPLIANCE_RULE_PROFILES } from "@/config/compliance/rulesets";
|
|
23
|
-
import {
|
|
24
|
-
CARRIER_CATALOG,
|
|
25
|
-
canonicalCarrier,
|
|
26
|
-
carrierCatalogEntry,
|
|
27
|
-
carrierProhibited,
|
|
28
|
-
type CarrierCatalogEntry,
|
|
29
|
-
type CarrierCode,
|
|
30
|
-
} from "./carrierEvidence.js";
|
|
31
|
-
|
|
32
|
-
export const RELEASE_HOLDS = [
|
|
33
|
-
"source-check-pending",
|
|
34
|
-
"source-ledger-conflict",
|
|
35
|
-
"source-authority-unreadable",
|
|
36
|
-
"source-authority-unavailable",
|
|
37
|
-
"source-sync-pending",
|
|
38
|
-
"evidence-unknown",
|
|
39
|
-
"evidence-stale",
|
|
40
|
-
"evidence-unreadable",
|
|
41
|
-
"evidence-absent",
|
|
42
|
-
"operator-hold",
|
|
43
|
-
"payment-pending",
|
|
44
|
-
"payment-unknown",
|
|
45
|
-
"payment-not-captured",
|
|
46
|
-
"refund-pending",
|
|
47
|
-
"refunded",
|
|
48
|
-
"refund-unknown",
|
|
49
|
-
"cancel-pending",
|
|
50
|
-
"cancelled",
|
|
51
|
-
"stock-unknown",
|
|
52
|
-
"stock-unconfirmed",
|
|
53
|
-
"fulfillment-unknown",
|
|
54
|
-
"ship-to-absent",
|
|
55
|
-
"ship-to-expired",
|
|
56
|
-
"ship-to-erased",
|
|
57
|
-
"ship-to-unreadable",
|
|
58
|
-
] as const;
|
|
59
|
-
|
|
60
|
-
export type ReleaseHold = (typeof RELEASE_HOLDS)[number];
|
|
61
|
-
|
|
62
|
-
export interface CarrierPolicy {
|
|
63
|
-
adultSignatureRequired: boolean;
|
|
64
|
-
/** The tenant's compliance profile enables PACT: only statutorily eligible carriers may carry its parcels. */
|
|
65
|
-
pactEnabled: boolean;
|
|
66
|
-
prohibitedCarriers: readonly string[];
|
|
67
|
-
/** Null when the tenant has not configured an account. Absence is not a hold. */
|
|
68
|
-
carrierAccountId: string | null;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface ReadinessInput {
|
|
72
|
-
shipTo?: OrderContactState;
|
|
73
|
-
sourceHolds?: readonly SourceReadiness[];
|
|
74
|
-
payment: PaymentState;
|
|
75
|
-
stock: StockState;
|
|
76
|
-
fulfillment: FulfillmentState;
|
|
77
|
-
label: LabelState;
|
|
78
|
-
evidence: CommerceEvidence;
|
|
79
|
-
operatorHold: boolean;
|
|
80
|
-
cancelPending: boolean;
|
|
81
|
-
providerOutcome: ProviderOutcome | null;
|
|
82
|
-
adultSignature: "accepted" | "refused" | "absent";
|
|
83
|
-
adultSignatureRequired: boolean;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const EVIDENCE_HOLDS: Record<EvidenceState, ReleaseHold | null> = {
|
|
87
|
-
fresh: null,
|
|
88
|
-
"not-required": null,
|
|
89
|
-
"not-computed": null,
|
|
90
|
-
UNKNOWN: "evidence-unknown",
|
|
91
|
-
stale: "evidence-stale",
|
|
92
|
-
unreadable: "evidence-unreadable",
|
|
93
|
-
absent: "evidence-absent",
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
function add(holds: ReleaseHold[], hold: ReleaseHold | null): void {
|
|
97
|
-
if (hold && !holds.includes(hold)) holds.push(hold);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** Holds that forbid creating a shipment intent. Compliance is not an input. */
|
|
101
|
-
export function releaseHolds(input: ReadinessInput): ReleaseHold[] {
|
|
102
|
-
const holds: ReleaseHold[] = [...(input.sourceHolds ?? [])];
|
|
103
|
-
for (const field of ["verification", "tax", "risk", "stock"] as const) {
|
|
104
|
-
const value = input.evidence[field];
|
|
105
|
-
add(holds, value in EVIDENCE_HOLDS ? EVIDENCE_HOLDS[value as EvidenceState] : "evidence-unreadable");
|
|
106
|
-
}
|
|
107
|
-
if (input.operatorHold) add(holds, "operator-hold");
|
|
108
|
-
if (input.cancelPending) add(holds, "cancel-pending");
|
|
109
|
-
if (input.fulfillment === "cancelled") add(holds, "cancelled");
|
|
110
|
-
if (input.fulfillment === "UNKNOWN") add(holds, "fulfillment-unknown");
|
|
111
|
-
if (input.payment === "pending" || input.payment === "authorized") add(holds, "payment-pending");
|
|
112
|
-
else if (input.payment === "UNKNOWN" || input.payment === "capture_unknown") add(holds, "payment-unknown");
|
|
113
|
-
else if (input.payment === "refund_requested") add(holds, "refund-pending");
|
|
114
|
-
else if (input.payment === "refunded") add(holds, "refunded");
|
|
115
|
-
else if (input.payment === "refund_unknown") add(holds, "refund-unknown");
|
|
116
|
-
else if (input.payment === "voided") add(holds, "cancelled");
|
|
117
|
-
else if (!paymentIsCaptured(input.payment)) add(holds, "payment-not-captured");
|
|
118
|
-
if (input.stock === "UNKNOWN") add(holds, "stock-unknown");
|
|
119
|
-
else if (input.stock !== "confirmed") add(holds, "stock-unconfirmed");
|
|
120
|
-
if (input.shipTo !== "present" && input.shipTo !== "restricted") {
|
|
121
|
-
add(holds, input.shipTo === "absent" ? "ship-to-absent" : input.shipTo === "expired" ? "ship-to-expired" :
|
|
122
|
-
input.shipTo === "erased" ? "ship-to-erased" : "ship-to-unreadable");
|
|
123
|
-
}
|
|
124
|
-
return holds;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function canRelease(input: ReadinessInput): boolean {
|
|
128
|
-
return input.fulfillment === "ready" && releaseHolds(input).length === 0;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function handoffRefusal(input: ReadinessInput): ReleaseHold | "adult-signature" | "label" | "reconcile" | "fulfillment" | "evidence" | "payment" | "stock" | "reuse" | "ship-to" | null {
|
|
132
|
-
const holds = releaseHolds(input);
|
|
133
|
-
if (holds.length > 0) return holds[0] ?? "fulfillment";
|
|
134
|
-
const decision = decideCommerceCommand({
|
|
135
|
-
command: "hand-off",
|
|
136
|
-
payment: input.payment,
|
|
137
|
-
stock: input.stock,
|
|
138
|
-
fulfillment: input.fulfillment,
|
|
139
|
-
label: input.label,
|
|
140
|
-
evidence: input.evidence,
|
|
141
|
-
providerOutcome: input.providerOutcome,
|
|
142
|
-
shipTo: input.shipTo,
|
|
143
|
-
});
|
|
144
|
-
if (!decision.admit) return decision.reason === "admitted" ? "fulfillment" : decision.reason;
|
|
145
|
-
if (input.adultSignatureRequired && input.adultSignature !== "accepted") return "adult-signature";
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function carrierPolicyForTenant(tenant: {
|
|
150
|
-
tenant_id: string;
|
|
151
|
-
compliance?: { ruleProfile?: string };
|
|
152
|
-
carrierAccountId?: unknown;
|
|
153
|
-
}): CarrierPolicy {
|
|
154
|
-
const profile = tenant.compliance?.ruleProfile;
|
|
155
|
-
const build =
|
|
156
|
-
profile && Object.hasOwn(COMPLIANCE_RULE_PROFILES, profile)
|
|
157
|
-
? COMPLIANCE_RULE_PROFILES[profile as ComplianceRuleProfile]
|
|
158
|
-
: undefined;
|
|
159
|
-
const ruleset = build ? build(tenant.tenant_id) : null;
|
|
160
|
-
const raw = tenant.carrierAccountId;
|
|
161
|
-
const carrierAccountId = typeof raw === "string" && raw.trim() !== "" ? raw.trim() : null;
|
|
162
|
-
const enabled = ruleset?.pactAct.enabled === true;
|
|
163
|
-
return {
|
|
164
|
-
adultSignatureRequired: enabled && ruleset.pactAct.adultSignatureRequired === true,
|
|
165
|
-
pactEnabled: enabled,
|
|
166
|
-
prohibitedCarriers: enabled ? [...ruleset.pactAct.prohibitedCarriers] : [],
|
|
167
|
-
carrierAccountId,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* The tenant's compliance intersected with the carrier catalog. Prohibited when the carrier is in
|
|
173
|
-
* the policy's prohibited set, when PACT is enabled and the carrier is not statutorily eligible,
|
|
174
|
-
* or when adult signature is required and the carrier does not support it. A carrier the catalog
|
|
175
|
-
* does not declare has no eligibility and no adult-signature support, so it fails closed.
|
|
176
|
-
*/
|
|
177
|
-
export function carrierPolicyRefusal(
|
|
178
|
-
carrier: string,
|
|
179
|
-
policy: CarrierPolicy,
|
|
180
|
-
catalog: readonly CarrierCatalogEntry[] = CARRIER_CATALOG,
|
|
181
|
-
): "carrier-prohibited" | null {
|
|
182
|
-
if (carrierProhibited(carrier, policy.prohibitedCarriers)) return "carrier-prohibited";
|
|
183
|
-
const entry = carrierCatalogEntry(carrier, catalog);
|
|
184
|
-
if (policy.pactEnabled && !entry?.pactEligible) return "carrier-prohibited";
|
|
185
|
-
if (policy.adultSignatureRequired && (!entry || entry.adultSignature === "unsupported")) return "carrier-prohibited";
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/** A supplied carrier is never a selection. A carrier the tenant's policy refuses answers carrier-prohibited. */
|
|
190
|
-
export function carrierSelectionRefusal(
|
|
191
|
-
policy: CarrierPolicy,
|
|
192
|
-
carrier: string | undefined,
|
|
193
|
-
catalog: readonly CarrierCatalogEntry[] = CARRIER_CATALOG,
|
|
194
|
-
): "carrier-prohibited" | "vendor-not-selected" | null {
|
|
195
|
-
if (carrier === undefined) return null;
|
|
196
|
-
if (canonicalCarrier(carrier) === "") return "vendor-not-selected";
|
|
197
|
-
return carrierPolicyRefusal(carrier, policy, catalog) ?? "vendor-not-selected";
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* A processor's reported carrier. Prohibited when the current policy refuses it or the order's
|
|
202
|
-
* label-intent snapshot prohibits it; a handoff carrier must equal the carrier its label was bought with.
|
|
203
|
-
*/
|
|
204
|
-
export function carrierEvidenceRefusal(input: {
|
|
205
|
-
carrier: CarrierCode;
|
|
206
|
-
policy: CarrierPolicy;
|
|
207
|
-
snapshotProhibited: readonly string[];
|
|
208
|
-
labelCarrier?: string | null;
|
|
209
|
-
catalog?: readonly CarrierCatalogEntry[];
|
|
210
|
-
}): "carrier-prohibited" | "carrier-mismatch" | null {
|
|
211
|
-
if (carrierPolicyRefusal(input.carrier, input.policy, input.catalog)) return "carrier-prohibited";
|
|
212
|
-
if (carrierProhibited(input.carrier, input.snapshotProhibited)) return "carrier-prohibited";
|
|
213
|
-
if (input.labelCarrier !== undefined && (input.labelCarrier === null || canonicalCarrier(input.labelCarrier) !== input.carrier)) {
|
|
214
|
-
return "carrier-mismatch";
|
|
215
|
-
}
|
|
216
|
-
return null;
|
|
217
|
-
}
|
|
@@ -1,388 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Assignment-keyed shipments and exceptions: the closed request schemas a processor posts against
|
|
3
|
-
* one assignment, the per-line quantity ledger (assigned, shipped, cancelled), and the statements a
|
|
4
|
-
* shipment or exception writes. Every statement here is gated on the order having committed at the
|
|
5
|
-
* new event version in the same batch, so the order's compare-and-set serializes every write to
|
|
6
|
-
* the assignment and its lines.
|
|
7
|
-
*/
|
|
8
|
-
import type { CommerceStage } from "@tot/public-runtime";
|
|
9
|
-
import type { FulfillmentDatabase, SqlStatement } from "./store.js";
|
|
10
|
-
import {
|
|
11
|
-
CARRIER_CODES,
|
|
12
|
-
CARRIER_SERVICE,
|
|
13
|
-
TRACKING_NUMBER,
|
|
14
|
-
carrierProhibited,
|
|
15
|
-
parseCarrierCode,
|
|
16
|
-
trackingUrlAllowed,
|
|
17
|
-
type CarrierCode,
|
|
18
|
-
} from "./carrierEvidence.js";
|
|
19
|
-
|
|
20
|
-
export const EXCEPTION_CODES = [
|
|
21
|
-
"vendor_rejected",
|
|
22
|
-
"backordered",
|
|
23
|
-
"out_of_stock",
|
|
24
|
-
"damaged",
|
|
25
|
-
"address_undeliverable",
|
|
26
|
-
"carrier_refused",
|
|
27
|
-
"other",
|
|
28
|
-
] as const;
|
|
29
|
-
export type ExceptionCode = (typeof EXCEPTION_CODES)[number];
|
|
30
|
-
|
|
31
|
-
export interface ShipmentLine {
|
|
32
|
-
sku: string;
|
|
33
|
-
quantity: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface AssignmentShipmentEvidence {
|
|
37
|
-
kind: "shipment";
|
|
38
|
-
assignmentId: string;
|
|
39
|
-
lines: ShipmentLine[];
|
|
40
|
-
/** The carrier code as posted; plan time refuses one outside the allowed set. */
|
|
41
|
-
carrier: string;
|
|
42
|
-
service?: string;
|
|
43
|
-
trackingNumber: string;
|
|
44
|
-
trackingUrl?: string;
|
|
45
|
-
adultSignature: "accepted" | "refused" | "absent";
|
|
46
|
-
expectedVersion?: number;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface AssignmentExceptionEvidence {
|
|
50
|
-
kind: "exception";
|
|
51
|
-
assignmentId: string;
|
|
52
|
-
lines: ShipmentLine[];
|
|
53
|
-
code: ExceptionCode;
|
|
54
|
-
note?: string;
|
|
55
|
-
expectedVersion?: number;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface AssignmentShipmentView {
|
|
59
|
-
assignmentId: string;
|
|
60
|
-
shipmentId: string;
|
|
61
|
-
fulfilledLines: ShipmentLine[];
|
|
62
|
-
complete: boolean;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface AssignmentExceptionView {
|
|
66
|
-
assignmentId: string;
|
|
67
|
-
exceptionId: string;
|
|
68
|
-
code: ExceptionCode;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** One assignment line as stored. */
|
|
72
|
-
export interface AssignmentLineState {
|
|
73
|
-
lineId: string;
|
|
74
|
-
sku: string;
|
|
75
|
-
locationId: string;
|
|
76
|
-
assigned: number;
|
|
77
|
-
shipped: number;
|
|
78
|
-
cancelled: number;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** An open exception as the operator desk reads it. */
|
|
82
|
-
export interface AssignmentExceptionRecord {
|
|
83
|
-
exceptionId: string;
|
|
84
|
-
assignmentId: string;
|
|
85
|
-
code: ExceptionCode;
|
|
86
|
-
lines: ShipmentLine[];
|
|
87
|
-
note: string | null;
|
|
88
|
-
createdAt: string;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const SHIPMENT_KEYS = new Set(["lines", "carrier", "service", "trackingNumber", "trackingUrl", "adultSignature"]);
|
|
92
|
-
const EXCEPTION_KEYS = new Set(["lines", "code", "note"]);
|
|
93
|
-
const LINE_KEYS = new Set(["sku", "quantity"]);
|
|
94
|
-
const CARRIER_PATTERN = /^[A-Z0-9_]{2,40}$/;
|
|
95
|
-
const SKU_MAX = 256;
|
|
96
|
-
const LINES_MAX = 500;
|
|
97
|
-
const NOTE_MAX = 500;
|
|
98
|
-
/** A note is free text, never contact data: no address sign and no run of seven or more digits. */
|
|
99
|
-
const NOTE_CONTACT = /@|\d[\d\s().-]{5,}\d/;
|
|
100
|
-
|
|
101
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
102
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/** The request lines: one entry per sku, each quantity a positive safe integer. Null when malformed. */
|
|
106
|
-
function parseLines(value: unknown): ShipmentLine[] | null {
|
|
107
|
-
if (!Array.isArray(value) || value.length === 0 || value.length > LINES_MAX) return null;
|
|
108
|
-
const seen = new Set<string>();
|
|
109
|
-
const lines: ShipmentLine[] = [];
|
|
110
|
-
for (const item of value) {
|
|
111
|
-
if (!isRecord(item) || Object.keys(item).some((key) => !LINE_KEYS.has(key))) return null;
|
|
112
|
-
const { sku, quantity } = item;
|
|
113
|
-
if (typeof sku !== "string" || sku.length === 0 || sku.length > SKU_MAX || sku.trim() !== sku) return null;
|
|
114
|
-
if (!Number.isSafeInteger(quantity) || Number(quantity) < 1) return null;
|
|
115
|
-
if (seen.has(sku)) return null;
|
|
116
|
-
seen.add(sku);
|
|
117
|
-
lines.push({ sku, quantity: Number(quantity) });
|
|
118
|
-
}
|
|
119
|
-
return lines;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function closedKeys(body: Record<string, unknown>, allowed: ReadonlySet<string>): boolean {
|
|
123
|
-
return Object.keys(body).every((key) => allowed.has(key)) && Object.values(body).every((value) => value !== null);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/** `AssignmentShipmentWrite` in its closed schema, or null (400 malformed). */
|
|
127
|
-
export function parseAssignmentShipment(assignmentId: string, body: unknown): AssignmentShipmentEvidence | null {
|
|
128
|
-
if (!isRecord(body) || !closedKeys(body, SHIPMENT_KEYS)) return null;
|
|
129
|
-
const lines = parseLines(body.lines);
|
|
130
|
-
if (!lines) return null;
|
|
131
|
-
if (typeof body.carrier !== "string" || !CARRIER_PATTERN.test(body.carrier)) return null;
|
|
132
|
-
if (typeof body.trackingNumber !== "string" || !TRACKING_NUMBER.test(body.trackingNumber)) return null;
|
|
133
|
-
if (body.service !== undefined && (typeof body.service !== "string" || !CARRIER_SERVICE.test(body.service))) return null;
|
|
134
|
-
const known = parseCarrierCode(body.carrier);
|
|
135
|
-
if (body.trackingUrl !== undefined && (known === null || !trackingUrlAllowed(known, body.trackingUrl))) return null;
|
|
136
|
-
const adult = body.adultSignature ?? "absent";
|
|
137
|
-
if (adult !== "accepted" && adult !== "refused" && adult !== "absent") return null;
|
|
138
|
-
return {
|
|
139
|
-
kind: "shipment",
|
|
140
|
-
assignmentId,
|
|
141
|
-
lines,
|
|
142
|
-
carrier: body.carrier,
|
|
143
|
-
trackingNumber: body.trackingNumber,
|
|
144
|
-
adultSignature: adult,
|
|
145
|
-
...(typeof body.service === "string" ? { service: body.service } : {}),
|
|
146
|
-
...(typeof body.trackingUrl === "string" ? { trackingUrl: body.trackingUrl } : {}),
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** `AssignmentExceptionWrite` in its closed schema, or null (400 malformed). */
|
|
151
|
-
export function parseAssignmentException(assignmentId: string, body: unknown): AssignmentExceptionEvidence | null {
|
|
152
|
-
if (!isRecord(body) || !closedKeys(body, EXCEPTION_KEYS)) return null;
|
|
153
|
-
const lines = parseLines(body.lines);
|
|
154
|
-
if (!lines) return null;
|
|
155
|
-
if (typeof body.code !== "string" || !(EXCEPTION_CODES as readonly string[]).includes(body.code)) return null;
|
|
156
|
-
if (body.note !== undefined) {
|
|
157
|
-
if (typeof body.note !== "string" || body.note.length === 0 || body.note.length > NOTE_MAX) return null;
|
|
158
|
-
if (NOTE_CONTACT.test(body.note) || /[\u0000-\u001f\u007f]/.test(body.note)) return null;
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
kind: "exception",
|
|
162
|
-
assignmentId,
|
|
163
|
-
lines,
|
|
164
|
-
code: body.code as ExceptionCode,
|
|
165
|
-
...(typeof body.note === "string" ? { note: body.note } : {}),
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** The carriers an order may ship with: the closed set minus the policy's and the order's prohibited carriers. */
|
|
170
|
-
export function allowedCarriers(policyProhibited: readonly string[], snapshotProhibited: readonly string[]): CarrierCode[] {
|
|
171
|
-
return CARRIER_CODES.filter((code) => !carrierProhibited(code, policyProhibited, snapshotProhibited));
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/** Why `carrier` may not carry this order, or null. */
|
|
175
|
-
export function shipmentCarrierRefusal(
|
|
176
|
-
carrier: string,
|
|
177
|
-
policyProhibited: readonly string[],
|
|
178
|
-
snapshotProhibited: readonly string[],
|
|
179
|
-
): "carrier-prohibited" | "carrier-unsupported" | null {
|
|
180
|
-
if (carrierProhibited(carrier, policyProhibited, snapshotProhibited)) return "carrier-prohibited";
|
|
181
|
-
return parseCarrierCode(carrier) === null ? "carrier-unsupported" : null;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export function remainingQuantity(line: AssignmentLineState): number {
|
|
185
|
-
return line.assigned - line.shipped - line.cancelled;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/** Why `requested` cannot be taken from `lines`, or null: an unknown sku, or more than a line's remainder. */
|
|
189
|
-
export function lineRefusal(
|
|
190
|
-
lines: readonly AssignmentLineState[],
|
|
191
|
-
requested: readonly ShipmentLine[],
|
|
192
|
-
): "line-unknown" | "quantity-exceeded" | null {
|
|
193
|
-
for (const want of requested) {
|
|
194
|
-
const line = lines.find((item) => item.sku === want.sku);
|
|
195
|
-
if (!line) return "line-unknown";
|
|
196
|
-
if (want.quantity > remainingQuantity(line)) return "quantity-exceeded";
|
|
197
|
-
}
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/** True when shipping `requested` leaves every line with nothing remaining. */
|
|
202
|
-
export function completesLines(lines: readonly AssignmentLineState[], requested: readonly ShipmentLine[]): boolean {
|
|
203
|
-
return lines.every((line) => remainingQuantity(line) - (requested.find((item) => item.sku === line.sku)?.quantity ?? 0) === 0);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/** Each line's whole remainder, the shipment a whole-order handoff records. Lines with none are omitted. */
|
|
207
|
-
export function remainingLines(lines: readonly AssignmentLineState[]): ShipmentLine[] {
|
|
208
|
-
return lines.filter((line) => remainingQuantity(line) > 0).map((line) => ({ sku: line.sku, quantity: remainingQuantity(line) }));
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/** The assignment's stored lines in line order. */
|
|
212
|
-
export async function readAssignmentLines(db: Pick<FulfillmentDatabase, "all">, assignmentId: string): Promise<AssignmentLineState[]> {
|
|
213
|
-
const rows = await db.all<{
|
|
214
|
-
line_id: string;
|
|
215
|
-
sku: string;
|
|
216
|
-
location_id: string;
|
|
217
|
-
quantity_assigned: number;
|
|
218
|
-
quantity_shipped: number;
|
|
219
|
-
quantity_cancelled: number;
|
|
220
|
-
}>(
|
|
221
|
-
`SELECT line_id, sku, location_id, quantity_assigned, quantity_shipped, quantity_cancelled
|
|
222
|
-
FROM fulfillment_assignment_lines WHERE assignment_id = ?
|
|
223
|
-
ORDER BY CAST(line_id AS INTEGER) ASC, line_id ASC`,
|
|
224
|
-
[assignmentId],
|
|
225
|
-
);
|
|
226
|
-
return rows.map((row) => ({
|
|
227
|
-
lineId: row.line_id,
|
|
228
|
-
sku: row.sku,
|
|
229
|
-
locationId: row.location_id,
|
|
230
|
-
assigned: Number(row.quantity_assigned),
|
|
231
|
-
shipped: Number(row.quantity_shipped),
|
|
232
|
-
cancelled: Number(row.quantity_cancelled),
|
|
233
|
-
}));
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/** SQL condition: the order committed at `version` in this batch. */
|
|
237
|
-
export function orderCommittedAt(scope: { tenantId: string; stage: CommerceStage; orderId: string }, version: number): SqlStatement {
|
|
238
|
-
return {
|
|
239
|
-
sql: `EXISTS (
|
|
240
|
-
SELECT 1 FROM scrappy_commerce_orders
|
|
241
|
-
WHERE tenant_id = ? AND stage = ? AND order_id = ? AND event_version = ?
|
|
242
|
-
)`,
|
|
243
|
-
params: [scope.tenantId, scope.stage, scope.orderId, version],
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Adds `requested` to each line's shipped quantity, from the quantity read at the planned version.
|
|
249
|
-
* The table's CHECK aborts the batch if shipped plus cancelled would exceed assigned.
|
|
250
|
-
*/
|
|
251
|
-
export function consumeLinesStatements(
|
|
252
|
-
assignmentId: string,
|
|
253
|
-
lines: readonly AssignmentLineState[],
|
|
254
|
-
requested: readonly ShipmentLine[],
|
|
255
|
-
gate: SqlStatement,
|
|
256
|
-
): SqlStatement[] {
|
|
257
|
-
return requested.map((want) => {
|
|
258
|
-
const line = lines.find((item) => item.sku === want.sku)!;
|
|
259
|
-
return {
|
|
260
|
-
sql: `UPDATE fulfillment_assignment_lines SET quantity_shipped = quantity_shipped + ?
|
|
261
|
-
WHERE assignment_id = ? AND line_id = ? AND quantity_shipped = ? AND quantity_cancelled = ? AND ${gate.sql}`,
|
|
262
|
-
params: [want.quantity, assignmentId, line.lineId, line.shipped, line.cancelled, ...gate.params],
|
|
263
|
-
};
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
export function insertShipmentStatement(
|
|
268
|
-
input: {
|
|
269
|
-
shipmentId: string;
|
|
270
|
-
assignmentId: string;
|
|
271
|
-
tenantId: string;
|
|
272
|
-
stage: CommerceStage;
|
|
273
|
-
orderId: string;
|
|
274
|
-
installId: string;
|
|
275
|
-
carrier: string;
|
|
276
|
-
service: string | null;
|
|
277
|
-
trackingNumber: string;
|
|
278
|
-
trackingUrl: string | null;
|
|
279
|
-
adultSignature: "accepted" | "refused" | "absent";
|
|
280
|
-
lines: readonly ShipmentLine[];
|
|
281
|
-
now: string;
|
|
282
|
-
},
|
|
283
|
-
gate: SqlStatement,
|
|
284
|
-
): SqlStatement {
|
|
285
|
-
return {
|
|
286
|
-
sql: `INSERT INTO fulfillment_shipments (
|
|
287
|
-
shipment_id, assignment_id, tenant_id, stage, order_id, install_id, carrier, service,
|
|
288
|
-
tracking_number, tracking_url, adult_signature, shipped_items, created_at
|
|
289
|
-
) SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? WHERE ${gate.sql}`,
|
|
290
|
-
params: [
|
|
291
|
-
input.shipmentId,
|
|
292
|
-
input.assignmentId,
|
|
293
|
-
input.tenantId,
|
|
294
|
-
input.stage,
|
|
295
|
-
input.orderId,
|
|
296
|
-
input.installId,
|
|
297
|
-
input.carrier,
|
|
298
|
-
input.service,
|
|
299
|
-
input.trackingNumber,
|
|
300
|
-
input.trackingUrl,
|
|
301
|
-
input.adultSignature,
|
|
302
|
-
JSON.stringify(input.lines.map((line) => ({ sku: line.sku, quantity: line.quantity }))),
|
|
303
|
-
input.now,
|
|
304
|
-
...gate.params,
|
|
305
|
-
],
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/** Event gate: the shipment row exists — the shipment it reports committed. */
|
|
310
|
-
export function shipmentCommittedGate(shipmentId: string): SqlStatement {
|
|
311
|
-
return { sql: `EXISTS (SELECT 1 FROM fulfillment_shipments WHERE shipment_id = ?)`, params: [shipmentId] };
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
export function insertExceptionStatement(
|
|
315
|
-
input: {
|
|
316
|
-
exceptionId: string;
|
|
317
|
-
assignmentId: string;
|
|
318
|
-
tenantId: string;
|
|
319
|
-
stage: CommerceStage;
|
|
320
|
-
orderId: string;
|
|
321
|
-
installId: string;
|
|
322
|
-
code: ExceptionCode;
|
|
323
|
-
lines: readonly ShipmentLine[];
|
|
324
|
-
note: string | null;
|
|
325
|
-
now: string;
|
|
326
|
-
},
|
|
327
|
-
gate: SqlStatement,
|
|
328
|
-
): SqlStatement {
|
|
329
|
-
return {
|
|
330
|
-
sql: `INSERT INTO fulfillment_assignment_exceptions (
|
|
331
|
-
exception_id, assignment_id, tenant_id, stage, order_id, install_id, code, lines, note, state, created_at
|
|
332
|
-
) SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, 'open', ? WHERE ${gate.sql}`,
|
|
333
|
-
params: [
|
|
334
|
-
input.exceptionId,
|
|
335
|
-
input.assignmentId,
|
|
336
|
-
input.tenantId,
|
|
337
|
-
input.stage,
|
|
338
|
-
input.orderId,
|
|
339
|
-
input.installId,
|
|
340
|
-
input.code,
|
|
341
|
-
JSON.stringify(input.lines.map((line) => ({ sku: line.sku, quantity: line.quantity }))),
|
|
342
|
-
input.note,
|
|
343
|
-
input.now,
|
|
344
|
-
...gate.params,
|
|
345
|
-
],
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/** The order's open exceptions, oldest first. Rows whose stored shape fails validation are skipped. */
|
|
350
|
-
export async function readOpenExceptions(
|
|
351
|
-
db: Pick<FulfillmentDatabase, "all">,
|
|
352
|
-
scope: { tenantId: string; stage: CommerceStage; orderId: string },
|
|
353
|
-
): Promise<AssignmentExceptionRecord[]> {
|
|
354
|
-
const rows = await db.all<{
|
|
355
|
-
exception_id: string;
|
|
356
|
-
assignment_id: string;
|
|
357
|
-
code: string;
|
|
358
|
-
lines: string;
|
|
359
|
-
note: string | null;
|
|
360
|
-
created_at: string;
|
|
361
|
-
}>(
|
|
362
|
-
`SELECT exception_id, assignment_id, code, lines, note, created_at FROM fulfillment_assignment_exceptions
|
|
363
|
-
WHERE tenant_id = ? AND stage = ? AND order_id = ? AND state = 'open'
|
|
364
|
-
ORDER BY created_at ASC, exception_id ASC`,
|
|
365
|
-
[scope.tenantId, scope.stage, scope.orderId],
|
|
366
|
-
);
|
|
367
|
-
const records: AssignmentExceptionRecord[] = [];
|
|
368
|
-
for (const row of rows) {
|
|
369
|
-
if (!(EXCEPTION_CODES as readonly string[]).includes(row.code)) continue;
|
|
370
|
-
let parsed: unknown;
|
|
371
|
-
try {
|
|
372
|
-
parsed = JSON.parse(row.lines);
|
|
373
|
-
} catch {
|
|
374
|
-
continue;
|
|
375
|
-
}
|
|
376
|
-
const lines = parseLines(parsed);
|
|
377
|
-
if (!lines) continue;
|
|
378
|
-
records.push({
|
|
379
|
-
exceptionId: row.exception_id,
|
|
380
|
-
assignmentId: row.assignment_id,
|
|
381
|
-
code: row.code as ExceptionCode,
|
|
382
|
-
lines,
|
|
383
|
-
note: typeof row.note === "string" ? row.note : null,
|
|
384
|
-
createdAt: row.created_at,
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
return records;
|
|
388
|
-
}
|