@zappie/sdk 0.28.1 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +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-B8lItidz.d.ts} +229 -5
- package/dist/client.js +0 -1
- package/dist/config/index.d.ts +31 -0
- 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 +174 -6
- 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/in-venue/client.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
import{receiptFile}from"@zappie/sdk/receipts";import{apiError,requestWithRetry}from"../internal/customer-http.js";import{publicId}from"./bill.js";import{InVenueError}from"./error.js";import{watchBill}from"./watch.js";var DEFAULT_CUSTOMER_BASE="/_zappie/api";function createInVenue(options={}){const base=(options.customerBase??DEFAULT_CUSTOMER_BASE).replace(/\/+$/,"");const fetcher=options.fetch??globalThis.fetch;const request=async(path,init={})=>{const response=await requestWithRetry(fetcher,base+path,init,"Could not reach the storefront");if(!response.ok){const value=await apiError(response,`The storefront answered ${response.status}`);throw new InVenueError(response.status,value.apiCode,value.message,value.param,value.issues)}return await response.json()};const post=(path,body,idempotencyKey)=>request(path,{method:"POST",headers:{"Content-Type":"application/json","Idempotency-Key":idempotencyKey},body:JSON.stringify(body)});const receiptUrl=id=>`${base}/dine-in-orders/${encodeURIComponent(publicId("ord",id))}/receipt`;const signal=value=>value?{signal:value}:{};const order=(id,readOptions={})=>{const query=readOptions.diners?.length?`?${new URLSearchParams({diners:readOptions.diners.join(",")})}`:"";return request(`/dine-in-orders/${encodeURIComponent(publicId("ord",id))}${query}`,signal(readOptions.signal))};return{payPoint:(id,readOptions={})=>request(`/pay-points/${encodeURIComponent(publicId("pp",id))}`,signal(readOptions.signal)),entry:(id,readOptions={})=>request(`/pay-points/${encodeURIComponent(publicId("pp",id))}/entry`,signal(readOptions.signal)),menuGroup(id,readOptions={}){const query=readOptions.payPointId?`?${new URLSearchParams({pay_point_id:publicId("pp",readOptions.payPointId)})}`:"";return request(`/menu-groups/${encodeURIComponent(publicId("mgrp",id))}${query}`,signal(readOptions.signal))},wallet:()=>request("/me/wallet"),receiptUrl,receipt:id=>receiptFile(receiptUrl(id),fetcher),dineInOrder:order,placeDineInOrder(body,idempotencyKey){return post("/dine-in-orders",{...body,pay_point_id:publicId("pp",body.pay_point_id)},idempotencyKey)},payDineInOrder(id,body,idempotencyKey){return post(`/dine-in-orders/${encodeURIComponent(publicId("ord",id))}/payments`,body,idempotencyKey)},watchDineInOrder(id,watchOptions){return watchBill(base,publicId("ord",id),(orderId,abort)=>order(orderId,signal(abort)),watchOptions)}}}export{createInVenue};
|
|
2
|
-
//# sourceMappingURL=client.js.map
|
package/dist/in-venue/error.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
import{stableErrorCode,ZappieError}from"../internal/customer-http.js";var InVenueError=class extends ZappieError{constructor(status,apiCode,message,param,issues){super(stableErrorCode(status,apiCode),message,{status,retryable:status===429||status>=500,...param!==void 0?{param}:{}});this.apiCode=apiCode;if(issues!==void 0){this.issues=issues}}};export{InVenueError};
|
|
2
|
-
//# sourceMappingURL=error.js.map
|
package/dist/in-venue/index.d.ts
CHANGED
|
@@ -4,27 +4,44 @@ import { ZappieError, Zappie } from '@zappie/sdk';
|
|
|
4
4
|
* An API amount in minor currency units with its currency code.
|
|
5
5
|
*/
|
|
6
6
|
type Money = {
|
|
7
|
+
/** The amount in the currency's minor units, such as kobo for NGN. */
|
|
7
8
|
amount_minor: number;
|
|
9
|
+
/** The ISO 4217 currency code, such as `NGN`. */
|
|
8
10
|
currency: string;
|
|
9
11
|
};
|
|
10
12
|
/**
|
|
11
13
|
* What scanning a table opens. `menu_id` or `menu_group_id` is set only when the business chose one.
|
|
12
14
|
*/
|
|
13
15
|
type PayPointTarget = {
|
|
16
|
+
/**
|
|
17
|
+
* What the table opens. `menu` opens the table's menu, the one target that keeps a table bill.
|
|
18
|
+
* `menu_group` opens a group of menus. `self_service_menu` and `self_service_menu_group` open a
|
|
19
|
+
* menu or menu group that keeps no table bill. `collect_payment` takes a payment, with no menu.
|
|
20
|
+
* `beacon` opens the business's page of links. `unknown` is a target this API version doesn't name.
|
|
21
|
+
*/
|
|
14
22
|
type: "menu" | "menu_group" | "self_service_menu" | "self_service_menu_group" | "collect_payment" | "beacon" | "unknown";
|
|
23
|
+
/** The menu the table opens, with its `menu_` prefix. Set only when the business chose one. */
|
|
15
24
|
menu_id?: string;
|
|
25
|
+
/** The menu group the table opens, with its `mgrp_` prefix. Set only when the business chose one. */
|
|
16
26
|
menu_group_id?: string;
|
|
17
27
|
};
|
|
18
28
|
/**
|
|
19
29
|
* The table or counter a guest scanned, with its branch and the bill it holds while that bill is open.
|
|
20
30
|
*/
|
|
21
31
|
type PayPoint = {
|
|
32
|
+
/** Always `pay_point`. */
|
|
22
33
|
object: "pay_point";
|
|
34
|
+
/** The table's ID, with its `pp_` prefix. */
|
|
23
35
|
id: string;
|
|
36
|
+
/** The table's name, such as "Table 4". */
|
|
24
37
|
name: string;
|
|
38
|
+
/** The branch the table belongs to. */
|
|
25
39
|
branch_id: string;
|
|
40
|
+
/** What scanning the table opens. */
|
|
26
41
|
target: PayPointTarget;
|
|
42
|
+
/** The bill the table holds while it is open and has something on it. Null otherwise, and always null with a test key. */
|
|
27
43
|
open_order_id: string | null;
|
|
44
|
+
/** Whether the branch takes table orders right now. */
|
|
28
45
|
accepting_dine_in: boolean;
|
|
29
46
|
};
|
|
30
47
|
/**
|
|
@@ -32,25 +49,40 @@ type PayPoint = {
|
|
|
32
49
|
* `dine_in_disabled` means the branch isn't taking table orders right now.
|
|
33
50
|
*/
|
|
34
51
|
type PayPointDestination = {
|
|
52
|
+
/**
|
|
53
|
+
* The page to show. `dine_in_order` is the guest's open bill at this table, in `order_id`.
|
|
54
|
+
* `menu`, `menu_group`, `self_service_menu`, `self_service_menu_group`, `collect_payment` and
|
|
55
|
+
* `beacon` follow the table's target, as in {@link PayPointTarget}. `dine_in_disabled` means the
|
|
56
|
+
* branch isn't taking table orders right now.
|
|
57
|
+
*/
|
|
35
58
|
type: "dine_in_order" | "menu" | "menu_group" | "self_service_menu" | "self_service_menu_group" | "collect_payment" | "beacon" | "dine_in_disabled";
|
|
59
|
+
/** The guest's open bill. Set only for `dine_in_order`. */
|
|
36
60
|
order_id?: string;
|
|
61
|
+
/** The menu to show. Set only for a menu page whose table names one. */
|
|
37
62
|
menu_id?: string;
|
|
63
|
+
/** The menu group to show. Set only for a menu group page whose table names one. */
|
|
38
64
|
menu_group_id?: string;
|
|
39
65
|
};
|
|
40
66
|
/**
|
|
41
67
|
* Where a guest lands from a table.
|
|
42
68
|
*/
|
|
43
69
|
type PayPointEntry = {
|
|
70
|
+
/** Always `pay_point_entry`. */
|
|
44
71
|
object: "pay_point_entry";
|
|
72
|
+
/** The table the guest scanned, with its `pp_` prefix. */
|
|
45
73
|
pay_point_id: string;
|
|
74
|
+
/** The page to show the guest. */
|
|
46
75
|
destination: PayPointDestination;
|
|
47
76
|
};
|
|
48
77
|
/**
|
|
49
78
|
* One menu of a group, without its items. Read its items with the storefront client.
|
|
50
79
|
*/
|
|
51
80
|
type MenuGroupMenu = {
|
|
81
|
+
/** The menu's ID, with its `menu_` prefix. */
|
|
52
82
|
id: string;
|
|
83
|
+
/** The menu's name. */
|
|
53
84
|
name: string;
|
|
85
|
+
/** The menu's description. Null or left out when it has none. */
|
|
54
86
|
description?: string | null;
|
|
55
87
|
[field: string]: unknown;
|
|
56
88
|
};
|
|
@@ -58,46 +90,72 @@ type MenuGroupMenu = {
|
|
|
58
90
|
* A menu group with its menus as the branch serves them on the fulfilment asked for.
|
|
59
91
|
*/
|
|
60
92
|
type MenuGroup = {
|
|
93
|
+
/** Always `menu_group`. */
|
|
61
94
|
object: "menu_group";
|
|
95
|
+
/** The group's ID, with its `mgrp_` prefix. */
|
|
62
96
|
id: string;
|
|
97
|
+
/** The group's name. */
|
|
63
98
|
name: string;
|
|
99
|
+
/** The group's description. Null when it has none. */
|
|
64
100
|
description: string | null;
|
|
101
|
+
/** The address of the group's logo. Null when it has none. */
|
|
65
102
|
logo: string | null;
|
|
103
|
+
/** The fulfilment mode the group's menus were read for, such as `dine_in`. */
|
|
66
104
|
fulfilment: string;
|
|
105
|
+
/** The group's menus in the group's own order, without their items. */
|
|
67
106
|
menus: MenuGroupMenu[];
|
|
68
107
|
};
|
|
69
108
|
/**
|
|
70
109
|
* An option recorded on a bill line.
|
|
71
110
|
*/
|
|
72
111
|
type BillChoice = {
|
|
112
|
+
/** The choice group the option belongs to. */
|
|
73
113
|
group_id: string;
|
|
114
|
+
/** The option's ID. */
|
|
74
115
|
choice_id: string;
|
|
116
|
+
/** The option's name. */
|
|
75
117
|
name: string;
|
|
118
|
+
/** The option's price as the bill holds it. */
|
|
76
119
|
price: Money;
|
|
120
|
+
/** How many of the option the line has. */
|
|
77
121
|
quantity: number;
|
|
78
122
|
};
|
|
79
123
|
/**
|
|
80
124
|
* One line of a table's bill and the guest who ordered it. `diner_id` is null for a line staff added for nobody.
|
|
81
125
|
*/
|
|
82
126
|
type DineInLine = {
|
|
127
|
+
/** The item ordered. */
|
|
83
128
|
item_id: string;
|
|
129
|
+
/** The variant ordered. Left out for an item without variants. */
|
|
84
130
|
variant_id?: string;
|
|
131
|
+
/** The item's name. */
|
|
85
132
|
name: string;
|
|
133
|
+
/** How many were ordered. */
|
|
86
134
|
quantity: number;
|
|
135
|
+
/** The price of one unit. */
|
|
87
136
|
unit_price: Money;
|
|
137
|
+
/** The line's total. */
|
|
88
138
|
total: Money;
|
|
139
|
+
/** The guest's note on the line. Left out when there is none. */
|
|
89
140
|
notes?: string;
|
|
141
|
+
/** The guest who ordered the line, by customer ID. Null for a line staff added for nobody. */
|
|
90
142
|
diner_id: string | null;
|
|
143
|
+
/** The options on the line, attribute options included. */
|
|
91
144
|
choices: BillChoice[];
|
|
92
145
|
};
|
|
93
146
|
/**
|
|
94
147
|
* A guest on the bill, by first name only, with their share.
|
|
95
148
|
*/
|
|
96
149
|
type Diner = {
|
|
150
|
+
/** The guest's customer ID, with its `cus_` prefix. */
|
|
97
151
|
id: string;
|
|
152
|
+
/** The guest's first name. */
|
|
98
153
|
first_name: string;
|
|
154
|
+
/** The guest's lines plus their share of the charges. */
|
|
99
155
|
total: Money;
|
|
156
|
+
/** What payments for this guest cover. */
|
|
100
157
|
paid: Money;
|
|
158
|
+
/** `total` minus `paid`, never below 0. */
|
|
101
159
|
remaining: Money;
|
|
102
160
|
};
|
|
103
161
|
/**
|
|
@@ -105,69 +163,108 @@ type Diner = {
|
|
|
105
163
|
* and `payment` stay whole.
|
|
106
164
|
*/
|
|
107
165
|
type DineInOrder = {
|
|
166
|
+
/** Always `dine_in_order`. */
|
|
108
167
|
object: "dine_in_order";
|
|
168
|
+
/** The bill's order ID, with its `ord_` prefix. */
|
|
109
169
|
id: string;
|
|
170
|
+
/** The table's name when the bill opened. */
|
|
110
171
|
table: string;
|
|
172
|
+
/** The branch the bill is at. */
|
|
111
173
|
branch_id: string;
|
|
174
|
+
/**
|
|
175
|
+
* Where the bill stands. `open` means guests can still order on it. `closed` means staff closed
|
|
176
|
+
* the bill, or it closed itself once paid. `voided` means staff voided it. A bill stays open
|
|
177
|
+
* until staff close or void it.
|
|
178
|
+
*/
|
|
112
179
|
status: "open" | "closed" | "voided";
|
|
180
|
+
/** The bill's ISO 4217 currency code. */
|
|
113
181
|
currency: string;
|
|
182
|
+
/** Each diner's lines, combined per diner in the order they were placed. */
|
|
114
183
|
lines: DineInLine[];
|
|
184
|
+
/** The lines' total before charges, for the diners asked about or the whole bill. */
|
|
115
185
|
subtotal: Money;
|
|
186
|
+
/** Charges added on top of the prices, each with its `code`, the business's own `label` and its `amount`. */
|
|
116
187
|
charges: {
|
|
117
188
|
code: string;
|
|
118
189
|
label: string;
|
|
119
190
|
amount: Money;
|
|
120
191
|
}[];
|
|
192
|
+
/** `subtotal` plus `charges`. */
|
|
121
193
|
total: Money;
|
|
194
|
+
/** What has been paid, for the diners asked about or the whole bill. */
|
|
122
195
|
paid: Money;
|
|
196
|
+
/** `total` minus `paid`, never below 0. */
|
|
123
197
|
remaining: Money;
|
|
198
|
+
/** Every guest with lines on the bill. */
|
|
124
199
|
diners: Diner[];
|
|
200
|
+
/**
|
|
201
|
+
* The whole bill's payment, whichever diners were asked about. Its `status` is `paid` when
|
|
202
|
+
* payments cover the total, `partially_paid` when part of it is paid and `unpaid` when nothing is.
|
|
203
|
+
*/
|
|
125
204
|
payment: {
|
|
126
205
|
status: "paid" | "partially_paid" | "unpaid";
|
|
127
206
|
amount_paid: Money;
|
|
128
207
|
remaining: Money;
|
|
129
208
|
};
|
|
209
|
+
/** When the bill opened, as an RFC 3339 timestamp in UTC. */
|
|
130
210
|
placed_at: string;
|
|
211
|
+
/** When the bill last changed, as an RFC 3339 timestamp in UTC. */
|
|
131
212
|
updated_at: string;
|
|
213
|
+
/** The diners asked about. Empty means the whole bill. */
|
|
132
214
|
diner_ids: string[];
|
|
133
215
|
};
|
|
134
216
|
/**
|
|
135
217
|
* One line a guest orders, in quote line fields.
|
|
136
218
|
*/
|
|
137
219
|
type DineInOrderLine = {
|
|
220
|
+
/** An ID you choose for the line. The API returns it unchanged. */
|
|
138
221
|
line_id: string;
|
|
222
|
+
/** The item to order. */
|
|
139
223
|
item_id: string;
|
|
224
|
+
/** The menu the guest chose the item from. Required when the item sits in more than one menu. */
|
|
140
225
|
menu_id?: string;
|
|
226
|
+
/** The variant to order. Required when the item has attribute groups. */
|
|
141
227
|
variant_id?: string;
|
|
228
|
+
/** How many to order, from 1 to 99. */
|
|
142
229
|
quantity: number;
|
|
230
|
+
/** The options picked in choice groups, each with its group, option and quantity. `quantity` defaults to 1. Pick attributes with `variant_id` instead. */
|
|
143
231
|
options?: {
|
|
144
232
|
group_id: string;
|
|
145
233
|
choice_id: string;
|
|
146
234
|
quantity?: number;
|
|
147
235
|
}[];
|
|
236
|
+
/** What the guest typed, keyed by text group ID. */
|
|
148
237
|
inputs?: Record<string, string>;
|
|
238
|
+
/** The guest's note for the line. It goes on the bill. */
|
|
149
239
|
note?: string;
|
|
150
240
|
};
|
|
151
241
|
/**
|
|
152
242
|
* The lines a signed-in guest adds to a table's bill.
|
|
153
243
|
*/
|
|
154
244
|
type DineInOrderRequest = {
|
|
245
|
+
/** The table. The lines go on its open bill, or open a new one. May be bare or carry its `pp_` prefix. */
|
|
155
246
|
pay_point_id: string;
|
|
247
|
+
/** The lines to add, from 1 to 100. A line with a blocking issue is refused with `line_invalid`. */
|
|
156
248
|
lines: DineInOrderLine[];
|
|
157
249
|
};
|
|
158
250
|
/**
|
|
159
251
|
* The diners a guest pays for. Leave `diner_ids` empty to pay the whole bill.
|
|
160
252
|
*/
|
|
161
253
|
type DineInPaymentRequest = {
|
|
254
|
+
/** The diners to pay for, by customer ID. Leave it out or empty to pay the whole bill. */
|
|
162
255
|
diner_ids?: string[];
|
|
256
|
+
/** Take what the guest's wallet holds first. Needs the wallet scope. Defaults to false. */
|
|
163
257
|
use_wallet_balance?: boolean;
|
|
164
258
|
};
|
|
165
259
|
/**
|
|
166
260
|
* The payment a guest finishes on Zappie's payment page at `url`.
|
|
167
261
|
*/
|
|
168
262
|
type BillPayment = {
|
|
263
|
+
/** The payment's own ID, as the payment page takes it. */
|
|
169
264
|
payment_request_id: string;
|
|
265
|
+
/** The amount this payment asks for. */
|
|
170
266
|
amount: Money;
|
|
267
|
+
/** The payment page to send the guest to. */
|
|
171
268
|
url: string;
|
|
172
269
|
};
|
|
173
270
|
/**
|
|
@@ -175,7 +272,9 @@ type BillPayment = {
|
|
|
175
272
|
* list holds nothing.
|
|
176
273
|
*/
|
|
177
274
|
type Wallet = {
|
|
275
|
+
/** Always `wallet`. */
|
|
178
276
|
object: "wallet";
|
|
277
|
+
/** One balance per currency the guest holds. */
|
|
179
278
|
balances: Money[];
|
|
180
279
|
};
|
|
181
280
|
/**
|
|
@@ -184,13 +283,16 @@ type Wallet = {
|
|
|
184
283
|
type InVenueClientOptions = {
|
|
185
284
|
/** The same-origin API base. Defaults to `/_zappie/api`, which Zappie hosting serves. */
|
|
186
285
|
customerBase?: string;
|
|
286
|
+
/** The fetch implementation for every request. Defaults to the global `fetch`. */
|
|
187
287
|
fetch?: typeof fetch;
|
|
188
288
|
};
|
|
189
289
|
/**
|
|
190
|
-
* A bill callback, optional cancellation
|
|
290
|
+
* A bill callback, optional cancellation and the fallback polling interval. The watch always follows the whole bill.
|
|
191
291
|
*/
|
|
192
292
|
type WatchBillOptions = {
|
|
293
|
+
/** Called with the current bill, then with the bill after each change. A call with a `closed` or `voided` bill is the last. */
|
|
193
294
|
onBill(order: DineInOrder): void;
|
|
295
|
+
/** Aborting it stops the watch. */
|
|
194
296
|
signal?: AbortSignal;
|
|
195
297
|
/** Polling interval in milliseconds when the event stream is unavailable. Defaults to 15 seconds. */
|
|
196
298
|
pollMs?: number;
|
|
@@ -309,16 +411,22 @@ type InVenueClient = ReturnType<typeof createInVenue>;
|
|
|
309
411
|
* `order_refused`, `nothing_to_pay` or `line_invalid`. Statuses 429 and 5xx are marked retryable.
|
|
310
412
|
*/
|
|
311
413
|
declare class InVenueError extends ZappieError {
|
|
414
|
+
/** The API's own error code, such as `order_refused`, `nothing_to_pay` or `line_invalid`. `server_error` when the body carried none. */
|
|
312
415
|
readonly apiCode: string;
|
|
416
|
+
/** The `issues` list from the error body, as the API sent it, such as the blocking issues on `quote_issues`. Left out when the body has none. */
|
|
313
417
|
readonly issues?: unknown;
|
|
314
|
-
constructor(status: number,
|
|
418
|
+
constructor(status: number,
|
|
419
|
+
/** The API's own error code, such as `order_refused`, `nothing_to_pay` or `line_invalid`. `server_error` when the body carried none. */
|
|
420
|
+
apiCode: string, message: string, param?: string, issues?: unknown);
|
|
315
421
|
}
|
|
316
422
|
|
|
317
423
|
/**
|
|
318
424
|
* The table a storefront client is scoped to: its branch, the table itself and the menu it shows.
|
|
319
425
|
*/
|
|
320
426
|
type TableScope = {
|
|
427
|
+
/** The table's branch. The client reads that branch's dine-in menus. */
|
|
321
428
|
branchId: string;
|
|
429
|
+
/** The table, bare or with its `pp_` prefix. Its bag is stored under this table's own keys. */
|
|
322
430
|
payPointId: string;
|
|
323
431
|
/** The one menu to show. Leave it out to show every menu the branch serves at tables. */
|
|
324
432
|
menuId?: string;
|
package/dist/in-venue/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
import{billScope,destinationPath,publicId,scopeMessage,sortDiners,unassignedTotal}from"./bill.js";import{createInVenue}from"./client.js";import{InVenueError}from"./error.js";import{createTableClient}from"./table.js";export{InVenueError,billScope,createInVenue,createTableClient,destinationPath,publicId,scopeMessage,sortDiners,unassignedTotal};
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1 @@
|
|
|
1
1
|
"use client";import{billScope,publicId,scopeMessage,sortDiners,unassignedTotal}from"@zappie/sdk/in-venue";import{canShareReceipt}from"@zappie/sdk/receipts";import{redirectToCheckout}from"@zappie/sdk/redirect";import{lastTable,rememberTable}from"./order-panel.js";import{currentPath,errorMessage,formatMoney,go,newKey,Shell,Status,Totals,useEffect,useGuest,useId,useLoaded,useRef,useState}from"./shared.js";import{jsx,jsxs}from"react/jsx-runtime";function BillPage({orderId,payPointId,...site}){const id=publicId("ord",orderId);const first=useLoaded(id,signal=>site.inVenue.dineInOrder(id,{signal}));const[live,setLive]=useState();const{inVenue}=site;useEffect(()=>{if(first.status!=="ready"){return}const controller=new AbortController;inVenue.watchDineInOrder(id,{onBill:setLive,signal:controller.signal});return()=>controller.abort()},[inVenue,id,first.status]);useEffect(()=>{if(payPointId){rememberTable(publicId("pp",payPointId))}},[payPointId]);if(first.status!=="ready"){return jsx(Status,{state:first,site})}return jsx(Bill,{site,order:live??first.value,payPointId:payPointId?publicId("pp",payPointId):lastTable()})}function Bill({site,order,payPointId}){const guest=useGuest(site.customer);const diners=sortDiners(order.diners,guest.me);const mine=Boolean(guest.me&&diners.some(diner=>diner.id===guest.me));const[selected,setSelected]=useState([]);const[touched,setTouched]=useState(false);useEffect(()=>{if(!touched&&mine&&guest.me){setSelected([guest.me])}},[touched,mine,guest.me]);const scope=billScope(selected,diners);const scopeKey=scope.join(",");const[scoped,setScoped]=useState();const[updating,setUpdating]=useState(false);const{inVenue}=site;useEffect(()=>{if(!scopeKey){setScoped(void 0);setUpdating(false);return}const controller=new AbortController;setUpdating(true);const timer=setTimeout(()=>{inVenue.dineInOrder(order.id,{diners:scopeKey.split(","),signal:controller.signal}).then(value=>{setScoped(value);setUpdating(false)}).catch(()=>{if(!controller.signal.aborted){setUpdating(false)}})},500);return()=>{clearTimeout(timer);controller.abort()}},[inVenue,order.id,order.updated_at,scopeKey]);const view=scopeKey&&scoped?scoped:order;const paid=order.payment.status==="paid";const open=order.status==="open";const showPills=diners.length>1||Boolean(guest.me)&&!mine;const unassigned=scopeKey?unassignedTotal(order):0;const[payments,setPayments]=useState(false);const[confirming,setConfirming]=useState(false);const[paying,setPaying]=useState(false);const[failure,setFailure]=useState();const key=useRef(void 0);const confirmId=useId();const toggle=diner=>{if(diners.length===1){return}setTouched(true);setFailure(void 0);setSelected(current=>current.includes(diner)?current.filter(value=>value!==diner):[...current,diner])};const pay=async()=>{setFailure(void 0);if(!guest.authenticated){site.customer.signIn(currentPath());return}if(key.current?.scope!==scopeKey){key.current={scope:scopeKey,key:newKey()}}setPaying(true);try{const amount=view.remaining.amount_minor;const wallet=await inVenue.wallet().then(({balances})=>(balances.find(balance=>balance.currency===order.currency)?.amount_minor??0)<amount,()=>false);const payment=await inVenue.payDineInOrder(order.id,{diner_ids:scope,use_wallet_balance:wallet},key.current.key);const target=new URL(payment.url);const here=globalThis.location?.href;if(here){target.searchParams.set("return",here)}redirectToCheckout(target.toString(),globalThis.top??void 0)}catch(error){setFailure(errorMessage(error));setPaying(false)}};const start=()=>{const self=Boolean(guest.me)&&selected.length===1&&selected[0]===guest.me;if(guest.authenticated&&!self){setConfirming(true);return}void pay()};const disabled=paying||updating||view.remaining.amount_minor<=0||paid;return jsxs(Shell,{site,label:"Bill",children:[jsxs("header",{className:"z-in-venue__row",children:[jsxs("h1",{children:[order.table,paid&&jsx("span",{className:"z-in-venue__badge",children:"Paid"})]}),showPills&&jsx("button",{type:"button",className:"z-in-venue__link","aria-expanded":payments,onClick:()=>setPayments(value=>!value),children:"View payments"})]}),payments&&jsx("section",{className:"z-in-venue__panel","aria-label":"Payments",children:jsx("ul",{className:"z-in-venue__lines",children:diners.map(diner=>jsxs("li",{className:"z-in-venue__row",children:[jsx("span",{children:diner.id===guest.me?"You":diner.first_name||"Guest"}),jsx("span",{children:diner.remaining.amount_minor>0?`${formatMoney(diner.paid)} paid \xB7 ${formatMoney(diner.remaining)} left`:"Paid"})]},diner.id))})}),showPills&&jsxs("section",{className:"z-in-venue__scope","aria-label":"Whose bill",children:[jsx("div",{className:"z-in-venue__tabs",role:"group","aria-label":"Diners",children:diners.map(diner=>jsx("button",{type:"button",className:"z-in-venue__pill","aria-pressed":selected.includes(diner.id),disabled:diners.length===1,onClick:()=>toggle(diner.id),children:diner.id===guest.me?"Mine":diner.first_name||"Guest"},diner.id))}),diners.length>1&&jsxs("p",{className:"z-in-venue__muted","aria-live":"polite",children:[scopeMessage(false,scope,diners,guest.me),touched?"":" Select others to see theirs."]}),unassigned>0&&jsxs("p",{className:"z-in-venue__muted",children:[formatMoney({amount_minor:unassigned,currency:order.currency})," ","in table items isn't assigned to anyone. View everyone's bill to pay for them."]})]}),jsx("ul",{className:"z-in-venue__lines","aria-busy":updating,children:view.lines.map((line,index)=>jsxs("li",{className:"z-in-venue__line",children:[jsxs("span",{children:[line.quantity,"\xD7"]}),jsxs("span",{children:[line.name,line.choices.length>0&&jsx("small",{children:line.choices.map(choice=>choice.quantity>1?`${choice.quantity}\xD7 ${choice.name}`:choice.name).join(", ")}),line.notes&&jsx("small",{children:line.notes})]}),jsx("span",{children:formatMoney(line.total)})]},`${line.item_id}:${line.diner_id??""}:${index}`))}),jsx(Totals,{rows:[["Subtotal",formatMoney(view.subtotal)],...view.charges.map(charge=>[charge.label,formatMoney(charge.amount)]),["Total",formatMoney(view.total)],...view.paid.amount_minor>0?[["Paid",formatMoney(view.paid)]]:[],...view.paid.amount_minor>0&&!paid?[["Left to pay",formatMoney(view.remaining)]]:[]]}),jsx("p",{className:"z-in-venue__muted",children:jsx("time",{dateTime:order.placed_at,children:new Date(order.placed_at).toLocaleString()})}),order.payment.amount_paid.amount_minor>0&&jsx(Receipt,{url:inVenue.receiptUrl(order.id),read:()=>inVenue.receipt(order.id)}),failure&&jsx("p",{className:"z-in-venue__alert",role:"alert",children:failure}),confirming&&jsxs("section",{className:"z-in-venue__panel",role:"alertdialog","aria-labelledby":confirmId,children:[jsx("h2",{id:confirmId,children:"Confirm payment"}),jsx("p",{children:scopeMessage(true,scope,diners,guest.me)}),jsx("p",{className:"z-in-venue__muted",children:"You can view everyone's bill by choosing the names at the top of the page."}),jsxs("div",{className:"z-in-venue__row",children:[jsx("button",{type:"button",className:"z-in-venue__button",disabled:paying,onClick:()=>setConfirming(false),children:"Cancel"}),jsx("button",{type:"button",className:"z-in-venue__button","data-primary":"","aria-busy":paying,disabled:paying,onClick:()=>void pay(),children:paying?"Confirming\u2026":"Confirm"})]})]}),open&&!paid&&!confirming&&jsxs("div",{className:"z-in-venue__actions",children:[payPointId&&jsx("button",{type:"button",className:"z-in-venue__button",onClick:()=>go(site.navigate,`/dine-in/menus?pay_point_id=${encodeURIComponent(payPointId)}`),children:"View menus"}),jsx("button",{type:"button",className:"z-in-venue__button","data-primary":"","aria-busy":paying||site.customer.pending,disabled:disabled||site.customer.pending,onClick:start,children:"I'm ready to pay"})]})]})}function Receipt({url,read}){const[file,setFile]=useState();const share=event=>{if(!canShareReceipt()){return}event.preventDefault();(file?Promise.resolve(file):read()).then(value=>{setFile(value);return navigator.share({files:[value]})}).catch(()=>void 0)};return jsx("a",{className:"z-in-venue__button",href:url,download:true,onClick:share,children:file?"Share receipt":"Download receipt"})}export{BillPage};
|
|
2
|
-
//# sourceMappingURL=bill-page.js.map
|
|
@@ -1,2 +1 @@
|
|
|
1
1
|
"use client";import{BillPage}from"./bill-page.js";import{PayPointPage}from"./pay-point-page.js";import{notFound}from"./shared.js";import{TableMenusPage}from"./table-menus-page.js";import{jsx}from"react/jsx-runtime";var segment=value=>{try{return decodeURIComponent(value)}catch{return void 0}};function matchInVenueRoute(pathname,search=""){const query=new URLSearchParams(search);const parts=pathname.split("/").filter(Boolean);const payPointId=query.get("pay_point_id")||void 0;const optional=name=>query.get(name)||void 0;if(parts.length!==2){return void 0}const[prefix,rest]=parts;const id=segment(rest);if(!id){return void 0}if(prefix==="pay-point"){return{type:"pay-point",payPointId:id}}if(prefix==="dine-in"&&id==="menus"){if(!payPointId){return void 0}const menuId=optional("menu_id");const menuGroupId=optional("menu_group_id");return{type:"dine-in-menus",payPointId,...menuId?{menuId}:{},...menuGroupId?{menuGroupId}:{}}}if(prefix==="dine-in"){return{type:"bill",orderId:id,...payPointId?{payPointId}:{}}}return void 0}function InVenuePage({pathname,search,renderMenu,...site}){const route=matchInVenueRoute(pathname,search);if(!route){throw notFound()}if(route.type==="pay-point"){return jsx(PayPointPage,{payPointId:route.payPointId,...site},route.payPointId)}if(route.type==="bill"){return jsx(BillPage,{orderId:route.orderId,...route.payPointId?{payPointId:route.payPointId}:{},...site},route.orderId)}return jsx(TableMenusPage,{payPointId:route.payPointId,...route.menuId?{menuId:route.menuId}:{},...route.menuGroupId?{menuGroupId:route.menuGroupId}:{},renderMenu,...site},route.payPointId)}export{InVenuePage,matchInVenueRoute};
|
|
2
|
-
//# sourceMappingURL=in-venue-page.js.map
|
|
@@ -1,2 +1 @@
|
|
|
1
1
|
"use client";import{format}from"@zappie/sdk";import{useCart,useCartCatalogue,useZappie}from"@zappie/sdk/react";import{currentPath,errorMessage,go,newKey,Totals,useEffect,useId,useRef,useState}from"./shared.js";import{jsx,jsxs}from"react/jsx-runtime";var LAST_TABLE="zappie:table:last";function rememberTable(payPointId){try{globalThis.localStorage?.setItem(LAST_TABLE,payPointId)}catch{}}function lastTable(){try{return globalThis.localStorage?.getItem(LAST_TABLE)??void 0}catch{return void 0}}function lineKey(lines){return lines.map(line=>`${line.id}:${line.quantity}`).join(",")}var PLACE="zappie_place";var intentKey=payPointId=>`zappie:table:${payPointId}:place`;function takeIntent(payPointId){const location=globalThis.location;if(!new URLSearchParams(location?.search).has(PLACE)){return void 0}try{const raw=sessionStorage.getItem(intentKey(payPointId));sessionStorage.removeItem(intentKey(payPointId));const intent=raw?JSON.parse(raw):void 0;return intent&&Date.now()-intent.at<6e5?intent:void 0}catch{return void 0}}function withPlace(path,set){const url=new URL(path,"https://table.invalid");if(set){url.searchParams.set(PLACE,"1")}else{url.searchParams.delete(PLACE)}return`${url.pathname}${url.search}`}function choiceNames(line,menu){const groups=menu?.items[line.itemId]?.optionGroups??[];return line.choices.map(picked=>{const name=groups.find(group=>group.id===picked.groupId)?.choices.find(choice=>choice.id===picked.choiceId)?.name;return name&&picked.quantity>1?`${picked.quantity}\xD7 ${name}`:name}).filter(Boolean).join(", ")}function OrderPanel({site,payPoint,guest}){const{cart}=useZappie();const snapshot=useCart();const catalogue=useCartCatalogue();const{lines,isHydrated,fulfilment,actions,state,issues}=snapshot;const[open,setOpen]=useState(false);const[placing,setPlacing]=useState(false);const[failure,setFailure]=useState();const[onBill,setOnBill]=useState(false);const key=useRef(void 0);const titleId=useId();useEffect(()=>{if(!isHydrated){return}if(fulfilment?.type!=="dine_in"||fulfilment.branchId!==payPoint.branch_id||fulfilment.table!==payPoint.name||fulfilment.payPointId!==payPoint.id){cart.setFulfilment({type:"dine_in",branchId:payPoint.branch_id,table:payPoint.name,payPointId:payPoint.id})}},[cart,isHydrated,fulfilment,payPoint]);const linesKey=lineKey(lines);useEffect(()=>{if(!open||!linesKey||fulfilment?.type!=="dine_in"){return}setFailure(void 0);cart.quote().catch(error=>setFailure(errorMessage(error)))},[cart,open,linesKey,fulfilment]);const{inVenue}=site;useEffect(()=>{const orderId=payPoint.open_order_id;if(!guest.me||!orderId){setOnBill(false);return}let live=true;inVenue.dineInOrder(orderId).then(order=>{if(live){setOnBill(order.diners.some(diner=>diner.id===guest.me))}}).catch(()=>void 0);return()=>{live=false}},[inVenue,guest.me,payPoint.open_order_id]);const place=async()=>{setFailure(void 0);if(key.current?.lines!==linesKey){key.current={lines:linesKey,key:newKey()}}if(!guest.authenticated){try{sessionStorage.setItem(intentKey(payPoint.id),JSON.stringify({...key.current,at:Date.now()}))}catch{}site.customer.signIn(withPlace(currentPath(),true));return}setPlacing(true);try{const payload=cart.toCheckoutPayload();const order=await inVenue.placeDineInOrder({pay_point_id:payPoint.id,lines:payload.lines},key.current.key);cart.clear();go(site.navigate,`/dine-in/${encodeURIComponent(order.id)}?pay_point_id=${encodeURIComponent(payPoint.id)}`)}catch(error){setFailure(errorMessage(error));setPlacing(false)}};const resumed=useRef(false);useEffect(()=>{if(resumed.current||!isHydrated||!guest.authenticated||fulfilment?.type!=="dine_in"){return}resumed.current=true;const intent=takeIntent(payPoint.id);if(!intent){return}go(site.navigate,withPlace(currentPath(),false),true);setOpen(true);if(intent.lines===linesKey){key.current={lines:intent.lines,key:intent.key};void place()}});if(!isHydrated||lines.length===0){return null}const quote=state.status==="quoted"||state.status==="needs_attention"?state.quote:void 0;const blocking=issues.filter(issue=>issue.severity==="blocking");const quoting=state.status==="quoting";const label=!guest.authenticated?"Place order":onBill?"Update order":"Confirm order";if(!open){return jsx("div",{className:"z-in-venue__actions",children:jsxs("button",{type:"button",className:"z-in-venue__button","data-primary":"",onClick:()=>setOpen(true),children:["Review order (",snapshot.count,")",snapshot.subtotal?` \xB7 ${format.money(snapshot.subtotal)}`:""]})})}return jsxs("section",{className:"z-in-venue__panel","aria-labelledby":titleId,children:[jsxs("div",{className:"z-in-venue__row",children:[jsx("h2",{id:titleId,children:"Your order"}),jsx("button",{type:"button",className:"z-in-venue__link",onClick:()=>setOpen(false),children:"Keep browsing"})]}),jsx("ul",{className:"z-in-venue__lines",children:lines.map(line=>jsxs("li",{className:"z-in-venue__line",children:[jsxs("span",{className:"z-in-venue__stepper",children:[jsx("button",{type:"button","aria-label":`Remove one ${line.name}`,disabled:placing,onClick:()=>line.quantity>1?actions.update(line.id,{quantity:line.quantity-1}):actions.remove(line.id),children:"\u2212"}),jsx("span",{"aria-label":`${line.quantity} of ${line.name}`,children:line.quantity}),jsx("button",{type:"button","aria-label":`Add one more ${line.name}`,disabled:placing,onClick:()=>actions.update(line.id,{quantity:line.quantity+1}),children:"+"})]}),jsxs("span",{children:[line.name,choiceNames(line,catalogue)&&jsx("small",{children:choiceNames(line,catalogue)}),line.note&&jsx("small",{children:line.note})]}),jsx("span",{children:format.money(line.lineSubtotal)})]},line.id))}),quote&&jsx(Totals,{rows:[["Subtotal",format.money(quote.subtotal)],...quote.fees.map(fee=>[fee.label,format.money(fee.amount)]),...quote.discounts.map(discount=>[discount.label,`\u2212${format.money(discount.amount)}`]),["Total",format.money(quote.total)]]}),quoting&&!quote&&jsx("p",{className:"z-in-venue__muted",role:"status",children:"Working out your total\u2026"}),blocking.map(issue=>jsx("p",{className:"z-in-venue__alert",children:issue.message},`${issue.code}:${issue.lineId??""}`)),failure&&jsx("p",{className:"z-in-venue__alert",role:"alert",children:failure}),jsx("button",{type:"button",className:"z-in-venue__button","data-primary":"","aria-busy":placing||site.customer.pending,disabled:placing||site.customer.pending||guest.authenticated&&(blocking.length>0||quoting),onClick:()=>void place(),children:placing?"Placing your order\u2026":label})]})}export{OrderPanel,lastTable,rememberTable};
|
|
2
|
-
//# sourceMappingURL=order-panel.js.map
|
|
@@ -1,2 +1 @@
|
|
|
1
1
|
"use client";import{destinationPath}from"@zappie/sdk/in-venue";import{go,Shell,Status,useEffect,useGuest,useLoaded}from"./shared.js";import{jsx,jsxs}from"react/jsx-runtime";function PayPointPage({payPointId,...site}){const guest=useGuest(site.customer);const entry=useLoaded(guest.known?`${payPointId}:${guest.authenticated}`:void 0,signal=>site.inVenue.entry(payPointId,{signal}));const path=entry.status==="ready"?destinationPath(entry.value.destination,entry.value.pay_point_id):void 0;const unusable=entry.status==="ready"&&/^(self_service|collect_payment)/.test(entry.value.destination.type);const{navigate}=site;useEffect(()=>{if(path){go(navigate,path,true)}},[navigate,path]);if(!guest.known||entry.status==="ready"&&path){return jsx(Status,{state:{status:"loading"},site})}if(unusable){return jsx(Shell,{site,label:"Table",children:jsxs("section",{className:"z-in-venue__status",children:[jsx("h1",{children:"This table can't be used on this site"}),jsx("p",{className:"z-in-venue__muted",children:"Ask a member of staff for help."})]})})}return jsx(Status,{state:entry.status==="ready"?{status:"missing"}:entry,site})}export{PayPointPage};
|
|
2
|
-
//# sourceMappingURL=pay-point-page.js.map
|
|
@@ -30,4 +30,3 @@
|
|
|
30
30
|
.z-in-venue__stepper{display:inline-flex;align-items:center;gap:var(--z-space-2,.5em)}
|
|
31
31
|
.z-in-venue__stepper button{min-width:32px;min-height:32px;padding:0}
|
|
32
32
|
`;export{Fragment,Shell,Status,Totals,currentPath,errorMessage,formatMoney,go,newKey,notFound,settle,useCallback,useEffect,useGuest,useId,useLoaded,useMemo,useRef,useState};
|
|
33
|
-
//# sourceMappingURL=shared.js.map
|
|
@@ -1,2 +1 @@
|
|
|
1
1
|
"use client";import{createTableClient,publicId}from"@zappie/sdk/in-venue";import{ZappieProvider}from"@zappie/sdk/react";import{OrderPanel,rememberTable}from"./order-panel.js";import{Fragment,go,Shell,Status,useCallback,useEffect,useGuest,useLoaded,useMemo,useState}from"./shared.js";import{jsx,jsxs}from"react/jsx-runtime";function GroupLogo({src}){const[fit,setFit]=useState("contain");const measure=useCallback(image=>{if(image?.complete&&image.naturalWidth>0){setFit(image.naturalWidth>image.naturalHeight?"contain":"cover")}},[]);return jsx("img",{ref:measure,className:"z-in-venue__logo",src,alt:"","data-fit":fit,onLoad:event=>measure(event.currentTarget)})}function withMenu(menuId){const location=globalThis.location;const params=new URLSearchParams(location?.search??"");params.set("menu_id",menuId);return`${location?.pathname??"/dine-in/menus"}?${params}`}function TableMenusPage({payPointId,menuId,menuGroupId,renderMenu,...site}){const table=useLoaded(payPointId,signal=>site.inVenue.payPoint(payPointId,{signal}));const payPoint=table.status==="ready"?table.value:void 0;const groupId=menuGroupId??payPoint?.target.menu_group_id;const group=useLoaded(payPoint?`${payPoint.id}:${groupId??""}`:void 0,signal=>groupId?site.inVenue.menuGroup(groupId,{payPointId:payPoint.id,signal}):Promise.resolve(null));useEffect(()=>{if(payPoint){rememberTable(payPoint.id)}},[payPoint]);if(table.status!=="ready"){return jsx(Status,{state:table,site})}if(group.status!=="ready"){return jsx(Status,{state:group,site})}return jsx(TableMenus,{site,payPoint:table.value,group:group.value,menuId:menuId??table.value.target.menu_id,renderMenu})}function TableMenus({site,payPoint,group,menuId,renderMenu}){const guest=useGuest(site.customer);const menus=group?.menus??[];const chosen=menuId?publicId("menu",menuId):void 0;const selected=group&&!menus.some(menu=>menu.id===chosen)?menus[0]?.id:chosen;const tableClient=useMemo(()=>createTableClient(site.client,{branchId:payPoint.branch_id,payPointId:payPoint.id,...selected?{menuId:selected}:{}}),[site.client,payPoint.branch_id,payPoint.id,selected]);return jsxs(Shell,{site,label:"Menu",children:[jsxs("header",{className:"z-in-venue__row",children:[jsxs("div",{children:[group?.logo&&jsx(GroupLogo,{src:group.logo}),group&&jsx("p",{className:"z-in-venue__muted",children:group.name}),jsx("h1",{children:payPoint.name})]}),payPoint.open_order_id&&jsx("button",{type:"button",className:"z-in-venue__button",onClick:()=>go(site.navigate,`/dine-in/${encodeURIComponent(payPoint.open_order_id)}?pay_point_id=${encodeURIComponent(payPoint.id)}`),children:"View table bill"})]}),menus.length>1&&jsx("nav",{className:"z-in-venue__tabs","aria-label":"Menus",children:menus.map(menu=>jsx("button",{type:"button",className:"z-in-venue__pill","aria-current":menu.id===selected,onClick:()=>go(site.navigate,withMenu(menu.id),true),children:menu.name},menu.id))}),jsxs(ZappieProvider,{client:tableClient,children:[jsx(Fragment,{children:renderMenu({branchId:payPoint.branch_id,...selected?{menuId:selected}:{}})},selected??"all"),jsx(OrderPanel,{site,payPoint,guest})]})]})}export{TableMenusPage};
|
|
2
|
-
//# sourceMappingURL=table-menus-page.js.map
|
package/dist/in-venue/react.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
"use client";import{BillPage}from"./react/bill-page.js";import{InVenuePage,matchInVenueRoute}from"./react/in-venue-page.js";import{PayPointPage}from"./react/pay-point-page.js";import{TableMenusPage}from"./react/table-menus-page.js";export{BillPage,InVenuePage,PayPointPage,TableMenusPage,matchInVenueRoute};
|
|
2
|
-
//# sourceMappingURL=react.js.map
|
package/dist/in-venue/table.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
import{createZappie,RestTransport}from"@zappie/sdk";import{publicId}from"./bill.js";function tableStorage(provided,payPointId){const prefix=`zappie:table:${payPointId}:`;const area=()=>provided??globalThis.localStorage;return{getItem:key=>area().getItem(prefix+key),setItem:(key,value)=>area().setItem(prefix+key,value),removeItem:key=>area().removeItem(prefix+key)}}function tableTransport(base,menuId){const selected=base.getSelectedMenu?.bind(base);return{getStore:ctx=>base.getStore(ctx),getItem:ctx=>base.getItem(ctx),quote:(ctx,body)=>base.quote(ctx,body),getMenuVersion:ctx=>base.getMenuVersion({...ctx,fulfilment:"dineIn"}),async getMenu(ctx){if(!menuId||!selected){return base.getMenu({...ctx,fulfilment:"dineIn"})}const response=await selected({...ctx,menuId,orderContext:"dineIn"});if("notModified"in response){return response}const{completeness:_partial,...menu}=response.menu;return{menu,etag:response.etag}},...selected?{getSelectedMenu:selected}:{},...base.getCategoryPage?{getCategoryPage:base.getCategoryPage.bind(base)}:{},...base.search&&!menuId?{search:base.search.bind(base)}:{}}}function createTableClient(site,scope){const{cart:_cart,transport,...config}=site.config;const base=transport??new RestTransport({...config.baseUrl?{baseUrl:config.baseUrl}:{},...config.fetch?{fetch:config.fetch}:{}});const menuId=scope.menuId?publicId("menu",scope.menuId):void 0;const client=createZappie({...config,..._cart?.ttl?{cart:{ttl:_cart.ttl}}:{},branch:scope.branchId,transport:tableTransport(base,menuId),storage:tableStorage(config.storage,publicId("pp",scope.payPointId))});const store=site.store.peek();if(store){client._internal.hydrateStore(store)}return client}export{createTableClient};
|
|
2
|
-
//# sourceMappingURL=table.js.map
|
package/dist/in-venue/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=types.js.map
|
package/dist/in-venue/watch.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
import{wait}from"../internal/customer-http.js";import{InVenueError}from"./error.js";var ended=order=>order.status==="closed"||order.status==="voided";function watchBill(base,id,read,options){const controller=new AbortController;const pollMs=options.pollMs??15e3;let source;let failures=0;let stopped=false;const stop=()=>{if(stopped){return}stopped=true;source?.close();controller.abort();options.signal?.removeEventListener("abort",stop)};const publish=order=>{options.onBill(order);if(ended(order)){stop()}};const poll=async()=>{while(!stopped){try{publish(await read(id,controller.signal))}catch(failure){if(failure instanceof InVenueError&&failure.status!==void 0&&failure.status>=400&&failure.status<500){stop();return}}if(!stopped){await wait(pollMs,controller.signal).catch(()=>void 0)}}};const connect=()=>{if(stopped||typeof EventSource==="undefined"){void poll();return}source=new EventSource(`${base}/dine-in-orders/${encodeURIComponent(id)}/events`);source.addEventListener("bill",event=>{failures=0;let next;try{next=JSON.parse(event.data)}catch{return}publish(next)});source.onerror=()=>{source?.close();if(stopped){return}failures++;if(failures>=2){void poll()}else{connect()}}};options.signal?.addEventListener("abort",stop,{once:true});if(options.signal?.aborted){stop()}else{connect()}return stop}export{watchBill};
|
|
2
|
-
//# sourceMappingURL=watch.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
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-B8lItidz.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, i as WireQuote } from './types-
|
|
5
|
-
export { A as AppliedPerk, j as CartFix, c as CartFulfilment, e as CartIssueCode, d as CartModule, k as CartSnapshot, f as CartState, l as CartSyncAdapter, m as CartSyncDocument, n as CheckoutCustomer, D as DeliveryAddress, P as PendingFulfilment, o as WireFix, W as WireFulfilment, p as WireIssue, q as WireLine, h 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 BranchCategory, c as Category, d as CheckoutField, e as Choice, f as Currency, F as Formatters, g as Fulfilment, h as MenuSchedule, i as MenuSection, j as MoneyFormatOptions, k as OpeningTime, l as OptionCondition, P as PaymentMethodKind, m as SpecialHours, V as Variant, n as format, o as money } from './models-
|
|
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-B8lItidz.js';
|
|
4
|
+
import { g as CartIssue, a as Quote, b as CartLineInput, C as CartLine, Q as QuoteRequest, i as WireQuote } from './types-CuPaBf6k.js';
|
|
5
|
+
export { A as AppliedPerk, j as CartFix, c as CartFulfilment, e as CartIssueCode, d as CartModule, k as CartSnapshot, f as CartState, l as CartSyncAdapter, m as CartSyncDocument, n as CheckoutCustomer, D as DeliveryAddress, P as PendingFulfilment, o as WireFix, W as WireFulfilment, p as WireIssue, q as WireLine, h as WireMoney } from './types-CuPaBf6k.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-C77LjkK8.js';
|
|
7
|
+
export { b as BranchCategory, c as Category, d as CheckoutField, e as Choice, f as Currency, F as Formatters, g as Fulfilment, h as MenuSchedule, i as MenuSection, j as MoneyFormatOptions, k as OpeningTime, l as OptionCondition, P as PaymentMethodKind, m as SpecialHours, V as Variant, n as format, o as money } from './models-C77LjkK8.js';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* The error a cart method throws when a line, a fulfilment or the checkout payload is invalid.
|
|
11
|
+
* Its `code` is always `cart_invalid`, and its message is the first issue's message.
|
|
12
|
+
*/
|
|
9
13
|
declare class ZappieCartError extends ZappieError {
|
|
10
|
-
readonly issues: CartIssue[];
|
|
11
|
-
|
|
14
|
+
/** The issues that stopped the change, each with its fixes. */ readonly issues: CartIssue[];
|
|
15
|
+
/** @param issues - The issues that stopped the change, each with its fixes. */
|
|
16
|
+
constructor(
|
|
17
|
+
/** The issues that stopped the change, each with its fixes. */ issues: CartIssue[]);
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
/**
|
|
@@ -79,36 +85,54 @@ declare function validateLine(item: Item | undefined, raw: CartLineInput, ctx: {
|
|
|
79
85
|
|
|
80
86
|
/** REST connection options. A custom fetch can provide tracing or mock responses. */
|
|
81
87
|
type RestTransportOptions = {
|
|
88
|
+
/**
|
|
89
|
+
* The storefront API address. Defaults to `https://api.zappie.ai/storefront/v1`. It must be HTTPS,
|
|
90
|
+
* or HTTP on localhost, with no credentials, query or fragment.
|
|
91
|
+
*/
|
|
82
92
|
baseUrl?: string;
|
|
93
|
+
/** The fetch to call. Defaults to the global fetch. */
|
|
83
94
|
fetch?: typeof fetch;
|
|
84
95
|
};
|
|
85
96
|
/** REST read adapter for the versioned storefront API. */
|
|
86
97
|
declare class RestTransport implements Transport {
|
|
98
|
+
/** The API address requests go to, without a trailing slash. */
|
|
87
99
|
readonly baseUrl: string;
|
|
88
100
|
private fetcher;
|
|
89
101
|
constructor(opts?: RestTransportOptions);
|
|
90
102
|
private request;
|
|
91
103
|
private json;
|
|
104
|
+
/** Price a cart with `POST /quote`. Returns the quote as the API sends it, for the cart to check and map. */
|
|
92
105
|
quote(ctx: RequestCtx, body: QuoteRequest): Promise<WireQuote>;
|
|
106
|
+
/** Read the store and its branches with `GET /store`. */
|
|
93
107
|
getStore(ctx: RequestCtx): Promise<Store>;
|
|
108
|
+
/**
|
|
109
|
+
* Read a branch's catalogue with `GET /menus`, following every page cursor. Returns
|
|
110
|
+
* `notModified` when `ifNoneMatch` still matches. Throws `server_error` when the menu changes
|
|
111
|
+
* between pages.
|
|
112
|
+
*/
|
|
94
113
|
getMenu(ctx: RequestCtx & {
|
|
95
114
|
branchId: string;
|
|
96
115
|
ifNoneMatch?: string;
|
|
97
116
|
metadataOnly?: boolean;
|
|
98
117
|
fulfilment?: MenuFulfilment;
|
|
99
118
|
}): Promise<MenuResponse>;
|
|
119
|
+
/** Read one complete source menu with `GET /menus/{id}`. */
|
|
100
120
|
getSelectedMenu(ctx: SelectedMenuRequest): Promise<SelectedMenuResponse>;
|
|
121
|
+
/** Search the branch's items with `GET /items/search`, 25 at a time. */
|
|
101
122
|
search(ctx: SearchRequest): Promise<SearchPage>;
|
|
123
|
+
/** Read one page of a source menu's category with `GET /menus/{menu}/categories/{category}/items`. */
|
|
102
124
|
getCategoryPage(ctx: RequestCtx & {
|
|
103
125
|
branchId: string;
|
|
104
126
|
menuId: string;
|
|
105
127
|
categoryId: string;
|
|
106
128
|
cursor?: string;
|
|
107
129
|
}): Promise<CategoryPage>;
|
|
130
|
+
/** Read the catalogue's current versions with `GET /menus/version`. */
|
|
108
131
|
getMenuVersion(ctx: RequestCtx & {
|
|
109
132
|
branchId: string;
|
|
110
133
|
fulfilment?: MenuFulfilment;
|
|
111
134
|
}): Promise<MenuVersion>;
|
|
135
|
+
/** Read one item at a branch with `GET /items/{id}`. */
|
|
112
136
|
getItem(ctx: RequestCtx & {
|
|
113
137
|
branchId: string;
|
|
114
138
|
itemId: string;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import{ZappieCartError}from"./cart/errors.js";import{holdsForLater,isHeldQuote}from"./cart/held.js";import{previewItem}from"./cart/preview.js";import{estimateUnitPrice}from"./cart/price.js";import{resolveSourceMenu,withDefaultMenu}from"./cart/source-menu.js";import{validateLine}from"./cart/validate.js";import{createZappie}from"./client.js";import{API_VERSION}from"./config.js";import{ZappieError,isZappieError}from"./errors.js";export*from"./models.js";import{format,money}from"./money.js";import{RestTransport}from"./transport/rest.js";var VERSION=true?"0.
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import{ZappieCartError}from"./cart/errors.js";import{holdsForLater,isHeldQuote}from"./cart/held.js";import{previewItem}from"./cart/preview.js";import{estimateUnitPrice}from"./cart/price.js";import{resolveSourceMenu,withDefaultMenu}from"./cart/source-menu.js";import{validateLine}from"./cart/validate.js";import{createZappie}from"./client.js";import{API_VERSION}from"./config.js";import{ZappieError,isZappieError}from"./errors.js";export*from"./models.js";import{format,money}from"./money.js";import{RestTransport}from"./transport/rest.js";var VERSION=true?"0.29.0":"0.0.0-development";export{API_VERSION,RestTransport,VERSION,ZappieCartError,ZappieError,createZappie,estimateUnitPrice,format,holdsForLater,isHeldQuote,isZappieError,money,previewItem,resolveSourceMenu,validateLine,withDefaultMenu};
|
|
@@ -1,29 +1,42 @@
|
|
|
1
1
|
import { RequestCtx } from '../index.js';
|
|
2
|
-
import '../models-
|
|
3
|
-
import '../types-
|
|
2
|
+
import '../models-C77LjkK8.js';
|
|
3
|
+
import '../types-CuPaBf6k.js';
|
|
4
4
|
|
|
5
5
|
/** Public integration IDs and browser keys. Your app decides when to load scripts. */
|
|
6
6
|
type Integrations = {
|
|
7
|
+
/** The browser credential to load the interactive map with. Left out when maps are not set up. Test keys get the staging credential, which allows browser maps on approved storefront domains only. */
|
|
7
8
|
googleMaps?: {
|
|
8
9
|
browserKey: string;
|
|
9
10
|
};
|
|
11
|
+
/** The measurement ID to load the business's analytics tag with. Left out when the business hasn't turned it on, and always with a test key. */
|
|
10
12
|
googleAnalytics?: {
|
|
11
13
|
measurementId: string;
|
|
12
14
|
};
|
|
15
|
+
/** The pixel ID to load the business's ad pixel with. Left out when the business hasn't turned it on, and always with a test key. */
|
|
13
16
|
metaPixel?: {
|
|
14
17
|
pixelId: string;
|
|
15
18
|
};
|
|
16
19
|
};
|
|
17
20
|
/** A backend that supplies public integration IDs and browser keys without loading scripts. */
|
|
18
21
|
type IntegrationsTransport = {
|
|
22
|
+
/**
|
|
23
|
+
* Read the integrations for the request's key and API version, already in the SDK's shape.
|
|
24
|
+
*
|
|
25
|
+
* @param ctx - The key, API version and abort signal of the read.
|
|
26
|
+
*/
|
|
19
27
|
getIntegrations(ctx: RequestCtx): Promise<Integrations>;
|
|
20
28
|
};
|
|
21
29
|
/** Credentials and optional connection settings for the integrations read. */
|
|
22
30
|
type IntegrationsOptions = {
|
|
31
|
+
/** Your publishable API key. */
|
|
23
32
|
key: string;
|
|
33
|
+
/** The storefront API base. Defaults to `https://api.zappie.ai/storefront/v1`. Must be HTTPS, or HTTP on localhost. */
|
|
24
34
|
baseUrl?: string;
|
|
35
|
+
/** The `Zappie-Version` the read sends. Defaults to the SDK's `API_VERSION`. */
|
|
25
36
|
version?: string;
|
|
37
|
+
/** The fetch implementation for the read. Defaults to the global `fetch`. */
|
|
26
38
|
fetch?: typeof fetch;
|
|
39
|
+
/** A backend to read from instead of the REST API. When set, `fetch` and `baseUrl` aren't used for the read. */
|
|
27
40
|
transport?: IntegrationsTransport;
|
|
28
41
|
};
|
|
29
42
|
/**
|
|
@@ -1,2 +1 @@
|
|
|
1
1
|
import{requestWithRetry}from"../internal/customer-http.js";import{API_VERSION,RestTransport,validateConfig,ZappieError}from"../places/sdk.js";function createIntegrations(options){validateConfig({store:"integrations",key:options.key});const base=new RestTransport(options).baseUrl;return{async get(read={}){const ctx={key:options.key,version:options.version??API_VERSION,...read};if(options.transport){return options.transport.getIntegrations(ctx)}const response=await requestWithRetry(options.fetch??((input,init)=>globalThis.fetch(input,init)),`${base}/store/integrations`,{redirect:"manual",headers:{Authorization:`Bearer ${ctx.key}`,"Zappie-Version":ctx.version},...read},"Could not read storefront integrations");if(!response.ok){throw new ZappieError("server_error","Could not read storefront integrations",{status:response.status})}const value=await response.json();const record=value2=>{if(!value2||typeof value2!=="object"||Array.isArray(value2)){throw new ZappieError("server_error","Invalid storefront integrations")}return value2};const raw=record(value);const id=(value2,key)=>{const result=record(value2)[key];if(typeof result!=="string"||!result){throw new ZappieError("server_error","Invalid storefront integration ID")}return result};return{...raw.google_maps!=null?{googleMaps:{browserKey:id(raw.google_maps,"browser_key")}}:{},...raw.google_analytics!=null?{googleAnalytics:{measurementId:id(raw.google_analytics,"measurement_id")}}:{},...raw.meta_pixel!=null?{metaPixel:{pixelId:id(raw.meta_pixel,"pixel_id")}}:{}}}}}export{createIntegrations};
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
package/dist/internal/abort.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
function abortReason(signal){return signal?.reason??new DOMException("The request was aborted","AbortError")}function throwIfAborted(signal){if(signal?.aborted){throw abortReason(signal)}}function delay(ms,signal){return new Promise((resolve,reject)=>{throwIfAborted(signal);const abort=()=>{clearTimeout(timer);reject(abortReason(signal))};const timer=setTimeout(()=>{signal?.removeEventListener("abort",abort);resolve()},ms);signal?.addEventListener("abort",abort,{once:true})})}export{abortReason,delay,throwIfAborted};
|
|
2
|
-
//# sourceMappingURL=abort.js.map
|
package/dist/internal/cache.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
import{asError}from"../errors.js";import{abortReason,throwIfAborted}from"./abort.js";var REFRESH_BACKOFF_MS=1e4;var EMPTY=Object.freeze({fetchedAt:0,loading:false});var Cache=class{constructor(onError){this.onError=onError;this.entries=new Map;this.listeners=new Set;this.flights=new Map;this.subscribe=fn=>{this.listeners.add(fn);return()=>{this.listeners.delete(fn)}}}snapshot(key){return this.entries.get(key)??EMPTY}notify(){for(const fn of[...this.listeners]){fn()}}set(key,value,etag){this.entries.set(key,{value,fetchedAt:Date.now(),loading:false,...etag!==void 0?{etag}:{}});this.notify()}stale(key){const entry=this.snapshot(key);return entry.value!==void 0&&Date.now()-entry.fetchedAt>=6e4}async get(key,loader,signal){throwIfAborted(signal);const entry=this.snapshot(key);const age=Date.now()-entry.fetchedAt;if(entry.value!==void 0&&age<6e4){return entry.value}const background=entry.value!==void 0&&age<6e5;if(background&&entry.failedAt!==void 0&&Date.now()-entry.failedAt<REFRESH_BACKOFF_MS){return entry.value}let flight=this.flights.get(key);if(!flight){const controller=new AbortController;flight={controller,users:0,keepAlive:background,promise:Promise.resolve()};const current2=flight;this.flights.set(key,current2);const loading={...entry,loading:true};this.entries.set(key,loading);this.notify();current2.promise=Promise.resolve().then(()=>{throwIfAborted(controller.signal);return loader(controller.signal,entry)}).then(result=>{if(this.entries.get(key)===loading&&!controller.signal.aborted){this.set(key,result.value,result.etag);result.onStored?.()}return result.value}).catch(error=>{if(this.entries.get(key)===loading){this.entries.set(key,controller.signal.aborted?{...entry,loading:false}:{...entry,loading:false,error:asError(error),failedAt:Date.now()});this.notify();if(!controller.signal.aborted){this.onError(asError(error))}}throw controller.signal.aborted?abortReason(controller.signal):asError(error)}).finally(()=>{if(this.flights.get(key)===current2){this.flights.delete(key)}})}if(background){flight.keepAlive=true;void flight.promise.catch(()=>{});return entry.value}const current=flight;current.users++;return new Promise((resolve,reject)=>{let done=false;const finish=callback=>{if(done){return}done=true;signal?.removeEventListener("abort",abort);current.users--;callback()};const abort=()=>{finish(()=>reject(abortReason(signal)));if(current.users===0&&!current.keepAlive){current.controller.abort(abortReason(signal));if(this.flights.get(key)===current){this.flights.delete(key)}}};signal?.addEventListener("abort",abort,{once:true});current.promise.then(value=>finish(()=>resolve(value)),error=>finish(()=>reject(error)));if(signal?.aborted){abort()}})}};export{Cache};
|
|
2
|
-
//# sourceMappingURL=cache.js.map
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import{ZappieError}from"@zappie/sdk";function stableErrorCode(status,apiCode){if(status===
|
|
2
|
-
//# sourceMappingURL=customer-http.js.map
|
|
1
|
+
import{ZappieError}from"@zappie/sdk";function stableErrorCode(status,apiCode){if(status===401){return"unauthorized"}if(status===403){return apiCode==="scope_required"?apiCode:"forbidden"}if(status===404){return"not_found"}if(status===429){return"rate_limited"}return status<500?"invalid_request":"server_error"}async function apiError(response,fallback){const body=await response.json().catch(()=>void 0);const error=body?.error;const value=error&&typeof error==="object"?error:{};return{apiCode:typeof value.code==="string"?value.code:"server_error",message:typeof value.message==="string"?value.message:fallback,...typeof value.param==="string"?{param:value.param}:{},..."issues"in value?{issues:value.issues}:{}}}function wait(ms,signal){signal?.throwIfAborted();return new Promise((resolve,reject)=>{const done=()=>{signal?.removeEventListener("abort",aborted);resolve()};const timer=setTimeout(done,ms);const aborted=()=>{clearTimeout(timer);signal?.removeEventListener("abort",aborted);reject(signal?.reason??new DOMException("Aborted","AbortError"))};signal?.addEventListener("abort",aborted,{once:true})})}async function requestWithRetry(fetcher,input,init,message,retry=true){try{return await fetcher(input,{...init,credentials:"same-origin",headers:{Accept:"application/json",...init.headers}})}catch(cause){if(init.signal?.aborted){throw init.signal.reason??cause}if(!retry){throw new ZappieError("network_error",message,{cause,retryable:true})}await wait(400,init.signal??void 0);return requestWithRetry(fetcher,input,init,message,false)}}export{ZappieError,apiError,requestWithRetry,stableErrorCode,wait};
|
package/dist/internal/emitter.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
function createEmitter(){const listeners=new Map;return{on(event,fn){const set=listeners.get(event)??new Set;listeners.set(event,set);set.add(fn);return()=>{set.delete(fn)}},emit(event,payload){for(const fn of[...listeners.get(event)??[]]){try{fn(payload)}catch(error){console.error("Zappie event listener failed",error)}}}}}export{createEmitter};
|
|
2
|
-
//# sourceMappingURL=emitter.js.map
|
|
@@ -1,2 +1 @@
|
|
|
1
1
|
import{ZappieError}from"../errors.js";import{money}from"../money.js";function sumMoney(values,zero){let amount=zero.amountMinor;for(const value of values){if(value.currency!==zero.currency){throw new ZappieError("invalid_request","Cannot combine different currencies")}amount=money(amount+value.amountMinor,zero.currency).amountMinor}return money(amount,zero.currency)}function multiplyMoney(value,quantity){if(!Number.isSafeInteger(quantity)){throw new ZappieError("invalid_request","Money requires an integer quantity")}return money(value.amountMinor*quantity,value.currency)}export{multiplyMoney,sumMoney};
|
|
2
|
-
//# sourceMappingURL=money-math.js.map
|
|
@@ -1,2 +1 @@
|
|
|
1
1
|
var PREFIX="zappie:perk-hold:";function holdPerks(ids,session){try{for(const id of ids??[]){localStorage[PREFIX+id]=`${session.id} ${session.expires_at}`}}catch{}}function heldBy(id){try{const[session,until]=(localStorage.getItem(PREFIX+id)??"").split(" ");if(session&&Date.parse(until)>Date.now()){return session}localStorage.removeItem(PREFIX+id)}catch{}return void 0}function unhold(id){try{localStorage.removeItem(PREFIX+id)}catch{}}export{heldBy,holdPerks,unhold};
|
|
2
|
-
//# sourceMappingURL=perk-hold.js.map
|