@suqo/sdk 2.0.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/dist/index.cjs CHANGED
@@ -96,6 +96,7 @@ function mapHttpError(input) {
96
96
  const { status, statusText, body, requestId, retryAfter } = input;
97
97
  const fallbackMessage = `Request failed with status ${status}${statusText ? ` (${statusText})` : ""}`;
98
98
  const base = { status, rawBody: body, ...requestId !== void 0 ? { requestId } : {} };
99
+ const fallback = (suqoMessage) => typeof body === "string" ? fallbackMessage : suqoMessage;
99
100
  switch (status) {
100
101
  case 401:
101
102
  return new AuthenticationError(messageFrom(body, fallbackMessage), base);
@@ -104,7 +105,7 @@ function mapHttpError(input) {
104
105
  const message = messageFrom(body, "KYC verification needed to perform this action.");
105
106
  return new KycRequiredError(message, { ...base, kycStatus: body.status_code });
106
107
  }
107
- return new PermissionDeniedError(messageFrom(body, "You do not have permission to perform this action."), base);
108
+ return new PermissionDeniedError(messageFrom(body, fallback("You do not have permission to perform this action.")), base);
108
109
  }
109
110
  case 400: {
110
111
  if (isDetailShaped(body)) {
@@ -113,10 +114,10 @@ function mapHttpError(input) {
113
114
  if (isMessageList(body)) {
114
115
  return new ValidationError(body.join(" "), { ...base, fieldErrors: {} });
115
116
  }
116
- return new ValidationError("Validation failed.", { ...base, fieldErrors: fieldErrorsFrom(body) });
117
+ return new ValidationError(fallback("Validation failed."), { ...base, fieldErrors: fieldErrorsFrom(body) });
117
118
  }
118
119
  case 404:
119
- return new NotFoundError(messageFrom(body, "Not found."), base);
120
+ return new NotFoundError(messageFrom(body, fallback("Not found.")), base);
120
121
  case 429:
121
122
  return new RateLimitError(messageFrom(body, fallbackMessage), {
122
123
  ...base,
@@ -265,13 +266,13 @@ function combineSignals(signals) {
265
266
  function defaultSleep(ms) {
266
267
  return new Promise((resolve) => setTimeout(resolve, ms));
267
268
  }
268
- async function parseJsonBody(response) {
269
+ async function parseJsonBody(response, keepText = false) {
269
270
  const text = await response.text();
270
271
  if (text.length === 0) return void 0;
271
272
  try {
272
273
  return JSON.parse(text);
273
274
  } catch {
274
- return void 0;
275
+ return keepText ? text : void 0;
275
276
  }
276
277
  }
277
278
  function toNetworkError(cause, timeoutMs, callerCancelled) {
@@ -327,7 +328,7 @@ var HttpClient = class {
327
328
  if (response.ok) {
328
329
  return await parseJsonBody(response);
329
330
  }
330
- const body = await parseJsonBody(response);
331
+ const body = await parseJsonBody(response, true);
331
332
  const retryAfter = parseRetryAfterMs(response.headers.get("Retry-After")) ?? (response.status === 429 ? parseRetryAfterDetailMs(body) : void 0);
332
333
  if (!isLastAttempt && retryable && isRetryableFailure({ networkError: false, status: response.status })) {
333
334
  await this.#sleepOrAbort(retryAfter ?? backoffDelayMs(attempt - 1), options.signal, timeoutMs);
@@ -920,7 +921,9 @@ function deserializeLineItem(wire) {
920
921
  nextPaymentDue: wire.next_payment_due ?? null,
921
922
  // Each kind carries one of these and not the other, so they stay absent rather than null.
922
923
  ...wire.image_urls !== void 0 ? { imageUrls: wire.image_urls } : {},
923
- ...wire.plan_name !== void 0 ? { planName: wire.plan_name } : {}
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 } : {}
924
927
  };
925
928
  }
926
929
  function deserializeCheckoutSession(wire) {
@@ -1183,7 +1186,7 @@ var SuqoClient = class {
1183
1186
  };
1184
1187
 
1185
1188
  // src/index.ts
1186
- var VERSION = "2.0.0";
1189
+ var VERSION = "2.1.0";
1187
1190
 
1188
1191
  exports.AuthenticationError = AuthenticationError;
1189
1192
  exports.KycRequiredError = KycRequiredError;