@swell/apps-sdk 1.0.141 → 1.0.143
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/LICENSE +22 -0
- package/README.md +304 -0
- package/dist/index.cjs +254 -62
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +252 -62
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +253 -62
- package/dist/index.mjs.map +4 -4
- package/dist/src/compatibility/shopify-objects/collection.d.ts +1 -1
- package/dist/src/resources/product.d.ts +13 -0
- package/dist/src/theme.d.ts +1 -1
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/logger.d.ts +21 -0
- package/dist/types/shopify.d.ts +3 -3
- package/dist/types/swell.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -80,6 +80,97 @@ import JSON52 from "json5";
|
|
|
80
80
|
// src/resources.ts
|
|
81
81
|
import { cloneDeep as cloneDeep2 } from "lodash-es";
|
|
82
82
|
|
|
83
|
+
// src/utils/logger.ts
|
|
84
|
+
var logLevels = {
|
|
85
|
+
error: 0,
|
|
86
|
+
warn: 1,
|
|
87
|
+
info: 2,
|
|
88
|
+
debug: 3
|
|
89
|
+
};
|
|
90
|
+
var currentLogLevel = "warn";
|
|
91
|
+
var currentTimestampFormat = "off";
|
|
92
|
+
var isStructured = false;
|
|
93
|
+
function configureSdkLogger(config = {}) {
|
|
94
|
+
if (config.level && logLevels[config.level] !== void 0) {
|
|
95
|
+
currentLogLevel = config.level;
|
|
96
|
+
}
|
|
97
|
+
if (config.timestamp) {
|
|
98
|
+
currentTimestampFormat = config.timestamp;
|
|
99
|
+
}
|
|
100
|
+
if (typeof config.structured === "boolean") {
|
|
101
|
+
isStructured = config.structured;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function getTimestamp() {
|
|
105
|
+
if (currentTimestampFormat === "iso") {
|
|
106
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
107
|
+
}
|
|
108
|
+
if (currentTimestampFormat === "unix") {
|
|
109
|
+
return Date.now();
|
|
110
|
+
}
|
|
111
|
+
return void 0;
|
|
112
|
+
}
|
|
113
|
+
function formatArgs(args) {
|
|
114
|
+
const timestamp = getTimestamp();
|
|
115
|
+
if (!isStructured) {
|
|
116
|
+
return timestamp !== void 0 ? [...args, `(${timestamp})`] : args;
|
|
117
|
+
}
|
|
118
|
+
let message = "";
|
|
119
|
+
let context = {};
|
|
120
|
+
const messageParts = [];
|
|
121
|
+
for (const arg of args) {
|
|
122
|
+
if (arg instanceof Error) {
|
|
123
|
+
context.error = {
|
|
124
|
+
name: arg.name,
|
|
125
|
+
message: arg.message,
|
|
126
|
+
stack: arg.stack
|
|
127
|
+
};
|
|
128
|
+
} else if (typeof arg === "object" && arg !== null && !Array.isArray(arg) && Object.getPrototypeOf(arg) === Object.prototype) {
|
|
129
|
+
Object.assign(context, arg);
|
|
130
|
+
} else {
|
|
131
|
+
messageParts.push(arg);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
message = messageParts.map((part) => typeof part === "object" ? JSON.stringify(part) : part).join(" ");
|
|
135
|
+
const finalLogObject = {
|
|
136
|
+
message,
|
|
137
|
+
...context,
|
|
138
|
+
...timestamp && { timestamp }
|
|
139
|
+
};
|
|
140
|
+
return [finalLogObject];
|
|
141
|
+
}
|
|
142
|
+
var logger = {
|
|
143
|
+
error: (...args) => {
|
|
144
|
+
console.error(...formatArgs(args));
|
|
145
|
+
},
|
|
146
|
+
warn: (...args) => {
|
|
147
|
+
if (logLevels[currentLogLevel] >= logLevels.warn) {
|
|
148
|
+
console.warn(...formatArgs(args));
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
info: (...args) => {
|
|
152
|
+
if (logLevels[currentLogLevel] >= logLevels.info) {
|
|
153
|
+
console.info(...formatArgs(args));
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
debug: (...args) => {
|
|
157
|
+
if (logLevels[currentLogLevel] >= logLevels.debug) {
|
|
158
|
+
console.debug(...formatArgs(args));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
function createTraceId(data) {
|
|
163
|
+
if (data === void 0) {
|
|
164
|
+
return Math.random().toString(36).substring(2, 10);
|
|
165
|
+
}
|
|
166
|
+
let hash = 5381;
|
|
167
|
+
for (let i = 0; i < data.length; i++) {
|
|
168
|
+
const char = data.charCodeAt(i);
|
|
169
|
+
hash = (hash << 5) + hash + char;
|
|
170
|
+
}
|
|
171
|
+
return (hash >>> 0).toString(16);
|
|
172
|
+
}
|
|
173
|
+
|
|
83
174
|
// src/liquid/utils.ts
|
|
84
175
|
import { Drop } from "liquidjs";
|
|
85
176
|
|
|
@@ -475,7 +566,7 @@ var StorefrontResource = class {
|
|
|
475
566
|
return instance[prop];
|
|
476
567
|
}
|
|
477
568
|
instance._result = instance._get().catch((err) => {
|
|
478
|
-
|
|
569
|
+
logger.error(err);
|
|
479
570
|
return instance._getCollectionResultOrProp(instance, prop);
|
|
480
571
|
});
|
|
481
572
|
}
|
|
@@ -483,7 +574,7 @@ var StorefrontResource = class {
|
|
|
483
574
|
return instance._result.then(() => {
|
|
484
575
|
return instance._getCollectionResultOrProp(instance, prop);
|
|
485
576
|
}).catch((err) => {
|
|
486
|
-
|
|
577
|
+
logger.error(err);
|
|
487
578
|
return null;
|
|
488
579
|
});
|
|
489
580
|
}
|
|
@@ -542,7 +633,7 @@ var StorefrontResource = class {
|
|
|
542
633
|
}
|
|
543
634
|
return result;
|
|
544
635
|
}).catch((err) => {
|
|
545
|
-
|
|
636
|
+
logger.error(err);
|
|
546
637
|
return null;
|
|
547
638
|
});
|
|
548
639
|
}
|
|
@@ -720,7 +811,7 @@ var SwellStorefrontCollection = class _SwellStorefrontCollection extends SwellSt
|
|
|
720
811
|
}
|
|
721
812
|
return result;
|
|
722
813
|
}).catch((err) => {
|
|
723
|
-
|
|
814
|
+
logger.error(err);
|
|
724
815
|
return null;
|
|
725
816
|
});
|
|
726
817
|
}
|
|
@@ -834,7 +925,7 @@ var SwellStorefrontRecord = class extends SwellStorefrontResource {
|
|
|
834
925
|
}
|
|
835
926
|
return result;
|
|
836
927
|
}).catch((err) => {
|
|
837
|
-
|
|
928
|
+
logger.error(err);
|
|
838
929
|
return null;
|
|
839
930
|
});
|
|
840
931
|
}
|
|
@@ -868,15 +959,25 @@ var SwellStorefrontSingleton = class extends SwellStorefrontResource {
|
|
|
868
959
|
}
|
|
869
960
|
async _get() {
|
|
870
961
|
if (this._getter) {
|
|
962
|
+
const trace = createTraceId();
|
|
963
|
+
logger.debug("[SDK] Resource fetch start", {
|
|
964
|
+
resource: this.constructor.name,
|
|
965
|
+
hash: this._getterHash,
|
|
966
|
+
trace
|
|
967
|
+
});
|
|
871
968
|
const getter = this._getter.bind(this);
|
|
872
969
|
this._result = Promise.resolve().then(getter).then((result) => {
|
|
970
|
+
logger.debug("[SDK] Resource fetch end", {
|
|
971
|
+
hash: this._getterHash,
|
|
972
|
+
trace
|
|
973
|
+
});
|
|
873
974
|
this._result = result;
|
|
874
975
|
if (result) {
|
|
875
976
|
Object.assign(this, result);
|
|
876
977
|
}
|
|
877
978
|
return result;
|
|
878
979
|
}).catch((err) => {
|
|
879
|
-
|
|
980
|
+
logger.error(err, { trace });
|
|
880
981
|
return null;
|
|
881
982
|
});
|
|
882
983
|
}
|
|
@@ -6960,6 +7061,7 @@ var DEFAULT_OPTIONS = Object.freeze({
|
|
|
6960
7061
|
ttl: DEFAULT_TTL
|
|
6961
7062
|
});
|
|
6962
7063
|
var NULL_VALUE = "__NULL__";
|
|
7064
|
+
var SWR_PROMISE_MAP = /* @__PURE__ */ new Map();
|
|
6963
7065
|
var Cache = class {
|
|
6964
7066
|
client;
|
|
6965
7067
|
workerCtx;
|
|
@@ -6981,19 +7083,31 @@ var Cache = class {
|
|
|
6981
7083
|
* This will always return the cached value immediately if exists
|
|
6982
7084
|
*/
|
|
6983
7085
|
async fetchSWR(key, fetchFn, ttl = DEFAULT_SWR_TTL) {
|
|
7086
|
+
const trace = createTraceId();
|
|
7087
|
+
logger.debug("[SDK] Cache fetch start", { key, trace });
|
|
6984
7088
|
const cacheValue = await this.client.get(key);
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
|
|
6988
|
-
|
|
6989
|
-
|
|
6990
|
-
|
|
6991
|
-
|
|
7089
|
+
let promise = SWR_PROMISE_MAP.get(key);
|
|
7090
|
+
if (promise === void 0) {
|
|
7091
|
+
promise = Promise.resolve().then(fetchFn).then(resolveAsyncResources).then(async (value) => {
|
|
7092
|
+
const isNull = value === null || value === void 0;
|
|
7093
|
+
await this.client.set(key, isNull ? NULL_VALUE : value, ttl);
|
|
7094
|
+
logger.debug("[SDK] Cache update done", { key, trace });
|
|
7095
|
+
return value;
|
|
7096
|
+
}).finally(() => {
|
|
7097
|
+
SWR_PROMISE_MAP.delete(key);
|
|
7098
|
+
});
|
|
7099
|
+
SWR_PROMISE_MAP.set(key, promise);
|
|
7100
|
+
}
|
|
7101
|
+
if (typeof this.workerCtx?.waitUntil === "function") {
|
|
7102
|
+
this.workerCtx.waitUntil(promise);
|
|
6992
7103
|
}
|
|
6993
7104
|
if (cacheValue !== void 0) {
|
|
7105
|
+
logger.debug("[SDK] Cache check done", { status: "HIT", key, trace });
|
|
6994
7106
|
return cacheValue === NULL_VALUE ? null : cacheValue;
|
|
6995
7107
|
}
|
|
6996
|
-
|
|
7108
|
+
logger.debug("[SDK] Cache check done", { status: "MISS", key, trace });
|
|
7109
|
+
const result = await promise;
|
|
7110
|
+
logger.debug("[SDK] Cache fetch end", { key, trace });
|
|
6997
7111
|
return result;
|
|
6998
7112
|
}
|
|
6999
7113
|
async get(key) {
|
|
@@ -7288,6 +7402,16 @@ function transformSwellVariant(params, product, variant) {
|
|
|
7288
7402
|
}
|
|
7289
7403
|
|
|
7290
7404
|
// src/resources/product.ts
|
|
7405
|
+
var SORT_OPTIONS = [
|
|
7406
|
+
{ value: "", name: "Featured" },
|
|
7407
|
+
{ value: "popularity", name: "Popularity", query: "popularity desc" },
|
|
7408
|
+
{ value: "price_asc", name: "Price, low to high", query: "price asc" },
|
|
7409
|
+
{ value: "price_desc", name: "Price, high to low", query: "price desc" },
|
|
7410
|
+
{ value: "date_asc", name: "Date, old to new", query: "date asc" },
|
|
7411
|
+
{ value: "date_desc", name: "Date, new to old", query: "date desc" },
|
|
7412
|
+
{ value: "name_asc", name: "Product name, A-Z", query: "name asc" },
|
|
7413
|
+
{ value: "name_desc", name: "Product name, Z-A", query: "name desc" }
|
|
7414
|
+
];
|
|
7291
7415
|
function transformSwellProduct(params, product) {
|
|
7292
7416
|
if (!product) {
|
|
7293
7417
|
return product;
|
|
@@ -7324,6 +7448,28 @@ var SwellProduct = class extends SwellStorefrontRecord {
|
|
|
7324
7448
|
return res;
|
|
7325
7449
|
}
|
|
7326
7450
|
};
|
|
7451
|
+
function productQueryWithFilters(swell, query = {}) {
|
|
7452
|
+
const sortBy = swell.queryParams.sort || "";
|
|
7453
|
+
const filters2 = Object.entries(swell.queryParams).reduce(
|
|
7454
|
+
(acc, [key, value]) => {
|
|
7455
|
+
if (key.startsWith("filter_")) {
|
|
7456
|
+
const qkey = key.replace("filter_", "");
|
|
7457
|
+
if (value?.gte !== void 0 || value?.lte !== void 0) {
|
|
7458
|
+
acc[qkey] = [value.gte || 0, value.lte || void 0];
|
|
7459
|
+
} else {
|
|
7460
|
+
acc[qkey] = value;
|
|
7461
|
+
}
|
|
7462
|
+
}
|
|
7463
|
+
return acc;
|
|
7464
|
+
},
|
|
7465
|
+
{}
|
|
7466
|
+
);
|
|
7467
|
+
return {
|
|
7468
|
+
sort: SORT_OPTIONS.find((option) => option.value === sortBy)?.query || void 0,
|
|
7469
|
+
$filters: filters2,
|
|
7470
|
+
...query
|
|
7471
|
+
};
|
|
7472
|
+
}
|
|
7327
7473
|
|
|
7328
7474
|
// src/api.ts
|
|
7329
7475
|
var DEFAULT_API_HOST = "https://api.schema.io";
|
|
@@ -7368,8 +7514,12 @@ var Swell = class _Swell {
|
|
|
7368
7514
|
queryParams,
|
|
7369
7515
|
workerEnv,
|
|
7370
7516
|
workerCtx,
|
|
7517
|
+
logger: loggerConfig,
|
|
7371
7518
|
...clientProps
|
|
7372
7519
|
} = params;
|
|
7520
|
+
if (loggerConfig) {
|
|
7521
|
+
configureSdkLogger(loggerConfig);
|
|
7522
|
+
}
|
|
7373
7523
|
this.url = url instanceof URL ? url : new URL(url || "");
|
|
7374
7524
|
this.config = config;
|
|
7375
7525
|
this.shopifyCompatibilityConfig = shopifyCompatibilityConfig;
|
|
@@ -7379,7 +7529,9 @@ var Swell = class _Swell {
|
|
|
7379
7529
|
this.workerCtx = workerCtx;
|
|
7380
7530
|
this.workerEnv = workerEnv;
|
|
7381
7531
|
this.resourceLoadingIndicator = params.resourceLoadingIndicator;
|
|
7382
|
-
|
|
7532
|
+
logger.info(
|
|
7533
|
+
`[SDK] KV cache: ${this.workerEnv?.THEME ? "enabled" : "disabled"}`
|
|
7534
|
+
);
|
|
7383
7535
|
if (serverHeaders) {
|
|
7384
7536
|
const { headers: headers2, swellHeaders: swellHeaders2 } = _Swell.formatHeaders(serverHeaders);
|
|
7385
7537
|
this.headers = headers2;
|
|
@@ -7493,7 +7645,7 @@ var Swell = class _Swell {
|
|
|
7493
7645
|
if (err instanceof Error) {
|
|
7494
7646
|
err.message = `Swell: unable to load settings (${err.message})`;
|
|
7495
7647
|
}
|
|
7496
|
-
|
|
7648
|
+
logger.error(err);
|
|
7497
7649
|
}
|
|
7498
7650
|
return this.storefront.settings.get();
|
|
7499
7651
|
}
|
|
@@ -7576,7 +7728,9 @@ var Swell = class _Swell {
|
|
|
7576
7728
|
decodeURIComponent(this.swellHeaders["storefront-context"])
|
|
7577
7729
|
);
|
|
7578
7730
|
} catch (error) {
|
|
7579
|
-
|
|
7731
|
+
logger.error(
|
|
7732
|
+
"[SDK] Failed to parse swell-storefront-context. Ignoring..."
|
|
7733
|
+
);
|
|
7580
7734
|
}
|
|
7581
7735
|
}
|
|
7582
7736
|
return storefrontContext;
|
|
@@ -7606,7 +7760,7 @@ var Swell = class _Swell {
|
|
|
7606
7760
|
return this.getRequestCache().fetchSWR(
|
|
7607
7761
|
getCacheKey("request", [this.instanceId, method, url, id, data, opt]),
|
|
7608
7762
|
() => {
|
|
7609
|
-
|
|
7763
|
+
logger.info("[SDK] Storefront request", { method, url, id, data });
|
|
7610
7764
|
return storefrontRequest(method, url, id, data, opt);
|
|
7611
7765
|
}
|
|
7612
7766
|
);
|
|
@@ -7630,7 +7784,7 @@ var Swell = class _Swell {
|
|
|
7630
7784
|
*/
|
|
7631
7785
|
getResourceCache() {
|
|
7632
7786
|
let cache = resourceCaches.get(this.instanceId);
|
|
7633
|
-
if (
|
|
7787
|
+
if (cache === void 0) {
|
|
7634
7788
|
cache = new ResourceCache({
|
|
7635
7789
|
kvStore: this.workerEnv?.THEME,
|
|
7636
7790
|
workerCtx: this.workerCtx
|
|
@@ -7644,7 +7798,7 @@ var Swell = class _Swell {
|
|
|
7644
7798
|
*/
|
|
7645
7799
|
getRequestCache() {
|
|
7646
7800
|
let cache = requestCaches.get(this.instanceId);
|
|
7647
|
-
if (
|
|
7801
|
+
if (cache === void 0) {
|
|
7648
7802
|
cache = new RequestCache({
|
|
7649
7803
|
kvStore: this.workerEnv?.THEME,
|
|
7650
7804
|
workerCtx: this.workerCtx
|
|
@@ -7697,6 +7851,11 @@ var SwellBackendAPI = class {
|
|
|
7697
7851
|
}
|
|
7698
7852
|
const endpointUrl = String(url).startsWith("/") ? url.substring(1) : url;
|
|
7699
7853
|
const requestUrl = `${this.apiHost}/${endpointUrl}${query}`;
|
|
7854
|
+
const trace = createTraceId();
|
|
7855
|
+
logger.debug("[SDK] Backend request start", {
|
|
7856
|
+
query: `/${endpointUrl}${query}`,
|
|
7857
|
+
trace
|
|
7858
|
+
});
|
|
7700
7859
|
const response = await fetch(requestUrl, requestOptions);
|
|
7701
7860
|
const responseText = await response.text();
|
|
7702
7861
|
let result;
|
|
@@ -7705,6 +7864,10 @@ var SwellBackendAPI = class {
|
|
|
7705
7864
|
} catch {
|
|
7706
7865
|
result = String(responseText || "").trim();
|
|
7707
7866
|
}
|
|
7867
|
+
logger.debug("[SDK] Backend request end", {
|
|
7868
|
+
status: response.status,
|
|
7869
|
+
trace
|
|
7870
|
+
});
|
|
7708
7871
|
if (response.status > 299) {
|
|
7709
7872
|
throw new SwellError(result, {
|
|
7710
7873
|
status: response.status,
|
|
@@ -14747,9 +14910,11 @@ function ShopifyCollection(instance, category) {
|
|
|
14747
14910
|
if (category instanceof StorefrontResource) {
|
|
14748
14911
|
category = cloneStorefrontResource(category);
|
|
14749
14912
|
}
|
|
14913
|
+
const productMapper = (product) => ShopifyProduct(instance, product);
|
|
14750
14914
|
const resolveProducts = makeProductsCollectionResolve(
|
|
14915
|
+
instance,
|
|
14751
14916
|
category,
|
|
14752
|
-
|
|
14917
|
+
productMapper
|
|
14753
14918
|
);
|
|
14754
14919
|
return new ShopifyResource({
|
|
14755
14920
|
all_products_count: defer(
|
|
@@ -14801,8 +14966,9 @@ function ShopifyCollection(instance, category) {
|
|
|
14801
14966
|
category,
|
|
14802
14967
|
(category2) => getFirstImage(instance, category2)
|
|
14803
14968
|
),
|
|
14804
|
-
filters:
|
|
14805
|
-
|
|
14969
|
+
filters: deferWith(
|
|
14970
|
+
category,
|
|
14971
|
+
(category2) => (category2?.filter_options ?? []).map(
|
|
14806
14972
|
(filter) => ShopifyFilter(instance, filter)
|
|
14807
14973
|
)
|
|
14808
14974
|
),
|
|
@@ -14812,9 +14978,7 @@ function ShopifyCollection(instance, category) {
|
|
|
14812
14978
|
metafields: {},
|
|
14813
14979
|
next_product: void 0,
|
|
14814
14980
|
previous_product: void 0,
|
|
14815
|
-
products:
|
|
14816
|
-
return (await resolveProducts())?.results ?? [];
|
|
14817
|
-
}),
|
|
14981
|
+
products: getProducts(instance, category, productMapper),
|
|
14818
14982
|
products_count: defer(
|
|
14819
14983
|
async () => (await resolveProducts())?.results?.length || 0
|
|
14820
14984
|
),
|
|
@@ -14853,28 +15017,35 @@ function convertToShopifySorting(value) {
|
|
|
14853
15017
|
return "manual";
|
|
14854
15018
|
}
|
|
14855
15019
|
}
|
|
14856
|
-
function
|
|
14857
|
-
|
|
14858
|
-
|
|
14859
|
-
|
|
14860
|
-
|
|
14861
|
-
|
|
14862
|
-
|
|
14863
|
-
|
|
14864
|
-
|
|
14865
|
-
|
|
15020
|
+
function getProducts(instance, object, mapper) {
|
|
15021
|
+
return deferWith(object, (object2) => {
|
|
15022
|
+
const { page, limit: limit2 } = instance.swell.queryParams;
|
|
15023
|
+
const categoryFilter = object2.id && object2.id !== "all" ? object2.id : void 0;
|
|
15024
|
+
const productQuery = categoryFilter ? { category: categoryFilter, $variants: true } : { $variants: true };
|
|
15025
|
+
const filterQuery = productQueryWithFilters(instance.swell, productQuery);
|
|
15026
|
+
const products = new SwellStorefrontCollection(
|
|
15027
|
+
instance.swell,
|
|
15028
|
+
"products",
|
|
15029
|
+
{
|
|
15030
|
+
page,
|
|
15031
|
+
limit: limit2,
|
|
15032
|
+
...filterQuery
|
|
15033
|
+
},
|
|
15034
|
+
async function() {
|
|
15035
|
+
return this._defaultGetter().call(this);
|
|
14866
15036
|
}
|
|
14867
|
-
|
|
14868
|
-
|
|
14869
|
-
|
|
14870
|
-
|
|
14871
|
-
};
|
|
15037
|
+
);
|
|
15038
|
+
return products._cloneWithCompatibilityResult(
|
|
15039
|
+
(products2) => {
|
|
15040
|
+
return { ...products2, results: products2.results.map(mapper) };
|
|
14872
15041
|
}
|
|
14873
|
-
|
|
14874
|
-
return null;
|
|
15042
|
+
);
|
|
14875
15043
|
});
|
|
15044
|
+
}
|
|
15045
|
+
function makeProductsCollectionResolve(instance, object, mapper) {
|
|
15046
|
+
const products = getProducts(instance, object, mapper);
|
|
14876
15047
|
async function resolveProducts() {
|
|
14877
|
-
const resolved = await
|
|
15048
|
+
const resolved = await products.resolve();
|
|
14878
15049
|
if (resolved && "_resolve" in resolved) {
|
|
14879
15050
|
return resolved._resolve();
|
|
14880
15051
|
}
|
|
@@ -15638,11 +15809,15 @@ function ShopifySearch(instance, search) {
|
|
|
15638
15809
|
if (search instanceof ShopifyResource) {
|
|
15639
15810
|
return search.clone();
|
|
15640
15811
|
}
|
|
15641
|
-
const resolveProducts = makeProductsCollectionResolve(
|
|
15642
|
-
|
|
15643
|
-
|
|
15644
|
-
|
|
15645
|
-
|
|
15812
|
+
const resolveProducts = makeProductsCollectionResolve(
|
|
15813
|
+
instance,
|
|
15814
|
+
search,
|
|
15815
|
+
(product) => {
|
|
15816
|
+
const shopifyProduct = ShopifyProduct(instance, product);
|
|
15817
|
+
shopifyProduct.object_type = "product";
|
|
15818
|
+
return shopifyProduct;
|
|
15819
|
+
}
|
|
15820
|
+
);
|
|
15646
15821
|
return new ShopifyResource({
|
|
15647
15822
|
default_sort_by: deferWith(
|
|
15648
15823
|
search,
|
|
@@ -19129,9 +19304,14 @@ var SwellTheme3 = class {
|
|
|
19129
19304
|
}
|
|
19130
19305
|
async initGlobals(pageId, altTemplate) {
|
|
19131
19306
|
this.pageId = pageId;
|
|
19307
|
+
const trace = createTraceId();
|
|
19308
|
+
logger.debug("[SDK] Theme init start", { page: pageId, trace });
|
|
19132
19309
|
await this.themeLoader.init(this.themeConfigs || void 0);
|
|
19310
|
+
logger.debug("[SDK] ThemeLoader init done", { page: pageId, trace });
|
|
19133
19311
|
const { store, session, menus, geo, configs } = await this.getSettingsAndConfigs();
|
|
19312
|
+
logger.debug("[SDK] Theme settings load done", { page: pageId, trace });
|
|
19134
19313
|
const { settings, request, page, cart, account, customer } = await this.resolvePageData(store, configs, pageId, altTemplate);
|
|
19314
|
+
logger.debug("[SDK] Theme page data load done", { page: pageId, trace });
|
|
19135
19315
|
this.page = page;
|
|
19136
19316
|
const globals = {
|
|
19137
19317
|
...this.globalData,
|
|
@@ -19158,6 +19338,7 @@ var SwellTheme3 = class {
|
|
|
19158
19338
|
if (this.shopifyCompatibility) {
|
|
19159
19339
|
this.shopifyCompatibility.adaptQueryParams();
|
|
19160
19340
|
}
|
|
19341
|
+
logger.debug("[SDK] Theme init end", { page: pageId, trace });
|
|
19161
19342
|
}
|
|
19162
19343
|
setGlobals(globals) {
|
|
19163
19344
|
if (this.shopifyCompatibility) {
|
|
@@ -19190,7 +19371,7 @@ var SwellTheme3 = class {
|
|
|
19190
19371
|
try {
|
|
19191
19372
|
configValue = JSON56.parse(config.file_data);
|
|
19192
19373
|
} catch (err) {
|
|
19193
|
-
|
|
19374
|
+
logger.error(`Error parsing config`, err, { configName });
|
|
19194
19375
|
configValue = {};
|
|
19195
19376
|
}
|
|
19196
19377
|
acc[configName] = configValue;
|
|
@@ -19277,7 +19458,7 @@ var SwellTheme3 = class {
|
|
|
19277
19458
|
templateConfig?.file_data || "{}"
|
|
19278
19459
|
);
|
|
19279
19460
|
} catch (err) {
|
|
19280
|
-
|
|
19461
|
+
logger.warn(err);
|
|
19281
19462
|
}
|
|
19282
19463
|
if (pageSchema?.page) {
|
|
19283
19464
|
const {
|
|
@@ -19582,7 +19763,7 @@ var SwellTheme3 = class {
|
|
|
19582
19763
|
try {
|
|
19583
19764
|
return JSON56.parse(localeConfig?.file_data || "{}");
|
|
19584
19765
|
} catch (err) {
|
|
19585
|
-
|
|
19766
|
+
logger.warn(err);
|
|
19586
19767
|
}
|
|
19587
19768
|
}
|
|
19588
19769
|
return {};
|
|
@@ -19751,10 +19932,20 @@ var SwellTheme3 = class {
|
|
|
19751
19932
|
return "";
|
|
19752
19933
|
}
|
|
19753
19934
|
template = unescapeLiquidSyntax(template);
|
|
19935
|
+
const trace = createTraceId();
|
|
19754
19936
|
try {
|
|
19755
|
-
|
|
19937
|
+
logger.debug("[SDK] Render template start", {
|
|
19938
|
+
config: config.name,
|
|
19939
|
+
trace
|
|
19940
|
+
});
|
|
19941
|
+
const result = await this.liquidSwell.parseAndRender(template, data);
|
|
19942
|
+
logger.debug("[SDK] Render template end", {
|
|
19943
|
+
config: config.name,
|
|
19944
|
+
trace
|
|
19945
|
+
});
|
|
19946
|
+
return result;
|
|
19756
19947
|
} catch (err) {
|
|
19757
|
-
|
|
19948
|
+
logger.error(err);
|
|
19758
19949
|
return `<!-- template render error: ${err.message} -->`;
|
|
19759
19950
|
}
|
|
19760
19951
|
}
|
|
@@ -19762,7 +19953,7 @@ var SwellTheme3 = class {
|
|
|
19762
19953
|
try {
|
|
19763
19954
|
return await this.liquidSwell.parseAndRender(templateString, data);
|
|
19764
19955
|
} catch (err) {
|
|
19765
|
-
|
|
19956
|
+
logger.error(err);
|
|
19766
19957
|
return "";
|
|
19767
19958
|
}
|
|
19768
19959
|
}
|
|
@@ -19786,7 +19977,7 @@ var SwellTheme3 = class {
|
|
|
19786
19977
|
);
|
|
19787
19978
|
}
|
|
19788
19979
|
} catch (err) {
|
|
19789
|
-
|
|
19980
|
+
logger.warn(err);
|
|
19790
19981
|
return void 0;
|
|
19791
19982
|
}
|
|
19792
19983
|
} else if (config?.file_path?.endsWith(".liquid")) {
|
|
@@ -19839,11 +20030,10 @@ var SwellTheme3 = class {
|
|
|
19839
20030
|
try {
|
|
19840
20031
|
return JSON56.parse(content);
|
|
19841
20032
|
} catch (err) {
|
|
19842
|
-
|
|
19843
|
-
|
|
19844
|
-
config.file_path,
|
|
20033
|
+
logger.error("[SDK] Unable to render theme template", {
|
|
20034
|
+
file: config.file_path,
|
|
19845
20035
|
content
|
|
19846
|
-
);
|
|
20036
|
+
});
|
|
19847
20037
|
throw new PageError(err);
|
|
19848
20038
|
}
|
|
19849
20039
|
}
|
|
@@ -20100,7 +20290,7 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
|
|
|
20100
20290
|
try {
|
|
20101
20291
|
schema = JSON56.parse(resolvedConfig?.file_data) || void 0;
|
|
20102
20292
|
} catch (err) {
|
|
20103
|
-
|
|
20293
|
+
logger.warn(err);
|
|
20104
20294
|
}
|
|
20105
20295
|
}
|
|
20106
20296
|
return schema;
|
|
@@ -20490,7 +20680,7 @@ function parseJsonConfig(config) {
|
|
|
20490
20680
|
try {
|
|
20491
20681
|
return JSON56.parse(config?.file_data || "{}");
|
|
20492
20682
|
} catch (err) {
|
|
20493
|
-
|
|
20683
|
+
logger.warn(err);
|
|
20494
20684
|
return {};
|
|
20495
20685
|
}
|
|
20496
20686
|
}
|
|
@@ -20966,6 +21156,7 @@ export {
|
|
|
20966
21156
|
adaptShopifyMenuData,
|
|
20967
21157
|
arrayToObject,
|
|
20968
21158
|
cloneStorefrontResource,
|
|
21159
|
+
configureSdkLogger,
|
|
20969
21160
|
deferMenuItemUrlAndResource,
|
|
20970
21161
|
dehydrateSwellRefsInStorefrontResources,
|
|
20971
21162
|
extractSettingsFromForm,
|