@mohasinac/appkit 4.7.1 → 4.7.2
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.
|
@@ -35,7 +35,13 @@ export interface CheckoutValueOtpDoc {
|
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Enforce the per-user send rate-limit.
|
|
38
|
-
* Throws AuthorizationError
|
|
38
|
+
* Throws AuthorizationError with a user-facing "already sent, retry in N
|
|
39
|
+
* minutes" message when throttled — root-caused 2026-08-20: this used to
|
|
40
|
+
* throw the bare internal string "checkoutValueOtpRateLimit", which the
|
|
41
|
+
* client showed verbatim in a toast. A buyer who retried "Send code"
|
|
42
|
+
* within the cooldown (e.g. after not seeing the first email land) saw a
|
|
43
|
+
* cryptic error instead of being told a code was already on its way,
|
|
44
|
+
* making the whole feature look broken.
|
|
39
45
|
*/
|
|
40
46
|
export declare function enforceCheckoutValueOtpRateLimit(db: Db, uid: string): Promise<void>;
|
|
41
47
|
/** Build the checkout-value OTP WhatsApp/SMS message body. */
|
|
@@ -51,7 +51,13 @@ export function checkoutValueOtpRateLimitRef(db, uid) {
|
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* Enforce the per-user send rate-limit.
|
|
54
|
-
* Throws AuthorizationError
|
|
54
|
+
* Throws AuthorizationError with a user-facing "already sent, retry in N
|
|
55
|
+
* minutes" message when throttled — root-caused 2026-08-20: this used to
|
|
56
|
+
* throw the bare internal string "checkoutValueOtpRateLimit", which the
|
|
57
|
+
* client showed verbatim in a toast. A buyer who retried "Send code"
|
|
58
|
+
* within the cooldown (e.g. after not seeing the first email land) saw a
|
|
59
|
+
* cryptic error instead of being told a code was already on its way,
|
|
60
|
+
* making the whole feature look broken.
|
|
55
61
|
*/
|
|
56
62
|
export async function enforceCheckoutValueOtpRateLimit(db, uid) {
|
|
57
63
|
const metaRef = checkoutValueOtpRateLimitRef(db, uid);
|
|
@@ -63,7 +69,8 @@ export async function enforceCheckoutValueOtpRateLimit(db, uid) {
|
|
|
63
69
|
const lastSentMs = resolveDate(meta?.lastSentAt)?.getTime() ?? 0;
|
|
64
70
|
const elapsed = Date.now() - lastSentMs;
|
|
65
71
|
if (elapsed < CHECKOUT_VALUE_OTP_COOLDOWN_MS) {
|
|
66
|
-
|
|
72
|
+
const remainingMinutes = Math.max(1, Math.ceil((CHECKOUT_VALUE_OTP_COOLDOWN_MS - elapsed) / 60000));
|
|
73
|
+
throw new AuthorizationError(`We already sent a code — check your inbox (and spam folder). You can request a new one in ${remainingMinutes} minute${remainingMinutes === 1 ? "" : "s"}.`);
|
|
67
74
|
}
|
|
68
75
|
tx.set(metaRef, { lastSentAt: new Date() }, { merge: true });
|
|
69
76
|
});
|
|
@@ -12,8 +12,8 @@ const __O = {
|
|
|
12
12
|
};
|
|
13
13
|
const CLS_REMOVE_BTN = "self-start text-[var(--appkit-color-text-faint)] transition hover:text-error";
|
|
14
14
|
export function CartItemRow({ item, onQtyChange, onRemove, href, isOutOfStock = false }) {
|
|
15
|
-
return (_jsxs(Div, { layout: "flex", gap: "4", surface: "card", padding: "sm", className: `transition-opacity ${isOutOfStock ? "opacity-60" : ""}`, children: [_jsx(Div, { surface: "muted", className: `relative h-20 w-20 flex-shrink-0 ${__O.hidden}`, rounded: "lg", children: item.meta.image && (_jsx(MediaImage, { src: item.meta.image, alt: item.meta.title, size: "thumbnail" })) }), _jsxs(Stack, { justify: "between", className: "flex-1", children: [_jsxs(Row, { gap: "xs", className: "", align: "start", children: [href ? (_jsx(TextLink, { href: href, target: "_blank", rel: "noopener noreferrer", weight: "medium", className: "text-[var(--appkit-color-text)] hover:underline underline-offset-2 line-clamp-2", children: item.meta.title })) : (_jsx(Text, { truncate: 2, weight: "medium", color: "primary", children: item.meta.title })), isOutOfStock && (_jsx(Span, { padding: "pill-2xs", color: "error", surface: "danger-surface", weight: "semibold", className: "flex-shrink-0 text-[10px] tracking-wide", rounded: "default", transform: "uppercase", children: "Out of Stock" }))] }), item.meta.attributes &&
|
|
16
|
-
Object.keys(item.meta.attributes).length > 0 && (_jsx(Text, { className: "text-[var(--appkit-color-text-muted)]", size: "xs", children: Object.entries(item.meta.attributes)
|
|
15
|
+
return (_jsxs(Div, { layout: "flex", gap: "4", surface: "card", padding: "sm", className: `transition-opacity ${isOutOfStock ? "opacity-60" : ""}`, children: [_jsx(Div, { surface: "muted", className: `relative h-20 w-20 flex-shrink-0 ${__O.hidden}`, rounded: "lg", children: item.meta.image && (_jsx(MediaImage, { src: item.meta.image, alt: item.meta.title, size: "thumbnail" })) }), _jsxs(Stack, { justify: "between", className: "flex-1 min-w-0", children: [_jsxs(Row, { gap: "xs", className: "", align: "start", children: [href ? (_jsx(TextLink, { href: href, target: "_blank", rel: "noopener noreferrer", weight: "medium", className: "text-[var(--appkit-color-text)] hover:underline underline-offset-2 line-clamp-2", children: item.meta.title })) : (_jsx(Text, { truncate: 2, weight: "medium", color: "primary", children: item.meta.title })), isOutOfStock && (_jsx(Span, { padding: "pill-2xs", color: "error", surface: "danger-surface", weight: "semibold", className: "flex-shrink-0 text-[10px] tracking-wide", rounded: "default", transform: "uppercase", children: "Out of Stock" }))] }), item.meta.attributes &&
|
|
16
|
+
Object.keys(item.meta.attributes).length > 0 && (_jsx(Text, { className: "text-[var(--appkit-color-text-muted)]", size: "xs", truncate: 1, children: Object.entries(item.meta.attributes)
|
|
17
17
|
.map(([k, v]) => `${k}: ${v}`)
|
|
18
18
|
.join(", ") })), _jsxs(Row, { justify: "between", children: [_jsx(Text, { className: "text-[var(--appkit-color-text)]", weight: "semibold", children: formatCurrency(item.meta.price * item.quantity, item.meta.currency) }), onQtyChange && !isOutOfStock && (_jsxs(Row, { gap: "sm", children: [_jsx(Button, { rounded: "full", onClick: () => onQtyChange(item.id, item.quantity - 1), disabled: item.quantity <= 1, variant: "outline", size: "sm", className: "h-7 w-7 justify-center border border-neutral-200 border-[var(--appkit-color-border)] text-[length:var(--appkit-text-sm)] disabled:opacity-40", children: "\u2212" }), _jsx(Span, { size: "sm", className: "min-w-[1.5rem]", align: "center", children: item.quantity }), _jsx(Button, { rounded: "full", onClick: () => onQtyChange(item.id, item.quantity + 1), variant: "outline", size: "sm", className: "h-7 w-7 justify-center border border-neutral-200 border-[var(--appkit-color-border)] text-[length:var(--appkit-text-sm)]", children: "+" })] })), isOutOfStock && (_jsxs(Span, { size: "xs", color: "muted", children: ["Qty: ", item.quantity] }))] })] }), onRemove && (_jsx(Button, { onClick: () => onRemove(item.id), variant: "ghost", size: "sm", "aria-label": ACTIONS.CART["remove-item"].ariaLabel, className: CLS_REMOVE_BTN, children: "\u2715" }))] }));
|
|
19
19
|
}
|
|
@@ -32,7 +32,7 @@ export async function sendCheckoutValueOtp(userId, userEmail) {
|
|
|
32
32
|
const maskedEmail = domain
|
|
33
33
|
? `${local.length <= 2 ? "*".repeat(local.length) : local[0] + "*".repeat(local.length - 2) + local[local.length - 1]}@${domain}`
|
|
34
34
|
: "***";
|
|
35
|
-
await sendEmail({
|
|
35
|
+
const { error } = await sendEmail({
|
|
36
36
|
to: userEmail,
|
|
37
37
|
subject: `${siteName}: Verify your order`,
|
|
38
38
|
html: `
|
|
@@ -44,6 +44,17 @@ export async function sendCheckoutValueOtp(userId, userEmail) {
|
|
|
44
44
|
</div>
|
|
45
45
|
`,
|
|
46
46
|
});
|
|
47
|
+
if (error) {
|
|
48
|
+
// Root-caused 2026-08-20: this used to be fire-and-forget — the
|
|
49
|
+
// Firestore OTP doc was written and the caller always got back a
|
|
50
|
+
// success response ("code sent") regardless of whether the email
|
|
51
|
+
// actually went out. Any Resend-side failure (bad API key,
|
|
52
|
+
// unverified sending domain, outage) silently stranded the buyer
|
|
53
|
+
// with a checkout they could never complete, since the OTP gate
|
|
54
|
+
// gave no indication anything had gone wrong.
|
|
55
|
+
serverLogger.error("Failed to send checkout value OTP email", { uid: userId, error });
|
|
56
|
+
throw new ValidationError("We couldn't send the verification code — please try again in a moment, or contact support if this keeps happening.");
|
|
57
|
+
}
|
|
47
58
|
serverLogger.info(`Checkout value OTP sent: uid=${userId}`);
|
|
48
59
|
return { maskedEmail };
|
|
49
60
|
}
|