@tokenoftrust/storefront-runner 7.3.2 → 7.5.1
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/agent/checkoutProtocol.ts +196 -0
- package/apps/storefront/src/lib/checkout/agent/checkoutSession.ts +296 -0
- package/apps/storefront/src/lib/checkout/agent/webBotAuth.ts +347 -0
- 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 +522 -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/checkout-sessions/[id].ts +9 -0
- package/apps/storefront/src/pages/api/commerce/checkout-sessions.ts +8 -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
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Review and confirm handlers for assistant cart proposals.
|
|
3
|
+
*
|
|
4
|
+
* Review resolves an assistant's lines against the routed tenant's own catalog into an offer the
|
|
5
|
+
* shopper can read. Confirm takes only the reviewed proposal id and digest, resolves the lines
|
|
6
|
+
* again, and hands them into the same server-owned signed cart pipeline an ordinary product page
|
|
7
|
+
* uses. Tenant, price, tax, shipping, destination and order source come from the request's
|
|
8
|
+
* trusted context and the catalog; an assistant or shopper payload can supply none of them, and
|
|
9
|
+
* no step here charges, submits an order or attests verification.
|
|
10
|
+
*
|
|
11
|
+
* Logs carry the tenant, stable reason codes and counts. They never carry list text, line text,
|
|
12
|
+
* ids a shopper typed, or buyer data.
|
|
13
|
+
*/
|
|
14
|
+
import type { APIContext } from "astro";
|
|
15
|
+
import {
|
|
16
|
+
buildVariantCartPayload,
|
|
17
|
+
commerceTenantId,
|
|
18
|
+
enforceCartSubmission,
|
|
19
|
+
signCartLine,
|
|
20
|
+
tenantPublicOrigin,
|
|
21
|
+
CART_PROPOSAL_TTL_SECONDS,
|
|
22
|
+
CHECKOUT_NAVIGATION_REFERRER_POLICY,
|
|
23
|
+
SHIPPING_UNAVAILABLE_CART_MESSAGE,
|
|
24
|
+
type CartProposalLine,
|
|
25
|
+
type CartProposalReason,
|
|
26
|
+
type TenantConfig,
|
|
27
|
+
} from "@tot/public-runtime";
|
|
28
|
+
import { addProposalToBoundCart, CART_UNAVAILABLE_MESSAGE, withCartSession } from "@/lib/checkout/commerce/cartSession";
|
|
29
|
+
import { completeCartFields, ledgerSoldOut, trustedReturnUrl } from "@/lib/checkout/commerce/checkoutHandoffRoute";
|
|
30
|
+
import { resolveCartSigning, shopperCartDenialMessage, type CartSigningResolution } from "@/lib/checkout/shared/checkoutCommerce";
|
|
31
|
+
import {
|
|
32
|
+
catalogEntries,
|
|
33
|
+
decodeProposalId,
|
|
34
|
+
encodeProposalId,
|
|
35
|
+
proposalAge,
|
|
36
|
+
proposalIdKey,
|
|
37
|
+
proposalReplayKey,
|
|
38
|
+
resolveProposalLines,
|
|
39
|
+
validateConfirmRequest,
|
|
40
|
+
validateReviewRequest,
|
|
41
|
+
type ProposalCatalog,
|
|
42
|
+
type ProposalRequestLine,
|
|
43
|
+
} from "./cartProposal";
|
|
44
|
+
import { matchList } from "./listMatcher";
|
|
45
|
+
import { renderPasteForm, renderRefusal, renderReview, type ReviewView } from "./reviewHtml";
|
|
46
|
+
|
|
47
|
+
export const CART_PROPOSAL_REVIEW_PATH = "/api/cart-proposal/review";
|
|
48
|
+
export const CART_PROPOSAL_CONFIRM_PATH = "/api/cart-proposal/confirm";
|
|
49
|
+
|
|
50
|
+
const MAX_BODY_BYTES = 65_536;
|
|
51
|
+
const NO_COMMERCE_MESSAGE = "Checkout is unavailable because this store has no cart configured.";
|
|
52
|
+
|
|
53
|
+
export interface ProposalCompliance {
|
|
54
|
+
status: string;
|
|
55
|
+
blocks: Array<{ code: string; message: string }>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ProposalDeps {
|
|
59
|
+
/** Seconds since the epoch. */
|
|
60
|
+
now?: () => number;
|
|
61
|
+
/** The compliance preflight of the reviewed lines; null when it cannot be evaluated. */
|
|
62
|
+
preflight?: (context: APIContext, lines: readonly CartProposalLine[]) => Promise<ProposalCompliance | null>;
|
|
63
|
+
fetch?: typeof fetch;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ConfirmDeps extends ProposalDeps {
|
|
67
|
+
/**
|
|
68
|
+
* The path of a product's own page in the tenant's declared URL form. Supplied by the route so
|
|
69
|
+
* the checkout capability does not import the content capability's URL rules. Confirm signs it as
|
|
70
|
+
* the cart line's return page, as an ordinary product page does.
|
|
71
|
+
*/
|
|
72
|
+
productPagePath: (context: APIContext, handle: string) => string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const SECURITY_HEADERS = {
|
|
76
|
+
"cache-control": "private, no-store",
|
|
77
|
+
"x-robots-tag": "noindex, nofollow",
|
|
78
|
+
"referrer-policy": "no-referrer",
|
|
79
|
+
"x-tot-payment-authorized": "false",
|
|
80
|
+
} as const;
|
|
81
|
+
|
|
82
|
+
/** The query parameter that carries a reviewed proposal's id to the review screen. */
|
|
83
|
+
export const CART_PROPOSAL_ID_PARAM = "proposalId";
|
|
84
|
+
|
|
85
|
+
export function jsonReply(body: unknown, status: number, extra: Record<string, string> = {}): Response {
|
|
86
|
+
return new Response(JSON.stringify(body), {
|
|
87
|
+
status,
|
|
88
|
+
headers: { "content-type": "application/json; charset=utf-8", ...SECURITY_HEADERS, ...extra },
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function htmlReply(html: string, status: number): Response {
|
|
93
|
+
return new Response(html, {
|
|
94
|
+
status,
|
|
95
|
+
headers: { "content-type": "text/html; charset=utf-8", ...SECURITY_HEADERS },
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function wantsJson(request: Request): boolean {
|
|
100
|
+
const accept = request.headers.get("accept") ?? "";
|
|
101
|
+
if (accept.includes("application/json")) return true;
|
|
102
|
+
if (accept.includes("text/html")) return false;
|
|
103
|
+
return (request.headers.get("content-type") ?? "").includes("application/json");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function basePrefix(context: APIContext): string {
|
|
107
|
+
return (context.locals.apiBasePath ?? context.locals.basePath ?? "").replace(/\/+$/, "");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function logProposal(context: APIContext, event: string, detail: Record<string, string | number | boolean>): void {
|
|
111
|
+
console.info(`[storefront] cart-proposal ${event} ${JSON.stringify({
|
|
112
|
+
tenant: context.locals.tenant.tenant_id,
|
|
113
|
+
stage: context.locals.browserEnvironment?.environment ?? "unknown",
|
|
114
|
+
...detail,
|
|
115
|
+
})}`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface Refusal {
|
|
119
|
+
status: number;
|
|
120
|
+
code: CartProposalReason;
|
|
121
|
+
message: string;
|
|
122
|
+
reasons?: Array<{ code: CartProposalReason; field?: string }>;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function refuse(context: APIContext, refusal: Refusal, event: string): Response {
|
|
126
|
+
logProposal(context, event, { code: refusal.code, reasons: refusal.reasons?.length ?? 1 });
|
|
127
|
+
if (wantsJson(context.request)) {
|
|
128
|
+
return jsonReply({
|
|
129
|
+
error: refusal.code,
|
|
130
|
+
...(refusal.reasons ? { reasons: refusal.reasons } : {}),
|
|
131
|
+
message: refusal.message,
|
|
132
|
+
}, refusal.status);
|
|
133
|
+
}
|
|
134
|
+
return htmlReply(renderRefusal(refusal.code, refusal.message), refusal.status);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The parsed request body: JSON or a urlencoded form, bounded. `null` is an unreadable body. */
|
|
138
|
+
export async function readBody(request: Request): Promise<Record<string, unknown> | unknown[] | null> {
|
|
139
|
+
const type = request.headers.get("content-type") ?? "";
|
|
140
|
+
const declared = Number(request.headers.get("content-length") ?? "0");
|
|
141
|
+
if (Number.isFinite(declared) && declared > MAX_BODY_BYTES) return null;
|
|
142
|
+
let text: string;
|
|
143
|
+
try {
|
|
144
|
+
text = await request.text();
|
|
145
|
+
} catch (error) {
|
|
146
|
+
// A body stream that fails mid-read (client abort, reset) is an unreadable body, not a defect.
|
|
147
|
+
if (error instanceof TypeError || error instanceof DOMException) return null;
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
if (text.length > MAX_BODY_BYTES) return null;
|
|
151
|
+
if (type.includes("application/json")) {
|
|
152
|
+
try {
|
|
153
|
+
const parsed: unknown = JSON.parse(text);
|
|
154
|
+
return parsed && typeof parsed === "object" ? (parsed as Record<string, unknown> | unknown[]) : null;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (error instanceof SyntaxError) return null;
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (type.includes("application/x-www-form-urlencoded")) {
|
|
161
|
+
const body: Record<string, unknown> = {};
|
|
162
|
+
for (const [name, value] of new URLSearchParams(text)) body[name] = value;
|
|
163
|
+
return body;
|
|
164
|
+
}
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** A cart-changing request must come from this store's own pages. */
|
|
169
|
+
function sameOrigin(context: APIContext): boolean {
|
|
170
|
+
const { request } = context;
|
|
171
|
+
const site = request.headers.get("sec-fetch-site");
|
|
172
|
+
if (site && site !== "same-origin" && site !== "none") return false;
|
|
173
|
+
const origin = request.headers.get("origin");
|
|
174
|
+
if (!origin) return true;
|
|
175
|
+
// A page served with `referrer-policy: no-referrer` (the review page) submits its own forms with
|
|
176
|
+
// `Origin: null`. That is this store's own page only when the browser also says same-origin.
|
|
177
|
+
if (origin === "null") return site === "same-origin";
|
|
178
|
+
let host: string;
|
|
179
|
+
try {
|
|
180
|
+
host = new URL(origin).host.toLowerCase();
|
|
181
|
+
} catch {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
const { tenant } = context.locals;
|
|
185
|
+
const domain = tenant.appDomain?.toLowerCase();
|
|
186
|
+
const allowed = [new URL(request.url).host.toLowerCase(), ...(domain ? [domain, `www.${domain}`] : [])];
|
|
187
|
+
if (context.locals.requestOrigin) {
|
|
188
|
+
try {
|
|
189
|
+
allowed.push(new URL(context.locals.requestOrigin).host.toLowerCase());
|
|
190
|
+
} catch { /* an unreadable declared origin allows nothing extra */ }
|
|
191
|
+
}
|
|
192
|
+
return allowed.includes(host);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export async function proposalCatalog(context: APIContext, tenant: TenantConfig): Promise<ProposalCatalog> {
|
|
196
|
+
return {
|
|
197
|
+
tenantScope: tenant.tot_data_scope,
|
|
198
|
+
currency: tenant.currency,
|
|
199
|
+
products: await context.locals.tot.getAllActiveProducts(),
|
|
200
|
+
soldOut: (sku) => ledgerSoldOut(context, tenant, sku),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** The cart-signing resolution, or the refusal to return when this store cannot sign carts. */
|
|
205
|
+
export async function proposalSigning(
|
|
206
|
+
context: APIContext,
|
|
207
|
+
commerce: NonNullable<APIContext["locals"]["commerce"]>,
|
|
208
|
+
event: string,
|
|
209
|
+
): Promise<CartSigningResolution | Response> {
|
|
210
|
+
let signing: CartSigningResolution;
|
|
211
|
+
try {
|
|
212
|
+
signing = await resolveCartSigning(commerce);
|
|
213
|
+
} catch {
|
|
214
|
+
return refuse(context, {
|
|
215
|
+
status: 503,
|
|
216
|
+
code: "commerce_unavailable",
|
|
217
|
+
message: shopperCartDenialMessage("signing-unavailable", ""),
|
|
218
|
+
}, event);
|
|
219
|
+
}
|
|
220
|
+
if (!signing.enabled) {
|
|
221
|
+
return refuse(context, {
|
|
222
|
+
status: 503,
|
|
223
|
+
code: "commerce_unavailable",
|
|
224
|
+
message: shopperCartDenialMessage("signing-unavailable", signing.operatorError ?? ""),
|
|
225
|
+
}, event);
|
|
226
|
+
}
|
|
227
|
+
return signing;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function proposalTotal(lines: readonly CartProposalLine[]): number {
|
|
231
|
+
return lines.reduce((sum, line) => sum + Math.round(line.lineTotal * 100), 0) / 100;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** GET: the paste form. */
|
|
235
|
+
export function cartProposalForm(context: APIContext): Response {
|
|
236
|
+
const prefix = basePrefix(context);
|
|
237
|
+
return htmlReply(renderPasteForm(`${prefix}${CART_PROPOSAL_REVIEW_PATH}`), 200);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* GET: the paste form, or with a proposal id the shopper's review of that proposal. The id is the
|
|
242
|
+
* HMAC-authenticated token a review mints; it is verified before anything is read from it, and
|
|
243
|
+
* another store's id, an expired one and a malformed one are each refused. The lines are resolved
|
|
244
|
+
* again against the routed store's own catalog, so what the shopper reads is today's price and
|
|
245
|
+
* availability. Reads only: confirming stays the same-origin POST.
|
|
246
|
+
*/
|
|
247
|
+
export async function cartProposalOpen(context: APIContext, deps: ProposalDeps = {}): Promise<Response> {
|
|
248
|
+
const id = new URL(context.request.url).searchParams.get(CART_PROPOSAL_ID_PARAM);
|
|
249
|
+
if (id === null) return cartProposalForm(context);
|
|
250
|
+
const { tenant, commerce } = context.locals;
|
|
251
|
+
if (!commerce) {
|
|
252
|
+
return refuse(context, { status: 409, code: "commerce_unavailable", message: NO_COMMERCE_MESSAGE }, "open-refused");
|
|
253
|
+
}
|
|
254
|
+
const signing = await proposalSigning(context, commerce, "open-refused");
|
|
255
|
+
if (signing instanceof Response) return signing;
|
|
256
|
+
|
|
257
|
+
const token = await decodeProposalId(id, proposalIdKey(signing.secret));
|
|
258
|
+
if (!token) {
|
|
259
|
+
return refuse(context, { status: 422, code: "proposal_invalid", message: "This order review is not valid. Review your order again." }, "open-refused");
|
|
260
|
+
}
|
|
261
|
+
if (token.tenant !== tenant.tot_data_scope) {
|
|
262
|
+
return refuse(context, { status: 422, code: "proposal_tenant_mismatch", message: "This order review is not valid for this store. Review your order again." }, "open-refused");
|
|
263
|
+
}
|
|
264
|
+
const now = (deps.now ?? (() => Math.floor(Date.now() / 1000)))();
|
|
265
|
+
const age = proposalAge(token.issuedAt, now);
|
|
266
|
+
if (age === "invalid") {
|
|
267
|
+
return refuse(context, { status: 422, code: "proposal_invalid", message: "This order review is not valid. Review your order again." }, "open-refused");
|
|
268
|
+
}
|
|
269
|
+
if (age === "expired") {
|
|
270
|
+
return refuse(context, { status: 409, code: "offer_expired", message: "This order review has expired. Review your order again." }, "open-refused");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
let catalog: ProposalCatalog;
|
|
274
|
+
try {
|
|
275
|
+
catalog = await proposalCatalog(context, tenant);
|
|
276
|
+
} catch {
|
|
277
|
+
return refuse(context, { status: 503, code: "cart_unavailable", message: CART_UNAVAILABLE_MESSAGE }, "open-refused");
|
|
278
|
+
}
|
|
279
|
+
const live = await resolveProposalLines(token.lines, catalog);
|
|
280
|
+
if (live.refused.length > 0 || live.lines.length !== token.lines.length) {
|
|
281
|
+
return refuse(context, { status: 409, code: "offer_stale", message: "Prices or availability changed. Review your order again." }, "open-refused");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
let compliance: ProposalCompliance | null = null;
|
|
285
|
+
if (deps.preflight) {
|
|
286
|
+
try {
|
|
287
|
+
compliance = await deps.preflight(context, live.lines);
|
|
288
|
+
} catch {
|
|
289
|
+
compliance = null;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
logProposal(context, "opened", { lines: live.lines.length });
|
|
293
|
+
const prefix = basePrefix(context);
|
|
294
|
+
const view: ReviewView = {
|
|
295
|
+
confirmAction: `${prefix}${CART_PROPOSAL_CONFIRM_PATH}`,
|
|
296
|
+
reviewAction: `${prefix}${CART_PROPOSAL_REVIEW_PATH}`,
|
|
297
|
+
proposal: {
|
|
298
|
+
id,
|
|
299
|
+
digest: live.digest,
|
|
300
|
+
expiresAt: token.issuedAt + CART_PROPOSAL_TTL_SECONDS,
|
|
301
|
+
currency: tenant.currency,
|
|
302
|
+
total: proposalTotal(live.lines),
|
|
303
|
+
lines: live.lines,
|
|
304
|
+
},
|
|
305
|
+
refused: [],
|
|
306
|
+
unmatched: [],
|
|
307
|
+
compliance,
|
|
308
|
+
};
|
|
309
|
+
return htmlReply(renderReview(view), 200);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** POST: resolve an assistant's lines into a reviewable offer. Reads only; changes no cart. */
|
|
313
|
+
export async function cartProposalReview(context: APIContext, deps: ProposalDeps = {}): Promise<Response> {
|
|
314
|
+
const { tenant, commerce } = context.locals;
|
|
315
|
+
if (!commerce) {
|
|
316
|
+
return refuse(context, { status: 409, code: "commerce_unavailable", message: NO_COMMERCE_MESSAGE }, "review-refused");
|
|
317
|
+
}
|
|
318
|
+
const signing = await proposalSigning(context, commerce, "review-refused");
|
|
319
|
+
if (signing instanceof Response) return signing;
|
|
320
|
+
const body = await readBody(context.request);
|
|
321
|
+
const validated = validateReviewRequest(body);
|
|
322
|
+
if (!validated.ok) {
|
|
323
|
+
return refuse(context, {
|
|
324
|
+
status: 422,
|
|
325
|
+
code: validated.reasons[0]?.code ?? "invalid_request",
|
|
326
|
+
message: "This order request could not be read.",
|
|
327
|
+
reasons: validated.reasons,
|
|
328
|
+
}, "review-refused");
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
let catalog: ProposalCatalog;
|
|
332
|
+
try {
|
|
333
|
+
catalog = await proposalCatalog(context, tenant);
|
|
334
|
+
} catch {
|
|
335
|
+
return refuse(context, { status: 503, code: "cart_unavailable", message: CART_UNAVAILABLE_MESSAGE }, "review-refused");
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
let requested: ProposalRequestLine[];
|
|
339
|
+
let sourceText: string[] | null = null;
|
|
340
|
+
let unmatched: Array<{ reason: CartProposalReason; text: string }> = [];
|
|
341
|
+
if (validated.request.assistant === "list-text") {
|
|
342
|
+
const matched = matchList(validated.request.text, catalogEntries(catalog));
|
|
343
|
+
if (!matched.ok) {
|
|
344
|
+
return refuse(context, { status: 422, code: matched.reason, message: "This list could not be read." }, "review-refused");
|
|
345
|
+
}
|
|
346
|
+
requested = matched.matched.map((line) => ({ variantId: line.variantId, quantity: line.quantity }));
|
|
347
|
+
sourceText = matched.matched.map((line) => matched.lineTexts[line.source] ?? "");
|
|
348
|
+
unmatched = matched.unmatched.map((line) => ({ reason: line.reason, text: line.text }));
|
|
349
|
+
} else {
|
|
350
|
+
requested = validated.request.lines;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const resolved = await resolveProposalLines(requested, catalog);
|
|
354
|
+
const refused = resolved.refused.map((item) => ({
|
|
355
|
+
index: item.index,
|
|
356
|
+
reason: item.reason,
|
|
357
|
+
...(sourceText ? { text: sourceText[item.index] ?? "" } : {}),
|
|
358
|
+
}));
|
|
359
|
+
const issuedAt = (deps.now ?? (() => Math.floor(Date.now() / 1000)))();
|
|
360
|
+
const proposal = resolved.lines.length > 0
|
|
361
|
+
? {
|
|
362
|
+
id: await encodeProposalId({
|
|
363
|
+
tenant: tenant.tot_data_scope,
|
|
364
|
+
issuedAt,
|
|
365
|
+
lines: resolved.lines.map((line) => ({ variantId: line.variantId, quantity: line.quantity })),
|
|
366
|
+
}, proposalIdKey(signing.secret)),
|
|
367
|
+
digest: resolved.digest,
|
|
368
|
+
issuedAt,
|
|
369
|
+
expiresAt: issuedAt + CART_PROPOSAL_TTL_SECONDS,
|
|
370
|
+
currency: tenant.currency,
|
|
371
|
+
total: proposalTotal(resolved.lines),
|
|
372
|
+
lines: resolved.lines,
|
|
373
|
+
}
|
|
374
|
+
: null;
|
|
375
|
+
|
|
376
|
+
let compliance: ProposalCompliance | null = null;
|
|
377
|
+
if (proposal && deps.preflight) {
|
|
378
|
+
try {
|
|
379
|
+
compliance = await deps.preflight(context, proposal.lines);
|
|
380
|
+
} catch {
|
|
381
|
+
compliance = null;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
logProposal(context, "reviewed", {
|
|
386
|
+
assistant: validated.request.assistant,
|
|
387
|
+
lines: resolved.lines.length,
|
|
388
|
+
refused: resolved.refused.length,
|
|
389
|
+
unmatched: unmatched.length,
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
const status = proposal ? 200 : 422;
|
|
393
|
+
if (wantsJson(context.request)) {
|
|
394
|
+
return jsonReply({ proposal, refused, unmatched, compliance, confirmable: proposal !== null }, status);
|
|
395
|
+
}
|
|
396
|
+
const prefix = basePrefix(context);
|
|
397
|
+
const view: ReviewView = {
|
|
398
|
+
confirmAction: `${prefix}${CART_PROPOSAL_CONFIRM_PATH}`,
|
|
399
|
+
reviewAction: `${prefix}${CART_PROPOSAL_REVIEW_PATH}`,
|
|
400
|
+
proposal,
|
|
401
|
+
refused,
|
|
402
|
+
unmatched,
|
|
403
|
+
compliance,
|
|
404
|
+
};
|
|
405
|
+
return htmlReply(renderReview(view), status);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** POST: hand a reviewed proposal into the signed cart. Takes only `{proposalId, digest}`. */
|
|
409
|
+
export async function cartProposalConfirm(context: APIContext, deps: ConfirmDeps): Promise<Response> {
|
|
410
|
+
const { tenant, commerce } = context.locals;
|
|
411
|
+
if (!sameOrigin(context)) {
|
|
412
|
+
return refuse(context, { status: 403, code: "cross_origin", message: "This request cannot be accepted." }, "confirm-refused");
|
|
413
|
+
}
|
|
414
|
+
if (!commerce) {
|
|
415
|
+
return refuse(context, { status: 409, code: "commerce_unavailable", message: NO_COMMERCE_MESSAGE }, "confirm-refused");
|
|
416
|
+
}
|
|
417
|
+
const signing = await proposalSigning(context, commerce, "confirm-refused");
|
|
418
|
+
if (signing instanceof Response) return signing;
|
|
419
|
+
|
|
420
|
+
const validated = validateConfirmRequest(await readBody(context.request));
|
|
421
|
+
if (!validated.ok) {
|
|
422
|
+
return refuse(context, {
|
|
423
|
+
status: 422,
|
|
424
|
+
code: validated.reasons[0]?.code ?? "invalid_request",
|
|
425
|
+
message: "This confirmation could not be read.",
|
|
426
|
+
reasons: validated.reasons,
|
|
427
|
+
}, "confirm-refused");
|
|
428
|
+
}
|
|
429
|
+
const token = await decodeProposalId(validated.proposalId, proposalIdKey(signing.secret));
|
|
430
|
+
if (!token) {
|
|
431
|
+
return refuse(context, { status: 422, code: "proposal_invalid", message: "This order review is not valid. Review your order again." }, "confirm-refused");
|
|
432
|
+
}
|
|
433
|
+
if (token.tenant !== tenant.tot_data_scope) {
|
|
434
|
+
return refuse(context, { status: 422, code: "proposal_tenant_mismatch", message: "This order review is not valid for this store. Review your order again." }, "confirm-refused");
|
|
435
|
+
}
|
|
436
|
+
const now = (deps.now ?? (() => Math.floor(Date.now() / 1000)))();
|
|
437
|
+
const age = proposalAge(token.issuedAt, now);
|
|
438
|
+
if (age === "invalid") {
|
|
439
|
+
return refuse(context, { status: 422, code: "proposal_invalid", message: "This order review is not valid. Review your order again." }, "confirm-refused");
|
|
440
|
+
}
|
|
441
|
+
if (age === "expired") {
|
|
442
|
+
return refuse(context, { status: 409, code: "offer_expired", message: "This order review has expired. Review your order again." }, "confirm-refused");
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
let catalog: ProposalCatalog;
|
|
446
|
+
try {
|
|
447
|
+
catalog = await proposalCatalog(context, tenant);
|
|
448
|
+
} catch {
|
|
449
|
+
return refuse(context, { status: 503, code: "cart_unavailable", message: CART_UNAVAILABLE_MESSAGE }, "confirm-refused");
|
|
450
|
+
}
|
|
451
|
+
const live = await resolveProposalLines(token.lines, catalog);
|
|
452
|
+
if (live.refused.length > 0 || live.lines.length !== token.lines.length || live.digest !== validated.digest) {
|
|
453
|
+
return refuse(context, { status: 409, code: "offer_stale", message: "Prices or availability changed. Review your order again." }, "confirm-refused");
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const entries = new Map(catalogEntries(catalog).map((entry) => [entry.variant.id, entry]));
|
|
457
|
+
const publicOrigin = tenantPublicOrigin(tenant, {
|
|
458
|
+
requestOrigin: context.locals.requestOrigin || new URL(context.request.url).origin,
|
|
459
|
+
basePath: context.locals.imageBasePath || context.locals.apiBasePath || context.locals.basePath,
|
|
460
|
+
});
|
|
461
|
+
const lines: Array<Array<{ name: string; value: string }>> = [];
|
|
462
|
+
const codes: string[] = [];
|
|
463
|
+
for (const line of live.lines) {
|
|
464
|
+
const entry = entries.get(line.variantId);
|
|
465
|
+
if (!entry) {
|
|
466
|
+
return refuse(context, { status: 409, code: "offer_stale", message: "Prices or availability changed. Review your order again." }, "confirm-refused");
|
|
467
|
+
}
|
|
468
|
+
const payload = await buildVariantCartPayload(entry.product, entry.variant, {
|
|
469
|
+
mode: commerce.mode,
|
|
470
|
+
secret: signing.secret,
|
|
471
|
+
tenantId: commerceTenantId(tenant),
|
|
472
|
+
currency: tenant.currency,
|
|
473
|
+
publicOrigin,
|
|
474
|
+
});
|
|
475
|
+
const enforced = await enforceCartSubmission({
|
|
476
|
+
entries: [
|
|
477
|
+
...payload.hidden.map((field): [string, string] => [field.name, field.value]),
|
|
478
|
+
[payload.quantityName, String(line.quantity)],
|
|
479
|
+
],
|
|
480
|
+
mode: commerce.mode,
|
|
481
|
+
secret: signing.secret,
|
|
482
|
+
trustedTenantId: commerceTenantId(tenant),
|
|
483
|
+
});
|
|
484
|
+
if (!enforced.ok) {
|
|
485
|
+
return refuse(context, { status: 409, code: "offer_stale", message: "Prices or availability changed. Review your order again." }, "confirm-refused");
|
|
486
|
+
}
|
|
487
|
+
const productPage = new URL(deps.productPagePath(context, entry.product.handle), context.request.url).toString();
|
|
488
|
+
const completed = await completeCartFields(context, commerce, tenant, signing.secret, enforced.fields, {
|
|
489
|
+
ref: null,
|
|
490
|
+
returnUrl: trustedReturnUrl(context.request, tenant, productPage),
|
|
491
|
+
});
|
|
492
|
+
if (!completed) {
|
|
493
|
+
return refuse(context, { status: 409, code: "cart_unavailable", message: SHIPPING_UNAVAILABLE_CART_MESSAGE }, "confirm-refused");
|
|
494
|
+
}
|
|
495
|
+
const code = completed.find((field) => field.name.split("||")[0] === "code")?.value;
|
|
496
|
+
if (code) codes.push(code);
|
|
497
|
+
lines.push(completed.map((field) => ({ name: field.name, value: field.value })));
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const added = await addProposalToBoundCart(
|
|
501
|
+
context,
|
|
502
|
+
commerce,
|
|
503
|
+
commerceTenantId(tenant),
|
|
504
|
+
{ key: await proposalReplayKey(token, validated.digest), codes, lines },
|
|
505
|
+
(line) => signCartLine(line.fields, { mode: commerce.mode, secret: signing.secret, code: line.code }),
|
|
506
|
+
deps.fetch,
|
|
507
|
+
);
|
|
508
|
+
if (!added) {
|
|
509
|
+
return refuse(context, { status: 503, code: "cart_unavailable", message: CART_UNAVAILABLE_MESSAGE }, "confirm-refused");
|
|
510
|
+
}
|
|
511
|
+
const location = withCartSession(commerce.cartUrl, added.id);
|
|
512
|
+
logProposal(context, "confirmed", { lines: live.lines.length, replayed: added.replayed });
|
|
513
|
+
if (wantsJson(context.request)) {
|
|
514
|
+
return jsonReply({ location, replayed: added.replayed, lines: live.lines.length }, 200, {
|
|
515
|
+
"referrer-policy": CHECKOUT_NAVIGATION_REFERRER_POLICY,
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
return new Response(null, {
|
|
519
|
+
status: 303,
|
|
520
|
+
headers: { ...SECURITY_HEADERS, location, "referrer-policy": CHECKOUT_NAVIGATION_REFERRER_POLICY },
|
|
521
|
+
});
|
|
522
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The review screen markup. A server-rendered page with no script: the shopper reads the
|
|
3
|
+
* resolved lines, the refused and unmatched lines, and the compliance status, and confirms with a
|
|
4
|
+
* plain form post of the proposal id and digest. Every dynamic value is escaped here.
|
|
5
|
+
*/
|
|
6
|
+
import type { CartProposalLine, CartProposalReason } from "@tot/public-runtime";
|
|
7
|
+
|
|
8
|
+
export interface ReviewView {
|
|
9
|
+
/** Where the confirm form posts. */
|
|
10
|
+
confirmAction: string;
|
|
11
|
+
/** Where the paste form posts. */
|
|
12
|
+
reviewAction: string;
|
|
13
|
+
proposal: { id: string; digest: string; expiresAt: number; currency: string; total: number; lines: CartProposalLine[] } | null;
|
|
14
|
+
refused: Array<{ index: number; reason: CartProposalReason; text?: string }>;
|
|
15
|
+
unmatched: Array<{ reason: CartProposalReason; text: string }>;
|
|
16
|
+
compliance: { status: string; blocks: Array<{ code: string; message: string }> } | null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function escapeHtml(value: string): string {
|
|
20
|
+
return value.replace(/[&<>"']/g, (ch) => {
|
|
21
|
+
if (ch === "&") return "&";
|
|
22
|
+
if (ch === "<") return "<";
|
|
23
|
+
if (ch === ">") return ">";
|
|
24
|
+
if (ch === '"') return """;
|
|
25
|
+
return "'";
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function money(amount: number, currency: string): string {
|
|
30
|
+
try {
|
|
31
|
+
return new Intl.NumberFormat("en-US", { style: "currency", currency }).format(amount);
|
|
32
|
+
} catch {
|
|
33
|
+
return `${amount.toFixed(2)} ${currency}`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function page(body: string): string {
|
|
38
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8">` +
|
|
39
|
+
`<meta name="viewport" content="width=device-width,initial-scale=1">` +
|
|
40
|
+
`<meta name="robots" content="noindex,nofollow"><title>Review your order</title></head>` +
|
|
41
|
+
`<body><main>${body}</main></body></html>`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function pasteForm(action: string): string {
|
|
45
|
+
return `<form method="post" action="${escapeHtml(action)}" data-cart-proposal-paste>` +
|
|
46
|
+
`<input type="hidden" name="assistant" value="list-text">` +
|
|
47
|
+
`<label for="proposal-text">Paste your list, one item per line (for example: 10 x Product Flavor)</label>` +
|
|
48
|
+
`<textarea id="proposal-text" name="text" rows="6" maxlength="4000" required></textarea>` +
|
|
49
|
+
`<button type="submit">Review order</button></form>`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The paste form alone. */
|
|
53
|
+
export function renderPasteForm(reviewAction: string): string {
|
|
54
|
+
return page(`<h1>Order from a list</h1>${pasteForm(reviewAction)}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function renderReview(view: ReviewView): string {
|
|
58
|
+
const parts: string[] = ["<h1>Review your order</h1>",
|
|
59
|
+
`<p data-payment-authorized="false">Nothing is charged or submitted here. Confirming adds these items to your cart.</p>`];
|
|
60
|
+
|
|
61
|
+
if (view.proposal) {
|
|
62
|
+
const { proposal } = view;
|
|
63
|
+
const rows = proposal.lines.map((line) =>
|
|
64
|
+
`<tr data-variant-id="${escapeHtml(line.variantId)}"><td>${escapeHtml(line.productTitle)}` +
|
|
65
|
+
`${line.variantTitle && line.variantTitle !== line.productTitle ? ` — ${escapeHtml(line.variantTitle)}` : ""}</td>` +
|
|
66
|
+
`<td>${line.quantity}</td><td>${escapeHtml(money(line.unitPrice, line.currency))}</td>` +
|
|
67
|
+
`<td>${escapeHtml(money(line.lineTotal, line.currency))}</td><td>In stock</td></tr>`).join("");
|
|
68
|
+
parts.push(
|
|
69
|
+
`<table data-cart-proposal-lines><thead><tr><th>Item</th><th>Quantity</th><th>Price</th><th>Line total</th><th>Availability</th></tr></thead>` +
|
|
70
|
+
`<tbody>${rows}</tbody></table>`,
|
|
71
|
+
`<p data-cart-proposal-total>Total: ${escapeHtml(money(proposal.total, proposal.currency))}</p>`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (view.refused.length > 0) {
|
|
75
|
+
parts.push(`<section data-cart-proposal-refused><h2>Not added</h2><ul>${view.refused.map((item) =>
|
|
76
|
+
`<li data-reason="${escapeHtml(item.reason)}">${item.text ? `${escapeHtml(item.text)}: ` : ""}${escapeHtml(item.reason)}</li>`).join("")}</ul></section>`);
|
|
77
|
+
}
|
|
78
|
+
if (view.unmatched.length > 0) {
|
|
79
|
+
parts.push(`<section data-cart-proposal-unmatched><h2>Not matched</h2><ul>${view.unmatched.map((item) =>
|
|
80
|
+
`<li data-reason="${escapeHtml(item.reason)}">${escapeHtml(item.text)}: ${escapeHtml(item.reason)}</li>`).join("")}</ul></section>`);
|
|
81
|
+
}
|
|
82
|
+
if (view.compliance) {
|
|
83
|
+
parts.push(`<section data-cart-proposal-compliance data-status="${escapeHtml(view.compliance.status)}"><h2>Checkout requirements</h2>` +
|
|
84
|
+
`<p>${escapeHtml(view.compliance.status)}</p>` +
|
|
85
|
+
`${view.compliance.blocks.length ? `<ul>${view.compliance.blocks.map((block) =>
|
|
86
|
+
`<li data-code="${escapeHtml(block.code)}">${escapeHtml(block.message)}</li>`).join("")}</ul>` : ""}</section>`);
|
|
87
|
+
}
|
|
88
|
+
if (view.proposal) {
|
|
89
|
+
parts.push(`<form method="post" action="${escapeHtml(view.confirmAction)}" data-cart-proposal-confirm>` +
|
|
90
|
+
`<input type="hidden" name="proposalId" value="${escapeHtml(view.proposal.id)}">` +
|
|
91
|
+
`<input type="hidden" name="digest" value="${escapeHtml(view.proposal.digest)}">` +
|
|
92
|
+
`<button type="submit">Confirm and add to cart</button></form>`);
|
|
93
|
+
}
|
|
94
|
+
parts.push(pasteForm(view.reviewAction));
|
|
95
|
+
return page(parts.join(""));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function renderRefusal(code: CartProposalReason, message: string): string {
|
|
99
|
+
return page(`<h1>Order review</h1><p data-cart-proposal-refusal="${escapeHtml(code)}" data-payment-authorized="false">${escapeHtml(message)}</p>`);
|
|
100
|
+
}
|
|
@@ -257,21 +257,38 @@ export function verifiedRefKey(preflightUrl: string): string {
|
|
|
257
257
|
return `tot:verified-ref:${preflightUrl}`;
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
|
|
260
|
+
function isStoreWideVerifiedKey(key: string): boolean {
|
|
261
|
+
return key.startsWith("tot:verified-ref:");
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function readFromStorage(get: () => Storage, key: string): string | null {
|
|
261
265
|
try {
|
|
262
|
-
const v =
|
|
266
|
+
const v = get().getItem(key);
|
|
263
267
|
return v && v.trim() ? v : null;
|
|
264
268
|
} catch {
|
|
265
269
|
return null;
|
|
266
270
|
}
|
|
267
271
|
}
|
|
268
272
|
|
|
273
|
+
export function readStoredRef(key: string): string | null {
|
|
274
|
+
const fromSession = readFromStorage(() => sessionStorage, key);
|
|
275
|
+
if (fromSession) return fromSession;
|
|
276
|
+
return isStoreWideVerifiedKey(key) ? readFromStorage(() => localStorage, key) : null;
|
|
277
|
+
}
|
|
278
|
+
|
|
269
279
|
export function writeStoredRef(key: string, ref: string): void {
|
|
270
280
|
try {
|
|
271
281
|
sessionStorage.setItem(key, ref);
|
|
272
282
|
} catch {
|
|
273
283
|
/* storage disabled — the flow still works, it just can't survive a reload */
|
|
274
284
|
}
|
|
285
|
+
if (isStoreWideVerifiedKey(key)) {
|
|
286
|
+
try {
|
|
287
|
+
localStorage.setItem(key, ref);
|
|
288
|
+
} catch {
|
|
289
|
+
/* storage disabled */
|
|
290
|
+
}
|
|
291
|
+
}
|
|
275
292
|
}
|
|
276
293
|
|
|
277
294
|
export function clearStoredRef(key: string): void {
|
|
@@ -280,4 +297,11 @@ export function clearStoredRef(key: string): void {
|
|
|
280
297
|
} catch {
|
|
281
298
|
/* storage disabled */
|
|
282
299
|
}
|
|
300
|
+
if (isStoreWideVerifiedKey(key)) {
|
|
301
|
+
try {
|
|
302
|
+
localStorage.removeItem(key);
|
|
303
|
+
} catch {
|
|
304
|
+
/* storage disabled */
|
|
305
|
+
}
|
|
306
|
+
}
|
|
283
307
|
}
|