plutin 1.1.3 → 1.2.1
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/core/decorators/controller-http-decorator.cjs +1 -3
- package/dist/core/decorators/controller-http-decorator.cjs.map +1 -1
- package/dist/core/decorators/controller-http-decorator.js +1 -3
- package/dist/core/decorators/controller-http-decorator.js.map +1 -1
- package/dist/core/http/base-controller.cjs +1 -1
- package/dist/core/http/base-controller.cjs.map +1 -1
- package/dist/core/http/base-controller.js +1 -3
- package/dist/core/http/base-controller.js.map +1 -1
- package/dist/index.cjs +189 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +186 -4
- package/dist/index.js.map +1 -1
- package/dist/infra/adapters/http/express-adapter.cjs +5 -1
- package/dist/infra/adapters/http/express-adapter.cjs.map +1 -1
- package/dist/infra/adapters/http/express-adapter.d.cts +1 -1
- package/dist/infra/adapters/http/express-adapter.d.ts +1 -1
- package/dist/infra/adapters/http/express-adapter.js +1 -1
- package/dist/infra/adapters/http/express-adapter.js.map +1 -1
- package/dist/infra/adapters/http/fastify-adapter.cjs +5 -1
- package/dist/infra/adapters/http/fastify-adapter.cjs.map +1 -1
- package/dist/infra/adapters/http/fastify-adapter.d.cts +1 -1
- package/dist/infra/adapters/http/fastify-adapter.d.ts +1 -1
- package/dist/infra/adapters/http/fastify-adapter.js +1 -1
- package/dist/infra/adapters/http/fastify-adapter.js.map +1 -1
- package/dist/infra/adapters/http/validate-controller-metadata.cjs.map +1 -1
- package/dist/infra/adapters/http/validate-controller-metadata.js.map +1 -1
- package/dist/infra/adapters/notifications/notification-factory.cjs +219 -0
- package/dist/infra/adapters/notifications/notification-factory.cjs.map +1 -0
- package/dist/infra/adapters/notifications/notification-factory.d.cts +18 -0
- package/dist/infra/adapters/notifications/notification-factory.d.ts +18 -0
- package/dist/infra/adapters/notifications/notification-factory.js +184 -0
- package/dist/infra/adapters/notifications/notification-factory.js.map +1 -0
- package/dist/infra/adapters/validators/zod/index.cjs.map +1 -1
- package/dist/infra/adapters/validators/zod/index.js.map +1 -1
- package/dist/infra/adapters/validators/zod/zod-validator.cjs.map +1 -1
- package/dist/infra/adapters/validators/zod/zod-validator.js.map +1 -1
- package/dist/infra/env/index.cjs +1 -1
- package/dist/infra/env/index.cjs.map +1 -1
- package/dist/infra/env/index.js +3 -1
- package/dist/infra/env/index.js.map +1 -1
- package/package.json +2 -10
package/dist/index.cjs
CHANGED
|
@@ -448,8 +448,11 @@ __export(src_exports, {
|
|
|
448
448
|
DependencyContainer: () => DependencyContainer,
|
|
449
449
|
DiscordNotifier: () => DiscordNotifier,
|
|
450
450
|
Entity: () => Entity,
|
|
451
|
+
ExpressAdapter: () => ExpressAdapter,
|
|
452
|
+
FastifyAdapter: () => FastifyAdapter,
|
|
451
453
|
Inject: () => Inject,
|
|
452
454
|
NotificationErrorInMemory: () => NotificationErrorInMemory,
|
|
455
|
+
NotificationFactory: () => NotificationFactory,
|
|
453
456
|
SentryNotifier: () => SentryNotifier,
|
|
454
457
|
UniqueEntityId: () => UniqueEntityId,
|
|
455
458
|
ValueObject: () => ValueObject,
|
|
@@ -460,9 +463,6 @@ __export(src_exports, {
|
|
|
460
463
|
});
|
|
461
464
|
module.exports = __toCommonJS(src_exports);
|
|
462
465
|
|
|
463
|
-
// src/core/http/base-controller.ts
|
|
464
|
-
var import_reflect_metadata2 = require("reflect-metadata");
|
|
465
|
-
|
|
466
466
|
// src/core/decorators/dependency-container.ts
|
|
467
467
|
var import_reflect_metadata = require("reflect-metadata");
|
|
468
468
|
var DependencyContainer = class {
|
|
@@ -624,6 +624,7 @@ var ValidationError = class extends Error {
|
|
|
624
624
|
};
|
|
625
625
|
|
|
626
626
|
// src/core/http/base-controller.ts
|
|
627
|
+
var import_reflect_metadata2 = require("reflect-metadata");
|
|
627
628
|
var BaseController = class {
|
|
628
629
|
static {
|
|
629
630
|
__name(this, "BaseController");
|
|
@@ -934,13 +935,164 @@ __name(getTakeAndSkip, "getTakeAndSkip");
|
|
|
934
935
|
var import_cors = __toESM(require("cors"), 1);
|
|
935
936
|
var import_express = __toESM(require("express"), 1);
|
|
936
937
|
|
|
938
|
+
// src/infra/adapters/http/response-error-code.ts
|
|
939
|
+
var ErrorResponseCode = /* @__PURE__ */ function(ErrorResponseCode2) {
|
|
940
|
+
ErrorResponseCode2["NO_CONTENT_BODY"] = "B001";
|
|
941
|
+
ErrorResponseCode2["NO_CONTENT_ERROR"] = "B002";
|
|
942
|
+
return ErrorResponseCode2;
|
|
943
|
+
}({});
|
|
944
|
+
|
|
937
945
|
// src/infra/adapters/http/validate-controller-metadata.ts
|
|
938
946
|
var import_reflect_metadata3 = require("reflect-metadata");
|
|
947
|
+
function validateControllerMetadata(controller) {
|
|
948
|
+
const metadata = Reflect.getMetadata("route", controller.constructor);
|
|
949
|
+
if (!metadata) {
|
|
950
|
+
throw new Error(`Controller ${controller.constructor.name} not have metadata. Need to add decorator.`);
|
|
951
|
+
}
|
|
952
|
+
return {
|
|
953
|
+
metadata
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
__name(validateControllerMetadata, "validateControllerMetadata");
|
|
957
|
+
|
|
958
|
+
// src/infra/adapters/http/express-adapter.ts
|
|
959
|
+
var ExpressAdapter = class {
|
|
960
|
+
static {
|
|
961
|
+
__name(this, "ExpressAdapter");
|
|
962
|
+
}
|
|
963
|
+
env;
|
|
964
|
+
instance;
|
|
965
|
+
server;
|
|
966
|
+
constructor(env) {
|
|
967
|
+
this.env = env;
|
|
968
|
+
this.instance = (0, import_express.default)();
|
|
969
|
+
this.instance.use((0, import_cors.default)());
|
|
970
|
+
this.instance.use(import_express.default.json({
|
|
971
|
+
limit: "10mb"
|
|
972
|
+
}));
|
|
973
|
+
this.instance.use(import_express.default.urlencoded({
|
|
974
|
+
limit: "10mb",
|
|
975
|
+
extended: false
|
|
976
|
+
}));
|
|
977
|
+
this.instance.disable("x-powered-by");
|
|
978
|
+
}
|
|
979
|
+
registerRoute(controllerClass) {
|
|
980
|
+
const { metadata } = validateControllerMetadata(controllerClass);
|
|
981
|
+
this.instance[metadata.method](metadata.path, async (request, response) => {
|
|
982
|
+
const requestData = {
|
|
983
|
+
body: request.body,
|
|
984
|
+
params: request.params,
|
|
985
|
+
headers: request.headers,
|
|
986
|
+
query: request.query
|
|
987
|
+
};
|
|
988
|
+
try {
|
|
989
|
+
const output = await controllerClass.execute(requestData);
|
|
990
|
+
response.status(output.code || 204).json(output.data || {
|
|
991
|
+
code: ErrorResponseCode.NO_CONTENT_BODY
|
|
992
|
+
});
|
|
993
|
+
} catch (err) {
|
|
994
|
+
const error = await controllerClass.failure(err, {
|
|
995
|
+
env: this.env.ENVIRONMENT,
|
|
996
|
+
request: {
|
|
997
|
+
body: requestData.body,
|
|
998
|
+
headers: requestData.headers,
|
|
999
|
+
params: request.params,
|
|
1000
|
+
query: requestData.query,
|
|
1001
|
+
url: metadata.path,
|
|
1002
|
+
method: metadata.method
|
|
1003
|
+
}
|
|
1004
|
+
});
|
|
1005
|
+
response.status(error.code).json(error.data || {
|
|
1006
|
+
error: ErrorResponseCode.NO_CONTENT_ERROR
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
async startServer(port) {
|
|
1012
|
+
return new Promise((resolve) => {
|
|
1013
|
+
this.server = this.instance.listen(port, () => {
|
|
1014
|
+
console.log(`\u{1F680} Server is running on PORT ${port}`);
|
|
1015
|
+
resolve();
|
|
1016
|
+
});
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
async closeServer() {
|
|
1020
|
+
return new Promise((resolve, reject) => {
|
|
1021
|
+
if (this.server) {
|
|
1022
|
+
this.server.close((err) => {
|
|
1023
|
+
if (err)
|
|
1024
|
+
return reject(err);
|
|
1025
|
+
resolve();
|
|
1026
|
+
});
|
|
1027
|
+
} else {
|
|
1028
|
+
resolve();
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
939
1033
|
|
|
940
1034
|
// src/infra/adapters/http/fastify-adapter.ts
|
|
941
1035
|
var import_cors2 = __toESM(require("@fastify/cors"), 1);
|
|
942
1036
|
var import_fastify = __toESM(require("fastify"), 1);
|
|
943
1037
|
var import_qs = __toESM(require("qs"), 1);
|
|
1038
|
+
var FastifyAdapter = class {
|
|
1039
|
+
static {
|
|
1040
|
+
__name(this, "FastifyAdapter");
|
|
1041
|
+
}
|
|
1042
|
+
env;
|
|
1043
|
+
instance;
|
|
1044
|
+
constructor(env) {
|
|
1045
|
+
this.env = env;
|
|
1046
|
+
this.instance = (0, import_fastify.default)({
|
|
1047
|
+
bodyLimit: 10 * 1024 * 1024,
|
|
1048
|
+
querystringParser: (str) => import_qs.default.parse(str)
|
|
1049
|
+
});
|
|
1050
|
+
this.instance.register(import_cors2.default);
|
|
1051
|
+
}
|
|
1052
|
+
registerRoute(controllerClass) {
|
|
1053
|
+
const { metadata } = validateControllerMetadata(controllerClass);
|
|
1054
|
+
this.instance[metadata.method](metadata.path, async (request, reply) => {
|
|
1055
|
+
const requestData = {
|
|
1056
|
+
body: request.body,
|
|
1057
|
+
params: request.params,
|
|
1058
|
+
headers: request.headers,
|
|
1059
|
+
query: request.query
|
|
1060
|
+
};
|
|
1061
|
+
try {
|
|
1062
|
+
const output = await controllerClass.execute(requestData);
|
|
1063
|
+
return reply.status(output.code || 200).send(output.data || {
|
|
1064
|
+
code: ErrorResponseCode.NO_CONTENT_BODY
|
|
1065
|
+
});
|
|
1066
|
+
} catch (err) {
|
|
1067
|
+
const error = await controllerClass.failure(err, {
|
|
1068
|
+
env: this.env.ENVIRONMENT,
|
|
1069
|
+
request: {
|
|
1070
|
+
body: requestData.body,
|
|
1071
|
+
headers: requestData.headers,
|
|
1072
|
+
params: request.params,
|
|
1073
|
+
query: requestData.query,
|
|
1074
|
+
url: metadata.path,
|
|
1075
|
+
method: metadata.method
|
|
1076
|
+
}
|
|
1077
|
+
});
|
|
1078
|
+
return reply.status(error.code || 200).send(error.data || {
|
|
1079
|
+
code: ErrorResponseCode.NO_CONTENT_ERROR
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
async startServer(port) {
|
|
1085
|
+
await this.instance.listen({
|
|
1086
|
+
port
|
|
1087
|
+
});
|
|
1088
|
+
if (this.env.NODE_ENV !== "test") {
|
|
1089
|
+
console.log(`\u{1F680} Server is running on PORT ${port}`);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
async closeServer() {
|
|
1093
|
+
await this.instance.close();
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
944
1096
|
|
|
945
1097
|
// src/infra/adapters/notifications/discord.ts
|
|
946
1098
|
var import_discord_webhook_node = require("discord-webhook-node");
|
|
@@ -1080,6 +1232,34 @@ SentryNotifier = _ts_decorate2([
|
|
|
1080
1232
|
])
|
|
1081
1233
|
], SentryNotifier);
|
|
1082
1234
|
|
|
1235
|
+
// src/infra/adapters/notifications/notification-factory.ts
|
|
1236
|
+
var NotificationFactory = class {
|
|
1237
|
+
static {
|
|
1238
|
+
__name(this, "NotificationFactory");
|
|
1239
|
+
}
|
|
1240
|
+
static define(env, definitions) {
|
|
1241
|
+
const defaultDefinition = {
|
|
1242
|
+
test: this.defineProvider(definitions?.local ?? "console"),
|
|
1243
|
+
development: this.defineProvider(definitions?.local ?? "console"),
|
|
1244
|
+
staging: this.defineProvider(definitions?.local ?? "discord"),
|
|
1245
|
+
production: this.defineProvider(definitions?.local ?? "sentry")
|
|
1246
|
+
};
|
|
1247
|
+
return defaultDefinition[env];
|
|
1248
|
+
}
|
|
1249
|
+
static defineProvider(provider) {
|
|
1250
|
+
switch (provider) {
|
|
1251
|
+
case "console":
|
|
1252
|
+
return NotificationErrorInMemory;
|
|
1253
|
+
case "discord":
|
|
1254
|
+
return DiscordNotifier;
|
|
1255
|
+
case "sentry":
|
|
1256
|
+
return SentryNotifier;
|
|
1257
|
+
default:
|
|
1258
|
+
return NotificationErrorInMemory;
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1083
1263
|
// src/infra/adapters/validators/zod/zod-map-error.ts
|
|
1084
1264
|
var ZodMapError = class {
|
|
1085
1265
|
static {
|
|
@@ -1199,13 +1379,15 @@ function zodValidator(schema) {
|
|
|
1199
1379
|
}
|
|
1200
1380
|
__name(zodValidator, "zodValidator");
|
|
1201
1381
|
|
|
1382
|
+
// src/infra/env/index.ts
|
|
1383
|
+
var import_zod = require("zod");
|
|
1384
|
+
|
|
1202
1385
|
// node_modules/dotenv/config.js
|
|
1203
1386
|
(function() {
|
|
1204
1387
|
require_main().config(Object.assign({}, require_env_options(), require_cli_options()(process.argv)));
|
|
1205
1388
|
})();
|
|
1206
1389
|
|
|
1207
1390
|
// src/infra/env/index.ts
|
|
1208
|
-
var import_zod = require("zod");
|
|
1209
1391
|
var baseEnvSchema = import_zod.z.object({
|
|
1210
1392
|
NODE_ENV: import_zod.z.enum([
|
|
1211
1393
|
"test",
|
|
@@ -1231,8 +1413,11 @@ var baseEnvSchema = import_zod.z.object({
|
|
|
1231
1413
|
DependencyContainer,
|
|
1232
1414
|
DiscordNotifier,
|
|
1233
1415
|
Entity,
|
|
1416
|
+
ExpressAdapter,
|
|
1417
|
+
FastifyAdapter,
|
|
1234
1418
|
Inject,
|
|
1235
1419
|
NotificationErrorInMemory,
|
|
1420
|
+
NotificationFactory,
|
|
1236
1421
|
SentryNotifier,
|
|
1237
1422
|
UniqueEntityId,
|
|
1238
1423
|
ValueObject,
|