@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
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Scheduled PRUNE + ROLLUP for the per-tenant raw-interaction D1 stores
|
|
3
|
-
* (`dt-storage-per-tenant-d1`).
|
|
4
|
-
*
|
|
5
|
-
* WHAT THIS DOES, per tenant, per sweep:
|
|
6
|
-
* 1. READ the rows aging out of the 90-day window (`ingested_at < cutoff`,
|
|
7
|
-
* the SERVER receive clock — never the client `ts`, which a beacon can
|
|
8
|
-
* skew arbitrarily).
|
|
9
|
-
* 2. ROLL UP those rows via the already-built, pure `aggregateInteractions()`
|
|
10
|
-
* and write them to the dedicated `INTERACTION_ANALYTICS` dataset via
|
|
11
|
-
* the already-built `writeInteractionAnalytics()` — durable long-term
|
|
12
|
-
* aggregates survive the delete below. Both are reused verbatim from
|
|
13
|
-
* `interactionStore.ts`, never reimplemented here.
|
|
14
|
-
* 3. DELETE those same rows. `DELETE FROM interaction_events WHERE
|
|
15
|
-
* ingested_at < ?` is an index range scan
|
|
16
|
-
* (`idx_interaction_events_ingested_at`), not a table scan.
|
|
17
|
-
* 4. MEASURE the database's current size (`PRAGMA page_count * page_size`)
|
|
18
|
-
* and warn when a tenant is approaching D1's 10GB-per-database ceiling —
|
|
19
|
-
* the point is to surface this BEFORE writes start failing, not after.
|
|
20
|
-
* 5. WRITE BACK the `tracking_tenant_databases` bookkeeping columns
|
|
21
|
-
* (`last_pruned_at`, `pruned_rows`, `size_bytes`, `size_checked_at`) that
|
|
22
|
-
* `dt-storage-per-tenant-d1` added for exactly this purpose.
|
|
23
|
-
*
|
|
24
|
-
* WORK QUEUE. One sweep processes a bounded BATCH of tenants
|
|
25
|
-
* (`ORDER BY last_pruned_at ASC` — SQLite sorts NULL first, so a tenant that
|
|
26
|
-
* has never been pruned is swept immediately), not the whole fleet in one
|
|
27
|
-
* invocation. A frequent-enough cron (see `workers/pruneRollupWorker.ts`)
|
|
28
|
-
* cycles fairly through every tenant over time instead of risking one run
|
|
29
|
-
* exceeding the Worker's CPU/wall-clock budget as the tenant count grows.
|
|
30
|
-
*
|
|
31
|
-
* NOT DONE HERE (by design, per the binding decisions this unit follows):
|
|
32
|
-
* - No DROP-based time-partitioned schema. The DROP-vs-DELETE cost
|
|
33
|
-
* asymmetry noted in `d1-cost-basis-verified` is UNVERIFIED inference;
|
|
34
|
-
* this sticks to the straightforward `DELETE ... WHERE ingested_at < ?`
|
|
35
|
-
* against the single `interaction_events` table dt-storage-per-tenant-d1
|
|
36
|
-
* already built. A future optimization pass can revisit it once verified.
|
|
37
|
-
* - No outbound alert transport. Same posture as `activity/alerts.ts`: this
|
|
38
|
-
* module DETECTS a tenant approaching the ceiling and logs it
|
|
39
|
-
* (`console.warn`, grep-able in Workers Logs) plus returns it in the
|
|
40
|
-
* structured sweep result — where it goes from there (a dashboard, a
|
|
41
|
-
* polled endpoint) is a sink's job, not this module's.
|
|
42
|
-
*
|
|
43
|
-
* BEST-EFFORT PER TENANT. One tenant's prune failing (a REST error, a
|
|
44
|
-
* transient D1 fault) is caught, logged, and recorded in that tenant's
|
|
45
|
-
* outcome — it never aborts the rest of the batch.
|
|
46
|
-
*/
|
|
47
|
-
import type { Queryable } from "../../catalog/d1/catalog.js";
|
|
48
|
-
import type { AnalyticsEngineLike } from "../../activity/store.js";
|
|
49
|
-
import { fromD1Rest, type D1ControlConfig } from "./d1Control.js";
|
|
50
|
-
import { aggregateInteractions, writeInteractionAnalytics } from "./interactionStore.js";
|
|
51
|
-
import type { StampedInteractionEvent } from "./collectorIngest.js";
|
|
52
|
-
|
|
53
|
-
/** The settled retention window (`settled-operational-choices`). */
|
|
54
|
-
export const DEFAULT_RETENTION_DAYS = 90;
|
|
55
|
-
|
|
56
|
-
/** How many tenants one sweep invocation processes. */
|
|
57
|
-
export const DEFAULT_BATCH_SIZE = 25;
|
|
58
|
-
|
|
59
|
-
/** D1's documented per-database ceiling. */
|
|
60
|
-
export const D1_SIZE_CEILING_BYTES = 10 * 1024 * 1024 * 1024;
|
|
61
|
-
|
|
62
|
-
/** Warn at 80% of the ceiling — well before writes start failing. */
|
|
63
|
-
const DEFAULT_SIZE_WARNING_RATIO = 0.8;
|
|
64
|
-
|
|
65
|
-
/** One row of the prune work queue. */
|
|
66
|
-
export interface TenantPruneRow {
|
|
67
|
-
tenant_id: string;
|
|
68
|
-
database_uuid: string;
|
|
69
|
-
last_pruned_at: string | null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface PruneSweepDeps {
|
|
73
|
-
/** The shared STOREFRONT_APPS_DB handle holding the directory table. */
|
|
74
|
-
apps: Queryable;
|
|
75
|
-
/** D1 REST credentials + transport, for reaching each tenant's own database. */
|
|
76
|
-
control: D1ControlConfig;
|
|
77
|
-
/** The dedicated interaction AE dataset. Absent ⇒ rollup is skipped, prune
|
|
78
|
-
* still runs (never block retention on an unavailable aggregates sink). */
|
|
79
|
-
analytics?: AnalyticsEngineLike;
|
|
80
|
-
/** ISO-8601 "now" — injected so the sweep is deterministic under test. */
|
|
81
|
-
now: string;
|
|
82
|
-
retentionDays?: number;
|
|
83
|
-
batchSize?: number;
|
|
84
|
-
/** Absolute byte threshold for the ceiling warning; defaults to 80% of
|
|
85
|
-
* `D1_SIZE_CEILING_BYTES`. */
|
|
86
|
-
sizeWarningBytes?: number;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface TenantPruneOutcome {
|
|
90
|
-
tenantId: string;
|
|
91
|
-
prunedRows: number;
|
|
92
|
-
aggregatesWritten: number;
|
|
93
|
-
sizeBytes: number | null;
|
|
94
|
-
/** True when `sizeBytes` is at/above the warning threshold. */
|
|
95
|
-
sizeWarning: boolean;
|
|
96
|
-
/** Set only when this tenant's sweep failed; the batch still continues. */
|
|
97
|
-
error?: string;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export interface PruneSweepResult {
|
|
101
|
-
tenantsSwept: number;
|
|
102
|
-
totalPrunedRows: number;
|
|
103
|
-
totalAggregatesWritten: number;
|
|
104
|
-
tenants: TenantPruneOutcome[];
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/** Map one raw `interaction_events` row (snake_case D1 columns) back to the
|
|
108
|
-
* `StampedInteractionEvent` shape `aggregateInteractions()` expects. PURE. */
|
|
109
|
-
export function rawRowToEvent(row: Record<string, unknown>): StampedInteractionEvent {
|
|
110
|
-
return {
|
|
111
|
-
type: "click",
|
|
112
|
-
el: String(row.el ?? ""),
|
|
113
|
-
action: (row.action as string | null) ?? null,
|
|
114
|
-
placement: (row.placement as string | null) ?? null,
|
|
115
|
-
scope: (row.scope as string | null) ?? null,
|
|
116
|
-
index: (row.idx as number | null) ?? null,
|
|
117
|
-
ts: String(row.ts ?? ""),
|
|
118
|
-
correlationId: String(row.correlation_id ?? ""),
|
|
119
|
-
seq: Number(row.seq ?? 0),
|
|
120
|
-
tenant_id: String(row.tenant_id ?? ""),
|
|
121
|
-
stream: "interaction",
|
|
122
|
-
ingested_at: String(row.ingested_at ?? ""),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/** The prune work queue: oldest-`last_pruned_at`-first (NULL — never pruned —
|
|
127
|
-
* sorts first in SQLite ASC). Never throws. */
|
|
128
|
-
export async function listPruneCandidates(
|
|
129
|
-
apps: Queryable,
|
|
130
|
-
batchSize: number,
|
|
131
|
-
): Promise<TenantPruneRow[]> {
|
|
132
|
-
try {
|
|
133
|
-
return await apps.all<TenantPruneRow>(
|
|
134
|
-
`SELECT tenant_id, database_uuid, last_pruned_at
|
|
135
|
-
FROM tracking_tenant_databases
|
|
136
|
-
ORDER BY last_pruned_at ASC
|
|
137
|
-
LIMIT ?`,
|
|
138
|
-
batchSize,
|
|
139
|
-
);
|
|
140
|
-
} catch (err) {
|
|
141
|
-
console.error(
|
|
142
|
-
`[tracking:prune] directory read failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
143
|
-
);
|
|
144
|
-
return [];
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/** `PRAGMA page_count * page_size` — the current on-disk size of one tenant's
|
|
149
|
-
* database. Returns null (never throws) when the pragmas are unavailable. */
|
|
150
|
-
async function readDatabaseSizeBytes(db: Queryable): Promise<number | null> {
|
|
151
|
-
try {
|
|
152
|
-
const pageCount = await db.first<{ page_count: number }>("PRAGMA page_count");
|
|
153
|
-
const pageSize = await db.first<{ page_size: number }>("PRAGMA page_size");
|
|
154
|
-
if (!pageCount || !pageSize) return null;
|
|
155
|
-
const count = Number(pageCount.page_count);
|
|
156
|
-
const size = Number(pageSize.page_size);
|
|
157
|
-
if (!Number.isFinite(count) || !Number.isFinite(size)) return null;
|
|
158
|
-
return count * size;
|
|
159
|
-
} catch {
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/** Prune + roll up ONE tenant's database. Never throws. */
|
|
165
|
-
export async function pruneTenant(
|
|
166
|
-
row: TenantPruneRow,
|
|
167
|
-
deps: PruneSweepDeps,
|
|
168
|
-
): Promise<TenantPruneOutcome> {
|
|
169
|
-
const retentionDays = deps.retentionDays ?? DEFAULT_RETENTION_DAYS;
|
|
170
|
-
const sizeWarningBytes =
|
|
171
|
-
deps.sizeWarningBytes ?? Math.floor(D1_SIZE_CEILING_BYTES * DEFAULT_SIZE_WARNING_RATIO);
|
|
172
|
-
const cutoff = new Date(
|
|
173
|
-
Date.parse(deps.now) - retentionDays * 24 * 60 * 60 * 1000,
|
|
174
|
-
).toISOString();
|
|
175
|
-
|
|
176
|
-
try {
|
|
177
|
-
const db = fromD1Rest(deps.control, row.database_uuid);
|
|
178
|
-
|
|
179
|
-
// Read the aging-out rows BEFORE deleting them — the rollup needs them.
|
|
180
|
-
const aging = await db.all<Record<string, unknown>>(
|
|
181
|
-
`SELECT tenant_id, stream, type, el, action, placement, scope, idx, correlation_id, seq, ts, ingested_at
|
|
182
|
-
FROM interaction_events WHERE ingested_at < ?`,
|
|
183
|
-
cutoff,
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
let aggregatesWritten = 0;
|
|
187
|
-
if (aging.length > 0) {
|
|
188
|
-
if (deps.analytics) {
|
|
189
|
-
const aggregates = aggregateInteractions(aging.map(rawRowToEvent));
|
|
190
|
-
writeInteractionAnalytics(deps.analytics, aggregates);
|
|
191
|
-
aggregatesWritten = aggregates.length;
|
|
192
|
-
}
|
|
193
|
-
// The DELETE itself never depends on the rollup succeeding — retention
|
|
194
|
-
// must not stall because the aggregates sink is unavailable.
|
|
195
|
-
await db.run(`DELETE FROM interaction_events WHERE ingested_at < ?`, cutoff);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const sizeBytes = await readDatabaseSizeBytes(db);
|
|
199
|
-
const sizeWarning = sizeBytes != null && sizeBytes >= sizeWarningBytes;
|
|
200
|
-
if (sizeWarning) {
|
|
201
|
-
console.warn(
|
|
202
|
-
`[tracking:prune] tenant ${row.tenant_id} database at ${sizeBytes} bytes — ` +
|
|
203
|
-
`approaching the ${D1_SIZE_CEILING_BYTES}-byte D1 per-database ceiling`,
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
await deps.apps.run(
|
|
208
|
-
`UPDATE tracking_tenant_databases
|
|
209
|
-
SET last_pruned_at = ?, pruned_rows = pruned_rows + ?, size_bytes = ?, size_checked_at = ?
|
|
210
|
-
WHERE tenant_id = ?`,
|
|
211
|
-
deps.now,
|
|
212
|
-
aging.length,
|
|
213
|
-
sizeBytes,
|
|
214
|
-
deps.now,
|
|
215
|
-
row.tenant_id,
|
|
216
|
-
);
|
|
217
|
-
|
|
218
|
-
return {
|
|
219
|
-
tenantId: row.tenant_id,
|
|
220
|
-
prunedRows: aging.length,
|
|
221
|
-
aggregatesWritten,
|
|
222
|
-
sizeBytes,
|
|
223
|
-
sizeWarning,
|
|
224
|
-
};
|
|
225
|
-
} catch (err) {
|
|
226
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
227
|
-
console.error(`[tracking:prune] sweep failed for ${row.tenant_id}: ${message}`);
|
|
228
|
-
return {
|
|
229
|
-
tenantId: row.tenant_id,
|
|
230
|
-
prunedRows: 0,
|
|
231
|
-
aggregatesWritten: 0,
|
|
232
|
-
sizeBytes: null,
|
|
233
|
-
sizeWarning: false,
|
|
234
|
-
error: message,
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Run one bounded batch of the prune sweep: pull the oldest-pruned tenants
|
|
241
|
-
* off the work queue and prune+roll-up each in turn. Sequential, not
|
|
242
|
-
* parallel — keeps one invocation's D1 REST call volume predictable rather
|
|
243
|
-
* than fanning every tenant in the batch out concurrently.
|
|
244
|
-
*/
|
|
245
|
-
export async function runPruneSweep(deps: PruneSweepDeps): Promise<PruneSweepResult> {
|
|
246
|
-
const batchSize = deps.batchSize ?? DEFAULT_BATCH_SIZE;
|
|
247
|
-
const candidates = await listPruneCandidates(deps.apps, batchSize);
|
|
248
|
-
|
|
249
|
-
const tenants: TenantPruneOutcome[] = [];
|
|
250
|
-
for (const row of candidates) {
|
|
251
|
-
tenants.push(await pruneTenant(row, deps));
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return {
|
|
255
|
-
tenantsSwept: tenants.length,
|
|
256
|
-
totalPrunedRows: tenants.reduce((n, t) => n + t.prunedRows, 0),
|
|
257
|
-
totalAggregatesWritten: tenants.reduce((n, t) => n + t.aggregatesWritten, 0),
|
|
258
|
-
tenants,
|
|
259
|
-
};
|
|
260
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Merchant-facing READ authorization over the per-tenant interaction D1
|
|
3
|
-
* databases `dt-storage-per-tenant-d1` built (`tenantD1Registry.ts`,
|
|
4
|
-
* `interactionStore.ts`). This is `dt-tenant-isolation`: the release-order
|
|
5
|
-
* doc's hard invariant is "no merchant-visible surface ships until this
|
|
6
|
-
* lands", and this module is that surface's data-access layer.
|
|
7
|
-
*
|
|
8
|
-
* THE ISOLATION GUARANTEE THIS MODULE RELIES ON (built by
|
|
9
|
-
* `dt-storage-per-tenant-d1`, not re-implemented here): `resolveTenantStore`
|
|
10
|
-
* is the ONLY way to get a `Queryable`, and it is bound to exactly one
|
|
11
|
-
* tenant's database UUID. There is no handle anywhere that spans two
|
|
12
|
-
* tenants' rows, so every function below is safe to call with an UNSCOPED
|
|
13
|
-
* `SELECT` — the database itself is the isolation boundary, not the `WHERE`
|
|
14
|
-
* clause. A `tenant_id = ?` predicate is still included below (matching the
|
|
15
|
-
* `TenantInteractionStore.tenantId` the caller resolved — NEVER a
|
|
16
|
-
* client-suppliable value) as defence-in-depth and to keep the row's
|
|
17
|
-
* redundant `tenant_id` column meaningful, not because it is what makes the
|
|
18
|
-
* isolation hold.
|
|
19
|
-
*
|
|
20
|
-
* `assertStoreOwnership` is the extra check this unit adds on top: before
|
|
21
|
-
* trusting a resolved store for a read, confirm `interaction_store_meta`
|
|
22
|
-
* (stamped by `dt-storage-per-tenant-d1` at provision time) actually says
|
|
23
|
-
* this database belongs to the tenant we resolved it for. A resolution bug
|
|
24
|
-
* that somehow handed back the wrong store is caught here rather than
|
|
25
|
-
* silently serving the wrong tenant's rows to a merchant.
|
|
26
|
-
*/
|
|
27
|
-
import type { TenantInteractionStore } from "./tenantD1Registry.js";
|
|
28
|
-
|
|
29
|
-
/** One row of the merchant-visible recent-events feed. */
|
|
30
|
-
export interface RecentInteractionEvent {
|
|
31
|
-
type: string;
|
|
32
|
-
el: string;
|
|
33
|
-
action: string | null;
|
|
34
|
-
placement: string | null;
|
|
35
|
-
scope: string | null;
|
|
36
|
-
ts: string;
|
|
37
|
-
ingestedAt: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** One rolled-up (action, el) count — the merchant-visible summary shape. */
|
|
41
|
-
export interface InteractionActionCount {
|
|
42
|
-
el: string;
|
|
43
|
-
action: string;
|
|
44
|
-
count: number;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface InteractionInsights {
|
|
48
|
-
totalEvents: number;
|
|
49
|
-
byAction: InteractionActionCount[];
|
|
50
|
-
recent: RecentInteractionEvent[];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Cap on the recent-events feed — a dashboard preview, not an export. */
|
|
54
|
-
const DEFAULT_RECENT_LIMIT = 50;
|
|
55
|
-
const MAX_RECENT_LIMIT = 200;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Confirm a resolved store's `interaction_store_meta` row actually names the
|
|
59
|
-
* tenant we resolved it for. Returns `false` (never throws) on any mismatch,
|
|
60
|
-
* a missing meta row, or a query failure — all fail-closed: the caller must
|
|
61
|
-
* treat that as "cannot verify this store, do not read from it."
|
|
62
|
-
*/
|
|
63
|
-
export async function assertStoreOwnership(
|
|
64
|
-
store: Pick<TenantInteractionStore, "tenantId" | "db">,
|
|
65
|
-
): Promise<boolean> {
|
|
66
|
-
try {
|
|
67
|
-
const meta = await store.db.first<{ tenant_id: string }>(
|
|
68
|
-
`SELECT tenant_id FROM interaction_store_meta WHERE id = 1`,
|
|
69
|
-
);
|
|
70
|
-
return !!meta && meta.tenant_id === store.tenantId;
|
|
71
|
-
} catch {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Recent raw events for ONE tenant's own store, newest first. Scoped to the
|
|
78
|
-
* resolved store's database (the isolation boundary) AND to its
|
|
79
|
-
* `tenantId` (defence-in-depth) — there is no parameter here through which a
|
|
80
|
-
* caller can ask for a different tenant's rows; the only tenant this can
|
|
81
|
-
* ever return is the one `store` was resolved for.
|
|
82
|
-
*/
|
|
83
|
-
export async function readRecentInteractionEvents(
|
|
84
|
-
store: Pick<TenantInteractionStore, "tenantId" | "db">,
|
|
85
|
-
opts?: { limit?: number },
|
|
86
|
-
): Promise<RecentInteractionEvent[]> {
|
|
87
|
-
const limit = Math.max(1, Math.min(opts?.limit ?? DEFAULT_RECENT_LIMIT, MAX_RECENT_LIMIT));
|
|
88
|
-
return store.db.all<RecentInteractionEvent>(
|
|
89
|
-
`SELECT type, el, action, placement, scope, ts, ingested_at AS ingestedAt
|
|
90
|
-
FROM interaction_events
|
|
91
|
-
WHERE tenant_id = ?
|
|
92
|
-
ORDER BY ingested_at DESC
|
|
93
|
-
LIMIT ?`,
|
|
94
|
-
store.tenantId,
|
|
95
|
-
limit,
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Simple aggregate over ONE tenant's own store: total row count + a rollup by
|
|
101
|
-
* (el, action). Mirrors the AE dimension tuple's spirit but computed directly
|
|
102
|
-
* off the tenant's own raw rows, scoped the same way as
|
|
103
|
-
* {@link readRecentInteractionEvents}.
|
|
104
|
-
*/
|
|
105
|
-
export async function readInteractionSummary(
|
|
106
|
-
store: Pick<TenantInteractionStore, "tenantId" | "db">,
|
|
107
|
-
): Promise<{ totalEvents: number; byAction: InteractionActionCount[] }> {
|
|
108
|
-
const totalRow = await store.db.first<{ n: number }>(
|
|
109
|
-
`SELECT COUNT(*) AS n FROM interaction_events WHERE tenant_id = ?`,
|
|
110
|
-
store.tenantId,
|
|
111
|
-
);
|
|
112
|
-
const byAction = await store.db.all<InteractionActionCount>(
|
|
113
|
-
`SELECT el, COALESCE(action, '') AS action, COUNT(*) AS count
|
|
114
|
-
FROM interaction_events
|
|
115
|
-
WHERE tenant_id = ?
|
|
116
|
-
GROUP BY el, action
|
|
117
|
-
ORDER BY count DESC`,
|
|
118
|
-
store.tenantId,
|
|
119
|
-
);
|
|
120
|
-
return { totalEvents: totalRow?.n ?? 0, byAction };
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* The full merchant-visible read: ownership-asserted, then summary + recent
|
|
125
|
-
* feed off the SAME scoped store. Returns `undefined` when the store fails
|
|
126
|
-
* the ownership assertion — fail-closed, never a partial/best-guess result.
|
|
127
|
-
*/
|
|
128
|
-
export async function readTenantInteractionInsights(
|
|
129
|
-
store: Pick<TenantInteractionStore, "tenantId" | "db">,
|
|
130
|
-
opts?: { limit?: number },
|
|
131
|
-
): Promise<InteractionInsights | undefined> {
|
|
132
|
-
if (!(await assertStoreOwnership(store))) return undefined;
|
|
133
|
-
const [summary, recent] = await Promise.all([
|
|
134
|
-
readInteractionSummary(store),
|
|
135
|
-
readRecentInteractionEvents(store, opts),
|
|
136
|
-
]);
|
|
137
|
-
return { totalEvents: summary.totalEvents, byAction: summary.byAction, recent };
|
|
138
|
-
}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `data-tot-el` writeback (dt-id-writeback) — the git-time rewriter that turns
|
|
3
|
-
* `tracking-id-derivation.ts`'s PROPOSALS into an actual attribute in a tenant's
|
|
4
|
-
* source HTML, so a human reviews and accepts a real diff (never a silent
|
|
5
|
-
* runtime mutation). Mirrors the pattern `the-build/toc.ts` already uses for
|
|
6
|
-
* heading anchors: parse5 fragment/document tree, mutate in place, re-`serialize()`
|
|
7
|
-
* ONLY when something actually changed (byte-preserving otherwise).
|
|
8
|
-
*
|
|
9
|
-
* Scope: tenant-authored BODY documents only (`content/home.html`,
|
|
10
|
-
* `content/<tenant>/pages-html/<slug>.html`) — never governed chrome, which
|
|
11
|
-
* `trackingAttributes()` / `trackingAttributesHtml()` already stamp via a
|
|
12
|
-
* separate, non-derived path (`dt-stamp-chrome-nav`). This module does not know
|
|
13
|
-
* about chrome and must never be pointed at `chrome.html` / `chrome.json`.
|
|
14
|
-
*
|
|
15
|
-
* Contract: docs/architecture/interaction-tracking-attribute-contract.md
|
|
16
|
-
* ("Deriving `data-tot-el`").
|
|
17
|
-
*/
|
|
18
|
-
import { parse, parseFragment, serialize } from "parse5";
|
|
19
|
-
import {
|
|
20
|
-
createTrackingIdDeriver,
|
|
21
|
-
isTrackableNode,
|
|
22
|
-
TRACKING_ATTR_EL,
|
|
23
|
-
type DerivationOptions,
|
|
24
|
-
type DerivationConfidence,
|
|
25
|
-
type StructuralNode,
|
|
26
|
-
} from "@tot/public-runtime";
|
|
27
|
-
|
|
28
|
-
/** Minimal structural view of a parse5 node (duck-typed, as toc.ts does). */
|
|
29
|
-
interface P5Attr {
|
|
30
|
-
name: string;
|
|
31
|
-
value: string;
|
|
32
|
-
}
|
|
33
|
-
interface P5Node {
|
|
34
|
-
nodeName: string;
|
|
35
|
-
tagName?: string;
|
|
36
|
-
attrs?: P5Attr[];
|
|
37
|
-
childNodes?: P5Node[];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** One proposed (or already-declared) `data-tot-el` this pass encountered. */
|
|
41
|
-
export interface TrackingWritebackProposal {
|
|
42
|
-
/** The proposed (or, for a `"declared"` row, the pre-existing) value. */
|
|
43
|
-
el: string;
|
|
44
|
-
confidence: DerivationConfidence;
|
|
45
|
-
/** Most-significant-first, per `DerivedTrackingId.signals` — the diff annotation. */
|
|
46
|
-
signals: readonly string[];
|
|
47
|
-
/** True iff a human should name this element before accepting the diff. */
|
|
48
|
-
needsReview: boolean;
|
|
49
|
-
/** True iff `data-tot-el` was ALREADY present (nothing written; verbatim). */
|
|
50
|
-
alreadyDeclared: boolean;
|
|
51
|
-
/** The element's tag, for the review listing. */
|
|
52
|
-
tag: string;
|
|
53
|
-
/** A short open-tag snippet (no children) so a reviewer can locate the element. */
|
|
54
|
-
snippet: string;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface TrackingWritebackResult {
|
|
58
|
-
/** The (possibly) rewritten source. Byte-identical to the input when `changed` is false. */
|
|
59
|
-
html: string;
|
|
60
|
-
/** True iff at least one element gained a new `data-tot-el`. */
|
|
61
|
-
changed: boolean;
|
|
62
|
-
/** Every candidate element seen, in document order — declared rows included. */
|
|
63
|
-
proposals: TrackingWritebackProposal[];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function attrsToRecord(attrs?: P5Attr[]): Record<string, string> | undefined {
|
|
67
|
-
if (!attrs || attrs.length === 0) return undefined;
|
|
68
|
-
const rec: Record<string, string> = {};
|
|
69
|
-
for (const a of attrs) rec[a.name] = a.value;
|
|
70
|
-
return rec;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function toStructuralNode(node: P5Node): StructuralNode {
|
|
74
|
-
return { tag: (node.tagName ?? "").toLowerCase(), attrs: attrsToRecord(node.attrs) };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function openTagSnippet(node: StructuralNode): string {
|
|
78
|
-
const attrs = node.attrs ?? {};
|
|
79
|
-
const parts = Object.entries(attrs)
|
|
80
|
-
.filter((entry): entry is [string, string] => typeof entry[1] === "string")
|
|
81
|
-
.map(([k, v]) => `${k}="${v}"`);
|
|
82
|
-
return `<${node.tag}${parts.length ? " " + parts.join(" ") : ""}>`;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function isElement(node: P5Node): node is P5Node & { tagName: string } {
|
|
86
|
-
return typeof node.tagName === "string" && node.tagName.length > 0;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** Every `data-tot-el` value anywhere in the tree, in document order — the
|
|
90
|
-
* pre-existing identities a fresh proposal must never collide with, per the
|
|
91
|
-
* derivation engine's own handoff ("reserve() every id already in the source,
|
|
92
|
-
* BEFORE deriving"). Deliberately unfiltered by {@link isTrackableNode}: a
|
|
93
|
-
* hand-authored id on an element this pass wouldn't otherwise touch still
|
|
94
|
-
* occupies the namespace. */
|
|
95
|
-
function* declaredIds(root: P5Node): Generator<string> {
|
|
96
|
-
for (const child of root.childNodes ?? []) {
|
|
97
|
-
if (isElement(child)) {
|
|
98
|
-
const value = child.attrs?.find((a) => a.name === TRACKING_ATTR_EL)?.value?.trim();
|
|
99
|
-
if (value) yield value;
|
|
100
|
-
}
|
|
101
|
-
yield* declaredIds(child);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Walk the tree in document order, yielding every trackable element with its
|
|
107
|
-
* ancestor stack (OUTERMOST first — the derivation engine's own contract).
|
|
108
|
-
*/
|
|
109
|
-
function* candidates(
|
|
110
|
-
root: P5Node,
|
|
111
|
-
ancestors: readonly P5Node[] = [],
|
|
112
|
-
): Generator<{ node: P5Node; ancestors: readonly P5Node[] }> {
|
|
113
|
-
for (const child of root.childNodes ?? []) {
|
|
114
|
-
if (isElement(child)) {
|
|
115
|
-
if (isTrackableNode(toStructuralNode(child))) {
|
|
116
|
-
yield { node: child, ancestors };
|
|
117
|
-
}
|
|
118
|
-
yield* candidates(child, [...ancestors, child]);
|
|
119
|
-
} else {
|
|
120
|
-
yield* candidates(child, ancestors);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Whether `html` looks like a full document (vs. a body-only fragment). */
|
|
126
|
-
function isFullDocument(html: string): boolean {
|
|
127
|
-
return /^\s*(<!doctype\s|<html[\s>])/i.test(html);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Propose (and write) `data-tot-el` for every undeclared trackable element in
|
|
132
|
-
* `html`. Pure: no I/O, no network. `confidence: "declared"` elements are
|
|
133
|
-
* returned in `proposals` for a complete review listing but are NEVER mutated —
|
|
134
|
-
* a declared identity is permanent (per the derivation engine's own contract).
|
|
135
|
-
*
|
|
136
|
-
* `html` may be a full tenant document (`content/home.html`, doctype + `<html>`)
|
|
137
|
-
* or a body-only fragment (`content/<tenant>/pages-html/<slug>.html`) — detected
|
|
138
|
-
* automatically so one function serves both writeback call sites.
|
|
139
|
-
*/
|
|
140
|
-
export function deriveTrackingWriteback(
|
|
141
|
-
html: string,
|
|
142
|
-
options?: DerivationOptions,
|
|
143
|
-
): TrackingWritebackResult {
|
|
144
|
-
const fullDocument = isFullDocument(html);
|
|
145
|
-
const root = (fullDocument ? parse(html) : parseFragment(html)) as unknown as P5Node;
|
|
146
|
-
|
|
147
|
-
const deriver = createTrackingIdDeriver(options);
|
|
148
|
-
for (const id of declaredIds(root)) deriver.reserve(id);
|
|
149
|
-
|
|
150
|
-
const proposals: TrackingWritebackProposal[] = [];
|
|
151
|
-
let changed = false;
|
|
152
|
-
|
|
153
|
-
for (const { node, ancestors } of candidates(root)) {
|
|
154
|
-
const structural = toStructuralNode(node);
|
|
155
|
-
const alreadyDeclared = Boolean(structural.attrs?.[TRACKING_ATTR_EL]?.trim());
|
|
156
|
-
const derived = deriver.derive({
|
|
157
|
-
node: structural,
|
|
158
|
-
ancestors: ancestors.map(toStructuralNode),
|
|
159
|
-
});
|
|
160
|
-
proposals.push({
|
|
161
|
-
el: derived.el,
|
|
162
|
-
confidence: derived.confidence,
|
|
163
|
-
signals: derived.signals,
|
|
164
|
-
needsReview: derived.needsReview,
|
|
165
|
-
alreadyDeclared,
|
|
166
|
-
tag: structural.tag,
|
|
167
|
-
snippet: openTagSnippet(structural),
|
|
168
|
-
});
|
|
169
|
-
if (alreadyDeclared) continue; // declared verbatim — never overwritten
|
|
170
|
-
node.attrs = [...(node.attrs ?? []), { name: TRACKING_ATTR_EL, value: derived.el }];
|
|
171
|
-
changed = true;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return { html: changed ? serialize(root as never) : html, changed, proposals };
|
|
175
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* dt-id-writeback — turns {@link deriveTrackingWriteback} proposals for one or
|
|
3
|
-
* more tenant body documents into the SAME reviewable-candidate shape the admin
|
|
4
|
-
* Blog tab already rides (`pages/api/admin/blog.ts`): a content-only
|
|
5
|
-
* {@link FileChange} patch opened via `ChangeClient.openCandidate`, so a human
|
|
6
|
-
* reviews a real PR diff and accepts it — never a silent runtime mutation.
|
|
7
|
-
*
|
|
8
|
-
* This module is pure (no MCP call, no ChangeClient dependency) so the patch +
|
|
9
|
-
* PR body construction is unit-testable without a live forge; the route that
|
|
10
|
-
* calls `openCandidate` is a thin wrapper (see the sibling API route).
|
|
11
|
-
*/
|
|
12
|
-
import { deriveTrackingWriteback, type TrackingWritebackProposal } from "./rewriteTrackingIds.js";
|
|
13
|
-
import type { DerivationOptions } from "@tot/public-runtime";
|
|
14
|
-
|
|
15
|
-
/** One tenant body document to scan — repo-relative path + its current content. */
|
|
16
|
-
export interface WritebackSourceFile {
|
|
17
|
-
/** e.g. "content/home.html" or "content/acme/pages-html/pricing.html". */
|
|
18
|
-
path: string;
|
|
19
|
-
content: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** One file this writeback pass actually changed, plus its full proposal list. */
|
|
23
|
-
export interface WritebackFileResult {
|
|
24
|
-
path: string;
|
|
25
|
-
content: string;
|
|
26
|
-
proposals: readonly TrackingWritebackProposal[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface WritebackCandidatePlan {
|
|
30
|
-
/** Files that gained at least one new `data-tot-el` — the `FileChange` patch. */
|
|
31
|
-
patch: { path: string; content: string }[];
|
|
32
|
-
/** Every changed file's full proposal list, for the PR body + a caller's own reporting. */
|
|
33
|
-
files: WritebackFileResult[];
|
|
34
|
-
/** True iff `patch` is non-empty — nothing to open when false. */
|
|
35
|
-
hasChanges: boolean;
|
|
36
|
-
/** Count of `needsReview: true` rows across every changed file — the review flag. */
|
|
37
|
-
needsReviewCount: number;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Run the derivation writeback over every source file and assemble the patch a
|
|
42
|
-
* candidate PR would carry. Files with no undeclared trackable elements (already
|
|
43
|
-
* fully migrated, or nothing trackable) are omitted from `patch` entirely — this
|
|
44
|
-
* never proposes a no-op change.
|
|
45
|
-
*/
|
|
46
|
-
export function planTrackingWriteback(
|
|
47
|
-
sources: readonly WritebackSourceFile[],
|
|
48
|
-
options?: DerivationOptions,
|
|
49
|
-
): WritebackCandidatePlan {
|
|
50
|
-
const files: WritebackFileResult[] = [];
|
|
51
|
-
const patch: { path: string; content: string }[] = [];
|
|
52
|
-
let needsReviewCount = 0;
|
|
53
|
-
|
|
54
|
-
for (const source of sources) {
|
|
55
|
-
const result = deriveTrackingWriteback(source.content, options);
|
|
56
|
-
if (!result.changed) continue;
|
|
57
|
-
files.push({ path: source.path, content: result.html, proposals: result.proposals });
|
|
58
|
-
patch.push({ path: source.path, content: result.html });
|
|
59
|
-
needsReviewCount += result.proposals.filter((p) => p.needsReview && !p.alreadyDeclared).length;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return { patch, files, hasChanges: patch.length > 0, needsReviewCount };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Render the candidate PR's body: a per-file listing of every NEWLY-assigned
|
|
67
|
-
* `data-tot-el`, with `needsReview: true` rows called out in their own section
|
|
68
|
-
* (per the derivation engine's own design intent — a positional id is the one a
|
|
69
|
-
* human should rename before accepting). `signals` is the diff annotation.
|
|
70
|
-
*/
|
|
71
|
-
export function formatWritebackReviewBody(plan: WritebackCandidatePlan): string {
|
|
72
|
-
const lines: string[] = [
|
|
73
|
-
"Derived `data-tot-el` identity for tenant-authored body elements that had none.",
|
|
74
|
-
"`confidence: \"declared\"` elements are untouched (never overwritten).",
|
|
75
|
-
"",
|
|
76
|
-
];
|
|
77
|
-
|
|
78
|
-
const needsReview = plan.files.flatMap((f) =>
|
|
79
|
-
f.proposals
|
|
80
|
-
.filter((p) => p.needsReview && !p.alreadyDeclared)
|
|
81
|
-
.map((p) => ({ file: f.path, proposal: p })),
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
if (needsReview.length > 0) {
|
|
85
|
-
lines.push(
|
|
86
|
-
`## ⚠ Needs review — ${needsReview.length} element${needsReview.length === 1 ? "" : "s"} named by position`,
|
|
87
|
-
"",
|
|
88
|
-
"These derived ids leaned on sibling order (no author-chosen name, class, or link found). " +
|
|
89
|
-
"Rename them to something meaningful before accepting.",
|
|
90
|
-
"",
|
|
91
|
-
);
|
|
92
|
-
for (const { file, proposal } of needsReview) {
|
|
93
|
-
lines.push(`- \`${file}\`: \`${proposal.el}\` — ${proposal.snippet} _(${proposal.signals.join(", ")})_`);
|
|
94
|
-
}
|
|
95
|
-
lines.push("");
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
for (const file of plan.files) {
|
|
99
|
-
const assigned = file.proposals.filter((p) => !p.alreadyDeclared);
|
|
100
|
-
if (assigned.length === 0) continue;
|
|
101
|
-
lines.push(`## \`${file.path}\` — ${assigned.length} id${assigned.length === 1 ? "" : "s"} assigned`, "");
|
|
102
|
-
for (const p of assigned) {
|
|
103
|
-
const flag = p.needsReview ? "⚠ " : "";
|
|
104
|
-
lines.push(`- ${flag}\`${p.el}\` (${p.confidence}) — ${p.snippet} _(${p.signals.join(", ")})_`);
|
|
105
|
-
}
|
|
106
|
-
lines.push("");
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return lines.join("\n").trimEnd() + "\n";
|
|
110
|
-
}
|