@swell/apps-sdk 1.0.146 → 1.0.148

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
@@ -535,17 +535,18 @@ function toEnumerable(val) {
535
535
  if (isArray(val)) return val;
536
536
  if (isString(val) && val.length > 0) return [val];
537
537
  if (isIterable(val)) return Array.from(val);
538
- if (isObject(val))
538
+ if (isObject(val)) {
539
539
  return Object.entries(val).reduce((acc, [key, value]) => {
540
540
  acc.push({ id: key, ...value });
541
541
  return acc;
542
542
  }, []);
543
+ }
543
544
  return [];
544
545
  }
545
546
  async function resolveEnumerable(val) {
546
547
  if (val instanceof SwellStorefrontCollection) {
547
- await val._get();
548
- return [...val];
548
+ const iterator = await val.iterator();
549
+ return [...iterator];
549
550
  } else if (val instanceof import_liquidjs.Drop && Symbol.iterator in val) {
550
551
  const iterFn = val[Symbol.iterator];
551
552
  if (typeof iterFn === "function") {
@@ -767,12 +768,13 @@ var StorefrontResource = class {
767
768
  return Promise.resolve().then(getter).then((result) => {
768
769
  return this._transformResult(result);
769
770
  }).then((result) => {
770
- this._result = result;
771
+ this._result = result ?? null;
771
772
  if (result) {
772
773
  Object.assign(this, result);
773
774
  }
774
775
  return result;
775
776
  }).catch((err) => {
777
+ this._result = null;
776
778
  logger.error(err);
777
779
  return null;
778
780
  });
@@ -841,12 +843,14 @@ var StorefrontResource = class {
841
843
  };
842
844
  function cloneStorefrontResource(input) {
843
845
  const resourceName = input._resourceName;
844
- const clone = new StorefrontResource(input._getter);
845
- clone._params = input._params;
846
- clone._transformResult = input._transformResult.bind(clone);
847
- Object.defineProperty(clone.constructor, "name", {
846
+ const ClonedClass = class extends StorefrontResource {
847
+ };
848
+ Object.defineProperty(ClonedClass, "name", {
848
849
  value: resourceName
849
850
  });
851
+ const clone = new ClonedClass(input._getter);
852
+ clone._params = input._params;
853
+ clone._transformResult = input._transformResult.bind(clone);
850
854
  Object.defineProperty(clone, "_resourceName", {
851
855
  value: resourceName
852
856
  });
@@ -874,8 +878,12 @@ var SwellStorefrontResource = class extends StorefrontResource {
874
878
  if (_swell && _collection.startsWith("content/")) {
875
879
  const type = _collection.split("/")[1]?.replace(/\/$/, "").trim();
876
880
  this._resource = {
877
- list: (query) => _swell.storefront.content.list(type, query),
878
- get: (id, query) => _swell.storefront.content.get(type, id, query)
881
+ list(query) {
882
+ return _swell.storefront.content.list(type, query);
883
+ },
884
+ get(id, query) {
885
+ return _swell.storefront.content.get(type, id, query);
886
+ }
879
887
  };
880
888
  }
881
889
  if (!this._resource?.get) {
@@ -944,7 +952,7 @@ var SwellStorefrontCollection = class _SwellStorefrontCollection extends SwellSt
944
952
  getter,
945
953
  isResourceCacheble(this._collection)
946
954
  ).then((result) => {
947
- this._result = result;
955
+ this._result = result ?? null;
948
956
  if (result) {
949
957
  Object.assign(this, result, {
950
958
  length: result.results?.length || 0
@@ -952,16 +960,29 @@ var SwellStorefrontCollection = class _SwellStorefrontCollection extends SwellSt
952
960
  }
953
961
  return result;
954
962
  }).catch((err) => {
963
+ this._result = null;
955
964
  logger.error(err);
956
965
  return null;
957
966
  });
958
967
  }
959
968
  return this._result;
960
969
  }
970
+ get size() {
971
+ if (this._result !== void 0) {
972
+ return this.length;
973
+ }
974
+ return this._resolve().then(() => this.length);
975
+ }
961
976
  [Symbol.iterator]() {
962
977
  return this.iterator();
963
978
  }
964
979
  iterator() {
980
+ if (this._result !== void 0) {
981
+ return this.makeIterator();
982
+ }
983
+ return this._resolve().then(() => this.makeIterator());
984
+ }
985
+ makeIterator() {
965
986
  return (this.results || []).values();
966
987
  }
967
988
  _clone(newProps) {
@@ -15264,7 +15285,7 @@ function ShopifyAddress(instance, address, account) {
15264
15285
  address,
15265
15286
  (address2) => address2.first_name || account?.first_name
15266
15287
  ),
15267
- id: defer(() => address.id),
15288
+ id: defer(() => address.id || address.account_address_id),
15268
15289
  last_name: deferWith(
15269
15290
  address,
15270
15291
  (address2) => address2.last_name || account?.last_name
@@ -15292,7 +15313,10 @@ function ShopifyAddress(instance, address, account) {
15292
15313
  address2.country
15293
15314
  )
15294
15315
  ),
15295
- url: deferWith(address, (address2) => `/account/addresses/${address2.id}`),
15316
+ url: deferWith(
15317
+ address,
15318
+ (address2) => `/account/addresses/${address2.id || address2.account_address_id}`
15319
+ ),
15296
15320
  zip: defer(() => address.zip)
15297
15321
  });
15298
15322
  }