chargebee 3.6.1 → 3.8.0-beta.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,37 @@
1
+ ### v3.7.0 (2025-05-15)
2
+ * * *
3
+
4
+ ### New Resources
5
+ * UsageFile has been added.
6
+
7
+ ### Input Parameter
8
+ * discount[apply_on] has been made optional from required in Estimate#CreateSubItemEstimateRequest.
9
+ * discount[apply_on] has been made optional from required in Estimate#CreateSubItemForCustomerEstimateRequest.
10
+ * discount[apply_on] has been made optional from required in Estimate#UpdateSubscriptionForItemsRequest.
11
+ * discount[apply_on] has been made optional from required in HostedPage#CheckoutNewForItemsRequest.
12
+ * discount[apply_on] has been made optional from required in HostedPage#CheckoutNewForItemsRequest.
13
+ * discount[apply_on] has been made optional from required in HostedPage#CheckoutNewForItemsRequest.
14
+ * discount[apply_on] has been made optional from required in HostedPage#CheckoutNewForItemsRequest.
15
+ * discount[apply_on] has been made optional from required in PricingPageSession#CheckoutNewForItemsRequest.
16
+ * discount[apply_on] has been made optional from required in PricingPageSession#CreateForExistingSubscriptionRequest.
17
+ * discount[apply_on] has been made optional from required in Quote#CreateSubItemsForCustomerQuoteRequest.
18
+ * discount[apply_on] has been made optional from required in Quote#EditCreateSubCustomerQuoteForItemsRequest.
19
+ * discount[apply_on] has been made optional from required in Quote#UpdateSubscriptionQuoteForItemsRequest.
20
+ * discount[apply_on] has been made optional from required in Quote#EditUpdateSubscriptionQuoteForItemsRequest.
21
+ * discount[apply_on] has been made optional from required in Subscription#CreateWithItemsRequest.
22
+ * discount[apply_on] has been made optional from required in Subscription#UpdateForItemsRequest.
23
+ * discount[apply_on] has been made optional from required in Subscription#ImportForItemsRequest.
24
+ * line_item_addresses[] has been added to Invoice#ImportInvoiceRequest.
25
+ * source has been added to OmnichannelSubscription#OmnichannelSubscriptionListRequest.
26
+
27
+ ### Attributes:
28
+ * swift_code has been made optional from required in VirtualBankAccount.
29
+
30
+ ### Enum Attributes:
31
+ * OMNICHANNEL_SUBSCRIPTION_ITEM_PAUSED has been added to EventTypeEnum.
32
+ * PAUSED has been added to OmnichannelSubscriptionItem#StatusEnum.
33
+ * MERCHANT_REVOKED has been added to OmnichannelSubscriptionItem#CancellationReasonEnum.
34
+
1
35
  ### v3.6.1 (2025-04-25)
2
36
  * * *
3
37
 
package/README.md CHANGED
@@ -143,6 +143,72 @@ const chargebeeSiteEU = new Chargebee({
143
143
 
144
144
  An attribute `api_version` is added to the [Event](https://apidocs.chargebee.com/docs/api/events) resource, which indicates the API version based on which the event content is structured. In your webhook servers, ensure this `api_version` is the same as the [API version](https://apidocs.chargebee.com/docs/api#versions) used by your webhook server's client library.
145
145
 
146
+ ### Retry Handling
147
+
148
+ Chargebee's SDK includes built-in retry logic to handle temporary network issues and server-side errors. This feature is **disabled by default** but can be **enabled when needed**.
149
+
150
+ #### Key features include:
151
+
152
+ - **Automatic retries for specific HTTP status codes**: Retries are automatically triggered for status codes `500`, `502`, `503`, and `504`.
153
+ - **Exponential backoff**: Retry delays increase exponentially to prevent overwhelming the server.
154
+ - **Rate limit management**: If a `429 Too Many Requests` response is received with a `Retry-After` header, the SDK waits for the specified duration before retrying.
155
+ > *Note: Exponential backoff and max retries do not apply in this case.*
156
+ - **Customizable retry behavior**: Retry logic can be configured using the `retryConfig` parameter in the environment configuration.
157
+
158
+ #### Example: Customizing Retry Logic
159
+
160
+ You can enable and configure the retry logic by passing a `retryConfig` object when initializing the Chargebee environment:
161
+
162
+ ```typescript
163
+ import Chargebee from 'chargebee';
164
+
165
+ const chargebee = new Chargebee({
166
+ site: "{{site}}",
167
+ apiKey: "{{api-key}}",
168
+ retryConfig: {
169
+ enabled: true, // Enable retry logic
170
+ maxRetries: 5, // Maximum number of retries
171
+ delayMs: 300, // Initial delay between retries in milliseconds
172
+ retryOn: [500, 502, 503, 504], // HTTP status codes to retry on
173
+ },
174
+ });
175
+
176
+ try {
177
+ const { customer } = await chargebee.customer.create({
178
+ email: "john@test.com",
179
+ });
180
+ console.log("Customer created:", customer);
181
+ } catch (err) {
182
+ console.error("Request failed after retries:", err);
183
+ }
184
+ ```
185
+
186
+ #### Example: Rate Limit retry logic
187
+
188
+ You can enable and configure the retry logic for rate-limit by passing a `retryConfig` object when initializing the Chargebee environment:
189
+
190
+ ```typescript
191
+ import Chargebee from 'chargebee';
192
+
193
+ const chargebee = new Chargebee({
194
+ site: "{{site}}",
195
+ apiKey: "{{api-key}}",
196
+ retryConfig: {
197
+ enabled: true,
198
+ retryOn: [429],
199
+ },
200
+ });
201
+
202
+ try {
203
+ const { customer } = await chargebee.customer.create({
204
+ email: "john@test.com",
205
+ });
206
+ console.log("Customer created:", customer);
207
+ } catch (err) {
208
+ console.error("Request failed after retries:", err);
209
+ }
210
+ ```
211
+
146
212
  ## Feedback
147
213
 
148
214
  If you find any bugs or have any questions / feedback, open an issue in this repository or reach out to us on dx@chargebee.com
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RequestWrapper = void 0;
4
- const util_js_1 = require("./util.js");
5
- const coreCommon_js_1 = require("./coreCommon.js");
4
+ const util_1 = require("./util");
5
+ const coreCommon_1 = require("./coreCommon");
6
6
  const node_buffer_1 = require("node:buffer");
7
7
  class RequestWrapper {
8
8
  constructor(args, apiCall, envArg) {
@@ -23,73 +23,134 @@ class RequestWrapper {
23
23
  }
24
24
  return idParam;
25
25
  }
26
- request() {
26
+ static parseRetryAfter(retryAfter) {
27
+ if (!retryAfter)
28
+ return null;
29
+ const seconds = parseInt(retryAfter, 10);
30
+ if (!isNaN(seconds)) {
31
+ return seconds * 1000;
32
+ }
33
+ return null;
34
+ }
35
+ async request() {
27
36
  let env = {};
28
- (0, util_js_1.extend)(true, env, this.envArg);
37
+ (0, util_1.extend)(true, env, this.envArg);
38
+ const retryConfig = Object.assign({ enabled: false, maxRetries: 3, delayMs: 200, retryOn: [500, 502, 503, 504] }, env.retryConfig);
29
39
  const urlIdParam = this.apiCall.hasIdInUrl ? this.args[0] : null;
30
40
  let params = this.apiCall.hasIdInUrl
31
41
  ? this.args[1]
32
42
  : this.args[0];
33
43
  let headers = this.apiCall.hasIdInUrl ? this.args[2] : this.args[1];
34
44
  Object.assign(this.httpHeaders, headers);
35
- const promise = new Promise(async (resolve, reject) => {
36
- function callBackWrapper(err, response) {
37
- if (err) {
38
- reject(err);
39
- }
40
- else {
41
- resolve(response);
42
- }
45
+ if (this.apiCall.httpMethod === 'POST' &&
46
+ !this.httpHeaders['chargebee-idempotency-key'] &&
47
+ this.apiCall.options &&
48
+ this.apiCall.options.isIdempotent) {
49
+ this.httpHeaders['chargebee-idempotency-key'] = (0, util_1.generateUUIDv4)();
50
+ }
51
+ const makeRequest = async (attempt = 0) => {
52
+ let path = (0, util_1.getApiURL)(env, this.apiCall.urlPrefix, this.apiCall.urlSuffix, urlIdParam);
53
+ if (typeof params === 'undefined' || params === null) {
54
+ params = {};
43
55
  }
56
+ if (this.apiCall.httpMethod === 'GET') {
57
+ const queryParam = this.apiCall.isListReq
58
+ ? (0, util_1.encodeListParams)((0, util_1.serialize)(params))
59
+ : (0, util_1.encodeParams)((0, util_1.serialize)(params));
60
+ path += '?' + queryParam;
61
+ params = {};
62
+ }
63
+ const jsonKeys = this.apiCall.jsonKeys;
64
+ const data = this.apiCall.isJsonRequest
65
+ ? JSON.stringify(params)
66
+ : (0, util_1.encodeParams)(params, undefined, undefined, undefined, jsonKeys);
67
+ const requestHeaders = Object.assign({}, this.httpHeaders);
68
+ if (data.length) {
69
+ (0, util_1.extend)(true, requestHeaders, {
70
+ 'Content-Length': data.length,
71
+ });
72
+ }
73
+ const contentType = this.apiCall.isJsonRequest
74
+ ? 'application/json;charset=UTF-8'
75
+ : 'application/x-www-form-urlencoded; charset=utf-8';
76
+ (0, util_1.extend)(true, requestHeaders, {
77
+ Authorization: 'Basic ' + node_buffer_1.Buffer.from(env.apiKey + ':').toString('base64'),
78
+ Accept: 'application/json',
79
+ 'Content-Type': contentType,
80
+ 'User-Agent': 'Chargebee-NodeJs-Client ' + env.clientVersion,
81
+ 'Lang-Version': typeof process === 'undefined' ? '' : process.version,
82
+ });
83
+ if (attempt > 0) {
84
+ requestHeaders['X-CB-Retry-Attempt'] = attempt.toString();
85
+ }
86
+ const resp = await this.envArg.httpClient.makeApiRequest({
87
+ host: (0, util_1.getHost)(env, this.apiCall.subDomain),
88
+ port: env.port,
89
+ path,
90
+ method: this.apiCall.httpMethod,
91
+ protocol: env.protocol,
92
+ headers: requestHeaders,
93
+ data,
94
+ timeout: env.timeout,
95
+ });
96
+ return new Promise((resolve, reject) => {
97
+ (0, coreCommon_1.handleResponse)((err, response) => {
98
+ if (err)
99
+ return reject(err);
100
+ return resolve(response);
101
+ }, resp);
102
+ });
103
+ };
104
+ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
105
+ const withRetry = async (retryCount, startTime) => {
106
+ var _a, _b, _c, _d, _e, _f;
44
107
  try {
45
- let path = (0, util_js_1.getApiURL)(env, this.apiCall.urlPrefix, this.apiCall.urlSuffix, urlIdParam);
46
- if (typeof params === 'undefined' || params === null) {
47
- params = {};
48
- }
49
- if (this.apiCall.httpMethod === 'GET') {
50
- params = (0, util_js_1.serialize)(params);
51
- let queryParam = this.apiCall.isListReq
52
- ? (0, util_js_1.encodeListParams)(params)
53
- : (0, util_js_1.encodeParams)(params);
54
- path += '?' + queryParam;
55
- params = {};
108
+ return await makeRequest(retryCount);
109
+ }
110
+ catch (err) {
111
+ const statusCode = (_d = (_c = (_a = err.statusCode) !== null && _a !== void 0 ? _a : (_b = err.response) === null || _b === void 0 ? void 0 : _b.statusCode) !== null && _c !== void 0 ? _c : err.http_code) !== null && _d !== void 0 ? _d : err.http_status_code;
112
+ const isRateLimitError = statusCode === 429 && retryConfig.enabled;
113
+ if (isRateLimitError) {
114
+ const headers = ((_e = err.response) === null || _e === void 0 ? void 0 : _e.headers) || err.headers || {};
115
+ const retryAfterHeader = (_f = headers['retry-after']) === null || _f === void 0 ? void 0 : _f.toLowerCase();
116
+ const parsedDelay = RequestWrapper.parseRetryAfter(retryAfterHeader);
117
+ if (!parsedDelay) {
118
+ (0, util_1.log)(env, {
119
+ level: 'ERROR',
120
+ message: `Rate limit error occurred, but no retry-after header found. Retrying in ${retryConfig.delayMs}ms.`,
121
+ });
122
+ throw err;
123
+ }
124
+ (0, util_1.log)(env, {
125
+ level: 'INFO',
126
+ message: `Rate limit error occurred. Retrying in ${parsedDelay}ms.`,
127
+ });
128
+ await delay(parsedDelay);
56
129
  }
57
- const jsonKeys = this.apiCall.jsonKeys;
58
- let data = this.apiCall.isJsonRequest
59
- ? JSON.stringify(params)
60
- : (0, util_js_1.encodeParams)(params, undefined, undefined, undefined, jsonKeys);
61
- if (data.length) {
62
- (0, util_js_1.extend)(true, this.httpHeaders, {
63
- 'Content-Length': data.length,
130
+ else {
131
+ const canRetry = retryConfig.enabled &&
132
+ retryConfig.retryOn.includes(statusCode) &&
133
+ retryCount < retryConfig.maxRetries;
134
+ if (!canRetry) {
135
+ (0, util_1.log)(env, {
136
+ level: 'ERROR',
137
+ message: `Request failed after ${retryCount} retries: ${err.message}`,
138
+ });
139
+ throw err;
140
+ }
141
+ let retryDelayMs = retryConfig.delayMs * Math.pow(2, retryCount) +
142
+ Math.random() * 100;
143
+ (0, util_1.log)(env, {
144
+ level: 'INFO',
145
+ message: `Retrying request [${retryCount + 1}/${retryConfig.maxRetries}] in ${retryDelayMs}ms due to status code ${statusCode}.`,
64
146
  });
147
+ await delay(retryDelayMs);
65
148
  }
66
- const contentType = this.apiCall.isJsonRequest
67
- ? 'application/json;charset=UTF-8'
68
- : 'application/x-www-form-urlencoded; charset=utf-8';
69
- (0, util_js_1.extend)(true, this.httpHeaders, {
70
- Authorization: 'Basic ' + node_buffer_1.Buffer.from(env.apiKey + ':').toString('base64'),
71
- Accept: 'application/json',
72
- 'Content-Type': contentType,
73
- 'User-Agent': 'Chargebee-NodeJs-Client ' + env.clientVersion,
74
- 'Lang-Version': typeof process === 'undefined' ? '' : process.version,
75
- });
76
- const resp = await this.envArg.httpClient.makeApiRequest({
77
- host: (0, util_js_1.getHost)(env, this.apiCall.subDomain),
78
- port: env.port,
79
- path,
80
- method: this.apiCall.httpMethod,
81
- protocol: env.protocol,
82
- headers: this.httpHeaders,
83
- data: data,
84
- timeout: env.timeout,
85
- });
86
- (0, coreCommon_js_1.handleResponse)(callBackWrapper, resp);
149
+ return await withRetry(retryCount + 1, startTime);
87
150
  }
88
- catch (err) {
89
- callBackWrapper(err, null);
90
- }
91
- });
92
- return (0, util_js_1.callbackifyPromise)(promise);
151
+ };
152
+ const promise = withRetry(0, Date.now());
153
+ return (0, util_1.callbackifyPromise)(promise);
93
154
  }
94
155
  }
95
156
  exports.RequestWrapper = RequestWrapper;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.waitForProcessToComplete = void 0;
4
- const util_js_1 = require("./util.js");
4
+ const util_1 = require("./util");
5
5
  const waitForProcessToComplete = (retrieveHandling, env) => {
6
- if (typeof retrieveHandling == 'undefined' || !(0, util_js_1.isFunction)(retrieveHandling)) {
6
+ if (typeof retrieveHandling == 'undefined' || !(0, util_1.isFunction)(retrieveHandling)) {
7
7
  throw new Error('The handling parameter should be a method.');
8
8
  }
9
9
  const DummyRequestWrapper = function () {
@@ -12,15 +12,15 @@ const waitForProcessToComplete = (retrieveHandling, env) => {
12
12
  const _request = function (callBack, envOptions) {
13
13
  const jsonConstructor = {}.constructor;
14
14
  if (typeof envOptions !== 'undefined') {
15
- (0, util_js_1.extend)(true, env, envOptions);
15
+ (0, util_1.extend)(true, env, envOptions);
16
16
  }
17
17
  else if (typeof callBack !== 'undefined' &&
18
18
  callBack.constructor === jsonConstructor &&
19
- !(0, util_js_1.isFunction)(callBack)) {
20
- (0, util_js_1.extend)(true, env, callBack);
19
+ !(0, util_1.isFunction)(callBack)) {
20
+ (0, util_1.extend)(true, env, callBack);
21
21
  callBack = undefined;
22
22
  }
23
- if (typeof callBack !== 'undefined' && !(0, util_js_1.isFunction)(callBack)) {
23
+ if (typeof callBack !== 'undefined' && !(0, util_1.isFunction)(callBack)) {
24
24
  throw new Error('The callback parameter passed is incorrect.');
25
25
  }
26
26
  const promise = new Promise((resolve, reject) => {
@@ -32,7 +32,7 @@ const waitForProcessToComplete = (retrieveHandling, env) => {
32
32
  reject(err);
33
33
  }
34
34
  });
35
- return (0, util_js_1.callbackifyPromise)(promise, callBack);
35
+ return (0, util_1.callbackifyPromise)(promise, callBack);
36
36
  };
37
37
  return new DummyRequestWrapper();
38
38
  };
package/cjs/coreCommon.js CHANGED
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleResponse = void 0;
4
4
  exports.throwError = throwError;
5
- const chargebeeError_js_1 = require("./chargebeeError.js");
6
- const util_js_1 = require("./util.js");
5
+ const chargebeeError_1 = require("./chargebeeError");
6
+ const util_1 = require("./util");
7
7
  const IDEMPOTENCY_REPLAYED_HEADER = 'chargebee-idempotency-replayed';
8
8
  function throwError(callBack, rawError, headers) {
9
- const error = new chargebeeError_js_1.ChargebeeError({
9
+ const error = new chargebeeError_1.ChargebeeError({
10
10
  message: rawError.message,
11
11
  type: rawError.type,
12
12
  api_error_code: rawError.errorCode,
@@ -31,7 +31,7 @@ const handleResponse = async (callback, response) => {
31
31
  }
32
32
  else {
33
33
  res.isIdempotencyReplayed = false;
34
- if ((0, util_js_1.isNotUndefinedNEmpty)(headers[IDEMPOTENCY_REPLAYED_HEADER])) {
34
+ if ((0, util_1.isNotUndefinedNEmpty)(headers[IDEMPOTENCY_REPLAYED_HEADER])) {
35
35
  res.isIdempotencyReplayed = headers[IDEMPOTENCY_REPLAYED_HEADER];
36
36
  }
37
37
  res.headers = headers;
@@ -1,24 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CreateChargebee = void 0;
4
- const RequestWrapper_js_1 = require("./RequestWrapper.js");
5
- const environment_js_1 = require("./environment.js");
6
- const api_endpoints_js_1 = require("./resources/api_endpoints.js");
7
- const util_js_1 = require("./util.js");
8
- const asyncApiSupport_js_1 = require("./asyncApiSupport.js");
4
+ const RequestWrapper_1 = require("./RequestWrapper");
5
+ const environment_1 = require("./environment");
6
+ const api_endpoints_1 = require("./resources/api_endpoints");
7
+ const util_1 = require("./util");
8
+ const asyncApiSupport_1 = require("./asyncApiSupport");
9
9
  const CreateChargebee = (httpClient) => {
10
10
  const Chargebee = function (conf) {
11
- this._env = Object.assign({}, environment_js_1.Environment);
12
- (0, util_js_1.extend)(true, this._env, conf);
11
+ this._env = Object.assign({}, environment_1.Environment);
12
+ (0, util_1.extend)(true, this._env, conf);
13
13
  // @ts-ignore
14
14
  this._env.httpClient = httpClient;
15
15
  this._buildResources();
16
- this._endpoints = api_endpoints_js_1.Endpoints;
16
+ this._endpoints = api_endpoints_1.Endpoints;
17
17
  };
18
18
  Chargebee.prototype = {
19
19
  _createApiFunc(apiCall, env) {
20
20
  return async function () {
21
- const rw = new RequestWrapper_js_1.RequestWrapper(arguments, apiCall, env);
21
+ const rw = new RequestWrapper_1.RequestWrapper(arguments, apiCall, env);
22
22
  return rw.getRequest();
23
23
  };
24
24
  },
@@ -32,7 +32,7 @@ const CreateChargebee = (httpClient) => {
32
32
  return result;
33
33
  }
34
34
  else if (exportObj.status === 'in_process') {
35
- await (0, util_js_1.sleep)(this._env.exportWaitInMillis);
35
+ await (0, util_1.sleep)(this._env.exportWaitInMillis);
36
36
  continue;
37
37
  }
38
38
  else {
@@ -41,7 +41,7 @@ const CreateChargebee = (httpClient) => {
41
41
  }
42
42
  throw new Error('Export is taking too long');
43
43
  };
44
- return (0, asyncApiSupport_js_1.waitForProcessToComplete)(retrieve);
44
+ return (0, asyncApiSupport_1.waitForProcessToComplete)(retrieve);
45
45
  },
46
46
  _timeMachineWait() {
47
47
  let count = 0;
@@ -53,7 +53,7 @@ const CreateChargebee = (httpClient) => {
53
53
  return result;
54
54
  }
55
55
  else if (time_machine.time_travel_status === 'in_progress') {
56
- await (0, util_js_1.sleep)(this._env.timemachineWaitInMillis);
56
+ await (0, util_1.sleep)(this._env.timemachineWaitInMillis);
57
57
  continue;
58
58
  }
59
59
  else {
@@ -62,13 +62,13 @@ const CreateChargebee = (httpClient) => {
62
62
  }
63
63
  throw new Error('The time travel is taking too much time');
64
64
  };
65
- return (0, asyncApiSupport_js_1.waitForProcessToComplete)(retrieve);
65
+ return (0, asyncApiSupport_1.waitForProcessToComplete)(retrieve);
66
66
  },
67
67
  _buildResources() {
68
- for (const res in api_endpoints_js_1.Endpoints) {
68
+ for (const res in api_endpoints_1.Endpoints) {
69
69
  this[res] = {};
70
70
  // @ts-ignore
71
- const apiCalls = api_endpoints_js_1.Endpoints[res];
71
+ const apiCalls = api_endpoints_1.Endpoints[res];
72
72
  for (let apiIdx = 0; apiIdx < apiCalls.length; apiIdx++) {
73
73
  const metaArr = apiCalls[apiIdx];
74
74
  const apiCall = {
@@ -81,6 +81,7 @@ const CreateChargebee = (httpClient) => {
81
81
  subDomain: metaArr[5],
82
82
  isJsonRequest: metaArr[6],
83
83
  jsonKeys: metaArr[7],
84
+ options: metaArr[8],
84
85
  };
85
86
  this[res][apiCall.methodName] = this._createApiFunc(apiCall, this._env);
86
87
  }
@@ -11,7 +11,7 @@ exports.Environment = {
11
11
  hostSuffix: '.chargebee.com',
12
12
  apiPath: '/api/v2',
13
13
  timeout: DEFAULT_TIME_OUT,
14
- clientVersion: 'v3.6.1',
14
+ clientVersion: 'v3.8.0-beta.1',
15
15
  port: DEFAULT_PORT,
16
16
  timemachineWaitInMillis: DEFAULT_TIME_MACHINE_WAIT,
17
17
  exportWaitInMillis: DEFAULT_EXPORT_WAIT,
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpClientResponse = exports.HttpClient = void 0;
4
- const chargebeeError_js_1 = require("../chargebeeError.js");
4
+ const chargebeeError_1 = require("../chargebeeError");
5
5
  class HttpClient {
6
6
  async makeApiRequest(props) {
7
7
  throw new Error('makeApiRequest is not implemented');
8
8
  }
9
9
  static timeOutError() {
10
- const error = new chargebeeError_js_1.ChargebeeError({
10
+ const error = new chargebeeError_1.ChargebeeError({
11
11
  message: 'io_error',
12
12
  type: 'timeout',
13
13
  api_error_code: 'request aborted due to timeout.',
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FetchHttpClientResponse = exports.FetchHttpClient = void 0;
4
- const ClientInterface_js_1 = require("./ClientInterface.js");
5
- class FetchHttpClient extends ClientInterface_js_1.HttpClient {
4
+ const ClientInterface_1 = require("./ClientInterface");
5
+ class FetchHttpClient extends ClientInterface_1.HttpClient {
6
6
  async makeApiRequest(props) {
7
7
  const headers = this._createHeaders(props.headers);
8
8
  let url = `${props.protocol}://${props.host}:${props.port}${props.path}`;
@@ -33,7 +33,7 @@ class FetchHttpClient extends ClientInterface_js_1.HttpClient {
33
33
  const timeoutPromise = new Promise((_, reject) => {
34
34
  pendingTimeoutId = setTimeout(() => {
35
35
  pendingTimeoutId = null;
36
- reject(ClientInterface_js_1.HttpClient.timeOutError());
36
+ reject(ClientInterface_1.HttpClient.timeOutError());
37
37
  }, timeout);
38
38
  });
39
39
  const fetchPromise = fetch(url, fetchOptions);
@@ -47,14 +47,14 @@ class FetchHttpClient extends ClientInterface_js_1.HttpClient {
47
47
  const abort = new AbortController();
48
48
  let timeoutId = setTimeout(() => {
49
49
  timeoutId = null;
50
- abort.abort(ClientInterface_js_1.HttpClient.timeOutError());
50
+ abort.abort(ClientInterface_1.HttpClient.timeOutError());
51
51
  }, timeout);
52
52
  try {
53
53
  return await fetch(url, Object.assign(Object.assign({}, fetchOptions), { signal: abort.signal }));
54
54
  }
55
55
  catch (err) {
56
56
  if (err.name === 'AbortError') {
57
- return Promise.reject(ClientInterface_js_1.HttpClient.timeOutError());
57
+ return Promise.reject(ClientInterface_1.HttpClient.timeOutError());
58
58
  }
59
59
  else {
60
60
  return Promise.reject(err);
@@ -68,7 +68,7 @@ class FetchHttpClient extends ClientInterface_js_1.HttpClient {
68
68
  }
69
69
  }
70
70
  exports.FetchHttpClient = FetchHttpClient;
71
- class FetchHttpClientResponse extends ClientInterface_js_1.HttpClientResponse {
71
+ class FetchHttpClientResponse extends ClientInterface_1.HttpClientResponse {
72
72
  constructor(response) {
73
73
  super(response.status, FetchHttpClientResponse._transformHeadersToObject(response.headers));
74
74
  this._res = response;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NodeHttpClientResponse = exports.NodeHttpClient = void 0;
4
- const ClientInterface_js_1 = require("./ClientInterface.js");
4
+ const ClientInterface_1 = require("./ClientInterface");
5
5
  const http = require("http");
6
6
  const https = require("https");
7
- class NodeHttpClient extends ClientInterface_js_1.HttpClient {
7
+ class NodeHttpClient extends ClientInterface_1.HttpClient {
8
8
  async makeApiRequest(props) {
9
9
  const protocol = props.protocol === 'http' ? http : https;
10
10
  const requestPromise = new Promise((resolve, reject) => {
@@ -16,7 +16,7 @@ class NodeHttpClient extends ClientInterface_js_1.HttpClient {
16
16
  headers: props.headers,
17
17
  });
18
18
  req.setTimeout(props.timeout, () => {
19
- throw ClientInterface_js_1.HttpClient.timeOutError();
19
+ throw ClientInterface_1.HttpClient.timeOutError();
20
20
  });
21
21
  req.on('response', (res) => {
22
22
  resolve(new NodeHttpClientResponse(res));
@@ -31,7 +31,7 @@ class NodeHttpClient extends ClientInterface_js_1.HttpClient {
31
31
  }
32
32
  }
33
33
  exports.NodeHttpClient = NodeHttpClient;
34
- class NodeHttpClientResponse extends ClientInterface_js_1.HttpClientResponse {
34
+ class NodeHttpClientResponse extends ClientInterface_1.HttpClientResponse {
35
35
  constructor(res) {
36
36
  //@ts-ignore
37
37
  super(res.statusCode, res.headers);