zitejs 0.9.54 → 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/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/upload/index.d.ts +11 -1
- package/dist/cjs/upload/index.js +107 -1
- package/dist/esm/cli.js +0 -0
- 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/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
|
@@ -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;
|
|
@@ -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;
|
package/dist/cjs/upload/index.js
CHANGED
|
@@ -1,6 +1,112 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileUploadError = void 0;
|
|
4
|
+
exports.uploadFile = uploadFile;
|
|
3
5
|
exports.useUpload = useUpload;
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const config_js_1 = require("../auth/config.js");
|
|
8
|
+
const constants_js_1 = require("../auth/constants.js");
|
|
9
|
+
class FileUploadError extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'FileUploadError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.FileUploadError = FileUploadError;
|
|
16
|
+
function getZiteAppMode(hostname) {
|
|
17
|
+
const maybeId = hostname.split('.')[0];
|
|
18
|
+
if (maybeId?.startsWith(constants_js_1.ZITE_APP_EDITOR_HOSTNAME_PREFIX))
|
|
19
|
+
return 'preview';
|
|
20
|
+
if (maybeId?.startsWith(constants_js_1.ZITE_APP_ACTION_HOSTNAME_PREFIX))
|
|
21
|
+
return 'preview';
|
|
22
|
+
if (constants_js_1.ZITE_SANDBOX_DOMAINS.some(d => hostname === d || hostname.endsWith('.' + d))) {
|
|
23
|
+
return 'preview';
|
|
24
|
+
}
|
|
25
|
+
return 'live';
|
|
26
|
+
}
|
|
27
|
+
function readBlobAsDataUrl(blob) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
const reader = new FileReader();
|
|
30
|
+
reader.onload = () => resolve(reader.result);
|
|
31
|
+
reader.onerror = () => reject(reader.error ?? new Error('Failed to read file'));
|
|
32
|
+
reader.readAsDataURL(blob);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
async function toDataUrl(data) {
|
|
36
|
+
if (data instanceof Blob) {
|
|
37
|
+
return readBlobAsDataUrl(data);
|
|
38
|
+
}
|
|
39
|
+
if (data instanceof ArrayBuffer) {
|
|
40
|
+
const bytes = new Uint8Array(data);
|
|
41
|
+
let binary = '';
|
|
42
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
43
|
+
binary += String.fromCharCode(bytes[i]);
|
|
44
|
+
}
|
|
45
|
+
return 'data:application/octet-stream;base64,' + btoa(binary);
|
|
46
|
+
}
|
|
47
|
+
if (typeof data === 'string') {
|
|
48
|
+
if (data.startsWith('data:'))
|
|
49
|
+
return data;
|
|
50
|
+
if (/^[A-Za-z0-9+/]+=*$/.test(data)) {
|
|
51
|
+
return 'data:application/octet-stream;base64,' + data;
|
|
52
|
+
}
|
|
53
|
+
return 'data:text/plain;base64,' + btoa(unescape(encodeURIComponent(data)));
|
|
54
|
+
}
|
|
55
|
+
throw new FileUploadError('Invalid data format. Expected string, Blob, ArrayBuffer, or File.');
|
|
56
|
+
}
|
|
57
|
+
function resolveFilename(data, filename) {
|
|
58
|
+
if (filename)
|
|
59
|
+
return filename;
|
|
60
|
+
if (typeof File !== 'undefined' && data instanceof File && data.name) {
|
|
61
|
+
return data.name;
|
|
62
|
+
}
|
|
63
|
+
throw new FileUploadError('A filename is required unless the uploaded data is a File.');
|
|
64
|
+
}
|
|
65
|
+
async function performUpload(data, filename) {
|
|
66
|
+
const body = await toDataUrl(data);
|
|
67
|
+
const mode = getZiteAppMode(window.location.hostname);
|
|
68
|
+
const flowId = (0, config_js_1.getFlowId)();
|
|
69
|
+
const token = typeof localStorage !== 'undefined'
|
|
70
|
+
? localStorage.getItem('zite.auth.token')
|
|
71
|
+
: null;
|
|
72
|
+
const res = await fetch((0, config_js_1.getApiUrl)() + '/v1/zite/public/' + flowId + '/upload?mode=' + mode, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers: {
|
|
75
|
+
'Content-Type': 'application/json',
|
|
76
|
+
...(token ? { Authorization: 'Bearer ' + token } : {}),
|
|
77
|
+
},
|
|
78
|
+
body: JSON.stringify({ data: body, filename }),
|
|
79
|
+
});
|
|
80
|
+
if (!res.ok) {
|
|
81
|
+
let message = 'Upload failed';
|
|
82
|
+
try {
|
|
83
|
+
const err = (await res.json());
|
|
84
|
+
if (err.message)
|
|
85
|
+
message = err.message;
|
|
86
|
+
}
|
|
87
|
+
catch { }
|
|
88
|
+
throw new FileUploadError(message);
|
|
89
|
+
}
|
|
90
|
+
const result = (await res.json());
|
|
91
|
+
if (!result.success || !result.fileUrl) {
|
|
92
|
+
throw new FileUploadError(result.message ?? 'Upload failed');
|
|
93
|
+
}
|
|
94
|
+
return result.fileUrl;
|
|
95
|
+
}
|
|
96
|
+
async function uploadFile({ data, filename, }) {
|
|
97
|
+
return { fileUrl: await performUpload(data, filename) };
|
|
98
|
+
}
|
|
4
99
|
function useUpload() {
|
|
5
|
-
|
|
100
|
+
const [isUploading, setIsUploading] = (0, react_1.useState)(false);
|
|
101
|
+
const upload = (0, react_1.useCallback)(async (file, filename) => {
|
|
102
|
+
setIsUploading(true);
|
|
103
|
+
try {
|
|
104
|
+
const url = await performUpload(file, resolveFilename(file, filename));
|
|
105
|
+
return { url };
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
setIsUploading(false);
|
|
109
|
+
}
|
|
110
|
+
}, []);
|
|
111
|
+
return { upload, isUploading };
|
|
6
112
|
}
|
package/dist/esm/cli.js
CHANGED
|
File without changes
|
package/dist/esm/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/esm/pdf/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { getSdkCall } from '../internal/sdkCall.js';
|
|
2
|
+
const PDF_LIB_INTEGRATION_ID = '__pdf__';
|
|
1
3
|
export class ZitePdf {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
+
static renderHtml(params) {
|
|
5
|
+
return getSdkCall()(PDF_LIB_INTEGRATION_ID, 'ZitePdf', 'renderHtml', params);
|
|
4
6
|
}
|
|
5
7
|
}
|
|
8
|
+
export const Pdf = ZitePdf;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const fn = globalThis.__wrapSdkCall;
|
|
3
|
-
if (!fn) {
|
|
4
|
-
throw new Error("Zite SDK runtime not initialized. Endpoints must run inside the Zite worker.");
|
|
5
|
-
}
|
|
6
|
-
return fn;
|
|
7
|
-
}
|
|
1
|
+
import { getSdkCall } from "../internal/sdkCall.js";
|
|
8
2
|
const DB_INTEGRATION_ID = "databases";
|
|
9
3
|
function getBaseId() {
|
|
10
4
|
try {
|
|
@@ -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,11 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { getSdkCall } from '../internal/sdkCall.js';
|
|
2
|
+
const SCHEDULES_SDK_INTEGRATION_ID = '__schedules__';
|
|
3
|
+
export class ZiteSchedules {
|
|
4
|
+
static add(args) {
|
|
5
|
+
return getSdkCall()(SCHEDULES_SDK_INTEGRATION_ID, 'ZiteSchedules', 'add', args);
|
|
4
6
|
}
|
|
5
|
-
static
|
|
6
|
-
|
|
7
|
+
static list(args) {
|
|
8
|
+
return getSdkCall()(SCHEDULES_SDK_INTEGRATION_ID, 'ZiteSchedules', 'list', args ?? {});
|
|
7
9
|
}
|
|
8
|
-
static
|
|
9
|
-
|
|
10
|
+
static remove(args) {
|
|
11
|
+
return getSdkCall()(SCHEDULES_SDK_INTEGRATION_ID, 'ZiteSchedules', 'remove', args);
|
|
12
|
+
}
|
|
13
|
+
static update(args) {
|
|
14
|
+
return getSdkCall()(SCHEDULES_SDK_INTEGRATION_ID, 'ZiteSchedules', 'update', args);
|
|
10
15
|
}
|
|
11
16
|
}
|
|
17
|
+
export const Schedules = ZiteSchedules;
|
|
@@ -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;
|
package/dist/esm/upload/index.js
CHANGED
|
@@ -1,3 +1,106 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
import { getApiUrl, getFlowId } from '../auth/config.js';
|
|
3
|
+
import { ZITE_APP_ACTION_HOSTNAME_PREFIX, ZITE_APP_EDITOR_HOSTNAME_PREFIX, ZITE_SANDBOX_DOMAINS, } from '../auth/constants.js';
|
|
4
|
+
export class FileUploadError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'FileUploadError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function getZiteAppMode(hostname) {
|
|
11
|
+
const maybeId = hostname.split('.')[0];
|
|
12
|
+
if (maybeId?.startsWith(ZITE_APP_EDITOR_HOSTNAME_PREFIX))
|
|
13
|
+
return 'preview';
|
|
14
|
+
if (maybeId?.startsWith(ZITE_APP_ACTION_HOSTNAME_PREFIX))
|
|
15
|
+
return 'preview';
|
|
16
|
+
if (ZITE_SANDBOX_DOMAINS.some(d => hostname === d || hostname.endsWith('.' + d))) {
|
|
17
|
+
return 'preview';
|
|
18
|
+
}
|
|
19
|
+
return 'live';
|
|
20
|
+
}
|
|
21
|
+
function readBlobAsDataUrl(blob) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
const reader = new FileReader();
|
|
24
|
+
reader.onload = () => resolve(reader.result);
|
|
25
|
+
reader.onerror = () => reject(reader.error ?? new Error('Failed to read file'));
|
|
26
|
+
reader.readAsDataURL(blob);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async function toDataUrl(data) {
|
|
30
|
+
if (data instanceof Blob) {
|
|
31
|
+
return readBlobAsDataUrl(data);
|
|
32
|
+
}
|
|
33
|
+
if (data instanceof ArrayBuffer) {
|
|
34
|
+
const bytes = new Uint8Array(data);
|
|
35
|
+
let binary = '';
|
|
36
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
37
|
+
binary += String.fromCharCode(bytes[i]);
|
|
38
|
+
}
|
|
39
|
+
return 'data:application/octet-stream;base64,' + btoa(binary);
|
|
40
|
+
}
|
|
41
|
+
if (typeof data === 'string') {
|
|
42
|
+
if (data.startsWith('data:'))
|
|
43
|
+
return data;
|
|
44
|
+
if (/^[A-Za-z0-9+/]+=*$/.test(data)) {
|
|
45
|
+
return 'data:application/octet-stream;base64,' + data;
|
|
46
|
+
}
|
|
47
|
+
return 'data:text/plain;base64,' + btoa(unescape(encodeURIComponent(data)));
|
|
48
|
+
}
|
|
49
|
+
throw new FileUploadError('Invalid data format. Expected string, Blob, ArrayBuffer, or File.');
|
|
50
|
+
}
|
|
51
|
+
function resolveFilename(data, filename) {
|
|
52
|
+
if (filename)
|
|
53
|
+
return filename;
|
|
54
|
+
if (typeof File !== 'undefined' && data instanceof File && data.name) {
|
|
55
|
+
return data.name;
|
|
56
|
+
}
|
|
57
|
+
throw new FileUploadError('A filename is required unless the uploaded data is a File.');
|
|
58
|
+
}
|
|
59
|
+
async function performUpload(data, filename) {
|
|
60
|
+
const body = await toDataUrl(data);
|
|
61
|
+
const mode = getZiteAppMode(window.location.hostname);
|
|
62
|
+
const flowId = getFlowId();
|
|
63
|
+
const token = typeof localStorage !== 'undefined'
|
|
64
|
+
? localStorage.getItem('zite.auth.token')
|
|
65
|
+
: null;
|
|
66
|
+
const res = await fetch(getApiUrl() + '/v1/zite/public/' + flowId + '/upload?mode=' + mode, {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
headers: {
|
|
69
|
+
'Content-Type': 'application/json',
|
|
70
|
+
...(token ? { Authorization: 'Bearer ' + token } : {}),
|
|
71
|
+
},
|
|
72
|
+
body: JSON.stringify({ data: body, filename }),
|
|
73
|
+
});
|
|
74
|
+
if (!res.ok) {
|
|
75
|
+
let message = 'Upload failed';
|
|
76
|
+
try {
|
|
77
|
+
const err = (await res.json());
|
|
78
|
+
if (err.message)
|
|
79
|
+
message = err.message;
|
|
80
|
+
}
|
|
81
|
+
catch { }
|
|
82
|
+
throw new FileUploadError(message);
|
|
83
|
+
}
|
|
84
|
+
const result = (await res.json());
|
|
85
|
+
if (!result.success || !result.fileUrl) {
|
|
86
|
+
throw new FileUploadError(result.message ?? 'Upload failed');
|
|
87
|
+
}
|
|
88
|
+
return result.fileUrl;
|
|
89
|
+
}
|
|
90
|
+
export async function uploadFile({ data, filename, }) {
|
|
91
|
+
return { fileUrl: await performUpload(data, filename) };
|
|
92
|
+
}
|
|
1
93
|
export function useUpload() {
|
|
2
|
-
|
|
94
|
+
const [isUploading, setIsUploading] = useState(false);
|
|
95
|
+
const upload = useCallback(async (file, filename) => {
|
|
96
|
+
setIsUploading(true);
|
|
97
|
+
try {
|
|
98
|
+
const url = await performUpload(file, resolveFilename(file, filename));
|
|
99
|
+
return { url };
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
setIsUploading(false);
|
|
103
|
+
}
|
|
104
|
+
}, []);
|
|
105
|
+
return { upload, isUploading };
|
|
3
106
|
}
|
package/package.json
CHANGED
package/dist/cjs/api/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCaller = void 0;
|
|
4
|
-
var index_js_1 = require("../caller/index.js");
|
|
5
|
-
Object.defineProperty(exports, "createCaller", { enumerable: true, get: function () { return index_js_1.createCaller; } });
|
package/dist/cjs/db/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTableClient = void 0;
|
|
4
|
-
var index_js_1 = require("../runtime/index.js");
|
|
5
|
-
Object.defineProperty(exports, "createTableClient", { enumerable: true, get: function () { return index_js_1.createTableClient; } });
|
package/dist/esm/api/index.d.ts
DELETED
package/dist/esm/api/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createCaller } from '../caller/index.js';
|
package/dist/esm/db/index.d.ts
DELETED
package/dist/esm/db/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createTableClient } from '../runtime/index.js';
|