zitejs 0.9.14 → 0.9.16

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.
@@ -11,19 +11,36 @@ function getRunnerUrl() {
11
11
  const env = (0, env_js_1.getEnv)('ZITE_ENV', 'VITE_ZITE_ENV') ?? 'production';
12
12
  return (0, env_js_1.getEnv)('ZITE_RUNNER_URL', 'VITE_ZITE_RUNNER_URL') ?? ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
13
13
  }
14
- function getToken() {
15
- return (0, env_js_1.getEnv)('ZITE_DB_TOKEN', 'VITE_ZITE_DB_TOKEN') ?? '';
14
+ /**
15
+ * Get the user's usage token for endpoint auth.
16
+ * In internal mode: injected by app-runtime as window._ziteUsageToken
17
+ * In external mode: stored in localStorage by the auth flow
18
+ */
19
+ function getUsageToken() {
20
+ if (typeof window !== 'undefined') {
21
+ const win = window;
22
+ if (typeof win._ziteUsageToken === 'string')
23
+ return win._ziteUsageToken;
24
+ }
25
+ // Fallback to stored auth token (external mode)
26
+ if (typeof localStorage !== 'undefined') {
27
+ const stored = localStorage.getItem('zite.auth.token');
28
+ if (stored)
29
+ return stored;
30
+ }
31
+ return '';
16
32
  }
17
33
  function createCaller(endpoint, name, flowId) {
18
34
  return async (input) => {
19
35
  const appId = flowId ?? (0, env_js_1.getEnv)('ZITE_FLOW_ID', 'VITE_ZITE_FLOW_ID') ?? '';
36
+ const token = getUsageToken();
20
37
  const res = await fetch(getRunnerUrl() + '/public/' + appId + '/api/' + name, {
21
38
  method: 'POST',
22
39
  headers: {
23
- Authorization: `Bearer ${getToken()}`,
40
+ ...(token ? { Authorization: `Bearer ${token}` } : {}),
24
41
  'Content-Type': 'application/json',
25
42
  },
26
- body: JSON.stringify({ ...input, mode: 'preview', usageToken: getToken() }),
43
+ body: JSON.stringify({ ...input, mode: 'preview', usageToken: token }),
27
44
  });
28
45
  if (!res.ok) {
29
46
  const text = await res.text().catch(() => '');
package/dist/cjs/cli.js CHANGED
@@ -50,6 +50,11 @@ async function main() {
50
50
  await runDev();
51
51
  break;
52
52
  }
53
+ case 'generate': {
54
+ const { runGenerate } = await Promise.resolve().then(() => __importStar(require('./dev/index.js')));
55
+ await runGenerate();
56
+ break;
57
+ }
53
58
  case 'check': {
54
59
  const { runCheck } = await Promise.resolve().then(() => __importStar(require('./check/index.js')));
55
60
  await runCheck();
@@ -63,11 +68,12 @@ async function main() {
63
68
  default:
64
69
  console.error(command
65
70
  ? `Unknown command: ${command}`
66
- : 'Usage: zitejs <sync|dev|check|bundle>');
71
+ : 'Usage: zitejs <sync|dev|generate|check|bundle>');
67
72
  console.error('');
68
73
  console.error('Commands:');
69
- console.error(' sync Generate .zite/db.ts and .zite/api.ts from your database schema');
70
- console.error(' dev Run sync then watch for changes (like npx convex dev)');
74
+ console.error(' sync Generate .zite/db.ts from database schema (single-app)');
75
+ console.error(' dev Run sync then watch for changes (like npx convex dev)');
76
+ console.error(' generate One-shot sync + regenerate all apps .zite/ files (monorepo)');
71
77
  console.error(' check Run tsc --noEmit and vite build for all apps');
72
78
  console.error(' bundle Bundle src/api/*.ts endpoints for cloudflare-lambda');
73
79
  process.exit(1);
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runGenerate = runGenerate;
3
4
  exports.runDev = runDev;
4
5
  const fs_1 = require("fs");
5
6
  const fs_2 = require("fs");
@@ -52,6 +53,22 @@ function regenerateAppApiTs(appDir) {
52
53
  console.log(`Updated apps/${appDir}/.zite/api.ts`);
53
54
  }
54
55
  }
56
+ async function runGenerate() {
57
+ // 1. Run sync (generates root .zite/db.ts)
58
+ try {
59
+ await (0, index_js_1.runSync)();
60
+ }
61
+ catch (err) {
62
+ console.warn('Sync failed (continuing with app generation):', err instanceof Error ? err.message : err);
63
+ }
64
+ // 2. Find all apps and regenerate their .zite/ files
65
+ const appDirs = findAppDirs();
66
+ for (const app of appDirs) {
67
+ regenerateAppApiTs(app);
68
+ regenerateAppTypedWrappers(app);
69
+ }
70
+ console.log('Done!');
71
+ }
55
72
  async function runDev() {
56
73
  const env = process.env.ZITE_ENV ?? 'production';
57
74
  console.log(`zitejs dev — environment: ${env}`);
@@ -8,19 +8,36 @@ function getRunnerUrl() {
8
8
  const env = getEnv('ZITE_ENV', 'VITE_ZITE_ENV') ?? 'production';
9
9
  return getEnv('ZITE_RUNNER_URL', 'VITE_ZITE_RUNNER_URL') ?? ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
10
10
  }
11
- function getToken() {
12
- return getEnv('ZITE_DB_TOKEN', 'VITE_ZITE_DB_TOKEN') ?? '';
11
+ /**
12
+ * Get the user's usage token for endpoint auth.
13
+ * In internal mode: injected by app-runtime as window._ziteUsageToken
14
+ * In external mode: stored in localStorage by the auth flow
15
+ */
16
+ function getUsageToken() {
17
+ if (typeof window !== 'undefined') {
18
+ const win = window;
19
+ if (typeof win._ziteUsageToken === 'string')
20
+ return win._ziteUsageToken;
21
+ }
22
+ // Fallback to stored auth token (external mode)
23
+ if (typeof localStorage !== 'undefined') {
24
+ const stored = localStorage.getItem('zite.auth.token');
25
+ if (stored)
26
+ return stored;
27
+ }
28
+ return '';
13
29
  }
14
30
  export function createCaller(endpoint, name, flowId) {
15
31
  return async (input) => {
16
32
  const appId = flowId ?? getEnv('ZITE_FLOW_ID', 'VITE_ZITE_FLOW_ID') ?? '';
33
+ const token = getUsageToken();
17
34
  const res = await fetch(getRunnerUrl() + '/public/' + appId + '/api/' + name, {
18
35
  method: 'POST',
19
36
  headers: {
20
- Authorization: `Bearer ${getToken()}`,
37
+ ...(token ? { Authorization: `Bearer ${token}` } : {}),
21
38
  'Content-Type': 'application/json',
22
39
  },
23
- body: JSON.stringify({ ...input, mode: 'preview', usageToken: getToken() }),
40
+ body: JSON.stringify({ ...input, mode: 'preview', usageToken: token }),
24
41
  });
25
42
  if (!res.ok) {
26
43
  const text = await res.text().catch(() => '');
package/dist/esm/cli.js CHANGED
@@ -15,6 +15,11 @@ async function main() {
15
15
  await runDev();
16
16
  break;
17
17
  }
18
+ case 'generate': {
19
+ const { runGenerate } = await import('./dev/index.js');
20
+ await runGenerate();
21
+ break;
22
+ }
18
23
  case 'check': {
19
24
  const { runCheck } = await import('./check/index.js');
20
25
  await runCheck();
@@ -28,11 +33,12 @@ async function main() {
28
33
  default:
29
34
  console.error(command
30
35
  ? `Unknown command: ${command}`
31
- : 'Usage: zitejs <sync|dev|check|bundle>');
36
+ : 'Usage: zitejs <sync|dev|generate|check|bundle>');
32
37
  console.error('');
33
38
  console.error('Commands:');
34
- console.error(' sync Generate .zite/db.ts and .zite/api.ts from your database schema');
35
- console.error(' dev Run sync then watch for changes (like npx convex dev)');
39
+ console.error(' sync Generate .zite/db.ts from database schema (single-app)');
40
+ console.error(' dev Run sync then watch for changes (like npx convex dev)');
41
+ console.error(' generate One-shot sync + regenerate all apps .zite/ files (monorepo)');
36
42
  console.error(' check Run tsc --noEmit and vite build for all apps');
37
43
  console.error(' bundle Bundle src/api/*.ts endpoints for cloudflare-lambda');
38
44
  process.exit(1);
@@ -1 +1,2 @@
1
+ export declare function runGenerate(): Promise<void>;
1
2
  export declare function runDev(): Promise<void>;
@@ -49,6 +49,22 @@ function regenerateAppApiTs(appDir) {
49
49
  console.log(`Updated apps/${appDir}/.zite/api.ts`);
50
50
  }
51
51
  }
52
+ export async function runGenerate() {
53
+ // 1. Run sync (generates root .zite/db.ts)
54
+ try {
55
+ await runSync();
56
+ }
57
+ catch (err) {
58
+ console.warn('Sync failed (continuing with app generation):', err instanceof Error ? err.message : err);
59
+ }
60
+ // 2. Find all apps and regenerate their .zite/ files
61
+ const appDirs = findAppDirs();
62
+ for (const app of appDirs) {
63
+ regenerateAppApiTs(app);
64
+ regenerateAppTypedWrappers(app);
65
+ }
66
+ console.log('Done!');
67
+ }
52
68
  export async function runDev() {
53
69
  const env = process.env.ZITE_ENV ?? 'production';
54
70
  console.log(`zitejs dev — environment: ${env}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.14",
3
+ "version": "0.9.16",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/runtime/index.js",