@dodopayments/sveltekit 0.2.5 → 0.2.6

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/dist/index.js CHANGED
@@ -4272,7 +4272,7 @@ const safeJSON = (text) => {
4272
4272
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
4273
4273
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
4274
4274
 
4275
- const VERSION = '2.4.6'; // x-release-please-version
4275
+ const VERSION = '2.23.2'; // x-release-please-version
4276
4276
 
4277
4277
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
4278
4278
  /**
@@ -4482,6 +4482,25 @@ const FallbackEncoder = ({ headers, body }) => {
4482
4482
  };
4483
4483
  };
4484
4484
 
4485
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
4486
+ /**
4487
+ * Basic re-implementation of `qs.stringify` for primitive types.
4488
+ */
4489
+ function stringifyQuery(query) {
4490
+ return Object.entries(query)
4491
+ .filter(([_, value]) => typeof value !== 'undefined')
4492
+ .map(([key, value]) => {
4493
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
4494
+ return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
4495
+ }
4496
+ if (value === null) {
4497
+ return `${encodeURIComponent(key)}=`;
4498
+ }
4499
+ throw new DodoPaymentsError(`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`);
4500
+ })
4501
+ .join('&');
4502
+ }
4503
+
4485
4504
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
4486
4505
  const levelNumbers = {
4487
4506
  off: 0,
@@ -4575,6 +4594,11 @@ async function defaultParseResponse(client, props) {
4575
4594
  const mediaType = contentType?.split(';')[0]?.trim();
4576
4595
  const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
4577
4596
  if (isJSON) {
4597
+ const contentLength = response.headers.get('content-length');
4598
+ if (contentLength === '0') {
4599
+ // if there is no content we can't do anything
4600
+ return undefined;
4601
+ }
4578
4602
  const json = await response.json();
4579
4603
  return json;
4580
4604
  }
@@ -4995,6 +5019,16 @@ class Addons extends APIResource {
4995
5019
  }
4996
5020
  }
4997
5021
 
5022
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5023
+ let Balances$1 = class Balances extends APIResource {
5024
+ retrieveLedger(query = {}, options) {
5025
+ return this._client.getAPIList('/balances/ledger', (DefaultPageNumberPagination), {
5026
+ query,
5027
+ ...options,
5028
+ });
5029
+ }
5030
+ };
5031
+
4998
5032
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
4999
5033
  class Brands extends APIResource {
5000
5034
  create(body, options) {
@@ -5025,66 +5059,155 @@ class CheckoutSessions extends APIResource {
5025
5059
  retrieve(id, options) {
5026
5060
  return this._client.get(path `/checkouts/${id}`, options);
5027
5061
  }
5028
- }
5029
-
5030
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5031
- let CustomerPortal$1 = class CustomerPortal extends APIResource {
5032
- create(customerID, params = {}, options) {
5033
- const { send_email } = params ?? {};
5034
- return this._client.post(path `/customers/${customerID}/customer-portal/session`, {
5035
- query: { send_email },
5036
- ...options,
5037
- });
5038
- }
5039
- };
5040
-
5041
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5042
- class LedgerEntries extends APIResource {
5043
- create(customerID, body, options) {
5044
- return this._client.post(path `/customers/${customerID}/wallets/ledger-entries`, { body, ...options });
5045
- }
5046
- list(customerID, query = {}, options) {
5047
- return this._client.getAPIList(path `/customers/${customerID}/wallets/ledger-entries`, (DefaultPageNumberPagination), { query, ...options });
5062
+ preview(body, options) {
5063
+ return this._client.post('/checkouts/preview', { body, ...options });
5048
5064
  }
5049
5065
  }
5050
5066
 
5051
5067
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5052
- class Wallets extends APIResource {
5053
- constructor() {
5054
- super(...arguments);
5055
- this.ledgerEntries = new LedgerEntries(this._client);
5056
- }
5057
- list(customerID, options) {
5058
- return this._client.get(path `/customers/${customerID}/wallets`, options);
5059
- }
5060
- }
5061
- Wallets.LedgerEntries = LedgerEntries;
5062
-
5063
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5064
- class Customers extends APIResource {
5065
- constructor() {
5066
- super(...arguments);
5067
- this.customerPortal = new CustomerPortal$1(this._client);
5068
- this.wallets = new Wallets(this._client);
5068
+ class Balances extends APIResource {
5069
+ /**
5070
+ * Returns the credit balance details for a specific customer and credit
5071
+ * entitlement.
5072
+ *
5073
+ * # Authentication
5074
+ *
5075
+ * Requires an API key with `Viewer` role or higher.
5076
+ *
5077
+ * # Path Parameters
5078
+ *
5079
+ * - `credit_entitlement_id` - The unique identifier of the credit entitlement
5080
+ * - `customer_id` - The unique identifier of the customer
5081
+ *
5082
+ * # Responses
5083
+ *
5084
+ * - `200 OK` - Returns the customer's balance
5085
+ * - `404 Not Found` - Credit entitlement or customer balance not found
5086
+ * - `500 Internal Server Error` - Database or server error
5087
+ */
5088
+ retrieve(customerID, params, options) {
5089
+ const { credit_entitlement_id } = params;
5090
+ return this._client.get(path `/credit-entitlements/${credit_entitlement_id}/balances/${customerID}`, options);
5069
5091
  }
5070
- create(body, options) {
5071
- return this._client.post('/customers', { body, ...options });
5092
+ /**
5093
+ * Returns a paginated list of customer credit balances for the given credit
5094
+ * entitlement.
5095
+ *
5096
+ * # Authentication
5097
+ *
5098
+ * Requires an API key with `Viewer` role or higher.
5099
+ *
5100
+ * # Path Parameters
5101
+ *
5102
+ * - `credit_entitlement_id` - The unique identifier of the credit entitlement
5103
+ *
5104
+ * # Query Parameters
5105
+ *
5106
+ * - `page_size` - Number of items per page (default: 10, max: 100)
5107
+ * - `page_number` - Zero-based page number (default: 0)
5108
+ * - `customer_id` - Optional filter by specific customer
5109
+ *
5110
+ * # Responses
5111
+ *
5112
+ * - `200 OK` - Returns list of customer balances
5113
+ * - `404 Not Found` - Credit entitlement not found
5114
+ * - `500 Internal Server Error` - Database or server error
5115
+ */
5116
+ list(creditEntitlementID, query = {}, options) {
5117
+ return this._client.getAPIList(path `/credit-entitlements/${creditEntitlementID}/balances`, (DefaultPageNumberPagination), { query, ...options });
5072
5118
  }
5073
- retrieve(customerID, options) {
5074
- return this._client.get(path `/customers/${customerID}`, options);
5119
+ /**
5120
+ * For credit entries, a new grant is created. For debit entries, credits are
5121
+ * deducted from existing grants using FIFO (oldest first).
5122
+ *
5123
+ * # Authentication
5124
+ *
5125
+ * Requires an API key with `Editor` role.
5126
+ *
5127
+ * # Path Parameters
5128
+ *
5129
+ * - `credit_entitlement_id` - The unique identifier of the credit entitlement
5130
+ * - `customer_id` - The unique identifier of the customer
5131
+ *
5132
+ * # Request Body
5133
+ *
5134
+ * - `entry_type` - "credit" or "debit"
5135
+ * - `amount` - Amount to credit or debit
5136
+ * - `reason` - Optional human-readable reason
5137
+ * - `expires_at` - Optional expiration for credited amount (only for credit type)
5138
+ * - `idempotency_key` - Optional key to prevent duplicate entries
5139
+ *
5140
+ * # Responses
5141
+ *
5142
+ * - `201 Created` - Ledger entry created successfully
5143
+ * - `400 Bad Request` - Invalid request (e.g., debit with insufficient balance)
5144
+ * - `404 Not Found` - Credit entitlement or customer not found
5145
+ * - `409 Conflict` - Idempotency key already exists
5146
+ * - `500 Internal Server Error` - Database or server error
5147
+ */
5148
+ createLedgerEntry(customerID, params, options) {
5149
+ const { credit_entitlement_id, ...body } = params;
5150
+ return this._client.post(path `/credit-entitlements/${credit_entitlement_id}/balances/${customerID}/ledger-entries`, { body, ...options });
5075
5151
  }
5076
- update(customerID, body, options) {
5077
- return this._client.patch(path `/customers/${customerID}`, { body, ...options });
5152
+ /**
5153
+ * Returns a paginated list of credit grants with optional filtering by status.
5154
+ *
5155
+ * # Authentication
5156
+ *
5157
+ * Requires an API key with `Viewer` role or higher.
5158
+ *
5159
+ * # Path Parameters
5160
+ *
5161
+ * - `credit_entitlement_id` - The unique identifier of the credit entitlement
5162
+ * - `customer_id` - The unique identifier of the customer
5163
+ *
5164
+ * # Query Parameters
5165
+ *
5166
+ * - `page_size` - Number of items per page (default: 10, max: 100)
5167
+ * - `page_number` - Zero-based page number (default: 0)
5168
+ * - `status` - Filter by status: active, expired, depleted
5169
+ *
5170
+ * # Responses
5171
+ *
5172
+ * - `200 OK` - Returns list of grants
5173
+ * - `404 Not Found` - Credit entitlement not found
5174
+ * - `500 Internal Server Error` - Database or server error
5175
+ */
5176
+ listGrants(customerID, params, options) {
5177
+ const { credit_entitlement_id, ...query } = params;
5178
+ return this._client.getAPIList(path `/credit-entitlements/${credit_entitlement_id}/balances/${customerID}/grants`, (DefaultPageNumberPagination), { query, ...options });
5078
5179
  }
5079
- list(query = {}, options) {
5080
- return this._client.getAPIList('/customers', (DefaultPageNumberPagination), {
5081
- query,
5082
- ...options,
5083
- });
5180
+ /**
5181
+ * Returns a paginated list of credit transaction history with optional filtering.
5182
+ *
5183
+ * # Authentication
5184
+ *
5185
+ * Requires an API key with `Viewer` role or higher.
5186
+ *
5187
+ * # Path Parameters
5188
+ *
5189
+ * - `credit_entitlement_id` - The unique identifier of the credit entitlement
5190
+ * - `customer_id` - The unique identifier of the customer
5191
+ *
5192
+ * # Query Parameters
5193
+ *
5194
+ * - `page_size` - Number of items per page (default: 10, max: 100)
5195
+ * - `page_number` - Zero-based page number (default: 0)
5196
+ * - `transaction_type` - Filter by transaction type
5197
+ * - `start_date` - Filter entries from this date
5198
+ * - `end_date` - Filter entries until this date
5199
+ *
5200
+ * # Responses
5201
+ *
5202
+ * - `200 OK` - Returns list of ledger entries
5203
+ * - `404 Not Found` - Credit entitlement not found
5204
+ * - `500 Internal Server Error` - Database or server error
5205
+ */
5206
+ listLedger(customerID, params, options) {
5207
+ const { credit_entitlement_id, ...query } = params;
5208
+ return this._client.getAPIList(path `/credit-entitlements/${credit_entitlement_id}/balances/${customerID}/ledger`, (DefaultPageNumberPagination), { query, ...options });
5084
5209
  }
5085
5210
  }
5086
- Customers.CustomerPortal = CustomerPortal$1;
5087
- Customers.Wallets = Wallets;
5088
5211
 
5089
5212
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5090
5213
  const brand_privateNullableHeaders = /* @__PURE__ */ Symbol('brand.privateNullableHeaders');
@@ -5154,6 +5277,313 @@ const buildHeaders = (newHeaders) => {
5154
5277
  return { [brand_privateNullableHeaders]: true, values: targetHeaders, nulls: nullHeaders };
5155
5278
  };
5156
5279
 
5280
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5281
+ class CreditEntitlements extends APIResource {
5282
+ constructor() {
5283
+ super(...arguments);
5284
+ this.balances = new Balances(this._client);
5285
+ }
5286
+ /**
5287
+ * Credit entitlements define reusable credit templates that can be attached to
5288
+ * products. Each entitlement defines how credits behave in terms of expiration,
5289
+ * rollover, and overage.
5290
+ *
5291
+ * # Authentication
5292
+ *
5293
+ * Requires an API key with `Editor` role.
5294
+ *
5295
+ * # Request Body
5296
+ *
5297
+ * - `name` - Human-readable name of the credit entitlement (1-255 characters,
5298
+ * required)
5299
+ * - `description` - Optional description (max 1000 characters)
5300
+ * - `precision` - Decimal precision for credit amounts (0-10 decimal places)
5301
+ * - `unit` - Unit of measurement for the credit (e.g., "API Calls", "Tokens",
5302
+ * "Credits")
5303
+ * - `expires_after_days` - Number of days after which credits expire (optional)
5304
+ * - `rollover_enabled` - Whether unused credits can rollover to the next period
5305
+ * - `rollover_percentage` - Percentage of unused credits that rollover (0-100)
5306
+ * - `rollover_timeframe_count` - Count of timeframe periods for rollover limit
5307
+ * - `rollover_timeframe_interval` - Interval type (day, week, month, year)
5308
+ * - `max_rollover_count` - Maximum number of times credits can be rolled over
5309
+ * - `overage_enabled` - Whether overage charges apply when credits run out
5310
+ * (requires price_per_unit)
5311
+ * - `overage_limit` - Maximum overage units allowed (optional)
5312
+ * - `currency` - Currency for pricing (required if price_per_unit is set)
5313
+ * - `price_per_unit` - Price per credit unit (decimal)
5314
+ *
5315
+ * # Responses
5316
+ *
5317
+ * - `201 Created` - Credit entitlement created successfully, returns the full
5318
+ * entitlement object
5319
+ * - `422 Unprocessable Entity` - Invalid request parameters or validation failure
5320
+ * - `500 Internal Server Error` - Database or server error
5321
+ *
5322
+ * # Business Logic
5323
+ *
5324
+ * - A unique ID with prefix `cde_` is automatically generated for the entitlement
5325
+ * - Created and updated timestamps are automatically set
5326
+ * - Currency is required when price_per_unit is set
5327
+ * - price_per_unit is required when overage_enabled is true
5328
+ * - rollover_timeframe_count and rollover_timeframe_interval must both be set or
5329
+ * both be null
5330
+ */
5331
+ create(body, options) {
5332
+ return this._client.post('/credit-entitlements', { body, ...options });
5333
+ }
5334
+ /**
5335
+ * Returns the full details of a single credit entitlement including all
5336
+ * configuration settings for expiration, rollover, and overage policies.
5337
+ *
5338
+ * # Authentication
5339
+ *
5340
+ * Requires an API key with `Viewer` role or higher.
5341
+ *
5342
+ * # Path Parameters
5343
+ *
5344
+ * - `id` - The unique identifier of the credit entitlement (format: `cde_...`)
5345
+ *
5346
+ * # Responses
5347
+ *
5348
+ * - `200 OK` - Returns the full credit entitlement object
5349
+ * - `404 Not Found` - Credit entitlement does not exist or does not belong to the
5350
+ * authenticated business
5351
+ * - `500 Internal Server Error` - Database or server error
5352
+ *
5353
+ * # Business Logic
5354
+ *
5355
+ * - Only non-deleted credit entitlements can be retrieved through this endpoint
5356
+ * - The entitlement must belong to the authenticated business (business_id check)
5357
+ * - Deleted entitlements return a 404 error and must be retrieved via the list
5358
+ * endpoint with `deleted=true`
5359
+ */
5360
+ retrieve(id, options) {
5361
+ return this._client.get(path `/credit-entitlements/${id}`, options);
5362
+ }
5363
+ /**
5364
+ * Allows partial updates to a credit entitlement's configuration. Only the fields
5365
+ * provided in the request body will be updated; all other fields remain unchanged.
5366
+ * This endpoint supports nullable fields using the double option pattern.
5367
+ *
5368
+ * # Authentication
5369
+ *
5370
+ * Requires an API key with `Editor` role.
5371
+ *
5372
+ * # Path Parameters
5373
+ *
5374
+ * - `id` - The unique identifier of the credit entitlement to update (format:
5375
+ * `cde_...`)
5376
+ *
5377
+ * # Request Body (all fields optional)
5378
+ *
5379
+ * - `name` - Human-readable name of the credit entitlement (1-255 characters)
5380
+ * - `description` - Optional description (max 1000 characters)
5381
+ * - `unit` - Unit of measurement for the credit (1-50 characters)
5382
+ *
5383
+ * Note: `precision` cannot be modified after creation as it would invalidate
5384
+ * existing grants.
5385
+ *
5386
+ * - `expires_after_days` - Number of days after which credits expire (use `null`
5387
+ * to remove expiration)
5388
+ * - `rollover_enabled` - Whether unused credits can rollover to the next period
5389
+ * - `rollover_percentage` - Percentage of unused credits that rollover (0-100,
5390
+ * nullable)
5391
+ * - `rollover_timeframe_count` - Count of timeframe periods for rollover limit
5392
+ * (nullable)
5393
+ * - `rollover_timeframe_interval` - Interval type (day, week, month, year,
5394
+ * nullable)
5395
+ * - `max_rollover_count` - Maximum number of times credits can be rolled over
5396
+ * (nullable)
5397
+ * - `overage_enabled` - Whether overage charges apply when credits run out
5398
+ * - `overage_limit` - Maximum overage units allowed (nullable)
5399
+ * - `currency` - Currency for pricing (nullable)
5400
+ * - `price_per_unit` - Price per credit unit (decimal, nullable)
5401
+ *
5402
+ * # Responses
5403
+ *
5404
+ * - `200 OK` - Credit entitlement updated successfully
5405
+ * - `404 Not Found` - Credit entitlement does not exist or does not belong to the
5406
+ * authenticated business
5407
+ * - `422 Unprocessable Entity` - Invalid request parameters or validation failure
5408
+ * - `500 Internal Server Error` - Database or server error
5409
+ *
5410
+ * # Business Logic
5411
+ *
5412
+ * - Only non-deleted credit entitlements can be updated
5413
+ * - Fields set to `null` explicitly will clear the database value (using double
5414
+ * option pattern)
5415
+ * - The `updated_at` timestamp is automatically updated on successful modification
5416
+ * - Changes take effect immediately but do not retroactively affect existing
5417
+ * credit grants
5418
+ * - The merged state is validated: currency required with price, rollover
5419
+ * timeframe fields together, price required for overage
5420
+ */
5421
+ update(id, body, options) {
5422
+ return this._client.patch(path `/credit-entitlements/${id}`, {
5423
+ body,
5424
+ ...options,
5425
+ headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
5426
+ });
5427
+ }
5428
+ /**
5429
+ * Returns a paginated list of credit entitlements, allowing filtering of deleted
5430
+ * entitlements. By default, only non-deleted entitlements are returned.
5431
+ *
5432
+ * # Authentication
5433
+ *
5434
+ * Requires an API key with `Viewer` role or higher.
5435
+ *
5436
+ * # Query Parameters
5437
+ *
5438
+ * - `page_size` - Number of items per page (default: 10, max: 100)
5439
+ * - `page_number` - Zero-based page number (default: 0)
5440
+ * - `deleted` - Boolean flag to list deleted entitlements instead of active ones
5441
+ * (default: false)
5442
+ *
5443
+ * # Responses
5444
+ *
5445
+ * - `200 OK` - Returns a list of credit entitlements wrapped in a response object
5446
+ * - `422 Unprocessable Entity` - Invalid query parameters (e.g., page_size > 100)
5447
+ * - `500 Internal Server Error` - Database or server error
5448
+ *
5449
+ * # Business Logic
5450
+ *
5451
+ * - Results are ordered by creation date in descending order (newest first)
5452
+ * - Only entitlements belonging to the authenticated business are returned
5453
+ * - The `deleted` parameter controls visibility of soft-deleted entitlements
5454
+ * - Pagination uses offset-based pagination (offset = page_number \* page_size)
5455
+ */
5456
+ list(query = {}, options) {
5457
+ return this._client.getAPIList('/credit-entitlements', (DefaultPageNumberPagination), {
5458
+ query,
5459
+ ...options,
5460
+ });
5461
+ }
5462
+ delete(id, options) {
5463
+ return this._client.delete(path `/credit-entitlements/${id}`, {
5464
+ ...options,
5465
+ headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
5466
+ });
5467
+ }
5468
+ /**
5469
+ * Undeletes a soft-deleted credit entitlement by clearing `deleted_at`, making it
5470
+ * available again through standard list and get endpoints.
5471
+ *
5472
+ * # Authentication
5473
+ *
5474
+ * Requires an API key with `Editor` role.
5475
+ *
5476
+ * # Path Parameters
5477
+ *
5478
+ * - `id` - The unique identifier of the credit entitlement to restore (format:
5479
+ * `cde_...`)
5480
+ *
5481
+ * # Responses
5482
+ *
5483
+ * - `200 OK` - Credit entitlement restored successfully
5484
+ * - `500 Internal Server Error` - Database error, entitlement not found, or
5485
+ * entitlement is not deleted
5486
+ *
5487
+ * # Business Logic
5488
+ *
5489
+ * - Only deleted credit entitlements can be restored
5490
+ * - The query filters for `deleted_at IS NOT NULL`, so non-deleted entitlements
5491
+ * will result in 0 rows affected
5492
+ * - If no rows are affected (entitlement doesn't exist, doesn't belong to
5493
+ * business, or is not deleted), returns 500
5494
+ * - The `updated_at` timestamp is automatically updated on successful restoration
5495
+ * - Once restored, the entitlement becomes immediately available in the standard
5496
+ * list and get endpoints
5497
+ * - All configuration settings are preserved during delete/restore operations
5498
+ *
5499
+ * # Error Handling
5500
+ *
5501
+ * This endpoint returns 500 Internal Server Error in several cases:
5502
+ *
5503
+ * - The credit entitlement does not exist
5504
+ * - The credit entitlement belongs to a different business
5505
+ * - The credit entitlement is not currently deleted (already active)
5506
+ *
5507
+ * Callers should verify the entitlement exists and is deleted before calling this
5508
+ * endpoint.
5509
+ */
5510
+ undelete(id, options) {
5511
+ return this._client.post(path `/credit-entitlements/${id}/undelete`, {
5512
+ ...options,
5513
+ headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
5514
+ });
5515
+ }
5516
+ }
5517
+ CreditEntitlements.Balances = Balances;
5518
+
5519
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5520
+ let CustomerPortal$1 = class CustomerPortal extends APIResource {
5521
+ create(customerID, params = {}, options) {
5522
+ const { send_email } = params ?? {};
5523
+ return this._client.post(path `/customers/${customerID}/customer-portal/session`, {
5524
+ query: { send_email },
5525
+ ...options,
5526
+ });
5527
+ }
5528
+ };
5529
+
5530
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5531
+ class LedgerEntries extends APIResource {
5532
+ create(customerID, body, options) {
5533
+ return this._client.post(path `/customers/${customerID}/wallets/ledger-entries`, { body, ...options });
5534
+ }
5535
+ list(customerID, query = {}, options) {
5536
+ return this._client.getAPIList(path `/customers/${customerID}/wallets/ledger-entries`, (DefaultPageNumberPagination), { query, ...options });
5537
+ }
5538
+ }
5539
+
5540
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5541
+ class Wallets extends APIResource {
5542
+ constructor() {
5543
+ super(...arguments);
5544
+ this.ledgerEntries = new LedgerEntries(this._client);
5545
+ }
5546
+ list(customerID, options) {
5547
+ return this._client.get(path `/customers/${customerID}/wallets`, options);
5548
+ }
5549
+ }
5550
+ Wallets.LedgerEntries = LedgerEntries;
5551
+
5552
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5553
+ class Customers extends APIResource {
5554
+ constructor() {
5555
+ super(...arguments);
5556
+ this.customerPortal = new CustomerPortal$1(this._client);
5557
+ this.wallets = new Wallets(this._client);
5558
+ }
5559
+ create(body, options) {
5560
+ return this._client.post('/customers', { body, ...options });
5561
+ }
5562
+ retrieve(customerID, options) {
5563
+ return this._client.get(path `/customers/${customerID}`, options);
5564
+ }
5565
+ update(customerID, body, options) {
5566
+ return this._client.patch(path `/customers/${customerID}`, { body, ...options });
5567
+ }
5568
+ list(query = {}, options) {
5569
+ return this._client.getAPIList('/customers', (DefaultPageNumberPagination), {
5570
+ query,
5571
+ ...options,
5572
+ });
5573
+ }
5574
+ /**
5575
+ * List all credit entitlements for a customer with their current balances
5576
+ */
5577
+ listCreditEntitlements(customerID, options) {
5578
+ return this._client.get(path `/customers/${customerID}/credit-entitlements`, options);
5579
+ }
5580
+ retrievePaymentMethods(customerID, options) {
5581
+ return this._client.get(path `/customers/${customerID}/payment-methods`, options);
5582
+ }
5583
+ }
5584
+ Customers.CustomerPortal = CustomerPortal$1;
5585
+ Customers.Wallets = Wallets;
5586
+
5157
5587
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5158
5588
  class Discounts extends APIResource {
5159
5589
  /**
@@ -5193,6 +5623,14 @@ class Discounts extends APIResource {
5193
5623
  headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
5194
5624
  });
5195
5625
  }
5626
+ /**
5627
+ * Validate and fetch a discount by its code name (e.g., "SAVE20"). This allows
5628
+ * real-time validation directly against the API using the human-readable discount
5629
+ * code instead of requiring the internal discount_id.
5630
+ */
5631
+ retrieveByCode(code, options) {
5632
+ return this._client.get(path `/discounts/code/${code}`, options);
5633
+ }
5196
5634
  }
5197
5635
 
5198
5636
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
@@ -5391,6 +5829,9 @@ class Misc extends APIResource {
5391
5829
 
5392
5830
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5393
5831
  class Payments extends APIResource {
5832
+ /**
5833
+ * @deprecated
5834
+ */
5394
5835
  create(body, options) {
5395
5836
  return this._client.post('/payments', { body, ...options });
5396
5837
  }
@@ -5426,11 +5867,29 @@ class Images extends APIResource {
5426
5867
  }
5427
5868
  }
5428
5869
 
5870
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5871
+ class ShortLinks extends APIResource {
5872
+ /**
5873
+ * Gives a Short Checkout URL with custom slug for a product. Uses a Static
5874
+ * Checkout URL under the hood.
5875
+ */
5876
+ create(id, body, options) {
5877
+ return this._client.post(path `/products/${id}/short_links`, { body, ...options });
5878
+ }
5879
+ /**
5880
+ * Lists all short links created by the business.
5881
+ */
5882
+ list(query = {}, options) {
5883
+ return this._client.getAPIList('/products/short_links', (DefaultPageNumberPagination), { query, ...options });
5884
+ }
5885
+ }
5886
+
5429
5887
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5430
5888
  class Products extends APIResource {
5431
5889
  constructor() {
5432
5890
  super(...arguments);
5433
5891
  this.images = new Images(this._client);
5892
+ this.shortLinks = new ShortLinks(this._client);
5434
5893
  }
5435
5894
  create(body, options) {
5436
5895
  return this._client.post('/products', { body, ...options });
@@ -5468,6 +5927,7 @@ class Products extends APIResource {
5468
5927
  }
5469
5928
  }
5470
5929
  Products.Images = Images;
5930
+ Products.ShortLinks = ShortLinks;
5471
5931
 
5472
5932
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5473
5933
  class Refunds extends APIResource {
@@ -5487,6 +5947,9 @@ class Refunds extends APIResource {
5487
5947
 
5488
5948
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
5489
5949
  class Subscriptions extends APIResource {
5950
+ /**
5951
+ * @deprecated
5952
+ */
5490
5953
  create(body, options) {
5491
5954
  return this._client.post('/subscriptions', { body, ...options });
5492
5955
  }
@@ -5512,6 +5975,15 @@ class Subscriptions extends APIResource {
5512
5975
  charge(subscriptionID, body, options) {
5513
5976
  return this._client.post(path `/subscriptions/${subscriptionID}/charge`, { body, ...options });
5514
5977
  }
5978
+ previewChangePlan(subscriptionID, body, options) {
5979
+ return this._client.post(path `/subscriptions/${subscriptionID}/change-plan/preview`, {
5980
+ body,
5981
+ ...options,
5982
+ });
5983
+ }
5984
+ retrieveCreditUsage(subscriptionID, options) {
5985
+ return this._client.get(path `/subscriptions/${subscriptionID}/credit-usage`, options);
5986
+ }
5515
5987
  /**
5516
5988
  * Get detailed usage history for a subscription that includes usage-based billing
5517
5989
  * (metered components). This endpoint provides insights into customer usage
@@ -5559,6 +6031,12 @@ class Subscriptions extends APIResource {
5559
6031
  retrieveUsageHistory(subscriptionID, query = {}, options) {
5560
6032
  return this._client.getAPIList(path `/subscriptions/${subscriptionID}/usage-history`, (DefaultPageNumberPagination), { query, ...options });
5561
6033
  }
6034
+ updatePaymentMethod(subscriptionID, body, options) {
6035
+ return this._client.post(path `/subscriptions/${subscriptionID}/update-payment-method`, {
6036
+ body,
6037
+ ...options,
6038
+ });
6039
+ }
5562
6040
  }
5563
6041
 
5564
6042
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
@@ -6680,6 +7158,8 @@ class DodoPayments {
6680
7158
  this.webhookEvents = new WebhookEvents(this);
6681
7159
  this.usageEvents = new UsageEvents(this);
6682
7160
  this.meters = new Meters(this);
7161
+ this.balances = new Balances$1(this);
7162
+ this.creditEntitlements = new CreditEntitlements(this);
6683
7163
  if (bearerToken === undefined) {
6684
7164
  throw new DodoPaymentsError("The DODO_PAYMENTS_API_KEY environment variable is missing or empty; either provide it, or instantiate the DodoPayments client with an bearerToken option, like new DodoPayments({ bearerToken: 'My Bearer Token' }).");
6685
7165
  }
@@ -6744,18 +7224,7 @@ class DodoPayments {
6744
7224
  * Basic re-implementation of `qs.stringify` for primitive types.
6745
7225
  */
6746
7226
  stringifyQuery(query) {
6747
- return Object.entries(query)
6748
- .filter(([_, value]) => typeof value !== 'undefined')
6749
- .map(([key, value]) => {
6750
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
6751
- return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
6752
- }
6753
- if (value === null) {
6754
- return `${encodeURIComponent(key)}=`;
6755
- }
6756
- throw new DodoPaymentsError(`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`);
6757
- })
6758
- .join('&');
7227
+ return stringifyQuery(query);
6759
7228
  }
6760
7229
  getUserAgent() {
6761
7230
  return `${this.constructor.name}/JS ${VERSION}`;
@@ -6919,7 +7388,9 @@ class DodoPayments {
6919
7388
  return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
6920
7389
  }
6921
7390
  getAPIList(path, Page, opts) {
6922
- return this.requestAPIList(Page, { method: 'get', path, ...opts });
7391
+ return this.requestAPIList(Page, opts && 'then' in opts ?
7392
+ opts.then((opts) => ({ method: 'get', path, ...opts }))
7393
+ : { method: 'get', path, ...opts });
6923
7394
  }
6924
7395
  requestAPIList(Page, options) {
6925
7396
  const request = this.makeRequest(options, null, undefined);
@@ -6927,9 +7398,10 @@ class DodoPayments {
6927
7398
  }
6928
7399
  async fetchWithTimeout(url, init, ms, controller) {
6929
7400
  const { signal, method, ...options } = init || {};
7401
+ const abort = this._makeAbort(controller);
6930
7402
  if (signal)
6931
- signal.addEventListener('abort', () => controller.abort());
6932
- const timeout = setTimeout(() => controller.abort(), ms);
7403
+ signal.addEventListener('abort', abort, { once: true });
7404
+ const timeout = setTimeout(abort, ms);
6933
7405
  const isReadableBody = (globalThis.ReadableStream && options.body instanceof globalThis.ReadableStream) ||
6934
7406
  (typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
6935
7407
  const fetchOptions = {
@@ -6994,9 +7466,9 @@ class DodoPayments {
6994
7466
  timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
6995
7467
  }
6996
7468
  }
6997
- // If the API asks us to wait a certain amount of time (and it's a reasonable amount),
6998
- // just do what it says, but otherwise calculate a default
6999
- if (!(timeoutMillis && 0 <= timeoutMillis && timeoutMillis < 60 * 1000)) {
7469
+ // If the API asks us to wait a certain amount of time, just do what it
7470
+ // says, but otherwise calculate a default
7471
+ if (timeoutMillis === undefined) {
7000
7472
  const maxRetries = options.maxRetries ?? this.maxRetries;
7001
7473
  timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
7002
7474
  }
@@ -7058,6 +7530,11 @@ class DodoPayments {
7058
7530
  this.validateHeaders(headers);
7059
7531
  return headers.values;
7060
7532
  }
7533
+ _makeAbort(controller) {
7534
+ // note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
7535
+ // would capture all request options, and cause a memory leak.
7536
+ return () => controller.abort();
7537
+ }
7061
7538
  buildBody({ options: { body, headers: rawHeaders } }) {
7062
7539
  if (!body) {
7063
7540
  return { bodyHeaders: undefined, body: undefined };
@@ -7086,6 +7563,13 @@ class DodoPayments {
7086
7563
  (Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))) {
7087
7564
  return { bodyHeaders: undefined, body: ReadableStreamFrom(body) };
7088
7565
  }
7566
+ else if (typeof body === 'object' &&
7567
+ headers.values.get('content-type') === 'application/x-www-form-urlencoded') {
7568
+ return {
7569
+ bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
7570
+ body: this.stringifyQuery(body),
7571
+ };
7572
+ }
7089
7573
  else {
7090
7574
  return __classPrivateFieldGet(this, _DodoPayments_encoder, "f").call(this, { body, headers });
7091
7575
  }
@@ -7130,6 +7614,8 @@ DodoPayments.Webhooks = Webhooks$1;
7130
7614
  DodoPayments.WebhookEvents = WebhookEvents;
7131
7615
  DodoPayments.UsageEvents = UsageEvents;
7132
7616
  DodoPayments.Meters = Meters;
7617
+ DodoPayments.Balances = Balances$1;
7618
+ DodoPayments.CreditEntitlements = CreditEntitlements;
7133
7619
 
7134
7620
  // src/checkout/checkout.ts
7135
7621
  var checkoutQuerySchema = objectType({
@@ -7708,23 +8194,33 @@ var PaymentSchema = objectType({
7708
8194
  payload_type: literalType("Payment"),
7709
8195
  billing: objectType({
7710
8196
  city: stringType().nullable(),
7711
- country: stringType().nullable(),
8197
+ country: stringType(),
7712
8198
  state: stringType().nullable(),
7713
8199
  street: stringType().nullable(),
7714
8200
  zipcode: stringType().nullable()
7715
8201
  }),
7716
8202
  brand_id: stringType(),
7717
8203
  business_id: stringType(),
8204
+ card_holder_name: stringType().nullable(),
7718
8205
  card_issuing_country: stringType().nullable(),
7719
8206
  card_last_four: stringType().nullable(),
7720
8207
  card_network: stringType().nullable(),
7721
8208
  card_type: stringType().nullable(),
8209
+ checkout_session_id: stringType().nullable(),
7722
8210
  created_at: stringType().transform((d) => new Date(d)),
7723
8211
  currency: stringType(),
8212
+ custom_field_responses: arrayType(
8213
+ objectType({
8214
+ key: stringType(),
8215
+ value: stringType()
8216
+ })
8217
+ ).nullable(),
7724
8218
  customer: objectType({
7725
8219
  customer_id: stringType(),
7726
8220
  email: stringType(),
7727
- name: stringType().nullable()
8221
+ metadata: recordType(anyType()),
8222
+ name: stringType(),
8223
+ phone_number: stringType().nullable()
7728
8224
  }),
7729
8225
  digital_products_delivered: booleanType(),
7730
8226
  discount_id: stringType().nullable(),
@@ -7735,27 +8231,25 @@ var PaymentSchema = objectType({
7735
8231
  created_at: stringType().transform((d) => new Date(d)),
7736
8232
  currency: stringType(),
7737
8233
  dispute_id: stringType(),
7738
- dispute_stage: enumType([
7739
- "pre_dispute",
7740
- "dispute_opened",
7741
- "dispute_won",
7742
- "dispute_lost"
7743
- ]),
8234
+ dispute_stage: enumType(["pre_dispute", "dispute", "pre_arbitration"]),
7744
8235
  dispute_status: enumType([
7745
8236
  "dispute_opened",
7746
- "dispute_won",
7747
- "dispute_lost",
8237
+ "dispute_expired",
7748
8238
  "dispute_accepted",
7749
8239
  "dispute_cancelled",
7750
- "dispute_challenged"
8240
+ "dispute_challenged",
8241
+ "dispute_won",
8242
+ "dispute_lost"
7751
8243
  ]),
7752
8244
  payment_id: stringType(),
7753
8245
  remarks: stringType().nullable()
7754
8246
  })
7755
- ).nullable(),
8247
+ ).default([]),
7756
8248
  error_code: stringType().nullable(),
7757
8249
  error_message: stringType().nullable(),
7758
- metadata: recordType(anyType()).nullable(),
8250
+ invoice_id: stringType().nullable(),
8251
+ invoice_url: stringType().nullable(),
8252
+ metadata: recordType(anyType()),
7759
8253
  payment_id: stringType(),
7760
8254
  payment_link: stringType().nullable(),
7761
8255
  payment_method: stringType().nullable(),
@@ -7768,21 +8262,34 @@ var PaymentSchema = objectType({
7768
8262
  ).nullable(),
7769
8263
  refunds: arrayType(
7770
8264
  objectType({
7771
- amount: numberType(),
8265
+ amount: numberType().nullable(),
7772
8266
  business_id: stringType(),
7773
8267
  created_at: stringType().transform((d) => new Date(d)),
7774
- currency: stringType(),
8268
+ currency: stringType().nullable(),
7775
8269
  is_partial: booleanType(),
7776
8270
  payment_id: stringType(),
7777
8271
  reason: stringType().nullable(),
7778
8272
  refund_id: stringType(),
7779
- status: enumType(["succeeded", "failed", "pending"])
8273
+ status: enumType(["succeeded", "failed", "pending", "review"])
7780
8274
  })
7781
- ).nullable(),
8275
+ ),
8276
+ refund_status: enumType(["partial", "full"]).nullable(),
7782
8277
  settlement_amount: numberType(),
7783
8278
  settlement_currency: stringType(),
7784
8279
  settlement_tax: numberType().nullable(),
7785
- status: enumType(["succeeded", "failed", "pending", "processing", "cancelled"]),
8280
+ status: enumType([
8281
+ "succeeded",
8282
+ "failed",
8283
+ "cancelled",
8284
+ "processing",
8285
+ "requires_customer_action",
8286
+ "requires_merchant_action",
8287
+ "requires_payment_method",
8288
+ "requires_confirmation",
8289
+ "requires_capture",
8290
+ "partially_captured",
8291
+ "partially_captured_and_capturable"
8292
+ ]).nullable(),
7786
8293
  subscription_id: stringType().nullable(),
7787
8294
  tax: numberType().nullable(),
7788
8295
  total_amount: numberType(),
@@ -7795,10 +8302,10 @@ var SubscriptionSchema = objectType({
7795
8302
  addon_id: stringType(),
7796
8303
  quantity: numberType()
7797
8304
  })
7798
- ).nullable(),
8305
+ ),
7799
8306
  billing: objectType({
7800
8307
  city: stringType().nullable(),
7801
- country: stringType().nullable(),
8308
+ country: stringType(),
7802
8309
  state: stringType().nullable(),
7803
8310
  street: stringType().nullable(),
7804
8311
  zipcode: stringType().nullable()
@@ -7810,15 +8317,72 @@ var SubscriptionSchema = objectType({
7810
8317
  customer: objectType({
7811
8318
  customer_id: stringType(),
7812
8319
  email: stringType(),
7813
- name: stringType().nullable()
8320
+ metadata: recordType(anyType()),
8321
+ name: stringType(),
8322
+ phone_number: stringType().nullable()
7814
8323
  }),
8324
+ custom_field_responses: arrayType(
8325
+ objectType({
8326
+ key: stringType(),
8327
+ value: stringType()
8328
+ })
8329
+ ).nullable(),
8330
+ discount_cycles_remaining: numberType().nullable(),
7815
8331
  discount_id: stringType().nullable(),
7816
- metadata: recordType(anyType()).nullable(),
7817
- next_billing_date: stringType().transform((d) => new Date(d)).nullable(),
8332
+ expires_at: stringType().transform((d) => new Date(d)).nullable(),
8333
+ credit_entitlement_cart: arrayType(
8334
+ objectType({
8335
+ credit_entitlement_id: stringType(),
8336
+ credit_entitlement_name: stringType(),
8337
+ credits_amount: stringType(),
8338
+ overage_balance: stringType(),
8339
+ overage_behavior: enumType([
8340
+ "forgive_at_reset",
8341
+ "invoice_at_billing",
8342
+ "carry_deficit",
8343
+ "carry_deficit_auto_repay"
8344
+ ]),
8345
+ overage_enabled: booleanType(),
8346
+ product_id: stringType(),
8347
+ remaining_balance: stringType(),
8348
+ rollover_enabled: booleanType(),
8349
+ unit: stringType(),
8350
+ expires_after_days: numberType().nullable(),
8351
+ low_balance_threshold_percent: numberType().nullable(),
8352
+ max_rollover_count: numberType().nullable(),
8353
+ overage_limit: stringType().nullable(),
8354
+ rollover_percentage: numberType().nullable(),
8355
+ rollover_timeframe_count: numberType().nullable(),
8356
+ rollover_timeframe_interval: enumType(["Day", "Week", "Month", "Year"]).nullable()
8357
+ })
8358
+ ),
8359
+ meter_credit_entitlement_cart: arrayType(
8360
+ objectType({
8361
+ credit_entitlement_id: stringType(),
8362
+ meter_id: stringType(),
8363
+ meter_name: stringType(),
8364
+ meter_units_per_credit: stringType(),
8365
+ product_id: stringType()
8366
+ })
8367
+ ),
8368
+ meters: arrayType(
8369
+ objectType({
8370
+ currency: stringType(),
8371
+ description: stringType().nullable(),
8372
+ free_threshold: numberType(),
8373
+ measurement_unit: stringType(),
8374
+ meter_id: stringType(),
8375
+ name: stringType(),
8376
+ price_per_unit: stringType().nullable()
8377
+ })
8378
+ ),
8379
+ metadata: recordType(anyType()),
8380
+ next_billing_date: stringType().transform((d) => new Date(d)),
7818
8381
  on_demand: booleanType(),
7819
8382
  payment_frequency_count: numberType(),
7820
8383
  payment_frequency_interval: enumType(["Day", "Week", "Month", "Year"]),
7821
- previous_billing_date: stringType().transform((d) => new Date(d)).nullable(),
8384
+ payment_method_id: stringType().nullable(),
8385
+ previous_billing_date: stringType().transform((d) => new Date(d)),
7822
8386
  product_id: stringType(),
7823
8387
  quantity: numberType(),
7824
8388
  recurring_pre_tax_amount: numberType(),
@@ -7826,7 +8390,6 @@ var SubscriptionSchema = objectType({
7826
8390
  "pending",
7827
8391
  "active",
7828
8392
  "on_hold",
7829
- "paused",
7830
8393
  "cancelled",
7831
8394
  "expired",
7832
8395
  "failed"
@@ -7834,20 +8397,29 @@ var SubscriptionSchema = objectType({
7834
8397
  subscription_id: stringType(),
7835
8398
  subscription_period_count: numberType(),
7836
8399
  subscription_period_interval: enumType(["Day", "Week", "Month", "Year"]),
8400
+ tax_id: stringType().nullable(),
7837
8401
  tax_inclusive: booleanType(),
7838
8402
  trial_period_days: numberType()
7839
8403
  });
7840
8404
  var RefundSchema = objectType({
7841
8405
  payload_type: literalType("Refund"),
7842
- amount: numberType(),
8406
+ amount: numberType().nullable(),
7843
8407
  business_id: stringType(),
7844
8408
  created_at: stringType().transform((d) => new Date(d)),
7845
- currency: stringType(),
8409
+ customer: objectType({
8410
+ customer_id: stringType(),
8411
+ email: stringType(),
8412
+ metadata: recordType(anyType()),
8413
+ name: stringType(),
8414
+ phone_number: stringType().nullable()
8415
+ }),
8416
+ currency: stringType().nullable(),
7846
8417
  is_partial: booleanType(),
8418
+ metadata: recordType(anyType()),
7847
8419
  payment_id: stringType(),
7848
8420
  reason: stringType().nullable(),
7849
8421
  refund_id: stringType(),
7850
- status: enumType(["succeeded", "failed", "pending"])
8422
+ status: enumType(["succeeded", "failed", "pending", "review"])
7851
8423
  });
7852
8424
  var DisputeSchema = objectType({
7853
8425
  payload_type: literalType("Dispute"),
@@ -7855,27 +8427,31 @@ var DisputeSchema = objectType({
7855
8427
  business_id: stringType(),
7856
8428
  created_at: stringType().transform((d) => new Date(d)),
7857
8429
  currency: stringType(),
8430
+ customer: objectType({
8431
+ customer_id: stringType(),
8432
+ email: stringType(),
8433
+ metadata: recordType(anyType()),
8434
+ name: stringType(),
8435
+ phone_number: stringType().nullable()
8436
+ }),
7858
8437
  dispute_id: stringType(),
7859
- dispute_stage: enumType([
7860
- "pre_dispute",
7861
- "dispute_opened",
7862
- "dispute_won",
7863
- "dispute_lost"
7864
- ]),
8438
+ dispute_stage: enumType(["pre_dispute", "dispute", "pre_arbitration"]),
7865
8439
  dispute_status: enumType([
7866
8440
  "dispute_opened",
7867
- "dispute_won",
7868
- "dispute_lost",
8441
+ "dispute_expired",
7869
8442
  "dispute_accepted",
7870
8443
  "dispute_cancelled",
7871
- "dispute_challenged"
8444
+ "dispute_challenged",
8445
+ "dispute_won",
8446
+ "dispute_lost"
7872
8447
  ]),
7873
8448
  payment_id: stringType(),
8449
+ reason: stringType().nullable(),
7874
8450
  remarks: stringType().nullable()
7875
8451
  });
7876
8452
  var LicenseKeySchema = objectType({
7877
8453
  payload_type: literalType("LicenseKey"),
7878
- activations_limit: numberType(),
8454
+ activations_limit: numberType().nullable(),
7879
8455
  business_id: stringType(),
7880
8456
  created_at: stringType().transform((d) => new Date(d)),
7881
8457
  customer_id: stringType(),
@@ -7885,7 +8461,7 @@ var LicenseKeySchema = objectType({
7885
8461
  key: stringType(),
7886
8462
  payment_id: stringType(),
7887
8463
  product_id: stringType(),
7888
- status: enumType(["active", "inactive", "expired"]),
8464
+ status: enumType(["active", "expired", "disabled"]),
7889
8465
  subscription_id: stringType().nullable()
7890
8466
  });
7891
8467
  var PaymentSucceededPayloadSchema = objectType({
@@ -7984,12 +8560,6 @@ var SubscriptionRenewedPayloadSchema = objectType({
7984
8560
  timestamp: stringType().transform((d) => new Date(d)),
7985
8561
  data: SubscriptionSchema
7986
8562
  });
7987
- var SubscriptionPausedPayloadSchema = objectType({
7988
- business_id: stringType(),
7989
- type: literalType("subscription.paused"),
7990
- timestamp: stringType().transform((d) => new Date(d)),
7991
- data: SubscriptionSchema
7992
- });
7993
8563
  var SubscriptionPlanChangedPayloadSchema = objectType({
7994
8564
  business_id: stringType(),
7995
8565
  type: literalType("subscription.plan_changed"),
@@ -8026,6 +8596,94 @@ var LicenseKeyCreatedPayloadSchema = objectType({
8026
8596
  timestamp: stringType().transform((d) => new Date(d)),
8027
8597
  data: LicenseKeySchema
8028
8598
  });
8599
+ var CreditLedgerEntrySchema = objectType({
8600
+ payload_type: literalType("CreditLedgerEntry"),
8601
+ id: stringType(),
8602
+ amount: stringType(),
8603
+ balance_after: stringType(),
8604
+ balance_before: stringType(),
8605
+ business_id: stringType(),
8606
+ created_at: stringType().transform((d) => new Date(d)),
8607
+ credit_entitlement_id: stringType(),
8608
+ customer_id: stringType(),
8609
+ is_credit: booleanType(),
8610
+ overage_after: stringType(),
8611
+ overage_before: stringType(),
8612
+ transaction_type: enumType([
8613
+ "credit_added",
8614
+ "credit_deducted",
8615
+ "credit_expired",
8616
+ "credit_rolled_over",
8617
+ "rollover_forfeited",
8618
+ "overage_charged",
8619
+ "auto_top_up",
8620
+ "manual_adjustment",
8621
+ "refund"
8622
+ ]),
8623
+ description: stringType().nullable(),
8624
+ grant_id: stringType().nullable(),
8625
+ reference_id: stringType().nullable(),
8626
+ reference_type: stringType().nullable()
8627
+ });
8628
+ var CreditBalanceLowSchema = objectType({
8629
+ payload_type: literalType("CreditBalanceLow"),
8630
+ customer_id: stringType(),
8631
+ subscription_id: stringType(),
8632
+ credit_entitlement_id: stringType(),
8633
+ credit_entitlement_name: stringType(),
8634
+ available_balance: stringType(),
8635
+ subscription_credits_amount: stringType(),
8636
+ threshold_percent: numberType(),
8637
+ threshold_amount: stringType()
8638
+ });
8639
+ var CreditAddedPayloadSchema = objectType({
8640
+ business_id: stringType(),
8641
+ type: literalType("credit.added"),
8642
+ timestamp: stringType().transform((d) => new Date(d)),
8643
+ data: CreditLedgerEntrySchema
8644
+ });
8645
+ var CreditDeductedPayloadSchema = objectType({
8646
+ business_id: stringType(),
8647
+ type: literalType("credit.deducted"),
8648
+ timestamp: stringType().transform((d) => new Date(d)),
8649
+ data: CreditLedgerEntrySchema
8650
+ });
8651
+ var CreditExpiredPayloadSchema = objectType({
8652
+ business_id: stringType(),
8653
+ type: literalType("credit.expired"),
8654
+ timestamp: stringType().transform((d) => new Date(d)),
8655
+ data: CreditLedgerEntrySchema
8656
+ });
8657
+ var CreditRolledOverPayloadSchema = objectType({
8658
+ business_id: stringType(),
8659
+ type: literalType("credit.rolled_over"),
8660
+ timestamp: stringType().transform((d) => new Date(d)),
8661
+ data: CreditLedgerEntrySchema
8662
+ });
8663
+ var CreditRolloverForfeitedPayloadSchema = objectType({
8664
+ business_id: stringType(),
8665
+ type: literalType("credit.rollover_forfeited"),
8666
+ timestamp: stringType().transform((d) => new Date(d)),
8667
+ data: CreditLedgerEntrySchema
8668
+ });
8669
+ var CreditOverageChargedPayloadSchema = objectType({
8670
+ business_id: stringType(),
8671
+ type: literalType("credit.overage_charged"),
8672
+ timestamp: stringType().transform((d) => new Date(d)),
8673
+ data: CreditLedgerEntrySchema
8674
+ });
8675
+ var CreditManualAdjustmentPayloadSchema = objectType({
8676
+ business_id: stringType(),
8677
+ type: literalType("credit.manual_adjustment"),
8678
+ timestamp: stringType().transform((d) => new Date(d)),
8679
+ data: CreditLedgerEntrySchema
8680
+ });
8681
+ var CreditBalanceLowPayloadSchema = objectType({
8682
+ business_id: stringType(),
8683
+ type: literalType("credit.balance_low"),
8684
+ timestamp: stringType().transform((d) => new Date(d)),
8685
+ data: CreditBalanceLowSchema
8686
+ });
8029
8687
  var WebhookPayloadSchema = discriminatedUnionType("type", [
8030
8688
  PaymentSucceededPayloadSchema,
8031
8689
  PaymentFailedPayloadSchema,
@@ -8043,13 +8701,20 @@ var WebhookPayloadSchema = discriminatedUnionType("type", [
8043
8701
  SubscriptionActivePayloadSchema,
8044
8702
  SubscriptionOnHoldPayloadSchema,
8045
8703
  SubscriptionRenewedPayloadSchema,
8046
- SubscriptionPausedPayloadSchema,
8047
8704
  SubscriptionPlanChangedPayloadSchema,
8048
8705
  SubscriptionCancelledPayloadSchema,
8049
8706
  SubscriptionFailedPayloadSchema,
8050
8707
  SubscriptionExpiredPayloadSchema,
8051
8708
  SubscriptionUpdatedPayloadSchema,
8052
- LicenseKeyCreatedPayloadSchema
8709
+ LicenseKeyCreatedPayloadSchema,
8710
+ CreditAddedPayloadSchema,
8711
+ CreditDeductedPayloadSchema,
8712
+ CreditExpiredPayloadSchema,
8713
+ CreditRolledOverPayloadSchema,
8714
+ CreditRolloverForfeitedPayloadSchema,
8715
+ CreditOverageChargedPayloadSchema,
8716
+ CreditManualAdjustmentPayloadSchema,
8717
+ CreditBalanceLowPayloadSchema
8053
8718
  ]);
8054
8719
 
8055
8720
  // ../../node_modules/@stablelib/base64/lib/base64.js
@@ -8777,9 +9442,6 @@ async function handleWebhookPayload(payload, config, context) {
8777
9442
  if (payload.type === "subscription.renewed") {
8778
9443
  await callHandler(config.onSubscriptionRenewed, payload);
8779
9444
  }
8780
- if (payload.type === "subscription.paused") {
8781
- await callHandler(config.onSubscriptionPaused, payload);
8782
- }
8783
9445
  if (payload.type === "subscription.plan_changed") {
8784
9446
  await callHandler(config.onSubscriptionPlanChanged, payload);
8785
9447
  }
@@ -8798,6 +9460,30 @@ async function handleWebhookPayload(payload, config, context) {
8798
9460
  if (payload.type === "license_key.created") {
8799
9461
  await callHandler(config.onLicenseKeyCreated, payload);
8800
9462
  }
9463
+ if (payload.type === "credit.added") {
9464
+ await callHandler(config.onCreditAdded, payload);
9465
+ }
9466
+ if (payload.type === "credit.deducted") {
9467
+ await callHandler(config.onCreditDeducted, payload);
9468
+ }
9469
+ if (payload.type === "credit.expired") {
9470
+ await callHandler(config.onCreditExpired, payload);
9471
+ }
9472
+ if (payload.type === "credit.rolled_over") {
9473
+ await callHandler(config.onCreditRolledOver, payload);
9474
+ }
9475
+ if (payload.type === "credit.rollover_forfeited") {
9476
+ await callHandler(config.onCreditRolloverForfeited, payload);
9477
+ }
9478
+ if (payload.type === "credit.overage_charged") {
9479
+ await callHandler(config.onCreditOverageCharged, payload);
9480
+ }
9481
+ if (payload.type === "credit.manual_adjustment") {
9482
+ await callHandler(config.onCreditManualAdjustment, payload);
9483
+ }
9484
+ if (payload.type === "credit.balance_low") {
9485
+ await callHandler(config.onCreditBalanceLow, payload);
9486
+ }
8801
9487
  }
8802
9488
 
8803
9489
  const Webhooks = ({ webhookKey, ...eventHandlers }) => {