From 770e791613a24e6909e7a61118de0e2b0dee3f15 Mon Sep 17 00:00:00 2001 From: Arno Kaimbacher Date: Tue, 21 May 2024 14:41:10 +0200 Subject: [PATCH] - typsafe vanilla_error_reporter.ts - updated Dockerfole for using node 20 - remove validator_old.ts - npm updates --- Dockerfile | 5 +- app/Controllers/Http/Auth/UserController.ts | 2 +- app/exceptions/handler.ts | 2 +- app/validators/vanilla_error_reporter.ts | 30 +- config/app.ts | 4 +- package-lock.json | 357 +++++++++----------- providers/validator_provider.ts | 1 + start/kernel.ts | 44 ++- start/validator_old.ts | 140 -------- 9 files changed, 204 insertions(+), 381 deletions(-) delete mode 100644 start/validator_old.ts diff --git a/Dockerfile b/Dockerfile index 7184d96..0338337 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ ################## First Stage - Creating base ######################### # Created a variable to hold our node base image -ARG NODE_IMAGE=node:18-bookworm-slim +ARG NODE_IMAGE=node:20-bookworm-slim FROM $NODE_IMAGE AS base # Install dumb-init and ClamAV, and perform ClamAV database update @@ -67,7 +67,8 @@ COPY --chown=node:node . . # In this stage, we will start building dependencies FROM dependencies AS build # We run "node ace build" to build the app (dist folder) for production -RUN node ace build --production +RUN node ace build # --production +# RUN node ace build --ignore-ts-errors ################## Final Stage - Production ######################### diff --git a/app/Controllers/Http/Auth/UserController.ts b/app/Controllers/Http/Auth/UserController.ts index 54794f4..1029bcb 100644 --- a/app/Controllers/Http/Auth/UserController.ts +++ b/app/Controllers/Http/Auth/UserController.ts @@ -4,7 +4,7 @@ import User from '#models/user'; import TwoFactorAuthProvider from '#app/services/TwoFactorAuthProvider'; import hash from '@adonisjs/core/services/hash'; // import { schema, rules } from '@adonisjs/validator'; -import vine, { SimpleMessagesProvider } from '@vinejs/vine'; +import vine from '@vinejs/vine'; // Here we are generating secret and recovery codes for the user that’s enabling 2FA and storing them to our database. export default class UserController { diff --git a/app/exceptions/handler.ts b/app/exceptions/handler.ts index 3115cca..d8f1c63 100644 --- a/app/exceptions/handler.ts +++ b/app/exceptions/handler.ts @@ -68,7 +68,7 @@ export default class HttpExceptionHandler extends ExceptionHandler { // } public async handle(error: any, ctx: HttpContext) { - const { response, request, session, inertia } = ctx; + const { response, request, session } = ctx; /** * Handle failed authentication attempt diff --git a/app/validators/vanilla_error_reporter.ts b/app/validators/vanilla_error_reporter.ts index 2cc606f..a429060 100644 --- a/app/validators/vanilla_error_reporter.ts +++ b/app/validators/vanilla_error_reporter.ts @@ -17,7 +17,7 @@ export interface MessagesBagContract { * given validation failure. */ export class MessagesBag implements MessagesBagContract { - messages; + messages: Message; wildCardCallback; constructor(messages: string[]) { this.messages = messages; @@ -66,13 +66,16 @@ export class MessagesBag implements MessagesBagContract { /** * Shape of the error message collected by the SimpleErrorReporter */ -// type SimpleError = { -// message: string; -// field: string; -// rule: string; -// index?: number; -// meta?: Record; -// }; +type SimpleError = { + message: string; + field: string; + rule: string; + index?: number; + meta?: Record; +}; +export interface Message { + [key: string]: any; +} /** * Simple error reporter collects error messages as an array of object. * Each object has following properties. @@ -84,7 +87,7 @@ export class MessagesBag implements MessagesBagContract { * - args?: Record */ export class VanillaErrorReporter implements ErrorReporterContract { - private messages; + // private messages; // private bail; /** * Boolean to know one or more errors have been reported @@ -94,7 +97,7 @@ export class VanillaErrorReporter implements ErrorReporterContract { * Collection of errors */ // errors: SimpleError[] = []; - errors = {}; + errors: Message = {}; /** * Report an error. */ @@ -117,7 +120,12 @@ export class VanillaErrorReporter implements ErrorReporterContract { // } // this.errors.push(error); this.hasErrors = true; - const error = { + // if (this.errors[field.getFieldPath()]) { + // this.errors[field.getFieldPath()]?.push(message); + // } else { + // this.errors[field.getFieldPath()] = [message]; + // } + const error: SimpleError = { message, rule, field: field.getFieldPath(), diff --git a/config/app.ts b/config/app.ts index e826d5a..fea93ab 100644 --- a/config/app.ts +++ b/config/app.ts @@ -12,7 +12,7 @@ import env from '#start/env'; // import type { AssetsManagerConfig } from '@ioc:Adonis/Core/AssetsManager'; // import { ServerConfig } from "@adonisjs/core/services/server"; // import { LoggerConfig } from "@adonisjs/core/types/logger"; -import { ValidatorConfig } from "@adonisjs/validator/types"; +// import { ValidatorConfig } from "@adonisjs/validator/types"; import { defineConfig } from "@adonisjs/core/http"; /* @@ -163,7 +163,7 @@ export const http = defineConfig({ | to the default config https://git.io/JT0WE | */ -export const validator: ValidatorConfig = {}; +export const validator = {}; /* |-------------------------------------------------------------------------- diff --git a/package-lock.json b/package-lock.json index 687e9e2..a0800b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -903,12 +903,12 @@ } }, "node_modules/@adonisjs/inertia": { - "version": "1.0.0-27", - "resolved": "https://registry.npmjs.org/@adonisjs/inertia/-/inertia-1.0.0-27.tgz", - "integrity": "sha512-T3G4s8mzdPv1+JEGvq7AAgc62kBB8n0DmrQAQHy8M5vzYy0swNcKjdNwiSdG6ChJSys/yX91QwcUoyRltUAtZA==", + "version": "1.0.0-28", + "resolved": "https://registry.npmjs.org/@adonisjs/inertia/-/inertia-1.0.0-28.tgz", + "integrity": "sha512-/suBR1Q6Di4s6A8JrlH4muqUY/wH1k+Xts+2p8RdkYbsmuuIsFPzPMSzjGObE2hnvOIDJm2ZlG1DIgWpHdj9BQ==", "dependencies": { "@poppinss/utils": "^6.7.3", - "@tuyau/utils": "^0.0.3", + "@tuyau/utils": "^0.0.4", "crc-32": "^1.2.2", "edge-error": "^4.0.1", "html-entities": "^2.5.2", @@ -1015,9 +1015,9 @@ } }, "node_modules/@adonisjs/presets": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@adonisjs/presets/-/presets-2.4.0.tgz", - "integrity": "sha512-pgv0dxWCg9ktbPBHCBxVnxP8DXYV6xgDWWwctcjGuXCFAkP1BN5CamTfAiQFftF4Je0G7giyK9jz/TOoBurG0g==", + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/@adonisjs/presets/-/presets-2.4.1.tgz", + "integrity": "sha512-STJ021TGsvfTGs1oEielf0ww+RxBMFLzNy94Um2hkJZbCLpsBVchKcjJg4IH2nnU7htrlm1DbNXusg/OtiAW3Q==", "dependencies": { "@poppinss/utils": "^6.7.3" }, @@ -3759,9 +3759,9 @@ } }, "node_modules/@inertiajs/core/node_modules/axios": { - "version": "1.6.8", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", - "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.1.tgz", + "integrity": "sha512-+LV37nQcd1EpFalkXksWNBiA17NZ5m5/WspmHGmZmdx1qBOg/VNq/c4eRJiA9VQQHBOs+N0ZhhdU10h2TyNK7Q==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -4611,9 +4611,9 @@ } }, "node_modules/@redis/client": { - "version": "1.5.14", - "resolved": "https://registry.npmjs.org/@redis/client/-/client-1.5.14.tgz", - "integrity": "sha512-YGn0GqsRBFUQxklhY7v562VMOP0DcmlrHHs3IV1mFE3cbxe31IITUkqhBcIhVSI/2JqtWAJXg5mjV4aU+zD0HA==", + "version": "1.5.16", + "resolved": "https://registry.npmjs.org/@redis/client/-/client-1.5.16.tgz", + "integrity": "sha512-X1a3xQ5kEMvTib5fBrHKh6Y+pXbeKXqziYuxOUo1ojQNECg4M5Etd1qqyhMap+lFUOAh8S7UYevgJHOm4A+NOg==", "dependencies": { "cluster-key-slot": "1.1.2", "generic-pool": "3.9.0", @@ -4875,9 +4875,9 @@ "devOptional": true }, "node_modules/@sindresorhus/is": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-6.3.0.tgz", - "integrity": "sha512-bOSPck7aIJjASXIg1qvXSIjXhVBpIEKdl2Wxg4pVqoTRPL8wWExKBrnGIh6CEnhkFQHfc36k7APhO3uXV4g5xg==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-6.3.1.tgz", + "integrity": "sha512-FX4MfcifwJyFOI2lPoX7PQxCqx8BG1HCho7WdiXwpEQx1Ycij0JxkfYtGK7yqNScrZGSlt6RE6sw8QYoH7eKnQ==", "engines": { "node": ">=16" }, @@ -5423,9 +5423,9 @@ "dev": true }, "node_modules/@tuyau/utils": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/@tuyau/utils/-/utils-0.0.3.tgz", - "integrity": "sha512-/BFxr+RqHT0JhPSxBoh254cEOAkVrct3EQABiuXrBNicfRZPDltgB0/lh+V/MCpOcmbL/8LrbLLa7gyE0FEJYw==" + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/@tuyau/utils/-/utils-0.0.4.tgz", + "integrity": "sha512-ex6CAJNLiTuOvx7nUrgs8FwNG/t88Mi8QTLSO3muHbB6vBSpYimZ6iSUkk4cjEFd4XDy0y+24GDgXKoBfGf4ag==" }, "node_modules/@types/bcryptjs": { "version": "2.4.6", @@ -5864,6 +5864,67 @@ "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==", "dev": true }, + "node_modules/@typescript-eslint/eslint-plugin": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.62.0.tgz", + "integrity": "sha512-TiZzBSJja/LbhNPvk6yc0JrX9XqhQ0hdh6M2svYfsHGejaKFIAGd9MQ+ERIMzLGlN/kZoYIgdxFV0PuljTKXag==", + "dev": true, + "dependencies": { + "@eslint-community/regexpp": "^4.4.0", + "@typescript-eslint/scope-manager": "5.62.0", + "@typescript-eslint/type-utils": "5.62.0", + "@typescript-eslint/utils": "5.62.0", + "debug": "^4.3.4", + "graphemer": "^1.4.0", + "ignore": "^5.2.0", + "natural-compare-lite": "^1.4.0", + "semver": "^7.3.7", + "tsutils": "^3.21.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "@typescript-eslint/parser": "^5.0.0", + "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/parser": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.62.0.tgz", + "integrity": "sha512-VlJEV0fOQ7BExOsHYAGrgbEiZoi8D+Bl2+f6V2RrXerRSylnp+ZBHmPvaIa8cz0Ajx7WO7Z5RqfgYg7ED1nRhA==", + "dev": true, + "dependencies": { + "@typescript-eslint/scope-manager": "5.62.0", + "@typescript-eslint/types": "5.62.0", + "@typescript-eslint/typescript-estree": "5.62.0", + "debug": "^4.3.4" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, "node_modules/@typescript-eslint/scope-manager": { "version": "5.62.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.62.0.tgz", @@ -5908,54 +5969,6 @@ } } }, - "node_modules/@typescript-eslint/type-utils/node_modules/@typescript-eslint/utils": { - "version": "5.62.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.62.0.tgz", - "integrity": "sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==", - "dev": true, - "dependencies": { - "@eslint-community/eslint-utils": "^4.2.0", - "@types/json-schema": "^7.0.9", - "@types/semver": "^7.3.12", - "@typescript-eslint/scope-manager": "5.62.0", - "@typescript-eslint/types": "5.62.0", - "@typescript-eslint/typescript-estree": "5.62.0", - "eslint-scope": "^5.1.1", - "semver": "^7.3.7" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" - } - }, - "node_modules/@typescript-eslint/type-utils/node_modules/eslint-scope": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", - "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", - "dev": true, - "dependencies": { - "esrecurse": "^4.3.0", - "estraverse": "^4.1.1" - }, - "engines": { - "node": ">=8.0.0" - } - }, - "node_modules/@typescript-eslint/type-utils/node_modules/estraverse": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", - "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", - "dev": true, - "engines": { - "node": ">=4.0" - } - }, "node_modules/@typescript-eslint/types": { "version": "5.62.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.62.0.tgz", @@ -6025,6 +6038,54 @@ "node": ">=8" } }, + "node_modules/@typescript-eslint/utils": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.62.0.tgz", + "integrity": "sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==", + "dev": true, + "dependencies": { + "@eslint-community/eslint-utils": "^4.2.0", + "@types/json-schema": "^7.0.9", + "@types/semver": "^7.3.12", + "@typescript-eslint/scope-manager": "5.62.0", + "@typescript-eslint/types": "5.62.0", + "@typescript-eslint/typescript-estree": "5.62.0", + "eslint-scope": "^5.1.1", + "semver": "^7.3.7" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, + "node_modules/@typescript-eslint/utils/node_modules/eslint-scope": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", + "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", + "dev": true, + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^4.1.1" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@typescript-eslint/utils/node_modules/estraverse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", + "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, "node_modules/@typescript-eslint/visitor-keys": { "version": "5.62.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.62.0.tgz", @@ -6824,6 +6885,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-2.0.0.tgz", "integrity": "sha512-Ci/qENmwHnsYo9xKIcUJN5LeDKdJ6R1Z1j9V/J5wyq8nh/mYPEpIKJbBZXtZjG04HiK7zV/p6Vs9952MrMeUIw==", + "deprecated": "This package is no longer supported.", "dependencies": { "delegates": "^1.0.0", "readable-stream": "^3.6.0" @@ -7043,9 +7105,9 @@ } }, "node_modules/aws4": { - "version": "1.12.0", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.12.0.tgz", - "integrity": "sha512-NmWvPnx0F1SfrQbYwOi7OeaNGokp9XhzNioJ/CSBs8Qa4vxug81mhJEAVZwxXuBmYB5KDRfMq/F3RR0BIU7sWg==" + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.13.0.tgz", + "integrity": "sha512-3AungXC4I8kKsS9PuS4JH2nc+0bVY/mjgrephHTIi8fpEeGsTHBUJeosp0Wc1myYMElmD0B3Oc4XL/HVJ4PV2g==" }, "node_modules/axios": { "version": "0.21.4", @@ -7476,9 +7538,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001618", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001618.tgz", - "integrity": "sha512-p407+D1tIkDvsEAPS22lJxLQQaG8OTBEqo0KhzfABGk0TU4juBNDSfH0hyAp/HRyx+M8L17z/ltyhxh27FTfQg==", + "version": "1.0.30001620", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001620.tgz", + "integrity": "sha512-WJvYsOjd1/BYUY6SNGUosK9DUidBPDTnOARHp3fSmFO1ekdxaY6nKRttEVrfMmYi80ctS0kz1wiWmm14fVc3ew==", "dev": true, "funding": [ { @@ -7605,9 +7667,9 @@ } }, "node_modules/chart.js": { - "version": "4.4.2", - "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-4.4.2.tgz", - "integrity": "sha512-6GD7iKwFpP5kbSD4MeRRRlTnQvxfQREy36uEtm1hzHzcOqwWx0YEHuspuoNlslu+nciLIB7fjjsHkUv/FzFcOg==", + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-4.4.3.tgz", + "integrity": "sha512-qK1gkGSRYcJzqrrzdR6a+I0vQ4/R+SoODXyAjscQ/4mzuNzySaMCd+hyVxitSY1+L2fjPD1Gbn+ibNqRmwQeLw==", "dev": true, "dependencies": { "@kurkle/color": "^0.3.0" @@ -9371,9 +9433,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "node_modules/electron-to-chromium": { - "version": "1.4.769", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.769.tgz", - "integrity": "sha512-bZu7p623NEA2rHTc9K1vykl57ektSPQYFFqQir8BOYf6EKOB+yIsbFB9Kpm7Cgt6tsLr9sRkqfqSZUw7LP1XxQ==", + "version": "1.4.776", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.776.tgz", + "integrity": "sha512-s694bi3+gUzlliqxjPHpa9NRTlhzTgB34aan+pVKZmOTGy2xoZXl+8E1B8i5p5rtev3PKMK/H4asgNejC+YHNg==", "dev": true }, "node_modules/emittery": { @@ -9569,9 +9631,9 @@ } }, "node_modules/es-module-lexer": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.5.2.tgz", - "integrity": "sha512-l60ETUTmLqbVbVHv1J4/qj+M8nq7AwMzEcg3kmJDt9dCNrTk+yHcYFf/Kw75pMDwd9mPcIGCG5LcS20SxYRzFA==" + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.5.3.tgz", + "integrity": "sha512-i1gCgmR9dCl6Vil6UKPI/trA69s08g/syhiDK9TG0Nf1RJjjFI+AzoWW7sPufzkgYAn861skuCwJa0pIIHYxvg==" }, "node_modules/es-object-atoms": { "version": "1.0.0", @@ -9773,115 +9835,6 @@ "eslint": "^8.0.0" } }, - "node_modules/eslint-plugin-adonis/node_modules/@typescript-eslint/eslint-plugin": { - "version": "5.62.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.62.0.tgz", - "integrity": "sha512-TiZzBSJja/LbhNPvk6yc0JrX9XqhQ0hdh6M2svYfsHGejaKFIAGd9MQ+ERIMzLGlN/kZoYIgdxFV0PuljTKXag==", - "dev": true, - "dependencies": { - "@eslint-community/regexpp": "^4.4.0", - "@typescript-eslint/scope-manager": "5.62.0", - "@typescript-eslint/type-utils": "5.62.0", - "@typescript-eslint/utils": "5.62.0", - "debug": "^4.3.4", - "graphemer": "^1.4.0", - "ignore": "^5.2.0", - "natural-compare-lite": "^1.4.0", - "semver": "^7.3.7", - "tsutils": "^3.21.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "@typescript-eslint/parser": "^5.0.0", - "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, - "node_modules/eslint-plugin-adonis/node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/utils": { - "version": "5.62.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.62.0.tgz", - "integrity": "sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==", - "dev": true, - "dependencies": { - "@eslint-community/eslint-utils": "^4.2.0", - "@types/json-schema": "^7.0.9", - "@types/semver": "^7.3.12", - "@typescript-eslint/scope-manager": "5.62.0", - "@typescript-eslint/types": "5.62.0", - "@typescript-eslint/typescript-estree": "5.62.0", - "eslint-scope": "^5.1.1", - "semver": "^7.3.7" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" - } - }, - "node_modules/eslint-plugin-adonis/node_modules/@typescript-eslint/parser": { - "version": "5.62.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.62.0.tgz", - "integrity": "sha512-VlJEV0fOQ7BExOsHYAGrgbEiZoi8D+Bl2+f6V2RrXerRSylnp+ZBHmPvaIa8cz0Ajx7WO7Z5RqfgYg7ED1nRhA==", - "dev": true, - "dependencies": { - "@typescript-eslint/scope-manager": "5.62.0", - "@typescript-eslint/types": "5.62.0", - "@typescript-eslint/typescript-estree": "5.62.0", - "debug": "^4.3.4" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, - "node_modules/eslint-plugin-adonis/node_modules/eslint-scope": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", - "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", - "dev": true, - "dependencies": { - "esrecurse": "^4.3.0", - "estraverse": "^4.1.1" - }, - "engines": { - "node": ">=8.0.0" - } - }, - "node_modules/eslint-plugin-adonis/node_modules/estraverse": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", - "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", - "dev": true, - "engines": { - "node": ">=4.0" - } - }, "node_modules/eslint-plugin-prettier": { "version": "5.1.3", "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.1.3.tgz", @@ -10806,6 +10759,7 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.2.tgz", "integrity": "sha512-+5J6MS/5XksCuXq++uFRsnUd7Ovu1XenbeuIuNRJxYWjgQbPuFhT14lAvsWfqfAmnwluf1OwMjz39HjfLPci0Q==", + "deprecated": "This package is no longer supported.", "dependencies": { "aproba": "^1.0.3 || ^2.0.0", "color-support": "^1.1.2", @@ -13551,6 +13505,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.1.tgz", "integrity": "sha512-AqZtDUWOMKs1G/8lwylVjrdYgqA4d9nu8hc+0gzRxlDb1I10+FHBGMXs6aiQHFdCUUlqH99MUMuLfzWDNDtfxw==", + "deprecated": "This package is no longer supported.", "dependencies": { "are-we-there-yet": "^2.0.0", "console-control-strings": "^1.1.0", @@ -15490,12 +15445,12 @@ } }, "node_modules/redis": { - "version": "4.6.13", - "resolved": "https://registry.npmjs.org/redis/-/redis-4.6.13.tgz", - "integrity": "sha512-MHgkS4B+sPjCXpf+HfdetBwbRz6vCtsceTmw1pHNYJAsYxrfpOP6dz+piJWGos8wqG7qb3vj/Rrc5qOlmInUuA==", + "version": "4.6.14", + "resolved": "https://registry.npmjs.org/redis/-/redis-4.6.14.tgz", + "integrity": "sha512-GrNg/e33HtsQwNXL7kJT+iNFPSwE1IPmd7wzV3j4f2z0EYxZfZE7FVTmUysgAtqQQtg5NXF5SNLR9OdO/UHOfw==", "dependencies": { "@redis/bloom": "1.2.0", - "@redis/client": "1.5.14", + "@redis/client": "1.5.16", "@redis/graph": "1.1.1", "@redis/json": "1.0.6", "@redis/search": "1.1.6", @@ -15940,9 +15895,9 @@ } }, "node_modules/saxon-js/node_modules/axios": { - "version": "1.6.8", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", - "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.1.tgz", + "integrity": "sha512-+LV37nQcd1EpFalkXksWNBiA17NZ5m5/WspmHGmZmdx1qBOg/VNq/c4eRJiA9VQQHBOs+N0ZhhdU10h2TyNK7Q==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -18813,9 +18768,9 @@ } }, "node_modules/xslt3/node_modules/axios": { - "version": "1.6.8", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", - "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.1.tgz", + "integrity": "sha512-+LV37nQcd1EpFalkXksWNBiA17NZ5m5/WspmHGmZmdx1qBOg/VNq/c4eRJiA9VQQHBOs+N0ZhhdU10h2TyNK7Q==", "dev": true, "dependencies": { "follow-redirects": "^1.15.6", diff --git a/providers/validator_provider.ts b/providers/validator_provider.ts index 5347c57..cae8083 100644 --- a/providers/validator_provider.ts +++ b/providers/validator_provider.ts @@ -1,3 +1,4 @@ +// @ts-nocheck import type { ApplicationService } from '@adonisjs/core/types'; import { validator } from '@adonisjs/validator'; import { Request } from '@adonisjs/core/http'; diff --git a/start/kernel.ts b/start/kernel.ts index 47d42e3..dc0df9e 100644 --- a/start/kernel.ts +++ b/start/kernel.ts @@ -9,12 +9,10 @@ | */ -import server from '@adonisjs/core/services/server' -import router from '@adonisjs/core/services/router' +import server from '@adonisjs/core/services/server'; +import router from '@adonisjs/core/services/router'; -server.errorHandler( - () => import('#exceptions/handler') -) +server.errorHandler(() => import('#exceptions/handler')); /** * The server middleware stack runs middleware on all the HTTP @@ -22,33 +20,33 @@ server.errorHandler( * the request URL. */ server.use([ - () => import('#middleware/container_bindings_middleware'), - () => import('@adonisjs/static/static_middleware'), - // () => import('@adonisjs/cors/cors_middleware'), - () => import('@adonisjs/inertia/inertia_middleware'), -]) + () => import('#middleware/container_bindings_middleware'), + () => import('@adonisjs/static/static_middleware'), + // () => import('@adonisjs/cors/cors_middleware'), + () => import('@adonisjs/inertia/inertia_middleware'), +]); /** * The router middleware stack runs middleware on all the HTTP * requests with a registered route. */ router.use([ - () => import('@adonisjs/core/bodyparser_middleware'), - () => import('@adonisjs/session/session_middleware'), - () => import('@adonisjs/shield/shield_middleware'), - // () => import('@adonisjs/inertia/inertia_middleware'), - () => import('@adonisjs/auth/initialize_auth_middleware'), - () => import('#middleware/stardust_middleware'), - // () => import('@eidellev/adonis-stardust/build/middleware/Stardust.js'), -]) + () => import('@adonisjs/core/bodyparser_middleware'), + () => import('@adonisjs/session/session_middleware'), + () => import('@adonisjs/shield/shield_middleware'), + // () => import('@adonisjs/inertia/inertia_middleware'), + () => import('@adonisjs/auth/initialize_auth_middleware'), + () => import('#middleware/stardust_middleware'), + // () => import('@eidellev/adonis-stardust/build/middleware/Stardust.js'), +]); /** * Named middleware collection must be explicitly assigned to * the routes or the routes group. */ export const middleware = router.named({ - guest: () => import('#middleware/guest_middleware'), - auth: () => import('#middleware/auth_middleware'), - is: () => import('#middleware/role_middleware'), - can: () => import('#middleware/can_middleware'), -}) + guest: () => import('#middleware/guest_middleware'), + auth: () => import('#middleware/auth_middleware'), + is: () => import('#middleware/role_middleware'), + can: () => import('#middleware/can_middleware'), +}); diff --git a/start/validator_old.ts b/start/validator_old.ts deleted file mode 100644 index 6b0aa40..0000000 --- a/start/validator_old.ts +++ /dev/null @@ -1,140 +0,0 @@ -/* -|-------------------------------------------------------------------------- -| Preloaded File -|-------------------------------------------------------------------------- -| -| Any code written inside this file will be executed during the application -| boot. -https://issuehunt.io/r/adonisjs/validator/issues/84 -| -*/ -// import { string } from '@ioc:Adonis/Core/Helpers'; -import { validator } from '@adonisjs/validator'; - -validator.rule('uniqueArray', (dataArray, [field], { pointer, arrayExpressionPointer, errorReporter }) => { - const array = dataArray; //validator.helpers.getFieldValue(data, field, tip); - - if (!Array.isArray(array)) { - throw new Error(`The ${pointer} must be an array.`); - } - - const uniqueValues = new Set(); - for (let i = 0; i < array.length; i++) { - const item = array[i]; - const attributeValue = item[field]; // Extract the attribute value for uniqueness check - - if (uniqueValues.has(attributeValue)) { - // throw new Error(`The ${field} array contains duplicate values for the ${field} attribute.`) - errorReporter.report( - pointer, - 'uniqueArray', // Keep an eye on this - `The ${pointer} array contains duplicate values for the ${field} attribute.`, - arrayExpressionPointer, - { field, array: pointer }, - ); - return; - } - - uniqueValues.add(attributeValue); - } -}); - -validator.rule( - 'translatedLanguage', - (value, [mainLanguageField, typeField], { root, tip, pointer, arrayExpressionPointer, errorReporter }) => { - if (typeof value !== 'string') { - return; - } - // const fieldValue = validator. getValue(data, field) - // this should return the "category_id" value present in "root", but i got undefined - const mainLanguage = validator.helpers.getFieldValue(mainLanguageField, root, tip); - const type = validator.helpers.getFieldValue(typeField, root, tip); - - if (type && type === 'Translated') { - if (value === mainLanguage) { - errorReporter.report( - pointer, - 'translatedLanguage', // Keep an eye on this - 'translatedLanguage validation failed', - arrayExpressionPointer, - { mainLanguage }, - ); - } - } - - // if (value !== string.camelCase(value)) { - // options.errorReporter.report( - // options.pointer, - // 'camelCase', - // 'camelCase validation failed', - // options.arrayExpressionPointer - // ); - // } - }, -); - -validator.rule('fileExtension', async (value, [extensions], { pointer, arrayExpressionPointer, errorReporter }) => { - const allowedExtensions = extensions.map((ext: string) => ext.toLowerCase()); - const uploadedFile = value; - - if (!uploadedFile) { - return; - } - - const extension = uploadedFile.extname.toLowerCase().replace('.', ''); - - if (!allowedExtensions.includes(extension)) { - errorReporter.report( - pointer, - 'fileExtension', - 'Invalid file extension. Only {{ extensions }} files are allowed.', - arrayExpressionPointer, - ); - } -}); - -// validator.rule( -// 'clamavScan', -// (value, [field], { root, tip, pointer, arrayExpressionPointer, errorReporter }) => { -// if (typeof value !== 'object') { -// return; -// } -// const uploadedFile = validator.helpers.getFieldValue(field, root, tip); -// // return rules.file({}, [ -// // async (file) => { -// // const clamdhost = process.env['CLAMD_HOST'] ?? '127.0.0.1'; -// // const clamdport = Number(process.env['CLAMD_PORT']) ?? '3310'; -// // try { -// // var isInfected = await scanFileForViruses(file.tmpPath, clamdhost, clamdport); -// // } catch (error) { -// // throw new Error(`${pointer}: ${error.message}`); -// // } -// // }, -// // ]); -// }); - -// async function scanFileForViruses(filePath, host, port): Promise { -// // const clamscan = await (new ClamScan().init()); -// const opts: ClamScan.Options = { -// preference: 'clamdscan', -// clamdscan: { -// active: true, -// host, -// port, -// multiscan: true, -// }, -// }; -// const clamscan = await new ClamScan().init(opts); - -// return new Promise((resolve, reject) => { -// clamscan.isInfected(filePath, (err, file, isInfected: boolean) => { -// if (err) { -// reject(err); -// } else if (isInfected) { -// reject(new Error(`File ${file} is infected!`)); -// } else { -// resolve(isInfected); -// } -// }); -// }); -// }