@zintrust/core 0.1.23 → 0.1.25
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/package.json +4 -3
- package/src/auth/Auth.d.ts.map +1 -0
- package/src/boot/Application.d.ts.map +1 -1
- package/src/boot/Application.js +8 -0
- package/src/boot/bootstrap.js +34 -15
- package/src/cache/drivers/RedisDriver.d.ts.map +1 -1
- package/src/cache/drivers/RedisDriver.js +10 -5
- package/src/cli/CLI.d.ts.map +1 -1
- package/src/cli/CLI.js +6 -0
- package/src/cli/commands/DbSeedCommand.d.ts.map +1 -1
- package/src/cli/commands/DbSeedCommand.js +6 -38
- package/src/cli/commands/MigrateCommand.d.ts.map +1 -1
- package/src/cli/commands/MigrateCommand.js +12 -55
- package/src/cli/commands/MigrateWorkerCommand.d.ts.map +1 -1
- package/src/cli/commands/MigrateWorkerCommand.js +8 -54
- package/src/cli/commands/NewCommand.d.ts.map +1 -1
- package/src/cli/commands/NewCommand.js +1 -13
- package/src/cli/commands/QueueCommand.d.ts.map +1 -1
- package/src/cli/commands/QueueCommand.js +89 -39
- package/src/cli/commands/QueueLockCommand.d.ts +7 -0
- package/src/cli/commands/QueueLockCommand.d.ts.map +1 -0
- package/src/cli/commands/QueueLockCommand.js +138 -0
- package/src/cli/commands/StartCommand.d.ts.map +1 -1
- package/src/cli/commands/StartCommand.js +16 -16
- package/src/cli/commands/TemplatesCommand.js +1 -1
- package/src/cli/commands/WorkerCommands.d.ts.map +1 -1
- package/src/cli/commands/WorkerCommands.js +46 -22
- package/src/cli/scaffolding/ProjectScaffolder.js +2 -2
- package/src/cli/scaffolding/RouteGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/RouteGenerator.js +27 -28
- package/src/cli/services/VersionChecker.d.ts +53 -0
- package/src/cli/services/VersionChecker.d.ts.map +1 -0
- package/src/cli/services/VersionChecker.js +176 -0
- package/src/cli/utils/DatabaseCliUtils.d.ts +20 -0
- package/src/cli/utils/DatabaseCliUtils.d.ts.map +1 -0
- package/src/cli/utils/DatabaseCliUtils.js +54 -0
- package/src/cli/workers/QueueWorkRunner.d.ts.map +1 -1
- package/src/cli/workers/QueueWorkRunner.js +128 -7
- package/src/common/ExternalServiceUtils.d.ts +2 -2
- package/src/config/app.d.ts +4 -0
- package/src/config/app.d.ts.map +1 -1
- package/src/config/app.js +9 -0
- package/src/config/constants.d.ts +140 -10
- package/src/config/constants.d.ts.map +1 -1
- package/src/config/constants.js +86 -5
- package/src/config/index.d.ts +1 -0
- package/src/config/index.d.ts.map +1 -1
- package/src/config/middleware.d.ts +6 -6
- package/src/config/middleware.d.ts.map +1 -1
- package/src/config/middleware.js +6 -7
- package/src/config/queue.d.ts +4 -0
- package/src/config/queue.d.ts.map +1 -1
- package/src/config/queue.js +1 -1
- package/src/config/redis.d.ts +17 -0
- package/src/config/redis.d.ts.map +1 -0
- package/src/config/redis.js +54 -0
- package/src/config/type.d.ts +3 -0
- package/src/config/type.d.ts.map +1 -1
- package/src/http/Request.d.ts +10 -1
- package/src/http/Request.d.ts.map +1 -1
- package/src/http/Request.js +79 -7
- package/src/http/error-pages/ErrorPageRenderer.d.ts.map +1 -1
- package/src/http/error-pages/ErrorPageRenderer.js +4 -3
- package/src/index.d.ts +14 -11
- package/src/index.d.ts.map +1 -1
- package/src/index.js +18 -11
- package/src/lang/lang.d.ts +23 -0
- package/src/lang/lang.d.ts.map +1 -0
- package/src/lang/lang.js +22 -0
- package/src/middleware/ErrorHandlerMiddleware.d.ts.map +1 -1
- package/src/middleware/ErrorHandlerMiddleware.js +9 -1
- package/src/migrations/schema/SchemaCompiler.js +1 -1
- package/src/migrations/schema/types.d.ts +1 -1
- package/src/migrations/schema/types.d.ts.map +1 -1
- package/src/node.d.ts +1 -1
- package/src/node.d.ts.map +1 -1
- package/src/node.js +1 -1
- package/src/orm/Database.d.ts +1 -1
- package/src/orm/Database.d.ts.map +1 -1
- package/src/orm/Database.js +22 -3
- package/src/performance/Optimizer.js +1 -1
- package/src/routing/Router.d.ts +6 -2
- package/src/routing/Router.d.ts.map +1 -1
- package/src/routing/Router.js +19 -4
- package/src/runtime/PluginAutoImports.d.ts.map +1 -1
- package/src/runtime/PluginAutoImports.js +1 -13
- package/src/runtime/PluginManager.d.ts.map +1 -1
- package/src/runtime/PluginManager.js +2 -14
- package/src/runtime/PluginRegistry.js +2 -2
- package/src/start.d.ts.map +1 -1
- package/src/start.js +8 -7
- package/src/templates/TemplateRegistry.js +2 -2
- package/src/templates/TemplateRegistry.ts +2 -2
- package/src/templates/feature/Queue.ts.tpl +114 -0
- package/src/templates/project/basic/app/Controllers/UserController.ts.tpl +22 -0
- package/src/templates/project/basic/config/queue.ts.tpl +19 -0
- package/src/templates/project/basic/package.json.tpl +2 -1
- package/src/templates/project/basic/src/index.ts.tpl +0 -3
- package/src/toolkit/Secrets/providers/AwsSecretsManager.d.ts.map +1 -1
- package/src/toolkit/Secrets/providers/AwsSecretsManager.js +1 -13
- package/src/toolkit/Secrets/providers/CloudflareKv.d.ts.map +1 -1
- package/src/toolkit/Secrets/providers/CloudflareKv.js +4 -16
- package/src/tools/broadcast/drivers/Redis.d.ts.map +1 -1
- package/src/tools/broadcast/drivers/Redis.js +8 -56
- package/src/tools/mail/Mail.d.ts +1 -29
- package/src/tools/mail/Mail.d.ts.map +1 -1
- package/src/tools/mail/Mail.js +1 -111
- package/src/tools/mail/drivers/SendGrid.d.ts.map +1 -1
- package/src/tools/mail/drivers/SendGrid.js +4 -3
- package/src/tools/mail/drivers/Smtp.d.ts.map +1 -1
- package/src/tools/mail/drivers/Smtp.js +32 -10
- package/src/tools/mail/index.d.ts +40 -0
- package/src/tools/mail/index.d.ts.map +1 -0
- package/src/tools/mail/index.js +129 -0
- package/src/tools/mail/template-loader.d.ts +10 -0
- package/src/tools/mail/template-loader.d.ts.map +1 -0
- package/src/tools/mail/template-loader.js +101 -0
- package/src/tools/mail/template-utils.d.ts +10 -0
- package/src/tools/mail/template-utils.d.ts.map +1 -0
- package/src/tools/mail/template-utils.js +16 -0
- package/src/tools/mail/templates/index.d.ts +30 -0
- package/src/tools/mail/templates/index.d.ts.map +1 -1
- package/src/tools/mail/templates/index.js +69 -0
- package/src/tools/queue/AdvancedQueue.d.ts +19 -0
- package/src/tools/queue/AdvancedQueue.d.ts.map +1 -0
- package/src/tools/queue/AdvancedQueue.js +352 -0
- package/src/tools/queue/DeduplicationBuilder.d.ts +20 -0
- package/src/tools/queue/DeduplicationBuilder.d.ts.map +1 -0
- package/src/tools/queue/DeduplicationBuilder.js +77 -0
- package/src/tools/queue/LockProvider.d.ts +25 -0
- package/src/tools/queue/LockProvider.d.ts.map +1 -0
- package/src/tools/queue/LockProvider.js +276 -0
- package/src/tools/queue/Queue.d.ts.map +1 -1
- package/src/tools/queue/Queue.js +2 -1
- package/src/tools/queue/QueueExtensions.d.ts +46 -0
- package/src/tools/queue/QueueExtensions.d.ts.map +1 -0
- package/src/tools/queue/QueueExtensions.js +129 -0
- package/src/tools/queue/QueueRuntimeRegistration.d.ts.map +1 -1
- package/src/tools/queue/QueueRuntimeRegistration.js +2 -2
- package/src/tools/queue/drivers/Database.d.ts +23 -0
- package/src/tools/queue/drivers/Database.d.ts.map +1 -0
- package/src/tools/queue/drivers/Database.js +123 -0
- package/src/tools/queue/drivers/Redis.d.ts.map +1 -1
- package/src/tools/queue/drivers/Redis.js +11 -82
- package/src/tools/queue/index.d.ts +9 -0
- package/src/tools/queue/index.d.ts.map +1 -0
- package/src/tools/queue/index.js +7 -0
- package/src/tools/redis/RedisKeyManager.d.ts +64 -0
- package/src/tools/redis/RedisKeyManager.d.ts.map +1 -0
- package/src/tools/redis/RedisKeyManager.js +124 -0
- package/src/tools/storage/drivers/S3.d.ts.map +1 -1
- package/src/tools/storage/drivers/S3.js +4 -16
- package/src/types/Queue.d.ts +62 -0
- package/src/types/Queue.d.ts.map +1 -0
- package/src/types/Queue.js +5 -0
- package/src/features/Auth.d.ts.map +0 -1
- package/src/features/Queue.d.ts +0 -21
- package/src/features/Queue.d.ts.map +0 -1
- package/src/features/Queue.js +0 -33
- package/src/templates/features/Queue.ts.tpl +0 -47
- package/src/tools/mail/templates/markdown/index.d.ts +0 -17
- package/src/tools/mail/templates/markdown/index.d.ts.map +0 -1
- package/src/tools/mail/templates/markdown/index.js +0 -49
- package/src/tools/mail/templates/markdown/registry.d.ts +0 -15
- package/src/tools/mail/templates/markdown/registry.d.ts.map +0 -1
- package/src/tools/mail/templates/markdown/registry.js +0 -34
- package/src/tools/mail/templates/markdown/validator.d.ts +0 -16
- package/src/tools/mail/templates/markdown/validator.d.ts.map +0 -1
- package/src/tools/mail/templates/markdown/validator.js +0 -24
- /package/src/{features → auth}/Auth.d.ts +0 -0
- /package/src/{features → auth}/Auth.js +0 -0
- /package/src/templates/{features → auth}/Auth.ts.tpl +0 -0
package/src/routing/Router.d.ts
CHANGED
|
@@ -27,6 +27,9 @@ export interface Route {
|
|
|
27
27
|
meta?: RouteMeta;
|
|
28
28
|
}
|
|
29
29
|
export type RouteGroupCallback = (router: IRouter) => void;
|
|
30
|
+
export type GroupOptions<MiddlewareName extends string = string> = {
|
|
31
|
+
middleware?: ReadonlyArray<MiddlewareName>;
|
|
32
|
+
};
|
|
30
33
|
export interface ResourceController {
|
|
31
34
|
index?: RouteHandler;
|
|
32
35
|
show?: RouteHandler;
|
|
@@ -45,6 +48,7 @@ export type IRouter = {
|
|
|
45
48
|
routes: Route[];
|
|
46
49
|
prefix: string;
|
|
47
50
|
routeIndex: Map<string, Route[]>;
|
|
51
|
+
inheritedMiddleware?: ReadonlyArray<string>;
|
|
48
52
|
};
|
|
49
53
|
export declare const createRouter: () => IRouter;
|
|
50
54
|
/**
|
|
@@ -53,8 +57,8 @@ export declare const createRouter: () => IRouter;
|
|
|
53
57
|
*/
|
|
54
58
|
export declare const Router: Readonly<{
|
|
55
59
|
createRouter: () => IRouter;
|
|
56
|
-
scopeRouter: (router: IRouter, prefix: string) => IRouter;
|
|
57
|
-
group: (router: IRouter, prefix: string, callback: RouteGroupCallback) => void;
|
|
60
|
+
scopeRouter: (router: IRouter, prefix: string, inheritedMiddleware?: ReadonlyArray<string>) => IRouter;
|
|
61
|
+
group: <M extends string = string>(router: IRouter, prefix: string, callback: RouteGroupCallback, options?: GroupOptions<M>) => void;
|
|
58
62
|
resource: <M extends string = string>(router: IRouter, path: string, controller: ResourceController, options?: ResourceOptions<M>) => void;
|
|
59
63
|
get: <M extends string = string>(router: IRouter, path: string, handler: RouteHandler, options?: RouteOptions<M>) => void;
|
|
60
64
|
post: <M extends string = string>(router: IRouter, path: string, handler: RouteHandler, options?: RouteOptions<M>) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../../src/routing/Router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,wBAAwB,CAAC;AAEhC;;;GAGG;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAEnF,MAAM,MAAM,YAAY,CAAC,cAAc,SAAS,MAAM,GAAG,MAAM,IAAI;IACjE,UAAU,CAAC,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAC3C,IAAI,CAAC,EAAE,cAAc,CAAC;CACvB,CAAC;AAEF,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,YAAY,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,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pB,OAAO,QACT,MAAM,WACH,YAAY,YACX,YAAY,CAAC,CAAC,CAAC,KACxB,IAAI;UAIM,CAAC,SAAS,MAAM,mBACnB,OAAO,QACT,MAAM,WACH,YAAY,YACX,YAAY,CAAC,CAAC,CAAC,KACxB,IAAI;YAIQ,CAAC,SAAS,MAAM,mBACrB,OAAO,QACT,MAAM,WACH,YAAY,YACX,YAAY,CAAC,CAAC,CAAC,KACxB,IAAI;UAIM,CAAC,SAAS,MAAM,mBACnB,OAAO,QACT,MAAM,WACH,YAAY,YACX,YAAY,CAAC,CAAC,CAAC,KACxB,IAAI;UAIM,CAAC,SAAS,MAAM,mBACnB,OAAO,QACT,MAAM,WACH,YAAY,YACX,YAAY,CAAC,CAAC,CAAC,KACxB,IAAI;oBAOgB,OAAO,UAAU,MAAM,QAAQ,MAAM,KAAG,UAAU,GAAG,IAAI;wBAGrD,OAAO,KAAG,KAAK,EAAE;EAmB1C,CAAC;AAEH,eAAe,MAAM,CAAC"}
|
package/src/routing/Router.js
CHANGED
|
@@ -31,13 +31,27 @@ const pathToRegex = (path) => {
|
|
|
31
31
|
*/
|
|
32
32
|
const registerRoute = (router, method, path, handler, options) => {
|
|
33
33
|
const { pattern, paramNames } = pathToRegex(path);
|
|
34
|
+
// Merge inherited middleware with route-specific middleware
|
|
35
|
+
let routeMiddleware;
|
|
36
|
+
if (router.inheritedMiddleware && router.inheritedMiddleware.length > 0) {
|
|
37
|
+
const routeSpecificMiddleware = Array.isArray(options?.middleware)
|
|
38
|
+
? options?.middleware
|
|
39
|
+
: [];
|
|
40
|
+
routeMiddleware = [...router.inheritedMiddleware, ...routeSpecificMiddleware];
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const hasRouteSpecificMiddleware = Array.isArray(options?.middleware);
|
|
44
|
+
if (hasRouteSpecificMiddleware) {
|
|
45
|
+
routeMiddleware = options?.middleware;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
34
48
|
const route = {
|
|
35
49
|
method,
|
|
36
50
|
path,
|
|
37
51
|
pattern,
|
|
38
52
|
handler,
|
|
39
53
|
paramNames,
|
|
40
|
-
middleware:
|
|
54
|
+
middleware: routeMiddleware,
|
|
41
55
|
meta: normalizeRouteMeta(options?.meta),
|
|
42
56
|
};
|
|
43
57
|
router.routes.push(route);
|
|
@@ -139,13 +153,14 @@ const joinPaths = (prefix, path) => {
|
|
|
139
153
|
return pfx || '/';
|
|
140
154
|
return `${pfx}${pth}`;
|
|
141
155
|
};
|
|
142
|
-
const scopeRouter = (router, prefix) => ({
|
|
156
|
+
const scopeRouter = (router, prefix, inheritedMiddleware) => ({
|
|
143
157
|
routes: router.routes,
|
|
144
158
|
prefix: joinPaths(router.prefix, prefix),
|
|
145
159
|
routeIndex: router.routeIndex,
|
|
160
|
+
inheritedMiddleware,
|
|
146
161
|
});
|
|
147
|
-
const group = (router, prefix, callback) => {
|
|
148
|
-
callback(scopeRouter(router, prefix));
|
|
162
|
+
const group = (router, prefix, callback, options) => {
|
|
163
|
+
callback(scopeRouter(router, prefix, options?.middleware));
|
|
149
164
|
};
|
|
150
165
|
function buildResourcePaths(prefix, path) {
|
|
151
166
|
const base = joinPaths(prefix, path);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginAutoImports.d.ts","sourceRoot":"","sources":["../../../src/runtime/PluginAutoImports.ts"],"names":[],"mappings":"AAOA,KAAK,YAAY,GACb;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAChC;IACE,EAAE,EAAE,KAAK,CAAC;IACV,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,WAAW,GAAG,eAAe,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;
|
|
1
|
+
{"version":3,"file":"PluginAutoImports.d.ts","sourceRoot":"","sources":["../../../src/runtime/PluginAutoImports.ts"],"names":[],"mappings":"AAOA,KAAK,YAAY,GACb;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAChC;IACE,EAAE,EAAE,KAAK,CAAC;IACV,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,WAAW,GAAG,eAAe,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAwBN,eAAO,MAAM,iBAAiB;IAC5B;;;;;;OAMG;mCACkC,OAAO,CAAC,YAAY,CAAC;EAgC1D,CAAC"}
|
|
@@ -1,21 +1,9 @@
|
|
|
1
1
|
import { pathToFileURL } from '../node-singletons/url.js';
|
|
2
|
-
import {
|
|
2
|
+
import { readEnvString } from '../common/ExternalServiceUtils.js';
|
|
3
3
|
import { Logger } from '../config/logger.js';
|
|
4
4
|
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
5
5
|
import { existsSync } from '../node-singletons/fs.js';
|
|
6
6
|
import * as path from '../node-singletons/path.js';
|
|
7
|
-
const readEnvString = (key) => {
|
|
8
|
-
const anyEnv = Env;
|
|
9
|
-
const fromEnv = typeof anyEnv.get === 'function' ? anyEnv.get(key, '') : '';
|
|
10
|
-
if (typeof fromEnv === 'string' && fromEnv.trim() !== '')
|
|
11
|
-
return fromEnv;
|
|
12
|
-
if (typeof process !== 'undefined') {
|
|
13
|
-
const raw = process.env?.[key];
|
|
14
|
-
if (typeof raw === 'string')
|
|
15
|
-
return raw;
|
|
16
|
-
}
|
|
17
|
-
return fromEnv ?? '';
|
|
18
|
-
};
|
|
19
7
|
const getProjectCwd = () => process.cwd();
|
|
20
8
|
const getProjectRootEnv = () => readEnvString('ZINTRUST_PROJECT_ROOT');
|
|
21
9
|
const resolveProjectRoot = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../../src/runtime/PluginManager.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../../src/runtime/PluginManager.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAgShE,eAAO,MAAM,aAAa;IACxB;;OAEG;YACK,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAIxC;;OAEG;yBACkB,MAAM,GAAG,MAAM,GAAG,IAAI;IAW3C;;OAEG;0BACyB,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA0DrD;;OAEG;sBACqB,MAAM,YAAY;QAAE,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BrF;;;;OAIG;wBACuB,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;EA2ChD,CAAC"}
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* Plugin Manager
|
|
4
4
|
* Handles installation and removal of framework plugins.
|
|
5
5
|
*/
|
|
6
|
-
import { execSync } from '../node-singletons/child-process.js';
|
|
7
6
|
import { SpawnUtil } from '../cli/utils/spawn.js';
|
|
7
|
+
import { readEnvString } from '../common/ExternalServiceUtils.js';
|
|
8
8
|
import { esmDirname, resolvePackageManager } from '../common/index.js';
|
|
9
|
-
import { Env } from '../config/env.js';
|
|
10
9
|
import { Logger } from '../config/logger.js';
|
|
11
10
|
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
11
|
+
import { execSync } from '../node-singletons/child-process.js';
|
|
12
12
|
import { existsSync, fsPromises as fs } from '../node-singletons/fs.js';
|
|
13
13
|
import * as path from '../node-singletons/path.js';
|
|
14
14
|
import { PluginRegistry } from './PluginRegistry.js';
|
|
@@ -27,18 +27,6 @@ function findPackageRoot(startDir) {
|
|
|
27
27
|
// Fallback to a reasonable default if package.json isn't found.
|
|
28
28
|
return path.resolve(startDir, '../..');
|
|
29
29
|
}
|
|
30
|
-
const readEnvString = (key) => {
|
|
31
|
-
const anyEnv = Env;
|
|
32
|
-
const fromEnv = typeof anyEnv.get === 'function' ? anyEnv.get(key, '') : '';
|
|
33
|
-
if (typeof fromEnv === 'string' && fromEnv.trim() !== '')
|
|
34
|
-
return fromEnv;
|
|
35
|
-
if (typeof process !== 'undefined') {
|
|
36
|
-
const raw = process.env?.[key];
|
|
37
|
-
if (typeof raw === 'string')
|
|
38
|
-
return raw;
|
|
39
|
-
}
|
|
40
|
-
return fromEnv ?? '';
|
|
41
|
-
};
|
|
42
30
|
const getProjectCwd = () => process.cwd();
|
|
43
31
|
const getProjectRootEnv = () => readEnvString('ZINTRUST_PROJECT_ROOT');
|
|
44
32
|
const getAllowPostInstallEnv = () => readEnvString('ZINTRUST_ALLOW_POSTINSTALL').trim();
|
|
@@ -43,8 +43,8 @@ export const PluginRegistry = {
|
|
|
43
43
|
devDependencies: ['@types/jsonwebtoken', '@types/bcrypt'],
|
|
44
44
|
templates: [
|
|
45
45
|
{
|
|
46
|
-
source: '
|
|
47
|
-
destination: 'src/
|
|
46
|
+
source: 'auth/Auth.ts.tpl',
|
|
47
|
+
destination: 'src/auth/Auth.ts',
|
|
48
48
|
},
|
|
49
49
|
],
|
|
50
50
|
postInstall: {
|
package/src/start.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/start.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/start.ts"],"names":[],"mappings":"AAwBA,eAAO,MAAM,UAAU,GAAI,eAAe,MAAM,KAAG,OAYlD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,KAAK,QAAa,OAAO,CAAC,IAAI,CAO1C,CAAC;AAEF;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEpE;;GAEG;AACH,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAElD;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC"}
|
package/src/start.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
+
import { ZintrustLang } from './lang/lang.js';
|
|
1
2
|
const isNodeRuntime = () => {
|
|
2
3
|
// Avoid importing any `node:*` modules so this file remains Worker-safe.
|
|
3
4
|
// In Workers/Deno, `process` is typically undefined.
|
|
4
|
-
return (typeof process !==
|
|
5
|
-
typeof process ===
|
|
5
|
+
return (typeof process !== ZintrustLang.UNDEFINED &&
|
|
6
|
+
typeof process === ZintrustLang.OBJECT &&
|
|
6
7
|
process !== null &&
|
|
7
|
-
typeof process.versions ===
|
|
8
|
+
typeof process.versions === ZintrustLang.OBJECT);
|
|
8
9
|
};
|
|
9
10
|
const fileUrlToPathLike = (value) => {
|
|
10
|
-
if (!value.startsWith(
|
|
11
|
+
if (!value.startsWith(ZintrustLang.FILE_PROTOCOL))
|
|
11
12
|
return value;
|
|
12
13
|
// Basic file URL decoding (sufficient for macOS/Linux paths).
|
|
13
14
|
try {
|
|
14
|
-
return decodeURIComponent(value.slice(
|
|
15
|
+
return decodeURIComponent(value.slice(ZintrustLang.FILE_PROTOCOL.length));
|
|
15
16
|
}
|
|
16
17
|
catch {
|
|
17
|
-
return value.slice(
|
|
18
|
+
return value.slice(ZintrustLang.FILE_PROTOCOL.length);
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
21
|
export const isNodeMain = (importMetaUrl) => {
|
|
@@ -41,7 +42,7 @@ export const start = async () => {
|
|
|
41
42
|
// Compiled output places bootstrap at `dist/src/boot/bootstrap.js`.
|
|
42
43
|
// This file compiles to `dist/src/start.js`, so relative import is stable.
|
|
43
44
|
// In unit tests, importing bootstrap has heavy side effects (starts server + exits).
|
|
44
|
-
await import('./boot/' +
|
|
45
|
+
await import('./boot/' + ZintrustLang.BOOTSTRAPJS);
|
|
45
46
|
};
|
|
46
47
|
/**
|
|
47
48
|
* Cloudflare Workers entry (module worker style).
|
|
@@ -25,8 +25,8 @@ const MAPPINGS = [
|
|
|
25
25
|
description: 'SQL Server database adapter',
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
|
-
basePath: 'src/
|
|
29
|
-
templatePath: 'src/templates/
|
|
28
|
+
basePath: 'src/auth/Auth.ts',
|
|
29
|
+
templatePath: 'src/templates/auth/Auth.ts.tpl',
|
|
30
30
|
description: 'Authentication feature with JWT & bcrypt',
|
|
31
31
|
},
|
|
32
32
|
{
|
|
@@ -32,8 +32,8 @@ const MAPPINGS: TemplateMapping[] = [
|
|
|
32
32
|
description: 'SQL Server database adapter',
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
|
-
basePath: 'src/
|
|
36
|
-
templatePath: 'src/templates/
|
|
35
|
+
basePath: 'src/auth/Auth.ts',
|
|
36
|
+
templatePath: 'src/templates/auth/Auth.ts.tpl',
|
|
37
37
|
description: 'Authentication feature with JWT & bcrypt',
|
|
38
38
|
},
|
|
39
39
|
{
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// TEMPLATE_START
|
|
2
|
+
|
|
3
|
+
import { generateSecureJobId } from '@zintrust/core';
|
|
4
|
+
import { Logger } from '@zintrust/core';
|
|
5
|
+
|
|
6
|
+
export interface QueueJob {
|
|
7
|
+
id: string;
|
|
8
|
+
data: unknown;
|
|
9
|
+
timestamp: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Queue Feature Template
|
|
14
|
+
*
|
|
15
|
+
* This template shows both in-memory and BullMQ Redis options.
|
|
16
|
+
* Choose the appropriate implementation based on your needs:
|
|
17
|
+
*
|
|
18
|
+
* 1. In-Memory Queue: For testing and development only
|
|
19
|
+
* 2. BullMQ Redis Queue: For production with enterprise features
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
// Option 1: Simple In-Memory Queue (Development/Testing Only)
|
|
23
|
+
export const InMemoryQueue = Object.freeze({
|
|
24
|
+
jobs: [] as QueueJob[],
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Add a job to the queue
|
|
28
|
+
*/
|
|
29
|
+
add<T>(data: T): string {
|
|
30
|
+
const id = generateSecureJobId();
|
|
31
|
+
const job: QueueJob = {
|
|
32
|
+
id,
|
|
33
|
+
data,
|
|
34
|
+
timestamp: Date.now(),
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
InMemoryQueue.jobs.push(job);
|
|
38
|
+
Logger.info(`[InMemoryQueue] Job added: ${id}`);
|
|
39
|
+
return id;
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Process jobs
|
|
44
|
+
*/
|
|
45
|
+
async process(handler: (job: QueueJob) => Promise<void>): Promise<void> {
|
|
46
|
+
Logger.info('[InMemoryQueue] Processing jobs...');
|
|
47
|
+
const jobsToProcess = [...InMemoryQueue.jobs];
|
|
48
|
+
InMemoryQueue.jobs.length = 0;
|
|
49
|
+
await Promise.all(jobsToProcess.map(async (job) => handler(job)));
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Option 2: BullMQ Redis Queue (Production Recommended)
|
|
54
|
+
// To use this, set QUEUE_DRIVER=redis in your environment
|
|
55
|
+
// Configure BullMQ settings with BULLMQ_* environment variables:
|
|
56
|
+
// - BULLMQ_REMOVE_ON_COMPLETE (default: 100)
|
|
57
|
+
// - BULLMQ_REMOVE_ON_FAIL (default: 50)
|
|
58
|
+
// - BULLMQ_DEFAULT_ATTEMPTS (default: 3)
|
|
59
|
+
// - BULLMQ_BACKOFF_DELAY (default: 2000)
|
|
60
|
+
// - BULLMQ_BACKOFF_TYPE (default: 'exponential')
|
|
61
|
+
|
|
62
|
+
export const RedisQueue = Object.freeze({
|
|
63
|
+
/**
|
|
64
|
+
* Add a job to the queue using BullMQ Redis
|
|
65
|
+
* This provides enterprise features: auto-scaling, circuit breaker, DLQ, monitoring
|
|
66
|
+
*/
|
|
67
|
+
async add<T>(data: T): Promise<string> {
|
|
68
|
+
// Import dynamically to avoid circular dependencies
|
|
69
|
+
const { Queue } = await import('@zintrust/core');
|
|
70
|
+
|
|
71
|
+
const id = generateSecureJobId();
|
|
72
|
+
const job: QueueJob = {
|
|
73
|
+
id,
|
|
74
|
+
data,
|
|
75
|
+
timestamp: Date.now(),
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// Uses BullMQ when QUEUE_DRIVER=redis
|
|
79
|
+
const jobId = await Queue.enqueue('default', job);
|
|
80
|
+
Logger.info(`[RedisQueue] Job added via BullMQ: ${jobId}`);
|
|
81
|
+
return jobId;
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Note: For BullMQ, use proper workers instead of manual processing
|
|
86
|
+
* See documentation for setting up BullMQ workers
|
|
87
|
+
*/
|
|
88
|
+
async process(_handler: (job: QueueJob) => Promise<void>): Promise<void> {
|
|
89
|
+
Logger.warn('[RedisQueue] Manual processing not recommended for BullMQ. Use proper workers instead.');
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Default export - choose based on environment
|
|
94
|
+
export const Queue = (() => {
|
|
95
|
+
const driver = process.env.QUEUE_DRIVER;
|
|
96
|
+
|
|
97
|
+
switch (driver) {
|
|
98
|
+
case 'redis':
|
|
99
|
+
return RedisQueue; // BullMQ Redis with enterprise features
|
|
100
|
+
case 'sqs':
|
|
101
|
+
case 'rabbitmq':
|
|
102
|
+
case 'database':
|
|
103
|
+
// For production drivers, use the main Queue API from @tools/queue/Queue
|
|
104
|
+
// This template only provides in-memory and Redis implementations
|
|
105
|
+
Logger.warn(`Queue driver '${driver}' not implemented in this template. Falling back to in-memory.`);
|
|
106
|
+
return InMemoryQueue; // Fall back to in-memory for unsupported drivers
|
|
107
|
+
case 'sync':
|
|
108
|
+
case 'inmemory':
|
|
109
|
+
default:
|
|
110
|
+
return InMemoryQueue; // Simple in-memory for development
|
|
111
|
+
}
|
|
112
|
+
})();
|
|
113
|
+
|
|
114
|
+
// TEMPLATE_END
|
|
@@ -72,6 +72,28 @@ const userControllerMethods: IUserController = {
|
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Fill user data
|
|
77
|
+
* POST /users/:id/fill
|
|
78
|
+
*/
|
|
79
|
+
async fill(req: IRequest, res: IResponse): Promise<void> {
|
|
80
|
+
try {
|
|
81
|
+
const id = req.params['id'];
|
|
82
|
+
const user = await User.find(id);
|
|
83
|
+
if (user === null) {
|
|
84
|
+
res.status(404).json({ error: 'User not found' });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const body = req.body;
|
|
88
|
+
user.fill(body);
|
|
89
|
+
await user.save();
|
|
90
|
+
res.json({ message: 'User data filled', user });
|
|
91
|
+
} catch (error) {
|
|
92
|
+
Logger.error('Error filling user data:', error);
|
|
93
|
+
res.status(500).json({ error: 'Failed to fill user data' });
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
|
|
75
97
|
/**
|
|
76
98
|
* Show edit form
|
|
77
99
|
* GET /users/:id/edit
|
|
@@ -6,6 +6,23 @@ import { Env, type QueueConfigOverrides, type QueueDriverName } from '@zintrust/
|
|
|
6
6
|
* Keep this file declarative:
|
|
7
7
|
* - Core owns env parsing/default logic.
|
|
8
8
|
* - Projects can override config by editing values below.
|
|
9
|
+
*
|
|
10
|
+
* BullMQ Redis Driver Environment Variables:
|
|
11
|
+
* When QUEUE_DRIVER=redis, the system uses BullMQ for enterprise features.
|
|
12
|
+
* Additional BullMQ-specific settings can be configured via environment variables:
|
|
13
|
+
*
|
|
14
|
+
* | Environment Variable | Default | Description | Example |
|
|
15
|
+
* |---------------------|---------|-------------|---------|
|
|
16
|
+
* | BULLMQ_REMOVE_ON_COMPLETE | 100 | Number of completed jobs to keep in Redis | 200 |
|
|
17
|
+
* | BULLMQ_REMOVE_ON_FAIL | 50 | Number of failed jobs to keep in Redis | 25 |
|
|
18
|
+
* | BULLMQ_DEFAULT_ATTEMPTS | 3 | Default retry attempts for jobs | 5 |
|
|
19
|
+
* | BULLMQ_BACKOFF_DELAY | 2000 | Delay between retries (milliseconds) | 5000 |
|
|
20
|
+
* | BULLMQ_BACKOFF_TYPE | exponential | Backoff strategy: 'exponential', 'fixed', 'custom' | fixed |
|
|
21
|
+
*
|
|
22
|
+
* Usage Examples:
|
|
23
|
+
* Development: BULLMQ_REMOVE_ON_COMPLETE=500 BULLMQ_DEFAULT_ATTEMPTS=2
|
|
24
|
+
* Production: BULLMQ_REMOVE_ON_COMPLETE=50 BULLMQ_DEFAULT_ATTEMPTS=5
|
|
25
|
+
* High-Volume: BULLMQ_REMOVE_ON_COMPLETE=10 BULLMQ_BACKOFF_DELAY=500
|
|
9
26
|
*/
|
|
10
27
|
|
|
11
28
|
export default {
|
|
@@ -25,6 +42,8 @@ export default {
|
|
|
25
42
|
port: Env.getInt('REDIS_PORT', 6379),
|
|
26
43
|
password: Env.get('REDIS_PASSWORD'),
|
|
27
44
|
database: Env.getInt('REDIS_QUEUE_DB', 1),
|
|
45
|
+
// Note: Redis driver uses BullMQ for enterprise features
|
|
46
|
+
// See BullMQ environment variables in file header for customization
|
|
28
47
|
},
|
|
29
48
|
rabbitmq: {
|
|
30
49
|
driver: 'rabbitmq' as const,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AwsSecretsManager.d.ts","sourceRoot":"","sources":["../../../../../src/toolkit/Secrets/providers/AwsSecretsManager.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,cAAc,GAAG;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;
|
|
1
|
+
{"version":3,"file":"AwsSecretsManager.d.ts","sourceRoot":"","sources":["../../../../../src/toolkit/Secrets/providers/AwsSecretsManager.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,cAAc,GAAG;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AA0GF,eAAO,MAAM,iBAAiB;qBACX;QACf,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;QACzE,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KAC9D;iBAsDY,MAAM,EAAE;EAcrB,CAAC;AAEH,eAAe,iBAAiB,CAAC"}
|
|
@@ -1,19 +1,7 @@
|
|
|
1
|
+
import { readEnvString } from '../../../common/ExternalServiceUtils.js';
|
|
1
2
|
import { AwsSigV4 } from '../../../common/index.js';
|
|
2
|
-
import { Env } from '../../../config/env.js';
|
|
3
3
|
import { ErrorFactory } from '../../../exceptions/ZintrustError.js';
|
|
4
4
|
const sha256Hex = (data) => AwsSigV4.sha256Hex(data);
|
|
5
|
-
const readEnvString = (key) => {
|
|
6
|
-
const anyEnv = Env;
|
|
7
|
-
const fromEnv = typeof anyEnv.get === 'function' ? anyEnv.get(key, '') : '';
|
|
8
|
-
if (typeof fromEnv === 'string' && fromEnv.trim() !== '')
|
|
9
|
-
return fromEnv;
|
|
10
|
-
if (typeof process !== 'undefined') {
|
|
11
|
-
const raw = process.env?.[key];
|
|
12
|
-
if (typeof raw === 'string')
|
|
13
|
-
return raw;
|
|
14
|
-
}
|
|
15
|
-
return fromEnv ?? '';
|
|
16
|
-
};
|
|
17
5
|
const buildAuthorization = (params) => {
|
|
18
6
|
const canonicalUri = '/';
|
|
19
7
|
const canonicalQueryString = '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudflareKv.d.ts","sourceRoot":"","sources":["../../../../../src/toolkit/Secrets/providers/CloudflareKv.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY;qBACN;QACf,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;QACxE,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KAC/E;
|
|
1
|
+
{"version":3,"file":"CloudflareKv.d.ts","sourceRoot":"","sources":["../../../../../src/toolkit/Secrets/providers/CloudflareKv.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY;qBACN;QACf,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;QACxE,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KAC/E;iBAsEY,MAAM,EAAE;EAcrB,CAAC;AAEH,eAAe,YAAY,CAAC"}
|
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readEnvString } from '../../../common/ExternalServiceUtils.js';
|
|
2
2
|
import { ErrorFactory } from '../../../exceptions/ZintrustError.js';
|
|
3
3
|
export const CloudflareKv = Object.freeze({
|
|
4
4
|
createFromEnv() {
|
|
5
|
-
const readEnvString = (key) => {
|
|
6
|
-
const anyEnv = Env;
|
|
7
|
-
const fromEnv = typeof anyEnv.get === 'function' ? anyEnv.get(key, '') : '';
|
|
8
|
-
if (typeof fromEnv === 'string' && fromEnv.trim() !== '')
|
|
9
|
-
return fromEnv;
|
|
10
|
-
if (typeof process !== 'undefined') {
|
|
11
|
-
const raw = process.env?.[key];
|
|
12
|
-
if (typeof raw === 'string')
|
|
13
|
-
return raw;
|
|
14
|
-
}
|
|
15
|
-
return fromEnv ?? '';
|
|
16
|
-
};
|
|
17
5
|
const accountId = readEnvString('CLOUDFLARE_ACCOUNT_ID');
|
|
18
6
|
const apiToken = readEnvString('CLOUDFLARE_API_TOKEN');
|
|
19
7
|
const defaultNamespaceId = readEnvString('CLOUDFLARE_KV_NAMESPACE_ID');
|
|
@@ -71,13 +59,13 @@ export const CloudflareKv = Object.freeze({
|
|
|
71
59
|
},
|
|
72
60
|
doctorEnv() {
|
|
73
61
|
const missing = [];
|
|
74
|
-
const accountId = (
|
|
62
|
+
const accountId = readEnvString('CLOUDFLARE_ACCOUNT_ID').trim();
|
|
75
63
|
if (accountId === '')
|
|
76
64
|
missing.push('CLOUDFLARE_ACCOUNT_ID');
|
|
77
|
-
const apiToken = (
|
|
65
|
+
const apiToken = readEnvString('CLOUDFLARE_API_TOKEN').trim();
|
|
78
66
|
if (apiToken === '')
|
|
79
67
|
missing.push('CLOUDFLARE_API_TOKEN');
|
|
80
|
-
const namespaceId = (
|
|
68
|
+
const namespaceId = readEnvString('CLOUDFLARE_KV_NAMESPACE_ID').trim();
|
|
81
69
|
if (namespaceId === '')
|
|
82
70
|
missing.push('CLOUDFLARE_KV_NAMESPACE_ID');
|
|
83
71
|
return missing;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Redis.d.ts","sourceRoot":"","sources":["../../../../../src/tools/broadcast/drivers/Redis.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Redis.d.ts","sourceRoot":"","sources":["../../../../../src/tools/broadcast/drivers/Redis.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5D,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAOF,eAAO,MAAM,WAAW;4BAED,0BAA0B,WAAW,MAAM,SAAS,MAAM,QAAQ,OAAO;;;;CAsB5F,CAAC;AAEL,eAAe,WAAW,CAAC"}
|
|
@@ -1,63 +1,15 @@
|
|
|
1
|
+
import { ensureDriver } from '../../../config/redis.js';
|
|
1
2
|
import { ErrorFactory } from '../../../exceptions/ZintrustError.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
throw ErrorFactory.createConfigError('Redis broadcast driver requires host');
|
|
7
|
-
if (!Number.isFinite(port) || port <= 0) {
|
|
8
|
-
throw ErrorFactory.createConfigError('Redis broadcast driver requires a valid port');
|
|
9
|
-
}
|
|
10
|
-
const password = (config.password ?? '').trim();
|
|
11
|
-
const authPart = password ? `:${encodeURIComponent(password)}@` : '';
|
|
12
|
-
return `redis://${authPart}${host}:${port}`;
|
|
3
|
+
import { createRedisKey } from '../../redis/RedisKeyManager.js';
|
|
4
|
+
const normalizePrefix = (value) => {
|
|
5
|
+
const prefix = (value ?? '').trim();
|
|
6
|
+
return prefix || 'broadcast:';
|
|
13
7
|
};
|
|
14
8
|
export const RedisDriver = (() => {
|
|
15
|
-
let client = null;
|
|
16
|
-
let connected = false;
|
|
17
|
-
const ensureClient = async (config) => {
|
|
18
|
-
// Always validate config even if a client is already cached
|
|
19
|
-
const url = buildRedisUrl(config);
|
|
20
|
-
if (connected && client !== null)
|
|
21
|
-
return client;
|
|
22
|
-
// Import lazily so package is optional for environments that don't use Redis
|
|
23
|
-
try {
|
|
24
|
-
const mod = (await import('redis'));
|
|
25
|
-
client = mod.createClient({ url });
|
|
26
|
-
if (typeof client.connect === 'function') {
|
|
27
|
-
try {
|
|
28
|
-
await client.connect();
|
|
29
|
-
connected = true;
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
connected = false;
|
|
33
|
-
throw ErrorFactory.createTryCatchError('Redis broadcast driver failed to connect', err);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
connected = true;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
const globalFake = globalThis
|
|
42
|
-
.__fakeRedisClient;
|
|
43
|
-
if (globalFake === undefined) {
|
|
44
|
-
throw ErrorFactory.createConfigError("Redis broadcast driver requires the 'redis' package (run `zin add broadcast:redis` / `zin plugin install broadcast:redis`, or `npm install redis`) or a test fake client set in globalThis.__fakeRedisClient");
|
|
45
|
-
}
|
|
46
|
-
client = globalFake;
|
|
47
|
-
connected = true;
|
|
48
|
-
}
|
|
49
|
-
if (client === null)
|
|
50
|
-
throw ErrorFactory.createConfigError('Redis client could not be initialized');
|
|
51
|
-
return client;
|
|
52
|
-
};
|
|
53
|
-
const normalizePrefix = (value) => {
|
|
54
|
-
const prefix = (value ?? '').trim();
|
|
55
|
-
return prefix || 'broadcast:';
|
|
56
|
-
};
|
|
57
9
|
return {
|
|
58
10
|
async send(config, channel, event, data) {
|
|
59
|
-
const cli = await
|
|
60
|
-
const
|
|
11
|
+
const cli = await ensureDriver('publish');
|
|
12
|
+
const prefixedChannel = createRedisKey(`broadcast:${normalizePrefix(config.channelPrefix)}${channel}`);
|
|
61
13
|
let message;
|
|
62
14
|
try {
|
|
63
15
|
message = JSON.stringify({ event, data });
|
|
@@ -65,7 +17,7 @@ export const RedisDriver = (() => {
|
|
|
65
17
|
catch (err) {
|
|
66
18
|
throw ErrorFactory.createTryCatchError('Failed to serialize broadcast payload', err);
|
|
67
19
|
}
|
|
68
|
-
const published = await cli.publish(
|
|
20
|
+
const published = await cli.publish(prefixedChannel, message);
|
|
69
21
|
return { ok: true, published };
|
|
70
22
|
},
|
|
71
23
|
};
|
package/src/tools/mail/Mail.d.ts
CHANGED
|
@@ -1,30 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export type SendMailInput = {
|
|
3
|
-
to: string | string[];
|
|
4
|
-
subject: string;
|
|
5
|
-
text: string;
|
|
6
|
-
html?: string;
|
|
7
|
-
from?: {
|
|
8
|
-
address?: string;
|
|
9
|
-
name?: string;
|
|
10
|
-
};
|
|
11
|
-
attachments?: AttachmentInput[];
|
|
12
|
-
};
|
|
13
|
-
export type SendMailResult = {
|
|
14
|
-
ok: boolean;
|
|
15
|
-
driver: 'sendgrid' | 'disabled' | 'smtp' | 'ses' | 'mailgun' | 'nodemailer';
|
|
16
|
-
messageId?: string;
|
|
17
|
-
};
|
|
18
|
-
export declare const Mail: Readonly<{
|
|
19
|
-
/**
|
|
20
|
-
* Select a named mailer (key from mailConfig.drivers).
|
|
21
|
-
*
|
|
22
|
-
* Example: `Mail.mailer('transactional').send(...)`
|
|
23
|
-
*/
|
|
24
|
-
mailer(name: string): Readonly<{
|
|
25
|
-
send: (input: SendMailInput) => Promise<SendMailResult>;
|
|
26
|
-
}>;
|
|
27
|
-
send(input: SendMailInput): Promise<SendMailResult>;
|
|
28
|
-
}>;
|
|
29
|
-
export default Mail;
|
|
1
|
+
export { default, Mail } from './index';
|
|
30
2
|
//# sourceMappingURL=Mail.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mail.d.ts","sourceRoot":"","sources":["../../../../src/tools/mail/Mail.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Mail.d.ts","sourceRoot":"","sources":["../../../../src/tools/mail/Mail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC"}
|