zitejs 0.9.4 → 0.9.5

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.
@@ -24,15 +24,16 @@ function getRunnerUrl() {
24
24
  function getToken() {
25
25
  return getEnv('ZITE_DB_TOKEN', 'VITE_ZITE_DB_TOKEN') ?? '';
26
26
  }
27
- function createCaller(endpoint, name) {
27
+ function createCaller(endpoint, name, flowId) {
28
28
  return async (input) => {
29
- const res = await fetch(getRunnerUrl() + '/api/' + name, {
29
+ const appId = flowId ?? getEnv('ZITE_FLOW_ID', 'VITE_ZITE_FLOW_ID') ?? '';
30
+ const res = await fetch(getRunnerUrl() + '/public/' + appId + '/api/' + name, {
30
31
  method: 'POST',
31
32
  headers: {
32
33
  Authorization: `Bearer ${getToken()}`,
33
34
  'Content-Type': 'application/json',
34
35
  },
35
- body: JSON.stringify(input),
36
+ body: JSON.stringify({ ...input, mode: 'preview', usageToken: getToken() }),
36
37
  });
37
38
  if (!res.ok) {
38
39
  const text = await res.text().catch(() => '');
@@ -21,12 +21,23 @@ function findAppDirs() {
21
21
  .filter(d => d.isDirectory())
22
22
  .map(d => d.name);
23
23
  }
24
+ function getFlowId(appDir) {
25
+ try {
26
+ const configPath = (0, path_1.join)('apps', appDir, 'zite.config.json');
27
+ if ((0, fs_2.existsSync)(configPath)) {
28
+ const config = JSON.parse((0, fs_2.readFileSync)(configPath, 'utf-8'));
29
+ return config.id;
30
+ }
31
+ }
32
+ catch { }
33
+ return undefined;
34
+ }
24
35
  function regenerateAppApiTs(appDir) {
25
36
  const apiDir = (0, path_1.join)('apps', appDir, 'src', 'api');
26
37
  if (!(0, fs_2.existsSync)(apiDir))
27
38
  return;
28
39
  const endpointFiles = (0, fs_2.readdirSync)(apiDir).filter((f) => f.endsWith('.ts') || f.endsWith('.js'));
29
- const content = (0, lib_js_1.generateApiTs)(endpointFiles);
40
+ const content = (0, lib_js_1.generateApiTs)(endpointFiles, getFlowId(appDir));
30
41
  if (content) {
31
42
  const outDir = (0, path_1.join)('apps', appDir, '.zite');
32
43
  (0, fs_2.mkdirSync)(outDir, { recursive: true });
@@ -119,7 +119,7 @@ function generateDbDts(base, schema) {
119
119
  lines.push('');
120
120
  return lines.join('\n');
121
121
  }
122
- function generateApiTs(endpointFiles) {
122
+ function generateApiTs(endpointFiles, flowId) {
123
123
  if (!endpointFiles || endpointFiles.length === 0)
124
124
  return null;
125
125
  const lines = [
@@ -135,10 +135,11 @@ function generateApiTs(endpointFiles) {
135
135
  lines.push(`import ${camelName}Endpoint from '../src/api/${name}';`);
136
136
  endpointNames.push(camelName);
137
137
  }
138
+ const flowIdArg = flowId ? `, '${flowId}'` : '';
138
139
  lines.push('');
139
140
  // Named exports for each endpoint (backwards compat with old zite-endpoints-sdk imports)
140
141
  for (const name of endpointNames) {
141
- lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}');`);
142
+ lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}'${flowIdArg});`);
142
143
  }
143
144
  lines.push('');
144
145
  // Also export as a single api object
@@ -4,4 +4,4 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown> {
4
4
  context: unknown;
5
5
  }) => Promise<TOutput> | TOutput;
6
6
  }
7
- export declare function createCaller<TInput, TOutput>(endpoint: EndpointConfig<TInput, TOutput>, name: string): (input: TInput) => Promise<TOutput>;
7
+ export declare function createCaller<TInput, TOutput>(endpoint: EndpointConfig<TInput, TOutput>, name: string, flowId?: string): (input: TInput) => Promise<TOutput>;
@@ -21,15 +21,16 @@ function getRunnerUrl() {
21
21
  function getToken() {
22
22
  return getEnv('ZITE_DB_TOKEN', 'VITE_ZITE_DB_TOKEN') ?? '';
23
23
  }
24
- export function createCaller(endpoint, name) {
24
+ export function createCaller(endpoint, name, flowId) {
25
25
  return async (input) => {
26
- const res = await fetch(getRunnerUrl() + '/api/' + name, {
26
+ const appId = flowId ?? getEnv('ZITE_FLOW_ID', 'VITE_ZITE_FLOW_ID') ?? '';
27
+ const res = await fetch(getRunnerUrl() + '/public/' + appId + '/api/' + name, {
27
28
  method: 'POST',
28
29
  headers: {
29
30
  Authorization: `Bearer ${getToken()}`,
30
31
  'Content-Type': 'application/json',
31
32
  },
32
- body: JSON.stringify(input),
33
+ body: JSON.stringify({ ...input, mode: 'preview', usageToken: getToken() }),
33
34
  });
34
35
  if (!res.ok) {
35
36
  const text = await res.text().catch(() => '');
@@ -1,5 +1,5 @@
1
1
  import { watch } from 'fs';
2
- import { existsSync, readdirSync, writeFileSync, mkdirSync, } from 'fs';
2
+ import { existsSync, readdirSync, readFileSync, writeFileSync, mkdirSync, } from 'fs';
3
3
  import { join } from 'path';
4
4
  import { runSync } from '../sync/index.js';
5
5
  import { generateApiTs } from '../sync/lib.js';
@@ -18,12 +18,23 @@ function findAppDirs() {
18
18
  .filter(d => d.isDirectory())
19
19
  .map(d => d.name);
20
20
  }
21
+ function getFlowId(appDir) {
22
+ try {
23
+ const configPath = join('apps', appDir, 'zite.config.json');
24
+ if (existsSync(configPath)) {
25
+ const config = JSON.parse(readFileSync(configPath, 'utf-8'));
26
+ return config.id;
27
+ }
28
+ }
29
+ catch { }
30
+ return undefined;
31
+ }
21
32
  function regenerateAppApiTs(appDir) {
22
33
  const apiDir = join('apps', appDir, 'src', 'api');
23
34
  if (!existsSync(apiDir))
24
35
  return;
25
36
  const endpointFiles = readdirSync(apiDir).filter((f) => f.endsWith('.ts') || f.endsWith('.js'));
26
- const content = generateApiTs(endpointFiles);
37
+ const content = generateApiTs(endpointFiles, getFlowId(appDir));
27
38
  if (content) {
28
39
  const outDir = join('apps', appDir, '.zite');
29
40
  mkdirSync(outDir, { recursive: true });
@@ -22,4 +22,4 @@ export declare function toCamelCase(name: string): string;
22
22
  export declare function generateSchema(base: BaseMetadata): ZiteSchema;
23
23
  export declare function generateDbTs(base: BaseMetadata, schema: ZiteSchema, integrationId?: string): string;
24
24
  export declare function generateDbDts(base: BaseMetadata, schema: ZiteSchema): string;
25
- export declare function generateApiTs(endpointFiles: string[]): string | null;
25
+ export declare function generateApiTs(endpointFiles: string[], flowId?: string): string | null;
@@ -111,7 +111,7 @@ export function generateDbDts(base, schema) {
111
111
  lines.push('');
112
112
  return lines.join('\n');
113
113
  }
114
- export function generateApiTs(endpointFiles) {
114
+ export function generateApiTs(endpointFiles, flowId) {
115
115
  if (!endpointFiles || endpointFiles.length === 0)
116
116
  return null;
117
117
  const lines = [
@@ -127,10 +127,11 @@ export function generateApiTs(endpointFiles) {
127
127
  lines.push(`import ${camelName}Endpoint from '../src/api/${name}';`);
128
128
  endpointNames.push(camelName);
129
129
  }
130
+ const flowIdArg = flowId ? `, '${flowId}'` : '';
130
131
  lines.push('');
131
132
  // Named exports for each endpoint (backwards compat with old zite-endpoints-sdk imports)
132
133
  for (const name of endpointNames) {
133
- lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}');`);
134
+ lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}'${flowIdArg});`);
134
135
  }
135
136
  lines.push('');
136
137
  // Also export as a single api object
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.4",
3
+ "version": "0.9.5",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/runtime/index.js",