@zappie/sdk 0.5.2 → 0.7.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +16 -16
  3. package/dist/account/index.d.ts +2 -191
  4. package/dist/account/index.js +1 -6
  5. package/dist/account/index.js.map +1 -1
  6. package/dist/checkout/error.js +2 -3
  7. package/dist/checkout/error.js.map +1 -1
  8. package/dist/{client-DHxakZrv.d.ts → client-DInn0X0F.d.ts} +1 -1
  9. package/dist/customer/error.js +2 -3
  10. package/dist/customer/error.js.map +1 -1
  11. package/dist/debug.js +1 -1
  12. package/dist/errors.js +3 -1
  13. package/dist/errors.js.map +1 -1
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.js +1 -1
  16. package/dist/internal/customer-http.js +11 -7
  17. package/dist/internal/customer-http.js.map +1 -1
  18. package/dist/internal.d.ts +1 -1
  19. package/dist/persist/catalogue.d.ts +1 -1
  20. package/dist/places/error.js +2 -3
  21. package/dist/places/error.js.map +1 -1
  22. package/dist/places/index.d.ts +5 -2
  23. package/dist/server/index.d.ts +16 -2
  24. package/dist/server/index.js +2 -0
  25. package/dist/server/index.js.map +1 -1
  26. package/dist/server/sign-in.js +18 -0
  27. package/dist/server/sign-in.js.map +6 -0
  28. package/dist/testing/index.d.ts +3 -120
  29. package/dist/testing/index.js +1 -4
  30. package/dist/transport/selected-menu.d.ts +1 -1
  31. package/package.json +1 -1
  32. package/dist/account/client.js +0 -86
  33. package/dist/account/client.js.map +0 -6
  34. package/dist/account/errors.js +0 -20
  35. package/dist/account/errors.js.map +0 -6
  36. package/dist/account/types.js +0 -1
  37. package/dist/account/types.js.map +0 -6
  38. package/dist/customer/sdk.js +0 -6
  39. package/dist/customer/sdk.js.map +0 -6
  40. package/dist/testing/account.js +0 -126
  41. package/dist/testing/account.js.map +0 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @zappie/sdk
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 97d7e6a: A shopper who reaches `/sign-in` from a link or `navigate()` now gets Zappie's sign-in page. Before, React Router followed the loader's `redirect("/_zappie/login?…")` inside the app, which has no route for it, so the site showed its not-found page.
8
+
9
+ `@zappie/sdk/server` adds `signInRedirect(returnTo, init?)`. Return it from your `/sign-in` loader: `return signInRedirect(request)`. It reads the request's `return` query parameter, keeps it only when it is a path on this site and falls back to `/`. The response is a 302 to `/_zappie/login?return=<path>` with the header React Router's `redirectDocument` sets, so a client-side navigation loads the page in full. You can pass a path in place of the request, and `init` for extra headers or another status.
10
+
11
+ `eslint-plugin-zappie` adds `platform-routes-full-load`, an error in the recommended config, so `zappie check` reports it. It reports a React Router `redirect` or `replace` to a `/_zappie/` path, `navigate()` or `<Navigate>` to one, and a `<Link>`, `<NavLink>` or `<Form>` that targets one without `reloadDocument`.
12
+
13
+ The starter's `/sign-in` route returns `signInRedirect(request)`, and its `app/safe-return.ts` is gone.
14
+
15
+ ## 0.6.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 9893d0c: Breaking: the site account client is removed. It was deprecated in the previous release because the shopper's Zappie account lives on the accounts portal and the API no longer serves its routes. Both packages take a minor bump because they are below 1.0.
20
+
21
+ `@zappie/sdk/account` no longer exports `createAccount`, `AccountClient`, `ScopeRequiredError`, `NotFoundError` or the account types. `@zappie/sdk/testing` no longer exports `mockAccountFetch`, `accountFixtures`, `MockAccountFixtures` or `MockAccountOptions`. The `@zappie/foundations/account` entry is removed with every part in it.
22
+
23
+ To link to the shopper's account, add `ZappieAccountLink` from `@zappie/foundations`, or build the address with `useZappieAccountUrl()`, `zappieAccountUrl(page)` or `accountsUrl()` from `@zappie/sdk/account`. These stay as they are.
24
+
25
+ - 546e44c: A 403 has its own error codes instead of `server_error`. When the shopper's sign-in doesn't include the scope a call needs, `CustomerError`, `CheckoutError` and `PlacesError` have the code `scope_required`, and so does a storefront read. Ask the shopper to sign in again. Any other 403, such as `mode_mismatch` or `origin_not_allowed`, has the code `forbidden`. The API's own code stays on `apiCode`, and neither code is retried.
26
+
27
+ Code that checked for `server_error` on a 403 now sees `scope_required` or `forbidden`.
28
+
29
+ ### Patch Changes
30
+
31
+ - 490c672: The SDK's storefront API contract fixture now matches the current API. The SDK already read every field the contract adds, so nothing changes at runtime. A menu has `layout` and `isActive`. A branch has `slug`, `promos`, `socialLinks`, `pickupAddress`, `orderAheadDays` and `isDefault`. Integrations have `googleMaps`, and a place's `route` has `duration_seconds`. A store from an API that doesn't send the new branch fields yet still loads without them. A `null` pickup address or Google Maps credential is left out. `Place.route` documents that it is absent when there is no road from the branch, and that `duration_seconds` is drive time without live traffic.
32
+
3
33
  ## 0.5.2
4
34
 
5
35
  ### Patch Changes
package/README.md CHANGED
@@ -50,22 +50,22 @@ Prices always come from Zappie. The cart shows a local estimate while it waits,
50
50
 
51
51
  ## Entry points
52
52
 
53
- | Import | For |
54
- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
55
- | `@zappie/sdk` | The client, the cart, money formatting and errors |
56
- | `@zappie/sdk/react` | `ZappieProvider` and hooks such as `useStore`, `useMenu` and `useCart` |
57
- | `@zappie/sdk/checkout` | Opening Zappie's hosted checkout and checking it completed |
58
- | `@zappie/sdk/checkout-defaults` | The phone, address, region and time a signed-in checkout starts from |
59
- | `@zappie/sdk/customer` and `/customer/react` | Signed-in customers, their orders and saved addresses |
60
- | `@zappie/sdk/account` | `accountsUrl`, a link to the shopper's Zappie account on the accounts portal. Its account calls are deprecated |
61
- | `@zappie/sdk/integrations` | Public integration IDs and browser keys |
62
- | `@zappie/sdk/places` | Address search and delivery-zone checks |
63
- | `@zappie/sdk/pricing` | An item's starting price and whether to show it as "From" |
64
- | `@zappie/sdk/server` | Server-side reads, storefront URLs, `verifyWebhook()`, menu snapshots and sign-in crypto |
65
- | `@zappie/sdk/template` and `/template/react` | Template settings and responsive images for template authors |
66
- | `@zappie/sdk/testing` | A mock client for your tests |
67
- | `@zappie/sdk/url` | Storefront URL parsing and canonical redirects |
68
- | `@zappie/sdk/redirect` | Same-origin validation for untrusted redirect targets |
53
+ | Import | For |
54
+ | -------------------------------------------- | ---------------------------------------------------------------------------------------- |
55
+ | `@zappie/sdk` | The client, the cart, money formatting and errors |
56
+ | `@zappie/sdk/react` | `ZappieProvider` and hooks such as `useStore`, `useMenu` and `useCart` |
57
+ | `@zappie/sdk/checkout` | Opening Zappie's hosted checkout and checking it completed |
58
+ | `@zappie/sdk/checkout-defaults` | The phone, address, region and time a signed-in checkout starts from |
59
+ | `@zappie/sdk/customer` and `/customer/react` | Signed-in customers, their orders and saved addresses |
60
+ | `@zappie/sdk/account` | `accountsUrl`, a link to the shopper's Zappie account on the accounts portal |
61
+ | `@zappie/sdk/integrations` | Public integration IDs and browser keys |
62
+ | `@zappie/sdk/places` | Address search and delivery-zone checks |
63
+ | `@zappie/sdk/pricing` | An item's starting price and whether to show it as "From" |
64
+ | `@zappie/sdk/server` | Server-side reads, storefront URLs, `verifyWebhook()`, menu snapshots and sign-in crypto |
65
+ | `@zappie/sdk/template` and `/template/react` | Template settings and responsive images for template authors |
66
+ | `@zappie/sdk/testing` | A mock client for your tests |
67
+ | `@zappie/sdk/url` | Storefront URL parsing and canonical redirects |
68
+ | `@zappie/sdk/redirect` | Same-origin validation for untrusted redirect targets |
69
69
 
70
70
  Customer sign-in runs through Zappie's site host, so `@zappie/sdk/customer` works on sites Zappie hosts. Sign-in for a site you host yourself isn't available yet.
71
71
 
@@ -1,192 +1,3 @@
1
- import { ZappieError } from '@zappie/sdk';
2
-
3
- /**
4
- * A customer API amount in minor currency units, paired with its currency code.
5
- */
6
- type Money = {
7
- amount_minor: number;
8
- currency: string;
9
- };
10
-
11
- /**
12
- * A scope the account calls need. A token without it gets `scope_required`.
13
- *
14
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
15
- */
16
- type AccountScope = "wallet" | "cards" | "payments:read";
17
- /**
18
- * One balance in the shopper's Zappie wallet, which is the same at every business.
19
- *
20
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
21
- */
22
- type Wallet = {
23
- currency: string;
24
- balance: Money;
25
- };
26
- /**
27
- * A card the shopper saved when they paid. It never carries the full card number.
28
- *
29
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
30
- */
31
- type SavedCard = {
32
- id: string;
33
- /** The card scheme in lower case, such as `mastercard`. */
34
- brand: string;
35
- last4: string;
36
- exp_month: number;
37
- exp_year: number;
38
- };
39
- /**
40
- * A payment the shopper made at this business.
41
- *
42
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
43
- */
44
- type CustomerPayment = {
45
- id: string;
46
- status: "successful" | "failed" | "refunded";
47
- /** What the payment was for. */
48
- amount: Money;
49
- /** What the shopper paid, fees included. */
50
- paid: Money;
51
- reference: string;
52
- branch_id: string;
53
- /** The order the payment paid for, or null when it wasn't a delivery or pickup order. */
54
- order_id: string | null;
55
- created_at: string;
56
- paid_at: string | null;
57
- };
58
- /**
59
- * A page of payments and the cursor for the next page, or null at the end.
60
- *
61
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
62
- */
63
- type PaymentsPage = {
64
- payments: CustomerPayment[];
65
- next_cursor: string | null;
66
- };
67
- /**
68
- * How the shopper paid. A card shows its brand and last four digits, a bank transfer its bank and account name.
69
- *
70
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
71
- */
72
- type PaymentMethodDetails = {
73
- type: "card" | "card_terminal" | "bank_transfer" | "wallet" | "apple_pay" | "google_pay" | "store_credit" | "loyalty_points" | "mobile_money" | "other";
74
- card_brand?: string;
75
- card_last4?: string;
76
- bank_name?: string;
77
- account_name?: string;
78
- };
79
- /**
80
- * A payment with what its receipt shows: the branch's name and how the shopper paid.
81
- *
82
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
83
- */
84
- type PaymentReceipt = CustomerPayment & {
85
- branch_name: string;
86
- method: PaymentMethodDetails;
87
- };
88
- /**
89
- * Where the account calls go and how. They share the customer client's defaults, so a site that
90
- * changed `customerBase` or `fetch` for createCustomer passes the same values here.
91
- *
92
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
93
- */
94
- type AccountClientOptions = {
95
- customerBase?: string;
96
- fetch?: typeof fetch;
97
- /** The site's customer client. A call the session no longer allows re-checks it, so the site sees the shopper signed out. */
98
- customer?: {
99
- session(): Promise<unknown>;
100
- };
101
- };
102
-
103
- /**
104
- * Create a client for the shopper's wallet, saved cards and payments at this business, through the
105
- * same endpoint and session as createCustomer. Load it only on account pages.
106
- * A call the shopper's sign-in doesn't allow rejects with ScopeRequiredError. A card or payment that
107
- * isn't theirs rejects with NotFoundError. Any other failure is a CustomerError.
108
- *
109
- * @param options - Endpoint and fetch overrides, and the site's customer client.
110
- * @returns The account calls.
111
- *
112
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
113
- */
114
- declare function createAccount(options?: AccountClientOptions): {
115
- /**
116
- * The shopper's Zappie wallet, one balance per currency, naira first. Needs the `wallet` scope.
117
- *
118
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
119
- */
120
- wallets(): Promise<Wallet[]>;
121
- /**
122
- * The cards the shopper saved when they paid. Needs the `cards` scope.
123
- *
124
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
125
- */
126
- cards(): Promise<SavedCard[]>;
127
- /**
128
- * Remove one of the shopper's saved cards. Needs the `cards` scope.
129
- *
130
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
131
- */
132
- removeCard: (id: string) => Promise<void>;
133
- /**
134
- * One page of the shopper's payments at this business, newest first. Needs the `payments:read` scope.
135
- *
136
- * @param page - Up to 50 payments a page, 20 by default, and the next_cursor of the previous page.
137
- *
138
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
139
- */
140
- payments(page?: {
141
- limit?: number;
142
- cursor?: string;
143
- }): Promise<PaymentsPage>;
144
- /**
145
- * One payment with what its receipt shows. Needs the `payments:read` scope.
146
- *
147
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
148
- */
149
- payment: (id: string) => Promise<PaymentReceipt>;
150
- };
151
- /**
152
- * The wallet, card and payment calls returned by createAccount.
153
- *
154
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
155
- */
156
- type AccountClient = ReturnType<typeof createAccount>;
157
-
158
- /**
159
- * A customer API failure with its HTTP status, API code and optional validation issues.
160
- * Statuses 429 and 5xx are marked retryable.
161
- */
162
- declare class CustomerError extends ZappieError {
163
- readonly apiCode: string;
164
- readonly issues?: unknown;
165
- constructor(status: number, apiCode: string, message: string, param?: string, issues?: unknown);
166
- }
167
-
168
- /**
169
- * The shopper's sign-in doesn't include the scope this call needs, usually because they signed in
170
- * before the site asked for it. Offer to sign in again. It doesn't sign the shopper out.
171
- *
172
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
173
- */
174
- declare class ScopeRequiredError extends CustomerError {
175
- /** The scope the call needs. */
176
- readonly scope: AccountScope;
177
- constructor(
178
- /** The scope the call needs. */
179
- scope: AccountScope, message: string);
180
- }
181
- /**
182
- * The card or payment isn't the shopper's, or isn't at this business.
183
- *
184
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
185
- */
186
- declare class NotFoundError extends CustomerError {
187
- constructor(message: string);
188
- }
189
-
190
1
  /** The Zappie environment a service URL points at. */
191
2
  type ZappieEnvironment = "production" | "staging";
192
3
 
@@ -206,5 +17,5 @@ declare function accountsUrl(path: AccountsPage, environment?: ZappieEnvironment
206
17
  returnTo?: string | URL;
207
18
  }): string;
208
19
 
209
- export { NotFoundError, ScopeRequiredError, accountsUrl, createAccount };
210
- export type { AccountClient, AccountClientOptions, AccountScope, AccountsPage, CustomerPayment, PaymentMethodDetails, PaymentReceipt, PaymentsPage, SavedCard, Wallet };
20
+ export { accountsUrl };
21
+ export type { AccountsPage };
@@ -1,11 +1,6 @@
1
1
  // src/account/index.ts
2
- import { createAccount } from "./client.js";
3
- import { NotFoundError, ScopeRequiredError } from "./errors.js";
4
2
  import { accountsUrl } from "./url.js";
5
3
  export {
6
- NotFoundError,
7
- ScopeRequiredError,
8
- accountsUrl,
9
- createAccount
4
+ accountsUrl
10
5
  };
11
6
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/account/index.ts"],
4
- "mappings": ";AAAA,SAAS,qBAAqB;AAE9B,SAAS,eAAe,0BAA0B;AAElD,SAAS,mBAAmB;",
4
+ "mappings": ";AAAA,SAAS,mBAAmB;",
5
5
  "names": []
6
6
  }
@@ -1,9 +1,8 @@
1
1
  // src/checkout/error.ts
2
- import { stableErrorCode } from "../internal/customer-http.js";
3
- import { ZappieError } from "./sdk.js";
2
+ import { stableErrorCode, ZappieError } from "../internal/customer-http.js";
4
3
  var CheckoutError = class extends ZappieError {
5
4
  constructor(status, apiCode, message, param, issues) {
6
- super(stableErrorCode(status), message, {
5
+ super(stableErrorCode(status, apiCode), message, {
7
6
  status,
8
7
  // 409 means the same idempotency key is still being processed; retrying with it is safe.
9
8
  retryable: status === 409 || status === 429 || status >= 500,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/checkout/error.ts"],
4
- "mappings": ";AAAA,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAMrB,IAAM,gBAAN,cAA4B,YAAY;AAAA,EAG7C,YACE,QACS,SACT,SACA,OACA,QACA;AACA,UAAM,gBAAgB,MAAM,GAAG,SAAS;AAAA,MACtC;AAAA;AAAA,MAEA,WAAW,WAAW,OAAO,WAAW,OAAO,UAAU;AAAA,MACzD,GAAI,UAAU,SAAY,EAAE,MAAM,IAAI,CAAC;AAAA,IACzC,CAAC;AAVQ;AAWT,QAAI,WAAW,QAAW;AACxB,WAAK,SAAS;AAAA,IAChB;AAAA,EACF;AACF;",
4
+ "mappings": ";AAAA,SAAS,iBAAiB,mBAAmB;AAMtC,IAAM,gBAAN,cAA4B,YAAY;AAAA,EAG7C,YACE,QACS,SACT,SACA,OACA,QACA;AACA,UAAM,gBAAgB,QAAQ,OAAO,GAAG,SAAS;AAAA,MAC/C;AAAA;AAAA,MAEA,WAAW,WAAW,OAAO,WAAW,OAAO,UAAU;AAAA,MACzD,GAAI,UAAU,SAAY,EAAE,MAAM,IAAI,CAAC;AAAA,IACzC,CAAC;AAVQ;AAWT,QAAI,WAAW,QAAW;AACxB,WAAK,SAAS;AAAA,IAChB;AAAA,EACF;AACF;",
5
5
  "names": []
6
6
  }
@@ -2,7 +2,7 @@ import { a as Menu, C as CategoryPage, S as Store, I as Item, M as Money, F as F
2
2
  import { Q as QuoteRequest, g as WireQuote, i as CartIssueCode, d as CartModule, b as CartLineInput } from './types-CxY5C6AN.js';
3
3
 
4
4
  /** Stable public error codes. */
5
- type ZappieErrorCode = "network_error" | "timeout" | "rate_limited" | "unauthorized" | "forbidden_origin" | "not_found" | "store_not_found" | "branch_not_found" | "item_not_found" | "cart_invalid" | "invalid_request" | "version_unsupported" | "server_error";
5
+ type ZappieErrorCode = "network_error" | "timeout" | "rate_limited" | "unauthorized" | "forbidden" | "forbidden_origin" | "scope_required" | "not_found" | "store_not_found" | "branch_not_found" | "item_not_found" | "cart_invalid" | "invalid_request" | "version_unsupported" | "server_error";
6
6
  /** Context attached to an SDK failure. */
7
7
  type ErrorDetails = {
8
8
  status?: number;
@@ -1,9 +1,8 @@
1
1
  // src/customer/error.ts
2
- import { stableErrorCode } from "../internal/customer-http.js";
3
- import { ZappieError } from "./sdk.js";
2
+ import { stableErrorCode, ZappieError } from "../internal/customer-http.js";
4
3
  var CustomerError = class extends ZappieError {
5
4
  constructor(status, apiCode, message, param, issues) {
6
- super(stableErrorCode(status), message, {
5
+ super(stableErrorCode(status, apiCode), message, {
7
6
  status,
8
7
  retryable: status === 429 || status >= 500,
9
8
  ...param !== void 0 ? { param } : {}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/customer/error.ts"],
4
- "mappings": ";AAAA,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAMrB,IAAM,gBAAN,cAA4B,YAAY;AAAA,EAG7C,YACE,QACS,SACT,SACA,OACA,QACA;AACA,UAAM,gBAAgB,MAAM,GAAG,SAAS;AAAA,MACtC;AAAA,MACA,WAAW,WAAW,OAAO,UAAU;AAAA,MACvC,GAAI,UAAU,SAAY,EAAE,MAAM,IAAI,CAAC;AAAA,IACzC,CAAC;AATQ;AAUT,QAAI,WAAW,QAAW;AACxB,WAAK,SAAS;AAAA,IAChB;AAAA,EACF;AACF;",
4
+ "mappings": ";AAAA,SAAS,iBAAiB,mBAAmB;AAMtC,IAAM,gBAAN,cAA4B,YAAY;AAAA,EAG7C,YACE,QACS,SACT,SACA,OACA,QACA;AACA,UAAM,gBAAgB,QAAQ,OAAO,GAAG,SAAS;AAAA,MAC/C;AAAA,MACA,WAAW,WAAW,OAAO,UAAU;AAAA,MACvC,GAAI,UAAU,SAAY,EAAE,MAAM,IAAI,CAAC;AAAA,IACzC,CAAC;AATQ;AAUT,QAAI,WAAW,QAAW;AACxB,WAAK,SAAS;AAAA,IAChB;AAAA,EACF;AACF;",
5
5
  "names": []
6
6
  }
package/dist/debug.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/debug.ts
2
- var VERSION = true ? "0.5.2" : "0.0.0-development";
2
+ var VERSION = true ? "0.7.0" : "0.0.0-development";
3
3
  function installDebug(client) {
4
4
  if (typeof window === "undefined" || client.mode !== "test") {
5
5
  return;
package/dist/errors.js CHANGED
@@ -4,7 +4,9 @@ var codes = [
4
4
  "timeout",
5
5
  "rate_limited",
6
6
  "unauthorized",
7
+ "forbidden",
7
8
  "forbidden_origin",
9
+ "scope_required",
8
10
  "not_found",
9
11
  "store_not_found",
10
12
  "branch_not_found",
@@ -47,7 +49,7 @@ function wireError(value, status, requestId) {
47
49
  const e = envelope.error && typeof envelope.error === "object" ? envelope.error : {};
48
50
  const fallback = status === 401 ? "unauthorized" : status === 403 ? "forbidden_origin" : status === 404 ? "not_found" : status === 429 ? "rate_limited" : status >= 500 ? "server_error" : "invalid_request";
49
51
  const known = typeof e.code === "string" && codes.includes(e.code);
50
- const code = known ? e.code : e.code ? "server_error" : fallback;
52
+ const code = known ? e.code : e.code ? status === 403 ? "forbidden" : "server_error" : fallback;
51
53
  const message = typeof e.message === "string" ? e.message : "The storefront request failed";
52
54
  return new ZappieError(
53
55
  code,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/errors.ts"],
4
- "mappings": ";AAeA,IAAM,QA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IACtB,QACA,IAAI,YAAY,iBAAiB,iCAAiC;AAAA,IAChE,OAAO;AAAA,EACT,CAAC;AACP;AACO,SAAS,UACd,OACA,QACA,WACa;AACb,QAAM,WACJ,SAAS,OAAO,UAAU,WACrB,QACD,CAAC;AACP,QAAM,IACJ,SAAS,SAAS,OAAO,SAAS,UAAU,WACvC,SAAS,QACV,CAAC;AACP,QAAM,WACJ,WAAW,MACP,iBACA,WAAW,MACT,qBACA,WAAW,MACT,cACA,WAAW,MACT,iBACA,UAAU,MACR,iBACA;AACd,QAAM,QAAQ,OAAO,EAAE,SAAS,YAAY,MAAM,SAAS,EAAE,IAAI;AACjE,QAAM,OAAO,QACR,EAAE,OACH,EAAE,OACA,WAAW,MACT,cACA,iBACF;AACN,QAAM,UACJ,OAAO,EAAE,YAAY,WAAW,EAAE,UAAU;AAC9C,SAAO,IAAI;AAAA,IACT;AAAA,IACA,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,EAAE,IAAI,CAAC,KAAK,OAAO,KAAK;AAAA,IACrD;AAAA,MACE;AAAA,MACA,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC;AAAA,MACjC,GAAI,OAAO,EAAE,UAAU,WAAW,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAAA,MACxD,GAAI,OAAO,EAAE,YAAY,WAAW,EAAE,QAAQ,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC/D;AAAA,EACF;AACF;",
5
5
  "names": []
6
6
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { a as ZappieError, T as Transport, R as RequestCtx, f as MenuFulfilment, g as MenuResponse, j as SearchRequest, k as SearchPage, l as MenuVersion } from './client-DHxakZrv.js';
1
+ import { a as ZappieError, T as Transport, R as RequestCtx, f as MenuFulfilment, g as MenuResponse, j as SearchRequest, k as SearchPage, l as MenuVersion } from './client-DInn0X0F.js';
2
2
  import { SelectedMenuRequest, SelectedMenuResponse } from './transport/selected-menu.js';
3
- export { A as API_VERSION, E as ErrorDetails, m as MenuReadOptions, M as MenuResource, n as ReadOptions, S as StorageLike, c as StoreResource, Z as Zappie, b as ZappieClientOptions, b as ZappieConfig, e as ZappieErrorCode, d as ZappieEvents, o as createZappie, p as isZappieError } from './client-DHxakZrv.js';
3
+ export { A as API_VERSION, E as ErrorDetails, m as MenuReadOptions, M as MenuResource, n as ReadOptions, S as StorageLike, c as StoreResource, Z as Zappie, b as ZappieClientOptions, b as ZappieConfig, e as ZappieErrorCode, d as ZappieEvents, o as createZappie, p as isZappieError } from './client-DInn0X0F.js';
4
4
  import { f as CartIssue, b as CartLineInput, C as CartLine, Q as QuoteRequest, g as WireQuote } from './types-CxY5C6AN.js';
5
5
  export { h as CartFix, c as CartFulfilment, i as CartIssueCode, d as CartModule, j as CartSnapshot, e as CartState, k as CartSyncAdapter, l as CartSyncDocument, D as DeliveryAddress, a as Quote, m as WireFix, W as WireFulfilment, n as WireIssue, o as WireLine, p as WireMoney } from './types-CxY5C6AN.js';
6
6
  import { I as Item, O as OptionGroup, M as Money, a as Menu, B as Branch, S as Store, C as CategoryPage } from './models-C-kEg1Id.js';
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { ZappieError, isZappieError } from "./errors.js";
10
10
  export * from "./models.js";
11
11
  import { format, money } from "./money.js";
12
12
  import { RestTransport } from "./transport/rest.js";
13
- var VERSION = true ? "0.5.2" : "0.0.0-development";
13
+ var VERSION = true ? "0.7.0" : "0.0.0-development";
14
14
  export {
15
15
  API_VERSION,
16
16
  RestTransport,
@@ -1,12 +1,15 @@
1
1
  // src/internal/customer-http.ts
2
2
  import { ZappieError } from "@zappie/sdk";
3
- function stableErrorCode(status) {
3
+ function stableErrorCode(status, apiCode) {
4
4
  if (status === 400 || status === 422) {
5
5
  return "invalid_request";
6
6
  }
7
7
  if (status === 401) {
8
8
  return "unauthorized";
9
9
  }
10
+ if (status === 403) {
11
+ return apiCode === "scope_required" ? apiCode : "forbidden";
12
+ }
10
13
  if (status === 404) {
11
14
  return "not_found";
12
15
  }
@@ -16,13 +19,13 @@ function stableErrorCode(status) {
16
19
  return "server_error";
17
20
  }
18
21
  async function apiError(response, fallback) {
19
- const body = await response.json().catch(() => ({}));
20
- const envelope = body && typeof body === "object" ? body : {};
21
- const value = "error" in envelope && envelope.error && typeof envelope.error === "object" ? envelope.error : {};
22
+ const body = await response.json().catch(() => void 0);
23
+ const error = body?.error;
24
+ const value = error && typeof error === "object" ? error : {};
22
25
  return {
23
- apiCode: "code" in value && typeof value.code === "string" ? value.code : "server_error",
24
- message: "message" in value && typeof value.message === "string" ? value.message : fallback,
25
- ..."param" in value && typeof value.param === "string" ? { param: value.param } : {},
26
+ apiCode: typeof value.code === "string" ? value.code : "server_error",
27
+ message: typeof value.message === "string" ? value.message : fallback,
28
+ ...typeof value.param === "string" ? { param: value.param } : {},
26
29
  ..."issues" in value ? { issues: value.issues } : {}
27
30
  };
28
31
  }
@@ -66,6 +69,7 @@ async function requestWithRetry(fetcher, input, init, message) {
66
69
  throw new ZappieError("network_error", message, { retryable: true });
67
70
  }
68
71
  export {
72
+ ZappieError,
69
73
  apiError,
70
74
  requestWithRetry,
71
75
  stableErrorCode,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/internal/customer-http.ts"],
4
- "mappings": ";AAEA,SAAS,mBAAmB;AASrB,SAAS,gBAAgB,QAAgB;AAC9C,MAAI,WAAW,OAAO,WAAW,KAAK;AACpC,WAAO;AAAA,EACT;AACA,MAAI,WAAW,KAAK;AAClB,WAAO;AAAA,EACT;AACA,MAAI,WAAW,KAAK;AAClB,WAAO;AAAA,EACT;AACA,MAAI,WAAW,KAAK;AAClB,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,eAAsB,SACpB,UACA,UAC0B;AAC1B,QAAM,OAAO,MAAM,SAAS,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AACnD,QAAM,WAAW,QAAQ,OAAO,SAAS,WAAW,OAAO,CAAC;AAC5D,QA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BAAa,KAAK;AAClB,cAAQ,oBAAoB,SAAS,OAAO;AAC5C,aAAO,QAAQ,UAAU,IAAI,aAAa,WAAW,YAAY,CAAC;AAAA,IACpE;AACA,YAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;AAAA,EAC3D,CAAC;AACH;AAEA,eAAsB,iBACpB,SACA,OACA,MACA,SACmB;AACnB,WAAS,UAAU,GAAG,UAAU,GAAG,WAAW;AAC5C,QAAI;AACF,aAAO,MAAM,QAAQ,OAAO;AAAA,QAC1B,GAAG;AAAA,QACH,aAAa;AAAA,QACb,SAAS,EAAE,QAAQ,oBAAoB,GAAG,KAAK,QAAQ;AAAA,MACzD,CAAC;AAAA,IACH,SAAS,OAAO;AACd,UAAI,KAAK,QAAQ,SAAS;AACxB,cAAM,KAAK,OAAO,UAAU;AAAA,MAC9B;AACA,UAAI,YAAY,GAAG;AACjB,cAAM,IAAI,YAAY,iBAAiB,SAAS;AAAA,UAC9C;AAAA,UACA,WAAW;AAAA,QACb,CAAC;AAAA,MACH;AACA,YAAM,KAAK,KAAK,KAAK,UAAU,MAAS;AAAA,IAC1C;AAAA,EACF;AACA,QAAM,IAAI,YAAY,iBAAiB,SAAS,EAAE,WAAW,KAAK,CAAC;AACrE;",
5
5
  "names": []
6
6
  }
@@ -1,5 +1,5 @@
1
1
  import { CartFulfilment, WireFulfilment } from './index.js';
2
- export { v as validateConfig } from './client-DHxakZrv.js';
2
+ export { v as validateConfig } from './client-DInn0X0F.js';
3
3
  import './models-C-kEg1Id.js';
4
4
 
5
5
  /**
@@ -1,3 +1,3 @@
1
- export { q as CATALOGUE_MAX_AGE_MS, r as CATALOGUE_MAX_BYTES, s as CatalogueScope, t as SavedCatalogue, u as catalogueDigest, w as catalogueKey, x as createCatalogueStorage, y as createSavedCatalogue } from '../client-DHxakZrv.js';
1
+ export { q as CATALOGUE_MAX_AGE_MS, r as CATALOGUE_MAX_BYTES, s as CatalogueScope, t as SavedCatalogue, u as catalogueDigest, w as catalogueKey, x as createCatalogueStorage, y as createSavedCatalogue } from '../client-DInn0X0F.js';
2
2
  import '../models-C-kEg1Id.js';
3
3
  import '../types-CxY5C6AN.js';
@@ -1,9 +1,8 @@
1
1
  // src/places/error.ts
2
- import { stableErrorCode } from "../internal/customer-http.js";
3
- import { ZappieError } from "./sdk.js";
2
+ import { stableErrorCode, ZappieError } from "../internal/customer-http.js";
4
3
  var PlacesError = class extends ZappieError {
5
4
  constructor(status, apiCode, message, param, issues) {
6
- super(stableErrorCode(status), message, {
5
+ super(stableErrorCode(status, apiCode), message, {
7
6
  status,
8
7
  retryable: status === 429 || status >= 500,
9
8
  ...param !== void 0 ? { param } : {}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/places/error.ts"],
4
- "mappings": ";AAAA,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAMrB,IAAM,cAAN,cAA0B,YAAY;AAAA,EAG3C,YACE,QACS,SACT,SACA,OACA,QACA;AACA,UAAM,gBAAgB,MAAM,GAAG,SAAS;AAAA,MACtC;AAAA,MACA,WAAW,WAAW,OAAO,UAAU;AAAA,MACvC,GAAI,UAAU,SAAY,EAAE,MAAM,IAAI,CAAC;AAAA,IACzC,CAAC;AATQ;AAUT,QAAI,WAAW,QAAW;AACxB,WAAK,SAAS;AAAA,IAChB;AAAA,EACF;AACF;",
4
+ "mappings": ";AAAA,SAAS,iBAAiB,mBAAmB;AAMtC,IAAM,cAAN,cAA0B,YAAY;AAAA,EAG3C,YACE,QACS,SACT,SACA,OACA,QACA;AACA,UAAM,gBAAgB,QAAQ,OAAO,GAAG,SAAS;AAAA,MAC/C;AAAA,MACA,WAAW,WAAW,OAAO,UAAU;AAAA,MACvC,GAAI,UAAU,SAAY,EAAE,MAAM,IAAI,CAAC;AAAA,IACzC,CAAC;AATQ;AAUT,QAAI,WAAW,QAAW;AACxB,WAAK,SAAS;AAAA,IAChB;AAAA,EACF;AACF;",
5
5
  "names": []
6
6
  }
@@ -18,11 +18,14 @@ type Place = {
18
18
  country?: string;
19
19
  lat: number;
20
20
  lng: number;
21
- /** The route from the branch. Each field is absent when the API doesn't send it. */
21
+ /**
22
+ * The drive from the branch, measured by road. Absent when there is no road between them. Each
23
+ * field is absent when the API doesn't send it.
24
+ */
22
25
  route?: {
23
26
  /** Road distance in metres. */
24
27
  distance_meters?: number;
25
- /** Travel time in seconds. */
28
+ /** Drive time in seconds, without live traffic. */
26
29
  duration_seconds?: number;
27
30
  };
28
31
  };
@@ -1,5 +1,5 @@
1
1
  import { Menu, Store, Formatters } from '../index.js';
2
- import { C as Cache } from '../client-DHxakZrv.js';
2
+ import { C as Cache } from '../client-DInn0X0F.js';
3
3
  import { ZappieError, ZappieConfig, Transport, StorageLike, StoreResource, MenuResource, ZappieEvents } from '../index.js';
4
4
  export { VERSION } from '../index.js';
5
5
  import { CartModule, CartLineInput } from '../index.js';
@@ -588,6 +588,20 @@ declare function inlineScriptHashes(html: string): Promise<string[]>;
588
588
  /** Build the report-only security headers for a storefront document response. */
589
589
  declare function securityHeaders(options?: SecurityHeadersOptions): Headers;
590
590
 
591
+ /**
592
+ * Send the shopper to Zappie's sign-in page from a route loader or action.
593
+ *
594
+ * The response tells React Router to load the page in full, the way `redirectDocument` does.
595
+ * Zappie hosting serves `/_zappie/login`, so a plain `redirect` followed inside the app would
596
+ * render your not-found page. Other frameworks read it as an ordinary 302.
597
+ *
598
+ * @param returnTo - The request, whose `return` query parameter is read, or the path to come back
599
+ * to. A path that leaves the site, or a missing one, returns the shopper to `/`.
600
+ * @param init - Extra response settings, such as a `Set-Cookie` header. The status defaults to 302.
601
+ * @returns A redirect to `/_zappie/login?return=<path>`.
602
+ */
603
+ declare function signInRedirect(returnTo: Request | URL | string | null | undefined, init?: ResponseInit): Response;
604
+
591
605
  /** Event names sent by the Zappie webhook API. */
592
606
  type WebhookEventType = "menu.updated" | "branch.hours_changed" | "store.updated" | "checkout.session.completed" | "checkout.session.expired" | "order.created" | "order.paid" | "order.status_changed" | "customer.signed_in" | "payout.initiated" | "payout.paid" | "payout.failed" | "payout_request.created" | "payout_request.approved" | "payout_request.rejected" | "payment.received";
593
607
  /** The event envelope sent in a Zappie webhook request. */
@@ -663,5 +677,5 @@ declare function createZappieServer({ secretKey, ...config }: ZappieServerConfig
663
677
  };
664
678
  }>;
665
679
 
666
- export { STOREFRONT_QUERY_PARAMETERS, STOREFRONT_V1_QUERY_PARAMETERS, ZappieTokenError, ZappieWebhookSignatureError, applyAvailability, buildStorefrontUrl, canonicalJson, cookieSessionStore, createAvailabilityPatch, createMenuSnapshot, createPkce, createSecurityNonce, createStoreSnapshot, createTokenVerifier, createZappieServer, inlineScriptHashes, isMenuSnapshot, menuSnapshotFromPayload, openSealedValue, parseStorefrontUrl, randomToken, sealValue, securityHeaders, snapshotHash, snapshotKeys, storefrontRedirect, verifyWebhook };
680
+ export { STOREFRONT_QUERY_PARAMETERS, STOREFRONT_V1_QUERY_PARAMETERS, ZappieTokenError, ZappieWebhookSignatureError, applyAvailability, buildStorefrontUrl, canonicalJson, cookieSessionStore, createAvailabilityPatch, createMenuSnapshot, createPkce, createSecurityNonce, createStoreSnapshot, createTokenVerifier, createZappieServer, inlineScriptHashes, isMenuSnapshot, menuSnapshotFromPayload, openSealedValue, parseStorefrontUrl, randomToken, sealValue, securityHeaders, signInRedirect, snapshotHash, snapshotKeys, storefrontRedirect, verifyWebhook };
667
681
  export type { AvailabilityPatch, AvailabilityPatchInput, CookieSessionStoreOptions, EdgeSnapshotReader, IdTokenChecks, IdTokenClaims, MenuSnapshot, MenuSnapshotInput, MenuSnapshotPayloadInput, PkcePair, SealOptions, SealSecret, SecurityHeadersOptions, SessionData, SessionStore, SnapshotVersionRecord, StoreSnapshot, StorefrontInstallation, StorefrontPageState, StorefrontQuery, StorefrontRoute, StorefrontUrlInput, StorefrontUrlOptions, TokenAlgorithm, TokenClaims, TokenErrorReason, TokenVerifier, TokenVerifierOptions, VerifyTokenChecks, VerifyWebhookOptions, WebhookEvent, WebhookEventType, ZappieServerConfig };
@@ -37,6 +37,7 @@ import {
37
37
  inlineScriptHashes,
38
38
  securityHeaders
39
39
  } from "./security.js";
40
+ import { signInRedirect } from "./sign-in.js";
40
41
  import {
41
42
  verifyWebhook,
42
43
  ZappieWebhookSignatureError
@@ -72,6 +73,7 @@ export {
72
73
  randomToken,
73
74
  sealValue,
74
75
  securityHeaders,
76
+ signInRedirect,
75
77
  snapshotHash,
76
78
  snapshotKeys,
77
79
  storefrontRedirect,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/server/index.ts"],
4
- "mappings": ";AAAA,SAAS,mBAAmB;AAG5B,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAOK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OASK;AACP;AAAA,EACE;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAQK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAUA,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA,GAAG;AACL,GAAuB;AACrB,SAAO,YAAY,EAAE,GAAG,QAAQ,KAAK,UAAU,GAAG,IAAI;AACxD;",
4
+ "mappings": ";AAAA,SAAS,mBAAmB;AAG5B,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAOK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OASK;AACP;AAAA,EACE;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAQK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAUA,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA,GAAG;AACL,GAAuB;AACrB,SAAO,YAAY,EAAE,GAAG,QAAQ,KAAK,UAAU,GAAG,IAAI;AACxD;",
5
5
  "names": []
6
6
  }
@@ -0,0 +1,18 @@
1
+ // src/server/sign-in.ts
2
+ import { sameOriginPath } from "../internal/return-path.js";
3
+ function signInRedirect(returnTo, init = {}) {
4
+ const path = typeof returnTo === "object" && returnTo !== null ? new URL(
5
+ returnTo instanceof URL ? returnTo : returnTo.url
6
+ ).searchParams.get("return") : returnTo;
7
+ const headers = new Headers(init.headers);
8
+ headers.set(
9
+ "Location",
10
+ `/_zappie/login?return=${encodeURIComponent(sameOriginPath(path) ?? "/")}`
11
+ );
12
+ headers.set("X-Remix-Reload-Document", "true");
13
+ return new Response(null, { ...init, status: init.status ?? 302, headers });
14
+ }
15
+ export {
16
+ signInRedirect
17
+ };
18
+ //# sourceMappingURL=sign-in.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/server/sign-in.ts"],
4
+ "mappings": ";AAAA,SAAS,sBAAsB;AAcxB,SAAS,eACd,UACA,OAAqB,CAAC,GACZ;AACV,QAAM,OACJ,OAAO,aAAa,YAAY,aAAa,OACzC,IAAI;AAAA,IACF,oBAAoB,MAAM,WAAW,SAAS;AAAA,EAChD,EAAE,aAAa,IAAI,QAAQ,IAC3B;AACN,QAAM,UAAU,IAAI,QAAQ,KAAK,OAAO;AACxC,UAAQ;AAAA,IACN;AAAA,IACA,yBAAyB,mBAAmB,eAAe,IAAI,KAAK,GAAG,CAAC;AAAA,EAC1E;AAEA,UAAQ,IAAI,2BAA2B,MAAM;AAC7C,SAAO,IAAI,SAAS,MAAM,EAAE,GAAG,MAAM,QAAQ,KAAK,UAAU,KAAK,QAAQ,CAAC;AAC5E;",
5
+ "names": []
6
+ }
@@ -1,126 +1,9 @@
1
- import { C as Cache } from '../client-DHxakZrv.js';
1
+ import { C as Cache } from '../client-DInn0X0F.js';
2
2
  import { Transport, ZappieErrorCode, StorageLike, StoreResource, MenuResource, ZappieEvents } from '../index.js';
3
3
  import { Store, Menu, Formatters } from '../index.js';
4
4
  export { VERSION } from '../index.js';
5
5
  import { CartModule, CartLineInput } from '../index.js';
6
6
 
7
- /**
8
- * A customer API amount in minor currency units, paired with its currency code.
9
- */
10
- type Money = {
11
- amount_minor: number;
12
- currency: string;
13
- };
14
-
15
- /**
16
- * A scope the account calls need. A token without it gets `scope_required`.
17
- *
18
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
19
- */
20
- type AccountScope = "wallet" | "cards" | "payments:read";
21
- /**
22
- * One balance in the shopper's Zappie wallet, which is the same at every business.
23
- *
24
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
25
- */
26
- type Wallet = {
27
- currency: string;
28
- balance: Money;
29
- };
30
- /**
31
- * A card the shopper saved when they paid. It never carries the full card number.
32
- *
33
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
34
- */
35
- type SavedCard = {
36
- id: string;
37
- /** The card scheme in lower case, such as `mastercard`. */
38
- brand: string;
39
- last4: string;
40
- exp_month: number;
41
- exp_year: number;
42
- };
43
- /**
44
- * A payment the shopper made at this business.
45
- *
46
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
47
- */
48
- type CustomerPayment = {
49
- id: string;
50
- status: "successful" | "failed" | "refunded";
51
- /** What the payment was for. */
52
- amount: Money;
53
- /** What the shopper paid, fees included. */
54
- paid: Money;
55
- reference: string;
56
- branch_id: string;
57
- /** The order the payment paid for, or null when it wasn't a delivery or pickup order. */
58
- order_id: string | null;
59
- created_at: string;
60
- paid_at: string | null;
61
- };
62
- /**
63
- * How the shopper paid. A card shows its brand and last four digits, a bank transfer its bank and account name.
64
- *
65
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
66
- */
67
- type PaymentMethodDetails = {
68
- type: "card" | "card_terminal" | "bank_transfer" | "wallet" | "apple_pay" | "google_pay" | "store_credit" | "loyalty_points" | "mobile_money" | "other";
69
- card_brand?: string;
70
- card_last4?: string;
71
- bank_name?: string;
72
- account_name?: string;
73
- };
74
- /**
75
- * A payment with what its receipt shows: the branch's name and how the shopper paid.
76
- *
77
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
78
- */
79
- type PaymentReceipt = CustomerPayment & {
80
- branch_name: string;
81
- method: PaymentMethodDetails;
82
- };
83
-
84
- /**
85
- * The wallets, saved cards and payment receipts the mock account endpoints answer with.
86
- *
87
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
88
- */
89
- type MockAccountFixtures = {
90
- wallets: Wallet[];
91
- cards: SavedCard[];
92
- /** Newest first, as the API lists them. */
93
- payments: PaymentReceipt[];
94
- };
95
- /**
96
- * The scopes the mock shopper granted. Leave it out to grant all three.
97
- *
98
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
99
- */
100
- type MockAccountOptions = {
101
- scopes?: AccountScope[];
102
- };
103
- /**
104
- * Sample account data with no real cards or people: two balances, two cards and three payments.
105
- *
106
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
107
- */
108
- declare const accountFixtures: MockAccountFixtures;
109
- /**
110
- * A fetch that answers the account endpoints `/me/wallets`, `/me/cards`, `/me/cards/{card_id}`,
111
- * `/me/payments` and `/me/payments/{payment_id}` as the API does, from fixtures and in memory.
112
- * Pass it as `fetch` to createAccount, or call it from a mock API server. A removed card stays
113
- * removed for this fetch. A scope left out of `scopes` answers 403 `scope_required`. Any other
114
- * path answers 404.
115
- *
116
- * @param fixtures - The account data. Defaults to accountFixtures.
117
- * @param options - The scopes the shopper granted.
118
- * @returns A fetch implementation for the account endpoints.
119
- *
120
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
121
- */
122
- declare function mockAccountFetch(fixtures?: MockAccountFixtures, options?: MockAccountOptions): typeof fetch;
123
-
124
7
  /** Store and branch menus supplied to the deterministic mock transport. */
125
8
  type MockFixtures = {
126
9
  store: Store;
@@ -181,5 +64,5 @@ declare const fixtures: {
181
64
  };
182
65
  };
183
66
 
184
- export { accountFixtures, createMockZappie, fixtures, mockAccountFetch };
185
- export type { MockAccountFixtures, MockAccountOptions, MockFixtures, MockOptions };
67
+ export { createMockZappie, fixtures };
68
+ export type { MockFixtures, MockOptions };
@@ -7,7 +7,6 @@ import { delay, throwIfAborted } from "../internal/abort.js";
7
7
  import { multiplyMoney } from "../internal/money-math.js";
8
8
  import { money } from "../money.js";
9
9
  import { VERSION } from "../index.js";
10
- import { accountFixtures, mockAccountFetch } from "./account.js";
11
10
  function createMockZappie(input, opts = {}) {
12
11
  const fixtures2 = structuredClone(input);
13
12
  const before = async (method, ctx) => {
@@ -453,8 +452,6 @@ var fixtures = {
453
452
  };
454
453
  export {
455
454
  VERSION,
456
- accountFixtures,
457
455
  createMockZappie,
458
- fixtures,
459
- mockAccountFetch
456
+ fixtures
460
457
  };
@@ -1,3 +1,3 @@
1
- export { z as SelectedMenu, h as SelectedMenuRequest, i as SelectedMenuResponse, B as SelectedMenuTransport, D as createSelectedMenuReader, F as selectedMenu, G as selectedMenuKey } from '../client-DHxakZrv.js';
1
+ export { z as SelectedMenu, h as SelectedMenuRequest, i as SelectedMenuResponse, B as SelectedMenuTransport, D as createSelectedMenuReader, F as selectedMenu, G as selectedMenuKey } from '../client-DInn0X0F.js';
2
2
  import '../models-C-kEg1Id.js';
3
3
  import '../types-CxY5C6AN.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zappie/sdk",
3
- "version": "0.5.2",
3
+ "version": "0.7.0",
4
4
  "description": "Typed, framework-agnostic client for Zappie menus, carts, checkout, auth and events.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -1,86 +0,0 @@
1
- // src/account/client.ts
2
- import { CustomerError } from "../customer/error.js";
3
- import { createCustomerRequest } from "../customer/request.js";
4
- import { NotFoundError, ScopeRequiredError } from "./errors.js";
5
- function createAccount(options = {}) {
6
- const base = (options.customerBase ?? "/_zappie/api").replace(/\/+$/, "");
7
- const request = createCustomerRequest(
8
- base,
9
- options.fetch ?? globalThis.fetch,
10
- () => {
11
- void options.customer?.session().catch(() => void 0);
12
- }
13
- );
14
- const call = async (scope, path, method = "GET") => {
15
- try {
16
- return await request(path, { method });
17
- } catch (error) {
18
- if (error instanceof CustomerError) {
19
- if (error.apiCode === "scope_required") {
20
- throw new ScopeRequiredError(scope, error.message);
21
- }
22
- if (error.status === 404) {
23
- throw new NotFoundError(error.message);
24
- }
25
- }
26
- throw error;
27
- }
28
- };
29
- return {
30
- /**
31
- * The shopper's Zappie wallet, one balance per currency, naira first. Needs the `wallet` scope.
32
- *
33
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
34
- */
35
- async wallets() {
36
- return (await call("wallet", "/me/wallets")).wallets;
37
- },
38
- /**
39
- * The cards the shopper saved when they paid. Needs the `cards` scope.
40
- *
41
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
42
- */
43
- async cards() {
44
- return (await call("cards", "/me/cards")).cards;
45
- },
46
- /**
47
- * Remove one of the shopper's saved cards. Needs the `cards` scope.
48
- *
49
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
50
- */
51
- removeCard: (id) => call("cards", `/me/cards/${encodeURIComponent(id)}`, "DELETE"),
52
- /**
53
- * One page of the shopper's payments at this business, newest first. Needs the `payments:read` scope.
54
- *
55
- * @param page - Up to 50 payments a page, 20 by default, and the next_cursor of the previous page.
56
- *
57
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
58
- */
59
- payments(page = {}) {
60
- const query = new URLSearchParams();
61
- if (page.limit !== void 0) {
62
- query.set("limit", String(page.limit));
63
- }
64
- if (page.cursor !== void 0) {
65
- query.set("cursor", page.cursor);
66
- }
67
- return call(
68
- "payments:read",
69
- `/me/payments${query.size > 0 ? `?${query}` : ""}`
70
- );
71
- },
72
- /**
73
- * One payment with what its receipt shows. Needs the `payments:read` scope.
74
- *
75
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
76
- */
77
- payment: (id) => call(
78
- "payments:read",
79
- `/me/payments/${encodeURIComponent(id)}`
80
- )
81
- };
82
- }
83
- export {
84
- createAccount
85
- };
86
- //# sourceMappingURL=client.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/account/client.ts"],
4
- "mappings": ";AAAA,SAAS,qBAAqB;AAC9B,SA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AW,QAAW;AAC7B,cAAM,IAAI,UAAU,KAAK,MAAM;AAAA,MACjC;AACA,aAAO;AAAA,QACL;AAAA,QACA,eAAe,MAAM,OAAO,IAAI,IAAI,KAAK,KAAK,EAAE;AAAA,MAClD;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,SAAS,CAAC,OACR;AAAA,MACE;AAAA,MACA,gBAAgB,mBAAmB,EAAE,CAAC;AAAA,IACxC;AAAA,EACJ;AACF;",
5
- "names": []
6
- }
@@ -1,20 +0,0 @@
1
- // src/account/errors.ts
2
- import { CustomerError } from "../customer/error.js";
3
- var ScopeRequiredError = class extends CustomerError {
4
- constructor(scope, message) {
5
- super(403, "scope_required", message);
6
- this.scope = scope;
7
- this.name = "ScopeRequiredError";
8
- }
9
- };
10
- var NotFoundError = class extends CustomerError {
11
- constructor(message) {
12
- super(404, "not_found", message);
13
- this.name = "NotFoundError";
14
- }
15
- };
16
- export {
17
- NotFoundError,
18
- ScopeRequiredError
19
- };
20
- //# sourceMappingURL=errors.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/account/errors.ts"],
4
- "mappings": ";AAAA,SAAS,qBAAqB;AASvB,IAAM,qBAAN,cAAiC,cAAc;AAAA,EACpD,YAEW,OACT,SACA;AACA,UAAM,KAAK,kBAAkB,OAAO;AAH3B;AAIT,SAAK,OAAO;AAAA,EACd;AACF;AAOO,IAAM,gBAAN,cAA4B,cAAc;AAAA,EAC/C,YAAY,SAAiB;AAC3B,UAAM,KAAK,aAAa,OAAO;AAC/B,SAAK,OAAO;AAAA,EACd;AACF;",
5
- "names": []
6
- }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=types.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "mappings": "",
5
- "names": []
6
- }
@@ -1,6 +0,0 @@
1
- // src/customer/sdk.ts
2
- import { ZappieError } from "@zappie/sdk";
3
- export {
4
- ZappieError
5
- };
6
- //# sourceMappingURL=sdk.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/customer/sdk.ts"],
4
- "mappings": ";AAEA,SAAS,mBAAmB;",
5
- "names": []
6
- }
@@ -1,126 +0,0 @@
1
- // src/testing/account.ts
2
- var ngn = (amount_minor) => ({ amount_minor, currency: "NGN" });
3
- var receipt = (id, status, amount, at, method) => ({
4
- id,
5
- status,
6
- amount: ngn(amount),
7
- paid: ngn(amount),
8
- reference: `PAY_${id.slice(4).toUpperCase()}`,
9
- branch_id: "br_fixture",
10
- branch_name: "Main",
11
- order_id: status === "failed" ? null : `ord_${id.slice(4)}`,
12
- created_at: at,
13
- paid_at: status === "failed" ? null : at,
14
- method
15
- });
16
- var accountFixtures = {
17
- wallets: [
18
- { currency: "NGN", balance: ngn(25e5) },
19
- { currency: "USD", balance: { amount_minor: 1250, currency: "USD" } }
20
- ],
21
- cards: [
22
- {
23
- id: "card_fixture1",
24
- brand: "mastercard",
25
- last4: "4321",
26
- exp_month: 4,
27
- exp_year: 2029
28
- },
29
- {
30
- id: "card_fixture2",
31
- brand: "visa",
32
- last4: "1881",
33
- exp_month: 11,
34
- exp_year: 2027
35
- }
36
- ],
37
- payments: [
38
- receipt("pay_fixture3", "successful", 105e4, "2026-10-12T12:00:00Z", {
39
- type: "card",
40
- card_brand: "mastercard",
41
- card_last4: "4321"
42
- }),
43
- receipt("pay_fixture2", "refunded", 45e4, "2026-10-11T09:30:00Z", {
44
- type: "bank_transfer",
45
- bank_name: "Example Bank",
46
- account_name: "Ada Obi"
47
- }),
48
- receipt("pay_fixture1", "failed", 2e5, "2026-10-10T18:15:00Z", {
49
- type: "wallet"
50
- })
51
- ]
52
- };
53
- var SCOPES = ["wallet", "cards", "payments:read"];
54
- function mockAccountFetch(fixtures = accountFixtures, options = {}) {
55
- const data = structuredClone(fixtures);
56
- const granted = options.scopes ?? SCOPES;
57
- const error = (status, code, message) => Response.json({ error: { code, message } }, { status });
58
- return async (input, init) => {
59
- const request = new Request(
60
- new URL(String(input), "http://mock.test"),
61
- init
62
- );
63
- const url = new URL(request.url);
64
- const [, resource, id, extra] = /\/me\/(wallets|cards|payments)(?:\/([^/]+))?(\/.*)?$/.exec(
65
- url.pathname
66
- ) ?? [];
67
- if (!resource || extra !== void 0) {
68
- return error(404, "not_found", "No such endpoint.");
69
- }
70
- const scope = resource === "wallets" ? "wallet" : resource === "cards" ? "cards" : "payments:read";
71
- if (!granted.includes(scope)) {
72
- return error(
73
- 403,
74
- "scope_required",
75
- `The customer did not grant the ${scope} scope.`
76
- );
77
- }
78
- const method = request.method;
79
- if (resource === "wallets" && id === void 0 && method === "GET") {
80
- return Response.json({ wallets: data.wallets });
81
- }
82
- if (resource === "cards" && id === void 0 && method === "GET") {
83
- return Response.json({ cards: data.cards });
84
- }
85
- if (resource === "cards" && id !== void 0 && method === "DELETE") {
86
- const cardId = decodeURIComponent(id);
87
- if (!/^card_\w+$/.test(cardId)) {
88
- return error(400, "invalid_id", "That isn't a card ID.");
89
- }
90
- const index = data.cards.findIndex((card) => card.id === cardId);
91
- if (index < 0) {
92
- return error(404, "not_found", "No such card.");
93
- }
94
- data.cards.splice(index, 1);
95
- return new Response(null, { status: 204 });
96
- }
97
- if (resource === "payments" && method === "GET") {
98
- if (id !== void 0) {
99
- const found = data.payments.find(
100
- (payment) => payment.id === decodeURIComponent(id)
101
- );
102
- return found ? Response.json(found) : error(404, "not_found", "No such payment.");
103
- }
104
- const limit = Number(url.searchParams.get("limit") ?? 20);
105
- const cursor = url.searchParams.get("cursor");
106
- const start = cursor === null ? 0 : data.payments.findIndex((payment) => payment.id === cursor);
107
- if (!Number.isInteger(limit) || limit < 1 || start < 0) {
108
- return error(400, "parameter_invalid", "Check limit and cursor.");
109
- }
110
- const page = data.payments.slice(start, start + Math.min(limit, 50));
111
- const next = data.payments[start + page.length];
112
- return Response.json({
113
- payments: page.map(
114
- ({ branch_name: _name, method: _method, ...payment }) => payment
115
- ),
116
- next_cursor: next?.id ?? null
117
- });
118
- }
119
- return error(405, "method_not_allowed", "Method not allowed.");
120
- };
121
- }
122
- export {
123
- accountFixtures,
124
- mockAccountFetch
125
- };
126
- //# sourceMappingURL=account.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/testing/account.ts"],
4
- "mappings": ";AA2BA,IAAM,MAAM,CAAC,kBAA0B,EAAE,cAAc,UAAU,MAAM;AACvE,IAAM,UAAU,CACd,IACA,QACA,QACA,IACA,YACoB;AAAA,EACpB;AAAA,EACA;AAAA,EACA,QAAQ,IAAI,MAAM;AAAA,EAClB,MAAM,IAAI,MAAM;AAAA,EAChB,WAAW,OAAO,GAAG,MAAM,CAAC,EAAE,YAAY,CAAC;AAAA,EAC3C,WAAW;AAAA,EACX,aAAa;AAAA,EACb,UAAU,WAAW,WAAW,OAAO,OAAO,GAAG,MAAM,CAAC,CAAC;AAAA,EACzD,YAAY;AAAA,EACZ,SAAS,WAAW,WAAW,OAAO;AAAA,EACtC;AACF;AAOO,IAAM,kBAAuC;AAAA,EAClD,SAAS;AAAA,IACP,EAAE,UAAU,OAAO,SAAS,IAAI,IAAS,EAAE;AAAA,IAC3C,EAAE,UAAU,OAAO,SAAS,EAAE,cAAc,MAAO,UAAU,MAAM,EAAE;AAAA,EACvE;AAAA,EACA,OAAO;AAAA,IACL;AAAA,MACE,IAAI;AAAA,MACJ,OAAO;AAAA,MACP,OAAO;AAAA,MACP,WAAW;AAAA,MACX,UAAU;AAAA,IACZ;AAAA,IACA;AAAA,MACE,IAAI;AAAA,MACJ,OAAO;AAAA,MACP,OAAO;AAAA,MACP,WAAW;AAAA,MACX,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA,UAAU;AAAA,IACR,QAAQ,gBAAgB,cAAc,OAAW,wBAAwB;AAAA,MACvE,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,YAAY;AAAA,IACd,CAAC;AAAA,IACD,QAAQ,gBAAgB,YAAY,MAAS,wBAAwB;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