@tokenoftrust/storefront-runner 7.6.16 → 7.6.18

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.
@@ -1,12 +1,14 @@
1
1
  /**
2
- * `GET /api/contact/token` — a fresh signed submit token for this tenant's
3
- * contact form (`lib/engagement/contact/submitToken.ts`). Without
4
- * `CONTACT_FORM_TOKEN_SECRET` the form cannot work, so this answers 503 rather
2
+ * `GET /api/contact/token[?form=contact|bulk-quote]` — a fresh signed submit token
3
+ * for one of this tenant's public forms (`lib/engagement/contact/submitToken.ts`).
4
+ * The token is bound to the form, so a contact token cannot submit a bulk quote and
5
+ * the reverse. No `form` means the contact form; an unknown one is 400. Without
6
+ * `CONTACT_FORM_TOKEN_SECRET` the forms cannot work, so this answers 503 rather
5
7
  * than handing out an unsigned token.
6
8
  */
7
9
  import type { APIContext } from "astro";
8
10
  import { readEnv } from "@/lib/publication/shared/env";
9
- import { issueContactToken } from "@/lib/engagement/contact/submitToken";
11
+ import { issueContactToken, isContactFormKind } from "@/lib/engagement/contact/submitToken";
10
12
 
11
13
  export const prerender = false;
12
14
 
@@ -19,11 +21,15 @@ const HEADERS = {
19
21
  export async function GET(context: APIContext): Promise<Response> {
20
22
  const tenantId = context.locals?.tenant?.tenant_id;
21
23
  if (!tenantId) return new Response(JSON.stringify({ ok: false, error: "not_found" }), { status: 404, headers: HEADERS });
24
+ const requested = new URL(context.request.url).searchParams.get("form") ?? "contact";
25
+ if (!isContactFormKind(requested)) {
26
+ return new Response(JSON.stringify({ ok: false, error: "invalid_input" }), { status: 400, headers: HEADERS });
27
+ }
22
28
  const secret = await readEnv("CONTACT_FORM_TOKEN_SECRET");
23
29
  if (!secret) {
24
30
  console.log(`[contact] tenant=${tenantId} outcome=token_no_secret`);
25
31
  return new Response(JSON.stringify({ ok: false, error: "unavailable" }), { status: 503, headers: HEADERS });
26
32
  }
27
- const token = await issueContactToken(secret, tenantId);
33
+ const token = await issueContactToken(secret, tenantId, Date.now(), requested);
28
34
  return new Response(JSON.stringify({ ok: true, token }), { headers: HEADERS });
29
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "7.6.16",
3
+ "version": "7.6.18",
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",
@@ -10,6 +10,7 @@ import { extname, join, relative } from "node:path";
10
10
  import { workspacePathForTenantRelative } from "./tot-repo-mappings.mjs";
11
11
 
12
12
  const ERROR = "error";
13
+ const BULK_QUOTE_UNITS = ["each", "case", "gallon", "pail", "drum", "tote", "pound", "kilogram", "liter", "custom"];
13
14
  // Public routes implemented by the renderer. Authentication and cart URLs are
14
15
  // deliberately absent: they are flow-specific, not portable parity targets.
15
16
  const PLATFORM_ROUTES = ["/collections", "/collections/", "/products/", "/search", "/saved", "/account", "/account/", "/blog", "/blog/"];
@@ -256,8 +257,9 @@ function pageShape(value, file) {
256
257
  case "callout": if (!rich(section.body) || !["info", "warning", "legal", "success"].includes(section.tone) || section.title !== undefined && !string(section.title)) findings.push(finding("parity-section-shape", at, "callout requires supported tone, RichText body, and optional string title", "supply a valid callout")); break;
257
258
  case "contact": if (section.heading !== undefined && !string(section.heading) || section.email !== undefined && !string(section.email) || section.phone !== undefined && !string(section.phone) || section.address !== undefined && (!Array.isArray(section.address) || section.address.some((line) => !string(line))) || !string(section.email) && !string(section.phone) && !(Array.isArray(section.address) && section.address.length)) findings.push(finding("parity-section-shape", at, "contact requires string members and email, phone, or address", "supply valid contact details")); break;
258
259
  case "contact_form": if (["heading", "messageLabel", "submitLabel", "successMessage"].some((key) => section[key] !== undefined && !string(section[key])) || section.fields !== undefined && (!Array.isArray(section.fields) || section.fields.some((field) => field !== "name" && field !== "phone"))) findings.push(finding("parity-section-shape", at, "contact_form requires optional string copy and fields limited to name or phone", "supply a valid contact_form section")); break;
260
+ case "bulk_quote_form": if (["heading", "intro", "submitLabel", "successMessage"].some((key) => section[key] !== undefined && !string(section[key])) || section.units !== undefined && (!Array.isArray(section.units) || section.units.some((unit) => !BULK_QUOTE_UNITS.includes(unit)))) findings.push(finding("parity-section-shape", at, "bulk_quote_form requires optional string copy and units limited to the supported quote units", "supply a valid bulk_quote_form section")); break;
259
261
  case "needs_review": if (!string(section.reason) || section.severity !== undefined && !["blocker", "note"].includes(section.severity) || section.owner !== undefined && !string(section.owner) || section.href !== undefined && !string(section.href)) findings.push(finding("parity-section-shape", at, "needs_review requires reason and valid optional severity/owner/href", "supply a valid needs_review section")); break;
260
- default: findings.push(finding("parity-section-kind", `${at}/kind`, "section kind is not supported by the renderer", "use heading, paragraph, list, definitions, callout, contact, contact_form, or needs_review"));
262
+ default: findings.push(finding("parity-section-kind", `${at}/kind`, "section kind is not supported by the renderer", "use heading, paragraph, list, definitions, callout, contact, contact_form, bulk_quote_form, or needs_review"));
261
263
  }
262
264
  });
263
265
  const bodyHtml = typeof value.body_html === "string" && value.body_html.trim() !== "";