@diia-inhouse/http 1.9.0 → 4.0.1

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.
Files changed (32) hide show
  1. package/LICENCE.md +59 -59
  2. package/dist/interfaces/{http.js → httpClient.js} +1 -1
  3. package/dist/interfaces/httpClient.js.map +1 -0
  4. package/dist/interfaces/index.js +1 -1
  5. package/dist/interfaces/index.js.map +1 -1
  6. package/dist/services/errors/index.js +8 -0
  7. package/dist/services/errors/index.js.map +1 -0
  8. package/dist/services/errors/operationError.js +13 -0
  9. package/dist/services/errors/operationError.js.map +1 -0
  10. package/dist/services/errors/requestError.js +15 -0
  11. package/dist/services/errors/requestError.js.map +1 -0
  12. package/dist/services/httpClient.js +205 -141
  13. package/dist/services/httpClient.js.map +1 -1
  14. package/dist/services/index.js +3 -1
  15. package/dist/services/index.js.map +1 -1
  16. package/dist/services/utils.js +22 -0
  17. package/dist/services/utils.js.map +1 -0
  18. package/dist/types/interfaces/deps.d.ts +3 -5
  19. package/dist/types/interfaces/httpClient.d.ts +73 -0
  20. package/dist/types/interfaces/index.d.ts +1 -1
  21. package/dist/types/services/errors/index.d.ts +2 -0
  22. package/dist/types/services/errors/operationError.d.ts +4 -0
  23. package/dist/types/services/errors/requestError.d.ts +5 -0
  24. package/dist/types/services/httpClient.d.ts +18 -15
  25. package/dist/types/services/index.d.ts +1 -1
  26. package/dist/types/services/utils.d.ts +4 -0
  27. package/package.json +40 -42
  28. package/dist/interfaces/http.js.map +0 -1
  29. package/dist/services/http.js +0 -200
  30. package/dist/services/http.js.map +0 -1
  31. package/dist/types/interfaces/http.d.ts +0 -16
  32. package/dist/types/services/http.d.ts +0 -23
@@ -1 +1 @@
1
- {"version":3,"file":"httpClient.js","sourceRoot":"","sources":["../../src/services/httpClient.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA4D;AAC5D,yCAAuG;AACvG,2CAA2E;AAC3E,uDAAiE;AAGjE,8DAA4B;AAC5B,mCA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,MAAM,EAAE,GAAG,SAAS,CAAC,CAAA;IAC7F,CAAC;IAEO,oBAAoB,CAAC,MAAkC;QAC3D,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,MAAM,CAAA;QAE3F,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,4BAAa,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,CAAC,CAAA;QAEhG,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,4CAA4C,UAAU,EAAE,EAAE,CAAC,CAAA;QAE/F,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CAAA;IAC7F,CAAC;IAEO,SAAS,CACb,UAAkB,EAClB,MAAqB,EACrB,OAAe,EACf,WAAmB,EACnB,SAAqB;QAErB,OAAO;YACH,MAAM;YACN,UAAU;YACV,MAAM,EAAE,IAAI,CAAC,iBAAiB;YAC9B,WAAW,EAAE,GAAG,OAAO,IAAI,WAAW,EAAE;YACxC,SAAS,EAAE,+BAAgB,CAAC,IAAI;YAChC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACtC,CAAA;IACL,CAAC;CACJ;AA9PD,8CA8PC"}
@@ -14,6 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./http"), exports);
17
+ exports.checkServerIdentity = void 0;
18
18
  __exportStar(require("./httpClient"), exports);
19
+ var utils_1 = require("./utils");
20
+ Object.defineProperty(exports, "checkServerIdentity", { enumerable: true, get: function () { return utils_1.checkServerIdentity; } });
19
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAsB;AAEtB,+CAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAA4B;AAE5B,iCAA6C;AAApC,4GAAA,mBAAmB,OAAA"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.waitAndRun = exports.sleep = void 0;
4
+ exports.checkServerIdentity = checkServerIdentity;
5
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
6
+ exports.sleep = sleep;
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ const waitAndRun = async (callback, ms) => {
9
+ await (0, exports.sleep)(ms);
10
+ return await callback();
11
+ };
12
+ exports.waitAndRun = waitAndRun;
13
+ function checkServerIdentity(hostFingerprint) {
14
+ return (host, cert) => {
15
+ const certFingerprint = cert.fingerprint256 || cert.fingerprint;
16
+ if (!hostFingerprint || hostFingerprint === certFingerprint) {
17
+ return;
18
+ }
19
+ return new Error(`Fingerprint for host ${host} does not match`);
20
+ };
21
+ }
22
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/services/utils.ts"],"names":[],"mappings":";;;AAWA,kDAUC;AAnBM,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AAAxF,QAAA,KAAK,SAAmF;AAErG,8DAA8D;AACvD,MAAM,UAAU,GAAG,KAAK,EAA6C,QAAW,EAAE,EAAU,EAA0B,EAAE;IAC3H,MAAM,IAAA,aAAK,EAAC,EAAE,CAAC,CAAA;IAEf,OAAO,MAAM,QAAQ,EAAE,CAAA;AAC3B,CAAC,CAAA;AAJY,QAAA,UAAU,cAItB;AAED,SAAgB,mBAAmB,CAAC,eAAuB;IACvD,OAAO,CAAC,IAAY,EAAE,IAA+B,EAAE,EAAE;QACrD,MAAM,eAAe,GAAW,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,WAAW,CAAA;QAEvE,IAAI,CAAC,eAAe,IAAI,eAAe,KAAK,eAAe,EAAE,CAAC;YAC1D,OAAM;QACV,CAAC;QAED,OAAO,IAAI,KAAK,CAAC,wBAAwB,IAAI,iBAAiB,CAAC,CAAA;IACnE,CAAC,CAAA;AACL,CAAC"}
@@ -1,6 +1,4 @@
1
- import { HttpClientService, HttpService } from '../services';
2
- export type HttpDeps = {
3
- httpService: HttpService;
4
- httpsService: HttpService;
5
- http?: HttpClientService;
1
+ import { HttpClientService } from '../services';
2
+ export type HttpDeps<TMetricLabel extends string> = {
3
+ http?: HttpClientService<TMetricLabel>;
6
4
  };
@@ -0,0 +1,73 @@
1
+ import { Agent as httpAgent } from 'node:http';
2
+ import { Agent as httpsAgent } from 'node:https';
3
+ import { Span } from '@opentelemetry/api';
4
+ import { AxiosResponse, ResponseType } from 'axios';
5
+ import { ErrorType } from '@diia-inhouse/errors';
6
+ import { HttpMethod, HttpStatusCode } from '@diia-inhouse/types';
7
+ import { OperationError, RequestError } from '../services/errors';
8
+ export type ReadonlyQuery = Readonly<object>;
9
+ /**
10
+ * Enforces that T is a string literal or union of literals, not the broad `string` type.
11
+ * Resolves to `never` if T is exactly `string`, causing a compile error.
12
+ */
13
+ type LowCardinality<T extends string> = string extends T ? never : T;
14
+ export interface RequestOptions<TMetricLabel extends string> {
15
+ baseUrl?: string;
16
+ timeout?: number;
17
+ retries?: number;
18
+ retryInterval?: number;
19
+ query?: ReadonlyQuery;
20
+ headers?: Record<string, string>;
21
+ body?: unknown;
22
+ errorType?: ErrorType;
23
+ responseType?: ResponseType;
24
+ httpsAgent?: httpsAgent;
25
+ httpAgent?: httpAgent;
26
+ /**
27
+ * Label used to separate metrics on the same destination host.
28
+ *
29
+ * **Must have low cardinality** — use a finite set of known values, not dynamic strings
30
+ * like URLs, IDs, or user input. High-cardinality labels cause metric explosion and
31
+ * degrade monitoring system performance.
32
+ *
33
+ * Define as a string union type to enforce allowed values at compile time:
34
+ * @example
35
+ * type MyMetricLabel = 'getUserProfile' | 'createOrder' | 'validateDocument'
36
+ * const options: RequestOptions<MyMetricLabel> = { metricLabel: 'getUserProfile', ... }
37
+ */
38
+ metricLabel: LowCardinality<TMetricLabel>;
39
+ }
40
+ export interface FullRequestOptions<TMetricLabel extends string> extends RequestOptions<TMetricLabel> {
41
+ path: string;
42
+ method: HttpMethod;
43
+ }
44
+ export interface SuccessfulResponse<T> {
45
+ isOk: true;
46
+ statusCode: HttpStatusCode;
47
+ headers?: Record<string, string>;
48
+ body: T;
49
+ }
50
+ export interface FailureResponse<TError> {
51
+ isOk: false;
52
+ statusCode: HttpStatusCode;
53
+ headers?: Record<string, string>;
54
+ body: TError | undefined;
55
+ }
56
+ export type HttpClientResponse<TResponse, TError = unknown> = SuccessfulResponse<TResponse> | FailureResponse<TError>;
57
+ export interface ObserveRequestBaseParams {
58
+ statusCode: number;
59
+ retryCount: number;
60
+ startTime: bigint;
61
+ span: Span;
62
+ baseUrl: string;
63
+ metricLabel: string;
64
+ }
65
+ export interface ObserveRequestFailedParams extends ObserveRequestBaseParams {
66
+ errorType: ErrorType;
67
+ }
68
+ export interface RequestHelperResponse<TResponse> {
69
+ response?: AxiosResponse<TResponse>;
70
+ error?: RequestError | OperationError;
71
+ retryCount: number;
72
+ }
73
+ export {};
@@ -1,2 +1,2 @@
1
1
  export * from './deps';
2
- export * from './http';
2
+ export * from './httpClient';
@@ -0,0 +1,2 @@
1
+ export { OperationError } from './operationError';
2
+ export { RequestError } from './requestError';
@@ -0,0 +1,4 @@
1
+ import { RequestError } from './requestError';
2
+ export declare class OperationError extends RequestError {
3
+ constructor(message: string, originalError: Error);
4
+ }
@@ -0,0 +1,5 @@
1
+ export declare class RequestError extends Error {
2
+ readonly statusCode: number;
3
+ readonly originalError: Error;
4
+ constructor(message: string, statusCode: number, originalError: Error);
5
+ }
@@ -1,18 +1,21 @@
1
- /// <reference types="node" />
2
- import { RequestOptions } from 'node:https';
1
+ import { MetricsService } from '@diia-inhouse/diia-metrics';
3
2
  import { Logger } from '@diia-inhouse/types';
4
- import { HttpServiceResponse } from '../interfaces/http';
5
- export declare class HttpClientService {
3
+ import { HttpClientResponse, RequestOptions } from '../interfaces/httpClient';
4
+ export declare class HttpClientService<TMetricLabel extends string> {
6
5
  private logger;
7
- private readonly binaryMimeTypes;
8
- private readonly binaryMimeTypesPrefixes;
9
- constructor(logger: Logger);
10
- get<T>(options: RequestOptions, hostFingerprint?: string): Promise<HttpServiceResponse<T>>;
11
- post<T>(options: RequestOptions, hostFingerprint?: string, body?: unknown): Promise<HttpServiceResponse<T>>;
12
- put<T>(options: RequestOptions, hostFingerprint?: string, body?: unknown): Promise<HttpServiceResponse<T>>;
13
- delete<T>(options: RequestOptions, hostFingerprint?: string, body?: unknown): Promise<HttpServiceResponse<T>>;
14
- private makeRequest;
15
- private isJsonContentType;
16
- private isBinaryContentType;
17
- private setCheckServerIdentity;
6
+ private metrics;
7
+ private readonly systemServiceName;
8
+ private readonly timeout;
9
+ private readonly baseUrl;
10
+ constructor(logger: Logger, metrics: MetricsService, systemServiceName: string, timeout?: number, baseUrl?: string);
11
+ get<TResponse, TError>(path: string, opts: RequestOptions<TMetricLabel>): Promise<HttpClientResponse<TResponse, TError>>;
12
+ post<TResponse, TError>(path: string, opts: RequestOptions<TMetricLabel>): Promise<HttpClientResponse<TResponse, TError>>;
13
+ put<TResponse, TError>(path: string, opts: RequestOptions<TMetricLabel>): Promise<HttpClientResponse<TResponse, TError>>;
14
+ delete<TResponse, TError>(path: string, opts: RequestOptions<TMetricLabel>): Promise<HttpClientResponse<TResponse, TError>>;
15
+ patch<TResponse, TError>(path: string, opts: RequestOptions<TMetricLabel>): Promise<HttpClientResponse<TResponse, TError>>;
16
+ private request;
17
+ private requestHelper;
18
+ private observeSuccessRequest;
19
+ private observeFailedRequest;
20
+ private getLabels;
18
21
  }
@@ -1,2 +1,2 @@
1
- export * from './http';
2
1
  export * from './httpClient';
2
+ export { checkServerIdentity } from './utils';
@@ -0,0 +1,4 @@
1
+ import { PeerCertificateWithSHA256 } from '@diia-inhouse/types';
2
+ export declare const sleep: (ms: number) => Promise<void>;
3
+ export declare const waitAndRun: <T extends (...params: []) => Promise<any>>(callback: T, ms: number) => Promise<ReturnType<T>>;
4
+ export declare function checkServerIdentity(hostFingerprint: string): (host: string, cert: PeerCertificateWithSHA256) => Error | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diia-inhouse/http",
3
- "version": "1.9.0",
3
+ "version": "4.0.1",
4
4
  "description": "Wrapper to make http requests",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -11,47 +11,64 @@
11
11
  "dist"
12
12
  ],
13
13
  "engines": {
14
- "node": ">=13.14.0"
14
+ "node": ">=22"
15
15
  },
16
16
  "scripts": {
17
17
  "prebuild": "rimraf dist",
18
18
  "build": "tsc",
19
19
  "semantic-release": "semantic-release",
20
20
  "start": "npm run build && node dist/index.js",
21
- "lint": "eslint --ext .ts . && prettier --check .",
22
- "lint-fix": "eslint '*/**/*.{js,ts}' --fix && prettier --write .",
21
+ "lint": "eslint . && prettier --check .",
22
+ "lint-fix": "eslint --fix . && prettier --write .",
23
23
  "lint:lockfile": "lockfile-lint --path package-lock.json --allowed-hosts registry.npmjs.org --validate-https",
24
24
  "prepare": "npm run build",
25
- "test": "jest",
25
+ "test": "tsc --project tests/tsconfig.json --noEmit && vitest run",
26
+ "test:watch": "vitest watch",
26
27
  "test:unit": "npm run test --selectProjects unit --",
27
28
  "test:coverage": "npm run test --coverage --",
28
29
  "find-circulars": "madge --circular --extensions ts ./"
29
30
  },
30
31
  "dependencies": {
31
32
  "await-to-js": "3.0.0",
32
- "lodash": "4.17.21",
33
- "qs": "6.11.2"
33
+ "axios": "1.13.6",
34
+ "lodash": "4.17.23",
35
+ "qs": "6.15.0"
34
36
  },
35
37
  "peerDependencies": {
38
+ "@diia-inhouse/diia-metrics": ">=3.14.2",
36
39
  "@diia-inhouse/errors": ">=1.0.0",
37
- "@diia-inhouse/types": ">=1.0.0"
40
+ "@diia-inhouse/types": ">=1.0.0",
41
+ "@opentelemetry/api": ">=1.9.0",
42
+ "@opentelemetry/semantic-conventions": ">=1.28.0"
38
43
  },
39
44
  "devDependencies": {
40
- "@commitlint/cli": "17.6.5",
41
- "@diia-inhouse/configs": "1.31.1",
42
- "@diia-inhouse/diia-logger": "2.15.0",
43
- "@diia-inhouse/errors": "1.9.0",
44
- "@diia-inhouse/eslint-config": "5.1.0",
45
- "@diia-inhouse/test": "6.3.0",
46
- "@diia-inhouse/types": "6.24.0",
47
- "@types/lodash": "4.14.202",
48
- "@types/node": "20.2.5",
49
- "eslint-plugin-prettier": "5.1.3",
50
- "lockfile-lint": "4.10.1",
51
- "madge": "7.0.0",
52
- "nock": "13.3.1",
53
- "rimraf": "5.0.7",
54
- "semantic-release": "21.1.2"
45
+ "@commitlint/cli": "19.7.1",
46
+ "@diia-inhouse/configs": "6.1.1",
47
+ "@diia-inhouse/diia-logger": "3.16.4",
48
+ "@diia-inhouse/diia-metrics": "6.5.1",
49
+ "@diia-inhouse/errors": "1.18.3",
50
+ "@diia-inhouse/eslint-config": "8.4.0",
51
+ "@diia-inhouse/test": "7.3.3",
52
+ "@diia-inhouse/types": "11.5.0",
53
+ "@opentelemetry/api": "1.9.0",
54
+ "@opentelemetry/semantic-conventions": "1.40.0",
55
+ "@types/lodash": "4.17.24",
56
+ "@types/node": "25.3.3",
57
+ "@vitest/coverage-v8": "4.0.18",
58
+ "@vitest/ui": "4.0.18",
59
+ "eslint": "9.31.0",
60
+ "eslint-plugin-prettier": "5.2.3",
61
+ "lockfile-lint": "4.14.1",
62
+ "madge": "8.0.0",
63
+ "nock": "14.0.11",
64
+ "rimraf": "6.1.3",
65
+ "semantic-release": "24.2.7",
66
+ "vite-tsconfig-paths": "6.1.1",
67
+ "vitest": "4.0.18",
68
+ "vitest-mock-extended": "3.1.0"
69
+ },
70
+ "overrides": {
71
+ "form-data": "^4.0.4"
55
72
  },
56
73
  "release": {
57
74
  "extends": "@diia-inhouse/configs/dist/semantic-release/package",
@@ -62,25 +79,6 @@
62
79
  "commitlint": {
63
80
  "extends": "@diia-inhouse/configs/dist/commitlint"
64
81
  },
65
- "eslintConfig": {
66
- "extends": "@diia-inhouse/eslint-config",
67
- "overrides": [
68
- {
69
- "files": [
70
- "*.ts"
71
- ],
72
- "parserOptions": {
73
- "project": [
74
- "./tsconfig.json",
75
- "./tests/tsconfig.json"
76
- ]
77
- }
78
- }
79
- ]
80
- },
81
- "jest": {
82
- "preset": "@diia-inhouse/configs/dist/jest"
83
- },
84
82
  "prettier": "@diia-inhouse/eslint-config/prettier",
85
83
  "madge": {
86
84
  "tsConfig": "./tsconfig.json"
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/interfaces/http.ts"],"names":[],"mappings":""}
@@ -1,200 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.HttpService = void 0;
7
- /* eslint-disable n/no-unsupported-features/node-builtins */
8
- const node_http_1 = require("node:http");
9
- const node_https_1 = require("node:https");
10
- const node_querystring_1 = require("node:querystring");
11
- const await_to_js_1 = __importDefault(require("await-to-js"));
12
- const lodash_1 = require("lodash");
13
- const errors_1 = require("@diia-inhouse/errors");
14
- const types_1 = require("@diia-inhouse/types");
15
- /**
16
- * @deprecated use HttpClientService
17
- */
18
- class HttpService {
19
- logger;
20
- // eslint-disable-next-line @typescript-eslint/ban-types
21
- requestFn;
22
- binaryMimeTypes = ['application/pdf', 'application/p7s'];
23
- binaryMimeTypesPrefixes = ['image/'];
24
- constructor(logger, protocol) {
25
- this.logger = logger;
26
- this.requestFn = protocol === types_1.HttpProtocol.Http ? node_http_1.request : node_https_1.request;
27
- }
28
- async get(options, hostFingerprint) {
29
- this.setMethod(options, types_1.HttpMethod.GET);
30
- this.setCheckServerIdentity(options, hostFingerprint);
31
- return await (0, await_to_js_1.default)(this.makeRequest(options));
32
- }
33
- async post(options, hostFingerprint, body) {
34
- this.setMethod(options, types_1.HttpMethod.POST);
35
- this.setCheckServerIdentity(options, hostFingerprint);
36
- return await (0, await_to_js_1.default)(this.makeRequest(options, body));
37
- }
38
- async delete(options, hostFingerprint, body) {
39
- this.setMethod(options, types_1.HttpMethod.DELETE);
40
- this.setCheckServerIdentity(options, hostFingerprint);
41
- return await (0, await_to_js_1.default)(this.makeRequest(options, body));
42
- }
43
- async put(options, hostFingerprint, body) {
44
- this.setMethod(options, types_1.HttpMethod.PUT);
45
- this.setCheckServerIdentity(options, hostFingerprint);
46
- return await (0, await_to_js_1.default)(this.makeRequest(options, body));
47
- }
48
- setMethod(options, method) {
49
- options.method = method;
50
- }
51
- setCheckServerIdentity(options, hostFingerprint) {
52
- if (!hostFingerprint) {
53
- return;
54
- }
55
- const checkServerIdentity = (host, cert) => {
56
- const certFingerprint = cert.fingerprint256 || cert.fingerprint;
57
- this.logger.info(`Checking fingerprint for host: ${host}, fingerprint is ${certFingerprint}`);
58
- if (!hostFingerprint || hostFingerprint === certFingerprint) {
59
- this.logger.info('Fingerprint validated successfully');
60
- return;
61
- }
62
- this.logger.info('Failed to validate fingerprint');
63
- return new Error(`Fingerprint for host ${host} does not match`);
64
- };
65
- if (options.agent instanceof node_https_1.Agent) {
66
- ;
67
- options.agent.options.checkServerIdentity = checkServerIdentity;
68
- }
69
- else {
70
- options.agent = new node_https_1.Agent({ checkServerIdentity });
71
- }
72
- }
73
- makeRequest(options, body) {
74
- const { maxRetries = 0, retryDelay = 0, ...requestOptions } = options;
75
- return new Promise((resolve, reject) => {
76
- let retries = 0;
77
- const performRequest = () => {
78
- try {
79
- const data = [];
80
- const request = this.requestFn(requestOptions, (response) => {
81
- if (!this.isBinaryContentType(response.headers)) {
82
- response.setEncoding('utf8');
83
- }
84
- response.on('data', (chunk) => {
85
- data.push(chunk);
86
- });
87
- response.on('end', () => {
88
- let parsedData;
89
- const res = (0, lodash_1.cloneDeep)(response);
90
- const { statusCode = '' } = res;
91
- const isSuccessStatusCode = /2\d{2}/.test(statusCode.toString());
92
- res.data = res.data || undefined;
93
- if (data.length === 0) {
94
- this.logger.info('No data in response', { statusCode });
95
- if (!isSuccessStatusCode) {
96
- if (retries < maxRetries) {
97
- retries++;
98
- return setTimeout(performRequest, retryDelay);
99
- }
100
- else {
101
- return reject(res);
102
- }
103
- }
104
- return resolve(res);
105
- }
106
- try {
107
- if (this.isJsonContentType(response.headers)) {
108
- parsedData = JSON.parse(data.join(''));
109
- res.data = parsedData;
110
- }
111
- else if (this.isBinaryContentType(response.headers)) {
112
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
113
- res.data = Buffer.concat(data);
114
- }
115
- else {
116
- res.data = data.join('');
117
- }
118
- }
119
- catch (err) {
120
- this.logger.error(`Failed to parse data: ${data}`);
121
- if (err instanceof Error) {
122
- return reject(err);
123
- }
124
- }
125
- if (!isSuccessStatusCode) {
126
- if (retries < maxRetries) {
127
- retries++;
128
- return setTimeout(performRequest, retryDelay);
129
- }
130
- else {
131
- return reject(res);
132
- }
133
- }
134
- return resolve(res);
135
- });
136
- });
137
- request.on('error', (err) => {
138
- if (retries < maxRetries) {
139
- retries++;
140
- setTimeout(performRequest, retryDelay);
141
- }
142
- else {
143
- reject(err);
144
- }
145
- });
146
- request.on('timeout', () => {
147
- const message = 'Failed due timeout reason';
148
- this.logger.error(message);
149
- if (retries < maxRetries) {
150
- retries++;
151
- setTimeout(performRequest, retryDelay);
152
- }
153
- else {
154
- reject(new errors_1.RequestTimeoutError(message));
155
- }
156
- });
157
- request.on('abort', () => {
158
- const message = 'Failed due abort reason';
159
- this.logger.error(message);
160
- if (retries < maxRetries) {
161
- retries++;
162
- setTimeout(performRequest, retryDelay);
163
- }
164
- else {
165
- reject(new errors_1.ServiceUnavailableError(message));
166
- }
167
- });
168
- if (body) {
169
- const preparedBody = typeof body === 'string' ? body : (0, node_querystring_1.stringify)(body);
170
- request.write(preparedBody);
171
- }
172
- request.end();
173
- }
174
- catch (err) {
175
- if (err instanceof Error) {
176
- return reject(err);
177
- }
178
- }
179
- };
180
- performRequest();
181
- });
182
- }
183
- isJsonContentType(headers) {
184
- const contentTypeHeader = headers['content-type'];
185
- if (!contentTypeHeader) {
186
- return false;
187
- }
188
- return /^application\/json/.test(contentTypeHeader);
189
- }
190
- isBinaryContentType(headers) {
191
- const contentTypeHeader = headers['content-type'];
192
- if (!contentTypeHeader) {
193
- return false;
194
- }
195
- return (this.binaryMimeTypes.includes(contentTypeHeader) ||
196
- this.binaryMimeTypesPrefixes.some((mimeTypePrefix) => contentTypeHeader.startsWith(mimeTypePrefix)));
197
- }
198
- }
199
- exports.HttpService = HttpService;
200
- //# sourceMappingURL=http.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/services/http.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA4D;AAC5D,yCAAuG;AACvG,2CAA2D;AAC3D,uDAAiE;AAGjE,8DAA4B;AAC5B,mCAAkC;AAElC,iDAAmF;AACnF,+CAAiG;AAIjG;;GAEG;AACH,MAAa,WAAW;IASC;IARrB,wDAAwD;IAChD,SAAS,CAAU;IAEV,eAAe,GAAa,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAA;IAElE,uBAAuB,GAAa,CAAC,QAAQ,CAAC,CAAA;IAE/D,YACqB,MAAc,EAC/B,QAAsB;QADL,WAAM,G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AO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,4BAAS,EAAC,IAAI,CAAC,CAAA;wBAE9E,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;oBAC/B,CAAC;oBAED,OAAO,CAAC,GAAG,EAAE,CAAA;gBACjB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACX,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;wBACvB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;oBACtB,CAAC;gBACL,CAAC;YACL,CAAC,CAAA;YAED,cAAc,EAAE,CAAA;QACpB,CAAC,CACJ,CAAA;IACL,CAAC;IAEO,iBAAiB,CAAC,OAA4B;QAClD,MAAM,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;QAEjD,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACrB,OAAO,KAAK,CAAA;QAChB,CAAC;QAED,OAAO,oBAAoB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;IACvD,CAAC;IAEO,mBAAmB,CAAC,OAA4B;QACpD,MAAM,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;QAEjD,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACrB,OAAO,KAAK,CAAA;QAChB,CAAC;QAED,OAAO,CACH,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,iBAAiB,CAAC;YAChD,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,iBAAiB,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,CACtG,CAAA;IACL,CAAC;CACJ;AAjPD,kCAiPC"}
@@ -1,16 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { IncomingMessage } from 'node:http';
4
- import { RequestOptions } from 'node:https';
5
- import { HttpStatusCode } from '@diia-inhouse/types';
6
- export interface HttpServiceResponseResult<T = any> {
7
- data?: T;
8
- headers?: IncomingMessage['headers'];
9
- statusCode?: HttpStatusCode;
10
- statusMessage?: string;
11
- }
12
- export type HttpServiceResponse<T = any> = [Error & HttpServiceResponseResult<T>, undefined] | [null, HttpServiceResponseResult];
13
- export interface ExtendedRequestOptions extends RequestOptions {
14
- maxRetries?: number;
15
- retryDelay?: number;
16
- }