elseware-nodejs 1.11.6 → 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 +43 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +43 -7
- package/dist/index.js.map +1 -1
- package/package.json +78 -78
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1927,6 +1927,7 @@ var CircularQueue = class {
|
|
|
1927
1927
|
}
|
|
1928
1928
|
this.data = new Array(capacity);
|
|
1929
1929
|
}
|
|
1930
|
+
capacity;
|
|
1930
1931
|
data;
|
|
1931
1932
|
head = 0;
|
|
1932
1933
|
tail = 0;
|
|
@@ -4904,6 +4905,8 @@ var DatabaseManager = class {
|
|
|
4904
4905
|
this.provider = provider;
|
|
4905
4906
|
this.options = options;
|
|
4906
4907
|
}
|
|
4908
|
+
provider;
|
|
4909
|
+
options;
|
|
4907
4910
|
async connect() {
|
|
4908
4911
|
try {
|
|
4909
4912
|
await this.provider.connect();
|
|
@@ -4954,6 +4957,7 @@ var MongoDatabaseProvider = class {
|
|
|
4954
4957
|
constructor(config) {
|
|
4955
4958
|
this.config = config;
|
|
4956
4959
|
}
|
|
4960
|
+
config;
|
|
4957
4961
|
async connect() {
|
|
4958
4962
|
mongoose.set("strictQuery", this.config.strictQuery ?? true);
|
|
4959
4963
|
await mongoose.connect(this.config.uri);
|
|
@@ -5368,6 +5372,7 @@ var JoiValidator = class {
|
|
|
5368
5372
|
constructor(schema) {
|
|
5369
5373
|
this.schema = schema;
|
|
5370
5374
|
}
|
|
5375
|
+
schema;
|
|
5371
5376
|
validate(data) {
|
|
5372
5377
|
const result = this.schema.validate(data, {
|
|
5373
5378
|
abortEarly: false,
|
|
@@ -5396,6 +5401,7 @@ var ZodValidator = class {
|
|
|
5396
5401
|
constructor(schema) {
|
|
5397
5402
|
this.schema = schema;
|
|
5398
5403
|
}
|
|
5404
|
+
schema;
|
|
5399
5405
|
validate(data) {
|
|
5400
5406
|
const result = this.schema.safeParse(data);
|
|
5401
5407
|
if (!result.success) {
|
|
@@ -5584,6 +5590,7 @@ var BearerTokenStrategy = class {
|
|
|
5584
5590
|
constructor(tokenProvider) {
|
|
5585
5591
|
this.tokenProvider = tokenProvider;
|
|
5586
5592
|
}
|
|
5593
|
+
tokenProvider;
|
|
5587
5594
|
async getHeaders() {
|
|
5588
5595
|
const token = await this.tokenProvider.getToken();
|
|
5589
5596
|
return {
|
|
@@ -5597,6 +5604,7 @@ var StaticTokenProvider = class {
|
|
|
5597
5604
|
constructor(token) {
|
|
5598
5605
|
this.token = token;
|
|
5599
5606
|
}
|
|
5607
|
+
token;
|
|
5600
5608
|
getToken() {
|
|
5601
5609
|
return this.token;
|
|
5602
5610
|
}
|
|
@@ -5640,9 +5648,9 @@ var HttpClient = class {
|
|
|
5640
5648
|
let attempt = 0;
|
|
5641
5649
|
let lastError;
|
|
5642
5650
|
while (true) {
|
|
5651
|
+
const controller = new AbortController();
|
|
5652
|
+
const timeout = setTimeout(() => controller.abort(), this.timeout);
|
|
5643
5653
|
try {
|
|
5644
|
-
const controller = new AbortController();
|
|
5645
|
-
const timeout = setTimeout(() => controller.abort(), this.timeout);
|
|
5646
5654
|
const authHeaders = await this.authStrategy?.getHeaders();
|
|
5647
5655
|
const response = await fetch(`${this.baseUrl}${path2}`, {
|
|
5648
5656
|
method,
|
|
@@ -5656,17 +5664,19 @@ var HttpClient = class {
|
|
|
5656
5664
|
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
5657
5665
|
});
|
|
5658
5666
|
clearTimeout(timeout);
|
|
5659
|
-
const
|
|
5667
|
+
const parsedBody = await this.parseResponseBody(response);
|
|
5660
5668
|
if (!response.ok) {
|
|
5669
|
+
const payload = parsedBody;
|
|
5661
5670
|
throw new AppError(
|
|
5662
|
-
|
|
5671
|
+
payload?.message ?? response.statusText ?? "HTTP request failed",
|
|
5663
5672
|
response.status,
|
|
5664
5673
|
{
|
|
5665
|
-
code:
|
|
5674
|
+
code: payload?.code ?? "HTTP_REQUEST_FAILED",
|
|
5666
5675
|
details: {
|
|
5667
5676
|
service: this.serviceName,
|
|
5668
5677
|
method,
|
|
5669
|
-
path: path2
|
|
5678
|
+
path: path2,
|
|
5679
|
+
status: response.status
|
|
5670
5680
|
}
|
|
5671
5681
|
}
|
|
5672
5682
|
);
|
|
@@ -5675,8 +5685,9 @@ var HttpClient = class {
|
|
|
5675
5685
|
logger.info(
|
|
5676
5686
|
`[${this.serviceName}]` + (correlationId2 ? ` [${correlationId2}]` : "") + ` ${method} ${path2}`
|
|
5677
5687
|
);
|
|
5678
|
-
return
|
|
5688
|
+
return parsedBody;
|
|
5679
5689
|
} catch (error) {
|
|
5690
|
+
clearTimeout(timeout);
|
|
5680
5691
|
lastError = error;
|
|
5681
5692
|
if (this.retryPolicy.shouldRetry(attempt, error)) {
|
|
5682
5693
|
const delay = this.retryPolicy.getDelay(attempt, error);
|
|
@@ -5697,6 +5708,31 @@ var HttpClient = class {
|
|
|
5697
5708
|
);
|
|
5698
5709
|
throw lastError;
|
|
5699
5710
|
}
|
|
5711
|
+
async parseResponseBody(response) {
|
|
5712
|
+
if (response.status === 204) {
|
|
5713
|
+
return null;
|
|
5714
|
+
}
|
|
5715
|
+
const responseLike = response;
|
|
5716
|
+
const contentType = response.headers?.get?.("content-type") ?? "";
|
|
5717
|
+
if (contentType.includes("application/json") && typeof responseLike.json === "function") {
|
|
5718
|
+
return responseLike.json();
|
|
5719
|
+
}
|
|
5720
|
+
if (typeof responseLike.json === "function") {
|
|
5721
|
+
try {
|
|
5722
|
+
return await responseLike.json();
|
|
5723
|
+
} catch {
|
|
5724
|
+
}
|
|
5725
|
+
}
|
|
5726
|
+
if (typeof responseLike.text === "function") {
|
|
5727
|
+
const text = await responseLike.text();
|
|
5728
|
+
return {
|
|
5729
|
+
message: text || response.statusText || "HTTP request failed"
|
|
5730
|
+
};
|
|
5731
|
+
}
|
|
5732
|
+
return {
|
|
5733
|
+
message: response.statusText || "HTTP request failed"
|
|
5734
|
+
};
|
|
5735
|
+
}
|
|
5700
5736
|
sleep(ms) {
|
|
5701
5737
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5702
5738
|
}
|