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.
Files changed (118) hide show
  1. package/CHANGELOG.md +10 -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 +588 -1758
  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 -527
  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 +1406 -887
  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 -4335
  100. package/types/resources/SubscriptionEntitlement.d.ts +59 -160
  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
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Environment = void 0;
4
+ const DEFAULT_PROTOCOL = 'https';
5
+ const DEFAULT_TIME_OUT = 80000;
6
+ const DEFAULT_PORT = 443;
7
+ const DEFAULT_TIME_MACHINE_WAIT = 3000;
8
+ const DEFAULT_EXPORT_WAIT = 3000;
9
+ exports.Environment = {
10
+ protocol: DEFAULT_PROTOCOL,
11
+ hostSuffix: '.chargebee.com',
12
+ apiPath: '/api/v2',
13
+ timeout: DEFAULT_TIME_OUT,
14
+ clientVersion: 'v3.0.0-beta.1',
15
+ port: DEFAULT_PORT,
16
+ timemachineWaitInMillis: DEFAULT_TIME_MACHINE_WAIT,
17
+ exportWaitInMillis: DEFAULT_EXPORT_WAIT,
18
+ };
package/cjs/filter.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpClientResponse = exports.HttpClient = void 0;
4
+ const chargebeeError_js_1 = require("../chargebeeError.js");
5
+ class HttpClient {
6
+ async makeApiRequest(props) {
7
+ throw new Error('makeApiRequest is not implemented');
8
+ }
9
+ static timeOutError() {
10
+ const error = new chargebeeError_js_1.ChargebeeError({
11
+ message: 'io_error',
12
+ type: 'timeout',
13
+ api_error_code: 'request aborted due to timeout.',
14
+ http_status_code: 504,
15
+ http_code: 504,
16
+ error_code: 'request aborted due to timeout.',
17
+ }, null);
18
+ return error;
19
+ }
20
+ }
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;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FetchHttpClientResponse = exports.FetchHttpClient = void 0;
4
+ const ClientInterface_js_1 = require("./ClientInterface.js");
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
+ };
14
+ const response = globalThis.AbortController
15
+ ? await this.fetchWithAbortTimeout(url, fetchOptions, props.timeout)
16
+ : await this.fetchWithTimeout(url, fetchOptions, props.timeout);
17
+ return new FetchHttpClientResponse(response);
18
+ }
19
+ _createHeaders(httpHeaders) {
20
+ const headers = new Headers();
21
+ Object.entries(httpHeaders).forEach(([key, value]) => {
22
+ headers.append(key, String(value));
23
+ });
24
+ return headers;
25
+ }
26
+ async fetchWithTimeout(url, fetchOptions, timeout) {
27
+ let pendingTimeoutId;
28
+ const timeoutPromise = new Promise((_, reject) => {
29
+ pendingTimeoutId = setTimeout(() => {
30
+ pendingTimeoutId = null;
31
+ reject(ClientInterface_js_1.HttpClient.timeOutError());
32
+ }, timeout);
33
+ });
34
+ const fetchPromise = fetch(url, fetchOptions);
35
+ return Promise.race([fetchPromise, timeoutPromise]).finally(() => {
36
+ if (pendingTimeoutId) {
37
+ clearTimeout(pendingTimeoutId);
38
+ }
39
+ });
40
+ }
41
+ async fetchWithAbortTimeout(url, fetchOptions, timeout) {
42
+ const abort = new AbortController();
43
+ let timeoutId = setTimeout(() => {
44
+ timeoutId = null;
45
+ abort.abort(ClientInterface_js_1.HttpClient.timeOutError());
46
+ }, timeout);
47
+ const fetchPromise = fetch(url, Object.assign(Object.assign({}, fetchOptions), { signal: abort.signal }));
48
+ fetchPromise.finally(() => {
49
+ if (timeoutId) {
50
+ clearTimeout(timeoutId);
51
+ }
52
+ });
53
+ return fetchPromise.catch((err) => {
54
+ if (err.name === 'AbortError') {
55
+ throw ClientInterface_js_1.HttpClient.timeOutError();
56
+ }
57
+ else {
58
+ throw err;
59
+ }
60
+ });
61
+ }
62
+ }
63
+ exports.FetchHttpClient = FetchHttpClient;
64
+ class FetchHttpClientResponse extends ClientInterface_js_1.HttpClientResponse {
65
+ constructor(response) {
66
+ super(response.status, FetchHttpClientResponse._transformHeadersToObject(response.headers));
67
+ this._res = response;
68
+ }
69
+ getRawResponse() {
70
+ return this._res;
71
+ }
72
+ toJson() {
73
+ return this._res.json();
74
+ }
75
+ static _transformHeadersToObject(headers) {
76
+ const headersObj = {};
77
+ for (const entry of headers) {
78
+ if (!Array.isArray(entry) || entry.length != 2) {
79
+ throw new Error('Headers should be an iterable object.');
80
+ }
81
+ headersObj[entry[0]] = entry[1];
82
+ }
83
+ return headersObj;
84
+ }
85
+ }
86
+ exports.FetchHttpClientResponse = FetchHttpClientResponse;
@@ -0,0 +1,61 @@
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;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}