@heliyos/heliyos-api-core 1.0.53 → 1.0.55

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/dist/app.js CHANGED
@@ -56,10 +56,6 @@ const coreApp = (app, routes, options) => __awaiter(void 0, void 0, void 0, func
56
56
  const PORT = process.env.PORT || 3030;
57
57
  // Create HTTP server.
58
58
  const server = http_1.default.createServer(newApp);
59
- // Keep sockets open long enough for client pools and Service Connect proxies
60
- server.keepAliveTimeout = 65000;
61
- server.headersTimeout = 66000;
62
- server.setTimeout(30000);
63
59
  // Initialize mongoose database connections
64
60
  yield (0, mongoose_1.initializeDatabase)();
65
61
  // Graceful shutdown handler
package/dist/axios.js CHANGED
@@ -5,10 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.coreAxios = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
+ const axios_retry_1 = __importDefault(require("axios-retry"));
8
9
  const logger_1 = require("./logger");
9
10
  const http_1 = __importDefault(require("http"));
10
11
  const https_1 = __importDefault(require("https"));
11
- const axios_retry_1 = __importDefault(require("axios-retry"));
12
12
  const config = {
13
13
  withCredentials: true,
14
14
  };
@@ -68,21 +68,11 @@ const httpsAgent = new https_1.default.Agent({
68
68
  // Axios server configs
69
69
  const servers = {
70
70
  // Auth server
71
- authServer: (0, axios_retry_1.default)(axios_1.default.create(Object.assign(Object.assign({}, config), { baseURL: process.env.BASE_URL_AUTH_SERVER, auth: {
71
+ authServer: axios_1.default.create(Object.assign(Object.assign({}, config), { baseURL: process.env.BASE_URL_AUTH_SERVER, auth: {
72
72
  username: "auth",
73
73
  password: process.env.SECRET_OF_AUTH_SERVER,
74
74
  }, httpAgent,
75
- httpsAgent })), {
76
- retries: 3,
77
- retryDelay: axios_retry_1.default.exponentialDelay,
78
- shouldResetTimeout: true,
79
- retryCondition: (error) => {
80
- var _a;
81
- return axios_retry_1.default.isNetworkOrIdempotentRequestError(error) ||
82
- error.code === "ECONNRESET" ||
83
- ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 503;
84
- },
85
- }),
75
+ httpsAgent })),
86
76
  // Agent server
87
77
  agentServer: axios_1.default.create(Object.assign(Object.assign({}, config), { baseURL: process.env.BASE_URL_AGENT_SERVER, auth: {
88
78
  username: "agent",
@@ -98,6 +88,37 @@ const servers = {
98
88
  // Export axios plain object to call some third party external calls
99
89
  axios: axios_1.default,
100
90
  };
91
+ // Configure retry logic for all axios instances
92
+ const retryConfig = {
93
+ retries: 3, // Number of retry attempts
94
+ retryDelay: (retryCount) => {
95
+ // Exponential backoff: 1s, 2s, 4s
96
+ return Math.pow(2, retryCount) * 1000;
97
+ },
98
+ retryCondition: (error) => {
99
+ var _a, _b;
100
+ // Retry on network errors, 5xx errors, and specifically 503 errors
101
+ const isNetworkError = axios_retry_1.default.isNetworkError(error);
102
+ const isRetryableError = axios_retry_1.default.isRetryableError(error);
103
+ const is503Error = ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 503;
104
+ const isECONNRESET = error.code === 'ECONNRESET';
105
+ const isTimeout = error.code === 'ECONNABORTED' || error.code === 'ETIMEDOUT';
106
+ // Log retry attempts for debugging
107
+ if (isNetworkError || isRetryableError || is503Error || isECONNRESET || isTimeout) {
108
+ logger_1.logger.warn(`api-core:axios-retry:attempting-retry:error=${error.name}:${error.message}:code=${error.code}:status=${(_b = error.response) === null || _b === void 0 ? void 0 : _b.status}`);
109
+ }
110
+ return isNetworkError || isRetryableError || is503Error || isECONNRESET || isTimeout;
111
+ },
112
+ onRetry: (retryCount, error, requestConfig) => {
113
+ logger_1.logger.info(`api-core:axios-retry:retry-attempt=${retryCount}:url=${requestConfig.url}:method=${requestConfig.method}:error=${error.message}`);
114
+ },
115
+ };
116
+ // Apply retry configuration to all server instances
117
+ for (const server_name of Object.keys(servers)) {
118
+ if (server_name !== 'axios') { // Don't apply to the plain axios object
119
+ (0, axios_retry_1.default)(servers[server_name], retryConfig);
120
+ }
121
+ }
101
122
  // Apply error handler to response interceptors
102
123
  for (const server_name of Object.keys(servers)) {
103
124
  servers[server_name].interceptors.response.use((r) => r, handleAxiosError);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heliyos/heliyos-api-core",
3
- "version": "1.0.53",
3
+ "version": "1.0.55",
4
4
  "description": "Heliyos's core api functions and middlewares. Its a private package hosted on npm.",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {