@suqo/sdk 1.1.0 → 2.1.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/README.md CHANGED
@@ -31,12 +31,13 @@ See [`authentication.md`](docs/user/authentication.md) for how the API key deter
31
31
  | Examples | [`examples/`](examples/) — runnable scripts against your own sandbox |
32
32
  | Authentication | [`authentication.md`](docs/user/authentication.md) |
33
33
  | Products | [`products.md`](docs/user/products.md) |
34
+ | Checkout sessions | [`checkout-sessions.md`](docs/user/checkout-sessions.md) |
34
35
  | Subscriptions | [`subscriptions.md`](docs/user/subscriptions.md) |
35
36
  | Customers | [`customers.md`](docs/user/customers.md) |
36
37
  | Webhooks | [`webhooks.md`](docs/user/webhooks.md) |
37
38
  | Pagination | [`pagination.md`](docs/user/pagination.md) |
38
39
  | Errors | [`errors.md`](docs/user/errors.md) |
39
- | Rate limiting _(planned)_ | [`rate-limiting.md`](docs/user/rate-limiting.md) |
40
+ | Rate limiting | [`rate-limiting.md`](docs/user/rate-limiting.md) |
40
41
  | Idempotency _(planned)_ | [`idempotency.md`](docs/user/idempotency.md) |
41
42
 
42
43
  Every exported class and method also carries inline TSDoc — your editor will show it on hover without needing to open these files.
package/dist/index.cjs CHANGED
@@ -26,6 +26,8 @@ var KycRequiredError = class extends SuqoError {
26
26
  if (options.kycStatus !== void 0) this.kycStatus = options.kycStatus;
27
27
  }
28
28
  };
29
+ var PermissionDeniedError = class extends SuqoError {
30
+ };
29
31
  var ValidationError = class extends SuqoError {
30
32
  constructor(message, options = {}) {
31
33
  super(message, options);
@@ -50,7 +52,20 @@ function isRecord(value) {
50
52
  return typeof value === "object" && value !== null;
51
53
  }
52
54
 
55
+ // src/utils/assertPathId.ts
56
+ function assertPathId(id, method, reserved = []) {
57
+ if (!id || id === "." || id === "..") {
58
+ throw new SuqoConfigError(`${method}() requires a non-empty id other than "." or ".."`);
59
+ }
60
+ if (reserved.includes(id)) {
61
+ throw new SuqoConfigError(`${method}() was given "${id}", which is a route name, not an id`);
62
+ }
63
+ }
64
+
53
65
  // src/errors/mapHttpError.ts
66
+ function isMessageList(body) {
67
+ return Array.isArray(body) && body.length > 0 && body.every((item) => typeof item === "string");
68
+ }
54
69
  function isDetailShaped(body) {
55
70
  return isRecord(body) && typeof body.detail === "string" && body.detail.length > 0;
56
71
  }
@@ -81,22 +96,28 @@ function mapHttpError(input) {
81
96
  const { status, statusText, body, requestId, retryAfter } = input;
82
97
  const fallbackMessage = `Request failed with status ${status}${statusText ? ` (${statusText})` : ""}`;
83
98
  const base = { status, rawBody: body, ...requestId !== void 0 ? { requestId } : {} };
99
+ const fallback = (suqoMessage) => typeof body === "string" ? fallbackMessage : suqoMessage;
84
100
  switch (status) {
85
101
  case 401:
86
102
  return new AuthenticationError(messageFrom(body, fallbackMessage), base);
87
103
  case 403: {
88
- const kycStatus = isRecord(body) && typeof body.status_code === "string" ? body.status_code : void 0;
89
- const message = messageFrom(body, "KYC verification needed to perform this action.");
90
- return new KycRequiredError(message, { ...base, ...kycStatus !== void 0 ? { kycStatus } : {} });
104
+ if (isRecord(body) && typeof body.status_code === "string") {
105
+ const message = messageFrom(body, "KYC verification needed to perform this action.");
106
+ return new KycRequiredError(message, { ...base, kycStatus: body.status_code });
107
+ }
108
+ return new PermissionDeniedError(messageFrom(body, fallback("You do not have permission to perform this action.")), base);
91
109
  }
92
110
  case 400: {
93
111
  if (isDetailShaped(body)) {
94
112
  return new ValidationError(body.detail, base);
95
113
  }
96
- return new ValidationError("Validation failed.", { ...base, fieldErrors: fieldErrorsFrom(body) });
114
+ if (isMessageList(body)) {
115
+ return new ValidationError(body.join(" "), { ...base, fieldErrors: {} });
116
+ }
117
+ return new ValidationError(fallback("Validation failed."), { ...base, fieldErrors: fieldErrorsFrom(body) });
97
118
  }
98
119
  case 404:
99
- return new NotFoundError(messageFrom(body, "Not found."), base);
120
+ return new NotFoundError(messageFrom(body, fallback("Not found.")), base);
100
121
  case 429:
101
122
  return new RateLimitError(messageFrom(body, fallbackMessage), {
102
123
  ...base,
@@ -212,6 +233,12 @@ function parseRetryAfterMs(headerValue, now = Date.now()) {
212
233
  const delta = Math.max(dateMs - now, 0);
213
234
  return Math.min(delta, MAX_RETRY_AFTER_MS);
214
235
  }
236
+ function parseRetryAfterDetailMs(body) {
237
+ if (!isRecord(body) || typeof body.detail !== "string") return void 0;
238
+ const match = /available in (\d+(?:\.\d+)?) seconds?/i.exec(body.detail);
239
+ if (!match) return void 0;
240
+ return Math.min(Number(match[1]) * 1e3, MAX_RETRY_AFTER_MS);
241
+ }
215
242
 
216
243
  // src/http/signals.ts
217
244
  function combineSignals(signals) {
@@ -239,13 +266,13 @@ function combineSignals(signals) {
239
266
  function defaultSleep(ms) {
240
267
  return new Promise((resolve) => setTimeout(resolve, ms));
241
268
  }
242
- async function parseJsonBody(response) {
269
+ async function parseJsonBody(response, keepText = false) {
243
270
  const text = await response.text();
244
271
  if (text.length === 0) return void 0;
245
272
  try {
246
273
  return JSON.parse(text);
247
274
  } catch {
248
- return void 0;
275
+ return keepText ? text : void 0;
249
276
  }
250
277
  }
251
278
  function toNetworkError(cause, timeoutMs, callerCancelled) {
@@ -276,8 +303,8 @@ var HttpClient = class {
276
303
  * send, not just `unknown`.
277
304
  */
278
305
  async request(options) {
279
- if (options.method === "GET" && options.body !== void 0) {
280
- throw new TypeError("HttpClient.request: a GET request cannot carry a body.");
306
+ if ((options.method === "GET" || options.method === "DELETE") && options.body !== void 0) {
307
+ throw new TypeError(`HttpClient.request: a ${options.method} request cannot carry a body.`);
281
308
  }
282
309
  let url;
283
310
  try {
@@ -301,8 +328,8 @@ var HttpClient = class {
301
328
  if (response.ok) {
302
329
  return await parseJsonBody(response);
303
330
  }
304
- const body = await parseJsonBody(response);
305
- const retryAfter = parseRetryAfterMs(response.headers.get("Retry-After"));
331
+ const body = await parseJsonBody(response, true);
332
+ const retryAfter = parseRetryAfterMs(response.headers.get("Retry-After")) ?? (response.status === 429 ? parseRetryAfterDetailMs(body) : void 0);
306
333
  if (!isLastAttempt && retryable && isRetryableFailure({ networkError: false, status: response.status })) {
307
334
  await this.#sleepOrAbort(retryAfter ?? backoffDelayMs(attempt - 1), options.signal, timeoutMs);
308
335
  continue;
@@ -360,7 +387,7 @@ var HttpClient = class {
360
387
  if (isWrite) {
361
388
  headers["Content-Type"] = "application/json";
362
389
  }
363
- const body = options.method !== "GET" ? options.body : void 0;
390
+ const body = "body" in options ? options.body : void 0;
364
391
  const { signal, cleanup } = combineSignals([AbortSignal.timeout(timeoutMs), options.signal]);
365
392
  try {
366
393
  const init = {
@@ -430,14 +457,23 @@ function deserializeBillingPeriod(wire) {
430
457
  isCurrent: wire.is_current,
431
458
  isLimited: wire.is_limited,
432
459
  isArchived: wire.is_archived,
433
- offers: wire.offers
460
+ offers: (wire.offers ?? []).map(deserializeOffer)
461
+ };
462
+ }
463
+ function deserializeOffer(wire) {
464
+ return {
465
+ id: wire.id,
466
+ discountAmount: wire.discount_amount,
467
+ startsAt: wire.starts_at ?? null,
468
+ validUntil: wire.valid_until ?? null,
469
+ isActive: wire.is_active
434
470
  };
435
471
  }
436
472
  function deserializePlan(wire) {
437
473
  return {
438
474
  planId: wire.plan_id,
439
475
  planName: wire.plan_name,
440
- description: wire.description,
476
+ description: wire.description ?? null,
441
477
  // `openapi.yaml`'s Product schema has no `required` list at all, so `billing_periods` being
442
478
  // omitted entirely (not just an empty array) is spec-legal — `?? []` degrades to an empty
443
479
  // list instead of `.map` throwing on `undefined` (found in review, reproduced).
@@ -447,19 +483,19 @@ function deserializePlan(wire) {
447
483
  function deserializeProductVat(wire) {
448
484
  return {
449
485
  isVatActive: wire.is_vat_active,
450
- vatType: wire.vat_type,
451
- vatPercentage: wire.vat_percentage
486
+ vatType: wire.vat_type ?? null,
487
+ vatPercentage: wire.vat_percentage ?? null
452
488
  };
453
489
  }
454
490
  function deserializeProduct(wire) {
455
491
  return {
456
492
  productId: wire.product_id,
457
493
  name: wire.name,
458
- description: wire.description,
494
+ description: wire.description ?? null,
459
495
  type: wire.type,
460
496
  isActive: wire.is_active,
461
- termsAndConditions: wire.terms_and_conditions,
462
- featuresAndBenefits: wire.features_and_benefits,
497
+ termsAndConditions: wire.terms_and_conditions ?? null,
498
+ featuresAndBenefits: wire.features_and_benefits ?? null,
463
499
  // `== null` (not `=== null`) is deliberate — it catches both an explicit `null` and an
464
500
  // entirely omitted `vat` key. `openapi.yaml` has no `required` list for Product, so omitting
465
501
  // `vat` is spec-legal, and the old `=== null` check crashed on `deserializeProductVat(undefined)`
@@ -573,18 +609,26 @@ function deserializeSubscriptionCustomer(wire) {
573
609
  }
574
610
  return customer;
575
611
  }
612
+ function deserializeCheckoutSessionResponse(wire) {
613
+ return {
614
+ publicId: wire.public_id,
615
+ expiresAt: wire.expires_at,
616
+ checkoutUrl: wire.checkout_url
617
+ };
618
+ }
576
619
 
577
620
  // src/resources/subscriptions.ts
578
621
  var SUBSCRIPTIONS_PATH = "/api/v1/subscriptions";
622
+ var RENEW_PATH = "/api/v1/subscription/renew";
579
623
  function deserializeSubscriptionProduct(wire) {
580
624
  return {
581
- productId: wire.product_id,
582
- name: wire.name,
583
- planName: wire.plan_name,
584
- pbpId: wire.pbp_id,
585
- label: wire.label,
586
- price: wire.price,
587
- currency: wire.currency
625
+ productId: wire.product_id ?? null,
626
+ name: wire.name ?? null,
627
+ planName: wire.plan_name ?? null,
628
+ pbpId: wire.pbp_id ?? null,
629
+ label: wire.label ?? null,
630
+ price: wire.price ?? null,
631
+ currency: wire.currency ?? null
588
632
  };
589
633
  }
590
634
  function deserializeSubscription(wire) {
@@ -656,13 +700,28 @@ var SubscriptionsResource = class {
656
700
  });
657
701
  }
658
702
  /**
703
+ * Retrieves one of your own subscriptions by id. Built from Swagger's schema; not yet checked
704
+ * against a captured response.
705
+ */
706
+ async retrieve(id) {
707
+ assertPathId(id, "subscriptions.retrieve");
708
+ const wire = await this.#http.request({
709
+ method: "GET",
710
+ path: `${SUBSCRIPTIONS_PATH}/${encodeURIComponent(id)}`
711
+ });
712
+ return deserializeSubscription(wire);
713
+ }
714
+ /**
715
+ * **Legacy** — prefer `checkoutSessions.create()`, which takes up to ten items in one payment
716
+ * and doesn't need a full customer object. Still supported; existing integrations keep working.
717
+ *
659
718
  * Creates a subscription in `pending_checkout` state and returns a checkout URL for the buyer
660
719
  * to pay (SDK-SPEC.md §5). Redirect the buyer to `checkoutUrl`; the return is **not** proof of
661
720
  * payment — learn the real outcome via the `checkout.succeeded`/`checkout.failed` webhooks.
662
721
  *
663
- * Reuse behavior: an inactive/expired subscription for the same buyer + product + billing
664
- * period is reactivated rather than duplicated; only a currently `active` one triggers the
665
- * duplicate-subscription `ValidationError`.
722
+ * `customer.email` identifies the buyer. A buyer may hold only one live recurring subscription
723
+ * per product: a second one on any billing period of the same product throws `ValidationError`.
724
+ * To restart an inactive subscription, use `renew()` rather than creating a new one.
666
725
  *
667
726
  * Not auto-retryable — writes never retry until idempotency ships (SDK-SPEC.md §8, §12).
668
727
  */
@@ -682,11 +741,14 @@ var SubscriptionsResource = class {
682
741
  /**
683
742
  * Schedules cancellation for the end of the current billing period — **not** immediate
684
743
  * (confirmed with backend 2026-08-17; immediate cancellation is a future capability). Status
685
- * moves to `pending_cancellation`; the subscription stays active until the period ends.
744
+ * moves to `pending_cancellation`; the subscription stays active until the period ends. Calling
745
+ * it on a subscription already cancelled or pending cancellation returns it unchanged, so a
746
+ * retry by the caller is safe.
686
747
  *
687
748
  * Not auto-retryable — writes never retry until idempotency ships (SDK-SPEC.md §8, §12).
688
749
  */
689
750
  async cancel(id) {
751
+ assertPathId(id, "subscriptions.cancel");
690
752
  return this.#http.request({
691
753
  method: "POST",
692
754
  path: `${SUBSCRIPTIONS_PATH}/${encodeURIComponent(id)}/cancel`
@@ -709,18 +771,37 @@ var SubscriptionsResource = class {
709
771
  });
710
772
  }
711
773
  /**
712
- * Resumes a subscription. Confirmed public with backend (2026-08-18); the response shape
713
- * follows Swagger's `{ message }` example but — unlike Customers — isn't independently
714
- * confirmed, so treat it as likely-correct-but-unverified (docs/implementation-plan.md Ticket 4).
774
+ * Undoes a scheduled cancellation and returns the subscription to `active`. An already-active
775
+ * subscription is returned unchanged. Once a subscription is `cancelled` there is nothing to
776
+ * resume — use `renew()`.
715
777
  *
716
778
  * Not auto-retryable — writes never retry until idempotency ships (SDK-SPEC.md §8, §12).
717
779
  */
718
780
  async resume(id) {
781
+ assertPathId(id, "subscriptions.resume");
719
782
  return this.#http.request({
720
783
  method: "POST",
721
784
  path: `${SUBSCRIPTIONS_PATH}/${encodeURIComponent(id)}/resume`
722
785
  });
723
786
  }
787
+ /**
788
+ * Opens a checkout session for the next payment on one of your own subscriptions, reusing its
789
+ * customer and billing period (or partner-priced item) rather than resubmitting them — how an
790
+ * inactive subscription is restarted. Send the buyer to the returned `checkoutUrl`, and learn
791
+ * the outcome from the `checkout.*` webhooks, matched on `publicId`.
792
+ *
793
+ * A cancelled or archived subscription, or a paid one-time purchase, can't be renewed: that
794
+ * throws `ValidationError`. Not auto-retryable — writes never retry until idempotency ships
795
+ * (SDK-SPEC.md §8, §12).
796
+ */
797
+ async renew(subscriptionId) {
798
+ const wire = await this.#http.request({
799
+ method: "POST",
800
+ path: RENEW_PATH,
801
+ body: { subscription_id: subscriptionId }
802
+ });
803
+ return deserializeCheckoutSessionResponse(wire);
804
+ }
724
805
  };
725
806
 
726
807
  // src/resources/customers.ts
@@ -744,11 +825,6 @@ function serializeCustomerFields(params) {
744
825
  if (params.address !== void 0) wire.address = params.address;
745
826
  return wire;
746
827
  }
747
- function assertCustomerId(id, method) {
748
- if (!id || id === "." || id === "..") {
749
- throw new SuqoConfigError(`customers.${method}() requires a non-empty id other than "." or ".."`);
750
- }
751
- }
752
828
  var CustomersResource = class {
753
829
  #http;
754
830
  constructor(http) {
@@ -780,7 +856,7 @@ var CustomersResource = class {
780
856
  * wrong `number` type/doc claim here).
781
857
  */
782
858
  async retrieve(id) {
783
- assertCustomerId(id, "retrieve");
859
+ assertPathId(id, "customers.retrieve");
784
860
  const wire = await this.#http.request({
785
861
  method: "GET",
786
862
  path: `${CUSTOMERS_PATH}/${encodeURIComponent(id)}`
@@ -788,20 +864,24 @@ var CustomersResource = class {
788
864
  return deserializeCustomer(wire);
789
865
  }
790
866
  /**
791
- * Records a customer on the seller's account without opening a subscription. `phone` identifies
792
- * the buyer; the name, email and address are the seller's own copy and aren't shared with other
793
- * sellers.
867
+ * Records a customer on the seller's account without opening a subscription. `email` identifies
868
+ * the buyer and is required; `phone` is optional. The name and address are the seller's own copy
869
+ * and aren't shared with other sellers. Pass the returned `id` to `checkoutSessions.create()` as
870
+ * `customerId` to send the buyer straight to payment.
794
871
  *
795
- * A phone the seller already holds updates that existing customer instead of creating a second
796
- * one (the API answers `200` rather than `201`; both resolve to the `Customer` here). That makes
797
- * this call safe for the caller to retry — but, like every write, the SDK never retries it
798
- * automatically (SDK-SPEC.md §8, §12).
872
+ * An email or phone the seller already holds updates that existing customer instead of creating
873
+ * a second one (the API answers `200` rather than `201`; both resolve to the `Customer` here).
874
+ * That makes this call safe for the caller to retry — but, like every write, the SDK never
875
+ * retries it automatically (SDK-SPEC.md §8, §12).
799
876
  */
800
877
  async create(params) {
801
878
  const wire = await this.#http.request({
802
879
  method: "POST",
803
880
  path: CUSTOMERS_PATH,
804
- body: { phone: params.phone, ...serializeCustomerFields(params) }
881
+ body: {
882
+ ...serializeCustomerFields(params),
883
+ ...params.phone !== void 0 ? { phone: params.phone } : {}
884
+ }
805
885
  });
806
886
  return deserializeCustomer(wire);
807
887
  }
@@ -812,7 +892,7 @@ var CustomersResource = class {
812
892
  * Not auto-retryable — writes never retry until idempotency ships (SDK-SPEC.md §8, §12).
813
893
  */
814
894
  async update(id, params) {
815
- assertCustomerId(id, "update");
895
+ assertPathId(id, "customers.update");
816
896
  const wire = await this.#http.request({
817
897
  method: "PATCH",
818
898
  path: `${CUSTOMERS_PATH}/${encodeURIComponent(id)}`,
@@ -821,10 +901,212 @@ var CustomersResource = class {
821
901
  return deserializeCustomer(wire);
822
902
  }
823
903
  };
904
+
905
+ // src/resources/checkoutSessions.ts
906
+ var CHECKOUT_SESSIONS_PATH = "/api/v1/checkout-sessions";
907
+ function deserializeLineItem(wire) {
908
+ return {
909
+ name: wire.name,
910
+ amount: wire.amount,
911
+ pbpId: wire.pbp_id ?? null,
912
+ currency: wire.currency,
913
+ vatType: wire.vat_type ?? null,
914
+ vatPercentage: wire.vat_percentage ?? null,
915
+ discountAmount: wire.discount_amount ?? null,
916
+ intervalType: wire.interval_type,
917
+ intervalCount: wire.interval_count,
918
+ displayLabel: wire.display_label,
919
+ currentPeriodEnd: wire.current_period_end ?? null,
920
+ extendsTo: wire.extends_to ?? null,
921
+ nextPaymentDue: wire.next_payment_due ?? null,
922
+ // Each kind carries one of these and not the other, so they stay absent rather than null.
923
+ ...wire.image_urls !== void 0 ? { imageUrls: wire.image_urls } : {},
924
+ ...wire.plan_name !== void 0 ? { planName: wire.plan_name } : {},
925
+ // Every item carries it; absent (not null) only on sessions created before the API added it.
926
+ ...wire.subscription_id !== void 0 ? { subscriptionId: wire.subscription_id } : {}
927
+ };
928
+ }
929
+ function deserializeCheckoutSession(wire) {
930
+ return {
931
+ publicId: wire.public_id,
932
+ lineItems: (wire.line_items ?? []).map(deserializeLineItem),
933
+ customerId: wire.customer_id ?? null,
934
+ sellerDetails: {
935
+ id: wire.seller_details.id,
936
+ phone: wire.seller_details.phone,
937
+ businessLogo: wire.seller_details.business_logo ?? null,
938
+ businessName: wire.seller_details.business_name
939
+ },
940
+ returnUrl: wire.return_url,
941
+ expiresAt: wire.expires_at,
942
+ completedAt: wire.completed_at ?? null,
943
+ isExpired: wire.is_expired,
944
+ sessionType: wire.session_type ?? null
945
+ };
946
+ }
947
+ function serializeItem(item) {
948
+ if (item.pbpId !== void 0) return { pbp_id: item.pbpId };
949
+ return {
950
+ name: item.name,
951
+ amount: item.amount,
952
+ interval_type: item.intervalType,
953
+ interval_count: item.intervalCount
954
+ };
955
+ }
956
+ var CheckoutSessionsResource = class {
957
+ #http;
958
+ constructor(http) {
959
+ this.#http = http;
960
+ }
961
+ /**
962
+ * Opens a checkout session for one to ten items and returns a URL for the buyer to pay. Prices
963
+ * are snapshotted now, so a plan edited later can't change what the buyer was shown. Redirect
964
+ * the buyer to `checkoutUrl`; the return to `returnUrl` is **not** proof of payment — learn the
965
+ * outcome from `checkout.succeeded`/`checkout.failed`, matched on `publicId` (`session_id`).
966
+ *
967
+ * The API's one rate-limited endpoint: 20 sessions a minute per account. Past that it throws
968
+ * `RateLimitError` with `retryAfter` set. Never retried automatically — writes don't retry until
969
+ * idempotency ships (SDK-SPEC.md §8, §12) — so open a session when the buyer commits to paying,
970
+ * not on page load.
971
+ */
972
+ async create(params) {
973
+ const wire = await this.#http.request({
974
+ method: "POST",
975
+ path: CHECKOUT_SESSIONS_PATH,
976
+ body: {
977
+ items: params.items.map(serializeItem),
978
+ return_url: params.returnUrl,
979
+ ...params.customerId !== void 0 ? { customer_id: params.customerId } : {}
980
+ }
981
+ });
982
+ return deserializeCheckoutSessionResponse(wire);
983
+ }
984
+ /**
985
+ * Reads one of your own open sessions: its line items, customer, seller and expiry. Once paid,
986
+ * expired, unknown or someone else's, it throws `NotFoundError`.
987
+ */
988
+ async retrieve(id) {
989
+ assertPathId(id, "checkoutSessions.retrieve");
990
+ const wire = await this.#http.request({
991
+ method: "GET",
992
+ path: `${CHECKOUT_SESSIONS_PATH}/${encodeURIComponent(id)}`
993
+ });
994
+ return deserializeCheckoutSession(wire);
995
+ }
996
+ };
997
+ var WEBHOOKS_PATH = "/api/v1/webhooks";
998
+ var RESERVED_SEGMENTS = ["secret"];
999
+ function deserializeWebhook(wire) {
1000
+ return {
1001
+ id: wire.id,
1002
+ event: wire.event,
1003
+ endpointUrl: wire.endpoint_url,
1004
+ isActive: wire.is_active,
1005
+ createdAt: wire.created_at
1006
+ };
1007
+ }
1008
+ function serializeWebhookWrite(params) {
1009
+ const wire = {};
1010
+ if (params.event !== void 0) wire.event = params.event;
1011
+ if (params.endpointUrl !== void 0) wire.endpoint_url = params.endpointUrl;
1012
+ if (params.isActive !== void 0) wire.is_active = params.isActive;
1013
+ return wire;
1014
+ }
824
1015
  var DEFAULT_TOLERANCE_SEC = 300;
825
1016
  var SIGNATURE_PREFIX = "sha256=";
826
1017
  var HEX_DIGEST_RE = /^[0-9a-f]{64}$/i;
827
1018
  var WebhooksResource = class {
1019
+ #http;
1020
+ constructor(http) {
1021
+ this.#http = http;
1022
+ }
1023
+ /** Every webhook registered by your account. Not paginated — the API returns them all. */
1024
+ async list() {
1025
+ const wire = await this.#http.request({ method: "GET", path: WEBHOOKS_PATH });
1026
+ return wire.map(deserializeWebhook);
1027
+ }
1028
+ /**
1029
+ * Subscribes an `https` endpoint to one event. An account holds at most one webhook per event,
1030
+ * and the endpoint must resolve only to public addresses — either failing throws
1031
+ * `ValidationError`. Not auto-retryable (SDK-SPEC.md §8, §12).
1032
+ */
1033
+ async create(params) {
1034
+ const wire = await this.#http.request({
1035
+ method: "POST",
1036
+ path: WEBHOOKS_PATH,
1037
+ body: serializeWebhookWrite(params)
1038
+ });
1039
+ return deserializeWebhook(wire);
1040
+ }
1041
+ /** Retrieves one of your own webhooks by id (`whk_…`). */
1042
+ async retrieve(id) {
1043
+ assertPathId(id, "webhooks.retrieve", RESERVED_SEGMENTS);
1044
+ const wire = await this.#http.request({
1045
+ method: "GET",
1046
+ path: `${WEBHOOKS_PATH}/${encodeURIComponent(id)}`
1047
+ });
1048
+ return deserializeWebhook(wire);
1049
+ }
1050
+ /**
1051
+ * Overwrites a webhook's event, endpoint and active flag (`PUT`). `event` and `endpointUrl` are
1052
+ * both required; to change one field on its own, use {@link WebhooksResource.update}. Not
1053
+ * auto-retryable (SDK-SPEC.md §8, §12).
1054
+ */
1055
+ async replace(id, params) {
1056
+ assertPathId(id, "webhooks.replace", RESERVED_SEGMENTS);
1057
+ const wire = await this.#http.request({
1058
+ method: "PUT",
1059
+ path: `${WEBHOOKS_PATH}/${encodeURIComponent(id)}`,
1060
+ body: serializeWebhookWrite(params)
1061
+ });
1062
+ return deserializeWebhook(wire);
1063
+ }
1064
+ /**
1065
+ * Changes only the fields you send (`PATCH`) — e.g. `{ isActive: false }` pauses deliveries
1066
+ * without deleting the webhook. Not auto-retryable (SDK-SPEC.md §8, §12).
1067
+ */
1068
+ async update(id, params) {
1069
+ assertPathId(id, "webhooks.update", RESERVED_SEGMENTS);
1070
+ const wire = await this.#http.request({
1071
+ method: "PATCH",
1072
+ path: `${WEBHOOKS_PATH}/${encodeURIComponent(id)}`,
1073
+ body: serializeWebhookWrite(params)
1074
+ });
1075
+ return deserializeWebhook(wire);
1076
+ }
1077
+ /** Removes a webhook. Past delivery records are kept for debugging. Not auto-retryable (SDK-SPEC.md §8, §12). */
1078
+ async delete(id) {
1079
+ assertPathId(id, "webhooks.delete", RESERVED_SEGMENTS);
1080
+ await this.#http.request({
1081
+ method: "DELETE",
1082
+ path: `${WEBHOOKS_PATH}/${encodeURIComponent(id)}`
1083
+ });
1084
+ }
1085
+ /**
1086
+ * Returns the account's signing secret — the `secret` to pass to {@link WebhooksResource.verify}.
1087
+ * The API creates it on the first call; it can't be rotated through the API. Treat it like a
1088
+ * password: never log it.
1089
+ */
1090
+ async retrieveSecret() {
1091
+ const wire = await this.#http.request({
1092
+ method: "GET",
1093
+ path: `${WEBHOOKS_PATH}/secret`
1094
+ });
1095
+ return { signingSecret: wire.signing_secret };
1096
+ }
1097
+ /**
1098
+ * Queues a signed test delivery to the webhook's endpoint so you can check your receiver. It
1099
+ * resolves once the job is queued; the delivery itself arrives asynchronously. Note a test
1100
+ * delivery's body differs from a real event's (fields under `data`) — use it to check
1101
+ * `verify()`, not your payload parsing. Not auto-retryable (SDK-SPEC.md §8, §12).
1102
+ */
1103
+ async testDelivery(id) {
1104
+ assertPathId(id, "webhooks.testDelivery", RESERVED_SEGMENTS);
1105
+ await this.#http.request({
1106
+ method: "POST",
1107
+ path: `${WEBHOOKS_PATH}/${encodeURIComponent(id)}/test-delivery`
1108
+ });
1109
+ }
828
1110
  /**
829
1111
  * Verifies an inbound webhook delivery's signature. Returns `false` for any failure mode —
830
1112
  * malformed signature, expired timestamp, or a genuine mismatch — never throws, so a caller
@@ -874,7 +1156,8 @@ var SuqoClient = class {
874
1156
  this.products = new ProductsResource(http);
875
1157
  this.subscriptions = new SubscriptionsResource(http);
876
1158
  this.customers = new CustomersResource(http);
877
- this.webhooks = new WebhooksResource();
1159
+ this.checkoutSessions = new CheckoutSessionsResource(http);
1160
+ this.webhooks = new WebhooksResource(http);
878
1161
  }
879
1162
  /** `"sandbox" | "live"` — inferred from the key prefix, never selected explicitly (SDK-SPEC.md §2). */
880
1163
  get environment() {
@@ -903,12 +1186,13 @@ var SuqoClient = class {
903
1186
  };
904
1187
 
905
1188
  // src/index.ts
906
- var VERSION = "1.1.0";
1189
+ var VERSION = "2.1.0";
907
1190
 
908
1191
  exports.AuthenticationError = AuthenticationError;
909
1192
  exports.KycRequiredError = KycRequiredError;
910
1193
  exports.NetworkError = NetworkError;
911
1194
  exports.NotFoundError = NotFoundError;
1195
+ exports.PermissionDeniedError = PermissionDeniedError;
912
1196
  exports.RateLimitError = RateLimitError;
913
1197
  exports.ServerError = ServerError;
914
1198
  exports.SubscriptionStatus = SubscriptionStatus;