@zappie/sdk 0.18.0 → 0.18.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 (295) hide show
  1. package/CHANGELOG.md +6 -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.js +1 -12
  59. package/dist/config/index.js.map +1 -1
  60. package/dist/config.js +1 -27
  61. package/dist/config.js.map +1 -1
  62. package/dist/customer/client.js +1 -180
  63. package/dist/customer/client.js.map +1 -1
  64. package/dist/customer/error.js +1 -18
  65. package/dist/customer/error.js.map +1 -1
  66. package/dist/customer/index.js +1 -7
  67. package/dist/customer/index.js.map +1 -1
  68. package/dist/customer/navigation.js +1 -39
  69. package/dist/customer/navigation.js.map +1 -1
  70. package/dist/customer/react.js +1 -69
  71. package/dist/customer/react.js.map +1 -1
  72. package/dist/customer/reorder.js +1 -60
  73. package/dist/customer/reorder.js.map +1 -1
  74. package/dist/customer/request.js +1 -37
  75. package/dist/customer/request.js.map +1 -1
  76. package/dist/customer/watch-order.js +1 -79
  77. package/dist/customer/watch-order.js.map +1 -1
  78. package/dist/debug.js +1 -77
  79. package/dist/debug.js.map +1 -1
  80. package/dist/display/index.js +1 -30
  81. package/dist/display/index.js.map +1 -1
  82. package/dist/error-pages/art.js +1 -10
  83. package/dist/error-pages/art.js.map +1 -1
  84. package/dist/error-pages/index.js +2 -103
  85. package/dist/error-pages/index.js.map +1 -1
  86. package/dist/error-pages/react.js +1 -65
  87. package/dist/error-pages/react.js.map +1 -1
  88. package/dist/errors.js +1 -70
  89. package/dist/errors.js.map +1 -1
  90. package/dist/in-venue/bill.js +1 -69
  91. package/dist/in-venue/bill.js.map +1 -1
  92. package/dist/in-venue/client.js +1 -119
  93. package/dist/in-venue/client.js.map +1 -1
  94. package/dist/in-venue/error.js +1 -18
  95. package/dist/in-venue/error.js.map +1 -1
  96. package/dist/in-venue/index.js +1 -23
  97. package/dist/in-venue/index.js.map +1 -1
  98. package/dist/in-venue/react/bill-page.js +1 -350
  99. package/dist/in-venue/react/bill-page.js.map +1 -1
  100. package/dist/in-venue/react/in-venue-page.js +1 -102
  101. package/dist/in-venue/react/in-venue-page.js.map +1 -1
  102. package/dist/in-venue/react/order-panel.js +1 -283
  103. package/dist/in-venue/react/order-panel.js.map +1 -1
  104. package/dist/in-venue/react/pay-point-page.js +1 -50
  105. package/dist/in-venue/react/pay-point-page.js.map +1 -1
  106. package/dist/in-venue/react/shared.js +2 -171
  107. package/dist/in-venue/react/shared.js.map +1 -1
  108. package/dist/in-venue/react/table-menus-page.js +1 -151
  109. package/dist/in-venue/react/table-menus-page.js.map +1 -1
  110. package/dist/in-venue/react.js +1 -14
  111. package/dist/in-venue/react.js.map +1 -1
  112. package/dist/in-venue/table.js +1 -62
  113. package/dist/in-venue/table.js.map +1 -1
  114. package/dist/in-venue/watch.js +1 -82
  115. package/dist/in-venue/watch.js.map +1 -1
  116. package/dist/index.js +1 -31
  117. package/dist/index.js.map +1 -1
  118. package/dist/integrations/index.js +1 -78
  119. package/dist/integrations/index.js.map +1 -1
  120. package/dist/internal/abort.js +1 -28
  121. package/dist/internal/abort.js.map +1 -1
  122. package/dist/internal/cache.js +1 -141
  123. package/dist/internal/cache.js.map +1 -1
  124. package/dist/internal/customer-http.js +1 -75
  125. package/dist/internal/customer-http.js.map +1 -1
  126. package/dist/internal/emitter.js +1 -26
  127. package/dist/internal/emitter.js.map +1 -1
  128. package/dist/internal/image-widths.js +1 -5
  129. package/dist/internal/image-widths.js.map +1 -1
  130. package/dist/internal/money-math.js +1 -29
  131. package/dist/internal/money-math.js.map +1 -1
  132. package/dist/internal/perk-hold.js +1 -34
  133. package/dist/internal/perk-hold.js.map +1 -1
  134. package/dist/internal/remembered-address.js +1 -68
  135. package/dist/internal/remembered-address.js.map +1 -1
  136. package/dist/internal/return-path.js +1 -16
  137. package/dist/internal/return-path.js.map +1 -1
  138. package/dist/internal/service-url.js +1 -10
  139. package/dist/internal/service-url.js.map +1 -1
  140. package/dist/internal.js +1 -8
  141. package/dist/internal.js.map +1 -1
  142. package/dist/loyalty/cart.js +1 -55
  143. package/dist/loyalty/cart.js.map +1 -1
  144. package/dist/loyalty/client.js +1 -88
  145. package/dist/loyalty/client.js.map +1 -1
  146. package/dist/loyalty/index.js +1 -12
  147. package/dist/loyalty/index.js.map +1 -1
  148. package/dist/loyalty/react.js +1 -199
  149. package/dist/loyalty/react.js.map +1 -1
  150. package/dist/loyalty/release.js +1 -42
  151. package/dist/loyalty/release.js.map +1 -1
  152. package/dist/money.js +1 -46
  153. package/dist/money.js.map +1 -1
  154. package/dist/navigation/index.js +1 -55
  155. package/dist/navigation/index.js.map +1 -1
  156. package/dist/navigation/react.js +1 -17
  157. package/dist/navigation/react.js.map +1 -1
  158. package/dist/navigation-progress/index.js +1 -41
  159. package/dist/navigation-progress/index.js.map +1 -1
  160. package/dist/options/index.js +1 -103
  161. package/dist/options/index.js.map +1 -1
  162. package/dist/persist/catalogue.js +1 -205
  163. package/dist/persist/catalogue.js.map +1 -1
  164. package/dist/places/client.js +1 -96
  165. package/dist/places/client.js.map +1 -1
  166. package/dist/places/error.js +1 -18
  167. package/dist/places/error.js.map +1 -1
  168. package/dist/places/index.js +1 -7
  169. package/dist/places/index.js.map +1 -1
  170. package/dist/places/request.js +1 -39
  171. package/dist/places/request.js.map +1 -1
  172. package/dist/places/sdk.js +1 -9
  173. package/dist/places/sdk.js.map +1 -1
  174. package/dist/places/search.js +1 -79
  175. package/dist/places/search.js.map +1 -1
  176. package/dist/pricing/index.js +1 -80
  177. package/dist/pricing/index.js.map +1 -1
  178. package/dist/react/cart.js +1 -40
  179. package/dist/react/cart.js.map +1 -1
  180. package/dist/react/changes.js +1 -93
  181. package/dist/react/changes.js.map +1 -1
  182. package/dist/react/hooks.js +1 -90
  183. package/dist/react/hooks.js.map +1 -1
  184. package/dist/react/index.js +1 -19
  185. package/dist/react/index.js.map +1 -1
  186. package/dist/react/provider.js +1 -33
  187. package/dist/react/provider.js.map +1 -1
  188. package/dist/react/rollback.js +1 -89
  189. package/dist/react/rollback.js.map +1 -1
  190. package/dist/receipts/index.js +1 -48
  191. package/dist/receipts/index.js.map +1 -1
  192. package/dist/redirect/index.js +1 -30
  193. package/dist/redirect/index.js.map +1 -1
  194. package/dist/server/auth/crypto.js +1 -105
  195. package/dist/server/auth/crypto.js.map +1 -1
  196. package/dist/server/auth/jwt.js +1 -203
  197. package/dist/server/auth/jwt.js.map +1 -1
  198. package/dist/server/auth/session-store.js +1 -45
  199. package/dist/server/auth/session-store.js.map +1 -1
  200. package/dist/server/chosen-branch.js +1 -69
  201. package/dist/server/chosen-branch.js.map +1 -1
  202. package/dist/server/edge-cache.js +1 -394
  203. package/dist/server/edge-cache.js.map +1 -1
  204. package/dist/server/edge-snapshot.js +1 -199
  205. package/dist/server/edge-snapshot.js.map +1 -1
  206. package/dist/server/index.js +1 -113
  207. package/dist/server/index.js.map +1 -1
  208. package/dist/server/security.js +1 -135
  209. package/dist/server/security.js.map +1 -1
  210. package/dist/server/sign-in.js +1 -17
  211. package/dist/server/sign-in.js.map +1 -1
  212. package/dist/server/storefront-url/build-v1.js +1 -65
  213. package/dist/server/storefront-url/build-v1.js.map +1 -1
  214. package/dist/server/storefront-url/build-v2.js +1 -50
  215. package/dist/server/storefront-url/build-v2.js.map +1 -1
  216. package/dist/server/storefront-url/build.js +1 -18
  217. package/dist/server/storefront-url/build.js.map +1 -1
  218. package/dist/server/storefront-url/canonical.js +1 -35
  219. package/dist/server/storefront-url/canonical.js.map +1 -1
  220. package/dist/server/storefront-url/contract.js +1 -24
  221. package/dist/server/storefront-url/contract.js.map +1 -1
  222. package/dist/server/storefront-url/index.js +1 -15
  223. package/dist/server/storefront-url/index.js.map +1 -1
  224. package/dist/server/storefront-url/installation.js +1 -57
  225. package/dist/server/storefront-url/installation.js.map +1 -1
  226. package/dist/server/storefront-url/params.js +1 -88
  227. package/dist/server/storefront-url/params.js.map +1 -1
  228. package/dist/server/storefront-url/parse-v1.js +1 -137
  229. package/dist/server/storefront-url/parse-v1.js.map +1 -1
  230. package/dist/server/storefront-url/parse-v2.js +1 -84
  231. package/dist/server/storefront-url/parse-v2.js.map +1 -1
  232. package/dist/server/storefront-url/parse.js +1 -8
  233. package/dist/server/storefront-url/parse.js.map +1 -1
  234. package/dist/server/storefront-url/public-id.js +1 -7
  235. package/dist/server/storefront-url/public-id.js.map +1 -1
  236. package/dist/server/storefront-url/redirect.js +1 -43
  237. package/dist/server/storefront-url/redirect.js.map +1 -1
  238. package/dist/server/storefront-url/sign-in.js +1 -17
  239. package/dist/server/storefront-url/sign-in.js.map +1 -1
  240. package/dist/server/storefront-url/types.js +1 -55
  241. package/dist/server/storefront-url/types.js.map +1 -1
  242. package/dist/server/storefront-url/url.js +1 -73
  243. package/dist/server/storefront-url/url.js.map +1 -1
  244. package/dist/server/webhook.js +1 -95
  245. package/dist/server/webhook.js.map +1 -1
  246. package/dist/services/index.js +1 -18
  247. package/dist/services/index.js.map +1 -1
  248. package/dist/site-closed/index.js +1 -38
  249. package/dist/site-closed/index.js.map +1 -1
  250. package/dist/site-config/helpers.js +1 -58
  251. package/dist/site-config/helpers.js.map +1 -1
  252. package/dist/site-config/sections.js +1 -114
  253. package/dist/site-config/sections.js.map +1 -1
  254. package/dist/site-config/types.js +1 -31
  255. package/dist/site-config/types.js.map +1 -1
  256. package/dist/site-config/validate.js +1 -215
  257. package/dist/site-config/validate.js.map +1 -1
  258. package/dist/site-error/index.js +1 -32
  259. package/dist/site-error/index.js.map +1 -1
  260. package/dist/site-error/react.js +1 -14
  261. package/dist/site-error/react.js.map +1 -1
  262. package/dist/studio/index.js +1 -315
  263. package/dist/template/index.js +1 -88
  264. package/dist/template/index.js.map +1 -1
  265. package/dist/template/react.js +1 -111
  266. package/dist/template/react.js.map +1 -1
  267. package/dist/testing/index.js +1 -459
  268. package/dist/testing/loyalty.js +1 -109
  269. package/dist/testing/loyalty.js.map +1 -1
  270. package/dist/transport/category-page.js +1 -24
  271. package/dist/transport/category-page.js.map +1 -1
  272. package/dist/transport/mappers.js +1 -356
  273. package/dist/transport/mappers.js.map +1 -1
  274. package/dist/transport/presentation.js +1 -67
  275. package/dist/transport/presentation.js.map +1 -1
  276. package/dist/transport/quote-body.js +1 -23
  277. package/dist/transport/quote-body.js.map +1 -1
  278. package/dist/transport/rest.js +1 -327
  279. package/dist/transport/rest.js.map +1 -1
  280. package/dist/transport/search.js +1 -36
  281. package/dist/transport/search.js.map +1 -1
  282. package/dist/transport/selected-menu.js +1 -83
  283. package/dist/transport/selected-menu.js.map +1 -1
  284. package/dist/transport/store.js +1 -132
  285. package/dist/transport/store.js.map +1 -1
  286. package/dist/uploads/index.js +1 -36
  287. package/dist/uploads/index.js.map +1 -1
  288. package/dist/url/index.js +1 -15
  289. package/dist/url/index.js.map +1 -1
  290. package/dist/visits/index.js +1 -61
  291. package/dist/visits/index.js.map +1 -1
  292. package/dist/visits/page-views.js +1 -102
  293. package/dist/visits/page-views.js.map +1 -1
  294. package/dist/vite/index.js +3 -373
  295. 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.18.1",
4
4
  "description": "Typed, framework-agnostic client for Zappie menus, carts, checkout, auth and events.",
5
5
  "type": "module",
6
6
  "sideEffects": [