zitejs 0.9.39 → 0.9.40

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.
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Zite = void 0;
4
+ const TOKEN_PREFIXES = ["sk_prod_", "fillout_token_"];
5
+ function isValidToken(token) {
6
+ return TOKEN_PREFIXES.some((prefix) => token.startsWith(prefix));
7
+ }
8
+ const ziteError = async (verb, res) => {
9
+ const ct = res.headers.get("Content-Type")?.split(";")[0];
10
+ if (ct === "application/json") {
11
+ const body = await res.json();
12
+ if (body?.error?.message)
13
+ return new Error(body.error.message);
14
+ }
15
+ return new Error(`Failed to ${verb} with status code ${res.status}`);
16
+ };
17
+ class Zite {
18
+ token;
19
+ baseUrl;
20
+ constructor(token) {
21
+ if (typeof token !== "string" || !isValidToken(token)) {
22
+ throw new Error("Invalid Zite API key. Visit https://build.fillout.com/home/settings/developer to create one.");
23
+ }
24
+ this.token = token;
25
+ this.baseUrl = "https://tables.fillout.com/api/v1";
26
+ }
27
+ request = async (method, url, verb, body) => {
28
+ const res = await fetch(this.baseUrl + url, {
29
+ method,
30
+ headers: {
31
+ Authorization: `Bearer ${this.token}`,
32
+ ...(body ? { "Content-Type": "application/json" } : {}),
33
+ },
34
+ body: body ? JSON.stringify(body) : undefined,
35
+ });
36
+ if (!res.ok)
37
+ throw await ziteError(verb, res);
38
+ const data = await res.json();
39
+ return data;
40
+ };
41
+ record = {
42
+ create: (databaseId, tableId, record) => this.request("POST", `/bases/${e(databaseId)}/tables/${e(tableId)}/records`, "create record", { record }),
43
+ bulkCreate: (databaseId, tableId, records, matchOn) => this.request("POST", `/bases/${e(databaseId)}/tables/${e(tableId)}/records/bulk`, "bulk create records", { records, matchOn }),
44
+ get: (databaseId, tableId, recordId) => this.request("GET", `/bases/${e(databaseId)}/tables/${e(tableId)}/records/${e(recordId)}`, "get record"),
45
+ update: (databaseId, tableId, recordId, record) => this.request("PATCH", `/bases/${e(databaseId)}/tables/${e(tableId)}/records/${e(recordId)}`, "update record", { record }),
46
+ bulkUpdate: (databaseId, tableId, records) => this.request("PUT", `/bases/${e(databaseId)}/tables/${e(tableId)}/records/bulk`, "bulk update records", { records }),
47
+ delete: (databaseId, tableId, recordId) => this.request("DELETE", `/bases/${e(databaseId)}/tables/${e(tableId)}/records/${e(recordId)}`, "delete record"),
48
+ list: (databaseId, tableId, options) => this.request("POST", `/bases/${e(databaseId)}/tables/${e(tableId)}/records/list`, "list records", options),
49
+ };
50
+ field = {
51
+ create: (databaseId, tableId, field) => this.request("POST", `/bases/${e(databaseId)}/tables/${e(tableId)}/fields`, "create field", field),
52
+ update: (databaseId, tableId, fieldId, field) => this.request("PATCH", `/bases/${e(databaseId)}/tables/${e(tableId)}/fields/${e(fieldId)}`, "update field", field),
53
+ delete: (databaseId, tableId, fieldId) => this.request("DELETE", `/bases/${e(databaseId)}/tables/${e(tableId)}/fields/${e(fieldId)}`, "delete field"),
54
+ };
55
+ table = {
56
+ create: (databaseId, table) => this.request("POST", `/bases/${e(databaseId)}/tables`, "create table", table),
57
+ update: (databaseId, tableId, table) => this.request("PATCH", `/bases/${e(databaseId)}/tables/${e(tableId)}`, "update table", table),
58
+ delete: (databaseId, tableId) => this.request("DELETE", `/bases/${e(databaseId)}/tables/${e(tableId)}`, "delete table"),
59
+ };
60
+ database = {
61
+ create: (database) => this.request("POST", `/bases`, "create database", database),
62
+ list: () => this.request("GET", `/bases`, "list databases"),
63
+ get: (databaseId) => this.request("GET", `/bases/${e(databaseId)}`, "get database"),
64
+ delete: (databaseId) => this.request("DELETE", `/bases/${e(databaseId)}`, "delete database"),
65
+ };
66
+ }
67
+ exports.Zite = Zite;
68
+ const e = encodeURIComponent;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Zite = void 0;
18
+ var index_js_1 = require("./client/index.js");
19
+ Object.defineProperty(exports, "Zite", { enumerable: true, get: function () { return index_js_1.Zite; } });
20
+ __exportStar(require("./types/index.js"), exports);
@@ -0,0 +1,312 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.publicFieldDefinitionSchema = exports.updatedAtTemplateSchema = exports.createdAtTemplateSchema = exports.autonumberTemplateSchema = exports.formulaTemplateSchema = exports.sourceTemplateSchema = exports.lookupTemplateSchema = exports.linkedRecordTemplateSchema = exports.percentTemplateSchema = exports.durationTemplateSchema = exports.ratingTemplateSchema = exports.phoneNumberTemplateSchema = exports.urlTemplateSchema = exports.emailTemplateSchema = exports.attachmentsTemplateSchema = exports.checkboxTemplateSchema = exports.datetimeTemplateSchema = exports.dateTemplateSchema = exports.multipleSelectTemplateSchema = exports.singleSelectTemplateSchema = exports.numberTemplateSchema = exports.richTextTemplateSchema = exports.longTextTemplateSchema = exports.singleLineTextTemplateSchema = exports.currencyTemplateSchema = exports.aiGenerationConfigSchema = exports.selectOptionSchema = exports.fieldTypeSchema = exports.fieldTypeEnum = exports.durationFormatEnum = exports.timeFormatEnum = exports.dateFormatEnum = exports.numberFormatEnum = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.numberFormatEnum = [
6
+ "local",
7
+ "comma_period",
8
+ "period_comma",
9
+ "space_comma",
10
+ "space_period",
11
+ "no_separator",
12
+ ];
13
+ exports.dateFormatEnum = ["local", "long", "us", "european", "iso"];
14
+ exports.timeFormatEnum = ["12h", "24h"];
15
+ exports.durationFormatEnum = [
16
+ "h:mm",
17
+ "h:mm:ss",
18
+ "h:mm:ss.s",
19
+ "h:mm:ss.ss",
20
+ "h:mm:ss.sss",
21
+ ];
22
+ exports.fieldTypeEnum = [
23
+ "currency",
24
+ "single_line_text",
25
+ "long_text",
26
+ "rich_text",
27
+ "number",
28
+ "single_select",
29
+ "multiple_select",
30
+ "date",
31
+ "datetime",
32
+ "checkbox",
33
+ "attachments",
34
+ "email",
35
+ "url",
36
+ "phone_number",
37
+ "rating",
38
+ "duration",
39
+ "percent",
40
+ "linked_record",
41
+ "lookup",
42
+ "source",
43
+ "formula",
44
+ "autonumber",
45
+ "created_at",
46
+ "updated_at",
47
+ ];
48
+ exports.fieldTypeSchema = zod_1.z.enum(exports.fieldTypeEnum);
49
+ exports.selectOptionSchema = zod_1.z.object({
50
+ value: zod_1.z.string(),
51
+ label: zod_1.z.string(),
52
+ color: zod_1.z.string().optional(),
53
+ });
54
+ exports.aiGenerationConfigSchema = zod_1.z.object({
55
+ enabled: zod_1.z.boolean(),
56
+ prompt: zod_1.z.string().optional(),
57
+ });
58
+ exports.currencyTemplateSchema = zod_1.z.object({
59
+ currencySymbol: zod_1.z.string().min(1),
60
+ decimalPlaces: zod_1.z.number().min(0).max(10),
61
+ numberFormat: zod_1.z.enum(exports.numberFormatEnum),
62
+ defaultValue: zod_1.z.number().nullable().optional(),
63
+ });
64
+ exports.singleLineTextTemplateSchema = zod_1.z.object({
65
+ defaultValue: zod_1.z.string().optional(),
66
+ });
67
+ exports.longTextTemplateSchema = zod_1.z.object({
68
+ defaultValue: zod_1.z.string().optional(),
69
+ });
70
+ exports.richTextTemplateSchema = zod_1.z.object({
71
+ defaultValue: zod_1.z.string().optional(),
72
+ });
73
+ exports.numberTemplateSchema = zod_1.z.object({
74
+ decimalPlaces: zod_1.z.number().min(0).max(10),
75
+ numberFormat: zod_1.z.enum(exports.numberFormatEnum),
76
+ defaultValue: zod_1.z.number().nullable().optional(),
77
+ });
78
+ exports.singleSelectTemplateSchema = zod_1.z.object({
79
+ options: zod_1.z
80
+ .array(exports.selectOptionSchema)
81
+ .nullish()
82
+ .transform((opts) => (opts ?? []).filter((o) => o.label && o.label.trim() !== "")),
83
+ disableColors: zod_1.z
84
+ .boolean()
85
+ .nullish()
86
+ .transform((v) => v ?? false),
87
+ defaultValue: zod_1.z.string().optional(),
88
+ });
89
+ exports.multipleSelectTemplateSchema = zod_1.z.object({
90
+ options: zod_1.z
91
+ .array(exports.selectOptionSchema)
92
+ .nullish()
93
+ .transform((opts) => (opts ?? []).filter((o) => o.label && o.label.trim() !== "")),
94
+ disableColors: zod_1.z
95
+ .boolean()
96
+ .nullish()
97
+ .transform((v) => v ?? false),
98
+ defaultValue: zod_1.z.array(zod_1.z.string()).optional(),
99
+ });
100
+ exports.dateTemplateSchema = zod_1.z.object({
101
+ dateFormat: zod_1.z.enum(exports.dateFormatEnum),
102
+ });
103
+ exports.datetimeTemplateSchema = zod_1.z.object({
104
+ displayTimeZone: zod_1.z
105
+ .boolean()
106
+ .nullish()
107
+ .transform((v) => v ?? false),
108
+ dateFormat: zod_1.z
109
+ .enum(exports.dateFormatEnum)
110
+ .nullish()
111
+ .transform((v) => v ?? "local"),
112
+ timeFormat: zod_1.z
113
+ .enum(exports.timeFormatEnum)
114
+ .nullish()
115
+ .transform((v) => v ?? "12h"),
116
+ timezone: zod_1.z
117
+ .string()
118
+ .nullish()
119
+ .transform((v) => v ?? ""),
120
+ });
121
+ exports.checkboxTemplateSchema = zod_1.z.object({
122
+ defaultValue: zod_1.z.boolean().optional(),
123
+ });
124
+ exports.attachmentsTemplateSchema = zod_1.z.object({});
125
+ exports.emailTemplateSchema = zod_1.z.object({});
126
+ exports.urlTemplateSchema = zod_1.z.object({});
127
+ exports.phoneNumberTemplateSchema = zod_1.z.object({});
128
+ exports.ratingTemplateSchema = zod_1.z.object({
129
+ maxRating: zod_1.z.number().min(1).max(10),
130
+ defaultValue: zod_1.z.number().min(0).max(10).optional(),
131
+ });
132
+ exports.durationTemplateSchema = zod_1.z.object({
133
+ format: zod_1.z.enum(exports.durationFormatEnum),
134
+ defaultValue: zod_1.z.number().int().min(0).optional(),
135
+ });
136
+ exports.percentTemplateSchema = zod_1.z.object({
137
+ decimalPlaces: zod_1.z.number().min(0),
138
+ numberFormat: zod_1.z.enum(exports.numberFormatEnum),
139
+ showProgressBar: zod_1.z.boolean(),
140
+ allowNegative: zod_1.z.boolean(),
141
+ defaultValue: zod_1.z.number().nullable().optional(),
142
+ });
143
+ exports.linkedRecordTemplateSchema = zod_1.z.object({
144
+ tableId: zod_1.z.string(),
145
+ allowMultiple: zod_1.z.boolean().optional(),
146
+ });
147
+ exports.lookupTemplateSchema = zod_1.z.object({
148
+ linkedRecordFieldId: zod_1.z.string().min(1),
149
+ lookupFieldId: zod_1.z.string().min(1),
150
+ formulaExpression: zod_1.z.string().optional(),
151
+ resultType: zod_1.z
152
+ .enum(["text", "number", "date", "boolean", "array"])
153
+ .optional(),
154
+ });
155
+ exports.sourceTemplateSchema = zod_1.z.object({});
156
+ const formulaFormattingSchema = zod_1.z
157
+ .object({
158
+ numberDisplayType: zod_1.z
159
+ .enum(["number", "currency", "percent", "duration"])
160
+ .optional(),
161
+ currencyCode: zod_1.z.string().optional(),
162
+ decimalPlaces: zod_1.z.number().min(0).max(10).optional(),
163
+ numberFormat: zod_1.z
164
+ .enum(["local", "comma_period", "period_comma", "space_comma", "space_period"])
165
+ .optional(),
166
+ })
167
+ .optional();
168
+ exports.formulaTemplateSchema = zod_1.z.object({
169
+ expression: zod_1.z.string().min(1),
170
+ resultType: zod_1.z
171
+ .enum(["text", "number", "date", "boolean", "array"])
172
+ .optional(),
173
+ formatting: formulaFormattingSchema,
174
+ });
175
+ exports.autonumberTemplateSchema = zod_1.z.object({});
176
+ exports.createdAtTemplateSchema = zod_1.z.object({
177
+ displayTimeZone: zod_1.z
178
+ .boolean()
179
+ .nullish()
180
+ .transform((v) => v ?? false),
181
+ dateFormat: zod_1.z
182
+ .enum(exports.dateFormatEnum)
183
+ .nullish()
184
+ .transform((v) => v ?? "local"),
185
+ timeFormat: zod_1.z
186
+ .enum(exports.timeFormatEnum)
187
+ .nullish()
188
+ .transform((v) => v ?? "12h"),
189
+ timezone: zod_1.z
190
+ .string()
191
+ .nullish()
192
+ .transform((v) => v ?? ""),
193
+ });
194
+ exports.updatedAtTemplateSchema = zod_1.z.object({
195
+ displayTimeZone: zod_1.z
196
+ .boolean()
197
+ .nullish()
198
+ .transform((v) => v ?? false),
199
+ dateFormat: zod_1.z
200
+ .enum(exports.dateFormatEnum)
201
+ .nullish()
202
+ .transform((v) => v ?? "local"),
203
+ timeFormat: zod_1.z
204
+ .enum(exports.timeFormatEnum)
205
+ .nullish()
206
+ .transform((v) => v ?? "12h"),
207
+ timezone: zod_1.z
208
+ .string()
209
+ .nullish()
210
+ .transform((v) => v ?? ""),
211
+ });
212
+ const basePublicFieldSchema = zod_1.z.object({
213
+ name: zod_1.z.string(),
214
+ });
215
+ exports.publicFieldDefinitionSchema = zod_1.z.discriminatedUnion("type", [
216
+ basePublicFieldSchema.extend({
217
+ type: zod_1.z.literal("currency"),
218
+ template: exports.currencyTemplateSchema,
219
+ }),
220
+ basePublicFieldSchema.extend({
221
+ type: zod_1.z.literal("single_line_text"),
222
+ template: exports.singleLineTextTemplateSchema,
223
+ }),
224
+ basePublicFieldSchema.extend({
225
+ type: zod_1.z.literal("long_text"),
226
+ template: exports.longTextTemplateSchema,
227
+ }),
228
+ basePublicFieldSchema.extend({
229
+ type: zod_1.z.literal("rich_text"),
230
+ template: exports.richTextTemplateSchema,
231
+ }),
232
+ basePublicFieldSchema.extend({
233
+ type: zod_1.z.literal("number"),
234
+ template: exports.numberTemplateSchema,
235
+ }),
236
+ basePublicFieldSchema.extend({
237
+ type: zod_1.z.literal("single_select"),
238
+ template: exports.singleSelectTemplateSchema,
239
+ }),
240
+ basePublicFieldSchema.extend({
241
+ type: zod_1.z.literal("multiple_select"),
242
+ template: exports.multipleSelectTemplateSchema,
243
+ }),
244
+ basePublicFieldSchema.extend({
245
+ type: zod_1.z.literal("date"),
246
+ template: exports.dateTemplateSchema,
247
+ }),
248
+ basePublicFieldSchema.extend({
249
+ type: zod_1.z.literal("datetime"),
250
+ template: exports.datetimeTemplateSchema,
251
+ }),
252
+ basePublicFieldSchema.extend({
253
+ type: zod_1.z.literal("checkbox"),
254
+ template: exports.checkboxTemplateSchema,
255
+ }),
256
+ basePublicFieldSchema.extend({
257
+ type: zod_1.z.literal("attachments"),
258
+ template: exports.attachmentsTemplateSchema,
259
+ }),
260
+ basePublicFieldSchema.extend({
261
+ type: zod_1.z.literal("email"),
262
+ template: exports.emailTemplateSchema,
263
+ }),
264
+ basePublicFieldSchema.extend({
265
+ type: zod_1.z.literal("url"),
266
+ template: exports.urlTemplateSchema,
267
+ }),
268
+ basePublicFieldSchema.extend({
269
+ type: zod_1.z.literal("phone_number"),
270
+ template: exports.phoneNumberTemplateSchema,
271
+ }),
272
+ basePublicFieldSchema.extend({
273
+ type: zod_1.z.literal("rating"),
274
+ template: exports.ratingTemplateSchema,
275
+ }),
276
+ basePublicFieldSchema.extend({
277
+ type: zod_1.z.literal("duration"),
278
+ template: exports.durationTemplateSchema,
279
+ }),
280
+ basePublicFieldSchema.extend({
281
+ type: zod_1.z.literal("percent"),
282
+ template: exports.percentTemplateSchema,
283
+ }),
284
+ basePublicFieldSchema.extend({
285
+ type: zod_1.z.literal("linked_record"),
286
+ template: exports.linkedRecordTemplateSchema,
287
+ }),
288
+ basePublicFieldSchema.extend({
289
+ type: zod_1.z.literal("lookup"),
290
+ template: exports.lookupTemplateSchema,
291
+ }),
292
+ basePublicFieldSchema.extend({
293
+ type: zod_1.z.literal("source"),
294
+ template: exports.sourceTemplateSchema,
295
+ }),
296
+ basePublicFieldSchema.extend({
297
+ type: zod_1.z.literal("formula"),
298
+ template: exports.formulaTemplateSchema,
299
+ }),
300
+ basePublicFieldSchema.extend({
301
+ type: zod_1.z.literal("autonumber"),
302
+ template: exports.autonumberTemplateSchema,
303
+ }),
304
+ basePublicFieldSchema.extend({
305
+ type: zod_1.z.literal("created_at"),
306
+ template: exports.createdAtTemplateSchema,
307
+ }),
308
+ basePublicFieldSchema.extend({
309
+ type: zod_1.z.literal("updated_at"),
310
+ template: exports.updatedAtTemplateSchema,
311
+ }),
312
+ ]);
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./fields.js"), exports);
18
+ __exportStar(require("./tables.js"), exports);
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.databaseSchema = exports.publicTableDefinitionSchema = exports.tableSchema = exports.viewSchema = exports.fieldSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const fields_js_1 = require("./fields.js");
6
+ exports.fieldSchema = zod_1.z
7
+ .object({
8
+ id: zod_1.z.string(),
9
+ order: zod_1.z.number(),
10
+ })
11
+ .and(fields_js_1.publicFieldDefinitionSchema);
12
+ exports.viewSchema = zod_1.z.object({
13
+ id: zod_1.z.string(),
14
+ name: zod_1.z.string(),
15
+ type: zod_1.z.string(),
16
+ config: zod_1.z.unknown(),
17
+ });
18
+ exports.tableSchema = zod_1.z.object({
19
+ id: zod_1.z.string(),
20
+ name: zod_1.z.string(),
21
+ order: zod_1.z.number(),
22
+ primaryFieldId: zod_1.z.string(),
23
+ fields: zod_1.z.array(exports.fieldSchema),
24
+ views: zod_1.z.array(exports.viewSchema),
25
+ url: zod_1.z.string(),
26
+ });
27
+ exports.publicTableDefinitionSchema = zod_1.z.object({
28
+ name: zod_1.z.string(),
29
+ fields: zod_1.z.array(fields_js_1.publicFieldDefinitionSchema),
30
+ });
31
+ exports.databaseSchema = zod_1.z.object({
32
+ id: zod_1.z.string(),
33
+ name: zod_1.z.string(),
34
+ tables: zod_1.z.array(exports.tableSchema),
35
+ createdAt: zod_1.z.string(),
36
+ updatedAt: zod_1.z.string(),
37
+ url: zod_1.z.string(),
38
+ workspaceId: zod_1.z.string().optional(),
39
+ });