@swell/apps-sdk 1.0.143 → 1.0.144
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 +1 -1
- package/dist/index.cjs +51 -19
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +51 -19
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +51 -19
- package/dist/index.mjs.map +2 -2
- package/dist/src/api.d.ts +1 -1
- package/dist/src/cache/cache.d.ts +1 -1
- package/dist/src/theme.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -138,7 +138,7 @@ class Swell {
|
|
|
138
138
|
post<T>(url: string, data: SwellData): Promise<T>;
|
|
139
139
|
put<T>(url: string, data: SwellData): Promise<T>;
|
|
140
140
|
delete<T>(url: string, data?: SwellData): Promise<T>;
|
|
141
|
-
getCachedResource<T>(key: string, args: unknown[], handler: () => T): Promise<T>;
|
|
141
|
+
getCachedResource<T>(key: string, args: unknown[], handler: () => T, isCacheble = true): Promise<T>;
|
|
142
142
|
}
|
|
143
143
|
```
|
|
144
144
|
|
package/dist/index.cjs
CHANGED
|
@@ -649,6 +649,12 @@ async function forEachKeyDeep(obj, fn) {
|
|
|
649
649
|
}
|
|
650
650
|
|
|
651
651
|
// src/resources.ts
|
|
652
|
+
var NOT_CACHEBLE_COLLECTIONS = Object.freeze(
|
|
653
|
+
/* @__PURE__ */ new Set(["accounts:addresses", "accounts:orders", "accounts:subscriptions"])
|
|
654
|
+
);
|
|
655
|
+
function isResourceCacheble(name) {
|
|
656
|
+
return !NOT_CACHEBLE_COLLECTIONS.has(name);
|
|
657
|
+
}
|
|
652
658
|
var MAX_QUERY_PAGE_LIMIT = 100;
|
|
653
659
|
var DEFAULT_QUERY_PAGE_LIMIT = 15;
|
|
654
660
|
var StorefrontResource = class {
|
|
@@ -935,7 +941,8 @@ var SwellStorefrontCollection = class _SwellStorefrontCollection extends SwellSt
|
|
|
935
941
|
this._swell.queryParams,
|
|
936
942
|
this._getterHash
|
|
937
943
|
],
|
|
938
|
-
getter
|
|
944
|
+
getter,
|
|
945
|
+
isResourceCacheble(this._collection)
|
|
939
946
|
).then((result) => {
|
|
940
947
|
this._result = result;
|
|
941
948
|
if (result) {
|
|
@@ -1049,7 +1056,8 @@ var SwellStorefrontRecord = class extends SwellStorefrontResource {
|
|
|
1049
1056
|
this._swell.queryParams,
|
|
1050
1057
|
this._getterHash
|
|
1051
1058
|
],
|
|
1052
|
-
getter
|
|
1059
|
+
getter,
|
|
1060
|
+
isResourceCacheble(this._collection)
|
|
1053
1061
|
).then((result) => {
|
|
1054
1062
|
return this._transformResult(result);
|
|
1055
1063
|
}).then((result) => {
|
|
@@ -7216,16 +7224,18 @@ var Cache = class {
|
|
|
7216
7224
|
*
|
|
7217
7225
|
* This will always return the cached value immediately if exists
|
|
7218
7226
|
*/
|
|
7219
|
-
async fetchSWR(key, fetchFn, ttl = DEFAULT_SWR_TTL) {
|
|
7227
|
+
async fetchSWR(key, fetchFn, ttl = DEFAULT_SWR_TTL, isCacheble = true) {
|
|
7220
7228
|
const trace = createTraceId();
|
|
7221
7229
|
logger.debug("[SDK] Cache fetch start", { key, trace });
|
|
7222
|
-
const cacheValue = await this.client.get(key);
|
|
7230
|
+
const cacheValue = isCacheble ? await this.client.get(key) : void 0;
|
|
7223
7231
|
let promise = SWR_PROMISE_MAP.get(key);
|
|
7224
7232
|
if (promise === void 0) {
|
|
7225
7233
|
promise = Promise.resolve().then(fetchFn).then(resolveAsyncResources).then(async (value) => {
|
|
7226
7234
|
const isNull = value === null || value === void 0;
|
|
7227
|
-
|
|
7228
|
-
|
|
7235
|
+
if (isCacheble) {
|
|
7236
|
+
await this.client.set(key, isNull ? NULL_VALUE : value, ttl);
|
|
7237
|
+
logger.debug("[SDK] Cache update done", { key, trace });
|
|
7238
|
+
}
|
|
7229
7239
|
return value;
|
|
7230
7240
|
}).finally(() => {
|
|
7231
7241
|
SWR_PROMISE_MAP.delete(key);
|
|
@@ -7731,9 +7741,14 @@ var Swell = class _Swell {
|
|
|
7731
7741
|
* Fetches a resource.
|
|
7732
7742
|
* First attempts to fetch from cache.
|
|
7733
7743
|
*/
|
|
7734
|
-
async getCachedResource(key, args, handler) {
|
|
7744
|
+
async getCachedResource(key, args, handler, isCacheble = true) {
|
|
7735
7745
|
const cacheKey = getCacheKey(key, [this.instanceId, args]);
|
|
7736
|
-
return this.getResourceCache().fetchSWR(
|
|
7746
|
+
return this.getResourceCache().fetchSWR(
|
|
7747
|
+
cacheKey,
|
|
7748
|
+
handler,
|
|
7749
|
+
void 0,
|
|
7750
|
+
isCacheble
|
|
7751
|
+
);
|
|
7737
7752
|
}
|
|
7738
7753
|
async getAppSettings() {
|
|
7739
7754
|
const settings = await this.get(
|
|
@@ -7745,15 +7760,16 @@ var Swell = class _Swell {
|
|
|
7745
7760
|
return settings || {};
|
|
7746
7761
|
}
|
|
7747
7762
|
async getStorefrontSettings(force = false) {
|
|
7763
|
+
const storefrontSettings = this.storefront.settings;
|
|
7748
7764
|
try {
|
|
7749
|
-
const
|
|
7765
|
+
const allSettings = await this.storefront.request(
|
|
7750
7766
|
"get",
|
|
7751
7767
|
"/settings/all",
|
|
7752
7768
|
void 0,
|
|
7753
7769
|
force ? { $cache: false } : void 0,
|
|
7754
7770
|
{ force }
|
|
7755
7771
|
);
|
|
7756
|
-
const
|
|
7772
|
+
const { settings, menus, payments, subscriptions, session } = allSettings;
|
|
7757
7773
|
storefrontSettings.localizedState = {};
|
|
7758
7774
|
storefrontSettings.set({
|
|
7759
7775
|
value: settings
|
|
@@ -7781,7 +7797,7 @@ var Swell = class _Swell {
|
|
|
7781
7797
|
}
|
|
7782
7798
|
logger.error(err);
|
|
7783
7799
|
}
|
|
7784
|
-
return
|
|
7800
|
+
return storefrontSettings;
|
|
7785
7801
|
}
|
|
7786
7802
|
getStorefrontMenus() {
|
|
7787
7803
|
const menus = this.storefront.settings.getState(
|
|
@@ -15213,6 +15229,9 @@ function ShopifyAddress(instance, address, account) {
|
|
|
15213
15229
|
if (address instanceof StorefrontResource) {
|
|
15214
15230
|
address = cloneStorefrontResource(address);
|
|
15215
15231
|
}
|
|
15232
|
+
if (!address) {
|
|
15233
|
+
address = {};
|
|
15234
|
+
}
|
|
15216
15235
|
return new ShopifyResource({
|
|
15217
15236
|
address1: defer(() => address.address1),
|
|
15218
15237
|
address2: defer(() => address.address2),
|
|
@@ -16687,6 +16706,10 @@ ${injects.join("\n")}</script>`;
|
|
|
16687
16706
|
pageId = "account/order";
|
|
16688
16707
|
urlParams.id = segment3;
|
|
16689
16708
|
break;
|
|
16709
|
+
case "subscriptions":
|
|
16710
|
+
pageId = "account/subscription";
|
|
16711
|
+
urlParams.id = segment3;
|
|
16712
|
+
break;
|
|
16690
16713
|
case "register":
|
|
16691
16714
|
pageId = "account/login";
|
|
16692
16715
|
break;
|
|
@@ -19434,14 +19457,15 @@ var SwellTheme3 = class {
|
|
|
19434
19457
|
logger.debug("[SDK] Theme init start", { page: pageId, trace });
|
|
19435
19458
|
await this.themeLoader.init(this.themeConfigs || void 0);
|
|
19436
19459
|
logger.debug("[SDK] ThemeLoader init done", { page: pageId, trace });
|
|
19437
|
-
const { store, session, menus, geo, configs } = await this.getSettingsAndConfigs();
|
|
19460
|
+
const { store, session, menus, geo, configs, storefrontSettings } = await this.getSettingsAndConfigs();
|
|
19438
19461
|
logger.debug("[SDK] Theme settings load done", { page: pageId, trace });
|
|
19439
19462
|
const { settings, request, page, cart, account, customer } = await this.resolvePageData(store, configs, pageId, altTemplate);
|
|
19440
19463
|
logger.debug("[SDK] Theme page data load done", { page: pageId, trace });
|
|
19441
19464
|
this.page = page;
|
|
19442
19465
|
const globals = {
|
|
19443
19466
|
...this.globalData,
|
|
19444
|
-
store
|
|
19467
|
+
// return all storefront settings in the store
|
|
19468
|
+
store: { ...storefrontSettings, ...store },
|
|
19445
19469
|
settings,
|
|
19446
19470
|
session,
|
|
19447
19471
|
request,
|
|
@@ -19507,7 +19531,10 @@ var SwellTheme3 = class {
|
|
|
19507
19531
|
{}
|
|
19508
19532
|
)
|
|
19509
19533
|
};
|
|
19510
|
-
const session = await
|
|
19534
|
+
const [session, storeSettings] = await Promise.all([
|
|
19535
|
+
storefrontSettings.session(),
|
|
19536
|
+
storefrontSettings.get()
|
|
19537
|
+
]);
|
|
19511
19538
|
if (configs.translations) {
|
|
19512
19539
|
configs.language = configs.translations;
|
|
19513
19540
|
}
|
|
@@ -19520,11 +19547,13 @@ var SwellTheme3 = class {
|
|
|
19520
19547
|
await this.setCompatibilityConfigs(configs);
|
|
19521
19548
|
const menus = await this.resolveMenuSettings();
|
|
19522
19549
|
return {
|
|
19523
|
-
store:
|
|
19550
|
+
store: storeSettings?.store,
|
|
19524
19551
|
session,
|
|
19525
19552
|
menus,
|
|
19526
19553
|
geo,
|
|
19527
|
-
configs
|
|
19554
|
+
configs,
|
|
19555
|
+
// all settings
|
|
19556
|
+
storefrontSettings
|
|
19528
19557
|
};
|
|
19529
19558
|
}
|
|
19530
19559
|
async resolvePageData(store, configs, pageId, altTemplate) {
|
|
@@ -19613,7 +19642,8 @@ var SwellTheme3 = class {
|
|
|
19613
19642
|
this.fetchSingletonResourceCached(
|
|
19614
19643
|
"account",
|
|
19615
19644
|
() => this.fetchAccount(),
|
|
19616
|
-
() => null
|
|
19645
|
+
() => null,
|
|
19646
|
+
false
|
|
19617
19647
|
)
|
|
19618
19648
|
]);
|
|
19619
19649
|
if (!cart) {
|
|
@@ -19633,7 +19663,7 @@ var SwellTheme3 = class {
|
|
|
19633
19663
|
// Shopify only
|
|
19634
19664
|
};
|
|
19635
19665
|
}
|
|
19636
|
-
async fetchSingletonResourceCached(key, handler, defaultValue) {
|
|
19666
|
+
async fetchSingletonResourceCached(key, handler, defaultValue, isCacheble = true) {
|
|
19637
19667
|
const cacheKey = this.swell.storefront.session.getCookie();
|
|
19638
19668
|
if (!cacheKey) {
|
|
19639
19669
|
return defaultValue();
|
|
@@ -19641,7 +19671,8 @@ var SwellTheme3 = class {
|
|
|
19641
19671
|
const result = await this.swell.getCachedResource(
|
|
19642
19672
|
`${key}-${cacheKey}`,
|
|
19643
19673
|
[],
|
|
19644
|
-
handler
|
|
19674
|
+
handler,
|
|
19675
|
+
isCacheble
|
|
19645
19676
|
);
|
|
19646
19677
|
return result ?? defaultValue();
|
|
19647
19678
|
}
|
|
@@ -21172,6 +21203,7 @@ function createStorefrontRecord(resource, swell, path, parent_slug, parent_query
|
|
|
21172
21203
|
}
|
|
21173
21204
|
function createCollection(resource, swell, path, parent_slug, parent_query) {
|
|
21174
21205
|
const query = getResourceQuery(parent_slug, parent_query);
|
|
21206
|
+
query.$resource_path = path;
|
|
21175
21207
|
return new SwellStorefrontCollection(
|
|
21176
21208
|
swell,
|
|
21177
21209
|
resource,
|