camox 0.5.2 → 0.6.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.
@@ -1 +1 @@
1
- {"version":3,"file":"definitionsSync.d.ts","sourceRoot":"","sources":["../../../src/features/vite/definitionsSync.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAElD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAOjD,UAAU,sBAAsB;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACzB;AAgBD,wBAAsB,oBAAoB,CAAC,OAAO,EAAE;IAClD,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC,IAAI,CAAC,CAwFhB;AASD,wBAAsB,eAAe,CACnC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAkLf"}
1
+ {"version":3,"file":"definitionsSync.d.ts","sourceRoot":"","sources":["../../../src/features/vite/definitionsSync.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,aAAa,EAA0C,MAAM,MAAM,CAAC;AAE/F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAOjD,UAAU,sBAAsB;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACzB;AAgBD,wBAAsB,oBAAoB,CAAC,OAAO,EAAE;IAClD,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC,IAAI,CAAC,CAwFhB;AAsCD,wBAAsB,eAAe,CACnC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAkLf"}
@@ -1,5 +1,6 @@
1
1
  import { createServerApiClient } from "../../lib/api-client-server.js";
2
2
  import path from "node:path";
3
+ import { createServer, isRunnableDevEnvironment } from "vite";
3
4
  //#region src/features/vite/definitionsSync.ts
4
5
  var SYNC_DEBOUNCE_DELAY_MS = 100;
5
6
  /**
@@ -71,12 +72,33 @@ function getBlockIdFromFilePath(filePath) {
71
72
  return path.basename(filePath, path.extname(filePath));
72
73
  }
73
74
  var CAMOX_APP_PATH = "./src/camox/app.ts";
75
+ /**
76
+ * Load a module using SSR. Uses the server's SSR environment runner if available,
77
+ * otherwise falls back to a temporary Vite server (needed when Nitro or other
78
+ * frameworks configure the SSR environment as non-runnable).
79
+ */
80
+ async function ssrLoadModule(server, modulePath) {
81
+ const ssrEnv = server.environments.ssr;
82
+ if (ssrEnv && isRunnableDevEnvironment(ssrEnv)) return ssrEnv.runner.import(modulePath);
83
+ const tempServer = await createServer({
84
+ configFile: false,
85
+ root: server.config.root,
86
+ resolve: server.config.resolve,
87
+ server: { middlewareMode: true },
88
+ logLevel: "silent"
89
+ });
90
+ try {
91
+ return await tempServer.ssrLoadModule(modulePath);
92
+ } finally {
93
+ await tempServer.close();
94
+ }
95
+ }
74
96
  async function syncDefinitions(server, options) {
75
97
  const { projectSlug, syncSecret, apiUrl, environmentName } = options;
76
98
  const blocksDir = path.resolve(server.config.root, "src/camox/blocks");
77
99
  const client = createServerApiClient(apiUrl, environmentName);
78
100
  async function performInitialSync() {
79
- const camoxModule = await server.ssrLoadModule(CAMOX_APP_PATH);
101
+ const camoxModule = await ssrLoadModule(server, CAMOX_APP_PATH);
80
102
  if (!camoxModule.camoxApp) {
81
103
  server.config.logger.warn(`[camox] No camoxApp export found in ${CAMOX_APP_PATH}`, { timestamp: true });
82
104
  return;
@@ -94,7 +116,7 @@ async function syncDefinitions(server, options) {
94
116
  const relativePath = "./" + path.relative(server.config.root, filePath);
95
117
  const moduleNode = server.moduleGraph.getModuleById(relativePath);
96
118
  if (moduleNode) server.moduleGraph.invalidateModule(moduleNode);
97
- const blockModule = await server.ssrLoadModule(relativePath);
119
+ const blockModule = await ssrLoadModule(server, relativePath);
98
120
  if (!blockModule.block) {
99
121
  server.config.logger.warn(`[camox] No block export found in ${relativePath}`, { timestamp: true });
100
122
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../../src/features/vite/vite.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,MAAM,CAAC;AAuClE,MAAM,WAAW,kBAAkB;IACjC,0FAA0F;IAC1F,WAAW,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,4FAA4F;IAC5F,SAAS,CAAC,EAAE;QACV,2DAA2D;QAC3D,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,0EAA0E;QAC1E,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,oDAAoD;QACpD,sBAAsB,CAAC,EAAE,OAAO,CAAC;KAClC,CAAC;CACH;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CA2HzD"}
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../../src/features/vite/vite.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,MAAM,EAAyD,MAAM,MAAM,CAAC;AAoD1F,MAAM,WAAW,kBAAkB;IACjC,0FAA0F;IAC1F,WAAW,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,4FAA4F;IAC5F,SAAS,CAAC,EAAE;QACV,2DAA2D;QAC3D,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,0EAA0E;QAC1E,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,oDAAoD;QACpD,sBAAsB,CAAC,EAAE,OAAO,CAAC;KAClC,CAAC;CACH;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAuHzD"}
@@ -7,23 +7,33 @@ import { readFileSync } from "node:fs";
7
7
  import { homedir } from "node:os";
8
8
  import { dirname, join, resolve } from "node:path";
9
9
  import { fileURLToPath } from "node:url";
10
+ import { createServer } from "vite";
10
11
  //#region src/features/vite/vite.ts
11
12
  var sdkRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");
12
13
  var VIRTUAL_STUDIO_CSS = "virtual:camox-studio-css";
13
14
  var RESOLVED_VIRTUAL_STUDIO_CSS = "\0" + VIRTUAL_STUDIO_CSS;
15
+ /**
16
+ * use-sync-external-store is CJS-only and causes issues in ESM environments.
17
+ * Since all Camox apps use React 19+, we can redirect imports to React's built-in
18
+ * useSyncExternalStore instead. This handles all subpaths (e.g. /shim, /shim/index.js).
19
+ */
20
+ var USE_SYNC_EXTERNAL_STORE_RE = /^use-sync-external-store(\/|$)/;
21
+ var RESOLVED_USE_SYNC_SHIM = "\0use-sync-external-store-shim";
22
+ var USE_SYNC_SHIM_CODE = `export { useSyncExternalStore } from "react";\n`;
14
23
  var PRODUCTION_API_URL = "https://api.camox.ai";
15
24
  /** Authentication URL to use for Camox authentication (production Camox web app) */
16
25
  var DEFAULT_AUTHENTICATION_URL = "https://camox.ai";
17
- function resolveEnvironmentName(isDev) {
26
+ function resolveEnvironmentName(isDev, authenticationUrl) {
18
27
  if (!isDev) return "production";
19
28
  const authFile = join(homedir(), ".camox", "auth.json");
29
+ const key = authenticationUrl.replace(/\/+$/, "");
20
30
  let auth;
21
31
  try {
22
- auth = JSON.parse(readFileSync(authFile, "utf-8"));
32
+ auth = JSON.parse(readFileSync(authFile, "utf-8"))[key];
23
33
  } catch {
24
- throw new Error("Camox: not authenticated. Run `camox login` before starting the dev server.\nAuthentication is required so your dev environment is scoped to your user.");
34
+ throw new Error(`Camox: not authenticated for ${key}. Run \`camox login\` before starting the dev server.\nAuthentication is required so your dev environment is scoped to your user.`);
25
35
  }
26
- if (!auth.email) throw new Error("Camox: ~/.camox/auth.json is missing an email. Run `camox login` again.");
36
+ if (!auth?.email) throw new Error(`Camox: no session found for ${key} in ~/.camox/auth.json. Run \`camox login\` again.`);
27
37
  return `${auth.email.split("@")[0]}-dev`;
28
38
  }
29
39
  function camox(options) {
@@ -37,8 +47,10 @@ function camox(options) {
37
47
  name: "camox",
38
48
  resolveId(id) {
39
49
  if (id === VIRTUAL_STUDIO_CSS) return RESOLVED_VIRTUAL_STUDIO_CSS;
50
+ if (USE_SYNC_EXTERNAL_STORE_RE.test(id)) return RESOLVED_USE_SYNC_SHIM;
40
51
  },
41
52
  load(id) {
53
+ if (id === RESOLVED_USE_SYNC_SHIM) return USE_SYNC_SHIM_CODE;
42
54
  if (id !== RESOLVED_VIRTUAL_STUDIO_CSS) return;
43
55
  const cssPath = resolve(sdkRoot, "dist/studio.css");
44
56
  if (isBuild) {
@@ -53,17 +65,14 @@ function camox(options) {
53
65
  },
54
66
  config(_config, env) {
55
67
  isBuild = env.command === "build";
56
- environmentName = resolveEnvironmentName(env.command === "serve");
57
- return {
58
- optimizeDeps: { include: ["use-sync-external-store/shim"] },
59
- define: {
60
- __CAMOX_ANALYTICS_DISABLED__: JSON.stringify(!!options.disableAnalytics),
61
- __ENABLE_TANSTACK_DEVTOOLS__: JSON.stringify(enableTanstackDevtools),
62
- __CAMOX_ENVIRONMENT_NAME__: JSON.stringify(environmentName),
63
- __CAMOX_API_URL__: JSON.stringify(apiUrl),
64
- __CAMOX_PROJECT_SLUG__: JSON.stringify(options.projectSlug)
65
- }
66
- };
68
+ environmentName = resolveEnvironmentName(env.command === "serve", authenticationUrl);
69
+ return { define: {
70
+ __CAMOX_ANALYTICS_DISABLED__: JSON.stringify(!!options.disableAnalytics),
71
+ __ENABLE_TANSTACK_DEVTOOLS__: JSON.stringify(enableTanstackDevtools),
72
+ __CAMOX_ENVIRONMENT_NAME__: JSON.stringify(environmentName),
73
+ __CAMOX_API_URL__: JSON.stringify(apiUrl),
74
+ __CAMOX_PROJECT_SLUG__: JSON.stringify(options.projectSlug)
75
+ } };
67
76
  },
68
77
  configResolved(config) {
69
78
  resolvedConfig = config;
@@ -104,7 +113,6 @@ function camox(options) {
104
113
  },
105
114
  async closeBundle() {
106
115
  if (!isBuild) return;
107
- const { createServer } = await import("vite");
108
116
  const camoxAppPath = "./src/camox/app.ts";
109
117
  const tempServer = await createServer({
110
118
  configFile: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camox",
3
- "version": "0.5.2",
3
+ "version": "0.6.1",
4
4
  "bin": {
5
5
  "camox": "./bin/camox.mjs"
6
6
  },
@@ -98,9 +98,9 @@
98
98
  "react-dom": "^19.2.5",
99
99
  "react-og-preview": "^0.2.0",
100
100
  "shiki": "^4.0.2",
101
- "@camox/api": "0.5.2",
102
- "@camox/cli": "0.5.2",
103
- "@camox/ui": "0.5.2"
101
+ "@camox/api": "0.6.1",
102
+ "@camox/cli": "0.6.1",
103
+ "@camox/ui": "0.6.1"
104
104
  },
105
105
  "devDependencies": {
106
106
  "@babel/core": "^7.29.0",