arkos 1.7.3-rc → 1.7.5-rc
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/cjs/components/arkos-gateway/arkos-gateway.js +8 -3
- package/dist/cjs/components/arkos-gateway/arkos-gateway.js.map +1 -1
- package/dist/cjs/components/arkos-gateway/types.js.map +1 -1
- package/dist/cjs/exports/websockets.js.map +1 -1
- package/dist/cjs/modules/auth/auth.router.js +2 -1
- package/dist/cjs/modules/auth/auth.router.js.map +1 -1
- package/dist/cjs/modules/file-upload/file-upload.router.js +2 -1
- package/dist/cjs/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-swagger-default-configs.js +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-swagger-default-configs.js.map +1 -1
- package/dist/cjs/utils/arkos-router/arkos-router-openapi-manager.js.map +1 -1
- package/dist/cjs/utils/arkos-router/route-config-validator.js +5 -5
- package/dist/cjs/utils/arkos-router/route-config-validator.js.map +1 -1
- package/dist/cjs/utils/cli/generate.js +8 -3
- package/dist/cjs/utils/cli/generate.js.map +1 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/router-template.js +2 -3
- package/dist/cjs/utils/cli/utils/template-generator/templates/router-template.js.map +1 -1
- package/dist/cjs/utils/dynamic-loader.js +2 -2
- package/dist/cjs/utils/dynamic-loader.js.map +1 -1
- package/dist/esm/components/arkos-gateway/arkos-gateway.js +8 -3
- package/dist/esm/components/arkos-gateway/arkos-gateway.js.map +1 -1
- package/dist/esm/components/arkos-gateway/types.js.map +1 -1
- package/dist/esm/exports/websockets.js.map +1 -1
- package/dist/esm/modules/auth/auth.router.js +2 -1
- package/dist/esm/modules/auth/auth.router.js.map +1 -1
- package/dist/esm/modules/file-upload/file-upload.router.js +2 -1
- package/dist/esm/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/get-swagger-default-configs.js +1 -1
- package/dist/esm/modules/swagger/utils/helpers/get-swagger-default-configs.js.map +1 -1
- package/dist/esm/utils/arkos-router/arkos-router-openapi-manager.js.map +1 -1
- package/dist/esm/utils/arkos-router/route-config-validator.js +5 -5
- package/dist/esm/utils/arkos-router/route-config-validator.js.map +1 -1
- package/dist/esm/utils/cli/generate.js +8 -3
- package/dist/esm/utils/cli/generate.js.map +1 -1
- package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/router-template.js +2 -3
- package/dist/esm/utils/cli/utils/template-generator/templates/router-template.js.map +1 -1
- package/dist/esm/utils/dynamic-loader.js +2 -2
- package/dist/esm/utils/dynamic-loader.js.map +1 -1
- package/dist/types/components/arkos-gateway/arkos-gateway.d.ts +6 -5
- package/dist/types/components/arkos-gateway/types.d.ts +7 -0
- package/dist/types/exports/websockets.d.ts +1 -1
- package/package.json +12 -31
|
@@ -23,6 +23,7 @@ class IArkosGateway {
|
|
|
23
23
|
constructor(config) {
|
|
24
24
|
this.events = [];
|
|
25
25
|
this.pipes = [];
|
|
26
|
+
this.middlewares = [];
|
|
26
27
|
this.gateways = [];
|
|
27
28
|
this.hooks = [];
|
|
28
29
|
this.config = config;
|
|
@@ -39,7 +40,7 @@ class IArkosGateway {
|
|
|
39
40
|
this.gateways.push(item);
|
|
40
41
|
}
|
|
41
42
|
else if (typeof item === "function") {
|
|
42
|
-
this.
|
|
43
|
+
this.middlewares.push(item);
|
|
43
44
|
}
|
|
44
45
|
else {
|
|
45
46
|
throw new Error(`Invalid value for gateway.use() — expected an ArkosGateway instance or a middleware function but received "${typeof item}".`);
|
|
@@ -106,7 +107,7 @@ class IArkosGateway {
|
|
|
106
107
|
io._arkosGatewayRegistered = true;
|
|
107
108
|
this._register(io, undefined, this.hooks || [], this.pipes || [], options);
|
|
108
109
|
}
|
|
109
|
-
_register(io, parentConfig, inheritedHooks = [], inheritedPipes = [], options = {}) {
|
|
110
|
+
_register(io, parentConfig, inheritedHooks = [], inheritedPipes = [], options = {}, inheritedMiddlewares = []) {
|
|
110
111
|
options.store = options.store ?? memory_gateway_store_1.defaultGatewayStore;
|
|
111
112
|
const { store } = options;
|
|
112
113
|
const parentName = parentConfig?.name;
|
|
@@ -125,6 +126,7 @@ class IArkosGateway {
|
|
|
125
126
|
parentConfig?.authentication !== false;
|
|
126
127
|
const resolvedRateLimit = this.config.rateLimit ?? parentConfig?.rateLimit;
|
|
127
128
|
const resolvedHooks = [...inheritedHooks, ...this.hooks];
|
|
129
|
+
const resolvedMiddlewares = [...inheritedMiddlewares, ...this.middlewares];
|
|
128
130
|
const connectHandlers = resolvedHooks
|
|
129
131
|
.filter((h) => h.type === "connection")
|
|
130
132
|
.map((h) => h.handler);
|
|
@@ -134,6 +136,9 @@ class IArkosGateway {
|
|
|
134
136
|
const errorHandlers = resolvedHooks
|
|
135
137
|
.filter((h) => h.type === "error")
|
|
136
138
|
.map((h) => h.handler);
|
|
139
|
+
for (const middleware of resolvedMiddlewares) {
|
|
140
|
+
ns.use((socket, next) => middleware(socket, next));
|
|
141
|
+
}
|
|
137
142
|
if (resolvedAuth && (0, arkos_config_helpers_1.isAuthenticationEnabled)()) {
|
|
138
143
|
ns.use(async (socket, next) => {
|
|
139
144
|
socket = socket;
|
|
@@ -338,7 +343,7 @@ For further help see https://www.arkosjs.com/docs/core-concepts/authentication/s
|
|
|
338
343
|
name: namespaceName,
|
|
339
344
|
authentication: resolvedAuth,
|
|
340
345
|
rateLimit: resolvedRateLimit,
|
|
341
|
-
}, resolvedHooks, inheritedPipes, options);
|
|
346
|
+
}, resolvedHooks, inheritedPipes, options, resolvedMiddlewares);
|
|
342
347
|
}
|
|
343
348
|
}
|
|
344
349
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arkos-gateway.js","sourceRoot":"","sources":["../../../../src/components/arkos-gateway/arkos-gateway.ts"],"names":[],"mappings":";;;;;;AAiBA,qDAAwE;AAC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,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClC,KAAK,CAAC,SAAS,CACb,EAAE,EACF;gBACE,IAAI,EAAE,aAAa;gBACnB,cAAc,EAAE,YAAY;gBAC5B,SAAS,EAAE,iBAAiB;aAC7B,EACD,aAAa,EACb,cAAc,EACd,OAAO,CACR,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAhkBD,sCAgkBC;AA6BD,SAAS,YAAY,CAAC,MAA0B;IAC9C,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC;AAED,kBAAe,YAAY,CAAC","sourcesContent":["import {\n ArkosGatewayConfig,\n ArkosGatewayErrorHandler,\n ArkosGatewayEventConfig,\n ArkosGatewayEventEntry,\n ArkosGatewayHandler,\n ArkosGatewayHookHandler,\n ArkosGatewayHookType,\n ArkosGatewayPipe,\n ArkosGatewayConnectionHandler,\n ArkosSocket,\n ArkosGatewayRegisterOptions,\n ArkosBroadcastOperator,\n ArkosEmitTarget,\n} from \"./types\";\nimport { Validator } from \"../../types/validation/validator\";\nimport { BroadcastOperator, Namespace, Server } from \"socket.io\";\nimport { authActionService, authService } from \"../../exports/services\";\nimport { checkRateLimit, clearRateLimitForSocket } from \"./utils/rate-limiter\";\nimport {\n handleArkosGatewayErrors,\n runArkosGatewayPipes,\n handleGatewayEventLog,\n handleGatewayLifecycleLog,\n} from \"./utils/helpers\";\nimport authHookManager from \"../../modules/auth/utils/auth-hooks-manager\";\nimport { getArkosConfig } from \"../../server\";\nimport validationManager from \"../../types/validation/validation-manager\";\nimport { loginRequiredError } from \"../../modules/auth/utils/auth-error-objects\";\nimport errorPrettifier from \"../../modules/base/utils/error-prettifier\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { defaultGatewayStore } from \"./utils/memory-gateway-store\";\nimport { ArkosBroadcastOperatorImpl, mountArkosSocketExtensions } from \"./socket-extensions\";\nimport {\n isAuthenticationEnabled,\n isUsingAuthentication,\n} from \"../../utils/helpers/arkos-config.helpers\";\nimport ExitError from \"../../utils/helpers/exit-error\";\nimport { getUserFileExtension } from \"../../utils/helpers/fs.helpers\";\nimport {\n BadRequestError,\n TooManyRequestsError,\n} from \"../../modules/error-handler/utils/errors\";\n\nexport class IArkosGateway {\n private config: ArkosGatewayConfig;\n private events: ArkosGatewayEventEntry[] = [];\n private pipes: ArkosGatewayPipe[] = [];\n private gateways: IArkosGateway[] = [];\n private hooks: {\n type: ArkosGatewayHookType;\n handler: ArkosGatewayHookHandler;\n }[] = [];\n private _nsp!: Namespace\n\n constructor(config: ArkosGatewayConfig) {\n this.config = config;\n this.config.name = config.name ?? \"web-socket\";\n }\n\n get nsp(): Omit<Namespace, keyof ArkosEmitTarget | keyof BroadcastOperator<any, any>> & ArkosBroadcastOperator {\n if (!this._nsp) throw new Error(`gateway.nsp accessed before register()`);\n return new ArkosBroadcastOperatorImpl(this._nsp.sockets, this._nsp) as any;\n }\n\n /**\n * Register a Socket.io connection-level middleware — runs before a socket\n * is accepted into this gateway's namespace. Also accepts a child\n * `ArkosGateway` which will inherit this gateway's name as prefix along\n * with its auth, rateLimit, and pipes.\n *\n * @example\n * chatGateway.use((socket, next) => {\n * console.log(\"incoming connection\", socket.id)\n * })\n *\n * // nested gateway\n * chatGateway.use(notificationsGateway)\n */\n use(...middlewareOrGateway: Array<ArkosGatewayPipe | IArkosGateway>): this {\n for (const item of middlewareOrGateway) {\n if (item instanceof IArkosGateway) {\n this.gateways.push(item);\n } else if (typeof item === \"function\") {\n this.pipes.push(item as ArkosGatewayPipe);\n } else {\n throw new Error(\n `Invalid value for gateway.use() — expected an ArkosGateway instance or a middleware function but received \"${typeof item}\".`\n );\n }\n }\n return this;\n }\n\n /**\n * Register a pipe — middleware that runs before event handlers.\n *\n * When called with a function only, the pipe runs before every event\n * handler in this gateway and drills down to child gateways.\n *\n * When called with an event config object, the pipe runs only for that\n * specific event.\n *\n * @example\n * // runs before every event in this gateway\n * chatGateway.pipe((socket, data) => {\n * })\n *\n * // runs only before \"send_message\"\n * chatGateway.pipe({ event: \"send_message\" }, (socket, data) => {\n * })\n */\n pipe(fn: ArkosGatewayPipe): this;\n pipe<TSchema extends Validator = any>(\n eventConfig: { event: string },\n fn: ArkosGatewayPipe\n ): this;\n pipe<TSchema extends Validator = any>(\n fnOrConfig: ArkosGatewayPipe | ArkosGatewayEventConfig<TSchema>,\n fn?: ArkosGatewayPipe\n ): this {\n if (typeof fnOrConfig === \"function\") {\n this.pipes.push(fnOrConfig);\n } else if (fnOrConfig && typeof fnOrConfig === \"object\" && fn) {\n const entry = this.events.find(\n (e) => e.config.event === fnOrConfig.event\n );\n if (entry) {\n entry.pipes = entry.pipes ?? [];\n entry.pipes.push(fn);\n } else {\n this.events.push({\n config: { event: fnOrConfig.event, _pipeOnly: true } as any,\n handler: null as any,\n pipes: [fn],\n });\n }\n } else {\n throw new Error(\n `Invalid arguments for gateway.pipe() — pass a middleware function, or an event config object followed by a middleware function.`\n );\n }\n return this;\n }\n\n /**\n * Register an event handler.\n *\n * @example\n * chatGateway.on(\n * { event: \"send_message\", validation: MessageSchema, ack: true },\n * (socket, data, ack) => {\n * socket.to(data.room).emit(\"receive_message\", data)\n * ack?.({ status: \"ok\" })\n * }\n * )\n */\n on<TSchema extends Validator = any>(\n eventConfig: ArkosGatewayEventConfig<TSchema>,\n handler: ArkosGatewayHandler\n ): this {\n if (eventConfig.disabled) return this;\n\n if (eventConfig.authorization && this.config.authentication === false) {\n throw new Error(\n `Event \"${eventConfig.event}\" on \"${this.config.name}\" gateway defines authorization rules ` +\n `but the gateway has authentication: false. Enable authentication on the gateway to use per-event authentication.`\n );\n }\n\n const deferred = this.events.find(\n (e) => (e.config as any)._pipeOnly && e.config.event === eventConfig.event\n );\n\n const entry: ArkosGatewayEventEntry = {\n config: eventConfig,\n handler,\n pipes: [...this.pipes, ...(deferred?.pipes ?? [])],\n };\n\n if (deferred) {\n const idx = this.events.indexOf(deferred);\n this.events.splice(idx, 1, entry);\n } else {\n this.events.push(entry);\n }\n\n if (typeof eventConfig?.authorization == \"object\")\n // To reuse later on\n (eventConfig.authorization as any)._authAction = authActionService.add(\n eventConfig.authorization!.action,\n eventConfig.authorization!.resource,\n {\n [eventConfig.authorization!.action]: eventConfig.authorization?.rule,\n }\n );\n\n return this;\n }\n\n /**\n * Register a lifecycle hook.\n *\n * - `\"connection\"` — called after a socket successfully connects and passes authentication.\n * - `\"disconnect\"` — called when a socket disconnects.\n * - `\"error\"` — called when an error is thrown inside any event handler.\n * If not registered, Arkos emits a default `\"error\"` event to the socket.\n *\n * @example\n * chatGateway.hook(\"connection\", (socket) => {\n * console.log(\"connected\", socket.user.id)\n * })\n *\n * chatGateway.hook(\"error\", (err, socket) => {\n * socket.emit(\"error\", { message: err.message })\n * })\n */\n hook(type: \"connection\", handler: ArkosGatewayConnectionHandler): this;\n hook(type: \"disconnect\", handler: ArkosGatewayConnectionHandler): this;\n hook(type: \"error\", handler: ArkosGatewayErrorHandler): this;\n hook(\n type: ArkosGatewayHookType,\n handler: ArkosGatewayConnectionHandler | ArkosGatewayErrorHandler\n ): this {\n this.hooks.push({ type, handler });\n return this;\n }\n\n /**\n * Wire this gateway into a Socket.io `Server` instance.\n * Registers the namespace, auth middleware, rate limiting, pipes,\n * and all event handlers — then recurses into child gateways.\n *\n * @example\n * const io = new Server(server)\n * chatGateway.register(io)\n */\n register(io: Server, options: ArkosGatewayRegisterOptions = {}): void {\n if ((io as any)._arkosGatewayRegistered)\n throw new Error(\n `The method gateway.register() can only be called once per io server instance. Use gateway.use() to compose gateways, see https://www.arkosjs.com/docs/guides/web-sockets/setup.`\n );\n (io as any)._arkosGatewayRegistered = true;\n this._register(io, undefined, this.hooks || [], this.pipes || [], options);\n }\n\n private _register(\n io: Server,\n parentConfig?: ArkosGatewayConfig,\n inheritedHooks: {\n type: ArkosGatewayHookType;\n handler: ArkosGatewayHookHandler;\n }[] = [],\n inheritedPipes: ArkosGatewayPipe[] = [],\n options: ArkosGatewayRegisterOptions = {}\n ): void {\n options.store = options.store ?? defaultGatewayStore;\n const { store } = options;\n\n const parentName = parentConfig?.name;\n const ownName = this.config.name;\n this.config = deepmerge(parentConfig || {}, this.config, {\n arrayMerge: (_, sourceArray) => sourceArray,\n });\n this.config.name = ownName;\n const localConfig = this.config;\n\n const namespaceName = parentName\n ? `${parentName.replace(/\\/$/, \"\")}/${ownName.replace(/^\\//, \"\")}`\n : (ownName ?? \"\");\n\n const ns = io.of(namespaceName);\n this._nsp = ns;\n\n const resolvedAuth =\n this.config.authentication !== false &&\n parentConfig?.authentication !== false;\n\n const resolvedRateLimit = this.config.rateLimit ?? parentConfig?.rateLimit;\n const resolvedHooks = [...inheritedHooks, ...this.hooks];\n\n const connectHandlers = resolvedHooks\n .filter((h) => h.type === \"connection\")\n .map((h) => h.handler as ArkosGatewayConnectionHandler);\n\n const disconnectHandlers = resolvedHooks\n .filter((h) => h.type === \"disconnect\")\n .map((h) => h.handler as ArkosGatewayConnectionHandler);\n\n const errorHandlers = resolvedHooks\n .filter((h) => h.type === \"error\")\n .map((h) => h.handler as ArkosGatewayErrorHandler);\n\n if (resolvedAuth && isAuthenticationEnabled()) {\n ns.use(async (socket: any, next) => {\n socket = socket as ArkosSocket;\n const startTime = new Date().getTime();\n try {\n await authHookManager.runAuthenticate(\n {\n context: socket,\n done: (err?: any) => {\n if (err) throw err;\n next();\n },\n },\n async (socket) => {\n const user = await authService.getAuthenticatedUser(socket);\n if (!user) throw loginRequiredError;\n return user;\n },\n \"currentUser\"\n );\n } catch (err: any) {\n handleArkosGatewayErrors(err, socket, errorHandlers, {\n startTime,\n namespace: this.config.name,\n event: \"authentication\",\n });\n next(err);\n }\n });\n } else if (\n (this.config.authentication || parentConfig?.authentication) &&\n !isUsingAuthentication()\n )\n throw ExitError(\n `Trying to authenticate gateway ${this.config.name ? `${this.config.name}` : \"\"} without choosing an authentication mode under arkos.config.${getUserFileExtension()}.\n\nFor further help see https://www.arkosjs.com/docs/core-concepts/authentication/setup.`\n );\n\n ns.on(\"connection\", async (s) => {\n const socket = s as ArkosSocket;\n socket.locals = {};\n\n socket._arkos = { store, gatewayConfig: localConfig };\n mountArkosSocketExtensions(socket);\n\n handleGatewayLifecycleLog(this.config.name, \"connected\", socket.id);\n const connectionStartTime = new Date().getTime();\n\n if (socket.currentUser?.id)\n socket.join(`arkos::user:${socket.currentUser.id}`);\n\n try {\n for (const handler of connectHandlers) await handler(socket);\n } catch (err: any) {\n handleArkosGatewayErrors(err, socket, [], {\n startTime: connectionStartTime,\n namespace: this.config.name,\n event: \"connection\",\n });\n return;\n }\n\n socket.on(\"disconnect\", async () => {\n handleGatewayLifecycleLog(this.config.name, \"disconnected\", socket.id);\n\n await clearRateLimitForSocket(socket.id, store);\n try {\n for (const handler of disconnectHandlers) await handler(socket);\n } catch (err) {\n handleArkosGatewayErrors(err, socket, [], {\n startTime: connectionStartTime,\n namespace: this.config.name,\n event: \"disconnection\",\n });\n }\n });\n\n for (const entry of this.events) {\n if ((entry.config as any)._pipeOnly || !entry.handler) continue;\n\n const { config: eventConfig, handler, pipes: eventPipes = [] } = entry;\n\n if (\n (this.config.authentication || parentConfig?.authentication) &&\n !isUsingAuthentication()\n )\n throw ExitError(\n `Trying to use authorization gateway.on(\"${eventConfig.event}\") without choosing an authentication mode under arkos.config.${getUserFileExtension()}.\n\nFor further help see https://www.arkosjs.com/docs/core-concepts/authentication/setup.`\n );\n\n socket.on(eventConfig.event, async (...args: any[]) => {\n socket.locals = {};\n const startTime = new Date().getTime();\n let data = args[0];\n\n const ack =\n typeof args[args.length - 1] === \"function\"\n ? args[args.length - 1]\n : undefined;\n\n let ackCalled = false;\n const wrappedAck = ack\n ? (...response: any) => {\n ackCalled = true;\n ack(...response);\n }\n : undefined;\n\n function resolveDedup() {\n if (\n eventConfig.dedup === false ||\n localConfig.dedup === false ||\n parentConfig?.dedup === false\n )\n return null;\n\n return {\n enabled: true,\n ttl: 3600,\n ...parentConfig?.dedup,\n ...localConfig?.dedup,\n ...eventConfig?.dedup,\n };\n }\n\n const dedupOpt = resolveDedup();\n\n try {\n const meta = data?._meta || {};\n const resolvedMaxAge =\n eventConfig.maxAge ?? localConfig.maxAge ?? parentConfig?.maxAge;\n\n if (resolvedMaxAge && !meta.timestamp)\n throw new BadRequestError(\n \"Missing _meta.timestamp for maxAge deduplication\"\n );\n\n if (meta.timestamp !== undefined) {\n const timestamp = new Date(meta.timestamp);\n\n if (isNaN(timestamp.getTime())) {\n throw new BadRequestError(\n \"Invalid data._meta.timestamp\",\n \"InvalidTimestamp\"\n );\n }\n\n const age = Date.now() - timestamp.getTime();\n\n if (age + 1000 < 0)\n throw new BadRequestError(\n \"Timestamp is in the future\",\n \"FutureTimestamp\"\n );\n\n if (resolvedMaxAge && age > resolvedMaxAge) {\n throw new BadRequestError(\"Message is too old\", \"StaleMessage\");\n }\n }\n\n if (dedupOpt && dedupOpt?.enabled !== false) {\n if (!meta?.mid)\n throw new BadRequestError(\n \"Missing data._meta.mid in your payload for deduplication\",\n \"MissingDedupMessageId\",\n { data }\n );\n\n if (typeof meta.mid !== \"string\" || meta.mid.trim() === \"\")\n throw new BadRequestError(\n \"Invalid data._meta.mid, it must be a non-empty string\",\n \"InvalidMessageId\"\n );\n\n const key = `arkos::dedup:${eventConfig.event}:${meta.mid}`;\n const ttl = dedupOpt?.ttl ?? 3600;\n\n const acquired = await store.setIfNotExists(key, ttl);\n\n if (acquired === false)\n return wrappedAck?.({\n success: true,\n duplicate: true,\n });\n\n const { _meta, ...payload } = data;\n data = payload;\n\n socket.meta = meta;\n }\n\n const rateLimitOptions = eventConfig.rateLimit ?? resolvedRateLimit;\n if (rateLimitOptions !== false) {\n const { allowed, retryAfter } = await checkRateLimit(\n socket.id,\n eventConfig.event,\n rateLimitOptions || {},\n options.store!\n );\n if (!allowed) {\n throw new TooManyRequestsError(undefined, undefined, {\n retryAfter,\n });\n }\n }\n\n if (\n typeof eventConfig.authorization === \"object\" &&\n resolvedAuth &&\n isAuthenticationEnabled()\n ) {\n await authHookManager.runAuthorize(\n { context: socket, done: () => { } },\n (eventConfig?.authorization as any)?._authAction,\n \"currentUser\"\n );\n }\n\n if (eventConfig.validation) {\n const arkosConfig = getArkosConfig();\n const {\n validationFn,\n isValidValidator,\n validatorName,\n validatorNameType,\n } = validationManager;\n\n if (!isValidValidator(eventConfig.validation))\n throw new Error(\n `Your validation resolver is set to ${arkosConfig.validation!.resolver}, ` +\n `please provide a valid ${validatorName} in order to use { validation: ${validatorNameType} } ` +\n `under event handler \"${eventConfig.event}\" in \"${this.config.name}\" gateway.`\n );\n\n const shouldValidate = validationManager.shouldValidate(\n eventConfig.validation,\n data\n );\n\n if (shouldValidate === \"prohibit\")\n throw new BadRequestError(\n \"Event data is not allowed for this event.\",\n \"EventDataNotAllowed\",\n { data }\n );\n else if (shouldValidate === \"passthrough\") data = data;\n else {\n try {\n data = await (validationFn as any)(\n eventConfig.validation,\n data\n );\n } catch (err: any) {\n const { validationConfig } = validationManager;\n\n const resolver = validationConfig?.resolver;\n const isZod = validationConfig?.resolver === \"zod\";\n\n const prettifiedError = errorPrettifier.prettify(\n resolver as any,\n err\n );\n const error = prettifiedError[0];\n\n throw new BadRequestError(\n error.message,\n `InvalidData`,\n isZod ? err.format() : err\n );\n }\n }\n }\n\n socket.data = data;\n\n await runArkosGatewayPipes(\n [...inheritedPipes, ...eventPipes],\n socket,\n data\n );\n\n await handler(socket, data, wrappedAck);\n\n handleGatewayEventLog(\n this.config.name,\n eventConfig.event,\n 200,\n startTime\n );\n\n if (eventConfig.ack && ack && !ackCalled) {\n ack({ success: true });\n }\n } catch (err: any) {\n handleArkosGatewayErrors(\n err,\n socket,\n errorHandlers,\n {\n startTime,\n namespace: this.config.name,\n event: eventConfig.event,\n },\n ack\n );\n }\n });\n }\n });\n\n for (const child of this.gateways) {\n child._register(\n io,\n {\n name: namespaceName,\n authentication: resolvedAuth,\n rateLimit: resolvedRateLimit,\n },\n resolvedHooks,\n inheritedPipes,\n options\n );\n }\n }\n}\n\n/**\n * Creates an Arkos WebSocket Gateway backed by Socket.io.\n *\n * Handles authentication, validation, rate limiting, pipes,\n * error handling, and nested gateways — all declaratively.\n * Enhances every connected socket with `socket.user()`, `socket.peer()`,\n * `socket.retry()`, and automatic `_meta` injection on outgoing emits.\n *\n * @example\n * ```ts\n * const chatGateway = ArkosGateway({\n * name: \"chat\",\n * authentication: true,\n * rateLimit: { windowMs: 60_000, max: 200 },\n * })\n *\n * chatGateway.on(\n * { event: \"send_message\", validation: MessageSchema, ack: true },\n * (socket, data, ack) => {\n * socket.to(data.room).emit(\"receive_message\", data)\n * ack?.({ status: \"ok\" })\n * }\n * )\n * ```\n * @since 1.7.0-canary.18\n * @see {@link https://www.arkosjs.com/docs/core-concepts/components/gateways}\n */\nfunction ArkosGateway(config: ArkosGatewayConfig) {\n return new IArkosGateway(config);\n}\n\nexport default ArkosGateway;\n"]}
|
|
1
|
+
{"version":3,"file":"arkos-gateway.js","sourceRoot":"","sources":["../../../../src/components/arkos-gateway/arkos-gateway.ts"],"names":[],"mappings":";;;;;;AAkBA,qDAAwE;AACxE,uDAA+E;AAC/E,6CAKyB;AACzB,qGAA0E;AAC1E,yCAA8C;AAC9C,mGAA0E;AAC1E,oFAAiF;AACjF,iGAAwE;AACxE,4FAA6D;AAC7D,uEAAmE;AACnE,2DAA6F;AAC7F,mFAGkD;AAClD,gFAAuD;AACvD,+DAAsE;AACtE,qEAGkD;AAElD,MAAa,aAAa;IAYxB,YAAY,MAA0B;QAV9B,WAAM,GAA6B,EAAE,CAAC;QACtC,UAAK,GAAuB,EAAE,CAAC;QAC/B,gBAAW,GAA6B,EAAE,CAAC;QAC3C,aAAQ,GAAoB,EAAE,CAAC;QAC/B,UAAK,GAGP,EAAE,CAAC;QAIP,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,YAAY,CAAC;IAC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AiB;aAC7B,EACD,aAAa,EACb,cAAc,EACd,OAAO,EACP,mBAAmB,CACpB,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAxkBD,sCAwkBC;AA6BD,SAAS,YAAY,CAAC,MAA0B;IAC9C,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC;AAED,kBAAe,YAAY,CAAC","sourcesContent":["import {\n ArkosGatewayConfig,\n ArkosGatewayErrorHandler,\n ArkosGatewayEventConfig,\n ArkosGatewayEventEntry,\n ArkosGatewayHandler,\n ArkosGatewayHookHandler,\n ArkosGatewayHookType,\n ArkosGatewayPipe,\n ArkosGatewayMiddleware,\n ArkosGatewayConnectionHandler,\n ArkosSocket,\n ArkosGatewayRegisterOptions,\n ArkosBroadcastOperator,\n ArkosEmitTarget,\n} from \"./types\";\nimport { Validator } from \"../../types/validation/validator\";\nimport { BroadcastOperator, Namespace, Server } from \"socket.io\";\nimport { authActionService, authService } from \"../../exports/services\";\nimport { checkRateLimit, clearRateLimitForSocket } from \"./utils/rate-limiter\";\nimport {\n handleArkosGatewayErrors,\n runArkosGatewayPipes,\n handleGatewayEventLog,\n handleGatewayLifecycleLog,\n} from \"./utils/helpers\";\nimport authHookManager from \"../../modules/auth/utils/auth-hooks-manager\";\nimport { getArkosConfig } from \"../../server\";\nimport validationManager from \"../../types/validation/validation-manager\";\nimport { loginRequiredError } from \"../../modules/auth/utils/auth-error-objects\";\nimport errorPrettifier from \"../../modules/base/utils/error-prettifier\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { defaultGatewayStore } from \"./utils/memory-gateway-store\";\nimport { ArkosBroadcastOperatorImpl, mountArkosSocketExtensions } from \"./socket-extensions\";\nimport {\n isAuthenticationEnabled,\n isUsingAuthentication,\n} from \"../../utils/helpers/arkos-config.helpers\";\nimport ExitError from \"../../utils/helpers/exit-error\";\nimport { getUserFileExtension } from \"../../utils/helpers/fs.helpers\";\nimport {\n BadRequestError,\n TooManyRequestsError,\n} from \"../../modules/error-handler/utils/errors\";\n\nexport class IArkosGateway {\n private config: ArkosGatewayConfig;\n private events: ArkosGatewayEventEntry[] = [];\n private pipes: ArkosGatewayPipe[] = [];\n private middlewares: ArkosGatewayMiddleware[] = [];\n private gateways: IArkosGateway[] = [];\n private hooks: {\n type: ArkosGatewayHookType;\n handler: ArkosGatewayHookHandler;\n }[] = [];\n private _nsp!: Namespace\n\n constructor(config: ArkosGatewayConfig) {\n this.config = config;\n this.config.name = config.name ?? \"web-socket\";\n }\n\n get nsp(): Omit<Namespace, keyof ArkosEmitTarget | keyof BroadcastOperator<any, any>> & ArkosBroadcastOperator {\n if (!this._nsp) throw new Error(`gateway.nsp accessed before register()`);\n return new ArkosBroadcastOperatorImpl(this._nsp.sockets, this._nsp) as any;\n }\n\n /**\n * Register a Socket.io connection-level middleware — runs before a socket\n * is accepted into this gateway's namespace, and before authentication.\n * Also accepts a child `ArkosGateway` which will inherit this gateway's\n * name as prefix along with its auth, rateLimit, and pipes.\n *\n * @example\n * chatGateway.use((socket, next) => {\n * console.log(\"incoming connection\", socket.id)\n * })\n *\n * // nested gateway\n * chatGateway.use(notificationsGateway)\n */\n use(...middlewareOrGateway: Array<ArkosGatewayMiddleware | IArkosGateway>): this {\n for (const item of middlewareOrGateway) {\n if (item instanceof IArkosGateway) {\n this.gateways.push(item);\n } else if (typeof item === \"function\") {\n this.middlewares.push(item as ArkosGatewayMiddleware);\n } else {\n throw new Error(\n `Invalid value for gateway.use() — expected an ArkosGateway instance or a middleware function but received \"${typeof item}\".`\n );\n }\n }\n return this;\n }\n\n /**\n * Register a pipe — middleware that runs before event handlers.\n *\n * When called with a function only, the pipe runs before every event\n * handler in this gateway and drills down to child gateways.\n *\n * When called with an event config object, the pipe runs only for that\n * specific event.\n *\n * @example\n * // runs before every event in this gateway\n * chatGateway.pipe((socket, data) => {\n * })\n *\n * // runs only before \"send_message\"\n * chatGateway.pipe({ event: \"send_message\" }, (socket, data) => {\n * })\n */\n pipe(fn: ArkosGatewayPipe): this;\n pipe<TSchema extends Validator = any>(\n eventConfig: { event: string },\n fn: ArkosGatewayPipe\n ): this;\n pipe<TSchema extends Validator = any>(\n fnOrConfig: ArkosGatewayPipe | ArkosGatewayEventConfig<TSchema>,\n fn?: ArkosGatewayPipe\n ): this {\n if (typeof fnOrConfig === \"function\") {\n this.pipes.push(fnOrConfig);\n } else if (fnOrConfig && typeof fnOrConfig === \"object\" && fn) {\n const entry = this.events.find(\n (e) => e.config.event === fnOrConfig.event\n );\n if (entry) {\n entry.pipes = entry.pipes ?? [];\n entry.pipes.push(fn);\n } else {\n this.events.push({\n config: { event: fnOrConfig.event, _pipeOnly: true } as any,\n handler: null as any,\n pipes: [fn],\n });\n }\n } else {\n throw new Error(\n `Invalid arguments for gateway.pipe() — pass a middleware function, or an event config object followed by a middleware function.`\n );\n }\n return this;\n }\n\n /**\n * Register an event handler.\n *\n * @example\n * chatGateway.on(\n * { event: \"send_message\", validation: MessageSchema, ack: true },\n * (socket, data, ack) => {\n * socket.to(data.room).emit(\"receive_message\", data)\n * ack?.({ status: \"ok\" })\n * }\n * )\n */\n on<TSchema extends Validator = any>(\n eventConfig: ArkosGatewayEventConfig<TSchema>,\n handler: ArkosGatewayHandler\n ): this {\n if (eventConfig.disabled) return this;\n\n if (eventConfig.authorization && this.config.authentication === false) {\n throw new Error(\n `Event \"${eventConfig.event}\" on \"${this.config.name}\" gateway defines authorization rules ` +\n `but the gateway has authentication: false. Enable authentication on the gateway to use per-event authentication.`\n );\n }\n\n const deferred = this.events.find(\n (e) => (e.config as any)._pipeOnly && e.config.event === eventConfig.event\n );\n\n const entry: ArkosGatewayEventEntry = {\n config: eventConfig,\n handler,\n pipes: [...this.pipes, ...(deferred?.pipes ?? [])],\n };\n\n if (deferred) {\n const idx = this.events.indexOf(deferred);\n this.events.splice(idx, 1, entry);\n } else {\n this.events.push(entry);\n }\n\n if (typeof eventConfig?.authorization == \"object\")\n // To reuse later on\n (eventConfig.authorization as any)._authAction = authActionService.add(\n eventConfig.authorization!.action,\n eventConfig.authorization!.resource,\n {\n [eventConfig.authorization!.action]: eventConfig.authorization?.rule,\n }\n );\n\n return this;\n }\n\n /**\n * Register a lifecycle hook.\n *\n * - `\"connection\"` — called after a socket successfully connects and passes authentication.\n * - `\"disconnect\"` — called when a socket disconnects.\n * - `\"error\"` — called when an error is thrown inside any event handler.\n * If not registered, Arkos emits a default `\"error\"` event to the socket.\n *\n * @example\n * chatGateway.hook(\"connection\", (socket) => {\n * console.log(\"connected\", socket.user.id)\n * })\n *\n * chatGateway.hook(\"error\", (err, socket) => {\n * socket.emit(\"error\", { message: err.message })\n * })\n */\n hook(type: \"connection\", handler: ArkosGatewayConnectionHandler): this;\n hook(type: \"disconnect\", handler: ArkosGatewayConnectionHandler): this;\n hook(type: \"error\", handler: ArkosGatewayErrorHandler): this;\n hook(\n type: ArkosGatewayHookType,\n handler: ArkosGatewayConnectionHandler | ArkosGatewayErrorHandler\n ): this {\n this.hooks.push({ type, handler });\n return this;\n }\n\n /**\n * Wire this gateway into a Socket.io `Server` instance.\n * Registers the namespace, auth middleware, rate limiting, pipes,\n * and all event handlers — then recurses into child gateways.\n *\n * @example\n * const io = new Server(server)\n * chatGateway.register(io)\n */\n register(io: Server, options: ArkosGatewayRegisterOptions = {}): void {\n if ((io as any)._arkosGatewayRegistered)\n throw new Error(\n `The method gateway.register() can only be called once per io server instance. Use gateway.use() to compose gateways, see https://www.arkosjs.com/docs/guides/web-sockets/setup.`\n );\n (io as any)._arkosGatewayRegistered = true;\n this._register(io, undefined, this.hooks || [], this.pipes || [], options);\n }\n\n private _register(\n io: Server,\n parentConfig?: ArkosGatewayConfig,\n inheritedHooks: {\n type: ArkosGatewayHookType;\n handler: ArkosGatewayHookHandler;\n }[] = [],\n inheritedPipes: ArkosGatewayPipe[] = [],\n options: ArkosGatewayRegisterOptions = {},\n inheritedMiddlewares: ArkosGatewayMiddleware[] = []\n ): void {\n options.store = options.store ?? defaultGatewayStore;\n const { store } = options;\n\n const parentName = parentConfig?.name;\n const ownName = this.config.name;\n this.config = deepmerge(parentConfig || {}, this.config, {\n arrayMerge: (_, sourceArray) => sourceArray,\n });\n this.config.name = ownName;\n const localConfig = this.config;\n\n const namespaceName = parentName\n ? `${parentName.replace(/\\/$/, \"\")}/${ownName.replace(/^\\//, \"\")}`\n : (ownName ?? \"\");\n\n const ns = io.of(namespaceName);\n this._nsp = ns;\n\n const resolvedAuth =\n this.config.authentication !== false &&\n parentConfig?.authentication !== false;\n\n const resolvedRateLimit = this.config.rateLimit ?? parentConfig?.rateLimit;\n const resolvedHooks = [...inheritedHooks, ...this.hooks];\n const resolvedMiddlewares = [...inheritedMiddlewares, ...this.middlewares];\n\n const connectHandlers = resolvedHooks\n .filter((h) => h.type === \"connection\")\n .map((h) => h.handler as ArkosGatewayConnectionHandler);\n\n const disconnectHandlers = resolvedHooks\n .filter((h) => h.type === \"disconnect\")\n .map((h) => h.handler as ArkosGatewayConnectionHandler);\n\n const errorHandlers = resolvedHooks\n .filter((h) => h.type === \"error\")\n .map((h) => h.handler as ArkosGatewayErrorHandler);\n\n for (const middleware of resolvedMiddlewares) {\n ns.use((socket, next) => middleware(socket as ArkosSocket, next));\n }\n\n if (resolvedAuth && isAuthenticationEnabled()) {\n ns.use(async (socket: any, next) => {\n socket = socket as ArkosSocket;\n const startTime = new Date().getTime();\n try {\n await authHookManager.runAuthenticate(\n {\n context: socket,\n done: (err?: any) => {\n if (err) throw err;\n next();\n },\n },\n async (socket) => {\n const user = await authService.getAuthenticatedUser(socket);\n if (!user) throw loginRequiredError;\n return user;\n },\n \"currentUser\"\n );\n } catch (err: any) {\n handleArkosGatewayErrors(err, socket, errorHandlers, {\n startTime,\n namespace: this.config.name,\n event: \"authentication\",\n });\n next(err);\n }\n });\n } else if (\n (this.config.authentication || parentConfig?.authentication) &&\n !isUsingAuthentication()\n )\n throw ExitError(\n `Trying to authenticate gateway ${this.config.name ? `${this.config.name}` : \"\"} without choosing an authentication mode under arkos.config.${getUserFileExtension()}.\n\nFor further help see https://www.arkosjs.com/docs/core-concepts/authentication/setup.`\n );\n\n ns.on(\"connection\", async (s) => {\n const socket = s as ArkosSocket;\n socket.locals = {};\n\n socket._arkos = { store, gatewayConfig: localConfig };\n mountArkosSocketExtensions(socket);\n\n handleGatewayLifecycleLog(this.config.name, \"connected\", socket.id);\n const connectionStartTime = new Date().getTime();\n\n if (socket.currentUser?.id)\n socket.join(`arkos::user:${socket.currentUser.id}`);\n\n try {\n for (const handler of connectHandlers) await handler(socket);\n } catch (err: any) {\n handleArkosGatewayErrors(err, socket, [], {\n startTime: connectionStartTime,\n namespace: this.config.name,\n event: \"connection\",\n });\n return;\n }\n\n socket.on(\"disconnect\", async () => {\n handleGatewayLifecycleLog(this.config.name, \"disconnected\", socket.id);\n\n await clearRateLimitForSocket(socket.id, store);\n try {\n for (const handler of disconnectHandlers) await handler(socket);\n } catch (err) {\n handleArkosGatewayErrors(err, socket, [], {\n startTime: connectionStartTime,\n namespace: this.config.name,\n event: \"disconnection\",\n });\n }\n });\n\n for (const entry of this.events) {\n if ((entry.config as any)._pipeOnly || !entry.handler) continue;\n\n const { config: eventConfig, handler, pipes: eventPipes = [] } = entry;\n\n if (\n (this.config.authentication || parentConfig?.authentication) &&\n !isUsingAuthentication()\n )\n throw ExitError(\n `Trying to use authorization gateway.on(\"${eventConfig.event}\") without choosing an authentication mode under arkos.config.${getUserFileExtension()}.\n\nFor further help see https://www.arkosjs.com/docs/core-concepts/authentication/setup.`\n );\n\n socket.on(eventConfig.event, async (...args: any[]) => {\n socket.locals = {};\n const startTime = new Date().getTime();\n let data = args[0];\n\n const ack =\n typeof args[args.length - 1] === \"function\"\n ? args[args.length - 1]\n : undefined;\n\n let ackCalled = false;\n const wrappedAck = ack\n ? (...response: any) => {\n ackCalled = true;\n ack(...response);\n }\n : undefined;\n\n function resolveDedup() {\n if (\n eventConfig.dedup === false ||\n localConfig.dedup === false ||\n parentConfig?.dedup === false\n )\n return null;\n\n return {\n enabled: true,\n ttl: 3600,\n ...parentConfig?.dedup,\n ...localConfig?.dedup,\n ...eventConfig?.dedup,\n };\n }\n\n const dedupOpt = resolveDedup();\n\n try {\n const meta = data?._meta || {};\n const resolvedMaxAge =\n eventConfig.maxAge ?? localConfig.maxAge ?? parentConfig?.maxAge;\n\n if (resolvedMaxAge && !meta.timestamp)\n throw new BadRequestError(\n \"Missing _meta.timestamp for maxAge deduplication\"\n );\n\n if (meta.timestamp !== undefined) {\n const timestamp = new Date(meta.timestamp);\n\n if (isNaN(timestamp.getTime())) {\n throw new BadRequestError(\n \"Invalid data._meta.timestamp\",\n \"InvalidTimestamp\"\n );\n }\n\n const age = Date.now() - timestamp.getTime();\n\n if (age + 1000 < 0)\n throw new BadRequestError(\n \"Timestamp is in the future\",\n \"FutureTimestamp\"\n );\n\n if (resolvedMaxAge && age > resolvedMaxAge) {\n throw new BadRequestError(\"Message is too old\", \"StaleMessage\");\n }\n }\n\n if (dedupOpt && dedupOpt?.enabled !== false) {\n if (!meta?.mid)\n throw new BadRequestError(\n \"Missing data._meta.mid in your payload for deduplication\",\n \"MissingDedupMessageId\",\n { data }\n );\n\n if (typeof meta.mid !== \"string\" || meta.mid.trim() === \"\")\n throw new BadRequestError(\n \"Invalid data._meta.mid, it must be a non-empty string\",\n \"InvalidMessageId\"\n );\n\n const key = `arkos::dedup:${eventConfig.event}:${meta.mid}`;\n const ttl = dedupOpt?.ttl ?? 3600;\n\n const acquired = await store.setIfNotExists(key, ttl);\n\n if (acquired === false)\n return wrappedAck?.({\n success: true,\n duplicate: true,\n });\n\n const { _meta, ...payload } = data;\n data = payload;\n\n socket.meta = meta;\n }\n\n const rateLimitOptions = eventConfig.rateLimit ?? resolvedRateLimit;\n if (rateLimitOptions !== false) {\n const { allowed, retryAfter } = await checkRateLimit(\n socket.id,\n eventConfig.event,\n rateLimitOptions || {},\n options.store!\n );\n if (!allowed) {\n throw new TooManyRequestsError(undefined, undefined, {\n retryAfter,\n });\n }\n }\n\n if (\n typeof eventConfig.authorization === \"object\" &&\n resolvedAuth &&\n isAuthenticationEnabled()\n ) {\n await authHookManager.runAuthorize(\n { context: socket, done: () => { } },\n (eventConfig?.authorization as any)?._authAction,\n \"currentUser\"\n );\n }\n\n if (eventConfig.validation) {\n const arkosConfig = getArkosConfig();\n const {\n validationFn,\n isValidValidator,\n validatorName,\n validatorNameType,\n } = validationManager;\n\n if (!isValidValidator(eventConfig.validation))\n throw new Error(\n `Your validation resolver is set to ${arkosConfig.validation!.resolver}, ` +\n `please provide a valid ${validatorName} in order to use { validation: ${validatorNameType} } ` +\n `under event handler \"${eventConfig.event}\" in \"${this.config.name}\" gateway.`\n );\n\n const shouldValidate = validationManager.shouldValidate(\n eventConfig.validation,\n data\n );\n\n if (shouldValidate === \"prohibit\")\n throw new BadRequestError(\n \"Event data is not allowed for this event.\",\n \"EventDataNotAllowed\",\n { data }\n );\n else if (shouldValidate === \"passthrough\") data = data;\n else {\n try {\n data = await (validationFn as any)(\n eventConfig.validation,\n data\n );\n } catch (err: any) {\n const { validationConfig } = validationManager;\n\n const resolver = validationConfig?.resolver;\n const isZod = validationConfig?.resolver === \"zod\";\n\n const prettifiedError = errorPrettifier.prettify(\n resolver as any,\n err\n );\n const error = prettifiedError[0];\n\n throw new BadRequestError(\n error.message,\n `InvalidData`,\n isZod ? err.format() : err\n );\n }\n }\n }\n\n socket.data = data;\n\n await runArkosGatewayPipes(\n [...inheritedPipes, ...eventPipes],\n socket,\n data\n );\n\n await handler(socket, data, wrappedAck);\n\n handleGatewayEventLog(\n this.config.name,\n eventConfig.event,\n 200,\n startTime\n );\n\n if (eventConfig.ack && ack && !ackCalled) {\n ack({ success: true });\n }\n } catch (err: any) {\n handleArkosGatewayErrors(\n err,\n socket,\n errorHandlers,\n {\n startTime,\n namespace: this.config.name,\n event: eventConfig.event,\n },\n ack\n );\n }\n });\n }\n });\n\n for (const child of this.gateways) {\n child._register(\n io,\n {\n name: namespaceName,\n authentication: resolvedAuth,\n rateLimit: resolvedRateLimit,\n },\n resolvedHooks,\n inheritedPipes,\n options,\n resolvedMiddlewares\n );\n }\n }\n}\n\n/**\n * Creates an Arkos WebSocket Gateway backed by Socket.io.\n *\n * Handles authentication, validation, rate limiting, pipes,\n * error handling, and nested gateways — all declaratively.\n * Enhances every connected socket with `socket.user()`, `socket.peer()`,\n * `socket.retry()`, and automatic `_meta` injection on outgoing emits.\n *\n * @example\n * ```ts\n * const chatGateway = ArkosGateway({\n * name: \"chat\",\n * authentication: true,\n * rateLimit: { windowMs: 60_000, max: 200 },\n * })\n *\n * chatGateway.on(\n * { event: \"send_message\", validation: MessageSchema, ack: true },\n * (socket, data, ack) => {\n * socket.to(data.room).emit(\"receive_message\", data)\n * ack?.({ status: \"ok\" })\n * }\n * )\n * ```\n * @since 1.7.0-canary.18\n * @see {@link https://www.arkosjs.com/docs/core-concepts/components/gateways}\n */\nfunction ArkosGateway(config: ArkosGatewayConfig) {\n return new IArkosGateway(config);\n}\n\nexport default ArkosGateway;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/components/arkos-gateway/types.ts"],"names":[],"mappings":";;;AA4jBA,MAAa,sBAAsB;CAAI;AAAvC,wDAAuC","sourcesContent":["import { BroadcastOperator, Socket } from \"socket.io\";\nimport { User } from \"../../types\";\nimport { DefaultEventsMap } from \"socket.io\";\nimport { Validator } from \"../../types/validation/validator\";\nimport { Options as RateLimitOptions } from \"express-rate-limit\";\nimport { DetailedAccessControlRule } from \"../../types/auth\";\n///@ts-ignore\nimport {\n AllButLast,\n DecorateAcknowledgements,\n DecorateAcknowledgementsWithMultipleResponses,\n EventNames,\n EventNamesWithAck,\n EventNamesWithError,\n EventParams,\n FirstNonErrorArg,\n Last,\n ///@ts-ignore\n} from \"socket.io/dist/typed-events\";\n\nexport interface EventsMap {\n [event: string]: any;\n}\n\nexport interface ArkosSocket<\n ListenEvents extends EventsMap = DefaultEventsMap,\n EmitEvents extends EventsMap = ListenEvents,\n ServerSideEvents extends EventsMap = DefaultEventsMap,\n SocketData extends Validator = any,\n SocketLocals extends Record<string, any> = Record<string, any>,\n> extends Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData> {\n /**\n * Populated by Arkos after successful authentication on connection.\n * Available in all event handlers when `authentication: true` on the gateway.\n */\n currentUser?: User;\n\n /**\n * Populated by Arkos after successful validation.\n * Typed to the event's validation schema when using TypeScript.\n */\n data: SocketData;\n\n /** User access token. */\n accessToken?: string;\n\n /**\n * Metadata from the incoming message, extracted from `_meta` by Arkos.\n *\n * - `mid`: Unique message ID used for deduplication.\n * - `timestamp`: When the message was sent by the client.\n */\n meta?: {\n mid?: string;\n timestamp?: string | number | Date;\n };\n\n /**\n * Per-event local storage, scoped to the current event pipeline.\n * Use to pass data between pipes and the event handler — like Express's `res.locals`.\n * Reset automatically on each event.\n *\n * @example\n * chatGateway.pipe((socket, data) => {\n * socket.locals.enriched = enrichUser(socket.currentUser)\n * })\n *\n * chatGateway.on({ event: \"send_message\" }, (socket, data) => {\n * console.log(socket.locals.enriched)\n * })\n */\n locals?: SocketLocals;\n\n /**\n * Internal Arkos context injected by the gateway at connection time.\n *\n * @internal\n */\n _arkos: {\n store: ArkosGatewayStore;\n gatewayConfig: ArkosGatewayConfig;\n };\n\n /**\n * Targets all active socket connections of a user by their user ID.\n * Uses the internal `arkos::user:{userId}` room convention.\n *\n * Supports emit, management, and exclusion operations across all of the\n * user's active connections.\n *\n * @example\n * socket.user(userId).emit(\"notification\", data)\n * socket.user(userId).except({ user: otherUserId }).emit(\"sync\", data)\n * const sockets = await socket.user(userId).fetchSockets()\n * const online = await socket.user(userId).isOnline()\n *\n * @since 1.7.0-canary.29\n */\n user(userId: string): ArkosUserTarget;\n\n /**\n * Wraps the next `emit` or `emitWithAck` with exponential backoff retry logic.\n * Chain `.timeout(ms)` before `.emitWithAck()` as usual.\n *\n * @example\n * socket.retry(3).emit(\"event\", data)\n * socket.retry(3).timeout(5000).emitWithAck(\"event\", data)\n *\n * @since 1.7.0-canary.29\n */\n retry(\n times: number,\n initialDelay?: number,\n multiplier?: number\n ): ArkosRetryTarget;\n\n /**\n * Emits an event to this client.\n * Arkos automatically injects `_meta` (`mid` + `timestamp`) into every outgoing payload\n * for client-side deduplication and freshness checks.\n *\n * @example\n * socket.emit(\"message\", { text: \"hello\" })\n * socket.emit(\"notification\", { title: \"New order\" })\n */\n emit<Ev extends EventNames<EmitEvents>>(\n ev: Ev,\n ...args: EventParams<EmitEvents, Ev>\n ): true;\n\n /**\n * Emits an event and waits for an acknowledgement from the client.\n * Arkos injects `_meta` automatically. Use `.timeout(ms)` to avoid hanging indefinitely.\n *\n * @example\n * const response = await socket.timeout(5000).emitWithAck(\"confirm\", data)\n */\n emitWithAck<Ev extends EventNamesWithAck<EmitEvents>>(\n ev: Ev,\n ...args: AllButLast<EventParams<EmitEvents, Ev>>\n ): Promise<FirstNonErrorArg<Last<EventParams<EmitEvents, Ev>>>>;\n\n /**\n * Targets a room when broadcasting — excludes the sender.\n * Returns an {@link ArkosBroadcastOperator} with enhanced `.except({ user })` support\n * and automatic `_meta` injection on every `.emit()`.\n *\n * @example\n * socket.to(\"room-101\").emit(\"message\", data)\n * socket.to(\"room-101\").except({ user: userId }).emit(\"message\", data)\n * socket.to(\"room-101\").volatile.emit(\"typing\", data)\n * await socket.to(\"room-101\").timeout(3000).emitWithAck(\"confirm\", data)\n *\n * @since 1.7.0-canary.29\n */\n to(\n room: string | string[]\n ): ArkosBroadcastOperator<\n DecorateAcknowledgementsWithMultipleResponses<EmitEvents>,\n SocketData\n > &\n BroadcastOperator<EmitEvents, SocketData>;\n /**\n * Broadcasts to all connected clients except the sender.\n * Returns an {@link ArkosBroadcastOperator} with enhanced `.except({ user })` support\n * and automatic `_meta` injection on every `.emit()`.\n *\n * @example\n * socket.broadcast.emit(\"announcement\", data)\n * socket.broadcast.except({ user: userId }).emit(\"announcement\", data)\n * socket.broadcast.volatile.emit(\"ping\", data)\n *\n * @since 1.7.0-canary.29\n */\n get broadcast(): ArkosBroadcastOperator<\n DecorateAcknowledgementsWithMultipleResponses<EmitEvents>,\n SocketData\n > &\n BroadcastOperator<EmitEvents, SocketData>;\n}\n\n/**\n * Enhanced broadcast/room target returned by `socket.to()` and `socket.broadcast`.\n * Extends the native `BroadcastOperator` with `{ user }` exclusion support\n * and automatic `_meta` injection on emit.\n *\n * @since 1.7.0-canary.29\n */\nexport interface ArkosBroadcastOperator<\n EmitEvents extends EventsMap = DefaultEventsMap,\n SocketData extends Validator = any,\n> extends BroadcastOperator<EmitEvents, SocketData> {\n /**\n * Exclude sockets from the broadcast.\n * Accepts a room name, socket ID, or `{ user: string | string[] }` to exclude\n * all sockets belonging to one or more users.\n *\n * @example\n * socket.to(\"room-101\").except(\"room-102\").emit(\"foo\", data)\n * socket.broadcast.except({ user: userId }).emit(\"foo\", data)\n * socket.broadcast.except({ user: [userId1, userId2] }).emit(\"foo\", data)\n */\n except(\n room: string | string[] | { user: string | string[] }\n ): ArkosBroadcastOperator<EmitEvents, SocketData>;\n\n /**\n * Emits to all clients,`_meta` is injected automatically.\n *\n * @example\n * // the “foo” event will be broadcast to all connected clients\n * io.emit(\"foo\", \"bar\");\n *\n * // the “foo” event will be broadcast to all connected clients in the “room-101” room\n * io.to(\"room-101\").emit(\"foo\", \"bar\");\n *\n * // with an acknowledgement expected from all connected clients\n * io.timeout(1000).emit(\"some-event\", (err, responses) => {\n * if (err) {\n * // some clients did not acknowledge the event in the given delay\n * } else {\n * console.log(responses); // one response per client\n * }\n * });\n *\n * @return Always true\n */\n emit<Ev extends EventNames<EmitEvents>>(\n ev: Ev,\n ...args: EventParams<EmitEvents, Ev>\n ): true;\n\n /** Chain volatile flag — event may be lost if client is not ready. */\n get volatile(): ArkosBroadcastOperator<EmitEvents, SocketData>;\n\n /** Chain compress flag. */\n compress(value: boolean): ArkosBroadcastOperator<EmitEvents, SocketData>;\n\n /** Chain timeout for `emitWithAck`. */\n timeout(\n ms: number\n ): ArkosBroadcastOperator<DecorateAcknowledgements<EmitEvents>, SocketData>;\n\n /**\n * Emits an event and waits for an acknowledgement from all clients.\n * `_meta` is injected automatically\n * @example\n * try {\n * const responses = await io.timeout(1000).emitWithAck(\"some-event\");\n * console.log(responses); // one response per client\n * } catch (e) {\n * // some clients did not acknowledge the event in the given delay\n * }\n *\n * @return a Promise that will be fulfilled when all clients have acknowledged the event\n */\n emitWithAck<Ev extends EventNamesWithError<EmitEvents>>(\n ev: Ev,\n ...args: AllButLast<EventParams<EmitEvents, Ev>>\n ): Promise<FirstNonErrorArg<Last<EventParams<EmitEvents, Ev>>>>;\n\n /**\n * Targets all active socket connections of a user by their user ID.\n * Uses the internal `arkos::user:{userId}` room convention.\n *\n * Supports emit, management, and exclusion operations across all of the\n * user's active connections.\n *\n * @example\n * socket.user(userId).emit(\"notification\", data)\n * socket.user(userId).except({ user: otherUserId }).emit(\"sync\", data)\n * const sockets = await socket.user(userId).fetchSockets()\n * const online = await socket.user(userId).isOnline()\n *\n * @since 1.7.0-canary.29\n */\n user(userId: string): ArkosUserTarget;\n /**\n * Returns all unique user IDs currently in the target room(s).\n *\n * @example\n * const users = await socket.to(\"room-123\").users()\n */\n users(): Promise<string[]>;\n}\n\n/**\n * Returned by `socket.retry(n)`. Wraps `emit` and `emitWithAck`\n * with exponential backoff. Chain `.timeout(ms)` before `.emitWithAck()` as usual.\n *\n * @since 1.7.0-canary.29\n */\nexport interface ArkosRetryTarget {\n /** Emit with ack and retry. `_meta` is injected automatically. */\n emitWithAck(event: string, data: any, ...rest: any[]): Promise<any>;\n\n /**\n * Chain a timeout before `emitWithAck`.\n *\n * @example\n * socket.retry(3).timeout(5000).emitWithAck(\"event\", data)\n */\n timeout(ms: number): ArkosRetryTarget;\n}\n\n/**\n * Returned by `socket.user(userId)`.\n * Targets all active socket connections of a user.\n *\n * @since 1.7.0-canary.29\n */\nexport interface ArkosUserTarget extends ArkosBroadcastOperator {\n /**\n * Returns all active rooms for this user.\n *\n * @example\n * const rooms = await socket.user(userId).activeRooms()\n * console.log(rooms.length) // number of active tabs/connections\n */\n activeRooms(): Promise<string[]>;\n}\n\nexport type ArkosGatewayPipe = (\n socket: ArkosSocket,\n data: any\n) => void | Promise<void>;\n\nexport type ArkosGatewayEventConfig<TSchema extends Validator = any> = {\n /** The Socket.io event name to listen for. */\n event: string;\n\n /** Zod schema or class-validator DTO to validate the incoming event payload. */\n validation?: TSchema;\n\n /** Per-event rate limiting. Overrides gateway-level `rateLimit` for this event. */\n rateLimit?: Partial<RateLimitOptions> | false;\n\n /**\n * Authorization configuration.\n *\n * @remarks Gateway `authentication` must NOT be `false` or this throws at registration time.\n */\n authorization?: {\n resource: string;\n action: string;\n rule?: DetailedAccessControlRule | string[] | \"*\";\n };\n\n /**\n * When `true`, Arkos automatically calls `ack({ success: true })` after the handler\n * finishes, unless the handler already called ack manually.\n */\n ack?: boolean;\n\n /** Disables this event handler without removing it. */\n disabled?: boolean;\n\n /**\n * Maximum age in milliseconds for incoming messages.\n * Requires `data._meta.timestamp`. Events older than this are rejected.\n */\n maxAge?: number;\n\n /** Per-event deduplication. Overrides gateway-level `dedup`. */\n dedup?:\n | {\n /** @default true */\n enabled?: boolean;\n /** Time-to-live in seconds for the dedup key. @default 3600 */\n ttl?: number;\n }\n | false;\n};\n\nexport type ArkosGatewayAckFn = (response: any) => void;\n\nexport type ArkosGatewayHandler<TData = any> = (\n socket: ArkosSocket,\n data: TData,\n ack?: ArkosGatewayAckFn\n) => void | Promise<void>;\n\nexport type ArkosGatewayEventEntry = {\n config: ArkosGatewayEventConfig;\n handler: ArkosGatewayHandler;\n pipes: ArkosGatewayPipe[];\n};\n\nexport type ArkosGatewayConnectionHandler = (\n socket: ArkosSocket\n) => void | Promise<void>;\n\nexport type ArkosGatewayHookHandler =\n | ArkosGatewayConnectionHandler\n | ArkosGatewayErrorHandler;\n\nexport type ArkosGatewayErrorHandler = (\n error: any,\n socket: ArkosSocket\n) => void | Promise<void>;\n\nexport type ArkosGatewayHookType = \"connection\" | \"disconnect\" | \"error\";\n\nexport type ArkosGatewayConfig = {\n /**\n * Socket.io namespace for this gateway.\n *\n * @example\n * name: \"/chat\"\n */\n name: string;\n\n /**\n * When `true`, Arkos runs auth middleware on connection and populates `socket.currentUser`.\n * Unauthenticated sockets are rejected.\n *\n * @default false\n */\n authentication?: boolean;\n\n /** Gateway-level rate limiting, applied per socket. Can be overridden per event. */\n rateLimit?: Partial<RateLimitOptions>;\n\n /**\n * Gateway-level deduplication. Drills down to child gateways and can be overridden\n * per child or per event listener.\n */\n dedup?:\n | {\n /** @default true */\n enabled?: boolean;\n /** @default 3600 */\n ttl?: number;\n }\n | false;\n\n /**\n * Maximum age in milliseconds for incoming messages.\n * Can be overridden per event via `maxAge` in `gateway.on()`.\n */\n maxAge?: number;\n};\n\n/**\n * Options for `gateway.register()`.\n * Passed once at the root — applies to all child gateways.\n */\nexport type ArkosGatewayRegisterOptions = {\n /**\n * Unified store for rate limiting and deduplication.\n * Defaults to an in-memory store — zero config for single-instance deployments.\n * For distributed deployments plug in a Redis-backed store.\n *\n * @example\n * store: new RedisArkosStore(redis)\n */\n store?: ArkosGatewayStore;\n};\n\n/**\n * Unified store interface for rate limiting and deduplication.\n * Implement this to plug in Redis, Valkey, or any distributed store.\n *\n * @example\n * class RedisArkosStore implements ArkosGatewayStore {\n * async increment(key, windowMs) { ... }\n * async clear(prefix) { ... }\n * async has(key) { ... }\n * async set(key, ttl) { ... }\n * async setIfNotExists(key, ttl) { ... }\n * }\n */\nexport interface ArkosGatewayStore {\n /** Increment a rate limit counter. Key format: `arkos::rl:{socketId}:{event}` */\n increment(\n key: string,\n windowMs: number\n ): Promise<{ count: number; resetAt: number }>;\n\n /** Clear all rate limit entries matching a prefix. Key format: `arkos::rl:{socketId}` */\n clear(prefix: string): Promise<void>;\n\n /** Check if a dedup key exists. */\n has(key: string): Promise<boolean>;\n\n /** Store a dedup key with TTL in seconds. */\n set(key: string, ttl: number): Promise<void>;\n\n /**\n * Atomically store a dedup key only if it does not already exist.\n * Returns `true` if created (process the message), `false` if duplicate (skip).\n */\n setIfNotExists(key: string, ttl: number): Promise<boolean>;\n}\n\n/**\n * Minimal broadcast/emit contract that {@link ArkosBroadcastOperatorImpl} wraps.\n * Deliberately narrower than socket.io's `BroadcastOperator` — only the methods\n * Arkos actually calls, so both a `BroadcastOperator` (from `socket.to()`) and a\n * raw `Namespace` (from `gateway.nsp`) satisfy it structurally.\n *\n * @since 1.7.1-canary.3\n */\nexport interface ArkosEmitTarget<EmitEvents extends EventsMap = DefaultEventsMap> {\n /**\n * Emits an event to the target. `_meta` (`mid` + `timestamp`) is injected automatically.\n *\n * @example\n * socket.to(\"room-101\").emit(\"message\", { text: \"hello\" })\n * socket.broadcast.emit(\"announcement\", data)\n */\n emit(event: string, ...args: any[]): boolean;\n\n /**\n * Emits an event and waits for an acknowledgement from all matched clients.\n * `_meta` is injected automatically.\n *\n * Optional — not every target supports ack collection directly (e.g. a raw\n * `Namespace` requires `.timeout(ms)` first). Throws at runtime if called on\n * a target that doesn't implement it natively.\n *\n * @example\n * const responses = await socket.to(\"room-101\").timeout(3000).emitWithAck(\"confirm\", data)\n */\n emitWithAck?(event: string, ...args: any[]): Promise<any>;\n\n /**\n * Excludes sockets from the broadcast.\n * Accepts a room name, socket ID, or array of rooms/IDs.\n * For `{ user }` exclusion, see {@link ArkosBroadcastOperatorImpl.except}.\n *\n * @example\n * socket.to(\"room-101\").except(\"room-102\").emit(\"foo\", data)\n */\n except(room: string | string[]): ArkosEmitTarget<EmitEvents>;\n\n /**\n * Sets the compress flag for the next emission.\n *\n * @example\n * socket.broadcast.compress(false).emit(\"ping\", data)\n */\n compress(value: boolean): ArkosEmitTarget<EmitEvents>;\n\n /**\n * Sets a timeout in milliseconds for `emitWithAck`.\n * Rejects the promise if no client acknowledges within the given delay.\n *\n * @example\n * socket.to(\"room-101\").timeout(3000).emitWithAck(\"confirm\", data)\n */\n timeout(ms: number): ArkosEmitTarget\n\n /**\n * Returns all sockets currently matched by this target.\n *\n * @example\n * const sockets = await socket.to(\"room-101\").fetchSockets()\n */\n fetchSockets(): Promise<any[]>;\n\n to(room: string | string[]): ArkosEmitTarget\n\n /**\n * Sets the volatile flag — the event may be dropped if the client is not ready.\n * Useful for high-frequency non-critical events like cursor positions or typing indicators.\n *\n * @example\n * socket.to(\"room-101\").volatile.emit(\"cursor\", position)\n */\n readonly volatile: ArkosEmitTarget<EmitEvents>;\n}\nexport class ArkosGatewayController { }\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/components/arkos-gateway/types.ts"],"names":[],"mappings":";;;AAukBA,MAAa,sBAAsB;CAAI;AAAvC,wDAAuC","sourcesContent":["import { BroadcastOperator, Socket } from \"socket.io\";\nimport { User } from \"../../types\";\nimport { DefaultEventsMap } from \"socket.io\";\nimport { Validator } from \"../../types/validation/validator\";\nimport { Options as RateLimitOptions } from \"express-rate-limit\";\nimport { DetailedAccessControlRule } from \"../../types/auth\";\n///@ts-ignore\nimport {\n AllButLast,\n DecorateAcknowledgements,\n DecorateAcknowledgementsWithMultipleResponses,\n EventNames,\n EventNamesWithAck,\n EventNamesWithError,\n EventParams,\n FirstNonErrorArg,\n Last,\n ///@ts-ignore\n} from \"socket.io/dist/typed-events\";\n\nexport interface EventsMap {\n [event: string]: any;\n}\n\nexport interface ArkosSocket<\n ListenEvents extends EventsMap = DefaultEventsMap,\n EmitEvents extends EventsMap = ListenEvents,\n ServerSideEvents extends EventsMap = DefaultEventsMap,\n SocketData extends Validator = any,\n SocketLocals extends Record<string, any> = Record<string, any>,\n> extends Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData> {\n /**\n * Populated by Arkos after successful authentication on connection.\n * Available in all event handlers when `authentication: true` on the gateway.\n */\n currentUser?: User;\n\n /**\n * Populated by Arkos after successful validation.\n * Typed to the event's validation schema when using TypeScript.\n */\n data: SocketData;\n\n /** User access token. */\n accessToken?: string;\n\n /**\n * Metadata from the incoming message, extracted from `_meta` by Arkos.\n *\n * - `mid`: Unique message ID used for deduplication.\n * - `timestamp`: When the message was sent by the client.\n */\n meta?: {\n mid?: string;\n timestamp?: string | number | Date;\n };\n\n /**\n * Per-event local storage, scoped to the current event pipeline.\n * Use to pass data between pipes and the event handler — like Express's `res.locals`.\n * Reset automatically on each event.\n *\n * @example\n * chatGateway.pipe((socket, data) => {\n * socket.locals.enriched = enrichUser(socket.currentUser)\n * })\n *\n * chatGateway.on({ event: \"send_message\" }, (socket, data) => {\n * console.log(socket.locals.enriched)\n * })\n */\n locals?: SocketLocals;\n\n /**\n * Internal Arkos context injected by the gateway at connection time.\n *\n * @internal\n */\n _arkos: {\n store: ArkosGatewayStore;\n gatewayConfig: ArkosGatewayConfig;\n };\n\n /**\n * Targets all active socket connections of a user by their user ID.\n * Uses the internal `arkos::user:{userId}` room convention.\n *\n * Supports emit, management, and exclusion operations across all of the\n * user's active connections.\n *\n * @example\n * socket.user(userId).emit(\"notification\", data)\n * socket.user(userId).except({ user: otherUserId }).emit(\"sync\", data)\n * const sockets = await socket.user(userId).fetchSockets()\n * const online = await socket.user(userId).isOnline()\n *\n * @since 1.7.0-canary.29\n */\n user(userId: string): ArkosUserTarget;\n\n /**\n * Wraps the next `emit` or `emitWithAck` with exponential backoff retry logic.\n * Chain `.timeout(ms)` before `.emitWithAck()` as usual.\n *\n * @example\n * socket.retry(3).emit(\"event\", data)\n * socket.retry(3).timeout(5000).emitWithAck(\"event\", data)\n *\n * @since 1.7.0-canary.29\n */\n retry(\n times: number,\n initialDelay?: number,\n multiplier?: number\n ): ArkosRetryTarget;\n\n /**\n * Emits an event to this client.\n * Arkos automatically injects `_meta` (`mid` + `timestamp`) into every outgoing payload\n * for client-side deduplication and freshness checks.\n *\n * @example\n * socket.emit(\"message\", { text: \"hello\" })\n * socket.emit(\"notification\", { title: \"New order\" })\n */\n emit<Ev extends EventNames<EmitEvents>>(\n ev: Ev,\n ...args: EventParams<EmitEvents, Ev>\n ): true;\n\n /**\n * Emits an event and waits for an acknowledgement from the client.\n * Arkos injects `_meta` automatically. Use `.timeout(ms)` to avoid hanging indefinitely.\n *\n * @example\n * const response = await socket.timeout(5000).emitWithAck(\"confirm\", data)\n */\n emitWithAck<Ev extends EventNamesWithAck<EmitEvents>>(\n ev: Ev,\n ...args: AllButLast<EventParams<EmitEvents, Ev>>\n ): Promise<FirstNonErrorArg<Last<EventParams<EmitEvents, Ev>>>>;\n\n /**\n * Targets a room when broadcasting — excludes the sender.\n * Returns an {@link ArkosBroadcastOperator} with enhanced `.except({ user })` support\n * and automatic `_meta` injection on every `.emit()`.\n *\n * @example\n * socket.to(\"room-101\").emit(\"message\", data)\n * socket.to(\"room-101\").except({ user: userId }).emit(\"message\", data)\n * socket.to(\"room-101\").volatile.emit(\"typing\", data)\n * await socket.to(\"room-101\").timeout(3000).emitWithAck(\"confirm\", data)\n *\n * @since 1.7.0-canary.29\n */\n to(\n room: string | string[]\n ): ArkosBroadcastOperator<\n DecorateAcknowledgementsWithMultipleResponses<EmitEvents>,\n SocketData\n > &\n BroadcastOperator<EmitEvents, SocketData>;\n /**\n * Broadcasts to all connected clients except the sender.\n * Returns an {@link ArkosBroadcastOperator} with enhanced `.except({ user })` support\n * and automatic `_meta` injection on every `.emit()`.\n *\n * @example\n * socket.broadcast.emit(\"announcement\", data)\n * socket.broadcast.except({ user: userId }).emit(\"announcement\", data)\n * socket.broadcast.volatile.emit(\"ping\", data)\n *\n * @since 1.7.0-canary.29\n */\n get broadcast(): ArkosBroadcastOperator<\n DecorateAcknowledgementsWithMultipleResponses<EmitEvents>,\n SocketData\n > &\n BroadcastOperator<EmitEvents, SocketData>;\n}\n\n/**\n * Enhanced broadcast/room target returned by `socket.to()` and `socket.broadcast`.\n * Extends the native `BroadcastOperator` with `{ user }` exclusion support\n * and automatic `_meta` injection on emit.\n *\n * @since 1.7.0-canary.29\n */\nexport interface ArkosBroadcastOperator<\n EmitEvents extends EventsMap = DefaultEventsMap,\n SocketData extends Validator = any,\n> extends BroadcastOperator<EmitEvents, SocketData> {\n /**\n * Exclude sockets from the broadcast.\n * Accepts a room name, socket ID, or `{ user: string | string[] }` to exclude\n * all sockets belonging to one or more users.\n *\n * @example\n * socket.to(\"room-101\").except(\"room-102\").emit(\"foo\", data)\n * socket.broadcast.except({ user: userId }).emit(\"foo\", data)\n * socket.broadcast.except({ user: [userId1, userId2] }).emit(\"foo\", data)\n */\n except(\n room: string | string[] | { user: string | string[] }\n ): ArkosBroadcastOperator<EmitEvents, SocketData>;\n\n /**\n * Emits to all clients,`_meta` is injected automatically.\n *\n * @example\n * // the “foo” event will be broadcast to all connected clients\n * io.emit(\"foo\", \"bar\");\n *\n * // the “foo” event will be broadcast to all connected clients in the “room-101” room\n * io.to(\"room-101\").emit(\"foo\", \"bar\");\n *\n * // with an acknowledgement expected from all connected clients\n * io.timeout(1000).emit(\"some-event\", (err, responses) => {\n * if (err) {\n * // some clients did not acknowledge the event in the given delay\n * } else {\n * console.log(responses); // one response per client\n * }\n * });\n *\n * @return Always true\n */\n emit<Ev extends EventNames<EmitEvents>>(\n ev: Ev,\n ...args: EventParams<EmitEvents, Ev>\n ): true;\n\n /** Chain volatile flag — event may be lost if client is not ready. */\n get volatile(): ArkosBroadcastOperator<EmitEvents, SocketData>;\n\n /** Chain compress flag. */\n compress(value: boolean): ArkosBroadcastOperator<EmitEvents, SocketData>;\n\n /** Chain timeout for `emitWithAck`. */\n timeout(\n ms: number\n ): ArkosBroadcastOperator<DecorateAcknowledgements<EmitEvents>, SocketData>;\n\n /**\n * Emits an event and waits for an acknowledgement from all clients.\n * `_meta` is injected automatically\n * @example\n * try {\n * const responses = await io.timeout(1000).emitWithAck(\"some-event\");\n * console.log(responses); // one response per client\n * } catch (e) {\n * // some clients did not acknowledge the event in the given delay\n * }\n *\n * @return a Promise that will be fulfilled when all clients have acknowledged the event\n */\n emitWithAck<Ev extends EventNamesWithError<EmitEvents>>(\n ev: Ev,\n ...args: AllButLast<EventParams<EmitEvents, Ev>>\n ): Promise<FirstNonErrorArg<Last<EventParams<EmitEvents, Ev>>>>;\n\n /**\n * Targets all active socket connections of a user by their user ID.\n * Uses the internal `arkos::user:{userId}` room convention.\n *\n * Supports emit, management, and exclusion operations across all of the\n * user's active connections.\n *\n * @example\n * socket.user(userId).emit(\"notification\", data)\n * socket.user(userId).except({ user: otherUserId }).emit(\"sync\", data)\n * const sockets = await socket.user(userId).fetchSockets()\n * const online = await socket.user(userId).isOnline()\n *\n * @since 1.7.0-canary.29\n */\n user(userId: string): ArkosUserTarget;\n /**\n * Returns all unique user IDs currently in the target room(s).\n *\n * @example\n * const users = await socket.to(\"room-123\").users()\n */\n users(): Promise<string[]>;\n}\n\n/**\n * Returned by `socket.retry(n)`. Wraps `emit` and `emitWithAck`\n * with exponential backoff. Chain `.timeout(ms)` before `.emitWithAck()` as usual.\n *\n * @since 1.7.0-canary.29\n */\nexport interface ArkosRetryTarget {\n /** Emit with ack and retry. `_meta` is injected automatically. */\n emitWithAck(event: string, data: any, ...rest: any[]): Promise<any>;\n\n /**\n * Chain a timeout before `emitWithAck`.\n *\n * @example\n * socket.retry(3).timeout(5000).emitWithAck(\"event\", data)\n */\n timeout(ms: number): ArkosRetryTarget;\n}\n\n/**\n * Returned by `socket.user(userId)`.\n * Targets all active socket connections of a user.\n *\n * @since 1.7.0-canary.29\n */\nexport interface ArkosUserTarget extends ArkosBroadcastOperator {\n /**\n * Returns all active rooms for this user.\n *\n * @example\n * const rooms = await socket.user(userId).activeRooms()\n * console.log(rooms.length) // number of active tabs/connections\n */\n activeRooms(): Promise<string[]>;\n}\n\nexport type ArkosGatewayPipe = (\n socket: ArkosSocket,\n data: any\n) => void | Promise<void>;\n\n/**\n * Connection-level middleware registered with `gateway.use()`.\n * Same `(socket, next)` contract as Socket.io namespace middleware.\n * Runs before the namespace's authentication middleware and is inherited\n * by nested gateways.\n */\nexport type ArkosGatewayMiddleware = (\n socket: ArkosSocket,\n next: (err?: any) => void\n) => void | Promise<void>;\n\nexport type ArkosGatewayEventConfig<TSchema extends Validator = any> = {\n /** The Socket.io event name to listen for. */\n event: string;\n\n /** Zod schema or class-validator DTO to validate the incoming event payload. */\n validation?: TSchema;\n\n /** Per-event rate limiting. Overrides gateway-level `rateLimit` for this event. */\n rateLimit?: Partial<RateLimitOptions> | false;\n\n /**\n * Authorization configuration.\n *\n * @remarks Gateway `authentication` must NOT be `false` or this throws at registration time.\n */\n authorization?: {\n resource: string;\n action: string;\n rule?: DetailedAccessControlRule | string[] | \"*\";\n };\n\n /**\n * When `true`, Arkos automatically calls `ack({ success: true })` after the handler\n * finishes, unless the handler already called ack manually.\n */\n ack?: boolean;\n\n /** Disables this event handler without removing it. */\n disabled?: boolean;\n\n /**\n * Maximum age in milliseconds for incoming messages.\n * Requires `data._meta.timestamp`. Events older than this are rejected.\n */\n maxAge?: number;\n\n /** Per-event deduplication. Overrides gateway-level `dedup`. */\n dedup?:\n | {\n /** @default true */\n enabled?: boolean;\n /** Time-to-live in seconds for the dedup key. @default 3600 */\n ttl?: number;\n }\n | false;\n};\n\nexport type ArkosGatewayAckFn = (response: any) => void;\n\nexport type ArkosGatewayHandler<TData = any> = (\n socket: ArkosSocket,\n data: TData,\n ack?: ArkosGatewayAckFn\n) => void | Promise<void>;\n\nexport type ArkosGatewayEventEntry = {\n config: ArkosGatewayEventConfig;\n handler: ArkosGatewayHandler;\n pipes: ArkosGatewayPipe[];\n};\n\nexport type ArkosGatewayConnectionHandler = (\n socket: ArkosSocket\n) => void | Promise<void>;\n\nexport type ArkosGatewayHookHandler =\n | ArkosGatewayConnectionHandler\n | ArkosGatewayErrorHandler;\n\nexport type ArkosGatewayErrorHandler = (\n error: any,\n socket: ArkosSocket\n) => void | Promise<void>;\n\nexport type ArkosGatewayHookType = \"connection\" | \"disconnect\" | \"error\";\n\nexport type ArkosGatewayConfig = {\n /**\n * Socket.io namespace for this gateway.\n *\n * @example\n * name: \"/chat\"\n */\n name: string;\n\n /**\n * When `true`, Arkos runs auth middleware on connection and populates `socket.currentUser`.\n * Unauthenticated sockets are rejected.\n *\n * @default false\n */\n authentication?: boolean;\n\n /** Gateway-level rate limiting, applied per socket. Can be overridden per event. */\n rateLimit?: Partial<RateLimitOptions>;\n\n /**\n * Gateway-level deduplication. Drills down to child gateways and can be overridden\n * per child or per event listener.\n */\n dedup?:\n | {\n /** @default true */\n enabled?: boolean;\n /** @default 3600 */\n ttl?: number;\n }\n | false;\n\n /**\n * Maximum age in milliseconds for incoming messages.\n * Can be overridden per event via `maxAge` in `gateway.on()`.\n */\n maxAge?: number;\n};\n\n/**\n * Options for `gateway.register()`.\n * Passed once at the root — applies to all child gateways.\n */\nexport type ArkosGatewayRegisterOptions = {\n /**\n * Unified store for rate limiting and deduplication.\n * Defaults to an in-memory store — zero config for single-instance deployments.\n * For distributed deployments plug in a Redis-backed store.\n *\n * @example\n * store: new RedisArkosStore(redis)\n */\n store?: ArkosGatewayStore;\n};\n\n/**\n * Unified store interface for rate limiting and deduplication.\n * Implement this to plug in Redis, Valkey, or any distributed store.\n *\n * @example\n * class RedisArkosStore implements ArkosGatewayStore {\n * async increment(key, windowMs) { ... }\n * async clear(prefix) { ... }\n * async has(key) { ... }\n * async set(key, ttl) { ... }\n * async setIfNotExists(key, ttl) { ... }\n * }\n */\nexport interface ArkosGatewayStore {\n /** Increment a rate limit counter. Key format: `arkos::rl:{socketId}:{event}` */\n increment(\n key: string,\n windowMs: number\n ): Promise<{ count: number; resetAt: number }>;\n\n /** Clear all rate limit entries matching a prefix. Key format: `arkos::rl:{socketId}` */\n clear(prefix: string): Promise<void>;\n\n /** Check if a dedup key exists. */\n has(key: string): Promise<boolean>;\n\n /** Store a dedup key with TTL in seconds. */\n set(key: string, ttl: number): Promise<void>;\n\n /**\n * Atomically store a dedup key only if it does not already exist.\n * Returns `true` if created (process the message), `false` if duplicate (skip).\n */\n setIfNotExists(key: string, ttl: number): Promise<boolean>;\n}\n\n/**\n * Minimal broadcast/emit contract that {@link ArkosBroadcastOperatorImpl} wraps.\n * Deliberately narrower than socket.io's `BroadcastOperator` — only the methods\n * Arkos actually calls, so both a `BroadcastOperator` (from `socket.to()`) and a\n * raw `Namespace` (from `gateway.nsp`) satisfy it structurally.\n *\n * @since 1.7.1-canary.3\n */\nexport interface ArkosEmitTarget<EmitEvents extends EventsMap = DefaultEventsMap> {\n /**\n * Emits an event to the target. `_meta` (`mid` + `timestamp`) is injected automatically.\n *\n * @example\n * socket.to(\"room-101\").emit(\"message\", { text: \"hello\" })\n * socket.broadcast.emit(\"announcement\", data)\n */\n emit(event: string, ...args: any[]): boolean;\n\n /**\n * Emits an event and waits for an acknowledgement from all matched clients.\n * `_meta` is injected automatically.\n *\n * Optional — not every target supports ack collection directly (e.g. a raw\n * `Namespace` requires `.timeout(ms)` first). Throws at runtime if called on\n * a target that doesn't implement it natively.\n *\n * @example\n * const responses = await socket.to(\"room-101\").timeout(3000).emitWithAck(\"confirm\", data)\n */\n emitWithAck?(event: string, ...args: any[]): Promise<any>;\n\n /**\n * Excludes sockets from the broadcast.\n * Accepts a room name, socket ID, or array of rooms/IDs.\n * For `{ user }` exclusion, see {@link ArkosBroadcastOperatorImpl.except}.\n *\n * @example\n * socket.to(\"room-101\").except(\"room-102\").emit(\"foo\", data)\n */\n except(room: string | string[]): ArkosEmitTarget<EmitEvents>;\n\n /**\n * Sets the compress flag for the next emission.\n *\n * @example\n * socket.broadcast.compress(false).emit(\"ping\", data)\n */\n compress(value: boolean): ArkosEmitTarget<EmitEvents>;\n\n /**\n * Sets a timeout in milliseconds for `emitWithAck`.\n * Rejects the promise if no client acknowledges within the given delay.\n *\n * @example\n * socket.to(\"room-101\").timeout(3000).emitWithAck(\"confirm\", data)\n */\n timeout(ms: number): ArkosEmitTarget\n\n /**\n * Returns all sockets currently matched by this target.\n *\n * @example\n * const sockets = await socket.to(\"room-101\").fetchSockets()\n */\n fetchSockets(): Promise<any[]>;\n\n to(room: string | string[]): ArkosEmitTarget\n\n /**\n * Sets the volatile flag — the event may be dropped if the client is not ready.\n * Useful for high-frequency non-critical events like cursor positions or typing indicators.\n *\n * @example\n * socket.to(\"room-101\").volatile.emit(\"cursor\", position)\n */\n readonly volatile: ArkosEmitTarget<EmitEvents>;\n}\nexport class ArkosGatewayController { }\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websockets.js","sourceRoot":"","sources":["../../../src/exports/websockets.ts"],"names":[],"mappings":";;;;;;AAAA,8FAAqE;
|
|
1
|
+
{"version":3,"file":"websockets.js","sourceRoot":"","sources":["../../../src/exports/websockets.ts"],"names":[],"mappings":";;;;;;AAAA,8FAAqE;AAiB5D,uBAjBF,uBAAY,CAiBE;AAfrB,2EAA0E;AAAjE,8GAAA,aAAa,OAAA;AACtB,2DAA2E;AAAlE,+GAAA,sBAAsB,OAAA","sourcesContent":["import ArkosGateway from \"../components/arkos-gateway/arkos-gateway\";\n\nexport { IArkosGateway } from \"../components/arkos-gateway/arkos-gateway\";\nexport { ArkosGatewayController } from \"../components/arkos-gateway/types\";\nexport type {\n ArkosSocket,\n ArkosGatewayConfig,\n ArkosGatewayEventConfig,\n ArkosGatewayHandler,\n ArkosGatewayPipe,\n ArkosGatewayMiddleware,\n ArkosGatewayConnectionHandler,\n ArkosGatewayErrorHandler,\n ArkosGatewayAckFn,\n ArkosBroadcastOperator,\n} from \"../components/arkos-gateway/types\";\n\nexport { ArkosGateway };\n"]}
|
|
@@ -17,6 +17,7 @@ const fs_helpers_1 = require("../../utils/helpers/fs.helpers.js");
|
|
|
17
17
|
const arkos_router_1 = __importDefault(require("../../utils/arkos-router/index.js"));
|
|
18
18
|
const auth_openapi_generator_1 = __importDefault(require("./utils/auth-openapi-generator.js"));
|
|
19
19
|
const prisma_helpers_1 = require("../../utils/helpers/prisma.helpers.js");
|
|
20
|
+
const exit_error_1 = __importDefault(require("../../utils/helpers/exit-error.js"));
|
|
20
21
|
const router = (0, arkos_router_1.default)();
|
|
21
22
|
function getAuthRouter(arkosConfig) {
|
|
22
23
|
if (!(0, prisma_helpers_1.getPrismaInstance)())
|
|
@@ -28,7 +29,7 @@ function getAuthRouter(arkosConfig) {
|
|
|
28
29
|
if (router_validator_1.default.isExpressRouter(customRouter))
|
|
29
30
|
router.use({ path: "/auth" }, customRouter);
|
|
30
31
|
else
|
|
31
|
-
throw
|
|
32
|
+
throw (0, exit_error_1.default)(`ValidationError: The exported router from auth.router.${(0, fs_helpers_1.getUserFileExtension)()} is not a valid express or arkos Router.`);
|
|
32
33
|
}
|
|
33
34
|
const authController = (0, auth_controller_1.authControllerFactory)(interceptors);
|
|
34
35
|
if (routerConfig?.disable === true)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.router.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.router.ts"],"names":[],"mappings":";;;;;AA0BA,sCAmUC;AA5VD,uDAA0D;AAC1D,4EAA2C;AAC3C,+DAAiE;AACjE,+DAGkC;AAClC,4FAA6D;AAE7D,yEAG6C;AAC7C,mFAA+E;AAC/E,oFAA2D;AAC3D,sFAA6D;AAC7D,+DAAsE;AACtE,4EAAmD;AAEnD,4FAAkE;AAElE,uEAAuE;AAEvE,MAAM,MAAM,GAAG,IAAA,sBAAW,GAAE,CAAC;AAE7B,SAAgB,aAAa,CAAC,WAA4B;IACxD,IAAI,CAAC,IAAA,kCAAiB,GAAE;QAAE,OAAO,MAAM,CAAC;IAExC,MAAM,EACJ,YAAY,EACZ,IAAI,EACJ,OAAO,EACP,kBAAkB,EAClB,MAAM,EAAE,kBAAkB,EAC1B,WAAW,GACZ,GAAG,IAAA,oCAAmB,EAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAEtC,MAAM,YAAY,GACf,kBAAkB,EAAE,MAAc,IAAI,EAAE,CAAC;IAC5C,MAAM,YAAY,GAAG,kBAAkB,EAAE,OAAiB,CAAC;IAE3D,IAAI,YAAY,IAAI,kBAAkB,EAAE,CAAC;QACvC,IAAI,0BAAe,CAAC,eAAe,CAAC,YAAY,CAAC;YAC/C,MAAM,CAAC,GAAG,CAAC,EAAE,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IAAA,mCAAiB,EAAC,YAAY,EAAE,uBAAuB,CAAC,EAC3D,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,yBAAyB,EAAE;YAC5D,IAAI,EAAE,OAAO;SACd,CAAC,CACH,CAAC;IACJ,CAAC;IAGD,IAAI,CAAC,IAAA,wCAAkB,EAAC,YAAY,EAAE,mBAAmB,CAAC,EAAE,CAAC;QAC3D,MAAM,CAAC,GAAG,CACR,IAAA,mCAAiB,EACf,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,MAAM,EACN,WAAW,CACZ,EACD,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,uBAAuB,CAAC,EAC3D,cAAc,CAAC,iBAAiB,EAChC,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,sBAAsB,CAAC,EAC1D,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,wBAAwB,EAAE;YAC3D,IAAI,EAAE,OAAO;SACd,CAAC,CACH,CAAC;IACJ,CAAC;IAED,0BAAe,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAa,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { authControllerFactory } from \"./auth.controller\";\nimport rateLimit from \"express-rate-limit\";\nimport { getModuleComponents } from \"../../utils/dynamic-loader\";\nimport {\n addPrismaQueryOptionsToRequest,\n sendResponse,\n} from \"../base/base.middlewares\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthPrismaQueryOptions } from \"../../types\";\nimport {\n processMiddleware,\n createRouteConfig,\n} from \"../../utils/helpers/routers.helpers\";\nimport { isEndpointDisabled } from \"../base/utils/helpers/base.router.helpers\";\nimport debuggerService from \"../debugger/debugger.service\";\nimport routerValidator from \"../base/utils/router-validator\";\nimport { getUserFileExtension } from \"../../utils/helpers/fs.helpers\";\nimport ArkosRouter from \"../../utils/arkos-router\";\nimport { UserArkosConfig } from \"../../utils/define-config\";\nimport authOpenAPIGenerator from \"./utils/auth-openapi-generator\";\nimport { AuthRouterEndpoint, RouteHook } from \"../../types/router-config\";\nimport { getPrismaInstance } from \"../../utils/helpers/prisma.helpers\";\n\nconst router = ArkosRouter();\n\nexport function getAuthRouter(arkosConfig: UserArkosConfig) {\n if (!getPrismaInstance()) return router;\n\n const {\n interceptors,\n dtos,\n schemas,\n prismaQueryOptions,\n router: customRouterModule,\n authConfigs,\n } = getModuleComponents(\"auth\") || {};\n\n const routerConfig: RouteHook<\"auth\"> =\n (customRouterModule?.config as any) || {};\n const customRouter = customRouterModule?.default as Router;\n\n if (customRouter && customRouterModule) {\n if (routerValidator.isExpressRouter(customRouter))\n router.use({ path: \"/auth\" }, customRouter);\n else\n throw Error(\n `ValidationError: The exported router from auth.router.${getUserFileExtension()} is not a valid express or arkos Router.`\n );\n }\n\n const authController = authControllerFactory(interceptors);\n\n if (routerConfig?.disable === true) return router;\n\n const getValidationSchemaOrDto = (\n key: \"updateMe\" | \"updatePassword\" | \"login\" | \"signup\"\n ) => {\n const validationConfigs = arkosConfig?.validation;\n if (validationConfigs?.resolver === \"class-validator\") return dtos?.[key];\n else if (validationConfigs?.resolver === \"zod\") return schemas?.[key];\n\n return undefined;\n };\n\n const endpoints: AuthRouterEndpoint[] = [\n \"login\",\n \"logout\",\n \"signup\",\n \"updatePassword\",\n \"getMe\",\n \"updateMe\",\n \"deleteMe\",\n \"findManyAuthAction\",\n \"findOneAuthAction\",\n ];\n\n for (const endpoint of endpoints) {\n let endpointConfig = routerConfig[endpoint] || {};\n\n const schema = getValidationSchemaOrDto(endpoint as any);\n if (\n schema &&\n endpointConfig?.validation !== false &&\n endpointConfig?.validation?.body !== false\n )\n endpointConfig = {\n ...(endpointConfig || {}),\n validation: {\n ...(endpointConfig?.validation || {}),\n body: schema,\n },\n };\n\n if (endpointConfig?.experimental?.openapi !== false)\n endpointConfig = {\n ...(endpointConfig || {}),\n experimental: {\n ...(endpointConfig?.experimental || {}),\n openapi: authOpenAPIGenerator.getOpenApiConfig(\n endpointConfig,\n endpoint\n ),\n },\n };\n\n routerConfig[endpoint] = endpointConfig;\n }\n\n // GET /users/me - Get current user\n if (!isEndpointDisabled(routerConfig, \"getMe\")) {\n router.get(\n createRouteConfig(\n arkosConfig,\n \"getMe\",\n \"users\",\n \"/me\",\n routerConfig,\n \"auth\",\n true\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"getMe\"\n ),\n ...processMiddleware(interceptors?.beforeGetMe),\n authController.getMe,\n ...processMiddleware(interceptors?.afterGetMe),\n sendResponse,\n ...processMiddleware(interceptors?.onGetMeError, { type: \"error\" })\n );\n }\n\n // PATCH /users/me - Update current user\n if (!isEndpointDisabled(routerConfig, \"updateMe\")) {\n router.patch(\n createRouteConfig(\n arkosConfig,\n \"updateMe\",\n \"users\",\n \"/me\",\n routerConfig,\n \"auth\",\n true\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updateMe\"\n ),\n ...processMiddleware(interceptors?.beforeUpdateMe),\n authController.updateMe,\n ...processMiddleware(interceptors?.afterUpdateMe),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdateMeError, { type: \"error\" })\n );\n }\n\n // DELETE /users/me - Delete current user\n if (!isEndpointDisabled(routerConfig, \"deleteMe\")) {\n router.delete(\n createRouteConfig(\n arkosConfig,\n \"deleteMe\",\n \"users\",\n \"/me\",\n routerConfig,\n \"auth\",\n true\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"deleteMe\"\n ),\n ...processMiddleware(interceptors?.beforeDeleteMe),\n authController.deleteMe,\n ...processMiddleware(interceptors?.afterDeleteMe),\n sendResponse,\n ...processMiddleware(interceptors?.onDeleteMeError, { type: \"error\" })\n );\n }\n\n // Apply rate limiting to auth routes\n if (\n !isEndpointDisabled(routerConfig, \"login\") ||\n !isEndpointDisabled(routerConfig, \"logout\") ||\n !isEndpointDisabled(routerConfig, \"signup\") ||\n !isEndpointDisabled(routerConfig, \"updatePassword\")\n ) {\n router.use(\n { path: \"/auth\" },\n rateLimit(\n deepmerge(\n {\n windowMs: 5000,\n limit: 10,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n handler: (_, res) => {\n res.status(429).json({\n message: \"Too many requests, please try again later\",\n });\n },\n },\n arkosConfig?.authentication?.rateLimit || {}\n )\n )\n );\n }\n\n // POST /auth/login - Login\n if (!isEndpointDisabled(routerConfig, \"login\")) {\n router.post(\n createRouteConfig(\n arkosConfig,\n \"login\",\n \"auth\",\n \"/login\",\n routerConfig,\n \"auth\",\n false\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"login\"\n ),\n ...processMiddleware(interceptors?.beforeLogin),\n authController.login,\n ...processMiddleware(interceptors?.afterLogin),\n sendResponse,\n ...processMiddleware(interceptors?.onLoginError, { type: \"error\" })\n );\n }\n\n // DELETE /auth/logout - Logout\n if (!isEndpointDisabled(routerConfig, \"logout\")) {\n router.delete(\n createRouteConfig(\n arkosConfig,\n \"logout\",\n \"auth\",\n \"/logout\",\n routerConfig,\n \"auth\",\n true\n ),\n ...processMiddleware(interceptors?.beforeLogout),\n authController.logout,\n ...processMiddleware(interceptors?.afterLogout),\n sendResponse,\n ...processMiddleware(interceptors?.onLogoutError, { type: \"error\" })\n );\n }\n\n // POST /auth/signup - Signup\n if (!isEndpointDisabled(routerConfig, \"signup\")) {\n router.post(\n createRouteConfig(\n arkosConfig,\n \"signup\",\n \"auth\",\n \"/signup\",\n routerConfig,\n \"auth\",\n false\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"signup\"\n ),\n ...processMiddleware(interceptors?.beforeSignup),\n authController.signup,\n ...processMiddleware(interceptors?.afterSignup),\n sendResponse,\n ...processMiddleware(interceptors?.onSignupError, { type: \"error\" })\n );\n }\n\n // POST /auth/update-password - Update password\n if (!isEndpointDisabled(routerConfig, \"updatePassword\")) {\n router.post(\n createRouteConfig(\n arkosConfig,\n \"updatePassword\",\n \"auth\",\n \"/update-password\",\n routerConfig,\n \"auth\",\n true\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updatePassword\"\n ),\n ...processMiddleware(interceptors?.beforeUpdatePassword),\n authController.updatePassword,\n ...processMiddleware(interceptors?.afterUpdatePassword),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdatePasswordError, {\n type: \"error\",\n })\n );\n }\n\n // GET /auth-actions - Find many auth actions\n if (!isEndpointDisabled(routerConfig, \"findManyAuthAction\")) {\n router.get(\n createRouteConfig(\n arkosConfig,\n \"findManyAuthAction\",\n \"auth-actions\",\n \"\",\n routerConfig,\n \"auth\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeFindManyAuthAction),\n authController.findManyAuthAction,\n ...processMiddleware(interceptors?.afterFindManyAuthAction),\n sendResponse,\n ...processMiddleware(interceptors?.onFindManyAuthActionError, {\n type: \"error\",\n })\n );\n }\n\n // GET /auth-actions/:resourceName - Find one auth action\n if (!isEndpointDisabled(routerConfig, \"findOneAuthAction\")) {\n router.get(\n createRouteConfig(\n arkosConfig,\n \"findOneAuthAction\",\n \"auth-actions\",\n \"/:resourceName\",\n routerConfig,\n \"auth\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeFindOneAuthAction),\n authController.findOneAuthAction,\n ...processMiddleware(interceptors?.afterFindOneAuthAction),\n sendResponse,\n ...processMiddleware(interceptors?.onFindOneAuthActionError, {\n type: \"error\",\n })\n );\n }\n\n debuggerService.logModuleFinalRouter(\"auth\", router as any);\n return router;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"auth.router.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.router.ts"],"names":[],"mappings":";;;;;AA2BA,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AC,EAC3D,cAAc,CAAC,iBAAiB,EAChC,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,sBAAsB,CAAC,EAC1D,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,wBAAwB,EAAE;YAC3D,IAAI,EAAE,OAAO;SACd,CAAC,CACH,CAAC;IACJ,CAAC;IAED,0BAAe,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAa,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { authControllerFactory } from \"./auth.controller\";\nimport rateLimit from \"express-rate-limit\";\nimport { getModuleComponents } from \"../../utils/dynamic-loader\";\nimport {\n addPrismaQueryOptionsToRequest,\n sendResponse,\n} from \"../base/base.middlewares\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthPrismaQueryOptions } from \"../../types\";\nimport {\n processMiddleware,\n createRouteConfig,\n} from \"../../utils/helpers/routers.helpers\";\nimport { isEndpointDisabled } from \"../base/utils/helpers/base.router.helpers\";\nimport debuggerService from \"../debugger/debugger.service\";\nimport routerValidator from \"../base/utils/router-validator\";\nimport { getUserFileExtension } from \"../../utils/helpers/fs.helpers\";\nimport ArkosRouter from \"../../utils/arkos-router\";\nimport { UserArkosConfig } from \"../../utils/define-config\";\nimport authOpenAPIGenerator from \"./utils/auth-openapi-generator\";\nimport { AuthRouterEndpoint, RouteHook } from \"../../types/router-config\";\nimport { getPrismaInstance } from \"../../utils/helpers/prisma.helpers\";\nimport ExitError from \"../../utils/helpers/exit-error\";\n\nconst router = ArkosRouter();\n\nexport function getAuthRouter(arkosConfig: UserArkosConfig) {\n if (!getPrismaInstance()) return router;\n\n const {\n interceptors,\n dtos,\n schemas,\n prismaQueryOptions,\n router: customRouterModule,\n authConfigs,\n } = getModuleComponents(\"auth\") || {};\n\n const routerConfig: RouteHook<\"auth\"> =\n (customRouterModule?.config as any) || {};\n const customRouter = customRouterModule?.default as Router;\n\n if (customRouter && customRouterModule) {\n if (routerValidator.isExpressRouter(customRouter))\n router.use({ path: \"/auth\" }, customRouter);\n else\n throw ExitError(\n `ValidationError: The exported router from auth.router.${getUserFileExtension()} is not a valid express or arkos Router.`\n );\n }\n\n const authController = authControllerFactory(interceptors);\n\n if (routerConfig?.disable === true) return router;\n\n const getValidationSchemaOrDto = (\n key: \"updateMe\" | \"updatePassword\" | \"login\" | \"signup\"\n ) => {\n const validationConfigs = arkosConfig?.validation;\n if (validationConfigs?.resolver === \"class-validator\") return dtos?.[key];\n else if (validationConfigs?.resolver === \"zod\") return schemas?.[key];\n\n return undefined;\n };\n\n const endpoints: AuthRouterEndpoint[] = [\n \"login\",\n \"logout\",\n \"signup\",\n \"updatePassword\",\n \"getMe\",\n \"updateMe\",\n \"deleteMe\",\n \"findManyAuthAction\",\n \"findOneAuthAction\",\n ];\n\n for (const endpoint of endpoints) {\n let endpointConfig = routerConfig[endpoint] || {};\n\n const schema = getValidationSchemaOrDto(endpoint as any);\n if (\n schema &&\n endpointConfig?.validation !== false &&\n endpointConfig?.validation?.body !== false\n )\n endpointConfig = {\n ...(endpointConfig || {}),\n validation: {\n ...(endpointConfig?.validation || {}),\n body: schema,\n },\n };\n\n if (endpointConfig?.experimental?.openapi !== false)\n endpointConfig = {\n ...(endpointConfig || {}),\n experimental: {\n ...(endpointConfig?.experimental || {}),\n openapi: authOpenAPIGenerator.getOpenApiConfig(\n endpointConfig,\n endpoint\n ),\n },\n };\n\n routerConfig[endpoint] = endpointConfig;\n }\n\n // GET /users/me - Get current user\n if (!isEndpointDisabled(routerConfig, \"getMe\")) {\n router.get(\n createRouteConfig(\n arkosConfig,\n \"getMe\",\n \"users\",\n \"/me\",\n routerConfig,\n \"auth\",\n true\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"getMe\"\n ),\n ...processMiddleware(interceptors?.beforeGetMe),\n authController.getMe,\n ...processMiddleware(interceptors?.afterGetMe),\n sendResponse,\n ...processMiddleware(interceptors?.onGetMeError, { type: \"error\" })\n );\n }\n\n // PATCH /users/me - Update current user\n if (!isEndpointDisabled(routerConfig, \"updateMe\")) {\n router.patch(\n createRouteConfig(\n arkosConfig,\n \"updateMe\",\n \"users\",\n \"/me\",\n routerConfig,\n \"auth\",\n true\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updateMe\"\n ),\n ...processMiddleware(interceptors?.beforeUpdateMe),\n authController.updateMe,\n ...processMiddleware(interceptors?.afterUpdateMe),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdateMeError, { type: \"error\" })\n );\n }\n\n // DELETE /users/me - Delete current user\n if (!isEndpointDisabled(routerConfig, \"deleteMe\")) {\n router.delete(\n createRouteConfig(\n arkosConfig,\n \"deleteMe\",\n \"users\",\n \"/me\",\n routerConfig,\n \"auth\",\n true\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"deleteMe\"\n ),\n ...processMiddleware(interceptors?.beforeDeleteMe),\n authController.deleteMe,\n ...processMiddleware(interceptors?.afterDeleteMe),\n sendResponse,\n ...processMiddleware(interceptors?.onDeleteMeError, { type: \"error\" })\n );\n }\n\n // Apply rate limiting to auth routes\n if (\n !isEndpointDisabled(routerConfig, \"login\") ||\n !isEndpointDisabled(routerConfig, \"logout\") ||\n !isEndpointDisabled(routerConfig, \"signup\") ||\n !isEndpointDisabled(routerConfig, \"updatePassword\")\n ) {\n router.use(\n { path: \"/auth\" },\n rateLimit(\n deepmerge(\n {\n windowMs: 5000,\n limit: 10,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n handler: (_, res) => {\n res.status(429).json({\n message: \"Too many requests, please try again later\",\n });\n },\n },\n arkosConfig?.authentication?.rateLimit || {}\n )\n )\n );\n }\n\n // POST /auth/login - Login\n if (!isEndpointDisabled(routerConfig, \"login\")) {\n router.post(\n createRouteConfig(\n arkosConfig,\n \"login\",\n \"auth\",\n \"/login\",\n routerConfig,\n \"auth\",\n false\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"login\"\n ),\n ...processMiddleware(interceptors?.beforeLogin),\n authController.login,\n ...processMiddleware(interceptors?.afterLogin),\n sendResponse,\n ...processMiddleware(interceptors?.onLoginError, { type: \"error\" })\n );\n }\n\n // DELETE /auth/logout - Logout\n if (!isEndpointDisabled(routerConfig, \"logout\")) {\n router.delete(\n createRouteConfig(\n arkosConfig,\n \"logout\",\n \"auth\",\n \"/logout\",\n routerConfig,\n \"auth\",\n true\n ),\n ...processMiddleware(interceptors?.beforeLogout),\n authController.logout,\n ...processMiddleware(interceptors?.afterLogout),\n sendResponse,\n ...processMiddleware(interceptors?.onLogoutError, { type: \"error\" })\n );\n }\n\n // POST /auth/signup - Signup\n if (!isEndpointDisabled(routerConfig, \"signup\")) {\n router.post(\n createRouteConfig(\n arkosConfig,\n \"signup\",\n \"auth\",\n \"/signup\",\n routerConfig,\n \"auth\",\n false\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"signup\"\n ),\n ...processMiddleware(interceptors?.beforeSignup),\n authController.signup,\n ...processMiddleware(interceptors?.afterSignup),\n sendResponse,\n ...processMiddleware(interceptors?.onSignupError, { type: \"error\" })\n );\n }\n\n // POST /auth/update-password - Update password\n if (!isEndpointDisabled(routerConfig, \"updatePassword\")) {\n router.post(\n createRouteConfig(\n arkosConfig,\n \"updatePassword\",\n \"auth\",\n \"/update-password\",\n routerConfig,\n \"auth\",\n true\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updatePassword\"\n ),\n ...processMiddleware(interceptors?.beforeUpdatePassword),\n authController.updatePassword,\n ...processMiddleware(interceptors?.afterUpdatePassword),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdatePasswordError, {\n type: \"error\",\n })\n );\n }\n\n // GET /auth-actions - Find many auth actions\n if (!isEndpointDisabled(routerConfig, \"findManyAuthAction\")) {\n router.get(\n createRouteConfig(\n arkosConfig,\n \"findManyAuthAction\",\n \"auth-actions\",\n \"\",\n routerConfig,\n \"auth\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeFindManyAuthAction),\n authController.findManyAuthAction,\n ...processMiddleware(interceptors?.afterFindManyAuthAction),\n sendResponse,\n ...processMiddleware(interceptors?.onFindManyAuthActionError, {\n type: \"error\",\n })\n );\n }\n\n // GET /auth-actions/:resourceName - Find one auth action\n if (!isEndpointDisabled(routerConfig, \"findOneAuthAction\")) {\n router.get(\n createRouteConfig(\n arkosConfig,\n \"findOneAuthAction\",\n \"auth-actions\",\n \"/:resourceName\",\n routerConfig,\n \"auth\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeFindOneAuthAction),\n authController.findOneAuthAction,\n ...processMiddleware(interceptors?.afterFindOneAuthAction),\n sendResponse,\n ...processMiddleware(interceptors?.onFindOneAuthActionError, {\n type: \"error\",\n })\n );\n }\n\n debuggerService.logModuleFinalRouter(\"auth\", router as any);\n return router;\n}\n"]}
|
|
@@ -19,6 +19,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
19
19
|
const arkos_router_1 = __importDefault(require("../../utils/arkos-router/index.js"));
|
|
20
20
|
const file_upload_json_schema_generator_1 = __importDefault(require("./utils/file-upload-json-schema-generator.js"));
|
|
21
21
|
const app_error_1 = __importDefault(require("../error-handler/utils/app-error.js"));
|
|
22
|
+
const exit_error_1 = __importDefault(require("../../utils/helpers/exit-error.js"));
|
|
22
23
|
function getFileUploadRouter(arkosConfig) {
|
|
23
24
|
const router = (0, arkos_router_1.default)();
|
|
24
25
|
const { fileUpload, globalPrefix } = arkosConfig;
|
|
@@ -46,7 +47,7 @@ function getFileUploadRouter(arkosConfig) {
|
|
|
46
47
|
if (router_validator_1.default.isExpressRouter(customRouter))
|
|
47
48
|
router.use({ path: basePathname }, customRouter);
|
|
48
49
|
else
|
|
49
|
-
throw
|
|
50
|
+
throw (0, exit_error_1.default)(`ValidationError: The exported router from file-upload.router.${(0, fs_helpers_1.getUserFileExtension)()} is not a valid express or arkos Router.`);
|
|
50
51
|
}
|
|
51
52
|
const endpoints = [
|
|
52
53
|
"findFile",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-upload.router.js","sourceRoot":"","sources":["../../../../src/modules/file-upload/file-upload.router.ts"],"names":[],"mappings":";;;;;AAwBA,kDAqLC;AA5MD,+DAAiE;AACjE,sFAA4D;AAC5D,sDAA8B;AAC9B,4FAA6D;AAE7D,+DAAwD;AACxD,yEAG6C;AAC7C,6EAAuE;AACvE,mFAA+E;AAC/E,oFAA2D;AAC3D,sFAA6D;AAC7D,+DAAsE;AAEtE,gDAAwB;AACxB,4EAAmD;AAGnD,kHAAsF;AACtF,iFAAwD;AAExD,SAAgB,mBAAmB,CAAC,WAA4B;IAC9D,MAAM,MAAM,GAAG,IAAA,sBAAW,GAAE,CAAC;IAC7B,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,WAAW,CAAC;IAEjD,IAAI,CAAC,UAAU,EAAE,OAAO,KAAK,KAAK;QAAE,OAAO,MAAM,CAAC;IAElD,MAAM,gBAAgB,GAAG,IAAA,oCAAmB,EAAC,aAAa,CAAC,CAAC;IAC5D,IAAI,EACF,YAAY,GAAG,EAAS,EACxB,WAAW,GAAG,EAAiB,EAC/B,MAAM,EAAE,kBAAkB,GAC3B,GAAQ,EAAE,CAAC;IAEZ,IAAI,gBAAgB;QAClB,CAAC;YACC,YAAY,GAAG,EAAE;YACjB,WAAW,GAAG,EAAE;YAChB,MAAM,EAAE,kBAAkB;SAC3B,GAAG,gBAAgB,CAAC,CAAC;IAExB,MAAM,YAAY,GAAG,kBAAkB,EAAE,MAAM,IAAI,EAAE,CAAC;IACtD,IAAI,YAAY,EAAE,OAAO,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAElD,M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,EACpD,gCAAoB,CAAC,UAAU,EAC/B,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,eAAe,CAAC,EACnD,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,iBAAiB,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CACzE,CAAC;IACJ,CAAC;IAED,0BAAe,CAAC,oBAAoB,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { getModuleComponents } from \"../../utils/dynamic-loader\";\nimport fileUploadController from \"./file-upload.controller\";\nimport express from \"express\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthConfigs } from \"../../types/auth\";\nimport { sendResponse } from \"../base/base.middlewares\";\nimport {\n createRouteConfig,\n processMiddleware,\n} from \"../../utils/helpers/routers.helpers\";\nimport { adjustRequestUrl } from \"./utils/helpers/file-upload.helpers\";\nimport { isEndpointDisabled } from \"../base/utils/helpers/base.router.helpers\";\nimport debuggerService from \"../debugger/debugger.service\";\nimport routerValidator from \"../base/utils/router-validator\";\nimport { getUserFileExtension } from \"../../utils/helpers/fs.helpers\";\nimport { ArkosNextFunction, ArkosRequest, ArkosResponse } from \"../../exports\";\nimport path from \"path\";\nimport ArkosRouter from \"../../utils/arkos-router\";\nimport { UserArkosConfig } from \"../../utils/define-config\";\nimport { FileUploadRouterEndpoint } from \"../../types/router-config\";\nimport fileUploadJsonSchemaGenerator from \"./utils/file-upload-json-schema-generator\";\nimport AppError from \"../error-handler/utils/app-error\";\n\nexport function getFileUploadRouter(arkosConfig: UserArkosConfig) {\n const router = ArkosRouter();\n const { fileUpload, globalPrefix } = arkosConfig;\n\n if (!fileUpload?.enabled === false) return router;\n\n const moduleComponents = getModuleComponents(\"file-upload\");\n let {\n interceptors = {} as any,\n authConfigs = {} as AuthConfigs,\n router: customRouterModule,\n }: any = {};\n\n if (moduleComponents)\n ({\n interceptors = {},\n authConfigs = {},\n router: customRouterModule,\n } = moduleComponents);\n\n const routerConfig = customRouterModule?.config || {};\n if (routerConfig?.disable === true) return router;\n\n const customRouter = customRouterModule?.default as Router;\n let basePathname = fileUpload?.baseRoute || \"/api/uploads/\";\n\n if (!basePathname.startsWith(\"/\")) basePathname = \"/\" + basePathname;\n if (!basePathname.endsWith(\"/\")) basePathname = basePathname + \"/\";\n\n // Strip leading slash so createRouteConfig can prepend its own \"/\"\n // e.g. \"/api/uploads/\" → \"api/uploads/\" → createRouteConfig builds \"/api/uploads/*\"\n const baseRoutePrefix = basePathname.slice(1);\n\n if (customRouter && customRouterModule) {\n if (routerValidator.isExpressRouter(customRouter))\n router.use({ path: basePathname }, customRouter);\n else\n throw Error(\n `ValidationError: The exported router from file-upload.router.${getUserFileExtension()} is not a valid express or arkos Router.`\n );\n }\n\n const endpoints: FileUploadRouterEndpoint[] = [\n \"findFile\",\n \"uploadFile\",\n \"updateFile\",\n \"deleteFile\",\n ];\n\n for (const endpoint of endpoints) {\n const endpointConfig = routerConfig[endpoint];\n if (endpointConfig?.experimental?.openapi === false) continue;\n routerConfig[endpoint] = {\n ...(endpointConfig || {}),\n experimental: {\n ...(endpointConfig?.experimental || {}),\n openapi: fileUploadJsonSchemaGenerator.getOpenApiConfig(\n endpointConfig,\n endpoint\n ),\n },\n };\n }\n\n if (!isEndpointDisabled(routerConfig, \"findFile\")) {\n const baseUploadDirFullPath = path.resolve(\n path\n .join(process.cwd(), fileUpload?.baseUploadDir || \"uploads\")\n .replaceAll(\"//\", \"/\")\n );\n router.get(\n createRouteConfig(\n arkosConfig,\n \"findFile\",\n baseRoutePrefix,\n `*`,\n routerConfig,\n \"file-upload\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeFindFile),\n adjustRequestUrl,\n express.static(\n baseUploadDirFullPath,\n deepmerge(\n {\n maxAge: \"1y\",\n etag: true,\n lastModified: true,\n dotfiles: \"ignore\",\n fallthrough: false,\n index: false,\n cacheControl: true,\n },\n fileUpload?.expressStatic || {}\n )\n ),\n (\n err: any,\n req: ArkosRequest,\n _res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n if (err.code === \"ENOENT\") {\n const filepath = req.path.replace(\n `${globalPrefix}/${arkosConfig.fileUpload?.baseRoute}`.replace(\"//\", \"/\"),\n \"\"\n );\n throw new AppError(\n `File ${filepath} was not found`,\n 404,\n \"FileNotFound\",\n { filepath }\n );\n }\n\n next(err);\n },\n ...processMiddleware(interceptors?.onFindFileError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"uploadFile\")) {\n router.post(\n createRouteConfig(\n arkosConfig,\n \"uploadFile\",\n baseRoutePrefix,\n `:fileType`,\n routerConfig,\n \"file-upload\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeUploadFile),\n fileUploadController.uploadFile,\n ...processMiddleware(interceptors?.afterUploadFile),\n sendResponse,\n ...processMiddleware(interceptors?.onUploadFileError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"updateFile\")) {\n router.patch(\n createRouteConfig(\n arkosConfig,\n \"updateFile\",\n baseRoutePrefix,\n `:fileType/:fileName`,\n routerConfig,\n \"file-upload\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeUpdateFile),\n fileUploadController.updateFile,\n ...processMiddleware(interceptors?.afterUpdateFile),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdateFileError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"deleteFile\")) {\n router.delete(\n createRouteConfig(\n arkosConfig,\n \"deleteFile\",\n baseRoutePrefix,\n `:fileType/:fileName`,\n routerConfig,\n \"file-upload\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeDeleteFile),\n fileUploadController.deleteFile,\n ...processMiddleware(interceptors?.afterDeleteFile),\n sendResponse,\n ...processMiddleware(interceptors?.onDeleteFileError, { type: \"error\" })\n );\n }\n\n debuggerService.logModuleFinalRouter(\"file-upload\", router);\n return router;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"file-upload.router.js","sourceRoot":"","sources":["../../../../src/modules/file-upload/file-upload.router.ts"],"names":[],"mappings":";;;;;AAyBA,kDAqLC;AA7MD,+DAAiE;AACjE,sFAA4D;AAC5D,sDAA8B;AAC9B,4FAA6D;AAE7D,+DAAwD;AACxD,yEAG6C;AAC7C,6EAAuE;AACvE,mFAA+E;AAC/E,oFAA2D;AAC3D,sFAA6D;AAC7D,+DAAsE;AAEtE,gDAAwB;AACxB,4EAAmD;AAGnD,kHAAsF;AACtF,iFAAwD;AACxD,gFAAuD;AAEvD,SAAgB,mBAAmB,CAAC,WAA4B;IAC9D,MAAM,MAAM,GAAG,IAAA,sBAAW,GAAE,CAAC;IAC7B,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,WAAW,CAAC;IAEjD,IAAI,CAAC,UAAU,EAAE,OAAO,KAAK,KAAK;QAAE,OAAO,MAAM,CAAC;IAElD,MAAM,gBAAgB,GAAG,IAAA,oCAAmB,EAAC,aAAa,CAAC,CAAC;IAC5D,IAAI,EACF,YAAY,GAAG,EAAS,EACxB,WAAW,GAAG,EAAiB,EAC/B,MAAM,EAAE,kBAAkB,GAC3B,GAAQ,EAAE,CAAC;IAEZ,IAAI,gBAAgB;QAClB,CAAC;YACC,YAAY,GAAG,EAAE;YACjB,WAAW,GAAG,EAAE;YAChB,MAAM,EAAE,kBAAkB;SAC3B,GAAG,gBAAgB,CAAC,CAAC;IAExB,MAAM,YAAY,GAAG,kBAAkB,EAAE,MAAM,IAAI,EAAE,CAAC;IACtD,IAAI,YAAY,EAAE,OAAO,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAElD,MAAM,YAAY,GAAG,kBAAkB,EAAE,OAAiB,CAAC;IAC3D,IAAI,YAAY,GAAG,UAAU,EAAE,SAAS,IAAI,eAAe,CAAC;IAE5D,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,YAAY,GAAG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AAE,OAAO,EAAE,CAAC,CACzE,CAAC;IACJ,CAAC;IAED,0BAAe,CAAC,oBAAoB,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { getModuleComponents } from \"../../utils/dynamic-loader\";\nimport fileUploadController from \"./file-upload.controller\";\nimport express from \"express\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthConfigs } from \"../../types/auth\";\nimport { sendResponse } from \"../base/base.middlewares\";\nimport {\n createRouteConfig,\n processMiddleware,\n} from \"../../utils/helpers/routers.helpers\";\nimport { adjustRequestUrl } from \"./utils/helpers/file-upload.helpers\";\nimport { isEndpointDisabled } from \"../base/utils/helpers/base.router.helpers\";\nimport debuggerService from \"../debugger/debugger.service\";\nimport routerValidator from \"../base/utils/router-validator\";\nimport { getUserFileExtension } from \"../../utils/helpers/fs.helpers\";\nimport { ArkosNextFunction, ArkosRequest, ArkosResponse } from \"../../exports\";\nimport path from \"path\";\nimport ArkosRouter from \"../../utils/arkos-router\";\nimport { UserArkosConfig } from \"../../utils/define-config\";\nimport { FileUploadRouterEndpoint } from \"../../types/router-config\";\nimport fileUploadJsonSchemaGenerator from \"./utils/file-upload-json-schema-generator\";\nimport AppError from \"../error-handler/utils/app-error\";\nimport ExitError from \"../../utils/helpers/exit-error\";\n\nexport function getFileUploadRouter(arkosConfig: UserArkosConfig) {\n const router = ArkosRouter();\n const { fileUpload, globalPrefix } = arkosConfig;\n\n if (!fileUpload?.enabled === false) return router;\n\n const moduleComponents = getModuleComponents(\"file-upload\");\n let {\n interceptors = {} as any,\n authConfigs = {} as AuthConfigs,\n router: customRouterModule,\n }: any = {};\n\n if (moduleComponents)\n ({\n interceptors = {},\n authConfigs = {},\n router: customRouterModule,\n } = moduleComponents);\n\n const routerConfig = customRouterModule?.config || {};\n if (routerConfig?.disable === true) return router;\n\n const customRouter = customRouterModule?.default as Router;\n let basePathname = fileUpload?.baseRoute || \"/api/uploads/\";\n\n if (!basePathname.startsWith(\"/\")) basePathname = \"/\" + basePathname;\n if (!basePathname.endsWith(\"/\")) basePathname = basePathname + \"/\";\n\n // Strip leading slash so createRouteConfig can prepend its own \"/\"\n // e.g. \"/api/uploads/\" → \"api/uploads/\" → createRouteConfig builds \"/api/uploads/*\"\n const baseRoutePrefix = basePathname.slice(1);\n\n if (customRouter && customRouterModule) {\n if (routerValidator.isExpressRouter(customRouter))\n router.use({ path: basePathname }, customRouter);\n else\n throw ExitError(\n `ValidationError: The exported router from file-upload.router.${getUserFileExtension()} is not a valid express or arkos Router.`\n );\n }\n\n const endpoints: FileUploadRouterEndpoint[] = [\n \"findFile\",\n \"uploadFile\",\n \"updateFile\",\n \"deleteFile\",\n ];\n\n for (const endpoint of endpoints) {\n const endpointConfig = routerConfig[endpoint];\n if (endpointConfig?.experimental?.openapi === false) continue;\n routerConfig[endpoint] = {\n ...(endpointConfig || {}),\n experimental: {\n ...(endpointConfig?.experimental || {}),\n openapi: fileUploadJsonSchemaGenerator.getOpenApiConfig(\n endpointConfig,\n endpoint\n ),\n },\n };\n }\n\n if (!isEndpointDisabled(routerConfig, \"findFile\")) {\n const baseUploadDirFullPath = path.resolve(\n path\n .join(process.cwd(), fileUpload?.baseUploadDir || \"uploads\")\n .replaceAll(\"//\", \"/\")\n );\n router.get(\n createRouteConfig(\n arkosConfig,\n \"findFile\",\n baseRoutePrefix,\n `*`,\n routerConfig,\n \"file-upload\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeFindFile),\n adjustRequestUrl,\n express.static(\n baseUploadDirFullPath,\n deepmerge(\n {\n maxAge: \"1y\",\n etag: true,\n lastModified: true,\n dotfiles: \"ignore\",\n fallthrough: false,\n index: false,\n cacheControl: true,\n },\n fileUpload?.expressStatic || {}\n )\n ),\n (\n err: any,\n req: ArkosRequest,\n _res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n if (err.code === \"ENOENT\") {\n const filepath = req.path.replace(\n `${globalPrefix}/${arkosConfig.fileUpload?.baseRoute}`.replace(\"//\", \"/\"),\n \"\"\n );\n throw new AppError(\n `File ${filepath} was not found`,\n 404,\n \"FileNotFound\",\n { filepath }\n );\n }\n\n next(err);\n },\n ...processMiddleware(interceptors?.onFindFileError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"uploadFile\")) {\n router.post(\n createRouteConfig(\n arkosConfig,\n \"uploadFile\",\n baseRoutePrefix,\n `:fileType`,\n routerConfig,\n \"file-upload\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeUploadFile),\n fileUploadController.uploadFile,\n ...processMiddleware(interceptors?.afterUploadFile),\n sendResponse,\n ...processMiddleware(interceptors?.onUploadFileError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"updateFile\")) {\n router.patch(\n createRouteConfig(\n arkosConfig,\n \"updateFile\",\n baseRoutePrefix,\n `:fileType/:fileName`,\n routerConfig,\n \"file-upload\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeUpdateFile),\n fileUploadController.updateFile,\n ...processMiddleware(interceptors?.afterUpdateFile),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdateFileError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"deleteFile\")) {\n router.delete(\n createRouteConfig(\n arkosConfig,\n \"deleteFile\",\n baseRoutePrefix,\n `:fileType/:fileName`,\n routerConfig,\n \"file-upload\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeDeleteFile),\n fileUploadController.deleteFile,\n ...processMiddleware(interceptors?.afterDeleteFile),\n sendResponse,\n ...processMiddleware(interceptors?.onDeleteFileError, { type: \"error\" })\n );\n }\n\n debuggerService.logModuleFinalRouter(\"file-upload\", router);\n return router;\n}\n"]}
|
|
@@ -56,7 +56,7 @@ function getSwaggerDefaultConfig(defaultModelsPaths) {
|
|
|
56
56
|
description: "API documentation generated by Arkos.js",
|
|
57
57
|
},
|
|
58
58
|
pageTitle: "Arkos.js API Documentation",
|
|
59
|
-
customCss: `.scalar-client {
|
|
59
|
+
customCss: `.scalar-app-client {
|
|
60
60
|
width: 100vw !important;
|
|
61
61
|
height: 100vh !important;
|
|
62
62
|
max-width: 100vw !important;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-swagger-default-configs.js","sourceRoot":"","sources":["../../../../../../src/modules/swagger/utils/helpers/get-swagger-default-configs.ts"],"names":[],"mappings":";;AAGA,0CAqEC;AAxED,+CAAoD;AACpD,yEAAoE;AAEpE,SAAwB,uBAAuB,CAC7C,kBAAuC;IAEvC,MAAM,WAAW,GAAG;QAClB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM;QACtD,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,MAAO,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,WAAW;KAC7D,CAAC;IACF,MAAM,MAAM,GAAG,IAAA,uBAAc,GAAE,CAAC;IAEhC,OAAO;QACL,QAAQ,EAAE,OAAO;QACjB,IAAI,EAAE,QAAQ;QACd,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,UAAU,EAAE;gBACV,OAAO,EAAE,OAAO;gBAChB,IAAI,EAAE;oBACJ,KAAK,EAAE,qBAAqB;oBAC5B,OAAO,EAAE,OAAO;oBAChB,WAAW,EACT,sFAAsF;iBACzF;gBACD,OAAO,EAAE;oBACP;wBACE,GAAG,EAAE,UAAU,CAAC,SAAS,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,IAAI,WAAW,CAAC,IAAI,EAAE;wBACvI,WAAW,EAAE,SAAS,IAAA,yBAAU,EAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC,SAAS;qBACjF;iBACF;gBACD,KAAK,EAAE,kBAAkB;gBACzB,UAAU,EAAE;oBACV,eAAe,EAAE;wBACf,UAAU,EAAE;4BACV,IAAI,EAAE,MAAM;4BACZ,MAAM,EAAE,QAAQ;4BAChB,YAAY,EAAE,KAAK;yBACpB;qBACF;iBACF;gBACD,QAAQ,EAAE,EAAE;aACb;YACD,IAAI,EAAE,CAAC,2BAA2B,EAAE,0BAA0B,CAAC;YAC/D,WAAW,EAAE,IAAI;YACjB,eAAe,EAAE,IAAI;YACrB,oBAAoB,EAAE,KAAK;SAC5B;QACD,+BAA+B,EAAE;YAC/B,KAAK,EAAE,WAAW;YAClB,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,QAAQ;YAChB,WAAW,EAAE,IAAI;YACjB,kBAAkB,EAAE,KAAK;YACzB,GAAG,EAAE,MAAM,CAAC,YAAY,GAAG,6CAA6C;YACxE,QAAQ,EAAE;gBACR,KAAK,EAAE,4BAA4B;gBACnC,WAAW,EAAE,yCAAyC;aACvD;YACD,SAAS,EAAE,4BAA4B;YACvC,SAAS,EAAE;;;;;;;;;EASf;SACG;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { getArkosConfig } from \"../../../../server\";\nimport { capitalize } from \"../../../../utils/helpers/text.helpers\";\n\nexport default function getSwaggerDefaultConfig(\n defaultModelsPaths: Record<string, any
|
|
1
|
+
{"version":3,"file":"get-swagger-default-configs.js","sourceRoot":"","sources":["../../../../../../src/modules/swagger/utils/helpers/get-swagger-default-configs.ts"],"names":[],"mappings":";;AAGA,0CAqEC;AAxED,+CAAoD;AACpD,yEAAoE;AAEpE,SAAwB,uBAAuB,CAC7C,kBAAuC;IAEvC,MAAM,WAAW,GAAG;QAClB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM;QACtD,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,MAAO,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,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E,4BAA4B;gBACnC,WAAW,EAAE,yCAAyC;aACvD;YACD,SAAS,EAAE,4BAA4B;YACvC,SAAS,EAAE;;;;;;;;;EASf;SACG;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { getArkosConfig } from \"../../../../server\";\nimport { capitalize } from \"../../../../utils/helpers/text.helpers\";\n\nexport default function getSwaggerDefaultConfig(\n defaultModelsPaths: Record<string, any>,\n) {\n const portAndHost = {\n port: process.env.__PORT || process.env.PORT || \"8000\",\n host: process.env.__HOST! || process.env.HOST || \"127.0.0.1\",\n };\n const config = getArkosConfig();\n\n return {\n endpoint: \"/docs\",\n mode: \"prisma\",\n strict: false,\n options: {\n definition: {\n openapi: \"3.1.0\",\n info: {\n title: \"Powered By Arkos.js\",\n version: \"1.0.0\",\n description:\n \"This API was automatically generated by Arkos.js, read more about at www.arkosjs.com\",\n },\n servers: [\n {\n url: `http://${[\"0.0.0.0\", \"localhost\", \"127.0.0.1\"].includes(portAndHost.host!) ? \"localhost\" : portAndHost.host}:${portAndHost.port}`,\n description: `Local ${capitalize(process.env.NODE_ENV || \"development\")} Server`,\n },\n ],\n paths: defaultModelsPaths,\n components: {\n securitySchemes: {\n BearerAuth: {\n type: \"http\",\n scheme: \"bearer\",\n bearerFormat: \"JWT\",\n },\n },\n },\n security: [],\n },\n apis: [\"./src/**/*.router.{ts,js}\", \"./src/**/*.route.{ts,js}\"],\n deepLinking: true,\n tryItOutEnabled: true,\n persistAuthorization: false,\n },\n scalarApiReferenceConfiguration: {\n theme: \"deepSpace\",\n darkMode: true,\n layout: \"modern\",\n showSidebar: true,\n hideDownloadButton: false,\n cdn: config.globalPrefix + \"/scalar-api-reference/browser/standalone.js\",\n metaData: {\n title: \"Arkos.js API Documentation\",\n description: \"API documentation generated by Arkos.js\",\n },\n pageTitle: \"Arkos.js API Documentation\",\n customCss: `.scalar-app-client {\nwidth: 100vw !important;\nheight: 100vh !important;\nmax-width: 100vw !important;\nmax-height: 100vh !important;\ntop: 0 !important;\nleft: 0 !important;\ntransform: none !important;\nborder-radius: 0 !important;\n}`,\n },\n };\n}\n\n"]}
|