@ai-matrx/auth 0.3.4 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +1 -0
- package/dist/{auth-cookie-DWx6Q3xo.d.cts → auth-cookie-QPVLJJwP.d.cts} +11 -2
- package/dist/{auth-cookie-DWx6Q3xo.d.ts → auth-cookie-QPVLJJwP.d.ts} +11 -2
- package/dist/browser.cjs +192 -0
- package/dist/browser.d.cts +34 -0
- package/dist/browser.d.ts +34 -0
- package/dist/browser.js +169 -0
- package/dist/{claims-KrRxsfaG.d.cts → claims-Vno769TE.d.cts} +1 -1
- package/dist/{claims-KrRxsfaG.d.ts → claims-Vno769TE.d.ts} +1 -1
- package/dist/cookies.cjs +6 -3
- package/dist/cookies.d.cts +1 -1
- package/dist/cookies.d.ts +1 -1
- package/dist/cookies.js +6 -3
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/matrx-oauth.cjs +2 -2
- package/dist/matrx-oauth.js +2 -2
- package/dist/next.cjs +71 -56
- package/dist/next.d.cts +7 -13
- package/dist/next.d.ts +7 -13
- package/dist/next.js +65 -51
- package/package.json +12 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog — @ai-matrx/auth
|
|
2
2
|
|
|
3
|
+
## 0.3.6
|
|
4
|
+
### Unreleased
|
|
5
|
+
- New `@ai-matrx/auth/browser` (`createBrowserSupabase`, shared code path with `createNextSupabase().browserClient()`).
|
|
6
|
+
- New `MATRX_AUTH_COOKIE` ({ current, legacy }). BREAKING: `DEFAULT_AUTH_COOKIE_NAME` removed; the default cookie name is now `sb-matrx-auth-v2`.
|
|
7
|
+
|
|
8
|
+
## 0.3.5
|
|
9
|
+
|
|
10
|
+
Automatic changed-only republish (docs/metadata drift since the last tag — see
|
|
11
|
+
`git diff npm/auth/v0.3.4..npm/auth/v0.3.5 -- apps/shared/auth`).
|
|
12
|
+
No source changes intended and no consumer action required.
|
|
13
|
+
|
|
3
14
|
## 0.3.4
|
|
4
15
|
|
|
5
16
|
Automatic changed-only republish (docs/metadata drift since the last tag — see
|
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ const credentials = sessionCredentials(supabase); // hand to @ai-matrx/api's c
|
|
|
22
22
|
| `/session-identity` | who is acting, live from the session |
|
|
23
23
|
| `/cookies` | the domain-wide auth cookie and the active-organization cookie |
|
|
24
24
|
| `/next` | every Next.js Supabase client (browser, RSC, route, middleware) |
|
|
25
|
+
| `/browser` | the framework-free browser Supabase client over the shared auth cookie (non-Next apps) |
|
|
25
26
|
| `/react` | `useSession`, `useActiveOrganization`, `useSessionIdentity` |
|
|
26
27
|
| `/node` | `fileStorage` — a script's session survives between runs |
|
|
27
28
|
| `/testing` | fake sessions for tests |
|
|
@@ -48,7 +48,16 @@ interface AuthCookieValue {
|
|
|
48
48
|
name: string;
|
|
49
49
|
value: string;
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
/**
|
|
52
|
+
* THE one auth-cookie name pair every Matrx host binds to. `current` is the live storage key;
|
|
53
|
+
* `legacy` is the superseded key (West-project era) that `migrateLegacyCookies` seeds from and
|
|
54
|
+
* the middleware clears. Every caller passes this pair; the old single-name default (which was
|
|
55
|
+
* the LEGACY name) is retired.
|
|
56
|
+
*/
|
|
57
|
+
declare const MATRX_AUTH_COOKIE: {
|
|
58
|
+
readonly current: "sb-matrx-auth-v2";
|
|
59
|
+
readonly legacy: "sb-matrx-auth";
|
|
60
|
+
};
|
|
52
61
|
interface CreateAuthCookieArgs {
|
|
53
62
|
/** The apex domain one login must span (e.g. `"aimatrx.com"`). */
|
|
54
63
|
apexDomain: string;
|
|
@@ -165,4 +174,4 @@ interface ReconciledAuthCookies {
|
|
|
165
174
|
declare function parseCookieHeader(header: string | null | undefined): AuthCookieValue[];
|
|
166
175
|
declare function createAuthCookie(args: CreateAuthCookieArgs): AuthCookie;
|
|
167
176
|
|
|
168
|
-
export { type AuthCookie as A, type CreateAuthCookieArgs as C,
|
|
177
|
+
export { type AuthCookie as A, type CreateAuthCookieArgs as C, MATRX_AUTH_COOKIE as M, type ReconciledAuthCookies as R, type AuthCookieOptions as a, type AuthCookieValue as b, createAuthCookie as c, parseCookieHeader as p };
|
|
@@ -48,7 +48,16 @@ interface AuthCookieValue {
|
|
|
48
48
|
name: string;
|
|
49
49
|
value: string;
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
/**
|
|
52
|
+
* THE one auth-cookie name pair every Matrx host binds to. `current` is the live storage key;
|
|
53
|
+
* `legacy` is the superseded key (West-project era) that `migrateLegacyCookies` seeds from and
|
|
54
|
+
* the middleware clears. Every caller passes this pair; the old single-name default (which was
|
|
55
|
+
* the LEGACY name) is retired.
|
|
56
|
+
*/
|
|
57
|
+
declare const MATRX_AUTH_COOKIE: {
|
|
58
|
+
readonly current: "sb-matrx-auth-v2";
|
|
59
|
+
readonly legacy: "sb-matrx-auth";
|
|
60
|
+
};
|
|
52
61
|
interface CreateAuthCookieArgs {
|
|
53
62
|
/** The apex domain one login must span (e.g. `"aimatrx.com"`). */
|
|
54
63
|
apexDomain: string;
|
|
@@ -165,4 +174,4 @@ interface ReconciledAuthCookies {
|
|
|
165
174
|
declare function parseCookieHeader(header: string | null | undefined): AuthCookieValue[];
|
|
166
175
|
declare function createAuthCookie(args: CreateAuthCookieArgs): AuthCookie;
|
|
167
176
|
|
|
168
|
-
export { type AuthCookie as A, type CreateAuthCookieArgs as C,
|
|
177
|
+
export { type AuthCookie as A, type CreateAuthCookieArgs as C, MATRX_AUTH_COOKIE as M, type ReconciledAuthCookies as R, type AuthCookieOptions as a, type AuthCookieValue as b, createAuthCookie as c, parseCookieHeader as p };
|
package/dist/browser.cjs
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/browser.ts
|
|
21
|
+
var browser_exports = {};
|
|
22
|
+
__export(browser_exports, {
|
|
23
|
+
MATRX_AUTH_COOKIE: () => MATRX_AUTH_COOKIE,
|
|
24
|
+
createAuthCookie: () => createAuthCookie,
|
|
25
|
+
createBrowserSupabase: () => createBrowserSupabase
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(browser_exports);
|
|
28
|
+
|
|
29
|
+
// src/browser/supabase.ts
|
|
30
|
+
var import_ssr = require("@supabase/ssr");
|
|
31
|
+
|
|
32
|
+
// src/cookies/auth-cookie.ts
|
|
33
|
+
var MATRX_AUTH_COOKIE = {
|
|
34
|
+
current: "sb-matrx-auth-v2",
|
|
35
|
+
legacy: "sb-matrx-auth"
|
|
36
|
+
};
|
|
37
|
+
function parseCookieHeader(header) {
|
|
38
|
+
if (!header) return [];
|
|
39
|
+
const out = [];
|
|
40
|
+
for (const pair of header.split(";")) {
|
|
41
|
+
const eq = pair.indexOf("=");
|
|
42
|
+
const name = (eq === -1 ? pair : pair.slice(0, eq)).trim();
|
|
43
|
+
if (!name) continue;
|
|
44
|
+
const raw = eq === -1 ? "" : pair.slice(eq + 1).trim();
|
|
45
|
+
let value = raw;
|
|
46
|
+
try {
|
|
47
|
+
value = decodeURIComponent(raw);
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
out.push({ name, value });
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
function belongsToStorageKey(name, storageKey) {
|
|
55
|
+
if (name === storageKey) return true;
|
|
56
|
+
if (!name.startsWith(`${storageKey}.`)) return false;
|
|
57
|
+
return /^(0|[1-9][0-9]*)$/.test(name.slice(storageKey.length + 1));
|
|
58
|
+
}
|
|
59
|
+
function renamedCookie(cookie, from, to) {
|
|
60
|
+
if (cookie.name === from) return { ...cookie, name: to };
|
|
61
|
+
const prefix = `${from}.`;
|
|
62
|
+
if (!cookie.name.startsWith(prefix)) return null;
|
|
63
|
+
const chunk = cookie.name.slice(prefix.length);
|
|
64
|
+
if (!/^(0|[1-9][0-9]*)$/.test(chunk)) return null;
|
|
65
|
+
return { ...cookie, name: `${to}.${chunk}` };
|
|
66
|
+
}
|
|
67
|
+
function createAuthCookie(args) {
|
|
68
|
+
const cookieName = args.cookieName ?? MATRX_AUTH_COOKIE.current;
|
|
69
|
+
const legacyCookieName = args.legacyCookieName;
|
|
70
|
+
const apex = args.apexDomain.toLowerCase();
|
|
71
|
+
const optionsForHost = (host) => {
|
|
72
|
+
const normalized = (host ?? "").toLowerCase();
|
|
73
|
+
const hostname = normalized.startsWith("[") ? normalized.slice(1, normalized.indexOf("]")) : normalized === "::1" ? normalized : normalized.split(":")[0] ?? "";
|
|
74
|
+
const loopback = hostname === "localhost" || hostname.endsWith(".localhost") || hostname === "::1" || /^127(?:\.(?:0|[1-9]\d{0,2})){3}$/.test(hostname) && hostname.split(".").every((part) => Number(part) <= 255);
|
|
75
|
+
const secure = !loopback;
|
|
76
|
+
const onApex = hostname === apex || hostname.endsWith(`.${apex}`);
|
|
77
|
+
return onApex ? { name: cookieName, domain: `.${apex}`, secure } : { name: cookieName, secure };
|
|
78
|
+
};
|
|
79
|
+
const isCurrentCookie = (name) => belongsToStorageKey(name, cookieName);
|
|
80
|
+
const isAuthCookie = (name) => isCurrentCookie(name) || legacyCookieName !== void 0 && (name === legacyCookieName || name.startsWith(`${legacyCookieName}.`));
|
|
81
|
+
const reconcile = (cookies) => {
|
|
82
|
+
const seen = /* @__PURE__ */ new Map();
|
|
83
|
+
const out = [];
|
|
84
|
+
const shadowed = /* @__PURE__ */ new Set();
|
|
85
|
+
for (const cookie of cookies) {
|
|
86
|
+
const at = seen.get(cookie.name);
|
|
87
|
+
if (at === void 0) {
|
|
88
|
+
seen.set(cookie.name, out.length);
|
|
89
|
+
out.push({ name: cookie.name, value: cookie.value });
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (!isAuthCookie(cookie.name)) continue;
|
|
93
|
+
shadowed.add(cookie.name);
|
|
94
|
+
const held = out[at];
|
|
95
|
+
if (held !== void 0 && held.value.length === 0) {
|
|
96
|
+
out[at] = { name: cookie.name, value: cookie.value };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const ambiguous = /* @__PURE__ */ new Set();
|
|
100
|
+
const ambiguousKeys = [];
|
|
101
|
+
const byName = new Map(out.map((cookie) => [cookie.name, cookie]));
|
|
102
|
+
const storageKeys = [cookieName, ...legacyCookieName ? [legacyCookieName] : []];
|
|
103
|
+
for (const storageKey of storageKeys) {
|
|
104
|
+
const unchunked = byName.get(storageKey);
|
|
105
|
+
const firstChunk = byName.get(`${storageKey}.0`);
|
|
106
|
+
if (!unchunked?.value || !firstChunk?.value) continue;
|
|
107
|
+
ambiguousKeys.push(storageKey);
|
|
108
|
+
for (const { name } of out) {
|
|
109
|
+
if (belongsToStorageKey(name, storageKey)) ambiguous.add(name);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const resolved = ambiguous.size === 0 ? out : out.filter(({ name }) => !ambiguous.has(name));
|
|
113
|
+
const shadowedNames = [...shadowed];
|
|
114
|
+
const ambiguousNames = [...ambiguous];
|
|
115
|
+
return {
|
|
116
|
+
cookies: resolved,
|
|
117
|
+
shadowedNames,
|
|
118
|
+
ambiguousNames,
|
|
119
|
+
ambiguousKeys,
|
|
120
|
+
split: shadowedNames.length > 0 || ambiguousNames.length > 0
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
return {
|
|
124
|
+
cookieName,
|
|
125
|
+
legacyCookieName,
|
|
126
|
+
optionsForHost,
|
|
127
|
+
reconcile,
|
|
128
|
+
browserOptions: () => optionsForHost(
|
|
129
|
+
typeof window !== "undefined" ? window.location.hostname : null
|
|
130
|
+
),
|
|
131
|
+
isCurrentCookie,
|
|
132
|
+
migrateLegacyCookies: (cookies) => {
|
|
133
|
+
if (!legacyCookieName) return [];
|
|
134
|
+
if (cookies.some(({ name }) => isCurrentCookie(name))) return [];
|
|
135
|
+
return cookies.flatMap((cookie) => {
|
|
136
|
+
const renamed = renamedCookie(cookie, legacyCookieName, cookieName);
|
|
137
|
+
return renamed ? [renamed] : [];
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/browser/supabase.ts
|
|
144
|
+
var BROWSER_SLOT = /* @__PURE__ */ Symbol.for("ai-matrx.data.next.browser-client");
|
|
145
|
+
function readBrowserSlot() {
|
|
146
|
+
return globalThis[BROWSER_SLOT];
|
|
147
|
+
}
|
|
148
|
+
function writeBrowserSlot(slot) {
|
|
149
|
+
globalThis[BROWSER_SLOT] = slot;
|
|
150
|
+
}
|
|
151
|
+
function browserCookieAdapter(authCookie) {
|
|
152
|
+
return {
|
|
153
|
+
getAll: () => authCookie.reconcile(
|
|
154
|
+
typeof document === "undefined" ? [] : parseCookieHeader(document.cookie)
|
|
155
|
+
).cookies,
|
|
156
|
+
setAll: (cookiesToSet) => {
|
|
157
|
+
if (typeof document === "undefined") return;
|
|
158
|
+
for (const cookie of cookiesToSet) {
|
|
159
|
+
const options = cookie.options ?? {};
|
|
160
|
+
const parts = [
|
|
161
|
+
`${cookie.name}=${encodeURIComponent(cookie.value)}`,
|
|
162
|
+
`Path=${typeof options.path === "string" ? options.path : "/"}`
|
|
163
|
+
];
|
|
164
|
+
if (typeof options.domain === "string") {
|
|
165
|
+
parts.push(`Domain=${options.domain}`);
|
|
166
|
+
}
|
|
167
|
+
if (typeof options.maxAge === "number") {
|
|
168
|
+
parts.push(`Max-Age=${options.maxAge}`);
|
|
169
|
+
}
|
|
170
|
+
if (typeof options.sameSite === "string") {
|
|
171
|
+
parts.push(`SameSite=${options.sameSite}`);
|
|
172
|
+
}
|
|
173
|
+
if (options.secure === true || location.protocol === "https:") parts.push("Secure");
|
|
174
|
+
document.cookie = parts.join("; ");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function createBrowserSupabase(config) {
|
|
180
|
+
const slotKey = `${config.url}|${config.key}|${config.authCookie.cookieName}`;
|
|
181
|
+
const existing = readBrowserSlot();
|
|
182
|
+
if (existing && existing.key === slotKey) {
|
|
183
|
+
return existing.client;
|
|
184
|
+
}
|
|
185
|
+
const raw = (0, import_ssr.createBrowserClient)(config.url, config.key, {
|
|
186
|
+
cookieOptions: config.authCookie.browserOptions(),
|
|
187
|
+
cookies: browserCookieAdapter(config.authCookie)
|
|
188
|
+
});
|
|
189
|
+
const client = config.wrapBrowserClient ? config.wrapBrowserClient(raw) : raw;
|
|
190
|
+
writeBrowserSlot({ key: slotKey, client });
|
|
191
|
+
return client;
|
|
192
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createBrowserClient } from '@supabase/ssr';
|
|
2
|
+
import { A as AuthCookie } from './auth-cookie-QPVLJJwP.cjs';
|
|
3
|
+
export { a as AuthCookieOptions, b as AuthCookieValue, C as CreateAuthCookieArgs, M as MATRX_AUTH_COOKIE, R as ReconciledAuthCookies, c as createAuthCookie } from './auth-cookie-QPVLJJwP.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @ai-matrx/auth/browser — the framework-free browser Supabase client.
|
|
7
|
+
*
|
|
8
|
+
* This is the browser half of `createNextSupabase`, MOVED here (not rewritten) so a non-Next app
|
|
9
|
+
* (the Vite Office app) and the Next apps share ONE code path: the `globalThis`-slot singleton,
|
|
10
|
+
* `authCookie.browserOptions()` (the host decides the cookie scope: apex hosts `.aimatrx.com`,
|
|
11
|
+
* loopback and `*.localhost` host-only), and the reconcile-guarded cookie adapter.
|
|
12
|
+
* `createNextSupabase(...).browserClient()` calls `createBrowserSupabase` below.
|
|
13
|
+
*
|
|
14
|
+
* Imports nothing from `next/*` and nothing from `../next/supabase`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
type DatabaseLike = Record<string, unknown>;
|
|
18
|
+
type NextBrowserClient<DB extends DatabaseLike> = ReturnType<typeof createBrowserClient<DB>>;
|
|
19
|
+
interface CreateBrowserSupabaseConfig {
|
|
20
|
+
/** `https://db.matrxserver.com`. */
|
|
21
|
+
url: string;
|
|
22
|
+
/** The `sb_publishable_*` key. */
|
|
23
|
+
key: string;
|
|
24
|
+
/** `createAuthCookie({ cookieName: MATRX_AUTH_COOKIE.current, legacyCookieName: MATRX_AUTH_COOKIE.legacy, … })`. */
|
|
25
|
+
authCookie: AuthCookie;
|
|
26
|
+
/**
|
|
27
|
+
* Host wrapper applied to the BROWSER client only (diagnostics/error capture). Must not change
|
|
28
|
+
* query behavior.
|
|
29
|
+
*/
|
|
30
|
+
wrapBrowserClient?: <C extends object>(client: C) => C;
|
|
31
|
+
}
|
|
32
|
+
declare function createBrowserSupabase<DB extends DatabaseLike = DatabaseLike>(config: CreateBrowserSupabaseConfig): NextBrowserClient<DB>;
|
|
33
|
+
|
|
34
|
+
export { AuthCookie, type CreateBrowserSupabaseConfig, type DatabaseLike, type NextBrowserClient, createBrowserSupabase };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createBrowserClient } from '@supabase/ssr';
|
|
2
|
+
import { A as AuthCookie } from './auth-cookie-QPVLJJwP.js';
|
|
3
|
+
export { a as AuthCookieOptions, b as AuthCookieValue, C as CreateAuthCookieArgs, M as MATRX_AUTH_COOKIE, R as ReconciledAuthCookies, c as createAuthCookie } from './auth-cookie-QPVLJJwP.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @ai-matrx/auth/browser — the framework-free browser Supabase client.
|
|
7
|
+
*
|
|
8
|
+
* This is the browser half of `createNextSupabase`, MOVED here (not rewritten) so a non-Next app
|
|
9
|
+
* (the Vite Office app) and the Next apps share ONE code path: the `globalThis`-slot singleton,
|
|
10
|
+
* `authCookie.browserOptions()` (the host decides the cookie scope: apex hosts `.aimatrx.com`,
|
|
11
|
+
* loopback and `*.localhost` host-only), and the reconcile-guarded cookie adapter.
|
|
12
|
+
* `createNextSupabase(...).browserClient()` calls `createBrowserSupabase` below.
|
|
13
|
+
*
|
|
14
|
+
* Imports nothing from `next/*` and nothing from `../next/supabase`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
type DatabaseLike = Record<string, unknown>;
|
|
18
|
+
type NextBrowserClient<DB extends DatabaseLike> = ReturnType<typeof createBrowserClient<DB>>;
|
|
19
|
+
interface CreateBrowserSupabaseConfig {
|
|
20
|
+
/** `https://db.matrxserver.com`. */
|
|
21
|
+
url: string;
|
|
22
|
+
/** The `sb_publishable_*` key. */
|
|
23
|
+
key: string;
|
|
24
|
+
/** `createAuthCookie({ cookieName: MATRX_AUTH_COOKIE.current, legacyCookieName: MATRX_AUTH_COOKIE.legacy, … })`. */
|
|
25
|
+
authCookie: AuthCookie;
|
|
26
|
+
/**
|
|
27
|
+
* Host wrapper applied to the BROWSER client only (diagnostics/error capture). Must not change
|
|
28
|
+
* query behavior.
|
|
29
|
+
*/
|
|
30
|
+
wrapBrowserClient?: <C extends object>(client: C) => C;
|
|
31
|
+
}
|
|
32
|
+
declare function createBrowserSupabase<DB extends DatabaseLike = DatabaseLike>(config: CreateBrowserSupabaseConfig): NextBrowserClient<DB>;
|
|
33
|
+
|
|
34
|
+
export { AuthCookie, type CreateBrowserSupabaseConfig, type DatabaseLike, type NextBrowserClient, createBrowserSupabase };
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// src/browser/supabase.ts
|
|
2
|
+
import { createBrowserClient } from "@supabase/ssr";
|
|
3
|
+
|
|
4
|
+
// src/cookies/auth-cookie.ts
|
|
5
|
+
var MATRX_AUTH_COOKIE = {
|
|
6
|
+
current: "sb-matrx-auth-v2",
|
|
7
|
+
legacy: "sb-matrx-auth"
|
|
8
|
+
};
|
|
9
|
+
function parseCookieHeader(header) {
|
|
10
|
+
if (!header) return [];
|
|
11
|
+
const out = [];
|
|
12
|
+
for (const pair of header.split(";")) {
|
|
13
|
+
const eq = pair.indexOf("=");
|
|
14
|
+
const name = (eq === -1 ? pair : pair.slice(0, eq)).trim();
|
|
15
|
+
if (!name) continue;
|
|
16
|
+
const raw = eq === -1 ? "" : pair.slice(eq + 1).trim();
|
|
17
|
+
let value = raw;
|
|
18
|
+
try {
|
|
19
|
+
value = decodeURIComponent(raw);
|
|
20
|
+
} catch {
|
|
21
|
+
}
|
|
22
|
+
out.push({ name, value });
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
function belongsToStorageKey(name, storageKey) {
|
|
27
|
+
if (name === storageKey) return true;
|
|
28
|
+
if (!name.startsWith(`${storageKey}.`)) return false;
|
|
29
|
+
return /^(0|[1-9][0-9]*)$/.test(name.slice(storageKey.length + 1));
|
|
30
|
+
}
|
|
31
|
+
function renamedCookie(cookie, from, to) {
|
|
32
|
+
if (cookie.name === from) return { ...cookie, name: to };
|
|
33
|
+
const prefix = `${from}.`;
|
|
34
|
+
if (!cookie.name.startsWith(prefix)) return null;
|
|
35
|
+
const chunk = cookie.name.slice(prefix.length);
|
|
36
|
+
if (!/^(0|[1-9][0-9]*)$/.test(chunk)) return null;
|
|
37
|
+
return { ...cookie, name: `${to}.${chunk}` };
|
|
38
|
+
}
|
|
39
|
+
function createAuthCookie(args) {
|
|
40
|
+
const cookieName = args.cookieName ?? MATRX_AUTH_COOKIE.current;
|
|
41
|
+
const legacyCookieName = args.legacyCookieName;
|
|
42
|
+
const apex = args.apexDomain.toLowerCase();
|
|
43
|
+
const optionsForHost = (host) => {
|
|
44
|
+
const normalized = (host ?? "").toLowerCase();
|
|
45
|
+
const hostname = normalized.startsWith("[") ? normalized.slice(1, normalized.indexOf("]")) : normalized === "::1" ? normalized : normalized.split(":")[0] ?? "";
|
|
46
|
+
const loopback = hostname === "localhost" || hostname.endsWith(".localhost") || hostname === "::1" || /^127(?:\.(?:0|[1-9]\d{0,2})){3}$/.test(hostname) && hostname.split(".").every((part) => Number(part) <= 255);
|
|
47
|
+
const secure = !loopback;
|
|
48
|
+
const onApex = hostname === apex || hostname.endsWith(`.${apex}`);
|
|
49
|
+
return onApex ? { name: cookieName, domain: `.${apex}`, secure } : { name: cookieName, secure };
|
|
50
|
+
};
|
|
51
|
+
const isCurrentCookie = (name) => belongsToStorageKey(name, cookieName);
|
|
52
|
+
const isAuthCookie = (name) => isCurrentCookie(name) || legacyCookieName !== void 0 && (name === legacyCookieName || name.startsWith(`${legacyCookieName}.`));
|
|
53
|
+
const reconcile = (cookies) => {
|
|
54
|
+
const seen = /* @__PURE__ */ new Map();
|
|
55
|
+
const out = [];
|
|
56
|
+
const shadowed = /* @__PURE__ */ new Set();
|
|
57
|
+
for (const cookie of cookies) {
|
|
58
|
+
const at = seen.get(cookie.name);
|
|
59
|
+
if (at === void 0) {
|
|
60
|
+
seen.set(cookie.name, out.length);
|
|
61
|
+
out.push({ name: cookie.name, value: cookie.value });
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (!isAuthCookie(cookie.name)) continue;
|
|
65
|
+
shadowed.add(cookie.name);
|
|
66
|
+
const held = out[at];
|
|
67
|
+
if (held !== void 0 && held.value.length === 0) {
|
|
68
|
+
out[at] = { name: cookie.name, value: cookie.value };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const ambiguous = /* @__PURE__ */ new Set();
|
|
72
|
+
const ambiguousKeys = [];
|
|
73
|
+
const byName = new Map(out.map((cookie) => [cookie.name, cookie]));
|
|
74
|
+
const storageKeys = [cookieName, ...legacyCookieName ? [legacyCookieName] : []];
|
|
75
|
+
for (const storageKey of storageKeys) {
|
|
76
|
+
const unchunked = byName.get(storageKey);
|
|
77
|
+
const firstChunk = byName.get(`${storageKey}.0`);
|
|
78
|
+
if (!unchunked?.value || !firstChunk?.value) continue;
|
|
79
|
+
ambiguousKeys.push(storageKey);
|
|
80
|
+
for (const { name } of out) {
|
|
81
|
+
if (belongsToStorageKey(name, storageKey)) ambiguous.add(name);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const resolved = ambiguous.size === 0 ? out : out.filter(({ name }) => !ambiguous.has(name));
|
|
85
|
+
const shadowedNames = [...shadowed];
|
|
86
|
+
const ambiguousNames = [...ambiguous];
|
|
87
|
+
return {
|
|
88
|
+
cookies: resolved,
|
|
89
|
+
shadowedNames,
|
|
90
|
+
ambiguousNames,
|
|
91
|
+
ambiguousKeys,
|
|
92
|
+
split: shadowedNames.length > 0 || ambiguousNames.length > 0
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
cookieName,
|
|
97
|
+
legacyCookieName,
|
|
98
|
+
optionsForHost,
|
|
99
|
+
reconcile,
|
|
100
|
+
browserOptions: () => optionsForHost(
|
|
101
|
+
typeof window !== "undefined" ? window.location.hostname : null
|
|
102
|
+
),
|
|
103
|
+
isCurrentCookie,
|
|
104
|
+
migrateLegacyCookies: (cookies) => {
|
|
105
|
+
if (!legacyCookieName) return [];
|
|
106
|
+
if (cookies.some(({ name }) => isCurrentCookie(name))) return [];
|
|
107
|
+
return cookies.flatMap((cookie) => {
|
|
108
|
+
const renamed = renamedCookie(cookie, legacyCookieName, cookieName);
|
|
109
|
+
return renamed ? [renamed] : [];
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/browser/supabase.ts
|
|
116
|
+
var BROWSER_SLOT = /* @__PURE__ */ Symbol.for("ai-matrx.data.next.browser-client");
|
|
117
|
+
function readBrowserSlot() {
|
|
118
|
+
return globalThis[BROWSER_SLOT];
|
|
119
|
+
}
|
|
120
|
+
function writeBrowserSlot(slot) {
|
|
121
|
+
globalThis[BROWSER_SLOT] = slot;
|
|
122
|
+
}
|
|
123
|
+
function browserCookieAdapter(authCookie) {
|
|
124
|
+
return {
|
|
125
|
+
getAll: () => authCookie.reconcile(
|
|
126
|
+
typeof document === "undefined" ? [] : parseCookieHeader(document.cookie)
|
|
127
|
+
).cookies,
|
|
128
|
+
setAll: (cookiesToSet) => {
|
|
129
|
+
if (typeof document === "undefined") return;
|
|
130
|
+
for (const cookie of cookiesToSet) {
|
|
131
|
+
const options = cookie.options ?? {};
|
|
132
|
+
const parts = [
|
|
133
|
+
`${cookie.name}=${encodeURIComponent(cookie.value)}`,
|
|
134
|
+
`Path=${typeof options.path === "string" ? options.path : "/"}`
|
|
135
|
+
];
|
|
136
|
+
if (typeof options.domain === "string") {
|
|
137
|
+
parts.push(`Domain=${options.domain}`);
|
|
138
|
+
}
|
|
139
|
+
if (typeof options.maxAge === "number") {
|
|
140
|
+
parts.push(`Max-Age=${options.maxAge}`);
|
|
141
|
+
}
|
|
142
|
+
if (typeof options.sameSite === "string") {
|
|
143
|
+
parts.push(`SameSite=${options.sameSite}`);
|
|
144
|
+
}
|
|
145
|
+
if (options.secure === true || location.protocol === "https:") parts.push("Secure");
|
|
146
|
+
document.cookie = parts.join("; ");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function createBrowserSupabase(config) {
|
|
152
|
+
const slotKey = `${config.url}|${config.key}|${config.authCookie.cookieName}`;
|
|
153
|
+
const existing = readBrowserSlot();
|
|
154
|
+
if (existing && existing.key === slotKey) {
|
|
155
|
+
return existing.client;
|
|
156
|
+
}
|
|
157
|
+
const raw = createBrowserClient(config.url, config.key, {
|
|
158
|
+
cookieOptions: config.authCookie.browserOptions(),
|
|
159
|
+
cookies: browserCookieAdapter(config.authCookie)
|
|
160
|
+
});
|
|
161
|
+
const client = config.wrapBrowserClient ? config.wrapBrowserClient(raw) : raw;
|
|
162
|
+
writeBrowserSlot({ key: slotKey, client });
|
|
163
|
+
return client;
|
|
164
|
+
}
|
|
165
|
+
export {
|
|
166
|
+
MATRX_AUTH_COOKIE,
|
|
167
|
+
createAuthCookie,
|
|
168
|
+
createBrowserSupabase
|
|
169
|
+
};
|
|
@@ -148,4 +148,4 @@ declare function createClaimsCache(client: ClaimsCapableClient & {
|
|
|
148
148
|
};
|
|
149
149
|
}, options: ClaimsCacheOptions): () => Promise<ClaimsResult>;
|
|
150
150
|
|
|
151
|
-
export { type ApiClaimsUser as A, type
|
|
151
|
+
export { type ApiClaimsUser as A, type ClaimsCapableClient as C, PROJECT_SIGNING_KEYS as P, type ClaimsCacheOptions as a, type ClaimsProfile as b, type ClaimsResult as c, PROJECT_SIGNING_KEY_AUTHORITIES as d, accountFlagsFor as e, confirmUnverifiableSession as f, createClaimsCache as g, getClaimsUser as h, isAuthTransportFailure as i, isSignedOutError as j, isUnverifiableTokenError as k, isUnverifiableTokenRefusal as l, looksLikeJwt as m, profileFromClaims as n, pinnedSigningKeysFor as p, userFromClaims as u };
|
|
@@ -148,4 +148,4 @@ declare function createClaimsCache(client: ClaimsCapableClient & {
|
|
|
148
148
|
};
|
|
149
149
|
}, options: ClaimsCacheOptions): () => Promise<ClaimsResult>;
|
|
150
150
|
|
|
151
|
-
export { type ApiClaimsUser as A, type
|
|
151
|
+
export { type ApiClaimsUser as A, type ClaimsCapableClient as C, PROJECT_SIGNING_KEYS as P, type ClaimsCacheOptions as a, type ClaimsProfile as b, type ClaimsResult as c, PROJECT_SIGNING_KEY_AUTHORITIES as d, accountFlagsFor as e, confirmUnverifiableSession as f, createClaimsCache as g, getClaimsUser as h, isAuthTransportFailure as i, isSignedOutError as j, isUnverifiableTokenError as k, isUnverifiableTokenRefusal as l, looksLikeJwt as m, profileFromClaims as n, pinnedSigningKeysFor as p, userFromClaims as u };
|
package/dist/cookies.cjs
CHANGED
|
@@ -22,7 +22,7 @@ var cookies_exports = {};
|
|
|
22
22
|
__export(cookies_exports, {
|
|
23
23
|
DEFAULT_ACTIVE_ORG_COOKIE_MAX_AGE: () => DEFAULT_ACTIVE_ORG_COOKIE_MAX_AGE,
|
|
24
24
|
DEFAULT_ACTIVE_ORG_COOKIE_NAME: () => DEFAULT_ACTIVE_ORG_COOKIE_NAME,
|
|
25
|
-
|
|
25
|
+
MATRX_AUTH_COOKIE: () => MATRX_AUTH_COOKIE,
|
|
26
26
|
createActiveOrgCookie: () => createActiveOrgCookie,
|
|
27
27
|
createAuthCookie: () => createAuthCookie,
|
|
28
28
|
decodeActiveOrgSelection: () => decodeActiveOrgSelection,
|
|
@@ -32,7 +32,10 @@ __export(cookies_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(cookies_exports);
|
|
33
33
|
|
|
34
34
|
// src/cookies/auth-cookie.ts
|
|
35
|
-
var
|
|
35
|
+
var MATRX_AUTH_COOKIE = {
|
|
36
|
+
current: "sb-matrx-auth-v2",
|
|
37
|
+
legacy: "sb-matrx-auth"
|
|
38
|
+
};
|
|
36
39
|
function parseCookieHeader(header) {
|
|
37
40
|
if (!header) return [];
|
|
38
41
|
const out = [];
|
|
@@ -64,7 +67,7 @@ function renamedCookie(cookie, from, to) {
|
|
|
64
67
|
return { ...cookie, name: `${to}.${chunk}` };
|
|
65
68
|
}
|
|
66
69
|
function createAuthCookie(args) {
|
|
67
|
-
const cookieName = args.cookieName ??
|
|
70
|
+
const cookieName = args.cookieName ?? MATRX_AUTH_COOKIE.current;
|
|
68
71
|
const legacyCookieName = args.legacyCookieName;
|
|
69
72
|
const apex = args.apexDomain.toLowerCase();
|
|
70
73
|
const optionsForHost = (host) => {
|
package/dist/cookies.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AuthCookie, a as AuthCookieOptions, b as AuthCookieValue, C as CreateAuthCookieArgs,
|
|
1
|
+
export { A as AuthCookie, a as AuthCookieOptions, b as AuthCookieValue, C as CreateAuthCookieArgs, M as MATRX_AUTH_COOKIE, R as ReconciledAuthCookies, c as createAuthCookie, p as parseCookieHeader } from './auth-cookie-QPVLJJwP.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* THE ACTIVE-ORGANIZATION COOKIE — one browser-stored "which organization am I
|
package/dist/cookies.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AuthCookie, a as AuthCookieOptions, b as AuthCookieValue, C as CreateAuthCookieArgs,
|
|
1
|
+
export { A as AuthCookie, a as AuthCookieOptions, b as AuthCookieValue, C as CreateAuthCookieArgs, M as MATRX_AUTH_COOKIE, R as ReconciledAuthCookies, c as createAuthCookie, p as parseCookieHeader } from './auth-cookie-QPVLJJwP.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* THE ACTIVE-ORGANIZATION COOKIE — one browser-stored "which organization am I
|
package/dist/cookies.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// src/cookies/auth-cookie.ts
|
|
2
|
-
var
|
|
2
|
+
var MATRX_AUTH_COOKIE = {
|
|
3
|
+
current: "sb-matrx-auth-v2",
|
|
4
|
+
legacy: "sb-matrx-auth"
|
|
5
|
+
};
|
|
3
6
|
function parseCookieHeader(header) {
|
|
4
7
|
if (!header) return [];
|
|
5
8
|
const out = [];
|
|
@@ -31,7 +34,7 @@ function renamedCookie(cookie, from, to) {
|
|
|
31
34
|
return { ...cookie, name: `${to}.${chunk}` };
|
|
32
35
|
}
|
|
33
36
|
function createAuthCookie(args) {
|
|
34
|
-
const cookieName = args.cookieName ??
|
|
37
|
+
const cookieName = args.cookieName ?? MATRX_AUTH_COOKIE.current;
|
|
35
38
|
const legacyCookieName = args.legacyCookieName;
|
|
36
39
|
const apex = args.apexDomain.toLowerCase();
|
|
37
40
|
const optionsForHost = (host) => {
|
|
@@ -201,7 +204,7 @@ function createActiveOrgCookie(args) {
|
|
|
201
204
|
export {
|
|
202
205
|
DEFAULT_ACTIVE_ORG_COOKIE_MAX_AGE,
|
|
203
206
|
DEFAULT_ACTIVE_ORG_COOKIE_NAME,
|
|
204
|
-
|
|
207
|
+
MATRX_AUTH_COOKIE,
|
|
205
208
|
createActiveOrgCookie,
|
|
206
209
|
createAuthCookie,
|
|
207
210
|
decodeActiveOrgSelection,
|
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,7 @@ export { C as ChromeStorageAreaLike, a as StorageUnavailableError, b as browserS
|
|
|
5
5
|
import { SupabaseClient, User } from '@supabase/supabase-js';
|
|
6
6
|
export { AuthChangeEvent, Session, User, UserAttributes } from '@supabase/supabase-js';
|
|
7
7
|
export { CredentialsPort, MatrxCredential, MatrxCredentialKind } from './credentials.cjs';
|
|
8
|
-
export { A as ApiClaimsUser,
|
|
8
|
+
export { A as ApiClaimsUser, a as ClaimsCacheOptions, C as ClaimsCapableClient, b as ClaimsProfile, c as ClaimsResult, P as PROJECT_SIGNING_KEYS, d as PROJECT_SIGNING_KEY_AUTHORITIES, e as accountFlagsFor, f as confirmUnverifiableSession, g as createClaimsCache, h as getClaimsUser, i as isAuthTransportFailure, j as isSignedOutError, k as isUnverifiableTokenError, l as isUnverifiableTokenRefusal, m as looksLikeJwt, p as pinnedSigningKeysFor, n as profileFromClaims, u as userFromClaims } from './claims-Vno769TE.cjs';
|
|
9
9
|
|
|
10
10
|
/** How long a request may wait for the first auth report before going anyway. */
|
|
11
11
|
declare const SESSION_ATTACH_BUDGET_MS = 3000;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { C as ChromeStorageAreaLike, a as StorageUnavailableError, b as browserS
|
|
|
5
5
|
import { SupabaseClient, User } from '@supabase/supabase-js';
|
|
6
6
|
export { AuthChangeEvent, Session, User, UserAttributes } from '@supabase/supabase-js';
|
|
7
7
|
export { CredentialsPort, MatrxCredential, MatrxCredentialKind } from './credentials.js';
|
|
8
|
-
export { A as ApiClaimsUser,
|
|
8
|
+
export { A as ApiClaimsUser, a as ClaimsCacheOptions, C as ClaimsCapableClient, b as ClaimsProfile, c as ClaimsResult, P as PROJECT_SIGNING_KEYS, d as PROJECT_SIGNING_KEY_AUTHORITIES, e as accountFlagsFor, f as confirmUnverifiableSession, g as createClaimsCache, h as getClaimsUser, i as isAuthTransportFailure, j as isSignedOutError, k as isUnverifiableTokenError, l as isUnverifiableTokenRefusal, m as looksLikeJwt, p as pinnedSigningKeysFor, n as profileFromClaims, u as userFromClaims } from './claims-Vno769TE.js';
|
|
9
9
|
|
|
10
10
|
/** How long a request may wait for the first auth report before going anyway. */
|
|
11
11
|
declare const SESSION_ATTACH_BUDGET_MS = 3000;
|
package/dist/matrx-oauth.cjs
CHANGED
|
@@ -131,7 +131,7 @@ function personIdFromAccessToken(token) {
|
|
|
131
131
|
expiresAtMs: typeof payload.exp === "number" ? payload.exp * 1e3 : null
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
|
-
function
|
|
134
|
+
function oauthErrorFromBody(raw) {
|
|
135
135
|
try {
|
|
136
136
|
const j = JSON.parse(raw);
|
|
137
137
|
for (const key of ["error_description", "error_message", "msg", "error", "code"]) {
|
|
@@ -268,7 +268,7 @@ function createMatrxOAuth(config, ports) {
|
|
|
268
268
|
};
|
|
269
269
|
}
|
|
270
270
|
const code = String(body["error"] ?? body["error_code"] ?? res.status);
|
|
271
|
-
const detail =
|
|
271
|
+
const detail = oauthErrorFromBody(text) ?? text.slice(0, 200);
|
|
272
272
|
if (isExchange) {
|
|
273
273
|
throw new MatrxOAuthError("token_exchange_failed", `Token exchange failed (${res.status}): ${detail}`);
|
|
274
274
|
}
|
package/dist/matrx-oauth.js
CHANGED
|
@@ -97,7 +97,7 @@ function personIdFromAccessToken(token) {
|
|
|
97
97
|
expiresAtMs: typeof payload.exp === "number" ? payload.exp * 1e3 : null
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
|
-
function
|
|
100
|
+
function oauthErrorFromBody(raw) {
|
|
101
101
|
try {
|
|
102
102
|
const j = JSON.parse(raw);
|
|
103
103
|
for (const key of ["error_description", "error_message", "msg", "error", "code"]) {
|
|
@@ -234,7 +234,7 @@ function createMatrxOAuth(config, ports) {
|
|
|
234
234
|
};
|
|
235
235
|
}
|
|
236
236
|
const code = String(body["error"] ?? body["error_code"] ?? res.status);
|
|
237
|
-
const detail =
|
|
237
|
+
const detail = oauthErrorFromBody(text) ?? text.slice(0, 200);
|
|
238
238
|
if (isExchange) {
|
|
239
239
|
throw new MatrxOAuthError("token_exchange_failed", `Token exchange failed (${res.status}): ${detail}`);
|
|
240
240
|
}
|
package/dist/next.cjs
CHANGED
|
@@ -23,7 +23,7 @@ __export(next_exports, {
|
|
|
23
23
|
AMBIGUOUS_AUTH_COOKIE_HEADER: () => AMBIGUOUS_AUTH_COOKIE_HEADER,
|
|
24
24
|
AUTH_COOKIE_RESPONSE_HEADERS: () => AUTH_COOKIE_RESPONSE_HEADERS,
|
|
25
25
|
AUTH_REFRESH_CEILING_MS: () => AUTH_REFRESH_CEILING_MS,
|
|
26
|
-
|
|
26
|
+
MATRX_AUTH_COOKIE: () => MATRX_AUTH_COOKIE,
|
|
27
27
|
MissingSupabaseIdentityError: () => MissingSupabaseIdentityError,
|
|
28
28
|
SPLIT_COOKIE_JAR_HEADER: () => SPLIT_COOKIE_JAR_HEADER,
|
|
29
29
|
createAuthBudget: () => createAuthBudget,
|
|
@@ -38,10 +38,16 @@ __export(next_exports, {
|
|
|
38
38
|
module.exports = __toCommonJS(next_exports);
|
|
39
39
|
|
|
40
40
|
// src/next/supabase.ts
|
|
41
|
+
var import_ssr2 = require("@supabase/ssr");
|
|
42
|
+
|
|
43
|
+
// src/browser/supabase.ts
|
|
41
44
|
var import_ssr = require("@supabase/ssr");
|
|
42
45
|
|
|
43
46
|
// src/cookies/auth-cookie.ts
|
|
44
|
-
var
|
|
47
|
+
var MATRX_AUTH_COOKIE = {
|
|
48
|
+
current: "sb-matrx-auth-v2",
|
|
49
|
+
legacy: "sb-matrx-auth"
|
|
50
|
+
};
|
|
45
51
|
function parseCookieHeader(header) {
|
|
46
52
|
if (!header) return [];
|
|
47
53
|
const out = [];
|
|
@@ -73,7 +79,7 @@ function renamedCookie(cookie, from, to) {
|
|
|
73
79
|
return { ...cookie, name: `${to}.${chunk}` };
|
|
74
80
|
}
|
|
75
81
|
function createAuthCookie(args) {
|
|
76
|
-
const cookieName = args.cookieName ??
|
|
82
|
+
const cookieName = args.cookieName ?? MATRX_AUTH_COOKIE.current;
|
|
77
83
|
const legacyCookieName = args.legacyCookieName;
|
|
78
84
|
const apex = args.apexDomain.toLowerCase();
|
|
79
85
|
const optionsForHost = (host) => {
|
|
@@ -148,6 +154,57 @@ function createAuthCookie(args) {
|
|
|
148
154
|
};
|
|
149
155
|
}
|
|
150
156
|
|
|
157
|
+
// src/browser/supabase.ts
|
|
158
|
+
var BROWSER_SLOT = /* @__PURE__ */ Symbol.for("ai-matrx.data.next.browser-client");
|
|
159
|
+
function readBrowserSlot() {
|
|
160
|
+
return globalThis[BROWSER_SLOT];
|
|
161
|
+
}
|
|
162
|
+
function writeBrowserSlot(slot) {
|
|
163
|
+
globalThis[BROWSER_SLOT] = slot;
|
|
164
|
+
}
|
|
165
|
+
function browserCookieAdapter(authCookie) {
|
|
166
|
+
return {
|
|
167
|
+
getAll: () => authCookie.reconcile(
|
|
168
|
+
typeof document === "undefined" ? [] : parseCookieHeader(document.cookie)
|
|
169
|
+
).cookies,
|
|
170
|
+
setAll: (cookiesToSet) => {
|
|
171
|
+
if (typeof document === "undefined") return;
|
|
172
|
+
for (const cookie of cookiesToSet) {
|
|
173
|
+
const options = cookie.options ?? {};
|
|
174
|
+
const parts = [
|
|
175
|
+
`${cookie.name}=${encodeURIComponent(cookie.value)}`,
|
|
176
|
+
`Path=${typeof options.path === "string" ? options.path : "/"}`
|
|
177
|
+
];
|
|
178
|
+
if (typeof options.domain === "string") {
|
|
179
|
+
parts.push(`Domain=${options.domain}`);
|
|
180
|
+
}
|
|
181
|
+
if (typeof options.maxAge === "number") {
|
|
182
|
+
parts.push(`Max-Age=${options.maxAge}`);
|
|
183
|
+
}
|
|
184
|
+
if (typeof options.sameSite === "string") {
|
|
185
|
+
parts.push(`SameSite=${options.sameSite}`);
|
|
186
|
+
}
|
|
187
|
+
if (options.secure === true || location.protocol === "https:") parts.push("Secure");
|
|
188
|
+
document.cookie = parts.join("; ");
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function createBrowserSupabase(config) {
|
|
194
|
+
const slotKey = `${config.url}|${config.key}|${config.authCookie.cookieName}`;
|
|
195
|
+
const existing = readBrowserSlot();
|
|
196
|
+
if (existing && existing.key === slotKey) {
|
|
197
|
+
return existing.client;
|
|
198
|
+
}
|
|
199
|
+
const raw = (0, import_ssr.createBrowserClient)(config.url, config.key, {
|
|
200
|
+
cookieOptions: config.authCookie.browserOptions(),
|
|
201
|
+
cookies: browserCookieAdapter(config.authCookie)
|
|
202
|
+
});
|
|
203
|
+
const client = config.wrapBrowserClient ? config.wrapBrowserClient(raw) : raw;
|
|
204
|
+
writeBrowserSlot({ key: slotKey, client });
|
|
205
|
+
return client;
|
|
206
|
+
}
|
|
207
|
+
|
|
151
208
|
// src/next/supabase.ts
|
|
152
209
|
var RESPONSE_COOKIE_ATTRIBUTES = [
|
|
153
210
|
"domain",
|
|
@@ -305,13 +362,6 @@ async function resolveIdentity(client, budget) {
|
|
|
305
362
|
return unreachable(cause);
|
|
306
363
|
}
|
|
307
364
|
}
|
|
308
|
-
var BROWSER_SLOT = /* @__PURE__ */ Symbol.for("ai-matrx.data.next.browser-client");
|
|
309
|
-
function readBrowserSlot() {
|
|
310
|
-
return globalThis[BROWSER_SLOT];
|
|
311
|
-
}
|
|
312
|
-
function writeBrowserSlot(slot) {
|
|
313
|
-
globalThis[BROWSER_SLOT] = slot;
|
|
314
|
-
}
|
|
315
365
|
function createNextSupabase(config) {
|
|
316
366
|
const url = requireIdentity(config.supabaseUrl, "NEXT_PUBLIC_SUPABASE_URL");
|
|
317
367
|
const key = requireIdentity(
|
|
@@ -323,47 +373,12 @@ function createNextSupabase(config) {
|
|
|
323
373
|
...config.cookieName !== void 0 ? { cookieName: config.cookieName } : {},
|
|
324
374
|
...config.legacyCookieName !== void 0 ? { legacyCookieName: config.legacyCookieName } : {}
|
|
325
375
|
});
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
).cookies,
|
|
332
|
-
setAll: (cookiesToSet) => {
|
|
333
|
-
if (typeof document === "undefined") return;
|
|
334
|
-
for (const cookie of cookiesToSet) {
|
|
335
|
-
const options = cookie.options ?? {};
|
|
336
|
-
const parts = [
|
|
337
|
-
`${cookie.name}=${encodeURIComponent(cookie.value)}`,
|
|
338
|
-
`Path=${typeof options.path === "string" ? options.path : "/"}`
|
|
339
|
-
];
|
|
340
|
-
if (typeof options.domain === "string") {
|
|
341
|
-
parts.push(`Domain=${options.domain}`);
|
|
342
|
-
}
|
|
343
|
-
if (typeof options.maxAge === "number") {
|
|
344
|
-
parts.push(`Max-Age=${options.maxAge}`);
|
|
345
|
-
}
|
|
346
|
-
if (typeof options.sameSite === "string") {
|
|
347
|
-
parts.push(`SameSite=${options.sameSite}`);
|
|
348
|
-
}
|
|
349
|
-
if (options.secure === true || location.protocol === "https:") parts.push("Secure");
|
|
350
|
-
document.cookie = parts.join("; ");
|
|
351
|
-
}
|
|
352
|
-
}
|
|
376
|
+
const browserClient = () => createBrowserSupabase({
|
|
377
|
+
url,
|
|
378
|
+
key,
|
|
379
|
+
authCookie,
|
|
380
|
+
...config.wrapBrowserClient !== void 0 ? { wrapBrowserClient: config.wrapBrowserClient } : {}
|
|
353
381
|
});
|
|
354
|
-
const browserClient = () => {
|
|
355
|
-
const existing = readBrowserSlot();
|
|
356
|
-
if (existing && existing.key === slotKey) {
|
|
357
|
-
return existing.client;
|
|
358
|
-
}
|
|
359
|
-
const raw = (0, import_ssr.createBrowserClient)(url, key, {
|
|
360
|
-
cookieOptions: authCookie.browserOptions(),
|
|
361
|
-
cookies: browserCookieAdapter()
|
|
362
|
-
});
|
|
363
|
-
const client = wrap ? wrap(raw) : raw;
|
|
364
|
-
writeBrowserSlot({ key: slotKey, client });
|
|
365
|
-
return client;
|
|
366
|
-
};
|
|
367
382
|
const reconciledGetAll = (getAllRaw, cookieHeader) => {
|
|
368
383
|
const parsed = parseCookieHeader(cookieHeader);
|
|
369
384
|
if (parsed.length > 0) {
|
|
@@ -380,7 +395,7 @@ function createNextSupabase(config) {
|
|
|
380
395
|
}) => {
|
|
381
396
|
const written = /* @__PURE__ */ new Set();
|
|
382
397
|
const budget = createAuthBudget(AUTH_RESOLVE_TIMEOUT_MS);
|
|
383
|
-
return (0,
|
|
398
|
+
return (0, import_ssr2.createServerClient)(url, key, {
|
|
384
399
|
cookieOptions: authCookie.optionsForHost(host),
|
|
385
400
|
global: { fetch: budget.fetch },
|
|
386
401
|
cookies: {
|
|
@@ -422,7 +437,7 @@ function createNextSupabase(config) {
|
|
|
422
437
|
}) => {
|
|
423
438
|
const written = /* @__PURE__ */ new Set();
|
|
424
439
|
const budget = createAuthBudget(AUTH_RESOLVE_TIMEOUT_MS);
|
|
425
|
-
return (0,
|
|
440
|
+
return (0, import_ssr2.createServerClient)(url, key, {
|
|
426
441
|
cookieOptions: authCookie.optionsForHost(host),
|
|
427
442
|
global: { fetch: budget.fetch },
|
|
428
443
|
cookies: {
|
|
@@ -520,7 +535,7 @@ function createNextSupabase(config) {
|
|
|
520
535
|
}
|
|
521
536
|
response = next;
|
|
522
537
|
};
|
|
523
|
-
const client = (0,
|
|
538
|
+
const client = (0, import_ssr2.createServerClient)(url, key, {
|
|
524
539
|
cookieOptions: hostCookieOptions,
|
|
525
540
|
// Identity calls out of THIS pass share one deadline; see createAuthBudget.
|
|
526
541
|
global: { fetch: budget.fetch },
|
|
@@ -543,7 +558,7 @@ function createNextSupabase(config) {
|
|
|
543
558
|
).map(({ name, value }) => ({
|
|
544
559
|
name,
|
|
545
560
|
value,
|
|
546
|
-
options: { ...
|
|
561
|
+
options: { ...import_ssr2.DEFAULT_COOKIE_OPTIONS, ...cookieOptions }
|
|
547
562
|
}))
|
|
548
563
|
);
|
|
549
564
|
}
|
|
@@ -554,7 +569,7 @@ function createNextSupabase(config) {
|
|
|
554
569
|
}
|
|
555
570
|
}
|
|
556
571
|
if (authCookie.legacyCookieName && !authUnavailable) {
|
|
557
|
-
await (0,
|
|
572
|
+
await (0, import_ssr2.clearAuthCookiesAtScopes)({
|
|
558
573
|
getAll: () => readCookies(),
|
|
559
574
|
setAll: (cookiesToSet, headers) => {
|
|
560
575
|
applyCookies(
|
|
@@ -585,7 +600,7 @@ function createNextSupabase(config) {
|
|
|
585
600
|
name,
|
|
586
601
|
value,
|
|
587
602
|
options: {
|
|
588
|
-
...
|
|
603
|
+
...import_ssr2.DEFAULT_COOKIE_OPTIONS,
|
|
589
604
|
domain: hostCookieOptions.domain,
|
|
590
605
|
path: "/",
|
|
591
606
|
// A Domain-scoped auth cookie only ever exists on https here,
|
package/dist/next.d.cts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { createServerClient
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { createServerClient } from '@supabase/ssr';
|
|
2
|
+
import { DatabaseLike, NextBrowserClient } from './browser.cjs';
|
|
3
|
+
import { b as AuthCookieValue, A as AuthCookie, a as AuthCookieOptions } from './auth-cookie-QPVLJJwP.cjs';
|
|
4
|
+
export { C as CreateAuthCookieArgs, M as MATRX_AUTH_COOKIE, c as createAuthCookie } from './auth-cookie-QPVLJJwP.cjs';
|
|
4
5
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
5
|
-
import {
|
|
6
|
+
import { C as ClaimsCapableClient, A as ApiClaimsUser } from './claims-Vno769TE.cjs';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @ai-matrx/data/next — the Next.js Supabase binding.
|
|
@@ -40,13 +41,6 @@ import { a as ClaimsCapableClient, A as ApiClaimsUser } from './claims-KrRxsfaG.
|
|
|
40
41
|
* non-Next consumer's graph.
|
|
41
42
|
*/
|
|
42
43
|
|
|
43
|
-
/**
|
|
44
|
-
* A `Database` type as generated by Supabase. Deliberately structural: the
|
|
45
|
-
* package never imports a host's generated types, and a host that has not
|
|
46
|
-
* generated any still gets a working (untyped-rows) client.
|
|
47
|
-
*/
|
|
48
|
-
type DatabaseLike = Record<string, unknown>;
|
|
49
|
-
type NextBrowserClient<DB extends DatabaseLike> = ReturnType<typeof createBrowserClient<DB>>;
|
|
50
44
|
type NextServerClient<DB extends DatabaseLike> = ReturnType<typeof createServerClient<DB>>;
|
|
51
45
|
/** A cookie to write, as `@supabase/ssr` hands it to `setAll`. */
|
|
52
46
|
interface CookieToSet {
|
|
@@ -134,7 +128,7 @@ interface NextSupabaseConfig {
|
|
|
134
128
|
publishableKey: string | undefined;
|
|
135
129
|
/** The apex domain one login must span, e.g. `"aimatrx.com"`. */
|
|
136
130
|
apexDomain: string;
|
|
137
|
-
/** Auth cookie name. Defaults to
|
|
131
|
+
/** Auth cookie name. Defaults to `MATRX_AUTH_COOKIE.current`. */
|
|
138
132
|
cookieName?: string;
|
|
139
133
|
/** A superseded storage key to migrate from and then clear. */
|
|
140
134
|
legacyCookieName?: string;
|
|
@@ -462,4 +456,4 @@ declare function createServiceClient<Database = unknown>(options: {
|
|
|
462
456
|
secretKey: string | null | undefined;
|
|
463
457
|
}): SupabaseClient<Database>;
|
|
464
458
|
|
|
465
|
-
export { AMBIGUOUS_AUTH_COOKIE_HEADER, AUTH_COOKIE_RESPONSE_HEADERS, AUTH_REFRESH_CEILING_MS, type AuthBudget, AuthCookie, AuthCookieOptions, AuthCookieValue, type CookieToSet,
|
|
459
|
+
export { AMBIGUOUS_AUTH_COOKIE_HEADER, AUTH_COOKIE_RESPONSE_HEADERS, AUTH_REFRESH_CEILING_MS, type AuthBudget, AuthCookie, AuthCookieOptions, AuthCookieValue, type CookieToSet, DatabaseLike, type MiddlewareResponse, type MiddlewareSession, type MiddlewareSessionArgs, MissingSupabaseIdentityError, NextBrowserClient, type NextServerClient, type NextSupabase, type NextSupabaseConfig, type RequestCookieJar, type RequestLike, type ResponseCookie, type ResponseCookieJar, SPLIT_COOKIE_JAR_HEADER, type ServerAuthOptions, type ServerAuthState, type ServerCookieStore, type VerifyRequestOptions, createAuthBudget, createNextSupabase, createServerAuth, createServiceClient, serializeSetCookie, toResponseCookie, verifyRequest };
|
package/dist/next.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { createServerClient
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { createServerClient } from '@supabase/ssr';
|
|
2
|
+
import { DatabaseLike, NextBrowserClient } from './browser.js';
|
|
3
|
+
import { b as AuthCookieValue, A as AuthCookie, a as AuthCookieOptions } from './auth-cookie-QPVLJJwP.js';
|
|
4
|
+
export { C as CreateAuthCookieArgs, M as MATRX_AUTH_COOKIE, c as createAuthCookie } from './auth-cookie-QPVLJJwP.js';
|
|
4
5
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
5
|
-
import {
|
|
6
|
+
import { C as ClaimsCapableClient, A as ApiClaimsUser } from './claims-Vno769TE.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @ai-matrx/data/next — the Next.js Supabase binding.
|
|
@@ -40,13 +41,6 @@ import { a as ClaimsCapableClient, A as ApiClaimsUser } from './claims-KrRxsfaG.
|
|
|
40
41
|
* non-Next consumer's graph.
|
|
41
42
|
*/
|
|
42
43
|
|
|
43
|
-
/**
|
|
44
|
-
* A `Database` type as generated by Supabase. Deliberately structural: the
|
|
45
|
-
* package never imports a host's generated types, and a host that has not
|
|
46
|
-
* generated any still gets a working (untyped-rows) client.
|
|
47
|
-
*/
|
|
48
|
-
type DatabaseLike = Record<string, unknown>;
|
|
49
|
-
type NextBrowserClient<DB extends DatabaseLike> = ReturnType<typeof createBrowserClient<DB>>;
|
|
50
44
|
type NextServerClient<DB extends DatabaseLike> = ReturnType<typeof createServerClient<DB>>;
|
|
51
45
|
/** A cookie to write, as `@supabase/ssr` hands it to `setAll`. */
|
|
52
46
|
interface CookieToSet {
|
|
@@ -134,7 +128,7 @@ interface NextSupabaseConfig {
|
|
|
134
128
|
publishableKey: string | undefined;
|
|
135
129
|
/** The apex domain one login must span, e.g. `"aimatrx.com"`. */
|
|
136
130
|
apexDomain: string;
|
|
137
|
-
/** Auth cookie name. Defaults to
|
|
131
|
+
/** Auth cookie name. Defaults to `MATRX_AUTH_COOKIE.current`. */
|
|
138
132
|
cookieName?: string;
|
|
139
133
|
/** A superseded storage key to migrate from and then clear. */
|
|
140
134
|
legacyCookieName?: string;
|
|
@@ -462,4 +456,4 @@ declare function createServiceClient<Database = unknown>(options: {
|
|
|
462
456
|
secretKey: string | null | undefined;
|
|
463
457
|
}): SupabaseClient<Database>;
|
|
464
458
|
|
|
465
|
-
export { AMBIGUOUS_AUTH_COOKIE_HEADER, AUTH_COOKIE_RESPONSE_HEADERS, AUTH_REFRESH_CEILING_MS, type AuthBudget, AuthCookie, AuthCookieOptions, AuthCookieValue, type CookieToSet,
|
|
459
|
+
export { AMBIGUOUS_AUTH_COOKIE_HEADER, AUTH_COOKIE_RESPONSE_HEADERS, AUTH_REFRESH_CEILING_MS, type AuthBudget, AuthCookie, AuthCookieOptions, AuthCookieValue, type CookieToSet, DatabaseLike, type MiddlewareResponse, type MiddlewareSession, type MiddlewareSessionArgs, MissingSupabaseIdentityError, NextBrowserClient, type NextServerClient, type NextSupabase, type NextSupabaseConfig, type RequestCookieJar, type RequestLike, type ResponseCookie, type ResponseCookieJar, SPLIT_COOKIE_JAR_HEADER, type ServerAuthOptions, type ServerAuthState, type ServerCookieStore, type VerifyRequestOptions, createAuthBudget, createNextSupabase, createServerAuth, createServiceClient, serializeSetCookie, toResponseCookie, verifyRequest };
|
package/dist/next.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
// src/next/supabase.ts
|
|
2
2
|
import {
|
|
3
3
|
clearAuthCookiesAtScopes,
|
|
4
|
-
createBrowserClient,
|
|
5
4
|
createServerClient,
|
|
6
5
|
DEFAULT_COOKIE_OPTIONS
|
|
7
6
|
} from "@supabase/ssr";
|
|
8
7
|
|
|
8
|
+
// src/browser/supabase.ts
|
|
9
|
+
import { createBrowserClient } from "@supabase/ssr";
|
|
10
|
+
|
|
9
11
|
// src/cookies/auth-cookie.ts
|
|
10
|
-
var
|
|
12
|
+
var MATRX_AUTH_COOKIE = {
|
|
13
|
+
current: "sb-matrx-auth-v2",
|
|
14
|
+
legacy: "sb-matrx-auth"
|
|
15
|
+
};
|
|
11
16
|
function parseCookieHeader(header) {
|
|
12
17
|
if (!header) return [];
|
|
13
18
|
const out = [];
|
|
@@ -39,7 +44,7 @@ function renamedCookie(cookie, from, to) {
|
|
|
39
44
|
return { ...cookie, name: `${to}.${chunk}` };
|
|
40
45
|
}
|
|
41
46
|
function createAuthCookie(args) {
|
|
42
|
-
const cookieName = args.cookieName ??
|
|
47
|
+
const cookieName = args.cookieName ?? MATRX_AUTH_COOKIE.current;
|
|
43
48
|
const legacyCookieName = args.legacyCookieName;
|
|
44
49
|
const apex = args.apexDomain.toLowerCase();
|
|
45
50
|
const optionsForHost = (host) => {
|
|
@@ -114,6 +119,57 @@ function createAuthCookie(args) {
|
|
|
114
119
|
};
|
|
115
120
|
}
|
|
116
121
|
|
|
122
|
+
// src/browser/supabase.ts
|
|
123
|
+
var BROWSER_SLOT = /* @__PURE__ */ Symbol.for("ai-matrx.data.next.browser-client");
|
|
124
|
+
function readBrowserSlot() {
|
|
125
|
+
return globalThis[BROWSER_SLOT];
|
|
126
|
+
}
|
|
127
|
+
function writeBrowserSlot(slot) {
|
|
128
|
+
globalThis[BROWSER_SLOT] = slot;
|
|
129
|
+
}
|
|
130
|
+
function browserCookieAdapter(authCookie) {
|
|
131
|
+
return {
|
|
132
|
+
getAll: () => authCookie.reconcile(
|
|
133
|
+
typeof document === "undefined" ? [] : parseCookieHeader(document.cookie)
|
|
134
|
+
).cookies,
|
|
135
|
+
setAll: (cookiesToSet) => {
|
|
136
|
+
if (typeof document === "undefined") return;
|
|
137
|
+
for (const cookie of cookiesToSet) {
|
|
138
|
+
const options = cookie.options ?? {};
|
|
139
|
+
const parts = [
|
|
140
|
+
`${cookie.name}=${encodeURIComponent(cookie.value)}`,
|
|
141
|
+
`Path=${typeof options.path === "string" ? options.path : "/"}`
|
|
142
|
+
];
|
|
143
|
+
if (typeof options.domain === "string") {
|
|
144
|
+
parts.push(`Domain=${options.domain}`);
|
|
145
|
+
}
|
|
146
|
+
if (typeof options.maxAge === "number") {
|
|
147
|
+
parts.push(`Max-Age=${options.maxAge}`);
|
|
148
|
+
}
|
|
149
|
+
if (typeof options.sameSite === "string") {
|
|
150
|
+
parts.push(`SameSite=${options.sameSite}`);
|
|
151
|
+
}
|
|
152
|
+
if (options.secure === true || location.protocol === "https:") parts.push("Secure");
|
|
153
|
+
document.cookie = parts.join("; ");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function createBrowserSupabase(config) {
|
|
159
|
+
const slotKey = `${config.url}|${config.key}|${config.authCookie.cookieName}`;
|
|
160
|
+
const existing = readBrowserSlot();
|
|
161
|
+
if (existing && existing.key === slotKey) {
|
|
162
|
+
return existing.client;
|
|
163
|
+
}
|
|
164
|
+
const raw = createBrowserClient(config.url, config.key, {
|
|
165
|
+
cookieOptions: config.authCookie.browserOptions(),
|
|
166
|
+
cookies: browserCookieAdapter(config.authCookie)
|
|
167
|
+
});
|
|
168
|
+
const client = config.wrapBrowserClient ? config.wrapBrowserClient(raw) : raw;
|
|
169
|
+
writeBrowserSlot({ key: slotKey, client });
|
|
170
|
+
return client;
|
|
171
|
+
}
|
|
172
|
+
|
|
117
173
|
// src/next/supabase.ts
|
|
118
174
|
var RESPONSE_COOKIE_ATTRIBUTES = [
|
|
119
175
|
"domain",
|
|
@@ -271,13 +327,6 @@ async function resolveIdentity(client, budget) {
|
|
|
271
327
|
return unreachable(cause);
|
|
272
328
|
}
|
|
273
329
|
}
|
|
274
|
-
var BROWSER_SLOT = /* @__PURE__ */ Symbol.for("ai-matrx.data.next.browser-client");
|
|
275
|
-
function readBrowserSlot() {
|
|
276
|
-
return globalThis[BROWSER_SLOT];
|
|
277
|
-
}
|
|
278
|
-
function writeBrowserSlot(slot) {
|
|
279
|
-
globalThis[BROWSER_SLOT] = slot;
|
|
280
|
-
}
|
|
281
330
|
function createNextSupabase(config) {
|
|
282
331
|
const url = requireIdentity(config.supabaseUrl, "NEXT_PUBLIC_SUPABASE_URL");
|
|
283
332
|
const key = requireIdentity(
|
|
@@ -289,47 +338,12 @@ function createNextSupabase(config) {
|
|
|
289
338
|
...config.cookieName !== void 0 ? { cookieName: config.cookieName } : {},
|
|
290
339
|
...config.legacyCookieName !== void 0 ? { legacyCookieName: config.legacyCookieName } : {}
|
|
291
340
|
});
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
).cookies,
|
|
298
|
-
setAll: (cookiesToSet) => {
|
|
299
|
-
if (typeof document === "undefined") return;
|
|
300
|
-
for (const cookie of cookiesToSet) {
|
|
301
|
-
const options = cookie.options ?? {};
|
|
302
|
-
const parts = [
|
|
303
|
-
`${cookie.name}=${encodeURIComponent(cookie.value)}`,
|
|
304
|
-
`Path=${typeof options.path === "string" ? options.path : "/"}`
|
|
305
|
-
];
|
|
306
|
-
if (typeof options.domain === "string") {
|
|
307
|
-
parts.push(`Domain=${options.domain}`);
|
|
308
|
-
}
|
|
309
|
-
if (typeof options.maxAge === "number") {
|
|
310
|
-
parts.push(`Max-Age=${options.maxAge}`);
|
|
311
|
-
}
|
|
312
|
-
if (typeof options.sameSite === "string") {
|
|
313
|
-
parts.push(`SameSite=${options.sameSite}`);
|
|
314
|
-
}
|
|
315
|
-
if (options.secure === true || location.protocol === "https:") parts.push("Secure");
|
|
316
|
-
document.cookie = parts.join("; ");
|
|
317
|
-
}
|
|
318
|
-
}
|
|
341
|
+
const browserClient = () => createBrowserSupabase({
|
|
342
|
+
url,
|
|
343
|
+
key,
|
|
344
|
+
authCookie,
|
|
345
|
+
...config.wrapBrowserClient !== void 0 ? { wrapBrowserClient: config.wrapBrowserClient } : {}
|
|
319
346
|
});
|
|
320
|
-
const browserClient = () => {
|
|
321
|
-
const existing = readBrowserSlot();
|
|
322
|
-
if (existing && existing.key === slotKey) {
|
|
323
|
-
return existing.client;
|
|
324
|
-
}
|
|
325
|
-
const raw = createBrowserClient(url, key, {
|
|
326
|
-
cookieOptions: authCookie.browserOptions(),
|
|
327
|
-
cookies: browserCookieAdapter()
|
|
328
|
-
});
|
|
329
|
-
const client = wrap ? wrap(raw) : raw;
|
|
330
|
-
writeBrowserSlot({ key: slotKey, client });
|
|
331
|
-
return client;
|
|
332
|
-
};
|
|
333
347
|
const reconciledGetAll = (getAllRaw, cookieHeader) => {
|
|
334
348
|
const parsed = parseCookieHeader(cookieHeader);
|
|
335
349
|
if (parsed.length > 0) {
|
|
@@ -758,7 +772,7 @@ export {
|
|
|
758
772
|
AMBIGUOUS_AUTH_COOKIE_HEADER,
|
|
759
773
|
AUTH_COOKIE_RESPONSE_HEADERS,
|
|
760
774
|
AUTH_REFRESH_CEILING_MS,
|
|
761
|
-
|
|
775
|
+
MATRX_AUTH_COOKIE,
|
|
762
776
|
MissingSupabaseIdentityError,
|
|
763
777
|
SPLIT_COOKIE_JAR_HEADER,
|
|
764
778
|
createAuthBudget,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-matrx/auth",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "AI Matrx sign-in, session and organizations for every app: sign in/out, session storage and refresh per platform (browser, Next.js, extension, desktop, Node), the current person, their organizations and favourites, the one active organization (held requests, never a list filter), and the credentials @ai-matrx/data and @ai-matrx/api read.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -92,6 +92,16 @@
|
|
|
92
92
|
"default": "./dist/next.cjs"
|
|
93
93
|
}
|
|
94
94
|
},
|
|
95
|
+
"./browser": {
|
|
96
|
+
"import": {
|
|
97
|
+
"types": "./dist/browser.d.ts",
|
|
98
|
+
"default": "./dist/browser.js"
|
|
99
|
+
},
|
|
100
|
+
"require": {
|
|
101
|
+
"types": "./dist/browser.d.cts",
|
|
102
|
+
"default": "./dist/browser.cjs"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
95
105
|
"./react": {
|
|
96
106
|
"import": {
|
|
97
107
|
"types": "./dist/react.d.ts",
|
|
@@ -211,5 +221,5 @@
|
|
|
211
221
|
"test": "vitest run",
|
|
212
222
|
"verify:tarball": "node ./scripts/verify-tarball.mjs"
|
|
213
223
|
},
|
|
214
|
-
"gitHead": "
|
|
224
|
+
"gitHead": "cd85c8a24fbc3f8eb2f2c450142cbdbd6130b31f"
|
|
215
225
|
}
|