chargebee 3.14.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 (37) hide show
  1. package/CHANGELOG.md +32 -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/esm/RequestWrapper.js +12 -8
  11. package/esm/chargebee.esm.js +1 -5
  12. package/esm/coreCommon.js +5 -5
  13. package/esm/createChargebee.js +2 -1
  14. package/esm/environment.js +1 -1
  15. package/esm/net/ClientInterface.js +1 -19
  16. package/esm/net/FetchClient.js +9 -38
  17. package/package.json +1 -1
  18. package/types/core.d.ts +2 -0
  19. package/types/index.d.ts +72 -63
  20. package/types/resources/CreditNote.d.ts +2 -0
  21. package/types/resources/CreditNoteEstimate.d.ts +1 -0
  22. package/types/resources/Customer.d.ts +1 -1
  23. package/types/resources/Entitlement.d.ts +1 -1
  24. package/types/resources/EntitlementOverride.d.ts +1 -1
  25. package/types/resources/Event.d.ts +1 -0
  26. package/types/resources/Invoice.d.ts +24 -0
  27. package/types/resources/InvoiceEstimate.d.ts +1 -0
  28. package/types/resources/OmnichannelSubscriptionItem.d.ts +1 -1
  29. package/types/resources/PaymentIntent.d.ts +42 -0
  30. package/types/resources/Quote.d.ts +1 -0
  31. package/types/resources/QuoteLineGroup.d.ts +1 -0
  32. package/types/resources/SalesOrder.d.ts +1 -1
  33. package/types/resources/SubscriptionEntitlement.d.ts +1 -1
  34. package/types/resources/Transaction.d.ts +4 -1
  35. package/types/resources/WebhookEvent.d.ts +5 -0
  36. package/cjs/net/NodeClient.js +0 -61
  37. package/esm/net/NodeClient.js +0 -56
package/CHANGELOG.md CHANGED
@@ -1,3 +1,35 @@
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
+
1
33
  ### v3.14.0 (2025-09-23)
2
34
  * * *
3
35
 
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 = response.getStatusCode() === 204 ? response : 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.14.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;
@@ -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 = response.getStatusCode() === 204 ? response : 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.14.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
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chargebee",
3
- "version": "3.14.0",
3
+ "version": "3.15.0",
4
4
  "description": "A library for integrating with Chargebee.",
5
5
  "scripts": {
6
6
  "prepack": "npm install && npm run build",
package/types/core.d.ts CHANGED
@@ -360,6 +360,7 @@ declare module 'chargebee' {
360
360
  | 'usage_file_ingested'
361
361
  | 'omnichannel_subscription_item_pause_scheduled'
362
362
  | 'omnichannel_subscription_moved_in'
363
+ | 'omnichannel_transaction_created'
363
364
  | 'plan_created'
364
365
  | 'plan_updated'
365
366
  | 'plan_deleted'
@@ -423,6 +424,7 @@ declare module 'chargebee' {
423
424
  | 'solidgate'
424
425
  | 'paystack'
425
426
  | 'jp_morgan'
427
+ | 'deutsche_bank'
426
428
  | 'gocardless'
427
429
  | 'not_applicable';
428
430
  type HierarchyOperationTypeEnum =
package/types/index.d.ts CHANGED
@@ -103,74 +103,83 @@
103
103
  ///<reference path='./resources/WebhookEndpoint.d.ts' />
104
104
  ///<reference path='./resources/Content.d.ts' />
105
105
  ///<reference path='./resources/WebhookEvent.d.ts' />
106
+ declare module 'chargebee' {
107
+ export type Config = {
108
+ /**
109
+ * @apiKey api key for the site.
110
+ */
111
+ apiKey: string;
112
+ /**
113
+ * @site api site name.
114
+ */
115
+ site: string;
116
+ /**
117
+ * @apiPath this value indicates the api version, default value is /api/v2.
118
+ */
119
+ apiPath?: '/api/v2' | '/api/v1';
120
+ /**
121
+ * @timeout client side request timeout in milliseconds, default value is 80000ms.
122
+ */
123
+ timeout?: number;
124
+ /**
125
+ * @port url port
126
+ */
127
+ port?: number;
128
+ /**
129
+ * @timemachineWaitInMillis time interval at which two subsequent retrieve timemachine call in milliseconds, default value is 3000ms.
130
+ */
131
+ timemachineWaitInMillis?: number;
132
+ /**
133
+ * @exportWaitInMillis time interval at which two subsequent retrieve export call in milliseconds, default value is 3000ms.
134
+ */
135
+ exportWaitInMillis?: number;
136
+ /**
137
+ * @protocol http protocol, default value is https
138
+ */
139
+ protocol?: 'https' | 'http';
140
+ /**
141
+ * @hostSuffix url host suffix, default value is .chargebee.com
142
+ */
143
+ hostSuffix?: string;
106
144
 
107
- export type Config = {
108
- /**
109
- * @apiKey api key for the site.
110
- */
111
- apiKey: string;
112
- /**
113
- * @site api site name.
114
- */
115
- site: string;
116
- /**
117
- * @apiPath this value indicates the api version, default value is /api/v2.
118
- */
119
- apiPath?: '/api/v2' | '/api/v1';
120
- /**
121
- * @timeout client side request timeout in milliseconds, default value is 80000ms.
122
- */
123
- timeout?: number;
124
- /**
125
- * @port url port
126
- */
127
- port?: number;
128
- /**
129
- * @timemachineWaitInMillis time interval at which two subsequent retrieve timemachine call in milliseconds, default value is 3000ms.
130
- */
131
- timemachineWaitInMillis?: number;
132
- /**
133
- * @exportWaitInMillis time interval at which two subsequent retrieve export call in milliseconds, default value is 3000ms.
134
- */
135
- exportWaitInMillis?: number;
136
- /**
137
- * @protocol http protocol, default value is https
138
- */
139
- protocol?: 'https' | 'http';
140
- /**
141
- * @hostSuffix url host suffix, default value is .chargebee.com
142
- */
143
- hostSuffix?: string;
145
+ /**
146
+ * @retryConfig retry configuration for the client, default value is { enabled: false, maxRetries: 3, delayMs: 1000, retryOn: [500, 502, 503, 504]}
147
+ */
148
+ retryConfig?: RetryConfig;
144
149
 
145
- /**
146
- * @retryConfig retry configuration for the client, default value is { enabled: false, maxRetries: 3, delayMs: 1000, retryOn: [500, 502, 503, 504]}
147
- */
148
- retryConfig?: RetryConfig;
150
+ /**
151
+ * @enableDebugLogs whether to enable debug logs, default value is false
152
+ */
153
+ enableDebugLogs?: boolean;
149
154
 
150
- /**
151
- * @enableDebugLogs whether to enable debug logs, default value is false
152
- */
153
- enableDebugLogs?: boolean;
155
+ /**
156
+ * @userAgentSuffix optional string appended to the User-Agent header for additional logging
157
+ */
158
+ userAgentSuffix?: string;
154
159
 
155
- /**
156
- * @userAgentSuffix optional string appended to the User-Agent header for additional logging
157
- */
158
- userAgentSuffix?: string;
159
- };
160
+ /**
161
+ * @httpClient optional http client implementation, default http client will be used if not provided
162
+ */
163
+ httpClient?: HttpClientInterface;
164
+ };
165
+
166
+ export interface HttpClientInterface {
167
+ makeApiRequest: (request: Request, timeout: number) => Promise<Response>;
168
+ }
169
+
170
+ export type RetryConfig = {
171
+ /**
172
+ * @enabled whether to enable retry logic, default value is false
173
+ * @maxRetries maximum number of retries, default value is 3
174
+ * @delayMs delay in milliseconds between retries, default value is 1000ms
175
+ * @retryOn array of HTTP status codes to retry on, default value is [500, 502, 503, 504]
176
+ */
177
+ enabled?: boolean;
178
+ maxRetries?: number;
179
+ delayMs?: number;
180
+ retryOn?: Array<number>;
181
+ };
160
182
 
161
- export type RetryConfig = {
162
- /**
163
- * @enabled whether to enable retry logic, default value is false
164
- * @maxRetries maximum number of retries, default value is 3
165
- * @delayMs delay in milliseconds between retries, default value is 1000ms
166
- * @retryOn array of HTTP status codes to retry on, default value is [500, 502, 503, 504]
167
- */
168
- enabled?: boolean;
169
- maxRetries?: number;
170
- delayMs?: number;
171
- retryOn?: Array<number>;
172
- };
173
- declare module 'chargebee' {
174
183
  export default class Chargebee {
175
184
  constructor(config: Config);
176
185
  addon: Addon.AddonResource;
@@ -331,6 +331,7 @@ declare module 'chargebee' {
331
331
  export interface Discount {
332
332
  amount: number;
333
333
  description?: string;
334
+ line_item_id?: string;
334
335
  entity_type:
335
336
  | 'item_level_coupon'
336
337
  | 'document_level_coupon'
@@ -584,6 +585,7 @@ declare module 'chargebee' {
584
585
  allocated_at: number;
585
586
  }
586
587
  export interface DiscountsImportCreditNoteInputParam {
588
+ line_item_id?: string;
587
589
  entity_type:
588
590
  | 'item_level_coupon'
589
591
  | 'document_level_coupon'
@@ -125,6 +125,7 @@ declare module 'chargebee' {
125
125
  export interface Discount {
126
126
  amount: number;
127
127
  description?: string;
128
+ line_item_id?: string;
128
129
  entity_type:
129
130
  | 'item_level_coupon'
130
131
  | 'document_level_coupon'
@@ -348,7 +348,7 @@ declare module 'chargebee' {
348
348
  }
349
349
 
350
350
  export interface ListHierarchyDetailResponse {
351
- list: { hierarchies: any[] }[];
351
+ list: { hierarchy: Hierarchy }[];
352
352
  next_offset?: string;
353
353
  }
354
354
 
@@ -31,7 +31,7 @@ declare module 'chargebee' {
31
31
  }
32
32
 
33
33
  export interface CreateResponse {
34
- entitlement: Entitlement;
34
+ list: { entitlement: Entitlement }[];
35
35
  }
36
36
 
37
37
  // REQUEST PARAMS
@@ -35,7 +35,7 @@ declare module 'chargebee' {
35
35
  }
36
36
 
37
37
  export interface AddEntitlementOverrideForSubscriptionResponse {
38
- entitlement_override: EntitlementOverride;
38
+ list: { entitlement_override: EntitlementOverride }[];
39
39
  }
40
40
 
41
41
  export interface ListEntitlementOverrideForSubscriptionResponse {
@@ -47,6 +47,7 @@ declare module 'chargebee' {
47
47
  CustomerDeletedContent &
48
48
  RefundInitiatedContent &
49
49
  InvoiceGeneratedWithBackdatingContent &
50
+ OmnichannelTransactionCreatedContent &
50
51
  AddUsagesReminderContent &
51
52
  VoucherCreatedContent &
52
53
  RuleUpdatedContent &
@@ -61,6 +61,7 @@ declare module 'chargebee' {
61
61
  taxes?: Invoice.Tax[];
62
62
  tax_origin?: Invoice.TaxOrigin;
63
63
  linked_payments?: Invoice.LinkedPayment[];
64
+ reference_transactions?: Invoice.ReferenceTransaction[];
64
65
  dunning_attempts?: Invoice.DunningAttempt[];
65
66
  applied_credits?: Invoice.AppliedCredit[];
66
67
  adjustment_credit_notes?: Invoice.AdjustmentCreditNote[];
@@ -614,6 +615,7 @@ declare module 'chargebee' {
614
615
  export interface Discount {
615
616
  amount: number;
616
617
  description?: string;
618
+ line_item_id?: string;
617
619
  entity_type:
618
620
  | 'item_level_coupon'
619
621
  | 'document_level_coupon'
@@ -649,6 +651,27 @@ declare module 'chargebee' {
649
651
  txn_date?: number;
650
652
  txn_amount?: number;
651
653
  }
654
+ export interface ReferenceTransaction {
655
+ applied_amount: number;
656
+ applied_at: number;
657
+ txn_id: string;
658
+ txn_status?:
659
+ | 'in_progress'
660
+ | 'success'
661
+ | 'voided'
662
+ | 'failure'
663
+ | 'timeout'
664
+ | 'needs_attention'
665
+ | 'late_failure';
666
+ txn_date?: number;
667
+ txn_amount?: number;
668
+ txn_type: 'authorization' | 'payment' | 'refund' | 'payment_reversal';
669
+ amount_capturable: number;
670
+ authorization_reason?:
671
+ | 'verification'
672
+ | 'blocking_funds'
673
+ | 'scheduled_capture';
674
+ }
652
675
  export interface DunningAttempt {
653
676
  attempt: number;
654
677
  transaction_id?: string;
@@ -1536,6 +1559,7 @@ declare module 'chargebee' {
1536
1559
  note?: string;
1537
1560
  }
1538
1561
  export interface DiscountsImportInvoiceInputParam {
1562
+ line_item_id?: string;
1539
1563
  entity_type:
1540
1564
  | 'item_level_coupon'
1541
1565
  | 'document_level_coupon'
@@ -153,6 +153,7 @@ declare module 'chargebee' {
153
153
  export interface Discount {
154
154
  amount: number;
155
155
  description?: string;
156
+ line_item_id?: string;
156
157
  entity_type:
157
158
  | 'item_level_coupon'
158
159
  | 'document_level_coupon'
@@ -29,7 +29,7 @@ declare module 'chargebee' {
29
29
  resumes_at?: number;
30
30
  has_scheduled_changes: boolean;
31
31
  resource_version?: number;
32
- omnichannel_subscription_item_offers: OmnichannelSubscriptionItemOffer[];
32
+ omnichannel_subscription_item_offers?: OmnichannelSubscriptionItemOffer[];
33
33
  upcoming_renewal?: OmnichannelSubscriptionItem.UpcomingRenewal;
34
34
  linked_item?: OmnichannelSubscriptionItem.LinkedItem;
35
35
  }
@@ -41,6 +41,7 @@ declare module 'chargebee' {
41
41
  customer_id: string;
42
42
  gateway?: string;
43
43
  active_payment_attempt?: PaymentIntent.PaymentAttempt;
44
+ payment_attempts?: PaymentIntent.PaymentAttempt[];
44
45
  business_entity_id?: string;
45
46
  }
46
47
 
@@ -110,6 +111,47 @@ declare module 'chargebee' {
110
111
  id_at_gateway?: string;
111
112
  error_code?: string;
112
113
  error_text?: string;
114
+ checkout_details?: string;
115
+ created_at: number;
116
+ modified_at: number;
117
+ error_detail?: GatewayErrorDetail;
118
+ }
119
+ export interface PaymentAttempt {
120
+ id?: string;
121
+ status:
122
+ | 'inited'
123
+ | 'requires_identification'
124
+ | 'requires_challenge'
125
+ | 'requires_redirection'
126
+ | 'authorized'
127
+ | 'refused'
128
+ | 'pending_authorization';
129
+ payment_method_type?:
130
+ | 'card'
131
+ | 'ideal'
132
+ | 'sofort'
133
+ | 'bancontact'
134
+ | 'google_pay'
135
+ | 'dotpay'
136
+ | 'giropay'
137
+ | 'apple_pay'
138
+ | 'upi'
139
+ | 'netbanking_emandates'
140
+ | 'paypal_express_checkout'
141
+ | 'direct_debit'
142
+ | 'boleto'
143
+ | 'venmo'
144
+ | 'amazon_payments'
145
+ | 'pay_to'
146
+ | 'faster_payments'
147
+ | 'sepa_instant_transfer'
148
+ | 'klarna_pay_now'
149
+ | 'online_banking_poland'
150
+ | 'payconiq_by_bancontact';
151
+ id_at_gateway?: string;
152
+ error_code?: string;
153
+ error_text?: string;
154
+ checkout_details?: string;
113
155
  created_at: number;
114
156
  modified_at: number;
115
157
  error_detail?: GatewayErrorDetail;
@@ -405,6 +405,7 @@ declare module 'chargebee' {
405
405
  export interface Discount {
406
406
  amount: number;
407
407
  description?: string;
408
+ line_item_id?: string;
408
409
  entity_type:
409
410
  | 'item_level_coupon'
410
411
  | 'document_level_coupon'
@@ -116,6 +116,7 @@ declare module 'chargebee' {
116
116
  export interface Discount {
117
117
  amount: number;
118
118
  description?: string;
119
+ line_item_id?: string;
119
120
  entity_type:
120
121
  | 'item_level_coupon'
121
122
  | 'document_level_coupon'
@@ -76,7 +76,7 @@ declare module 'chargebee' {
76
76
  export interface Discount {
77
77
  id: string;
78
78
  invoice_name?: string;
79
- type: 'fixed_amount' | 'percentage';
79
+ type: 'fixed_amount' | 'percentage' | 'offer_quantity';
80
80
  apply_on: 'invoice_amount' | 'specific_item_price';
81
81
  duration_type: 'one_time' | 'forever' | 'limited_period';
82
82
  percentage?: number;
@@ -43,7 +43,7 @@ declare module 'chargebee' {
43
43
  }
44
44
 
45
45
  export interface SetSubscriptionEntitlementAvailabilityResponse {
46
- subscription_entitlement: SubscriptionEntitlement;
46
+ list: { subscription_entitlement: SubscriptionEntitlement }[];
47
47
  }
48
48
 
49
49
  export interface Component {
@@ -29,7 +29,10 @@ declare module 'chargebee' {
29
29
  fraud_flag?: 'safe' | 'suspicious' | 'fraudulent';
30
30
  initiator_type?: 'customer' | 'merchant';
31
31
  three_d_secure?: boolean;
32
- authorization_reason?: 'blocking_funds' | 'verification';
32
+ authorization_reason?:
33
+ | 'blocking_funds'
34
+ | 'verification'
35
+ | 'scheduled_capture';
33
36
  error_code?: string;
34
37
  error_text?: string;
35
38
  voided_at?: number;
@@ -31,6 +31,7 @@ declare module 'chargebee' {
31
31
  CustomerDeleted = 'customer_deleted',
32
32
  RefundInitiated = 'refund_initiated',
33
33
  InvoiceGeneratedWithBackdating = 'invoice_generated_with_backdating',
34
+ OmnichannelTransactionCreated = 'omnichannel_transaction_created',
34
35
  AddUsagesReminder = 'add_usages_reminder',
35
36
  VoucherCreated = 'voucher_created',
36
37
  RuleUpdated = 'rule_updated',
@@ -242,6 +243,7 @@ declare module 'chargebee' {
242
243
  [WebhookContentType.CustomerDeleted]: CustomerDeletedContent;
243
244
  [WebhookContentType.RefundInitiated]: RefundInitiatedContent;
244
245
  [WebhookContentType.InvoiceGeneratedWithBackdating]: InvoiceGeneratedWithBackdatingContent;
246
+ [WebhookContentType.OmnichannelTransactionCreated]: OmnichannelTransactionCreatedContent;
245
247
  [WebhookContentType.AddUsagesReminder]: AddUsagesReminderContent;
246
248
  [WebhookContentType.VoucherCreated]: VoucherCreatedContent;
247
249
  [WebhookContentType.RuleUpdated]: RuleUpdatedContent;
@@ -633,6 +635,9 @@ declare module 'chargebee' {
633
635
  export type InvoiceGeneratedWithBackdatingContent = {
634
636
  invoice: Invoice;
635
637
  };
638
+ export type OmnichannelTransactionCreatedContent = {
639
+ omnichannel_transaction: OmnichannelTransaction;
640
+ };
636
641
  export type AddUsagesReminderContent = {
637
642
  subscription: Subscription;
638
643
 
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NodeHttpClientResponse = exports.NodeHttpClient = void 0;
4
- const ClientInterface_js_1 = require("./ClientInterface.js");
5
- const http = require("http");
6
- const https = require("https");
7
- class NodeHttpClient extends ClientInterface_js_1.HttpClient {
8
- async makeApiRequest(props) {
9
- const protocol = props.protocol === 'http' ? http : https;
10
- const requestPromise = new Promise((resolve, reject) => {
11
- const req = protocol.request({
12
- hostname: props.host,
13
- path: props.path,
14
- method: props.method,
15
- port: props.port,
16
- headers: props.headers,
17
- });
18
- req.setTimeout(props.timeout, () => {
19
- throw ClientInterface_js_1.HttpClient.timeOutError();
20
- });
21
- req.on('response', (res) => {
22
- resolve(new NodeHttpClientResponse(res));
23
- });
24
- req.on('error', (error) => {
25
- reject(error);
26
- });
27
- req.write(props.data);
28
- req.end();
29
- });
30
- return requestPromise;
31
- }
32
- }
33
- exports.NodeHttpClient = NodeHttpClient;
34
- class NodeHttpClientResponse extends ClientInterface_js_1.HttpClientResponse {
35
- constructor(res) {
36
- //@ts-ignore
37
- super(res.statusCode, res.headers);
38
- this._res = res;
39
- }
40
- getRawResponse() {
41
- return this._res;
42
- }
43
- toJson() {
44
- return new Promise((resolve, reject) => {
45
- let response = '';
46
- this._res.setEncoding('utf8');
47
- this._res.on('data', (chunk) => {
48
- response += chunk;
49
- });
50
- this._res.once('end', () => {
51
- try {
52
- resolve(JSON.parse(response));
53
- }
54
- catch (e) {
55
- reject(e);
56
- }
57
- });
58
- });
59
- }
60
- }
61
- exports.NodeHttpClientResponse = NodeHttpClientResponse;
@@ -1,56 +0,0 @@
1
- import { HttpClient, HttpClientResponse, } from './ClientInterface.js';
2
- import * as http from 'http';
3
- import * as https from 'https';
4
- export class NodeHttpClient extends HttpClient {
5
- async makeApiRequest(props) {
6
- const protocol = props.protocol === 'http' ? http : https;
7
- const requestPromise = new Promise((resolve, reject) => {
8
- const req = protocol.request({
9
- hostname: props.host,
10
- path: props.path,
11
- method: props.method,
12
- port: props.port,
13
- headers: props.headers,
14
- });
15
- req.setTimeout(props.timeout, () => {
16
- throw HttpClient.timeOutError();
17
- });
18
- req.on('response', (res) => {
19
- resolve(new NodeHttpClientResponse(res));
20
- });
21
- req.on('error', (error) => {
22
- reject(error);
23
- });
24
- req.write(props.data);
25
- req.end();
26
- });
27
- return requestPromise;
28
- }
29
- }
30
- export class NodeHttpClientResponse extends HttpClientResponse {
31
- constructor(res) {
32
- //@ts-ignore
33
- super(res.statusCode, res.headers);
34
- this._res = res;
35
- }
36
- getRawResponse() {
37
- return this._res;
38
- }
39
- toJson() {
40
- return new Promise((resolve, reject) => {
41
- let response = '';
42
- this._res.setEncoding('utf8');
43
- this._res.on('data', (chunk) => {
44
- response += chunk;
45
- });
46
- this._res.once('end', () => {
47
- try {
48
- resolve(JSON.parse(response));
49
- }
50
- catch (e) {
51
- reject(e);
52
- }
53
- });
54
- });
55
- }
56
- }