zitejs 0.9.52 → 0.9.53
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.d.ts +1 -0
- package/dist/cjs/caller/index.js +25 -17
- package/dist/cjs/sync/lib.js +7 -7
- package/dist/esm/caller/index.d.ts +1 -0
- package/dist/esm/caller/index.js +26 -18
- package/dist/esm/sync/lib.js +7 -7
- package/package.json +1 -1
|
@@ -4,4 +4,5 @@ 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>(name: string, flowId?: string): (input: TInput) => Promise<TOutput>;
|
|
7
8
|
export declare function createCaller<TInput, TOutput>(endpoint: EndpointConfig<TInput, TOutput>, name: string, flowId?: string): (input: TInput) => Promise<TOutput>;
|
package/dist/cjs/caller/index.js
CHANGED
|
@@ -3,13 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createCaller = createCaller;
|
|
4
4
|
const env_js_1 = require("../internal/env.js");
|
|
5
5
|
const ENVIRONMENTS = {
|
|
6
|
-
production:
|
|
7
|
-
staging:
|
|
8
|
-
local:
|
|
6
|
+
production: "https://workflows.zite.com",
|
|
7
|
+
staging: "https://workflows.zitestaging.com",
|
|
8
|
+
local: "http://localhost:2506",
|
|
9
9
|
};
|
|
10
10
|
function getRunnerUrl() {
|
|
11
|
-
const env = (0, env_js_1.getEnv)(
|
|
12
|
-
return (0, env_js_1.getEnv)(
|
|
11
|
+
const env = (0, env_js_1.getEnv)("ZITE_ENV", "VITE_ZITE_ENV") ?? "production";
|
|
12
|
+
return ((0, env_js_1.getEnv)("ZITE_RUNNER_URL", "VITE_ZITE_RUNNER_URL") ??
|
|
13
|
+
ENVIRONMENTS[env] ??
|
|
14
|
+
ENVIRONMENTS.production);
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* Get the user's usage token for endpoint auth.
|
|
@@ -17,33 +19,39 @@ function getRunnerUrl() {
|
|
|
17
19
|
* In external mode: stored in localStorage by the auth flow
|
|
18
20
|
*/
|
|
19
21
|
function getUsageToken() {
|
|
20
|
-
if (typeof window !==
|
|
22
|
+
if (typeof window !== "undefined") {
|
|
21
23
|
const win = window;
|
|
22
|
-
if (typeof win._ziteUsageToken ===
|
|
24
|
+
if (typeof win._ziteUsageToken === "string")
|
|
23
25
|
return win._ziteUsageToken;
|
|
24
26
|
}
|
|
25
27
|
// Fallback to stored auth token (external mode)
|
|
26
|
-
if (typeof localStorage !==
|
|
27
|
-
const stored = localStorage.getItem(
|
|
28
|
+
if (typeof localStorage !== "undefined") {
|
|
29
|
+
const stored = localStorage.getItem("zite.auth.token");
|
|
28
30
|
if (stored)
|
|
29
31
|
return stored;
|
|
30
32
|
}
|
|
31
|
-
return
|
|
33
|
+
return "";
|
|
32
34
|
}
|
|
33
|
-
function createCaller(
|
|
35
|
+
function createCaller(endpointOrName, nameOrFlowId, flowId) {
|
|
36
|
+
const name = typeof endpointOrName === "string" ? endpointOrName : nameOrFlowId;
|
|
37
|
+
const resolvedFlowId = typeof endpointOrName === "string" ? nameOrFlowId : flowId;
|
|
34
38
|
return async (input) => {
|
|
35
|
-
const appId =
|
|
39
|
+
const appId = resolvedFlowId ?? (0, env_js_1.getEnv)("ZITE_FLOW_ID", "VITE_ZITE_FLOW_ID") ?? "";
|
|
36
40
|
const token = getUsageToken();
|
|
37
|
-
const res = await fetch(getRunnerUrl() +
|
|
38
|
-
method:
|
|
41
|
+
const res = await fetch(getRunnerUrl() + "/public/" + appId + "/api/" + name, {
|
|
42
|
+
method: "POST",
|
|
39
43
|
headers: {
|
|
40
44
|
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
41
|
-
|
|
45
|
+
"Content-Type": "application/json",
|
|
42
46
|
},
|
|
43
|
-
body: JSON.stringify({
|
|
47
|
+
body: JSON.stringify({
|
|
48
|
+
inputs: input,
|
|
49
|
+
mode: "preview",
|
|
50
|
+
usageToken: token,
|
|
51
|
+
}),
|
|
44
52
|
});
|
|
45
53
|
if (!res.ok) {
|
|
46
|
-
const text = await res.text().catch(() =>
|
|
54
|
+
const text = await res.text().catch(() => "");
|
|
47
55
|
throw new Error(`API call failed (${res.status}): ${text}`);
|
|
48
56
|
}
|
|
49
57
|
return res.json();
|
package/dist/cjs/sync/lib.js
CHANGED
|
@@ -282,18 +282,18 @@ function generateApiTs(endpointFiles) {
|
|
|
282
282
|
for (const file of endpointFiles) {
|
|
283
283
|
const name = file.replace(/\.(ts|js)$/, "");
|
|
284
284
|
const camelName = toCamelCase(name);
|
|
285
|
-
|
|
285
|
+
const pascal = toPascalCase(camelName);
|
|
286
|
+
lines.push(`import type { default as _${pascal}Ep } from '../src/api/${name}';`);
|
|
286
287
|
endpointNames.push(camelName);
|
|
287
288
|
}
|
|
288
289
|
lines.push("");
|
|
289
|
-
for (const name of endpointNames) {
|
|
290
|
-
lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}');`);
|
|
291
|
-
}
|
|
292
|
-
lines.push("");
|
|
293
290
|
for (const name of endpointNames) {
|
|
294
291
|
const pascal = toPascalCase(name);
|
|
295
|
-
lines.push(`
|
|
296
|
-
lines.push(`export type ${pascal}
|
|
292
|
+
lines.push(`type _${pascal}Cfg = typeof _${pascal}Ep;`);
|
|
293
|
+
lines.push(`export type ${pascal}InputType = Parameters<_${pascal}Cfg['execute']>[0]['input'];`);
|
|
294
|
+
lines.push(`export type ${pascal}OutputType = Awaited<ReturnType<_${pascal}Cfg['execute']>>;`);
|
|
295
|
+
lines.push(`export const ${name} = createCaller<${pascal}InputType, ${pascal}OutputType>('${name}');`);
|
|
296
|
+
lines.push("");
|
|
297
297
|
}
|
|
298
298
|
lines.push("");
|
|
299
299
|
lines.push("export const api = {");
|
|
@@ -4,4 +4,5 @@ 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>(name: string, flowId?: string): (input: TInput) => Promise<TOutput>;
|
|
7
8
|
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
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { getEnv } from
|
|
1
|
+
import { getEnv } from "../internal/env.js";
|
|
2
2
|
const ENVIRONMENTS = {
|
|
3
|
-
production:
|
|
4
|
-
staging:
|
|
5
|
-
local:
|
|
3
|
+
production: "https://workflows.zite.com",
|
|
4
|
+
staging: "https://workflows.zitestaging.com",
|
|
5
|
+
local: "http://localhost:2506",
|
|
6
6
|
};
|
|
7
7
|
function getRunnerUrl() {
|
|
8
|
-
const env = getEnv(
|
|
9
|
-
return getEnv(
|
|
8
|
+
const env = getEnv("ZITE_ENV", "VITE_ZITE_ENV") ?? "production";
|
|
9
|
+
return (getEnv("ZITE_RUNNER_URL", "VITE_ZITE_RUNNER_URL") ??
|
|
10
|
+
ENVIRONMENTS[env] ??
|
|
11
|
+
ENVIRONMENTS.production);
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
14
|
* Get the user's usage token for endpoint auth.
|
|
@@ -14,33 +16,39 @@ function getRunnerUrl() {
|
|
|
14
16
|
* In external mode: stored in localStorage by the auth flow
|
|
15
17
|
*/
|
|
16
18
|
function getUsageToken() {
|
|
17
|
-
if (typeof window !==
|
|
19
|
+
if (typeof window !== "undefined") {
|
|
18
20
|
const win = window;
|
|
19
|
-
if (typeof win._ziteUsageToken ===
|
|
21
|
+
if (typeof win._ziteUsageToken === "string")
|
|
20
22
|
return win._ziteUsageToken;
|
|
21
23
|
}
|
|
22
24
|
// Fallback to stored auth token (external mode)
|
|
23
|
-
if (typeof localStorage !==
|
|
24
|
-
const stored = localStorage.getItem(
|
|
25
|
+
if (typeof localStorage !== "undefined") {
|
|
26
|
+
const stored = localStorage.getItem("zite.auth.token");
|
|
25
27
|
if (stored)
|
|
26
28
|
return stored;
|
|
27
29
|
}
|
|
28
|
-
return
|
|
30
|
+
return "";
|
|
29
31
|
}
|
|
30
|
-
export function createCaller(
|
|
32
|
+
export function createCaller(endpointOrName, nameOrFlowId, flowId) {
|
|
33
|
+
const name = typeof endpointOrName === "string" ? endpointOrName : nameOrFlowId;
|
|
34
|
+
const resolvedFlowId = typeof endpointOrName === "string" ? nameOrFlowId : flowId;
|
|
31
35
|
return async (input) => {
|
|
32
|
-
const appId =
|
|
36
|
+
const appId = resolvedFlowId ?? getEnv("ZITE_FLOW_ID", "VITE_ZITE_FLOW_ID") ?? "";
|
|
33
37
|
const token = getUsageToken();
|
|
34
|
-
const res = await fetch(getRunnerUrl() +
|
|
35
|
-
method:
|
|
38
|
+
const res = await fetch(getRunnerUrl() + "/public/" + appId + "/api/" + name, {
|
|
39
|
+
method: "POST",
|
|
36
40
|
headers: {
|
|
37
41
|
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
38
|
-
|
|
42
|
+
"Content-Type": "application/json",
|
|
39
43
|
},
|
|
40
|
-
body: JSON.stringify({
|
|
44
|
+
body: JSON.stringify({
|
|
45
|
+
inputs: input,
|
|
46
|
+
mode: "preview",
|
|
47
|
+
usageToken: token,
|
|
48
|
+
}),
|
|
41
49
|
});
|
|
42
50
|
if (!res.ok) {
|
|
43
|
-
const text = await res.text().catch(() =>
|
|
51
|
+
const text = await res.text().catch(() => "");
|
|
44
52
|
throw new Error(`API call failed (${res.status}): ${text}`);
|
|
45
53
|
}
|
|
46
54
|
return res.json();
|
package/dist/esm/sync/lib.js
CHANGED
|
@@ -271,18 +271,18 @@ export function generateApiTs(endpointFiles) {
|
|
|
271
271
|
for (const file of endpointFiles) {
|
|
272
272
|
const name = file.replace(/\.(ts|js)$/, "");
|
|
273
273
|
const camelName = toCamelCase(name);
|
|
274
|
-
|
|
274
|
+
const pascal = toPascalCase(camelName);
|
|
275
|
+
lines.push(`import type { default as _${pascal}Ep } from '../src/api/${name}';`);
|
|
275
276
|
endpointNames.push(camelName);
|
|
276
277
|
}
|
|
277
278
|
lines.push("");
|
|
278
|
-
for (const name of endpointNames) {
|
|
279
|
-
lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}');`);
|
|
280
|
-
}
|
|
281
|
-
lines.push("");
|
|
282
279
|
for (const name of endpointNames) {
|
|
283
280
|
const pascal = toPascalCase(name);
|
|
284
|
-
lines.push(`
|
|
285
|
-
lines.push(`export type ${pascal}
|
|
281
|
+
lines.push(`type _${pascal}Cfg = typeof _${pascal}Ep;`);
|
|
282
|
+
lines.push(`export type ${pascal}InputType = Parameters<_${pascal}Cfg['execute']>[0]['input'];`);
|
|
283
|
+
lines.push(`export type ${pascal}OutputType = Awaited<ReturnType<_${pascal}Cfg['execute']>>;`);
|
|
284
|
+
lines.push(`export const ${name} = createCaller<${pascal}InputType, ${pascal}OutputType>('${name}');`);
|
|
285
|
+
lines.push("");
|
|
286
286
|
}
|
|
287
287
|
lines.push("");
|
|
288
288
|
lines.push("export const api = {");
|