chargebee 3.8.0-beta.1 → 3.8.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.
- package/CHANGELOG.md +65 -0
- package/README.md +0 -66
- package/cjs/RequestWrapper.js +56 -117
- package/cjs/asyncApiSupport.js +7 -7
- package/cjs/coreCommon.js +4 -4
- package/cjs/createChargebee.js +15 -16
- package/cjs/environment.js +1 -1
- package/cjs/net/ClientInterface.js +2 -2
- package/cjs/net/FetchClient.js +6 -6
- package/cjs/net/NodeClient.js +4 -4
- package/cjs/resources/api_endpoints.js +42 -0
- package/cjs/util.js +36 -61
- package/esm/RequestWrapper.js +54 -115
- package/esm/asyncApiSupport.js +1 -1
- package/esm/coreCommon.js +2 -2
- package/esm/createChargebee.js +5 -6
- package/esm/environment.js +1 -1
- package/esm/net/ClientInterface.js +1 -1
- package/esm/net/FetchClient.js +1 -1
- package/esm/net/NodeClient.js +1 -1
- package/esm/resources/api_endpoints.js +42 -0
- package/esm/util.js +36 -59
- package/package.json +1 -1
- package/types/core.d.ts +4 -0
- package/types/index.d.ts +1 -23
- package/types/resources/Configuration.d.ts +1 -0
- package/types/resources/CreditNote.d.ts +10 -1
- package/types/resources/CreditNoteEstimate.d.ts +1 -1
- package/types/resources/Estimate.d.ts +10 -0
- package/types/resources/Invoice.d.ts +40 -4
- package/types/resources/InvoiceEstimate.d.ts +1 -1
- package/types/resources/Item.d.ts +2 -1
- package/types/resources/OmnichannelSubscriptionItem.d.ts +6 -0
- package/types/resources/Quote.d.ts +139 -4
- package/types/resources/QuoteLineGroup.d.ts +1 -1
- package/types/resources/QuotedRamp.d.ts +93 -0
- package/types/resources/Subscription.d.ts +2 -0
package/cjs/util.js
CHANGED
|
@@ -7,50 +7,53 @@ exports.serialize = serialize;
|
|
|
7
7
|
exports.encodeListParams = encodeListParams;
|
|
8
8
|
exports.getHost = getHost;
|
|
9
9
|
exports.encodeParams = encodeParams;
|
|
10
|
-
exports.log = log;
|
|
11
|
-
exports.generateUUIDv4 = generateUUIDv4;
|
|
12
10
|
const extend = (deep, target, copy) => {
|
|
13
11
|
_extendsFn(deep, target, copy);
|
|
14
12
|
};
|
|
15
13
|
exports.extend = extend;
|
|
16
14
|
const _extendsFn = (...args) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
target
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (deep && copy && (typeof copy === 'object' || (0, exports.isArray)(copy))) {
|
|
39
|
-
if ((0, exports.isArray)(copy)) {
|
|
40
|
-
clone = (0, exports.isArray)(src) ? src : [];
|
|
15
|
+
{
|
|
16
|
+
let options, name, src, copy, copyIsArray, clone, target = args[0] || {}, i = 1, length = args.length, deep = false;
|
|
17
|
+
if (typeof target === 'boolean') {
|
|
18
|
+
deep = target;
|
|
19
|
+
target = args[1] || {};
|
|
20
|
+
i = 2;
|
|
21
|
+
}
|
|
22
|
+
if (typeof target !== 'object' && typeof target !== 'function') {
|
|
23
|
+
target = {};
|
|
24
|
+
}
|
|
25
|
+
if (length === i) {
|
|
26
|
+
target = this;
|
|
27
|
+
--i;
|
|
28
|
+
}
|
|
29
|
+
for (; i < length; i++) {
|
|
30
|
+
if ((options = args[i]) !== null) {
|
|
31
|
+
for (name in options) {
|
|
32
|
+
src = target[name];
|
|
33
|
+
copy = options[name];
|
|
34
|
+
if (target === copy) {
|
|
35
|
+
continue;
|
|
41
36
|
}
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
if (deep &&
|
|
38
|
+
copy &&
|
|
39
|
+
(typeof copy === 'object' || (copyIsArray = (0, exports.isArray)(copy)))) {
|
|
40
|
+
if (copyIsArray) {
|
|
41
|
+
copyIsArray = false;
|
|
42
|
+
clone = src && (0, exports.isArray)(src) ? src : [];
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
clone = src && typeof src === 'object' ? src : {};
|
|
46
|
+
}
|
|
47
|
+
target[name] = (0, exports.extend)(deep, clone, copy);
|
|
48
|
+
}
|
|
49
|
+
else if (copy !== undefined) {
|
|
50
|
+
target[name] = copy;
|
|
44
51
|
}
|
|
45
|
-
target[name] = _extendsFn(deep, clone, copy);
|
|
46
|
-
}
|
|
47
|
-
else if (copy !== undefined) {
|
|
48
|
-
target[name] = copy;
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
54
|
}
|
|
55
|
+
return target;
|
|
52
56
|
}
|
|
53
|
-
return target;
|
|
54
57
|
};
|
|
55
58
|
const isArray = (obj) => {
|
|
56
59
|
return (Array.isArray(obj) ||
|
|
@@ -218,31 +221,3 @@ function encodeParams(paramObj, serialized, scope, index, jsonKeys, level = 0) {
|
|
|
218
221
|
}
|
|
219
222
|
return serialized.join('&').replace(/%20/g, '+');
|
|
220
223
|
}
|
|
221
|
-
function log(env, { level = 'INFO', message = '', context = {}, functionName = '' }) {
|
|
222
|
-
if (!env.enableDebugLogs) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
const timestamp = new Date().toISOString();
|
|
226
|
-
const service = 'chargebee-node';
|
|
227
|
-
const metaString = Object.entries(context)
|
|
228
|
-
.map(([key, value]) => `${key}=${value}`)
|
|
229
|
-
.join(', ');
|
|
230
|
-
const logLine = `[${timestamp}] [${level.toUpperCase()}] [${service}] ${functionName} - ${message}${metaString ? ` (${metaString})` : ''}`;
|
|
231
|
-
console.debug(logLine);
|
|
232
|
-
}
|
|
233
|
-
const crypto_1 = require("crypto");
|
|
234
|
-
function generateUUIDv4() {
|
|
235
|
-
const bytes = (0, crypto_1.randomBytes)(16);
|
|
236
|
-
// Set version to 4 (UUIDv4)
|
|
237
|
-
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
238
|
-
// Set variant to 10xxxxxx
|
|
239
|
-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
240
|
-
const hex = bytes.toString('hex');
|
|
241
|
-
return [
|
|
242
|
-
hex.slice(0, 8),
|
|
243
|
-
hex.slice(8, 12),
|
|
244
|
-
hex.slice(12, 16),
|
|
245
|
-
hex.slice(16, 20),
|
|
246
|
-
hex.slice(20),
|
|
247
|
-
].join('-');
|
|
248
|
-
}
|
package/esm/RequestWrapper.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { extend, callbackifyPromise, getApiURL, encodeListParams, encodeParams, serialize, getHost,
|
|
2
|
-
import { handleResponse } from './coreCommon';
|
|
1
|
+
import { extend, callbackifyPromise, getApiURL, encodeListParams, encodeParams, serialize, getHost, } from './util.js';
|
|
2
|
+
import { handleResponse } from './coreCommon.js';
|
|
3
3
|
import { Buffer } from 'node:buffer';
|
|
4
4
|
export class RequestWrapper {
|
|
5
5
|
constructor(args, apiCall, envArg) {
|
|
@@ -20,133 +20,72 @@ export class RequestWrapper {
|
|
|
20
20
|
}
|
|
21
21
|
return idParam;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
if (!retryAfter)
|
|
25
|
-
return null;
|
|
26
|
-
const seconds = parseInt(retryAfter, 10);
|
|
27
|
-
if (!isNaN(seconds)) {
|
|
28
|
-
return seconds * 1000;
|
|
29
|
-
}
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
async request() {
|
|
23
|
+
request() {
|
|
33
24
|
let env = {};
|
|
34
25
|
extend(true, env, this.envArg);
|
|
35
|
-
const retryConfig = Object.assign({ enabled: false, maxRetries: 3, delayMs: 200, retryOn: [500, 502, 503, 504] }, env.retryConfig);
|
|
36
26
|
const urlIdParam = this.apiCall.hasIdInUrl ? this.args[0] : null;
|
|
37
27
|
let params = this.apiCall.hasIdInUrl
|
|
38
28
|
? this.args[1]
|
|
39
29
|
: this.args[0];
|
|
40
30
|
let headers = this.apiCall.hasIdInUrl ? this.args[2] : this.args[1];
|
|
41
31
|
Object.assign(this.httpHeaders, headers);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (typeof params === 'undefined' || params === null) {
|
|
51
|
-
params = {};
|
|
52
|
-
}
|
|
53
|
-
if (this.apiCall.httpMethod === 'GET') {
|
|
54
|
-
const queryParam = this.apiCall.isListReq
|
|
55
|
-
? encodeListParams(serialize(params))
|
|
56
|
-
: encodeParams(serialize(params));
|
|
57
|
-
path += '?' + queryParam;
|
|
58
|
-
params = {};
|
|
59
|
-
}
|
|
60
|
-
const jsonKeys = this.apiCall.jsonKeys;
|
|
61
|
-
const data = this.apiCall.isJsonRequest
|
|
62
|
-
? JSON.stringify(params)
|
|
63
|
-
: encodeParams(params, undefined, undefined, undefined, jsonKeys);
|
|
64
|
-
const requestHeaders = Object.assign({}, this.httpHeaders);
|
|
65
|
-
if (data.length) {
|
|
66
|
-
extend(true, requestHeaders, {
|
|
67
|
-
'Content-Length': data.length,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
const contentType = this.apiCall.isJsonRequest
|
|
71
|
-
? 'application/json;charset=UTF-8'
|
|
72
|
-
: 'application/x-www-form-urlencoded; charset=utf-8';
|
|
73
|
-
extend(true, requestHeaders, {
|
|
74
|
-
Authorization: 'Basic ' + Buffer.from(env.apiKey + ':').toString('base64'),
|
|
75
|
-
Accept: 'application/json',
|
|
76
|
-
'Content-Type': contentType,
|
|
77
|
-
'User-Agent': 'Chargebee-NodeJs-Client ' + env.clientVersion,
|
|
78
|
-
'Lang-Version': typeof process === 'undefined' ? '' : process.version,
|
|
79
|
-
});
|
|
80
|
-
if (attempt > 0) {
|
|
81
|
-
requestHeaders['X-CB-Retry-Attempt'] = attempt.toString();
|
|
32
|
+
const promise = new Promise(async (resolve, reject) => {
|
|
33
|
+
function callBackWrapper(err, response) {
|
|
34
|
+
if (err) {
|
|
35
|
+
reject(err);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
resolve(response);
|
|
39
|
+
}
|
|
82
40
|
}
|
|
83
|
-
const resp = await this.envArg.httpClient.makeApiRequest({
|
|
84
|
-
host: getHost(env, this.apiCall.subDomain),
|
|
85
|
-
port: env.port,
|
|
86
|
-
path,
|
|
87
|
-
method: this.apiCall.httpMethod,
|
|
88
|
-
protocol: env.protocol,
|
|
89
|
-
headers: requestHeaders,
|
|
90
|
-
data,
|
|
91
|
-
timeout: env.timeout,
|
|
92
|
-
});
|
|
93
|
-
return new Promise((resolve, reject) => {
|
|
94
|
-
handleResponse((err, response) => {
|
|
95
|
-
if (err)
|
|
96
|
-
return reject(err);
|
|
97
|
-
return resolve(response);
|
|
98
|
-
}, resp);
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
102
|
-
const withRetry = async (retryCount, startTime) => {
|
|
103
|
-
var _a, _b, _c, _d, _e, _f;
|
|
104
41
|
try {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const statusCode = (_d = (_c = (_a = err.statusCode) !== null && _a !== void 0 ? _a : (_b = err.response) === null || _b === void 0 ? void 0 : _b.statusCode) !== null && _c !== void 0 ? _c : err.http_code) !== null && _d !== void 0 ? _d : err.http_status_code;
|
|
109
|
-
const isRateLimitError = statusCode === 429 && retryConfig.enabled;
|
|
110
|
-
if (isRateLimitError) {
|
|
111
|
-
const headers = ((_e = err.response) === null || _e === void 0 ? void 0 : _e.headers) || err.headers || {};
|
|
112
|
-
const retryAfterHeader = (_f = headers['retry-after']) === null || _f === void 0 ? void 0 : _f.toLowerCase();
|
|
113
|
-
const parsedDelay = RequestWrapper.parseRetryAfter(retryAfterHeader);
|
|
114
|
-
if (!parsedDelay) {
|
|
115
|
-
log(env, {
|
|
116
|
-
level: 'ERROR',
|
|
117
|
-
message: `Rate limit error occurred, but no retry-after header found. Retrying in ${retryConfig.delayMs}ms.`,
|
|
118
|
-
});
|
|
119
|
-
throw err;
|
|
120
|
-
}
|
|
121
|
-
log(env, {
|
|
122
|
-
level: 'INFO',
|
|
123
|
-
message: `Rate limit error occurred. Retrying in ${parsedDelay}ms.`,
|
|
124
|
-
});
|
|
125
|
-
await delay(parsedDelay);
|
|
42
|
+
let path = getApiURL(env, this.apiCall.urlPrefix, this.apiCall.urlSuffix, urlIdParam);
|
|
43
|
+
if (typeof params === 'undefined' || params === null) {
|
|
44
|
+
params = {};
|
|
126
45
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
message: `Retrying request [${retryCount + 1}/${retryConfig.maxRetries}] in ${retryDelayMs}ms due to status code ${statusCode}.`,
|
|
46
|
+
if (this.apiCall.httpMethod === 'GET') {
|
|
47
|
+
params = serialize(params);
|
|
48
|
+
let queryParam = this.apiCall.isListReq
|
|
49
|
+
? encodeListParams(params)
|
|
50
|
+
: encodeParams(params);
|
|
51
|
+
path += '?' + queryParam;
|
|
52
|
+
params = {};
|
|
53
|
+
}
|
|
54
|
+
const jsonKeys = this.apiCall.jsonKeys;
|
|
55
|
+
let data = this.apiCall.isJsonRequest
|
|
56
|
+
? JSON.stringify(params)
|
|
57
|
+
: encodeParams(params, undefined, undefined, undefined, jsonKeys);
|
|
58
|
+
if (data.length) {
|
|
59
|
+
extend(true, this.httpHeaders, {
|
|
60
|
+
'Content-Length': data.length,
|
|
143
61
|
});
|
|
144
|
-
await delay(retryDelayMs);
|
|
145
62
|
}
|
|
146
|
-
|
|
63
|
+
const contentType = this.apiCall.isJsonRequest
|
|
64
|
+
? 'application/json;charset=UTF-8'
|
|
65
|
+
: 'application/x-www-form-urlencoded; charset=utf-8';
|
|
66
|
+
extend(true, this.httpHeaders, {
|
|
67
|
+
Authorization: 'Basic ' + Buffer.from(env.apiKey + ':').toString('base64'),
|
|
68
|
+
Accept: 'application/json',
|
|
69
|
+
'Content-Type': contentType,
|
|
70
|
+
'User-Agent': 'Chargebee-NodeJs-Client ' + env.clientVersion,
|
|
71
|
+
'Lang-Version': typeof process === 'undefined' ? '' : process.version,
|
|
72
|
+
});
|
|
73
|
+
const resp = await this.envArg.httpClient.makeApiRequest({
|
|
74
|
+
host: getHost(env, this.apiCall.subDomain),
|
|
75
|
+
port: env.port,
|
|
76
|
+
path,
|
|
77
|
+
method: this.apiCall.httpMethod,
|
|
78
|
+
protocol: env.protocol,
|
|
79
|
+
headers: this.httpHeaders,
|
|
80
|
+
data: data,
|
|
81
|
+
timeout: env.timeout,
|
|
82
|
+
});
|
|
83
|
+
handleResponse(callBackWrapper, resp);
|
|
147
84
|
}
|
|
148
|
-
|
|
149
|
-
|
|
85
|
+
catch (err) {
|
|
86
|
+
callBackWrapper(err, null);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
150
89
|
return callbackifyPromise(promise);
|
|
151
90
|
}
|
|
152
91
|
}
|
package/esm/asyncApiSupport.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isFunction, extend, callbackifyPromise } from './util';
|
|
1
|
+
import { isFunction, extend, callbackifyPromise } from './util.js';
|
|
2
2
|
export const waitForProcessToComplete = (retrieveHandling, env) => {
|
|
3
3
|
if (typeof retrieveHandling == 'undefined' || !isFunction(retrieveHandling)) {
|
|
4
4
|
throw new Error('The handling parameter should be a method.');
|
package/esm/coreCommon.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ChargebeeError } from './chargebeeError';
|
|
2
|
-
import { isNotUndefinedNEmpty } from './util';
|
|
1
|
+
import { ChargebeeError } from './chargebeeError.js';
|
|
2
|
+
import { isNotUndefinedNEmpty } from './util.js';
|
|
3
3
|
const IDEMPOTENCY_REPLAYED_HEADER = 'chargebee-idempotency-replayed';
|
|
4
4
|
export function throwError(callBack, rawError, headers) {
|
|
5
5
|
const error = new ChargebeeError({
|
package/esm/createChargebee.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { RequestWrapper } from './RequestWrapper';
|
|
2
|
-
import { Environment } from './environment';
|
|
3
|
-
import { Endpoints } from './resources/api_endpoints';
|
|
4
|
-
import { extend, sleep } from './util';
|
|
5
|
-
import { waitForProcessToComplete } from './asyncApiSupport';
|
|
1
|
+
import { RequestWrapper } from './RequestWrapper.js';
|
|
2
|
+
import { Environment } from './environment.js';
|
|
3
|
+
import { Endpoints } from './resources/api_endpoints.js';
|
|
4
|
+
import { extend, sleep } from './util.js';
|
|
5
|
+
import { waitForProcessToComplete } from './asyncApiSupport.js';
|
|
6
6
|
export const CreateChargebee = (httpClient) => {
|
|
7
7
|
const Chargebee = function (conf) {
|
|
8
8
|
this._env = Object.assign({}, Environment);
|
|
@@ -78,7 +78,6 @@ export const CreateChargebee = (httpClient) => {
|
|
|
78
78
|
subDomain: metaArr[5],
|
|
79
79
|
isJsonRequest: metaArr[6],
|
|
80
80
|
jsonKeys: metaArr[7],
|
|
81
|
-
options: metaArr[8],
|
|
82
81
|
};
|
|
83
82
|
this[res][apiCall.methodName] = this._createApiFunc(apiCall, this._env);
|
|
84
83
|
}
|
package/esm/environment.js
CHANGED
|
@@ -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.8.0
|
|
11
|
+
clientVersion: 'v3.8.0',
|
|
12
12
|
port: DEFAULT_PORT,
|
|
13
13
|
timemachineWaitInMillis: DEFAULT_TIME_MACHINE_WAIT,
|
|
14
14
|
exportWaitInMillis: DEFAULT_EXPORT_WAIT,
|
package/esm/net/FetchClient.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HttpClient, HttpClientResponse, } from './ClientInterface';
|
|
1
|
+
import { HttpClient, HttpClientResponse, } from './ClientInterface.js';
|
|
2
2
|
export class FetchHttpClient extends HttpClient {
|
|
3
3
|
async makeApiRequest(props) {
|
|
4
4
|
const headers = this._createHeaders(props.headers);
|
package/esm/net/NodeClient.js
CHANGED
|
@@ -1246,6 +1246,32 @@ export const Endpoints = {
|
|
|
1246
1246
|
isIdempotent: true,
|
|
1247
1247
|
},
|
|
1248
1248
|
],
|
|
1249
|
+
[
|
|
1250
|
+
'pauseDunning',
|
|
1251
|
+
'POST',
|
|
1252
|
+
'/invoices',
|
|
1253
|
+
'/pause_dunning',
|
|
1254
|
+
true,
|
|
1255
|
+
null,
|
|
1256
|
+
false,
|
|
1257
|
+
{},
|
|
1258
|
+
{
|
|
1259
|
+
isIdempotent: true,
|
|
1260
|
+
},
|
|
1261
|
+
],
|
|
1262
|
+
[
|
|
1263
|
+
'resumeDunning',
|
|
1264
|
+
'POST',
|
|
1265
|
+
'/invoices',
|
|
1266
|
+
'/resume_dunning',
|
|
1267
|
+
true,
|
|
1268
|
+
null,
|
|
1269
|
+
false,
|
|
1270
|
+
{},
|
|
1271
|
+
{
|
|
1272
|
+
isIdempotent: true,
|
|
1273
|
+
},
|
|
1274
|
+
],
|
|
1249
1275
|
[
|
|
1250
1276
|
'importInvoice',
|
|
1251
1277
|
'POST',
|
|
@@ -2910,6 +2936,7 @@ export const Endpoints = {
|
|
|
2910
2936
|
],
|
|
2911
2937
|
quotedSubscription: [],
|
|
2912
2938
|
quotedCharge: [],
|
|
2939
|
+
quotedRamp: [],
|
|
2913
2940
|
quoteLineGroup: [],
|
|
2914
2941
|
plan: [
|
|
2915
2942
|
[
|
|
@@ -4267,6 +4294,21 @@ export const Endpoints = {
|
|
|
4267
4294
|
},
|
|
4268
4295
|
],
|
|
4269
4296
|
],
|
|
4297
|
+
nonSubscription: [
|
|
4298
|
+
[
|
|
4299
|
+
'processReceipt',
|
|
4300
|
+
'POST',
|
|
4301
|
+
'/non_subscriptions',
|
|
4302
|
+
'/one_time_purchase',
|
|
4303
|
+
true,
|
|
4304
|
+
null,
|
|
4305
|
+
false,
|
|
4306
|
+
{},
|
|
4307
|
+
{
|
|
4308
|
+
isIdempotent: true,
|
|
4309
|
+
},
|
|
4310
|
+
],
|
|
4311
|
+
],
|
|
4270
4312
|
entitlementOverride: [
|
|
4271
4313
|
[
|
|
4272
4314
|
'addEntitlementOverrideForSubscription',
|
package/esm/util.js
CHANGED
|
@@ -2,43 +2,48 @@ export const extend = (deep, target, copy) => {
|
|
|
2
2
|
_extendsFn(deep, target, copy);
|
|
3
3
|
};
|
|
4
4
|
const _extendsFn = (...args) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
target
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (deep && copy && (typeof copy === 'object' || isArray(copy))) {
|
|
27
|
-
if (isArray(copy)) {
|
|
28
|
-
clone = isArray(src) ? src : [];
|
|
5
|
+
{
|
|
6
|
+
let options, name, src, copy, copyIsArray, clone, target = args[0] || {}, i = 1, length = args.length, deep = false;
|
|
7
|
+
if (typeof target === 'boolean') {
|
|
8
|
+
deep = target;
|
|
9
|
+
target = args[1] || {};
|
|
10
|
+
i = 2;
|
|
11
|
+
}
|
|
12
|
+
if (typeof target !== 'object' && typeof target !== 'function') {
|
|
13
|
+
target = {};
|
|
14
|
+
}
|
|
15
|
+
if (length === i) {
|
|
16
|
+
target = this;
|
|
17
|
+
--i;
|
|
18
|
+
}
|
|
19
|
+
for (; i < length; i++) {
|
|
20
|
+
if ((options = args[i]) !== null) {
|
|
21
|
+
for (name in options) {
|
|
22
|
+
src = target[name];
|
|
23
|
+
copy = options[name];
|
|
24
|
+
if (target === copy) {
|
|
25
|
+
continue;
|
|
29
26
|
}
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
if (deep &&
|
|
28
|
+
copy &&
|
|
29
|
+
(typeof copy === 'object' || (copyIsArray = isArray(copy)))) {
|
|
30
|
+
if (copyIsArray) {
|
|
31
|
+
copyIsArray = false;
|
|
32
|
+
clone = src && isArray(src) ? src : [];
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
clone = src && typeof src === 'object' ? src : {};
|
|
36
|
+
}
|
|
37
|
+
target[name] = extend(deep, clone, copy);
|
|
38
|
+
}
|
|
39
|
+
else if (copy !== undefined) {
|
|
40
|
+
target[name] = copy;
|
|
32
41
|
}
|
|
33
|
-
target[name] = _extendsFn(deep, clone, copy);
|
|
34
|
-
}
|
|
35
|
-
else if (copy !== undefined) {
|
|
36
|
-
target[name] = copy;
|
|
37
42
|
}
|
|
38
43
|
}
|
|
39
44
|
}
|
|
45
|
+
return target;
|
|
40
46
|
}
|
|
41
|
-
return target;
|
|
42
47
|
};
|
|
43
48
|
export const isArray = (obj) => {
|
|
44
49
|
return (Array.isArray(obj) ||
|
|
@@ -200,31 +205,3 @@ export function encodeParams(paramObj, serialized, scope, index, jsonKeys, level
|
|
|
200
205
|
}
|
|
201
206
|
return serialized.join('&').replace(/%20/g, '+');
|
|
202
207
|
}
|
|
203
|
-
export function log(env, { level = 'INFO', message = '', context = {}, functionName = '' }) {
|
|
204
|
-
if (!env.enableDebugLogs) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
const timestamp = new Date().toISOString();
|
|
208
|
-
const service = 'chargebee-node';
|
|
209
|
-
const metaString = Object.entries(context)
|
|
210
|
-
.map(([key, value]) => `${key}=${value}`)
|
|
211
|
-
.join(', ');
|
|
212
|
-
const logLine = `[${timestamp}] [${level.toUpperCase()}] [${service}] ${functionName} - ${message}${metaString ? ` (${metaString})` : ''}`;
|
|
213
|
-
console.debug(logLine);
|
|
214
|
-
}
|
|
215
|
-
import { randomBytes } from 'crypto';
|
|
216
|
-
export function generateUUIDv4() {
|
|
217
|
-
const bytes = randomBytes(16);
|
|
218
|
-
// Set version to 4 (UUIDv4)
|
|
219
|
-
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
220
|
-
// Set variant to 10xxxxxx
|
|
221
|
-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
222
|
-
const hex = bytes.toString('hex');
|
|
223
|
-
return [
|
|
224
|
-
hex.slice(0, 8),
|
|
225
|
-
hex.slice(8, 12),
|
|
226
|
-
hex.slice(12, 16),
|
|
227
|
-
hex.slice(16, 20),
|
|
228
|
-
hex.slice(20),
|
|
229
|
-
].join('-');
|
|
230
|
-
}
|
package/package.json
CHANGED
package/types/core.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ declare module 'chargebee' {
|
|
|
38
38
|
type BillingAlignmentModeEnum = 'immediate' | 'delayed';
|
|
39
39
|
type BillingDateModeEnum = 'using_defaults' | 'manually_set';
|
|
40
40
|
type BillingDayOfWeekModeEnum = 'using_defaults' | 'manually_set';
|
|
41
|
+
type BillingPeriodUnitEnum = 'day' | 'week' | 'month' | 'year';
|
|
42
|
+
type BillingStartOptionEnum = 'immediately' | 'on_specific_date';
|
|
41
43
|
type CancelOptionEnum =
|
|
42
44
|
| 'immediately'
|
|
43
45
|
| 'end_of_term'
|
|
@@ -54,6 +56,7 @@ declare module 'chargebee' {
|
|
|
54
56
|
| 'contract_termination'
|
|
55
57
|
| 'on_demand';
|
|
56
58
|
type ChargeOnOptionEnum = 'immediately' | 'on_event';
|
|
59
|
+
type ChargebeeResponseSchemaTypeEnum = 'plans_addons' | 'items' | 'compat';
|
|
57
60
|
type ChargesHandlingEnum = 'invoice_immediately' | 'add_to_unbilled_charges';
|
|
58
61
|
type ContractTermCancelOptionEnum =
|
|
59
62
|
| 'terminate_immediately'
|
|
@@ -345,6 +348,7 @@ declare module 'chargebee' {
|
|
|
345
348
|
| 'sales_order_updated'
|
|
346
349
|
| 'omnichannel_subscription_item_changed'
|
|
347
350
|
| 'omnichannel_subscription_item_paused'
|
|
351
|
+
| 'omnichannel_subscription_item_resumed'
|
|
348
352
|
| 'plan_created'
|
|
349
353
|
| 'plan_updated'
|
|
350
354
|
| 'plan_deleted'
|
package/types/index.d.ts
CHANGED
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
///<reference path='./resources/Quote.d.ts' />
|
|
65
65
|
///<reference path='./resources/QuoteLineGroup.d.ts' />
|
|
66
66
|
///<reference path='./resources/QuotedCharge.d.ts' />
|
|
67
|
+
///<reference path='./resources/QuotedRamp.d.ts' />
|
|
67
68
|
///<reference path='./resources/QuotedSubscription.d.ts' />
|
|
68
69
|
///<reference path='./resources/Ramp.d.ts' />
|
|
69
70
|
///<reference path='./resources/RecordedPurchase.d.ts' />
|
|
@@ -121,29 +122,6 @@ export type Config = {
|
|
|
121
122
|
* @hostSuffix url host suffix, default value is .chargebee.com
|
|
122
123
|
*/
|
|
123
124
|
hostSuffix?: string;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* @retryConfig retry configuration for the client, default value is { enabled: false, maxRetries: 3, delayMs: 1000, retryOn: [500, 502, 503, 504]}
|
|
127
|
-
*/
|
|
128
|
-
retryConfig?: RetryConfig;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @enableDebugLogs whether to enable debug logs, default value is false
|
|
132
|
-
*/
|
|
133
|
-
enableDebugLogs?: boolean;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export type RetryConfig = {
|
|
137
|
-
/**
|
|
138
|
-
* @enabled whether to enable retry logic, default value is false
|
|
139
|
-
* @maxRetries maximum number of retries, default value is 3
|
|
140
|
-
* @delayMs delay in milliseconds between retries, default value is 1000ms
|
|
141
|
-
* @retryOn array of HTTP status codes to retry on, default value is [500, 502, 503, 504]
|
|
142
|
-
*/
|
|
143
|
-
enabled?: boolean;
|
|
144
|
-
maxRetries?: number;
|
|
145
|
-
delayMs?: number;
|
|
146
|
-
retryOn?: Array<number>;
|
|
147
125
|
};
|
|
148
126
|
declare module 'chargebee' {
|
|
149
127
|
export default class Chargebee {
|