@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/{DocsViewerServiceProvider-qFCaeiUv.js → DocsViewerServiceProvider-D2cuVgtN.js}
RENAMED
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
import { r as ServiceProvider } from "./loopback-guard-
|
|
2
|
-
import { n as createDocsViewerAccessGuard, r as isDocsViewerEnabled, t as DOCS_VIEWER_PATH } from "./endpoint-
|
|
1
|
+
import { r as ServiceProvider } from "./loopback-guard-DT9gHF0F.js";
|
|
2
|
+
import { n as createDocsViewerAccessGuard, r as isDocsViewerEnabled, t as DOCS_VIEWER_PATH } from "./endpoint-BXipU2Jj.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
5
|
import { readFile } from "node:fs/promises";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
//#region src/docs-viewer/DocsViewerServiceProvider.ts
|
|
8
8
|
/**
|
|
9
|
-
* How long a built `data.json` payload answers
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* unchanged — the build reads and renders every doc, which is real work
|
|
13
|
-
* inside the process serving the app under development.
|
|
9
|
+
* How long a built `data.json` payload answers requests. Longer than the UI's
|
|
10
|
+
* poll interval, so a visible tab does not re-read and re-render every doc
|
|
11
|
+
* inside the dev server every few seconds only to find the ETag unchanged.
|
|
14
12
|
*/
|
|
15
13
|
const DATA_CACHE_TTL_MS = 15e3;
|
|
16
14
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* interactive relation graph. Only active while `isDocsViewerEnabled()`
|
|
20
|
-
* holds. All routes are GET; the whole bundle ships as one payload, so
|
|
21
|
-
* no route takes a path parameter.
|
|
15
|
+
* The docs viewer (RFC 0005) at /_guren/docs: a read-only, loopback-guarded UI
|
|
16
|
+
* over the OKF docs bundle, mounted only while `isDocsViewerEnabled()` holds.
|
|
22
17
|
*/
|
|
23
18
|
var DocsViewerServiceProvider = class extends ServiceProvider {
|
|
24
19
|
register() {}
|
|
@@ -2,65 +2,29 @@ import { createHash, createHmac, randomBytes, scrypt, timingSafeEqual } from "cr
|
|
|
2
2
|
import { promisify } from "util";
|
|
3
3
|
//#region src/encryption/Hash.ts
|
|
4
4
|
const scryptAsync = promisify(scrypt);
|
|
5
|
-
/**
|
|
6
|
-
* Hash a value using the specified algorithm.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* hash('hello') // SHA-256 by default
|
|
11
|
-
* hash('hello', 'sha512')
|
|
12
|
-
* hash('hello', 'md5')
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
5
|
+
/** Hash a value; SHA-256 by default. */
|
|
15
6
|
function hash(value, algorithm = "sha256", encoding = "hex") {
|
|
16
7
|
return createHash(algorithm).update(value).digest(encoding);
|
|
17
8
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Create an HMAC signature.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* hmac('message', 'secret-key')
|
|
24
|
-
* hmac('message', 'secret-key', { algorithm: 'sha512' })
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
9
|
+
/** Create an HMAC signature; SHA-256 by default. */
|
|
27
10
|
function hmac(value, key, options = {}) {
|
|
28
11
|
const { algorithm = "sha256", encoding = "hex" } = options;
|
|
29
12
|
return createHmac(algorithm, key).update(value).digest(encoding);
|
|
30
13
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Verify an HMAC signature.
|
|
33
|
-
*/
|
|
34
14
|
function verifyHmac(value, signature, key, options = {}) {
|
|
35
15
|
return secureCompare(signature, hmac(value, key, options));
|
|
36
16
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Create a SHA-256 hash.
|
|
39
|
-
*/
|
|
40
17
|
function sha256(value) {
|
|
41
18
|
return hash(value, "sha256");
|
|
42
19
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Create a SHA-512 hash.
|
|
45
|
-
*/
|
|
46
20
|
function sha512(value) {
|
|
47
21
|
return hash(value, "sha512");
|
|
48
22
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Create an MD5 hash (not secure, use only for checksums).
|
|
51
|
-
*/
|
|
23
|
+
/** Not secure — checksums only. */
|
|
52
24
|
function md5(value) {
|
|
53
25
|
return hash(value, "md5");
|
|
54
26
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Hash a password using scrypt.
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```typescript
|
|
60
|
-
* const hashed = await hashPassword('mypassword')
|
|
61
|
-
* // Returns: $scrypt$N=16384,r=8,p=1$salt$hash
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
27
|
+
/** scrypt, returning `$scrypt$N=16384,r=8,p=1$salt$hash`. */
|
|
64
28
|
async function hashPassword(password, options = {}) {
|
|
65
29
|
const { cost = 16384, memory = 8, saltLength = 16, keyLength = 64 } = options;
|
|
66
30
|
const salt = randomBytes(saltLength);
|
|
@@ -71,14 +35,7 @@ async function hashPassword(password, options = {}) {
|
|
|
71
35
|
});
|
|
72
36
|
return `$scrypt$${`N=${cost},r=${memory},p=1`}$${salt.toString("base64")}$${derived.toString("base64")}`;
|
|
73
37
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Verify a password against a hash.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```typescript
|
|
79
|
-
* const isValid = await verifyPassword('mypassword', hashedPassword)
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
38
|
+
/** Verify a password against a hash. */
|
|
82
39
|
async function verifyPassword(password, hash) {
|
|
83
40
|
if (!hash.startsWith("$scrypt$")) throw new Error("Invalid password hash format.");
|
|
84
41
|
const parts = hash.split("$");
|
|
@@ -91,6 +48,8 @@ async function verifyPassword(password, hash) {
|
|
|
91
48
|
}
|
|
92
49
|
const salt = Buffer.from(saltB64, "base64");
|
|
93
50
|
const expectedHash = Buffer.from(hashB64, "base64");
|
|
51
|
+
if (salt.length === 0 || expectedHash.length === 0) throw new Error("Invalid password hash format.");
|
|
52
|
+
if (!isPositiveInteger(params.N) || !isPositiveInteger(params.r) || !isPositiveInteger(params.p ?? 1)) throw new Error("Invalid password hash format.");
|
|
94
53
|
const derived = await scryptAsync(password, salt, expectedHash.length, {
|
|
95
54
|
N: params.N,
|
|
96
55
|
r: params.r,
|
|
@@ -98,9 +57,10 @@ async function verifyPassword(password, hash) {
|
|
|
98
57
|
});
|
|
99
58
|
return timingSafeEqual(derived, expectedHash);
|
|
100
59
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
60
|
+
function isPositiveInteger(value) {
|
|
61
|
+
return Number.isInteger(value) && value > 0;
|
|
62
|
+
}
|
|
63
|
+
/** Whether the hash was made with different parameters than `options`. */
|
|
104
64
|
function needsRehash(hash, options = {}) {
|
|
105
65
|
const { cost = 16384, memory = 8 } = options;
|
|
106
66
|
if (!hash.startsWith("$scrypt$")) return true;
|
|
@@ -114,18 +74,13 @@ function needsRehash(hash, options = {}) {
|
|
|
114
74
|
}
|
|
115
75
|
return params.N !== cost || params.r !== memory;
|
|
116
76
|
}
|
|
117
|
-
/**
|
|
118
|
-
* Constant-time string comparison.
|
|
119
|
-
*/
|
|
77
|
+
/** Constant-time comparison. */
|
|
120
78
|
function secureCompare(a, b) {
|
|
121
79
|
if (a.length !== b.length) return false;
|
|
122
80
|
const bufA = Buffer.from(a);
|
|
123
81
|
const bufB = Buffer.from(b);
|
|
124
82
|
return timingSafeEqual(bufA, bufB);
|
|
125
83
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Check if a value matches a hash.
|
|
128
|
-
*/
|
|
129
84
|
function check(value, hash, algorithm = "sha256") {
|
|
130
85
|
return secureCompare(createHash(algorithm).update(value).digest("hex"), hash);
|
|
131
86
|
}
|
|
@@ -1,35 +1,8 @@
|
|
|
1
1
|
//#region src/errors/HttpException.ts
|
|
2
|
-
/**
|
|
3
|
-
* Base HTTP exception class.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* // Using factory methods
|
|
8
|
-
* throw HttpException.notFound('User not found')
|
|
9
|
-
* throw HttpException.unauthorized('Invalid credentials')
|
|
10
|
-
*
|
|
11
|
-
* // Custom status code
|
|
12
|
-
* throw new HttpException(418, "I'm a teapot")
|
|
13
|
-
*
|
|
14
|
-
* // With validation errors
|
|
15
|
-
* throw HttpException.unprocessable('Validation failed', {
|
|
16
|
-
* email: ['Email is required', 'Email must be valid'],
|
|
17
|
-
* password: ['Password is too short'],
|
|
18
|
-
* })
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
2
|
+
/** Base HTTP exception class. */
|
|
21
3
|
var HttpException = class HttpException extends Error {
|
|
22
|
-
/**
|
|
23
|
-
* HTTP status code.
|
|
24
|
-
*/
|
|
25
4
|
statusCode;
|
|
26
|
-
/**
|
|
27
|
-
* Validation or field-specific errors.
|
|
28
|
-
*/
|
|
29
5
|
errors;
|
|
30
|
-
/**
|
|
31
|
-
* Additional error data.
|
|
32
|
-
*/
|
|
33
6
|
data;
|
|
34
7
|
constructor(statusCode, message, errors, data) {
|
|
35
8
|
super(message);
|
|
@@ -39,9 +12,6 @@ var HttpException = class HttpException extends Error {
|
|
|
39
12
|
this.data = data;
|
|
40
13
|
if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
|
|
41
14
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Convert to response format.
|
|
44
|
-
*/
|
|
45
15
|
toResponse(debug = false) {
|
|
46
16
|
const body = { message: this.message };
|
|
47
17
|
if (this.errors) body.errors = this.errors;
|
|
@@ -54,9 +24,6 @@ var HttpException = class HttpException extends Error {
|
|
|
54
24
|
body
|
|
55
25
|
};
|
|
56
26
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Convert to JSON.
|
|
59
|
-
*/
|
|
60
27
|
toJSON() {
|
|
61
28
|
return {
|
|
62
29
|
name: this.name,
|
|
@@ -66,93 +33,49 @@ var HttpException = class HttpException extends Error {
|
|
|
66
33
|
data: this.data
|
|
67
34
|
};
|
|
68
35
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Create a 400 Bad Request exception.
|
|
71
|
-
*/
|
|
72
36
|
static badRequest(message = "Bad Request") {
|
|
73
37
|
return new HttpException(400, message);
|
|
74
38
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Create a 401 Unauthorized exception.
|
|
77
|
-
*/
|
|
78
39
|
static unauthorized(message = "Unauthorized") {
|
|
79
40
|
return new HttpException(401, message);
|
|
80
41
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Create a 403 Forbidden exception.
|
|
83
|
-
*/
|
|
84
42
|
static forbidden(message = "Forbidden") {
|
|
85
43
|
return new HttpException(403, message);
|
|
86
44
|
}
|
|
87
|
-
/**
|
|
88
|
-
* Create a 404 Not Found exception.
|
|
89
|
-
*/
|
|
90
45
|
static notFound(message = "Not Found") {
|
|
91
46
|
return new HttpException(404, message);
|
|
92
47
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Create a 405 Method Not Allowed exception.
|
|
95
|
-
*/
|
|
96
48
|
static methodNotAllowed(message = "Method Not Allowed") {
|
|
97
49
|
return new HttpException(405, message);
|
|
98
50
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Create a 409 Conflict exception.
|
|
101
|
-
*/
|
|
102
51
|
static conflict(message = "Conflict") {
|
|
103
52
|
return new HttpException(409, message);
|
|
104
53
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Create a 410 Gone exception.
|
|
107
|
-
*/
|
|
108
54
|
static gone(message = "Gone") {
|
|
109
55
|
return new HttpException(410, message);
|
|
110
56
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Create a 422 Unprocessable Entity exception.
|
|
113
|
-
*/
|
|
114
57
|
static unprocessable(message = "Unprocessable Entity", errors) {
|
|
115
58
|
return new HttpException(422, message, errors);
|
|
116
59
|
}
|
|
117
|
-
/**
|
|
118
|
-
* Create a 429 Too Many Requests exception.
|
|
119
|
-
*/
|
|
120
60
|
static tooManyRequests(message = "Too Many Requests") {
|
|
121
61
|
return new HttpException(429, message);
|
|
122
62
|
}
|
|
123
|
-
/**
|
|
124
|
-
* Create a 500 Internal Server Error exception.
|
|
125
|
-
*/
|
|
126
63
|
static internal(message = "Internal Server Error") {
|
|
127
64
|
return new HttpException(500, message);
|
|
128
65
|
}
|
|
129
|
-
/**
|
|
130
|
-
* Create a 501 Not Implemented exception.
|
|
131
|
-
*/
|
|
132
66
|
static notImplemented(message = "Not Implemented") {
|
|
133
67
|
return new HttpException(501, message);
|
|
134
68
|
}
|
|
135
|
-
/**
|
|
136
|
-
* Create a 502 Bad Gateway exception.
|
|
137
|
-
*/
|
|
138
69
|
static badGateway(message = "Bad Gateway") {
|
|
139
70
|
return new HttpException(502, message);
|
|
140
71
|
}
|
|
141
|
-
/**
|
|
142
|
-
* Create a 503 Service Unavailable exception.
|
|
143
|
-
*/
|
|
144
72
|
static serviceUnavailable(message = "Service Unavailable") {
|
|
145
73
|
return new HttpException(503, message);
|
|
146
74
|
}
|
|
147
|
-
/**
|
|
148
|
-
* Create a 504 Gateway Timeout exception.
|
|
149
|
-
*/
|
|
150
75
|
static gatewayTimeout(message = "Gateway Timeout") {
|
|
151
76
|
return new HttpException(504, message);
|
|
152
77
|
}
|
|
153
|
-
/**
|
|
154
|
-
* Check if an error is an HTTP exception.
|
|
155
|
-
*/
|
|
78
|
+
/** Duck-typed: an exception from another copy of the package still passes. */
|
|
156
79
|
static isHttpException(error) {
|
|
157
80
|
return error instanceof HttpException || typeof error === "object" && error !== null && "statusCode" in error && typeof error.statusCode === "number" && "toResponse" in error && typeof error.toResponse === "function";
|
|
158
81
|
}
|
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
//#region src/container/Container.ts
|
|
3
3
|
/**
|
|
4
|
-
* Dependency injection container
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* const container = new Container()
|
|
9
|
-
*
|
|
10
|
-
* // Register services
|
|
11
|
-
* container.singleton('events', (c) => new EventManager())
|
|
12
|
-
* container.instance('config', loadConfig())
|
|
13
|
-
*
|
|
14
|
-
* // Type-safe resolution (known bindings)
|
|
15
|
-
* const events = container.make('events') // EventManager
|
|
16
|
-
*
|
|
17
|
-
* // Generic resolution (custom bindings)
|
|
18
|
-
* const db = container.make<Database>('db')
|
|
19
|
-
* ```
|
|
4
|
+
* Dependency injection container. Keys from `ServiceBindings` type `make()`
|
|
5
|
+
* automatically; other keys take an explicit type parameter (`make<T>(key)`).
|
|
20
6
|
*/
|
|
21
7
|
var Container = class Container {
|
|
22
8
|
bindings = /* @__PURE__ */ new Map();
|
|
@@ -26,12 +12,14 @@ var Container = class Container {
|
|
|
26
12
|
resolvingStack = [];
|
|
27
13
|
scopedInstances = [];
|
|
28
14
|
fakes = /* @__PURE__ */ new Map();
|
|
29
|
-
/** @internal Used by ProviderManager to resolve deferred providers on demand */
|
|
30
|
-
deferredProviderLoader = null;
|
|
31
15
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
16
|
+
* @internal Installed by ProviderManager once every eager provider has booted.
|
|
17
|
+
* Called from make() for an unbound key; must run the deferred provider's
|
|
18
|
+
* register() synchronously before returning (boot() may settle on the returned
|
|
19
|
+
* promise). `undefined` means no deferred provider claims the service.
|
|
34
20
|
*/
|
|
21
|
+
deferredProviderLoader = null;
|
|
22
|
+
/** Bind a factory; each resolution creates a new instance. */
|
|
35
23
|
bind(key, factory) {
|
|
36
24
|
this.bindings.set(key, {
|
|
37
25
|
factory,
|
|
@@ -39,10 +27,7 @@ var Container = class Container {
|
|
|
39
27
|
});
|
|
40
28
|
return this;
|
|
41
29
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Bind a singleton service to the container.
|
|
44
|
-
* Only one instance is created and reused.
|
|
45
|
-
*/
|
|
30
|
+
/** Bind a factory whose single instance is reused. */
|
|
46
31
|
singleton(key, factory) {
|
|
47
32
|
this.bindings.set(key, {
|
|
48
33
|
factory,
|
|
@@ -50,9 +35,6 @@ var Container = class Container {
|
|
|
50
35
|
});
|
|
51
36
|
return this;
|
|
52
37
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Bind an existing instance to the container.
|
|
55
|
-
*/
|
|
56
38
|
instance(key, value) {
|
|
57
39
|
this.bindings.set(key, {
|
|
58
40
|
factory: () => value,
|
|
@@ -67,11 +49,9 @@ var Container = class Container {
|
|
|
67
49
|
if (resolvedKey !== key && this.fakes.has(resolvedKey)) return this.fakes.get(resolvedKey);
|
|
68
50
|
let binding = this.bindings.get(resolvedKey);
|
|
69
51
|
if (!binding && this.deferredProviderLoader) {
|
|
70
|
-
|
|
71
|
-
this.
|
|
72
|
-
|
|
73
|
-
});
|
|
74
|
-
if (resolved) binding = this.bindings.get(resolvedKey);
|
|
52
|
+
const loading = this.deferredProviderLoader(resolvedKey);
|
|
53
|
+
binding = this.bindings.get(resolvedKey);
|
|
54
|
+
if (loading && !binding) throw new Error(`Deferred provider for "${key}" did not bind "${resolvedKey}" synchronously in register(). Container.make() cannot await an async register(); bind the service synchronously, or await ProviderManager.loadDeferredProvider() before resolving it.`);
|
|
75
55
|
}
|
|
76
56
|
if (!binding) throw new Error(`Service "${key}" not found in container`);
|
|
77
57
|
if (binding.singleton && binding.instance !== void 0) return binding.instance;
|
|
@@ -90,9 +70,6 @@ var Container = class Container {
|
|
|
90
70
|
this.resolvingStack.pop();
|
|
91
71
|
}
|
|
92
72
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Resolve a service with additional parameters.
|
|
95
|
-
*/
|
|
96
73
|
makeWith(key, params) {
|
|
97
74
|
const resolvedKey = this.resolveAlias(key);
|
|
98
75
|
const binding = this.bindings.get(resolvedKey);
|
|
@@ -102,24 +79,15 @@ var Container = class Container {
|
|
|
102
79
|
for (const [paramKey, paramValue] of Object.entries(params)) tempContainer.instance(paramKey, paramValue);
|
|
103
80
|
return binding.factory(tempContainer);
|
|
104
81
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Check if a service is bound in the container.
|
|
107
|
-
*/
|
|
108
82
|
has(key) {
|
|
109
83
|
const resolvedKey = this.resolveAlias(key);
|
|
110
84
|
return this.bindings.has(resolvedKey);
|
|
111
85
|
}
|
|
112
|
-
/**
|
|
113
|
-
* Create an alias for a service.
|
|
114
|
-
*/
|
|
115
86
|
alias(alias, key) {
|
|
116
87
|
if (alias === key) throw new Error("Alias cannot be the same as the key");
|
|
117
88
|
this.aliases.set(alias, key);
|
|
118
89
|
return this;
|
|
119
90
|
}
|
|
120
|
-
/**
|
|
121
|
-
* Tag multiple services with a tag name.
|
|
122
|
-
*/
|
|
123
91
|
tag(keys, tagName) {
|
|
124
92
|
let taggedKeys = this.tags.get(tagName);
|
|
125
93
|
if (!taggedKeys) {
|
|
@@ -129,17 +97,11 @@ var Container = class Container {
|
|
|
129
97
|
for (const key of keys) taggedKeys.add(key);
|
|
130
98
|
return this;
|
|
131
99
|
}
|
|
132
|
-
/**
|
|
133
|
-
* Resolve all services with a given tag.
|
|
134
|
-
*/
|
|
135
100
|
tagged(tagName) {
|
|
136
101
|
const taggedKeys = this.tags.get(tagName);
|
|
137
102
|
if (!taggedKeys) return [];
|
|
138
103
|
return Array.from(taggedKeys).map((key) => this.make(key));
|
|
139
104
|
}
|
|
140
|
-
/**
|
|
141
|
-
* Define a contextual binding.
|
|
142
|
-
*/
|
|
143
105
|
when(concrete) {
|
|
144
106
|
return { needs: (abstract) => {
|
|
145
107
|
return { give: (factoryOrValue) => {
|
|
@@ -152,10 +114,7 @@ var Container = class Container {
|
|
|
152
114
|
} };
|
|
153
115
|
} };
|
|
154
116
|
}
|
|
155
|
-
/**
|
|
156
|
-
* Run a callback within a scoped context.
|
|
157
|
-
* Services resolved within the scope are cached and released when the scope ends.
|
|
158
|
-
*/
|
|
117
|
+
/** Services resolved inside the callback are cached for the scope and released when it ends. */
|
|
159
118
|
scoped(callback) {
|
|
160
119
|
this.scopedInstances.push(/* @__PURE__ */ new Map());
|
|
161
120
|
try {
|
|
@@ -164,9 +123,6 @@ var Container = class Container {
|
|
|
164
123
|
this.scopedInstances.pop();
|
|
165
124
|
}
|
|
166
125
|
}
|
|
167
|
-
/**
|
|
168
|
-
* Run an async callback within a scoped context.
|
|
169
|
-
*/
|
|
170
126
|
async scopedAsync(callback) {
|
|
171
127
|
this.scopedInstances.push(/* @__PURE__ */ new Map());
|
|
172
128
|
try {
|
|
@@ -181,49 +137,28 @@ var Container = class Container {
|
|
|
181
137
|
this.fakes.delete(key);
|
|
182
138
|
} };
|
|
183
139
|
}
|
|
184
|
-
/**
|
|
185
|
-
* Check if a service is currently faked.
|
|
186
|
-
*/
|
|
187
140
|
isFaked(key) {
|
|
188
141
|
return this.fakes.has(key);
|
|
189
142
|
}
|
|
190
|
-
/**
|
|
191
|
-
* Remove all fakes.
|
|
192
|
-
*/
|
|
193
143
|
clearFakes() {
|
|
194
144
|
this.fakes.clear();
|
|
195
145
|
}
|
|
196
|
-
/**
|
|
197
|
-
* Flush all resolved singleton instances.
|
|
198
|
-
*/
|
|
199
146
|
flush() {
|
|
200
147
|
for (const binding of this.bindings.values()) binding.instance = void 0;
|
|
201
148
|
}
|
|
202
|
-
/**
|
|
203
|
-
* Remove a binding from the container.
|
|
204
|
-
*/
|
|
205
149
|
forget(key) {
|
|
206
150
|
const resolvedKey = this.resolveAlias(key);
|
|
207
151
|
this.bindings.delete(resolvedKey);
|
|
208
152
|
return this;
|
|
209
153
|
}
|
|
210
|
-
/**
|
|
211
|
-
* Get all bound service keys.
|
|
212
|
-
*/
|
|
213
154
|
getBindings() {
|
|
214
155
|
return Array.from(this.bindings.keys());
|
|
215
156
|
}
|
|
216
|
-
/**
|
|
217
|
-
* Get all aliases.
|
|
218
|
-
*/
|
|
219
157
|
getAliases() {
|
|
220
158
|
const result = {};
|
|
221
159
|
for (const [alias, key] of this.aliases) result[alias] = key;
|
|
222
160
|
return result;
|
|
223
161
|
}
|
|
224
|
-
/**
|
|
225
|
-
* Get all tags.
|
|
226
|
-
*/
|
|
227
162
|
getTags() {
|
|
228
163
|
const result = {};
|
|
229
164
|
for (const [tag, keys] of this.tags) result[tag] = Array.from(keys);
|
|
@@ -246,9 +181,6 @@ var Container = class Container {
|
|
|
246
181
|
return null;
|
|
247
182
|
}
|
|
248
183
|
};
|
|
249
|
-
/**
|
|
250
|
-
* Create a new container instance.
|
|
251
|
-
*/
|
|
252
184
|
function createContainer() {
|
|
253
185
|
return new Container();
|
|
254
186
|
}
|
|
@@ -265,94 +197,37 @@ function resolve(key) {
|
|
|
265
197
|
}
|
|
266
198
|
//#endregion
|
|
267
199
|
//#region src/queue/Job.ts
|
|
268
|
-
/**
|
|
269
|
-
* Global queue driver instance.
|
|
270
|
-
* Set via setQueueDriver() or QueueManager.
|
|
271
|
-
*/
|
|
272
200
|
let globalDriver = null;
|
|
273
|
-
/**
|
|
274
|
-
* Set the global queue driver.
|
|
275
|
-
*/
|
|
276
201
|
function setQueueDriver(driver) {
|
|
277
202
|
globalDriver = driver;
|
|
278
203
|
}
|
|
279
|
-
/**
|
|
280
|
-
* Get the global queue driver.
|
|
281
|
-
*/
|
|
282
204
|
function getQueueDriver() {
|
|
283
205
|
return globalDriver;
|
|
284
206
|
}
|
|
285
|
-
/**
|
|
286
|
-
* Generate a unique job ID.
|
|
287
|
-
*/
|
|
288
207
|
function generateJobId() {
|
|
289
208
|
return randomBytes(16).toString("hex");
|
|
290
209
|
}
|
|
291
|
-
/**
|
|
292
|
-
* Base class for defining jobs.
|
|
293
|
-
*
|
|
294
|
-
* @example
|
|
295
|
-
* ```ts
|
|
296
|
-
* class SendWelcomeEmailJob extends Job<{ userId: string }> {
|
|
297
|
-
* static queue = 'emails'
|
|
298
|
-
* static maxAttempts = 5
|
|
299
|
-
*
|
|
300
|
-
* async handle({ userId }: { userId: string }): Promise<void> {
|
|
301
|
-
* const user = await User.find(userId)
|
|
302
|
-
* await mail.to(user.email).template(WelcomeEmail, user).send()
|
|
303
|
-
* }
|
|
304
|
-
*
|
|
305
|
-
* async failed({ userId }: { userId: string }, error: Error): Promise<void> {
|
|
306
|
-
* console.error(`Failed to send welcome email to user ${userId}:`, error)
|
|
307
|
-
* }
|
|
308
|
-
* }
|
|
309
|
-
*
|
|
310
|
-
* // Dispatch the job
|
|
311
|
-
* await SendWelcomeEmailJob.dispatch({ userId: '123' })
|
|
312
|
-
*
|
|
313
|
-
* // Dispatch with delay
|
|
314
|
-
* await SendWelcomeEmailJob.dispatchAfter(60000, { userId: '123' })
|
|
315
|
-
* ```
|
|
316
|
-
*/
|
|
317
210
|
var Job = class {
|
|
318
211
|
/**
|
|
319
|
-
* Stable wire name
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
* from it. When omitted the class name is used, which breaks if a bundler
|
|
323
|
-
* mangles identifiers or if the class is later renamed while messages are
|
|
324
|
-
* still in flight. Set it to pin the name across both.
|
|
325
|
-
*
|
|
212
|
+
* Stable wire name: queued messages record it and the worker resolves the
|
|
213
|
+
* class back from it. Defaults to the class name, which breaks under
|
|
214
|
+
* identifier mangling or a rename with messages still in flight.
|
|
326
215
|
* @default the class name
|
|
327
216
|
*/
|
|
328
217
|
static jobName;
|
|
329
|
-
/**
|
|
330
|
-
* The queue this job should be dispatched to.
|
|
331
|
-
* @default 'default'
|
|
332
|
-
*/
|
|
218
|
+
/** @default 'default' */
|
|
333
219
|
static queue = "default";
|
|
334
|
-
/**
|
|
335
|
-
* Maximum number of times the job should be attempted.
|
|
336
|
-
* @default 3
|
|
337
|
-
*/
|
|
220
|
+
/** @default 3 */
|
|
338
221
|
static maxAttempts = 3;
|
|
339
222
|
/**
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
* - 'linear': attempt * 1000ms (1s, 2s, 3s, 4s, ...)
|
|
343
|
-
* - number: fixed delay in milliseconds
|
|
223
|
+
* 'exponential' = 2^attempt * 1000ms, 'linear' = attempt * 1000ms, a number
|
|
224
|
+
* is a fixed delay in milliseconds.
|
|
344
225
|
* @default 'exponential'
|
|
345
226
|
*/
|
|
346
227
|
static backoff = "exponential";
|
|
347
228
|
make(key) {
|
|
348
229
|
return getContainer().make(key);
|
|
349
230
|
}
|
|
350
|
-
/**
|
|
351
|
-
* Dispatch the job to the queue.
|
|
352
|
-
*
|
|
353
|
-
* @param payload - Job payload data
|
|
354
|
-
* @param options - Optional dispatch options
|
|
355
|
-
*/
|
|
356
231
|
static async dispatch(payload, options = {}) {
|
|
357
232
|
const driver = globalDriver;
|
|
358
233
|
if (!driver) throw new Error("Queue driver not configured. Call setQueueDriver() first.");
|
|
@@ -373,22 +248,12 @@ var Job = class {
|
|
|
373
248
|
await driver.push(job);
|
|
374
249
|
return jobId;
|
|
375
250
|
}
|
|
376
|
-
/**
|
|
377
|
-
* Dispatch the job after a delay.
|
|
378
|
-
*
|
|
379
|
-
* @param delayMs - Delay in milliseconds
|
|
380
|
-
* @param payload - Job payload data
|
|
381
|
-
* @param options - Optional dispatch options (delay is overridden)
|
|
382
|
-
*/
|
|
383
251
|
static async dispatchAfter(delayMs, payload, options = {}) {
|
|
384
252
|
return this.dispatch(payload, {
|
|
385
253
|
...options,
|
|
386
254
|
delay: delayMs
|
|
387
255
|
});
|
|
388
256
|
}
|
|
389
|
-
/**
|
|
390
|
-
* Calculate the retry delay based on backoff strategy.
|
|
391
|
-
*/
|
|
392
257
|
static calculateRetryDelay(attempts) {
|
|
393
258
|
if (typeof this.backoff === "number") return this.backoff;
|
|
394
259
|
if (this.backoff === "linear") return attempts * 1e3;
|
|
@@ -396,44 +261,24 @@ var Job = class {
|
|
|
396
261
|
}
|
|
397
262
|
};
|
|
398
263
|
/**
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
* or bundling with identifier mangling does not orphan queued messages.
|
|
403
|
-
*
|
|
404
|
-
* Only an *own* `jobName` counts. Static members are inherited, so reading it
|
|
405
|
-
* off the prototype chain would make every subclass of a pinned job claim its
|
|
406
|
-
* parent's identity and overwrite it in the registry. A subclass that wants a
|
|
407
|
-
* pinned name declares its own.
|
|
264
|
+
* Only an *own* `jobName` counts: statics are inherited, so reading the
|
|
265
|
+
* prototype chain would make every subclass of a pinned job claim its
|
|
266
|
+
* parent's identity and overwrite it in the registry.
|
|
408
267
|
*/
|
|
409
268
|
function resolveJobName(jobClass) {
|
|
410
269
|
return (Object.prototype.hasOwnProperty.call(jobClass, "jobName") ? jobClass.jobName : void 0) ?? jobClass.name;
|
|
411
270
|
}
|
|
412
|
-
/**
|
|
413
|
-
* Job registry for looking up job classes by name.
|
|
414
|
-
*/
|
|
415
271
|
const jobRegistry = /* @__PURE__ */ new Map();
|
|
416
|
-
/**
|
|
417
|
-
* Register a job class for the worker to use.
|
|
418
|
-
*/
|
|
419
272
|
function registerJob(jobClass) {
|
|
420
273
|
jobRegistry.set(resolveJobName(jobClass), jobClass);
|
|
421
274
|
}
|
|
422
|
-
/**
|
|
423
|
-
* Get a registered job class by name.
|
|
424
|
-
*/
|
|
425
275
|
function getJob(name) {
|
|
426
276
|
return jobRegistry.get(name);
|
|
427
277
|
}
|
|
428
|
-
/**
|
|
429
|
-
* Get all registered job classes.
|
|
430
|
-
*/
|
|
431
278
|
function getRegisteredJobs() {
|
|
432
279
|
return new Map(jobRegistry);
|
|
433
280
|
}
|
|
434
|
-
/**
|
|
435
|
-
* Clear all registered jobs (for testing).
|
|
436
|
-
*/
|
|
281
|
+
/** Testing only. */
|
|
437
282
|
function clearJobRegistry() {
|
|
438
283
|
jobRegistry.clear();
|
|
439
284
|
}
|