@zappie/sdk 0.10.9 → 0.11.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 +25 -0
- package/README.md +99 -19
- package/dist/cart/item.d.ts +1 -1
- package/dist/{client-CtDaenmW.d.ts → client-C47e44tl.d.ts} +1 -1
- package/dist/customer/client.js +8 -8
- package/dist/customer/client.js.map +1 -1
- package/dist/customer/index.d.ts +4 -2
- package/dist/debug.js +1 -1
- package/dist/error-pages/art.js +11 -0
- package/dist/error-pages/art.js.map +6 -0
- package/dist/error-pages/index.d.ts +58 -0
- package/dist/error-pages/index.js +122 -0
- package/dist/error-pages/index.js.map +6 -0
- package/dist/error-pages/react.d.ts +20 -0
- package/dist/error-pages/react.js +66 -0
- package/dist/error-pages/react.js.map +6 -0
- package/dist/in-venue/bill.js +70 -0
- package/dist/in-venue/bill.js.map +6 -0
- package/dist/in-venue/client.js +120 -0
- package/dist/in-venue/client.js.map +6 -0
- package/dist/in-venue/error.js +19 -0
- package/dist/in-venue/error.js.map +6 -0
- package/dist/in-venue/index.d.ts +338 -0
- package/dist/in-venue/index.js +24 -0
- package/dist/in-venue/index.js.map +6 -0
- package/dist/in-venue/react/bill-page.js +348 -0
- package/dist/in-venue/react/bill-page.js.map +6 -0
- package/dist/in-venue/react/in-venue-page.js +103 -0
- package/dist/in-venue/react/in-venue-page.js.map +6 -0
- package/dist/in-venue/react/order-panel.js +281 -0
- package/dist/in-venue/react/order-panel.js.map +6 -0
- package/dist/in-venue/react/pay-point-page.js +51 -0
- package/dist/in-venue/react/pay-point-page.js.map +6 -0
- package/dist/in-venue/react/shared.js +190 -0
- package/dist/in-venue/react/shared.js.map +6 -0
- package/dist/in-venue/react/table-menus-page.js +148 -0
- package/dist/in-venue/react/table-menus-page.js.map +6 -0
- package/dist/in-venue/react.d.ts +120 -0
- package/dist/in-venue/react.js +15 -0
- package/dist/in-venue/react.js.map +6 -0
- package/dist/in-venue/table.js +63 -0
- package/dist/in-venue/table.js.map +6 -0
- package/dist/in-venue/types.js +1 -0
- package/dist/in-venue/types.js.map +6 -0
- package/dist/in-venue/watch.js +83 -0
- package/dist/in-venue/watch.js.map +6 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/integrations/index.d.ts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/persist/catalogue.d.ts +2 -2
- package/dist/receipts/index.d.ts +23 -0
- package/dist/receipts/index.js +49 -0
- package/dist/receipts/index.js.map +6 -0
- package/dist/server/index.d.ts +1 -1
- package/dist/site-error/index.d.ts +45 -0
- package/dist/site-error/index.js +33 -0
- package/dist/site-error/index.js.map +6 -0
- package/dist/site-error/react.d.ts +18 -0
- package/dist/site-error/react.js +15 -0
- package/dist/site-error/react.js.map +6 -0
- package/dist/studio/index.js +1 -0
- package/dist/testing/index.d.ts +1 -1
- package/dist/transport/search.d.ts +1 -1
- package/dist/transport/selected-menu.d.ts +2 -2
- package/dist/{types-DMMeyB5d.d.ts → types-ooHA0lwH.d.ts} +2 -0
- package/package.json +30 -2
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/in-venue/react/table-menus-page.tsx
|
|
4
|
+
import {
|
|
5
|
+
createTableClient,
|
|
6
|
+
publicId
|
|
7
|
+
} from "@zappie/sdk/in-venue";
|
|
8
|
+
import { ZappieProvider } from "@zappie/sdk/react";
|
|
9
|
+
import { Fragment, useCallback, useEffect, useMemo, useState } from "react";
|
|
10
|
+
import { OrderPanel, rememberTable } from "./order-panel.js";
|
|
11
|
+
import {
|
|
12
|
+
go,
|
|
13
|
+
Shell,
|
|
14
|
+
Status,
|
|
15
|
+
useGuest,
|
|
16
|
+
useLoaded
|
|
17
|
+
} from "./shared.js";
|
|
18
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
+
function GroupLogo({ src }) {
|
|
20
|
+
const [fit, setFit] = useState("contain");
|
|
21
|
+
const measure = useCallback((image) => {
|
|
22
|
+
if (image?.complete && image.naturalWidth > 0) {
|
|
23
|
+
setFit(image.naturalWidth > image.naturalHeight ? "contain" : "cover");
|
|
24
|
+
}
|
|
25
|
+
}, []);
|
|
26
|
+
return /* @__PURE__ */ jsx(
|
|
27
|
+
"img",
|
|
28
|
+
{
|
|
29
|
+
ref: measure,
|
|
30
|
+
className: "z-in-venue__logo",
|
|
31
|
+
src,
|
|
32
|
+
alt: "",
|
|
33
|
+
"data-fit": fit,
|
|
34
|
+
onLoad: (event) => measure(event.currentTarget)
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
function withMenu(menuId) {
|
|
39
|
+
const location = globalThis.location;
|
|
40
|
+
const params = new URLSearchParams(location?.search ?? "");
|
|
41
|
+
params.set("menu_id", menuId);
|
|
42
|
+
return `${location?.pathname ?? "/dine-in/menus"}?${params}`;
|
|
43
|
+
}
|
|
44
|
+
function TableMenusPage({
|
|
45
|
+
payPointId,
|
|
46
|
+
menuId,
|
|
47
|
+
menuGroupId,
|
|
48
|
+
renderMenu,
|
|
49
|
+
...site
|
|
50
|
+
}) {
|
|
51
|
+
const table = useLoaded(
|
|
52
|
+
payPointId,
|
|
53
|
+
(signal) => site.inVenue.payPoint(payPointId, { signal })
|
|
54
|
+
);
|
|
55
|
+
const payPoint = table.status === "ready" ? table.value : void 0;
|
|
56
|
+
const groupId = menuGroupId ?? payPoint?.target.menu_group_id;
|
|
57
|
+
const group = useLoaded(
|
|
58
|
+
payPoint ? `${payPoint.id}:${groupId ?? ""}` : void 0,
|
|
59
|
+
(signal) => groupId ? site.inVenue.menuGroup(groupId, {
|
|
60
|
+
payPointId: payPoint.id,
|
|
61
|
+
signal
|
|
62
|
+
}) : Promise.resolve(null)
|
|
63
|
+
);
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (payPoint) {
|
|
66
|
+
rememberTable(payPoint.id);
|
|
67
|
+
}
|
|
68
|
+
}, [payPoint]);
|
|
69
|
+
if (table.status !== "ready") {
|
|
70
|
+
return /* @__PURE__ */ jsx(Status, { state: table, site });
|
|
71
|
+
}
|
|
72
|
+
if (group.status !== "ready") {
|
|
73
|
+
return /* @__PURE__ */ jsx(Status, { state: group, site });
|
|
74
|
+
}
|
|
75
|
+
return /* @__PURE__ */ jsx(
|
|
76
|
+
TableMenus,
|
|
77
|
+
{
|
|
78
|
+
site,
|
|
79
|
+
payPoint: table.value,
|
|
80
|
+
group: group.value,
|
|
81
|
+
menuId: menuId ?? table.value.target.menu_id,
|
|
82
|
+
renderMenu
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
function TableMenus({
|
|
87
|
+
site,
|
|
88
|
+
payPoint,
|
|
89
|
+
group,
|
|
90
|
+
menuId,
|
|
91
|
+
renderMenu
|
|
92
|
+
}) {
|
|
93
|
+
const guest = useGuest(site.customer);
|
|
94
|
+
const menus = group?.menus ?? [];
|
|
95
|
+
const chosen = menuId ? publicId("menu", menuId) : void 0;
|
|
96
|
+
const selected = group && !menus.some((menu) => menu.id === chosen) ? menus[0]?.id : chosen;
|
|
97
|
+
const tableClient = useMemo(
|
|
98
|
+
() => createTableClient(site.client, {
|
|
99
|
+
branchId: payPoint.branch_id,
|
|
100
|
+
payPointId: payPoint.id,
|
|
101
|
+
...selected ? { menuId: selected } : {}
|
|
102
|
+
}),
|
|
103
|
+
[site.client, payPoint.branch_id, payPoint.id, selected]
|
|
104
|
+
);
|
|
105
|
+
return /* @__PURE__ */ jsxs(Shell, { site, label: "Menu", children: [
|
|
106
|
+
/* @__PURE__ */ jsxs("header", { className: "z-in-venue__row", children: [
|
|
107
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
108
|
+
group?.logo && /* @__PURE__ */ jsx(GroupLogo, { src: group.logo }),
|
|
109
|
+
group && /* @__PURE__ */ jsx("p", { className: "z-in-venue__muted", children: group.name }),
|
|
110
|
+
/* @__PURE__ */ jsx("h1", { children: payPoint.name })
|
|
111
|
+
] }),
|
|
112
|
+
payPoint.open_order_id && /* @__PURE__ */ jsx(
|
|
113
|
+
"button",
|
|
114
|
+
{
|
|
115
|
+
type: "button",
|
|
116
|
+
className: "z-in-venue__button",
|
|
117
|
+
onClick: () => go(
|
|
118
|
+
site.navigate,
|
|
119
|
+
`/dine-in/${encodeURIComponent(payPoint.open_order_id)}?pay_point_id=${encodeURIComponent(payPoint.id)}`
|
|
120
|
+
),
|
|
121
|
+
children: "View table bill"
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
] }),
|
|
125
|
+
menus.length > 1 && /* @__PURE__ */ jsx("nav", { className: "z-in-venue__tabs", "aria-label": "Menus", children: menus.map((menu) => /* @__PURE__ */ jsx(
|
|
126
|
+
"button",
|
|
127
|
+
{
|
|
128
|
+
type: "button",
|
|
129
|
+
className: "z-in-venue__pill",
|
|
130
|
+
"aria-current": menu.id === selected,
|
|
131
|
+
onClick: () => go(site.navigate, withMenu(menu.id), true),
|
|
132
|
+
children: menu.name
|
|
133
|
+
},
|
|
134
|
+
menu.id
|
|
135
|
+
)) }),
|
|
136
|
+
/* @__PURE__ */ jsxs(ZappieProvider, { client: tableClient, children: [
|
|
137
|
+
/* @__PURE__ */ jsx(Fragment, { children: renderMenu({
|
|
138
|
+
branchId: payPoint.branch_id,
|
|
139
|
+
...selected ? { menuId: selected } : {}
|
|
140
|
+
}) }, selected ?? "all"),
|
|
141
|
+
/* @__PURE__ */ jsx(OrderPanel, { site, payPoint, guest })
|
|
142
|
+
] })
|
|
143
|
+
] });
|
|
144
|
+
}
|
|
145
|
+
export {
|
|
146
|
+
TableMenusPage
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=table-menus-page.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/in-venue/react/table-menus-page.tsx"],
|
|
4
|
+
"mappings": ";;;AACA;AAAA,EACE;AAAA,EAGA;AAAA,OACK;AACP,SAAS,sB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MAAM,MAAM;AAAA,QAC3C,SAAS,oBAAC,OAAE,WAAU,qBAAqB,gBAAM,MAAK;AAAA,QACvD,oBAAC,QAAI,mBAAS,MAAK;AAAA,SACrB;AAAA,MACC,SAAS,iBACR;AAAA,QAAC;AAAA;AAAA,UACC,MAAK;AAAA,UACL,WAAU;AAAA,UACV,SAAS,MACP;AAAA,YACE,KAAK;AAAA,YACL,YAAY,mBAAmB,SAAS,aAAc,CAAC,iBAAiB,mBAAmB,SAAS,EAAE,CAAC;AAAA,UACzG;AAAA,UAEH;AAAA;AAAA,MAED;AAAA,OAEJ;AAAA,IACC,MAAM,SAAS,KACd,oBAAC,SAAI,WAAU,oBAAmB,cAAW,SAC1C,gBAAM,IAAI,CAAC,SACV;AAAA,MAAC;AAAA;AAAA,QAEC,MAAK;AAAA,QACL,WAAU;AAAA,QACV,gBAAc,KAAK,OAAO;AAAA,QAC1B,SAAS,MAAM,GAAG,KAAK,UAAU,SAAS,KAAK,EAAE,GAAG,IAAI;AAAA,QAEvD,eAAK;AAAA;AAAA,MAND,KAAK;AAAA,IAOZ,CACD,GACH;AAAA,IAEF,qBAAC,kBAAe,QAAQ,aACtB;AAAA,0BAAC,YACE,qBAAW;AAAA,QACV,UAAU,SAAS;AAAA,QACnB,GAAI,WAAW,EAAE,QAAQ,SAAS,IAAI,CAAC;AAAA,MACzC,CAAC,KAJY,YAAY,KAK3B;AAAA,MACA,oBAAC,cAAW,MAAY,UAAoB,OAAc;AAAA,OAC5D;AAAA,KACF;AAEJ;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { Zappie } from '@zappie/sdk';
|
|
4
|
+
import { CustomerClient } from '@zappie/sdk/customer';
|
|
5
|
+
import { InVenueClient } from '@zappie/sdk/in-venue';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* What every in-venue page needs from the site: its clients, its router and its own chrome.
|
|
9
|
+
*/
|
|
10
|
+
type InVenueSiteProps = {
|
|
11
|
+
/** The site's storefront client. Table pages copy its key and endpoints. */
|
|
12
|
+
client: Zappie;
|
|
13
|
+
/** The in-venue client from `createInVenue()`. */
|
|
14
|
+
inVenue: InVenueClient;
|
|
15
|
+
/** The site's customer client, for sign-in and the signed-in guest. */
|
|
16
|
+
customer: CustomerClient;
|
|
17
|
+
/** Go to a path on this site with the site's router. */
|
|
18
|
+
navigate: (href: string, options?: {
|
|
19
|
+
replace?: boolean;
|
|
20
|
+
}) => void;
|
|
21
|
+
/** The site's header, shown above the page. */
|
|
22
|
+
header?: ReactNode;
|
|
23
|
+
/** The site's footer, shown below the page. */
|
|
24
|
+
footer?: ReactNode;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Draws one menu of the table with the site's own catalogue and item sheet. It renders inside a
|
|
28
|
+
* `ZappieProvider` whose client is the table's, so `useMenu()` reads the table's menu and adding
|
|
29
|
+
* an item fills the table's bag. Leave out the site's own bag and checkout. The page brings its own.
|
|
30
|
+
*/
|
|
31
|
+
type RenderTableMenu = (props: {
|
|
32
|
+
branchId: string;
|
|
33
|
+
menuId?: string;
|
|
34
|
+
}) => ReactNode;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* What the bill page takes beyond the site's props.
|
|
38
|
+
*/
|
|
39
|
+
type BillPageProps = InVenueSiteProps & {
|
|
40
|
+
orderId: string;
|
|
41
|
+
/** The `pay_point_id` the address carries, for the way back to the table's menu. */
|
|
42
|
+
payPointId?: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* `/dine-in/:order`: the table's bill, live. It shows the table, each line, the charges and the total
|
|
46
|
+
* while unpaid, and Paid once paid. When the bill has more than one diner, a pill per diner ("Mine"
|
|
47
|
+
* for the signed-in guest) narrows the bill to the diners chosen, and "I'm ready to pay" pays for
|
|
48
|
+
* them on Zappie's payment page, which comes back to this bill.
|
|
49
|
+
*/
|
|
50
|
+
declare function BillPage({ orderId, payPointId, ...site }: BillPageProps): react.JSX.Element;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* An in-venue page the platform serves, read from a storefront path.
|
|
54
|
+
*/
|
|
55
|
+
type InVenueRoute = {
|
|
56
|
+
type: "pay-point";
|
|
57
|
+
payPointId: string;
|
|
58
|
+
} | {
|
|
59
|
+
type: "dine-in-menus";
|
|
60
|
+
payPointId: string;
|
|
61
|
+
menuId?: string;
|
|
62
|
+
menuGroupId?: string;
|
|
63
|
+
} | {
|
|
64
|
+
type: "bill";
|
|
65
|
+
orderId: string;
|
|
66
|
+
payPointId?: string;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Read an in-venue page from a path and query, as the classic app and printed table codes spell
|
|
70
|
+
* them: `/pay-point/:id`, `/dine-in/menus` and `/dine-in/:order`, with `pay_point_id`, `menu_id`
|
|
71
|
+
* and `menu_group_id`. Anything else, including a menus page without `pay_point_id`, is undefined.
|
|
72
|
+
*
|
|
73
|
+
* @param pathname - The path, such as `/dine-in/menus`.
|
|
74
|
+
* @param search - The query string, with or without its `?`.
|
|
75
|
+
*/
|
|
76
|
+
declare function matchInVenueRoute(pathname: string, search?: string): InVenueRoute | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Every in-venue page in one route component. Mount it at `pay-point/:id`, `dine-in/menus` and
|
|
79
|
+
* `dine-in/:order`, before the site's catch-all, and pass the current path and query. A path it doesn't serve,
|
|
80
|
+
* an unknown table or bill, and a failed load reach the site's own error boundary: a missing one as a thrown 404
|
|
81
|
+
* Response.
|
|
82
|
+
*/
|
|
83
|
+
declare function InVenuePage({ pathname, search, renderMenu, ...site }: InVenueSiteProps & {
|
|
84
|
+
pathname: string;
|
|
85
|
+
search?: string;
|
|
86
|
+
renderMenu: RenderTableMenu;
|
|
87
|
+
}): react.JSX.Element;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* `/pay-point/:id`: find where the guest who scanned the table lands and send them there. A diner on
|
|
91
|
+
* the table's open bill opens the bill. Anyone else gets the table's menu or menu group. A
|
|
92
|
+
* self-service or collect-payment table, which storefronts don't serve, says so and sends the guest
|
|
93
|
+
* to staff. An unknown table, a beacon, or a branch not taking table orders throws a 404 Response to the site's
|
|
94
|
+
* error boundary, and any other failure throws its error there.
|
|
95
|
+
*/
|
|
96
|
+
declare function PayPointPage({ payPointId, ...site }: InVenueSiteProps & {
|
|
97
|
+
payPointId: string;
|
|
98
|
+
}): react.JSX.Element;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* What the table menus page takes beyond the site's props.
|
|
102
|
+
*/
|
|
103
|
+
type TableMenusPageProps = InVenueSiteProps & {
|
|
104
|
+
payPointId: string;
|
|
105
|
+
/** The `menu_id` the address carries. Defaults to the menu the table pins. */
|
|
106
|
+
menuId?: string;
|
|
107
|
+
/** The `menu_group_id` the address carries. Defaults to the group the table pins. */
|
|
108
|
+
menuGroupId?: string;
|
|
109
|
+
renderMenu: RenderTableMenu;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* `/dine-in/menus`: the table's menu, drawn by the site's own catalogue.
|
|
113
|
+
* The table pins one menu, a menu group, or neither, which shows every menu the branch serves at
|
|
114
|
+
* tables. The table's name heads the page and there's no branch or fulfilment choice. At a dine-in
|
|
115
|
+
* table the guest reviews the bag, places the order onto the table's bill and can open the bill.
|
|
116
|
+
*/
|
|
117
|
+
declare function TableMenusPage({ payPointId, menuId, menuGroupId, renderMenu, ...site }: TableMenusPageProps): react.JSX.Element;
|
|
118
|
+
|
|
119
|
+
export { BillPage, InVenuePage, PayPointPage, TableMenusPage, matchInVenueRoute };
|
|
120
|
+
export type { BillPageProps, InVenueRoute, InVenueSiteProps, RenderTableMenu, TableMenusPageProps };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/in-venue/react/index.tsx
|
|
4
|
+
import { BillPage } from "./react/bill-page.js";
|
|
5
|
+
import { InVenuePage, matchInVenueRoute } from "./react/in-venue-page.js";
|
|
6
|
+
import { PayPointPage } from "./react/pay-point-page.js";
|
|
7
|
+
import { TableMenusPage } from "./react/table-menus-page.js";
|
|
8
|
+
export {
|
|
9
|
+
BillPage,
|
|
10
|
+
InVenuePage,
|
|
11
|
+
PayPointPage,
|
|
12
|
+
TableMenusPage,
|
|
13
|
+
matchInVenueRoute
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/in-venue/table.ts
|
|
2
|
+
import { createZappie, RestTransport } from "@zappie/sdk";
|
|
3
|
+
import { publicId } from "./bill.js";
|
|
4
|
+
function tableStorage(provided, payPointId) {
|
|
5
|
+
const prefix = `zappie:table:${payPointId}:`;
|
|
6
|
+
const area = () => provided ?? globalThis.localStorage;
|
|
7
|
+
return {
|
|
8
|
+
getItem: (key) => area().getItem(prefix + key),
|
|
9
|
+
setItem: (key, value) => area().setItem(prefix + key, value),
|
|
10
|
+
removeItem: (key) => area().removeItem(prefix + key)
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function tableTransport(base, menuId) {
|
|
14
|
+
const selected = base.getSelectedMenu?.bind(base);
|
|
15
|
+
return {
|
|
16
|
+
getStore: (ctx) => base.getStore(ctx),
|
|
17
|
+
getItem: (ctx) => base.getItem(ctx),
|
|
18
|
+
quote: (ctx, body) => base.quote(ctx, body),
|
|
19
|
+
getMenuVersion: (ctx) => base.getMenuVersion({ ...ctx, fulfilment: "dineIn" }),
|
|
20
|
+
async getMenu(ctx) {
|
|
21
|
+
if (!menuId || !selected) {
|
|
22
|
+
return base.getMenu({ ...ctx, fulfilment: "dineIn" });
|
|
23
|
+
}
|
|
24
|
+
const response = await selected({
|
|
25
|
+
...ctx,
|
|
26
|
+
menuId,
|
|
27
|
+
orderContext: "dineIn"
|
|
28
|
+
});
|
|
29
|
+
if ("notModified" in response) {
|
|
30
|
+
return response;
|
|
31
|
+
}
|
|
32
|
+
const { completeness: _partial, ...menu } = response.menu;
|
|
33
|
+
return { menu, etag: response.etag };
|
|
34
|
+
},
|
|
35
|
+
...selected ? { getSelectedMenu: selected } : {},
|
|
36
|
+
...base.getCategoryPage ? { getCategoryPage: base.getCategoryPage.bind(base) } : {},
|
|
37
|
+
...base.search && !menuId ? { search: base.search.bind(base) } : {}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function createTableClient(site, scope) {
|
|
41
|
+
const { cart: _cart, transport, ...config } = site.config;
|
|
42
|
+
const base = transport ?? new RestTransport({
|
|
43
|
+
...config.baseUrl ? { baseUrl: config.baseUrl } : {},
|
|
44
|
+
...config.fetch ? { fetch: config.fetch } : {}
|
|
45
|
+
});
|
|
46
|
+
const menuId = scope.menuId ? publicId("menu", scope.menuId) : void 0;
|
|
47
|
+
const client = createZappie({
|
|
48
|
+
...config,
|
|
49
|
+
..._cart?.ttl ? { cart: { ttl: _cart.ttl } } : {},
|
|
50
|
+
branch: scope.branchId,
|
|
51
|
+
transport: tableTransport(base, menuId),
|
|
52
|
+
storage: tableStorage(config.storage, publicId("pp", scope.payPointId))
|
|
53
|
+
});
|
|
54
|
+
const store = site.store.peek();
|
|
55
|
+
if (store) {
|
|
56
|
+
client._internal.hydrateStore(store);
|
|
57
|
+
}
|
|
58
|
+
return client;
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
createTableClient
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=table.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/in-venue/table.ts"],
|
|
4
|
+
"mappings": ";AAEA,SAAS,cAAc,qBAAqB;AAG5C,SAAS,gBAAgB;AAczB,SAAS,aACP,UACA,YACa;AACb,QAAM,SAAS,gBAAgB,UAAU;AACzC,QAAM,OAAO,MAAmB,YAAY,WAAW;AACvD,SAAO;AAAA,IACL,SAAS,CAAC,QAAQ,KAAK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G,OAAO,IAAI,KAAK;AACnD,QAAM,OACJ,aACA,IAAI,cAAc;AAAA,IAChB,GAAI,OAAO,UAAU,EAAE,SAAS,OAAO,QAAQ,IAAI,CAAC;AAAA,IACpD,GAAI,OAAO,QAAQ,EAAE,OAAO,OAAO,MAAM,IAAI,CAAC;AAAA,EAChD,CAAC;AACH,QAAM,SAAS,MAAM,SAAS,SAAS,QAAQ,MAAM,MAAM,IAAI;AAC/D,QAAM,SAAS,aAAa;AAAA,IAC1B,GAAG;AAAA,IACH,GAAI,OAAO,MAAM,EAAE,MAAM,EAAE,KAAK,MAAM,IAAI,EAAE,IAAI,CAAC;AAAA,IACjD,QAAQ,MAAM;AAAA,IACd,WAAW,eAAe,MAAM,MAAM;AAAA,IACtC,SAAS,aAAa,OAAO,SAAS,SAAS,MAAM,MAAM,UAAU,CAAC;AAAA,EACxE,CAAC;AACD,QAAM,QAAQ,KAAK,MAAM,KAAK;AAC9B,MAAI,OAAO;AACT,WAAO,UAAU,aAAa,KAAK;AAAA,EACrC;AACA,SAAO;AACT;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// src/in-venue/watch.ts
|
|
2
|
+
import { wait } from "../internal/customer-http.js";
|
|
3
|
+
import { InVenueError } from "./error.js";
|
|
4
|
+
var ended = (order) => order.status === "closed" || order.status === "voided";
|
|
5
|
+
function watchBill(base, id, read, options) {
|
|
6
|
+
const controller = new AbortController();
|
|
7
|
+
const pollMs = options.pollMs ?? 15e3;
|
|
8
|
+
let source;
|
|
9
|
+
let failures = 0;
|
|
10
|
+
let stopped = false;
|
|
11
|
+
const stop = () => {
|
|
12
|
+
if (stopped) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
stopped = true;
|
|
16
|
+
source?.close();
|
|
17
|
+
controller.abort();
|
|
18
|
+
options.signal?.removeEventListener("abort", stop);
|
|
19
|
+
};
|
|
20
|
+
const publish = (order) => {
|
|
21
|
+
options.onBill(order);
|
|
22
|
+
if (ended(order)) {
|
|
23
|
+
stop();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const poll = async () => {
|
|
27
|
+
while (!stopped) {
|
|
28
|
+
try {
|
|
29
|
+
publish(await read(id, controller.signal));
|
|
30
|
+
} catch (failure) {
|
|
31
|
+
if (failure instanceof InVenueError && failure.status !== void 0 && failure.status >= 400 && failure.status < 500) {
|
|
32
|
+
stop();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (!stopped) {
|
|
37
|
+
await wait(pollMs, controller.signal).catch(() => void 0);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const connect = () => {
|
|
42
|
+
if (stopped || typeof EventSource === "undefined") {
|
|
43
|
+
void poll();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
source = new EventSource(
|
|
47
|
+
`${base}/dine-in-orders/${encodeURIComponent(id)}/events`
|
|
48
|
+
);
|
|
49
|
+
source.addEventListener("bill", (event) => {
|
|
50
|
+
failures = 0;
|
|
51
|
+
let next;
|
|
52
|
+
try {
|
|
53
|
+
next = JSON.parse(event.data);
|
|
54
|
+
} catch {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
publish(next);
|
|
58
|
+
});
|
|
59
|
+
source.onerror = () => {
|
|
60
|
+
source?.close();
|
|
61
|
+
if (stopped) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
failures++;
|
|
65
|
+
if (failures >= 2) {
|
|
66
|
+
void poll();
|
|
67
|
+
} else {
|
|
68
|
+
connect();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
options.signal?.addEventListener("abort", stop, { once: true });
|
|
73
|
+
if (options.signal?.aborted) {
|
|
74
|
+
stop();
|
|
75
|
+
} else {
|
|
76
|
+
connect();
|
|
77
|
+
}
|
|
78
|
+
return stop;
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
watchBill
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=watch.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/in-venue/watch.ts"],
|
|
4
|
+
"mappings": ";AAAA,SAAS,YAAY;AACrB,SAAS,oBAAoB;AAK7B,IAAM,QAAQ,CAAC,UACb,MAAM,WAAW,YAAY,MAAM,WAAW;AAEzC,SAAS,UACd,MACA,IACA,MACA,SACY;AACZ,QAAM,aAAa,IAAI,gBAAgB;AACvC,QAAM,SAAS,QAAQ,UAAU;AACjC,MAAI;AACJ,MAAI,WAAW;AACf,MAAI,UAAU;AACd,QAAM,OAAO,MAAM;AACjB,QAAI,SAAS;AACX;AAAA,IACF;AACA,cAAU;AACV,YAAQ,MAAM;AACd,eAAW,MAAM;AACjB,YAAQ,QAAQ,oBAAoB,SAAS,IAAI;AAAA,EACnD;AACA,QAAM,UAAU,CAAC,UAAuB;AACtC,YAAQ,OAAO,KAAK;AACpB,QAAI,MAAM,KAAK,GAAG;AAChB,WAAK;AAAA,IACP;AAAA,EACF;AACA,QAAM,OAAO,YAAY;AACvB,WAAO,CAAC,SAAS;AACf,UAAI;AACF,gBAAQ,MAAM,KAAK,IAAI,WAAW,MAAM,CAAC;AAAA,MAC3C,SAAS,SAAS;AAChB,YACE,mBAAmB,gBACnB,QAAQ,WAAW,UACnB,QAAQ,UAAU,OAClB,QAAQ,SAAS,KACjB;AACA,eAAK;AACL;AAAA,QACF;AAAA,MACF;AACA,UAAI,CAAC,SAAS;AACZ,cAAM,KAAK,QAAQ,WAAW,MAAM,EAAE,MAAM,MAAM,MAAS;AAAA,MAC7D;AAAA,IACF;AAAA,EACF;AAGA,QAAM,UAAU,MAAM;AACpB,QAAI,WAAW,OAAO,gBAAgB,aAAa;AACjD,WAAK,KAAK;AACV;AAAA,IACF;AACA,aAAS,IAAI;AAAA,MACX,GAAG,IAAI,mBAAmB,mBAAmB,EAAE,CAAC;AAAA,IAClD;AACA,WAAO,iBAAiB,QAAQ,CAAC,UAAU;AACzC,iBAAW;AACX,UAAI;AACJ,UAAI;AACF,eAAO,KAAK,MAAO,MAAuB,IAAI;AAAA,MAChD,QAAQ;AACN;AAAA,MACF;AACA,cAAQ,IAAI;AAAA,IACd,CAAC;AACD,WAAO,UAAU,MAAM;AACrB,cAAQ,MAAM;AACd,UAAI,SAAS;AACX;AAAA,MACF;AACA;AACA,UAAI,YAAY,GAAG;AACjB,aAAK,KAAK;AAAA,MACZ,OAAO;AACL,gBAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACA,UAAQ,QAAQ,iBAAiB,SAAS,MAAM,EAAE,MAAM,KAAK,CAAC;AAC9D,MAAI,QAAQ,QAAQ,SAAS;AAC3B,SAAK;AAAA,EACP,OAAO;AACL,YAAQ;AAAA,EACV;AACA,SAAO;AACT;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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-C47e44tl.js';
|
|
2
2
|
import { SelectedMenuRequest, SelectedMenuResponse } from './transport/selected-menu.js';
|
|
3
|
-
export { A as API_VERSION, E as ErrorDetails, e as MenuReadOptions, M as MenuResource, n as ReadOptions, S as StorageLike, c as StoreResource, Z as Zappie, b as ZappieClientOptions, b as ZappieConfig, f as ZappieErrorCode, d as ZappieEvents, o as createZappie, p as isZappieError } from './client-
|
|
4
|
-
import { g as CartIssue, a as Quote, b as CartLineInput, C as CartLine, Q as QuoteRequest, h as WireQuote } from './types-
|
|
5
|
-
export { i as CartFix, c as CartFulfilment, e as CartIssueCode, d as CartModule, j as CartSnapshot, f as CartState, k as CartSyncAdapter, l as CartSyncDocument, D as DeliveryAddress, m as WireFix, W as WireFulfilment, n as WireIssue, o as WireLine, p as WireMoney } from './types-
|
|
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-C47e44tl.js';
|
|
4
|
+
import { g as CartIssue, a as Quote, b as CartLineInput, C as CartLine, Q as QuoteRequest, h as WireQuote } from './types-ooHA0lwH.js';
|
|
5
|
+
export { i as CartFix, c as CartFulfilment, e as CartIssueCode, d as CartModule, j as CartSnapshot, f as CartState, k as CartSyncAdapter, l as CartSyncDocument, D as DeliveryAddress, m as WireFix, W as WireFulfilment, n as WireIssue, o as WireLine, p as WireMoney } from './types-ooHA0lwH.js';
|
|
6
6
|
import { I as Item, O as OptionGroup, M as Money, a as Menu, B as Branch, S as Store, C as CategoryPage } from './models-asoc6fS3.js';
|
|
7
7
|
export { b as BranchCategory, c as Category, d as Choice, e as Currency, F as Formatters, f as Fulfilment, g as MenuSchedule, h as MenuSection, i as MoneyFormatOptions, j as OpeningTime, k as OptionCondition, P as PaymentMethodKind, l as SpecialHours, V as Variant, m as format, n as money } from './models-asoc6fS3.js';
|
|
8
8
|
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { ZappieError, isZappieError } from "./errors.js";
|
|
|
11
11
|
export * from "./models.js";
|
|
12
12
|
import { format, money } from "./money.js";
|
|
13
13
|
import { RestTransport } from "./transport/rest.js";
|
|
14
|
-
var VERSION = true ? "0.
|
|
14
|
+
var VERSION = true ? "0.11.0" : "0.0.0-development";
|
|
15
15
|
export {
|
|
16
16
|
API_VERSION,
|
|
17
17
|
RestTransport,
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { q as CATALOGUE_MAX_AGE_MS, r as CATALOGUE_MAX_BYTES, s as CatalogueScope, t as SavedCatalogue, u as catalogueDigest, w as catalogueKey, x as createCatalogueStorage, y as createSavedCatalogue } from '../client-
|
|
1
|
+
export { q as CATALOGUE_MAX_AGE_MS, r as CATALOGUE_MAX_BYTES, s as CatalogueScope, t as SavedCatalogue, u as catalogueDigest, w as catalogueKey, x as createCatalogueStorage, y as createSavedCatalogue } from '../client-C47e44tl.js';
|
|
2
2
|
import '../models-asoc6fS3.js';
|
|
3
|
-
import '../types-
|
|
3
|
+
import '../types-ooHA0lwH.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch a receipt PDF as a File named as the API names it, such as `Receipt-1042.pdf`.
|
|
3
|
+
* A refusal throws a ZappieError with its status, such as 401 for a signed-out customer or 404 for someone else's order.
|
|
4
|
+
*
|
|
5
|
+
* @param url - The receipt's address, such as `/_zappie/api/dine-in-orders/ord_1/receipt`.
|
|
6
|
+
* @param fetcher - The fetch to use. Defaults to the global fetch.
|
|
7
|
+
*/
|
|
8
|
+
declare function receiptFile(url: string, fetcher?: typeof fetch): Promise<File>;
|
|
9
|
+
/**
|
|
10
|
+
* A signed-in customer's online order receipt, from `customerBase` (`/_zappie/api` on Zappie hosting). Prefer
|
|
11
|
+
* `receipt(id)` on the customer client, which calls this.
|
|
12
|
+
*
|
|
13
|
+
* @param customerBase - The same-origin API base.
|
|
14
|
+
* @param id - The order.
|
|
15
|
+
* @param fetcher - The fetch to use. Defaults to the global fetch.
|
|
16
|
+
*/
|
|
17
|
+
declare function orderReceipt(customerBase: string, id: string, fetcher?: typeof fetch): Promise<File>;
|
|
18
|
+
/**
|
|
19
|
+
* Whether this browser can hand a PDF to the device's share sheet.
|
|
20
|
+
*/
|
|
21
|
+
declare function canShareReceipt(): boolean;
|
|
22
|
+
|
|
23
|
+
export { canShareReceipt, orderReceipt, receiptFile };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/receipts/index.ts
|
|
2
|
+
import {
|
|
3
|
+
apiError,
|
|
4
|
+
requestWithRetry,
|
|
5
|
+
stableErrorCode,
|
|
6
|
+
ZappieError
|
|
7
|
+
} from "../internal/customer-http.js";
|
|
8
|
+
async function receiptFile(url, fetcher = globalThis.fetch) {
|
|
9
|
+
const response = await requestWithRetry(
|
|
10
|
+
fetcher,
|
|
11
|
+
url,
|
|
12
|
+
{ cache: "no-store", headers: { Accept: "application/pdf" } },
|
|
13
|
+
"Could not reach the receipt"
|
|
14
|
+
);
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
const value = await apiError(response, "The receipt didn't load");
|
|
17
|
+
throw new ZappieError(
|
|
18
|
+
stableErrorCode(response.status, value.apiCode),
|
|
19
|
+
value.message,
|
|
20
|
+
{ status: response.status }
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
const name = /filename="?([^";]+)/.exec(
|
|
24
|
+
response.headers.get("content-disposition") ?? ""
|
|
25
|
+
)?.[1] ?? "Receipt.pdf";
|
|
26
|
+
return new File([await response.arrayBuffer()], name, {
|
|
27
|
+
type: "application/pdf"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function orderReceipt(customerBase, id, fetcher) {
|
|
31
|
+
return receiptFile(
|
|
32
|
+
`${customerBase}/me/orders/${encodeURIComponent(id)}/receipt`,
|
|
33
|
+
fetcher
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
function canShareReceipt() {
|
|
37
|
+
const navigator = globalThis.navigator;
|
|
38
|
+
return Boolean(
|
|
39
|
+
navigator?.canShare?.({
|
|
40
|
+
files: [new File([], "Receipt.pdf", { type: "application/pdf" })]
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
canShareReceipt,
|
|
46
|
+
orderReceipt,
|
|
47
|
+
receiptFile
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/receipts/index.ts"],
|
|
4
|
+
"mappings": ";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AASP,eAAsB,YACpB,KACA,UAAwB,WAAW,OACpB;AACf,QAAM,WAAW,MAAM;AAAA,IACrB;AAAA,IACA;AAAA,IACA,EAAE,OAAO,YAAY,SAAS,EAAE,QAAQ,kBAAkB,EAAE;AAAA,IAC5D;AAAA,EACF;AACA,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,QAAQ,MAAM,SAAS,UAAU,yBAAyB;AAChE,UAAM,IAAI;AAAA,MACR,gBAAgB,SAAS,QAAQ,MAAM,OAAO;AAAA,MAC9C,MAAM;AAAA,MACN,EAAE,QAAQ,SAAS,OAAO;AAAA,IAC5B;AAAA,EACF;AACA,QAAM,OACJ,sBAAsB;AAAA,IACpB,SAAS,QAAQ,IAAI,qBAAqB,KAAK;AAAA,EACjD,IAAI,CAAC,KAAK;AACZ,SAAO,IAAI,KAAK,CAAC,MAAM,SAAS,YAAY,CAAC,GAAG,MAAM;AAAA,IACpD,MAAM;AAAA,EACR,CAAC;AACH;AAUO,SAAS,aACd,cACA,IACA,SACe;AACf,SAAO;AAAA,IACL,GAAG,YAAY,cAAc,mBAAmB,EAAE,CAAC;AAAA,IACnD;AAAA,EACF;AACF;AAKO,SAAS,kBAA2B;AACzC,QAAM,YAAY,WAAW;AAC7B,SAAO;AAAA,IACL,WAAW,WAAW;AAAA,MACpB,OAAO,CAAC,IAAI,KAAK,CAAC,GAAG,eAAe,EAAE,MAAM,kBAAkB,CAAC,CAAC;AAAA,IAClE,CAAC;AAAA,EACH;AACF;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Branch, Store, Menu, Formatters } from '../index.js';
|
|
2
|
-
import { C as Cache } from '../client-
|
|
2
|
+
import { C as Cache } from '../client-C47e44tl.js';
|
|
3
3
|
import { ZappieError, Zappie, ZappieConfig, Transport, StorageLike, StoreResource, MenuResource, ZappieEvents, MenuReadOptions } from '../index.js';
|
|
4
4
|
export { VERSION } from '../index.js';
|
|
5
5
|
import { CartModule, CartLineInput } from '../index.js';
|