@supabase/supabase-js 1.35.5 → 1.36.0-next.11
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/main/SupabaseClient.d.ts +33 -27
- package/dist/main/SupabaseClient.d.ts.map +1 -1
- package/dist/main/SupabaseClient.js +70 -69
- package/dist/main/SupabaseClient.js.map +1 -1
- package/dist/main/index.d.ts +6 -5
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +3 -2
- package/dist/main/index.js.map +1 -1
- package/dist/main/lib/SupabaseRealtimeClient.d.ts +10 -7
- package/dist/main/lib/SupabaseRealtimeClient.d.ts.map +1 -1
- package/dist/main/lib/SupabaseRealtimeClient.js +42 -28
- package/dist/main/lib/SupabaseRealtimeClient.js.map +1 -1
- package/dist/main/lib/constants.d.ts +0 -1
- package/dist/main/lib/constants.d.ts.map +1 -1
- package/dist/main/lib/constants.js +1 -2
- package/dist/main/lib/constants.js.map +1 -1
- package/dist/main/lib/fetch.d.ts +9 -0
- package/dist/main/lib/fetch.d.ts.map +1 -0
- package/dist/main/lib/fetch.js +75 -0
- package/dist/main/lib/fetch.js.map +1 -0
- package/dist/main/lib/types.d.ts +51 -34
- package/dist/main/lib/types.d.ts.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/module/SupabaseClient.d.ts +33 -27
- package/dist/module/SupabaseClient.d.ts.map +1 -1
- package/dist/module/SupabaseClient.js +71 -70
- package/dist/module/SupabaseClient.js.map +1 -1
- package/dist/module/index.d.ts +6 -5
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +2 -2
- package/dist/module/index.js.map +1 -1
- package/dist/module/lib/SupabaseRealtimeClient.d.ts +10 -7
- package/dist/module/lib/SupabaseRealtimeClient.d.ts.map +1 -1
- package/dist/module/lib/SupabaseRealtimeClient.js +42 -28
- package/dist/module/lib/SupabaseRealtimeClient.js.map +1 -1
- package/dist/module/lib/constants.d.ts +0 -1
- package/dist/module/lib/constants.d.ts.map +1 -1
- package/dist/module/lib/constants.js +0 -1
- package/dist/module/lib/constants.js.map +1 -1
- package/dist/module/lib/fetch.d.ts +9 -0
- package/dist/module/lib/fetch.d.ts.map +1 -0
- package/dist/module/lib/fetch.js +46 -0
- package/dist/module/lib/fetch.js.map +1 -0
- package/dist/module/lib/types.d.ts +51 -34
- package/dist/module/lib/types.d.ts.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.js +1 -1
- package/dist/umd/supabase.js +1 -1
- package/package.json +7 -6
- package/src/SupabaseClient.ts +128 -102
- package/src/index.ts +17 -15
- package/src/lib/SupabaseRealtimeClient.ts +50 -33
- package/src/lib/constants.ts +0 -1
- package/src/lib/fetch.ts +47 -0
- package/src/lib/types.ts +53 -36
- package/src/lib/version.ts +1 -1
- package/dist/main/lib/SupabaseQueryBuilder.d.ts +0 -26
- package/dist/main/lib/SupabaseQueryBuilder.d.ts.map +0 -1
- package/dist/main/lib/SupabaseQueryBuilder.js +0 -31
- package/dist/main/lib/SupabaseQueryBuilder.js.map +0 -1
- package/dist/module/lib/SupabaseQueryBuilder.d.ts +0 -26
- package/dist/module/lib/SupabaseQueryBuilder.d.ts.map +0 -1
- package/dist/module/lib/SupabaseQueryBuilder.js +0 -27
- package/dist/module/lib/SupabaseQueryBuilder.js.map +0 -1
- package/dist/umd/98.supabase.js +0 -1
- package/src/lib/SupabaseQueryBuilder.ts +0 -61
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
import { Fetch, SupabaseClientOptions } from './lib/types';
|
|
2
|
-
import { SupabaseAuthClient } from './lib/SupabaseAuthClient';
|
|
3
|
-
import { SupabaseQueryBuilder } from './lib/SupabaseQueryBuilder';
|
|
4
|
-
import { SupabaseStorageClient } from '@supabase/storage-js';
|
|
5
1
|
import { FunctionsClient } from '@supabase/functions-js';
|
|
6
|
-
import {
|
|
2
|
+
import { PostgrestClient, PostgrestFilterBuilder, PostgrestQueryBuilder } from '@supabase/postgrest-js';
|
|
3
|
+
import { RealtimeChannel, RealtimeClient } from '@supabase/realtime-js';
|
|
4
|
+
import { SupabaseStorageClient } from '@supabase/storage-js';
|
|
5
|
+
import { SupabaseAuthClient } from './lib/SupabaseAuthClient';
|
|
6
|
+
import { SupabaseRealtimeClient } from './lib/SupabaseRealtimeClient';
|
|
7
|
+
import { Fetch, GenericSchema, SupabaseClientOptions } from './lib/types';
|
|
7
8
|
/**
|
|
8
9
|
* Supabase Client.
|
|
9
10
|
*
|
|
10
11
|
* An isomorphic Javascript client for interacting with Postgres.
|
|
11
12
|
*/
|
|
12
|
-
export default class SupabaseClient {
|
|
13
|
+
export default class SupabaseClient<Database = any, SchemaName extends string & keyof Database = 'public' extends keyof Database ? 'public' : string & keyof Database, Schema extends GenericSchema = Database[SchemaName] extends GenericSchema ? Database[SchemaName] : any> {
|
|
13
14
|
protected supabaseUrl: string;
|
|
14
15
|
protected supabaseKey: string;
|
|
15
16
|
/**
|
|
16
17
|
* Supabase Auth allows you to create and manage user sessions for access to data that is secured by access policies.
|
|
17
18
|
*/
|
|
18
19
|
auth: SupabaseAuthClient;
|
|
19
|
-
protected schema: string;
|
|
20
|
-
protected restUrl: string;
|
|
21
20
|
protected realtimeUrl: string;
|
|
22
21
|
protected authUrl: string;
|
|
23
22
|
protected storageUrl: string;
|
|
24
23
|
protected functionsUrl: string;
|
|
25
24
|
protected realtime: RealtimeClient;
|
|
25
|
+
protected rest: PostgrestClient<Database, SchemaName>;
|
|
26
26
|
protected multiTab: boolean;
|
|
27
|
+
protected storageKey: string;
|
|
27
28
|
protected fetch?: Fetch;
|
|
28
29
|
protected changedAccessToken: string | undefined;
|
|
29
30
|
protected shouldThrowOnError: boolean;
|
|
@@ -43,7 +44,7 @@ export default class SupabaseClient {
|
|
|
43
44
|
* @param options.multiTab Set to "false" if you want to disable multi-tab/window events.
|
|
44
45
|
* @param options.fetch A custom fetch implementation.
|
|
45
46
|
*/
|
|
46
|
-
constructor(supabaseUrl: string, supabaseKey: string, options?: SupabaseClientOptions);
|
|
47
|
+
constructor(supabaseUrl: string, supabaseKey: string, options?: SupabaseClientOptions<SchemaName>);
|
|
47
48
|
/**
|
|
48
49
|
* Supabase Functions allows you to deploy and invoke edge functions.
|
|
49
50
|
*/
|
|
@@ -57,7 +58,7 @@ export default class SupabaseClient {
|
|
|
57
58
|
*
|
|
58
59
|
* @param table The table name to operate on.
|
|
59
60
|
*/
|
|
60
|
-
from<
|
|
61
|
+
from<TableName extends string & keyof Schema['Tables'], Table extends Schema['Tables'][TableName]>(table: TableName): PostgrestQueryBuilder<Table>;
|
|
61
62
|
/**
|
|
62
63
|
* Perform a function call.
|
|
63
64
|
*
|
|
@@ -67,41 +68,46 @@ export default class SupabaseClient {
|
|
|
67
68
|
* @param count Count algorithm to use to count rows in a table.
|
|
68
69
|
*
|
|
69
70
|
*/
|
|
70
|
-
rpc<
|
|
71
|
+
rpc<FunctionName extends string & keyof Schema['Functions'], Function_ extends Schema['Functions'][FunctionName]>(fn: FunctionName, args?: Function_['Args'], options?: {
|
|
71
72
|
head?: boolean;
|
|
72
|
-
count?:
|
|
73
|
-
}):
|
|
73
|
+
count?: 'exact' | 'planned' | 'estimated';
|
|
74
|
+
}): PostgrestFilterBuilder<Function_['Returns'] extends any[] ? Function_['Returns'][number] extends Record<string, unknown> ? Function_['Returns'][number] : never : never, Function_['Returns']>;
|
|
75
|
+
/**
|
|
76
|
+
* Creates a channel with Broadcast and Presence.
|
|
77
|
+
*/
|
|
78
|
+
channel(name: string, opts?: {
|
|
79
|
+
[key: string]: any;
|
|
80
|
+
}): SupabaseRealtimeClient;
|
|
74
81
|
/**
|
|
75
|
-
* Closes and removes all
|
|
76
|
-
*
|
|
82
|
+
* Closes and removes all channels and returns a list of removed
|
|
83
|
+
* channels and their errors.
|
|
77
84
|
*/
|
|
78
|
-
|
|
85
|
+
removeAllChannels(): Promise<{
|
|
79
86
|
data: {
|
|
80
|
-
|
|
87
|
+
channels: RealtimeChannel;
|
|
81
88
|
};
|
|
82
89
|
error: Error | null;
|
|
83
90
|
}[]>;
|
|
84
91
|
/**
|
|
85
|
-
* Closes and removes a
|
|
92
|
+
* Closes and removes a channel and returns the number of open channels.
|
|
86
93
|
*
|
|
87
|
-
* @param
|
|
94
|
+
* @param channel The channel you want to close and remove.
|
|
88
95
|
*/
|
|
89
|
-
|
|
96
|
+
removeChannel(channel: RealtimeChannel): Promise<{
|
|
90
97
|
data: {
|
|
91
|
-
|
|
98
|
+
openChannels: number;
|
|
92
99
|
};
|
|
93
100
|
error: Error | null;
|
|
94
101
|
}>;
|
|
95
|
-
private
|
|
96
|
-
private
|
|
102
|
+
private _getAccessToken;
|
|
103
|
+
private _closeChannel;
|
|
104
|
+
private _unsubscribeChannel;
|
|
97
105
|
/**
|
|
98
|
-
* Returns an array of all your
|
|
106
|
+
* Returns an array of all your channels.
|
|
99
107
|
*/
|
|
100
|
-
|
|
108
|
+
getChannels(): RealtimeChannel[];
|
|
101
109
|
private _initSupabaseAuthClient;
|
|
102
110
|
private _initRealtimeClient;
|
|
103
|
-
private _initPostgRESTClient;
|
|
104
|
-
private _getAuthHeaders;
|
|
105
111
|
private _listenForMultiTabEvents;
|
|
106
112
|
private _listenForAuthEvents;
|
|
107
113
|
private _handleTokenChanged;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SupabaseClient.d.ts","sourceRoot":"","sources":["../../src/SupabaseClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SupabaseClient.d.ts","sourceRoot":"","sources":["../../src/SupabaseClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAExD,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAyB,MAAM,uBAAuB,CAAA;AAC9F,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAA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,EAAE,eAAe,CAAA;SAAE,CAAC;QAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;KAAE,EAAE,CAC/D;IAaD;;;;OAIG;IACG,aAAa,CACjB,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC;QAAE,IAAI,EAAE;YAAE,YAAY,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;KAAE,CAAC;YAUrD,eAAe;YAMf,aAAa;IAa3B,OAAO,CAAC,mBAAmB;IAU3B;;OAEG;IACH,WAAW,IAAI,eAAe,EAAE;IAIhC,OAAO,CAAC,uBAAuB;IA+B/B,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,wBAAwB;IA2BhC,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,mBAAmB;CAsB5B"}
|
|
@@ -9,14 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const constants_1 = require("./lib/constants");
|
|
13
|
-
const helpers_1 = require("./lib/helpers");
|
|
14
|
-
const SupabaseAuthClient_1 = require("./lib/SupabaseAuthClient");
|
|
15
|
-
const SupabaseQueryBuilder_1 = require("./lib/SupabaseQueryBuilder");
|
|
16
|
-
const storage_js_1 = require("@supabase/storage-js");
|
|
17
12
|
const functions_js_1 = require("@supabase/functions-js");
|
|
18
13
|
const postgrest_js_1 = require("@supabase/postgrest-js");
|
|
19
14
|
const realtime_js_1 = require("@supabase/realtime-js");
|
|
15
|
+
const storage_js_1 = require("@supabase/storage-js");
|
|
16
|
+
const constants_1 = require("./lib/constants");
|
|
17
|
+
const fetch_1 = require("./lib/fetch");
|
|
18
|
+
const helpers_1 = require("./lib/helpers");
|
|
19
|
+
const SupabaseAuthClient_1 = require("./lib/SupabaseAuthClient");
|
|
20
|
+
const SupabaseRealtimeClient_1 = require("./lib/SupabaseRealtimeClient");
|
|
20
21
|
const DEFAULT_OPTIONS = {
|
|
21
22
|
schema: 'public',
|
|
22
23
|
autoRefreshToken: true,
|
|
@@ -45,6 +46,7 @@ class SupabaseClient {
|
|
|
45
46
|
* @param options.fetch A custom fetch implementation.
|
|
46
47
|
*/
|
|
47
48
|
constructor(supabaseUrl, supabaseKey, options) {
|
|
49
|
+
var _a, _b, _c, _d, _e;
|
|
48
50
|
this.supabaseUrl = supabaseUrl;
|
|
49
51
|
this.supabaseKey = supabaseKey;
|
|
50
52
|
if (!supabaseUrl)
|
|
@@ -52,8 +54,6 @@ class SupabaseClient {
|
|
|
52
54
|
if (!supabaseKey)
|
|
53
55
|
throw new Error('supabaseKey is required.');
|
|
54
56
|
const _supabaseUrl = (0, helpers_1.stripTrailingSlash)(supabaseUrl);
|
|
55
|
-
const settings = Object.assign(Object.assign({}, DEFAULT_OPTIONS), options);
|
|
56
|
-
this.restUrl = `${_supabaseUrl}/rest/v1`;
|
|
57
57
|
this.realtimeUrl = `${_supabaseUrl}/realtime/v1`.replace('http', 'ws');
|
|
58
58
|
this.authUrl = `${_supabaseUrl}/auth/v1`;
|
|
59
59
|
this.storageUrl = `${_supabaseUrl}/storage/v1`;
|
|
@@ -65,13 +65,22 @@ class SupabaseClient {
|
|
|
65
65
|
else {
|
|
66
66
|
this.functionsUrl = `${_supabaseUrl}/functions/v1`;
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.
|
|
68
|
+
// default storage key uses the supabase project ref as a namespace
|
|
69
|
+
const defaultStorageKey = `sb-${new URL(this.authUrl).hostname.split('.')[0]}-auth-token`;
|
|
70
|
+
this.storageKey = (_b = (_a = options === null || options === void 0 ? void 0 : options.auth) === null || _a === void 0 ? void 0 : _a.storageKey) !== null && _b !== void 0 ? _b : defaultStorageKey;
|
|
71
|
+
const settings = Object.assign(Object.assign(Object.assign({}, DEFAULT_OPTIONS), options), { storageKey: this.storageKey });
|
|
72
|
+
this.multiTab = (_d = (_c = settings.auth) === null || _c === void 0 ? void 0 : _c.multiTab) !== null && _d !== void 0 ? _d : false;
|
|
71
73
|
this.headers = Object.assign(Object.assign({}, constants_1.DEFAULT_HEADERS), options === null || options === void 0 ? void 0 : options.headers);
|
|
72
74
|
this.shouldThrowOnError = settings.shouldThrowOnError || false;
|
|
73
|
-
this.auth = this._initSupabaseAuthClient(settings);
|
|
75
|
+
this.auth = this._initSupabaseAuthClient(settings.auth || {}, this.headers, settings.fetch);
|
|
76
|
+
this.fetch = (0, fetch_1.fetchWithAuth)(supabaseKey, this._getAccessToken.bind(this), settings.fetch);
|
|
74
77
|
this.realtime = this._initRealtimeClient(Object.assign({ headers: this.headers }, settings.realtime));
|
|
78
|
+
this.rest = new postgrest_js_1.PostgrestClient(`${_supabaseUrl}/rest/v1`, {
|
|
79
|
+
headers: this.headers,
|
|
80
|
+
schema: (_e = options === null || options === void 0 ? void 0 : options.db) === null || _e === void 0 ? void 0 : _e.schema,
|
|
81
|
+
fetch: this.fetch,
|
|
82
|
+
throwOnError: this.shouldThrowOnError,
|
|
83
|
+
});
|
|
75
84
|
this._listenForAuthEvents();
|
|
76
85
|
this._listenForMultiTabEvents();
|
|
77
86
|
// In the future we might allow the user to pass in a logger to receive these events.
|
|
@@ -84,7 +93,7 @@ class SupabaseClient {
|
|
|
84
93
|
*/
|
|
85
94
|
get functions() {
|
|
86
95
|
return new functions_js_1.FunctionsClient(this.functionsUrl, {
|
|
87
|
-
headers: this.
|
|
96
|
+
headers: this.headers,
|
|
88
97
|
customFetch: this.fetch,
|
|
89
98
|
});
|
|
90
99
|
}
|
|
@@ -92,7 +101,7 @@ class SupabaseClient {
|
|
|
92
101
|
* Supabase Storage allows you to manage user-generated content, such as photos or videos.
|
|
93
102
|
*/
|
|
94
103
|
get storage() {
|
|
95
|
-
return new storage_js_1.SupabaseStorageClient(this.storageUrl, this.
|
|
104
|
+
return new storage_js_1.SupabaseStorageClient(this.storageUrl, this.headers, this.fetch);
|
|
96
105
|
}
|
|
97
106
|
/**
|
|
98
107
|
* Perform a table operation.
|
|
@@ -100,15 +109,7 @@ class SupabaseClient {
|
|
|
100
109
|
* @param table The table name to operate on.
|
|
101
110
|
*/
|
|
102
111
|
from(table) {
|
|
103
|
-
|
|
104
|
-
return new SupabaseQueryBuilder_1.SupabaseQueryBuilder(url, {
|
|
105
|
-
headers: this._getAuthHeaders(),
|
|
106
|
-
schema: this.schema,
|
|
107
|
-
realtime: this.realtime,
|
|
108
|
-
table,
|
|
109
|
-
fetch: this.fetch,
|
|
110
|
-
shouldThrowOnError: this.shouldThrowOnError,
|
|
111
|
-
});
|
|
112
|
+
return this.rest.from(table);
|
|
112
113
|
}
|
|
113
114
|
/**
|
|
114
115
|
* Perform a function call.
|
|
@@ -119,56 +120,71 @@ class SupabaseClient {
|
|
|
119
120
|
* @param count Count algorithm to use to count rows in a table.
|
|
120
121
|
*
|
|
121
122
|
*/
|
|
122
|
-
rpc(fn,
|
|
123
|
-
|
|
124
|
-
return rest.rpc(fn, params, { head, count });
|
|
123
|
+
rpc(fn, args = {}, options) {
|
|
124
|
+
return this.rest.rpc(fn, args, options);
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
|
-
*
|
|
128
|
-
* subscriptions and their errors.
|
|
127
|
+
* Creates a channel with Broadcast and Presence.
|
|
129
128
|
*/
|
|
130
|
-
|
|
129
|
+
channel(name, opts) {
|
|
130
|
+
if (!this.realtime.isConnected()) {
|
|
131
|
+
this.realtime.connect();
|
|
132
|
+
}
|
|
133
|
+
return new SupabaseRealtimeClient_1.SupabaseRealtimeClient(this.realtime, name, opts);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Closes and removes all channels and returns a list of removed
|
|
137
|
+
* channels and their errors.
|
|
138
|
+
*/
|
|
139
|
+
removeAllChannels() {
|
|
131
140
|
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
return
|
|
141
|
+
const allChans = this.getChannels().slice();
|
|
142
|
+
const allChanPromises = allChans.map((chan) => this.removeChannel(chan));
|
|
143
|
+
const allRemovedChans = yield Promise.all(allChanPromises);
|
|
144
|
+
return allRemovedChans.map(({ error }, i) => {
|
|
136
145
|
return {
|
|
137
|
-
data: {
|
|
146
|
+
data: { channels: allChans[i] },
|
|
138
147
|
error,
|
|
139
148
|
};
|
|
140
149
|
});
|
|
141
150
|
});
|
|
142
151
|
}
|
|
143
152
|
/**
|
|
144
|
-
* Closes and removes a
|
|
153
|
+
* Closes and removes a channel and returns the number of open channels.
|
|
145
154
|
*
|
|
146
|
-
* @param
|
|
155
|
+
* @param channel The channel you want to close and remove.
|
|
147
156
|
*/
|
|
148
|
-
|
|
157
|
+
removeChannel(channel) {
|
|
149
158
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
const { error } = yield this.
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
if (
|
|
159
|
+
const { error } = yield this._closeChannel(channel);
|
|
160
|
+
const allChans = this.getChannels();
|
|
161
|
+
const openChanCount = allChans.filter((chan) => chan.isJoined()).length;
|
|
162
|
+
if (allChans.length === 0)
|
|
154
163
|
yield this.realtime.disconnect();
|
|
155
|
-
return { data: {
|
|
164
|
+
return { data: { openChannels: openChanCount }, error };
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
_getAccessToken() {
|
|
168
|
+
var _a;
|
|
169
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
const { session } = yield this.auth.getSession();
|
|
171
|
+
return (_a = session === null || session === void 0 ? void 0 : session.access_token) !== null && _a !== void 0 ? _a : null;
|
|
156
172
|
});
|
|
157
173
|
}
|
|
158
|
-
|
|
174
|
+
_closeChannel(channel) {
|
|
159
175
|
return __awaiter(this, void 0, void 0, function* () {
|
|
160
176
|
let error = null;
|
|
161
|
-
if (!
|
|
162
|
-
const { error: unsubError } = yield this.
|
|
177
|
+
if (!channel.isClosed()) {
|
|
178
|
+
const { error: unsubError } = yield this._unsubscribeChannel(channel);
|
|
163
179
|
error = unsubError;
|
|
164
180
|
}
|
|
165
|
-
this.realtime.remove(
|
|
181
|
+
this.realtime.remove(channel);
|
|
166
182
|
return { error };
|
|
167
183
|
});
|
|
168
184
|
}
|
|
169
|
-
|
|
185
|
+
_unsubscribeChannel(channel) {
|
|
170
186
|
return new Promise((resolve) => {
|
|
171
|
-
|
|
187
|
+
channel
|
|
172
188
|
.unsubscribe()
|
|
173
189
|
.receive('ok', () => resolve({ error: null }))
|
|
174
190
|
.receive('error', (error) => resolve({ error }))
|
|
@@ -176,12 +192,12 @@ class SupabaseClient {
|
|
|
176
192
|
});
|
|
177
193
|
}
|
|
178
194
|
/**
|
|
179
|
-
* Returns an array of all your
|
|
195
|
+
* Returns an array of all your channels.
|
|
180
196
|
*/
|
|
181
|
-
|
|
197
|
+
getChannels() {
|
|
182
198
|
return this.realtime.channels;
|
|
183
199
|
}
|
|
184
|
-
_initSupabaseAuthClient({ autoRefreshToken, persistSession, detectSessionInUrl, localStorage,
|
|
200
|
+
_initSupabaseAuthClient({ autoRefreshToken, persistSession, detectSessionInUrl, localStorage, cookieOptions, multiTab, storageKey, }, headers, fetch) {
|
|
185
201
|
const authHeaders = {
|
|
186
202
|
Authorization: `Bearer ${this.supabaseKey}`,
|
|
187
203
|
apikey: `${this.supabaseKey}`,
|
|
@@ -189,6 +205,7 @@ class SupabaseClient {
|
|
|
189
205
|
return new SupabaseAuthClient_1.SupabaseAuthClient({
|
|
190
206
|
url: this.authUrl,
|
|
191
207
|
headers: Object.assign(Object.assign({}, headers), authHeaders),
|
|
208
|
+
storageKey: storageKey,
|
|
192
209
|
autoRefreshToken,
|
|
193
210
|
persistSession,
|
|
194
211
|
detectSessionInUrl,
|
|
@@ -199,23 +216,7 @@ class SupabaseClient {
|
|
|
199
216
|
});
|
|
200
217
|
}
|
|
201
218
|
_initRealtimeClient(options) {
|
|
202
|
-
return new realtime_js_1.RealtimeClient(this.realtimeUrl, Object.assign(Object.assign({}, options), { params: Object.assign(
|
|
203
|
-
}
|
|
204
|
-
_initPostgRESTClient() {
|
|
205
|
-
return new postgrest_js_1.PostgrestClient(this.restUrl, {
|
|
206
|
-
headers: this._getAuthHeaders(),
|
|
207
|
-
schema: this.schema,
|
|
208
|
-
fetch: this.fetch,
|
|
209
|
-
throwOnError: this.shouldThrowOnError,
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
_getAuthHeaders() {
|
|
213
|
-
var _a, _b;
|
|
214
|
-
const headers = Object.assign({}, this.headers);
|
|
215
|
-
const authBearer = (_b = (_a = this.auth.session()) === null || _a === void 0 ? void 0 : _a.access_token) !== null && _b !== void 0 ? _b : this.supabaseKey;
|
|
216
|
-
headers['apikey'] = this.supabaseKey;
|
|
217
|
-
headers['Authorization'] = headers['Authorization'] || `Bearer ${authBearer}`;
|
|
218
|
-
return headers;
|
|
219
|
+
return new realtime_js_1.RealtimeClient(this.realtimeUrl, Object.assign(Object.assign({}, options), { params: Object.assign({ apikey: this.supabaseKey, vsndate: '2022' }, options === null || options === void 0 ? void 0 : options.params) }));
|
|
219
220
|
}
|
|
220
221
|
_listenForMultiTabEvents() {
|
|
221
222
|
if (!this.multiTab || !(0, helpers_1.isBrowser)() || !(window === null || window === void 0 ? void 0 : window.addEventListener)) {
|
|
@@ -224,7 +225,7 @@ class SupabaseClient {
|
|
|
224
225
|
try {
|
|
225
226
|
return window === null || window === void 0 ? void 0 : window.addEventListener('storage', (e) => {
|
|
226
227
|
var _a, _b, _c;
|
|
227
|
-
if (e.key ===
|
|
228
|
+
if (e.key === this.storageKey) {
|
|
228
229
|
const newSession = JSON.parse(String(e.newValue));
|
|
229
230
|
const accessToken = (_b = (_a = newSession === null || newSession === void 0 ? void 0 : newSession.currentSession) === null || _a === void 0 ? void 0 : _a.access_token) !== null && _b !== void 0 ? _b : undefined;
|
|
230
231
|
const previousAccessToken = (_c = this.auth.session()) === null || _c === void 0 ? void 0 : _c.access_token;
|
|
@@ -246,7 +247,7 @@ class SupabaseClient {
|
|
|
246
247
|
}
|
|
247
248
|
}
|
|
248
249
|
_listenForAuthEvents() {
|
|
249
|
-
let
|
|
250
|
+
let data = this.auth.onAuthStateChange((event, session) => {
|
|
250
251
|
this._handleTokenChanged(event, session === null || session === void 0 ? void 0 : session.access_token, 'CLIENT');
|
|
251
252
|
});
|
|
252
253
|
return data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SupabaseClient.js","sourceRoot":"","sources":["../../src/SupabaseClient.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"SupabaseClient.js","sourceRoot":"","sources":["../../src/SupabaseClient.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,yDAAwD;AAExD,yDAI+B;AAC/B,uDAA8F;AAC9F,qDAA4D;AAC5D,+CAAiD;AACjD,uCAA2C;AAC3C,2CAA6D;AAC7D,iEAA6D;AAC7D,yEAAqE;AAGrE,MAAM,eAAe,GAAG;IACtB,MAAM,EAAE,QAAQ;IAChB,gBAAgB,EAAE,IAAI;IACtB,cAAc,EAAE,IAAI;IACpB,kBAAkB,EAAE,IAAI;IACxB,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,2BAAe;CACzB,CAAA;AAED;;;;GAIG;AACH,MAAqB,cAAc;IA8BjC;;;;;;;;;;;;OAYG;IACH,YACY,WAAmB,EACnB,WAAmB,EAC7B,OAA2C;;QAFjC,gBAAW,GAAX,WAAW,CAAQ;QACnB,gBAAW,GAAX,WAAW,CAAQ;QAG7B,IAAI,CAAC,WAAW;YAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;QAC7D,IAAI,CAAC,WAAW;YAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;QAE7D,MAAM,YAAY,GAAG,IAAA,4BAAkB,EAAC,WAAW,CAAC,CAAA;QAEpD,IAAI,CAAC,WAAW,GAAG,GAAG,YAAY,cAAc,CAAC,OAAO,CAAC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yB,EACzB,MAA4B;QAE5B,IACE,CAAC,KAAK,KAAK,iBAAiB,IAAI,KAAK,KAAK,WAAW,CAAC;YACtD,IAAI,CAAC,kBAAkB,KAAK,KAAK,EACjC;YACA,oBAAoB;YACpB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAM,CAAC,CAAA;YAC7B,0EAA0E;YAC1E,iDAAiD;YACjD,IAAI,MAAM,IAAI,SAAS;gBAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAM,CAAC,CAAA;YAElD,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAA;SAChC;aAAM,IAAI,KAAK,KAAK,YAAY,IAAI,KAAK,KAAK,cAAc,EAAE;YAC7D,mBAAmB;YACnB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;YACvC,IAAI,MAAM,IAAI,SAAS;gBAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAA;SAC7C;IACH,CAAC;CACF;AA1UD,iCA0UC"}
|
package/dist/main/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import SupabaseClient from './SupabaseClient';
|
|
2
|
-
import {
|
|
3
|
-
import { User as AuthUser, Session as AuthSession } from '@supabase/gotrue-js';
|
|
2
|
+
import type { GenericSchema, SupabaseClientOptions } from './lib/types';
|
|
4
3
|
export * from '@supabase/gotrue-js';
|
|
5
|
-
export {
|
|
4
|
+
export type { User as AuthUser, Session as AuthSession } from '@supabase/gotrue-js';
|
|
5
|
+
export type { PostgrestResponse, PostgrestSingleResponse, PostgrestMaybeSingleResponse, PostgrestError, } from '@supabase/postgrest-js';
|
|
6
6
|
export * from '@supabase/realtime-js';
|
|
7
|
+
export { default as SupabaseClient } from './SupabaseClient';
|
|
8
|
+
export type { SupabaseClientOptions, SupabaseRealtimePayload } from './lib/types';
|
|
7
9
|
/**
|
|
8
10
|
* Creates a new Supabase Client.
|
|
9
11
|
*/
|
|
10
|
-
declare const createClient: (supabaseUrl: string, supabaseKey: string, options?: SupabaseClientOptions | undefined) => SupabaseClient
|
|
11
|
-
export { createClient, SupabaseClient, SupabaseClientOptions, SupabaseRealtimePayload, AuthUser, AuthSession, };
|
|
12
|
+
export declare const createClient: <Database = any, SchemaName extends string & keyof Database = "public" extends keyof Database ? "public" : string & keyof Database, Schema extends GenericSchema = Database[SchemaName] extends GenericSchema ? Database[SchemaName] : any>(supabaseUrl: string, supabaseKey: string, options?: SupabaseClientOptions<SchemaName> | undefined) => SupabaseClient<Database, SchemaName, Schema>;
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/main/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAEvE,cAAc,qBAAqB,CAAA;AACnC,YAAY,EAAE,IAAI,IAAI,QAAQ,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACnF,YAAY,EACV,iBAAiB,EACjB,uBAAuB,EACvB,4BAA4B,EAC5B,cAAc,GACf,MAAM,wBAAwB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAC5D,YAAY,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAEjF;;GAEG;AACH,eAAO,MAAM,YAAY,2PASV,MAAM,eACN,MAAM,0GAIpB,CAAA"}
|
package/dist/main/index.js
CHANGED
|
@@ -17,11 +17,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.createClient = exports.SupabaseClient = void 0;
|
|
21
21
|
const SupabaseClient_1 = __importDefault(require("./SupabaseClient"));
|
|
22
|
-
exports.SupabaseClient = SupabaseClient_1.default;
|
|
23
22
|
__exportStar(require("@supabase/gotrue-js"), exports);
|
|
24
23
|
__exportStar(require("@supabase/realtime-js"), exports);
|
|
24
|
+
var SupabaseClient_2 = require("./SupabaseClient");
|
|
25
|
+
Object.defineProperty(exports, "SupabaseClient", { enumerable: true, get: function () { return __importDefault(SupabaseClient_2).default; } });
|
|
25
26
|
/**
|
|
26
27
|
* Creates a new Supabase Client.
|
|
27
28
|
*/
|
package/dist/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,sEAA6C;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,sEAA6C;AAG7C,sDAAmC;AAQnC,wDAAqC;AACrC,mDAA4D;AAAnD,iIAAA,OAAO,OAAkB;AAGlC;;GAEG;AACI,MAAM,YAAY,GAAG,CAS1B,WAAmB,EACnB,WAAmB,EACnB,OAA2C,EACG,EAAE;IAChD,OAAO,IAAI,wBAAc,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,CAAA;AAC9D,CAAC,CAAA;AAdY,QAAA,YAAY,gBAcxB"}
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GenericObject, SupabaseEventTypes, SupabaseRealtimePayload } from './types';
|
|
1
|
+
import { RealtimeChannel, RealtimeClient } from '@supabase/realtime-js';
|
|
3
2
|
export declare class SupabaseRealtimeClient {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
socket: RealtimeClient;
|
|
4
|
+
channel: RealtimeChannel;
|
|
5
|
+
constructor(socket: RealtimeClient, name: string, opts?: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
});
|
|
6
8
|
private getPayloadRecords;
|
|
7
9
|
/**
|
|
8
10
|
* The event you want to listen to.
|
|
9
11
|
*
|
|
10
12
|
* @param event The event
|
|
13
|
+
* @param filter An object that specifies what you want to listen to from the event.
|
|
11
14
|
* @param callback A callback function that is called whenever the event occurs.
|
|
12
15
|
*/
|
|
13
|
-
on(event:
|
|
16
|
+
on(event: string, filter?: Record<string, string>, callback?: (payload: any) => void): this;
|
|
14
17
|
/**
|
|
15
|
-
* Enables the
|
|
18
|
+
* Enables the channel.
|
|
16
19
|
*/
|
|
17
|
-
subscribe(callback?: Function):
|
|
20
|
+
subscribe(callback?: Function): RealtimeChannel;
|
|
18
21
|
}
|
|
19
22
|
//# sourceMappingURL=SupabaseRealtimeClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SupabaseRealtimeClient.d.ts","sourceRoot":"","sources":["../../../src/lib/SupabaseRealtimeClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"SupabaseRealtimeClient.d.ts","sourceRoot":"","sources":["../../../src/lib/SupabaseRealtimeClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAgB,MAAM,uBAAuB,CAAA;AAGrF,qBAAa,sBAAsB;IACjC,MAAM,EAAE,cAAc,CAAA;IACtB,OAAO,EAAE,eAAe,CAAA;gBAEZ,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAO;IAKnF,OAAO,CAAC,iBAAiB;IAiBzB;;;;;;OAMG;IACH,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI;IAwBpF;;OAEG;IACH,SAAS,CAAC,QAAQ,GAAE,QAAmB;CA2BxC"}
|
|
@@ -3,14 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SupabaseRealtimeClient = void 0;
|
|
4
4
|
const realtime_js_1 = require("@supabase/realtime-js");
|
|
5
5
|
class SupabaseRealtimeClient {
|
|
6
|
-
constructor(socket,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const userToken = headers['Authorization'].split(' ')[1];
|
|
10
|
-
if (userToken) {
|
|
11
|
-
chanParams['user_token'] = userToken;
|
|
12
|
-
}
|
|
13
|
-
this.subscription = socket.channel(topic, chanParams);
|
|
6
|
+
constructor(socket, name, opts = {}) {
|
|
7
|
+
this.socket = socket;
|
|
8
|
+
this.channel = socket.channel(`realtime:${name}`, opts);
|
|
14
9
|
}
|
|
15
10
|
getPayloadRecords(payload) {
|
|
16
11
|
const records = {
|
|
@@ -29,36 +24,55 @@ class SupabaseRealtimeClient {
|
|
|
29
24
|
* The event you want to listen to.
|
|
30
25
|
*
|
|
31
26
|
* @param event The event
|
|
27
|
+
* @param filter An object that specifies what you want to listen to from the event.
|
|
32
28
|
* @param callback A callback function that is called whenever the event occurs.
|
|
33
29
|
*/
|
|
34
|
-
on(event, callback) {
|
|
35
|
-
this.
|
|
36
|
-
let enrichedPayload =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
30
|
+
on(event, filter, callback) {
|
|
31
|
+
this.channel.on(event, filter !== null && filter !== void 0 ? filter : {}, ({ payload }) => {
|
|
32
|
+
let enrichedPayload = payload;
|
|
33
|
+
if (event === 'realtime') {
|
|
34
|
+
const { schema, table, commit_timestamp, type, errors } = enrichedPayload;
|
|
35
|
+
enrichedPayload = {
|
|
36
|
+
schema: schema,
|
|
37
|
+
table: table,
|
|
38
|
+
commit_timestamp: commit_timestamp,
|
|
39
|
+
eventType: type,
|
|
40
|
+
new: {},
|
|
41
|
+
old: {},
|
|
42
|
+
errors: errors,
|
|
43
|
+
};
|
|
44
|
+
enrichedPayload = Object.assign(Object.assign({}, enrichedPayload), this.getPayloadRecords(payload));
|
|
45
|
+
}
|
|
46
|
+
callback && callback(enrichedPayload);
|
|
47
47
|
});
|
|
48
48
|
return this;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
* Enables the
|
|
51
|
+
* Enables the channel.
|
|
52
52
|
*/
|
|
53
53
|
subscribe(callback = () => { }) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.
|
|
54
|
+
// if the socket already has a good accessToken
|
|
55
|
+
// we can just use it straight away
|
|
56
|
+
if (this.socket.accessToken) {
|
|
57
|
+
this.channel.updateJoinPayload({
|
|
58
|
+
user_token: this.socket.accessToken,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
this.channel.onError((e) => callback('CHANNEL_ERROR', e));
|
|
62
|
+
this.channel.onClose(() => callback('CLOSED'));
|
|
63
|
+
this.channel
|
|
57
64
|
.subscribe()
|
|
58
|
-
.receive('ok', () =>
|
|
59
|
-
|
|
65
|
+
.receive('ok', () => {
|
|
66
|
+
callback('SUBSCRIBED');
|
|
67
|
+
// re-set the accessToken again in case it was set while
|
|
68
|
+
// the subscription was isJoining
|
|
69
|
+
if (this.socket.accessToken) {
|
|
70
|
+
this.socket.setAuth(this.socket.accessToken);
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
.receive('error', (e) => callback('CHANNEL_ERROR', e))
|
|
60
74
|
.receive('timeout', () => callback('RETRYING_AFTER_TIMEOUT'));
|
|
61
|
-
return this.
|
|
75
|
+
return this.channel;
|
|
62
76
|
}
|
|
63
77
|
}
|
|
64
78
|
exports.SupabaseRealtimeClient = SupabaseRealtimeClient;
|