@zappie/foundations 0.11.1 → 0.12.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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @zappie/foundations
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 919ca1c: `@zappie/foundations/checkout` holds checkout behaviour with no markup: `useCheckoutFlow` for a bag or a cart page. It keeps how the order arrives and where, the contact details, the time, issues and their fixes and held totals, and one Pay button that guides the shopper to what is missing before it opens payment. A guest pays with a phone number, and sign-in is asked only when the business requires a customer. Payment comes back to `/checkout/return`, and a cancel to `/checkout`. Your template draws every surface. The subpath loads only where you import it, never with the initial entry.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [208a60c]
12
+ - @zappie/sdk@0.10.6
13
+
3
14
  ## 0.11.1
4
15
 
5
16
  ### Patch Changes
package/README.md CHANGED
@@ -36,6 +36,7 @@ Want ready-made, styled components instead? Copy them into your project from the
36
36
  | `@zappie/foundations` | Every part |
37
37
  | `@zappie/foundations/next` | Keeping overlays in step with Back and Forward in a Next.js app |
38
38
  | `@zappie/foundations/branch-switch` | Choosing a branch in a React Router site without waiting for the server |
39
+ | `@zappie/foundations/checkout` | Checkout behaviour for a bag or a cart page, with no markup |
39
40
  | `@zappie/foundations/rich-text` | Sanitising and parsing merchant rich text before you render it |
40
41
 
41
42
  ## Docs
@@ -153,6 +154,34 @@ return isOpen ? (
153
154
  ) : null;
154
155
  ```
155
156
 
157
+ ## Checkout flow
158
+
159
+ `useCheckoutFlow` from `@zappie/foundations/checkout` holds a checkout's behaviour and renders nothing. Your template draws the bag or cart page, each field and every word. Call it inside a `ZappieProvider`, and pass the clients once, not on every render.
160
+
161
+ ```tsx
162
+ import { useCheckoutFlow } from "@zappie/foundations/checkout";
163
+
164
+ const flow = useCheckoutFlow({ branch, menu, contactFields });
165
+
166
+ <button
167
+ type="button"
168
+ data-zappie-checkout=""
169
+ data-state={flow.pay.status}
170
+ disabled={!flow.pay.enabled}
171
+ aria-busy={flow.pay.status === "busy" || undefined}
172
+ onClick={async () => show(await flow.pay.activate())}
173
+ >
174
+ {labels[flow.pay.status]}
175
+ </button>;
176
+ ```
177
+
178
+ - `pay.status` is one of, in this order: `busy`, `empty`, `checking`, `closed`, `address`, `area`, `time`, `fix_issues`, `sign_in`, `phone`, `contact`, `quoting`, `retry` and `pay`. The first that applies wins.
179
+ - `pay.activate()` opens payment for `pay`, signs in for `sign_in` and asks for the total again for `retry`. For the other enabled statuses it returns the step to show: `{ step: "address" }`, `"area"`, `"time"`, `{ step: "issue", issue }` or `{ step: "contact", field }`.
180
+ - A guest pays with a phone number. Sign-in is asked only when the quote, or opening payment, says the business requires a customer.
181
+ - Payment comes back to `/checkout/return`, and a cancel to `reviewPath`, `/checkout` by default. A sign-in comes back there too, and the details the shopper typed are kept in session storage.
182
+ - Pressing Pay counts the visit's `checkout` event.
183
+ - `error` is `quote_failed`, `open_failed` or `sign_in_failed`, for your own message.
184
+
156
185
  ## Branch switch
157
186
 
158
187
  Choosing a branch shows that branch's menu without waiting for the server. A
@@ -0,0 +1,48 @@
1
+ // src/checkout/attempt.ts
2
+ import { checkoutFulfilment } from "@zappie/sdk/checkout";
3
+ function fulfilment(payload) {
4
+ const value = checkoutFulfilment(payload.fulfilment);
5
+ if (value.type === "dine_in") {
6
+ throw new Error("Dine-in checkout is unavailable");
7
+ }
8
+ const scheduled = value.scheduled_for !== void 0 ? { scheduled_for: value.scheduled_for } : {};
9
+ if (value.type === "pickup") {
10
+ return { type: "pickup", ...scheduled };
11
+ }
12
+ return {
13
+ type: "delivery",
14
+ ...value.address !== void 0 ? { address: value.address } : {},
15
+ ...value.delivery_region_id !== void 0 ? { delivery_region_id: value.delivery_region_id } : {},
16
+ ...value.instructions !== void 0 ? { instructions: value.instructions } : {},
17
+ ...scheduled
18
+ };
19
+ }
20
+ function createCheckoutAttempt() {
21
+ let current;
22
+ return (input) => {
23
+ const { payload, attribution } = input;
24
+ const phone = input.contactPhone.trim().replace(/\s+/g, "");
25
+ const digest = JSON.stringify({ payload, phone });
26
+ if (current?.digest === digest) {
27
+ return current.attempt;
28
+ }
29
+ const request = {
30
+ branch_id: input.branchId,
31
+ menu_version: payload.menu_version,
32
+ lines: payload.lines,
33
+ fulfilment: fulfilment(payload),
34
+ ...phone ? { contact_phone: phone } : {},
35
+ ...payload.promo_code ? { promo_code: payload.promo_code } : {},
36
+ ...attribution.source ? { source: attribution.source } : {},
37
+ ...attribution.campaign ? { campaign: attribution.campaign } : {},
38
+ return_url: input.returnUrl,
39
+ cancel_url: input.cancelUrl
40
+ };
41
+ current = { digest, attempt: { key: crypto.randomUUID(), request } };
42
+ return current.attempt;
43
+ };
44
+ }
45
+ export {
46
+ createCheckoutAttempt
47
+ };
48
+ //# sourceMappingURL=attempt.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/checkout/attempt.ts"],
4
+ "mappings": ";AACA,SAAS,0BAAgD;AAOzD,SAAS,WAAW,SAAiD;AACnE,QAAM,QAAQ,mBAAmB,QAAQ,UAAU;AACnD,MAAI,MAAM,SAAS,WAAW;AAC5B,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AACA,QAAM,YACJ,MAAM,kBAAkB,SACpB,EAAE,eAAe,MAAM,cAAc,IACrC,CAAC;AACP,MAAI,MAAM,SAAS,UAAU;AAC3B,WAAO,EAAE,MAAM,UAAU,GAAG,UAAU;AAAA,EACxC;AACA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,GAAI,MAAM,YAAY,SAAY,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;AAAA,IAChE,GAAI,MAAM,uBAAuB,SAC7B,EAAE,oBAAoB,MAAM,mBAAmB,IAC/C,CAAC;AAAA,IACL,GAAI,MAAM,iBAAiB,SACvB,EAAE,cAAc,MAAM,aAAa,IACnC,CAAC;AAAA,IACL,GAAG;AAAA,EACL;AACF;AAQO,SAAS,wBAAwB;AACtC,MAAI;AACJ,SAAO,CAAC,UAOe;AACrB,UAAM,EAAE,SAAS,YAAY,IAAI;AACjC,UAAM,QAAQ,MAAM,aAAa,KAAK,EAAE,QAAQ,QAAQ,EAAE;AAC1D,UAAM,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC;AAChD,QAAI,SAAS,WAAW,QAAQ;AAC9B,aAAO,QAAQ;AAAA,IACjB;AACA,UAAM,UAA2B;AAAA,MAC/B,WAAW,MAAM;AAAA,MACjB,cAAc,QAAQ;AAAA,MACtB,OAAO,QAAQ;AAAA,MACf,YAAY,WAAW,OAAO;AAAA,MAC9B,GAAI,QAAQ,EAAE,eAAe,MAAM,IAAI,CAAC;AAAA,MACxC,GAAI,QAAQ,aAAa,EAAE,YAAY,QAAQ,WAAW,IAAI,CAAC;AAAA,MAC/D,GAAI,YAAY,SAAS,EAAE,QAAQ,YAAY,OAAO,IAAI,CAAC;AAAA,MAC3D,GAAI,YAAY,WAAW,EAAE,UAAU,YAAY,SAAS,IAAI,CAAC;AAAA,MACjE,YAAY,MAAM;AAAA,MAClB,YAAY,MAAM;AAAA,IACpB;AACA,cAAU,EAAE,QAAQ,SAAS,EAAE,KAAK,OAAO,WAAW,GAAG,QAAQ,EAAE;AACnE,WAAO,QAAQ;AAAA,EACjB;AACF;",
5
+ "names": []
6
+ }
@@ -0,0 +1,36 @@
1
+ // src/checkout/contact.ts
2
+ import { isContactPhoneValid } from "@zappie/sdk/checkout";
3
+ function fullPhone(typed, dialCode = "+234") {
4
+ const value = typed.trim().replace(/\s+/g, "");
5
+ if (!value) {
6
+ return "";
7
+ }
8
+ return value.startsWith("+") ? value : `${dialCode}${value.replace(/^0/, "")}`;
9
+ }
10
+ var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
11
+ function contactProblems(fields, values, phone, accountPhone, dialCode = "+234") {
12
+ const problems = {};
13
+ if (!phone.trim()) {
14
+ if (!accountPhone) {
15
+ problems.phone = "missing";
16
+ }
17
+ } else if (!isContactPhoneValid(fullPhone(phone, dialCode))) {
18
+ problems.phone = "invalid";
19
+ }
20
+ for (const field of fields) {
21
+ const value = values[field.key]?.trim() ?? "";
22
+ if (!value) {
23
+ if (field.required) {
24
+ problems[field.key] = "missing";
25
+ }
26
+ } else if (field.type === "email" && !emailPattern.test(value) || field.type === "tel" && !isContactPhoneValid(value)) {
27
+ problems[field.key] = "invalid";
28
+ }
29
+ }
30
+ return problems;
31
+ }
32
+ export {
33
+ contactProblems,
34
+ fullPhone
35
+ };
36
+ //# sourceMappingURL=contact.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/checkout/contact.ts"],
4
+ "mappings": ";AAAA,SAAS,2BAA2B;AA0B7B,SAAS,UAAU,OAAe,WAAW,QAAgB;AAClE,QAAM,QAAQ,MAAM,KAAK,EAAE,QAAQ,QAAQ,EAAE;AAC7C,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AACA,SAAO,MAAM,WAAW,GAAG,IACvB,QACA,GAAG,QAAQ,GAAG,MAAM,QAAQ,MAAM,EAAE,CAAC;AAC3C;AAEA,IAAM,eAAe;AAad,SAAS,gBACd,QACA,QACA,OACA,cACA,WAAW,QACqB;AAChC,QAAM,WAA2C,CAAC;AAClD,MAAI,CAAC,MAAM,KAAK,GAAG;AACjB,QAAI,CAAC,cAAc;AACjB,eAAS,QAAQ;AAAA,IACnB;AAAA,EACF,WAAW,CAAC,oBAAoB,UAAU,OAAO,QAAQ,CAAC,GAAG;AAC3D,aAAS,QAAQ;AAAA,EACnB;AACA,aAAW,SAAS,QAAQ;AAC1B,UAAM,QAAQ,OAAO,MAAM,GAAG,GAAG,KAAK,KAAK;AAC3C,QAAI,CAAC,OAAO;AACV,UAAI,MAAM,UAAU;AAClB,iBAAS,MAAM,GAAG,IAAI;AAAA,MACxB;AAAA,IACF,WACG,MAAM,SAAS,WAAW,CAAC,aAAa,KAAK,KAAK,KAClD,MAAM,SAAS,SAAS,CAAC,oBAAoB,KAAK,GACnD;AACA,eAAS,MAAM,GAAG,IAAI;AAAA,IACxB;AAAA,EACF;AACA,SAAO;AACT;",
5
+ "names": []
6
+ }
@@ -0,0 +1,309 @@
1
+ import { CartModule, CartState, CartIssue, Branch, Menu, CartLine, CartFulfilment, DeliveryAddress, Quote, CartFix } from '@zappie/sdk';
2
+ import { CheckoutRequest, CheckoutClient } from '@zappie/sdk/checkout';
3
+ import { CustomerClient } from '@zappie/sdk/customer';
4
+
5
+ type Payload = ReturnType<CartModule["toCheckoutPayload"]>;
6
+ /** One checkout request and the idempotency key it keeps while its payload stays the same. */
7
+ type CheckoutAttempt = {
8
+ key: string;
9
+ request: CheckoutRequest;
10
+ };
11
+ /**
12
+ * Builds checkout requests that reuse one idempotency key for retries of the same payload and
13
+ * phone, and take a new key when either changes.
14
+ *
15
+ * @returns A function from the payload and its addresses to the attempt to open.
16
+ */
17
+ declare function createCheckoutAttempt(): (input: {
18
+ payload: Payload;
19
+ branchId: string;
20
+ contactPhone: string;
21
+ returnUrl: string;
22
+ cancelUrl: string;
23
+ attribution: {
24
+ source: string;
25
+ campaign: string;
26
+ };
27
+ }) => CheckoutAttempt;
28
+
29
+ /**
30
+ * A contact detail the business asks for beside the phone number, such as a name or an email,
31
+ * required or optional.
32
+ */
33
+ type ContactField = {
34
+ key: string;
35
+ label: string;
36
+ type: "text" | "email" | "tel";
37
+ required: boolean;
38
+ };
39
+ /** What the shopper typed in each contact field, by its key. */
40
+ type ContactValues = Readonly<Record<string, string>>;
41
+ /** Why a contact detail stops Pay: it is empty and required, or it doesn't read as valid. */
42
+ type ContactProblem = "missing" | "invalid";
43
+ /**
44
+ * The number to send: the shopper's own international number, or a local number typed without
45
+ * its dial code, with any leading 0 dropped.
46
+ *
47
+ * @param typed - The number as typed.
48
+ * @param dialCode - The dial code a local number takes, such as `+234`.
49
+ */
50
+ declare function fullPhone(typed: string, dialCode?: string): string;
51
+ /**
52
+ * What is wrong with each contact detail, by key, with `phone` for the phone. Empty when the
53
+ * shopper can pay. A guest always gives a phone. A signed-in shopper who types none pays with
54
+ * their account's.
55
+ *
56
+ * @param fields - The business's contact fields beside the phone.
57
+ * @param values - What the shopper typed in them.
58
+ * @param phone - The phone as typed.
59
+ * @param accountPhone - The signed-in customer's masked phone, when they have one.
60
+ * @param dialCode - The dial code a local number takes.
61
+ */
62
+ declare function contactProblems(fields: readonly ContactField[], values: ContactValues, phone: string, accountPhone?: string, dialCode?: string): Record<string, ContactProblem>;
63
+
64
+ /**
65
+ * Sends the shopper to sign in and come back to `path`, unless a sign-in for `path` just came
66
+ * back to this page without a session: then it stays and returns `false`, once.
67
+ */
68
+ declare function signInOnce(path: string): boolean;
69
+
70
+ /**
71
+ * What the one Pay button does now, in precedence order: the first that applies wins.
72
+ *
73
+ * - `busy`: payment or sign-in is opening. Disabled until the page unloads.
74
+ * - `empty`: the cart has no lines. Disabled.
75
+ * - `checking`: the cart hasn't hydrated or the session isn't known yet. Disabled.
76
+ * - `closed`: the branch takes no order now or ahead. Disabled.
77
+ * - `address`, `area`, `time`: enabled. A press asks for that step.
78
+ * - `fix_issues`: enabled. A press points at the first blocking issue.
79
+ * - `sign_in`: enabled, only when the business requires a customer for this order.
80
+ * - `phone`, `contact`: enabled. A press points at the first invalid field.
81
+ * - `quoting`: disabled while the total updates.
82
+ * - `retry`: enabled. A press asks for the total again.
83
+ * - `pay`: enabled. A press opens payment.
84
+ */
85
+ type CheckoutStatus = "busy" | "empty" | "checking" | "closed" | "address" | "area" | "time" | "fix_issues" | "sign_in" | "phone" | "contact" | "quoting" | "retry" | "pay";
86
+ /** Whether the shopper's session has been checked yet, and its answer. */
87
+ type CheckoutAuth = "unknown" | "authenticated" | "anonymous";
88
+ /** What decides the Pay button's status. */
89
+ type CheckoutStatusInput = {
90
+ busy: boolean;
91
+ hydrated: boolean;
92
+ lines: number;
93
+ auth: CheckoutAuth;
94
+ closed: boolean;
95
+ /** Delivery is chosen and the cart has no address for it. */
96
+ needsAddress: boolean;
97
+ needsTime: boolean;
98
+ state: CartState;
99
+ /** The last quote request for this cart failed. */
100
+ quoteFailed: boolean;
101
+ /** Opening payment answered that the business needs a signed-in customer. */
102
+ signInRequired: boolean;
103
+ /** The first contact field that stops Pay, with `phone` for the phone. */
104
+ contactField?: string | undefined;
105
+ };
106
+ /** Whether the Pay button takes a press in this status. */
107
+ declare function payEnabled(status: CheckoutStatus): boolean;
108
+ /** The issue `fix_issues` points at: the first blocking one, else the first the cart raised. */
109
+ declare function firstIssue(state: CartState): CartIssue | undefined;
110
+ /**
111
+ * The Pay button's status, in the precedence `CheckoutStatus` lists. Sign-in is asked only when
112
+ * the quote, or opening payment, says the business requires a customer. Otherwise a guest pays
113
+ * with a phone number.
114
+ *
115
+ * @param input - The cart, session, timing and contact state.
116
+ */
117
+ declare function checkoutStatus(input: CheckoutStatusInput): CheckoutStatus;
118
+
119
+ /** How the bag can be timed, as checkout decides it. */
120
+ type CheckoutTiming = {
121
+ /** Whether the branch takes orders for a later slot. */
122
+ ahead: boolean;
123
+ /** Whether a line sits only on pre-order menus that ask for notice, so it must be scheduled. */
124
+ notice: boolean;
125
+ /** Whether the order can be placed for now: the branch is open and nothing needs notice. */
126
+ canNow: boolean;
127
+ /** Whether the branch takes no order at all: closed, and not taking orders ahead either. */
128
+ closed: boolean;
129
+ /** Whether Pay waits for a time: the order can't be placed for now and no time is chosen. */
130
+ needsTime: boolean;
131
+ /** When a closed branch opens next, as an ISO instant, for a label such as "Opens at 7:00". */
132
+ opensAt?: string;
133
+ };
134
+ /**
135
+ * Whether the bag must be scheduled: a line sits only on pre-order menus that ask for notice. A
136
+ * line that names its menu is judged by it, otherwise by every menu that lists the item, as the
137
+ * API reads it.
138
+ *
139
+ * @param menu - The branch's menu, with its source menus and their schedules.
140
+ * @param lines - The cart's lines.
141
+ */
142
+ declare function mustSchedule(menu: Menu | undefined, lines: readonly Pick<CartLine, "itemId" | "menuId">[]): boolean;
143
+ /**
144
+ * How the bag can be timed. A branch that takes orders ahead offers now and later, now only while
145
+ * it is open and nothing in the bag needs notice. A branch that doesn't offers now while open and
146
+ * nothing while closed.
147
+ *
148
+ * @param branch - The cart's branch.
149
+ * @param menu - The branch's menu, for pre-order notice.
150
+ * @param lines - The cart's lines.
151
+ * @param scheduledFor - The chosen time, if any.
152
+ */
153
+ declare function checkoutTiming(branch: Branch, menu: Menu | undefined, lines: readonly Pick<CartLine, "itemId" | "menuId">[], scheduledFor?: string): CheckoutTiming;
154
+
155
+ /** How the order reaches the shopper. */
156
+ type CheckoutMode = "delivery" | "pickup";
157
+ /** The cart's delivery fulfilment. */
158
+ type CheckoutDelivery = Extract<CartFulfilment, {
159
+ type: "delivery";
160
+ }>;
161
+ /**
162
+ * The step the template shows next: the address, the delivery area, the time, an issue, a contact
163
+ * field (`phone` or the business field's key), or the item a line's option fix opens.
164
+ */
165
+ type CheckoutIntent = {
166
+ step: "address";
167
+ } | {
168
+ step: "area";
169
+ } | {
170
+ step: "time";
171
+ } | {
172
+ step: "issue";
173
+ issue: CartIssue;
174
+ } | {
175
+ step: "contact";
176
+ field: string;
177
+ } | {
178
+ step: "item";
179
+ itemId: string;
180
+ lineId: string;
181
+ };
182
+ /**
183
+ * A failure the template words: the total couldn't be priced, payment couldn't open, or a
184
+ * sign-in came back without a session the site can use.
185
+ */
186
+ type CheckoutFlowError = "quote_failed" | "open_failed" | "sign_in_failed";
187
+ /** The customer client methods the flow reads. */
188
+ type CheckoutCustomer = Pick<CustomerClient, "state" | "customer" | "onChange" | "addresses" | "session">;
189
+ /** Where the checkout flow reads its branch and how it leaves the page. */
190
+ type CheckoutFlowOptions = {
191
+ /** The cart's branch. */
192
+ branch: Branch;
193
+ /** The branch's menu, for pre-order notice on its source menus. */
194
+ menu?: Menu | undefined;
195
+ /** The contact fields the business asks for beside the phone. */
196
+ contactFields?: readonly ContactField[];
197
+ /** How the order can reach the shopper. Defaults to the branch's delivery and pickup. */
198
+ offers?: readonly CheckoutMode[];
199
+ /**
200
+ * The page payment's cancel and sign-in come back to. Defaults to `/checkout`, which reopens
201
+ * the bag on a food site and shows the cart page on a retail site.
202
+ */
203
+ reviewPath?: string;
204
+ /** The dial code a local phone number takes. Defaults to `+234`. */
205
+ dialCode?: string;
206
+ /** The session storage key prefix that keeps typed details across a sign-in. */
207
+ storageKey?: string;
208
+ /** The checkout client. Defaults to `createCheckout()`. */
209
+ checkout?: CheckoutClient;
210
+ /** The customer client. Defaults to `createCustomer()`, disposed on unmount. */
211
+ customer?: CheckoutCustomer;
212
+ /** Leaves for the payment page. Defaults to `redirectToCheckout` on the top window. */
213
+ redirect?: (url: string) => void;
214
+ /** Leaves to sign in and come back to `path`. Returns `false` when the shopper stayed. */
215
+ signIn?: (path: string) => boolean;
216
+ /** The visit's source and campaign. Defaults to `currentSource`. */
217
+ attribution?: () => {
218
+ source: string;
219
+ campaign: string;
220
+ };
221
+ };
222
+ /** The shopper's contact details and what stops Pay among them. */
223
+ type CheckoutContact = {
224
+ /** The phone as typed. */
225
+ phone: string;
226
+ /** The phone payment receives, with its dial code, or empty to use the account's. */
227
+ contactPhone: string;
228
+ setPhone(phone: string): void;
229
+ /** The signed-in customer's masked phone, used when the shopper types none. */
230
+ accountPhone?: string | undefined;
231
+ fields: readonly ContactField[];
232
+ values: ContactValues;
233
+ setField(key: string, value: string): void;
234
+ /** What stops Pay, by key, with `phone` for the phone. */
235
+ problems: Readonly<Record<string, ContactProblem>>;
236
+ /** The keys whose problem the template shows: blurred fields, and all of them after Pay. */
237
+ shown: ReadonlySet<string>;
238
+ show(key: string): void;
239
+ };
240
+ /** The one Pay button: its status, whether it takes a press, and what a press does. */
241
+ type CheckoutPay = {
242
+ status: CheckoutStatus;
243
+ enabled: boolean;
244
+ /** Where a `busy` button is going. */
245
+ leavingFor?: "payment" | "sign_in" | undefined;
246
+ /** The issue `fix_issues` points at. */
247
+ issue?: CartIssue | undefined;
248
+ /** The contact field `phone` or `contact` points at. */
249
+ field?: string | undefined;
250
+ /**
251
+ * Acts on the status: opens payment, signs in, asks for the total again, or returns the step
252
+ * the template shows next. Counts the visit's `checkout` event when it opens payment or sign-in.
253
+ */
254
+ activate(): Promise<CheckoutIntent | undefined>;
255
+ };
256
+ /** Checkout state and actions, with no markup. */
257
+ type CheckoutFlow = {
258
+ mode: CheckoutMode;
259
+ offers: readonly CheckoutMode[];
260
+ /** Chooses delivery or pickup. Returns the address step when delivery has no known address. */
261
+ choose(mode: CheckoutMode): CheckoutIntent | undefined;
262
+ delivery?: CheckoutDelivery | undefined;
263
+ /** Sets the delivery address, keeping the rider note, and remembers it on this device. */
264
+ setAddress(address: DeliveryAddress, options?: {
265
+ remember?: boolean;
266
+ }): void;
267
+ /** Sets the delivery area. Returns the address step when there is no address yet. */
268
+ setRegion(regionId: string): CheckoutIntent | undefined;
269
+ /** Sets the rider note. Returns the address step when there is no address yet. */
270
+ setNote(note: string): CheckoutIntent | undefined;
271
+ scheduledFor?: string | undefined;
272
+ /** Chooses a time, or now with `null`. */
273
+ schedule(at: string | null): void;
274
+ timing: CheckoutTiming;
275
+ contact: CheckoutContact;
276
+ auth: CheckoutAuth;
277
+ quote?: Quote | undefined;
278
+ /** Whether the total is being updated. */
279
+ pricing: boolean;
280
+ /**
281
+ * Whether the quote holds lines until a time is chosen (`time`) or the branch opens
282
+ * (`opening`), and so prices none of them: show the cart's subtotal and a note, never zero.
283
+ */
284
+ held?: "time" | "opening" | undefined;
285
+ /** The cart's issues, without Choose a time fixes where the branch takes no orders ahead. */
286
+ issues: readonly CartIssue[];
287
+ /** Applies an issue's fix, or returns the step the template shows for it. */
288
+ fix(issue: CartIssue, action: CartFix): CheckoutIntent | undefined;
289
+ error?: CheckoutFlowError | undefined;
290
+ clearError(): void;
291
+ pay: CheckoutPay;
292
+ };
293
+ /**
294
+ * The whole checkout's behaviour, headless: how the order arrives and where, contact details, the
295
+ * time, issues and their fixes, totals while held, and one Pay button that guides the shopper to
296
+ * what is missing before it opens payment. It renders nothing. The template draws every surface.
297
+ *
298
+ * A guest pays with a phone number. Sign-in is asked only when the quote, or opening payment,
299
+ * says the business requires a customer. Payment returns to `/checkout/return` and a cancel comes
300
+ * back to `reviewPath`. Typed details are kept in session storage, so a sign-in loses nothing.
301
+ * Call it inside a `ZappieProvider`.
302
+ *
303
+ * @param options - The branch, menu and contact fields, and the clients to use.
304
+ * @returns State and actions for the bag or cart page.
305
+ */
306
+ declare function useCheckoutFlow(options: CheckoutFlowOptions): CheckoutFlow;
307
+
308
+ export { checkoutStatus, checkoutTiming, contactProblems, createCheckoutAttempt, firstIssue, fullPhone, mustSchedule, payEnabled, signInOnce, useCheckoutFlow };
309
+ export type { CheckoutAttempt, CheckoutAuth, CheckoutContact, CheckoutCustomer, CheckoutDelivery, CheckoutFlow, CheckoutFlowError, CheckoutFlowOptions, CheckoutIntent, CheckoutMode, CheckoutPay, CheckoutStatus, CheckoutStatusInput, CheckoutTiming, ContactField, ContactProblem, ContactValues };
@@ -0,0 +1,22 @@
1
+ "use client";
2
+
3
+ // src/checkout/index.ts
4
+ import { createCheckoutAttempt } from "./attempt.js";
5
+ import { contactProblems, fullPhone } from "./contact.js";
6
+ import { signInOnce } from "./sign-in.js";
7
+ import { checkoutStatus, firstIssue, payEnabled } from "./status.js";
8
+ import { checkoutTiming, mustSchedule } from "./timing.js";
9
+ import { useCheckoutFlow } from "./use-checkout-flow.js";
10
+ export {
11
+ checkoutStatus,
12
+ checkoutTiming,
13
+ contactProblems,
14
+ createCheckoutAttempt,
15
+ firstIssue,
16
+ fullPhone,
17
+ mustSchedule,
18
+ payEnabled,
19
+ signInOnce,
20
+ useCheckoutFlow
21
+ };
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/checkout/index.ts"],
4
+ "mappings": ";;;AAGA,SAAS,6BAA6B;AAEtC,SAAS,iBAAiB,iBAAiB;AAE3C,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB,YAAY,kBAAkB;AAMvD,SAAS,gBAAgB,oBAAoB;AAE7C,SAAS,uBAAuB;",
5
+ "names": []
6
+ }
@@ -0,0 +1,26 @@
1
+ // src/checkout/sign-in.ts
2
+ var ATTEMPT_KEY = "zappie:sign-in";
3
+ var ATTEMPT_MS = 10 * 6e4;
4
+ function returnedFromSignIn(path) {
5
+ const attempt = sessionStorage.getItem(ATTEMPT_KEY) ?? "";
6
+ const space = attempt.indexOf(" ");
7
+ const at = Number(attempt.slice(0, space));
8
+ const [navigation] = performance.getEntriesByType("navigation");
9
+ return space > 0 && attempt.slice(space + 1) === path && at < performance.timeOrigin && Date.now() - at < ATTEMPT_MS && navigation?.type !== "back_forward";
10
+ }
11
+ function signInOnce(path) {
12
+ try {
13
+ if (returnedFromSignIn(path)) {
14
+ sessionStorage.removeItem(ATTEMPT_KEY);
15
+ return false;
16
+ }
17
+ sessionStorage.setItem(ATTEMPT_KEY, `${Date.now()} ${path}`);
18
+ } catch {
19
+ }
20
+ window.location.assign(`/_zappie/login?return=${encodeURIComponent(path)}`);
21
+ return true;
22
+ }
23
+ export {
24
+ signInOnce
25
+ };
26
+ //# sourceMappingURL=sign-in.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/checkout/sign-in.ts"],
4
+ "mappings": ";AAEA,IAAM,cAAc;AAEpB,IAAM,aAAa,KAAK;AAExB,SAAS,mBAAmB,MAAuB;AACjD,QAAM,UAAU,eAAe,QAAQ,WAAW,KAAK;AACvD,QAAM,QAAQ,QAAQ,QAAQ,GAAG;AACjC,QAAM,KAAK,OAAO,QAAQ,MAAM,GAAG,KAAK,CAAC;AACzC,QAAM,CAAC,UAAU,IAAI,YAAY,iBAAiB,YAAY;AAE9D,SACE,QAAQ,KACR,QAAQ,MAAM,QAAQ,CAAC,MAAM,QAC7B,KAAK,YAAY,cACjB,KAAK,IAAI,IAAI,KAAK,cAClB,YAAY,SAAS;AAEzB;AAMO,SAAS,WAAW,MAAuB;AAChD,MAAI;AACF,QAAI,mBAAmB,IAAI,GAAG;AAC5B,qBAAe,WAAW,WAAW;AACrC,aAAO;AAAA,IACT;AACA,mBAAe,QAAQ,aAAa,GAAG,KAAK,IAAI,CAAC,IAAI,IAAI,EAAE;AAAA,EAC7D,QAAQ;AAAA,EAER;AACA,SAAO,SAAS,OAAO,yBAAyB,mBAAmB,IAAI,CAAC,EAAE;AAC1E,SAAO;AACT;",
5
+ "names": []
6
+ }
@@ -0,0 +1,73 @@
1
+ // src/checkout/status.ts
2
+ var ENABLED = /* @__PURE__ */ new Set([
3
+ "address",
4
+ "area",
5
+ "time",
6
+ "fix_issues",
7
+ "sign_in",
8
+ "phone",
9
+ "contact",
10
+ "retry",
11
+ "pay"
12
+ ]);
13
+ function payEnabled(status) {
14
+ return ENABLED.has(status);
15
+ }
16
+ function quoteOf(state) {
17
+ return "quote" in state ? state.quote : void 0;
18
+ }
19
+ function firstIssue(state) {
20
+ const issues = state.status === "needs_attention" ? state.issues : quoteOf(state)?.issues ?? [];
21
+ return issues.find((issue) => issue.severity === "blocking") ?? issues[0];
22
+ }
23
+ function checkoutStatus(input) {
24
+ const { state } = input;
25
+ if (input.busy) {
26
+ return "busy";
27
+ }
28
+ if (input.hydrated && input.lines === 0) {
29
+ return "empty";
30
+ }
31
+ if (!input.hydrated || input.auth === "unknown") {
32
+ return "checking";
33
+ }
34
+ if (input.closed) {
35
+ return "closed";
36
+ }
37
+ if (input.needsAddress) {
38
+ return "address";
39
+ }
40
+ const quote = quoteOf(state);
41
+ const issues = state.status === "needs_attention" ? state.issues : quote?.issues ?? [];
42
+ if (issues.some((issue) => issue.code === "delivery_region_required")) {
43
+ return "area";
44
+ }
45
+ if (input.needsTime) {
46
+ return "time";
47
+ }
48
+ if (issues.some((issue) => issue.severity === "blocking") || state.status === "needs_attention" && issues.length > 0 || quote && (!quote.canCheckout || quote.checkout.reason === "issues")) {
49
+ return "fix_issues";
50
+ }
51
+ if (input.signInRequired || quote?.checkout.reason === "customer_required") {
52
+ return "sign_in";
53
+ }
54
+ if (input.contactField !== void 0) {
55
+ return input.contactField === "phone" ? "phone" : "contact";
56
+ }
57
+ if (state.status === "quoting") {
58
+ return "quoting";
59
+ }
60
+ if (input.quoteFailed || state.status === "needs_attention" && !quote) {
61
+ return "retry";
62
+ }
63
+ if (quote) {
64
+ return "pay";
65
+ }
66
+ return "quoting";
67
+ }
68
+ export {
69
+ checkoutStatus,
70
+ firstIssue,
71
+ payEnabled
72
+ };
73
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/checkout/status.ts"],
4
+ "mappings": ";AAuDA,IAAM,UAAuC,oBAAI,IAAI;AAAA,EACnD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,SAAS,WAAW,QAAiC;AAC1D,SAAO,QAAQ,IAAI,MAAM;AAC3B;AAEA,SAAS,QAAQ,OAAqC;AACpD,SAAO,WAAW,QAAQ,MAAM,QAAQ;AAC1C;AAGO,SAAS,WAAW,OAAyC;AAClE,QAAM,SACJ,MAAM,WAAW,oBACb,MAAM,SACL,QAAQ,KAAK,GAAG,UAAU,CAAC;AAClC,SAAO,OAAO,KAAK,CAAC,UAAU,MAAM,aAAa,UAAU,KAAK,OAAO,CAAC;AAC1E;AASO,SAAS,eAAe,OAA4C;AACzE,QAAM,EAAE,MAAM,IAAI;AAClB,MAAI,MAAM,MAAM;AACd,WAAO;AAAA,EACT;AACA,MAAI,MAAM,YAAY,MAAM,UAAU,GAAG;AACvC,WAAO;AAAA,EACT;AACA,MAAI,CAAC,MAAM,YAAY,MAAM,SAAS,WAAW;AAC/C,WAAO;AAAA,EACT;AACA,MAAI,MAAM,QAAQ;AAChB,WAAO;AAAA,EACT;AACA,MAAI,MAAM,cAAc;AACtB,WAAO;AAAA,EACT;AACA,QAAM,QAAQ,QAAQ,KAAK;AAC3B,QAAM,SACJ,MAAM,WAAW,oBAAoB,MAAM,SAAU,OAAO,UAAU,CAAC;AACzE,MAAI,OAAO,KAAK,CAAC,UAAU,MAAM,SAAS,0BAA0B,GAAG;AACrE,WAAO;AAAA,EACT;AACA,MAAI,MAAM,WAAW;AACnB,WAAO;AAAA,EACT;AAEA,MACE,OAAO,KAAK,CAAC,UAAU,MAAM,aAAa,UAAU,KACnD,MAAM,WAAW,qBAAqB,OAAO,SAAS,KACtD,UAAU,CAAC,MAAM,eAAe,MAAM,SAAS,WAAW,WAC3D;AACA,WAAO;AAAA,EACT;AACA,MAAI,MAAM,kBAAkB,OAAO,SAAS,WAAW,qBAAqB;AAC1E,WAAO;AAAA,EACT;AACA,MAAI,MAAM,iBAAiB,QAAW;AACpC,WAAO,MAAM,iBAAiB,UAAU,UAAU;AAAA,EACpD;AACA,MAAI,MAAM,WAAW,WAAW;AAC9B,WAAO;AAAA,EACT;AACA,MAAI,MAAM,eAAgB,MAAM,WAAW,qBAAqB,CAAC,OAAQ;AACvE,WAAO;AAAA,EACT;AACA,MAAI,OAAO;AACT,WAAO;AAAA,EACT;AACA,SAAO;AACT;",
5
+ "names": []
6
+ }
@@ -0,0 +1,39 @@
1
+ // src/checkout/timing.ts
2
+ import { canOrderAhead } from "../status/hours.js";
3
+ function mustSchedule(menu, lines) {
4
+ const sections = menu?.menus ?? [];
5
+ const notice = (id) => {
6
+ const schedule = sections.find((section) => section.id === id)?.schedule;
7
+ return Boolean(
8
+ schedule?.preorder && (schedule.preorderNoticeHours ?? 0) > 0
9
+ );
10
+ };
11
+ return lines.some((line) => {
12
+ const menus = line.menuId ? [line.menuId] : sections.filter(
13
+ (section) => section.categoryIds.some(
14
+ (categoryId) => menu?.categories.find((category) => category.id === categoryId)?.itemIds.includes(line.itemId)
15
+ )
16
+ ).map((section) => section.id);
17
+ return menus.length > 0 && menus.every(notice);
18
+ });
19
+ }
20
+ function checkoutTiming(branch, menu, lines, scheduledFor) {
21
+ const ahead = canOrderAhead(branch);
22
+ const notice = mustSchedule(menu, lines);
23
+ const canNow = branch.isOpen && !notice;
24
+ const closed = !branch.isOpen && !ahead;
25
+ const opensAt = branch.isOpen ? void 0 : branch.closedUntil ?? branch.nextChangeAt;
26
+ return {
27
+ ahead,
28
+ notice,
29
+ canNow,
30
+ closed,
31
+ needsTime: ahead && !canNow && !scheduledFor,
32
+ ...opensAt ? { opensAt } : {}
33
+ };
34
+ }
35
+ export {
36
+ checkoutTiming,
37
+ mustSchedule
38
+ };
39
+ //# sourceMappingURL=timing.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/checkout/timing.ts"],
4
+ "mappings": ";AACA,SAAS,qBAAqB;AA0BvB,SAAS,aACd,MACA,OACS;AACT,QAAM,WAAW,MAAM,SAAS,CAAC;AACjC,QAAM,SAAS,CAAC,OAAe;AAC7B,UAAM,WAAW,SAAS,KAAK,CAAC,YAAY,QAAQ,OAAO,EAAE,GAAG;AAChE,WAAO;AAAA,MACL,UAAU,aAAa,SAAS,uBAAuB,KAAK;AAAA,IAC9D;AAAA,EACF;AACA,SAAO,MAAM,KAAK,CAAC,SAAS;AAC1B,UAAM,QAAQ,KAAK,SACf,CAAC,KAAK,MAAM,IACZ,SACG;AAAA,MAAO,CAAC,YACP,QAAQ,YAAY;AAAA,QAAK,CAAC,eACxB,MAAM,WACH,KAAK,CAAC,aAAa,SAAS,OAAO,UAAU,GAC5C,QAAQ,SAAS,KAAK,MAAM;AAAA,MAClC;AAAA,IACF,EACC,IAAI,CAAC,YAAY,QAAQ,EAAE;AAClC,WAAO,MAAM,SAAS,KAAK,MAAM,MAAM,MAAM;AAAA,EAC/C,CAAC;AACH;AAYO,SAAS,eACd,QACA,MACA,OACA,cACgB;AAChB,QAAM,QAAQ,cAAc,MAAM;AAClC,QAAM,SAAS,aAAa,MAAM,KAAK;AACvC,QAAM,SAAS,OAAO,UAAU,CAAC;AACjC,QAAM,SAAS,CAAC,OAAO,UAAU,CAAC;AAClC,QAAM,UAAU,OAAO,SACnB,SACC,OAAO,eAAe,OAAO;AAClC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,SAAS,CAAC,UAAU,CAAC;AAAA,IAChC,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC/B;AACF;",
5
+ "names": []
6
+ }
@@ -0,0 +1,472 @@
1
+ "use client";
2
+
3
+ // src/checkout/use-checkout-flow.ts
4
+ import {
5
+ holdsForLater,
6
+ isHeldQuote
7
+ } from "@zappie/sdk";
8
+ import {
9
+ CheckoutError,
10
+ createCheckout
11
+ } from "@zappie/sdk/checkout";
12
+ import {
13
+ defaultRegion,
14
+ prefillFulfilment,
15
+ rememberAddress,
16
+ rememberedAddress,
17
+ watchCheckoutDefaults
18
+ } from "@zappie/sdk/checkout-defaults";
19
+ import { createCustomer } from "@zappie/sdk/customer";
20
+ import { usePendingNavigation } from "@zappie/sdk/navigation/react";
21
+ import { useCart } from "@zappie/sdk/react";
22
+ import { redirectToCheckout } from "@zappie/sdk/redirect";
23
+ import { countEvent, currentSource } from "@zappie/sdk/visits";
24
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
25
+ import { createCheckoutAttempt } from "./attempt.js";
26
+ import {
27
+ contactProblems,
28
+ fullPhone
29
+ } from "./contact.js";
30
+ import { signInOnce } from "./sign-in.js";
31
+ import {
32
+ checkoutStatus,
33
+ firstIssue,
34
+ payEnabled
35
+ } from "./status.js";
36
+ import { checkoutTiming } from "./timing.js";
37
+ function readSession(key) {
38
+ try {
39
+ return window.sessionStorage.getItem(key);
40
+ } catch {
41
+ return null;
42
+ }
43
+ }
44
+ function writeSession(key, value) {
45
+ try {
46
+ window.sessionStorage.setItem(key, value);
47
+ } catch {
48
+ }
49
+ }
50
+ var aborted = (failure) => failure instanceof Error && failure.name === "AbortError";
51
+ var NO_FIELDS = [];
52
+ function useCheckoutFlow(options) {
53
+ const {
54
+ branch,
55
+ menu,
56
+ contactFields = NO_FIELDS,
57
+ reviewPath = "/checkout",
58
+ dialCode = "+234",
59
+ storageKey = "zappie:checkout"
60
+ } = options;
61
+ const cart = useCart();
62
+ const checkout = useMemo(
63
+ () => options.checkout ?? createCheckout(),
64
+ [options.checkout]
65
+ );
66
+ const customer = useMemo(
67
+ () => options.customer ?? createCustomer(),
68
+ [options.customer]
69
+ );
70
+ const owned = options.customer === void 0;
71
+ const attempt = useMemo(() => createCheckoutAttempt(), []);
72
+ const leaving = usePendingNavigation();
73
+ const [auth, setAuth] = useState("unknown");
74
+ const [defaults, setDefaults] = useState();
75
+ const [phone, setPhoneState] = useState("");
76
+ const [values, setValues] = useState({});
77
+ const [shown, setShown] = useState(/* @__PURE__ */ new Set());
78
+ const [error, setError] = useState();
79
+ const [signInRequired, setSignInRequired] = useState(false);
80
+ const [leavingFor, setLeavingFor] = useState();
81
+ const [failedKey, setFailedKey] = useState();
82
+ const offers = useMemo(
83
+ () => options.offers ?? ["delivery", "pickup"].filter(
84
+ (type) => branch.fulfilment[type]
85
+ ),
86
+ [options.offers, branch.fulfilment]
87
+ );
88
+ const branchId = cart.branchId ?? branch.id;
89
+ const fulfilment = cart.fulfilment;
90
+ const [mode, setMode] = useState(
91
+ fulfilment?.type === "pickup" ? "pickup" : offers[0] ?? "pickup"
92
+ );
93
+ const [pendingAt, setPendingAt] = useState();
94
+ const synced = useRef(false);
95
+ useEffect(() => {
96
+ if (!cart.isHydrated || synced.current) {
97
+ return;
98
+ }
99
+ synced.current = true;
100
+ if (fulfilment?.type === "delivery" || fulfilment?.type === "pickup") {
101
+ setMode(fulfilment.type);
102
+ }
103
+ }, [cart.isHydrated, fulfilment?.type]);
104
+ const delivery = mode === "delivery" && fulfilment?.type === "delivery" ? fulfilment : void 0;
105
+ const scheduledFor = (fulfilment && fulfilment.type !== "dine_in" && fulfilment.type === mode ? fulfilment.scheduledFor : void 0) ?? pendingAt;
106
+ useEffect(() => {
107
+ setPhoneState(readSession(`${storageKey}.phone`) ?? "");
108
+ try {
109
+ setValues(
110
+ JSON.parse(
111
+ readSession(`${storageKey}.contact`) ?? "{}"
112
+ )
113
+ );
114
+ } catch {
115
+ setValues({});
116
+ }
117
+ }, [storageKey]);
118
+ const read = useRef({ branch, fulfilment });
119
+ read.current = { branch, fulfilment };
120
+ useEffect(() => {
121
+ const stopDefaults = watchCheckoutDefaults(
122
+ customer,
123
+ () => read.current,
124
+ setDefaults
125
+ );
126
+ const stopAuth = customer.onChange((state) => setAuth(state));
127
+ void customer.session().then(
128
+ (current) => setAuth(current ? "authenticated" : "anonymous"),
129
+ () => setAuth("anonymous")
130
+ );
131
+ return () => {
132
+ stopDefaults();
133
+ stopAuth();
134
+ if (owned && "dispose" in customer) {
135
+ customer.dispose();
136
+ }
137
+ };
138
+ }, [customer, owned]);
139
+ useEffect(() => {
140
+ if (cart.isHydrated && cart.lines.length > 0 && mode === "pickup" && fulfilment?.type !== "pickup") {
141
+ cart.actions.setFulfilment({
142
+ type: "pickup",
143
+ branchId,
144
+ ...pendingAt ? { scheduledFor: pendingAt } : {}
145
+ });
146
+ }
147
+ }, [
148
+ branchId,
149
+ cart.actions,
150
+ cart.isHydrated,
151
+ cart.lines.length,
152
+ fulfilment?.type,
153
+ mode,
154
+ pendingAt
155
+ ]);
156
+ const setDelivery = useCallback(
157
+ (patch, at = scheduledFor) => {
158
+ const address = patch.address ?? delivery?.address;
159
+ if (!address?.line1) {
160
+ return;
161
+ }
162
+ const regionId = defaultRegion(
163
+ branch,
164
+ patch.deliveryRegionId ?? delivery?.deliveryRegionId
165
+ );
166
+ cart.actions.setFulfilment({
167
+ type: "delivery",
168
+ branchId,
169
+ address,
170
+ ...regionId ? { deliveryRegionId: regionId } : {},
171
+ ...at ? { scheduledFor: at } : {}
172
+ });
173
+ },
174
+ [branch, branchId, cart.actions, delivery, scheduledFor]
175
+ );
176
+ const prefilled = useRef(void 0);
177
+ useEffect(() => {
178
+ if (!cart.isHydrated || cart.lines.length === 0) {
179
+ return;
180
+ }
181
+ const filled = prefillFulfilment(fulfilment, branch);
182
+ if (filled && filled !== fulfilment) {
183
+ cart.actions.setFulfilment(filled);
184
+ return;
185
+ }
186
+ const address = defaults?.address;
187
+ if (mode === "delivery" && !fulfilment && address && prefilled.current !== address) {
188
+ prefilled.current = address;
189
+ setDelivery({ address });
190
+ }
191
+ }, [
192
+ branch,
193
+ cart.actions,
194
+ cart.isHydrated,
195
+ cart.lines.length,
196
+ defaults?.address,
197
+ fulfilment,
198
+ mode,
199
+ setDelivery
200
+ ]);
201
+ const quoteKey = JSON.stringify([cart.lines, fulfilment, cart.promoCode]);
202
+ const quoted = useRef("");
203
+ useEffect(() => {
204
+ if (cart.isHydrated && cart.lines.length > 0 && cart.state.status === "ready" && quoted.current !== quoteKey) {
205
+ quoted.current = quoteKey;
206
+ void cart.actions.quote().then(
207
+ () => {
208
+ setFailedKey(void 0);
209
+ setError(
210
+ (current) => current === "quote_failed" ? void 0 : current
211
+ );
212
+ },
213
+ (failure) => {
214
+ if (!aborted(failure)) {
215
+ setFailedKey(quoteKey);
216
+ setError("quote_failed");
217
+ }
218
+ }
219
+ );
220
+ }
221
+ }, [
222
+ cart.actions,
223
+ cart.isHydrated,
224
+ cart.lines.length,
225
+ cart.state.status,
226
+ quoteKey
227
+ ]);
228
+ const timing = checkoutTiming(branch, menu, cart.lines, scheduledFor);
229
+ const quote = "quote" in cart.state ? cart.state.quote : void 0;
230
+ const heldQuote = isHeldQuote(quote);
231
+ const issues = useMemo(
232
+ () => timing.ahead ? cart.issues : cart.issues.map(
233
+ (issue2) => holdsForLater(issue2) ? {
234
+ ...issue2,
235
+ fixes: issue2.fixes.filter(
236
+ (entry) => entry.action !== "schedule"
237
+ )
238
+ } : issue2
239
+ ),
240
+ [cart.issues, timing.ahead]
241
+ );
242
+ const accountPhone = defaults?.phone.fromAccount ? defaults.phone.display : void 0;
243
+ const problems = contactProblems(
244
+ contactFields,
245
+ values,
246
+ phone,
247
+ accountPhone,
248
+ dialCode
249
+ );
250
+ const contactField = Object.keys(problems)[0];
251
+ const contactPhone = phone.trim() ? fullPhone(phone, dialCode) : "";
252
+ const status = checkoutStatus({
253
+ busy: leaving.pending,
254
+ hydrated: cart.isHydrated,
255
+ lines: cart.lines.length,
256
+ auth,
257
+ closed: timing.closed,
258
+ needsAddress: mode === "delivery" && !delivery?.address.line1,
259
+ needsTime: timing.needsTime,
260
+ state: cart.state,
261
+ quoteFailed: failedKey === quoteKey,
262
+ signInRequired,
263
+ contactField
264
+ });
265
+ const choose = (type) => {
266
+ setMode(type);
267
+ if (type === "delivery" && fulfilment?.type !== "delivery") {
268
+ setPendingAt(scheduledFor);
269
+ const known = rememberedAddress() ?? defaults?.address;
270
+ if (known) {
271
+ setDelivery({ address: known }, scheduledFor);
272
+ return void 0;
273
+ }
274
+ return { step: "address" };
275
+ }
276
+ return void 0;
277
+ };
278
+ const setAddress = (address, { remember = true } = {}) => {
279
+ const note = delivery?.address.instructions;
280
+ setDelivery({
281
+ address: note ? { ...address, instructions: note } : address
282
+ });
283
+ if (remember) {
284
+ rememberAddress(address);
285
+ }
286
+ };
287
+ const setRegion = (regionId) => {
288
+ if (!delivery) {
289
+ return { step: "address" };
290
+ }
291
+ setDelivery({ deliveryRegionId: regionId });
292
+ return void 0;
293
+ };
294
+ const setNote = (note) => {
295
+ if (!delivery) {
296
+ return { step: "address" };
297
+ }
298
+ const { instructions: _old, ...address } = delivery.address;
299
+ const value = note.trim();
300
+ setDelivery({
301
+ address: value ? { ...address, instructions: value } : address
302
+ });
303
+ return void 0;
304
+ };
305
+ const schedule = (at) => {
306
+ setPendingAt(at ?? void 0);
307
+ if (!fulfilment || fulfilment.type === "dine_in" || fulfilment.type !== mode) {
308
+ return;
309
+ }
310
+ const { scheduledFor: _old, ...rest } = fulfilment;
311
+ cart.actions.setFulfilment(at ? { ...rest, scheduledFor: at } : rest);
312
+ };
313
+ const fix = (issue2, action) => {
314
+ setError(void 0);
315
+ switch (action.action) {
316
+ case "change_address":
317
+ return { step: "address" };
318
+ case "choose_region":
319
+ return { step: "area" };
320
+ case "schedule":
321
+ return { step: "time" };
322
+ case "switch_fulfilment":
323
+ return choose(mode === "delivery" ? "pickup" : "delivery");
324
+ case "choose_option":
325
+ case "choose_other_option": {
326
+ const line = cart.lines.find((entry) => entry.id === issue2.lineId);
327
+ return line ? { step: "item", itemId: line.itemId, lineId: line.id } : void 0;
328
+ }
329
+ default:
330
+ cart.actions.applyFix(
331
+ cart.issues.find(
332
+ (entry) => entry.code === issue2.code && entry.lineId === issue2.lineId && entry.message === issue2.message
333
+ ) ?? issue2,
334
+ action
335
+ );
336
+ return void 0;
337
+ }
338
+ };
339
+ const signIn = options.signIn ?? signInOnce;
340
+ const leaveToSignIn = () => {
341
+ setLeavingFor("sign_in");
342
+ if (!signIn(reviewPath)) {
343
+ leaving.end();
344
+ setError("sign_in_failed");
345
+ }
346
+ };
347
+ const redirect = options.redirect ?? ((url) => redirectToCheckout(url, window.top ?? window));
348
+ const attribution = options.attribution ?? currentSource;
349
+ const openPayment = async () => {
350
+ setLeavingFor("payment");
351
+ try {
352
+ const prepared = attempt({
353
+ payload: cart.actions.toCheckoutPayload(),
354
+ branchId,
355
+ contactPhone,
356
+ returnUrl: `${location.origin}/checkout/return`,
357
+ cancelUrl: `${location.origin}${reviewPath}`,
358
+ attribution: attribution()
359
+ });
360
+ const session = await checkout.open(prepared.request, prepared.key);
361
+ redirect(session.url);
362
+ } catch (failure) {
363
+ if (failure instanceof CheckoutError && failure.apiCode === "customer_required") {
364
+ setSignInRequired(true);
365
+ leaveToSignIn();
366
+ return;
367
+ }
368
+ leaving.end();
369
+ setError("open_failed");
370
+ }
371
+ };
372
+ const retry = async () => {
373
+ setFailedKey(void 0);
374
+ try {
375
+ await cart.actions.quote({ force: true });
376
+ setError(void 0);
377
+ } catch (failure) {
378
+ if (!aborted(failure)) {
379
+ setFailedKey(quoteKey);
380
+ setError("quote_failed");
381
+ }
382
+ }
383
+ };
384
+ const issue = status === "fix_issues" ? firstIssue(cart.state) : void 0;
385
+ const activate = async () => {
386
+ setError(void 0);
387
+ switch (status) {
388
+ case "address":
389
+ return { step: "address" };
390
+ case "area":
391
+ return { step: "area" };
392
+ case "time":
393
+ return { step: "time" };
394
+ case "fix_issues": {
395
+ const target = issue ?? issues[0];
396
+ return target ? { step: "issue", issue: target } : void 0;
397
+ }
398
+ case "phone":
399
+ case "contact":
400
+ setShown((current) => /* @__PURE__ */ new Set([...current, ...Object.keys(problems)]));
401
+ return contactField ? { step: "contact", field: contactField } : void 0;
402
+ case "retry":
403
+ await retry();
404
+ return void 0;
405
+ case "sign_in":
406
+ countEvent("checkout");
407
+ await leaving.start(leaveToSignIn);
408
+ return void 0;
409
+ case "pay":
410
+ countEvent("checkout");
411
+ await leaving.start(openPayment);
412
+ return void 0;
413
+ default:
414
+ return void 0;
415
+ }
416
+ };
417
+ return {
418
+ mode,
419
+ offers,
420
+ choose,
421
+ delivery,
422
+ setAddress,
423
+ setRegion,
424
+ setNote,
425
+ scheduledFor,
426
+ schedule,
427
+ timing,
428
+ contact: {
429
+ phone,
430
+ contactPhone,
431
+ setPhone: (value) => {
432
+ setPhoneState(value);
433
+ writeSession(`${storageKey}.phone`, value);
434
+ },
435
+ accountPhone,
436
+ fields: contactFields,
437
+ values,
438
+ setField: (key, value) => {
439
+ setValues((current) => {
440
+ const next = { ...current, [key]: value };
441
+ writeSession(`${storageKey}.contact`, JSON.stringify(next));
442
+ return next;
443
+ });
444
+ },
445
+ problems,
446
+ shown,
447
+ show: (key) => setShown(
448
+ (current) => current.has(key) ? current : /* @__PURE__ */ new Set([...current, key])
449
+ )
450
+ },
451
+ auth,
452
+ quote,
453
+ pricing: cart.state.status === "quoting",
454
+ held: heldQuote ? timing.ahead ? "time" : "opening" : void 0,
455
+ issues,
456
+ fix,
457
+ error,
458
+ clearError: () => setError(void 0),
459
+ pay: {
460
+ status,
461
+ enabled: payEnabled(status),
462
+ leavingFor: status === "busy" ? leavingFor : void 0,
463
+ issue,
464
+ field: status === "phone" || status === "contact" ? contactField : void 0,
465
+ activate
466
+ }
467
+ };
468
+ }
469
+ export {
470
+ useCheckoutFlow
471
+ };
472
+ //# sourceMappingURL=use-checkout-flow.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/checkout/use-checkout-flow.ts"],
4
+ "mappings": ";;;AACA;AAAA,EACE;AAAA,EACA;AAAA,OAQK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,sBAA2C;AACpD,SAAS,4BAA4B;AACrC,SAAS,eAAe;AACxB,SAAS,0BAA0B;AACnC,SAAS,YAAY,qBAAqB;AAC1C,SAAS,aAAa,WAAW,SAAS,QAAQ,gBAAgB;AAClE,SAAS,6BAA6B;AACtC;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AACP,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,sBAA2C;AAwIpD,SAAS,YAAY,KAAa;AAChC,MAAI;AACF,WAAO,OAAO,eAAe,QAAQ,GAAG;AAAA,EAC1C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,aAAa,KAAa,OAAe;AAChD,MAAI;AACF,WAAO,eAAe,QAAQ,KAAK,KAAK;AAAA,EAC1C,QAAQ;AAAA,EAER;AACF;AAEA,IAAM,UAAU,CAAC,YACf,mBAAmB,SAAS,QAAQ,SAAS;AAE/C,IAAM,YAAqC,CAAC;AAerC,SAAS,gBAAgB,SAA4C;AAC1E,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,IAChB,aAAa;AAAA,IACb,WAAW;AAAA,IACX,aAAa;AAAA,EACf,IAAI;AACJ,QAAM,OAAO,QAAQ;AACrB,QAAM,WAAW;AAAA,IACf,MAAM,QAAQ,YAAY,eAAe;AAAA,IACzC,CAAC,QA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KAAK,MAAM,WAAW;AAAA,IAC/B,MAAM,YAAa,OAAO,QAAQ,SAAS,YAAa;AAAA,IACxD;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY,MAAM,SAAS,MAAS;AAAA,IACpC,KAAK;AAAA,MACH;AAAA,MACA,SAAS,WAAW,MAAM;AAAA,MAC1B,YAAY,WAAW,SAAS,aAAa;AAAA,MAC7C;AAAA,MACA,OACE,WAAW,WAAW,WAAW,YAAY,eAAe;AAAA,MAC9D;AAAA,IACF;AAAA,EACF;AACF;",
5
+ "names": ["issue"]
6
+ }
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var PACKAGE_VERSION = true ? "0.11.1" : "0.0.0-development";
2
+ var PACKAGE_VERSION = true ? "0.12.0" : "0.0.0-development";
3
3
  export {
4
4
  PACKAGE_VERSION
5
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zappie/foundations",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "description": "UI-less React primitives for Zappie storefronts: behaviour, state and accessibility without styles.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -21,6 +21,10 @@
21
21
  "types": "./dist/schedule/index.d.ts",
22
22
  "import": "./dist/schedule/index.js"
23
23
  },
24
+ "./checkout": {
25
+ "types": "./dist/checkout/index.d.ts",
26
+ "import": "./dist/checkout/index.js"
27
+ },
24
28
  "./rich-text": {
25
29
  "types": "./dist/rich-text/index.d.ts",
26
30
  "import": "./dist/rich-text/index.js"
@@ -45,7 +49,7 @@
45
49
  "peerDependencies": {
46
50
  "react": "^18.2.0 || ^19.0.0",
47
51
  "react-dom": "^18.2.0 || ^19.0.0",
48
- "@zappie/sdk": "^0.10.3"
52
+ "@zappie/sdk": "^0.10.6"
49
53
  },
50
54
  "repository": {
51
55
  "type": "git",
@@ -55,7 +59,7 @@
55
59
  "devDependencies": {
56
60
  "@types/google.maps": "^3.66.7",
57
61
  "esbuild": "^0.28.2",
58
- "@zappie/sdk": "0.10.5"
62
+ "@zappie/sdk": "0.10.6"
59
63
  },
60
64
  "license": "MIT",
61
65
  "homepage": "https://github.com/zappie/storefront-packages#readme",