zitejs 0.4.0 → 0.5.1
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/api/index.js +22 -0
- package/dist/cjs/auth/index.js +10 -0
- package/dist/cjs/backend/index.js +16 -0
- package/dist/cjs/db/index.js +8 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pdf/index.js +9 -0
- package/dist/cjs/schedules/index.js +15 -0
- package/dist/cjs/sync/index.js +65 -0
- package/dist/cjs/sync/lib.js +189 -0
- package/dist/cjs/upload/index.js +6 -0
- package/dist/esm/api/index.d.ts +4 -0
- package/dist/esm/api/index.d.ts.map +1 -0
- package/dist/esm/api/index.js +20 -0
- package/dist/esm/api/index.js.map +1 -0
- package/dist/esm/auth/index.d.ts +14 -0
- package/dist/esm/auth/index.d.ts.map +1 -0
- package/dist/esm/auth/index.js +7 -0
- package/dist/esm/auth/index.js.map +1 -0
- package/dist/esm/backend/index.d.ts +27 -0
- package/dist/esm/backend/index.d.ts.map +1 -0
- package/dist/esm/backend/index.js +12 -0
- package/dist/esm/backend/index.js.map +1 -0
- package/dist/esm/db/index.d.ts +17 -0
- package/dist/esm/db/index.d.ts.map +1 -0
- package/dist/esm/db/index.js +6 -0
- package/dist/esm/db/index.js.map +1 -0
- package/dist/esm/pdf/index.d.ts +10 -0
- package/dist/esm/pdf/index.d.ts.map +1 -0
- package/dist/esm/pdf/index.js +6 -0
- package/dist/esm/pdf/index.js.map +1 -0
- package/dist/esm/schedules/index.d.ts +17 -0
- package/dist/esm/schedules/index.d.ts.map +1 -0
- package/dist/esm/schedules/index.js +12 -0
- package/dist/esm/schedules/index.js.map +1 -0
- package/dist/esm/sync/index.d.ts +3 -0
- package/dist/esm/sync/index.d.ts.map +1 -0
- package/dist/esm/sync/index.js +64 -0
- package/dist/esm/sync/index.js.map +1 -0
- package/dist/esm/sync/lib.d.ts +26 -0
- package/dist/esm/sync/lib.d.ts.map +1 -0
- package/dist/esm/sync/lib.js +182 -0
- package/dist/esm/sync/lib.js.map +1 -0
- package/dist/esm/upload/index.d.ts +7 -0
- package/dist/esm/upload/index.d.ts.map +1 -0
- package/dist/esm/upload/index.js +4 -0
- package/dist/esm/upload/index.js.map +1 -0
- package/package.json +39 -25
- package/api/index.d.ts +0 -21
- package/api/index.js +0 -22
- package/auth/index.d.ts +0 -23
- package/auth/index.js +0 -8
- package/backend/index.d.ts +0 -39
- package/backend/index.js +0 -13
- package/db/index.d.ts +0 -34
- package/db/index.js +0 -23
- package/pdf/index.d.ts +0 -15
- package/pdf/index.js +0 -6
- package/schedules/index.d.ts +0 -19
- package/schedules/index.js +0 -12
- package/sync/index.js +0 -87
- package/sync/lib.js +0 -173
- package/upload/index.d.ts +0 -11
- package/upload/index.js +0 -4
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCaller = createCaller;
|
|
4
|
+
const BASE_URL = process.env.ZITE_API_URL ?? '';
|
|
5
|
+
const TOKEN = process.env.ZITE_DB_TOKEN ?? '';
|
|
6
|
+
function createCaller(endpoint) {
|
|
7
|
+
return async (input) => {
|
|
8
|
+
const res = await fetch(BASE_URL + '/api/' + endpoint._name, {
|
|
9
|
+
method: 'POST',
|
|
10
|
+
headers: {
|
|
11
|
+
Authorization: `Bearer ${TOKEN}`,
|
|
12
|
+
'Content-Type': 'application/json',
|
|
13
|
+
},
|
|
14
|
+
body: JSON.stringify(input),
|
|
15
|
+
});
|
|
16
|
+
if (!res.ok) {
|
|
17
|
+
const text = await res.text().catch(() => '');
|
|
18
|
+
throw new Error(`API call failed (${res.status}): ${text}`);
|
|
19
|
+
}
|
|
20
|
+
return res.json();
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAuth = useAuth;
|
|
4
|
+
exports.getCurrentUser = getCurrentUser;
|
|
5
|
+
function useAuth() {
|
|
6
|
+
throw new Error('useAuth() is only available in the Zite runtime.');
|
|
7
|
+
}
|
|
8
|
+
function getCurrentUser() {
|
|
9
|
+
throw new Error('getCurrentUser() is only available in the Zite runtime.');
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZiteError = void 0;
|
|
4
|
+
exports.createEndpoint = createEndpoint;
|
|
5
|
+
class ZiteError extends Error {
|
|
6
|
+
statusCode;
|
|
7
|
+
constructor(message, options) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = 'ZiteError';
|
|
10
|
+
this.statusCode = options?.statusCode ?? 500;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.ZiteError = ZiteError;
|
|
14
|
+
function createEndpoint(config) {
|
|
15
|
+
return config;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZiteSchedule = void 0;
|
|
4
|
+
class ZiteSchedule {
|
|
5
|
+
static create(config) {
|
|
6
|
+
throw new Error('ZiteSchedule is only available in the Zite runtime.');
|
|
7
|
+
}
|
|
8
|
+
static delete(id) {
|
|
9
|
+
throw new Error('ZiteSchedule is only available in the Zite runtime.');
|
|
10
|
+
}
|
|
11
|
+
static list() {
|
|
12
|
+
throw new Error('ZiteSchedule is only available in the Zite runtime.');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.ZiteSchedule = ZiteSchedule;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const lib_js_1 = require("./lib.js");
|
|
7
|
+
const BASE_URL = process.env.ZITE_DB_URL ?? 'https://tables.fillout.com/api/v1';
|
|
8
|
+
const TOKEN = process.env.ZITE_DB_TOKEN ?? '';
|
|
9
|
+
async function fetchBaseMetadata(baseId) {
|
|
10
|
+
const url = `${BASE_URL}/bases/${encodeURIComponent(baseId)}`;
|
|
11
|
+
const res = await fetch(url, {
|
|
12
|
+
headers: { Authorization: `Bearer ${TOKEN}` },
|
|
13
|
+
});
|
|
14
|
+
if (!res.ok) {
|
|
15
|
+
throw new Error(`Failed to fetch base metadata (${res.status}): ${await res.text()}`);
|
|
16
|
+
}
|
|
17
|
+
return res.json();
|
|
18
|
+
}
|
|
19
|
+
async function main() {
|
|
20
|
+
if (!TOKEN) {
|
|
21
|
+
console.error('Error: ZITE_DB_TOKEN is required.');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
let baseId = process.env.ZITE_BASE_ID;
|
|
25
|
+
if (!baseId) {
|
|
26
|
+
try {
|
|
27
|
+
const config = JSON.parse((0, fs_1.readFileSync)('zite.config.json', 'utf-8'));
|
|
28
|
+
baseId = config.project?.basePublicIdentifier;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
/* ignore */
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (!baseId) {
|
|
35
|
+
console.error('Error: Could not determine base ID.');
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
console.log(`Syncing database ${baseId}...`);
|
|
39
|
+
const base = await fetchBaseMetadata(baseId);
|
|
40
|
+
console.log(`Found ${base.tables?.length ?? 0} tables`);
|
|
41
|
+
const schema = (0, lib_js_1.generateSchema)(base);
|
|
42
|
+
(0, fs_1.writeFileSync)('zite.schema.json', JSON.stringify(schema, null, 2));
|
|
43
|
+
console.log('Wrote zite.schema.json');
|
|
44
|
+
const dbTs = (0, lib_js_1.generateDbTs)(base, schema, baseId);
|
|
45
|
+
const dbDts = (0, lib_js_1.generateDbDts)(base, schema);
|
|
46
|
+
const dotZite = '.zite';
|
|
47
|
+
(0, fs_1.mkdirSync)(dotZite, { recursive: true });
|
|
48
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(dotZite, 'db.ts'), dbTs);
|
|
49
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(dotZite, 'db.d.ts'), dbDts);
|
|
50
|
+
console.log('Wrote .zite/db.ts + .zite/db.d.ts');
|
|
51
|
+
const apiDir = (0, path_1.join)('src', 'api');
|
|
52
|
+
if ((0, fs_1.existsSync)(apiDir)) {
|
|
53
|
+
const endpointFiles = (0, fs_1.readdirSync)(apiDir).filter((f) => f.endsWith('.ts') || f.endsWith('.js'));
|
|
54
|
+
const apiTs = (0, lib_js_1.generateApiTs)(endpointFiles);
|
|
55
|
+
if (apiTs) {
|
|
56
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(dotZite, 'api.ts'), apiTs);
|
|
57
|
+
console.log('Wrote .zite/api.ts');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
console.log('Done!');
|
|
61
|
+
}
|
|
62
|
+
main().catch((err) => {
|
|
63
|
+
console.error('Sync failed:', err.message);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
});
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toPascalCase = toPascalCase;
|
|
4
|
+
exports.toCamelCase = toCamelCase;
|
|
5
|
+
exports.generateSchema = generateSchema;
|
|
6
|
+
exports.generateDbTs = generateDbTs;
|
|
7
|
+
exports.generateDbDts = generateDbDts;
|
|
8
|
+
exports.generateApiTs = generateApiTs;
|
|
9
|
+
const FIELD_TYPE_MAP = {
|
|
10
|
+
single_line_text: 'string',
|
|
11
|
+
long_text: 'string',
|
|
12
|
+
email: 'string',
|
|
13
|
+
url: 'string',
|
|
14
|
+
phone_number: 'string',
|
|
15
|
+
number: 'number',
|
|
16
|
+
currency: 'number',
|
|
17
|
+
percent: 'number',
|
|
18
|
+
rating: 'number',
|
|
19
|
+
duration: 'number',
|
|
20
|
+
single_select: 'string',
|
|
21
|
+
multiple_select: 'string[]',
|
|
22
|
+
checkbox: 'boolean',
|
|
23
|
+
date: 'string',
|
|
24
|
+
datetime: 'string',
|
|
25
|
+
attachments: 'Array<{ url: string; name?: string }>',
|
|
26
|
+
linked_record: 'string[]',
|
|
27
|
+
lookup: 'unknown',
|
|
28
|
+
autonumber: 'number',
|
|
29
|
+
source: 'string',
|
|
30
|
+
};
|
|
31
|
+
function toPascalCase(name) {
|
|
32
|
+
return name
|
|
33
|
+
.replace(/[^a-zA-Z0-9]+(.)/g, (_, c) => c.toUpperCase())
|
|
34
|
+
.replace(/^(.)/, (_, c) => c.toUpperCase());
|
|
35
|
+
}
|
|
36
|
+
function toCamelCase(name) {
|
|
37
|
+
const pascal = toPascalCase(name);
|
|
38
|
+
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
39
|
+
}
|
|
40
|
+
function tsTypeForField(field) {
|
|
41
|
+
return FIELD_TYPE_MAP[field.type] ?? 'unknown';
|
|
42
|
+
}
|
|
43
|
+
function generateSchema(base) {
|
|
44
|
+
const schema = { tables: {} };
|
|
45
|
+
for (const table of base.tables ?? []) {
|
|
46
|
+
const tableName = toCamelCase(table.name);
|
|
47
|
+
const fields = {};
|
|
48
|
+
for (const field of table.fields ?? []) {
|
|
49
|
+
fields[toCamelCase(field.name)] = { id: field.id };
|
|
50
|
+
}
|
|
51
|
+
schema.tables[tableName] = { id: table.id, fields };
|
|
52
|
+
}
|
|
53
|
+
return schema;
|
|
54
|
+
}
|
|
55
|
+
function generateDbTs(base, schema, baseId) {
|
|
56
|
+
const lines = [];
|
|
57
|
+
lines.push('// Auto-generated by zitejs sync. Do not edit manually.');
|
|
58
|
+
lines.push('');
|
|
59
|
+
lines.push("const BASE_URL = process.env.ZITE_DB_URL ?? 'https://tables.fillout.com/api/v1';");
|
|
60
|
+
lines.push("const TOKEN = process.env.ZITE_DB_TOKEN ?? '';");
|
|
61
|
+
lines.push('');
|
|
62
|
+
lines.push('async function dbFetch(method: string, path: string, body?: unknown) {');
|
|
63
|
+
lines.push(' const res = await fetch(BASE_URL + path, {');
|
|
64
|
+
lines.push(' method,');
|
|
65
|
+
lines.push(' headers: {');
|
|
66
|
+
lines.push(' Authorization: `Bearer ${TOKEN}`,');
|
|
67
|
+
lines.push(" ...(body ? { 'Content-Type': 'application/json' } : {}),");
|
|
68
|
+
lines.push(' },');
|
|
69
|
+
lines.push(' body: body ? JSON.stringify(body) : undefined,');
|
|
70
|
+
lines.push(' });');
|
|
71
|
+
lines.push(' if (!res.ok) {');
|
|
72
|
+
lines.push(" const text = await res.text().catch(() => '');");
|
|
73
|
+
lines.push(' throw new Error(`Zite DB request failed (${res.status}): ${text}`);');
|
|
74
|
+
lines.push(' }');
|
|
75
|
+
lines.push(' return res.json();');
|
|
76
|
+
lines.push('}');
|
|
77
|
+
lines.push('');
|
|
78
|
+
for (const table of base.tables ?? []) {
|
|
79
|
+
const className = toPascalCase(table.name);
|
|
80
|
+
const recordType = `${className}RecordType`;
|
|
81
|
+
lines.push(`export type ${recordType} = {`);
|
|
82
|
+
lines.push(' id: string;');
|
|
83
|
+
for (const field of table.fields ?? []) {
|
|
84
|
+
const fieldName = toCamelCase(field.name);
|
|
85
|
+
const tsType = tsTypeForField(field);
|
|
86
|
+
lines.push(` ${fieldName}: ${tsType};`);
|
|
87
|
+
}
|
|
88
|
+
lines.push(' createdAt: string;');
|
|
89
|
+
lines.push(' updatedAt: string;');
|
|
90
|
+
lines.push('};');
|
|
91
|
+
lines.push('');
|
|
92
|
+
}
|
|
93
|
+
lines.push('function createTableClient<T>(baseId: string, tableId: string) {');
|
|
94
|
+
lines.push(' const base = `/bases/${encodeURIComponent(baseId)}/tables/${encodeURIComponent(tableId)}`;');
|
|
95
|
+
lines.push(' return {');
|
|
96
|
+
lines.push(' findMany: (options?: { limit?: number; offset?: number; sort?: unknown[]; filter?: unknown }): Promise<{ records: T[]; total: number; hasMore: boolean }> =>');
|
|
97
|
+
lines.push(' dbFetch("POST", `${base}/records/list`, options),');
|
|
98
|
+
lines.push(' findOne: (recordId: string): Promise<T> =>');
|
|
99
|
+
lines.push(' dbFetch("GET", `${base}/records/${encodeURIComponent(recordId)}`),');
|
|
100
|
+
lines.push(' create: (data: Partial<T>): Promise<T> =>');
|
|
101
|
+
lines.push(' dbFetch("POST", `${base}/records`, { record: data }),');
|
|
102
|
+
lines.push(' update: (recordId: string, data: Partial<T>): Promise<T> =>');
|
|
103
|
+
lines.push(' dbFetch("PATCH", `${base}/records/${encodeURIComponent(recordId)}`, { record: data }),');
|
|
104
|
+
lines.push(' delete: (recordId: string): Promise<{ deleted: true }> =>');
|
|
105
|
+
lines.push(' dbFetch("DELETE", `${base}/records/${encodeURIComponent(recordId)}`),');
|
|
106
|
+
lines.push(' bulkCreate: (records: Partial<T>[]): Promise<T[]> =>');
|
|
107
|
+
lines.push(' dbFetch("POST", `${base}/records/bulk`, { records }),');
|
|
108
|
+
lines.push(' };');
|
|
109
|
+
lines.push('}');
|
|
110
|
+
lines.push('');
|
|
111
|
+
lines.push(`const BASE_ID = '${baseId}';`);
|
|
112
|
+
lines.push('');
|
|
113
|
+
lines.push('export const zite = {');
|
|
114
|
+
for (const table of base.tables ?? []) {
|
|
115
|
+
const className = toPascalCase(table.name);
|
|
116
|
+
const propName = toCamelCase(table.name);
|
|
117
|
+
const tableId = schema.tables[propName]?.id ?? table.id;
|
|
118
|
+
lines.push(` ${propName}: createTableClient<${className}RecordType>(BASE_ID, '${tableId}'),`);
|
|
119
|
+
}
|
|
120
|
+
lines.push('};');
|
|
121
|
+
lines.push('');
|
|
122
|
+
return lines.join('\n');
|
|
123
|
+
}
|
|
124
|
+
function generateDbDts(base, schema) {
|
|
125
|
+
const lines = [
|
|
126
|
+
'// Auto-generated by zitejs sync. Do not edit manually.',
|
|
127
|
+
'// This file contains only type declarations for LLM context.',
|
|
128
|
+
'// See db.ts for the full runtime implementation.',
|
|
129
|
+
'',
|
|
130
|
+
'interface TableClient<T> {',
|
|
131
|
+
' findMany(options?: { limit?: number; offset?: number; sort?: unknown[]; filter?: unknown }): Promise<{ records: T[]; total: number; hasMore: boolean }>;',
|
|
132
|
+
' findOne(recordId: string): Promise<T>;',
|
|
133
|
+
' create(data: Partial<T>): Promise<T>;',
|
|
134
|
+
' update(recordId: string, data: Partial<T>): Promise<T>;',
|
|
135
|
+
' delete(recordId: string): Promise<{ deleted: true }>;',
|
|
136
|
+
' bulkCreate(records: Partial<T>[]): Promise<T[]>;',
|
|
137
|
+
'}',
|
|
138
|
+
'',
|
|
139
|
+
];
|
|
140
|
+
for (const table of base.tables ?? []) {
|
|
141
|
+
const className = toPascalCase(table.name);
|
|
142
|
+
const recordType = `${className}RecordType`;
|
|
143
|
+
lines.push(`export type ${recordType} = {`);
|
|
144
|
+
lines.push(' id: string;');
|
|
145
|
+
for (const field of table.fields ?? []) {
|
|
146
|
+
const fieldName = toCamelCase(field.name);
|
|
147
|
+
const tsType = tsTypeForField(field);
|
|
148
|
+
lines.push(` ${fieldName}: ${tsType};`);
|
|
149
|
+
}
|
|
150
|
+
lines.push(' createdAt: string;');
|
|
151
|
+
lines.push(' updatedAt: string;');
|
|
152
|
+
lines.push('};');
|
|
153
|
+
lines.push('');
|
|
154
|
+
}
|
|
155
|
+
lines.push('export declare const zite: {');
|
|
156
|
+
for (const table of base.tables ?? []) {
|
|
157
|
+
const className = toPascalCase(table.name);
|
|
158
|
+
const propName = toCamelCase(table.name);
|
|
159
|
+
lines.push(` ${propName}: TableClient<${className}RecordType>;`);
|
|
160
|
+
}
|
|
161
|
+
lines.push('};');
|
|
162
|
+
lines.push('');
|
|
163
|
+
return lines.join('\n');
|
|
164
|
+
}
|
|
165
|
+
function generateApiTs(endpointFiles) {
|
|
166
|
+
if (!endpointFiles || endpointFiles.length === 0)
|
|
167
|
+
return null;
|
|
168
|
+
const lines = [
|
|
169
|
+
'// Auto-generated by zitejs sync. Do not edit manually.',
|
|
170
|
+
'',
|
|
171
|
+
"import { createCaller } from 'zitejs/api';",
|
|
172
|
+
'',
|
|
173
|
+
];
|
|
174
|
+
const endpointNames = [];
|
|
175
|
+
for (const file of endpointFiles) {
|
|
176
|
+
const name = file.replace(/\.(ts|js)$/, '');
|
|
177
|
+
const camelName = toCamelCase(name);
|
|
178
|
+
lines.push(`import ${camelName}Endpoint from '../src/api/${name}';`);
|
|
179
|
+
endpointNames.push(camelName);
|
|
180
|
+
}
|
|
181
|
+
lines.push('');
|
|
182
|
+
lines.push('export const api = {');
|
|
183
|
+
for (const name of endpointNames) {
|
|
184
|
+
lines.push(` ${name}: createCaller(${name}Endpoint),`);
|
|
185
|
+
}
|
|
186
|
+
lines.push('};');
|
|
187
|
+
lines.push('');
|
|
188
|
+
return lines.join('\n');
|
|
189
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAK1D,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,EAC1C,QAAQ,EAAE,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,GACxC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAgBrC;AAED,YAAY,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const BASE_URL = process.env.ZITE_API_URL ?? '';
|
|
2
|
+
const TOKEN = process.env.ZITE_DB_TOKEN ?? '';
|
|
3
|
+
export function createCaller(endpoint) {
|
|
4
|
+
return async (input) => {
|
|
5
|
+
const res = await fetch(BASE_URL + '/api/' + endpoint._name, {
|
|
6
|
+
method: 'POST',
|
|
7
|
+
headers: {
|
|
8
|
+
Authorization: `Bearer ${TOKEN}`,
|
|
9
|
+
'Content-Type': 'application/json',
|
|
10
|
+
},
|
|
11
|
+
body: JSON.stringify(input),
|
|
12
|
+
});
|
|
13
|
+
if (!res.ok) {
|
|
14
|
+
const text = await res.text().catch(() => '');
|
|
15
|
+
throw new Error(`API call failed (${res.status}): ${text}`);
|
|
16
|
+
}
|
|
17
|
+
return res.json();
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAEA,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC;AAChD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE,CAAC;AAE9C,MAAM,UAAU,YAAY,CAC1B,QAAyC;IAEzC,OAAO,KAAK,EAAE,KAAa,EAAoB,EAAE;QAC/C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC,KAAK,EAAE;YAC3D,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,KAAK,EAAE;gBAChC,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;SAC5B,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,oBAAoB,GAAG,CAAC,MAAM,MAAM,IAAI,EAAE,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,GAAG,CAAC,IAAI,EAAsB,CAAC;IACxC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ZiteUser {
|
|
2
|
+
id: string;
|
|
3
|
+
email?: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
export declare function useAuth(): {
|
|
8
|
+
user: ZiteUser | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
authLoading: boolean;
|
|
11
|
+
logout: () => void;
|
|
12
|
+
};
|
|
13
|
+
export declare function getCurrentUser(): ZiteUser | null;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,wBAAgB,OAAO,IAAI;IACzB,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,CAEA;AAED,wBAAgB,cAAc,IAAI,QAAQ,GAAG,IAAI,CAEhD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,OAAO;IAMrB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface ZiteRequestContext {
|
|
2
|
+
userId?: string;
|
|
3
|
+
organizationId?: string;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
export interface ZiteScheduledContext extends ZiteRequestContext {
|
|
7
|
+
scheduledAt: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class ZiteError extends Error {
|
|
10
|
+
statusCode: number;
|
|
11
|
+
constructor(message: string, options?: {
|
|
12
|
+
statusCode?: number;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export interface EndpointConfig<TInput = unknown, TOutput = unknown> {
|
|
16
|
+
description?: string;
|
|
17
|
+
inputSchema?: unknown;
|
|
18
|
+
outputSchema?: unknown;
|
|
19
|
+
stream?: boolean;
|
|
20
|
+
_name?: string;
|
|
21
|
+
execute: (params: {
|
|
22
|
+
input: TInput;
|
|
23
|
+
context: ZiteRequestContext | ZiteScheduledContext;
|
|
24
|
+
}) => Promise<TOutput> | TOutput;
|
|
25
|
+
}
|
|
26
|
+
export declare function createEndpoint<TInput = unknown, TOutput = unknown>(config: EndpointConfig<TInput, TOutput>): EndpointConfig<TInput, TOutput>;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/backend/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAC9D,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,SAAU,SAAQ,KAAK;IAClC,UAAU,EAAE,MAAM,CAAC;gBAEP,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE;CAK/D;AAED,MAAM,WAAW,cAAc,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,CAAC,MAAM,EAAE;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,kBAAkB,GAAG,oBAAoB,CAAC;KACpD,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CAClC;AAED,wBAAgB,cAAc,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAChE,MAAM,EAAE,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,GACtC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAEjC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class ZiteError extends Error {
|
|
2
|
+
statusCode;
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = 'ZiteError';
|
|
6
|
+
this.statusCode = options?.statusCode ?? 500;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function createEndpoint(config) {
|
|
10
|
+
return config;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/backend/index.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,UAAU,CAAS;IAEnB,YAAY,OAAe,EAAE,OAAiC;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,GAAG,CAAC;IAC/C,CAAC;CACF;AAcD,MAAM,UAAU,cAAc,CAC5B,MAAuC;IAEvC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const zite: Record<string, {
|
|
2
|
+
findMany(params?: {
|
|
3
|
+
limit?: number;
|
|
4
|
+
offset?: number;
|
|
5
|
+
sort?: unknown[];
|
|
6
|
+
filter?: unknown;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
records: Record<string, unknown>[];
|
|
9
|
+
hasMore: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
findOne(id: string): Promise<Record<string, unknown>>;
|
|
12
|
+
create(data: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
13
|
+
update(id: string, data: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
14
|
+
delete(id: string): Promise<void>;
|
|
15
|
+
bulkCreate(items: Record<string, unknown>[]): Promise<Record<string, unknown>[]>;
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/db/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,EAAE,MAAM,CACvB,MAAM,EACN;IACE,QAAQ,CAAC,MAAM,CAAC,EAAE;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;QACjB,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACtE,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtD,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACxE,MAAM,CACJ,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACpC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,UAAU,CACR,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAC/B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;CACvC,CAOD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/db/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAoBb,IAAI,KAAK,CAAC,EAAW,EAAE;IACzB,GAAG;QACD,MAAM,IAAI,KAAK,CACb,uEAAuE,CACxE,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pdf/index.ts"],"names":[],"mappings":"AAAA,qBAAa,OAAO;IAClB,QAAQ,CAAC,OAAO,EAAE;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;CAGrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pdf/index.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,OAAO;IAClB,QAAQ,CAAC,OAGR;QACC,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class ZiteSchedule {
|
|
2
|
+
static create(config: {
|
|
3
|
+
name: string;
|
|
4
|
+
cron: string;
|
|
5
|
+
endpoint: string;
|
|
6
|
+
input?: Record<string, unknown>;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
id: string;
|
|
9
|
+
}>;
|
|
10
|
+
static delete(id: string): Promise<void>;
|
|
11
|
+
static list(): Promise<Array<{
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
cron: string;
|
|
15
|
+
}>>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/schedules/index.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAY;IACvB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;QACpB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACjC,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAI3B,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAG1E"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class ZiteSchedule {
|
|
2
|
+
static create(config) {
|
|
3
|
+
throw new Error('ZiteSchedule is only available in the Zite runtime.');
|
|
4
|
+
}
|
|
5
|
+
static delete(id) {
|
|
6
|
+
throw new Error('ZiteSchedule is only available in the Zite runtime.');
|
|
7
|
+
}
|
|
8
|
+
static list() {
|
|
9
|
+
throw new Error('ZiteSchedule is only available in the Zite runtime.');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/schedules/index.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,MAAM,CAAC,MAKb;QACC,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,EAAU;QACtB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,CAAC,IAAI;QACT,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sync/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync, } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { generateSchema, generateDbTs, generateDbDts, generateApiTs } from './lib.js';
|
|
5
|
+
const BASE_URL = process.env.ZITE_DB_URL ?? 'https://tables.fillout.com/api/v1';
|
|
6
|
+
const TOKEN = process.env.ZITE_DB_TOKEN ?? '';
|
|
7
|
+
async function fetchBaseMetadata(baseId) {
|
|
8
|
+
const url = `${BASE_URL}/bases/${encodeURIComponent(baseId)}`;
|
|
9
|
+
const res = await fetch(url, {
|
|
10
|
+
headers: { Authorization: `Bearer ${TOKEN}` },
|
|
11
|
+
});
|
|
12
|
+
if (!res.ok) {
|
|
13
|
+
throw new Error(`Failed to fetch base metadata (${res.status}): ${await res.text()}`);
|
|
14
|
+
}
|
|
15
|
+
return res.json();
|
|
16
|
+
}
|
|
17
|
+
async function main() {
|
|
18
|
+
if (!TOKEN) {
|
|
19
|
+
console.error('Error: ZITE_DB_TOKEN is required.');
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
let baseId = process.env.ZITE_BASE_ID;
|
|
23
|
+
if (!baseId) {
|
|
24
|
+
try {
|
|
25
|
+
const config = JSON.parse(readFileSync('zite.config.json', 'utf-8'));
|
|
26
|
+
baseId = config.project?.basePublicIdentifier;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
/* ignore */
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (!baseId) {
|
|
33
|
+
console.error('Error: Could not determine base ID.');
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
console.log(`Syncing database ${baseId}...`);
|
|
37
|
+
const base = await fetchBaseMetadata(baseId);
|
|
38
|
+
console.log(`Found ${base.tables?.length ?? 0} tables`);
|
|
39
|
+
const schema = generateSchema(base);
|
|
40
|
+
writeFileSync('zite.schema.json', JSON.stringify(schema, null, 2));
|
|
41
|
+
console.log('Wrote zite.schema.json');
|
|
42
|
+
const dbTs = generateDbTs(base, schema, baseId);
|
|
43
|
+
const dbDts = generateDbDts(base, schema);
|
|
44
|
+
const dotZite = '.zite';
|
|
45
|
+
mkdirSync(dotZite, { recursive: true });
|
|
46
|
+
writeFileSync(join(dotZite, 'db.ts'), dbTs);
|
|
47
|
+
writeFileSync(join(dotZite, 'db.d.ts'), dbDts);
|
|
48
|
+
console.log('Wrote .zite/db.ts + .zite/db.d.ts');
|
|
49
|
+
const apiDir = join('src', 'api');
|
|
50
|
+
if (existsSync(apiDir)) {
|
|
51
|
+
const endpointFiles = readdirSync(apiDir).filter((f) => f.endsWith('.ts') || f.endsWith('.js'));
|
|
52
|
+
const apiTs = generateApiTs(endpointFiles);
|
|
53
|
+
if (apiTs) {
|
|
54
|
+
writeFileSync(join(dotZite, 'api.ts'), apiTs);
|
|
55
|
+
console.log('Wrote .zite/api.ts');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
console.log('Done!');
|
|
59
|
+
}
|
|
60
|
+
main().catch((err) => {
|
|
61
|
+
console.error('Sync failed:', err.message);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
});
|
|
64
|
+
//# sourceMappingURL=index.js.map
|