@shop-on/theme-dev-host 0.10.0 → 0.11.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.
package/README.md CHANGED
@@ -54,8 +54,8 @@ admin with `--env prod` so the right key verifies it.
54
54
 
55
55
  ## Saving back to source
56
56
 
57
- The editor's draft is in-memory — "publish" clears it, it doesn't persist. To
58
- commit your work, use the editor's **Save** (writes the current templates +
57
+ The editor's draft is in-memory and a dev install has no publish. To commit
58
+ your work, use the editor's **Save** (writes the current templates +
59
59
  section groups + settings into the theme's `src/`) or **Save as preset** (writes
60
60
  the current settings under a new named preset). Git is the checkpoint: Save →
61
61
  `src/` → commit. `--preset <handle>` picks which slot Save targets, so you can
@@ -1,9 +1,9 @@
1
1
  -----BEGIN PUBLIC KEY-----
2
- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxvrVRevpM9Q4DE8mWony
3
- MYK2AKBKEXA9sxkerBSAJutggePuPn65xwOC4V90+0SUeXUeobe8Ux0QT3QKy244
4
- oqE3Ykkonwin3+Ws81ZmI4zzo7d1MXXHkuRko64JJT1LHtOYNsxI209177qxxf6J
5
- tmprUic5tyq8U2TgcbK4qd38mSLI4QFOieDU0r3uqc8U7S4A9NnHzrba9/lUIouJ
6
- RvU1j0k4wonnk0idAkRuTWLmQRAcNZQnAVQvQ9t9ShLCC0FSnD2quvV3V1r0YnWY
7
- +sYRy67zVvJ8DgyhIuJdX8cpWPWTh0DUTspHSPMufmeeq058IIkixJz2poDIdtLl
8
- /wIDAQAB
2
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0gwrsEKhHMVyBs9LlEyT
3
+ 9xfrc6uODGXOplfjX0RSeOiDypNBY1gNsY0gYaaDhad3AASkKSgTDlxp4p3oNUpe
4
+ a/6a7eI5FoUuXcbZbcktV3fJcTYbjte18zAoslc0bUQCPh9XM0A1vwNzK/C+sCNt
5
+ rF76A3YOIniHO11wf/k5hk0ZZ17FLQHh6F1gIi0QgFO8FrkcqpCsavI4Wjc0qdMK
6
+ n5MmVA3hNfDbKjU/ZSYr7S307r8ernz6krB+WGJqscafCvp6R3eZtnrGswnjKmBX
7
+ oyglmyX6+6RIZhuhZ8mFbSx2a4jHgDZ+5uOXMsPyi86MWKykw9Q72Y7E6ytvM0mD
8
+ aQIDAQAB
9
9
  -----END PUBLIC KEY-----
package/dist/auth.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { EditorAuthError } from "./verify.mjs";
3
- //#region src/auth.ts
3
+ // src/auth.ts
4
4
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
5
5
  const SID_TTL_MS = 18e5;
6
6
  const MAX_SIDS = 100;
@@ -19,7 +19,7 @@ function createEditorAuth(verify) {
19
19
  const expires = sids.get(sid);
20
20
  return expires !== void 0 && expires > Date.now();
21
21
  }
22
- async function applyJwt(c, header, scope) {
22
+ async function applyJwt(c, header) {
23
23
  let claims;
24
24
  try {
25
25
  claims = await verify(header.slice(7));
@@ -27,31 +27,29 @@ function createEditorAuth(verify) {
27
27
  if (err instanceof EditorAuthError) return reject(c, err.reason);
28
28
  throw err;
29
29
  }
30
- if (!claims.scp.includes(scope)) return reject(c, `wrong scope (route takes ${scope})`);
30
+ if (!claims.scp.includes("editor")) return reject(c, "wrong scope (routes take editor)");
31
31
  const storeSlug = c.req.param("storeSlug") ?? "";
32
32
  const installId = c.req.param("installId") ?? "";
33
33
  if (claims.shop_handle !== storeSlug) return reject(c, `shop mismatch (token shop_handle=${claims.shop_handle}, path=${storeSlug})`);
34
34
  if (claims.install_id !== installId) return reject(c, `install mismatch (token install_id=${claims.install_id}, path=${installId})`);
35
- if (scope === "editor") registerSid(claims.sid);
35
+ registerSid(claims.sid);
36
36
  c.set("sid", claims.sid);
37
37
  c.set("shopHandle", storeSlug);
38
38
  c.set("installId", installId);
39
39
  c.set("userId", claims.sub ?? "");
40
40
  return null;
41
41
  }
42
- function bearerOnly(scope) {
43
- return async (c, next) => {
44
- const header = c.req.header("Authorization");
45
- if (!header?.startsWith("Bearer ")) return reject(c, "missing bearer token");
46
- const fail = await applyJwt(c, header, scope);
47
- if (fail) return fail;
48
- await next();
49
- };
50
- }
42
+ const editorAuth = async (c, next) => {
43
+ const header = c.req.header("Authorization");
44
+ if (!header?.startsWith("Bearer ")) return reject(c, "missing bearer token");
45
+ const fail = await applyJwt(c, header);
46
+ if (fail) return fail;
47
+ await next();
48
+ };
51
49
  const editorAuthOrPreview = async (c, next) => {
52
50
  const header = c.req.header("Authorization");
53
51
  if (header?.startsWith("Bearer ")) {
54
- const fail = await applyJwt(c, header, "editor");
52
+ const fail = await applyJwt(c, header);
55
53
  if (fail) return fail;
56
54
  await next();
57
55
  return;
@@ -66,10 +64,8 @@ function createEditorAuth(verify) {
66
64
  await next();
67
65
  };
68
66
  return {
69
- editorAuth: bearerOnly("editor"),
70
- publishAuth: bearerOnly("editor:publish"),
67
+ editorAuth,
71
68
  editorAuthOrPreview
72
69
  };
73
70
  }
74
- //#endregion
75
71
  export { createEditorAuth };
package/dist/drafts.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { applyOps, touchedEntries } from "@shop-on/theme-contract/ops";
3
- //#region src/drafts.ts
3
+ // src/drafts.ts
4
4
  /** Batches kept for `GET /draft/ops`; a client further behind gets `{reset}`. */
5
5
  const RING_SIZE = 256;
6
6
  const READ_COUNT = 32;
@@ -12,7 +12,6 @@ function createDraftStore() {
12
12
  if (!d) {
13
13
  d = {
14
14
  seq: 0,
15
- publishedSeq: 0,
16
15
  templates: /* @__PURE__ */ new Map(),
17
16
  groups: /* @__PURE__ */ new Map(),
18
17
  clients: /* @__PURE__ */ new Map(),
@@ -30,13 +29,6 @@ function createDraftStore() {
30
29
  seq(key) {
31
30
  return drafts.get(key)?.seq ?? 0;
32
31
  },
33
- publishedSeq(key) {
34
- return drafts.get(key)?.publishedSeq ?? 0;
35
- },
36
- hasUnpublishedEdits(key) {
37
- const d = drafts.get(key);
38
- return d !== void 0 && d.seq > d.publishedSeq;
39
- },
40
32
  /** The draft's settings, or undefined when the draft never touched them. */
41
33
  settings(key) {
42
34
  return drafts.get(key)?.settings;
@@ -117,25 +109,6 @@ function createDraftStore() {
117
109
  seq: d.seq
118
110
  };
119
111
  },
120
- /** Drop every edit (publish / discard): the next read is the disk copy. */
121
- reset(key, reset) {
122
- const d = draftFor(key);
123
- d.settings = void 0;
124
- d.templates.clear();
125
- d.groups.clear();
126
- d.clients.clear();
127
- d.seq += 1;
128
- d.publishedSeq = d.seq;
129
- push(d, {
130
- seq: d.seq,
131
- clientId: "",
132
- batchId: "",
133
- userId: "",
134
- ops: [],
135
- reset
136
- });
137
- return d.seq;
138
- },
139
112
  /** Batches after `since`, or `{reset}` when the ring cannot catch the client up. */
140
113
  readSince(key, since) {
141
114
  const d = drafts.get(key);
@@ -165,5 +138,4 @@ function createDraftStore() {
165
138
  }
166
139
  };
167
140
  }
168
- //#endregion
169
141
  export { createDraftStore };
@@ -13,11 +13,11 @@ import { MAX_BATCH_BYTES, OpBatchBodySchema, TabOpBatchBodySchema, agentClientId
13
13
  import { CUSTOM_SECTION_VALIDATING_TOOLS, applyEditorTool, isEditorToolName } from "@shop-on/theme-contract/editor-tools";
14
14
  import { readThemeAiDir } from "@shop-on/theme-contract/ai-files";
15
15
  import { invalidTemplateId } from "@shop-on/theme-contract/store-path";
16
- //#region src/editor-app.ts
16
+ // src/editor-app.ts
17
17
  const PREFIX = "/api/stores/:storeSlug/:installId";
18
18
  const PROTOCOL_VERSION = 2;
19
19
  function registerEditorRoutes(app, configDir, auth, store, opts) {
20
- const { editorAuth, publishAuth, editorAuthOrPreview } = auth;
20
+ const { editorAuth, editorAuthOrPreview } = auth;
21
21
  const themeSrcDir = opts?.themeSrcDir;
22
22
  const presetOverride = opts?.preset;
23
23
  const drafts = createDraftStore();
@@ -94,7 +94,6 @@ function registerEditorRoutes(app, configDir, auth, store, opts) {
94
94
  app.get(`${PREFIX}/editor-loader`, editorAuthOrPreview, async (c) => {
95
95
  const key = draftKey(c);
96
96
  const seq = drafts.seq(key);
97
- const publishedSeq = drafts.publishedSeq(key);
98
97
  const locale = await loadLocale(configDir, parseLang(c));
99
98
  const [schemaRaw, sections, blocks, templates, sectionGroups] = await Promise.all([
100
99
  readFile(path.join(configDir, "settings-schema.json"), "utf-8").catch(() => null),
@@ -143,7 +142,6 @@ function registerEditorRoutes(app, configDir, auth, store, opts) {
143
142
  settings,
144
143
  activePreset,
145
144
  seq,
146
- publishedSeq,
147
145
  protocolVersion: PROTOCOL_VERSION
148
146
  });
149
147
  });
@@ -284,23 +282,6 @@ function registerEditorRoutes(app, configDir, auth, store, opts) {
284
282
  });
285
283
  });
286
284
  app.post(`${PREFIX}/draft/touch`, editorAuth, (c) => c.body(null, 204));
287
- app.delete(`${PREFIX}/draft`, publishAuth, (c) => {
288
- const key = draftKey(c);
289
- if (!drafts.hasUnpublishedEdits(key)) return c.json({ error: "No unpublished changes" }, 404);
290
- return c.json({
291
- ok: true,
292
- seq: drafts.reset(key, "discard")
293
- });
294
- });
295
- app.post(`${PREFIX}/publish`, publishAuth, (c) => {
296
- const key = draftKey(c);
297
- if (!drafts.hasUnpublishedEdits(key)) return c.json({ error: "No unpublished changes" }, 404);
298
- drafts.reset(key, "publish");
299
- return c.json({
300
- ok: true,
301
- published: true
302
- });
303
- });
304
285
  async function saveListingPreset() {
305
286
  if (!themeSrcDir) return void 0;
306
287
  try {
@@ -399,5 +380,4 @@ function registerEditorRoutes(app, configDir, auth, store, opts) {
399
380
  }
400
381
  });
401
382
  }
402
- //#endregion
403
383
  export { registerEditorRoutes };
package/dist/gateway.mjs CHANGED
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
  import { materializeThemeConfig, watchThemeConfig } from "./materialize.mjs";
3
- import { createEditorVerifier } from "./verify.mjs";
4
- import { createEditorAuth } from "./auth.mjs";
5
3
  import { registerEditorRoutes } from "./editor-app.mjs";
6
4
  import { createProxy } from "./proxy.mjs";
5
+ import { createEditorAuth } from "./auth.mjs";
6
+ import { createEditorVerifier } from "./verify.mjs";
7
7
  import { mkdtempSync } from "node:fs";
8
8
  import path from "node:path";
9
9
  import os from "node:os";
10
10
  import { Hono } from "hono";
11
11
  import { serve } from "@hono/node-server";
12
- //#region src/gateway.ts
12
+ // src/gateway.ts
13
13
  async function startGateway(opts) {
14
14
  const themeSrcDir = path.join(opts.themeDir, "src");
15
15
  const storesDir = mkdtempSync(path.join(os.tmpdir(), "theme-dev-host-"));
@@ -41,5 +41,4 @@ async function startGateway(opts) {
41
41
  }
42
42
  };
43
43
  }
44
- //#endregion
45
44
  export { startGateway };
package/dist/keys.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFileSync } from "node:fs";
3
3
  import path from "node:path";
4
- //#region src/keys.ts
4
+ // src/keys.ts
5
5
  const PLATFORM_ENVS = [
6
6
  "dev",
7
7
  "staging",
@@ -16,5 +16,4 @@ function resolveJwtPublicKey(env) {
16
16
  const certPath = path.resolve(import.meta.dirname, "../certs", `jwtRS256.${env}.pub`);
17
17
  return readFileSync(certPath, "utf-8");
18
18
  }
19
- //#endregion
20
19
  export { PLATFORM_ENVS, isPlatformEnv, resolveJwtPublicKey };
package/dist/launch.mjs CHANGED
@@ -5,7 +5,7 @@ import { isPlatformEnv, resolveJwtPublicKey } from "./keys.mjs";
5
5
  import { spawn } from "node:child_process";
6
6
  import { readFileSync } from "node:fs";
7
7
  import path from "node:path";
8
- //#region src/launch.ts
8
+ // src/launch.ts
9
9
  function flagValue(name) {
10
10
  const i = process.argv.indexOf(`--${name}`);
11
11
  if (i < 0) return void 0;
@@ -95,5 +95,4 @@ child.on("exit", (code) => {
95
95
  console.log(`\ntheme dev server exited — shutting down gateway.`);
96
96
  shutdown(code ?? 0);
97
97
  });
98
- //#endregion
99
98
  export {};
package/dist/locale.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import path from "node:path";
3
3
  import { readFile, readdir } from "node:fs/promises";
4
- //#region src/locale.ts
4
+ // src/locale.ts
5
5
  async function readJsonDir(dir) {
6
6
  let files;
7
7
  try {
@@ -99,5 +99,4 @@ function parseLang(c) {
99
99
  function unwrapSettings(data, preset) {
100
100
  return data.presets ? data.presets[preset ?? data.current?.preset]?.settings ?? {} : data;
101
101
  }
102
- //#endregion
103
102
  export { LANG_RE, loadLocale, loadStorefrontLocale, parseLang, readJsonDir, resolveDisplayName, resolveTranslations, unwrapSettings };
@@ -4,7 +4,7 @@ import path from "node:path";
4
4
  import { copyFile, cp, mkdir, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
5
5
  import { currentPresetHandle } from "@shop-on/theme-contract/preset-listing";
6
6
  import { overlayPresetListing } from "@shop-on/theme-contract/preset-materializer";
7
- //#region src/materialize.ts
7
+ // src/materialize.ts
8
8
  const JSON_DIRS = [
9
9
  "sections",
10
10
  "blocks",
@@ -80,5 +80,4 @@ function watchThemeConfig(themeSrcDir, configDir, opts = {}) {
80
80
  }, 150);
81
81
  });
82
82
  }
83
- //#endregion
84
83
  export { materializeThemeConfig, watchThemeConfig };
package/dist/proxy.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- //#region src/proxy.ts
2
+ // src/proxy.ts
3
3
  function createProxy(target) {
4
4
  const targetOrigin = new URL(target).origin;
5
5
  return async (c) => {
@@ -31,5 +31,4 @@ function createProxy(target) {
31
31
  });
32
32
  };
33
33
  }
34
- //#endregion
35
34
  export { createProxy };
package/dist/richtext.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { RICHTEXT_SANITIZE_CONFIG, registerRichTextHooks } from "@shop-on/theme-contract/editor-tools";
3
- //#region src/richtext.ts
3
+ // src/richtext.ts
4
4
  let loading;
5
5
  function loadRichTextSanitizer() {
6
6
  loading ??= import("isomorphic-dompurify").then(({ default: purify }) => {
@@ -12,5 +12,4 @@ function loadRichTextSanitizer() {
12
12
  });
13
13
  return loading;
14
14
  }
15
- //#endregion
16
15
  export { loadRichTextSanitizer };
package/dist/save.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import path from "node:path";
3
3
  import { mkdir, readFile, writeFile } from "node:fs/promises";
4
4
  import { PRESET_HANDLE_RE } from "@shop-on/theme-contract/preset-listing";
5
- //#region src/save.ts
5
+ // src/save.ts
6
6
  function serialize(data) {
7
7
  return `${JSON.stringify(data, null, 2)}\n`;
8
8
  }
@@ -50,5 +50,4 @@ async function writeSettingsPreset(themeSrcDir, handle, settings, opts = {}) {
50
50
  await mkdir(path.dirname(file), { recursive: true });
51
51
  await writeFile(file, serialize(next), "utf-8");
52
52
  }
53
- //#endregion
54
53
  export { isValidPresetHandle, isWritableThemePath, writeSettingsPreset, writeThemeSourceFiles };
package/dist/tunnel.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawn } from "node:child_process";
3
- //#region src/tunnel.ts
3
+ // src/tunnel.ts
4
4
  const PROVIDERS = {
5
5
  cloudflared: {
6
6
  argv: (port) => [
@@ -89,5 +89,4 @@ async function startTunnel(provider, port, publicUrl) {
89
89
  const p = PROVIDERS[provider];
90
90
  return spawnTunnel(provider, p.argv(port), p.urlRe);
91
91
  }
92
- //#endregion
93
92
  export { startTunnel };
package/dist/verify.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { importSPKI, jwtVerify } from "jose";
3
- //#region src/verify.ts
3
+ // src/verify.ts
4
4
  var EditorAuthError = class extends Error {
5
5
  reason;
6
6
  constructor(reason) {
@@ -34,5 +34,4 @@ function createEditorVerifier(pem) {
34
34
  }
35
35
  };
36
36
  }
37
- //#endregion
38
37
  export { EditorAuthError, createEditorVerifier };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shop-on/theme-dev-host",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Local theme-editor dev server: serves the editor contract + proxies a theme's dev server behind one origin, so a theme runs locally and previews in a real admin theme-editor. Nucleus of the future theme CLI.",
5
5
  "license": "SEE LICENSE IN dist/LICENSE.md",
6
6
  "bin": {
@@ -12,17 +12,17 @@
12
12
  ],
13
13
  "type": "module",
14
14
  "dependencies": {
15
- "@hono/node-server": "^2.1.5",
16
- "hono": "^4.13.13",
17
- "isomorphic-dompurify": "4.6.0",
18
- "jose": "^6.2.13",
19
- "@shop-on/theme-contract": "0.10.0"
15
+ "@hono/node-server": "^2.1.8",
16
+ "@shop-on/theme-contract": "0.11.0",
17
+ "hono": "^4.13.18",
18
+ "isomorphic-dompurify": "4.7.0",
19
+ "jose": "^6.2.17"
20
20
  },
21
21
  "devDependencies": {
22
- "@types/node": "26.6.5",
22
+ "@types/node": "26.6.6",
23
23
  "tsx": "^4.23.15",
24
24
  "typescript": "7.0.2",
25
- "vitest": "5.0.5"
25
+ "vitest": "5.1.0"
26
26
  },
27
27
  "scripts": {
28
28
  "dev": "tsx src/index.ts",