@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/dist/index.mjs
CHANGED
|
@@ -515,6 +515,12 @@ async function forEachKeyDeep(obj, fn) {
|
|
|
515
515
|
}
|
|
516
516
|
|
|
517
517
|
// src/resources.ts
|
|
518
|
+
var NOT_CACHEBLE_COLLECTIONS = Object.freeze(
|
|
519
|
+
/* @__PURE__ */ new Set(["accounts:addresses", "accounts:orders", "accounts:subscriptions"])
|
|
520
|
+
);
|
|
521
|
+
function isResourceCacheble(name) {
|
|
522
|
+
return !NOT_CACHEBLE_COLLECTIONS.has(name);
|
|
523
|
+
}
|
|
518
524
|
var MAX_QUERY_PAGE_LIMIT = 100;
|
|
519
525
|
var DEFAULT_QUERY_PAGE_LIMIT = 15;
|
|
520
526
|
var StorefrontResource = class {
|
|
@@ -801,7 +807,8 @@ var SwellStorefrontCollection = class _SwellStorefrontCollection extends SwellSt
|
|
|
801
807
|
this._swell.queryParams,
|
|
802
808
|
this._getterHash
|
|
803
809
|
],
|
|
804
|
-
getter
|
|
810
|
+
getter,
|
|
811
|
+
isResourceCacheble(this._collection)
|
|
805
812
|
).then((result) => {
|
|
806
813
|
this._result = result;
|
|
807
814
|
if (result) {
|
|
@@ -915,7 +922,8 @@ var SwellStorefrontRecord = class extends SwellStorefrontResource {
|
|
|
915
922
|
this._swell.queryParams,
|
|
916
923
|
this._getterHash
|
|
917
924
|
],
|
|
918
|
-
getter
|
|
925
|
+
getter,
|
|
926
|
+
isResourceCacheble(this._collection)
|
|
919
927
|
).then((result) => {
|
|
920
928
|
return this._transformResult(result);
|
|
921
929
|
}).then((result) => {
|
|
@@ -7082,16 +7090,18 @@ var Cache = class {
|
|
|
7082
7090
|
*
|
|
7083
7091
|
* This will always return the cached value immediately if exists
|
|
7084
7092
|
*/
|
|
7085
|
-
async fetchSWR(key, fetchFn, ttl = DEFAULT_SWR_TTL) {
|
|
7093
|
+
async fetchSWR(key, fetchFn, ttl = DEFAULT_SWR_TTL, isCacheble = true) {
|
|
7086
7094
|
const trace = createTraceId();
|
|
7087
7095
|
logger.debug("[SDK] Cache fetch start", { key, trace });
|
|
7088
|
-
const cacheValue = await this.client.get(key);
|
|
7096
|
+
const cacheValue = isCacheble ? await this.client.get(key) : void 0;
|
|
7089
7097
|
let promise = SWR_PROMISE_MAP.get(key);
|
|
7090
7098
|
if (promise === void 0) {
|
|
7091
7099
|
promise = Promise.resolve().then(fetchFn).then(resolveAsyncResources).then(async (value) => {
|
|
7092
7100
|
const isNull = value === null || value === void 0;
|
|
7093
|
-
|
|
7094
|
-
|
|
7101
|
+
if (isCacheble) {
|
|
7102
|
+
await this.client.set(key, isNull ? NULL_VALUE : value, ttl);
|
|
7103
|
+
logger.debug("[SDK] Cache update done", { key, trace });
|
|
7104
|
+
}
|
|
7095
7105
|
return value;
|
|
7096
7106
|
}).finally(() => {
|
|
7097
7107
|
SWR_PROMISE_MAP.delete(key);
|
|
@@ -7597,9 +7607,14 @@ var Swell = class _Swell {
|
|
|
7597
7607
|
* Fetches a resource.
|
|
7598
7608
|
* First attempts to fetch from cache.
|
|
7599
7609
|
*/
|
|
7600
|
-
async getCachedResource(key, args, handler) {
|
|
7610
|
+
async getCachedResource(key, args, handler, isCacheble = true) {
|
|
7601
7611
|
const cacheKey = getCacheKey(key, [this.instanceId, args]);
|
|
7602
|
-
return this.getResourceCache().fetchSWR(
|
|
7612
|
+
return this.getResourceCache().fetchSWR(
|
|
7613
|
+
cacheKey,
|
|
7614
|
+
handler,
|
|
7615
|
+
void 0,
|
|
7616
|
+
isCacheble
|
|
7617
|
+
);
|
|
7603
7618
|
}
|
|
7604
7619
|
async getAppSettings() {
|
|
7605
7620
|
const settings = await this.get(
|
|
@@ -7611,15 +7626,16 @@ var Swell = class _Swell {
|
|
|
7611
7626
|
return settings || {};
|
|
7612
7627
|
}
|
|
7613
7628
|
async getStorefrontSettings(force = false) {
|
|
7629
|
+
const storefrontSettings = this.storefront.settings;
|
|
7614
7630
|
try {
|
|
7615
|
-
const
|
|
7631
|
+
const allSettings = await this.storefront.request(
|
|
7616
7632
|
"get",
|
|
7617
7633
|
"/settings/all",
|
|
7618
7634
|
void 0,
|
|
7619
7635
|
force ? { $cache: false } : void 0,
|
|
7620
7636
|
{ force }
|
|
7621
7637
|
);
|
|
7622
|
-
const
|
|
7638
|
+
const { settings, menus, payments, subscriptions, session } = allSettings;
|
|
7623
7639
|
storefrontSettings.localizedState = {};
|
|
7624
7640
|
storefrontSettings.set({
|
|
7625
7641
|
value: settings
|
|
@@ -7647,7 +7663,7 @@ var Swell = class _Swell {
|
|
|
7647
7663
|
}
|
|
7648
7664
|
logger.error(err);
|
|
7649
7665
|
}
|
|
7650
|
-
return
|
|
7666
|
+
return storefrontSettings;
|
|
7651
7667
|
}
|
|
7652
7668
|
getStorefrontMenus() {
|
|
7653
7669
|
const menus = this.storefront.settings.getState(
|
|
@@ -15079,6 +15095,9 @@ function ShopifyAddress(instance, address, account) {
|
|
|
15079
15095
|
if (address instanceof StorefrontResource) {
|
|
15080
15096
|
address = cloneStorefrontResource(address);
|
|
15081
15097
|
}
|
|
15098
|
+
if (!address) {
|
|
15099
|
+
address = {};
|
|
15100
|
+
}
|
|
15082
15101
|
return new ShopifyResource({
|
|
15083
15102
|
address1: defer(() => address.address1),
|
|
15084
15103
|
address2: defer(() => address.address2),
|
|
@@ -16553,6 +16572,10 @@ ${injects.join("\n")}</script>`;
|
|
|
16553
16572
|
pageId = "account/order";
|
|
16554
16573
|
urlParams.id = segment3;
|
|
16555
16574
|
break;
|
|
16575
|
+
case "subscriptions":
|
|
16576
|
+
pageId = "account/subscription";
|
|
16577
|
+
urlParams.id = segment3;
|
|
16578
|
+
break;
|
|
16556
16579
|
case "register":
|
|
16557
16580
|
pageId = "account/login";
|
|
16558
16581
|
break;
|
|
@@ -19308,14 +19331,15 @@ var SwellTheme3 = class {
|
|
|
19308
19331
|
logger.debug("[SDK] Theme init start", { page: pageId, trace });
|
|
19309
19332
|
await this.themeLoader.init(this.themeConfigs || void 0);
|
|
19310
19333
|
logger.debug("[SDK] ThemeLoader init done", { page: pageId, trace });
|
|
19311
|
-
const { store, session, menus, geo, configs } = await this.getSettingsAndConfigs();
|
|
19334
|
+
const { store, session, menus, geo, configs, storefrontSettings } = await this.getSettingsAndConfigs();
|
|
19312
19335
|
logger.debug("[SDK] Theme settings load done", { page: pageId, trace });
|
|
19313
19336
|
const { settings, request, page, cart, account, customer } = await this.resolvePageData(store, configs, pageId, altTemplate);
|
|
19314
19337
|
logger.debug("[SDK] Theme page data load done", { page: pageId, trace });
|
|
19315
19338
|
this.page = page;
|
|
19316
19339
|
const globals = {
|
|
19317
19340
|
...this.globalData,
|
|
19318
|
-
store
|
|
19341
|
+
// return all storefront settings in the store
|
|
19342
|
+
store: { ...storefrontSettings, ...store },
|
|
19319
19343
|
settings,
|
|
19320
19344
|
session,
|
|
19321
19345
|
request,
|
|
@@ -19381,7 +19405,10 @@ var SwellTheme3 = class {
|
|
|
19381
19405
|
{}
|
|
19382
19406
|
)
|
|
19383
19407
|
};
|
|
19384
|
-
const session = await
|
|
19408
|
+
const [session, storeSettings] = await Promise.all([
|
|
19409
|
+
storefrontSettings.session(),
|
|
19410
|
+
storefrontSettings.get()
|
|
19411
|
+
]);
|
|
19385
19412
|
if (configs.translations) {
|
|
19386
19413
|
configs.language = configs.translations;
|
|
19387
19414
|
}
|
|
@@ -19394,11 +19421,13 @@ var SwellTheme3 = class {
|
|
|
19394
19421
|
await this.setCompatibilityConfigs(configs);
|
|
19395
19422
|
const menus = await this.resolveMenuSettings();
|
|
19396
19423
|
return {
|
|
19397
|
-
store:
|
|
19424
|
+
store: storeSettings?.store,
|
|
19398
19425
|
session,
|
|
19399
19426
|
menus,
|
|
19400
19427
|
geo,
|
|
19401
|
-
configs
|
|
19428
|
+
configs,
|
|
19429
|
+
// all settings
|
|
19430
|
+
storefrontSettings
|
|
19402
19431
|
};
|
|
19403
19432
|
}
|
|
19404
19433
|
async resolvePageData(store, configs, pageId, altTemplate) {
|
|
@@ -19487,7 +19516,8 @@ var SwellTheme3 = class {
|
|
|
19487
19516
|
this.fetchSingletonResourceCached(
|
|
19488
19517
|
"account",
|
|
19489
19518
|
() => this.fetchAccount(),
|
|
19490
|
-
() => null
|
|
19519
|
+
() => null,
|
|
19520
|
+
false
|
|
19491
19521
|
)
|
|
19492
19522
|
]);
|
|
19493
19523
|
if (!cart) {
|
|
@@ -19507,7 +19537,7 @@ var SwellTheme3 = class {
|
|
|
19507
19537
|
// Shopify only
|
|
19508
19538
|
};
|
|
19509
19539
|
}
|
|
19510
|
-
async fetchSingletonResourceCached(key, handler, defaultValue) {
|
|
19540
|
+
async fetchSingletonResourceCached(key, handler, defaultValue, isCacheble = true) {
|
|
19511
19541
|
const cacheKey = this.swell.storefront.session.getCookie();
|
|
19512
19542
|
if (!cacheKey) {
|
|
19513
19543
|
return defaultValue();
|
|
@@ -19515,7 +19545,8 @@ var SwellTheme3 = class {
|
|
|
19515
19545
|
const result = await this.swell.getCachedResource(
|
|
19516
19546
|
`${key}-${cacheKey}`,
|
|
19517
19547
|
[],
|
|
19518
|
-
handler
|
|
19548
|
+
handler,
|
|
19549
|
+
isCacheble
|
|
19519
19550
|
);
|
|
19520
19551
|
return result ?? defaultValue();
|
|
19521
19552
|
}
|
|
@@ -21046,6 +21077,7 @@ function createStorefrontRecord(resource, swell, path, parent_slug, parent_query
|
|
|
21046
21077
|
}
|
|
21047
21078
|
function createCollection(resource, swell, path, parent_slug, parent_query) {
|
|
21048
21079
|
const query = getResourceQuery(parent_slug, parent_query);
|
|
21080
|
+
query.$resource_path = path;
|
|
21049
21081
|
return new SwellStorefrontCollection(
|
|
21050
21082
|
swell,
|
|
21051
21083
|
resource,
|