chargebee 3.13.0 → 3.15.0

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 (57) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/README.md +24 -0
  3. package/cjs/RequestWrapper.js +12 -8
  4. package/cjs/chargebee.cjs.js +1 -5
  5. package/cjs/coreCommon.js +5 -5
  6. package/cjs/createChargebee.js +2 -1
  7. package/cjs/environment.js +1 -1
  8. package/cjs/net/ClientInterface.js +2 -21
  9. package/cjs/net/FetchClient.js +9 -39
  10. package/cjs/resources/api_endpoints.js +66 -0
  11. package/esm/RequestWrapper.js +12 -8
  12. package/esm/chargebee.esm.js +1 -5
  13. package/esm/coreCommon.js +5 -5
  14. package/esm/createChargebee.js +2 -1
  15. package/esm/environment.js +1 -1
  16. package/esm/net/ClientInterface.js +1 -19
  17. package/esm/net/FetchClient.js +9 -38
  18. package/esm/resources/api_endpoints.js +66 -0
  19. package/package.json +1 -1
  20. package/types/core.d.ts +10 -1
  21. package/types/index.d.ts +79 -63
  22. package/types/resources/Comment.d.ts +0 -9
  23. package/types/resources/Content.d.ts +4 -0
  24. package/types/resources/CreditNote.d.ts +5 -1
  25. package/types/resources/CreditNoteEstimate.d.ts +32 -31
  26. package/types/resources/Currency.d.ts +11 -5
  27. package/types/resources/Customer.d.ts +2 -1
  28. package/types/resources/Entitlement.d.ts +1 -1
  29. package/types/resources/EntitlementOverride.d.ts +1 -1
  30. package/types/resources/Estimate.d.ts +2 -0
  31. package/types/resources/Event.d.ts +3 -0
  32. package/types/resources/GatewayErrorDetail.d.ts +1 -0
  33. package/types/resources/HostedPage.d.ts +2 -0
  34. package/types/resources/Invoice.d.ts +29 -1
  35. package/types/resources/InvoiceEstimate.d.ts +43 -42
  36. package/types/resources/OfferEvent.d.ts +25 -0
  37. package/types/resources/OfferFulfillment.d.ts +77 -0
  38. package/types/resources/OmnichannelOneTimeOrder.d.ts +1 -13
  39. package/types/resources/OmnichannelSubscription.d.ts +13 -12
  40. package/types/resources/OmnichannelSubscriptionItem.d.ts +1 -0
  41. package/types/resources/OmnichannelSubscriptionItemOffer.d.ts +22 -0
  42. package/types/resources/OmnichannelTransaction.d.ts +13 -0
  43. package/types/resources/Order.d.ts +0 -1
  44. package/types/resources/PaymentIntent.d.ts +42 -0
  45. package/types/resources/PersonalizedOffer.d.ts +64 -0
  46. package/types/resources/Quote.d.ts +35 -33
  47. package/types/resources/QuoteLineGroup.d.ts +22 -21
  48. package/types/resources/Ramp.d.ts +46 -0
  49. package/types/resources/SalesOrder.d.ts +2 -2
  50. package/types/resources/Subscription.d.ts +1 -1
  51. package/types/resources/SubscriptionEntitlement.d.ts +1 -1
  52. package/types/resources/SubscriptionEstimate.d.ts +0 -1
  53. package/types/resources/Transaction.d.ts +5 -1
  54. package/types/resources/UsageFile.d.ts +2 -0
  55. package/types/resources/WebhookEvent.d.ts +17 -0
  56. package/cjs/net/NodeClient.js +0 -61
  57. package/esm/net/NodeClient.js +0 -56
package/CHANGELOG.md CHANGED
@@ -1,3 +1,91 @@
1
+ ### v3.15.0 (2025-10-28)
2
+ * * *
3
+
4
+ ### New Attributes:
5
+ * reference_transactions has been added to Invoice.
6
+ * payment_attempts[] has been added to PaymentIntent.
7
+ * checkout_details has been added to PaymentIntent#PaymentAttempt.
8
+ * line_item_id has been added to CreditNoteEstimate#Discount.
9
+ * line_item_id has been added to CreditNote#Discount.
10
+ * line_item_id has been added to InvoiceEstimate#Discount.
11
+ * line_item_id has been added to Invoice#Discount.
12
+ * line_item_id has been added to InvoiceEstimate#Discount.
13
+ * line_item_id has been added to Quote#Discount.
14
+ * line_item_id has been added to QuoteLineGroup#Discount.
15
+
16
+ ### Modified Attributes:
17
+ * omnichannel_subscription_item_offers has been made optional attribute from required attribute.
18
+
19
+ ### New Input Parameters:
20
+ * discount[line_item_id] has been added to CreditNote#ImportCreditNoteRequest.
21
+ * discount[line_item_id] has been added to CreditNote#ImportInvoiceRequest.
22
+
23
+ ### New Enums:
24
+ * OMNICHANNEL_TRANSACTION_CREATED has been added to EventTypeEnum.
25
+ * DEUTSCHE_BANK has been added to Gateway.
26
+
27
+ ### Enhancements
28
+ * Added support for injectable **custom HTTP clients**.
29
+ * Added example implementation using **Axios**.
30
+ * Added example implementation using **ky**.
31
+ * Removed support for `http` and `https` based HttpClient as the minimum supported Node.js version for this package is >= 18.
32
+
33
+ ### v3.14.0 (2025-09-23)
34
+ * * *
35
+
36
+ ### New Resources:
37
+ * PersonalizedOffer has been added.
38
+ * OfferFulfillment has been added.
39
+ * OfferEvent has been added.
40
+ * OmnichannelSubscriptionItemOffer has been added.
41
+
42
+ ### New Attributes:
43
+ * business_entity_id has been added to Customer#Balance.
44
+ * processor_advice_code has been added to GatewayErrorDetail.
45
+ * processor_advice_code has been added to Transaction#GatewayErrorDetail.
46
+ * omnichannel_subscription_item_offers has been added to OmnichannelSubscriptionItem.
47
+ * linked_omnichannel_subscriptions has been added to OmnichannelTransaction.
48
+ * linked_omnichannel_one_time_orders has been added to OmnichannelTransaction.
49
+ * contract_term has been added to Ramp.
50
+ * charge_once has been added to Ramp#ItemsToAdd.
51
+ * charge_on_option has been added to Ramp#ItemsToAdd.
52
+ * charge_on_event has been added to Ramp#ItemsToAdd.
53
+ * charge_once has been added to Ramp#ItemsToUpdate.
54
+ * charge_on_option has been added to Ramp#ItemsToUpdate.
55
+ * charge_on_event has been added to Ramp#ItemsToUpdate.
56
+ * error_file_path has been added to UsageFile.
57
+ * error_file_url has been added to UsageFile.
58
+
59
+ ### New Endpoint:
60
+ * move has been added to OmnichannelSubscription.
61
+
62
+ ### New Parameters:
63
+ * offline_payment_method has been added to Estimate#CreateSubItemEstimateRequest.
64
+ * offline_payment_method has been added to Estimate#CreateSubItemForCustomerEstimateRequest.
65
+ * offline_payment_method has been added to HostedPage#CheckoutNewForItemsRequest.
66
+ * offline_payment_method has been added to Quote#SubscriptionCreateSubItemsForCustomerQuoteRequest.
67
+ * offline_payment_method has been added to Quote#SubscriptionEditCreateSubCustomerQuoteForItemsRequest.
68
+ * contract_term has been added to Ramp#CreateForSubscriptionRequest.
69
+ * items_to_add has been added to Ramp#CreateForSubscriptionRequest.
70
+ * items_to_update has been added to Ramp#CreateForSubscriptionRequest.
71
+ * contract_term has been added to Ramp#UpdateRequest.
72
+ * items_to_add has been added to Ramp#UpdateRequest.
73
+ * items_to_update has been added to Ramp#UpdateRequest.
74
+
75
+ ### New Enums:
76
+ * DUNNING_UPDATED has been added EventType.
77
+ * OMNICHANNEL_SUBSCRIPTION_MOVED_IN has been added to EventType.
78
+
79
+
80
+ ### Bug Fixes:
81
+ * currency list action has been marked as ListRequest.
82
+ * index has been removed from CreditNote#ShippingAddress.
83
+ * index has been removed from Invoice#ShippingAddress
84
+ * index has been removed from Order#ShippingAddress.
85
+ * index has been removed from Quote#ShippingAddress.
86
+ * index has been removed from SubscriptionEstimate#ShippingAddress.
87
+ * index has been removed from Subscription#ShippingAddress.
88
+
1
89
  ### v3.13.0 (2025-09-15)
2
90
  * * *
3
91
 
package/README.md CHANGED
@@ -237,6 +237,30 @@ const subscription = subscripitonActivatedEvent.content.subscription;
237
237
  * Use the `WebhookContentType` to specify the exact event type (e.g., `SubscriptionCreated`, `InvoiceGenerated`, etc.).
238
238
  * This approach ensures you get proper IntelliSense and compile-time checks when accessing event fields.
239
239
 
240
+ ### Custom HTTP Client
241
+
242
+ The SDK supports injecting a **custom HTTP client**, giving you full flexibility to control how API requests are made and handled. This feature is useful if you want to integrate your own networking stack, add custom logging, implement telemetry, or handle retries in a specific way.
243
+
244
+ With this enhancement, you can replace the default HTTP client with your own implementation by passing a custom client that adheres to the `HttpClientInterface` contract when initializing the Chargebee instance.
245
+
246
+ ```js
247
+ const chargebee = new Chargebee({
248
+ site: "{site}",
249
+ apiKey: "{key}",
250
+ httpClient: new CustomHttpClient(),
251
+ });
252
+ ```
253
+
254
+ #### Notes
255
+ * Your custom client must implement the `HttpClientInterface` provided by the SDK.
256
+ * This feature is especially useful in environments with strict networking policies or where advanced observability is required.
257
+ * Example implementations are available under:
258
+
259
+ * [`/examples/customHttpClient/axiosHttpClient.ts`](./examples/customHttpClient/axiosHttpClient.ts)
260
+ * [`/examples/customHttpClient/kyHttpClient.ts`](./examples/customHttpClient/kyHttpClient.ts)
261
+ * You may need to implement custom conversion logic when integrating third-party HTTP libraries, as their request and response formats might not directly align with the `HttpClientInterface` expected by the SDK.
262
+
263
+ These examples demonstrate how to implement and inject custom clients using `axios` and `ky`, respectively.
240
264
 
241
265
  ## Feedback
242
266
 
@@ -86,16 +86,13 @@ class RequestWrapper {
86
86
  if (attempt > 0) {
87
87
  requestHeaders['X-CB-Retry-Attempt'] = attempt.toString();
88
88
  }
89
- const resp = await this.envArg.httpClient.makeApiRequest({
90
- host: (0, util_js_1.getHost)(env, this.apiCall.subDomain),
91
- port: env.port,
92
- path,
89
+ const url = new URL(path, `${env.protocol}://${(0, util_js_1.getHost)(env, this.apiCall.subDomain)}${env.port ? `:${env.port}` : ''}`);
90
+ const request = new Request(url, {
93
91
  method: this.apiCall.httpMethod,
94
- protocol: env.protocol,
95
- headers: requestHeaders,
96
- data,
97
- timeout: env.timeout,
92
+ body: data !== null && data !== void 0 ? data : undefined,
93
+ headers: this._createHeaders(requestHeaders),
98
94
  });
95
+ const resp = await this.envArg.httpClient.makeApiRequest(request, env.timeout);
99
96
  return new Promise((resolve, reject) => {
100
97
  (0, coreCommon_js_1.handleResponse)((err, response) => {
101
98
  if (err)
@@ -155,5 +152,12 @@ class RequestWrapper {
155
152
  const promise = withRetry(0, Date.now());
156
153
  return (0, util_js_1.callbackifyPromise)(promise);
157
154
  }
155
+ _createHeaders(httpHeaders) {
156
+ const headers = new Headers();
157
+ Object.entries(httpHeaders).forEach(([key, value]) => {
158
+ headers.append(key, String(value));
159
+ });
160
+ return headers;
161
+ }
158
162
  }
159
163
  exports.RequestWrapper = RequestWrapper;
@@ -1,12 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const createChargebee_js_1 = require("./createChargebee.js");
4
- const NodeClient_js_1 = require("./net/NodeClient.js");
5
4
  const FetchClient_js_1 = require("./net/FetchClient.js");
6
- //@ts-ignore
7
- const httpClient = !globalThis.fetch
8
- ? new NodeClient_js_1.NodeHttpClient()
9
- : new FetchClient_js_1.FetchHttpClient();
5
+ const httpClient = new FetchClient_js_1.FetchHttpClient();
10
6
  const Chargebee = (0, createChargebee_js_1.CreateChargebee)(httpClient);
11
7
  module.exports = Chargebee;
12
8
  module.exports.Chargebee = Chargebee;
package/cjs/coreCommon.js CHANGED
@@ -21,9 +21,9 @@ function throwError(callBack, rawError, headers) {
21
21
  }
22
22
  const handleResponse = async (callback, response) => {
23
23
  try {
24
- const res = await response.toJson();
25
- const status = response.getStatusCode();
26
- const headers = response.getHeaders();
24
+ const status = response.status;
25
+ const headers = Object.fromEntries(response.headers.entries());
26
+ const res = status === 204 ? {} : await response.json();
27
27
  if (status && (status < 200 || status > 299)) {
28
28
  res.http_status_code = status;
29
29
  res.headers = headers;
@@ -40,8 +40,8 @@ const handleResponse = async (callback, response) => {
40
40
  }
41
41
  }
42
42
  catch (error) {
43
- const status = response.getStatusCode();
44
- const headers = response.getHeaders();
43
+ const status = response.status;
44
+ const headers = Object.fromEntries(response.headers.entries());
45
45
  switch (status) {
46
46
  case 503:
47
47
  return throwError(callback, {
@@ -11,7 +11,8 @@ const CreateChargebee = (httpClient) => {
11
11
  this._env = Object.assign({}, environment_js_1.Environment);
12
12
  (0, util_js_1.extend)(true, this._env, conf);
13
13
  // @ts-ignore
14
- this._env.httpClient = httpClient;
14
+ this._env.httpClient =
15
+ conf.httpClient != null ? conf.httpClient : httpClient;
15
16
  this._buildResources();
16
17
  this._endpoints = api_endpoints_js_1.Endpoints;
17
18
  };
@@ -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.13.0',
14
+ clientVersion: 'v3.15.0',
15
15
  port: DEFAULT_PORT,
16
16
  timemachineWaitInMillis: DEFAULT_TIME_MACHINE_WAIT,
17
17
  exportWaitInMillis: DEFAULT_EXPORT_WAIT,
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpClientResponse = exports.HttpClient = void 0;
3
+ exports.HttpClient = void 0;
4
4
  const chargebeeError_js_1 = require("../chargebeeError.js");
5
5
  class HttpClient {
6
- async makeApiRequest(props) {
6
+ async makeApiRequest(props, timeout) {
7
7
  throw new Error('makeApiRequest is not implemented');
8
8
  }
9
9
  static timeOutError() {
@@ -19,22 +19,3 @@ class HttpClient {
19
19
  }
20
20
  }
21
21
  exports.HttpClient = HttpClient;
22
- class HttpClientResponse {
23
- constructor(statusCode, headers) {
24
- this._statusCode = statusCode;
25
- this._headers = headers;
26
- }
27
- getStatusCode() {
28
- return this._statusCode;
29
- }
30
- getHeaders() {
31
- return this._headers;
32
- }
33
- getRawResponse() {
34
- throw new Error('getRawResponse not implemented.');
35
- }
36
- toJson() {
37
- throw new Error('toJSON not implemented.');
38
- }
39
- }
40
- exports.HttpClientResponse = HttpClientResponse;
@@ -1,21 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FetchHttpClientResponse = exports.FetchHttpClient = void 0;
3
+ exports.FetchHttpClient = void 0;
4
4
  const ClientInterface_js_1 = require("./ClientInterface.js");
5
5
  class FetchHttpClient extends ClientInterface_js_1.HttpClient {
6
- async makeApiRequest(props) {
7
- const headers = this._createHeaders(props.headers);
8
- let url = `${props.protocol}://${props.host}:${props.port}${props.path}`;
9
- let fetchOptions = {
10
- method: props.method,
11
- headers: headers,
12
- body: props.data ? props.data : undefined,
13
- };
6
+ async makeApiRequest(request, timeout) {
14
7
  try {
15
8
  const response = globalThis.AbortController
16
- ? await this.fetchWithAbortTimeout(url, fetchOptions, props.timeout)
17
- : await this.fetchWithTimeout(url, fetchOptions, props.timeout);
18
- return new FetchHttpClientResponse(response);
9
+ ? await this.fetchWithAbortTimeout(request, timeout)
10
+ : await this.fetchWithTimeout(request, timeout);
11
+ return response;
19
12
  }
20
13
  catch (err) {
21
14
  return Promise.reject(err);
@@ -28,7 +21,7 @@ class FetchHttpClient extends ClientInterface_js_1.HttpClient {
28
21
  });
29
22
  return headers;
30
23
  }
31
- async fetchWithTimeout(url, fetchOptions, timeout) {
24
+ async fetchWithTimeout(request, timeout) {
32
25
  let pendingTimeoutId;
33
26
  const timeoutPromise = new Promise((_, reject) => {
34
27
  pendingTimeoutId = setTimeout(() => {
@@ -36,21 +29,21 @@ class FetchHttpClient extends ClientInterface_js_1.HttpClient {
36
29
  reject(ClientInterface_js_1.HttpClient.timeOutError());
37
30
  }, timeout);
38
31
  });
39
- const fetchPromise = fetch(url, fetchOptions);
32
+ const fetchPromise = fetch(request);
40
33
  return Promise.race([fetchPromise, timeoutPromise]).finally(() => {
41
34
  if (pendingTimeoutId) {
42
35
  clearTimeout(pendingTimeoutId);
43
36
  }
44
37
  });
45
38
  }
46
- async fetchWithAbortTimeout(url, fetchOptions, timeout) {
39
+ async fetchWithAbortTimeout(request, timeout) {
47
40
  const abort = new AbortController();
48
41
  let timeoutId = setTimeout(() => {
49
42
  timeoutId = null;
50
43
  abort.abort(ClientInterface_js_1.HttpClient.timeOutError());
51
44
  }, timeout);
52
45
  try {
53
- return await fetch(url, Object.assign(Object.assign({}, fetchOptions), { signal: abort.signal }));
46
+ return await fetch(new Request(request, { signal: abort.signal }));
54
47
  }
55
48
  catch (err) {
56
49
  if (err.name === 'AbortError') {
@@ -68,26 +61,3 @@ class FetchHttpClient extends ClientInterface_js_1.HttpClient {
68
61
  }
69
62
  }
70
63
  exports.FetchHttpClient = FetchHttpClient;
71
- class FetchHttpClientResponse extends ClientInterface_js_1.HttpClientResponse {
72
- constructor(response) {
73
- super(response.status, FetchHttpClientResponse._transformHeadersToObject(response.headers));
74
- this._res = response;
75
- }
76
- getRawResponse() {
77
- return this._res;
78
- }
79
- toJson() {
80
- return this._res.json();
81
- }
82
- static _transformHeadersToObject(headers) {
83
- const headersObj = {};
84
- for (const entry of headers) {
85
- if (!Array.isArray(entry) || entry.length != 2) {
86
- throw new Error('Headers should be an iterable object.');
87
- }
88
- headersObj[entry[0]] = entry[1];
89
- }
90
- return headersObj;
91
- }
92
- }
93
- exports.FetchHttpClientResponse = FetchHttpClientResponse;
@@ -4645,6 +4645,19 @@ exports.Endpoints = {
4645
4645
  {},
4646
4646
  {},
4647
4647
  ],
4648
+ [
4649
+ 'move',
4650
+ 'POST',
4651
+ '/omnichannel_subscriptions',
4652
+ '/move',
4653
+ true,
4654
+ null,
4655
+ false,
4656
+ {},
4657
+ {
4658
+ isIdempotent: true,
4659
+ },
4660
+ ],
4648
4661
  ],
4649
4662
  omnichannelTransaction: [],
4650
4663
  omnichannelSubscriptionItem: [
@@ -4755,7 +4768,60 @@ exports.Endpoints = {
4755
4768
  {},
4756
4769
  ],
4757
4770
  ],
4771
+ personalizedOffer: [
4772
+ [
4773
+ 'personalizedOffers',
4774
+ 'POST',
4775
+ '/personalized_offers',
4776
+ null,
4777
+ false,
4778
+ 'grow',
4779
+ true,
4780
+ {
4781
+ custom: 0,
4782
+ },
4783
+ {},
4784
+ ],
4785
+ ],
4758
4786
  brand: [],
4787
+ offerFulfillment: [
4788
+ [
4789
+ 'offerFulfillments',
4790
+ 'POST',
4791
+ '/offer_fulfillments',
4792
+ null,
4793
+ false,
4794
+ 'grow',
4795
+ true,
4796
+ {},
4797
+ {},
4798
+ ],
4799
+ [
4800
+ 'offerFulfillmentsGet',
4801
+ 'GET',
4802
+ '/offer_fulfillments',
4803
+ null,
4804
+ true,
4805
+ 'grow',
4806
+ true,
4807
+ {},
4808
+ {},
4809
+ ],
4810
+ [
4811
+ 'offerFulfillmentsUpdate',
4812
+ 'POST',
4813
+ '/offer_fulfillments',
4814
+ null,
4815
+ true,
4816
+ 'grow',
4817
+ true,
4818
+ {},
4819
+ {},
4820
+ ],
4821
+ ],
4822
+ offerEvent: [
4823
+ ['offerEvents', 'POST', '/offer_events', null, false, 'grow', true, {}, {}],
4824
+ ],
4759
4825
  webhookEndpoint: [
4760
4826
  [
4761
4827
  'create',
@@ -83,16 +83,13 @@ export class RequestWrapper {
83
83
  if (attempt > 0) {
84
84
  requestHeaders['X-CB-Retry-Attempt'] = attempt.toString();
85
85
  }
86
- const resp = await this.envArg.httpClient.makeApiRequest({
87
- host: getHost(env, this.apiCall.subDomain),
88
- port: env.port,
89
- path,
86
+ const url = new URL(path, `${env.protocol}://${getHost(env, this.apiCall.subDomain)}${env.port ? `:${env.port}` : ''}`);
87
+ const request = new Request(url, {
90
88
  method: this.apiCall.httpMethod,
91
- protocol: env.protocol,
92
- headers: requestHeaders,
93
- data,
94
- timeout: env.timeout,
89
+ body: data !== null && data !== void 0 ? data : undefined,
90
+ headers: this._createHeaders(requestHeaders),
95
91
  });
92
+ const resp = await this.envArg.httpClient.makeApiRequest(request, env.timeout);
96
93
  return new Promise((resolve, reject) => {
97
94
  handleResponse((err, response) => {
98
95
  if (err)
@@ -152,4 +149,11 @@ export class RequestWrapper {
152
149
  const promise = withRetry(0, Date.now());
153
150
  return callbackifyPromise(promise);
154
151
  }
152
+ _createHeaders(httpHeaders) {
153
+ const headers = new Headers();
154
+ Object.entries(httpHeaders).forEach(([key, value]) => {
155
+ headers.append(key, String(value));
156
+ });
157
+ return headers;
158
+ }
155
159
  }
@@ -1,9 +1,5 @@
1
1
  import { CreateChargebee } from './createChargebee.js';
2
- import { NodeHttpClient } from './net/NodeClient.js';
3
2
  import { FetchHttpClient } from './net/FetchClient.js';
4
- //@ts-ignore
5
- const httpClient = !globalThis.fetch
6
- ? new NodeHttpClient()
7
- : new FetchHttpClient();
3
+ const httpClient = new FetchHttpClient();
8
4
  const Chargebee = CreateChargebee(httpClient);
9
5
  export default Chargebee;
package/esm/coreCommon.js CHANGED
@@ -17,9 +17,9 @@ export function throwError(callBack, rawError, headers) {
17
17
  }
18
18
  export const handleResponse = async (callback, response) => {
19
19
  try {
20
- const res = await response.toJson();
21
- const status = response.getStatusCode();
22
- const headers = response.getHeaders();
20
+ const status = response.status;
21
+ const headers = Object.fromEntries(response.headers.entries());
22
+ const res = status === 204 ? {} : await response.json();
23
23
  if (status && (status < 200 || status > 299)) {
24
24
  res.http_status_code = status;
25
25
  res.headers = headers;
@@ -36,8 +36,8 @@ export const handleResponse = async (callback, response) => {
36
36
  }
37
37
  }
38
38
  catch (error) {
39
- const status = response.getStatusCode();
40
- const headers = response.getHeaders();
39
+ const status = response.status;
40
+ const headers = Object.fromEntries(response.headers.entries());
41
41
  switch (status) {
42
42
  case 503:
43
43
  return throwError(callback, {
@@ -8,7 +8,8 @@ export const CreateChargebee = (httpClient) => {
8
8
  this._env = Object.assign({}, Environment);
9
9
  extend(true, this._env, conf);
10
10
  // @ts-ignore
11
- this._env.httpClient = httpClient;
11
+ this._env.httpClient =
12
+ conf.httpClient != null ? conf.httpClient : httpClient;
12
13
  this._buildResources();
13
14
  this._endpoints = Endpoints;
14
15
  };
@@ -8,7 +8,7 @@ export const Environment = {
8
8
  hostSuffix: '.chargebee.com',
9
9
  apiPath: '/api/v2',
10
10
  timeout: DEFAULT_TIME_OUT,
11
- clientVersion: 'v3.13.0',
11
+ clientVersion: 'v3.15.0',
12
12
  port: DEFAULT_PORT,
13
13
  timemachineWaitInMillis: DEFAULT_TIME_MACHINE_WAIT,
14
14
  exportWaitInMillis: DEFAULT_EXPORT_WAIT,
@@ -1,6 +1,6 @@
1
1
  import { ChargebeeError } from '../chargebeeError.js';
2
2
  export class HttpClient {
3
- async makeApiRequest(props) {
3
+ async makeApiRequest(props, timeout) {
4
4
  throw new Error('makeApiRequest is not implemented');
5
5
  }
6
6
  static timeOutError() {
@@ -15,21 +15,3 @@ export class HttpClient {
15
15
  return error;
16
16
  }
17
17
  }
18
- export class HttpClientResponse {
19
- constructor(statusCode, headers) {
20
- this._statusCode = statusCode;
21
- this._headers = headers;
22
- }
23
- getStatusCode() {
24
- return this._statusCode;
25
- }
26
- getHeaders() {
27
- return this._headers;
28
- }
29
- getRawResponse() {
30
- throw new Error('getRawResponse not implemented.');
31
- }
32
- toJson() {
33
- throw new Error('toJSON not implemented.');
34
- }
35
- }
@@ -1,18 +1,11 @@
1
- import { HttpClient, HttpClientResponse, } from './ClientInterface.js';
1
+ import { HttpClient } from './ClientInterface.js';
2
2
  export class FetchHttpClient extends HttpClient {
3
- async makeApiRequest(props) {
4
- const headers = this._createHeaders(props.headers);
5
- let url = `${props.protocol}://${props.host}:${props.port}${props.path}`;
6
- let fetchOptions = {
7
- method: props.method,
8
- headers: headers,
9
- body: props.data ? props.data : undefined,
10
- };
3
+ async makeApiRequest(request, timeout) {
11
4
  try {
12
5
  const response = globalThis.AbortController
13
- ? await this.fetchWithAbortTimeout(url, fetchOptions, props.timeout)
14
- : await this.fetchWithTimeout(url, fetchOptions, props.timeout);
15
- return new FetchHttpClientResponse(response);
6
+ ? await this.fetchWithAbortTimeout(request, timeout)
7
+ : await this.fetchWithTimeout(request, timeout);
8
+ return response;
16
9
  }
17
10
  catch (err) {
18
11
  return Promise.reject(err);
@@ -25,7 +18,7 @@ export class FetchHttpClient extends HttpClient {
25
18
  });
26
19
  return headers;
27
20
  }
28
- async fetchWithTimeout(url, fetchOptions, timeout) {
21
+ async fetchWithTimeout(request, timeout) {
29
22
  let pendingTimeoutId;
30
23
  const timeoutPromise = new Promise((_, reject) => {
31
24
  pendingTimeoutId = setTimeout(() => {
@@ -33,21 +26,21 @@ export class FetchHttpClient extends HttpClient {
33
26
  reject(HttpClient.timeOutError());
34
27
  }, timeout);
35
28
  });
36
- const fetchPromise = fetch(url, fetchOptions);
29
+ const fetchPromise = fetch(request);
37
30
  return Promise.race([fetchPromise, timeoutPromise]).finally(() => {
38
31
  if (pendingTimeoutId) {
39
32
  clearTimeout(pendingTimeoutId);
40
33
  }
41
34
  });
42
35
  }
43
- async fetchWithAbortTimeout(url, fetchOptions, timeout) {
36
+ async fetchWithAbortTimeout(request, timeout) {
44
37
  const abort = new AbortController();
45
38
  let timeoutId = setTimeout(() => {
46
39
  timeoutId = null;
47
40
  abort.abort(HttpClient.timeOutError());
48
41
  }, timeout);
49
42
  try {
50
- return await fetch(url, Object.assign(Object.assign({}, fetchOptions), { signal: abort.signal }));
43
+ return await fetch(new Request(request, { signal: abort.signal }));
51
44
  }
52
45
  catch (err) {
53
46
  if (err.name === 'AbortError') {
@@ -64,25 +57,3 @@ export class FetchHttpClient extends HttpClient {
64
57
  }
65
58
  }
66
59
  }
67
- export class FetchHttpClientResponse extends HttpClientResponse {
68
- constructor(response) {
69
- super(response.status, FetchHttpClientResponse._transformHeadersToObject(response.headers));
70
- this._res = response;
71
- }
72
- getRawResponse() {
73
- return this._res;
74
- }
75
- toJson() {
76
- return this._res.json();
77
- }
78
- static _transformHeadersToObject(headers) {
79
- const headersObj = {};
80
- for (const entry of headers) {
81
- if (!Array.isArray(entry) || entry.length != 2) {
82
- throw new Error('Headers should be an iterable object.');
83
- }
84
- headersObj[entry[0]] = entry[1];
85
- }
86
- return headersObj;
87
- }
88
- }