@swell/apps-sdk 1.0.145 → 1.0.147
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 +33 -15
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +33 -15
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +33 -15
- package/dist/index.mjs.map +2 -2
- package/dist/src/api.d.ts +2 -1
- package/dist/src/cache/cache.d.ts +1 -1
- package/dist/src/cache/cf-worker-kv-keyv-adapter.d.ts +1 -1
- package/dist/src/resources.d.ts +11 -7
- package/dist/types/cloudflare.d.ts +50 -0
- package/dist/types/swell.d.ts +1 -49
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
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.
|
|
548
|
-
return [...
|
|
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
|
|
845
|
-
|
|
846
|
-
|
|
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
|
|
878
|
-
|
|
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) {
|
|
@@ -15601,10 +15622,7 @@ function ShopifyCustomer(instance, account) {
|
|
|
15601
15622
|
),
|
|
15602
15623
|
orders_count: defer(() => account.order_count),
|
|
15603
15624
|
payment_methods: [],
|
|
15604
|
-
phone: deferWith(
|
|
15605
|
-
account,
|
|
15606
|
-
(account2) => account2.phone || account2.shipping?.phone || account2.billing?.phone
|
|
15607
|
-
),
|
|
15625
|
+
phone: deferWith(account, (account2) => account2.phone),
|
|
15608
15626
|
store_credit_account: deferWith(account, (account2) => ({
|
|
15609
15627
|
balance: ShopifyMoney(instance, Number(account2.balance))
|
|
15610
15628
|
})),
|