krisspy-sdk 0.5.1 → 0.5.2
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/index.js +127 -94
- package/dist/index.mjs +130 -94
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
|
|
1
21
|
// src/http.ts
|
|
2
22
|
var HttpClient = class {
|
|
3
23
|
constructor(options) {
|
|
24
|
+
var _a;
|
|
4
25
|
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
5
|
-
this.headers = {
|
|
6
|
-
"Content-Type": "application/json"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.debug = options.debug ?? false;
|
|
26
|
+
this.headers = __spreadValues({
|
|
27
|
+
"Content-Type": "application/json"
|
|
28
|
+
}, options.headers);
|
|
29
|
+
this.debug = (_a = options.debug) != null ? _a : false;
|
|
10
30
|
}
|
|
11
31
|
/**
|
|
12
32
|
* Set authorization header
|
|
@@ -24,7 +44,7 @@ var HttpClient = class {
|
|
|
24
44
|
* Update headers
|
|
25
45
|
*/
|
|
26
46
|
setHeaders(headers) {
|
|
27
|
-
this.headers = {
|
|
47
|
+
this.headers = __spreadValues(__spreadValues({}, this.headers), headers);
|
|
28
48
|
}
|
|
29
49
|
/**
|
|
30
50
|
* Build query string from params
|
|
@@ -45,14 +65,11 @@ var HttpClient = class {
|
|
|
45
65
|
* Make HTTP request
|
|
46
66
|
*/
|
|
47
67
|
async request(method, path, options) {
|
|
48
|
-
const url = `${this.baseUrl}${path}${options
|
|
49
|
-
const requestHeaders = {
|
|
50
|
-
...this.headers,
|
|
51
|
-
...options?.headers
|
|
52
|
-
};
|
|
68
|
+
const url = `${this.baseUrl}${path}${(options == null ? void 0 : options.params) ? this.buildQueryString(options.params) : ""}`;
|
|
69
|
+
const requestHeaders = __spreadValues(__spreadValues({}, this.headers), options == null ? void 0 : options.headers);
|
|
53
70
|
if (this.debug) {
|
|
54
71
|
console.log(`[Krisspy SDK] ${method} ${url}`);
|
|
55
|
-
if (options
|
|
72
|
+
if (options == null ? void 0 : options.body) {
|
|
56
73
|
console.log("[Krisspy SDK] Body:", JSON.stringify(options.body, null, 2));
|
|
57
74
|
}
|
|
58
75
|
}
|
|
@@ -60,11 +77,11 @@ var HttpClient = class {
|
|
|
60
77
|
const response = await fetch(url, {
|
|
61
78
|
method,
|
|
62
79
|
headers: requestHeaders,
|
|
63
|
-
body: options
|
|
80
|
+
body: (options == null ? void 0 : options.body) ? JSON.stringify(options.body) : void 0
|
|
64
81
|
});
|
|
65
82
|
const contentType = response.headers.get("content-type");
|
|
66
83
|
let data = null;
|
|
67
|
-
if (contentType
|
|
84
|
+
if (contentType == null ? void 0 : contentType.includes("application/json")) {
|
|
68
85
|
data = await response.json();
|
|
69
86
|
} else {
|
|
70
87
|
data = await response.text();
|
|
@@ -74,10 +91,10 @@ var HttpClient = class {
|
|
|
74
91
|
}
|
|
75
92
|
if (!response.ok) {
|
|
76
93
|
const error = {
|
|
77
|
-
message: data
|
|
78
|
-
code: data
|
|
79
|
-
details: data
|
|
80
|
-
hint: data
|
|
94
|
+
message: (data == null ? void 0 : data.error) || (data == null ? void 0 : data.message) || "Request failed",
|
|
95
|
+
code: data == null ? void 0 : data.code,
|
|
96
|
+
details: data == null ? void 0 : data.details,
|
|
97
|
+
hint: data == null ? void 0 : data.hint,
|
|
81
98
|
status: response.status
|
|
82
99
|
};
|
|
83
100
|
return { data: null, error, status: response.status };
|
|
@@ -141,7 +158,7 @@ function getLocalStorage() {
|
|
|
141
158
|
window.localStorage.setItem(testKey, "1");
|
|
142
159
|
window.localStorage.removeItem(testKey);
|
|
143
160
|
return window.localStorage;
|
|
144
|
-
} catch {
|
|
161
|
+
} catch (e) {
|
|
145
162
|
return null;
|
|
146
163
|
}
|
|
147
164
|
}
|
|
@@ -150,7 +167,8 @@ var MemoryStorage = class {
|
|
|
150
167
|
this.store = /* @__PURE__ */ new Map();
|
|
151
168
|
}
|
|
152
169
|
getItem(key) {
|
|
153
|
-
|
|
170
|
+
var _a;
|
|
171
|
+
return (_a = this.store.get(key)) != null ? _a : null;
|
|
154
172
|
}
|
|
155
173
|
setItem(key, value) {
|
|
156
174
|
this.store.set(key, value);
|
|
@@ -160,8 +178,9 @@ var MemoryStorage = class {
|
|
|
160
178
|
}
|
|
161
179
|
};
|
|
162
180
|
function resolveStorage(custom) {
|
|
181
|
+
var _a;
|
|
163
182
|
if (custom) return custom;
|
|
164
|
-
return getLocalStorage()
|
|
183
|
+
return (_a = getLocalStorage()) != null ? _a : new MemoryStorage();
|
|
165
184
|
}
|
|
166
185
|
function base64Encode(input) {
|
|
167
186
|
if (typeof btoa === "function") {
|
|
@@ -248,7 +267,7 @@ var KrisspyAuth = class {
|
|
|
248
267
|
return;
|
|
249
268
|
}
|
|
250
269
|
this.setSession(session);
|
|
251
|
-
} catch {
|
|
270
|
+
} catch (e) {
|
|
252
271
|
}
|
|
253
272
|
}
|
|
254
273
|
/**
|
|
@@ -274,7 +293,7 @@ var KrisspyAuth = class {
|
|
|
274
293
|
}
|
|
275
294
|
try {
|
|
276
295
|
this.storage.removeItem(`${STORAGE_KEY}-${this.backendId}`);
|
|
277
|
-
} catch {
|
|
296
|
+
} catch (e) {
|
|
278
297
|
}
|
|
279
298
|
}
|
|
280
299
|
/**
|
|
@@ -319,6 +338,7 @@ var KrisspyAuth = class {
|
|
|
319
338
|
* Sign up with email and password
|
|
320
339
|
*/
|
|
321
340
|
async signUp(credentials) {
|
|
341
|
+
var _a, _b, _c, _d, _e;
|
|
322
342
|
const path = `/api/v1/cloud-backends/${this.backendId}/auth/signup`;
|
|
323
343
|
const response = await this.http.post(path, {
|
|
324
344
|
email: credentials.email,
|
|
@@ -331,13 +351,13 @@ var KrisspyAuth = class {
|
|
|
331
351
|
error: response.error
|
|
332
352
|
};
|
|
333
353
|
}
|
|
334
|
-
if (response.data
|
|
354
|
+
if ((_a = response.data) == null ? void 0 : _a.session) {
|
|
335
355
|
this.setSession(response.data.session);
|
|
336
356
|
}
|
|
337
357
|
return {
|
|
338
358
|
data: {
|
|
339
|
-
user: response.data
|
|
340
|
-
session: response.data
|
|
359
|
+
user: (_c = (_b = response.data) == null ? void 0 : _b.user) != null ? _c : null,
|
|
360
|
+
session: (_e = (_d = response.data) == null ? void 0 : _d.session) != null ? _e : null
|
|
341
361
|
},
|
|
342
362
|
error: null
|
|
343
363
|
};
|
|
@@ -346,6 +366,7 @@ var KrisspyAuth = class {
|
|
|
346
366
|
* Sign in with email and password
|
|
347
367
|
*/
|
|
348
368
|
async signInWithPassword(credentials) {
|
|
369
|
+
var _a, _b, _c, _d, _e;
|
|
349
370
|
const path = `/api/v1/cloud-backends/${this.backendId}/auth/login`;
|
|
350
371
|
const response = await this.http.post(path, {
|
|
351
372
|
email: credentials.email,
|
|
@@ -357,13 +378,13 @@ var KrisspyAuth = class {
|
|
|
357
378
|
error: response.error
|
|
358
379
|
};
|
|
359
380
|
}
|
|
360
|
-
if (response.data
|
|
381
|
+
if ((_a = response.data) == null ? void 0 : _a.session) {
|
|
361
382
|
this.setSession(response.data.session);
|
|
362
383
|
}
|
|
363
384
|
return {
|
|
364
385
|
data: {
|
|
365
|
-
user: response.data
|
|
366
|
-
session: response.data
|
|
386
|
+
user: (_c = (_b = response.data) == null ? void 0 : _b.user) != null ? _c : null,
|
|
387
|
+
session: (_e = (_d = response.data) == null ? void 0 : _d.session) != null ? _e : null
|
|
367
388
|
},
|
|
368
389
|
error: null
|
|
369
390
|
};
|
|
@@ -372,6 +393,7 @@ var KrisspyAuth = class {
|
|
|
372
393
|
* Sign in with OAuth provider
|
|
373
394
|
*/
|
|
374
395
|
async signInWithOAuth(options) {
|
|
396
|
+
var _a;
|
|
375
397
|
const path = `/api/v1/cloud-backends/${this.backendId}/auth/oauth/${options.provider}`;
|
|
376
398
|
const response = await this.http.post(path, {
|
|
377
399
|
redirect_to: options.redirectTo
|
|
@@ -379,7 +401,7 @@ var KrisspyAuth = class {
|
|
|
379
401
|
if (response.error) {
|
|
380
402
|
return { data: null, error: response.error };
|
|
381
403
|
}
|
|
382
|
-
if (isBrowser() && response.data
|
|
404
|
+
if (isBrowser() && ((_a = response.data) == null ? void 0 : _a.url)) {
|
|
383
405
|
window.location.href = response.data.url;
|
|
384
406
|
}
|
|
385
407
|
return { data: response.data, error: null };
|
|
@@ -398,7 +420,8 @@ var KrisspyAuth = class {
|
|
|
398
420
|
* Refresh the session token
|
|
399
421
|
*/
|
|
400
422
|
async refreshSession() {
|
|
401
|
-
|
|
423
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
424
|
+
if (!((_a = this.currentSession) == null ? void 0 : _a.refresh_token)) {
|
|
402
425
|
return {
|
|
403
426
|
data: { user: null, session: null },
|
|
404
427
|
error: { message: "No refresh token available" }
|
|
@@ -416,13 +439,13 @@ var KrisspyAuth = class {
|
|
|
416
439
|
error: response.error
|
|
417
440
|
};
|
|
418
441
|
}
|
|
419
|
-
if (response.data
|
|
442
|
+
if ((_b = response.data) == null ? void 0 : _b.session) {
|
|
420
443
|
this.setSession(response.data.session);
|
|
421
444
|
}
|
|
422
445
|
return {
|
|
423
446
|
data: {
|
|
424
|
-
user: response.data
|
|
425
|
-
session: response.data
|
|
447
|
+
user: (_e = (_d = (_c = response.data) == null ? void 0 : _c.session) == null ? void 0 : _d.user) != null ? _e : null,
|
|
448
|
+
session: (_g = (_f = response.data) == null ? void 0 : _f.session) != null ? _g : null
|
|
426
449
|
},
|
|
427
450
|
error: null
|
|
428
451
|
};
|
|
@@ -461,19 +484,20 @@ var KrisspyAuth = class {
|
|
|
461
484
|
* Update user metadata
|
|
462
485
|
*/
|
|
463
486
|
async updateUser(data) {
|
|
487
|
+
var _a, _b, _c;
|
|
464
488
|
const path = `/api/v1/cloud-backends/${this.backendId}/auth/user`;
|
|
465
489
|
const response = await this.http.patch(path, data);
|
|
466
490
|
if (response.error) {
|
|
467
491
|
return { data: { user: null }, error: response.error };
|
|
468
492
|
}
|
|
469
|
-
if (response.data
|
|
493
|
+
if ((_a = response.data) == null ? void 0 : _a.user) {
|
|
470
494
|
this.currentUser = response.data.user;
|
|
471
495
|
if (this.currentSession) {
|
|
472
496
|
this.currentSession.user = response.data.user;
|
|
473
497
|
this.saveSession(this.currentSession);
|
|
474
498
|
}
|
|
475
499
|
}
|
|
476
|
-
return { data: { user: response.data
|
|
500
|
+
return { data: { user: (_c = (_b = response.data) == null ? void 0 : _b.user) != null ? _c : null }, error: null };
|
|
477
501
|
}
|
|
478
502
|
/**
|
|
479
503
|
* Request password reset
|
|
@@ -519,7 +543,7 @@ var KrisspyAuth = class {
|
|
|
519
543
|
const payload = JSON.parse(base64Decode(accessToken.split(".")[1]));
|
|
520
544
|
const session = {
|
|
521
545
|
access_token: accessToken,
|
|
522
|
-
refresh_token: refreshToken
|
|
546
|
+
refresh_token: refreshToken != null ? refreshToken : void 0,
|
|
523
547
|
expires_at: payload.exp,
|
|
524
548
|
expires_in: payload.exp ? payload.exp - Math.floor(Date.now() / 1e3) : 3600,
|
|
525
549
|
user: {
|
|
@@ -570,9 +594,10 @@ var StorageBucket = class {
|
|
|
570
594
|
* .upload('photo.png', base64Data, { contentType: 'image/png' })
|
|
571
595
|
*/
|
|
572
596
|
async upload(path, file, options) {
|
|
597
|
+
var _a, _b, _c, _d, _e;
|
|
573
598
|
try {
|
|
574
599
|
let base64Data;
|
|
575
|
-
let contentType = options
|
|
600
|
+
let contentType = options == null ? void 0 : options.contentType;
|
|
576
601
|
if (typeof file === "string") {
|
|
577
602
|
base64Data = file;
|
|
578
603
|
} else if (file instanceof Blob || file instanceof File) {
|
|
@@ -600,11 +625,11 @@ var StorageBucket = class {
|
|
|
600
625
|
}
|
|
601
626
|
return {
|
|
602
627
|
data: {
|
|
603
|
-
path: response.data
|
|
604
|
-
url: response.data
|
|
605
|
-
bucket: response.data
|
|
606
|
-
contentType: response.data
|
|
607
|
-
size: response.data
|
|
628
|
+
path: ((_a = response.data) == null ? void 0 : _a.path) || path,
|
|
629
|
+
url: ((_b = response.data) == null ? void 0 : _b.url) || "",
|
|
630
|
+
bucket: ((_c = response.data) == null ? void 0 : _c.bucket) || this.bucketName,
|
|
631
|
+
contentType: ((_d = response.data) == null ? void 0 : _d.contentType) || contentType || "application/octet-stream",
|
|
632
|
+
size: ((_e = response.data) == null ? void 0 : _e.size) || 0
|
|
608
633
|
},
|
|
609
634
|
error: null
|
|
610
635
|
};
|
|
@@ -646,6 +671,7 @@ var StorageBucket = class {
|
|
|
646
671
|
* .download('report.pdf')
|
|
647
672
|
*/
|
|
648
673
|
async download(path) {
|
|
674
|
+
var _a, _b, _c;
|
|
649
675
|
const apiPath = `/api/v1/cloud-backends/${this.backendId}/storage/download`;
|
|
650
676
|
const response = await this.http.post(apiPath, {
|
|
651
677
|
bucket: this.bucketName,
|
|
@@ -656,9 +682,9 @@ var StorageBucket = class {
|
|
|
656
682
|
}
|
|
657
683
|
return {
|
|
658
684
|
data: {
|
|
659
|
-
url: response.data
|
|
660
|
-
path: response.data
|
|
661
|
-
bucket: response.data
|
|
685
|
+
url: ((_a = response.data) == null ? void 0 : _a.url) || "",
|
|
686
|
+
path: ((_b = response.data) == null ? void 0 : _b.path) || path,
|
|
687
|
+
bucket: ((_c = response.data) == null ? void 0 : _c.bucket) || this.bucketName
|
|
662
688
|
},
|
|
663
689
|
error: null
|
|
664
690
|
};
|
|
@@ -676,6 +702,7 @@ var StorageBucket = class {
|
|
|
676
702
|
* const { error } = await krisspy.storage.from('images').remove(['a.jpg', 'b.jpg'])
|
|
677
703
|
*/
|
|
678
704
|
async remove(paths) {
|
|
705
|
+
var _a;
|
|
679
706
|
const results = [];
|
|
680
707
|
for (const path of paths) {
|
|
681
708
|
const apiPath = `/api/v1/cloud-backends/${this.backendId}/storage/delete`;
|
|
@@ -686,7 +713,7 @@ var StorageBucket = class {
|
|
|
686
713
|
if (response.error) {
|
|
687
714
|
return { data: null, error: response.error };
|
|
688
715
|
}
|
|
689
|
-
results.push({ success: response.data
|
|
716
|
+
results.push({ success: ((_a = response.data) == null ? void 0 : _a.success) || false });
|
|
690
717
|
}
|
|
691
718
|
return { data: { success: true }, error: null };
|
|
692
719
|
}
|
|
@@ -704,16 +731,17 @@ var StorageBucket = class {
|
|
|
704
731
|
* const { data, error } = await krisspy.storage.from('uploads').list('images/')
|
|
705
732
|
*/
|
|
706
733
|
async list(prefix, options) {
|
|
734
|
+
var _a;
|
|
707
735
|
const apiPath = `/api/v1/cloud-backends/${this.backendId}/storage/list`;
|
|
708
736
|
const response = await this.http.post(apiPath, {
|
|
709
737
|
bucket: this.bucketName,
|
|
710
738
|
prefix,
|
|
711
|
-
limit: options
|
|
739
|
+
limit: (options == null ? void 0 : options.limit) || 100
|
|
712
740
|
});
|
|
713
741
|
if (response.error) {
|
|
714
742
|
return { data: null, error: response.error };
|
|
715
743
|
}
|
|
716
|
-
return { data: response.data
|
|
744
|
+
return { data: ((_a = response.data) == null ? void 0 : _a.files) || [], error: null };
|
|
717
745
|
}
|
|
718
746
|
/**
|
|
719
747
|
* Create a signed URL for temporary access
|
|
@@ -727,6 +755,7 @@ var StorageBucket = class {
|
|
|
727
755
|
* .createSignedUrl('document.pdf', 3600)
|
|
728
756
|
*/
|
|
729
757
|
async createSignedUrl(path, expiresIn = 3600) {
|
|
758
|
+
var _a, _b, _c;
|
|
730
759
|
const apiPath = `/api/v1/cloud-backends/${this.backendId}/storage/signed-url`;
|
|
731
760
|
const response = await this.http.post(apiPath, {
|
|
732
761
|
bucket: this.bucketName,
|
|
@@ -738,9 +767,9 @@ var StorageBucket = class {
|
|
|
738
767
|
}
|
|
739
768
|
return {
|
|
740
769
|
data: {
|
|
741
|
-
signedUrl: response.data
|
|
742
|
-
path: response.data
|
|
743
|
-
expiresIn: response.data
|
|
770
|
+
signedUrl: ((_a = response.data) == null ? void 0 : _a.url) || "",
|
|
771
|
+
path: ((_b = response.data) == null ? void 0 : _b.path) || path,
|
|
772
|
+
expiresIn: ((_c = response.data) == null ? void 0 : _c.expiresIn) || expiresIn
|
|
744
773
|
},
|
|
745
774
|
error: null
|
|
746
775
|
};
|
|
@@ -773,6 +802,7 @@ var StorageBucket = class {
|
|
|
773
802
|
* })
|
|
774
803
|
*/
|
|
775
804
|
async uploadAndLink(path, file, options) {
|
|
805
|
+
var _a, _b;
|
|
776
806
|
try {
|
|
777
807
|
const uploadResult = await this.upload(path, file, {
|
|
778
808
|
contentType: options.contentType
|
|
@@ -782,10 +812,9 @@ var StorageBucket = class {
|
|
|
782
812
|
}
|
|
783
813
|
const fileData = uploadResult.data;
|
|
784
814
|
const column = options.column || "url";
|
|
785
|
-
const recordData = {
|
|
786
|
-
...options.data,
|
|
815
|
+
const recordData = __spreadProps(__spreadValues({}, options.data), {
|
|
787
816
|
[column]: fileData.url
|
|
788
|
-
};
|
|
817
|
+
});
|
|
789
818
|
const tablePath = `/api/v1/cloud-backends/${this.backendId}/rls/data/${options.table}`;
|
|
790
819
|
let recordResult;
|
|
791
820
|
if (options.recordId) {
|
|
@@ -806,7 +835,7 @@ var StorageBucket = class {
|
|
|
806
835
|
error: null
|
|
807
836
|
};
|
|
808
837
|
}
|
|
809
|
-
const record = recordResult.data
|
|
838
|
+
const record = ((_b = (_a = recordResult.data) == null ? void 0 : _a.data) == null ? void 0 : _b[0]) || recordData;
|
|
810
839
|
return {
|
|
811
840
|
data: {
|
|
812
841
|
file: fileData,
|
|
@@ -852,7 +881,8 @@ var StorageBucket = class {
|
|
|
852
881
|
}
|
|
853
882
|
// Helper: Detect MIME type from file extension
|
|
854
883
|
detectMimeType(path) {
|
|
855
|
-
|
|
884
|
+
var _a;
|
|
885
|
+
const ext = ((_a = path.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
|
|
856
886
|
const mimeTypes = {
|
|
857
887
|
// Images
|
|
858
888
|
jpg: "image/jpeg",
|
|
@@ -963,10 +993,10 @@ var RealtimeChannel = class {
|
|
|
963
993
|
this.realtime.sendSubscribe(this.name, sub.config);
|
|
964
994
|
}
|
|
965
995
|
this._state = "connected";
|
|
966
|
-
callback
|
|
996
|
+
callback == null ? void 0 : callback("connected");
|
|
967
997
|
}).catch((error) => {
|
|
968
998
|
this._state = "error";
|
|
969
|
-
callback
|
|
999
|
+
callback == null ? void 0 : callback("error", error);
|
|
970
1000
|
});
|
|
971
1001
|
this.realtime.registerChannel(this.name, this);
|
|
972
1002
|
return this;
|
|
@@ -1010,8 +1040,9 @@ var KrisspyRealtime = class {
|
|
|
1010
1040
|
* Set auth token for authenticated subscriptions
|
|
1011
1041
|
*/
|
|
1012
1042
|
setAuth(token) {
|
|
1043
|
+
var _a;
|
|
1013
1044
|
this.token = token;
|
|
1014
|
-
if (this.ws
|
|
1045
|
+
if (((_a = this.ws) == null ? void 0 : _a.readyState) === WebSocket.OPEN && token) {
|
|
1015
1046
|
this.send({ type: "auth", token });
|
|
1016
1047
|
}
|
|
1017
1048
|
}
|
|
@@ -1026,10 +1057,11 @@ var KrisspyRealtime = class {
|
|
|
1026
1057
|
* Connect to WebSocket server
|
|
1027
1058
|
*/
|
|
1028
1059
|
async connect() {
|
|
1060
|
+
var _a;
|
|
1029
1061
|
if (this.connectionPromise) {
|
|
1030
1062
|
return this.connectionPromise;
|
|
1031
1063
|
}
|
|
1032
|
-
if (this.ws
|
|
1064
|
+
if (((_a = this.ws) == null ? void 0 : _a.readyState) === WebSocket.OPEN) {
|
|
1033
1065
|
return Promise.resolve();
|
|
1034
1066
|
}
|
|
1035
1067
|
this.connectionPromise = new Promise((resolve, reject) => {
|
|
@@ -1159,7 +1191,8 @@ var KrisspyRealtime = class {
|
|
|
1159
1191
|
* Send message to WebSocket server
|
|
1160
1192
|
*/
|
|
1161
1193
|
send(message) {
|
|
1162
|
-
|
|
1194
|
+
var _a;
|
|
1195
|
+
if (((_a = this.ws) == null ? void 0 : _a.readyState) === WebSocket.OPEN) {
|
|
1163
1196
|
this.ws.send(JSON.stringify(message));
|
|
1164
1197
|
} else {
|
|
1165
1198
|
console.warn("[Krisspy Realtime] Cannot send message, WebSocket not connected");
|
|
@@ -1232,13 +1265,12 @@ var KrisspyAnalytics = class {
|
|
|
1232
1265
|
init(options) {
|
|
1233
1266
|
if (this.initialized) return;
|
|
1234
1267
|
if (!isBrowser()) return;
|
|
1235
|
-
this.options = {
|
|
1268
|
+
this.options = __spreadValues({
|
|
1236
1269
|
autoTrackPageViews: true,
|
|
1237
1270
|
autoTrackNavigation: true,
|
|
1238
1271
|
flushInterval: 5e3,
|
|
1239
|
-
debug: false
|
|
1240
|
-
|
|
1241
|
-
};
|
|
1272
|
+
debug: false
|
|
1273
|
+
}, options);
|
|
1242
1274
|
this.sessionId = this.getOrCreateSessionId();
|
|
1243
1275
|
this.initialized = true;
|
|
1244
1276
|
if (this.options.autoTrackPageViews) {
|
|
@@ -1267,10 +1299,7 @@ var KrisspyAnalytics = class {
|
|
|
1267
1299
|
eventName,
|
|
1268
1300
|
sessionId: this.sessionId,
|
|
1269
1301
|
userId: this.userId || void 0,
|
|
1270
|
-
properties: {
|
|
1271
|
-
...properties,
|
|
1272
|
-
...this.userId ? { _user_traits: this.userTraits } : {}
|
|
1273
|
-
},
|
|
1302
|
+
properties: __spreadValues(__spreadValues({}, properties), this.userId ? { _user_traits: this.userTraits } : {}),
|
|
1274
1303
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1275
1304
|
};
|
|
1276
1305
|
this.queue.push(event);
|
|
@@ -1285,7 +1314,7 @@ var KrisspyAnalytics = class {
|
|
|
1285
1314
|
this.userId = userId;
|
|
1286
1315
|
this.userTraits = traits || {};
|
|
1287
1316
|
if (this.initialized) {
|
|
1288
|
-
this.track("identify", { userId,
|
|
1317
|
+
this.track("identify", __spreadValues({ userId }, traits));
|
|
1289
1318
|
}
|
|
1290
1319
|
}
|
|
1291
1320
|
/**
|
|
@@ -1300,7 +1329,7 @@ var KrisspyAnalytics = class {
|
|
|
1300
1329
|
if (this.options.debug) {
|
|
1301
1330
|
console.log(`[Krisspy Analytics] Flushed ${events.length} events`);
|
|
1302
1331
|
}
|
|
1303
|
-
} catch {
|
|
1332
|
+
} catch (e) {
|
|
1304
1333
|
this.queue.unshift(...events);
|
|
1305
1334
|
}
|
|
1306
1335
|
}
|
|
@@ -1325,7 +1354,7 @@ var KrisspyAnalytics = class {
|
|
|
1325
1354
|
}).catch(() => {
|
|
1326
1355
|
});
|
|
1327
1356
|
}
|
|
1328
|
-
} catch {
|
|
1357
|
+
} catch (e) {
|
|
1329
1358
|
}
|
|
1330
1359
|
}
|
|
1331
1360
|
/**
|
|
@@ -1368,7 +1397,7 @@ var KrisspyAnalytics = class {
|
|
|
1368
1397
|
const id = Math.random().toString(36).substring(2, 15) + Date.now().toString(36);
|
|
1369
1398
|
window.localStorage.setItem(key, id);
|
|
1370
1399
|
return id;
|
|
1371
|
-
} catch {
|
|
1400
|
+
} catch (e) {
|
|
1372
1401
|
}
|
|
1373
1402
|
}
|
|
1374
1403
|
return Math.random().toString(36).substring(2, 15) + Date.now().toString(36);
|
|
@@ -1509,7 +1538,7 @@ var QueryBuilder = class {
|
|
|
1509
1538
|
* @example .order('created_at', { ascending: false })
|
|
1510
1539
|
*/
|
|
1511
1540
|
order(column, options) {
|
|
1512
|
-
const direction = options
|
|
1541
|
+
const direction = (options == null ? void 0 : options.ascending) === false ? "desc" : "asc";
|
|
1513
1542
|
this.orderClauses.push(`${column}.${direction}`);
|
|
1514
1543
|
return this;
|
|
1515
1544
|
}
|
|
@@ -1550,7 +1579,7 @@ var QueryBuilder = class {
|
|
|
1550
1579
|
* Build query params for the request
|
|
1551
1580
|
*/
|
|
1552
1581
|
buildParams() {
|
|
1553
|
-
const params = {
|
|
1582
|
+
const params = __spreadValues({}, this.queryParams);
|
|
1554
1583
|
if (this.selectColumns.length > 0 && !this.selectColumns.includes("*")) {
|
|
1555
1584
|
params["select"] = this.selectColumns.join(",");
|
|
1556
1585
|
}
|
|
@@ -1580,6 +1609,7 @@ var QueryBuilder = class {
|
|
|
1580
1609
|
* Execute the query
|
|
1581
1610
|
*/
|
|
1582
1611
|
async execute() {
|
|
1612
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1583
1613
|
const path = this.getBasePath();
|
|
1584
1614
|
const params = this.buildParams();
|
|
1585
1615
|
const response = await this.http.get(path, params);
|
|
@@ -1590,13 +1620,13 @@ var QueryBuilder = class {
|
|
|
1590
1620
|
return { data: null, error: response.error, count: null };
|
|
1591
1621
|
}
|
|
1592
1622
|
if (this.isSingle) {
|
|
1593
|
-
const item = response.data
|
|
1623
|
+
const item = (_c = (_b = (_a = response.data) == null ? void 0 : _a.data) == null ? void 0 : _b[0]) != null ? _c : null;
|
|
1594
1624
|
return { data: item, error: null };
|
|
1595
1625
|
}
|
|
1596
1626
|
return {
|
|
1597
|
-
data: response.data
|
|
1627
|
+
data: (_e = (_d = response.data) == null ? void 0 : _d.data) != null ? _e : [],
|
|
1598
1628
|
error: null,
|
|
1599
|
-
count: response.data
|
|
1629
|
+
count: (_g = (_f = response.data) == null ? void 0 : _f.count) != null ? _g : 0
|
|
1600
1630
|
};
|
|
1601
1631
|
}
|
|
1602
1632
|
/**
|
|
@@ -1605,15 +1635,16 @@ var QueryBuilder = class {
|
|
|
1605
1635
|
* @example .insert([{ name: 'iPhone' }, { name: 'iPad' }])
|
|
1606
1636
|
*/
|
|
1607
1637
|
async insert(data) {
|
|
1638
|
+
var _a, _b, _c, _d;
|
|
1608
1639
|
const path = this.getBasePath();
|
|
1609
1640
|
const response = await this.http.post(path, data);
|
|
1610
1641
|
if (response.error) {
|
|
1611
1642
|
return { data: null, error: response.error, count: 0 };
|
|
1612
1643
|
}
|
|
1613
1644
|
return {
|
|
1614
|
-
data: response.data
|
|
1645
|
+
data: (_b = (_a = response.data) == null ? void 0 : _a.data) != null ? _b : [],
|
|
1615
1646
|
error: null,
|
|
1616
|
-
count: response.data
|
|
1647
|
+
count: (_d = (_c = response.data) == null ? void 0 : _c.count) != null ? _d : 0
|
|
1617
1648
|
};
|
|
1618
1649
|
}
|
|
1619
1650
|
/**
|
|
@@ -1621,6 +1652,7 @@ var QueryBuilder = class {
|
|
|
1621
1652
|
* @example .update({ price: 899 }).eq('id', 123)
|
|
1622
1653
|
*/
|
|
1623
1654
|
async update(data) {
|
|
1655
|
+
var _a, _b, _c, _d;
|
|
1624
1656
|
const path = this.getBasePath();
|
|
1625
1657
|
const params = this.buildParams();
|
|
1626
1658
|
delete params["select"];
|
|
@@ -1632,9 +1664,9 @@ var QueryBuilder = class {
|
|
|
1632
1664
|
return { data: null, error: response.error, count: 0 };
|
|
1633
1665
|
}
|
|
1634
1666
|
return {
|
|
1635
|
-
data: response.data
|
|
1667
|
+
data: (_b = (_a = response.data) == null ? void 0 : _a.data) != null ? _b : [],
|
|
1636
1668
|
error: null,
|
|
1637
|
-
count: response.data
|
|
1669
|
+
count: (_d = (_c = response.data) == null ? void 0 : _c.count) != null ? _d : 0
|
|
1638
1670
|
};
|
|
1639
1671
|
}
|
|
1640
1672
|
/**
|
|
@@ -1642,6 +1674,7 @@ var QueryBuilder = class {
|
|
|
1642
1674
|
* @example .delete().eq('id', 123)
|
|
1643
1675
|
*/
|
|
1644
1676
|
async delete() {
|
|
1677
|
+
var _a, _b, _c, _d;
|
|
1645
1678
|
const path = this.getBasePath();
|
|
1646
1679
|
const params = this.buildParams();
|
|
1647
1680
|
delete params["select"];
|
|
@@ -1653,9 +1686,9 @@ var QueryBuilder = class {
|
|
|
1653
1686
|
return { data: null, error: response.error, count: 0 };
|
|
1654
1687
|
}
|
|
1655
1688
|
return {
|
|
1656
|
-
data: response.data
|
|
1689
|
+
data: (_b = (_a = response.data) == null ? void 0 : _a.data) != null ? _b : [],
|
|
1657
1690
|
error: null,
|
|
1658
|
-
count: response.data
|
|
1691
|
+
count: (_d = (_c = response.data) == null ? void 0 : _c.count) != null ? _d : 0
|
|
1659
1692
|
};
|
|
1660
1693
|
}
|
|
1661
1694
|
/**
|
|
@@ -1676,10 +1709,9 @@ var KrisspyClient = class {
|
|
|
1676
1709
|
this.useRLS = options.useRLS !== false;
|
|
1677
1710
|
this.http = new HttpClient({
|
|
1678
1711
|
baseUrl: this.baseUrl,
|
|
1679
|
-
headers: {
|
|
1680
|
-
...options.headers,
|
|
1712
|
+
headers: __spreadProps(__spreadValues({}, options.headers), {
|
|
1681
1713
|
"apikey": options.anonKey
|
|
1682
|
-
},
|
|
1714
|
+
}),
|
|
1683
1715
|
debug: options.debug
|
|
1684
1716
|
});
|
|
1685
1717
|
this._auth = new KrisspyAuth(this.http, this.backendId, options.storage);
|
|
@@ -1689,7 +1721,7 @@ var KrisspyClient = class {
|
|
|
1689
1721
|
this._auth.onAuthStateChange((event) => {
|
|
1690
1722
|
if (event === "SIGNED_IN") {
|
|
1691
1723
|
const session = this._auth.session();
|
|
1692
|
-
if (session
|
|
1724
|
+
if (session == null ? void 0 : session.access_token) {
|
|
1693
1725
|
this._realtime.setAuth(session.access_token);
|
|
1694
1726
|
}
|
|
1695
1727
|
} else if (event === "SIGNED_OUT") {
|
|
@@ -1856,12 +1888,13 @@ var KrisspyClient = class {
|
|
|
1856
1888
|
* const { data, error } = await krisspy.rpc('SELECT * FROM products WHERE price > $1', [100])
|
|
1857
1889
|
*/
|
|
1858
1890
|
async rpc(sql, params) {
|
|
1891
|
+
var _a, _b;
|
|
1859
1892
|
const path = `/api/v1/cloud-backends/${this.backendId}/sql`;
|
|
1860
1893
|
const response = await this.http.post(path, { sql, params });
|
|
1861
1894
|
if (response.error) {
|
|
1862
1895
|
return { data: null, error: response.error };
|
|
1863
1896
|
}
|
|
1864
|
-
return { data: response.data
|
|
1897
|
+
return { data: (_b = (_a = response.data) == null ? void 0 : _a.result) != null ? _b : null, error: null };
|
|
1865
1898
|
}
|
|
1866
1899
|
/**
|
|
1867
1900
|
* Invoke a serverless function
|
|
@@ -1875,19 +1908,20 @@ var KrisspyClient = class {
|
|
|
1875
1908
|
return {
|
|
1876
1909
|
invoke: async (functionName, options) => {
|
|
1877
1910
|
const path = `/api/v1/cloud-backends/${this.backendId}/functions/${functionName}/invoke`;
|
|
1878
|
-
const response = await this.http.post(path, options
|
|
1911
|
+
const response = await this.http.post(path, options == null ? void 0 : options.body, void 0);
|
|
1879
1912
|
if (response.error) {
|
|
1880
1913
|
return { data: null, error: response.error };
|
|
1881
1914
|
}
|
|
1882
1915
|
return { data: response.data, error: null };
|
|
1883
1916
|
},
|
|
1884
1917
|
list: async () => {
|
|
1918
|
+
var _a, _b;
|
|
1885
1919
|
const path = `/api/v1/cloud-backends/${this.backendId}/functions`;
|
|
1886
1920
|
const response = await this.http.get(path);
|
|
1887
1921
|
if (response.error) {
|
|
1888
1922
|
return { data: null, error: response.error };
|
|
1889
1923
|
}
|
|
1890
|
-
return { data: response.data
|
|
1924
|
+
return { data: (_b = (_a = response.data) == null ? void 0 : _a.functions) != null ? _b : [], error: null };
|
|
1891
1925
|
}
|
|
1892
1926
|
};
|
|
1893
1927
|
}
|
|
@@ -1906,23 +1940,25 @@ var KrisspyClient = class {
|
|
|
1906
1940
|
* List tables in the backend
|
|
1907
1941
|
*/
|
|
1908
1942
|
async listTables() {
|
|
1943
|
+
var _a, _b;
|
|
1909
1944
|
const path = `/api/v1/cloud-backends/${this.backendId}/tables`;
|
|
1910
1945
|
const response = await this.http.get(path);
|
|
1911
1946
|
if (response.error) {
|
|
1912
1947
|
return { data: null, error: response.error };
|
|
1913
1948
|
}
|
|
1914
|
-
return { data: response.data
|
|
1949
|
+
return { data: (_b = (_a = response.data) == null ? void 0 : _a.tables) != null ? _b : [], error: null };
|
|
1915
1950
|
}
|
|
1916
1951
|
/**
|
|
1917
1952
|
* Get table schema (columns)
|
|
1918
1953
|
*/
|
|
1919
1954
|
async getTableSchema(table) {
|
|
1955
|
+
var _a, _b;
|
|
1920
1956
|
const path = `/api/v1/cloud-backends/${this.backendId}/tables/${table}`;
|
|
1921
1957
|
const response = await this.http.get(path);
|
|
1922
1958
|
if (response.error) {
|
|
1923
1959
|
return { data: null, error: response.error };
|
|
1924
1960
|
}
|
|
1925
|
-
return { data: response.data
|
|
1961
|
+
return { data: (_b = (_a = response.data) == null ? void 0 : _a.columns) != null ? _b : [], error: null };
|
|
1926
1962
|
}
|
|
1927
1963
|
};
|
|
1928
1964
|
|