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 service_auth_guard_1 = require("../authentication/guards/service-auth.guard");
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 = axios_1.default.create({
43
- baseURL: this.baseUrls[this.isProduction ? 0 : 1],
44
- headers: {
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) && ids.length > 50) {
114
- // Parallelize requests for each chunk; flatten the results into one array.
115
- const batchPromises = (0, itlab_functions_1.createChunks)(ids, 50).map((chunk) => {
116
- config.params.ids = chunk;
117
- return this.fetchResourceCollectionBatch(endpoint, config);
118
- });
119
- const results = await Promise.all(batchPromises);
120
- return results.flat();
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} inputValue - The raw value received from the request query string.
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(inputValue) {
26
- const inputValues = Array.isArray(inputValue) ? inputValue : [inputValue];
27
- return inputValues.filter((value) => (0, class_validator_1.isMongoId)(value)).map(String);
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 (!(0, class_validator_1.isArray)(value))
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
- const transformed = [value].flat().map((item) => {
15
- let str = String(item);
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
- return opts.unique ? [...new Set(transformed)] : transformed;
27
+ if (!opts.unique)
28
+ return transformedValue;
29
+ return Array.from(new Set(transformedValue));
23
30
  });
24
31
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "Timo Scheuermann",
5
5
  "email": "timo.scheuermann@sv-informatik.de"
6
6
  },
7
- "version": "2.16.18",
7
+ "version": "2.16.19",
8
8
  "type": "commonjs",
9
9
  "files": [
10
10
  "dist"