@tokenoftrust/storefront-runner 7.6.12 → 7.6.14

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.
@@ -114,34 +114,55 @@ function idMatchParams(exact: string, prefix: string): string[] {
114
114
  return [exact, prefix, `${prefix.slice(0, -1)}/`];
115
115
  }
116
116
 
117
- /** Inserts a pending delivery for every eligible install of each inventory event of `topic` whose id matches. */
118
- function deliveryStatement(input: {
117
+ type InventoryEventTopic = typeof INVENTORY_CHANGED_TOPIC | typeof INVENTORY_STOCKTAKE_COMPLETED_TOPIC;
118
+
119
+ /**
120
+ * One statement inserting a pending delivery for every eligible install of each inventory event whose
121
+ * id and topic match any of `events`. A zero-row insert is a valid outcome.
122
+ */
123
+ export function inventoryDeliveriesStatement(input: {
119
124
  tenantId: string;
120
125
  stage: CommerceStage;
121
126
  now: string;
122
- idEquals: string;
123
- idPrefix: string;
124
- topic?: typeof INVENTORY_CHANGED_TOPIC | typeof INVENTORY_STOCKTAKE_COMPLETED_TOPIC;
127
+ events: readonly { idEquals: string; idPrefix: string; topic: InventoryEventTopic }[];
125
128
  }): SqlStatement {
126
- const topic = input.topic ?? INVENTORY_CHANGED_TOPIC;
129
+ if (input.events.length === 0) throw new Error("inventory-deliveries-need-an-event");
130
+ const matches = input.events.map(({ topic }) => `(${idMatchSql("e.id")} AND e.topic = '${topic}')`).join(" OR ");
127
131
  return {
128
132
  sql: `INSERT INTO webhook_deliveries
129
133
  (delivery_id, event_id, install_id, tenant_id, topic, state, attempts, created_at, updated_at)
130
- SELECT e.id || ':' || i.install_id, e.id, i.install_id, i.tenant_id, '${topic}', 'pending', 0, ?, ?
134
+ SELECT e.id || ':' || i.install_id, e.id, i.install_id, i.tenant_id, e.topic, 'pending', 0, ?, ?
131
135
  FROM webhook_events AS e JOIN app_installs AS i ON ${ELIGIBLE_INVENTORY_INSTALL_SQL}
132
- WHERE ${idMatchSql("e.id")} AND e.tenant_id = ? AND e.topic = '${topic}'
136
+ WHERE (${matches}) AND e.tenant_id = ?
133
137
  ON CONFLICT DO NOTHING`,
134
138
  params: [
135
139
  input.now,
136
140
  input.now,
137
141
  input.tenantId,
138
142
  appInstallEnvForStage(input.stage),
139
- ...idMatchParams(input.idEquals, input.idPrefix),
143
+ ...input.events.flatMap(({ idEquals, idPrefix }) => idMatchParams(idEquals, idPrefix)),
140
144
  input.tenantId,
141
145
  ],
142
146
  };
143
147
  }
144
148
 
149
+ /** Inserts a pending delivery for every eligible install of each inventory event of `topic` whose id matches. */
150
+ function deliveryStatement(input: {
151
+ tenantId: string;
152
+ stage: CommerceStage;
153
+ now: string;
154
+ idEquals: string;
155
+ idPrefix: string;
156
+ topic?: InventoryEventTopic;
157
+ }): SqlStatement {
158
+ return inventoryDeliveriesStatement({
159
+ tenantId: input.tenantId,
160
+ stage: input.stage,
161
+ now: input.now,
162
+ events: [{ idEquals: input.idEquals, idPrefix: input.idPrefix, topic: input.topic ?? INVENTORY_CHANGED_TOPIC }],
163
+ });
164
+ }
165
+
145
166
  /**
146
167
  * Statements appended to the same D1 batch as a state change that can move availability. For each
147
168
  * scoped sku the tenant's ledger holds, they recompute availability and store it in
@@ -30,6 +30,15 @@ import {
30
30
 
31
31
  declare const __GIT_SHA__: string | undefined;
32
32
 
33
+ /** Operational kill-switch env var for preview annotations, preview tours, and the feedback bridge. */
34
+ export const PREVIEW_FEEDBACK_DISABLED_ENV = "PREVIEW_FEEDBACK_DISABLED";
35
+
36
+ /** True for "1" / "on" / "true" / "yes" (case/space-insensitive); false otherwise. */
37
+ export function isPreviewFeedbackDisabled(raw: string | null | undefined): boolean {
38
+ const v = (raw ?? "").trim().toLowerCase();
39
+ return v === "1" || v === "on" || v === "true" || v === "yes";
40
+ }
41
+
33
42
  /**
34
43
  * A publication capture or materialization request: the capture probe header, or the Worker's
35
44
  * materialize binding (`MATERIALIZE_MODE_BINDING`) read as `"1"`. Never decorated, never handed
@@ -40,6 +49,7 @@ export function isPublicationCapture(headers: Headers, materializeMode: string |
40
49
  }
41
50
 
42
51
  export interface AnnotationModuleAccess {
52
+ disabled?: boolean;
43
53
  cdnForwarded: boolean;
44
54
  capture: boolean;
45
55
  secret: string | null;
@@ -53,7 +63,7 @@ export interface AnnotationModuleAccess {
53
63
  * and a capture or materialization request never qualify.
54
64
  */
55
65
  export async function mayLoadAnnotationModule(input: AnnotationModuleAccess): Promise<boolean> {
56
- if (input.cdnForwarded || input.capture || !input.secret) return false;
66
+ if (input.disabled || input.cdnForwarded || input.capture || !input.secret) return false;
57
67
  const cookie = input.cookies.get(PREVIEW_REVIEWER_COOKIE)?.value;
58
68
  return (await verifyReviewerCookieValue(input.secret, cookie)) !== null;
59
69
  }
@@ -65,6 +75,7 @@ export function renderingPlatformSha(): string | null {
65
75
  }
66
76
 
67
77
  export interface PreviewAnnotationDecoration {
78
+ disabled?: boolean;
68
79
  request: Request;
69
80
  customizationEnv: "live" | "test";
70
81
  /** The verified preview token this render rode in on, or null. */
@@ -107,7 +118,7 @@ async function previewKindAndRevision(
107
118
  export async function resolvePreviewAnnotationDocument(
108
119
  input: PreviewAnnotationDecoration,
109
120
  ): Promise<{ previewKind: PreviewKind; revision: string } | null> {
110
- if (input.cdnForwarded || input.request.method !== "GET" || input.capture ||
121
+ if (input.disabled || input.cdnForwarded || input.request.method !== "GET" || input.capture ||
111
122
  input.internalPublication || !input.secret) return null;
112
123
  const platformSha = input.platformSha === undefined ? renderingPlatformSha() : input.platformSha;
113
124
  if (!platformSha || !PLATFORM_SHA_PATTERN.test(platformSha)) return null;
@@ -38,7 +38,9 @@ import {
38
38
  } from "@/lib/publication/shared/previewReload";
39
39
  import {
40
40
  decoratePreviewAnnotations,
41
+ isPreviewFeedbackDisabled,
41
42
  isPublicationCapture,
43
+ PREVIEW_FEEDBACK_DISABLED_ENV,
42
44
  } from "@/lib/publication/shared/previewAnnotations/renderDecorator";
43
45
  import { tenantProtectedPrefixes } from "@/lib/publication/shared/previewAnnotations/protectedSurfaces";
44
46
  import {
@@ -897,6 +899,7 @@ export async function runRenderChain(input: RenderChainInput): Promise<Response>
897
899
  // decorator marks what it decorates `private, no-store`.
898
900
  let sharedRevision: Promise<string | null> | undefined;
899
901
  const previewDecoration = {
902
+ disabled: isPreviewFeedbackDisabled(await readEnv(PREVIEW_FEEDBACK_DISABLED_ENV)),
900
903
  request,
901
904
  customizationEnv: customization.env,
902
905
  previewToken,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "7.6.12",
3
+ "version": "7.6.14",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
6
6
  "packageManager": "pnpm@11.9.0",