@occluze/tether 0.6.7 → 0.6.8
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 +3 -3
- package/dist/esm/astro.js +2 -2
- package/dist/esm/chunks/account-C3NP6HFB.js +1 -0
- package/dist/esm/chunks/account-pages-WLK374FO.js +1 -0
- package/dist/esm/chunks/analytics-G3SAWMNL.js +1 -0
- package/dist/esm/chunks/chunk-27PJJZGC.js +1 -0
- package/dist/esm/chunks/chunk-2FSXS55U.js +1 -0
- package/dist/esm/chunks/chunk-FCSWQDVV.js +1 -0
- package/dist/esm/chunks/chunk-FOMSMIAM.js +1 -0
- package/dist/esm/chunks/chunk-GZJTCLLW.js +1 -0
- package/dist/esm/chunks/chunk-HEQILZVR.js +1 -0
- package/dist/esm/chunks/chunk-JOOEXYF3.js +4 -0
- package/dist/esm/chunks/chunk-MPTQYLSM.js +1 -0
- package/dist/esm/chunks/chunk-NEHZ37TU.js +3 -0
- package/dist/esm/chunks/chunk-V74KGEJF.js +1 -0
- package/dist/esm/chunks/chunk-VT4CDUJJ.js +1 -0
- package/dist/esm/chunks/chunk-YJLWX2HK.js +1 -0
- package/dist/esm/chunks/diagnose-6VVGZNTY.js +14 -0
- package/dist/esm/chunks/extras-GJVRDFM3.js +1 -0
- package/dist/esm/chunks/markets-ui-UNB4PTA7.js +1 -0
- package/dist/esm/chunks/search-OU75RNQL.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/server.js +2 -1
- package/dist/presets/barba.esm.js +56 -36
- package/dist/tether.account-pages.js +773 -442
- package/dist/tether.account-pages.min.js +1 -1
- package/dist/tether.account.js +648 -318
- package/dist/tether.account.min.js +1 -1
- package/dist/tether.analytics.js +318 -191
- package/dist/tether.analytics.min.js +1 -1
- package/dist/tether.diagnose.js +331 -242
- package/dist/tether.diagnose.min.js +2 -2
- package/dist/tether.extras.js +78 -33
- package/dist/tether.extras.min.js +1 -1
- package/dist/tether.js +3176 -2015
- package/dist/tether.markets.js +231 -126
- package/dist/tether.markets.min.js +1 -1
- package/dist/tether.min.js +0 -0
- package/dist/tether.min.js.map +4 -4
- package/dist/tether.search.js +221 -126
- package/dist/tether.search.min.js +1 -1
- package/package.json +23 -4
- package/src/account/addresses-view.js +92 -0
- package/src/account/browser-session.js +359 -0
- package/src/account/markup.js +48 -0
- package/src/account/operations.js +180 -0
- package/src/account/order-lines.js +96 -0
- package/src/account/order-list.js +91 -0
- package/src/account/order-page.js +192 -0
- package/src/account/page-events.js +288 -0
- package/src/account/server-client.js +172 -0
- package/src/account/shared.js +111 -0
- package/src/account/shopify-auth.js +150 -0
- package/src/account/subscriptions-view.js +158 -0
- package/src/account-api.js +118 -0
- package/src/account-links.js +35 -0
- package/src/account-pages.js +69 -298
- package/src/account.js +280 -323
- package/src/amounts.js +36 -0
- package/src/analytics-shopify.js +241 -0
- package/src/analytics.js +304 -184
- package/src/api-version.js +75 -25
- package/src/astro.js +233 -68
- package/src/cart/checkout.js +97 -0
- package/src/cart/drawer.js +138 -0
- package/src/cart/mutations.js +234 -0
- package/src/cart/render.js +294 -0
- package/src/cart/store.js +326 -0
- package/src/cart.js +320 -488
- package/src/client.js +214 -78
- package/src/collection.js +126 -57
- package/src/config.js +323 -59
- package/src/controls/cart-controls.js +155 -0
- package/src/controls/discount.js +96 -0
- package/src/controls/extras.js +63 -0
- package/src/controls/navigation.js +83 -0
- package/src/diagnose-markup.js +333 -0
- package/src/diagnose.js +251 -202
- package/src/dom.js +219 -220
- package/src/extras.js +119 -37
- package/src/fragments.js +115 -22
- package/src/images.js +104 -0
- package/src/index.js +245 -287
- package/src/initial.js +78 -66
- package/src/lazy-iife.js +92 -22
- package/src/lazy.js +25 -4
- package/src/loader.js +263 -124
- package/src/market-codes.js +35 -0
- package/src/markets-ui.js +169 -55
- package/src/markets.js +286 -85
- package/src/markup.js +64 -0
- package/src/mounting.js +214 -91
- package/src/page-market.js +116 -0
- package/src/parts/account-pages.js +4 -1
- package/src/parts/account.js +4 -1
- package/src/parts/analytics.js +4 -1
- package/src/parts/diagnose.js +4 -1
- package/src/parts/extras.js +4 -1
- package/src/parts/markets.js +4 -1
- package/src/parts/search.js +4 -1
- package/src/presets/barba.js +120 -30
- package/src/product-events.js +130 -0
- package/src/product-render.js +257 -0
- package/src/product-state.js +318 -0
- package/src/product.js +233 -459
- package/src/repeaters.js +173 -0
- package/src/search.js +277 -107
- package/src/selling-plans.js +107 -47
- package/src/server.js +168 -205
- package/src/shopify-values.js +89 -0
- package/src/status.js +99 -39
- package/src/store-html.js +0 -0
- package/src/storefront/catalog.js +199 -0
- package/src/storefront/json-ld.js +167 -0
- package/src/variant-render.js +165 -0
- package/types/astro.d.ts +13 -2
- package/types/index.d.ts +178 -27
- package/types/server.d.ts +89 -17
- package/dist/esm/chunks/account-Q6E2TFEV.js +0 -1
- package/dist/esm/chunks/account-pages-UZXR4R5F.js +0 -1
- package/dist/esm/chunks/analytics-IJBKATUP.js +0 -1
- package/dist/esm/chunks/chunk-4QJKLPYR.js +0 -1
- package/dist/esm/chunks/chunk-64TUD3QR.js +0 -1
- package/dist/esm/chunks/chunk-AJLPU2JC.js +0 -4
- package/dist/esm/chunks/chunk-FIOZPPC5.js +0 -1
- package/dist/esm/chunks/chunk-K2YEQAIH.js +0 -1
- package/dist/esm/chunks/chunk-KIDH76B7.js +0 -1
- package/dist/esm/chunks/chunk-PAYT5ZD7.js +0 -1
- package/dist/esm/chunks/chunk-RREHGH4A.js +0 -1
- package/dist/esm/chunks/chunk-SSJT43CJ.js +0 -1
- package/dist/esm/chunks/chunk-VC46IEJQ.js +0 -1
- package/dist/esm/chunks/diagnose-3WVAWNTX.js +0 -14
- package/dist/esm/chunks/extras-7I7WJX35.js +0 -1
- package/dist/esm/chunks/markets-ui-545XLFTE.js +0 -1
- package/dist/esm/chunks/search-NILMGYXG.js +0 -1
package/dist/tether.diagnose.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
(() => {
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __export = (target, all) => {
|
|
@@ -16,7 +17,7 @@
|
|
|
16
17
|
|
|
17
18
|
// tether-core:config.js
|
|
18
19
|
var m = window.Tether.__core["config.js"];
|
|
19
|
-
var { DEFAULTS, cfg, configure, isConfigured, log, reportError, warn } = m;
|
|
20
|
+
var { DEFAULTS, cfg, configure, isConfigured, log, reportError, resolveConfig, toMetafieldIdentifier, warn } = m;
|
|
20
21
|
|
|
21
22
|
// tether-core:client.js
|
|
22
23
|
var m2 = window.Tether.__core["client.js"];
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
|
|
25
26
|
// tether-core:dom.js
|
|
26
27
|
var m3 = window.Tether.__core["dom.js"];
|
|
27
|
-
var { attr, busy, cdnUrl,
|
|
28
|
+
var { attr, busy, cdnUrl, emit, formatDate, formatMoney, formatPercent, get, has, hasTemplate, imageUrl, notifyLayoutChanged, parseJSONAttr, productUrl, qsa, repeat, repeatKeyed, sameImage, scoped, sel, setImage, setSelected, setStoreHtml, setText, setTextTracked, show, toAttributes, watchImages } = m3;
|
|
28
29
|
|
|
29
30
|
// tether-core:loader.js
|
|
30
31
|
var m4 = window.Tether.__core["loader.js"];
|
|
@@ -39,118 +40,55 @@
|
|
|
39
40
|
var { STATUS_KEYS, boundary, isNotFound, ownedBy, resolveProductKey, setScopeStatus } = m6;
|
|
40
41
|
|
|
41
42
|
// src/api-version.js
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return
|
|
43
|
+
var QUARTERLY_VERSION = /^(\d{4})-(01|04|07|10)$/;
|
|
44
|
+
var MONTHS_PER_QUARTER = 3;
|
|
45
|
+
var QUARTERS_PER_YEAR = 4;
|
|
46
|
+
var MONTHS_SUPPORTED = 12;
|
|
47
|
+
var UPGRADE_WARNING_MONTHS = 3;
|
|
48
|
+
var AVERAGE_MONTH_MS = 30.44 * 24 * 3600 * 1e3;
|
|
49
|
+
function parseVersion(version) {
|
|
50
|
+
const match = QUARTERLY_VERSION.exec(typeof version === "string" ? version : "");
|
|
51
|
+
if (!match) return null;
|
|
52
|
+
return { year: Number(match[1]), month: Number(match[2]) };
|
|
53
|
+
}
|
|
54
|
+
var formatVersion = (year, month) => `${year}-${String(month).padStart(2, "0")}`;
|
|
55
|
+
function nextApiVersion(version, steps = 1) {
|
|
56
|
+
const parsed = parseVersion(version);
|
|
57
|
+
if (!parsed) throw new Error(`not a quarterly Shopify API version: ${version}`);
|
|
58
|
+
const quarter = parsed.year * QUARTERS_PER_YEAR + (parsed.month - 1) / MONTHS_PER_QUARTER + steps;
|
|
59
|
+
return formatVersion(Math.floor(quarter / QUARTERS_PER_YEAR), quarter % QUARTERS_PER_YEAR * MONTHS_PER_QUARTER + 1);
|
|
52
60
|
}
|
|
53
61
|
function apiVersionStatus(version, now = /* @__PURE__ */ new Date()) {
|
|
54
|
-
if (version === "unstable")
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
const
|
|
62
|
+
if (version === "unstable") {
|
|
63
|
+
return { version, ok: false, note: '"unstable" changes without notice: pin a dated version such as 2026-07' };
|
|
64
|
+
}
|
|
65
|
+
const parsed = parseVersion(version);
|
|
66
|
+
if (!parsed) return { version, ok: false, note: "not a quarterly version (YYYY-01, -04, -07 or -10)" };
|
|
67
|
+
const released = new Date(Date.UTC(parsed.year, parsed.month - 1, 1));
|
|
68
|
+
const supportedUntil = new Date(Date.UTC(parsed.year, parsed.month - 1 + MONTHS_SUPPORTED, 1));
|
|
69
|
+
const monthsLeft = (supportedUntil.getTime() - now.getTime()) / AVERAGE_MONTH_MS;
|
|
70
|
+
const isReleased = released <= now;
|
|
60
71
|
let note = `supported until about ${supportedUntil.toISOString().slice(0, 7)}`;
|
|
61
|
-
if (
|
|
62
|
-
else if (monthsLeft <= 0)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// src/markets.js
|
|
68
|
-
var COUNTRY = /^[A-Z]{2}$/;
|
|
69
|
-
var REGIONAL_LANGUAGES = /* @__PURE__ */ new Set(["PT_BR", "PT_PT", "ZH_CN", "ZH_TW"]);
|
|
70
|
-
var storageKey = () => `${cfg.prefix}:market:${cfg.domain}`;
|
|
71
|
-
var defaultEnv = () => ({
|
|
72
|
-
document: typeof document !== "undefined" ? document : null,
|
|
73
|
-
location: typeof window !== "undefined" ? window.location : null,
|
|
74
|
-
storage: (() => {
|
|
75
|
-
try {
|
|
76
|
-
return window.localStorage;
|
|
77
|
-
} catch {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
})(),
|
|
81
|
-
global: typeof window !== "undefined" ? window : {}
|
|
82
|
-
});
|
|
83
|
-
function toCountry(v) {
|
|
84
|
-
const c = String(v || "").trim().toUpperCase();
|
|
85
|
-
return COUNTRY.test(c) && c !== "XX" && c !== "T1" ? c : null;
|
|
86
|
-
}
|
|
87
|
-
function toLanguage(v) {
|
|
88
|
-
const raw = String(v || "").trim().replace("-", "_").toUpperCase();
|
|
89
|
-
if (!raw) return null;
|
|
90
|
-
if (REGIONAL_LANGUAGES.has(raw)) return raw;
|
|
91
|
-
const primary = raw.split("_")[0];
|
|
92
|
-
return /^[A-Z]{2,3}$/.test(primary) ? primary : null;
|
|
93
|
-
}
|
|
94
|
-
function readCookie(doc, name) {
|
|
95
|
-
if (!doc || !name) return null;
|
|
96
|
-
const hit = String(doc.cookie || "").split(";").map((c) => c.trim()).find((c) => c.startsWith(`${name}=`));
|
|
97
|
-
return hit ? decodeURIComponent(hit.slice(name.length + 1)) : null;
|
|
98
|
-
}
|
|
99
|
-
var lookup = (locales, key) => {
|
|
100
|
-
if (!locales || !key) return null;
|
|
101
|
-
const k = String(key).toLowerCase();
|
|
102
|
-
const found = Object.keys(locales).find((x) => x.toLowerCase() === k);
|
|
103
|
-
return found ? locales[found] : null;
|
|
104
|
-
};
|
|
105
|
-
var readers = {
|
|
106
|
-
saved(m7, env) {
|
|
107
|
-
if (m7.remember === false || !env.storage) return null;
|
|
108
|
-
try {
|
|
109
|
-
return JSON.parse(env.storage.getItem(storageKey()) || "null");
|
|
110
|
-
} catch {
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
server(m7, env) {
|
|
115
|
-
const meta = (name) => env.document?.querySelector?.(`meta[name="${name}"]`)?.getAttribute("content");
|
|
116
|
-
const country = env.global.TETHER_COUNTRY || meta("tether-country") || readCookie(env.document, m7.cookie || "tether_country");
|
|
117
|
-
const language = env.global.TETHER_LANGUAGE || meta("tether-language");
|
|
118
|
-
return { country, language };
|
|
119
|
-
},
|
|
120
|
-
webflow(m7, env) {
|
|
121
|
-
const segment = (env.location?.pathname || "/").split("/").filter(Boolean)[0];
|
|
122
|
-
const fromPath = lookup(m7.locales, segment);
|
|
123
|
-
if (fromPath) return fromPath;
|
|
124
|
-
const lang = env.document?.documentElement?.getAttribute("lang");
|
|
125
|
-
if (!lang) return null;
|
|
126
|
-
const mapped = lookup(m7.locales, lang) || lookup(m7.locales, lang.split("-")[0]);
|
|
127
|
-
if (mapped) return { locale: lang, ...mapped };
|
|
128
|
-
if (m7.locales && m7.strict) return null;
|
|
129
|
-
const region = lang.split("-")[1];
|
|
130
|
-
return { language: lang, country: region && region.length === 2 ? region : null, locale: lang };
|
|
72
|
+
if (!isReleased) note = "not released yet (release candidate at best)";
|
|
73
|
+
else if (monthsLeft <= 0) {
|
|
74
|
+
note = "no longer supported: Shopify falls back to the oldest supported version. Upgrade (see README)";
|
|
75
|
+
} else if (monthsLeft < UPGRADE_WARNING_MONTHS) {
|
|
76
|
+
note = `${note}: plan the upgrade to ${nextApiVersion(version)} or later (see README)`;
|
|
131
77
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
list.forEach((name) => {
|
|
140
|
-
const r = readers[name]?.(markets, env);
|
|
141
|
-
if (!r) return;
|
|
142
|
-
const vals = { country: toCountry(r.country), language: toLanguage(r.language), locale: r.locale || null };
|
|
143
|
-
Object.entries(vals).forEach(([k, v]) => {
|
|
144
|
-
if (v && !out[k]) {
|
|
145
|
-
out[k] = v;
|
|
146
|
-
out.sources[k] = name;
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
return out;
|
|
78
|
+
return {
|
|
79
|
+
version,
|
|
80
|
+
ok: isReleased && monthsLeft > 0,
|
|
81
|
+
monthsLeft: Math.round(monthsLeft),
|
|
82
|
+
next: nextApiVersion(version),
|
|
83
|
+
note
|
|
84
|
+
};
|
|
151
85
|
}
|
|
152
86
|
|
|
153
|
-
//
|
|
87
|
+
// tether-core:lazy.js
|
|
88
|
+
var m7 = window.Tether.__core["lazy.js"];
|
|
89
|
+
var { coreModules, loadPart } = m7;
|
|
90
|
+
|
|
91
|
+
// src/diagnose-markup.js
|
|
154
92
|
var SHOW = /* @__PURE__ */ new Set([
|
|
155
93
|
"in-stock",
|
|
156
94
|
"out-of-stock",
|
|
@@ -234,7 +172,8 @@
|
|
|
234
172
|
"swatch",
|
|
235
173
|
"image"
|
|
236
174
|
]);
|
|
237
|
-
var
|
|
175
|
+
var ATTRIBUTES = new Set(
|
|
176
|
+
`account account-bind account-link account-login account-logout add-label add-to-cart adding-text
|
|
238
177
|
always-enabled bind cart-checkout-charge cart-clear cart-close cart-count cart-discounts cart-drawer cart-label cart-lines
|
|
239
178
|
cart-note cart-open cart-subtotal cart-total cart-warning checkout code collection collection-bind countries country
|
|
240
179
|
country-bind country-label country-select default-plan default-purchase discount discount-code discount-form discount-input
|
|
@@ -247,191 +186,341 @@
|
|
|
247
186
|
plan-value product products purchase purchase-mode qty qty-minus qty-plus quantity recommendations reverse search
|
|
248
187
|
search-bind search-collections search-input search-limit search-min search-products search-queries search-results
|
|
249
188
|
search-state show soldout-text sort state subscribe-text variant variant-select variant-url max-width max-height crop
|
|
250
|
-
sig label hydrated busy`.split(/\s+/).filter(Boolean)
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
189
|
+
sig label hydrated busy`.split(/\s+/).filter(Boolean)
|
|
190
|
+
);
|
|
191
|
+
var PRODUCT_ONLY = [
|
|
192
|
+
"bind",
|
|
193
|
+
"option-list",
|
|
194
|
+
"option",
|
|
195
|
+
"variant-select",
|
|
196
|
+
"add-to-cart",
|
|
197
|
+
"purchase",
|
|
198
|
+
"plan-list",
|
|
199
|
+
"plan",
|
|
200
|
+
"qty",
|
|
201
|
+
"line-attribute"
|
|
202
|
+
];
|
|
203
|
+
var REPEATERS = ["option-list", "plan-list", "cart-lines", "list"];
|
|
204
|
+
var METAFIELD_BIND = "metafield:";
|
|
205
|
+
var IMAGE_BIND = /^image:\d+$/;
|
|
206
|
+
var DESCRIBED_CLASSES = 2;
|
|
207
|
+
function editDistance(from, to) {
|
|
208
|
+
let previous = Array.from({ length: to.length + 1 }, (_, index) => index);
|
|
209
|
+
for (let i = 1; i <= from.length; i++) {
|
|
210
|
+
const row = [i];
|
|
211
|
+
for (let j = 1; j <= to.length; j++) {
|
|
212
|
+
const substitution = (previous[j - 1] ?? 0) + (from[i - 1] === to[j - 1] ? 0 : 1);
|
|
213
|
+
row.push(Math.min((previous[j] ?? 0) + 1, (row[j - 1] ?? 0) + 1, substitution));
|
|
214
|
+
}
|
|
215
|
+
previous = row;
|
|
256
216
|
}
|
|
257
|
-
return
|
|
217
|
+
return previous[to.length] ?? 0;
|
|
258
218
|
}
|
|
259
219
|
function didYouMean(value, options, prefix = "") {
|
|
260
220
|
let best = null;
|
|
261
|
-
let
|
|
262
|
-
for (const
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
265
|
-
|
|
266
|
-
best =
|
|
221
|
+
let bestDistance = Infinity;
|
|
222
|
+
for (const option of options) {
|
|
223
|
+
const distance = editDistance(value, option);
|
|
224
|
+
if (distance < bestDistance) {
|
|
225
|
+
bestDistance = distance;
|
|
226
|
+
best = option;
|
|
267
227
|
}
|
|
268
228
|
}
|
|
269
|
-
|
|
229
|
+
const closeEnough = Math.max(2, Math.floor(value.length / 4));
|
|
230
|
+
return best !== null && bestDistance <= closeEnough ? ` Did you mean "${prefix}${best}"?` : "";
|
|
270
231
|
}
|
|
271
|
-
var mask = (t) => t ? `${String(t).slice(0, 4)}\u2026${String(t).slice(-4)} (${String(t).length} chars)` : "(missing)";
|
|
272
232
|
function describe(el) {
|
|
273
233
|
const id = el.id ? `#${el.id}` : "";
|
|
274
|
-
const
|
|
275
|
-
|
|
234
|
+
const classes = el.className && typeof el.className === "string" ? el.className.trim().split(/\s+/) : [];
|
|
235
|
+
const classText = classes.length ? `.${classes.slice(0, DESCRIBED_CLASSES).join(".")}` : "";
|
|
236
|
+
return `<${el.tagName.toLowerCase()}${id}${classText}>`;
|
|
276
237
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const add = (level, message, el) => problems.push({ level, message, element: el ? describe(el) : void 0, el });
|
|
280
|
-
const inProduct = (el) => Boolean(el.closest(sel("product")));
|
|
281
|
-
const listSel = `${sel("collection")},${sel("products")},${sel("recommendations")}`;
|
|
238
|
+
var listSelector = () => `${sel("collection")},${sel("products")},${sel("recommendations")}`;
|
|
239
|
+
function checkProductKeys(root, add) {
|
|
282
240
|
qsa(root, sel("product")).forEach((el) => {
|
|
283
|
-
if (el.closest(
|
|
241
|
+
if (el.closest(listSelector()) && el.closest(sel("list"))) return;
|
|
284
242
|
const { key, fromUrl, raw } = resolveProductKey(el);
|
|
285
|
-
if (!raw)
|
|
286
|
-
|
|
243
|
+
if (!raw) {
|
|
244
|
+
add(
|
|
245
|
+
"error",
|
|
246
|
+
`${attr("product")} has no value. Bind it to the Shopify handle (CMS field), or use "url:handle".`,
|
|
247
|
+
el
|
|
248
|
+
);
|
|
249
|
+
} else if (fromUrl && !key) {
|
|
250
|
+
add("warn", `${attr("product")}="${raw}" but this URL has no value for it (e.g. ?handle=my-product).`, el);
|
|
251
|
+
}
|
|
287
252
|
});
|
|
288
|
-
|
|
289
|
-
|
|
253
|
+
}
|
|
254
|
+
function checkPlacement(root, add) {
|
|
255
|
+
for (const name of PRODUCT_ONLY) {
|
|
290
256
|
qsa(root, sel(name)).forEach((el) => {
|
|
291
|
-
if (
|
|
257
|
+
if (el.closest(sel("product"))) return;
|
|
292
258
|
if (name === "line-attribute" && el.closest(sel("group"))) return;
|
|
293
259
|
add("warn", `${attr(name)} outside any ${attr("product")}: it does nothing here.`, el);
|
|
294
260
|
});
|
|
295
|
-
}
|
|
261
|
+
}
|
|
296
262
|
qsa(root, sel("group-add")).forEach((el) => {
|
|
297
263
|
if (!el.closest(sel("group"))) add("warn", `${attr("group-add")} outside a ${attr("group")}.`, el);
|
|
298
264
|
});
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
265
|
+
for (const name of REPEATERS) {
|
|
266
|
+
qsa(root, sel(name)).forEach((el) => {
|
|
267
|
+
if (!el.firstElementChild && !hasTemplate(el)) {
|
|
268
|
+
add("warn", `${attr(name)} without a template child: put one example element inside it.`, el);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
qsa(root, listSelector()).forEach((el) => {
|
|
273
|
+
if (!qsa(el, sel("list")).length) {
|
|
274
|
+
add("error", `List without a ${attr("list")} child: products have nowhere to render.`, el);
|
|
302
275
|
}
|
|
303
|
-
}));
|
|
304
|
-
qsa(root, listSel).forEach((el) => {
|
|
305
|
-
if (!qsa(el, sel("list")).length) add("error", `List without a ${attr("list")} child: products have nowhere to render.`, el);
|
|
306
276
|
});
|
|
277
|
+
}
|
|
278
|
+
function checkValues(root, add) {
|
|
307
279
|
qsa(root, sel("show")).forEach((el) => {
|
|
308
|
-
const
|
|
309
|
-
if (!SHOW.has(
|
|
280
|
+
const value = get(el, "show") ?? "";
|
|
281
|
+
if (!SHOW.has(value)) add("warn", `Unknown ${attr("show")}="${value}".${didYouMean(value, SHOW)}`, el);
|
|
310
282
|
});
|
|
311
283
|
qsa(root, sel("bind")).forEach((el) => {
|
|
312
|
-
const
|
|
313
|
-
if (!
|
|
314
|
-
add("warn", `Unknown ${attr("bind")}="${
|
|
284
|
+
const value = get(el, "bind") || "";
|
|
285
|
+
if (!value || BIND.has(value) || IMAGE_BIND.test(value) || value.startsWith(METAFIELD_BIND)) return;
|
|
286
|
+
add("warn", `Unknown ${attr("bind")}="${value}": it stays empty.${didYouMean(value, BIND)}`, el);
|
|
315
287
|
});
|
|
288
|
+
}
|
|
289
|
+
function checkMetafieldBinds(root, add) {
|
|
290
|
+
qsa(root, sel("bind")).forEach((el) => {
|
|
291
|
+
const value = get(el, "bind") || "";
|
|
292
|
+
if (!value.startsWith(METAFIELD_BIND)) return;
|
|
293
|
+
const ref = value.slice(METAFIELD_BIND.length);
|
|
294
|
+
const listed = cfg.metafields.some(
|
|
295
|
+
(metafield) => (typeof metafield === "string" ? metafield : `${metafield.namespace}.${metafield.key}`) === ref
|
|
296
|
+
);
|
|
297
|
+
if (!listed) {
|
|
298
|
+
add("error", `${attr("bind")}="${value}" but "${ref}" is not in config.metafields, so it stays empty.`, el);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
function checkAttributeNames(root, add) {
|
|
316
303
|
const prefix = `${cfg.prefix}-`;
|
|
317
|
-
const
|
|
304
|
+
const reported = /* @__PURE__ */ new Set();
|
|
318
305
|
qsa(root, "*").forEach((el) => {
|
|
319
|
-
for (const
|
|
320
|
-
if (!
|
|
321
|
-
const name =
|
|
322
|
-
if (
|
|
323
|
-
|
|
324
|
-
add("warn", `Unknown attribute ${
|
|
306
|
+
for (const { name: fullName } of el.attributes) {
|
|
307
|
+
if (!fullName.startsWith(prefix)) continue;
|
|
308
|
+
const name = fullName.slice(prefix.length);
|
|
309
|
+
if (ATTRIBUTES.has(name) || reported.has(name)) continue;
|
|
310
|
+
reported.add(name);
|
|
311
|
+
add("warn", `Unknown attribute ${fullName}: Tether ignores it.${didYouMean(name, ATTRIBUTES, prefix)}`, el);
|
|
325
312
|
}
|
|
326
313
|
});
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const listed = (cfg.metafields || []).some((m7) => (typeof m7 === "string" ? m7 : `${m7.namespace}.${m7.key}`) === ref);
|
|
332
|
-
if (!listed) add("error", `${attr("bind")}="${k}" but "${ref}" is not in config.metafields, so it stays empty.`, el);
|
|
333
|
-
});
|
|
334
|
-
if (qsa(root, sel("cart-open")).length && !qsa(root, sel("cart-drawer")).length) {
|
|
314
|
+
}
|
|
315
|
+
function checkCartAndScopes(root, add) {
|
|
316
|
+
const drawers = qsa(root, sel("cart-drawer")).length;
|
|
317
|
+
if (qsa(root, sel("cart-open")).length && !drawers) {
|
|
335
318
|
add("warn", `${attr("cart-open")} exists but there is no ${attr("cart-drawer")} on this page.`);
|
|
336
319
|
}
|
|
337
|
-
if (
|
|
320
|
+
if (drawers > 1) add("warn", `More than one ${attr("cart-drawer")}.`);
|
|
338
321
|
qsa(root, `[${attr("state")}="error"]`).forEach((el) => {
|
|
339
322
|
if (el.matches(boundary())) add("error", `Scope failed to load (${get(el, "error") || "error"}).`, el);
|
|
340
323
|
});
|
|
324
|
+
}
|
|
325
|
+
function checkMarkup(root = document) {
|
|
326
|
+
const problems = [];
|
|
327
|
+
const add = (level, message, el) => {
|
|
328
|
+
problems.push(el ? { level, message, element: describe(el), el } : { level, message });
|
|
329
|
+
};
|
|
330
|
+
checkProductKeys(root, add);
|
|
331
|
+
checkPlacement(root, add);
|
|
332
|
+
checkValues(root, add);
|
|
333
|
+
checkAttributeNames(root, add);
|
|
334
|
+
checkMetafieldBinds(root, add);
|
|
335
|
+
checkCartAndScopes(root, add);
|
|
336
|
+
return problems;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// src/diagnose.js
|
|
340
|
+
var MAX_PRODUCTS_CHECKED = 20;
|
|
341
|
+
var API_UPGRADE_WARNING_MONTHS = 3;
|
|
342
|
+
var TOKEN_EDGE_CHARACTERS = 4;
|
|
343
|
+
function maskToken(token) {
|
|
344
|
+
if (!token) return "(missing)";
|
|
345
|
+
return `${token.slice(0, TOKEN_EDGE_CHARACTERS)}\u2026${token.slice(-TOKEN_EDGE_CHARACTERS)} (${token.length} chars)`;
|
|
346
|
+
}
|
|
347
|
+
function errorText(error, fallback) {
|
|
348
|
+
if (error instanceof Error && error.message) return error.message;
|
|
349
|
+
const code = typeof error === "object" && error !== null ? Reflect.get(error, "code") : void 0;
|
|
350
|
+
return typeof code === "string" && code ? code : fallback;
|
|
351
|
+
}
|
|
352
|
+
function configSummary() {
|
|
353
|
+
return {
|
|
354
|
+
domain: cfg.domain || "(missing)",
|
|
355
|
+
token: maskToken(cfg.token),
|
|
356
|
+
apiVersion: cfg.apiVersion,
|
|
357
|
+
endpoint: cfg.domain ? endpoint() : null,
|
|
358
|
+
country: cfg.country,
|
|
359
|
+
language: cfg.language,
|
|
360
|
+
locale: cfg.locale,
|
|
361
|
+
markets: cfg.markets,
|
|
362
|
+
prefix: cfg.prefix,
|
|
363
|
+
productPath: cfg.productPath,
|
|
364
|
+
metafields: cfg.metafields,
|
|
365
|
+
autoMount: cfg.autoMount,
|
|
366
|
+
observe: cfg.observe,
|
|
367
|
+
onError: typeof cfg.onError === "function"
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
async function marketSummary() {
|
|
371
|
+
return {
|
|
372
|
+
country: cfg.country || null,
|
|
373
|
+
language: cfg.language || null,
|
|
374
|
+
locale: cfg.locale || null,
|
|
375
|
+
detected: cfg.markets?.detect ? (await loadPart("markets")).detectMarket(cfg.markets) : null
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
function apiVersionProblem({ ok, monthsLeft, note }) {
|
|
379
|
+
if (ok && (monthsLeft === void 0 || monthsLeft >= API_UPGRADE_WARNING_MONTHS)) return null;
|
|
380
|
+
return { level: ok ? "warn" : "error", message: `apiVersion ${cfg.apiVersion}: ${note}` };
|
|
381
|
+
}
|
|
382
|
+
async function checkStorefront() {
|
|
383
|
+
if (!isConfigured()) return { kind: "not-configured" };
|
|
384
|
+
const startedAt = Date.now();
|
|
385
|
+
try {
|
|
386
|
+
const data = await gql(
|
|
387
|
+
"query TetherDiagnose { shop { name primaryDomain { url } paymentSettings { currencyCode } } }",
|
|
388
|
+
{},
|
|
389
|
+
{ context: false }
|
|
390
|
+
);
|
|
391
|
+
const shop = {
|
|
392
|
+
name: data.shop.name,
|
|
393
|
+
url: data.shop.primaryDomain.url,
|
|
394
|
+
currency: data.shop.paymentSettings.currencyCode
|
|
395
|
+
};
|
|
396
|
+
return { kind: "reachable", shop, latencyMs: Date.now() - startedAt };
|
|
397
|
+
} catch (error) {
|
|
398
|
+
return { kind: "unreachable", error, latencyMs: Date.now() - startedAt };
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
function checkOptions(root, key, product) {
|
|
402
|
+
const problems = [];
|
|
403
|
+
const names = product.options.map((option) => option.name);
|
|
404
|
+
const roots = qsa(root, sel("product")).filter(
|
|
405
|
+
(el) => resolveProductKey(el).key === key && el.querySelector(sel("add-to-cart"))
|
|
406
|
+
);
|
|
407
|
+
for (const el of roots) {
|
|
408
|
+
const shown = new Set(
|
|
409
|
+
qsa(el, `${sel("option-list")},select${sel("option")}`).map(
|
|
410
|
+
(list) => get(list, "option-list") || get(list, "option")
|
|
411
|
+
)
|
|
412
|
+
);
|
|
413
|
+
if (!shown.size && qsa(el, `select${sel("variant-select")}`).length) continue;
|
|
414
|
+
if (!cfg.language) {
|
|
415
|
+
for (const name of shown) {
|
|
416
|
+
if (!name || names.includes(name)) continue;
|
|
417
|
+
problems.push({
|
|
418
|
+
level: "warn",
|
|
419
|
+
message: `Product "${product.handle}" has no option "${name}" (its options: ${names.join(", ") || "none"}).${didYouMean(name, names)}`
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
for (const option of product.options) {
|
|
424
|
+
if (option.optionValues.length <= 1 || shown.has(option.name)) continue;
|
|
425
|
+
problems.push({
|
|
426
|
+
level: "warn",
|
|
427
|
+
message: `Product "${product.handle}": option "${option.name}" (${option.optionValues.length} values) has no tether-option-list, so visitors can't choose it.`
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}
|
|
341
431
|
return problems;
|
|
342
432
|
}
|
|
433
|
+
async function checkProducts(root, report) {
|
|
434
|
+
const allKeys = qsa(root, sel("product")).map((el) => resolveProductKey(el).key);
|
|
435
|
+
const keys = [...new Set(allKeys.filter((key) => key !== null && key !== ""))].slice(0, MAX_PRODUCTS_CHECKED);
|
|
436
|
+
const results = await Promise.allSettled(keys.map((key) => getProduct(key)));
|
|
437
|
+
results.forEach((result, index) => {
|
|
438
|
+
const key = keys[index] ?? "";
|
|
439
|
+
if (result.status === "rejected") {
|
|
440
|
+
const reason = errorText(result.reason, "not loaded");
|
|
441
|
+
report.products.push({ key, error: result.reason instanceof Error ? result.reason.message : void 0 });
|
|
442
|
+
report.problems.push({
|
|
443
|
+
level: "error",
|
|
444
|
+
message: `Product "${key}": ${reason}. Is it published to the Headless channel?`
|
|
445
|
+
});
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
const product = result.value;
|
|
449
|
+
const plans = allPlans(product);
|
|
450
|
+
report.products.push({
|
|
451
|
+
key,
|
|
452
|
+
handle: product.handle,
|
|
453
|
+
title: product.title,
|
|
454
|
+
plans: plans.length,
|
|
455
|
+
requiresSellingPlan: product.requiresSellingPlan
|
|
456
|
+
});
|
|
457
|
+
for (const plan of plans) {
|
|
458
|
+
report.sellingPlans.push({ product: product.handle, group: plan.group.name, plan: plan.name, id: plan.id });
|
|
459
|
+
}
|
|
460
|
+
report.problems.push(...checkOptions(root, key, product));
|
|
461
|
+
});
|
|
462
|
+
}
|
|
343
463
|
async function diagnose({ root = document, silent = false, version, now = /* @__PURE__ */ new Date() } = {}) {
|
|
464
|
+
const storefront = await checkStorefront();
|
|
344
465
|
const report = {
|
|
345
466
|
version,
|
|
346
|
-
config:
|
|
347
|
-
domain: cfg.domain || "(missing)",
|
|
348
|
-
token: mask(cfg.token),
|
|
349
|
-
apiVersion: cfg.apiVersion,
|
|
350
|
-
endpoint: cfg.domain ? endpoint() : null,
|
|
351
|
-
country: cfg.country,
|
|
352
|
-
language: cfg.language,
|
|
353
|
-
locale: cfg.locale,
|
|
354
|
-
markets: cfg.markets || null,
|
|
355
|
-
prefix: cfg.prefix,
|
|
356
|
-
productPath: cfg.productPath,
|
|
357
|
-
metafields: cfg.metafields,
|
|
358
|
-
autoMount: cfg.autoMount,
|
|
359
|
-
observe: cfg.observe,
|
|
360
|
-
onError: typeof cfg.onError === "function"
|
|
361
|
-
},
|
|
467
|
+
config: configSummary(),
|
|
362
468
|
apiVersion: apiVersionStatus(cfg.apiVersion, now),
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
reachable:
|
|
366
|
-
|
|
367
|
-
latencyMs: null,
|
|
469
|
+
market: await marketSummary(),
|
|
470
|
+
reachable: storefront.kind === "reachable",
|
|
471
|
+
shop: storefront.kind === "reachable" ? storefront.shop : null,
|
|
472
|
+
latencyMs: storefront.kind === "not-configured" ? null : storefront.latencyMs,
|
|
368
473
|
products: [],
|
|
369
474
|
sellingPlans: [],
|
|
370
475
|
problems: []
|
|
371
476
|
};
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
} catch (err) {
|
|
381
|
-
report.problems.push({ level: "error", message: `Storefront API not reachable: ${err.message || err.code || "unknown error"}` });
|
|
382
|
-
}
|
|
383
|
-
report.latencyMs = Date.now() - t0;
|
|
384
|
-
if (report.reachable) {
|
|
385
|
-
const keys = [...new Set(qsa(root, sel("product")).map((el) => resolveProductKey(el).key).filter(Boolean))].slice(0, 20);
|
|
386
|
-
const results = await Promise.allSettled(keys.map((k) => getProduct(k)));
|
|
387
|
-
results.forEach((r, i) => {
|
|
388
|
-
if (r.status === "fulfilled") {
|
|
389
|
-
const p = r.value;
|
|
390
|
-
const plans = allPlans(p);
|
|
391
|
-
report.products.push({ key: keys[i], handle: p.handle, title: p.title, plans: plans.length, requiresSellingPlan: p.requiresSellingPlan });
|
|
392
|
-
plans.forEach((pl) => report.sellingPlans.push({ product: p.handle, group: pl.group?.name, plan: pl.name, id: pl.id }));
|
|
393
|
-
qsa(root, sel("product")).filter((el) => resolveProductKey(el).key === keys[i] && el.querySelector(sel("add-to-cart"))).forEach((el) => {
|
|
394
|
-
const shown = new Set(qsa(el, `${sel("option-list")},select${sel("option")}`).map((x) => get(x, "option-list") || get(x, "option")));
|
|
395
|
-
if (!shown.size && qsa(el, `select${sel("variant-select")}`).length) return;
|
|
396
|
-
const names = (p.options || []).map((o) => o.name);
|
|
397
|
-
if (!cfg.language) {
|
|
398
|
-
[...shown].filter((n) => n && !names.includes(n)).forEach((n) => {
|
|
399
|
-
report.problems.push({ level: "warn", message: `Product "${p.handle}" has no option "${n}" (its options: ${names.join(", ") || "none"}).${didYouMean(n, names)}` });
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
(p.options || []).filter((o) => o.optionValues.length > 1 && !shown.has(o.name)).forEach((o) => {
|
|
403
|
-
report.problems.push({ level: "warn", message: `Product "${p.handle}": option "${o.name}" (${o.optionValues.length} values) has no tether-option-list, so visitors can't choose it.` });
|
|
404
|
-
});
|
|
405
|
-
});
|
|
406
|
-
} else {
|
|
407
|
-
report.products.push({ key: keys[i], error: r.reason?.message });
|
|
408
|
-
report.problems.push({ level: "error", message: `Product "${keys[i]}": ${r.reason?.message || r.reason?.code || "not loaded"}. Is it published to the Headless channel?` });
|
|
409
|
-
}
|
|
477
|
+
switch (storefront.kind) {
|
|
478
|
+
case "not-configured":
|
|
479
|
+
report.problems.push({ level: "error", message: "TETHER_CONFIG needs domain and token." });
|
|
480
|
+
break;
|
|
481
|
+
case "unreachable":
|
|
482
|
+
report.problems.push({
|
|
483
|
+
level: "error",
|
|
484
|
+
message: `Storefront API not reachable: ${errorText(storefront.error, "unknown error")}`
|
|
410
485
|
});
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
486
|
+
break;
|
|
487
|
+
case "reachable":
|
|
488
|
+
await checkProducts(root, report);
|
|
489
|
+
break;
|
|
415
490
|
}
|
|
491
|
+
const versionProblem = apiVersionProblem(report.apiVersion);
|
|
492
|
+
if (versionProblem) report.problems.push(versionProblem);
|
|
416
493
|
if (typeof document !== "undefined") report.problems.push(...checkMarkup(root));
|
|
417
494
|
if (!silent) print(report);
|
|
418
495
|
return report;
|
|
419
496
|
}
|
|
420
|
-
function print(
|
|
421
|
-
const
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
497
|
+
function print(report) {
|
|
498
|
+
const errors = report.problems.filter((problem) => problem.level === "error").length;
|
|
499
|
+
const warnings = report.problems.length - errors;
|
|
500
|
+
console.group(`[${cfg.prefix}] diagnose: ${errors ? `${errors} error(s)` : "no errors"}, ${warnings} warning(s)`);
|
|
501
|
+
console.log("version", report.version, "| API", report.apiVersion.version, `(${report.apiVersion.note})`);
|
|
502
|
+
console.log("config", report.config);
|
|
503
|
+
const { country, language, detected } = report.market;
|
|
504
|
+
const inUse = [country, language].filter(Boolean).join(" / ") || "the store default";
|
|
505
|
+
console.log("market", `in use: ${inUse}`, detected ? `(detection picks ${JSON.stringify(detected)})` : "");
|
|
506
|
+
console.log(
|
|
507
|
+
report.shop ? `Storefront API reachable: ${report.shop.name} (${report.latencyMs ?? 0} ms)` : "Storefront API NOT reachable"
|
|
508
|
+
);
|
|
509
|
+
if (report.products.length) console.table(report.products);
|
|
510
|
+
if (report.sellingPlans.length) console.table(report.sellingPlans);
|
|
511
|
+
else if (report.reachable) console.log("No selling plans on the products of this page.");
|
|
512
|
+
for (const problem of report.problems) {
|
|
513
|
+
if (problem.level === "error") console.error(problem.message, problem.el ?? "");
|
|
514
|
+
else console.warn(problem.message, problem.el ?? "");
|
|
515
|
+
}
|
|
516
|
+
console.groupEnd();
|
|
433
517
|
}
|
|
434
518
|
|
|
435
519
|
// src/parts/diagnose.js
|
|
436
|
-
|
|
520
|
+
var { Tether } = (
|
|
521
|
+
/** @type {Window & { Tether?: { __parts: Record<string, unknown> } }} */
|
|
522
|
+
window
|
|
523
|
+
);
|
|
524
|
+
if (!Tether) throw new Error("tether.diagnose.js runs after the Tether script, which loads it");
|
|
525
|
+
Tether.__parts["diagnose"] = diagnose_exports;
|
|
437
526
|
})();
|