zitejs 0.9.54 → 0.9.56
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/client/index.d.ts +204 -0
- 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/types/fields.d.ts +120 -1
- package/dist/cjs/types/fields.js +50 -1
- package/dist/cjs/types/tables.d.ts +244 -0
- 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/client/index.d.ts +204 -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/types/fields.d.ts +120 -1
- package/dist/esm/types/fields.js +49 -0
- package/dist/esm/types/tables.d.ts +244 -0
- 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
|
@@ -202,6 +202,67 @@ export declare const fieldSchema: z.ZodIntersection<z.ZodObject<{
|
|
|
202
202
|
text: "text";
|
|
203
203
|
}>>;
|
|
204
204
|
}, z.core.$strip>;
|
|
205
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
206
|
+
name: z.ZodString;
|
|
207
|
+
type: z.ZodLiteral<"rollup">;
|
|
208
|
+
template: z.ZodObject<{
|
|
209
|
+
linkedRecordFieldId: z.ZodString;
|
|
210
|
+
rollupFieldId: z.ZodString;
|
|
211
|
+
aggregationFormula: z.ZodString;
|
|
212
|
+
formulaExpression: z.ZodOptional<z.ZodString>;
|
|
213
|
+
formatting: z.ZodOptional<z.ZodObject<{
|
|
214
|
+
numberDisplayType: z.ZodOptional<z.ZodEnum<{
|
|
215
|
+
number: "number";
|
|
216
|
+
currency: "currency";
|
|
217
|
+
duration: "duration";
|
|
218
|
+
percent: "percent";
|
|
219
|
+
}>>;
|
|
220
|
+
currencyCode: z.ZodOptional<z.ZodString>;
|
|
221
|
+
decimalPlaces: z.ZodOptional<z.ZodNumber>;
|
|
222
|
+
numberFormat: z.ZodOptional<z.ZodEnum<{
|
|
223
|
+
local: "local";
|
|
224
|
+
comma_period: "comma_period";
|
|
225
|
+
period_comma: "period_comma";
|
|
226
|
+
space_comma: "space_comma";
|
|
227
|
+
space_period: "space_period";
|
|
228
|
+
no_separator: "no_separator";
|
|
229
|
+
}>>;
|
|
230
|
+
displayTimeZone: z.ZodOptional<z.ZodBoolean>;
|
|
231
|
+
dateFormat: z.ZodOptional<z.ZodEnum<{
|
|
232
|
+
local: "local";
|
|
233
|
+
long: "long";
|
|
234
|
+
us: "us";
|
|
235
|
+
european: "european";
|
|
236
|
+
iso: "iso";
|
|
237
|
+
}>>;
|
|
238
|
+
timeFormat: z.ZodOptional<z.ZodEnum<{
|
|
239
|
+
"12h": "12h";
|
|
240
|
+
"24h": "24h";
|
|
241
|
+
}>>;
|
|
242
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
243
|
+
trueDisplay: z.ZodOptional<z.ZodString>;
|
|
244
|
+
falseDisplay: z.ZodOptional<z.ZodString>;
|
|
245
|
+
}, z.core.$strip>>;
|
|
246
|
+
filterEnabled: z.ZodOptional<z.ZodBoolean>;
|
|
247
|
+
sortEnabled: z.ZodOptional<z.ZodBoolean>;
|
|
248
|
+
resultType: z.ZodOptional<z.ZodEnum<{
|
|
249
|
+
number: "number";
|
|
250
|
+
boolean: "boolean";
|
|
251
|
+
date: "date";
|
|
252
|
+
array: "array";
|
|
253
|
+
text: "text";
|
|
254
|
+
}>>;
|
|
255
|
+
}, z.core.$strip>;
|
|
256
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
257
|
+
name: z.ZodString;
|
|
258
|
+
type: z.ZodLiteral<"updated_by">;
|
|
259
|
+
template: z.ZodObject<{}, z.core.$strip>;
|
|
260
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
261
|
+
name: z.ZodString;
|
|
262
|
+
type: z.ZodLiteral<"user">;
|
|
263
|
+
template: z.ZodObject<{
|
|
264
|
+
allowMultiple: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>, z.ZodTransform<boolean, boolean | null | undefined>>;
|
|
265
|
+
}, z.core.$strip>;
|
|
205
266
|
}, z.core.$strip>, z.ZodObject<{
|
|
206
267
|
name: z.ZodString;
|
|
207
268
|
type: z.ZodLiteral<"source">;
|
|
@@ -493,6 +554,67 @@ export declare const tableSchema: z.ZodObject<{
|
|
|
493
554
|
text: "text";
|
|
494
555
|
}>>;
|
|
495
556
|
}, z.core.$strip>;
|
|
557
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
558
|
+
name: z.ZodString;
|
|
559
|
+
type: z.ZodLiteral<"rollup">;
|
|
560
|
+
template: z.ZodObject<{
|
|
561
|
+
linkedRecordFieldId: z.ZodString;
|
|
562
|
+
rollupFieldId: z.ZodString;
|
|
563
|
+
aggregationFormula: z.ZodString;
|
|
564
|
+
formulaExpression: z.ZodOptional<z.ZodString>;
|
|
565
|
+
formatting: z.ZodOptional<z.ZodObject<{
|
|
566
|
+
numberDisplayType: z.ZodOptional<z.ZodEnum<{
|
|
567
|
+
number: "number";
|
|
568
|
+
currency: "currency";
|
|
569
|
+
duration: "duration";
|
|
570
|
+
percent: "percent";
|
|
571
|
+
}>>;
|
|
572
|
+
currencyCode: z.ZodOptional<z.ZodString>;
|
|
573
|
+
decimalPlaces: z.ZodOptional<z.ZodNumber>;
|
|
574
|
+
numberFormat: z.ZodOptional<z.ZodEnum<{
|
|
575
|
+
local: "local";
|
|
576
|
+
comma_period: "comma_period";
|
|
577
|
+
period_comma: "period_comma";
|
|
578
|
+
space_comma: "space_comma";
|
|
579
|
+
space_period: "space_period";
|
|
580
|
+
no_separator: "no_separator";
|
|
581
|
+
}>>;
|
|
582
|
+
displayTimeZone: z.ZodOptional<z.ZodBoolean>;
|
|
583
|
+
dateFormat: z.ZodOptional<z.ZodEnum<{
|
|
584
|
+
local: "local";
|
|
585
|
+
long: "long";
|
|
586
|
+
us: "us";
|
|
587
|
+
european: "european";
|
|
588
|
+
iso: "iso";
|
|
589
|
+
}>>;
|
|
590
|
+
timeFormat: z.ZodOptional<z.ZodEnum<{
|
|
591
|
+
"12h": "12h";
|
|
592
|
+
"24h": "24h";
|
|
593
|
+
}>>;
|
|
594
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
595
|
+
trueDisplay: z.ZodOptional<z.ZodString>;
|
|
596
|
+
falseDisplay: z.ZodOptional<z.ZodString>;
|
|
597
|
+
}, z.core.$strip>>;
|
|
598
|
+
filterEnabled: z.ZodOptional<z.ZodBoolean>;
|
|
599
|
+
sortEnabled: z.ZodOptional<z.ZodBoolean>;
|
|
600
|
+
resultType: z.ZodOptional<z.ZodEnum<{
|
|
601
|
+
number: "number";
|
|
602
|
+
boolean: "boolean";
|
|
603
|
+
date: "date";
|
|
604
|
+
array: "array";
|
|
605
|
+
text: "text";
|
|
606
|
+
}>>;
|
|
607
|
+
}, z.core.$strip>;
|
|
608
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
609
|
+
name: z.ZodString;
|
|
610
|
+
type: z.ZodLiteral<"updated_by">;
|
|
611
|
+
template: z.ZodObject<{}, z.core.$strip>;
|
|
612
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
613
|
+
name: z.ZodString;
|
|
614
|
+
type: z.ZodLiteral<"user">;
|
|
615
|
+
template: z.ZodObject<{
|
|
616
|
+
allowMultiple: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>, z.ZodTransform<boolean, boolean | null | undefined>>;
|
|
617
|
+
}, z.core.$strip>;
|
|
496
618
|
}, z.core.$strip>, z.ZodObject<{
|
|
497
619
|
name: z.ZodString;
|
|
498
620
|
type: z.ZodLiteral<"source">;
|
|
@@ -779,6 +901,67 @@ export declare const publicTableDefinitionSchema: z.ZodObject<{
|
|
|
779
901
|
text: "text";
|
|
780
902
|
}>>;
|
|
781
903
|
}, z.core.$strip>;
|
|
904
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
905
|
+
name: z.ZodString;
|
|
906
|
+
type: z.ZodLiteral<"rollup">;
|
|
907
|
+
template: z.ZodObject<{
|
|
908
|
+
linkedRecordFieldId: z.ZodString;
|
|
909
|
+
rollupFieldId: z.ZodString;
|
|
910
|
+
aggregationFormula: z.ZodString;
|
|
911
|
+
formulaExpression: z.ZodOptional<z.ZodString>;
|
|
912
|
+
formatting: z.ZodOptional<z.ZodObject<{
|
|
913
|
+
numberDisplayType: z.ZodOptional<z.ZodEnum<{
|
|
914
|
+
number: "number";
|
|
915
|
+
currency: "currency";
|
|
916
|
+
duration: "duration";
|
|
917
|
+
percent: "percent";
|
|
918
|
+
}>>;
|
|
919
|
+
currencyCode: z.ZodOptional<z.ZodString>;
|
|
920
|
+
decimalPlaces: z.ZodOptional<z.ZodNumber>;
|
|
921
|
+
numberFormat: z.ZodOptional<z.ZodEnum<{
|
|
922
|
+
local: "local";
|
|
923
|
+
comma_period: "comma_period";
|
|
924
|
+
period_comma: "period_comma";
|
|
925
|
+
space_comma: "space_comma";
|
|
926
|
+
space_period: "space_period";
|
|
927
|
+
no_separator: "no_separator";
|
|
928
|
+
}>>;
|
|
929
|
+
displayTimeZone: z.ZodOptional<z.ZodBoolean>;
|
|
930
|
+
dateFormat: z.ZodOptional<z.ZodEnum<{
|
|
931
|
+
local: "local";
|
|
932
|
+
long: "long";
|
|
933
|
+
us: "us";
|
|
934
|
+
european: "european";
|
|
935
|
+
iso: "iso";
|
|
936
|
+
}>>;
|
|
937
|
+
timeFormat: z.ZodOptional<z.ZodEnum<{
|
|
938
|
+
"12h": "12h";
|
|
939
|
+
"24h": "24h";
|
|
940
|
+
}>>;
|
|
941
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
942
|
+
trueDisplay: z.ZodOptional<z.ZodString>;
|
|
943
|
+
falseDisplay: z.ZodOptional<z.ZodString>;
|
|
944
|
+
}, z.core.$strip>>;
|
|
945
|
+
filterEnabled: z.ZodOptional<z.ZodBoolean>;
|
|
946
|
+
sortEnabled: z.ZodOptional<z.ZodBoolean>;
|
|
947
|
+
resultType: z.ZodOptional<z.ZodEnum<{
|
|
948
|
+
number: "number";
|
|
949
|
+
boolean: "boolean";
|
|
950
|
+
date: "date";
|
|
951
|
+
array: "array";
|
|
952
|
+
text: "text";
|
|
953
|
+
}>>;
|
|
954
|
+
}, z.core.$strip>;
|
|
955
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
956
|
+
name: z.ZodString;
|
|
957
|
+
type: z.ZodLiteral<"updated_by">;
|
|
958
|
+
template: z.ZodObject<{}, z.core.$strip>;
|
|
959
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
960
|
+
name: z.ZodString;
|
|
961
|
+
type: z.ZodLiteral<"user">;
|
|
962
|
+
template: z.ZodObject<{
|
|
963
|
+
allowMultiple: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>, z.ZodTransform<boolean, boolean | null | undefined>>;
|
|
964
|
+
}, z.core.$strip>;
|
|
782
965
|
}, z.core.$strip>, z.ZodObject<{
|
|
783
966
|
name: z.ZodString;
|
|
784
967
|
type: z.ZodLiteral<"source">;
|
|
@@ -1067,6 +1250,67 @@ export declare const databaseSchema: z.ZodObject<{
|
|
|
1067
1250
|
text: "text";
|
|
1068
1251
|
}>>;
|
|
1069
1252
|
}, z.core.$strip>;
|
|
1253
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1254
|
+
name: z.ZodString;
|
|
1255
|
+
type: z.ZodLiteral<"rollup">;
|
|
1256
|
+
template: z.ZodObject<{
|
|
1257
|
+
linkedRecordFieldId: z.ZodString;
|
|
1258
|
+
rollupFieldId: z.ZodString;
|
|
1259
|
+
aggregationFormula: z.ZodString;
|
|
1260
|
+
formulaExpression: z.ZodOptional<z.ZodString>;
|
|
1261
|
+
formatting: z.ZodOptional<z.ZodObject<{
|
|
1262
|
+
numberDisplayType: z.ZodOptional<z.ZodEnum<{
|
|
1263
|
+
number: "number";
|
|
1264
|
+
currency: "currency";
|
|
1265
|
+
duration: "duration";
|
|
1266
|
+
percent: "percent";
|
|
1267
|
+
}>>;
|
|
1268
|
+
currencyCode: z.ZodOptional<z.ZodString>;
|
|
1269
|
+
decimalPlaces: z.ZodOptional<z.ZodNumber>;
|
|
1270
|
+
numberFormat: z.ZodOptional<z.ZodEnum<{
|
|
1271
|
+
local: "local";
|
|
1272
|
+
comma_period: "comma_period";
|
|
1273
|
+
period_comma: "period_comma";
|
|
1274
|
+
space_comma: "space_comma";
|
|
1275
|
+
space_period: "space_period";
|
|
1276
|
+
no_separator: "no_separator";
|
|
1277
|
+
}>>;
|
|
1278
|
+
displayTimeZone: z.ZodOptional<z.ZodBoolean>;
|
|
1279
|
+
dateFormat: z.ZodOptional<z.ZodEnum<{
|
|
1280
|
+
local: "local";
|
|
1281
|
+
long: "long";
|
|
1282
|
+
us: "us";
|
|
1283
|
+
european: "european";
|
|
1284
|
+
iso: "iso";
|
|
1285
|
+
}>>;
|
|
1286
|
+
timeFormat: z.ZodOptional<z.ZodEnum<{
|
|
1287
|
+
"12h": "12h";
|
|
1288
|
+
"24h": "24h";
|
|
1289
|
+
}>>;
|
|
1290
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
1291
|
+
trueDisplay: z.ZodOptional<z.ZodString>;
|
|
1292
|
+
falseDisplay: z.ZodOptional<z.ZodString>;
|
|
1293
|
+
}, z.core.$strip>>;
|
|
1294
|
+
filterEnabled: z.ZodOptional<z.ZodBoolean>;
|
|
1295
|
+
sortEnabled: z.ZodOptional<z.ZodBoolean>;
|
|
1296
|
+
resultType: z.ZodOptional<z.ZodEnum<{
|
|
1297
|
+
number: "number";
|
|
1298
|
+
boolean: "boolean";
|
|
1299
|
+
date: "date";
|
|
1300
|
+
array: "array";
|
|
1301
|
+
text: "text";
|
|
1302
|
+
}>>;
|
|
1303
|
+
}, z.core.$strip>;
|
|
1304
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1305
|
+
name: z.ZodString;
|
|
1306
|
+
type: z.ZodLiteral<"updated_by">;
|
|
1307
|
+
template: z.ZodObject<{}, z.core.$strip>;
|
|
1308
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1309
|
+
name: z.ZodString;
|
|
1310
|
+
type: z.ZodLiteral<"user">;
|
|
1311
|
+
template: z.ZodObject<{
|
|
1312
|
+
allowMultiple: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>, z.ZodTransform<boolean, boolean | null | undefined>>;
|
|
1313
|
+
}, z.core.$strip>;
|
|
1070
1314
|
}, z.core.$strip>, z.ZodObject<{
|
|
1071
1315
|
name: z.ZodString;
|
|
1072
1316
|
type: z.ZodLiteral<"source">;
|
|
@@ -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';
|