itlab-internal-services 2.16.18 → 2.16.19
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.
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.BaseHttpService = void 0;
|
|
7
4
|
const common_1 = require("@nestjs/common");
|
|
8
|
-
const axios_1 = __importDefault(require("axios"));
|
|
9
5
|
const class_validator_1 = require("class-validator");
|
|
10
6
|
const itlab_functions_1 = require("itlab-functions");
|
|
11
|
-
const
|
|
7
|
+
const functions_1 = require("../../functions");
|
|
12
8
|
/**
|
|
13
9
|
* BaseHttpService
|
|
14
10
|
*
|
|
@@ -39,12 +35,9 @@ class BaseHttpService {
|
|
|
39
35
|
this.logger = new common_1.Logger(`${this.serviceName}Service`);
|
|
40
36
|
this.isProduction = this.configService.get('NODE_ENV') === 'production';
|
|
41
37
|
// Initialize Axios with base URL dynamically selected per environment.
|
|
42
|
-
this.httpClient =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// Kubernetes internal authentication for secure service-to-service calls.
|
|
46
|
-
[service_auth_guard_1.SERVICE_AUTH_HEADER_KEY]: this.authenticationOptions.k8sToken,
|
|
47
|
-
},
|
|
38
|
+
this.httpClient = (0, functions_1.createInternalAxiosClient)({
|
|
39
|
+
baseUrl: this.baseUrls[this.isProduction ? 0 : 1],
|
|
40
|
+
k8sToken: this.authenticationOptions.k8sToken,
|
|
48
41
|
});
|
|
49
42
|
// Add a request interceptor to log outbound traffic before each request is sent.
|
|
50
43
|
this.httpClient.interceptors.request.use((config) => {
|
|
@@ -110,14 +103,19 @@ class BaseHttpService {
|
|
|
110
103
|
async fetchResourceCollection(endpoint, config = {}) {
|
|
111
104
|
var _a;
|
|
112
105
|
const ids = (_a = config.params) === null || _a === void 0 ? void 0 : _a.ids;
|
|
113
|
-
if (ids && Array.isArray(ids)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
106
|
+
if (ids && Array.isArray(ids)) {
|
|
107
|
+
if (ids.length === 0)
|
|
108
|
+
return [];
|
|
109
|
+
if (ids.length > 50) {
|
|
110
|
+
// Parallelize requests for each chunk; flatten the results into one array.
|
|
111
|
+
const batchPromises = (0, itlab_functions_1.createChunks)(ids, 50).map((chunk) => {
|
|
112
|
+
const chunkConfig = Object.assign({}, config);
|
|
113
|
+
chunkConfig.params.ids = chunk;
|
|
114
|
+
return this.fetchResourceCollectionBatch(endpoint, chunkConfig);
|
|
115
|
+
});
|
|
116
|
+
const results = await Promise.all(batchPromises);
|
|
117
|
+
return results.flat();
|
|
118
|
+
}
|
|
121
119
|
}
|
|
122
120
|
return this.fetchResourceCollectionBatch(endpoint, config);
|
|
123
121
|
}
|
|
@@ -19,12 +19,17 @@ class ParseMongoIdsPipe {
|
|
|
19
19
|
/**
|
|
20
20
|
* Converts the raw input value into an array of valid MongoDB ID strings.
|
|
21
21
|
*
|
|
22
|
-
* @param {unknown}
|
|
22
|
+
* @param {unknown} value - The raw value received from the request query string.
|
|
23
23
|
* @returns {string[]} - Array of valid MongoDB IDs; returns empty array if input is invalid.
|
|
24
24
|
*/
|
|
25
|
-
transform(
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
transform(value) {
|
|
26
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
27
|
+
value = Object.values(value);
|
|
28
|
+
}
|
|
29
|
+
if (!Array.isArray(value))
|
|
30
|
+
return undefined;
|
|
31
|
+
const mongoIds = value.filter((v) => (0, class_validator_1.isMongoId)(v)).map((v) => String(v));
|
|
32
|
+
return Array.from(new Set(mongoIds));
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
35
|
/**
|
|
@@ -8,9 +8,12 @@ const class_validator_1 = require("class-validator");
|
|
|
8
8
|
*/
|
|
9
9
|
function MongoIdsTransform() {
|
|
10
10
|
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
11
|
-
if (!
|
|
11
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
12
|
+
value = Object.values(value);
|
|
13
|
+
}
|
|
14
|
+
if (!Array.isArray(value))
|
|
12
15
|
return undefined;
|
|
13
|
-
const mongoIds = value.filter((v) => (0, class_validator_1.isMongoId)(v));
|
|
16
|
+
const mongoIds = value.filter((v) => (0, class_validator_1.isMongoId)(v)).map((v) => String(v));
|
|
14
17
|
return Array.from(new Set(mongoIds));
|
|
15
18
|
});
|
|
16
19
|
}
|
|
@@ -11,14 +11,21 @@ const class_transformer_1 = require("class-transformer");
|
|
|
11
11
|
*/
|
|
12
12
|
function StringArrayTransform(opts = {}) {
|
|
13
13
|
return (0, class_transformer_1.Transform)(({ value }) => {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
15
|
+
value = Object.values(value);
|
|
16
|
+
}
|
|
17
|
+
if (!Array.isArray(value))
|
|
18
|
+
return undefined;
|
|
19
|
+
const transformedValue = value.map((value) => {
|
|
20
|
+
let str = String(value);
|
|
16
21
|
if (opts.trim)
|
|
17
22
|
str = str.trim();
|
|
18
23
|
if (opts.lowercase)
|
|
19
24
|
str = str.toLowerCase();
|
|
20
25
|
return str;
|
|
21
26
|
});
|
|
22
|
-
|
|
27
|
+
if (!opts.unique)
|
|
28
|
+
return transformedValue;
|
|
29
|
+
return Array.from(new Set(transformedValue));
|
|
23
30
|
});
|
|
24
31
|
}
|