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