corebase-js 0.2.0 → 0.2.3
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/realtime.js +19 -5
- package/dist/storage.d.ts +2 -1
- package/dist/storage.js +3 -1
- package/package.json +1 -1
package/dist/realtime.js
CHANGED
|
@@ -11,8 +11,23 @@ class RealtimeClient {
|
|
|
11
11
|
this.auth = auth;
|
|
12
12
|
}
|
|
13
13
|
getUrl() {
|
|
14
|
+
var _a;
|
|
14
15
|
const baseUrl = this.config.baseUrl || 'http://localhost:3000';
|
|
15
|
-
|
|
16
|
+
let url = baseUrl.replace(/^http/, 'ws') + '/v1/realtime';
|
|
17
|
+
// Append Auth params for standard browser support (which doesn't support headers)
|
|
18
|
+
const params = new URLSearchParams();
|
|
19
|
+
if (this.config.apiKey) {
|
|
20
|
+
params.append('x-api-key', this.config.apiKey);
|
|
21
|
+
}
|
|
22
|
+
const token = (_a = this.auth.getSession()) === null || _a === void 0 ? void 0 : _a.access_token;
|
|
23
|
+
if (token) {
|
|
24
|
+
params.append('token', token);
|
|
25
|
+
}
|
|
26
|
+
const queryString = params.toString();
|
|
27
|
+
if (queryString) {
|
|
28
|
+
url += `?${queryString}`;
|
|
29
|
+
}
|
|
30
|
+
return url;
|
|
16
31
|
}
|
|
17
32
|
connect() {
|
|
18
33
|
var _a;
|
|
@@ -27,11 +42,12 @@ class RealtimeClient {
|
|
|
27
42
|
headers['Authorization'] = `Bearer ${token}`;
|
|
28
43
|
}
|
|
29
44
|
try {
|
|
30
|
-
//
|
|
45
|
+
// Try to pass headers (Node.js / React Native)
|
|
31
46
|
// @ts-ignore
|
|
32
|
-
this.ws = new WebSocket(url,
|
|
47
|
+
this.ws = new WebSocket(url, undefined, { headers });
|
|
33
48
|
}
|
|
34
49
|
catch (e) {
|
|
50
|
+
// Fallback for standard browsers
|
|
35
51
|
this.ws = new WebSocket(url);
|
|
36
52
|
}
|
|
37
53
|
if (!this.ws)
|
|
@@ -55,8 +71,6 @@ class RealtimeClient {
|
|
|
55
71
|
};
|
|
56
72
|
this.ws.onerror = (e) => {
|
|
57
73
|
console.error('CoreBase Realtime error', e);
|
|
58
|
-
// Do not close immediately on error, let onclose handle it?
|
|
59
|
-
// Sometimes error precedes close.
|
|
60
74
|
};
|
|
61
75
|
}
|
|
62
76
|
disconnect() {
|
package/dist/storage.d.ts
CHANGED
|
@@ -10,9 +10,10 @@ export declare class StorageClient {
|
|
|
10
10
|
* 2. Uploading the file content directly to the cloud storage provider via the signed URL.
|
|
11
11
|
*
|
|
12
12
|
* @param file The File object to upload.
|
|
13
|
+
* @param bucketName The name of the bucket to upload the file to.
|
|
13
14
|
* @returns The key of the uploaded file.
|
|
14
15
|
*/
|
|
15
|
-
upload(file: File): Promise<ClientResponse<{
|
|
16
|
+
upload(file: File, bucketName: string): Promise<ClientResponse<{
|
|
16
17
|
key: string;
|
|
17
18
|
url: string;
|
|
18
19
|
}>>;
|
package/dist/storage.js
CHANGED
|
@@ -21,9 +21,10 @@ class StorageClient {
|
|
|
21
21
|
* 2. Uploading the file content directly to the cloud storage provider via the signed URL.
|
|
22
22
|
*
|
|
23
23
|
* @param file The File object to upload.
|
|
24
|
+
* @param bucketName The name of the bucket to upload the file to.
|
|
24
25
|
* @returns The key of the uploaded file.
|
|
25
26
|
*/
|
|
26
|
-
upload(file) {
|
|
27
|
+
upload(file, bucketName) {
|
|
27
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
29
|
// 1. Get Signed URL
|
|
29
30
|
const { data: signData, error: signError } = yield this.auth.request('/storage/upload/sign', {
|
|
@@ -32,6 +33,7 @@ class StorageClient {
|
|
|
32
33
|
filename: file.name,
|
|
33
34
|
contentType: file.type,
|
|
34
35
|
size: file.size,
|
|
36
|
+
bucketName
|
|
35
37
|
}),
|
|
36
38
|
});
|
|
37
39
|
if (signError) {
|