plutin 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base-controller-cec5714c.d.ts +46 -0
- package/dist/core/decorators/controller-http-decorator.cjs +752 -0
- package/dist/core/decorators/controller-http-decorator.cjs.map +1 -0
- package/dist/core/decorators/controller-http-decorator.d.cts +13 -0
- package/dist/core/decorators/controller-http-decorator.d.ts +13 -0
- package/dist/core/decorators/controller-http-decorator.js +735 -0
- package/dist/core/decorators/controller-http-decorator.js.map +1 -0
- package/dist/core/decorators/dependency-container.cjs +92 -0
- package/dist/core/decorators/dependency-container.cjs.map +1 -0
- package/dist/core/decorators/dependency-container.d.cts +22 -0
- package/dist/core/decorators/dependency-container.d.ts +22 -0
- package/dist/core/decorators/dependency-container.js +69 -0
- package/dist/core/decorators/dependency-container.js.map +1 -0
- package/dist/core/entities/aggregate-root.cjs +99 -0
- package/dist/core/entities/aggregate-root.cjs.map +1 -0
- package/dist/core/entities/aggregate-root.d.cts +8 -0
- package/dist/core/entities/aggregate-root.d.ts +8 -0
- package/dist/core/entities/aggregate-root.js +74 -0
- package/dist/core/entities/aggregate-root.js.map +1 -0
- package/dist/core/entities/common-dto.cjs +19 -0
- package/dist/core/entities/common-dto.cjs.map +1 -0
- package/dist/core/entities/common-dto.d.cts +10 -0
- package/dist/core/entities/common-dto.d.ts +10 -0
- package/dist/core/entities/common-dto.js +1 -0
- package/dist/core/entities/common-dto.js.map +1 -0
- package/dist/core/entities/domain-event.cjs +19 -0
- package/dist/core/entities/domain-event.cjs.map +1 -0
- package/dist/core/entities/domain-event.d.cts +6 -0
- package/dist/core/entities/domain-event.d.ts +6 -0
- package/dist/core/entities/domain-event.js +1 -0
- package/dist/core/entities/domain-event.js.map +1 -0
- package/dist/core/entities/entity.cjs +92 -0
- package/dist/core/entities/entity.cjs.map +1 -0
- package/dist/core/entities/entity.d.cts +17 -0
- package/dist/core/entities/entity.d.ts +17 -0
- package/dist/core/entities/entity.js +67 -0
- package/dist/core/entities/entity.js.map +1 -0
- package/dist/core/entities/optional.cjs +19 -0
- package/dist/core/entities/optional.cjs.map +1 -0
- package/dist/core/entities/optional.d.cts +3 -0
- package/dist/core/entities/optional.d.ts +3 -0
- package/dist/core/entities/optional.js +1 -0
- package/dist/core/entities/optional.js.map +1 -0
- package/dist/core/entities/unique-entity-id.cjs +50 -0
- package/dist/core/entities/unique-entity-id.cjs.map +1 -0
- package/dist/core/entities/unique-entity-id.d.cts +9 -0
- package/dist/core/entities/unique-entity-id.d.ts +9 -0
- package/dist/core/entities/unique-entity-id.js +27 -0
- package/dist/core/entities/unique-entity-id.js.map +1 -0
- package/dist/core/entities/value-object.cjs +40 -0
- package/dist/core/entities/value-object.cjs.map +1 -0
- package/dist/core/entities/value-object.d.cts +6 -0
- package/dist/core/entities/value-object.d.ts +6 -0
- package/dist/core/entities/value-object.js +17 -0
- package/dist/core/entities/value-object.js.map +1 -0
- package/dist/core/entities/watched-list.cjs +121 -0
- package/dist/core/entities/watched-list.cjs.map +1 -0
- package/dist/core/entities/watched-list.d.cts +27 -0
- package/dist/core/entities/watched-list.d.ts +27 -0
- package/dist/core/entities/watched-list.js +98 -0
- package/dist/core/entities/watched-list.js.map +1 -0
- package/dist/core/entities/watched-list.test.cjs +186 -0
- package/dist/core/entities/watched-list.test.cjs.map +1 -0
- package/dist/core/entities/watched-list.test.d.cts +2 -0
- package/dist/core/entities/watched-list.test.d.ts +2 -0
- package/dist/core/entities/watched-list.test.js +185 -0
- package/dist/core/entities/watched-list.test.js.map +1 -0
- package/dist/core/errors/api-common-error.cjs +38 -0
- package/dist/core/errors/api-common-error.cjs.map +1 -0
- package/dist/core/errors/api-common-error.d.cts +28 -0
- package/dist/core/errors/api-common-error.d.ts +28 -0
- package/dist/core/errors/api-common-error.js +13 -0
- package/dist/core/errors/api-common-error.js.map +1 -0
- package/dist/core/errors/application-error.cjs +54 -0
- package/dist/core/errors/application-error.cjs.map +1 -0
- package/dist/core/errors/application-error.d.cts +8 -0
- package/dist/core/errors/application-error.d.ts +8 -0
- package/dist/core/errors/application-error.js +33 -0
- package/dist/core/errors/application-error.js.map +1 -0
- package/dist/core/errors/conflict-error.cjs +56 -0
- package/dist/core/errors/conflict-error.cjs.map +1 -0
- package/dist/core/errors/conflict-error.d.cts +13 -0
- package/dist/core/errors/conflict-error.d.ts +13 -0
- package/dist/core/errors/conflict-error.js +35 -0
- package/dist/core/errors/conflict-error.js.map +1 -0
- package/dist/core/errors/domain-error.cjs +54 -0
- package/dist/core/errors/domain-error.cjs.map +1 -0
- package/dist/core/errors/domain-error.d.cts +8 -0
- package/dist/core/errors/domain-error.d.ts +8 -0
- package/dist/core/errors/domain-error.js +33 -0
- package/dist/core/errors/domain-error.js.map +1 -0
- package/dist/core/errors/http-client-error.cjs +54 -0
- package/dist/core/errors/http-client-error.cjs.map +1 -0
- package/dist/core/errors/http-client-error.d.cts +8 -0
- package/dist/core/errors/http-client-error.d.ts +8 -0
- package/dist/core/errors/http-client-error.js +33 -0
- package/dist/core/errors/http-client-error.js.map +1 -0
- package/dist/core/errors/infra-error.cjs +54 -0
- package/dist/core/errors/infra-error.cjs.map +1 -0
- package/dist/core/errors/infra-error.d.cts +8 -0
- package/dist/core/errors/infra-error.d.ts +8 -0
- package/dist/core/errors/infra-error.js +33 -0
- package/dist/core/errors/infra-error.js.map +1 -0
- package/dist/core/errors/validation-error.cjs +55 -0
- package/dist/core/errors/validation-error.cjs.map +1 -0
- package/dist/core/errors/validation-error.d.cts +8 -0
- package/dist/core/errors/validation-error.d.ts +8 -0
- package/dist/core/errors/validation-error.js +34 -0
- package/dist/core/errors/validation-error.js.map +1 -0
- package/dist/core/http/base-controller.cjs +731 -0
- package/dist/core/http/base-controller.cjs.map +1 -0
- package/dist/core/http/base-controller.d.cts +1 -0
- package/dist/core/http/base-controller.d.ts +1 -0
- package/dist/core/http/base-controller.js +720 -0
- package/dist/core/http/base-controller.js.map +1 -0
- package/dist/core/http/dto-response.cjs +19 -0
- package/dist/core/http/dto-response.cjs.map +1 -0
- package/dist/core/http/dto-response.d.cts +10 -0
- package/dist/core/http/dto-response.d.ts +10 -0
- package/dist/core/http/dto-response.js +1 -0
- package/dist/core/http/dto-response.js.map +1 -0
- package/dist/core/http/error-notifier.cjs +19 -0
- package/dist/core/http/error-notifier.cjs.map +1 -0
- package/dist/core/http/error-notifier.d.cts +1 -0
- package/dist/core/http/error-notifier.d.ts +1 -0
- package/dist/core/http/error-notifier.js +1 -0
- package/dist/core/http/error-notifier.js.map +1 -0
- package/dist/core/http/get-take-and-skip.cjs +40 -0
- package/dist/core/http/get-take-and-skip.cjs.map +1 -0
- package/dist/core/http/get-take-and-skip.d.cts +6 -0
- package/dist/core/http/get-take-and-skip.d.ts +6 -0
- package/dist/core/http/get-take-and-skip.js +17 -0
- package/dist/core/http/get-take-and-skip.js.map +1 -0
- package/dist/core/http/health-connections.cjs +42 -0
- package/dist/core/http/health-connections.cjs.map +1 -0
- package/dist/core/http/health-connections.d.cts +16 -0
- package/dist/core/http/health-connections.d.ts +16 -0
- package/dist/core/http/health-connections.js +23 -0
- package/dist/core/http/health-connections.js.map +1 -0
- package/dist/core/http/http.cjs +19 -0
- package/dist/core/http/http.cjs.map +1 -0
- package/dist/core/http/http.d.cts +10 -0
- package/dist/core/http/http.d.ts +10 -0
- package/dist/core/http/http.js +1 -0
- package/dist/core/http/http.js.map +1 -0
- package/dist/core/http/pagination.cjs +19 -0
- package/dist/core/http/pagination.cjs.map +1 -0
- package/dist/core/http/pagination.d.cts +9 -0
- package/dist/core/http/pagination.d.ts +9 -0
- package/dist/core/http/pagination.js +1 -0
- package/dist/core/http/pagination.js.map +1 -0
- package/dist/core/http/validator.cjs +19 -0
- package/dist/core/http/validator.cjs.map +1 -0
- package/dist/core/http/validator.d.cts +11 -0
- package/dist/core/http/validator.d.ts +11 -0
- package/dist/core/http/validator.js +1 -0
- package/dist/core/http/validator.js.map +1 -0
- package/dist/core/index.cjs +957 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +18 -0
- package/dist/core/index.d.ts +18 -0
- package/dist/core/index.js +933 -0
- package/dist/core/index.js.map +1 -0
- package/dist/infra/adapters/http/express-adapter.cjs +577 -0
- package/dist/infra/adapters/http/express-adapter.cjs.map +1 -0
- package/dist/infra/adapters/http/express-adapter.d.cts +15 -0
- package/dist/infra/adapters/http/express-adapter.d.ts +15 -0
- package/dist/infra/adapters/http/express-adapter.js +556 -0
- package/dist/infra/adapters/http/express-adapter.js.map +1 -0
- package/dist/infra/adapters/http/fastify-adapter.cjs +562 -0
- package/dist/infra/adapters/http/fastify-adapter.cjs.map +1 -0
- package/dist/infra/adapters/http/fastify-adapter.d.cts +14 -0
- package/dist/infra/adapters/http/fastify-adapter.d.ts +14 -0
- package/dist/infra/adapters/http/fastify-adapter.js +541 -0
- package/dist/infra/adapters/http/fastify-adapter.js.map +1 -0
- package/dist/infra/adapters/http/response-error-code.cjs +35 -0
- package/dist/infra/adapters/http/response-error-code.cjs.map +1 -0
- package/dist/infra/adapters/http/response-error-code.d.cts +6 -0
- package/dist/infra/adapters/http/response-error-code.d.ts +6 -0
- package/dist/infra/adapters/http/response-error-code.js +10 -0
- package/dist/infra/adapters/http/response-error-code.js.map +1 -0
- package/dist/infra/adapters/http/validate-controller-metadata.cjs +42 -0
- package/dist/infra/adapters/http/validate-controller-metadata.cjs.map +1 -0
- package/dist/infra/adapters/http/validate-controller-metadata.d.cts +11 -0
- package/dist/infra/adapters/http/validate-controller-metadata.d.ts +11 -0
- package/dist/infra/adapters/http/validate-controller-metadata.js +19 -0
- package/dist/infra/adapters/http/validate-controller-metadata.js.map +1 -0
- package/dist/infra/adapters/notifications/discord.cjs +86 -0
- package/dist/infra/adapters/notifications/discord.cjs.map +1 -0
- package/dist/infra/adapters/notifications/discord.d.cts +14 -0
- package/dist/infra/adapters/notifications/discord.d.ts +14 -0
- package/dist/infra/adapters/notifications/discord.js +65 -0
- package/dist/infra/adapters/notifications/discord.js.map +1 -0
- package/dist/infra/adapters/notifications/in-memory.cjs +40 -0
- package/dist/infra/adapters/notifications/in-memory.cjs.map +1 -0
- package/dist/infra/adapters/notifications/in-memory.d.cts +8 -0
- package/dist/infra/adapters/notifications/in-memory.d.ts +8 -0
- package/dist/infra/adapters/notifications/in-memory.js +21 -0
- package/dist/infra/adapters/notifications/in-memory.js.map +1 -0
- package/dist/infra/adapters/notifications/sentry.cjs +129 -0
- package/dist/infra/adapters/notifications/sentry.cjs.map +1 -0
- package/dist/infra/adapters/notifications/sentry.d.cts +13 -0
- package/dist/infra/adapters/notifications/sentry.d.ts +13 -0
- package/dist/infra/adapters/notifications/sentry.js +96 -0
- package/dist/infra/adapters/notifications/sentry.js.map +1 -0
- package/dist/infra/adapters/validators/zod/index.cjs +179 -0
- package/dist/infra/adapters/validators/zod/index.cjs.map +1 -0
- package/dist/infra/adapters/validators/zod/index.d.cts +19 -0
- package/dist/infra/adapters/validators/zod/index.d.ts +19 -0
- package/dist/infra/adapters/validators/zod/index.js +154 -0
- package/dist/infra/adapters/validators/zod/index.js.map +1 -0
- package/dist/infra/adapters/validators/zod/zod-map-error.cjs +79 -0
- package/dist/infra/adapters/validators/zod/zod-map-error.cjs.map +1 -0
- package/dist/infra/adapters/validators/zod/zod-map-error.d.cts +15 -0
- package/dist/infra/adapters/validators/zod/zod-map-error.d.ts +15 -0
- package/dist/infra/adapters/validators/zod/zod-map-error.js +60 -0
- package/dist/infra/adapters/validators/zod/zod-map-error.js.map +1 -0
- package/dist/infra/adapters/validators/zod/zod-validator.cjs +178 -0
- package/dist/infra/adapters/validators/zod/zod-validator.cjs.map +1 -0
- package/dist/infra/adapters/validators/zod/zod-validator.d.cts +13 -0
- package/dist/infra/adapters/validators/zod/zod-validator.d.ts +13 -0
- package/dist/infra/adapters/validators/zod/zod-validator.js +153 -0
- package/dist/infra/adapters/validators/zod/zod-validator.js.map +1 -0
- package/dist/infra/env/index.cjs +473 -0
- package/dist/infra/env/index.cjs.map +1 -0
- package/dist/infra/env/index.d.cts +10 -0
- package/dist/infra/env/index.d.ts +10 -0
- package/dist/infra/env/index.js +456 -0
- package/dist/infra/env/index.js.map +1 -0
- package/dist/infra/index.cjs +781 -0
- package/dist/infra/index.cjs.map +1 -0
- package/dist/infra/index.d.cts +5 -0
- package/dist/infra/index.d.ts +5 -0
- package/dist/infra/index.js +752 -0
- package/dist/infra/index.js.map +1 -0
- package/package.json +82 -0
- package/readme.md +56 -0
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
5
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
6
|
+
}) : x)(function(x) {
|
|
7
|
+
if (typeof require !== "undefined")
|
|
8
|
+
return require.apply(this, arguments);
|
|
9
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
|
+
});
|
|
11
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
12
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// node_modules/dotenv/package.json
|
|
16
|
+
var require_package = __commonJS({
|
|
17
|
+
"node_modules/dotenv/package.json"(exports, module) {
|
|
18
|
+
module.exports = {
|
|
19
|
+
name: "dotenv",
|
|
20
|
+
version: "16.5.0",
|
|
21
|
+
description: "Loads environment variables from .env file",
|
|
22
|
+
main: "lib/main.js",
|
|
23
|
+
types: "lib/main.d.ts",
|
|
24
|
+
exports: {
|
|
25
|
+
".": {
|
|
26
|
+
types: "./lib/main.d.ts",
|
|
27
|
+
require: "./lib/main.js",
|
|
28
|
+
default: "./lib/main.js"
|
|
29
|
+
},
|
|
30
|
+
"./config": "./config.js",
|
|
31
|
+
"./config.js": "./config.js",
|
|
32
|
+
"./lib/env-options": "./lib/env-options.js",
|
|
33
|
+
"./lib/env-options.js": "./lib/env-options.js",
|
|
34
|
+
"./lib/cli-options": "./lib/cli-options.js",
|
|
35
|
+
"./lib/cli-options.js": "./lib/cli-options.js",
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
scripts: {
|
|
39
|
+
"dts-check": "tsc --project tests/types/tsconfig.json",
|
|
40
|
+
lint: "standard",
|
|
41
|
+
pretest: "npm run lint && npm run dts-check",
|
|
42
|
+
test: "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
|
|
43
|
+
"test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=lcov",
|
|
44
|
+
prerelease: "npm test",
|
|
45
|
+
release: "standard-version"
|
|
46
|
+
},
|
|
47
|
+
repository: {
|
|
48
|
+
type: "git",
|
|
49
|
+
url: "git://github.com/motdotla/dotenv.git"
|
|
50
|
+
},
|
|
51
|
+
homepage: "https://github.com/motdotla/dotenv#readme",
|
|
52
|
+
funding: "https://dotenvx.com",
|
|
53
|
+
keywords: [
|
|
54
|
+
"dotenv",
|
|
55
|
+
"env",
|
|
56
|
+
".env",
|
|
57
|
+
"environment",
|
|
58
|
+
"variables",
|
|
59
|
+
"config",
|
|
60
|
+
"settings"
|
|
61
|
+
],
|
|
62
|
+
readmeFilename: "README.md",
|
|
63
|
+
license: "BSD-2-Clause",
|
|
64
|
+
devDependencies: {
|
|
65
|
+
"@types/node": "^18.11.3",
|
|
66
|
+
decache: "^4.6.2",
|
|
67
|
+
sinon: "^14.0.1",
|
|
68
|
+
standard: "^17.0.0",
|
|
69
|
+
"standard-version": "^9.5.0",
|
|
70
|
+
tap: "^19.2.0",
|
|
71
|
+
typescript: "^4.8.4"
|
|
72
|
+
},
|
|
73
|
+
engines: {
|
|
74
|
+
node: ">=12"
|
|
75
|
+
},
|
|
76
|
+
browser: {
|
|
77
|
+
fs: false
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// node_modules/dotenv/lib/main.js
|
|
84
|
+
var require_main = __commonJS({
|
|
85
|
+
"node_modules/dotenv/lib/main.js"(exports, module) {
|
|
86
|
+
"use strict";
|
|
87
|
+
var fs = __require("fs");
|
|
88
|
+
var path = __require("path");
|
|
89
|
+
var os = __require("os");
|
|
90
|
+
var crypto = __require("crypto");
|
|
91
|
+
var packageJson = require_package();
|
|
92
|
+
var version = packageJson.version;
|
|
93
|
+
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
94
|
+
function parse(src) {
|
|
95
|
+
const obj = {};
|
|
96
|
+
let lines = src.toString();
|
|
97
|
+
lines = lines.replace(/\r\n?/mg, "\n");
|
|
98
|
+
let match;
|
|
99
|
+
while ((match = LINE.exec(lines)) != null) {
|
|
100
|
+
const key = match[1];
|
|
101
|
+
let value = match[2] || "";
|
|
102
|
+
value = value.trim();
|
|
103
|
+
const maybeQuote = value[0];
|
|
104
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
|
|
105
|
+
if (maybeQuote === '"') {
|
|
106
|
+
value = value.replace(/\\n/g, "\n");
|
|
107
|
+
value = value.replace(/\\r/g, "\r");
|
|
108
|
+
}
|
|
109
|
+
obj[key] = value;
|
|
110
|
+
}
|
|
111
|
+
return obj;
|
|
112
|
+
}
|
|
113
|
+
__name(parse, "parse");
|
|
114
|
+
function _parseVault(options) {
|
|
115
|
+
const vaultPath = _vaultPath(options);
|
|
116
|
+
const result = DotenvModule.configDotenv({
|
|
117
|
+
path: vaultPath
|
|
118
|
+
});
|
|
119
|
+
if (!result.parsed) {
|
|
120
|
+
const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
|
|
121
|
+
err.code = "MISSING_DATA";
|
|
122
|
+
throw err;
|
|
123
|
+
}
|
|
124
|
+
const keys = _dotenvKey(options).split(",");
|
|
125
|
+
const length = keys.length;
|
|
126
|
+
let decrypted;
|
|
127
|
+
for (let i = 0; i < length; i++) {
|
|
128
|
+
try {
|
|
129
|
+
const key = keys[i].trim();
|
|
130
|
+
const attrs = _instructions(result, key);
|
|
131
|
+
decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
|
|
132
|
+
break;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (i + 1 >= length) {
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return DotenvModule.parse(decrypted);
|
|
140
|
+
}
|
|
141
|
+
__name(_parseVault, "_parseVault");
|
|
142
|
+
function _warn(message) {
|
|
143
|
+
console.log(`[dotenv@${version}][WARN] ${message}`);
|
|
144
|
+
}
|
|
145
|
+
__name(_warn, "_warn");
|
|
146
|
+
function _debug(message) {
|
|
147
|
+
console.log(`[dotenv@${version}][DEBUG] ${message}`);
|
|
148
|
+
}
|
|
149
|
+
__name(_debug, "_debug");
|
|
150
|
+
function _dotenvKey(options) {
|
|
151
|
+
if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
|
|
152
|
+
return options.DOTENV_KEY;
|
|
153
|
+
}
|
|
154
|
+
if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
|
|
155
|
+
return process.env.DOTENV_KEY;
|
|
156
|
+
}
|
|
157
|
+
return "";
|
|
158
|
+
}
|
|
159
|
+
__name(_dotenvKey, "_dotenvKey");
|
|
160
|
+
function _instructions(result, dotenvKey) {
|
|
161
|
+
let uri;
|
|
162
|
+
try {
|
|
163
|
+
uri = new URL(dotenvKey);
|
|
164
|
+
} catch (error) {
|
|
165
|
+
if (error.code === "ERR_INVALID_URL") {
|
|
166
|
+
const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
|
|
167
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
168
|
+
throw err;
|
|
169
|
+
}
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
const key = uri.password;
|
|
173
|
+
if (!key) {
|
|
174
|
+
const err = new Error("INVALID_DOTENV_KEY: Missing key part");
|
|
175
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
176
|
+
throw err;
|
|
177
|
+
}
|
|
178
|
+
const environment = uri.searchParams.get("environment");
|
|
179
|
+
if (!environment) {
|
|
180
|
+
const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
|
|
181
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
182
|
+
throw err;
|
|
183
|
+
}
|
|
184
|
+
const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
|
|
185
|
+
const ciphertext = result.parsed[environmentKey];
|
|
186
|
+
if (!ciphertext) {
|
|
187
|
+
const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
|
|
188
|
+
err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
|
|
189
|
+
throw err;
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
ciphertext,
|
|
193
|
+
key
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
__name(_instructions, "_instructions");
|
|
197
|
+
function _vaultPath(options) {
|
|
198
|
+
let possibleVaultPath = null;
|
|
199
|
+
if (options && options.path && options.path.length > 0) {
|
|
200
|
+
if (Array.isArray(options.path)) {
|
|
201
|
+
for (const filepath of options.path) {
|
|
202
|
+
if (fs.existsSync(filepath)) {
|
|
203
|
+
possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
|
|
211
|
+
}
|
|
212
|
+
if (fs.existsSync(possibleVaultPath)) {
|
|
213
|
+
return possibleVaultPath;
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
__name(_vaultPath, "_vaultPath");
|
|
218
|
+
function _resolveHome(envPath) {
|
|
219
|
+
return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
|
|
220
|
+
}
|
|
221
|
+
__name(_resolveHome, "_resolveHome");
|
|
222
|
+
function _configVault(options) {
|
|
223
|
+
const debug = Boolean(options && options.debug);
|
|
224
|
+
if (debug) {
|
|
225
|
+
_debug("Loading env from encrypted .env.vault");
|
|
226
|
+
}
|
|
227
|
+
const parsed = DotenvModule._parseVault(options);
|
|
228
|
+
let processEnv = process.env;
|
|
229
|
+
if (options && options.processEnv != null) {
|
|
230
|
+
processEnv = options.processEnv;
|
|
231
|
+
}
|
|
232
|
+
DotenvModule.populate(processEnv, parsed, options);
|
|
233
|
+
return {
|
|
234
|
+
parsed
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
__name(_configVault, "_configVault");
|
|
238
|
+
function configDotenv(options) {
|
|
239
|
+
const dotenvPath = path.resolve(process.cwd(), ".env");
|
|
240
|
+
let encoding = "utf8";
|
|
241
|
+
const debug = Boolean(options && options.debug);
|
|
242
|
+
if (options && options.encoding) {
|
|
243
|
+
encoding = options.encoding;
|
|
244
|
+
} else {
|
|
245
|
+
if (debug) {
|
|
246
|
+
_debug("No encoding is specified. UTF-8 is used by default");
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
let optionPaths = [
|
|
250
|
+
dotenvPath
|
|
251
|
+
];
|
|
252
|
+
if (options && options.path) {
|
|
253
|
+
if (!Array.isArray(options.path)) {
|
|
254
|
+
optionPaths = [
|
|
255
|
+
_resolveHome(options.path)
|
|
256
|
+
];
|
|
257
|
+
} else {
|
|
258
|
+
optionPaths = [];
|
|
259
|
+
for (const filepath of options.path) {
|
|
260
|
+
optionPaths.push(_resolveHome(filepath));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
let lastError;
|
|
265
|
+
const parsedAll = {};
|
|
266
|
+
for (const path2 of optionPaths) {
|
|
267
|
+
try {
|
|
268
|
+
const parsed = DotenvModule.parse(fs.readFileSync(path2, {
|
|
269
|
+
encoding
|
|
270
|
+
}));
|
|
271
|
+
DotenvModule.populate(parsedAll, parsed, options);
|
|
272
|
+
} catch (e) {
|
|
273
|
+
if (debug) {
|
|
274
|
+
_debug(`Failed to load ${path2} ${e.message}`);
|
|
275
|
+
}
|
|
276
|
+
lastError = e;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
let processEnv = process.env;
|
|
280
|
+
if (options && options.processEnv != null) {
|
|
281
|
+
processEnv = options.processEnv;
|
|
282
|
+
}
|
|
283
|
+
DotenvModule.populate(processEnv, parsedAll, options);
|
|
284
|
+
if (lastError) {
|
|
285
|
+
return {
|
|
286
|
+
parsed: parsedAll,
|
|
287
|
+
error: lastError
|
|
288
|
+
};
|
|
289
|
+
} else {
|
|
290
|
+
return {
|
|
291
|
+
parsed: parsedAll
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
__name(configDotenv, "configDotenv");
|
|
296
|
+
function config(options) {
|
|
297
|
+
if (_dotenvKey(options).length === 0) {
|
|
298
|
+
return DotenvModule.configDotenv(options);
|
|
299
|
+
}
|
|
300
|
+
const vaultPath = _vaultPath(options);
|
|
301
|
+
if (!vaultPath) {
|
|
302
|
+
_warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
|
|
303
|
+
return DotenvModule.configDotenv(options);
|
|
304
|
+
}
|
|
305
|
+
return DotenvModule._configVault(options);
|
|
306
|
+
}
|
|
307
|
+
__name(config, "config");
|
|
308
|
+
function decrypt(encrypted, keyStr) {
|
|
309
|
+
const key = Buffer.from(keyStr.slice(-64), "hex");
|
|
310
|
+
let ciphertext = Buffer.from(encrypted, "base64");
|
|
311
|
+
const nonce = ciphertext.subarray(0, 12);
|
|
312
|
+
const authTag = ciphertext.subarray(-16);
|
|
313
|
+
ciphertext = ciphertext.subarray(12, -16);
|
|
314
|
+
try {
|
|
315
|
+
const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
|
|
316
|
+
aesgcm.setAuthTag(authTag);
|
|
317
|
+
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
|
318
|
+
} catch (error) {
|
|
319
|
+
const isRange = error instanceof RangeError;
|
|
320
|
+
const invalidKeyLength = error.message === "Invalid key length";
|
|
321
|
+
const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
|
|
322
|
+
if (isRange || invalidKeyLength) {
|
|
323
|
+
const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
|
|
324
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
325
|
+
throw err;
|
|
326
|
+
} else if (decryptionFailed) {
|
|
327
|
+
const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
|
|
328
|
+
err.code = "DECRYPTION_FAILED";
|
|
329
|
+
throw err;
|
|
330
|
+
} else {
|
|
331
|
+
throw error;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
__name(decrypt, "decrypt");
|
|
336
|
+
function populate(processEnv, parsed, options = {}) {
|
|
337
|
+
const debug = Boolean(options && options.debug);
|
|
338
|
+
const override = Boolean(options && options.override);
|
|
339
|
+
if (typeof parsed !== "object") {
|
|
340
|
+
const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
|
|
341
|
+
err.code = "OBJECT_REQUIRED";
|
|
342
|
+
throw err;
|
|
343
|
+
}
|
|
344
|
+
for (const key of Object.keys(parsed)) {
|
|
345
|
+
if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
|
|
346
|
+
if (override === true) {
|
|
347
|
+
processEnv[key] = parsed[key];
|
|
348
|
+
}
|
|
349
|
+
if (debug) {
|
|
350
|
+
if (override === true) {
|
|
351
|
+
_debug(`"${key}" is already defined and WAS overwritten`);
|
|
352
|
+
} else {
|
|
353
|
+
_debug(`"${key}" is already defined and was NOT overwritten`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
} else {
|
|
357
|
+
processEnv[key] = parsed[key];
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
__name(populate, "populate");
|
|
362
|
+
var DotenvModule = {
|
|
363
|
+
configDotenv,
|
|
364
|
+
_configVault,
|
|
365
|
+
_parseVault,
|
|
366
|
+
config,
|
|
367
|
+
decrypt,
|
|
368
|
+
parse,
|
|
369
|
+
populate
|
|
370
|
+
};
|
|
371
|
+
module.exports.configDotenv = DotenvModule.configDotenv;
|
|
372
|
+
module.exports._configVault = DotenvModule._configVault;
|
|
373
|
+
module.exports._parseVault = DotenvModule._parseVault;
|
|
374
|
+
module.exports.config = DotenvModule.config;
|
|
375
|
+
module.exports.decrypt = DotenvModule.decrypt;
|
|
376
|
+
module.exports.parse = DotenvModule.parse;
|
|
377
|
+
module.exports.populate = DotenvModule.populate;
|
|
378
|
+
module.exports = DotenvModule;
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
// node_modules/dotenv/lib/env-options.js
|
|
383
|
+
var require_env_options = __commonJS({
|
|
384
|
+
"node_modules/dotenv/lib/env-options.js"(exports, module) {
|
|
385
|
+
"use strict";
|
|
386
|
+
var options = {};
|
|
387
|
+
if (process.env.DOTENV_CONFIG_ENCODING != null) {
|
|
388
|
+
options.encoding = process.env.DOTENV_CONFIG_ENCODING;
|
|
389
|
+
}
|
|
390
|
+
if (process.env.DOTENV_CONFIG_PATH != null) {
|
|
391
|
+
options.path = process.env.DOTENV_CONFIG_PATH;
|
|
392
|
+
}
|
|
393
|
+
if (process.env.DOTENV_CONFIG_DEBUG != null) {
|
|
394
|
+
options.debug = process.env.DOTENV_CONFIG_DEBUG;
|
|
395
|
+
}
|
|
396
|
+
if (process.env.DOTENV_CONFIG_OVERRIDE != null) {
|
|
397
|
+
options.override = process.env.DOTENV_CONFIG_OVERRIDE;
|
|
398
|
+
}
|
|
399
|
+
if (process.env.DOTENV_CONFIG_DOTENV_KEY != null) {
|
|
400
|
+
options.DOTENV_KEY = process.env.DOTENV_CONFIG_DOTENV_KEY;
|
|
401
|
+
}
|
|
402
|
+
module.exports = options;
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
// node_modules/dotenv/lib/cli-options.js
|
|
407
|
+
var require_cli_options = __commonJS({
|
|
408
|
+
"node_modules/dotenv/lib/cli-options.js"(exports, module) {
|
|
409
|
+
"use strict";
|
|
410
|
+
var re = /^dotenv_config_(encoding|path|debug|override|DOTENV_KEY)=(.+)$/;
|
|
411
|
+
module.exports = /* @__PURE__ */ __name(function optionMatcher(args) {
|
|
412
|
+
return args.reduce(function(acc, cur) {
|
|
413
|
+
const matches = cur.match(re);
|
|
414
|
+
if (matches) {
|
|
415
|
+
acc[matches[1]] = matches[2];
|
|
416
|
+
}
|
|
417
|
+
return acc;
|
|
418
|
+
}, {});
|
|
419
|
+
}, "optionMatcher");
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
// src/infra/adapters/http/express-adapter.ts
|
|
424
|
+
import cors from "cors";
|
|
425
|
+
import express from "express";
|
|
426
|
+
|
|
427
|
+
// node_modules/dotenv/config.js
|
|
428
|
+
(function() {
|
|
429
|
+
require_main().config(Object.assign({}, require_env_options(), require_cli_options()(process.argv)));
|
|
430
|
+
})();
|
|
431
|
+
|
|
432
|
+
// src/infra/env/index.ts
|
|
433
|
+
import { z } from "zod";
|
|
434
|
+
var envSchema = z.object({
|
|
435
|
+
NODE_ENV: z.enum([
|
|
436
|
+
"test",
|
|
437
|
+
"development",
|
|
438
|
+
"production"
|
|
439
|
+
]).default("production"),
|
|
440
|
+
ENVIRONMENT: z.enum([
|
|
441
|
+
"test",
|
|
442
|
+
"development",
|
|
443
|
+
"staging",
|
|
444
|
+
"production"
|
|
445
|
+
]).default("development"),
|
|
446
|
+
PORT: z.coerce.number().default(3333),
|
|
447
|
+
SHOULD_NOTIFY_ERROR: z.coerce.boolean().default(true),
|
|
448
|
+
SENTRY_DSN: z.string().optional(),
|
|
449
|
+
DISCORD_WEBHOOK_URL: z.string().optional()
|
|
450
|
+
});
|
|
451
|
+
var _env = envSchema.safeParse(process.env);
|
|
452
|
+
if (_env.success === false) {
|
|
453
|
+
console.error("\u274C Invalid environment variables.", _env.error.format());
|
|
454
|
+
throw new Error("Invalid environment variables.");
|
|
455
|
+
}
|
|
456
|
+
var env = _env.data;
|
|
457
|
+
|
|
458
|
+
// src/infra/adapters/http/validate-controller-metadata.ts
|
|
459
|
+
import "reflect-metadata";
|
|
460
|
+
|
|
461
|
+
// src/infra/adapters/http/fastify-adapter.ts
|
|
462
|
+
import cors2 from "@fastify/cors";
|
|
463
|
+
import fastify from "fastify";
|
|
464
|
+
import qs from "qs";
|
|
465
|
+
|
|
466
|
+
// src/core/decorators/dependency-container.ts
|
|
467
|
+
import "reflect-metadata";
|
|
468
|
+
function Inject(token) {
|
|
469
|
+
return (target, _propertyKey, parameterIndex) => {
|
|
470
|
+
const constructor = typeof target === "function" ? target : target.constructor;
|
|
471
|
+
const existingInjectedParams = Reflect.getOwnMetadata("inject:params", constructor) || {};
|
|
472
|
+
existingInjectedParams[parameterIndex] = token;
|
|
473
|
+
Reflect.defineMetadata("inject:params", existingInjectedParams, constructor);
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
__name(Inject, "Inject");
|
|
477
|
+
|
|
478
|
+
// src/infra/adapters/notifications/discord.ts
|
|
479
|
+
import { MessageBuilder, Webhook } from "discord-webhook-node";
|
|
480
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
481
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
482
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
483
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
484
|
+
else
|
|
485
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
486
|
+
if (d = decorators[i])
|
|
487
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
488
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
489
|
+
}
|
|
490
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
491
|
+
function _ts_metadata(k, v) {
|
|
492
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
493
|
+
return Reflect.metadata(k, v);
|
|
494
|
+
}
|
|
495
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
496
|
+
function _ts_param(paramIndex, decorator) {
|
|
497
|
+
return function(target, key) {
|
|
498
|
+
decorator(target, key, paramIndex);
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
__name(_ts_param, "_ts_param");
|
|
502
|
+
var DiscordNotifier = class {
|
|
503
|
+
static {
|
|
504
|
+
__name(this, "DiscordNotifier");
|
|
505
|
+
}
|
|
506
|
+
options;
|
|
507
|
+
webhook;
|
|
508
|
+
constructor(options) {
|
|
509
|
+
this.options = options;
|
|
510
|
+
this.webhook = new Webhook(this.options.url);
|
|
511
|
+
}
|
|
512
|
+
async notify(error, context) {
|
|
513
|
+
const embed = new MessageBuilder().setTitle("\u{1F6A8} Error").addField("Message", `\`\`\`${error.message.slice(0, 300)}\`\`\``).addField("Route:", `\`[${context?.request?.method}] ${context?.request?.url}\``, true).addField("Params:", "```json\n" + JSON.stringify(context?.request?.params, null, 2) + "\n```", true).addField("Query:", "```json\n" + JSON.stringify(context?.request?.query, null, 2) + "\n```", true).addField("Headers:", "```json\n" + JSON.stringify(context?.request?.headers, null, 2) + "\n```", true).addField("Body:", "```json\n" + JSON.stringify(context?.request?.body, null, 2) + "\n```").addField("Stack Trace:", "```" + (error.stack || "No stack provided").slice(0, 900) + "```").setFooter(`Env: ${this.options.env || "development"}`).setTimestamp();
|
|
514
|
+
await this.webhook.send(embed);
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
DiscordNotifier = _ts_decorate([
|
|
518
|
+
_ts_param(0, Inject("DiscordConfig")),
|
|
519
|
+
_ts_metadata("design:type", Function),
|
|
520
|
+
_ts_metadata("design:paramtypes", [
|
|
521
|
+
typeof DiscordOptions === "undefined" ? Object : DiscordOptions
|
|
522
|
+
])
|
|
523
|
+
], DiscordNotifier);
|
|
524
|
+
|
|
525
|
+
// src/infra/adapters/notifications/sentry.ts
|
|
526
|
+
import * as Sentry from "@sentry/node";
|
|
527
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
528
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
529
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
530
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
531
|
+
else
|
|
532
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
533
|
+
if (d = decorators[i])
|
|
534
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
535
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
536
|
+
}
|
|
537
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
538
|
+
function _ts_metadata2(k, v) {
|
|
539
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
540
|
+
return Reflect.metadata(k, v);
|
|
541
|
+
}
|
|
542
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
543
|
+
function _ts_param2(paramIndex, decorator) {
|
|
544
|
+
return function(target, key) {
|
|
545
|
+
decorator(target, key, paramIndex);
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
__name(_ts_param2, "_ts_param");
|
|
549
|
+
var SentryNotifier = class {
|
|
550
|
+
static {
|
|
551
|
+
__name(this, "SentryNotifier");
|
|
552
|
+
}
|
|
553
|
+
options;
|
|
554
|
+
constructor(options) {
|
|
555
|
+
this.options = options;
|
|
556
|
+
Sentry.init({
|
|
557
|
+
dsn: this.options.dsn,
|
|
558
|
+
environment: this.options.environment,
|
|
559
|
+
attachStacktrace: true,
|
|
560
|
+
tracesSampleRate: this.options.environment === "production" ? 0.1 : 1,
|
|
561
|
+
maxBreadcrumbs: 100,
|
|
562
|
+
debug: this.options.environment !== "production"
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
async notify(error, context) {
|
|
566
|
+
Sentry.withScope((scope) => {
|
|
567
|
+
scope.setLevel("error");
|
|
568
|
+
if (context?.env)
|
|
569
|
+
scope.setTag("env", context.env);
|
|
570
|
+
if (context?.user) {
|
|
571
|
+
scope.setUser({
|
|
572
|
+
id: context.user.id,
|
|
573
|
+
username: context.user.name,
|
|
574
|
+
email: context.user.email
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
if (context?.request) {
|
|
578
|
+
const { body, query, params, headers, method, url, requestId } = context.request;
|
|
579
|
+
scope.setContext("http", {
|
|
580
|
+
method,
|
|
581
|
+
requestId,
|
|
582
|
+
url,
|
|
583
|
+
headers,
|
|
584
|
+
query,
|
|
585
|
+
body,
|
|
586
|
+
params
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
Sentry.captureException(error);
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
SentryNotifier = _ts_decorate2([
|
|
594
|
+
_ts_param2(0, Inject("SentryConfig")),
|
|
595
|
+
_ts_metadata2("design:type", Function),
|
|
596
|
+
_ts_metadata2("design:paramtypes", [
|
|
597
|
+
typeof SentryOptions === "undefined" ? Object : SentryOptions
|
|
598
|
+
])
|
|
599
|
+
], SentryNotifier);
|
|
600
|
+
|
|
601
|
+
// src/core/errors/api-common-error.ts
|
|
602
|
+
var ApiErrorEnum = /* @__PURE__ */ function(ApiErrorEnum2) {
|
|
603
|
+
ApiErrorEnum2["DOMAIN"] = "ERR001";
|
|
604
|
+
ApiErrorEnum2["APPLICATION"] = "ERR002";
|
|
605
|
+
ApiErrorEnum2["INFRA"] = "ERR003";
|
|
606
|
+
ApiErrorEnum2["HTTP_CLIENT"] = "ERR004";
|
|
607
|
+
ApiErrorEnum2["VALIDATOR"] = "ERR005";
|
|
608
|
+
return ApiErrorEnum2;
|
|
609
|
+
}({});
|
|
610
|
+
|
|
611
|
+
// src/core/errors/validation-error.ts
|
|
612
|
+
var ValidationError = class extends Error {
|
|
613
|
+
static {
|
|
614
|
+
__name(this, "ValidationError");
|
|
615
|
+
}
|
|
616
|
+
props;
|
|
617
|
+
constructor(errors) {
|
|
618
|
+
super("Validation Error");
|
|
619
|
+
this.props = {
|
|
620
|
+
code: 400,
|
|
621
|
+
errorCode: ApiErrorEnum.VALIDATOR,
|
|
622
|
+
message: "Validation Error",
|
|
623
|
+
occurredAt: /* @__PURE__ */ new Date(),
|
|
624
|
+
errors
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
// src/infra/adapters/validators/zod/zod-map-error.ts
|
|
630
|
+
var ZodMapError = class {
|
|
631
|
+
static {
|
|
632
|
+
__name(this, "ZodMapError");
|
|
633
|
+
}
|
|
634
|
+
static mapCommon(error) {
|
|
635
|
+
return {
|
|
636
|
+
type: error.code,
|
|
637
|
+
path: error.path.join("."),
|
|
638
|
+
property: error.path.pop(),
|
|
639
|
+
propertyType: error.expected,
|
|
640
|
+
receivedValue: error.received,
|
|
641
|
+
message: error.message
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
static mapInvalidUnion(error) {
|
|
645
|
+
const [errors] = error.unionErrors.flat().map((err) => err.issues.map((item) => this.mapCommon(item)));
|
|
646
|
+
return errors;
|
|
647
|
+
}
|
|
648
|
+
static mapInvalidType(error) {
|
|
649
|
+
return [
|
|
650
|
+
this.mapCommon(error)
|
|
651
|
+
];
|
|
652
|
+
}
|
|
653
|
+
static mapErrorsFactory(error) {
|
|
654
|
+
if (error.code === "invalid_union") {
|
|
655
|
+
return this.mapInvalidUnion(error);
|
|
656
|
+
}
|
|
657
|
+
return this.mapInvalidType(error);
|
|
658
|
+
}
|
|
659
|
+
static mapErrors(errors) {
|
|
660
|
+
const standardizedErrors = /* @__PURE__ */ new Map();
|
|
661
|
+
errors.flat().forEach((error) => {
|
|
662
|
+
const keyError = standardizedErrors.get(error.path[0]);
|
|
663
|
+
if (keyError) {
|
|
664
|
+
if (!keyError.propertyErrors) {
|
|
665
|
+
keyError.propertyErrors = [];
|
|
666
|
+
}
|
|
667
|
+
keyError.propertyErrors.push(...this.mapErrorsFactory(error));
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
standardizedErrors.set(error.path[0], {
|
|
671
|
+
location: error.path[0],
|
|
672
|
+
propertyErrors: Array.from([
|
|
673
|
+
...this.mapErrorsFactory(error)
|
|
674
|
+
])
|
|
675
|
+
});
|
|
676
|
+
});
|
|
677
|
+
return Array.from(standardizedErrors, ([, arr]) => ({
|
|
678
|
+
...arr
|
|
679
|
+
})).flat();
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
// src/infra/adapters/validators/zod/index.ts
|
|
684
|
+
var ZodValidator = class {
|
|
685
|
+
static {
|
|
686
|
+
__name(this, "ZodValidator");
|
|
687
|
+
}
|
|
688
|
+
zodSchema;
|
|
689
|
+
constructor(zodSchema) {
|
|
690
|
+
this.zodSchema = zodSchema;
|
|
691
|
+
}
|
|
692
|
+
async validate(requestHttp) {
|
|
693
|
+
const errors = [];
|
|
694
|
+
const { data: headersData = {}, error: headersErrors = {} } = requestHttp.headers ? await this.zodSchema.shape.headers.safeParseAsync(requestHttp.headers, {
|
|
695
|
+
path: [
|
|
696
|
+
"headers"
|
|
697
|
+
]
|
|
698
|
+
}) : {};
|
|
699
|
+
if (headersErrors?.errors) {
|
|
700
|
+
errors.push(headersErrors?.errors);
|
|
701
|
+
}
|
|
702
|
+
const { data: paramsData = {}, error: paramsErrors = {} } = requestHttp.params ? await this.zodSchema.shape.params.safeParseAsync(requestHttp.params, {
|
|
703
|
+
path: [
|
|
704
|
+
"params"
|
|
705
|
+
]
|
|
706
|
+
}) : {};
|
|
707
|
+
if (paramsErrors?.errors) {
|
|
708
|
+
errors.push(paramsErrors?.errors);
|
|
709
|
+
}
|
|
710
|
+
const { data: queryData = {}, error: queryErrors = {} } = requestHttp.query ? await this.zodSchema.shape.query.safeParseAsync(requestHttp.query, {
|
|
711
|
+
path: [
|
|
712
|
+
"query"
|
|
713
|
+
]
|
|
714
|
+
}) : {};
|
|
715
|
+
if (queryErrors?.errors) {
|
|
716
|
+
errors.push(queryErrors?.errors);
|
|
717
|
+
}
|
|
718
|
+
const { data: bodyData = {}, error: bodyErrors = {} } = requestHttp.body ? await this.zodSchema.shape.body.safeParseAsync(requestHttp.body, {
|
|
719
|
+
path: [
|
|
720
|
+
"body"
|
|
721
|
+
]
|
|
722
|
+
}) : {};
|
|
723
|
+
if (bodyErrors?.errors) {
|
|
724
|
+
errors.push(bodyErrors?.errors);
|
|
725
|
+
}
|
|
726
|
+
if (errors.length) {
|
|
727
|
+
throw new ValidationError(ZodMapError.mapErrors(errors));
|
|
728
|
+
}
|
|
729
|
+
return {
|
|
730
|
+
body: bodyData,
|
|
731
|
+
headers: headersData,
|
|
732
|
+
params: paramsData,
|
|
733
|
+
query: queryData
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
// src/infra/adapters/validators/zod/zod-validator.ts
|
|
739
|
+
function zodValidator(schema) {
|
|
740
|
+
return async (request) => {
|
|
741
|
+
const validator = new ZodValidator(schema);
|
|
742
|
+
const validatedRequest = await validator.validate(request);
|
|
743
|
+
return validatedRequest;
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
__name(zodValidator, "zodValidator");
|
|
747
|
+
export {
|
|
748
|
+
SentryNotifier,
|
|
749
|
+
env,
|
|
750
|
+
zodValidator
|
|
751
|
+
};
|
|
752
|
+
//# sourceMappingURL=index.js.map
|