@usethrottle/builder-react 0.4.3 → 0.5.1

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/server.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
4
 
@@ -12,70 +12,157 @@
12
12
 
13
13
 
14
14
 
15
- var _chunkE7SRVAFVcjs = require('./chunk-E7SRVAFV.cjs');
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+ var _chunkUNL4JWZScjs = require('./chunk-UNL4JWZS.cjs');
16
26
 
17
27
  // src/server/load-site.ts
18
28
  var _builder = require('@usethrottle/builder');
29
+ function siteThemeOf(site) {
30
+ const theme = site.theme;
31
+ return typeof _optionalChain([theme, 'optionalAccess', _2 => _2.customCssHref]) === "string" ? { theme: { customCssHref: theme.customCssHref } } : {};
32
+ }
19
33
  async function loadSite(options) {
20
34
  const { locale, slots = [], packs = [], page, mediaOrigin = "", currency } = options;
21
- const client = _chunkE7SRVAFVcjs.clientOf.call(void 0, options);
35
+ const client = _chunkUNL4JWZScjs.clientOf.call(void 0, options);
22
36
  let bundle;
23
37
  try {
24
- bundle = await _chunkE7SRVAFVcjs.getBundle.call(void 0, { client, locale, slots, page });
38
+ bundle = await _chunkUNL4JWZScjs.getBundle.call(void 0, { client, locale, slots, page });
25
39
  } catch (error) {
26
40
  if (!(error instanceof _builder.BuilderUnavailableError) || client.mode === "build") throw error;
27
- _chunkE7SRVAFVcjs.warnOnce.call(void 0, "site-unavailable", `The Builder could not be read (${error.reason}); the store renders without its Builder header, footer and slots`);
41
+ _chunkUNL4JWZScjs.warnOnce.call(void 0, "site-unavailable", `The Builder could not be read (${error.reason}); the store renders without its Builder header, footer and slots`);
28
42
  return { status: "unavailable", locale };
29
43
  }
30
- const registry = _chunkE7SRVAFVcjs.createRendererRegistry.call(void 0, packs);
44
+ const registry = _chunkUNL4JWZScjs.createRendererRegistry.call(void 0, packs);
31
45
  const names = Object.keys(bundle.slots);
32
46
  const withShared = (loaded) => ({
33
47
  ...loaded,
34
48
  ...(_nullishCoalesce(loaded.savedSections, () => ( bundle.savedSections))) === void 0 ? {} : { savedSections: _nullishCoalesce(loaded.savedSections, () => ( bundle.savedSections)) }
35
49
  });
36
50
  const documents = [bundle.header, bundle.footer, ...names.map((n) => bundle.slots[n])].map(withShared);
37
- const data = await _chunkE7SRVAFVcjs.staticDataFor.call(void 0, documents, registry, locale, currency);
51
+ const data = await _chunkUNL4JWZScjs.staticDataFor.call(void 0, documents, registry, locale, currency);
38
52
  return {
39
53
  status: "ok",
40
54
  locale,
41
55
  generation: bundle.generation,
42
56
  siteVersion: bundle.site.siteVersion,
57
+ loadedAt: (/* @__PURE__ */ new Date()).toISOString(),
43
58
  mediaOrigin,
44
59
  settings: bundle.site.settings,
45
- header: _chunkE7SRVAFVcjs.partOf.call(void 0, bundle.header, data, bundle),
46
- footer: _chunkE7SRVAFVcjs.partOf.call(void 0, bundle.footer, data, bundle),
47
- slots: Object.fromEntries(names.map((name) => [name, _chunkE7SRVAFVcjs.partOf.call(void 0, bundle.slots[name], data, bundle)]))
60
+ ...siteThemeOf(bundle.site),
61
+ header: _chunkUNL4JWZScjs.partOf.call(void 0, bundle.header, data, bundle),
62
+ footer: _chunkUNL4JWZScjs.partOf.call(void 0, bundle.footer, data, bundle),
63
+ slots: Object.fromEntries(names.map((name) => [name, _chunkUNL4JWZScjs.partOf.call(void 0, bundle.slots[name], data, bundle)]))
48
64
  };
49
65
  }
50
66
 
51
67
  // src/server/sitemap.ts
52
68
 
53
- async function builderSitemap(options) {
69
+ var SITEMAP_MAX_URLS = 5e4;
70
+ var isRec = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
71
+ function sitemapRulesOf(settings) {
72
+ const seo = isRec(settings.seo) ? settings.seo : {};
73
+ const rules = isRec(seo.sitemap) ? seo.sitemap : {};
74
+ const on = (key) => rules[key] !== false;
75
+ const toggles = { pages: on("pages"), products: on("products"), collections: on("collections"), categories: on("categories"), tags: on("tags") };
76
+ return { pages: toggles.pages, exclude: Array.isArray(rules.exclude) ? rules.exclude.filter((x) => typeof x === "string") : [], toggles };
77
+ }
78
+ function excluded(rules, pathname, slug) {
79
+ return rules.some((rule) => {
80
+ if (rule.startsWith("/")) return rule.endsWith("*") ? pathname.startsWith(rule.slice(0, -1)) : pathname === rule || pathname === `${rule}/`;
81
+ return slug !== void 0 && rule === slug;
82
+ });
83
+ }
84
+ var xmlEscape = (text) => text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&apos;");
85
+ function safeLoc(loc, origin) {
86
+ try {
87
+ const parsed = new URL(loc);
88
+ return parsed.origin === origin ? xmlEscape(parsed.href) : null;
89
+ } catch (e) {
90
+ return null;
91
+ }
92
+ }
93
+ var pathnameOf = (url) => {
94
+ try {
95
+ return new URL(url).pathname;
96
+ } catch (e2) {
97
+ return url;
98
+ }
99
+ };
100
+ async function builderSitemapParts(options, extras = {}) {
101
+ const origin = _chunkUNL4JWZScjs.originOf.call(void 0, options.storeUrl);
102
+ const entries = await pageEntries(options, origin);
103
+ if (origin === void 0) return { parts: [] };
104
+ const rules = sitemapRulesOf(await settingsOf(options));
105
+ const seen = new Set(entries.map((entry) => entry.url));
106
+ for (const contributor of _nullishCoalesce(extras.contributors, () => ( []))) {
107
+ try {
108
+ for await (const item of contributor({ toggles: rules.toggles })) {
109
+ const loc = typeof item.loc === "string" ? safeLoc(item.loc, origin) : null;
110
+ if (loc === null || seen.has(loc)) continue;
111
+ if (excluded(rules.exclude, pathnameOf(loc))) continue;
112
+ seen.add(loc);
113
+ const when = item.lastmod === void 0 ? void 0 : new Date(item.lastmod);
114
+ entries.push({ url: loc, ...when === void 0 || Number.isNaN(when.getTime()) ? {} : { lastModified: when } });
115
+ }
116
+ } catch (error) {
117
+ _chunkUNL4JWZScjs.warnOnce.call(void 0, "sitemap-contributor", `A sitemap contributor failed (${error instanceof Error ? error.message : "unknown error"}); the sitemap leaves out its URLs`);
118
+ }
119
+ }
120
+ const parts = [];
121
+ for (let from = 0; from < entries.length; from += SITEMAP_MAX_URLS) parts.push(entries.slice(from, from + SITEMAP_MAX_URLS));
122
+ if (parts.length < 2) return { parts };
123
+ const items = parts.map((_, index) => `<sitemap><loc>${xmlEscape(origin)}/sitemap/${String(index)}.xml</loc></sitemap>`).join("");
124
+ return { parts, indexXml: `<?xml version="1.0" encoding="UTF-8"?><sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${items}</sitemapindex>` };
125
+ }
126
+ async function builderSitemap(options, extras = {}) {
127
+ return (await builderSitemapParts(options, extras)).parts.flat();
128
+ }
129
+ async function settingsOf(options) {
130
+ try {
131
+ return (await _chunkUNL4JWZScjs.clientOf.call(void 0, options).site({ locale: _nullishCoalesce(options.locale, () => ( "en")) })).settings;
132
+ } catch (e3) {
133
+ return {};
134
+ }
135
+ }
136
+ async function pageEntries(options, origin) {
54
137
  if (options.client === void 0 && (options.builderKey === void 0 || options.builderKey === "")) {
55
- _chunkE7SRVAFVcjs.warnOnce.call(void 0, "sitemap-no-key", "builderSitemap has no builderKey (is THROTTLE_BUILDER_KEY set?); the sitemap leaves out the Builder pages");
138
+ _chunkUNL4JWZScjs.warnOnce.call(void 0, "sitemap-no-key", "builderSitemap has no builderKey (is THROTTLE_BUILDER_KEY set?); the sitemap leaves out the Builder pages");
56
139
  return [];
57
140
  }
58
- const client = _chunkE7SRVAFVcjs.clientOf.call(void 0, options);
59
- const origin = _chunkE7SRVAFVcjs.originOf.call(void 0, options.storeUrl);
141
+ const client = _chunkUNL4JWZScjs.clientOf.call(void 0, options);
60
142
  if (origin === void 0) {
61
- _chunkE7SRVAFVcjs.warnOnce.call(void 0, "sitemap-origin", "builderSitemap needs a storeUrl (https://shop.example.com) that is an http(s) origin. The Builder does not publish the store URL.");
143
+ _chunkUNL4JWZScjs.warnOnce.call(void 0, "sitemap-origin", "builderSitemap needs a storeUrl (https://shop.example.com) that is an http(s) origin. The Builder does not publish the store URL.");
62
144
  return [];
63
145
  }
64
146
  const locale = _nullishCoalesce(options.locale, () => ( "en"));
65
147
  try {
66
148
  const pages = await client.pages.list();
67
149
  const { settings } = await client.site({ locale });
150
+ const rules = sitemapRulesOf(settings);
151
+ if (!rules.pages) return [];
68
152
  const indexable = await withoutNoindex(client, pages, locale);
69
- const { list } = _chunkE7SRVAFVcjs.siteLocales.call(void 0, settings);
153
+ const { list } = _chunkUNL4JWZScjs.siteLocales.call(void 0, settings);
70
154
  const prefixes = options.localeRoute !== true ? [void 0] : list.length > 0 ? list : [locale];
71
155
  return indexable.flatMap((page) => {
72
- const path = _chunkE7SRVAFVcjs.pagePathOf.call(void 0, settings, page, options.pagePath);
73
- if (path === null) return [];
74
- return prefixes.map((prefix) => ({ url: `${origin}${_chunkE7SRVAFVcjs.localized.call(void 0, path, prefix)}`, lastModified: new Date(page.updatedAt) }));
156
+ const path = _chunkUNL4JWZScjs.pagePathOf.call(void 0, settings, page, options.pagePath);
157
+ if (path === null || excluded(rules.exclude, path, page.slug)) return [];
158
+ return prefixes.flatMap((prefix) => {
159
+ const url = safeLoc(`${origin}${_chunkUNL4JWZScjs.localized.call(void 0, path, prefix)}`, origin);
160
+ return url === null ? [] : [{ url, lastModified: new Date(page.updatedAt) }];
161
+ });
75
162
  });
76
163
  } catch (error) {
77
164
  if (!(error instanceof _builder.BuilderUnavailableError) || client.mode === "build") throw error;
78
- _chunkE7SRVAFVcjs.warnOnce.call(void 0, "sitemap-unavailable", `The Builder could not be read (${error.reason}); the sitemap leaves out its pages`);
165
+ _chunkUNL4JWZScjs.warnOnce.call(void 0, "sitemap-unavailable", `The Builder could not be read (${error.reason}); the sitemap leaves out its pages`);
79
166
  return [];
80
167
  }
81
168
  }
@@ -89,22 +176,88 @@ async function withoutNoindex(client, pages, locale) {
89
176
  slice.map(
90
177
  (page) => client.pages.get(page.slug, { locale }).catch((error) => {
91
178
  if (error instanceof _builder.BuilderNotFoundError) return "gone";
92
- _chunkE7SRVAFVcjs.warnOnce.call(void 0, "sitemap-page-read", `A page could not be read for the sitemap (${error instanceof Error ? error.message : "unknown error"}); it stays listed`);
179
+ _chunkUNL4JWZScjs.warnOnce.call(void 0, "sitemap-page-read", `A page could not be read for the sitemap (${error instanceof Error ? error.message : "unknown error"}); it stays listed`);
93
180
  return void 0;
94
181
  })
95
182
  )
96
183
  );
97
184
  slice.forEach((page, index) => {
98
185
  const answer = answers[index];
99
- if (answer === "gone" || answer !== void 0 && (_chunkE7SRVAFVcjs.isRedirect.call(void 0, answer) || _chunkE7SRVAFVcjs.pageSeoOf.call(void 0, answer).noindex)) skip.add(page.slug);
186
+ if (answer === "gone" || answer !== void 0 && (_chunkUNL4JWZScjs.isRedirect.call(void 0, answer) || _chunkUNL4JWZScjs.pageSeoOf.call(void 0, answer).noindex)) skip.add(page.slug);
100
187
  });
101
188
  }
102
189
  return pages.filter((page) => !skip.has(page.slug));
103
190
  }
104
191
 
192
+ // src/server/robots.ts
193
+ var isRec2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
194
+ var DEFAULT_ROBOTS_DISALLOW = [
195
+ "/cart",
196
+ "/account",
197
+ "/sign-in",
198
+ "/sign-up",
199
+ "/order/",
200
+ "/search"
201
+ ];
202
+ var MAX_EXTRA_LINES = 50;
203
+ var MAX_LINE = 200;
204
+ var CONTROL = new RegExp(`[\\x00-\\x1F\\x7F\\x85${String.fromCharCode(8232, 8233)}]`, "u");
205
+ var DIRECTIVE = /^(?:(?:User-agent|Allow|Disallow|Crawl-delay|Sitemap)\s*:|#)/iu;
206
+ var BLOCKS_ALL = /^Disallow\s*:\s*\/\*?\s*(?:#.*)?$/iu;
207
+ var USER_AGENT = /^User-agent\s*:\s*([^#]*?)\s*(?:#.*)?$/iu;
208
+ var validLine = (value) => typeof value === "string" && value.trim() !== "" && value.length <= MAX_LINE && !CONTROL.test(value);
209
+ function validExtras(values) {
210
+ const kept = [];
211
+ let agents = ["*"];
212
+ let started = false;
213
+ let inRules = false;
214
+ for (const value of values) {
215
+ if (!validLine(value)) continue;
216
+ const line = value.trim();
217
+ if (!DIRECTIVE.test(line)) continue;
218
+ const agent = USER_AGENT.exec(line);
219
+ if (agent !== null) {
220
+ agents = !started || inRules ? [_nullishCoalesce(agent[1], () => ( ""))] : [...agents, _nullishCoalesce(agent[1], () => ( ""))];
221
+ started = true;
222
+ inRules = false;
223
+ } else if (/^(?:Allow|Disallow|Crawl-delay)\s*:/iu.test(line)) {
224
+ if (BLOCKS_ALL.test(line) && agents.includes("*")) continue;
225
+ inRules = true;
226
+ }
227
+ kept.push(line);
228
+ }
229
+ return kept;
230
+ }
231
+ var validDisallow = (value) => validLine(value) && value.trim() !== "/";
232
+ function siteOriginOf(site, options = {}) {
233
+ const settings = _nullishCoalesce(site.settings, () => ( {}));
234
+ const seo = isRec2(settings.seo) ? settings.seo : {};
235
+ return _nullishCoalesce(_nullishCoalesce(_chunkUNL4JWZScjs.originOf.call(void 0, typeof seo.canonicalBase === "string" ? seo.canonicalBase : void 0), () => ( _chunkUNL4JWZScjs.originOf.call(void 0, options.storeUrl))), () => ( _chunkUNL4JWZScjs.originOf.call(void 0, typeof settings.storeUrl === "string" ? settings.storeUrl : void 0)));
236
+ }
237
+ function builderRobots(site, options = {}) {
238
+ const settings = _nullishCoalesce(site.settings, () => ( {}));
239
+ const seo = isRec2(settings.seo) ? settings.seo : {};
240
+ const robots = isRec2(seo.robots) ? seo.robots : {};
241
+ const disallow = Array.isArray(robots.disallow) ? robots.disallow.filter(validDisallow) : [...DEFAULT_ROBOTS_DISALLOW];
242
+ const extra = Array.isArray(robots.extra) ? validExtras(robots.extra).slice(0, MAX_EXTRA_LINES) : [];
243
+ const origin = siteOriginOf(site, options);
244
+ return [
245
+ "User-agent: *",
246
+ ...disallow.map((path) => `Disallow: ${path}`),
247
+ ...origin === void 0 ? [] : [`Sitemap: ${origin}/sitemap.xml`],
248
+ ...extra,
249
+ ""
250
+ ].join("\n");
251
+ }
252
+ function builderRobotsResponse(site, options = {}) {
253
+ return new Response(builderRobots(site, options), {
254
+ headers: { "content-type": "text/plain; charset=utf-8" }
255
+ });
256
+ }
257
+
105
258
  // src/server/static-params.ts
106
259
  async function builderStaticParams(options) {
107
- const client = _chunkE7SRVAFVcjs.clientOf.call(void 0, options);
260
+ const client = _chunkUNL4JWZScjs.clientOf.call(void 0, options);
108
261
  if (client.mode !== "build")
109
262
  throw new TypeError(
110
263
  'builderStaticParams generates every page of a frozen release: give it a client made with createBuilderClient({ mode: "build" }). A live store keeps its pages dynamic.'
@@ -123,4 +276,20 @@ async function builderStaticParams(options) {
123
276
 
124
277
 
125
278
 
126
- exports.BuilderNotFoundError = _builder.BuilderNotFoundError; exports.BuilderUnavailableError = _builder.BuilderUnavailableError; exports.builderSitemap = builderSitemap; exports.builderStaticParams = builderStaticParams; exports.getBundle = _chunkE7SRVAFVcjs.getBundle; exports.loadBuilderPage = _chunkE7SRVAFVcjs.loadBuilderPage; exports.loadSite = loadSite;
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+ exports.BuilderNotFoundError = _builder.BuilderNotFoundError; exports.BuilderUnavailableError = _builder.BuilderUnavailableError; exports.DEFAULT_ROBOTS_DISALLOW = DEFAULT_ROBOTS_DISALLOW; exports.SITEMAP_MAX_URLS = SITEMAP_MAX_URLS; exports.breadcrumbJsonLd = _chunkUNL4JWZScjs.breadcrumbJsonLd; exports.builderRobots = builderRobots; exports.builderRobotsResponse = builderRobotsResponse; exports.builderSitemap = builderSitemap; exports.builderSitemapParts = builderSitemapParts; exports.builderStaticParams = builderStaticParams; exports.faqJsonLd = _chunkUNL4JWZScjs.faqJsonLd; exports.getBundle = _chunkUNL4JWZScjs.getBundle; exports.isOwnPath = _chunkUNL4JWZScjs.isOwnPath; exports.jsonLdString = _chunkUNL4JWZScjs.jsonLdString; exports.loadBuilderPage = _chunkUNL4JWZScjs.loadBuilderPage; exports.loadBuilderPageByPath = _chunkUNL4JWZScjs.loadBuilderPageByPath; exports.loadBuilderTemplate = _chunkUNL4JWZScjs.loadBuilderTemplate; exports.loadOwnPagePaths = _chunkUNL4JWZScjs.loadOwnPagePaths; exports.loadSite = loadSite; exports.localBusinessJsonLd = _chunkUNL4JWZScjs.localBusinessJsonLd; exports.organizationJsonLd = _chunkUNL4JWZScjs.organizationJsonLd; exports.siteOriginOf = siteOriginOf; exports.webSiteJsonLd = _chunkUNL4JWZScjs.webSiteJsonLd;
package/dist/server.d.cts CHANGED
@@ -1,8 +1,9 @@
1
- import { C as ClientOptions, W as WidgetPack, b as LoadedSite, L as LoadedPage, a as LoadedRedirect, P as PagePathResolver } from './seo-BYBk3Sya.cjs';
2
- export { B as BundleAsk, g as getBundle } from './seo-BYBk3Sya.cjs';
1
+ import { b as ClientOptions, W as WidgetPack, e as LoadedSite, L as LoadedPage, d as LoadedRedirect, c as LoadedPart, P as PagePathResolver } from './seo-iX2POfOp.cjs';
2
+ export { a as BundleAsk, g as getBundle } from './seo-iX2POfOp.cjs';
3
+ import { TemplateAnswer } from '@usethrottle/builder';
3
4
  export { BuilderNotFoundError, BuilderUnavailableError } from '@usethrottle/builder';
5
+ import { TemplateName } from '@usethrottle/builder-schema';
4
6
  import 'react';
5
- import '@usethrottle/builder-schema';
6
7
 
7
8
  type LoadSiteOptions = ClientOptions & {
8
9
  locale: string;
@@ -43,6 +44,19 @@ type LoadBuilderPageOptions = ClientOptions & {
43
44
  /** The shopper's currency, as for `loadSite({ currency })`. */
44
45
  currency?: string;
45
46
  };
47
+ /** A page's own path (`/about`, D39): not the legacy `/` and `/pages/...` answers the page route covers. */
48
+ declare const isOwnPath: (path: unknown) => path is string;
49
+ /**
50
+ * Reads the page that answers at its own path, or the redirect of an older path of a page (`slug_redirects`).
51
+ * Uses the client's `pages.getByPath` when it has one; otherwise the page list (its summaries carry `path`), which
52
+ * also answers a 308 for a listed slug whose own path has moved. An older path that is no longer any page's slug
53
+ * is only found by `getByPath` (no Worker call is made per unknown path). Rejects with `BuilderNotFoundError` when nothing is at the path.
54
+ */
55
+ declare function loadBuilderPageByPath(options: Omit<LoadBuilderPageOptions, 'slug'> & {
56
+ path: string;
57
+ }): Promise<LoadedPage | LoadedRedirect>;
58
+ /** The own paths (`/about`) of the published pages, for `BuilderProvider`'s `ownPagePaths`. */
59
+ declare function loadOwnPagePaths(options: ClientOptions): Promise<string[]>;
46
60
  /**
47
61
  * Reads one published page for a request. Data of the page's non-perShopper
48
62
  * sources is resolved here, each distinct binding once, into `initialData`;
@@ -54,6 +68,25 @@ type LoadBuilderPageOptions = ClientOptions & {
54
68
  */
55
69
  declare function loadBuilderPage(options: LoadBuilderPageOptions): Promise<LoadedPage | LoadedRedirect>;
56
70
 
71
+ type LoadBuilderTemplateOptions = ClientOptions & {
72
+ name: TemplateName;
73
+ locale: string;
74
+ packs?: readonly WidgetPack[];
75
+ /** The shopper's currency, as for `loadBuilderPage`. */
76
+ currency?: string | undefined;
77
+ /** What the bundle answer holds once for every document (saved sections, code runtime). */
78
+ shared?: Pick<TemplateAnswer, 'savedSections' | 'code'>;
79
+ };
80
+ /**
81
+ * Reads one published template (`client.getTemplate`) for a request, with the data of its non-perShopper sources
82
+ * resolved once. `context.*` bindings are the loader's and are not resolved here. An unpublished template is an empty
83
+ * document, never an error; `BuilderUnavailableError` is the client's own answer when it has no last good one.
84
+ */
85
+ declare function loadBuilderTemplate(options: LoadBuilderTemplateOptions): Promise<{
86
+ part: LoadedPart;
87
+ meta: TemplateAnswer['meta'];
88
+ }>;
89
+
57
90
  type BuilderSitemapOptions = ClientOptions & {
58
91
  /** The store's origin (`https://shop.example.com`). The Builder does not publish it, so it is required: without a valid one the sitemap is empty. */
59
92
  storeUrl?: string;
@@ -67,11 +100,157 @@ type BuilderSitemapOptions = ClientOptions & {
67
100
  /** Where your store serves a page, as for `createBuilderPage`. Pass the same function. */
68
101
  pagePath?: PagePathResolver;
69
102
  };
70
- /** The published pages as sitemap entries. An unavailable Builder, or no key at all, gives an empty list and a warning, never a failed sitemap (a build-mode client fails the build instead). */
71
- declare function builderSitemap(options: BuilderSitemapOptions): Promise<{
103
+ /** URLs per sitemap file (the sitemaps.org limit). */
104
+ declare const SITEMAP_MAX_URLS = 50000;
105
+ /** The site's `seo.sitemap` toggles, resolved: each kind is `true` unless the site set it to `false`. */
106
+ type SitemapToggles = {
107
+ pages: boolean;
108
+ products: boolean;
109
+ collections: boolean;
110
+ categories: boolean;
111
+ tags: boolean;
112
+ };
113
+ /** What a contributor is called with: the site's resolved toggles, so it can skip a kind that is switched off. */
114
+ type SitemapContributorContext = {
115
+ toggles: SitemapToggles;
116
+ };
117
+ /**
118
+ * A source of extra URLs (the catalog pack's products, collections, ...). `loc` is an absolute URL on the store's origin.
119
+ * It is called with `{ toggles }`; a contributor that takes no argument still works.
120
+ */
121
+ type SitemapContributor = (context: SitemapContributorContext) => AsyncIterable<{
122
+ loc: string;
123
+ lastmod?: Date | string | undefined;
124
+ }>;
125
+ type BuilderSitemapExtras = {
126
+ contributors?: readonly SitemapContributor[] | undefined;
127
+ };
128
+ type SitemapEntry = {
72
129
  url: string;
73
- lastModified: Date;
74
- }[]>;
130
+ lastModified?: Date;
131
+ };
132
+ /**
133
+ * The sitemap in files of at most 50,000 URLs, with the XML of the sitemap index when there is more than one
134
+ * (`<origin>/sitemap/<n>.xml`, Next's `generateSitemaps` numbering). Pages first, then each contributor; a URL is
135
+ * listed once; a contributor that throws, or answers another origin, loses only that URL or source.
136
+ */
137
+ declare function builderSitemapParts(options: BuilderSitemapOptions, extras?: BuilderSitemapExtras): Promise<{
138
+ parts: SitemapEntry[][];
139
+ indexXml?: string;
140
+ }>;
141
+ /**
142
+ * The published pages (and the contributors' URLs) as sitemap entries. An unavailable Builder, or no key at all, gives an
143
+ * empty list and a warning, never a failed sitemap (a build-mode client fails the build instead). Beyond 50,000 URLs use
144
+ * `builderSitemapParts`.
145
+ */
146
+ declare function builderSitemap(options: BuilderSitemapOptions, extras?: BuilderSitemapExtras): Promise<SitemapEntry[]>;
147
+
148
+ type Rec = Record<string, unknown>;
149
+ /** The default disallow list (spec §11.4). */
150
+ declare const DEFAULT_ROBOTS_DISALLOW: readonly ["/cart", "/account", "/sign-in", "/sign-up", "/order/", "/search"];
151
+ /** The site as the SEO helpers read it: the published settings (v1 or v2; the v2 `seo` fields are all optional). */
152
+ type SeoSite = {
153
+ settings?: Rec | undefined;
154
+ };
155
+ type SeoSiteOptions = {
156
+ /** The store's origin, the base of the `Sitemap:` line when the settings carry no `seo.canonicalBase`. */
157
+ storeUrl?: string | undefined;
158
+ };
159
+ /** The site origin for absolute URLs: `seo.canonicalBase`, else `storeUrl` (an option, then `settings.storeUrl`). */
160
+ declare function siteOriginOf(site: SeoSite, options?: SeoSiteOptions): string | undefined;
161
+ /**
162
+ * The text of `robots.txt`: `User-agent: *`, the disallow list (the site's, else the default), a `Sitemap:` line, then up
163
+ * to 50 extra lines the merchant wrote. An extra line is kept only when it is one plain line that starts with a robots
164
+ * directive (`User-agent`, `Allow`, `Disallow`, `Crawl-delay`, `Sitemap`) or `#`, and is not a bare `Disallow: /`.
165
+ *
166
+ * Next's `app/robots.ts` must return a `MetadataRoute.Robots` object, not text, so do NOT use this there: serve it from
167
+ * `app/robots.txt/route.ts` with `builderRobotsResponse` (or `new Response(builderRobots(...))`).
168
+ */
169
+ declare function builderRobots(site: SeoSite, options?: SeoSiteOptions): string;
170
+ /** `builderRobots` as a `text/plain` response, for an `app/robots.txt/route.ts` handler (`export const GET = ...`). */
171
+ declare function builderRobotsResponse(site: SeoSite, options?: SeoSiteOptions): Response;
172
+
173
+ /** JSON-LD builders (spec §11.4). Each answers a plain object with the schema.org required properties. */
174
+ type JsonLd = Record<string, unknown>;
175
+ declare function organizationJsonLd(input: {
176
+ name: string;
177
+ url: string;
178
+ logo?: string | undefined;
179
+ sameAs?: readonly string[] | undefined;
180
+ }): {
181
+ sameAs?: string[] | undefined;
182
+ logo?: string | undefined;
183
+ '@context': "https://schema.org";
184
+ '@type': "Organization";
185
+ name: string;
186
+ url: string;
187
+ };
188
+ /** `WebSite` with a `SearchAction` that targets the store's search route (`/search?q=` by default). */
189
+ declare function webSiteJsonLd(input: {
190
+ name: string;
191
+ url: string;
192
+ searchPath?: string | undefined;
193
+ }): {
194
+ '@context': "https://schema.org";
195
+ '@type': "WebSite";
196
+ name: string;
197
+ url: string;
198
+ potentialAction: {
199
+ '@type': "SearchAction";
200
+ target: {
201
+ '@type': "EntryPoint";
202
+ urlTemplate: string;
203
+ };
204
+ 'query-input': string;
205
+ };
206
+ };
207
+ declare function breadcrumbJsonLd(items: readonly {
208
+ name: string;
209
+ url: string;
210
+ }[]): {
211
+ '@context': "https://schema.org";
212
+ '@type': "BreadcrumbList";
213
+ itemListElement: {
214
+ '@type': "ListItem";
215
+ position: number;
216
+ name: string;
217
+ item: string;
218
+ }[];
219
+ };
220
+ declare function faqJsonLd(items: readonly {
221
+ question: string;
222
+ answer: string;
223
+ }[]): {
224
+ '@context': "https://schema.org";
225
+ '@type': "FAQPage";
226
+ mainEntity: {
227
+ '@type': "Question";
228
+ name: string;
229
+ acceptedAnswer: {
230
+ '@type': "Answer";
231
+ text: string;
232
+ };
233
+ }[];
234
+ };
235
+ /** `LocalBusiness` (or `Store`): name and address are the required properties. */
236
+ declare function localBusinessJsonLd(input: {
237
+ name: string;
238
+ url: string;
239
+ address: string;
240
+ phone?: string | undefined;
241
+ openingHours?: readonly string[] | undefined;
242
+ type?: 'LocalBusiness' | 'Store' | undefined;
243
+ }): {
244
+ openingHours?: string[] | undefined;
245
+ telephone?: string | undefined;
246
+ '@context': "https://schema.org";
247
+ '@type': "LocalBusiness" | "Store";
248
+ name: string;
249
+ url: string;
250
+ address: string;
251
+ };
252
+ /** The text for `<script type="application/ld+json">`: `<` is escaped so a value cannot close the element. */
253
+ declare function jsonLdString(value: unknown): string;
75
254
 
76
255
  type BuilderStaticParamsOptions = ClientOptions & {
77
256
  /** The dynamic segment of the route, as in `createBuilderPage({ fromParams })`. Default `handle`. */
@@ -92,4 +271,4 @@ type BuilderStaticParamsOptions = ClientOptions & {
92
271
  */
93
272
  declare function builderStaticParams(options: BuilderStaticParamsOptions): Promise<Record<string, string>[]>;
94
273
 
95
- export { type BuilderSitemapOptions, type BuilderStaticParamsOptions, type LoadBuilderPageOptions, type LoadSiteOptions, LoadedPage, LoadedRedirect, LoadedSite, builderSitemap, builderStaticParams, loadBuilderPage, loadSite };
274
+ export { type BuilderSitemapExtras, type BuilderSitemapOptions, type BuilderStaticParamsOptions, DEFAULT_ROBOTS_DISALLOW, type JsonLd, type LoadBuilderPageOptions, type LoadBuilderTemplateOptions, type LoadSiteOptions, LoadedPage, LoadedRedirect, LoadedSite, SITEMAP_MAX_URLS, type SeoSite, type SeoSiteOptions, type SitemapContributor, type SitemapContributorContext, type SitemapEntry, type SitemapToggles, breadcrumbJsonLd, builderRobots, builderRobotsResponse, builderSitemap, builderSitemapParts, builderStaticParams, faqJsonLd, isOwnPath, jsonLdString, loadBuilderPage, loadBuilderPageByPath, loadBuilderTemplate, loadOwnPagePaths, loadSite, localBusinessJsonLd, organizationJsonLd, siteOriginOf, webSiteJsonLd };