elseware-nodejs 1.11.0 → 1.11.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/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/index.cjs +193 -180
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -45
- package/dist/index.d.ts +11 -45
- package/dist/index.js +194 -177
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import dotenv from 'dotenv';
|
|
2
1
|
import mongoose from 'mongoose';
|
|
3
2
|
import { randomUUID } from 'crypto';
|
|
4
3
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
@@ -12,138 +11,6 @@ import juice from 'juice';
|
|
|
12
11
|
import jwt from 'jsonwebtoken';
|
|
13
12
|
import multer from 'multer';
|
|
14
13
|
|
|
15
|
-
// src/configs/env.ts
|
|
16
|
-
|
|
17
|
-
// src/utils/errorToString.ts
|
|
18
|
-
function errorToString(error) {
|
|
19
|
-
if (error instanceof Error) {
|
|
20
|
-
return `${error.name}: ${error.message}
|
|
21
|
-
${error.stack ?? ""}`;
|
|
22
|
-
}
|
|
23
|
-
if (typeof error === "object") {
|
|
24
|
-
try {
|
|
25
|
-
return JSON.stringify(error, null, 2);
|
|
26
|
-
} catch {
|
|
27
|
-
return "[Unserializable object]";
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return String(error);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// src/configs/logger.ts
|
|
34
|
-
var Logger = class {
|
|
35
|
-
timestamp = true;
|
|
36
|
-
enabled = true;
|
|
37
|
-
// Use to configure once at the root
|
|
38
|
-
configure(options = {}) {
|
|
39
|
-
this.timestamp = options.timestamp ?? this.timestamp;
|
|
40
|
-
this.enabled = options.enabled ?? this.enabled;
|
|
41
|
-
}
|
|
42
|
-
format(msg) {
|
|
43
|
-
if (!this.timestamp) return msg;
|
|
44
|
-
return `[${(/* @__PURE__ */ new Date()).toISOString()}] ${msg}`;
|
|
45
|
-
}
|
|
46
|
-
output(msg) {
|
|
47
|
-
if (!this.enabled) return;
|
|
48
|
-
console.log(this.format(msg));
|
|
49
|
-
}
|
|
50
|
-
// Log Levels
|
|
51
|
-
success(msg) {
|
|
52
|
-
this.output(`\u2705 ${msg}`);
|
|
53
|
-
}
|
|
54
|
-
info(msg) {
|
|
55
|
-
this.output(`\u{1F539} ${msg}`);
|
|
56
|
-
}
|
|
57
|
-
warning(msg) {
|
|
58
|
-
this.output(`\u26A0\uFE0F ${msg}`);
|
|
59
|
-
}
|
|
60
|
-
danger(message, error) {
|
|
61
|
-
if (error) {
|
|
62
|
-
this.output(`\u274C ${message}
|
|
63
|
-
${errorToString(error)}`);
|
|
64
|
-
} else {
|
|
65
|
-
this.output(`\u274C ${message}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
log(msg) {
|
|
69
|
-
this.output(`\u2022 ${msg}`);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
var logger = new Logger();
|
|
73
|
-
|
|
74
|
-
// src/configs/env.ts
|
|
75
|
-
dotenv.config({ quiet: true });
|
|
76
|
-
function loadEnv(options) {
|
|
77
|
-
const result = options.schema.safeParse(process.env);
|
|
78
|
-
if (!result.success) {
|
|
79
|
-
handleError(result.error);
|
|
80
|
-
}
|
|
81
|
-
logger.success("Env Configurations validated");
|
|
82
|
-
const env = result.data;
|
|
83
|
-
return options.transform ? options.transform(env) : env;
|
|
84
|
-
}
|
|
85
|
-
function handleError(error) {
|
|
86
|
-
logger.danger("Env validation failed");
|
|
87
|
-
const grouped = {};
|
|
88
|
-
error.issues.forEach((err) => {
|
|
89
|
-
const key = err.path.join(".") || "unknown";
|
|
90
|
-
const rawValue = key !== "unknown" ? process.env[key] : void 0;
|
|
91
|
-
const isSecret = key.toLowerCase().includes("secret");
|
|
92
|
-
const safeValue = isSecret ? "***" : rawValue;
|
|
93
|
-
const message = [
|
|
94
|
-
`message: ${err.message}`,
|
|
95
|
-
`code: ${err.code}`,
|
|
96
|
-
rawValue !== void 0 ? `value: ${JSON.stringify(safeValue)}` : null
|
|
97
|
-
].filter(Boolean).join(" | ");
|
|
98
|
-
if (!grouped[key]) grouped[key] = [];
|
|
99
|
-
grouped[key].push(message);
|
|
100
|
-
});
|
|
101
|
-
Object.entries(grouped).forEach(([key, messages]) => {
|
|
102
|
-
logger.info(key);
|
|
103
|
-
messages.forEach((msg) => logger.log(` - ${msg}`));
|
|
104
|
-
});
|
|
105
|
-
logger.danger("Application startup aborted!");
|
|
106
|
-
process.exit(1);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// src/configs/cors/allowedOrigins.ts
|
|
110
|
-
function createAllowedOrigins(options = {}) {
|
|
111
|
-
const { origins, defaults = ["http://localhost:3000"] } = options;
|
|
112
|
-
let allowedOrigins = [];
|
|
113
|
-
if (typeof origins === "string") {
|
|
114
|
-
allowedOrigins = origins.split(",").map((origin) => origin.trim()).filter(Boolean);
|
|
115
|
-
}
|
|
116
|
-
if (Array.isArray(origins)) {
|
|
117
|
-
allowedOrigins = origins.map((origin) => origin.trim()).filter(Boolean);
|
|
118
|
-
}
|
|
119
|
-
if (allowedOrigins.length === 0) {
|
|
120
|
-
allowedOrigins = [...defaults];
|
|
121
|
-
}
|
|
122
|
-
return allowedOrigins;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// src/configs/cors/corsOptions.ts
|
|
126
|
-
function createCorsOptions(allowedOrigins) {
|
|
127
|
-
return {
|
|
128
|
-
origin(origin, callback) {
|
|
129
|
-
if (!origin || allowedOrigins.includes(origin)) {
|
|
130
|
-
return callback(null, true);
|
|
131
|
-
}
|
|
132
|
-
return callback(new Error(`CORS blocked: ${origin} is not allowed`));
|
|
133
|
-
},
|
|
134
|
-
credentials: true,
|
|
135
|
-
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
|
136
|
-
allowedHeaders: [
|
|
137
|
-
"Content-Type",
|
|
138
|
-
"Authorization",
|
|
139
|
-
"X-Requested-With",
|
|
140
|
-
"Accept"
|
|
141
|
-
],
|
|
142
|
-
exposedHeaders: ["Set-Cookie"],
|
|
143
|
-
optionsSuccessStatus: 204
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
14
|
// src/data-structures/array/CircularArray.ts
|
|
148
15
|
var CircularArray = class {
|
|
149
16
|
capacity;
|
|
@@ -4826,7 +4693,147 @@ var SegmentTree = class {
|
|
|
4826
4693
|
}
|
|
4827
4694
|
};
|
|
4828
4695
|
|
|
4829
|
-
// src/
|
|
4696
|
+
// src/core/constants/defaultOrigins.ts
|
|
4697
|
+
var DEFAULT_ALLOWED_ORIGINS = ["http://localhost:3000"];
|
|
4698
|
+
|
|
4699
|
+
// src/infrastructure/cors/createAllowedOrigins.ts
|
|
4700
|
+
function createAllowedOrigins(options = {}) {
|
|
4701
|
+
const { origins, defaults = DEFAULT_ALLOWED_ORIGINS } = options;
|
|
4702
|
+
let allowedOrigins = [];
|
|
4703
|
+
if (typeof origins === "string") {
|
|
4704
|
+
allowedOrigins = origins.split(",").map((origin) => origin.trim()).filter(Boolean);
|
|
4705
|
+
}
|
|
4706
|
+
if (Array.isArray(origins)) {
|
|
4707
|
+
allowedOrigins = origins.map((origin) => origin.trim()).filter(Boolean);
|
|
4708
|
+
}
|
|
4709
|
+
if (allowedOrigins.length === 0) {
|
|
4710
|
+
allowedOrigins = [...defaults];
|
|
4711
|
+
}
|
|
4712
|
+
return allowedOrigins;
|
|
4713
|
+
}
|
|
4714
|
+
|
|
4715
|
+
// src/infrastructure/cors/createCorsOptions.ts
|
|
4716
|
+
function createCorsOptions(allowedOrigins) {
|
|
4717
|
+
return {
|
|
4718
|
+
origin(origin, callback) {
|
|
4719
|
+
if (!origin || allowedOrigins.includes(origin)) {
|
|
4720
|
+
return callback(null, true);
|
|
4721
|
+
}
|
|
4722
|
+
return callback(new Error(`CORS blocked: ${origin} is not allowed`));
|
|
4723
|
+
},
|
|
4724
|
+
credentials: true,
|
|
4725
|
+
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
|
4726
|
+
allowedHeaders: [
|
|
4727
|
+
"Content-Type",
|
|
4728
|
+
"Authorization",
|
|
4729
|
+
"X-Requested-With",
|
|
4730
|
+
"Accept"
|
|
4731
|
+
],
|
|
4732
|
+
exposedHeaders: ["Set-Cookie"],
|
|
4733
|
+
optionsSuccessStatus: 204
|
|
4734
|
+
};
|
|
4735
|
+
}
|
|
4736
|
+
|
|
4737
|
+
// src/utils/errorToString.ts
|
|
4738
|
+
function errorToString(error) {
|
|
4739
|
+
if (error instanceof Error) {
|
|
4740
|
+
return `${error.name}: ${error.message}
|
|
4741
|
+
${error.stack ?? ""}`;
|
|
4742
|
+
}
|
|
4743
|
+
if (typeof error === "object") {
|
|
4744
|
+
try {
|
|
4745
|
+
return JSON.stringify(error, null, 2);
|
|
4746
|
+
} catch {
|
|
4747
|
+
return "[Unserializable object]";
|
|
4748
|
+
}
|
|
4749
|
+
}
|
|
4750
|
+
return String(error);
|
|
4751
|
+
}
|
|
4752
|
+
|
|
4753
|
+
// src/core/logger/colors.ts
|
|
4754
|
+
var colors = {
|
|
4755
|
+
reset: "\x1B[0m",
|
|
4756
|
+
blue: "\x1B[34m",
|
|
4757
|
+
yellow: "\x1B[33m",
|
|
4758
|
+
red: "\x1B[31m",
|
|
4759
|
+
cyan: "\x1B[36m"
|
|
4760
|
+
};
|
|
4761
|
+
|
|
4762
|
+
// src/core/logger/Logger.ts
|
|
4763
|
+
var Logger = class {
|
|
4764
|
+
enabled = true;
|
|
4765
|
+
timestamp = true;
|
|
4766
|
+
colorsEnabled = true;
|
|
4767
|
+
minimumLevel = "INFO" /* INFO */;
|
|
4768
|
+
configure(options = {}) {
|
|
4769
|
+
this.enabled = options.enabled ?? this.enabled;
|
|
4770
|
+
this.timestamp = options.timestamp ?? this.timestamp;
|
|
4771
|
+
this.colorsEnabled = options.colors ?? this.colorsEnabled;
|
|
4772
|
+
this.minimumLevel = options.level ?? this.minimumLevel;
|
|
4773
|
+
}
|
|
4774
|
+
levelWeight(level) {
|
|
4775
|
+
switch (level) {
|
|
4776
|
+
case "DEBUG" /* DEBUG */:
|
|
4777
|
+
return 10;
|
|
4778
|
+
case "INFO" /* INFO */:
|
|
4779
|
+
return 20;
|
|
4780
|
+
case "WARN" /* WARN */:
|
|
4781
|
+
return 30;
|
|
4782
|
+
case "ERROR" /* ERROR */:
|
|
4783
|
+
return 40;
|
|
4784
|
+
}
|
|
4785
|
+
}
|
|
4786
|
+
shouldLog(level) {
|
|
4787
|
+
return this.levelWeight(level) >= this.levelWeight(this.minimumLevel);
|
|
4788
|
+
}
|
|
4789
|
+
formatLevel(level) {
|
|
4790
|
+
if (!this.colorsEnabled) {
|
|
4791
|
+
return level;
|
|
4792
|
+
}
|
|
4793
|
+
switch (level) {
|
|
4794
|
+
case "DEBUG" /* DEBUG */:
|
|
4795
|
+
return `${colors.cyan}${level}${colors.reset}`;
|
|
4796
|
+
case "INFO" /* INFO */:
|
|
4797
|
+
return `${colors.blue}${level}${colors.reset}`;
|
|
4798
|
+
case "WARN" /* WARN */:
|
|
4799
|
+
return `${colors.yellow}${level}${colors.reset}`;
|
|
4800
|
+
case "ERROR" /* ERROR */:
|
|
4801
|
+
return `${colors.red}${level}${colors.reset}`;
|
|
4802
|
+
}
|
|
4803
|
+
}
|
|
4804
|
+
write(level, message) {
|
|
4805
|
+
if (!this.enabled) {
|
|
4806
|
+
return;
|
|
4807
|
+
}
|
|
4808
|
+
if (!this.shouldLog(level)) {
|
|
4809
|
+
return;
|
|
4810
|
+
}
|
|
4811
|
+
const timestamp = this.timestamp ? `[${(/* @__PURE__ */ new Date()).toISOString()}] ` : "";
|
|
4812
|
+
console.log(`${timestamp}[${this.formatLevel(level)}] ${message}`);
|
|
4813
|
+
}
|
|
4814
|
+
debug(message) {
|
|
4815
|
+
this.write("DEBUG" /* DEBUG */, message);
|
|
4816
|
+
}
|
|
4817
|
+
info(message) {
|
|
4818
|
+
this.write("INFO" /* INFO */, message);
|
|
4819
|
+
}
|
|
4820
|
+
warn(message) {
|
|
4821
|
+
this.write("WARN" /* WARN */, message);
|
|
4822
|
+
}
|
|
4823
|
+
error(message, error) {
|
|
4824
|
+
if (error) {
|
|
4825
|
+
this.write("ERROR" /* ERROR */, `${message}
|
|
4826
|
+
${errorToString(error)}`);
|
|
4827
|
+
return;
|
|
4828
|
+
}
|
|
4829
|
+
this.write("ERROR" /* ERROR */, message);
|
|
4830
|
+
}
|
|
4831
|
+
};
|
|
4832
|
+
|
|
4833
|
+
// src/core/logger/index.ts
|
|
4834
|
+
var logger = new Logger();
|
|
4835
|
+
|
|
4836
|
+
// src/infrastructure/database/DatabaseManager.ts
|
|
4830
4837
|
var DatabaseManager = class {
|
|
4831
4838
|
constructor(provider, options = {
|
|
4832
4839
|
enableShutdownHooks: true
|
|
@@ -4837,21 +4844,21 @@ var DatabaseManager = class {
|
|
|
4837
4844
|
async connect() {
|
|
4838
4845
|
try {
|
|
4839
4846
|
await this.provider.connect();
|
|
4840
|
-
logger.
|
|
4847
|
+
logger.info("Database connected");
|
|
4841
4848
|
if (this.options.enableShutdownHooks) {
|
|
4842
4849
|
this.registerShutdownHooks();
|
|
4843
4850
|
}
|
|
4844
4851
|
} catch (error) {
|
|
4845
|
-
logger.
|
|
4852
|
+
logger.error("Database connection failed", error);
|
|
4846
4853
|
throw error;
|
|
4847
4854
|
}
|
|
4848
4855
|
}
|
|
4849
4856
|
async disconnect() {
|
|
4850
4857
|
try {
|
|
4851
4858
|
await this.provider.disconnect();
|
|
4852
|
-
logger.
|
|
4859
|
+
logger.info("Database disconnected");
|
|
4853
4860
|
} catch (error) {
|
|
4854
|
-
logger.
|
|
4861
|
+
logger.error("Database disconnect failed", error);
|
|
4855
4862
|
throw error;
|
|
4856
4863
|
}
|
|
4857
4864
|
}
|
|
@@ -4863,12 +4870,20 @@ var DatabaseManager = class {
|
|
|
4863
4870
|
}
|
|
4864
4871
|
registerShutdownHooks() {
|
|
4865
4872
|
process.once("SIGINT", async () => {
|
|
4866
|
-
|
|
4867
|
-
|
|
4873
|
+
logger.info("SIGINT received, shutting down database connection");
|
|
4874
|
+
try {
|
|
4875
|
+
await this.disconnect();
|
|
4876
|
+
} finally {
|
|
4877
|
+
process.exit(0);
|
|
4878
|
+
}
|
|
4868
4879
|
});
|
|
4869
4880
|
process.once("SIGTERM", async () => {
|
|
4870
|
-
|
|
4871
|
-
|
|
4881
|
+
logger.info("SIGTERM received, shutting down database connection");
|
|
4882
|
+
try {
|
|
4883
|
+
await this.disconnect();
|
|
4884
|
+
} finally {
|
|
4885
|
+
process.exit(0);
|
|
4886
|
+
}
|
|
4872
4887
|
});
|
|
4873
4888
|
}
|
|
4874
4889
|
};
|
|
@@ -4902,7 +4917,7 @@ var MongoDatabaseProvider = class {
|
|
|
4902
4917
|
}
|
|
4903
4918
|
};
|
|
4904
4919
|
|
|
4905
|
-
// src/errors/
|
|
4920
|
+
// src/core/errors/AppError.ts
|
|
4906
4921
|
var AppError = class extends Error {
|
|
4907
4922
|
statusCode;
|
|
4908
4923
|
status;
|
|
@@ -4912,20 +4927,20 @@ var AppError = class extends Error {
|
|
|
4912
4927
|
constructor(message, statusCode = 500, options) {
|
|
4913
4928
|
super(message);
|
|
4914
4929
|
this.statusCode = statusCode;
|
|
4915
|
-
this.status =
|
|
4916
|
-
this.isOperational = true;
|
|
4930
|
+
this.status = statusCode >= 400 && statusCode < 500 ? "fail" : "error";
|
|
4931
|
+
this.isOperational = options?.isOperational ?? true;
|
|
4917
4932
|
this.code = options?.code;
|
|
4918
4933
|
this.details = options?.details;
|
|
4919
4934
|
Error.captureStackTrace(this, this.constructor);
|
|
4920
4935
|
}
|
|
4921
4936
|
};
|
|
4922
4937
|
|
|
4923
|
-
// src/http/handlers/AsyncHandler.ts
|
|
4938
|
+
// src/infrastructure/http/handlers/AsyncHandler.ts
|
|
4924
4939
|
var AsyncHandler = (fn) => (req, res, next) => {
|
|
4925
4940
|
Promise.resolve(fn(req, res, next)).catch(next);
|
|
4926
4941
|
};
|
|
4927
4942
|
|
|
4928
|
-
// src/http/query/QueryConstants.ts
|
|
4943
|
+
// src/infrastructure/http/query/QueryConstants.ts
|
|
4929
4944
|
var QUERY_RESERVED_FIELDS = [
|
|
4930
4945
|
"page",
|
|
4931
4946
|
"limit",
|
|
@@ -4950,7 +4965,7 @@ var SUPPORTED_OPERATORS = [
|
|
|
4950
4965
|
"endsWith"
|
|
4951
4966
|
];
|
|
4952
4967
|
|
|
4953
|
-
// src/http/query/ApiFeatures.ts
|
|
4968
|
+
// src/infrastructure/http/query/ApiFeatures.ts
|
|
4954
4969
|
var ApiFeatures = class {
|
|
4955
4970
|
static parse(query) {
|
|
4956
4971
|
return {
|
|
@@ -5028,7 +5043,7 @@ var ApiFeatures = class {
|
|
|
5028
5043
|
}
|
|
5029
5044
|
};
|
|
5030
5045
|
|
|
5031
|
-
// src/http/responses/ApiResponse.ts
|
|
5046
|
+
// src/infrastructure/http/responses/ApiResponse.ts
|
|
5032
5047
|
var ApiResponse = class _ApiResponse {
|
|
5033
5048
|
static send(res, options) {
|
|
5034
5049
|
const {
|
|
@@ -5102,7 +5117,7 @@ var ApiResponse = class _ApiResponse {
|
|
|
5102
5117
|
}
|
|
5103
5118
|
};
|
|
5104
5119
|
|
|
5105
|
-
// src/http/controllers/CrudControllerFactory.ts
|
|
5120
|
+
// src/infrastructure/http/controllers/CrudControllerFactory.ts
|
|
5106
5121
|
var CrudControllerFactory = class {
|
|
5107
5122
|
static create(repository, options = {}) {
|
|
5108
5123
|
const resourceName = options.resourceName ?? "Resource";
|
|
@@ -5204,12 +5219,12 @@ var CrudControllerFactory = class {
|
|
|
5204
5219
|
}
|
|
5205
5220
|
};
|
|
5206
5221
|
|
|
5207
|
-
// src/http/middleware/AuthMiddleware.ts
|
|
5222
|
+
// src/infrastructure/http/middleware/AuthMiddleware.ts
|
|
5208
5223
|
var authMiddleware = (_req, _res, next) => {
|
|
5209
5224
|
next();
|
|
5210
5225
|
};
|
|
5211
5226
|
|
|
5212
|
-
// src/http/middleware/ErrorMiddleware.ts
|
|
5227
|
+
// src/infrastructure/http/middleware/ErrorMiddleware.ts
|
|
5213
5228
|
var handleCastError = (err) => new AppError(`Invalid ${err.path}: ${err.value}`, 400, {
|
|
5214
5229
|
code: "INVALID_ID"
|
|
5215
5230
|
});
|
|
@@ -5239,11 +5254,13 @@ var ErrorMiddleware = (isProduction = false) => (err, _req, res, _next) => {
|
|
|
5239
5254
|
if (err instanceof AppError) {
|
|
5240
5255
|
error = err;
|
|
5241
5256
|
} else if (err instanceof Error) {
|
|
5242
|
-
error = new AppError(err.message, 500
|
|
5243
|
-
|
|
5257
|
+
error = new AppError(err.message, 500, {
|
|
5258
|
+
isOperational: false
|
|
5259
|
+
});
|
|
5244
5260
|
} else {
|
|
5245
|
-
error = new AppError("Internal Server Error", 500
|
|
5246
|
-
|
|
5261
|
+
error = new AppError("Internal Server Error", 500, {
|
|
5262
|
+
isOperational: false
|
|
5263
|
+
});
|
|
5247
5264
|
}
|
|
5248
5265
|
if (err && err.name === "CastError") {
|
|
5249
5266
|
error = handleCastError(err);
|
|
@@ -5263,9 +5280,9 @@ var ErrorMiddleware = (isProduction = false) => (err, _req, res, _next) => {
|
|
|
5263
5280
|
error = handleJWTExpiredError();
|
|
5264
5281
|
}
|
|
5265
5282
|
if (!error.isOperational) {
|
|
5266
|
-
logger.
|
|
5283
|
+
logger.error("Programming error", err);
|
|
5267
5284
|
} else {
|
|
5268
|
-
logger.
|
|
5285
|
+
logger.error("Operational error", {
|
|
5269
5286
|
message: error.message
|
|
5270
5287
|
});
|
|
5271
5288
|
}
|
|
@@ -5293,7 +5310,7 @@ var ErrorMiddleware = (isProduction = false) => (err, _req, res, _next) => {
|
|
|
5293
5310
|
});
|
|
5294
5311
|
};
|
|
5295
5312
|
|
|
5296
|
-
// src/http/validation/Validator.ts
|
|
5313
|
+
// src/infrastructure/http/validation/Validator.ts
|
|
5297
5314
|
var isJoiSchema = (schema) => {
|
|
5298
5315
|
return typeof schema === "object" && schema !== null && "validate" in schema;
|
|
5299
5316
|
};
|
|
@@ -5301,7 +5318,7 @@ var isZodSchema = (schema) => {
|
|
|
5301
5318
|
return typeof schema === "object" && schema !== null && "safeParse" in schema;
|
|
5302
5319
|
};
|
|
5303
5320
|
|
|
5304
|
-
// src/http/validation/JoiValidator.ts
|
|
5321
|
+
// src/infrastructure/http/validation/JoiValidator.ts
|
|
5305
5322
|
var JoiValidator = class {
|
|
5306
5323
|
constructor(schema) {
|
|
5307
5324
|
this.schema = schema;
|
|
@@ -5329,7 +5346,7 @@ var JoiValidator = class {
|
|
|
5329
5346
|
}
|
|
5330
5347
|
};
|
|
5331
5348
|
|
|
5332
|
-
// src/http/validation/ZodValidator.ts
|
|
5349
|
+
// src/infrastructure/http/validation/ZodValidator.ts
|
|
5333
5350
|
var ZodValidator = class {
|
|
5334
5351
|
constructor(schema) {
|
|
5335
5352
|
this.schema = schema;
|
|
@@ -5354,7 +5371,7 @@ var ZodValidator = class {
|
|
|
5354
5371
|
}
|
|
5355
5372
|
};
|
|
5356
5373
|
|
|
5357
|
-
// src/http/middleware/ValidationMiddleware.ts
|
|
5374
|
+
// src/infrastructure/http/middleware/ValidationMiddleware.ts
|
|
5358
5375
|
var validate = (schema) => (req, _res, next) => {
|
|
5359
5376
|
let result;
|
|
5360
5377
|
if (isJoiSchema(schema)) {
|
|
@@ -5376,7 +5393,7 @@ var validate = (schema) => (req, _res, next) => {
|
|
|
5376
5393
|
next();
|
|
5377
5394
|
};
|
|
5378
5395
|
|
|
5379
|
-
// src/http/utils/PickFields.ts
|
|
5396
|
+
// src/infrastructure/http/utils/PickFields.ts
|
|
5380
5397
|
function pickFields(obj, fields, options = {}) {
|
|
5381
5398
|
const removeUndefined = options.removeUndefined ?? false;
|
|
5382
5399
|
const removeNull = options.removeNull ?? false;
|
|
@@ -5438,7 +5455,7 @@ var RequestContext = class {
|
|
|
5438
5455
|
}
|
|
5439
5456
|
};
|
|
5440
5457
|
|
|
5441
|
-
// src/networking/middleware/RequestContextMiddleware.ts
|
|
5458
|
+
// src/infrastructure/networking/middleware/RequestContextMiddleware.ts
|
|
5442
5459
|
function createRequestContextMiddleware(options = {}) {
|
|
5443
5460
|
const {
|
|
5444
5461
|
correlationHeaderName = "X-Correlation-Id",
|
|
@@ -5458,7 +5475,7 @@ function createRequestContextMiddleware(options = {}) {
|
|
|
5458
5475
|
};
|
|
5459
5476
|
}
|
|
5460
5477
|
|
|
5461
|
-
// src/networking/observability/TracingHeaders.ts
|
|
5478
|
+
// src/infrastructure/networking/observability/TracingHeaders.ts
|
|
5462
5479
|
var TracingHeaders = class {
|
|
5463
5480
|
static build() {
|
|
5464
5481
|
const headers = {};
|
|
@@ -5482,7 +5499,7 @@ var TracingHeaders = class {
|
|
|
5482
5499
|
}
|
|
5483
5500
|
};
|
|
5484
5501
|
|
|
5485
|
-
// src/networking/resilience/ExponentialBackoffRetryPolicy.ts
|
|
5502
|
+
// src/infrastructure/networking/resilience/ExponentialBackoffRetryPolicy.ts
|
|
5486
5503
|
var ExponentialBackoffRetryPolicy = class {
|
|
5487
5504
|
retries;
|
|
5488
5505
|
baseDelay;
|
|
@@ -5501,7 +5518,7 @@ var ExponentialBackoffRetryPolicy = class {
|
|
|
5501
5518
|
}
|
|
5502
5519
|
};
|
|
5503
5520
|
|
|
5504
|
-
// src/networking/resilience/FixedRetryPolicy.ts
|
|
5521
|
+
// src/infrastructure/networking/resilience/FixedRetryPolicy.ts
|
|
5505
5522
|
var FixedRetryPolicy = class {
|
|
5506
5523
|
retries;
|
|
5507
5524
|
delay;
|
|
@@ -5517,7 +5534,7 @@ var FixedRetryPolicy = class {
|
|
|
5517
5534
|
}
|
|
5518
5535
|
};
|
|
5519
5536
|
|
|
5520
|
-
// src/networking/security/BearerTokenStrategy.ts
|
|
5537
|
+
// src/infrastructure/networking/security/BearerTokenStrategy.ts
|
|
5521
5538
|
var BearerTokenStrategy = class {
|
|
5522
5539
|
constructor(tokenProvider) {
|
|
5523
5540
|
this.tokenProvider = tokenProvider;
|
|
@@ -5530,7 +5547,7 @@ var BearerTokenStrategy = class {
|
|
|
5530
5547
|
}
|
|
5531
5548
|
};
|
|
5532
5549
|
|
|
5533
|
-
// src/networking/security/StaticTokenProvider.ts
|
|
5550
|
+
// src/infrastructure/networking/security/StaticTokenProvider.ts
|
|
5534
5551
|
var StaticTokenProvider = class {
|
|
5535
5552
|
constructor(token) {
|
|
5536
5553
|
this.token = token;
|
|
@@ -5540,7 +5557,7 @@ var StaticTokenProvider = class {
|
|
|
5540
5557
|
}
|
|
5541
5558
|
};
|
|
5542
5559
|
|
|
5543
|
-
// src/networking/transport/HttpClient.ts
|
|
5560
|
+
// src/infrastructure/networking/transport/HttpClient.ts
|
|
5544
5561
|
var HttpClient = class {
|
|
5545
5562
|
baseUrl;
|
|
5546
5563
|
timeout;
|
|
@@ -5618,7 +5635,7 @@ var HttpClient = class {
|
|
|
5618
5635
|
lastError = error;
|
|
5619
5636
|
if (this.retryPolicy.shouldRetry(attempt, error)) {
|
|
5620
5637
|
const delay = this.retryPolicy.getDelay(attempt, error);
|
|
5621
|
-
logger.
|
|
5638
|
+
logger.warn(
|
|
5622
5639
|
`[${this.serviceName}] retry ${attempt + 1} after ${delay}ms`
|
|
5623
5640
|
);
|
|
5624
5641
|
await this.sleep(delay);
|
|
@@ -5629,7 +5646,7 @@ var HttpClient = class {
|
|
|
5629
5646
|
}
|
|
5630
5647
|
}
|
|
5631
5648
|
const correlationId = RequestContext.getCorrelationId();
|
|
5632
|
-
logger.
|
|
5649
|
+
logger.error(
|
|
5633
5650
|
`[${this.serviceName}]` + (correlationId ? ` [${correlationId}]` : "") + ` request failed`,
|
|
5634
5651
|
lastError
|
|
5635
5652
|
);
|
|
@@ -5640,7 +5657,7 @@ var HttpClient = class {
|
|
|
5640
5657
|
}
|
|
5641
5658
|
};
|
|
5642
5659
|
|
|
5643
|
-
// src/networking/services/ServiceClient.ts
|
|
5660
|
+
// src/infrastructure/networking/services/ServiceClient.ts
|
|
5644
5661
|
var ServiceClient = class extends HttpClient {
|
|
5645
5662
|
async getData(path2) {
|
|
5646
5663
|
const response = await super.get(path2);
|
|
@@ -5664,7 +5681,7 @@ var ServiceClient = class extends HttpClient {
|
|
|
5664
5681
|
}
|
|
5665
5682
|
};
|
|
5666
5683
|
|
|
5667
|
-
// src/networking/services/InternalServiceClient.ts
|
|
5684
|
+
// src/infrastructure/networking/services/InternalServiceClient.ts
|
|
5668
5685
|
var InternalServiceClient = class extends ServiceClient {
|
|
5669
5686
|
constructor(baseUrl, serviceToken, serviceName) {
|
|
5670
5687
|
super(baseUrl, {
|
|
@@ -6103,7 +6120,7 @@ var JWTService = class {
|
|
|
6103
6120
|
try {
|
|
6104
6121
|
return jwt.verify(token, this.accessSecret);
|
|
6105
6122
|
} catch (err) {
|
|
6106
|
-
logger.
|
|
6123
|
+
logger.error("Access token verification failed:", err.message);
|
|
6107
6124
|
return null;
|
|
6108
6125
|
}
|
|
6109
6126
|
}
|
|
@@ -6111,7 +6128,7 @@ var JWTService = class {
|
|
|
6111
6128
|
try {
|
|
6112
6129
|
return jwt.verify(token, this.refreshSecret);
|
|
6113
6130
|
} catch (err) {
|
|
6114
|
-
logger.
|
|
6131
|
+
logger.error("Refresh token verification failed:", err.message);
|
|
6115
6132
|
return null;
|
|
6116
6133
|
}
|
|
6117
6134
|
}
|
|
@@ -6268,6 +6285,6 @@ function sleep(ms) {
|
|
|
6268
6285
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
6269
6286
|
}
|
|
6270
6287
|
|
|
6271
|
-
export { AVLTree, AdjacencyList, AdjacencyMatrix, ApiFeatures, ApiResponse,
|
|
6288
|
+
export { AVLTree, AdjacencyList, AdjacencyMatrix, ApiFeatures, ApiResponse, AsyncHandler, AzureBlobStorageService, BPlusTree, BTree, BearerTokenStrategy, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, CloudinaryService, ConsistentHash, CorrelationId, CountMinSketch, CrudControllerFactory, DEFAULT_LIMIT, DEFAULT_PAGE, DEFAULT_SORT_DIRECTION, DatabaseManager, Deque, DirectedGraph, DisjointSetUnion, DoublyLinkedList, DynamicArray, EmailService, ErrorMiddleware, ExponentialBackoffRetryPolicy, FenwickTree, FibNode, FibonacciHeap, FixedRetryPolicy, Graph, HashMap, HashSet, HttpClient, HyperLogLog, InternalServiceClient, IntervalTree, JWTService, JoiValidator, KDTree, LFUCache, LRUCache, MaxHeap, MaxStack, MinHeap, MinStack, MongoDatabaseProvider, MongoRepository, MulterFileHandlerService, MultiSet, Node, OrderedSet, PairingHeap, PairingNode, PriorityQueue, QUERY_RESERVED_FIELDS, QuadTree, Queue, RadixTree, RedBlackTree, RequestContext, SMTPProvider, SUPPORTED_OPERATORS, SegmentTree, ServiceClient, Set2 as Set, SinglyLinkedList, SparseTable, SplayTree, Stack, StaticArray, StaticTokenProvider, SuffixArray, SuffixTree, TemplateEngine, TernarySearchTree, TracingHeaders, TreeNode, Trie, ZodValidator, authMiddleware, createAllowedOrigins, createCorsOptions, createRequestContextMiddleware, days, errorToString, hours, isJoiSchema, isZodSchema, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
|
|
6272
6289
|
//# sourceMappingURL=index.js.map
|
|
6273
6290
|
//# sourceMappingURL=index.js.map
|