@zappie/sdk 0.11.1 → 0.13.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.
@@ -1,4 +1,8 @@
1
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";
2
6
  import { parseSync } from "vite";
3
7
  var SOURCE_ATTRIBUTE = "data-zappie-source";
4
8
  var COMPONENT_ATTRIBUTE = "data-zappie-component";
@@ -7,13 +11,31 @@ function zappieSource({ previewHost }) {
7
11
  return {
8
12
  name: "zappie-source",
9
13
  enforce: "pre",
10
- apply: (_config, { command }) => command === "serve" && Boolean(previewHost),
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
+ },
11
30
  configResolved(config) {
12
31
  root = config.root;
13
32
  },
14
33
  transform: {
15
34
  filter: { id: /\.[jt]sx$/ },
16
35
  handler(code, id) {
36
+ if (!previewHost) {
37
+ return null;
38
+ }
17
39
  if (!id.startsWith(`${root}/`)) {
18
40
  return null;
19
41
  }
@@ -26,6 +48,37 @@ function zappieSource({ previewHost }) {
26
48
  }
27
49
  };
28
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
+ }
29
82
  function markSource(code, file) {
30
83
  if (!/^[\x21-\x7e]+$/.test(file)) {
31
84
  return null;
@@ -204,12 +257,12 @@ function zappieUploads({ host }) {
204
257
  apply: (_config, { command }) => command === "serve" && Boolean(origin),
205
258
  configureServer(server) {
206
259
  server.middlewares.use((request, response, next) => {
207
- const path = request.url ?? "";
208
- if (!origin || !path.startsWith(UPLOADS_PREFIX)) {
260
+ const path2 = request.url ?? "";
261
+ if (!origin || !path2.startsWith(UPLOADS_PREFIX)) {
209
262
  next();
210
263
  return;
211
264
  }
212
- void forwardUpload(origin, path, request.method, request.headers.accept).then(({ status, headers, body }) => {
265
+ void forwardUpload(origin, path2, request.method, request.headers.accept).then(({ status, headers, body }) => {
213
266
  response.writeHead(status, headers);
214
267
  response.end(body);
215
268
  }).catch(() => {
@@ -231,7 +284,7 @@ function uploadsOrigin(host) {
231
284
  return void 0;
232
285
  }
233
286
  }
234
- async function forwardUpload(origin, path, method = "GET", accept) {
287
+ async function forwardUpload(origin, path2, method = "GET", accept) {
235
288
  if (method !== "GET" && method !== "HEAD") {
236
289
  return {
237
290
  status: 405,
@@ -239,7 +292,7 @@ async function forwardUpload(origin, path, method = "GET", accept) {
239
292
  body: Buffer.alloc(0)
240
293
  };
241
294
  }
242
- const upstream = await fetch(`${origin}${path}`, {
295
+ const upstream = await fetch(`${origin}${path2}`, {
243
296
  method,
244
297
  headers: accept ? { accept } : {}
245
298
  });
@@ -256,13 +309,65 @@ async function forwardUpload(origin, path, method = "GET", accept) {
256
309
  body: Buffer.from(await upstream.arrayBuffer())
257
310
  };
258
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
+ }
259
361
  export {
260
362
  COMPONENT_ATTRIBUTE,
261
363
  SOURCE_ATTRIBUTE,
262
364
  forwardUpload,
263
365
  markSource,
366
+ streamingRenderer,
264
367
  uploadsOrigin,
368
+ zappieDevEntries,
265
369
  zappieHoistImports,
266
370
  zappieSource,
267
- zappieUploads
371
+ zappieUploads,
372
+ zappieWorker
268
373
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zappie/sdk",
3
- "version": "0.11.1",
3
+ "version": "0.13.0",
4
4
  "description": "Typed, framework-agnostic client for Zappie menus, carts, checkout, auth and events.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -141,6 +141,10 @@
141
141
  "types": "./dist/site-error/react.d.ts",
142
142
  "import": "./dist/site-error/react.js"
143
143
  },
144
+ "./site-closed": {
145
+ "types": "./dist/site-closed/index.d.ts",
146
+ "import": "./dist/site-closed/index.js"
147
+ },
144
148
  "./receipts": {
145
149
  "types": "./dist/receipts/index.d.ts",
146
150
  "import": "./dist/receipts/index.js"
@@ -204,7 +208,7 @@
204
208
  "vite": "8.3.5"
205
209
  },
206
210
  "scripts": {
207
- "build": "tsup && tsup --config tsup.checkout.config.ts && tsup --config tsup.checkout-defaults.config.ts && tsup --config tsup.customer.config.ts && tsup --config tsup.in-venue.config.ts && tsup --config tsup.account.config.ts && tsup --config tsup.places.config.ts && tsup --config tsup.url.config.ts && tsup --config tsup.redirect.config.ts && tsup --config tsup.navigation.config.ts && tsup --config tsup.services.config.ts && tsup --config tsup.visits.config.ts && tsup --config tsup.pricing.config.ts && tsup --config tsup.display.config.ts && tsup --config tsup.branches.config.ts && tsup --config tsup.options.config.ts && tsup --config tsup.site-config.config.ts && tsup --config tsup.template.config.ts && tsup --config tsup.error-pages.config.ts && tsup --config tsup.site-error.config.ts && tsup --config tsup.receipts.config.ts && node ../../scripts/release-packages/build-modules.mjs --no-sources-content --unmapped=studio/index.js --unmapped=testing/index.js --unmapped=vite/index.js",
211
+ "build": "tsup && tsup --config tsup.checkout.config.ts && tsup --config tsup.checkout-defaults.config.ts && tsup --config tsup.customer.config.ts && tsup --config tsup.in-venue.config.ts && tsup --config tsup.account.config.ts && tsup --config tsup.places.config.ts && tsup --config tsup.url.config.ts && tsup --config tsup.redirect.config.ts && tsup --config tsup.navigation.config.ts && tsup --config tsup.services.config.ts && tsup --config tsup.visits.config.ts && tsup --config tsup.pricing.config.ts && tsup --config tsup.display.config.ts && tsup --config tsup.branches.config.ts && tsup --config tsup.options.config.ts && tsup --config tsup.site-config.config.ts && tsup --config tsup.template.config.ts && tsup --config tsup.error-pages.config.ts && tsup --config tsup.site-error.config.ts && tsup --config tsup.site-closed.config.ts && tsup --config tsup.receipts.config.ts && node ../../scripts/release-packages/build-modules.mjs --no-sources-content --unmapped=studio/index.js --unmapped=testing/index.js --unmapped=vite/index.js",
208
212
  "test": "vitest run --root ../.. packages/sdk/test",
209
213
  "size": "node ../../scripts/release-packages/size-sdk.mjs && size-limit"
210
214
  }