@tokenoftrust/storefront-runner 6.12.5 → 6.12.7

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.
@@ -208,7 +208,8 @@ export type RegistryErrorCode =
208
208
  | "invalid_webhook_endpoint"
209
209
  | "invalid_widget_placement"
210
210
  | "unknown_version"
211
- | "invalid_version_facets";
211
+ | "invalid_version_facets"
212
+ | "invalid_manifest";
212
213
 
213
214
  /**
214
215
  * `install()`'s return: the install row PLUS the one-time client credential
@@ -404,6 +405,37 @@ export function resolveVersionFacets(args: {
404
405
  };
405
406
  }
406
407
 
408
+ const CLIENT_AUTH_MEMBERS = new Set(["method", "jwks", "jwksUri"]);
409
+ const PUBLIC_JWK_MEMBERS = new Set(["kty", "kid", "alg", "use", "n", "e", "crv", "x", "y"]);
410
+
411
+ /**
412
+ * Why a manifest's `clientAuth` is refused, or `null`. A `clientAuth` names public key material
413
+ * only: `method`, a `jwksUri` string, or a `jwks` of `{keys}` whose members are public JWK members.
414
+ * A private member (`d`, `p`, `k`, ...) or any member the contract does not name is refused, so no
415
+ * install or update stores private key material in a manifest.
416
+ */
417
+ export function clientAuthViolation(manifest: unknown): string | null {
418
+ const root = asObject(manifest);
419
+ if (!root || !("clientAuth" in root)) return null;
420
+ const clientAuth = asObject(root.clientAuth);
421
+ if (!clientAuth) return "manifest.clientAuth must be an object";
422
+ const unknown = Object.keys(clientAuth).find((key) => !CLIENT_AUTH_MEMBERS.has(key));
423
+ if (unknown !== undefined) return `manifest.clientAuth.${unknown} is not a clientAuth member`;
424
+ if (clientAuth.jwksUri !== undefined && typeof clientAuth.jwksUri !== "string") return "manifest.clientAuth.jwksUri must be a string";
425
+ if (clientAuth.jwks === undefined) return null;
426
+ const jwks = asObject(clientAuth.jwks);
427
+ if (!jwks || !Array.isArray(jwks.keys) || Object.keys(jwks).some((key) => key !== "keys")) {
428
+ return "manifest.clientAuth.jwks must be {keys: [...]}";
429
+ }
430
+ for (const [index, key] of (jwks.keys as unknown[]).entries()) {
431
+ const jwk = asObject(key);
432
+ if (!jwk) return `manifest.clientAuth.jwks.keys[${index}] must be an object`;
433
+ const member = Object.keys(jwk).find((name) => !PUBLIC_JWK_MEMBERS.has(name));
434
+ if (member !== undefined) return `manifest.clientAuth.jwks.keys[${index}].${member} is not a public key member`;
435
+ }
436
+ return null;
437
+ }
438
+
407
439
  function asObject(value: unknown): Record<string, unknown> | undefined {
408
440
  return value !== null && typeof value === "object" && !Array.isArray(value)
409
441
  ? (value as Record<string, unknown>)
@@ -479,6 +511,7 @@ export class AppRegistryService {
479
511
  );
480
512
  }
481
513
 
514
+ this.assertPublicClientAuth(input.manifest);
482
515
  if (input.webhookEndpoint != null) this.assertValidWebhookEndpoint(input.webhookEndpoint);
483
516
  const widgetPlacements = this.assertValidWidgetPlacements(input.widgetPlacements, validation.scopes);
484
517
 
@@ -607,6 +640,7 @@ export class AppRegistryService {
607
640
  effectiveScopes = validation.scopes;
608
641
  }
609
642
 
643
+ if (patch.manifest !== undefined) this.assertPublicClientAuth(patch.manifest);
610
644
  if (patch.webhookEndpoint != null) this.assertValidWebhookEndpoint(patch.webhookEndpoint);
611
645
  const widgetPlacements =
612
646
  patch.widgetPlacements !== undefined
@@ -782,6 +816,12 @@ export class AppRegistryService {
782
816
  * guarantee as `validateScopes` above. Never called for a `null`/absent
783
817
  * endpoint — that's still allowed (a webhook target is optional).
784
818
  */
819
+ /** Shared gate for `install`/`update`: refuse a manifest `clientAuth` carrying anything but public key material. */
820
+ private assertPublicClientAuth(manifest: unknown): void {
821
+ const violation = clientAuthViolation(manifest);
822
+ if (violation !== null) throw new RegistryError(`Invalid manifest: ${violation}.`, "invalid_manifest");
823
+ }
824
+
785
825
  private assertValidWebhookEndpoint(webhookEndpoint: string): void {
786
826
  const validation = validateWebhookEndpoint(webhookEndpoint);
787
827
  if (!validation.ok) {
@@ -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.7",
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",