@midsummer-ai/sdk 0.1.0-staging.3814 → 0.1.0-staging.3817
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/auth/contract.mjs +2 -1
- package/auth/index.mjs +1 -1
- package/auth/password.mjs +1 -1
- package/{auth-C5lH_TF0.mjs → auth-BvX0Xd2G.mjs} +14 -394
- package/{engine-9WBvqNSV.mjs → engine-BEuwy5dz.mjs} +108 -223
- package/guard-DrFHnHzr.mjs +579 -0
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { i as __toCommonJS, n as __esmMin, r as __exportAll, t as __commonJSMin } from "./rolldown-runtime-CL6CfywC.mjs";
|
|
2
|
+
import { KEY_PREFIX } from "./auth/key.mjs";
|
|
3
|
+
import { h as IDENTITY_SCOPES, o as ourWords, u as JoinRefused, x as resourceOf } from "./guard-DrFHnHzr.mjs";
|
|
4
|
+
import { impersonationIdentifier } from "./auth/impersonate.mjs";
|
|
2
5
|
import { $ as queueAfterTransactionHook, $t as getOrigin, A as freshSessionMiddleware, At as userSchema, B as sensitiveSessionMiddleware, Bt as jwtVerify, C as parseScopeField, Ct as parseAccountOutput, D as constantTimeEqual, Dt as parseUserInput, E as generateRandomString, Et as parseSessionOutput, F as listSessions, Ft as decodeJwt, G as createAuthMiddleware, Gt as JWTExpired, H as appendQueryParams, Ht as JOSEError, I as requestOnlySessionMiddleware, It as decodeProtectedHeader, J as defu, Jt as hasServerSessionStore, K as isAPIError$1, Kt as sha256, L as revokeOtherSessions, Lt as importJWK, M as getSession, Mt as number, N as getSessionFromCtx, Nt as string, O as getOAuthServerContext, Ot as parseUserOutput, P as isStateful, Pt as signJWT, Q as getCurrentAdapter, Qt as getHost, R as revokeSession, Rt as createLocalJWKSet, S as parseProviderEmailVerified, St as mergeSchema, T as symmetricEncrypt, Tt as parseSessionInput, U as normalizePathname, Ut as JWKSNoMatchingKey, V as sessionMiddleware, Vt as isJwkSet, W as createAuthEndpoint, Wt as JWKSTimeout, X as findInvalidTrustedProxies, Xt as isPromise, Y as createRateLimitKey, Yt as shouldBindAccountCookieToSessionUser, Z as getIP, Zt as getBaseURL, _ as encodeBasicCredentials, _t as parseSetCookieHeader, a as resolveSigningKey, an as BASE_ERROR_CODES, at as tryGetCurrentAuthEndpointContext, b as getPrimaryClientId, bt as buildSyntheticUserOutput, c as getDefaultKeyAlg, ct as deleteSessionCookie, d as getOperationId, dt as setCookieCache, en as getProtocol, et as runWithAdapter, f as verifyJwsAccessToken, ft as setSessionCookie, g as resolveClientAssertionParams, gt as createRouter$1, h as betterFetch, ht as setAccountCookie, i as getJwtToken, in as trimTrailingSlashes, it as getCurrentAuthEndpointContext, j as getAuthoritativeSessionFromCtx, jt as coreSchema, k as setOAuthState, kt as filterOutputFields, l as getJwksAdapter, lt as expireCookie, m as fetchRefusingRedirects, mt as getAccountCookie, n as metadataResponse, nn as isRequestLike, nt as runtimeSchemaCheckFor, o as signJWT$1, on as defineErrorCodes, ot as createHash, p as DPOP_SIGNING_ALGORITHMS, pt as createHMAC, q as isLoopbackHost$1, qt as hkdf, r as oauthProvider, rn as resolveBaseURL, rt as schemaCheckFor, s as createJwk, sn as wildcardMatch, st as createCookieGetter, t as getIssuer, tn as isDynamicBaseURLConfig, tt as runWithTransaction, u as dispatchAuthEndpoint, ut as getCookies, v as generateCodeChallenge, vt as parseCookieCachePayload, w as symmetricDecrypt, wt as parseAdditionalUserInputFromProviderProfile, x as mergeScopes, xt as getSessionDefaultFields, y as getOAuth2Tokens, yt as getDate$1, z as revokeSessions, zt as SignJWT } from "./authorize-BzDrbYtI-0gOzDrp2.mjs";
|
|
3
6
|
import { B as getBooleanEnvVar, E as bytesToHex, F as logger, H as isDevelopment, M as utf8ToBytes, P as createLogger, R as ENV, U as isProduction, V as getEnvVar, W as isTest, a as createRandomStringGenerator, b as getAuthTables, c as ATTR_DB_COLLECTION_NAME, d as ATTR_HTTP_RESPONSE_STATUS_CODE, g as base64Url, h as base64$1, i as generateId$1, o as createWithSpan, s as ATTR_CONTEXT, t as encodeDeterministicId, u as ATTR_HOOK_TYPE, v as toUint8Array, y as safeJSONParse, z as env } from "./get-id-field-vhOArqXN.mjs";
|
|
4
7
|
import { C as string$1, D as xor, F as BetterAuthError, H as getBetterAuthVersion, P as APIError, S as strictObject, T as unknown, b as optional, c as array, d as email, f as ipv4, g as looseObject, h as literal, j as validate, l as boolean, m as json, o as _enum, s as any, u as date, v as number$1, w as union, x as record, y as object } from "./schemas-DTJTcCdK.mjs";
|
|
5
8
|
import { n as hasRequestState, r as runWithRequestState, t as defineRequestState } from "./request-state-BaLB2Hrt.mjs";
|
|
6
9
|
import { t as createAdapterFactory } from "./factory-9jfDGyc1.mjs";
|
|
7
|
-
import { KEY_PREFIX } from "./auth/key.mjs";
|
|
8
|
-
import { l as screenName, t as authCss } from "./style-CCFT-5rG.mjs";
|
|
9
|
-
import { impersonationIdentifier } from "./auth/impersonate.mjs";
|
|
10
10
|
import { isBcrypt } from "./auth/import.mjs";
|
|
11
11
|
import fsPromises from "node:fs/promises";
|
|
12
12
|
import path from "node:path";
|
|
@@ -21102,7 +21102,7 @@ const _getWebCryptoInternals = {
|
|
|
21102
21102
|
* @param data The data to generate a digest of
|
|
21103
21103
|
* @param algorithm A COSE algorithm ID that maps to a desired SHA algorithm
|
|
21104
21104
|
*/
|
|
21105
|
-
async function digest
|
|
21105
|
+
async function digest(data, algorithm) {
|
|
21106
21106
|
const WebCrypto = await getWebCrypto();
|
|
21107
21107
|
const subtleAlgorithm = mapCoseAlgToWebCryptoAlg(algorithm);
|
|
21108
21108
|
const hashed = await WebCrypto.subtle.digest(subtleAlgorithm, data);
|
|
@@ -39000,7 +39000,7 @@ const _parseAuthenticatorDataInternals = { stubThis: (value) => value };
|
|
|
39000
39000
|
*/
|
|
39001
39001
|
function toHash(data, algorithm = -7) {
|
|
39002
39002
|
if (typeof data === "string") data = fromUTF8String(data);
|
|
39003
|
-
return digest
|
|
39003
|
+
return digest(data, algorithm);
|
|
39004
39004
|
}
|
|
39005
39005
|
//#endregion
|
|
39006
39006
|
//#region ../../node_modules/.bun/@simplewebauthn+server@13.3.3/node_modules/@simplewebauthn/server/esm/helpers/validateCertificatePath.js
|
|
@@ -47829,192 +47829,26 @@ const mcp = (options) => {
|
|
|
47829
47829
|
}
|
|
47830
47830
|
};
|
|
47831
47831
|
};
|
|
47832
|
-
/** How long who a key or a token acts for is kept in memory, in ms. */
|
|
47833
|
-
const AGENT_CACHE_MS = 3e4;
|
|
47834
|
-
/** How many of them one process keeps; past it the oldest is read again when asked. */
|
|
47835
|
-
const KEPT_AGENTS = 1e3;
|
|
47836
|
-
/** The scopes the authorization server itself gives meaning to: who the person is, and staying signed in. */
|
|
47837
|
-
const IDENTITY_SCOPES = {
|
|
47838
|
-
openid: "Know who you are",
|
|
47839
|
-
profile: "See your name and picture",
|
|
47840
|
-
email: "See your email address",
|
|
47841
|
-
offline_access: "Stay connected until you remove it"
|
|
47842
|
-
};
|
|
47843
|
-
/** The address tokens for `origin`'s MCP server are bound to. */
|
|
47844
|
-
const resourceOf = (origin, settings) => `${origin}${settings.mcpPath === "/" ? "" : settings.mcpPath}`;
|
|
47845
|
-
/**
|
|
47846
|
-
* The engine's plugins for agents. Their tables are always there, so `db/authTables.ts` is the same for every
|
|
47847
|
-
* app; clients can register themselves only once the app declares a scope, since before that there is nothing
|
|
47848
|
-
* for one to ask for.
|
|
47849
|
-
*/
|
|
47850
|
-
function agentPlugins(origin, settings) {
|
|
47851
|
-
const declared = Object.keys(settings.scopes);
|
|
47852
|
-
return [
|
|
47853
|
-
jwt({ disableSettingJwtHeader: true }),
|
|
47854
|
-
mcp({
|
|
47855
|
-
resource: resourceOf(origin, settings),
|
|
47856
|
-
loginPage: settings.signInPage,
|
|
47857
|
-
consentPage: settings.consentPage,
|
|
47858
|
-
scopes: [...Object.keys(IDENTITY_SCOPES), ...declared],
|
|
47859
|
-
accessTokenExpiresIn: 300,
|
|
47860
|
-
allowDynamicClientRegistration: declared.length > 0,
|
|
47861
|
-
allowUnauthenticatedClientRegistration: declared.length > 0,
|
|
47862
|
-
clientRegistrationDefaultApplicationType: "infer"
|
|
47863
|
-
}),
|
|
47864
|
-
apiKey({
|
|
47865
|
-
defaultPrefix: KEY_PREFIX,
|
|
47866
|
-
rateLimit: { enabled: false },
|
|
47867
|
-
enableMetadata: true
|
|
47868
|
-
})
|
|
47869
|
-
];
|
|
47870
|
-
}
|
|
47871
|
-
/** An agent's credential on a request: an API key, an MCP client's access token, or neither. */
|
|
47872
|
-
function credentialOf(request) {
|
|
47873
|
-
const header = request.headers.get("x-api-key")?.trim();
|
|
47874
|
-
if (header) return { key: header };
|
|
47875
|
-
const bearer = /^Bearer\s+(\S+)$/i.exec(request.headers.get("authorization") ?? "")?.[1];
|
|
47876
|
-
if (!bearer) return null;
|
|
47877
|
-
return bearer.startsWith("key_") ? { key: bearer } : { token: bearer };
|
|
47878
|
-
}
|
|
47879
|
-
/** A small memory of what was read, each entry for `AGENT_CACHE_MS`. */
|
|
47880
|
-
function remembering(clock = Date.now) {
|
|
47881
|
-
const kept = /* @__PURE__ */ new Map();
|
|
47882
|
-
return {
|
|
47883
|
-
async get(name, read) {
|
|
47884
|
-
const found = kept.get(name);
|
|
47885
|
-
if (found && found.until > clock()) return found.value;
|
|
47886
|
-
const value = await read();
|
|
47887
|
-
if (kept.size >= KEPT_AGENTS) kept.delete(kept.keys().next().value);
|
|
47888
|
-
kept.set(name, {
|
|
47889
|
-
until: clock() + AGENT_CACHE_MS,
|
|
47890
|
-
value
|
|
47891
|
-
});
|
|
47892
|
-
return value;
|
|
47893
|
-
},
|
|
47894
|
-
forget(name) {
|
|
47895
|
-
kept.delete(name);
|
|
47896
|
-
}
|
|
47897
|
-
};
|
|
47898
|
-
}
|
|
47899
|
-
const digest = async (text) => [...new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text)))].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
47900
|
-
/**
|
|
47901
|
-
* The agent a key signs in, or null for one that is unknown, revoked or expired. A key is checked by
|
|
47902
|
-
* the engine, which notes when it was last used; the answer is kept for `AGENT_CACHE_MS`.
|
|
47903
|
-
*/
|
|
47904
|
-
async function agentOfKey(instance, key, memory) {
|
|
47905
|
-
if (!key.startsWith("key_") || key.length > 512) return null;
|
|
47906
|
-
return memory.get(`key:${await digest(key)}`, async () => {
|
|
47907
|
-
const checked = await instance.api.verifyApiKey({ body: { key } });
|
|
47908
|
-
if (!checked.valid || !checked.key) return null;
|
|
47909
|
-
return {
|
|
47910
|
-
via: "key",
|
|
47911
|
-
userId: checked.key.referenceId,
|
|
47912
|
-
scopes: checked.key.permissions?.scope ?? [],
|
|
47913
|
-
agent: {
|
|
47914
|
-
id: checked.key.id,
|
|
47915
|
-
...checked.key.name ? { name: checked.key.name } : {}
|
|
47916
|
-
}
|
|
47917
|
-
};
|
|
47918
|
-
});
|
|
47919
|
-
}
|
|
47920
|
-
/**
|
|
47921
|
-
* The agent an MCP client's access token signs in, or null for one that is not this app's: its signature by the
|
|
47922
|
-
* app's own keys, its issuer, that it is bound to the app's MCP address, and its expiry are all checked.
|
|
47923
|
-
*/
|
|
47924
|
-
async function agentOfToken(instance, token, origin, authPath, resource) {
|
|
47925
|
-
let claims;
|
|
47926
|
-
try {
|
|
47927
|
-
claims = await verifyJwsAccessToken(token, {
|
|
47928
|
-
jwksFetch: async () => await instance.api.getJwks(),
|
|
47929
|
-
jwksCacheKey: instance,
|
|
47930
|
-
verifyOptions: {
|
|
47931
|
-
issuer: `${origin}${authPath}`,
|
|
47932
|
-
audience: resource
|
|
47933
|
-
}
|
|
47934
|
-
});
|
|
47935
|
-
} catch {
|
|
47936
|
-
return null;
|
|
47937
|
-
}
|
|
47938
|
-
const client = typeof claims.azp === "string" ? claims.azp : typeof claims.client_id === "string" ? claims.client_id : null;
|
|
47939
|
-
if (typeof claims.sub !== "string" || !client) return null;
|
|
47940
|
-
const scopes = typeof claims.scope === "string" ? claims.scope.split(" ").filter((scope) => scope && !(scope in IDENTITY_SCOPES)) : [];
|
|
47941
|
-
return {
|
|
47942
|
-
via: "client",
|
|
47943
|
-
userId: claims.sub,
|
|
47944
|
-
scopes,
|
|
47945
|
-
agent: { id: client }
|
|
47946
|
-
};
|
|
47947
|
-
}
|
|
47948
|
-
/** What an MCP client is told when a request needs signing in (401) or a scope its token lacks (403), as RFC 9728 and RFC 6750 say. */
|
|
47949
|
-
function challenge(origin, settings, scope, lacking) {
|
|
47950
|
-
const metadata = `${origin}/.well-known/oauth-protected-resource${settings.mcpPath === "/" ? "" : settings.mcpPath}`;
|
|
47951
|
-
const parts = [
|
|
47952
|
-
...lacking ? ["error=\"insufficient_scope\""] : [],
|
|
47953
|
-
...scope ? [`scope="${scope}"`] : [],
|
|
47954
|
-
`resource_metadata="${metadata}"`
|
|
47955
|
-
];
|
|
47956
|
-
const message = lacking ? `This needs the scope ${scope}.` : "Sign in to use this.";
|
|
47957
|
-
return Response.json({
|
|
47958
|
-
error: lacking ? "insufficient_scope" : "unauthorized",
|
|
47959
|
-
message
|
|
47960
|
-
}, {
|
|
47961
|
-
status: lacking ? 403 : 401,
|
|
47962
|
-
headers: {
|
|
47963
|
-
"WWW-Authenticate": `Bearer ${parts.join(", ")}`,
|
|
47964
|
-
"Cache-Control": "no-store"
|
|
47965
|
-
}
|
|
47966
|
-
});
|
|
47967
|
-
}
|
|
47968
|
-
const escape$2 = (text) => text.replace(/[&<>"']/g, (c) => ({
|
|
47969
|
-
"&": "&",
|
|
47970
|
-
"<": "<",
|
|
47971
|
-
">": ">",
|
|
47972
|
-
"\"": """,
|
|
47973
|
-
"'": "'"
|
|
47974
|
-
})[c]);
|
|
47975
|
-
/**
|
|
47976
|
-
* The page that asks a signed-in person whether a client may use the app as them: the client's name, where it
|
|
47977
|
-
* goes back to, and each scope it asks for in the app's own words. Its two buttons post the same signed query
|
|
47978
|
-
* the page was opened with, so what is granted is what was shown.
|
|
47979
|
-
*/
|
|
47980
|
-
function consentPage(input) {
|
|
47981
|
-
const lines = input.scopes.map((scope) => `<li>${escape$2(input.described[scope] ?? IDENTITY_SCOPES[scope] ?? scope)}</li>`).join("");
|
|
47982
|
-
const app = screenName(input.app, []);
|
|
47983
|
-
const title = `${input.client} wants to use ${app ? `${app} as you` : "your account"}`;
|
|
47984
|
-
return `<!doctype html>
|
|
47985
|
-
<html lang="en">
|
|
47986
|
-
<head>
|
|
47987
|
-
<meta charset="utf-8">
|
|
47988
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
47989
|
-
<meta name="robots" content="noindex">
|
|
47990
|
-
<meta name="color-scheme" content="light dark">
|
|
47991
|
-
<title>${escape$2(title)}</title>
|
|
47992
|
-
<style>${authCss()}</style>
|
|
47993
|
-
</head>
|
|
47994
|
-
<body class="msa msa-screen">
|
|
47995
|
-
<main class="msa-card" aria-labelledby="msa-title">
|
|
47996
|
-
<header class="msa-head"><div class="msa-titles"><h1 id="msa-title" class="msa-title">${escape$2(title)}</h1><p class="msa-lead">You're signed in as <span class="msa-subject msa-inline">${escape$2(input.person)}</span>. It goes back to <span class="msa-subject msa-inline">${escape$2(input.returnsTo)}</span>.</p></div></header>
|
|
47997
|
-
<div class="msa-body">
|
|
47998
|
-
<ul class="msa-list">${lines}</ul>
|
|
47999
|
-
<form method="post" action="${escape$2(input.action)}" class="msa-actions">
|
|
48000
|
-
<input type="hidden" name="oauth_query" value="${escape$2(input.query)}">
|
|
48001
|
-
<button class="msa-button msa-secondary" name="accept" value="false">Don't allow</button>
|
|
48002
|
-
<button class="msa-button msa-primary" name="accept" value="true">Allow</button>
|
|
48003
|
-
</form>
|
|
48004
|
-
</div>
|
|
48005
|
-
</main>
|
|
48006
|
-
</body>
|
|
48007
|
-
</html>
|
|
48008
|
-
`;
|
|
48009
|
-
}
|
|
48010
47832
|
//#endregion
|
|
48011
47833
|
//#region src/auth/engine.ts
|
|
48012
47834
|
/**
|
|
48013
|
-
* The sign-in engine's private Adapter. Everything that knows which engine signs people in is here
|
|
48014
|
-
*
|
|
47835
|
+
* The sign-in engine's private Adapter. Everything that knows which engine signs people in is here; the rest of
|
|
47836
|
+
* `@midsummer-ai/sdk/auth` reaches it only through `Engine`, in its own types, and loads this module with `import()`
|
|
47837
|
+
* when a request first needs it (`engineAdapter` in `./index.ts`). It is
|
|
48015
47838
|
* bundled into the SDK's build, so an app installs nothing more, and nothing it returns, sets or logs names it:
|
|
48016
47839
|
* cookies start `midsummer.`, tables are Midsummer's (`TABLES`), and log lines and errors are in our words.
|
|
48017
47840
|
*/
|
|
47841
|
+
var engine_exports = /* @__PURE__ */ __exportAll({
|
|
47842
|
+
TABLES: () => TABLES,
|
|
47843
|
+
agentOfToken: () => agentOfToken,
|
|
47844
|
+
agentPlugins: () => agentPlugins,
|
|
47845
|
+
buildEngine: () => buildEngine,
|
|
47846
|
+
engineLine: () => engineLine,
|
|
47847
|
+
engineTables: () => engineTables,
|
|
47848
|
+
hashPassword: () => hashPassword,
|
|
47849
|
+
isBcrypt: () => isBcrypt,
|
|
47850
|
+
verifyPassword: () => verifyPassword
|
|
47851
|
+
});
|
|
48018
47852
|
/** Midsummer's name for each of the engine's tables, which is what the app's database calls it. */
|
|
48019
47853
|
const TABLES = {
|
|
48020
47854
|
user: "users",
|
|
@@ -48154,10 +47988,6 @@ const hashPassword = (password) => hashPassword$1(password);
|
|
|
48154
47988
|
async function verifyPassword(input) {
|
|
48155
47989
|
return isBcrypt(input.hash) ? bcryptjs_default.compare(input.password, input.hash) : verifyPassword$1$1(input);
|
|
48156
47990
|
}
|
|
48157
|
-
/** Engine log lines in Midsummer's words: they never name the engine. */
|
|
48158
|
-
function ourWords(text) {
|
|
48159
|
-
return text.replace(/\[better[- ]?auth\]:?\s*/gi, "").replace(/BETTER_AUTH_/g, "AUTH_").replace(/better[- ]?auth/gi, "sign-in");
|
|
48160
|
-
}
|
|
48161
47991
|
/**
|
|
48162
47992
|
* One of the engine's log lines in Midsummer's words: one about its own settings says what happened instead, since an
|
|
48163
47993
|
* app can't change them; any other is `ourWords`.
|
|
@@ -48171,40 +48001,60 @@ function errorLine(error) {
|
|
|
48171
48001
|
const code = error.code;
|
|
48172
48002
|
return `${error.name}${typeof code === "string" && code ? ` (${code})` : ""}${error.message ? `: ${error.message}` : ""}`;
|
|
48173
48003
|
}
|
|
48174
|
-
/**
|
|
48175
|
-
|
|
48176
|
-
|
|
48177
|
-
|
|
48178
|
-
|
|
48179
|
-
|
|
48180
|
-
|
|
48181
|
-
|
|
48182
|
-
|
|
48183
|
-
|
|
48184
|
-
|
|
48185
|
-
|
|
48186
|
-
|
|
48187
|
-
|
|
48188
|
-
|
|
48189
|
-
|
|
48190
|
-
|
|
48191
|
-
|
|
48192
|
-
|
|
48193
|
-
|
|
48194
|
-
|
|
48195
|
-
|
|
48196
|
-
|
|
48197
|
-
|
|
48198
|
-
|
|
48199
|
-
|
|
48200
|
-
|
|
48201
|
-
|
|
48202
|
-
|
|
48203
|
-
|
|
48204
|
-
|
|
48205
|
-
|
|
48004
|
+
/**
|
|
48005
|
+
* The engine's plugins for agents. Their tables are always there, so `db/authTables.ts` is the same for every
|
|
48006
|
+
* app; clients can register themselves only once the app declares a scope, since before that there is nothing
|
|
48007
|
+
* for one to ask for.
|
|
48008
|
+
*/
|
|
48009
|
+
function agentPlugins(origin, settings) {
|
|
48010
|
+
const declared = Object.keys(settings.scopes);
|
|
48011
|
+
return [
|
|
48012
|
+
jwt({ disableSettingJwtHeader: true }),
|
|
48013
|
+
mcp({
|
|
48014
|
+
resource: resourceOf(origin, settings),
|
|
48015
|
+
loginPage: settings.signInPage,
|
|
48016
|
+
consentPage: settings.consentPage,
|
|
48017
|
+
scopes: [...Object.keys(IDENTITY_SCOPES), ...declared],
|
|
48018
|
+
accessTokenExpiresIn: 300,
|
|
48019
|
+
allowDynamicClientRegistration: declared.length > 0,
|
|
48020
|
+
allowUnauthenticatedClientRegistration: declared.length > 0,
|
|
48021
|
+
clientRegistrationDefaultApplicationType: "infer"
|
|
48022
|
+
}),
|
|
48023
|
+
apiKey({
|
|
48024
|
+
defaultPrefix: KEY_PREFIX,
|
|
48025
|
+
rateLimit: { enabled: false },
|
|
48026
|
+
enableMetadata: true
|
|
48027
|
+
})
|
|
48028
|
+
];
|
|
48029
|
+
}
|
|
48030
|
+
/**
|
|
48031
|
+
* The agent an MCP client's access token signs in, or null for one that is not this app's: its signature by the
|
|
48032
|
+
* app's own keys, its issuer, that it is bound to the app's MCP address, and its expiry are all checked.
|
|
48033
|
+
*/
|
|
48034
|
+
async function agentOfToken(instance, token, origin, authPath, resource) {
|
|
48035
|
+
let claims;
|
|
48036
|
+
try {
|
|
48037
|
+
claims = await verifyJwsAccessToken(token, {
|
|
48038
|
+
jwksFetch: async () => await instance.api.getJwks(),
|
|
48039
|
+
jwksCacheKey: instance,
|
|
48040
|
+
verifyOptions: {
|
|
48041
|
+
issuer: `${origin}${authPath}`,
|
|
48042
|
+
audience: resource
|
|
48043
|
+
}
|
|
48044
|
+
});
|
|
48045
|
+
} catch {
|
|
48046
|
+
return null;
|
|
48206
48047
|
}
|
|
48207
|
-
|
|
48048
|
+
const client = typeof claims.azp === "string" ? claims.azp : typeof claims.client_id === "string" ? claims.client_id : null;
|
|
48049
|
+
if (typeof claims.sub !== "string" || !client) return null;
|
|
48050
|
+
const scopes = typeof claims.scope === "string" ? claims.scope.split(" ").filter((scope) => scope && !(scope in IDENTITY_SCOPES)) : [];
|
|
48051
|
+
return {
|
|
48052
|
+
via: "client",
|
|
48053
|
+
userId: claims.sub,
|
|
48054
|
+
scopes,
|
|
48055
|
+
agent: { id: client }
|
|
48056
|
+
};
|
|
48057
|
+
}
|
|
48208
48058
|
/** Who passwords imported as bcrypt are written again for, once the first sign-in with each proves it. */
|
|
48209
48059
|
const rehashing = /* @__PURE__ */ new Map();
|
|
48210
48060
|
const REHASH_KEPT = 100;
|
|
@@ -48433,5 +48283,40 @@ function buildEngine(config) {
|
|
|
48433
48283
|
ready: instance.$context.then(() => void 0)
|
|
48434
48284
|
};
|
|
48435
48285
|
}
|
|
48286
|
+
/** The tables the engine asks for, under Midsummer's names: each field, and the table a reference points to by our name. */
|
|
48287
|
+
function engineTables() {
|
|
48288
|
+
const quiet = { call: async () => null };
|
|
48289
|
+
const options = optionsFor({
|
|
48290
|
+
origin: "https://app.invalid",
|
|
48291
|
+
appName: "app",
|
|
48292
|
+
secret: "x".repeat(32),
|
|
48293
|
+
store: quiet,
|
|
48294
|
+
env: {},
|
|
48295
|
+
send: async () => {},
|
|
48296
|
+
agents: {
|
|
48297
|
+
scopes: {},
|
|
48298
|
+
mcpPath: "/mcp",
|
|
48299
|
+
signInPage: "/sign-in",
|
|
48300
|
+
consentPage: "/consent"
|
|
48301
|
+
},
|
|
48302
|
+
invitationUrl: () => "",
|
|
48303
|
+
admit: async () => {},
|
|
48304
|
+
changed: () => {},
|
|
48305
|
+
impersonationS: 60,
|
|
48306
|
+
cacheS: 60,
|
|
48307
|
+
confirmEmail: false
|
|
48308
|
+
}, quiet);
|
|
48309
|
+
const tables = getAuthTables(options);
|
|
48310
|
+
return Object.values(tables).map((table) => ({
|
|
48311
|
+
name: tableOf(table.modelName),
|
|
48312
|
+
fields: Object.fromEntries(Object.entries(table.fields).map(([key, field]) => [key, field.references ? {
|
|
48313
|
+
...field,
|
|
48314
|
+
references: {
|
|
48315
|
+
...field.references,
|
|
48316
|
+
model: tableOf(tables[field.references.model]?.modelName ?? field.references.model)
|
|
48317
|
+
}
|
|
48318
|
+
} : field]))
|
|
48319
|
+
}));
|
|
48320
|
+
}
|
|
48436
48321
|
//#endregion
|
|
48437
|
-
export {
|
|
48322
|
+
export { hashPassword as n, verifyPassword as r, engine_exports as t };
|