@vectoriox/iox-ui 5.102.0 → 5.103.0
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/commerce-core/index.d.ts +331 -6
- package/fesm2022/vectoriox-iox-ui-commerce-core.mjs +523 -24
- package/fesm2022/vectoriox-iox-ui-commerce-core.mjs.map +1 -1
- package/package.json +1 -1
- package/src/commerce-core/cart-transport.ts +7 -1
- package/src/commerce-core/cart.ts +28 -2
- package/src/commerce-core/coupons.ts +186 -0
- package/src/commerce-core/order-snapshot.ts +3 -0
- package/src/commerce-core/public-api.ts +4 -1
- package/src/commerce-core/recovery.ts +381 -0
- package/src/commerce-core/site-checkout.ts +46 -6
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { CheckoutStep } from './checkout';
|
|
2
|
+
import { CommerceLabel, labelIn } from './labels';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The journey and recovery (commerce plan §3g, C-D13, C-D14 — E4): when a purchase counts as abandoned, the reminder
|
|
6
|
+
* sequence (1 h · 24 h · 72 h, the last may carry a coupon), the ONE consent rule a reminder obeys, the funnel the owner
|
|
7
|
+
* reads, the words of the reminder email and the unsubscribe page, and their site paths. Pure: no clock is read —
|
|
8
|
+
* every caller passes `now` (epoch ms).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const HOUR_MS = 60 * 60 * 1000;
|
|
12
|
+
|
|
13
|
+
/** A purchase with an email and no payment for this long is abandoned — a lead the owner can follow up. */
|
|
14
|
+
export const ABANDONED_AFTER_MS = HOUR_MS;
|
|
15
|
+
|
|
16
|
+
/** A reminder this late (a pod was down, reminders were just switched on) is passed over, never sent stale. */
|
|
17
|
+
export const REMINDER_LATE_MS = 12 * HOUR_MS;
|
|
18
|
+
|
|
19
|
+
export enum ReminderStep {
|
|
20
|
+
First = 'first',
|
|
21
|
+
Second = 'second',
|
|
22
|
+
Third = 'third',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ReminderTiming {
|
|
26
|
+
readonly step: ReminderStep;
|
|
27
|
+
/** After the buyer's LAST activity on the checkout. */
|
|
28
|
+
readonly afterMs: number;
|
|
29
|
+
/** The owner's coupon rides this one, when there is one. */
|
|
30
|
+
readonly carriesCoupon: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The sequence (board 9): 1 hour after leaving, after 24 hours, after 72 hours + a coupon. */
|
|
34
|
+
export const REMINDER_SEQUENCE: readonly ReminderTiming[] = Object.freeze([
|
|
35
|
+
{ step: ReminderStep.First, afterMs: HOUR_MS, carriesCoupon: false },
|
|
36
|
+
{ step: ReminderStep.Second, afterMs: 24 * HOUR_MS, carriesCoupon: false },
|
|
37
|
+
{ step: ReminderStep.Third, afterMs: 72 * HOUR_MS, carriesCoupon: true },
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
export const REMINDER_STEPS: readonly ReminderStep[] = Object.freeze(REMINDER_SEQUENCE.map(timing => timing.step));
|
|
41
|
+
|
|
42
|
+
/** The owner's words for one reminder — blank keeps the default. */
|
|
43
|
+
export interface ReminderWords {
|
|
44
|
+
subject?: string | null;
|
|
45
|
+
lead?: string | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ReminderSettings {
|
|
49
|
+
enabled: boolean;
|
|
50
|
+
steps: Record<ReminderStep, boolean>;
|
|
51
|
+
/** A coupon code of the studio's, offered in the reminder that carries one. */
|
|
52
|
+
couponCode: string | null;
|
|
53
|
+
words: Partial<Record<ReminderStep, ReminderWords>>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const REMINDER_WORDS_MAX = 200;
|
|
57
|
+
|
|
58
|
+
/** On, every step on, no coupon (board 9). Reminders still go ONLY to a buyer who ticked consent. */
|
|
59
|
+
export const DEFAULT_REMINDER_SETTINGS: Readonly<ReminderSettings> = Object.freeze({
|
|
60
|
+
enabled: true,
|
|
61
|
+
steps: Object.freeze({ [ReminderStep.First]: true, [ReminderStep.Second]: true, [ReminderStep.Third]: true }) as Record<ReminderStep, boolean>,
|
|
62
|
+
couponCode: null,
|
|
63
|
+
words: Object.freeze({}),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const text = (value: unknown, max: number): string | null =>
|
|
67
|
+
typeof value === 'string' && value.trim() ? value.trim().slice(0, max) : null;
|
|
68
|
+
|
|
69
|
+
/** A stored (or sent) settings value read leniently: anything missing or malformed is the default. */
|
|
70
|
+
export function reminderSettingsOf(raw: unknown): ReminderSettings {
|
|
71
|
+
const r = raw && typeof raw === 'object' ? raw as Partial<ReminderSettings> : {};
|
|
72
|
+
const steps = { ...DEFAULT_REMINDER_SETTINGS.steps };
|
|
73
|
+
const words: Partial<Record<ReminderStep, ReminderWords>> = {};
|
|
74
|
+
for (const step of REMINDER_STEPS) {
|
|
75
|
+
if (typeof r.steps?.[step] === 'boolean') steps[step] = r.steps[step];
|
|
76
|
+
const w = r.words?.[step];
|
|
77
|
+
const subject = text(w?.subject, REMINDER_WORDS_MAX);
|
|
78
|
+
const lead = text(w?.lead, REMINDER_WORDS_MAX * 2);
|
|
79
|
+
if (subject || lead) words[step] = { subject, lead };
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
enabled: typeof r.enabled === 'boolean' ? r.enabled : DEFAULT_REMINDER_SETTINGS.enabled,
|
|
83
|
+
steps,
|
|
84
|
+
couponCode: text(r.couponCode, 64)?.toUpperCase() ?? null,
|
|
85
|
+
words,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ── consent (T7 — the marketing tick, never the cookie decision) ─────────────────────────────────────────
|
|
90
|
+
|
|
91
|
+
/** One recorded decision about marketing: the checkout's tick, the customer's latest, an unsubscribe, the owner's stop. */
|
|
92
|
+
export interface ConsentDecision {
|
|
93
|
+
given: boolean;
|
|
94
|
+
at: string | number | Date | null | undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const timeOf = (at: ConsentDecision['at']): number => {
|
|
98
|
+
if (at === null || at === undefined) return Number.NEGATIVE_INFINITY;
|
|
99
|
+
const ms = at instanceof Date ? at.getTime() : new Date(at as string).getTime();
|
|
100
|
+
return Number.isFinite(ms) ? ms : Number.NEGATIVE_INFINITY;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* THE consent gate of a marketing message (Israel's Communications Law §30A, the GDPR — C-D14): the LATEST decision
|
|
105
|
+
* wins. A tick at a checkout allows; an unsubscribe or the owner's "Stop reminders" after it forbids; a new tick at a
|
|
106
|
+
* later checkout allows again. No decision at all forbids — a reminder is never sent on silence. A tie forbids.
|
|
107
|
+
*/
|
|
108
|
+
export function marketingAllowed(...decisions: ReadonlyArray<ConsentDecision | null | undefined>): boolean {
|
|
109
|
+
let latest: { given: boolean; at: number } | null = null;
|
|
110
|
+
for (const d of decisions) {
|
|
111
|
+
if (!d || typeof d.given !== 'boolean') continue;
|
|
112
|
+
const at = timeOf(d.at);
|
|
113
|
+
if (!latest || at > latest.at || (at === latest.at && !d.given)) latest = { given: d.given, at };
|
|
114
|
+
}
|
|
115
|
+
return latest?.given === true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ── the sequence ─────────────────────────────────────────────────────────────────────────────────────────
|
|
119
|
+
|
|
120
|
+
/** Why a checkout gets no (more) reminders. */
|
|
121
|
+
export enum ReminderStop {
|
|
122
|
+
/** The purchase was made. */
|
|
123
|
+
Completed = 'completed',
|
|
124
|
+
NoEmail = 'no-email',
|
|
125
|
+
/** No tick, or the latest decision is a withdrawal. */
|
|
126
|
+
NoConsent = 'no-consent',
|
|
127
|
+
/** The owner marked the lead lost. */
|
|
128
|
+
Lost = 'lost',
|
|
129
|
+
/** The studio's reminders are off. */
|
|
130
|
+
Off = 'off',
|
|
131
|
+
/** Every reminder was sent, or its time has passed. */
|
|
132
|
+
Done = 'done',
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface ReminderFacts {
|
|
136
|
+
/** The checkout is still open (no order placed from it). */
|
|
137
|
+
open: boolean;
|
|
138
|
+
hasEmail: boolean;
|
|
139
|
+
/** `marketingAllowed(...)` for this buyer. */
|
|
140
|
+
consent: boolean;
|
|
141
|
+
lost: boolean;
|
|
142
|
+
/** Epoch ms of the buyer's last activity on the checkout. */
|
|
143
|
+
lastActivityAt: number;
|
|
144
|
+
/** Steps already sent, failed or passed over — never tried twice. */
|
|
145
|
+
done: readonly ReminderStep[];
|
|
146
|
+
settings: ReminderSettings;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export type ReminderPlan =
|
|
150
|
+
| { due: true; step: ReminderStep; dueAt: number; carriesCoupon: boolean }
|
|
151
|
+
| { due: false; stop: ReminderStop };
|
|
152
|
+
|
|
153
|
+
const STOPS: ReadonlyArray<{ stop: ReminderStop; when: (f: ReminderFacts) => boolean }> = Object.freeze([
|
|
154
|
+
{ stop: ReminderStop.Completed, when: (f: ReminderFacts) => !f.open },
|
|
155
|
+
{ stop: ReminderStop.NoEmail, when: (f: ReminderFacts) => !f.hasEmail },
|
|
156
|
+
{ stop: ReminderStop.NoConsent, when: (f: ReminderFacts) => !f.consent },
|
|
157
|
+
{ stop: ReminderStop.Lost, when: (f: ReminderFacts) => f.lost },
|
|
158
|
+
{ stop: ReminderStop.Off, when: (f: ReminderFacts) => !f.settings.enabled },
|
|
159
|
+
]);
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The next reminder of a checkout at `now`: the first step that is switched on, not done yet, and not more than
|
|
163
|
+
* `REMINDER_LATE_MS` past its time — due at `lastActivityAt + afterMs` (it may be in the future: the scheduler waits).
|
|
164
|
+
* A buyer who comes back moves every later reminder with their activity. Steps too late are passed over silently.
|
|
165
|
+
*/
|
|
166
|
+
export function nextReminder(facts: ReminderFacts, now: number): ReminderPlan {
|
|
167
|
+
const stopped = STOPS.find(rule => rule.when(facts));
|
|
168
|
+
if (stopped) return { due: false, stop: stopped.stop };
|
|
169
|
+
for (const timing of REMINDER_SEQUENCE) {
|
|
170
|
+
if (facts.done.includes(timing.step) || facts.settings.steps[timing.step] !== true) continue;
|
|
171
|
+
const dueAt = facts.lastActivityAt + timing.afterMs;
|
|
172
|
+
if (now > dueAt + REMINDER_LATE_MS) continue;
|
|
173
|
+
return { due: true, step: timing.step, dueAt, carriesCoupon: timing.carriesCoupon };
|
|
174
|
+
}
|
|
175
|
+
return { due: false, stop: ReminderStop.Done };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The step's number as the owner reads it ("Reminder 2"). */
|
|
179
|
+
export function reminderNumber(step: ReminderStep): number {
|
|
180
|
+
return REMINDER_STEPS.indexOf(step) + 1;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** What became of one reminder. */
|
|
184
|
+
export enum ReminderOutcome {
|
|
185
|
+
Sent = 'sent',
|
|
186
|
+
Failed = 'failed',
|
|
187
|
+
/** Not sent, on purpose — `ReminderSkip` says why. */
|
|
188
|
+
Skipped = 'skipped',
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export enum ReminderSkip {
|
|
192
|
+
/** The studio's sender domain is not verified: it would land in spam (T13). */
|
|
193
|
+
SenderUnverified = 'sender-unverified',
|
|
194
|
+
NoMailer = 'no-mailer',
|
|
195
|
+
/** The studio's public address is unknown, so there is no link to put in it. */
|
|
196
|
+
NoSiteAddress = 'no-site-address',
|
|
197
|
+
/** The bag is empty now: nothing to come back to. */
|
|
198
|
+
EmptyBag = 'empty-bag',
|
|
199
|
+
/** A send was started and the pod stopped before it was recorded: never sent twice. */
|
|
200
|
+
Interrupted = 'interrupted',
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Is a checkout an abandoned purchase at `now`: open, with an email, untouched for an hour. */
|
|
204
|
+
export function isAbandoned(c: { open: boolean; hasEmail: boolean; lastActivityAt: number }, now: number): boolean {
|
|
205
|
+
return c.open && c.hasEmail && now - c.lastActivityAt >= ABANDONED_AFTER_MS;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Where a purchase stopped: the step after the furthest one the buyer completed (board 9's "Stopped at"). */
|
|
209
|
+
export function stoppedAt(furthest: CheckoutStep | null | undefined): CheckoutStep {
|
|
210
|
+
if (furthest === CheckoutStep.Paid) return CheckoutStep.Paid;
|
|
211
|
+
if (furthest === CheckoutStep.Delivery || furthest === CheckoutStep.Payment) return CheckoutStep.Payment;
|
|
212
|
+
return CheckoutStep.Delivery;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ── the funnel (Shop ▸ Sales journey) ─────────────────────────────────────────────────────────────────────
|
|
216
|
+
|
|
217
|
+
export enum FunnelStage {
|
|
218
|
+
AddedToBag = 'added-to-bag',
|
|
219
|
+
GaveEmail = 'gave-email',
|
|
220
|
+
ChoseDelivery = 'chose-delivery',
|
|
221
|
+
ReachedPayment = 'reached-payment',
|
|
222
|
+
PlacedOrder = 'placed-order',
|
|
223
|
+
Paid = 'paid',
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export const FUNNEL_STAGES: readonly FunnelStage[] = Object.freeze([
|
|
227
|
+
FunnelStage.AddedToBag, FunnelStage.GaveEmail, FunnelStage.ChoseDelivery, FunnelStage.ReachedPayment, FunnelStage.PlacedOrder, FunnelStage.Paid,
|
|
228
|
+
]);
|
|
229
|
+
|
|
230
|
+
export interface FunnelRow {
|
|
231
|
+
stage: FunnelStage;
|
|
232
|
+
count: number;
|
|
233
|
+
/** Whole percent of the first stage. */
|
|
234
|
+
share: number;
|
|
235
|
+
/** Whole percent lost since the previous stage; null on the first. */
|
|
236
|
+
drop: number | null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const count = (value: unknown): number => (typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.floor(value) : 0);
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* The funnel's rows. Each stage is a subset of the one before, so a count is raised to the next stage's when the
|
|
243
|
+
* records disagree (a bag removed after 30 days while its checkout is kept) — a share never passes 100 %.
|
|
244
|
+
*/
|
|
245
|
+
export function funnelOf(counts: Partial<Record<FunnelStage, number>>): FunnelRow[] {
|
|
246
|
+
const values = FUNNEL_STAGES.map(stage => count(counts[stage]));
|
|
247
|
+
for (let i = values.length - 2; i >= 0; i--) values[i] = Math.max(values[i], values[i + 1]);
|
|
248
|
+
const first = values[0];
|
|
249
|
+
return FUNNEL_STAGES.map((stage, i) => ({
|
|
250
|
+
stage,
|
|
251
|
+
count: values[i],
|
|
252
|
+
share: first ? Math.round((values[i] / first) * 100) : 0,
|
|
253
|
+
drop: i === 0 ? null : values[i - 1] ? Math.round(((values[i - 1] - values[i]) / values[i - 1]) * 100) : 0,
|
|
254
|
+
}));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** The stage that loses the most buyers after `after` (board 9: "After contact, the biggest drop is at delivery"). */
|
|
258
|
+
export function biggestDrop(rows: readonly FunnelRow[], after: FunnelStage = FunnelStage.GaveEmail): FunnelStage | null {
|
|
259
|
+
const from = rows.findIndex(row => row.stage === after);
|
|
260
|
+
let best: FunnelRow | null = null;
|
|
261
|
+
for (const row of rows.slice(from + 1)) if ((row.drop ?? 0) > 0 && (!best || (row.drop ?? 0) > (best.drop ?? 0))) best = row;
|
|
262
|
+
return best?.stage ?? null;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** The Sales journey's periods (board 9). */
|
|
266
|
+
export const JOURNEY_PERIODS_DAYS: readonly number[] = Object.freeze([7, 30, 90]);
|
|
267
|
+
export const DEFAULT_JOURNEY_DAYS = 30;
|
|
268
|
+
|
|
269
|
+
// ── one purchase's journey (board 8) ──────────────────────────────────────────────────────────────────────
|
|
270
|
+
|
|
271
|
+
/** What a timeline says happened — the purchase's own records, never browsing (C-D13). */
|
|
272
|
+
export enum JourneyEventKind {
|
|
273
|
+
CheckoutStarted = 'checkout-started',
|
|
274
|
+
DeliveryChosen = 'delivery-chosen',
|
|
275
|
+
PaymentChosen = 'payment-chosen',
|
|
276
|
+
ReminderSent = 'reminder-sent',
|
|
277
|
+
ReminderFailed = 'reminder-failed',
|
|
278
|
+
ReminderSkipped = 'reminder-skipped',
|
|
279
|
+
ReminderScheduled = 'reminder-scheduled',
|
|
280
|
+
CameBack = 'came-back',
|
|
281
|
+
Unsubscribed = 'unsubscribed',
|
|
282
|
+
MarkedLost = 'marked-lost',
|
|
283
|
+
OrderPlaced = 'order-placed',
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ── the site paths ────────────────────────────────────────────────────────────────────────────────────────
|
|
287
|
+
|
|
288
|
+
/** `/<orgLabel>/checkout/r/<token>` — the reminder's link: the bag restored, the step they left. */
|
|
289
|
+
export const RECOVERY_PATH = 'r';
|
|
290
|
+
/** `/<orgLabel>/checkout/unsubscribe/<token>` — works without signing in. */
|
|
291
|
+
export const UNSUBSCRIBE_PATH = 'unsubscribe';
|
|
292
|
+
|
|
293
|
+
const checkoutTail = (orgLabel: string | null | undefined, tail: string): string => {
|
|
294
|
+
const label = String(orgLabel ?? '').replace(/^\/+|\/+$/g, '');
|
|
295
|
+
const path = `checkout/${tail}`;
|
|
296
|
+
return label ? `/${encodeURIComponent(label)}/${path}` : `/${path}`;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
export function recoveryHref(orgLabel: string | null | undefined, token: string): string {
|
|
300
|
+
return checkoutTail(orgLabel, `${RECOVERY_PATH}/${encodeURIComponent(token)}`);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export function unsubscribeHref(orgLabel: string | null | undefined, token: string): string {
|
|
304
|
+
return checkoutTail(orgLabel, `${UNSUBSCRIBE_PATH}/${encodeURIComponent(token)}`);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** `GET|POST api/site/:orgId/marketing/unsubscribe/:token` — the page's state. The email is masked. */
|
|
308
|
+
export interface SiteUnsubscribeState {
|
|
309
|
+
subscribed: boolean;
|
|
310
|
+
email: string;
|
|
311
|
+
siteName: string | null;
|
|
312
|
+
language: string;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** `n•••@example.com` — enough for a person to recognise their address, not enough to harvest it. */
|
|
316
|
+
export function maskEmail(email: string | null | undefined): string {
|
|
317
|
+
const value = String(email ?? '');
|
|
318
|
+
const at = value.indexOf('@');
|
|
319
|
+
if (at < 1) return '';
|
|
320
|
+
return `${value[0]}•••${value.slice(at)}`;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// ── the words ─────────────────────────────────────────────────────────────────────────────────────────────
|
|
324
|
+
|
|
325
|
+
export enum RecoveryWord {
|
|
326
|
+
SubjectFirst = 'subjectFirst',
|
|
327
|
+
SubjectSecond = 'subjectSecond',
|
|
328
|
+
SubjectThird = 'subjectThird',
|
|
329
|
+
Heading = 'heading',
|
|
330
|
+
Lead = 'lead',
|
|
331
|
+
Return = 'return',
|
|
332
|
+
KeptDetails = 'keptDetails',
|
|
333
|
+
CouponOffer = 'couponOffer',
|
|
334
|
+
Why = 'why',
|
|
335
|
+
Unsubscribe = 'unsubscribe',
|
|
336
|
+
UnsubscribeTitle = 'unsubscribeTitle',
|
|
337
|
+
UnsubscribeAsk = 'unsubscribeAsk',
|
|
338
|
+
UnsubscribeButton = 'unsubscribeButton',
|
|
339
|
+
UnsubscribeDone = 'unsubscribeDone',
|
|
340
|
+
UnsubscribeAlready = 'unsubscribeAlready',
|
|
341
|
+
UnsubscribeUnknown = 'unsubscribeUnknown',
|
|
342
|
+
UnsubscribeTransactional = 'unsubscribeTransactional',
|
|
343
|
+
RecoveryDone = 'recoveryDone',
|
|
344
|
+
RecoveryExpired = 'recoveryExpired',
|
|
345
|
+
Restoring = 'restoring',
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** `{studio}`, `{code}`, `{offer}`, `{step}`, `{email}` are filled by `recoveryWord`. */
|
|
349
|
+
export const RECOVERY_WORDS: Readonly<Record<RecoveryWord, CommerceLabel>> = Object.freeze({
|
|
350
|
+
[RecoveryWord.SubjectFirst]: { en: '{studio}: your bag is waiting', he: '{studio}: הסל שלך מחכה' },
|
|
351
|
+
[RecoveryWord.SubjectSecond]: { en: '{studio}: still thinking it over?', he: '{studio}: עדיין מתלבטים?' },
|
|
352
|
+
[RecoveryWord.SubjectThird]: { en: '{studio}: a little something to finish your order', he: '{studio}: משהו קטן כדי להשלים את ההזמנה' },
|
|
353
|
+
[RecoveryWord.Heading]: { en: 'You left something in your bag', he: 'השארת משהו בסל' },
|
|
354
|
+
[RecoveryWord.Lead]: { en: 'Your bag at {studio} is just as you left it.', he: 'הסל שלך ב{studio} בדיוק כפי שהשארת אותו.' },
|
|
355
|
+
[RecoveryWord.Return]: { en: 'Return to checkout', he: 'חזרה לתשלום' },
|
|
356
|
+
[RecoveryWord.KeptDetails]: { en: 'We kept your details — you will continue from {step}.', he: 'שמרנו את הפרטים שלך — ממשיכים מ{step}.' },
|
|
357
|
+
[RecoveryWord.CouponOffer]: { en: 'Use the code {code} for {offer}.', he: 'השתמשו בקוד {code} לקבלת {offer}.' },
|
|
358
|
+
[RecoveryWord.Why]: { en: 'You are getting this because you asked {studio} for reminders and offers.', he: 'המייל נשלח כי ביקשת מ{studio} תזכורות והצעות.' },
|
|
359
|
+
[RecoveryWord.Unsubscribe]: { en: 'Unsubscribe', he: 'הסרה מרשימת התפוצה' },
|
|
360
|
+
[RecoveryWord.UnsubscribeTitle]: { en: 'Reminders and offers from {studio}', he: 'תזכורות והצעות מ{studio}' },
|
|
361
|
+
[RecoveryWord.UnsubscribeAsk]: { en: 'Stop sending reminders and offers to {email}?', he: 'להפסיק לשלוח תזכורות והצעות אל {email}?' },
|
|
362
|
+
[RecoveryWord.UnsubscribeButton]: { en: 'Unsubscribe', he: 'הסירו אותי' },
|
|
363
|
+
[RecoveryWord.UnsubscribeDone]: { en: 'Done. {studio} will send no more reminders or offers to {email}.', he: 'בוצע. {studio} לא ישלחו עוד תזכורות או הצעות אל {email}.' },
|
|
364
|
+
[RecoveryWord.UnsubscribeAlready]: { en: '{email} gets no reminders or offers from {studio}.', he: '{email} לא מקבל/ת תזכורות או הצעות מ{studio}.' },
|
|
365
|
+
[RecoveryWord.UnsubscribeUnknown]: { en: 'This link does not work any more. You will get no reminders or offers through it.', he: 'הקישור הזה כבר לא פעיל. לא יישלחו דרכו תזכורות או הצעות.' },
|
|
366
|
+
[RecoveryWord.UnsubscribeTransactional]: { en: 'Emails about an order you place still arrive.', he: 'מיילים על הזמנה שתבצעו ימשיכו להגיע.' },
|
|
367
|
+
[RecoveryWord.RecoveryDone]: { en: 'This purchase was already completed.', he: 'הרכישה הזו כבר הושלמה.' },
|
|
368
|
+
[RecoveryWord.RecoveryExpired]: { en: 'This bag is no longer kept. You are welcome to shop again.', he: 'הסל הזה כבר לא שמור. אפשר לקנות שוב.' },
|
|
369
|
+
[RecoveryWord.Restoring]: { en: 'Opening your bag…', he: 'פותחים את הסל שלך…' },
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
export function recoveryWord(word: RecoveryWord, lang: string | null | undefined, fill: Readonly<Record<string, string | number>> = {}): string {
|
|
373
|
+
return labelIn(RECOVERY_WORDS[word], lang).replace(/\{(\w+)\}/g, (all, key) => (key in fill ? String(fill[key]) : all));
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/** The default subject of each reminder. */
|
|
377
|
+
export const REMINDER_SUBJECT_WORDS: Readonly<Record<ReminderStep, RecoveryWord>> = Object.freeze({
|
|
378
|
+
[ReminderStep.First]: RecoveryWord.SubjectFirst,
|
|
379
|
+
[ReminderStep.Second]: RecoveryWord.SubjectSecond,
|
|
380
|
+
[ReminderStep.Third]: RecoveryWord.SubjectThird,
|
|
381
|
+
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { SiteCartView } from './cart-transport';
|
|
2
2
|
import { BusinessIdentity, CheckoutStep, LegalPage } from './checkout';
|
|
3
3
|
import { CurrencyCode } from './currency';
|
|
4
|
+
import { COUPON_REFUSAL_LABELS, CouponRefusal } from './coupons';
|
|
4
5
|
import { CommerceLabel, labelIn } from './labels';
|
|
5
|
-
import { Money } from './money';
|
|
6
|
+
import { isMoney, Money } from './money';
|
|
6
7
|
import { OrderSnapshot, PostalAddress } from './order-snapshot';
|
|
7
8
|
import { OrderState } from './orders';
|
|
8
9
|
import { DeliveryFit, PaymentMethodKind } from './payments';
|
|
@@ -20,6 +21,12 @@ export enum SiteCommerceRoute {
|
|
|
20
21
|
CheckoutOptions = 'checkout/options',
|
|
21
22
|
Checkout = 'checkout',
|
|
22
23
|
CheckoutPlace = 'checkout/place',
|
|
24
|
+
/** `PUT {code}` applies a coupon to the open checkout; `DELETE` removes it (E4). */
|
|
25
|
+
CheckoutCoupon = 'checkout/coupon',
|
|
26
|
+
/** `POST /:token` — a reminder's link: the bag back under this browser's cookie, the checkout as it was (E4). */
|
|
27
|
+
CheckoutRecover = 'checkout/recover',
|
|
28
|
+
/** `GET|POST /:token` — the unsubscribe page's state, and the unsubscribe itself (E4). */
|
|
29
|
+
Unsubscribe = 'marketing/unsubscribe',
|
|
23
30
|
Order = 'order',
|
|
24
31
|
}
|
|
25
32
|
|
|
@@ -224,6 +231,10 @@ export enum CheckoutWord {
|
|
|
224
231
|
StepOf = 'stepOf',
|
|
225
232
|
OrderMissing = 'orderMissing',
|
|
226
233
|
Legal = 'legal',
|
|
234
|
+
Coupon = 'coupon',
|
|
235
|
+
ApplyCoupon = 'applyCoupon',
|
|
236
|
+
RemoveCoupon = 'removeCoupon',
|
|
237
|
+
Discount = 'discount',
|
|
227
238
|
}
|
|
228
239
|
|
|
229
240
|
/** `{name}`, `{n}`, `{of}`, `{amount}`, `{percent}`, `{number}`, `{email}`, `{total}`, `{place}` are filled by `checkoutWord`. */
|
|
@@ -269,6 +280,10 @@ export const CHECKOUT_WORDS: Readonly<Record<CheckoutWord, CommerceLabel>> = Obj
|
|
|
269
280
|
[CheckoutWord.StepOf]: { en: 'Step {n} of {of}', he: 'שלב {n} מתוך {of}' },
|
|
270
281
|
[CheckoutWord.OrderMissing]: { en: 'We could not find this order.', he: 'לא מצאנו את ההזמנה הזו.' },
|
|
271
282
|
[CheckoutWord.Legal]: { en: 'Policies', he: 'מדיניות' },
|
|
283
|
+
[CheckoutWord.Coupon]: { en: 'Coupon code', he: 'קוד קופון' },
|
|
284
|
+
[CheckoutWord.ApplyCoupon]: { en: 'Apply', he: 'החלה' },
|
|
285
|
+
[CheckoutWord.RemoveCoupon]: { en: 'Remove', he: 'הסרה' },
|
|
286
|
+
[CheckoutWord.Discount]: { en: 'Discount · {code}', he: 'הנחה · {code}' },
|
|
272
287
|
});
|
|
273
288
|
|
|
274
289
|
export function checkoutWord(word: CheckoutWord, lang: string | null | undefined, fill: Readonly<Record<string, string | number>> = {}): string {
|
|
@@ -289,6 +304,8 @@ export enum CheckoutSlot {
|
|
|
289
304
|
Terms = 'terms',
|
|
290
305
|
/** The order summary: the bag itself changed. */
|
|
291
306
|
Cart = 'cart',
|
|
307
|
+
/** The coupon field in the order summary (E4). */
|
|
308
|
+
Coupon = 'coupon',
|
|
292
309
|
/** The whole page: closed, busy, unreachable. */
|
|
293
310
|
Page = 'page',
|
|
294
311
|
}
|
|
@@ -328,6 +345,17 @@ export enum SiteRefusalCode {
|
|
|
328
345
|
UnknownSite = 'unknown-site',
|
|
329
346
|
/** The owner blocked this buyer (commerce E3c): no checkout, no order. */
|
|
330
347
|
CustomerBlocked = 'customer-blocked',
|
|
348
|
+
CouponUnknown = 'coupon-unknown',
|
|
349
|
+
CouponDisabled = 'coupon-disabled',
|
|
350
|
+
CouponNotStarted = 'coupon-not-started',
|
|
351
|
+
CouponExpired = 'coupon-expired',
|
|
352
|
+
CouponUsedUp = 'coupon-used-up',
|
|
353
|
+
CouponMinimumNotMet = 'coupon-minimum-not-met',
|
|
354
|
+
CouponNotUsable = 'coupon-not-usable',
|
|
355
|
+
/** A reminder's link to a purchase that was completed (E4). */
|
|
356
|
+
RecoveryDone = 'recovery-done',
|
|
357
|
+
/** A reminder's link whose bag is gone, or a link that is not one. */
|
|
358
|
+
RecoveryExpired = 'recovery-expired',
|
|
331
359
|
Network = 'network',
|
|
332
360
|
}
|
|
333
361
|
|
|
@@ -374,6 +402,15 @@ export const SITE_REFUSALS: Readonly<Record<SiteRefusalCode, RefusalRule>> = Obj
|
|
|
374
402
|
[SiteRefusalCode.UnknownOrder]: { slot: CheckoutSlot.Page, label: { en: 'We could not find this order.', he: 'לא מצאנו את ההזמנה הזו.' } },
|
|
375
403
|
[SiteRefusalCode.UnknownSite]: { slot: CheckoutSlot.Page, label: CLOSED },
|
|
376
404
|
[SiteRefusalCode.CustomerBlocked]: { slot: CheckoutSlot.Page, label: { en: 'This account cannot place orders here. Contact the business.', he: 'החשבון הזה לא יכול לבצע הזמנות כאן. פנו לעסק.' } },
|
|
405
|
+
[SiteRefusalCode.CouponUnknown]: { slot: CheckoutSlot.Coupon, label: COUPON_REFUSAL_LABELS[CouponRefusal.Unknown] },
|
|
406
|
+
[SiteRefusalCode.CouponDisabled]: { slot: CheckoutSlot.Coupon, label: COUPON_REFUSAL_LABELS[CouponRefusal.Disabled] },
|
|
407
|
+
[SiteRefusalCode.CouponNotStarted]: { slot: CheckoutSlot.Coupon, label: COUPON_REFUSAL_LABELS[CouponRefusal.NotStarted] },
|
|
408
|
+
[SiteRefusalCode.CouponExpired]: { slot: CheckoutSlot.Coupon, label: COUPON_REFUSAL_LABELS[CouponRefusal.Expired] },
|
|
409
|
+
[SiteRefusalCode.CouponUsedUp]: { slot: CheckoutSlot.Coupon, label: COUPON_REFUSAL_LABELS[CouponRefusal.UsedUp] },
|
|
410
|
+
[SiteRefusalCode.CouponMinimumNotMet]: { slot: CheckoutSlot.Coupon, label: COUPON_REFUSAL_LABELS[CouponRefusal.MinimumNotMet] },
|
|
411
|
+
[SiteRefusalCode.CouponNotUsable]: { slot: CheckoutSlot.Coupon, label: COUPON_REFUSAL_LABELS[CouponRefusal.NotUsable] },
|
|
412
|
+
[SiteRefusalCode.RecoveryDone]: { slot: CheckoutSlot.Page, label: { en: 'This purchase was already completed.', he: 'הרכישה הזו כבר הושלמה.' } },
|
|
413
|
+
[SiteRefusalCode.RecoveryExpired]: { slot: CheckoutSlot.Page, label: { en: 'This bag is no longer kept. You are welcome to shop again.', he: 'הסל הזה כבר לא שמור. אפשר לקנות שוב.' } },
|
|
377
414
|
[SiteRefusalCode.Network]: { slot: CheckoutSlot.Page, label: { en: 'We could not reach the shop. Try again.', he: 'לא הצלחנו להגיע לחנות. נסו שוב.' } },
|
|
378
415
|
});
|
|
379
416
|
|
|
@@ -389,10 +426,11 @@ const isRefusalCode = (code: unknown): code is SiteRefusalCode =>
|
|
|
389
426
|
|
|
390
427
|
const ORDER_REFUSED = 'order-refused';
|
|
391
428
|
|
|
392
|
-
function refusalOf(code: unknown, lang: string | null | undefined): SiteRefusal {
|
|
429
|
+
function refusalOf(code: unknown, lang: string | null | undefined, fill: Readonly<Record<string, string>> = {}): SiteRefusal {
|
|
393
430
|
const known: SiteRefusalCode = isRefusalCode(code) ? code : SiteRefusalCode.InvalidBody;
|
|
394
431
|
const rule = SITE_REFUSALS[known];
|
|
395
|
-
|
|
432
|
+
const words = labelIn(rule.label, lang).replace(/\{(\w+)\}/g, (all, key) => fill[key] ?? all);
|
|
433
|
+
return { code: isRefusalCode(code) ? code : String(code ?? known), slot: rule.slot, words };
|
|
396
434
|
}
|
|
397
435
|
|
|
398
436
|
/**
|
|
@@ -400,10 +438,12 @@ function refusalOf(code: unknown, lang: string | null | undefined): SiteRefusal
|
|
|
400
438
|
* `refusals` on its own field; any other code is one sentence; no body at all is `network`. `message` is a log line
|
|
401
439
|
* and is never shown. One sentence per slot (the first wins).
|
|
402
440
|
*/
|
|
403
|
-
export function siteRefusalsOf(body: unknown, lang: string | null | undefined): SiteRefusal[] {
|
|
404
|
-
const answer = body && typeof body === 'object' ? body as { code?: unknown; refusals?: unknown } : null;
|
|
441
|
+
export function siteRefusalsOf(body: unknown, lang: string | null | undefined, formatMoney?: (value: Money) => string): SiteRefusal[] {
|
|
442
|
+
const answer = body && typeof body === 'object' ? body as { code?: unknown; refusals?: unknown; minimum?: unknown } : null;
|
|
405
443
|
if (!answer) return [refusalOf(SiteRefusalCode.Network, lang)];
|
|
406
444
|
const codes = answer.code === ORDER_REFUSED && Array.isArray(answer.refusals) && answer.refusals.length ? answer.refusals : [answer.code];
|
|
445
|
+
// A coupon's minimum is said as an amount (`{amount}`), in the host's money format.
|
|
446
|
+
const fill: Record<string, string> = isMoney(answer.minimum) && formatMoney ? { amount: formatMoney(answer.minimum) } : {};
|
|
407
447
|
const seen = new Set<CheckoutSlot>();
|
|
408
|
-
return codes.map(code => refusalOf(code, lang)).filter(r => !seen.has(r.slot) && !!seen.add(r.slot));
|
|
448
|
+
return codes.map(code => refusalOf(code, lang, fill)).filter(r => !seen.has(r.slot) && !!seen.add(r.slot));
|
|
409
449
|
}
|