@tokenoftrust/storefront-runner 6.12.5 → 6.12.6

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.
@@ -182,16 +182,27 @@ export function availabilitySyncStatements(input: {
182
182
  deliveryStatement({ tenantId, stage, now: input.now, idEquals: "", idPrefix: `${input.token}.` }),
183
183
  );
184
184
  }
185
+ // Freshness of the stored availability: a recompute that moves the number (or first stores it) is
186
+ // as of the later of the newest ledger observation and this transition, so an accepted location or
187
+ // reservation change reads as fresh; an unchanged recompute keeps the later of the stored and ledger
188
+ // stamps, so a no-op write never refreshes stale mirror data.
185
189
  statements.push({
186
190
  sql: `${computed}
187
191
  INSERT INTO commerce_inventory_availability (tenant_id, stage, sku, available, version, as_of)
188
- SELECT ?, ?, computed.sku, computed.available, 1, computed.as_of FROM computed WHERE computed.as_of IS NOT NULL
192
+ SELECT ?, ?, computed.sku, computed.available, 1,
193
+ CASE WHEN av.sku IS NOT NULL AND av.available = computed.available
194
+ THEN CASE WHEN julianday(av.as_of) >= julianday(computed.as_of) THEN av.as_of ELSE computed.as_of END
195
+ ELSE CASE WHEN julianday(computed.as_of) >= julianday(?) THEN computed.as_of ELSE ? END
196
+ END
197
+ FROM computed LEFT JOIN commerce_inventory_availability AS av
198
+ ON av.tenant_id = ? AND av.stage = ? AND av.sku = computed.sku
199
+ WHERE computed.as_of IS NOT NULL
189
200
  ON CONFLICT (tenant_id, stage, sku) DO UPDATE SET
190
201
  version = CASE WHEN commerce_inventory_availability.available != excluded.available
191
202
  THEN commerce_inventory_availability.version + 1 ELSE commerce_inventory_availability.version END,
192
203
  available = excluded.available,
193
204
  as_of = excluded.as_of`,
194
- params: [...computedParams, tenantId, stage],
205
+ params: [...computedParams, tenantId, stage, input.now, input.now, tenantId, stage],
195
206
  });
196
207
  return statements;
197
208
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "6.12.5",
3
+ "version": "6.12.6",
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",