@zappie/sdk 0.28.2 → 0.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. package/CHANGELOG.md +18 -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-CW_OWZ0l.d.ts} +229 -5
  41. package/dist/client.js +0 -1
  42. package/dist/config/index.d.ts +38 -3
  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 +179 -8
  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,26 +1,111 @@
1
- import { a as Menu, C as CategoryPage, S as Store, I as Item, M as Money, F as Formatters } from './models-DLGs3UI2.js';
2
- import { Q as QuoteRequest, i as WireQuote, e as CartIssueCode, d as CartModule, b as CartLineInput } from './types-8HB4-7D9.js';
1
+ import { a as Menu, C as CategoryPage, S as Store, I as Item, M as Money, F as Formatters } from './models-C77LjkK8.js';
2
+ import { Q as QuoteRequest, i as WireQuote, e as CartIssueCode, d as CartModule, b as CartLineInput } from './types-CuPaBf6k.js';
3
3
 
4
4
  /** Stable public error codes. */
5
- type ZappieErrorCode = "network_error" | "timeout" | "rate_limited" | "unauthorized" | "forbidden" | "forbidden_origin" | "scope_required" | "not_found" | "store_not_found" | "branch_not_found" | "item_not_found" | "cart_invalid" | "invalid_request" | "version_unsupported" | "server_error";
5
+ type ZappieErrorCode =
6
+ /**
7
+ * The request never got an answer: a read still failed after two retries, a customer request
8
+ * failed after one retry, or the server helpers could not fetch the token signing keys. Any
9
+ * failure that is not already a ZappieError is wrapped with this code too. Retryable.
10
+ */
11
+ "network_error"
12
+ /** Reserved. The SDK doesn't raise it today, and the storefront API doesn't send it. Retryable. */
13
+ | "timeout"
14
+ /**
15
+ * The API answered 429. Reads retry twice first, unless `Retry-After` asks for more than 5
16
+ * seconds. Retryable.
17
+ */
18
+ | "rate_limited"
19
+ /**
20
+ * The key or customer token was refused: a customer or loyalty request answered 401, the server
21
+ * helpers refused a token, or a read answered 401 with no error code.
22
+ */
23
+ | "unauthorized"
24
+ /**
25
+ * The key may not do this: a customer request answered 403, or a read answered 403 with an error
26
+ * code this SDK doesn't know, such as `origin_not_allowed`. `apiCode` holds the API's own code.
27
+ */
28
+ | "forbidden"
29
+ /** A read answered 403 with no error code, which the SDK takes as a website the key doesn't allow. */
30
+ | "forbidden_origin"
31
+ /** The customer's token lacks a scope the request needs. The API's own code, passed through. */
32
+ | "scope_required"
33
+ /** The API answered 404 with the code `not_found`, with an error code this SDK doesn't know, or with no code. */
34
+ | "not_found"
35
+ /** Reserved. The SDK doesn't raise it today, and the storefront API doesn't send it. */
36
+ | "store_not_found"
37
+ /**
38
+ * No branch of the store matches the `branch` you passed, by id or slug, or the store has no
39
+ * branches. The cart raises it too when its branch is not in the loaded store.
40
+ */
41
+ | "branch_not_found"
42
+ /**
43
+ * The item isn't in the menu: `useItem` finds no item with that id once the menu loads, or a
44
+ * custom transport raised it. The cart reports a missing line as a `ZappieCartError` instead.
45
+ */
46
+ | "item_not_found"
47
+ /**
48
+ * The cart refused a change or checkout. A `ZappieCartError` carries it, with the reasons in its
49
+ * `issues`.
50
+ */
51
+ | "cart_invalid"
52
+ /**
53
+ * Your code sent something the SDK or the API refuses: a missing store, a key of the wrong kind,
54
+ * a secret key in a browser, a bad `baseUrl`, a cart `ttl` that is not positive, an invalid amount
55
+ * or currency, or a read the transport doesn't support. Also any request the API refused with a
56
+ * 4xx status no other code names, with an error code this SDK doesn't know or with none.
57
+ * `apiCode` holds the API's own code when it sent one.
58
+ */
59
+ | "invalid_request"
60
+ /** Reserved. The SDK doesn't raise it today, and the storefront API doesn't send it. */
61
+ | "version_unsupported"
62
+ /**
63
+ * The API answered 500 or above, after the SDK retried twice for a read, or sent a response the
64
+ * SDK can't read. Retryable.
65
+ */
66
+ | "server_error";
6
67
  /** Context attached to an SDK failure. */
7
68
  type ErrorDetails = {
69
+ /** The HTTP status the API answered with. Left out when the failure never reached the API. */
8
70
  status?: number;
71
+ /** The request field the failure is about, such as `branch` or `lines[0].item_id`. */
9
72
  param?: string;
73
+ /** A docs page for the code. Defaults to `https://docs.zappie.ai/errors#` followed by the code. */
10
74
  docUrl?: string;
75
+ /** The id the API gave the request, from the `Zappie-Request-Id` header. Quote it when you ask about a request. */
11
76
  requestId?: string;
77
+ /** Whether trying again can succeed. Defaults to true for `network_error`, `timeout`, `rate_limited` and `server_error`. */
12
78
  retryable?: boolean;
79
+ /** The API's own error code, such as `origin_not_allowed`, kept as it came. Left out when the API sent none. */
80
+ apiCode?: string;
81
+ /** The underlying failure, set as the error's `cause`. */
13
82
  cause?: unknown;
14
83
  };
15
84
  /** An SDK error you can handle by its stable code. */
16
85
  declare class ZappieError extends Error {
86
+ /** The stable code to branch on. */
17
87
  readonly code: ZappieErrorCode;
88
+ /** The HTTP status the API answered with. Left out when the failure never reached the API. */
18
89
  readonly status?: number;
90
+ /** The request field the failure is about, such as `branch`. Left out when there isn't one. */
19
91
  readonly param?: string;
92
+ /** A docs page for the code: the API's `doc_url` when it sent one, otherwise `https://docs.zappie.ai/errors#` followed by the code. */
20
93
  readonly docUrl: string;
94
+ /** The id the API gave the request, from the `Zappie-Request-Id` header. Left out when the API sent none. */
21
95
  readonly requestId?: string;
96
+ /**
97
+ * The API's own error code, as it came, even one this SDK doesn't know yet. `code` maps it to a
98
+ * stable code. Left out when the failure never reached the API or the API named no code.
99
+ */
100
+ readonly apiCode?: string;
101
+ /**
102
+ * Whether trying again can succeed. True by default for `network_error`, `timeout`,
103
+ * `rate_limited` and `server_error`.
104
+ */
22
105
  readonly retryable: boolean;
23
- constructor(code: ZappieErrorCode, message: string, details?: ErrorDetails);
106
+ constructor(
107
+ /** The stable code to branch on. */
108
+ code: ZappieErrorCode, message: string, details?: ErrorDetails);
24
109
  }
25
110
  /** Check whether a thrown value is a ZappieError. */
26
111
  declare function isZappieError(error: unknown): error is ZappieError;
@@ -29,25 +114,35 @@ declare function isZappieError(error: unknown): error is ZappieError;
29
114
  * The store, branch, order context and source menu that identify a saved catalogue.
30
115
  */
31
116
  type CatalogueScope = {
117
+ /** The store the client is set up with, as in the client's `store` setting. The saved catalogues of each store live apart. */
32
118
  store: string;
119
+ /** The branch whose menu is saved. */
33
120
  branchId: string;
121
+ /** The order context the menu was read for. `delivery` and `pickup` are online orders. `dineIn` is an order at a table. */
34
122
  orderContext: "delivery" | "pickup" | "dineIn";
123
+ /** The source menu that is saved. */
35
124
  menuId: string;
36
125
  };
37
126
  /** The saved coverage. A complete source menu still covers only part of the branch. */
38
127
  type SavedCatalogue = {
128
+ /** What the saved copy is of. */
39
129
  scope: CatalogueScope;
130
+ /** The source menu as it was read. */
40
131
  menu: Menu;
132
+ /** The menus the copy covers and whether it covers each of them whole. A read only returns a copy that covers exactly `scope.menuId`. */
41
133
  coverage: {
42
134
  menuIds: string[];
43
135
  complete: boolean;
44
136
  };
137
+ /** The category pages saved with the menu, each under its category and the cursor it was read with, when it had one. */
45
138
  pages: {
46
139
  categoryId: string;
47
140
  cursor?: string;
48
141
  page: CategoryPage;
49
142
  }[];
143
+ /** The cache tag of the saved copy. `publish` replaces it with a SHA-256 digest of the menu's content. A copy without one is never read. */
50
144
  etag: string;
145
+ /** When the copy was saved, in milliseconds since the Unix epoch. A copy older than its storage's maximum age is never read. */
51
146
  savedAt: number;
52
147
  /**
53
148
  * The host's catalogue revision when saved. An unchanged revision means the
@@ -86,9 +181,11 @@ declare function createSavedCatalogue(client: Zappie, scope: CatalogueScope): {
86
181
 
87
182
  /** Complete for the named source, never complete for the branch. */
88
183
  type SelectedMenu = {
184
+ /** Every item of the one source menu. It is partial as a branch catalogue, since other menus are left out. */
89
185
  menu: Menu & {
90
186
  completeness: "partial";
91
187
  };
188
+ /** Confirms the response holds every item of the requested menu, and only that menu. */
92
189
  coverage: {
93
190
  menuIds: [string];
94
191
  complete: true;
@@ -116,6 +213,7 @@ type SelectedMenuRequest = RequestCtx & {
116
213
  * A transport that reads one complete source menu without claiming branch-wide coverage.
117
214
  */
118
215
  type SelectedMenuTransport = {
216
+ /** Read one source menu. Returns `notModified` with the ETag when `ifNoneMatch` still matches. */
119
217
  getSelectedMenu(request: SelectedMenuRequest): Promise<SelectedMenuResponse>;
120
218
  };
121
219
  /** Dependencies are passed by REST to avoid splitting core shared chunks. */
@@ -134,9 +232,13 @@ declare function createSelectedMenuReader(client: Zappie): {
134
232
 
135
233
  /** Per-request credentials and cancellation. Never shared across clients. */
136
234
  type RequestCtx = {
235
+ /** The client's key, sent as a bearer token. */
137
236
  key: string;
237
+ /** The API version, sent as the `Zappie-Version` header. */
138
238
  version: string;
239
+ /** Cancels the request when aborted. */
139
240
  signal?: AbortSignal;
241
+ /** Sent as the `Idempotency-Key` header when set. Left out by every read and by quotes unless the caller passes one. */
140
242
  idempotencyKey?: string;
141
243
  };
142
244
  /** Full menu response or a conditional-cache hit. */
@@ -149,31 +251,44 @@ type MenuResponse = {
149
251
  };
150
252
  /** Opaque content and availability versions. */
151
253
  type MenuVersion = {
254
+ /** Changes with any change to the menus, availability included. Read the menus again when it moves. */
152
255
  version: string;
256
+ /** Changes only when an item's availability or stock label changes. */
153
257
  availabilityHash: string;
154
258
  };
155
259
  /** Replaceable read-only backend for the storefront SDK. */
156
260
  interface Transport {
261
+ /** Read one complete source menu. Optional. Without it, selected-menu reads throw. */
157
262
  getSelectedMenu?(ctx: SelectedMenuRequest): Promise<SelectedMenuResponse>;
263
+ /** Search the branch's items. Optional. Without it, `menu.search` throws `invalid_request`. */
158
264
  search?(ctx: SearchRequest): Promise<SearchPage>;
265
+ /** Price a cart. Returns the quote as the API sends it, for the cart to check and map. */
159
266
  quote(ctx: RequestCtx, body: QuoteRequest): Promise<WireQuote>;
267
+ /** Read the store and its branches. */
160
268
  getStore(ctx: RequestCtx): Promise<Store>;
269
+ /**
270
+ * Read a branch's catalogue, every page of it. Returns `notModified` when `ifNoneMatch` still
271
+ * matches. With `metadataOnly`, returns menus and categories without items.
272
+ */
161
273
  getMenu(ctx: RequestCtx & {
162
274
  branchId: string;
163
275
  ifNoneMatch?: string;
164
276
  metadataOnly?: boolean;
165
277
  fulfilment?: MenuFulfilment | undefined;
166
278
  }): Promise<MenuResponse>;
279
+ /** Read one page of a source menu's category. Optional. Without it, `menu.page` throws `invalid_request`. */
167
280
  getCategoryPage?(ctx: RequestCtx & {
168
281
  branchId: string;
169
282
  menuId: string;
170
283
  categoryId: string;
171
284
  cursor?: string;
172
285
  }): Promise<CategoryPage>;
286
+ /** Read the catalogue's current content and availability versions. */
173
287
  getMenuVersion(ctx: RequestCtx & {
174
288
  branchId: string;
175
289
  fulfilment?: MenuFulfilment | undefined;
176
290
  }): Promise<MenuVersion>;
291
+ /** Read one item at a branch. */
177
292
  getItem(ctx: RequestCtx & {
178
293
  branchId: string;
179
294
  itemId: string;
@@ -187,7 +302,9 @@ type SearchRequest = RequestCtx & {
187
302
  };
188
303
  /** Matching items with their source menus and categories. This is a partial catalogue. */
189
304
  type SearchPage = {
305
+ /** The matching items, with their source menus and categories, as a partial catalogue. */
190
306
  menu: Menu;
307
+ /** Pass it as `cursor` to read the next page. Left out on the last page. */
191
308
  nextCursor?: string;
192
309
  };
193
310
 
@@ -195,28 +312,72 @@ type SearchPage = {
195
312
  declare const API_VERSION = "2026-10-01";
196
313
  /** A storage adapter you can supply to save carts. */
197
314
  interface StorageLike {
315
+ /** Read the value saved under a key, or null when there is none. */
198
316
  getItem(key: string): string | null;
317
+ /** Save a value under a key, replacing any value already there. */
199
318
  setItem(key: string, value: string): void;
319
+ /** Remove the value saved under a key. */
200
320
  removeItem(key: string): void;
201
321
  /** Provide length and key to let the SDK remove expired carts for this store. */
202
322
  readonly length?: number;
323
+ /**
324
+ * The key at a position, from 0 to `length` minus 1, or null past the end.
325
+ *
326
+ * @param index - The position to read.
327
+ */
203
328
  key?(index: number): string | null;
204
329
  }
205
330
  /** Settings for your storefront client. Each client keeps its own credentials and caches. */
206
331
  type ZappieConfig = {
332
+ /**
333
+ * Your business tag, as the dashboard shows it under Settings, Business. The SDK names saved carts and caches by it and never sends
334
+ * it: the API finds the store from your key. Required.
335
+ */
207
336
  store: string;
337
+ /**
338
+ * Your publishable key, `pk_test_` or `pk_live_` followed by the rest. A `pk_test_` key also turns
339
+ * on the debug tools in a browser. `createZappie` refuses secret keys.
340
+ */
208
341
  key: string;
342
+ /**
343
+ * The branch to read, by id or slug. Defaults to the store's default branch, or its first branch
344
+ * when none is marked default. A read's own `branch` option wins over it.
345
+ */
209
346
  branch?: string;
347
+ /** A read backend in place of the REST transport, such as a test fixture. When set, `baseUrl` and `fetch` are ignored. */
210
348
  transport?: Transport;
349
+ /**
350
+ * The storefront API address. Defaults to `https://api.zappie.ai/storefront/v1`. It must be HTTPS,
351
+ * or HTTP on localhost, with no credentials, query or fragment.
352
+ */
211
353
  baseUrl?: string;
354
+ /** The API version, sent as the `Zappie-Version` header. Defaults to `API_VERSION`, `2026-10-01`. */
212
355
  version?: string;
356
+ /** The fetch the REST transport calls, to add tracing or mock responses. Defaults to the global fetch. */
213
357
  fetch?: typeof fetch;
214
358
  /** Route cart quotes through the same-origin customer channel when set. */
215
359
  customerBase?: string;
360
+ /**
361
+ * Where carts are saved. Defaults to `localStorage` in a browser. Without one, or when storage
362
+ * fails, carts are kept in memory for the life of the client.
363
+ */
216
364
  storage?: StorageLike;
365
+ /**
366
+ * Reserved for a later analytics transport. Defaults to true. The SDK sends no telemetry today
367
+ * whatever its value: events reach only the listeners you add with `on`.
368
+ */
217
369
  telemetry?: boolean;
370
+ /** Cart settings. */
218
371
  cart?: {
372
+ /**
373
+ * How long a saved cart lives after its last change, in milliseconds. Defaults to 7 days
374
+ * (604800000). An older cart is discarded on load and `cart_expired` fires. It must be positive.
375
+ */
219
376
  ttl?: number;
377
+ /**
378
+ * A name that keeps a separate saved cart per branch, such as one for delivery and one for
379
+ * pickup. A scoped cart takes over the branch's unscoped cart once.
380
+ */
220
381
  storageScope?: string;
221
382
  };
222
383
  };
@@ -252,52 +413,71 @@ declare class Cache {
252
413
 
253
414
  /** Events currently emitted by the read-only SDK. */
254
415
  type ZappieEvents = {
416
+ /** Reserved. The SDK doesn't emit it today. */
255
417
  search: {
256
418
  query: string;
257
419
  resultCount: number;
258
420
  };
421
+ /** The browser storage for the cart is unavailable, so the cart lives in memory for this client. Sent once. */
259
422
  warning: {
260
423
  message: string;
261
424
  };
425
+ /** A saved cart was older than `cart.ttl` and was cleared when the branch's cart loaded. */
262
426
  cart_expired: {
263
427
  branchId: string;
264
428
  };
429
+ /** Items were added. `quantity` is how many were added, and `value` is their price for that quantity. */
265
430
  add_to_cart: {
266
431
  itemId: string;
267
432
  quantity: number;
268
433
  value: Money;
269
434
  };
435
+ /** A line was removed. `quantity` is how many it held, and `value` is its subtotal. */
270
436
  remove_from_cart: {
271
437
  itemId: string;
272
438
  quantity: number;
273
439
  value: Money;
274
440
  };
441
+ /** A line changed. `quantity` is its new quantity. */
275
442
  update_cart_line: {
276
443
  lineId: string;
277
444
  itemId: string;
278
445
  quantity: number;
279
446
  };
447
+ /** A quote was asked for with `force`, as when the shopper opens the cart. */
280
448
  view_cart: Record<string, never>;
449
+ /** One for each issue a cart check or a quote found. */
281
450
  cart_issue: {
282
451
  code: CartIssueCode;
283
452
  };
453
+ /** A quote request failed. `code` is the error's code. */
284
454
  quote_failed: {
285
455
  code: string;
286
456
  };
457
+ /** A branch's menus changed. `version` is the new menu version. */
287
458
  "menu:updated": {
288
459
  branchId: string;
289
460
  version: string;
290
461
  };
462
+ /** A background step failed, such as a menu refresh, a cache write or loading the saved cart. */
291
463
  error: {
292
464
  error: ZappieError;
293
465
  };
294
466
  };
295
467
 
296
468
  /** A catalogue fulfilment mode accepted by menu reads. */
297
- type MenuFulfilment = "delivery" | "pickup" | "dineIn";
469
+ type MenuFulfilment =
470
+ /** Orders delivered to the shopper. */
471
+ "delivery"
472
+ /** Orders the shopper collects from the branch. */
473
+ | "pickup"
474
+ /** Orders placed at a table in the branch. Sent to the API as `dine_in`. */
475
+ | "dineIn";
298
476
  /** Optional branch selection and cancellation for resource reads. */
299
477
  type ReadOptions = {
478
+ /** The branch to read, by id or slug. Defaults to the client's `branch`, then the store's default branch, then its first. */
300
479
  branch?: string;
480
+ /** Cancels the read when aborted. */
301
481
  signal?: AbortSignal;
302
482
  };
303
483
  /** Optional branch and fulfilment selection for catalogue reads. */
@@ -306,25 +486,69 @@ type MenuReadOptions = ReadOptions & {
306
486
  };
307
487
  /** Read-only store resource. */
308
488
  interface StoreResource {
489
+ /**
490
+ * Read the store and its branches. A read under a minute old is reused. One up to 10 minutes old
491
+ * is returned at once and refreshed in the background. Reads in flight share one request.
492
+ */
309
493
  get(opts?: {
310
494
  signal?: AbortSignal;
311
495
  }): Promise<Store>;
496
+ /** The store already read, without a request, or undefined before the first read lands. */
312
497
  peek(): Store | undefined;
313
498
  }
314
499
  /** Read-only branch catalogue and item resources. */
315
500
  interface MenuResource {
501
+ /**
502
+ * Search the branch's items. Returns up to 25 matches as a partial catalogue, with a cursor for
503
+ * the next page. Throws `invalid_request` when the transport has no search.
504
+ *
505
+ * @param query - The text to search for. Surrounding spaces are trimmed.
506
+ * @param opts - The branch, a cancel signal and the `cursor` from the previous page.
507
+ */
316
508
  search(query: string, opts?: ReadOptions & {
317
509
  cursor?: string;
318
510
  }): Promise<SearchPage>;
511
+ /**
512
+ * Read the branch's whole catalogue, every page of it. Reads are cached like the store's, and a
513
+ * changed version fires `menu:updated`. With `metadataOnly`, it reads the menus and categories
514
+ * without items, as a partial catalogue.
515
+ */
319
516
  get(opts?: MenuReadOptions & {
320
517
  metadataOnly?: boolean;
321
518
  }): Promise<Menu>;
519
+ /**
520
+ * Read one page of a source menu's category, as a partial catalogue. Throws `invalid_request`
521
+ * when the transport has no category pages.
522
+ *
523
+ * @param menuId - The source menu, from `MenuSection.id`.
524
+ * @param categoryId - The category in that menu.
525
+ * @param opts - The branch, a cancel signal and the `cursor` from the previous page.
526
+ */
322
527
  page(menuId: string, categoryId: string, opts?: ReadOptions & {
323
528
  cursor?: string;
324
529
  }): Promise<CategoryPage>;
530
+ /**
531
+ * The branch's catalogue already read or hydrated, without a request. Falls back to a
532
+ * metadata-only read, and is undefined when neither is cached.
533
+ *
534
+ * @param branch - The branch, by id or slug. Defaults as `ReadOptions.branch` does.
535
+ */
325
536
  peek(branch?: string): Menu | undefined;
537
+ /** Read the catalogue's current versions, to check for changes without reading the menus again. */
326
538
  version(opts?: MenuReadOptions): Promise<MenuVersion>;
539
+ /**
540
+ * Read one item. It comes from the complete catalogue when that is cached, otherwise from a
541
+ * single-item read, after a metadata-only menu read when no menu is cached.
542
+ *
543
+ * @param id - The item id.
544
+ */
327
545
  item(id: string, opts?: ReadOptions): Promise<Item>;
546
+ /**
547
+ * Put a catalogue read elsewhere, such as on the server, into this client's cache without a
548
+ * request. Fires `menu:updated` when it replaces a different version.
549
+ *
550
+ * @param menu - The catalogue to store under its `branchId`.
551
+ */
328
552
  hydrate(menu: Menu): void;
329
553
  }
330
554
  /** A storefront client and its isolated resource state. */
package/dist/client.js CHANGED
@@ -1,2 +1 @@
1
1
  import{createCart}from"./cart/index.js";import{createWorkingSet}from"./cart/working-set.js";import{API_VERSION,validateConfig}from"./config.js";import{ZappieError}from"./errors.js";import{Cache}from"./internal/cache.js";import{createEmitter}from"./internal/emitter.js";import{format}from"./money.js";import{RestTransport}from"./transport/rest.js";function buildClient(input,secret=false){const mode=validateConfig(input,secret);const config=Object.freeze({...input,version:input.version??API_VERSION,telemetry:input.telemetry??true});const transport=input.transport??new RestTransport({...input.baseUrl?{baseUrl:input.baseUrl}:{},...input.fetch?{fetch:input.fetch}:{}});const events=createEmitter();const cache=new Cache(error=>events.emit("error",{error}));const ctx=signal=>({key:config.key,version:config.version,...signal?{signal}:{}});const store={get:(opts={})=>cache.get("store",async signal=>({value:await transport.getStore(ctx(signal))}),opts.signal),peek:()=>cache.snapshot("store").value};const resolveBranch=(value,requested)=>{const selected=requested??config.branch;const branch=selected?value.branches.find(b=>b.id===selected||b.slug===selected):value.branches.find(b=>b.isDefault)??value.branches[0];if(!branch){throw new ZappieError("branch_not_found","No matching storefront branch",{param:"branch"})}return branch};let hydratedBranch;const branchKey=requested=>{const value=store.peek();if(value){return resolveBranch(value,requested).id}const selected=requested??config.branch;if(hydratedBranch&&(selected===void 0||selected===config.branch||selected===hydratedBranch)){return hydratedBranch}return selected??"default"};const menuKey=requested=>`menu:${branchKey(requested)}`;const readMenu=(branchId,opts)=>cache.get(`menu:${branchId}${opts.fulfilment?`:${opts.fulfilment}`:""}${opts.metadataOnly?":partial":""}`,async(signal,entry)=>{const response=await transport.getMenu({...ctx(signal),branchId,fulfilment:opts.fulfilment,...opts.metadataOnly?{metadataOnly:true}:{},...entry.etag?{ifNoneMatch:entry.etag}:{}});if("notModified"in response){if(!entry.value){throw new ZappieError("server_error","Received 304 without a cached menu")}return{value:entry.value,...response.etag??entry.etag?{etag:response.etag??entry.etag}:{}}}if(!opts.metadataOnly&&response.menu.completeness==="partial"){throw new ZappieError("server_error","Partial catalogue cannot satisfy a complete read")}if(response.menu.branchId!==branchId){throw new ZappieError("server_error","Menu belongs to a different branch")}return{value:response.menu,etag:response.etag??response.menu.version,onStored:()=>{if(entry.value&&entry.value.version!==response.menu.version){events.emit("menu:updated",{branchId,version:response.menu.version})}}}},opts.signal);const menu={async search(query,opts={}){if(!transport.search){throw new ZappieError("invalid_request","Transport does not support search")}const branch=resolveBranch(await store.get(opts),opts.branch);return transport.search({...ctx(opts.signal),branchId:branch.id,query,...opts.cursor?{cursor:opts.cursor}:{}})},async get(opts={}){return readMenu(resolveBranch(await store.get(opts),opts.branch).id,opts)},peek:branch=>cache.snapshot(menuKey(branch)).value??cache.snapshot(`${menuKey(branch)}:partial`).value,async page(menuId,categoryId,opts={}){if(!transport.getCategoryPage){throw new ZappieError("invalid_request","Transport does not support category pages")}const branch=resolveBranch(await store.get(opts),opts.branch);return transport.getCategoryPage({...ctx(opts.signal),branchId:branch.id,menuId,categoryId,...opts.cursor?{cursor:opts.cursor}:{}})},async version(opts={}){const branch=resolveBranch(await store.get(opts),opts.branch);return transport.getMenuVersion({...ctx(opts.signal),branchId:branch.id,fulfilment:opts.fulfilment})},async item(id,opts={}){const branch=resolveBranch(await store.get(opts),opts.branch);if(!menu.peek(branch.id)||menu.peek(branch.id)?.completeness==="partial"){await menu.get({...opts,metadataOnly:true})}return readItem(id,branch.id,false,opts.signal)},hydrate(value){hydratedBranch??(hydratedBranch=value.branchId);const previous=cache.snapshot(`menu:${value.branchId}`).value;cache.set(`menu:${value.branchId}${value.completeness==="partial"?":partial":""}`,value,value.version);if(previous&&previous.version!==value.version){events.emit("menu:updated",{branchId:value.branchId,version:value.version})}}};const itemValues=new Map;const peekItem=(id,branch)=>itemValues.get(`${branch}:${id}`);const readItem=async(id,branch,fresh=false,signal)=>{const complete=cache.snapshot(`menu:${branch}`).value;const load=(requestSignal=signal)=>transport.getItem({...ctx(requestSignal),branchId:branch,itemId:id});try{const value=fresh?await load():complete&&Object.hasOwn(complete.items,id)?complete.items[id]:await cache.get(`item:${branch}:${id}`,async requestSignal=>({value:await load(requestSignal)}),signal);if(fresh){cache.set(`item:${branch}:${id}`,value)}itemValues.set(`${branch}:${id}`,value);return value}catch(error){if(error.code==="item_not_found"){itemValues.delete(`${branch}:${id}`);cache.set(`item:${branch}:${id}`,void 0)}throw error}};const workingSet=createWorkingSet({menu,store,transport,context:ctx,peekItem,readItem});const{cart,setLegacyReader,cartCatalogue}=createCart({workingSet,config,menu,store,transport,context:ctx,events});return Object.freeze({cart,config,mode,store,menu,format,on:events.on,_internal:{cartCatalogue,setLegacyReader,transport,cache,emit:events.emit,menuKey,readMenu,hydrateStore:value=>cache.set("store",value)}})}function createZappie(config){const client=buildClient(config);if(client.mode==="test"&&typeof window!=="undefined"){void import("./debug.js").then(({installDebug})=>installDebug(client))}return client}export{buildClient,createZappie};
2
- //# sourceMappingURL=client.js.map
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Default site budgets: 200 KB gzipped JavaScript, 50 KB gzipped CSS, 2500 ms LCP and 3000 ms until the first product card is tappable.
2
+ * Default site budgets: 200 KiB gzipped JavaScript, 50 KiB gzipped CSS, 2500 ms LCP and 3000 ms until the first product card is tappable.
3
+ * A KiB is 1,024 bytes.
3
4
  */
4
5
  declare const DEFAULT_BUDGETS: {
5
6
  readonly jsKbGz: 200;
@@ -17,17 +18,27 @@ type RouteCssBudget = number | Record<string, number>;
17
18
  * The store, theme and optional build policies you export from zappie.config.ts.
18
19
  */
19
20
  type ZappieSiteConfig = {
21
+ /** Your business tag, the same one you pass to `createZappie()`. Find it in the dashboard under Settings, Business. Required and non-empty. */
20
22
  store: string;
23
+ /** Branch slugs for this site. When set, it needs at least one non-empty slug, each listed once. */
21
24
  branches?: string[];
25
+ /** The path to your theme file, relative to the project, such as `./theme.json`. It must end in `.json`. */
22
26
  theme: string;
23
27
  /**
28
+ * Paths to prerender. Zappie hosting ignores it.
29
+ *
24
30
  * @deprecated Zappie hosting prerenders no page: every page renders in your Worker, and its page cache keeps the
25
31
  * anonymous ones. `validateConfig` warns when it is set. Remove it.
26
32
  */
27
33
  prerender?: string[];
34
+ /** Menu settings. `hiddenCategories` lists the categories to keep off the menu. */
28
35
  menu?: {
29
36
  hiddenCategories?: string[];
30
37
  };
38
+ /**
39
+ * Packages your site may depend on beyond GLOBAL_PACKAGE_ALLOWLIST. `allow` takes lowercase npm package names, such
40
+ * as `lucide-react` or `@scope/name`. `zappie check` fails a dependency that neither list allows.
41
+ */
31
42
  packages?: {
32
43
  allow?: string[];
33
44
  };
@@ -39,6 +50,10 @@ type ZappieSiteConfig = {
39
50
  until: string;
40
51
  }[];
41
52
  };
53
+ /**
54
+ * Hosts your site may send requests to. `allow` takes hostnames without a scheme, path, port or IP, such as
55
+ * `api.example.com`, or a leading `*.` for every subdomain. The lint rules report a request to a host not listed.
56
+ */
42
57
  outbound?: {
43
58
  allow?: string[];
44
59
  };
@@ -56,11 +71,13 @@ type ZappieSiteConfig = {
56
71
  };
57
72
  /** Each budget left out uses DEFAULT_BUDGETS. */
58
73
  budgets?: {
74
+ /** The gzipped JavaScript, in KiB, each route loads with the client entry. Default: 200. */
59
75
  jsKbGz?: number;
60
- /** Every client stylesheet together, gzipped, in KiB. `zappie check` enforces it only while `routeCssKbGz` is unset. */
76
+ /** Every client stylesheet together, gzipped, in KiB. Default: 50. `zappie check` enforces it only while `routeCssKbGz` is unset. */
61
77
  cssKbGz?: number;
78
+ /** The menu's largest contentful paint budget, in milliseconds. Default: 2500. `zappie verify` fails a menu over 2500 ms whatever this says. */
62
79
  lcpMs?: number;
63
- /** V15's limit for the first product card to become tappable. Values below 3000 use 3000. */
80
+ /** V15's limit, in milliseconds, for the first product card to become tappable. Default: 3000. Values below 3000 use 3000. */
64
81
  tappableMs?: number;
65
82
  /**
66
83
  * The gzipped CSS, in KiB, a route may load on its first load: the shared base plus that route's own stylesheets.
@@ -81,6 +98,7 @@ type ZappieSiteConfig = {
81
98
  * `zappie verify` fails. Unset, verify warns above 50 percent and never fails.
82
99
  */
83
100
  unusedCssPercent?: number;
101
+ /** Why a budget is above its default. Without a reason, a raised budget is a config error. With one, it is a warning. */
84
102
  override?: {
85
103
  reason: string;
86
104
  };
@@ -96,6 +114,10 @@ type ZappieSiteConfig = {
96
114
  };
97
115
  };
98
116
  };
117
+ /**
118
+ * Analytics ids Zappie forwards storefront events to. `forward.ga4` takes a measurement id that starts with `G-`, and
119
+ * `forward.metaPixel` takes a pixel id of digits only.
120
+ */
99
121
  analytics?: {
100
122
  forward?: {
101
123
  ga4?: string;
@@ -140,16 +162,29 @@ type ZappieSiteConfig = {
140
162
  * A configuration diagnostic with its field path, stable code, message and severity.
141
163
  */
142
164
  type ConfigIssue = {
165
+ /** The field the issue is about, such as `budgets.lcpMs` or `packages.allow[0]`. `$` means the whole configuration. */
143
166
  path: string;
167
+ /**
168
+ * What kind of issue it is. `invalid_type` is a value of the wrong type. `missing_required` is a required field left
169
+ * out. `unknown_key` is a key the configuration doesn't have. `invalid_format` is a value of the right type in the
170
+ * wrong form, such as a theme path that isn't a relative `.json` path. `duplicate` is a value listed twice.
171
+ * `redundant_allowlist` is a package in `packages.allow` that is already allowed globally. `budget_override` is a
172
+ * budget above its default, an error without `budgets.override.reason` and a warning with one. `unused_setting` is a
173
+ * setting that does nothing, such as `prerender`.
174
+ */
144
175
  code: "invalid_type" | "missing_required" | "unknown_key" | "invalid_format" | "duplicate" | "redundant_allowlist" | "budget_override" | "unused_setting";
176
+ /** A sentence that says what is wrong and how to fix it. */
145
177
  message: string;
178
+ /** How much the issue matters. `error` makes `valid` false. `warning` is reported and leaves `valid` as it is. */
146
179
  severity: "error" | "warning";
147
180
  };
148
181
  /**
149
182
  * Configuration validation results. Warnings alone do not make valid false.
150
183
  */
151
184
  type ConfigValidation = {
185
+ /** True when no issue has the `error` severity. */
152
186
  valid: boolean;
187
+ /** Every error and warning found, in the order the fields were checked. */
153
188
  issues: ConfigIssue[];
154
189
  };
155
190
 
@@ -1,2 +1 @@
1
1
  import{DEFAULT_BUDGETS,GLOBAL_PACKAGE_ALLOWLIST}from"../site-config/types.js";import{validateConfig}from"../site-config/validate.js";function defineConfig(config){return config}export{DEFAULT_BUDGETS,GLOBAL_PACKAGE_ALLOWLIST,defineConfig,validateConfig};
2
- //# sourceMappingURL=index.js.map
package/dist/config.js CHANGED
@@ -1,2 +1 @@
1
1
  import{ZappieError}from"./errors.js";var API_VERSION="2026-10-01";function validateConfig(config,secret=false){if(!config.store?.trim()){throw new ZappieError("invalid_request","A storefront slug is required")}if(secret&&typeof window!=="undefined"){throw new ZappieError("invalid_request","Secret keys cannot be used in a browser")}const pattern=secret?/^sk_(test|live)_.+$/:/^pk_(test|live)_.+$/;const match=pattern.exec(config.key);if(!match){throw new ZappieError("invalid_request",secret?"A secret sk_test_ or sk_live_ key is required":"Use a publishable pk_test_ or pk_live_ key; secret keys are never accepted by createZappie")}return match[1]}export{API_VERSION,validateConfig};
2
- //# sourceMappingURL=config.js.map
@@ -1,2 +1 @@
1
1
  import{createPendingNavigation}from"@zappie/sdk/navigation";import{requestWithRetry}from"../internal/customer-http.js";import{orderReceipt}from"@zappie/sdk/receipts";import{forgetBagAddresses,forgetRememberedAddress,settleShopper}from"../internal/remembered-address.js";import{currentPath,leaveTo,safeReturnTo}from"./navigation.js";import{createCustomerRequest,readCustomerResponse}from"./request.js";import{watchOrder}from"./watch-order.js";var DEFAULT_CUSTOMER_BASE="/_zappie/api";var DEFAULT_SESSION_PATH="/_zappie/session";function createCustomer(options={}){const base=(options.customerBase??DEFAULT_CUSTOMER_BASE).replace(/\/+$/,"");const sessionPath=options.sessionPath??DEFAULT_SESSION_PATH;const fetcher=options.fetch??globalThis.fetch;let customer=options.initialCustomer??null;let state=options.initialCustomer===void 0?"unknown":customer?"authenticated":"anonymous";const settle=()=>{if(state!=="unknown"){settleShopper(customer?.id??null)}};settle();const listeners=new Set;const notify=()=>{for(const listener of listeners){listener(state,customer)}};const update=(next,nextState)=>{if(JSON.stringify([state,customer])===JSON.stringify([nextState,next])){return}state=nextState;customer=next;settle();globalThis.__zappieEmit?.("auth:changed",{state,customer});notify()};const leaving=createPendingNavigation();leaving.subscribe(notify);const request=createCustomerRequest(base,fetcher,()=>{update(null,"anonymous")});const readOrder=(id,signal)=>request(`/me/orders/${encodeURIComponent(id)}`,signal?{signal}:{});let pending;const check=async()=>{const response=await requestWithRetry(fetcher,sessionPath,{cache:"no-store"},"Could not check the customer session");const body=await readCustomerResponse(response,"session");const next=body.customer??null;update(next,next?"authenticated":"anonymous");return next};const refresh=()=>{pending??(pending=check().finally(()=>{pending=void 0}));return pending};const doc=globalThis.document;const recheck=()=>{if(doc?.visibilityState!=="hidden"){void refresh().catch(()=>void 0)}};doc?.addEventListener("visibilitychange",recheck);globalThis.addEventListener?.("pageshow",recheck);return{get state(){return state},get customer(){return customer},get pending(){return leaving.pending},session:refresh,dispose(){doc?.removeEventListener("visibilitychange",recheck);globalThis.removeEventListener?.("pageshow",recheck);listeners.clear()},onChange(listener){listeners.add(listener);return()=>{listeners.delete(listener)}},signIn(returnTo){void leaving.start(()=>leaveTo(`/_zappie/login?return=${encodeURIComponent(safeReturnTo(returnTo??currentPath()))}`))},signOut(){void leaving.start(async()=>{globalThis.__zappieShopper=void 0;forgetRememberedAddress();const perks=forgetBagAddresses();if(perks.length){await globalThis.__zappieReleasePerks?.(perks)}return leaveTo("/_zappie/logout",true)})},profile:()=>request("/me"),addresses:()=>request("/me/addresses").then(result=>result.addresses),addAddress:body=>request("/me/addresses",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(body)}),removeAddress:id=>request(`/me/addresses/${encodeURIComponent(id)}`,{method:"DELETE"}),orders(options2={}){const query=new URLSearchParams(JSON.parse(JSON.stringify(options2)));return request(`/me/orders${query.size?`?${query}`:""}`)},order:readOrder,payBalance:(id,pay={})=>request(`/me/orders/${encodeURIComponent(id)}/payments`,{method:"POST",headers:{"Content-Type":"application/json","Idempotency-Key":pay.idempotencyKey??crypto.randomUUID()},body:JSON.stringify({use_wallet_balance:pay.useWalletBalance})}),reorder:id=>request(`/me/orders/${encodeURIComponent(id)}/reorder`,{method:"POST"}),receipt:id=>orderReceipt(base,id,fetcher),receiptUrl:id=>`${base}/me/orders/${encodeURIComponent(id)}/receipt`,watchOrder(id,watchOptions){return watchOrder(base,id,readOrder,watchOptions)}}}export{createCustomer};
2
- //# sourceMappingURL=client.js.map
@@ -1,2 +1 @@
1
1
  import{stableErrorCode,ZappieError}from"../internal/customer-http.js";var CustomerError=class extends ZappieError{constructor(status,apiCode,message,param,issues){super(stableErrorCode(status,apiCode),message,{status,retryable:status===429||status>=500,...param!==void 0?{param}:{}});this.apiCode=apiCode;if(issues!==void 0){this.issues=issues}}};export{CustomerError};
2
- //# sourceMappingURL=error.js.map