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.js
CHANGED
|
@@ -420,9 +420,6 @@ var require_cli_options = __commonJS({
|
|
|
420
420
|
}
|
|
421
421
|
});
|
|
422
422
|
|
|
423
|
-
// src/core/http/base-controller.ts
|
|
424
|
-
import "reflect-metadata";
|
|
425
|
-
|
|
426
423
|
// src/core/decorators/dependency-container.ts
|
|
427
424
|
import "reflect-metadata";
|
|
428
425
|
var DependencyContainer = class {
|
|
@@ -584,6 +581,7 @@ var ValidationError = class extends Error {
|
|
|
584
581
|
};
|
|
585
582
|
|
|
586
583
|
// src/core/http/base-controller.ts
|
|
584
|
+
import "reflect-metadata";
|
|
587
585
|
var BaseController = class {
|
|
588
586
|
static {
|
|
589
587
|
__name(this, "BaseController");
|
|
@@ -894,13 +892,164 @@ __name(getTakeAndSkip, "getTakeAndSkip");
|
|
|
894
892
|
import cors from "cors";
|
|
895
893
|
import express from "express";
|
|
896
894
|
|
|
895
|
+
// src/infra/adapters/http/response-error-code.ts
|
|
896
|
+
var ErrorResponseCode = /* @__PURE__ */ function(ErrorResponseCode2) {
|
|
897
|
+
ErrorResponseCode2["NO_CONTENT_BODY"] = "B001";
|
|
898
|
+
ErrorResponseCode2["NO_CONTENT_ERROR"] = "B002";
|
|
899
|
+
return ErrorResponseCode2;
|
|
900
|
+
}({});
|
|
901
|
+
|
|
897
902
|
// src/infra/adapters/http/validate-controller-metadata.ts
|
|
898
903
|
import "reflect-metadata";
|
|
904
|
+
function validateControllerMetadata(controller) {
|
|
905
|
+
const metadata = Reflect.getMetadata("route", controller.constructor);
|
|
906
|
+
if (!metadata) {
|
|
907
|
+
throw new Error(`Controller ${controller.constructor.name} not have metadata. Need to add decorator.`);
|
|
908
|
+
}
|
|
909
|
+
return {
|
|
910
|
+
metadata
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
__name(validateControllerMetadata, "validateControllerMetadata");
|
|
914
|
+
|
|
915
|
+
// src/infra/adapters/http/express-adapter.ts
|
|
916
|
+
var ExpressAdapter = class {
|
|
917
|
+
static {
|
|
918
|
+
__name(this, "ExpressAdapter");
|
|
919
|
+
}
|
|
920
|
+
env;
|
|
921
|
+
instance;
|
|
922
|
+
server;
|
|
923
|
+
constructor(env) {
|
|
924
|
+
this.env = env;
|
|
925
|
+
this.instance = express();
|
|
926
|
+
this.instance.use(cors());
|
|
927
|
+
this.instance.use(express.json({
|
|
928
|
+
limit: "10mb"
|
|
929
|
+
}));
|
|
930
|
+
this.instance.use(express.urlencoded({
|
|
931
|
+
limit: "10mb",
|
|
932
|
+
extended: false
|
|
933
|
+
}));
|
|
934
|
+
this.instance.disable("x-powered-by");
|
|
935
|
+
}
|
|
936
|
+
registerRoute(controllerClass) {
|
|
937
|
+
const { metadata } = validateControllerMetadata(controllerClass);
|
|
938
|
+
this.instance[metadata.method](metadata.path, async (request, response) => {
|
|
939
|
+
const requestData = {
|
|
940
|
+
body: request.body,
|
|
941
|
+
params: request.params,
|
|
942
|
+
headers: request.headers,
|
|
943
|
+
query: request.query
|
|
944
|
+
};
|
|
945
|
+
try {
|
|
946
|
+
const output = await controllerClass.execute(requestData);
|
|
947
|
+
response.status(output.code || 204).json(output.data || {
|
|
948
|
+
code: ErrorResponseCode.NO_CONTENT_BODY
|
|
949
|
+
});
|
|
950
|
+
} catch (err) {
|
|
951
|
+
const error = await controllerClass.failure(err, {
|
|
952
|
+
env: this.env.ENVIRONMENT,
|
|
953
|
+
request: {
|
|
954
|
+
body: requestData.body,
|
|
955
|
+
headers: requestData.headers,
|
|
956
|
+
params: request.params,
|
|
957
|
+
query: requestData.query,
|
|
958
|
+
url: metadata.path,
|
|
959
|
+
method: metadata.method
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
response.status(error.code).json(error.data || {
|
|
963
|
+
error: ErrorResponseCode.NO_CONTENT_ERROR
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
async startServer(port) {
|
|
969
|
+
return new Promise((resolve) => {
|
|
970
|
+
this.server = this.instance.listen(port, () => {
|
|
971
|
+
console.log(`\u{1F680} Server is running on PORT ${port}`);
|
|
972
|
+
resolve();
|
|
973
|
+
});
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
async closeServer() {
|
|
977
|
+
return new Promise((resolve, reject) => {
|
|
978
|
+
if (this.server) {
|
|
979
|
+
this.server.close((err) => {
|
|
980
|
+
if (err)
|
|
981
|
+
return reject(err);
|
|
982
|
+
resolve();
|
|
983
|
+
});
|
|
984
|
+
} else {
|
|
985
|
+
resolve();
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
};
|
|
899
990
|
|
|
900
991
|
// src/infra/adapters/http/fastify-adapter.ts
|
|
901
992
|
import cors2 from "@fastify/cors";
|
|
902
993
|
import fastify from "fastify";
|
|
903
994
|
import qs from "qs";
|
|
995
|
+
var FastifyAdapter = class {
|
|
996
|
+
static {
|
|
997
|
+
__name(this, "FastifyAdapter");
|
|
998
|
+
}
|
|
999
|
+
env;
|
|
1000
|
+
instance;
|
|
1001
|
+
constructor(env) {
|
|
1002
|
+
this.env = env;
|
|
1003
|
+
this.instance = fastify({
|
|
1004
|
+
bodyLimit: 10 * 1024 * 1024,
|
|
1005
|
+
querystringParser: (str) => qs.parse(str)
|
|
1006
|
+
});
|
|
1007
|
+
this.instance.register(cors2);
|
|
1008
|
+
}
|
|
1009
|
+
registerRoute(controllerClass) {
|
|
1010
|
+
const { metadata } = validateControllerMetadata(controllerClass);
|
|
1011
|
+
this.instance[metadata.method](metadata.path, async (request, reply) => {
|
|
1012
|
+
const requestData = {
|
|
1013
|
+
body: request.body,
|
|
1014
|
+
params: request.params,
|
|
1015
|
+
headers: request.headers,
|
|
1016
|
+
query: request.query
|
|
1017
|
+
};
|
|
1018
|
+
try {
|
|
1019
|
+
const output = await controllerClass.execute(requestData);
|
|
1020
|
+
return reply.status(output.code || 200).send(output.data || {
|
|
1021
|
+
code: ErrorResponseCode.NO_CONTENT_BODY
|
|
1022
|
+
});
|
|
1023
|
+
} catch (err) {
|
|
1024
|
+
const error = await controllerClass.failure(err, {
|
|
1025
|
+
env: this.env.ENVIRONMENT,
|
|
1026
|
+
request: {
|
|
1027
|
+
body: requestData.body,
|
|
1028
|
+
headers: requestData.headers,
|
|
1029
|
+
params: request.params,
|
|
1030
|
+
query: requestData.query,
|
|
1031
|
+
url: metadata.path,
|
|
1032
|
+
method: metadata.method
|
|
1033
|
+
}
|
|
1034
|
+
});
|
|
1035
|
+
return reply.status(error.code || 200).send(error.data || {
|
|
1036
|
+
code: ErrorResponseCode.NO_CONTENT_ERROR
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
async startServer(port) {
|
|
1042
|
+
await this.instance.listen({
|
|
1043
|
+
port
|
|
1044
|
+
});
|
|
1045
|
+
if (this.env.NODE_ENV !== "test") {
|
|
1046
|
+
console.log(`\u{1F680} Server is running on PORT ${port}`);
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
async closeServer() {
|
|
1050
|
+
await this.instance.close();
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
904
1053
|
|
|
905
1054
|
// src/infra/adapters/notifications/discord.ts
|
|
906
1055
|
import { MessageBuilder, Webhook } from "discord-webhook-node";
|
|
@@ -1040,6 +1189,34 @@ SentryNotifier = _ts_decorate2([
|
|
|
1040
1189
|
])
|
|
1041
1190
|
], SentryNotifier);
|
|
1042
1191
|
|
|
1192
|
+
// src/infra/adapters/notifications/notification-factory.ts
|
|
1193
|
+
var NotificationFactory = class {
|
|
1194
|
+
static {
|
|
1195
|
+
__name(this, "NotificationFactory");
|
|
1196
|
+
}
|
|
1197
|
+
static define(env, definitions) {
|
|
1198
|
+
const defaultDefinition = {
|
|
1199
|
+
test: this.defineProvider(definitions?.local ?? "console"),
|
|
1200
|
+
development: this.defineProvider(definitions?.local ?? "console"),
|
|
1201
|
+
staging: this.defineProvider(definitions?.local ?? "discord"),
|
|
1202
|
+
production: this.defineProvider(definitions?.local ?? "sentry")
|
|
1203
|
+
};
|
|
1204
|
+
return defaultDefinition[env];
|
|
1205
|
+
}
|
|
1206
|
+
static defineProvider(provider) {
|
|
1207
|
+
switch (provider) {
|
|
1208
|
+
case "console":
|
|
1209
|
+
return NotificationErrorInMemory;
|
|
1210
|
+
case "discord":
|
|
1211
|
+
return DiscordNotifier;
|
|
1212
|
+
case "sentry":
|
|
1213
|
+
return SentryNotifier;
|
|
1214
|
+
default:
|
|
1215
|
+
return NotificationErrorInMemory;
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
|
|
1043
1220
|
// src/infra/adapters/validators/zod/zod-map-error.ts
|
|
1044
1221
|
var ZodMapError = class {
|
|
1045
1222
|
static {
|
|
@@ -1159,13 +1336,15 @@ function zodValidator(schema) {
|
|
|
1159
1336
|
}
|
|
1160
1337
|
__name(zodValidator, "zodValidator");
|
|
1161
1338
|
|
|
1339
|
+
// src/infra/env/index.ts
|
|
1340
|
+
import { z } from "zod";
|
|
1341
|
+
|
|
1162
1342
|
// node_modules/dotenv/config.js
|
|
1163
1343
|
(function() {
|
|
1164
1344
|
require_main().config(Object.assign({}, require_env_options(), require_cli_options()(process.argv)));
|
|
1165
1345
|
})();
|
|
1166
1346
|
|
|
1167
1347
|
// src/infra/env/index.ts
|
|
1168
|
-
import { z } from "zod";
|
|
1169
1348
|
var baseEnvSchema = z.object({
|
|
1170
1349
|
NODE_ENV: z.enum([
|
|
1171
1350
|
"test",
|
|
@@ -1190,8 +1369,11 @@ export {
|
|
|
1190
1369
|
DependencyContainer,
|
|
1191
1370
|
DiscordNotifier,
|
|
1192
1371
|
Entity,
|
|
1372
|
+
ExpressAdapter,
|
|
1373
|
+
FastifyAdapter,
|
|
1193
1374
|
Inject,
|
|
1194
1375
|
NotificationErrorInMemory,
|
|
1376
|
+
NotificationFactory,
|
|
1195
1377
|
SentryNotifier,
|
|
1196
1378
|
UniqueEntityId,
|
|
1197
1379
|
ValueObject,
|