@commet/node 7.0.0 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -200,6 +200,35 @@ var InvoicesResource = class {
200
200
  }
201
201
  };
202
202
 
203
+ // src/resources/payments.ts
204
+ var PaymentsResource = class {
205
+ constructor(httpClient) {
206
+ this.httpClient = httpClient;
207
+ }
208
+ /** List payments with cursor-based pagination. Filter by customer. */
209
+ async list(params, options) {
210
+ return this.httpClient.get("/payments", params, options);
211
+ }
212
+ /** Create a hosted payment link. Returns a url the customer opens to pay with any card. Calculates tax, generates an invoice, and vaults the payment method on confirmation. No subscription or plan required. */
213
+ async create(params, options) {
214
+ return this.httpClient.post("/payments", params, options);
215
+ }
216
+ /** Charge a customer's vaulted payment method off-session. Calculates tax, generates an invoice, and sends a receipt. No subscription or plan required. */
217
+ async charge(params, options) {
218
+ return this.httpClient.post("/payments/charge", params, options);
219
+ }
220
+ /** Retrieve a payment by its public ID. */
221
+ async get(params, options) {
222
+ const { id } = params;
223
+ return this.httpClient.get(`/payments/${id}`, void 0, options);
224
+ }
225
+ /** Cancel a pending payment link so it can no longer be paid. Only a link that has not been paid or started processing can be canceled; canceling an already canceled link is a no-op. Charges cannot be canceled. */
226
+ async cancel(params, options) {
227
+ const { id } = params;
228
+ return this.httpClient.post(`/payments/${id}/cancel`, {}, options);
229
+ }
230
+ };
231
+
203
232
  // src/resources/payouts.ts
204
233
  var PayoutsResource = class {
205
234
  constructor(httpClient) {
@@ -507,6 +536,29 @@ var SubscriptionsResource = class {
507
536
  const { id } = params;
508
537
  return this.httpClient.post(`/subscriptions/${id}/uncancel`, {}, options);
509
538
  }
539
+ /** Retries the outstanding renewal charge for a past_due subscription. On a successful charge the subscription recovers to active and a payment.recovered webhook is delivered; a declined charge returns an error and the subscription stays past_due. */
540
+ async reactivate(params, options) {
541
+ const { id } = params;
542
+ return this.httpClient.post(`/subscriptions/${id}/reactivate`, {}, options);
543
+ }
544
+ /** Generates a hosted, signed recovery link that lets the customer pay the outstanding renewal charge for a past_due subscription. Unlike reactivate, which charges server-to-server, this returns a link the merchant can deliver through their own email, SMS, or dashboard. The link carries a self-contained signed token and stays valid until the charge is paid or the subscription is no longer past due. */
545
+ async createRecoveryLink(params, options) {
546
+ const { id } = params;
547
+ return this.httpClient.post(
548
+ `/subscriptions/${id}/recovery-link`,
549
+ {},
550
+ options
551
+ );
552
+ }
553
+ /** Creates a hosted checkout session for the customer to update the subscription's default payment method. */
554
+ async updatePaymentMethod(params, options) {
555
+ const { id, ...rest } = params;
556
+ return this.httpClient.post(
557
+ `/subscriptions/${id}/payment-method/update`,
558
+ rest,
559
+ options
560
+ );
561
+ }
510
562
  /** Upgrade, downgrade, or change billing interval. */
511
563
  async changePlan(params, options) {
512
564
  const { id, ...rest } = params;
@@ -602,7 +654,7 @@ var TransactionsResource = class {
602
654
  const { id } = params;
603
655
  return this.httpClient.post(`/transactions/${id}/refund`, {}, options);
604
656
  }
605
- /** Retry a failed payment transaction. Creates a new invoice and initiates a new payment attempt. */
657
+ /** Retry a failed subscription renewal. Re-charges the outstanding renewal invoice through the recovery engine. */
606
658
  async retry(params, options) {
607
659
  const { id } = params;
608
660
  return this.httpClient.post(`/transactions/${id}/retry`, {}, options);
@@ -619,6 +671,7 @@ var GeneratedResources = class {
619
671
  this.featureAccess = new FeatureAccessResource(http);
620
672
  this.features = new FeaturesResource(http);
621
673
  this.invoices = new InvoicesResource(http);
674
+ this.payments = new PaymentsResource(http);
622
675
  this.payouts = new PayoutsResource(http);
623
676
  this.planGroups = new PlanGroupsResource(http);
624
677
  this.plans = new PlansResource(http);
@@ -764,7 +817,7 @@ var CommetValidationError = class extends CommetError {
764
817
 
765
818
  // src/version.ts
766
819
  var API_VERSION = "2026-06-10";
767
- var SDK_VERSION = "7.0.0";
820
+ var SDK_VERSION = "7.2.0";
768
821
 
769
822
  // src/utils/telemetry.ts
770
823
  var registeredIntegrations = /* @__PURE__ */ new Set();
@@ -848,6 +901,7 @@ var DEFAULT_RETRY_CONFIG = {
848
901
  // 8s
849
902
  retryableStatusCodes: [408, 429, 500, 502, 503, 504]
850
903
  };
904
+ var RETRY_AFTER_CAP_MS = 3e4;
851
905
  var _CommetHTTPClient = class _CommetHTTPClient {
852
906
  constructor(config) {
853
907
  this.lastRequestMetrics = null;
@@ -959,17 +1013,16 @@ var _CommetHTTPClient = class _CommetHTTPClient {
959
1013
  }
960
1014
  if (!response.ok) {
961
1015
  if (attempt <= this.retryConfig.maxRetries && this.retryConfig.retryableStatusCodes.includes(response.status)) {
962
- const delay = Math.min(
963
- this.retryConfig.baseDelay * 2 ** (attempt - 1),
964
- this.retryConfig.maxDelay
965
- );
966
- if (this.config.debug) {
967
- console.log(
968
- `[Commet SDK] Retrying in ${delay}ms (attempt ${attempt}/${this.retryConfig.maxRetries})`
969
- );
1016
+ const delay = this.retryDelayMs(attempt, response);
1017
+ if (delay !== null) {
1018
+ if (this.config.debug) {
1019
+ console.log(
1020
+ `[Commet SDK] Retrying in ${delay}ms (attempt ${attempt}/${this.retryConfig.maxRetries})`
1021
+ );
1022
+ }
1023
+ await this.sleep(delay);
1024
+ return this.executeRequest(method, url, data, options, attempt + 1);
970
1025
  }
971
- await this.sleep(delay);
972
- return this.executeRequest(method, url, data, options, attempt + 1);
973
1026
  }
974
1027
  if (this.config.debug) {
975
1028
  console.log(
@@ -1019,10 +1072,7 @@ var _CommetHTTPClient = class _CommetHTTPClient {
1019
1072
  const isTimeoutErrorModern = typeof globalThis.DOMException !== "undefined" && error instanceof DOMException && error.name === "TimeoutError";
1020
1073
  if (isNetworkError || isTimeoutError || isTimeoutErrorModern) {
1021
1074
  if (attempt <= this.retryConfig.maxRetries) {
1022
- const delay = Math.min(
1023
- this.retryConfig.baseDelay * 2 ** (attempt - 1),
1024
- this.retryConfig.maxDelay
1025
- );
1075
+ const delay = this.backoffDelayMs(attempt);
1026
1076
  if (this.config.debug) {
1027
1077
  console.log(`[Commet SDK] Network error, retrying in ${delay}ms`);
1028
1078
  }
@@ -1058,6 +1108,26 @@ var _CommetHTTPClient = class _CommetHTTPClient {
1058
1108
  }
1059
1109
  return finalUrl;
1060
1110
  }
1111
+ // 429 retries wait exactly what the rate limiter reports in Retry-After
1112
+ // (seconds until the window resets); a 429 without the header did not come
1113
+ // from the rate limiter, so it is not retried (returns null). Exponential
1114
+ // backoff only applies to statuses that carry no server-provided wait.
1115
+ retryDelayMs(attempt, response) {
1116
+ if (response.status === 429) {
1117
+ const retryAfterSeconds = Number(response.headers.get("retry-after"));
1118
+ if (Number.isFinite(retryAfterSeconds) && retryAfterSeconds > 0) {
1119
+ return Math.min(retryAfterSeconds * 1e3, RETRY_AFTER_CAP_MS);
1120
+ }
1121
+ return null;
1122
+ }
1123
+ return this.backoffDelayMs(attempt);
1124
+ }
1125
+ backoffDelayMs(attempt) {
1126
+ return Math.min(
1127
+ this.retryConfig.baseDelay * 2 ** (attempt - 1),
1128
+ this.retryConfig.maxDelay
1129
+ );
1130
+ }
1061
1131
  generateIdempotencyKey() {
1062
1132
  return `commet-node-retry-${crypto.randomUUID()}`;
1063
1133
  }