zitejs 0.9.53 → 0.9.55
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/backend/index.d.ts +10 -4
- package/dist/cjs/backend/index.js +1 -1
- package/dist/cjs/caller/index.d.ts +5 -0
- package/dist/cjs/caller/index.js +100 -8
- package/dist/cjs/dev/index.js +6 -1
- package/dist/cjs/internal/sdkCall.d.ts +2 -0
- package/dist/cjs/internal/sdkCall.js +10 -0
- package/dist/cjs/pdf/index.d.ts +10 -7
- package/dist/cjs/pdf/index.js +6 -3
- package/dist/cjs/runtime/index.js +14 -20
- package/dist/cjs/schedules/index.d.ts +101 -11
- package/dist/cjs/schedules/index.js +15 -9
- package/dist/cjs/sync/index.js +7 -4
- package/dist/cjs/sync/lib.d.ts +5 -1
- package/dist/cjs/sync/lib.js +58 -13
- package/dist/cjs/upload/index.d.ts +11 -1
- package/dist/cjs/upload/index.js +107 -1
- package/dist/esm/backend/index.d.ts +10 -4
- package/dist/esm/backend/index.js +1 -1
- package/dist/esm/caller/index.d.ts +5 -0
- package/dist/esm/caller/index.js +99 -8
- package/dist/esm/cli.js +0 -0
- package/dist/esm/dev/index.js +6 -1
- package/dist/esm/internal/sdkCall.d.ts +2 -0
- package/dist/esm/internal/sdkCall.js +7 -0
- package/dist/esm/pdf/index.d.ts +10 -7
- package/dist/esm/pdf/index.js +5 -2
- package/dist/esm/runtime/index.js +1 -7
- package/dist/esm/schedules/index.d.ts +101 -11
- package/dist/esm/schedules/index.js +13 -7
- package/dist/esm/sync/index.js +7 -4
- package/dist/esm/sync/lib.d.ts +5 -1
- package/dist/esm/sync/lib.js +58 -13
- package/dist/esm/upload/index.d.ts +11 -1
- package/dist/esm/upload/index.js +104 -1
- package/package.json +1 -1
- package/dist/cjs/api/index.js +0 -5
- package/dist/cjs/db/index.js +0 -5
- package/dist/esm/api/index.d.ts +0 -2
- package/dist/esm/api/index.js +0 -1
- package/dist/esm/db/index.d.ts +0 -2
- package/dist/esm/db/index.js +0 -1
|
@@ -21,16 +21,22 @@ type SchemaLike<T> = {
|
|
|
21
21
|
_output: T;
|
|
22
22
|
parse: (data: unknown) => T;
|
|
23
23
|
};
|
|
24
|
-
export
|
|
24
|
+
export type ZiteStreamInterface = {
|
|
25
|
+
write: (data: unknown) => Promise<void>;
|
|
26
|
+
forward: (asyncIterable: AsyncIterable<string>) => Promise<string>;
|
|
27
|
+
};
|
|
28
|
+
export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream extends boolean = false> {
|
|
25
29
|
description?: string;
|
|
26
30
|
inputSchema?: SchemaLike<TInput>;
|
|
27
31
|
outputSchema?: SchemaLike<TOutput>;
|
|
28
|
-
stream?:
|
|
32
|
+
stream?: TStream;
|
|
29
33
|
authenticated?: boolean;
|
|
30
34
|
execute: (params: {
|
|
31
35
|
input: TInput;
|
|
32
36
|
context: ZiteRequestContext | ZiteScheduledContext;
|
|
33
|
-
}
|
|
37
|
+
} & (TStream extends true ? {
|
|
38
|
+
stream: ZiteStreamInterface;
|
|
39
|
+
} : {})) => Promise<TOutput> | TOutput;
|
|
34
40
|
}
|
|
35
|
-
export declare function createEndpoint<TInput = unknown, TOutput = unknown>(config: EndpointConfig<TInput, TOutput>): EndpointConfig<TInput, TOutput>;
|
|
41
|
+
export declare function createEndpoint<TInput = unknown, TOutput = unknown, TStream extends boolean = false>(config: EndpointConfig<TInput, TOutput, TStream>): EndpointConfig<TInput, TOutput, TStream>;
|
|
36
42
|
export {};
|
|
@@ -6,3 +6,8 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown> {
|
|
|
6
6
|
}
|
|
7
7
|
export declare function createCaller<TInput, TOutput>(name: string, flowId?: string): (input: TInput) => Promise<TOutput>;
|
|
8
8
|
export declare function createCaller<TInput, TOutput>(endpoint: EndpointConfig<TInput, TOutput>, name: string, flowId?: string): (input: TInput) => Promise<TOutput>;
|
|
9
|
+
export type StreamingResponse<T> = {
|
|
10
|
+
[Symbol.asyncIterator](): AsyncIterator<string>;
|
|
11
|
+
result: Promise<T>;
|
|
12
|
+
};
|
|
13
|
+
export declare function createStreamingCaller<TInput, TOutput>(name: string): (input: TInput) => StreamingResponse<TOutput>;
|
package/dist/cjs/caller/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createCaller = createCaller;
|
|
4
|
+
exports.createStreamingCaller = createStreamingCaller;
|
|
4
5
|
const env_js_1 = require("../internal/env.js");
|
|
5
6
|
const ENVIRONMENTS = {
|
|
6
7
|
production: "https://workflows.zite.com",
|
|
@@ -32,13 +33,15 @@ function getUsageToken() {
|
|
|
32
33
|
}
|
|
33
34
|
return "";
|
|
34
35
|
}
|
|
35
|
-
function
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
function buildFetchOptions(name, input, extra) {
|
|
37
|
+
const appId = (0, env_js_1.getEnv)("ZITE_FLOW_ID", "VITE_ZITE_FLOW_ID") ?? "";
|
|
38
|
+
const token = getUsageToken();
|
|
39
|
+
const ziteAuthToken = typeof localStorage !== "undefined"
|
|
40
|
+
? localStorage.getItem("zite.auth.token")
|
|
41
|
+
: null;
|
|
42
|
+
return {
|
|
43
|
+
url: getRunnerUrl() + "/public/" + appId + "/api/" + name,
|
|
44
|
+
init: {
|
|
42
45
|
method: "POST",
|
|
43
46
|
headers: {
|
|
44
47
|
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
@@ -48,8 +51,17 @@ function createCaller(endpointOrName, nameOrFlowId, flowId) {
|
|
|
48
51
|
inputs: input,
|
|
49
52
|
mode: "preview",
|
|
50
53
|
usageToken: token,
|
|
54
|
+
...(ziteAuthToken ? { ziteAuthToken } : {}),
|
|
55
|
+
...extra,
|
|
51
56
|
}),
|
|
52
|
-
}
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function createCaller(endpointOrName, nameOrFlowId, flowId) {
|
|
61
|
+
const name = typeof endpointOrName === "string" ? endpointOrName : nameOrFlowId;
|
|
62
|
+
return async (input) => {
|
|
63
|
+
const { url, init } = buildFetchOptions(name, input);
|
|
64
|
+
const res = await fetch(url, init);
|
|
53
65
|
if (!res.ok) {
|
|
54
66
|
const text = await res.text().catch(() => "");
|
|
55
67
|
throw new Error(`API call failed (${res.status}): ${text}`);
|
|
@@ -57,3 +69,83 @@ function createCaller(endpointOrName, nameOrFlowId, flowId) {
|
|
|
57
69
|
return res.json();
|
|
58
70
|
};
|
|
59
71
|
}
|
|
72
|
+
function createStreamingCaller(name) {
|
|
73
|
+
return (input) => {
|
|
74
|
+
let resultResolve;
|
|
75
|
+
let resultReject;
|
|
76
|
+
const resultPromise = new Promise((resolve, reject) => {
|
|
77
|
+
resultResolve = resolve;
|
|
78
|
+
resultReject = reject;
|
|
79
|
+
});
|
|
80
|
+
const { url, init } = buildFetchOptions(name, input, { stream: true });
|
|
81
|
+
const fetchPromise = fetch(url, init);
|
|
82
|
+
return {
|
|
83
|
+
async *[Symbol.asyncIterator]() {
|
|
84
|
+
try {
|
|
85
|
+
const response = await fetchPromise;
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
const errorData = await response.json().catch(() => ({}));
|
|
88
|
+
const error = new Error(errorData.message ||
|
|
89
|
+
`Error with endpoint ${name}: ${response.status}`);
|
|
90
|
+
resultReject(error);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
if (!response.body) {
|
|
94
|
+
const error = new Error("No response body for streaming endpoint");
|
|
95
|
+
resultReject(error);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
const reader = response.body
|
|
99
|
+
.pipeThrough(new TextDecoderStream())
|
|
100
|
+
.getReader();
|
|
101
|
+
let buffer = "";
|
|
102
|
+
while (true) {
|
|
103
|
+
const { value, done } = await reader.read();
|
|
104
|
+
if (done)
|
|
105
|
+
break;
|
|
106
|
+
buffer += value;
|
|
107
|
+
while (buffer.includes("\n\n")) {
|
|
108
|
+
const eventEnd = buffer.indexOf("\n\n");
|
|
109
|
+
const eventBlock = buffer.substring(0, eventEnd);
|
|
110
|
+
buffer = buffer.substring(eventEnd + 2);
|
|
111
|
+
const eventTypeMatch = eventBlock.match(/^event: (.+)$/m);
|
|
112
|
+
const dataMatch = eventBlock.match(/^data: (.+)$/m);
|
|
113
|
+
const eventType = eventTypeMatch?.[1];
|
|
114
|
+
const dataStr = dataMatch?.[1];
|
|
115
|
+
if (eventType === "data" && dataStr) {
|
|
116
|
+
try {
|
|
117
|
+
yield JSON.parse(dataStr);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
yield dataStr;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else if (eventType === "result" && dataStr) {
|
|
124
|
+
try {
|
|
125
|
+
resultResolve(JSON.parse(dataStr));
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
resultResolve(dataStr);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else if (eventType === "error" && dataStr) {
|
|
132
|
+
try {
|
|
133
|
+
const errorData = JSON.parse(dataStr);
|
|
134
|
+
resultReject(new Error(errorData.message || "Streaming error"));
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
resultReject(new Error(dataStr || "Streaming error"));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
resultReject(error);
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
result: resultPromise,
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
}
|
package/dist/cjs/dev/index.js
CHANGED
|
@@ -44,7 +44,12 @@ function regenerateAppApiTs(appDir) {
|
|
|
44
44
|
const apiDir = (0, path_1.join)("apps", appDir, "src", "api");
|
|
45
45
|
if (!(0, fs_2.existsSync)(apiDir))
|
|
46
46
|
return;
|
|
47
|
-
const endpointFiles = (0, fs_2.readdirSync)(apiDir)
|
|
47
|
+
const endpointFiles = (0, fs_2.readdirSync)(apiDir)
|
|
48
|
+
.filter((f) => f.endsWith(".ts") || f.endsWith(".js"))
|
|
49
|
+
.map((f) => ({
|
|
50
|
+
fileName: f,
|
|
51
|
+
content: (0, fs_2.readFileSync)((0, path_1.join)(apiDir, f), "utf-8"),
|
|
52
|
+
}));
|
|
48
53
|
const content = (0, lib_js_1.generateApiTs)(endpointFiles);
|
|
49
54
|
if (content) {
|
|
50
55
|
const outDir = (0, path_1.join)("apps", appDir, ".zite");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSdkCall = getSdkCall;
|
|
4
|
+
function getSdkCall() {
|
|
5
|
+
const fn = globalThis.__wrapSdkCall;
|
|
6
|
+
if (!fn) {
|
|
7
|
+
throw new Error('Zite SDK runtime not initialized. Endpoints must run inside the Zite worker.');
|
|
8
|
+
}
|
|
9
|
+
return fn;
|
|
10
|
+
}
|
package/dist/cjs/pdf/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
export interface RenderHtmlParams {
|
|
2
|
+
html: string;
|
|
3
|
+
filename?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface RenderHtmlResult {
|
|
6
|
+
url: string;
|
|
7
|
+
filename: string;
|
|
8
|
+
}
|
|
1
9
|
export declare class ZitePdf {
|
|
2
|
-
|
|
3
|
-
html: string;
|
|
4
|
-
[key: string]: unknown;
|
|
5
|
-
}): Promise<{
|
|
6
|
-
url: string;
|
|
7
|
-
[key: string]: unknown;
|
|
8
|
-
}>;
|
|
10
|
+
static renderHtml(params: RenderHtmlParams): Promise<RenderHtmlResult>;
|
|
9
11
|
}
|
|
12
|
+
export declare const Pdf: typeof ZitePdf;
|
package/dist/cjs/pdf/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ZitePdf = void 0;
|
|
3
|
+
exports.Pdf = exports.ZitePdf = void 0;
|
|
4
|
+
const sdkCall_js_1 = require("../internal/sdkCall.js");
|
|
5
|
+
const PDF_LIB_INTEGRATION_ID = '__pdf__';
|
|
4
6
|
class ZitePdf {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
static renderHtml(params) {
|
|
8
|
+
return (0, sdkCall_js_1.getSdkCall)()(PDF_LIB_INTEGRATION_ID, 'ZitePdf', 'renderHtml', params);
|
|
7
9
|
}
|
|
8
10
|
}
|
|
9
11
|
exports.ZitePdf = ZitePdf;
|
|
12
|
+
exports.Pdf = ZitePdf;
|
|
@@ -4,13 +4,7 @@ exports.createCaller = void 0;
|
|
|
4
4
|
exports.createTableClient = createTableClient;
|
|
5
5
|
exports.createSqlClient = createSqlClient;
|
|
6
6
|
exports.createAirtableClient = createAirtableClient;
|
|
7
|
-
|
|
8
|
-
const fn = globalThis.__wrapSdkCall;
|
|
9
|
-
if (!fn) {
|
|
10
|
-
throw new Error("Zite SDK runtime not initialized. Endpoints must run inside the Zite worker.");
|
|
11
|
-
}
|
|
12
|
-
return fn;
|
|
13
|
-
}
|
|
7
|
+
const sdkCall_js_1 = require("../internal/sdkCall.js");
|
|
14
8
|
const DB_INTEGRATION_ID = "databases";
|
|
15
9
|
function getBaseId() {
|
|
16
10
|
try {
|
|
@@ -38,33 +32,33 @@ function resolveTableId(className) {
|
|
|
38
32
|
}
|
|
39
33
|
function createTableClient(className) {
|
|
40
34
|
return {
|
|
41
|
-
findAll: (options) => getSdkCall()(DB_INTEGRATION_ID, className, "findAll", {
|
|
35
|
+
findAll: (options) => (0, sdkCall_js_1.getSdkCall)()(DB_INTEGRATION_ID, className, "findAll", {
|
|
42
36
|
baseId: getBaseId(),
|
|
43
37
|
tableId: resolveTableId(className),
|
|
44
38
|
...options,
|
|
45
39
|
}),
|
|
46
|
-
findOne: (recordId) => getSdkCall()(DB_INTEGRATION_ID, className, "findOne", {
|
|
40
|
+
findOne: (recordId) => (0, sdkCall_js_1.getSdkCall)()(DB_INTEGRATION_ID, className, "findOne", {
|
|
47
41
|
baseId: getBaseId(),
|
|
48
42
|
tableId: resolveTableId(className),
|
|
49
43
|
...(typeof recordId === "string" ? { id: recordId } : recordId),
|
|
50
44
|
}),
|
|
51
|
-
create: (data) => getSdkCall()(DB_INTEGRATION_ID, className, "create", {
|
|
45
|
+
create: (data) => (0, sdkCall_js_1.getSdkCall)()(DB_INTEGRATION_ID, className, "create", {
|
|
52
46
|
baseId: getBaseId(),
|
|
53
47
|
tableId: resolveTableId(className),
|
|
54
48
|
...data,
|
|
55
49
|
}),
|
|
56
|
-
update: (id, data) => getSdkCall()(DB_INTEGRATION_ID, className, "update", {
|
|
50
|
+
update: (id, data) => (0, sdkCall_js_1.getSdkCall)()(DB_INTEGRATION_ID, className, "update", {
|
|
57
51
|
baseId: getBaseId(),
|
|
58
52
|
tableId: resolveTableId(className),
|
|
59
53
|
id,
|
|
60
54
|
...data,
|
|
61
55
|
}),
|
|
62
|
-
delete: (id) => getSdkCall()(DB_INTEGRATION_ID, className, "delete", {
|
|
56
|
+
delete: (id) => (0, sdkCall_js_1.getSdkCall)()(DB_INTEGRATION_ID, className, "delete", {
|
|
63
57
|
baseId: getBaseId(),
|
|
64
58
|
tableId: resolveTableId(className),
|
|
65
59
|
id,
|
|
66
60
|
}),
|
|
67
|
-
bulkCreate: (records) => getSdkCall()(DB_INTEGRATION_ID, className, "bulkCreate", {
|
|
61
|
+
bulkCreate: (records) => (0, sdkCall_js_1.getSdkCall)()(DB_INTEGRATION_ID, className, "bulkCreate", {
|
|
68
62
|
baseId: getBaseId(),
|
|
69
63
|
tableId: resolveTableId(className),
|
|
70
64
|
records,
|
|
@@ -72,35 +66,35 @@ function createTableClient(className) {
|
|
|
72
66
|
};
|
|
73
67
|
}
|
|
74
68
|
function createSqlClient() {
|
|
75
|
-
return (params) => getSdkCall()(DB_INTEGRATION_ID, "Db", "executeSql", {
|
|
69
|
+
return (params) => (0, sdkCall_js_1.getSdkCall)()(DB_INTEGRATION_ID, "Db", "executeSql", {
|
|
76
70
|
baseId: getBaseId(),
|
|
77
71
|
...params,
|
|
78
72
|
});
|
|
79
73
|
}
|
|
80
74
|
function createAirtableClient(integrationId, className, implicitParams) {
|
|
81
75
|
return {
|
|
82
|
-
findAll: (options) => getSdkCall()(integrationId, className, "findAll", {
|
|
76
|
+
findAll: (options) => (0, sdkCall_js_1.getSdkCall)()(integrationId, className, "findAll", {
|
|
83
77
|
...implicitParams,
|
|
84
78
|
...options,
|
|
85
79
|
}),
|
|
86
|
-
findOne: (params) => getSdkCall()(integrationId, className, "findOne", {
|
|
80
|
+
findOne: (params) => (0, sdkCall_js_1.getSdkCall)()(integrationId, className, "findOne", {
|
|
87
81
|
...implicitParams,
|
|
88
82
|
...params,
|
|
89
83
|
}),
|
|
90
|
-
create: (data) => getSdkCall()(integrationId, className, "create", {
|
|
84
|
+
create: (data) => (0, sdkCall_js_1.getSdkCall)()(integrationId, className, "create", {
|
|
91
85
|
...implicitParams,
|
|
92
86
|
...data,
|
|
93
87
|
}),
|
|
94
|
-
bulkCreate: (records) => getSdkCall()(integrationId, className, "bulkCreate", {
|
|
88
|
+
bulkCreate: (records) => (0, sdkCall_js_1.getSdkCall)()(integrationId, className, "bulkCreate", {
|
|
95
89
|
...implicitParams,
|
|
96
90
|
records,
|
|
97
91
|
}),
|
|
98
|
-
update: (id, data) => getSdkCall()(integrationId, className, "update", {
|
|
92
|
+
update: (id, data) => (0, sdkCall_js_1.getSdkCall)()(integrationId, className, "update", {
|
|
99
93
|
...implicitParams,
|
|
100
94
|
id,
|
|
101
95
|
...data,
|
|
102
96
|
}),
|
|
103
|
-
delete: (id) => getSdkCall()(integrationId, className, "delete", {
|
|
97
|
+
delete: (id) => (0, sdkCall_js_1.getSdkCall)()(integrationId, className, "delete", {
|
|
104
98
|
...implicitParams,
|
|
105
99
|
id,
|
|
106
100
|
}),
|
|
@@ -1,16 +1,106 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
type DayOfWeek = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat';
|
|
2
|
+
type ActiveWindow = {
|
|
3
|
+
hoursRange?: {
|
|
4
|
+
from: string;
|
|
5
|
+
to: string;
|
|
6
|
+
};
|
|
7
|
+
daysOfWeek?: DayOfWeek[];
|
|
8
|
+
};
|
|
9
|
+
export type ZiteSchedule = {
|
|
10
|
+
scheduleType: 'recurring';
|
|
11
|
+
schedule: {
|
|
12
|
+
frequency: 'minutely';
|
|
13
|
+
interval: number;
|
|
14
|
+
activeWindow?: ActiveWindow;
|
|
15
|
+
} | {
|
|
16
|
+
frequency: 'hourly';
|
|
17
|
+
interval: number;
|
|
18
|
+
minute?: number;
|
|
19
|
+
activeWindow?: ActiveWindow;
|
|
20
|
+
} | {
|
|
21
|
+
frequency: 'daily';
|
|
22
|
+
interval: number;
|
|
23
|
+
times: string[];
|
|
24
|
+
} | {
|
|
25
|
+
frequency: 'weekly';
|
|
26
|
+
interval: number;
|
|
27
|
+
daysOfWeek: DayOfWeek[];
|
|
28
|
+
times: string[];
|
|
29
|
+
} | {
|
|
30
|
+
frequency: 'monthly';
|
|
31
|
+
interval: 1;
|
|
32
|
+
monthlyDay: {
|
|
33
|
+
type: 'dayOfMonth';
|
|
34
|
+
day: number | 'last';
|
|
35
|
+
} | {
|
|
36
|
+
type: 'weekdayOccurrence';
|
|
37
|
+
weekday: DayOfWeek;
|
|
38
|
+
occurrence: 1 | 2 | 3 | 4 | 'last';
|
|
39
|
+
};
|
|
40
|
+
times: string[];
|
|
41
|
+
};
|
|
42
|
+
endPolicy?: {
|
|
43
|
+
type: 'never';
|
|
44
|
+
} | {
|
|
45
|
+
type: 'onDate';
|
|
46
|
+
endAt: string;
|
|
47
|
+
} | {
|
|
48
|
+
type: 'afterOccurrences';
|
|
49
|
+
occurrences: number;
|
|
50
|
+
};
|
|
51
|
+
overlapPolicy?: 'skip' | 'allow';
|
|
52
|
+
timezone: string;
|
|
53
|
+
paused?: boolean;
|
|
54
|
+
} | {
|
|
55
|
+
scheduleType: 'oneTime';
|
|
56
|
+
fireAt: string;
|
|
57
|
+
timezone: string;
|
|
58
|
+
paused?: boolean;
|
|
59
|
+
};
|
|
60
|
+
export type Schedule = ZiteSchedule;
|
|
61
|
+
export type RuntimeScheduleInfo = {
|
|
62
|
+
id: string;
|
|
63
|
+
cronJobId: string;
|
|
64
|
+
endpointId: string;
|
|
65
|
+
schedule: ZiteSchedule | null;
|
|
66
|
+
inputs?: Record<string, unknown>;
|
|
67
|
+
paused: boolean;
|
|
68
|
+
nextActionTimes: string[];
|
|
69
|
+
recentActions: {
|
|
70
|
+
scheduledAt: string;
|
|
71
|
+
takenAt: string;
|
|
72
|
+
workflowId: string;
|
|
73
|
+
firstExecutionRunId: string;
|
|
74
|
+
}[];
|
|
75
|
+
};
|
|
76
|
+
export declare class ZiteSchedules {
|
|
77
|
+
static add(args: {
|
|
78
|
+
endpointId: string;
|
|
79
|
+
schedule: ZiteSchedule;
|
|
80
|
+
inputs?: Record<string, unknown>;
|
|
7
81
|
}): Promise<{
|
|
8
82
|
id: string;
|
|
83
|
+
cronJobId: string;
|
|
9
84
|
}>;
|
|
10
|
-
static
|
|
11
|
-
|
|
85
|
+
static list(args?: {
|
|
86
|
+
endpointId?: string;
|
|
87
|
+
}): Promise<{
|
|
88
|
+
schedules: RuntimeScheduleInfo[];
|
|
89
|
+
}>;
|
|
90
|
+
static remove(args: {
|
|
12
91
|
id: string;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
92
|
+
}): Promise<{
|
|
93
|
+
id: string;
|
|
94
|
+
deleted: true;
|
|
95
|
+
}>;
|
|
96
|
+
static update(args: {
|
|
97
|
+
id: string;
|
|
98
|
+
schedule?: ZiteSchedule;
|
|
99
|
+
inputs?: Record<string, unknown>;
|
|
100
|
+
}): Promise<{
|
|
101
|
+
id: string;
|
|
102
|
+
updated: true;
|
|
103
|
+
}>;
|
|
16
104
|
}
|
|
105
|
+
export declare const Schedules: typeof ZiteSchedules;
|
|
106
|
+
export {};
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
exports.Schedules = exports.ZiteSchedules = void 0;
|
|
4
|
+
const sdkCall_js_1 = require("../internal/sdkCall.js");
|
|
5
|
+
const SCHEDULES_SDK_INTEGRATION_ID = '__schedules__';
|
|
6
|
+
class ZiteSchedules {
|
|
7
|
+
static add(args) {
|
|
8
|
+
return (0, sdkCall_js_1.getSdkCall)()(SCHEDULES_SDK_INTEGRATION_ID, 'ZiteSchedules', 'add', args);
|
|
7
9
|
}
|
|
8
|
-
static
|
|
9
|
-
|
|
10
|
+
static list(args) {
|
|
11
|
+
return (0, sdkCall_js_1.getSdkCall)()(SCHEDULES_SDK_INTEGRATION_ID, 'ZiteSchedules', 'list', args ?? {});
|
|
10
12
|
}
|
|
11
|
-
static
|
|
12
|
-
|
|
13
|
+
static remove(args) {
|
|
14
|
+
return (0, sdkCall_js_1.getSdkCall)()(SCHEDULES_SDK_INTEGRATION_ID, 'ZiteSchedules', 'remove', args);
|
|
15
|
+
}
|
|
16
|
+
static update(args) {
|
|
17
|
+
return (0, sdkCall_js_1.getSdkCall)()(SCHEDULES_SDK_INTEGRATION_ID, 'ZiteSchedules', 'update', args);
|
|
13
18
|
}
|
|
14
19
|
}
|
|
15
|
-
exports.
|
|
20
|
+
exports.ZiteSchedules = ZiteSchedules;
|
|
21
|
+
exports.Schedules = ZiteSchedules;
|
package/dist/cjs/sync/index.js
CHANGED
|
@@ -27,9 +27,7 @@ const DB_ENVIRONMENTS = {
|
|
|
27
27
|
local: "http://localhost:2507/api/v1",
|
|
28
28
|
};
|
|
29
29
|
const env = process.env.ZITE_ENV ?? "production";
|
|
30
|
-
const BASE_URL = process.env.ZITE_DB_URL ??
|
|
31
|
-
DB_ENVIRONMENTS[env] ??
|
|
32
|
-
DB_ENVIRONMENTS.production;
|
|
30
|
+
const BASE_URL = process.env.ZITE_DB_URL ?? DB_ENVIRONMENTS[env] ?? DB_ENVIRONMENTS.production;
|
|
33
31
|
const TOKEN = process.env.ZITE_DB_TOKEN ?? "";
|
|
34
32
|
async function fetchDatabase(baseId) {
|
|
35
33
|
const url = `${BASE_URL}/bases/${encodeURIComponent(baseId)}`;
|
|
@@ -88,7 +86,12 @@ function regenerateApiTs() {
|
|
|
88
86
|
const apiDir = (0, path_1.join)("src", "api");
|
|
89
87
|
if (!(0, fs_1.existsSync)(apiDir))
|
|
90
88
|
return;
|
|
91
|
-
const endpointFiles = (0, fs_1.readdirSync)(apiDir)
|
|
89
|
+
const endpointFiles = (0, fs_1.readdirSync)(apiDir)
|
|
90
|
+
.filter((f) => f.endsWith(".ts") || f.endsWith(".js"))
|
|
91
|
+
.map((f) => ({
|
|
92
|
+
fileName: f,
|
|
93
|
+
content: (0, fs_1.readFileSync)((0, path_1.join)(apiDir, f), "utf-8"),
|
|
94
|
+
}));
|
|
92
95
|
const apiTs = (0, lib_js_1.generateApiTs)(endpointFiles);
|
|
93
96
|
if (apiTs) {
|
|
94
97
|
(0, fs_1.mkdirSync)(".zite", { recursive: true });
|
package/dist/cjs/sync/lib.d.ts
CHANGED
|
@@ -30,7 +30,11 @@ export declare function generateSchema(database: Database, existingSchema?: Zite
|
|
|
30
30
|
* Pure function — no external data needed beyond what's in the schema file.
|
|
31
31
|
*/
|
|
32
32
|
export declare function generateDbTs(schema: ZiteSchema): string;
|
|
33
|
-
export
|
|
33
|
+
export type EndpointFileInfo = {
|
|
34
|
+
fileName: string;
|
|
35
|
+
content?: string;
|
|
36
|
+
};
|
|
37
|
+
export declare function generateApiTs(endpointFiles: (string | EndpointFileInfo)[]): string | null;
|
|
34
38
|
export declare function generateUserTs(usersTableFields?: Array<{
|
|
35
39
|
name: string;
|
|
36
40
|
type: string;
|
package/dist/cjs/sync/lib.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.generateUserTs = generateUserTs;
|
|
|
9
9
|
exports.generateAuthWrapperTs = generateAuthWrapperTs;
|
|
10
10
|
exports.generateAirtableTs = generateAirtableTs;
|
|
11
11
|
exports.generateBackendWrapperTs = generateBackendWrapperTs;
|
|
12
|
+
const parser_1 = require("@babel/parser");
|
|
12
13
|
const FIELD_TYPE_MAP = {
|
|
13
14
|
single_line_text: "string",
|
|
14
15
|
long_text: "string",
|
|
@@ -269,36 +270,80 @@ function generateDbTs(schema) {
|
|
|
269
270
|
lines.push("");
|
|
270
271
|
return lines.join("\n");
|
|
271
272
|
}
|
|
273
|
+
function detectStreamEnabled(source) {
|
|
274
|
+
try {
|
|
275
|
+
const ast = (0, parser_1.parse)(source, {
|
|
276
|
+
sourceType: "module",
|
|
277
|
+
plugins: ["typescript"],
|
|
278
|
+
});
|
|
279
|
+
const defaultExport = ast.program.body.find((n) => n.type === "ExportDefaultDeclaration" &&
|
|
280
|
+
n.declaration.type === "CallExpression");
|
|
281
|
+
if (!defaultExport || defaultExport.type !== "ExportDefaultDeclaration")
|
|
282
|
+
return false;
|
|
283
|
+
const call = defaultExport.declaration;
|
|
284
|
+
if (call.type !== "CallExpression" || call.arguments.length === 0)
|
|
285
|
+
return false;
|
|
286
|
+
const arg = call.arguments[0];
|
|
287
|
+
if (arg.type !== "ObjectExpression")
|
|
288
|
+
return false;
|
|
289
|
+
const streamProp = arg.properties.find((p) => p.type === "ObjectProperty" &&
|
|
290
|
+
((p.key.type === "Identifier" && p.key.name === "stream") ||
|
|
291
|
+
(p.key.type === "StringLiteral" && p.key.value === "stream")));
|
|
292
|
+
if (!streamProp || streamProp.type !== "ObjectProperty")
|
|
293
|
+
return false;
|
|
294
|
+
return (streamProp.value.type === "BooleanLiteral" &&
|
|
295
|
+
streamProp.value.value === true);
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
272
301
|
function generateApiTs(endpointFiles) {
|
|
273
302
|
if (!endpointFiles || endpointFiles.length === 0)
|
|
274
303
|
return null;
|
|
304
|
+
const endpoints = [];
|
|
305
|
+
for (const file of endpointFiles) {
|
|
306
|
+
const fileName = typeof file === "string" ? file : file.fileName;
|
|
307
|
+
const content = typeof file === "string" ? undefined : file.content;
|
|
308
|
+
const name = fileName.replace(/\.(ts|js)$/, "");
|
|
309
|
+
const camelName = toCamelCase(name);
|
|
310
|
+
const pascal = toPascalCase(camelName);
|
|
311
|
+
const stream = content ? detectStreamEnabled(content) : false;
|
|
312
|
+
endpoints.push({ camelName, pascal, stream });
|
|
313
|
+
}
|
|
314
|
+
const hasStreaming = endpoints.some((e) => e.stream);
|
|
275
315
|
const lines = [
|
|
276
316
|
"// Auto-generated by zitejs sync. Do not edit manually.",
|
|
277
317
|
"",
|
|
278
|
-
|
|
318
|
+
hasStreaming
|
|
319
|
+
? "import { createCaller, createStreamingCaller } from 'zitejs/caller';"
|
|
320
|
+
: "import { createCaller } from 'zitejs/caller';",
|
|
279
321
|
"",
|
|
280
322
|
];
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
const
|
|
284
|
-
const
|
|
285
|
-
const
|
|
286
|
-
lines.push(`import type { default as _${pascal}Ep } from '../src/api/${
|
|
287
|
-
endpointNames.push(camelName);
|
|
323
|
+
for (const { pascal, camelName } of endpoints) {
|
|
324
|
+
const name = camelName.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
325
|
+
const rawName = endpointFiles[endpoints.findIndex((e) => e.camelName === camelName)];
|
|
326
|
+
const fileName = typeof rawName === "string" ? rawName : rawName.fileName;
|
|
327
|
+
const baseName = fileName.replace(/\.(ts|js)$/, "");
|
|
328
|
+
lines.push(`import type { default as _${pascal}Ep } from '../src/api/${baseName}';`);
|
|
288
329
|
}
|
|
289
330
|
lines.push("");
|
|
290
|
-
for (const
|
|
291
|
-
const pascal = toPascalCase(name);
|
|
331
|
+
for (const { camelName, pascal, stream } of endpoints) {
|
|
292
332
|
lines.push(`type _${pascal}Cfg = typeof _${pascal}Ep;`);
|
|
293
333
|
lines.push(`export type ${pascal}InputType = Parameters<_${pascal}Cfg['execute']>[0]['input'];`);
|
|
294
334
|
lines.push(`export type ${pascal}OutputType = Awaited<ReturnType<_${pascal}Cfg['execute']>>;`);
|
|
295
|
-
|
|
335
|
+
if (stream) {
|
|
336
|
+
lines.push(`export const ${camelName} = createStreamingCaller<${pascal}InputType, ${pascal}OutputType>('${camelName}');`);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
lines.push(`export const ${camelName} = createCaller<${pascal}InputType, ${pascal}OutputType>('${camelName}');`);
|
|
340
|
+
}
|
|
296
341
|
lines.push("");
|
|
297
342
|
}
|
|
298
343
|
lines.push("");
|
|
299
344
|
lines.push("export const api = {");
|
|
300
|
-
for (const
|
|
301
|
-
lines.push(` ${
|
|
345
|
+
for (const { camelName } of endpoints) {
|
|
346
|
+
lines.push(` ${camelName},`);
|
|
302
347
|
}
|
|
303
348
|
lines.push("};");
|
|
304
349
|
lines.push("");
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
export type UploadData = string | Blob | ArrayBuffer | File;
|
|
2
|
+
export declare class FileUploadError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare function uploadFile({ data, filename, }: {
|
|
6
|
+
data: UploadData;
|
|
7
|
+
filename: string;
|
|
8
|
+
}): Promise<{
|
|
9
|
+
fileUrl: string;
|
|
10
|
+
}>;
|
|
1
11
|
export declare function useUpload(): {
|
|
2
|
-
upload: (file: File) => Promise<{
|
|
12
|
+
upload: (file: File | Blob | ArrayBuffer | string, filename?: string) => Promise<{
|
|
3
13
|
url: string;
|
|
4
14
|
}>;
|
|
5
15
|
isUploading: boolean;
|