@zappie/sdk 0.28.2 → 0.29.1
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/dist/account/index.d.ts +16 -2
- package/dist/account/index.js +0 -1
- package/dist/account/url.js +0 -1
- package/dist/branches/index.d.ts +2 -0
- package/dist/branches/index.js +0 -1
- package/dist/cart/branch.d.ts +18 -0
- package/dist/cart/branch.js +0 -1
- package/dist/cart/errors.js +0 -1
- package/dist/cart/held.js +0 -1
- package/dist/cart/index.js +1 -2
- package/dist/cart/item.d.ts +1 -1
- package/dist/cart/item.js +0 -1
- package/dist/cart/preview.js +0 -1
- package/dist/cart/price.js +0 -1
- package/dist/cart/quote-client.js +0 -1
- package/dist/cart/quote-response.js +1 -2
- package/dist/cart/quote.d.ts +1 -1
- package/dist/cart/reconcile.js +0 -1
- package/dist/cart/source-menu.js +0 -1
- package/dist/cart/storage.js +0 -1
- package/dist/cart/types.js +0 -1
- package/dist/cart/validate.js +0 -1
- package/dist/cart/wire.js +0 -1
- package/dist/cart/working-set.js +0 -1
- package/dist/checkout/client.js +0 -1
- package/dist/checkout/embed.d.ts +67 -2
- package/dist/checkout/embed.js +0 -1
- package/dist/checkout/error.js +0 -1
- package/dist/checkout/index.d.ts +74 -3
- package/dist/checkout/index.js +0 -1
- package/dist/checkout/react.d.ts +67 -2
- package/dist/checkout/react.js +0 -1
- package/dist/checkout/readiness.js +0 -1
- package/dist/checkout/sdk.js +0 -1
- package/dist/checkout/session.js +0 -1
- package/dist/checkout/types.js +0 -1
- package/dist/checkout-defaults/index.d.ts +10 -1
- package/dist/checkout-defaults/index.js +0 -1
- package/dist/{client-B89-aNcl.d.ts → client-CW_OWZ0l.d.ts} +229 -5
- package/dist/client.js +0 -1
- package/dist/config/index.d.ts +38 -3
- package/dist/config/index.js +0 -1
- package/dist/config.js +0 -1
- package/dist/customer/client.js +0 -1
- package/dist/customer/error.js +0 -1
- package/dist/customer/index.d.ts +180 -5
- package/dist/customer/index.js +0 -1
- package/dist/customer/navigation.js +0 -1
- package/dist/customer/react.js +0 -1
- package/dist/customer/reorder.d.ts +8 -0
- package/dist/customer/reorder.js +0 -1
- package/dist/customer/request.js +0 -1
- package/dist/customer/types.js +0 -1
- package/dist/customer/watch-order.js +0 -1
- package/dist/debug.js +1 -2
- package/dist/display/index.d.ts +5 -1
- package/dist/display/index.js +0 -1
- package/dist/error-pages/art.js +0 -1
- package/dist/error-pages/index.d.ts +12 -1
- package/dist/error-pages/index.js +0 -1
- package/dist/error-pages/react.js +0 -1
- package/dist/errors.js +1 -2
- package/dist/in-venue/bill.js +0 -1
- package/dist/in-venue/client.js +0 -1
- package/dist/in-venue/error.js +0 -1
- package/dist/in-venue/index.d.ts +110 -2
- package/dist/in-venue/index.js +0 -1
- package/dist/in-venue/react/bill-page.js +0 -1
- package/dist/in-venue/react/in-venue-page.js +0 -1
- package/dist/in-venue/react/order-panel.js +0 -1
- package/dist/in-venue/react/pay-point-page.js +0 -1
- package/dist/in-venue/react/shared.js +0 -1
- package/dist/in-venue/react/table-menus-page.js +0 -1
- package/dist/in-venue/react.js +0 -1
- package/dist/in-venue/table.js +0 -1
- package/dist/in-venue/types.js +0 -1
- package/dist/in-venue/watch.js +0 -1
- package/dist/index.d.ts +32 -8
- package/dist/index.js +1 -2
- package/dist/integrations/index.d.ts +15 -2
- package/dist/integrations/index.js +0 -1
- package/dist/internal/abort.js +0 -1
- package/dist/internal/cache.js +0 -1
- package/dist/internal/customer-http.js +1 -2
- package/dist/internal/emitter.js +0 -1
- package/dist/internal/image-widths.js +0 -1
- package/dist/internal/money-math.js +0 -1
- package/dist/internal/perk-hold.js +0 -1
- package/dist/internal/remembered-address.js +0 -1
- package/dist/internal/return-path.js +0 -1
- package/dist/internal/service-url.js +0 -1
- package/dist/internal.d.ts +2 -2
- package/dist/internal.js +0 -1
- package/dist/loyalty/cart.js +0 -1
- package/dist/loyalty/client.js +0 -1
- package/dist/loyalty/index.d.ts +410 -2
- package/dist/loyalty/index.js +0 -1
- package/dist/loyalty/react.d.ts +15 -1
- package/dist/loyalty/react.js +0 -1
- package/dist/loyalty/release.js +0 -1
- package/dist/loyalty/types.js +0 -1
- package/dist/menu/index.d.ts +5 -1
- package/dist/menu/index.js +0 -1
- package/dist/models-C77LjkK8.d.ts +540 -0
- package/dist/models.js +0 -1
- package/dist/money.js +0 -1
- package/dist/navigation/index.d.ts +8 -0
- package/dist/navigation/index.js +0 -1
- package/dist/navigation/react.js +0 -1
- package/dist/navigation-progress/index.js +0 -1
- package/dist/options/index.d.ts +5 -1
- package/dist/options/index.js +0 -1
- package/dist/persist/catalogue.d.ts +3 -3
- package/dist/persist/catalogue.js +0 -1
- package/dist/places/client.js +0 -1
- package/dist/places/error.js +0 -1
- package/dist/places/index.d.ts +41 -1
- package/dist/places/index.js +0 -1
- package/dist/places/request.js +0 -1
- package/dist/places/sdk.js +0 -1
- package/dist/places/search.js +0 -1
- package/dist/places/types.js +0 -1
- package/dist/pricing/index.js +0 -1
- package/dist/react/cart.js +0 -1
- package/dist/react/changes.js +0 -1
- package/dist/react/hooks.js +0 -1
- package/dist/react/index.js +0 -1
- package/dist/react/provider.js +0 -1
- package/dist/react/rollback.js +0 -1
- package/dist/receipts/index.js +1 -2
- package/dist/redirect/index.js +0 -1
- package/dist/rich-text/index.d.ts +4 -0
- package/dist/rich-text/index.js +0 -1
- package/dist/server/auth/crypto.js +0 -1
- package/dist/server/auth/jwt.js +0 -1
- package/dist/server/auth/session-store.js +0 -1
- package/dist/server/chosen-branch.js +0 -1
- package/dist/server/edge-cache.js +0 -1
- package/dist/server/edge-snapshot.js +0 -1
- package/dist/server/index.d.ts +179 -8
- package/dist/server/index.js +0 -1
- package/dist/server/legacy-order.js +0 -1
- package/dist/server/page-cache.js +0 -1
- package/dist/server/security.js +0 -1
- package/dist/server/sign-in.js +0 -1
- package/dist/server/site-seo.js +0 -1
- package/dist/server/site-worker.js +0 -1
- package/dist/server/storefront-url/build-v1.js +0 -1
- package/dist/server/storefront-url/build-v2.js +0 -1
- package/dist/server/storefront-url/build.js +0 -1
- package/dist/server/storefront-url/canonical.js +0 -1
- package/dist/server/storefront-url/contract.js +0 -1
- package/dist/server/storefront-url/index.js +0 -1
- package/dist/server/storefront-url/installation.js +0 -1
- package/dist/server/storefront-url/params.js +0 -1
- package/dist/server/storefront-url/parse-v1.js +0 -1
- package/dist/server/storefront-url/parse-v2.js +0 -1
- package/dist/server/storefront-url/parse.js +0 -1
- package/dist/server/storefront-url/public-id.js +0 -1
- package/dist/server/storefront-url/redirect.js +0 -1
- package/dist/server/storefront-url/sign-in.js +0 -1
- package/dist/server/storefront-url/types.js +0 -1
- package/dist/server/storefront-url/url.js +0 -1
- package/dist/server/webhook.js +0 -1
- package/dist/services/index.d.ts +5 -1
- package/dist/services/index.js +0 -1
- package/dist/site-closed/index.d.ts +3 -0
- package/dist/site-closed/index.js +0 -1
- package/dist/site-config/helpers.js +0 -1
- package/dist/site-config/sections.js +0 -1
- package/dist/site-config/types.js +0 -1
- package/dist/site-config/validate.js +0 -1
- package/dist/site-error/index.d.ts +9 -1
- package/dist/site-error/index.js +0 -1
- package/dist/site-error/react.js +0 -1
- package/dist/studio/index.d.ts +2 -0
- package/dist/template/index.d.ts +7 -1
- package/dist/template/index.js +0 -1
- package/dist/template/react.js +0 -1
- package/dist/testing/index.d.ts +28 -1
- package/dist/testing/index.js +1 -1
- package/dist/testing/loyalty.js +0 -1
- package/dist/transport/category-page.js +0 -1
- package/dist/transport/mappers.js +0 -1
- package/dist/transport/presentation.js +0 -1
- package/dist/transport/quote-body.js +0 -1
- package/dist/transport/rest.js +0 -1
- package/dist/transport/search.d.ts +1 -1
- package/dist/transport/search.js +0 -1
- package/dist/transport/selected-menu.d.ts +3 -3
- package/dist/transport/selected-menu.js +0 -1
- package/dist/transport/store.js +0 -1
- package/dist/transport/types.js +0 -1
- package/dist/types-CuPaBf6k.d.ts +838 -0
- package/dist/uploads/index.js +0 -1
- package/dist/url/index.d.ts +31 -0
- package/dist/url/index.js +0 -1
- package/dist/visits/index.d.ts +26 -1
- package/dist/visits/index.js +0 -1
- package/dist/visits/page-views.js +0 -1
- package/dist/vite/index.d.ts +2 -0
- package/package.json +2 -2
- package/dist/account/index.js.map +0 -6
- package/dist/account/url.js.map +0 -6
- package/dist/branches/index.js.map +0 -6
- package/dist/cart/branch.js.map +0 -6
- package/dist/cart/errors.js.map +0 -6
- package/dist/cart/held.js.map +0 -6
- package/dist/cart/index.js.map +0 -6
- package/dist/cart/item.js.map +0 -6
- package/dist/cart/preview.js.map +0 -6
- package/dist/cart/price.js.map +0 -6
- package/dist/cart/quote-client.js.map +0 -6
- package/dist/cart/quote-response.js.map +0 -6
- package/dist/cart/reconcile.js.map +0 -6
- package/dist/cart/source-menu.js.map +0 -6
- package/dist/cart/storage.js.map +0 -6
- package/dist/cart/types.js.map +0 -6
- package/dist/cart/validate.js.map +0 -6
- package/dist/cart/wire.js.map +0 -6
- package/dist/cart/working-set.js.map +0 -6
- package/dist/checkout/client.js.map +0 -6
- package/dist/checkout/embed.js.map +0 -6
- package/dist/checkout/error.js.map +0 -6
- package/dist/checkout/index.js.map +0 -6
- package/dist/checkout/react.js.map +0 -6
- package/dist/checkout/readiness.js.map +0 -6
- package/dist/checkout/sdk.js.map +0 -6
- package/dist/checkout/session.js.map +0 -6
- package/dist/checkout/types.js.map +0 -6
- package/dist/checkout-defaults/index.js.map +0 -6
- package/dist/client.js.map +0 -6
- package/dist/config/index.js.map +0 -6
- package/dist/config.js.map +0 -6
- package/dist/customer/client.js.map +0 -6
- package/dist/customer/error.js.map +0 -6
- package/dist/customer/index.js.map +0 -6
- package/dist/customer/navigation.js.map +0 -6
- package/dist/customer/react.js.map +0 -6
- package/dist/customer/reorder.js.map +0 -6
- package/dist/customer/request.js.map +0 -6
- package/dist/customer/types.js.map +0 -6
- package/dist/customer/watch-order.js.map +0 -6
- package/dist/debug.js.map +0 -6
- package/dist/display/index.js.map +0 -6
- package/dist/error-pages/art.js.map +0 -6
- package/dist/error-pages/index.js.map +0 -6
- package/dist/error-pages/react.js.map +0 -6
- package/dist/errors.js.map +0 -6
- package/dist/in-venue/bill.js.map +0 -6
- package/dist/in-venue/client.js.map +0 -6
- package/dist/in-venue/error.js.map +0 -6
- package/dist/in-venue/index.js.map +0 -6
- package/dist/in-venue/react/bill-page.js.map +0 -6
- package/dist/in-venue/react/in-venue-page.js.map +0 -6
- package/dist/in-venue/react/order-panel.js.map +0 -6
- package/dist/in-venue/react/pay-point-page.js.map +0 -6
- package/dist/in-venue/react/shared.js.map +0 -6
- package/dist/in-venue/react/table-menus-page.js.map +0 -6
- package/dist/in-venue/react.js.map +0 -6
- package/dist/in-venue/table.js.map +0 -6
- package/dist/in-venue/types.js.map +0 -6
- package/dist/in-venue/watch.js.map +0 -6
- package/dist/index.js.map +0 -6
- package/dist/integrations/index.js.map +0 -6
- package/dist/internal/abort.js.map +0 -6
- package/dist/internal/cache.js.map +0 -6
- package/dist/internal/customer-http.js.map +0 -6
- package/dist/internal/emitter.js.map +0 -6
- package/dist/internal/image-widths.js.map +0 -6
- package/dist/internal/money-math.js.map +0 -6
- package/dist/internal/perk-hold.js.map +0 -6
- package/dist/internal/remembered-address.js.map +0 -6
- package/dist/internal/return-path.js.map +0 -6
- package/dist/internal/service-url.js.map +0 -6
- package/dist/internal.js.map +0 -6
- package/dist/loyalty/cart.js.map +0 -6
- package/dist/loyalty/client.js.map +0 -6
- package/dist/loyalty/index.js.map +0 -6
- package/dist/loyalty/react.js.map +0 -6
- package/dist/loyalty/release.js.map +0 -6
- package/dist/loyalty/types.js.map +0 -6
- package/dist/menu/index.js.map +0 -6
- package/dist/models-DLGs3UI2.d.ts +0 -307
- package/dist/models.js.map +0 -6
- package/dist/money.js.map +0 -6
- package/dist/navigation/index.js.map +0 -6
- package/dist/navigation/react.js.map +0 -6
- package/dist/navigation-progress/index.js.map +0 -6
- package/dist/options/index.js.map +0 -6
- package/dist/persist/catalogue.js.map +0 -6
- package/dist/places/client.js.map +0 -6
- package/dist/places/error.js.map +0 -6
- package/dist/places/index.js.map +0 -6
- package/dist/places/request.js.map +0 -6
- package/dist/places/sdk.js.map +0 -6
- package/dist/places/search.js.map +0 -6
- package/dist/places/types.js.map +0 -6
- package/dist/pricing/index.js.map +0 -6
- package/dist/react/cart.js.map +0 -6
- package/dist/react/changes.js.map +0 -6
- package/dist/react/hooks.js.map +0 -6
- package/dist/react/index.js.map +0 -6
- package/dist/react/provider.js.map +0 -6
- package/dist/react/rollback.js.map +0 -6
- package/dist/receipts/index.js.map +0 -6
- package/dist/redirect/index.js.map +0 -6
- package/dist/rich-text/index.js.map +0 -6
- package/dist/server/auth/crypto.js.map +0 -6
- package/dist/server/auth/jwt.js.map +0 -6
- package/dist/server/auth/session-store.js.map +0 -6
- package/dist/server/chosen-branch.js.map +0 -6
- package/dist/server/edge-cache.js.map +0 -6
- package/dist/server/edge-snapshot.js.map +0 -6
- package/dist/server/index.js.map +0 -6
- package/dist/server/legacy-order.js.map +0 -6
- package/dist/server/page-cache.js.map +0 -6
- package/dist/server/security.js.map +0 -6
- package/dist/server/sign-in.js.map +0 -6
- package/dist/server/site-seo.js.map +0 -6
- package/dist/server/site-worker.js.map +0 -6
- package/dist/server/storefront-url/build-v1.js.map +0 -6
- package/dist/server/storefront-url/build-v2.js.map +0 -6
- package/dist/server/storefront-url/build.js.map +0 -6
- package/dist/server/storefront-url/canonical.js.map +0 -6
- package/dist/server/storefront-url/contract.js.map +0 -6
- package/dist/server/storefront-url/index.js.map +0 -6
- package/dist/server/storefront-url/installation.js.map +0 -6
- package/dist/server/storefront-url/params.js.map +0 -6
- package/dist/server/storefront-url/parse-v1.js.map +0 -6
- package/dist/server/storefront-url/parse-v2.js.map +0 -6
- package/dist/server/storefront-url/parse.js.map +0 -6
- package/dist/server/storefront-url/public-id.js.map +0 -6
- package/dist/server/storefront-url/redirect.js.map +0 -6
- package/dist/server/storefront-url/sign-in.js.map +0 -6
- package/dist/server/storefront-url/types.js.map +0 -6
- package/dist/server/storefront-url/url.js.map +0 -6
- package/dist/server/webhook.js.map +0 -6
- package/dist/services/index.js.map +0 -6
- package/dist/site-closed/index.js.map +0 -6
- package/dist/site-config/helpers.js.map +0 -6
- package/dist/site-config/sections.js.map +0 -6
- package/dist/site-config/types.js.map +0 -6
- package/dist/site-config/validate.js.map +0 -6
- package/dist/site-error/index.js.map +0 -6
- package/dist/site-error/react.js.map +0 -6
- package/dist/template/index.js.map +0 -6
- package/dist/template/react.js.map +0 -6
- package/dist/testing/loyalty.js.map +0 -6
- package/dist/transport/category-page.js.map +0 -6
- package/dist/transport/mappers.js.map +0 -6
- package/dist/transport/presentation.js.map +0 -6
- package/dist/transport/quote-body.js.map +0 -6
- package/dist/transport/rest.js.map +0 -6
- package/dist/transport/search.js.map +0 -6
- package/dist/transport/selected-menu.js.map +0 -6
- package/dist/transport/store.js.map +0 -6
- package/dist/transport/types.js.map +0 -6
- package/dist/types-8HB4-7D9.d.ts +0 -457
- package/dist/uploads/index.js.map +0 -6
- package/dist/url/index.js.map +0 -6
- package/dist/visits/index.js.map +0 -6
- package/dist/visits/page-views.js.map +0 -6
package/dist/loyalty/index.js
CHANGED
package/dist/loyalty/react.d.ts
CHANGED
|
@@ -9,7 +9,9 @@ type Currency = string;
|
|
|
9
9
|
* An API monetary amount in minor units with its currency code.
|
|
10
10
|
*/
|
|
11
11
|
type WireMoney = {
|
|
12
|
+
/** The amount in minor units of the currency, such as kobo or cents. */
|
|
12
13
|
amount_minor: number;
|
|
14
|
+
/** The ISO 4217 currency code. */
|
|
13
15
|
currency: Currency;
|
|
14
16
|
};
|
|
15
17
|
|
|
@@ -27,7 +29,19 @@ declare function useLoyaltyClient(): LoyaltyClient;
|
|
|
27
29
|
* customer, and `scope_required` when the shopper signed in before rewards needed their
|
|
28
30
|
* permission: offer `signInAgain`.
|
|
29
31
|
*/
|
|
30
|
-
type LoyaltyStatus =
|
|
32
|
+
type LoyaltyStatus =
|
|
33
|
+
/** The read hasn't answered yet. A read turned off with `enabled: false` stays here. */
|
|
34
|
+
"loading"
|
|
35
|
+
/** The read succeeded and its data is there. */
|
|
36
|
+
| "ready"
|
|
37
|
+
/** The API answered `feature_off` or `loyalty_off`: the business has loyalty turned off. */
|
|
38
|
+
| "off"
|
|
39
|
+
/** The API answered 401: no customer is signed in. */
|
|
40
|
+
| "signed_out"
|
|
41
|
+
/** The shopper signed in before rewards needed their permission. Offer `signInAgain`. */
|
|
42
|
+
| "scope_required"
|
|
43
|
+
/** Any other failure. The hook's `error` holds it. */
|
|
44
|
+
| "error";
|
|
31
45
|
/** The status a loyalty failure means, from its HTTP status and the API's code. */
|
|
32
46
|
declare function loyaltyStatus(error: unknown): LoyaltyStatus;
|
|
33
47
|
/** Sign in once more, so the site may use rewards, and come back to this page. */
|
package/dist/loyalty/react.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
"use client";import{applyPerk,createLoyalty,removePerk}from"@zappie/sdk/loyalty";import{useCart}from"@zappie/sdk/react";import{createContext,useCallback,useContext,useEffect,useRef,useState}from"react";import{currentPath,leaveTo,safeReturnTo}from"../customer/navigation.js";import{jsx}from"react/jsx-runtime";var Context=createContext(null);var shared;function LoyaltyProvider({client,children}){return jsx(Context.Provider,{value:client,children})}function useLoyaltyClient(){return useContext(Context)??(shared??(shared=createLoyalty()))}function loyaltyStatus(error){const{status,apiCode}=error??{};return status===401?"signed_out":apiCode==="scope_required"?"scope_required":apiCode==="feature_off"||apiCode==="loyalty_off"?"off":"error"}function signInAgain(returnTo){leaveTo(`/_zappie/login?return=${encodeURIComponent(safeReturnTo(returnTo??currentPath()))}`)}function useRead(key,load){const client=useLoyaltyClient();const[state,setState]=useState({status:"loading"});const[round,setRound]=useState(0);const loader=useRef(load);loader.current=load;useEffect(()=>{if(key===void 0){return}let active=true;const run=()=>{loader.current(client).then(data=>{if(active){setState({key,status:"ready",data})}},error=>{if(active){setState({key,status:loyaltyStatus(error),error})}})};run();const stop=client.onChange(run);return()=>{active=false;stop()}},[client,key,round]);const refresh=useCallback(()=>setRound(value=>value+1),[]);return state.key===key?{status:state.status,data:state.data,error:state.error,refresh}:{status:"loading",refresh}}function useLoyalty(options={}){const read=useRead(options.enabled===false?void 0:"points",client=>client.points());return{status:read.status,enabled:read.status==="ready"&&read.data.enabled,points:read.data?.points,error:read.error,refresh:read.refresh,signInAgain}}function usePerks(branchId){const read=useRead(branchId===void 0?void 0:`perks:${branchId}`,client=>client.perks(branchId));return{status:read.status,perks:read.data??[],error:read.error,refresh:read.refresh}}function useStoreCredit(branchId){const read=useRead(branchId===void 0?void 0:`credit:${branchId}`,client=>client.storeCredit(branchId));return{status:read.status,enabled:read.status==="ready"&&read.data.enabled,balance:read.data?.balance,error:read.error}}var claiming=new Set;function claimedKey(orderId){return`zappie:loyalty-claim:${orderId}`}function useClaimPoints(orderId,options){const client=useLoyaltyClient();const[earned,setEarned]=useState();useEffect(()=>{if(!orderId||!options.paid||claiming.has(orderId)){return}try{if(sessionStorage.getItem(claimedKey(orderId))){return}}catch{}claiming.add(orderId);client.claim(orderId).then(claim=>{try{sessionStorage.setItem(claimedKey(orderId),"1")}catch{}if(claim.points_earned>0){setEarned({orderId,points:claim.points_earned})}},()=>{claiming.delete(orderId)})},[client,orderId,options.paid]);const dismiss=useCallback(()=>setEarned(void 0),[]);return{pointsEarned:earned?.orderId===orderId?earned?.points:void 0,dismiss}}function useCartPerks(){const client=useLoyaltyClient();const cart=useCart();const[busy,setBusy]=useState();const[error,setError]=useState();const running=useRef(false);const run=useCallback(async(target,action)=>{if(running.current){return void 0}running.current=true;setBusy(target);setError(void 0);try{return await action()}catch(failure){setError(failure);return void 0}finally{running.current=false;setBusy(void 0)}},[]);return{perks:cart.perks,busy,error,clearError:()=>setError(void 0),apply:perk=>run(perk.id,()=>applyPerk(cart.actions,client,perk)),remove:redemptionId=>run(redemptionId,()=>removePerk(cart.actions,client,redemptionId))}}export{LoyaltyProvider,loyaltyStatus,signInAgain,useCartPerks,useClaimPoints,useLoyalty,useLoyaltyClient,usePerks,useStoreCredit};
|
|
2
|
-
//# sourceMappingURL=react.js.map
|
package/dist/loyalty/release.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
import{heldBy,unhold}from"../internal/perk-hold.js";async function held(id,base,fetcher=globalThis.fetch){const session=heldBy(id);if(!session){return false}try{const response=await fetcher(`${base}/checkout/sessions/${encodeURIComponent(session)}`,{credentials:"same-origin",headers:{Accept:"application/json"}});const ended=response.ok?(await response.json()).status!=="open":response.status===404;if(ended){unhold(id)}return!ended}catch{return true}}async function releasePerks(perks,customerBase="/_zappie/api",fetcher=globalThis.fetch){const base=customerBase.replace(/\/+$/,"");await Promise.all(perks.map(async({redemptionId})=>{if(!await held(redemptionId,base,fetcher)){await fetcher(`${base}/me/loyalty/redemptions/${encodeURIComponent(redemptionId)}`,{method:"DELETE",credentials:"same-origin",headers:{Accept:"application/json"}}).catch(()=>void 0)}}))}export{held,releasePerks};
|
|
2
|
-
//# sourceMappingURL=release.js.map
|
package/dist/loyalty/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=types.js.map
|
package/dist/menu/index.d.ts
CHANGED
|
@@ -7,7 +7,11 @@ type CategoryView = Category & {
|
|
|
7
7
|
itemCount: number;
|
|
8
8
|
};
|
|
9
9
|
/** An order type a site's switch offers. */
|
|
10
|
-
type OrderType =
|
|
10
|
+
type OrderType =
|
|
11
|
+
/** Orders delivered to the shopper. */
|
|
12
|
+
"delivery"
|
|
13
|
+
/** Orders the shopper collects from the branch. */
|
|
14
|
+
| "pickup";
|
|
11
15
|
/** The branch's menus that list a category, or the whole menu as one section when it lists no menus. */
|
|
12
16
|
declare function sectionsOf(menu: Menu): Section[];
|
|
13
17
|
/**
|
package/dist/menu/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
function sectionsOf(menu){return menu.menus?.length?menu.menus.filter(section=>section.categoryIds.length>0):[{id:menu.id,name:menu.name,categoryIds:menu.categories.map(category=>category.id)}]}function categoriesOf(menu,section){const ids=section?.categoryIds??sectionsOf(menu).flatMap(entry=>entry.categoryIds);return[...new Set(ids)].map(id=>menu.categories.find(category=>category.id===id)).filter(category=>Boolean(category)).map(category=>({...category,itemCount:category.itemIds.filter(itemId=>menu.items[itemId]).length})).filter(category=>category.itemCount>0)}function itemsOf(menu,categories){const ids=new Set(categories.flatMap(category=>category.itemIds));return[...ids].flatMap(id=>menu.items[id]??[])}function categoryOfItem(menu,itemId){return menu.categories.find(category=>category.itemIds.includes(itemId))}function sectionOfCategory(sections,categoryId){return categoryId?sections.find(section=>section.categoryIds.includes(categoryId)):void 0}var itemHref=(itemId,menuId)=>`/item/${encodeURIComponent(itemId)}${menuId?`?menu=${encodeURIComponent(menuId)}`:""}`;function menuHref(sectionId,categoryId){const query=new URLSearchParams;if(sectionId){query.set("menu",sectionId)}if(categoryId){query.set("category",categoryId)}const search=query.toString();return search?`/menu?${search}`:"/menu"}function orderTypesOf(branch,menu){const listed=menu?.menus?.flatMap(section=>section.fulfilment??[]);const offers=["delivery","pickup"].filter(type=>branch.fulfilment[type]);return listed?.length?offers.filter(type=>listed.includes(type)):offers}function directionsHref(store,branch){return branch.coordinates?`https://www.google.com/maps/dir/?api=1&destination=${branch.coordinates.lat},${branch.coordinates.lng}`:`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(branch.address??store.name)}`}export{categoriesOf,categoryOfItem,directionsHref,itemHref,itemsOf,menuHref,orderTypesOf,sectionOfCategory,sectionsOf};
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
declare const MoneyBrand: unique symbol;
|
|
2
|
+
/** A normalized ISO 4217 currency code. */
|
|
3
|
+
type Currency = string;
|
|
4
|
+
/** A frozen amount in safe integer minor units. Create it with money(). */
|
|
5
|
+
type Money = {
|
|
6
|
+
/** The amount in minor units of the currency, such as kobo for NGN. A safe integer, never rounded. */
|
|
7
|
+
readonly amountMinor: number;
|
|
8
|
+
/** The ISO 4217 currency code, in capitals, such as `NGN`. */
|
|
9
|
+
readonly currency: Currency;
|
|
10
|
+
/** A type-only brand, so only `money()` makes a Money. It holds no value at runtime. */
|
|
11
|
+
readonly [MoneyBrand]: true;
|
|
12
|
+
};
|
|
13
|
+
/** Validate an amount in minor units and freeze it without rounding. */
|
|
14
|
+
declare function money(amountMinor: number, currency: Currency): Money;
|
|
15
|
+
/** Currency presentation options. */
|
|
16
|
+
type MoneyFormatOptions = {
|
|
17
|
+
/** True shows the minor digits of a whole amount, such as ₦1,500.00 in place of ₦1,500. Defaults to false. */
|
|
18
|
+
showZeroDecimals?: boolean;
|
|
19
|
+
/** True shortens large amounts, such as ₦1.5K. Defaults to false. */
|
|
20
|
+
compact?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* When to show a sign. `auto` shows a minus on negative amounts only. `always` also shows a plus
|
|
23
|
+
* on positive amounts. Defaults to `auto`.
|
|
24
|
+
*/
|
|
25
|
+
sign?: "auto" | "always";
|
|
26
|
+
};
|
|
27
|
+
/** Format amounts for display. Use server quotes for final prices. */
|
|
28
|
+
interface Formatters {
|
|
29
|
+
/**
|
|
30
|
+
* Format an amount with its currency symbol and the currency's minor digits. Whole amounts drop
|
|
31
|
+
* their minor digits unless `showZeroDecimals` is set. Throws `invalid_request` when the amount
|
|
32
|
+
* is not a safe integer or the currency is not a valid code.
|
|
33
|
+
*
|
|
34
|
+
* @param value - The amount to format.
|
|
35
|
+
* @param opts - How to present it.
|
|
36
|
+
*/
|
|
37
|
+
money(value: Money, opts?: MoneyFormatOptions): string;
|
|
38
|
+
}
|
|
39
|
+
/** Format money with currency-specific minor units and locale defaults. */
|
|
40
|
+
declare const format: Formatters;
|
|
41
|
+
|
|
42
|
+
/** Payment methods you can display. Checkout decides which are available. */
|
|
43
|
+
type PaymentMethodKind =
|
|
44
|
+
/** A card payment online. */
|
|
45
|
+
"card"
|
|
46
|
+
/** A bank transfer to the account checkout shows. */
|
|
47
|
+
| "bank_transfer"
|
|
48
|
+
/** Store credit the customer holds with the business. Listed when the business has store credit. */
|
|
49
|
+
| "wallet"
|
|
50
|
+
/** A payment from a payment app with the reference, link or QR code that checkout shows. */
|
|
51
|
+
| "zap"
|
|
52
|
+
/** A payment from the wallet built into the shopper's phone or browser. The value names the wallet. */
|
|
53
|
+
| "apple_pay"
|
|
54
|
+
/** A payment from the wallet built into the shopper's phone or browser. The value names the wallet. */
|
|
55
|
+
| "google_pay";
|
|
56
|
+
/** Fulfilment capabilities supplied by the service. */
|
|
57
|
+
type Fulfilment = {
|
|
58
|
+
/** True when orders can be picked up. */
|
|
59
|
+
pickup: boolean;
|
|
60
|
+
/** True when orders can be delivered. */
|
|
61
|
+
delivery: boolean;
|
|
62
|
+
/** True when table orders are taken. The API sends it as `dine_in`. */
|
|
63
|
+
dineIn: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* True when pickup or delivery orders can be scheduled ahead. The API sends it as `scheduled`.
|
|
66
|
+
* `orderAheadDays` and a menu's preorder settings say how far ahead.
|
|
67
|
+
*/
|
|
68
|
+
scheduling: boolean;
|
|
69
|
+
};
|
|
70
|
+
/** An opening interval in local time, including whether the day is disabled. */
|
|
71
|
+
type OpeningTime = {
|
|
72
|
+
/** The day of the week. 0 is Sunday and 6 is Saturday. */
|
|
73
|
+
day: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
74
|
+
/** When the slot opens, as `HH:MM` in the branch's time zone. */
|
|
75
|
+
opens: string;
|
|
76
|
+
/**
|
|
77
|
+
* When the slot closes, as `HH:MM` in the branch's time zone. A close earlier than `opens` runs
|
|
78
|
+
* past midnight into the next day.
|
|
79
|
+
*/
|
|
80
|
+
closes: string;
|
|
81
|
+
/** True when the slot is saved but takes no orders. Left out means false. Menu schedules leave disabled slots out. */
|
|
82
|
+
disabled?: boolean;
|
|
83
|
+
};
|
|
84
|
+
/** Calendar exception to the weekly hours. */
|
|
85
|
+
type SpecialHours = {
|
|
86
|
+
/** The day the exception applies to, as `YYYY-MM-DD` in the branch's time zone. */
|
|
87
|
+
date: string;
|
|
88
|
+
/** True when the branch is closed all that day. */
|
|
89
|
+
closed: boolean;
|
|
90
|
+
/** When the branch opens that day, as `HH:MM` in the branch's time zone. Left out when it is closed. */
|
|
91
|
+
opens?: string;
|
|
92
|
+
/** When the branch closes that day, as `HH:MM` in the branch's time zone. Left out when it is closed. */
|
|
93
|
+
closes?: string;
|
|
94
|
+
};
|
|
95
|
+
/** What kind of venue a branch is. */
|
|
96
|
+
type BranchCategory =
|
|
97
|
+
/** A venue that serves food and drink. In-person orders are called Dine-in. */
|
|
98
|
+
"RESTAURANT"
|
|
99
|
+
/** A shop. In-person orders are called Walk-in. */
|
|
100
|
+
| "RETAIL";
|
|
101
|
+
/** Branch details, opening hours and fulfilment options. */
|
|
102
|
+
type Branch = {
|
|
103
|
+
/** Currency used for this branch's prices. */
|
|
104
|
+
currency?: Currency;
|
|
105
|
+
/** Country code for the branch address. */
|
|
106
|
+
country?: string;
|
|
107
|
+
/** Delivery regions and their quoted base fees. */
|
|
108
|
+
deliveryRegions?: {
|
|
109
|
+
id: string;
|
|
110
|
+
name: string;
|
|
111
|
+
fee: Money;
|
|
112
|
+
}[];
|
|
113
|
+
/** The branch's public id. */
|
|
114
|
+
id: string;
|
|
115
|
+
/** The branch tag, or the branch's public id when no tag is saved. `ReadOptions.branch` accepts either. */
|
|
116
|
+
slug: string;
|
|
117
|
+
/** The branch name. */
|
|
118
|
+
name: string;
|
|
119
|
+
/**
|
|
120
|
+
* The branch's IANA time zone, such as `Africa/Lagos`. Opening hours, `isOpen` and menu schedules
|
|
121
|
+
* are read in it. Left out only when the API doesn't send one.
|
|
122
|
+
*/
|
|
123
|
+
timezone?: string;
|
|
124
|
+
/**
|
|
125
|
+
* The branch address on one line, as the merchant saved it, or the pickup location's address when
|
|
126
|
+
* none is saved. Left out when the API sends no address.
|
|
127
|
+
*/
|
|
128
|
+
address?: string;
|
|
129
|
+
/** The branch contact number with its country code, such as `+2348012345678`. Left out when none is saved. */
|
|
130
|
+
phone?: string;
|
|
131
|
+
/**
|
|
132
|
+
* What kind of venue the branch is. Absent when the API doesn't say, which
|
|
133
|
+
* reads as a restaurant. `inVenueLabel()` from `@zappie/sdk/display` names
|
|
134
|
+
* in-person orders by it.
|
|
135
|
+
*/
|
|
136
|
+
category?: BranchCategory;
|
|
137
|
+
/**
|
|
138
|
+
* Where the branch is, in degrees. It comes from the pickup location and is left out when none
|
|
139
|
+
* is saved.
|
|
140
|
+
*/
|
|
141
|
+
coordinates?: {
|
|
142
|
+
lat: number;
|
|
143
|
+
lng: number;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* The saved pickup location: its place id, as `@zappie/sdk/places` gives it, and its coordinates
|
|
147
|
+
* in degrees. Left out when none is saved.
|
|
148
|
+
*/
|
|
149
|
+
pickupAddress?: {
|
|
150
|
+
placeId?: string;
|
|
151
|
+
coordinates?: {
|
|
152
|
+
lat: number;
|
|
153
|
+
lng: number;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
/** Automatic promotions to display. The quote decides whether an order qualifies. */
|
|
157
|
+
promos?: {
|
|
158
|
+
id: string;
|
|
159
|
+
name: string;
|
|
160
|
+
description: string;
|
|
161
|
+
}[];
|
|
162
|
+
/** How many days ahead a branch takes orders, even while closed. Zero: only while open. */
|
|
163
|
+
orderAheadDays?: number;
|
|
164
|
+
/**
|
|
165
|
+
* The branch's public links. `type` is `instagram`, `facebook`, `twitter`, `tiktok`, `whatsapp`
|
|
166
|
+
* or `website`. Only HTTP and HTTPS links are kept.
|
|
167
|
+
*/
|
|
168
|
+
socialLinks?: {
|
|
169
|
+
type: string;
|
|
170
|
+
url: string;
|
|
171
|
+
}[];
|
|
172
|
+
/** The weekly opening slots, one per entry. Slots saved as disabled are included with `disabled` set. */
|
|
173
|
+
openingTimes: OpeningTime[];
|
|
174
|
+
/** Dates whose hours differ from the weekly ones. Reserved. The API doesn't send it today, so REST reads leave it out. */
|
|
175
|
+
specialHours?: SpecialHours[];
|
|
176
|
+
/**
|
|
177
|
+
* True when the branch is open, worked out by the server in the branch's time zone when the store
|
|
178
|
+
* was read. A branch with no opening hours is closed.
|
|
179
|
+
*/
|
|
180
|
+
isOpen: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* When a temporary closure ends, as an RFC 3339 date and time. Reserved. The API doesn't send it
|
|
183
|
+
* today, so REST reads leave it out.
|
|
184
|
+
*/
|
|
185
|
+
closedUntil?: string;
|
|
186
|
+
/**
|
|
187
|
+
* When a closed branch next opens, as an RFC 3339 date and time in UTC. Left out while the branch
|
|
188
|
+
* is open, and when no opening slot is ahead.
|
|
189
|
+
*/
|
|
190
|
+
nextChangeAt?: string;
|
|
191
|
+
/**
|
|
192
|
+
* True for the branch a shopper starts on when nothing else picks one. The client reads this
|
|
193
|
+
* branch when neither `ZappieClientOptions.branch` nor a read's `branch` names one.
|
|
194
|
+
*/
|
|
195
|
+
isDefault?: boolean;
|
|
196
|
+
/** The order types the branch takes. */
|
|
197
|
+
fulfilment: Fulfilment;
|
|
198
|
+
/** The smallest order the branch takes. Reserved. The API doesn't send it today, so REST reads leave it out. */
|
|
199
|
+
minimumOrder?: Money;
|
|
200
|
+
};
|
|
201
|
+
/** Public storefront identity and branch directory. */
|
|
202
|
+
type Store = {
|
|
203
|
+
/** Search and sharing settings. Absent when the store has no site settings. */
|
|
204
|
+
seo?: {
|
|
205
|
+
titlePattern: string;
|
|
206
|
+
description: string;
|
|
207
|
+
shareImageUrl: string;
|
|
208
|
+
searchConsoleToken: string;
|
|
209
|
+
hidden: boolean;
|
|
210
|
+
redirects: {
|
|
211
|
+
from: string;
|
|
212
|
+
to: string;
|
|
213
|
+
}[];
|
|
214
|
+
};
|
|
215
|
+
/** The business's public id. */
|
|
216
|
+
id: string;
|
|
217
|
+
/** The business's tag. */
|
|
218
|
+
slug: string;
|
|
219
|
+
/** The business name. */
|
|
220
|
+
name: string;
|
|
221
|
+
/** The store's ISO 4217 currency code, in capitals, such as `NGN`. */
|
|
222
|
+
currency: Currency;
|
|
223
|
+
/**
|
|
224
|
+
* The first branch's IANA time zone, such as `Africa/Lagos`. Empty when the store has no branches.
|
|
225
|
+
* Each branch carries its own `timezone`, so read that one for a branch's hours.
|
|
226
|
+
*/
|
|
227
|
+
timezone: string;
|
|
228
|
+
/** The store description. Left out when none is saved. */
|
|
229
|
+
description?: string;
|
|
230
|
+
/** Merchant choices declared by the active template manifest. */
|
|
231
|
+
templateSettings?: Record<string, string | number | boolean>;
|
|
232
|
+
/**
|
|
233
|
+
* The store's images, each as a URL: `logoUrl` and `coverImageUrl`. Each is left out when none is
|
|
234
|
+
* saved. `accent` is reserved: the REST transport never fills it.
|
|
235
|
+
*/
|
|
236
|
+
brand: {
|
|
237
|
+
logoUrl?: string;
|
|
238
|
+
coverImageUrl?: string;
|
|
239
|
+
accent?: string;
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* The order types the store takes. Each one is true when at least one branch takes it, unless the
|
|
243
|
+
* API sends a store-wide value.
|
|
244
|
+
*/
|
|
245
|
+
fulfilment: Fulfilment;
|
|
246
|
+
/**
|
|
247
|
+
* How customers can pay online at any branch. Cash and other in-person methods are never listed.
|
|
248
|
+
* A method newer than this SDK is skipped with a console warning.
|
|
249
|
+
*/
|
|
250
|
+
paymentMethods: PaymentMethodKind[];
|
|
251
|
+
/** The branches your key can see, in the order the API sends them. */
|
|
252
|
+
branches: Branch[];
|
|
253
|
+
/** What checkout asks beside the phone, phone last. Absent from an older API. */
|
|
254
|
+
checkoutFields?: CheckoutField[];
|
|
255
|
+
};
|
|
256
|
+
/** A detail a business asks for at checkout, such as an email. */
|
|
257
|
+
type CheckoutField = {
|
|
258
|
+
/** `given_name`, `family_name`, `email` or `phone`. */
|
|
259
|
+
key: string;
|
|
260
|
+
/** The label to show with the input. */
|
|
261
|
+
label: string;
|
|
262
|
+
/**
|
|
263
|
+
* The input to show. `text` is free text, `email` is an email address and `phone` is a phone
|
|
264
|
+
* number. A field of any other type is left out of `Store.checkoutFields`.
|
|
265
|
+
*/
|
|
266
|
+
type: "text" | "email" | "phone";
|
|
267
|
+
/** True when checkout refuses an order without it. */
|
|
268
|
+
required: boolean;
|
|
269
|
+
/** True for the details every business can ask for. */
|
|
270
|
+
builtin: boolean;
|
|
271
|
+
/** Empty branch or menu ids mean every one. */
|
|
272
|
+
appliesTo: {
|
|
273
|
+
branchIds: string[];
|
|
274
|
+
menuIds: string[];
|
|
275
|
+
fulfilment: ("pickup" | "delivery")[];
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
/** Availability schedule in the owning branch's local timezone. */
|
|
279
|
+
type MenuSchedule = {
|
|
280
|
+
/** When the menu serves, in the branch's time zone. Disabled slots are left out. Empty means all day, every day. */
|
|
281
|
+
openingTimes: OpeningTime[];
|
|
282
|
+
/** True when the menu takes orders ahead. Left out otherwise. */
|
|
283
|
+
preorder?: boolean;
|
|
284
|
+
/**
|
|
285
|
+
* The fewest hours ahead an order from this menu must be scheduled. Above 0, every order from the
|
|
286
|
+
* menu must be scheduled. Set only with `preorder`.
|
|
287
|
+
*/
|
|
288
|
+
preorderNoticeHours?: number;
|
|
289
|
+
/**
|
|
290
|
+
* How many service days ahead an order can be scheduled. 0 uses the branch's `orderAheadDays`. Set
|
|
291
|
+
* only with `preorder`.
|
|
292
|
+
*/
|
|
293
|
+
preorderMaxDays?: number;
|
|
294
|
+
};
|
|
295
|
+
/** A source menu retained when the branch exposes several menus. */
|
|
296
|
+
type MenuSection = {
|
|
297
|
+
/** Fulfilment modes returned for this source menu. */
|
|
298
|
+
fulfilment?: string[];
|
|
299
|
+
/** Placement count before you load items. Omitted when unknown. */
|
|
300
|
+
placementCount?: number;
|
|
301
|
+
/** A display setting the merchant saved for this menu. The API sends every item whatever its value. */
|
|
302
|
+
paginated?: boolean;
|
|
303
|
+
/** The source menu's id. */
|
|
304
|
+
id: string;
|
|
305
|
+
/** The source menu's name, such as Breakfast. */
|
|
306
|
+
name: string;
|
|
307
|
+
/** The ids of the menu's categories, in order. Each one is in `Menu.categories`. */
|
|
308
|
+
categoryIds: string[];
|
|
309
|
+
/**
|
|
310
|
+
* The merchant's preferred layout for the menu. `LIST` shows items in rows, `GRID` in a grid and
|
|
311
|
+
* `CARD` as cards. Left out when the API doesn't send one.
|
|
312
|
+
*/
|
|
313
|
+
layout?: "LIST" | "GRID" | "CARD";
|
|
314
|
+
/** Whether this menu is available now at the selected branch. */
|
|
315
|
+
isActive?: boolean;
|
|
316
|
+
/** Plain-text merchant banner. */
|
|
317
|
+
infoBanner?: string;
|
|
318
|
+
/** Sanitized rich-text banner supplied by the service. */
|
|
319
|
+
infoBannerHtml?: string;
|
|
320
|
+
/** When the menu serves and whether it takes orders ahead. Left out when the menu has neither hours nor preorder. */
|
|
321
|
+
schedule?: MenuSchedule;
|
|
322
|
+
};
|
|
323
|
+
/** A branch catalogue that stores each item once across categories. */
|
|
324
|
+
type Menu = {
|
|
325
|
+
/**
|
|
326
|
+
* How much of the catalogue this holds. `partial` is a search result, a category page, a single
|
|
327
|
+
* source menu or a metadata-only read. `complete` holds every item. Left out means complete.
|
|
328
|
+
* Partial snapshots never satisfy a complete menu read.
|
|
329
|
+
*/
|
|
330
|
+
completeness?: "partial" | "complete";
|
|
331
|
+
/** The source menu's id when the branch has one menu, otherwise `branch:` followed by the branch id. */
|
|
332
|
+
id: string;
|
|
333
|
+
/** The id of the branch this catalogue belongs to. */
|
|
334
|
+
branchId: string;
|
|
335
|
+
/** The source menu's name when the branch has one menu, otherwise `Catalogue`. */
|
|
336
|
+
name: string;
|
|
337
|
+
/** An opaque version that changes with any change to the menus, availability included. */
|
|
338
|
+
version: string;
|
|
339
|
+
/** Every category across the source menus, each once, with its items in order. */
|
|
340
|
+
categories: Category[];
|
|
341
|
+
/** Every item in the catalogue, keyed by item id and stored once. */
|
|
342
|
+
items: Record<string, Item>;
|
|
343
|
+
/** The source menus the branch serves in this order type, in order. */
|
|
344
|
+
menus?: MenuSection[];
|
|
345
|
+
/** The menu's schedule. Set only when the branch has one source menu with a schedule. */
|
|
346
|
+
schedule?: MenuSchedule;
|
|
347
|
+
};
|
|
348
|
+
/** Ordered category membership. */
|
|
349
|
+
type Category = {
|
|
350
|
+
/** The category id. */
|
|
351
|
+
id: string;
|
|
352
|
+
/** The category name. */
|
|
353
|
+
name: string;
|
|
354
|
+
/** The category description. The REST transport never fills it. */
|
|
355
|
+
description?: string;
|
|
356
|
+
/** The ids of the category's items at this branch, in order. Each one is a key in `Menu.items`. Empty in a metadata-only read. */
|
|
357
|
+
itemIds: string[];
|
|
358
|
+
};
|
|
359
|
+
/** An exact variant with its selected attributes, price and availability. */
|
|
360
|
+
type Variant = {
|
|
361
|
+
/** A low-stock hint for shoppers. This does not give a stock balance. */
|
|
362
|
+
lowStock?: boolean;
|
|
363
|
+
/** The variant id. A cart line names it as `variantId`. */
|
|
364
|
+
id: string;
|
|
365
|
+
/** The attribute choices that select this variant, as attribute group id to choice id. Empty for an item without attributes. */
|
|
366
|
+
attributeChoices: Record<string, string>;
|
|
367
|
+
/** The variant's full price, not a difference from the item price. */
|
|
368
|
+
price: Money;
|
|
369
|
+
/** Whether the variant can be ordered at this branch. */
|
|
370
|
+
isAvailable: boolean;
|
|
371
|
+
/**
|
|
372
|
+
* Photos of this exact variant, such as one colour. Empty when the variant
|
|
373
|
+
* shows the item's `images`, and when the API predates variant photos.
|
|
374
|
+
*/
|
|
375
|
+
images: string[];
|
|
376
|
+
};
|
|
377
|
+
/** Item details and choices, with at least one exact variant. */
|
|
378
|
+
type Item = {
|
|
379
|
+
/** Fulfilment modes returned for this item. */
|
|
380
|
+
fulfilment?: string[];
|
|
381
|
+
/** Exact source placements returned by targeted item reads. */
|
|
382
|
+
placements?: {
|
|
383
|
+
menuId: string;
|
|
384
|
+
categoryId: string;
|
|
385
|
+
}[];
|
|
386
|
+
/** Stock text for display. Use isAvailable and the server quote to check eligibility. */
|
|
387
|
+
stockLabel?: string;
|
|
388
|
+
/** The active promotion on the item, by name. Left out when there is none. */
|
|
389
|
+
promo?: {
|
|
390
|
+
name: string;
|
|
391
|
+
};
|
|
392
|
+
/** The item id. */
|
|
393
|
+
id: string;
|
|
394
|
+
/** The item name. */
|
|
395
|
+
name: string;
|
|
396
|
+
/** Plain text with the editor's formatting removed. */
|
|
397
|
+
description?: string;
|
|
398
|
+
/**
|
|
399
|
+
* The same description as rich text, sanitized by the service: no scripts, embedded content or
|
|
400
|
+
* HTML attributes. Omitted when there is no description, and from older services. The SDK never
|
|
401
|
+
* renders it. Render it where you show `description`, and fall back to `description` without it.
|
|
402
|
+
*/
|
|
403
|
+
descriptionHtml?: string;
|
|
404
|
+
/** The item's image URLs. Empty when it has none. */
|
|
405
|
+
images: string[];
|
|
406
|
+
/** The branch price. For an item whose own price is 0, the lowest variant price. */
|
|
407
|
+
price: Money;
|
|
408
|
+
/** The earlier price, to show struck through. Left out unless it is above `price`. */
|
|
409
|
+
compareAtPrice?: Money;
|
|
410
|
+
/**
|
|
411
|
+
* Whether the item can be ordered now. Also false when the item carries an option rule or variant
|
|
412
|
+
* this SDK can't read, so the cart never takes it.
|
|
413
|
+
*/
|
|
414
|
+
isAvailable: boolean;
|
|
415
|
+
/**
|
|
416
|
+
* How many one line can order. `min` is 1 when the item sets none. `max` is left out when the item
|
|
417
|
+
* sets none. `step` is always 1.
|
|
418
|
+
*/
|
|
419
|
+
quantity: {
|
|
420
|
+
min: number;
|
|
421
|
+
max?: number;
|
|
422
|
+
step: number;
|
|
423
|
+
};
|
|
424
|
+
/** The item's exact variants. There is always at least one. */
|
|
425
|
+
variants: [Variant, ...Variant[]];
|
|
426
|
+
/** The attribute groups first, then the add-on and instruction groups. */
|
|
427
|
+
optionGroups: OptionGroup[];
|
|
428
|
+
/** Labels for the item. The API doesn't send tags today, so REST reads give an empty list. */
|
|
429
|
+
tags: string[];
|
|
430
|
+
};
|
|
431
|
+
/** Conditions that change option rules when selected choices match. */
|
|
432
|
+
type OptionCondition = {
|
|
433
|
+
/** The group whose picks the rule reads. */
|
|
434
|
+
groupId: string;
|
|
435
|
+
/** The choices in that group that trigger the rule. Empty when the rule counts picks instead. */
|
|
436
|
+
choiceIds: string[];
|
|
437
|
+
/**
|
|
438
|
+
* How `choiceIds` trigger the rule. `any` triggers when the shopper picks one of them. `all` needs
|
|
439
|
+
* every one. Defaults to `any`.
|
|
440
|
+
*/
|
|
441
|
+
match: "any" | "all";
|
|
442
|
+
/**
|
|
443
|
+
* Triggers on how many different choices the shopper picks in that group, whatever their
|
|
444
|
+
* quantities. `eq` is exactly `value`, `gte` is `value` or more and `lte` is `value` or fewer. When
|
|
445
|
+
* set, `choiceIds` and `match` don't apply.
|
|
446
|
+
*/
|
|
447
|
+
count?: {
|
|
448
|
+
op: "eq" | "gte" | "lte";
|
|
449
|
+
value: number;
|
|
450
|
+
};
|
|
451
|
+
/** Whether the group needs a pick while the rule applies. Left out when the rule doesn't change it. */
|
|
452
|
+
setRequired?: boolean | null;
|
|
453
|
+
/** The group's `selection.min` while the rule applies. Left out when the rule doesn't change it. */
|
|
454
|
+
setMin?: number | null;
|
|
455
|
+
/** The group's `selection.max` while the rule applies. 0 removes the upper limit. Left out when the rule doesn't change it. */
|
|
456
|
+
setMax?: number | null;
|
|
457
|
+
};
|
|
458
|
+
/** Addon or exact-variant attribute selection rules. */
|
|
459
|
+
type OptionGroup = {
|
|
460
|
+
/** The group id. A cart line's choices name it as `groupId`, and its `inputs` key text by it. */
|
|
461
|
+
id: string;
|
|
462
|
+
/** The group name, such as Size or Add-ons. */
|
|
463
|
+
name: string;
|
|
464
|
+
/** Help to show with the group. Left out when none is set. */
|
|
465
|
+
helpText?: string;
|
|
466
|
+
/**
|
|
467
|
+
* How the shopper answers. `select` picks from `choices`, for attribute and add-on groups. `text`
|
|
468
|
+
* is an instruction the shopper types. `number`, `date` (`YYYY-MM-DD`), `time` (`HH:MM`) and
|
|
469
|
+
* `toggle` (`true` or `false`) are typed answers the cart validates. The REST transport only
|
|
470
|
+
* produces `select` and `text`. A group of a kind newer than the SDK is dropped, and its item
|
|
471
|
+
* reads as unavailable.
|
|
472
|
+
*/
|
|
473
|
+
kind: "select" | "text" | "number" | "date" | "time" | "toggle";
|
|
474
|
+
/** Whether the shopper must pick or type something in this group. Attribute groups always need a pick. A condition's `setRequired` can change it. */
|
|
475
|
+
required: boolean;
|
|
476
|
+
/** False when the group is off. The cart then drops its picks and never requires it. The REST transport never sets it. */
|
|
477
|
+
isAvailable?: boolean;
|
|
478
|
+
/**
|
|
479
|
+
* True when a `select` group also takes a typed response in place of a pick. The REST transport
|
|
480
|
+
* never sets it.
|
|
481
|
+
*/
|
|
482
|
+
isInformational?: boolean;
|
|
483
|
+
/**
|
|
484
|
+
* How many units the shopper picks. `min` is the fewest once they pick anything, and each choice
|
|
485
|
+
* counts its quantity. `max` is left out when the group has no upper limit.
|
|
486
|
+
*/
|
|
487
|
+
selection: {
|
|
488
|
+
min: number;
|
|
489
|
+
max?: number;
|
|
490
|
+
};
|
|
491
|
+
/** True for an attribute group, whose picks select the exact variant. False for add-ons and instructions. */
|
|
492
|
+
isAttribute: boolean;
|
|
493
|
+
/** The choices of an attribute or add-on group. Empty for a text group. */
|
|
494
|
+
choices: Choice[];
|
|
495
|
+
/**
|
|
496
|
+
* Settings for a typed answer. `placeholder` is the input's placeholder. `maxLength` is the most
|
|
497
|
+
* characters the cart takes, 500 when unset. The REST transport fills only `placeholder`.
|
|
498
|
+
*/
|
|
499
|
+
input?: {
|
|
500
|
+
maxLength?: number;
|
|
501
|
+
placeholder?: string;
|
|
502
|
+
};
|
|
503
|
+
/** Rules that change this group while the shopper's picks in another group match. They apply in order. Left out when there are none. */
|
|
504
|
+
conditions?: OptionCondition[];
|
|
505
|
+
};
|
|
506
|
+
/** A selectable option. Attribute prices are zero to avoid charging twice. */
|
|
507
|
+
type Choice = {
|
|
508
|
+
/** An attribute price adjustment for display. Cart calculations exclude it. */
|
|
509
|
+
priceHint?: Money;
|
|
510
|
+
/** The choice id. */
|
|
511
|
+
id: string;
|
|
512
|
+
/** The choice name, such as Large. */
|
|
513
|
+
name: string;
|
|
514
|
+
/** What one unit of the choice adds to the line. Zero for an attribute choice. */
|
|
515
|
+
price: Money;
|
|
516
|
+
/** Whether the shopper can pick the choice now. Attribute choices are always true, and the variant's `isAvailable` decides. */
|
|
517
|
+
isAvailable: boolean;
|
|
518
|
+
/**
|
|
519
|
+
* How many units of the choice one pick takes, when the shopper can pick more than one. `min`
|
|
520
|
+
* defaults to 1. Left out when the quantity is always 1.
|
|
521
|
+
*/
|
|
522
|
+
quantity?: {
|
|
523
|
+
min: number;
|
|
524
|
+
max?: number;
|
|
525
|
+
};
|
|
526
|
+
};
|
|
527
|
+
/** One page of a source menu category. This is a partial branch catalogue. */
|
|
528
|
+
type CategoryPage = {
|
|
529
|
+
/** The page's items and their category, as a partial catalogue. */
|
|
530
|
+
menu: Menu;
|
|
531
|
+
/** The source menu the page belongs to. */
|
|
532
|
+
menuId: string;
|
|
533
|
+
/** The category the page belongs to. */
|
|
534
|
+
categoryId: string;
|
|
535
|
+
/** Pass it as `cursor` to read the next page. Left out on the last page. */
|
|
536
|
+
nextCursor?: string;
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
export { format as n, money as o };
|
|
540
|
+
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, CheckoutField as d, Choice as e, Currency as f, Fulfilment as g, MenuSchedule as h, MenuSection as i, MoneyFormatOptions as j, OpeningTime as k, OptionCondition as l, SpecialHours as m };
|
package/dist/models.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=models.js.map
|
package/dist/money.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
import{ZappieError}from"./errors.js";var ZERO_DIGIT_CURRENCIES=" AFN ALL BIF CLP DJF GNF IQD IRR ISK JPY KMF KPW KRW LAK LBP MGA MMK PYG RSD RWF SLL SOS SYP UGX UYI VND VUV XAF XOF XPF YER ";var THREE_DIGIT_CURRENCIES=" BHD JOD KWD LYD OMR TND ";var FOUR_DIGIT_CURRENCIES=" CLF UYW ";var API_ONLY_CURRENCIES=" BOV CHE CHW CLF COU MXV USN UYI UYW VED ";var contains=(codes,currency)=>codes.includes(currency);var intlCurrencies;var isCurrency=code=>/^[A-Z]{3}$/.test(code)&&(!Intl.supportedValuesOf||contains(API_ONLY_CURRENCIES,code)||(intlCurrencies??(intlCurrencies=new Set(Intl.supportedValuesOf("currency")))).has(code));var currencyDigits=currency=>contains(ZERO_DIGIT_CURRENCIES,currency)?0:contains(THREE_DIGIT_CURRENCIES,currency)?3:contains(FOUR_DIGIT_CURRENCIES,currency)?4:2;function money(amountMinor,currency){const normalized=typeof currency==="string"?currency.trim().toUpperCase():"";if(!Number.isSafeInteger(amountMinor)||!isCurrency(normalized)){throw new ZappieError("invalid_request","Money requires safe integer minor units and a valid ISO 4217 currency")}return Object.freeze({amountMinor,currency:normalized})}var formatters={};var format={money(value,opts={}){const{amountMinor,currency}=money(value.amountMinor,value.currency);const digits=currencyDigits(currency);const fraction=opts.showZeroDecimals||amountMinor%10**digits?digits:0;const key=currency+fraction+opts.compact+opts.sign;return(formatters[key]??(formatters[key]=new Intl.NumberFormat(currency==="NGN"?"en-NG":"en",{style:"currency",currency,currencyDisplay:"narrowSymbol",minimumFractionDigits:fraction,maximumFractionDigits:digits,notation:opts.compact?"compact":"standard",signDisplay:opts.sign||"auto"}))).format(amountMinor/10**digits)}};export{format,money};
|
|
2
|
-
//# sourceMappingURL=money.js.map
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
/** The parts of a link's click or a form's submit event that `follow` reads. */
|
|
2
2
|
type FollowEvent = {
|
|
3
|
+
/** True when the page already handled the event. `follow` then leaves it alone. */
|
|
3
4
|
defaultPrevented: boolean;
|
|
5
|
+
/** Stop the browser following the link or submitting the form. `follow` calls it on a second click while pending. */
|
|
4
6
|
preventDefault(): void;
|
|
7
|
+
/** The link or form the handler is on. A link with `target="_blank"` is left alone. */
|
|
5
8
|
currentTarget: EventTarget | null;
|
|
9
|
+
/** The mouse button pressed. Any button but the main one (0) leaves the event alone. Left out for a form's submit. */
|
|
6
10
|
button?: number;
|
|
11
|
+
/** True while the Meta key is held. `follow` then leaves the event alone. */
|
|
7
12
|
metaKey?: boolean;
|
|
13
|
+
/** True while the Control key is held. `follow` then leaves the event alone. */
|
|
8
14
|
ctrlKey?: boolean;
|
|
15
|
+
/** True while the Shift key is held. `follow` then leaves the event alone. */
|
|
9
16
|
shiftKey?: boolean;
|
|
17
|
+
/** True while the Alt key is held. `follow` then leaves the event alone. */
|
|
10
18
|
altKey?: boolean;
|
|
11
19
|
};
|
|
12
20
|
/**
|
package/dist/navigation/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
var STARTING=Promise.resolve();function createPendingNavigation(){const listeners=new Set;let run;const set=next=>{run=next;(next?addEventListener:removeEventListener)("pageshow",end);listeners.forEach(listener=>listener())};const end=event=>{if(run&&event?.persisted!==false){set()}};const start=leave=>{if(run){return run}set(STARTING);const current=new Promise(resolve=>resolve(leave?.()));if(run){run=current}current.catch(()=>{if(run===current){end()}});return current};return{get pending(){return!!run},start,end:()=>end(),follow(event){if(run){event.preventDefault()}else if(!(event.defaultPrevented||event.button||event.metaKey||event.ctrlKey||event.shiftKey||event.altKey||event.currentTarget?.target==="_blank")){void start()}},subscribe(listener){listeners.add(listener);return()=>{listeners.delete(listener)}}}}export{createPendingNavigation};
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
package/dist/navigation/react.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
"use client";import{createPendingNavigation}from"@zappie/sdk/navigation";import{useState,useSyncExternalStore}from"react";function usePendingNavigation(){const[nav]=useState(createPendingNavigation);const pending=useSyncExternalStore(nav.subscribe,()=>nav.pending,()=>false);return{pending,start:nav.start,end:nav.end,follow:nav.follow}}export{usePendingNavigation};
|
|
2
|
-
//# sourceMappingURL=react.js.map
|
|
@@ -1,2 +1 @@
|
|
|
1
1
|
"use client";import{useEffect,useState}from"react";import{jsx}from"react/jsx-runtime";var PRESSED=":where(a[href],button:enabled):active{opacity:.7}";function useDelayedActive(active,delayMs=150){const[shown,setShown]=useState(false);useEffect(()=>{if(!active){return}const timer=setTimeout(()=>setShown(true),delayMs);return()=>{clearTimeout(timer);setShown(false)}},[active,delayMs]);return active&&shown}function NavigationProgress({active,delayMs,color="currentColor",pressed=true}){return jsx("div",{className:"zappie-nav-progress","data-run":useDelayedActive(active,delayMs)||void 0,"aria-hidden":true,style:{background:color},children:pressed&&jsx("style",{children:PRESSED})})}export{NavigationProgress,useDelayedActive};
|
|
2
|
-
//# sourceMappingURL=index.js.map
|