@suqo/sdk 1.0.0 → 1.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
@@ -360,7 +360,7 @@ var HttpClient = class {
360
360
  if (isWrite) {
361
361
  headers["Content-Type"] = "application/json";
362
362
  }
363
- const body = options.method === "POST" ? options.body : void 0;
363
+ const body = options.method !== "GET" ? options.body : void 0;
364
364
  const { signal, cleanup } = combineSignals([AbortSignal.timeout(timeoutMs), options.signal]);
365
365
  try {
366
366
  const init = {
@@ -465,7 +465,7 @@ function deserializeProduct(wire) {
465
465
  // `vat` is spec-legal, and the old `=== null` check crashed on `deserializeProductVat(undefined)`
466
466
  // when that happened (found in review, reproduced).
467
467
  vat: wire.vat == null ? null : deserializeProductVat(wire.vat),
468
- productImage: wire.product_image,
468
+ productImage: (wire.product_image ?? []).map((img) => ({ image: img.image, imageOrder: img.image_order })),
469
469
  // Same reasoning as `billingPeriods` above — `plan` being omitted entirely is spec-legal.
470
470
  plan: (wire.plan ?? []).map(deserializePlan),
471
471
  totalSubscribers: wire.total_subscribers,
@@ -728,12 +728,27 @@ var CUSTOMERS_PATH = "/api/v1/customers";
728
728
  function deserializeCustomer(wire) {
729
729
  return {
730
730
  id: wire.id,
731
- buyerPhone: wire.buyer_phone,
732
- buyerEmail: wire.buyer_email,
733
- fullName: wire.full_name,
731
+ // `?? null` on all four nullable fields (not a direct pass-through, found in review): catches
732
+ // both an explicit `null` and an entirely omitted key — see the WireCustomer comment above.
733
+ buyerPhone: wire.buyer_phone ?? null,
734
+ buyerEmail: wire.buyer_email ?? null,
735
+ fullName: wire.full_name ?? null,
736
+ address: wire.address ?? null,
734
737
  createdAt: wire.created_at
735
738
  };
736
739
  }
740
+ function serializeCustomerFields(params) {
741
+ const wire = {};
742
+ if (params.fullName !== void 0) wire.full_name = params.fullName;
743
+ if (params.email !== void 0) wire.email = params.email;
744
+ if (params.address !== void 0) wire.address = params.address;
745
+ return wire;
746
+ }
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
+ }
737
752
  var CustomersResource = class {
738
753
  #http;
739
754
  constructor(http) {
@@ -760,16 +775,51 @@ var CustomersResource = class {
760
775
  });
761
776
  }
762
777
  /**
763
- * Retrieves a single customer by id. Unlike every other resource in this API, `id` is an
764
- * **integer**, not a UUID (SDK-SPEC.md §5 naming note; `openapi.yaml` `Customer.id`).
778
+ * Retrieves a single customer by id — an opaque prefixed string (e.g. `"cus_1ce18d624"`), like
779
+ * `pbp_...` on billing periods, not an integer and not a UUID (Bug #42 corrected the previously
780
+ * wrong `number` type/doc claim here).
765
781
  */
766
782
  async retrieve(id) {
783
+ assertCustomerId(id, "retrieve");
767
784
  const wire = await this.#http.request({
768
785
  method: "GET",
769
786
  path: `${CUSTOMERS_PATH}/${encodeURIComponent(id)}`
770
787
  });
771
788
  return deserializeCustomer(wire);
772
789
  }
790
+ /**
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.
794
+ *
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).
799
+ */
800
+ async create(params) {
801
+ const wire = await this.#http.request({
802
+ method: "POST",
803
+ path: CUSTOMERS_PATH,
804
+ body: { phone: params.phone, ...serializeCustomerFields(params) }
805
+ });
806
+ return deserializeCustomer(wire);
807
+ }
808
+ /**
809
+ * Updates the seller's copy of a customer's name, email or address. Send only the fields you're
810
+ * changing; `""` clears a field. The phone can't be changed.
811
+ *
812
+ * Not auto-retryable — writes never retry until idempotency ships (SDK-SPEC.md §8, §12).
813
+ */
814
+ async update(id, params) {
815
+ assertCustomerId(id, "update");
816
+ const wire = await this.#http.request({
817
+ method: "PATCH",
818
+ path: `${CUSTOMERS_PATH}/${encodeURIComponent(id)}`,
819
+ body: serializeCustomerFields(params)
820
+ });
821
+ return deserializeCustomer(wire);
822
+ }
773
823
  };
774
824
  var DEFAULT_TOLERANCE_SEC = 300;
775
825
  var SIGNATURE_PREFIX = "sha256=";
@@ -853,7 +903,7 @@ var SuqoClient = class {
853
903
  };
854
904
 
855
905
  // src/index.ts
856
- var VERSION = "1.0.0";
906
+ var VERSION = "1.1.0";
857
907
 
858
908
  exports.AuthenticationError = AuthenticationError;
859
909
  exports.KycRequiredError = KycRequiredError;