@depup/supabase__supabase-js 2.99.2-depup.0
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/README.md +25 -0
- package/changes.json +5 -0
- package/dist/cors.cjs +85 -0
- package/dist/cors.cjs.map +1 -0
- package/dist/cors.d.cts +56 -0
- package/dist/cors.d.cts.map +1 -0
- package/dist/cors.d.mts +56 -0
- package/dist/cors.d.mts.map +1 -0
- package/dist/cors.mjs +84 -0
- package/dist/cors.mjs.map +1 -0
- package/dist/index.cjs +622 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +564 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +564 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +575 -0
- package/dist/index.mjs.map +1 -0
- package/dist/umd/supabase.js +23 -0
- package/package.json +138 -0
- package/src/SupabaseClient.ts +589 -0
- package/src/cors.ts +75 -0
- package/src/index.ts +101 -0
- package/src/lib/SupabaseAuthClient.ts +8 -0
- package/src/lib/constants.ts +35 -0
- package/src/lib/fetch.ts +36 -0
- package/src/lib/helpers.ts +98 -0
- package/src/lib/rest/types/common/common.ts +66 -0
- package/src/lib/rest/types/common/rpc.ts +158 -0
- package/src/lib/types.ts +173 -0
- package/src/lib/version.ts +7 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,622 @@
|
|
|
1
|
+
let __supabase_functions_js = require("@supabase/functions-js");
|
|
2
|
+
let __supabase_postgrest_js = require("@supabase/postgrest-js");
|
|
3
|
+
let __supabase_realtime_js = require("@supabase/realtime-js");
|
|
4
|
+
let __supabase_storage_js = require("@supabase/storage-js");
|
|
5
|
+
let __supabase_auth_js = require("@supabase/auth-js");
|
|
6
|
+
|
|
7
|
+
//#region src/lib/version.ts
|
|
8
|
+
const version = "2.99.2";
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/lib/constants.ts
|
|
12
|
+
let JS_ENV = "";
|
|
13
|
+
if (typeof Deno !== "undefined") JS_ENV = "deno";
|
|
14
|
+
else if (typeof document !== "undefined") JS_ENV = "web";
|
|
15
|
+
else if (typeof navigator !== "undefined" && navigator.product === "ReactNative") JS_ENV = "react-native";
|
|
16
|
+
else JS_ENV = "node";
|
|
17
|
+
const DEFAULT_HEADERS = { "X-Client-Info": `supabase-js-${JS_ENV}/${version}` };
|
|
18
|
+
const DEFAULT_GLOBAL_OPTIONS = { headers: DEFAULT_HEADERS };
|
|
19
|
+
const DEFAULT_DB_OPTIONS = { schema: "public" };
|
|
20
|
+
const DEFAULT_AUTH_OPTIONS = {
|
|
21
|
+
autoRefreshToken: true,
|
|
22
|
+
persistSession: true,
|
|
23
|
+
detectSessionInUrl: true,
|
|
24
|
+
flowType: "implicit"
|
|
25
|
+
};
|
|
26
|
+
const DEFAULT_REALTIME_OPTIONS = {};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/typeof.js
|
|
30
|
+
function _typeof(o) {
|
|
31
|
+
"@babel/helpers - typeof";
|
|
32
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
33
|
+
return typeof o$1;
|
|
34
|
+
} : function(o$1) {
|
|
35
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
36
|
+
}, _typeof(o);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/toPrimitive.js
|
|
41
|
+
function toPrimitive(t, r) {
|
|
42
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
43
|
+
var e = t[Symbol.toPrimitive];
|
|
44
|
+
if (void 0 !== e) {
|
|
45
|
+
var i = e.call(t, r || "default");
|
|
46
|
+
if ("object" != _typeof(i)) return i;
|
|
47
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
48
|
+
}
|
|
49
|
+
return ("string" === r ? String : Number)(t);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/toPropertyKey.js
|
|
54
|
+
function toPropertyKey(t) {
|
|
55
|
+
var i = toPrimitive(t, "string");
|
|
56
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/defineProperty.js
|
|
61
|
+
function _defineProperty(e, r, t) {
|
|
62
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
63
|
+
value: t,
|
|
64
|
+
enumerable: !0,
|
|
65
|
+
configurable: !0,
|
|
66
|
+
writable: !0
|
|
67
|
+
}) : e[r] = t, e;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/objectSpread2.js
|
|
72
|
+
function ownKeys(e, r) {
|
|
73
|
+
var t = Object.keys(e);
|
|
74
|
+
if (Object.getOwnPropertySymbols) {
|
|
75
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
76
|
+
r && (o = o.filter(function(r$1) {
|
|
77
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
78
|
+
})), t.push.apply(t, o);
|
|
79
|
+
}
|
|
80
|
+
return t;
|
|
81
|
+
}
|
|
82
|
+
function _objectSpread2(e) {
|
|
83
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
84
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
85
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
|
86
|
+
_defineProperty(e, r$1, t[r$1]);
|
|
87
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
88
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return e;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/lib/fetch.ts
|
|
96
|
+
const resolveFetch = (customFetch) => {
|
|
97
|
+
if (customFetch) return (...args) => customFetch(...args);
|
|
98
|
+
return (...args) => fetch(...args);
|
|
99
|
+
};
|
|
100
|
+
const resolveHeadersConstructor = () => {
|
|
101
|
+
return Headers;
|
|
102
|
+
};
|
|
103
|
+
const fetchWithAuth = (supabaseKey, getAccessToken, customFetch) => {
|
|
104
|
+
const fetch$1 = resolveFetch(customFetch);
|
|
105
|
+
const HeadersConstructor = resolveHeadersConstructor();
|
|
106
|
+
return async (input, init) => {
|
|
107
|
+
var _await$getAccessToken;
|
|
108
|
+
const accessToken = (_await$getAccessToken = await getAccessToken()) !== null && _await$getAccessToken !== void 0 ? _await$getAccessToken : supabaseKey;
|
|
109
|
+
let headers = new HeadersConstructor(init === null || init === void 0 ? void 0 : init.headers);
|
|
110
|
+
if (!headers.has("apikey")) headers.set("apikey", supabaseKey);
|
|
111
|
+
if (!headers.has("Authorization")) headers.set("Authorization", `Bearer ${accessToken}`);
|
|
112
|
+
return fetch$1(input, _objectSpread2(_objectSpread2({}, init), {}, { headers }));
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/lib/helpers.ts
|
|
118
|
+
function ensureTrailingSlash(url) {
|
|
119
|
+
return url.endsWith("/") ? url : url + "/";
|
|
120
|
+
}
|
|
121
|
+
function applySettingDefaults(options, defaults) {
|
|
122
|
+
var _DEFAULT_GLOBAL_OPTIO, _globalOptions$header;
|
|
123
|
+
const { db: dbOptions, auth: authOptions, realtime: realtimeOptions, global: globalOptions } = options;
|
|
124
|
+
const { db: DEFAULT_DB_OPTIONS$1, auth: DEFAULT_AUTH_OPTIONS$1, realtime: DEFAULT_REALTIME_OPTIONS$1, global: DEFAULT_GLOBAL_OPTIONS$1 } = defaults;
|
|
125
|
+
const result = {
|
|
126
|
+
db: _objectSpread2(_objectSpread2({}, DEFAULT_DB_OPTIONS$1), dbOptions),
|
|
127
|
+
auth: _objectSpread2(_objectSpread2({}, DEFAULT_AUTH_OPTIONS$1), authOptions),
|
|
128
|
+
realtime: _objectSpread2(_objectSpread2({}, DEFAULT_REALTIME_OPTIONS$1), realtimeOptions),
|
|
129
|
+
storage: {},
|
|
130
|
+
global: _objectSpread2(_objectSpread2(_objectSpread2({}, DEFAULT_GLOBAL_OPTIONS$1), globalOptions), {}, { headers: _objectSpread2(_objectSpread2({}, (_DEFAULT_GLOBAL_OPTIO = DEFAULT_GLOBAL_OPTIONS$1 === null || DEFAULT_GLOBAL_OPTIONS$1 === void 0 ? void 0 : DEFAULT_GLOBAL_OPTIONS$1.headers) !== null && _DEFAULT_GLOBAL_OPTIO !== void 0 ? _DEFAULT_GLOBAL_OPTIO : {}), (_globalOptions$header = globalOptions === null || globalOptions === void 0 ? void 0 : globalOptions.headers) !== null && _globalOptions$header !== void 0 ? _globalOptions$header : {}) }),
|
|
131
|
+
accessToken: async () => ""
|
|
132
|
+
};
|
|
133
|
+
if (options.accessToken) result.accessToken = options.accessToken;
|
|
134
|
+
else delete result.accessToken;
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Validates a Supabase client URL
|
|
139
|
+
*
|
|
140
|
+
* @param {string} supabaseUrl - The Supabase client URL string.
|
|
141
|
+
* @returns {URL} - The validated base URL.
|
|
142
|
+
* @throws {Error}
|
|
143
|
+
*/
|
|
144
|
+
function validateSupabaseUrl(supabaseUrl) {
|
|
145
|
+
const trimmedUrl = supabaseUrl === null || supabaseUrl === void 0 ? void 0 : supabaseUrl.trim();
|
|
146
|
+
if (!trimmedUrl) throw new Error("supabaseUrl is required.");
|
|
147
|
+
if (!trimmedUrl.match(/^https?:\/\//i)) throw new Error("Invalid supabaseUrl: Must be a valid HTTP or HTTPS URL.");
|
|
148
|
+
try {
|
|
149
|
+
return new URL(ensureTrailingSlash(trimmedUrl));
|
|
150
|
+
} catch (_unused) {
|
|
151
|
+
throw Error("Invalid supabaseUrl: Provided URL is malformed.");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/lib/SupabaseAuthClient.ts
|
|
157
|
+
var SupabaseAuthClient = class extends __supabase_auth_js.AuthClient {
|
|
158
|
+
constructor(options) {
|
|
159
|
+
super(options);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/SupabaseClient.ts
|
|
165
|
+
/**
|
|
166
|
+
* Supabase Client.
|
|
167
|
+
*
|
|
168
|
+
* An isomorphic Javascript client for interacting with Postgres.
|
|
169
|
+
*/
|
|
170
|
+
var SupabaseClient = class {
|
|
171
|
+
/**
|
|
172
|
+
* Create a new client for use in the browser.
|
|
173
|
+
*
|
|
174
|
+
* @category Initializing
|
|
175
|
+
*
|
|
176
|
+
* @param supabaseUrl The unique Supabase URL which is supplied when you create a new project in your project dashboard.
|
|
177
|
+
* @param supabaseKey The unique Supabase Key which is supplied when you create a new project in your project dashboard.
|
|
178
|
+
* @param options.db.schema You can switch in between schemas. The schema needs to be on the list of exposed schemas inside Supabase.
|
|
179
|
+
* @param options.auth.autoRefreshToken Set to "true" if you want to automatically refresh the token before expiring.
|
|
180
|
+
* @param options.auth.persistSession Set to "true" if you want to automatically save the user session into local storage.
|
|
181
|
+
* @param options.auth.detectSessionInUrl Set to "true" if you want to automatically detects OAuth grants in the URL and signs in the user.
|
|
182
|
+
* @param options.realtime Options passed along to realtime-js constructor.
|
|
183
|
+
* @param options.storage Options passed along to the storage-js constructor.
|
|
184
|
+
* @param options.global.fetch A custom fetch implementation.
|
|
185
|
+
* @param options.global.headers Any additional headers to send with each network request.
|
|
186
|
+
*
|
|
187
|
+
* @example Creating a client
|
|
188
|
+
* ```js
|
|
189
|
+
* import { createClient } from '@supabase/supabase-js'
|
|
190
|
+
*
|
|
191
|
+
* // Create a single supabase client for interacting with your database
|
|
192
|
+
* const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key')
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* @example With a custom domain
|
|
196
|
+
* ```js
|
|
197
|
+
* import { createClient } from '@supabase/supabase-js'
|
|
198
|
+
*
|
|
199
|
+
* // Use a custom domain as the supabase URL
|
|
200
|
+
* const supabase = createClient('https://my-custom-domain.com', 'publishable-or-anon-key')
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @example With additional parameters
|
|
204
|
+
* ```js
|
|
205
|
+
* import { createClient } from '@supabase/supabase-js'
|
|
206
|
+
*
|
|
207
|
+
* const options = {
|
|
208
|
+
* db: {
|
|
209
|
+
* schema: 'public',
|
|
210
|
+
* },
|
|
211
|
+
* auth: {
|
|
212
|
+
* autoRefreshToken: true,
|
|
213
|
+
* persistSession: true,
|
|
214
|
+
* detectSessionInUrl: true
|
|
215
|
+
* },
|
|
216
|
+
* global: {
|
|
217
|
+
* headers: { 'x-my-custom-header': 'my-app-name' },
|
|
218
|
+
* },
|
|
219
|
+
* }
|
|
220
|
+
* const supabase = createClient("https://xyzcompany.supabase.co", "publishable-or-anon-key", options)
|
|
221
|
+
* ```
|
|
222
|
+
*
|
|
223
|
+
* @exampleDescription With custom schemas
|
|
224
|
+
* By default the API server points to the `public` schema. You can enable other database schemas within the Dashboard.
|
|
225
|
+
* Go to [Settings > API > Exposed schemas](/dashboard/project/_/settings/api) and add the schema which you want to expose to the API.
|
|
226
|
+
*
|
|
227
|
+
* Note: each client connection can only access a single schema, so the code above can access the `other_schema` schema but cannot access the `public` schema.
|
|
228
|
+
*
|
|
229
|
+
* @example With custom schemas
|
|
230
|
+
* ```js
|
|
231
|
+
* import { createClient } from '@supabase/supabase-js'
|
|
232
|
+
*
|
|
233
|
+
* const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key', {
|
|
234
|
+
* // Provide a custom schema. Defaults to "public".
|
|
235
|
+
* db: { schema: 'other_schema' }
|
|
236
|
+
* })
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* @exampleDescription Custom fetch implementation
|
|
240
|
+
* `supabase-js` uses the [`cross-fetch`](https://www.npmjs.com/package/cross-fetch) library to make HTTP requests,
|
|
241
|
+
* but an alternative `fetch` implementation can be provided as an option.
|
|
242
|
+
* This is most useful in environments where `cross-fetch` is not compatible (for instance Cloudflare Workers).
|
|
243
|
+
*
|
|
244
|
+
* @example Custom fetch implementation
|
|
245
|
+
* ```js
|
|
246
|
+
* import { createClient } from '@supabase/supabase-js'
|
|
247
|
+
*
|
|
248
|
+
* const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key', {
|
|
249
|
+
* global: { fetch: fetch.bind(globalThis) }
|
|
250
|
+
* })
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @exampleDescription React Native options with AsyncStorage
|
|
254
|
+
* For React Native we recommend using `AsyncStorage` as the storage implementation for Supabase Auth.
|
|
255
|
+
*
|
|
256
|
+
* @example React Native options with AsyncStorage
|
|
257
|
+
* ```js
|
|
258
|
+
* import 'react-native-url-polyfill/auto'
|
|
259
|
+
* import { createClient } from '@supabase/supabase-js'
|
|
260
|
+
* import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
261
|
+
*
|
|
262
|
+
* const supabase = createClient("https://xyzcompany.supabase.co", "publishable-or-anon-key", {
|
|
263
|
+
* auth: {
|
|
264
|
+
* storage: AsyncStorage,
|
|
265
|
+
* autoRefreshToken: true,
|
|
266
|
+
* persistSession: true,
|
|
267
|
+
* detectSessionInUrl: false,
|
|
268
|
+
* },
|
|
269
|
+
* });
|
|
270
|
+
* ```
|
|
271
|
+
*
|
|
272
|
+
* @exampleDescription React Native options with Expo SecureStore
|
|
273
|
+
* If you wish to encrypt the user's session information, you can use `aes-js` and store the encryption key in Expo SecureStore.
|
|
274
|
+
* The `aes-js` library, a reputable JavaScript-only implementation of the AES encryption algorithm in CTR mode.
|
|
275
|
+
* A new 256-bit encryption key is generated using the `react-native-get-random-values` library.
|
|
276
|
+
* This key is stored inside Expo's SecureStore, while the value is encrypted and placed inside AsyncStorage.
|
|
277
|
+
*
|
|
278
|
+
* Please make sure that:
|
|
279
|
+
* - You keep the `expo-secure-store`, `aes-js` and `react-native-get-random-values` libraries up-to-date.
|
|
280
|
+
* - Choose the correct [`SecureStoreOptions`](https://docs.expo.dev/versions/latest/sdk/securestore/#securestoreoptions) for your app's needs.
|
|
281
|
+
* E.g. [`SecureStore.WHEN_UNLOCKED`](https://docs.expo.dev/versions/latest/sdk/securestore/#securestorewhen_unlocked) regulates when the data can be accessed.
|
|
282
|
+
* - Carefully consider optimizations or other modifications to the above example, as those can lead to introducing subtle security vulnerabilities.
|
|
283
|
+
*
|
|
284
|
+
* @example React Native options with Expo SecureStore
|
|
285
|
+
* ```ts
|
|
286
|
+
* import 'react-native-url-polyfill/auto'
|
|
287
|
+
* import { createClient } from '@supabase/supabase-js'
|
|
288
|
+
* import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
289
|
+
* import * as SecureStore from 'expo-secure-store';
|
|
290
|
+
* import * as aesjs from 'aes-js';
|
|
291
|
+
* import 'react-native-get-random-values';
|
|
292
|
+
*
|
|
293
|
+
* // As Expo's SecureStore does not support values larger than 2048
|
|
294
|
+
* // bytes, an AES-256 key is generated and stored in SecureStore, while
|
|
295
|
+
* // it is used to encrypt/decrypt values stored in AsyncStorage.
|
|
296
|
+
* class LargeSecureStore {
|
|
297
|
+
* private async _encrypt(key: string, value: string) {
|
|
298
|
+
* const encryptionKey = crypto.getRandomValues(new Uint8Array(256 / 8));
|
|
299
|
+
*
|
|
300
|
+
* const cipher = new aesjs.ModeOfOperation.ctr(encryptionKey, new aesjs.Counter(1));
|
|
301
|
+
* const encryptedBytes = cipher.encrypt(aesjs.utils.utf8.toBytes(value));
|
|
302
|
+
*
|
|
303
|
+
* await SecureStore.setItemAsync(key, aesjs.utils.hex.fromBytes(encryptionKey));
|
|
304
|
+
*
|
|
305
|
+
* return aesjs.utils.hex.fromBytes(encryptedBytes);
|
|
306
|
+
* }
|
|
307
|
+
*
|
|
308
|
+
* private async _decrypt(key: string, value: string) {
|
|
309
|
+
* const encryptionKeyHex = await SecureStore.getItemAsync(key);
|
|
310
|
+
* if (!encryptionKeyHex) {
|
|
311
|
+
* return encryptionKeyHex;
|
|
312
|
+
* }
|
|
313
|
+
*
|
|
314
|
+
* const cipher = new aesjs.ModeOfOperation.ctr(aesjs.utils.hex.toBytes(encryptionKeyHex), new aesjs.Counter(1));
|
|
315
|
+
* const decryptedBytes = cipher.decrypt(aesjs.utils.hex.toBytes(value));
|
|
316
|
+
*
|
|
317
|
+
* return aesjs.utils.utf8.fromBytes(decryptedBytes);
|
|
318
|
+
* }
|
|
319
|
+
*
|
|
320
|
+
* async getItem(key: string) {
|
|
321
|
+
* const encrypted = await AsyncStorage.getItem(key);
|
|
322
|
+
* if (!encrypted) { return encrypted; }
|
|
323
|
+
*
|
|
324
|
+
* return await this._decrypt(key, encrypted);
|
|
325
|
+
* }
|
|
326
|
+
*
|
|
327
|
+
* async removeItem(key: string) {
|
|
328
|
+
* await AsyncStorage.removeItem(key);
|
|
329
|
+
* await SecureStore.deleteItemAsync(key);
|
|
330
|
+
* }
|
|
331
|
+
*
|
|
332
|
+
* async setItem(key: string, value: string) {
|
|
333
|
+
* const encrypted = await this._encrypt(key, value);
|
|
334
|
+
*
|
|
335
|
+
* await AsyncStorage.setItem(key, encrypted);
|
|
336
|
+
* }
|
|
337
|
+
* }
|
|
338
|
+
*
|
|
339
|
+
* const supabase = createClient("https://xyzcompany.supabase.co", "publishable-or-anon-key", {
|
|
340
|
+
* auth: {
|
|
341
|
+
* storage: new LargeSecureStore(),
|
|
342
|
+
* autoRefreshToken: true,
|
|
343
|
+
* persistSession: true,
|
|
344
|
+
* detectSessionInUrl: false,
|
|
345
|
+
* },
|
|
346
|
+
* });
|
|
347
|
+
* ```
|
|
348
|
+
*
|
|
349
|
+
* @example With a database query
|
|
350
|
+
* ```ts
|
|
351
|
+
* import { createClient } from '@supabase/supabase-js'
|
|
352
|
+
*
|
|
353
|
+
* const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key')
|
|
354
|
+
*
|
|
355
|
+
* const { data } = await supabase.from('profiles').select('*')
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
constructor(supabaseUrl, supabaseKey, options) {
|
|
359
|
+
var _settings$auth$storag, _settings$global$head;
|
|
360
|
+
this.supabaseUrl = supabaseUrl;
|
|
361
|
+
this.supabaseKey = supabaseKey;
|
|
362
|
+
const baseUrl = validateSupabaseUrl(supabaseUrl);
|
|
363
|
+
if (!supabaseKey) throw new Error("supabaseKey is required.");
|
|
364
|
+
this.realtimeUrl = new URL("realtime/v1", baseUrl);
|
|
365
|
+
this.realtimeUrl.protocol = this.realtimeUrl.protocol.replace("http", "ws");
|
|
366
|
+
this.authUrl = new URL("auth/v1", baseUrl);
|
|
367
|
+
this.storageUrl = new URL("storage/v1", baseUrl);
|
|
368
|
+
this.functionsUrl = new URL("functions/v1", baseUrl);
|
|
369
|
+
const defaultStorageKey = `sb-${baseUrl.hostname.split(".")[0]}-auth-token`;
|
|
370
|
+
const DEFAULTS = {
|
|
371
|
+
db: DEFAULT_DB_OPTIONS,
|
|
372
|
+
realtime: DEFAULT_REALTIME_OPTIONS,
|
|
373
|
+
auth: _objectSpread2(_objectSpread2({}, DEFAULT_AUTH_OPTIONS), {}, { storageKey: defaultStorageKey }),
|
|
374
|
+
global: DEFAULT_GLOBAL_OPTIONS
|
|
375
|
+
};
|
|
376
|
+
const settings = applySettingDefaults(options !== null && options !== void 0 ? options : {}, DEFAULTS);
|
|
377
|
+
this.storageKey = (_settings$auth$storag = settings.auth.storageKey) !== null && _settings$auth$storag !== void 0 ? _settings$auth$storag : "";
|
|
378
|
+
this.headers = (_settings$global$head = settings.global.headers) !== null && _settings$global$head !== void 0 ? _settings$global$head : {};
|
|
379
|
+
if (!settings.accessToken) {
|
|
380
|
+
var _settings$auth;
|
|
381
|
+
this.auth = this._initSupabaseAuthClient((_settings$auth = settings.auth) !== null && _settings$auth !== void 0 ? _settings$auth : {}, this.headers, settings.global.fetch);
|
|
382
|
+
} else {
|
|
383
|
+
this.accessToken = settings.accessToken;
|
|
384
|
+
this.auth = new Proxy({}, { get: (_, prop) => {
|
|
385
|
+
throw new Error(`@supabase/supabase-js: Supabase Client is configured with the accessToken option, accessing supabase.auth.${String(prop)} is not possible`);
|
|
386
|
+
} });
|
|
387
|
+
}
|
|
388
|
+
this.fetch = fetchWithAuth(supabaseKey, this._getAccessToken.bind(this), settings.global.fetch);
|
|
389
|
+
this.realtime = this._initRealtimeClient(_objectSpread2({
|
|
390
|
+
headers: this.headers,
|
|
391
|
+
accessToken: this._getAccessToken.bind(this)
|
|
392
|
+
}, settings.realtime));
|
|
393
|
+
if (this.accessToken) Promise.resolve(this.accessToken()).then((token) => this.realtime.setAuth(token)).catch((e) => console.warn("Failed to set initial Realtime auth token:", e));
|
|
394
|
+
this.rest = new __supabase_postgrest_js.PostgrestClient(new URL("rest/v1", baseUrl).href, {
|
|
395
|
+
headers: this.headers,
|
|
396
|
+
schema: settings.db.schema,
|
|
397
|
+
fetch: this.fetch,
|
|
398
|
+
timeout: settings.db.timeout,
|
|
399
|
+
urlLengthLimit: settings.db.urlLengthLimit
|
|
400
|
+
});
|
|
401
|
+
this.storage = new __supabase_storage_js.StorageClient(this.storageUrl.href, this.headers, this.fetch, options === null || options === void 0 ? void 0 : options.storage);
|
|
402
|
+
if (!settings.accessToken) this._listenForAuthEvents();
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Supabase Functions allows you to deploy and invoke edge functions.
|
|
406
|
+
*/
|
|
407
|
+
get functions() {
|
|
408
|
+
return new __supabase_functions_js.FunctionsClient(this.functionsUrl.href, {
|
|
409
|
+
headers: this.headers,
|
|
410
|
+
customFetch: this.fetch
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Perform a query on a table or a view.
|
|
415
|
+
*
|
|
416
|
+
* @param relation - The table or view name to query
|
|
417
|
+
*/
|
|
418
|
+
from(relation) {
|
|
419
|
+
return this.rest.from(relation);
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Select a schema to query or perform an function (rpc) call.
|
|
423
|
+
*
|
|
424
|
+
* The schema needs to be on the list of exposed schemas inside Supabase.
|
|
425
|
+
*
|
|
426
|
+
* @param schema - The schema to query
|
|
427
|
+
*/
|
|
428
|
+
schema(schema) {
|
|
429
|
+
return this.rest.schema(schema);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Perform a function call.
|
|
433
|
+
*
|
|
434
|
+
* @param fn - The function name to call
|
|
435
|
+
* @param args - The arguments to pass to the function call
|
|
436
|
+
* @param options - Named parameters
|
|
437
|
+
* @param options.head - When set to `true`, `data` will not be returned.
|
|
438
|
+
* Useful if you only need the count.
|
|
439
|
+
* @param options.get - When set to `true`, the function will be called with
|
|
440
|
+
* read-only access mode.
|
|
441
|
+
* @param options.count - Count algorithm to use to count rows returned by the
|
|
442
|
+
* function. Only applicable for [set-returning
|
|
443
|
+
* functions](https://www.postgresql.org/docs/current/functions-srf.html).
|
|
444
|
+
*
|
|
445
|
+
* `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
|
|
446
|
+
* hood.
|
|
447
|
+
*
|
|
448
|
+
* `"planned"`: Approximated but fast count algorithm. Uses the Postgres
|
|
449
|
+
* statistics under the hood.
|
|
450
|
+
*
|
|
451
|
+
* `"estimated"`: Uses exact count for low numbers and planned count for high
|
|
452
|
+
* numbers.
|
|
453
|
+
*/
|
|
454
|
+
rpc(fn, args = {}, options = {
|
|
455
|
+
head: false,
|
|
456
|
+
get: false,
|
|
457
|
+
count: void 0
|
|
458
|
+
}) {
|
|
459
|
+
return this.rest.rpc(fn, args, options);
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Creates a Realtime channel with Broadcast, Presence, and Postgres Changes.
|
|
463
|
+
*
|
|
464
|
+
* @param {string} name - The name of the Realtime channel.
|
|
465
|
+
* @param {Object} opts - The options to pass to the Realtime channel.
|
|
466
|
+
*
|
|
467
|
+
*/
|
|
468
|
+
channel(name, opts = { config: {} }) {
|
|
469
|
+
return this.realtime.channel(name, opts);
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Returns all Realtime channels.
|
|
473
|
+
*/
|
|
474
|
+
getChannels() {
|
|
475
|
+
return this.realtime.getChannels();
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Unsubscribes and removes Realtime channel from Realtime client.
|
|
479
|
+
*
|
|
480
|
+
* @param {RealtimeChannel} channel - The name of the Realtime channel.
|
|
481
|
+
*
|
|
482
|
+
*/
|
|
483
|
+
removeChannel(channel) {
|
|
484
|
+
return this.realtime.removeChannel(channel);
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Unsubscribes and removes all Realtime channels from Realtime client.
|
|
488
|
+
*/
|
|
489
|
+
removeAllChannels() {
|
|
490
|
+
return this.realtime.removeAllChannels();
|
|
491
|
+
}
|
|
492
|
+
async _getAccessToken() {
|
|
493
|
+
var _this = this;
|
|
494
|
+
var _data$session$access_, _data$session;
|
|
495
|
+
if (_this.accessToken) return await _this.accessToken();
|
|
496
|
+
const { data } = await _this.auth.getSession();
|
|
497
|
+
return (_data$session$access_ = (_data$session = data.session) === null || _data$session === void 0 ? void 0 : _data$session.access_token) !== null && _data$session$access_ !== void 0 ? _data$session$access_ : _this.supabaseKey;
|
|
498
|
+
}
|
|
499
|
+
_initSupabaseAuthClient({ autoRefreshToken, persistSession, detectSessionInUrl, storage, userStorage, storageKey, flowType, lock, debug, throwOnError }, headers, fetch$1) {
|
|
500
|
+
const authHeaders = {
|
|
501
|
+
Authorization: `Bearer ${this.supabaseKey}`,
|
|
502
|
+
apikey: `${this.supabaseKey}`
|
|
503
|
+
};
|
|
504
|
+
return new SupabaseAuthClient({
|
|
505
|
+
url: this.authUrl.href,
|
|
506
|
+
headers: _objectSpread2(_objectSpread2({}, authHeaders), headers),
|
|
507
|
+
storageKey,
|
|
508
|
+
autoRefreshToken,
|
|
509
|
+
persistSession,
|
|
510
|
+
detectSessionInUrl,
|
|
511
|
+
storage,
|
|
512
|
+
userStorage,
|
|
513
|
+
flowType,
|
|
514
|
+
lock,
|
|
515
|
+
debug,
|
|
516
|
+
throwOnError,
|
|
517
|
+
fetch: fetch$1,
|
|
518
|
+
hasCustomAuthorizationHeader: Object.keys(this.headers).some((key) => key.toLowerCase() === "authorization")
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
_initRealtimeClient(options) {
|
|
522
|
+
return new __supabase_realtime_js.RealtimeClient(this.realtimeUrl.href, _objectSpread2(_objectSpread2({}, options), {}, { params: _objectSpread2(_objectSpread2({}, { apikey: this.supabaseKey }), options === null || options === void 0 ? void 0 : options.params) }));
|
|
523
|
+
}
|
|
524
|
+
_listenForAuthEvents() {
|
|
525
|
+
return this.auth.onAuthStateChange((event, session) => {
|
|
526
|
+
this._handleTokenChanged(event, "CLIENT", session === null || session === void 0 ? void 0 : session.access_token);
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
_handleTokenChanged(event, source, token) {
|
|
530
|
+
if ((event === "TOKEN_REFRESHED" || event === "SIGNED_IN") && this.changedAccessToken !== token) {
|
|
531
|
+
this.changedAccessToken = token;
|
|
532
|
+
this.realtime.setAuth(token);
|
|
533
|
+
} else if (event === "SIGNED_OUT") {
|
|
534
|
+
this.realtime.setAuth();
|
|
535
|
+
if (source == "STORAGE") this.auth.signOut();
|
|
536
|
+
this.changedAccessToken = void 0;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
//#endregion
|
|
542
|
+
//#region src/index.ts
|
|
543
|
+
/**
|
|
544
|
+
* Creates a new Supabase Client.
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* ```ts
|
|
548
|
+
* import { createClient } from '@supabase/supabase-js'
|
|
549
|
+
*
|
|
550
|
+
* const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key')
|
|
551
|
+
* const { data, error } = await supabase.from('profiles').select('*')
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
const createClient = (supabaseUrl, supabaseKey, options) => {
|
|
555
|
+
return new SupabaseClient(supabaseUrl, supabaseKey, options);
|
|
556
|
+
};
|
|
557
|
+
function shouldShowDeprecationWarning() {
|
|
558
|
+
if (typeof window !== "undefined") return false;
|
|
559
|
+
const _process = globalThis["process"];
|
|
560
|
+
if (!_process) return false;
|
|
561
|
+
const processVersion = _process["version"];
|
|
562
|
+
if (processVersion === void 0 || processVersion === null) return false;
|
|
563
|
+
const versionMatch = processVersion.match(/^v(\d+)\./);
|
|
564
|
+
if (!versionMatch) return false;
|
|
565
|
+
return parseInt(versionMatch[1], 10) <= 18;
|
|
566
|
+
}
|
|
567
|
+
if (shouldShowDeprecationWarning()) console.warn("⚠️ Node.js 18 and below are deprecated and will no longer be supported in future versions of @supabase/supabase-js. Please upgrade to Node.js 20 or later. For more information, visit: https://github.com/orgs/supabase/discussions/37217");
|
|
568
|
+
|
|
569
|
+
//#endregion
|
|
570
|
+
Object.defineProperty(exports, 'FunctionRegion', {
|
|
571
|
+
enumerable: true,
|
|
572
|
+
get: function () {
|
|
573
|
+
return __supabase_functions_js.FunctionRegion;
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
Object.defineProperty(exports, 'FunctionsError', {
|
|
577
|
+
enumerable: true,
|
|
578
|
+
get: function () {
|
|
579
|
+
return __supabase_functions_js.FunctionsError;
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
Object.defineProperty(exports, 'FunctionsFetchError', {
|
|
583
|
+
enumerable: true,
|
|
584
|
+
get: function () {
|
|
585
|
+
return __supabase_functions_js.FunctionsFetchError;
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
Object.defineProperty(exports, 'FunctionsHttpError', {
|
|
589
|
+
enumerable: true,
|
|
590
|
+
get: function () {
|
|
591
|
+
return __supabase_functions_js.FunctionsHttpError;
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
Object.defineProperty(exports, 'FunctionsRelayError', {
|
|
595
|
+
enumerable: true,
|
|
596
|
+
get: function () {
|
|
597
|
+
return __supabase_functions_js.FunctionsRelayError;
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
Object.defineProperty(exports, 'PostgrestError', {
|
|
601
|
+
enumerable: true,
|
|
602
|
+
get: function () {
|
|
603
|
+
return __supabase_postgrest_js.PostgrestError;
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
exports.SupabaseClient = SupabaseClient;
|
|
607
|
+
exports.createClient = createClient;
|
|
608
|
+
Object.keys(__supabase_auth_js).forEach(function (k) {
|
|
609
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
610
|
+
enumerable: true,
|
|
611
|
+
get: function () { return __supabase_auth_js[k]; }
|
|
612
|
+
});
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
Object.keys(__supabase_realtime_js).forEach(function (k) {
|
|
616
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
617
|
+
enumerable: true,
|
|
618
|
+
get: function () { return __supabase_realtime_js[k]; }
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
//# sourceMappingURL=index.cjs.map
|