@machinemetrics/mm-erp-sdk 0.1.1-beta.1 → 0.1.1-beta.2

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 +1 @@
1
- {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/utils/http-client.ts"],"names":[],"mappings":"AAEA,qBAAa,SAAU,SAAQ,KAAK;IAGzB,MAAM,EAAE,MAAM;IACd,IAAI,CAAC,EAAE,MAAM;IACb,IAAI,CAAC,EAAE,OAAO;gBAHrB,OAAO,EAAE,MAAM,EACR,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,IAAI,CAAC,EAAE,OAAO,YAAA;CAKxB;AAED,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErE,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,UAAU,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;CAC3E;AAED,MAAM,WA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,GAAG,SAAS,CAAC;CAC3E;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU;CAGzD"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@machinemetrics/mm-erp-sdk",
3
3
  "description": "A library for syncing data between MachineMetrics and ERP systems",
4
- "version": "0.1.1-beta.1",
4
+ "version": "0.1.1-beta.2",
5
5
  "license": "MIT",
6
6
  "author": "machinemetrics",
7
7
  "main": "dist/mm-erp-sdk.js",
@@ -1,4 +1,5 @@
1
1
  import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from "axios";
2
+ import logger from "../services/reporting-service/logger";
2
3
 
3
4
  export class HTTPError extends Error {
4
5
  constructor(
@@ -79,10 +80,19 @@ class AxiosClient implements HTTPClient {
79
80
  params: config.params,
80
81
  };
81
82
 
83
+ logger.debug("HTTP request starting", {
84
+ url: config.url,
85
+ method: config.method,
86
+ baseURL: this.client.defaults.baseURL,
87
+ retryAttempts: this.retryAttempts
88
+ });
89
+
82
90
  let lastError: unknown;
83
91
  for (let attempt = 0; attempt <= this.retryAttempts; attempt++) {
84
92
  try {
93
+ logger.debug(`HTTP request attempt ${attempt + 1}/${this.retryAttempts + 1}`);
85
94
  const response = await this.client.request<T>(axiosConfig);
95
+ logger.debug("HTTP request succeeded", { status: response.status });
86
96
  return {
87
97
  data: response.data,
88
98
  status: response.status,
@@ -90,6 +100,15 @@ class AxiosClient implements HTTPClient {
90
100
  };
91
101
  } catch (error) {
92
102
  lastError = error;
103
+ logger.debug(`HTTP request attempt ${attempt + 1} failed`, {
104
+ errorType: typeof error,
105
+ errorConstructor: error?.constructor?.name,
106
+ isAxiosError: error instanceof AxiosError,
107
+ message: error instanceof Error ? error.message : String(error),
108
+ code: (error as any)?.code,
109
+ status: (error as any)?.response?.status
110
+ });
111
+
93
112
  // Don't retry on 4xx errors (client errors)
94
113
  if (
95
114
  error instanceof AxiosError &&
@@ -97,10 +116,13 @@ class AxiosClient implements HTTPClient {
97
116
  error.response.status >= 400 &&
98
117
  error.response.status < 500
99
118
  ) {
119
+ logger.debug("Not retrying due to 4xx client error");
100
120
  break;
101
121
  }
102
122
  // If this was the last attempt, don't wait
103
123
  if (attempt < this.retryAttempts) {
124
+ const waitTime = Math.pow(2, attempt) * 1000;
125
+ logger.debug(`Waiting ${waitTime}ms before retry`);
104
126
  // Exponential backoff: wait 2^attempt * 1000ms
105
127
  await new Promise((resolve) =>
106
128
  setTimeout(resolve, Math.pow(2, attempt) * 1000)
@@ -108,6 +130,7 @@ class AxiosClient implements HTTPClient {
108
130
  }
109
131
  }
110
132
  }
133
+ logger.debug("HTTP request failed after all retries, throwing error");
111
134
  throw this.handleError(lastError, config);
112
135
  }
113
136