krisspy-sdk 0.5.0 → 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.js
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
6
23
|
var __export = (target, all) => {
|
|
7
24
|
for (var name in all)
|
|
8
25
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -38,12 +55,12 @@ module.exports = __toCommonJS(index_exports);
|
|
|
38
55
|
// src/http.ts
|
|
39
56
|
var HttpClient = class {
|
|
40
57
|
constructor(options) {
|
|
58
|
+
var _a;
|
|
41
59
|
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
42
|
-
this.headers = {
|
|
43
|
-
"Content-Type": "application/json"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this.debug = options.debug ?? false;
|
|
60
|
+
this.headers = __spreadValues({
|
|
61
|
+
"Content-Type": "application/json"
|
|
62
|
+
}, options.headers);
|
|
63
|
+
this.debug = (_a = options.debug) != null ? _a : false;
|
|
47
64
|
}
|
|
48
65
|
/**
|
|
49
66
|
* Set authorization header
|
|
@@ -61,7 +78,7 @@ var HttpClient = class {
|
|
|
61
78
|
* Update headers
|
|
62
79
|
*/
|
|
63
80
|
setHeaders(headers) {
|
|
64
|
-
this.headers = {
|
|
81
|
+
this.headers = __spreadValues(__spreadValues({}, this.headers), headers);
|
|
65
82
|
}
|
|
66
83
|
/**
|
|
67
84
|
* Build query string from params
|
|
@@ -82,14 +99,11 @@ var HttpClient = class {
|
|
|
82
99
|
* Make HTTP request
|
|
83
100
|
*/
|
|
84
101
|
async request(method, path, options) {
|
|
85
|
-
const url = `${this.baseUrl}${path}${options
|
|
86
|
-
const requestHeaders = {
|
|
87
|
-
...this.headers,
|
|
88
|
-
...options?.headers
|
|
89
|
-
};
|
|
102
|
+
const url = `${this.baseUrl}${path}${(options == null ? void 0 : options.params) ? this.buildQueryString(options.params) : ""}`;
|
|
103
|
+
const requestHeaders = __spreadValues(__spreadValues({}, this.headers), options == null ? void 0 : options.headers);
|
|
90
104
|
if (this.debug) {
|
|
91
105
|
console.log(`[Krisspy SDK] ${method} ${url}`);
|
|
92
|
-
if (options
|
|
106
|
+
if (options == null ? void 0 : options.body) {
|
|
93
107
|
console.log("[Krisspy SDK] Body:", JSON.stringify(options.body, null, 2));
|
|
94
108
|
}
|
|
95
109
|
}
|
|
@@ -97,11 +111,11 @@ var HttpClient = class {
|
|
|
97
111
|
const response = await fetch(url, {
|
|
98
112
|
method,
|
|
99
113
|
headers: requestHeaders,
|
|
100
|
-
body: options
|
|
114
|
+
body: (options == null ? void 0 : options.body) ? JSON.stringify(options.body) : void 0
|
|
101
115
|
});
|
|
102
116
|
const contentType = response.headers.get("content-type");
|
|
103
117
|
let data = null;
|
|
104
|
-
if (contentType
|
|
118
|
+
if (contentType == null ? void 0 : contentType.includes("application/json")) {
|
|
105
119
|
data = await response.json();
|
|
106
120
|
} else {
|
|
107
121
|
data = await response.text();
|
|
@@ -111,10 +125,10 @@ var HttpClient = class {
|
|
|
111
125
|
}
|
|
112
126
|
if (!response.ok) {
|
|
113
127
|
const error = {
|
|
114
|
-
message: data
|
|
115
|
-
code: data
|
|
116
|
-
details: data
|
|
117
|
-
hint: data
|
|
128
|
+
message: (data == null ? void 0 : data.error) || (data == null ? void 0 : data.message) || "Request failed",
|
|
129
|
+
code: data == null ? void 0 : data.code,
|
|
130
|
+
details: data == null ? void 0 : data.details,
|
|
131
|
+
hint: data == null ? void 0 : data.hint,
|
|
118
132
|
status: response.status
|
|
119
133
|
};
|
|
120
134
|
return { data: null, error, status: response.status };
|
|
@@ -178,7 +192,7 @@ function getLocalStorage() {
|
|
|
178
192
|
window.localStorage.setItem(testKey, "1");
|
|
179
193
|
window.localStorage.removeItem(testKey);
|
|
180
194
|
return window.localStorage;
|
|
181
|
-
} catch {
|
|
195
|
+
} catch (e) {
|
|
182
196
|
return null;
|
|
183
197
|
}
|
|
184
198
|
}
|
|
@@ -187,7 +201,8 @@ var MemoryStorage = class {
|
|
|
187
201
|
this.store = /* @__PURE__ */ new Map();
|
|
188
202
|
}
|
|
189
203
|
getItem(key) {
|
|
190
|
-
|
|
204
|
+
var _a;
|
|
205
|
+
return (_a = this.store.get(key)) != null ? _a : null;
|
|
191
206
|
}
|
|
192
207
|
setItem(key, value) {
|
|
193
208
|
this.store.set(key, value);
|
|
@@ -197,8 +212,9 @@ var MemoryStorage = class {
|
|
|
197
212
|
}
|
|
198
213
|
};
|
|
199
214
|
function resolveStorage(custom) {
|
|
215
|
+
var _a;
|
|
200
216
|
if (custom) return custom;
|
|
201
|
-
return getLocalStorage()
|
|
217
|
+
return (_a = getLocalStorage()) != null ? _a : new MemoryStorage();
|
|
202
218
|
}
|
|
203
219
|
function base64Encode(input) {
|
|
204
220
|
if (typeof btoa === "function") {
|
|
@@ -285,7 +301,7 @@ var KrisspyAuth = class {
|
|
|
285
301
|
return;
|
|
286
302
|
}
|
|
287
303
|
this.setSession(session);
|
|
288
|
-
} catch {
|
|
304
|
+
} catch (e) {
|
|
289
305
|
}
|
|
290
306
|
}
|
|
291
307
|
/**
|
|
@@ -311,7 +327,7 @@ var KrisspyAuth = class {
|
|
|
311
327
|
}
|
|
312
328
|
try {
|
|
313
329
|
this.storage.removeItem(`${STORAGE_KEY}-${this.backendId}`);
|
|
314
|
-
} catch {
|
|
330
|
+
} catch (e) {
|
|
315
331
|
}
|
|
316
332
|
}
|
|
317
333
|
/**
|
|
@@ -356,6 +372,7 @@ var KrisspyAuth = class {
|
|
|
356
372
|
* Sign up with email and password
|
|
357
373
|
*/
|
|
358
374
|
async signUp(credentials) {
|
|
375
|
+
var _a, _b, _c, _d, _e;
|
|
359
376
|
const path = `/api/v1/cloud-backends/${this.backendId}/auth/signup`;
|
|
360
377
|
const response = await this.http.post(path, {
|
|
361
378
|
email: credentials.email,
|
|
@@ -368,13 +385,13 @@ var KrisspyAuth = class {
|
|
|
368
385
|
error: response.error
|
|
369
386
|
};
|
|
370
387
|
}
|
|
371
|
-
if (response.data
|
|
388
|
+
if ((_a = response.data) == null ? void 0 : _a.session) {
|
|
372
389
|
this.setSession(response.data.session);
|
|
373
390
|
}
|
|
374
391
|
return {
|
|
375
392
|
data: {
|
|
376
|
-
user: response.data
|
|
377
|
-
session: response.data
|
|
393
|
+
user: (_c = (_b = response.data) == null ? void 0 : _b.user) != null ? _c : null,
|
|
394
|
+
session: (_e = (_d = response.data) == null ? void 0 : _d.session) != null ? _e : null
|
|
378
395
|
},
|
|
379
396
|
error: null
|
|
380
397
|
};
|
|
@@ -383,6 +400,7 @@ var KrisspyAuth = class {
|
|
|
383
400
|
* Sign in with email and password
|
|
384
401
|
*/
|
|
385
402
|
async signInWithPassword(credentials) {
|
|
403
|
+
var _a, _b, _c, _d, _e;
|
|
386
404
|
const path = `/api/v1/cloud-backends/${this.backendId}/auth/login`;
|
|
387
405
|
const response = await this.http.post(path, {
|
|
388
406
|
email: credentials.email,
|
|
@@ -394,13 +412,13 @@ var KrisspyAuth = class {
|
|
|
394
412
|
error: response.error
|
|
395
413
|
};
|
|
396
414
|
}
|
|
397
|
-
if (response.data
|
|
415
|
+
if ((_a = response.data) == null ? void 0 : _a.session) {
|
|
398
416
|
this.setSession(response.data.session);
|
|
399
417
|
}
|
|
400
418
|
return {
|
|
401
419
|
data: {
|
|
402
|
-
user: response.data
|
|
403
|
-
session: response.data
|
|
420
|
+
user: (_c = (_b = response.data) == null ? void 0 : _b.user) != null ? _c : null,
|
|
421
|
+
session: (_e = (_d = response.data) == null ? void 0 : _d.session) != null ? _e : null
|
|
404
422
|
},
|
|
405
423
|
error: null
|
|
406
424
|
};
|
|
@@ -409,6 +427,7 @@ var KrisspyAuth = class {
|
|
|
409
427
|
* Sign in with OAuth provider
|
|
410
428
|
*/
|
|
411
429
|
async signInWithOAuth(options) {
|
|
430
|
+
var _a;
|
|
412
431
|
const path = `/api/v1/cloud-backends/${this.backendId}/auth/oauth/${options.provider}`;
|
|
413
432
|
const response = await this.http.post(path, {
|
|
414
433
|
redirect_to: options.redirectTo
|
|
@@ -416,7 +435,7 @@ var KrisspyAuth = class {
|
|
|
416
435
|
if (response.error) {
|
|
417
436
|
return { data: null, error: response.error };
|
|
418
437
|
}
|
|
419
|
-
if (isBrowser() && response.data
|
|
438
|
+
if (isBrowser() && ((_a = response.data) == null ? void 0 : _a.url)) {
|
|
420
439
|
window.location.href = response.data.url;
|
|
421
440
|
}
|
|
422
441
|
return { data: response.data, error: null };
|
|
@@ -435,7 +454,8 @@ var KrisspyAuth = class {
|
|
|
435
454
|
* Refresh the session token
|
|
436
455
|
*/
|
|
437
456
|
async refreshSession() {
|
|
438
|
-
|
|
457
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
458
|
+
if (!((_a = this.currentSession) == null ? void 0 : _a.refresh_token)) {
|
|
439
459
|
return {
|
|
440
460
|
data: { user: null, session: null },
|
|
441
461
|
error: { message: "No refresh token available" }
|
|
@@ -453,13 +473,13 @@ var KrisspyAuth = class {
|
|
|
453
473
|
error: response.error
|
|
454
474
|
};
|
|
455
475
|
}
|
|
456
|
-
if (response.data
|
|
476
|
+
if ((_b = response.data) == null ? void 0 : _b.session) {
|
|
457
477
|
this.setSession(response.data.session);
|
|
458
478
|
}
|
|
459
479
|
return {
|
|
460
480
|
data: {
|
|
461
|
-
user: response.data
|
|
462
|
-
session: response.data
|
|
481
|
+
user: (_e = (_d = (_c = response.data) == null ? void 0 : _c.session) == null ? void 0 : _d.user) != null ? _e : null,
|
|
482
|
+
session: (_g = (_f = response.data) == null ? void 0 : _f.session) != null ? _g : null
|
|
463
483
|
},
|
|
464
484
|
error: null
|
|
465
485
|
};
|
|
@@ -498,19 +518,20 @@ var KrisspyAuth = class {
|
|
|
498
518
|
* Update user metadata
|
|
499
519
|
*/
|
|
500
520
|
async updateUser(data) {
|
|
521
|
+
var _a, _b, _c;
|
|
501
522
|
const path = `/api/v1/cloud-backends/${this.backendId}/auth/user`;
|
|
502
523
|
const response = await this.http.patch(path, data);
|
|
503
524
|
if (response.error) {
|
|
504
525
|
return { data: { user: null }, error: response.error };
|
|
505
526
|
}
|
|
506
|
-
if (response.data
|
|
527
|
+
if ((_a = response.data) == null ? void 0 : _a.user) {
|
|
507
528
|
this.currentUser = response.data.user;
|
|
508
529
|
if (this.currentSession) {
|
|
509
530
|
this.currentSession.user = response.data.user;
|
|
510
531
|
this.saveSession(this.currentSession);
|
|
511
532
|
}
|
|
512
533
|
}
|
|
513
|
-
return { data: { user: response.data
|
|
534
|
+
return { data: { user: (_c = (_b = response.data) == null ? void 0 : _b.user) != null ? _c : null }, error: null };
|
|
514
535
|
}
|
|
515
536
|
/**
|
|
516
537
|
* Request password reset
|
|
@@ -556,7 +577,7 @@ var KrisspyAuth = class {
|
|
|
556
577
|
const payload = JSON.parse(base64Decode(accessToken.split(".")[1]));
|
|
557
578
|
const session = {
|
|
558
579
|
access_token: accessToken,
|
|
559
|
-
refresh_token: refreshToken
|
|
580
|
+
refresh_token: refreshToken != null ? refreshToken : void 0,
|
|
560
581
|
expires_at: payload.exp,
|
|
561
582
|
expires_in: payload.exp ? payload.exp - Math.floor(Date.now() / 1e3) : 3600,
|
|
562
583
|
user: {
|
|
@@ -607,9 +628,10 @@ var StorageBucket = class {
|
|
|
607
628
|
* .upload('photo.png', base64Data, { contentType: 'image/png' })
|
|
608
629
|
*/
|
|
609
630
|
async upload(path, file, options) {
|
|
631
|
+
var _a, _b, _c, _d, _e;
|
|
610
632
|
try {
|
|
611
633
|
let base64Data;
|
|
612
|
-
let contentType = options
|
|
634
|
+
let contentType = options == null ? void 0 : options.contentType;
|
|
613
635
|
if (typeof file === "string") {
|
|
614
636
|
base64Data = file;
|
|
615
637
|
} else if (file instanceof Blob || file instanceof File) {
|
|
@@ -637,11 +659,11 @@ var StorageBucket = class {
|
|
|
637
659
|
}
|
|
638
660
|
return {
|
|
639
661
|
data: {
|
|
640
|
-
path: response.data
|
|
641
|
-
url: response.data
|
|
642
|
-
bucket: response.data
|
|
643
|
-
contentType: response.data
|
|
644
|
-
size: response.data
|
|
662
|
+
path: ((_a = response.data) == null ? void 0 : _a.path) || path,
|
|
663
|
+
url: ((_b = response.data) == null ? void 0 : _b.url) || "",
|
|
664
|
+
bucket: ((_c = response.data) == null ? void 0 : _c.bucket) || this.bucketName,
|
|
665
|
+
contentType: ((_d = response.data) == null ? void 0 : _d.contentType) || contentType || "application/octet-stream",
|
|
666
|
+
size: ((_e = response.data) == null ? void 0 : _e.size) || 0
|
|
645
667
|
},
|
|
646
668
|
error: null
|
|
647
669
|
};
|
|
@@ -683,6 +705,7 @@ var StorageBucket = class {
|
|
|
683
705
|
* .download('report.pdf')
|
|
684
706
|
*/
|
|
685
707
|
async download(path) {
|
|
708
|
+
var _a, _b, _c;
|
|
686
709
|
const apiPath = `/api/v1/cloud-backends/${this.backendId}/storage/download`;
|
|
687
710
|
const response = await this.http.post(apiPath, {
|
|
688
711
|
bucket: this.bucketName,
|
|
@@ -693,9 +716,9 @@ var StorageBucket = class {
|
|
|
693
716
|
}
|
|
694
717
|
return {
|
|
695
718
|
data: {
|
|
696
|
-
url: response.data
|
|
697
|
-
path: response.data
|
|
698
|
-
bucket: response.data
|
|
719
|
+
url: ((_a = response.data) == null ? void 0 : _a.url) || "",
|
|
720
|
+
path: ((_b = response.data) == null ? void 0 : _b.path) || path,
|
|
721
|
+
bucket: ((_c = response.data) == null ? void 0 : _c.bucket) || this.bucketName
|
|
699
722
|
},
|
|
700
723
|
error: null
|
|
701
724
|
};
|
|
@@ -713,6 +736,7 @@ var StorageBucket = class {
|
|
|
713
736
|
* const { error } = await krisspy.storage.from('images').remove(['a.jpg', 'b.jpg'])
|
|
714
737
|
*/
|
|
715
738
|
async remove(paths) {
|
|
739
|
+
var _a;
|
|
716
740
|
const results = [];
|
|
717
741
|
for (const path of paths) {
|
|
718
742
|
const apiPath = `/api/v1/cloud-backends/${this.backendId}/storage/delete`;
|
|
@@ -723,7 +747,7 @@ var StorageBucket = class {
|
|
|
723
747
|
if (response.error) {
|
|
724
748
|
return { data: null, error: response.error };
|
|
725
749
|
}
|
|
726
|
-
results.push({ success: response.data
|
|
750
|
+
results.push({ success: ((_a = response.data) == null ? void 0 : _a.success) || false });
|
|
727
751
|
}
|
|
728
752
|
return { data: { success: true }, error: null };
|
|
729
753
|
}
|
|
@@ -741,16 +765,17 @@ var StorageBucket = class {
|
|
|
741
765
|
* const { data, error } = await krisspy.storage.from('uploads').list('images/')
|
|
742
766
|
*/
|
|
743
767
|
async list(prefix, options) {
|
|
768
|
+
var _a;
|
|
744
769
|
const apiPath = `/api/v1/cloud-backends/${this.backendId}/storage/list`;
|
|
745
770
|
const response = await this.http.post(apiPath, {
|
|
746
771
|
bucket: this.bucketName,
|
|
747
772
|
prefix,
|
|
748
|
-
limit: options
|
|
773
|
+
limit: (options == null ? void 0 : options.limit) || 100
|
|
749
774
|
});
|
|
750
775
|
if (response.error) {
|
|
751
776
|
return { data: null, error: response.error };
|
|
752
777
|
}
|
|
753
|
-
return { data: response.data
|
|
778
|
+
return { data: ((_a = response.data) == null ? void 0 : _a.files) || [], error: null };
|
|
754
779
|
}
|
|
755
780
|
/**
|
|
756
781
|
* Create a signed URL for temporary access
|
|
@@ -764,6 +789,7 @@ var StorageBucket = class {
|
|
|
764
789
|
* .createSignedUrl('document.pdf', 3600)
|
|
765
790
|
*/
|
|
766
791
|
async createSignedUrl(path, expiresIn = 3600) {
|
|
792
|
+
var _a, _b, _c;
|
|
767
793
|
const apiPath = `/api/v1/cloud-backends/${this.backendId}/storage/signed-url`;
|
|
768
794
|
const response = await this.http.post(apiPath, {
|
|
769
795
|
bucket: this.bucketName,
|
|
@@ -775,9 +801,9 @@ var StorageBucket = class {
|
|
|
775
801
|
}
|
|
776
802
|
return {
|
|
777
803
|
data: {
|
|
778
|
-
signedUrl: response.data
|
|
779
|
-
path: response.data
|
|
780
|
-
expiresIn: response.data
|
|
804
|
+
signedUrl: ((_a = response.data) == null ? void 0 : _a.url) || "",
|
|
805
|
+
path: ((_b = response.data) == null ? void 0 : _b.path) || path,
|
|
806
|
+
expiresIn: ((_c = response.data) == null ? void 0 : _c.expiresIn) || expiresIn
|
|
781
807
|
},
|
|
782
808
|
error: null
|
|
783
809
|
};
|
|
@@ -810,6 +836,7 @@ var StorageBucket = class {
|
|
|
810
836
|
* })
|
|
811
837
|
*/
|
|
812
838
|
async uploadAndLink(path, file, options) {
|
|
839
|
+
var _a, _b;
|
|
813
840
|
try {
|
|
814
841
|
const uploadResult = await this.upload(path, file, {
|
|
815
842
|
contentType: options.contentType
|
|
@@ -819,10 +846,9 @@ var StorageBucket = class {
|
|
|
819
846
|
}
|
|
820
847
|
const fileData = uploadResult.data;
|
|
821
848
|
const column = options.column || "url";
|
|
822
|
-
const recordData = {
|
|
823
|
-
...options.data,
|
|
849
|
+
const recordData = __spreadProps(__spreadValues({}, options.data), {
|
|
824
850
|
[column]: fileData.url
|
|
825
|
-
};
|
|
851
|
+
});
|
|
826
852
|
const tablePath = `/api/v1/cloud-backends/${this.backendId}/rls/data/${options.table}`;
|
|
827
853
|
let recordResult;
|
|
828
854
|
if (options.recordId) {
|
|
@@ -843,7 +869,7 @@ var StorageBucket = class {
|
|
|
843
869
|
error: null
|
|
844
870
|
};
|
|
845
871
|
}
|
|
846
|
-
const record = recordResult.data
|
|
872
|
+
const record = ((_b = (_a = recordResult.data) == null ? void 0 : _a.data) == null ? void 0 : _b[0]) || recordData;
|
|
847
873
|
return {
|
|
848
874
|
data: {
|
|
849
875
|
file: fileData,
|
|
@@ -889,7 +915,8 @@ var StorageBucket = class {
|
|
|
889
915
|
}
|
|
890
916
|
// Helper: Detect MIME type from file extension
|
|
891
917
|
detectMimeType(path) {
|
|
892
|
-
|
|
918
|
+
var _a;
|
|
919
|
+
const ext = ((_a = path.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
|
|
893
920
|
const mimeTypes = {
|
|
894
921
|
// Images
|
|
895
922
|
jpg: "image/jpeg",
|
|
@@ -1000,10 +1027,10 @@ var RealtimeChannel = class {
|
|
|
1000
1027
|
this.realtime.sendSubscribe(this.name, sub.config);
|
|
1001
1028
|
}
|
|
1002
1029
|
this._state = "connected";
|
|
1003
|
-
callback
|
|
1030
|
+
callback == null ? void 0 : callback("connected");
|
|
1004
1031
|
}).catch((error) => {
|
|
1005
1032
|
this._state = "error";
|
|
1006
|
-
callback
|
|
1033
|
+
callback == null ? void 0 : callback("error", error);
|
|
1007
1034
|
});
|
|
1008
1035
|
this.realtime.registerChannel(this.name, this);
|
|
1009
1036
|
return this;
|
|
@@ -1047,8 +1074,9 @@ var KrisspyRealtime = class {
|
|
|
1047
1074
|
* Set auth token for authenticated subscriptions
|
|
1048
1075
|
*/
|
|
1049
1076
|
setAuth(token) {
|
|
1077
|
+
var _a;
|
|
1050
1078
|
this.token = token;
|
|
1051
|
-
if (this.ws
|
|
1079
|
+
if (((_a = this.ws) == null ? void 0 : _a.readyState) === WebSocket.OPEN && token) {
|
|
1052
1080
|
this.send({ type: "auth", token });
|
|
1053
1081
|
}
|
|
1054
1082
|
}
|
|
@@ -1063,10 +1091,11 @@ var KrisspyRealtime = class {
|
|
|
1063
1091
|
* Connect to WebSocket server
|
|
1064
1092
|
*/
|
|
1065
1093
|
async connect() {
|
|
1094
|
+
var _a;
|
|
1066
1095
|
if (this.connectionPromise) {
|
|
1067
1096
|
return this.connectionPromise;
|
|
1068
1097
|
}
|
|
1069
|
-
if (this.ws
|
|
1098
|
+
if (((_a = this.ws) == null ? void 0 : _a.readyState) === WebSocket.OPEN) {
|
|
1070
1099
|
return Promise.resolve();
|
|
1071
1100
|
}
|
|
1072
1101
|
this.connectionPromise = new Promise((resolve, reject) => {
|
|
@@ -1196,7 +1225,8 @@ var KrisspyRealtime = class {
|
|
|
1196
1225
|
* Send message to WebSocket server
|
|
1197
1226
|
*/
|
|
1198
1227
|
send(message) {
|
|
1199
|
-
|
|
1228
|
+
var _a;
|
|
1229
|
+
if (((_a = this.ws) == null ? void 0 : _a.readyState) === WebSocket.OPEN) {
|
|
1200
1230
|
this.ws.send(JSON.stringify(message));
|
|
1201
1231
|
} else {
|
|
1202
1232
|
console.warn("[Krisspy Realtime] Cannot send message, WebSocket not connected");
|
|
@@ -1269,13 +1299,12 @@ var KrisspyAnalytics = class {
|
|
|
1269
1299
|
init(options) {
|
|
1270
1300
|
if (this.initialized) return;
|
|
1271
1301
|
if (!isBrowser()) return;
|
|
1272
|
-
this.options = {
|
|
1302
|
+
this.options = __spreadValues({
|
|
1273
1303
|
autoTrackPageViews: true,
|
|
1274
1304
|
autoTrackNavigation: true,
|
|
1275
1305
|
flushInterval: 5e3,
|
|
1276
|
-
debug: false
|
|
1277
|
-
|
|
1278
|
-
};
|
|
1306
|
+
debug: false
|
|
1307
|
+
}, options);
|
|
1279
1308
|
this.sessionId = this.getOrCreateSessionId();
|
|
1280
1309
|
this.initialized = true;
|
|
1281
1310
|
if (this.options.autoTrackPageViews) {
|
|
@@ -1304,10 +1333,7 @@ var KrisspyAnalytics = class {
|
|
|
1304
1333
|
eventName,
|
|
1305
1334
|
sessionId: this.sessionId,
|
|
1306
1335
|
userId: this.userId || void 0,
|
|
1307
|
-
properties: {
|
|
1308
|
-
...properties,
|
|
1309
|
-
...this.userId ? { _user_traits: this.userTraits } : {}
|
|
1310
|
-
},
|
|
1336
|
+
properties: __spreadValues(__spreadValues({}, properties), this.userId ? { _user_traits: this.userTraits } : {}),
|
|
1311
1337
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1312
1338
|
};
|
|
1313
1339
|
this.queue.push(event);
|
|
@@ -1322,7 +1348,7 @@ var KrisspyAnalytics = class {
|
|
|
1322
1348
|
this.userId = userId;
|
|
1323
1349
|
this.userTraits = traits || {};
|
|
1324
1350
|
if (this.initialized) {
|
|
1325
|
-
this.track("identify", { userId,
|
|
1351
|
+
this.track("identify", __spreadValues({ userId }, traits));
|
|
1326
1352
|
}
|
|
1327
1353
|
}
|
|
1328
1354
|
/**
|
|
@@ -1337,7 +1363,7 @@ var KrisspyAnalytics = class {
|
|
|
1337
1363
|
if (this.options.debug) {
|
|
1338
1364
|
console.log(`[Krisspy Analytics] Flushed ${events.length} events`);
|
|
1339
1365
|
}
|
|
1340
|
-
} catch {
|
|
1366
|
+
} catch (e) {
|
|
1341
1367
|
this.queue.unshift(...events);
|
|
1342
1368
|
}
|
|
1343
1369
|
}
|
|
@@ -1362,7 +1388,7 @@ var KrisspyAnalytics = class {
|
|
|
1362
1388
|
}).catch(() => {
|
|
1363
1389
|
});
|
|
1364
1390
|
}
|
|
1365
|
-
} catch {
|
|
1391
|
+
} catch (e) {
|
|
1366
1392
|
}
|
|
1367
1393
|
}
|
|
1368
1394
|
/**
|
|
@@ -1405,7 +1431,7 @@ var KrisspyAnalytics = class {
|
|
|
1405
1431
|
const id = Math.random().toString(36).substring(2, 15) + Date.now().toString(36);
|
|
1406
1432
|
window.localStorage.setItem(key, id);
|
|
1407
1433
|
return id;
|
|
1408
|
-
} catch {
|
|
1434
|
+
} catch (e) {
|
|
1409
1435
|
}
|
|
1410
1436
|
}
|
|
1411
1437
|
return Math.random().toString(36).substring(2, 15) + Date.now().toString(36);
|
|
@@ -1546,7 +1572,7 @@ var QueryBuilder = class {
|
|
|
1546
1572
|
* @example .order('created_at', { ascending: false })
|
|
1547
1573
|
*/
|
|
1548
1574
|
order(column, options) {
|
|
1549
|
-
const direction = options
|
|
1575
|
+
const direction = (options == null ? void 0 : options.ascending) === false ? "desc" : "asc";
|
|
1550
1576
|
this.orderClauses.push(`${column}.${direction}`);
|
|
1551
1577
|
return this;
|
|
1552
1578
|
}
|
|
@@ -1587,7 +1613,7 @@ var QueryBuilder = class {
|
|
|
1587
1613
|
* Build query params for the request
|
|
1588
1614
|
*/
|
|
1589
1615
|
buildParams() {
|
|
1590
|
-
const params = {
|
|
1616
|
+
const params = __spreadValues({}, this.queryParams);
|
|
1591
1617
|
if (this.selectColumns.length > 0 && !this.selectColumns.includes("*")) {
|
|
1592
1618
|
params["select"] = this.selectColumns.join(",");
|
|
1593
1619
|
}
|
|
@@ -1617,6 +1643,7 @@ var QueryBuilder = class {
|
|
|
1617
1643
|
* Execute the query
|
|
1618
1644
|
*/
|
|
1619
1645
|
async execute() {
|
|
1646
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1620
1647
|
const path = this.getBasePath();
|
|
1621
1648
|
const params = this.buildParams();
|
|
1622
1649
|
const response = await this.http.get(path, params);
|
|
@@ -1627,13 +1654,13 @@ var QueryBuilder = class {
|
|
|
1627
1654
|
return { data: null, error: response.error, count: null };
|
|
1628
1655
|
}
|
|
1629
1656
|
if (this.isSingle) {
|
|
1630
|
-
const item = response.data
|
|
1657
|
+
const item = (_c = (_b = (_a = response.data) == null ? void 0 : _a.data) == null ? void 0 : _b[0]) != null ? _c : null;
|
|
1631
1658
|
return { data: item, error: null };
|
|
1632
1659
|
}
|
|
1633
1660
|
return {
|
|
1634
|
-
data: response.data
|
|
1661
|
+
data: (_e = (_d = response.data) == null ? void 0 : _d.data) != null ? _e : [],
|
|
1635
1662
|
error: null,
|
|
1636
|
-
count: response.data
|
|
1663
|
+
count: (_g = (_f = response.data) == null ? void 0 : _f.count) != null ? _g : 0
|
|
1637
1664
|
};
|
|
1638
1665
|
}
|
|
1639
1666
|
/**
|
|
@@ -1642,15 +1669,16 @@ var QueryBuilder = class {
|
|
|
1642
1669
|
* @example .insert([{ name: 'iPhone' }, { name: 'iPad' }])
|
|
1643
1670
|
*/
|
|
1644
1671
|
async insert(data) {
|
|
1672
|
+
var _a, _b, _c, _d;
|
|
1645
1673
|
const path = this.getBasePath();
|
|
1646
1674
|
const response = await this.http.post(path, data);
|
|
1647
1675
|
if (response.error) {
|
|
1648
1676
|
return { data: null, error: response.error, count: 0 };
|
|
1649
1677
|
}
|
|
1650
1678
|
return {
|
|
1651
|
-
data: response.data
|
|
1679
|
+
data: (_b = (_a = response.data) == null ? void 0 : _a.data) != null ? _b : [],
|
|
1652
1680
|
error: null,
|
|
1653
|
-
count: response.data
|
|
1681
|
+
count: (_d = (_c = response.data) == null ? void 0 : _c.count) != null ? _d : 0
|
|
1654
1682
|
};
|
|
1655
1683
|
}
|
|
1656
1684
|
/**
|
|
@@ -1658,6 +1686,7 @@ var QueryBuilder = class {
|
|
|
1658
1686
|
* @example .update({ price: 899 }).eq('id', 123)
|
|
1659
1687
|
*/
|
|
1660
1688
|
async update(data) {
|
|
1689
|
+
var _a, _b, _c, _d;
|
|
1661
1690
|
const path = this.getBasePath();
|
|
1662
1691
|
const params = this.buildParams();
|
|
1663
1692
|
delete params["select"];
|
|
@@ -1669,9 +1698,9 @@ var QueryBuilder = class {
|
|
|
1669
1698
|
return { data: null, error: response.error, count: 0 };
|
|
1670
1699
|
}
|
|
1671
1700
|
return {
|
|
1672
|
-
data: response.data
|
|
1701
|
+
data: (_b = (_a = response.data) == null ? void 0 : _a.data) != null ? _b : [],
|
|
1673
1702
|
error: null,
|
|
1674
|
-
count: response.data
|
|
1703
|
+
count: (_d = (_c = response.data) == null ? void 0 : _c.count) != null ? _d : 0
|
|
1675
1704
|
};
|
|
1676
1705
|
}
|
|
1677
1706
|
/**
|
|
@@ -1679,6 +1708,7 @@ var QueryBuilder = class {
|
|
|
1679
1708
|
* @example .delete().eq('id', 123)
|
|
1680
1709
|
*/
|
|
1681
1710
|
async delete() {
|
|
1711
|
+
var _a, _b, _c, _d;
|
|
1682
1712
|
const path = this.getBasePath();
|
|
1683
1713
|
const params = this.buildParams();
|
|
1684
1714
|
delete params["select"];
|
|
@@ -1690,9 +1720,9 @@ var QueryBuilder = class {
|
|
|
1690
1720
|
return { data: null, error: response.error, count: 0 };
|
|
1691
1721
|
}
|
|
1692
1722
|
return {
|
|
1693
|
-
data: response.data
|
|
1723
|
+
data: (_b = (_a = response.data) == null ? void 0 : _a.data) != null ? _b : [],
|
|
1694
1724
|
error: null,
|
|
1695
|
-
count: response.data
|
|
1725
|
+
count: (_d = (_c = response.data) == null ? void 0 : _c.count) != null ? _d : 0
|
|
1696
1726
|
};
|
|
1697
1727
|
}
|
|
1698
1728
|
/**
|
|
@@ -1713,10 +1743,9 @@ var KrisspyClient = class {
|
|
|
1713
1743
|
this.useRLS = options.useRLS !== false;
|
|
1714
1744
|
this.http = new HttpClient({
|
|
1715
1745
|
baseUrl: this.baseUrl,
|
|
1716
|
-
headers: {
|
|
1717
|
-
...options.headers,
|
|
1746
|
+
headers: __spreadProps(__spreadValues({}, options.headers), {
|
|
1718
1747
|
"apikey": options.anonKey
|
|
1719
|
-
},
|
|
1748
|
+
}),
|
|
1720
1749
|
debug: options.debug
|
|
1721
1750
|
});
|
|
1722
1751
|
this._auth = new KrisspyAuth(this.http, this.backendId, options.storage);
|
|
@@ -1726,7 +1755,7 @@ var KrisspyClient = class {
|
|
|
1726
1755
|
this._auth.onAuthStateChange((event) => {
|
|
1727
1756
|
if (event === "SIGNED_IN") {
|
|
1728
1757
|
const session = this._auth.session();
|
|
1729
|
-
if (session
|
|
1758
|
+
if (session == null ? void 0 : session.access_token) {
|
|
1730
1759
|
this._realtime.setAuth(session.access_token);
|
|
1731
1760
|
}
|
|
1732
1761
|
} else if (event === "SIGNED_OUT") {
|
|
@@ -1893,12 +1922,13 @@ var KrisspyClient = class {
|
|
|
1893
1922
|
* const { data, error } = await krisspy.rpc('SELECT * FROM products WHERE price > $1', [100])
|
|
1894
1923
|
*/
|
|
1895
1924
|
async rpc(sql, params) {
|
|
1925
|
+
var _a, _b;
|
|
1896
1926
|
const path = `/api/v1/cloud-backends/${this.backendId}/sql`;
|
|
1897
1927
|
const response = await this.http.post(path, { sql, params });
|
|
1898
1928
|
if (response.error) {
|
|
1899
1929
|
return { data: null, error: response.error };
|
|
1900
1930
|
}
|
|
1901
|
-
return { data: response.data
|
|
1931
|
+
return { data: (_b = (_a = response.data) == null ? void 0 : _a.result) != null ? _b : null, error: null };
|
|
1902
1932
|
}
|
|
1903
1933
|
/**
|
|
1904
1934
|
* Invoke a serverless function
|
|
@@ -1912,19 +1942,20 @@ var KrisspyClient = class {
|
|
|
1912
1942
|
return {
|
|
1913
1943
|
invoke: async (functionName, options) => {
|
|
1914
1944
|
const path = `/api/v1/cloud-backends/${this.backendId}/functions/${functionName}/invoke`;
|
|
1915
|
-
const response = await this.http.post(path, options
|
|
1945
|
+
const response = await this.http.post(path, options == null ? void 0 : options.body, void 0);
|
|
1916
1946
|
if (response.error) {
|
|
1917
1947
|
return { data: null, error: response.error };
|
|
1918
1948
|
}
|
|
1919
1949
|
return { data: response.data, error: null };
|
|
1920
1950
|
},
|
|
1921
1951
|
list: async () => {
|
|
1952
|
+
var _a, _b;
|
|
1922
1953
|
const path = `/api/v1/cloud-backends/${this.backendId}/functions`;
|
|
1923
1954
|
const response = await this.http.get(path);
|
|
1924
1955
|
if (response.error) {
|
|
1925
1956
|
return { data: null, error: response.error };
|
|
1926
1957
|
}
|
|
1927
|
-
return { data: response.data
|
|
1958
|
+
return { data: (_b = (_a = response.data) == null ? void 0 : _a.functions) != null ? _b : [], error: null };
|
|
1928
1959
|
}
|
|
1929
1960
|
};
|
|
1930
1961
|
}
|
|
@@ -1943,23 +1974,25 @@ var KrisspyClient = class {
|
|
|
1943
1974
|
* List tables in the backend
|
|
1944
1975
|
*/
|
|
1945
1976
|
async listTables() {
|
|
1977
|
+
var _a, _b;
|
|
1946
1978
|
const path = `/api/v1/cloud-backends/${this.backendId}/tables`;
|
|
1947
1979
|
const response = await this.http.get(path);
|
|
1948
1980
|
if (response.error) {
|
|
1949
1981
|
return { data: null, error: response.error };
|
|
1950
1982
|
}
|
|
1951
|
-
return { data: response.data
|
|
1983
|
+
return { data: (_b = (_a = response.data) == null ? void 0 : _a.tables) != null ? _b : [], error: null };
|
|
1952
1984
|
}
|
|
1953
1985
|
/**
|
|
1954
1986
|
* Get table schema (columns)
|
|
1955
1987
|
*/
|
|
1956
1988
|
async getTableSchema(table) {
|
|
1989
|
+
var _a, _b;
|
|
1957
1990
|
const path = `/api/v1/cloud-backends/${this.backendId}/tables/${table}`;
|
|
1958
1991
|
const response = await this.http.get(path);
|
|
1959
1992
|
if (response.error) {
|
|
1960
1993
|
return { data: null, error: response.error };
|
|
1961
1994
|
}
|
|
1962
|
-
return { data: response.data
|
|
1995
|
+
return { data: (_b = (_a = response.data) == null ? void 0 : _a.columns) != null ? _b : [], error: null };
|
|
1963
1996
|
}
|
|
1964
1997
|
};
|
|
1965
1998
|
|