@zappie/sdk 0.5.1 → 0.6.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 +30 -0
- package/README.md +16 -16
- package/dist/account/index.d.ts +2 -131
- package/dist/account/index.js +1 -6
- package/dist/account/index.js.map +1 -1
- package/dist/checkout/error.js +2 -3
- package/dist/checkout/error.js.map +1 -1
- package/dist/{client-DHxakZrv.d.ts → client-DInn0X0F.d.ts} +1 -1
- package/dist/customer/error.js +2 -3
- package/dist/customer/error.js.map +1 -1
- package/dist/debug.js +1 -1
- package/dist/errors.js +3 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/internal/customer-http.js +11 -7
- package/dist/internal/customer-http.js.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/persist/catalogue.d.ts +1 -1
- package/dist/places/error.js +2 -3
- package/dist/places/error.js.map +1 -1
- package/dist/places/index.d.ts +5 -2
- package/dist/server/index.d.ts +1 -1
- package/dist/testing/index.d.ts +3 -82
- package/dist/testing/index.js +1 -4
- package/dist/transport/selected-menu.d.ts +1 -1
- package/package.json +1 -1
- package/dist/account/client.js +0 -68
- package/dist/account/client.js.map +0 -6
- package/dist/account/errors.js +0 -20
- package/dist/account/errors.js.map +0 -6
- package/dist/account/types.js +0 -1
- package/dist/account/types.js.map +0 -6
- package/dist/customer/sdk.js +0 -6
- package/dist/customer/sdk.js.map +0 -6
- package/dist/testing/account.js +0 -126
- package/dist/testing/account.js.map +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @zappie/sdk
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 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.
|
|
8
|
+
|
|
9
|
+
`@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.
|
|
10
|
+
|
|
11
|
+
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.
|
|
12
|
+
|
|
13
|
+
- 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.
|
|
14
|
+
|
|
15
|
+
Code that checked for `server_error` on a 403 now sees `scope_required` or `forbidden`.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 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.
|
|
20
|
+
|
|
21
|
+
## 0.5.2
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 6ea8744: The shopper's Zappie account, with their profile, saved cards, wallet and payments, lives on the Zappie accounts portal. A site keeps its orders, its store contact and one "Your Zappie account" row.
|
|
26
|
+
|
|
27
|
+
`@zappie/foundations` adds that row. `ZappieAccountLink` renders an unstyled link labelled "Your Zappie account" to the portal's `/account`, with a return link to the current page. `useZappieAccountUrl()` gives the same address for your own link, and `zappieAccountUrl(page)` builds it for any page. `zappieEnvironment(host)` picks the portal: `staging` for localhost and the loopback addresses, `*.workers.dev`, `*.zappie-sites.dev` and any host with `.stg.` in it, and `production` for every other host, including `<tag>.zappie.shop` and custom domains. `SignInOptions.scopes` no longer accepts `cards` or `payments:read`.
|
|
28
|
+
|
|
29
|
+
The kit's account page and the starter's account page show the row below "Your orders".
|
|
30
|
+
|
|
31
|
+
`createAccount` and its calls, `ScopeRequiredError`, `NotFoundError` and the account types in `@zappie/sdk/account`, `mockAccountFetch` and `accountFixtures` in `@zappie/sdk/testing`, and the parts in `@zappie/foundations/account` are deprecated and removed in the next minor release. The API is removing the routes they call. `accountsUrl` stays as it is.
|
|
32
|
+
|
|
3
33
|
## 0.5.1
|
|
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` |
|
|
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
|
|
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
|
|
package/dist/account/index.d.ts
CHANGED
|
@@ -1,132 +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
|
-
/** A scope the account calls need. A token without it gets `scope_required`. */
|
|
12
|
-
type AccountScope = "wallet" | "cards" | "payments:read";
|
|
13
|
-
/** One balance in the shopper's Zappie wallet, which is the same at every business. */
|
|
14
|
-
type Wallet = {
|
|
15
|
-
currency: string;
|
|
16
|
-
balance: Money;
|
|
17
|
-
};
|
|
18
|
-
/** A card the shopper saved when they paid. It never carries the full card number. */
|
|
19
|
-
type SavedCard = {
|
|
20
|
-
id: string;
|
|
21
|
-
/** The card scheme in lower case, such as `mastercard`. */
|
|
22
|
-
brand: string;
|
|
23
|
-
last4: string;
|
|
24
|
-
exp_month: number;
|
|
25
|
-
exp_year: number;
|
|
26
|
-
};
|
|
27
|
-
/** A payment the shopper made at this business. */
|
|
28
|
-
type CustomerPayment = {
|
|
29
|
-
id: string;
|
|
30
|
-
status: "successful" | "failed" | "refunded";
|
|
31
|
-
/** What the payment was for. */
|
|
32
|
-
amount: Money;
|
|
33
|
-
/** What the shopper paid, fees included. */
|
|
34
|
-
paid: Money;
|
|
35
|
-
reference: string;
|
|
36
|
-
branch_id: string;
|
|
37
|
-
/** The order the payment paid for, or null when it wasn't a delivery or pickup order. */
|
|
38
|
-
order_id: string | null;
|
|
39
|
-
created_at: string;
|
|
40
|
-
paid_at: string | null;
|
|
41
|
-
};
|
|
42
|
-
/** A page of payments and the cursor for the next page, or null at the end. */
|
|
43
|
-
type PaymentsPage = {
|
|
44
|
-
payments: CustomerPayment[];
|
|
45
|
-
next_cursor: string | null;
|
|
46
|
-
};
|
|
47
|
-
/** How the shopper paid. A card shows its brand and last four digits, a bank transfer its bank and account name. */
|
|
48
|
-
type PaymentMethodDetails = {
|
|
49
|
-
type: "card" | "card_terminal" | "bank_transfer" | "wallet" | "apple_pay" | "google_pay" | "store_credit" | "loyalty_points" | "mobile_money" | "other";
|
|
50
|
-
card_brand?: string;
|
|
51
|
-
card_last4?: string;
|
|
52
|
-
bank_name?: string;
|
|
53
|
-
account_name?: string;
|
|
54
|
-
};
|
|
55
|
-
/** A payment with what its receipt shows: the branch's name and how the shopper paid. */
|
|
56
|
-
type PaymentReceipt = CustomerPayment & {
|
|
57
|
-
branch_name: string;
|
|
58
|
-
method: PaymentMethodDetails;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Where the account calls go and how. They share the customer client's defaults, so a site that
|
|
62
|
-
* changed `customerBase` or `fetch` for createCustomer passes the same values here.
|
|
63
|
-
*/
|
|
64
|
-
type AccountClientOptions = {
|
|
65
|
-
customerBase?: string;
|
|
66
|
-
fetch?: typeof fetch;
|
|
67
|
-
/** The site's customer client. A call the session no longer allows re-checks it, so the site sees the shopper signed out. */
|
|
68
|
-
customer?: {
|
|
69
|
-
session(): Promise<unknown>;
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Create a client for the shopper's wallet, saved cards and payments at this business, through the
|
|
75
|
-
* same endpoint and session as createCustomer. Load it only on account pages.
|
|
76
|
-
* A call the shopper's sign-in doesn't allow rejects with ScopeRequiredError. A card or payment that
|
|
77
|
-
* isn't theirs rejects with NotFoundError. Any other failure is a CustomerError.
|
|
78
|
-
*
|
|
79
|
-
* @param options - Endpoint and fetch overrides, and the site's customer client.
|
|
80
|
-
* @returns The account calls.
|
|
81
|
-
*/
|
|
82
|
-
declare function createAccount(options?: AccountClientOptions): {
|
|
83
|
-
/** The shopper's Zappie wallet, one balance per currency, naira first. Needs the `wallet` scope. */
|
|
84
|
-
wallets(): Promise<Wallet[]>;
|
|
85
|
-
/** The cards the shopper saved when they paid. Needs the `cards` scope. */
|
|
86
|
-
cards(): Promise<SavedCard[]>;
|
|
87
|
-
/** Remove one of the shopper's saved cards. Needs the `cards` scope. */
|
|
88
|
-
removeCard: (id: string) => Promise<void>;
|
|
89
|
-
/**
|
|
90
|
-
* One page of the shopper's payments at this business, newest first. Needs the `payments:read` scope.
|
|
91
|
-
*
|
|
92
|
-
* @param page - Up to 50 payments a page, 20 by default, and the next_cursor of the previous page.
|
|
93
|
-
*/
|
|
94
|
-
payments(page?: {
|
|
95
|
-
limit?: number;
|
|
96
|
-
cursor?: string;
|
|
97
|
-
}): Promise<PaymentsPage>;
|
|
98
|
-
/** One payment with what its receipt shows. Needs the `payments:read` scope. */
|
|
99
|
-
payment: (id: string) => Promise<PaymentReceipt>;
|
|
100
|
-
};
|
|
101
|
-
/** The wallet, card and payment calls returned by createAccount. */
|
|
102
|
-
type AccountClient = ReturnType<typeof createAccount>;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* A customer API failure with its HTTP status, API code and optional validation issues.
|
|
106
|
-
* Statuses 429 and 5xx are marked retryable.
|
|
107
|
-
*/
|
|
108
|
-
declare class CustomerError extends ZappieError {
|
|
109
|
-
readonly apiCode: string;
|
|
110
|
-
readonly issues?: unknown;
|
|
111
|
-
constructor(status: number, apiCode: string, message: string, param?: string, issues?: unknown);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* The shopper's sign-in doesn't include the scope this call needs, usually because they signed in
|
|
116
|
-
* before the site asked for it. Offer to sign in again. It doesn't sign the shopper out.
|
|
117
|
-
*/
|
|
118
|
-
declare class ScopeRequiredError extends CustomerError {
|
|
119
|
-
/** The scope the call needs. */
|
|
120
|
-
readonly scope: AccountScope;
|
|
121
|
-
constructor(
|
|
122
|
-
/** The scope the call needs. */
|
|
123
|
-
scope: AccountScope, message: string);
|
|
124
|
-
}
|
|
125
|
-
/** The card or payment isn't the shopper's, or isn't at this business. */
|
|
126
|
-
declare class NotFoundError extends CustomerError {
|
|
127
|
-
constructor(message: string);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
1
|
/** The Zappie environment a service URL points at. */
|
|
131
2
|
type ZappieEnvironment = "production" | "staging";
|
|
132
3
|
|
|
@@ -146,5 +17,5 @@ declare function accountsUrl(path: AccountsPage, environment?: ZappieEnvironment
|
|
|
146
17
|
returnTo?: string | URL;
|
|
147
18
|
}): string;
|
|
148
19
|
|
|
149
|
-
export {
|
|
150
|
-
export type {
|
|
20
|
+
export { accountsUrl };
|
|
21
|
+
export type { AccountsPage };
|
package/dist/account/index.js
CHANGED
|
@@ -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
|
-
|
|
7
|
-
ScopeRequiredError,
|
|
8
|
-
accountsUrl,
|
|
9
|
-
createAccount
|
|
4
|
+
accountsUrl
|
|
10
5
|
};
|
|
11
6
|
//# sourceMappingURL=index.js.map
|
package/dist/checkout/error.js
CHANGED
|
@@ -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,
|
|
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;
|
package/dist/customer/error.js
CHANGED
|
@@ -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,
|
|
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
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,
|
package/dist/errors.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/errors.ts"],
|
|
4
|
-
"mappings": ";
|
|
4
|
+
"mappings": ";AAiBA,IAAM,QAA2B;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAWO,IAAM,cAAN,cAA0B,MAAM;AAAA,EAMrC,YACW,MACT,SACA,UAAwB,CAAC,GACzB;AACA,UAAM,SAAS,EAAE,OAAO,QAAQ,MAAM,CAAC;AAJ9B;AAKT,SAAK,OAAO;AACZ,QAAI,QAAQ,WAAW,QAAW;AAChC,WAAK,SAAS,QAAQ;AAAA,IACxB;AACA,QAAI,QAAQ,UAAU,QAAW;AAC/B,WAAK,QAAQ,QAAQ;AAAA,IACvB;AACA,QAAI,QAAQ,cAAc,QAAW;AACnC,WAAK,YAAY,QAAQ;AAAA,IAC3B;AACA,SAAK,SAAS,QAAQ,UAAU,iCAAiC,IAAI;AACrE,SAAK,YACH,QAAQ,aACR,CAAC,iBAAiB,WAAW,gBAAgB,cAAc,EAAE;AAAA,MAC3D;AAAA,IACF;AAAA,EACJ;AACF;AAEO,SAAS,cAAc,OAAsC;AAClE,SAAO,iBAAiB;AAC1B;AACO,SAAS,QAAQ,OAA6B;AACnD,SAAO,cAAc,KAAK,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-
|
|
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-
|
|
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.
|
|
13
|
+
var VERSION = true ? "0.6.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
|
|
21
|
-
const value =
|
|
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:
|
|
24
|
-
message:
|
|
25
|
-
...
|
|
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;
|
|
4
|
+
"mappings": ";AAEA,SAAS,mBAAmB;AAWrB,SAAS,gBAAgB,QAAgB,SAAiB;AAC/D,MAAI,WAAW,OAAO,WAAW,KAAK;AACpC,WAAO;AAAA,EACT;AACA,MAAI,WAAW,KAAK;AAClB,WAAO;AAAA,EACT;AACA,MAAI,WAAW,KAAK;AAClB,WAAO,YAAY,mBAAmB,UAAU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;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
|
}
|
package/dist/internal.d.ts
CHANGED
|
@@ -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-
|
|
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';
|
package/dist/places/error.js
CHANGED
|
@@ -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 } : {}
|
package/dist/places/error.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/places/error.ts"],
|
|
4
|
-
"mappings": ";AAAA,SAAS,
|
|
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
|
}
|
package/dist/places/index.d.ts
CHANGED
|
@@ -18,11 +18,14 @@ type Place = {
|
|
|
18
18
|
country?: string;
|
|
19
19
|
lat: number;
|
|
20
20
|
lng: number;
|
|
21
|
-
/**
|
|
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
|
-
/**
|
|
28
|
+
/** Drive time in seconds, without live traffic. */
|
|
26
29
|
duration_seconds?: number;
|
|
27
30
|
};
|
|
28
31
|
};
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Menu, Store, Formatters } from '../index.js';
|
|
2
|
-
import { C as Cache } from '../client-
|
|
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';
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,88 +1,9 @@
|
|
|
1
|
-
import { C as Cache } from '../client-
|
|
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
|
-
/** A scope the account calls need. A token without it gets `scope_required`. */
|
|
16
|
-
type AccountScope = "wallet" | "cards" | "payments:read";
|
|
17
|
-
/** One balance in the shopper's Zappie wallet, which is the same at every business. */
|
|
18
|
-
type Wallet = {
|
|
19
|
-
currency: string;
|
|
20
|
-
balance: Money;
|
|
21
|
-
};
|
|
22
|
-
/** A card the shopper saved when they paid. It never carries the full card number. */
|
|
23
|
-
type SavedCard = {
|
|
24
|
-
id: string;
|
|
25
|
-
/** The card scheme in lower case, such as `mastercard`. */
|
|
26
|
-
brand: string;
|
|
27
|
-
last4: string;
|
|
28
|
-
exp_month: number;
|
|
29
|
-
exp_year: number;
|
|
30
|
-
};
|
|
31
|
-
/** A payment the shopper made at this business. */
|
|
32
|
-
type CustomerPayment = {
|
|
33
|
-
id: string;
|
|
34
|
-
status: "successful" | "failed" | "refunded";
|
|
35
|
-
/** What the payment was for. */
|
|
36
|
-
amount: Money;
|
|
37
|
-
/** What the shopper paid, fees included. */
|
|
38
|
-
paid: Money;
|
|
39
|
-
reference: string;
|
|
40
|
-
branch_id: string;
|
|
41
|
-
/** The order the payment paid for, or null when it wasn't a delivery or pickup order. */
|
|
42
|
-
order_id: string | null;
|
|
43
|
-
created_at: string;
|
|
44
|
-
paid_at: string | null;
|
|
45
|
-
};
|
|
46
|
-
/** How the shopper paid. A card shows its brand and last four digits, a bank transfer its bank and account name. */
|
|
47
|
-
type PaymentMethodDetails = {
|
|
48
|
-
type: "card" | "card_terminal" | "bank_transfer" | "wallet" | "apple_pay" | "google_pay" | "store_credit" | "loyalty_points" | "mobile_money" | "other";
|
|
49
|
-
card_brand?: string;
|
|
50
|
-
card_last4?: string;
|
|
51
|
-
bank_name?: string;
|
|
52
|
-
account_name?: string;
|
|
53
|
-
};
|
|
54
|
-
/** A payment with what its receipt shows: the branch's name and how the shopper paid. */
|
|
55
|
-
type PaymentReceipt = CustomerPayment & {
|
|
56
|
-
branch_name: string;
|
|
57
|
-
method: PaymentMethodDetails;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/** The wallets, saved cards and payment receipts the mock account endpoints answer with. */
|
|
61
|
-
type MockAccountFixtures = {
|
|
62
|
-
wallets: Wallet[];
|
|
63
|
-
cards: SavedCard[];
|
|
64
|
-
/** Newest first, as the API lists them. */
|
|
65
|
-
payments: PaymentReceipt[];
|
|
66
|
-
};
|
|
67
|
-
/** The scopes the mock shopper granted. Leave it out to grant all three. */
|
|
68
|
-
type MockAccountOptions = {
|
|
69
|
-
scopes?: AccountScope[];
|
|
70
|
-
};
|
|
71
|
-
/** Sample account data with no real cards or people: two balances, two cards and three payments. */
|
|
72
|
-
declare const accountFixtures: MockAccountFixtures;
|
|
73
|
-
/**
|
|
74
|
-
* A fetch that answers the account endpoints `/me/wallets`, `/me/cards`, `/me/cards/{card_id}`,
|
|
75
|
-
* `/me/payments` and `/me/payments/{payment_id}` as the API does, from fixtures and in memory.
|
|
76
|
-
* Pass it as `fetch` to createAccount, or call it from a mock API server. A removed card stays
|
|
77
|
-
* removed for this fetch. A scope left out of `scopes` answers 403 `scope_required`. Any other
|
|
78
|
-
* path answers 404.
|
|
79
|
-
*
|
|
80
|
-
* @param fixtures - The account data. Defaults to accountFixtures.
|
|
81
|
-
* @param options - The scopes the shopper granted.
|
|
82
|
-
* @returns A fetch implementation for the account endpoints.
|
|
83
|
-
*/
|
|
84
|
-
declare function mockAccountFetch(fixtures?: MockAccountFixtures, options?: MockAccountOptions): typeof fetch;
|
|
85
|
-
|
|
86
7
|
/** Store and branch menus supplied to the deterministic mock transport. */
|
|
87
8
|
type MockFixtures = {
|
|
88
9
|
store: Store;
|
|
@@ -143,5 +64,5 @@ declare const fixtures: {
|
|
|
143
64
|
};
|
|
144
65
|
};
|
|
145
66
|
|
|
146
|
-
export {
|
|
147
|
-
export type {
|
|
67
|
+
export { createMockZappie, fixtures };
|
|
68
|
+
export type { MockFixtures, MockOptions };
|
package/dist/testing/index.js
CHANGED
|
@@ -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-
|
|
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
package/dist/account/client.js
DELETED
|
@@ -1,68 +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
|
-
/** The shopper's Zappie wallet, one balance per currency, naira first. Needs the `wallet` scope. */
|
|
31
|
-
async wallets() {
|
|
32
|
-
return (await call("wallet", "/me/wallets")).wallets;
|
|
33
|
-
},
|
|
34
|
-
/** The cards the shopper saved when they paid. Needs the `cards` scope. */
|
|
35
|
-
async cards() {
|
|
36
|
-
return (await call("cards", "/me/cards")).cards;
|
|
37
|
-
},
|
|
38
|
-
/** Remove one of the shopper's saved cards. Needs the `cards` scope. */
|
|
39
|
-
removeCard: (id) => call("cards", `/me/cards/${encodeURIComponent(id)}`, "DELETE"),
|
|
40
|
-
/**
|
|
41
|
-
* One page of the shopper's payments at this business, newest first. Needs the `payments:read` scope.
|
|
42
|
-
*
|
|
43
|
-
* @param page - Up to 50 payments a page, 20 by default, and the next_cursor of the previous page.
|
|
44
|
-
*/
|
|
45
|
-
payments(page = {}) {
|
|
46
|
-
const query = new URLSearchParams();
|
|
47
|
-
if (page.limit !== void 0) {
|
|
48
|
-
query.set("limit", String(page.limit));
|
|
49
|
-
}
|
|
50
|
-
if (page.cursor !== void 0) {
|
|
51
|
-
query.set("cursor", page.cursor);
|
|
52
|
-
}
|
|
53
|
-
return call(
|
|
54
|
-
"payments:read",
|
|
55
|
-
`/me/payments${query.size > 0 ? `?${query}` : ""}`
|
|
56
|
-
);
|
|
57
|
-
},
|
|
58
|
-
/** One payment with what its receipt shows. Needs the `payments:read` scope. */
|
|
59
|
-
payment: (id) => call(
|
|
60
|
-
"payments:read",
|
|
61
|
-
`/me/payments/${encodeURIComponent(id)}`
|
|
62
|
-
)
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
export {
|
|
66
|
-
createAccount
|
|
67
|
-
};
|
|
68
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/account/client.ts"],
|
|
4
|
-
"mappings": ";AAAA,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AACtC,SAAS,eAAe,0BAA0B;AAmB3C,SAAS,cAAc,UAAgC,CAAC,GAAG;AAChE,QAAM,QAAQ,QAAQ,gBAAgB,gBAAgB,QAAQ,QAAQ,EAAE;AACxE,QAAM,UAAU;AAAA,IACd;AAAA,IACA,QAAQ,SAAS,WAAW;AAAA,IAC5B,MAAM;AACJ,WAAK,QAAQ,UAAU,QAAQ,EAAE,MAAM,MAAM,MAAS;AAAA,IACxD;AAAA,EACF;AACA,QAAM,OAAO,OACX,OACA,MACA,SAAS,UACM;AACf,QAAI;AACF,aAAO,MAAM,QAAW,MAAM,EAAE,OAAO,CAAC;AAAA,IAC1C,SAAS,OAAO;AACd,UAAI,iBAAiB,eAAe;AAClC,YAAI,MAAM,YAAY,kBAAkB;AACtC,gBAAM,IAAI,mBAAmB,OAAO,MAAM,OAAO;AAAA,QACnD;AACA,YAAI,MAAM,WAAW,KAAK;AACxB,gBAAM,IAAI,cAAc,MAAM,OAAO;AAAA,QACvC;AAAA,MACF;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACA,SAAO;AAAA;AAAA,IAEL,MAAM,UAA6B;AACjC,cAAQ,MAAM,KAA4B,UAAU,aAAa,GAC9D;AAAA,IACL;AAAA;AAAA,IAEA,MAAM,QAA8B;AAClC,cAAQ,MAAM,KAA6B,SAAS,WAAW,GAAG;AAAA,IACpE;AAAA;AAAA,IAEA,YAAY,CAAC,OACX,KAAK,SAAS,aAAa,mBAAmB,EAAE,CAAC,IAAI,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAM/D,SAAS,OAA4C,CAAC,GAAG;AACvD,YAAM,QAAQ,IAAI,gBAAgB;AAClC,UAAI,KAAK,UAAU,QAAW;AAC5B,cAAM,IAAI,SAAS,OAAO,KAAK,KAAK,CAAC;AAAA,MACvC;AACA,UAAI,KAAK,WAAW,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,IAEA,SAAS,CAAC,OACR;AAAA,MACE;AAAA,MACA,gBAAgB,mBAAmB,EAAE,CAAC;AAAA,IACxC;AAAA,EACJ;AACF;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
package/dist/account/errors.js
DELETED
|
@@ -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;AAOvB,IAAM,qBAAN,cAAiC,cAAc;AAAA,EACpD,YAEW,OACT,SACA;AACA,UAAM,KAAK,kBAAkB,OAAO;AAH3B;AAIT,SAAK,OAAO;AAAA,EACd;AACF;AAGO,IAAM,gBAAN,cAA4B,cAAc;AAAA,EAC/C,YAAY,SAAiB;AAC3B,UAAM,KAAK,aAAa,OAAO;AAC/B,SAAK,OAAO;AAAA,EACd;AACF;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
package/dist/account/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=types.js.map
|
package/dist/customer/sdk.js
DELETED
package/dist/customer/sdk.js.map
DELETED
package/dist/testing/account.js
DELETED
|
@@ -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": ";AAmBA,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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