@tokenoftrust/storefront-runner 7.6.10 → 7.6.12

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.
@@ -298,7 +298,7 @@ export function readCatalogFiles(entries, { tenantScope, inventoryProvider }) {
298
298
  // LISTING_DESCRIPTION_CHARS) plus every collection whole, or, when any file fails validation, the
299
299
  // failures. A product page reads its full file.
300
300
 
301
- /** Version of the projection document; a reader refuses any other. */
301
+ /** Version of the projection document written by this build; readers accept version 1..CATALOG_LISTING_VERSION. */
302
302
  export const CATALOG_LISTING_VERSION = 2;
303
303
  /** Metafield namespaces a listing keeps: the compliance classification a listing's readiness and gates read. */
304
304
  export const LISTING_METAFIELD_NAMESPACES = Object.freeze(["compliance", "bigcommerce_custom"]);
@@ -406,7 +406,13 @@ export function readCatalogListing(raw, { tenantScope, inventoryProvider }) {
406
406
  } catch {
407
407
  doc = null;
408
408
  }
409
- if (!isObject(doc) || doc.version !== CATALOG_LISTING_VERSION) {
409
+ if (
410
+ !isObject(doc) ||
411
+ typeof doc.version !== "number" ||
412
+ !Number.isInteger(doc.version) ||
413
+ doc.version < 1 ||
414
+ doc.version > CATALOG_LISTING_VERSION
415
+ ) {
410
416
  throw new CatalogFileError([
411
417
  { path: "catalog/", issues: ["the catalog listing projection is unreadable; reconcile the preview again"] },
412
418
  ]);
@@ -13,6 +13,7 @@ export type { AgentRoleId };
13
13
  export const PREVIEW_VIEW_ROLE = "preview:view" as const satisfies AgentRoleId;
14
14
  export const ADMIN_READ_ROLE = "admin:read" as const satisfies AgentRoleId;
15
15
  export const ORDERS_FULFIL_BY_ID_ROLE = "orders:fulfil-by-id" as const satisfies AgentRoleId;
16
+ export const PROPOSALS_WRITE_ROLE = "proposals:write" as const satisfies AgentRoleId;
16
17
  export const ORDERS_READ_HOLDS_ROLE = "orders:read-holds" as const satisfies AgentRoleId;
17
18
 
18
19
  /** True when the catalog permits the role and the grant names it exactly. */
@@ -34,6 +34,7 @@ import {
34
34
  agentHoldsRole,
35
35
  ORDERS_FULFIL_BY_ID_ROLE,
36
36
  ORDERS_READ_HOLDS_ROLE,
37
+ PROPOSALS_WRITE_ROLE,
37
38
  type AgentRoleId,
38
39
  } from "./agentRoles.js";
39
40
 
@@ -60,6 +61,7 @@ export const AGENT_ROLE_ROUTES: ReadonlyArray<{ method: string; path: string; ro
60
61
  { method: "GET", path: "/api/admin/purchasing/orders", role: ADMIN_READ_ROLE },
61
62
  { method: "GET", path: "/api/admin/purchasing/orders/:id", role: ADMIN_READ_ROLE },
62
63
  { method: "POST", path: "/api/admin/fulfillment/fulfil-by-id", role: ORDERS_FULFIL_BY_ID_ROLE },
64
+ { method: "POST", path: "/api/admin/proposals", role: PROPOSALS_WRITE_ROLE },
63
65
  { method: "GET", path: "/api/admin/hold-reasons", role: ORDERS_READ_HOLDS_ROLE },
64
66
  ];
65
67
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  /** The vendored artifact's schema and the digest tot20 stamped on it. */
7
7
  export const CAPABILITY_CATALOG_SCHEMA = "tot.capability-catalog/v1" as const;
8
- export const CAPABILITY_CATALOG_DIGEST = "sha256:ad601b987e2dc989aeaae1315d451cbce5d9b824393eebba409aa36fee1e2089" as const;
8
+ export const CAPABILITY_CATALOG_DIGEST = "sha256:0325d1d04b03c03895d741463c587354c9bf99e992b526bc52cb68132f5429b6" as const;
9
9
 
10
10
  /** Every capability row id the catalog names. */
11
11
  export const CATALOG_CAPABILITY_IDS = [
@@ -84,6 +84,8 @@ export const CATALOG_CAPABILITY_IDS = [
84
84
  "orders:read-recipient",
85
85
  "orders:webhook",
86
86
  "preview:view",
87
+ "proposal-events:read",
88
+ "proposals:write",
87
89
  "purchasing:read",
88
90
  "purchasing:write",
89
91
  "reports:read",
@@ -130,6 +132,7 @@ export const AGENT_ROLE_IDS = [
130
132
  "orders:fulfil-by-id",
131
133
  "orders:read-holds",
132
134
  "preview:view",
135
+ "proposals:write",
133
136
  ] as const satisfies readonly CatalogCapabilityId[];
134
137
  export type AgentRoleId = (typeof AGENT_ROLE_IDS)[number];
135
138
 
@@ -146,6 +149,7 @@ export const APP_AUDIENCE_CAPABILITY_IDS = [
146
149
  "orders:read-minimal",
147
150
  "orders:read-recipient",
148
151
  "orders:webhook",
152
+ "proposal-events:read",
149
153
  "purchasing:read",
150
154
  "purchasing:write",
151
155
  "reports:read",
@@ -165,6 +169,7 @@ export const PRIVATE_APP_SCOPE_IDS = [
165
169
  "orders:read-minimal",
166
170
  "orders:read-recipient",
167
171
  "orders:webhook",
172
+ "proposal-events:read",
168
173
  "purchasing:read",
169
174
  "purchasing:write",
170
175
  "reports:read",
@@ -516,7 +516,7 @@ export class AppRegistryService {
516
516
  const widgetPlacements = this.assertValidWidgetPlacements(input.widgetPlacements, validation.scopes);
517
517
 
518
518
  const existing = await this.findRowByAppTenantEnv(input.appId, ctx.tenantId, input.env);
519
- if (existing) {
519
+ if (existing && existing.status !== "uninstalled") {
520
520
  throw new RegistryError(
521
521
  `App "${input.appId}" is already installed for this tenant/env.`,
522
522
  "already_installed",
@@ -533,24 +533,63 @@ export class AppRegistryService {
533
533
  override: input.versionFacets,
534
534
  });
535
535
 
536
- const installId = crypto.randomUUID();
536
+ const installId = existing ? existing.install_id : crypto.randomUUID();
537
537
  const now = this.now();
538
- await this.db.run(
539
- `INSERT INTO app_installs (${INSTALL_ROW_COLUMNS}) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)`,
540
- ...installRowParams({
541
- installId,
542
- appId: input.appId,
543
- appVersion: facets.appVersion,
544
- tenantId: ctx.tenantId,
545
- env: input.env,
546
- scopes: validation.scopes,
547
- manifest: input.manifest,
548
- webhookEndpoint: input.webhookEndpoint ?? null,
549
- widgetPlacements,
550
- actor: ctx.actor,
538
+ if (existing) {
539
+ await this.db.run(
540
+ `UPDATE app_installs
541
+ SET app_version = ?, status = 'active', scopes = ?, manifest = ?,
542
+ webhook_endpoint = ?, widget_placements = ?, install_actor = ?, updated_at = ?
543
+ WHERE install_id = ?`,
544
+ facets.appVersion,
545
+ JSON.stringify(validation.scopes),
546
+ JSON.stringify(input.manifest),
547
+ input.webhookEndpoint ?? null,
548
+ JSON.stringify(widgetPlacements),
549
+ ctx.actor,
551
550
  now,
552
- }),
553
- );
551
+ installId,
552
+ );
553
+ } else {
554
+ await this.db.run(
555
+ `INSERT INTO app_installs (${INSTALL_ROW_COLUMNS}) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)`,
556
+ ...installRowParams({
557
+ installId,
558
+ appId: input.appId,
559
+ appVersion: facets.appVersion,
560
+ tenantId: ctx.tenantId,
561
+ env: input.env,
562
+ scopes: validation.scopes,
563
+ manifest: input.manifest,
564
+ webhookEndpoint: input.webhookEndpoint ?? null,
565
+ widgetPlacements,
566
+ actor: ctx.actor,
567
+ now,
568
+ }),
569
+ );
570
+ }
571
+
572
+ const rollbackInstallRow = async () => {
573
+ if (existing) {
574
+ await this.db.run(
575
+ `UPDATE app_installs
576
+ SET app_version = ?, status = ?, scopes = ?, manifest = ?,
577
+ webhook_endpoint = ?, widget_placements = ?, install_actor = ?, updated_at = ?
578
+ WHERE install_id = ?`,
579
+ existing.app_version,
580
+ existing.status,
581
+ existing.scopes,
582
+ existing.manifest,
583
+ existing.webhook_endpoint,
584
+ existing.widget_placements,
585
+ existing.install_actor,
586
+ existing.updated_at,
587
+ installId,
588
+ );
589
+ } else {
590
+ await this.db.run(`DELETE FROM app_installs WHERE install_id = ?`, installId);
591
+ }
592
+ };
554
593
 
555
594
  let issued: IssuedCredentialSecret;
556
595
  try {
@@ -560,7 +599,7 @@ export class AppRegistryService {
560
599
  // issuance failed AFTER that — delete it (and skip the audit row) so no
561
600
  // orphaned "active" install with no credential ever survives. Matches
562
601
  // the scope-denied path's guarantee: a failed install leaves no trace.
563
- await this.db.run(`DELETE FROM app_installs WHERE install_id = ?`, installId);
602
+ await rollbackInstallRow();
564
603
  throw cause;
565
604
  }
566
605
 
@@ -577,7 +616,7 @@ export class AppRegistryService {
577
616
  });
578
617
  } catch (cause) {
579
618
  await this.credentials.clear(installId).catch(() => {});
580
- await this.db.run(`DELETE FROM app_installs WHERE install_id = ?`, installId);
619
+ await rollbackInstallRow();
581
620
  throw this.asRegistryError(cause);
582
621
  }
583
622
 
@@ -3,7 +3,7 @@
3
3
  * `tot_preview` cookies), shared by every middleware layer that consults it: the
4
4
  * front door's static passthrough and mirror stage, the control-plane gate, and the
5
5
  * render chain. A presented context is verified by `requireValidPreviewToken` and
6
- * never degrades to "absent" (except a cookie-only expired token, below); the control plane and the render chain refuse it with
6
+ * never degrades to "absent" (except a cookie-only expired or wrong-tenant token, below); the control plane and the render chain refuse it with
7
7
  * `previewContextRefusalResponse` before any publication, page-cache, rewrite-target
8
8
  * or source resolution.
9
9
  *
@@ -61,11 +61,16 @@ export async function resolveRequestPreviewContext(
61
61
  secret: input.secret,
62
62
  nowSeconds: input.nowSeconds,
63
63
  });
64
- // A `tot_preview` cookie alone that has merely expired grants nothing and proves no
65
- // tampering: it reads as absent, so the viewer falls back to session or public
66
- // access instead of a dead-end 403. Any presented `__preview` query value, and every
67
- // other refusal (bad signature, wrong tenant, ambiguity), still refuses.
68
- if (context.status === "refused" && context.reason === "expired" && queryValues.length === 0) {
64
+ // A `tot_preview` cookie alone that has expired or belongs to another tenant on
65
+ // a shared host grants nothing and proves no tampering: it reads as absent, so
66
+ // the viewer falls back to session or public access instead of a dead-end 403.
67
+ // Any presented `__preview` query value, and every other refusal (bad signature,
68
+ // malformed, empty, duplicate, ambiguity, unavailable verifier), still refuses.
69
+ if (
70
+ context.status === "refused" &&
71
+ (context.reason === "expired" || context.reason === "wrong-tenant") &&
72
+ queryValues.length === 0
73
+ ) {
69
74
  return { context: { status: "absent" }, presented, cookieValue: null };
70
75
  }
71
76
  if (
@@ -20,7 +20,7 @@ const { tenant, tot, basePath, features } = Astro.locals;
20
20
  // A handful of collections to redirect lost visitors toward. Marketing tenants
21
21
  // (features.catalog === false) have no /collections route at all — skip the
22
22
  // fetch entirely rather than trust it to come back empty.
23
- const collections = features.catalog ? (await tot.listCollections()).slice(0, 3) : [];
23
+ const collections = features.catalog ? (await tot.listCollections().catch(() => [])).slice(0, 3) : [];
24
24
  ---
25
25
 
26
26
  <Layout
@@ -25,6 +25,17 @@ const { tenant, canonicalBase, content, basePath, apiBasePath, capabilities, fea
25
25
  Astro.locals;
26
26
  const slug = (Astro.params.slug ?? "").replace(/^\/+|\/+$/g, "");
27
27
 
28
+ // Astro's DefaultErrorHandler falls back to this catch-all when no 500 route exists,
29
+ // passing `{ error }` in Astro.props with status 500. Preserve the 500 instead of
30
+ // returning a body-less 404, which DefaultErrorHandler.mergeResponses would otherwise
31
+ // use to overwrite the 500 with an empty 404.
32
+ if ("error" in Astro.props || Astro.response.status === 500) {
33
+ return new Response("Internal Server Error", {
34
+ status: 500,
35
+ headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" },
36
+ });
37
+ }
38
+
28
39
  // Defensive: never let the catch-all answer for first-class route namespaces.
29
40
  // (Keeps the commerce boundary hard — a marketing subpage can never shadow a
30
41
  // product/collection route.)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "7.6.10",
3
+ "version": "7.6.12",
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",