@guren/server 2.25.1 → 2.27.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/{DocsViewerServiceProvider-CIRNHQ2I.js → DocsViewerServiceProvider-BMbcTYVw.js} +1 -1
- package/dist/{Gate-YOt54xGF.js → Gate-BL_zW82W.js} +1 -1
- package/dist/{Job-COMzBNOL.js → Job-DsFMcXVk.js} +35 -3
- package/dist/{McpServiceProvider-B-LioPSz.js → McpServiceProvider-PGFPlYTy.js} +1 -1
- package/dist/{Resource-BdYd4J9a.js → Resource-q3tJpJ0K.js} +194 -54
- package/dist/{ServiceProvider-DDW3MqQJ.js → ServiceProvider-G0YclITd.js} +60 -8
- package/dist/agent/dispatch.d.ts +4 -4
- package/dist/agent/public.js +1 -1
- package/dist/agent/scopes.d.ts +1 -3
- package/dist/agent-request-Caj6bnbj.js +18 -0
- package/dist/auth/AuthManager.d.ts +4 -0
- package/dist/auth/email-verification.d.ts +8 -1
- package/dist/auth/index.js +1 -1
- package/dist/auth/password/describe-hasher.d.ts +11 -0
- package/dist/auth/password-reset.d.ts +8 -2
- package/dist/{auth-vFeem6uM.js → auth-DIugW0O-.js} +108 -13
- package/dist/authorization/index.js +2 -2
- package/dist/authorization/middleware.d.ts +8 -0
- package/dist/{authorization-BLhwA2Yh.js → authorization-Daa6CxCg.js} +17 -2
- package/dist/broadcasting/BroadcastManager.d.ts +23 -6
- package/dist/broadcasting/index.d.ts +1 -1
- package/dist/broadcasting/index.js +1 -1
- package/dist/broadcasting/types.d.ts +13 -1
- package/dist/{broadcasting-BUBCPCnu.js → broadcasting-N4cRV42s.js} +205 -34
- package/dist/cache/CacheManager.d.ts +5 -0
- package/dist/cache/TaggedCache.d.ts +2 -0
- package/dist/cache/index.js +1 -1
- package/dist/cache/pending-computations.d.ts +22 -0
- package/dist/cache/stores/FileStore.d.ts +2 -0
- package/dist/cache/stores/MemoryStore.d.ts +1 -0
- package/dist/cache/stores/RedisStore.d.ts +1 -0
- package/dist/cache/stores/file-lock.d.ts +1 -0
- package/dist/cache/types.d.ts +2 -0
- package/dist/{cache-93n2PCnB.js → cache-BlXopnH1.js} +247 -38
- package/dist/contained-path-BkNSBljW.js +78 -0
- package/dist/container/Container.d.ts +6 -2
- package/dist/container/ServiceProvider.d.ts +27 -2
- package/dist/container/defineModule.d.ts +14 -5
- package/dist/container/definePlugin.d.ts +2 -0
- package/dist/{default-application-D5ezhhiV.js → default-application-DWwscxfW.js} +14 -18
- package/dist/dev-banner-CfQDnkfQ.js +51 -0
- package/dist/{dispatch-BAwzftws.js → dispatch-ENWpBxbE.js} +26 -4
- package/dist/driver-map-CkQc52j-.js +12 -0
- package/dist/encryption/index.js +1 -1
- package/dist/{encryption-D1dxfMqD.js → encryption-CWK5l22W.js} +1 -1
- package/dist/events/EventManager.d.ts +2 -0
- package/dist/events/index.js +1 -1
- package/dist/{events-c94CdUFc.js → events-DQavGm8W.js} +20 -7
- package/dist/health/HealthManager.d.ts +0 -1
- package/dist/health/index.js +1 -1
- package/dist/{health-CB0oS_UE.js → health-Bg0Xj3aD.js} +8 -8
- package/dist/host-port-t6wQFaRu.js +15 -0
- package/dist/hot-reload/testing.d.ts +2 -1
- package/dist/http/Application.d.ts +31 -2
- package/dist/http/dev-banner.d.ts +0 -8
- package/dist/http/host-port.d.ts +8 -0
- package/dist/http/middleware/force-https.d.ts +2 -1
- package/dist/http/middleware/index.d.ts +1 -0
- package/dist/http/middleware/rate-limit.d.ts +1 -4
- package/dist/http/middleware/session-manager.d.ts +5 -0
- package/dist/http/middleware/websocket-origin.d.ts +22 -0
- package/dist/http/public-assets.d.ts +6 -1
- package/dist/i18n/index.js +1 -1
- package/dist/{i18n-DqcRD4qL.js → i18n-DmMKcbqj.js} +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +744 -273
- package/dist/internal/agent-request.d.ts +18 -0
- package/dist/internal/app-conventions.d.ts +6 -0
- package/dist/internal/app-conventions.js +9 -0
- package/dist/internal/dispatched-request.d.ts +4 -0
- package/dist/internal/testing.d.ts +1 -1
- package/dist/internal/testing.js +3 -3
- package/dist/internal/zod-json-schema.js +1 -1
- package/dist/introspection/driver-map.d.ts +3 -0
- package/dist/introspection/flag.d.ts +12 -0
- package/dist/introspection/manifest.d.ts +17 -0
- package/dist/introspection/plain-json.d.ts +7 -0
- package/dist/introspection/types.d.ts +167 -0
- package/dist/lambda/index.js +66 -28
- package/dist/logging/index.js +1 -1
- package/dist/{logging-YbKmbAd7.js → logging-Ci0mBk5k.js} +1 -1
- package/dist/mail/index.js +1 -1
- package/dist/{mail-uRBrUl9q.js → mail-CI2Kfe8P.js} +2 -2
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Controller.d.ts +3 -2
- package/dist/mvc/Router.d.ts +33 -0
- package/dist/mvc/inertia/InertiaEngine.d.ts +31 -0
- package/dist/mvc/inertia/props.d.ts +71 -0
- package/dist/notifications/index.js +1 -1
- package/dist/notifications/registry.d.ts +2 -2
- package/dist/{notifications-LHuujttf.js → notifications-Bp2uamzD.js} +7 -5
- package/dist/providers/ConfigServiceProvider.d.ts +12 -5
- package/dist/queue/Job.d.ts +5 -0
- package/dist/queue/QueueManager.d.ts +3 -0
- package/dist/queue/Worker.d.ts +6 -1
- package/dist/queue/drivers/RedisDriver.d.ts +4 -2
- package/dist/queue/drivers/SqsDriver.d.ts +31 -2
- package/dist/queue/drivers/redis-queue-scripts.d.ts +83 -0
- package/dist/queue/index.js +2 -2
- package/dist/queue/serialize.d.ts +7 -0
- package/dist/queue/types.d.ts +13 -2
- package/dist/{queue-BiBn5Sff.js → queue-C8s3buYz.js} +299 -125
- package/dist/redis/RedisEmailVerificationStore.d.ts +2 -0
- package/dist/redis/RedisPasswordResetStore.d.ts +2 -0
- package/dist/redis/auth-token-scripts.d.ts +4 -0
- package/dist/redis/index.js +50 -0
- package/dist/runtime/index.js +17 -37
- package/dist/scheduling/ScheduledTask.d.ts +2 -1
- package/dist/scheduling/index.js +1 -1
- package/dist/{scheduling-DhYfbJFj.js → scheduling-DNV5tj44.js} +32 -38
- package/dist/serialize-CKXek0Tr.js +17 -0
- package/dist/storage/StorageManager.d.ts +5 -0
- package/dist/storage/drivers/LocalDriver.d.ts +15 -0
- package/dist/storage/index.js +1 -1
- package/dist/storage/url-path.d.ts +2 -0
- package/dist/{storage-6HLaUf9j.js → storage-IlUesK2t.js} +91 -29
- package/dist/support/contained-path.d.ts +8 -0
- package/dist/support/registry-collision.d.ts +12 -0
- package/dist/{vite-manifest-DK55BTLk.js → vite-manifest-wPxfAzjW.js} +2 -58
- package/package.json +6 -2
- package/dist/trim-slashes-BLY9hKAa.js +0 -22
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { UserProvider } from './types.js';
|
|
2
2
|
import { buildTokenUrl, parseTokenUrl } from './utils.js';
|
|
3
3
|
/**
|
|
4
4
|
* Configuration for password reset tokens. Applies at issuance only: the expiry
|
|
@@ -18,6 +18,10 @@ export interface PasswordResetConfig {
|
|
|
18
18
|
export interface PasswordResetTokenStore {
|
|
19
19
|
/** Store a token ID with associated email and expiration */
|
|
20
20
|
store(tokenId: string, email: string, expiresAt: Date): Promise<void>;
|
|
21
|
+
/** Atomically replace every token for this email. Required by token issuance. */
|
|
22
|
+
replace?(tokenId: string, email: string, expiresAt: Date): Promise<void>;
|
|
23
|
+
/** Atomically delete this token only if its stored email matches. Required by completion. */
|
|
24
|
+
consume?(tokenId: string, email: string): Promise<boolean>;
|
|
21
25
|
/** Find email by token ID, returns null if not found or already dropped */
|
|
22
26
|
find(tokenId: string): Promise<{
|
|
23
27
|
email: string;
|
|
@@ -32,6 +36,8 @@ export interface PasswordResetTokenStore {
|
|
|
32
36
|
export declare class MemoryPasswordResetStore implements PasswordResetTokenStore {
|
|
33
37
|
private tokens;
|
|
34
38
|
store(tokenId: string, email: string, expiresAt: Date): Promise<void>;
|
|
39
|
+
replace(tokenId: string, email: string, expiresAt: Date): Promise<void>;
|
|
40
|
+
consume(tokenId: string, email: string): Promise<boolean>;
|
|
35
41
|
find(tokenId: string): Promise<{
|
|
36
42
|
email: string;
|
|
37
43
|
expiresAt: Date;
|
|
@@ -58,7 +64,7 @@ export declare function verifyPasswordResetToken(token: string, store: PasswordR
|
|
|
58
64
|
* Complete a password reset: update the user's password and invalidate the
|
|
59
65
|
* token. Returns the user, or `null` when the token is invalid.
|
|
60
66
|
*/
|
|
61
|
-
export declare function completePasswordReset<T
|
|
67
|
+
export declare function completePasswordReset<T>(token: string, newPassword: string, store: PasswordResetTokenStore, provider: Pick<UserProvider<T>, 'retrieveByCredentials'>, updatePassword: (user: T, password: string) => Promise<void>): Promise<T | null>;
|
|
62
68
|
/** Build a password reset URL from a base URL and token. */
|
|
63
69
|
export declare const buildPasswordResetUrl: typeof buildTokenUrl;
|
|
64
70
|
/** Parse a password reset URL to extract the token and optional email. */
|
|
@@ -4,6 +4,7 @@ import { a as setResolvedPrincipal, i as getResolvedPrincipal, o as Authenticati
|
|
|
4
4
|
import { d as verifyPassword, o as needsRehash, r as hashPassword } from "./Hash-D2DFd8xX.js";
|
|
5
5
|
import { C as secureCompare, S as parseTokenUrl, _ as verifyApiToken, b as generateToken, c as hasBearerHeader, l as parseApiToken, p as revokePresentedToken, t as API_TOKEN_KEY, u as readBearerToken, v as buildTokenUrl, w as secureStringCompare, x as hashToken, y as generateId } from "./api-token-BbgDEd6j.js";
|
|
6
6
|
import { isExpired } from "./support/expiry.js";
|
|
7
|
+
import { n as isAgentToolRequest } from "./agent-request-Caj6bnbj.js";
|
|
7
8
|
import { deleteCookie, getCookie, setCookie } from "hono/cookie";
|
|
8
9
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
9
10
|
import { Model } from "@guren/orm";
|
|
@@ -1069,6 +1070,32 @@ var TokenGuard = class {
|
|
|
1069
1070
|
}
|
|
1070
1071
|
session() {}
|
|
1071
1072
|
};
|
|
1073
|
+
//#endregion
|
|
1074
|
+
//#region src/auth/password/describe-hasher.ts
|
|
1075
|
+
/**
|
|
1076
|
+
* Matched by exact constructor, so a subclass (which may override `hash()`) or an
|
|
1077
|
+
* app's own `PasswordHasher` reads as unknown rather than as the class it extends.
|
|
1078
|
+
*/
|
|
1079
|
+
function describePasswordHasher(hasher) {
|
|
1080
|
+
switch (hasher.constructor) {
|
|
1081
|
+
case DefaultHasher: return {
|
|
1082
|
+
algorithm: hasher.algorithm,
|
|
1083
|
+
requiresBun: hasher.algorithm === "argon2"
|
|
1084
|
+
};
|
|
1085
|
+
case NodeHasher: return {
|
|
1086
|
+
algorithm: "scrypt",
|
|
1087
|
+
requiresBun: false
|
|
1088
|
+
};
|
|
1089
|
+
case ScryptHasher: return {
|
|
1090
|
+
algorithm: hasher.algorithm === "bcrypt" ? "bcrypt" : "argon2",
|
|
1091
|
+
requiresBun: true
|
|
1092
|
+
};
|
|
1093
|
+
default: return {
|
|
1094
|
+
algorithm: null,
|
|
1095
|
+
requiresBun: null
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1072
1099
|
const DEFAULT_PROVIDER = "users";
|
|
1073
1100
|
/**
|
|
1074
1101
|
* The guard name an unqualified lookup resolves to on a request the pipeline
|
|
@@ -1103,7 +1130,13 @@ var AuthManager = class {
|
|
|
1103
1130
|
this.guards.set(name, { factory });
|
|
1104
1131
|
}
|
|
1105
1132
|
registerProvider(name, factory) {
|
|
1106
|
-
this.
|
|
1133
|
+
this.setProvider(name, factory);
|
|
1134
|
+
}
|
|
1135
|
+
setProvider(name, factory, description) {
|
|
1136
|
+
this.providers.set(name, {
|
|
1137
|
+
factory,
|
|
1138
|
+
...description ? { description } : {}
|
|
1139
|
+
});
|
|
1107
1140
|
}
|
|
1108
1141
|
/** The guard `useTokens()` registered, or null. On this class rather than the contract, like `getApiTokenOptions()`. */
|
|
1109
1142
|
getTokenGuard() {
|
|
@@ -1217,7 +1250,12 @@ var AuthManager = class {
|
|
|
1217
1250
|
hasher
|
|
1218
1251
|
};
|
|
1219
1252
|
bindPasswordHasher(model, hasher);
|
|
1220
|
-
this.
|
|
1253
|
+
this.setProvider(providerName, () => new ModelUserProvider(model, defaultOptions), {
|
|
1254
|
+
kind: "model",
|
|
1255
|
+
model: model.name,
|
|
1256
|
+
hasher: hasher.constructor.name,
|
|
1257
|
+
...describePasswordHasher(hasher)
|
|
1258
|
+
});
|
|
1221
1259
|
this.registerGuard(guardName, ({ session, manager }) => {
|
|
1222
1260
|
return new SessionGuard({
|
|
1223
1261
|
provider: manager.getProvider(providerName),
|
|
@@ -1268,6 +1306,23 @@ var AuthManager = class {
|
|
|
1268
1306
|
getApiTokenStore() {
|
|
1269
1307
|
return this.apiTokenStore ?? void 0;
|
|
1270
1308
|
}
|
|
1309
|
+
/** Guards and providers as registered, constructing no provider (RFC 0026 §1). */
|
|
1310
|
+
describe() {
|
|
1311
|
+
const providers = {};
|
|
1312
|
+
for (const [name, entry] of this.providers) providers[name] = entry.description ? { ...entry.description } : {
|
|
1313
|
+
kind: "custom",
|
|
1314
|
+
hasher: null,
|
|
1315
|
+
algorithm: null,
|
|
1316
|
+
requiresBun: null
|
|
1317
|
+
};
|
|
1318
|
+
return {
|
|
1319
|
+
guards: this.guardNames(),
|
|
1320
|
+
defaultGuard: this.defaultGuard,
|
|
1321
|
+
hasher: this.passwordHasher.constructor.name,
|
|
1322
|
+
...describePasswordHasher(this.passwordHasher),
|
|
1323
|
+
providers
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1271
1326
|
};
|
|
1272
1327
|
//#endregion
|
|
1273
1328
|
//#region src/support/redirect-target.ts
|
|
@@ -1297,6 +1352,17 @@ function hostMatchesAllowlist(target, allowedHosts) {
|
|
|
1297
1352
|
return false;
|
|
1298
1353
|
}
|
|
1299
1354
|
//#endregion
|
|
1355
|
+
//#region src/http/middleware/index.ts
|
|
1356
|
+
function defineMiddleware(handler) {
|
|
1357
|
+
return handler;
|
|
1358
|
+
}
|
|
1359
|
+
function jsonResponse(data, status = 200) {
|
|
1360
|
+
return new Response(JSON.stringify(data), {
|
|
1361
|
+
status,
|
|
1362
|
+
headers: { "Content-Type": "application/json; charset=utf-8" }
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
//#endregion
|
|
1300
1366
|
//#region src/auth/oauth/index.ts
|
|
1301
1367
|
/** Session key holding the per-browser bindings between authorize and callback. */
|
|
1302
1368
|
const OAUTH_SESSION_BINDING_KEY = "guren:oauth.bindings";
|
|
@@ -1806,6 +1872,20 @@ var MemoryPasswordResetStore = class {
|
|
|
1806
1872
|
expiresAt
|
|
1807
1873
|
});
|
|
1808
1874
|
}
|
|
1875
|
+
async replace(tokenId, email, expiresAt) {
|
|
1876
|
+
const normalizedEmail = email.toLowerCase();
|
|
1877
|
+
for (const [id, record] of this.tokens) if (record.email.toLowerCase() === normalizedEmail) this.tokens.delete(id);
|
|
1878
|
+
this.tokens.set(tokenId, {
|
|
1879
|
+
email: normalizedEmail,
|
|
1880
|
+
expiresAt
|
|
1881
|
+
});
|
|
1882
|
+
}
|
|
1883
|
+
async consume(tokenId, email) {
|
|
1884
|
+
const record = this.tokens.get(tokenId);
|
|
1885
|
+
if (!record || record.email !== email) return false;
|
|
1886
|
+
this.tokens.delete(tokenId);
|
|
1887
|
+
return true;
|
|
1888
|
+
}
|
|
1809
1889
|
async find(tokenId) {
|
|
1810
1890
|
const record = this.tokens.get(tokenId);
|
|
1811
1891
|
if (!record) return null;
|
|
@@ -1819,7 +1899,7 @@ var MemoryPasswordResetStore = class {
|
|
|
1819
1899
|
this.tokens.delete(tokenId);
|
|
1820
1900
|
}
|
|
1821
1901
|
async deleteForEmail(email) {
|
|
1822
|
-
for (const [hash, record] of this.tokens) if (record.email === email) this.tokens.delete(hash);
|
|
1902
|
+
for (const [hash, record] of this.tokens) if (record.email.toLowerCase() === email.toLowerCase()) this.tokens.delete(hash);
|
|
1823
1903
|
}
|
|
1824
1904
|
/** Clear all tokens (useful for testing) */
|
|
1825
1905
|
clear() {
|
|
@@ -1836,7 +1916,7 @@ function createPasswordResetSigner() {
|
|
|
1836
1916
|
async function createPasswordResetToken(email, store, config = {}) {
|
|
1837
1917
|
const expiresIn = config.expiresIn ?? DEFAULT_EXPIRES_IN;
|
|
1838
1918
|
const tokenLength = config.tokenLength ?? DEFAULT_TOKEN_LENGTH;
|
|
1839
|
-
|
|
1919
|
+
if (!store.replace) throw new Error("Password reset token issuance requires an atomic store.replace() implementation.");
|
|
1840
1920
|
const tokenId = generateId();
|
|
1841
1921
|
const expiresAt = new Date(Date.now() + expiresIn);
|
|
1842
1922
|
const token = createPasswordResetSigner().sign({
|
|
@@ -1847,7 +1927,7 @@ async function createPasswordResetToken(email, store, config = {}) {
|
|
|
1847
1927
|
purpose: PASSWORD_RESET_PURPOSE,
|
|
1848
1928
|
expiresIn
|
|
1849
1929
|
});
|
|
1850
|
-
await store.
|
|
1930
|
+
await store.replace(tokenId, email.toLowerCase(), expiresAt);
|
|
1851
1931
|
return {
|
|
1852
1932
|
token,
|
|
1853
1933
|
tokenId,
|
|
@@ -1877,8 +1957,9 @@ async function completePasswordReset(token, newPassword, store, provider, update
|
|
|
1877
1957
|
await store.delete(claims.id);
|
|
1878
1958
|
return null;
|
|
1879
1959
|
}
|
|
1960
|
+
if (!store.consume) throw new Error("Password reset completion requires an atomic store.consume() implementation.");
|
|
1961
|
+
if (!await store.consume(claims.id, record.email)) return null;
|
|
1880
1962
|
await updatePassword(user, newPassword);
|
|
1881
|
-
await store.delete(claims.id);
|
|
1882
1963
|
return user;
|
|
1883
1964
|
}
|
|
1884
1965
|
/** Build a password reset URL from a base URL and token. */
|
|
@@ -1893,6 +1974,20 @@ var MemoryEmailVerificationStore = class {
|
|
|
1893
1974
|
async store(token) {
|
|
1894
1975
|
this.tokens.set(token.tokenId, token);
|
|
1895
1976
|
}
|
|
1977
|
+
async replace(token) {
|
|
1978
|
+
const email = token.email.toLowerCase();
|
|
1979
|
+
for (const [id, record] of this.tokens) if (record.email.toLowerCase() === email) this.tokens.delete(id);
|
|
1980
|
+
this.tokens.set(token.tokenId, {
|
|
1981
|
+
...token,
|
|
1982
|
+
email
|
|
1983
|
+
});
|
|
1984
|
+
}
|
|
1985
|
+
async consume(tokenId, email) {
|
|
1986
|
+
const record = this.tokens.get(tokenId);
|
|
1987
|
+
if (!record || record.email !== email) return false;
|
|
1988
|
+
this.tokens.delete(tokenId);
|
|
1989
|
+
return true;
|
|
1990
|
+
}
|
|
1896
1991
|
async findByTokenId(tokenId) {
|
|
1897
1992
|
return this.tokens.get(tokenId) ?? null;
|
|
1898
1993
|
}
|
|
@@ -1929,7 +2024,7 @@ async function createEmailVerificationToken(email, store, config = {}) {
|
|
|
1929
2024
|
...DEFAULT_CONFIG,
|
|
1930
2025
|
...config
|
|
1931
2026
|
};
|
|
1932
|
-
|
|
2027
|
+
if (!store.replace) throw new Error("Email verification token issuance requires an atomic store.replace() implementation.");
|
|
1933
2028
|
const tokenId = generateId();
|
|
1934
2029
|
const now = /* @__PURE__ */ new Date();
|
|
1935
2030
|
const expiresAt = new Date(now.getTime() + expiresIn);
|
|
@@ -1941,7 +2036,7 @@ async function createEmailVerificationToken(email, store, config = {}) {
|
|
|
1941
2036
|
purpose: EMAIL_VERIFICATION_PURPOSE,
|
|
1942
2037
|
expiresIn
|
|
1943
2038
|
});
|
|
1944
|
-
await store.
|
|
2039
|
+
await store.replace({
|
|
1945
2040
|
email: email.toLowerCase(),
|
|
1946
2041
|
tokenId,
|
|
1947
2042
|
expiresAt,
|
|
@@ -1973,9 +2068,9 @@ async function completeEmailVerification(token, store, markVerified) {
|
|
|
1973
2068
|
const storedToken = await store.findByTokenId(claims.id);
|
|
1974
2069
|
if (!storedToken) return null;
|
|
1975
2070
|
if (storedToken.email.toLowerCase() !== claims.email.toLowerCase()) return null;
|
|
1976
|
-
|
|
1977
|
-
await store.
|
|
1978
|
-
return
|
|
2071
|
+
if (!store.consume) throw new Error("Email verification completion requires an atomic store.consume() implementation.");
|
|
2072
|
+
if (!await store.consume(claims.id, storedToken.email)) return null;
|
|
2073
|
+
return markVerified(storedToken.email);
|
|
1979
2074
|
}
|
|
1980
2075
|
/** Build a verification URL. */
|
|
1981
2076
|
const buildVerificationUrl = buildTokenUrl;
|
|
@@ -1997,9 +2092,9 @@ function requireVerifiedEmail(options = {}) {
|
|
|
1997
2092
|
return async (ctx, next) => {
|
|
1998
2093
|
if (!isEmailVerified(await (options.getUser ?? (async (c) => {
|
|
1999
2094
|
return await getAuthContext(c)?.user() ?? null;
|
|
2000
|
-
}))(ctx))) return ctx.redirect(redirectTo);
|
|
2095
|
+
}))(ctx))) return isAgentToolRequest(ctx) ? jsonResponse({ message: "Email address is not verified" }, 403) : ctx.redirect(redirectTo);
|
|
2001
2096
|
await next();
|
|
2002
2097
|
};
|
|
2003
2098
|
}
|
|
2004
2099
|
//#endregion
|
|
2005
|
-
export { verifyOAuthState as A,
|
|
2100
|
+
export { verifyOAuthState as A, ModelUserProvider as B, createGoogleOAuthProviderConfig as C, fetchOAuthUserProfile as D, exchangeOAuthCode as E, normalizeRedirectTarget as F, installAgentPrincipal as G, NodeHasher as H, AuthManager as I, createSessionMiddleware as J, readAgentPrincipal as K, DEFAULT_PROVIDER as L, jsonResponse as M, hostMatchesAllowlist as N, parseOAuthRedirectUrl as O, isAppRelativePath as P, TokenGuard as R, createGitHubOAuthProviderConfig as S, createOAuthState as T, ScryptHasher as U, DefaultHasher as V, BaseUserProvider as W, getSessionFromContext as X, defaultCookieSecure as Y, OAUTH_SESSION_BINDING_KEY as _, isEmailVerified as a, buildOAuthRedirectUrl as b, verifyEmailToken as c, completePasswordReset as d, createPasswordResetToken as f, MemoryOAuthStateStore as g, AuthenticatableModel as h, createEmailVerificationToken as i, defineMiddleware as j, sanitizeOAuthRedirect as k, MemoryPasswordResetStore as l, verifyPasswordResetToken as m, buildVerificationUrl as n, parseVerificationUrl as o, parsePasswordResetUrl as p, MemorySessionStore as q, completeEmailVerification as r, requireVerifiedEmail as s, MemoryEmailVerificationStore as t, buildPasswordResetUrl as u, OAuthManager as v, createOAuthManager as w, createDiscordOAuthProviderConfig as x, buildOAuthAuthorizeUrl as y, SessionGuard as z };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as withAuthorization, n as authorizeMiddleware, o as Policy, r as authorizeResourceMiddleware, s as definePolicy, t as authorizeAllMiddleware } from "../authorization-
|
|
2
|
-
import { a as cannot, f as setGate, i as can, l as getGate, n as Response, o as createGate, r as authorize, s as defineGate, t as Gate, u as isAuthorizationResponse } from "../Gate-
|
|
1
|
+
import { a as withAuthorization, n as authorizeMiddleware, o as Policy, r as authorizeResourceMiddleware, s as definePolicy, t as authorizeAllMiddleware } from "../authorization-Daa6CxCg.js";
|
|
2
|
+
import { a as cannot, f as setGate, i as can, l as getGate, n as Response, o as createGate, r as authorize, s as defineGate, t as Gate, u as isAuthorizationResponse } from "../Gate-BL_zW82W.js";
|
|
3
3
|
export { Gate, Policy, Response, authorize, authorizeAllMiddleware, authorizeMiddleware, authorizeResourceMiddleware, can, cannot, createGate, defineGate, definePolicy, getGate, isAuthorizationResponse, setGate, withAuthorization };
|
|
@@ -2,6 +2,7 @@ import type { Context } from '../http/Application.js';
|
|
|
2
2
|
import type { Middleware } from '../http/middleware/index.js';
|
|
3
3
|
import type { AuthorizeOptions, AuthorizeResourceOptions } from './types.js';
|
|
4
4
|
import { Gate } from './Gate.js';
|
|
5
|
+
import { type MiddlewareCapabilities } from '../http/middleware/capabilities.js';
|
|
5
6
|
/**
|
|
6
7
|
* Middleware to authorize an ability. An array argument is snapshotted at
|
|
7
8
|
* creation, and a one-element array behaves exactly like the bare ability.
|
|
@@ -24,6 +25,13 @@ export declare function authorizeAllMiddleware(input: string[], modelResolver?:
|
|
|
24
25
|
* contract (RFC 0007): not re-exported from the package root.
|
|
25
26
|
*/
|
|
26
27
|
export declare function resourceAbilityForMethod(method: string): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* The ability an authorization stamp checks when it says so unambiguously,
|
|
30
|
+
* else undefined, meaning undetermined. A resource check resolves through the
|
|
31
|
+
* verb map, so only with the route's method. The one rule for agent tools and
|
|
32
|
+
* the introspection manifest (RFC 0016 §4, RFC 0026 §3). Internal contract (RFC 0007).
|
|
33
|
+
*/
|
|
34
|
+
export declare function derivableAbility(authorization: MiddlewareCapabilities['authorization'], method?: string): string | undefined;
|
|
27
35
|
/**
|
|
28
36
|
* Maps HTTP methods to policy abilities. A method outside the built-in mapping
|
|
29
37
|
* (a custom verb via `router.on()`) is denied with a 403 rather than downgraded
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as denialToException, d as resolveGate, g as tryGetRequestContainer, n as Response, p as AuthorizationException } from "./Gate-
|
|
1
|
+
import { c as denialToException, d as resolveGate, g as tryGetRequestContainer, n as Response, p as AuthorizationException } from "./Gate-BL_zW82W.js";
|
|
2
2
|
//#region src/http/middleware/capabilities.ts
|
|
3
3
|
/**
|
|
4
4
|
* Internal security-capability marker (RFC 0007): built-in middleware
|
|
@@ -168,6 +168,21 @@ function resourceAbilityForMethod(method) {
|
|
|
168
168
|
return RESOURCE_ABILITY_BY_METHOD[method.toUpperCase()];
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
171
|
+
* The ability an authorization stamp checks when it says so unambiguously,
|
|
172
|
+
* else undefined, meaning undetermined. A resource check resolves through the
|
|
173
|
+
* verb map, so only with the route's method. The one rule for agent tools and
|
|
174
|
+
* the introspection manifest (RFC 0016 §4, RFC 0026 §3). Internal contract (RFC 0007).
|
|
175
|
+
*/
|
|
176
|
+
function derivableAbility(authorization, method) {
|
|
177
|
+
if (!authorization) return void 0;
|
|
178
|
+
if (authorization.resource) {
|
|
179
|
+
if (!authorization.resource.fromMethodMap || method === void 0) return void 0;
|
|
180
|
+
if (authorization.abilities.length > 0 || authorization.mode !== "all") return void 0;
|
|
181
|
+
return resourceAbilityForMethod(method);
|
|
182
|
+
}
|
|
183
|
+
return authorization.abilities.length === 1 && authorization.mode === "all" ? authorization.abilities[0] : void 0;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
171
186
|
* Maps HTTP methods to policy abilities. A method outside the built-in mapping
|
|
172
187
|
* (a custom verb via `router.on()`) is denied with a 403 rather than downgraded
|
|
173
188
|
* to `view`: guessing would let a view-only user reach a mutating handler. Map
|
|
@@ -214,4 +229,4 @@ function withAuthorization(gate) {
|
|
|
214
229
|
};
|
|
215
230
|
}
|
|
216
231
|
//#endregion
|
|
217
|
-
export { withAuthorization as a, capabilitiesOf as c,
|
|
232
|
+
export { withAuthorization as a, capabilitiesOf as c, derivableAbility as i, mergeCapabilities as l, authorizeMiddleware as n, Policy as o, authorizeResourceMiddleware as r, definePolicy as s, authorizeAllMiddleware as t, stampCapabilities as u };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BroadcastDriver, BroadcastDriverFactory, BroadcastManagerOptions, ChannelAuthorizer, PresenceChannelAuthorizer, ChannelRegistration, SSEMiddlewareOptions, AuthMiddlewareOptions, SSEClient, WebSocketClient, BroadcastEvent } from './types.js';
|
|
1
|
+
import type { BroadcastDriver, BroadcastDriverFactory, BroadcastManagerOptions, ChannelAuthorizer, PresenceChannelAuthorizer, ChannelRegistration, SSEMiddlewareOptions, WebSocketMiddlewareOptions, AuthMiddlewareOptions, SSEClient, WebSocketClient, BroadcastEvent } from './types.js';
|
|
2
2
|
import { Channel, PrivateChannel, PresenceChannel } from './channels/index.js';
|
|
3
3
|
import type { Middleware } from '../http/middleware/index.js';
|
|
4
4
|
/** Broadcast manager for real-time event broadcasting. */
|
|
@@ -30,9 +30,21 @@ export declare class BroadcastManager {
|
|
|
30
30
|
id: string | number;
|
|
31
31
|
info?: Record<string, unknown>;
|
|
32
32
|
} | null>;
|
|
33
|
+
private filterAuthorizedChannels;
|
|
33
34
|
protected findChannelRegistration(channelName: string): ChannelRegistration | undefined;
|
|
34
35
|
protected matchPattern(pattern: string, channelName: string): boolean;
|
|
35
36
|
sseMiddleware(options?: SSEMiddlewareOptions): Middleware;
|
|
37
|
+
/**
|
|
38
|
+
* A route that upgrades to a WebSocket carrying broadcast events, the socket
|
|
39
|
+
* counterpart of `sseMiddleware()`; it needs `Application.listen()` on Bun.
|
|
40
|
+
* Frames are JSON. The server sends `{ event, data }`, first `connected` with
|
|
41
|
+
* `{ clientId, channels }`; the client sends `{ action: 'subscribe' | 'unsubscribe',
|
|
42
|
+
* channel }`, answered by a `subscription` event, and anything else is ignored.
|
|
43
|
+
*/
|
|
44
|
+
webSocketMiddleware(options?: WebSocketMiddlewareOptions): Middleware;
|
|
45
|
+
private handleWebSocketMessage;
|
|
46
|
+
/** The one answer `POST /broadcasting/auth` and a socket's `subscribe` both give. */
|
|
47
|
+
private authorizeAndAttach;
|
|
36
48
|
authMiddleware(options?: AuthMiddlewareOptions): Middleware;
|
|
37
49
|
subscribeClient(clientId: string, channel: string): boolean;
|
|
38
50
|
/**
|
|
@@ -56,6 +68,11 @@ export declare class BroadcastManager {
|
|
|
56
68
|
userId?: string | number;
|
|
57
69
|
}): string;
|
|
58
70
|
removeWebSocketClient(clientId: string): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Subscribes without authorizing, like `subscribeClient()`: for a channel the
|
|
73
|
+
* server chose. Put a channel the client named through `authorize()` first,
|
|
74
|
+
* as `webSocketMiddleware()` and `authMiddleware()` do.
|
|
75
|
+
*/
|
|
59
76
|
subscribeWebSocketClient(clientId: string, channel: string): boolean;
|
|
60
77
|
unsubscribeWebSocketClient(clientId: string, channel: string): boolean;
|
|
61
78
|
getWebSocketClient(clientId: string): WebSocketClient | undefined;
|
|
@@ -65,11 +82,11 @@ export declare class BroadcastManager {
|
|
|
65
82
|
getClients(): SSEClient[];
|
|
66
83
|
getChannelClients(channel: string): SSEClient[];
|
|
67
84
|
/**
|
|
68
|
-
* Close every SSE connection this manager holds. Each
|
|
69
|
-
* is only cleared on stream cancel or request abort, and
|
|
70
|
-
* waits for in-flight requests while an SSE response never
|
|
71
|
-
* hot reload the timers would go on pinging.
|
|
72
|
-
* `close()` reaching another client would drop it
|
|
85
|
+
* Close every SSE and WebSocket connection this manager holds. Each SSE stream
|
|
86
|
+
* owns a ping timer that is only cleared on stream cancel or request abort, and
|
|
87
|
+
* `Bun.serve().stop()` waits for in-flight requests while an SSE response never
|
|
88
|
+
* finishes — so on a hot reload the timers would go on pinging. Both lists are
|
|
89
|
+
* snapshots: a `close()` reaching another client would drop it mid-iteration.
|
|
73
90
|
*/
|
|
74
91
|
disconnectAll(): void;
|
|
75
92
|
protected generateClientId(prefix?: 'sse' | 'ws'): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { BroadcastEvent, BroadcastDriver, PresenceBroadcastDriver, ChannelAuthorizer, PresenceChannelAuthorizer, PresenceMember, SSEClient, WebSocketClient, BroadcastManagerOptions, BroadcastDriverFactory, ChannelRegistration, SSEMiddlewareOptions, AuthMiddlewareOptions, BroadcastableEvent, } from './types.js';
|
|
1
|
+
export type { BroadcastEvent, BroadcastDriver, PresenceBroadcastDriver, ChannelAuthorizer, PresenceChannelAuthorizer, PresenceMember, SSEClient, WebSocketClient, BroadcastManagerOptions, BroadcastDriverFactory, ChannelRegistration, SSEMiddlewareOptions, WebSocketMiddlewareOptions, AuthMiddlewareOptions, BroadcastableEvent, } from './types.js';
|
|
2
2
|
export { BroadcastManager, setBroadcastManager, getBroadcastManager, createBroadcastManager, } from './BroadcastManager.js';
|
|
3
3
|
export { createTypedBroadcaster, } from './typed.js';
|
|
4
4
|
export type { TypedBroadcaster, TypedChannelHandle, TypedPrivateChannelHandle, TypedPresenceChannelHandle, } from './typed.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as setBroadcastManager, c as PresenceChannel, i as getBroadcastManager, l as PrivateChannel, n as BroadcastManager, o as RedisDriver, r as createBroadcastManager, s as MemoryDriver, t as createTypedBroadcaster, u as Channel } from "../broadcasting-
|
|
1
|
+
import { a as setBroadcastManager, c as PresenceChannel, i as getBroadcastManager, l as PrivateChannel, n as BroadcastManager, o as RedisDriver, r as createBroadcastManager, s as MemoryDriver, t as createTypedBroadcaster, u as Channel } from "../broadcasting-N4cRV42s.js";
|
|
2
2
|
export { BroadcastManager, Channel, MemoryDriver, PresenceChannel, PrivateChannel, RedisDriver, createBroadcastManager, createTypedBroadcaster, getBroadcastManager, setBroadcastManager };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WebSocketOriginOptions } from '../http/middleware/websocket-origin.js';
|
|
1
2
|
export interface BroadcastEvent {
|
|
2
3
|
channel: string;
|
|
3
4
|
event: string;
|
|
@@ -59,11 +60,22 @@ export interface SSEMiddlewareOptions {
|
|
|
59
60
|
retry?: number;
|
|
60
61
|
/**
|
|
61
62
|
* Resolves the user from the request context, which authorizes channels
|
|
62
|
-
* requested via the `?channels=` query parameter.
|
|
63
|
+
* requested via the `?channels=` query parameter. Defaults to the session
|
|
64
|
+
* user, from the auth context under `AUTH_CONTEXT_KEY`.
|
|
65
|
+
*/
|
|
66
|
+
getUser?: (ctx: unknown) => unknown | Promise<unknown>;
|
|
67
|
+
}
|
|
68
|
+
/** `allowedOrigins` is the `createWebSocketOriginGuard()` option; any other browser `Origin` gets 403. */
|
|
69
|
+
export interface WebSocketMiddlewareOptions extends WebSocketOriginOptions {
|
|
70
|
+
/**
|
|
71
|
+
* Resolves the user from the upgrade request. That one user authorizes the
|
|
72
|
+
* `?channels=` query and every `subscribe` message for the socket's lifetime.
|
|
73
|
+
* Defaults to the session user from the auth context.
|
|
63
74
|
*/
|
|
64
75
|
getUser?: (ctx: unknown) => unknown | Promise<unknown>;
|
|
65
76
|
}
|
|
66
77
|
export interface AuthMiddlewareOptions {
|
|
78
|
+
/** Resolves the requesting user. Defaults to the session user from the auth context. */
|
|
67
79
|
getUser?: (ctx: unknown) => unknown | Promise<unknown>;
|
|
68
80
|
}
|
|
69
81
|
/** Implemented by Event classes that broadcast. */
|