chargebee 2.40.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.
- package/CHANGELOG.md +10 -1
- package/LICENSE +1 -1
- package/README.md +90 -172
- package/cjs/RequestWrapper.js +81 -0
- package/cjs/asyncApiSupport.js +39 -0
- package/cjs/chargebee.cjs.js +13 -0
- package/cjs/chargebee.cjs.worker.js +9 -0
- package/cjs/chargebeeError.js +17 -0
- package/cjs/coreCommon.js +72 -0
- package/cjs/createChargebee.js +92 -0
- package/cjs/environment.js +18 -0
- package/cjs/filter.js +1 -0
- package/cjs/net/ClientInterface.js +40 -0
- package/cjs/net/FetchClient.js +86 -0
- package/cjs/net/NodeClient.js +61 -0
- package/cjs/package.json +1 -0
- package/cjs/resources/api_endpoints.js +1086 -0
- package/cjs/util.js +218 -0
- package/esm/RequestWrapper.js +77 -0
- package/esm/asyncApiSupport.js +35 -0
- package/esm/chargebee.esm.js +9 -0
- package/esm/chargebee.esm.worker.js +5 -0
- package/esm/chargebeeError.js +13 -0
- package/esm/coreCommon.js +67 -0
- package/esm/createChargebee.js +88 -0
- package/esm/environment.js +15 -0
- package/esm/filter.js +1 -0
- package/esm/net/ClientInterface.js +35 -0
- package/esm/net/FetchClient.js +81 -0
- package/esm/net/NodeClient.js +56 -0
- package/esm/package.json +1 -0
- package/esm/resources/api_endpoints.js +1083 -0
- package/esm/util.js +202 -0
- package/package.json +69 -38
- package/types/core.d.ts +558 -89
- package/types/index.d.ts +91 -54
- package/types/resources/Address.d.ts +57 -272
- package/types/resources/AdvanceInvoiceSchedule.d.ts +21 -94
- package/types/resources/AttachedItem.d.ts +91 -329
- package/types/resources/Attribute.d.ts +5 -5
- package/types/resources/BusinessEntity.d.ts +49 -69
- package/types/resources/BusinessEntityTransfer.d.ts +11 -17
- package/types/resources/Card.d.ts +146 -424
- package/types/resources/Comment.d.ts +72 -189
- package/types/resources/Contact.d.ts +12 -64
- package/types/resources/ContractTerm.d.ts +15 -96
- package/types/resources/Coupon.d.ts +282 -758
- package/types/resources/CouponCode.d.ts +56 -52
- package/types/resources/CouponSet.d.ts +92 -234
- package/types/resources/CreditNote.d.ts +588 -1758
- package/types/resources/CreditNoteEstimate.d.ts +131 -157
- package/types/resources/Currency.d.ts +75 -62
- package/types/resources/Customer.d.ts +892 -835
- package/types/resources/CustomerEntitlement.d.ts +36 -0
- package/types/resources/DifferentialPrice.d.ts +116 -314
- package/types/resources/Discount.d.ts +20 -125
- package/types/resources/Download.d.ts +6 -22
- package/types/resources/Entitlement.d.ts +51 -160
- package/types/resources/EntitlementOverride.d.ts +58 -139
- package/types/resources/Estimate.d.ts +1178 -527
- package/types/resources/Event.d.ts +67 -178
- package/types/resources/Export.d.ts +563 -723
- package/types/resources/Feature.d.ts +117 -433
- package/types/resources/GatewayErrorDetail.d.ts +16 -72
- package/types/resources/Gift.d.ts +265 -432
- package/types/resources/Hierarchy.d.ts +8 -36
- package/types/resources/HostedPage.d.ts +1017 -1153
- package/types/resources/ImpactedItem.d.ts +13 -50
- package/types/resources/ImpactedItemPrice.d.ts +13 -15
- package/types/resources/ImpactedSubscription.d.ts +13 -45
- package/types/resources/InAppSubscription.d.ts +93 -389
- package/types/resources/Installment.d.ts +35 -110
- package/types/resources/InstallmentConfig.d.ts +54 -155
- package/types/resources/InstallmentDetail.d.ts +19 -27
- package/types/resources/Invoice.d.ts +1574 -3157
- package/types/resources/InvoiceEstimate.d.ts +131 -161
- package/types/resources/Item.d.ts +133 -611
- package/types/resources/ItemEntitlement.d.ts +78 -215
- package/types/resources/ItemFamily.d.ts +69 -178
- package/types/resources/ItemPrice.d.ts +291 -1203
- package/types/resources/Metadata.d.ts +3 -5
- package/types/resources/Order.d.ts +538 -1471
- package/types/resources/PaymentIntent.d.ts +163 -347
- package/types/resources/PaymentReferenceNumber.d.ts +7 -29
- package/types/resources/PaymentSource.d.ts +476 -1272
- package/types/resources/PaymentVoucher.d.ts +87 -306
- package/types/resources/PortalSession.d.ts +71 -207
- package/types/resources/PriceVariant.d.ts +91 -279
- package/types/resources/PricingPageSession.d.ts +92 -41
- package/types/resources/PromotionalCredit.d.ts +90 -346
- package/types/resources/Purchase.d.ts +185 -315
- package/types/resources/Quote.d.ts +1406 -887
- package/types/resources/QuoteLineGroup.d.ts +125 -452
- package/types/resources/QuotedCharge.d.ts +45 -274
- package/types/resources/QuotedSubscription.d.ts +100 -488
- package/types/resources/Ramp.d.ts +233 -724
- package/types/resources/ResourceMigration.d.ts +25 -80
- package/types/resources/SiteMigrationDetail.d.ts +34 -112
- package/types/resources/Subscription.d.ts +2390 -4335
- package/types/resources/SubscriptionEntitlement.d.ts +59 -160
- package/types/resources/SubscriptionEstimate.d.ts +51 -75
- package/types/resources/TaxWithheld.d.ts +15 -40
- package/types/resources/ThirdPartyPaymentMethod.d.ts +7 -29
- package/types/resources/TimeMachine.d.ts +43 -97
- package/types/resources/Token.d.ts +15 -85
- package/types/resources/Transaction.d.ts +278 -900
- package/types/resources/UnbilledCharge.d.ts +189 -164
- package/types/resources/Usage.d.ts +89 -279
- package/types/resources/VirtualBankAccount.d.ts +103 -255
- package/types/resources/filter.d.ts +52 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -81
- package/.github/ISSUE_TEMPLATE/config.yml +0 -6
- package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -34
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -8
- package/lib/chargebee.js +0 -512
- package/lib/resources/api_endpoints.js +0 -2912
- package/types/resources/NonSubscription.d.ts +0 -30
- package/types/resources/Session.d.ts +0 -41
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
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
|
+
|
|
1
10
|
### v2.40.0 (2024-08-14)
|
|
2
11
|
* * *
|
|
3
12
|
|
|
@@ -2543,4 +2552,4 @@ Support for deleting the plans & addons. See our API documentation on [Delete a
|
|
|
2543
2552
|
|
|
2544
2553
|
### v1.0.0 (2014-02-02)
|
|
2545
2554
|
* * *
|
|
2546
|
-
Initial version of ChargeBee NodeJS binding.
|
|
2555
|
+
Initial version of ChargeBee NodeJS binding.
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,229 +1,147 @@
|
|
|
1
|
-
# Chargebee Node.js
|
|
1
|
+
# Chargebee Node.js / TypeScript client library (Beta)
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
[](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
|
|
7
|
+
Node.js 18 or higher.
|
|
14
8
|
|
|
15
9
|
## Installation
|
|
16
10
|
|
|
17
|
-
Install the
|
|
11
|
+
Install the beta version of the library with npm:
|
|
18
12
|
|
|
19
13
|
```sh
|
|
20
|
-
npm install chargebee
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
pnpm
|
|
14
|
+
npm install chargebee@beta
|
|
15
|
+
```
|
|
16
|
+
With pnpm:
|
|
17
|
+
```sh
|
|
18
|
+
pnpm add chargebee@beta
|
|
25
19
|
```
|
|
26
20
|
|
|
27
|
-
|
|
21
|
+
With yarn:
|
|
22
|
+
```sh
|
|
23
|
+
yarn add chargebee@beta
|
|
24
|
+
```
|
|
28
25
|
|
|
29
|
-
|
|
26
|
+
## Usage
|
|
30
27
|
|
|
31
|
-
The
|
|
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
|
-
```
|
|
35
|
-
|
|
32
|
+
```typescript
|
|
33
|
+
import Chargebee from 'chargebee';
|
|
36
34
|
|
|
37
|
-
chargebee
|
|
38
|
-
site:
|
|
39
|
-
|
|
35
|
+
const chargebee = new Chargebee({
|
|
36
|
+
site: "{{site}}",
|
|
37
|
+
apiKey: "{{api-key}}",
|
|
40
38
|
});
|
|
41
39
|
```
|
|
42
40
|
|
|
43
|
-
Or using
|
|
41
|
+
Or using Common JS module system:
|
|
44
42
|
|
|
45
|
-
```
|
|
46
|
-
|
|
43
|
+
```javascript
|
|
44
|
+
const Chargebee = require('chargebee');
|
|
47
45
|
|
|
48
|
-
chargebee
|
|
49
|
-
site:
|
|
50
|
-
|
|
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
|
-
```
|
|
54
|
+
```typescript
|
|
58
55
|
try {
|
|
59
|
-
const
|
|
60
|
-
.
|
|
61
|
-
|
|
62
|
-
|
|
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
|
|
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
|
-
```
|
|
138
|
-
|
|
139
|
-
|
|
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
|
|
142
|
-
first_name: {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
177
|
-
|
|
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
|
-
```
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
###
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
|
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;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateChargebee = void 0;
|
|
4
|
+
const RequestWrapper_js_1 = require("./RequestWrapper.js");
|
|
5
|
+
const environment_js_1 = require("./environment.js");
|
|
6
|
+
const api_endpoints_js_1 = require("./resources/api_endpoints.js");
|
|
7
|
+
const util_js_1 = require("./util.js");
|
|
8
|
+
const asyncApiSupport_js_1 = require("./asyncApiSupport.js");
|
|
9
|
+
const CreateChargebee = (httpClient) => {
|
|
10
|
+
const Chargebee = function (conf) {
|
|
11
|
+
this._env = Object.assign({}, environment_js_1.Environment);
|
|
12
|
+
(0, util_js_1.extend)(true, this._env, conf);
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
this._env.httpClient = httpClient;
|
|
15
|
+
this._buildResources();
|
|
16
|
+
this._endpoints = api_endpoints_js_1.Endpoints;
|
|
17
|
+
};
|
|
18
|
+
Chargebee.prototype = {
|
|
19
|
+
_createApiFunc(apiCall, env) {
|
|
20
|
+
return async function () {
|
|
21
|
+
const rw = new RequestWrapper_js_1.RequestWrapper(arguments, apiCall, env);
|
|
22
|
+
return rw.getRequest();
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
_waitForExport(exportId) {
|
|
26
|
+
let count = 0;
|
|
27
|
+
const retrieve = async () => {
|
|
28
|
+
while (count++ < 30) {
|
|
29
|
+
const result = await this.export.retrieve(exportId).request();
|
|
30
|
+
const exportObj = result.export;
|
|
31
|
+
if (exportObj.status === 'completed') {
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
else if (exportObj.status === 'in_process') {
|
|
35
|
+
await (0, util_js_1.sleep)(this._env.exportWaitInMillis);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
throw new Error('Export is taking too long');
|
|
43
|
+
};
|
|
44
|
+
return (0, asyncApiSupport_js_1.waitForProcessToComplete)(retrieve);
|
|
45
|
+
},
|
|
46
|
+
_timeMachineWait() {
|
|
47
|
+
let count = 0;
|
|
48
|
+
const retrieve = async () => {
|
|
49
|
+
while (count++ < 30) {
|
|
50
|
+
const result = await this.time_machine.retrieve('delorean').request();
|
|
51
|
+
const time_machine = result.time_machine;
|
|
52
|
+
if (time_machine.time_travel_status === 'succeeded') {
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
else if (time_machine.time_travel_status === 'in_progress') {
|
|
56
|
+
await (0, util_js_1.sleep)(this._env.timemachineWaitInMillis);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
throw new Error('The time travel is taking too much time');
|
|
64
|
+
};
|
|
65
|
+
return (0, asyncApiSupport_js_1.waitForProcessToComplete)(retrieve);
|
|
66
|
+
},
|
|
67
|
+
_buildResources() {
|
|
68
|
+
for (const res in api_endpoints_js_1.Endpoints) {
|
|
69
|
+
this[res] = {};
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
const apiCalls = api_endpoints_js_1.Endpoints[res];
|
|
72
|
+
for (let apiIdx = 0; apiIdx < apiCalls.length; apiIdx++) {
|
|
73
|
+
const metaArr = apiCalls[apiIdx];
|
|
74
|
+
const apiCall = {
|
|
75
|
+
methodName: metaArr[0],
|
|
76
|
+
httpMethod: metaArr[1],
|
|
77
|
+
urlPrefix: metaArr[2],
|
|
78
|
+
urlSuffix: metaArr[3],
|
|
79
|
+
hasIdInUrl: metaArr[4],
|
|
80
|
+
isListReq: metaArr[0] === 'list',
|
|
81
|
+
};
|
|
82
|
+
this[res][apiCall.methodName] = this._createApiFunc(apiCall, this._env);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
this.export.wait_for_export_completion = this._waitForExport.bind(this);
|
|
86
|
+
this.timeMachine.wait_for_time_travel_completion =
|
|
87
|
+
this._timeMachineWait.bind(this);
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
return Chargebee;
|
|
91
|
+
};
|
|
92
|
+
exports.CreateChargebee = CreateChargebee;
|