arkos 1.4.12-beta → 1.4.13-beta

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.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/types/arkos-config/utils.ts"],"names":[],"mappings":"","sourcesContent":["import { ArkosRequest } from \"..\";\n\n/**\n * Context object passed to `before` auth hooks.\n */\nexport interface AuthBeforeHookContext {\n req: ArkosRequest;\n /**\n * Bypasses core logic and jumps directly to `after` hooks.\n */\n skip: () => void;\n}\n\n/**\n * Context object passed to `after` auth hooks.\n */\nexport interface AuthAfterHookContext {\n req: ArkosRequest;\n}\n\n/**\n * Context object passed to `onError` auth hooks.\n */\nexport interface AuthErrorHookContext {\n req: ArkosRequest;\n error: unknown;\n /**\n * Suppress the error and jump to `after` hooks.\n */\n skip: () => void;\n}\n\nexport type AuthHookHandler = (\n ctx: AuthBeforeHookContext\n) => void | Promise<void>;\nexport type AuthAfterHookHandler = (\n ctx: AuthAfterHookContext\n) => void | Promise<void>;\nexport type AuthErrorHookHandler = (\n ctx: AuthErrorHookContext\n) => void | Promise<void>;\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/types/arkos-config/utils.ts"],"names":[],"mappings":"","sourcesContent":["import { ArkosRequest } from \"..\";\nimport { AccessAction, DetailedAccessControlRule } from \"../auth\";\n\n/** Context passed to `before` hooks of `authenticate`. */\nexport interface AuthenticateBeforeHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n /** Bypasses core logic and jumps directly to `after` hooks. */\n skip: () => void;\n}\n\n/** Context passed to `after` hooks of `authenticate`. */\nexport interface AuthenticateAfterHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n}\n\n/** Context passed to `onError` hooks of `authenticate`. */\nexport interface AuthenticateErrorHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n /** The error thrown during authentication. */\n error: unknown;\n /** Suppresses the error and jumps to `after` hooks. */\n skip: () => void;\n}\n\nexport type AuthenticateHookHandler = (\n ctx: AuthenticateBeforeHookContext\n) => void | Promise<void>;\n\nexport type AuthenticateAfterHookHandler = (\n ctx: AuthenticateAfterHookContext\n) => void | Promise<void>;\n\nexport type AuthenticateErrorHookHandler = (\n ctx: AuthenticateErrorHookContext\n) => void | Promise<void>;\n\n/** Context passed to `before` hooks of `authorize`. */\nexport interface AuthorizeBeforeHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n /** The action being authorized (e.g. `\"Create\"`, `\"Delete\"`). */\n action: AccessAction;\n /** The resource being accessed in kebab-case (e.g. `\"post\"`, `\"cart-item\"`). */\n resource: string;\n /** The access control rule for this action. */\n rule?: string[] | DetailedAccessControlRule | \"*\";\n /** Bypasses core logic and jumps directly to `after` hooks. */\n skip: () => void;\n}\n\n/** Context passed to `after` hooks of `authorize`. */\nexport interface AuthorizeAfterHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n /** The action that was authorized (e.g. `\"Create\"`, `\"Delete\"`). */\n action: AccessAction;\n /** The resource that was accessed in kebab-case (e.g. `\"post\"`, `\"cart-item\"`). */\n resource: string;\n /** The access control rule that was applied. */\n rule?: string[] | DetailedAccessControlRule | \"*\";\n}\n\n/** Context passed to `onError` hooks of `authorize`. */\nexport interface AuthorizeErrorHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n /** The error thrown during authorization. */\n error: unknown;\n /** The action being authorized (e.g. `\"Create\"`, `\"Delete\"`). */\n action: AccessAction;\n /** The resource being accessed in kebab-case (e.g. `\"post\"`, `\"cart-item\"`). */\n resource: string;\n /** The access control rule for this action. */\n rule?: string[] | DetailedAccessControlRule | \"*\";\n /** Suppresses the error and jumps to `after` hooks. */\n skip: () => void;\n}\n\nexport type AuthorizeHookHandler = (\n ctx: AuthorizeBeforeHookContext\n) => void | Promise<void>;\n\nexport type AuthorizeAfterHookHandler = (\n ctx: AuthorizeAfterHookContext\n) => void | Promise<void>;\n\nexport type AuthorizeErrorHookHandler = (\n ctx: AuthorizeErrorHookContext\n) => void | Promise<void>;\n"]}
@@ -137,7 +137,7 @@ For further help see https://www.arkosjs.com/docs/core-concepts/authentication/s
137
137
  if (config.authentication && !authenticationConfig?.mode)
138
138
  throw Error(`Trying to authenticate route ${route} without choosing an authentication mode under arkos.config.${(0, fs_helpers_1.getUserFileExtension)()}
139
139
 
140
- For further help see https://www.arkosjs.com/docs/core-concepts/authentication-system.`);
140
+ For further help see https://www.arkosjs.com/docs/core-concepts/authentication/setup.`);
141
141
  handlers = [...(0, _1.getMiddlewareStack)(config), ...handlers];
142
142
  if (config.experimental?.uploads &&
143
143
  config.experimental.uploads.deleteOnError !== false)
@@ -1 +1 @@
1
- {"version":3,"file":"apply-arkos-router-proxy.js","sourceRoot":"","sources":["../../../../../../src/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.ts"],"names":[],"mappings":";;;;;AAkBA,sDAwNC;AAlOD,0FAAgE;AAChE,wBAAoD;AACpD,4DAAmE;AACnE,+CAAoD;AACpD,wFAA8D;AAC9D,qEAA+D;AAC/D,yFAA0D;AAC1D,6EAAoD;AACpD,sEAA6C;AAE7C,SAAgB,qBAAqB,CACnC,MAAS,EACT,OAGC,EACD,OAAgC,eAAe;IAE/C,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE;QACvB,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YACxB,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAa,CAAC;YAEvE,MAAM,WAAW,GAAG;gBAClB,KAAK;gBACL,MAAM;gBACN,KAAK;gBACL,OAAO;gBACP,QAAQ;gBACR,KAAK;gBACL,MAAM;gBACN,OAAO;gBACP,SAAS;aACD,CAAC;YAEX,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;gBACnB,OAAO,UACL,MAA4D,EAC5D,GAAG,QAAkC;oBAGrC,IACE,CAAC,MAAM;wBACP,OAAO,MAAM,KAAK,QAAQ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CAAC;oBAExD,IACE,MAAM,CAAC,YAAY,EAAE,OAAO;wBAC5B,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,aAAa,KAAK,KAAK;wBAEnD,QAAQ,CAAC,IAAI,CACX,IAAA,0BAAU,EACR,wBAAa,CAAC,iBAAiB,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,EAC5D,EAAE,IAAI,EAAE,OAAO,EAAE,CAClB,CACF,CAAC;oBAEJ,OAAO,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAC;gBACxD,CAAC,CAAC;YACJ,CAAC;YAED,OAAO,cAAc,CAAC;QACxB,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { RouterOptions } from \"express\";\nimport {\n ArkosAnyRequestHandler,\n ArkosRouteConfig,\n ArkosUseConfig,\n IArkosRoute,\n PathParams,\n} from \"../../types\";\nimport RouteConfigValidator from \"../../route-config-validator\";\nimport { applyPrefix, getMiddlewareStack } from \".\";\nimport { getUserFileExtension } from \"../../../helpers/fs.helpers\";\nimport { getArkosConfig } from \"../../../../server\";\nimport RouteConfigRegistry from \"../../route-config-registry\";\nimport { catchAsync } from \"../../../../exports/error-handler\";\nimport deepmerge from \"../../../helpers/deepmerge.helper\";\nimport ExitError from \"../../../helpers/exit-error\";\nimport uploadManager from \"./upload-manager\";\n\nexport function applyArkosRouterProxy<T extends object>(\n target: T,\n options?: RouterOptions & {\n prefix?: string | RegExp | Array<string | RegExp>;\n openapi?: { tags?: string[] };\n },\n name: \"app\" | \"ArkosRouter()\" = \"ArkosRouter()\"\n): T {\n return new Proxy(target, {\n get(target, prop, receiver) {\n const originalMethod = Reflect.get(target, prop, receiver) as Function;\n\n const httpMethods = [\n \"get\",\n \"post\",\n \"put\",\n \"patch\",\n \"delete\",\n \"all\",\n \"head\",\n \"trace\",\n \"options\",\n ] as const;\n\n if (prop === \"use\") {\n return function (\n config: ArkosUseConfig | PathParams | ArkosAnyRequestHandler,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n // if not an ArkosUseConfig object, fall through to native Express use\n if (\n !config ||\n typeof config !== \"object\" ||\n Array.isArray(config) ||\n typeof config === \"function\"\n )\n return originalMethod.call(target, config, ...handlers);\n\n if ((config as ArkosUseConfig).disabled) return;\n\n const useConfig = config as ArkosUseConfig;\n const path = useConfig.path\n ? applyPrefix(options?.prefix, useConfig.path)\n : undefined;\n\n const arkosConfig = getArkosConfig();\n const authenticationConfig = arkosConfig.authentication;\n\n if (useConfig.authentication && !authenticationConfig?.mode)\n throw ExitError(\n `Trying to authenticate route use${path ? ` ${path}` : \"\"} 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 const middlewareStack = getMiddlewareStack(useConfig);\n\n const allHandlers = [...middlewareStack, ...handlers];\n\n return path\n ? originalMethod.call(target, path, ...allHandlers)\n : originalMethod.call(target, ...allHandlers);\n };\n }\n\n if (prop === \"route\") {\n return function (path: PathParams) {\n const routeChain: any = {};\n\n httpMethods.forEach((method) => {\n routeChain[method] = function (\n config: ArkosAnyRequestHandler | Omit<ArkosRouteConfig, \"path\">,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n const fullConfig: ArkosRouteConfig = {\n ...config,\n ...(options?.openapi\n ? {\n experimental: {\n openapi: options.openapi,\n },\n }\n : {}),\n path,\n };\n\n receiver[method](fullConfig, ...handlers);\n\n return routeChain as IArkosRoute;\n };\n });\n\n return routeChain;\n };\n }\n\n if (httpMethods.includes(prop as any)) {\n return function (\n config: ArkosRouteConfig,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n if (config.disabled) return;\n\n if (!RouteConfigValidator.isArkosRouteConfig(config))\n throw Error(\n `First argument of ${name}.${prop as string}() must be a valid ArkosRouteConfig object with path field, but recevied ${typeof config === \"object\" ? JSON.stringify(config, null, 2) : config}`\n );\n\n const path = applyPrefix(options?.prefix, config.path);\n\n config = {\n ...config,\n ...(options?.openapi\n ? {\n experimental: {\n ...config?.experimental,\n openapi: deepmerge(\n options.openapi || {},\n config?.experimental?.openapi || {}\n ),\n },\n }\n : {}),\n path,\n };\n\n if ([null, undefined].includes(path as any))\n throw Error(\n \"Please pass valid value for path field to use in your route\"\n );\n\n const method = prop as string;\n const UndefinedHandlerError = (handler: any) =>\n Error(\n `Wrong value for handler in route ${method.toUpperCase()} ${path}, recevied ${handler}.`\n );\n\n if (handlers.length > 0) {\n const flattenHandlers = (arr: any[]): ArkosAnyRequestHandler[] => {\n return arr.reduce((flat, item) => {\n return flat.concat(\n Array.isArray(item) ? flattenHandlers(item) : item\n );\n }, []);\n };\n\n const flatHandlers = flattenHandlers(handlers);\n\n handlers = flatHandlers.map((handler: ArkosAnyRequestHandler) => {\n if (!handler) throw UndefinedHandlerError(handler);\n\n if (typeof handler !== \"function\") {\n throw UndefinedHandlerError(handler);\n }\n\n return catchAsync(handler, {\n type: handler.length > 3 ? \"error\" : \"normal\",\n });\n });\n\n const finalHandler = handlers[handlers.length - 1];\n RouteConfigRegistry.register(finalHandler, config, method);\n }\n\n const arkosConfig = getArkosConfig();\n const validationConfig = arkosConfig.validation;\n const authenticationConfig = arkosConfig.authentication;\n const strictValidation = validationConfig?.strict;\n const route = `${method.toUpperCase()} ${path}`;\n\n if (\n strictValidation &&\n (!(\"validation\" in config) ||\n (\"validation\" in config &&\n !config.validation &&\n config.validation !== undefined))\n )\n throw Error(\n \"When using strict validation you must either pass { validation: false } in order to explicitly tell that no input will be received, or pass `undefined` for each input type e.g { validation: { query: undefined } } in order to deny the input of given request input.\"\n );\n\n if (\n !validationConfig?.resolver &&\n Object.keys(config.validation || {}).length > 0\n )\n throw Error(\n `Trying to pass validators into route ${route} config validation option without choosing a validation resolver under arkos.init({ validation: { resolver: '' } })`\n );\n\n if (config.authentication && !authenticationConfig?.mode)\n throw Error(\n `Trying to authenticate route ${route} without choosing an authentication mode under arkos.config.${getUserFileExtension()}\n\nFor further help see https://www.arkosjs.com/docs/core-concepts/authentication-system.`\n );\n\n handlers = [...getMiddlewareStack(config), ...handlers];\n\n if (\n config.experimental?.uploads &&\n config.experimental.uploads.deleteOnError !== false\n )\n handlers.push(\n catchAsync(\n uploadManager.handleFileCleanup(config.experimental.uploads),\n { type: \"error\" }\n )\n );\n\n return originalMethod.call(target, path, ...handlers);\n };\n }\n // }\n return originalMethod;\n },\n });\n}\n"]}
1
+ {"version":3,"file":"apply-arkos-router-proxy.js","sourceRoot":"","sources":["../../../../../../src/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.ts"],"names":[],"mappings":";;;;;AAkBA,sDAwNC;AAlOD,0FAAgE;AAChE,wBAAoD;AACpD,4DAAmE;AACnE,+CAAoD;AACpD,wFAA8D;AAC9D,qEAA+D;AAC/D,yFAA0D;AAC1D,6EAAoD;AACpD,sEAA6C;AAE7C,SAAgB,qBAAqB,CACnC,MAAS,EACT,OAGC,EACD,OAAgC,eAAe;IAE/C,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE;QACvB,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YACxB,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAa,CAAC;YAEvE,MAAM,WAAW,GAAG;gBAClB,KAAK;gBACL,MAAM;gBACN,KAAK;gBACL,OAAO;gBACP,QAAQ;gBACR,KAAK;gBACL,MAAM;gBACN,OAAO;gBACP,SAAS;aACD,CAAC;YAEX,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;gBACnB,OAAO,UACL,MAA4D,EAC5D,GAAG,QAAkC;oBAGrC,IACE,CAAC,MAAM;wBACP,OAAO,MAAM,KAAK,QAAQ;wBAC1B,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;wBACrB,OAAO,MAAM,KAAK,UAAU;wBAE5B,OAAO,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC,C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BAAa,CAAC,iBAAiB,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,EAC5D,EAAE,IAAI,EAAE,OAAO,EAAE,CAClB,CACF,CAAC;oBAEJ,OAAO,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAC;gBACxD,CAAC,CAAC;YACJ,CAAC;YAED,OAAO,cAAc,CAAC;QACxB,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { RouterOptions } from \"express\";\nimport {\n ArkosAnyRequestHandler,\n ArkosRouteConfig,\n ArkosUseConfig,\n IArkosRoute,\n PathParams,\n} from \"../../types\";\nimport RouteConfigValidator from \"../../route-config-validator\";\nimport { applyPrefix, getMiddlewareStack } from \".\";\nimport { getUserFileExtension } from \"../../../helpers/fs.helpers\";\nimport { getArkosConfig } from \"../../../../server\";\nimport RouteConfigRegistry from \"../../route-config-registry\";\nimport { catchAsync } from \"../../../../exports/error-handler\";\nimport deepmerge from \"../../../helpers/deepmerge.helper\";\nimport ExitError from \"../../../helpers/exit-error\";\nimport uploadManager from \"./upload-manager\";\n\nexport function applyArkosRouterProxy<T extends object>(\n target: T,\n options?: RouterOptions & {\n prefix?: string | RegExp | Array<string | RegExp>;\n openapi?: { tags?: string[] };\n },\n name: \"app\" | \"ArkosRouter()\" = \"ArkosRouter()\"\n): T {\n return new Proxy(target, {\n get(target, prop, receiver) {\n const originalMethod = Reflect.get(target, prop, receiver) as Function;\n\n const httpMethods = [\n \"get\",\n \"post\",\n \"put\",\n \"patch\",\n \"delete\",\n \"all\",\n \"head\",\n \"trace\",\n \"options\",\n ] as const;\n\n if (prop === \"use\") {\n return function (\n config: ArkosUseConfig | PathParams | ArkosAnyRequestHandler,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n // if not an ArkosUseConfig object, fall through to native Express use\n if (\n !config ||\n typeof config !== \"object\" ||\n Array.isArray(config) ||\n typeof config === \"function\"\n )\n return originalMethod.call(target, config, ...handlers);\n\n if ((config as ArkosUseConfig).disabled) return;\n\n const useConfig = config as ArkosUseConfig;\n const path = useConfig.path\n ? applyPrefix(options?.prefix, useConfig.path)\n : undefined;\n\n const arkosConfig = getArkosConfig();\n const authenticationConfig = arkosConfig.authentication;\n\n if (useConfig.authentication && !authenticationConfig?.mode)\n throw ExitError(\n `Trying to authenticate route use${path ? ` ${path}` : \"\"} 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 const middlewareStack = getMiddlewareStack(useConfig);\n\n const allHandlers = [...middlewareStack, ...handlers];\n\n return path\n ? originalMethod.call(target, path, ...allHandlers)\n : originalMethod.call(target, ...allHandlers);\n };\n }\n\n if (prop === \"route\") {\n return function (path: PathParams) {\n const routeChain: any = {};\n\n httpMethods.forEach((method) => {\n routeChain[method] = function (\n config: ArkosAnyRequestHandler | Omit<ArkosRouteConfig, \"path\">,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n const fullConfig: ArkosRouteConfig = {\n ...config,\n ...(options?.openapi\n ? {\n experimental: {\n openapi: options.openapi,\n },\n }\n : {}),\n path,\n };\n\n receiver[method](fullConfig, ...handlers);\n\n return routeChain as IArkosRoute;\n };\n });\n\n return routeChain;\n };\n }\n\n if (httpMethods.includes(prop as any)) {\n return function (\n config: ArkosRouteConfig,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n if (config.disabled) return;\n\n if (!RouteConfigValidator.isArkosRouteConfig(config))\n throw Error(\n `First argument of ${name}.${prop as string}() must be a valid ArkosRouteConfig object with path field, but recevied ${typeof config === \"object\" ? JSON.stringify(config, null, 2) : config}`\n );\n\n const path = applyPrefix(options?.prefix, config.path);\n\n config = {\n ...config,\n ...(options?.openapi\n ? {\n experimental: {\n ...config?.experimental,\n openapi: deepmerge(\n options.openapi || {},\n config?.experimental?.openapi || {}\n ),\n },\n }\n : {}),\n path,\n };\n\n if ([null, undefined].includes(path as any))\n throw Error(\n \"Please pass valid value for path field to use in your route\"\n );\n\n const method = prop as string;\n const UndefinedHandlerError = (handler: any) =>\n Error(\n `Wrong value for handler in route ${method.toUpperCase()} ${path}, recevied ${handler}.`\n );\n\n if (handlers.length > 0) {\n const flattenHandlers = (arr: any[]): ArkosAnyRequestHandler[] => {\n return arr.reduce((flat, item) => {\n return flat.concat(\n Array.isArray(item) ? flattenHandlers(item) : item\n );\n }, []);\n };\n\n const flatHandlers = flattenHandlers(handlers);\n\n handlers = flatHandlers.map((handler: ArkosAnyRequestHandler) => {\n if (!handler) throw UndefinedHandlerError(handler);\n\n if (typeof handler !== \"function\") {\n throw UndefinedHandlerError(handler);\n }\n\n return catchAsync(handler, {\n type: handler.length > 3 ? \"error\" : \"normal\",\n });\n });\n\n const finalHandler = handlers[handlers.length - 1];\n RouteConfigRegistry.register(finalHandler, config, method);\n }\n\n const arkosConfig = getArkosConfig();\n const validationConfig = arkosConfig.validation;\n const authenticationConfig = arkosConfig.authentication;\n const strictValidation = validationConfig?.strict;\n const route = `${method.toUpperCase()} ${path}`;\n\n if (\n strictValidation &&\n (!(\"validation\" in config) ||\n (\"validation\" in config &&\n !config.validation &&\n config.validation !== undefined))\n )\n throw Error(\n \"When using strict validation you must either pass { validation: false } in order to explicitly tell that no input will be received, or pass `undefined` for each input type e.g { validation: { query: undefined } } in order to deny the input of given request input.\"\n );\n\n if (\n !validationConfig?.resolver &&\n Object.keys(config.validation || {}).length > 0\n )\n throw Error(\n `Trying to pass validators into route ${route} config validation option without choosing a validation resolver under arkos.init({ validation: { resolver: '' } })`\n );\n\n if (config.authentication && !authenticationConfig?.mode)\n throw Error(\n `Trying to authenticate route ${route} 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 handlers = [...getMiddlewareStack(config), ...handlers];\n\n if (\n config.experimental?.uploads &&\n config.experimental.uploads.deleteOnError !== false\n )\n handlers.push(\n catchAsync(\n uploadManager.handleFileCleanup(config.experimental.uploads),\n { type: \"error\" }\n )\n );\n\n return originalMethod.call(target, path, ...handlers);\n };\n }\n // }\n return originalMethod;\n },\n });\n}\n"]}
@@ -19,6 +19,6 @@ function killServerChildProcess() {
19
19
  (0, start_1.killProductionServerChildProcess)();
20
20
  }
21
21
  function getVersion() {
22
- return "1.4.12-beta";
22
+ return "1.4.13-beta";
23
23
  }
24
24
  //# sourceMappingURL=cli.helpers.js.map
@@ -8,7 +8,6 @@ exports.loadPrismaModule = loadPrismaModule;
8
8
  exports.handlePrismaGet = handlePrismaGet;
9
9
  exports.getPrismaInstance = getPrismaInstance;
10
10
  const fs_1 = __importDefault(require("fs"));
11
- const app_error_1 = __importDefault(require("../../modules/error-handler/utils/app-error.js"));
12
11
  const fs_helpers_1 = require("./fs.helpers.js");
13
12
  const global_helpers_1 = require("./global.helpers.js");
14
13
  const prisma_schema_parser_1 = __importDefault(require("../prisma/prisma-schema-parser.js"));
@@ -32,7 +31,7 @@ async function loadPrismaModule() {
32
31
  }
33
32
  catch (error) {
34
33
  if (error.message === "Prisma not found")
35
- throw new app_error_1.default(`Could not initialize Prisma module. Make sure your prisma instance is exported as default under src/utils/prisma/index.${(0, fs_helpers_1.getUserFileExtension)()}, read more about Arkos.js Project Structure under https://www.arkosjs.com/docs/getting-started/project-structure#utilities-directory`, 500, {}, "PrismaInstanceNotFound");
34
+ return sheu_1.default.warn(`Could not find your prisma instance under src/utils/prisma/index.${(0, fs_helpers_1.getUserFileExtension)()}, see https://www.arkosjs.com/docs/core-concepts/prisma-orm/setup`, { timestamp: true });
36
35
  throw error;
37
36
  }
38
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"prisma.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/prisma.helpers.ts"],"names":[],"mappings":";;;;;;AAUA,4CA6BC;AAED,0CA4CC;AAED,8CAMC;AA7FD,4CAAoB;AACpB,4FAAmE;AACnE,6CAAgE;AAChE,qDAAgD;AAChD,0FAAgE;AAChE,iEAAw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AC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,SAAgB,iBAAiB;IAC/B,IAAI,CAAC,sBAAc;QAAE,OAAO,IAAI,CAAC;IAEjC,OAAO,IAAI,KAAK,CAAC,sBAAc,EAAE;QAC/B,GAAG,EAAE,eAAe;KACrB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import fs from \"fs\";\nimport AppError from \"../../modules/error-handler/utils/app-error\";\nimport { crd, getUserFileExtension as ext } from \"./fs.helpers\";\nimport { importModule } from \"./global.helpers\";\nimport prismaSchemaParser from \"../prisma/prisma-schema-parser\";\nimport { getArkosConfig } from \"./arkos-config.helpers\";\nimport sheu from \"../sheu\";\n\nexport let prismaInstance: any = null;\n\nexport async function loadPrismaModule() {\n if (!prismaInstance) {\n try {\n let prismaPath = `${crd()}/src/utils/prisma.${ext()}`;\n\n if (!fs.existsSync(prismaPath))\n prismaPath = `${crd()}/src/utils/prisma/index.${ext()}`;\n\n if (!fs.existsSync(prismaPath)) throw new Error(`Prisma not found`);\n\n const prismaModule = await importModule(prismaPath, {\n fixExtension: false,\n });\n prismaInstance = prismaModule.default;\n\n if (!prismaInstance || typeof prismaInstance?.[\"$connect\"] !== \"function\")\n throw new Error(\"Prisma not found\");\n } catch (error: any) {\n if (error.message === \"Prisma not found\")\n throw new AppError(\n `Could not initialize Prisma module. Make sure your prisma instance is exported as default under src/utils/prisma/index.${ext()}, read more about Arkos.js Project Structure under https://www.arkosjs.com/docs/getting-started/project-structure#utilities-directory`,\n 500,\n {},\n \"PrismaInstanceNotFound\"\n );\n throw error;\n }\n }\n return prismaInstance;\n}\n\nexport function handlePrismaGet(target: any, prop: string, receiver: any) {\n const originalProperty = Reflect.get(target, prop, receiver);\n\n const isModel = prismaSchemaParser\n .getModelsAsArrayOfStrings()\n .find((m) => m.toLowerCase() === (prop as string)?.toLowerCase?.());\n\n if (isModel && originalProperty) {\n return new Proxy(originalProperty, {\n get(modelTarget, methodName, modelReceiver) {\n const originalMethod = Reflect.get(\n modelTarget,\n methodName,\n modelReceiver\n );\n\n if (typeof originalMethod === \"function\") {\n return function (...args: any[]) {\n const config = getArkosConfig();\n const debugLevel = config.debugging?.requests?.level || 0;\n\n if (debugLevel >= 3) {\n const queryArgs = args[0];\n\n if (queryArgs && Object.keys(queryArgs).length > 0) {\n sheu.debug(\n `Final Prisma Args\\n${JSON.stringify(queryArgs, null, 2)}`,\n { timestamp: true }\n );\n } else {\n sheu.debug(`Final Prisma Args - Empty`, { timestamp: true });\n }\n }\n\n return originalMethod.apply(modelTarget, args);\n };\n }\n\n return originalMethod;\n },\n });\n }\n\n return originalProperty;\n}\n\nexport function getPrismaInstance() {\n if (!prismaInstance) return null;\n\n return new Proxy(prismaInstance, {\n get: handlePrismaGet,\n });\n}\n"]}
1
+ {"version":3,"file":"prisma.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/prisma.helpers.ts"],"names":[],"mappings":";;;;;;AASA,4CA2BC;AAED,0CA4CC;AAED,8CAMC;AA1FD,4CAAoB;AACpB,6CAAgE;AAChE,qDAAgD;AAChD,0FAAgE;AAChE,iEAAwD;AACxD,mDAA2B;AAEhB,QAAA,cAAc,GAAQ,IAAI,CAAC;AAE/B,KAAK,UAAU,gBAAgB;IACpC,IAAI,CAAC,sBAAc,EAAE,CAAC;QACpB,IAAI,CAAC;YACH,IAAI,UAAU,GAAG,GAAG,IAAA,gBAAG,GAAE,qBAAqB,IAAA,iCAAG,GAAE,EAAE,CAAC;YAEtD,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC;gBAC5B,UAAU,GAAG,GAAG,IAAA,gBAAG,GAAE,2BAA2B,IAAA,iCAAG,GAAE,EAAE,CAAC;YAE1D,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;YAEpE,MAAM,YAAY,GAAG,MAAM,IAAA,6BAAY,EAAC,UAAU,EAAE;gBAClD,YAAY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AQ,EAAE,KAAK,IAAI,CAAC,CAAC;wBAE1D,IAAI,UAAU,IAAI,CAAC,EAAE,CAAC;4BACpB,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;4BAE1B,IAAI,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gCACnD,cAAI,CAAC,KAAK,CACR,sBAAsB,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAC1D,EAAE,SAAS,EAAE,IAAI,EAAE,CACpB,CAAC;4BACJ,CAAC;iCAAM,CAAC;gCACN,cAAI,CAAC,KAAK,CAAC,2BAA2B,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;4BAC/D,CAAC;wBACH,CAAC;wBAED,OAAO,cAAc,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;oBACjD,CAAC,CAAC;gBACJ,CAAC;gBAED,OAAO,cAAc,CAAC;YACxB,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,SAAgB,iBAAiB;IAC/B,IAAI,CAAC,sBAAc;QAAE,OAAO,IAAI,CAAC;IAEjC,OAAO,IAAI,KAAK,CAAC,sBAAc,EAAE;QAC/B,GAAG,EAAE,eAAe;KACrB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import fs from \"fs\";\nimport { crd, getUserFileExtension as ext } from \"./fs.helpers\";\nimport { importModule } from \"./global.helpers\";\nimport prismaSchemaParser from \"../prisma/prisma-schema-parser\";\nimport { getArkosConfig } from \"./arkos-config.helpers\";\nimport sheu from \"../sheu\";\n\nexport let prismaInstance: any = null;\n\nexport async function loadPrismaModule() {\n if (!prismaInstance) {\n try {\n let prismaPath = `${crd()}/src/utils/prisma.${ext()}`;\n\n if (!fs.existsSync(prismaPath))\n prismaPath = `${crd()}/src/utils/prisma/index.${ext()}`;\n\n if (!fs.existsSync(prismaPath)) throw new Error(`Prisma not found`);\n\n const prismaModule = await importModule(prismaPath, {\n fixExtension: false,\n });\n prismaInstance = prismaModule.default;\n\n if (!prismaInstance || typeof prismaInstance?.[\"$connect\"] !== \"function\")\n throw new Error(\"Prisma not found\");\n } catch (error: any) {\n if (error.message === \"Prisma not found\")\n return sheu.warn(\n `Could not find your prisma instance under src/utils/prisma/index.${ext()}, see https://www.arkosjs.com/docs/core-concepts/prisma-orm/setup`,\n { timestamp: true }\n );\n throw error;\n }\n }\n return prismaInstance;\n}\n\nexport function handlePrismaGet(target: any, prop: string, receiver: any) {\n const originalProperty = Reflect.get(target, prop, receiver);\n\n const isModel = prismaSchemaParser\n .getModelsAsArrayOfStrings()\n .find((m) => m.toLowerCase() === (prop as string)?.toLowerCase?.());\n\n if (isModel && originalProperty) {\n return new Proxy(originalProperty, {\n get(modelTarget, methodName, modelReceiver) {\n const originalMethod = Reflect.get(\n modelTarget,\n methodName,\n modelReceiver\n );\n\n if (typeof originalMethod === \"function\") {\n return function (...args: any[]) {\n const config = getArkosConfig();\n const debugLevel = config.debugging?.requests?.level || 0;\n\n if (debugLevel >= 3) {\n const queryArgs = args[0];\n\n if (queryArgs && Object.keys(queryArgs).length > 0) {\n sheu.debug(\n `Final Prisma Args\\n${JSON.stringify(queryArgs, null, 2)}`,\n { timestamp: true }\n );\n } else {\n sheu.debug(`Final Prisma Args - Empty`, { timestamp: true });\n }\n }\n\n return originalMethod.apply(modelTarget, args);\n };\n }\n\n return originalMethod;\n },\n });\n }\n\n return originalProperty;\n}\n\nexport function getPrismaInstance() {\n if (!prismaInstance) return null;\n\n return new Proxy(prismaInstance, {\n get: handlePrismaGet,\n });\n}\n"]}
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.default = initializeApp;
7
+ exports.addGlobalErrorHandler = addGlobalErrorHandler;
7
8
  const file_upload_router_1 = require("../modules/file-upload/file-upload.router.js");
8
9
  const auth_router_1 = require("../modules/auth/auth.router.js");
9
10
  const base_router_1 = require("../modules/base/base.router.js");
@@ -16,7 +17,6 @@ function initializeApp(app) {
16
17
  const config = (0, server_1.getArkosConfig)();
17
18
  const globalPrefix = config.globalPrefix || "/api";
18
19
  const routersConfig = config?.routers;
19
- const middlewaresConfig = config?.middlewares;
20
20
  if (routersConfig?.welcomeRoute !== false) {
21
21
  if (typeof routersConfig?.welcomeRoute === "function") {
22
22
  app.get({ path: globalPrefix }, routersConfig.welcomeRoute);
@@ -40,17 +40,13 @@ function initializeApp(app) {
40
40
  (process.env.ARKOS_BUILD !== "true" ||
41
41
  config.swagger.enableAfterBuild === true))
42
42
  app.use(globalPrefix, (0, swagger_router_1.getSwaggerRouter)(config, app));
43
+ return app;
44
+ }
45
+ function addGlobalErrorHandler(app) {
43
46
  app.use("*", (req) => {
44
47
  throw new error_handler_1.AppError(`Route ${req.method} ${req.originalUrl} was not found`, 404, { route: `${req.method} ${req.originalUrl}` }, "RouteNotFound");
45
48
  });
46
- if (middlewaresConfig?.errorHandler !== false) {
47
- if (typeof middlewaresConfig?.errorHandler === "function") {
48
- app.use(middlewaresConfig.errorHandler);
49
- }
50
- else {
51
- app.use(error_handler_controller_1.default);
52
- }
53
- }
49
+ app.use(error_handler_controller_1.default);
54
50
  return app;
55
51
  }
56
52
  //# sourceMappingURL=initialize-app.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"initialize-app.js","sourceRoot":"","sources":["../../../src/utils/initialize-app.ts"],"names":[],"mappings":";;;;;AAaA,gCAsDC;AAlED,kFAAgF;AAChF,6DAA4D;AAC5D,6DAGqC;AACrC,4DAAoD;AACpD,iHAA6E;AAC7E,sCAA2C;AAC3C,yEAAyE;AACzE,sEAAqE;AAErE,SAAwB,aAAa,CAAC,GAAU;IAC9C,MAAM,MAAM,GAAG,IAAA,uBAAc,GAAE,CAAC;IAChC,MAAM,YAAY,GAAG,MA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O,CAAC,gBAAgB,KAAK,IAAI,CAAC;QAE3C,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,IAAA,iCAAgB,EAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IAEvD,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE;QACnB,MAAM,IAAI,wBAAQ,CAChB,SAAS,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,WAAW,gBAAgB,EACtD,GAAG,EACH,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,WAAW,EAAE,EAAE,EAC7C,eAAe,CAChB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,IAAI,iBAAiB,EAAE,YAAY,KAAK,KAAK,EAAE,CAAC;QAC9C,IAAI,OAAO,iBAAiB,EAAE,YAAY,KAAK,UAAU,EAAE,CAAC;YAC1D,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,kCAAY,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { Arkos } from \"../types/arkos\";\nimport { getFileUploadRouter } from \"../modules/file-upload/file-upload.router\";\nimport { getAuthRouter } from \"../modules/auth/auth.router\";\nimport {\n getAvailableResourcesAndRoutesRouter,\n getPrismaModelsRouter,\n} from \"../modules/base/base.router\";\nimport { AppError } from \"../exports/error-handler\";\nimport errorHandler from \"../modules/error-handler/error-handler.controller\";\nimport { getArkosConfig } from \"../server\";\nimport { isAuthenticationEnabled } from \"./helpers/arkos-config.helpers\";\nimport { getSwaggerRouter } from \"../modules/swagger/swagger.router\";\n\nexport default function initializeApp(app: Arkos) {\n const config = getArkosConfig();\n const globalPrefix = config.globalPrefix || \"/api\";\n\n const routersConfig = config?.routers;\n const middlewaresConfig = config?.middlewares;\n\n if (routersConfig?.welcomeRoute !== false) {\n if (typeof routersConfig?.welcomeRoute === \"function\") {\n app.get({ path: globalPrefix }, routersConfig.welcomeRoute);\n } else {\n app.get({ path: globalPrefix }, (_, res) => {\n res.status(200).json({ message: config.welcomeMessage });\n });\n }\n }\n\n const fileUploadRouter = getFileUploadRouter(config);\n app.use(fileUploadRouter);\n\n if (isAuthenticationEnabled()) {\n const authRouter = getAuthRouter(config);\n app.use(globalPrefix, authRouter);\n }\n\n const modelsRouter = getPrismaModelsRouter(config);\n app.use(globalPrefix, modelsRouter);\n\n app.use(globalPrefix, getAvailableResourcesAndRoutesRouter());\n\n if (\n config.swagger &&\n (process.env.ARKOS_BUILD !== \"true\" ||\n config.swagger.enableAfterBuild === true)\n )\n app.use(globalPrefix, getSwaggerRouter(config, app));\n\n app.use(\"*\", (req) => {\n throw new AppError(\n `Route ${req.method} ${req.originalUrl} was not found`,\n 404,\n { route: `${req.method} ${req.originalUrl}` },\n \"RouteNotFound\"\n );\n });\n\n if (middlewaresConfig?.errorHandler !== false) {\n if (typeof middlewaresConfig?.errorHandler === \"function\") {\n app.use(middlewaresConfig.errorHandler);\n } else {\n app.use(errorHandler);\n }\n }\n return app;\n}\n"]}
1
+ {"version":3,"file":"initialize-app.js","sourceRoot":"","sources":["../../../src/utils/initialize-app.ts"],"names":[],"mappings":";;;;;AAaA,gCAqCC;AAED,sDAaC;AAhED,kFAAgF;AAChF,6DAA4D;AAC5D,6DAGqC;AACrC,4DAAoD;AACpD,iHAA6E;AAC7E,sCAA2C;AAC3C,yEAAyE;AACzE,sEAAqE;AAErE,SAAwB,aAAa,CAAC,GAAU;IAC9C,MAAM,MAAM,GAAG,IAAA,uBAAc,GAAE,CAAC;IAChC,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC;IAEnD,MAAM,aAAa,GAAG,MAAM,EAAE,OAAO,CAAC;IAEtC,IAAI,aAAa,EAAE,YAAY,KAAK,KAAK,EAAE,CAAC;QAC1C,IAAI,OAAO,aA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GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE;QACnB,MAAM,IAAI,wBAAQ,CAChB,SAAS,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,WAAW,gBAAgB,EACtD,GAAG,EACH,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,WAAW,EAAE,EAAE,EAC7C,eAAe,CAChB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,GAAG,CAAC,kCAAY,CAAC,CAAC;IAEtB,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { Arkos } from \"../types/arkos\";\nimport { getFileUploadRouter } from \"../modules/file-upload/file-upload.router\";\nimport { getAuthRouter } from \"../modules/auth/auth.router\";\nimport {\n getAvailableResourcesAndRoutesRouter,\n getPrismaModelsRouter,\n} from \"../modules/base/base.router\";\nimport { AppError } from \"../exports/error-handler\";\nimport errorHandler from \"../modules/error-handler/error-handler.controller\";\nimport { getArkosConfig } from \"../server\";\nimport { isAuthenticationEnabled } from \"./helpers/arkos-config.helpers\";\nimport { getSwaggerRouter } from \"../modules/swagger/swagger.router\";\n\nexport default function initializeApp(app: Arkos) {\n const config = getArkosConfig();\n const globalPrefix = config.globalPrefix || \"/api\";\n\n const routersConfig = config?.routers;\n\n if (routersConfig?.welcomeRoute !== false) {\n if (typeof routersConfig?.welcomeRoute === \"function\") {\n app.get({ path: globalPrefix }, routersConfig.welcomeRoute);\n } else {\n app.get({ path: globalPrefix }, (_, res) => {\n res.status(200).json({ message: config.welcomeMessage });\n });\n }\n }\n\n const fileUploadRouter = getFileUploadRouter(config);\n app.use(fileUploadRouter);\n\n if (isAuthenticationEnabled()) {\n const authRouter = getAuthRouter(config);\n app.use(globalPrefix, authRouter);\n }\n\n const modelsRouter = getPrismaModelsRouter(config);\n app.use(globalPrefix, modelsRouter);\n\n app.use(globalPrefix, getAvailableResourcesAndRoutesRouter());\n\n if (\n config.swagger &&\n (process.env.ARKOS_BUILD !== \"true\" ||\n config.swagger.enableAfterBuild === true)\n )\n app.use(globalPrefix, getSwaggerRouter(config, app));\n\n return app;\n}\n\nexport function addGlobalErrorHandler(app: Arkos) {\n app.use(\"*\", (req) => {\n throw new AppError(\n `Route ${req.method} ${req.originalUrl} was not found`,\n 404,\n { route: `${req.method} ${req.originalUrl}` },\n \"RouteNotFound\"\n );\n });\n\n app.use(errorHandler);\n\n return app;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/types/arkos-config/utils.ts"],"names":[],"mappings":"","sourcesContent":["import { ArkosRequest } from \"..\";\n\n/**\n * Context object passed to `before` auth hooks.\n */\nexport interface AuthBeforeHookContext {\n req: ArkosRequest;\n /**\n * Bypasses core logic and jumps directly to `after` hooks.\n */\n skip: () => void;\n}\n\n/**\n * Context object passed to `after` auth hooks.\n */\nexport interface AuthAfterHookContext {\n req: ArkosRequest;\n}\n\n/**\n * Context object passed to `onError` auth hooks.\n */\nexport interface AuthErrorHookContext {\n req: ArkosRequest;\n error: unknown;\n /**\n * Suppress the error and jump to `after` hooks.\n */\n skip: () => void;\n}\n\nexport type AuthHookHandler = (\n ctx: AuthBeforeHookContext\n) => void | Promise<void>;\nexport type AuthAfterHookHandler = (\n ctx: AuthAfterHookContext\n) => void | Promise<void>;\nexport type AuthErrorHookHandler = (\n ctx: AuthErrorHookContext\n) => void | Promise<void>;\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/types/arkos-config/utils.ts"],"names":[],"mappings":"","sourcesContent":["import { ArkosRequest } from \"..\";\nimport { AccessAction, DetailedAccessControlRule } from \"../auth\";\n\n/** Context passed to `before` hooks of `authenticate`. */\nexport interface AuthenticateBeforeHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n /** Bypasses core logic and jumps directly to `after` hooks. */\n skip: () => void;\n}\n\n/** Context passed to `after` hooks of `authenticate`. */\nexport interface AuthenticateAfterHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n}\n\n/** Context passed to `onError` hooks of `authenticate`. */\nexport interface AuthenticateErrorHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n /** The error thrown during authentication. */\n error: unknown;\n /** Suppresses the error and jumps to `after` hooks. */\n skip: () => void;\n}\n\nexport type AuthenticateHookHandler = (\n ctx: AuthenticateBeforeHookContext\n) => void | Promise<void>;\n\nexport type AuthenticateAfterHookHandler = (\n ctx: AuthenticateAfterHookContext\n) => void | Promise<void>;\n\nexport type AuthenticateErrorHookHandler = (\n ctx: AuthenticateErrorHookContext\n) => void | Promise<void>;\n\n/** Context passed to `before` hooks of `authorize`. */\nexport interface AuthorizeBeforeHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n /** The action being authorized (e.g. `\"Create\"`, `\"Delete\"`). */\n action: AccessAction;\n /** The resource being accessed in kebab-case (e.g. `\"post\"`, `\"cart-item\"`). */\n resource: string;\n /** The access control rule for this action. */\n rule?: string[] | DetailedAccessControlRule | \"*\";\n /** Bypasses core logic and jumps directly to `after` hooks. */\n skip: () => void;\n}\n\n/** Context passed to `after` hooks of `authorize`. */\nexport interface AuthorizeAfterHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n /** The action that was authorized (e.g. `\"Create\"`, `\"Delete\"`). */\n action: AccessAction;\n /** The resource that was accessed in kebab-case (e.g. `\"post\"`, `\"cart-item\"`). */\n resource: string;\n /** The access control rule that was applied. */\n rule?: string[] | DetailedAccessControlRule | \"*\";\n}\n\n/** Context passed to `onError` hooks of `authorize`. */\nexport interface AuthorizeErrorHookContext {\n /** The incoming request object. */\n req: ArkosRequest;\n /** The error thrown during authorization. */\n error: unknown;\n /** The action being authorized (e.g. `\"Create\"`, `\"Delete\"`). */\n action: AccessAction;\n /** The resource being accessed in kebab-case (e.g. `\"post\"`, `\"cart-item\"`). */\n resource: string;\n /** The access control rule for this action. */\n rule?: string[] | DetailedAccessControlRule | \"*\";\n /** Suppresses the error and jumps to `after` hooks. */\n skip: () => void;\n}\n\nexport type AuthorizeHookHandler = (\n ctx: AuthorizeBeforeHookContext\n) => void | Promise<void>;\n\nexport type AuthorizeAfterHookHandler = (\n ctx: AuthorizeAfterHookContext\n) => void | Promise<void>;\n\nexport type AuthorizeErrorHookHandler = (\n ctx: AuthorizeErrorHookContext\n) => void | Promise<void>;\n"]}
@@ -131,7 +131,7 @@ For further help see https://www.arkosjs.com/docs/core-concepts/authentication/s
131
131
  if (config.authentication && !authenticationConfig?.mode)
132
132
  throw Error(`Trying to authenticate route ${route} without choosing an authentication mode under arkos.config.${getUserFileExtension()}
133
133
 
134
- For further help see https://www.arkosjs.com/docs/core-concepts/authentication-system.`);
134
+ For further help see https://www.arkosjs.com/docs/core-concepts/authentication/setup.`);
135
135
  handlers = [...getMiddlewareStack(config), ...handlers];
136
136
  if (config.experimental?.uploads &&
137
137
  config.experimental.uploads.deleteOnError !== false)
@@ -1 +1 @@
1
- {"version":3,"file":"apply-arkos-router-proxy.js","sourceRoot":"","sources":["../../../../../../src/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.ts"],"names":[],"mappings":"AAQA,OAAO,oBAAoB,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,GAAG,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,mBAAmB,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/D,OAAO,SAAS,MAAM,mCAAmC,CAAC;AAC1D,OAAO,SAAS,MAAM,6BAA6B,CAAC;AACpD,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,MAAM,UAAU,qBAAqB,CACnC,MAAS,EACT,OAGC,EACD,OAAgC,eAAe;IAE/C,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE;QACvB,GAAG,CA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,UAAU,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC;wBAE/C,MAAM,KAAK,CACT,wCAAwC,KAAK,qHAAqH,CACnK,CAAC;oBAEJ,IAAI,MAAM,CAAC,cAAc,IAAI,CAAC,oBAAoB,EAAE,IAAI;wBACtD,MAAM,KAAK,CACT,gCAAgC,KAAK,+DAA+D,oBAAoB,EAAE;;uFAEjD,CAC1E,CAAC;oBAEJ,QAAQ,GAAG,CAAC,GAAG,kBAAkB,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC;oBAExD,IACE,MAAM,CAAC,YAAY,EAAE,OAAO;wBAC5B,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,aAAa,KAAK,KAAK;wBAEnD,QAAQ,CAAC,IAAI,CACX,UAAU,CACR,aAAa,CAAC,iBAAiB,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,EAC5D,EAAE,IAAI,EAAE,OAAO,EAAE,CAClB,CACF,CAAC;oBAEJ,OAAO,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAC;gBACxD,CAAC,CAAC;YACJ,CAAC;YAED,OAAO,cAAc,CAAC;QACxB,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { RouterOptions } from \"express\";\nimport {\n ArkosAnyRequestHandler,\n ArkosRouteConfig,\n ArkosUseConfig,\n IArkosRoute,\n PathParams,\n} from \"../../types\";\nimport RouteConfigValidator from \"../../route-config-validator\";\nimport { applyPrefix, getMiddlewareStack } from \".\";\nimport { getUserFileExtension } from \"../../../helpers/fs.helpers\";\nimport { getArkosConfig } from \"../../../../server\";\nimport RouteConfigRegistry from \"../../route-config-registry\";\nimport { catchAsync } from \"../../../../exports/error-handler\";\nimport deepmerge from \"../../../helpers/deepmerge.helper\";\nimport ExitError from \"../../../helpers/exit-error\";\nimport uploadManager from \"./upload-manager\";\n\nexport function applyArkosRouterProxy<T extends object>(\n target: T,\n options?: RouterOptions & {\n prefix?: string | RegExp | Array<string | RegExp>;\n openapi?: { tags?: string[] };\n },\n name: \"app\" | \"ArkosRouter()\" = \"ArkosRouter()\"\n): T {\n return new Proxy(target, {\n get(target, prop, receiver) {\n const originalMethod = Reflect.get(target, prop, receiver) as Function;\n\n const httpMethods = [\n \"get\",\n \"post\",\n \"put\",\n \"patch\",\n \"delete\",\n \"all\",\n \"head\",\n \"trace\",\n \"options\",\n ] as const;\n\n if (prop === \"use\") {\n return function (\n config: ArkosUseConfig | PathParams | ArkosAnyRequestHandler,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n // if not an ArkosUseConfig object, fall through to native Express use\n if (\n !config ||\n typeof config !== \"object\" ||\n Array.isArray(config) ||\n typeof config === \"function\"\n )\n return originalMethod.call(target, config, ...handlers);\n\n if ((config as ArkosUseConfig).disabled) return;\n\n const useConfig = config as ArkosUseConfig;\n const path = useConfig.path\n ? applyPrefix(options?.prefix, useConfig.path)\n : undefined;\n\n const arkosConfig = getArkosConfig();\n const authenticationConfig = arkosConfig.authentication;\n\n if (useConfig.authentication && !authenticationConfig?.mode)\n throw ExitError(\n `Trying to authenticate route use${path ? ` ${path}` : \"\"} 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 const middlewareStack = getMiddlewareStack(useConfig);\n\n const allHandlers = [...middlewareStack, ...handlers];\n\n return path\n ? originalMethod.call(target, path, ...allHandlers)\n : originalMethod.call(target, ...allHandlers);\n };\n }\n\n if (prop === \"route\") {\n return function (path: PathParams) {\n const routeChain: any = {};\n\n httpMethods.forEach((method) => {\n routeChain[method] = function (\n config: ArkosAnyRequestHandler | Omit<ArkosRouteConfig, \"path\">,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n const fullConfig: ArkosRouteConfig = {\n ...config,\n ...(options?.openapi\n ? {\n experimental: {\n openapi: options.openapi,\n },\n }\n : {}),\n path,\n };\n\n receiver[method](fullConfig, ...handlers);\n\n return routeChain as IArkosRoute;\n };\n });\n\n return routeChain;\n };\n }\n\n if (httpMethods.includes(prop as any)) {\n return function (\n config: ArkosRouteConfig,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n if (config.disabled) return;\n\n if (!RouteConfigValidator.isArkosRouteConfig(config))\n throw Error(\n `First argument of ${name}.${prop as string}() must be a valid ArkosRouteConfig object with path field, but recevied ${typeof config === \"object\" ? JSON.stringify(config, null, 2) : config}`\n );\n\n const path = applyPrefix(options?.prefix, config.path);\n\n config = {\n ...config,\n ...(options?.openapi\n ? {\n experimental: {\n ...config?.experimental,\n openapi: deepmerge(\n options.openapi || {},\n config?.experimental?.openapi || {}\n ),\n },\n }\n : {}),\n path,\n };\n\n if ([null, undefined].includes(path as any))\n throw Error(\n \"Please pass valid value for path field to use in your route\"\n );\n\n const method = prop as string;\n const UndefinedHandlerError = (handler: any) =>\n Error(\n `Wrong value for handler in route ${method.toUpperCase()} ${path}, recevied ${handler}.`\n );\n\n if (handlers.length > 0) {\n const flattenHandlers = (arr: any[]): ArkosAnyRequestHandler[] => {\n return arr.reduce((flat, item) => {\n return flat.concat(\n Array.isArray(item) ? flattenHandlers(item) : item\n );\n }, []);\n };\n\n const flatHandlers = flattenHandlers(handlers);\n\n handlers = flatHandlers.map((handler: ArkosAnyRequestHandler) => {\n if (!handler) throw UndefinedHandlerError(handler);\n\n if (typeof handler !== \"function\") {\n throw UndefinedHandlerError(handler);\n }\n\n return catchAsync(handler, {\n type: handler.length > 3 ? \"error\" : \"normal\",\n });\n });\n\n const finalHandler = handlers[handlers.length - 1];\n RouteConfigRegistry.register(finalHandler, config, method);\n }\n\n const arkosConfig = getArkosConfig();\n const validationConfig = arkosConfig.validation;\n const authenticationConfig = arkosConfig.authentication;\n const strictValidation = validationConfig?.strict;\n const route = `${method.toUpperCase()} ${path}`;\n\n if (\n strictValidation &&\n (!(\"validation\" in config) ||\n (\"validation\" in config &&\n !config.validation &&\n config.validation !== undefined))\n )\n throw Error(\n \"When using strict validation you must either pass { validation: false } in order to explicitly tell that no input will be received, or pass `undefined` for each input type e.g { validation: { query: undefined } } in order to deny the input of given request input.\"\n );\n\n if (\n !validationConfig?.resolver &&\n Object.keys(config.validation || {}).length > 0\n )\n throw Error(\n `Trying to pass validators into route ${route} config validation option without choosing a validation resolver under arkos.init({ validation: { resolver: '' } })`\n );\n\n if (config.authentication && !authenticationConfig?.mode)\n throw Error(\n `Trying to authenticate route ${route} without choosing an authentication mode under arkos.config.${getUserFileExtension()}\n\nFor further help see https://www.arkosjs.com/docs/core-concepts/authentication-system.`\n );\n\n handlers = [...getMiddlewareStack(config), ...handlers];\n\n if (\n config.experimental?.uploads &&\n config.experimental.uploads.deleteOnError !== false\n )\n handlers.push(\n catchAsync(\n uploadManager.handleFileCleanup(config.experimental.uploads),\n { type: \"error\" }\n )\n );\n\n return originalMethod.call(target, path, ...handlers);\n };\n }\n // }\n return originalMethod;\n },\n });\n}\n"]}
1
+ {"version":3,"file":"apply-arkos-router-proxy.js","sourceRoot":"","sources":["../../../../../../src/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.ts"],"names":[],"mappings":"AAQA,OAAO,oBAAoB,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,GAAG,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,mBAAmB,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/D,OAAO,SAAS,MAAM,mCAAmC,CAAC;AAC1D,OAAO,SAAS,MAAM,6BAA6B,CAAC;AACpD,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,MAAM,UAAU,qBAAqB,CACnC,MAAS,EACT,OAGC,EACD,OAAgC,eAAe;IAE/C,OAAO,IAAI,KAAK,CAAC,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AC,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC;wBAE/C,MAAM,KAAK,CACT,wCAAwC,KAAK,qHAAqH,CACnK,CAAC;oBAEJ,IAAI,MAAM,CAAC,cAAc,IAAI,CAAC,oBAAoB,EAAE,IAAI;wBACtD,MAAM,KAAK,CACT,gCAAgC,KAAK,+DAA+D,oBAAoB,EAAE;;sFAElD,CACzE,CAAC;oBAEJ,QAAQ,GAAG,CAAC,GAAG,kBAAkB,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC;oBAExD,IACE,MAAM,CAAC,YAAY,EAAE,OAAO;wBAC5B,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,aAAa,KAAK,KAAK;wBAEnD,QAAQ,CAAC,IAAI,CACX,UAAU,CACR,aAAa,CAAC,iBAAiB,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,EAC5D,EAAE,IAAI,EAAE,OAAO,EAAE,CAClB,CACF,CAAC;oBAEJ,OAAO,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAC;gBACxD,CAAC,CAAC;YACJ,CAAC;YAED,OAAO,cAAc,CAAC;QACxB,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { RouterOptions } from \"express\";\nimport {\n ArkosAnyRequestHandler,\n ArkosRouteConfig,\n ArkosUseConfig,\n IArkosRoute,\n PathParams,\n} from \"../../types\";\nimport RouteConfigValidator from \"../../route-config-validator\";\nimport { applyPrefix, getMiddlewareStack } from \".\";\nimport { getUserFileExtension } from \"../../../helpers/fs.helpers\";\nimport { getArkosConfig } from \"../../../../server\";\nimport RouteConfigRegistry from \"../../route-config-registry\";\nimport { catchAsync } from \"../../../../exports/error-handler\";\nimport deepmerge from \"../../../helpers/deepmerge.helper\";\nimport ExitError from \"../../../helpers/exit-error\";\nimport uploadManager from \"./upload-manager\";\n\nexport function applyArkosRouterProxy<T extends object>(\n target: T,\n options?: RouterOptions & {\n prefix?: string | RegExp | Array<string | RegExp>;\n openapi?: { tags?: string[] };\n },\n name: \"app\" | \"ArkosRouter()\" = \"ArkosRouter()\"\n): T {\n return new Proxy(target, {\n get(target, prop, receiver) {\n const originalMethod = Reflect.get(target, prop, receiver) as Function;\n\n const httpMethods = [\n \"get\",\n \"post\",\n \"put\",\n \"patch\",\n \"delete\",\n \"all\",\n \"head\",\n \"trace\",\n \"options\",\n ] as const;\n\n if (prop === \"use\") {\n return function (\n config: ArkosUseConfig | PathParams | ArkosAnyRequestHandler,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n // if not an ArkosUseConfig object, fall through to native Express use\n if (\n !config ||\n typeof config !== \"object\" ||\n Array.isArray(config) ||\n typeof config === \"function\"\n )\n return originalMethod.call(target, config, ...handlers);\n\n if ((config as ArkosUseConfig).disabled) return;\n\n const useConfig = config as ArkosUseConfig;\n const path = useConfig.path\n ? applyPrefix(options?.prefix, useConfig.path)\n : undefined;\n\n const arkosConfig = getArkosConfig();\n const authenticationConfig = arkosConfig.authentication;\n\n if (useConfig.authentication && !authenticationConfig?.mode)\n throw ExitError(\n `Trying to authenticate route use${path ? ` ${path}` : \"\"} 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 const middlewareStack = getMiddlewareStack(useConfig);\n\n const allHandlers = [...middlewareStack, ...handlers];\n\n return path\n ? originalMethod.call(target, path, ...allHandlers)\n : originalMethod.call(target, ...allHandlers);\n };\n }\n\n if (prop === \"route\") {\n return function (path: PathParams) {\n const routeChain: any = {};\n\n httpMethods.forEach((method) => {\n routeChain[method] = function (\n config: ArkosAnyRequestHandler | Omit<ArkosRouteConfig, \"path\">,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n const fullConfig: ArkosRouteConfig = {\n ...config,\n ...(options?.openapi\n ? {\n experimental: {\n openapi: options.openapi,\n },\n }\n : {}),\n path,\n };\n\n receiver[method](fullConfig, ...handlers);\n\n return routeChain as IArkosRoute;\n };\n });\n\n return routeChain;\n };\n }\n\n if (httpMethods.includes(prop as any)) {\n return function (\n config: ArkosRouteConfig,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n if (config.disabled) return;\n\n if (!RouteConfigValidator.isArkosRouteConfig(config))\n throw Error(\n `First argument of ${name}.${prop as string}() must be a valid ArkosRouteConfig object with path field, but recevied ${typeof config === \"object\" ? JSON.stringify(config, null, 2) : config}`\n );\n\n const path = applyPrefix(options?.prefix, config.path);\n\n config = {\n ...config,\n ...(options?.openapi\n ? {\n experimental: {\n ...config?.experimental,\n openapi: deepmerge(\n options.openapi || {},\n config?.experimental?.openapi || {}\n ),\n },\n }\n : {}),\n path,\n };\n\n if ([null, undefined].includes(path as any))\n throw Error(\n \"Please pass valid value for path field to use in your route\"\n );\n\n const method = prop as string;\n const UndefinedHandlerError = (handler: any) =>\n Error(\n `Wrong value for handler in route ${method.toUpperCase()} ${path}, recevied ${handler}.`\n );\n\n if (handlers.length > 0) {\n const flattenHandlers = (arr: any[]): ArkosAnyRequestHandler[] => {\n return arr.reduce((flat, item) => {\n return flat.concat(\n Array.isArray(item) ? flattenHandlers(item) : item\n );\n }, []);\n };\n\n const flatHandlers = flattenHandlers(handlers);\n\n handlers = flatHandlers.map((handler: ArkosAnyRequestHandler) => {\n if (!handler) throw UndefinedHandlerError(handler);\n\n if (typeof handler !== \"function\") {\n throw UndefinedHandlerError(handler);\n }\n\n return catchAsync(handler, {\n type: handler.length > 3 ? \"error\" : \"normal\",\n });\n });\n\n const finalHandler = handlers[handlers.length - 1];\n RouteConfigRegistry.register(finalHandler, config, method);\n }\n\n const arkosConfig = getArkosConfig();\n const validationConfig = arkosConfig.validation;\n const authenticationConfig = arkosConfig.authentication;\n const strictValidation = validationConfig?.strict;\n const route = `${method.toUpperCase()} ${path}`;\n\n if (\n strictValidation &&\n (!(\"validation\" in config) ||\n (\"validation\" in config &&\n !config.validation &&\n config.validation !== undefined))\n )\n throw Error(\n \"When using strict validation you must either pass { validation: false } in order to explicitly tell that no input will be received, or pass `undefined` for each input type e.g { validation: { query: undefined } } in order to deny the input of given request input.\"\n );\n\n if (\n !validationConfig?.resolver &&\n Object.keys(config.validation || {}).length > 0\n )\n throw Error(\n `Trying to pass validators into route ${route} config validation option without choosing a validation resolver under arkos.init({ validation: { resolver: '' } })`\n );\n\n if (config.authentication && !authenticationConfig?.mode)\n throw Error(\n `Trying to authenticate route ${route} 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 handlers = [...getMiddlewareStack(config), ...handlers];\n\n if (\n config.experimental?.uploads &&\n config.experimental.uploads.deleteOnError !== false\n )\n handlers.push(\n catchAsync(\n uploadManager.handleFileCleanup(config.experimental.uploads),\n { type: \"error\" }\n )\n );\n\n return originalMethod.call(target, path, ...handlers);\n };\n }\n // }\n return originalMethod;\n },\n });\n}\n"]}
@@ -11,6 +11,6 @@ export function killServerChildProcess() {
11
11
  killProductionServerChildProcess();
12
12
  }
13
13
  export function getVersion() {
14
- return "1.4.12-beta";
14
+ return "1.4.13-beta";
15
15
  }
16
16
  //# sourceMappingURL=cli.helpers.js.map
@@ -1,5 +1,4 @@
1
1
  import fs from "fs";
2
- import AppError from "../../modules/error-handler/utils/app-error.js";
3
2
  import { crd, getUserFileExtension as ext } from "./fs.helpers.js";
4
3
  import { importModule } from "./global.helpers.js";
5
4
  import prismaSchemaParser from "../prisma/prisma-schema-parser.js";
@@ -23,7 +22,7 @@ export async function loadPrismaModule() {
23
22
  }
24
23
  catch (error) {
25
24
  if (error.message === "Prisma not found")
26
- throw new AppError(`Could not initialize Prisma module. Make sure your prisma instance is exported as default under src/utils/prisma/index.${ext()}, read more about Arkos.js Project Structure under https://www.arkosjs.com/docs/getting-started/project-structure#utilities-directory`, 500, {}, "PrismaInstanceNotFound");
25
+ return sheu.warn(`Could not find your prisma instance under src/utils/prisma/index.${ext()}, see https://www.arkosjs.com/docs/core-concepts/prisma-orm/setup`, { timestamp: true });
27
26
  throw error;
28
27
  }
29
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"prisma.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/prisma.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,QAAQ,MAAM,6CAA6C,CAAC;AACnE,OAAO,EAAE,GAAG,EAAE,oBAAoB,IAAI,GAAG,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,kBAAkB,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,MAAM,CAAC,IAAI,cAAc,GAAQ,IAAI,CAAC;AAEtC,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,IAAI,CAAC;YACH,IAAI,UAAU,GAAG,GAAG,GAAG,EAAE,qBAAqB,GAAG,EAAE,EAAE,CAAC;YAEtD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;gBAC5B,UAAU,GAAG,GAAG,GAAG,EAAE,2BAA2B,GAAG,EAAE,EAAE,CAAC;YAE1D,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;YAEpE,MAAM,YAAY,GAAG,MAAM,YAAY,CAAC,UAAU,EAAE;gBAClD,YAAY,EAAE,KAAK;aACpB,CAAC,CAAC;YACH,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC;YAEtC,IAAI,CAAC,cAAc,IAAI,OAAO,cAAc,EAAE,CAAC,UAAU,CAAC,KAAK,UAAU;gBACvE,MAAM,IAAI,KAAK,CAAC,k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,MAAM,GAAG,CAAC,EAAE,CAAC;gCACnD,IAAI,CAAC,KAAK,CACR,sBAAsB,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAC1D,EAAE,SAAS,EAAE,IAAI,EAAE,CACpB,CAAC;4BACJ,CAAC;iCAAM,CAAC;gCACN,IAAI,CAAC,KAAK,CAAC,2BAA2B,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;4BAC/D,CAAC;wBACH,CAAC;wBAED,OAAO,cAAc,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;oBACjD,CAAC,CAAC;gBACJ,CAAC;gBAED,OAAO,cAAc,CAAC;YACxB,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,IAAI,CAAC,cAAc;QAAE,OAAO,IAAI,CAAC;IAEjC,OAAO,IAAI,KAAK,CAAC,cAAc,EAAE;QAC/B,GAAG,EAAE,eAAe;KACrB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import fs from \"fs\";\nimport AppError from \"../../modules/error-handler/utils/app-error\";\nimport { crd, getUserFileExtension as ext } from \"./fs.helpers\";\nimport { importModule } from \"./global.helpers\";\nimport prismaSchemaParser from \"../prisma/prisma-schema-parser\";\nimport { getArkosConfig } from \"./arkos-config.helpers\";\nimport sheu from \"../sheu\";\n\nexport let prismaInstance: any = null;\n\nexport async function loadPrismaModule() {\n if (!prismaInstance) {\n try {\n let prismaPath = `${crd()}/src/utils/prisma.${ext()}`;\n\n if (!fs.existsSync(prismaPath))\n prismaPath = `${crd()}/src/utils/prisma/index.${ext()}`;\n\n if (!fs.existsSync(prismaPath)) throw new Error(`Prisma not found`);\n\n const prismaModule = await importModule(prismaPath, {\n fixExtension: false,\n });\n prismaInstance = prismaModule.default;\n\n if (!prismaInstance || typeof prismaInstance?.[\"$connect\"] !== \"function\")\n throw new Error(\"Prisma not found\");\n } catch (error: any) {\n if (error.message === \"Prisma not found\")\n throw new AppError(\n `Could not initialize Prisma module. Make sure your prisma instance is exported as default under src/utils/prisma/index.${ext()}, read more about Arkos.js Project Structure under https://www.arkosjs.com/docs/getting-started/project-structure#utilities-directory`,\n 500,\n {},\n \"PrismaInstanceNotFound\"\n );\n throw error;\n }\n }\n return prismaInstance;\n}\n\nexport function handlePrismaGet(target: any, prop: string, receiver: any) {\n const originalProperty = Reflect.get(target, prop, receiver);\n\n const isModel = prismaSchemaParser\n .getModelsAsArrayOfStrings()\n .find((m) => m.toLowerCase() === (prop as string)?.toLowerCase?.());\n\n if (isModel && originalProperty) {\n return new Proxy(originalProperty, {\n get(modelTarget, methodName, modelReceiver) {\n const originalMethod = Reflect.get(\n modelTarget,\n methodName,\n modelReceiver\n );\n\n if (typeof originalMethod === \"function\") {\n return function (...args: any[]) {\n const config = getArkosConfig();\n const debugLevel = config.debugging?.requests?.level || 0;\n\n if (debugLevel >= 3) {\n const queryArgs = args[0];\n\n if (queryArgs && Object.keys(queryArgs).length > 0) {\n sheu.debug(\n `Final Prisma Args\\n${JSON.stringify(queryArgs, null, 2)}`,\n { timestamp: true }\n );\n } else {\n sheu.debug(`Final Prisma Args - Empty`, { timestamp: true });\n }\n }\n\n return originalMethod.apply(modelTarget, args);\n };\n }\n\n return originalMethod;\n },\n });\n }\n\n return originalProperty;\n}\n\nexport function getPrismaInstance() {\n if (!prismaInstance) return null;\n\n return new Proxy(prismaInstance, {\n get: handlePrismaGet,\n });\n}\n"]}
1
+ {"version":3,"file":"prisma.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/prisma.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,GAAG,EAAE,oBAAoB,IAAI,GAAG,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,kBAA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,CAAC;gBAED,OAAO,cAAc,CAAC;YACxB,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,IAAI,CAAC,cAAc;QAAE,OAAO,IAAI,CAAC;IAEjC,OAAO,IAAI,KAAK,CAAC,cAAc,EAAE;QAC/B,GAAG,EAAE,eAAe;KACrB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import fs from \"fs\";\nimport { crd, getUserFileExtension as ext } from \"./fs.helpers\";\nimport { importModule } from \"./global.helpers\";\nimport prismaSchemaParser from \"../prisma/prisma-schema-parser\";\nimport { getArkosConfig } from \"./arkos-config.helpers\";\nimport sheu from \"../sheu\";\n\nexport let prismaInstance: any = null;\n\nexport async function loadPrismaModule() {\n if (!prismaInstance) {\n try {\n let prismaPath = `${crd()}/src/utils/prisma.${ext()}`;\n\n if (!fs.existsSync(prismaPath))\n prismaPath = `${crd()}/src/utils/prisma/index.${ext()}`;\n\n if (!fs.existsSync(prismaPath)) throw new Error(`Prisma not found`);\n\n const prismaModule = await importModule(prismaPath, {\n fixExtension: false,\n });\n prismaInstance = prismaModule.default;\n\n if (!prismaInstance || typeof prismaInstance?.[\"$connect\"] !== \"function\")\n throw new Error(\"Prisma not found\");\n } catch (error: any) {\n if (error.message === \"Prisma not found\")\n return sheu.warn(\n `Could not find your prisma instance under src/utils/prisma/index.${ext()}, see https://www.arkosjs.com/docs/core-concepts/prisma-orm/setup`,\n { timestamp: true }\n );\n throw error;\n }\n }\n return prismaInstance;\n}\n\nexport function handlePrismaGet(target: any, prop: string, receiver: any) {\n const originalProperty = Reflect.get(target, prop, receiver);\n\n const isModel = prismaSchemaParser\n .getModelsAsArrayOfStrings()\n .find((m) => m.toLowerCase() === (prop as string)?.toLowerCase?.());\n\n if (isModel && originalProperty) {\n return new Proxy(originalProperty, {\n get(modelTarget, methodName, modelReceiver) {\n const originalMethod = Reflect.get(\n modelTarget,\n methodName,\n modelReceiver\n );\n\n if (typeof originalMethod === \"function\") {\n return function (...args: any[]) {\n const config = getArkosConfig();\n const debugLevel = config.debugging?.requests?.level || 0;\n\n if (debugLevel >= 3) {\n const queryArgs = args[0];\n\n if (queryArgs && Object.keys(queryArgs).length > 0) {\n sheu.debug(\n `Final Prisma Args\\n${JSON.stringify(queryArgs, null, 2)}`,\n { timestamp: true }\n );\n } else {\n sheu.debug(`Final Prisma Args - Empty`, { timestamp: true });\n }\n }\n\n return originalMethod.apply(modelTarget, args);\n };\n }\n\n return originalMethod;\n },\n });\n }\n\n return originalProperty;\n}\n\nexport function getPrismaInstance() {\n if (!prismaInstance) return null;\n\n return new Proxy(prismaInstance, {\n get: handlePrismaGet,\n });\n}\n"]}
@@ -10,7 +10,6 @@ export default function initializeApp(app) {
10
10
  const config = getArkosConfig();
11
11
  const globalPrefix = config.globalPrefix || "/api";
12
12
  const routersConfig = config?.routers;
13
- const middlewaresConfig = config?.middlewares;
14
13
  if (routersConfig?.welcomeRoute !== false) {
15
14
  if (typeof routersConfig?.welcomeRoute === "function") {
16
15
  app.get({ path: globalPrefix }, routersConfig.welcomeRoute);
@@ -34,17 +33,13 @@ export default function initializeApp(app) {
34
33
  (process.env.ARKOS_BUILD !== "true" ||
35
34
  config.swagger.enableAfterBuild === true))
36
35
  app.use(globalPrefix, getSwaggerRouter(config, app));
36
+ return app;
37
+ }
38
+ export function addGlobalErrorHandler(app) {
37
39
  app.use("*", (req) => {
38
40
  throw new AppError(`Route ${req.method} ${req.originalUrl} was not found`, 404, { route: `${req.method} ${req.originalUrl}` }, "RouteNotFound");
39
41
  });
40
- if (middlewaresConfig?.errorHandler !== false) {
41
- if (typeof middlewaresConfig?.errorHandler === "function") {
42
- app.use(middlewaresConfig.errorHandler);
43
- }
44
- else {
45
- app.use(errorHandler);
46
- }
47
- }
42
+ app.use(errorHandler);
48
43
  return app;
49
44
  }
50
45
  //# sourceMappingURL=initialize-app.js.map
@@ -1 +1 @@
1
- {"version":3,"file":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AAY,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { Arkos } from \"../types/arkos\";\nimport { getFileUploadRouter } from \"../modules/file-upload/file-upload.router\";\nimport { getAuthRouter } from \"../modules/auth/auth.router\";\nimport {\n getAvailableResourcesAndRoutesRouter,\n getPrismaModelsRouter,\n} from \"../modules/base/base.router\";\nimport { AppError } from \"../exports/error-handler\";\nimport errorHandler from \"../modules/error-handler/error-handler.controller\";\nimport { getArkosConfig } from \"../server\";\nimport { isAuthenticationEnabled } from \"./helpers/arkos-config.helpers\";\nimport { getSwaggerRouter } from \"../modules/swagger/swagger.router\";\n\nexport default function initializeApp(app: Arkos) {\n const config = getArkosConfig();\n const globalPrefix = config.globalPrefix || \"/api\";\n\n const routersConfig = config?.routers;\n const middlewaresConfig = config?.middlewares;\n\n if (routersConfig?.welcomeRoute !== false) {\n if (typeof routersConfig?.welcomeRoute === \"function\") {\n app.get({ path: globalPrefix }, routersConfig.welcomeRoute);\n } else {\n app.get({ path: globalPrefix }, (_, res) => {\n res.status(200).json({ message: config.welcomeMessage });\n });\n }\n }\n\n const fileUploadRouter = getFileUploadRouter(config);\n app.use(fileUploadRouter);\n\n if (isAuthenticationEnabled()) {\n const authRouter = getAuthRouter(config);\n app.use(globalPrefix, authRouter);\n }\n\n const modelsRouter = getPrismaModelsRouter(config);\n app.use(globalPrefix, modelsRouter);\n\n app.use(globalPrefix, getAvailableResourcesAndRoutesRouter());\n\n if (\n config.swagger &&\n (process.env.ARKOS_BUILD !== \"true\" ||\n config.swagger.enableAfterBuild === true)\n )\n app.use(globalPrefix, getSwaggerRouter(config, app));\n\n app.use(\"*\", (req) => {\n throw new AppError(\n `Route ${req.method} ${req.originalUrl} was not found`,\n 404,\n { route: `${req.method} ${req.originalUrl}` },\n \"RouteNotFound\"\n );\n });\n\n if (middlewaresConfig?.errorHandler !== false) {\n if (typeof middlewaresConfig?.errorHandler === \"function\") {\n app.use(middlewaresConfig.errorHandler);\n } else {\n app.use(errorHandler);\n }\n }\n return app;\n}\n"]}
1
+ {"version":3,"file":"initialize-app.js","sourceRoot":"","sources":["../../../src/utils/initialize-app.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,oCAAoC,EACpC,qBAAqB,GACtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,YAAY,MAAM,mDAAmD,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,GAAU;IAC9C,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC;IAEnD,MAAM,aAAa,GAAG,MAAM,EAAE,OAAO,CAAC;IAEtC,IAAI,aAAa,EAAE,YAAY,KAAK,KAAK,EAAE,CAAC;QAC1C,IAAI,OAAO,aAAa,EAAE,YAAY,KAAK,UAAU,EAAE,CAAC;YACtD,GAAG,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;QAC9D,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;gBACzC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC;YAC3D,CAAC,CAAC,CAA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/file-upload/file-upload.router\";\nimport { getAuthRouter } from \"../modules/auth/auth.router\";\nimport {\n getAvailableResourcesAndRoutesRouter,\n getPrismaModelsRouter,\n} from \"../modules/base/base.router\";\nimport { AppError } from \"../exports/error-handler\";\nimport errorHandler from \"../modules/error-handler/error-handler.controller\";\nimport { getArkosConfig } from \"../server\";\nimport { isAuthenticationEnabled } from \"./helpers/arkos-config.helpers\";\nimport { getSwaggerRouter } from \"../modules/swagger/swagger.router\";\n\nexport default function initializeApp(app: Arkos) {\n const config = getArkosConfig();\n const globalPrefix = config.globalPrefix || \"/api\";\n\n const routersConfig = config?.routers;\n\n if (routersConfig?.welcomeRoute !== false) {\n if (typeof routersConfig?.welcomeRoute === \"function\") {\n app.get({ path: globalPrefix }, routersConfig.welcomeRoute);\n } else {\n app.get({ path: globalPrefix }, (_, res) => {\n res.status(200).json({ message: config.welcomeMessage });\n });\n }\n }\n\n const fileUploadRouter = getFileUploadRouter(config);\n app.use(fileUploadRouter);\n\n if (isAuthenticationEnabled()) {\n const authRouter = getAuthRouter(config);\n app.use(globalPrefix, authRouter);\n }\n\n const modelsRouter = getPrismaModelsRouter(config);\n app.use(globalPrefix, modelsRouter);\n\n app.use(globalPrefix, getAvailableResourcesAndRoutesRouter());\n\n if (\n config.swagger &&\n (process.env.ARKOS_BUILD !== \"true\" ||\n config.swagger.enableAfterBuild === true)\n )\n app.use(globalPrefix, getSwaggerRouter(config, app));\n\n return app;\n}\n\nexport function addGlobalErrorHandler(app: Arkos) {\n app.use(\"*\", (req) => {\n throw new AppError(\n `Route ${req.method} ${req.originalUrl} was not found`,\n 404,\n { route: `${req.method} ${req.originalUrl}` },\n \"RouteNotFound\"\n );\n });\n\n app.use(errorHandler);\n\n return app;\n}\n"]}
@@ -1,31 +1,68 @@
1
1
  import { ArkosRequest } from "..";
2
- /**
3
- * Context object passed to `before` auth hooks.
4
- */
5
- export interface AuthBeforeHookContext {
2
+ import { AccessAction, DetailedAccessControlRule } from "../auth";
3
+ /** Context passed to `before` hooks of `authenticate`. */
4
+ export interface AuthenticateBeforeHookContext {
5
+ /** The incoming request object. */
6
6
  req: ArkosRequest;
7
- /**
8
- * Bypasses core logic and jumps directly to `after` hooks.
9
- */
7
+ /** Bypasses core logic and jumps directly to `after` hooks. */
10
8
  skip: () => void;
11
9
  }
12
- /**
13
- * Context object passed to `after` auth hooks.
14
- */
15
- export interface AuthAfterHookContext {
10
+ /** Context passed to `after` hooks of `authenticate`. */
11
+ export interface AuthenticateAfterHookContext {
12
+ /** The incoming request object. */
16
13
  req: ArkosRequest;
17
14
  }
18
- /**
19
- * Context object passed to `onError` auth hooks.
20
- */
21
- export interface AuthErrorHookContext {
15
+ /** Context passed to `onError` hooks of `authenticate`. */
16
+ export interface AuthenticateErrorHookContext {
17
+ /** The incoming request object. */
22
18
  req: ArkosRequest;
19
+ /** The error thrown during authentication. */
23
20
  error: unknown;
24
- /**
25
- * Suppress the error and jump to `after` hooks.
26
- */
21
+ /** Suppresses the error and jumps to `after` hooks. */
27
22
  skip: () => void;
28
23
  }
29
- export type AuthHookHandler = (ctx: AuthBeforeHookContext) => void | Promise<void>;
30
- export type AuthAfterHookHandler = (ctx: AuthAfterHookContext) => void | Promise<void>;
31
- export type AuthErrorHookHandler = (ctx: AuthErrorHookContext) => void | Promise<void>;
24
+ export type AuthenticateHookHandler = (ctx: AuthenticateBeforeHookContext) => void | Promise<void>;
25
+ export type AuthenticateAfterHookHandler = (ctx: AuthenticateAfterHookContext) => void | Promise<void>;
26
+ export type AuthenticateErrorHookHandler = (ctx: AuthenticateErrorHookContext) => void | Promise<void>;
27
+ /** Context passed to `before` hooks of `authorize`. */
28
+ export interface AuthorizeBeforeHookContext {
29
+ /** The incoming request object. */
30
+ req: ArkosRequest;
31
+ /** The action being authorized (e.g. `"Create"`, `"Delete"`). */
32
+ action: AccessAction;
33
+ /** The resource being accessed in kebab-case (e.g. `"post"`, `"cart-item"`). */
34
+ resource: string;
35
+ /** The access control rule for this action. */
36
+ rule?: string[] | DetailedAccessControlRule | "*";
37
+ /** Bypasses core logic and jumps directly to `after` hooks. */
38
+ skip: () => void;
39
+ }
40
+ /** Context passed to `after` hooks of `authorize`. */
41
+ export interface AuthorizeAfterHookContext {
42
+ /** The incoming request object. */
43
+ req: ArkosRequest;
44
+ /** The action that was authorized (e.g. `"Create"`, `"Delete"`). */
45
+ action: AccessAction;
46
+ /** The resource that was accessed in kebab-case (e.g. `"post"`, `"cart-item"`). */
47
+ resource: string;
48
+ /** The access control rule that was applied. */
49
+ rule?: string[] | DetailedAccessControlRule | "*";
50
+ }
51
+ /** Context passed to `onError` hooks of `authorize`. */
52
+ export interface AuthorizeErrorHookContext {
53
+ /** The incoming request object. */
54
+ req: ArkosRequest;
55
+ /** The error thrown during authorization. */
56
+ error: unknown;
57
+ /** The action being authorized (e.g. `"Create"`, `"Delete"`). */
58
+ action: AccessAction;
59
+ /** The resource being accessed in kebab-case (e.g. `"post"`, `"cart-item"`). */
60
+ resource: string;
61
+ /** The access control rule for this action. */
62
+ rule?: string[] | DetailedAccessControlRule | "*";
63
+ /** Suppresses the error and jumps to `after` hooks. */
64
+ skip: () => void;
65
+ }
66
+ export type AuthorizeHookHandler = (ctx: AuthorizeBeforeHookContext) => void | Promise<void>;
67
+ export type AuthorizeAfterHookHandler = (ctx: AuthorizeAfterHookContext) => void | Promise<void>;
68
+ export type AuthorizeErrorHookHandler = (ctx: AuthorizeErrorHookContext) => void | Promise<void>;
@@ -1,2 +1,3 @@
1
1
  import { Arkos } from "../types/arkos";
2
2
  export default function initializeApp(app: Arkos): Arkos;
3
+ export declare function addGlobalErrorHandler(app: Arkos): Arkos;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkos",
3
- "version": "1.4.12-beta",
3
+ "version": "1.4.13-beta",
4
4
  "description": "The Express & Prisma RESTful Framework",
5
5
  "main": "dist/cjs/exports/index.js",
6
6
  "module": "dist/esm/exports/index.js",