diff --git a/.env.example b/.env.example index ece4861..c2bceaa 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ -DATABASE_URL="file:../data/app.db" -JWT_SECRET="replace-with-a-long-random-string" -SEED_ADMIN_NAME="Super Admin" -SEED_ADMIN_PHONE="0715127342" -SEED_ADMIN_PASSWORD="change-this-password" -PORT=3000 +DATABASE_URL="file:../data/app.db" +JWT_SECRET="replace-with-a-long-random-string" +SEED_ADMIN_NAME="Super Admin" +SEED_ADMIN_PHONE="0715127342" +SEED_ADMIN_PASSWORD="change-this-password" +PORT=3000 diff --git a/.gitignore b/.gitignore index e36ba54..854d0ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -node_modules/ -.env -data/*.db -data/*.db-journal +node_modules/ +.env +data/*.db +data/*.db-journal diff --git a/package-lock.json b/package-lock.json index 2bdbd67..9cd9302 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,1584 +1,1584 @@ -{ - "name": "dealer-network-api", - "version": "1.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "dealer-network-api", - "version": "1.0.0", - "hasInstallScript": true, - "dependencies": { - "@prisma/client": "^6.16.2", - "axios": "^1.12.2", - "bcryptjs": "^3.0.3", - "cors": "^2.8.5", - "dotenv": "^16.6.1", - "express": "^4.21.2", - "jsonwebtoken": "^9.0.2", - "prisma": "^6.16.2" - }, - "devDependencies": {} - }, - "node_modules/@prisma/client": { - "version": "6.19.3", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-6.19.3.tgz", - "integrity": "sha512-mKq3jQFhjvko5LTJFHGilsuQs+W+T3Gm451NzuTDGQxwCzwXHYnIu2zGkRoW+Exq3Rob7yp2MfzSrdIiZVhrBg==", - "hasInstallScript": true, - "license": "Apache-2.0", - "engines": { - "node": ">=18.18" - }, - "peerDependencies": { - "prisma": "*", - "typescript": ">=5.1.0" - }, - "peerDependenciesMeta": { - "prisma": { - "optional": true - }, - "typescript": { - "optional": true - } - } - }, - "node_modules/@prisma/config": { - "version": "6.19.3", - "resolved": "https://registry.npmjs.org/@prisma/config/-/config-6.19.3.tgz", - "integrity": "sha512-CBPT44BjlQxEt8kiMEauji2WHTDoVBOKl7UlewXmUgBPnr/oPRZC3psci5chJnYmH0ivEIog2OU9PGWoki3DLQ==", - "license": "Apache-2.0", - "dependencies": { - "c12": "3.1.0", - "deepmerge-ts": "7.1.5", - "effect": "3.21.0", - "empathic": "2.0.0" - } - }, - "node_modules/@prisma/debug": { - "version": "6.19.3", - "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-6.19.3.tgz", - "integrity": "sha512-ljkJ+SgpXNktLG0Q/n4JGYCkKf0f8oYLyjImS2I8e2q2WCfdRRtWER062ZV/ixaNP2M2VKlWXVJiGzZaUgbKZw==", - "license": "Apache-2.0" - }, - "node_modules/@prisma/engines": { - "version": "6.19.3", - "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-6.19.3.tgz", - "integrity": "sha512-RSYxtlYFl5pJ8ZePgMv0lZ9IzVCOdTPOegrs2qcbAEFrBI1G33h6wyC9kjQvo0DnYEhEVY0X4LsuFHXLKQk88g==", - "hasInstallScript": true, - "license": "Apache-2.0", - "dependencies": { - "@prisma/debug": "6.19.3", - "@prisma/engines-version": "7.1.1-3.c2990dca591cba766e3b7ef5d9e8a84796e47ab7", - "@prisma/fetch-engine": "6.19.3", - "@prisma/get-platform": "6.19.3" - } - }, - "node_modules/@prisma/engines-version": { - "version": "7.1.1-3.c2990dca591cba766e3b7ef5d9e8a84796e47ab7", - "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-7.1.1-3.c2990dca591cba766e3b7ef5d9e8a84796e47ab7.tgz", - "integrity": "sha512-03bgb1VD5gvuumNf+7fVGBzfpJPjmqV423l/WxsWk2cNQ42JD0/SsFBPhN6z8iAvdHs07/7ei77SKu7aZfq8bA==", - "license": "Apache-2.0" - }, - "node_modules/@prisma/fetch-engine": { - "version": "6.19.3", - "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-6.19.3.tgz", - "integrity": "sha512-tKtl/qco9Nt7LU5iKhpultD8O4vMCZcU2CHjNTnRrL1QvSUr5W/GcyFPjNL87GtRrwBc7ubXXD9xy4EvLvt8JA==", - "license": "Apache-2.0", - "dependencies": { - "@prisma/debug": "6.19.3", - "@prisma/engines-version": "7.1.1-3.c2990dca591cba766e3b7ef5d9e8a84796e47ab7", - "@prisma/get-platform": "6.19.3" - } - }, - "node_modules/@prisma/get-platform": { - "version": "6.19.3", - "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-6.19.3.tgz", - "integrity": "sha512-xFj1VcJ1N3MKooOQAGO0W5tsd0W2QzIvW7DD7c/8H14Zmp4jseeWAITm+w2LLoLrlhoHdPPh0NMZ8mfL6puoHA==", - "license": "Apache-2.0", - "dependencies": { - "@prisma/debug": "6.19.3" - } - }, - "node_modules/@standard-schema/spec": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz", - "integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==", - "license": "MIT" - }, - "node_modules/accepts": { - "version": "1.3.8", - "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", - "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", - "license": "MIT", - "dependencies": { - "mime-types": "~2.1.34", - "negotiator": "0.6.3" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/agent-base": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", - "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", - "license": "MIT", - "dependencies": { - "debug": "4" - }, - "engines": { - "node": ">= 6.0.0" - } - }, - "node_modules/agent-base/node_modules/debug": { - "version": "4.4.3", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", - "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", - "license": "MIT", - "dependencies": { - "ms": "^2.1.3" - }, - "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } - } - }, - "node_modules/agent-base/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "license": "MIT" - }, - "node_modules/array-flatten": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", - "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", - "license": "MIT" - }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "license": "MIT" - }, - "node_modules/axios": { - "version": "1.20.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.20.0.tgz", - "integrity": "sha512-r8aOh8j9cGKpgQAqpzrUHnSIc6a59Y3Xf/cv8sy1DrHCkZHzQGEuoq1tARk6qSyDdtQGSDgpb9kFlruzPvrgwg==", - "license": "MIT", - "dependencies": { - "follow-redirects": "^1.16.0", - "form-data": "^4.0.6", - "https-proxy-agent": "^5.0.1", - "proxy-from-env": "^2.1.0" - } - }, - "node_modules/bcryptjs": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-3.0.3.tgz", - "integrity": "sha512-GlF5wPWnSa/X5LKM1o0wz0suXIINz1iHRLvTS+sLyi7XPbe5ycmYI3DlZqVGZZtDgl4DmasFg7gOB3JYbphV5g==", - "license": "BSD-3-Clause", - "bin": { - "bcrypt": "bin/bcrypt" - } - }, - "node_modules/body-parser": { - "version": "1.20.8", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.8.tgz", - "integrity": "sha512-JNcyFQ64OiijEkPzUBTCe+hyPXUD/3LEldGQ6iF5LR1w00mx9o7xtDWHXBY2iItjdCFGoilOLNQbH943ut7pHA==", - "license": "MIT", - "dependencies": { - "bytes": "~3.1.2", - "content-type": "~1.0.5", - "debug": "2.6.9", - "depd": "2.0.0", - "destroy": "~1.2.0", - "http-errors": "~2.0.1", - "iconv-lite": "~0.4.24", - "on-finished": "~2.4.1", - "qs": "~6.16.0", - "raw-body": "~2.5.3", - "type-is": "~1.6.18", - "unpipe": "~1.0.0" - }, - "engines": { - "node": ">= 0.8", - "npm": "1.2.8000 || >= 1.4.16" - } - }, - "node_modules/buffer-equal-constant-time": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", - "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==", - "license": "BSD-3-Clause" - }, - "node_modules/bytes": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", - "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/c12": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/c12/-/c12-3.1.0.tgz", - "integrity": "sha512-uWoS8OU1MEIsOv8p/5a82c3H31LsWVR5qiyXVfBNOzfffjUWtPnhAb4BYI2uG2HfGmZmFjCtui5XNWaps+iFuw==", - "license": "MIT", - "dependencies": { - "chokidar": "^4.0.3", - "confbox": "^0.2.2", - "defu": "^6.1.4", - "dotenv": "^16.6.1", - "exsolve": "^1.0.7", - "giget": "^2.0.0", - "jiti": "^2.4.2", - "ohash": "^2.0.11", - "pathe": "^2.0.3", - "perfect-debounce": "^1.0.0", - "pkg-types": "^2.2.0", - "rc9": "^2.1.2" - }, - "peerDependencies": { - "magicast": "^0.3.5" - }, - "peerDependenciesMeta": { - "magicast": { - "optional": true - } - } - }, - "node_modules/call-bind-apply-helpers": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", - "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "function-bind": "^1.1.2" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/call-bound": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", - "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", - "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.2", - "get-intrinsic": "^1.3.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/chokidar": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz", - "integrity": "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==", - "license": "MIT", - "dependencies": { - "readdirp": "^4.0.1" - }, - "engines": { - "node": ">= 14.16.0" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/citty": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/citty/-/citty-0.1.6.tgz", - "integrity": "sha512-tskPPKEs8D2KPafUypv2gxwJP8h/OaJmC82QQGGDQcHvXX43xF2VDACcJVmZ0EuSxkpO9Kc4MlrA3q0+FG58AQ==", - "license": "MIT", - "dependencies": { - "consola": "^3.2.3" - } - }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "license": "MIT", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/confbox": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/confbox/-/confbox-0.2.4.tgz", - "integrity": "sha512-ysOGlgTFbN2/Y6Cg3Iye8YKulHw+R2fNXHrgSmXISQdMnomY6eNDprVdW9R5xBguEqI954+S6709UyiO7B+6OQ==", - "license": "MIT" - }, - "node_modules/consola": { - "version": "3.4.2", - "resolved": "https://registry.npmjs.org/consola/-/consola-3.4.2.tgz", - "integrity": "sha512-5IKcdX0nnYavi6G7TtOhwkYzyjfJlatbjMjuLSfE2kYT5pMDOilZ4OvMhi637CcDICTmz3wARPoyhqyX1Y+XvA==", - "license": "MIT", - "engines": { - "node": "^14.18.0 || >=16.10.0" - } - }, - "node_modules/content-disposition": { - "version": "0.5.4", - "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", - "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", - "license": "MIT", - "dependencies": { - "safe-buffer": "5.2.1" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/content-type": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", - "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/cookie": { - "version": "0.7.2", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", - "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/cookie-signature": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz", - "integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==", - "license": "MIT" - }, - "node_modules/cors": { - "version": "2.8.6", - "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", - "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==", - "license": "MIT", - "dependencies": { - "object-assign": "^4", - "vary": "^1" - }, - "engines": { - "node": ">= 0.10" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "license": "MIT", - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/deepmerge-ts": { - "version": "8.0.2", - "resolved": "https://registry.npmjs.org/deepmerge-ts/-/deepmerge-ts-8.0.2.tgz", - "integrity": "sha512-uqbvqLUMrc6p0MO+WBRtTxY55hmyh94WRwI5a++PZe54X+bfVh59FSN7uWCBCW1CCVjzjnrwzfI8zidE2obMMw==", - "funding": [ - { - "type": "ko-fi", - "url": "https://ko-fi.com/rebeccastevens" - }, - { - "type": "tidelift", - "url": "https://tidelift.com/funding/github/npm/deepmerge-ts" - } - ], - "license": "BSD-3-Clause", - "engines": { - "node": ">=16.9.0" - } - }, - "node_modules/defu": { - "version": "6.1.7", - "resolved": "https://registry.npmjs.org/defu/-/defu-6.1.7.tgz", - "integrity": "sha512-7z22QmUWiQ/2d0KkdYmANbRUVABpZ9SNYyH5vx6PZ+nE5bcC0l7uFvEfHlyld/HcGBFTL536ClDt3DEcSlEJAQ==", - "license": "MIT" - }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "license": "MIT", - "engines": { - "node": ">=0.4.0" - } - }, - "node_modules/depd": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", - "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/destr": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/destr/-/destr-2.0.5.tgz", - "integrity": "sha512-ugFTXCtDZunbzasqBxrK93Ik/DRYsO6S/fedkWEMKqt04xZ4csmnmwGDBAb07QWNaGMAmnTIemsYZCksjATwsA==", - "license": "MIT" - }, - "node_modules/destroy": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", - "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", - "license": "MIT", - "engines": { - "node": ">= 0.8", - "npm": "1.2.8000 || >= 1.4.16" - } - }, - "node_modules/dotenv": { - "version": "16.6.1", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.6.1.tgz", - "integrity": "sha512-uBq4egWHTcTt33a72vpSG0z3HnPuIl6NqYcTrKEg2azoEyl2hpW0zqlxysq2pK9HlDIHyHyakeYaYnSAwd8bow==", - "license": "BSD-2-Clause", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://dotenvx.com" - } - }, - "node_modules/dunder-proto": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", - "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", - "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.1", - "es-errors": "^1.3.0", - "gopd": "^1.2.0" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/ecdsa-sig-formatter": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", - "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", - "license": "Apache-2.0", - "dependencies": { - "safe-buffer": "^5.0.1" - } - }, - "node_modules/ee-first": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", - "license": "MIT" - }, - "node_modules/effect": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/effect/-/effect-3.21.0.tgz", - "integrity": "sha512-PPN80qRokCd1f015IANNhrwOnLO7GrrMQfk4/lnZRE/8j7UPWrNNjPV0uBrZutI/nHzernbW+J0hdqQysHiSnQ==", - "license": "MIT", - "dependencies": { - "@standard-schema/spec": "^1.0.0", - "fast-check": "^3.23.1" - } - }, - "node_modules/empathic": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/empathic/-/empathic-2.0.0.tgz", - "integrity": "sha512-i6UzDscO/XfAcNYD75CfICkmfLedpyPDdozrLMmQc5ORaQcdMoc21OnlEylMIqI7U8eniKrPMxxtj8k0vhmJhA==", - "license": "MIT", - "engines": { - "node": ">=14" - } - }, - "node_modules/encodeurl": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", - "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/es-define-property": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", - "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-errors": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", - "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-object-atoms": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz", - "integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-set-tostringtag": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", - "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.6", - "has-tostringtag": "^1.0.2", - "hasown": "^2.0.2" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/escape-html": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", - "license": "MIT" - }, - "node_modules/etag": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", - "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/express": { - "version": "4.22.3", - "resolved": "https://registry.npmjs.org/express/-/express-4.22.3.tgz", - "integrity": "sha512-Bdcs4+3qlpVlx2NRn6fgX2Ue2/gGRaPeawebgclM0ERSCqDpA+owF1fdPwjJUTAJWMTuAaxjDf+hzb0/4eKvvw==", - "license": "MIT", - "dependencies": { - "accepts": "~1.3.8", - "array-flatten": "1.1.1", - "body-parser": "~1.20.5", - "content-disposition": "~0.5.4", - "content-type": "~1.0.4", - "cookie": "~0.7.1", - "cookie-signature": "~1.0.6", - "debug": "2.6.9", - "depd": "2.0.0", - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "finalhandler": "~1.3.1", - "fresh": "~0.5.2", - "http-errors": "~2.0.0", - "merge-descriptors": "1.0.3", - "methods": "~1.1.2", - "on-finished": "~2.4.1", - "parseurl": "~1.3.3", - "path-to-regexp": "~0.1.13", - "proxy-addr": "~2.0.7", - "qs": "~6.16.0", - "range-parser": "~1.2.1", - "safe-buffer": "5.2.1", - "send": "~0.19.0", - "serve-static": "~1.16.2", - "setprototypeof": "1.2.0", - "statuses": "~2.0.1", - "type-is": "~1.6.18", - "utils-merge": "1.0.1", - "vary": "~1.1.2" - }, - "engines": { - "node": ">= 0.10.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/exsolve": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/exsolve/-/exsolve-1.1.1.tgz", - "integrity": "sha512-9U/jZUgjnSGyntRr6y5Muu1MJcwFl6kPu7k8qLF0IMNfLqvw0NZ4nnVDq0RVoZ0RvCyumib4Ez3KYrVfilrw+g==", - "license": "MIT" - }, - "node_modules/fast-check": { - "version": "3.23.2", - "resolved": "https://registry.npmjs.org/fast-check/-/fast-check-3.23.2.tgz", - "integrity": "sha512-h5+1OzzfCC3Ef7VbtKdcv7zsstUQwUDlYpUTvjeUsJAssPgLn7QzbboPtL5ro04Mq0rPOsMzl7q5hIbRs2wD1A==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/dubzzz" - }, - { - "type": "opencollective", - "url": "https://opencollective.com/fast-check" - } - ], - "license": "MIT", - "dependencies": { - "pure-rand": "^6.1.0" - }, - "engines": { - "node": ">=8.0.0" - } - }, - "node_modules/finalhandler": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz", - "integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==", - "license": "MIT", - "dependencies": { - "debug": "2.6.9", - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "on-finished": "~2.4.1", - "parseurl": "~1.3.3", - "statuses": "~2.0.2", - "unpipe": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/follow-redirects": { - "version": "1.16.0", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.0.tgz", - "integrity": "sha512-y5rN/uOsadFT/JfYwhxRS5R7Qce+g3zG97+JrtFZlC9klX/W5hD7iiLzScI4nZqUS7DNUdhPgw4xI8W2LuXlUw==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "license": "MIT", - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, - "node_modules/form-data": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.6.tgz", - "integrity": "sha512-vKatAh4SlVfgbv+YtmhiRjhEMJsYpsG1Y2rMQtR+SVSbytsSD1YGzDIcrAJmdFec88u/+VoGmxnl+80gL1tRCQ==", - "license": "MIT", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "es-set-tostringtag": "^2.1.0", - "hasown": "^2.0.4", - "mime-types": "^2.1.35" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/forwarded": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", - "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/fresh": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", - "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/function-bind": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", - "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/get-intrinsic": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", - "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", - "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.2", - "es-define-property": "^1.0.1", - "es-errors": "^1.3.0", - "es-object-atoms": "^1.1.1", - "function-bind": "^1.1.2", - "get-proto": "^1.0.1", - "gopd": "^1.2.0", - "has-symbols": "^1.1.0", - "hasown": "^2.0.2", - "math-intrinsics": "^1.1.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/get-proto": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", - "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", - "license": "MIT", - "dependencies": { - "dunder-proto": "^1.0.1", - "es-object-atoms": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/giget": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/giget/-/giget-2.0.0.tgz", - "integrity": "sha512-L5bGsVkxJbJgdnwyuheIunkGatUF/zssUoxxjACCseZYAVbaqdh9Tsmmlkl8vYan09H7sbvKt4pS8GqKLBrEzA==", - "license": "MIT", - "dependencies": { - "citty": "^0.1.6", - "consola": "^3.4.0", - "defu": "^6.1.4", - "node-fetch-native": "^1.6.6", - "nypm": "^0.6.0", - "pathe": "^2.0.3" - }, - "bin": { - "giget": "dist/cli.mjs" - } - }, - "node_modules/gopd": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", - "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-symbols": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", - "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-tostringtag": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", - "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", - "license": "MIT", - "dependencies": { - "has-symbols": "^1.0.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/hasown": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", - "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", - "license": "MIT", - "dependencies": { - "function-bind": "^1.1.2" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/http-errors": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", - "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", - "license": "MIT", - "dependencies": { - "depd": "~2.0.0", - "inherits": "~2.0.4", - "setprototypeof": "~1.2.0", - "statuses": "~2.0.2", - "toidentifier": "~1.0.1" - }, - "engines": { - "node": ">= 0.8" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/https-proxy-agent": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", - "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", - "license": "MIT", - "dependencies": { - "agent-base": "6", - "debug": "4" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/https-proxy-agent/node_modules/debug": { - "version": "4.4.3", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", - "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", - "license": "MIT", - "dependencies": { - "ms": "^2.1.3" - }, - "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } - } - }, - "node_modules/https-proxy-agent/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "license": "MIT" - }, - "node_modules/iconv-lite": { - "version": "0.4.24", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", - "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", - "license": "MIT", - "dependencies": { - "safer-buffer": ">= 2.1.2 < 3" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "license": "ISC" - }, - "node_modules/ipaddr.js": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", - "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", - "license": "MIT", - "engines": { - "node": ">= 0.10" - } - }, - "node_modules/jiti": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.7.0.tgz", - "integrity": "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ==", - "license": "MIT", - "bin": { - "jiti": "lib/jiti-cli.mjs" - } - }, - "node_modules/jsonwebtoken": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.3.tgz", - "integrity": "sha512-MT/xP0CrubFRNLNKvxJ2BYfy53Zkm++5bX9dtuPbqAeQpTVe0MQTFhao8+Cp//EmJp244xt6Drw/GVEGCUj40g==", - "license": "MIT", - "dependencies": { - "jws": "^4.0.1", - "lodash.includes": "^4.3.0", - "lodash.isboolean": "^3.0.3", - "lodash.isinteger": "^4.0.4", - "lodash.isnumber": "^3.0.3", - "lodash.isplainobject": "^4.0.6", - "lodash.isstring": "^4.0.1", - "lodash.once": "^4.0.0", - "ms": "^2.1.1", - "semver": "^7.5.4" - }, - "engines": { - "node": ">=12", - "npm": ">=6" - } - }, - "node_modules/jsonwebtoken/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "license": "MIT" - }, - "node_modules/jwa": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz", - "integrity": "sha512-hRF04fqJIP8Abbkq5NKGN0Bbr3JxlQ+qhZufXVr0DvujKy93ZCbXZMHDL4EOtodSbCWxOqR8MS1tXA5hwqCXDg==", - "license": "MIT", - "dependencies": { - "buffer-equal-constant-time": "^1.0.1", - "ecdsa-sig-formatter": "1.0.11", - "safe-buffer": "^5.0.1" - } - }, - "node_modules/jws": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz", - "integrity": "sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==", - "license": "MIT", - "dependencies": { - "jwa": "^2.0.1", - "safe-buffer": "^5.0.1" - } - }, - "node_modules/lodash.includes": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", - "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==", - "license": "MIT" - }, - "node_modules/lodash.isboolean": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", - "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==", - "license": "MIT" - }, - "node_modules/lodash.isinteger": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", - "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==", - "license": "MIT" - }, - "node_modules/lodash.isnumber": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", - "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==", - "license": "MIT" - }, - "node_modules/lodash.isplainobject": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", - "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==", - "license": "MIT" - }, - "node_modules/lodash.isstring": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", - "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==", - "license": "MIT" - }, - "node_modules/lodash.once": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", - "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==", - "license": "MIT" - }, - "node_modules/math-intrinsics": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", - "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/media-typer": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/merge-descriptors": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", - "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/methods": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", - "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", - "license": "MIT", - "bin": { - "mime": "cli.js" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "license": "MIT", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "license": "MIT" - }, - "node_modules/negotiator": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", - "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/node-fetch-native": { - "version": "1.6.7", - "resolved": "https://registry.npmjs.org/node-fetch-native/-/node-fetch-native-1.6.7.tgz", - "integrity": "sha512-g9yhqoedzIUm0nTnTqAQvueMPVOuIY16bqgAJJC8XOOubYFNwz6IER9qs0Gq2Xd0+CecCKFjtdDTMA4u4xG06Q==", - "license": "MIT" - }, - "node_modules/nypm": { - "version": "0.6.10", - "resolved": "https://registry.npmjs.org/nypm/-/nypm-0.6.10.tgz", - "integrity": "sha512-W72Hrj1petq+b3Hk2aAC+9zswetlIFTnDW4s5djseZh2nYqBbyQLOtj472HwcbcWykPBUW1WpWpjOd4nK6gMRw==", - "license": "MIT", - "dependencies": { - "citty": "^0.2.2", - "pathe": "^2.0.3", - "tinyexec": "^1.3.1" - }, - "bin": { - "nypm": "dist/cli.mjs" - }, - "engines": { - "node": ">=18" - } - }, - "node_modules/nypm/node_modules/citty": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/citty/-/citty-0.2.2.tgz", - "integrity": "sha512-+6vJA3L98yv+IdfKGZHBNiGW5KHn22e/JwID0Strsz8h4S/csAu/OuICwxrg44k5MRiZHWIo8XXuJgQTriRP4w==", - "license": "MIT" - }, - "node_modules/object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/object-inspect": { - "version": "1.13.4", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", - "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/ohash": { - "version": "2.0.12", - "resolved": "https://registry.npmjs.org/ohash/-/ohash-2.0.12.tgz", - "integrity": "sha512-65S/5gk9YSsaRjcyf7Nfa6h/d3E8/1gslpXfI4W7Dxn/oap8IKRuNT5VXkLQ1YFKIEg4apRY4Pj6aiwFzrDdmw==", - "license": "MIT" - }, - "node_modules/on-finished": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", - "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", - "license": "MIT", - "dependencies": { - "ee-first": "1.1.1" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/parseurl": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", - "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/path-to-regexp": { - "version": "0.1.13", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.13.tgz", - "integrity": "sha512-A/AGNMFN3c8bOlvV9RreMdrv7jsmF9XIfDeCd87+I8RNg6s78BhJxMu69NEMHBSJFxKidViTEdruRwEk/WIKqA==", - "license": "MIT" - }, - "node_modules/pathe": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", - "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", - "license": "MIT" - }, - "node_modules/perfect-debounce": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/perfect-debounce/-/perfect-debounce-1.0.0.tgz", - "integrity": "sha512-xCy9V055GLEqoFaHoC1SoLIaLmWctgCUaBaWxDZ7/Zx4CTyX7cJQLJOok/orfjZAh9kEYpjJa4d0KcJmCbctZA==", - "license": "MIT" - }, - "node_modules/pkg-types": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/pkg-types/-/pkg-types-2.3.3.tgz", - "integrity": "sha512-j/lCFdcppV0JxWpCEITdbDltBxPP6cHT+yNJ6Go2OgoSA9518X847X9z0p6LtA4Nc16+eQzCZjRrWanTGvHJ5w==", - "license": "MIT", - "dependencies": { - "confbox": "^0.3.1", - "exsolve": "^1.1.1", - "pathe": "^2.0.3" - } - }, - "node_modules/pkg-types/node_modules/confbox": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/confbox/-/confbox-0.3.1.tgz", - "integrity": "sha512-cKUSoKa8YxFZZSmraVi7onONx3amu77ngK3kGpsYHDH7drPwCRkQE1RYMPlLRrMtnciRj274XNRxcHxnKmDSnA==", - "license": "MIT" - }, - "node_modules/prisma": { - "version": "6.19.3", - "resolved": "https://registry.npmjs.org/prisma/-/prisma-6.19.3.tgz", - "integrity": "sha512-++ZJ0ijLrDJF6hNB4t4uxg2br3fC4H9Yc9tcbjr2fcNFP3rh/SBNrAgjhsqBU4Ght8JPrVofG/ZkXfnSfnYsFg==", - "hasInstallScript": true, - "license": "Apache-2.0", - "dependencies": { - "@prisma/config": "6.19.3", - "@prisma/engines": "6.19.3" - }, - "bin": { - "prisma": "build/index.js" - }, - "engines": { - "node": ">=18.18" - }, - "peerDependencies": { - "typescript": ">=5.1.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, - "node_modules/proxy-addr": { - "version": "2.0.8", - "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.8.tgz", - "integrity": "sha512-5nnx0yGyVUcY6t9RnWcARWtwT9F1D8O9rt08htPvnd49W1IgZtmLkhu9WfMzQj1cFxjHIO6connUNVW5k7AVyQ==", - "license": "MIT", - "dependencies": { - "forwarded": "0.2.0", - "ipaddr.js": "1.9.1" - }, - "engines": { - "node": ">= 0.10" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/proxy-from-env": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-2.1.0.tgz", - "integrity": "sha512-cJ+oHTW1VAEa8cJslgmUZrc+sjRKgAKl3Zyse6+PV38hZe/V6Z14TbCuXcan9F9ghlz4QrFr2c92TNF82UkYHA==", - "license": "MIT", - "engines": { - "node": ">=10" - } - }, - "node_modules/pure-rand": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-6.1.0.tgz", - "integrity": "sha512-bVWawvoZoBYpp6yIoQtQXHZjmz35RSVHnUOTefl8Vcjr8snTPY1wnpSPMWekcFwbxI6gtmT7rSYPFvz71ldiOA==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/dubzzz" - }, - { - "type": "opencollective", - "url": "https://opencollective.com/fast-check" - } - ], - "license": "MIT" - }, - "node_modules/qs": { - "version": "6.16.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.16.0.tgz", - "integrity": "sha512-h6fhOIaRrID2CbEY2fqs+7t+UXZo+MLAnU5gRIq85uFtdiUPCdsApMlHhXogKVM4HM2DVbIjGNTTYH2OcmP1vA==", - "license": "BSD-3-Clause", - "dependencies": { - "es-define-property": "^1.0.1", - "side-channel": "^1.1.1" - }, - "engines": { - "node": ">=0.6" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/range-parser": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", - "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/raw-body": { - "version": "2.5.3", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz", - "integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==", - "license": "MIT", - "dependencies": { - "bytes": "~3.1.2", - "http-errors": "~2.0.1", - "iconv-lite": "~0.4.24", - "unpipe": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/rc9": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/rc9/-/rc9-2.1.2.tgz", - "integrity": "sha512-btXCnMmRIBINM2LDZoEmOogIZU7Qe7zn4BpomSKZ/ykbLObuBdvG+mFq11DL6fjH1DRwHhrlgtYWG96bJiC7Cg==", - "license": "MIT", - "dependencies": { - "defu": "^6.1.4", - "destr": "^2.0.3" - } - }, - "node_modules/readdirp": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz", - "integrity": "sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==", - "license": "MIT", - "engines": { - "node": ">= 14.18.0" - }, - "funding": { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, - "node_modules/safer-buffer": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "license": "MIT" - }, - "node_modules/semver": { - "version": "7.8.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", - "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", - "license": "ISC", - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/send": { - "version": "0.19.2", - "resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz", - "integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==", - "license": "MIT", - "dependencies": { - "debug": "2.6.9", - "depd": "2.0.0", - "destroy": "1.2.0", - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "fresh": "~0.5.2", - "http-errors": "~2.0.1", - "mime": "1.6.0", - "ms": "2.1.3", - "on-finished": "~2.4.1", - "range-parser": "~1.2.1", - "statuses": "~2.0.2" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/send/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "license": "MIT" - }, - "node_modules/serve-static": { - "version": "1.16.3", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz", - "integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==", - "license": "MIT", - "dependencies": { - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "parseurl": "~1.3.3", - "send": "~0.19.1" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/setprototypeof": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", - "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", - "license": "ISC" - }, - "node_modules/side-channel": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz", - "integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "object-inspect": "^1.13.4", - "side-channel-list": "^1.0.1", - "side-channel-map": "^1.0.1", - "side-channel-weakmap": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/side-channel-list": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz", - "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "object-inspect": "^1.13.4" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/side-channel-map": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", - "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", - "license": "MIT", - "dependencies": { - "call-bound": "^1.0.2", - "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.5", - "object-inspect": "^1.13.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/side-channel-weakmap": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", - "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", - "license": "MIT", - "dependencies": { - "call-bound": "^1.0.2", - "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.5", - "object-inspect": "^1.13.3", - "side-channel-map": "^1.0.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/statuses": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", - "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/tinyexec": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.3.1.tgz", - "integrity": "sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA==", - "license": "MIT", - "engines": { - "node": ">=18" - } - }, - "node_modules/toidentifier": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", - "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", - "license": "MIT", - "engines": { - "node": ">=0.6" - } - }, - "node_modules/type-is": { - "version": "1.6.18", - "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", - "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", - "license": "MIT", - "dependencies": { - "media-typer": "0.3.0", - "mime-types": "~2.1.24" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/unpipe": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/utils-merge": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", - "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", - "license": "MIT", - "engines": { - "node": ">= 0.4.0" - } - }, - "node_modules/vary": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", - "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - } - } -} +{ + "name": "dealer-network-api", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "dealer-network-api", + "version": "1.0.0", + "hasInstallScript": true, + "dependencies": { + "@prisma/client": "^6.16.2", + "axios": "^1.12.2", + "bcryptjs": "^3.0.3", + "cors": "^2.8.5", + "dotenv": "^16.6.1", + "express": "^4.21.2", + "jsonwebtoken": "^9.0.2", + "prisma": "^6.16.2" + }, + "devDependencies": {} + }, + "node_modules/@prisma/client": { + "version": "6.19.3", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-6.19.3.tgz", + "integrity": "sha512-mKq3jQFhjvko5LTJFHGilsuQs+W+T3Gm451NzuTDGQxwCzwXHYnIu2zGkRoW+Exq3Rob7yp2MfzSrdIiZVhrBg==", + "hasInstallScript": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18" + }, + "peerDependencies": { + "prisma": "*", + "typescript": ">=5.1.0" + }, + "peerDependenciesMeta": { + "prisma": { + "optional": true + }, + "typescript": { + "optional": true + } + } + }, + "node_modules/@prisma/config": { + "version": "6.19.3", + "resolved": "https://registry.npmjs.org/@prisma/config/-/config-6.19.3.tgz", + "integrity": "sha512-CBPT44BjlQxEt8kiMEauji2WHTDoVBOKl7UlewXmUgBPnr/oPRZC3psci5chJnYmH0ivEIog2OU9PGWoki3DLQ==", + "license": "Apache-2.0", + "dependencies": { + "c12": "3.1.0", + "deepmerge-ts": "7.1.5", + "effect": "3.21.0", + "empathic": "2.0.0" + } + }, + "node_modules/@prisma/debug": { + "version": "6.19.3", + "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-6.19.3.tgz", + "integrity": "sha512-ljkJ+SgpXNktLG0Q/n4JGYCkKf0f8oYLyjImS2I8e2q2WCfdRRtWER062ZV/ixaNP2M2VKlWXVJiGzZaUgbKZw==", + "license": "Apache-2.0" + }, + "node_modules/@prisma/engines": { + "version": "6.19.3", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-6.19.3.tgz", + "integrity": "sha512-RSYxtlYFl5pJ8ZePgMv0lZ9IzVCOdTPOegrs2qcbAEFrBI1G33h6wyC9kjQvo0DnYEhEVY0X4LsuFHXLKQk88g==", + "hasInstallScript": true, + "license": "Apache-2.0", + "dependencies": { + "@prisma/debug": "6.19.3", + "@prisma/engines-version": "7.1.1-3.c2990dca591cba766e3b7ef5d9e8a84796e47ab7", + "@prisma/fetch-engine": "6.19.3", + "@prisma/get-platform": "6.19.3" + } + }, + "node_modules/@prisma/engines-version": { + "version": "7.1.1-3.c2990dca591cba766e3b7ef5d9e8a84796e47ab7", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-7.1.1-3.c2990dca591cba766e3b7ef5d9e8a84796e47ab7.tgz", + "integrity": "sha512-03bgb1VD5gvuumNf+7fVGBzfpJPjmqV423l/WxsWk2cNQ42JD0/SsFBPhN6z8iAvdHs07/7ei77SKu7aZfq8bA==", + "license": "Apache-2.0" + }, + "node_modules/@prisma/fetch-engine": { + "version": "6.19.3", + "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-6.19.3.tgz", + "integrity": "sha512-tKtl/qco9Nt7LU5iKhpultD8O4vMCZcU2CHjNTnRrL1QvSUr5W/GcyFPjNL87GtRrwBc7ubXXD9xy4EvLvt8JA==", + "license": "Apache-2.0", + "dependencies": { + "@prisma/debug": "6.19.3", + "@prisma/engines-version": "7.1.1-3.c2990dca591cba766e3b7ef5d9e8a84796e47ab7", + "@prisma/get-platform": "6.19.3" + } + }, + "node_modules/@prisma/get-platform": { + "version": "6.19.3", + "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-6.19.3.tgz", + "integrity": "sha512-xFj1VcJ1N3MKooOQAGO0W5tsd0W2QzIvW7DD7c/8H14Zmp4jseeWAITm+w2LLoLrlhoHdPPh0NMZ8mfL6puoHA==", + "license": "Apache-2.0", + "dependencies": { + "@prisma/debug": "6.19.3" + } + }, + "node_modules/@standard-schema/spec": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz", + "integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==", + "license": "MIT" + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "license": "MIT", + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/agent-base/node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/agent-base/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", + "license": "MIT" + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, + "node_modules/axios": { + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.20.0.tgz", + "integrity": "sha512-r8aOh8j9cGKpgQAqpzrUHnSIc6a59Y3Xf/cv8sy1DrHCkZHzQGEuoq1tARk6qSyDdtQGSDgpb9kFlruzPvrgwg==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.16.0", + "form-data": "^4.0.6", + "https-proxy-agent": "^5.0.1", + "proxy-from-env": "^2.1.0" + } + }, + "node_modules/bcryptjs": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-3.0.3.tgz", + "integrity": "sha512-GlF5wPWnSa/X5LKM1o0wz0suXIINz1iHRLvTS+sLyi7XPbe5ycmYI3DlZqVGZZtDgl4DmasFg7gOB3JYbphV5g==", + "license": "BSD-3-Clause", + "bin": { + "bcrypt": "bin/bcrypt" + } + }, + "node_modules/body-parser": { + "version": "1.20.8", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.8.tgz", + "integrity": "sha512-JNcyFQ64OiijEkPzUBTCe+hyPXUD/3LEldGQ6iF5LR1w00mx9o7xtDWHXBY2iItjdCFGoilOLNQbH943ut7pHA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "content-type": "~1.0.5", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "~1.2.0", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "on-finished": "~2.4.1", + "qs": "~6.16.0", + "raw-body": "~2.5.3", + "type-is": "~1.6.18", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==", + "license": "BSD-3-Clause" + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/c12": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/c12/-/c12-3.1.0.tgz", + "integrity": "sha512-uWoS8OU1MEIsOv8p/5a82c3H31LsWVR5qiyXVfBNOzfffjUWtPnhAb4BYI2uG2HfGmZmFjCtui5XNWaps+iFuw==", + "license": "MIT", + "dependencies": { + "chokidar": "^4.0.3", + "confbox": "^0.2.2", + "defu": "^6.1.4", + "dotenv": "^16.6.1", + "exsolve": "^1.0.7", + "giget": "^2.0.0", + "jiti": "^2.4.2", + "ohash": "^2.0.11", + "pathe": "^2.0.3", + "perfect-debounce": "^1.0.0", + "pkg-types": "^2.2.0", + "rc9": "^2.1.2" + }, + "peerDependencies": { + "magicast": "^0.3.5" + }, + "peerDependenciesMeta": { + "magicast": { + "optional": true + } + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/chokidar": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz", + "integrity": "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==", + "license": "MIT", + "dependencies": { + "readdirp": "^4.0.1" + }, + "engines": { + "node": ">= 14.16.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/citty": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/citty/-/citty-0.1.6.tgz", + "integrity": "sha512-tskPPKEs8D2KPafUypv2gxwJP8h/OaJmC82QQGGDQcHvXX43xF2VDACcJVmZ0EuSxkpO9Kc4MlrA3q0+FG58AQ==", + "license": "MIT", + "dependencies": { + "consola": "^3.2.3" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/confbox": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/confbox/-/confbox-0.2.4.tgz", + "integrity": "sha512-ysOGlgTFbN2/Y6Cg3Iye8YKulHw+R2fNXHrgSmXISQdMnomY6eNDprVdW9R5xBguEqI954+S6709UyiO7B+6OQ==", + "license": "MIT" + }, + "node_modules/consola": { + "version": "3.4.2", + "resolved": "https://registry.npmjs.org/consola/-/consola-3.4.2.tgz", + "integrity": "sha512-5IKcdX0nnYavi6G7TtOhwkYzyjfJlatbjMjuLSfE2kYT5pMDOilZ4OvMhi637CcDICTmz3wARPoyhqyX1Y+XvA==", + "license": "MIT", + "engines": { + "node": "^14.18.0 || >=16.10.0" + } + }, + "node_modules/content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "license": "MIT", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz", + "integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==", + "license": "MIT" + }, + "node_modules/cors": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/deepmerge-ts": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/deepmerge-ts/-/deepmerge-ts-8.0.2.tgz", + "integrity": "sha512-uqbvqLUMrc6p0MO+WBRtTxY55hmyh94WRwI5a++PZe54X+bfVh59FSN7uWCBCW1CCVjzjnrwzfI8zidE2obMMw==", + "funding": [ + { + "type": "ko-fi", + "url": "https://ko-fi.com/rebeccastevens" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/deepmerge-ts" + } + ], + "license": "BSD-3-Clause", + "engines": { + "node": ">=16.9.0" + } + }, + "node_modules/defu": { + "version": "6.1.7", + "resolved": "https://registry.npmjs.org/defu/-/defu-6.1.7.tgz", + "integrity": "sha512-7z22QmUWiQ/2d0KkdYmANbRUVABpZ9SNYyH5vx6PZ+nE5bcC0l7uFvEfHlyld/HcGBFTL536ClDt3DEcSlEJAQ==", + "license": "MIT" + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/destr": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/destr/-/destr-2.0.5.tgz", + "integrity": "sha512-ugFTXCtDZunbzasqBxrK93Ik/DRYsO6S/fedkWEMKqt04xZ4csmnmwGDBAb07QWNaGMAmnTIemsYZCksjATwsA==", + "license": "MIT" + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "license": "MIT", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/dotenv": { + "version": "16.6.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.6.1.tgz", + "integrity": "sha512-uBq4egWHTcTt33a72vpSG0z3HnPuIl6NqYcTrKEg2azoEyl2hpW0zqlxysq2pK9HlDIHyHyakeYaYnSAwd8bow==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "license": "Apache-2.0", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/effect": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/effect/-/effect-3.21.0.tgz", + "integrity": "sha512-PPN80qRokCd1f015IANNhrwOnLO7GrrMQfk4/lnZRE/8j7UPWrNNjPV0uBrZutI/nHzernbW+J0hdqQysHiSnQ==", + "license": "MIT", + "dependencies": { + "@standard-schema/spec": "^1.0.0", + "fast-check": "^3.23.1" + } + }, + "node_modules/empathic": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/empathic/-/empathic-2.0.0.tgz", + "integrity": "sha512-i6UzDscO/XfAcNYD75CfICkmfLedpyPDdozrLMmQc5ORaQcdMoc21OnlEylMIqI7U8eniKrPMxxtj8k0vhmJhA==", + "license": "MIT", + "engines": { + "node": ">=14" + } + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz", + "integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "4.22.3", + "resolved": "https://registry.npmjs.org/express/-/express-4.22.3.tgz", + "integrity": "sha512-Bdcs4+3qlpVlx2NRn6fgX2Ue2/gGRaPeawebgclM0ERSCqDpA+owF1fdPwjJUTAJWMTuAaxjDf+hzb0/4eKvvw==", + "license": "MIT", + "dependencies": { + "accepts": "~1.3.8", + "array-flatten": "1.1.1", + "body-parser": "~1.20.5", + "content-disposition": "~0.5.4", + "content-type": "~1.0.4", + "cookie": "~0.7.1", + "cookie-signature": "~1.0.6", + "debug": "2.6.9", + "depd": "2.0.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "~1.3.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.0", + "merge-descriptors": "1.0.3", + "methods": "~1.1.2", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "path-to-regexp": "~0.1.13", + "proxy-addr": "~2.0.7", + "qs": "~6.16.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "~0.19.0", + "serve-static": "~1.16.2", + "setprototypeof": "1.2.0", + "statuses": "~2.0.1", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/exsolve": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/exsolve/-/exsolve-1.1.1.tgz", + "integrity": "sha512-9U/jZUgjnSGyntRr6y5Muu1MJcwFl6kPu7k8qLF0IMNfLqvw0NZ4nnVDq0RVoZ0RvCyumib4Ez3KYrVfilrw+g==", + "license": "MIT" + }, + "node_modules/fast-check": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/fast-check/-/fast-check-3.23.2.tgz", + "integrity": "sha512-h5+1OzzfCC3Ef7VbtKdcv7zsstUQwUDlYpUTvjeUsJAssPgLn7QzbboPtL5ro04Mq0rPOsMzl7q5hIbRs2wD1A==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/dubzzz" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fast-check" + } + ], + "license": "MIT", + "dependencies": { + "pure-rand": "^6.1.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/finalhandler": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz", + "integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "statuses": "~2.0.2", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/follow-redirects": { + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.0.tgz", + "integrity": "sha512-y5rN/uOsadFT/JfYwhxRS5R7Qce+g3zG97+JrtFZlC9klX/W5hD7iiLzScI4nZqUS7DNUdhPgw4xI8W2LuXlUw==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.6.tgz", + "integrity": "sha512-vKatAh4SlVfgbv+YtmhiRjhEMJsYpsG1Y2rMQtR+SVSbytsSD1YGzDIcrAJmdFec88u/+VoGmxnl+80gL1tRCQ==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.4", + "mime-types": "^2.1.35" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/giget": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/giget/-/giget-2.0.0.tgz", + "integrity": "sha512-L5bGsVkxJbJgdnwyuheIunkGatUF/zssUoxxjACCseZYAVbaqdh9Tsmmlkl8vYan09H7sbvKt4pS8GqKLBrEzA==", + "license": "MIT", + "dependencies": { + "citty": "^0.1.6", + "consola": "^3.4.0", + "defu": "^6.1.4", + "node-fetch-native": "^1.6.6", + "nypm": "^0.6.0", + "pathe": "^2.0.3" + }, + "bin": { + "giget": "dist/cli.mjs" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "license": "MIT", + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", + "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "license": "MIT", + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/https-proxy-agent/node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/https-proxy-agent/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/jiti": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.7.0.tgz", + "integrity": "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ==", + "license": "MIT", + "bin": { + "jiti": "lib/jiti-cli.mjs" + } + }, + "node_modules/jsonwebtoken": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.3.tgz", + "integrity": "sha512-MT/xP0CrubFRNLNKvxJ2BYfy53Zkm++5bX9dtuPbqAeQpTVe0MQTFhao8+Cp//EmJp244xt6Drw/GVEGCUj40g==", + "license": "MIT", + "dependencies": { + "jws": "^4.0.1", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^7.5.4" + }, + "engines": { + "node": ">=12", + "npm": ">=6" + } + }, + "node_modules/jsonwebtoken/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/jwa": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz", + "integrity": "sha512-hRF04fqJIP8Abbkq5NKGN0Bbr3JxlQ+qhZufXVr0DvujKy93ZCbXZMHDL4EOtodSbCWxOqR8MS1tXA5hwqCXDg==", + "license": "MIT", + "dependencies": { + "buffer-equal-constant-time": "^1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/jws": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz", + "integrity": "sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==", + "license": "MIT", + "dependencies": { + "jwa": "^2.0.1", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==", + "license": "MIT" + }, + "node_modules/lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==", + "license": "MIT" + }, + "node_modules/lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==", + "license": "MIT" + }, + "node_modules/lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==", + "license": "MIT" + }, + "node_modules/lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==", + "license": "MIT" + }, + "node_modules/lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==", + "license": "MIT" + }, + "node_modules/lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==", + "license": "MIT" + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/merge-descriptors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", + "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/node-fetch-native": { + "version": "1.6.7", + "resolved": "https://registry.npmjs.org/node-fetch-native/-/node-fetch-native-1.6.7.tgz", + "integrity": "sha512-g9yhqoedzIUm0nTnTqAQvueMPVOuIY16bqgAJJC8XOOubYFNwz6IER9qs0Gq2Xd0+CecCKFjtdDTMA4u4xG06Q==", + "license": "MIT" + }, + "node_modules/nypm": { + "version": "0.6.10", + "resolved": "https://registry.npmjs.org/nypm/-/nypm-0.6.10.tgz", + "integrity": "sha512-W72Hrj1petq+b3Hk2aAC+9zswetlIFTnDW4s5djseZh2nYqBbyQLOtj472HwcbcWykPBUW1WpWpjOd4nK6gMRw==", + "license": "MIT", + "dependencies": { + "citty": "^0.2.2", + "pathe": "^2.0.3", + "tinyexec": "^1.3.1" + }, + "bin": { + "nypm": "dist/cli.mjs" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/nypm/node_modules/citty": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/citty/-/citty-0.2.2.tgz", + "integrity": "sha512-+6vJA3L98yv+IdfKGZHBNiGW5KHn22e/JwID0Strsz8h4S/csAu/OuICwxrg44k5MRiZHWIo8XXuJgQTriRP4w==", + "license": "MIT" + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/ohash": { + "version": "2.0.12", + "resolved": "https://registry.npmjs.org/ohash/-/ohash-2.0.12.tgz", + "integrity": "sha512-65S/5gk9YSsaRjcyf7Nfa6h/d3E8/1gslpXfI4W7Dxn/oap8IKRuNT5VXkLQ1YFKIEg4apRY4Pj6aiwFzrDdmw==", + "license": "MIT" + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.13.tgz", + "integrity": "sha512-A/AGNMFN3c8bOlvV9RreMdrv7jsmF9XIfDeCd87+I8RNg6s78BhJxMu69NEMHBSJFxKidViTEdruRwEk/WIKqA==", + "license": "MIT" + }, + "node_modules/pathe": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", + "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", + "license": "MIT" + }, + "node_modules/perfect-debounce": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/perfect-debounce/-/perfect-debounce-1.0.0.tgz", + "integrity": "sha512-xCy9V055GLEqoFaHoC1SoLIaLmWctgCUaBaWxDZ7/Zx4CTyX7cJQLJOok/orfjZAh9kEYpjJa4d0KcJmCbctZA==", + "license": "MIT" + }, + "node_modules/pkg-types": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/pkg-types/-/pkg-types-2.3.3.tgz", + "integrity": "sha512-j/lCFdcppV0JxWpCEITdbDltBxPP6cHT+yNJ6Go2OgoSA9518X847X9z0p6LtA4Nc16+eQzCZjRrWanTGvHJ5w==", + "license": "MIT", + "dependencies": { + "confbox": "^0.3.1", + "exsolve": "^1.1.1", + "pathe": "^2.0.3" + } + }, + "node_modules/pkg-types/node_modules/confbox": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/confbox/-/confbox-0.3.1.tgz", + "integrity": "sha512-cKUSoKa8YxFZZSmraVi7onONx3amu77ngK3kGpsYHDH7drPwCRkQE1RYMPlLRrMtnciRj274XNRxcHxnKmDSnA==", + "license": "MIT" + }, + "node_modules/prisma": { + "version": "6.19.3", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-6.19.3.tgz", + "integrity": "sha512-++ZJ0ijLrDJF6hNB4t4uxg2br3fC4H9Yc9tcbjr2fcNFP3rh/SBNrAgjhsqBU4Ght8JPrVofG/ZkXfnSfnYsFg==", + "hasInstallScript": true, + "license": "Apache-2.0", + "dependencies": { + "@prisma/config": "6.19.3", + "@prisma/engines": "6.19.3" + }, + "bin": { + "prisma": "build/index.js" + }, + "engines": { + "node": ">=18.18" + }, + "peerDependencies": { + "typescript": ">=5.1.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/proxy-addr": { + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.8.tgz", + "integrity": "sha512-5nnx0yGyVUcY6t9RnWcARWtwT9F1D8O9rt08htPvnd49W1IgZtmLkhu9WfMzQj1cFxjHIO6connUNVW5k7AVyQ==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/proxy-from-env": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-2.1.0.tgz", + "integrity": "sha512-cJ+oHTW1VAEa8cJslgmUZrc+sjRKgAKl3Zyse6+PV38hZe/V6Z14TbCuXcan9F9ghlz4QrFr2c92TNF82UkYHA==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/pure-rand": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-6.1.0.tgz", + "integrity": "sha512-bVWawvoZoBYpp6yIoQtQXHZjmz35RSVHnUOTefl8Vcjr8snTPY1wnpSPMWekcFwbxI6gtmT7rSYPFvz71ldiOA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/dubzzz" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fast-check" + } + ], + "license": "MIT" + }, + "node_modules/qs": { + "version": "6.16.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.16.0.tgz", + "integrity": "sha512-h6fhOIaRrID2CbEY2fqs+7t+UXZo+MLAnU5gRIq85uFtdiUPCdsApMlHhXogKVM4HM2DVbIjGNTTYH2OcmP1vA==", + "license": "BSD-3-Clause", + "dependencies": { + "es-define-property": "^1.0.1", + "side-channel": "^1.1.1" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz", + "integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/rc9": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/rc9/-/rc9-2.1.2.tgz", + "integrity": "sha512-btXCnMmRIBINM2LDZoEmOogIZU7Qe7zn4BpomSKZ/ykbLObuBdvG+mFq11DL6fjH1DRwHhrlgtYWG96bJiC7Cg==", + "license": "MIT", + "dependencies": { + "defu": "^6.1.4", + "destr": "^2.0.3" + } + }, + "node_modules/readdirp": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz", + "integrity": "sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==", + "license": "MIT", + "engines": { + "node": ">= 14.18.0" + }, + "funding": { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/semver": { + "version": "7.8.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", + "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/send": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz", + "integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.1", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "~2.4.1", + "range-parser": "~1.2.1", + "statuses": "~2.0.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/serve-static": { + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz", + "integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==", + "license": "MIT", + "dependencies": { + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "~0.19.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/side-channel": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz", + "integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4", + "side-channel-list": "^1.0.1", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz", + "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/tinyexec": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.3.1.tgz", + "integrity": "sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA==", + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "license": "MIT", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + } + } +} diff --git a/package.json b/package.json index ee909b3..a5205ec 100644 --- a/package.json +++ b/package.json @@ -1,29 +1,29 @@ -{ - "name": "dealer-network-api", - "version": "1.0.0", - "private": true, - "main": "src/index.js", - "scripts": { - "dev": "node --watch src/index.js", - "start": "prisma migrate deploy && node prisma/seed.js && node src/index.js", - "seed": "node prisma/seed.js", - "check": "node scripts/api-check.js", - "postinstall": "prisma generate" - }, - "prisma": { - "seed": "node prisma/seed.js" - }, - "dependencies": { - "@prisma/client": "^6.16.2", - "axios": "^1.12.2", - "bcryptjs": "^3.0.3", - "cors": "^2.8.5", - "dotenv": "^16.6.1", - "express": "^4.21.2", - "jsonwebtoken": "^9.0.2", - "prisma": "^6.16.2" - }, - "overrides": { - "deepmerge-ts": "^8.0.2" - } -} +{ + "name": "dealer-network-api", + "version": "1.0.0", + "private": true, + "main": "src/index.js", + "scripts": { + "dev": "node --watch src/index.js", + "start": "prisma migrate deploy && node prisma/seed.js && node src/index.js", + "seed": "node prisma/seed.js", + "check": "node scripts/api-check.js", + "postinstall": "prisma generate" + }, + "prisma": { + "seed": "node prisma/seed.js" + }, + "dependencies": { + "@prisma/client": "^6.16.2", + "axios": "^1.12.2", + "bcryptjs": "^3.0.3", + "cors": "^2.8.5", + "dotenv": "^16.6.1", + "express": "^4.21.2", + "jsonwebtoken": "^9.0.2", + "prisma": "^6.16.2" + }, + "overrides": { + "deepmerge-ts": "^8.0.2" + } +} diff --git a/prisma/migrations/20261001070000_password_login/migration.sql b/prisma/migrations/20261001070000_password_login/migration.sql index d1dcbc2..2705e18 100644 --- a/prisma/migrations/20261001070000_password_login/migration.sql +++ b/prisma/migrations/20261001070000_password_login/migration.sql @@ -1,34 +1,34 @@ --- CreateTable -CREATE TABLE "LoginRequest" ( - "id" TEXT NOT NULL PRIMARY KEY, - "userId" TEXT NOT NULL, - "status" TEXT NOT NULL, - "secretHash" TEXT NOT NULL, - "expiresAt" DATETIME NOT NULL, - "decidedById" TEXT, - "decidedAt" DATETIME, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT "LoginRequest_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "LoginRequest_decidedById_fkey" FOREIGN KEY ("decidedById") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); - --- RedefineTables -PRAGMA defer_foreign_keys=ON; -PRAGMA foreign_keys=OFF; -CREATE TABLE "new_User" ( - "id" TEXT NOT NULL PRIMARY KEY, - "name" TEXT NOT NULL, - "phone" TEXT NOT NULL, - "role" TEXT NOT NULL, - "dealerId" TEXT, - "passwordHash" TEXT, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" DATETIME NOT NULL, - CONSTRAINT "User_dealerId_fkey" FOREIGN KEY ("dealerId") REFERENCES "Dealer" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); -INSERT INTO "new_User" ("createdAt", "dealerId", "id", "name", "phone", "role", "updatedAt") SELECT "createdAt", "dealerId", "id", "name", "phone", "role", "updatedAt" FROM "User"; -DROP TABLE "User"; -ALTER TABLE "new_User" RENAME TO "User"; -CREATE UNIQUE INDEX "User_phone_key" ON "User"("phone"); -PRAGMA foreign_keys=ON; -PRAGMA defer_foreign_keys=OFF; +-- CreateTable +CREATE TABLE "LoginRequest" ( + "id" TEXT NOT NULL PRIMARY KEY, + "userId" TEXT NOT NULL, + "status" TEXT NOT NULL, + "secretHash" TEXT NOT NULL, + "expiresAt" DATETIME NOT NULL, + "decidedById" TEXT, + "decidedAt" DATETIME, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT "LoginRequest_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "LoginRequest_decidedById_fkey" FOREIGN KEY ("decidedById") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE +); + +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_User" ( + "id" TEXT NOT NULL PRIMARY KEY, + "name" TEXT NOT NULL, + "phone" TEXT NOT NULL, + "role" TEXT NOT NULL, + "dealerId" TEXT, + "passwordHash" TEXT, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "User_dealerId_fkey" FOREIGN KEY ("dealerId") REFERENCES "Dealer" ("id") ON DELETE SET NULL ON UPDATE CASCADE +); +INSERT INTO "new_User" ("createdAt", "dealerId", "id", "name", "phone", "role", "updatedAt") SELECT "createdAt", "dealerId", "id", "name", "phone", "role", "updatedAt" FROM "User"; +DROP TABLE "User"; +ALTER TABLE "new_User" RENAME TO "User"; +CREATE UNIQUE INDEX "User_phone_key" ON "User"("phone"); +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF; diff --git a/prisma/migrations/20261001090000_plate_number/migration.sql b/prisma/migrations/20261001090000_plate_number/migration.sql index c66b93f..05c9988 100644 --- a/prisma/migrations/20261001090000_plate_number/migration.sql +++ b/prisma/migrations/20261001090000_plate_number/migration.sql @@ -1,2 +1,2 @@ --- AlterTable -ALTER TABLE "Stock" ADD COLUMN "plateNumber" TEXT; +-- AlterTable +ALTER TABLE "Stock" ADD COLUMN "plateNumber" TEXT; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 0c44c32..b947409 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1,143 +1,143 @@ -generator client { - provider = "prisma-client-js" -} - -datasource db { - provider = "sqlite" - url = env("DATABASE_URL") -} - -model User { - id String @id @default(cuid()) - name String - phone String @unique - role String - dealerId String? - dealer Dealer? @relation("DealerStaff", fields: [dealerId], references: [id]) - passwordHash String? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - assignments DealerAssignment[] @relation("SalesRepAssignments") - stageLogs StageLog[] - transfers StockTransfer[] - events Event[] - servicePoints ServicePoint[] - loginRequests LoginRequest[] @relation("DealerLoginRequests") - loginDecisions LoginRequest[] @relation("LoginDecisions") -} - -model LoginRequest { - id String @id @default(cuid()) - userId String - user User @relation("DealerLoginRequests", fields: [userId], references: [id], onDelete: Cascade) - status String - secretHash String - expiresAt DateTime - decidedById String? - decidedBy User? @relation("LoginDecisions", fields: [decidedById], references: [id]) - decidedAt DateTime? - createdAt DateTime @default(now()) -} - -model Dealer { - id String @id @default(cuid()) - name String - code String @unique - district String? - address String? - phone String? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - staff User[] @relation("DealerStaff") - assignments DealerAssignment[] - stocks Stock[] - transfersFrom StockTransfer[] @relation("TransferFrom") - transfersTo StockTransfer[] @relation("TransferTo") - events Event[] -} - -model DealerAssignment { - salesRepId String - dealerId String - createdAt DateTime @default(now()) - salesRep User @relation("SalesRepAssignments", fields: [salesRepId], references: [id], onDelete: Cascade) - dealer Dealer @relation(fields: [dealerId], references: [id], onDelete: Cascade) - - @@id([salesRepId, dealerId]) -} - -model Stock { - id String @id @default(cuid()) - chassisNumber String @unique - engineNumber String @unique - model String - color String - currentDealerId String - currentDealer Dealer @relation(fields: [currentDealerId], references: [id]) - dateReceived DateTime @default(now()) - currentStage String @default("received") - paymentType String? - leaseProviderType String? - financeCompanyName String? - plateNumber String? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - stageLogs StageLog[] - transfers StockTransfer[] -} - -model StageLog { - id String @id @default(cuid()) - stockId String - stock Stock @relation(fields: [stockId], references: [id], onDelete: Cascade) - stage String - loggedAt DateTime @default(now()) - actorId String? - actor User? @relation(fields: [actorId], references: [id]) -} - -model StockTransfer { - id String @id @default(cuid()) - stockId String - stock Stock @relation(fields: [stockId], references: [id], onDelete: Cascade) - fromDealerId String - fromDealer Dealer @relation("TransferFrom", fields: [fromDealerId], references: [id]) - toDealerId String - toDealer Dealer @relation("TransferTo", fields: [toDealerId], references: [id]) - actorId String - actor User @relation(fields: [actorId], references: [id]) - transferredAt DateTime @default(now()) -} - -model Event { - id String @id @default(cuid()) - dealerId String - dealer Dealer @relation(fields: [dealerId], references: [id]) - planType String - month Int? - year Int? - title String - description String - expense Float - imageUrls String @default("[]") - createdById String - createdBy User @relation(fields: [createdById], references: [id]) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt -} - -model ServicePoint { - id String @id @default(cuid()) - name String - district String - address String? - phone String? - notes String? - createdById String - createdBy User @relation(fields: [createdById], references: [id]) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt -} +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "sqlite" + url = env("DATABASE_URL") +} + +model User { + id String @id @default(cuid()) + name String + phone String @unique + role String + dealerId String? + dealer Dealer? @relation("DealerStaff", fields: [dealerId], references: [id]) + passwordHash String? + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + assignments DealerAssignment[] @relation("SalesRepAssignments") + stageLogs StageLog[] + transfers StockTransfer[] + events Event[] + servicePoints ServicePoint[] + loginRequests LoginRequest[] @relation("DealerLoginRequests") + loginDecisions LoginRequest[] @relation("LoginDecisions") +} + +model LoginRequest { + id String @id @default(cuid()) + userId String + user User @relation("DealerLoginRequests", fields: [userId], references: [id], onDelete: Cascade) + status String + secretHash String + expiresAt DateTime + decidedById String? + decidedBy User? @relation("LoginDecisions", fields: [decidedById], references: [id]) + decidedAt DateTime? + createdAt DateTime @default(now()) +} + +model Dealer { + id String @id @default(cuid()) + name String + code String @unique + district String? + address String? + phone String? + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + staff User[] @relation("DealerStaff") + assignments DealerAssignment[] + stocks Stock[] + transfersFrom StockTransfer[] @relation("TransferFrom") + transfersTo StockTransfer[] @relation("TransferTo") + events Event[] +} + +model DealerAssignment { + salesRepId String + dealerId String + createdAt DateTime @default(now()) + salesRep User @relation("SalesRepAssignments", fields: [salesRepId], references: [id], onDelete: Cascade) + dealer Dealer @relation(fields: [dealerId], references: [id], onDelete: Cascade) + + @@id([salesRepId, dealerId]) +} + +model Stock { + id String @id @default(cuid()) + chassisNumber String @unique + engineNumber String @unique + model String + color String + currentDealerId String + currentDealer Dealer @relation(fields: [currentDealerId], references: [id]) + dateReceived DateTime @default(now()) + currentStage String @default("received") + paymentType String? + leaseProviderType String? + financeCompanyName String? + plateNumber String? + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + stageLogs StageLog[] + transfers StockTransfer[] +} + +model StageLog { + id String @id @default(cuid()) + stockId String + stock Stock @relation(fields: [stockId], references: [id], onDelete: Cascade) + stage String + loggedAt DateTime @default(now()) + actorId String? + actor User? @relation(fields: [actorId], references: [id]) +} + +model StockTransfer { + id String @id @default(cuid()) + stockId String + stock Stock @relation(fields: [stockId], references: [id], onDelete: Cascade) + fromDealerId String + fromDealer Dealer @relation("TransferFrom", fields: [fromDealerId], references: [id]) + toDealerId String + toDealer Dealer @relation("TransferTo", fields: [toDealerId], references: [id]) + actorId String + actor User @relation(fields: [actorId], references: [id]) + transferredAt DateTime @default(now()) +} + +model Event { + id String @id @default(cuid()) + dealerId String + dealer Dealer @relation(fields: [dealerId], references: [id]) + planType String + month Int? + year Int? + title String + description String + expense Float + imageUrls String @default("[]") + createdById String + createdBy User @relation(fields: [createdById], references: [id]) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt +} + +model ServicePoint { + id String @id @default(cuid()) + name String + district String + address String? + phone String? + notes String? + createdById String + createdBy User @relation(fields: [createdById], references: [id]) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt +} diff --git a/prisma/seed.js b/prisma/seed.js index a4abfad..ccf97d8 100644 --- a/prisma/seed.js +++ b/prisma/seed.js @@ -1,41 +1,41 @@ -const path = require('path'); -require('dotenv').config({ path: path.join(__dirname, '..', '.env') }); - -const prisma = require('../src/db'); -const { isValidPhone, normalizePhone } = require('../src/lib/phone'); -const { hashPassword } = require('../src/lib/passwords'); - -async function main() { - const name = String(process.env.SEED_ADMIN_NAME || 'Super Admin').trim(); - const phone = normalizePhone(process.env.SEED_ADMIN_PHONE); - const password = String(process.env.SEED_ADMIN_PASSWORD || ''); - if (!isValidPhone(phone)) { - throw new Error('SEED_ADMIN_PHONE must be a Sri Lankan mobile number'); - } - if (password.length < 8) { - throw new Error('SEED_ADMIN_PASSWORD must be at least 8 characters'); - } - - const passwordHash = await hashPassword(password); - const existingAdmin = await prisma.user.findFirst({ where: { role: 'superAdmin' } }); - const admin = existingAdmin - ? await prisma.user.update({ - where: { id: existingAdmin.id }, - data: { name, phone, role: 'superAdmin', dealerId: null, passwordHash }, - }) - : await prisma.user.upsert({ - where: { phone }, - update: { name, role: 'superAdmin', dealerId: null, passwordHash }, - create: { name, phone, role: 'superAdmin', passwordHash }, - }); - console.log(`Seeded super admin ${admin.name} (${admin.phone})`); -} - -main() - .catch((error) => { - console.error(error); - process.exitCode = 1; - }) - .finally(async () => { - await prisma.$disconnect(); - }); +const path = require('path'); +require('dotenv').config({ path: path.join(__dirname, '..', '.env') }); + +const prisma = require('../src/db'); +const { isValidPhone, normalizePhone } = require('../src/lib/phone'); +const { hashPassword } = require('../src/lib/passwords'); + +async function main() { + const name = String(process.env.SEED_ADMIN_NAME || 'Super Admin').trim(); + const phone = normalizePhone(process.env.SEED_ADMIN_PHONE); + const password = String(process.env.SEED_ADMIN_PASSWORD || ''); + if (!isValidPhone(phone)) { + throw new Error('SEED_ADMIN_PHONE must be a Sri Lankan mobile number'); + } + if (password.length < 8) { + throw new Error('SEED_ADMIN_PASSWORD must be at least 8 characters'); + } + + const passwordHash = await hashPassword(password); + const existingAdmin = await prisma.user.findFirst({ where: { role: 'superAdmin' } }); + const admin = existingAdmin + ? await prisma.user.update({ + where: { id: existingAdmin.id }, + data: { name, phone, role: 'superAdmin', dealerId: null, passwordHash }, + }) + : await prisma.user.upsert({ + where: { phone }, + update: { name, role: 'superAdmin', dealerId: null, passwordHash }, + create: { name, phone, role: 'superAdmin', passwordHash }, + }); + console.log(`Seeded super admin ${admin.name} (${admin.phone})`); +} + +main() + .catch((error) => { + console.error(error); + process.exitCode = 1; + }) + .finally(async () => { + await prisma.$disconnect(); + }); diff --git a/scripts/api-check.js b/scripts/api-check.js index 08abaa6..268a3e1 100644 --- a/scripts/api-check.js +++ b/scripts/api-check.js @@ -1,486 +1,554 @@ -const fs = require('fs'); -const path = require('path'); -const { execSync } = require('child_process'); - -const root = path.join(__dirname, '..'); -process.chdir(root); - -const dbPath = path.join(root, 'data', 'api-check.db'); -for (const file of [dbPath, `${dbPath}-journal`, `${dbPath}-wal`, `${dbPath}-shm`]) { - if (fs.existsSync(file)) fs.unlinkSync(file); -} - -process.env.DATABASE_URL = 'file:../data/api-check.db'; -process.env.JWT_SECRET = 'api-check-secret'; -process.env.TEXTLK_API_TOKEN = ''; -process.env.SEED_ADMIN_NAME = 'Super Admin'; -process.env.SEED_ADMIN_PHONE = '94770000001'; - -execSync('npx prisma db push --skip-generate --accept-data-loss', { - cwd: root, - stdio: 'inherit', - env: process.env, -}); - -const bcrypt = require('bcryptjs'); -const app = require('../src/app'); -const prisma = require('../src/db'); -const { ageBadge } = require('../src/lib/stockRules'); - -function assert(condition, message) { - if (!condition) throw new Error(message); -} - -async function request(port, method, urlPath, { token, body } = {}) { - const response = await fetch(`http://127.0.0.1:${port}${urlPath}`, { - method, - headers: { - 'Content-Type': 'application/json', - ...(token ? { Authorization: `Bearer ${token}` } : {}), - }, - body: body === undefined ? undefined : JSON.stringify(body), - }); - const text = await response.text(); - let json = null; - if (text) { - try { - json = JSON.parse(text); - } catch { - json = { raw: text }; - } - } - return { status: response.status, json }; -} - -function daysAgo(days) { - return new Date(Date.now() - days * 24 * 60 * 60 * 1000).toISOString(); -} - -async function run(port) { - assert(ageBadge(29) === 'green', '29 days is green'); - assert(ageBadge(30) === 'yellow', '30 days is yellow'); - assert(ageBadge(45) === 'yellow', '45 days is yellow'); - assert(ageBadge(46) === 'red', '46 days is red'); - - const unknown = await request(port, 'POST', '/api/auth/dealer-login', { - body: { phone: '94770000099' }, - }); - assert(unknown.status === 404, `unknown phone should be 404, got ${unknown.status}`); - - const adminHash = await bcrypt.hash('admin-pass-123', 10); - await prisma.user.create({ - data: { - name: 'Super Admin', - phone: '94770000001', - role: 'superAdmin', - passwordHash: adminHash, - }, - }); - - const badPassword = await request(port, 'POST', '/api/auth/staff-login', { - body: { phone: '94770000001', password: 'wrong-password' }, - }); - assert(badPassword.status === 401, 'wrong password should be rejected'); - - const verified = await request(port, 'POST', '/api/auth/staff-login', { - body: { phone: '94770000001', password: 'admin-pass-123' }, - }); - assert(verified.status === 200 && verified.json.token, 'staff login failed'); - const adminToken = verified.json.token; - - const me = await request(port, 'GET', '/api/auth/me', { token: adminToken }); - assert(me.status === 200 && me.json.role === 'superAdmin', '/me failed'); - const missing = await request(port, 'GET', '/api/auth/me'); - assert(missing.status === 401, 'missing token should be 401'); - - const dealerMissingPhone = await request(port, 'POST', '/api/admin/dealers', { - token: adminToken, - body: { name: 'No Phone', code: 'NONE' }, - }); - assert(dealerMissingPhone.status === 400, 'dealer without a phone should fail'); - - const dealerA = await request(port, 'POST', '/api/admin/dealers', { - token: adminToken, - body: { name: 'Kandy Motors', code: 'KDY', district: 'Kandy', phone: '94772222222' }, - }); - const dealerB = await request(port, 'POST', '/api/admin/dealers', { - token: adminToken, - body: { name: 'Galle Motors', code: 'GAL', district: 'Galle', phone: '94774444444' }, - }); - const dealerC = await request(port, 'POST', '/api/admin/dealers', { - token: adminToken, - body: { name: 'Jaffna Motors', code: 'JAF', district: 'Jaffna', phone: '94773333333' }, - }); - assert(dealerA.status === 201 && dealerB.status === 201 && dealerC.status === 201, 'dealer create failed'); - const kandyLogin = await prisma.user.findUnique({ where: { phone: '94772222222' } }); - assert( - kandyLogin && kandyLogin.role === 'dealer' && kandyLogin.dealerId === dealerA.json.data.id, - 'creating a dealer should create its login' - ); - - const rep = await request(port, 'POST', '/api/admin/sales-reps', { - token: adminToken, - body: { - name: 'Nimal Perera', - phone: '94771111111', - password: 'rep-pass-123', - dealerIds: [dealerA.json.data.id, dealerB.json.data.id], - }, - }); - assert(rep.status === 201, `sales rep create failed ${rep.status}`); - - async function staffLogin(phone, password) { - const result = await request(port, 'POST', '/api/auth/staff-login', { - body: { phone, password }, - }); - assert(result.status === 200 && result.json.token, `staff login failed for ${phone}`); - return result.json.token; - } - - async function approveDealer(phone, token) { - const started = await request(port, 'POST', '/api/auth/dealer-login', { body: { phone } }); - assert(started.status === 201, `dealer login failed for ${phone}: ${started.status}`); - const approved = await request( - port, - 'POST', - `/api/auth/login-requests/${started.json.requestId}/approve`, - { token } - ); - assert(approved.status === 200, `approve failed for ${phone}: ${approved.status}`); - const ready = await request( - port, - 'GET', - `/api/auth/dealer-login/${started.json.requestId}?secret=${encodeURIComponent(started.json.secret)}` - ); - assert(ready.status === 200 && ready.json.token, `dealer token missing for ${phone}`); - return ready.json.token; - } - - const repToken = await staffLogin('94771111111', 'rep-pass-123'); - - const dealerStaff = await request(port, 'POST', '/api/auth/staff-login', { - body: { phone: '94772222222', password: 'rep-pass-123' }, - }); - assert(dealerStaff.status === 401, 'dealer should not use staff login'); - - const repDealer = await request(port, 'POST', '/api/admin/dealers', { - token: repToken, - body: { name: 'Matara Motors', code: 'MTR', district: 'Matara', phone: '0715555555' }, - }); - assert(repDealer.status === 201, `sales rep dealer create failed ${repDealer.status}`); - const repDealers = await request(port, 'GET', '/api/dealers', { token: repToken }); - assert( - repDealers.status === 200 && repDealers.json.data.some((item) => item.code === 'MTR'), - 'sales rep should see the dealer they created' - ); - - const outsideRequest = await request(port, 'POST', '/api/auth/dealer-login', { - body: { phone: '94773333333' }, - }); - assert(outsideRequest.status === 201, 'outside dealer login failed'); - const repQueue = await request(port, 'GET', '/api/auth/login-requests', { token: repToken }); - assert( - repQueue.status === 200 && - !repQueue.json.data.some((item) => item.id === outsideRequest.json.requestId), - 'sales rep should not see an unassigned dealer login' - ); - const repDenied = await request( - port, - 'POST', - `/api/auth/login-requests/${outsideRequest.json.requestId}/approve`, - { token: repToken } - ); - assert(repDenied.status === 403, 'sales rep should not approve an unassigned dealer'); - - const dealerToken = await approveDealer('94772222222', adminToken); - - const ownStock = await request(port, 'POST', '/api/stocks', { - token: dealerToken, - body: { - chassisNumber: 'CH-OWN', - engineNumber: 'EN-OWN', - model: 'gn125', - color: 'Red', - currentDealerId: dealerA.json.data.id, - }, - }); - assert( - ownStock.status === 201 && ownStock.json.data.currentDealerId === dealerA.json.data.id, - `dealer should add stock to their own dealership ${ownStock.status}` - ); - const forbiddenStock = await request(port, 'POST', '/api/stocks', { - token: dealerToken, - body: { - chassisNumber: 'NOPE1', - engineNumber: 'ENG-NOPE', - model: 'gn125', - color: 'Red', - currentDealerId: dealerB.json.data.id, - }, - }); - assert(forbiddenStock.status === 403, 'dealer should not add stock to another dealership'); - - async function addStock(chassis, engine, days, dealerId) { - const created = await request(port, 'POST', '/api/stocks', { - token: adminToken, - body: { - chassisNumber: chassis, - engineNumber: engine, - model: 'gn125', - color: 'Black', - currentDealerId: dealerId, - dateReceived: daysAgo(days), - }, - }); - assert(created.status === 201, `stock create failed for ${chassis}: ${created.status} ${JSON.stringify(created.json)}`); - return created.json.data; - } - - const green = await addStock('CH-GREEN', 'EN-GREEN', 10, dealerA.json.data.id); - const yellow = await addStock('CH-YELLOW', 'EN-YELLOW', 35, dealerA.json.data.id); - const red = await addStock('CH-RED', 'EN-RED', 50, dealerA.json.data.id); - assert(green.badge === 'green' && green.ageInDays === 10, `green badge mismatch ${JSON.stringify(green)}`); - assert(yellow.badge === 'yellow' && yellow.ageInDays === 35, 'yellow badge mismatch'); - assert(red.badge === 'red' && red.ageInDays === 50, 'red badge mismatch'); - assert(green.stageLogDates.received, 'received stage was not logged'); - - const skip = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { - token: adminToken, - body: { stage: 'plateReceived' }, - }); - assert(skip.status === 400, 'skipping stages should fail'); - - const ordered = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { - token: dealerToken, - body: { stage: 'orderedByCustomer' }, - }); - assert(ordered.status === 200, 'dealer stage update failed'); - - const docs = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { - token: dealerToken, - body: { stage: 'documentsProcessed' }, - }); - assert(docs.status === 200, 'documents stage failed'); - - const payMissing = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { - token: dealerToken, - body: { stage: 'paymentApproved' }, - }); - assert(payMissing.status === 400, 'payment without type should fail'); - - const paid = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { - token: dealerToken, - body: { - stage: 'paymentApproved', - paymentType: 'lease', - leaseProviderType: 'thirdPartyFinance', - financeCompanyName: 'Sampath Finance', - }, - }); - assert(paid.status === 200 && paid.json.data.paymentType === 'lease', 'lease payment failed'); - assert(paid.json.data.stageLogDates.paymentApproved, 'payment stage log missing'); - - for (const stage of ['orderedByCustomer', 'documentsProcessed']) { - const stepped = await request(port, 'PATCH', '/api/stocks/CH-RED/stage', { - token: dealerToken, - body: { stage }, - }); - assert(stepped.status === 200, `CH-RED stage ${stage} failed`); - } - const bothMissingName = await request(port, 'PATCH', '/api/stocks/CH-RED/stage', { - token: dealerToken, - body: { stage: 'paymentApproved', paymentType: 'lease', leaseProviderType: 'both' }, - }); - assert(bothMissingName.status === 400, 'both lease options should require a finance company'); - const bothPaid = await request(port, 'PATCH', '/api/stocks/CH-RED/stage', { - token: dealerToken, - body: { - stage: 'paymentApproved', - paymentType: 'lease', - leaseProviderType: 'both', - financeCompanyName: 'GCI Finance', - }, - }); - assert( - bothPaid.status === 200 && - bothPaid.json.data.leaseProviderType === 'both' && - bothPaid.json.data.financeCompanyName === 'GCI Finance', - 'lease with both GCI and finance failed' - ); - - const registered = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { - token: dealerToken, - body: { stage: 'rmvRegistration' }, - }); - assert(registered.status === 200, 'rmv stage failed'); - const plateMissing = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { - token: dealerToken, - body: { stage: 'plateReceived' }, - }); - assert(plateMissing.status === 400, 'plate received without a number should fail'); - const plated = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { - token: dealerToken, - body: { stage: 'plateReceived', plateNumber: 'WP ABC-1234' }, - }); - assert( - plated.status === 200 && plated.json.data.plateNumber === 'WP ABC-1234', - 'saving the plate number failed' - ); - - const outside = await request(port, 'POST', '/api/stocks/CH-YELLOW/transfer', { - token: repToken, - body: { dealerId: dealerC.json.data.id }, - }); - assert(outside.status === 403, 'rep should not transfer outside assignment'); - - const moved = await request(port, 'POST', '/api/stocks/CH-YELLOW/transfer', { - token: repToken, - body: { dealerId: dealerB.json.data.id }, - }); - assert(moved.status === 200 && moved.json.data.currentDealerId === dealerB.json.data.id, 'transfer failed'); - - const eventBad = await request(port, 'POST', '/api/events', { - token: dealerToken, - body: { - dealerId: dealerA.json.data.id, - planType: 'monthlySpecial', - title: 'April push', - description: 'Showroom weekend', - expense: 15000, - imageUrls: [], - }, - }); - assert(eventBad.status === 400, 'monthly plan without month should fail'); - - const eventOk = await request(port, 'POST', '/api/events', { - token: dealerToken, - body: { - dealerId: dealerA.json.data.id, - planType: 'monthlySpecial', - month: 4, - year: 2026, - title: 'April push', - description: 'Showroom weekend', - expense: 15000, - imageUrls: ['https://example.com/poster.jpg'], - }, - }); - assert(eventOk.status === 201, 'event create failed'); - - const otherDealerEvent = await request(port, 'POST', '/api/events', { - token: dealerToken, - body: { - dealerId: dealerB.json.data.id, - planType: 'general', - title: 'Nope', - description: 'Wrong dealer', - expense: 1, - imageUrls: [], - }, - }); - assert(otherDealerEvent.status === 403, 'dealer should not post events for another dealer'); - - const pointForbidden = await request(port, 'POST', '/api/service-points', { - token: dealerToken, - body: { name: 'Hidden', district: 'Ratnapura' }, - }); - assert(pointForbidden.status === 403, 'dealer should not add service points'); - - const point = await request(port, 'POST', '/api/service-points', { - token: repToken, - body: { - name: 'Ratnapura Cycle Repair', - district: 'Ratnapura', - address: 'Main street', - notes: 'engine repair', - }, - }); - assert(point.status === 201, 'service point create failed'); - - const found = await request( - port, - 'GET', - '/api/service-points?district=Ratnapura&search=repair', - { token: dealerToken } - ); - assert( - found.status === 200 && found.json.data.some((item) => item.name === 'Ratnapura Cycle Repair'), - 'service point search failed' - ); - - const reassigned = await request(port, 'PATCH', '/api/admin/assign-dealer', { - token: adminToken, - body: { salesRepId: rep.json.data.id, dealerId: dealerC.json.data.id, assigned: true }, - }); - assert( - reassigned.status === 200 && reassigned.json.data.assignedDealerIds.includes(dealerC.json.data.id), - 'assign dealer failed' - ); - - const dealerD = await request(port, 'POST', '/api/admin/dealers', { - token: adminToken, - body: { name: 'Delete Motors', code: 'DEL', district: 'Colombo', phone: '94776666666' }, - }); - assert(dealerD.status === 201, 'dealer for delete test failed'); - await addStock('CH-DEL', 'EN-DEL', 1, dealerD.json.data.id); - const transferred = await request(port, 'POST', '/api/stocks/CH-DEL/transfer', { - token: adminToken, - body: { dealerId: dealerA.json.data.id }, - }); - assert(transferred.status === 200, 'transfer before delete failed'); - const dealerDToken = await approveDealer('94776666666', adminToken); - const doomedEvent = await request(port, 'POST', '/api/events', { - token: dealerDToken, - body: { - dealerId: dealerD.json.data.id, - planType: 'general', - title: 'Going away', - description: 'Removed with the dealer', - expense: 10, - imageUrls: [], - }, - }); - assert(doomedEvent.status === 201, 'event before delete failed'); - - const repDelete = await request(port, 'DELETE', `/api/admin/dealers/${dealerD.json.data.id}`, { - token: repToken, - }); - assert(repDelete.status === 403, 'sales rep should not delete a dealer'); - - const removed = await request(port, 'DELETE', `/api/admin/dealers/${dealerD.json.data.id}`, { - token: adminToken, - }); - assert(removed.status === 200, `dealer delete failed ${removed.status} ${JSON.stringify(removed.json)}`); - const dealerGone = await prisma.dealer.findUnique({ where: { id: dealerD.json.data.id } }); - const loginGone = await prisma.user.findUnique({ where: { phone: '94776666666' } }); - const eventGone = await prisma.event.findUnique({ where: { id: doomedEvent.json.data.id } }); - const stockKept = await prisma.stock.findUnique({ where: { chassisNumber: 'CH-DEL' } }); - assert(!dealerGone && !loginGone && !eventGone, 'dealer, login, and plans should be removed'); - assert(stockKept && stockKept.currentDealerId === dealerA.json.data.id, 'stock already transferred should stay'); - - const missingDelete = await request(port, 'DELETE', `/api/admin/dealers/${dealerD.json.data.id}`, { - token: adminToken, - }); - assert(missingDelete.status === 404, 'deleting a missing dealer should be 404'); -} - -async function main() { - const server = await new Promise((resolve) => { - const listening = app.listen(0, '127.0.0.1', () => resolve(listening)); - }); - try { - await run(server.address().port); - console.log('API checks passed'); - } finally { - await new Promise((resolve) => server.close(resolve)); - await prisma.$disconnect(); - for (const file of [dbPath, `${dbPath}-journal`, `${dbPath}-wal`, `${dbPath}-shm`]) { - if (fs.existsSync(file)) fs.unlinkSync(file); - } - } -} - -main().catch((error) => { - console.error(error); - process.exitCode = 1; -}); +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); + +const root = path.join(__dirname, '..'); +process.chdir(root); + +const dbPath = path.join(root, 'data', 'api-check.db'); +for (const file of [dbPath, `${dbPath}-journal`, `${dbPath}-wal`, `${dbPath}-shm`]) { + if (fs.existsSync(file)) fs.unlinkSync(file); +} + +process.env.DATABASE_URL = 'file:../data/api-check.db'; +process.env.JWT_SECRET = 'api-check-secret'; +process.env.TEXTLK_API_TOKEN = ''; +process.env.SEED_ADMIN_NAME = 'Super Admin'; +process.env.SEED_ADMIN_PHONE = '94770000001'; + +execSync('npx prisma db push --skip-generate --accept-data-loss', { + cwd: root, + stdio: 'inherit', + env: process.env, +}); + +const bcrypt = require('bcryptjs'); +const app = require('../src/app'); +const prisma = require('../src/db'); +const { ageBadge } = require('../src/lib/stockRules'); + +function assert(condition, message) { + if (!condition) throw new Error(message); +} + +async function request(port, method, urlPath, { token, body } = {}) { + const response = await fetch(`http://127.0.0.1:${port}${urlPath}`, { + method, + headers: { + 'Content-Type': 'application/json', + ...(token ? { Authorization: `Bearer ${token}` } : {}), + }, + body: body === undefined ? undefined : JSON.stringify(body), + }); + const text = await response.text(); + let json = null; + if (text) { + try { + json = JSON.parse(text); + } catch { + json = { raw: text }; + } + } + return { status: response.status, json }; +} + +function daysAgo(days) { + return new Date(Date.now() - days * 24 * 60 * 60 * 1000).toISOString(); +} + +async function run(port) { + assert(ageBadge(29) === 'green', '29 days is green'); + assert(ageBadge(30) === 'yellow', '30 days is yellow'); + assert(ageBadge(45) === 'yellow', '45 days is yellow'); + assert(ageBadge(46) === 'red', '46 days is red'); + + const unknown = await request(port, 'POST', '/api/auth/dealer-login', { + body: { phone: '94770000099' }, + }); + assert(unknown.status === 404, `unknown phone should be 404, got ${unknown.status}`); + + const adminHash = await bcrypt.hash('admin-pass-123', 10); + await prisma.user.create({ + data: { + name: 'Super Admin', + phone: '94770000001', + role: 'superAdmin', + passwordHash: adminHash, + }, + }); + + const badPassword = await request(port, 'POST', '/api/auth/staff-login', { + body: { phone: '94770000001', password: 'wrong-password' }, + }); + assert(badPassword.status === 401, 'wrong password should be rejected'); + + const verified = await request(port, 'POST', '/api/auth/staff-login', { + body: { phone: '94770000001', password: 'admin-pass-123' }, + }); + assert(verified.status === 200 && verified.json.token, 'staff login failed'); + const adminToken = verified.json.token; + + const me = await request(port, 'GET', '/api/auth/me', { token: adminToken }); + assert(me.status === 200 && me.json.role === 'superAdmin', '/me failed'); + const missing = await request(port, 'GET', '/api/auth/me'); + assert(missing.status === 401, 'missing token should be 401'); + + const dealerMissingPhone = await request(port, 'POST', '/api/admin/dealers', { + token: adminToken, + body: { name: 'No Phone', code: 'NONE' }, + }); + assert(dealerMissingPhone.status === 400, 'dealer without a phone should fail'); + + const dealerA = await request(port, 'POST', '/api/admin/dealers', { + token: adminToken, + body: { name: 'Kandy Motors', code: 'KDY', district: 'Kandy', phone: '94772222222' }, + }); + const dealerB = await request(port, 'POST', '/api/admin/dealers', { + token: adminToken, + body: { name: 'Galle Motors', code: 'GAL', district: 'Galle', phone: '94774444444' }, + }); + const dealerC = await request(port, 'POST', '/api/admin/dealers', { + token: adminToken, + body: { name: 'Jaffna Motors', code: 'JAF', district: 'Jaffna', phone: '94773333333' }, + }); + assert(dealerA.status === 201 && dealerB.status === 201 && dealerC.status === 201, 'dealer create failed'); + const kandyLogin = await prisma.user.findUnique({ where: { phone: '94772222222' } }); + assert( + kandyLogin && kandyLogin.role === 'dealer' && kandyLogin.dealerId === dealerA.json.data.id, + 'creating a dealer should create its login' + ); + + const rep = await request(port, 'POST', '/api/admin/sales-reps', { + token: adminToken, + body: { + name: 'Nimal Perera', + phone: '94771111111', + password: 'rep-pass-123', + dealerIds: [dealerA.json.data.id, dealerB.json.data.id], + }, + }); + assert(rep.status === 201, `sales rep create failed ${rep.status}`); + + async function staffLogin(phone, password) { + const result = await request(port, 'POST', '/api/auth/staff-login', { + body: { phone, password }, + }); + assert(result.status === 200 && result.json.token, `staff login failed for ${phone}`); + return result.json.token; + } + + async function approveDealer(phone, token) { + const started = await request(port, 'POST', '/api/auth/dealer-login', { body: { phone } }); + assert(started.status === 201, `dealer login failed for ${phone}: ${started.status}`); + const approved = await request( + port, + 'POST', + `/api/auth/login-requests/${started.json.requestId}/approve`, + { token } + ); + assert(approved.status === 200, `approve failed for ${phone}: ${approved.status}`); + const ready = await request( + port, + 'GET', + `/api/auth/dealer-login/${started.json.requestId}?secret=${encodeURIComponent(started.json.secret)}` + ); + assert(ready.status === 200 && ready.json.token, `dealer token missing for ${phone}`); + return ready.json.token; + } + + const repToken = await staffLogin('94771111111', 'rep-pass-123'); + + const dealerStaff = await request(port, 'POST', '/api/auth/staff-login', { + body: { phone: '94772222222', password: 'rep-pass-123' }, + }); + assert(dealerStaff.status === 401, 'dealer should not use staff login'); + + const repDealer = await request(port, 'POST', '/api/admin/dealers', { + token: repToken, + body: { name: 'Matara Motors', code: 'MTR', district: 'Matara', phone: '0715555555' }, + }); + assert(repDealer.status === 201, `sales rep dealer create failed ${repDealer.status}`); + const repDealers = await request(port, 'GET', '/api/dealers', { token: repToken }); + assert( + repDealers.status === 200 && repDealers.json.data.some((item) => item.code === 'MTR'), + 'sales rep should see the dealer they created' + ); + + const outsideRequest = await request(port, 'POST', '/api/auth/dealer-login', { + body: { phone: '94773333333' }, + }); + assert(outsideRequest.status === 201, 'outside dealer login failed'); + const repQueue = await request(port, 'GET', '/api/auth/login-requests', { token: repToken }); + assert( + repQueue.status === 200 && + !repQueue.json.data.some((item) => item.id === outsideRequest.json.requestId), + 'sales rep should not see an unassigned dealer login' + ); + const repDenied = await request( + port, + 'POST', + `/api/auth/login-requests/${outsideRequest.json.requestId}/approve`, + { token: repToken } + ); + assert(repDenied.status === 403, 'sales rep should not approve an unassigned dealer'); + + const dealerToken = await approveDealer('94772222222', adminToken); + + const ownStock = await request(port, 'POST', '/api/stocks', { + token: dealerToken, + body: { + chassisNumber: 'CH-OWN', + engineNumber: 'EN-OWN', + model: 'gn125', + color: 'Red', + currentDealerId: dealerA.json.data.id, + }, + }); + assert( + ownStock.status === 201 && ownStock.json.data.currentDealerId === dealerA.json.data.id, + `dealer should add stock to their own dealership ${ownStock.status}` + ); + const forbiddenStock = await request(port, 'POST', '/api/stocks', { + token: dealerToken, + body: { + chassisNumber: 'NOPE1', + engineNumber: 'ENG-NOPE', + model: 'gn125', + color: 'Red', + currentDealerId: dealerB.json.data.id, + }, + }); + assert(forbiddenStock.status === 403, 'dealer should not add stock to another dealership'); + + async function addStock(chassis, engine, days, dealerId) { + const created = await request(port, 'POST', '/api/stocks', { + token: adminToken, + body: { + chassisNumber: chassis, + engineNumber: engine, + model: 'gn125', + color: 'Black', + currentDealerId: dealerId, + dateReceived: daysAgo(days), + }, + }); + assert(created.status === 201, `stock create failed for ${chassis}: ${created.status} ${JSON.stringify(created.json)}`); + return created.json.data; + } + + const green = await addStock('CH-GREEN', 'EN-GREEN', 10, dealerA.json.data.id); + const yellow = await addStock('CH-YELLOW', 'EN-YELLOW', 35, dealerA.json.data.id); + const red = await addStock('CH-RED', 'EN-RED', 50, dealerA.json.data.id); + assert(green.badge === 'green' && green.ageInDays === 10, `green badge mismatch ${JSON.stringify(green)}`); + assert(yellow.badge === 'yellow' && yellow.ageInDays === 35, 'yellow badge mismatch'); + assert(red.badge === 'red' && red.ageInDays === 50, 'red badge mismatch'); + assert(green.stageLogDates.received, 'received stage was not logged'); + + const skip = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { + token: adminToken, + body: { stage: 'plateReceived' }, + }); + assert(skip.status === 400, 'skipping stages should fail'); + + const ordered = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { + token: dealerToken, + body: { stage: 'orderedByCustomer' }, + }); + assert(ordered.status === 200, 'dealer stage update failed'); + + const docs = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { + token: dealerToken, + body: { stage: 'documentsProcessed' }, + }); + assert(docs.status === 200, 'documents stage failed'); + + const payMissing = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { + token: dealerToken, + body: { stage: 'paymentApproved' }, + }); + assert(payMissing.status === 400, 'payment without type should fail'); + + const paid = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { + token: dealerToken, + body: { + stage: 'paymentApproved', + paymentType: 'lease', + leaseProviderType: 'thirdPartyFinance', + financeCompanyName: 'Sampath Finance', + }, + }); + assert(paid.status === 200 && paid.json.data.paymentType === 'lease', 'lease payment failed'); + assert(paid.json.data.stageLogDates.paymentApproved, 'payment stage log missing'); + + for (const stage of ['orderedByCustomer', 'documentsProcessed']) { + const stepped = await request(port, 'PATCH', '/api/stocks/CH-RED/stage', { + token: dealerToken, + body: { stage }, + }); + assert(stepped.status === 200, `CH-RED stage ${stage} failed`); + } + const bothMissingName = await request(port, 'PATCH', '/api/stocks/CH-RED/stage', { + token: dealerToken, + body: { stage: 'paymentApproved', paymentType: 'lease', leaseProviderType: 'both' }, + }); + assert(bothMissingName.status === 400, 'both lease options should require a finance company'); + const bothPaid = await request(port, 'PATCH', '/api/stocks/CH-RED/stage', { + token: dealerToken, + body: { + stage: 'paymentApproved', + paymentType: 'lease', + leaseProviderType: 'both', + financeCompanyName: 'GCI Finance', + }, + }); + assert( + bothPaid.status === 200 && + bothPaid.json.data.leaseProviderType === 'both' && + bothPaid.json.data.financeCompanyName === 'GCI Finance', + 'lease with both GCI and finance failed' + ); + + const registered = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { + token: dealerToken, + body: { stage: 'rmvRegistration' }, + }); + assert(registered.status === 200, 'rmv stage failed'); + const plateMissing = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { + token: dealerToken, + body: { stage: 'plateReceived' }, + }); + assert(plateMissing.status === 400, 'plate received without a number should fail'); + const plated = await request(port, 'PATCH', '/api/stocks/CH-GREEN/stage', { + token: dealerToken, + body: { stage: 'plateReceived', plateNumber: 'WP ABC-1234' }, + }); + assert( + plated.status === 200 && plated.json.data.plateNumber === 'WP ABC-1234', + 'saving the plate number failed' + ); + + const outside = await request(port, 'POST', '/api/stocks/CH-YELLOW/transfer', { + token: repToken, + body: { dealerId: dealerC.json.data.id }, + }); + assert(outside.status === 403, 'rep should not transfer outside assignment'); + + const moved = await request(port, 'POST', '/api/stocks/CH-YELLOW/transfer', { + token: repToken, + body: { dealerId: dealerB.json.data.id }, + }); + assert(moved.status === 200 && moved.json.data.currentDealerId === dealerB.json.data.id, 'transfer failed'); + + const dealerUndo = await request(port, 'POST', '/api/stocks/CH-RED/stage/undo', { + token: dealerToken, + }); + assert(dealerUndo.status === 403, 'dealer should not undo a stage'); + + const undonePayment = await request(port, 'POST', '/api/stocks/CH-RED/stage/undo', { + token: repToken, + }); + assert( + undonePayment.status === 200 && + undonePayment.json.data.currentStage === 'documentsProcessed' && + undonePayment.json.data.paymentType == null && + undonePayment.json.data.leaseProviderType == null && + undonePayment.json.data.financeCompanyName == null && + !undonePayment.json.data.stageLogDates.paymentApproved, + `undo payment stage failed ${JSON.stringify(undonePayment.json)}` + ); + const undoneDocs = await request(port, 'POST', '/api/stocks/CH-RED/stage/undo', { + token: repToken, + }); + assert( + undoneDocs.status === 200 && undoneDocs.json.data.currentStage === 'orderedByCustomer', + 'undo documents stage failed' + ); + const undoneOrder = await request(port, 'POST', '/api/stocks/CH-RED/stage/undo', { + token: repToken, + }); + assert( + undoneOrder.status === 200 && undoneOrder.json.data.currentStage === 'received', + 'undo ordered stage failed' + ); + const undoReceived = await request(port, 'POST', '/api/stocks/CH-RED/stage/undo', { + token: repToken, + }); + assert(undoReceived.status === 400, 'received stage should not be undoable'); + + const undonePlate = await request(port, 'POST', '/api/stocks/CH-GREEN/stage/undo', { + token: adminToken, + }); + assert( + undonePlate.status === 200 && + undonePlate.json.data.currentStage === 'rmvRegistration' && + undonePlate.json.data.plateNumber == null && + !undonePlate.json.data.stageLogDates.plateReceived, + `undo plate stage failed ${JSON.stringify(undonePlate.json)}` + ); + + await addStock('CH-OUT', 'EN-OUT', 1, dealerC.json.data.id); + const repUndoOutside = await request(port, 'POST', '/api/stocks/CH-OUT/stage/undo', { + token: repToken, + }); + assert(repUndoOutside.status === 403, 'sales rep should not undo stock outside assignment'); + const repDeleteOutside = await request(port, 'DELETE', '/api/stocks/CH-OUT', { token: repToken }); + assert(repDeleteOutside.status === 403, 'sales rep should not delete stock outside assignment'); + const dealerDelete = await request(port, 'DELETE', '/api/stocks/CH-YELLOW', { token: dealerToken }); + assert(dealerDelete.status === 403, 'dealer should not delete a bike'); + const deleted = await request(port, 'DELETE', '/api/stocks/CH-YELLOW', { token: repToken }); + assert(deleted.status === 200, `stock delete failed ${deleted.status} ${JSON.stringify(deleted.json)}`); + const stockGone = await prisma.stock.findUnique({ where: { chassisNumber: 'CH-YELLOW' } }); + const transferGone = await prisma.stockTransfer.findFirst({ where: { stockId: moved.json.data.id } }); + assert(!stockGone && !transferGone, 'deleted bike and its transfers should be gone'); + const missingStock = await request(port, 'DELETE', '/api/stocks/CH-YELLOW', { token: adminToken }); + assert(missingStock.status === 404, 'deleting a missing bike should be 404'); + const missingUndo = await request(port, 'POST', '/api/stocks/NO-SUCH/stage/undo', { + token: adminToken, + }); + assert(missingUndo.status === 404, 'undo of a missing bike should be 404'); + + const eventBad = await request(port, 'POST', '/api/events', { + token: dealerToken, + body: { + dealerId: dealerA.json.data.id, + planType: 'monthlySpecial', + title: 'April push', + description: 'Showroom weekend', + expense: 15000, + imageUrls: [], + }, + }); + assert(eventBad.status === 400, 'monthly plan without month should fail'); + + const eventOk = await request(port, 'POST', '/api/events', { + token: dealerToken, + body: { + dealerId: dealerA.json.data.id, + planType: 'monthlySpecial', + month: 4, + year: 2026, + title: 'April push', + description: 'Showroom weekend', + expense: 15000, + imageUrls: ['https://example.com/poster.jpg'], + }, + }); + assert(eventOk.status === 201, 'event create failed'); + + const otherDealerEvent = await request(port, 'POST', '/api/events', { + token: dealerToken, + body: { + dealerId: dealerB.json.data.id, + planType: 'general', + title: 'Nope', + description: 'Wrong dealer', + expense: 1, + imageUrls: [], + }, + }); + assert(otherDealerEvent.status === 403, 'dealer should not post events for another dealer'); + + const pointForbidden = await request(port, 'POST', '/api/service-points', { + token: dealerToken, + body: { name: 'Hidden', district: 'Ratnapura' }, + }); + assert(pointForbidden.status === 403, 'dealer should not add service points'); + + const point = await request(port, 'POST', '/api/service-points', { + token: repToken, + body: { + name: 'Ratnapura Cycle Repair', + district: 'Ratnapura', + address: 'Main street', + notes: 'engine repair', + }, + }); + assert(point.status === 201, 'service point create failed'); + + const found = await request( + port, + 'GET', + '/api/service-points?district=Ratnapura&search=repair', + { token: dealerToken } + ); + assert( + found.status === 200 && found.json.data.some((item) => item.name === 'Ratnapura Cycle Repair'), + 'service point search failed' + ); + + const reassigned = await request(port, 'PATCH', '/api/admin/assign-dealer', { + token: adminToken, + body: { salesRepId: rep.json.data.id, dealerId: dealerC.json.data.id, assigned: true }, + }); + assert( + reassigned.status === 200 && reassigned.json.data.assignedDealerIds.includes(dealerC.json.data.id), + 'assign dealer failed' + ); + + const dealerD = await request(port, 'POST', '/api/admin/dealers', { + token: adminToken, + body: { name: 'Delete Motors', code: 'DEL', district: 'Colombo', phone: '94776666666' }, + }); + assert(dealerD.status === 201, 'dealer for delete test failed'); + await addStock('CH-DEL', 'EN-DEL', 1, dealerD.json.data.id); + const transferred = await request(port, 'POST', '/api/stocks/CH-DEL/transfer', { + token: adminToken, + body: { dealerId: dealerA.json.data.id }, + }); + assert(transferred.status === 200, 'transfer before delete failed'); + const dealerDToken = await approveDealer('94776666666', adminToken); + const doomedEvent = await request(port, 'POST', '/api/events', { + token: dealerDToken, + body: { + dealerId: dealerD.json.data.id, + planType: 'general', + title: 'Going away', + description: 'Removed with the dealer', + expense: 10, + imageUrls: [], + }, + }); + assert(doomedEvent.status === 201, 'event before delete failed'); + + const repDelete = await request(port, 'DELETE', `/api/admin/dealers/${dealerD.json.data.id}`, { + token: repToken, + }); + assert(repDelete.status === 403, 'sales rep should not delete a dealer'); + + const removed = await request(port, 'DELETE', `/api/admin/dealers/${dealerD.json.data.id}`, { + token: adminToken, + }); + assert(removed.status === 200, `dealer delete failed ${removed.status} ${JSON.stringify(removed.json)}`); + const dealerGone = await prisma.dealer.findUnique({ where: { id: dealerD.json.data.id } }); + const loginGone = await prisma.user.findUnique({ where: { phone: '94776666666' } }); + const eventGone = await prisma.event.findUnique({ where: { id: doomedEvent.json.data.id } }); + const stockKept = await prisma.stock.findUnique({ where: { chassisNumber: 'CH-DEL' } }); + assert(!dealerGone && !loginGone && !eventGone, 'dealer, login, and plans should be removed'); + assert(stockKept && stockKept.currentDealerId === dealerA.json.data.id, 'stock already transferred should stay'); + + const missingDelete = await request(port, 'DELETE', `/api/admin/dealers/${dealerD.json.data.id}`, { + token: adminToken, + }); + assert(missingDelete.status === 404, 'deleting a missing dealer should be 404'); +} + +async function main() { + const server = await new Promise((resolve) => { + const listening = app.listen(0, '127.0.0.1', () => resolve(listening)); + }); + try { + await run(server.address().port); + console.log('API checks passed'); + } finally { + await new Promise((resolve) => server.close(resolve)); + await prisma.$disconnect(); + for (const file of [dbPath, `${dbPath}-journal`, `${dbPath}-wal`, `${dbPath}-shm`]) { + if (fs.existsSync(file)) fs.unlinkSync(file); + } + } +} + +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/src/app.js b/src/app.js index 4ca3ce6..93f0002 100644 --- a/src/app.js +++ b/src/app.js @@ -1,46 +1,46 @@ -const path = require('path'); -const express = require('express'); -const cors = require('cors'); -require('dotenv').config({ path: path.join(__dirname, '..', '.env') }); - -const authRoutes = require('./routes/auth'); -const dealerRoutes = require('./routes/dealers'); -const stockRoutes = require('./routes/stocks'); -const eventRoutes = require('./routes/events'); -const servicePointRoutes = require('./routes/servicePoints'); -const adminRoutes = require('./routes/admin'); - -const app = express(); - -app.use(cors()); -app.use(express.json()); - -app.get('/api/health', (req, res) => { - res.json({ success: true }); -}); - -app.use('/api/auth', authRoutes); -app.use('/api/dealers', dealerRoutes); -app.use('/api/stocks', stockRoutes); -app.use('/api/events', eventRoutes); -app.use('/api/service-points', servicePointRoutes); -app.use('/api/admin', adminRoutes); - -app.use((req, res) => { - res.status(404).json({ success: false, message: 'Not found' }); -}); - -app.use((err, req, res, next) => { - if (res.headersSent) return next(err); - if (err.code === 'P2002') { - return res.status(409).json({ success: false, message: 'Already exists' }); - } - const status = err.status || 500; - if (status >= 500) console.error(err); - return res.status(status).json({ - success: false, - message: status >= 500 ? 'Server error' : err.message, - }); -}); - -module.exports = app; +const path = require('path'); +const express = require('express'); +const cors = require('cors'); +require('dotenv').config({ path: path.join(__dirname, '..', '.env') }); + +const authRoutes = require('./routes/auth'); +const dealerRoutes = require('./routes/dealers'); +const stockRoutes = require('./routes/stocks'); +const eventRoutes = require('./routes/events'); +const servicePointRoutes = require('./routes/servicePoints'); +const adminRoutes = require('./routes/admin'); + +const app = express(); + +app.use(cors()); +app.use(express.json()); + +app.get('/api/health', (req, res) => { + res.json({ success: true }); +}); + +app.use('/api/auth', authRoutes); +app.use('/api/dealers', dealerRoutes); +app.use('/api/stocks', stockRoutes); +app.use('/api/events', eventRoutes); +app.use('/api/service-points', servicePointRoutes); +app.use('/api/admin', adminRoutes); + +app.use((req, res) => { + res.status(404).json({ success: false, message: 'Not found' }); +}); + +app.use((err, req, res, next) => { + if (res.headersSent) return next(err); + if (err.code === 'P2002') { + return res.status(409).json({ success: false, message: 'Already exists' }); + } + const status = err.status || 500; + if (status >= 500) console.error(err); + return res.status(status).json({ + success: false, + message: status >= 500 ? 'Server error' : err.message, + }); +}); + +module.exports = app; diff --git a/src/db.js b/src/db.js index 0dbc802..f7fd290 100644 --- a/src/db.js +++ b/src/db.js @@ -1,5 +1,5 @@ -const { PrismaClient } = require('@prisma/client'); - -const prisma = new PrismaClient(); - -module.exports = prisma; +const { PrismaClient } = require('@prisma/client'); + +const prisma = new PrismaClient(); + +module.exports = prisma; diff --git a/src/index.js b/src/index.js index cb73560..ebaabd4 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,6 @@ -const app = require('./app'); - -const port = Number(process.env.PORT) || 3000; -app.listen(port, () => { - console.log(`API listening on ${port}`); -}); +const app = require('./app'); + +const port = Number(process.env.PORT) || 3000; +app.listen(port, () => { + console.log(`API listening on ${port}`); +}); diff --git a/src/lib/access.js b/src/lib/access.js index 35fe6df..972c06a 100644 --- a/src/lib/access.js +++ b/src/lib/access.js @@ -1,30 +1,30 @@ -function assignedDealerIds(user) { - return (user.assignments || []).map((assignment) => assignment.dealerId); -} - -function canAccessDealer(user, dealerId) { - if (!dealerId) return false; - if (user.role === 'superAdmin') return true; - if (user.role === 'dealer') return user.dealerId === dealerId; - if (user.role === 'salesRep') return assignedDealerIds(user).includes(dealerId); - return false; -} - -function dealerScopeWhere(user) { - if (user.role === 'superAdmin') return {}; - if (user.role === 'dealer') return { currentDealerId: user.dealerId || '__none__' }; - return { currentDealerId: { in: assignedDealerIds(user) } }; -} - -function eventScopeWhere(user) { - if (user.role === 'superAdmin') return {}; - if (user.role === 'dealer') return { dealerId: user.dealerId || '__none__' }; - return { dealerId: { in: assignedDealerIds(user) } }; -} - -module.exports = { - assignedDealerIds, - canAccessDealer, - dealerScopeWhere, - eventScopeWhere, -}; +function assignedDealerIds(user) { + return (user.assignments || []).map((assignment) => assignment.dealerId); +} + +function canAccessDealer(user, dealerId) { + if (!dealerId) return false; + if (user.role === 'superAdmin') return true; + if (user.role === 'dealer') return user.dealerId === dealerId; + if (user.role === 'salesRep') return assignedDealerIds(user).includes(dealerId); + return false; +} + +function dealerScopeWhere(user) { + if (user.role === 'superAdmin') return {}; + if (user.role === 'dealer') return { currentDealerId: user.dealerId || '__none__' }; + return { currentDealerId: { in: assignedDealerIds(user) } }; +} + +function eventScopeWhere(user) { + if (user.role === 'superAdmin') return {}; + if (user.role === 'dealer') return { dealerId: user.dealerId || '__none__' }; + return { dealerId: { in: assignedDealerIds(user) } }; +} + +module.exports = { + assignedDealerIds, + canAccessDealer, + dealerScopeWhere, + eventScopeWhere, +}; diff --git a/src/lib/errors.js b/src/lib/errors.js index 7ef5460..bce1ab5 100644 --- a/src/lib/errors.js +++ b/src/lib/errors.js @@ -1,13 +1,13 @@ -function httpError(status, message) { - const err = new Error(message); - err.status = status; - return err; -} - -function asyncHandler(fn) { - return (req, res, next) => { - Promise.resolve(fn(req, res, next)).catch(next); - }; -} - -module.exports = { httpError, asyncHandler }; +function httpError(status, message) { + const err = new Error(message); + err.status = status; + return err; +} + +function asyncHandler(fn) { + return (req, res, next) => { + Promise.resolve(fn(req, res, next)).catch(next); + }; +} + +module.exports = { httpError, asyncHandler }; diff --git a/src/lib/passwords.js b/src/lib/passwords.js index 578ef11..7f6cab7 100644 --- a/src/lib/passwords.js +++ b/src/lib/passwords.js @@ -1,14 +1,14 @@ -const bcrypt = require('bcryptjs'); - -const ROUNDS = 10; - -function hashPassword(password) { - return bcrypt.hash(password, ROUNDS); -} - -function checkPassword(password, passwordHash) { - if (!passwordHash) return false; - return bcrypt.compare(password, passwordHash); -} - -module.exports = { hashPassword, checkPassword }; +const bcrypt = require('bcryptjs'); + +const ROUNDS = 10; + +function hashPassword(password) { + return bcrypt.hash(password, ROUNDS); +} + +function checkPassword(password, passwordHash) { + if (!passwordHash) return false; + return bcrypt.compare(password, passwordHash); +} + +module.exports = { hashPassword, checkPassword }; diff --git a/src/lib/phone.js b/src/lib/phone.js index 29dc7d0..01e7044 100644 --- a/src/lib/phone.js +++ b/src/lib/phone.js @@ -1,14 +1,14 @@ -const PHONE_PATTERN = /^947\d{8}$/; - -function normalizePhone(value) { - let phone = String(value || '').trim().replace(/[\s-]/g, ''); - if (phone.startsWith('+')) phone = phone.slice(1); - if (/^0\d{9}$/.test(phone)) phone = `94${phone.slice(1)}`; - return phone; -} - -function isValidPhone(phone) { - return PHONE_PATTERN.test(phone); -} - -module.exports = { PHONE_PATTERN, normalizePhone, isValidPhone }; +const PHONE_PATTERN = /^947\d{8}$/; + +function normalizePhone(value) { + let phone = String(value || '').trim().replace(/[\s-]/g, ''); + if (phone.startsWith('+')) phone = phone.slice(1); + if (/^0\d{9}$/.test(phone)) phone = `94${phone.slice(1)}`; + return phone; +} + +function isValidPhone(phone) { + return PHONE_PATTERN.test(phone); +} + +module.exports = { PHONE_PATTERN, normalizePhone, isValidPhone }; diff --git a/src/lib/stockRules.js b/src/lib/stockRules.js index cb0fcea..8381d63 100644 --- a/src/lib/stockRules.js +++ b/src/lib/stockRules.js @@ -1,70 +1,70 @@ -const STAGES = [ - 'received', - 'orderedByCustomer', - 'documentsProcessed', - 'paymentApproved', - 'rmvRegistration', - 'plateReceived', -]; - -const MODELS = ['gn125', 'boxer125', 'click150i']; -const PAYMENT_TYPES = ['cash', 'lease']; -const LEASE_PROVIDERS = ['gci', 'thirdPartyFinance', 'both']; - -function ageInDays(dateReceived, now = Date.now()) { - const diffTime = Math.abs(now - new Date(dateReceived).getTime()); - return Math.floor(diffTime / (1000 * 60 * 60 * 24)); -} - -function ageBadge(days) { - if (days < 30) return 'green'; - if (days <= 45) return 'yellow'; - return 'red'; -} - -function nextStage(current) { - const index = STAGES.indexOf(current); - if (index < 0 || index >= STAGES.length - 1) return null; - return STAGES[index + 1]; -} - -function stageLogMap(logs) { - const map = {}; - for (const log of logs) { - map[log.stage] = log.loggedAt; - } - return map; -} - -function serializeStock(stock) { - const days = ageInDays(stock.dateReceived); - return { - id: stock.id, - chassisNumber: stock.chassisNumber, - engineNumber: stock.engineNumber, - model: stock.model, - color: stock.color, - currentDealerId: stock.currentDealerId, - dealerName: stock.currentDealer ? stock.currentDealer.name : null, - dateReceived: stock.dateReceived, - currentStage: stock.currentStage, - stageLogDates: stageLogMap(stock.stageLogs || []), - paymentType: stock.paymentType, - leaseProviderType: stock.leaseProviderType, - financeCompanyName: stock.financeCompanyName, - plateNumber: stock.plateNumber, - ageInDays: days, - badge: ageBadge(days), - }; -} - -module.exports = { - STAGES, - MODELS, - PAYMENT_TYPES, - LEASE_PROVIDERS, - ageInDays, - ageBadge, - nextStage, - serializeStock, -}; +const STAGES = [ + 'received', + 'orderedByCustomer', + 'documentsProcessed', + 'paymentApproved', + 'rmvRegistration', + 'plateReceived', +]; + +const MODELS = ['gn125', 'boxer125', 'click150i']; +const PAYMENT_TYPES = ['cash', 'lease']; +const LEASE_PROVIDERS = ['gci', 'thirdPartyFinance', 'both']; + +function ageInDays(dateReceived, now = Date.now()) { + const diffTime = Math.abs(now - new Date(dateReceived).getTime()); + return Math.floor(diffTime / (1000 * 60 * 60 * 24)); +} + +function ageBadge(days) { + if (days < 30) return 'green'; + if (days <= 45) return 'yellow'; + return 'red'; +} + +function nextStage(current) { + const index = STAGES.indexOf(current); + if (index < 0 || index >= STAGES.length - 1) return null; + return STAGES[index + 1]; +} + +function stageLogMap(logs) { + const map = {}; + for (const log of logs) { + map[log.stage] = log.loggedAt; + } + return map; +} + +function serializeStock(stock) { + const days = ageInDays(stock.dateReceived); + return { + id: stock.id, + chassisNumber: stock.chassisNumber, + engineNumber: stock.engineNumber, + model: stock.model, + color: stock.color, + currentDealerId: stock.currentDealerId, + dealerName: stock.currentDealer ? stock.currentDealer.name : null, + dateReceived: stock.dateReceived, + currentStage: stock.currentStage, + stageLogDates: stageLogMap(stock.stageLogs || []), + paymentType: stock.paymentType, + leaseProviderType: stock.leaseProviderType, + financeCompanyName: stock.financeCompanyName, + plateNumber: stock.plateNumber, + ageInDays: days, + badge: ageBadge(days), + }; +} + +module.exports = { + STAGES, + MODELS, + PAYMENT_TYPES, + LEASE_PROVIDERS, + ageInDays, + ageBadge, + nextStage, + serializeStock, +}; diff --git a/src/lib/users.js b/src/lib/users.js index d4ffa19..f8d04be 100644 --- a/src/lib/users.js +++ b/src/lib/users.js @@ -1,31 +1,31 @@ -function publicUser(user, dealers) { - const profile = { - id: user.id, - name: user.name, - phone: user.phone, - role: user.role, - dealerId: user.dealerId, - assignedDealerIds: (user.assignments || []).map((assignment) => assignment.dealerId), - }; - if (dealers) { - profile.dealers = dealers.map((dealer) => ({ - id: dealer.id, - name: dealer.name, - code: dealer.code, - district: dealer.district, - })); - } - return profile; -} - -const userPublicSelect = { - id: true, - name: true, - phone: true, - role: true, - dealerId: true, - createdAt: true, - assignments: { select: { dealerId: true } }, -}; - -module.exports = { publicUser, userPublicSelect }; +function publicUser(user, dealers) { + const profile = { + id: user.id, + name: user.name, + phone: user.phone, + role: user.role, + dealerId: user.dealerId, + assignedDealerIds: (user.assignments || []).map((assignment) => assignment.dealerId), + }; + if (dealers) { + profile.dealers = dealers.map((dealer) => ({ + id: dealer.id, + name: dealer.name, + code: dealer.code, + district: dealer.district, + })); + } + return profile; +} + +const userPublicSelect = { + id: true, + name: true, + phone: true, + role: true, + dealerId: true, + createdAt: true, + assignments: { select: { dealerId: true } }, +}; + +module.exports = { publicUser, userPublicSelect }; diff --git a/src/middleware/auth.js b/src/middleware/auth.js index cfa4f04..9eda740 100644 --- a/src/middleware/auth.js +++ b/src/middleware/auth.js @@ -1,37 +1,37 @@ -const jwt = require('jsonwebtoken'); -const prisma = require('../db'); -const { userPublicSelect } = require('../lib/users'); - -async function requireAuth(req, res, next) { - const header = req.headers.authorization || ''; - const token = header.startsWith('Bearer ') ? header.slice(7).trim() : ''; - if (!token) { - return res.status(401).json({ success: false, message: 'Missing token' }); - } - - try { - const payload = jwt.verify(token, process.env.JWT_SECRET); - const user = await prisma.user.findUnique({ - where: { id: payload.sub }, - select: userPublicSelect, - }); - if (!user) { - return res.status(401).json({ success: false, message: 'Invalid token' }); - } - req.user = user; - return next(); - } catch { - return res.status(401).json({ success: false, message: 'Invalid token' }); - } -} - -function requireRole(...roles) { - return (req, res, next) => { - if (!roles.includes(req.user.role)) { - return res.status(403).json({ success: false, message: 'Forbidden' }); - } - return next(); - }; -} - -module.exports = { requireAuth, requireRole }; +const jwt = require('jsonwebtoken'); +const prisma = require('../db'); +const { userPublicSelect } = require('../lib/users'); + +async function requireAuth(req, res, next) { + const header = req.headers.authorization || ''; + const token = header.startsWith('Bearer ') ? header.slice(7).trim() : ''; + if (!token) { + return res.status(401).json({ success: false, message: 'Missing token' }); + } + + try { + const payload = jwt.verify(token, process.env.JWT_SECRET); + const user = await prisma.user.findUnique({ + where: { id: payload.sub }, + select: userPublicSelect, + }); + if (!user) { + return res.status(401).json({ success: false, message: 'Invalid token' }); + } + req.user = user; + return next(); + } catch { + return res.status(401).json({ success: false, message: 'Invalid token' }); + } +} + +function requireRole(...roles) { + return (req, res, next) => { + if (!roles.includes(req.user.role)) { + return res.status(403).json({ success: false, message: 'Forbidden' }); + } + return next(); + }; +} + +module.exports = { requireAuth, requireRole }; diff --git a/src/routes/admin.js b/src/routes/admin.js index a335fdd..8a1abd2 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -1,198 +1,198 @@ -const express = require('express'); -const prisma = require('../db'); -const { asyncHandler, httpError } = require('../lib/errors'); -const { isValidPhone, normalizePhone } = require('../lib/phone'); -const { hashPassword } = require('../lib/passwords'); -const { userPublicSelect, publicUser } = require('../lib/users'); -const { requireAuth, requireRole } = require('../middleware/auth'); - -const router = express.Router(); - -router.use(requireAuth); - -router.get( - '/dealers', - requireRole('superAdmin'), - asyncHandler(async (req, res) => { - const dealers = await prisma.dealer.findMany({ orderBy: { name: 'asc' } }); - return res.json({ success: true, data: dealers }); - }) -); - -router.post( - '/dealers', - requireRole('superAdmin', 'salesRep'), - asyncHandler(async (req, res) => { - const name = String(req.body?.name || '').trim(); - const code = String(req.body?.code || '').trim(); - const district = String(req.body?.district || '').trim() || null; - const address = String(req.body?.address || '').trim() || null; - const phone = normalizePhone(req.body?.phone); - if (!name || !code || !isValidPhone(phone)) { - throw httpError(400, 'Name, code, and a Sri Lankan mobile number are required'); - } - - const dealer = await prisma.$transaction(async (tx) => { - const created = await tx.dealer.create({ - data: { name, code, district, address, phone }, - }); - await tx.user.create({ - data: { name, phone, role: 'dealer', dealerId: created.id }, - }); - if (req.user.role === 'salesRep') { - await tx.dealerAssignment.create({ - data: { salesRepId: req.user.id, dealerId: created.id }, - }); - } - return created; - }); - return res.status(201).json({ success: true, data: dealer }); - }) -); - -router.delete( - '/dealers/:id', - requireRole('superAdmin'), - asyncHandler(async (req, res) => { - const id = String(req.params.id || '').trim(); - const dealer = await prisma.dealer.findUnique({ where: { id } }); - if (!dealer) throw httpError(404, 'Dealer not found'); - - await prisma.$transaction(async (tx) => { - const staff = await tx.user.findMany({ - where: { dealerId: id }, - select: { id: true }, - }); - const staffIds = staff.map((user) => user.id); - const stocks = await tx.stock.findMany({ - where: { currentDealerId: id }, - select: { id: true }, - }); - const stockIds = stocks.map((stock) => stock.id); - - await tx.stockTransfer.deleteMany({ - where: { - OR: [ - { fromDealerId: id }, - { toDealerId: id }, - ...(stockIds.length ? [{ stockId: { in: stockIds } }] : []), - ], - }, - }); - - if (staffIds.length) { - await tx.stockTransfer.updateMany({ - where: { actorId: { in: staffIds } }, - data: { actorId: req.user.id }, - }); - await tx.event.updateMany({ - where: { createdById: { in: staffIds }, dealerId: { not: id } }, - data: { createdById: req.user.id }, - }); - await tx.servicePoint.updateMany({ - where: { createdById: { in: staffIds } }, - data: { createdById: req.user.id }, - }); - } - - await tx.event.deleteMany({ where: { dealerId: id } }); - await tx.stock.deleteMany({ where: { currentDealerId: id } }); - if (staffIds.length) { - await tx.user.deleteMany({ where: { id: { in: staffIds } } }); - } - await tx.dealer.delete({ where: { id } }); - }); - - return res.json({ success: true }); - }) -); - -router.get( - '/sales-reps', - requireRole('superAdmin'), - asyncHandler(async (req, res) => { - const reps = await prisma.user.findMany({ - where: { role: 'salesRep' }, - select: userPublicSelect, - orderBy: { name: 'asc' }, - }); - return res.json({ success: true, data: reps.map((rep) => publicUser(rep)) }); - }) -); - -router.post( - '/sales-reps', - requireRole('superAdmin'), - asyncHandler(async (req, res) => { - const name = String(req.body?.name || '').trim(); - const phone = normalizePhone(req.body?.phone); - const password = String(req.body?.password || ''); - const dealerIds = Array.isArray(req.body?.dealerIds) ? req.body.dealerIds : []; - if (!name || !isValidPhone(phone)) { - throw httpError(400, 'Name and a Sri Lankan mobile number are required'); - } - if (password.length < 8) { - throw httpError(400, 'Password must be at least 8 characters'); - } - if (!dealerIds.every((id) => typeof id === 'string' && id.trim())) { - throw httpError(400, 'dealerIds must be a list of ids'); - } - const uniqueIds = [...new Set(dealerIds.map((id) => id.trim()))]; - if (uniqueIds.length) { - const found = await prisma.dealer.findMany({ where: { id: { in: uniqueIds } } }); - if (found.length !== uniqueIds.length) throw httpError(404, 'Dealer not found'); - } - - const user = await prisma.user.create({ - data: { - name, - phone, - role: 'salesRep', - passwordHash: await hashPassword(password), - assignments: { - create: uniqueIds.map((dealerId) => ({ dealerId })), - }, - }, - select: userPublicSelect, - }); - return res.status(201).json({ success: true, data: publicUser(user) }); - }) -); - -router.patch( - '/assign-dealer', - requireRole('superAdmin'), - asyncHandler(async (req, res) => { - const salesRepId = String(req.body?.salesRepId || '').trim(); - const dealerId = String(req.body?.dealerId || '').trim(); - const assigned = req.body?.assigned !== false; - if (!salesRepId || !dealerId) { - throw httpError(400, 'salesRepId and dealerId are required'); - } - - const [rep, dealer] = await Promise.all([ - prisma.user.findUnique({ where: { id: salesRepId } }), - prisma.dealer.findUnique({ where: { id: dealerId } }), - ]); - if (!rep || rep.role !== 'salesRep') throw httpError(404, 'Sales rep not found'); - if (!dealer) throw httpError(404, 'Dealer not found'); - - if (assigned) { - await prisma.dealerAssignment.upsert({ - where: { salesRepId_dealerId: { salesRepId, dealerId } }, - update: {}, - create: { salesRepId, dealerId }, - }); - } else { - await prisma.dealerAssignment.deleteMany({ where: { salesRepId, dealerId } }); - } - - const updated = await prisma.user.findUnique({ - where: { id: salesRepId }, - select: userPublicSelect, - }); - return res.json({ success: true, data: publicUser(updated) }); - }) -); - -module.exports = router; +const express = require('express'); +const prisma = require('../db'); +const { asyncHandler, httpError } = require('../lib/errors'); +const { isValidPhone, normalizePhone } = require('../lib/phone'); +const { hashPassword } = require('../lib/passwords'); +const { userPublicSelect, publicUser } = require('../lib/users'); +const { requireAuth, requireRole } = require('../middleware/auth'); + +const router = express.Router(); + +router.use(requireAuth); + +router.get( + '/dealers', + requireRole('superAdmin'), + asyncHandler(async (req, res) => { + const dealers = await prisma.dealer.findMany({ orderBy: { name: 'asc' } }); + return res.json({ success: true, data: dealers }); + }) +); + +router.post( + '/dealers', + requireRole('superAdmin', 'salesRep'), + asyncHandler(async (req, res) => { + const name = String(req.body?.name || '').trim(); + const code = String(req.body?.code || '').trim(); + const district = String(req.body?.district || '').trim() || null; + const address = String(req.body?.address || '').trim() || null; + const phone = normalizePhone(req.body?.phone); + if (!name || !code || !isValidPhone(phone)) { + throw httpError(400, 'Name, code, and a Sri Lankan mobile number are required'); + } + + const dealer = await prisma.$transaction(async (tx) => { + const created = await tx.dealer.create({ + data: { name, code, district, address, phone }, + }); + await tx.user.create({ + data: { name, phone, role: 'dealer', dealerId: created.id }, + }); + if (req.user.role === 'salesRep') { + await tx.dealerAssignment.create({ + data: { salesRepId: req.user.id, dealerId: created.id }, + }); + } + return created; + }); + return res.status(201).json({ success: true, data: dealer }); + }) +); + +router.delete( + '/dealers/:id', + requireRole('superAdmin'), + asyncHandler(async (req, res) => { + const id = String(req.params.id || '').trim(); + const dealer = await prisma.dealer.findUnique({ where: { id } }); + if (!dealer) throw httpError(404, 'Dealer not found'); + + await prisma.$transaction(async (tx) => { + const staff = await tx.user.findMany({ + where: { dealerId: id }, + select: { id: true }, + }); + const staffIds = staff.map((user) => user.id); + const stocks = await tx.stock.findMany({ + where: { currentDealerId: id }, + select: { id: true }, + }); + const stockIds = stocks.map((stock) => stock.id); + + await tx.stockTransfer.deleteMany({ + where: { + OR: [ + { fromDealerId: id }, + { toDealerId: id }, + ...(stockIds.length ? [{ stockId: { in: stockIds } }] : []), + ], + }, + }); + + if (staffIds.length) { + await tx.stockTransfer.updateMany({ + where: { actorId: { in: staffIds } }, + data: { actorId: req.user.id }, + }); + await tx.event.updateMany({ + where: { createdById: { in: staffIds }, dealerId: { not: id } }, + data: { createdById: req.user.id }, + }); + await tx.servicePoint.updateMany({ + where: { createdById: { in: staffIds } }, + data: { createdById: req.user.id }, + }); + } + + await tx.event.deleteMany({ where: { dealerId: id } }); + await tx.stock.deleteMany({ where: { currentDealerId: id } }); + if (staffIds.length) { + await tx.user.deleteMany({ where: { id: { in: staffIds } } }); + } + await tx.dealer.delete({ where: { id } }); + }); + + return res.json({ success: true }); + }) +); + +router.get( + '/sales-reps', + requireRole('superAdmin'), + asyncHandler(async (req, res) => { + const reps = await prisma.user.findMany({ + where: { role: 'salesRep' }, + select: userPublicSelect, + orderBy: { name: 'asc' }, + }); + return res.json({ success: true, data: reps.map((rep) => publicUser(rep)) }); + }) +); + +router.post( + '/sales-reps', + requireRole('superAdmin'), + asyncHandler(async (req, res) => { + const name = String(req.body?.name || '').trim(); + const phone = normalizePhone(req.body?.phone); + const password = String(req.body?.password || ''); + const dealerIds = Array.isArray(req.body?.dealerIds) ? req.body.dealerIds : []; + if (!name || !isValidPhone(phone)) { + throw httpError(400, 'Name and a Sri Lankan mobile number are required'); + } + if (password.length < 8) { + throw httpError(400, 'Password must be at least 8 characters'); + } + if (!dealerIds.every((id) => typeof id === 'string' && id.trim())) { + throw httpError(400, 'dealerIds must be a list of ids'); + } + const uniqueIds = [...new Set(dealerIds.map((id) => id.trim()))]; + if (uniqueIds.length) { + const found = await prisma.dealer.findMany({ where: { id: { in: uniqueIds } } }); + if (found.length !== uniqueIds.length) throw httpError(404, 'Dealer not found'); + } + + const user = await prisma.user.create({ + data: { + name, + phone, + role: 'salesRep', + passwordHash: await hashPassword(password), + assignments: { + create: uniqueIds.map((dealerId) => ({ dealerId })), + }, + }, + select: userPublicSelect, + }); + return res.status(201).json({ success: true, data: publicUser(user) }); + }) +); + +router.patch( + '/assign-dealer', + requireRole('superAdmin'), + asyncHandler(async (req, res) => { + const salesRepId = String(req.body?.salesRepId || '').trim(); + const dealerId = String(req.body?.dealerId || '').trim(); + const assigned = req.body?.assigned !== false; + if (!salesRepId || !dealerId) { + throw httpError(400, 'salesRepId and dealerId are required'); + } + + const [rep, dealer] = await Promise.all([ + prisma.user.findUnique({ where: { id: salesRepId } }), + prisma.dealer.findUnique({ where: { id: dealerId } }), + ]); + if (!rep || rep.role !== 'salesRep') throw httpError(404, 'Sales rep not found'); + if (!dealer) throw httpError(404, 'Dealer not found'); + + if (assigned) { + await prisma.dealerAssignment.upsert({ + where: { salesRepId_dealerId: { salesRepId, dealerId } }, + update: {}, + create: { salesRepId, dealerId }, + }); + } else { + await prisma.dealerAssignment.deleteMany({ where: { salesRepId, dealerId } }); + } + + const updated = await prisma.user.findUnique({ + where: { id: salesRepId }, + select: userPublicSelect, + }); + return res.json({ success: true, data: publicUser(updated) }); + }) +); + +module.exports = router; diff --git a/src/routes/auth.js b/src/routes/auth.js index a44b906..f5746c5 100644 --- a/src/routes/auth.js +++ b/src/routes/auth.js @@ -1,238 +1,238 @@ -const crypto = require('crypto'); -const express = require('express'); -const jwt = require('jsonwebtoken'); -const prisma = require('../db'); -const { asyncHandler, httpError } = require('../lib/errors'); -const { isValidPhone, normalizePhone } = require('../lib/phone'); -const { checkPassword } = require('../lib/passwords'); -const { publicUser, userPublicSelect } = require('../lib/users'); -const { assignedDealerIds, canAccessDealer } = require('../lib/access'); -const { requireAuth, requireRole } = require('../middleware/auth'); - -const router = express.Router(); -const REQUEST_TTL_MS = 5 * 60 * 1000; - -function signToken(user) { - return jwt.sign({ sub: user.id, role: user.role }, process.env.JWT_SECRET, { - expiresIn: '10y', - }); -} - -async function accessibleDealers(user) { - if (user.role === 'superAdmin') { - return prisma.dealer.findMany({ orderBy: { name: 'asc' } }); - } - if (user.role === 'dealer') { - if (!user.dealerId) return []; - const dealer = await prisma.dealer.findUnique({ where: { id: user.dealerId } }); - return dealer ? [dealer] : []; - } - const ids = assignedDealerIds(user); - if (ids.length === 0) return []; - return prisma.dealer.findMany({ - where: { id: { in: ids } }, - orderBy: { name: 'asc' }, - }); -} - -function hashSecret(secret) { - return crypto.createHash('sha256').update(secret).digest('hex'); -} - -function secretsMatch(storedHash, secret) { - const given = Buffer.from(hashSecret(secret)); - const stored = Buffer.from(storedHash); - return stored.length === given.length && crypto.timingSafeEqual(stored, given); -} - -async function expireStaleRequests() { - await prisma.loginRequest.updateMany({ - where: { status: 'pending', expiresAt: { lt: new Date() } }, - data: { status: 'expired' }, - }); -} - -router.post( - '/staff-login', - asyncHandler(async (req, res) => { - const phone = normalizePhone(req.body?.phone); - const password = String(req.body?.password || ''); - if (!isValidPhone(phone) || !password) { - throw httpError(400, 'Phone and password are required'); - } - - const user = await prisma.user.findUnique({ - where: { phone }, - select: { ...userPublicSelect, passwordHash: true }, - }); - const allowed = user && (user.role === 'superAdmin' || user.role === 'salesRep'); - const matches = allowed && (await checkPassword(password, user.passwordHash)); - if (!matches) { - throw httpError(401, 'Invalid phone or password'); - } - - const dealers = await accessibleDealers(user); - return res.json({ token: signToken(user), user: publicUser(user, dealers) }); - }) -); - -router.post( - '/dealer-login', - asyncHandler(async (req, res) => { - const phone = normalizePhone(req.body?.phone); - if (!isValidPhone(phone)) { - throw httpError(400, 'Phone must be a Sri Lankan mobile number'); - } - - const user = await prisma.user.findUnique({ where: { phone } }); - if (!user || user.role !== 'dealer') { - return res.status(404).json({ success: false, message: 'Not Registered' }); - } - - await prisma.loginRequest.updateMany({ - where: { userId: user.id, status: 'pending' }, - data: { status: 'expired' }, - }); - - const secret = crypto.randomBytes(32).toString('hex'); - const request = await prisma.loginRequest.create({ - data: { - userId: user.id, - status: 'pending', - secretHash: hashSecret(secret), - expiresAt: new Date(Date.now() + REQUEST_TTL_MS), - }, - }); - - return res.status(201).json({ requestId: request.id, secret }); - }) -); - -router.get( - '/dealer-login/:id', - asyncHandler(async (req, res) => { - const secret = String(req.query.secret || ''); - const request = await prisma.loginRequest.findUnique({ - where: { id: req.params.id }, - include: { user: { select: userPublicSelect } }, - }); - if (!request || !secret || !secretsMatch(request.secretHash, secret)) { - throw httpError(404, 'Login request not found'); - } - - if (request.status === 'pending' && request.expiresAt.getTime() < Date.now()) { - await prisma.loginRequest.update({ - where: { id: request.id }, - data: { status: 'expired' }, - }); - return res.json({ status: 'expired' }); - } - - if (request.status !== 'approved') { - return res.json({ status: request.status }); - } - - const consumed = await prisma.loginRequest.updateMany({ - where: { id: request.id, status: 'approved' }, - data: { status: 'consumed' }, - }); - if (consumed.count !== 1) { - return res.json({ status: 'consumed' }); - } - - const dealers = await accessibleDealers(request.user); - return res.json({ - status: 'approved', - token: signToken(request.user), - user: publicUser(request.user, dealers), - }); - }) -); - -router.get( - '/login-requests', - requireAuth, - requireRole('superAdmin', 'salesRep'), - asyncHandler(async (req, res) => { - await expireStaleRequests(); - const where = { status: 'pending' }; - if (req.user.role === 'salesRep') { - const ids = assignedDealerIds(req.user); - where.user = { dealerId: { in: ids.length ? ids : ['__none__'] } }; - } - - const requests = await prisma.loginRequest.findMany({ - where, - include: { user: { include: { dealer: true } } }, - orderBy: { createdAt: 'asc' }, - }); - - return res.json({ - success: true, - data: requests.map((request) => ({ - id: request.id, - status: request.status, - createdAt: request.createdAt, - expiresAt: request.expiresAt, - user: { - id: request.user.id, - name: request.user.name, - phone: request.user.phone, - dealerId: request.user.dealerId, - }, - dealerName: request.user.dealer ? request.user.dealer.name : null, - })), - }); - }) -); - -async function decideRequest(req, status) { - await expireStaleRequests(); - const request = await prisma.loginRequest.findUnique({ - where: { id: req.params.id }, - include: { user: true }, - }); - if (!request || request.status !== 'pending') { - throw httpError(404, 'Login request not found'); - } - if (!canAccessDealer(req.user, request.user.dealerId)) { - throw httpError(403, 'Forbidden'); - } - - await prisma.loginRequest.update({ - where: { id: request.id }, - data: { status, decidedById: req.user.id, decidedAt: new Date() }, - }); - return { id: request.id, status }; -} - -router.post( - '/login-requests/:id/approve', - requireAuth, - requireRole('superAdmin', 'salesRep'), - asyncHandler(async (req, res) => { - const result = await decideRequest(req, 'approved'); - return res.json({ success: true, data: result }); - }) -); - -router.post( - '/login-requests/:id/reject', - requireAuth, - requireRole('superAdmin', 'salesRep'), - asyncHandler(async (req, res) => { - const result = await decideRequest(req, 'rejected'); - return res.json({ success: true, data: result }); - }) -); - -router.get( - '/me', - requireAuth, - asyncHandler(async (req, res) => { - const dealers = await accessibleDealers(req.user); - return res.json(publicUser(req.user, dealers)); - }) -); - -module.exports = router; +const crypto = require('crypto'); +const express = require('express'); +const jwt = require('jsonwebtoken'); +const prisma = require('../db'); +const { asyncHandler, httpError } = require('../lib/errors'); +const { isValidPhone, normalizePhone } = require('../lib/phone'); +const { checkPassword } = require('../lib/passwords'); +const { publicUser, userPublicSelect } = require('../lib/users'); +const { assignedDealerIds, canAccessDealer } = require('../lib/access'); +const { requireAuth, requireRole } = require('../middleware/auth'); + +const router = express.Router(); +const REQUEST_TTL_MS = 5 * 60 * 1000; + +function signToken(user) { + return jwt.sign({ sub: user.id, role: user.role }, process.env.JWT_SECRET, { + expiresIn: '10y', + }); +} + +async function accessibleDealers(user) { + if (user.role === 'superAdmin') { + return prisma.dealer.findMany({ orderBy: { name: 'asc' } }); + } + if (user.role === 'dealer') { + if (!user.dealerId) return []; + const dealer = await prisma.dealer.findUnique({ where: { id: user.dealerId } }); + return dealer ? [dealer] : []; + } + const ids = assignedDealerIds(user); + if (ids.length === 0) return []; + return prisma.dealer.findMany({ + where: { id: { in: ids } }, + orderBy: { name: 'asc' }, + }); +} + +function hashSecret(secret) { + return crypto.createHash('sha256').update(secret).digest('hex'); +} + +function secretsMatch(storedHash, secret) { + const given = Buffer.from(hashSecret(secret)); + const stored = Buffer.from(storedHash); + return stored.length === given.length && crypto.timingSafeEqual(stored, given); +} + +async function expireStaleRequests() { + await prisma.loginRequest.updateMany({ + where: { status: 'pending', expiresAt: { lt: new Date() } }, + data: { status: 'expired' }, + }); +} + +router.post( + '/staff-login', + asyncHandler(async (req, res) => { + const phone = normalizePhone(req.body?.phone); + const password = String(req.body?.password || ''); + if (!isValidPhone(phone) || !password) { + throw httpError(400, 'Phone and password are required'); + } + + const user = await prisma.user.findUnique({ + where: { phone }, + select: { ...userPublicSelect, passwordHash: true }, + }); + const allowed = user && (user.role === 'superAdmin' || user.role === 'salesRep'); + const matches = allowed && (await checkPassword(password, user.passwordHash)); + if (!matches) { + throw httpError(401, 'Invalid phone or password'); + } + + const dealers = await accessibleDealers(user); + return res.json({ token: signToken(user), user: publicUser(user, dealers) }); + }) +); + +router.post( + '/dealer-login', + asyncHandler(async (req, res) => { + const phone = normalizePhone(req.body?.phone); + if (!isValidPhone(phone)) { + throw httpError(400, 'Phone must be a Sri Lankan mobile number'); + } + + const user = await prisma.user.findUnique({ where: { phone } }); + if (!user || user.role !== 'dealer') { + return res.status(404).json({ success: false, message: 'Not Registered' }); + } + + await prisma.loginRequest.updateMany({ + where: { userId: user.id, status: 'pending' }, + data: { status: 'expired' }, + }); + + const secret = crypto.randomBytes(32).toString('hex'); + const request = await prisma.loginRequest.create({ + data: { + userId: user.id, + status: 'pending', + secretHash: hashSecret(secret), + expiresAt: new Date(Date.now() + REQUEST_TTL_MS), + }, + }); + + return res.status(201).json({ requestId: request.id, secret }); + }) +); + +router.get( + '/dealer-login/:id', + asyncHandler(async (req, res) => { + const secret = String(req.query.secret || ''); + const request = await prisma.loginRequest.findUnique({ + where: { id: req.params.id }, + include: { user: { select: userPublicSelect } }, + }); + if (!request || !secret || !secretsMatch(request.secretHash, secret)) { + throw httpError(404, 'Login request not found'); + } + + if (request.status === 'pending' && request.expiresAt.getTime() < Date.now()) { + await prisma.loginRequest.update({ + where: { id: request.id }, + data: { status: 'expired' }, + }); + return res.json({ status: 'expired' }); + } + + if (request.status !== 'approved') { + return res.json({ status: request.status }); + } + + const consumed = await prisma.loginRequest.updateMany({ + where: { id: request.id, status: 'approved' }, + data: { status: 'consumed' }, + }); + if (consumed.count !== 1) { + return res.json({ status: 'consumed' }); + } + + const dealers = await accessibleDealers(request.user); + return res.json({ + status: 'approved', + token: signToken(request.user), + user: publicUser(request.user, dealers), + }); + }) +); + +router.get( + '/login-requests', + requireAuth, + requireRole('superAdmin', 'salesRep'), + asyncHandler(async (req, res) => { + await expireStaleRequests(); + const where = { status: 'pending' }; + if (req.user.role === 'salesRep') { + const ids = assignedDealerIds(req.user); + where.user = { dealerId: { in: ids.length ? ids : ['__none__'] } }; + } + + const requests = await prisma.loginRequest.findMany({ + where, + include: { user: { include: { dealer: true } } }, + orderBy: { createdAt: 'asc' }, + }); + + return res.json({ + success: true, + data: requests.map((request) => ({ + id: request.id, + status: request.status, + createdAt: request.createdAt, + expiresAt: request.expiresAt, + user: { + id: request.user.id, + name: request.user.name, + phone: request.user.phone, + dealerId: request.user.dealerId, + }, + dealerName: request.user.dealer ? request.user.dealer.name : null, + })), + }); + }) +); + +async function decideRequest(req, status) { + await expireStaleRequests(); + const request = await prisma.loginRequest.findUnique({ + where: { id: req.params.id }, + include: { user: true }, + }); + if (!request || request.status !== 'pending') { + throw httpError(404, 'Login request not found'); + } + if (!canAccessDealer(req.user, request.user.dealerId)) { + throw httpError(403, 'Forbidden'); + } + + await prisma.loginRequest.update({ + where: { id: request.id }, + data: { status, decidedById: req.user.id, decidedAt: new Date() }, + }); + return { id: request.id, status }; +} + +router.post( + '/login-requests/:id/approve', + requireAuth, + requireRole('superAdmin', 'salesRep'), + asyncHandler(async (req, res) => { + const result = await decideRequest(req, 'approved'); + return res.json({ success: true, data: result }); + }) +); + +router.post( + '/login-requests/:id/reject', + requireAuth, + requireRole('superAdmin', 'salesRep'), + asyncHandler(async (req, res) => { + const result = await decideRequest(req, 'rejected'); + return res.json({ success: true, data: result }); + }) +); + +router.get( + '/me', + requireAuth, + asyncHandler(async (req, res) => { + const dealers = await accessibleDealers(req.user); + return res.json(publicUser(req.user, dealers)); + }) +); + +module.exports = router; diff --git a/src/routes/dealers.js b/src/routes/dealers.js index 0168172..63afadc 100644 --- a/src/routes/dealers.js +++ b/src/routes/dealers.js @@ -1,41 +1,41 @@ -const express = require('express'); -const prisma = require('../db'); -const { asyncHandler } = require('../lib/errors'); -const { assignedDealerIds } = require('../lib/access'); -const { requireAuth } = require('../middleware/auth'); - -const router = express.Router(); - -router.get( - '/', - requireAuth, - asyncHandler(async (req, res) => { - let dealers; - if (req.user.role === 'superAdmin') { - dealers = await prisma.dealer.findMany({ orderBy: { name: 'asc' } }); - } else if (req.user.role === 'dealer') { - dealers = req.user.dealerId - ? await prisma.dealer.findMany({ where: { id: req.user.dealerId } }) - : []; - } else { - const ids = assignedDealerIds(req.user); - dealers = ids.length - ? await prisma.dealer.findMany({ where: { id: { in: ids } }, orderBy: { name: 'asc' } }) - : []; - } - - return res.json({ - success: true, - data: dealers.map((dealer) => ({ - id: dealer.id, - name: dealer.name, - code: dealer.code, - district: dealer.district, - address: dealer.address, - phone: dealer.phone, - })), - }); - }) -); - -module.exports = router; +const express = require('express'); +const prisma = require('../db'); +const { asyncHandler } = require('../lib/errors'); +const { assignedDealerIds } = require('../lib/access'); +const { requireAuth } = require('../middleware/auth'); + +const router = express.Router(); + +router.get( + '/', + requireAuth, + asyncHandler(async (req, res) => { + let dealers; + if (req.user.role === 'superAdmin') { + dealers = await prisma.dealer.findMany({ orderBy: { name: 'asc' } }); + } else if (req.user.role === 'dealer') { + dealers = req.user.dealerId + ? await prisma.dealer.findMany({ where: { id: req.user.dealerId } }) + : []; + } else { + const ids = assignedDealerIds(req.user); + dealers = ids.length + ? await prisma.dealer.findMany({ where: { id: { in: ids } }, orderBy: { name: 'asc' } }) + : []; + } + + return res.json({ + success: true, + data: dealers.map((dealer) => ({ + id: dealer.id, + name: dealer.name, + code: dealer.code, + district: dealer.district, + address: dealer.address, + phone: dealer.phone, + })), + }); + }) +); + +module.exports = router; diff --git a/src/routes/events.js b/src/routes/events.js index d03cae7..180e1c0 100644 --- a/src/routes/events.js +++ b/src/routes/events.js @@ -1,116 +1,116 @@ -const express = require('express'); -const prisma = require('../db'); -const { asyncHandler, httpError } = require('../lib/errors'); -const { canAccessDealer, eventScopeWhere } = require('../lib/access'); -const { requireAuth } = require('../middleware/auth'); - -const router = express.Router(); -const PLAN_TYPES = ['general', 'monthlySpecial']; - -function serializeEvent(event) { - let imageUrls = []; - try { - const parsed = JSON.parse(event.imageUrls || '[]'); - imageUrls = Array.isArray(parsed) ? parsed : []; - } catch { - imageUrls = []; - } - return { - id: event.id, - dealerId: event.dealerId, - dealerName: event.dealer ? event.dealer.name : null, - planType: event.planType, - month: event.month, - year: event.year, - title: event.title, - description: event.description, - expense: event.expense, - imageUrls, - createdById: event.createdById, - createdAt: event.createdAt, - }; -} - -router.use(requireAuth); - -router.get( - '/', - asyncHandler(async (req, res) => { - const where = eventScopeWhere(req.user); - const dealerId = typeof req.query.dealerId === 'string' ? req.query.dealerId.trim() : ''; - const planType = typeof req.query.planType === 'string' ? req.query.planType.trim() : ''; - - if (dealerId) { - if (!canAccessDealer(req.user, dealerId)) throw httpError(403, 'Forbidden'); - where.dealerId = dealerId; - } - if (planType) { - if (!PLAN_TYPES.includes(planType)) throw httpError(400, 'Invalid planType'); - where.planType = planType; - } - - const events = await prisma.event.findMany({ - where, - include: { dealer: true }, - orderBy: { createdAt: 'desc' }, - }); - return res.json({ success: true, data: events.map(serializeEvent) }); - }) -); - -router.post( - '/', - asyncHandler(async (req, res) => { - const title = String(req.body?.title || '').trim(); - const description = String(req.body?.description || '').trim(); - const planType = String(req.body?.planType || '').trim(); - const dealerId = String(req.body?.dealerId || req.user.dealerId || '').trim(); - const expense = Number(req.body?.expense); - const imageUrls = Array.isArray(req.body?.imageUrls) ? req.body.imageUrls : []; - - if (!title || !description || !dealerId) { - throw httpError(400, 'Title, description, and dealer are required'); - } - if (!PLAN_TYPES.includes(planType)) throw httpError(400, 'Invalid planType'); - if (!Number.isFinite(expense) || expense < 0) throw httpError(400, 'Expense must be a number'); - if (!imageUrls.every((url) => typeof url === 'string' && url.trim())) { - throw httpError(400, 'imageUrls must be a list of URL strings'); - } - if (!canAccessDealer(req.user, dealerId)) throw httpError(403, 'Forbidden'); - - let month = null; - let year = null; - if (planType === 'monthlySpecial') { - month = Number(req.body?.month); - year = Number(req.body?.year); - if (!Number.isInteger(month) || month < 1 || month > 12) { - throw httpError(400, 'month is required for a monthly plan'); - } - if (!Number.isInteger(year) || year < 2000 || year > 2100) { - throw httpError(400, 'year is required for a monthly plan'); - } - } - - const dealer = await prisma.dealer.findUnique({ where: { id: dealerId } }); - if (!dealer) throw httpError(404, 'Dealer not found'); - - const event = await prisma.event.create({ - data: { - dealerId, - planType, - month, - year, - title, - description, - expense, - imageUrls: JSON.stringify(imageUrls.map((url) => url.trim())), - createdById: req.user.id, - }, - include: { dealer: true }, - }); - - return res.status(201).json({ success: true, data: serializeEvent(event) }); - }) -); - -module.exports = router; +const express = require('express'); +const prisma = require('../db'); +const { asyncHandler, httpError } = require('../lib/errors'); +const { canAccessDealer, eventScopeWhere } = require('../lib/access'); +const { requireAuth } = require('../middleware/auth'); + +const router = express.Router(); +const PLAN_TYPES = ['general', 'monthlySpecial']; + +function serializeEvent(event) { + let imageUrls = []; + try { + const parsed = JSON.parse(event.imageUrls || '[]'); + imageUrls = Array.isArray(parsed) ? parsed : []; + } catch { + imageUrls = []; + } + return { + id: event.id, + dealerId: event.dealerId, + dealerName: event.dealer ? event.dealer.name : null, + planType: event.planType, + month: event.month, + year: event.year, + title: event.title, + description: event.description, + expense: event.expense, + imageUrls, + createdById: event.createdById, + createdAt: event.createdAt, + }; +} + +router.use(requireAuth); + +router.get( + '/', + asyncHandler(async (req, res) => { + const where = eventScopeWhere(req.user); + const dealerId = typeof req.query.dealerId === 'string' ? req.query.dealerId.trim() : ''; + const planType = typeof req.query.planType === 'string' ? req.query.planType.trim() : ''; + + if (dealerId) { + if (!canAccessDealer(req.user, dealerId)) throw httpError(403, 'Forbidden'); + where.dealerId = dealerId; + } + if (planType) { + if (!PLAN_TYPES.includes(planType)) throw httpError(400, 'Invalid planType'); + where.planType = planType; + } + + const events = await prisma.event.findMany({ + where, + include: { dealer: true }, + orderBy: { createdAt: 'desc' }, + }); + return res.json({ success: true, data: events.map(serializeEvent) }); + }) +); + +router.post( + '/', + asyncHandler(async (req, res) => { + const title = String(req.body?.title || '').trim(); + const description = String(req.body?.description || '').trim(); + const planType = String(req.body?.planType || '').trim(); + const dealerId = String(req.body?.dealerId || req.user.dealerId || '').trim(); + const expense = Number(req.body?.expense); + const imageUrls = Array.isArray(req.body?.imageUrls) ? req.body.imageUrls : []; + + if (!title || !description || !dealerId) { + throw httpError(400, 'Title, description, and dealer are required'); + } + if (!PLAN_TYPES.includes(planType)) throw httpError(400, 'Invalid planType'); + if (!Number.isFinite(expense) || expense < 0) throw httpError(400, 'Expense must be a number'); + if (!imageUrls.every((url) => typeof url === 'string' && url.trim())) { + throw httpError(400, 'imageUrls must be a list of URL strings'); + } + if (!canAccessDealer(req.user, dealerId)) throw httpError(403, 'Forbidden'); + + let month = null; + let year = null; + if (planType === 'monthlySpecial') { + month = Number(req.body?.month); + year = Number(req.body?.year); + if (!Number.isInteger(month) || month < 1 || month > 12) { + throw httpError(400, 'month is required for a monthly plan'); + } + if (!Number.isInteger(year) || year < 2000 || year > 2100) { + throw httpError(400, 'year is required for a monthly plan'); + } + } + + const dealer = await prisma.dealer.findUnique({ where: { id: dealerId } }); + if (!dealer) throw httpError(404, 'Dealer not found'); + + const event = await prisma.event.create({ + data: { + dealerId, + planType, + month, + year, + title, + description, + expense, + imageUrls: JSON.stringify(imageUrls.map((url) => url.trim())), + createdById: req.user.id, + }, + include: { dealer: true }, + }); + + return res.status(201).json({ success: true, data: serializeEvent(event) }); + }) +); + +module.exports = router; diff --git a/src/routes/servicePoints.js b/src/routes/servicePoints.js index facdaa3..b27c87c 100644 --- a/src/routes/servicePoints.js +++ b/src/routes/servicePoints.js @@ -1,72 +1,72 @@ -const express = require('express'); -const prisma = require('../db'); -const { asyncHandler, httpError } = require('../lib/errors'); -const { requireAuth, requireRole } = require('../middleware/auth'); - -const router = express.Router(); - -function serializePoint(point) { - return { - id: point.id, - name: point.name, - district: point.district, - address: point.address, - phone: point.phone, - notes: point.notes, - createdAt: point.createdAt, - }; -} - -router.use(requireAuth); - -router.get( - '/', - asyncHandler(async (req, res) => { - const district = typeof req.query.district === 'string' ? req.query.district.trim() : ''; - const search = typeof req.query.search === 'string' ? req.query.search.trim() : ''; - const where = {}; - if (district) where.district = district; - if (search) { - where.OR = [ - { name: { contains: search } }, - { district: { contains: search } }, - { address: { contains: search } }, - { phone: { contains: search } }, - { notes: { contains: search } }, - ]; - } - - const points = await prisma.servicePoint.findMany({ - where, - orderBy: { name: 'asc' }, - }); - return res.json({ success: true, data: points.map(serializePoint) }); - }) -); - -router.post( - '/', - requireRole('salesRep', 'superAdmin'), - asyncHandler(async (req, res) => { - const name = String(req.body?.name || '').trim(); - const district = String(req.body?.district || '').trim(); - const address = String(req.body?.address || '').trim() || null; - const phone = String(req.body?.phone || '').trim() || null; - const notes = String(req.body?.notes || '').trim() || null; - if (!name || !district) throw httpError(400, 'Name and district are required'); - - const point = await prisma.servicePoint.create({ - data: { - name, - district, - address, - phone, - notes, - createdById: req.user.id, - }, - }); - return res.status(201).json({ success: true, data: serializePoint(point) }); - }) -); - -module.exports = router; +const express = require('express'); +const prisma = require('../db'); +const { asyncHandler, httpError } = require('../lib/errors'); +const { requireAuth, requireRole } = require('../middleware/auth'); + +const router = express.Router(); + +function serializePoint(point) { + return { + id: point.id, + name: point.name, + district: point.district, + address: point.address, + phone: point.phone, + notes: point.notes, + createdAt: point.createdAt, + }; +} + +router.use(requireAuth); + +router.get( + '/', + asyncHandler(async (req, res) => { + const district = typeof req.query.district === 'string' ? req.query.district.trim() : ''; + const search = typeof req.query.search === 'string' ? req.query.search.trim() : ''; + const where = {}; + if (district) where.district = district; + if (search) { + where.OR = [ + { name: { contains: search } }, + { district: { contains: search } }, + { address: { contains: search } }, + { phone: { contains: search } }, + { notes: { contains: search } }, + ]; + } + + const points = await prisma.servicePoint.findMany({ + where, + orderBy: { name: 'asc' }, + }); + return res.json({ success: true, data: points.map(serializePoint) }); + }) +); + +router.post( + '/', + requireRole('salesRep', 'superAdmin'), + asyncHandler(async (req, res) => { + const name = String(req.body?.name || '').trim(); + const district = String(req.body?.district || '').trim(); + const address = String(req.body?.address || '').trim() || null; + const phone = String(req.body?.phone || '').trim() || null; + const notes = String(req.body?.notes || '').trim() || null; + if (!name || !district) throw httpError(400, 'Name and district are required'); + + const point = await prisma.servicePoint.create({ + data: { + name, + district, + address, + phone, + notes, + createdById: req.user.id, + }, + }); + return res.status(201).json({ success: true, data: serializePoint(point) }); + }) +); + +module.exports = router; diff --git a/src/routes/stocks.js b/src/routes/stocks.js index a293cec..bbb7ff2 100644 --- a/src/routes/stocks.js +++ b/src/routes/stocks.js @@ -1,209 +1,276 @@ -const express = require('express'); -const prisma = require('../db'); -const { asyncHandler, httpError } = require('../lib/errors'); -const { canAccessDealer, dealerScopeWhere } = require('../lib/access'); -const { - MODELS, - PAYMENT_TYPES, - LEASE_PROVIDERS, - nextStage, - serializeStock, -} = require('../lib/stockRules'); -const { requireAuth, requireRole } = require('../middleware/auth'); - -const router = express.Router(); -const stockInclude = { - currentDealer: true, - stageLogs: { orderBy: { loggedAt: 'asc' } }, -}; - -router.use(requireAuth); - -router.get( - '/', - asyncHandler(async (req, res) => { - const where = dealerScopeWhere(req.user); - const dealerId = typeof req.query.dealerId === 'string' ? req.query.dealerId.trim() : ''; - if (dealerId) { - if (!canAccessDealer(req.user, dealerId)) { - throw httpError(403, 'Forbidden'); - } - where.currentDealerId = dealerId; - } - - const stocks = await prisma.stock.findMany({ - where, - include: stockInclude, - orderBy: { dateReceived: 'asc' }, - }); - return res.json({ success: true, data: stocks.map(serializeStock) }); - }) -); - -router.post( - '/', - requireRole('dealer', 'salesRep', 'superAdmin'), - asyncHandler(async (req, res) => { - const chassisNumber = String(req.body?.chassisNumber || '').trim(); - const engineNumber = String(req.body?.engineNumber || '').trim(); - const model = String(req.body?.model || '').trim(); - const color = String(req.body?.color || '').trim(); - let currentDealerId = String(req.body?.currentDealerId || '').trim(); - const dateReceived = req.body?.dateReceived ? new Date(req.body.dateReceived) : new Date(); - - if (req.user.role === 'dealer') { - if (!req.user.dealerId) throw httpError(403, 'Forbidden'); - if (currentDealerId && currentDealerId !== req.user.dealerId) { - throw httpError(403, 'Forbidden'); - } - currentDealerId = req.user.dealerId; - } - - if (!chassisNumber || !engineNumber || !color || !currentDealerId) { - throw httpError(400, 'Chassis, engine, color, and dealer are required'); - } - if (!MODELS.includes(model)) { - throw httpError(400, 'Invalid model'); - } - if (Number.isNaN(dateReceived.getTime())) { - throw httpError(400, 'Invalid received date'); - } - if (!canAccessDealer(req.user, currentDealerId)) { - throw httpError(403, 'Forbidden'); - } - - const dealer = await prisma.dealer.findUnique({ where: { id: currentDealerId } }); - if (!dealer) throw httpError(404, 'Dealer not found'); - - const stock = await prisma.stock.create({ - data: { - chassisNumber, - engineNumber, - model, - color, - currentDealerId, - dateReceived, - currentStage: 'received', - stageLogs: { - create: { - stage: 'received', - loggedAt: dateReceived, - actorId: req.user.id, - }, - }, - }, - include: stockInclude, - }); - - return res.status(201).json({ success: true, data: serializeStock(stock) }); - }) -); - -router.patch( - '/:chassisNumber/stage', - asyncHandler(async (req, res) => { - const chassisNumber = req.params.chassisNumber; - const stock = await prisma.stock.findUnique({ - where: { chassisNumber }, - include: stockInclude, - }); - if (!stock) throw httpError(404, 'Stock not found'); - if (!canAccessDealer(req.user, stock.currentDealerId)) { - throw httpError(403, 'Forbidden'); - } - - const expected = nextStage(stock.currentStage); - const stage = String(req.body?.stage || '').trim(); - if (!expected) throw httpError(400, 'Stock is already at the final stage'); - if (stage !== expected) { - throw httpError(400, `Next stage must be ${expected}`); - } - - const data = { currentStage: stage }; - if (stage === 'paymentApproved') { - const paymentType = String(req.body?.paymentType || '').trim(); - if (!PAYMENT_TYPES.includes(paymentType)) { - throw httpError(400, 'paymentType must be cash or lease'); - } - data.paymentType = paymentType; - if (paymentType === 'lease') { - const leaseProviderType = String(req.body?.leaseProviderType || '').trim(); - if (!LEASE_PROVIDERS.includes(leaseProviderType)) { - throw httpError(400, 'Choose GCI, finance, or both'); - } - data.leaseProviderType = leaseProviderType; - const usesFinance = leaseProviderType === 'thirdPartyFinance' || leaseProviderType === 'both'; - if (usesFinance) { - const financeCompanyName = String(req.body?.financeCompanyName || '').trim(); - if (!financeCompanyName) throw httpError(400, 'financeCompanyName is required'); - data.financeCompanyName = financeCompanyName; - } else { - data.financeCompanyName = null; - } - } else { - data.leaseProviderType = null; - data.financeCompanyName = null; - } - } - if (stage === 'plateReceived') { - const plateNumber = String(req.body?.plateNumber || '').trim(); - if (!plateNumber) throw httpError(400, 'Plate number is required'); - data.plateNumber = plateNumber; - } - - const updated = await prisma.stock.update({ - where: { id: stock.id }, - data: { - ...data, - stageLogs: { - create: { stage, actorId: req.user.id }, - }, - }, - include: stockInclude, - }); - - return res.json({ success: true, data: serializeStock(updated) }); - }) -); - -router.post( - '/:chassisNumber/transfer', - requireRole('salesRep', 'superAdmin'), - asyncHandler(async (req, res) => { - const chassisNumber = req.params.chassisNumber; - const toDealerId = String(req.body?.dealerId || '').trim(); - if (!toDealerId) throw httpError(400, 'dealerId is required'); - - const stock = await prisma.stock.findUnique({ where: { chassisNumber } }); - if (!stock) throw httpError(404, 'Stock not found'); - if (stock.currentDealerId === toDealerId) { - throw httpError(400, 'Stock is already at that dealer'); - } - if (!canAccessDealer(req.user, stock.currentDealerId) || !canAccessDealer(req.user, toDealerId)) { - throw httpError(403, 'Forbidden'); - } - - const target = await prisma.dealer.findUnique({ where: { id: toDealerId } }); - if (!target) throw httpError(404, 'Dealer not found'); - - const updated = await prisma.$transaction(async (tx) => { - await tx.stockTransfer.create({ - data: { - stockId: stock.id, - fromDealerId: stock.currentDealerId, - toDealerId, - actorId: req.user.id, - }, - }); - return tx.stock.update({ - where: { id: stock.id }, - data: { currentDealerId: toDealerId }, - include: stockInclude, - }); - }); - - return res.json({ success: true, data: serializeStock(updated) }); - }) -); - -module.exports = router; +const express = require('express'); +const prisma = require('../db'); +const { asyncHandler, httpError } = require('../lib/errors'); +const { canAccessDealer, dealerScopeWhere } = require('../lib/access'); +const { + MODELS, + PAYMENT_TYPES, + LEASE_PROVIDERS, + nextStage, + serializeStock, +} = require('../lib/stockRules'); +const { requireAuth, requireRole } = require('../middleware/auth'); + +const router = express.Router(); +const stockInclude = { + currentDealer: true, + stageLogs: { orderBy: { loggedAt: 'asc' } }, +}; + +router.use(requireAuth); + +router.get( + '/', + asyncHandler(async (req, res) => { + const where = dealerScopeWhere(req.user); + const dealerId = typeof req.query.dealerId === 'string' ? req.query.dealerId.trim() : ''; + if (dealerId) { + if (!canAccessDealer(req.user, dealerId)) { + throw httpError(403, 'Forbidden'); + } + where.currentDealerId = dealerId; + } + + const stocks = await prisma.stock.findMany({ + where, + include: stockInclude, + orderBy: { dateReceived: 'asc' }, + }); + return res.json({ success: true, data: stocks.map(serializeStock) }); + }) +); + +router.post( + '/', + requireRole('dealer', 'salesRep', 'superAdmin'), + asyncHandler(async (req, res) => { + const chassisNumber = String(req.body?.chassisNumber || '').trim(); + const engineNumber = String(req.body?.engineNumber || '').trim(); + const model = String(req.body?.model || '').trim(); + const color = String(req.body?.color || '').trim(); + let currentDealerId = String(req.body?.currentDealerId || '').trim(); + const dateReceived = req.body?.dateReceived ? new Date(req.body.dateReceived) : new Date(); + + if (req.user.role === 'dealer') { + if (!req.user.dealerId) throw httpError(403, 'Forbidden'); + if (currentDealerId && currentDealerId !== req.user.dealerId) { + throw httpError(403, 'Forbidden'); + } + currentDealerId = req.user.dealerId; + } + + if (!chassisNumber || !engineNumber || !color || !currentDealerId) { + throw httpError(400, 'Chassis, engine, color, and dealer are required'); + } + if (!MODELS.includes(model)) { + throw httpError(400, 'Invalid model'); + } + if (Number.isNaN(dateReceived.getTime())) { + throw httpError(400, 'Invalid received date'); + } + if (!canAccessDealer(req.user, currentDealerId)) { + throw httpError(403, 'Forbidden'); + } + + const dealer = await prisma.dealer.findUnique({ where: { id: currentDealerId } }); + if (!dealer) throw httpError(404, 'Dealer not found'); + + const stock = await prisma.stock.create({ + data: { + chassisNumber, + engineNumber, + model, + color, + currentDealerId, + dateReceived, + currentStage: 'received', + stageLogs: { + create: { + stage: 'received', + loggedAt: dateReceived, + actorId: req.user.id, + }, + }, + }, + include: stockInclude, + }); + + return res.status(201).json({ success: true, data: serializeStock(stock) }); + }) +); + +router.patch( + '/:chassisNumber/stage', + asyncHandler(async (req, res) => { + const chassisNumber = req.params.chassisNumber; + const stock = await prisma.stock.findUnique({ + where: { chassisNumber }, + include: stockInclude, + }); + if (!stock) throw httpError(404, 'Stock not found'); + if (!canAccessDealer(req.user, stock.currentDealerId)) { + throw httpError(403, 'Forbidden'); + } + + const expected = nextStage(stock.currentStage); + const stage = String(req.body?.stage || '').trim(); + if (!expected) throw httpError(400, 'Stock is already at the final stage'); + if (stage !== expected) { + throw httpError(400, `Next stage must be ${expected}`); + } + + const data = { currentStage: stage }; + if (stage === 'paymentApproved') { + const paymentType = String(req.body?.paymentType || '').trim(); + if (!PAYMENT_TYPES.includes(paymentType)) { + throw httpError(400, 'paymentType must be cash or lease'); + } + data.paymentType = paymentType; + if (paymentType === 'lease') { + const leaseProviderType = String(req.body?.leaseProviderType || '').trim(); + if (!LEASE_PROVIDERS.includes(leaseProviderType)) { + throw httpError(400, 'Choose GCI, finance, or both'); + } + data.leaseProviderType = leaseProviderType; + const usesFinance = leaseProviderType === 'thirdPartyFinance' || leaseProviderType === 'both'; + if (usesFinance) { + const financeCompanyName = String(req.body?.financeCompanyName || '').trim(); + if (!financeCompanyName) throw httpError(400, 'financeCompanyName is required'); + data.financeCompanyName = financeCompanyName; + } else { + data.financeCompanyName = null; + } + } else { + data.leaseProviderType = null; + data.financeCompanyName = null; + } + } + if (stage === 'plateReceived') { + const plateNumber = String(req.body?.plateNumber || '').trim(); + if (!plateNumber) throw httpError(400, 'Plate number is required'); + data.plateNumber = plateNumber; + } + + const updated = await prisma.stock.update({ + where: { id: stock.id }, + data: { + ...data, + stageLogs: { + create: { stage, actorId: req.user.id }, + }, + }, + include: stockInclude, + }); + + return res.json({ success: true, data: serializeStock(updated) }); + }) +); + +router.post( + '/:chassisNumber/stage/undo', + requireRole('salesRep', 'superAdmin'), + asyncHandler(async (req, res) => { + const chassisNumber = req.params.chassisNumber; + const stock = await prisma.stock.findUnique({ + where: { chassisNumber }, + include: stockInclude, + }); + if (!stock) throw httpError(404, 'Stock not found'); + if (!canAccessDealer(req.user, stock.currentDealerId)) { + throw httpError(403, 'Forbidden'); + } + + const logs = [...stock.stageLogs].sort((a, b) => { + const diff = new Date(a.loggedAt).getTime() - new Date(b.loggedAt).getTime(); + if (diff !== 0) return diff; + return a.id < b.id ? -1 : a.id > b.id ? 1 : 0; + }); + const latest = logs[logs.length - 1]; + if (!latest || logs.length < 2 || stock.currentStage === 'received' || latest.stage === 'received') { + throw httpError(400, 'Nothing to undo'); + } + if (latest.stage !== stock.currentStage) { + throw httpError(400, 'Stage log does not match the current stage'); + } + + const previous = logs[logs.length - 2]; + const data = { currentStage: previous.stage }; + if (latest.stage === 'paymentApproved') { + data.paymentType = null; + data.leaseProviderType = null; + data.financeCompanyName = null; + } + if (latest.stage === 'plateReceived') { + data.plateNumber = null; + } + + const updated = await prisma.$transaction(async (tx) => { + await tx.stageLog.delete({ where: { id: latest.id } }); + return tx.stock.update({ + where: { id: stock.id }, + data, + include: stockInclude, + }); + }); + + return res.json({ success: true, data: serializeStock(updated) }); + }) +); + +router.delete( + '/:chassisNumber', + requireRole('salesRep', 'superAdmin'), + asyncHandler(async (req, res) => { + const chassisNumber = req.params.chassisNumber; + const stock = await prisma.stock.findUnique({ where: { chassisNumber } }); + if (!stock) throw httpError(404, 'Stock not found'); + if (!canAccessDealer(req.user, stock.currentDealerId)) { + throw httpError(403, 'Forbidden'); + } + + await prisma.stock.delete({ where: { id: stock.id } }); + return res.json({ success: true }); + }) +); + +router.post( + '/:chassisNumber/transfer', + requireRole('salesRep', 'superAdmin'), + asyncHandler(async (req, res) => { + const chassisNumber = req.params.chassisNumber; + const toDealerId = String(req.body?.dealerId || '').trim(); + if (!toDealerId) throw httpError(400, 'dealerId is required'); + + const stock = await prisma.stock.findUnique({ where: { chassisNumber } }); + if (!stock) throw httpError(404, 'Stock not found'); + if (stock.currentDealerId === toDealerId) { + throw httpError(400, 'Stock is already at that dealer'); + } + if (!canAccessDealer(req.user, stock.currentDealerId) || !canAccessDealer(req.user, toDealerId)) { + throw httpError(403, 'Forbidden'); + } + + const target = await prisma.dealer.findUnique({ where: { id: toDealerId } }); + if (!target) throw httpError(404, 'Dealer not found'); + + const updated = await prisma.$transaction(async (tx) => { + await tx.stockTransfer.create({ + data: { + stockId: stock.id, + fromDealerId: stock.currentDealerId, + toDealerId, + actorId: req.user.id, + }, + }); + return tx.stock.update({ + where: { id: stock.id }, + data: { currentDealerId: toDealerId }, + include: stockInclude, + }); + }); + + return res.json({ success: true, data: serializeStock(updated) }); + }) +); + +module.exports = router;