dodopayments 2.17.2 → 2.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/client.d.mts +8 -4
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +8 -4
  5. package/client.d.ts.map +1 -1
  6. package/client.js +14 -3
  7. package/client.js.map +1 -1
  8. package/client.mjs +14 -3
  9. package/client.mjs.map +1 -1
  10. package/internal/parse.d.mts.map +1 -1
  11. package/internal/parse.d.ts.map +1 -1
  12. package/internal/parse.js +5 -0
  13. package/internal/parse.js.map +1 -1
  14. package/internal/parse.mjs +5 -0
  15. package/internal/parse.mjs.map +1 -1
  16. package/package.json +1 -1
  17. package/resources/balances.d.mts +52 -0
  18. package/resources/balances.d.mts.map +1 -0
  19. package/resources/balances.d.ts +52 -0
  20. package/resources/balances.d.ts.map +1 -0
  21. package/resources/balances.js +16 -0
  22. package/resources/balances.js.map +1 -0
  23. package/resources/balances.mjs +12 -0
  24. package/resources/balances.mjs.map +1 -0
  25. package/resources/checkout-sessions.d.mts +289 -493
  26. package/resources/checkout-sessions.d.mts.map +1 -1
  27. package/resources/checkout-sessions.d.ts +289 -493
  28. package/resources/checkout-sessions.d.ts.map +1 -1
  29. package/resources/index.d.mts +2 -1
  30. package/resources/index.d.mts.map +1 -1
  31. package/resources/index.d.ts +2 -1
  32. package/resources/index.d.ts.map +1 -1
  33. package/resources/index.js +3 -1
  34. package/resources/index.js.map +1 -1
  35. package/resources/index.mjs +1 -0
  36. package/resources/index.mjs.map +1 -1
  37. package/resources/payments.d.mts +5 -0
  38. package/resources/payments.d.mts.map +1 -1
  39. package/resources/payments.d.ts +5 -0
  40. package/resources/payments.d.ts.map +1 -1
  41. package/resources/subscriptions.d.mts +20 -0
  42. package/resources/subscriptions.d.mts.map +1 -1
  43. package/resources/subscriptions.d.ts +20 -0
  44. package/resources/subscriptions.d.ts.map +1 -1
  45. package/resources/webhook-events.d.mts +1 -1
  46. package/resources/webhook-events.d.mts.map +1 -1
  47. package/resources/webhook-events.d.ts +1 -1
  48. package/resources/webhook-events.d.ts.map +1 -1
  49. package/src/client.ts +48 -5
  50. package/src/internal/parse.ts +6 -0
  51. package/src/resources/balances.ts +271 -0
  52. package/src/resources/checkout-sessions.ts +338 -577
  53. package/src/resources/index.ts +14 -0
  54. package/src/resources/payments.ts +6 -0
  55. package/src/resources/subscriptions.ts +22 -0
  56. package/src/resources/webhook-events.ts +6 -1
  57. package/src/version.ts +1 -1
  58. package/version.d.mts +1 -1
  59. package/version.d.ts +1 -1
  60. package/version.js +1 -1
  61. package/version.mjs +1 -1
package/src/client.ts CHANGED
@@ -33,6 +33,12 @@ import {
33
33
  AddonUpdateParams,
34
34
  Addons,
35
35
  } from './resources/addons';
36
+ import {
37
+ BalanceLedgerEntriesDefaultPageNumberPagination,
38
+ BalanceLedgerEntry,
39
+ BalanceRetrieveLedgerParams,
40
+ Balances,
41
+ } from './resources/balances';
36
42
  import {
37
43
  Brand,
38
44
  BrandCreateParams,
@@ -42,13 +48,21 @@ import {
42
48
  Brands,
43
49
  } from './resources/brands';
44
50
  import {
51
+ CheckoutSessionBillingAddress,
45
52
  CheckoutSessionCreateParams,
53
+ CheckoutSessionCustomization,
54
+ CheckoutSessionFlags,
46
55
  CheckoutSessionPreviewParams,
47
56
  CheckoutSessionPreviewResponse,
48
57
  CheckoutSessionRequest,
49
58
  CheckoutSessionResponse,
50
59
  CheckoutSessionStatus,
51
60
  CheckoutSessions,
61
+ CustomField,
62
+ ProductItemReq,
63
+ SubscriptionData,
64
+ ThemeConfig,
65
+ ThemeModeConfig,
52
66
  } from './resources/checkout-sessions';
53
67
  import {
54
68
  Discount,
@@ -738,9 +752,14 @@ export class DodoPayments {
738
752
  getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(
739
753
  path: string,
740
754
  Page: new (...args: any[]) => PageClass,
741
- opts?: RequestOptions,
755
+ opts?: PromiseOrValue<RequestOptions>,
742
756
  ): Pagination.PagePromise<PageClass, Item> {
743
- return this.requestAPIList(Page, { method: 'get', path, ...opts });
757
+ return this.requestAPIList(
758
+ Page,
759
+ opts && 'then' in opts ?
760
+ opts.then((opts) => ({ method: 'get', path, ...opts }))
761
+ : { method: 'get', path, ...opts },
762
+ );
744
763
  }
745
764
 
746
765
  requestAPIList<
@@ -748,7 +767,7 @@ export class DodoPayments {
748
767
  PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,
749
768
  >(
750
769
  Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,
751
- options: FinalRequestOptions,
770
+ options: PromiseOrValue<FinalRequestOptions>,
752
771
  ): Pagination.PagePromise<PageClass, Item> {
753
772
  const request = this.makeRequest(options, null, undefined);
754
773
  return new Pagination.PagePromise<PageClass, Item>(this as any as DodoPayments, request, Page);
@@ -761,9 +780,10 @@ export class DodoPayments {
761
780
  controller: AbortController,
762
781
  ): Promise<Response> {
763
782
  const { signal, method, ...options } = init || {};
764
- if (signal) signal.addEventListener('abort', () => controller.abort());
783
+ const abort = this._makeAbort(controller);
784
+ if (signal) signal.addEventListener('abort', abort, { once: true });
765
785
 
766
- const timeout = setTimeout(() => controller.abort(), ms);
786
+ const timeout = setTimeout(abort, ms);
767
787
 
768
788
  const isReadableBody =
769
789
  ((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
@@ -930,6 +950,12 @@ export class DodoPayments {
930
950
  return headers.values;
931
951
  }
932
952
 
953
+ private _makeAbort(controller: AbortController) {
954
+ // note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
955
+ // would capture all request options, and cause a memory leak.
956
+ return () => controller.abort();
957
+ }
958
+
933
959
  private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
934
960
  bodyHeaders: HeadersLike;
935
961
  body: BodyInit | undefined;
@@ -1006,6 +1032,7 @@ export class DodoPayments {
1006
1032
  webhookEvents: API.WebhookEvents = new API.WebhookEvents(this);
1007
1033
  usageEvents: API.UsageEvents = new API.UsageEvents(this);
1008
1034
  meters: API.Meters = new API.Meters(this);
1035
+ balances: API.Balances = new API.Balances(this);
1009
1036
  }
1010
1037
 
1011
1038
  DodoPayments.CheckoutSessions = CheckoutSessions;
@@ -1028,6 +1055,7 @@ DodoPayments.Webhooks = Webhooks;
1028
1055
  DodoPayments.WebhookEvents = WebhookEvents;
1029
1056
  DodoPayments.UsageEvents = UsageEvents;
1030
1057
  DodoPayments.Meters = Meters;
1058
+ DodoPayments.Balances = Balances;
1031
1059
 
1032
1060
  export declare namespace DodoPayments {
1033
1061
  export type RequestOptions = Opts.RequestOptions;
@@ -1046,9 +1074,17 @@ export declare namespace DodoPayments {
1046
1074
 
1047
1075
  export {
1048
1076
  CheckoutSessions as CheckoutSessions,
1077
+ type CheckoutSessionBillingAddress as CheckoutSessionBillingAddress,
1078
+ type CheckoutSessionCustomization as CheckoutSessionCustomization,
1079
+ type CheckoutSessionFlags as CheckoutSessionFlags,
1049
1080
  type CheckoutSessionRequest as CheckoutSessionRequest,
1050
1081
  type CheckoutSessionResponse as CheckoutSessionResponse,
1051
1082
  type CheckoutSessionStatus as CheckoutSessionStatus,
1083
+ type CustomField as CustomField,
1084
+ type ProductItemReq as ProductItemReq,
1085
+ type SubscriptionData as SubscriptionData,
1086
+ type ThemeConfig as ThemeConfig,
1087
+ type ThemeModeConfig as ThemeModeConfig,
1052
1088
  type CheckoutSessionPreviewResponse as CheckoutSessionPreviewResponse,
1053
1089
  type CheckoutSessionCreateParams as CheckoutSessionCreateParams,
1054
1090
  type CheckoutSessionPreviewParams as CheckoutSessionPreviewParams,
@@ -1278,4 +1314,11 @@ export declare namespace DodoPayments {
1278
1314
  type MeterCreateParams as MeterCreateParams,
1279
1315
  type MeterListParams as MeterListParams,
1280
1316
  };
1317
+
1318
+ export {
1319
+ Balances as Balances,
1320
+ type BalanceLedgerEntry as BalanceLedgerEntry,
1321
+ type BalanceLedgerEntriesDefaultPageNumberPagination as BalanceLedgerEntriesDefaultPageNumberPagination,
1322
+ type BalanceRetrieveLedgerParams as BalanceRetrieveLedgerParams,
1323
+ };
1281
1324
  }
@@ -29,6 +29,12 @@ export async function defaultParseResponse<T>(client: DodoPayments, props: APIRe
29
29
  const mediaType = contentType?.split(';')[0]?.trim();
30
30
  const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
31
31
  if (isJSON) {
32
+ const contentLength = response.headers.get('content-length');
33
+ if (contentLength === '0') {
34
+ // if there is no content we can't do anything
35
+ return undefined as T;
36
+ }
37
+
32
38
  const json = await response.json();
33
39
  return json as T;
34
40
  }
@@ -0,0 +1,271 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../core/resource';
4
+ import * as MiscAPI from './misc';
5
+ import {
6
+ DefaultPageNumberPagination,
7
+ type DefaultPageNumberPaginationParams,
8
+ PagePromise,
9
+ } from '../core/pagination';
10
+ import { RequestOptions } from '../internal/request-options';
11
+
12
+ export class Balances extends APIResource {
13
+ retrieveLedger(
14
+ query: BalanceRetrieveLedgerParams | null | undefined = {},
15
+ options?: RequestOptions,
16
+ ): PagePromise<BalanceLedgerEntriesDefaultPageNumberPagination, BalanceLedgerEntry> {
17
+ return this._client.getAPIList('/balances/ledger', DefaultPageNumberPagination<BalanceLedgerEntry>, {
18
+ query,
19
+ ...options,
20
+ });
21
+ }
22
+ }
23
+
24
+ export type BalanceLedgerEntriesDefaultPageNumberPagination = DefaultPageNumberPagination<BalanceLedgerEntry>;
25
+
26
+ export interface BalanceLedgerEntry {
27
+ id: string;
28
+
29
+ amount: number;
30
+
31
+ business_id: string;
32
+
33
+ created_at: string;
34
+
35
+ currency: MiscAPI.Currency;
36
+
37
+ event_type:
38
+ | 'payment'
39
+ | 'refund'
40
+ | 'refund_reversal'
41
+ | 'dispute'
42
+ | 'dispute_reversal'
43
+ | 'tax'
44
+ | 'tax_reversal'
45
+ | 'payment_fees'
46
+ | 'refund_fees'
47
+ | 'refund_fees_reversal'
48
+ | 'dispute_fees'
49
+ | 'payout'
50
+ | 'payout_fees'
51
+ | 'payout_reversal'
52
+ | 'payout_fees_reversal'
53
+ | 'dodo_credits'
54
+ | 'adjustment'
55
+ | 'currency_conversion';
56
+
57
+ is_credit: boolean;
58
+
59
+ usd_equivalent_amount: number;
60
+
61
+ after_balance?: number | null;
62
+
63
+ before_balance?: number | null;
64
+
65
+ description?: string | null;
66
+
67
+ reference_object_id?: string | null;
68
+ }
69
+
70
+ export interface BalanceRetrieveLedgerParams extends DefaultPageNumberPaginationParams {
71
+ /**
72
+ * Get events after this created time
73
+ */
74
+ created_at_gte?: string;
75
+
76
+ /**
77
+ * Get events created before this time
78
+ */
79
+ created_at_lte?: string;
80
+
81
+ /**
82
+ * Filter by currency
83
+ */
84
+ currency?:
85
+ | 'AED'
86
+ | 'ALL'
87
+ | 'AMD'
88
+ | 'ANG'
89
+ | 'AOA'
90
+ | 'ARS'
91
+ | 'AUD'
92
+ | 'AWG'
93
+ | 'AZN'
94
+ | 'BAM'
95
+ | 'BBD'
96
+ | 'BDT'
97
+ | 'BGN'
98
+ | 'BHD'
99
+ | 'BIF'
100
+ | 'BMD'
101
+ | 'BND'
102
+ | 'BOB'
103
+ | 'BRL'
104
+ | 'BSD'
105
+ | 'BWP'
106
+ | 'BYN'
107
+ | 'BZD'
108
+ | 'CAD'
109
+ | 'CHF'
110
+ | 'CLP'
111
+ | 'CNY'
112
+ | 'COP'
113
+ | 'CRC'
114
+ | 'CUP'
115
+ | 'CVE'
116
+ | 'CZK'
117
+ | 'DJF'
118
+ | 'DKK'
119
+ | 'DOP'
120
+ | 'DZD'
121
+ | 'EGP'
122
+ | 'ETB'
123
+ | 'EUR'
124
+ | 'FJD'
125
+ | 'FKP'
126
+ | 'GBP'
127
+ | 'GEL'
128
+ | 'GHS'
129
+ | 'GIP'
130
+ | 'GMD'
131
+ | 'GNF'
132
+ | 'GTQ'
133
+ | 'GYD'
134
+ | 'HKD'
135
+ | 'HNL'
136
+ | 'HRK'
137
+ | 'HTG'
138
+ | 'HUF'
139
+ | 'IDR'
140
+ | 'ILS'
141
+ | 'INR'
142
+ | 'IQD'
143
+ | 'JMD'
144
+ | 'JOD'
145
+ | 'JPY'
146
+ | 'KES'
147
+ | 'KGS'
148
+ | 'KHR'
149
+ | 'KMF'
150
+ | 'KRW'
151
+ | 'KWD'
152
+ | 'KYD'
153
+ | 'KZT'
154
+ | 'LAK'
155
+ | 'LBP'
156
+ | 'LKR'
157
+ | 'LRD'
158
+ | 'LSL'
159
+ | 'LYD'
160
+ | 'MAD'
161
+ | 'MDL'
162
+ | 'MGA'
163
+ | 'MKD'
164
+ | 'MMK'
165
+ | 'MNT'
166
+ | 'MOP'
167
+ | 'MRU'
168
+ | 'MUR'
169
+ | 'MVR'
170
+ | 'MWK'
171
+ | 'MXN'
172
+ | 'MYR'
173
+ | 'MZN'
174
+ | 'NAD'
175
+ | 'NGN'
176
+ | 'NIO'
177
+ | 'NOK'
178
+ | 'NPR'
179
+ | 'NZD'
180
+ | 'OMR'
181
+ | 'PAB'
182
+ | 'PEN'
183
+ | 'PGK'
184
+ | 'PHP'
185
+ | 'PKR'
186
+ | 'PLN'
187
+ | 'PYG'
188
+ | 'QAR'
189
+ | 'RON'
190
+ | 'RSD'
191
+ | 'RUB'
192
+ | 'RWF'
193
+ | 'SAR'
194
+ | 'SBD'
195
+ | 'SCR'
196
+ | 'SEK'
197
+ | 'SGD'
198
+ | 'SHP'
199
+ | 'SLE'
200
+ | 'SLL'
201
+ | 'SOS'
202
+ | 'SRD'
203
+ | 'SSP'
204
+ | 'STN'
205
+ | 'SVC'
206
+ | 'SZL'
207
+ | 'THB'
208
+ | 'TND'
209
+ | 'TOP'
210
+ | 'TRY'
211
+ | 'TTD'
212
+ | 'TWD'
213
+ | 'TZS'
214
+ | 'UAH'
215
+ | 'UGX'
216
+ | 'USD'
217
+ | 'UYU'
218
+ | 'UZS'
219
+ | 'VES'
220
+ | 'VND'
221
+ | 'VUV'
222
+ | 'WST'
223
+ | 'XAF'
224
+ | 'XCD'
225
+ | 'XOF'
226
+ | 'XPF'
227
+ | 'YER'
228
+ | 'ZAR'
229
+ | 'ZMW';
230
+
231
+ /**
232
+ * Filter by Ledger Event Type
233
+ */
234
+ event_type?:
235
+ | 'payment'
236
+ | 'refund'
237
+ | 'refund_reversal'
238
+ | 'dispute'
239
+ | 'dispute_reversal'
240
+ | 'tax'
241
+ | 'tax_reversal'
242
+ | 'payment_fees'
243
+ | 'refund_fees'
244
+ | 'refund_fees_reversal'
245
+ | 'dispute_fees'
246
+ | 'payout'
247
+ | 'payout_fees'
248
+ | 'payout_reversal'
249
+ | 'payout_fees_reversal'
250
+ | 'dodo_credits'
251
+ | 'adjustment'
252
+ | 'currency_conversion';
253
+
254
+ /**
255
+ * Min : 1, Max : 100, default 10
256
+ */
257
+ limit?: number;
258
+
259
+ /**
260
+ * Get events history of a specific object like payment/subscription/refund/dispute
261
+ */
262
+ reference_object_id?: string;
263
+ }
264
+
265
+ export declare namespace Balances {
266
+ export {
267
+ type BalanceLedgerEntry as BalanceLedgerEntry,
268
+ type BalanceLedgerEntriesDefaultPageNumberPagination as BalanceLedgerEntriesDefaultPageNumberPagination,
269
+ type BalanceRetrieveLedgerParams as BalanceRetrieveLedgerParams,
270
+ };
271
+ }