elseware-nodejs 1.11.5 → 1.11.7
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 +20 -20
- package/README.md +49 -49
- package/dist/index.cjs +82 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -8
- package/dist/index.d.ts +11 -8
- package/dist/index.js +82 -36
- package/dist/index.js.map +1 -1
- package/package.json +78 -78
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 elseware Technology
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 elseware Technology
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
# elseware-nodejs
|
|
2
|
-
|
|
3
|
-
A modern Node.js utility and application framework powering the Elseware ecosystem.
|
|
4
|
-
|
|
5
|
-
`elseware-nodejs` provides a collection of reusable components, utilities, middleware, abstractions, and development patterns for building scalable Node.js applications and microservices.
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- TypeScript-first development
|
|
10
|
-
- Express.js integration
|
|
11
|
-
- Repository pattern abstractions
|
|
12
|
-
- Service layer architecture
|
|
13
|
-
- Request context management
|
|
14
|
-
- Structured error handling
|
|
15
|
-
- Validation utilities
|
|
16
|
-
- Logging and observability support
|
|
17
|
-
- Microservice-friendly design
|
|
18
|
-
- Reusable application building blocks
|
|
19
|
-
|
|
20
|
-
## Installation
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
npm install elseware-nodejs
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Usage
|
|
27
|
-
|
|
28
|
-
```ts
|
|
29
|
-
import { AppError } from "elseware-nodejs";
|
|
30
|
-
|
|
31
|
-
throw new AppError("Something went wrong");
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Documentation
|
|
35
|
-
|
|
36
|
-
Documentation, guides, and usage examples are available in the official repository.
|
|
37
|
-
|
|
38
|
-
## About elseware Technology
|
|
39
|
-
|
|
40
|
-
elseware Technology builds tools, frameworks, and solutions for software engineering, cloud computing, game development, and developer productivity.
|
|
41
|
-
|
|
42
|
-
## Contributing
|
|
43
|
-
|
|
44
|
-
Contributions, issues, and feature requests are welcome.
|
|
45
|
-
|
|
46
|
-
## License
|
|
47
|
-
|
|
48
|
-
This project is licensed under the MIT License.
|
|
49
|
-
|
|
1
|
+
# elseware-nodejs
|
|
2
|
+
|
|
3
|
+
A modern Node.js utility and application framework powering the Elseware ecosystem.
|
|
4
|
+
|
|
5
|
+
`elseware-nodejs` provides a collection of reusable components, utilities, middleware, abstractions, and development patterns for building scalable Node.js applications and microservices.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- TypeScript-first development
|
|
10
|
+
- Express.js integration
|
|
11
|
+
- Repository pattern abstractions
|
|
12
|
+
- Service layer architecture
|
|
13
|
+
- Request context management
|
|
14
|
+
- Structured error handling
|
|
15
|
+
- Validation utilities
|
|
16
|
+
- Logging and observability support
|
|
17
|
+
- Microservice-friendly design
|
|
18
|
+
- Reusable application building blocks
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install elseware-nodejs
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { AppError } from "elseware-nodejs";
|
|
30
|
+
|
|
31
|
+
throw new AppError("Something went wrong");
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Documentation
|
|
35
|
+
|
|
36
|
+
Documentation, guides, and usage examples are available in the official repository.
|
|
37
|
+
|
|
38
|
+
## About elseware Technology
|
|
39
|
+
|
|
40
|
+
elseware Technology builds tools, frameworks, and solutions for software engineering, cloud computing, game development, and developer productivity.
|
|
41
|
+
|
|
42
|
+
## Contributing
|
|
43
|
+
|
|
44
|
+
Contributions, issues, and feature requests are welcome.
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
This project is licensed under the MIT License.
|
|
49
|
+
|
|
50
50
|
Copyright © 2026 elseware Technology.
|
package/dist/index.cjs
CHANGED
|
@@ -27,8 +27,7 @@ var juice__default = /*#__PURE__*/_interopDefault(juice);
|
|
|
27
27
|
var jwt__default = /*#__PURE__*/_interopDefault(jwt);
|
|
28
28
|
var multer__default = /*#__PURE__*/_interopDefault(multer);
|
|
29
29
|
|
|
30
|
-
// src/core/
|
|
31
|
-
var DEFAULT_ALLOWED_ORIGINS = ["http://localhost:3000"];
|
|
30
|
+
// src/core/environment/loadEnv.ts
|
|
32
31
|
|
|
33
32
|
// src/utils/errorToString.ts
|
|
34
33
|
function errorToString(error) {
|
|
@@ -1943,6 +1942,7 @@ var CircularQueue = class {
|
|
|
1943
1942
|
}
|
|
1944
1943
|
this.data = new Array(capacity);
|
|
1945
1944
|
}
|
|
1945
|
+
capacity;
|
|
1946
1946
|
data;
|
|
1947
1947
|
head = 0;
|
|
1948
1948
|
tail = 0;
|
|
@@ -4863,41 +4863,52 @@ var SegmentTree = class {
|
|
|
4863
4863
|
}
|
|
4864
4864
|
};
|
|
4865
4865
|
|
|
4866
|
-
// src/infrastructure/cors/
|
|
4867
|
-
function
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4866
|
+
// src/infrastructure/cors/isAllowedOrigin.ts
|
|
4867
|
+
function isAllowedOrigin(origin, allowedOrigins) {
|
|
4868
|
+
return allowedOrigins.some((allowedOrigin) => {
|
|
4869
|
+
if (allowedOrigin === "*") {
|
|
4870
|
+
return true;
|
|
4871
|
+
}
|
|
4872
|
+
if (allowedOrigin === origin) {
|
|
4873
|
+
return true;
|
|
4874
|
+
}
|
|
4875
|
+
if (allowedOrigin.startsWith("*.") && origin.endsWith(allowedOrigin.slice(1))) {
|
|
4876
|
+
return true;
|
|
4877
|
+
}
|
|
4878
|
+
return false;
|
|
4879
|
+
});
|
|
4880
4880
|
}
|
|
4881
4881
|
|
|
4882
4882
|
// src/infrastructure/cors/createCorsOptions.ts
|
|
4883
|
-
function createCorsOptions(
|
|
4883
|
+
function createCorsOptions(config) {
|
|
4884
|
+
const {
|
|
4885
|
+
allowedOrigins,
|
|
4886
|
+
allowCredentials = true,
|
|
4887
|
+
allowedMethods = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
|
4888
|
+
allowedHeaders = [
|
|
4889
|
+
"Content-Type",
|
|
4890
|
+
"Authorization",
|
|
4891
|
+
"X-Requested-With",
|
|
4892
|
+
"Accept"
|
|
4893
|
+
],
|
|
4894
|
+
exposedHeaders = ["Set-Cookie"],
|
|
4895
|
+
optionsSuccessStatus = 204
|
|
4896
|
+
} = config;
|
|
4884
4897
|
return {
|
|
4885
4898
|
origin(origin, callback) {
|
|
4886
|
-
if (!origin
|
|
4899
|
+
if (!origin) {
|
|
4900
|
+
return callback(null, true);
|
|
4901
|
+
}
|
|
4902
|
+
if (isAllowedOrigin(origin, allowedOrigins)) {
|
|
4887
4903
|
return callback(null, true);
|
|
4888
4904
|
}
|
|
4889
4905
|
return callback(new Error(`CORS blocked: ${origin} is not allowed`));
|
|
4890
4906
|
},
|
|
4891
|
-
credentials:
|
|
4892
|
-
methods:
|
|
4893
|
-
allowedHeaders
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
"X-Requested-With",
|
|
4897
|
-
"Accept"
|
|
4898
|
-
],
|
|
4899
|
-
exposedHeaders: ["Set-Cookie"],
|
|
4900
|
-
optionsSuccessStatus: 204
|
|
4907
|
+
credentials: allowCredentials,
|
|
4908
|
+
methods: allowedMethods,
|
|
4909
|
+
allowedHeaders,
|
|
4910
|
+
exposedHeaders,
|
|
4911
|
+
optionsSuccessStatus
|
|
4901
4912
|
};
|
|
4902
4913
|
}
|
|
4903
4914
|
|
|
@@ -4909,6 +4920,8 @@ var DatabaseManager = class {
|
|
|
4909
4920
|
this.provider = provider;
|
|
4910
4921
|
this.options = options;
|
|
4911
4922
|
}
|
|
4923
|
+
provider;
|
|
4924
|
+
options;
|
|
4912
4925
|
async connect() {
|
|
4913
4926
|
try {
|
|
4914
4927
|
await this.provider.connect();
|
|
@@ -4959,6 +4972,7 @@ var MongoDatabaseProvider = class {
|
|
|
4959
4972
|
constructor(config) {
|
|
4960
4973
|
this.config = config;
|
|
4961
4974
|
}
|
|
4975
|
+
config;
|
|
4962
4976
|
async connect() {
|
|
4963
4977
|
mongoose__default.default.set("strictQuery", this.config.strictQuery ?? true);
|
|
4964
4978
|
await mongoose__default.default.connect(this.config.uri);
|
|
@@ -5373,6 +5387,7 @@ var JoiValidator = class {
|
|
|
5373
5387
|
constructor(schema) {
|
|
5374
5388
|
this.schema = schema;
|
|
5375
5389
|
}
|
|
5390
|
+
schema;
|
|
5376
5391
|
validate(data) {
|
|
5377
5392
|
const result = this.schema.validate(data, {
|
|
5378
5393
|
abortEarly: false,
|
|
@@ -5401,6 +5416,7 @@ var ZodValidator = class {
|
|
|
5401
5416
|
constructor(schema) {
|
|
5402
5417
|
this.schema = schema;
|
|
5403
5418
|
}
|
|
5419
|
+
schema;
|
|
5404
5420
|
validate(data) {
|
|
5405
5421
|
const result = this.schema.safeParse(data);
|
|
5406
5422
|
if (!result.success) {
|
|
@@ -5589,6 +5605,7 @@ var BearerTokenStrategy = class {
|
|
|
5589
5605
|
constructor(tokenProvider) {
|
|
5590
5606
|
this.tokenProvider = tokenProvider;
|
|
5591
5607
|
}
|
|
5608
|
+
tokenProvider;
|
|
5592
5609
|
async getHeaders() {
|
|
5593
5610
|
const token = await this.tokenProvider.getToken();
|
|
5594
5611
|
return {
|
|
@@ -5602,6 +5619,7 @@ var StaticTokenProvider = class {
|
|
|
5602
5619
|
constructor(token) {
|
|
5603
5620
|
this.token = token;
|
|
5604
5621
|
}
|
|
5622
|
+
token;
|
|
5605
5623
|
getToken() {
|
|
5606
5624
|
return this.token;
|
|
5607
5625
|
}
|
|
@@ -5645,9 +5663,9 @@ var HttpClient = class {
|
|
|
5645
5663
|
let attempt = 0;
|
|
5646
5664
|
let lastError;
|
|
5647
5665
|
while (true) {
|
|
5666
|
+
const controller = new AbortController();
|
|
5667
|
+
const timeout = setTimeout(() => controller.abort(), this.timeout);
|
|
5648
5668
|
try {
|
|
5649
|
-
const controller = new AbortController();
|
|
5650
|
-
const timeout = setTimeout(() => controller.abort(), this.timeout);
|
|
5651
5669
|
const authHeaders = await this.authStrategy?.getHeaders();
|
|
5652
5670
|
const response = await fetch(`${this.baseUrl}${path2}`, {
|
|
5653
5671
|
method,
|
|
@@ -5661,17 +5679,19 @@ var HttpClient = class {
|
|
|
5661
5679
|
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
5662
5680
|
});
|
|
5663
5681
|
clearTimeout(timeout);
|
|
5664
|
-
const
|
|
5682
|
+
const parsedBody = await this.parseResponseBody(response);
|
|
5665
5683
|
if (!response.ok) {
|
|
5684
|
+
const payload = parsedBody;
|
|
5666
5685
|
throw new AppError(
|
|
5667
|
-
|
|
5686
|
+
payload?.message ?? response.statusText ?? "HTTP request failed",
|
|
5668
5687
|
response.status,
|
|
5669
5688
|
{
|
|
5670
|
-
code:
|
|
5689
|
+
code: payload?.code ?? "HTTP_REQUEST_FAILED",
|
|
5671
5690
|
details: {
|
|
5672
5691
|
service: this.serviceName,
|
|
5673
5692
|
method,
|
|
5674
|
-
path: path2
|
|
5693
|
+
path: path2,
|
|
5694
|
+
status: response.status
|
|
5675
5695
|
}
|
|
5676
5696
|
}
|
|
5677
5697
|
);
|
|
@@ -5680,8 +5700,9 @@ var HttpClient = class {
|
|
|
5680
5700
|
logger.info(
|
|
5681
5701
|
`[${this.serviceName}]` + (correlationId2 ? ` [${correlationId2}]` : "") + ` ${method} ${path2}`
|
|
5682
5702
|
);
|
|
5683
|
-
return
|
|
5703
|
+
return parsedBody;
|
|
5684
5704
|
} catch (error) {
|
|
5705
|
+
clearTimeout(timeout);
|
|
5685
5706
|
lastError = error;
|
|
5686
5707
|
if (this.retryPolicy.shouldRetry(attempt, error)) {
|
|
5687
5708
|
const delay = this.retryPolicy.getDelay(attempt, error);
|
|
@@ -5702,6 +5723,31 @@ var HttpClient = class {
|
|
|
5702
5723
|
);
|
|
5703
5724
|
throw lastError;
|
|
5704
5725
|
}
|
|
5726
|
+
async parseResponseBody(response) {
|
|
5727
|
+
if (response.status === 204) {
|
|
5728
|
+
return null;
|
|
5729
|
+
}
|
|
5730
|
+
const responseLike = response;
|
|
5731
|
+
const contentType = response.headers?.get?.("content-type") ?? "";
|
|
5732
|
+
if (contentType.includes("application/json") && typeof responseLike.json === "function") {
|
|
5733
|
+
return responseLike.json();
|
|
5734
|
+
}
|
|
5735
|
+
if (typeof responseLike.json === "function") {
|
|
5736
|
+
try {
|
|
5737
|
+
return await responseLike.json();
|
|
5738
|
+
} catch {
|
|
5739
|
+
}
|
|
5740
|
+
}
|
|
5741
|
+
if (typeof responseLike.text === "function") {
|
|
5742
|
+
const text = await responseLike.text();
|
|
5743
|
+
return {
|
|
5744
|
+
message: text || response.statusText || "HTTP request failed"
|
|
5745
|
+
};
|
|
5746
|
+
}
|
|
5747
|
+
return {
|
|
5748
|
+
message: response.statusText || "HTTP request failed"
|
|
5749
|
+
};
|
|
5750
|
+
}
|
|
5705
5751
|
sleep(ms) {
|
|
5706
5752
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5707
5753
|
}
|
|
@@ -6358,7 +6404,6 @@ exports.ConsistentHash = ConsistentHash;
|
|
|
6358
6404
|
exports.CorrelationId = CorrelationId;
|
|
6359
6405
|
exports.CountMinSketch = CountMinSketch;
|
|
6360
6406
|
exports.CrudControllerFactory = CrudControllerFactory;
|
|
6361
|
-
exports.DEFAULT_ALLOWED_ORIGINS = DEFAULT_ALLOWED_ORIGINS;
|
|
6362
6407
|
exports.DEFAULT_LIMIT = DEFAULT_LIMIT;
|
|
6363
6408
|
exports.DEFAULT_PAGE = DEFAULT_PAGE;
|
|
6364
6409
|
exports.DEFAULT_SORT_DIRECTION = DEFAULT_SORT_DIRECTION;
|
|
@@ -6427,12 +6472,12 @@ exports.TreeNode = TreeNode;
|
|
|
6427
6472
|
exports.Trie = Trie;
|
|
6428
6473
|
exports.ZodValidator = ZodValidator;
|
|
6429
6474
|
exports.authMiddleware = authMiddleware;
|
|
6430
|
-
exports.createAllowedOrigins = createAllowedOrigins;
|
|
6431
6475
|
exports.createCorsOptions = createCorsOptions;
|
|
6432
6476
|
exports.createRequestContextMiddleware = createRequestContextMiddleware;
|
|
6433
6477
|
exports.days = days;
|
|
6434
6478
|
exports.errorToString = errorToString;
|
|
6435
6479
|
exports.hours = hours;
|
|
6480
|
+
exports.isAllowedOrigin = isAllowedOrigin;
|
|
6436
6481
|
exports.isJoiSchema = isJoiSchema;
|
|
6437
6482
|
exports.isZodSchema = isZodSchema;
|
|
6438
6483
|
exports.loadEnv = loadEnv;
|