managed-deepagents 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/connectors/langsmith.d.ts +385 -0
- package/dist/connectors/langsmith.d.ts.map +1 -0
- package/dist/connectors/langsmith.js +431 -0
- package/dist/connectors/langsmith.js.map +1 -0
- package/dist/connectors.d.ts +7 -2
- package/dist/connectors.d.ts.map +1 -1
- package/dist/connectors.js +18 -1
- package/dist/connectors.js.map +1 -1
- package/dist/identity/index.d.ts +88 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +303 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/supabase.d.ts +48 -0
- package/dist/identity/supabase.d.ts.map +1 -0
- package/dist/identity/supabase.js +139 -0
- package/dist/identity/supabase.js.map +1 -0
- package/dist/identity/types.d.ts +185 -0
- package/dist/identity/types.d.ts.map +1 -0
- package/dist/identity/types.js +8 -0
- package/dist/identity/types.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/runtime/auth.d.ts +56 -0
- package/dist/runtime/auth.d.ts.map +1 -0
- package/dist/runtime/auth.js +204 -0
- package/dist/runtime/auth.js.map +1 -0
- package/dist/runtime/connector.d.ts +138 -0
- package/dist/runtime/connector.d.ts.map +1 -0
- package/dist/runtime/connector.js +82 -0
- package/dist/runtime/connector.js.map +1 -0
- package/dist/runtime/credentials.d.ts +68 -0
- package/dist/runtime/credentials.d.ts.map +1 -0
- package/dist/runtime/credentials.js +212 -0
- package/dist/runtime/credentials.js.map +1 -0
- package/dist/runtime/identity-http.d.ts +27 -0
- package/dist/runtime/identity-http.d.ts.map +1 -0
- package/dist/runtime/identity-http.js +159 -0
- package/dist/runtime/identity-http.js.map +1 -0
- package/dist/runtime/identity-runtime.d.ts +54 -0
- package/dist/runtime/identity-runtime.d.ts.map +1 -0
- package/dist/runtime/identity-runtime.js +151 -0
- package/dist/runtime/identity-runtime.js.map +1 -0
- package/dist/runtime/index.d.ts +14 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +114 -68
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/langsmith-connector.d.ts +247 -0
- package/dist/runtime/langsmith-connector.d.ts.map +1 -0
- package/dist/runtime/langsmith-connector.js +1175 -0
- package/dist/runtime/langsmith-connector.js.map +1 -0
- package/dist/runtime/managed-middleware.d.ts +25 -0
- package/dist/runtime/managed-middleware.d.ts.map +1 -0
- package/dist/runtime/managed-middleware.js +76 -0
- package/dist/runtime/managed-middleware.js.map +1 -0
- package/dist/runtime/managed-tools.d.ts +61 -0
- package/dist/runtime/managed-tools.d.ts.map +1 -0
- package/dist/runtime/managed-tools.js +102 -0
- package/dist/runtime/managed-tools.js.map +1 -0
- package/dist/runtime/sandbox-manager.d.ts +3 -2
- package/dist/runtime/sandbox-manager.d.ts.map +1 -1
- package/dist/runtime/sandbox-manager.js.map +1 -1
- package/dist/runtime/setup-script.d.ts +4 -7
- package/dist/runtime/setup-script.d.ts.map +1 -1
- package/dist/runtime/setup-script.js.map +1 -1
- package/dist/runtime/types.d.ts +23 -21
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/validated-token.d.ts +53 -0
- package/dist/runtime/validated-token.d.ts.map +1 -0
- package/dist/runtime/validated-token.js +411 -0
- package/dist/runtime/validated-token.js.map +1 -0
- package/dist/types.d.ts +15 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +12 -8
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The managed `identity.ts` declaration primitive.
|
|
3
|
+
*
|
|
4
|
+
* A project's root `identity.ts` exports a named `identity` created with
|
|
5
|
+
* `defineIdentity(...)` (or `defineIdentity.preset(...)`). The compiler
|
|
6
|
+
* discovers it, generates the custom-auth handler, and wires thread/memory
|
|
7
|
+
* scoping and downstream credentials.
|
|
8
|
+
*
|
|
9
|
+
* This module is pure authoring-time config construction plus eager validation —
|
|
10
|
+
* it has no runtime dependency (the `providers.*` helpers return plain data).
|
|
11
|
+
*/
|
|
12
|
+
import { supabaseProvider } from "./supabase.js";
|
|
13
|
+
export { supabaseAuthV1Base } from "./supabase.js";
|
|
14
|
+
const PRESETS = {
|
|
15
|
+
"private-assistant": {
|
|
16
|
+
ingress: { http: "trusted_backend" },
|
|
17
|
+
tenancy: "single",
|
|
18
|
+
scoping: { threads: "actor", memory: "actor", credentials: "actor" },
|
|
19
|
+
},
|
|
20
|
+
"multi-tenant-saas": {
|
|
21
|
+
ingress: { http: "trusted_backend" },
|
|
22
|
+
tenancy: "multi",
|
|
23
|
+
scoping: { threads: "actor", memory: "tenant", credentials: "agent" },
|
|
24
|
+
},
|
|
25
|
+
"shared-bot": {
|
|
26
|
+
ingress: { http: "trusted_backend" },
|
|
27
|
+
tenancy: "single",
|
|
28
|
+
scoping: { threads: "channel", memory: "actor", credentials: "agent" },
|
|
29
|
+
},
|
|
30
|
+
"internal-tool": {
|
|
31
|
+
ingress: { http: "trusted_backend" },
|
|
32
|
+
tenancy: "single",
|
|
33
|
+
scoping: { threads: "actor", memory: "actor", credentials: "agent" },
|
|
34
|
+
},
|
|
35
|
+
service: {
|
|
36
|
+
ingress: { http: "trusted_backend" },
|
|
37
|
+
tenancy: "single",
|
|
38
|
+
scoping: { memory: "agent", credentials: "agent" },
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Declare the identity contract for the deployment.
|
|
43
|
+
*
|
|
44
|
+
* Most developers call {@link defineIdentity.preset} instead. The three scoping
|
|
45
|
+
* axes are the power-user layer underneath.
|
|
46
|
+
*/
|
|
47
|
+
export const defineIdentity = Object.assign(function defineIdentity(config) {
|
|
48
|
+
validateIdentity(config);
|
|
49
|
+
return { kind: "identity", config };
|
|
50
|
+
}, {
|
|
51
|
+
preset(name, overrides) {
|
|
52
|
+
const base = PRESETS[name];
|
|
53
|
+
if (base === undefined) {
|
|
54
|
+
throw new Error(`defineIdentity.preset(...) unknown preset "${String(name)}". ` +
|
|
55
|
+
`Valid presets: ${Object.keys(PRESETS).join(", ")}.`);
|
|
56
|
+
}
|
|
57
|
+
return defineIdentity(deepMerge(base, overrides));
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Provider integrations — authoring-time sugar over {@link ValidatedTokenProvider}.
|
|
62
|
+
* Each returns a plain provider object you can spread-and-override, so
|
|
63
|
+
* there is no new runtime surface.
|
|
64
|
+
*/
|
|
65
|
+
export const providers = {
|
|
66
|
+
auth0({ domain, audience, }) {
|
|
67
|
+
return {
|
|
68
|
+
issuer: `https://${domain}/`,
|
|
69
|
+
jwks: `https://${domain}/.well-known/jwks.json`,
|
|
70
|
+
...(audience ? { audience } : {}),
|
|
71
|
+
algorithms: ["RS256"],
|
|
72
|
+
claims: { actor: "sub", tenant: "org_id" },
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
clerk({ domain }) {
|
|
76
|
+
return {
|
|
77
|
+
issuer: `https://${domain}`,
|
|
78
|
+
jwks: `https://${domain}/.well-known/jwks.json`,
|
|
79
|
+
algorithms: ["RS256"],
|
|
80
|
+
claims: { actor: "sub" },
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
okta({ domain, audience, }) {
|
|
84
|
+
return {
|
|
85
|
+
issuer: `https://${domain}`,
|
|
86
|
+
jwks: `https://${domain}/oauth2/v1/keys`,
|
|
87
|
+
...(audience ? { audience } : {}),
|
|
88
|
+
algorithms: ["RS256"],
|
|
89
|
+
claims: { actor: "sub" },
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
cognito({ userPoolId, region, }) {
|
|
93
|
+
const issuer = `https://cognito-idp.${region}.amazonaws.com/${userPoolId}`;
|
|
94
|
+
return {
|
|
95
|
+
issuer,
|
|
96
|
+
jwks: `${issuer}/.well-known/jwks.json`,
|
|
97
|
+
algorithms: ["RS256"],
|
|
98
|
+
claims: { actor: "sub" },
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
entra({ tenantId, audience, }) {
|
|
102
|
+
return {
|
|
103
|
+
issuer: `https://login.microsoftonline.com/${tenantId}/v2.0`,
|
|
104
|
+
jwks: `https://login.microsoftonline.com/${tenantId}/discovery/v2.0/keys`,
|
|
105
|
+
...(audience ? { audience } : {}),
|
|
106
|
+
algorithms: ["RS256"],
|
|
107
|
+
claims: { actor: "oid" },
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
google({ audience } = {}) {
|
|
111
|
+
return {
|
|
112
|
+
issuer: "https://accounts.google.com",
|
|
113
|
+
jwks: "https://www.googleapis.com/oauth2/v3/certs",
|
|
114
|
+
...(audience ? { audience } : {}),
|
|
115
|
+
algorithms: ["RS256"],
|
|
116
|
+
claims: { actor: "sub", email: "email" },
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
/** @see {@link supabaseProvider} */
|
|
120
|
+
supabase(options) {
|
|
121
|
+
return supabaseProvider(options);
|
|
122
|
+
},
|
|
123
|
+
/** Universal fallback for any OIDC-compliant IdP via discovery. */
|
|
124
|
+
oidc({ issuer, audience, }) {
|
|
125
|
+
return {
|
|
126
|
+
issuer,
|
|
127
|
+
discover: true,
|
|
128
|
+
algorithms: ["RS256"],
|
|
129
|
+
...(audience ? { audience } : {}),
|
|
130
|
+
claims: { actor: "sub" },
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
/**
|
|
134
|
+
* GitHub OAuth access tokens (opaque bearer tokens, not JWTs). MDA verifies
|
|
135
|
+
* each request by calling `GET https://api.github.com/user` with the token.
|
|
136
|
+
*/
|
|
137
|
+
github() {
|
|
138
|
+
return {
|
|
139
|
+
id: "github",
|
|
140
|
+
introspect: {
|
|
141
|
+
url: "https://api.github.com/user",
|
|
142
|
+
headers: {
|
|
143
|
+
Accept: "application/vnd.github+json",
|
|
144
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
145
|
+
"User-Agent": "managed-deepagents-github-example",
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
claims: { actor: "login", email: "email" },
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
/** MDA-issued anonymous/guest tokens. */
|
|
152
|
+
guest({ ttl, actorPrefix, } = {}) {
|
|
153
|
+
return {
|
|
154
|
+
id: "guest",
|
|
155
|
+
guest: {
|
|
156
|
+
issue: true,
|
|
157
|
+
...(ttl ? { ttl } : {}),
|
|
158
|
+
...(actorPrefix ? { actorPrefix } : {}),
|
|
159
|
+
},
|
|
160
|
+
claims: { actor: "sub" },
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
const MANAGED_CREDENTIAL_MODES = ["agent", "actor", "none"];
|
|
165
|
+
/**
|
|
166
|
+
* Eagerly reject illegal identity configs at authoring time so misconfig never
|
|
167
|
+
* reaches the compiler or runtime.
|
|
168
|
+
*/
|
|
169
|
+
export function validateIdentity(config) {
|
|
170
|
+
const provided = config;
|
|
171
|
+
const ingress = provided.ingress;
|
|
172
|
+
if (ingress === null || typeof ingress !== "object" || !("http" in ingress)) {
|
|
173
|
+
throw new Error("defineIdentity(...) requires an `ingress.http` value ('trusted_backend' or a validated_token config).");
|
|
174
|
+
}
|
|
175
|
+
const tenancy = provided.tenancy;
|
|
176
|
+
if (tenancy !== "single" && tenancy !== "multi") {
|
|
177
|
+
throw new Error('defineIdentity(...) requires `tenancy` to be "single" or "multi".');
|
|
178
|
+
}
|
|
179
|
+
const scoping = provided.scoping;
|
|
180
|
+
if (scoping === null || typeof scoping !== "object") {
|
|
181
|
+
throw new Error("defineIdentity(...) requires a `scoping` object.");
|
|
182
|
+
}
|
|
183
|
+
if (typeof scoping.memory !== "string") {
|
|
184
|
+
throw new Error('defineIdentity(...) requires `scoping.memory` (one of "actor" | "tenant" | "agent" | "none").');
|
|
185
|
+
}
|
|
186
|
+
// tenancy: "single" cannot use any tenant-scoped axis.
|
|
187
|
+
if (tenancy === "single") {
|
|
188
|
+
const tenantAxes = ["threads", "memory", "credentials"].filter((axis) => scoping[axis] === "tenant");
|
|
189
|
+
if (tenantAxes.length > 0) {
|
|
190
|
+
throw new Error(`defineIdentity(...) cannot use "tenant" scope (${tenantAxes.join(", ")}) with tenancy: "single". Set tenancy: "multi".`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// Credentials axis must agree with the presence of a resolver/endpoint.
|
|
194
|
+
const hasResolver = provided.credentials !== undefined;
|
|
195
|
+
const credentialsMode = scoping.credentials;
|
|
196
|
+
if (credentialsMode === "custom" && !hasResolver) {
|
|
197
|
+
throw new Error('defineIdentity(...) with scoping.credentials: "custom" requires a `credentials` resolver or endpoint.');
|
|
198
|
+
}
|
|
199
|
+
if (hasResolver &&
|
|
200
|
+
typeof credentialsMode === "string" &&
|
|
201
|
+
MANAGED_CREDENTIAL_MODES.includes(credentialsMode)) {
|
|
202
|
+
throw new Error(`defineIdentity(...) provides a \`credentials\` resolver but scoping.credentials is "${credentialsMode}". ` +
|
|
203
|
+
'Set scoping.credentials: "custom" (or remove the resolver).');
|
|
204
|
+
}
|
|
205
|
+
if (hasResolver) {
|
|
206
|
+
validateCredentialResolver(provided.credentials);
|
|
207
|
+
}
|
|
208
|
+
// validated_token ingress needs at least one provider, each with claims.actor.
|
|
209
|
+
const http = ingress.http;
|
|
210
|
+
if (isValidatedToken(http)) {
|
|
211
|
+
validateValidatedToken(http);
|
|
212
|
+
}
|
|
213
|
+
else if (http !== "trusted_backend") {
|
|
214
|
+
throw new Error('defineIdentity(...) `ingress.http` must be "trusted_backend" or a { mode: "validated_token", providers: [...] } config.');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function isValidatedToken(http) {
|
|
218
|
+
return (typeof http === "object" &&
|
|
219
|
+
http !== null &&
|
|
220
|
+
http.mode === "validated_token");
|
|
221
|
+
}
|
|
222
|
+
function validateValidatedToken(http) {
|
|
223
|
+
const list = http.providers;
|
|
224
|
+
if (!Array.isArray(list) || list.length === 0) {
|
|
225
|
+
throw new Error("defineIdentity(...) validated_token ingress requires a non-empty `providers` list.");
|
|
226
|
+
}
|
|
227
|
+
const multiple = list.length > 1;
|
|
228
|
+
for (const [index, entry] of list.entries()) {
|
|
229
|
+
const provider = entry;
|
|
230
|
+
const label = provider?.id ?? `#${index}`;
|
|
231
|
+
if (provider === null || typeof provider !== "object") {
|
|
232
|
+
throw new Error(`defineIdentity(...) validated_token provider ${label} must be an object.`);
|
|
233
|
+
}
|
|
234
|
+
if (typeof provider.claims !== "object" ||
|
|
235
|
+
provider.claims === null ||
|
|
236
|
+
typeof provider.claims.actor !== "string" ||
|
|
237
|
+
provider.claims.actor.length === 0) {
|
|
238
|
+
throw new Error(`defineIdentity(...) validated_token provider ${label} requires \`claims.actor\`.`);
|
|
239
|
+
}
|
|
240
|
+
if (multiple && typeof provider.id !== "string") {
|
|
241
|
+
throw new Error("defineIdentity(...) each validated_token provider requires an `id` when more than one is configured.");
|
|
242
|
+
}
|
|
243
|
+
const hasVerifier = typeof provider.jwks === "string" ||
|
|
244
|
+
provider.discover === true ||
|
|
245
|
+
typeof provider.discoveryUrl === "string" ||
|
|
246
|
+
provider.introspect !== undefined ||
|
|
247
|
+
provider.guest !== undefined;
|
|
248
|
+
if (!hasVerifier) {
|
|
249
|
+
throw new Error(`defineIdentity(...) validated_token provider ${label} must declare one of \`jwks\`, \`discover\`, \`discoveryUrl\`, \`introspect\`, or \`guest\`.`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function validateCredentialResolver(credentials) {
|
|
254
|
+
if (credentials === null || typeof credentials !== "object") {
|
|
255
|
+
throw new Error("defineIdentity(...) `credentials` must be a resolver ({ resolve }) or endpoint ({ endpoint }) config.");
|
|
256
|
+
}
|
|
257
|
+
const cfg = credentials;
|
|
258
|
+
const hasResolveFn = typeof cfg.resolve === "function";
|
|
259
|
+
const hasEndpoint = typeof cfg.endpoint === "object" &&
|
|
260
|
+
cfg.endpoint !== null &&
|
|
261
|
+
typeof cfg.endpoint.url === "string";
|
|
262
|
+
if (hasResolveFn === hasEndpoint) {
|
|
263
|
+
throw new Error("defineIdentity(...) `credentials` requires exactly one of `resolve` (function) or `endpoint` ({ url }).");
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function isPlainObject(value) {
|
|
267
|
+
return (typeof value === "object" &&
|
|
268
|
+
value !== null &&
|
|
269
|
+
!Array.isArray(value) &&
|
|
270
|
+
typeof value !== "function");
|
|
271
|
+
}
|
|
272
|
+
function deepMerge(base, patch) {
|
|
273
|
+
if (patch === undefined)
|
|
274
|
+
return structuredCloneConfig(base);
|
|
275
|
+
if (!isPlainObject(base) || !isPlainObject(patch)) {
|
|
276
|
+
return patch;
|
|
277
|
+
}
|
|
278
|
+
const out = { ...base };
|
|
279
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
280
|
+
if (value === undefined)
|
|
281
|
+
continue;
|
|
282
|
+
const current = out[key];
|
|
283
|
+
out[key] =
|
|
284
|
+
isPlainObject(current) && isPlainObject(value)
|
|
285
|
+
? deepMerge(current, value)
|
|
286
|
+
: value;
|
|
287
|
+
}
|
|
288
|
+
return out;
|
|
289
|
+
}
|
|
290
|
+
function structuredCloneConfig(value) {
|
|
291
|
+
if (Array.isArray(value)) {
|
|
292
|
+
return value.map((item) => structuredCloneConfig(item));
|
|
293
|
+
}
|
|
294
|
+
if (isPlainObject(value)) {
|
|
295
|
+
const out = {};
|
|
296
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
297
|
+
out[key] = structuredCloneConfig(inner);
|
|
298
|
+
}
|
|
299
|
+
return out;
|
|
300
|
+
}
|
|
301
|
+
return value;
|
|
302
|
+
}
|
|
303
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAgC,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CAAC;gBAC1D,CAAC,CAAC,KAAK,CAAC;IACd,CAAC;IACD,OAAO,GAAQ,CAAC;AAClB,CAAC;AAED,SAAS,qBAAqB,CAAI,KAAQ;IACxC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAiB,CAAC;IAC1E,CAAC;IACD,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,GAAG,GAA4B,EAAE,CAAC;QACxC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACjD,GAAG,CAAC,GAAG,CAAC,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,GAAQ,CAAC;IAClB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supabase validated-token provider helpers.
|
|
3
|
+
*
|
|
4
|
+
* Authoring-time sugar for {@link ValidatedTokenProvider} configs that talk to
|
|
5
|
+
* Supabase Auth (project refs, custom domains, multi-region introspection).
|
|
6
|
+
*/
|
|
7
|
+
import type { ValidatedTokenProvider } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* A single Supabase region for multi-region introspection. A bare string is the
|
|
10
|
+
* introspection URL (using the shared `${SUPABASE_ANON_KEY}`); an object pins a
|
|
11
|
+
* `projectRef` or explicit `url`, plus an optional region-specific `anonKey`
|
|
12
|
+
* (or raw `headers`) so each region uses its own project and anon key.
|
|
13
|
+
*/
|
|
14
|
+
export type SupabaseRegion = string | {
|
|
15
|
+
projectRef?: string;
|
|
16
|
+
url?: string;
|
|
17
|
+
anonKey?: string;
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
};
|
|
20
|
+
/** Options for {@link supabaseProvider}. */
|
|
21
|
+
export interface SupabaseProviderOptions {
|
|
22
|
+
projectRef?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Project URL or custom auth domain (e.g. `https://auth.example.com`).
|
|
25
|
+
* Sets `discoveryUrl` so the runtime resolves the real JWT `iss` + JWKS
|
|
26
|
+
* via OIDC — vanity hosts are not the token issuer.
|
|
27
|
+
*/
|
|
28
|
+
url?: string;
|
|
29
|
+
introspect?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Multi-region introspection: map each region to its Supabase project. A
|
|
32
|
+
* string is a `projectRef`; an object can pin an explicit `url`/`anonKey` (so
|
|
33
|
+
* each region uses its own project + anon key). Only valid with `introspect`.
|
|
34
|
+
*/
|
|
35
|
+
regions?: Record<string, SupabaseRegion>;
|
|
36
|
+
/** Client header carrying the region (default `x-supabase-region`). */
|
|
37
|
+
regionHeader?: string;
|
|
38
|
+
}
|
|
39
|
+
/** Normalize a Supabase project or custom-domain URL to the `…/auth/v1` root. */
|
|
40
|
+
export declare function supabaseAuthV1Base(url: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Build a Supabase {@link ValidatedTokenProvider}.
|
|
43
|
+
*
|
|
44
|
+
* @param options - Project ref, custom domain URL, and/or multi-region introspect.
|
|
45
|
+
* @returns A plain provider object for `defineIdentity` / `validated_token`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function supabaseProvider(options: SupabaseProviderOptions): ValidatedTokenProvider;
|
|
48
|
+
//# sourceMappingURL=supabase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/identity/supabase.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GACtB,MAAM,GACN;IACE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AAEN,4CAA4C;AAC5C,MAAM,WAAW,uBAAuB;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACzC,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAMD,iFAAiF;AACjF,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAStD;AAyDD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,uBAAuB,GAC/B,sBAAsB,CAgFxB"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supabase validated-token provider helpers.
|
|
3
|
+
*
|
|
4
|
+
* Authoring-time sugar for {@link ValidatedTokenProvider} configs that talk to
|
|
5
|
+
* Supabase Auth (project refs, custom domains, multi-region introspection).
|
|
6
|
+
*/
|
|
7
|
+
function supabaseBase(projectRef) {
|
|
8
|
+
return `https://${projectRef}.supabase.co/auth/v1`;
|
|
9
|
+
}
|
|
10
|
+
/** Normalize a Supabase project or custom-domain URL to the `…/auth/v1` root. */
|
|
11
|
+
export function supabaseAuthV1Base(url) {
|
|
12
|
+
let trimmed = url.replace(/\/$/, "");
|
|
13
|
+
if (trimmed.endsWith("/user")) {
|
|
14
|
+
trimmed = trimmed.slice(0, -"/user".length);
|
|
15
|
+
}
|
|
16
|
+
if (trimmed.endsWith("/auth/v1")) {
|
|
17
|
+
return trimmed;
|
|
18
|
+
}
|
|
19
|
+
return `${trimmed}/auth/v1`;
|
|
20
|
+
}
|
|
21
|
+
function supabaseRegionIssuers(regions) {
|
|
22
|
+
const issuers = [];
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
for (const entry of Object.values(regions)) {
|
|
25
|
+
let issuer;
|
|
26
|
+
if (typeof entry === "string") {
|
|
27
|
+
issuer = supabaseAuthV1Base(entry);
|
|
28
|
+
}
|
|
29
|
+
else if (entry.projectRef) {
|
|
30
|
+
issuer = supabaseBase(entry.projectRef);
|
|
31
|
+
}
|
|
32
|
+
else if (entry.url) {
|
|
33
|
+
issuer = supabaseAuthV1Base(entry.url);
|
|
34
|
+
}
|
|
35
|
+
if (issuer && !seen.has(issuer)) {
|
|
36
|
+
seen.add(issuer);
|
|
37
|
+
issuers.push(issuer);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return issuers;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Normalize authoring-time Supabase regions into the runtime `regions` shape. A
|
|
44
|
+
* bare string stays a URL (using the shared base `apikey`); an object resolves
|
|
45
|
+
* its `url` from `url`/`projectRef` and, when given, carries region-specific
|
|
46
|
+
* `headers`/`anonKey` that override the shared `apikey` at introspection time.
|
|
47
|
+
*/
|
|
48
|
+
function normalizeSupabaseRegions(regions) {
|
|
49
|
+
const out = {};
|
|
50
|
+
for (const [region, entry] of Object.entries(regions)) {
|
|
51
|
+
if (typeof entry === "string") {
|
|
52
|
+
out[region] = entry;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const url = entry.url ??
|
|
56
|
+
(entry.projectRef ? `${supabaseBase(entry.projectRef)}/user` : undefined);
|
|
57
|
+
if (!url) {
|
|
58
|
+
throw new Error(`providers.supabase(...) region "${region}" needs a \`projectRef\` or \`url\`.`);
|
|
59
|
+
}
|
|
60
|
+
const headers = entry.headers ?? (entry.anonKey ? { apikey: entry.anonKey } : undefined);
|
|
61
|
+
out[region] = headers ? { url, headers } : { url };
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Build a Supabase {@link ValidatedTokenProvider}.
|
|
67
|
+
*
|
|
68
|
+
* @param options - Project ref, custom domain URL, and/or multi-region introspect.
|
|
69
|
+
* @returns A plain provider object for `defineIdentity` / `validated_token`.
|
|
70
|
+
*/
|
|
71
|
+
export function supabaseProvider(options) {
|
|
72
|
+
const { projectRef, url, introspect, regions, regionHeader = "x-supabase-region", } = options;
|
|
73
|
+
if (projectRef && url) {
|
|
74
|
+
throw new Error("providers.supabase(...) accepts only one of `projectRef` or `url`.");
|
|
75
|
+
}
|
|
76
|
+
if (introspect) {
|
|
77
|
+
if (regions) {
|
|
78
|
+
const provider = {
|
|
79
|
+
id: "supabase",
|
|
80
|
+
introspect: {
|
|
81
|
+
regionHeader,
|
|
82
|
+
regions: normalizeSupabaseRegions(regions),
|
|
83
|
+
headers: { apikey: "${SUPABASE_ANON_KEY}" },
|
|
84
|
+
},
|
|
85
|
+
claims: { actor: "email" },
|
|
86
|
+
};
|
|
87
|
+
const issuers = supabaseRegionIssuers(regions);
|
|
88
|
+
if (issuers.length > 0) {
|
|
89
|
+
provider.issuers = issuers;
|
|
90
|
+
}
|
|
91
|
+
return provider;
|
|
92
|
+
}
|
|
93
|
+
if (url) {
|
|
94
|
+
const authBase = supabaseAuthV1Base(url);
|
|
95
|
+
return {
|
|
96
|
+
id: "supabase",
|
|
97
|
+
discoveryUrl: authBase,
|
|
98
|
+
introspect: {
|
|
99
|
+
url: `${authBase}/user`,
|
|
100
|
+
headers: { apikey: "${SUPABASE_ANON_KEY}" },
|
|
101
|
+
},
|
|
102
|
+
claims: { actor: "email" },
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (!projectRef) {
|
|
106
|
+
throw new Error("providers.supabase(...) requires `projectRef`, `url`, or `regions` when introspect is true.");
|
|
107
|
+
}
|
|
108
|
+
const base = supabaseBase(projectRef);
|
|
109
|
+
return {
|
|
110
|
+
id: "supabase",
|
|
111
|
+
issuer: base,
|
|
112
|
+
introspect: {
|
|
113
|
+
url: `${base}/user`,
|
|
114
|
+
headers: { apikey: "${SUPABASE_ANON_KEY}" },
|
|
115
|
+
},
|
|
116
|
+
claims: { actor: "email" },
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (url) {
|
|
120
|
+
return {
|
|
121
|
+
id: "supabase",
|
|
122
|
+
discoveryUrl: supabaseAuthV1Base(url),
|
|
123
|
+
algorithms: ["ES256", "RS256"],
|
|
124
|
+
claims: { actor: "email" },
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (!projectRef) {
|
|
128
|
+
throw new Error("providers.supabase(...) without `introspect` requires `projectRef` or `url`.");
|
|
129
|
+
}
|
|
130
|
+
const base = supabaseBase(projectRef);
|
|
131
|
+
return {
|
|
132
|
+
id: "supabase",
|
|
133
|
+
issuer: base,
|
|
134
|
+
jwks: `${base}/.well-known/jwks.json`,
|
|
135
|
+
algorithms: ["ES256", "RS256"],
|
|
136
|
+
claims: { actor: "email" },
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=supabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supabase.js","sourceRoot":"","sources":["../../src/identity/supabase.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAuCH,SAAS,YAAY,CAAC,UAAkB;IACtC,OAAO,WAAW,UAAU,sBAAsB,CAAC;AACrD,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,IAAI,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACrC,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9B,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IACD,IAAI,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,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