@tokenoftrust/storefront-runner 7.6.0 → 7.6.1
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.
|
@@ -117,6 +117,14 @@ export default function CartAddedDialog() {
|
|
|
117
117
|
</dl>
|
|
118
118
|
)}
|
|
119
119
|
<p class="mt-1 text-sm text-[var(--color-muted)]">Quantity: {detail.quantity}</p>
|
|
120
|
+
{detail.appliedCoupon && (
|
|
121
|
+
<p
|
|
122
|
+
data-cart-added-coupon={detail.appliedCoupon}
|
|
123
|
+
class="mt-2 inline-flex items-center rounded-full border border-[var(--color-border)] bg-[var(--color-bg)] px-3 py-1 text-xs font-medium text-[var(--color-text)]"
|
|
124
|
+
>
|
|
125
|
+
Promo code applied: {detail.appliedCoupon}
|
|
126
|
+
</p>
|
|
127
|
+
)}
|
|
120
128
|
</div>
|
|
121
129
|
</div>
|
|
122
130
|
) : (
|
|
@@ -73,6 +73,8 @@ export interface ParsedCart {
|
|
|
73
73
|
lines: CartLine[];
|
|
74
74
|
/** Messages the provider refused the request with. Empty when it accepted. */
|
|
75
75
|
errors: string[];
|
|
76
|
+
/** Promotional coupon codes active on the cart. */
|
|
77
|
+
coupons?: string[];
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
export type CartAddedDetail =
|
|
@@ -84,6 +86,7 @@ export type CartAddedDetail =
|
|
|
84
86
|
image: string | null;
|
|
85
87
|
count: number;
|
|
86
88
|
cartHref: string;
|
|
89
|
+
appliedCoupon?: string;
|
|
87
90
|
}
|
|
88
91
|
| { status: "error"; cartHref: string };
|
|
89
92
|
|
|
@@ -134,6 +137,37 @@ function wholeNumber(raw: unknown): number {
|
|
|
134
137
|
return Number.isFinite(n) && n > 0 ? Math.floor(n) : 0;
|
|
135
138
|
}
|
|
136
139
|
|
|
140
|
+
/** Valid promotional coupon codes present on a FoxyCart JSONcart `coupons` payload. */
|
|
141
|
+
export function parseCartCoupons(body: unknown): string[] {
|
|
142
|
+
const cart = record(body);
|
|
143
|
+
if (!cart) return [];
|
|
144
|
+
const rawCoupons = cart.coupons;
|
|
145
|
+
const out: string[] = [];
|
|
146
|
+
const push = (candidate: unknown) => {
|
|
147
|
+
const valid = normalizePromoCoupon(candidate);
|
|
148
|
+
if (valid && !out.includes(valid)) out.push(valid);
|
|
149
|
+
};
|
|
150
|
+
if (Array.isArray(rawCoupons)) {
|
|
151
|
+
for (const entry of rawCoupons) {
|
|
152
|
+
if (typeof entry === "string") {
|
|
153
|
+
push(entry);
|
|
154
|
+
} else {
|
|
155
|
+
const obj = record(entry);
|
|
156
|
+
if (obj) push(obj.code);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
const map = record(rawCoupons);
|
|
161
|
+
if (map) {
|
|
162
|
+
for (const [key, value] of Object.entries(map)) {
|
|
163
|
+
const obj = record(value);
|
|
164
|
+
push(obj?.code ?? key);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
}
|
|
170
|
+
|
|
137
171
|
/** The provider's cart JSON as a typed cart, or null when the body is not a cart. */
|
|
138
172
|
export function parseCart(body: unknown): ParsedCart | null {
|
|
139
173
|
const cart = record(body);
|
|
@@ -163,11 +197,13 @@ export function parseCart(body: unknown): ParsedCart | null {
|
|
|
163
197
|
})
|
|
164
198
|
: [];
|
|
165
199
|
const session = cart.session_id;
|
|
200
|
+
const coupons = parseCartCoupons(cart);
|
|
166
201
|
return {
|
|
167
202
|
count,
|
|
168
203
|
sessionId: typeof session === "string" && /^[a-z0-9]{10,64}$/.test(session) ? session : null,
|
|
169
204
|
lines,
|
|
170
205
|
errors,
|
|
206
|
+
...(coupons.length > 0 ? { coupons } : {}),
|
|
171
207
|
};
|
|
172
208
|
}
|
|
173
209
|
|
|
@@ -469,8 +505,10 @@ export function describeAdded(
|
|
|
469
505
|
cart: ParsedCart,
|
|
470
506
|
form: { title: string; code: string; quantity: number },
|
|
471
507
|
cartHref: string,
|
|
508
|
+
appliedCoupon?: string | null,
|
|
472
509
|
): CartAddedDetail {
|
|
473
510
|
const line = addedLine(cart, form.code);
|
|
511
|
+
const coupon = normalizePromoCoupon(appliedCoupon ?? cart.coupons?.[0]);
|
|
474
512
|
return {
|
|
475
513
|
status: "added",
|
|
476
514
|
title: form.title || line?.name || "Item",
|
|
@@ -479,6 +517,7 @@ export function describeAdded(
|
|
|
479
517
|
image: line?.image ?? null,
|
|
480
518
|
count: cart.count,
|
|
481
519
|
cartHref,
|
|
520
|
+
...(coupon ? { appliedCoupon: coupon } : {}),
|
|
482
521
|
};
|
|
483
522
|
}
|
|
484
523
|
|
|
@@ -539,19 +578,24 @@ export async function addFromForm(
|
|
|
539
578
|
const key = storedCountKey(config.cookiePath);
|
|
540
579
|
const quantity = wholeNumber(submittedField(data, "quantity")) || 1;
|
|
541
580
|
try {
|
|
542
|
-
const
|
|
581
|
+
const rawBody = await loadCartJsonp(location, cartOrigin, env);
|
|
582
|
+
const cart = parseCart(rawBody);
|
|
543
583
|
if (!cart || cart.errors.length > 0 || cart.count === 0) {
|
|
544
584
|
announce(env, { status: "error", cartHref: config.cartUrl });
|
|
545
585
|
return true;
|
|
546
586
|
}
|
|
547
587
|
writeStoredCount(env.storage, key, cart.count);
|
|
548
588
|
renderCartCount(env.doc, cart.count);
|
|
589
|
+
const submittedCoupon = normalizePromoCoupon(data.get("coupon"));
|
|
590
|
+
const appliedCoupon =
|
|
591
|
+
parseCartCoupons(rawBody)[0] ?? pendingCoupon ?? submittedCoupon ?? undefined;
|
|
549
592
|
announce(
|
|
550
593
|
env,
|
|
551
594
|
describeAdded(
|
|
552
595
|
cart,
|
|
553
596
|
{ title: form.dataset.productTitle ?? "", code: submittedField(data, "code"), quantity },
|
|
554
597
|
cartHrefFor(config, cart.sessionId),
|
|
598
|
+
appliedCoupon,
|
|
555
599
|
),
|
|
556
600
|
);
|
|
557
601
|
} catch {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "7.6.
|
|
3
|
+
"version": "7.6.1",
|
|
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",
|
|
@@ -140,6 +140,8 @@ export interface CheckoutOrderDetailResponse {
|
|
|
140
140
|
export interface CheckoutOrderListFilters {
|
|
141
141
|
queue?: string;
|
|
142
142
|
status?: string;
|
|
143
|
+
/** Optional redeemed coupon code filter (case-insensitive). */
|
|
144
|
+
coupon?: string;
|
|
143
145
|
/** ISO datetime lower bound. */
|
|
144
146
|
from?: string;
|
|
145
147
|
/** ISO datetime upper bound. */
|