@zappie/sdk 0.28.2 → 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.
Files changed (364) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/account/index.d.ts +16 -2
  3. package/dist/account/index.js +0 -1
  4. package/dist/account/url.js +0 -1
  5. package/dist/branches/index.d.ts +2 -0
  6. package/dist/branches/index.js +0 -1
  7. package/dist/cart/branch.d.ts +18 -0
  8. package/dist/cart/branch.js +0 -1
  9. package/dist/cart/errors.js +0 -1
  10. package/dist/cart/held.js +0 -1
  11. package/dist/cart/index.js +1 -2
  12. package/dist/cart/item.d.ts +1 -1
  13. package/dist/cart/item.js +0 -1
  14. package/dist/cart/preview.js +0 -1
  15. package/dist/cart/price.js +0 -1
  16. package/dist/cart/quote-client.js +0 -1
  17. package/dist/cart/quote-response.js +1 -2
  18. package/dist/cart/quote.d.ts +1 -1
  19. package/dist/cart/reconcile.js +0 -1
  20. package/dist/cart/source-menu.js +0 -1
  21. package/dist/cart/storage.js +0 -1
  22. package/dist/cart/types.js +0 -1
  23. package/dist/cart/validate.js +0 -1
  24. package/dist/cart/wire.js +0 -1
  25. package/dist/cart/working-set.js +0 -1
  26. package/dist/checkout/client.js +0 -1
  27. package/dist/checkout/embed.d.ts +67 -2
  28. package/dist/checkout/embed.js +0 -1
  29. package/dist/checkout/error.js +0 -1
  30. package/dist/checkout/index.d.ts +74 -3
  31. package/dist/checkout/index.js +0 -1
  32. package/dist/checkout/react.d.ts +67 -2
  33. package/dist/checkout/react.js +0 -1
  34. package/dist/checkout/readiness.js +0 -1
  35. package/dist/checkout/sdk.js +0 -1
  36. package/dist/checkout/session.js +0 -1
  37. package/dist/checkout/types.js +0 -1
  38. package/dist/checkout-defaults/index.d.ts +10 -1
  39. package/dist/checkout-defaults/index.js +0 -1
  40. package/dist/{client-B89-aNcl.d.ts → client-B8lItidz.d.ts} +229 -5
  41. package/dist/client.js +0 -1
  42. package/dist/config/index.d.ts +31 -0
  43. package/dist/config/index.js +0 -1
  44. package/dist/config.js +0 -1
  45. package/dist/customer/client.js +0 -1
  46. package/dist/customer/error.js +0 -1
  47. package/dist/customer/index.d.ts +180 -5
  48. package/dist/customer/index.js +0 -1
  49. package/dist/customer/navigation.js +0 -1
  50. package/dist/customer/react.js +0 -1
  51. package/dist/customer/reorder.d.ts +8 -0
  52. package/dist/customer/reorder.js +0 -1
  53. package/dist/customer/request.js +0 -1
  54. package/dist/customer/types.js +0 -1
  55. package/dist/customer/watch-order.js +0 -1
  56. package/dist/debug.js +1 -2
  57. package/dist/display/index.d.ts +5 -1
  58. package/dist/display/index.js +0 -1
  59. package/dist/error-pages/art.js +0 -1
  60. package/dist/error-pages/index.d.ts +12 -1
  61. package/dist/error-pages/index.js +0 -1
  62. package/dist/error-pages/react.js +0 -1
  63. package/dist/errors.js +1 -2
  64. package/dist/in-venue/bill.js +0 -1
  65. package/dist/in-venue/client.js +0 -1
  66. package/dist/in-venue/error.js +0 -1
  67. package/dist/in-venue/index.d.ts +110 -2
  68. package/dist/in-venue/index.js +0 -1
  69. package/dist/in-venue/react/bill-page.js +0 -1
  70. package/dist/in-venue/react/in-venue-page.js +0 -1
  71. package/dist/in-venue/react/order-panel.js +0 -1
  72. package/dist/in-venue/react/pay-point-page.js +0 -1
  73. package/dist/in-venue/react/shared.js +0 -1
  74. package/dist/in-venue/react/table-menus-page.js +0 -1
  75. package/dist/in-venue/react.js +0 -1
  76. package/dist/in-venue/table.js +0 -1
  77. package/dist/in-venue/types.js +0 -1
  78. package/dist/in-venue/watch.js +0 -1
  79. package/dist/index.d.ts +32 -8
  80. package/dist/index.js +1 -2
  81. package/dist/integrations/index.d.ts +15 -2
  82. package/dist/integrations/index.js +0 -1
  83. package/dist/internal/abort.js +0 -1
  84. package/dist/internal/cache.js +0 -1
  85. package/dist/internal/customer-http.js +1 -2
  86. package/dist/internal/emitter.js +0 -1
  87. package/dist/internal/image-widths.js +0 -1
  88. package/dist/internal/money-math.js +0 -1
  89. package/dist/internal/perk-hold.js +0 -1
  90. package/dist/internal/remembered-address.js +0 -1
  91. package/dist/internal/return-path.js +0 -1
  92. package/dist/internal/service-url.js +0 -1
  93. package/dist/internal.d.ts +2 -2
  94. package/dist/internal.js +0 -1
  95. package/dist/loyalty/cart.js +0 -1
  96. package/dist/loyalty/client.js +0 -1
  97. package/dist/loyalty/index.d.ts +410 -2
  98. package/dist/loyalty/index.js +0 -1
  99. package/dist/loyalty/react.d.ts +15 -1
  100. package/dist/loyalty/react.js +0 -1
  101. package/dist/loyalty/release.js +0 -1
  102. package/dist/loyalty/types.js +0 -1
  103. package/dist/menu/index.d.ts +5 -1
  104. package/dist/menu/index.js +0 -1
  105. package/dist/models-C77LjkK8.d.ts +540 -0
  106. package/dist/models.js +0 -1
  107. package/dist/money.js +0 -1
  108. package/dist/navigation/index.d.ts +8 -0
  109. package/dist/navigation/index.js +0 -1
  110. package/dist/navigation/react.js +0 -1
  111. package/dist/navigation-progress/index.js +0 -1
  112. package/dist/options/index.d.ts +5 -1
  113. package/dist/options/index.js +0 -1
  114. package/dist/persist/catalogue.d.ts +3 -3
  115. package/dist/persist/catalogue.js +0 -1
  116. package/dist/places/client.js +0 -1
  117. package/dist/places/error.js +0 -1
  118. package/dist/places/index.d.ts +41 -1
  119. package/dist/places/index.js +0 -1
  120. package/dist/places/request.js +0 -1
  121. package/dist/places/sdk.js +0 -1
  122. package/dist/places/search.js +0 -1
  123. package/dist/places/types.js +0 -1
  124. package/dist/pricing/index.js +0 -1
  125. package/dist/react/cart.js +0 -1
  126. package/dist/react/changes.js +0 -1
  127. package/dist/react/hooks.js +0 -1
  128. package/dist/react/index.js +0 -1
  129. package/dist/react/provider.js +0 -1
  130. package/dist/react/rollback.js +0 -1
  131. package/dist/receipts/index.js +1 -2
  132. package/dist/redirect/index.js +0 -1
  133. package/dist/rich-text/index.d.ts +4 -0
  134. package/dist/rich-text/index.js +0 -1
  135. package/dist/server/auth/crypto.js +0 -1
  136. package/dist/server/auth/jwt.js +0 -1
  137. package/dist/server/auth/session-store.js +0 -1
  138. package/dist/server/chosen-branch.js +0 -1
  139. package/dist/server/edge-cache.js +0 -1
  140. package/dist/server/edge-snapshot.js +0 -1
  141. package/dist/server/index.d.ts +174 -6
  142. package/dist/server/index.js +0 -1
  143. package/dist/server/legacy-order.js +0 -1
  144. package/dist/server/page-cache.js +0 -1
  145. package/dist/server/security.js +0 -1
  146. package/dist/server/sign-in.js +0 -1
  147. package/dist/server/site-seo.js +0 -1
  148. package/dist/server/site-worker.js +0 -1
  149. package/dist/server/storefront-url/build-v1.js +0 -1
  150. package/dist/server/storefront-url/build-v2.js +0 -1
  151. package/dist/server/storefront-url/build.js +0 -1
  152. package/dist/server/storefront-url/canonical.js +0 -1
  153. package/dist/server/storefront-url/contract.js +0 -1
  154. package/dist/server/storefront-url/index.js +0 -1
  155. package/dist/server/storefront-url/installation.js +0 -1
  156. package/dist/server/storefront-url/params.js +0 -1
  157. package/dist/server/storefront-url/parse-v1.js +0 -1
  158. package/dist/server/storefront-url/parse-v2.js +0 -1
  159. package/dist/server/storefront-url/parse.js +0 -1
  160. package/dist/server/storefront-url/public-id.js +0 -1
  161. package/dist/server/storefront-url/redirect.js +0 -1
  162. package/dist/server/storefront-url/sign-in.js +0 -1
  163. package/dist/server/storefront-url/types.js +0 -1
  164. package/dist/server/storefront-url/url.js +0 -1
  165. package/dist/server/webhook.js +0 -1
  166. package/dist/services/index.d.ts +5 -1
  167. package/dist/services/index.js +0 -1
  168. package/dist/site-closed/index.d.ts +3 -0
  169. package/dist/site-closed/index.js +0 -1
  170. package/dist/site-config/helpers.js +0 -1
  171. package/dist/site-config/sections.js +0 -1
  172. package/dist/site-config/types.js +0 -1
  173. package/dist/site-config/validate.js +0 -1
  174. package/dist/site-error/index.d.ts +9 -1
  175. package/dist/site-error/index.js +0 -1
  176. package/dist/site-error/react.js +0 -1
  177. package/dist/studio/index.d.ts +2 -0
  178. package/dist/template/index.d.ts +7 -1
  179. package/dist/template/index.js +0 -1
  180. package/dist/template/react.js +0 -1
  181. package/dist/testing/index.d.ts +28 -1
  182. package/dist/testing/index.js +1 -1
  183. package/dist/testing/loyalty.js +0 -1
  184. package/dist/transport/category-page.js +0 -1
  185. package/dist/transport/mappers.js +0 -1
  186. package/dist/transport/presentation.js +0 -1
  187. package/dist/transport/quote-body.js +0 -1
  188. package/dist/transport/rest.js +0 -1
  189. package/dist/transport/search.d.ts +1 -1
  190. package/dist/transport/search.js +0 -1
  191. package/dist/transport/selected-menu.d.ts +3 -3
  192. package/dist/transport/selected-menu.js +0 -1
  193. package/dist/transport/store.js +0 -1
  194. package/dist/transport/types.js +0 -1
  195. package/dist/types-CuPaBf6k.d.ts +838 -0
  196. package/dist/uploads/index.js +0 -1
  197. package/dist/url/index.d.ts +31 -0
  198. package/dist/url/index.js +0 -1
  199. package/dist/visits/index.d.ts +26 -1
  200. package/dist/visits/index.js +0 -1
  201. package/dist/visits/page-views.js +0 -1
  202. package/dist/vite/index.d.ts +2 -0
  203. package/package.json +2 -2
  204. package/dist/account/index.js.map +0 -6
  205. package/dist/account/url.js.map +0 -6
  206. package/dist/branches/index.js.map +0 -6
  207. package/dist/cart/branch.js.map +0 -6
  208. package/dist/cart/errors.js.map +0 -6
  209. package/dist/cart/held.js.map +0 -6
  210. package/dist/cart/index.js.map +0 -6
  211. package/dist/cart/item.js.map +0 -6
  212. package/dist/cart/preview.js.map +0 -6
  213. package/dist/cart/price.js.map +0 -6
  214. package/dist/cart/quote-client.js.map +0 -6
  215. package/dist/cart/quote-response.js.map +0 -6
  216. package/dist/cart/reconcile.js.map +0 -6
  217. package/dist/cart/source-menu.js.map +0 -6
  218. package/dist/cart/storage.js.map +0 -6
  219. package/dist/cart/types.js.map +0 -6
  220. package/dist/cart/validate.js.map +0 -6
  221. package/dist/cart/wire.js.map +0 -6
  222. package/dist/cart/working-set.js.map +0 -6
  223. package/dist/checkout/client.js.map +0 -6
  224. package/dist/checkout/embed.js.map +0 -6
  225. package/dist/checkout/error.js.map +0 -6
  226. package/dist/checkout/index.js.map +0 -6
  227. package/dist/checkout/react.js.map +0 -6
  228. package/dist/checkout/readiness.js.map +0 -6
  229. package/dist/checkout/sdk.js.map +0 -6
  230. package/dist/checkout/session.js.map +0 -6
  231. package/dist/checkout/types.js.map +0 -6
  232. package/dist/checkout-defaults/index.js.map +0 -6
  233. package/dist/client.js.map +0 -6
  234. package/dist/config/index.js.map +0 -6
  235. package/dist/config.js.map +0 -6
  236. package/dist/customer/client.js.map +0 -6
  237. package/dist/customer/error.js.map +0 -6
  238. package/dist/customer/index.js.map +0 -6
  239. package/dist/customer/navigation.js.map +0 -6
  240. package/dist/customer/react.js.map +0 -6
  241. package/dist/customer/reorder.js.map +0 -6
  242. package/dist/customer/request.js.map +0 -6
  243. package/dist/customer/types.js.map +0 -6
  244. package/dist/customer/watch-order.js.map +0 -6
  245. package/dist/debug.js.map +0 -6
  246. package/dist/display/index.js.map +0 -6
  247. package/dist/error-pages/art.js.map +0 -6
  248. package/dist/error-pages/index.js.map +0 -6
  249. package/dist/error-pages/react.js.map +0 -6
  250. package/dist/errors.js.map +0 -6
  251. package/dist/in-venue/bill.js.map +0 -6
  252. package/dist/in-venue/client.js.map +0 -6
  253. package/dist/in-venue/error.js.map +0 -6
  254. package/dist/in-venue/index.js.map +0 -6
  255. package/dist/in-venue/react/bill-page.js.map +0 -6
  256. package/dist/in-venue/react/in-venue-page.js.map +0 -6
  257. package/dist/in-venue/react/order-panel.js.map +0 -6
  258. package/dist/in-venue/react/pay-point-page.js.map +0 -6
  259. package/dist/in-venue/react/shared.js.map +0 -6
  260. package/dist/in-venue/react/table-menus-page.js.map +0 -6
  261. package/dist/in-venue/react.js.map +0 -6
  262. package/dist/in-venue/table.js.map +0 -6
  263. package/dist/in-venue/types.js.map +0 -6
  264. package/dist/in-venue/watch.js.map +0 -6
  265. package/dist/index.js.map +0 -6
  266. package/dist/integrations/index.js.map +0 -6
  267. package/dist/internal/abort.js.map +0 -6
  268. package/dist/internal/cache.js.map +0 -6
  269. package/dist/internal/customer-http.js.map +0 -6
  270. package/dist/internal/emitter.js.map +0 -6
  271. package/dist/internal/image-widths.js.map +0 -6
  272. package/dist/internal/money-math.js.map +0 -6
  273. package/dist/internal/perk-hold.js.map +0 -6
  274. package/dist/internal/remembered-address.js.map +0 -6
  275. package/dist/internal/return-path.js.map +0 -6
  276. package/dist/internal/service-url.js.map +0 -6
  277. package/dist/internal.js.map +0 -6
  278. package/dist/loyalty/cart.js.map +0 -6
  279. package/dist/loyalty/client.js.map +0 -6
  280. package/dist/loyalty/index.js.map +0 -6
  281. package/dist/loyalty/react.js.map +0 -6
  282. package/dist/loyalty/release.js.map +0 -6
  283. package/dist/loyalty/types.js.map +0 -6
  284. package/dist/menu/index.js.map +0 -6
  285. package/dist/models-DLGs3UI2.d.ts +0 -307
  286. package/dist/models.js.map +0 -6
  287. package/dist/money.js.map +0 -6
  288. package/dist/navigation/index.js.map +0 -6
  289. package/dist/navigation/react.js.map +0 -6
  290. package/dist/navigation-progress/index.js.map +0 -6
  291. package/dist/options/index.js.map +0 -6
  292. package/dist/persist/catalogue.js.map +0 -6
  293. package/dist/places/client.js.map +0 -6
  294. package/dist/places/error.js.map +0 -6
  295. package/dist/places/index.js.map +0 -6
  296. package/dist/places/request.js.map +0 -6
  297. package/dist/places/sdk.js.map +0 -6
  298. package/dist/places/search.js.map +0 -6
  299. package/dist/places/types.js.map +0 -6
  300. package/dist/pricing/index.js.map +0 -6
  301. package/dist/react/cart.js.map +0 -6
  302. package/dist/react/changes.js.map +0 -6
  303. package/dist/react/hooks.js.map +0 -6
  304. package/dist/react/index.js.map +0 -6
  305. package/dist/react/provider.js.map +0 -6
  306. package/dist/react/rollback.js.map +0 -6
  307. package/dist/receipts/index.js.map +0 -6
  308. package/dist/redirect/index.js.map +0 -6
  309. package/dist/rich-text/index.js.map +0 -6
  310. package/dist/server/auth/crypto.js.map +0 -6
  311. package/dist/server/auth/jwt.js.map +0 -6
  312. package/dist/server/auth/session-store.js.map +0 -6
  313. package/dist/server/chosen-branch.js.map +0 -6
  314. package/dist/server/edge-cache.js.map +0 -6
  315. package/dist/server/edge-snapshot.js.map +0 -6
  316. package/dist/server/index.js.map +0 -6
  317. package/dist/server/legacy-order.js.map +0 -6
  318. package/dist/server/page-cache.js.map +0 -6
  319. package/dist/server/security.js.map +0 -6
  320. package/dist/server/sign-in.js.map +0 -6
  321. package/dist/server/site-seo.js.map +0 -6
  322. package/dist/server/site-worker.js.map +0 -6
  323. package/dist/server/storefront-url/build-v1.js.map +0 -6
  324. package/dist/server/storefront-url/build-v2.js.map +0 -6
  325. package/dist/server/storefront-url/build.js.map +0 -6
  326. package/dist/server/storefront-url/canonical.js.map +0 -6
  327. package/dist/server/storefront-url/contract.js.map +0 -6
  328. package/dist/server/storefront-url/index.js.map +0 -6
  329. package/dist/server/storefront-url/installation.js.map +0 -6
  330. package/dist/server/storefront-url/params.js.map +0 -6
  331. package/dist/server/storefront-url/parse-v1.js.map +0 -6
  332. package/dist/server/storefront-url/parse-v2.js.map +0 -6
  333. package/dist/server/storefront-url/parse.js.map +0 -6
  334. package/dist/server/storefront-url/public-id.js.map +0 -6
  335. package/dist/server/storefront-url/redirect.js.map +0 -6
  336. package/dist/server/storefront-url/sign-in.js.map +0 -6
  337. package/dist/server/storefront-url/types.js.map +0 -6
  338. package/dist/server/storefront-url/url.js.map +0 -6
  339. package/dist/server/webhook.js.map +0 -6
  340. package/dist/services/index.js.map +0 -6
  341. package/dist/site-closed/index.js.map +0 -6
  342. package/dist/site-config/helpers.js.map +0 -6
  343. package/dist/site-config/sections.js.map +0 -6
  344. package/dist/site-config/types.js.map +0 -6
  345. package/dist/site-config/validate.js.map +0 -6
  346. package/dist/site-error/index.js.map +0 -6
  347. package/dist/site-error/react.js.map +0 -6
  348. package/dist/template/index.js.map +0 -6
  349. package/dist/template/react.js.map +0 -6
  350. package/dist/testing/loyalty.js.map +0 -6
  351. package/dist/transport/category-page.js.map +0 -6
  352. package/dist/transport/mappers.js.map +0 -6
  353. package/dist/transport/presentation.js.map +0 -6
  354. package/dist/transport/quote-body.js.map +0 -6
  355. package/dist/transport/rest.js.map +0 -6
  356. package/dist/transport/search.js.map +0 -6
  357. package/dist/transport/selected-menu.js.map +0 -6
  358. package/dist/transport/store.js.map +0 -6
  359. package/dist/transport/types.js.map +0 -6
  360. package/dist/types-8HB4-7D9.d.ts +0 -457
  361. package/dist/uploads/index.js.map +0 -6
  362. package/dist/url/index.js.map +0 -6
  363. package/dist/visits/index.js.map +0 -6
  364. package/dist/visits/page-views.js.map +0 -6
@@ -1,5 +1,5 @@
1
1
  import { Branch, Store, Menu, Item, Formatters } from '../index.js';
2
- import { C as Cache } from '../client-B89-aNcl.js';
2
+ import { C as Cache } from '../client-B8lItidz.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';
@@ -12,7 +12,9 @@ type StorefrontUrlInput = string | URL | Request;
12
12
  * The business and optional default branch bound to an installed storefront.
13
13
  */
14
14
  type StorefrontInstallation = {
15
+ /** The business slug the storefront serves, the segment after `/order/` in a classic URL. */
15
16
  business: string;
17
+ /** The slug of the branch a URL means when it names none. Left out when the storefront has no default branch. */
16
18
  defaultBranch?: string;
17
19
  };
18
20
  /**
@@ -20,8 +22,20 @@ type StorefrontInstallation = {
20
22
  * An installation selects v2 unless you explicitly request v1.
21
23
  */
22
24
  type StorefrontUrlOptions = {
25
+ /**
26
+ * Which URL contract to read and write. `v1` is the classic storefront anatomy: `/order/<business>/<branch>` paths,
27
+ * `/products/<item>` for an item, and the cart, checkout and sign-in as `modal_id` and `auth_modal_id` overlays on
28
+ * the menu. `v2` is the installed site's own paths: `/` for the menu, `/item/item_<id>`, `/cart`, `/checkout`,
29
+ * `/sign-in`, `/orders` and `/account`, with the menu as `?menu=menu_<id>`, the category as a `#c-cat_<id>` hash and
30
+ * `?branch=` only for a branch other than the default. `v2` needs `installation`, and without one `v1` is used.
31
+ * Defaults to `v2` when `installation` is set.
32
+ */
23
33
  contract?: "v1" | "v2";
34
+ /** The business and default branch the storefront is installed for. Without it, every URL uses `v1`. */
24
35
  installation?: StorefrontInstallation;
36
+ /**
37
+ * The origin to make a URL absolute with, such as `https://shop.example.com`. Left out, the builders return a path.
38
+ */
25
39
  origin?: string;
26
40
  };
27
41
  /** Query keys that URL contract v1 keeps. */
@@ -38,16 +52,33 @@ type StorefrontQuery = Readonly<Record<string, string>>;
38
52
  * Query parameters and named UI selections carried alongside a storefront route.
39
53
  */
40
54
  type StorefrontPageState = {
55
+ /**
56
+ * The query parameters the contract keeps: the recognized storefront keys and attribution keys such as `utm_source`
57
+ * or `gclid`. Other keys are dropped.
58
+ */
41
59
  query: StorefrontQuery;
60
+ /** The menu ID from `menu_id`. A `v2` URL carries the menu as `menu` in `query` instead. */
42
61
  menuId?: string;
62
+ /** The category ID from `category_id`, or in `v2` from a `#c-` hash. */
43
63
  categoryId?: string;
64
+ /** The raw `menu_layout` value. */
44
65
  menuLayout?: string;
66
+ /** The fulfilment mode from `pickup`. `pickup` when it is `true`, `delivery` when it is `false`. Left out otherwise. */
45
67
  mode?: "delivery" | "pickup";
68
+ /**
69
+ * The open overlay from `modal_id`, such as `product_<item>` for an item, `review-menu` for the cart and `payment`
70
+ * for the checkout.
71
+ */
46
72
  modalId?: string;
73
+ /** The open sign-in step from `auth_modal_id`, such as `send-otp`, `verify-otp` or `update-profile`. */
47
74
  authModalId?: string;
75
+ /** The payment ID from `payment_id`. */
48
76
  paymentId?: string;
77
+ /** The raw `lightbox` value. */
49
78
  lightbox?: string;
79
+ /** The raw `catalogue_search` value. */
50
80
  catalogueSearch?: string;
81
+ /** The raw `catalogue_categories` value. */
51
82
  catalogueCategories?: string;
52
83
  };
53
84
  type WithState = {
@@ -199,7 +230,11 @@ declare function sealValue(value: unknown, { secret, purpose }: SealOptions): Pr
199
230
  declare function openSealedValue<T = unknown>(sealed: string | null | undefined, { secret, purpose }: SealOptions): Promise<T | null>;
200
231
 
201
232
  /** Signing algorithms Sign in with Zappie tokens can use. */
202
- type TokenAlgorithm = "RS256" | "ES256";
233
+ type TokenAlgorithm =
234
+ /** RSA signatures with SHA-256. */
235
+ "RS256"
236
+ /** ECDSA signatures on the P-256 curve with SHA-256. */
237
+ | "ES256";
203
238
  declare const messages: {
204
239
  malformed: string;
205
240
  unsupported_algorithm: string;
@@ -218,18 +253,29 @@ declare const messages: {
218
253
  type TokenErrorReason = keyof typeof messages;
219
254
  /** A token Zappie's identity issuer didn't sign for you, or one that is no longer valid. */
220
255
  declare class ZappieTokenError extends ZappieError {
256
+ /** Why the token was refused. `keys_unavailable` gives the error the `network_error` code, and every other reason `unauthorized`. */
221
257
  readonly reason: TokenErrorReason;
222
- constructor(reason: TokenErrorReason, cause?: unknown);
258
+ constructor(
259
+ /** Why the token was refused. `keys_unavailable` gives the error the `network_error` code, and every other reason `unauthorized`. */
260
+ reason: TokenErrorReason, cause?: unknown);
223
261
  }
224
262
  /** The verified claims of a token. Extra claims stay on the object. */
225
263
  type TokenClaims = {
264
+ /** The issuer URL. It matches the verifier's `issuer`. */
226
265
  iss: string;
266
+ /** The audience or audiences the token was issued for. One of them is the audience you verified against. */
227
267
  aud: string | string[];
268
+ /** When the token expires, in seconds since the Unix epoch. */
228
269
  exp: number;
270
+ /** The subject, such as a customer ID that starts with `cus_`. Always set when the verifier checks a subject prefix. */
229
271
  sub?: string;
272
+ /** When the token was issued, in seconds since the Unix epoch. */
230
273
  iat?: number;
274
+ /** The earliest time the token is valid, in seconds since the Unix epoch. */
231
275
  nbf?: number;
276
+ /** The nonce the sign-in sent. It matches the nonce you passed when you checked one. */
232
277
  nonce?: string;
278
+ /** The issuer's session ID for the sign-in, when it sends one. The verifier doesn't check it. */
233
279
  sid?: string;
234
280
  [claim: string]: unknown;
235
281
  };
@@ -304,17 +350,21 @@ type SessionData = {
304
350
  givenName?: string;
305
351
  phoneMasked: string;
306
352
  };
353
+ /** The access token for calling Zappie as the customer. It stays on the server. */
307
354
  accessToken: string;
308
355
  /** When the access token expires, in epoch milliseconds. */
309
356
  accessExp: number;
357
+ /** The token that gets a new access token once `accessExp` passes. */
310
358
  refreshToken: string;
311
359
  /** The issuer's session id from the ID token, for back-channel logout. */
312
360
  idTokenSid?: string;
361
+ /** The scopes the customer granted the session's access token. */
313
362
  scopes: string[];
314
363
  /** Epoch milliseconds. */
315
364
  createdAt: number;
316
365
  /** Epoch milliseconds. */
317
366
  lastSeenAt: number;
367
+ /** Whether the session is in test or live mode. `test` is a test-mode session and `live` a live one. */
318
368
  mode: "test" | "live";
319
369
  };
320
370
  /**
@@ -438,10 +488,19 @@ declare function loadStoreAndMenu(client: Zappie, request: Request, options: Res
438
488
 
439
489
  /** The part of a Worker's `ExecutionContext` the edge cache uses: work that may finish after the response. */
440
490
  type EdgeContext = {
491
+ /** Keep the Worker running until `promise` settles, such as a cache write or a stale refresh. */
441
492
  waitUntil(promise: Promise<unknown>): void;
442
493
  };
443
494
  /** How a response came from the edge cache, in the `x-zappie-edge-cache` response header. */
444
- type EdgeCacheStatus = "HIT" | "STALE" | "MISS" | "BYPASS";
495
+ type EdgeCacheStatus =
496
+ /** Served from the cache while still fresh. */
497
+ "HIT"
498
+ /** Served from the cache after its fresh time, while a refresh runs after the response. */
499
+ | "STALE"
500
+ /** Not in the cache, so it was fetched or rendered. A page that may be shared is stored for next time. */
501
+ | "MISS"
502
+ /** The cache was skipped, because the request may not use it or no cache is available. */
503
+ | "BYPASS";
445
504
  /** The response header that says how the edge cache answered. */
446
505
  declare const EDGE_CACHE_HEADER = "x-zappie-edge-cache";
447
506
  /**
@@ -460,8 +519,11 @@ declare const DATA_VERSION_HEADER = "x-zappie-data-version";
460
519
  declare function rememberDataVersion(request: Request, ctx?: EdgeContext): void;
461
520
  /** The part of the Cache API the edge cache uses: a Worker's `caches.open()` cache, or a stand-in in tests. */
462
521
  type EdgeCache = {
522
+ /** Find the stored response for `request`. Resolves to `undefined` when there is none. */
463
523
  match(request: Request): Promise<Response | undefined>;
524
+ /** Store `response` under `request`, replacing what was there. */
464
525
  put(request: Request, response: Response): Promise<void>;
526
+ /** Remove the stored response for `request`. Resolves to true when there was one. */
465
527
  delete(request: Request): Promise<boolean>;
466
528
  };
467
529
  /**
@@ -472,7 +534,9 @@ type EdgeCache = {
472
534
  declare function openEdgeCache(): Promise<EdgeCache | undefined>;
473
535
  /** How long a response may be served fresh and then stale, in seconds, from its `Cache-Control`. */
474
536
  type Freshness = {
537
+ /** How long the response is served as is, in seconds. */
475
538
  fresh: number;
539
+ /** How long after that it may be served stale while it refreshes, in seconds. */
476
540
  stale: number;
477
541
  };
478
542
  /**
@@ -608,8 +672,11 @@ declare function cachePage(request: Request, render: (request: Request) => Promi
608
672
  * returns, with the facts a snapshot writer and reader need around it.
609
673
  */
610
674
  type MenuSnapshot = {
675
+ /** The snapshot format's version. Always 1. Readers skip any other value. */
611
676
  v: 1;
677
+ /** The ID of the store the menu belongs to. */
612
678
  storeId: string;
679
+ /** The ID of the branch the menu is for. It matches `menu.branchId`. */
613
680
  branchId: string;
614
681
  /** The API's menu version, the same value `GET /menus/version` returns. */
615
682
  version: string;
@@ -624,12 +691,15 @@ type MenuSnapshot = {
624
691
  };
625
692
  /** Store details as the edge keeps them: the SDK `Store` that `store.get()` returns. */
626
693
  type StoreSnapshot = {
694
+ /** The snapshot format's version. Always 1. */
627
695
  v: 1;
696
+ /** The store's ID, the same as `store.id`. */
628
697
  storeId: string;
629
698
  /** The first 16 hex digits of the SHA-256 of the store's canonical JSON. */
630
699
  contentHash: string;
631
700
  /** When the snapshot was built, as an ISO time. */
632
701
  builtAt: string;
702
+ /** The store details. */
633
703
  store: Store;
634
704
  };
635
705
  /**
@@ -637,12 +707,15 @@ type StoreSnapshot = {
637
707
  * availability change rewrites about 1 KB instead of the whole menu.
638
708
  */
639
709
  type AvailabilityPatch = {
710
+ /** The patch format's version. Always 1. */
640
711
  v: 1;
641
712
  /** The first 16 hex digits of the SHA-256 of this patch's canonical JSON. */
642
713
  version: string;
643
714
  /** The API's menu version after this change. A patched menu reports it. */
644
715
  menuVersion: string;
716
+ /** IDs of items sold out since the snapshot, sorted and unique. */
645
717
  soldOutItems: string[];
718
+ /** IDs of variants sold out since the snapshot, sorted and unique. An item with every variant sold out is sold out too. */
646
719
  soldOutVariants: string[];
647
720
  /** Choice ids in option groups. */
648
721
  soldOutOptions: string[];
@@ -655,7 +728,9 @@ type AvailabilityPatch = {
655
728
  type SnapshotVersionRecord = {
656
729
  /** The default branch's menu version. */
657
730
  version: string;
731
+ /** When the snapshots were built, as an ISO time. */
658
732
  builtAt: string;
733
+ /** A version for each branch, keyed by branch ID. */
659
734
  branches: Record<string, string>;
660
735
  };
661
736
  /** The edge key-value names for each snapshot. */
@@ -678,17 +753,22 @@ declare function canonicalJson(value: unknown): string;
678
753
  declare function snapshotHash(value: unknown): Promise<string>;
679
754
  /** Input for building a MenuSnapshot from an SDK menu. */
680
755
  type MenuSnapshotInput = {
756
+ /** The ID of the store the menu belongs to. Required. */
681
757
  storeId: string;
758
+ /** A complete branch menu with a branch ID and a version. A partial menu throws. */
682
759
  menu: Menu;
683
760
  /** Defaults to now. */
684
761
  builtAt?: Date | string;
762
+ /** The latest change among the source menus, as a date or a time string. Left out of the snapshot when not given. */
685
763
  sourceUpdatedAt?: Date | string;
686
764
  };
687
765
  /** Build a MenuSnapshot from a complete SDK menu. */
688
766
  declare function createMenuSnapshot({ storeId, menu, builtAt, sourceUpdatedAt, }: MenuSnapshotInput): Promise<MenuSnapshot>;
689
767
  /** Input for building a MenuSnapshot from the API's menu payload. */
690
768
  type MenuSnapshotPayloadInput = {
769
+ /** The ID of the store the menu belongs to. */
691
770
  storeId: string;
771
+ /** The ID of the branch the payload is for. */
692
772
  branchId: string;
693
773
  /** The JSON body of the API's branch menu read. */
694
774
  payload: unknown;
@@ -708,10 +788,15 @@ declare function createStoreSnapshot({ store, builtAt, }: {
708
788
  }): Promise<StoreSnapshot>;
709
789
  /** Input for building an AvailabilityPatch. */
710
790
  type AvailabilityPatchInput = {
791
+ /** The API's menu version after the change. Required. */
711
792
  menuVersion: string;
793
+ /** IDs of sold-out items. Duplicates are dropped and the list is sorted. Defaults to none. */
712
794
  soldOutItems?: readonly string[];
795
+ /** IDs of sold-out variants. Duplicates are dropped and the list is sorted. Defaults to none. */
713
796
  soldOutVariants?: readonly string[];
797
+ /** IDs of sold-out choices in option groups. Duplicates are dropped and the list is sorted. Defaults to none. */
714
798
  soldOutOptions?: readonly string[];
799
+ /** When the branch reopens, if it is closed for now. Left out when the branch is open. */
715
800
  closedUntil?: Date | string;
716
801
  /** Defaults to now. */
717
802
  updatedAt?: Date | string;
@@ -794,7 +879,13 @@ type LegacyRedirects = {
794
879
  declare function legacyRedirects({ business, menuPath, pages, dropQuery, homeCatalogue, }: LegacyRedirectsOptions): LegacyRedirects;
795
880
 
796
881
  /** How a site page may be cached: shared as a menu page, shared as a static file, or never shared. */
797
- type PageCache = "menu" | "static" | "private";
882
+ type PageCache =
883
+ /** A page that renders only public data. Shared for 30 seconds, then served stale for five minutes while it refreshes. */
884
+ "menu"
885
+ /** A static file such as robots.txt or the sitemap. Shared for five minutes, then served stale for a day. */
886
+ | "static"
887
+ /** Never shared or stored. */
888
+ | "private";
798
889
  /**
799
890
  * The `Cache-Control` for each page rule. A menu page renders no customer data, so a shared cache keeps it for 30
800
891
  * seconds and serves it stale for five minutes while it refreshes. Robots and the sitemap keep for five minutes and
@@ -813,7 +904,9 @@ declare const PREVIEW_HEADERS: readonly string[];
813
904
  declare const PRIVATE_PAGES: readonly RegExp[];
814
905
  /** What a server-rendered document reports for its cache headers. */
815
906
  type DocumentCacheInput = {
907
+ /** The page's path, matched against the page rules, such as `/menu`. */
816
908
  pathname: string;
909
+ /** The response's HTTP status. Anything but 200 is `private`. */
817
910
  status: number;
818
911
  /** Draft and review previews are never shared. */
819
912
  preview: boolean;
@@ -882,17 +975,27 @@ type RouteCssBudget = number | Record<string, number>;
882
975
  * The store, theme and optional build policies you export from zappie.config.ts.
883
976
  */
884
977
  type ZappieSiteConfig = {
978
+ /** The storefront slug, the same one you pass to `createZappie()`. Required and non-empty. */
885
979
  store: string;
980
+ /** Branch slugs for this site. When set, it needs at least one non-empty slug, each listed once. */
886
981
  branches?: string[];
982
+ /** The path to your theme file, relative to the project, such as `./theme.json`. It must end in `.json`. */
887
983
  theme: string;
888
984
  /**
985
+ * Paths to prerender. Zappie hosting ignores it.
986
+ *
889
987
  * @deprecated Zappie hosting prerenders no page: every page renders in your Worker, and its page cache keeps the
890
988
  * anonymous ones. `validateConfig` warns when it is set. Remove it.
891
989
  */
892
990
  prerender?: string[];
991
+ /** Menu settings. `hiddenCategories` lists the categories to keep off the menu. */
893
992
  menu?: {
894
993
  hiddenCategories?: string[];
895
994
  };
995
+ /**
996
+ * Packages your site may depend on beyond GLOBAL_PACKAGE_ALLOWLIST. `allow` takes lowercase npm package names, such
997
+ * as `lucide-react` or `@scope/name`. `zappie check` fails a dependency that neither list allows.
998
+ */
896
999
  packages?: {
897
1000
  allow?: string[];
898
1001
  };
@@ -904,6 +1007,10 @@ type ZappieSiteConfig = {
904
1007
  until: string;
905
1008
  }[];
906
1009
  };
1010
+ /**
1011
+ * Hosts your site may send requests to. `allow` takes hostnames without a scheme, path, port or IP, such as
1012
+ * `api.example.com`, or a leading `*.` for every subdomain. The lint rules report a request to a host not listed.
1013
+ */
907
1014
  outbound?: {
908
1015
  allow?: string[];
909
1016
  };
@@ -961,6 +1068,10 @@ type ZappieSiteConfig = {
961
1068
  };
962
1069
  };
963
1070
  };
1071
+ /**
1072
+ * Analytics ids Zappie forwards storefront events to. `forward.ga4` takes a measurement id that starts with `G-`, and
1073
+ * `forward.metaPixel` takes a pixel id of digits only.
1074
+ */
964
1075
  analytics?: {
965
1076
  forward?: {
966
1077
  ga4?: string;
@@ -1095,6 +1206,7 @@ declare function robotsResponse({ preview, store, ...options }: RobotsResponseOp
1095
1206
  type SitemapOptions = {
1096
1207
  /** The site's origin. */
1097
1208
  origin: string;
1209
+ /** The store. Its slug and default branch build each branch's menu URL, and its branches are listed in order. */
1098
1210
  store: Store;
1099
1211
  /** Each branch's menu, as {@link allMenus} reads them. A `null` is skipped. */
1100
1212
  menus: readonly (Menu | null)[];
@@ -1205,28 +1317,78 @@ declare function siteWorker<Env extends SiteWorkerEnv>({ render, deployId, cache
1205
1317
  declare function originFetch(origin: string, fetcher?: typeof fetch): typeof fetch;
1206
1318
 
1207
1319
  /** Event names sent by the Zappie webhook API. */
1208
- type WebhookEventType = "menu.updated" | "branch.hours_changed" | "store.updated" | "checkout.session.completed" | "checkout.session.expired" | "order.created" | "order.paid" | "order.status_changed" | "customer.signed_in" | "payout.initiated" | "payout.paid" | "payout.failed" | "payout_request.created" | "payout_request.approved" | "payout_request.rejected" | "payment.received";
1320
+ type WebhookEventType =
1321
+ /** A menu, category, item or stock change. Changes within 2 seconds of each other at the same branch arrive as one event. */
1322
+ "menu.updated"
1323
+ /** A branch's opening hours changed. */
1324
+ | "branch.hours_changed"
1325
+ /** Any other change to the business or a branch. */
1326
+ | "store.updated"
1327
+ /** A checkout session's order was placed. */
1328
+ | "checkout.session.completed"
1329
+ /** A checkout session expired unpaid. */
1330
+ | "checkout.session.expired"
1331
+ /** A pickup or delivery order was placed. */
1332
+ | "order.created"
1333
+ /** An order was paid. */
1334
+ | "order.paid"
1335
+ /** An order moved to a new status, once for each status. */
1336
+ | "order.status_changed"
1337
+ /** A customer signed in on the business's site, at most once a minute for each customer and site. */
1338
+ | "customer.signed_in"
1339
+ /** Reserved. The API doesn't send it. */
1340
+ | "payout.initiated"
1341
+ /** Reserved. The API doesn't send it. */
1342
+ | "payout.paid"
1343
+ /** Reserved. The API doesn't send it. */
1344
+ | "payout.failed"
1345
+ /** Reserved. The API doesn't send it. */
1346
+ | "payout_request.created"
1347
+ /** Reserved. The API doesn't send it. */
1348
+ | "payout_request.approved"
1349
+ /** Reserved. The API doesn't send it. */
1350
+ | "payout_request.rejected"
1351
+ /** The business received a payment. */
1352
+ | "payment.received";
1209
1353
  /** The event envelope sent in a Zappie webhook request. */
1210
1354
  type WebhookEvent = {
1355
+ /** The event's ID, such as `evt_2Xg8Nv3Qk7Ps`. */
1211
1356
  id: string;
1357
+ /** What happened. */
1212
1358
  type: WebhookEventType;
1359
+ /** The version of the envelope's shape, as a date such as `2026-10-01`. It is not your key's pinned version. */
1213
1360
  version: string;
1361
+ /** When Zappie recorded the event, in RFC 3339 in UTC. */
1214
1362
  created_at: string;
1363
+ /** True for a live event. Every event is live today. */
1215
1364
  livemode: boolean;
1365
+ /** The ID of the business the event belongs to. */
1216
1366
  business_id: string;
1367
+ /**
1368
+ * The ID of the branch the change belongs to. Left out for a change to the whole business, for
1369
+ * `customer.signed_in`, and for a `menu.updated` that comes from an item change.
1370
+ */
1217
1371
  branch_id?: string;
1372
+ /** A key Zappie derives from the change. The same change published again carries the same key, so use it to skip repeats. */
1218
1373
  idempotency_key: string;
1374
+ /** The event's payload, in `object`. Its shape depends on `type`, and it is empty when the type has none. */
1219
1375
  data: {
1220
1376
  object: Record<string, unknown>;
1221
1377
  };
1378
+ /** Reserved for the values the change replaced. It is null on every event today. */
1222
1379
  previous_attributes: Record<string, unknown> | null;
1223
1380
  };
1224
1381
  /** Input for webhook signature verification. */
1225
1382
  type VerifyWebhookOptions = {
1383
+ /** The raw request body, exactly as it arrived. A parsed and re-serialized body fails the check. */
1226
1384
  payload: string | Uint8Array;
1385
+ /** The `Zappie-Signature` header, in the form `t=<unix seconds>,v1=<hex signature>`. Missing fails the check. */
1227
1386
  header: string | null | undefined;
1387
+ /** The endpoint's signing secret. An empty one fails the check. */
1228
1388
  secret: string;
1389
+ /** How far the header's timestamp may be from `now`, in seconds. Defaults to 300. */
1229
1390
  toleranceSec?: number;
1391
+ /** The time to check the timestamp against. Defaults to the current time. */
1230
1392
  now?: Date;
1231
1393
  };
1232
1394
  /** A webhook signature that cannot be trusted. */
@@ -1238,6 +1400,12 @@ declare function verifyWebhook({ payload, header, secret, toleranceSec, now, }:
1238
1400
 
1239
1401
  /** An edge reader that returns a Menu snapshot or null. */
1240
1402
  interface EdgeSnapshotReader {
1403
+ /**
1404
+ * Read a branch's menu from the edge. Resolves to `null` when the edge holds none.
1405
+ *
1406
+ * @param storeId - The ID of the store the menu belongs to.
1407
+ * @param branchId - The ID of the branch whose menu to read.
1408
+ */
1241
1409
  getMenu(storeId: string, branchId: string): Promise<Menu | null>;
1242
1410
  }
1243
1411
  /** Settings for your server client. Keep secret keys out of browser bundles. */
@@ -1,2 +1 @@
1
1
  import{buildClient}from"../client.js";import{VERSION}from"../index.js";import{buildStorefrontUrl,parseStorefrontUrl,STOREFRONT_QUERY_PARAMETERS,STOREFRONT_V1_QUERY_PARAMETERS,storefrontRedirect}from"../url/index.js";import{createPkce,openSealedValue,randomToken,sealValue}from"./auth/crypto.js";import{createTokenVerifier,ZappieTokenError}from"./auth/jwt.js";import{cookieSessionStore}from"./auth/session-store.js";import{loadStoreAndMenu,requestedBranch,resolveBranch}from"./chosen-branch.js";import{apiCacheBypass,apiCacheKey,cachedApiFetch,cachePage,DATA_VERSION_HEADER,EDGE_CACHE_HEADER,openEdgeCache,pageCacheBypass,pageCacheKey,pageStoreBypass,rememberDataVersion,rotatePageNonce,sharedFreshness}from"./edge-cache.js";import{applyAvailability,canonicalJson,createAvailabilityPatch,createMenuSnapshot,createStoreSnapshot,isMenuSnapshot,menuSnapshotFromPayload,snapshotHash,snapshotKeys}from"./edge-snapshot.js";import{CLASSIC_QUERY_KEYS,legacyRedirects}from"./legacy-order.js";import{deferredDataFailed,PAGE_CACHE_CONTROL,pageCacheRules,PREVIEW_HEADERS,PRIVATE_PAGES,sharedCacheControl}from"./page-cache.js";import{createSecurityNonce,inlineScriptHashes,securityHeaders}from"./security.js";import{signInRedirect}from"./sign-in.js";import{allMenus,ROBOTS_DISALLOW,robotsResponse,robotsText,sitemapResponse,sitemapUrls,sitemapXml,storeRedirect}from"./site-seo.js";import{originFetch,siteWorker}from"./site-worker.js";import{verifyWebhook,ZappieWebhookSignatureError}from"./webhook.js";function createZappieServer({secretKey,...config}){return buildClient({...config,key:secretKey},true)}export{CLASSIC_QUERY_KEYS,DATA_VERSION_HEADER,EDGE_CACHE_HEADER,PAGE_CACHE_CONTROL,PREVIEW_HEADERS,PRIVATE_PAGES,ROBOTS_DISALLOW,STOREFRONT_QUERY_PARAMETERS,STOREFRONT_V1_QUERY_PARAMETERS,VERSION,ZappieTokenError,ZappieWebhookSignatureError,allMenus,apiCacheBypass,apiCacheKey,applyAvailability,buildStorefrontUrl,cachePage,cachedApiFetch,canonicalJson,cookieSessionStore,createAvailabilityPatch,createMenuSnapshot,createPkce,createSecurityNonce,createStoreSnapshot,createTokenVerifier,createZappieServer,deferredDataFailed,inlineScriptHashes,isMenuSnapshot,legacyRedirects,loadStoreAndMenu,menuSnapshotFromPayload,openEdgeCache,openSealedValue,originFetch,pageCacheBypass,pageCacheKey,pageCacheRules,pageStoreBypass,parseStorefrontUrl,randomToken,rememberDataVersion,requestedBranch,resolveBranch,robotsResponse,robotsText,rotatePageNonce,sealValue,securityHeaders,sharedCacheControl,sharedFreshness,signInRedirect,siteWorker,sitemapResponse,sitemapUrls,sitemapXml,snapshotHash,snapshotKeys,storeRedirect,storefrontRedirect,verifyWebhook};
2
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  import{parseStorefrontUrl,storefrontRedirect}from"./storefront-url/index.js";var CLASSIC_QUERY_KEYS=Object.freeze(["modal_id","auth_modal_id","menu_id","category_id","pickup","menu_layout"]);var moved=location=>new Response(null,{status:301,headers:{location}});function withQuery(pathname,query){const search=new URLSearchParams(Object.entries(query)).toString();return search?`${pathname}?${search}`:pathname}function withSearch(target,search){const[path,hash]=target.split("#");return`${path}${search}${hash?`#${hash}`:""}`}function legacyRedirects({business,menuPath="/menu",pages="home",dropQuery=[],homeCatalogue=false}){const installation={installation:{business}};const classicKeys=Object.freeze([...CLASSIC_QUERY_KEYS,...dropQuery]);const pagePath=slug=>pages==="keep"?`/pages/${slug}`:pages==="home"?"/":pages[slug]??"/";const siteDestination=contract=>{const url=new URL(contract,"https://storefront.invalid");const category=/^#c-(.+)$/.exec(url.hash)?.[1];if(category){url.searchParams.set("category",decodeURIComponent(category))}if(url.pathname==="/"&&(url.searchParams.has("branch")||url.searchParams.has("menu")||url.searchParams.has("category"))){return`${menuPath}${url.search}`}return`${url.pathname}${url.search}`};const branchOf=pathname=>{const parts=pathname.split("/").filter(Boolean);if(parts[0]!=="order"&&parts[0]!==business){return void 0}const rest=parts[0]===business?parts.slice(1):parts[1]===business?parts.slice(2):parts.slice(1);return rest[0]&&rest[0]!=="products"&&rest[0]!=="pages"?decodeURIComponent(rest[0]):void 0};const slugOf=pathname=>/\/pages\/([^/]+)/.exec(pathname)?.[1]??"";const destination=request=>{const given=new URL(typeof request==="string"?request:request instanceof URL?request.href:request.url);const url=given.pathname===`/${business}`||given.pathname.startsWith(`/${business}/`)?new URL(`/order${given.pathname}${given.search}`,given):given;const branch=branchOf(url.pathname);const mapped=storefrontRedirect(url,installation);if(mapped){const target=new URL(siteDestination(mapped),"https://storefront.invalid");if(branch&&!target.searchParams.has("branch")){target.searchParams.set("branch",branch)}for(const key of dropQuery){target.searchParams.delete(key)}if(pages!=="keep"&&target.pathname.startsWith("/pages/")){target.searchParams.delete("branch");return withSearch(pagePath(slugOf(target.pathname)),target.search)}return`${target.pathname}${target.search}`}const kept=Object.fromEntries(Object.entries(parseStorefrontUrl(url,installation).state.query??{}).filter(([key,value])=>typeof value==="string"&&!classicKeys.includes(key)));const product=new RegExp(`^/order(?:/${business.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})?/products/([^/]+)`).exec(url.pathname)?.[1];if(/\/pages\//.test(url.pathname)){const[path="/",hash]=pagePath(slugOf(url.pathname)).split("#");return`${withQuery(path,kept)}${hash?`#${hash}`:""}`}if(product){return withQuery(`/item/item_${product}`,kept)}if(url.pathname==="/profile"||url.pathname.startsWith("/profile/")){return withQuery("/account",kept)}if(branch){return withQuery(menuPath,{branch,...kept})}return withQuery("/",kept)};return{classicKeys,destination,siteDestination,classicHome(request){const url=new URL(request.url);if(url.pathname!=="/"){return void 0}if(classicKeys.some(key=>url.searchParams.has(key))){return moved(destination(url))}if(homeCatalogue&&(url.searchParams.has("branch")||url.searchParams.has("menu"))){return moved(siteDestination(`${url.pathname}${url.search}`))}return void 0},response:request=>moved(destination(request))}}export{CLASSIC_QUERY_KEYS,legacyRedirects};
2
- //# sourceMappingURL=legacy-order.js.map
@@ -1,2 +1 @@
1
1
  var PAGE_CACHE_CONTROL=Object.freeze({menu:"public, s-maxage=30, stale-while-revalidate=300",static:"public, s-maxage=300, stale-while-revalidate=86400",private:"private, no-store"});var PREVIEW_HEADERS=Object.freeze(["X-Zappie-Draft","X-Zappie-Review"]);var PRIVATE_PAGES=Object.freeze([/^\/_zappie(?:\/|$)/,/^\/cart\/?$/,/^\/checkout(?:\/|$)/,/^\/orders?(?:\/|$)/,/^\/account(?:\/|$)/,/^\/sign-in\/?$/]);function pageCacheRules(options){const menu=[...options.menu];const privatePages=[...options.private??PRIVATE_PAGES];const pageCacheFor=pathname=>{if(privatePages.some(pattern=>pattern.test(pathname))){return"private"}if(menu.some(pattern=>pattern.test(pathname))){return"menu"}return"private"};const documentCacheRule=input=>input.status!==200||input.preview||input.failed||input.setsCookie?"private":pageCacheFor(input.pathname);return{pageCacheFor,pageCacheControl(url){if(!url.pathname.endsWith(".data")){return void 0}const page=url.pathname.slice(0,-".data".length).replace(/^\/_(?:root)?$/,"/");const rule=pageCacheFor(page||"/");return rule==="private"?void 0:PAGE_CACHE_CONTROL[rule]},documentCacheRule,documentCacheHeaders(input){const rule=documentCacheRule(input);const headers={"cache-control":PAGE_CACHE_CONTROL[rule]};if(rule!=="private"){headers.vary=["Accept-Encoding",...PREVIEW_HEADERS].join(", ")}if(rule==="menu"&&input.menuVersion&&input.storeVersion){headers.etag=`W/"${input.menuVersion}-${input.storeVersion}-${input.deployId??"dev"}"`}return headers}}}function sharedCacheControl(value){return!/\b(?:private|no-store)\b/i.test(value)}var thenable=value=>typeof value?.then==="function";async function deferredDataFailed(loaderData){const deferred=Object.values(loaderData).flatMap(data=>data&&typeof data==="object"&&!thenable(data)?Object.values(data):[data]).filter(thenable);if(!deferred.length){return false}const settled=Promise.allSettled(deferred).then(results=>results.some(result=>result.status==="rejected"));return Promise.race([settled,new Promise(resolve=>setTimeout(resolve,0,true))])}export{PAGE_CACHE_CONTROL,PREVIEW_HEADERS,PRIVATE_PAGES,deferredDataFailed,pageCacheRules,sharedCacheControl};
2
- //# sourceMappingURL=page-cache.js.map
@@ -1,2 +1 @@
1
1
  import{hostname,record}from"../site-config/helpers.js";var DEFAULT_SOURCES={"img-src":["'self'","data:","https:"],"connect-src":["'self'"],"font-src":["'self'","https://fonts.gstatic.com"],"style-src":["'self'","'unsafe-inline'","https://fonts.googleapis.com"],"frame-src":["https://checkout.zappie.ai","https://elements.zappie.ai","https://accounts.zappie.ai"]};var sourceNames={imgSrc:"img-src",connectSrc:"connect-src",fontSrc:"font-src",styleSrc:"style-src",frameSrc:"frame-src"};var base64=bytes=>btoa(String.fromCharCode(...bytes));function createSecurityNonce(){return base64(crypto.getRandomValues(new Uint8Array(18))).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}async function inlineScriptHashes(html){const hashes=await Promise.all([...html.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)].filter(([,attributes=""])=>!/(?:^|\s)src\s*=/i.test(attributes)).map(async([,,source=""])=>{const digest=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(source));return`'sha256-${base64(new Uint8Array(digest))}'`}));return[...new Set(hashes)]}function apiOrigin(value){if(value===void 0){return"https://storefront-api.zappie.ai"}try{const url=new URL(value);if(url.protocol==="https:"||url.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(url.hostname)){return url.origin}}catch{return void 0}return void 0}function configuredSources(config){const configured=new Map;const csp=config?.security?.csp;if(!record(csp)){return configured}for(const[name,values]of Object.entries(csp)){const directive=sourceNames[name];if(!directive||!Array.isArray(values)){continue}const valid=values.filter(value=>typeof value==="string"&&!/[;,\s]/.test(value)&&hostname(value));configured.set(directive,valid.map(host=>`https://${host}`))}return configured}function securityHeaders(options={}){if(!options.nonce&&!options.scriptHashes?.length){throw new TypeError("securityHeaders needs a nonce or an inline script hash.")}const sources=Object.fromEntries(Object.entries(DEFAULT_SOURCES).map(([name,values])=>[name,[...values]]));const storefrontApiOrigin=apiOrigin(options.apiUrl);if(storefrontApiOrigin){sources["connect-src"].push(storefrontApiOrigin)}for(const[name,values]of configuredSources(options.config)){sources[name].push(...values)}const outbound=options.config?.outbound?.allow;if(Array.isArray(outbound)){sources["connect-src"].push(...outbound.filter(host=>typeof host==="string"&&!/[;,\s]/.test(host)&&hostname(host)).map(host=>`https://${host}`))}for(const values of Object.values(sources)){values.splice(0,values.length,...new Set(values))}const scriptSources=["'self'",...options.nonce?[`'nonce-${options.nonce}'`]:[],...options.scriptHashes??[],"'strict-dynamic'"];const directives=["default-src 'self'",`script-src ${scriptSources.join(" ")}`,...Object.entries(sources).map(([name,values])=>`${name} ${values.join(" ")}`),"form-action 'self' https://accounts.zappie.ai https://checkout.zappie.ai","base-uri 'self'","object-src 'none'",...!options.hosted?["frame-ancestors 'self'"]:[],"report-uri /_zappie/csp"];const headers=new Headers(options.headers);headers.set("content-security-policy-report-only",directives.join("; "));headers.set("strict-transport-security","max-age=31536000");headers.set("x-content-type-options","nosniff");headers.set("referrer-policy","strict-origin-when-cross-origin");headers.set("permissions-policy",'camera=(), microphone=(), usb=(), geolocation=(self), payment=(self "https://checkout.zappie.ai")');return headers}export{createSecurityNonce,inlineScriptHashes,securityHeaders};
2
- //# sourceMappingURL=security.js.map
@@ -1,2 +1 @@
1
1
  import{sameOriginPath}from"../internal/return-path.js";function signInRedirect(returnTo,init={}){const path=typeof returnTo==="object"&&returnTo!==null?new URL(returnTo instanceof URL?returnTo:returnTo.url).searchParams.get("return"):returnTo;const headers=new Headers(init.headers);headers.set("Location",`/_zappie/login?return=${encodeURIComponent(sameOriginPath(path)??"/")}`);headers.set("X-Remix-Reload-Document","true");return new Response(null,{...init,status:init.status??302,headers})}export{signInRedirect};
2
- //# sourceMappingURL=sign-in.js.map
@@ -1,4 +1,3 @@
1
1
  import{PAGE_CACHE_CONTROL}from"./page-cache.js";import{buildStorefrontUrl}from"./storefront-url/index.js";function storeRedirect(store,pathname){const clean=pathname.length>1?pathname.replace(/\/+$/,""):pathname;return store.seo?.redirects.find(entry=>entry.from===clean)?.to}function allMenus(client,store,{limit=8}={}){return Promise.all(store.branches.slice(0,limit).map(branch=>client.menu.get({branch:branch.id}).catch(()=>null)))}var ROBOTS_DISALLOW=Object.freeze(["/checkout","/account","/orders"]);function robotsText({origin,hidden,disallow=ROBOTS_DISALLOW}){if(hidden){return"User-agent: *\nDisallow: /\n"}const lines=["User-agent: *","Allow: /",...disallow.map(path=>`Disallow: ${path}`),"Disallow: /_zappie/",`Sitemap: ${origin}/sitemap.xml`];return`${lines.join("\n")}
2
2
  `}async function robotsResponse({preview,store,...options}){const hidden=preview||(await store()).seo?.hidden===true;return new Response(robotsText({...options,hidden}),{headers:{"content-type":"text/plain; charset=utf-8","cache-control":PAGE_CACHE_CONTROL[preview?"private":"static"]}})}function sitemapUrls({origin,store,menus,home=true,pages=[],branchMenus=true,items=()=>true}){const defaultBranch=store.branches.find(branch=>branch.isDefault)?.slug;const installation={business:store.slug,...defaultBranch?{defaultBranch}:{}};const urls=new Set;if(home){urls.add(`${origin}/`)}for(const page of pages){urls.add(new URL(page,origin).href)}if(branchMenus){for(const branch of store.branches){urls.add(typeof branchMenus==="function"?new URL(branchMenus(branch),origin).href:buildStorefrontUrl({type:"order-menu",business:store.slug,branch:branch.slug,state:{query:{}}},{contract:"v2",installation,origin}))}}for(const menu of menus){if(!menu){continue}const branch=store.branches.find(entry=>entry.id===menu.branchId);for(const item of Object.values(menu.items)){if(!items(item)){continue}urls.add(buildStorefrontUrl({type:"item",business:store.slug,...branch?{branch:branch.slug}:{},item:item.id,state:{query:{}}},{contract:"v2",installation,origin}))}}return[...urls]}var escapeXml=value=>value.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;");function sitemapXml(urls){return`<?xml version="1.0" encoding="UTF-8"?>
3
3
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${[...urls].map(url=>`<url><loc>${escapeXml(url)}</loc></url>`).join("")}</urlset>`}function sitemapResponse({preview,...options}){return new Response(sitemapXml(sitemapUrls(options)),{headers:{"content-type":"application/xml; charset=utf-8","cache-control":PAGE_CACHE_CONTROL[preview?"private":"static"]}})}export{ROBOTS_DISALLOW,allMenus,robotsResponse,robotsText,sitemapResponse,sitemapUrls,sitemapXml,storeRedirect};
4
- //# sourceMappingURL=site-seo.js.map
@@ -1,2 +1 @@
1
1
  import{platformErrorResponse}from"../error-pages/index.js";import{markClosedPage,siteClosed}from"../site-closed/index.js";import{cachePage,rememberDataVersion}from"./edge-cache.js";function siteWorker({render,deployId,cacheControl,branchCookie,redirect,store}){return{async fetch(request,env,ctx){try{if(siteClosed(request)){const response=await render(new Request(new URL("/",request.url),request),env,ctx);return response.ok?markClosedPage(response):response}const early=redirect?.(request);if(early){return early}const fresh=next=>render(next,env,ctx);rememberDataVersion(request,ctx);if(env.ZAPPIE_EDGE_CACHE==="off"||request.headers.has("x-forwarded-host")){return await fresh(request)}return await cachePage(request,fresh,{ctx,deployId:await deployId(),...cacheControl?{cacheControl}:{},...branchCookie?{branchCookie}:{}})}catch(error){console.error(error);let owner;try{owner=typeof store==="function"?store(env):store}catch{owner=void 0}return platformErrorResponse("went-wrong",owner?{store:owner}:{})}}}}function originFetch(origin,fetcher=(input,init)=>globalThis.fetch(input,init)){return(input,init)=>{const headers=new Headers(init?.headers??(input instanceof Request?input.headers:void 0));if(!headers.has("origin")){headers.set("origin",origin)}return fetcher(input,{...init,headers})}}export{originFetch,siteWorker};
2
- //# sourceMappingURL=site-worker.js.map
@@ -1,2 +1 @@
1
1
  import{menuRoute}from"./contract.js";import{publicInstallationPath}from"./installation.js";import{v1Params}from"./params.js";import"./types.js";import{encode}from"./url.js";var routePathV1=(route,options={})=>{switch(route.type){case"order-menu":return`/order/${encode(route.business)}${route.branch?`/${encode(route.branch)}`:""}${route.cataloguePath?"/products":""}`;case"item":{const branch=route.branch??options.installation?.defaultBranch;return branch?`/order/${encode(route.business)}/${encode(branch)}/products/${encode(route.item)}`:`/order/${encode(route.business)}`}case"cart":case"checkout":case"checkout-return":case"sign-in":return routePathV1(menuRoute(route),options);case"content-page":return`/order/${encode(route.business)}${route.branch?`/${encode(route.branch)}`:""}/pages/${encode(route.slug)}`;case"dine-in":return`/dine-in/${encode(route.order)}`;case"pay-point":return`/pay-point/${encode(route.payPoint)}`;case"beacon":return`/beacons/${encode(route.beacon)}`;case"link":return`/links/${encode(route.link)}`;case"pay-session":return`/pay/${encode(route.session)}`;case"payment-step":return`/payment/${encode(route.payment)}${route.step==="payment"?"":`/${route.step}`}`;case"payment-card":return`/payment/card/${encode(route.transaction)}`;case"profile":return`/profile/${route.page}${route.order?`/${encode(route.order)}`:""}`;case"explore":return route.home?"/":"/explore";case"unknown":return route.pathname||"/";case"dine-in-menus":return"/dine-in/menus";case"self-service-menus":return"/self-service/menus";case"collect-payment":case"reservation":return`/${route.type}`}};var buildV1=(route,options={})=>{const internal=routePathV1(route,options);const publicRoute=route.type==="item"&&route.branch===void 0&&options.installation?.defaultBranch?{...route,branch:options.installation.defaultBranch}:route;const pathname=publicInstallationPath(internal,publicRoute,options.installation);const query=v1Params(route).toString();return`${pathname}${query?`?${query}`:""}`};export{buildV1,routePathV1};
2
- //# sourceMappingURL=build-v1.js.map
@@ -1,2 +1 @@
1
1
  import{buildV1}from"./build-v1.js";import{canonicalRoute}from"./canonical.js";import{v2Params}from"./params.js";import{categoryHash,publicId}from"./public-id.js";import{encode}from"./url.js";var profilePath=route=>{if(route.page==="orders"){return`/orders${route.order?`/${encode(publicId(route.order,"ord"))}`:""}`}if(route.page==="edit"){return"/account"}const page=route.page==="add-store-credit"?"store-credit":route.page;return`/account/${page}`};var routePathV2=route=>{switch(route.type){case"order-menu":return"/";case"item":return`/item/${encode(publicId(route.item,"item"))}`;case"cart":return"/cart";case"checkout":return"/checkout";case"checkout-return":return"/checkout/return";case"sign-in":return"/sign-in";case"content-page":return`/pages/${encode(route.slug)}`;case"profile":return profilePath(route)}};var buildV2=(route,options)=>{const installation=options.installation;const canonical=canonicalRoute(route,installation);if(!("business"in canonical)&&canonical.type!=="profile"){return buildV1(canonical,options)}const pathname=routePathV2(canonical);const query=v2Params(canonical,installation).toString();const hash=categoryHash(canonical.state.categoryId);return`${pathname}${query?`?${query}`:""}${hash}`};export{buildV2};
2
- //# sourceMappingURL=build-v2.js.map
@@ -1,2 +1 @@
1
1
  import{buildV1}from"./build-v1.js";import{buildV2}from"./build-v2.js";import{usesV2}from"./contract.js";var buildStorefrontUrl=(route,options={})=>{const value=usesV2(options)?buildV2(route,options):buildV1(route,options);if(!options.origin){return value}try{return new URL(value,options.origin).toString()}catch{return value}};export{buildStorefrontUrl};
2
- //# sourceMappingURL=build.js.map
@@ -1,2 +1 @@
1
1
  import{CART_MODAL,CHECKOUT_MODAL,SIGN_IN_MODALS}from"./contract.js";import{signInFromOverlay}from"./sign-in.js";import{ITEM_MODAL_PREFIX}from"./url.js";var canonicalRoute=(route,installation)=>{if(route.type!=="order-menu"){return route}const{authModalId,modalId}=route.state;if(authModalId&&SIGN_IN_MODALS.includes(authModalId)){return signInFromOverlay(route,installation)}const common={business:route.business,...route.branch!==void 0?{branch:route.branch}:{},state:route.state};if(modalId?.startsWith(ITEM_MODAL_PREFIX)){return{type:"item",...common,item:modalId.slice(ITEM_MODAL_PREFIX.length)}}if(modalId===CART_MODAL||modalId===CHECKOUT_MODAL){return{type:modalId===CART_MODAL?"cart":"checkout",...common}}return route};export{canonicalRoute};
2
- //# sourceMappingURL=canonical.js.map
@@ -1,2 +1 @@
1
1
  var CART_MODAL="review-menu";var CHECKOUT_MODAL="payment";var SIGN_IN_MODAL="send-otp";var SIGN_IN_MODALS=[SIGN_IN_MODAL,"verify-otp","update-profile"];var usesV2=options=>options.contract!=="v1"&&options.installation!==void 0;var menuRoute=route=>({type:"order-menu",business:route.business,...route.branch!==void 0?{branch:route.branch}:{},state:route.state});export{CART_MODAL,CHECKOUT_MODAL,SIGN_IN_MODAL,SIGN_IN_MODALS,menuRoute,usesV2};
2
- //# sourceMappingURL=contract.js.map
@@ -1,2 +1 @@
1
1
  import{buildStorefrontUrl}from"./build.js";import{parseStorefrontUrl}from"./parse.js";import{storefrontRedirect}from"./redirect.js";import{STOREFRONT_QUERY_PARAMETERS,STOREFRONT_V1_QUERY_PARAMETERS}from"./types.js";export{STOREFRONT_QUERY_PARAMETERS,STOREFRONT_V1_QUERY_PARAMETERS,buildStorefrontUrl,parseStorefrontUrl,storefrontRedirect};
2
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  import"./types.js";import{decode,encode}from"./url.js";var normalizedPath=pathname=>{const trimmed=pathname.replace(/\/+$/,"");return trimmed||"/"};var installationPath=(pathname,installation)=>{if(!installation){return pathname}const business=`/order/${encode(installation.business)}`;if(pathname==="/"){return business}if(pathname==="/order"){return installation.defaultBranch?`${business}/${encode(installation.defaultBranch)}`:business}if(pathname.startsWith("/pages/")){return`${business}${pathname}`}if(!pathname.startsWith("/order/")||pathname===business||pathname.startsWith(`${business}/`)){return pathname}const suffix=pathname.slice("/order".length);if(installation.defaultBranch&&(suffix==="/products"||suffix.startsWith("/products/")||suffix.startsWith("/pages/"))){return`${business}/${encode(installation.defaultBranch)}${suffix}`}return`${business}${suffix}`};var publicInstallationPath=(pathname,route,installation)=>{if(!installation||!("business"in route)){return pathname}if(route.business!==installation.business){return pathname}if(route.type==="content-page"&&!route.branch){return`/pages/${encode(route.slug)}`}if(route.type==="order-menu"&&!route.branch){return"/"}const branchPrefix=`/order/${encode(route.business)}/${encode(route.branch??"")}`;const suffix=pathname.slice(branchPrefix.length);if(route.branch===installation.defaultBranch){return`/order${suffix}`}return`/order/${encode(route.branch??"")}${suffix}`};var segment=(parts,index)=>decode(parts[index]??"");export{installationPath,normalizedPath,publicInstallationPath,segment};
2
- //# sourceMappingURL=installation.js.map
@@ -1,2 +1 @@
1
1
  import{CART_MODAL,CHECKOUT_MODAL,SIGN_IN_MODAL}from"./contract.js";import{publicId}from"./public-id.js";import{STATE_FIELDS}from"./url.js";var stateParams=route=>{const params=new URLSearchParams(route.state.query);const state=route.state;for(const[key,field]of Object.entries(STATE_FIELDS)){const value=state[field];if(value!==void 0){params.set(key,value)}}if(state.mode){params.set("pickup",String(state.mode==="pickup"))}return params};var v1Params=route=>{const params=stateParams(route);if(route.type==="item"){params.delete("modal_id")}else if(route.type==="cart"){params.set("modal_id",CART_MODAL)}else if(route.type==="checkout"){params.set("modal_id",CHECKOUT_MODAL)}else if(route.type==="sign-in"){params.set("auth_modal_id",SIGN_IN_MODAL);if(route.returnTo!==void 0){params.set("return",route.returnTo)}}else if(route.type==="checkout-return"&&route.session!==void 0){params.set("session",route.session)}params.sort();return params};var v2Params=(route,installation)=>{const params=stateParams(route);const menu=params.get("menu_id");if(menu){params.set("menu",publicId(menu,"menu"))}for(const key of["menu_id","category_id","pickup","menu_layout","catalogue_search","catalogue_categories","template","catalog_rendering","prefetch","ws","env","business","business_tag","switched_branch","success","auto_scroll","preview","modal_id"]){params.delete(key)}if("business"in route){if(route.branch&&route.branch!==installation.defaultBranch){params.set("branch",route.branch)}else{params.delete("branch")}}if(route.type==="sign-in"){params.delete("auth_modal_id");if(route.returnTo!==void 0){params.set("return",route.returnTo)}}if(route.type==="checkout-return"&&route.session!==void 0){params.set("session",route.session)}params.sort();return params};export{v1Params,v2Params};
2
- //# sourceMappingURL=params.js.map
@@ -1,2 +1 @@
1
1
  import{installationPath,normalizedPath,segment}from"./installation.js";import"./types.js";import{ITEM_MODAL_PREFIX,inputUrl,pageState}from"./url.js";var FIXED_ROUTES={"/dine-in/menus":"dine-in-menus","/self-service/menus":"self-service-menus","/collect-payment":"collect-payment","/reservation":"reservation"};var ID_ROUTES={"dine-in":["dine-in","order"],"pay-point":["pay-point","payPoint"],beacons:["beacon","beacon"],links:["link","link"],pay:["pay-session","session"]};var parseV1=(input,options={})=>{try{const url=inputUrl(input);const state=pageState(url,"v1");const pathname=installationPath(normalizedPath(url.pathname),options.installation);const parts=pathname.split("/").filter(Boolean);if(parts[0]==="order"&&parts[1]){const business=segment(parts,1);if(parts[2]==="pages"&&parts.length===4){return{type:"content-page",business,slug:segment(parts,3),state}}const branch=parts[2]?segment(parts,2):void 0;if(branch&&parts[3]==="pages"&&parts.length===5){return{type:"content-page",business,branch,slug:segment(parts,4),state}}if(branch&&parts[3]==="products"&&parts[4]&&parts.length===5){return{type:"item",business,branch,item:segment(parts,4),state}}if(parts.length<=3||parts.length===4&&parts[3]==="products"){const modalItem=state.modalId?.startsWith(ITEM_MODAL_PREFIX)?state.modalId.slice(ITEM_MODAL_PREFIX.length):"";if(branch&&modalItem){return{type:"item",business,branch,item:modalItem,state}}return{type:"order-menu",business,...branch?{branch}:{},...parts[3]==="products"?{cataloguePath:true}:{},state}}}if(Object.hasOwn(FIXED_ROUTES,pathname)){return{type:FIXED_ROUTES[pathname],state}}const[prefix="",id]=parts;if(parts.length===2&&id&&Object.hasOwn(ID_ROUTES,prefix)){const[type,field]=ID_ROUTES[prefix];return{type,[field]:segment(parts,1),state}}if(parts[0]==="payment"&&parts[1]==="card"&&parts[2]&&parts.length===3){return{type:"payment-card",transaction:segment(parts,2),state}}if(parts[0]==="payment"&&parts[1]&&parts.length<=3){const step=parts[2];if(!step||["successful","failed","refunded"].includes(step)){return{type:"payment-step",payment:segment(parts,1),step:step||"payment",state}}}if(parts[0]==="orders"&&parts.length<=2){return{type:"profile",page:"orders",...parts[1]?{order:segment(parts,1)}:{},state}}if(parts[0]==="profile"&&parts[1]&&parts.length<=3){const page=parts[1];if(page==="add-store-credit"||page==="edit"||page==="payment-methods"||page==="transactions"){return{type:"profile",page,state}}if(page==="orders"){return{type:"profile",page,...parts[2]?{order:segment(parts,2)}:{},state}}}if(pathname==="/"||pathname==="/explore"){return{type:"explore",...pathname==="/"?{home:true}:{},state}}return{type:"unknown",pathname,state}}catch{return{type:"unknown",pathname:"",state:{query:{}}}}};export{parseV1};
2
- //# sourceMappingURL=parse-v1.js.map
@@ -1,2 +1 @@
1
1
  import{sameOriginPath}from"../../internal/return-path.js";import{canonicalRoute}from"./canonical.js";import{normalizedPath,segment}from"./installation.js";import{parseV1}from"./parse-v1.js";import{inputUrl,pageState}from"./url.js";var canonical=(url,state,business)=>{const pathname=normalizedPath(url.pathname);const parts=pathname.split("/").filter(Boolean);const branch=url.searchParams.get("branch");const common={business,...branch!==null?{branch}:{},state};if(pathname==="/"){return{type:"order-menu",...common}}if(parts[0]==="item"&&parts[1]&&parts.length===2){return{type:"item",...common,item:segment(parts,1)}}if(pathname==="/cart"||pathname==="/checkout"){return{type:pathname==="/cart"?"cart":"checkout",...common}}if(pathname==="/checkout/return"){const session=url.searchParams.get("session");return{type:"checkout-return",...common,...session!==null?{session}:{}}}if(pathname==="/sign-in"){const returnTo=sameOriginPath(url.searchParams.get("return"));return{type:"sign-in",...common,...returnTo!==void 0?{returnTo}:{}}}if(parts[0]==="pages"&&parts[1]&&parts.length===2){return{type:"content-page",...common,slug:segment(parts,1)}}if(parts[0]==="account"&&parts.length<=2){const pages={"payment-methods":"payment-methods",transactions:"transactions","store-credit":"add-store-credit"};if(parts.length===1){return{type:"profile",page:"edit",state}}const page=parts[1];if(page&&Object.hasOwn(pages,page)){return{type:"profile",page:pages[page],state}}}return null};var parseV2=(input,options)=>{try{const url=inputUrl(input);const state=pageState(url);const installation=options.installation;const route=canonical(url,state,installation.business);return canonicalRoute(route??parseV1(input,options),installation)}catch{return{type:"unknown",pathname:"",state:{query:{}}}}};export{parseV2};
2
- //# sourceMappingURL=parse-v2.js.map
@@ -1,2 +1 @@
1
1
  import{usesV2}from"./contract.js";import{parseV1}from"./parse-v1.js";import{parseV2}from"./parse-v2.js";var parseStorefrontUrl=(input,options={})=>usesV2(options)?parseV2(input,options):parseV1(input,options);export{parseStorefrontUrl};
2
- //# sourceMappingURL=parse.js.map
@@ -1,2 +1 @@
1
1
  var publicId=(value,prefix)=>value.startsWith(`${prefix}_`)?value:`${prefix}_${value}`;var categoryHash=category=>category?`#c-${encodeURIComponent(publicId(category,"cat"))}`:"";export{categoryHash,publicId};
2
- //# sourceMappingURL=public-id.js.map
@@ -1,2 +1 @@
1
1
  import{buildStorefrontUrl}from"./build.js";import{usesV2}from"./contract.js";import{normalizedPath}from"./installation.js";import{parseStorefrontUrl}from"./parse.js";import{inputUrl,isAttributionKey}from"./url.js";var comparable=url=>{url.searchParams.sort();return`${normalizedPath(url.pathname)}${url.search}${url.hash}`};var storefrontRedirect=(input,options={})=>{if(!usesV2(options)){return null}try{const route=parseStorefrontUrl(input,options);if(route.type==="unknown"){return null}const targetUrl=inputUrl(buildStorefrontUrl(route,options));const original=inputUrl(input);for(const key of[...targetUrl.searchParams.keys()]){if(isAttributionKey(key)){targetUrl.searchParams.delete(key)}}original.searchParams.forEach((value,key)=>{if(isAttributionKey(key)){targetUrl.searchParams.append(key,value)}});const path=comparable(targetUrl);if(comparable(original)===path){return null}return options.origin?targetUrl.href:path}catch{return null}};export{storefrontRedirect};
2
- //# sourceMappingURL=redirect.js.map
@@ -1,2 +1 @@
1
1
  import{v2Params}from"./params.js";import{categoryHash}from"./public-id.js";var signInFromOverlay=(route,installation)=>{const params=v2Params(route,installation);params.delete("auth_modal_id");const search=params.toString();return{type:"sign-in",business:route.business,state:{query:{}},returnTo:`/${search?`?${search}`:""}${categoryHash(route.state.categoryId)}`}};export{signInFromOverlay};
2
- //# sourceMappingURL=sign-in.js.map
@@ -1,2 +1 @@
1
1
  var STOREFRONT_V1_QUERY_PARAMETERS=["ref","utm_source","payment_id","context","prefetch","business_tag","pay_point_id","dine_in_order_id","no_context","payment_context_id","ws","preview","device","auto_scroll","pickup","branch_closed","order_id","modal_id","lightbox","menu_id","payment_method","beacon_id","menu_group_id","category_id","menu_layout","can_schedule","refresh","success","grant","portal","can_download_receipt","auth_modal_id","experimental_otp","branch","business","env","switched_branch","from","template","catalog_rendering","catalogue_search","catalogue_categories"];var STOREFRONT_QUERY_PARAMETERS=[...STOREFRONT_V1_QUERY_PARAMETERS,"menu","return","session"];export{STOREFRONT_QUERY_PARAMETERS,STOREFRONT_V1_QUERY_PARAMETERS};
2
- //# sourceMappingURL=types.js.map
@@ -1,2 +1 @@
1
1
  import{STOREFRONT_QUERY_PARAMETERS,STOREFRONT_V1_QUERY_PARAMETERS}from"./types.js";var FALLBACK_ORIGIN="https://storefront.invalid";var ITEM_MODAL_PREFIX="product_";var decode=value=>{try{return decodeURIComponent(value)}catch{return value}};var encode=value=>encodeURIComponent(value);var inputUrl=input=>{if(input instanceof URL){return new URL(input.toString())}const value=typeof input==="string"?input:input.url;return new URL(value,FALLBACK_ORIGIN)};var isAttributionKey=key=>/^utm_|^(ref|(fb|g|d|tt|tw)clid|msclkid|[gw]braid|li_fat_id|ScCid)$/.test(key);var queryRecord=(params,contract)=>{const allowed=contract==="v2"?STOREFRONT_QUERY_PARAMETERS:STOREFRONT_V1_QUERY_PARAMETERS;return Object.fromEntries([...params].filter(([key])=>allowed.includes(key)||isAttributionKey(key)))};var STATE_FIELDS={menu_id:"menuId",category_id:"categoryId",menu_layout:"menuLayout",modal_id:"modalId",auth_modal_id:"authModalId",payment_id:"paymentId",lightbox:"lightbox",catalogue_search:"catalogueSearch",catalogue_categories:"catalogueCategories"};var pageState=(url,contract="v2")=>{const query=queryRecord(url.searchParams,contract);const state={query};for(const[key,field]of Object.entries(STATE_FIELDS)){const value=url.searchParams.get(key);if(value!==null){state[field]=value}}const pickup=url.searchParams.get("pickup");if(pickup==="true"||pickup==="false"){state.mode=pickup==="true"?"pickup":"delivery"}if(state.categoryId===void 0&&contract==="v2"&&url.hash.startsWith("#c-")){state.categoryId=decode(url.hash.slice(3))}return state};export{FALLBACK_ORIGIN,ITEM_MODAL_PREFIX,STATE_FIELDS,decode,encode,inputUrl,isAttributionKey,pageState,queryRecord};
2
- //# sourceMappingURL=url.js.map
@@ -1,2 +1 @@
1
1
  import{ZappieError}from"../errors.js";var ZappieWebhookSignatureError=class extends ZappieError{constructor(){super("invalid_request","Zappie could not verify this webhook signature.");this.name="ZappieWebhookSignatureError"}};var encoder=new TextEncoder;async function verifyWebhook({payload,header,secret,toleranceSec=300,now=new Date}){const parsed=signatureHeader(header);if(secret.length===0||!parsed||!Number.isFinite(toleranceSec)||toleranceSec<0||Math.abs(now.getTime()/1e3-parsed.seconds)>toleranceSec){throw new ZappieWebhookSignatureError}const body=typeof payload==="string"?encoder.encode(payload):payload;const prefix=encoder.encode(`${parsed.timestamp}.`);const signed=new Uint8Array(prefix.length+body.length);signed.set(prefix);signed.set(body,prefix.length);const key=await crypto.subtle.importKey("raw",encoder.encode(secret),{name:"HMAC",hash:"SHA-256"},false,["verify"]);const matches=await Promise.all(parsed.signatures.map(async candidate=>{const valid=/^[0-9a-f]{64}$/.test(candidate);const bytes=valid?hex(candidate):new Uint8Array(32);const match=await crypto.subtle.verify("HMAC",key,bytes,signed);return valid&&match}));if(!matches.some(Boolean)){throw new ZappieWebhookSignatureError}let event;try{event=JSON.parse(new TextDecoder().decode(body))}catch(cause){throw new ZappieError("invalid_request","The verified webhook payload is not valid JSON.",{cause})}if(!event||typeof event!=="object"||Array.isArray(event)){throw new ZappieError("invalid_request","The verified webhook payload is not a JSON object.")}return event}function signatureHeader(header){let timestamp="";const signatures=[];for(const part of header?.split(",")??[]){const value=part.trim();const separator=value.indexOf("=");if(separator<0){continue}const key=value.slice(0,separator);const item=value.slice(separator+1);if(key==="t"){timestamp=item}else if(key==="v1"){signatures.push(item)}}if(!/^[+-]?\d+$/.test(timestamp)||signatures.length===0){return null}const seconds=Number(timestamp);return Number.isSafeInteger(seconds)?{timestamp,seconds,signatures}:null}function hex(value){const bytes=new Uint8Array(value.length/2);for(let index=0;index<bytes.length;index+=1){bytes[index]=Number.parseInt(value.slice(index*2,index*2+2),16)}return bytes}export{ZappieWebhookSignatureError,verifyWebhook};
2
- //# sourceMappingURL=webhook.js.map