elseware-nodejs 1.11.0 → 1.11.2
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 +192 -138
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +53 -32
- package/dist/index.d.ts +53 -32
- package/dist/index.js +191 -139
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -12,7 +12,8 @@ import juice from 'juice';
|
|
|
12
12
|
import jwt from 'jsonwebtoken';
|
|
13
13
|
import multer from 'multer';
|
|
14
14
|
|
|
15
|
-
// src/
|
|
15
|
+
// src/core/constants/defaultOrigins.ts
|
|
16
|
+
var DEFAULT_ALLOWED_ORIGINS = ["http://localhost:3000"];
|
|
16
17
|
|
|
17
18
|
// src/utils/errorToString.ts
|
|
18
19
|
function errorToString(error) {
|
|
@@ -30,119 +31,140 @@ ${error.stack ?? ""}`;
|
|
|
30
31
|
return String(error);
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
// src/
|
|
34
|
+
// src/core/logger/colors.ts
|
|
35
|
+
var colors = {
|
|
36
|
+
reset: "\x1B[0m",
|
|
37
|
+
blue: "\x1B[34m",
|
|
38
|
+
yellow: "\x1B[33m",
|
|
39
|
+
red: "\x1B[31m",
|
|
40
|
+
cyan: "\x1B[36m"
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/core/logger/Logger.ts
|
|
34
44
|
var Logger = class {
|
|
35
|
-
timestamp = true;
|
|
36
45
|
enabled = true;
|
|
37
|
-
|
|
46
|
+
timestamp = true;
|
|
47
|
+
colorsEnabled = true;
|
|
48
|
+
minimumLevel = "INFO" /* INFO */;
|
|
38
49
|
configure(options = {}) {
|
|
39
|
-
this.timestamp = options.timestamp ?? this.timestamp;
|
|
40
50
|
this.enabled = options.enabled ?? this.enabled;
|
|
51
|
+
this.timestamp = options.timestamp ?? this.timestamp;
|
|
52
|
+
this.colorsEnabled = options.colors ?? this.colorsEnabled;
|
|
53
|
+
this.minimumLevel = options.level ?? this.minimumLevel;
|
|
54
|
+
}
|
|
55
|
+
levelWeight(level) {
|
|
56
|
+
switch (level) {
|
|
57
|
+
case "DEBUG" /* DEBUG */:
|
|
58
|
+
return 10;
|
|
59
|
+
case "INFO" /* INFO */:
|
|
60
|
+
return 20;
|
|
61
|
+
case "WARN" /* WARN */:
|
|
62
|
+
return 30;
|
|
63
|
+
case "ERROR" /* ERROR */:
|
|
64
|
+
return 40;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
shouldLog(level) {
|
|
68
|
+
return this.levelWeight(level) >= this.levelWeight(this.minimumLevel);
|
|
69
|
+
}
|
|
70
|
+
formatLevel(level) {
|
|
71
|
+
if (!this.colorsEnabled) {
|
|
72
|
+
return level;
|
|
73
|
+
}
|
|
74
|
+
switch (level) {
|
|
75
|
+
case "DEBUG" /* DEBUG */:
|
|
76
|
+
return `${colors.cyan}${level}${colors.reset}`;
|
|
77
|
+
case "INFO" /* INFO */:
|
|
78
|
+
return `${colors.blue}${level}${colors.reset}`;
|
|
79
|
+
case "WARN" /* WARN */:
|
|
80
|
+
return `${colors.yellow}${level}${colors.reset}`;
|
|
81
|
+
case "ERROR" /* ERROR */:
|
|
82
|
+
return `${colors.red}${level}${colors.reset}`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
write(level, message) {
|
|
86
|
+
if (!this.enabled) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!this.shouldLog(level)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const timestamp = this.timestamp ? `[${(/* @__PURE__ */ new Date()).toISOString()}] ` : "";
|
|
93
|
+
console.log(`${timestamp}[${this.formatLevel(level)}] ${message}`);
|
|
41
94
|
}
|
|
42
|
-
|
|
43
|
-
|
|
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}`);
|
|
95
|
+
debug(message) {
|
|
96
|
+
this.write("DEBUG" /* DEBUG */, message);
|
|
53
97
|
}
|
|
54
|
-
info(
|
|
55
|
-
this.
|
|
98
|
+
info(message) {
|
|
99
|
+
this.write("INFO" /* INFO */, message);
|
|
56
100
|
}
|
|
57
|
-
|
|
58
|
-
this.
|
|
101
|
+
warn(message) {
|
|
102
|
+
this.write("WARN" /* WARN */, message);
|
|
59
103
|
}
|
|
60
|
-
|
|
104
|
+
error(message, error) {
|
|
61
105
|
if (error) {
|
|
62
|
-
this.
|
|
106
|
+
this.write("ERROR" /* ERROR */, `${message}
|
|
63
107
|
${errorToString(error)}`);
|
|
64
|
-
|
|
65
|
-
this.output(`\u274C ${message}`);
|
|
108
|
+
return;
|
|
66
109
|
}
|
|
67
|
-
|
|
68
|
-
log(msg) {
|
|
69
|
-
this.output(`\u2022 ${msg}`);
|
|
110
|
+
this.write("ERROR" /* ERROR */, message);
|
|
70
111
|
}
|
|
71
112
|
};
|
|
113
|
+
|
|
114
|
+
// src/core/logger/index.ts
|
|
72
115
|
var logger = new Logger();
|
|
73
116
|
|
|
74
|
-
// src/
|
|
117
|
+
// src/core/environment/loadEnv.ts
|
|
75
118
|
dotenv.config({ quiet: true });
|
|
76
119
|
function loadEnv(options) {
|
|
77
120
|
const result = options.schema.safeParse(process.env);
|
|
78
121
|
if (!result.success) {
|
|
79
|
-
|
|
122
|
+
handleValidationError(result.error);
|
|
80
123
|
}
|
|
81
|
-
logger.
|
|
124
|
+
logger.info("Environment variables validated");
|
|
82
125
|
const env = result.data;
|
|
83
126
|
return options.transform ? options.transform(env) : env;
|
|
84
127
|
}
|
|
85
|
-
function
|
|
86
|
-
logger.
|
|
128
|
+
function handleValidationError(error) {
|
|
129
|
+
logger.error("Environment validation failed");
|
|
87
130
|
const grouped = {};
|
|
88
|
-
error.issues.forEach((
|
|
89
|
-
const key =
|
|
131
|
+
error.issues.forEach((issue) => {
|
|
132
|
+
const key = issue.path.join(".") || "unknown";
|
|
90
133
|
const rawValue = key !== "unknown" ? process.env[key] : void 0;
|
|
91
|
-
const
|
|
92
|
-
const safeValue = isSecret ? "***" : rawValue;
|
|
134
|
+
const safeValue = key.toLowerCase().includes("secret") ? "***" : rawValue;
|
|
93
135
|
const message = [
|
|
94
|
-
`message: ${
|
|
95
|
-
`code: ${
|
|
136
|
+
`message: ${issue.message}`,
|
|
137
|
+
`code: ${issue.code}`,
|
|
96
138
|
rawValue !== void 0 ? `value: ${JSON.stringify(safeValue)}` : null
|
|
97
139
|
].filter(Boolean).join(" | ");
|
|
98
|
-
|
|
140
|
+
grouped[key] ??= [];
|
|
99
141
|
grouped[key].push(message);
|
|
100
142
|
});
|
|
101
143
|
Object.entries(grouped).forEach(([key, messages]) => {
|
|
102
|
-
logger.
|
|
103
|
-
messages.forEach((
|
|
144
|
+
logger.error(`ENV: ${key}`);
|
|
145
|
+
messages.forEach((message) => logger.error(` - ${message}`));
|
|
104
146
|
});
|
|
105
|
-
logger.
|
|
147
|
+
logger.error("Application startup aborted");
|
|
106
148
|
process.exit(1);
|
|
107
149
|
}
|
|
108
150
|
|
|
109
|
-
// src/
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
151
|
+
// src/core/errors/AppError.ts
|
|
152
|
+
var AppError = class extends Error {
|
|
153
|
+
statusCode;
|
|
154
|
+
status;
|
|
155
|
+
isOperational;
|
|
156
|
+
code;
|
|
157
|
+
details;
|
|
158
|
+
constructor(message, statusCode = 500, options) {
|
|
159
|
+
super(message);
|
|
160
|
+
this.statusCode = statusCode;
|
|
161
|
+
this.status = statusCode >= 400 && statusCode < 500 ? "fail" : "error";
|
|
162
|
+
this.isOperational = options?.isOperational ?? true;
|
|
163
|
+
this.code = options?.code;
|
|
164
|
+
this.details = options?.details;
|
|
165
|
+
Error.captureStackTrace(this, this.constructor);
|
|
121
166
|
}
|
|
122
|
-
|
|
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
|
-
}
|
|
167
|
+
};
|
|
146
168
|
|
|
147
169
|
// src/data-structures/array/CircularArray.ts
|
|
148
170
|
var CircularArray = class {
|
|
@@ -4826,7 +4848,45 @@ var SegmentTree = class {
|
|
|
4826
4848
|
}
|
|
4827
4849
|
};
|
|
4828
4850
|
|
|
4829
|
-
// src/
|
|
4851
|
+
// src/infrastructure/cors/createAllowedOrigins.ts
|
|
4852
|
+
function createAllowedOrigins(options = {}) {
|
|
4853
|
+
const { origins, defaults = DEFAULT_ALLOWED_ORIGINS } = options;
|
|
4854
|
+
let allowedOrigins = [];
|
|
4855
|
+
if (typeof origins === "string") {
|
|
4856
|
+
allowedOrigins = origins.split(",").map((origin) => origin.trim()).filter(Boolean);
|
|
4857
|
+
}
|
|
4858
|
+
if (Array.isArray(origins)) {
|
|
4859
|
+
allowedOrigins = origins.map((origin) => origin.trim()).filter(Boolean);
|
|
4860
|
+
}
|
|
4861
|
+
if (allowedOrigins.length === 0) {
|
|
4862
|
+
allowedOrigins = [...defaults];
|
|
4863
|
+
}
|
|
4864
|
+
return allowedOrigins;
|
|
4865
|
+
}
|
|
4866
|
+
|
|
4867
|
+
// src/infrastructure/cors/createCorsOptions.ts
|
|
4868
|
+
function createCorsOptions(allowedOrigins) {
|
|
4869
|
+
return {
|
|
4870
|
+
origin(origin, callback) {
|
|
4871
|
+
if (!origin || allowedOrigins.includes(origin)) {
|
|
4872
|
+
return callback(null, true);
|
|
4873
|
+
}
|
|
4874
|
+
return callback(new Error(`CORS blocked: ${origin} is not allowed`));
|
|
4875
|
+
},
|
|
4876
|
+
credentials: true,
|
|
4877
|
+
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
|
4878
|
+
allowedHeaders: [
|
|
4879
|
+
"Content-Type",
|
|
4880
|
+
"Authorization",
|
|
4881
|
+
"X-Requested-With",
|
|
4882
|
+
"Accept"
|
|
4883
|
+
],
|
|
4884
|
+
exposedHeaders: ["Set-Cookie"],
|
|
4885
|
+
optionsSuccessStatus: 204
|
|
4886
|
+
};
|
|
4887
|
+
}
|
|
4888
|
+
|
|
4889
|
+
// src/infrastructure/database/DatabaseManager.ts
|
|
4830
4890
|
var DatabaseManager = class {
|
|
4831
4891
|
constructor(provider, options = {
|
|
4832
4892
|
enableShutdownHooks: true
|
|
@@ -4837,21 +4897,21 @@ var DatabaseManager = class {
|
|
|
4837
4897
|
async connect() {
|
|
4838
4898
|
try {
|
|
4839
4899
|
await this.provider.connect();
|
|
4840
|
-
logger.
|
|
4900
|
+
logger.info("Database connected");
|
|
4841
4901
|
if (this.options.enableShutdownHooks) {
|
|
4842
4902
|
this.registerShutdownHooks();
|
|
4843
4903
|
}
|
|
4844
4904
|
} catch (error) {
|
|
4845
|
-
logger.
|
|
4905
|
+
logger.error("Database connection failed", error);
|
|
4846
4906
|
throw error;
|
|
4847
4907
|
}
|
|
4848
4908
|
}
|
|
4849
4909
|
async disconnect() {
|
|
4850
4910
|
try {
|
|
4851
4911
|
await this.provider.disconnect();
|
|
4852
|
-
logger.
|
|
4912
|
+
logger.info("Database disconnected");
|
|
4853
4913
|
} catch (error) {
|
|
4854
|
-
logger.
|
|
4914
|
+
logger.error("Database disconnect failed", error);
|
|
4855
4915
|
throw error;
|
|
4856
4916
|
}
|
|
4857
4917
|
}
|
|
@@ -4863,12 +4923,20 @@ var DatabaseManager = class {
|
|
|
4863
4923
|
}
|
|
4864
4924
|
registerShutdownHooks() {
|
|
4865
4925
|
process.once("SIGINT", async () => {
|
|
4866
|
-
|
|
4867
|
-
|
|
4926
|
+
logger.info("SIGINT received, shutting down database connection");
|
|
4927
|
+
try {
|
|
4928
|
+
await this.disconnect();
|
|
4929
|
+
} finally {
|
|
4930
|
+
process.exit(0);
|
|
4931
|
+
}
|
|
4868
4932
|
});
|
|
4869
4933
|
process.once("SIGTERM", async () => {
|
|
4870
|
-
|
|
4871
|
-
|
|
4934
|
+
logger.info("SIGTERM received, shutting down database connection");
|
|
4935
|
+
try {
|
|
4936
|
+
await this.disconnect();
|
|
4937
|
+
} finally {
|
|
4938
|
+
process.exit(0);
|
|
4939
|
+
}
|
|
4872
4940
|
});
|
|
4873
4941
|
}
|
|
4874
4942
|
};
|
|
@@ -4902,30 +4970,12 @@ var MongoDatabaseProvider = class {
|
|
|
4902
4970
|
}
|
|
4903
4971
|
};
|
|
4904
4972
|
|
|
4905
|
-
// src/
|
|
4906
|
-
var AppError = class extends Error {
|
|
4907
|
-
statusCode;
|
|
4908
|
-
status;
|
|
4909
|
-
isOperational;
|
|
4910
|
-
code;
|
|
4911
|
-
details;
|
|
4912
|
-
constructor(message, statusCode = 500, options) {
|
|
4913
|
-
super(message);
|
|
4914
|
-
this.statusCode = statusCode;
|
|
4915
|
-
this.status = `${statusCode}`.startsWith("4") ? "fail" : "error";
|
|
4916
|
-
this.isOperational = true;
|
|
4917
|
-
this.code = options?.code;
|
|
4918
|
-
this.details = options?.details;
|
|
4919
|
-
Error.captureStackTrace(this, this.constructor);
|
|
4920
|
-
}
|
|
4921
|
-
};
|
|
4922
|
-
|
|
4923
|
-
// src/http/handlers/AsyncHandler.ts
|
|
4973
|
+
// src/infrastructure/http/handlers/AsyncHandler.ts
|
|
4924
4974
|
var AsyncHandler = (fn) => (req, res, next) => {
|
|
4925
4975
|
Promise.resolve(fn(req, res, next)).catch(next);
|
|
4926
4976
|
};
|
|
4927
4977
|
|
|
4928
|
-
// src/http/query/QueryConstants.ts
|
|
4978
|
+
// src/infrastructure/http/query/QueryConstants.ts
|
|
4929
4979
|
var QUERY_RESERVED_FIELDS = [
|
|
4930
4980
|
"page",
|
|
4931
4981
|
"limit",
|
|
@@ -4950,7 +5000,7 @@ var SUPPORTED_OPERATORS = [
|
|
|
4950
5000
|
"endsWith"
|
|
4951
5001
|
];
|
|
4952
5002
|
|
|
4953
|
-
// src/http/query/ApiFeatures.ts
|
|
5003
|
+
// src/infrastructure/http/query/ApiFeatures.ts
|
|
4954
5004
|
var ApiFeatures = class {
|
|
4955
5005
|
static parse(query) {
|
|
4956
5006
|
return {
|
|
@@ -5028,7 +5078,7 @@ var ApiFeatures = class {
|
|
|
5028
5078
|
}
|
|
5029
5079
|
};
|
|
5030
5080
|
|
|
5031
|
-
// src/http/responses/ApiResponse.ts
|
|
5081
|
+
// src/infrastructure/http/responses/ApiResponse.ts
|
|
5032
5082
|
var ApiResponse = class _ApiResponse {
|
|
5033
5083
|
static send(res, options) {
|
|
5034
5084
|
const {
|
|
@@ -5102,7 +5152,7 @@ var ApiResponse = class _ApiResponse {
|
|
|
5102
5152
|
}
|
|
5103
5153
|
};
|
|
5104
5154
|
|
|
5105
|
-
// src/http/controllers/CrudControllerFactory.ts
|
|
5155
|
+
// src/infrastructure/http/controllers/CrudControllerFactory.ts
|
|
5106
5156
|
var CrudControllerFactory = class {
|
|
5107
5157
|
static create(repository, options = {}) {
|
|
5108
5158
|
const resourceName = options.resourceName ?? "Resource";
|
|
@@ -5204,12 +5254,12 @@ var CrudControllerFactory = class {
|
|
|
5204
5254
|
}
|
|
5205
5255
|
};
|
|
5206
5256
|
|
|
5207
|
-
// src/http/middleware/AuthMiddleware.ts
|
|
5257
|
+
// src/infrastructure/http/middleware/AuthMiddleware.ts
|
|
5208
5258
|
var authMiddleware = (_req, _res, next) => {
|
|
5209
5259
|
next();
|
|
5210
5260
|
};
|
|
5211
5261
|
|
|
5212
|
-
// src/http/middleware/ErrorMiddleware.ts
|
|
5262
|
+
// src/infrastructure/http/middleware/ErrorMiddleware.ts
|
|
5213
5263
|
var handleCastError = (err) => new AppError(`Invalid ${err.path}: ${err.value}`, 400, {
|
|
5214
5264
|
code: "INVALID_ID"
|
|
5215
5265
|
});
|
|
@@ -5219,7 +5269,7 @@ var handleDuplicateKey = (err) => {
|
|
|
5219
5269
|
code: "DUPLICATE_FIELD"
|
|
5220
5270
|
});
|
|
5221
5271
|
};
|
|
5222
|
-
var
|
|
5272
|
+
var handleValidationError2 = (err) => {
|
|
5223
5273
|
const errors = Object.entries(err.errors).reduce(
|
|
5224
5274
|
(acc, [key, value]) => {
|
|
5225
5275
|
acc[key] = value.message;
|
|
@@ -5239,11 +5289,13 @@ var ErrorMiddleware = (isProduction = false) => (err, _req, res, _next) => {
|
|
|
5239
5289
|
if (err instanceof AppError) {
|
|
5240
5290
|
error = err;
|
|
5241
5291
|
} else if (err instanceof Error) {
|
|
5242
|
-
error = new AppError(err.message, 500
|
|
5243
|
-
|
|
5292
|
+
error = new AppError(err.message, 500, {
|
|
5293
|
+
isOperational: false
|
|
5294
|
+
});
|
|
5244
5295
|
} else {
|
|
5245
|
-
error = new AppError("Internal Server Error", 500
|
|
5246
|
-
|
|
5296
|
+
error = new AppError("Internal Server Error", 500, {
|
|
5297
|
+
isOperational: false
|
|
5298
|
+
});
|
|
5247
5299
|
}
|
|
5248
5300
|
if (err && err.name === "CastError") {
|
|
5249
5301
|
error = handleCastError(err);
|
|
@@ -5254,7 +5306,7 @@ var ErrorMiddleware = (isProduction = false) => (err, _req, res, _next) => {
|
|
|
5254
5306
|
);
|
|
5255
5307
|
}
|
|
5256
5308
|
if (err && err.name === "ValidationError") {
|
|
5257
|
-
error =
|
|
5309
|
+
error = handleValidationError2(err);
|
|
5258
5310
|
}
|
|
5259
5311
|
if (err?.name === "JsonWebTokenError") {
|
|
5260
5312
|
error = handleJWTError();
|
|
@@ -5263,9 +5315,9 @@ var ErrorMiddleware = (isProduction = false) => (err, _req, res, _next) => {
|
|
|
5263
5315
|
error = handleJWTExpiredError();
|
|
5264
5316
|
}
|
|
5265
5317
|
if (!error.isOperational) {
|
|
5266
|
-
logger.
|
|
5318
|
+
logger.error("Programming error", err);
|
|
5267
5319
|
} else {
|
|
5268
|
-
logger.
|
|
5320
|
+
logger.error("Operational error", {
|
|
5269
5321
|
message: error.message
|
|
5270
5322
|
});
|
|
5271
5323
|
}
|
|
@@ -5293,7 +5345,7 @@ var ErrorMiddleware = (isProduction = false) => (err, _req, res, _next) => {
|
|
|
5293
5345
|
});
|
|
5294
5346
|
};
|
|
5295
5347
|
|
|
5296
|
-
// src/http/validation/Validator.ts
|
|
5348
|
+
// src/infrastructure/http/validation/Validator.ts
|
|
5297
5349
|
var isJoiSchema = (schema) => {
|
|
5298
5350
|
return typeof schema === "object" && schema !== null && "validate" in schema;
|
|
5299
5351
|
};
|
|
@@ -5301,7 +5353,7 @@ var isZodSchema = (schema) => {
|
|
|
5301
5353
|
return typeof schema === "object" && schema !== null && "safeParse" in schema;
|
|
5302
5354
|
};
|
|
5303
5355
|
|
|
5304
|
-
// src/http/validation/JoiValidator.ts
|
|
5356
|
+
// src/infrastructure/http/validation/JoiValidator.ts
|
|
5305
5357
|
var JoiValidator = class {
|
|
5306
5358
|
constructor(schema) {
|
|
5307
5359
|
this.schema = schema;
|
|
@@ -5329,7 +5381,7 @@ var JoiValidator = class {
|
|
|
5329
5381
|
}
|
|
5330
5382
|
};
|
|
5331
5383
|
|
|
5332
|
-
// src/http/validation/ZodValidator.ts
|
|
5384
|
+
// src/infrastructure/http/validation/ZodValidator.ts
|
|
5333
5385
|
var ZodValidator = class {
|
|
5334
5386
|
constructor(schema) {
|
|
5335
5387
|
this.schema = schema;
|
|
@@ -5354,7 +5406,7 @@ var ZodValidator = class {
|
|
|
5354
5406
|
}
|
|
5355
5407
|
};
|
|
5356
5408
|
|
|
5357
|
-
// src/http/middleware/ValidationMiddleware.ts
|
|
5409
|
+
// src/infrastructure/http/middleware/ValidationMiddleware.ts
|
|
5358
5410
|
var validate = (schema) => (req, _res, next) => {
|
|
5359
5411
|
let result;
|
|
5360
5412
|
if (isJoiSchema(schema)) {
|
|
@@ -5376,7 +5428,7 @@ var validate = (schema) => (req, _res, next) => {
|
|
|
5376
5428
|
next();
|
|
5377
5429
|
};
|
|
5378
5430
|
|
|
5379
|
-
// src/http/utils/PickFields.ts
|
|
5431
|
+
// src/infrastructure/http/utils/PickFields.ts
|
|
5380
5432
|
function pickFields(obj, fields, options = {}) {
|
|
5381
5433
|
const removeUndefined = options.removeUndefined ?? false;
|
|
5382
5434
|
const removeNull = options.removeNull ?? false;
|
|
@@ -5438,7 +5490,7 @@ var RequestContext = class {
|
|
|
5438
5490
|
}
|
|
5439
5491
|
};
|
|
5440
5492
|
|
|
5441
|
-
// src/networking/middleware/RequestContextMiddleware.ts
|
|
5493
|
+
// src/infrastructure/networking/middleware/RequestContextMiddleware.ts
|
|
5442
5494
|
function createRequestContextMiddleware(options = {}) {
|
|
5443
5495
|
const {
|
|
5444
5496
|
correlationHeaderName = "X-Correlation-Id",
|
|
@@ -5458,7 +5510,7 @@ function createRequestContextMiddleware(options = {}) {
|
|
|
5458
5510
|
};
|
|
5459
5511
|
}
|
|
5460
5512
|
|
|
5461
|
-
// src/networking/observability/TracingHeaders.ts
|
|
5513
|
+
// src/infrastructure/networking/observability/TracingHeaders.ts
|
|
5462
5514
|
var TracingHeaders = class {
|
|
5463
5515
|
static build() {
|
|
5464
5516
|
const headers = {};
|
|
@@ -5482,7 +5534,7 @@ var TracingHeaders = class {
|
|
|
5482
5534
|
}
|
|
5483
5535
|
};
|
|
5484
5536
|
|
|
5485
|
-
// src/networking/resilience/ExponentialBackoffRetryPolicy.ts
|
|
5537
|
+
// src/infrastructure/networking/resilience/ExponentialBackoffRetryPolicy.ts
|
|
5486
5538
|
var ExponentialBackoffRetryPolicy = class {
|
|
5487
5539
|
retries;
|
|
5488
5540
|
baseDelay;
|
|
@@ -5501,7 +5553,7 @@ var ExponentialBackoffRetryPolicy = class {
|
|
|
5501
5553
|
}
|
|
5502
5554
|
};
|
|
5503
5555
|
|
|
5504
|
-
// src/networking/resilience/FixedRetryPolicy.ts
|
|
5556
|
+
// src/infrastructure/networking/resilience/FixedRetryPolicy.ts
|
|
5505
5557
|
var FixedRetryPolicy = class {
|
|
5506
5558
|
retries;
|
|
5507
5559
|
delay;
|
|
@@ -5517,7 +5569,7 @@ var FixedRetryPolicy = class {
|
|
|
5517
5569
|
}
|
|
5518
5570
|
};
|
|
5519
5571
|
|
|
5520
|
-
// src/networking/security/BearerTokenStrategy.ts
|
|
5572
|
+
// src/infrastructure/networking/security/BearerTokenStrategy.ts
|
|
5521
5573
|
var BearerTokenStrategy = class {
|
|
5522
5574
|
constructor(tokenProvider) {
|
|
5523
5575
|
this.tokenProvider = tokenProvider;
|
|
@@ -5530,7 +5582,7 @@ var BearerTokenStrategy = class {
|
|
|
5530
5582
|
}
|
|
5531
5583
|
};
|
|
5532
5584
|
|
|
5533
|
-
// src/networking/security/StaticTokenProvider.ts
|
|
5585
|
+
// src/infrastructure/networking/security/StaticTokenProvider.ts
|
|
5534
5586
|
var StaticTokenProvider = class {
|
|
5535
5587
|
constructor(token) {
|
|
5536
5588
|
this.token = token;
|
|
@@ -5540,7 +5592,7 @@ var StaticTokenProvider = class {
|
|
|
5540
5592
|
}
|
|
5541
5593
|
};
|
|
5542
5594
|
|
|
5543
|
-
// src/networking/transport/HttpClient.ts
|
|
5595
|
+
// src/infrastructure/networking/transport/HttpClient.ts
|
|
5544
5596
|
var HttpClient = class {
|
|
5545
5597
|
baseUrl;
|
|
5546
5598
|
timeout;
|
|
@@ -5618,7 +5670,7 @@ var HttpClient = class {
|
|
|
5618
5670
|
lastError = error;
|
|
5619
5671
|
if (this.retryPolicy.shouldRetry(attempt, error)) {
|
|
5620
5672
|
const delay = this.retryPolicy.getDelay(attempt, error);
|
|
5621
|
-
logger.
|
|
5673
|
+
logger.warn(
|
|
5622
5674
|
`[${this.serviceName}] retry ${attempt + 1} after ${delay}ms`
|
|
5623
5675
|
);
|
|
5624
5676
|
await this.sleep(delay);
|
|
@@ -5629,7 +5681,7 @@ var HttpClient = class {
|
|
|
5629
5681
|
}
|
|
5630
5682
|
}
|
|
5631
5683
|
const correlationId = RequestContext.getCorrelationId();
|
|
5632
|
-
logger.
|
|
5684
|
+
logger.error(
|
|
5633
5685
|
`[${this.serviceName}]` + (correlationId ? ` [${correlationId}]` : "") + ` request failed`,
|
|
5634
5686
|
lastError
|
|
5635
5687
|
);
|
|
@@ -5640,7 +5692,7 @@ var HttpClient = class {
|
|
|
5640
5692
|
}
|
|
5641
5693
|
};
|
|
5642
5694
|
|
|
5643
|
-
// src/networking/services/ServiceClient.ts
|
|
5695
|
+
// src/infrastructure/networking/services/ServiceClient.ts
|
|
5644
5696
|
var ServiceClient = class extends HttpClient {
|
|
5645
5697
|
async getData(path2) {
|
|
5646
5698
|
const response = await super.get(path2);
|
|
@@ -5664,7 +5716,7 @@ var ServiceClient = class extends HttpClient {
|
|
|
5664
5716
|
}
|
|
5665
5717
|
};
|
|
5666
5718
|
|
|
5667
|
-
// src/networking/services/InternalServiceClient.ts
|
|
5719
|
+
// src/infrastructure/networking/services/InternalServiceClient.ts
|
|
5668
5720
|
var InternalServiceClient = class extends ServiceClient {
|
|
5669
5721
|
constructor(baseUrl, serviceToken, serviceName) {
|
|
5670
5722
|
super(baseUrl, {
|
|
@@ -6103,7 +6155,7 @@ var JWTService = class {
|
|
|
6103
6155
|
try {
|
|
6104
6156
|
return jwt.verify(token, this.accessSecret);
|
|
6105
6157
|
} catch (err) {
|
|
6106
|
-
logger.
|
|
6158
|
+
logger.error("Access token verification failed:", err.message);
|
|
6107
6159
|
return null;
|
|
6108
6160
|
}
|
|
6109
6161
|
}
|
|
@@ -6111,7 +6163,7 @@ var JWTService = class {
|
|
|
6111
6163
|
try {
|
|
6112
6164
|
return jwt.verify(token, this.refreshSecret);
|
|
6113
6165
|
} catch (err) {
|
|
6114
|
-
logger.
|
|
6166
|
+
logger.error("Refresh token verification failed:", err.message);
|
|
6115
6167
|
return null;
|
|
6116
6168
|
}
|
|
6117
6169
|
}
|
|
@@ -6268,6 +6320,6 @@ function sleep(ms) {
|
|
|
6268
6320
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
6269
6321
|
}
|
|
6270
6322
|
|
|
6271
|
-
export { AVLTree, AdjacencyList, AdjacencyMatrix, ApiFeatures, ApiResponse, AppError, 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, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
|
|
6323
|
+
export { AVLTree, AdjacencyList, AdjacencyMatrix, ApiFeatures, ApiResponse, AppError, AsyncHandler, AzureBlobStorageService, BPlusTree, BTree, BearerTokenStrategy, BinaryHeap, BinarySearchTree, BinaryTree, BloomFilter, CircularArray, CircularLinkedList, CircularQueue, CloudinaryService, ConsistentHash, CorrelationId, CountMinSketch, CrudControllerFactory, DEFAULT_ALLOWED_ORIGINS, 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, Logger, 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, loadEnv, logger, milliseconds, minutes, pickFields, seconds, sleep, toHours, toMinutes, toSeconds, validate };
|
|
6272
6324
|
//# sourceMappingURL=index.js.map
|
|
6273
6325
|
//# sourceMappingURL=index.js.map
|