import { __awaiter, __rest, init_tslib_es6, tslib_es6_exports } from "./chunk-B3JW6XJO.js"; import { __commonJS, __esm, __export, __toCommonJS, __toESM } from "./chunk-4B2QHNJT.js"; // ../../node_modules/.pnpm/@supabase+functions-js@2.86.2/node_modules/@supabase/functions-js/dist/module/helper.js var resolveFetch; var init_helper = __esm({ "../../node_modules/.pnpm/@supabase+functions-js@2.86.2/node_modules/@supabase/functions-js/dist/module/helper.js"() { resolveFetch = (customFetch) => { if (customFetch) { return (...args) => customFetch(...args); } return (...args) => fetch(...args); }; } }); // ../../node_modules/.pnpm/@supabase+functions-js@2.86.2/node_modules/@supabase/functions-js/dist/module/types.js var FunctionsError, FunctionsFetchError, FunctionsRelayError, FunctionsHttpError, FunctionRegion; var init_types = __esm({ "../../node_modules/.pnpm/@supabase+functions-js@2.86.2/node_modules/@supabase/functions-js/dist/module/types.js"() { FunctionsError = class extends Error { constructor(message, name = "FunctionsError", context) { super(message); this.name = name; this.context = context; } }; FunctionsFetchError = class extends FunctionsError { constructor(context) { super("Failed to send a request to the Edge Function", "FunctionsFetchError", context); } }; FunctionsRelayError = class extends FunctionsError { constructor(context) { super("Relay Error invoking the Edge Function", "FunctionsRelayError", context); } }; FunctionsHttpError = class extends FunctionsError { constructor(context) { super("Edge Function returned a non-2xx status code", "FunctionsHttpError", context); } }; (function(FunctionRegion3) { FunctionRegion3["Any"] = "any"; FunctionRegion3["ApNortheast1"] = "ap-northeast-1"; FunctionRegion3["ApNortheast2"] = "ap-northeast-2"; FunctionRegion3["ApSouth1"] = "ap-south-1"; FunctionRegion3["ApSoutheast1"] = "ap-southeast-1"; FunctionRegion3["ApSoutheast2"] = "ap-southeast-2"; FunctionRegion3["CaCentral1"] = "ca-central-1"; FunctionRegion3["EuCentral1"] = "eu-central-1"; FunctionRegion3["EuWest1"] = "eu-west-1"; FunctionRegion3["EuWest2"] = "eu-west-2"; FunctionRegion3["EuWest3"] = "eu-west-3"; FunctionRegion3["SaEast1"] = "sa-east-1"; FunctionRegion3["UsEast1"] = "us-east-1"; FunctionRegion3["UsWest1"] = "us-west-1"; FunctionRegion3["UsWest2"] = "us-west-2"; })(FunctionRegion || (FunctionRegion = {})); } }); // ../../node_modules/.pnpm/@supabase+functions-js@2.86.2/node_modules/@supabase/functions-js/dist/module/FunctionsClient.js var FunctionsClient; var init_FunctionsClient = __esm({ "../../node_modules/.pnpm/@supabase+functions-js@2.86.2/node_modules/@supabase/functions-js/dist/module/FunctionsClient.js"() { init_tslib_es6(); init_helper(); init_types(); FunctionsClient = class { /** * Creates a new Functions client bound to an Edge Functions URL. * * @example * ```ts * import { FunctionsClient, FunctionRegion } from '@supabase/functions-js' * * const functions = new FunctionsClient('https://xyzcompany.supabase.co/functions/v1', { * headers: { apikey: 'public-anon-key' }, * region: FunctionRegion.UsEast1, * }) * ``` */ constructor(url, { headers = {}, customFetch, region = FunctionRegion.Any } = {}) { this.url = url; this.headers = headers; this.region = region; this.fetch = resolveFetch(customFetch); } /** * Updates the authorization header * @param token - the new jwt token sent in the authorisation header * @example * ```ts * functions.setAuth(session.access_token) * ``` */ setAuth(token) { this.headers.Authorization = `Bearer ${token}`; } /** * Invokes a function * @param functionName - The name of the Function to invoke. * @param options - Options for invoking the Function. * @example * ```ts * const { data, error } = await functions.invoke('hello-world', { * body: { name: 'Ada' }, * }) * ``` */ invoke(functionName_1) { return __awaiter(this, arguments, void 0, function* (functionName, options = {}) { var _a2; let timeoutId; let timeoutController; try { const { headers, method, body: functionArgs, signal, timeout } = options; let _headers = {}; let { region } = options; if (!region) { region = this.region; } const url = new URL(`${this.url}/${functionName}`); if (region && region !== "any") { _headers["x-region"] = region; url.searchParams.set("forceFunctionRegion", region); } let body; if (functionArgs && (headers && !Object.prototype.hasOwnProperty.call(headers, "Content-Type") || !headers)) { if (typeof Blob !== "undefined" && functionArgs instanceof Blob || functionArgs instanceof ArrayBuffer) { _headers["Content-Type"] = "application/octet-stream"; body = functionArgs; } else if (typeof functionArgs === "string") { _headers["Content-Type"] = "text/plain"; body = functionArgs; } else if (typeof FormData !== "undefined" && functionArgs instanceof FormData) { body = functionArgs; } else { _headers["Content-Type"] = "application/json"; body = JSON.stringify(functionArgs); } } else { body = functionArgs; } let effectiveSignal = signal; if (timeout) { timeoutController = new AbortController(); timeoutId = setTimeout(() => timeoutController.abort(), timeout); if (signal) { effectiveSignal = timeoutController.signal; signal.addEventListener("abort", () => timeoutController.abort()); } else { effectiveSignal = timeoutController.signal; } } const response = yield this.fetch(url.toString(), { method: method || "POST", // headers priority is (high to low): // 1. invoke-level headers // 2. client-level headers // 3. default Content-Type header headers: Object.assign(Object.assign(Object.assign({}, _headers), this.headers), headers), body, signal: effectiveSignal }).catch((fetchError) => { throw new FunctionsFetchError(fetchError); }); const isRelayError = response.headers.get("x-relay-error"); if (isRelayError && isRelayError === "true") { throw new FunctionsRelayError(response); } if (!response.ok) { throw new FunctionsHttpError(response); } let responseType = ((_a2 = response.headers.get("Content-Type")) !== null && _a2 !== void 0 ? _a2 : "text/plain").split(";")[0].trim(); let data; if (responseType === "application/json") { data = yield response.json(); } else if (responseType === "application/octet-stream" || responseType === "application/pdf") { data = yield response.blob(); } else if (responseType === "text/event-stream") { data = response; } else if (responseType === "multipart/form-data") { data = yield response.formData(); } else { data = yield response.text(); } return { data, error: null, response }; } catch (error) { return { data: null, error, response: error instanceof FunctionsHttpError || error instanceof FunctionsRelayError ? error.context : void 0 }; } finally { if (timeoutId) { clearTimeout(timeoutId); } } }); } }; } }); // ../../node_modules/.pnpm/@supabase+functions-js@2.86.2/node_modules/@supabase/functions-js/dist/module/index.js var module_exports = {}; __export(module_exports, { FunctionRegion: () => FunctionRegion, FunctionsClient: () => FunctionsClient, FunctionsError: () => FunctionsError, FunctionsFetchError: () => FunctionsFetchError, FunctionsHttpError: () => FunctionsHttpError, FunctionsRelayError: () => FunctionsRelayError }); var init_module = __esm({ "../../node_modules/.pnpm/@supabase+functions-js@2.86.2/node_modules/@supabase/functions-js/dist/module/index.js"() { init_FunctionsClient(); init_types(); } }); // ../../node_modules/.pnpm/@supabase+postgrest-js@2.86.2/node_modules/@supabase/postgrest-js/dist/cjs/PostgrestError.js var require_PostgrestError = __commonJS({ "../../node_modules/.pnpm/@supabase+postgrest-js@2.86.2/node_modules/@supabase/postgrest-js/dist/cjs/PostgrestError.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var PostgrestError2 = class extends Error { /** * @example * ```ts * import PostgrestError from '@supabase/postgrest-js' * * throw new PostgrestError({ * message: 'Row level security prevented the request', * details: 'RLS denied the insert', * hint: 'Check your policies', * code: 'PGRST301', * }) * ``` */ constructor(context) { super(context.message); this.name = "PostgrestError"; this.details = context.details; this.hint = context.hint; this.code = context.code; } }; exports.default = PostgrestError2; } }); // ../../node_modules/.pnpm/@supabase+postgrest-js@2.86.2/node_modules/@supabase/postgrest-js/dist/cjs/PostgrestBuilder.js var require_PostgrestBuilder = __commonJS({ "../../node_modules/.pnpm/@supabase+postgrest-js@2.86.2/node_modules/@supabase/postgrest-js/dist/cjs/PostgrestBuilder.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports)); var PostgrestError_1 = tslib_1.__importDefault(require_PostgrestError()); var PostgrestBuilder = class { /** * Creates a builder configured for a specific PostgREST request. * * @example * ```ts * import PostgrestQueryBuilder from '@supabase/postgrest-js' * * const builder = new PostgrestQueryBuilder( * new URL('https://xyzcompany.supabase.co/rest/v1/users'), * { headers: new Headers({ apikey: 'public-anon-key' }) } * ) * ``` */ constructor(builder) { var _a2, _b; this.shouldThrowOnError = false; this.method = builder.method; this.url = builder.url; this.headers = new Headers(builder.headers); this.schema = builder.schema; this.body = builder.body; this.shouldThrowOnError = (_a2 = builder.shouldThrowOnError) !== null && _a2 !== void 0 ? _a2 : false; this.signal = builder.signal; this.isMaybeSingle = (_b = builder.isMaybeSingle) !== null && _b !== void 0 ? _b : false; if (builder.fetch) { this.fetch = builder.fetch; } else { this.fetch = fetch; } } /** * If there's an error with the query, throwOnError will reject the promise by * throwing the error instead of returning it as part of a successful response. * * {@link https://github.com/supabase/supabase-js/issues/92} */ throwOnError() { this.shouldThrowOnError = true; return this; } /** * Set an HTTP header for the request. */ setHeader(name, value) { this.headers = new Headers(this.headers); this.headers.set(name, value); return this; } then(onfulfilled, onrejected) { if (this.schema === void 0) { } else if (["GET", "HEAD"].includes(this.method)) { this.headers.set("Accept-Profile", this.schema); } else { this.headers.set("Content-Profile", this.schema); } if (this.method !== "GET" && this.method !== "HEAD") { this.headers.set("Content-Type", "application/json"); } const _fetch = this.fetch; let res = _fetch(this.url.toString(), { method: this.method, headers: this.headers, body: JSON.stringify(this.body), signal: this.signal }).then(async (res2) => { var _a2, _b, _c, _d; let error = null; let data = null; let count = null; let status = res2.status; let statusText = res2.statusText; if (res2.ok) { if (this.method !== "HEAD") { const body = await res2.text(); if (body === "") { } else if (this.headers.get("Accept") === "text/csv") { data = body; } else if (this.headers.get("Accept") && ((_a2 = this.headers.get("Accept")) === null || _a2 === void 0 ? void 0 : _a2.includes("application/vnd.pgrst.plan+text"))) { data = body; } else { data = JSON.parse(body); } } const countHeader = (_b = this.headers.get("Prefer")) === null || _b === void 0 ? void 0 : _b.match(/count=(exact|planned|estimated)/); const contentRange = (_c = res2.headers.get("content-range")) === null || _c === void 0 ? void 0 : _c.split("/"); if (countHeader && contentRange && contentRange.length > 1) { count = parseInt(contentRange[1]); } if (this.isMaybeSingle && this.method === "GET" && Array.isArray(data)) { if (data.length > 1) { error = { // https://github.com/PostgREST/postgrest/blob/a867d79c42419af16c18c3fb019eba8df992626f/src/PostgREST/Error.hs#L553 code: "PGRST116", details: `Results contain ${data.length} rows, application/vnd.pgrst.object+json requires 1 row`, hint: null, message: "JSON object requested, multiple (or no) rows returned" }; data = null; count = null; status = 406; statusText = "Not Acceptable"; } else if (data.length === 1) { data = data[0]; } else { data = null; } } } else { const body = await res2.text(); try { error = JSON.parse(body); if (Array.isArray(error) && res2.status === 404) { data = []; error = null; status = 200; statusText = "OK"; } } catch (_e) { if (res2.status === 404 && body === "") { status = 204; statusText = "No Content"; } else { error = { message: body }; } } if (error && this.isMaybeSingle && ((_d = error === null || error === void 0 ? void 0 : error.details) === null || _d === void 0 ? void 0 : _d.includes("0 rows"))) { error = null; status = 200; statusText = "OK"; } if (error && this.shouldThrowOnError) { throw new PostgrestError_1.default(error); } } const postgrestResponse = { error, data, count, status, statusText }; return postgrestResponse; }); if (!this.shouldThrowOnError) { res = res.catch((fetchError) => { var _a2, _b, _c, _d, _e, _f; let errorDetails = ""; const cause = fetchError === null || fetchError === void 0 ? void 0 : fetchError.cause; if (cause) { const causeMessage = (_a2 = cause === null || cause === void 0 ? void 0 : cause.message) !== null && _a2 !== void 0 ? _a2 : ""; const causeCode = (_b = cause === null || cause === void 0 ? void 0 : cause.code) !== null && _b !== void 0 ? _b : ""; errorDetails = `${(_c = fetchError === null || fetchError === void 0 ? void 0 : fetchError.name) !== null && _c !== void 0 ? _c : "FetchError"}: ${fetchError === null || fetchError === void 0 ? void 0 : fetchError.message}`; errorDetails += ` Caused by: ${(_d = cause === null || cause === void 0 ? void 0 : cause.name) !== null && _d !== void 0 ? _d : "Error"}: ${causeMessage}`; if (causeCode) { errorDetails += ` (${causeCode})`; } if (cause === null || cause === void 0 ? void 0 : cause.stack) { errorDetails += ` ${cause.stack}`; } } else { errorDetails = (_e = fetchError === null || fetchError === void 0 ? void 0 : fetchError.stack) !== null && _e !== void 0 ? _e : ""; } return { error: { message: `${(_f = fetchError === null || fetchError === void 0 ? void 0 : fetchError.name) !== null && _f !== void 0 ? _f : "FetchError"}: ${fetchError === null || fetchError === void 0 ? void 0 : fetchError.message}`, details: errorDetails, hint: "", code: "" }, data: null, count: null, status: 0, statusText: "" }; }); } return res.then(onfulfilled, onrejected); } /** * Override the type of the returned `data`. * * @typeParam NewResult - The new result type to override with * @deprecated Use overrideTypes() method at the end of your call chain instead */ returns() { return this; } /** * Override the type of the returned `data` field in the response. * * @typeParam NewResult - The new type to cast the response data to * @typeParam Options - Optional type configuration (defaults to { merge: true }) * @typeParam Options.merge - When true, merges the new type with existing return type. When false, replaces the existing types entirely (defaults to true) * @example * ```typescript * // Merge with existing types (default behavior) * const query = supabase * .from('users') * .select() * .overrideTypes<{ custom_field: string }>() * * // Replace existing types completely * const replaceQuery = supabase * .from('users') * .select() * .overrideTypes<{ id: number; name: string }, { merge: false }>() * ``` * @returns A PostgrestBuilder instance with the new type */ overrideTypes() { return this; } }; exports.default = PostgrestBuilder; } }); // ../../node_modules/.pnpm/@supabase+postgrest-js@2.86.2/node_modules/@supabase/postgrest-js/dist/cjs/PostgrestTransformBuilder.js var require_PostgrestTransformBuilder = __commonJS({ "../../node_modules/.pnpm/@supabase+postgrest-js@2.86.2/node_modules/@supabase/postgrest-js/dist/cjs/PostgrestTransformBuilder.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports)); var PostgrestBuilder_1 = tslib_1.__importDefault(require_PostgrestBuilder()); var PostgrestTransformBuilder = class extends PostgrestBuilder_1.default { /** * Perform a SELECT on the query result. * * By default, `.insert()`, `.update()`, `.upsert()`, and `.delete()` do not * return modified rows. By calling this method, modified rows are returned in * `data`. * * @param columns - The columns to retrieve, separated by commas */ select(columns) { let quoted = false; const cleanedColumns = (columns !== null && columns !== void 0 ? columns : "*").split("").map((c) => { if (/\s/.test(c) && !quoted) { return ""; } if (c === '"') { quoted = !quoted; } return c; }).join(""); this.url.searchParams.set("select", cleanedColumns); this.headers.append("Prefer", "return=representation"); return this; } /** * Order the query result by `column`. * * You can call this method multiple times to order by multiple columns. * * You can order referenced tables, but it only affects the ordering of the * parent table if you use `!inner` in the query. * * @param column - The column to order by * @param options - Named parameters * @param options.ascending - If `true`, the result will be in ascending order * @param options.nullsFirst - If `true`, `null`s appear first. If `false`, * `null`s appear last. * @param options.referencedTable - Set this to order a referenced table by * its columns * @param options.foreignTable - Deprecated, use `options.referencedTable` * instead */ order(column, { ascending = true, nullsFirst, foreignTable, referencedTable = foreignTable } = {}) { const key = referencedTable ? `${referencedTable}.order` : "order"; const existingOrder = this.url.searchParams.get(key); this.url.searchParams.set(key, `${existingOrder ? `${existingOrder},` : ""}${column}.${ascending ? "asc" : "desc"}${nullsFirst === void 0 ? "" : nullsFirst ? ".nullsfirst" : ".nullslast"}`); return this; } /** * Limit the query result by `count`. * * @param count - The maximum number of rows to return * @param options - Named parameters * @param options.referencedTable - Set this to limit rows of referenced * tables instead of the parent table * @param options.foreignTable - Deprecated, use `options.referencedTable` * instead */ limit(count, { foreignTable, referencedTable = foreignTable } = {}) { const key = typeof referencedTable === "undefined" ? "limit" : `${referencedTable}.limit`; this.url.searchParams.set(key, `${count}`); return this; } /** * Limit the query result by starting at an offset `from` and ending at the offset `to`. * Only records within this range are returned. * This respects the query order and if there is no order clause the range could behave unexpectedly. * The `from` and `to` values are 0-based and inclusive: `range(1, 3)` will include the second, third * and fourth rows of the query. * * @param from - The starting index from which to limit the result * @param to - The last index to which to limit the result * @param options - Named parameters * @param options.referencedTable - Set this to limit rows of referenced * tables instead of the parent table * @param options.foreignTable - Deprecated, use `options.referencedTable` * instead */ range(from, to, { foreignTable, referencedTable = foreignTable } = {}) { const keyOffset = typeof referencedTable === "undefined" ? "offset" : `${referencedTable}.offset`; const keyLimit = typeof referencedTable === "undefined" ? "limit" : `${referencedTable}.limit`; this.url.searchParams.set(keyOffset, `${from}`); this.url.searchParams.set(keyLimit, `${to - from + 1}`); return this; } /** * Set the AbortSignal for the fetch request. * * @param signal - The AbortSignal to use for the fetch request */ abortSignal(signal) { this.signal = signal; return this; } /** * Return `data` as a single object instead of an array of objects. * * Query result must be one row (e.g. using `.limit(1)`), otherwise this * returns an error. */ single() { this.headers.set("Accept", "application/vnd.pgrst.object+json"); return this; } /** * Return `data` as a single object instead of an array of objects. * * Query result must be zero or one row (e.g. using `.limit(1)`), otherwise * this returns an error. */ maybeSingle() { if (this.method === "GET") { this.headers.set("Accept", "application/json"); } else { this.headers.set("Accept", "application/vnd.pgrst.object+json"); } this.isMaybeSingle = true; return this; } /** * Return `data` as a string in CSV format. */ csv() { this.headers.set("Accept", "text/csv"); return this; } /** * Return `data` as an object in [GeoJSON](https://geojson.org) format. */ geojson() { this.headers.set("Accept", "application/geo+json"); return this; } /** * Return `data` as the EXPLAIN plan for the query. * * You need to enable the * [db_plan_enabled](https://supabase.com/docs/guides/database/debugging-performance#enabling-explain) * setting before using this method. * * @param options - Named parameters * * @param options.analyze - If `true`, the query will be executed and the * actual run time will be returned * * @param options.verbose - If `true`, the query identifier will be returned * and `data` will include the output columns of the query * * @param options.settings - If `true`, include information on configuration * parameters that affect query planning * * @param options.buffers - If `true`, include information on buffer usage * * @param options.wal - If `true`, include information on WAL record generation * * @param options.format - The format of the output, can be `"text"` (default) * or `"json"` */ explain({ analyze = false, verbose = false, settings = false, buffers = false, wal = false, format = "text" } = {}) { var _a2; const options = [ analyze ? "analyze" : null, verbose ? "verbose" : null, settings ? "settings" : null, buffers ? "buffers" : null, wal ? "wal" : null ].filter(Boolean).join("|"); const forMediatype = (_a2 = this.headers.get("Accept")) !== null && _a2 !== void 0 ? _a2 : "application/json"; this.headers.set("Accept", `application/vnd.pgrst.plan+${format}; for="${forMediatype}"; options=${options};`); if (format === "json") { return this; } else { return this; } } /** * Rollback the query. * * `data` will still be returned, but the query is not committed. */ rollback() { this.headers.append("Prefer", "tx=rollback"); return this; } /** * Override the type of the returned `data`. * * @typeParam NewResult - The new result type to override with * @deprecated Use overrideTypes() method at the end of your call chain instead */ returns() { return this; } /** * Set the maximum number of rows that can be affected by the query. * Only available in PostgREST v13+ and only works with PATCH and DELETE methods. * * @param value - The maximum number of rows that can be affected */ maxAffected(value) { this.headers.append("Prefer", "handling=strict"); this.headers.append("Prefer", `max-affected=${value}`); return this; } }; exports.default = PostgrestTransformBuilder; } }); // ../../node_modules/.pnpm/@supabase+postgrest-js@2.86.2/node_modules/@supabase/postgrest-js/dist/cjs/PostgrestFilterBuilder.js var require_PostgrestFilterBuilder = __commonJS({ "../../node_modules/.pnpm/@supabase+postgrest-js@2.86.2/node_modules/@supabase/postgrest-js/dist/cjs/PostgrestFilterBuilder.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports)); var PostgrestTransformBuilder_1 = tslib_1.__importDefault(require_PostgrestTransformBuilder()); var PostgrestReservedCharsRegexp = new RegExp("[,()]"); var PostgrestFilterBuilder = class extends PostgrestTransformBuilder_1.default { /** * Match only rows where `column` is equal to `value`. * * To check if the value of `column` is NULL, you should use `.is()` instead. * * @param column - The column to filter on * @param value - The value to filter with */ eq(column, value) { this.url.searchParams.append(column, `eq.${value}`); return this; } /** * Match only rows where `column` is not equal to `value`. * * @param column - The column to filter on * @param value - The value to filter with */ neq(column, value) { this.url.searchParams.append(column, `neq.${value}`); return this; } /** * Match only rows where `column` is greater than `value`. * * @param column - The column to filter on * @param value - The value to filter with */ gt(column, value) { this.url.searchParams.append(column, `gt.${value}`); return this; } /** * Match only rows where `column` is greater than or equal to `value`. * * @param column - The column to filter on * @param value - The value to filter with */ gte(column, value) { this.url.searchParams.append(column, `gte.${value}`); return this; } /** * Match only rows where `column` is less than `value`. * * @param column - The column to filter on * @param value - The value to filter with */ lt(column, value) { this.url.searchParams.append(column, `lt.${value}`); return this; } /** * Match only rows where `column` is less than or equal to `value`. * * @param column - The column to filter on * @param value - The value to filter with */ lte(column, value) { this.url.searchParams.append(column, `lte.${value}`); return this; } /** * Match only rows where `column` matches `pattern` case-sensitively. * * @param column - The column to filter on * @param pattern - The pattern to match with */ like(column, pattern) { this.url.searchParams.append(column, `like.${pattern}`); return this; } /** * Match only rows where `column` matches all of `patterns` case-sensitively. * * @param column - The column to filter on * @param patterns - The patterns to match with */ likeAllOf(column, patterns) { this.url.searchParams.append(column, `like(all).{${patterns.join(",")}}`); return this; } /** * Match only rows where `column` matches any of `patterns` case-sensitively. * * @param column - The column to filter on * @param patterns - The patterns to match with */ likeAnyOf(column, patterns) { this.url.searchParams.append(column, `like(any).{${patterns.join(",")}}`); return this; } /** * Match only rows where `column` matches `pattern` case-insensitively. * * @param column - The column to filter on * @param pattern - The pattern to match with */ ilike(column, pattern) { this.url.searchParams.append(column, `ilike.${pattern}`); return this; } /** * Match only rows where `column` matches all of `patterns` case-insensitively. * * @param column - The column to filter on * @param patterns - The patterns to match with */ ilikeAllOf(column, patterns) { this.url.searchParams.append(column, `ilike(all).{${patterns.join(",")}}`); return this; } /** * Match only rows where `column` matches any of `patterns` case-insensitively. * * @param column - The column to filter on * @param patterns - The patterns to match with */ ilikeAnyOf(column, patterns) { this.url.searchParams.append(column, `ilike(any).{${patterns.join(",")}}`); return this; } /** * Match only rows where `column` matches the PostgreSQL regex `pattern` * case-sensitively (using the `~` operator). * * @param column - The column to filter on * @param pattern - The PostgreSQL regular expression pattern to match with */ regexMatch(column, pattern) { this.url.searchParams.append(column, `match.${pattern}`); return this; } /** * Match only rows where `column` matches the PostgreSQL regex `pattern` * case-insensitively (using the `~*` operator). * * @param column - The column to filter on * @param pattern - The PostgreSQL regular expression pattern to match with */ regexIMatch(column, pattern) { this.url.searchParams.append(column, `imatch.${pattern}`); return this; } /** * Match only rows where `column` IS `value`. * * For non-boolean columns, this is only relevant for checking if the value of * `column` is NULL by setting `value` to `null`. * * For boolean columns, you can also set `value` to `true` or `false` and it * will behave the same way as `.eq()`. * * @param column - The column to filter on * @param value - The value to filter with */ is(column, value) { this.url.searchParams.append(column, `is.${value}`); return this; } /** * Match only rows where `column` IS DISTINCT FROM `value`. * * Unlike `.neq()`, this treats `NULL` as a comparable value. Two `NULL` values * are considered equal (not distinct), and comparing `NULL` with any non-NULL * value returns true (distinct). * * @param column - The column to filter on * @param value - The value to filter with */ isDistinct(column, value) { this.url.searchParams.append(column, `isdistinct.${value}`); return this; } /** * Match only rows where `column` is included in the `values` array. * * @param column - The column to filter on * @param values - The values array to filter with */ in(column, values) { const cleanedValues = Array.from(new Set(values)).map((s) => { if (typeof s === "string" && PostgrestReservedCharsRegexp.test(s)) return `"${s}"`; else return `${s}`; }).join(","); this.url.searchParams.append(column, `in.(${cleanedValues})`); return this; } /** * Only relevant for jsonb, array, and range columns. Match only rows where * `column` contains every element appearing in `value`. * * @param column - The jsonb, array, or range column to filter on * @param value - The jsonb, array, or range value to filter with */ contains(column, value) { if (typeof value === "string") { this.url.searchParams.append(column, `cs.${value}`); } else if (Array.isArray(value)) { this.url.searchParams.append(column, `cs.{${value.join(",")}}`); } else { this.url.searchParams.append(column, `cs.${JSON.stringify(value)}`); } return this; } /** * Only relevant for jsonb, array, and range columns. Match only rows where * every element appearing in `column` is contained by `value`. * * @param column - The jsonb, array, or range column to filter on * @param value - The jsonb, array, or range value to filter with */ containedBy(column, value) { if (typeof value === "string") { this.url.searchParams.append(column, `cd.${value}`); } else if (Array.isArray(value)) { this.url.searchParams.append(column, `cd.{${value.join(",")}}`); } else { this.url.searchParams.append(column, `cd.${JSON.stringify(value)}`); } return this; } /** * Only relevant for range columns. Match only rows where every element in * `column` is greater than any element in `range`. * * @param column - The range column to filter on * @param range - The range to filter with */ rangeGt(column, range) { this.url.searchParams.append(column, `sr.${range}`); return this; } /** * Only relevant for range columns. Match only rows where every element in * `column` is either contained in `range` or greater than any element in * `range`. * * @param column - The range column to filter on * @param range - The range to filter with */ rangeGte(column, range) { this.url.searchParams.append(column, `nxl.${range}`); return this; } /** * Only relevant for range columns. Match only rows where every element in * `column` is less than any element in `range`. * * @param column - The range column to filter on * @param range - The range to filter with */ rangeLt(column, range) { this.url.searchParams.append(column, `sl.${range}`); return this; } /** * Only relevant for range columns. Match only rows where every element in * `column` is either contained in `range` or less than any element in * `range`. * * @param column - The range column to filter on * @param range - The range to filter with */ rangeLte(column, range) { this.url.searchParams.append(column, `nxr.${range}`); return this; } /** * Only relevant for range columns. Match only rows where `column` is * mutually exclusive to `range` and there can be no element between the two * ranges. * * @param column - The range column to filter on * @param range - The range to filter with */ rangeAdjacent(column, range) { this.url.searchParams.append(column, `adj.${range}`); return this; } /** * Only relevant for array and range columns. Match only rows where * `column` and `value` have an element in common. * * @param column - The array or range column to filter on * @param value - The array or range value to filter with */ overlaps(column, value) { if (typeof value === "string") { this.url.searchParams.append(column, `ov.${value}`); } else { this.url.searchParams.append(column, `ov.{${value.join(",")}}`); } return this; } /** * Only relevant for text and tsvector columns. Match only rows where * `column` matches the query string in `query`. * * @param column - The text or tsvector column to filter on * @param query - The query text to match with * @param options - Named parameters * @param options.config - The text search configuration to use * @param options.type - Change how the `query` text is interpreted */ textSearch(column, query, { config, type } = {}) { let typePart = ""; if (type === "plain") { typePart = "pl"; } else if (type === "phrase") { typePart = "ph"; } else if (type === "websearch") { typePart = "w"; } const configPart = config === void 0 ? "" : `(${config})`; this.url.searchParams.append(column, `${typePart}fts${configPart}.${query}`); return this; } /** * Match only rows where each column in `query` keys is equal to its * associated value. Shorthand for multiple `.eq()`s. * * @param query - The object to filter with, with column names as keys mapped * to their filter values */ match(query) { Object.entries(query).forEach(([column, value]) => { this.url.searchParams.append(column, `eq.${value}`); }); return this; } /** * Match only rows which doesn't satisfy the filter. * * Unlike most filters, `opearator` and `value` are used as-is and need to * follow [PostgREST * syntax](https://postgrest.org/en/stable/api.html#operators). You also need * to make sure they are properly sanitized. * * @param column - The column to filter on * @param operator - The operator to be negated to filter with, following * PostgREST syntax * @param value - The value to filter with, following PostgREST syntax */ not(column, operator, value) { this.url.searchParams.append(column, `not.${operator}.${value}`); return this; } /** * Match only rows which satisfy at least one of the filters. * * Unlike most filters, `filters` is used as-is and needs to follow [PostgREST * syntax](https://postgrest.org/en/stable/api.html#operators). You also need * to make sure it's properly sanitized. * * It's currently not possible to do an `.or()` filter across multiple tables. * * @param filters - The filters to use, following PostgREST syntax * @param options - Named parameters * @param options.referencedTable - Set this to filter on referenced tables * instead of the parent table * @param options.foreignTable - Deprecated, use `referencedTable` instead */ or(filters, { foreignTable, referencedTable = foreignTable } = {}) { const key = referencedTable ? `${referencedTable}.or` : "or"; this.url.searchParams.append(key, `(${filters})`); return this; } /** * Match only rows which satisfy the filter. This is an escape hatch - you * should use the specific filter methods wherever possible. * * Unlike most filters, `opearator` and `value` are used as-is and need to * follow [PostgREST * syntax](https://postgrest.org/en/stable/api.html#operators). You also need * to make sure they are properly sanitized. * * @param column - The column to filter on * @param operator - The operator to filter with, following PostgREST syntax * @param value - The value to filter with, following PostgREST syntax */ filter(column, operator, value) { this.url.searchParams.append(column, `${operator}.${value}`); return this; } }; exports.default = PostgrestFilterBuilder; } }); // ../../node_modules/.pnpm/@supabase+postgrest-js@2.86.2/node_modules/@supabase/postgrest-js/dist/cjs/PostgrestQueryBuilder.js var require_PostgrestQueryBuilder = __commonJS({ "../../node_modules/.pnpm/@supabase+postgrest-js@2.86.2/node_modules/@supabase/postgrest-js/dist/cjs/PostgrestQueryBuilder.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports)); var PostgrestFilterBuilder_1 = tslib_1.__importDefault(require_PostgrestFilterBuilder()); var PostgrestQueryBuilder = class { /** * Creates a query builder scoped to a Postgres table or view. * * @example * ```ts * import PostgrestQueryBuilder from '@supabase/postgrest-js' * * const query = new PostgrestQueryBuilder( * new URL('https://xyzcompany.supabase.co/rest/v1/users'), * { headers: { apikey: 'public-anon-key' } } * ) * ``` */ constructor(url, { headers = {}, schema, fetch: fetch2 }) { this.url = url; this.headers = new Headers(headers); this.schema = schema; this.fetch = fetch2; } /** * Perform a SELECT query on the table or view. * * @param columns - The columns to retrieve, separated by commas. Columns can be renamed when returned with `customName:columnName` * * @param options - Named parameters * * @param options.head - When set to `true`, `data` will not be returned. * Useful if you only need the count. * * @param options.count - Count algorithm to use to count rows in the table or view. * * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the * hood. * * `"planned"`: Approximated but fast count algorithm. Uses the Postgres * statistics under the hood. * * `"estimated"`: Uses exact count for low numbers and planned count for high * numbers. */ select(columns, options) { const { head: head2 = false, count } = options !== null && options !== void 0 ? options : {}; const method = head2 ? "HEAD" : "GET"; let quoted = false; const cleanedColumns = (columns !== null && columns !== void 0 ? columns : "*").split("").map((c) => { if (/\s/.test(c) && !quoted) { return ""; } if (c === '"') { quoted = !quoted; } return c; }).join(""); this.url.searchParams.set("select", cleanedColumns); if (count) { this.headers.append("Prefer", `count=${count}`); } return new PostgrestFilterBuilder_1.default({ method, url: this.url, headers: this.headers, schema: this.schema, fetch: this.fetch }); } /** * Perform an INSERT into the table or view. * * By default, inserted rows are not returned. To return it, chain the call * with `.select()`. * * @param values - The values to insert. Pass an object to insert a single row * or an array to insert multiple rows. * * @param options - Named parameters * * @param options.count - Count algorithm to use to count inserted rows. * * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the * hood. * * `"planned"`: Approximated but fast count algorithm. Uses the Postgres * statistics under the hood. * * `"estimated"`: Uses exact count for low numbers and planned count for high * numbers. * * @param options.defaultToNull - Make missing fields default to `null`. * Otherwise, use the default value for the column. Only applies for bulk * inserts. */ insert(values, { count, defaultToNull = true } = {}) { var _a2; const method = "POST"; if (count) { this.headers.append("Prefer", `count=${count}`); } if (!defaultToNull) { this.headers.append("Prefer", `missing=default`); } if (Array.isArray(values)) { const columns = values.reduce((acc, x) => acc.concat(Object.keys(x)), []); if (columns.length > 0) { const uniqueColumns = [...new Set(columns)].map((column) => `"${column}"`); this.url.searchParams.set("columns", uniqueColumns.join(",")); } } return new PostgrestFilterBuilder_1.default({ method, url: this.url, headers: this.headers, schema: this.schema, body: values, fetch: (_a2 = this.fetch) !== null && _a2 !== void 0 ? _a2 : fetch }); } /** * Perform an UPSERT on the table or view. Depending on the column(s) passed * to `onConflict`, `.upsert()` allows you to perform the equivalent of * `.insert()` if a row with the corresponding `onConflict` columns doesn't * exist, or if it does exist, perform an alternative action depending on * `ignoreDuplicates`. * * By default, upserted rows are not returned. To return it, chain the call * with `.select()`. * * @param values - The values to upsert with. Pass an object to upsert a * single row or an array to upsert multiple rows. * * @param options - Named parameters * * @param options.onConflict - Comma-separated UNIQUE column(s) to specify how * duplicate rows are determined. Two rows are duplicates if all the * `onConflict` columns are equal. * * @param options.ignoreDuplicates - If `true`, duplicate rows are ignored. If * `false`, duplicate rows are merged with existing rows. * * @param options.count - Count algorithm to use to count upserted rows. * * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the * hood. * * `"planned"`: Approximated but fast count algorithm. Uses the Postgres * statistics under the hood. * * `"estimated"`: Uses exact count for low numbers and planned count for high * numbers. * * @param options.defaultToNull - Make missing fields default to `null`. * Otherwise, use the default value for the column. This only applies when * inserting new rows, not when merging with existing rows under * `ignoreDuplicates: false`. This also only applies when doing bulk upserts. * * @example Upsert a single row using a unique key * ```ts * // Upserting a single row, overwriting based on the 'username' unique column * const { data, error } = await supabase * .from('users') * .upsert({ username: 'supabot' }, { onConflict: 'username' }) * * // Example response: * // { * // data: [ * // { id: 4, message: 'bar', username: 'supabot' } * // ], * // error: null * // } * ``` * * @example Upsert with conflict resolution and exact row counting * ```ts * // Upserting and returning exact count * const { data, error, count } = await supabase * .from('users') * .upsert( * { * id: 3, * message: 'foo', * username: 'supabot' * }, * { * onConflict: 'username', * count: 'exact' * } * ) * * // Example response: * // { * // data: [ * // { * // id: 42, * // handle: "saoirse", * // display_name: "Saoirse" * // } * // ], * // count: 1, * // error: null * // } * ``` */ upsert(values, { onConflict, ignoreDuplicates = false, count, defaultToNull = true } = {}) { var _a2; const method = "POST"; this.headers.append("Prefer", `resolution=${ignoreDuplicates ? "ignore" : "merge"}-duplicates`); if (onConflict !== void 0) this.url.searchParams.set("on_conflict", onConflict); if (count) { this.headers.append("Prefer", `count=${count}`); } if (!defaultToNull) { this.headers.append("Prefer", "missing=default"); } if (Array.isArray(values)) { const columns = values.reduce((acc, x) => acc.concat(Object.keys(x)), []); if (columns.length > 0) { const uniqueColumns = [...new Set(columns)].map((column) => `"${column}"`); this.url.searchParams.set("columns", uniqueColumns.join(",")); } } return new PostgrestFilterBuilder_1.default({ method, url: this.url, headers: this.headers, schema: this.schema, body: values, fetch: (_a2 = this.fetch) !== null && _a2 !== void 0 ? _a2 : fetch }); } /** * Perform an UPDATE on the table or view. * * By default, updated rows are not returned. To return it, chain the call * with `.select()` after filters. * * @param values - The values to update with * * @param options - Named parameters * * @param options.count - Count algorithm to use to count updated rows. * * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the * hood. * * `"planned"`: Approximated but fast count algorithm. Uses the Postgres * statistics under the hood. * * `"estimated"`: Uses exact count for low numbers and planned count for high * numbers. */ update(values, { count } = {}) { var _a2; const method = "PATCH"; if (count) { this.headers.append("Prefer", `count=${count}`); } return new PostgrestFilterBuilder_1.default({ method, url: this.url, headers: this.headers, schema: this.schema, body: values, fetch: (_a2 = this.fetch) !== null && _a2 !== void 0 ? _a2 : fetch }); } /** * Perform a DELETE on the table or view. * * By default, deleted rows are not returned. To return it, chain the call * with `.select()` after filters. * * @param options - Named parameters * * @param options.count - Count algorithm to use to count deleted rows. * * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the * hood. * * `"planned"`: Approximated but fast count algorithm. Uses the Postgres * statistics under the hood. * * `"estimated"`: Uses exact count for low numbers and planned count for high * numbers. */ delete({ count } = {}) { var _a2; const method = "DELETE"; if (count) { this.headers.append("Prefer", `count=${count}`); } return new PostgrestFilterBuilder_1.default({ method, url: this.url, headers: this.headers, schema: this.schema, fetch: (_a2 = this.fetch) !== null && _a2 !== void 0 ? _a2 : fetch }); } }; exports.default = PostgrestQueryBuilder; } }); // ../../node_modules/.pnpm/@supabase+postgrest-js@2.86.2/node_modules/@supabase/postgrest-js/dist/cjs/PostgrestClient.js var require_PostgrestClient = __commonJS({ "../../node_modules/.pnpm/@supabase+postgrest-js@2.86.2/node_modules/@supabase/postgrest-js/dist/cjs/PostgrestClient.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports)); var PostgrestQueryBuilder_1 = tslib_1.__importDefault(require_PostgrestQueryBuilder()); var PostgrestFilterBuilder_1 = tslib_1.__importDefault(require_PostgrestFilterBuilder()); var PostgrestClient = class _PostgrestClient { // TODO: Add back shouldThrowOnError once we figure out the typings /** * Creates a PostgREST client. * * @param url - URL of the PostgREST endpoint * @param options - Named parameters * @param options.headers - Custom headers * @param options.schema - Postgres schema to switch to * @param options.fetch - Custom fetch * @example * ```ts * import PostgrestClient from '@supabase/postgrest-js' * * const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', { * headers: { apikey: 'public-anon-key' }, * schema: 'public', * }) * ``` */ constructor(url, { headers = {}, schema, fetch: fetch2 } = {}) { this.url = url; this.headers = new Headers(headers); this.schemaName = schema; this.fetch = fetch2; } /** * Perform a query on a table or a view. * * @param relation - The table or view name to query */ from(relation) { if (!relation || typeof relation !== "string" || relation.trim() === "") { throw new Error("Invalid relation name: relation must be a non-empty string."); } const url = new URL(`${this.url}/${relation}`); return new PostgrestQueryBuilder_1.default(url, { headers: new Headers(this.headers), schema: this.schemaName, fetch: this.fetch }); } /** * Select a schema to query or perform an function (rpc) call. * * The schema needs to be on the list of exposed schemas inside Supabase. * * @param schema - The schema to query */ schema(schema) { return new _PostgrestClient(this.url, { headers: this.headers, schema, fetch: this.fetch }); } /** * Perform a function call. * * @param fn - The function name to call * @param args - The arguments to pass to the function call * @param options - Named parameters * @param options.head - When set to `true`, `data` will not be returned. * Useful if you only need the count. * @param options.get - When set to `true`, the function will be called with * read-only access mode. * @param options.count - Count algorithm to use to count rows returned by the * function. Only applicable for [set-returning * functions](https://www.postgresql.org/docs/current/functions-srf.html). * * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the * hood. * * `"planned"`: Approximated but fast count algorithm. Uses the Postgres * statistics under the hood. * * `"estimated"`: Uses exact count for low numbers and planned count for high * numbers. * * @example * ```ts * // For cross-schema functions where type inference fails, use overrideTypes: * const { data } = await supabase * .schema('schema_b') * .rpc('function_a', {}) * .overrideTypes<{ id: string; user_id: string }[]>() * ``` */ rpc(fn, args = {}, { head: head2 = false, get: get2 = false, count } = {}) { var _a2; let method; const url = new URL(`${this.url}/rpc/${fn}`); let body; if (head2 || get2) { method = head2 ? "HEAD" : "GET"; Object.entries(args).filter(([_, value]) => value !== void 0).map(([name, value]) => [name, Array.isArray(value) ? `{${value.join(",")}}` : `${value}`]).forEach(([name, value]) => { url.searchParams.append(name, value); }); } else { method = "POST"; body = args; } const headers = new Headers(this.headers); if (count) { headers.set("Prefer", `count=${count}`); } return new PostgrestFilterBuilder_1.default({ method, url, headers, schema: this.schemaName, body, fetch: (_a2 = this.fetch) !== null && _a2 !== void 0 ? _a2 : fetch }); } }; exports.default = PostgrestClient; } }); // ../../node_modules/.pnpm/@supabase+postgrest-js@2.86.2/node_modules/@supabase/postgrest-js/dist/cjs/index.js var require_cjs = __commonJS({ "../../node_modules/.pnpm/@supabase+postgrest-js@2.86.2/node_modules/@supabase/postgrest-js/dist/cjs/index.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PostgrestError = exports.PostgrestBuilder = exports.PostgrestTransformBuilder = exports.PostgrestFilterBuilder = exports.PostgrestQueryBuilder = exports.PostgrestClient = void 0; var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports)); var PostgrestClient_1 = tslib_1.__importDefault(require_PostgrestClient()); exports.PostgrestClient = PostgrestClient_1.default; var PostgrestQueryBuilder_1 = tslib_1.__importDefault(require_PostgrestQueryBuilder()); exports.PostgrestQueryBuilder = PostgrestQueryBuilder_1.default; var PostgrestFilterBuilder_1 = tslib_1.__importDefault(require_PostgrestFilterBuilder()); exports.PostgrestFilterBuilder = PostgrestFilterBuilder_1.default; var PostgrestTransformBuilder_1 = tslib_1.__importDefault(require_PostgrestTransformBuilder()); exports.PostgrestTransformBuilder = PostgrestTransformBuilder_1.default; var PostgrestBuilder_1 = tslib_1.__importDefault(require_PostgrestBuilder()); exports.PostgrestBuilder = PostgrestBuilder_1.default; var PostgrestError_1 = tslib_1.__importDefault(require_PostgrestError()); exports.PostgrestError = PostgrestError_1.default; exports.default = { PostgrestClient: PostgrestClient_1.default, PostgrestQueryBuilder: PostgrestQueryBuilder_1.default, PostgrestFilterBuilder: PostgrestFilterBuilder_1.default, PostgrestTransformBuilder: PostgrestTransformBuilder_1.default, PostgrestBuilder: PostgrestBuilder_1.default, PostgrestError: PostgrestError_1.default }; } }); // ../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/lib/websocket-factory.js var WebSocketFactory, websocket_factory_default; var init_websocket_factory = __esm({ "../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/lib/websocket-factory.js"() { WebSocketFactory = class { /** * Static-only utility – prevent instantiation. */ constructor() { } static detectEnvironment() { var _a2; if (typeof WebSocket !== "undefined") { return { type: "native", constructor: WebSocket }; } if (typeof globalThis !== "undefined" && typeof globalThis.WebSocket !== "undefined") { return { type: "native", constructor: globalThis.WebSocket }; } if (typeof global !== "undefined" && typeof global.WebSocket !== "undefined") { return { type: "native", constructor: global.WebSocket }; } if (typeof globalThis !== "undefined" && typeof globalThis.WebSocketPair !== "undefined" && typeof globalThis.WebSocket === "undefined") { return { type: "cloudflare", error: "Cloudflare Workers detected. WebSocket clients are not supported in Cloudflare Workers.", workaround: "Use Cloudflare Workers WebSocket API for server-side WebSocket handling, or deploy to a different runtime." }; } if (typeof globalThis !== "undefined" && globalThis.EdgeRuntime || typeof navigator !== "undefined" && ((_a2 = navigator.userAgent) === null || _a2 === void 0 ? void 0 : _a2.includes("Vercel-Edge"))) { return { type: "unsupported", error: "Edge runtime detected (Vercel Edge/Netlify Edge). WebSockets are not supported in edge functions.", workaround: "Use serverless functions or a different deployment target for WebSocket functionality." }; } if (typeof process !== "undefined") { const processVersions = process["versions"]; if (processVersions && processVersions["node"]) { const versionString = processVersions["node"]; const nodeVersion = parseInt(versionString.replace(/^v/, "").split(".")[0]); if (nodeVersion >= 22) { if (typeof globalThis.WebSocket !== "undefined") { return { type: "native", constructor: globalThis.WebSocket }; } return { type: "unsupported", error: `Node.js ${nodeVersion} detected but native WebSocket not found.`, workaround: "Provide a WebSocket implementation via the transport option." }; } return { type: "unsupported", error: `Node.js ${nodeVersion} detected without native WebSocket support.`, workaround: 'For Node.js < 22, install "ws" package and provide it via the transport option:\nimport ws from "ws"\nnew RealtimeClient(url, { transport: ws })' }; } } return { type: "unsupported", error: "Unknown JavaScript runtime without WebSocket support.", workaround: "Ensure you're running in a supported environment (browser, Node.js, Deno) or provide a custom WebSocket implementation." }; } /** * Returns the best available WebSocket constructor for the current runtime. * * @example * ```ts * const WS = WebSocketFactory.getWebSocketConstructor() * const socket = new WS('wss://realtime.supabase.co/socket') * ``` */ static getWebSocketConstructor() { const env = this.detectEnvironment(); if (env.constructor) { return env.constructor; } let errorMessage = env.error || "WebSocket not supported in this environment."; if (env.workaround) { errorMessage += ` Suggested solution: ${env.workaround}`; } throw new Error(errorMessage); } /** * Creates a WebSocket using the detected constructor. * * @example * ```ts * const socket = WebSocketFactory.createWebSocket('wss://realtime.supabase.co/socket') * ``` */ static createWebSocket(url, protocols) { const WS = this.getWebSocketConstructor(); return new WS(url, protocols); } /** * Detects whether the runtime can establish WebSocket connections. * * @example * ```ts * if (!WebSocketFactory.isWebSocketSupported()) { * console.warn('Falling back to long polling') * } * ``` */ static isWebSocketSupported() { try { const env = this.detectEnvironment(); return env.type === "native" || env.type === "ws"; } catch (_a2) { return false; } } }; websocket_factory_default = WebSocketFactory; } }); // ../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/lib/version.js var version; var init_version = __esm({ "../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/lib/version.js"() { version = "2.86.2"; } }); // ../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/lib/constants.js var DEFAULT_VERSION, VSN_1_0_0, VSN_2_0_0, DEFAULT_VSN, DEFAULT_TIMEOUT, WS_CLOSE_NORMAL, MAX_PUSH_BUFFER_SIZE, SOCKET_STATES, CHANNEL_STATES, CHANNEL_EVENTS, TRANSPORTS, CONNECTION_STATE; var init_constants = __esm({ "../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/lib/constants.js"() { init_version(); DEFAULT_VERSION = `realtime-js/${version}`; VSN_1_0_0 = "1.0.0"; VSN_2_0_0 = "2.0.0"; DEFAULT_VSN = VSN_1_0_0; DEFAULT_TIMEOUT = 1e4; WS_CLOSE_NORMAL = 1e3; MAX_PUSH_BUFFER_SIZE = 100; (function(SOCKET_STATES2) { SOCKET_STATES2[SOCKET_STATES2["connecting"] = 0] = "connecting"; SOCKET_STATES2[SOCKET_STATES2["open"] = 1] = "open"; SOCKET_STATES2[SOCKET_STATES2["closing"] = 2] = "closing"; SOCKET_STATES2[SOCKET_STATES2["closed"] = 3] = "closed"; })(SOCKET_STATES || (SOCKET_STATES = {})); (function(CHANNEL_STATES2) { CHANNEL_STATES2["closed"] = "closed"; CHANNEL_STATES2["errored"] = "errored"; CHANNEL_STATES2["joined"] = "joined"; CHANNEL_STATES2["joining"] = "joining"; CHANNEL_STATES2["leaving"] = "leaving"; })(CHANNEL_STATES || (CHANNEL_STATES = {})); (function(CHANNEL_EVENTS2) { CHANNEL_EVENTS2["close"] = "phx_close"; CHANNEL_EVENTS2["error"] = "phx_error"; CHANNEL_EVENTS2["join"] = "phx_join"; CHANNEL_EVENTS2["reply"] = "phx_reply"; CHANNEL_EVENTS2["leave"] = "phx_leave"; CHANNEL_EVENTS2["access_token"] = "access_token"; })(CHANNEL_EVENTS || (CHANNEL_EVENTS = {})); (function(TRANSPORTS2) { TRANSPORTS2["websocket"] = "websocket"; })(TRANSPORTS || (TRANSPORTS = {})); (function(CONNECTION_STATE2) { CONNECTION_STATE2["Connecting"] = "connecting"; CONNECTION_STATE2["Open"] = "open"; CONNECTION_STATE2["Closing"] = "closing"; CONNECTION_STATE2["Closed"] = "closed"; })(CONNECTION_STATE || (CONNECTION_STATE = {})); } }); // ../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/lib/serializer.js var Serializer; var init_serializer = __esm({ "../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/lib/serializer.js"() { Serializer = class { constructor(allowedMetadataKeys) { this.HEADER_LENGTH = 1; this.USER_BROADCAST_PUSH_META_LENGTH = 6; this.KINDS = { userBroadcastPush: 3, userBroadcast: 4 }; this.BINARY_ENCODING = 0; this.JSON_ENCODING = 1; this.BROADCAST_EVENT = "broadcast"; this.allowedMetadataKeys = []; this.allowedMetadataKeys = allowedMetadataKeys !== null && allowedMetadataKeys !== void 0 ? allowedMetadataKeys : []; } encode(msg, callback) { if (msg.event === this.BROADCAST_EVENT && !(msg.payload instanceof ArrayBuffer) && typeof msg.payload.event === "string") { return callback(this._binaryEncodeUserBroadcastPush(msg)); } let payload = [msg.join_ref, msg.ref, msg.topic, msg.event, msg.payload]; return callback(JSON.stringify(payload)); } _binaryEncodeUserBroadcastPush(message) { var _a2; if (this._isArrayBuffer((_a2 = message.payload) === null || _a2 === void 0 ? void 0 : _a2.payload)) { return this._encodeBinaryUserBroadcastPush(message); } else { return this._encodeJsonUserBroadcastPush(message); } } _encodeBinaryUserBroadcastPush(message) { var _a2, _b; const userPayload = (_b = (_a2 = message.payload) === null || _a2 === void 0 ? void 0 : _a2.payload) !== null && _b !== void 0 ? _b : new ArrayBuffer(0); return this._encodeUserBroadcastPush(message, this.BINARY_ENCODING, userPayload); } _encodeJsonUserBroadcastPush(message) { var _a2, _b; const userPayload = (_b = (_a2 = message.payload) === null || _a2 === void 0 ? void 0 : _a2.payload) !== null && _b !== void 0 ? _b : {}; const encoder = new TextEncoder(); const encodedUserPayload = encoder.encode(JSON.stringify(userPayload)).buffer; return this._encodeUserBroadcastPush(message, this.JSON_ENCODING, encodedUserPayload); } _encodeUserBroadcastPush(message, encodingType, encodedPayload) { var _a2, _b; const topic = message.topic; const ref = (_a2 = message.ref) !== null && _a2 !== void 0 ? _a2 : ""; const joinRef = (_b = message.join_ref) !== null && _b !== void 0 ? _b : ""; const userEvent = message.payload.event; const rest = this.allowedMetadataKeys ? this._pick(message.payload, this.allowedMetadataKeys) : {}; const metadata = Object.keys(rest).length === 0 ? "" : JSON.stringify(rest); if (joinRef.length > 255) { throw new Error(`joinRef length ${joinRef.length} exceeds maximum of 255`); } if (ref.length > 255) { throw new Error(`ref length ${ref.length} exceeds maximum of 255`); } if (topic.length > 255) { throw new Error(`topic length ${topic.length} exceeds maximum of 255`); } if (userEvent.length > 255) { throw new Error(`userEvent length ${userEvent.length} exceeds maximum of 255`); } if (metadata.length > 255) { throw new Error(`metadata length ${metadata.length} exceeds maximum of 255`); } const metaLength = this.USER_BROADCAST_PUSH_META_LENGTH + joinRef.length + ref.length + topic.length + userEvent.length + metadata.length; const header = new ArrayBuffer(this.HEADER_LENGTH + metaLength); let view = new DataView(header); let offset = 0; view.setUint8(offset++, this.KINDS.userBroadcastPush); view.setUint8(offset++, joinRef.length); view.setUint8(offset++, ref.length); view.setUint8(offset++, topic.length); view.setUint8(offset++, userEvent.length); view.setUint8(offset++, metadata.length); view.setUint8(offset++, encodingType); Array.from(joinRef, (char) => view.setUint8(offset++, char.charCodeAt(0))); Array.from(ref, (char) => view.setUint8(offset++, char.charCodeAt(0))); Array.from(topic, (char) => view.setUint8(offset++, char.charCodeAt(0))); Array.from(userEvent, (char) => view.setUint8(offset++, char.charCodeAt(0))); Array.from(metadata, (char) => view.setUint8(offset++, char.charCodeAt(0))); var combined = new Uint8Array(header.byteLength + encodedPayload.byteLength); combined.set(new Uint8Array(header), 0); combined.set(new Uint8Array(encodedPayload), header.byteLength); return combined.buffer; } decode(rawPayload, callback) { if (this._isArrayBuffer(rawPayload)) { let result = this._binaryDecode(rawPayload); return callback(result); } if (typeof rawPayload === "string") { const jsonPayload = JSON.parse(rawPayload); const [join_ref, ref, topic, event, payload] = jsonPayload; return callback({ join_ref, ref, topic, event, payload }); } return callback({}); } _binaryDecode(buffer) { const view = new DataView(buffer); const kind = view.getUint8(0); const decoder = new TextDecoder(); switch (kind) { case this.KINDS.userBroadcast: return this._decodeUserBroadcast(buffer, view, decoder); } } _decodeUserBroadcast(buffer, view, decoder) { const topicSize = view.getUint8(1); const userEventSize = view.getUint8(2); const metadataSize = view.getUint8(3); const payloadEncoding = view.getUint8(4); let offset = this.HEADER_LENGTH + 4; const topic = decoder.decode(buffer.slice(offset, offset + topicSize)); offset = offset + topicSize; const userEvent = decoder.decode(buffer.slice(offset, offset + userEventSize)); offset = offset + userEventSize; const metadata = decoder.decode(buffer.slice(offset, offset + metadataSize)); offset = offset + metadataSize; const payload = buffer.slice(offset, buffer.byteLength); const parsedPayload = payloadEncoding === this.JSON_ENCODING ? JSON.parse(decoder.decode(payload)) : payload; const data = { type: this.BROADCAST_EVENT, event: userEvent, payload: parsedPayload }; if (metadataSize > 0) { data["meta"] = JSON.parse(metadata); } return { join_ref: null, ref: null, topic, event: this.BROADCAST_EVENT, payload: data }; } _isArrayBuffer(buffer) { var _a2; return buffer instanceof ArrayBuffer || ((_a2 = buffer === null || buffer === void 0 ? void 0 : buffer.constructor) === null || _a2 === void 0 ? void 0 : _a2.name) === "ArrayBuffer"; } _pick(obj, keys) { if (!obj || typeof obj !== "object") { return {}; } return Object.fromEntries(Object.entries(obj).filter(([key]) => keys.includes(key))); } }; } }); // ../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/lib/timer.js var Timer; var init_timer = __esm({ "../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/lib/timer.js"() { Timer = class { constructor(callback, timerCalc) { this.callback = callback; this.timerCalc = timerCalc; this.timer = void 0; this.tries = 0; this.callback = callback; this.timerCalc = timerCalc; } reset() { this.tries = 0; clearTimeout(this.timer); this.timer = void 0; } // Cancels any previous scheduleTimeout and schedules callback scheduleTimeout() { clearTimeout(this.timer); this.timer = setTimeout(() => { this.tries = this.tries + 1; this.callback(); }, this.timerCalc(this.tries + 1)); } }; } }); // ../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/lib/transformers.js var PostgresTypes, convertChangeData, convertColumn, convertCell, noop, toBoolean, toNumber, toJson, toArray, toTimestampString, httpEndpointURL; var init_transformers = __esm({ "../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/lib/transformers.js"() { (function(PostgresTypes2) { PostgresTypes2["abstime"] = "abstime"; PostgresTypes2["bool"] = "bool"; PostgresTypes2["date"] = "date"; PostgresTypes2["daterange"] = "daterange"; PostgresTypes2["float4"] = "float4"; PostgresTypes2["float8"] = "float8"; PostgresTypes2["int2"] = "int2"; PostgresTypes2["int4"] = "int4"; PostgresTypes2["int4range"] = "int4range"; PostgresTypes2["int8"] = "int8"; PostgresTypes2["int8range"] = "int8range"; PostgresTypes2["json"] = "json"; PostgresTypes2["jsonb"] = "jsonb"; PostgresTypes2["money"] = "money"; PostgresTypes2["numeric"] = "numeric"; PostgresTypes2["oid"] = "oid"; PostgresTypes2["reltime"] = "reltime"; PostgresTypes2["text"] = "text"; PostgresTypes2["time"] = "time"; PostgresTypes2["timestamp"] = "timestamp"; PostgresTypes2["timestamptz"] = "timestamptz"; PostgresTypes2["timetz"] = "timetz"; PostgresTypes2["tsrange"] = "tsrange"; PostgresTypes2["tstzrange"] = "tstzrange"; })(PostgresTypes || (PostgresTypes = {})); convertChangeData = (columns, record, options = {}) => { var _a2; const skipTypes = (_a2 = options.skipTypes) !== null && _a2 !== void 0 ? _a2 : []; if (!record) { return {}; } return Object.keys(record).reduce((acc, rec_key) => { acc[rec_key] = convertColumn(rec_key, columns, record, skipTypes); return acc; }, {}); }; convertColumn = (columnName, columns, record, skipTypes) => { const column = columns.find((x) => x.name === columnName); const colType = column === null || column === void 0 ? void 0 : column.type; const value = record[columnName]; if (colType && !skipTypes.includes(colType)) { return convertCell(colType, value); } return noop(value); }; convertCell = (type, value) => { if (type.charAt(0) === "_") { const dataType = type.slice(1, type.length); return toArray(value, dataType); } switch (type) { case PostgresTypes.bool: return toBoolean(value); case PostgresTypes.float4: case PostgresTypes.float8: case PostgresTypes.int2: case PostgresTypes.int4: case PostgresTypes.int8: case PostgresTypes.numeric: case PostgresTypes.oid: return toNumber(value); case PostgresTypes.json: case PostgresTypes.jsonb: return toJson(value); case PostgresTypes.timestamp: return toTimestampString(value); // Format to be consistent with PostgREST case PostgresTypes.abstime: // To allow users to cast it based on Timezone case PostgresTypes.date: // To allow users to cast it based on Timezone case PostgresTypes.daterange: case PostgresTypes.int4range: case PostgresTypes.int8range: case PostgresTypes.money: case PostgresTypes.reltime: // To allow users to cast it based on Timezone case PostgresTypes.text: case PostgresTypes.time: // To allow users to cast it based on Timezone case PostgresTypes.timestamptz: // To allow users to cast it based on Timezone case PostgresTypes.timetz: // To allow users to cast it based on Timezone case PostgresTypes.tsrange: case PostgresTypes.tstzrange: return noop(value); default: return noop(value); } }; noop = (value) => { return value; }; toBoolean = (value) => { switch (value) { case "t": return true; case "f": return false; default: return value; } }; toNumber = (value) => { if (typeof value === "string") { const parsedValue = parseFloat(value); if (!Number.isNaN(parsedValue)) { return parsedValue; } } return value; }; toJson = (value) => { if (typeof value === "string") { try { return JSON.parse(value); } catch (error) { console.log(`JSON parse error: ${error}`); return value; } } return value; }; toArray = (value, type) => { if (typeof value !== "string") { return value; } const lastIdx = value.length - 1; const closeBrace = value[lastIdx]; const openBrace = value[0]; if (openBrace === "{" && closeBrace === "}") { let arr; const valTrim = value.slice(1, lastIdx); try { arr = JSON.parse("[" + valTrim + "]"); } catch (_) { arr = valTrim ? valTrim.split(",") : []; } return arr.map((val) => convertCell(type, val)); } return value; }; toTimestampString = (value) => { if (typeof value === "string") { return value.replace(" ", "T"); } return value; }; httpEndpointURL = (socketUrl) => { const wsUrl = new URL(socketUrl); wsUrl.protocol = wsUrl.protocol.replace(/^ws/i, "http"); wsUrl.pathname = wsUrl.pathname.replace(/\/+$/, "").replace(/\/socket\/websocket$/i, "").replace(/\/socket$/i, "").replace(/\/websocket$/i, ""); if (wsUrl.pathname === "" || wsUrl.pathname === "/") { wsUrl.pathname = "/api/broadcast"; } else { wsUrl.pathname = wsUrl.pathname + "/api/broadcast"; } return wsUrl.href; }; } }); // ../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/lib/push.js var Push; var init_push = __esm({ "../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/lib/push.js"() { init_constants(); Push = class { /** * Initializes the Push * * @param channel The Channel * @param event The event, for example `"phx_join"` * @param payload The payload, for example `{user_id: 123}` * @param timeout The push timeout in milliseconds */ constructor(channel, event, payload = {}, timeout = DEFAULT_TIMEOUT) { this.channel = channel; this.event = event; this.payload = payload; this.timeout = timeout; this.sent = false; this.timeoutTimer = void 0; this.ref = ""; this.receivedResp = null; this.recHooks = []; this.refEvent = null; } resend(timeout) { this.timeout = timeout; this._cancelRefEvent(); this.ref = ""; this.refEvent = null; this.receivedResp = null; this.sent = false; this.send(); } send() { if (this._hasReceived("timeout")) { return; } this.startTimeout(); this.sent = true; this.channel.socket.push({ topic: this.channel.topic, event: this.event, payload: this.payload, ref: this.ref, join_ref: this.channel._joinRef() }); } updatePayload(payload) { this.payload = Object.assign(Object.assign({}, this.payload), payload); } receive(status, callback) { var _a2; if (this._hasReceived(status)) { callback((_a2 = this.receivedResp) === null || _a2 === void 0 ? void 0 : _a2.response); } this.recHooks.push({ status, callback }); return this; } startTimeout() { if (this.timeoutTimer) { return; } this.ref = this.channel.socket._makeRef(); this.refEvent = this.channel._replyEventName(this.ref); const callback = (payload) => { this._cancelRefEvent(); this._cancelTimeout(); this.receivedResp = payload; this._matchReceive(payload); }; this.channel._on(this.refEvent, {}, callback); this.timeoutTimer = setTimeout(() => { this.trigger("timeout", {}); }, this.timeout); } trigger(status, response) { if (this.refEvent) this.channel._trigger(this.refEvent, { status, response }); } destroy() { this._cancelRefEvent(); this._cancelTimeout(); } _cancelRefEvent() { if (!this.refEvent) { return; } this.channel._off(this.refEvent, {}); } _cancelTimeout() { clearTimeout(this.timeoutTimer); this.timeoutTimer = void 0; } _matchReceive({ status, response }) { this.recHooks.filter((h) => h.status === status).forEach((h) => h.callback(response)); } _hasReceived(status) { return this.receivedResp && this.receivedResp.status === status; } }; } }); // ../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/RealtimePresence.js var REALTIME_PRESENCE_LISTEN_EVENTS, RealtimePresence; var init_RealtimePresence = __esm({ "../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/RealtimePresence.js"() { (function(REALTIME_PRESENCE_LISTEN_EVENTS3) { REALTIME_PRESENCE_LISTEN_EVENTS3["SYNC"] = "sync"; REALTIME_PRESENCE_LISTEN_EVENTS3["JOIN"] = "join"; REALTIME_PRESENCE_LISTEN_EVENTS3["LEAVE"] = "leave"; })(REALTIME_PRESENCE_LISTEN_EVENTS || (REALTIME_PRESENCE_LISTEN_EVENTS = {})); RealtimePresence = class _RealtimePresence { /** * Creates a Presence helper that keeps the local presence state in sync with the server. * * @param channel - The realtime channel to bind to. * @param opts - Optional custom event names, e.g. `{ events: { state: 'state', diff: 'diff' } }`. * * @example * ```ts * const presence = new RealtimePresence(channel) * * channel.on('presence', ({ event, key }) => { * console.log(`Presence ${event} on ${key}`) * }) * ``` */ constructor(channel, opts) { this.channel = channel; this.state = {}; this.pendingDiffs = []; this.joinRef = null; this.enabled = false; this.caller = { onJoin: () => { }, onLeave: () => { }, onSync: () => { } }; const events = (opts === null || opts === void 0 ? void 0 : opts.events) || { state: "presence_state", diff: "presence_diff" }; this.channel._on(events.state, {}, (newState) => { const { onJoin, onLeave, onSync } = this.caller; this.joinRef = this.channel._joinRef(); this.state = _RealtimePresence.syncState(this.state, newState, onJoin, onLeave); this.pendingDiffs.forEach((diff) => { this.state = _RealtimePresence.syncDiff(this.state, diff, onJoin, onLeave); }); this.pendingDiffs = []; onSync(); }); this.channel._on(events.diff, {}, (diff) => { const { onJoin, onLeave, onSync } = this.caller; if (this.inPendingSyncState()) { this.pendingDiffs.push(diff); } else { this.state = _RealtimePresence.syncDiff(this.state, diff, onJoin, onLeave); onSync(); } }); this.onJoin((key, currentPresences, newPresences) => { this.channel._trigger("presence", { event: "join", key, currentPresences, newPresences }); }); this.onLeave((key, currentPresences, leftPresences) => { this.channel._trigger("presence", { event: "leave", key, currentPresences, leftPresences }); }); this.onSync(() => { this.channel._trigger("presence", { event: "sync" }); }); } /** * Used to sync the list of presences on the server with the * client's state. * * An optional `onJoin` and `onLeave` callback can be provided to * react to changes in the client's local presences across * disconnects and reconnects with the server. * * @internal */ static syncState(currentState, newState, onJoin, onLeave) { const state = this.cloneDeep(currentState); const transformedState = this.transformState(newState); const joins = {}; const leaves = {}; this.map(state, (key, presences) => { if (!transformedState[key]) { leaves[key] = presences; } }); this.map(transformedState, (key, newPresences) => { const currentPresences = state[key]; if (currentPresences) { const newPresenceRefs = newPresences.map((m) => m.presence_ref); const curPresenceRefs = currentPresences.map((m) => m.presence_ref); const joinedPresences = newPresences.filter((m) => curPresenceRefs.indexOf(m.presence_ref) < 0); const leftPresences = currentPresences.filter((m) => newPresenceRefs.indexOf(m.presence_ref) < 0); if (joinedPresences.length > 0) { joins[key] = joinedPresences; } if (leftPresences.length > 0) { leaves[key] = leftPresences; } } else { joins[key] = newPresences; } }); return this.syncDiff(state, { joins, leaves }, onJoin, onLeave); } /** * Used to sync a diff of presence join and leave events from the * server, as they happen. * * Like `syncState`, `syncDiff` accepts optional `onJoin` and * `onLeave` callbacks to react to a user joining or leaving from a * device. * * @internal */ static syncDiff(state, diff, onJoin, onLeave) { const { joins, leaves } = { joins: this.transformState(diff.joins), leaves: this.transformState(diff.leaves) }; if (!onJoin) { onJoin = () => { }; } if (!onLeave) { onLeave = () => { }; } this.map(joins, (key, newPresences) => { var _a2; const currentPresences = (_a2 = state[key]) !== null && _a2 !== void 0 ? _a2 : []; state[key] = this.cloneDeep(newPresences); if (currentPresences.length > 0) { const joinedPresenceRefs = state[key].map((m) => m.presence_ref); const curPresences = currentPresences.filter((m) => joinedPresenceRefs.indexOf(m.presence_ref) < 0); state[key].unshift(...curPresences); } onJoin(key, currentPresences, newPresences); }); this.map(leaves, (key, leftPresences) => { let currentPresences = state[key]; if (!currentPresences) return; const presenceRefsToRemove = leftPresences.map((m) => m.presence_ref); currentPresences = currentPresences.filter((m) => presenceRefsToRemove.indexOf(m.presence_ref) < 0); state[key] = currentPresences; onLeave(key, currentPresences, leftPresences); if (currentPresences.length === 0) delete state[key]; }); return state; } /** @internal */ static map(obj, func) { return Object.getOwnPropertyNames(obj).map((key) => func(key, obj[key])); } /** * Remove 'metas' key * Change 'phx_ref' to 'presence_ref' * Remove 'phx_ref' and 'phx_ref_prev' * * @example * // returns { * abc123: [ * { presence_ref: '2', user_id: 1 }, * { presence_ref: '3', user_id: 2 } * ] * } * RealtimePresence.transformState({ * abc123: { * metas: [ * { phx_ref: '2', phx_ref_prev: '1' user_id: 1 }, * { phx_ref: '3', user_id: 2 } * ] * } * }) * * @internal */ static transformState(state) { state = this.cloneDeep(state); return Object.getOwnPropertyNames(state).reduce((newState, key) => { const presences = state[key]; if ("metas" in presences) { newState[key] = presences.metas.map((presence) => { presence["presence_ref"] = presence["phx_ref"]; delete presence["phx_ref"]; delete presence["phx_ref_prev"]; return presence; }); } else { newState[key] = presences; } return newState; }, {}); } /** @internal */ static cloneDeep(obj) { return JSON.parse(JSON.stringify(obj)); } /** @internal */ onJoin(callback) { this.caller.onJoin = callback; } /** @internal */ onLeave(callback) { this.caller.onLeave = callback; } /** @internal */ onSync(callback) { this.caller.onSync = callback; } /** @internal */ inPendingSyncState() { return !this.joinRef || this.joinRef !== this.channel._joinRef(); } }; } }); // ../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/RealtimeChannel.js var REALTIME_POSTGRES_CHANGES_LISTEN_EVENT, REALTIME_LISTEN_TYPES, REALTIME_SUBSCRIBE_STATES, REALTIME_CHANNEL_STATES, RealtimeChannel; var init_RealtimeChannel = __esm({ "../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/RealtimeChannel.js"() { init_constants(); init_push(); init_timer(); init_RealtimePresence(); init_transformers(); init_transformers(); (function(REALTIME_POSTGRES_CHANGES_LISTEN_EVENT3) { REALTIME_POSTGRES_CHANGES_LISTEN_EVENT3["ALL"] = "*"; REALTIME_POSTGRES_CHANGES_LISTEN_EVENT3["INSERT"] = "INSERT"; REALTIME_POSTGRES_CHANGES_LISTEN_EVENT3["UPDATE"] = "UPDATE"; REALTIME_POSTGRES_CHANGES_LISTEN_EVENT3["DELETE"] = "DELETE"; })(REALTIME_POSTGRES_CHANGES_LISTEN_EVENT || (REALTIME_POSTGRES_CHANGES_LISTEN_EVENT = {})); (function(REALTIME_LISTEN_TYPES3) { REALTIME_LISTEN_TYPES3["BROADCAST"] = "broadcast"; REALTIME_LISTEN_TYPES3["PRESENCE"] = "presence"; REALTIME_LISTEN_TYPES3["POSTGRES_CHANGES"] = "postgres_changes"; REALTIME_LISTEN_TYPES3["SYSTEM"] = "system"; })(REALTIME_LISTEN_TYPES || (REALTIME_LISTEN_TYPES = {})); (function(REALTIME_SUBSCRIBE_STATES3) { REALTIME_SUBSCRIBE_STATES3["SUBSCRIBED"] = "SUBSCRIBED"; REALTIME_SUBSCRIBE_STATES3["TIMED_OUT"] = "TIMED_OUT"; REALTIME_SUBSCRIBE_STATES3["CLOSED"] = "CLOSED"; REALTIME_SUBSCRIBE_STATES3["CHANNEL_ERROR"] = "CHANNEL_ERROR"; })(REALTIME_SUBSCRIBE_STATES || (REALTIME_SUBSCRIBE_STATES = {})); REALTIME_CHANNEL_STATES = CHANNEL_STATES; RealtimeChannel = class _RealtimeChannel { /** * Creates a channel that can broadcast messages, sync presence, and listen to Postgres changes. * * The topic determines which realtime stream you are subscribing to. Config options let you * enable acknowledgement for broadcasts, presence tracking, or private channels. * * @example * ```ts * import RealtimeClient from '@supabase/realtime-js' * * const client = new RealtimeClient('https://xyzcompany.supabase.co/realtime/v1', { * params: { apikey: 'public-anon-key' }, * }) * const channel = new RealtimeChannel('realtime:public:messages', { config: {} }, client) * ``` */ constructor(topic, params = { config: {} }, socket) { var _a2, _b; this.topic = topic; this.params = params; this.socket = socket; this.bindings = {}; this.state = CHANNEL_STATES.closed; this.joinedOnce = false; this.pushBuffer = []; this.subTopic = topic.replace(/^realtime:/i, ""); this.params.config = Object.assign({ broadcast: { ack: false, self: false }, presence: { key: "", enabled: false }, private: false }, params.config); this.timeout = this.socket.timeout; this.joinPush = new Push(this, CHANNEL_EVENTS.join, this.params, this.timeout); this.rejoinTimer = new Timer(() => this._rejoinUntilConnected(), this.socket.reconnectAfterMs); this.joinPush.receive("ok", () => { this.state = CHANNEL_STATES.joined; this.rejoinTimer.reset(); this.pushBuffer.forEach((pushEvent) => pushEvent.send()); this.pushBuffer = []; }); this._onClose(() => { this.rejoinTimer.reset(); this.socket.log("channel", `close ${this.topic} ${this._joinRef()}`); this.state = CHANNEL_STATES.closed; this.socket._remove(this); }); this._onError((reason) => { if (this._isLeaving() || this._isClosed()) { return; } this.socket.log("channel", `error ${this.topic}`, reason); this.state = CHANNEL_STATES.errored; this.rejoinTimer.scheduleTimeout(); }); this.joinPush.receive("timeout", () => { if (!this._isJoining()) { return; } this.socket.log("channel", `timeout ${this.topic}`, this.joinPush.timeout); this.state = CHANNEL_STATES.errored; this.rejoinTimer.scheduleTimeout(); }); this.joinPush.receive("error", (reason) => { if (this._isLeaving() || this._isClosed()) { return; } this.socket.log("channel", `error ${this.topic}`, reason); this.state = CHANNEL_STATES.errored; this.rejoinTimer.scheduleTimeout(); }); this._on(CHANNEL_EVENTS.reply, {}, (payload, ref) => { this._trigger(this._replyEventName(ref), payload); }); this.presence = new RealtimePresence(this); this.broadcastEndpointURL = httpEndpointURL(this.socket.endPoint); this.private = this.params.config.private || false; if (!this.private && ((_b = (_a2 = this.params.config) === null || _a2 === void 0 ? void 0 : _a2.broadcast) === null || _b === void 0 ? void 0 : _b.replay)) { throw `tried to use replay on public channel '${this.topic}'. It must be a private channel.`; } } /** Subscribe registers your client with the server */ subscribe(callback, timeout = this.timeout) { var _a2, _b, _c; if (!this.socket.isConnected()) { this.socket.connect(); } if (this.state == CHANNEL_STATES.closed) { const { config: { broadcast, presence, private: isPrivate } } = this.params; const postgres_changes = (_b = (_a2 = this.bindings.postgres_changes) === null || _a2 === void 0 ? void 0 : _a2.map((r) => r.filter)) !== null && _b !== void 0 ? _b : []; const presence_enabled = !!this.bindings[REALTIME_LISTEN_TYPES.PRESENCE] && this.bindings[REALTIME_LISTEN_TYPES.PRESENCE].length > 0 || ((_c = this.params.config.presence) === null || _c === void 0 ? void 0 : _c.enabled) === true; const accessTokenPayload = {}; const config = { broadcast, presence: Object.assign(Object.assign({}, presence), { enabled: presence_enabled }), postgres_changes, private: isPrivate }; if (this.socket.accessTokenValue) { accessTokenPayload.access_token = this.socket.accessTokenValue; } this._onError((e) => callback === null || callback === void 0 ? void 0 : callback(REALTIME_SUBSCRIBE_STATES.CHANNEL_ERROR, e)); this._onClose(() => callback === null || callback === void 0 ? void 0 : callback(REALTIME_SUBSCRIBE_STATES.CLOSED)); this.updateJoinPayload(Object.assign({ config }, accessTokenPayload)); this.joinedOnce = true; this._rejoin(timeout); this.joinPush.receive("ok", async ({ postgres_changes: postgres_changes2 }) => { var _a3; this.socket.setAuth(); if (postgres_changes2 === void 0) { callback === null || callback === void 0 ? void 0 : callback(REALTIME_SUBSCRIBE_STATES.SUBSCRIBED); return; } else { const clientPostgresBindings = this.bindings.postgres_changes; const bindingsLen = (_a3 = clientPostgresBindings === null || clientPostgresBindings === void 0 ? void 0 : clientPostgresBindings.length) !== null && _a3 !== void 0 ? _a3 : 0; const newPostgresBindings = []; for (let i = 0; i < bindingsLen; i++) { const clientPostgresBinding = clientPostgresBindings[i]; const { filter: { event, schema, table, filter } } = clientPostgresBinding; const serverPostgresFilter = postgres_changes2 && postgres_changes2[i]; if (serverPostgresFilter && serverPostgresFilter.event === event && serverPostgresFilter.schema === schema && serverPostgresFilter.table === table && serverPostgresFilter.filter === filter) { newPostgresBindings.push(Object.assign(Object.assign({}, clientPostgresBinding), { id: serverPostgresFilter.id })); } else { this.unsubscribe(); this.state = CHANNEL_STATES.errored; callback === null || callback === void 0 ? void 0 : callback(REALTIME_SUBSCRIBE_STATES.CHANNEL_ERROR, new Error("mismatch between server and client bindings for postgres changes")); return; } } this.bindings.postgres_changes = newPostgresBindings; callback && callback(REALTIME_SUBSCRIBE_STATES.SUBSCRIBED); return; } }).receive("error", (error) => { this.state = CHANNEL_STATES.errored; callback === null || callback === void 0 ? void 0 : callback(REALTIME_SUBSCRIBE_STATES.CHANNEL_ERROR, new Error(JSON.stringify(Object.values(error).join(", ") || "error"))); return; }).receive("timeout", () => { callback === null || callback === void 0 ? void 0 : callback(REALTIME_SUBSCRIBE_STATES.TIMED_OUT); return; }); } return this; } /** * Returns the current presence state for this channel. * * The shape is a map keyed by presence key (for example a user id) where each entry contains the * tracked metadata for that user. */ presenceState() { return this.presence.state; } /** * Sends the supplied payload to the presence tracker so other subscribers can see that this * client is online. Use `untrack` to stop broadcasting presence for the same key. */ async track(payload, opts = {}) { return await this.send({ type: "presence", event: "track", payload }, opts.timeout || this.timeout); } /** * Removes the current presence state for this client. */ async untrack(opts = {}) { return await this.send({ type: "presence", event: "untrack" }, opts); } on(type, filter, callback) { if (this.state === CHANNEL_STATES.joined && type === REALTIME_LISTEN_TYPES.PRESENCE) { this.socket.log("channel", `resubscribe to ${this.topic} due to change in presence callbacks on joined channel`); this.unsubscribe().then(() => this.subscribe()); } return this._on(type, filter, callback); } /** * Sends a broadcast message explicitly via REST API. * * This method always uses the REST API endpoint regardless of WebSocket connection state. * Useful when you want to guarantee REST delivery or when gradually migrating from implicit REST fallback. * * @param event The name of the broadcast event * @param payload Payload to be sent (required) * @param opts Options including timeout * @returns Promise resolving to object with success status, and error details if failed */ async httpSend(event, payload, opts = {}) { var _a2; const authorization = this.socket.accessTokenValue ? `Bearer ${this.socket.accessTokenValue}` : ""; if (payload === void 0 || payload === null) { return Promise.reject("Payload is required for httpSend()"); } const options = { method: "POST", headers: { Authorization: authorization, apikey: this.socket.apiKey ? this.socket.apiKey : "", "Content-Type": "application/json" }, body: JSON.stringify({ messages: [ { topic: this.subTopic, event, payload, private: this.private } ] }) }; const response = await this._fetchWithTimeout(this.broadcastEndpointURL, options, (_a2 = opts.timeout) !== null && _a2 !== void 0 ? _a2 : this.timeout); if (response.status === 202) { return { success: true }; } let errorMessage = response.statusText; try { const errorBody = await response.json(); errorMessage = errorBody.error || errorBody.message || errorMessage; } catch (_b) { } return Promise.reject(new Error(errorMessage)); } /** * Sends a message into the channel. * * @param args Arguments to send to channel * @param args.type The type of event to send * @param args.event The name of the event being sent * @param args.payload Payload to be sent * @param opts Options to be used during the send process */ async send(args, opts = {}) { var _a2, _b; if (!this._canPush() && args.type === "broadcast") { console.warn("Realtime send() is automatically falling back to REST API. This behavior will be deprecated in the future. Please use httpSend() explicitly for REST delivery."); const { event, payload: endpoint_payload } = args; const authorization = this.socket.accessTokenValue ? `Bearer ${this.socket.accessTokenValue}` : ""; const options = { method: "POST", headers: { Authorization: authorization, apikey: this.socket.apiKey ? this.socket.apiKey : "", "Content-Type": "application/json" }, body: JSON.stringify({ messages: [ { topic: this.subTopic, event, payload: endpoint_payload, private: this.private } ] }) }; try { const response = await this._fetchWithTimeout(this.broadcastEndpointURL, options, (_a2 = opts.timeout) !== null && _a2 !== void 0 ? _a2 : this.timeout); await ((_b = response.body) === null || _b === void 0 ? void 0 : _b.cancel()); return response.ok ? "ok" : "error"; } catch (error) { if (error.name === "AbortError") { return "timed out"; } else { return "error"; } } } else { return new Promise((resolve) => { var _a3, _b2, _c; const push = this._push(args.type, args, opts.timeout || this.timeout); if (args.type === "broadcast" && !((_c = (_b2 = (_a3 = this.params) === null || _a3 === void 0 ? void 0 : _a3.config) === null || _b2 === void 0 ? void 0 : _b2.broadcast) === null || _c === void 0 ? void 0 : _c.ack)) { resolve("ok"); } push.receive("ok", () => resolve("ok")); push.receive("error", () => resolve("error")); push.receive("timeout", () => resolve("timed out")); }); } } /** * Updates the payload that will be sent the next time the channel joins (reconnects). * Useful for rotating access tokens or updating config without re-creating the channel. */ updateJoinPayload(payload) { this.joinPush.updatePayload(payload); } /** * Leaves the channel. * * Unsubscribes from server events, and instructs channel to terminate on server. * Triggers onClose() hooks. * * To receive leave acknowledgements, use the a `receive` hook to bind to the server ack, ie: * channel.unsubscribe().receive("ok", () => alert("left!") ) */ unsubscribe(timeout = this.timeout) { this.state = CHANNEL_STATES.leaving; const onClose = () => { this.socket.log("channel", `leave ${this.topic}`); this._trigger(CHANNEL_EVENTS.close, "leave", this._joinRef()); }; this.joinPush.destroy(); let leavePush = null; return new Promise((resolve) => { leavePush = new Push(this, CHANNEL_EVENTS.leave, {}, timeout); leavePush.receive("ok", () => { onClose(); resolve("ok"); }).receive("timeout", () => { onClose(); resolve("timed out"); }).receive("error", () => { resolve("error"); }); leavePush.send(); if (!this._canPush()) { leavePush.trigger("ok", {}); } }).finally(() => { leavePush === null || leavePush === void 0 ? void 0 : leavePush.destroy(); }); } /** * Teardown the channel. * * Destroys and stops related timers. */ teardown() { this.pushBuffer.forEach((push) => push.destroy()); this.pushBuffer = []; this.rejoinTimer.reset(); this.joinPush.destroy(); this.state = CHANNEL_STATES.closed; this.bindings = {}; } /** @internal */ async _fetchWithTimeout(url, options, timeout) { const controller = new AbortController(); const id = setTimeout(() => controller.abort(), timeout); const response = await this.socket.fetch(url, Object.assign(Object.assign({}, options), { signal: controller.signal })); clearTimeout(id); return response; } /** @internal */ _push(event, payload, timeout = this.timeout) { if (!this.joinedOnce) { throw `tried to push '${event}' to '${this.topic}' before joining. Use channel.subscribe() before pushing events`; } let pushEvent = new Push(this, event, payload, timeout); if (this._canPush()) { pushEvent.send(); } else { this._addToPushBuffer(pushEvent); } return pushEvent; } /** @internal */ _addToPushBuffer(pushEvent) { pushEvent.startTimeout(); this.pushBuffer.push(pushEvent); if (this.pushBuffer.length > MAX_PUSH_BUFFER_SIZE) { const removedPush = this.pushBuffer.shift(); if (removedPush) { removedPush.destroy(); this.socket.log("channel", `discarded push due to buffer overflow: ${removedPush.event}`, removedPush.payload); } } } /** * Overridable message hook * * Receives all events for specialized message handling before dispatching to the channel callbacks. * Must return the payload, modified or unmodified. * * @internal */ _onMessage(_event, payload, _ref) { return payload; } /** @internal */ _isMember(topic) { return this.topic === topic; } /** @internal */ _joinRef() { return this.joinPush.ref; } /** @internal */ _trigger(type, payload, ref) { var _a2, _b; const typeLower = type.toLocaleLowerCase(); const { close, error, leave, join } = CHANNEL_EVENTS; const events = [close, error, leave, join]; if (ref && events.indexOf(typeLower) >= 0 && ref !== this._joinRef()) { return; } let handledPayload = this._onMessage(typeLower, payload, ref); if (payload && !handledPayload) { throw "channel onMessage callbacks must return the payload, modified or unmodified"; } if (["insert", "update", "delete"].includes(typeLower)) { (_a2 = this.bindings.postgres_changes) === null || _a2 === void 0 ? void 0 : _a2.filter((bind) => { var _a3, _b2, _c; return ((_a3 = bind.filter) === null || _a3 === void 0 ? void 0 : _a3.event) === "*" || ((_c = (_b2 = bind.filter) === null || _b2 === void 0 ? void 0 : _b2.event) === null || _c === void 0 ? void 0 : _c.toLocaleLowerCase()) === typeLower; }).map((bind) => bind.callback(handledPayload, ref)); } else { (_b = this.bindings[typeLower]) === null || _b === void 0 ? void 0 : _b.filter((bind) => { var _a3, _b2, _c, _d, _e, _f; if (["broadcast", "presence", "postgres_changes"].includes(typeLower)) { if ("id" in bind) { const bindId = bind.id; const bindEvent = (_a3 = bind.filter) === null || _a3 === void 0 ? void 0 : _a3.event; return bindId && ((_b2 = payload.ids) === null || _b2 === void 0 ? void 0 : _b2.includes(bindId)) && (bindEvent === "*" || (bindEvent === null || bindEvent === void 0 ? void 0 : bindEvent.toLocaleLowerCase()) === ((_c = payload.data) === null || _c === void 0 ? void 0 : _c.type.toLocaleLowerCase())); } else { const bindEvent = (_e = (_d = bind === null || bind === void 0 ? void 0 : bind.filter) === null || _d === void 0 ? void 0 : _d.event) === null || _e === void 0 ? void 0 : _e.toLocaleLowerCase(); return bindEvent === "*" || bindEvent === ((_f = payload === null || payload === void 0 ? void 0 : payload.event) === null || _f === void 0 ? void 0 : _f.toLocaleLowerCase()); } } else { return bind.type.toLocaleLowerCase() === typeLower; } }).map((bind) => { if (typeof handledPayload === "object" && "ids" in handledPayload) { const postgresChanges = handledPayload.data; const { schema, table, commit_timestamp, type: type2, errors } = postgresChanges; const enrichedPayload = { schema, table, commit_timestamp, eventType: type2, new: {}, old: {}, errors }; handledPayload = Object.assign(Object.assign({}, enrichedPayload), this._getPayloadRecords(postgresChanges)); } bind.callback(handledPayload, ref); }); } } /** @internal */ _isClosed() { return this.state === CHANNEL_STATES.closed; } /** @internal */ _isJoined() { return this.state === CHANNEL_STATES.joined; } /** @internal */ _isJoining() { return this.state === CHANNEL_STATES.joining; } /** @internal */ _isLeaving() { return this.state === CHANNEL_STATES.leaving; } /** @internal */ _replyEventName(ref) { return `chan_reply_${ref}`; } /** @internal */ _on(type, filter, callback) { const typeLower = type.toLocaleLowerCase(); const binding = { type: typeLower, filter, callback }; if (this.bindings[typeLower]) { this.bindings[typeLower].push(binding); } else { this.bindings[typeLower] = [binding]; } return this; } /** @internal */ _off(type, filter) { const typeLower = type.toLocaleLowerCase(); if (this.bindings[typeLower]) { this.bindings[typeLower] = this.bindings[typeLower].filter((bind) => { var _a2; return !(((_a2 = bind.type) === null || _a2 === void 0 ? void 0 : _a2.toLocaleLowerCase()) === typeLower && _RealtimeChannel.isEqual(bind.filter, filter)); }); } return this; } /** @internal */ static isEqual(obj1, obj2) { if (Object.keys(obj1).length !== Object.keys(obj2).length) { return false; } for (const k in obj1) { if (obj1[k] !== obj2[k]) { return false; } } return true; } /** @internal */ _rejoinUntilConnected() { this.rejoinTimer.scheduleTimeout(); if (this.socket.isConnected()) { this._rejoin(); } } /** * Registers a callback that will be executed when the channel closes. * * @internal */ _onClose(callback) { this._on(CHANNEL_EVENTS.close, {}, callback); } /** * Registers a callback that will be executed when the channel encounteres an error. * * @internal */ _onError(callback) { this._on(CHANNEL_EVENTS.error, {}, (reason) => callback(reason)); } /** * Returns `true` if the socket is connected and the channel has been joined. * * @internal */ _canPush() { return this.socket.isConnected() && this._isJoined(); } /** @internal */ _rejoin(timeout = this.timeout) { if (this._isLeaving()) { return; } this.socket._leaveOpenTopic(this.topic); this.state = CHANNEL_STATES.joining; this.joinPush.resend(timeout); } /** @internal */ _getPayloadRecords(payload) { const records = { new: {}, old: {} }; if (payload.type === "INSERT" || payload.type === "UPDATE") { records.new = convertChangeData(payload.columns, payload.record); } if (payload.type === "UPDATE" || payload.type === "DELETE") { records.old = convertChangeData(payload.columns, payload.old_record); } return records; } }; } }); // ../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/RealtimeClient.js var noop2, CONNECTION_TIMEOUTS, RECONNECT_INTERVALS, DEFAULT_RECONNECT_FALLBACK, WORKER_SCRIPT, RealtimeClient; var init_RealtimeClient = __esm({ "../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/RealtimeClient.js"() { init_websocket_factory(); init_constants(); init_serializer(); init_timer(); init_transformers(); init_RealtimeChannel(); noop2 = () => { }; CONNECTION_TIMEOUTS = { HEARTBEAT_INTERVAL: 25e3, RECONNECT_DELAY: 10, HEARTBEAT_TIMEOUT_FALLBACK: 100 }; RECONNECT_INTERVALS = [1e3, 2e3, 5e3, 1e4]; DEFAULT_RECONNECT_FALLBACK = 1e4; WORKER_SCRIPT = ` addEventListener("message", (e) => { if (e.data.event === "start") { setInterval(() => postMessage({ event: "keepAlive" }), e.data.interval); } });`; RealtimeClient = class { /** * Initializes the Socket. * * @param endPoint The string WebSocket endpoint, ie, "ws://example.com/socket", "wss://example.com", "/socket" (inherited host & protocol) * @param httpEndpoint The string HTTP endpoint, ie, "https://example.com", "/" (inherited host & protocol) * @param options.transport The Websocket Transport, for example WebSocket. This can be a custom implementation * @param options.timeout The default timeout in milliseconds to trigger push timeouts. * @param options.params The optional params to pass when connecting. * @param options.headers Deprecated: headers cannot be set on websocket connections and this option will be removed in the future. * @param options.heartbeatIntervalMs The millisec interval to send a heartbeat message. * @param options.heartbeatCallback The optional function to handle heartbeat status. * @param options.logger The optional function for specialized logging, ie: logger: (kind, msg, data) => { console.log(`${kind}: ${msg}`, data) } * @param options.logLevel Sets the log level for Realtime * @param options.encode The function to encode outgoing messages. Defaults to JSON: (payload, callback) => callback(JSON.stringify(payload)) * @param options.decode The function to decode incoming messages. Defaults to Serializer's decode. * @param options.reconnectAfterMs he optional function that returns the millsec reconnect interval. Defaults to stepped backoff off. * @param options.worker Use Web Worker to set a side flow. Defaults to false. * @param options.workerUrl The URL of the worker script. Defaults to https://realtime.supabase.com/worker.js that includes a heartbeat event call to keep the connection alive. * @example * ```ts * import RealtimeClient from '@supabase/realtime-js' * * const client = new RealtimeClient('https://xyzcompany.supabase.co/realtime/v1', { * params: { apikey: 'public-anon-key' }, * }) * client.connect() * ``` */ constructor(endPoint, options) { var _a2; this.accessTokenValue = null; this.apiKey = null; this.channels = new Array(); this.endPoint = ""; this.httpEndpoint = ""; this.headers = {}; this.params = {}; this.timeout = DEFAULT_TIMEOUT; this.transport = null; this.heartbeatIntervalMs = CONNECTION_TIMEOUTS.HEARTBEAT_INTERVAL; this.heartbeatTimer = void 0; this.pendingHeartbeatRef = null; this.heartbeatCallback = noop2; this.ref = 0; this.reconnectTimer = null; this.vsn = DEFAULT_VSN; this.logger = noop2; this.conn = null; this.sendBuffer = []; this.serializer = new Serializer(); this.stateChangeCallbacks = { open: [], close: [], error: [], message: [] }; this.accessToken = null; this._connectionState = "disconnected"; this._wasManualDisconnect = false; this._authPromise = null; this._resolveFetch = (customFetch) => { if (customFetch) { return (...args) => customFetch(...args); } return (...args) => fetch(...args); }; if (!((_a2 = options === null || options === void 0 ? void 0 : options.params) === null || _a2 === void 0 ? void 0 : _a2.apikey)) { throw new Error("API key is required to connect to Realtime"); } this.apiKey = options.params.apikey; this.endPoint = `${endPoint}/${TRANSPORTS.websocket}`; this.httpEndpoint = httpEndpointURL(endPoint); this._initializeOptions(options); this._setupReconnectionTimer(); this.fetch = this._resolveFetch(options === null || options === void 0 ? void 0 : options.fetch); } /** * Connects the socket, unless already connected. */ connect() { if (this.isConnecting() || this.isDisconnecting() || this.conn !== null && this.isConnected()) { return; } this._setConnectionState("connecting"); if (this.accessToken && !this._authPromise) { this._setAuthSafely("connect"); } if (this.transport) { this.conn = new this.transport(this.endpointURL()); } else { try { this.conn = websocket_factory_default.createWebSocket(this.endpointURL()); } catch (error) { this._setConnectionState("disconnected"); const errorMessage = error.message; if (errorMessage.includes("Node.js")) { throw new Error(`${errorMessage} To use Realtime in Node.js, you need to provide a WebSocket implementation: Option 1: Use Node.js 22+ which has native WebSocket support Option 2: Install and provide the "ws" package: npm install ws import ws from "ws" const client = new RealtimeClient(url, { ...options, transport: ws })`); } throw new Error(`WebSocket not available: ${errorMessage}`); } } this._setupConnectionHandlers(); } /** * Returns the URL of the websocket. * @returns string The URL of the websocket. */ endpointURL() { return this._appendParams(this.endPoint, Object.assign({}, this.params, { vsn: this.vsn })); } /** * Disconnects the socket. * * @param code A numeric status code to send on disconnect. * @param reason A custom reason for the disconnect. */ disconnect(code, reason) { if (this.isDisconnecting()) { return; } this._setConnectionState("disconnecting", true); if (this.conn) { const fallbackTimer = setTimeout(() => { this._setConnectionState("disconnected"); }, 100); this.conn.onclose = () => { clearTimeout(fallbackTimer); this._setConnectionState("disconnected"); }; if (typeof this.conn.close === "function") { if (code) { this.conn.close(code, reason !== null && reason !== void 0 ? reason : ""); } else { this.conn.close(); } } this._teardownConnection(); } else { this._setConnectionState("disconnected"); } } /** * Returns all created channels */ getChannels() { return this.channels; } /** * Unsubscribes and removes a single channel * @param channel A RealtimeChannel instance */ async removeChannel(channel) { const status = await channel.unsubscribe(); if (this.channels.length === 0) { this.disconnect(); } return status; } /** * Unsubscribes and removes all channels */ async removeAllChannels() { const values_1 = await Promise.all(this.channels.map((channel) => channel.unsubscribe())); this.channels = []; this.disconnect(); return values_1; } /** * Logs the message. * * For customized logging, `this.logger` can be overridden. */ log(kind, msg, data) { this.logger(kind, msg, data); } /** * Returns the current state of the socket. */ connectionState() { switch (this.conn && this.conn.readyState) { case SOCKET_STATES.connecting: return CONNECTION_STATE.Connecting; case SOCKET_STATES.open: return CONNECTION_STATE.Open; case SOCKET_STATES.closing: return CONNECTION_STATE.Closing; default: return CONNECTION_STATE.Closed; } } /** * Returns `true` is the connection is open. */ isConnected() { return this.connectionState() === CONNECTION_STATE.Open; } /** * Returns `true` if the connection is currently connecting. */ isConnecting() { return this._connectionState === "connecting"; } /** * Returns `true` if the connection is currently disconnecting. */ isDisconnecting() { return this._connectionState === "disconnecting"; } /** * Creates (or reuses) a {@link RealtimeChannel} for the provided topic. * * Topics are automatically prefixed with `realtime:` to match the Realtime service. * If a channel with the same topic already exists it will be returned instead of creating * a duplicate connection. */ channel(topic, params = { config: {} }) { const realtimeTopic = `realtime:${topic}`; const exists = this.getChannels().find((c) => c.topic === realtimeTopic); if (!exists) { const chan = new RealtimeChannel(`realtime:${topic}`, params, this); this.channels.push(chan); return chan; } else { return exists; } } /** * Push out a message if the socket is connected. * * If the socket is not connected, the message gets enqueued within a local buffer, and sent out when a connection is next established. */ push(data) { const { topic, event, payload, ref } = data; const callback = () => { this.encode(data, (result) => { var _a2; (_a2 = this.conn) === null || _a2 === void 0 ? void 0 : _a2.send(result); }); }; this.log("push", `${topic} ${event} (${ref})`, payload); if (this.isConnected()) { callback(); } else { this.sendBuffer.push(callback); } } /** * Sets the JWT access token used for channel subscription authorization and Realtime RLS. * * If param is null it will use the `accessToken` callback function or the token set on the client. * * On callback used, it will set the value of the token internal to the client. * * @param token A JWT string to override the token set on the client. */ async setAuth(token = null) { this._authPromise = this._performAuth(token); try { await this._authPromise; } finally { this._authPromise = null; } } /** * Sends a heartbeat message if the socket is connected. */ async sendHeartbeat() { var _a2; if (!this.isConnected()) { try { this.heartbeatCallback("disconnected"); } catch (e) { this.log("error", "error in heartbeat callback", e); } return; } if (this.pendingHeartbeatRef) { this.pendingHeartbeatRef = null; this.log("transport", "heartbeat timeout. Attempting to re-establish connection"); try { this.heartbeatCallback("timeout"); } catch (e) { this.log("error", "error in heartbeat callback", e); } this._wasManualDisconnect = false; (_a2 = this.conn) === null || _a2 === void 0 ? void 0 : _a2.close(WS_CLOSE_NORMAL, "heartbeat timeout"); setTimeout(() => { var _a3; if (!this.isConnected()) { (_a3 = this.reconnectTimer) === null || _a3 === void 0 ? void 0 : _a3.scheduleTimeout(); } }, CONNECTION_TIMEOUTS.HEARTBEAT_TIMEOUT_FALLBACK); return; } this.pendingHeartbeatRef = this._makeRef(); this.push({ topic: "phoenix", event: "heartbeat", payload: {}, ref: this.pendingHeartbeatRef }); try { this.heartbeatCallback("sent"); } catch (e) { this.log("error", "error in heartbeat callback", e); } this._setAuthSafely("heartbeat"); } /** * Sets a callback that receives lifecycle events for internal heartbeat messages. * Useful for instrumenting connection health (e.g. sent/ok/timeout/disconnected). */ onHeartbeat(callback) { this.heartbeatCallback = callback; } /** * Flushes send buffer */ flushSendBuffer() { if (this.isConnected() && this.sendBuffer.length > 0) { this.sendBuffer.forEach((callback) => callback()); this.sendBuffer = []; } } /** * Return the next message ref, accounting for overflows * * @internal */ _makeRef() { let newRef = this.ref + 1; if (newRef === this.ref) { this.ref = 0; } else { this.ref = newRef; } return this.ref.toString(); } /** * Unsubscribe from channels with the specified topic. * * @internal */ _leaveOpenTopic(topic) { let dupChannel = this.channels.find((c) => c.topic === topic && (c._isJoined() || c._isJoining())); if (dupChannel) { this.log("transport", `leaving duplicate topic "${topic}"`); dupChannel.unsubscribe(); } } /** * Removes a subscription from the socket. * * @param channel An open subscription. * * @internal */ _remove(channel) { this.channels = this.channels.filter((c) => c.topic !== channel.topic); } /** @internal */ _onConnMessage(rawMessage) { this.decode(rawMessage.data, (msg) => { if (msg.topic === "phoenix" && msg.event === "phx_reply") { try { this.heartbeatCallback(msg.payload.status === "ok" ? "ok" : "error"); } catch (e) { this.log("error", "error in heartbeat callback", e); } } if (msg.ref && msg.ref === this.pendingHeartbeatRef) { this.pendingHeartbeatRef = null; } const { topic, event, payload, ref } = msg; const refString = ref ? `(${ref})` : ""; const status = payload.status || ""; this.log("receive", `${status} ${topic} ${event} ${refString}`.trim(), payload); this.channels.filter((channel) => channel._isMember(topic)).forEach((channel) => channel._trigger(event, payload, ref)); this._triggerStateCallbacks("message", msg); }); } /** * Clear specific timer * @internal */ _clearTimer(timer) { var _a2; if (timer === "heartbeat" && this.heartbeatTimer) { clearInterval(this.heartbeatTimer); this.heartbeatTimer = void 0; } else if (timer === "reconnect") { (_a2 = this.reconnectTimer) === null || _a2 === void 0 ? void 0 : _a2.reset(); } } /** * Clear all timers * @internal */ _clearAllTimers() { this._clearTimer("heartbeat"); this._clearTimer("reconnect"); } /** * Setup connection handlers for WebSocket events * @internal */ _setupConnectionHandlers() { if (!this.conn) return; if ("binaryType" in this.conn) { ; this.conn.binaryType = "arraybuffer"; } this.conn.onopen = () => this._onConnOpen(); this.conn.onerror = (error) => this._onConnError(error); this.conn.onmessage = (event) => this._onConnMessage(event); this.conn.onclose = (event) => this._onConnClose(event); } /** * Teardown connection and cleanup resources * @internal */ _teardownConnection() { if (this.conn) { if (this.conn.readyState === SOCKET_STATES.open || this.conn.readyState === SOCKET_STATES.connecting) { try { this.conn.close(); } catch (e) { this.log("error", "Error closing connection", e); } } this.conn.onopen = null; this.conn.onerror = null; this.conn.onmessage = null; this.conn.onclose = null; this.conn = null; } this._clearAllTimers(); this.channels.forEach((channel) => channel.teardown()); } /** @internal */ _onConnOpen() { this._setConnectionState("connected"); this.log("transport", `connected to ${this.endpointURL()}`); const authPromise = this._authPromise || (this.accessToken && !this.accessTokenValue ? this.setAuth() : Promise.resolve()); authPromise.then(() => { this.flushSendBuffer(); }).catch((e) => { this.log("error", "error waiting for auth on connect", e); this.flushSendBuffer(); }); this._clearTimer("reconnect"); if (!this.worker) { this._startHeartbeat(); } else { if (!this.workerRef) { this._startWorkerHeartbeat(); } } this._triggerStateCallbacks("open"); } /** @internal */ _startHeartbeat() { this.heartbeatTimer && clearInterval(this.heartbeatTimer); this.heartbeatTimer = setInterval(() => this.sendHeartbeat(), this.heartbeatIntervalMs); } /** @internal */ _startWorkerHeartbeat() { if (this.workerUrl) { this.log("worker", `starting worker for from ${this.workerUrl}`); } else { this.log("worker", `starting default worker`); } const objectUrl = this._workerObjectUrl(this.workerUrl); this.workerRef = new Worker(objectUrl); this.workerRef.onerror = (error) => { this.log("worker", "worker error", error.message); this.workerRef.terminate(); }; this.workerRef.onmessage = (event) => { if (event.data.event === "keepAlive") { this.sendHeartbeat(); } }; this.workerRef.postMessage({ event: "start", interval: this.heartbeatIntervalMs }); } /** @internal */ _onConnClose(event) { var _a2; this._setConnectionState("disconnected"); this.log("transport", "close", event); this._triggerChanError(); this._clearTimer("heartbeat"); if (!this._wasManualDisconnect) { (_a2 = this.reconnectTimer) === null || _a2 === void 0 ? void 0 : _a2.scheduleTimeout(); } this._triggerStateCallbacks("close", event); } /** @internal */ _onConnError(error) { this._setConnectionState("disconnected"); this.log("transport", `${error}`); this._triggerChanError(); this._triggerStateCallbacks("error", error); } /** @internal */ _triggerChanError() { this.channels.forEach((channel) => channel._trigger(CHANNEL_EVENTS.error)); } /** @internal */ _appendParams(url, params) { if (Object.keys(params).length === 0) { return url; } const prefix = url.match(/\?/) ? "&" : "?"; const query = new URLSearchParams(params); return `${url}${prefix}${query}`; } _workerObjectUrl(url) { let result_url; if (url) { result_url = url; } else { const blob = new Blob([WORKER_SCRIPT], { type: "application/javascript" }); result_url = URL.createObjectURL(blob); } return result_url; } /** * Set connection state with proper state management * @internal */ _setConnectionState(state, manual = false) { this._connectionState = state; if (state === "connecting") { this._wasManualDisconnect = false; } else if (state === "disconnecting") { this._wasManualDisconnect = manual; } } /** * Perform the actual auth operation * @internal */ async _performAuth(token = null) { let tokenToSend; if (token) { tokenToSend = token; } else if (this.accessToken) { tokenToSend = await this.accessToken(); } else { tokenToSend = this.accessTokenValue; } if (this.accessTokenValue != tokenToSend) { this.accessTokenValue = tokenToSend; this.channels.forEach((channel) => { const payload = { access_token: tokenToSend, version: DEFAULT_VERSION }; tokenToSend && channel.updateJoinPayload(payload); if (channel.joinedOnce && channel._isJoined()) { channel._push(CHANNEL_EVENTS.access_token, { access_token: tokenToSend }); } }); } } /** * Wait for any in-flight auth operations to complete * @internal */ async _waitForAuthIfNeeded() { if (this._authPromise) { await this._authPromise; } } /** * Safely call setAuth with standardized error handling * @internal */ _setAuthSafely(context = "general") { this.setAuth().catch((e) => { this.log("error", `error setting auth in ${context}`, e); }); } /** * Trigger state change callbacks with proper error handling * @internal */ _triggerStateCallbacks(event, data) { try { this.stateChangeCallbacks[event].forEach((callback) => { try { callback(data); } catch (e) { this.log("error", `error in ${event} callback`, e); } }); } catch (e) { this.log("error", `error triggering ${event} callbacks`, e); } } /** * Setup reconnection timer with proper configuration * @internal */ _setupReconnectionTimer() { this.reconnectTimer = new Timer(async () => { setTimeout(async () => { await this._waitForAuthIfNeeded(); if (!this.isConnected()) { this.connect(); } }, CONNECTION_TIMEOUTS.RECONNECT_DELAY); }, this.reconnectAfterMs); } /** * Initialize client options with defaults * @internal */ _initializeOptions(options) { var _a2, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; this.transport = (_a2 = options === null || options === void 0 ? void 0 : options.transport) !== null && _a2 !== void 0 ? _a2 : null; this.timeout = (_b = options === null || options === void 0 ? void 0 : options.timeout) !== null && _b !== void 0 ? _b : DEFAULT_TIMEOUT; this.heartbeatIntervalMs = (_c = options === null || options === void 0 ? void 0 : options.heartbeatIntervalMs) !== null && _c !== void 0 ? _c : CONNECTION_TIMEOUTS.HEARTBEAT_INTERVAL; this.worker = (_d = options === null || options === void 0 ? void 0 : options.worker) !== null && _d !== void 0 ? _d : false; this.accessToken = (_e = options === null || options === void 0 ? void 0 : options.accessToken) !== null && _e !== void 0 ? _e : null; this.heartbeatCallback = (_f = options === null || options === void 0 ? void 0 : options.heartbeatCallback) !== null && _f !== void 0 ? _f : noop2; this.vsn = (_g = options === null || options === void 0 ? void 0 : options.vsn) !== null && _g !== void 0 ? _g : DEFAULT_VSN; if (options === null || options === void 0 ? void 0 : options.params) this.params = options.params; if (options === null || options === void 0 ? void 0 : options.logger) this.logger = options.logger; if ((options === null || options === void 0 ? void 0 : options.logLevel) || (options === null || options === void 0 ? void 0 : options.log_level)) { this.logLevel = options.logLevel || options.log_level; this.params = Object.assign(Object.assign({}, this.params), { log_level: this.logLevel }); } this.reconnectAfterMs = (_h = options === null || options === void 0 ? void 0 : options.reconnectAfterMs) !== null && _h !== void 0 ? _h : ((tries) => { return RECONNECT_INTERVALS[tries - 1] || DEFAULT_RECONNECT_FALLBACK; }); switch (this.vsn) { case VSN_1_0_0: this.encode = (_j = options === null || options === void 0 ? void 0 : options.encode) !== null && _j !== void 0 ? _j : ((payload, callback) => { return callback(JSON.stringify(payload)); }); this.decode = (_k = options === null || options === void 0 ? void 0 : options.decode) !== null && _k !== void 0 ? _k : ((payload, callback) => { return callback(JSON.parse(payload)); }); break; case VSN_2_0_0: this.encode = (_l = options === null || options === void 0 ? void 0 : options.encode) !== null && _l !== void 0 ? _l : this.serializer.encode.bind(this.serializer); this.decode = (_m = options === null || options === void 0 ? void 0 : options.decode) !== null && _m !== void 0 ? _m : this.serializer.decode.bind(this.serializer); break; default: throw new Error(`Unsupported serializer version: ${this.vsn}`); } if (this.worker) { if (typeof window !== "undefined" && !window.Worker) { throw new Error("Web Worker is not supported"); } this.workerUrl = options === null || options === void 0 ? void 0 : options.workerUrl; } } }; } }); // ../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/index.js var module_exports2 = {}; __export(module_exports2, { REALTIME_CHANNEL_STATES: () => REALTIME_CHANNEL_STATES, REALTIME_LISTEN_TYPES: () => REALTIME_LISTEN_TYPES, REALTIME_POSTGRES_CHANGES_LISTEN_EVENT: () => REALTIME_POSTGRES_CHANGES_LISTEN_EVENT, REALTIME_PRESENCE_LISTEN_EVENTS: () => REALTIME_PRESENCE_LISTEN_EVENTS, REALTIME_SUBSCRIBE_STATES: () => REALTIME_SUBSCRIBE_STATES, RealtimeChannel: () => RealtimeChannel, RealtimeClient: () => RealtimeClient, RealtimePresence: () => RealtimePresence, WebSocketFactory: () => websocket_factory_default }); var init_module2 = __esm({ "../../node_modules/.pnpm/@supabase+realtime-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/realtime-js/dist/module/index.js"() { init_RealtimeClient(); init_RealtimeChannel(); init_RealtimePresence(); init_websocket_factory(); } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/errors.js function isStorageError(error) { return typeof error === "object" && error !== null && "__isStorageError" in error; } var StorageError, StorageApiError, StorageUnknownError; var init_errors = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/errors.js"() { StorageError = class extends Error { constructor(message) { super(message); this.__isStorageError = true; this.name = "StorageError"; } }; StorageApiError = class extends StorageError { constructor(message, status, statusCode) { super(message); this.name = "StorageApiError"; this.status = status; this.statusCode = statusCode; } toJSON() { return { name: this.name, message: this.message, status: this.status, statusCode: this.statusCode }; } }; StorageUnknownError = class extends StorageError { constructor(message, originalError) { super(message); this.name = "StorageUnknownError"; this.originalError = originalError; } }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/helpers.js var resolveFetch2, resolveResponse, recursiveToCamel, isPlainObject, isValidBucketName; var init_helpers = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/helpers.js"() { resolveFetch2 = (customFetch) => { if (customFetch) { return (...args) => customFetch(...args); } return (...args) => fetch(...args); }; resolveResponse = () => { return Response; }; recursiveToCamel = (item) => { if (Array.isArray(item)) { return item.map((el) => recursiveToCamel(el)); } else if (typeof item === "function" || item !== Object(item)) { return item; } const result = {}; Object.entries(item).forEach(([key, value]) => { const newKey = key.replace(/([-_][a-z])/gi, (c) => c.toUpperCase().replace(/[-_]/g, "")); result[newKey] = recursiveToCamel(value); }); return result; }; isPlainObject = (value) => { if (typeof value !== "object" || value === null) { return false; } const prototype = Object.getPrototypeOf(value); return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value); }; isValidBucketName = (bucketName) => { if (!bucketName || typeof bucketName !== "string") { return false; } if (bucketName.length === 0 || bucketName.length > 100) { return false; } if (bucketName.trim() !== bucketName) { return false; } if (bucketName.includes("/") || bucketName.includes("\\")) { return false; } const bucketNameRegex = /^[\w!.\*'() &$@=;:+,?-]+$/; return bucketNameRegex.test(bucketName); }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/fetch.js function _handleRequest(fetcher, method, url, options, parameters, body) { return __awaiter(this, void 0, void 0, function* () { return new Promise((resolve, reject) => { fetcher(url, _getRequestParams(method, options, parameters, body)).then((result) => { if (!result.ok) throw result; if (options === null || options === void 0 ? void 0 : options.noResolveJson) return result; return result.json(); }).then((data) => resolve(data)).catch((error) => handleError(error, reject, options)); }); }); } function get(fetcher, url, options, parameters) { return __awaiter(this, void 0, void 0, function* () { return _handleRequest(fetcher, "GET", url, options, parameters); }); } function post(fetcher, url, body, options, parameters) { return __awaiter(this, void 0, void 0, function* () { return _handleRequest(fetcher, "POST", url, options, parameters, body); }); } function put(fetcher, url, body, options, parameters) { return __awaiter(this, void 0, void 0, function* () { return _handleRequest(fetcher, "PUT", url, options, parameters, body); }); } function head(fetcher, url, options, parameters) { return __awaiter(this, void 0, void 0, function* () { return _handleRequest(fetcher, "HEAD", url, Object.assign(Object.assign({}, options), { noResolveJson: true }), parameters); }); } function remove(fetcher, url, body, options, parameters) { return __awaiter(this, void 0, void 0, function* () { return _handleRequest(fetcher, "DELETE", url, options, parameters, body); }); } var _getErrorMessage, handleError, _getRequestParams; var init_fetch = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/fetch.js"() { init_tslib_es6(); init_errors(); init_helpers(); _getErrorMessage = (err) => { var _a2; return err.msg || err.message || err.error_description || (typeof err.error === "string" ? err.error : (_a2 = err.error) === null || _a2 === void 0 ? void 0 : _a2.message) || JSON.stringify(err); }; handleError = (error, reject, options) => __awaiter(void 0, void 0, void 0, function* () { const Res = yield resolveResponse(); if (error instanceof Res && !(options === null || options === void 0 ? void 0 : options.noResolveJson)) { error.json().then((err) => { const status = error.status || 500; const statusCode = (err === null || err === void 0 ? void 0 : err.statusCode) || status + ""; reject(new StorageApiError(_getErrorMessage(err), status, statusCode)); }).catch((err) => { reject(new StorageUnknownError(_getErrorMessage(err), err)); }); } else { reject(new StorageUnknownError(_getErrorMessage(error), error)); } }); _getRequestParams = (method, options, parameters, body) => { const params = { method, headers: (options === null || options === void 0 ? void 0 : options.headers) || {} }; if (method === "GET" || !body) { return params; } if (isPlainObject(body)) { params.headers = Object.assign({ "Content-Type": "application/json" }, options === null || options === void 0 ? void 0 : options.headers); params.body = JSON.stringify(body); } else { params.body = body; } if (options === null || options === void 0 ? void 0 : options.duplex) { params.duplex = options.duplex; } return Object.assign(Object.assign({}, params), parameters); }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/packages/StreamDownloadBuilder.js var StreamDownloadBuilder; var init_StreamDownloadBuilder = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/packages/StreamDownloadBuilder.js"() { init_tslib_es6(); init_errors(); StreamDownloadBuilder = class { constructor(downloadFn, shouldThrowOnError) { this.downloadFn = downloadFn; this.shouldThrowOnError = shouldThrowOnError; } then(onfulfilled, onrejected) { return this.execute().then(onfulfilled, onrejected); } execute() { return __awaiter(this, void 0, void 0, function* () { try { const result = yield this.downloadFn(); return { data: result.body, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/packages/BlobDownloadBuilder.js var _a, BlobDownloadBuilder, BlobDownloadBuilder_default; var init_BlobDownloadBuilder = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/packages/BlobDownloadBuilder.js"() { init_tslib_es6(); init_errors(); init_StreamDownloadBuilder(); BlobDownloadBuilder = class { constructor(downloadFn, shouldThrowOnError) { this.downloadFn = downloadFn; this.shouldThrowOnError = shouldThrowOnError; this[_a] = "BlobDownloadBuilder"; this.promise = null; } asStream() { return new StreamDownloadBuilder(this.downloadFn, this.shouldThrowOnError); } then(onfulfilled, onrejected) { return this.getPromise().then(onfulfilled, onrejected); } catch(onrejected) { return this.getPromise().catch(onrejected); } finally(onfinally) { return this.getPromise().finally(onfinally); } getPromise() { if (!this.promise) { this.promise = this.execute(); } return this.promise; } execute() { return __awaiter(this, void 0, void 0, function* () { try { const result = yield this.downloadFn(); return { data: yield result.blob(), error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } }; _a = Symbol.toStringTag; BlobDownloadBuilder_default = BlobDownloadBuilder; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/packages/StorageFileApi.js var DEFAULT_SEARCH_OPTIONS, DEFAULT_FILE_OPTIONS, StorageFileApi; var init_StorageFileApi = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/packages/StorageFileApi.js"() { init_tslib_es6(); init_errors(); init_fetch(); init_helpers(); init_BlobDownloadBuilder(); DEFAULT_SEARCH_OPTIONS = { limit: 100, offset: 0, sortBy: { column: "name", order: "asc" } }; DEFAULT_FILE_OPTIONS = { cacheControl: "3600", contentType: "text/plain;charset=UTF-8", upsert: false }; StorageFileApi = class { constructor(url, headers = {}, bucketId, fetch2) { this.shouldThrowOnError = false; this.url = url; this.headers = headers; this.bucketId = bucketId; this.fetch = resolveFetch2(fetch2); } /** * Enable throwing errors instead of returning them. * * @category File Buckets */ throwOnError() { this.shouldThrowOnError = true; return this; } /** * Uploads a file to an existing bucket or replaces an existing file at the specified path with a new one. * * @param method HTTP method. * @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload. * @param fileBody The body of the file to be stored in the bucket. */ uploadOrUpdate(method, path, fileBody, fileOptions) { return __awaiter(this, void 0, void 0, function* () { try { let body; const options = Object.assign(Object.assign({}, DEFAULT_FILE_OPTIONS), fileOptions); let headers = Object.assign(Object.assign({}, this.headers), method === "POST" && { "x-upsert": String(options.upsert) }); const metadata = options.metadata; if (typeof Blob !== "undefined" && fileBody instanceof Blob) { body = new FormData(); body.append("cacheControl", options.cacheControl); if (metadata) { body.append("metadata", this.encodeMetadata(metadata)); } body.append("", fileBody); } else if (typeof FormData !== "undefined" && fileBody instanceof FormData) { body = fileBody; if (!body.has("cacheControl")) { body.append("cacheControl", options.cacheControl); } if (metadata && !body.has("metadata")) { body.append("metadata", this.encodeMetadata(metadata)); } } else { body = fileBody; headers["cache-control"] = `max-age=${options.cacheControl}`; headers["content-type"] = options.contentType; if (metadata) { headers["x-metadata"] = this.toBase64(this.encodeMetadata(metadata)); } const isStream = typeof ReadableStream !== "undefined" && body instanceof ReadableStream || body && typeof body === "object" && "pipe" in body && typeof body.pipe === "function"; if (isStream && !options.duplex) { options.duplex = "half"; } } if (fileOptions === null || fileOptions === void 0 ? void 0 : fileOptions.headers) { headers = Object.assign(Object.assign({}, headers), fileOptions.headers); } const cleanPath = this._removeEmptyFolders(path); const _path = this._getFinalPath(cleanPath); const data = yield (method == "PUT" ? put : post)(this.fetch, `${this.url}/object/${_path}`, body, Object.assign({ headers }, (options === null || options === void 0 ? void 0 : options.duplex) ? { duplex: options.duplex } : {})); return { data: { path: cleanPath, id: data.Id, fullPath: data.Key }, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * Uploads a file to an existing bucket. * * @category File Buckets * @param path The file path, including the file name. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload. * @param fileBody The body of the file to be stored in the bucket. * @param fileOptions Optional file upload options including cacheControl, contentType, upsert, and metadata. * @returns Promise with response containing file path, id, and fullPath or error * * @example Upload file * ```js * const avatarFile = event.target.files[0] * const { data, error } = await supabase * .storage * .from('avatars') * .upload('public/avatar1.png', avatarFile, { * cacheControl: '3600', * upsert: false * }) * ``` * * Response: * ```json * { * "data": { * "path": "public/avatar1.png", * "fullPath": "avatars/public/avatar1.png" * }, * "error": null * } * ``` * * @example Upload file using `ArrayBuffer` from base64 file data * ```js * import { decode } from 'base64-arraybuffer' * * const { data, error } = await supabase * .storage * .from('avatars') * .upload('public/avatar1.png', decode('base64FileData'), { * contentType: 'image/png' * }) * ``` */ upload(path, fileBody, fileOptions) { return __awaiter(this, void 0, void 0, function* () { return this.uploadOrUpdate("POST", path, fileBody, fileOptions); }); } /** * Upload a file with a token generated from `createSignedUploadUrl`. * * @category File Buckets * @param path The file path, including the file name. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload. * @param token The token generated from `createSignedUploadUrl` * @param fileBody The body of the file to be stored in the bucket. * @param fileOptions HTTP headers (cacheControl, contentType, etc.). * **Note:** The `upsert` option has no effect here. To enable upsert behavior, * pass `{ upsert: true }` when calling `createSignedUploadUrl()` instead. * @returns Promise with response containing file path and fullPath or error * * @example Upload to a signed URL * ```js * const { data, error } = await supabase * .storage * .from('avatars') * .uploadToSignedUrl('folder/cat.jpg', 'token-from-createSignedUploadUrl', file) * ``` * * Response: * ```json * { * "data": { * "path": "folder/cat.jpg", * "fullPath": "avatars/folder/cat.jpg" * }, * "error": null * } * ``` */ uploadToSignedUrl(path, token, fileBody, fileOptions) { return __awaiter(this, void 0, void 0, function* () { const cleanPath = this._removeEmptyFolders(path); const _path = this._getFinalPath(cleanPath); const url = new URL(this.url + `/object/upload/sign/${_path}`); url.searchParams.set("token", token); try { let body; const options = Object.assign({ upsert: DEFAULT_FILE_OPTIONS.upsert }, fileOptions); const headers = Object.assign(Object.assign({}, this.headers), { "x-upsert": String(options.upsert) }); if (typeof Blob !== "undefined" && fileBody instanceof Blob) { body = new FormData(); body.append("cacheControl", options.cacheControl); body.append("", fileBody); } else if (typeof FormData !== "undefined" && fileBody instanceof FormData) { body = fileBody; body.append("cacheControl", options.cacheControl); } else { body = fileBody; headers["cache-control"] = `max-age=${options.cacheControl}`; headers["content-type"] = options.contentType; } const data = yield put(this.fetch, url.toString(), body, { headers }); return { data: { path: cleanPath, fullPath: data.Key }, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * Creates a signed upload URL. * Signed upload URLs can be used to upload files to the bucket without further authentication. * They are valid for 2 hours. * * @category File Buckets * @param path The file path, including the current file name. For example `folder/image.png`. * @param options.upsert If set to true, allows the file to be overwritten if it already exists. * @returns Promise with response containing signed upload URL, token, and path or error * * @example Create Signed Upload URL * ```js * const { data, error } = await supabase * .storage * .from('avatars') * .createSignedUploadUrl('folder/cat.jpg') * ``` * * Response: * ```json * { * "data": { * "signedUrl": "https://example.supabase.co/storage/v1/object/upload/sign/avatars/folder/cat.jpg?token=", * "path": "folder/cat.jpg", * "token": "" * }, * "error": null * } * ``` */ createSignedUploadUrl(path, options) { return __awaiter(this, void 0, void 0, function* () { try { let _path = this._getFinalPath(path); const headers = Object.assign({}, this.headers); if (options === null || options === void 0 ? void 0 : options.upsert) { headers["x-upsert"] = "true"; } const data = yield post(this.fetch, `${this.url}/object/upload/sign/${_path}`, {}, { headers }); const url = new URL(this.url + data.url); const token = url.searchParams.get("token"); if (!token) { throw new StorageError("No token returned by API"); } return { data: { signedUrl: url.toString(), path, token }, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * Replaces an existing file at the specified path with a new one. * * @category File Buckets * @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to update. * @param fileBody The body of the file to be stored in the bucket. * @param fileOptions Optional file upload options including cacheControl, contentType, upsert, and metadata. * @returns Promise with response containing file path, id, and fullPath or error * * @example Update file * ```js * const avatarFile = event.target.files[0] * const { data, error } = await supabase * .storage * .from('avatars') * .update('public/avatar1.png', avatarFile, { * cacheControl: '3600', * upsert: true * }) * ``` * * Response: * ```json * { * "data": { * "path": "public/avatar1.png", * "fullPath": "avatars/public/avatar1.png" * }, * "error": null * } * ``` * * @example Update file using `ArrayBuffer` from base64 file data * ```js * import {decode} from 'base64-arraybuffer' * * const { data, error } = await supabase * .storage * .from('avatars') * .update('public/avatar1.png', decode('base64FileData'), { * contentType: 'image/png' * }) * ``` */ update(path, fileBody, fileOptions) { return __awaiter(this, void 0, void 0, function* () { return this.uploadOrUpdate("PUT", path, fileBody, fileOptions); }); } /** * Moves an existing file to a new path in the same bucket. * * @category File Buckets * @param fromPath The original file path, including the current file name. For example `folder/image.png`. * @param toPath The new file path, including the new file name. For example `folder/image-new.png`. * @param options The destination options. * @returns Promise with response containing success message or error * * @example Move file * ```js * const { data, error } = await supabase * .storage * .from('avatars') * .move('public/avatar1.png', 'private/avatar2.png') * ``` * * Response: * ```json * { * "data": { * "message": "Successfully moved" * }, * "error": null * } * ``` */ move(fromPath, toPath, options) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield post(this.fetch, `${this.url}/object/move`, { bucketId: this.bucketId, sourceKey: fromPath, destinationKey: toPath, destinationBucket: options === null || options === void 0 ? void 0 : options.destinationBucket }, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * Copies an existing file to a new path in the same bucket. * * @category File Buckets * @param fromPath The original file path, including the current file name. For example `folder/image.png`. * @param toPath The new file path, including the new file name. For example `folder/image-copy.png`. * @param options The destination options. * @returns Promise with response containing copied file path or error * * @example Copy file * ```js * const { data, error } = await supabase * .storage * .from('avatars') * .copy('public/avatar1.png', 'private/avatar2.png') * ``` * * Response: * ```json * { * "data": { * "path": "avatars/private/avatar2.png" * }, * "error": null * } * ``` */ copy(fromPath, toPath, options) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield post(this.fetch, `${this.url}/object/copy`, { bucketId: this.bucketId, sourceKey: fromPath, destinationKey: toPath, destinationBucket: options === null || options === void 0 ? void 0 : options.destinationBucket }, { headers: this.headers }); return { data: { path: data.Key }, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * Creates a signed URL. Use a signed URL to share a file for a fixed amount of time. * * @category File Buckets * @param path The file path, including the current file name. For example `folder/image.png`. * @param expiresIn The number of seconds until the signed URL expires. For example, `60` for a URL which is valid for one minute. * @param options.download triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename. * @param options.transform Transform the asset before serving it to the client. * @returns Promise with response containing signed URL or error * * @example Create Signed URL * ```js * const { data, error } = await supabase * .storage * .from('avatars') * .createSignedUrl('folder/avatar1.png', 60) * ``` * * Response: * ```json * { * "data": { * "signedUrl": "https://example.supabase.co/storage/v1/object/sign/avatars/folder/avatar1.png?token=" * }, * "error": null * } * ``` * * @example Create a signed URL for an asset with transformations * ```js * const { data } = await supabase * .storage * .from('avatars') * .createSignedUrl('folder/avatar1.png', 60, { * transform: { * width: 100, * height: 100, * } * }) * ``` * * @example Create a signed URL which triggers the download of the asset * ```js * const { data } = await supabase * .storage * .from('avatars') * .createSignedUrl('folder/avatar1.png', 60, { * download: true, * }) * ``` */ createSignedUrl(path, expiresIn, options) { return __awaiter(this, void 0, void 0, function* () { try { let _path = this._getFinalPath(path); let data = yield post(this.fetch, `${this.url}/object/sign/${_path}`, Object.assign({ expiresIn }, (options === null || options === void 0 ? void 0 : options.transform) ? { transform: options.transform } : {}), { headers: this.headers }); const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download) ? `&download=${options.download === true ? "" : options.download}` : ""; const signedUrl = encodeURI(`${this.url}${data.signedURL}${downloadQueryParam}`); data = { signedUrl }; return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * Creates multiple signed URLs. Use a signed URL to share a file for a fixed amount of time. * * @category File Buckets * @param paths The file paths to be downloaded, including the current file names. For example `['folder/image.png', 'folder2/image2.png']`. * @param expiresIn The number of seconds until the signed URLs expire. For example, `60` for URLs which are valid for one minute. * @param options.download triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename. * @returns Promise with response containing array of objects with signedUrl, path, and error or error * * @example Create Signed URLs * ```js * const { data, error } = await supabase * .storage * .from('avatars') * .createSignedUrls(['folder/avatar1.png', 'folder/avatar2.png'], 60) * ``` * * Response: * ```json * { * "data": [ * { * "error": null, * "path": "folder/avatar1.png", * "signedURL": "/object/sign/avatars/folder/avatar1.png?token=", * "signedUrl": "https://example.supabase.co/storage/v1/object/sign/avatars/folder/avatar1.png?token=" * }, * { * "error": null, * "path": "folder/avatar2.png", * "signedURL": "/object/sign/avatars/folder/avatar2.png?token=", * "signedUrl": "https://example.supabase.co/storage/v1/object/sign/avatars/folder/avatar2.png?token=" * } * ], * "error": null * } * ``` */ createSignedUrls(paths, expiresIn, options) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield post(this.fetch, `${this.url}/object/sign/${this.bucketId}`, { expiresIn, paths }, { headers: this.headers }); const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download) ? `&download=${options.download === true ? "" : options.download}` : ""; return { data: data.map((datum) => Object.assign(Object.assign({}, datum), { signedUrl: datum.signedURL ? encodeURI(`${this.url}${datum.signedURL}${downloadQueryParam}`) : null })), error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * Downloads a file from a private bucket. For public buckets, make a request to the URL returned from `getPublicUrl` instead. * * @category File Buckets * @param path The full path and file name of the file to be downloaded. For example `folder/image.png`. * @param options.transform Transform the asset before serving it to the client. * @returns BlobDownloadBuilder instance for downloading the file * * @example Download file * ```js * const { data, error } = await supabase * .storage * .from('avatars') * .download('folder/avatar1.png') * ``` * * Response: * ```json * { * "data": , * "error": null * } * ``` * * @example Download file with transformations * ```js * const { data, error } = await supabase * .storage * .from('avatars') * .download('folder/avatar1.png', { * transform: { * width: 100, * height: 100, * quality: 80 * } * }) * ``` */ download(path, options) { const wantsTransformation = typeof (options === null || options === void 0 ? void 0 : options.transform) !== "undefined"; const renderPath = wantsTransformation ? "render/image/authenticated" : "object"; const transformationQuery = this.transformOptsToQueryString((options === null || options === void 0 ? void 0 : options.transform) || {}); const queryString = transformationQuery ? `?${transformationQuery}` : ""; const _path = this._getFinalPath(path); const downloadFn = () => get(this.fetch, `${this.url}/${renderPath}/${_path}${queryString}`, { headers: this.headers, noResolveJson: true }); return new BlobDownloadBuilder_default(downloadFn, this.shouldThrowOnError); } /** * Retrieves the details of an existing file. * * @category File Buckets * @param path The file path, including the file name. For example `folder/image.png`. * @returns Promise with response containing file metadata or error * * @example Get file info * ```js * const { data, error } = await supabase * .storage * .from('avatars') * .info('folder/avatar1.png') * ``` */ info(path) { return __awaiter(this, void 0, void 0, function* () { const _path = this._getFinalPath(path); try { const data = yield get(this.fetch, `${this.url}/object/info/${_path}`, { headers: this.headers }); return { data: recursiveToCamel(data), error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * Checks the existence of a file. * * @category File Buckets * @param path The file path, including the file name. For example `folder/image.png`. * @returns Promise with response containing boolean indicating file existence or error * * @example Check file existence * ```js * const { data, error } = await supabase * .storage * .from('avatars') * .exists('folder/avatar1.png') * ``` */ exists(path) { return __awaiter(this, void 0, void 0, function* () { const _path = this._getFinalPath(path); try { yield head(this.fetch, `${this.url}/object/${_path}`, { headers: this.headers }); return { data: true, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error) && error instanceof StorageUnknownError) { const originalError = error.originalError; if ([400, 404].includes(originalError === null || originalError === void 0 ? void 0 : originalError.status)) { return { data: false, error }; } } throw error; } }); } /** * A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset. * This function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset. * * @category File Buckets * @param path The path and name of the file to generate the public URL for. For example `folder/image.png`. * @param options.download Triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename. * @param options.transform Transform the asset before serving it to the client. * @returns Object with public URL * * @example Returns the URL for an asset in a public bucket * ```js * const { data } = supabase * .storage * .from('public-bucket') * .getPublicUrl('folder/avatar1.png') * ``` * * Response: * ```json * { * "data": { * "publicUrl": "https://example.supabase.co/storage/v1/object/public/public-bucket/folder/avatar1.png" * } * } * ``` * * @example Returns the URL for an asset in a public bucket with transformations * ```js * const { data } = supabase * .storage * .from('public-bucket') * .getPublicUrl('folder/avatar1.png', { * transform: { * width: 100, * height: 100, * } * }) * ``` * * @example Returns the URL which triggers the download of an asset in a public bucket * ```js * const { data } = supabase * .storage * .from('public-bucket') * .getPublicUrl('folder/avatar1.png', { * download: true, * }) * ``` */ getPublicUrl(path, options) { const _path = this._getFinalPath(path); const _queryString = []; const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download) ? `download=${options.download === true ? "" : options.download}` : ""; if (downloadQueryParam !== "") { _queryString.push(downloadQueryParam); } const wantsTransformation = typeof (options === null || options === void 0 ? void 0 : options.transform) !== "undefined"; const renderPath = wantsTransformation ? "render/image" : "object"; const transformationQuery = this.transformOptsToQueryString((options === null || options === void 0 ? void 0 : options.transform) || {}); if (transformationQuery !== "") { _queryString.push(transformationQuery); } let queryString = _queryString.join("&"); if (queryString !== "") { queryString = `?${queryString}`; } return { data: { publicUrl: encodeURI(`${this.url}/${renderPath}/public/${_path}${queryString}`) } }; } /** * Deletes files within the same bucket * * @category File Buckets * @param paths An array of files to delete, including the path and file name. For example [`'folder/image.png'`]. * @returns Promise with response containing array of deleted file objects or error * * @example Delete file * ```js * const { data, error } = await supabase * .storage * .from('avatars') * .remove(['folder/avatar1.png']) * ``` * * Response: * ```json * { * "data": [], * "error": null * } * ``` */ remove(paths) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield remove(this.fetch, `${this.url}/object/${this.bucketId}`, { prefixes: paths }, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * Get file metadata * @param id the file id to retrieve metadata */ // async getMetadata( // id: string // ): Promise< // | { // data: Metadata // error: null // } // | { // data: null // error: StorageError // } // > { // try { // const data = await get(this.fetch, `${this.url}/metadata/${id}`, { headers: this.headers }) // return { data, error: null } // } catch (error) { // if (isStorageError(error)) { // return { data: null, error } // } // throw error // } // } /** * Update file metadata * @param id the file id to update metadata * @param meta the new file metadata */ // async updateMetadata( // id: string, // meta: Metadata // ): Promise< // | { // data: Metadata // error: null // } // | { // data: null // error: StorageError // } // > { // try { // const data = await post( // this.fetch, // `${this.url}/metadata/${id}`, // { ...meta }, // { headers: this.headers } // ) // return { data, error: null } // } catch (error) { // if (isStorageError(error)) { // return { data: null, error } // } // throw error // } // } /** * Lists all the files and folders within a path of the bucket. * * @category File Buckets * @param path The folder path. * @param options Search options including limit (defaults to 100), offset, sortBy, and search * @param parameters Optional fetch parameters including signal for cancellation * @returns Promise with response containing array of files or error * * @example List files in a bucket * ```js * const { data, error } = await supabase * .storage * .from('avatars') * .list('folder', { * limit: 100, * offset: 0, * sortBy: { column: 'name', order: 'asc' }, * }) * ``` * * Response: * ```json * { * "data": [ * { * "name": "avatar1.png", * "id": "e668cf7f-821b-4a2f-9dce-7dfa5dd1cfd2", * "updated_at": "2024-05-22T23:06:05.580Z", * "created_at": "2024-05-22T23:04:34.443Z", * "last_accessed_at": "2024-05-22T23:04:34.443Z", * "metadata": { * "eTag": "\"c5e8c553235d9af30ef4f6e280790b92\"", * "size": 32175, * "mimetype": "image/png", * "cacheControl": "max-age=3600", * "lastModified": "2024-05-22T23:06:05.574Z", * "contentLength": 32175, * "httpStatusCode": 200 * } * } * ], * "error": null * } * ``` * * @example Search files in a bucket * ```js * const { data, error } = await supabase * .storage * .from('avatars') * .list('folder', { * limit: 100, * offset: 0, * sortBy: { column: 'name', order: 'asc' }, * search: 'jon' * }) * ``` */ list(path, options, parameters) { return __awaiter(this, void 0, void 0, function* () { try { const body = Object.assign(Object.assign(Object.assign({}, DEFAULT_SEARCH_OPTIONS), options), { prefix: path || "" }); const data = yield post(this.fetch, `${this.url}/object/list/${this.bucketId}`, body, { headers: this.headers }, parameters); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * @experimental this method signature might change in the future * * @category File Buckets * @param options search options * @param parameters */ listV2(options, parameters) { return __awaiter(this, void 0, void 0, function* () { try { const body = Object.assign({}, options); const data = yield post(this.fetch, `${this.url}/object/list-v2/${this.bucketId}`, body, { headers: this.headers }, parameters); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } encodeMetadata(metadata) { return JSON.stringify(metadata); } toBase64(data) { if (typeof Buffer !== "undefined") { return Buffer.from(data).toString("base64"); } return btoa(data); } _getFinalPath(path) { return `${this.bucketId}/${path.replace(/^\/+/, "")}`; } _removeEmptyFolders(path) { return path.replace(/^\/|\/$/g, "").replace(/\/+/g, "/"); } transformOptsToQueryString(transform) { const params = []; if (transform.width) { params.push(`width=${transform.width}`); } if (transform.height) { params.push(`height=${transform.height}`); } if (transform.resize) { params.push(`resize=${transform.resize}`); } if (transform.format) { params.push(`format=${transform.format}`); } if (transform.quality) { params.push(`quality=${transform.quality}`); } return params.join("&"); } }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/version.js var version2; var init_version2 = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/version.js"() { version2 = "2.86.2"; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/constants.js var DEFAULT_HEADERS; var init_constants2 = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/constants.js"() { init_version2(); DEFAULT_HEADERS = { "X-Client-Info": `storage-js/${version2}` }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/packages/StorageBucketApi.js var StorageBucketApi; var init_StorageBucketApi = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/packages/StorageBucketApi.js"() { init_tslib_es6(); init_constants2(); init_errors(); init_fetch(); init_helpers(); StorageBucketApi = class { constructor(url, headers = {}, fetch2, opts) { this.shouldThrowOnError = false; const baseUrl = new URL(url); if (opts === null || opts === void 0 ? void 0 : opts.useNewHostname) { const isSupabaseHost = /supabase\.(co|in|red)$/.test(baseUrl.hostname); if (isSupabaseHost && !baseUrl.hostname.includes("storage.supabase.")) { baseUrl.hostname = baseUrl.hostname.replace("supabase.", "storage.supabase."); } } this.url = baseUrl.href.replace(/\/$/, ""); this.headers = Object.assign(Object.assign({}, DEFAULT_HEADERS), headers); this.fetch = resolveFetch2(fetch2); } /** * Enable throwing errors instead of returning them. * * @category File Buckets */ throwOnError() { this.shouldThrowOnError = true; return this; } /** * Retrieves the details of all Storage buckets within an existing project. * * @category File Buckets * @param options Query parameters for listing buckets * @param options.limit Maximum number of buckets to return * @param options.offset Number of buckets to skip * @param options.sortColumn Column to sort by ('id', 'name', 'created_at', 'updated_at') * @param options.sortOrder Sort order ('asc' or 'desc') * @param options.search Search term to filter bucket names * @returns Promise with response containing array of buckets or error * * @example List buckets * ```js * const { data, error } = await supabase * .storage * .listBuckets() * ``` * * @example List buckets with options * ```js * const { data, error } = await supabase * .storage * .listBuckets({ * limit: 10, * offset: 0, * sortColumn: 'created_at', * sortOrder: 'desc', * search: 'prod' * }) * ``` */ listBuckets(options) { return __awaiter(this, void 0, void 0, function* () { try { const queryString = this.listBucketOptionsToQueryString(options); const data = yield get(this.fetch, `${this.url}/bucket${queryString}`, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * Retrieves the details of an existing Storage bucket. * * @category File Buckets * @param id The unique identifier of the bucket you would like to retrieve. * @returns Promise with response containing bucket details or error * * @example Get bucket * ```js * const { data, error } = await supabase * .storage * .getBucket('avatars') * ``` * * Response: * ```json * { * "data": { * "id": "avatars", * "name": "avatars", * "owner": "", * "public": false, * "file_size_limit": 1024, * "allowed_mime_types": [ * "image/png" * ], * "created_at": "2024-05-22T22:26:05.100Z", * "updated_at": "2024-05-22T22:26:05.100Z" * }, * "error": null * } * ``` */ getBucket(id) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield get(this.fetch, `${this.url}/bucket/${id}`, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * Creates a new Storage bucket * * @category File Buckets * @param id A unique identifier for the bucket you are creating. * @param options.public The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations. By default, buckets are private. * @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket. * The global file size limit takes precedence over this value. * The default value is null, which doesn't set a per bucket file size limit. * @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload. * The default value is null, which allows files with all mime types to be uploaded. * Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png. * @param options.type (private-beta) specifies the bucket type. see `BucketType` for more details. * - default bucket type is `STANDARD` * @returns Promise with response containing newly created bucket name or error * * @example Create bucket * ```js * const { data, error } = await supabase * .storage * .createBucket('avatars', { * public: false, * allowedMimeTypes: ['image/png'], * fileSizeLimit: 1024 * }) * ``` * * Response: * ```json * { * "data": { * "name": "avatars" * }, * "error": null * } * ``` */ createBucket(id_1) { return __awaiter(this, arguments, void 0, function* (id, options = { public: false }) { try { const data = yield post(this.fetch, `${this.url}/bucket`, { id, name: id, type: options.type, public: options.public, file_size_limit: options.fileSizeLimit, allowed_mime_types: options.allowedMimeTypes }, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * Updates a Storage bucket * * @category File Buckets * @param id A unique identifier for the bucket you are updating. * @param options.public The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations. * @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket. * The global file size limit takes precedence over this value. * The default value is null, which doesn't set a per bucket file size limit. * @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload. * The default value is null, which allows files with all mime types to be uploaded. * Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png. * @returns Promise with response containing success message or error * * @example Update bucket * ```js * const { data, error } = await supabase * .storage * .updateBucket('avatars', { * public: false, * allowedMimeTypes: ['image/png'], * fileSizeLimit: 1024 * }) * ``` * * Response: * ```json * { * "data": { * "message": "Successfully updated" * }, * "error": null * } * ``` */ updateBucket(id, options) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield put(this.fetch, `${this.url}/bucket/${id}`, { id, name: id, public: options.public, file_size_limit: options.fileSizeLimit, allowed_mime_types: options.allowedMimeTypes }, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * Removes all objects inside a single bucket. * * @category File Buckets * @param id The unique identifier of the bucket you would like to empty. * @returns Promise with success message or error * * @example Empty bucket * ```js * const { data, error } = await supabase * .storage * .emptyBucket('avatars') * ``` * * Response: * ```json * { * "data": { * "message": "Successfully emptied" * }, * "error": null * } * ``` */ emptyBucket(id) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield post(this.fetch, `${this.url}/bucket/${id}/empty`, {}, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * Deletes an existing bucket. A bucket can't be deleted with existing objects inside it. * You must first `empty()` the bucket. * * @category File Buckets * @param id The unique identifier of the bucket you would like to delete. * @returns Promise with success message or error * * @example Delete bucket * ```js * const { data, error } = await supabase * .storage * .deleteBucket('avatars') * ``` * * Response: * ```json * { * "data": { * "message": "Successfully deleted" * }, * "error": null * } * ``` */ deleteBucket(id) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield remove(this.fetch, `${this.url}/bucket/${id}`, {}, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } listBucketOptionsToQueryString(options) { const params = {}; if (options) { if ("limit" in options) { params.limit = String(options.limit); } if ("offset" in options) { params.offset = String(options.offset); } if (options.search) { params.search = options.search; } if (options.sortColumn) { params.sortColumn = options.sortColumn; } if (options.sortOrder) { params.sortOrder = options.sortOrder; } } return Object.keys(params).length > 0 ? "?" + new URLSearchParams(params).toString() : ""; } }; } }); // ../../node_modules/.pnpm/iceberg-js@0.8.1/node_modules/iceberg-js/dist/index.mjs function buildUrl(baseUrl, path, query) { const url = new URL(path, baseUrl); if (query) { for (const [key, value] of Object.entries(query)) { if (value !== void 0) { url.searchParams.set(key, value); } } } return url.toString(); } async function buildAuthHeaders(auth) { if (!auth || auth.type === "none") { return {}; } if (auth.type === "bearer") { return { Authorization: `Bearer ${auth.token}` }; } if (auth.type === "header") { return { [auth.name]: auth.value }; } if (auth.type === "custom") { return await auth.getHeaders(); } return {}; } function createFetchClient(options) { const fetchFn = options.fetchImpl ?? globalThis.fetch; return { async request({ method, path, query, body, headers }) { const url = buildUrl(options.baseUrl, path, query); const authHeaders = await buildAuthHeaders(options.auth); const res = await fetchFn(url, { method, headers: { ...body ? { "Content-Type": "application/json" } : {}, ...authHeaders, ...headers }, body: body ? JSON.stringify(body) : void 0 }); const text = await res.text(); const isJson = (res.headers.get("content-type") || "").includes("application/json"); const data = isJson && text ? JSON.parse(text) : text; if (!res.ok) { const errBody = isJson ? data : void 0; const errorDetail = errBody == null ? void 0 : errBody.error; throw new IcebergError( (errorDetail == null ? void 0 : errorDetail.message) ?? `Request failed with status ${res.status}`, { status: res.status, icebergType: errorDetail == null ? void 0 : errorDetail.type, icebergCode: errorDetail == null ? void 0 : errorDetail.code, details: errBody } ); } return { status: res.status, headers: res.headers, data }; } }; } function namespaceToPath(namespace) { return namespace.join(""); } function namespaceToPath2(namespace) { return namespace.join(""); } var IcebergError, NamespaceOperations, TableOperations, IcebergRestCatalog; var init_dist = __esm({ "../../node_modules/.pnpm/iceberg-js@0.8.1/node_modules/iceberg-js/dist/index.mjs"() { IcebergError = class extends Error { constructor(message, opts) { var _a2; super(message); this.name = "IcebergError"; this.status = opts.status; this.icebergType = opts.icebergType; this.icebergCode = opts.icebergCode; this.details = opts.details; this.isCommitStateUnknown = opts.icebergType === "CommitStateUnknownException" || [500, 502, 504].includes(opts.status) && ((_a2 = opts.icebergType) == null ? void 0 : _a2.includes("CommitState")) === true; } /** * Returns true if the error is a 404 Not Found error. */ isNotFound() { return this.status === 404; } /** * Returns true if the error is a 409 Conflict error. */ isConflict() { return this.status === 409; } /** * Returns true if the error is a 419 Authentication Timeout error. */ isAuthenticationTimeout() { return this.status === 419; } }; NamespaceOperations = class { constructor(client, prefix = "") { this.client = client; this.prefix = prefix; } async listNamespaces(parent) { const query = parent ? { parent: namespaceToPath(parent.namespace) } : void 0; const response = await this.client.request({ method: "GET", path: `${this.prefix}/namespaces`, query }); return response.data.namespaces.map((ns) => ({ namespace: ns })); } async createNamespace(id, metadata) { const request = { namespace: id.namespace, properties: metadata == null ? void 0 : metadata.properties }; const response = await this.client.request({ method: "POST", path: `${this.prefix}/namespaces`, body: request }); return response.data; } async dropNamespace(id) { await this.client.request({ method: "DELETE", path: `${this.prefix}/namespaces/${namespaceToPath(id.namespace)}` }); } async loadNamespaceMetadata(id) { const response = await this.client.request({ method: "GET", path: `${this.prefix}/namespaces/${namespaceToPath(id.namespace)}` }); return { properties: response.data.properties }; } async namespaceExists(id) { try { await this.client.request({ method: "HEAD", path: `${this.prefix}/namespaces/${namespaceToPath(id.namespace)}` }); return true; } catch (error) { if (error instanceof IcebergError && error.status === 404) { return false; } throw error; } } async createNamespaceIfNotExists(id, metadata) { try { return await this.createNamespace(id, metadata); } catch (error) { if (error instanceof IcebergError && error.status === 409) { return; } throw error; } } }; TableOperations = class { constructor(client, prefix = "", accessDelegation) { this.client = client; this.prefix = prefix; this.accessDelegation = accessDelegation; } async listTables(namespace) { const response = await this.client.request({ method: "GET", path: `${this.prefix}/namespaces/${namespaceToPath2(namespace.namespace)}/tables` }); return response.data.identifiers; } async createTable(namespace, request) { const headers = {}; if (this.accessDelegation) { headers["X-Iceberg-Access-Delegation"] = this.accessDelegation; } const response = await this.client.request({ method: "POST", path: `${this.prefix}/namespaces/${namespaceToPath2(namespace.namespace)}/tables`, body: request, headers }); return response.data.metadata; } async updateTable(id, request) { const response = await this.client.request({ method: "POST", path: `${this.prefix}/namespaces/${namespaceToPath2(id.namespace)}/tables/${id.name}`, body: request }); return { "metadata-location": response.data["metadata-location"], metadata: response.data.metadata }; } async dropTable(id, options) { await this.client.request({ method: "DELETE", path: `${this.prefix}/namespaces/${namespaceToPath2(id.namespace)}/tables/${id.name}`, query: { purgeRequested: String((options == null ? void 0 : options.purge) ?? false) } }); } async loadTable(id) { const headers = {}; if (this.accessDelegation) { headers["X-Iceberg-Access-Delegation"] = this.accessDelegation; } const response = await this.client.request({ method: "GET", path: `${this.prefix}/namespaces/${namespaceToPath2(id.namespace)}/tables/${id.name}`, headers }); return response.data.metadata; } async tableExists(id) { const headers = {}; if (this.accessDelegation) { headers["X-Iceberg-Access-Delegation"] = this.accessDelegation; } try { await this.client.request({ method: "HEAD", path: `${this.prefix}/namespaces/${namespaceToPath2(id.namespace)}/tables/${id.name}`, headers }); return true; } catch (error) { if (error instanceof IcebergError && error.status === 404) { return false; } throw error; } } async createTableIfNotExists(namespace, request) { try { return await this.createTable(namespace, request); } catch (error) { if (error instanceof IcebergError && error.status === 409) { return await this.loadTable({ namespace: namespace.namespace, name: request.name }); } throw error; } } }; IcebergRestCatalog = class { /** * Creates a new Iceberg REST Catalog client. * * @param options - Configuration options for the catalog client */ constructor(options) { var _a2; let prefix = "v1"; if (options.catalogName) { prefix += `/${options.catalogName}`; } const baseUrl = options.baseUrl.endsWith("/") ? options.baseUrl : `${options.baseUrl}/`; this.client = createFetchClient({ baseUrl, auth: options.auth, fetchImpl: options.fetch }); this.accessDelegation = (_a2 = options.accessDelegation) == null ? void 0 : _a2.join(","); this.namespaceOps = new NamespaceOperations(this.client, prefix); this.tableOps = new TableOperations(this.client, prefix, this.accessDelegation); } /** * Lists all namespaces in the catalog. * * @param parent - Optional parent namespace to list children under * @returns Array of namespace identifiers * * @example * ```typescript * // List all top-level namespaces * const namespaces = await catalog.listNamespaces(); * * // List namespaces under a parent * const children = await catalog.listNamespaces({ namespace: ['analytics'] }); * ``` */ async listNamespaces(parent) { return this.namespaceOps.listNamespaces(parent); } /** * Creates a new namespace in the catalog. * * @param id - Namespace identifier to create * @param metadata - Optional metadata properties for the namespace * @returns Response containing the created namespace and its properties * * @example * ```typescript * const response = await catalog.createNamespace( * { namespace: ['analytics'] }, * { properties: { owner: 'data-team' } } * ); * console.log(response.namespace); // ['analytics'] * console.log(response.properties); // { owner: 'data-team', ... } * ``` */ async createNamespace(id, metadata) { return this.namespaceOps.createNamespace(id, metadata); } /** * Drops a namespace from the catalog. * * The namespace must be empty (contain no tables) before it can be dropped. * * @param id - Namespace identifier to drop * * @example * ```typescript * await catalog.dropNamespace({ namespace: ['analytics'] }); * ``` */ async dropNamespace(id) { await this.namespaceOps.dropNamespace(id); } /** * Loads metadata for a namespace. * * @param id - Namespace identifier to load * @returns Namespace metadata including properties * * @example * ```typescript * const metadata = await catalog.loadNamespaceMetadata({ namespace: ['analytics'] }); * console.log(metadata.properties); * ``` */ async loadNamespaceMetadata(id) { return this.namespaceOps.loadNamespaceMetadata(id); } /** * Lists all tables in a namespace. * * @param namespace - Namespace identifier to list tables from * @returns Array of table identifiers * * @example * ```typescript * const tables = await catalog.listTables({ namespace: ['analytics'] }); * console.log(tables); // [{ namespace: ['analytics'], name: 'events' }, ...] * ``` */ async listTables(namespace) { return this.tableOps.listTables(namespace); } /** * Creates a new table in the catalog. * * @param namespace - Namespace to create the table in * @param request - Table creation request including name, schema, partition spec, etc. * @returns Table metadata for the created table * * @example * ```typescript * const metadata = await catalog.createTable( * { namespace: ['analytics'] }, * { * name: 'events', * schema: { * type: 'struct', * fields: [ * { id: 1, name: 'id', type: 'long', required: true }, * { id: 2, name: 'timestamp', type: 'timestamp', required: true } * ], * 'schema-id': 0 * }, * 'partition-spec': { * 'spec-id': 0, * fields: [ * { source_id: 2, field_id: 1000, name: 'ts_day', transform: 'day' } * ] * } * } * ); * ``` */ async createTable(namespace, request) { return this.tableOps.createTable(namespace, request); } /** * Updates an existing table's metadata. * * Can update the schema, partition spec, or properties of a table. * * @param id - Table identifier to update * @param request - Update request with fields to modify * @returns Response containing the metadata location and updated table metadata * * @example * ```typescript * const response = await catalog.updateTable( * { namespace: ['analytics'], name: 'events' }, * { * properties: { 'read.split.target-size': '134217728' } * } * ); * console.log(response['metadata-location']); // s3://... * console.log(response.metadata); // TableMetadata object * ``` */ async updateTable(id, request) { return this.tableOps.updateTable(id, request); } /** * Drops a table from the catalog. * * @param id - Table identifier to drop * * @example * ```typescript * await catalog.dropTable({ namespace: ['analytics'], name: 'events' }); * ``` */ async dropTable(id, options) { await this.tableOps.dropTable(id, options); } /** * Loads metadata for a table. * * @param id - Table identifier to load * @returns Table metadata including schema, partition spec, location, etc. * * @example * ```typescript * const metadata = await catalog.loadTable({ namespace: ['analytics'], name: 'events' }); * console.log(metadata.schema); * console.log(metadata.location); * ``` */ async loadTable(id) { return this.tableOps.loadTable(id); } /** * Checks if a namespace exists in the catalog. * * @param id - Namespace identifier to check * @returns True if the namespace exists, false otherwise * * @example * ```typescript * const exists = await catalog.namespaceExists({ namespace: ['analytics'] }); * console.log(exists); // true or false * ``` */ async namespaceExists(id) { return this.namespaceOps.namespaceExists(id); } /** * Checks if a table exists in the catalog. * * @param id - Table identifier to check * @returns True if the table exists, false otherwise * * @example * ```typescript * const exists = await catalog.tableExists({ namespace: ['analytics'], name: 'events' }); * console.log(exists); // true or false * ``` */ async tableExists(id) { return this.tableOps.tableExists(id); } /** * Creates a namespace if it does not exist. * * If the namespace already exists, returns void. If created, returns the response. * * @param id - Namespace identifier to create * @param metadata - Optional metadata properties for the namespace * @returns Response containing the created namespace and its properties, or void if it already exists * * @example * ```typescript * const response = await catalog.createNamespaceIfNotExists( * { namespace: ['analytics'] }, * { properties: { owner: 'data-team' } } * ); * if (response) { * console.log('Created:', response.namespace); * } else { * console.log('Already exists'); * } * ``` */ async createNamespaceIfNotExists(id, metadata) { return this.namespaceOps.createNamespaceIfNotExists(id, metadata); } /** * Creates a table if it does not exist. * * If the table already exists, returns its metadata instead. * * @param namespace - Namespace to create the table in * @param request - Table creation request including name, schema, partition spec, etc. * @returns Table metadata for the created or existing table * * @example * ```typescript * const metadata = await catalog.createTableIfNotExists( * { namespace: ['analytics'] }, * { * name: 'events', * schema: { * type: 'struct', * fields: [ * { id: 1, name: 'id', type: 'long', required: true }, * { id: 2, name: 'timestamp', type: 'timestamp', required: true } * ], * 'schema-id': 0 * } * } * ); * ``` */ async createTableIfNotExists(namespace, request) { return this.tableOps.createTableIfNotExists(namespace, request); } }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/packages/StorageAnalyticsClient.js var StorageAnalyticsClient; var init_StorageAnalyticsClient = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/packages/StorageAnalyticsClient.js"() { init_tslib_es6(); init_dist(); init_constants2(); init_errors(); init_fetch(); init_helpers(); StorageAnalyticsClient = class { /** * @alpha * * Creates a new StorageAnalyticsClient instance * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Analytics Buckets * @param url - The base URL for the storage API * @param headers - HTTP headers to include in requests * @param fetch - Optional custom fetch implementation * * @example * ```typescript * const client = new StorageAnalyticsClient(url, headers) * ``` */ constructor(url, headers = {}, fetch2) { this.shouldThrowOnError = false; this.url = url.replace(/\/$/, ""); this.headers = Object.assign(Object.assign({}, DEFAULT_HEADERS), headers); this.fetch = resolveFetch2(fetch2); } /** * @alpha * * Enable throwing errors instead of returning them in the response * When enabled, failed operations will throw instead of returning { data: null, error } * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Analytics Buckets * @returns This instance for method chaining */ throwOnError() { this.shouldThrowOnError = true; return this; } /** * @alpha * * Creates a new analytics bucket using Iceberg tables * Analytics buckets are optimized for analytical queries and data processing * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Analytics Buckets * @param name A unique name for the bucket you are creating * @returns Promise with response containing newly created analytics bucket or error * * @example Create analytics bucket * ```js * const { data, error } = await supabase * .storage * .analytics * .createBucket('analytics-data') * ``` * * Response: * ```json * { * "data": { * "name": "analytics-data", * "type": "ANALYTICS", * "format": "iceberg", * "created_at": "2024-05-22T22:26:05.100Z", * "updated_at": "2024-05-22T22:26:05.100Z" * }, * "error": null * } * ``` */ createBucket(name) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield post(this.fetch, `${this.url}/bucket`, { name }, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * @alpha * * Retrieves the details of all Analytics Storage buckets within an existing project * Only returns buckets of type 'ANALYTICS' * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Analytics Buckets * @param options Query parameters for listing buckets * @param options.limit Maximum number of buckets to return * @param options.offset Number of buckets to skip * @param options.sortColumn Column to sort by ('name', 'created_at', 'updated_at') * @param options.sortOrder Sort order ('asc' or 'desc') * @param options.search Search term to filter bucket names * @returns Promise with response containing array of analytics buckets or error * * @example List analytics buckets * ```js * const { data, error } = await supabase * .storage * .analytics * .listBuckets({ * limit: 10, * offset: 0, * sortColumn: 'created_at', * sortOrder: 'desc' * }) * ``` * * Response: * ```json * { * "data": [ * { * "name": "analytics-data", * "type": "ANALYTICS", * "format": "iceberg", * "created_at": "2024-05-22T22:26:05.100Z", * "updated_at": "2024-05-22T22:26:05.100Z" * } * ], * "error": null * } * ``` */ listBuckets(options) { return __awaiter(this, void 0, void 0, function* () { try { const queryParams = new URLSearchParams(); if ((options === null || options === void 0 ? void 0 : options.limit) !== void 0) queryParams.set("limit", options.limit.toString()); if ((options === null || options === void 0 ? void 0 : options.offset) !== void 0) queryParams.set("offset", options.offset.toString()); if (options === null || options === void 0 ? void 0 : options.sortColumn) queryParams.set("sortColumn", options.sortColumn); if (options === null || options === void 0 ? void 0 : options.sortOrder) queryParams.set("sortOrder", options.sortOrder); if (options === null || options === void 0 ? void 0 : options.search) queryParams.set("search", options.search); const queryString = queryParams.toString(); const url = queryString ? `${this.url}/bucket?${queryString}` : `${this.url}/bucket`; const data = yield get(this.fetch, url, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * @alpha * * Deletes an existing analytics bucket * A bucket can't be deleted with existing objects inside it * You must first empty the bucket before deletion * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Analytics Buckets * @param bucketName The unique identifier of the bucket you would like to delete * @returns Promise with response containing success message or error * * @example Delete analytics bucket * ```js * const { data, error } = await supabase * .storage * .analytics * .deleteBucket('analytics-data') * ``` * * Response: * ```json * { * "data": { * "message": "Successfully deleted" * }, * "error": null * } * ``` */ deleteBucket(bucketName) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield remove(this.fetch, `${this.url}/bucket/${bucketName}`, {}, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageError(error)) { return { data: null, error }; } throw error; } }); } /** * @alpha * * Get an Iceberg REST Catalog client configured for a specific analytics bucket * Use this to perform advanced table and namespace operations within the bucket * The returned client provides full access to the Apache Iceberg REST Catalog API * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Analytics Buckets * @param bucketName - The name of the analytics bucket (warehouse) to connect to * @returns Configured IcebergRestCatalog instance for advanced Iceberg operations * * @example Get catalog and create table * ```js * // First, create an analytics bucket * const { data: bucket, error: bucketError } = await supabase * .storage * .analytics * .createBucket('analytics-data') * * // Get the Iceberg catalog for that bucket * const catalog = supabase.storage.analytics.from('analytics-data') * * // Create a namespace * await catalog.createNamespace({ namespace: ['default'] }) * * // Create a table with schema * await catalog.createTable( * { namespace: ['default'] }, * { * name: 'events', * schema: { * type: 'struct', * fields: [ * { id: 1, name: 'id', type: 'long', required: true }, * { id: 2, name: 'timestamp', type: 'timestamp', required: true }, * { id: 3, name: 'user_id', type: 'string', required: false } * ], * 'schema-id': 0, * 'identifier-field-ids': [1] * }, * 'partition-spec': { * 'spec-id': 0, * fields: [] * }, * 'write-order': { * 'order-id': 0, * fields: [] * }, * properties: { * 'write.format.default': 'parquet' * } * } * ) * ``` * * @example List tables in namespace * ```js * const catalog = supabase.storage.analytics.from('analytics-data') * * // List all tables in the default namespace * const tables = await catalog.listTables({ namespace: ['default'] }) * console.log(tables) // [{ namespace: ['default'], name: 'events' }] * ``` * * @example Working with namespaces * ```js * const catalog = supabase.storage.analytics.from('analytics-data') * * // List all namespaces * const namespaces = await catalog.listNamespaces() * * // Create namespace with properties * await catalog.createNamespace( * { namespace: ['production'] }, * { properties: { owner: 'data-team', env: 'prod' } } * ) * ``` * * @example Cleanup operations * ```js * const catalog = supabase.storage.analytics.from('analytics-data') * * // Drop table with purge option (removes all data) * await catalog.dropTable( * { namespace: ['default'], name: 'events' }, * { purge: true } * ) * * // Drop namespace (must be empty) * await catalog.dropNamespace({ namespace: ['default'] }) * ``` * * @example Error handling with catalog operations * ```js * import { IcebergError } from 'iceberg-js' * * const catalog = supabase.storage.analytics.from('analytics-data') * * try { * await catalog.dropTable({ namespace: ['default'], name: 'events' }, { purge: true }) * } catch (error) { * // Handle 404 errors (resource not found) * const is404 = * (error instanceof IcebergError && error.status === 404) || * error?.status === 404 || * error?.details?.error?.code === 404 * * if (is404) { * console.log('Table does not exist') * } else { * throw error // Re-throw other errors * } * } * ``` * * @remarks * This method provides a bridge between Supabase's bucket management and the standard * Apache Iceberg REST Catalog API. The bucket name maps to the Iceberg warehouse parameter. * All authentication and configuration is handled automatically using your Supabase credentials. * * **Error Handling**: Operations may throw `IcebergError` from the iceberg-js library. * Always handle 404 errors gracefully when checking for resource existence. * * **Cleanup Operations**: When using `dropTable`, the `purge: true` option permanently * deletes all table data. Without it, the table is marked as deleted but data remains. * * **Library Dependency**: The returned catalog is an instance of `IcebergRestCatalog` * from iceberg-js. For complete API documentation and advanced usage, refer to the * [iceberg-js documentation](https://supabase.github.io/iceberg-js/). * * For advanced Iceberg operations beyond bucket management, you can also install and use * the `iceberg-js` package directly with manual configuration. */ from(bucketName) { if (!isValidBucketName(bucketName)) { throw new StorageError("Invalid bucket name: File, folder, and bucket names must follow AWS object key naming guidelines and should avoid the use of any other characters."); } return new IcebergRestCatalog({ baseUrl: this.url, catalogName: bucketName, // Maps to the warehouse parameter in Supabase's implementation auth: { type: "custom", getHeaders: () => __awaiter(this, void 0, void 0, function* () { return this.headers; }) }, fetch: this.fetch }); } }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/constants.js var DEFAULT_HEADERS2; var init_constants3 = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/constants.js"() { init_version2(); DEFAULT_HEADERS2 = { "X-Client-Info": `storage-js/${version2}`, "Content-Type": "application/json" }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/errors.js function isStorageVectorsError(error) { return typeof error === "object" && error !== null && "__isStorageVectorsError" in error; } var StorageVectorsError, StorageVectorsApiError, StorageVectorsUnknownError, StorageVectorsErrorCode; var init_errors2 = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/errors.js"() { StorageVectorsError = class extends Error { constructor(message) { super(message); this.__isStorageVectorsError = true; this.name = "StorageVectorsError"; } }; StorageVectorsApiError = class extends StorageVectorsError { constructor(message, status, statusCode) { super(message); this.name = "StorageVectorsApiError"; this.status = status; this.statusCode = statusCode; } toJSON() { return { name: this.name, message: this.message, status: this.status, statusCode: this.statusCode }; } }; StorageVectorsUnknownError = class extends StorageVectorsError { constructor(message, originalError) { super(message); this.name = "StorageVectorsUnknownError"; this.originalError = originalError; } }; (function(StorageVectorsErrorCode2) { StorageVectorsErrorCode2["InternalError"] = "InternalError"; StorageVectorsErrorCode2["S3VectorConflictException"] = "S3VectorConflictException"; StorageVectorsErrorCode2["S3VectorNotFoundException"] = "S3VectorNotFoundException"; StorageVectorsErrorCode2["S3VectorBucketNotEmpty"] = "S3VectorBucketNotEmpty"; StorageVectorsErrorCode2["S3VectorMaxBucketsExceeded"] = "S3VectorMaxBucketsExceeded"; StorageVectorsErrorCode2["S3VectorMaxIndexesExceeded"] = "S3VectorMaxIndexesExceeded"; })(StorageVectorsErrorCode || (StorageVectorsErrorCode = {})); } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/helpers.js var resolveFetch3, resolveResponse2, isPlainObject2, normalizeToFloat32, validateVectorDimension; var init_helpers2 = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/helpers.js"() { resolveFetch3 = (customFetch) => { if (customFetch) { return (...args) => customFetch(...args); } return (...args) => fetch(...args); }; resolveResponse2 = () => { return Response; }; isPlainObject2 = (value) => { if (typeof value !== "object" || value === null) { return false; } const prototype = Object.getPrototypeOf(value); return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value); }; normalizeToFloat32 = (values) => { return Array.from(new Float32Array(values)); }; validateVectorDimension = (vector, expectedDimension) => { if (expectedDimension !== void 0 && vector.float32.length !== expectedDimension) { throw new Error(`Vector dimension mismatch: expected ${expectedDimension}, got ${vector.float32.length}`); } }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/fetch.js function _handleRequest2(fetcher, method, url, options, parameters, body) { return __awaiter(this, void 0, void 0, function* () { return new Promise((resolve, reject) => { fetcher(url, _getRequestParams2(method, options, parameters, body)).then((result) => { if (!result.ok) throw result; if (options === null || options === void 0 ? void 0 : options.noResolveJson) return result; const contentType = result.headers.get("content-type"); if (!contentType || !contentType.includes("application/json")) { return {}; } return result.json(); }).then((data) => resolve(data)).catch((error) => handleError2(error, reject, options)); }); }); } function post2(fetcher, url, body, options, parameters) { return __awaiter(this, void 0, void 0, function* () { return _handleRequest2(fetcher, "POST", url, options, parameters, body); }); } var _getErrorMessage2, handleError2, _getRequestParams2; var init_fetch2 = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/fetch.js"() { init_tslib_es6(); init_errors2(); init_helpers2(); _getErrorMessage2 = (err) => err.msg || err.message || err.error_description || err.error || JSON.stringify(err); handleError2 = (error, reject, options) => __awaiter(void 0, void 0, void 0, function* () { const isResponseLike = error && typeof error === "object" && "status" in error && "ok" in error && typeof error.status === "number"; if (isResponseLike && !(options === null || options === void 0 ? void 0 : options.noResolveJson)) { const status = error.status || 500; const responseError = error; if (typeof responseError.json === "function") { responseError.json().then((err) => { const statusCode = (err === null || err === void 0 ? void 0 : err.statusCode) || (err === null || err === void 0 ? void 0 : err.code) || status + ""; reject(new StorageVectorsApiError(_getErrorMessage2(err), status, statusCode)); }).catch(() => { const statusCode = status + ""; const message = responseError.statusText || `HTTP ${status} error`; reject(new StorageVectorsApiError(message, status, statusCode)); }); } else { const statusCode = status + ""; const message = responseError.statusText || `HTTP ${status} error`; reject(new StorageVectorsApiError(message, status, statusCode)); } } else { reject(new StorageVectorsUnknownError(_getErrorMessage2(error), error)); } }); _getRequestParams2 = (method, options, parameters, body) => { const params = { method, headers: (options === null || options === void 0 ? void 0 : options.headers) || {} }; if (method === "GET" || !body) { return params; } if (isPlainObject2(body)) { params.headers = Object.assign({ "Content-Type": "application/json" }, options === null || options === void 0 ? void 0 : options.headers); params.body = JSON.stringify(body); } else { params.body = body; } return Object.assign(Object.assign({}, params), parameters); }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/VectorIndexApi.js var VectorIndexApi; var init_VectorIndexApi = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/VectorIndexApi.js"() { init_tslib_es6(); init_constants3(); init_errors2(); init_fetch2(); init_helpers2(); VectorIndexApi = class { /** Creates a new VectorIndexApi instance */ constructor(url, headers = {}, fetch2) { this.shouldThrowOnError = false; this.url = url.replace(/\/$/, ""); this.headers = Object.assign(Object.assign({}, DEFAULT_HEADERS2), headers); this.fetch = resolveFetch3(fetch2); } /** Enable throwing errors instead of returning them in the response */ throwOnError() { this.shouldThrowOnError = true; return this; } /** Creates a new vector index within a bucket */ createIndex(options) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield post2(this.fetch, `${this.url}/CreateIndex`, options, { headers: this.headers }); return { data: data || {}, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageVectorsError(error)) { return { data: null, error }; } throw error; } }); } /** Retrieves metadata for a specific vector index */ getIndex(vectorBucketName, indexName) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield post2(this.fetch, `${this.url}/GetIndex`, { vectorBucketName, indexName }, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageVectorsError(error)) { return { data: null, error }; } throw error; } }); } /** Lists vector indexes within a bucket with optional filtering and pagination */ listIndexes(options) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield post2(this.fetch, `${this.url}/ListIndexes`, options, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageVectorsError(error)) { return { data: null, error }; } throw error; } }); } /** Deletes a vector index and all its data */ deleteIndex(vectorBucketName, indexName) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield post2(this.fetch, `${this.url}/DeleteIndex`, { vectorBucketName, indexName }, { headers: this.headers }); return { data: data || {}, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageVectorsError(error)) { return { data: null, error }; } throw error; } }); } }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/VectorDataApi.js var VectorDataApi; var init_VectorDataApi = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/VectorDataApi.js"() { init_tslib_es6(); init_constants3(); init_errors2(); init_fetch2(); init_helpers2(); VectorDataApi = class { /** Creates a new VectorDataApi instance */ constructor(url, headers = {}, fetch2) { this.shouldThrowOnError = false; this.url = url.replace(/\/$/, ""); this.headers = Object.assign(Object.assign({}, DEFAULT_HEADERS2), headers); this.fetch = resolveFetch3(fetch2); } /** Enable throwing errors instead of returning them in the response */ throwOnError() { this.shouldThrowOnError = true; return this; } /** Inserts or updates vectors in batch (1-500 per request) */ putVectors(options) { return __awaiter(this, void 0, void 0, function* () { try { if (options.vectors.length < 1 || options.vectors.length > 500) { throw new Error("Vector batch size must be between 1 and 500 items"); } const data = yield post2(this.fetch, `${this.url}/PutVectors`, options, { headers: this.headers }); return { data: data || {}, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageVectorsError(error)) { return { data: null, error }; } throw error; } }); } /** Retrieves vectors by their keys in batch */ getVectors(options) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield post2(this.fetch, `${this.url}/GetVectors`, options, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageVectorsError(error)) { return { data: null, error }; } throw error; } }); } /** Lists vectors in an index with pagination */ listVectors(options) { return __awaiter(this, void 0, void 0, function* () { try { if (options.segmentCount !== void 0) { if (options.segmentCount < 1 || options.segmentCount > 16) { throw new Error("segmentCount must be between 1 and 16"); } if (options.segmentIndex !== void 0) { if (options.segmentIndex < 0 || options.segmentIndex >= options.segmentCount) { throw new Error(`segmentIndex must be between 0 and ${options.segmentCount - 1}`); } } } const data = yield post2(this.fetch, `${this.url}/ListVectors`, options, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageVectorsError(error)) { return { data: null, error }; } throw error; } }); } /** Queries for similar vectors using approximate nearest neighbor search */ queryVectors(options) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield post2(this.fetch, `${this.url}/QueryVectors`, options, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageVectorsError(error)) { return { data: null, error }; } throw error; } }); } /** Deletes vectors by their keys in batch (1-500 per request) */ deleteVectors(options) { return __awaiter(this, void 0, void 0, function* () { try { if (options.keys.length < 1 || options.keys.length > 500) { throw new Error("Keys batch size must be between 1 and 500 items"); } const data = yield post2(this.fetch, `${this.url}/DeleteVectors`, options, { headers: this.headers }); return { data: data || {}, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageVectorsError(error)) { return { data: null, error }; } throw error; } }); } }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/VectorBucketApi.js var VectorBucketApi; var init_VectorBucketApi = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/VectorBucketApi.js"() { init_tslib_es6(); init_constants3(); init_errors2(); init_fetch2(); init_helpers2(); VectorBucketApi = class { /** Creates a new VectorBucketApi instance */ constructor(url, headers = {}, fetch2) { this.shouldThrowOnError = false; this.url = url.replace(/\/$/, ""); this.headers = Object.assign(Object.assign({}, DEFAULT_HEADERS2), headers); this.fetch = resolveFetch3(fetch2); } /** Enable throwing errors instead of returning them in the response */ throwOnError() { this.shouldThrowOnError = true; return this; } /** Creates a new vector bucket */ createBucket(vectorBucketName) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield post2(this.fetch, `${this.url}/CreateVectorBucket`, { vectorBucketName }, { headers: this.headers }); return { data: data || {}, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageVectorsError(error)) { return { data: null, error }; } throw error; } }); } /** Retrieves metadata for a specific vector bucket */ getBucket(vectorBucketName) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield post2(this.fetch, `${this.url}/GetVectorBucket`, { vectorBucketName }, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageVectorsError(error)) { return { data: null, error }; } throw error; } }); } /** Lists vector buckets with optional filtering and pagination */ listBuckets() { return __awaiter(this, arguments, void 0, function* (options = {}) { try { const data = yield post2(this.fetch, `${this.url}/ListVectorBuckets`, options, { headers: this.headers }); return { data, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageVectorsError(error)) { return { data: null, error }; } throw error; } }); } /** Deletes a vector bucket (must be empty first) */ deleteBucket(vectorBucketName) { return __awaiter(this, void 0, void 0, function* () { try { const data = yield post2(this.fetch, `${this.url}/DeleteVectorBucket`, { vectorBucketName }, { headers: this.headers }); return { data: data || {}, error: null }; } catch (error) { if (this.shouldThrowOnError) { throw error; } if (isStorageVectorsError(error)) { return { data: null, error }; } throw error; } }); } }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/StorageVectorsClient.js var StorageVectorsClient, VectorBucketScope, VectorIndexScope; var init_StorageVectorsClient = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/StorageVectorsClient.js"() { init_tslib_es6(); init_VectorIndexApi(); init_VectorDataApi(); init_VectorBucketApi(); StorageVectorsClient = class extends VectorBucketApi { /** * @alpha * * Creates a StorageVectorsClient that can manage buckets, indexes, and vectors. * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param url - Base URL of the Storage Vectors REST API. * @param options.headers - Optional headers (for example `Authorization`) applied to every request. * @param options.fetch - Optional custom `fetch` implementation for non-browser runtimes. * * @example * ```typescript * const client = new StorageVectorsClient(url, options) * ``` */ constructor(url, options = {}) { super(url, options.headers || {}, options.fetch); } /** * * @alpha * * Access operations for a specific vector bucket * Returns a scoped client for index and vector operations within the bucket * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param vectorBucketName - Name of the vector bucket * @returns Bucket-scoped client with index and vector operations * * @example * ```typescript * const bucket = supabase.storage.vectors.from('embeddings-prod') * ``` */ from(vectorBucketName) { return new VectorBucketScope(this.url, this.headers, vectorBucketName, this.fetch); } /** * * @alpha * * Creates a new vector bucket * Vector buckets are containers for vector indexes and their data * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param vectorBucketName - Unique name for the vector bucket * @returns Promise with empty response on success or error * * @example * ```typescript * const { data, error } = await supabase * .storage * .vectors * .createBucket('embeddings-prod') * ``` */ createBucket(vectorBucketName) { const _super = Object.create(null, { createBucket: { get: () => super.createBucket } }); return __awaiter(this, void 0, void 0, function* () { return _super.createBucket.call(this, vectorBucketName); }); } /** * * @alpha * * Retrieves metadata for a specific vector bucket * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param vectorBucketName - Name of the vector bucket * @returns Promise with bucket metadata or error * * @example * ```typescript * const { data, error } = await supabase * .storage * .vectors * .getBucket('embeddings-prod') * * console.log('Bucket created:', data?.vectorBucket.creationTime) * ``` */ getBucket(vectorBucketName) { const _super = Object.create(null, { getBucket: { get: () => super.getBucket } }); return __awaiter(this, void 0, void 0, function* () { return _super.getBucket.call(this, vectorBucketName); }); } /** * * @alpha * * Lists all vector buckets with optional filtering and pagination * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param options - Optional filters (prefix, maxResults, nextToken) * @returns Promise with list of buckets or error * * @example * ```typescript * const { data, error } = await supabase * .storage * .vectors * .listBuckets({ prefix: 'embeddings-' }) * * data?.vectorBuckets.forEach(bucket => { * console.log(bucket.vectorBucketName) * }) * ``` */ listBuckets() { const _super = Object.create(null, { listBuckets: { get: () => super.listBuckets } }); return __awaiter(this, arguments, void 0, function* (options = {}) { return _super.listBuckets.call(this, options); }); } /** * * @alpha * * Deletes a vector bucket (bucket must be empty) * All indexes must be deleted before deleting the bucket * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param vectorBucketName - Name of the vector bucket to delete * @returns Promise with empty response on success or error * * @example * ```typescript * const { data, error } = await supabase * .storage * .vectors * .deleteBucket('embeddings-old') * ``` */ deleteBucket(vectorBucketName) { const _super = Object.create(null, { deleteBucket: { get: () => super.deleteBucket } }); return __awaiter(this, void 0, void 0, function* () { return _super.deleteBucket.call(this, vectorBucketName); }); } }; VectorBucketScope = class extends VectorIndexApi { /** * @alpha * * Creates a helper that automatically scopes all index operations to the provided bucket. * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @example * ```typescript * const bucket = supabase.storage.vectors.from('embeddings-prod') * ``` */ constructor(url, headers, vectorBucketName, fetch2) { super(url, headers, fetch2); this.vectorBucketName = vectorBucketName; } /** * * @alpha * * Creates a new vector index in this bucket * Convenience method that automatically includes the bucket name * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param options - Index configuration (vectorBucketName is automatically set) * @returns Promise with empty response on success or error * * @example * ```typescript * const bucket = supabase.storage.vectors.from('embeddings-prod') * await bucket.createIndex({ * indexName: 'documents-openai', * dataType: 'float32', * dimension: 1536, * distanceMetric: 'cosine', * metadataConfiguration: { * nonFilterableMetadataKeys: ['raw_text'] * } * }) * ``` */ createIndex(options) { const _super = Object.create(null, { createIndex: { get: () => super.createIndex } }); return __awaiter(this, void 0, void 0, function* () { return _super.createIndex.call(this, Object.assign(Object.assign({}, options), { vectorBucketName: this.vectorBucketName })); }); } /** * * @alpha * * Lists indexes in this bucket * Convenience method that automatically includes the bucket name * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param options - Listing options (vectorBucketName is automatically set) * @returns Promise with response containing indexes array and pagination token or error * * @example * ```typescript * const bucket = supabase.storage.vectors.from('embeddings-prod') * const { data } = await bucket.listIndexes({ prefix: 'documents-' }) * ``` */ listIndexes() { const _super = Object.create(null, { listIndexes: { get: () => super.listIndexes } }); return __awaiter(this, arguments, void 0, function* (options = {}) { return _super.listIndexes.call(this, Object.assign(Object.assign({}, options), { vectorBucketName: this.vectorBucketName })); }); } /** * * @alpha * * Retrieves metadata for a specific index in this bucket * Convenience method that automatically includes the bucket name * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param indexName - Name of the index to retrieve * @returns Promise with index metadata or error * * @example * ```typescript * const bucket = supabase.storage.vectors.from('embeddings-prod') * const { data } = await bucket.getIndex('documents-openai') * console.log('Dimension:', data?.index.dimension) * ``` */ getIndex(indexName) { const _super = Object.create(null, { getIndex: { get: () => super.getIndex } }); return __awaiter(this, void 0, void 0, function* () { return _super.getIndex.call(this, this.vectorBucketName, indexName); }); } /** * * @alpha * * Deletes an index from this bucket * Convenience method that automatically includes the bucket name * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param indexName - Name of the index to delete * @returns Promise with empty response on success or error * * @example * ```typescript * const bucket = supabase.storage.vectors.from('embeddings-prod') * await bucket.deleteIndex('old-index') * ``` */ deleteIndex(indexName) { const _super = Object.create(null, { deleteIndex: { get: () => super.deleteIndex } }); return __awaiter(this, void 0, void 0, function* () { return _super.deleteIndex.call(this, this.vectorBucketName, indexName); }); } /** * * @alpha * * Access operations for a specific index within this bucket * Returns a scoped client for vector data operations * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param indexName - Name of the index * @returns Index-scoped client with vector data operations * * @example * ```typescript * const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai') * * // Insert vectors * await index.putVectors({ * vectors: [ * { key: 'doc-1', data: { float32: [...] }, metadata: { title: 'Intro' } } * ] * }) * * // Query similar vectors * const { data } = await index.queryVectors({ * queryVector: { float32: [...] }, * topK: 5 * }) * ``` */ index(indexName) { return new VectorIndexScope(this.url, this.headers, this.vectorBucketName, indexName, this.fetch); } }; VectorIndexScope = class extends VectorDataApi { /** * * @alpha * * Creates a helper that automatically scopes all vector operations to the provided bucket/index names. * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @example * ```typescript * const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai') * ``` */ constructor(url, headers, vectorBucketName, indexName, fetch2) { super(url, headers, fetch2); this.vectorBucketName = vectorBucketName; this.indexName = indexName; } /** * * @alpha * * Inserts or updates vectors in this index * Convenience method that automatically includes bucket and index names * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param options - Vector insertion options (bucket and index names automatically set) * @returns Promise with empty response on success or error * * @example * ```typescript * const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai') * await index.putVectors({ * vectors: [ * { * key: 'doc-1', * data: { float32: [0.1, 0.2, ...] }, * metadata: { title: 'Introduction', page: 1 } * } * ] * }) * ``` */ putVectors(options) { const _super = Object.create(null, { putVectors: { get: () => super.putVectors } }); return __awaiter(this, void 0, void 0, function* () { return _super.putVectors.call(this, Object.assign(Object.assign({}, options), { vectorBucketName: this.vectorBucketName, indexName: this.indexName })); }); } /** * * @alpha * * Retrieves vectors by keys from this index * Convenience method that automatically includes bucket and index names * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param options - Vector retrieval options (bucket and index names automatically set) * @returns Promise with response containing vectors array or error * * @example * ```typescript * const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai') * const { data } = await index.getVectors({ * keys: ['doc-1', 'doc-2'], * returnMetadata: true * }) * ``` */ getVectors(options) { const _super = Object.create(null, { getVectors: { get: () => super.getVectors } }); return __awaiter(this, void 0, void 0, function* () { return _super.getVectors.call(this, Object.assign(Object.assign({}, options), { vectorBucketName: this.vectorBucketName, indexName: this.indexName })); }); } /** * * @alpha * * Lists vectors in this index with pagination * Convenience method that automatically includes bucket and index names * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param options - Listing options (bucket and index names automatically set) * @returns Promise with response containing vectors array and pagination token or error * * @example * ```typescript * const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai') * const { data } = await index.listVectors({ * maxResults: 500, * returnMetadata: true * }) * ``` */ listVectors() { const _super = Object.create(null, { listVectors: { get: () => super.listVectors } }); return __awaiter(this, arguments, void 0, function* (options = {}) { return _super.listVectors.call(this, Object.assign(Object.assign({}, options), { vectorBucketName: this.vectorBucketName, indexName: this.indexName })); }); } /** * * @alpha * * Queries for similar vectors in this index * Convenience method that automatically includes bucket and index names * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param options - Query options (bucket and index names automatically set) * @returns Promise with response containing matches array of similar vectors ordered by distance or error * * @example * ```typescript * const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai') * const { data } = await index.queryVectors({ * queryVector: { float32: [0.1, 0.2, ...] }, * topK: 5, * filter: { category: 'technical' }, * returnDistance: true, * returnMetadata: true * }) * ``` */ queryVectors(options) { const _super = Object.create(null, { queryVectors: { get: () => super.queryVectors } }); return __awaiter(this, void 0, void 0, function* () { return _super.queryVectors.call(this, Object.assign(Object.assign({}, options), { vectorBucketName: this.vectorBucketName, indexName: this.indexName })); }); } /** * * @alpha * * Deletes vectors by keys from this index * Convenience method that automatically includes bucket and index names * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @param options - Deletion options (bucket and index names automatically set) * @returns Promise with empty response on success or error * * @example * ```typescript * const index = supabase.storage.vectors.from('embeddings-prod').index('documents-openai') * await index.deleteVectors({ * keys: ['doc-1', 'doc-2', 'doc-3'] * }) * ``` */ deleteVectors(options) { const _super = Object.create(null, { deleteVectors: { get: () => super.deleteVectors } }); return __awaiter(this, void 0, void 0, function* () { return _super.deleteVectors.call(this, Object.assign(Object.assign({}, options), { vectorBucketName: this.vectorBucketName, indexName: this.indexName })); }); } }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/index.js var init_vectors = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/vectors/index.js"() { init_StorageVectorsClient(); init_VectorBucketApi(); init_VectorIndexApi(); init_VectorDataApi(); init_errors2(); init_helpers2(); } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/StorageClient.js var StorageClient; var init_StorageClient = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/StorageClient.js"() { init_StorageFileApi(); init_StorageBucketApi(); init_StorageAnalyticsClient(); init_vectors(); StorageClient = class extends StorageBucketApi { /** * Creates a client for Storage buckets, files, analytics, and vectors. * * @category File Buckets * @example * ```ts * import { StorageClient } from '@supabase/storage-js' * * const storage = new StorageClient('https://xyzcompany.supabase.co/storage/v1', { * apikey: 'public-anon-key', * }) * const avatars = storage.from('avatars') * ``` */ constructor(url, headers = {}, fetch2, opts) { super(url, headers, fetch2, opts); } /** * Perform file operation in a bucket. * * @category File Buckets * @param id The bucket id to operate on. * * @example * ```typescript * const avatars = supabase.storage.from('avatars') * ``` */ from(id) { return new StorageFileApi(this.url, this.headers, id, this.fetch); } /** * * @alpha * * Access vector storage operations. * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Vector Buckets * @returns A StorageVectorsClient instance configured with the current storage settings. */ get vectors() { return new StorageVectorsClient(this.url + "/vector", { headers: this.headers, fetch: this.fetch }); } /** * * @alpha * * Access analytics storage operations using Iceberg tables. * * **Public alpha:** This API is part of a public alpha release and may not be available to your account type. * * @category Analytics Buckets * @returns A StorageAnalyticsClient instance configured with the current storage settings. */ get analytics() { return new StorageAnalyticsClient(this.url + "/iceberg", this.headers, this.fetch); } }; } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/types.js var init_types2 = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/lib/types.js"() { } }); // ../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/index.js var module_exports3 = {}; __export(module_exports3, { StorageAnalyticsClient: () => StorageAnalyticsClient, StorageApiError: () => StorageApiError, StorageClient: () => StorageClient, StorageError: () => StorageError, StorageUnknownError: () => StorageUnknownError, StorageVectorsApiError: () => StorageVectorsApiError, StorageVectorsClient: () => StorageVectorsClient, StorageVectorsError: () => StorageVectorsError, StorageVectorsErrorCode: () => StorageVectorsErrorCode, StorageVectorsUnknownError: () => StorageVectorsUnknownError, VectorBucketApi: () => VectorBucketApi, VectorBucketScope: () => VectorBucketScope, VectorDataApi: () => VectorDataApi, VectorIndexApi: () => VectorIndexApi, VectorIndexScope: () => VectorIndexScope, isPlainObject: () => isPlainObject2, isStorageError: () => isStorageError, isStorageVectorsError: () => isStorageVectorsError, normalizeToFloat32: () => normalizeToFloat32, resolveFetch: () => resolveFetch3, resolveResponse: () => resolveResponse2, validateVectorDimension: () => validateVectorDimension }); var init_module3 = __esm({ "../../node_modules/.pnpm/@supabase+storage-js@2.86.2/node_modules/@supabase/storage-js/dist/module/index.js"() { init_StorageClient(); init_StorageAnalyticsClient(); init_types2(); init_errors(); init_vectors(); } }); // ../../node_modules/.pnpm/@supabase+supabase-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/supabase-js/dist/main/lib/version.js var require_version = __commonJS({ "../../node_modules/.pnpm/@supabase+supabase-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/supabase-js/dist/main/lib/version.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.version = void 0; exports.version = "2.86.2"; } }); // ../../node_modules/.pnpm/@supabase+supabase-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/supabase-js/dist/main/lib/constants.js var require_constants = __commonJS({ "../../node_modules/.pnpm/@supabase+supabase-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/supabase-js/dist/main/lib/constants.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DEFAULT_REALTIME_OPTIONS = exports.DEFAULT_AUTH_OPTIONS = exports.DEFAULT_DB_OPTIONS = exports.DEFAULT_GLOBAL_OPTIONS = exports.DEFAULT_HEADERS = void 0; var version_1 = require_version(); var JS_ENV = ""; if (typeof Deno !== "undefined") { JS_ENV = "deno"; } else if (typeof document !== "undefined") { JS_ENV = "web"; } else if (typeof navigator !== "undefined" && navigator.product === "ReactNative") { JS_ENV = "react-native"; } else { JS_ENV = "node"; } exports.DEFAULT_HEADERS = { "X-Client-Info": `supabase-js-${JS_ENV}/${version_1.version}` }; exports.DEFAULT_GLOBAL_OPTIONS = { headers: exports.DEFAULT_HEADERS }; exports.DEFAULT_DB_OPTIONS = { schema: "public" }; exports.DEFAULT_AUTH_OPTIONS = { autoRefreshToken: true, persistSession: true, detectSessionInUrl: true, flowType: "implicit" }; exports.DEFAULT_REALTIME_OPTIONS = {}; } }); // ../../node_modules/.pnpm/@supabase+supabase-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/supabase-js/dist/main/lib/fetch.js var require_fetch = __commonJS({ "../../node_modules/.pnpm/@supabase+supabase-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/supabase-js/dist/main/lib/fetch.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fetchWithAuth = exports.resolveHeadersConstructor = exports.resolveFetch = void 0; var resolveFetch5 = (customFetch) => { if (customFetch) { return (...args) => customFetch(...args); } return (...args) => fetch(...args); }; exports.resolveFetch = resolveFetch5; var resolveHeadersConstructor = () => { return Headers; }; exports.resolveHeadersConstructor = resolveHeadersConstructor; var fetchWithAuth = (supabaseKey, getAccessToken, customFetch) => { const fetch2 = (0, exports.resolveFetch)(customFetch); const HeadersConstructor = (0, exports.resolveHeadersConstructor)(); return async (input, init) => { var _a2; const accessToken = (_a2 = await getAccessToken()) !== null && _a2 !== void 0 ? _a2 : supabaseKey; let headers = new HeadersConstructor(init === null || init === void 0 ? void 0 : init.headers); if (!headers.has("apikey")) { headers.set("apikey", supabaseKey); } if (!headers.has("Authorization")) { headers.set("Authorization", `Bearer ${accessToken}`); } return fetch2(input, Object.assign(Object.assign({}, init), { headers })); }; }; exports.fetchWithAuth = fetchWithAuth; } }); // ../../node_modules/.pnpm/@supabase+supabase-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/supabase-js/dist/main/lib/helpers.js var require_helpers = __commonJS({ "../../node_modules/.pnpm/@supabase+supabase-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/supabase-js/dist/main/lib/helpers.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isBrowser = void 0; exports.uuid = uuid; exports.ensureTrailingSlash = ensureTrailingSlash; exports.applySettingDefaults = applySettingDefaults; exports.validateSupabaseUrl = validateSupabaseUrl; function uuid() { return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) { var r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8; return v.toString(16); }); } function ensureTrailingSlash(url) { return url.endsWith("/") ? url : url + "/"; } var isBrowser2 = () => typeof window !== "undefined"; exports.isBrowser = isBrowser2; function applySettingDefaults(options, defaults) { var _a2, _b; const { db: dbOptions, auth: authOptions, realtime: realtimeOptions, global: globalOptions } = options; const { db: DEFAULT_DB_OPTIONS, auth: DEFAULT_AUTH_OPTIONS, realtime: DEFAULT_REALTIME_OPTIONS, global: DEFAULT_GLOBAL_OPTIONS } = defaults; const result = { db: Object.assign(Object.assign({}, DEFAULT_DB_OPTIONS), dbOptions), auth: Object.assign(Object.assign({}, DEFAULT_AUTH_OPTIONS), authOptions), realtime: Object.assign(Object.assign({}, DEFAULT_REALTIME_OPTIONS), realtimeOptions), storage: {}, global: Object.assign(Object.assign(Object.assign({}, DEFAULT_GLOBAL_OPTIONS), globalOptions), { headers: Object.assign(Object.assign({}, (_a2 = DEFAULT_GLOBAL_OPTIONS === null || DEFAULT_GLOBAL_OPTIONS === void 0 ? void 0 : DEFAULT_GLOBAL_OPTIONS.headers) !== null && _a2 !== void 0 ? _a2 : {}), (_b = globalOptions === null || globalOptions === void 0 ? void 0 : globalOptions.headers) !== null && _b !== void 0 ? _b : {}) }), accessToken: async () => "" }; if (options.accessToken) { result.accessToken = options.accessToken; } else { delete result.accessToken; } return result; } function validateSupabaseUrl(supabaseUrl) { const trimmedUrl = supabaseUrl === null || supabaseUrl === void 0 ? void 0 : supabaseUrl.trim(); if (!trimmedUrl) { throw new Error("supabaseUrl is required."); } if (!trimmedUrl.match(/^https?:\/\//i)) { throw new Error("Invalid supabaseUrl: Must be a valid HTTP or HTTPS URL."); } try { return new URL(ensureTrailingSlash(trimmedUrl)); } catch (_a2) { throw Error("Invalid supabaseUrl: Provided URL is malformed."); } } } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/version.js var version3; var init_version3 = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/version.js"() { version3 = "2.86.2"; } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/constants.js var AUTO_REFRESH_TICK_DURATION_MS, AUTO_REFRESH_TICK_THRESHOLD, EXPIRY_MARGIN_MS, GOTRUE_URL, STORAGE_KEY, DEFAULT_HEADERS3, API_VERSION_HEADER_NAME, API_VERSIONS, BASE64URL_REGEX, JWKS_TTL; var init_constants4 = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/constants.js"() { init_version3(); AUTO_REFRESH_TICK_DURATION_MS = 30 * 1e3; AUTO_REFRESH_TICK_THRESHOLD = 3; EXPIRY_MARGIN_MS = AUTO_REFRESH_TICK_THRESHOLD * AUTO_REFRESH_TICK_DURATION_MS; GOTRUE_URL = "http://localhost:9999"; STORAGE_KEY = "supabase.auth.token"; DEFAULT_HEADERS3 = { "X-Client-Info": `gotrue-js/${version3}` }; API_VERSION_HEADER_NAME = "X-Supabase-Api-Version"; API_VERSIONS = { "2024-01-01": { timestamp: Date.parse("2024-01-01T00:00:00.0Z"), name: "2024-01-01" } }; BASE64URL_REGEX = /^([a-z0-9_-]{4})*($|[a-z0-9_-]{3}$|[a-z0-9_-]{2}$)$/i; JWKS_TTL = 10 * 60 * 1e3; } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/errors.js function isAuthError(error) { return typeof error === "object" && error !== null && "__isAuthError" in error; } function isAuthApiError(error) { return isAuthError(error) && error.name === "AuthApiError"; } function isAuthSessionMissingError(error) { return isAuthError(error) && error.name === "AuthSessionMissingError"; } function isAuthImplicitGrantRedirectError(error) { return isAuthError(error) && error.name === "AuthImplicitGrantRedirectError"; } function isAuthRetryableFetchError(error) { return isAuthError(error) && error.name === "AuthRetryableFetchError"; } function isAuthWeakPasswordError(error) { return isAuthError(error) && error.name === "AuthWeakPasswordError"; } var AuthError, AuthApiError, AuthUnknownError, CustomAuthError, AuthSessionMissingError, AuthInvalidTokenResponseError, AuthInvalidCredentialsError, AuthImplicitGrantRedirectError, AuthPKCEGrantCodeExchangeError, AuthRetryableFetchError, AuthWeakPasswordError, AuthInvalidJwtError; var init_errors3 = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/errors.js"() { AuthError = class extends Error { constructor(message, status, code) { super(message); this.__isAuthError = true; this.name = "AuthError"; this.status = status; this.code = code; } }; AuthApiError = class extends AuthError { constructor(message, status, code) { super(message, status, code); this.name = "AuthApiError"; this.status = status; this.code = code; } }; AuthUnknownError = class extends AuthError { constructor(message, originalError) { super(message); this.name = "AuthUnknownError"; this.originalError = originalError; } }; CustomAuthError = class extends AuthError { constructor(message, name, status, code) { super(message, status, code); this.name = name; this.status = status; } }; AuthSessionMissingError = class extends CustomAuthError { constructor() { super("Auth session missing!", "AuthSessionMissingError", 400, void 0); } }; AuthInvalidTokenResponseError = class extends CustomAuthError { constructor() { super("Auth session or user missing", "AuthInvalidTokenResponseError", 500, void 0); } }; AuthInvalidCredentialsError = class extends CustomAuthError { constructor(message) { super(message, "AuthInvalidCredentialsError", 400, void 0); } }; AuthImplicitGrantRedirectError = class extends CustomAuthError { constructor(message, details = null) { super(message, "AuthImplicitGrantRedirectError", 500, void 0); this.details = null; this.details = details; } toJSON() { return { name: this.name, message: this.message, status: this.status, details: this.details }; } }; AuthPKCEGrantCodeExchangeError = class extends CustomAuthError { constructor(message, details = null) { super(message, "AuthPKCEGrantCodeExchangeError", 500, void 0); this.details = null; this.details = details; } toJSON() { return { name: this.name, message: this.message, status: this.status, details: this.details }; } }; AuthRetryableFetchError = class extends CustomAuthError { constructor(message, status) { super(message, "AuthRetryableFetchError", status, void 0); } }; AuthWeakPasswordError = class extends CustomAuthError { constructor(message, status, reasons) { super(message, "AuthWeakPasswordError", status, "weak_password"); this.reasons = reasons; } }; AuthInvalidJwtError = class extends CustomAuthError { constructor(message) { super(message, "AuthInvalidJwtError", 400, "invalid_jwt"); } }; } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/base64url.js function byteToBase64URL(byte, state, emit) { if (byte !== null) { state.queue = state.queue << 8 | byte; state.queuedBits += 8; while (state.queuedBits >= 6) { const pos = state.queue >> state.queuedBits - 6 & 63; emit(TO_BASE64URL[pos]); state.queuedBits -= 6; } } else if (state.queuedBits > 0) { state.queue = state.queue << 6 - state.queuedBits; state.queuedBits = 6; while (state.queuedBits >= 6) { const pos = state.queue >> state.queuedBits - 6 & 63; emit(TO_BASE64URL[pos]); state.queuedBits -= 6; } } } function byteFromBase64URL(charCode, state, emit) { const bits = FROM_BASE64URL[charCode]; if (bits > -1) { state.queue = state.queue << 6 | bits; state.queuedBits += 6; while (state.queuedBits >= 8) { emit(state.queue >> state.queuedBits - 8 & 255); state.queuedBits -= 8; } } else if (bits === -2) { return; } else { throw new Error(`Invalid Base64-URL character "${String.fromCharCode(charCode)}"`); } } function stringFromBase64URL(str) { const conv = []; const utf8Emit = (codepoint) => { conv.push(String.fromCodePoint(codepoint)); }; const utf8State = { utf8seq: 0, codepoint: 0 }; const b64State = { queue: 0, queuedBits: 0 }; const byteEmit = (byte) => { stringFromUTF8(byte, utf8State, utf8Emit); }; for (let i = 0; i < str.length; i += 1) { byteFromBase64URL(str.charCodeAt(i), b64State, byteEmit); } return conv.join(""); } function codepointToUTF8(codepoint, emit) { if (codepoint <= 127) { emit(codepoint); return; } else if (codepoint <= 2047) { emit(192 | codepoint >> 6); emit(128 | codepoint & 63); return; } else if (codepoint <= 65535) { emit(224 | codepoint >> 12); emit(128 | codepoint >> 6 & 63); emit(128 | codepoint & 63); return; } else if (codepoint <= 1114111) { emit(240 | codepoint >> 18); emit(128 | codepoint >> 12 & 63); emit(128 | codepoint >> 6 & 63); emit(128 | codepoint & 63); return; } throw new Error(`Unrecognized Unicode codepoint: ${codepoint.toString(16)}`); } function stringToUTF8(str, emit) { for (let i = 0; i < str.length; i += 1) { let codepoint = str.charCodeAt(i); if (codepoint > 55295 && codepoint <= 56319) { const highSurrogate = (codepoint - 55296) * 1024 & 65535; const lowSurrogate = str.charCodeAt(i + 1) - 56320 & 65535; codepoint = (lowSurrogate | highSurrogate) + 65536; i += 1; } codepointToUTF8(codepoint, emit); } } function stringFromUTF8(byte, state, emit) { if (state.utf8seq === 0) { if (byte <= 127) { emit(byte); return; } for (let leadingBit = 1; leadingBit < 6; leadingBit += 1) { if ((byte >> 7 - leadingBit & 1) === 0) { state.utf8seq = leadingBit; break; } } if (state.utf8seq === 2) { state.codepoint = byte & 31; } else if (state.utf8seq === 3) { state.codepoint = byte & 15; } else if (state.utf8seq === 4) { state.codepoint = byte & 7; } else { throw new Error("Invalid UTF-8 sequence"); } state.utf8seq -= 1; } else if (state.utf8seq > 0) { if (byte <= 127) { throw new Error("Invalid UTF-8 sequence"); } state.codepoint = state.codepoint << 6 | byte & 63; state.utf8seq -= 1; if (state.utf8seq === 0) { emit(state.codepoint); } } } function base64UrlToUint8Array(str) { const result = []; const state = { queue: 0, queuedBits: 0 }; const onByte = (byte) => { result.push(byte); }; for (let i = 0; i < str.length; i += 1) { byteFromBase64URL(str.charCodeAt(i), state, onByte); } return new Uint8Array(result); } function stringToUint8Array(str) { const result = []; stringToUTF8(str, (byte) => result.push(byte)); return new Uint8Array(result); } function bytesToBase64URL(bytes) { const result = []; const state = { queue: 0, queuedBits: 0 }; const onChar = (char) => { result.push(char); }; bytes.forEach((byte) => byteToBase64URL(byte, state, onChar)); byteToBase64URL(null, state, onChar); return result.join(""); } var TO_BASE64URL, IGNORE_BASE64URL, FROM_BASE64URL; var init_base64url = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/base64url.js"() { TO_BASE64URL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".split(""); IGNORE_BASE64URL = " \n\r=".split(""); FROM_BASE64URL = (() => { const charMap = new Array(128); for (let i = 0; i < charMap.length; i += 1) { charMap[i] = -1; } for (let i = 0; i < IGNORE_BASE64URL.length; i += 1) { charMap[IGNORE_BASE64URL[i].charCodeAt(0)] = -2; } for (let i = 0; i < TO_BASE64URL.length; i += 1) { charMap[TO_BASE64URL[i].charCodeAt(0)] = i; } return charMap; })(); } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/helpers.js function expiresAt(expiresIn) { const timeNow = Math.round(Date.now() / 1e3); return timeNow + expiresIn; } function generateCallbackId() { return Symbol("auth-callback"); } function parseParametersFromURL(href) { const result = {}; const url = new URL(href); if (url.hash && url.hash[0] === "#") { try { const hashSearchParams = new URLSearchParams(url.hash.substring(1)); hashSearchParams.forEach((value, key) => { result[key] = value; }); } catch (e) { } } url.searchParams.forEach((value, key) => { result[key] = value; }); return result; } function decodeJWT(token) { const parts = token.split("."); if (parts.length !== 3) { throw new AuthInvalidJwtError("Invalid JWT structure"); } for (let i = 0; i < parts.length; i++) { if (!BASE64URL_REGEX.test(parts[i])) { throw new AuthInvalidJwtError("JWT not in base64url format"); } } const data = { // using base64url lib header: JSON.parse(stringFromBase64URL(parts[0])), payload: JSON.parse(stringFromBase64URL(parts[1])), signature: base64UrlToUint8Array(parts[2]), raw: { header: parts[0], payload: parts[1] } }; return data; } async function sleep(time) { return await new Promise((accept) => { setTimeout(() => accept(null), time); }); } function retryable(fn, isRetryable) { const promise = new Promise((accept, reject) => { ; (async () => { for (let attempt = 0; attempt < Infinity; attempt++) { try { const result = await fn(attempt); if (!isRetryable(attempt, null, result)) { accept(result); return; } } catch (e) { if (!isRetryable(attempt, e)) { reject(e); return; } } } })(); }); return promise; } function dec2hex(dec) { return ("0" + dec.toString(16)).substr(-2); } function generatePKCEVerifier() { const verifierLength = 56; const array = new Uint32Array(verifierLength); if (typeof crypto === "undefined") { const charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"; const charSetLen = charSet.length; let verifier = ""; for (let i = 0; i < verifierLength; i++) { verifier += charSet.charAt(Math.floor(Math.random() * charSetLen)); } return verifier; } crypto.getRandomValues(array); return Array.from(array, dec2hex).join(""); } async function sha256(randomString) { const encoder = new TextEncoder(); const encodedData = encoder.encode(randomString); const hash = await crypto.subtle.digest("SHA-256", encodedData); const bytes = new Uint8Array(hash); return Array.from(bytes).map((c) => String.fromCharCode(c)).join(""); } async function generatePKCEChallenge(verifier) { const hasCryptoSupport = typeof crypto !== "undefined" && typeof crypto.subtle !== "undefined" && typeof TextEncoder !== "undefined"; if (!hasCryptoSupport) { console.warn("WebCrypto API is not supported. Code challenge method will default to use plain instead of sha256."); return verifier; } const hashed = await sha256(verifier); return btoa(hashed).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); } async function getCodeChallengeAndMethod(storage, storageKey, isPasswordRecovery = false) { const codeVerifier = generatePKCEVerifier(); let storedCodeVerifier = codeVerifier; if (isPasswordRecovery) { storedCodeVerifier += "/PASSWORD_RECOVERY"; } await setItemAsync(storage, `${storageKey}-code-verifier`, storedCodeVerifier); const codeChallenge = await generatePKCEChallenge(codeVerifier); const codeChallengeMethod = codeVerifier === codeChallenge ? "plain" : "s256"; return [codeChallenge, codeChallengeMethod]; } function parseResponseAPIVersion(response) { const apiVersion = response.headers.get(API_VERSION_HEADER_NAME); if (!apiVersion) { return null; } if (!apiVersion.match(API_VERSION_REGEX)) { return null; } try { const date = /* @__PURE__ */ new Date(`${apiVersion}T00:00:00.0Z`); return date; } catch (e) { return null; } } function validateExp(exp) { if (!exp) { throw new Error("Missing exp claim"); } const timeNow = Math.floor(Date.now() / 1e3); if (exp <= timeNow) { throw new Error("JWT has expired"); } } function getAlgorithm(alg) { switch (alg) { case "RS256": return { name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-256" } }; case "ES256": return { name: "ECDSA", namedCurve: "P-256", hash: { name: "SHA-256" } }; default: throw new Error("Invalid alg claim"); } } function validateUUID(str) { if (!UUID_REGEX.test(str)) { throw new Error("@supabase/auth-js: Expected parameter to be UUID but is not"); } } function userNotAvailableProxy() { const proxyTarget = {}; return new Proxy(proxyTarget, { get: (target, prop) => { if (prop === "__isUserNotAvailableProxy") { return true; } if (typeof prop === "symbol") { const sProp = prop.toString(); if (sProp === "Symbol(Symbol.toPrimitive)" || sProp === "Symbol(Symbol.toStringTag)" || sProp === "Symbol(util.inspect.custom)") { return void 0; } } throw new Error(`@supabase/auth-js: client was created with userStorage option and there was no user stored in the user storage. Accessing the "${prop}" property of the session object is not supported. Please use getUser() instead.`); }, set: (_target, prop) => { throw new Error(`@supabase/auth-js: client was created with userStorage option and there was no user stored in the user storage. Setting the "${prop}" property of the session object is not supported. Please use getUser() to fetch a user object you can manipulate.`); }, deleteProperty: (_target, prop) => { throw new Error(`@supabase/auth-js: client was created with userStorage option and there was no user stored in the user storage. Deleting the "${prop}" property of the session object is not supported. Please use getUser() to fetch a user object you can manipulate.`); } }); } function insecureUserWarningProxy(user, suppressWarningRef) { return new Proxy(user, { get: (target, prop, receiver) => { if (prop === "__isInsecureUserWarningProxy") { return true; } if (typeof prop === "symbol") { const sProp = prop.toString(); if (sProp === "Symbol(Symbol.toPrimitive)" || sProp === "Symbol(Symbol.toStringTag)" || sProp === "Symbol(util.inspect.custom)" || sProp === "Symbol(nodejs.util.inspect.custom)") { return Reflect.get(target, prop, receiver); } } if (!suppressWarningRef.value && typeof prop === "string") { console.warn("Using the user object as returned from supabase.auth.getSession() or from some supabase.auth.onAuthStateChange() events could be insecure! This value comes directly from the storage medium (usually cookies on the server) and may not be authentic. Use supabase.auth.getUser() instead which authenticates the data by contacting the Supabase Auth server."); suppressWarningRef.value = true; } return Reflect.get(target, prop, receiver); } }); } function deepClone(obj) { return JSON.parse(JSON.stringify(obj)); } var isBrowser, localStorageWriteTests, supportsLocalStorage, resolveFetch4, looksLikeFetchResponse, setItemAsync, getItemAsync, removeItemAsync, Deferred, API_VERSION_REGEX, UUID_REGEX; var init_helpers3 = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/helpers.js"() { init_constants4(); init_errors3(); init_base64url(); isBrowser = () => typeof window !== "undefined" && typeof document !== "undefined"; localStorageWriteTests = { tested: false, writable: false }; supportsLocalStorage = () => { if (!isBrowser()) { return false; } try { if (typeof globalThis.localStorage !== "object") { return false; } } catch (e) { return false; } if (localStorageWriteTests.tested) { return localStorageWriteTests.writable; } const randomKey = `lswt-${Math.random()}${Math.random()}`; try { globalThis.localStorage.setItem(randomKey, randomKey); globalThis.localStorage.removeItem(randomKey); localStorageWriteTests.tested = true; localStorageWriteTests.writable = true; } catch (e) { localStorageWriteTests.tested = true; localStorageWriteTests.writable = false; } return localStorageWriteTests.writable; }; resolveFetch4 = (customFetch) => { if (customFetch) { return (...args) => customFetch(...args); } return (...args) => fetch(...args); }; looksLikeFetchResponse = (maybeResponse) => { return typeof maybeResponse === "object" && maybeResponse !== null && "status" in maybeResponse && "ok" in maybeResponse && "json" in maybeResponse && typeof maybeResponse.json === "function"; }; setItemAsync = async (storage, key, data) => { await storage.setItem(key, JSON.stringify(data)); }; getItemAsync = async (storage, key) => { const value = await storage.getItem(key); if (!value) { return null; } try { return JSON.parse(value); } catch (_a2) { return value; } }; removeItemAsync = async (storage, key) => { await storage.removeItem(key); }; Deferred = class _Deferred { constructor() { ; this.promise = new _Deferred.promiseConstructor((res, rej) => { ; this.resolve = res; this.reject = rej; }); } }; Deferred.promiseConstructor = Promise; API_VERSION_REGEX = /^2[0-9]{3}-(0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-9]|3[0-1])$/i; UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/; } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/fetch.js async function handleError3(error) { var _a2; if (!looksLikeFetchResponse(error)) { throw new AuthRetryableFetchError(_getErrorMessage3(error), 0); } if (NETWORK_ERROR_CODES.includes(error.status)) { throw new AuthRetryableFetchError(_getErrorMessage3(error), error.status); } let data; try { data = await error.json(); } catch (e) { throw new AuthUnknownError(_getErrorMessage3(e), e); } let errorCode = void 0; const responseAPIVersion = parseResponseAPIVersion(error); if (responseAPIVersion && responseAPIVersion.getTime() >= API_VERSIONS["2024-01-01"].timestamp && typeof data === "object" && data && typeof data.code === "string") { errorCode = data.code; } else if (typeof data === "object" && data && typeof data.error_code === "string") { errorCode = data.error_code; } if (!errorCode) { if (typeof data === "object" && data && typeof data.weak_password === "object" && data.weak_password && Array.isArray(data.weak_password.reasons) && data.weak_password.reasons.length && data.weak_password.reasons.reduce((a, i) => a && typeof i === "string", true)) { throw new AuthWeakPasswordError(_getErrorMessage3(data), error.status, data.weak_password.reasons); } } else if (errorCode === "weak_password") { throw new AuthWeakPasswordError(_getErrorMessage3(data), error.status, ((_a2 = data.weak_password) === null || _a2 === void 0 ? void 0 : _a2.reasons) || []); } else if (errorCode === "session_not_found") { throw new AuthSessionMissingError(); } throw new AuthApiError(_getErrorMessage3(data), error.status || 500, errorCode); } async function _request(fetcher, method, url, options) { var _a2; const headers = Object.assign({}, options === null || options === void 0 ? void 0 : options.headers); if (!headers[API_VERSION_HEADER_NAME]) { headers[API_VERSION_HEADER_NAME] = API_VERSIONS["2024-01-01"].name; } if (options === null || options === void 0 ? void 0 : options.jwt) { headers["Authorization"] = `Bearer ${options.jwt}`; } const qs = (_a2 = options === null || options === void 0 ? void 0 : options.query) !== null && _a2 !== void 0 ? _a2 : {}; if (options === null || options === void 0 ? void 0 : options.redirectTo) { qs["redirect_to"] = options.redirectTo; } const queryString = Object.keys(qs).length ? "?" + new URLSearchParams(qs).toString() : ""; const data = await _handleRequest3(fetcher, method, url + queryString, { headers, noResolveJson: options === null || options === void 0 ? void 0 : options.noResolveJson }, {}, options === null || options === void 0 ? void 0 : options.body); return (options === null || options === void 0 ? void 0 : options.xform) ? options === null || options === void 0 ? void 0 : options.xform(data) : { data: Object.assign({}, data), error: null }; } async function _handleRequest3(fetcher, method, url, options, parameters, body) { const requestParams = _getRequestParams3(method, options, parameters, body); let result; try { result = await fetcher(url, Object.assign({}, requestParams)); } catch (e) { console.error(e); throw new AuthRetryableFetchError(_getErrorMessage3(e), 0); } if (!result.ok) { await handleError3(result); } if (options === null || options === void 0 ? void 0 : options.noResolveJson) { return result; } try { return await result.json(); } catch (e) { await handleError3(e); } } function _sessionResponse(data) { var _a2; let session = null; if (hasSession(data)) { session = Object.assign({}, data); if (!data.expires_at) { session.expires_at = expiresAt(data.expires_in); } } const user = (_a2 = data.user) !== null && _a2 !== void 0 ? _a2 : data; return { data: { session, user }, error: null }; } function _sessionResponsePassword(data) { const response = _sessionResponse(data); if (!response.error && data.weak_password && typeof data.weak_password === "object" && Array.isArray(data.weak_password.reasons) && data.weak_password.reasons.length && data.weak_password.message && typeof data.weak_password.message === "string" && data.weak_password.reasons.reduce((a, i) => a && typeof i === "string", true)) { response.data.weak_password = data.weak_password; } return response; } function _userResponse(data) { var _a2; const user = (_a2 = data.user) !== null && _a2 !== void 0 ? _a2 : data; return { data: { user }, error: null }; } function _ssoResponse(data) { return { data, error: null }; } function _generateLinkResponse(data) { const { action_link, email_otp, hashed_token, redirect_to, verification_type } = data, rest = __rest(data, ["action_link", "email_otp", "hashed_token", "redirect_to", "verification_type"]); const properties = { action_link, email_otp, hashed_token, redirect_to, verification_type }; const user = Object.assign({}, rest); return { data: { properties, user }, error: null }; } function _noResolveJsonResponse(data) { return data; } function hasSession(data) { return data.access_token && data.refresh_token && data.expires_in; } var _getErrorMessage3, NETWORK_ERROR_CODES, _getRequestParams3; var init_fetch3 = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/fetch.js"() { init_tslib_es6(); init_constants4(); init_helpers3(); init_errors3(); _getErrorMessage3 = (err) => err.msg || err.message || err.error_description || err.error || JSON.stringify(err); NETWORK_ERROR_CODES = [502, 503, 504]; _getRequestParams3 = (method, options, parameters, body) => { const params = { method, headers: (options === null || options === void 0 ? void 0 : options.headers) || {} }; if (method === "GET") { return params; } params.headers = Object.assign({ "Content-Type": "application/json;charset=UTF-8" }, options === null || options === void 0 ? void 0 : options.headers); params.body = JSON.stringify(body); return Object.assign(Object.assign({}, params), parameters); }; } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/types.js var SIGN_OUT_SCOPES; var init_types3 = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/types.js"() { SIGN_OUT_SCOPES = ["global", "local", "others"]; } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/GoTrueAdminApi.js var GoTrueAdminApi; var init_GoTrueAdminApi = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/GoTrueAdminApi.js"() { init_tslib_es6(); init_fetch3(); init_helpers3(); init_types3(); init_errors3(); GoTrueAdminApi = class { /** * Creates an admin API client that can be used to manage users and OAuth clients. * * @example * ```ts * import { GoTrueAdminApi } from '@supabase/auth-js' * * const admin = new GoTrueAdminApi({ * url: 'https://xyzcompany.supabase.co/auth/v1', * headers: { Authorization: `Bearer ${process.env.SUPABASE_SERVICE_ROLE_KEY}` }, * }) * ``` */ constructor({ url = "", headers = {}, fetch: fetch2 }) { this.url = url; this.headers = headers; this.fetch = resolveFetch4(fetch2); this.mfa = { listFactors: this._listFactors.bind(this), deleteFactor: this._deleteFactor.bind(this) }; this.oauth = { listClients: this._listOAuthClients.bind(this), createClient: this._createOAuthClient.bind(this), getClient: this._getOAuthClient.bind(this), updateClient: this._updateOAuthClient.bind(this), deleteClient: this._deleteOAuthClient.bind(this), regenerateClientSecret: this._regenerateOAuthClientSecret.bind(this) }; } /** * Removes a logged-in session. * @param jwt A valid, logged-in JWT. * @param scope The logout sope. */ async signOut(jwt, scope = SIGN_OUT_SCOPES[0]) { if (SIGN_OUT_SCOPES.indexOf(scope) < 0) { throw new Error(`@supabase/auth-js: Parameter scope must be one of ${SIGN_OUT_SCOPES.join(", ")}`); } try { await _request(this.fetch, "POST", `${this.url}/logout?scope=${scope}`, { headers: this.headers, jwt, noResolveJson: true }); return { data: null, error: null }; } catch (error) { if (isAuthError(error)) { return { data: null, error }; } throw error; } } /** * Sends an invite link to an email address. * @param email The email address of the user. * @param options Additional options to be included when inviting. */ async inviteUserByEmail(email, options = {}) { try { return await _request(this.fetch, "POST", `${this.url}/invite`, { body: { email, data: options.data }, headers: this.headers, redirectTo: options.redirectTo, xform: _userResponse }); } catch (error) { if (isAuthError(error)) { return { data: { user: null }, error }; } throw error; } } /** * Generates email links and OTPs to be sent via a custom email provider. * @param email The user's email. * @param options.password User password. For signup only. * @param options.data Optional user metadata. For signup only. * @param options.redirectTo The redirect url which should be appended to the generated link */ async generateLink(params) { try { const { options } = params, rest = __rest(params, ["options"]); const body = Object.assign(Object.assign({}, rest), options); if ("newEmail" in rest) { body.new_email = rest === null || rest === void 0 ? void 0 : rest.newEmail; delete body["newEmail"]; } return await _request(this.fetch, "POST", `${this.url}/admin/generate_link`, { body, headers: this.headers, xform: _generateLinkResponse, redirectTo: options === null || options === void 0 ? void 0 : options.redirectTo }); } catch (error) { if (isAuthError(error)) { return { data: { properties: null, user: null }, error }; } throw error; } } // User Admin API /** * Creates a new user. * This function should only be called on a server. Never expose your `service_role` key in the browser. */ async createUser(attributes) { try { return await _request(this.fetch, "POST", `${this.url}/admin/users`, { body: attributes, headers: this.headers, xform: _userResponse }); } catch (error) { if (isAuthError(error)) { return { data: { user: null }, error }; } throw error; } } /** * Get a list of users. * * This function should only be called on a server. Never expose your `service_role` key in the browser. * @param params An object which supports `page` and `perPage` as numbers, to alter the paginated results. */ async listUsers(params) { var _a2, _b, _c, _d, _e, _f, _g; try { const pagination = { nextPage: null, lastPage: 0, total: 0 }; const response = await _request(this.fetch, "GET", `${this.url}/admin/users`, { headers: this.headers, noResolveJson: true, query: { page: (_b = (_a2 = params === null || params === void 0 ? void 0 : params.page) === null || _a2 === void 0 ? void 0 : _a2.toString()) !== null && _b !== void 0 ? _b : "", per_page: (_d = (_c = params === null || params === void 0 ? void 0 : params.perPage) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : "" }, xform: _noResolveJsonResponse }); if (response.error) throw response.error; const users = await response.json(); const total = (_e = response.headers.get("x-total-count")) !== null && _e !== void 0 ? _e : 0; const links = (_g = (_f = response.headers.get("link")) === null || _f === void 0 ? void 0 : _f.split(",")) !== null && _g !== void 0 ? _g : []; if (links.length > 0) { links.forEach((link) => { const page = parseInt(link.split(";")[0].split("=")[1].substring(0, 1)); const rel = JSON.parse(link.split(";")[1].split("=")[1]); pagination[`${rel}Page`] = page; }); pagination.total = parseInt(total); } return { data: Object.assign(Object.assign({}, users), pagination), error: null }; } catch (error) { if (isAuthError(error)) { return { data: { users: [] }, error }; } throw error; } } /** * Get user by id. * * @param uid The user's unique identifier * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ async getUserById(uid) { validateUUID(uid); try { return await _request(this.fetch, "GET", `${this.url}/admin/users/${uid}`, { headers: this.headers, xform: _userResponse }); } catch (error) { if (isAuthError(error)) { return { data: { user: null }, error }; } throw error; } } /** * Updates the user data. * * @param attributes The data you want to update. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ async updateUserById(uid, attributes) { validateUUID(uid); try { return await _request(this.fetch, "PUT", `${this.url}/admin/users/${uid}`, { body: attributes, headers: this.headers, xform: _userResponse }); } catch (error) { if (isAuthError(error)) { return { data: { user: null }, error }; } throw error; } } /** * Delete a user. Requires a `service_role` key. * * @param id The user id you want to remove. * @param shouldSoftDelete If true, then the user will be soft-deleted from the auth schema. Soft deletion allows user identification from the hashed user ID but is not reversible. * Defaults to false for backward compatibility. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ async deleteUser(id, shouldSoftDelete = false) { validateUUID(id); try { return await _request(this.fetch, "DELETE", `${this.url}/admin/users/${id}`, { headers: this.headers, body: { should_soft_delete: shouldSoftDelete }, xform: _userResponse }); } catch (error) { if (isAuthError(error)) { return { data: { user: null }, error }; } throw error; } } async _listFactors(params) { validateUUID(params.userId); try { const { data, error } = await _request(this.fetch, "GET", `${this.url}/admin/users/${params.userId}/factors`, { headers: this.headers, xform: (factors) => { return { data: { factors }, error: null }; } }); return { data, error }; } catch (error) { if (isAuthError(error)) { return { data: null, error }; } throw error; } } async _deleteFactor(params) { validateUUID(params.userId); validateUUID(params.id); try { const data = await _request(this.fetch, "DELETE", `${this.url}/admin/users/${params.userId}/factors/${params.id}`, { headers: this.headers }); return { data, error: null }; } catch (error) { if (isAuthError(error)) { return { data: null, error }; } throw error; } } /** * Lists all OAuth clients with optional pagination. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ async _listOAuthClients(params) { var _a2, _b, _c, _d, _e, _f, _g; try { const pagination = { nextPage: null, lastPage: 0, total: 0 }; const response = await _request(this.fetch, "GET", `${this.url}/admin/oauth/clients`, { headers: this.headers, noResolveJson: true, query: { page: (_b = (_a2 = params === null || params === void 0 ? void 0 : params.page) === null || _a2 === void 0 ? void 0 : _a2.toString()) !== null && _b !== void 0 ? _b : "", per_page: (_d = (_c = params === null || params === void 0 ? void 0 : params.perPage) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : "" }, xform: _noResolveJsonResponse }); if (response.error) throw response.error; const clients = await response.json(); const total = (_e = response.headers.get("x-total-count")) !== null && _e !== void 0 ? _e : 0; const links = (_g = (_f = response.headers.get("link")) === null || _f === void 0 ? void 0 : _f.split(",")) !== null && _g !== void 0 ? _g : []; if (links.length > 0) { links.forEach((link) => { const page = parseInt(link.split(";")[0].split("=")[1].substring(0, 1)); const rel = JSON.parse(link.split(";")[1].split("=")[1]); pagination[`${rel}Page`] = page; }); pagination.total = parseInt(total); } return { data: Object.assign(Object.assign({}, clients), pagination), error: null }; } catch (error) { if (isAuthError(error)) { return { data: { clients: [] }, error }; } throw error; } } /** * Creates a new OAuth client. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ async _createOAuthClient(params) { try { return await _request(this.fetch, "POST", `${this.url}/admin/oauth/clients`, { body: params, headers: this.headers, xform: (client) => { return { data: client, error: null }; } }); } catch (error) { if (isAuthError(error)) { return { data: null, error }; } throw error; } } /** * Gets details of a specific OAuth client. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ async _getOAuthClient(clientId) { try { return await _request(this.fetch, "GET", `${this.url}/admin/oauth/clients/${clientId}`, { headers: this.headers, xform: (client) => { return { data: client, error: null }; } }); } catch (error) { if (isAuthError(error)) { return { data: null, error }; } throw error; } } /** * Updates an existing OAuth client. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ async _updateOAuthClient(clientId, params) { try { return await _request(this.fetch, "PUT", `${this.url}/admin/oauth/clients/${clientId}`, { body: params, headers: this.headers, xform: (client) => { return { data: client, error: null }; } }); } catch (error) { if (isAuthError(error)) { return { data: null, error }; } throw error; } } /** * Deletes an OAuth client. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ async _deleteOAuthClient(clientId) { try { await _request(this.fetch, "DELETE", `${this.url}/admin/oauth/clients/${clientId}`, { headers: this.headers, noResolveJson: true }); return { data: null, error: null }; } catch (error) { if (isAuthError(error)) { return { data: null, error }; } throw error; } } /** * Regenerates the secret for an OAuth client. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. * * This function should only be called on a server. Never expose your `service_role` key in the browser. */ async _regenerateOAuthClientSecret(clientId) { try { return await _request(this.fetch, "POST", `${this.url}/admin/oauth/clients/${clientId}/regenerate_secret`, { headers: this.headers, xform: (client) => { return { data: client, error: null }; } }); } catch (error) { if (isAuthError(error)) { return { data: null, error }; } throw error; } } }; } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/local-storage.js function memoryLocalStorageAdapter(store = {}) { return { getItem: (key) => { return store[key] || null; }, setItem: (key, value) => { store[key] = value; }, removeItem: (key) => { delete store[key]; } }; } var init_local_storage = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/local-storage.js"() { } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/locks.js async function navigatorLock(name, acquireTimeout, fn) { if (internals.debug) { console.log("@supabase/gotrue-js: navigatorLock: acquire lock", name, acquireTimeout); } const abortController = new globalThis.AbortController(); if (acquireTimeout > 0) { setTimeout(() => { abortController.abort(); if (internals.debug) { console.log("@supabase/gotrue-js: navigatorLock acquire timed out", name); } }, acquireTimeout); } return await Promise.resolve().then(() => globalThis.navigator.locks.request(name, acquireTimeout === 0 ? { mode: "exclusive", ifAvailable: true } : { mode: "exclusive", signal: abortController.signal }, async (lock) => { if (lock) { if (internals.debug) { console.log("@supabase/gotrue-js: navigatorLock: acquired", name, lock.name); } try { return await fn(); } finally { if (internals.debug) { console.log("@supabase/gotrue-js: navigatorLock: released", name, lock.name); } } } else { if (acquireTimeout === 0) { if (internals.debug) { console.log("@supabase/gotrue-js: navigatorLock: not immediately available", name); } throw new NavigatorLockAcquireTimeoutError(`Acquiring an exclusive Navigator LockManager lock "${name}" immediately failed`); } else { if (internals.debug) { try { const result = await globalThis.navigator.locks.query(); console.log("@supabase/gotrue-js: Navigator LockManager state", JSON.stringify(result, null, " ")); } catch (e) { console.warn("@supabase/gotrue-js: Error when querying Navigator LockManager state", e); } } console.warn("@supabase/gotrue-js: Navigator LockManager returned a null lock when using #request without ifAvailable set to true, it appears this browser is not following the LockManager spec https://developer.mozilla.org/en-US/docs/Web/API/LockManager/request"); return await fn(); } } })); } async function processLock(name, acquireTimeout, fn) { var _a2; const previousOperation = (_a2 = PROCESS_LOCKS[name]) !== null && _a2 !== void 0 ? _a2 : Promise.resolve(); const currentOperation = Promise.race([ previousOperation.catch(() => { return null; }), acquireTimeout >= 0 ? new Promise((_, reject) => { setTimeout(() => { reject(new ProcessLockAcquireTimeoutError(`Acquring process lock with name "${name}" timed out`)); }, acquireTimeout); }) : null ].filter((x) => x)).catch((e) => { if (e && e.isAcquireTimeout) { throw e; } return null; }).then(async () => { return await fn(); }); PROCESS_LOCKS[name] = currentOperation.catch(async (e) => { if (e && e.isAcquireTimeout) { await previousOperation; return null; } throw e; }); return await currentOperation; } var internals, LockAcquireTimeoutError, NavigatorLockAcquireTimeoutError, ProcessLockAcquireTimeoutError, PROCESS_LOCKS; var init_locks = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/locks.js"() { init_helpers3(); internals = { /** * @experimental */ debug: !!(globalThis && supportsLocalStorage() && globalThis.localStorage && globalThis.localStorage.getItem("supabase.gotrue-js.locks.debug") === "true") }; LockAcquireTimeoutError = class extends Error { constructor(message) { super(message); this.isAcquireTimeout = true; } }; NavigatorLockAcquireTimeoutError = class extends LockAcquireTimeoutError { }; ProcessLockAcquireTimeoutError = class extends LockAcquireTimeoutError { }; PROCESS_LOCKS = {}; } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/polyfills.js function polyfillGlobalThis() { if (typeof globalThis === "object") return; try { Object.defineProperty(Object.prototype, "__magic__", { get: function() { return this; }, configurable: true }); __magic__.globalThis = __magic__; delete Object.prototype.__magic__; } catch (e) { if (typeof self !== "undefined") { self.globalThis = self; } } } var init_polyfills = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/polyfills.js"() { } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/web3/ethereum.js function getAddress(address) { if (!/^0x[a-fA-F0-9]{40}$/.test(address)) { throw new Error(`@supabase/auth-js: Address "${address}" is invalid.`); } return address.toLowerCase(); } function fromHex(hex) { return parseInt(hex, 16); } function toHex(value) { const bytes = new TextEncoder().encode(value); const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join(""); return "0x" + hex; } function createSiweMessage(parameters) { var _a2; const { chainId, domain, expirationTime, issuedAt = /* @__PURE__ */ new Date(), nonce, notBefore, requestId, resources, scheme, uri, version: version4 } = parameters; { if (!Number.isInteger(chainId)) throw new Error(`@supabase/auth-js: Invalid SIWE message field "chainId". Chain ID must be a EIP-155 chain ID. Provided value: ${chainId}`); if (!domain) throw new Error(`@supabase/auth-js: Invalid SIWE message field "domain". Domain must be provided.`); if (nonce && nonce.length < 8) throw new Error(`@supabase/auth-js: Invalid SIWE message field "nonce". Nonce must be at least 8 characters. Provided value: ${nonce}`); if (!uri) throw new Error(`@supabase/auth-js: Invalid SIWE message field "uri". URI must be provided.`); if (version4 !== "1") throw new Error(`@supabase/auth-js: Invalid SIWE message field "version". Version must be '1'. Provided value: ${version4}`); if ((_a2 = parameters.statement) === null || _a2 === void 0 ? void 0 : _a2.includes("\n")) throw new Error(`@supabase/auth-js: Invalid SIWE message field "statement". Statement must not include '\\n'. Provided value: ${parameters.statement}`); } const address = getAddress(parameters.address); const origin = scheme ? `${scheme}://${domain}` : domain; const statement = parameters.statement ? `${parameters.statement} ` : ""; const prefix = `${origin} wants you to sign in with your Ethereum account: ${address} ${statement}`; let suffix = `URI: ${uri} Version: ${version4} Chain ID: ${chainId}${nonce ? ` Nonce: ${nonce}` : ""} Issued At: ${issuedAt.toISOString()}`; if (expirationTime) suffix += ` Expiration Time: ${expirationTime.toISOString()}`; if (notBefore) suffix += ` Not Before: ${notBefore.toISOString()}`; if (requestId) suffix += ` Request ID: ${requestId}`; if (resources) { let content = "\nResources:"; for (const resource of resources) { if (!resource || typeof resource !== "string") throw new Error(`@supabase/auth-js: Invalid SIWE message field "resources". Every resource must be a valid string. Provided value: ${resource}`); content += ` - ${resource}`; } suffix += content; } return `${prefix} ${suffix}`; } var init_ethereum = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/web3/ethereum.js"() { } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/webauthn.errors.js function identifyRegistrationError({ error, options }) { var _a2, _b, _c; const { publicKey } = options; if (!publicKey) { throw Error("options was missing required publicKey property"); } if (error.name === "AbortError") { if (options.signal instanceof AbortSignal) { return new WebAuthnError({ message: "Registration ceremony was sent an abort signal", code: "ERROR_CEREMONY_ABORTED", cause: error }); } } else if (error.name === "ConstraintError") { if (((_a2 = publicKey.authenticatorSelection) === null || _a2 === void 0 ? void 0 : _a2.requireResidentKey) === true) { return new WebAuthnError({ message: "Discoverable credentials were required but no available authenticator supported it", code: "ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT", cause: error }); } else if ( // @ts-ignore: `mediation` doesn't yet exist on CredentialCreationOptions but it's possible as of Sept 2024 options.mediation === "conditional" && ((_b = publicKey.authenticatorSelection) === null || _b === void 0 ? void 0 : _b.userVerification) === "required" ) { return new WebAuthnError({ message: "User verification was required during automatic registration but it could not be performed", code: "ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE", cause: error }); } else if (((_c = publicKey.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.userVerification) === "required") { return new WebAuthnError({ message: "User verification was required but no available authenticator supported it", code: "ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT", cause: error }); } } else if (error.name === "InvalidStateError") { return new WebAuthnError({ message: "The authenticator was previously registered", code: "ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED", cause: error }); } else if (error.name === "NotAllowedError") { return new WebAuthnError({ message: error.message, code: "ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY", cause: error }); } else if (error.name === "NotSupportedError") { const validPubKeyCredParams = publicKey.pubKeyCredParams.filter((param) => param.type === "public-key"); if (validPubKeyCredParams.length === 0) { return new WebAuthnError({ message: 'No entry in pubKeyCredParams was of type "public-key"', code: "ERROR_MALFORMED_PUBKEYCREDPARAMS", cause: error }); } return new WebAuthnError({ message: "No available authenticator supported any of the specified pubKeyCredParams algorithms", code: "ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG", cause: error }); } else if (error.name === "SecurityError") { const effectiveDomain = window.location.hostname; if (!isValidDomain(effectiveDomain)) { return new WebAuthnError({ message: `${window.location.hostname} is an invalid domain`, code: "ERROR_INVALID_DOMAIN", cause: error }); } else if (publicKey.rp.id !== effectiveDomain) { return new WebAuthnError({ message: `The RP ID "${publicKey.rp.id}" is invalid for this domain`, code: "ERROR_INVALID_RP_ID", cause: error }); } } else if (error.name === "TypeError") { if (publicKey.user.id.byteLength < 1 || publicKey.user.id.byteLength > 64) { return new WebAuthnError({ message: "User ID was not between 1 and 64 characters", code: "ERROR_INVALID_USER_ID_LENGTH", cause: error }); } } else if (error.name === "UnknownError") { return new WebAuthnError({ message: "The authenticator was unable to process the specified options, or could not create a new credential", code: "ERROR_AUTHENTICATOR_GENERAL_ERROR", cause: error }); } return new WebAuthnError({ message: "a Non-Webauthn related error has occurred", code: "ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY", cause: error }); } function identifyAuthenticationError({ error, options }) { const { publicKey } = options; if (!publicKey) { throw Error("options was missing required publicKey property"); } if (error.name === "AbortError") { if (options.signal instanceof AbortSignal) { return new WebAuthnError({ message: "Authentication ceremony was sent an abort signal", code: "ERROR_CEREMONY_ABORTED", cause: error }); } } else if (error.name === "NotAllowedError") { return new WebAuthnError({ message: error.message, code: "ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY", cause: error }); } else if (error.name === "SecurityError") { const effectiveDomain = window.location.hostname; if (!isValidDomain(effectiveDomain)) { return new WebAuthnError({ message: `${window.location.hostname} is an invalid domain`, code: "ERROR_INVALID_DOMAIN", cause: error }); } else if (publicKey.rpId !== effectiveDomain) { return new WebAuthnError({ message: `The RP ID "${publicKey.rpId}" is invalid for this domain`, code: "ERROR_INVALID_RP_ID", cause: error }); } } else if (error.name === "UnknownError") { return new WebAuthnError({ message: "The authenticator was unable to process the specified options, or could not create a new assertion signature", code: "ERROR_AUTHENTICATOR_GENERAL_ERROR", cause: error }); } return new WebAuthnError({ message: "a Non-Webauthn related error has occurred", code: "ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY", cause: error }); } var WebAuthnError, WebAuthnUnknownError; var init_webauthn_errors = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/webauthn.errors.js"() { init_webauthn(); WebAuthnError = class extends Error { constructor({ message, code, cause, name }) { var _a2; super(message, { cause }); this.__isWebAuthnError = true; this.name = (_a2 = name !== null && name !== void 0 ? name : cause instanceof Error ? cause.name : void 0) !== null && _a2 !== void 0 ? _a2 : "Unknown Error"; this.code = code; } }; WebAuthnUnknownError = class extends WebAuthnError { constructor(message, originalError) { super({ code: "ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY", cause: originalError, message }); this.name = "WebAuthnUnknownError"; this.originalError = originalError; } }; } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/webauthn.js function deserializeCredentialCreationOptions(options) { if (!options) { throw new Error("Credential creation options are required"); } if (typeof PublicKeyCredential !== "undefined" && "parseCreationOptionsFromJSON" in PublicKeyCredential && typeof PublicKeyCredential.parseCreationOptionsFromJSON === "function") { return PublicKeyCredential.parseCreationOptionsFromJSON( /** we assert the options here as typescript still doesn't know about future webauthn types */ options ); } const { challenge: challengeStr, user: userOpts, excludeCredentials } = options, restOptions = __rest( options, ["challenge", "user", "excludeCredentials"] ); const challenge = base64UrlToUint8Array(challengeStr).buffer; const user = Object.assign(Object.assign({}, userOpts), { id: base64UrlToUint8Array(userOpts.id).buffer }); const result = Object.assign(Object.assign({}, restOptions), { challenge, user }); if (excludeCredentials && excludeCredentials.length > 0) { result.excludeCredentials = new Array(excludeCredentials.length); for (let i = 0; i < excludeCredentials.length; i++) { const cred = excludeCredentials[i]; result.excludeCredentials[i] = Object.assign(Object.assign({}, cred), { id: base64UrlToUint8Array(cred.id).buffer, type: cred.type || "public-key", // Cast transports to handle future transport types like "cable" transports: cred.transports }); } } return result; } function deserializeCredentialRequestOptions(options) { if (!options) { throw new Error("Credential request options are required"); } if (typeof PublicKeyCredential !== "undefined" && "parseRequestOptionsFromJSON" in PublicKeyCredential && typeof PublicKeyCredential.parseRequestOptionsFromJSON === "function") { return PublicKeyCredential.parseRequestOptionsFromJSON(options); } const { challenge: challengeStr, allowCredentials } = options, restOptions = __rest( options, ["challenge", "allowCredentials"] ); const challenge = base64UrlToUint8Array(challengeStr).buffer; const result = Object.assign(Object.assign({}, restOptions), { challenge }); if (allowCredentials && allowCredentials.length > 0) { result.allowCredentials = new Array(allowCredentials.length); for (let i = 0; i < allowCredentials.length; i++) { const cred = allowCredentials[i]; result.allowCredentials[i] = Object.assign(Object.assign({}, cred), { id: base64UrlToUint8Array(cred.id).buffer, type: cred.type || "public-key", // Cast transports to handle future transport types like "cable" transports: cred.transports }); } } return result; } function serializeCredentialCreationResponse(credential) { var _a2; if ("toJSON" in credential && typeof credential.toJSON === "function") { return credential.toJSON(); } const credentialWithAttachment = credential; return { id: credential.id, rawId: credential.id, response: { attestationObject: bytesToBase64URL(new Uint8Array(credential.response.attestationObject)), clientDataJSON: bytesToBase64URL(new Uint8Array(credential.response.clientDataJSON)) }, type: "public-key", clientExtensionResults: credential.getClientExtensionResults(), // Convert null to undefined and cast to AuthenticatorAttachment type authenticatorAttachment: (_a2 = credentialWithAttachment.authenticatorAttachment) !== null && _a2 !== void 0 ? _a2 : void 0 }; } function serializeCredentialRequestResponse(credential) { var _a2; if ("toJSON" in credential && typeof credential.toJSON === "function") { return credential.toJSON(); } const credentialWithAttachment = credential; const clientExtensionResults = credential.getClientExtensionResults(); const assertionResponse = credential.response; return { id: credential.id, rawId: credential.id, // W3C spec expects rawId to match id for JSON format response: { authenticatorData: bytesToBase64URL(new Uint8Array(assertionResponse.authenticatorData)), clientDataJSON: bytesToBase64URL(new Uint8Array(assertionResponse.clientDataJSON)), signature: bytesToBase64URL(new Uint8Array(assertionResponse.signature)), userHandle: assertionResponse.userHandle ? bytesToBase64URL(new Uint8Array(assertionResponse.userHandle)) : void 0 }, type: "public-key", clientExtensionResults, // Convert null to undefined and cast to AuthenticatorAttachment type authenticatorAttachment: (_a2 = credentialWithAttachment.authenticatorAttachment) !== null && _a2 !== void 0 ? _a2 : void 0 }; } function isValidDomain(hostname) { return ( // Consider localhost valid as well since it's okay wrt Secure Contexts hostname === "localhost" || /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(hostname) ); } function browserSupportsWebAuthn() { var _a2, _b; return !!(isBrowser() && "PublicKeyCredential" in window && window.PublicKeyCredential && "credentials" in navigator && typeof ((_a2 = navigator === null || navigator === void 0 ? void 0 : navigator.credentials) === null || _a2 === void 0 ? void 0 : _a2.create) === "function" && typeof ((_b = navigator === null || navigator === void 0 ? void 0 : navigator.credentials) === null || _b === void 0 ? void 0 : _b.get) === "function"); } async function createCredential(options) { try { const response = await navigator.credentials.create( /** we assert the type here until typescript types are updated */ options ); if (!response) { return { data: null, error: new WebAuthnUnknownError("Empty credential response", response) }; } if (!(response instanceof PublicKeyCredential)) { return { data: null, error: new WebAuthnUnknownError("Browser returned unexpected credential type", response) }; } return { data: response, error: null }; } catch (err) { return { data: null, error: identifyRegistrationError({ error: err, options }) }; } } async function getCredential(options) { try { const response = await navigator.credentials.get( /** we assert the type here until typescript types are updated */ options ); if (!response) { return { data: null, error: new WebAuthnUnknownError("Empty credential response", response) }; } if (!(response instanceof PublicKeyCredential)) { return { data: null, error: new WebAuthnUnknownError("Browser returned unexpected credential type", response) }; } return { data: response, error: null }; } catch (err) { return { data: null, error: identifyAuthenticationError({ error: err, options }) }; } } function deepMerge(...sources) { const isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val); const isArrayBufferLike = (val) => val instanceof ArrayBuffer || ArrayBuffer.isView(val); const result = {}; for (const source of sources) { if (!source) continue; for (const key in source) { const value = source[key]; if (value === void 0) continue; if (Array.isArray(value)) { result[key] = value; } else if (isArrayBufferLike(value)) { result[key] = value; } else if (isObject(value)) { const existing = result[key]; if (isObject(existing)) { result[key] = deepMerge(existing, value); } else { result[key] = deepMerge(value); } } else { result[key] = value; } } } return result; } function mergeCredentialCreationOptions(baseOptions, overrides) { return deepMerge(DEFAULT_CREATION_OPTIONS, baseOptions, overrides || {}); } function mergeCredentialRequestOptions(baseOptions, overrides) { return deepMerge(DEFAULT_REQUEST_OPTIONS, baseOptions, overrides || {}); } var WebAuthnAbortService, webAuthnAbortService, DEFAULT_CREATION_OPTIONS, DEFAULT_REQUEST_OPTIONS, WebAuthnApi; var init_webauthn = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/lib/webauthn.js"() { init_tslib_es6(); init_base64url(); init_errors3(); init_helpers3(); init_webauthn_errors(); WebAuthnAbortService = class { /** * Create an abort signal for a new WebAuthn operation. * Automatically cancels any existing operation. * * @returns {AbortSignal} Signal to pass to navigator.credentials.create() or .get() * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal MDN - AbortSignal} */ createNewAbortSignal() { if (this.controller) { const abortError = new Error("Cancelling existing WebAuthn API call for new one"); abortError.name = "AbortError"; this.controller.abort(abortError); } const newController = new AbortController(); this.controller = newController; return newController.signal; } /** * Manually cancel the current WebAuthn operation. * Useful for cleaning up when user cancels or navigates away. * * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort MDN - AbortController.abort} */ cancelCeremony() { if (this.controller) { const abortError = new Error("Manually cancelling existing WebAuthn API call"); abortError.name = "AbortError"; this.controller.abort(abortError); this.controller = void 0; } } }; webAuthnAbortService = new WebAuthnAbortService(); DEFAULT_CREATION_OPTIONS = { hints: ["security-key"], authenticatorSelection: { authenticatorAttachment: "cross-platform", requireResidentKey: false, /** set to preferred because older yubikeys don't have PIN/Biometric */ userVerification: "preferred", residentKey: "discouraged" }, attestation: "direct" }; DEFAULT_REQUEST_OPTIONS = { /** set to preferred because older yubikeys don't have PIN/Biometric */ userVerification: "preferred", hints: ["security-key"], attestation: "direct" }; WebAuthnApi = class { constructor(client) { this.client = client; this.enroll = this._enroll.bind(this); this.challenge = this._challenge.bind(this); this.verify = this._verify.bind(this); this.authenticate = this._authenticate.bind(this); this.register = this._register.bind(this); } /** * Enroll a new WebAuthn factor. * Creates an unverified WebAuthn factor that must be verified with a credential. * * @experimental This method is experimental and may change in future releases * @param {Omit} params - Enrollment parameters (friendlyName required) * @returns {Promise} Enrolled factor details or error * @see {@link https://w3c.github.io/webauthn/#sctn-registering-a-new-credential W3C WebAuthn Spec - Registering a New Credential} */ async _enroll(params) { return this.client.mfa.enroll(Object.assign(Object.assign({}, params), { factorType: "webauthn" })); } /** * Challenge for WebAuthn credential creation or authentication. * Combines server challenge with browser credential operations. * Handles both registration (create) and authentication (request) flows. * * @experimental This method is experimental and may change in future releases * @param {MFAChallengeWebauthnParams & { friendlyName?: string; signal?: AbortSignal }} params - Challenge parameters including factorId * @param {Object} overrides - Allows you to override the parameters passed to navigator.credentials * @param {PublicKeyCredentialCreationOptionsFuture} overrides.create - Override options for credential creation * @param {PublicKeyCredentialRequestOptionsFuture} overrides.request - Override options for credential request * @returns {Promise} Challenge response with credential or error * @see {@link https://w3c.github.io/webauthn/#sctn-credential-creation W3C WebAuthn Spec - Credential Creation} * @see {@link https://w3c.github.io/webauthn/#sctn-verifying-assertion W3C WebAuthn Spec - Verifying Assertion} */ async _challenge({ factorId, webauthn, friendlyName, signal }, overrides) { try { const { data: challengeResponse, error: challengeError } = await this.client.mfa.challenge({ factorId, webauthn }); if (!challengeResponse) { return { data: null, error: challengeError }; } const abortSignal = signal !== null && signal !== void 0 ? signal : webAuthnAbortService.createNewAbortSignal(); if (challengeResponse.webauthn.type === "create") { const { user } = challengeResponse.webauthn.credential_options.publicKey; if (!user.name) { user.name = `${user.id}:${friendlyName}`; } if (!user.displayName) { user.displayName = user.name; } } switch (challengeResponse.webauthn.type) { case "create": { const options = mergeCredentialCreationOptions(challengeResponse.webauthn.credential_options.publicKey, overrides === null || overrides === void 0 ? void 0 : overrides.create); const { data, error } = await createCredential({ publicKey: options, signal: abortSignal }); if (data) { return { data: { factorId, challengeId: challengeResponse.id, webauthn: { type: challengeResponse.webauthn.type, credential_response: data } }, error: null }; } return { data: null, error }; } case "request": { const options = mergeCredentialRequestOptions(challengeResponse.webauthn.credential_options.publicKey, overrides === null || overrides === void 0 ? void 0 : overrides.request); const { data, error } = await getCredential(Object.assign(Object.assign({}, challengeResponse.webauthn.credential_options), { publicKey: options, signal: abortSignal })); if (data) { return { data: { factorId, challengeId: challengeResponse.id, webauthn: { type: challengeResponse.webauthn.type, credential_response: data } }, error: null }; } return { data: null, error }; } } } catch (error) { if (isAuthError(error)) { return { data: null, error }; } return { data: null, error: new AuthUnknownError("Unexpected error in challenge", error) }; } } /** * Verify a WebAuthn credential with the server. * Completes the WebAuthn ceremony by sending the credential to the server for verification. * * @experimental This method is experimental and may change in future releases * @param {Object} params - Verification parameters * @param {string} params.challengeId - ID of the challenge being verified * @param {string} params.factorId - ID of the WebAuthn factor * @param {MFAVerifyWebauthnParams['webauthn']} params.webauthn - WebAuthn credential response * @returns {Promise} Verification result with session or error * @see {@link https://w3c.github.io/webauthn/#sctn-verifying-assertion W3C WebAuthn Spec - Verifying an Authentication Assertion} * */ async _verify({ challengeId, factorId, webauthn }) { return this.client.mfa.verify({ factorId, challengeId, webauthn }); } /** * Complete WebAuthn authentication flow. * Performs challenge and verification in a single operation for existing credentials. * * @experimental This method is experimental and may change in future releases * @param {Object} params - Authentication parameters * @param {string} params.factorId - ID of the WebAuthn factor to authenticate with * @param {Object} params.webauthn - WebAuthn configuration * @param {string} params.webauthn.rpId - Relying Party ID (defaults to current hostname) * @param {string[]} params.webauthn.rpOrigins - Allowed origins (defaults to current origin) * @param {AbortSignal} params.webauthn.signal - Optional abort signal * @param {PublicKeyCredentialRequestOptionsFuture} overrides - Override options for navigator.credentials.get * @returns {Promise>} Authentication result * @see {@link https://w3c.github.io/webauthn/#sctn-authentication W3C WebAuthn Spec - Authentication Ceremony} * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialRequestOptions MDN - PublicKeyCredentialRequestOptions} */ async _authenticate({ factorId, webauthn: { rpId = typeof window !== "undefined" ? window.location.hostname : void 0, rpOrigins = typeof window !== "undefined" ? [window.location.origin] : void 0, signal } = {} }, overrides) { if (!rpId) { return { data: null, error: new AuthError("rpId is required for WebAuthn authentication") }; } try { if (!browserSupportsWebAuthn()) { return { data: null, error: new AuthUnknownError("Browser does not support WebAuthn", null) }; } const { data: challengeResponse, error: challengeError } = await this.challenge({ factorId, webauthn: { rpId, rpOrigins }, signal }, { request: overrides }); if (!challengeResponse) { return { data: null, error: challengeError }; } const { webauthn } = challengeResponse; return this._verify({ factorId, challengeId: challengeResponse.challengeId, webauthn: { type: webauthn.type, rpId, rpOrigins, credential_response: webauthn.credential_response } }); } catch (error) { if (isAuthError(error)) { return { data: null, error }; } return { data: null, error: new AuthUnknownError("Unexpected error in authenticate", error) }; } } /** * Complete WebAuthn registration flow. * Performs enrollment, challenge, and verification in a single operation for new credentials. * * @experimental This method is experimental and may change in future releases * @param {Object} params - Registration parameters * @param {string} params.friendlyName - User-friendly name for the credential * @param {string} params.rpId - Relying Party ID (defaults to current hostname) * @param {string[]} params.rpOrigins - Allowed origins (defaults to current origin) * @param {AbortSignal} params.signal - Optional abort signal * @param {PublicKeyCredentialCreationOptionsFuture} overrides - Override options for navigator.credentials.create * @returns {Promise>} Registration result * @see {@link https://w3c.github.io/webauthn/#sctn-registering-a-new-credential W3C WebAuthn Spec - Registration Ceremony} * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions MDN - PublicKeyCredentialCreationOptions} */ async _register({ friendlyName, webauthn: { rpId = typeof window !== "undefined" ? window.location.hostname : void 0, rpOrigins = typeof window !== "undefined" ? [window.location.origin] : void 0, signal } = {} }, overrides) { if (!rpId) { return { data: null, error: new AuthError("rpId is required for WebAuthn registration") }; } try { if (!browserSupportsWebAuthn()) { return { data: null, error: new AuthUnknownError("Browser does not support WebAuthn", null) }; } const { data: factor, error: enrollError } = await this._enroll({ friendlyName }); if (!factor) { await this.client.mfa.listFactors().then((factors) => { var _a2; return (_a2 = factors.data) === null || _a2 === void 0 ? void 0 : _a2.all.find((v) => v.factor_type === "webauthn" && v.friendly_name === friendlyName && v.status !== "unverified"); }).then((factor2) => factor2 ? this.client.mfa.unenroll({ factorId: factor2 === null || factor2 === void 0 ? void 0 : factor2.id }) : void 0); return { data: null, error: enrollError }; } const { data: challengeResponse, error: challengeError } = await this._challenge({ factorId: factor.id, friendlyName: factor.friendly_name, webauthn: { rpId, rpOrigins }, signal }, { create: overrides }); if (!challengeResponse) { return { data: null, error: challengeError }; } return this._verify({ factorId: factor.id, challengeId: challengeResponse.challengeId, webauthn: { rpId, rpOrigins, type: challengeResponse.webauthn.type, credential_response: challengeResponse.webauthn.credential_response } }); } catch (error) { if (isAuthError(error)) { return { data: null, error }; } return { data: null, error: new AuthUnknownError("Unexpected error in register", error) }; } } }; } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/GoTrueClient.js async function lockNoOp(name, acquireTimeout, fn) { return await fn(); } var DEFAULT_OPTIONS, GLOBAL_JWKS, GoTrueClient, GoTrueClient_default; var init_GoTrueClient = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/GoTrueClient.js"() { init_GoTrueAdminApi(); init_constants4(); init_errors3(); init_fetch3(); init_helpers3(); init_local_storage(); init_locks(); init_polyfills(); init_version3(); init_base64url(); init_ethereum(); init_webauthn(); polyfillGlobalThis(); DEFAULT_OPTIONS = { url: GOTRUE_URL, storageKey: STORAGE_KEY, autoRefreshToken: true, persistSession: true, detectSessionInUrl: true, headers: DEFAULT_HEADERS3, flowType: "implicit", debug: false, hasCustomAuthorizationHeader: false, throwOnError: false }; GLOBAL_JWKS = {}; GoTrueClient = class _GoTrueClient { /** * The JWKS used for verifying asymmetric JWTs */ get jwks() { var _a2, _b; return (_b = (_a2 = GLOBAL_JWKS[this.storageKey]) === null || _a2 === void 0 ? void 0 : _a2.jwks) !== null && _b !== void 0 ? _b : { keys: [] }; } set jwks(value) { GLOBAL_JWKS[this.storageKey] = Object.assign(Object.assign({}, GLOBAL_JWKS[this.storageKey]), { jwks: value }); } get jwks_cached_at() { var _a2, _b; return (_b = (_a2 = GLOBAL_JWKS[this.storageKey]) === null || _a2 === void 0 ? void 0 : _a2.cachedAt) !== null && _b !== void 0 ? _b : Number.MIN_SAFE_INTEGER; } set jwks_cached_at(value) { GLOBAL_JWKS[this.storageKey] = Object.assign(Object.assign({}, GLOBAL_JWKS[this.storageKey]), { cachedAt: value }); } /** * Create a new client for use in the browser. * * @example * ```ts * import { GoTrueClient } from '@supabase/auth-js' * * const auth = new GoTrueClient({ * url: 'https://xyzcompany.supabase.co/auth/v1', * headers: { apikey: 'public-anon-key' }, * storageKey: 'supabase-auth', * }) * ``` */ constructor(options) { var _a2, _b, _c; this.userStorage = null; this.memoryStorage = null; this.stateChangeEmitters = /* @__PURE__ */ new Map(); this.autoRefreshTicker = null; this.visibilityChangedCallback = null; this.refreshingDeferred = null; this.initializePromise = null; this.detectSessionInUrl = true; this.hasCustomAuthorizationHeader = false; this.suppressGetSessionWarning = false; this.lockAcquired = false; this.pendingInLock = []; this.broadcastChannel = null; this.logger = console.log; const settings = Object.assign(Object.assign({}, DEFAULT_OPTIONS), options); this.storageKey = settings.storageKey; this.instanceID = (_a2 = _GoTrueClient.nextInstanceID[this.storageKey]) !== null && _a2 !== void 0 ? _a2 : 0; _GoTrueClient.nextInstanceID[this.storageKey] = this.instanceID + 1; this.logDebugMessages = !!settings.debug; if (typeof settings.debug === "function") { this.logger = settings.debug; } if (this.instanceID > 0 && isBrowser()) { const message = `${this._logPrefix()} Multiple GoTrueClient instances detected in the same browser context. It is not an error, but this should be avoided as it may produce undefined behavior when used concurrently under the same storage key.`; console.warn(message); if (this.logDebugMessages) { console.trace(message); } } this.persistSession = settings.persistSession; this.autoRefreshToken = settings.autoRefreshToken; this.admin = new GoTrueAdminApi({ url: settings.url, headers: settings.headers, fetch: settings.fetch }); this.url = settings.url; this.headers = settings.headers; this.fetch = resolveFetch4(settings.fetch); this.lock = settings.lock || lockNoOp; this.detectSessionInUrl = settings.detectSessionInUrl; this.flowType = settings.flowType; this.hasCustomAuthorizationHeader = settings.hasCustomAuthorizationHeader; this.throwOnError = settings.throwOnError; if (settings.lock) { this.lock = settings.lock; } else if (isBrowser() && ((_b = globalThis === null || globalThis === void 0 ? void 0 : globalThis.navigator) === null || _b === void 0 ? void 0 : _b.locks)) { this.lock = navigatorLock; } else { this.lock = lockNoOp; } if (!this.jwks) { this.jwks = { keys: [] }; this.jwks_cached_at = Number.MIN_SAFE_INTEGER; } this.mfa = { verify: this._verify.bind(this), enroll: this._enroll.bind(this), unenroll: this._unenroll.bind(this), challenge: this._challenge.bind(this), listFactors: this._listFactors.bind(this), challengeAndVerify: this._challengeAndVerify.bind(this), getAuthenticatorAssuranceLevel: this._getAuthenticatorAssuranceLevel.bind(this), webauthn: new WebAuthnApi(this) }; this.oauth = { getAuthorizationDetails: this._getAuthorizationDetails.bind(this), approveAuthorization: this._approveAuthorization.bind(this), denyAuthorization: this._denyAuthorization.bind(this), listGrants: this._listOAuthGrants.bind(this), revokeGrant: this._revokeOAuthGrant.bind(this) }; if (this.persistSession) { if (settings.storage) { this.storage = settings.storage; } else { if (supportsLocalStorage()) { this.storage = globalThis.localStorage; } else { this.memoryStorage = {}; this.storage = memoryLocalStorageAdapter(this.memoryStorage); } } if (settings.userStorage) { this.userStorage = settings.userStorage; } } else { this.memoryStorage = {}; this.storage = memoryLocalStorageAdapter(this.memoryStorage); } if (isBrowser() && globalThis.BroadcastChannel && this.persistSession && this.storageKey) { try { this.broadcastChannel = new globalThis.BroadcastChannel(this.storageKey); } catch (e) { console.error("Failed to create a new BroadcastChannel, multi-tab state changes will not be available", e); } (_c = this.broadcastChannel) === null || _c === void 0 ? void 0 : _c.addEventListener("message", async (event) => { this._debug("received broadcast notification from other tab or client", event); await this._notifyAllSubscribers(event.data.event, event.data.session, false); }); } this.initialize(); } /** * Returns whether error throwing mode is enabled for this client. */ isThrowOnErrorEnabled() { return this.throwOnError; } /** * Centralizes return handling with optional error throwing. When `throwOnError` is enabled * and the provided result contains a non-nullish error, the error is thrown instead of * being returned. This ensures consistent behavior across all public API methods. */ _returnResult(result) { if (this.throwOnError && result && result.error) { throw result.error; } return result; } _logPrefix() { return `GoTrueClient@${this.storageKey}:${this.instanceID} (${version3}) ${(/* @__PURE__ */ new Date()).toISOString()}`; } _debug(...args) { if (this.logDebugMessages) { this.logger(this._logPrefix(), ...args); } return this; } /** * Initializes the client session either from the url or from storage. * This method is automatically called when instantiating the client, but should also be called * manually when checking for an error from an auth redirect (oauth, magiclink, password recovery, etc). */ async initialize() { if (this.initializePromise) { return await this.initializePromise; } this.initializePromise = (async () => { return await this._acquireLock(-1, async () => { return await this._initialize(); }); })(); return await this.initializePromise; } /** * IMPORTANT: * 1. Never throw in this method, as it is called from the constructor * 2. Never return a session from this method as it would be cached over * the whole lifetime of the client */ async _initialize() { var _a2; try { let params = {}; let callbackUrlType = "none"; if (isBrowser()) { params = parseParametersFromURL(window.location.href); if (this._isImplicitGrantCallback(params)) { callbackUrlType = "implicit"; } else if (await this._isPKCECallback(params)) { callbackUrlType = "pkce"; } } if (isBrowser() && this.detectSessionInUrl && callbackUrlType !== "none") { const { data, error } = await this._getSessionFromURL(params, callbackUrlType); if (error) { this._debug("#_initialize()", "error detecting session from URL", error); if (isAuthImplicitGrantRedirectError(error)) { const errorCode = (_a2 = error.details) === null || _a2 === void 0 ? void 0 : _a2.code; if (errorCode === "identity_already_exists" || errorCode === "identity_not_found" || errorCode === "single_identity_not_deletable") { return { error }; } } await this._removeSession(); return { error }; } const { session, redirectType } = data; this._debug("#_initialize()", "detected session in URL", session, "redirect type", redirectType); await this._saveSession(session); setTimeout(async () => { if (redirectType === "recovery") { await this._notifyAllSubscribers("PASSWORD_RECOVERY", session); } else { await this._notifyAllSubscribers("SIGNED_IN", session); } }, 0); return { error: null }; } await this._recoverAndRefresh(); return { error: null }; } catch (error) { if (isAuthError(error)) { return this._returnResult({ error }); } return this._returnResult({ error: new AuthUnknownError("Unexpected error during initialization", error) }); } finally { await this._handleVisibilityChange(); this._debug("#_initialize()", "end"); } } /** * Creates a new anonymous user. * * @returns A session where the is_anonymous claim in the access token JWT set to true */ async signInAnonymously(credentials) { var _a2, _b, _c; try { const res = await _request(this.fetch, "POST", `${this.url}/signup`, { headers: this.headers, body: { data: (_b = (_a2 = credentials === null || credentials === void 0 ? void 0 : credentials.options) === null || _a2 === void 0 ? void 0 : _a2.data) !== null && _b !== void 0 ? _b : {}, gotrue_meta_security: { captcha_token: (_c = credentials === null || credentials === void 0 ? void 0 : credentials.options) === null || _c === void 0 ? void 0 : _c.captchaToken } }, xform: _sessionResponse }); const { data, error } = res; if (error || !data) { return this._returnResult({ data: { user: null, session: null }, error }); } const session = data.session; const user = data.user; if (data.session) { await this._saveSession(data.session); await this._notifyAllSubscribers("SIGNED_IN", session); } return this._returnResult({ data: { user, session }, error: null }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: { user: null, session: null }, error }); } throw error; } } /** * Creates a new user. * * Be aware that if a user account exists in the system you may get back an * error message that attempts to hide this information from the user. * This method has support for PKCE via email signups. The PKCE flow cannot be used when autoconfirm is enabled. * * @returns A logged-in session if the server has "autoconfirm" ON * @returns A user if the server has "autoconfirm" OFF */ async signUp(credentials) { var _a2, _b, _c; try { let res; if ("email" in credentials) { const { email, password, options } = credentials; let codeChallenge = null; let codeChallengeMethod = null; if (this.flowType === "pkce") { ; [codeChallenge, codeChallengeMethod] = await getCodeChallengeAndMethod(this.storage, this.storageKey); } res = await _request(this.fetch, "POST", `${this.url}/signup`, { headers: this.headers, redirectTo: options === null || options === void 0 ? void 0 : options.emailRedirectTo, body: { email, password, data: (_a2 = options === null || options === void 0 ? void 0 : options.data) !== null && _a2 !== void 0 ? _a2 : {}, gotrue_meta_security: { captcha_token: options === null || options === void 0 ? void 0 : options.captchaToken }, code_challenge: codeChallenge, code_challenge_method: codeChallengeMethod }, xform: _sessionResponse }); } else if ("phone" in credentials) { const { phone, password, options } = credentials; res = await _request(this.fetch, "POST", `${this.url}/signup`, { headers: this.headers, body: { phone, password, data: (_b = options === null || options === void 0 ? void 0 : options.data) !== null && _b !== void 0 ? _b : {}, channel: (_c = options === null || options === void 0 ? void 0 : options.channel) !== null && _c !== void 0 ? _c : "sms", gotrue_meta_security: { captcha_token: options === null || options === void 0 ? void 0 : options.captchaToken } }, xform: _sessionResponse }); } else { throw new AuthInvalidCredentialsError("You must provide either an email or phone number and a password"); } const { data, error } = res; if (error || !data) { await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`); return this._returnResult({ data: { user: null, session: null }, error }); } const session = data.session; const user = data.user; if (data.session) { await this._saveSession(data.session); await this._notifyAllSubscribers("SIGNED_IN", session); } return this._returnResult({ data: { user, session }, error: null }); } catch (error) { await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`); if (isAuthError(error)) { return this._returnResult({ data: { user: null, session: null }, error }); } throw error; } } /** * Log in an existing user with an email and password or phone and password. * * Be aware that you may get back an error message that will not distinguish * between the cases where the account does not exist or that the * email/phone and password combination is wrong or that the account can only * be accessed via social login. */ async signInWithPassword(credentials) { try { let res; if ("email" in credentials) { const { email, password, options } = credentials; res = await _request(this.fetch, "POST", `${this.url}/token?grant_type=password`, { headers: this.headers, body: { email, password, gotrue_meta_security: { captcha_token: options === null || options === void 0 ? void 0 : options.captchaToken } }, xform: _sessionResponsePassword }); } else if ("phone" in credentials) { const { phone, password, options } = credentials; res = await _request(this.fetch, "POST", `${this.url}/token?grant_type=password`, { headers: this.headers, body: { phone, password, gotrue_meta_security: { captcha_token: options === null || options === void 0 ? void 0 : options.captchaToken } }, xform: _sessionResponsePassword }); } else { throw new AuthInvalidCredentialsError("You must provide either an email or phone number and a password"); } const { data, error } = res; if (error) { return this._returnResult({ data: { user: null, session: null }, error }); } else if (!data || !data.session || !data.user) { const invalidTokenError = new AuthInvalidTokenResponseError(); return this._returnResult({ data: { user: null, session: null }, error: invalidTokenError }); } if (data.session) { await this._saveSession(data.session); await this._notifyAllSubscribers("SIGNED_IN", data.session); } return this._returnResult({ data: Object.assign({ user: data.user, session: data.session }, data.weak_password ? { weakPassword: data.weak_password } : null), error }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: { user: null, session: null }, error }); } throw error; } } /** * Log in an existing user via a third-party provider. * This method supports the PKCE flow. */ async signInWithOAuth(credentials) { var _a2, _b, _c, _d; return await this._handleProviderSignIn(credentials.provider, { redirectTo: (_a2 = credentials.options) === null || _a2 === void 0 ? void 0 : _a2.redirectTo, scopes: (_b = credentials.options) === null || _b === void 0 ? void 0 : _b.scopes, queryParams: (_c = credentials.options) === null || _c === void 0 ? void 0 : _c.queryParams, skipBrowserRedirect: (_d = credentials.options) === null || _d === void 0 ? void 0 : _d.skipBrowserRedirect }); } /** * Log in an existing user by exchanging an Auth Code issued during the PKCE flow. */ async exchangeCodeForSession(authCode) { await this.initializePromise; return this._acquireLock(-1, async () => { return this._exchangeCodeForSession(authCode); }); } /** * Signs in a user by verifying a message signed by the user's private key. * Supports Ethereum (via Sign-In-With-Ethereum) & Solana (Sign-In-With-Solana) standards, * both of which derive from the EIP-4361 standard * With slight variation on Solana's side. * @reference https://eips.ethereum.org/EIPS/eip-4361 */ async signInWithWeb3(credentials) { const { chain } = credentials; switch (chain) { case "ethereum": return await this.signInWithEthereum(credentials); case "solana": return await this.signInWithSolana(credentials); default: throw new Error(`@supabase/auth-js: Unsupported chain "${chain}"`); } } async signInWithEthereum(credentials) { var _a2, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; let message; let signature; if ("message" in credentials) { message = credentials.message; signature = credentials.signature; } else { const { chain, wallet, statement, options } = credentials; let resolvedWallet; if (!isBrowser()) { if (typeof wallet !== "object" || !(options === null || options === void 0 ? void 0 : options.url)) { throw new Error("@supabase/auth-js: Both wallet and url must be specified in non-browser environments."); } resolvedWallet = wallet; } else if (typeof wallet === "object") { resolvedWallet = wallet; } else { const windowAny = window; if ("ethereum" in windowAny && typeof windowAny.ethereum === "object" && "request" in windowAny.ethereum && typeof windowAny.ethereum.request === "function") { resolvedWallet = windowAny.ethereum; } else { throw new Error(`@supabase/auth-js: No compatible Ethereum wallet interface on the window object (window.ethereum) detected. Make sure the user already has a wallet installed and connected for this app. Prefer passing the wallet interface object directly to signInWithWeb3({ chain: 'ethereum', wallet: resolvedUserWallet }) instead.`); } } const url = new URL((_a2 = options === null || options === void 0 ? void 0 : options.url) !== null && _a2 !== void 0 ? _a2 : window.location.href); const accounts = await resolvedWallet.request({ method: "eth_requestAccounts" }).then((accs) => accs).catch(() => { throw new Error(`@supabase/auth-js: Wallet method eth_requestAccounts is missing or invalid`); }); if (!accounts || accounts.length === 0) { throw new Error(`@supabase/auth-js: No accounts available. Please ensure the wallet is connected.`); } const address = getAddress(accounts[0]); let chainId = (_b = options === null || options === void 0 ? void 0 : options.signInWithEthereum) === null || _b === void 0 ? void 0 : _b.chainId; if (!chainId) { const chainIdHex = await resolvedWallet.request({ method: "eth_chainId" }); chainId = fromHex(chainIdHex); } const siweMessage = { domain: url.host, address, statement, uri: url.href, version: "1", chainId, nonce: (_c = options === null || options === void 0 ? void 0 : options.signInWithEthereum) === null || _c === void 0 ? void 0 : _c.nonce, issuedAt: (_e = (_d = options === null || options === void 0 ? void 0 : options.signInWithEthereum) === null || _d === void 0 ? void 0 : _d.issuedAt) !== null && _e !== void 0 ? _e : /* @__PURE__ */ new Date(), expirationTime: (_f = options === null || options === void 0 ? void 0 : options.signInWithEthereum) === null || _f === void 0 ? void 0 : _f.expirationTime, notBefore: (_g = options === null || options === void 0 ? void 0 : options.signInWithEthereum) === null || _g === void 0 ? void 0 : _g.notBefore, requestId: (_h = options === null || options === void 0 ? void 0 : options.signInWithEthereum) === null || _h === void 0 ? void 0 : _h.requestId, resources: (_j = options === null || options === void 0 ? void 0 : options.signInWithEthereum) === null || _j === void 0 ? void 0 : _j.resources }; message = createSiweMessage(siweMessage); signature = await resolvedWallet.request({ method: "personal_sign", params: [toHex(message), address] }); } try { const { data, error } = await _request(this.fetch, "POST", `${this.url}/token?grant_type=web3`, { headers: this.headers, body: Object.assign({ chain: "ethereum", message, signature }, ((_k = credentials.options) === null || _k === void 0 ? void 0 : _k.captchaToken) ? { gotrue_meta_security: { captcha_token: (_l = credentials.options) === null || _l === void 0 ? void 0 : _l.captchaToken } } : null), xform: _sessionResponse }); if (error) { throw error; } if (!data || !data.session || !data.user) { const invalidTokenError = new AuthInvalidTokenResponseError(); return this._returnResult({ data: { user: null, session: null }, error: invalidTokenError }); } if (data.session) { await this._saveSession(data.session); await this._notifyAllSubscribers("SIGNED_IN", data.session); } return this._returnResult({ data: Object.assign({}, data), error }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: { user: null, session: null }, error }); } throw error; } } async signInWithSolana(credentials) { var _a2, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; let message; let signature; if ("message" in credentials) { message = credentials.message; signature = credentials.signature; } else { const { chain, wallet, statement, options } = credentials; let resolvedWallet; if (!isBrowser()) { if (typeof wallet !== "object" || !(options === null || options === void 0 ? void 0 : options.url)) { throw new Error("@supabase/auth-js: Both wallet and url must be specified in non-browser environments."); } resolvedWallet = wallet; } else if (typeof wallet === "object") { resolvedWallet = wallet; } else { const windowAny = window; if ("solana" in windowAny && typeof windowAny.solana === "object" && ("signIn" in windowAny.solana && typeof windowAny.solana.signIn === "function" || "signMessage" in windowAny.solana && typeof windowAny.solana.signMessage === "function")) { resolvedWallet = windowAny.solana; } else { throw new Error(`@supabase/auth-js: No compatible Solana wallet interface on the window object (window.solana) detected. Make sure the user already has a wallet installed and connected for this app. Prefer passing the wallet interface object directly to signInWithWeb3({ chain: 'solana', wallet: resolvedUserWallet }) instead.`); } } const url = new URL((_a2 = options === null || options === void 0 ? void 0 : options.url) !== null && _a2 !== void 0 ? _a2 : window.location.href); if ("signIn" in resolvedWallet && resolvedWallet.signIn) { const output = await resolvedWallet.signIn(Object.assign(Object.assign(Object.assign({ issuedAt: (/* @__PURE__ */ new Date()).toISOString() }, options === null || options === void 0 ? void 0 : options.signInWithSolana), { // non-overridable properties version: "1", domain: url.host, uri: url.href }), statement ? { statement } : null)); let outputToProcess; if (Array.isArray(output) && output[0] && typeof output[0] === "object") { outputToProcess = output[0]; } else if (output && typeof output === "object" && "signedMessage" in output && "signature" in output) { outputToProcess = output; } else { throw new Error("@supabase/auth-js: Wallet method signIn() returned unrecognized value"); } if ("signedMessage" in outputToProcess && "signature" in outputToProcess && (typeof outputToProcess.signedMessage === "string" || outputToProcess.signedMessage instanceof Uint8Array) && outputToProcess.signature instanceof Uint8Array) { message = typeof outputToProcess.signedMessage === "string" ? outputToProcess.signedMessage : new TextDecoder().decode(outputToProcess.signedMessage); signature = outputToProcess.signature; } else { throw new Error("@supabase/auth-js: Wallet method signIn() API returned object without signedMessage and signature fields"); } } else { if (!("signMessage" in resolvedWallet) || typeof resolvedWallet.signMessage !== "function" || !("publicKey" in resolvedWallet) || typeof resolvedWallet !== "object" || !resolvedWallet.publicKey || !("toBase58" in resolvedWallet.publicKey) || typeof resolvedWallet.publicKey.toBase58 !== "function") { throw new Error("@supabase/auth-js: Wallet does not have a compatible signMessage() and publicKey.toBase58() API"); } message = [ `${url.host} wants you to sign in with your Solana account:`, resolvedWallet.publicKey.toBase58(), ...statement ? ["", statement, ""] : [""], "Version: 1", `URI: ${url.href}`, `Issued At: ${(_c = (_b = options === null || options === void 0 ? void 0 : options.signInWithSolana) === null || _b === void 0 ? void 0 : _b.issuedAt) !== null && _c !== void 0 ? _c : (/* @__PURE__ */ new Date()).toISOString()}`, ...((_d = options === null || options === void 0 ? void 0 : options.signInWithSolana) === null || _d === void 0 ? void 0 : _d.notBefore) ? [`Not Before: ${options.signInWithSolana.notBefore}`] : [], ...((_e = options === null || options === void 0 ? void 0 : options.signInWithSolana) === null || _e === void 0 ? void 0 : _e.expirationTime) ? [`Expiration Time: ${options.signInWithSolana.expirationTime}`] : [], ...((_f = options === null || options === void 0 ? void 0 : options.signInWithSolana) === null || _f === void 0 ? void 0 : _f.chainId) ? [`Chain ID: ${options.signInWithSolana.chainId}`] : [], ...((_g = options === null || options === void 0 ? void 0 : options.signInWithSolana) === null || _g === void 0 ? void 0 : _g.nonce) ? [`Nonce: ${options.signInWithSolana.nonce}`] : [], ...((_h = options === null || options === void 0 ? void 0 : options.signInWithSolana) === null || _h === void 0 ? void 0 : _h.requestId) ? [`Request ID: ${options.signInWithSolana.requestId}`] : [], ...((_k = (_j = options === null || options === void 0 ? void 0 : options.signInWithSolana) === null || _j === void 0 ? void 0 : _j.resources) === null || _k === void 0 ? void 0 : _k.length) ? [ "Resources", ...options.signInWithSolana.resources.map((resource) => `- ${resource}`) ] : [] ].join("\n"); const maybeSignature = await resolvedWallet.signMessage(new TextEncoder().encode(message), "utf8"); if (!maybeSignature || !(maybeSignature instanceof Uint8Array)) { throw new Error("@supabase/auth-js: Wallet signMessage() API returned an recognized value"); } signature = maybeSignature; } } try { const { data, error } = await _request(this.fetch, "POST", `${this.url}/token?grant_type=web3`, { headers: this.headers, body: Object.assign({ chain: "solana", message, signature: bytesToBase64URL(signature) }, ((_l = credentials.options) === null || _l === void 0 ? void 0 : _l.captchaToken) ? { gotrue_meta_security: { captcha_token: (_m = credentials.options) === null || _m === void 0 ? void 0 : _m.captchaToken } } : null), xform: _sessionResponse }); if (error) { throw error; } if (!data || !data.session || !data.user) { const invalidTokenError = new AuthInvalidTokenResponseError(); return this._returnResult({ data: { user: null, session: null }, error: invalidTokenError }); } if (data.session) { await this._saveSession(data.session); await this._notifyAllSubscribers("SIGNED_IN", data.session); } return this._returnResult({ data: Object.assign({}, data), error }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: { user: null, session: null }, error }); } throw error; } } async _exchangeCodeForSession(authCode) { const storageItem = await getItemAsync(this.storage, `${this.storageKey}-code-verifier`); const [codeVerifier, redirectType] = (storageItem !== null && storageItem !== void 0 ? storageItem : "").split("/"); try { const { data, error } = await _request(this.fetch, "POST", `${this.url}/token?grant_type=pkce`, { headers: this.headers, body: { auth_code: authCode, code_verifier: codeVerifier }, xform: _sessionResponse }); await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`); if (error) { throw error; } if (!data || !data.session || !data.user) { const invalidTokenError = new AuthInvalidTokenResponseError(); return this._returnResult({ data: { user: null, session: null, redirectType: null }, error: invalidTokenError }); } if (data.session) { await this._saveSession(data.session); await this._notifyAllSubscribers("SIGNED_IN", data.session); } return this._returnResult({ data: Object.assign(Object.assign({}, data), { redirectType: redirectType !== null && redirectType !== void 0 ? redirectType : null }), error }); } catch (error) { await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`); if (isAuthError(error)) { return this._returnResult({ data: { user: null, session: null, redirectType: null }, error }); } throw error; } } /** * Allows signing in with an OIDC ID token. The authentication provider used * should be enabled and configured. */ async signInWithIdToken(credentials) { try { const { options, provider, token, access_token, nonce } = credentials; const res = await _request(this.fetch, "POST", `${this.url}/token?grant_type=id_token`, { headers: this.headers, body: { provider, id_token: token, access_token, nonce, gotrue_meta_security: { captcha_token: options === null || options === void 0 ? void 0 : options.captchaToken } }, xform: _sessionResponse }); const { data, error } = res; if (error) { return this._returnResult({ data: { user: null, session: null }, error }); } else if (!data || !data.session || !data.user) { const invalidTokenError = new AuthInvalidTokenResponseError(); return this._returnResult({ data: { user: null, session: null }, error: invalidTokenError }); } if (data.session) { await this._saveSession(data.session); await this._notifyAllSubscribers("SIGNED_IN", data.session); } return this._returnResult({ data, error }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: { user: null, session: null }, error }); } throw error; } } /** * Log in a user using magiclink or a one-time password (OTP). * * If the `{{ .ConfirmationURL }}` variable is specified in the email template, a magiclink will be sent. * If the `{{ .Token }}` variable is specified in the email template, an OTP will be sent. * If you're using phone sign-ins, only an OTP will be sent. You won't be able to send a magiclink for phone sign-ins. * * Be aware that you may get back an error message that will not distinguish * between the cases where the account does not exist or, that the account * can only be accessed via social login. * * Do note that you will need to configure a Whatsapp sender on Twilio * if you are using phone sign in with the 'whatsapp' channel. The whatsapp * channel is not supported on other providers * at this time. * This method supports PKCE when an email is passed. */ async signInWithOtp(credentials) { var _a2, _b, _c, _d, _e; try { if ("email" in credentials) { const { email, options } = credentials; let codeChallenge = null; let codeChallengeMethod = null; if (this.flowType === "pkce") { ; [codeChallenge, codeChallengeMethod] = await getCodeChallengeAndMethod(this.storage, this.storageKey); } const { error } = await _request(this.fetch, "POST", `${this.url}/otp`, { headers: this.headers, body: { email, data: (_a2 = options === null || options === void 0 ? void 0 : options.data) !== null && _a2 !== void 0 ? _a2 : {}, create_user: (_b = options === null || options === void 0 ? void 0 : options.shouldCreateUser) !== null && _b !== void 0 ? _b : true, gotrue_meta_security: { captcha_token: options === null || options === void 0 ? void 0 : options.captchaToken }, code_challenge: codeChallenge, code_challenge_method: codeChallengeMethod }, redirectTo: options === null || options === void 0 ? void 0 : options.emailRedirectTo }); return this._returnResult({ data: { user: null, session: null }, error }); } if ("phone" in credentials) { const { phone, options } = credentials; const { data, error } = await _request(this.fetch, "POST", `${this.url}/otp`, { headers: this.headers, body: { phone, data: (_c = options === null || options === void 0 ? void 0 : options.data) !== null && _c !== void 0 ? _c : {}, create_user: (_d = options === null || options === void 0 ? void 0 : options.shouldCreateUser) !== null && _d !== void 0 ? _d : true, gotrue_meta_security: { captcha_token: options === null || options === void 0 ? void 0 : options.captchaToken }, channel: (_e = options === null || options === void 0 ? void 0 : options.channel) !== null && _e !== void 0 ? _e : "sms" } }); return this._returnResult({ data: { user: null, session: null, messageId: data === null || data === void 0 ? void 0 : data.message_id }, error }); } throw new AuthInvalidCredentialsError("You must provide either an email or phone number."); } catch (error) { await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`); if (isAuthError(error)) { return this._returnResult({ data: { user: null, session: null }, error }); } throw error; } } /** * Log in a user given a User supplied OTP or TokenHash received through mobile or email. */ async verifyOtp(params) { var _a2, _b; try { let redirectTo = void 0; let captchaToken = void 0; if ("options" in params) { redirectTo = (_a2 = params.options) === null || _a2 === void 0 ? void 0 : _a2.redirectTo; captchaToken = (_b = params.options) === null || _b === void 0 ? void 0 : _b.captchaToken; } const { data, error } = await _request(this.fetch, "POST", `${this.url}/verify`, { headers: this.headers, body: Object.assign(Object.assign({}, params), { gotrue_meta_security: { captcha_token: captchaToken } }), redirectTo, xform: _sessionResponse }); if (error) { throw error; } if (!data) { const tokenVerificationError = new Error("An error occurred on token verification."); throw tokenVerificationError; } const session = data.session; const user = data.user; if (session === null || session === void 0 ? void 0 : session.access_token) { await this._saveSession(session); await this._notifyAllSubscribers(params.type == "recovery" ? "PASSWORD_RECOVERY" : "SIGNED_IN", session); } return this._returnResult({ data: { user, session }, error: null }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: { user: null, session: null }, error }); } throw error; } } /** * Attempts a single-sign on using an enterprise Identity Provider. A * successful SSO attempt will redirect the current page to the identity * provider authorization page. The redirect URL is implementation and SSO * protocol specific. * * You can use it by providing a SSO domain. Typically you can extract this * domain by asking users for their email address. If this domain is * registered on the Auth instance the redirect will use that organization's * currently active SSO Identity Provider for the login. * * If you have built an organization-specific login page, you can use the * organization's SSO Identity Provider UUID directly instead. */ async signInWithSSO(params) { var _a2, _b, _c, _d, _e; try { let codeChallenge = null; let codeChallengeMethod = null; if (this.flowType === "pkce") { ; [codeChallenge, codeChallengeMethod] = await getCodeChallengeAndMethod(this.storage, this.storageKey); } const result = await _request(this.fetch, "POST", `${this.url}/sso`, { body: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, "providerId" in params ? { provider_id: params.providerId } : null), "domain" in params ? { domain: params.domain } : null), { redirect_to: (_b = (_a2 = params.options) === null || _a2 === void 0 ? void 0 : _a2.redirectTo) !== null && _b !== void 0 ? _b : void 0 }), ((_c = params === null || params === void 0 ? void 0 : params.options) === null || _c === void 0 ? void 0 : _c.captchaToken) ? { gotrue_meta_security: { captcha_token: params.options.captchaToken } } : null), { skip_http_redirect: true, code_challenge: codeChallenge, code_challenge_method: codeChallengeMethod }), headers: this.headers, xform: _ssoResponse }); if (((_d = result.data) === null || _d === void 0 ? void 0 : _d.url) && isBrowser() && !((_e = params.options) === null || _e === void 0 ? void 0 : _e.skipBrowserRedirect)) { window.location.assign(result.data.url); } return this._returnResult(result); } catch (error) { await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`); if (isAuthError(error)) { return this._returnResult({ data: null, error }); } throw error; } } /** * Sends a reauthentication OTP to the user's email or phone number. * Requires the user to be signed-in. */ async reauthenticate() { await this.initializePromise; return await this._acquireLock(-1, async () => { return await this._reauthenticate(); }); } async _reauthenticate() { try { return await this._useSession(async (result) => { const { data: { session }, error: sessionError } = result; if (sessionError) throw sessionError; if (!session) throw new AuthSessionMissingError(); const { error } = await _request(this.fetch, "GET", `${this.url}/reauthenticate`, { headers: this.headers, jwt: session.access_token }); return this._returnResult({ data: { user: null, session: null }, error }); }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: { user: null, session: null }, error }); } throw error; } } /** * Resends an existing signup confirmation email, email change email, SMS OTP or phone change OTP. */ async resend(credentials) { try { const endpoint = `${this.url}/resend`; if ("email" in credentials) { const { email, type, options } = credentials; const { error } = await _request(this.fetch, "POST", endpoint, { headers: this.headers, body: { email, type, gotrue_meta_security: { captcha_token: options === null || options === void 0 ? void 0 : options.captchaToken } }, redirectTo: options === null || options === void 0 ? void 0 : options.emailRedirectTo }); return this._returnResult({ data: { user: null, session: null }, error }); } else if ("phone" in credentials) { const { phone, type, options } = credentials; const { data, error } = await _request(this.fetch, "POST", endpoint, { headers: this.headers, body: { phone, type, gotrue_meta_security: { captcha_token: options === null || options === void 0 ? void 0 : options.captchaToken } } }); return this._returnResult({ data: { user: null, session: null, messageId: data === null || data === void 0 ? void 0 : data.message_id }, error }); } throw new AuthInvalidCredentialsError("You must provide either an email or phone number and a type"); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: { user: null, session: null }, error }); } throw error; } } /** * Returns the session, refreshing it if necessary. * * The session returned can be null if the session is not detected which can happen in the event a user is not signed-in or has logged out. * * **IMPORTANT:** This method loads values directly from the storage attached * to the client. If that storage is based on request cookies for example, * the values in it may not be authentic and therefore it's strongly advised * against using this method and its results in such circumstances. A warning * will be emitted if this is detected. Use {@link #getUser()} instead. */ async getSession() { await this.initializePromise; const result = await this._acquireLock(-1, async () => { return this._useSession(async (result2) => { return result2; }); }); return result; } /** * Acquires a global lock based on the storage key. */ async _acquireLock(acquireTimeout, fn) { this._debug("#_acquireLock", "begin", acquireTimeout); try { if (this.lockAcquired) { const last = this.pendingInLock.length ? this.pendingInLock[this.pendingInLock.length - 1] : Promise.resolve(); const result = (async () => { await last; return await fn(); })(); this.pendingInLock.push((async () => { try { await result; } catch (e) { } })()); return result; } return await this.lock(`lock:${this.storageKey}`, acquireTimeout, async () => { this._debug("#_acquireLock", "lock acquired for storage key", this.storageKey); try { this.lockAcquired = true; const result = fn(); this.pendingInLock.push((async () => { try { await result; } catch (e) { } })()); await result; while (this.pendingInLock.length) { const waitOn = [...this.pendingInLock]; await Promise.all(waitOn); this.pendingInLock.splice(0, waitOn.length); } return await result; } finally { this._debug("#_acquireLock", "lock released for storage key", this.storageKey); this.lockAcquired = false; } }); } finally { this._debug("#_acquireLock", "end"); } } /** * Use instead of {@link #getSession} inside the library. It is * semantically usually what you want, as getting a session involves some * processing afterwards that requires only one client operating on the * session at once across multiple tabs or processes. */ async _useSession(fn) { this._debug("#_useSession", "begin"); try { const result = await this.__loadSession(); return await fn(result); } finally { this._debug("#_useSession", "end"); } } /** * NEVER USE DIRECTLY! * * Always use {@link #_useSession}. */ async __loadSession() { this._debug("#__loadSession()", "begin"); if (!this.lockAcquired) { this._debug("#__loadSession()", "used outside of an acquired lock!", new Error().stack); } try { let currentSession = null; const maybeSession = await getItemAsync(this.storage, this.storageKey); this._debug("#getSession()", "session from storage", maybeSession); if (maybeSession !== null) { if (this._isValidSession(maybeSession)) { currentSession = maybeSession; } else { this._debug("#getSession()", "session from storage is not valid"); await this._removeSession(); } } if (!currentSession) { return { data: { session: null }, error: null }; } const hasExpired = currentSession.expires_at ? currentSession.expires_at * 1e3 - Date.now() < EXPIRY_MARGIN_MS : false; this._debug("#__loadSession()", `session has${hasExpired ? "" : " not"} expired`, "expires_at", currentSession.expires_at); if (!hasExpired) { if (this.userStorage) { const maybeUser = await getItemAsync(this.userStorage, this.storageKey + "-user"); if (maybeUser === null || maybeUser === void 0 ? void 0 : maybeUser.user) { currentSession.user = maybeUser.user; } else { currentSession.user = userNotAvailableProxy(); } } if (this.storage.isServer && currentSession.user && !currentSession.user.__isUserNotAvailableProxy) { const suppressWarningRef = { value: this.suppressGetSessionWarning }; currentSession.user = insecureUserWarningProxy(currentSession.user, suppressWarningRef); if (suppressWarningRef.value) { this.suppressGetSessionWarning = true; } } return { data: { session: currentSession }, error: null }; } const { data: session, error } = await this._callRefreshToken(currentSession.refresh_token); if (error) { return this._returnResult({ data: { session: null }, error }); } return this._returnResult({ data: { session }, error: null }); } finally { this._debug("#__loadSession()", "end"); } } /** * Gets the current user details if there is an existing session. This method * performs a network request to the Supabase Auth server, so the returned * value is authentic and can be used to base authorization rules on. * * @param jwt Takes in an optional access token JWT. If no JWT is provided, the JWT from the current session is used. */ async getUser(jwt) { if (jwt) { return await this._getUser(jwt); } await this.initializePromise; const result = await this._acquireLock(-1, async () => { return await this._getUser(); }); if (result.data.user) { this.suppressGetSessionWarning = true; } return result; } async _getUser(jwt) { try { if (jwt) { return await _request(this.fetch, "GET", `${this.url}/user`, { headers: this.headers, jwt, xform: _userResponse }); } return await this._useSession(async (result) => { var _a2, _b, _c; const { data, error } = result; if (error) { throw error; } if (!((_a2 = data.session) === null || _a2 === void 0 ? void 0 : _a2.access_token) && !this.hasCustomAuthorizationHeader) { return { data: { user: null }, error: new AuthSessionMissingError() }; } return await _request(this.fetch, "GET", `${this.url}/user`, { headers: this.headers, jwt: (_c = (_b = data.session) === null || _b === void 0 ? void 0 : _b.access_token) !== null && _c !== void 0 ? _c : void 0, xform: _userResponse }); }); } catch (error) { if (isAuthError(error)) { if (isAuthSessionMissingError(error)) { await this._removeSession(); await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`); } return this._returnResult({ data: { user: null }, error }); } throw error; } } /** * Updates user data for a logged in user. */ async updateUser(attributes, options = {}) { await this.initializePromise; return await this._acquireLock(-1, async () => { return await this._updateUser(attributes, options); }); } async _updateUser(attributes, options = {}) { try { return await this._useSession(async (result) => { const { data: sessionData, error: sessionError } = result; if (sessionError) { throw sessionError; } if (!sessionData.session) { throw new AuthSessionMissingError(); } const session = sessionData.session; let codeChallenge = null; let codeChallengeMethod = null; if (this.flowType === "pkce" && attributes.email != null) { ; [codeChallenge, codeChallengeMethod] = await getCodeChallengeAndMethod(this.storage, this.storageKey); } const { data, error: userError } = await _request(this.fetch, "PUT", `${this.url}/user`, { headers: this.headers, redirectTo: options === null || options === void 0 ? void 0 : options.emailRedirectTo, body: Object.assign(Object.assign({}, attributes), { code_challenge: codeChallenge, code_challenge_method: codeChallengeMethod }), jwt: session.access_token, xform: _userResponse }); if (userError) { throw userError; } session.user = data.user; await this._saveSession(session); await this._notifyAllSubscribers("USER_UPDATED", session); return this._returnResult({ data: { user: session.user }, error: null }); }); } catch (error) { await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`); if (isAuthError(error)) { return this._returnResult({ data: { user: null }, error }); } throw error; } } /** * Sets the session data from the current session. If the current session is expired, setSession will take care of refreshing it to obtain a new session. * If the refresh token or access token in the current session is invalid, an error will be thrown. * @param currentSession The current session that minimally contains an access token and refresh token. */ async setSession(currentSession) { await this.initializePromise; return await this._acquireLock(-1, async () => { return await this._setSession(currentSession); }); } async _setSession(currentSession) { try { if (!currentSession.access_token || !currentSession.refresh_token) { throw new AuthSessionMissingError(); } const timeNow = Date.now() / 1e3; let expiresAt2 = timeNow; let hasExpired = true; let session = null; const { payload } = decodeJWT(currentSession.access_token); if (payload.exp) { expiresAt2 = payload.exp; hasExpired = expiresAt2 <= timeNow; } if (hasExpired) { const { data: refreshedSession, error } = await this._callRefreshToken(currentSession.refresh_token); if (error) { return this._returnResult({ data: { user: null, session: null }, error }); } if (!refreshedSession) { return { data: { user: null, session: null }, error: null }; } session = refreshedSession; } else { const { data, error } = await this._getUser(currentSession.access_token); if (error) { throw error; } session = { access_token: currentSession.access_token, refresh_token: currentSession.refresh_token, user: data.user, token_type: "bearer", expires_in: expiresAt2 - timeNow, expires_at: expiresAt2 }; await this._saveSession(session); await this._notifyAllSubscribers("SIGNED_IN", session); } return this._returnResult({ data: { user: session.user, session }, error: null }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: { session: null, user: null }, error }); } throw error; } } /** * Returns a new session, regardless of expiry status. * Takes in an optional current session. If not passed in, then refreshSession() will attempt to retrieve it from getSession(). * If the current session's refresh token is invalid, an error will be thrown. * @param currentSession The current session. If passed in, it must contain a refresh token. */ async refreshSession(currentSession) { await this.initializePromise; return await this._acquireLock(-1, async () => { return await this._refreshSession(currentSession); }); } async _refreshSession(currentSession) { try { return await this._useSession(async (result) => { var _a2; if (!currentSession) { const { data, error: error2 } = result; if (error2) { throw error2; } currentSession = (_a2 = data.session) !== null && _a2 !== void 0 ? _a2 : void 0; } if (!(currentSession === null || currentSession === void 0 ? void 0 : currentSession.refresh_token)) { throw new AuthSessionMissingError(); } const { data: session, error } = await this._callRefreshToken(currentSession.refresh_token); if (error) { return this._returnResult({ data: { user: null, session: null }, error }); } if (!session) { return this._returnResult({ data: { user: null, session: null }, error: null }); } return this._returnResult({ data: { user: session.user, session }, error: null }); }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: { user: null, session: null }, error }); } throw error; } } /** * Gets the session data from a URL string */ async _getSessionFromURL(params, callbackUrlType) { try { if (!isBrowser()) throw new AuthImplicitGrantRedirectError("No browser detected."); if (params.error || params.error_description || params.error_code) { throw new AuthImplicitGrantRedirectError(params.error_description || "Error in URL with unspecified error_description", { error: params.error || "unspecified_error", code: params.error_code || "unspecified_code" }); } switch (callbackUrlType) { case "implicit": if (this.flowType === "pkce") { throw new AuthPKCEGrantCodeExchangeError("Not a valid PKCE flow url."); } break; case "pkce": if (this.flowType === "implicit") { throw new AuthImplicitGrantRedirectError("Not a valid implicit grant flow url."); } break; default: } if (callbackUrlType === "pkce") { this._debug("#_initialize()", "begin", "is PKCE flow", true); if (!params.code) throw new AuthPKCEGrantCodeExchangeError("No code detected."); const { data: data2, error: error2 } = await this._exchangeCodeForSession(params.code); if (error2) throw error2; const url = new URL(window.location.href); url.searchParams.delete("code"); window.history.replaceState(window.history.state, "", url.toString()); return { data: { session: data2.session, redirectType: null }, error: null }; } const { provider_token, provider_refresh_token, access_token, refresh_token, expires_in, expires_at, token_type } = params; if (!access_token || !expires_in || !refresh_token || !token_type) { throw new AuthImplicitGrantRedirectError("No session defined in URL"); } const timeNow = Math.round(Date.now() / 1e3); const expiresIn = parseInt(expires_in); let expiresAt2 = timeNow + expiresIn; if (expires_at) { expiresAt2 = parseInt(expires_at); } const actuallyExpiresIn = expiresAt2 - timeNow; if (actuallyExpiresIn * 1e3 <= AUTO_REFRESH_TICK_DURATION_MS) { console.warn(`@supabase/gotrue-js: Session as retrieved from URL expires in ${actuallyExpiresIn}s, should have been closer to ${expiresIn}s`); } const issuedAt = expiresAt2 - expiresIn; if (timeNow - issuedAt >= 120) { console.warn("@supabase/gotrue-js: Session as retrieved from URL was issued over 120s ago, URL could be stale", issuedAt, expiresAt2, timeNow); } else if (timeNow - issuedAt < 0) { console.warn("@supabase/gotrue-js: Session as retrieved from URL was issued in the future? Check the device clock for skew", issuedAt, expiresAt2, timeNow); } const { data, error } = await this._getUser(access_token); if (error) throw error; const session = { provider_token, provider_refresh_token, access_token, expires_in: expiresIn, expires_at: expiresAt2, refresh_token, token_type, user: data.user }; window.location.hash = ""; this._debug("#_getSessionFromURL()", "clearing window.location.hash"); return this._returnResult({ data: { session, redirectType: params.type }, error: null }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: { session: null, redirectType: null }, error }); } throw error; } } /** * Checks if the current URL contains parameters given by an implicit oauth grant flow (https://www.rfc-editor.org/rfc/rfc6749.html#section-4.2) */ _isImplicitGrantCallback(params) { return Boolean(params.access_token || params.error_description); } /** * Checks if the current URL and backing storage contain parameters given by a PKCE flow */ async _isPKCECallback(params) { const currentStorageContent = await getItemAsync(this.storage, `${this.storageKey}-code-verifier`); return !!(params.code && currentStorageContent); } /** * Inside a browser context, `signOut()` will remove the logged in user from the browser session and log them out - removing all items from localstorage and then trigger a `"SIGNED_OUT"` event. * * For server-side management, you can revoke all refresh tokens for a user by passing a user's JWT through to `auth.api.signOut(JWT: string)`. * There is no way to revoke a user's access token jwt until it expires. It is recommended to set a shorter expiry on the jwt for this reason. * * If using `others` scope, no `SIGNED_OUT` event is fired! */ async signOut(options = { scope: "global" }) { await this.initializePromise; return await this._acquireLock(-1, async () => { return await this._signOut(options); }); } async _signOut({ scope } = { scope: "global" }) { return await this._useSession(async (result) => { var _a2; const { data, error: sessionError } = result; if (sessionError) { return this._returnResult({ error: sessionError }); } const accessToken = (_a2 = data.session) === null || _a2 === void 0 ? void 0 : _a2.access_token; if (accessToken) { const { error } = await this.admin.signOut(accessToken, scope); if (error) { if (!(isAuthApiError(error) && (error.status === 404 || error.status === 401 || error.status === 403))) { return this._returnResult({ error }); } } } if (scope !== "others") { await this._removeSession(); await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`); } return this._returnResult({ error: null }); }); } onAuthStateChange(callback) { const id = generateCallbackId(); const subscription = { id, callback, unsubscribe: () => { this._debug("#unsubscribe()", "state change callback with id removed", id); this.stateChangeEmitters.delete(id); } }; this._debug("#onAuthStateChange()", "registered callback with id", id); this.stateChangeEmitters.set(id, subscription); (async () => { await this.initializePromise; await this._acquireLock(-1, async () => { this._emitInitialSession(id); }); })(); return { data: { subscription } }; } async _emitInitialSession(id) { return await this._useSession(async (result) => { var _a2, _b; try { const { data: { session }, error } = result; if (error) throw error; await ((_a2 = this.stateChangeEmitters.get(id)) === null || _a2 === void 0 ? void 0 : _a2.callback("INITIAL_SESSION", session)); this._debug("INITIAL_SESSION", "callback id", id, "session", session); } catch (err) { await ((_b = this.stateChangeEmitters.get(id)) === null || _b === void 0 ? void 0 : _b.callback("INITIAL_SESSION", null)); this._debug("INITIAL_SESSION", "callback id", id, "error", err); console.error(err); } }); } /** * Sends a password reset request to an email address. This method supports the PKCE flow. * * @param email The email address of the user. * @param options.redirectTo The URL to send the user to after they click the password reset link. * @param options.captchaToken Verification token received when the user completes the captcha on the site. */ async resetPasswordForEmail(email, options = {}) { let codeChallenge = null; let codeChallengeMethod = null; if (this.flowType === "pkce") { ; [codeChallenge, codeChallengeMethod] = await getCodeChallengeAndMethod( this.storage, this.storageKey, true // isPasswordRecovery ); } try { return await _request(this.fetch, "POST", `${this.url}/recover`, { body: { email, code_challenge: codeChallenge, code_challenge_method: codeChallengeMethod, gotrue_meta_security: { captcha_token: options.captchaToken } }, headers: this.headers, redirectTo: options.redirectTo }); } catch (error) { await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`); if (isAuthError(error)) { return this._returnResult({ data: null, error }); } throw error; } } /** * Gets all the identities linked to a user. */ async getUserIdentities() { var _a2; try { const { data, error } = await this.getUser(); if (error) throw error; return this._returnResult({ data: { identities: (_a2 = data.user.identities) !== null && _a2 !== void 0 ? _a2 : [] }, error: null }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: null, error }); } throw error; } } async linkIdentity(credentials) { if ("token" in credentials) { return this.linkIdentityIdToken(credentials); } return this.linkIdentityOAuth(credentials); } async linkIdentityOAuth(credentials) { var _a2; try { const { data, error } = await this._useSession(async (result) => { var _a3, _b, _c, _d, _e; const { data: data2, error: error2 } = result; if (error2) throw error2; const url = await this._getUrlForProvider(`${this.url}/user/identities/authorize`, credentials.provider, { redirectTo: (_a3 = credentials.options) === null || _a3 === void 0 ? void 0 : _a3.redirectTo, scopes: (_b = credentials.options) === null || _b === void 0 ? void 0 : _b.scopes, queryParams: (_c = credentials.options) === null || _c === void 0 ? void 0 : _c.queryParams, skipBrowserRedirect: true }); return await _request(this.fetch, "GET", url, { headers: this.headers, jwt: (_e = (_d = data2.session) === null || _d === void 0 ? void 0 : _d.access_token) !== null && _e !== void 0 ? _e : void 0 }); }); if (error) throw error; if (isBrowser() && !((_a2 = credentials.options) === null || _a2 === void 0 ? void 0 : _a2.skipBrowserRedirect)) { window.location.assign(data === null || data === void 0 ? void 0 : data.url); } return this._returnResult({ data: { provider: credentials.provider, url: data === null || data === void 0 ? void 0 : data.url }, error: null }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: { provider: credentials.provider, url: null }, error }); } throw error; } } async linkIdentityIdToken(credentials) { return await this._useSession(async (result) => { var _a2; try { const { error: sessionError, data: { session } } = result; if (sessionError) throw sessionError; const { options, provider, token, access_token, nonce } = credentials; const res = await _request(this.fetch, "POST", `${this.url}/token?grant_type=id_token`, { headers: this.headers, jwt: (_a2 = session === null || session === void 0 ? void 0 : session.access_token) !== null && _a2 !== void 0 ? _a2 : void 0, body: { provider, id_token: token, access_token, nonce, link_identity: true, gotrue_meta_security: { captcha_token: options === null || options === void 0 ? void 0 : options.captchaToken } }, xform: _sessionResponse }); const { data, error } = res; if (error) { return this._returnResult({ data: { user: null, session: null }, error }); } else if (!data || !data.session || !data.user) { return this._returnResult({ data: { user: null, session: null }, error: new AuthInvalidTokenResponseError() }); } if (data.session) { await this._saveSession(data.session); await this._notifyAllSubscribers("USER_UPDATED", data.session); } return this._returnResult({ data, error }); } catch (error) { await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`); if (isAuthError(error)) { return this._returnResult({ data: { user: null, session: null }, error }); } throw error; } }); } /** * Unlinks an identity from a user by deleting it. The user will no longer be able to sign in with that identity once it's unlinked. */ async unlinkIdentity(identity) { try { return await this._useSession(async (result) => { var _a2, _b; const { data, error } = result; if (error) { throw error; } return await _request(this.fetch, "DELETE", `${this.url}/user/identities/${identity.identity_id}`, { headers: this.headers, jwt: (_b = (_a2 = data.session) === null || _a2 === void 0 ? void 0 : _a2.access_token) !== null && _b !== void 0 ? _b : void 0 }); }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: null, error }); } throw error; } } /** * Generates a new JWT. * @param refreshToken A valid refresh token that was returned on login. */ async _refreshAccessToken(refreshToken) { const debugName = `#_refreshAccessToken(${refreshToken.substring(0, 5)}...)`; this._debug(debugName, "begin"); try { const startedAt = Date.now(); return await retryable(async (attempt) => { if (attempt > 0) { await sleep(200 * Math.pow(2, attempt - 1)); } this._debug(debugName, "refreshing attempt", attempt); return await _request(this.fetch, "POST", `${this.url}/token?grant_type=refresh_token`, { body: { refresh_token: refreshToken }, headers: this.headers, xform: _sessionResponse }); }, (attempt, error) => { const nextBackOffInterval = 200 * Math.pow(2, attempt); return error && isAuthRetryableFetchError(error) && // retryable only if the request can be sent before the backoff overflows the tick duration Date.now() + nextBackOffInterval - startedAt < AUTO_REFRESH_TICK_DURATION_MS; }); } catch (error) { this._debug(debugName, "error", error); if (isAuthError(error)) { return this._returnResult({ data: { session: null, user: null }, error }); } throw error; } finally { this._debug(debugName, "end"); } } _isValidSession(maybeSession) { const isValidSession = typeof maybeSession === "object" && maybeSession !== null && "access_token" in maybeSession && "refresh_token" in maybeSession && "expires_at" in maybeSession; return isValidSession; } async _handleProviderSignIn(provider, options) { const url = await this._getUrlForProvider(`${this.url}/authorize`, provider, { redirectTo: options.redirectTo, scopes: options.scopes, queryParams: options.queryParams }); this._debug("#_handleProviderSignIn()", "provider", provider, "options", options, "url", url); if (isBrowser() && !options.skipBrowserRedirect) { window.location.assign(url); } return { data: { provider, url }, error: null }; } /** * Recovers the session from LocalStorage and refreshes the token * Note: this method is async to accommodate for AsyncStorage e.g. in React native. */ async _recoverAndRefresh() { var _a2, _b; const debugName = "#_recoverAndRefresh()"; this._debug(debugName, "begin"); try { const currentSession = await getItemAsync(this.storage, this.storageKey); if (currentSession && this.userStorage) { let maybeUser = await getItemAsync(this.userStorage, this.storageKey + "-user"); if (!this.storage.isServer && Object.is(this.storage, this.userStorage) && !maybeUser) { maybeUser = { user: currentSession.user }; await setItemAsync(this.userStorage, this.storageKey + "-user", maybeUser); } currentSession.user = (_a2 = maybeUser === null || maybeUser === void 0 ? void 0 : maybeUser.user) !== null && _a2 !== void 0 ? _a2 : userNotAvailableProxy(); } else if (currentSession && !currentSession.user) { if (!currentSession.user) { const separateUser = await getItemAsync(this.storage, this.storageKey + "-user"); if (separateUser && (separateUser === null || separateUser === void 0 ? void 0 : separateUser.user)) { currentSession.user = separateUser.user; await removeItemAsync(this.storage, this.storageKey + "-user"); await setItemAsync(this.storage, this.storageKey, currentSession); } else { currentSession.user = userNotAvailableProxy(); } } } this._debug(debugName, "session from storage", currentSession); if (!this._isValidSession(currentSession)) { this._debug(debugName, "session is not valid"); if (currentSession !== null) { await this._removeSession(); } return; } const expiresWithMargin = ((_b = currentSession.expires_at) !== null && _b !== void 0 ? _b : Infinity) * 1e3 - Date.now() < EXPIRY_MARGIN_MS; this._debug(debugName, `session has${expiresWithMargin ? "" : " not"} expired with margin of ${EXPIRY_MARGIN_MS}s`); if (expiresWithMargin) { if (this.autoRefreshToken && currentSession.refresh_token) { const { error } = await this._callRefreshToken(currentSession.refresh_token); if (error) { console.error(error); if (!isAuthRetryableFetchError(error)) { this._debug(debugName, "refresh failed with a non-retryable error, removing the session", error); await this._removeSession(); } } } } else if (currentSession.user && currentSession.user.__isUserNotAvailableProxy === true) { try { const { data, error: userError } = await this._getUser(currentSession.access_token); if (!userError && (data === null || data === void 0 ? void 0 : data.user)) { currentSession.user = data.user; await this._saveSession(currentSession); await this._notifyAllSubscribers("SIGNED_IN", currentSession); } else { this._debug(debugName, "could not get user data, skipping SIGNED_IN notification"); } } catch (getUserError) { console.error("Error getting user data:", getUserError); this._debug(debugName, "error getting user data, skipping SIGNED_IN notification", getUserError); } } else { await this._notifyAllSubscribers("SIGNED_IN", currentSession); } } catch (err) { this._debug(debugName, "error", err); console.error(err); return; } finally { this._debug(debugName, "end"); } } async _callRefreshToken(refreshToken) { var _a2, _b; if (!refreshToken) { throw new AuthSessionMissingError(); } if (this.refreshingDeferred) { return this.refreshingDeferred.promise; } const debugName = `#_callRefreshToken(${refreshToken.substring(0, 5)}...)`; this._debug(debugName, "begin"); try { this.refreshingDeferred = new Deferred(); const { data, error } = await this._refreshAccessToken(refreshToken); if (error) throw error; if (!data.session) throw new AuthSessionMissingError(); await this._saveSession(data.session); await this._notifyAllSubscribers("TOKEN_REFRESHED", data.session); const result = { data: data.session, error: null }; this.refreshingDeferred.resolve(result); return result; } catch (error) { this._debug(debugName, "error", error); if (isAuthError(error)) { const result = { data: null, error }; if (!isAuthRetryableFetchError(error)) { await this._removeSession(); } (_a2 = this.refreshingDeferred) === null || _a2 === void 0 ? void 0 : _a2.resolve(result); return result; } (_b = this.refreshingDeferred) === null || _b === void 0 ? void 0 : _b.reject(error); throw error; } finally { this.refreshingDeferred = null; this._debug(debugName, "end"); } } async _notifyAllSubscribers(event, session, broadcast = true) { const debugName = `#_notifyAllSubscribers(${event})`; this._debug(debugName, "begin", session, `broadcast = ${broadcast}`); try { if (this.broadcastChannel && broadcast) { this.broadcastChannel.postMessage({ event, session }); } const errors = []; const promises = Array.from(this.stateChangeEmitters.values()).map(async (x) => { try { await x.callback(event, session); } catch (e) { errors.push(e); } }); await Promise.all(promises); if (errors.length > 0) { for (let i = 0; i < errors.length; i += 1) { console.error(errors[i]); } throw errors[0]; } } finally { this._debug(debugName, "end"); } } /** * set currentSession and currentUser * process to _startAutoRefreshToken if possible */ async _saveSession(session) { this._debug("#_saveSession()", session); this.suppressGetSessionWarning = true; await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`); const sessionToProcess = Object.assign({}, session); const userIsProxy = sessionToProcess.user && sessionToProcess.user.__isUserNotAvailableProxy === true; if (this.userStorage) { if (!userIsProxy && sessionToProcess.user) { await setItemAsync(this.userStorage, this.storageKey + "-user", { user: sessionToProcess.user }); } else if (userIsProxy) { } const mainSessionData = Object.assign({}, sessionToProcess); delete mainSessionData.user; const clonedMainSessionData = deepClone(mainSessionData); await setItemAsync(this.storage, this.storageKey, clonedMainSessionData); } else { const clonedSession = deepClone(sessionToProcess); await setItemAsync(this.storage, this.storageKey, clonedSession); } } async _removeSession() { this._debug("#_removeSession()"); this.suppressGetSessionWarning = false; await removeItemAsync(this.storage, this.storageKey); await removeItemAsync(this.storage, this.storageKey + "-code-verifier"); await removeItemAsync(this.storage, this.storageKey + "-user"); if (this.userStorage) { await removeItemAsync(this.userStorage, this.storageKey + "-user"); } await this._notifyAllSubscribers("SIGNED_OUT", null); } /** * Removes any registered visibilitychange callback. * * {@see #startAutoRefresh} * {@see #stopAutoRefresh} */ _removeVisibilityChangedCallback() { this._debug("#_removeVisibilityChangedCallback()"); const callback = this.visibilityChangedCallback; this.visibilityChangedCallback = null; try { if (callback && isBrowser() && (window === null || window === void 0 ? void 0 : window.removeEventListener)) { window.removeEventListener("visibilitychange", callback); } } catch (e) { console.error("removing visibilitychange callback failed", e); } } /** * This is the private implementation of {@link #startAutoRefresh}. Use this * within the library. */ async _startAutoRefresh() { await this._stopAutoRefresh(); this._debug("#_startAutoRefresh()"); const ticker = setInterval(() => this._autoRefreshTokenTick(), AUTO_REFRESH_TICK_DURATION_MS); this.autoRefreshTicker = ticker; if (ticker && typeof ticker === "object" && typeof ticker.unref === "function") { ticker.unref(); } else if (typeof Deno !== "undefined" && typeof Deno.unrefTimer === "function") { Deno.unrefTimer(ticker); } setTimeout(async () => { await this.initializePromise; await this._autoRefreshTokenTick(); }, 0); } /** * This is the private implementation of {@link #stopAutoRefresh}. Use this * within the library. */ async _stopAutoRefresh() { this._debug("#_stopAutoRefresh()"); const ticker = this.autoRefreshTicker; this.autoRefreshTicker = null; if (ticker) { clearInterval(ticker); } } /** * Starts an auto-refresh process in the background. The session is checked * every few seconds. Close to the time of expiration a process is started to * refresh the session. If refreshing fails it will be retried for as long as * necessary. * * If you set the {@link GoTrueClientOptions#autoRefreshToken} you don't need * to call this function, it will be called for you. * * On browsers the refresh process works only when the tab/window is in the * foreground to conserve resources as well as prevent race conditions and * flooding auth with requests. If you call this method any managed * visibility change callback will be removed and you must manage visibility * changes on your own. * * On non-browser platforms the refresh process works *continuously* in the * background, which may not be desirable. You should hook into your * platform's foreground indication mechanism and call these methods * appropriately to conserve resources. * * {@see #stopAutoRefresh} */ async startAutoRefresh() { this._removeVisibilityChangedCallback(); await this._startAutoRefresh(); } /** * Stops an active auto refresh process running in the background (if any). * * If you call this method any managed visibility change callback will be * removed and you must manage visibility changes on your own. * * See {@link #startAutoRefresh} for more details. */ async stopAutoRefresh() { this._removeVisibilityChangedCallback(); await this._stopAutoRefresh(); } /** * Runs the auto refresh token tick. */ async _autoRefreshTokenTick() { this._debug("#_autoRefreshTokenTick()", "begin"); try { await this._acquireLock(0, async () => { try { const now = Date.now(); try { return await this._useSession(async (result) => { const { data: { session } } = result; if (!session || !session.refresh_token || !session.expires_at) { this._debug("#_autoRefreshTokenTick()", "no session"); return; } const expiresInTicks = Math.floor((session.expires_at * 1e3 - now) / AUTO_REFRESH_TICK_DURATION_MS); this._debug("#_autoRefreshTokenTick()", `access token expires in ${expiresInTicks} ticks, a tick lasts ${AUTO_REFRESH_TICK_DURATION_MS}ms, refresh threshold is ${AUTO_REFRESH_TICK_THRESHOLD} ticks`); if (expiresInTicks <= AUTO_REFRESH_TICK_THRESHOLD) { await this._callRefreshToken(session.refresh_token); } }); } catch (e) { console.error("Auto refresh tick failed with error. This is likely a transient error.", e); } } finally { this._debug("#_autoRefreshTokenTick()", "end"); } }); } catch (e) { if (e.isAcquireTimeout || e instanceof LockAcquireTimeoutError) { this._debug("auto refresh token tick lock not available"); } else { throw e; } } } /** * Registers callbacks on the browser / platform, which in-turn run * algorithms when the browser window/tab are in foreground. On non-browser * platforms it assumes always foreground. */ async _handleVisibilityChange() { this._debug("#_handleVisibilityChange()"); if (!isBrowser() || !(window === null || window === void 0 ? void 0 : window.addEventListener)) { if (this.autoRefreshToken) { this.startAutoRefresh(); } return false; } try { this.visibilityChangedCallback = async () => await this._onVisibilityChanged(false); window === null || window === void 0 ? void 0 : window.addEventListener("visibilitychange", this.visibilityChangedCallback); await this._onVisibilityChanged(true); } catch (error) { console.error("_handleVisibilityChange", error); } } /** * Callback registered with `window.addEventListener('visibilitychange')`. */ async _onVisibilityChanged(calledFromInitialize) { const methodName = `#_onVisibilityChanged(${calledFromInitialize})`; this._debug(methodName, "visibilityState", document.visibilityState); if (document.visibilityState === "visible") { if (this.autoRefreshToken) { this._startAutoRefresh(); } if (!calledFromInitialize) { await this.initializePromise; await this._acquireLock(-1, async () => { if (document.visibilityState !== "visible") { this._debug(methodName, "acquired the lock to recover the session, but the browser visibilityState is no longer visible, aborting"); return; } await this._recoverAndRefresh(); }); } } else if (document.visibilityState === "hidden") { if (this.autoRefreshToken) { this._stopAutoRefresh(); } } } /** * Generates the relevant login URL for a third-party provider. * @param options.redirectTo A URL or mobile address to send the user to after they are confirmed. * @param options.scopes A space-separated list of scopes granted to the OAuth application. * @param options.queryParams An object of key-value pairs containing query parameters granted to the OAuth application. */ async _getUrlForProvider(url, provider, options) { const urlParams = [`provider=${encodeURIComponent(provider)}`]; if (options === null || options === void 0 ? void 0 : options.redirectTo) { urlParams.push(`redirect_to=${encodeURIComponent(options.redirectTo)}`); } if (options === null || options === void 0 ? void 0 : options.scopes) { urlParams.push(`scopes=${encodeURIComponent(options.scopes)}`); } if (this.flowType === "pkce") { const [codeChallenge, codeChallengeMethod] = await getCodeChallengeAndMethod(this.storage, this.storageKey); const flowParams = new URLSearchParams({ code_challenge: `${encodeURIComponent(codeChallenge)}`, code_challenge_method: `${encodeURIComponent(codeChallengeMethod)}` }); urlParams.push(flowParams.toString()); } if (options === null || options === void 0 ? void 0 : options.queryParams) { const query = new URLSearchParams(options.queryParams); urlParams.push(query.toString()); } if (options === null || options === void 0 ? void 0 : options.skipBrowserRedirect) { urlParams.push(`skip_http_redirect=${options.skipBrowserRedirect}`); } return `${url}?${urlParams.join("&")}`; } async _unenroll(params) { try { return await this._useSession(async (result) => { var _a2; const { data: sessionData, error: sessionError } = result; if (sessionError) { return this._returnResult({ data: null, error: sessionError }); } return await _request(this.fetch, "DELETE", `${this.url}/factors/${params.factorId}`, { headers: this.headers, jwt: (_a2 = sessionData === null || sessionData === void 0 ? void 0 : sessionData.session) === null || _a2 === void 0 ? void 0 : _a2.access_token }); }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: null, error }); } throw error; } } async _enroll(params) { try { return await this._useSession(async (result) => { var _a2, _b; const { data: sessionData, error: sessionError } = result; if (sessionError) { return this._returnResult({ data: null, error: sessionError }); } const body = Object.assign({ friendly_name: params.friendlyName, factor_type: params.factorType }, params.factorType === "phone" ? { phone: params.phone } : params.factorType === "totp" ? { issuer: params.issuer } : {}); const { data, error } = await _request(this.fetch, "POST", `${this.url}/factors`, { body, headers: this.headers, jwt: (_a2 = sessionData === null || sessionData === void 0 ? void 0 : sessionData.session) === null || _a2 === void 0 ? void 0 : _a2.access_token }); if (error) { return this._returnResult({ data: null, error }); } if (params.factorType === "totp" && data.type === "totp" && ((_b = data === null || data === void 0 ? void 0 : data.totp) === null || _b === void 0 ? void 0 : _b.qr_code)) { data.totp.qr_code = `data:image/svg+xml;utf-8,${data.totp.qr_code}`; } return this._returnResult({ data, error: null }); }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: null, error }); } throw error; } } async _verify(params) { return this._acquireLock(-1, async () => { try { return await this._useSession(async (result) => { var _a2; const { data: sessionData, error: sessionError } = result; if (sessionError) { return this._returnResult({ data: null, error: sessionError }); } const body = Object.assign({ challenge_id: params.challengeId }, "webauthn" in params ? { webauthn: Object.assign(Object.assign({}, params.webauthn), { credential_response: params.webauthn.type === "create" ? serializeCredentialCreationResponse(params.webauthn.credential_response) : serializeCredentialRequestResponse(params.webauthn.credential_response) }) } : { code: params.code }); const { data, error } = await _request(this.fetch, "POST", `${this.url}/factors/${params.factorId}/verify`, { body, headers: this.headers, jwt: (_a2 = sessionData === null || sessionData === void 0 ? void 0 : sessionData.session) === null || _a2 === void 0 ? void 0 : _a2.access_token }); if (error) { return this._returnResult({ data: null, error }); } await this._saveSession(Object.assign({ expires_at: Math.round(Date.now() / 1e3) + data.expires_in }, data)); await this._notifyAllSubscribers("MFA_CHALLENGE_VERIFIED", data); return this._returnResult({ data, error }); }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: null, error }); } throw error; } }); } async _challenge(params) { return this._acquireLock(-1, async () => { try { return await this._useSession(async (result) => { var _a2; const { data: sessionData, error: sessionError } = result; if (sessionError) { return this._returnResult({ data: null, error: sessionError }); } const response = await _request(this.fetch, "POST", `${this.url}/factors/${params.factorId}/challenge`, { body: params, headers: this.headers, jwt: (_a2 = sessionData === null || sessionData === void 0 ? void 0 : sessionData.session) === null || _a2 === void 0 ? void 0 : _a2.access_token }); if (response.error) { return response; } const { data } = response; if (data.type !== "webauthn") { return { data, error: null }; } switch (data.webauthn.type) { case "create": return { data: Object.assign(Object.assign({}, data), { webauthn: Object.assign(Object.assign({}, data.webauthn), { credential_options: Object.assign(Object.assign({}, data.webauthn.credential_options), { publicKey: deserializeCredentialCreationOptions(data.webauthn.credential_options.publicKey) }) }) }), error: null }; case "request": return { data: Object.assign(Object.assign({}, data), { webauthn: Object.assign(Object.assign({}, data.webauthn), { credential_options: Object.assign(Object.assign({}, data.webauthn.credential_options), { publicKey: deserializeCredentialRequestOptions(data.webauthn.credential_options.publicKey) }) }) }), error: null }; } }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: null, error }); } throw error; } }); } /** * {@see GoTrueMFAApi#challengeAndVerify} */ async _challengeAndVerify(params) { const { data: challengeData, error: challengeError } = await this._challenge({ factorId: params.factorId }); if (challengeError) { return this._returnResult({ data: null, error: challengeError }); } return await this._verify({ factorId: params.factorId, challengeId: challengeData.id, code: params.code }); } /** * {@see GoTrueMFAApi#listFactors} */ async _listFactors() { var _a2; const { data: { user }, error: userError } = await this.getUser(); if (userError) { return { data: null, error: userError }; } const data = { all: [], phone: [], totp: [], webauthn: [] }; for (const factor of (_a2 = user === null || user === void 0 ? void 0 : user.factors) !== null && _a2 !== void 0 ? _a2 : []) { data.all.push(factor); if (factor.status === "verified") { ; data[factor.factor_type].push(factor); } } return { data, error: null }; } /** * {@see GoTrueMFAApi#getAuthenticatorAssuranceLevel} */ async _getAuthenticatorAssuranceLevel() { var _a2, _b; const { data: { session }, error: sessionError } = await this.getSession(); if (sessionError) { return this._returnResult({ data: null, error: sessionError }); } if (!session) { return { data: { currentLevel: null, nextLevel: null, currentAuthenticationMethods: [] }, error: null }; } const { payload } = decodeJWT(session.access_token); let currentLevel = null; if (payload.aal) { currentLevel = payload.aal; } let nextLevel = currentLevel; const verifiedFactors = (_b = (_a2 = session.user.factors) === null || _a2 === void 0 ? void 0 : _a2.filter((factor) => factor.status === "verified")) !== null && _b !== void 0 ? _b : []; if (verifiedFactors.length > 0) { nextLevel = "aal2"; } const currentAuthenticationMethods = payload.amr || []; return { data: { currentLevel, nextLevel, currentAuthenticationMethods }, error: null }; } /** * Retrieves details about an OAuth authorization request. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. * * Returns authorization details including client info, scopes, and user information. * If the API returns a redirect_uri, it means consent was already given - the caller * should handle the redirect manually if needed. */ async _getAuthorizationDetails(authorizationId) { try { return await this._useSession(async (result) => { const { data: { session }, error: sessionError } = result; if (sessionError) { return this._returnResult({ data: null, error: sessionError }); } if (!session) { return this._returnResult({ data: null, error: new AuthSessionMissingError() }); } return await _request(this.fetch, "GET", `${this.url}/oauth/authorizations/${authorizationId}`, { headers: this.headers, jwt: session.access_token, xform: (data) => ({ data, error: null }) }); }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: null, error }); } throw error; } } /** * Approves an OAuth authorization request. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. */ async _approveAuthorization(authorizationId, options) { try { return await this._useSession(async (result) => { const { data: { session }, error: sessionError } = result; if (sessionError) { return this._returnResult({ data: null, error: sessionError }); } if (!session) { return this._returnResult({ data: null, error: new AuthSessionMissingError() }); } const response = await _request(this.fetch, "POST", `${this.url}/oauth/authorizations/${authorizationId}/consent`, { headers: this.headers, jwt: session.access_token, body: { action: "approve" }, xform: (data) => ({ data, error: null }) }); if (response.data && response.data.redirect_url) { if (isBrowser() && !(options === null || options === void 0 ? void 0 : options.skipBrowserRedirect)) { window.location.assign(response.data.redirect_url); } } return response; }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: null, error }); } throw error; } } /** * Denies an OAuth authorization request. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. */ async _denyAuthorization(authorizationId, options) { try { return await this._useSession(async (result) => { const { data: { session }, error: sessionError } = result; if (sessionError) { return this._returnResult({ data: null, error: sessionError }); } if (!session) { return this._returnResult({ data: null, error: new AuthSessionMissingError() }); } const response = await _request(this.fetch, "POST", `${this.url}/oauth/authorizations/${authorizationId}/consent`, { headers: this.headers, jwt: session.access_token, body: { action: "deny" }, xform: (data) => ({ data, error: null }) }); if (response.data && response.data.redirect_url) { if (isBrowser() && !(options === null || options === void 0 ? void 0 : options.skipBrowserRedirect)) { window.location.assign(response.data.redirect_url); } } return response; }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: null, error }); } throw error; } } /** * Lists all OAuth grants that the authenticated user has authorized. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. */ async _listOAuthGrants() { try { return await this._useSession(async (result) => { const { data: { session }, error: sessionError } = result; if (sessionError) { return this._returnResult({ data: null, error: sessionError }); } if (!session) { return this._returnResult({ data: null, error: new AuthSessionMissingError() }); } return await _request(this.fetch, "GET", `${this.url}/user/oauth/grants`, { headers: this.headers, jwt: session.access_token, xform: (data) => ({ data, error: null }) }); }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: null, error }); } throw error; } } /** * Revokes a user's OAuth grant for a specific client. * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth. */ async _revokeOAuthGrant(options) { try { return await this._useSession(async (result) => { const { data: { session }, error: sessionError } = result; if (sessionError) { return this._returnResult({ data: null, error: sessionError }); } if (!session) { return this._returnResult({ data: null, error: new AuthSessionMissingError() }); } await _request(this.fetch, "DELETE", `${this.url}/user/oauth/grants`, { headers: this.headers, jwt: session.access_token, query: { client_id: options.clientId }, noResolveJson: true }); return { data: {}, error: null }; }); } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: null, error }); } throw error; } } async fetchJwk(kid, jwks = { keys: [] }) { let jwk = jwks.keys.find((key) => key.kid === kid); if (jwk) { return jwk; } const now = Date.now(); jwk = this.jwks.keys.find((key) => key.kid === kid); if (jwk && this.jwks_cached_at + JWKS_TTL > now) { return jwk; } const { data, error } = await _request(this.fetch, "GET", `${this.url}/.well-known/jwks.json`, { headers: this.headers }); if (error) { throw error; } if (!data.keys || data.keys.length === 0) { return null; } this.jwks = data; this.jwks_cached_at = now; jwk = data.keys.find((key) => key.kid === kid); if (!jwk) { return null; } return jwk; } /** * Extracts the JWT claims present in the access token by first verifying the * JWT against the server's JSON Web Key Set endpoint * `/.well-known/jwks.json` which is often cached, resulting in significantly * faster responses. Prefer this method over {@link #getUser} which always * sends a request to the Auth server for each JWT. * * If the project is not using an asymmetric JWT signing key (like ECC or * RSA) it always sends a request to the Auth server (similar to {@link * #getUser}) to verify the JWT. * * @param jwt An optional specific JWT you wish to verify, not the one you * can obtain from {@link #getSession}. * @param options Various additional options that allow you to customize the * behavior of this method. */ async getClaims(jwt, options = {}) { try { let token = jwt; if (!token) { const { data, error } = await this.getSession(); if (error || !data.session) { return this._returnResult({ data: null, error }); } token = data.session.access_token; } const { header, payload, signature, raw: { header: rawHeader, payload: rawPayload } } = decodeJWT(token); if (!(options === null || options === void 0 ? void 0 : options.allowExpired)) { validateExp(payload.exp); } const signingKey = !header.alg || header.alg.startsWith("HS") || !header.kid || !("crypto" in globalThis && "subtle" in globalThis.crypto) ? null : await this.fetchJwk(header.kid, (options === null || options === void 0 ? void 0 : options.keys) ? { keys: options.keys } : options === null || options === void 0 ? void 0 : options.jwks); if (!signingKey) { const { error } = await this.getUser(token); if (error) { throw error; } return { data: { claims: payload, header, signature }, error: null }; } const algorithm = getAlgorithm(header.alg); const publicKey = await crypto.subtle.importKey("jwk", signingKey, algorithm, true, [ "verify" ]); const isValid = await crypto.subtle.verify(algorithm, publicKey, signature, stringToUint8Array(`${rawHeader}.${rawPayload}`)); if (!isValid) { throw new AuthInvalidJwtError("Invalid JWT signature"); } return { data: { claims: payload, header, signature }, error: null }; } catch (error) { if (isAuthError(error)) { return this._returnResult({ data: null, error }); } throw error; } } }; GoTrueClient.nextInstanceID = {}; GoTrueClient_default = GoTrueClient; } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/AuthAdminApi.js var AuthAdminApi, AuthAdminApi_default; var init_AuthAdminApi = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/AuthAdminApi.js"() { init_GoTrueAdminApi(); AuthAdminApi = GoTrueAdminApi; AuthAdminApi_default = AuthAdminApi; } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/AuthClient.js var AuthClient, AuthClient_default; var init_AuthClient = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/AuthClient.js"() { init_GoTrueClient(); AuthClient = GoTrueClient_default; AuthClient_default = AuthClient; } }); // ../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/index.js var module_exports4 = {}; __export(module_exports4, { AuthAdminApi: () => AuthAdminApi_default, AuthApiError: () => AuthApiError, AuthClient: () => AuthClient_default, AuthError: () => AuthError, AuthImplicitGrantRedirectError: () => AuthImplicitGrantRedirectError, AuthInvalidCredentialsError: () => AuthInvalidCredentialsError, AuthInvalidJwtError: () => AuthInvalidJwtError, AuthInvalidTokenResponseError: () => AuthInvalidTokenResponseError, AuthPKCEGrantCodeExchangeError: () => AuthPKCEGrantCodeExchangeError, AuthRetryableFetchError: () => AuthRetryableFetchError, AuthSessionMissingError: () => AuthSessionMissingError, AuthUnknownError: () => AuthUnknownError, AuthWeakPasswordError: () => AuthWeakPasswordError, CustomAuthError: () => CustomAuthError, GoTrueAdminApi: () => GoTrueAdminApi, GoTrueClient: () => GoTrueClient_default, NavigatorLockAcquireTimeoutError: () => NavigatorLockAcquireTimeoutError, SIGN_OUT_SCOPES: () => SIGN_OUT_SCOPES, isAuthApiError: () => isAuthApiError, isAuthError: () => isAuthError, isAuthImplicitGrantRedirectError: () => isAuthImplicitGrantRedirectError, isAuthRetryableFetchError: () => isAuthRetryableFetchError, isAuthSessionMissingError: () => isAuthSessionMissingError, isAuthWeakPasswordError: () => isAuthWeakPasswordError, lockInternals: () => internals, navigatorLock: () => navigatorLock, processLock: () => processLock }); var init_module4 = __esm({ "../../node_modules/.pnpm/@supabase+auth-js@2.86.2/node_modules/@supabase/auth-js/dist/module/index.js"() { init_GoTrueAdminApi(); init_GoTrueClient(); init_AuthAdminApi(); init_AuthClient(); init_types3(); init_errors3(); init_locks(); } }); // ../../node_modules/.pnpm/@supabase+supabase-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/supabase-js/dist/main/lib/SupabaseAuthClient.js var require_SupabaseAuthClient = __commonJS({ "../../node_modules/.pnpm/@supabase+supabase-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/supabase-js/dist/main/lib/SupabaseAuthClient.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SupabaseAuthClient = void 0; var auth_js_1 = (init_module4(), __toCommonJS(module_exports4)); var SupabaseAuthClient = class extends auth_js_1.AuthClient { constructor(options) { super(options); } }; exports.SupabaseAuthClient = SupabaseAuthClient; } }); // ../../node_modules/.pnpm/@supabase+supabase-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/supabase-js/dist/main/SupabaseClient.js var require_SupabaseClient = __commonJS({ "../../node_modules/.pnpm/@supabase+supabase-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/supabase-js/dist/main/SupabaseClient.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var functions_js_1 = (init_module(), __toCommonJS(module_exports)); var postgrest_js_1 = require_cjs(); var realtime_js_1 = (init_module2(), __toCommonJS(module_exports2)); var storage_js_1 = (init_module3(), __toCommonJS(module_exports3)); var constants_1 = require_constants(); var fetch_1 = require_fetch(); var helpers_1 = require_helpers(); var SupabaseAuthClient_1 = require_SupabaseAuthClient(); var SupabaseClient2 = class { /** * Create a new client for use in the browser. * @param supabaseUrl The unique Supabase URL which is supplied when you create a new project in your project dashboard. * @param supabaseKey The unique Supabase Key which is supplied when you create a new project in your project dashboard. * @param options.db.schema You can switch in between schemas. The schema needs to be on the list of exposed schemas inside Supabase. * @param options.auth.autoRefreshToken Set to "true" if you want to automatically refresh the token before expiring. * @param options.auth.persistSession Set to "true" if you want to automatically save the user session into local storage. * @param options.auth.detectSessionInUrl Set to "true" if you want to automatically detects OAuth grants in the URL and signs in the user. * @param options.realtime Options passed along to realtime-js constructor. * @param options.storage Options passed along to the storage-js constructor. * @param options.global.fetch A custom fetch implementation. * @param options.global.headers Any additional headers to send with each network request. * @example * ```ts * import { createClient } from '@supabase/supabase-js' * * const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key') * const { data } = await supabase.from('profiles').select('*') * ``` */ constructor(supabaseUrl, supabaseKey, options) { var _a2, _b, _c; this.supabaseUrl = supabaseUrl; this.supabaseKey = supabaseKey; const baseUrl = (0, helpers_1.validateSupabaseUrl)(supabaseUrl); if (!supabaseKey) throw new Error("supabaseKey is required."); this.realtimeUrl = new URL("realtime/v1", baseUrl); this.realtimeUrl.protocol = this.realtimeUrl.protocol.replace("http", "ws"); this.authUrl = new URL("auth/v1", baseUrl); this.storageUrl = new URL("storage/v1", baseUrl); this.functionsUrl = new URL("functions/v1", baseUrl); const defaultStorageKey = `sb-${baseUrl.hostname.split(".")[0]}-auth-token`; const DEFAULTS = { db: constants_1.DEFAULT_DB_OPTIONS, realtime: constants_1.DEFAULT_REALTIME_OPTIONS, auth: Object.assign(Object.assign({}, constants_1.DEFAULT_AUTH_OPTIONS), { storageKey: defaultStorageKey }), global: constants_1.DEFAULT_GLOBAL_OPTIONS }; const settings = (0, helpers_1.applySettingDefaults)(options !== null && options !== void 0 ? options : {}, DEFAULTS); this.storageKey = (_a2 = settings.auth.storageKey) !== null && _a2 !== void 0 ? _a2 : ""; this.headers = (_b = settings.global.headers) !== null && _b !== void 0 ? _b : {}; if (!settings.accessToken) { this.auth = this._initSupabaseAuthClient((_c = settings.auth) !== null && _c !== void 0 ? _c : {}, this.headers, settings.global.fetch); } else { this.accessToken = settings.accessToken; this.auth = new Proxy({}, { get: (_, prop) => { throw new Error(`@supabase/supabase-js: Supabase Client is configured with the accessToken option, accessing supabase.auth.${String(prop)} is not possible`); } }); } this.fetch = (0, fetch_1.fetchWithAuth)(supabaseKey, this._getAccessToken.bind(this), settings.global.fetch); this.realtime = this._initRealtimeClient(Object.assign({ headers: this.headers, accessToken: this._getAccessToken.bind(this) }, settings.realtime)); if (this.accessToken) { this.accessToken().then((token) => this.realtime.setAuth(token)).catch((e) => console.warn("Failed to set initial Realtime auth token:", e)); } this.rest = new postgrest_js_1.PostgrestClient(new URL("rest/v1", baseUrl).href, { headers: this.headers, schema: settings.db.schema, fetch: this.fetch }); this.storage = new storage_js_1.StorageClient(this.storageUrl.href, this.headers, this.fetch, options === null || options === void 0 ? void 0 : options.storage); if (!settings.accessToken) { this._listenForAuthEvents(); } } /** * Supabase Functions allows you to deploy and invoke edge functions. */ get functions() { return new functions_js_1.FunctionsClient(this.functionsUrl.href, { headers: this.headers, customFetch: this.fetch }); } /** * Perform a query on a table or a view. * * @param relation - The table or view name to query */ from(relation) { return this.rest.from(relation); } // NOTE: signatures must be kept in sync with PostgrestClient.schema /** * Select a schema to query or perform an function (rpc) call. * * The schema needs to be on the list of exposed schemas inside Supabase. * * @param schema - The schema to query */ schema(schema) { return this.rest.schema(schema); } // NOTE: signatures must be kept in sync with PostgrestClient.rpc /** * Perform a function call. * * @param fn - The function name to call * @param args - The arguments to pass to the function call * @param options - Named parameters * @param options.head - When set to `true`, `data` will not be returned. * Useful if you only need the count. * @param options.get - When set to `true`, the function will be called with * read-only access mode. * @param options.count - Count algorithm to use to count rows returned by the * function. Only applicable for [set-returning * functions](https://www.postgresql.org/docs/current/functions-srf.html). * * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the * hood. * * `"planned"`: Approximated but fast count algorithm. Uses the Postgres * statistics under the hood. * * `"estimated"`: Uses exact count for low numbers and planned count for high * numbers. */ rpc(fn, args = {}, options = { head: false, get: false, count: void 0 }) { return this.rest.rpc(fn, args, options); } /** * Creates a Realtime channel with Broadcast, Presence, and Postgres Changes. * * @param {string} name - The name of the Realtime channel. * @param {Object} opts - The options to pass to the Realtime channel. * */ channel(name, opts = { config: {} }) { return this.realtime.channel(name, opts); } /** * Returns all Realtime channels. */ getChannels() { return this.realtime.getChannels(); } /** * Unsubscribes and removes Realtime channel from Realtime client. * * @param {RealtimeChannel} channel - The name of the Realtime channel. * */ removeChannel(channel) { return this.realtime.removeChannel(channel); } /** * Unsubscribes and removes all Realtime channels from Realtime client. */ removeAllChannels() { return this.realtime.removeAllChannels(); } async _getAccessToken() { var _a2, _b; if (this.accessToken) { return await this.accessToken(); } const { data } = await this.auth.getSession(); return (_b = (_a2 = data.session) === null || _a2 === void 0 ? void 0 : _a2.access_token) !== null && _b !== void 0 ? _b : this.supabaseKey; } _initSupabaseAuthClient({ autoRefreshToken, persistSession, detectSessionInUrl, storage, userStorage, storageKey, flowType, lock, debug, throwOnError }, headers, fetch2) { const authHeaders = { Authorization: `Bearer ${this.supabaseKey}`, apikey: `${this.supabaseKey}` }; return new SupabaseAuthClient_1.SupabaseAuthClient({ url: this.authUrl.href, headers: Object.assign(Object.assign({}, authHeaders), headers), storageKey, autoRefreshToken, persistSession, detectSessionInUrl, storage, userStorage, flowType, lock, debug, throwOnError, fetch: fetch2, // auth checks if there is a custom authorizaiton header using this flag // so it knows whether to return an error when getUser is called with no session hasCustomAuthorizationHeader: Object.keys(this.headers).some((key) => key.toLowerCase() === "authorization") }); } _initRealtimeClient(options) { return new realtime_js_1.RealtimeClient(this.realtimeUrl.href, Object.assign(Object.assign({}, options), { params: Object.assign({ apikey: this.supabaseKey }, options === null || options === void 0 ? void 0 : options.params) })); } _listenForAuthEvents() { const data = this.auth.onAuthStateChange((event, session) => { this._handleTokenChanged(event, "CLIENT", session === null || session === void 0 ? void 0 : session.access_token); }); return data; } _handleTokenChanged(event, source, token) { if ((event === "TOKEN_REFRESHED" || event === "SIGNED_IN") && this.changedAccessToken !== token) { this.changedAccessToken = token; this.realtime.setAuth(token); } else if (event === "SIGNED_OUT") { this.realtime.setAuth(); if (source == "STORAGE") this.auth.signOut(); this.changedAccessToken = void 0; } } }; exports.default = SupabaseClient2; } }); // ../../node_modules/.pnpm/@supabase+supabase-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/supabase-js/dist/main/index.js var require_main = __commonJS({ "../../node_modules/.pnpm/@supabase+supabase-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/supabase-js/dist/main/index.js"(exports) { "use strict"; var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) { if (k2 === void 0) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === void 0) k2 = k; o[k2] = m[k]; })); var __exportStar = exports && exports.__exportStar || function(m, exports2) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p); }; var __importDefault = exports && exports.__importDefault || function(mod) { return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createClient = exports.SupabaseClient = exports.FunctionRegion = exports.FunctionsError = exports.FunctionsRelayError = exports.FunctionsFetchError = exports.FunctionsHttpError = exports.PostgrestError = void 0; var SupabaseClient_1 = __importDefault(require_SupabaseClient()); __exportStar((init_module4(), __toCommonJS(module_exports4)), exports); var postgrest_js_1 = require_cjs(); Object.defineProperty(exports, "PostgrestError", { enumerable: true, get: function() { return postgrest_js_1.PostgrestError; } }); var functions_js_1 = (init_module(), __toCommonJS(module_exports)); Object.defineProperty(exports, "FunctionsHttpError", { enumerable: true, get: function() { return functions_js_1.FunctionsHttpError; } }); Object.defineProperty(exports, "FunctionsFetchError", { enumerable: true, get: function() { return functions_js_1.FunctionsFetchError; } }); Object.defineProperty(exports, "FunctionsRelayError", { enumerable: true, get: function() { return functions_js_1.FunctionsRelayError; } }); Object.defineProperty(exports, "FunctionsError", { enumerable: true, get: function() { return functions_js_1.FunctionsError; } }); Object.defineProperty(exports, "FunctionRegion", { enumerable: true, get: function() { return functions_js_1.FunctionRegion; } }); __exportStar((init_module2(), __toCommonJS(module_exports2)), exports); var SupabaseClient_2 = require_SupabaseClient(); Object.defineProperty(exports, "SupabaseClient", { enumerable: true, get: function() { return __importDefault(SupabaseClient_2).default; } }); var createClient2 = (supabaseUrl, supabaseKey, options) => { return new SupabaseClient_1.default(supabaseUrl, supabaseKey, options); }; exports.createClient = createClient2; function shouldShowDeprecationWarning() { if (typeof window !== "undefined") { return false; } if (typeof process === "undefined") { return false; } const processVersion = process["version"]; if (processVersion === void 0 || processVersion === null) { return false; } const versionMatch = processVersion.match(/^v(\d+)\./); if (!versionMatch) { return false; } const majorVersion = parseInt(versionMatch[1], 10); return majorVersion <= 18; } 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`); } } }); // ../../node_modules/.pnpm/@supabase+supabase-js@2.86.2_bufferutil@4.1.0_utf-8-validate@5.0.10/node_modules/@supabase/supabase-js/dist/esm/wrapper.mjs var index = __toESM(require_main(), 1); var { PostgrestError, FunctionsHttpError: FunctionsHttpError2, FunctionsFetchError: FunctionsFetchError2, FunctionsRelayError: FunctionsRelayError2, FunctionsError: FunctionsError2, FunctionRegion: FunctionRegion2, SupabaseClient, createClient, GoTrueAdminApi: GoTrueAdminApi2, GoTrueClient: GoTrueClient2, AuthAdminApi: AuthAdminApi2, AuthClient: AuthClient2, navigatorLock: navigatorLock2, NavigatorLockAcquireTimeoutError: NavigatorLockAcquireTimeoutError2, lockInternals, processLock: processLock2, SIGN_OUT_SCOPES: SIGN_OUT_SCOPES2, AuthError: AuthError2, AuthApiError: AuthApiError2, AuthUnknownError: AuthUnknownError2, CustomAuthError: CustomAuthError2, AuthSessionMissingError: AuthSessionMissingError2, AuthInvalidTokenResponseError: AuthInvalidTokenResponseError2, AuthInvalidCredentialsError: AuthInvalidCredentialsError2, AuthImplicitGrantRedirectError: AuthImplicitGrantRedirectError2, AuthPKCEGrantCodeExchangeError: AuthPKCEGrantCodeExchangeError2, AuthRetryableFetchError: AuthRetryableFetchError2, AuthWeakPasswordError: AuthWeakPasswordError2, AuthInvalidJwtError: AuthInvalidJwtError2, isAuthError: isAuthError2, isAuthApiError: isAuthApiError2, isAuthSessionMissingError: isAuthSessionMissingError2, isAuthImplicitGrantRedirectError: isAuthImplicitGrantRedirectError2, isAuthRetryableFetchError: isAuthRetryableFetchError2, isAuthWeakPasswordError: isAuthWeakPasswordError2, RealtimePresence: RealtimePresence2, RealtimeChannel: RealtimeChannel2, RealtimeClient: RealtimeClient2, REALTIME_LISTEN_TYPES: REALTIME_LISTEN_TYPES2, REALTIME_POSTGRES_CHANGES_LISTEN_EVENT: REALTIME_POSTGRES_CHANGES_LISTEN_EVENT2, REALTIME_PRESENCE_LISTEN_EVENTS: REALTIME_PRESENCE_LISTEN_EVENTS2, REALTIME_SUBSCRIBE_STATES: REALTIME_SUBSCRIBE_STATES2, REALTIME_CHANNEL_STATES: REALTIME_CHANNEL_STATES2 } = index.default || index; var wrapper_default = index.default || index; export { AuthAdminApi2 as AuthAdminApi, AuthApiError2 as AuthApiError, AuthClient2 as AuthClient, AuthError2 as AuthError, AuthImplicitGrantRedirectError2 as AuthImplicitGrantRedirectError, AuthInvalidCredentialsError2 as AuthInvalidCredentialsError, AuthInvalidJwtError2 as AuthInvalidJwtError, AuthInvalidTokenResponseError2 as AuthInvalidTokenResponseError, AuthPKCEGrantCodeExchangeError2 as AuthPKCEGrantCodeExchangeError, AuthRetryableFetchError2 as AuthRetryableFetchError, AuthSessionMissingError2 as AuthSessionMissingError, AuthUnknownError2 as AuthUnknownError, AuthWeakPasswordError2 as AuthWeakPasswordError, CustomAuthError2 as CustomAuthError, FunctionRegion2 as FunctionRegion, FunctionsError2 as FunctionsError, FunctionsFetchError2 as FunctionsFetchError, FunctionsHttpError2 as FunctionsHttpError, FunctionsRelayError2 as FunctionsRelayError, GoTrueAdminApi2 as GoTrueAdminApi, GoTrueClient2 as GoTrueClient, NavigatorLockAcquireTimeoutError2 as NavigatorLockAcquireTimeoutError, PostgrestError, REALTIME_CHANNEL_STATES2 as REALTIME_CHANNEL_STATES, REALTIME_LISTEN_TYPES2 as REALTIME_LISTEN_TYPES, REALTIME_POSTGRES_CHANGES_LISTEN_EVENT2 as REALTIME_POSTGRES_CHANGES_LISTEN_EVENT, REALTIME_PRESENCE_LISTEN_EVENTS2 as REALTIME_PRESENCE_LISTEN_EVENTS, REALTIME_SUBSCRIBE_STATES2 as REALTIME_SUBSCRIBE_STATES, RealtimeChannel2 as RealtimeChannel, RealtimeClient2 as RealtimeClient, RealtimePresence2 as RealtimePresence, SIGN_OUT_SCOPES2 as SIGN_OUT_SCOPES, SupabaseClient, createClient, wrapper_default as default, isAuthApiError2 as isAuthApiError, isAuthError2 as isAuthError, isAuthImplicitGrantRedirectError2 as isAuthImplicitGrantRedirectError, isAuthRetryableFetchError2 as isAuthRetryableFetchError, isAuthSessionMissingError2 as isAuthSessionMissingError, isAuthWeakPasswordError2 as isAuthWeakPasswordError, lockInternals, navigatorLock2 as navigatorLock, processLock2 as processLock }; //# sourceMappingURL=@supabase_supabase-js.js.map