@zappie/sdk 0.10.5 → 0.10.7
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 +18 -0
- package/README.md +23 -6
- package/dist/cart/item.d.ts +1 -1
- package/dist/cart/quote.d.ts +1 -1
- package/dist/{client-Bn7nRoy3.d.ts → client-CtDaenmW.d.ts} +2 -2
- package/dist/debug.js +1 -1
- package/dist/display/index.d.ts +32 -0
- package/dist/display/index.js +31 -0
- package/dist/display/index.js.map +6 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1 -1
- package/dist/integrations/index.d.ts +2 -2
- package/dist/internal.d.ts +2 -2
- package/dist/{models-C-kEg1Id.d.ts → models-asoc6fS3.d.ts} +10 -2
- package/dist/money.js +21 -32
- package/dist/money.js.map +1 -1
- package/dist/persist/catalogue.d.ts +3 -3
- package/dist/pricing/index.d.ts +22 -3
- package/dist/pricing/index.js +63 -12
- package/dist/pricing/index.js.map +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/transport/search.d.ts +1 -1
- package/dist/transport/selected-menu.d.ts +3 -3
- package/dist/transport/store.js +2 -0
- package/dist/transport/store.js.map +1 -1
- package/dist/{types-BzyzhqYz.d.ts → types-DMMeyB5d.d.ts} +1 -1
- package/dist/visits/index.d.ts +5 -3
- package/dist/visits/page-views.js.map +1 -1
- package/package.json +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @zappie/sdk
|
|
2
2
|
|
|
3
|
+
## 0.10.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a3f008f: `Branch` now has `category`, `"RESTAURANT"` or `"RETAIL"`, as the storefront API sends it. A branch without one is a restaurant.
|
|
8
|
+
|
|
9
|
+
New `@zappie/sdk/display` entry. `inVenueLabel(branch)` returns "Walk-in" for a retail branch and "Dine-in" otherwise. `formatPhone(phone, { country })` spaces a Nigerian or Ghanaian number for reading, such as "+234 809 822 6262", and returns any other number as given. Keep linking with the unspaced number.
|
|
10
|
+
|
|
11
|
+
`startingPrice()` now counts a required group's minimum. "Box of four rolls", where the shopper picks exactly four, starts at four of the cheapest roll plus the base price instead of one roll. A choice counts once unless the shopper can set its quantity. New `startingPriceWith(item, choices)` gives the starting price when the shopper picks from the given choices only, such as one plan length.
|
|
12
|
+
|
|
13
|
+
`format.money()` keeps one number formatter per currency and option set instead of building one on every call.
|
|
14
|
+
|
|
15
|
+
## 0.10.6
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 208a60c: `countEvent("checkout")` counts the funnel's checkout step when a shopper presses Pay in the bag or on a cart page. It is the same step a `/checkout` page view reaches.
|
|
20
|
+
|
|
3
21
|
## 0.10.5
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -60,7 +60,8 @@ Prices always come from Zappie. The cart shows a local estimate while it waits,
|
|
|
60
60
|
| `@zappie/sdk/account` | `accountsUrl`, a link to the shopper's Zappie account on the accounts portal |
|
|
61
61
|
| `@zappie/sdk/integrations` | Public integration IDs and browser keys |
|
|
62
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"
|
|
63
|
+
| `@zappie/sdk/pricing` | An item's starting price, its price with given choices, and whether to show it as "From" |
|
|
64
|
+
| `@zappie/sdk/display` | Phone numbers spaced for reading, and what a branch calls an in-person order |
|
|
64
65
|
| `@zappie/sdk/branches` | The nearest branch to a shopper, and each branch's distance from them |
|
|
65
66
|
| `@zappie/sdk/options` | Option group rules: radio or checkbox, the group's limit, its labels and the note limit |
|
|
66
67
|
| `@zappie/sdk/server` | Server-side reads, storefront URLs, `verifyWebhook()`, menu snapshots and sign-in crypto |
|
|
@@ -133,16 +134,32 @@ MIT
|
|
|
133
134
|
### Starting price
|
|
134
135
|
|
|
135
136
|
`startingPrice(item)` from `@zappie/sdk/pricing` returns the price an item starts from: the cheapest
|
|
136
|
-
available variant plus the cheapest
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
add-on raises it. `item.price` is
|
|
137
|
+
available variant plus the cheapest valid choices of each required add-on group. A group that needs
|
|
138
|
+
exactly or at least four choices adds its four cheapest units, and a choice counts once unless the
|
|
139
|
+
shopper can set its quantity. It is the rule Zappie uses for a product's starting price. When no
|
|
140
|
+
variant is available, it uses the cheapest variant. `showsFromPrice(item)` says whether to show that
|
|
141
|
+
price as "From": available variants differ in price, or a required add-on raises it. `item.price` is
|
|
142
|
+
the branch price, not the starting price.
|
|
143
|
+
|
|
144
|
+
`startingPriceWith(item, choices)` is the starting price when the shopper picks from the given
|
|
145
|
+
choices only, such as one plan length: `[{ groupId: "length", choiceId: "4-weeks" }]`. An attribute
|
|
146
|
+
group narrows the variants, and an add-on group narrows its choices.
|
|
141
147
|
|
|
142
148
|
The API sends one `available` flag per item and variant, and a free-text
|
|
143
149
|
`stockLabel`. It doesn't say whether an item is sold out or unavailable for
|
|
144
150
|
another reason, so `isAvailable` covers both.
|
|
145
151
|
|
|
152
|
+
### Phone numbers and in-person orders
|
|
153
|
+
|
|
154
|
+
`formatPhone(phone)` from `@zappie/sdk/display` spaces a number for reading:
|
|
155
|
+
`formatPhone("+2348098226262")` is `"+234 809 822 6262"`. Link with the unspaced
|
|
156
|
+
number, as in `tel:+2348098226262`. It knows Nigerian and Ghanaian numbers and
|
|
157
|
+
returns any other number as given. Pass `{ country: "NG" }` to read a number
|
|
158
|
+
written without a country code.
|
|
159
|
+
|
|
160
|
+
`inVenueLabel(branch)` says what an order placed at the branch is called:
|
|
161
|
+
"Walk-in" when `branch.category` is `"RETAIL"`, and "Dine-in" otherwise.
|
|
162
|
+
|
|
146
163
|
### Place routes
|
|
147
164
|
|
|
148
165
|
`places.place(placeId, { branchId })` returns `route` with optional
|
package/dist/cart/item.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Zappie } from '../index.js';
|
|
2
2
|
import { Item } from '../index.js';
|
|
3
|
-
import '../types-
|
|
3
|
+
import '../types-DMMeyB5d.js';
|
|
4
4
|
|
|
5
5
|
/** Register an item already read by a partial/selected catalogue, without fetching it again. */
|
|
6
6
|
declare function prepareItem(client: Zappie, item: Item, options: {
|
package/dist/cart/quote.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as Menu, C as CategoryPage, S as Store, I as Item, M as Money, F as Formatters } from './models-
|
|
2
|
-
import { Q as QuoteRequest, h as WireQuote, e as CartIssueCode, d as CartModule, b as CartLineInput } from './types-
|
|
1
|
+
import { a as Menu, C as CategoryPage, S as Store, I as Item, M as Money, F as Formatters } from './models-asoc6fS3.js';
|
|
2
|
+
import { Q as QuoteRequest, h as WireQuote, e as CartIssueCode, d as CartModule, b as CartLineInput } from './types-DMMeyB5d.js';
|
|
3
3
|
|
|
4
4
|
/** Stable public error codes. */
|
|
5
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";
|
package/dist/debug.js
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Branch } from '@zappie/sdk';
|
|
2
|
+
|
|
3
|
+
/** What an order placed at the branch is called. */
|
|
4
|
+
type InVenueLabel = "Dine-in" | "Walk-in";
|
|
5
|
+
/**
|
|
6
|
+
* What to call an order placed at the branch: "Walk-in" for a retail branch and
|
|
7
|
+
* "Dine-in" otherwise. A branch without a category is a restaurant.
|
|
8
|
+
*
|
|
9
|
+
* @param branch - The branch the order is for.
|
|
10
|
+
*/
|
|
11
|
+
declare function inVenueLabel(branch: Pick<Branch, "category">): InVenueLabel;
|
|
12
|
+
/** Options for `formatPhone`. */
|
|
13
|
+
type FormatPhoneOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* The two-letter country code to read a number without a leading "+" in,
|
|
16
|
+
* such as "NG" for "0809 822 6262".
|
|
17
|
+
*/
|
|
18
|
+
country?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A phone number spaced for reading, such as "+234 809 822 6262" for
|
|
22
|
+
* "+2348098226262". Use the unspaced number in `tel:` links. A trunk "0"
|
|
23
|
+
* after the country code is dropped. A number from a country Zappie doesn't
|
|
24
|
+
* operate in, or one that doesn't read as a phone number, comes back as given.
|
|
25
|
+
*
|
|
26
|
+
* @param phone - The number, ideally in E.164 form such as "+2348098226262".
|
|
27
|
+
* @param options - The country to read a number without a "+" in.
|
|
28
|
+
*/
|
|
29
|
+
declare function formatPhone(phone: string, options?: FormatPhoneOptions): string;
|
|
30
|
+
|
|
31
|
+
export { formatPhone, inVenueLabel };
|
|
32
|
+
export type { FormatPhoneOptions, InVenueLabel };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/display/index.ts
|
|
2
|
+
function inVenueLabel(branch) {
|
|
3
|
+
return branch.category === "RETAIL" ? "Walk-in" : "Dine-in";
|
|
4
|
+
}
|
|
5
|
+
var PLANS = {
|
|
6
|
+
NG: ["234", [3, 3, 4]],
|
|
7
|
+
GH: ["233", [2, 3, 4]]
|
|
8
|
+
};
|
|
9
|
+
function formatPhone(phone, options = {}) {
|
|
10
|
+
const compact = phone.replace(/[\s().-]/g, "");
|
|
11
|
+
const plan = compact[0] === "+" ? Object.values(PLANS).find(([code2]) => compact.startsWith(code2, 1)) : PLANS[options.country?.toUpperCase() ?? ""];
|
|
12
|
+
if (!plan) {
|
|
13
|
+
return phone;
|
|
14
|
+
}
|
|
15
|
+
const [code, groups] = plan;
|
|
16
|
+
const length = groups.reduce((sum, size) => sum + size, 0);
|
|
17
|
+
const national = (compact[0] === "+" ? compact.slice(1 + code.length) : compact.length === code.length + length && compact.startsWith(code) ? compact.slice(code.length) : compact).replace(/^0/, "");
|
|
18
|
+
if (national.length !== length || !/^\d+$/.test(national)) {
|
|
19
|
+
return phone;
|
|
20
|
+
}
|
|
21
|
+
let at = 0;
|
|
22
|
+
return [
|
|
23
|
+
`+${code}`,
|
|
24
|
+
...groups.map((size) => national.slice(at, at += size))
|
|
25
|
+
].join(" ");
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
formatPhone,
|
|
29
|
+
inVenueLabel
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/display/index.ts"],
|
|
4
|
+
"mappings": ";AAaO,SAAS,aAAa,QAAgD;AAC3E,SAAO,OAAO,aAAa,WAAW,YAAY;AACpD;AAaA,IAAM,QAA0D;AAAA,EAC9D,IAAI,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC;AAAA,EACrB,IAAI,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC;AACvB;AAWO,SAAS,YACd,OACA,UAA8B,CAAC,GACvB;AACR,QAAM,UAAU,MAAM,QAAQ,aAAa,EAAE;AAC7C,QAAM,OACJ,QAAQ,CAAC,MAAM,MACX,OAAO,OAAO,KAAK,EAAE,KAAK,CAAC,CAACA,KAAI,MAAM,QAAQ,WAAWA,OAAM,CAAC,CAAC,IACjE,MAAM,QAAQ,SAAS,YAAY,KAAK,EAAE;AAChD,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AACA,QAAM,CAAC,MAAM,MAAM,IAAI;AACvB,QAAM,SAAS,OAAO,OAAO,CAAC,KAAK,SAAS,MAAM,MAAM,CAAC;AAEzD,QAAM,YACJ,QAAQ,CAAC,MAAM,MACX,QAAQ,MAAM,IAAI,KAAK,MAAM,IAC7B,QAAQ,WAAW,KAAK,SAAS,UAAU,QAAQ,WAAW,IAAI,IAChE,QAAQ,MAAM,KAAK,MAAM,IACzB,SACN,QAAQ,MAAM,EAAE;AAClB,MAAI,SAAS,WAAW,UAAU,CAAC,QAAQ,KAAK,QAAQ,GAAG;AACzD,WAAO;AAAA,EACT;AACA,MAAI,KAAK;AACT,SAAO;AAAA,IACL,IAAI,IAAI;AAAA,IACR,GAAG,OAAO,IAAI,CAAC,SAAS,SAAS,MAAM,IAAK,MAAM,IAAK,CAAC;AAAA,EAC1D,EAAE,KAAK,GAAG;AACZ;",
|
|
5
|
+
"names": ["code"]
|
|
6
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { a as ZappieError, T as Transport, R as RequestCtx, g as MenuFulfilment, h as MenuResponse, k as SearchRequest, l as SearchPage, m as MenuVersion } from './client-
|
|
1
|
+
import { a as ZappieError, T as Transport, R as RequestCtx, g as MenuFulfilment, h as MenuResponse, k as SearchRequest, l as SearchPage, m as MenuVersion } from './client-CtDaenmW.js';
|
|
2
2
|
import { SelectedMenuRequest, SelectedMenuResponse } from './transport/selected-menu.js';
|
|
3
|
-
export { A as API_VERSION, E as ErrorDetails, e as MenuReadOptions, M as MenuResource, n as ReadOptions, S as StorageLike, c as StoreResource, Z as Zappie, b as ZappieClientOptions, b as ZappieConfig, f as ZappieErrorCode, d as ZappieEvents, o as createZappie, p as isZappieError } from './client-
|
|
4
|
-
import { g as CartIssue, a as Quote, b as CartLineInput, C as CartLine, Q as QuoteRequest, h as WireQuote } from './types-
|
|
5
|
-
export { i as CartFix, c as CartFulfilment, e as CartIssueCode, d as CartModule, j as CartSnapshot, f as CartState, k as CartSyncAdapter, l as CartSyncDocument, D as DeliveryAddress, m as WireFix, W as WireFulfilment, n as WireIssue, o as WireLine, p as WireMoney } from './types-
|
|
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-
|
|
7
|
-
export { b as
|
|
3
|
+
export { A as API_VERSION, E as ErrorDetails, e as MenuReadOptions, M as MenuResource, n as ReadOptions, S as StorageLike, c as StoreResource, Z as Zappie, b as ZappieClientOptions, b as ZappieConfig, f as ZappieErrorCode, d as ZappieEvents, o as createZappie, p as isZappieError } from './client-CtDaenmW.js';
|
|
4
|
+
import { g as CartIssue, a as Quote, b as CartLineInput, C as CartLine, Q as QuoteRequest, h as WireQuote } from './types-DMMeyB5d.js';
|
|
5
|
+
export { i as CartFix, c as CartFulfilment, e as CartIssueCode, d as CartModule, j as CartSnapshot, f as CartState, k as CartSyncAdapter, l as CartSyncDocument, D as DeliveryAddress, m as WireFix, W as WireFulfilment, n as WireIssue, o as WireLine, p as WireMoney } from './types-DMMeyB5d.js';
|
|
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-asoc6fS3.js';
|
|
7
|
+
export { b as BranchCategory, c as Category, d as Choice, e as Currency, F as Formatters, f as Fulfilment, g as MenuSchedule, h as MenuSection, i as MoneyFormatOptions, j as OpeningTime, k as OptionCondition, P as PaymentMethodKind, l as SpecialHours, V as Variant, m as format, n as money } from './models-asoc6fS3.js';
|
|
8
8
|
|
|
9
9
|
declare class ZappieCartError extends ZappieError {
|
|
10
10
|
readonly issues: CartIssue[];
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { ZappieError, isZappieError } from "./errors.js";
|
|
|
11
11
|
export * from "./models.js";
|
|
12
12
|
import { format, money } from "./money.js";
|
|
13
13
|
import { RestTransport } from "./transport/rest.js";
|
|
14
|
-
var VERSION = true ? "0.10.
|
|
14
|
+
var VERSION = true ? "0.10.7" : "0.0.0-development";
|
|
15
15
|
export {
|
|
16
16
|
API_VERSION,
|
|
17
17
|
RestTransport,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RequestCtx } from '../index.js';
|
|
2
|
-
import '../models-
|
|
3
|
-
import '../types-
|
|
2
|
+
import '../models-asoc6fS3.js';
|
|
3
|
+
import '../types-DMMeyB5d.js';
|
|
4
4
|
|
|
5
5
|
/** Public integration IDs and browser keys. Your app decides when to load scripts. */
|
|
6
6
|
type Integrations = {
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CartFulfilment, WireFulfilment } from './index.js';
|
|
2
|
-
export { v as validateConfig } from './client-
|
|
3
|
-
import './models-
|
|
2
|
+
export { v as validateConfig } from './client-CtDaenmW.js';
|
|
3
|
+
import './models-asoc6fS3.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Convert a cart fulfilment selection to the API field names used by quotes and checkout.
|
|
@@ -45,6 +45,8 @@ type SpecialHours = {
|
|
|
45
45
|
opens?: string;
|
|
46
46
|
closes?: string;
|
|
47
47
|
};
|
|
48
|
+
/** What kind of venue a branch is. */
|
|
49
|
+
type BranchCategory = "RESTAURANT" | "RETAIL";
|
|
48
50
|
/** Branch details, opening hours and fulfilment options. */
|
|
49
51
|
type Branch = {
|
|
50
52
|
/** Currency used for this branch's prices. */
|
|
@@ -63,6 +65,12 @@ type Branch = {
|
|
|
63
65
|
timezone?: string;
|
|
64
66
|
address?: string;
|
|
65
67
|
phone?: string;
|
|
68
|
+
/**
|
|
69
|
+
* What kind of venue the branch is. Absent when the API doesn't say, which
|
|
70
|
+
* reads as a restaurant. `inVenueLabel()` from `@zappie/sdk/display` names
|
|
71
|
+
* in-person orders by it.
|
|
72
|
+
*/
|
|
73
|
+
category?: BranchCategory;
|
|
66
74
|
coordinates?: {
|
|
67
75
|
lat: number;
|
|
68
76
|
lng: number;
|
|
@@ -271,5 +279,5 @@ type CategoryPage = {
|
|
|
271
279
|
nextCursor?: string;
|
|
272
280
|
};
|
|
273
281
|
|
|
274
|
-
export { format as
|
|
275
|
-
export type { Branch as B, CategoryPage as C, Formatters as F, Item as I, Money as M, OptionGroup as O, PaymentMethodKind as P, Store as S, Variant as V, Menu as a,
|
|
282
|
+
export { format as m, money as n };
|
|
283
|
+
export type { Branch as B, CategoryPage as C, Formatters as F, Item as I, Money as M, OptionGroup as O, PaymentMethodKind as P, Store as S, Variant as V, Menu as a, BranchCategory as b, Category as c, Choice as d, Currency as e, Fulfilment as f, MenuSchedule as g, MenuSection as h, MoneyFormatOptions as i, OpeningTime as j, OptionCondition as k, SpecialHours as l };
|
package/dist/money.js
CHANGED
|
@@ -4,27 +4,11 @@ var ZERO_DIGIT_CURRENCIES = " AFN ALL BIF CLP DJF GNF IQD IRR ISK JPY KMF KPW KR
|
|
|
4
4
|
var THREE_DIGIT_CURRENCIES = " BHD JOD KWD LYD OMR TND ";
|
|
5
5
|
var FOUR_DIGIT_CURRENCIES = " CLF UYW ";
|
|
6
6
|
var API_ONLY_CURRENCIES = " BOV CHE CHW CLF COU MXV USN UYI UYW VED ";
|
|
7
|
-
var contains = (codes, currency) => codes.includes(
|
|
7
|
+
var contains = (codes, currency) => codes.includes(currency);
|
|
8
8
|
var intlCurrencies;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
if (typeof Intl.supportedValuesOf !== "function") {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
intlCurrencies ?? (intlCurrencies = new Set(Intl.supportedValuesOf("currency")));
|
|
17
|
-
return contains(API_ONLY_CURRENCIES, code) || intlCurrencies.has(code);
|
|
18
|
-
}
|
|
19
|
-
function currencyDigits(currency) {
|
|
20
|
-
if (contains(ZERO_DIGIT_CURRENCIES, currency)) {
|
|
21
|
-
return 0;
|
|
22
|
-
}
|
|
23
|
-
if (contains(THREE_DIGIT_CURRENCIES, currency)) {
|
|
24
|
-
return 3;
|
|
25
|
-
}
|
|
26
|
-
return contains(FOUR_DIGIT_CURRENCIES, currency) ? 4 : 2;
|
|
27
|
-
}
|
|
9
|
+
var isCurrency = (code) => /^[A-Z]{3}$/.test(code) && // Runtimes without Intl.supportedValuesOf accept any three-letter code.
|
|
10
|
+
(!Intl.supportedValuesOf || contains(API_ONLY_CURRENCIES, code) || (intlCurrencies ?? (intlCurrencies = new Set(Intl.supportedValuesOf("currency")))).has(code));
|
|
11
|
+
var currencyDigits = (currency) => contains(ZERO_DIGIT_CURRENCIES, currency) ? 0 : contains(THREE_DIGIT_CURRENCIES, currency) ? 3 : contains(FOUR_DIGIT_CURRENCIES, currency) ? 4 : 2;
|
|
28
12
|
function money(amountMinor, currency) {
|
|
29
13
|
const normalized = typeof currency === "string" ? currency.trim().toUpperCase() : "";
|
|
30
14
|
if (!Number.isSafeInteger(amountMinor) || !isCurrency(normalized)) {
|
|
@@ -35,20 +19,25 @@ function money(amountMinor, currency) {
|
|
|
35
19
|
}
|
|
36
20
|
return Object.freeze({ amountMinor, currency: normalized });
|
|
37
21
|
}
|
|
22
|
+
var formatters = {};
|
|
38
23
|
var format = {
|
|
39
24
|
money(value, opts = {}) {
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
currency:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
25
|
+
const { amountMinor, currency } = money(value.amountMinor, value.currency);
|
|
26
|
+
const digits = currencyDigits(currency);
|
|
27
|
+
const fraction = opts.showZeroDecimals || amountMinor % 10 ** digits ? digits : 0;
|
|
28
|
+
const key = currency + fraction + opts.compact + opts.sign;
|
|
29
|
+
return (formatters[key] ?? (formatters[key] = new Intl.NumberFormat(
|
|
30
|
+
currency === "NGN" ? "en-NG" : "en",
|
|
31
|
+
{
|
|
32
|
+
style: "currency",
|
|
33
|
+
currency,
|
|
34
|
+
currencyDisplay: "narrowSymbol",
|
|
35
|
+
minimumFractionDigits: fraction,
|
|
36
|
+
maximumFractionDigits: digits,
|
|
37
|
+
notation: opts.compact ? "compact" : "standard",
|
|
38
|
+
signDisplay: opts.sign || "auto"
|
|
39
|
+
}
|
|
40
|
+
))).format(amountMinor / 10 ** digits);
|
|
52
41
|
}
|
|
53
42
|
};
|
|
54
43
|
export {
|
package/dist/money.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 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;AACtD,YAAQ,sCAAoB,IAAI,KAAK;AAAA,MACnC,aAAa,QAAQ,UAAU;AAAA,MAC/B;AAAA,QACE,OAAO;AAAA,QACP;AAAA,QACA,iBAAiB;AAAA,QACjB,uBAAuB;AAAA,QACvB,uBAAuB;AAAA,QACvB,UAAU,KAAK,UAAU,YAAY;AAAA,QACrC,aAAa,KAAK,QAAQ;AAAA,MAC5B;AAAA,IACF,IAAG,OAAO,cAAc,MAAM,MAAM;AAAA,EACtC;AACF;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -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-
|
|
2
|
-
import '../models-
|
|
3
|
-
import '../types-
|
|
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-CtDaenmW.js';
|
|
2
|
+
import '../models-asoc6fS3.js';
|
|
3
|
+
import '../types-DMMeyB5d.js';
|
package/dist/pricing/index.d.ts
CHANGED
|
@@ -1,15 +1,33 @@
|
|
|
1
1
|
import { Item, Money } from '@zappie/sdk';
|
|
2
2
|
|
|
3
|
+
/** Choices to narrow an item to, as a cart line names them. */
|
|
4
|
+
type PricedChoices = readonly {
|
|
5
|
+
groupId: string;
|
|
6
|
+
choiceId: string;
|
|
7
|
+
}[];
|
|
3
8
|
/**
|
|
4
9
|
* The lowest price a shopper can pay for one of this item, by the same rule
|
|
5
10
|
* Zappie uses for a product's starting price: the cheapest available variant
|
|
6
|
-
* plus the cheapest
|
|
7
|
-
*
|
|
11
|
+
* plus the cheapest valid choices of each required add-on group. A group that
|
|
12
|
+
* needs exactly or at least four choices adds its four cheapest units. Available
|
|
13
|
+
* choices are used when they can fill the group. When no variant is available,
|
|
14
|
+
* the cheapest variant is used. Optional groups add nothing.
|
|
8
15
|
*
|
|
9
16
|
* @param item - The catalogue item.
|
|
10
17
|
* @returns A display price. Use a server quote for checkout totals.
|
|
11
18
|
*/
|
|
12
19
|
declare function startingPrice(item: Item): Money;
|
|
20
|
+
/**
|
|
21
|
+
* The starting price of this item when the shopper picks from the given choices only, such as
|
|
22
|
+
* the price of one plan length or one size. Each group named in `choices` is narrowed to the
|
|
23
|
+
* named choices, and an attribute group narrows the variants to the ones with that choice. Other
|
|
24
|
+
* groups count as `startingPrice` counts them.
|
|
25
|
+
*
|
|
26
|
+
* @param item - The catalogue item.
|
|
27
|
+
* @param choices - The choices to narrow to, by group and choice ID.
|
|
28
|
+
* @returns A display price. Use a server quote for checkout totals.
|
|
29
|
+
*/
|
|
30
|
+
declare function startingPriceWith(item: Item, choices: PricedChoices): Money;
|
|
13
31
|
/**
|
|
14
32
|
* Whether to show the starting price as "From": true when available variants
|
|
15
33
|
* have different prices, or a required add-on raises the starting price.
|
|
@@ -18,4 +36,5 @@ declare function startingPrice(item: Item): Money;
|
|
|
18
36
|
*/
|
|
19
37
|
declare function showsFromPrice(item: Item): boolean;
|
|
20
38
|
|
|
21
|
-
export { showsFromPrice, startingPrice };
|
|
39
|
+
export { showsFromPrice, startingPrice, startingPriceWith };
|
|
40
|
+
export type { PricedChoices };
|
package/dist/pricing/index.js
CHANGED
|
@@ -1,19 +1,69 @@
|
|
|
1
1
|
// src/pricing/index.ts
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
money,
|
|
4
|
+
ZappieError
|
|
5
|
+
} from "@zappie/sdk";
|
|
6
|
+
var byPrice = (a, b) => a.price.amountMinor - b.price.amountMinor;
|
|
7
|
+
function fill(group, choices) {
|
|
8
|
+
const need = Math.max(group.selection.min, 1);
|
|
9
|
+
const prices = [];
|
|
10
|
+
let count = 0;
|
|
11
|
+
for (const choice of choices.sort(byPrice)) {
|
|
12
|
+
const { min = 1, max = choice.quantity ? Infinity : 1 } = choice.quantity ?? {};
|
|
13
|
+
const units = Math.max(min, Math.min(need - count, max));
|
|
14
|
+
if (count < need && count + units <= (group.selection.max || Infinity)) {
|
|
15
|
+
prices.push(...Array(units).fill(choice.price));
|
|
16
|
+
count += units;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return [prices, count >= need];
|
|
20
|
+
}
|
|
4
21
|
function startingPrice(item) {
|
|
5
22
|
const available = item.variants.filter((variant) => variant.isAvailable);
|
|
6
|
-
const base =
|
|
7
|
-
|
|
8
|
-
|
|
23
|
+
const base = (available.length ? available : item.variants).filter((variant) => variant.price.amountMinor >= 0).sort(byPrice)[0]?.price ?? item.price;
|
|
24
|
+
const prices = item.optionGroups.flatMap((group) => {
|
|
25
|
+
if (group.isAttribute || !group.required || group.kind !== "select") {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const priced = group.choices.filter(
|
|
29
|
+
(choice) => choice.price.amountMinor >= 0
|
|
30
|
+
);
|
|
31
|
+
const [taken, filled] = fill(
|
|
32
|
+
group,
|
|
33
|
+
priced.filter((choice) => choice.isAvailable)
|
|
34
|
+
);
|
|
35
|
+
return filled ? taken : fill(group, priced)[0];
|
|
36
|
+
});
|
|
37
|
+
let total = base.amountMinor;
|
|
38
|
+
for (const price of prices) {
|
|
39
|
+
if (price.currency !== base.currency) {
|
|
40
|
+
throw new ZappieError(
|
|
41
|
+
"invalid_request",
|
|
42
|
+
"Cannot combine different currencies"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
total += price.amountMinor;
|
|
46
|
+
}
|
|
47
|
+
return money(total, base.currency);
|
|
48
|
+
}
|
|
49
|
+
function startingPriceWith(item, choices) {
|
|
50
|
+
const keeps = (groupId, choiceId) => !choices.some((picked) => picked.groupId === groupId) || choices.some(
|
|
51
|
+
(picked) => picked.groupId === groupId && picked.choiceId === choiceId
|
|
52
|
+
);
|
|
53
|
+
const variants = item.variants.filter(
|
|
54
|
+
(variant) => Object.entries(variant.attributeChoices).every(
|
|
55
|
+
([groupId, choiceId]) => keeps(groupId, choiceId)
|
|
9
56
|
)
|
|
10
|
-
) ?? item.price;
|
|
11
|
-
return sumMoney(
|
|
12
|
-
item.optionGroups.flatMap(
|
|
13
|
-
(group) => !group.isAttribute && group.required && group.kind === "select" ? cheapest(group.choices.map((choice) => choice.price)) ?? [] : []
|
|
14
|
-
),
|
|
15
|
-
base
|
|
16
57
|
);
|
|
58
|
+
return startingPrice({
|
|
59
|
+
...item,
|
|
60
|
+
// Choices no variant carries leave the variants as they are.
|
|
61
|
+
variants: variants.length ? variants : item.variants,
|
|
62
|
+
optionGroups: item.optionGroups.map((group) => ({
|
|
63
|
+
...group,
|
|
64
|
+
choices: group.choices.filter((choice) => keeps(group.id, choice.id))
|
|
65
|
+
}))
|
|
66
|
+
});
|
|
17
67
|
}
|
|
18
68
|
function showsFromPrice(item) {
|
|
19
69
|
const prices = [
|
|
@@ -25,6 +75,7 @@ function showsFromPrice(item) {
|
|
|
25
75
|
}
|
|
26
76
|
export {
|
|
27
77
|
showsFromPrice,
|
|
28
|
-
startingPrice
|
|
78
|
+
startingPrice,
|
|
79
|
+
startingPriceWith
|
|
29
80
|
};
|
|
30
81
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/pricing/index.ts"],
|
|
4
|
-
"mappings": ";AAAA,
|
|
4
|
+
"mappings": ";AAGA;AAAA,EACE;AAAA,EACA;AAAA,OAKK;AAKP,IAAM,UAAU,CAAC,GAAqB,MACpC,EAAE,MAAM,cAAc,EAAE,MAAM;AAMhC,SAAS,KAAK,OAAoB,SAAuC;AACvE,QAAM,OAAO,KAAK,IAAI,MAAM,UAAU,KAAK,CAAC;AAC5C,QAAM,SAAkB,CAAC;AACzB,MAAI,QAAQ;AACZ,aAAW,UAAU,QAAQ,KAAK,O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,SAAS,kBAAkB,MAAY,SAA+B;AAC3E,QAAM,QAAQ,CAAC,SAAiB,aAC9B,CAAC,QAAQ,KAAK,CAAC,WAAW,OAAO,YAAY,OAAO,KACpD,QAAQ;AAAA,IACN,CAAC,WAAW,OAAO,YAAY,WAAW,OAAO,aAAa;AAAA,EAChE;AACF,QAAM,WAAW,KAAK,SAAS;AAAA,IAAO,CAAC,YACrC,OAAO,QAAQ,QAAQ,gBAAgB,EAAE;AAAA,MAAM,CAAC,CAAC,SAAS,QAAQ,MAChE,MAAM,SAAS,QAAQ;AAAA,IACzB;AAAA,EACF;AACA,SAAO,cAAc;AAAA,IACnB,GAAG;AAAA;AAAA,IAEH,UAAW,SAAS,SAAS,WAAW,KAAK;AAAA,IAC7C,cAAc,KAAK,aAAa,IAAI,CAAC,WAAW;AAAA,MAC9C,GAAG;AAAA,MACH,SAAS,MAAM,QAAQ,OAAO,CAAC,WAAW,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;AAAA,IACtE,EAAE;AAAA,EACJ,CAAC;AACH;AAQO,SAAS,eAAe,MAAqB;AAClD,QAAM,SAAS;AAAA,IACb,GAAG,IAAI;AAAA,MACL,KAAK,SACF,OAAO,CAAC,YAAY,QAAQ,WAAW,EACvC,IAAI,CAAC,YAAY,QAAQ,MAAM,WAAW;AAAA,IAC/C;AAAA,EACF;AACA,SACE,OAAO,SAAS,KACf,OAAO,WAAW,KAAK,cAAc,IAAI,EAAE,cAAc,OAAO,CAAC;AAEtE;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Branch, Store, Menu, Formatters } from '../index.js';
|
|
2
|
-
import { C as Cache } from '../client-
|
|
2
|
+
import { C as Cache } from '../client-CtDaenmW.js';
|
|
3
3
|
import { ZappieError, Zappie, ZappieConfig, Transport, StorageLike, StoreResource, MenuResource, ZappieEvents, MenuReadOptions } 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,4 +1,4 @@
|
|
|
1
|
-
import { C as Cache } from '../client-
|
|
1
|
+
import { C as Cache } from '../client-CtDaenmW.js';
|
|
2
2
|
import { Transport, ZappieErrorCode, StorageLike, StoreResource, MenuResource, ZappieEvents, MenuReadOptions } from '../index.js';
|
|
3
3
|
import { Store, Menu, Formatters } from '../index.js';
|
|
4
4
|
export { VERSION } from '../index.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Menu } from '../index.js';
|
|
2
2
|
import { SearchRequest, SearchPage } from '../index.js';
|
|
3
|
-
import '../types-
|
|
3
|
+
import '../types-DMMeyB5d.js';
|
|
4
4
|
|
|
5
5
|
/** Loaded only when search is used; request authentication/retries stay in REST. */
|
|
6
6
|
declare function searchPage(ctx: SearchRequest, read: (path: string) => Promise<unknown>, mapMenu: (value: unknown, branchId: string) => Menu, invalid: () => Error): Promise<SearchPage>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { z as SelectedMenu, i as SelectedMenuRequest, j as SelectedMenuResponse, B as SelectedMenuTransport, D as createSelectedMenuReader, F as selectedMenu, G as selectedMenuKey } from '../client-
|
|
2
|
-
import '../models-
|
|
3
|
-
import '../types-
|
|
1
|
+
export { z as SelectedMenu, i as SelectedMenuRequest, j as SelectedMenuResponse, B as SelectedMenuTransport, D as createSelectedMenuReader, F as selectedMenu, G as selectedMenuKey } from '../client-CtDaenmW.js';
|
|
2
|
+
import '../models-asoc6fS3.js';
|
|
3
|
+
import '../types-DMMeyB5d.js';
|
package/dist/transport/store.js
CHANGED
|
@@ -47,6 +47,8 @@ function mapStore(value, record, text, list, hours, mapMoney, money, opt, isStri
|
|
|
47
47
|
fulfilment: fulfilment(branch.fulfilment),
|
|
48
48
|
...address !== void 0 ? { address } : {},
|
|
49
49
|
...isString(branch.phone) ? { phone: branch.phone.trim() } : {},
|
|
50
|
+
// A category the SDK doesn't know yet is left out, so it reads as a restaurant.
|
|
51
|
+
...branch.category === "RESTAURANT" || branch.category === "RETAIL" ? { category: branch.category } : {},
|
|
50
52
|
...opt("timezone", branch.timezone, isString),
|
|
51
53
|
...branchCoordinates ? { coordinates: branchCoordinates } : {},
|
|
52
54
|
...opt("closedUntil", branch.closed_until, isString),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/transport/store.ts"],
|
|
4
|
-
"mappings": ";AAWO,SAAS,SACd,OACA,QACA,MACA,MACA,OACA,UACA,OACA,KACA,UACA,WACA,QACO;AACP,QAAM,cAAc,CAAC,UAAmB;AACtC,UAAMA,eAAc,OAAO,SAAS,CAAC,CAAC;AACtC,WAAO,OAAOA,aAAY,QAAQ,YAChC,OAAOA,aAAY,QAAQ,WACzB,EAAE,KAAKA,aAAY,KAAK,KAAKA,aAAY,IAAI,IAC7C;AAAA,EACN;AACA,QAAM,aAAa,CAAC,UAA+B;AACjD,UAAMC,SAAQ,OAAO,KAAK;AAC1B,WAAO;AAAA,MACL,QAAQA,OAAM,WAAW;AAAA,MACzB,UAAUA,OAAM,aAAa;AAAA,MAC7B,QAAQA,OAAM,YAAY;AAAA,MAC1B,YAAYA,OAAM,cAAc;AAAA,IAClC;AAAA,EACF;AACA,QAAM,SAAS,OAAO,KAAK;AAC3B,QAAM,QAAQ,OAAO,OAAO,SAAS,CAAC,CAAC;AACvC,QAAM,WAAqB,KAAK,OAAO,QAAQ,EAAE,IAAI,CAAC,QAAQ;AAC5D,UAAM,SAAS,OAAO,GAAG;AACzB,UAAM,SAAS,OAAO,OAAO,kBAAkB,CAAC,CAAC;AACjD,UAAM,oBAAoB,YAAY,OAAO,WAAW;AACxD,UAAM,gBAAgB;AAAA,MACpB,GAAG,IAAI,WAAW,OAAO,UAAU,QAAQ;AAAA,MAC3C,GAAI,oBAAoB,EAAE,aAAa,kBAAkB,IAAI,CAAC;AAA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WAAW,GAAG;AAAA,IAC1C;AAAA,EACF;AACA,QAAM,mBAAmB,OAAO,OAAO,qBAAqB,CAAC,CAAC;AAI9D,SAAO;AAAA,IACL,GAAI,OAAO,OAAO,OAAO,EAAE,KAAK,OAAO,OAAO,GAAG,EAAE,IAAI,CAAC;AAAA,IACxD,IAAI,KAAK,OAAO,EAAE;AAAA,IAClB,MAAM,KAAK,OAAO,IAAI;AAAA,IACtB,MAAM,KAAK,OAAO,IAAI;AAAA,IACtB,UAAU,MAAM,GAAG,KAAK,OAAO,QAAQ,CAAa,EAAE;AAAA,IACtD,UAAU,KAAK,OAAO,QAAQ;AAAA,IAC9B,GAAG,IAAI,eAAe,OAAO,aAAa,QAAQ;AAAA,IAClD,GAAI,OAAO,sBAAsB,SAAY,EAAE,iBAAiB,IAAI,CAAC;AAAA,IACrE,OAAO;AAAA,MACL,GAAG,IAAI,WAAW,MAAM,UAAU,QAAQ;AAAA,MAC1C,GAAG,IAAI,iBAAiB,MAAM,iBAAiB,QAAQ;AAAA,IACzD;AAAA,IACA,YAAY,OAAO,aAAa,WAAW,OAAO,UAAU,IAAI;AAAA,IAChE;AAAA,IACA;AAAA,EACF;AACF;",
|
|
5
5
|
"names": ["coordinates", "value", "raw"]
|
|
6
6
|
}
|
package/dist/visits/index.d.ts
CHANGED
|
@@ -17,9 +17,11 @@ type PageView = {
|
|
|
17
17
|
step: boolean;
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
|
-
* Supported visit events: adding an item
|
|
20
|
+
* Supported visit events: adding an item, viewing the bag, and pressing Pay. `checkout` is the
|
|
21
|
+
* funnel's checkout step, the same step a `/checkout` page view reaches, so count it when the
|
|
22
|
+
* shopper activates Pay in the bag or on a cart page.
|
|
21
23
|
*/
|
|
22
|
-
type VisitEventName = "add" | "bag";
|
|
24
|
+
type VisitEventName = "add" | "bag" | "checkout";
|
|
23
25
|
/**
|
|
24
26
|
* A visit event with its path, attribution and whether this event is a new step.
|
|
25
27
|
*/
|
|
@@ -73,7 +75,7 @@ type CountPageInput = Omit<PageViewInput, "storage"> & {
|
|
|
73
75
|
*/
|
|
74
76
|
declare function countPage(input: CountPageInput): void;
|
|
75
77
|
/**
|
|
76
|
-
* Send an add or
|
|
78
|
+
* Send an add, bag or checkout event for the current path after countPage has enabled counting.
|
|
77
79
|
* Does nothing without a browser window or sendBeacon support.
|
|
78
80
|
*/
|
|
79
81
|
declare function countEvent(event: VisitEventName): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/visits/page-views.ts"],
|
|
4
|
-
"mappings": ";AAAA,IAAM,YAAY;
|
|
4
|
+
"mappings": ";AAAA,IAAM,YAAY;AAsDlB,SAAS,OAAO,SAAqC;AACnD,MAAI;AACF,UAAM,MAAM,QAAQ,QAAQ,SAAS;AACrC,QAAI,KAAK;AACP,aAAO,KAAK,MAAM,GAAG;AAAA,IACvB;AACA,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,KAAK,SAAuB,OAAoB;AACvD,MAAI;AACF,YAAQ,QAAQ,WAAW,KAAK,UAAU,KAAK,CAAC;AAAA,EAClD,QAAQ;AAAA,EAER;AACF;AAEA,SAAS,OAAO,MAAsB;AACpC,MAAI,SAAS,KAAK;AAChB,WAAO;AAAA,EACT;AACA,MAAI,KAAK,WAAW,QAAQ,GAAG;AAC7B,WAAO;AAAA,EACT;AACA,MAAI,SAAS,SAAS;AACpB,WAAO;AAAA,EACT;AACA,MAAI,SAAS,aAAa;AACxB,WAAO;AAAA,EACT;AACA,MAAI,KAAK,WAAW,YAAY,GAAG;AACjC,WAAO;AAAA,EACT;AACA,MAAI,KAAK,WAAW,SAAS,GAAG;AAC9B,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,SAAS,QAAQ,SAAuB,OAAc,MAAuB;AAC3E,QAAM,QAAQ,MAAM,SAAS,CAAC;AAC9B,MAAI,MAAM,SAAS,I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O,OAAO;AAC5B,SAAO;AAAA,IACL,QAAQ,OAAO,UAAU;AAAA,IACzB,UAAU,OAAO,YAAY;AAAA,EAC/B;AACF;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zappie/sdk",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.7",
|
|
4
4
|
"description": "Typed, framework-agnostic client for Zappie menus, carts, checkout, auth and events.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -97,6 +97,10 @@
|
|
|
97
97
|
"types": "./dist/pricing/index.d.ts",
|
|
98
98
|
"import": "./dist/pricing/index.js"
|
|
99
99
|
},
|
|
100
|
+
"./display": {
|
|
101
|
+
"types": "./dist/display/index.d.ts",
|
|
102
|
+
"import": "./dist/display/index.js"
|
|
103
|
+
},
|
|
100
104
|
"./branches": {
|
|
101
105
|
"types": "./dist/branches/index.d.ts",
|
|
102
106
|
"import": "./dist/branches/index.js"
|
|
@@ -172,7 +176,7 @@
|
|
|
172
176
|
"vite": "8.3.5"
|
|
173
177
|
},
|
|
174
178
|
"scripts": {
|
|
175
|
-
"build": "tsup && tsup --config tsup.checkout.config.ts && tsup --config tsup.checkout-defaults.config.ts && tsup --config tsup.customer.config.ts && tsup --config tsup.account.config.ts && tsup --config tsup.places.config.ts && tsup --config tsup.url.config.ts && tsup --config tsup.redirect.config.ts && tsup --config tsup.navigation.config.ts && tsup --config tsup.services.config.ts && tsup --config tsup.visits.config.ts && tsup --config tsup.pricing.config.ts && tsup --config tsup.branches.config.ts && tsup --config tsup.options.config.ts && tsup --config tsup.site-config.config.ts && tsup --config tsup.template.config.ts && node ../../scripts/release-packages/build-modules.mjs --no-sources-content --unmapped=studio/index.js --unmapped=testing/index.js --unmapped=vite/index.js",
|
|
179
|
+
"build": "tsup && tsup --config tsup.checkout.config.ts && tsup --config tsup.checkout-defaults.config.ts && tsup --config tsup.customer.config.ts && tsup --config tsup.account.config.ts && tsup --config tsup.places.config.ts && tsup --config tsup.url.config.ts && tsup --config tsup.redirect.config.ts && tsup --config tsup.navigation.config.ts && tsup --config tsup.services.config.ts && tsup --config tsup.visits.config.ts && tsup --config tsup.pricing.config.ts && tsup --config tsup.display.config.ts && tsup --config tsup.branches.config.ts && tsup --config tsup.options.config.ts && tsup --config tsup.site-config.config.ts && tsup --config tsup.template.config.ts && node ../../scripts/release-packages/build-modules.mjs --no-sources-content --unmapped=studio/index.js --unmapped=testing/index.js --unmapped=vite/index.js",
|
|
176
180
|
"test": "vitest run --root ../.. packages/sdk/test",
|
|
177
181
|
"size": "node ../../scripts/release-packages/size-sdk.mjs && size-limit"
|
|
178
182
|
}
|