zitejs 0.9.3 → 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.
- package/dist/cjs/caller/index.js +18 -8
- package/dist/cjs/dev/index.js +12 -1
- package/dist/cjs/runtime/index.js +14 -5
- package/dist/cjs/sync/lib.js +3 -2
- package/dist/esm/backend/index.d.ts +0 -1
- package/dist/esm/caller/index.d.ts +1 -2
- package/dist/esm/caller/index.js +18 -8
- package/dist/esm/cli.js +0 -0
- package/dist/esm/dev/index.js +13 -2
- package/dist/esm/runtime/index.js +14 -5
- package/dist/esm/sync/lib.d.ts +1 -1
- package/dist/esm/sync/lib.js +3 -2
- package/package.json +1 -1
package/dist/cjs/caller/index.js
CHANGED
|
@@ -6,24 +6,34 @@ const ENVIRONMENTS = {
|
|
|
6
6
|
staging: 'https://workflows.zitestaging.com',
|
|
7
7
|
local: 'http://localhost:2506',
|
|
8
8
|
};
|
|
9
|
+
function getEnv(key, viteKey) {
|
|
10
|
+
if (typeof process !== 'undefined' && process.env?.[key])
|
|
11
|
+
return process.env[key];
|
|
12
|
+
try {
|
|
13
|
+
// @ts-ignore — import.meta.env is Vite-specific
|
|
14
|
+
if (viteKey && typeof import.meta !== 'undefined' && import.meta.env?.[viteKey])
|
|
15
|
+
return import.meta.env[viteKey];
|
|
16
|
+
}
|
|
17
|
+
catch { }
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
9
20
|
function getRunnerUrl() {
|
|
10
|
-
const env = (
|
|
11
|
-
return (
|
|
12
|
-
ENVIRONMENTS[env] ||
|
|
13
|
-
ENVIRONMENTS.production);
|
|
21
|
+
const env = getEnv('ZITE_ENV', 'VITE_ZITE_ENV') ?? 'production';
|
|
22
|
+
return getEnv('ZITE_RUNNER_URL', 'VITE_ZITE_RUNNER_URL') ?? ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
|
|
14
23
|
}
|
|
15
24
|
function getToken() {
|
|
16
|
-
return (
|
|
25
|
+
return getEnv('ZITE_DB_TOKEN', 'VITE_ZITE_DB_TOKEN') ?? '';
|
|
17
26
|
}
|
|
18
|
-
function createCaller(endpoint) {
|
|
27
|
+
function createCaller(endpoint, name, flowId) {
|
|
19
28
|
return async (input) => {
|
|
20
|
-
const
|
|
29
|
+
const appId = flowId ?? getEnv('ZITE_FLOW_ID', 'VITE_ZITE_FLOW_ID') ?? '';
|
|
30
|
+
const res = await fetch(getRunnerUrl() + '/public/' + appId + '/api/' + name, {
|
|
21
31
|
method: 'POST',
|
|
22
32
|
headers: {
|
|
23
33
|
Authorization: `Bearer ${getToken()}`,
|
|
24
34
|
'Content-Type': 'application/json',
|
|
25
35
|
},
|
|
26
|
-
body: JSON.stringify(input),
|
|
36
|
+
body: JSON.stringify({ ...input, mode: 'preview', usageToken: getToken() }),
|
|
27
37
|
});
|
|
28
38
|
if (!res.ok) {
|
|
29
39
|
const text = await res.text().catch(() => '');
|
package/dist/cjs/dev/index.js
CHANGED
|
@@ -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 });
|
|
@@ -8,14 +8,23 @@ const ENVIRONMENTS = {
|
|
|
8
8
|
staging: 'https://workflows.zitestaging.com',
|
|
9
9
|
local: 'http://localhost:2506',
|
|
10
10
|
};
|
|
11
|
+
function getEnv(key, viteKey) {
|
|
12
|
+
if (typeof process !== 'undefined' && process.env?.[key])
|
|
13
|
+
return process.env[key];
|
|
14
|
+
try {
|
|
15
|
+
// @ts-ignore — import.meta.env is Vite-specific
|
|
16
|
+
if (viteKey && typeof import.meta !== 'undefined' && import.meta.env?.[viteKey])
|
|
17
|
+
return import.meta.env[viteKey];
|
|
18
|
+
}
|
|
19
|
+
catch { }
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
11
22
|
function getRunnerUrl() {
|
|
12
|
-
const env = (
|
|
13
|
-
return (
|
|
14
|
-
ENVIRONMENTS[env] ||
|
|
15
|
-
ENVIRONMENTS.production);
|
|
23
|
+
const env = getEnv('ZITE_ENV', 'VITE_ZITE_ENV') ?? 'production';
|
|
24
|
+
return getEnv('ZITE_RUNNER_URL', 'VITE_ZITE_RUNNER_URL') ?? ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
|
|
16
25
|
}
|
|
17
26
|
function getToken() {
|
|
18
|
-
return (
|
|
27
|
+
return getEnv('ZITE_DB_TOKEN', 'VITE_ZITE_DB_TOKEN') ?? '';
|
|
19
28
|
}
|
|
20
29
|
async function wrapSdkCall(integrationId, className, methodName, params) {
|
|
21
30
|
const res = await fetch(`${getRunnerUrl()}/sdk/execute`, {
|
package/dist/cjs/sync/lib.js
CHANGED
|
@@ -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);`);
|
|
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
|
|
@@ -21,7 +21,6 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown> {
|
|
|
21
21
|
inputSchema?: SchemaLike<TInput>;
|
|
22
22
|
outputSchema?: SchemaLike<TOutput>;
|
|
23
23
|
stream?: boolean;
|
|
24
|
-
_name?: string;
|
|
25
24
|
execute: (params: {
|
|
26
25
|
input: TInput;
|
|
27
26
|
context: ZiteRequestContext | ZiteScheduledContext;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export interface EndpointConfig<TInput = unknown, TOutput = unknown> {
|
|
2
|
-
_name?: string;
|
|
3
2
|
execute: (params: {
|
|
4
3
|
input: TInput;
|
|
5
4
|
context: unknown;
|
|
6
5
|
}) => Promise<TOutput> | TOutput;
|
|
7
6
|
}
|
|
8
|
-
export declare function createCaller<TInput, TOutput>(endpoint: EndpointConfig<TInput, TOutput
|
|
7
|
+
export declare function createCaller<TInput, TOutput>(endpoint: EndpointConfig<TInput, TOutput>, name: string, flowId?: string): (input: TInput) => Promise<TOutput>;
|
package/dist/esm/caller/index.js
CHANGED
|
@@ -3,24 +3,34 @@ const ENVIRONMENTS = {
|
|
|
3
3
|
staging: 'https://workflows.zitestaging.com',
|
|
4
4
|
local: 'http://localhost:2506',
|
|
5
5
|
};
|
|
6
|
+
function getEnv(key, viteKey) {
|
|
7
|
+
if (typeof process !== 'undefined' && process.env?.[key])
|
|
8
|
+
return process.env[key];
|
|
9
|
+
try {
|
|
10
|
+
// @ts-ignore — import.meta.env is Vite-specific
|
|
11
|
+
if (viteKey && typeof import.meta !== 'undefined' && import.meta.env?.[viteKey])
|
|
12
|
+
return import.meta.env[viteKey];
|
|
13
|
+
}
|
|
14
|
+
catch { }
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
6
17
|
function getRunnerUrl() {
|
|
7
|
-
const env = (
|
|
8
|
-
return (
|
|
9
|
-
ENVIRONMENTS[env] ||
|
|
10
|
-
ENVIRONMENTS.production);
|
|
18
|
+
const env = getEnv('ZITE_ENV', 'VITE_ZITE_ENV') ?? 'production';
|
|
19
|
+
return getEnv('ZITE_RUNNER_URL', 'VITE_ZITE_RUNNER_URL') ?? ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
|
|
11
20
|
}
|
|
12
21
|
function getToken() {
|
|
13
|
-
return (
|
|
22
|
+
return getEnv('ZITE_DB_TOKEN', 'VITE_ZITE_DB_TOKEN') ?? '';
|
|
14
23
|
}
|
|
15
|
-
export function createCaller(endpoint) {
|
|
24
|
+
export function createCaller(endpoint, name, flowId) {
|
|
16
25
|
return async (input) => {
|
|
17
|
-
const
|
|
26
|
+
const appId = flowId ?? getEnv('ZITE_FLOW_ID', 'VITE_ZITE_FLOW_ID') ?? '';
|
|
27
|
+
const res = await fetch(getRunnerUrl() + '/public/' + appId + '/api/' + name, {
|
|
18
28
|
method: 'POST',
|
|
19
29
|
headers: {
|
|
20
30
|
Authorization: `Bearer ${getToken()}`,
|
|
21
31
|
'Content-Type': 'application/json',
|
|
22
32
|
},
|
|
23
|
-
body: JSON.stringify(input),
|
|
33
|
+
body: JSON.stringify({ ...input, mode: 'preview', usageToken: getToken() }),
|
|
24
34
|
});
|
|
25
35
|
if (!res.ok) {
|
|
26
36
|
const text = await res.text().catch(() => '');
|
package/dist/esm/cli.js
CHANGED
|
File without changes
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -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 });
|
|
@@ -3,14 +3,23 @@ const ENVIRONMENTS = {
|
|
|
3
3
|
staging: 'https://workflows.zitestaging.com',
|
|
4
4
|
local: 'http://localhost:2506',
|
|
5
5
|
};
|
|
6
|
+
function getEnv(key, viteKey) {
|
|
7
|
+
if (typeof process !== 'undefined' && process.env?.[key])
|
|
8
|
+
return process.env[key];
|
|
9
|
+
try {
|
|
10
|
+
// @ts-ignore — import.meta.env is Vite-specific
|
|
11
|
+
if (viteKey && typeof import.meta !== 'undefined' && import.meta.env?.[viteKey])
|
|
12
|
+
return import.meta.env[viteKey];
|
|
13
|
+
}
|
|
14
|
+
catch { }
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
6
17
|
function getRunnerUrl() {
|
|
7
|
-
const env = (
|
|
8
|
-
return (
|
|
9
|
-
ENVIRONMENTS[env] ||
|
|
10
|
-
ENVIRONMENTS.production);
|
|
18
|
+
const env = getEnv('ZITE_ENV', 'VITE_ZITE_ENV') ?? 'production';
|
|
19
|
+
return getEnv('ZITE_RUNNER_URL', 'VITE_ZITE_RUNNER_URL') ?? ENVIRONMENTS[env] ?? ENVIRONMENTS.production;
|
|
11
20
|
}
|
|
12
21
|
function getToken() {
|
|
13
|
-
return (
|
|
22
|
+
return getEnv('ZITE_DB_TOKEN', 'VITE_ZITE_DB_TOKEN') ?? '';
|
|
14
23
|
}
|
|
15
24
|
export async function wrapSdkCall(integrationId, className, methodName, params) {
|
|
16
25
|
const res = await fetch(`${getRunnerUrl()}/sdk/execute`, {
|
package/dist/esm/sync/lib.d.ts
CHANGED
|
@@ -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;
|
package/dist/esm/sync/lib.js
CHANGED
|
@@ -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);`);
|
|
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
|