@guren/server 2.14.0 → 2.16.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-qFCaeiUv.js → DocsViewerServiceProvider-D2cuVgtN.js} +7 -12
- package/dist/{Hash-CzrwKeDp.js → Hash-D2DFd8xX.js} +12 -57
- package/dist/{HttpException-BkS3euNG.js → HttpException-BlQ2yEmT.js} +2 -79
- package/dist/{Job-BVT813DO.js → Job-DxQK8h3P.js} +24 -179
- package/dist/{McpServiceProvider-BawsYjgN.js → McpServiceProvider-nNcbCIQX.js} +11 -20
- package/dist/{Random-DbIJ22KQ.js → Random-S0OvCuR8.js} +9 -106
- package/dist/agent/AgentApprovalRequested.d.ts +31 -0
- package/dist/agent/approval.d.ts +184 -0
- package/dist/agent/audit-emitter.d.ts +36 -0
- package/dist/agent/audit.d.ts +67 -0
- package/dist/agent/derive.d.ts +32 -66
- package/dist/agent/dispatch.d.ts +53 -63
- package/dist/agent/events.d.ts +11 -19
- package/dist/agent/meta-tools.d.ts +34 -0
- package/dist/agent/public.d.ts +14 -0
- package/dist/agent/public.js +2 -0
- package/dist/agent/redact.d.ts +16 -38
- package/dist/agent/scopes.d.ts +23 -69
- package/dist/auth/AuthManager.d.ts +19 -40
- package/dist/auth/AuthenticatableModel.d.ts +2 -2
- package/dist/auth/SessionGuard.d.ts +0 -1
- package/dist/auth/TokenGuard.d.ts +6 -26
- package/dist/auth/api-token.d.ts +16 -148
- package/dist/auth/context.d.ts +5 -10
- package/dist/auth/email-verification.d.ts +29 -127
- package/dist/auth/index.js +1 -1
- package/dist/auth/oauth/index.d.ts +35 -57
- package/dist/auth/password/DefaultHasher.d.ts +9 -5
- package/dist/auth/password/PasswordHasher.d.ts +7 -0
- package/dist/auth/password/hash-format.d.ts +11 -0
- package/dist/auth/password-reset.d.ts +16 -42
- package/dist/auth/providers/ModelUserProvider.d.ts +3 -4
- package/dist/auth/providers/UserProvider.d.ts +4 -4
- package/dist/auth/signed-token.d.ts +18 -0
- package/dist/auth/types.d.ts +9 -32
- package/dist/auth/utils.d.ts +6 -27
- package/dist/{auth-BSUc14CD.js → auth-CbdPH4Cd.js} +252 -496
- package/dist/authorization/Gate.d.ts +9 -145
- package/dist/authorization/Policy.d.ts +6 -53
- package/dist/authorization/index.js +1 -1
- package/dist/authorization/middleware.d.ts +16 -62
- package/dist/authorization/types.d.ts +8 -64
- package/dist/{authorization-CdfbCj8J.js → authorization-CdEWZZw3.js} +44 -309
- package/dist/broadcasting/BroadcastManager.d.ts +29 -149
- package/dist/broadcasting/channels/Channel.d.ts +1 -19
- package/dist/broadcasting/channels/PresenceChannel.d.ts +1 -55
- package/dist/broadcasting/channels/PrivateChannel.d.ts +1 -23
- package/dist/broadcasting/drivers/MemoryDriver.d.ts +18 -70
- package/dist/broadcasting/drivers/RedisDriver.d.ts +3 -80
- package/dist/broadcasting/drivers/index.d.ts +1 -1
- package/dist/broadcasting/index.d.ts +1 -1
- package/dist/broadcasting/index.js +1 -1
- package/dist/broadcasting/types.d.ts +7 -88
- package/dist/{broadcasting-BxU-LIfF.js → broadcasting-B5RzB0A2.js} +87 -414
- package/dist/cache/CacheManager.d.ts +8 -62
- package/dist/cache/TaggedCache.d.ts +2 -35
- package/dist/cache/index.js +1 -1
- package/dist/cache/stores/FileStore.d.ts +2 -36
- package/dist/cache/stores/MemoryStore.d.ts +2 -26
- package/dist/cache/stores/RedisStore.d.ts +1 -29
- package/dist/cache/types.d.ts +21 -128
- package/dist/{cache-BYnZf2FR.js → cache-BOOIr324.js} +19 -198
- package/dist/client-C4TEr_Dd.js +9 -0
- package/dist/console/Command.d.ts +17 -126
- package/dist/console/ConsoleKernel.d.ts +2 -74
- package/dist/console/Input.d.ts +5 -113
- package/dist/console/Output.d.ts +3 -99
- package/dist/console/types.d.ts +3 -33
- package/dist/container/Container.d.ts +12 -103
- package/dist/container/ServiceProvider.d.ts +17 -61
- package/dist/container/bindings.d.ts +10 -12
- package/dist/container/defineModule.d.ts +16 -54
- package/dist/container/definePlugin.d.ts +12 -45
- package/dist/container/types.d.ts +2 -34
- package/dist/context-CXk_umpT.js +21 -0
- package/dist/database/Factory.d.ts +4 -57
- package/dist/database/Seeder.d.ts +8 -46
- package/dist/database/SeederRunner.d.ts +3 -33
- package/dist/database/types.d.ts +3 -24
- package/dist/discovery/AutoDiscovery.d.ts +10 -82
- package/dist/dispatch-BAwzftws.js +238 -0
- package/dist/docs-viewer/DocsViewerServiceProvider.d.ts +2 -5
- package/dist/docs-viewer/endpoint.d.ts +5 -11
- package/dist/encryption/Encrypter.d.ts +5 -71
- package/dist/encryption/Hash.d.ts +7 -57
- package/dist/encryption/Random.d.ts +6 -99
- package/dist/encryption/index.js +3 -3
- package/dist/encryption/types.d.ts +10 -72
- package/dist/{encryption-DJtkkhiw.js → encryption-uwP3Di4D.js} +13 -79
- package/dist/{endpoint-D6GIqOpe.js → endpoint-BXipU2Jj.js} +6 -12
- package/dist/endpoint-Dsw3Acvq.js +26 -0
- package/dist/errors/ExceptionHandler.d.ts +3 -90
- package/dist/errors/HttpException.d.ts +2 -79
- package/dist/errors/debug-page.d.ts +3 -17
- package/dist/errors/error-page.d.ts +1 -0
- package/dist/errors/exceptions/AuthenticationException.d.ts +2 -24
- package/dist/errors/exceptions/AuthorizationException.d.ts +1 -24
- package/dist/errors/exceptions/MethodNotAllowedException.d.ts +1 -23
- package/dist/errors/exceptions/NotFoundHttpException.d.ts +1 -27
- package/dist/errors/exceptions/ValidationException.d.ts +2 -43
- package/dist/errors/types.d.ts +1 -25
- package/dist/{errors-BgeOl_DC.js → errors-JpkcCjjn.js} +3 -41
- package/dist/events/Event.d.ts +1 -28
- package/dist/events/EventManager.d.ts +5 -107
- package/dist/events/Listener.d.ts +7 -55
- package/dist/events/builtin.d.ts +0 -24
- package/dist/events/index.js +1 -1
- package/dist/events/types.d.ts +4 -22
- package/dist/{events-aIH_bWRx.js → events-DOmAHDeP.js} +11 -191
- package/dist/facades/index.d.ts +2 -14
- package/dist/health/HealthCheck.d.ts +0 -24
- package/dist/health/HealthManager.d.ts +0 -36
- package/dist/health/checks/CacheCheck.d.ts +2 -17
- package/dist/health/checks/CustomCheck.d.ts +0 -9
- package/dist/health/checks/DatabaseCheck.d.ts +2 -17
- package/dist/health/checks/MemoryCheck.d.ts +3 -12
- package/dist/health/checks/RedisCheck.d.ts +1 -13
- package/dist/health/checks/StorageCheck.d.ts +2 -17
- package/dist/health/index.js +1 -1
- package/dist/health/types.d.ts +4 -24
- package/dist/{health-VWdWXRwh.js → health-DQSvUplL.js} +1 -76
- package/dist/hot-disposables-B5BXqaIH.js +167 -0
- package/dist/hot-reload/hot-disposables.d.ts +22 -74
- package/dist/hot-reload/testing.d.ts +4 -9
- package/dist/http/Application.d.ts +62 -208
- package/dist/http/FormRequest.d.ts +4 -55
- package/dist/http/dev-assets.d.ts +16 -18
- package/dist/http/dev-banner.d.ts +2 -5
- package/dist/http/inertia-assets.d.ts +3 -6
- package/dist/http/middleware/capabilities.d.ts +27 -50
- package/dist/http/middleware/cors.d.ts +4 -29
- package/dist/http/middleware/csp.d.ts +2 -25
- package/dist/http/middleware/csrf.d.ts +20 -95
- package/dist/http/middleware/detect-locale.d.ts +7 -27
- package/dist/http/middleware/force-https.d.ts +6 -24
- package/dist/http/middleware/host-authorization.d.ts +2 -12
- package/dist/http/middleware/loopback-guard.d.ts +15 -33
- package/dist/http/middleware/rate-limit.d.ts +29 -126
- package/dist/http/middleware/redirect-safety.d.ts +2 -20
- package/dist/http/middleware/request-id.d.ts +1 -14
- package/dist/http/middleware/request-logging.d.ts +2 -13
- package/dist/http/middleware/response-headers.d.ts +5 -13
- package/dist/http/middleware/security-headers.d.ts +2 -16
- package/dist/http/middleware/session.d.ts +15 -34
- package/dist/http/middleware/validation-errors-cookie.d.ts +7 -18
- package/dist/http/middleware/validation.d.ts +8 -63
- package/dist/http/public-assets.d.ts +14 -0
- package/dist/http/request.d.ts +49 -48
- package/dist/http/resources/CursorPaginator.d.ts +5 -64
- package/dist/http/resources/Paginator.d.ts +7 -84
- package/dist/http/resources/Resource.d.ts +9 -65
- package/dist/http/resources/ResourceCollection.d.ts +5 -39
- package/dist/http/resources/types.d.ts +10 -30
- package/dist/http/static-documents.d.ts +21 -0
- package/dist/http/validation/Validator.d.ts +25 -85
- package/dist/http/validation/rules.d.ts +48 -147
- package/dist/http/validation/types.d.ts +16 -61
- package/dist/http/vite-assets.d.ts +5 -28
- package/dist/http/vite-dev-server.d.ts +6 -9
- package/dist/http/vite-manifest.d.ts +19 -33
- package/dist/i18n/I18nManager.d.ts +12 -78
- package/dist/i18n/Translator.d.ts +3 -54
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/loaders/JsonLoader.d.ts +4 -31
- package/dist/i18n/loaders/MemoryLoader.d.ts +1 -21
- package/dist/i18n/pluralization.d.ts +4 -13
- package/dist/i18n/types.d.ts +17 -69
- package/dist/{i18n-mcWi7LCd.js → i18n-Cg1aajRP.js} +31 -225
- package/dist/index.d.ts +13 -4
- package/dist/index.js +1036 -3080
- package/dist/internal/agent-preflight.d.ts +9 -21
- package/dist/internal/request.d.ts +10 -17
- package/dist/internal/request.js +2 -2
- package/dist/internal/route-path.d.ts +9 -21
- package/dist/internal/route-path.js +9 -21
- package/dist/internal/zod-compat.d.ts +55 -122
- package/dist/internal/zod-compat.js +39 -70
- package/dist/internal/zod-json-schema.d.ts +18 -54
- package/dist/internal/zod-json-schema.js +46 -123
- package/dist/jsx-runtime.d.ts +3 -8
- package/dist/lambda/index.d.ts +17 -79
- package/dist/lambda/index.js +11 -59
- package/dist/logging/LogManager.d.ts +1 -51
- package/dist/logging/Logger.d.ts +8 -47
- package/dist/logging/channels/ConsoleChannel.d.ts +1 -3
- package/dist/logging/channels/DailyFileChannel.d.ts +1 -5
- package/dist/logging/channels/FileChannel.d.ts +1 -3
- package/dist/logging/daily-file-path.d.ts +15 -0
- package/dist/logging/index.d.ts +1 -0
- package/dist/logging/index.js +2 -2
- package/dist/logging/types.d.ts +13 -45
- package/dist/{logging-CPaRMuPP.js → logging-zOY1XCtq.js} +83 -129
- package/dist/{loopback-guard-D0Kc7-xc.js → loopback-guard-DT9gHF0F.js} +41 -92
- package/dist/mail/Mail.d.ts +10 -106
- package/dist/mail/MailManager.d.ts +2 -60
- package/dist/mail/index.js +1 -1
- package/dist/mail/transports/LogTransport.d.ts +1 -4
- package/dist/mail/transports/MemoryTransport.d.ts +1 -63
- package/dist/mail/transports/ResendTransport.d.ts +1 -23
- package/dist/mail/transports/SmtpTransport.d.ts +1 -31
- package/dist/mail/types.d.ts +28 -150
- package/dist/{mail-DfEfSQEr.js → mail-76DWy9lj.js} +31 -289
- package/dist/mcp/McpServiceProvider.d.ts +4 -10
- package/dist/mcp/create-mcp-server.d.ts +25 -57
- package/dist/mcp/endpoint.d.ts +12 -36
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Controller.d.ts +46 -253
- package/dist/mvc/Router.d.ts +50 -129
- package/dist/mvc/inertia/InertiaEngine.d.ts +18 -48
- package/dist/mvc/inertia/shared.d.ts +6 -19
- package/dist/mvc/mount-route.d.ts +2 -6
- package/dist/mvc/view.d.ts +1 -2
- package/dist/notifications/Notification.d.ts +8 -75
- package/dist/notifications/NotificationManager.d.ts +15 -88
- package/dist/notifications/channels/DatabaseChannel.d.ts +1 -41
- package/dist/notifications/channels/MailChannel.d.ts +2 -31
- package/dist/notifications/channels/MemoryChannel.d.ts +2 -62
- package/dist/notifications/channels/SlackChannel.d.ts +3 -48
- package/dist/notifications/index.js +1 -1
- package/dist/notifications/notifiable-type.d.ts +3 -6
- package/dist/notifications/registry.d.ts +8 -27
- package/dist/notifications/types.d.ts +16 -53
- package/dist/{notifications-BGqmUNZ8.js → notifications-okWFs9ly.js} +37 -335
- package/dist/providers/AuthServiceProvider.d.ts +1 -3
- package/dist/providers/AuthorizationServiceProvider.d.ts +2 -3
- package/dist/providers/BroadcastServiceProvider.d.ts +1 -3
- package/dist/providers/CacheServiceProvider.d.ts +1 -3
- package/dist/providers/EncryptionServiceProvider.d.ts +1 -3
- package/dist/providers/ErrorServiceProvider.d.ts +1 -4
- package/dist/providers/EventServiceProvider.d.ts +1 -3
- package/dist/providers/HealthServiceProvider.d.ts +1 -3
- package/dist/providers/I18nServiceProvider.d.ts +6 -10
- package/dist/providers/InertiaServiceProvider.d.ts +1 -4
- package/dist/providers/LogServiceProvider.d.ts +1 -3
- package/dist/providers/MailServiceProvider.d.ts +1 -3
- package/dist/providers/NotificationServiceProvider.d.ts +1 -3
- package/dist/providers/OAuthServiceProvider.d.ts +1 -3
- package/dist/providers/QueueServiceProvider.d.ts +1 -3
- package/dist/providers/SchedulingServiceProvider.d.ts +1 -3
- package/dist/providers/StorageServiceProvider.d.ts +1 -3
- package/dist/queue/FailedJobReporter.d.ts +1 -24
- package/dist/queue/Job.d.ts +12 -99
- package/dist/queue/QueueManager.d.ts +6 -57
- package/dist/queue/Worker.d.ts +4 -65
- package/dist/queue/drivers/MemoryDriver.d.ts +3 -44
- package/dist/queue/drivers/RedisDriver.d.ts +7 -65
- package/dist/queue/drivers/SqsDriver.d.ts +6 -57
- package/dist/queue/drivers/SyncDriver.d.ts +10 -13
- package/dist/queue/index.js +2 -2
- package/dist/queue/types.d.ts +10 -92
- package/dist/{queue-CXrRK85G.js → queue-CcXCjuJI.js} +32 -260
- package/dist/redis/RedisApiTokenStore.d.ts +4 -56
- package/dist/redis/RedisEmailVerificationStore.d.ts +4 -37
- package/dist/redis/RedisOAuthStateStore.d.ts +2 -10
- package/dist/redis/RedisPasswordResetStore.d.ts +4 -37
- package/dist/redis/RedisRateLimitStore.d.ts +16 -49
- package/dist/redis/RedisSessionStore.d.ts +3 -44
- package/dist/redis/client.d.ts +2 -32
- package/dist/redis/index.js +47 -232
- package/dist/redis/redis-values.d.ts +6 -12
- package/dist/redis/scan-keys.d.ts +1 -4
- package/dist/request-CLOYytGP.js +68 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +108 -74
- package/dist/scheduling/CronParser.d.ts +0 -29
- package/dist/scheduling/Schedule.d.ts +1 -153
- package/dist/scheduling/ScheduledTask.d.ts +0 -31
- package/dist/scheduling/Scheduler.d.ts +0 -70
- package/dist/scheduling/index.js +1 -1
- package/dist/scheduling/types.d.ts +4 -65
- package/dist/{scheduling-CPiEdtQd.js → scheduling-C6tcOtUl.js} +2 -287
- package/dist/storage/StorageManager.d.ts +0 -48
- package/dist/storage/drivers/LocalDriver.d.ts +1 -25
- package/dist/storage/drivers/MemoryDriver.d.ts +5 -35
- package/dist/storage/drivers/S3Driver.d.ts +6 -36
- package/dist/storage/drivers/s3-acl.d.ts +5 -10
- package/dist/storage/index.js +1 -1
- package/dist/storage/types.d.ts +27 -265
- package/dist/{storage-TLD9t0Q2.js → storage-BB59f07j.js} +17 -157
- package/dist/support/contained-path.d.ts +10 -20
- package/dist/support/error-polyfill.d.ts +4 -6
- package/dist/support/expiry.d.ts +17 -33
- package/dist/support/expiry.js +17 -33
- package/dist/support/import-map.d.ts +3 -7
- package/dist/support/inertia-defaults.d.ts +5 -10
- package/dist/support/redirect-target.d.ts +4 -6
- package/dist/support/stack-frames.d.ts +11 -50
- package/dist/support/trim-slashes.d.ts +4 -7
- package/dist/support/warn-once.d.ts +2 -6
- package/dist/{trim-slashes-ZJ_VsY5s.js → trim-slashes-BLY9hKAa.js} +4 -7
- package/dist/{vite-manifest-BGfWbPYp.js → vite-manifest-CTQp-SOo.js} +34 -58
- package/package.json +6 -2
- package/dist/client-Dd7vLcqp.js +0 -27
- package/dist/context-DoD0c7J_.js +0 -26
- package/dist/endpoint-D-20PiHY.js +0 -46
- package/dist/hot-disposables-WsTX2ySN.js +0 -281
- package/dist/request-CRVuIiQr.js +0 -78
package/dist/database/types.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Seeder class interface.
|
|
3
|
-
*
|
|
4
2
|
* @deprecated The constructor shape `BaseSeeder` and `SeederRunner` expect.
|
|
5
3
|
* Write seeders with `defineSeeder` from `@guren/core` instead. Deprecated in
|
|
6
4
|
* 2.9.0, removed in 3.0.0.
|
|
@@ -9,8 +7,6 @@ export interface SeederClass {
|
|
|
9
7
|
new (): Seeder;
|
|
10
8
|
}
|
|
11
9
|
/**
|
|
12
|
-
* Abstract seeder interface.
|
|
13
|
-
*
|
|
14
10
|
* Exported from the package root as `SeederInterface`.
|
|
15
11
|
*
|
|
16
12
|
* @deprecated The no-context `run()` shape `BaseSeeder` imposes. Write seeders
|
|
@@ -20,15 +16,9 @@ export interface SeederClass {
|
|
|
20
16
|
export interface Seeder {
|
|
21
17
|
run(): Promise<void>;
|
|
22
18
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Factory class interface.
|
|
25
|
-
*/
|
|
26
19
|
export interface FactoryClass<T> {
|
|
27
20
|
new (): Factory<T>;
|
|
28
21
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Abstract factory interface.
|
|
31
|
-
*/
|
|
32
22
|
export interface Factory<T> {
|
|
33
23
|
definition(): Partial<T>;
|
|
34
24
|
make(overrides?: Partial<T>): T;
|
|
@@ -37,27 +27,16 @@ export interface Factory<T> {
|
|
|
37
27
|
createMany(count: number, overrides?: Partial<T>): Promise<T[]>;
|
|
38
28
|
}
|
|
39
29
|
/**
|
|
40
|
-
* Seeder runner options.
|
|
41
|
-
*
|
|
42
30
|
* @deprecated Options for `SeederRunner`, which no Guren command reaches.
|
|
43
31
|
* Write seeders with `defineSeeder` from `@guren/core` and run them with
|
|
44
32
|
* `db:seed`. Deprecated in 2.9.0, removed in 3.0.0.
|
|
45
33
|
*/
|
|
46
34
|
export interface SeederRunnerOptions {
|
|
47
|
-
/**
|
|
48
|
-
* Path to seeders directory.
|
|
49
|
-
*/
|
|
50
35
|
seedersPath?: string;
|
|
51
|
-
/**
|
|
52
|
-
* Default seeder class name.
|
|
53
|
-
*/
|
|
36
|
+
/** Default seeder class name. */
|
|
54
37
|
defaultSeeder?: string;
|
|
55
|
-
/**
|
|
56
|
-
* Force run in production.
|
|
57
|
-
*/
|
|
38
|
+
/** Force run in production. */
|
|
58
39
|
force?: boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Silent mode (no console output).
|
|
61
|
-
*/
|
|
40
|
+
/** No console output. */
|
|
62
41
|
silent?: boolean;
|
|
63
42
|
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Options for configuring the auto-discovery engine.
|
|
3
|
-
*/
|
|
4
1
|
export interface DiscoveryOptions {
|
|
5
2
|
/** Base path for scanning. Defaults to `process.cwd()`. */
|
|
6
3
|
basePath?: string;
|
|
@@ -13,109 +10,40 @@ export interface DiscoveryOptions {
|
|
|
13
10
|
/** Whether to discover events in `app/Events/`. Defaults to `true`. */
|
|
14
11
|
events?: boolean;
|
|
15
12
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Result of the auto-discovery scan.
|
|
18
|
-
*/
|
|
19
13
|
export interface DiscoveryResult {
|
|
20
|
-
/** Discovered service provider classes. */
|
|
21
14
|
providers: Array<new (...args: unknown[]) => unknown>;
|
|
22
|
-
/** Discovered event listeners with their associated event name. */
|
|
23
15
|
listeners: Array<{
|
|
24
16
|
event: string;
|
|
25
17
|
listener: new () => unknown;
|
|
26
18
|
}>;
|
|
27
|
-
/** Discovered job classes. */
|
|
28
19
|
jobs: Array<new () => unknown>;
|
|
29
|
-
/** Discovered event classes. */
|
|
30
20
|
events: Array<new () => unknown>;
|
|
31
21
|
}
|
|
32
22
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* `defineModule` lists for modules — which is what `guren check` verifies
|
|
39
|
-
* and what bundle-deploy targets (Workers, Vercel, Lambda) require, since a
|
|
40
|
-
* runtime directory scan finds nothing in a bundle. A caller that wants
|
|
41
|
-
* discovery runs the scan itself and feeds each result into the matching
|
|
42
|
-
* registry, as the example below does.
|
|
43
|
-
*
|
|
44
|
-
* Uses `Bun.Glob` to scan directories and dynamic `import()` to load modules.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* const discovery = new AutoDiscovery({ basePath: '/app' })
|
|
49
|
-
* const result = await discovery.discover()
|
|
50
|
-
*
|
|
51
|
-
* // Register discovered providers
|
|
52
|
-
* for (const ProviderClass of result.providers) {
|
|
53
|
-
* providerManager.register(ProviderClass)
|
|
54
|
-
* }
|
|
55
|
-
*
|
|
56
|
-
* // Register discovered listeners
|
|
57
|
-
* for (const { event, listener } of result.listeners) {
|
|
58
|
-
* eventManager.listen(event, listener)
|
|
59
|
-
* }
|
|
60
|
-
* ```
|
|
23
|
+
* Scans application directories for providers, listeners, jobs and events via
|
|
24
|
+
* `Bun.Glob` and dynamic `import()`. Standalone by design: nothing in
|
|
25
|
+
* `Application` runs it, so registration stays explicit — what `guren check`
|
|
26
|
+
* verifies and what bundle-deploy targets (Workers, Vercel, Lambda) require,
|
|
27
|
+
* since a runtime directory scan finds nothing in a bundle.
|
|
61
28
|
*/
|
|
62
29
|
export declare class AutoDiscovery {
|
|
63
30
|
private basePath;
|
|
64
31
|
private options;
|
|
65
32
|
constructor(options?: DiscoveryOptions);
|
|
66
|
-
/**
|
|
67
|
-
* Run the discovery scan across all enabled directories.
|
|
68
|
-
*/
|
|
69
33
|
discover(): Promise<DiscoveryResult>;
|
|
70
|
-
/**
|
|
71
|
-
* Discover service providers in `app/Providers/`.
|
|
72
|
-
*
|
|
73
|
-
* A module is considered a provider if it exports a class (default or named)
|
|
74
|
-
* that has a `register` method (i.e., implements the Provider interface).
|
|
75
|
-
*/
|
|
34
|
+
/** `app/Providers/`: any exported class with a `register` method. */
|
|
76
35
|
private discoverProviders;
|
|
77
|
-
/**
|
|
78
|
-
* Discover event listeners in `app/Listeners/`.
|
|
79
|
-
*
|
|
80
|
-
* A listener class must have a `static event` property (string) that indicates
|
|
81
|
-
* which event it handles, and a `handle` method.
|
|
82
|
-
*/
|
|
36
|
+
/** `app/Listeners/`: classes with a string `static event` and a `handle` method. */
|
|
83
37
|
private discoverListeners;
|
|
84
|
-
/**
|
|
85
|
-
* Discover jobs in `app/Jobs/`.
|
|
86
|
-
*
|
|
87
|
-
* A job class must have a `handle` method.
|
|
88
|
-
*/
|
|
38
|
+
/** `app/Jobs/`: classes with a `handle` method. */
|
|
89
39
|
private discoverJobs;
|
|
90
|
-
/**
|
|
91
|
-
* Discover events in `app/Events/`.
|
|
92
|
-
*
|
|
93
|
-
* Any exported class from the Events directory is considered an event class.
|
|
94
|
-
*/
|
|
40
|
+
/** `app/Events/`: every exported class counts. */
|
|
95
41
|
private discoverEvents;
|
|
96
|
-
/**
|
|
97
|
-
* Scan a directory for TypeScript files using Bun.Glob.
|
|
98
|
-
* Returns an array of imported modules. Skips `index.ts` barrel files.
|
|
99
|
-
*/
|
|
42
|
+
/** Imports every `.ts` file in the directory, skipping `index.ts` barrels. */
|
|
100
43
|
private scanDirectory;
|
|
101
|
-
/**
|
|
102
|
-
* Extract all class constructors (functions) from a module's exports.
|
|
103
|
-
*/
|
|
104
44
|
private extractClasses;
|
|
105
|
-
/**
|
|
106
|
-
* Check if a value is a constructor function (class).
|
|
107
|
-
*/
|
|
108
45
|
private isConstructor;
|
|
109
|
-
/**
|
|
110
|
-
* Check if a class looks like a service provider (has a `register` method).
|
|
111
|
-
*/
|
|
112
46
|
private isProvider;
|
|
113
|
-
/**
|
|
114
|
-
* Get the `static event` property from a class, if it exists and is a string.
|
|
115
|
-
*/
|
|
116
47
|
private getStaticEvent;
|
|
117
|
-
/**
|
|
118
|
-
* Check if a class has a `handle` method on its prototype.
|
|
119
|
-
*/
|
|
120
48
|
private hasHandleMethod;
|
|
121
49
|
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { PATH_PARAM_PATTERN } from "./internal/route-path.js";
|
|
2
|
+
//#region src/internal/agent-preflight.ts
|
|
3
|
+
/**
|
|
4
|
+
* The wire protocol of an agent preflight (RFC 0016 §5.4), in a leaf module so
|
|
5
|
+
* `Router` (which answers one) and `agent/dispatch` (which asks) share it
|
|
6
|
+
* without importing each other and closing a cycle. Not exported from the
|
|
7
|
+
* package index: an external dispatcher goes through
|
|
8
|
+
* `BuildToolRequestOptions.preflight`, and the header spelling stays internal.
|
|
9
|
+
*/
|
|
10
|
+
/** Request header asking the route for a verdict instead of an execution. */
|
|
11
|
+
const AGENT_PREFLIGHT_HEADER = "X-Guren-Agent-Preflight";
|
|
12
|
+
/**
|
|
13
|
+
* Response header marking a body as a preflight verdict rather than the route's
|
|
14
|
+
* own output. Read by the route's `output` schema validation (which would
|
|
15
|
+
* otherwise reject the verdict as a 500) and by the MCP response mapping (which
|
|
16
|
+
* would otherwise advertise it as the tool's `structuredContent`).
|
|
17
|
+
*/
|
|
18
|
+
const AGENT_PREFLIGHT_VERDICT_HEADER = "X-Guren-Agent-Preflight-Verdict";
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/agent/dispatch.ts
|
|
21
|
+
/** How many characters of a non-JSON response body survive into the result. */
|
|
22
|
+
const TEXT_RESPONSE_CAP = 5e4;
|
|
23
|
+
/**
|
|
24
|
+
* The argument-level spelling of a preflight request (RFC 0016 §5.4), for a
|
|
25
|
+
* surface whose callers pass flat arguments rather than dispatch options. No
|
|
26
|
+
* adapter accepts it today — every surface asks through
|
|
27
|
+
* `BuildToolRequestOptions.preflight`. A surface adopting it owns the stripping:
|
|
28
|
+
* it is an instruction to the adapter, not a field of any route's contract.
|
|
29
|
+
*/
|
|
30
|
+
const PREFLIGHT_ARGUMENT = "_preflight";
|
|
31
|
+
/**
|
|
32
|
+
* The agent-facing diagnosis of a {@link ToolRequestBuildFailure}. One function
|
|
33
|
+
* rather than a string per adapter: the same tool is reachable from several
|
|
34
|
+
* surfaces, and a diagnosis that varied by surface would have an agent
|
|
35
|
+
* debugging the client instead of its own call.
|
|
36
|
+
*/
|
|
37
|
+
function describeBuildFailure(failure) {
|
|
38
|
+
if ("missing" in failure) return `Missing required path parameter(s): ${failure.missing.join(", ")}.`;
|
|
39
|
+
return `Path parameter(s) ${failure.invalidPath.join(", ")} may not be "." or ".." — a dot-segment would resolve to a different route than the one authorized.`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Rebuild the HTTP request a tool call describes. The flat argument object is
|
|
43
|
+
* taken apart along `tool.inputSources`, so a POST route's `query` keys land
|
|
44
|
+
* where `validateQuery` reads them; unadvertised keys are forwarded for the
|
|
45
|
+
* route's validator to reject. GET and HEAD force everything into the query
|
|
46
|
+
* string: `Request` refuses a body there, and a GET `body` schema is a defect.
|
|
47
|
+
*/
|
|
48
|
+
function buildToolRequest(tool, args, options = {}) {
|
|
49
|
+
const origin = options.origin ?? "http://localhost";
|
|
50
|
+
const missing = [];
|
|
51
|
+
const invalidPath = [];
|
|
52
|
+
const pathOnly = /* @__PURE__ */ new Set();
|
|
53
|
+
const path = tool.path.replace(PATH_PARAM_PATTERN, (_match, lead, name) => {
|
|
54
|
+
const value = args[name];
|
|
55
|
+
if (value === void 0) {
|
|
56
|
+
missing.push(name);
|
|
57
|
+
return `${lead}:${name}`;
|
|
58
|
+
}
|
|
59
|
+
const stringified = String(value);
|
|
60
|
+
if (stringified === "." || stringified === "..") {
|
|
61
|
+
invalidPath.push(name);
|
|
62
|
+
return `${lead}:${name}`;
|
|
63
|
+
}
|
|
64
|
+
const source = sourceOf(tool, name);
|
|
65
|
+
if (source === void 0 || source === "params" || source === "path") pathOnly.add(name);
|
|
66
|
+
return `${lead}${encodeURIComponent(stringified)}`;
|
|
67
|
+
});
|
|
68
|
+
if (missing.length > 0) return { missing };
|
|
69
|
+
if (invalidPath.length > 0) return { invalidPath };
|
|
70
|
+
const method = tool.method;
|
|
71
|
+
const bodyless = method === "GET" || method === "HEAD";
|
|
72
|
+
const query = new URLSearchParams();
|
|
73
|
+
const bodyEntries = [];
|
|
74
|
+
for (const [key, value] of Object.entries(args)) {
|
|
75
|
+
if (pathOnly.has(key) || value === void 0) continue;
|
|
76
|
+
const source = sourceOf(tool, key);
|
|
77
|
+
if (bodyless || source === "query" || source === "params" || source === "path" || tool.inputBodyNested && key !== "body") appendQueryValue(query, key, value);
|
|
78
|
+
else bodyEntries.push([key, value]);
|
|
79
|
+
}
|
|
80
|
+
const headers = new Headers({
|
|
81
|
+
Accept: "application/json",
|
|
82
|
+
"X-Guren-Agent-Surface": options.surface ?? "mcp"
|
|
83
|
+
});
|
|
84
|
+
if (options.authorization) headers.set("Authorization", options.authorization);
|
|
85
|
+
if (options.preflight) headers.set(AGENT_PREFLIGHT_HEADER, "1");
|
|
86
|
+
let body;
|
|
87
|
+
if (!bodyless) {
|
|
88
|
+
if (tool.inputBodyNested) {
|
|
89
|
+
if (Object.hasOwn(args, "body")) body = JSON.stringify(args.body);
|
|
90
|
+
} else if (bodyEntries.length > 0) body = JSON.stringify(accumulate(bodyEntries));
|
|
91
|
+
}
|
|
92
|
+
if (body !== void 0) headers.set("Content-Type", "application/json");
|
|
93
|
+
const qs = query.toString();
|
|
94
|
+
const url = `${origin}${path}${qs ? `?${qs}` : ""}`;
|
|
95
|
+
return { request: new Request(url, {
|
|
96
|
+
method,
|
|
97
|
+
headers,
|
|
98
|
+
body
|
|
99
|
+
}) };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The contract a property was declared under, or undefined if the derivation
|
|
103
|
+
* never advertised it. `Object.hasOwn` rather than a plain read: a JSON
|
|
104
|
+
* argument may legally be named `__proto__`, and `inputSources['__proto__']`
|
|
105
|
+
* would otherwise resolve to `Object.prototype`, not undefined.
|
|
106
|
+
*/
|
|
107
|
+
function sourceOf(tool, name) {
|
|
108
|
+
return Object.hasOwn(tool.inputSources, name) ? tool.inputSources[name] : void 0;
|
|
109
|
+
}
|
|
110
|
+
/** Primitives stringify; anything structured rides as JSON text. */
|
|
111
|
+
function appendQueryValue(query, key, value) {
|
|
112
|
+
if (Array.isArray(value)) {
|
|
113
|
+
for (const element of value) query.append(key, serializeQueryScalar(element));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
query.append(key, serializeQueryScalar(value));
|
|
117
|
+
}
|
|
118
|
+
function serializeQueryScalar(value) {
|
|
119
|
+
if (value === null || typeof value !== "object") return String(value);
|
|
120
|
+
return JSON.stringify(value);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Null-prototype accumulator, spread back to plain: a JSON argument may
|
|
124
|
+
* legally be named `__proto__`, and assigning that key on `{}` invokes the
|
|
125
|
+
* prototype setter instead of defining the property — the same rule the
|
|
126
|
+
* derivation and the redaction walk apply.
|
|
127
|
+
*/
|
|
128
|
+
function accumulate(entries) {
|
|
129
|
+
const record = Object.create(null);
|
|
130
|
+
for (const [key, value] of entries) record[key] = value;
|
|
131
|
+
return { ...record };
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Whether the tool advertises an object output schema — the only kind MCP
|
|
135
|
+
* lists, and so the only kind obliging a success result to carry
|
|
136
|
+
* `structuredContent`. `describeTool` and `mapToolResponse` must agree on this
|
|
137
|
+
* exact predicate, or one advertises a schema the other cannot satisfy.
|
|
138
|
+
*/
|
|
139
|
+
function advertisesStructuredOutput(tool) {
|
|
140
|
+
return tool.outputSchema?.type === "object";
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Map the application's response onto an MCP tool result (RFC 0016 §3.4): 2xx
|
|
144
|
+
* JSON → text (+ `structuredContent` for an object `outputSchema`); Inertia page
|
|
145
|
+
* JSON → `page.props`; 204/3xx → status line, not an error; 4xx/5xx → `isError`
|
|
146
|
+
* with the handler's body; other → capped text. An object-`outputSchema` success
|
|
147
|
+
* lacking an object becomes `isError`: the SDK client rejects it after the route ran.
|
|
148
|
+
*/
|
|
149
|
+
async function mapToolResponse(tool, response) {
|
|
150
|
+
const status = response.status;
|
|
151
|
+
const structured = advertisesStructuredOutput(tool);
|
|
152
|
+
if (status === 204 || status >= 300 && status < 400) {
|
|
153
|
+
const location = response.headers.get("Location");
|
|
154
|
+
const text = location ? `HTTP ${status} (Location: ${location})` : `HTTP ${status}`;
|
|
155
|
+
if (structured) return inconsistentOutput(tool, text, status);
|
|
156
|
+
return {
|
|
157
|
+
content: [{
|
|
158
|
+
type: "text",
|
|
159
|
+
text
|
|
160
|
+
}],
|
|
161
|
+
status
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const raw = await response.text();
|
|
165
|
+
if (status >= 400) return {
|
|
166
|
+
content: [{
|
|
167
|
+
type: "text",
|
|
168
|
+
text: raw || `HTTP ${status}`
|
|
169
|
+
}],
|
|
170
|
+
isError: true,
|
|
171
|
+
status
|
|
172
|
+
};
|
|
173
|
+
const parsed = parseJsonBody(response, raw);
|
|
174
|
+
if (parsed === void 0) {
|
|
175
|
+
const text = raw.length > TEXT_RESPONSE_CAP ? `${raw.slice(0, TEXT_RESPONSE_CAP)}… [truncated ${raw.length - TEXT_RESPONSE_CAP} characters]` : raw;
|
|
176
|
+
if (structured) return inconsistentOutput(tool, `a non-JSON body (${text.slice(0, 200)})`, status);
|
|
177
|
+
return {
|
|
178
|
+
content: [{
|
|
179
|
+
type: "text",
|
|
180
|
+
text
|
|
181
|
+
}],
|
|
182
|
+
status
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
if (response.headers.get("X-Guren-Agent-Preflight-Verdict") !== null) return {
|
|
186
|
+
content: [{
|
|
187
|
+
type: "text",
|
|
188
|
+
text: JSON.stringify(parsed)
|
|
189
|
+
}],
|
|
190
|
+
status,
|
|
191
|
+
preflightVerdict: true
|
|
192
|
+
};
|
|
193
|
+
const payload = unwrapInertiaProps(tool, response, parsed);
|
|
194
|
+
if (structured && !isRecord(payload)) return inconsistentOutput(tool, `a ${Array.isArray(payload) ? "JSON array" : typeof payload} body`, status);
|
|
195
|
+
const outcome = {
|
|
196
|
+
content: [{
|
|
197
|
+
type: "text",
|
|
198
|
+
text: JSON.stringify(payload)
|
|
199
|
+
}],
|
|
200
|
+
status
|
|
201
|
+
};
|
|
202
|
+
if (structured && isRecord(payload)) outcome.structuredContent = payload;
|
|
203
|
+
return outcome;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* A success response that cannot satisfy the tool's advertised object output
|
|
207
|
+
* schema. An error result is the honest signal that the route and its declared
|
|
208
|
+
* `output` disagree, and it sidesteps the SDK's structuredContent requirement.
|
|
209
|
+
*/
|
|
210
|
+
function inconsistentOutput(tool, detail, status) {
|
|
211
|
+
return {
|
|
212
|
+
content: [{
|
|
213
|
+
type: "text",
|
|
214
|
+
text: `The tool "${tool.toolName}" advertises an output schema, but the route returned ${detail} (HTTP ${status}) — no structured result could be produced.`
|
|
215
|
+
}],
|
|
216
|
+
isError: true,
|
|
217
|
+
status
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function parseJsonBody(response, raw) {
|
|
221
|
+
if (!(response.headers.get("Content-Type") ?? "").includes("json") || raw === "") return void 0;
|
|
222
|
+
try {
|
|
223
|
+
return JSON.parse(raw);
|
|
224
|
+
} catch {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function unwrapInertiaProps(tool, response, parsed) {
|
|
229
|
+
if (tool.outputSchema) return parsed;
|
|
230
|
+
if (response.headers.get("X-Inertia") !== "true") return parsed;
|
|
231
|
+
if (!isRecord(parsed) || !("props" in parsed)) return parsed;
|
|
232
|
+
return parsed.props;
|
|
233
|
+
}
|
|
234
|
+
function isRecord(value) {
|
|
235
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
236
|
+
}
|
|
237
|
+
//#endregion
|
|
238
|
+
export { mapToolResponse as a, describeBuildFailure as i, advertisesStructuredOutput as n, AGENT_PREFLIGHT_HEADER as o, buildToolRequest as r, AGENT_PREFLIGHT_VERDICT_HEADER as s, PREFLIGHT_ARGUMENT as t };
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { ServiceProvider } from '../container/ServiceProvider.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* interactive relation graph. Only active while `isDocsViewerEnabled()`
|
|
6
|
-
* holds. All routes are GET; the whole bundle ships as one payload, so
|
|
7
|
-
* no route takes a path parameter.
|
|
3
|
+
* The docs viewer (RFC 0005) at /_guren/docs: a read-only, loopback-guarded UI
|
|
4
|
+
* over the OKF docs bundle, mounted only while `isDocsViewerEnabled()` holds.
|
|
8
5
|
*/
|
|
9
6
|
export declare class DocsViewerServiceProvider extends ServiceProvider {
|
|
10
7
|
register(): void;
|
|
@@ -8,17 +8,11 @@
|
|
|
8
8
|
import type { MiddlewareHandler } from 'hono';
|
|
9
9
|
export declare const DOCS_VIEWER_PATH = "/_guren/docs";
|
|
10
10
|
/**
|
|
11
|
-
* Whether the docs viewer is mounted
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* The environment reads use plain member access so that the deploy plugins'
|
|
18
|
-
* `--define 'process.env.NODE_ENV="production"'` settles the production
|
|
19
|
-
* branch at bundle time; an optional chain is a different expression and no
|
|
20
|
-
* define matches it. See `mcp/endpoint.ts` for the full reasoning — and do
|
|
21
|
-
* not add optional chaining back, a test reads this file for it.
|
|
11
|
+
* Whether the docs viewer is mounted: opt-in via `GUREN_DOCS=1`, never in
|
|
12
|
+
* production — it renders the project's private knowledge bundle. Plain
|
|
13
|
+
* `process.env.X` access on purpose: the deploy plugins' `--define
|
|
14
|
+
* 'process.env.NODE_ENV="production"'` settles that branch at bundle time, and
|
|
15
|
+
* an optional chain is a different expression no define matches (`mcp/endpoint.ts`; a test greps this file).
|
|
22
16
|
*/
|
|
23
17
|
export declare function isDocsViewerEnabled(): boolean;
|
|
24
18
|
/**
|
|
@@ -1,96 +1,30 @@
|
|
|
1
1
|
import type { EncrypterConfig, EncryptOptions, DecryptOptions, EncryptedPayload } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Encrypter for secure data encryption using AES.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* const encrypter = new Encrypter({ key: 'base64-encoded-32-byte-key' })
|
|
8
|
-
*
|
|
9
|
-
* // Encrypt
|
|
10
|
-
* const encrypted = encrypter.encrypt({ userId: 123, role: 'admin' })
|
|
11
|
-
*
|
|
12
|
-
* // Decrypt
|
|
13
|
-
* const data = encrypter.decrypt(encrypted)
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
2
|
+
/** AES encryption over a base64-encoded 32-byte key. */
|
|
16
3
|
export declare class Encrypter {
|
|
17
|
-
/**
|
|
18
|
-
* Encryption key.
|
|
19
|
-
*/
|
|
20
4
|
protected key: Buffer;
|
|
21
5
|
protected previousKeys: Buffer[];
|
|
22
|
-
/**
|
|
23
|
-
* Cipher algorithm.
|
|
24
|
-
*/
|
|
25
6
|
protected cipher: 'aes-256-gcm' | 'aes-256-cbc';
|
|
26
7
|
constructor(config: EncrypterConfig);
|
|
27
|
-
/**
|
|
28
|
-
* Encrypt a value.
|
|
29
|
-
*/
|
|
30
8
|
encrypt(value: unknown, options?: EncryptOptions): string;
|
|
31
|
-
/**
|
|
32
|
-
* Decrypt a value.
|
|
33
|
-
*/
|
|
34
9
|
decrypt<T = unknown>(payload: string, options?: DecryptOptions): T;
|
|
35
|
-
/**
|
|
36
|
-
* Encrypt a string (no serialization).
|
|
37
|
-
*/
|
|
38
10
|
encryptString(value: string): string;
|
|
39
|
-
/**
|
|
40
|
-
* Decrypt a string (no deserialization).
|
|
41
|
-
*/
|
|
42
11
|
decryptString(payload: string): string;
|
|
43
|
-
/**
|
|
44
|
-
* Encrypt using AES-256-GCM.
|
|
45
|
-
*/
|
|
46
12
|
protected encryptGcm(data: string): string;
|
|
47
|
-
/**
|
|
48
|
-
* Decrypt using AES-256-GCM.
|
|
49
|
-
*/
|
|
50
13
|
protected decryptGcm(payload: EncryptedPayload): string;
|
|
51
|
-
/**
|
|
52
|
-
* Encrypt using AES-256-CBC with HMAC.
|
|
53
|
-
*/
|
|
54
14
|
protected encryptCbc(data: string): string;
|
|
55
|
-
/**
|
|
56
|
-
* Decrypt using AES-256-CBC with HMAC verification.
|
|
57
|
-
*/
|
|
58
15
|
protected decryptCbc(payload: EncryptedPayload): string;
|
|
59
|
-
/**
|
|
60
|
-
* Create HMAC for CBC mode.
|
|
61
|
-
*/
|
|
62
16
|
protected createMac(iv: Buffer, encrypted: Buffer, key?: Buffer): string;
|
|
63
|
-
/**
|
|
64
|
-
* Constant-time string comparison.
|
|
65
|
-
*/
|
|
17
|
+
/** Constant-time comparison. */
|
|
66
18
|
protected secureCompare(a: string, b: string): boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Get the encryption key (base64).
|
|
69
|
-
*/
|
|
19
|
+
/** The encryption key, base64-encoded. */
|
|
70
20
|
getKey(): string;
|
|
71
21
|
protected tryDecryptWithKeys(run: (key: Buffer) => string): string;
|
|
72
22
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Generate a random encryption key.
|
|
75
|
-
*/
|
|
76
23
|
export declare function generateKey(): string;
|
|
77
|
-
/**
|
|
78
|
-
* Create an encrypter instance.
|
|
79
|
-
*/
|
|
80
24
|
export declare function createEncrypter(config: EncrypterConfig): Encrypter;
|
|
81
|
-
/**
|
|
82
|
-
* Set the global encrypter.
|
|
83
|
-
*/
|
|
84
25
|
export declare function setEncrypter(encrypter: Encrypter): void;
|
|
85
|
-
/**
|
|
86
|
-
* Get the global encrypter.
|
|
87
|
-
*/
|
|
88
26
|
export declare function getEncrypter(): Encrypter;
|
|
89
|
-
/**
|
|
90
|
-
* Encrypt a value using the global encrypter.
|
|
91
|
-
*/
|
|
27
|
+
/** Encrypt with the global encrypter. */
|
|
92
28
|
export declare function encrypt(value: unknown, options?: EncryptOptions): string;
|
|
93
|
-
/**
|
|
94
|
-
* Decrypt a value using the global encrypter.
|
|
95
|
-
*/
|
|
29
|
+
/** Decrypt with the global encrypter. */
|
|
96
30
|
export declare function decrypt<T = unknown>(payload: string, options?: DecryptOptions): T;
|
|
@@ -1,69 +1,19 @@
|
|
|
1
1
|
import type { HashAlgorithm, HmacOptions, PasswordHashOptions } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Hash a value using the specified algorithm.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* hash('hello') // SHA-256 by default
|
|
8
|
-
* hash('hello', 'sha512')
|
|
9
|
-
* hash('hello', 'md5')
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
2
|
+
/** Hash a value; SHA-256 by default. */
|
|
12
3
|
export declare function hash(value: string | Buffer, algorithm?: HashAlgorithm, encoding?: 'hex' | 'base64'): string;
|
|
13
|
-
/**
|
|
14
|
-
* Create an HMAC signature.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* hmac('message', 'secret-key')
|
|
19
|
-
* hmac('message', 'secret-key', { algorithm: 'sha512' })
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
4
|
+
/** Create an HMAC signature; SHA-256 by default. */
|
|
22
5
|
export declare function hmac(value: string | Buffer, key: string | Buffer, options?: HmacOptions): string;
|
|
23
|
-
/**
|
|
24
|
-
* Verify an HMAC signature.
|
|
25
|
-
*/
|
|
26
6
|
export declare function verifyHmac(value: string | Buffer, signature: string, key: string | Buffer, options?: HmacOptions): boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Create a SHA-256 hash.
|
|
29
|
-
*/
|
|
30
7
|
export declare function sha256(value: string | Buffer): string;
|
|
31
|
-
/**
|
|
32
|
-
* Create a SHA-512 hash.
|
|
33
|
-
*/
|
|
34
8
|
export declare function sha512(value: string | Buffer): string;
|
|
35
|
-
/**
|
|
36
|
-
* Create an MD5 hash (not secure, use only for checksums).
|
|
37
|
-
*/
|
|
9
|
+
/** Not secure — checksums only. */
|
|
38
10
|
export declare function md5(value: string | Buffer): string;
|
|
39
|
-
/**
|
|
40
|
-
* Hash a password using scrypt.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* const hashed = await hashPassword('mypassword')
|
|
45
|
-
* // Returns: $scrypt$N=16384,r=8,p=1$salt$hash
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
11
|
+
/** scrypt, returning `$scrypt$N=16384,r=8,p=1$salt$hash`. */
|
|
48
12
|
export declare function hashPassword(password: string, options?: PasswordHashOptions): Promise<string>;
|
|
49
|
-
/**
|
|
50
|
-
* Verify a password against a hash.
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```typescript
|
|
54
|
-
* const isValid = await verifyPassword('mypassword', hashedPassword)
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
13
|
+
/** Verify a password against a hash. */
|
|
57
14
|
export declare function verifyPassword(password: string, hash: string): Promise<boolean>;
|
|
58
|
-
/**
|
|
59
|
-
* Check if a password needs to be rehashed (parameters changed).
|
|
60
|
-
*/
|
|
15
|
+
/** Whether the hash was made with different parameters than `options`. */
|
|
61
16
|
export declare function needsRehash(hash: string, options?: PasswordHashOptions): boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Constant-time string comparison.
|
|
64
|
-
*/
|
|
17
|
+
/** Constant-time comparison. */
|
|
65
18
|
export declare function secureCompare(a: string, b: string): boolean;
|
|
66
|
-
/**
|
|
67
|
-
* Check if a value matches a hash.
|
|
68
|
-
*/
|
|
69
19
|
export declare function check(value: string | Buffer, hash: string, algorithm?: HashAlgorithm): boolean;
|