@supabase/supabase-js 1.35.3 → 1.36.0-next.10
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 +25 -38
- package/dist/main/SupabaseClient.d.ts.map +1 -1
- package/dist/main/SupabaseClient.js +53 -79
- 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 +25 -38
- package/dist/module/SupabaseClient.d.ts.map +1 -1
- package/dist/module/SupabaseClient.js +55 -81
- 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 +6 -5
- package/src/SupabaseClient.ts +107 -117
- 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/src/lib/SupabaseQueryBuilder.ts +0 -61
|
@@ -7,14 +7,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { DEFAULT_HEADERS, STORAGE_KEY } from './lib/constants';
|
|
11
|
-
import { stripTrailingSlash, isBrowser } from './lib/helpers';
|
|
12
|
-
import { SupabaseAuthClient } from './lib/SupabaseAuthClient';
|
|
13
|
-
import { SupabaseQueryBuilder } from './lib/SupabaseQueryBuilder';
|
|
14
|
-
import { SupabaseStorageClient } from '@supabase/storage-js';
|
|
15
10
|
import { FunctionsClient } from '@supabase/functions-js';
|
|
16
|
-
import { PostgrestClient } from '@supabase/postgrest-js';
|
|
17
|
-
import { RealtimeClient
|
|
11
|
+
import { PostgrestClient, } from '@supabase/postgrest-js';
|
|
12
|
+
import { RealtimeClient } from '@supabase/realtime-js';
|
|
13
|
+
import { SupabaseStorageClient } from '@supabase/storage-js';
|
|
14
|
+
import { DEFAULT_HEADERS } from './lib/constants';
|
|
15
|
+
import { fetchWithAuth } from './lib/fetch';
|
|
16
|
+
import { isBrowser, stripTrailingSlash } from './lib/helpers';
|
|
17
|
+
import { SupabaseAuthClient } from './lib/SupabaseAuthClient';
|
|
18
|
+
import { SupabaseRealtimeClient } from './lib/SupabaseRealtimeClient';
|
|
18
19
|
const DEFAULT_OPTIONS = {
|
|
19
20
|
schema: 'public',
|
|
20
21
|
autoRefreshToken: true,
|
|
@@ -43,6 +44,7 @@ export default class SupabaseClient {
|
|
|
43
44
|
* @param options.fetch A custom fetch implementation.
|
|
44
45
|
*/
|
|
45
46
|
constructor(supabaseUrl, supabaseKey, options) {
|
|
47
|
+
var _a, _b, _c, _d, _e;
|
|
46
48
|
this.supabaseUrl = supabaseUrl;
|
|
47
49
|
this.supabaseKey = supabaseKey;
|
|
48
50
|
if (!supabaseUrl)
|
|
@@ -50,8 +52,6 @@ export default class SupabaseClient {
|
|
|
50
52
|
if (!supabaseKey)
|
|
51
53
|
throw new Error('supabaseKey is required.');
|
|
52
54
|
const _supabaseUrl = stripTrailingSlash(supabaseUrl);
|
|
53
|
-
const settings = Object.assign(Object.assign({}, DEFAULT_OPTIONS), options);
|
|
54
|
-
this.restUrl = `${_supabaseUrl}/rest/v1`;
|
|
55
55
|
this.realtimeUrl = `${_supabaseUrl}/realtime/v1`.replace('http', 'ws');
|
|
56
56
|
this.authUrl = `${_supabaseUrl}/auth/v1`;
|
|
57
57
|
this.storageUrl = `${_supabaseUrl}/storage/v1`;
|
|
@@ -63,13 +63,22 @@ export default class SupabaseClient {
|
|
|
63
63
|
else {
|
|
64
64
|
this.functionsUrl = `${_supabaseUrl}/functions/v1`;
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.
|
|
66
|
+
// default storage key uses the supabase project ref as a namespace
|
|
67
|
+
const defaultStorageKey = `sb-${new URL(this.authUrl).hostname.split('.')[0]}-auth-token`;
|
|
68
|
+
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;
|
|
69
|
+
const settings = Object.assign(Object.assign(Object.assign({}, DEFAULT_OPTIONS), options), { storageKey: this.storageKey });
|
|
70
|
+
this.multiTab = (_d = (_c = settings.auth) === null || _c === void 0 ? void 0 : _c.multiTab) !== null && _d !== void 0 ? _d : false;
|
|
69
71
|
this.headers = Object.assign(Object.assign({}, DEFAULT_HEADERS), options === null || options === void 0 ? void 0 : options.headers);
|
|
70
72
|
this.shouldThrowOnError = settings.shouldThrowOnError || false;
|
|
71
|
-
this.auth = this._initSupabaseAuthClient(settings);
|
|
73
|
+
this.auth = this._initSupabaseAuthClient(settings.auth || {}, this.headers, settings.fetch);
|
|
74
|
+
this.fetch = fetchWithAuth(supabaseKey, this._getAccessToken.bind(this), settings.fetch);
|
|
72
75
|
this.realtime = this._initRealtimeClient(Object.assign({ headers: this.headers }, settings.realtime));
|
|
76
|
+
this.rest = new PostgrestClient(`${_supabaseUrl}/rest/v1`, {
|
|
77
|
+
headers: this.headers,
|
|
78
|
+
schema: (_e = options === null || options === void 0 ? void 0 : options.db) === null || _e === void 0 ? void 0 : _e.schema,
|
|
79
|
+
fetch: this.fetch,
|
|
80
|
+
throwOnError: this.shouldThrowOnError,
|
|
81
|
+
});
|
|
73
82
|
this._listenForAuthEvents();
|
|
74
83
|
this._listenForMultiTabEvents();
|
|
75
84
|
// In the future we might allow the user to pass in a logger to receive these events.
|
|
@@ -82,7 +91,7 @@ export default class SupabaseClient {
|
|
|
82
91
|
*/
|
|
83
92
|
get functions() {
|
|
84
93
|
return new FunctionsClient(this.functionsUrl, {
|
|
85
|
-
headers: this.
|
|
94
|
+
headers: this.headers,
|
|
86
95
|
customFetch: this.fetch,
|
|
87
96
|
});
|
|
88
97
|
}
|
|
@@ -90,7 +99,7 @@ export default class SupabaseClient {
|
|
|
90
99
|
* Supabase Storage allows you to manage user-generated content, such as photos or videos.
|
|
91
100
|
*/
|
|
92
101
|
get storage() {
|
|
93
|
-
return new SupabaseStorageClient(this.storageUrl, this.
|
|
102
|
+
return new SupabaseStorageClient(this.storageUrl, this.headers, this.fetch);
|
|
94
103
|
}
|
|
95
104
|
/**
|
|
96
105
|
* Perform a table operation.
|
|
@@ -98,15 +107,7 @@ export default class SupabaseClient {
|
|
|
98
107
|
* @param table The table name to operate on.
|
|
99
108
|
*/
|
|
100
109
|
from(table) {
|
|
101
|
-
|
|
102
|
-
return new SupabaseQueryBuilder(url, {
|
|
103
|
-
headers: this._getAuthHeaders(),
|
|
104
|
-
schema: this.schema,
|
|
105
|
-
realtime: this.realtime,
|
|
106
|
-
table,
|
|
107
|
-
fetch: this.fetch,
|
|
108
|
-
shouldThrowOnError: this.shouldThrowOnError,
|
|
109
|
-
});
|
|
110
|
+
return this.rest.from(table);
|
|
110
111
|
}
|
|
111
112
|
/**
|
|
112
113
|
* Perform a function call.
|
|
@@ -117,34 +118,30 @@ export default class SupabaseClient {
|
|
|
117
118
|
* @param count Count algorithm to use to count rows in a table.
|
|
118
119
|
*
|
|
119
120
|
*/
|
|
120
|
-
rpc(fn,
|
|
121
|
-
|
|
122
|
-
return rest.rpc(fn, params, { head, count });
|
|
121
|
+
rpc(fn, args = {}, options) {
|
|
122
|
+
return this.rest.rpc(fn, args, options);
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
125
|
* Creates a channel with Broadcast and Presence.
|
|
126
|
-
* Activated when vsndate query param is present in the WebSocket URL.
|
|
127
126
|
*/
|
|
128
127
|
channel(name, opts) {
|
|
129
|
-
var _a, _b;
|
|
130
|
-
const userToken = (_b = (_a = this.auth.session()) === null || _a === void 0 ? void 0 : _a.access_token) !== null && _b !== void 0 ? _b : this.supabaseKey;
|
|
131
128
|
if (!this.realtime.isConnected()) {
|
|
132
129
|
this.realtime.connect();
|
|
133
130
|
}
|
|
134
|
-
return this.realtime
|
|
131
|
+
return new SupabaseRealtimeClient(this.realtime, name, opts);
|
|
135
132
|
}
|
|
136
133
|
/**
|
|
137
|
-
* Closes and removes all
|
|
138
|
-
*
|
|
134
|
+
* Closes and removes all channels and returns a list of removed
|
|
135
|
+
* channels and their errors.
|
|
139
136
|
*/
|
|
140
|
-
|
|
137
|
+
removeAllChannels() {
|
|
141
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
return
|
|
139
|
+
const allChans = this.getChannels().slice();
|
|
140
|
+
const allChanPromises = allChans.map((chan) => this.removeChannel(chan));
|
|
141
|
+
const allRemovedChans = yield Promise.all(allChanPromises);
|
|
142
|
+
return allRemovedChans.map(({ error }, i) => {
|
|
146
143
|
return {
|
|
147
|
-
data: {
|
|
144
|
+
data: { channels: allChans[i] },
|
|
148
145
|
error,
|
|
149
146
|
};
|
|
150
147
|
});
|
|
@@ -157,43 +154,35 @@ export default class SupabaseClient {
|
|
|
157
154
|
*/
|
|
158
155
|
removeChannel(channel) {
|
|
159
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
const { error } = yield this.
|
|
161
|
-
const allChans = this.
|
|
157
|
+
const { error } = yield this._closeChannel(channel);
|
|
158
|
+
const allChans = this.getChannels();
|
|
162
159
|
const openChanCount = allChans.filter((chan) => chan.isJoined()).length;
|
|
163
160
|
if (allChans.length === 0)
|
|
164
161
|
yield this.realtime.disconnect();
|
|
165
162
|
return { data: { openChannels: openChanCount }, error };
|
|
166
163
|
});
|
|
167
164
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
*
|
|
171
|
-
* @param subscription The subscription you want to close and remove.
|
|
172
|
-
*/
|
|
173
|
-
removeSubscription(subscription) {
|
|
165
|
+
_getAccessToken() {
|
|
166
|
+
var _a;
|
|
174
167
|
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
-
const {
|
|
176
|
-
|
|
177
|
-
const openSubCount = allSubs.filter((chan) => chan.isJoined()).length;
|
|
178
|
-
if (allSubs.length === 0)
|
|
179
|
-
yield this.realtime.disconnect();
|
|
180
|
-
return { data: { openSubscriptions: openSubCount }, error };
|
|
168
|
+
const { session } = yield this.auth.getSession();
|
|
169
|
+
return (_a = session === null || session === void 0 ? void 0 : session.access_token) !== null && _a !== void 0 ? _a : null;
|
|
181
170
|
});
|
|
182
171
|
}
|
|
183
|
-
|
|
172
|
+
_closeChannel(channel) {
|
|
184
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
185
174
|
let error = null;
|
|
186
|
-
if (!
|
|
187
|
-
const { error: unsubError } = yield this.
|
|
175
|
+
if (!channel.isClosed()) {
|
|
176
|
+
const { error: unsubError } = yield this._unsubscribeChannel(channel);
|
|
188
177
|
error = unsubError;
|
|
189
178
|
}
|
|
190
|
-
this.realtime.remove(
|
|
179
|
+
this.realtime.remove(channel);
|
|
191
180
|
return { error };
|
|
192
181
|
});
|
|
193
182
|
}
|
|
194
|
-
|
|
183
|
+
_unsubscribeChannel(channel) {
|
|
195
184
|
return new Promise((resolve) => {
|
|
196
|
-
|
|
185
|
+
channel
|
|
197
186
|
.unsubscribe()
|
|
198
187
|
.receive('ok', () => resolve({ error: null }))
|
|
199
188
|
.receive('error', (error) => resolve({ error }))
|
|
@@ -201,12 +190,12 @@ export default class SupabaseClient {
|
|
|
201
190
|
});
|
|
202
191
|
}
|
|
203
192
|
/**
|
|
204
|
-
* Returns an array of all your
|
|
193
|
+
* Returns an array of all your channels.
|
|
205
194
|
*/
|
|
206
|
-
|
|
195
|
+
getChannels() {
|
|
207
196
|
return this.realtime.channels;
|
|
208
197
|
}
|
|
209
|
-
_initSupabaseAuthClient({ autoRefreshToken, persistSession, detectSessionInUrl, localStorage,
|
|
198
|
+
_initSupabaseAuthClient({ autoRefreshToken, persistSession, detectSessionInUrl, localStorage, cookieOptions, multiTab, storageKey, }, headers, fetch) {
|
|
210
199
|
const authHeaders = {
|
|
211
200
|
Authorization: `Bearer ${this.supabaseKey}`,
|
|
212
201
|
apikey: `${this.supabaseKey}`,
|
|
@@ -214,6 +203,7 @@ export default class SupabaseClient {
|
|
|
214
203
|
return new SupabaseAuthClient({
|
|
215
204
|
url: this.authUrl,
|
|
216
205
|
headers: Object.assign(Object.assign({}, headers), authHeaders),
|
|
206
|
+
storageKey: storageKey,
|
|
217
207
|
autoRefreshToken,
|
|
218
208
|
persistSession,
|
|
219
209
|
detectSessionInUrl,
|
|
@@ -224,23 +214,7 @@ export default class SupabaseClient {
|
|
|
224
214
|
});
|
|
225
215
|
}
|
|
226
216
|
_initRealtimeClient(options) {
|
|
227
|
-
return new RealtimeClient(this.realtimeUrl, Object.assign(Object.assign({}, options), { params: Object.assign(
|
|
228
|
-
}
|
|
229
|
-
_initPostgRESTClient() {
|
|
230
|
-
return new PostgrestClient(this.restUrl, {
|
|
231
|
-
headers: this._getAuthHeaders(),
|
|
232
|
-
schema: this.schema,
|
|
233
|
-
fetch: this.fetch,
|
|
234
|
-
throwOnError: this.shouldThrowOnError,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
_getAuthHeaders() {
|
|
238
|
-
var _a, _b;
|
|
239
|
-
const headers = Object.assign({}, this.headers);
|
|
240
|
-
const authBearer = (_b = (_a = this.auth.session()) === null || _a === void 0 ? void 0 : _a.access_token) !== null && _b !== void 0 ? _b : this.supabaseKey;
|
|
241
|
-
headers['apikey'] = this.supabaseKey;
|
|
242
|
-
headers['Authorization'] = headers['Authorization'] || `Bearer ${authBearer}`;
|
|
243
|
-
return headers;
|
|
217
|
+
return new 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) }));
|
|
244
218
|
}
|
|
245
219
|
_listenForMultiTabEvents() {
|
|
246
220
|
if (!this.multiTab || !isBrowser() || !(window === null || window === void 0 ? void 0 : window.addEventListener)) {
|
|
@@ -249,7 +223,7 @@ export default class SupabaseClient {
|
|
|
249
223
|
try {
|
|
250
224
|
return window === null || window === void 0 ? void 0 : window.addEventListener('storage', (e) => {
|
|
251
225
|
var _a, _b, _c;
|
|
252
|
-
if (e.key ===
|
|
226
|
+
if (e.key === this.storageKey) {
|
|
253
227
|
const newSession = JSON.parse(String(e.newValue));
|
|
254
228
|
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;
|
|
255
229
|
const previousAccessToken = (_c = this.auth.session()) === null || _c === void 0 ? void 0 : _c.access_token;
|
|
@@ -271,7 +245,7 @@ export default class SupabaseClient {
|
|
|
271
245
|
}
|
|
272
246
|
}
|
|
273
247
|
_listenForAuthEvents() {
|
|
274
|
-
let
|
|
248
|
+
let data = this.auth.onAuthStateChange((event, session) => {
|
|
275
249
|
this._handleTokenChanged(event, session === null || session === void 0 ? void 0 : session.access_token, 'CLIENT');
|
|
276
250
|
});
|
|
277
251
|
return data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SupabaseClient.js","sourceRoot":"","sources":["../../src/SupabaseClient.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"SupabaseClient.js","sourceRoot":"","sources":["../../src/SupabaseClient.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAExD,OAAO,EACL,eAAe,GAGhB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAmB,cAA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AAI,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"}
|
package/dist/module/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
|
|
@@ -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/module/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import SupabaseClient from './SupabaseClient';
|
|
2
2
|
export * from '@supabase/gotrue-js';
|
|
3
3
|
export * from '@supabase/realtime-js';
|
|
4
|
+
export { default as SupabaseClient } from './SupabaseClient';
|
|
4
5
|
/**
|
|
5
6
|
* Creates a new Supabase Client.
|
|
6
7
|
*/
|
|
7
|
-
const createClient = (supabaseUrl, supabaseKey, options) => {
|
|
8
|
+
export const createClient = (supabaseUrl, supabaseKey, options) => {
|
|
8
9
|
return new SupabaseClient(supabaseUrl, supabaseKey, options);
|
|
9
10
|
};
|
|
10
|
-
export { createClient, SupabaseClient, };
|
|
11
11
|
//# sourceMappingURL=index.js.map
|
package/dist/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAG7C,cAAc,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAG7C,cAAc,qBAAqB,CAAA;AAQnC,cAAc,uBAAuB,CAAA;AACrC,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAG5D;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAS1B,WAAmB,EACnB,WAAmB,EACnB,OAA2C,EACG,EAAE;IAChD,OAAO,IAAI,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,CAAA;AAC9D,CAAC,CAAA"}
|
|
@@ -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"}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { Transformers } from '@supabase/realtime-js';
|
|
2
2
|
export class SupabaseRealtimeClient {
|
|
3
|
-
constructor(socket,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const userToken = headers['Authorization'].split(' ')[1];
|
|
7
|
-
if (userToken) {
|
|
8
|
-
chanParams['user_token'] = userToken;
|
|
9
|
-
}
|
|
10
|
-
this.subscription = socket.channel(topic, chanParams);
|
|
3
|
+
constructor(socket, name, opts = {}) {
|
|
4
|
+
this.socket = socket;
|
|
5
|
+
this.channel = socket.channel(`realtime:${name}`, opts);
|
|
11
6
|
}
|
|
12
7
|
getPayloadRecords(payload) {
|
|
13
8
|
const records = {
|
|
@@ -26,36 +21,55 @@ export class SupabaseRealtimeClient {
|
|
|
26
21
|
* The event you want to listen to.
|
|
27
22
|
*
|
|
28
23
|
* @param event The event
|
|
24
|
+
* @param filter An object that specifies what you want to listen to from the event.
|
|
29
25
|
* @param callback A callback function that is called whenever the event occurs.
|
|
30
26
|
*/
|
|
31
|
-
on(event, callback) {
|
|
32
|
-
this.
|
|
33
|
-
let enrichedPayload =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
on(event, filter, callback) {
|
|
28
|
+
this.channel.on(event, filter !== null && filter !== void 0 ? filter : {}, ({ payload }) => {
|
|
29
|
+
let enrichedPayload = payload;
|
|
30
|
+
if (event === 'realtime') {
|
|
31
|
+
const { schema, table, commit_timestamp, type, errors } = enrichedPayload;
|
|
32
|
+
enrichedPayload = {
|
|
33
|
+
schema: schema,
|
|
34
|
+
table: table,
|
|
35
|
+
commit_timestamp: commit_timestamp,
|
|
36
|
+
eventType: type,
|
|
37
|
+
new: {},
|
|
38
|
+
old: {},
|
|
39
|
+
errors: errors,
|
|
40
|
+
};
|
|
41
|
+
enrichedPayload = Object.assign(Object.assign({}, enrichedPayload), this.getPayloadRecords(payload));
|
|
42
|
+
}
|
|
43
|
+
callback && callback(enrichedPayload);
|
|
44
44
|
});
|
|
45
45
|
return this;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
|
-
* Enables the
|
|
48
|
+
* Enables the channel.
|
|
49
49
|
*/
|
|
50
50
|
subscribe(callback = () => { }) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.
|
|
51
|
+
// if the socket already has a good accessToken
|
|
52
|
+
// we can just use it straight away
|
|
53
|
+
if (this.socket.accessToken) {
|
|
54
|
+
this.channel.updateJoinPayload({
|
|
55
|
+
user_token: this.socket.accessToken,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
this.channel.onError((e) => callback('CHANNEL_ERROR', e));
|
|
59
|
+
this.channel.onClose(() => callback('CLOSED'));
|
|
60
|
+
this.channel
|
|
54
61
|
.subscribe()
|
|
55
|
-
.receive('ok', () =>
|
|
56
|
-
|
|
62
|
+
.receive('ok', () => {
|
|
63
|
+
callback('SUBSCRIBED');
|
|
64
|
+
// re-set the accessToken again in case it was set while
|
|
65
|
+
// the subscription was isJoining
|
|
66
|
+
if (this.socket.accessToken) {
|
|
67
|
+
this.socket.setAuth(this.socket.accessToken);
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
.receive('error', (e) => callback('CHANNEL_ERROR', e))
|
|
57
71
|
.receive('timeout', () => callback('RETRYING_AFTER_TIMEOUT'));
|
|
58
|
-
return this.
|
|
72
|
+
return this.channel;
|
|
59
73
|
}
|
|
60
74
|
}
|
|
61
75
|
//# sourceMappingURL=SupabaseRealtimeClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SupabaseRealtimeClient.js","sourceRoot":"","sources":["../../../src/lib/SupabaseRealtimeClient.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"SupabaseRealtimeClient.js","sourceRoot":"","sources":["../../../src/lib/SupabaseRealtimeClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAGrF,MAAM,OAAO,sBAAsB;IAIjC,YAAY,MAAsB,EAA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AAC,wBAAwB,CAAC,CAAC,CAAA;QAE/D,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe;;CAAgD,CAAA
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe;;CAAgD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,eAAe,EAAE,eAAe,OAAO,EAAE,EAAE,CAAA
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,eAAe,EAAE,eAAe,OAAO,EAAE,EAAE,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare type Fetch = typeof fetch;
|
|
2
|
+
export declare const resolveFetch: (customFetch?: typeof fetch | undefined) => Fetch;
|
|
3
|
+
export declare const resolveHeadersConstructor: () => {
|
|
4
|
+
new (init?: HeadersInit | undefined): Headers;
|
|
5
|
+
prototype: Headers;
|
|
6
|
+
};
|
|
7
|
+
export declare const fetchWithAuth: (supabaseKey: string, getAccessToken: () => Promise<string | null>, customFetch?: typeof fetch | undefined) => Fetch;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/lib/fetch.ts"],"names":[],"mappings":"AAEA,aAAK,KAAK,GAAG,OAAO,KAAK,CAAA;AAEzB,eAAO,MAAM,YAAY,8CAA0B,KAUlD,CAAA;AAED,eAAO,MAAM,yBAAyB;;;CAMrC,CAAA;AAED,eAAO,MAAM,aAAa,gBACX,MAAM,kBACH,MAAM,QAAQ,MAAM,GAAG,IAAI,CAAC,6CAE3C,KAkBF,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import crossFetch, { Headers as CrossFetchHeaders } from 'cross-fetch';
|
|
11
|
+
export const resolveFetch = (customFetch) => {
|
|
12
|
+
let _fetch;
|
|
13
|
+
if (customFetch) {
|
|
14
|
+
_fetch = customFetch;
|
|
15
|
+
}
|
|
16
|
+
else if (typeof fetch === 'undefined') {
|
|
17
|
+
_fetch = crossFetch;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
_fetch = fetch;
|
|
21
|
+
}
|
|
22
|
+
return (...args) => _fetch(...args);
|
|
23
|
+
};
|
|
24
|
+
export const resolveHeadersConstructor = () => {
|
|
25
|
+
if (typeof Headers === 'undefined') {
|
|
26
|
+
return CrossFetchHeaders;
|
|
27
|
+
}
|
|
28
|
+
return Headers;
|
|
29
|
+
};
|
|
30
|
+
export const fetchWithAuth = (supabaseKey, getAccessToken, customFetch) => {
|
|
31
|
+
const fetch = resolveFetch(customFetch);
|
|
32
|
+
const HeadersConstructor = resolveHeadersConstructor();
|
|
33
|
+
return (input, init) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
var _a;
|
|
35
|
+
const accessToken = (_a = (yield getAccessToken())) !== null && _a !== void 0 ? _a : supabaseKey;
|
|
36
|
+
let headers = new HeadersConstructor(init === null || init === void 0 ? void 0 : init.headers);
|
|
37
|
+
if (!headers.has('apikey')) {
|
|
38
|
+
headers.set('apikey', supabaseKey);
|
|
39
|
+
}
|
|
40
|
+
if (!headers.has('Authorization')) {
|
|
41
|
+
headers.set('Authorization', `Bearer ${accessToken}`);
|
|
42
|
+
}
|
|
43
|
+
return fetch(input, Object.assign(Object.assign({}, init), { headers }));
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/lib/fetch.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,UAAU,EAAE,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAItE,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,WAAmB,EAAS,EAAE;IACzD,IAAI,MAAa,CAAA;IACjB,IAAI,WAAW,EAAE;QACf,MAAM,GAAG,WAAW,CAAA;KACrB;SAAM,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;QACvC,MAAM,GAAG,UAA8B,CAAA;KACxC;SAAM;QACL,MAAM,GAAG,KAAK,CAAA;KACf;IACD,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAA;AACrC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,EAAE;IAC5C,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;QAClC,OAAO,iBAAi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