@zappie/sdk 0.18.0 → 0.19.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 (297) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/account/index.js +1 -5
  3. package/dist/account/index.js.map +1 -1
  4. package/dist/account/url.js +1 -23
  5. package/dist/account/url.js.map +1 -1
  6. package/dist/branches/index.js +1 -43
  7. package/dist/branches/index.js.map +1 -1
  8. package/dist/cart/branch.js +1 -82
  9. package/dist/cart/branch.js.map +1 -1
  10. package/dist/cart/errors.js +1 -12
  11. package/dist/cart/errors.js.map +1 -1
  12. package/dist/cart/held.js +1 -17
  13. package/dist/cart/held.js.map +1 -1
  14. package/dist/cart/index.js +1 -782
  15. package/dist/cart/index.js.map +1 -1
  16. package/dist/cart/item.js +1 -11
  17. package/dist/cart/item.js.map +1 -1
  18. package/dist/cart/preview.js +1 -31
  19. package/dist/cart/preview.js.map +1 -1
  20. package/dist/cart/price.js +1 -24
  21. package/dist/cart/price.js.map +1 -1
  22. package/dist/cart/quote-client.js +1 -107
  23. package/dist/cart/quote-client.js.map +1 -1
  24. package/dist/cart/quote-response.js +1 -214
  25. package/dist/cart/quote-response.js.map +1 -1
  26. package/dist/cart/reconcile.js +1 -107
  27. package/dist/cart/reconcile.js.map +1 -1
  28. package/dist/cart/source-menu.js +1 -20
  29. package/dist/cart/source-menu.js.map +1 -1
  30. package/dist/cart/storage.js +1 -175
  31. package/dist/cart/storage.js.map +1 -1
  32. package/dist/cart/validate.js +1 -270
  33. package/dist/cart/validate.js.map +1 -1
  34. package/dist/cart/wire.js +1 -42
  35. package/dist/cart/wire.js.map +1 -1
  36. package/dist/cart/working-set.js +1 -79
  37. package/dist/cart/working-set.js.map +1 -1
  38. package/dist/checkout/client.js +1 -116
  39. package/dist/checkout/client.js.map +1 -1
  40. package/dist/checkout/embed.js +1 -247
  41. package/dist/checkout/embed.js.map +1 -1
  42. package/dist/checkout/error.js +1 -19
  43. package/dist/checkout/error.js.map +1 -1
  44. package/dist/checkout/index.js +1 -12
  45. package/dist/checkout/index.js.map +1 -1
  46. package/dist/checkout/react.js +1 -45
  47. package/dist/checkout/react.js.map +1 -1
  48. package/dist/checkout/readiness.js +1 -35
  49. package/dist/checkout/readiness.js.map +1 -1
  50. package/dist/checkout/sdk.js +1 -8
  51. package/dist/checkout/sdk.js.map +1 -1
  52. package/dist/checkout/session.js +1 -57
  53. package/dist/checkout/session.js.map +1 -1
  54. package/dist/checkout-defaults/index.js +1 -205
  55. package/dist/checkout-defaults/index.js.map +1 -1
  56. package/dist/client.js +1 -255
  57. package/dist/client.js.map +1 -1
  58. package/dist/config/index.d.ts +5 -0
  59. package/dist/config/index.js +1 -12
  60. package/dist/config/index.js.map +1 -1
  61. package/dist/config.js +1 -27
  62. package/dist/config.js.map +1 -1
  63. package/dist/customer/client.js +1 -180
  64. package/dist/customer/client.js.map +1 -1
  65. package/dist/customer/error.js +1 -18
  66. package/dist/customer/error.js.map +1 -1
  67. package/dist/customer/index.js +1 -7
  68. package/dist/customer/index.js.map +1 -1
  69. package/dist/customer/navigation.js +1 -39
  70. package/dist/customer/navigation.js.map +1 -1
  71. package/dist/customer/react.js +1 -69
  72. package/dist/customer/react.js.map +1 -1
  73. package/dist/customer/reorder.js +1 -60
  74. package/dist/customer/reorder.js.map +1 -1
  75. package/dist/customer/request.js +1 -37
  76. package/dist/customer/request.js.map +1 -1
  77. package/dist/customer/watch-order.js +1 -79
  78. package/dist/customer/watch-order.js.map +1 -1
  79. package/dist/debug.js +1 -77
  80. package/dist/debug.js.map +1 -1
  81. package/dist/display/index.js +1 -30
  82. package/dist/display/index.js.map +1 -1
  83. package/dist/error-pages/art.js +1 -10
  84. package/dist/error-pages/art.js.map +1 -1
  85. package/dist/error-pages/index.js +2 -103
  86. package/dist/error-pages/index.js.map +1 -1
  87. package/dist/error-pages/react.js +1 -65
  88. package/dist/error-pages/react.js.map +1 -1
  89. package/dist/errors.js +1 -70
  90. package/dist/errors.js.map +1 -1
  91. package/dist/in-venue/bill.js +1 -69
  92. package/dist/in-venue/bill.js.map +1 -1
  93. package/dist/in-venue/client.js +1 -119
  94. package/dist/in-venue/client.js.map +1 -1
  95. package/dist/in-venue/error.js +1 -18
  96. package/dist/in-venue/error.js.map +1 -1
  97. package/dist/in-venue/index.js +1 -23
  98. package/dist/in-venue/index.js.map +1 -1
  99. package/dist/in-venue/react/bill-page.js +1 -350
  100. package/dist/in-venue/react/bill-page.js.map +1 -1
  101. package/dist/in-venue/react/in-venue-page.js +1 -102
  102. package/dist/in-venue/react/in-venue-page.js.map +1 -1
  103. package/dist/in-venue/react/order-panel.js +1 -283
  104. package/dist/in-venue/react/order-panel.js.map +1 -1
  105. package/dist/in-venue/react/pay-point-page.js +1 -50
  106. package/dist/in-venue/react/pay-point-page.js.map +1 -1
  107. package/dist/in-venue/react/shared.js +2 -171
  108. package/dist/in-venue/react/shared.js.map +1 -1
  109. package/dist/in-venue/react/table-menus-page.js +1 -151
  110. package/dist/in-venue/react/table-menus-page.js.map +1 -1
  111. package/dist/in-venue/react.js +1 -14
  112. package/dist/in-venue/react.js.map +1 -1
  113. package/dist/in-venue/table.js +1 -62
  114. package/dist/in-venue/table.js.map +1 -1
  115. package/dist/in-venue/watch.js +1 -82
  116. package/dist/in-venue/watch.js.map +1 -1
  117. package/dist/index.js +1 -31
  118. package/dist/index.js.map +1 -1
  119. package/dist/integrations/index.js +1 -78
  120. package/dist/integrations/index.js.map +1 -1
  121. package/dist/internal/abort.js +1 -28
  122. package/dist/internal/abort.js.map +1 -1
  123. package/dist/internal/cache.js +1 -141
  124. package/dist/internal/cache.js.map +1 -1
  125. package/dist/internal/customer-http.js +1 -75
  126. package/dist/internal/customer-http.js.map +1 -1
  127. package/dist/internal/emitter.js +1 -26
  128. package/dist/internal/emitter.js.map +1 -1
  129. package/dist/internal/image-widths.js +1 -5
  130. package/dist/internal/image-widths.js.map +1 -1
  131. package/dist/internal/money-math.js +1 -29
  132. package/dist/internal/money-math.js.map +1 -1
  133. package/dist/internal/perk-hold.js +1 -34
  134. package/dist/internal/perk-hold.js.map +1 -1
  135. package/dist/internal/remembered-address.js +1 -68
  136. package/dist/internal/remembered-address.js.map +1 -1
  137. package/dist/internal/return-path.js +1 -16
  138. package/dist/internal/return-path.js.map +1 -1
  139. package/dist/internal/service-url.js +1 -10
  140. package/dist/internal/service-url.js.map +1 -1
  141. package/dist/internal.js +1 -8
  142. package/dist/internal.js.map +1 -1
  143. package/dist/loyalty/cart.js +1 -55
  144. package/dist/loyalty/cart.js.map +1 -1
  145. package/dist/loyalty/client.js +1 -88
  146. package/dist/loyalty/client.js.map +1 -1
  147. package/dist/loyalty/index.js +1 -12
  148. package/dist/loyalty/index.js.map +1 -1
  149. package/dist/loyalty/react.js +1 -199
  150. package/dist/loyalty/react.js.map +1 -1
  151. package/dist/loyalty/release.js +1 -42
  152. package/dist/loyalty/release.js.map +1 -1
  153. package/dist/money.js +1 -46
  154. package/dist/money.js.map +1 -1
  155. package/dist/navigation/index.js +1 -55
  156. package/dist/navigation/index.js.map +1 -1
  157. package/dist/navigation/react.js +1 -17
  158. package/dist/navigation/react.js.map +1 -1
  159. package/dist/navigation-progress/index.js +1 -41
  160. package/dist/navigation-progress/index.js.map +1 -1
  161. package/dist/options/index.js +1 -103
  162. package/dist/options/index.js.map +1 -1
  163. package/dist/persist/catalogue.js +1 -205
  164. package/dist/persist/catalogue.js.map +1 -1
  165. package/dist/places/client.js +1 -96
  166. package/dist/places/client.js.map +1 -1
  167. package/dist/places/error.js +1 -18
  168. package/dist/places/error.js.map +1 -1
  169. package/dist/places/index.js +1 -7
  170. package/dist/places/index.js.map +1 -1
  171. package/dist/places/request.js +1 -39
  172. package/dist/places/request.js.map +1 -1
  173. package/dist/places/sdk.js +1 -9
  174. package/dist/places/sdk.js.map +1 -1
  175. package/dist/places/search.js +1 -79
  176. package/dist/places/search.js.map +1 -1
  177. package/dist/pricing/index.js +1 -80
  178. package/dist/pricing/index.js.map +1 -1
  179. package/dist/react/cart.js +1 -40
  180. package/dist/react/cart.js.map +1 -1
  181. package/dist/react/changes.js +1 -93
  182. package/dist/react/changes.js.map +1 -1
  183. package/dist/react/hooks.js +1 -90
  184. package/dist/react/hooks.js.map +1 -1
  185. package/dist/react/index.js +1 -19
  186. package/dist/react/index.js.map +1 -1
  187. package/dist/react/provider.js +1 -33
  188. package/dist/react/provider.js.map +1 -1
  189. package/dist/react/rollback.js +1 -89
  190. package/dist/react/rollback.js.map +1 -1
  191. package/dist/receipts/index.js +1 -48
  192. package/dist/receipts/index.js.map +1 -1
  193. package/dist/redirect/index.js +1 -30
  194. package/dist/redirect/index.js.map +1 -1
  195. package/dist/server/auth/crypto.js +1 -105
  196. package/dist/server/auth/crypto.js.map +1 -1
  197. package/dist/server/auth/jwt.js +1 -203
  198. package/dist/server/auth/jwt.js.map +1 -1
  199. package/dist/server/auth/session-store.js +1 -45
  200. package/dist/server/auth/session-store.js.map +1 -1
  201. package/dist/server/chosen-branch.js +1 -69
  202. package/dist/server/chosen-branch.js.map +1 -1
  203. package/dist/server/edge-cache.js +1 -394
  204. package/dist/server/edge-cache.js.map +1 -1
  205. package/dist/server/edge-snapshot.js +1 -199
  206. package/dist/server/edge-snapshot.js.map +1 -1
  207. package/dist/server/index.d.ts +5 -0
  208. package/dist/server/index.js +1 -113
  209. package/dist/server/index.js.map +1 -1
  210. package/dist/server/security.js +1 -135
  211. package/dist/server/security.js.map +1 -1
  212. package/dist/server/sign-in.js +1 -17
  213. package/dist/server/sign-in.js.map +1 -1
  214. package/dist/server/storefront-url/build-v1.js +1 -65
  215. package/dist/server/storefront-url/build-v1.js.map +1 -1
  216. package/dist/server/storefront-url/build-v2.js +1 -50
  217. package/dist/server/storefront-url/build-v2.js.map +1 -1
  218. package/dist/server/storefront-url/build.js +1 -18
  219. package/dist/server/storefront-url/build.js.map +1 -1
  220. package/dist/server/storefront-url/canonical.js +1 -35
  221. package/dist/server/storefront-url/canonical.js.map +1 -1
  222. package/dist/server/storefront-url/contract.js +1 -24
  223. package/dist/server/storefront-url/contract.js.map +1 -1
  224. package/dist/server/storefront-url/index.js +1 -15
  225. package/dist/server/storefront-url/index.js.map +1 -1
  226. package/dist/server/storefront-url/installation.js +1 -57
  227. package/dist/server/storefront-url/installation.js.map +1 -1
  228. package/dist/server/storefront-url/params.js +1 -88
  229. package/dist/server/storefront-url/params.js.map +1 -1
  230. package/dist/server/storefront-url/parse-v1.js +1 -137
  231. package/dist/server/storefront-url/parse-v1.js.map +1 -1
  232. package/dist/server/storefront-url/parse-v2.js +1 -84
  233. package/dist/server/storefront-url/parse-v2.js.map +1 -1
  234. package/dist/server/storefront-url/parse.js +1 -8
  235. package/dist/server/storefront-url/parse.js.map +1 -1
  236. package/dist/server/storefront-url/public-id.js +1 -7
  237. package/dist/server/storefront-url/public-id.js.map +1 -1
  238. package/dist/server/storefront-url/redirect.js +1 -43
  239. package/dist/server/storefront-url/redirect.js.map +1 -1
  240. package/dist/server/storefront-url/sign-in.js +1 -17
  241. package/dist/server/storefront-url/sign-in.js.map +1 -1
  242. package/dist/server/storefront-url/types.js +1 -55
  243. package/dist/server/storefront-url/types.js.map +1 -1
  244. package/dist/server/storefront-url/url.js +1 -73
  245. package/dist/server/storefront-url/url.js.map +1 -1
  246. package/dist/server/webhook.js +1 -95
  247. package/dist/server/webhook.js.map +1 -1
  248. package/dist/services/index.js +1 -18
  249. package/dist/services/index.js.map +1 -1
  250. package/dist/site-closed/index.js +1 -38
  251. package/dist/site-closed/index.js.map +1 -1
  252. package/dist/site-config/helpers.js +1 -58
  253. package/dist/site-config/helpers.js.map +1 -1
  254. package/dist/site-config/sections.js +1 -114
  255. package/dist/site-config/sections.js.map +1 -1
  256. package/dist/site-config/types.js +1 -31
  257. package/dist/site-config/types.js.map +1 -1
  258. package/dist/site-config/validate.js +1 -215
  259. package/dist/site-config/validate.js.map +1 -1
  260. package/dist/site-error/index.js +1 -32
  261. package/dist/site-error/index.js.map +1 -1
  262. package/dist/site-error/react.js +1 -14
  263. package/dist/site-error/react.js.map +1 -1
  264. package/dist/studio/index.js +1 -315
  265. package/dist/template/index.js +1 -88
  266. package/dist/template/index.js.map +1 -1
  267. package/dist/template/react.js +1 -111
  268. package/dist/template/react.js.map +1 -1
  269. package/dist/testing/index.js +1 -459
  270. package/dist/testing/loyalty.js +1 -109
  271. package/dist/testing/loyalty.js.map +1 -1
  272. package/dist/transport/category-page.js +1 -24
  273. package/dist/transport/category-page.js.map +1 -1
  274. package/dist/transport/mappers.js +1 -356
  275. package/dist/transport/mappers.js.map +1 -1
  276. package/dist/transport/presentation.js +1 -67
  277. package/dist/transport/presentation.js.map +1 -1
  278. package/dist/transport/quote-body.js +1 -23
  279. package/dist/transport/quote-body.js.map +1 -1
  280. package/dist/transport/rest.js +1 -327
  281. package/dist/transport/rest.js.map +1 -1
  282. package/dist/transport/search.js +1 -36
  283. package/dist/transport/search.js.map +1 -1
  284. package/dist/transport/selected-menu.js +1 -83
  285. package/dist/transport/selected-menu.js.map +1 -1
  286. package/dist/transport/store.js +1 -132
  287. package/dist/transport/store.js.map +1 -1
  288. package/dist/uploads/index.js +1 -36
  289. package/dist/uploads/index.js.map +1 -1
  290. package/dist/url/index.js +1 -15
  291. package/dist/url/index.js.map +1 -1
  292. package/dist/visits/index.js +1 -61
  293. package/dist/visits/index.js.map +1 -1
  294. package/dist/visits/page-views.js +1 -102
  295. package/dist/visits/page-views.js.map +1 -1
  296. package/dist/vite/index.js +3 -373
  297. package/package.json +1 -1
@@ -1,373 +1,3 @@
1
- // src/vite/index.ts
2
- import { randomBytes } from "node:crypto";
3
- import { existsSync, readFileSync, realpathSync } from "node:fs";
4
- import { createRequire } from "node:module";
5
- import path from "node:path";
6
- import { parseSync } from "vite";
7
- var SOURCE_ATTRIBUTE = "data-zappie-source";
8
- var COMPONENT_ATTRIBUTE = "data-zappie-component";
9
- function zappieSource({ previewHost }) {
10
- let root = "";
11
- return {
12
- name: "zappie-source",
13
- enforce: "pre",
14
- apply: (_config, { command }) => command === "serve",
15
- config(config) {
16
- root = path.resolve(config.root ?? process.cwd());
17
- },
18
- configEnvironment(name) {
19
- if (name !== "client") {
20
- return;
21
- }
22
- const include = zappieDevEntries(root);
23
- return {
24
- optimizeDeps: {
25
- entries: ["app/**/*.{js,jsx,ts,tsx}"],
26
- ...include.length ? { include } : {}
27
- }
28
- };
29
- },
30
- configResolved(config) {
31
- root = config.root;
32
- },
33
- transform: {
34
- filter: { id: /\.[jt]sx$/ },
35
- handler(code, id) {
36
- if (!previewHost) {
37
- return null;
38
- }
39
- if (!id.startsWith(`${root}/`)) {
40
- return null;
41
- }
42
- const file = id.slice(root.length + 1);
43
- if (!file.startsWith("app/") || file.includes("node_modules/")) {
44
- return null;
45
- }
46
- return markSource(code, file);
47
- }
48
- }
49
- };
50
- }
51
- var SERVER_ONLY_ENTRIES = {
52
- "@zappie/sdk": ["./vite", "./server", "./testing"],
53
- "@zappie/foundations": ["./next"]
54
- };
55
- function zappieDevEntries(root) {
56
- return Object.entries(SERVER_ONLY_ENTRIES).flatMap(([name, serverOnly]) => {
57
- const manifest = installedManifest(root, name);
58
- if (!manifest) {
59
- return [];
60
- }
61
- const exports = manifest.exports;
62
- const subpaths = exports && typeof exports === "object" && !Array.isArray(exports) ? Object.keys(exports).filter((key) => key.startsWith(".")) : ["."];
63
- return subpaths.filter(
64
- (subpath) => !serverOnly.includes(subpath) && !subpath.includes("*") && !/\.(?:css|json)$/.test(subpath)
65
- ).map(
66
- (subpath) => subpath === "." ? name : `${name}${subpath.slice(1)}`
67
- );
68
- });
69
- }
70
- function installedManifest(root, name) {
71
- for (let directory = path.resolve(root); ; directory = path.dirname(directory)) {
72
- const file = path.join(directory, "node_modules", name, "package.json");
73
- if (existsSync(file)) {
74
- const real = realpathSync(file);
75
- return real.split(path.sep).includes("node_modules") ? JSON.parse(readFileSync(real, "utf8")) : void 0;
76
- }
77
- if (path.dirname(directory) === directory) {
78
- return void 0;
79
- }
80
- }
81
- }
82
- function markSource(code, file) {
83
- if (!/^[\x21-\x7e]+$/.test(file)) {
84
- return null;
85
- }
86
- const escaped = file.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("<", "&lt;");
87
- const parsed = parseSync(file, code);
88
- if (parsed.errors.length > 0) {
89
- return null;
90
- }
91
- const lineStarts = [0];
92
- for (let index = code.indexOf("\n"); index !== -1; index = code.indexOf("\n", index + 1)) {
93
- lineStarts.push(index + 1);
94
- }
95
- const lineOf = (offset) => {
96
- let low = 0;
97
- let high = lineStarts.length - 1;
98
- while (low < high) {
99
- const middle = low + high + 1 >> 1;
100
- if (lineStarts[middle] <= offset) {
101
- low = middle;
102
- } else {
103
- high = middle - 1;
104
- }
105
- }
106
- return low;
107
- };
108
- const inserts = [];
109
- const visit = (value, component) => {
110
- if (!value || typeof value !== "object") {
111
- return;
112
- }
113
- if (Array.isArray(value)) {
114
- for (const entry of value) {
115
- visit(entry, component);
116
- }
117
- return;
118
- }
119
- const node = value;
120
- const named = componentName(node) ?? component;
121
- if (node.type === "JSXOpeningElement") {
122
- const name = node.name;
123
- const attributes = node.attributes;
124
- if (name.type === "JSXIdentifier" && typeof name.name === "string" && /^[a-z]/.test(name.name) && !attributes.some(
125
- (attribute) => attribute.name?.name === SOURCE_ATTRIBUTE
126
- )) {
127
- const component2 = named ? ` ${COMPONENT_ATTRIBUTE}="${named}"` : "";
128
- inserts.push([
129
- name.end,
130
- ` ${SOURCE_ATTRIBUTE}="${escaped}:${lineOf(node.start) + 1}"${component2}`
131
- ]);
132
- }
133
- }
134
- for (const key in node) {
135
- if (key !== "type" && key !== "start" && key !== "end") {
136
- visit(node[key], named);
137
- }
138
- }
139
- };
140
- visit(parsed.program, void 0);
141
- if (inserts.length === 0) {
142
- return null;
143
- }
144
- inserts.sort((a, b) => a[0] - b[0]);
145
- let output = "";
146
- let from = 0;
147
- const lines = lineStarts.map(
148
- () => [[0, 0]]
149
- );
150
- const added = lineStarts.map(() => 0);
151
- for (const [offset, text] of inserts) {
152
- output += code.slice(from, offset) + text;
153
- from = offset;
154
- const line = lineOf(offset);
155
- const column = offset - lineStarts[line];
156
- added[line] += text.length;
157
- lines[line].push([column + added[line], column]);
158
- }
159
- output += code.slice(from);
160
- let previousLine = 0;
161
- let previousColumn = 0;
162
- const mappings = lines.map((segments, line) => {
163
- let previousGenerated = 0;
164
- return segments.map(([generated, original]) => {
165
- const encoded = vlq(generated - previousGenerated) + "A" + vlq(line - previousLine) + vlq(original - previousColumn);
166
- previousGenerated = generated;
167
- previousLine = line;
168
- previousColumn = original;
169
- return encoded;
170
- }).join(",");
171
- }).join(";");
172
- return {
173
- code: output,
174
- map: { version: 3, sources: [file], names: [], mappings }
175
- };
176
- }
177
- var BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
178
- function vlq(value) {
179
- let rest = value < 0 ? -value << 1 | 1 : value << 1;
180
- let encoded = "";
181
- do {
182
- let digit = rest & 31;
183
- rest >>>= 5;
184
- if (rest > 0) {
185
- digit |= 32;
186
- }
187
- encoded += BASE64[digit];
188
- } while (rest > 0);
189
- return encoded;
190
- }
191
- function componentName(node) {
192
- const id = node.id ?? void 0;
193
- const capitalised = (name) => typeof name === "string" && /^[A-Z]/.test(name) ? name : void 0;
194
- if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression") {
195
- return capitalised(id?.name);
196
- }
197
- if (node.type === "VariableDeclarator" && id?.type === "Identifier") {
198
- return capitalised(id.name);
199
- }
200
- return void 0;
201
- }
202
- function zappieHoistImports() {
203
- return {
204
- name: "zappie-hoist-imports",
205
- apply: "build",
206
- applyToEnvironment: (environment) => environment.config.consumer === "client",
207
- generateBundle(_options, bundle) {
208
- const importsOf = (fileName) => {
209
- const chunk = bundle[fileName];
210
- return chunk?.type === "chunk" ? chunk.imports : [];
211
- };
212
- for (const chunk of Object.values(bundle)) {
213
- if (chunk.type !== "chunk" || !chunk.isEntry) {
214
- continue;
215
- }
216
- const listed = /* @__PURE__ */ new Set([chunk.fileName, ...chunk.imports]);
217
- const hoisted = [];
218
- const pending = [...chunk.imports];
219
- for (let index = 0; index < pending.length; index++) {
220
- for (const next of importsOf(pending[index])) {
221
- if (!listed.has(next)) {
222
- listed.add(next);
223
- hoisted.push(next);
224
- pending.push(next);
225
- }
226
- }
227
- }
228
- if (hoisted.length === 0) {
229
- continue;
230
- }
231
- const from = chunk.fileName.split("/").slice(0, -1);
232
- chunk.code += `
233
- ${hoisted.map(
234
- (file) => `import ${JSON.stringify(relativeImport(from, file))};`
235
- ).join("")}
236
- `;
237
- chunk.imports.push(...hoisted);
238
- }
239
- }
240
- };
241
- }
242
- function relativeImport(from, file) {
243
- const to = file.split("/");
244
- let shared = 0;
245
- while (shared < from.length && shared < to.length - 1 && from[shared] === to[shared]) {
246
- shared++;
247
- }
248
- const up = from.length - shared;
249
- const rest = to.slice(shared).join("/");
250
- return up === 0 ? `./${rest}` : `${"../".repeat(up)}${rest}`;
251
- }
252
- var UPLOADS_PREFIX = "/_zappie/assets/";
253
- function zappieUploads({ host }) {
254
- const origin = uploadsOrigin(host);
255
- return {
256
- name: "zappie-uploads",
257
- apply: (_config, { command }) => command === "serve" && Boolean(origin),
258
- configureServer(server) {
259
- server.middlewares.use((request, response, next) => {
260
- const path2 = request.url ?? "";
261
- if (!origin || !path2.startsWith(UPLOADS_PREFIX)) {
262
- next();
263
- return;
264
- }
265
- void forwardUpload(origin, path2, request.method, request.headers.accept).then(({ status, headers, body }) => {
266
- response.writeHead(status, headers);
267
- response.end(body);
268
- }).catch(() => {
269
- response.writeHead(502, { "cache-control": "no-store" });
270
- response.end();
271
- });
272
- });
273
- }
274
- };
275
- }
276
- function uploadsOrigin(host) {
277
- if (!host) {
278
- return void 0;
279
- }
280
- try {
281
- const url = new URL(host.includes("://") ? host : `https://${host}`);
282
- return url.protocol === "https:" ? url.origin : void 0;
283
- } catch {
284
- return void 0;
285
- }
286
- }
287
- async function forwardUpload(origin, path2, method = "GET", accept) {
288
- if (method !== "GET" && method !== "HEAD") {
289
- return {
290
- status: 405,
291
- headers: { allow: "GET, HEAD" },
292
- body: Buffer.alloc(0)
293
- };
294
- }
295
- const upstream = await fetch(`${origin}${path2}`, {
296
- method,
297
- headers: accept ? { accept } : {}
298
- });
299
- const headers = {};
300
- for (const key of ["content-type", "cache-control", "vary"]) {
301
- const value = upstream.headers.get(key);
302
- if (value) {
303
- headers[key] = value;
304
- }
305
- }
306
- return {
307
- status: upstream.status,
308
- headers,
309
- body: Buffer.from(await upstream.arrayBuffer())
310
- };
311
- }
312
- function zappieWorker() {
313
- let root = process.cwd();
314
- let building = false;
315
- let renderer;
316
- return {
317
- name: "zappie-worker",
318
- enforce: "pre",
319
- config(config, { command }) {
320
- root = path.resolve(config.root ?? process.cwd());
321
- building = command === "build";
322
- return {
323
- define: {
324
- "import.meta.env.ZAPPIE_DEPLOY_ID": JSON.stringify(
325
- building ? randomBytes(8).toString("hex") : "dev"
326
- )
327
- }
328
- };
329
- },
330
- configEnvironment(name) {
331
- return building && name !== "client" ? { build: { minify: true } } : void 0;
332
- },
333
- resolveId: {
334
- filter: { id: STREAMING_ONLY },
335
- handler(source) {
336
- if (!building || this.environment.config.consumer === "client" || !STREAMING_ONLY.test(source)) {
337
- return null;
338
- }
339
- renderer ?? (renderer = streamingRenderer(root) ?? null);
340
- return renderer;
341
- }
342
- }
343
- };
344
- }
345
- var STREAMING_ONLY = /^react-dom\/server(?:\.edge)?$/;
346
- function streamingRenderer(root) {
347
- try {
348
- const manifest = createRequire(path.join(root, "package.json")).resolve(
349
- "react-dom/package.json"
350
- );
351
- const file = path.join(
352
- path.dirname(manifest),
353
- "cjs",
354
- "react-dom-server.edge.production.js"
355
- );
356
- return existsSync(file) ? file : void 0;
357
- } catch {
358
- return void 0;
359
- }
360
- }
361
- export {
362
- COMPONENT_ATTRIBUTE,
363
- SOURCE_ATTRIBUTE,
364
- forwardUpload,
365
- markSource,
366
- streamingRenderer,
367
- uploadsOrigin,
368
- zappieDevEntries,
369
- zappieHoistImports,
370
- zappieSource,
371
- zappieUploads,
372
- zappieWorker
373
- };
1
+ import{randomBytes}from"node:crypto";import{existsSync,readFileSync,realpathSync}from"node:fs";import{createRequire}from"node:module";import path from"node:path";import{parseSync}from"vite";var SOURCE_ATTRIBUTE="data-zappie-source";var COMPONENT_ATTRIBUTE="data-zappie-component";function zappieSource({previewHost}){let root="";return{name:"zappie-source",enforce:"pre",apply:(_config,{command})=>command==="serve",config(config){root=path.resolve(config.root??process.cwd())},configEnvironment(name){if(name!=="client"){return}const include=zappieDevEntries(root);return{optimizeDeps:{entries:["app/**/*.{js,jsx,ts,tsx}"],...include.length?{include}:{}}}},configResolved(config){root=config.root},transform:{filter:{id:/\.[jt]sx$/},handler(code,id){if(!previewHost){return null}if(!id.startsWith(`${root}/`)){return null}const file=id.slice(root.length+1);if(!file.startsWith("app/")||file.includes("node_modules/")){return null}return markSource(code,file)}}}}var SERVER_ONLY_ENTRIES={"@zappie/sdk":["./vite","./server","./testing"],"@zappie/foundations":["./next"]};function zappieDevEntries(root){return Object.entries(SERVER_ONLY_ENTRIES).flatMap(([name,serverOnly])=>{const manifest=installedManifest(root,name);if(!manifest){return[]}const exports=manifest.exports;const subpaths=exports&&typeof exports==="object"&&!Array.isArray(exports)?Object.keys(exports).filter(key=>key.startsWith(".")):["."];return subpaths.filter(subpath=>!serverOnly.includes(subpath)&&!subpath.includes("*")&&!/\.(?:css|json)$/.test(subpath)).map(subpath=>subpath==="."?name:`${name}${subpath.slice(1)}`)})}function installedManifest(root,name){for(let directory=path.resolve(root);;directory=path.dirname(directory)){const file=path.join(directory,"node_modules",name,"package.json");if(existsSync(file)){const real=realpathSync(file);return real.split(path.sep).includes("node_modules")?JSON.parse(readFileSync(real,"utf8")):void 0}if(path.dirname(directory)===directory){return void 0}}}function markSource(code,file){if(!/^[\x21-\x7e]+$/.test(file)){return null}const escaped=file.replaceAll("&","&amp;").replaceAll('"',"&quot;").replaceAll("<","&lt;");const parsed=parseSync(file,code);if(parsed.errors.length>0){return null}const lineStarts=[0];for(let index=code.indexOf("\n");index!==-1;index=code.indexOf("\n",index+1)){lineStarts.push(index+1)}const lineOf=offset=>{let low=0;let high=lineStarts.length-1;while(low<high){const middle=low+high+1>>1;if(lineStarts[middle]<=offset){low=middle}else{high=middle-1}}return low};const inserts=[];const visit=(value,component)=>{if(!value||typeof value!=="object"){return}if(Array.isArray(value)){for(const entry of value){visit(entry,component)}return}const node=value;const named=componentName(node)??component;if(node.type==="JSXOpeningElement"){const name=node.name;const attributes=node.attributes;if(name.type==="JSXIdentifier"&&typeof name.name==="string"&&/^[a-z]/.test(name.name)&&!attributes.some(attribute=>attribute.name?.name===SOURCE_ATTRIBUTE)){const component2=named?` ${COMPONENT_ATTRIBUTE}="${named}"`:"";inserts.push([name.end,` ${SOURCE_ATTRIBUTE}="${escaped}:${lineOf(node.start)+1}"${component2}`])}}for(const key in node){if(key!=="type"&&key!=="start"&&key!=="end"){visit(node[key],named)}}};visit(parsed.program,void 0);if(inserts.length===0){return null}inserts.sort((a,b)=>a[0]-b[0]);let output="";let from=0;const lines=lineStarts.map(()=>[[0,0]]);const added=lineStarts.map(()=>0);for(const[offset,text]of inserts){output+=code.slice(from,offset)+text;from=offset;const line=lineOf(offset);const column=offset-lineStarts[line];added[line]+=text.length;lines[line].push([column+added[line],column])}output+=code.slice(from);let previousLine=0;let previousColumn=0;const mappings=lines.map((segments,line)=>{let previousGenerated=0;return segments.map(([generated,original])=>{const encoded=vlq(generated-previousGenerated)+"A"+vlq(line-previousLine)+vlq(original-previousColumn);previousGenerated=generated;previousLine=line;previousColumn=original;return encoded}).join(",")}).join(";");return{code:output,map:{version:3,sources:[file],names:[],mappings}}}var BASE64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function vlq(value){let rest=value<0?-value<<1|1:value<<1;let encoded="";do{let digit=rest&31;rest>>>=5;if(rest>0){digit|=32}encoded+=BASE64[digit]}while(rest>0);return encoded}function componentName(node){const id=node.id??void 0;const capitalised=name=>typeof name==="string"&&/^[A-Z]/.test(name)?name:void 0;if(node.type==="FunctionDeclaration"||node.type==="FunctionExpression"){return capitalised(id?.name)}if(node.type==="VariableDeclarator"&&id?.type==="Identifier"){return capitalised(id.name)}return void 0}function zappieHoistImports(){return{name:"zappie-hoist-imports",apply:"build",applyToEnvironment:environment=>environment.config.consumer==="client",generateBundle(_options,bundle){const importsOf=fileName=>{const chunk=bundle[fileName];return chunk?.type==="chunk"?chunk.imports:[]};for(const chunk of Object.values(bundle)){if(chunk.type!=="chunk"||!chunk.isEntry){continue}const listed=new Set([chunk.fileName,...chunk.imports]);const hoisted=[];const pending=[...chunk.imports];for(let index=0;index<pending.length;index++){for(const next of importsOf(pending[index])){if(!listed.has(next)){listed.add(next);hoisted.push(next);pending.push(next)}}}if(hoisted.length===0){continue}const from=chunk.fileName.split("/").slice(0,-1);chunk.code+=`
2
+ ${hoisted.map(file=>`import ${JSON.stringify(relativeImport(from,file))};`).join("")}
3
+ `;chunk.imports.push(...hoisted)}}}}function relativeImport(from,file){const to=file.split("/");let shared=0;while(shared<from.length&&shared<to.length-1&&from[shared]===to[shared]){shared++}const up=from.length-shared;const rest=to.slice(shared).join("/");return up===0?`./${rest}`:`${"../".repeat(up)}${rest}`}var UPLOADS_PREFIX="/_zappie/assets/";function zappieUploads({host}){const origin=uploadsOrigin(host);return{name:"zappie-uploads",apply:(_config,{command})=>command==="serve"&&Boolean(origin),configureServer(server){server.middlewares.use((request,response,next)=>{const path2=request.url??"";if(!origin||!path2.startsWith(UPLOADS_PREFIX)){next();return}void forwardUpload(origin,path2,request.method,request.headers.accept).then(({status,headers,body})=>{response.writeHead(status,headers);response.end(body)}).catch(()=>{response.writeHead(502,{"cache-control":"no-store"});response.end()})})}}}function uploadsOrigin(host){if(!host){return void 0}try{const url=new URL(host.includes("://")?host:`https://${host}`);return url.protocol==="https:"?url.origin:void 0}catch{return void 0}}async function forwardUpload(origin,path2,method="GET",accept){if(method!=="GET"&&method!=="HEAD"){return{status:405,headers:{allow:"GET, HEAD"},body:Buffer.alloc(0)}}const upstream=await fetch(`${origin}${path2}`,{method,headers:accept?{accept}:{}});const headers={};for(const key of["content-type","cache-control","vary"]){const value=upstream.headers.get(key);if(value){headers[key]=value}}return{status:upstream.status,headers,body:Buffer.from(await upstream.arrayBuffer())}}function zappieWorker(){let root=process.cwd();let building=false;let renderer;return{name:"zappie-worker",enforce:"pre",config(config,{command}){root=path.resolve(config.root??process.cwd());building=command==="build";return{define:{"import.meta.env.ZAPPIE_DEPLOY_ID":JSON.stringify(building?randomBytes(8).toString("hex"):"dev")}}},configEnvironment(name){return building&&name!=="client"?{build:{minify:true}}:void 0},resolveId:{filter:{id:STREAMING_ONLY},handler(source){if(!building||this.environment.config.consumer==="client"||!STREAMING_ONLY.test(source)){return null}renderer??(renderer=streamingRenderer(root)??null);return renderer}}}}var STREAMING_ONLY=/^react-dom\/server(?:\.edge)?$/;function streamingRenderer(root){try{const manifest=createRequire(path.join(root,"package.json")).resolve("react-dom/package.json");const file=path.join(path.dirname(manifest),"cjs","react-dom-server.edge.production.js");return existsSync(file)?file:void 0}catch{return void 0}}export{COMPONENT_ATTRIBUTE,SOURCE_ATTRIBUTE,forwardUpload,markSource,streamingRenderer,uploadsOrigin,zappieDevEntries,zappieHoistImports,zappieSource,zappieUploads,zappieWorker};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zappie/sdk",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "Typed, framework-agnostic client for Zappie menus, carts, checkout, auth and events.",
5
5
  "type": "module",
6
6
  "sideEffects": [