@guren/server 2.1.0 → 2.2.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/{McpServiceProvider-7BB5FPF3.js → McpServiceProvider-GRDYNEQG.js} +1 -1
- package/dist/auth/AuthManager.d.ts +30 -0
- package/dist/auth/AuthenticatableModel.d.ts +25 -0
- package/dist/auth/RequestAuthContext.d.ts +24 -0
- package/dist/auth/SessionGuard.d.ts +31 -0
- package/dist/auth/api-token.d.ts +299 -0
- package/dist/auth/email-verification.d.ts +203 -0
- package/dist/auth/index.d.ts +18 -110
- package/dist/auth/index.js +3 -1
- package/dist/auth/oauth/index.d.ts +239 -0
- package/dist/auth/password/DefaultHasher.d.ts +13 -0
- package/dist/auth/password/NodeHasher.d.ts +22 -0
- package/dist/auth/password/PasswordHasher.d.ts +5 -0
- package/dist/auth/password/ScryptHasher.d.ts +26 -0
- package/dist/auth/password-reset.d.ts +91 -0
- package/dist/auth/providers/ModelUserProvider.d.ts +36 -0
- package/dist/auth/providers/UserProvider.d.ts +9 -0
- package/dist/auth/types.d.ts +102 -0
- package/dist/auth/utils.d.ts +39 -0
- package/dist/{Gate-CynjZCtS.d.ts → authorization/Gate.d.ts} +30 -111
- package/dist/authorization/Policy.d.ts +77 -0
- package/dist/authorization/index.d.ts +5 -129
- package/dist/authorization/index.js +3 -1
- package/dist/authorization/middleware.d.ts +49 -0
- package/dist/authorization/types.d.ts +108 -0
- package/dist/broadcasting/BroadcastManager.d.ts +205 -0
- package/dist/broadcasting/channels/Channel.d.ts +28 -0
- package/dist/broadcasting/channels/PresenceChannel.d.ts +72 -0
- package/dist/broadcasting/channels/PrivateChannel.d.ts +32 -0
- package/dist/broadcasting/channels/index.d.ts +3 -0
- package/dist/broadcasting/drivers/MemoryDriver.d.ts +93 -0
- package/dist/broadcasting/drivers/RedisDriver.d.ts +112 -0
- package/dist/broadcasting/drivers/index.d.ts +2 -0
- package/dist/broadcasting/index.d.ts +6 -233
- package/dist/broadcasting/index.js +1 -1
- package/dist/broadcasting/typed.d.ts +23 -0
- package/dist/broadcasting/types.d.ts +155 -0
- package/dist/cache/CacheManager.d.ts +87 -0
- package/dist/cache/TaggedCache.d.ts +62 -0
- package/dist/cache/index.d.ts +6 -233
- package/dist/cache/index.js +1 -1
- package/dist/cache/stores/FileStore.d.ts +64 -0
- package/dist/cache/stores/MemoryStore.d.ts +52 -0
- package/dist/cache/stores/RedisStore.d.ts +53 -0
- package/dist/{CacheManager-BmDzUKrF.d.ts → cache/types.d.ts} +26 -99
- package/dist/{chunk-TVY72CLV.js → chunk-4VE3LYOM.js} +3 -2
- package/dist/{chunk-FZD2AKJI.js → chunk-7OB2YXRE.js} +56 -28
- package/dist/{chunk-HONCNQXZ.js → chunk-BUQXOZCT.js} +97 -10
- package/dist/{chunk-DSDX3ASM.js → chunk-CDZUNKI6.js} +65 -83
- package/dist/{chunk-CWI4AJ47.js → chunk-HPET6XY5.js} +13 -9
- package/dist/{chunk-A3ISJVEV.js → chunk-HR2KZ3WL.js} +23 -5
- package/dist/{chunk-EARA7JM4.js → chunk-PZKUDFMW.js} +11 -8
- package/dist/console/Command.d.ts +179 -0
- package/dist/{ConsoleKernel-CJg975mp.d.ts → console/ConsoleKernel.d.ts} +4 -6
- package/dist/console/Input.d.ts +140 -0
- package/dist/console/Output.d.ts +161 -0
- package/dist/console/index.d.ts +5 -0
- package/dist/console/types.d.ts +106 -0
- package/dist/container/Container.d.ts +148 -0
- package/dist/container/ServiceProvider.d.ts +103 -0
- package/dist/container/bindings.d.ts +55 -0
- package/dist/container/defineModule.d.ts +88 -0
- package/dist/container/definePlugin.d.ts +62 -0
- package/dist/container/index.d.ts +8 -0
- package/dist/container/types.d.ts +73 -0
- package/dist/database/Factory.d.ts +82 -0
- package/dist/database/Seeder.d.ts +35 -0
- package/dist/database/SeederRunner.d.ts +41 -0
- package/dist/database/index.d.ts +4 -0
- package/dist/database/types.d.ts +49 -0
- package/dist/discovery/AutoDiscovery.d.ts +113 -0
- package/dist/discovery/index.d.ts +2 -0
- package/dist/docs-viewer/DocsViewerServiceProvider.d.ts +12 -0
- package/dist/docs-viewer/endpoint.d.ts +19 -0
- package/dist/encryption/Encrypter.d.ts +96 -0
- package/dist/encryption/Hash.d.ts +69 -0
- package/dist/encryption/MessageSigner.d.ts +21 -0
- package/dist/encryption/Random.d.ts +119 -0
- package/dist/encryption/app-key.d.ts +12 -0
- package/dist/encryption/index.d.ts +10 -222
- package/dist/encryption/signed-url.d.ts +9 -0
- package/dist/encryption/types.d.ts +103 -0
- package/dist/errors/ExceptionHandler.d.ts +118 -0
- package/dist/errors/HttpException.d.ts +106 -0
- package/dist/errors/debug-page.d.ts +22 -0
- package/dist/errors/error-page.d.ts +1 -0
- package/dist/errors/exceptions/AuthenticationException.d.ts +32 -0
- package/dist/errors/exceptions/AuthorizationException.d.ts +32 -0
- package/dist/errors/exceptions/MethodNotAllowedException.d.ts +31 -0
- package/dist/errors/exceptions/NotFoundHttpException.d.ts +36 -0
- package/dist/errors/exceptions/ValidationException.d.ts +60 -0
- package/dist/errors/exceptions/index.d.ts +5 -0
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/types.d.ts +43 -0
- package/dist/events/Event.d.ts +33 -0
- package/dist/{EventManager-CmIoLt7r.d.ts → events/EventManager.d.ts} +4 -86
- package/dist/events/Listener.d.ts +79 -0
- package/dist/events/builtin.d.ts +73 -0
- package/dist/events/index.d.ts +6 -155
- package/dist/events/types.d.ts +48 -0
- package/dist/facades/index.d.ts +31 -0
- package/dist/health/HealthCheck.d.ts +34 -0
- package/dist/health/HealthManager.d.ts +53 -0
- package/dist/health/checks/CacheCheck.d.ts +35 -0
- package/dist/health/checks/CustomCheck.d.ts +23 -0
- package/dist/health/checks/DatabaseCheck.d.ts +33 -0
- package/dist/health/checks/MemoryCheck.d.ts +32 -0
- package/dist/health/checks/RedisCheck.d.ts +27 -0
- package/dist/health/checks/StorageCheck.d.ts +35 -0
- package/dist/health/checks/index.d.ts +12 -0
- package/dist/health/index.d.ts +5 -185
- package/dist/health/types.d.ts +52 -0
- package/dist/hot-reload/hot-disposables.d.ts +96 -0
- package/dist/hot-reload/testing.d.ts +14 -0
- package/dist/http/Application.d.ts +187 -0
- package/dist/http/FormRequest.d.ts +73 -0
- package/dist/http/dev-assets.d.ts +51 -0
- package/dist/http/dev-banner.d.ts +7 -0
- package/dist/http/inertia-assets.d.ts +22 -0
- package/dist/http/middleware/auth.d.ts +13 -0
- package/dist/http/middleware/capabilities.d.ts +22 -0
- package/dist/http/middleware/cors.d.ts +40 -0
- package/dist/http/middleware/csp.d.ts +59 -0
- package/dist/http/middleware/csrf.d.ts +121 -0
- package/dist/http/middleware/detect-locale.d.ts +65 -0
- package/dist/http/middleware/force-https.d.ts +34 -0
- package/dist/http/middleware/host-authorization.d.ts +24 -0
- package/dist/http/middleware/index.d.ts +19 -0
- package/dist/http/middleware/loopback-guard.d.ts +38 -0
- package/dist/{rate-limit-D9J2b4S1.d.ts → http/middleware/rate-limit.d.ts} +22 -50
- package/dist/http/middleware/redirect-safety.d.ts +29 -0
- package/dist/http/middleware/request-id.d.ts +19 -0
- package/dist/http/middleware/request-logging.d.ts +16 -0
- package/dist/http/middleware/security-headers.d.ts +49 -0
- package/dist/http/middleware/session.d.ts +93 -0
- package/dist/http/middleware/validation.d.ts +94 -0
- package/dist/http/public-assets.d.ts +15 -0
- package/dist/http/request.d.ts +24 -0
- package/dist/http/resources/CursorPaginator.d.ts +106 -0
- package/dist/http/resources/Paginator.d.ts +130 -0
- package/dist/http/resources/Resource.d.ts +67 -0
- package/dist/http/resources/ResourceCollection.d.ts +60 -0
- package/dist/http/resources/index.d.ts +6 -0
- package/dist/http/resources/types.d.ts +91 -0
- package/dist/http/validation/Validator.d.ts +128 -0
- package/dist/http/validation/index.d.ts +3 -0
- package/dist/http/validation/rules.d.ts +196 -0
- package/dist/http/validation/types.d.ts +96 -0
- package/dist/http/vite-dev-server.d.ts +27 -0
- package/dist/i18n/I18nManager.d.ts +114 -0
- package/dist/i18n/Translator.d.ts +80 -0
- package/dist/i18n/index.d.ts +6 -101
- package/dist/i18n/index.js +5 -3
- package/dist/i18n/loaders/JsonLoader.d.ts +47 -0
- package/dist/i18n/loaders/MemoryLoader.d.ts +37 -0
- package/dist/i18n/pluralization.d.ts +19 -0
- package/dist/i18n/types.d.ts +106 -0
- package/dist/index.d.ts +69 -2605
- package/dist/index.js +332 -152
- package/dist/lambda/index.d.ts +17 -37
- package/dist/logging/LogManager.d.ts +83 -0
- package/dist/logging/Logger.d.ts +76 -0
- package/dist/logging/channels/ConsoleChannel.d.ts +11 -0
- package/dist/logging/channels/DailyFileChannel.d.ts +20 -0
- package/dist/logging/channels/FileChannel.d.ts +15 -0
- package/dist/logging/index.d.ts +8 -50
- package/dist/logging/types.d.ts +96 -0
- package/dist/mail/Mail.d.ts +138 -0
- package/dist/mail/MailManager.d.ts +79 -0
- package/dist/mail/address.d.ts +8 -0
- package/dist/mail/index.d.ts +7 -316
- package/dist/mail/transports/LogTransport.d.ts +19 -0
- package/dist/mail/transports/MemoryTransport.d.ts +84 -0
- package/dist/mail/transports/ResendTransport.d.ts +32 -0
- package/dist/mail/transports/SmtpTransport.d.ts +40 -0
- package/dist/{MailManager-DpMvYiP9.d.ts → mail/types.d.ts} +11 -92
- package/dist/mcp/McpServiceProvider.d.ts +17 -0
- package/dist/mcp/create-mcp-server.d.ts +144 -0
- package/dist/mcp/endpoint.d.ts +29 -0
- package/dist/mcp/index.d.ts +3 -185
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Controller.d.ts +326 -0
- package/dist/mvc/Router.d.ts +239 -0
- package/dist/mvc/ViewEngine.d.ts +11 -0
- package/dist/mvc/inertia/InertiaEngine.d.ts +114 -0
- package/dist/mvc/inertia/shared.d.ts +90 -0
- package/dist/mvc/mount-route.d.ts +10 -0
- package/dist/notifications/Notification.d.ts +99 -0
- package/dist/notifications/NotificationManager.d.ts +150 -0
- package/dist/notifications/channels/DatabaseChannel.d.ts +55 -0
- package/dist/notifications/channels/MailChannel.d.ts +45 -0
- package/dist/notifications/channels/MemoryChannel.d.ts +85 -0
- package/dist/notifications/channels/SlackChannel.d.ts +73 -0
- package/dist/notifications/channels/index.d.ts +4 -0
- package/dist/notifications/index.d.ts +6 -322
- package/dist/notifications/notifiable-type.d.ts +10 -0
- package/dist/notifications/registry.d.ts +39 -0
- package/dist/notifications/types.d.ts +162 -0
- package/dist/providers/AuthServiceProvider.d.ts +7 -0
- package/dist/providers/AuthorizationServiceProvider.d.ts +9 -0
- package/dist/providers/BroadcastServiceProvider.d.ts +7 -0
- package/dist/providers/CacheServiceProvider.d.ts +7 -0
- package/dist/providers/EncryptionServiceProvider.d.ts +7 -0
- package/dist/providers/ErrorServiceProvider.d.ts +9 -0
- package/dist/providers/EventServiceProvider.d.ts +7 -0
- package/dist/providers/HealthServiceProvider.d.ts +7 -0
- package/dist/providers/I18nServiceProvider.d.ts +27 -0
- package/dist/providers/InertiaServiceProvider.d.ts +20 -0
- package/dist/providers/LogServiceProvider.d.ts +7 -0
- package/dist/providers/MailServiceProvider.d.ts +7 -0
- package/dist/providers/NotificationServiceProvider.d.ts +8 -0
- package/dist/providers/OAuthServiceProvider.d.ts +7 -0
- package/dist/providers/QueueServiceProvider.d.ts +7 -0
- package/dist/providers/SchedulingServiceProvider.d.ts +7 -0
- package/dist/providers/StorageServiceProvider.d.ts +7 -0
- package/dist/providers/index.d.ts +17 -0
- package/dist/queue/FailedJobReporter.d.ts +40 -0
- package/dist/queue/Job.d.ts +140 -0
- package/dist/queue/QueueManager.d.ts +79 -0
- package/dist/queue/Worker.d.ts +99 -0
- package/dist/queue/drivers/MemoryDriver.d.ts +60 -0
- package/dist/queue/drivers/RedisDriver.d.ts +96 -0
- package/dist/queue/drivers/SqsDriver.d.ts +108 -0
- package/dist/queue/drivers/SyncDriver.d.ts +28 -0
- package/dist/queue/index.d.ts +9 -453
- package/dist/queue/types.d.ts +171 -0
- package/dist/redis/RedisApiTokenStore.d.ts +78 -0
- package/dist/redis/RedisEmailVerificationStore.d.ts +54 -0
- package/dist/redis/RedisOAuthStateStore.d.ts +26 -0
- package/dist/redis/RedisPasswordResetStore.d.ts +57 -0
- package/dist/redis/RedisRateLimitStore.d.ts +77 -0
- package/dist/redis/RedisSessionStore.d.ts +61 -0
- package/dist/redis/client.d.ts +41 -0
- package/dist/redis/index.d.ts +14 -356
- package/dist/redis/index.js +5 -2
- package/dist/redis/scan-keys.d.ts +6 -0
- package/dist/runtime/index.d.ts +8 -95
- package/dist/runtime/index.js +1 -1
- package/dist/scheduling/CronParser.d.ts +37 -0
- package/dist/scheduling/Schedule.d.ts +229 -0
- package/dist/scheduling/ScheduledTask.d.ts +47 -0
- package/dist/scheduling/Scheduler.d.ts +99 -0
- package/dist/scheduling/index.d.ts +5 -41
- package/dist/scheduling/types.d.ts +97 -0
- package/dist/storage/StorageManager.d.ts +65 -0
- package/dist/storage/drivers/LocalDriver.d.ts +55 -0
- package/dist/storage/drivers/MemoryDriver.d.ts +66 -0
- package/dist/storage/drivers/S3Driver.d.ts +72 -0
- package/dist/storage/index.d.ts +5 -197
- package/dist/{StorageManager-oZTHqaza.d.ts → storage/types.d.ts} +10 -77
- package/dist/support/error-polyfill.d.ts +9 -0
- package/dist/support/import-map.d.ts +13 -0
- package/dist/support/redirect-target.d.ts +11 -0
- package/dist/support/stack-frames.d.ts +56 -0
- package/dist/support/trim-slashes.d.ts +11 -0
- package/dist/vite/index.d.ts +2 -35
- package/dist/vite/index.js +0 -3
- package/dist/vite/plugin.d.ts +34 -0
- package/package.json +3 -3
- package/dist/AuthManager-DBP4KYsx.d.ts +0 -79
- package/dist/BroadcastManager-D8KoJxiV.d.ts +0 -492
- package/dist/HealthManager-DUyMIzsZ.d.ts +0 -141
- package/dist/I18nManager-BiSoczfV.d.ts +0 -275
- package/dist/LogManager-7mxnkaPM.d.ts +0 -256
- package/dist/Scheduler-pZiT8i57.d.ts +0 -471
- package/dist/api-token-D24VPr_E.d.ts +0 -663
- package/dist/app-key-CsBfRC_Q.d.ts +0 -214
- package/dist/email-verification-D60YF2ZO.d.ts +0 -329
- package/dist/index-9_Jzj5jo.d.ts +0 -7
- package/dist/validation-yAL53e1S.d.ts +0 -2610
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
logDevServerBanner,
|
|
3
3
|
parseImportMap,
|
|
4
4
|
startViteDevServer
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-PZKUDFMW.js";
|
|
6
6
|
import {
|
|
7
7
|
PendingSchedule,
|
|
8
8
|
Schedule,
|
|
@@ -42,8 +42,9 @@ import {
|
|
|
42
42
|
selectPluralForm,
|
|
43
43
|
setI18n,
|
|
44
44
|
t,
|
|
45
|
-
tc
|
|
46
|
-
|
|
45
|
+
tc,
|
|
46
|
+
tryGetI18n
|
|
47
|
+
} from "./chunk-HR2KZ3WL.js";
|
|
47
48
|
import {
|
|
48
49
|
ConsoleChannel,
|
|
49
50
|
DailyFileChannel,
|
|
@@ -134,6 +135,7 @@ import {
|
|
|
134
135
|
MemorySessionStore,
|
|
135
136
|
ModelUserProvider,
|
|
136
137
|
NodeHasher,
|
|
138
|
+
OAUTH_SESSION_BINDING_KEY,
|
|
137
139
|
OAuthManager,
|
|
138
140
|
ScryptHasher,
|
|
139
141
|
SessionGuard,
|
|
@@ -178,7 +180,7 @@ import {
|
|
|
178
180
|
verifyEmailToken,
|
|
179
181
|
verifyOAuthState,
|
|
180
182
|
verifyPasswordResetToken
|
|
181
|
-
} from "./chunk-
|
|
183
|
+
} from "./chunk-BUQXOZCT.js";
|
|
182
184
|
import {
|
|
183
185
|
Gate,
|
|
184
186
|
Policy,
|
|
@@ -195,7 +197,7 @@ import {
|
|
|
195
197
|
getGate,
|
|
196
198
|
setGate,
|
|
197
199
|
withAuthorization
|
|
198
|
-
} from "./chunk-
|
|
200
|
+
} from "./chunk-7OB2YXRE.js";
|
|
199
201
|
import {
|
|
200
202
|
AuthorizationException,
|
|
201
203
|
ExceptionHandler,
|
|
@@ -228,7 +230,7 @@ import {
|
|
|
228
230
|
getBroadcastManager,
|
|
229
231
|
parseRequestPayload,
|
|
230
232
|
setBroadcastManager
|
|
231
|
-
} from "./chunk-
|
|
233
|
+
} from "./chunk-4VE3LYOM.js";
|
|
232
234
|
import {
|
|
233
235
|
CacheManager,
|
|
234
236
|
FileStore,
|
|
@@ -236,7 +238,7 @@ import {
|
|
|
236
238
|
RedisStore,
|
|
237
239
|
TaggedCache,
|
|
238
240
|
createCacheManager
|
|
239
|
-
} from "./chunk-
|
|
241
|
+
} from "./chunk-HPET6XY5.js";
|
|
240
242
|
import {
|
|
241
243
|
claimHotDisposable,
|
|
242
244
|
isHotReloadRuntime,
|
|
@@ -904,11 +906,11 @@ async function resolveModelBindings(c, modelBindings, path) {
|
|
|
904
906
|
const params = c.req.param();
|
|
905
907
|
const pathParams = path?.match(/:([a-zA-Z0-9_-]+)/g)?.map((p) => p.slice(1)) ?? [];
|
|
906
908
|
for (const param of pathParams) {
|
|
907
|
-
const
|
|
908
|
-
if (!
|
|
909
|
+
const resolver = modelBindings.get(param);
|
|
910
|
+
if (!resolver) continue;
|
|
909
911
|
const value = params[param];
|
|
910
912
|
if (value !== void 0) {
|
|
911
|
-
const model = await
|
|
913
|
+
const model = await resolver(value);
|
|
912
914
|
resolved.push(model);
|
|
913
915
|
}
|
|
914
916
|
}
|
|
@@ -1032,7 +1034,10 @@ function randomNonce() {
|
|
|
1032
1034
|
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1033
1035
|
}
|
|
1034
1036
|
function bindableSessionId(session) {
|
|
1035
|
-
|
|
1037
|
+
if (!session) {
|
|
1038
|
+
return void 0;
|
|
1039
|
+
}
|
|
1040
|
+
return session.willPersist?.() ?? !session.isNew ? session.id : void 0;
|
|
1036
1041
|
}
|
|
1037
1042
|
function mintCsrfToken(sessionId) {
|
|
1038
1043
|
const signer = createCsrfSigner();
|
|
@@ -1042,7 +1047,10 @@ function verifiedClaims(token) {
|
|
|
1042
1047
|
return createCsrfSigner().verify(token, { purpose: CSRF_PURPOSE });
|
|
1043
1048
|
}
|
|
1044
1049
|
function claimsUsableFor(claims, boundId) {
|
|
1045
|
-
|
|
1050
|
+
if (claims.sid === void 0) {
|
|
1051
|
+
return boundId === void 0;
|
|
1052
|
+
}
|
|
1053
|
+
return boundId !== void 0 && secureCompare(claims.sid, boundId);
|
|
1046
1054
|
}
|
|
1047
1055
|
function matchesPattern(path, pattern) {
|
|
1048
1056
|
if (pattern.endsWith("/*")) {
|
|
@@ -1058,21 +1066,23 @@ function isMcpEndpointRequest(path) {
|
|
|
1058
1066
|
return path === MCP_ENDPOINT_PATH && isMcpEndpointEnabled();
|
|
1059
1067
|
}
|
|
1060
1068
|
function getCsrfToken(ctx) {
|
|
1061
|
-
const pending = ctx.get(CSRF_CONTEXT_KEY);
|
|
1062
|
-
if (pending) {
|
|
1063
|
-
return pending;
|
|
1064
|
-
}
|
|
1065
1069
|
const boundId = bindableSessionId(getSessionFromContext(ctx));
|
|
1070
|
+
const issued = ctx.get(CSRF_CONTEXT_KEY);
|
|
1071
|
+
if (issued && issued.boundId === boundId) {
|
|
1072
|
+
return issued.token;
|
|
1073
|
+
}
|
|
1074
|
+
return remember(ctx, reusableCookieToken(ctx, boundId) ?? mintCsrfToken(boundId), boundId);
|
|
1075
|
+
}
|
|
1076
|
+
function reusableCookieToken(ctx, boundId) {
|
|
1066
1077
|
const cookieToken = getCookie(ctx, XSRF_COOKIE_NAME);
|
|
1067
|
-
if (cookieToken) {
|
|
1068
|
-
|
|
1069
|
-
if (claims && claimsUsableFor(claims, boundId)) {
|
|
1070
|
-
ctx.set(CSRF_CONTEXT_KEY, cookieToken);
|
|
1071
|
-
return cookieToken;
|
|
1072
|
-
}
|
|
1078
|
+
if (!cookieToken) {
|
|
1079
|
+
return void 0;
|
|
1073
1080
|
}
|
|
1074
|
-
const
|
|
1075
|
-
|
|
1081
|
+
const claims = verifiedClaims(cookieToken);
|
|
1082
|
+
return claims && claimsUsableFor(claims, boundId) ? cookieToken : void 0;
|
|
1083
|
+
}
|
|
1084
|
+
function remember(ctx, token, boundId) {
|
|
1085
|
+
ctx.set(CSRF_CONTEXT_KEY, { token, boundId });
|
|
1076
1086
|
return token;
|
|
1077
1087
|
}
|
|
1078
1088
|
function csrfField(ctx) {
|
|
@@ -1084,17 +1094,13 @@ function verifyCsrfToken(ctx, token) {
|
|
|
1084
1094
|
return false;
|
|
1085
1095
|
}
|
|
1086
1096
|
const claims = verifiedClaims(token);
|
|
1087
|
-
if (claims) {
|
|
1097
|
+
if (claims && claimsUsableFor(claims, bindableSessionId(getSessionFromContext(ctx)))) {
|
|
1088
1098
|
if (claims.sid !== void 0) {
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
const cookieToken = getCookie(ctx, XSRF_COOKIE_NAME);
|
|
1095
|
-
if (cookieToken && secureCompare(token, cookieToken)) {
|
|
1096
|
-
return true;
|
|
1097
|
-
}
|
|
1099
|
+
return true;
|
|
1100
|
+
}
|
|
1101
|
+
const cookieToken = getCookie(ctx, XSRF_COOKIE_NAME);
|
|
1102
|
+
if (cookieToken && secureCompare(token, cookieToken)) {
|
|
1103
|
+
return true;
|
|
1098
1104
|
}
|
|
1099
1105
|
}
|
|
1100
1106
|
const sessionToken = getSessionFromContext(ctx)?.get(CSRF_TOKEN_KEY);
|
|
@@ -1143,19 +1149,22 @@ function createCsrfMiddleware(options = {}) {
|
|
|
1143
1149
|
cookieOptions = {}
|
|
1144
1150
|
} = options;
|
|
1145
1151
|
const protectedMethods = new Set(methods.map((m) => m.toUpperCase()));
|
|
1152
|
+
const settleCookie = (ctx) => {
|
|
1153
|
+
if (enableCookie) {
|
|
1154
|
+
setXsrfCookie(ctx, getCsrfToken(ctx), cookieOptions);
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1146
1157
|
return async (ctx, next) => {
|
|
1147
1158
|
const method = ctx.req.method.toUpperCase();
|
|
1148
1159
|
const path = new URL(ctx.req.url).pathname;
|
|
1149
1160
|
if (!protectedMethods.has(method)) {
|
|
1150
|
-
const token = getCsrfToken(ctx);
|
|
1151
1161
|
await next();
|
|
1152
|
-
|
|
1153
|
-
setXsrfCookie(ctx, token, cookieOptions);
|
|
1154
|
-
}
|
|
1162
|
+
settleCookie(ctx);
|
|
1155
1163
|
return;
|
|
1156
1164
|
}
|
|
1157
1165
|
if (isExcluded(path, exclude) || isMcpEndpointRequest(path)) {
|
|
1158
1166
|
await next();
|
|
1167
|
+
settleCookie(ctx);
|
|
1159
1168
|
return;
|
|
1160
1169
|
}
|
|
1161
1170
|
const requestToken = await getTokenFromRequest(ctx);
|
|
@@ -1167,9 +1176,7 @@ function createCsrfMiddleware(options = {}) {
|
|
|
1167
1176
|
return jsonResponse({ message: "CSRF token mismatch" }, 403);
|
|
1168
1177
|
}
|
|
1169
1178
|
await next();
|
|
1170
|
-
|
|
1171
|
-
setXsrfCookie(ctx, getCsrfToken(ctx), cookieOptions);
|
|
1172
|
-
}
|
|
1179
|
+
settleCookie(ctx);
|
|
1173
1180
|
};
|
|
1174
1181
|
}
|
|
1175
1182
|
function setXsrfCookie(ctx, token, options = {}) {
|
|
@@ -1232,15 +1239,8 @@ function validateSafe(schema, data) {
|
|
|
1232
1239
|
|
|
1233
1240
|
// src/http/middleware/rate-limit.ts
|
|
1234
1241
|
var BaseMemoryStore = class {
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
* This store's claim on its hot-reload slot, if it holds one.
|
|
1238
|
-
*
|
|
1239
|
-
* Unlike the cache sweep, this interval is not `unref()`ed, so a leaked one
|
|
1240
|
-
* both duplicates work and keeps the process alive on its own.
|
|
1241
|
-
*/
|
|
1242
|
-
hotReloadClaim;
|
|
1243
|
-
constructor(cleanupIntervalMs = 6e4) {
|
|
1242
|
+
constructor(cleanupIntervalMs = 6e4, now = () => Date.now()) {
|
|
1243
|
+
this.now = now;
|
|
1244
1244
|
if (cleanupIntervalMs <= 0) {
|
|
1245
1245
|
return;
|
|
1246
1246
|
}
|
|
@@ -1252,6 +1252,15 @@ var BaseMemoryStore = class {
|
|
|
1252
1252
|
() => this.destroy()
|
|
1253
1253
|
);
|
|
1254
1254
|
}
|
|
1255
|
+
now;
|
|
1256
|
+
cleanupInterval;
|
|
1257
|
+
/**
|
|
1258
|
+
* This store's claim on its hot-reload slot, if it holds one.
|
|
1259
|
+
*
|
|
1260
|
+
* Unlike the cache sweep, this interval is not `unref()`ed, so a leaked one
|
|
1261
|
+
* both duplicates work and keeps the process alive on its own.
|
|
1262
|
+
*/
|
|
1263
|
+
hotReloadClaim;
|
|
1255
1264
|
destroy() {
|
|
1256
1265
|
if (this.cleanupInterval) {
|
|
1257
1266
|
clearInterval(this.cleanupInterval);
|
|
@@ -1265,14 +1274,14 @@ var MemoryRateLimitStore = class extends BaseMemoryStore {
|
|
|
1265
1274
|
async get(key) {
|
|
1266
1275
|
const entry = this.entries.get(key);
|
|
1267
1276
|
if (!entry) return null;
|
|
1268
|
-
if (
|
|
1277
|
+
if (this.now() >= entry.resetAt) {
|
|
1269
1278
|
this.entries.delete(key);
|
|
1270
1279
|
return null;
|
|
1271
1280
|
}
|
|
1272
1281
|
return entry;
|
|
1273
1282
|
}
|
|
1274
1283
|
async increment(key, windowMs) {
|
|
1275
|
-
const now =
|
|
1284
|
+
const now = this.now();
|
|
1276
1285
|
const existing = this.entries.get(key);
|
|
1277
1286
|
if (existing && now < existing.resetAt) {
|
|
1278
1287
|
existing.count++;
|
|
@@ -1286,7 +1295,7 @@ var MemoryRateLimitStore = class extends BaseMemoryStore {
|
|
|
1286
1295
|
this.entries.delete(key);
|
|
1287
1296
|
}
|
|
1288
1297
|
cleanup() {
|
|
1289
|
-
const now =
|
|
1298
|
+
const now = this.now();
|
|
1290
1299
|
for (const [key, entry] of this.entries.entries()) {
|
|
1291
1300
|
if (now >= entry.resetAt) {
|
|
1292
1301
|
this.entries.delete(key);
|
|
@@ -1353,13 +1362,19 @@ function createRateLimitMiddleware(options = {}) {
|
|
|
1353
1362
|
windowMs = 6e4,
|
|
1354
1363
|
trustProxy = false,
|
|
1355
1364
|
keyGenerator = trustProxy ? proxyAwareKeyGenerator : defaultKeyGenerator,
|
|
1356
|
-
store
|
|
1365
|
+
// An injected clock must drive the default store too, or expiry would run
|
|
1366
|
+
// on real time while Retry-After runs on the fake clock. The shared default
|
|
1367
|
+
// store stays on real time, so build a dedicated store instead — without
|
|
1368
|
+
// auto-cleanup, since a real-time sweep is meaningless on a fake clock and
|
|
1369
|
+
// its interval would outlive tests.
|
|
1370
|
+
store = options.now ? new MemoryRateLimitStore(0, options.now) : getDefaultStore(),
|
|
1357
1371
|
skip,
|
|
1358
1372
|
onRateLimited,
|
|
1359
1373
|
headers = true,
|
|
1360
1374
|
message = "Too many requests, please try again later.",
|
|
1361
1375
|
statusCode = 429,
|
|
1362
|
-
keyPrefix = "rl:"
|
|
1376
|
+
keyPrefix = "rl:",
|
|
1377
|
+
now = () => Date.now()
|
|
1363
1378
|
} = options;
|
|
1364
1379
|
return async (ctx, next) => {
|
|
1365
1380
|
if (skip && await skip(ctx)) {
|
|
@@ -1369,7 +1384,7 @@ function createRateLimitMiddleware(options = {}) {
|
|
|
1369
1384
|
const key = `${keyPrefix}${baseKey}`;
|
|
1370
1385
|
const entry = await store.increment(key, windowMs);
|
|
1371
1386
|
const remaining = Math.max(0, limit - entry.count);
|
|
1372
|
-
const resetSeconds = Math.ceil((entry.resetAt -
|
|
1387
|
+
const resetSeconds = Math.max(0, Math.ceil((entry.resetAt - now()) / 1e3));
|
|
1373
1388
|
if (headers) {
|
|
1374
1389
|
ctx.header("X-RateLimit-Limit", limit.toString());
|
|
1375
1390
|
ctx.header("X-RateLimit-Remaining", remaining.toString());
|
|
@@ -1416,7 +1431,7 @@ var SlidingWindowRateLimitStore = class extends BaseMemoryStore {
|
|
|
1416
1431
|
async get(key) {
|
|
1417
1432
|
const entry = this.requests.get(key);
|
|
1418
1433
|
if (!entry || entry.timestamps.length === 0) return null;
|
|
1419
|
-
const now =
|
|
1434
|
+
const now = this.now();
|
|
1420
1435
|
const windowStart = now - entry.windowMs;
|
|
1421
1436
|
const timestamps = entry.timestamps.filter((t2) => t2 > windowStart);
|
|
1422
1437
|
if (timestamps.length === 0) {
|
|
@@ -1429,7 +1444,7 @@ var SlidingWindowRateLimitStore = class extends BaseMemoryStore {
|
|
|
1429
1444
|
return { count: timestamps.length, resetAt: timestamps[0] + entry.windowMs };
|
|
1430
1445
|
}
|
|
1431
1446
|
async increment(key, windowMs) {
|
|
1432
|
-
const now =
|
|
1447
|
+
const now = this.now();
|
|
1433
1448
|
const windowStart = now - windowMs;
|
|
1434
1449
|
const entry = this.requests.get(key);
|
|
1435
1450
|
let timestamps = entry ? entry.timestamps.filter((t2) => t2 > windowStart) : [];
|
|
@@ -1441,7 +1456,7 @@ var SlidingWindowRateLimitStore = class extends BaseMemoryStore {
|
|
|
1441
1456
|
this.requests.delete(key);
|
|
1442
1457
|
}
|
|
1443
1458
|
cleanup() {
|
|
1444
|
-
const now =
|
|
1459
|
+
const now = this.now();
|
|
1445
1460
|
for (const [key, entry] of this.requests.entries()) {
|
|
1446
1461
|
const windowStart = now - entry.windowMs;
|
|
1447
1462
|
const valid = entry.timestamps.filter((t2) => t2 > windowStart);
|
|
@@ -1754,6 +1769,16 @@ import { createMiddleware as createMiddleware3 } from "hono/factory";
|
|
|
1754
1769
|
import { getCookie as getCookie2 } from "hono/cookie";
|
|
1755
1770
|
import { parseAccept } from "hono/utils/accept";
|
|
1756
1771
|
var LOCALE_CONTEXT_KEY = "locale";
|
|
1772
|
+
function getRequestLocale(c) {
|
|
1773
|
+
const locale = c.var?.[LOCALE_CONTEXT_KEY];
|
|
1774
|
+
return typeof locale === "string" && locale.length > 0 ? locale : void 0;
|
|
1775
|
+
}
|
|
1776
|
+
function getRequestTranslator(c) {
|
|
1777
|
+
const vars = c.var;
|
|
1778
|
+
const t2 = vars?.["t"];
|
|
1779
|
+
const tc2 = vars?.["tc"];
|
|
1780
|
+
return typeof t2 === "function" && typeof tc2 === "function" ? { t: t2, tc: tc2 } : void 0;
|
|
1781
|
+
}
|
|
1757
1782
|
var DEFAULT_SOURCES = ["query", "cookie", "header"];
|
|
1758
1783
|
function detectLocaleMiddleware(options) {
|
|
1759
1784
|
const supported = options.supported.map((locale) => locale.trim()).filter(Boolean);
|
|
@@ -1788,26 +1813,20 @@ function detectLocaleMiddleware(options) {
|
|
|
1788
1813
|
return void 0;
|
|
1789
1814
|
};
|
|
1790
1815
|
const translators = /* @__PURE__ */ new Map();
|
|
1791
|
-
const
|
|
1792
|
-
|
|
1793
|
-
return void 0;
|
|
1794
|
-
}
|
|
1816
|
+
const supportedSet = new Set(supported);
|
|
1817
|
+
const bindingFor = (locale, i18n) => {
|
|
1795
1818
|
const cached = translators.get(locale);
|
|
1796
1819
|
if (cached) {
|
|
1797
1820
|
return cached;
|
|
1798
1821
|
}
|
|
1799
|
-
const i18n = options.i18n ?? tryGlobalI18n();
|
|
1800
|
-
if (!i18n) {
|
|
1801
|
-
return void 0;
|
|
1802
|
-
}
|
|
1803
|
-
await i18n.loadLocale(locale).catch(() => {
|
|
1804
|
-
});
|
|
1805
1822
|
const translator = i18n.forLocale(locale);
|
|
1806
1823
|
const binding = {
|
|
1807
1824
|
t: translator.t.bind(translator),
|
|
1808
1825
|
tc: translator.tc.bind(translator)
|
|
1809
1826
|
};
|
|
1810
|
-
|
|
1827
|
+
if (supportedSet.has(locale) && i18n.isLocaleLoaded(locale)) {
|
|
1828
|
+
translators.set(locale, binding);
|
|
1829
|
+
}
|
|
1811
1830
|
return binding;
|
|
1812
1831
|
};
|
|
1813
1832
|
return createMiddleware3(async (c, next) => {
|
|
@@ -1825,21 +1844,17 @@ function detectLocaleMiddleware(options) {
|
|
|
1825
1844
|
}
|
|
1826
1845
|
}
|
|
1827
1846
|
c.set(LOCALE_CONTEXT_KEY, resolved);
|
|
1828
|
-
const
|
|
1829
|
-
if (
|
|
1830
|
-
|
|
1831
|
-
|
|
1847
|
+
const i18n = options.i18n === false ? void 0 : options.i18n ?? tryGetI18n();
|
|
1848
|
+
if (i18n) {
|
|
1849
|
+
await i18n.loadLocale(resolved).catch(() => {
|
|
1850
|
+
});
|
|
1851
|
+
const current = () => bindingFor(getRequestLocale(c) ?? resolved, i18n);
|
|
1852
|
+
c.set("t", (key, replacements) => current().t(key, replacements));
|
|
1853
|
+
c.set("tc", (key, count, replacements) => current().tc(key, count, replacements));
|
|
1832
1854
|
}
|
|
1833
1855
|
await next();
|
|
1834
1856
|
});
|
|
1835
1857
|
}
|
|
1836
|
-
function tryGlobalI18n() {
|
|
1837
|
-
try {
|
|
1838
|
-
return getI18n();
|
|
1839
|
-
} catch {
|
|
1840
|
-
return void 0;
|
|
1841
|
-
}
|
|
1842
|
-
}
|
|
1843
1858
|
|
|
1844
1859
|
// src/http/middleware/index.ts
|
|
1845
1860
|
function defineMiddleware(handler) {
|
|
@@ -2009,6 +2024,163 @@ var ErrorServiceProvider = class extends ServiceProvider {
|
|
|
2009
2024
|
}
|
|
2010
2025
|
};
|
|
2011
2026
|
|
|
2027
|
+
// src/mvc/inertia/shared.ts
|
|
2028
|
+
var INERTIA_SHARED_PROPS_BINDING = "inertia.sharedProps";
|
|
2029
|
+
var registrationSequence = 0;
|
|
2030
|
+
var SharedInertiaPropsRegistry = class {
|
|
2031
|
+
resolvers = [];
|
|
2032
|
+
/** Replace every resolver registered in this scope. */
|
|
2033
|
+
set(resolverFn) {
|
|
2034
|
+
this.resolvers = resolverFn ? [orderedResolver(resolverFn)] : [];
|
|
2035
|
+
}
|
|
2036
|
+
/**
|
|
2037
|
+
* Register additional shared props without replacing resolvers registered
|
|
2038
|
+
* earlier — the new resolver's props are merged over the previous ones.
|
|
2039
|
+
*/
|
|
2040
|
+
share(resolverFn) {
|
|
2041
|
+
this.resolvers.push(orderedResolver(resolverFn));
|
|
2042
|
+
}
|
|
2043
|
+
/** The resolvers registered in this scope, ordered by registration. */
|
|
2044
|
+
entries() {
|
|
2045
|
+
return this.resolvers;
|
|
2046
|
+
}
|
|
2047
|
+
/**
|
|
2048
|
+
* The scope's registrations composed into one resolver, or null when empty.
|
|
2049
|
+
* The composition is a snapshot: resolvers registered later are not picked up.
|
|
2050
|
+
*/
|
|
2051
|
+
get() {
|
|
2052
|
+
if (this.resolvers.length === 0) return null;
|
|
2053
|
+
if (this.resolvers.length === 1) return this.resolvers[0].resolve;
|
|
2054
|
+
const snapshot = [...this.resolvers];
|
|
2055
|
+
return (ctx) => applyResolvers(snapshot, ctx);
|
|
2056
|
+
}
|
|
2057
|
+
async resolve(ctx) {
|
|
2058
|
+
return applyResolvers(this.resolvers, ctx);
|
|
2059
|
+
}
|
|
2060
|
+
};
|
|
2061
|
+
function orderedResolver(resolverFn) {
|
|
2062
|
+
return {
|
|
2063
|
+
seq: registrationSequence++,
|
|
2064
|
+
resolve: resolverFn
|
|
2065
|
+
};
|
|
2066
|
+
}
|
|
2067
|
+
async function applyResolvers(entries, ctx) {
|
|
2068
|
+
const merged = {};
|
|
2069
|
+
for (const entry of entries) {
|
|
2070
|
+
const props = await entry.resolve(ctx);
|
|
2071
|
+
if (props && typeof props === "object") {
|
|
2072
|
+
Object.assign(merged, props);
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
return merged;
|
|
2076
|
+
}
|
|
2077
|
+
var globalRegistry = new SharedInertiaPropsRegistry();
|
|
2078
|
+
function scopedRegistry(container) {
|
|
2079
|
+
if (!container?.has?.(INERTIA_SHARED_PROPS_BINDING)) return null;
|
|
2080
|
+
return container.make(INERTIA_SHARED_PROPS_BINDING);
|
|
2081
|
+
}
|
|
2082
|
+
function ensureSharedInertiaPropsRegistry(container) {
|
|
2083
|
+
const existing = scopedRegistry(container);
|
|
2084
|
+
if (existing) return existing;
|
|
2085
|
+
const registry = new SharedInertiaPropsRegistry();
|
|
2086
|
+
container.instance(INERTIA_SHARED_PROPS_BINDING, registry);
|
|
2087
|
+
return registry;
|
|
2088
|
+
}
|
|
2089
|
+
function setInertiaSharedProps(resolverFn) {
|
|
2090
|
+
globalRegistry.set(resolverFn);
|
|
2091
|
+
}
|
|
2092
|
+
function getInertiaSharedPropsResolver() {
|
|
2093
|
+
return globalRegistry.get();
|
|
2094
|
+
}
|
|
2095
|
+
function shareInertiaProps(resolverFn, container) {
|
|
2096
|
+
const registry = container ? ensureSharedInertiaPropsRegistry(container) : globalRegistry;
|
|
2097
|
+
registry.share(resolverFn);
|
|
2098
|
+
}
|
|
2099
|
+
async function resolveSharedInertiaProps(ctx, container) {
|
|
2100
|
+
const scoped = scopedRegistry(container);
|
|
2101
|
+
if (!scoped) return globalRegistry.resolve(ctx);
|
|
2102
|
+
const globalEntries = globalRegistry.entries();
|
|
2103
|
+
if (globalEntries.length === 0) return scoped.resolve(ctx);
|
|
2104
|
+
const ordered = [...globalEntries, ...scoped.entries()].sort((a, b) => a.seq - b.seq);
|
|
2105
|
+
return applyResolvers(ordered, ctx);
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
// src/providers/I18nServiceProvider.ts
|
|
2109
|
+
var I18nServiceProvider = class extends ServiceProvider {
|
|
2110
|
+
register() {
|
|
2111
|
+
const app = this.application();
|
|
2112
|
+
const options = app?.i18nOptions;
|
|
2113
|
+
if (options) {
|
|
2114
|
+
if (options.supported.length === 0) {
|
|
2115
|
+
throw new Error("createApp({ i18n }) requires at least one supported locale.");
|
|
2116
|
+
}
|
|
2117
|
+
if (options.fallback && !options.supported.includes(options.fallback)) {
|
|
2118
|
+
throw new Error(
|
|
2119
|
+
`createApp({ i18n }): fallback locale '${options.fallback}' must be one of the supported locales (${options.supported.join(", ")}).`
|
|
2120
|
+
);
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
this.container.singleton("i18n", () => {
|
|
2124
|
+
if (!options) {
|
|
2125
|
+
return createI18n({ locale: "en" });
|
|
2126
|
+
}
|
|
2127
|
+
const fallback = options.fallback ?? options.supported[0];
|
|
2128
|
+
return createI18n({
|
|
2129
|
+
locale: fallback,
|
|
2130
|
+
fallbackLocale: fallback,
|
|
2131
|
+
path: options.loader ? void 0 : options.path ?? "lang",
|
|
2132
|
+
loader: options.loader
|
|
2133
|
+
});
|
|
2134
|
+
});
|
|
2135
|
+
if (app && options && options.detect !== false) {
|
|
2136
|
+
const manager = this.container.make("i18n");
|
|
2137
|
+
app.use("*", detectLocaleMiddleware({
|
|
2138
|
+
...options.detect,
|
|
2139
|
+
supported: options.supported,
|
|
2140
|
+
fallback: manager.getLocale(),
|
|
2141
|
+
i18n: manager
|
|
2142
|
+
}));
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
async boot() {
|
|
2146
|
+
const options = this.application()?.i18nOptions;
|
|
2147
|
+
if (!options) return;
|
|
2148
|
+
const manager = this.container.make("i18n");
|
|
2149
|
+
await manager.loadLocales([...options.supported]);
|
|
2150
|
+
for (const locale of options.supported) {
|
|
2151
|
+
if (Object.keys(manager.getMessages(locale)).length === 0) {
|
|
2152
|
+
console.warn(
|
|
2153
|
+
`[guren] i18n: no translations loaded for locale '${locale}'` + (options.loader ? "." : ` \u2014 expected ${options.path ?? "lang"}/${locale}/*.json.`)
|
|
2154
|
+
);
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
if (options.share !== false) {
|
|
2158
|
+
const fallback = manager.getFallbackLocale() ?? manager.getLocale();
|
|
2159
|
+
const supported = new Set(options.supported);
|
|
2160
|
+
const propsByLocale = /* @__PURE__ */ new Map();
|
|
2161
|
+
shareInertiaProps((ctx) => {
|
|
2162
|
+
const locale = getRequestLocale(ctx) ?? fallback;
|
|
2163
|
+
let i18nProps = propsByLocale.get(locale);
|
|
2164
|
+
if (!i18nProps) {
|
|
2165
|
+
i18nProps = {
|
|
2166
|
+
locale,
|
|
2167
|
+
fallbackLocale: fallback,
|
|
2168
|
+
messages: manager.messagesForLocale(locale)
|
|
2169
|
+
};
|
|
2170
|
+
if (supported.has(locale)) {
|
|
2171
|
+
propsByLocale.set(locale, i18nProps);
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
return { _i18n: i18nProps };
|
|
2175
|
+
}, this.container);
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
/** The provider works standalone on a bare container (no `app` binding). */
|
|
2179
|
+
application() {
|
|
2180
|
+
return this.container.has("app") ? this.container.make("app") : void 0;
|
|
2181
|
+
}
|
|
2182
|
+
};
|
|
2183
|
+
|
|
2012
2184
|
// src/mvc/inertia/InertiaEngine.ts
|
|
2013
2185
|
import { isAbsolute, resolve as resolvePath } from "path";
|
|
2014
2186
|
import { pathToFileURL } from "url";
|
|
@@ -2317,31 +2489,6 @@ var ViewEngine = class {
|
|
|
2317
2489
|
}
|
|
2318
2490
|
};
|
|
2319
2491
|
|
|
2320
|
-
// src/mvc/inertia/shared.ts
|
|
2321
|
-
var resolver = null;
|
|
2322
|
-
function setInertiaSharedProps(resolverFn) {
|
|
2323
|
-
resolver = resolverFn;
|
|
2324
|
-
}
|
|
2325
|
-
function getInertiaSharedPropsResolver() {
|
|
2326
|
-
return resolver;
|
|
2327
|
-
}
|
|
2328
|
-
function shareInertiaProps(resolverFn) {
|
|
2329
|
-
const previous = resolver;
|
|
2330
|
-
resolver = async (ctx) => {
|
|
2331
|
-
const prev = previous ? await previous(ctx) : {};
|
|
2332
|
-
const next = await resolverFn(ctx);
|
|
2333
|
-
return { ...prev, ...next };
|
|
2334
|
-
};
|
|
2335
|
-
}
|
|
2336
|
-
async function resolveSharedInertiaProps(ctx) {
|
|
2337
|
-
if (!resolver) return {};
|
|
2338
|
-
const shared = await resolver(ctx);
|
|
2339
|
-
if (shared && typeof shared === "object") {
|
|
2340
|
-
return shared;
|
|
2341
|
-
}
|
|
2342
|
-
return {};
|
|
2343
|
-
}
|
|
2344
|
-
|
|
2345
2492
|
// src/providers/InertiaServiceProvider.ts
|
|
2346
2493
|
var InertiaServiceProvider = class extends ServiceProvider {
|
|
2347
2494
|
register() {
|
|
@@ -2391,19 +2538,16 @@ var InertiaServiceProvider = class extends ServiceProvider {
|
|
|
2391
2538
|
});
|
|
2392
2539
|
}
|
|
2393
2540
|
/**
|
|
2394
|
-
*
|
|
2541
|
+
* Auto-inject flashed `errors` into shared props. Scoped to this app's
|
|
2542
|
+
* container so a second Application booted in the same process keeps its
|
|
2543
|
+
* own registrations.
|
|
2395
2544
|
*/
|
|
2396
2545
|
registerSharedErrors() {
|
|
2397
|
-
|
|
2398
|
-
setInertiaSharedProps(async (ctx) => {
|
|
2399
|
-
const prev = previous ? await previous(ctx) : {};
|
|
2546
|
+
shareInertiaProps(async (ctx) => {
|
|
2400
2547
|
const session = getSessionFromContext(ctx);
|
|
2401
2548
|
const errors = session?.getFlash("errors");
|
|
2402
|
-
return {
|
|
2403
|
-
|
|
2404
|
-
...errors && Object.keys(errors).length > 0 ? { errors } : {}
|
|
2405
|
-
};
|
|
2406
|
-
});
|
|
2549
|
+
return errors && Object.keys(errors).length > 0 ? { errors } : {};
|
|
2550
|
+
}, this.container);
|
|
2407
2551
|
}
|
|
2408
2552
|
};
|
|
2409
2553
|
|
|
@@ -2508,19 +2652,17 @@ var Application = class {
|
|
|
2508
2652
|
...Array.isArray(this.options.providers) ? this.options.providers : [],
|
|
2509
2653
|
...moduleProviders
|
|
2510
2654
|
];
|
|
2511
|
-
const
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2655
|
+
const hasUserProviderOf = (base) => userProviders.some((provider) => provider === base || provider.prototype instanceof base);
|
|
2656
|
+
if (this.options.i18n && !hasUserProviderOf(I18nServiceProvider)) {
|
|
2657
|
+
this.providerManager.register(I18nServiceProvider);
|
|
2658
|
+
}
|
|
2659
|
+
if (!hasUserProviderOf(ErrorServiceProvider)) {
|
|
2515
2660
|
this.providerManager.register(ErrorServiceProvider);
|
|
2516
2661
|
}
|
|
2517
2662
|
if (userProviders.length > 0) {
|
|
2518
2663
|
this.providerManager.registerMany(userProviders);
|
|
2519
2664
|
}
|
|
2520
|
-
|
|
2521
|
-
(provider) => provider === InertiaServiceProvider || provider.prototype instanceof InertiaServiceProvider
|
|
2522
|
-
);
|
|
2523
|
-
if (!hasUserInertiaProvider) {
|
|
2665
|
+
if (!hasUserProviderOf(InertiaServiceProvider)) {
|
|
2524
2666
|
this.providerManager.register(InertiaServiceProvider);
|
|
2525
2667
|
}
|
|
2526
2668
|
}
|
|
@@ -2542,6 +2684,9 @@ var Application = class {
|
|
|
2542
2684
|
get authOptions() {
|
|
2543
2685
|
return this.options.auth;
|
|
2544
2686
|
}
|
|
2687
|
+
get i18nOptions() {
|
|
2688
|
+
return this.options.i18n;
|
|
2689
|
+
}
|
|
2545
2690
|
markAutoSessionAttached() {
|
|
2546
2691
|
this.autoSessionAttached = true;
|
|
2547
2692
|
}
|
|
@@ -2579,7 +2724,7 @@ var Application = class {
|
|
|
2579
2724
|
await this.mountRoutes();
|
|
2580
2725
|
await this.mountDevEndpoint(
|
|
2581
2726
|
isMcpEndpointEnabled(),
|
|
2582
|
-
async () => (await import("./McpServiceProvider-
|
|
2727
|
+
async () => (await import("./McpServiceProvider-GRDYNEQG.js")).McpServiceProvider,
|
|
2583
2728
|
"GUREN_MCP=1 but the MCP endpoint could not load \u2014 is @modelcontextprotocol/sdk installed?"
|
|
2584
2729
|
);
|
|
2585
2730
|
await this.mountDevEndpoint(
|
|
@@ -2653,7 +2798,7 @@ var Application = class {
|
|
|
2653
2798
|
const { server: server2, localUrl } = await startViteDevServer({
|
|
2654
2799
|
root: viteOptions?.root ?? process.cwd(),
|
|
2655
2800
|
config: viteOptions?.config,
|
|
2656
|
-
host: viteOptions?.host
|
|
2801
|
+
host: viteOptions?.host,
|
|
2657
2802
|
port: viteOptions?.port
|
|
2658
2803
|
});
|
|
2659
2804
|
this.viteDevServer = server2;
|
|
@@ -2930,11 +3075,13 @@ var Controller = class {
|
|
|
2930
3075
|
const { url: overrideUrl, ...rest } = options;
|
|
2931
3076
|
const url2 = overrideUrl ?? ctx.req.path ?? ctx.req.url ?? "";
|
|
2932
3077
|
const component = typeof componentOrPage === "string" ? componentOrPage : componentOrPage.component ?? componentOrPage.id;
|
|
2933
|
-
const sharedProps = await resolveSharedInertiaProps(ctx);
|
|
3078
|
+
const sharedProps = await resolveSharedInertiaProps(ctx, this._container);
|
|
2934
3079
|
const propsWithShared = { ...sharedProps, ...props };
|
|
2935
3080
|
const response = await inertia(component, propsWithShared, {
|
|
2936
3081
|
...rest,
|
|
2937
|
-
|
|
3082
|
+
// No 'en' fallback here (unlike the locale getter): unconfigured apps
|
|
3083
|
+
// keep the Inertia engine's own default lang.
|
|
3084
|
+
lang: rest.lang ?? this.#resolveLocale(),
|
|
2938
3085
|
url: url2,
|
|
2939
3086
|
request: ctx.req.raw
|
|
2940
3087
|
});
|
|
@@ -2945,29 +3092,65 @@ var Controller = class {
|
|
|
2945
3092
|
return response;
|
|
2946
3093
|
}
|
|
2947
3094
|
/**
|
|
2948
|
-
*
|
|
2949
|
-
*
|
|
2950
|
-
*
|
|
2951
|
-
*
|
|
3095
|
+
* Locale resolved for the current request: the request-scoped `locale`
|
|
3096
|
+
* context variable (set by locale middleware) wins over the app-wide i18n
|
|
3097
|
+
* locale (the router-injected container binding, then the `setI18n()`
|
|
3098
|
+
* global). Falls back to `'en'` when no i18n is configured.
|
|
2952
3099
|
*/
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
3100
|
+
get locale() {
|
|
3101
|
+
return this.#resolveLocale() ?? "en";
|
|
3102
|
+
}
|
|
3103
|
+
/**
|
|
3104
|
+
* Translate a key for the current request locale.
|
|
3105
|
+
*
|
|
3106
|
+
* Uses the request-scoped translator bound by the locale detection
|
|
3107
|
+
* middleware when present, falling back to a translator scoped to
|
|
3108
|
+
* `this.locale` from the container's `i18n` binding (then the `setI18n()`
|
|
3109
|
+
* global).
|
|
3110
|
+
*
|
|
3111
|
+
* @example
|
|
3112
|
+
* ```typescript
|
|
3113
|
+
* this.t('posts.created')
|
|
3114
|
+
* this.t('posts.greeting', { name: user.name })
|
|
3115
|
+
* ```
|
|
3116
|
+
*/
|
|
3117
|
+
t(key, replacements) {
|
|
3118
|
+
return this.#requestTranslator().t(key, replacements);
|
|
3119
|
+
}
|
|
3120
|
+
/**
|
|
3121
|
+
* Translate a key with a count for pluralization, using the same locale
|
|
3122
|
+
* resolution as {@link Controller.t}.
|
|
3123
|
+
*/
|
|
3124
|
+
tc(key, count, replacements) {
|
|
3125
|
+
return this.#requestTranslator().tc(key, count, replacements);
|
|
3126
|
+
}
|
|
3127
|
+
#requestTranslator() {
|
|
3128
|
+
const bound = getRequestTranslator(this.ctx);
|
|
3129
|
+
if (bound) {
|
|
3130
|
+
return bound;
|
|
3131
|
+
}
|
|
3132
|
+
const i18n = this.#resolveI18n();
|
|
3133
|
+
if (!i18n) {
|
|
3134
|
+
throw new Error(
|
|
3135
|
+
"Controller i18n helpers require i18n to be configured. Pass createApp({ i18n }) or register an I18nManager."
|
|
3136
|
+
);
|
|
3137
|
+
}
|
|
3138
|
+
const locale = getRequestLocale(this.ctx);
|
|
3139
|
+
return locale && locale !== i18n.getLocale() ? i18n.forLocale(locale) : i18n;
|
|
3140
|
+
}
|
|
3141
|
+
#resolveLocale() {
|
|
3142
|
+
const requestLocale = getRequestLocale(this.ctx);
|
|
3143
|
+
if (requestLocale) {
|
|
2957
3144
|
return requestLocale;
|
|
2958
3145
|
}
|
|
2959
|
-
|
|
3146
|
+
const locale = this.#resolveI18n()?.getLocale();
|
|
3147
|
+
return typeof locale === "string" && locale.length > 0 ? locale : void 0;
|
|
3148
|
+
}
|
|
3149
|
+
#resolveI18n() {
|
|
2960
3150
|
if (this._container?.has?.("i18n")) {
|
|
2961
|
-
|
|
2962
|
-
} else {
|
|
2963
|
-
try {
|
|
2964
|
-
i18n = getI18n();
|
|
2965
|
-
} catch {
|
|
2966
|
-
i18n = void 0;
|
|
2967
|
-
}
|
|
3151
|
+
return this._container.make("i18n");
|
|
2968
3152
|
}
|
|
2969
|
-
|
|
2970
|
-
return typeof locale === "string" && locale.length > 0 ? locale : void 0;
|
|
3153
|
+
return tryGetI18n();
|
|
2971
3154
|
}
|
|
2972
3155
|
json(data, init = {}) {
|
|
2973
3156
|
return new Response(JSON.stringify(data), {
|
|
@@ -3239,13 +3422,6 @@ var LogServiceProvider = class extends ServiceProvider {
|
|
|
3239
3422
|
}
|
|
3240
3423
|
};
|
|
3241
3424
|
|
|
3242
|
-
// src/providers/I18nServiceProvider.ts
|
|
3243
|
-
var I18nServiceProvider = class extends ServiceProvider {
|
|
3244
|
-
register() {
|
|
3245
|
-
this.container.singleton("i18n", () => createI18n({ locale: "en" }));
|
|
3246
|
-
}
|
|
3247
|
-
};
|
|
3248
|
-
|
|
3249
3425
|
// src/providers/NotificationServiceProvider.ts
|
|
3250
3426
|
var NotificationServiceProvider = class extends ServiceProvider {
|
|
3251
3427
|
register() {
|
|
@@ -6833,6 +7009,7 @@ export {
|
|
|
6833
7009
|
Notification,
|
|
6834
7010
|
NotificationManager,
|
|
6835
7011
|
NotificationServiceProvider,
|
|
7012
|
+
OAUTH_SESSION_BINDING_KEY,
|
|
6836
7013
|
OAuthManager,
|
|
6837
7014
|
OAuthServiceProvider,
|
|
6838
7015
|
Output,
|
|
@@ -7013,6 +7190,8 @@ export {
|
|
|
7013
7190
|
getQueueDriver,
|
|
7014
7191
|
getRateLimitInfo,
|
|
7015
7192
|
getRegisteredJobs,
|
|
7193
|
+
getRequestLocale,
|
|
7194
|
+
getRequestTranslator,
|
|
7016
7195
|
getSessionFromContext,
|
|
7017
7196
|
getUserApiTokens,
|
|
7018
7197
|
getValidatedData,
|
|
@@ -7122,6 +7301,7 @@ export {
|
|
|
7122
7301
|
tokenCan,
|
|
7123
7302
|
tokenCanAll,
|
|
7124
7303
|
tokenCanAny,
|
|
7304
|
+
tryGetI18n,
|
|
7125
7305
|
unique,
|
|
7126
7306
|
url as urlRule,
|
|
7127
7307
|
urlSafeToken,
|