chargebee 2.39.0 → 3.0.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/LICENSE +1 -1
  3. package/README.md +90 -172
  4. package/cjs/RequestWrapper.js +81 -0
  5. package/cjs/asyncApiSupport.js +39 -0
  6. package/cjs/chargebee.cjs.js +13 -0
  7. package/cjs/chargebee.cjs.worker.js +9 -0
  8. package/cjs/chargebeeError.js +17 -0
  9. package/cjs/coreCommon.js +72 -0
  10. package/cjs/createChargebee.js +92 -0
  11. package/cjs/environment.js +18 -0
  12. package/cjs/filter.js +1 -0
  13. package/cjs/net/ClientInterface.js +40 -0
  14. package/cjs/net/FetchClient.js +86 -0
  15. package/cjs/net/NodeClient.js +61 -0
  16. package/cjs/package.json +1 -0
  17. package/cjs/resources/api_endpoints.js +1086 -0
  18. package/cjs/util.js +218 -0
  19. package/esm/RequestWrapper.js +77 -0
  20. package/esm/asyncApiSupport.js +35 -0
  21. package/esm/chargebee.esm.js +9 -0
  22. package/esm/chargebee.esm.worker.js +5 -0
  23. package/esm/chargebeeError.js +13 -0
  24. package/esm/coreCommon.js +67 -0
  25. package/esm/createChargebee.js +88 -0
  26. package/esm/environment.js +15 -0
  27. package/esm/filter.js +1 -0
  28. package/esm/net/ClientInterface.js +35 -0
  29. package/esm/net/FetchClient.js +81 -0
  30. package/esm/net/NodeClient.js +56 -0
  31. package/esm/package.json +1 -0
  32. package/esm/resources/api_endpoints.js +1083 -0
  33. package/esm/util.js +202 -0
  34. package/package.json +69 -38
  35. package/types/core.d.ts +558 -89
  36. package/types/index.d.ts +91 -54
  37. package/types/resources/Address.d.ts +57 -272
  38. package/types/resources/AdvanceInvoiceSchedule.d.ts +21 -94
  39. package/types/resources/AttachedItem.d.ts +91 -329
  40. package/types/resources/Attribute.d.ts +5 -5
  41. package/types/resources/BusinessEntity.d.ts +49 -69
  42. package/types/resources/BusinessEntityTransfer.d.ts +11 -17
  43. package/types/resources/Card.d.ts +146 -424
  44. package/types/resources/Comment.d.ts +72 -189
  45. package/types/resources/Contact.d.ts +12 -64
  46. package/types/resources/ContractTerm.d.ts +15 -96
  47. package/types/resources/Coupon.d.ts +282 -758
  48. package/types/resources/CouponCode.d.ts +56 -52
  49. package/types/resources/CouponSet.d.ts +92 -234
  50. package/types/resources/CreditNote.d.ts +589 -1757
  51. package/types/resources/CreditNoteEstimate.d.ts +131 -157
  52. package/types/resources/Currency.d.ts +75 -62
  53. package/types/resources/Customer.d.ts +892 -835
  54. package/types/resources/CustomerEntitlement.d.ts +36 -0
  55. package/types/resources/DifferentialPrice.d.ts +116 -314
  56. package/types/resources/Discount.d.ts +20 -125
  57. package/types/resources/Download.d.ts +6 -22
  58. package/types/resources/Entitlement.d.ts +51 -160
  59. package/types/resources/EntitlementOverride.d.ts +58 -139
  60. package/types/resources/Estimate.d.ts +1178 -525
  61. package/types/resources/Event.d.ts +67 -178
  62. package/types/resources/Export.d.ts +563 -723
  63. package/types/resources/Feature.d.ts +117 -433
  64. package/types/resources/GatewayErrorDetail.d.ts +16 -72
  65. package/types/resources/Gift.d.ts +265 -432
  66. package/types/resources/Hierarchy.d.ts +8 -36
  67. package/types/resources/HostedPage.d.ts +1017 -1153
  68. package/types/resources/ImpactedItem.d.ts +13 -50
  69. package/types/resources/ImpactedItemPrice.d.ts +13 -15
  70. package/types/resources/ImpactedSubscription.d.ts +13 -45
  71. package/types/resources/InAppSubscription.d.ts +93 -389
  72. package/types/resources/Installment.d.ts +35 -110
  73. package/types/resources/InstallmentConfig.d.ts +54 -155
  74. package/types/resources/InstallmentDetail.d.ts +19 -27
  75. package/types/resources/Invoice.d.ts +1574 -3157
  76. package/types/resources/InvoiceEstimate.d.ts +131 -161
  77. package/types/resources/Item.d.ts +133 -611
  78. package/types/resources/ItemEntitlement.d.ts +78 -215
  79. package/types/resources/ItemFamily.d.ts +69 -178
  80. package/types/resources/ItemPrice.d.ts +291 -1203
  81. package/types/resources/Metadata.d.ts +3 -5
  82. package/types/resources/Order.d.ts +538 -1471
  83. package/types/resources/PaymentIntent.d.ts +163 -347
  84. package/types/resources/PaymentReferenceNumber.d.ts +7 -29
  85. package/types/resources/PaymentSource.d.ts +476 -1272
  86. package/types/resources/PaymentVoucher.d.ts +87 -306
  87. package/types/resources/PortalSession.d.ts +71 -207
  88. package/types/resources/PriceVariant.d.ts +91 -279
  89. package/types/resources/PricingPageSession.d.ts +92 -41
  90. package/types/resources/PromotionalCredit.d.ts +90 -346
  91. package/types/resources/Purchase.d.ts +185 -315
  92. package/types/resources/Quote.d.ts +1407 -886
  93. package/types/resources/QuoteLineGroup.d.ts +125 -452
  94. package/types/resources/QuotedCharge.d.ts +45 -274
  95. package/types/resources/QuotedSubscription.d.ts +100 -488
  96. package/types/resources/Ramp.d.ts +233 -724
  97. package/types/resources/ResourceMigration.d.ts +25 -80
  98. package/types/resources/SiteMigrationDetail.d.ts +34 -112
  99. package/types/resources/Subscription.d.ts +2390 -4334
  100. package/types/resources/SubscriptionEntitlement.d.ts +59 -159
  101. package/types/resources/SubscriptionEstimate.d.ts +51 -75
  102. package/types/resources/TaxWithheld.d.ts +15 -40
  103. package/types/resources/ThirdPartyPaymentMethod.d.ts +7 -29
  104. package/types/resources/TimeMachine.d.ts +43 -97
  105. package/types/resources/Token.d.ts +15 -85
  106. package/types/resources/Transaction.d.ts +278 -900
  107. package/types/resources/UnbilledCharge.d.ts +189 -164
  108. package/types/resources/Usage.d.ts +89 -279
  109. package/types/resources/VirtualBankAccount.d.ts +103 -255
  110. package/types/resources/filter.d.ts +52 -0
  111. package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -81
  112. package/.github/ISSUE_TEMPLATE/config.yml +0 -6
  113. package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -34
  114. package/.github/PULL_REQUEST_TEMPLATE.md +0 -8
  115. package/lib/chargebee.js +0 -512
  116. package/lib/resources/api_endpoints.js +0 -2912
  117. package/types/resources/NonSubscription.d.ts +0 -30
  118. package/types/resources/Session.d.ts +0 -41
package/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ### v3.0.0-beta.1 (2024-08-26)
2
+ * * *
3
+
4
+ * Names of the resources, operations etc. have been changed from snake_case to camelCase. For example, configuration option api_key is now apiKey.
5
+ * Minimum Node.js version is 18
6
+ * Class based models are replaced with TypeScript types.
7
+ * Response will contain headers instead of responseHeaders.
8
+ * Response will contain isIdempotencyReplayed field instead of isIdempotencyReplayed() method.
9
+
10
+ ### v2.40.0 (2024-08-14)
11
+ * * *
12
+
13
+ #### New Attributes:
14
+ * feature_type has been added in SubscriptionEntitlement.
15
+ * business_entity_id has been made optional in Quote.
16
+ * business_entity_id has been made optional in CreditNote.
17
+
18
+ #### New Input parameters:
19
+ * invoice_usages has been added in Subscription#UpdateForItemsRequest.
20
+ * invoice_usages has been added in Estimate#UpdateSubscriptionForItemsRequest.
21
+
1
22
  ### v2.39.0 (2024-07-31)
2
23
  * * *
3
24
 
@@ -2531,4 +2552,4 @@ Support for deleting the plans & addons. See our API documentation on [Delete a
2531
2552
 
2532
2553
  ### v1.0.0 (2014-02-02)
2533
2554
  * * *
2534
- Initial version of ChargeBee NodeJS binding.
2555
+ Initial version of ChargeBee NodeJS binding.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2011-2024 ChargeBee, Inc.
3
+ Copyright (c) 2011-2024 Chargebee, Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person
6
6
  obtaining a copy of this software and associated documentation
package/README.md CHANGED
@@ -1,229 +1,147 @@
1
- # Chargebee Node.js Client Library
1
+ # Chargebee Node.js / TypeScript client library (Beta)
2
2
 
3
- [![npm](https://img.shields.io/npm/v/chargebee.svg?maxAge=3)](https://www.npmjs.com/package/chargebee)
4
- [![npm](https://img.shields.io/npm/dt/chargebee.svg?maxAge=3)](https://www.npmjs.com/package/chargebee)
5
-
6
- This is the [node.js](http://nodejs.org/) library for integrating with Chargebee. Sign up for a Chargebee account [here](https://www.chargebee.com).
7
-
8
- > **Note**
9
- > If you’re using [API V1](https://apidocs.chargebee.com/docs/api/v1), head to [chargebee-v1 branch](https://github.com/chargebee/chargebee-node/tree/chargebee-v1).
3
+ This is the [Node.js](http://nodejs.org/) library for integrating with Chargebee. Sign up for a Chargebee account [here](https://www.chargebee.com).
10
4
 
11
5
  ## Requirements
12
6
 
13
- Node 0.6 or higher.
7
+ Node.js 18 or higher.
14
8
 
15
9
  ## Installation
16
10
 
17
- Install the latest version of the library with:
11
+ Install the beta version of the library with npm:
18
12
 
19
13
  ```sh
20
- npm install chargebee
21
- # or
22
- yarn add chargebee
23
- # or
24
- pnpm install chargebee
14
+ npm install chargebee@beta
15
+ ```
16
+ With pnpm:
17
+ ```sh
18
+ pnpm add chargebee@beta
25
19
  ```
26
20
 
27
- ## Usage
21
+ With yarn:
22
+ ```sh
23
+ yarn add chargebee@beta
24
+ ```
28
25
 
29
- The package needs to be configured with your site's API key, which is available under Configure Chargebee Section. Refer [here](https://www.chargebee.com/docs/2.0/api_keys.html) for more details.
26
+ ## Usage
30
27
 
31
- The full documentation can be found on the Chargebee API Docs: [https://apidocs.chargebee.com/docs/api?lang=node](https://apidocs.chargebee.com/docs/api?lang=node)
28
+ The package needs to be configured with your site's API key, which is available under Configure Chargebee Section. Refer [here](https://www.chargebee.com/docs/2.0/api_keys.html) for more details.
32
29
 
30
+ If you're using ESM / TypeScript:
33
31
 
34
- ```js
35
- const chargebee = require('chargebee');
32
+ ```typescript
33
+ import Chargebee from 'chargebee';
36
34
 
37
- chargebee.configure({
38
- site: '<YOUR_SITE_NAME>',
39
- api_key: '<YOUR_API_KEY>',
35
+ const chargebee = new Chargebee({
36
+ site: "{{site}}",
37
+ apiKey: "{{api-key}}",
40
38
  });
41
39
  ```
42
40
 
43
- Or using ES modules,
41
+ Or using Common JS module system:
44
42
 
45
- ```js
46
- import chargebee from 'chargebee';
43
+ ```javascript
44
+ const Chargebee = require('chargebee');
47
45
 
48
- chargebee.configure({
49
- site: '<YOUR_SITE_NAME>',
50
- api_key: '<YOUR_API_KEY>',
46
+ const chargebee = new Chargebee({
47
+ site: "{{site}}",
48
+ apiKey: "{{api-key}}",
51
49
  });
52
-
53
50
  ```
54
51
 
55
52
  ### Using Async / Await
56
53
 
57
- ```js
54
+ ```typescript
58
55
  try {
59
- const result = await chargebee.customer
60
- .create({
61
- email: 'john@test.com',
62
- // other params
63
- })
64
- .request();
65
- // access customer as result.customer;
56
+ const { customer } = await chargebee.customer.create({
57
+ email: "john@test.com"
58
+ // other params
59
+ });
66
60
  } catch (err) {
67
61
  // handle error
68
62
  }
69
63
  ```
70
64
 
71
- ### Using Promises
72
-
73
- ```js
74
- chargebee.customer
75
- .create({
76
- email: 'john@test.com',
77
- // other params
78
- })
79
- .request()
80
- .then((result) => {
81
- // handle result
82
- // access customer as result.customer;
83
- })
84
- .catch((err) => {
85
- // handle error
86
- });
87
- ```
88
-
89
- ### Using callbacks
90
-
91
- ```js
92
- chargebee.customer
93
- .create({
94
- email: 'john@test.com',
95
- // other params
96
- })
97
- .request(function (error, result) {
98
- if (error) {
99
- // handle error
100
- } else {
101
- // handle result
102
- // access customer as result.customer;
103
- }
104
- });
105
- ```
106
-
107
- ### Usage with TypeScript
108
-
109
- You can import the types as shown below.
110
-
111
- ```ts
112
- import chargebee, { Customer } from 'chargebee';
113
-
114
- chargebee.configure({
115
- site: '<YOUR_SITE_NAME>',
116
- api_key: '<YOUR_API_KEY>',
117
- });
118
-
119
- const createCustomer = async () => {
120
- const inputParams: Customer.CreateInputParam = {
121
- email: 'john@test.com',
122
- first_name: 'John',
123
- last_name: 'Doe',
124
- };
125
-
126
- const { customer } = await chargebee.customer.create(inputParams).request();
127
- console.log(customer);
128
- };
129
-
130
- createCustomer();
131
- ```
132
-
133
65
  ### Using filters in the List API
134
66
 
135
- For pagination: `offset` is the parameter that is being used. The value used for this parameter must be the value returned for `next_offset` parameter in the previous API call.
67
+ For pagination, `offset` is the parameter that is being used. The value used for this parameter must be the value returned for `next_offset` parameter in the previous API call.
136
68
 
137
- ```js
138
- const fetchCustomers = async (offset) => {
139
- const result = await chargebee.customer.list({
69
+ ```typescript
70
+ async function getAllCustomers() {
71
+ const allCustomers: Customer[] = [];
72
+ let offset: string | undefined = undefined;
73
+
74
+ do {
75
+ const listCustomersReponse = await chargebee.customer.list({
140
76
  limit: 2,
141
- offset: offset,
142
- first_name: { is: 'John' },
143
- }).request();
144
-
145
- return {
146
- customers: result.list.map((obj) => obj.customer),
147
- next_offset: result.next_offset,
148
- };
149
- };
150
-
151
- const getCustomers = async () => {
152
- const { customers, next_offset } = await fetchCustomers();
153
- console.log('Offset:', next_offset); // Print the offset value
154
-
155
- // Fetching next set of customers
156
- await fetchCustomers(next_offset);
157
- };
158
-
159
- getCustomers().catch((err) => {
160
- console.log(err);
161
- });
77
+ offset,
78
+ first_name: {
79
+ is: "John"
80
+ }
81
+ });
82
+
83
+ const customers = listCustomersReponse.list.map(
84
+ (object) => object.customer
85
+ );
86
+
87
+ allCustomers.push(...customers);
88
+ offset = listCustomersReponse.next_offset;
89
+ } while (offset);
90
+
91
+ console.log(allCustomers);
92
+ }
162
93
  ```
163
94
 
164
- ### Using custom headers and custom fields:
165
-
166
- ```js
167
- const result = await chargebee.customer
168
- .create({ email: 'john@test.com', cf_host_url: 'http://xyz.com' }) //Add custom field in payload
169
- .headers({
170
- 'chargebee-event-email': 'all-disabled', // To disable webhooks
171
- 'chargebee-request-origin-ip': '192.168.1.2',
172
- })
173
- .setIdempotencyKey("safeKey")
174
- .request();
95
+ ### Using custom headers and custom fields
175
96
 
176
- const customer = result.customer;
177
- console.log(customer.cf_host_url);
97
+ ```typescript
98
+ const { customer } = await chargebee.customer.create(
99
+ {
100
+ email: "john@test.com",
101
+ cf_host_url: "http://xyz.com" // `cf_host_url` is a custom field in Customer object
102
+ },
103
+ {
104
+ "chargebee-event-email": "all-disabled" // To disable webhooks
105
+ }
106
+ );
178
107
  ```
179
108
 
180
109
  ### Creating an idempotent request
181
110
 
182
111
  [Idempotency keys](https://apidocs.chargebee.com/docs/api/idempotency?prod_cat_ver=2) are passed along with request headers to allow a safe retry of POST requests.
183
112
 
184
- ```js
185
- const result = await chargebee.customer
186
- .create({ email: 'john@test.com' })
187
- .setIdempotencyKey("safeKey")
188
- .request();
189
- const customer = result.customer;
190
- const headers = result.headers;
191
- const isIdempotencyReplayed = result.isIdempotencyReplayed;
192
- ```
193
-
194
- OR
195
-
196
- ```js
197
- chargebee.customer.create({ email: 'john@test.com', cf_host_url: 'http://xyz.com' })
198
- .setIdempotencyKey("safeKey")
199
- .request(function(error,result) {
200
- if(error){
201
- //handle error
202
- }else{
203
- const customer = result.customer;
204
- const headers = result.headers;
205
- const isIdempotencyReplayed = result.isIdempotencyReplayed;
113
+ ```typescript
114
+ const { customer, isIdempotencyReplayed } = await chargebee.customer.create(
115
+ { email: "john@test.com" },
116
+ {
117
+ "chargebee-idempotency-key": "eBs7iOFQuR7asUKHfddyxDDerOuF1JtFrLmDI" // Add idempotency key
206
118
  }
207
- });
119
+ );
120
+ console.log("isIdempotencyReplayed: ", isIdempotencyReplayed);
208
121
  ```
209
122
 
210
- ### Passing API Keys at request level
123
+ ### Creating multiple instances of Chargebee for different sites
124
+
125
+ ```typescript
126
+ const chargebeeSiteUS = new Chargebee({
127
+ apiKey: "{api-key}",
128
+ site: "my-site-us"
129
+ });
211
130
 
212
- ```js
213
- const newCust = await chargebee.customer.create({
214
- email: 'john@test.com',
215
- first_name: 'John',
216
- last_name: 'Doe'
217
- }).request({
218
- site: '<YOUR_SITE_NAME>',
219
- api_key: '<YOUR_API_KEY>',
131
+ const chargebeeSiteEU = new Chargebee({
132
+ apiKey: "{api-key}",
133
+ site: "my-site-eu"
220
134
  });
221
135
  ```
222
136
 
223
137
  ### Processing Webhooks - API Version Check
224
138
 
225
- An attribute, <b>api_version</b>, 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.
139
+ 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.
140
+
141
+ ## Feedback
142
+
143
+ If you find any bugs or have any feedback, open an issue in this repository or email it to dx@chargebee.com
226
144
 
227
145
  ## License
228
146
 
229
- See the [LICENSE](./LICENSE) file.
147
+ See the [LICENSE](./LICENSE) file.
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequestWrapper = void 0;
4
+ const util_js_1 = require("./util.js");
5
+ const coreCommon_js_1 = require("./coreCommon.js");
6
+ const node_buffer_1 = require("node:buffer");
7
+ const IDEMPOTENCY_HEADER = 'chargebee-idempotency-key';
8
+ class RequestWrapper {
9
+ constructor(args, apiCall, envArg) {
10
+ this.getRequest = () => {
11
+ return this.request();
12
+ };
13
+ this.args = args;
14
+ this.apiCall = apiCall;
15
+ this.envArg = envArg;
16
+ this.httpHeaders = {};
17
+ if (this.apiCall.hasIdInUrl) {
18
+ RequestWrapper._validateIdParam(this.args[0]);
19
+ }
20
+ }
21
+ static _validateIdParam(idParam) {
22
+ if (!idParam || typeof idParam !== 'string' || idParam.trim().length < 1) {
23
+ throw new Error('the required id parameter missing or wrong');
24
+ }
25
+ return idParam;
26
+ }
27
+ request() {
28
+ let env = {};
29
+ (0, util_js_1.extend)(true, env, this.envArg);
30
+ const urlIdParam = this.apiCall.hasIdInUrl ? this.args[0] : null;
31
+ let params = this.apiCall.hasIdInUrl
32
+ ? this.args[1]
33
+ : this.args[0];
34
+ let headers = this.apiCall.hasIdInUrl ? this.args[2] : this.args[1];
35
+ Object.assign(this.httpHeaders, headers);
36
+ const promise = new Promise(async (resolve, reject) => {
37
+ function callBackWrapper(err, response) {
38
+ if (err) {
39
+ reject(err);
40
+ }
41
+ else {
42
+ resolve(response);
43
+ }
44
+ }
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 = {};
56
+ }
57
+ let data = (0, util_js_1.encodeParams)(params);
58
+ (0, util_js_1.extend)(true, this.httpHeaders, {
59
+ Authorization: 'Basic ' + node_buffer_1.Buffer.from(env.apiKey + ':').toString('base64'),
60
+ Accept: 'application/json',
61
+ 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
62
+ 'Content-Length': data.length,
63
+ 'User-Agent': 'Chargebee-NodeJs-Client ' + env.clientVersion,
64
+ 'Lang-Version': typeof process === 'undefined' ? '' : process.version,
65
+ });
66
+ const resp = await this.envArg.httpClient.makeApiRequest({
67
+ host: (0, util_js_1.getHost)(env),
68
+ port: env.port,
69
+ path,
70
+ method: this.apiCall.httpMethod,
71
+ protocol: env.protocol,
72
+ headers: this.httpHeaders,
73
+ data: data,
74
+ timeout: env.timeout,
75
+ });
76
+ (0, coreCommon_js_1.handleResponse)(callBackWrapper, resp);
77
+ });
78
+ return (0, util_js_1.callbackifyPromise)(promise);
79
+ }
80
+ }
81
+ exports.RequestWrapper = RequestWrapper;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.waitForProcessToComplete = void 0;
4
+ const util_js_1 = require("./util.js");
5
+ const waitForProcessToComplete = (retrieveHandling, env) => {
6
+ if (typeof retrieveHandling == 'undefined' || !(0, util_js_1.isFunction)(retrieveHandling)) {
7
+ throw new Error('The handling parameter should be a method.');
8
+ }
9
+ const DummyRequestWrapper = function () {
10
+ this.request = _request;
11
+ };
12
+ const _request = function (callBack, envOptions) {
13
+ const jsonConstructor = {}.constructor;
14
+ if (typeof envOptions !== 'undefined') {
15
+ (0, util_js_1.extend)(true, env, envOptions);
16
+ }
17
+ else if (typeof callBack !== 'undefined' &&
18
+ callBack.constructor === jsonConstructor &&
19
+ !(0, util_js_1.isFunction)(callBack)) {
20
+ (0, util_js_1.extend)(true, env, callBack);
21
+ callBack = undefined;
22
+ }
23
+ if (typeof callBack !== 'undefined' && !(0, util_js_1.isFunction)(callBack)) {
24
+ throw new Error('The callback parameter passed is incorrect.');
25
+ }
26
+ const promise = new Promise((resolve, reject) => {
27
+ try {
28
+ const result = retrieveHandling();
29
+ resolve(result);
30
+ }
31
+ catch (err) {
32
+ reject(err);
33
+ }
34
+ });
35
+ return (0, util_js_1.callbackifyPromise)(promise, callBack);
36
+ };
37
+ return new DummyRequestWrapper();
38
+ };
39
+ exports.waitForProcessToComplete = waitForProcessToComplete;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const createChargebee_js_1 = require("./createChargebee.js");
4
+ const NodeClient_js_1 = require("./net/NodeClient.js");
5
+ 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();
10
+ const Chargebee = (0, createChargebee_js_1.CreateChargebee)(httpClient);
11
+ module.exports = Chargebee;
12
+ module.exports.Chargebee = Chargebee;
13
+ module.exports.default = Chargebee;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const createChargebee_js_1 = require("./createChargebee.js");
4
+ const FetchClient_js_1 = require("./net/FetchClient.js");
5
+ const httpClient = new FetchClient_js_1.FetchHttpClient();
6
+ const Chargebee = (0, createChargebee_js_1.CreateChargebee)(httpClient);
7
+ module.exports = Chargebee;
8
+ module.exports.Chargebee = Chargebee;
9
+ module.exports.default = Chargebee;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChargebeeError = void 0;
4
+ class ChargebeeError extends Error {
5
+ constructor(rawError, headers) {
6
+ super(rawError.message);
7
+ this.message = rawError.message;
8
+ this.type = rawError.type;
9
+ this.api_error_code = rawError.api_error_code;
10
+ this.http_status_code = rawError.http_status_code;
11
+ this.http_code = rawError.http_code;
12
+ this.error_code = rawError.error_code;
13
+ this.detail = rawError === null || rawError === void 0 ? void 0 : rawError.detail;
14
+ this.headers = headers;
15
+ }
16
+ }
17
+ exports.ChargebeeError = ChargebeeError;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleResponse = void 0;
4
+ exports.throwError = throwError;
5
+ const chargebeeError_js_1 = require("./chargebeeError.js");
6
+ const util_js_1 = require("./util.js");
7
+ const IDEMPOTENCY_REPLAYED_HEADER = 'chargebee-idempotency-replayed';
8
+ function throwError(callBack, rawError, headers) {
9
+ const error = new chargebeeError_js_1.ChargebeeError({
10
+ message: rawError.message,
11
+ type: rawError.type,
12
+ api_error_code: rawError.errorCode,
13
+ http_status_code: rawError.httpStatusCode,
14
+ http_code: rawError.httpStatusCode,
15
+ error_code: rawError.errorCode,
16
+ }, headers);
17
+ if (rawError['detail'] !== 'undefined') {
18
+ error['detail'] = rawError['detail'];
19
+ }
20
+ return callBack(error, null);
21
+ }
22
+ const handleResponse = async (callback, response) => {
23
+ try {
24
+ const res = await response.toJson();
25
+ const status = response.getStatusCode();
26
+ const headers = response.getHeaders();
27
+ if (status && (status < 200 || status > 299)) {
28
+ res.http_status_code = status;
29
+ res.headers = headers;
30
+ return callback(res, null);
31
+ }
32
+ else {
33
+ res.isIdempotencyReplayed = false;
34
+ if ((0, util_js_1.isNotUndefinedNEmpty)(headers[IDEMPOTENCY_REPLAYED_HEADER])) {
35
+ res.isIdempotencyReplayed = headers[IDEMPOTENCY_REPLAYED_HEADER];
36
+ }
37
+ res.headers = headers;
38
+ return callback(null, res);
39
+ }
40
+ }
41
+ catch (error) {
42
+ const status = response.getStatusCode();
43
+ const headers = response.getHeaders();
44
+ switch (status) {
45
+ case 503:
46
+ return throwError(callback, {
47
+ type: 'internal_temporary_error',
48
+ httpStatusCode: 503,
49
+ errorCode: 'internal_temporary_error',
50
+ message: 'Sorry, the server is currently unable to handle the request due to a temporary overload or scheduled maintenance. Please retry after sometime.',
51
+ detail: error,
52
+ }, headers);
53
+ case 504:
54
+ return throwError(callback, {
55
+ type: 'gateway_timeout',
56
+ httpStatusCode: 504,
57
+ errorCode: 'gateway_timeout',
58
+ message: 'The server did not receive a timely response from an upstream server, request aborted. If this problem persists, contact us at support@chargebee.com.',
59
+ detail: error,
60
+ }, headers);
61
+ default:
62
+ return throwError(callback, {
63
+ type: 'internal_error',
64
+ httpStatusCode: 500,
65
+ errorCode: 'internal_error',
66
+ message: 'Sorry, something went wrong when trying to process the request. If this problem persists, contact us at support@chargebee.com.',
67
+ detail: error,
68
+ }, headers);
69
+ }
70
+ }
71
+ };
72
+ exports.handleResponse = handleResponse;