@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.
- package/apps/storefront/src/components/content/storefront/content/BulkQuoteForm.astro +396 -0
- package/apps/storefront/src/components/content/storefront/content/ProseSections.astro +3 -0
- package/apps/storefront/src/lib/access/auth/agentSessionGate.ts +67 -0
- package/apps/storefront/src/lib/access/auth/loginGate.ts +30 -0
- package/apps/storefront/src/lib/access/auth/session.ts +12 -0
- package/apps/storefront/src/lib/content/prose.ts +36 -0
- package/apps/storefront/src/lib/engagement/contact/bulkQuote.ts +521 -0
- package/apps/storefront/src/lib/engagement/contact/submitToken.ts +29 -13
- package/apps/storefront/src/middleware/controlPlane.ts +8 -0
- package/apps/storefront/src/middleware/index.ts +8 -3
- package/apps/storefront/src/pages/api/contact/token.ts +11 -5
- package/package.json +1 -1
- package/packages/cli/src/visual-parity.mjs +3 -1
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* <BulkQuoteForm> — the `bulk_quote_form` page section: a wholesale quote request with
|
|
4
|
+
* a repeatable line-item list. Submissions go to the platform-owned JSON endpoint
|
|
5
|
+
* (contract: lib/engagement/contact/bulkQuote.ts), so the section carries copy and an
|
|
6
|
+
* optional unit subset only: no recipient, endpoint or script prop.
|
|
7
|
+
*
|
|
8
|
+
* The endpoint is JSON-only, so the form is revealed by script and visitors without JS
|
|
9
|
+
* see an explanatory note. Markup is static and escaped; the script builds line items by
|
|
10
|
+
* cloning the <template> row and writes every message with textContent.
|
|
11
|
+
*
|
|
12
|
+
* The endpoint is api-base-scoped (`apiBasePath`, never `basePath`, which a
|
|
13
|
+
* preview/candidate pin overrides with a render prefix that has no `/api` mirror). The
|
|
14
|
+
* markup is identical for every serving provider.
|
|
15
|
+
*/
|
|
16
|
+
import type { ProseBulkQuoteFormSection } from "@/lib/content/prose";
|
|
17
|
+
import { withBase } from "@/lib/publication/shared/basePath";
|
|
18
|
+
import { BULK_QUOTE_LIMITS, BULK_QUOTE_UNITS } from "@/lib/engagement/contact/bulkQuote";
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
section: ProseBulkQuoteFormSection;
|
|
22
|
+
/** Distinguishes ids when several forms share a page. */
|
|
23
|
+
index?: number;
|
|
24
|
+
}
|
|
25
|
+
const { section, index = 0 } = Astro.props;
|
|
26
|
+
const { apiBasePath } = Astro.locals;
|
|
27
|
+
const endpoint = withBase(apiBasePath ?? "", "/api/contact/bulk-quote");
|
|
28
|
+
const id = `bulk-quote-form-${index}`;
|
|
29
|
+
const L = BULK_QUOTE_LIMITS;
|
|
30
|
+
const declared: readonly string[] = Array.isArray(section.units) ? section.units : [];
|
|
31
|
+
const picked = BULK_QUOTE_UNITS.filter((u) => declared.includes(u));
|
|
32
|
+
const units = picked.length ? picked : BULK_QUOTE_UNITS;
|
|
33
|
+
const submitLabel = section.submitLabel ?? "Request a quote";
|
|
34
|
+
const successMessage = section.successMessage ?? "Thanks. We received your quote request.";
|
|
35
|
+
---
|
|
36
|
+
<section
|
|
37
|
+
class="bulk-quote"
|
|
38
|
+
data-bulk-quote-form
|
|
39
|
+
data-endpoint={endpoint}
|
|
40
|
+
data-success={successMessage}
|
|
41
|
+
data-max-items={L.lineItems}
|
|
42
|
+
aria-labelledby={section.heading ? `${id}-heading` : undefined}
|
|
43
|
+
>
|
|
44
|
+
{section.heading && <h2 id={`${id}-heading`} class="bulk-quote__heading">{section.heading}</h2>}
|
|
45
|
+
{section.intro && <p class="bulk-quote__intro">{section.intro}</p>}
|
|
46
|
+
<noscript>
|
|
47
|
+
<p class="bulk-quote__note">This quote form needs JavaScript. Enable it and reload, or use the contact details on this page.</p>
|
|
48
|
+
</noscript>
|
|
49
|
+
<form hidden novalidate data-bulk-quote-el>
|
|
50
|
+
<fieldset class="bulk-quote__group">
|
|
51
|
+
<legend>Your details</legend>
|
|
52
|
+
<div class="bulk-quote__field">
|
|
53
|
+
<label for={`${id}-businessName`}>Business name</label>
|
|
54
|
+
<input id={`${id}-businessName`} name="businessName" type="text" autocomplete="organization" required maxlength={L.businessName} />
|
|
55
|
+
</div>
|
|
56
|
+
<div class="bulk-quote__field">
|
|
57
|
+
<label for={`${id}-name`}>Your name</label>
|
|
58
|
+
<input id={`${id}-name`} name="name" type="text" autocomplete="name" required maxlength={L.name} />
|
|
59
|
+
</div>
|
|
60
|
+
<div class="bulk-quote__field">
|
|
61
|
+
<label for={`${id}-email`}>Email</label>
|
|
62
|
+
<input id={`${id}-email`} name="email" type="email" inputmode="email" autocomplete="email" required maxlength={L.email} />
|
|
63
|
+
</div>
|
|
64
|
+
<div class="bulk-quote__field">
|
|
65
|
+
<label for={`${id}-phone`}>Phone</label>
|
|
66
|
+
<input id={`${id}-phone`} name="phone" type="tel" inputmode="tel" autocomplete="tel" maxlength={L.phone} />
|
|
67
|
+
</div>
|
|
68
|
+
</fieldset>
|
|
69
|
+
|
|
70
|
+
<fieldset class="bulk-quote__group">
|
|
71
|
+
<legend>Items</legend>
|
|
72
|
+
<ol class="bulk-quote__items" data-bulk-quote-items></ol>
|
|
73
|
+
<button type="button" class="bulk-quote__add" data-bulk-quote-add>Add item</button>
|
|
74
|
+
</fieldset>
|
|
75
|
+
|
|
76
|
+
<fieldset class="bulk-quote__group">
|
|
77
|
+
<legend>Delivery</legend>
|
|
78
|
+
<div class="bulk-quote__field">
|
|
79
|
+
<label for={`${id}-destinationRegion`}>Destination state or region</label>
|
|
80
|
+
<input id={`${id}-destinationRegion`} name="destinationRegion" type="text" autocomplete="address-level1" maxlength={L.destinationRegion} />
|
|
81
|
+
</div>
|
|
82
|
+
<div class="bulk-quote__field">
|
|
83
|
+
<label for={`${id}-destinationPostalCode`}>Destination postal code</label>
|
|
84
|
+
<input id={`${id}-destinationPostalCode`} name="destinationPostalCode" type="text" autocomplete="postal-code" maxlength={L.destinationPostalCode} />
|
|
85
|
+
</div>
|
|
86
|
+
<div class="bulk-quote__field bulk-quote__field--check">
|
|
87
|
+
<input id={`${id}-liftgate`} name="liftgate" type="checkbox" />
|
|
88
|
+
<label for={`${id}-liftgate`}>Liftgate delivery needed</label>
|
|
89
|
+
</div>
|
|
90
|
+
<div class="bulk-quote__field">
|
|
91
|
+
<label for={`${id}-freightNotes`}>Freight notes</label>
|
|
92
|
+
<textarea id={`${id}-freightNotes`} name="freightNotes" rows="3" maxlength={L.freightNotes}></textarea>
|
|
93
|
+
</div>
|
|
94
|
+
</fieldset>
|
|
95
|
+
|
|
96
|
+
<fieldset class="bulk-quote__group">
|
|
97
|
+
<legend>Order details</legend>
|
|
98
|
+
<div class="bulk-quote__field">
|
|
99
|
+
<label for={`${id}-poNumber`}>PO number</label>
|
|
100
|
+
<input id={`${id}-poNumber`} name="poNumber" type="text" maxlength={L.poNumber} />
|
|
101
|
+
</div>
|
|
102
|
+
<div class="bulk-quote__field">
|
|
103
|
+
<label for={`${id}-timeline`}>Timeline</label>
|
|
104
|
+
<input id={`${id}-timeline`} name="timeline" type="text" maxlength={L.timeline} />
|
|
105
|
+
</div>
|
|
106
|
+
<div class="bulk-quote__field">
|
|
107
|
+
<label for={`${id}-notes`}>Notes</label>
|
|
108
|
+
<textarea id={`${id}-notes`} name="notes" rows="5" maxlength={L.notes}></textarea>
|
|
109
|
+
</div>
|
|
110
|
+
</fieldset>
|
|
111
|
+
|
|
112
|
+
<div class="bulk-quote__trap" aria-hidden="true">
|
|
113
|
+
<input name="company" type="text" tabindex="-1" autocomplete="off" />
|
|
114
|
+
</div>
|
|
115
|
+
<button type="submit" class="bulk-quote__submit">{submitLabel}</button>
|
|
116
|
+
</form>
|
|
117
|
+
<p class="bulk-quote__status" role="status" aria-live="polite" data-bulk-quote-status></p>
|
|
118
|
+
<p class="bulk-quote__ref" data-bulk-quote-ref hidden></p>
|
|
119
|
+
|
|
120
|
+
<template data-bulk-quote-row>
|
|
121
|
+
<li class="bulk-quote__item" data-bulk-quote-item>
|
|
122
|
+
<div class="bulk-quote__field">
|
|
123
|
+
<label>Description <textarea data-li="description" rows="2" required maxlength={L.description}></textarea></label>
|
|
124
|
+
</div>
|
|
125
|
+
<div class="bulk-quote__field">
|
|
126
|
+
<label>SKU <input data-li="sku" type="text" maxlength={L.sku} /></label>
|
|
127
|
+
</div>
|
|
128
|
+
<div class="bulk-quote__field">
|
|
129
|
+
<label>Quantity <input data-li="quantity" type="number" inputmode="decimal" min="0" max={L.quantityMax} step="any" required /></label>
|
|
130
|
+
</div>
|
|
131
|
+
<div class="bulk-quote__field">
|
|
132
|
+
<label>
|
|
133
|
+
Unit
|
|
134
|
+
<select data-li="unit">
|
|
135
|
+
{units.map((u) => <option value={u}>{u}</option>)}
|
|
136
|
+
</select>
|
|
137
|
+
</label>
|
|
138
|
+
</div>
|
|
139
|
+
<div class="bulk-quote__field">
|
|
140
|
+
<label>Pack size <input data-li="packSize" type="text" maxlength={L.packSize} /></label>
|
|
141
|
+
</div>
|
|
142
|
+
<button type="button" class="bulk-quote__remove" data-bulk-quote-remove>Remove item</button>
|
|
143
|
+
</li>
|
|
144
|
+
</template>
|
|
145
|
+
</section>
|
|
146
|
+
|
|
147
|
+
<style>
|
|
148
|
+
.bulk-quote { margin-top: 1.5rem; }
|
|
149
|
+
.bulk-quote__heading { font-family: var(--font-display, inherit); font-size: var(--heading-h2, 1.5rem); font-weight: 600; }
|
|
150
|
+
.bulk-quote__group { margin-top: 1.5rem; padding: 0; border: 0; }
|
|
151
|
+
.bulk-quote__group legend { font-weight: 700; padding: 0; }
|
|
152
|
+
.bulk-quote__items { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; }
|
|
153
|
+
.bulk-quote__item { padding: 1rem; border: 1px solid var(--color-border); border-radius: var(--radius-md, 0.375rem); }
|
|
154
|
+
.bulk-quote__field { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 1rem; }
|
|
155
|
+
.bulk-quote__field label { display: flex; flex-direction: column; gap: 0.35rem; font-weight: 600; }
|
|
156
|
+
.bulk-quote__field--check { flex-direction: row; align-items: center; }
|
|
157
|
+
.bulk-quote__field input:not([type="checkbox"]),
|
|
158
|
+
.bulk-quote__field textarea,
|
|
159
|
+
.bulk-quote__field select {
|
|
160
|
+
width: 100%;
|
|
161
|
+
padding: 0.65rem 0.8rem;
|
|
162
|
+
border: 1px solid var(--color-border);
|
|
163
|
+
border-radius: var(--radius-md, 0.375rem);
|
|
164
|
+
background: var(--color-surface);
|
|
165
|
+
color: var(--color-text);
|
|
166
|
+
font: inherit;
|
|
167
|
+
font-weight: 400;
|
|
168
|
+
}
|
|
169
|
+
.bulk-quote [aria-invalid="true"] { border-color: var(--color-danger, currentColor); }
|
|
170
|
+
.bulk-quote input:focus-visible,
|
|
171
|
+
.bulk-quote textarea:focus-visible,
|
|
172
|
+
.bulk-quote select:focus-visible,
|
|
173
|
+
.bulk-quote button:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
|
|
174
|
+
.bulk-quote__trap { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
|
|
175
|
+
.bulk-quote__add,
|
|
176
|
+
.bulk-quote__remove {
|
|
177
|
+
margin-top: 1rem;
|
|
178
|
+
min-height: var(--tap-target, 44px);
|
|
179
|
+
padding: 0.5rem 1.1rem;
|
|
180
|
+
border: 1px solid var(--color-border);
|
|
181
|
+
border-radius: var(--radius-md, 0.375rem);
|
|
182
|
+
background: var(--color-surface);
|
|
183
|
+
color: var(--color-text);
|
|
184
|
+
font: inherit;
|
|
185
|
+
cursor: pointer;
|
|
186
|
+
}
|
|
187
|
+
.bulk-quote__add[disabled] { opacity: 0.6; cursor: not-allowed; }
|
|
188
|
+
.bulk-quote__submit {
|
|
189
|
+
margin-top: 1.5rem;
|
|
190
|
+
min-height: var(--tap-target, 44px);
|
|
191
|
+
padding: 0.65rem 1.4rem;
|
|
192
|
+
border: 0;
|
|
193
|
+
border-radius: var(--radius-md, 0.375rem);
|
|
194
|
+
background: var(--color-accent);
|
|
195
|
+
color: var(--color-accent-contrast, var(--color-primary-contrast));
|
|
196
|
+
font: inherit;
|
|
197
|
+
font-weight: 700;
|
|
198
|
+
cursor: pointer;
|
|
199
|
+
}
|
|
200
|
+
.bulk-quote__submit[disabled] { opacity: 0.6; cursor: progress; }
|
|
201
|
+
.bulk-quote__status { margin-top: 1rem; min-height: 1.5em; color: var(--color-text); }
|
|
202
|
+
.bulk-quote__status[data-state="error"] { color: var(--color-danger, var(--color-text)); font-weight: 600; }
|
|
203
|
+
.bulk-quote__ref { font-weight: 600; }
|
|
204
|
+
.bulk-quote__note { color: var(--color-muted); }
|
|
205
|
+
</style>
|
|
206
|
+
|
|
207
|
+
<script>
|
|
208
|
+
import {
|
|
209
|
+
CONTACT_TOKEN_MAX_AGE_MS,
|
|
210
|
+
CONTACT_TOKEN_MIN_AGE_MS,
|
|
211
|
+
} from "@/lib/engagement/contact/contract";
|
|
212
|
+
import {
|
|
213
|
+
fetchBulkQuoteToken,
|
|
214
|
+
submitBulkQuote,
|
|
215
|
+
type BulkQuoteErrorCode,
|
|
216
|
+
type BulkQuoteSubmission,
|
|
217
|
+
type BulkQuoteUnit,
|
|
218
|
+
} from "@/lib/engagement/contact/bulkQuote";
|
|
219
|
+
|
|
220
|
+
const MESSAGES: Partial<Record<BulkQuoteErrorCode, string>> = {
|
|
221
|
+
rate_limited: "You have sent a few requests already. Wait a minute and try again.",
|
|
222
|
+
invalid_input: "Please check the highlighted field and try again.",
|
|
223
|
+
unavailable: "Quote requests can't be received right now. Your entries are still here; try again shortly.",
|
|
224
|
+
store_failed: "We couldn't save your request. Your entries are still here; try again.",
|
|
225
|
+
too_large: "That request is too large. Shorten it and try again.",
|
|
226
|
+
};
|
|
227
|
+
const GENERIC = "Something went wrong. Your entries are still here; try again.";
|
|
228
|
+
const wait = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
229
|
+
type Control = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
|
|
230
|
+
|
|
231
|
+
function setup(root: HTMLElement) {
|
|
232
|
+
const form = root.querySelector<HTMLFormElement>("[data-bulk-quote-el]");
|
|
233
|
+
const status = root.querySelector<HTMLElement>("[data-bulk-quote-status]");
|
|
234
|
+
const ref = root.querySelector<HTMLElement>("[data-bulk-quote-ref]");
|
|
235
|
+
const list = root.querySelector<HTMLElement>("[data-bulk-quote-items]");
|
|
236
|
+
const add = root.querySelector<HTMLButtonElement>("[data-bulk-quote-add]");
|
|
237
|
+
const row = root.querySelector<HTMLTemplateElement>("[data-bulk-quote-row]");
|
|
238
|
+
const endpoint = root.dataset.endpoint;
|
|
239
|
+
if (!form || !status || !ref || !list || !add || !row || !endpoint) return;
|
|
240
|
+
const maxItems = Number(root.dataset.maxItems) || 25;
|
|
241
|
+
// The wire contract appends /api/contact/... itself; hand it the api base.
|
|
242
|
+
const apiBase = endpoint.replace(/\/api\/contact\/bulk-quote$/, "");
|
|
243
|
+
const say = (text: string, state: "ok" | "error" | "") => {
|
|
244
|
+
status.textContent = text;
|
|
245
|
+
status.dataset.state = state;
|
|
246
|
+
};
|
|
247
|
+
const items = () => Array.from(list.querySelectorAll<HTMLElement>("[data-bulk-quote-item]"));
|
|
248
|
+
const control = (item: HTMLElement, key: string) =>
|
|
249
|
+
item.querySelector<Control>(`[data-li="${key}"]`);
|
|
250
|
+
const sync = () => {
|
|
251
|
+
const all = items();
|
|
252
|
+
add.disabled = all.length >= maxItems;
|
|
253
|
+
all.forEach((item) => {
|
|
254
|
+
const remove = item.querySelector<HTMLButtonElement>("[data-bulk-quote-remove]");
|
|
255
|
+
if (remove) remove.hidden = all.length <= 1;
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
const addItem = () => {
|
|
259
|
+
if (items().length >= maxItems) return;
|
|
260
|
+
list.appendChild(row.content.cloneNode(true));
|
|
261
|
+
sync();
|
|
262
|
+
};
|
|
263
|
+
addItem();
|
|
264
|
+
add.addEventListener("click", () => {
|
|
265
|
+
addItem();
|
|
266
|
+
const last = items().at(-1);
|
|
267
|
+
if (last) control(last, "description")?.focus();
|
|
268
|
+
});
|
|
269
|
+
list.addEventListener("click", (e) => {
|
|
270
|
+
const target = e.target as Element | null;
|
|
271
|
+
const remove = target?.closest("[data-bulk-quote-remove]");
|
|
272
|
+
if (!remove || items().length <= 1) return;
|
|
273
|
+
remove.closest("[data-bulk-quote-item]")?.remove();
|
|
274
|
+
sync();
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
let token: { value: string; at: number } | null = null;
|
|
278
|
+
const loadToken = async () => {
|
|
279
|
+
token = { value: await fetchBulkQuoteToken(apiBase), at: Date.now() };
|
|
280
|
+
};
|
|
281
|
+
const ready = loadToken();
|
|
282
|
+
form.hidden = false;
|
|
283
|
+
ready.catch(() => say("Quote requests can't be received right now. Try again shortly.", "error"));
|
|
284
|
+
|
|
285
|
+
const top = (name: string) => form.elements.namedItem(name) as Control | null;
|
|
286
|
+
const value = (name: string) => top(name)?.value.trim() ?? "";
|
|
287
|
+
const mark = (el: Element | null | undefined) => {
|
|
288
|
+
el?.setAttribute("aria-invalid", "true");
|
|
289
|
+
(el as HTMLElement | null | undefined)?.focus();
|
|
290
|
+
};
|
|
291
|
+
const flag = (field: string, index?: number) => {
|
|
292
|
+
const all = items();
|
|
293
|
+
if (field === "lineItems") return mark(add);
|
|
294
|
+
if (index !== undefined && all[index]) {
|
|
295
|
+
const target = control(all[index], field);
|
|
296
|
+
if (target) return mark(target);
|
|
297
|
+
return mark(all[index]);
|
|
298
|
+
}
|
|
299
|
+
mark(top(field));
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
form.addEventListener("submit", async (e) => {
|
|
303
|
+
e.preventDefault();
|
|
304
|
+
const button = form.querySelector<HTMLButtonElement>("button[type=submit]");
|
|
305
|
+
root.querySelectorAll("[aria-invalid]").forEach((el) => el.removeAttribute("aria-invalid"));
|
|
306
|
+
ref.hidden = true;
|
|
307
|
+
ref.textContent = "";
|
|
308
|
+
|
|
309
|
+
for (const field of ["businessName", "name"]) {
|
|
310
|
+
if (!value(field)) {
|
|
311
|
+
flag(field);
|
|
312
|
+
return say("Fill in the highlighted field.", "error");
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (!/^\S+@\S+$/.test(value("email"))) {
|
|
316
|
+
flag("email");
|
|
317
|
+
return say("Enter a valid email address.", "error");
|
|
318
|
+
}
|
|
319
|
+
const lineItems: BulkQuoteSubmission["lineItems"] = [];
|
|
320
|
+
const rows = items();
|
|
321
|
+
for (const [i, item] of rows.entries()) {
|
|
322
|
+
const read = (key: string) => control(item, key)?.value.trim() ?? "";
|
|
323
|
+
const description = read("description");
|
|
324
|
+
const quantity = Number(read("quantity"));
|
|
325
|
+
if (!description) {
|
|
326
|
+
flag("description", i);
|
|
327
|
+
return say("Describe each item.", "error");
|
|
328
|
+
}
|
|
329
|
+
if (!(quantity > 0)) {
|
|
330
|
+
flag("quantity", i);
|
|
331
|
+
return say("Enter a quantity greater than zero for each item.", "error");
|
|
332
|
+
}
|
|
333
|
+
const sku = read("sku");
|
|
334
|
+
const packSize = read("packSize");
|
|
335
|
+
lineItems.push({
|
|
336
|
+
description,
|
|
337
|
+
...(sku ? { sku } : {}),
|
|
338
|
+
quantity,
|
|
339
|
+
unit: read("unit") as BulkQuoteUnit,
|
|
340
|
+
...(packSize ? { packSize } : {}),
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (button) button.disabled = true;
|
|
345
|
+
say("Sending...", "");
|
|
346
|
+
try {
|
|
347
|
+
if (!token || Date.now() - token.at > CONTACT_TOKEN_MAX_AGE_MS - 60_000) await loadToken();
|
|
348
|
+
const age = Date.now() - token!.at;
|
|
349
|
+
if (age < CONTACT_TOKEN_MIN_AGE_MS) await wait(CONTACT_TOKEN_MIN_AGE_MS - age + 100);
|
|
350
|
+
const optional = (name: string) => {
|
|
351
|
+
const v = value(name);
|
|
352
|
+
return v ? { [name]: v } : {};
|
|
353
|
+
};
|
|
354
|
+
const result = await submitBulkQuote(apiBase, {
|
|
355
|
+
token: token!.value,
|
|
356
|
+
businessName: value("businessName"),
|
|
357
|
+
name: value("name"),
|
|
358
|
+
email: value("email"),
|
|
359
|
+
...optional("phone"),
|
|
360
|
+
lineItems,
|
|
361
|
+
...optional("destinationRegion"),
|
|
362
|
+
...optional("destinationPostalCode"),
|
|
363
|
+
liftgate: (top("liftgate") as HTMLInputElement | null)?.checked === true,
|
|
364
|
+
...optional("freightNotes"),
|
|
365
|
+
...optional("poNumber"),
|
|
366
|
+
...optional("timeline"),
|
|
367
|
+
...optional("notes"),
|
|
368
|
+
company: top("company")?.value ?? "",
|
|
369
|
+
});
|
|
370
|
+
if (result.body.ok) {
|
|
371
|
+
const quoteId = result.body.quoteId;
|
|
372
|
+
form.reset();
|
|
373
|
+
list.replaceChildren();
|
|
374
|
+
addItem();
|
|
375
|
+
token = null;
|
|
376
|
+
say(root.dataset.success ?? "Thanks. We received your quote request.", "ok");
|
|
377
|
+
ref.textContent = `Quote reference: ${quoteId}`;
|
|
378
|
+
ref.hidden = false;
|
|
379
|
+
loadToken().catch(() => {});
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const code = result.body.error;
|
|
383
|
+
if (code === "invalid_token" || code === "forbidden_origin") token = null;
|
|
384
|
+
if (result.body.field) flag(result.body.field, result.body.index);
|
|
385
|
+
say(MESSAGES[code] ?? GENERIC, "error");
|
|
386
|
+
if (!token) loadToken().catch(() => {});
|
|
387
|
+
} catch {
|
|
388
|
+
say(GENERIC, "error");
|
|
389
|
+
} finally {
|
|
390
|
+
if (button) button.disabled = false;
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
document.querySelectorAll<HTMLElement>("[data-bulk-quote-form]").forEach(setup);
|
|
396
|
+
</script>
|
|
@@ -17,6 +17,7 @@ import { normalizeProse, withHeadingIds } from "@/lib/content/prose";
|
|
|
17
17
|
import RichText from "@/components/content/storefront/content/RichText.astro";
|
|
18
18
|
import Callout from "@/components/content/storefront/content/Callout.astro";
|
|
19
19
|
import ContactForm from "@/components/content/storefront/content/ContactForm.astro";
|
|
20
|
+
import BulkQuoteForm from "@/components/content/storefront/content/BulkQuoteForm.astro";
|
|
20
21
|
import NeedsReviewCallout from "@/components/content/storefront/content/NeedsReviewCallout.astro";
|
|
21
22
|
|
|
22
23
|
interface Props {
|
|
@@ -112,6 +113,8 @@ const rendered = withHeadingIds(normalizeProse(sections));
|
|
|
112
113
|
);
|
|
113
114
|
case "contact_form":
|
|
114
115
|
return <ContactForm section={s} index={i} />;
|
|
116
|
+
case "bulk_quote_form":
|
|
117
|
+
return <BulkQuoteForm section={s} index={i} />;
|
|
115
118
|
case "needs_review":
|
|
116
119
|
return includeNeedsReview ? (
|
|
117
120
|
<NeedsReviewCallout flag={{ reason: s.reason, severity: s.severity, owner: s.owner, href: s.href }} />
|
|
@@ -25,8 +25,19 @@
|
|
|
25
25
|
* `/dashboard`, `/diag`, `/auth`, the preview review/grant/onboarding pages, and every
|
|
26
26
|
* non-GET request — is refused 403 by the middleware BEFORE any handler runs.
|
|
27
27
|
*
|
|
28
|
+
* Before any of that, a stage-bound agent session whose introspected stage is not the stage
|
|
29
|
+
* this Worker serves, or whose record holds neither a stage nor the grant-mode marker, is
|
|
30
|
+
* refused `stage_mismatch` on every agent door it can reach (the control-plane, API and
|
|
31
|
+
* preview-token routes, allowlisted or not). A grant-mode session is not stage-bound and
|
|
32
|
+
* passes this check; every other gate rule still applies to it. The stage lives
|
|
33
|
+
* here, once, so every agent door, present and future, inherits it. It governs the Worker's
|
|
34
|
+
* admin and API paths on both Cloudflare- and CloudFront-served tenants. Public content
|
|
35
|
+
* reads take the no-session path (`agentGate` in the middleware) and are unchanged; a
|
|
36
|
+
* tenant's public pages are served by the CDN and never reach this gate.
|
|
37
|
+
*
|
|
28
38
|
* Paths here are TENANT-RELATIVE (`renderPath`, prefix already stripped).
|
|
29
39
|
*/
|
|
40
|
+
import { COMMERCE_STAGES } from "@tot/public-runtime";
|
|
30
41
|
import type { SessionRecord } from "./session.js";
|
|
31
42
|
import { isAgentSession } from "./session.js";
|
|
32
43
|
import {
|
|
@@ -150,16 +161,72 @@ export function agentMayReach(method: string, renderPath: string, roles: readonl
|
|
|
150
161
|
return !AGENT_PRIVILEGED_MOUNTS.some((mount) => underMount(path, mount));
|
|
151
162
|
}
|
|
152
163
|
|
|
164
|
+
/**
|
|
165
|
+
* True only when the session's introspected stage is a known commerce stage AND equals
|
|
166
|
+
* the stage this Worker deployment serves. An absent or unknown session stage, or a
|
|
167
|
+
* serving stage that is unset or unknown, is false: the comparison fails closed.
|
|
168
|
+
*/
|
|
169
|
+
export function agentStageMatches(sessionStage: unknown, servingStage: unknown): boolean {
|
|
170
|
+
return (COMMERCE_STAGES as readonly unknown[]).includes(sessionStage) && sessionStage === servingStage;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Whether an agent session may act on the stage this Worker serves. A stage-bound
|
|
175
|
+
* session must match it. A session positively introspected as grant-mode
|
|
176
|
+
* (`stageUnbound`) is not stage-bound and passes. Everything else, including a record
|
|
177
|
+
* with no stage and no `stageUnbound`, is refused.
|
|
178
|
+
*/
|
|
179
|
+
export function agentStageAdmits(
|
|
180
|
+
binding: { stage?: unknown; stageUnbound?: unknown },
|
|
181
|
+
servingStage: unknown,
|
|
182
|
+
): boolean {
|
|
183
|
+
if (binding.stage !== undefined) return agentStageMatches(binding.stage, servingStage);
|
|
184
|
+
return binding.stageUnbound === true;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The answer for a hold-reasons read that carries both a Bearer credential and a session
|
|
189
|
+
* cookie: 400 `mixed_credentials`, in the error shape the hold-reasons door answers with.
|
|
190
|
+
* It is built here so the sponsored-agent gate can refuse before any session lookup
|
|
191
|
+
* without reaching the orders read path.
|
|
192
|
+
*/
|
|
193
|
+
export function holdReadMixedCredentialsRefusal(): Response {
|
|
194
|
+
return new Response(
|
|
195
|
+
JSON.stringify({ error: "mixed_credentials", code: "mixed_credentials" }),
|
|
196
|
+
{
|
|
197
|
+
status: 400,
|
|
198
|
+
headers: {
|
|
199
|
+
"content-type": "application/json; charset=utf-8",
|
|
200
|
+
"cache-control": "no-store",
|
|
201
|
+
"x-robots-tag": "noindex, nofollow",
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
153
207
|
/**
|
|
154
208
|
* The gate decision: null to proceed, or the 403 to answer. Only an AGENT session is
|
|
155
209
|
* ever refused here; a human session (or none) always proceeds unchanged.
|
|
210
|
+
*
|
|
211
|
+
* `servingStage` is the stage this Worker serves, from its per-environment config
|
|
212
|
+
* (`COMMERCE_STAGE`), never the request host. An agent session minted for a different
|
|
213
|
+
* stage is refused on every route this function sees, allowlisted or not, with
|
|
214
|
+
* `stage_mismatch`. The middleware calls it for control-plane requests and any path an
|
|
215
|
+
* agent may not reach as public content; public content GETs never read the session.
|
|
156
216
|
*/
|
|
157
217
|
export function agentSessionGateRefusal(
|
|
158
218
|
session: Pick<SessionRecord, "actor"> | null | undefined,
|
|
159
219
|
method: string,
|
|
160
220
|
renderPath: string,
|
|
221
|
+
servingStage: string | null | undefined,
|
|
161
222
|
): Response | null {
|
|
162
223
|
if (!isAgentSession(session)) return null;
|
|
224
|
+
if (!agentStageAdmits(session.actor, servingStage)) {
|
|
225
|
+
return new Response(
|
|
226
|
+
JSON.stringify({ error: "stage_mismatch", reason: "agentStageMismatch" }),
|
|
227
|
+
{ status: 403, headers: { "content-type": "application/json", "cache-control": "no-store" } },
|
|
228
|
+
);
|
|
229
|
+
}
|
|
163
230
|
if (agentMayReach(method, renderPath, session.actor.roles)) return null;
|
|
164
231
|
return new Response(
|
|
165
232
|
JSON.stringify({ error: "agent_route_not_allowed", reason: "agentDenied" }),
|
|
@@ -447,6 +447,29 @@ export function isAppCredentialRequest(input: AppCredentialRequest): boolean {
|
|
|
447
447
|
return APP_V1_PATH.test(renderPath) && /^Bearer\s+\S/.test(authorization);
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
+
const HOLD_READS_PATH = "/api/admin/hold-reasons";
|
|
451
|
+
|
|
452
|
+
export interface HoldReadBearerRequest {
|
|
453
|
+
method: string | undefined;
|
|
454
|
+
/** The publication render path (tenant-relative), never the raw request path. */
|
|
455
|
+
renderPath: string | undefined;
|
|
456
|
+
/** The request's `Authorization` header. */
|
|
457
|
+
authorization: string | null | undefined;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* A `GET` of the hold-reasons read carrying a `Bearer` credential: the only admin API that
|
|
462
|
+
* reaches its handler with no session. Presence only: the handler authorizes the credential live
|
|
463
|
+
* (grant authority, tenant, role, stage, expiry) and refuses everything else. `renderPath` is the
|
|
464
|
+
* tenant-relative publication path, so the host and tenant-prefixed routes match and a neighbor
|
|
465
|
+
* admin API, another method, a suffix or a trailing slash matches nothing.
|
|
466
|
+
*/
|
|
467
|
+
export function isHoldReadBearerRequest(input: HoldReadBearerRequest): boolean {
|
|
468
|
+
return input.method === "GET"
|
|
469
|
+
&& input.renderPath === HOLD_READS_PATH
|
|
470
|
+
&& /^Bearer\s+\S/i.test(input.authorization?.trim() ?? "");
|
|
471
|
+
}
|
|
472
|
+
|
|
450
473
|
/** The render path is the app token endpoint, whose form body {@link isAppCredentialRequest} reads. */
|
|
451
474
|
export function isAppTokenPath(renderPath: string | undefined): boolean {
|
|
452
475
|
return renderPath === APP_TOKEN_PATH;
|
|
@@ -505,6 +528,11 @@ export interface LoginGateInput {
|
|
|
505
528
|
* which authenticates the credential for this tenant's preview stage.
|
|
506
529
|
*/
|
|
507
530
|
appCredential?: boolean;
|
|
531
|
+
/**
|
|
532
|
+
* True when the request is an {@link isHoldReadBearerRequest} on a preview surface. It reaches
|
|
533
|
+
* its handler, which authorizes the credential live for this tenant and stage.
|
|
534
|
+
*/
|
|
535
|
+
holdReadBearer?: boolean;
|
|
508
536
|
}
|
|
509
537
|
|
|
510
538
|
/**
|
|
@@ -547,6 +575,8 @@ export function evaluateLoginGate(input: LoginGateInput): LoginGateDecision {
|
|
|
547
575
|
// An app's own credential on an app-gateway route reaches the handler, which is
|
|
548
576
|
// the authority for its tenant and install env (preview stage, `test` installs).
|
|
549
577
|
if (input.appCredential) return { action: "pass" };
|
|
578
|
+
// The hold-reasons read's own bearer reaches its handler, the authority for the credential.
|
|
579
|
+
if (input.holdReadBearer) return { action: "pass" };
|
|
550
580
|
if (input.hasValidSession) return { action: "pass" };
|
|
551
581
|
return { action: "redirect", location: loginRedirectLocation(input.pathname) };
|
|
552
582
|
}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* host↔resource check.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
import type { CommerceStage } from "@tot/public-runtime";
|
|
18
19
|
import type { CatalogCapabilityId } from "@/lib/access/shared/generated/capabilityCatalog.generated";
|
|
19
20
|
|
|
20
21
|
/** The cookie the browser carries; value is an opaque session id (not the record). */
|
|
@@ -71,6 +72,17 @@ export interface AgentActor {
|
|
|
71
72
|
boundTenant: string;
|
|
72
73
|
/** The trusted MCP origin that introspected the token; attestations come only from it. */
|
|
73
74
|
mcpOrigin: string;
|
|
75
|
+
/**
|
|
76
|
+
* The commerce stage tot-mcp bound the token to, as introspected. The gate refuses the
|
|
77
|
+
* session on every request unless it equals the stage this Worker serves.
|
|
78
|
+
*/
|
|
79
|
+
stage?: CommerceStage;
|
|
80
|
+
/**
|
|
81
|
+
* Set only when tot-mcp introspected the token as a grant-mode session, which holds its
|
|
82
|
+
* grant's full scope and is not stage-bound. A record with neither `stage` nor this flag
|
|
83
|
+
* is refused.
|
|
84
|
+
*/
|
|
85
|
+
stageUnbound?: true;
|
|
74
86
|
}
|
|
75
87
|
|
|
76
88
|
/** In-flight proof for one session-bound operation. The session never persists it. */
|
|
@@ -18,6 +18,7 @@ import type { RichText } from "./richtext.js";
|
|
|
18
18
|
import { plainText } from "./richtext.js";
|
|
19
19
|
import type { CalloutTone } from "./callout.js";
|
|
20
20
|
import type { NeedsReview } from "./needsReview.js";
|
|
21
|
+
import { BULK_QUOTE_UNITS, type BulkQuoteUnit } from "../engagement/contact/bulkQuote.js";
|
|
21
22
|
|
|
22
23
|
/** A section heading (renders <h2> or <h3>; carries/derives an anchor id). */
|
|
23
24
|
export interface ProseHeadingSection {
|
|
@@ -79,6 +80,20 @@ export interface ProseContactFormSection {
|
|
|
79
80
|
successMessage?: string;
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
/**
|
|
84
|
+
* A bulk / custom wholesale quote request form. The fields, endpoint and script are
|
|
85
|
+
* platform-owned (lib/engagement/contact/bulkQuote.ts): this section carries copy and an
|
|
86
|
+
* optional subset of the quote units only.
|
|
87
|
+
*/
|
|
88
|
+
export interface ProseBulkQuoteFormSection {
|
|
89
|
+
kind: "bulk_quote_form";
|
|
90
|
+
heading?: string;
|
|
91
|
+
intro?: string;
|
|
92
|
+
submitLabel?: string;
|
|
93
|
+
successMessage?: string;
|
|
94
|
+
units?: BulkQuoteUnit[];
|
|
95
|
+
}
|
|
96
|
+
|
|
82
97
|
/** A needs-review flag embedded in the flow (see needsReview.ts). */
|
|
83
98
|
export type ProseNeedsReviewSection = { kind: "needs_review" } & NeedsReview;
|
|
84
99
|
|
|
@@ -90,6 +105,7 @@ export type ProseSection =
|
|
|
90
105
|
| ProseCalloutSection
|
|
91
106
|
| ProseContactSection
|
|
92
107
|
| ProseContactFormSection
|
|
108
|
+
| ProseBulkQuoteFormSection
|
|
93
109
|
| ProseNeedsReviewSection;
|
|
94
110
|
|
|
95
111
|
/** A full structured page (policy / about / compliance). */
|
|
@@ -147,6 +163,9 @@ export function normalizeProse(
|
|
|
147
163
|
case "contact_form":
|
|
148
164
|
out.push(normalizeContactForm(s));
|
|
149
165
|
break;
|
|
166
|
+
case "bulk_quote_form":
|
|
167
|
+
out.push(normalizeBulkQuoteForm(s));
|
|
168
|
+
break;
|
|
150
169
|
case "needs_review":
|
|
151
170
|
if (s.reason.trim()) out.push(s);
|
|
152
171
|
break;
|
|
@@ -177,6 +196,23 @@ function normalizeContactForm(s: ProseContactFormSection): ProseContactFormSecti
|
|
|
177
196
|
return out;
|
|
178
197
|
}
|
|
179
198
|
|
|
199
|
+
/** Rebuild from the known copy props only; `units` keeps the declared units in canonical order. */
|
|
200
|
+
function normalizeBulkQuoteForm(s: ProseBulkQuoteFormSection): ProseBulkQuoteFormSection {
|
|
201
|
+
const raw: unknown = s.units;
|
|
202
|
+
const units = BULK_QUOTE_UNITS.filter((u) => Array.isArray(raw) && raw.includes(u));
|
|
203
|
+
const out: ProseBulkQuoteFormSection = { kind: "bulk_quote_form" };
|
|
204
|
+
const heading = copy(s.heading);
|
|
205
|
+
const intro = copy(s.intro);
|
|
206
|
+
const submitLabel = copy(s.submitLabel);
|
|
207
|
+
const successMessage = copy(s.successMessage);
|
|
208
|
+
if (heading) out.heading = heading;
|
|
209
|
+
if (intro) out.intro = intro;
|
|
210
|
+
if (submitLabel) out.submitLabel = submitLabel;
|
|
211
|
+
if (successMessage) out.successMessage = successMessage;
|
|
212
|
+
if (units.length) out.units = [...units];
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
215
|
+
|
|
180
216
|
/** Fill in a derived `id` for every heading that lacks one (for TOC anchoring). */
|
|
181
217
|
export function withHeadingIds(
|
|
182
218
|
sections: ReadonlyArray<ProseSection>,
|