@usethrottle/builder-react 0.5.1 → 0.5.3

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/next.cjs CHANGED
@@ -12,7 +12,9 @@
12
12
 
13
13
 
14
14
 
15
- var _chunkUNL4JWZScjs = require('./chunk-UNL4JWZS.cjs');
15
+
16
+
17
+ var _chunkJ2IHOBDXcjs = require('./chunk-J2IHOBDX.cjs');
16
18
 
17
19
  // src/next/index.ts
18
20
  var _react = require('react'); var React = _interopRequireWildcard(_react);
@@ -70,7 +72,7 @@ var BuilderUnavailablePageError = class extends Error {
70
72
  constructor(template) {
71
73
  super(`The ${template} template cannot be served: its data source is unavailable`);
72
74
  this.template = template;
73
- _chunkUNL4JWZScjs.__publicField.call(void 0, this, "name", "BuilderUnavailablePageError");
75
+ _chunkJ2IHOBDXcjs.__publicField.call(void 0, this, "name", "BuilderUnavailablePageError");
74
76
  }
75
77
  };
76
78
  var isRec = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
@@ -148,8 +150,8 @@ function createBuilderRoute(options) {
148
150
  return typeof params.locale === "string" ? params.locale : "en";
149
151
  }
150
152
  async function resolve(path, locale, currency) {
151
- const client = _chunkUNL4JWZScjs.clientOf.call(void 0, options);
152
- const bundle = await _chunkUNL4JWZScjs.getBundle.call(void 0, { client, locale, slots: options.slots });
153
+ const client = _chunkJ2IHOBDXcjs.clientOf.call(void 0, options);
154
+ const bundle = await _chunkJ2IHOBDXcjs.getBundle.call(void 0, { client, locale, slots: options.slots });
153
155
  const settings = bundle.site.settings;
154
156
  const read = {
155
157
  client: options.client,
@@ -172,11 +174,11 @@ function createBuilderRoute(options) {
172
174
  const params = matchTemplate(template, path);
173
175
  return params === null ? [] : [{ name, params }];
174
176
  })[0];
175
- const routeTable = _chunkUNL4JWZScjs.buildRouteTable.call(void 0, store, catalog);
177
+ const routeTable = _chunkJ2IHOBDXcjs.buildRouteTable.call(void 0, store, catalog);
176
178
  if (path === "/") {
177
179
  try {
178
- const home = await _chunkUNL4JWZScjs.loadBuilderPage.call(void 0, { ...read, slug: "home" });
179
- if (home.kind === "redirect") return redirectTo(home.redirectTo);
180
+ const home = await _chunkJ2IHOBDXcjs.loadBuilderPage.call(void 0, { ...read, slug: "home" });
181
+ if (home.kind === "redirect") return pageRedirectTo(home.redirectTo);
180
182
  return { kind: "page", slug: "home", page: home, path, own: false };
181
183
  } catch (error) {
182
184
  if (!isNotFound(error)) throw error;
@@ -186,18 +188,18 @@ function createBuilderRoute(options) {
186
188
  const handle = _optionalChain([matchTemplate, 'call', _6 => _6(pageRoute, path), 'optionalAccess', _7 => _7.handle]);
187
189
  if (matched === void 0 && handle === void 0 && path !== "/" && _builderschema.PAGE_PATH_RE.test(path)) {
188
190
  try {
189
- const found = await _chunkUNL4JWZScjs.loadBuilderPageByPath.call(void 0, { ...read, path });
190
- if (found.kind === "redirect") return redirectTo(found.redirectTo);
191
+ const found = await _chunkJ2IHOBDXcjs.loadBuilderPageByPath.call(void 0, { ...read, path });
192
+ if (found.kind === "redirect") return pageRedirectTo(found.redirectTo);
191
193
  return { kind: "page", slug: found.slug, page: found, path, own: true };
192
194
  } catch (error) {
193
- if (!isNotFound(error)) throw error;
195
+ if (!isNotFound(error) && !isNamed(error, "BuilderValidationError")) throw error;
194
196
  }
195
197
  }
196
198
  if (handle !== void 0) {
197
199
  try {
198
- const found = await _chunkUNL4JWZScjs.loadBuilderPage.call(void 0, { ...read, slug: handle });
199
- if (found.kind === "redirect") return redirectTo(found.redirectTo);
200
- if (_chunkUNL4JWZScjs.isOwnPath.call(void 0, found.path)) return { kind: "redirect", to: found.path, permanent: true };
200
+ const found = await _chunkJ2IHOBDXcjs.loadBuilderPage.call(void 0, { ...read, slug: handle });
201
+ if (found.kind === "redirect") return pageRedirectTo(found.redirectTo);
202
+ if (_chunkJ2IHOBDXcjs.isOwnPath.call(void 0, found.path)) return { kind: "redirect", to: found.path, permanent: true };
201
203
  return { kind: "page", slug: handle, page: found, path, own: false };
202
204
  } catch (error) {
203
205
  if (!isNotFound(error)) throw error;
@@ -209,7 +211,7 @@ function createBuilderRoute(options) {
209
211
  async function finish(matched, queryJson, locale, currency) {
210
212
  const { name, path, routeTable } = matched;
211
213
  const query = JSON.parse(queryJson);
212
- const bundle = await _chunkUNL4JWZScjs.getBundle.call(void 0, { client: _chunkUNL4JWZScjs.clientOf.call(void 0, options), locale, slots: options.slots });
214
+ const bundle = await _chunkJ2IHOBDXcjs.getBundle.call(void 0, { client: _chunkJ2IHOBDXcjs.clientOf.call(void 0, options), locale, slots: options.slots });
213
215
  const read = {
214
216
  client: options.client,
215
217
  builderKey: options.builderKey,
@@ -232,7 +234,7 @@ function createBuilderRoute(options) {
232
234
  ...bundle.code === void 0 ? {} : { code: bundle.code }
233
235
  };
234
236
  try {
235
- const { part, meta } = await _chunkUNL4JWZScjs.loadBuilderTemplate.call(void 0, { ...read, name, shared });
237
+ const { part, meta } = await _chunkJ2IHOBDXcjs.loadBuilderTemplate.call(void 0, { ...read, name, shared });
236
238
  return { kind: "template", name, part, context, meta, routeTable, path, unavailable };
237
239
  } catch (error) {
238
240
  const contribution = packs.flatMap((pack) => _nullishCoalesce(pack.templates, () => ( []))).find((entry) => entry.name === name);
@@ -255,6 +257,10 @@ function createBuilderRoute(options) {
255
257
  };
256
258
  }
257
259
  }
260
+ function pageRedirectTo(to) {
261
+ const path = sitePath(to);
262
+ return path === null ? { kind: "notFound" } : { kind: "redirect", to: path, permanent: true };
263
+ }
258
264
  function redirectTo(to) {
259
265
  const path = _nullishCoalesce(sitePath(to), () => ( (/^https?:\/\/[^\s\\]+$/iu.test(to) ? to : null)));
260
266
  return path === null ? { kind: "notFound" } : { kind: "redirect", to: path, permanent: true };
@@ -293,24 +299,47 @@ function createBuilderRoute(options) {
293
299
  return { resolved, params, locale, search: search === "" ? "" : `?${search}` };
294
300
  }
295
301
  function templateBody(resolved) {
296
- const view = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _builderreact.BuilderTemplateView, { name: resolved.name, part: resolved.part, context: resolved.context });
297
- const Root = _chunkUNL4JWZScjs.templateRootOf.call(void 0, packs, resolved.name);
302
+ const view = /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
303
+ _builderreact.BuilderTemplateView,
304
+ {
305
+ name: resolved.name,
306
+ part: resolved.part,
307
+ context: resolved.context,
308
+ frame: _optionalChain([resolved, 'access', _8 => _8.meta, 'optionalAccess', _9 => _9.frame])
309
+ }
310
+ );
311
+ const Root = _chunkJ2IHOBDXcjs.templateRootOf.call(void 0, packs, resolved.name);
298
312
  if (Root === void 0) return view;
299
313
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Root, { context: resolved.context, document: resolved.part.document, children: view });
300
314
  }
301
315
  async function Page(props) {
302
- const { resolved } = await request(props);
316
+ const { resolved, locale } = await request(props);
303
317
  switch (resolved.kind) {
304
318
  case "redirect":
305
319
  return resolved.permanent ? _navigation.permanentRedirect.call(void 0, resolved.to) : _navigation.redirect.call(void 0, resolved.to);
306
320
  case "notFound":
307
321
  return _navigation.notFound.call(void 0, );
308
- case "page":
309
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _builderreact.BuilderRouteScope, { ...resolved.own ? { allowPath: resolved.path } : {}, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _builderreact.BuilderPageView, { page: resolved.page }) });
322
+ case "page": {
323
+ const view = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _builderreact.BuilderRouteScope, { ...resolved.own ? { allowPath: resolved.path } : {}, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _builderreact.BuilderPageView, { page: resolved.page }) });
324
+ if (options.siteJsonLd === false || resolved.path !== "/") return view;
325
+ const bundle = await _chunkJ2IHOBDXcjs.getBundle.call(void 0, { client: _chunkJ2IHOBDXcjs.clientOf.call(void 0, options), locale, slots: options.slots });
326
+ const catalogOn = bundle.site.catalogInstalled !== false;
327
+ const search = { ...DEFAULT_CATALOG_TEMPLATE_PATHS, ...options.catalogRoutes }.search;
328
+ const entries = _chunkJ2IHOBDXcjs.siteJsonLdOf.call(void 0, bundle.site.settings, {
329
+ storeUrl: options.storeUrl,
330
+ mediaOrigin: _nullishCoalesce(options.mediaOrigin, () => ( "")),
331
+ searchPath: catalogOn && search !== void 0 && !search.includes("{") ? search : null
332
+ });
333
+ if (entries.length === 0) return view;
334
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
335
+ entries.map((entry) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "script", { type: "application/ld+json", children: _chunkJ2IHOBDXcjs.jsonLdString.call(void 0, entry) }, String(entry["@id"]))),
336
+ view
337
+ ] });
338
+ }
310
339
  case "template":
311
340
  if (resolved.unavailable) {
312
341
  if (options.unavailable === "error") throw new BuilderUnavailablePageError(resolved.name);
313
- _optionalChain([options, 'access', _8 => _8.onUnavailable, 'optionalCall', _9 => _9({
342
+ _optionalChain([options, 'access', _10 => _10.onUnavailable, 'optionalCall', _11 => _11({
314
343
  status: 503,
315
344
  headers: { "Retry-After": String(_nullishCoalesce(options.retryAfterSeconds, () => ( 30))) }
316
345
  })]);
@@ -323,14 +352,14 @@ function createBuilderRoute(options) {
323
352
  }
324
353
  }
325
354
  async function generateMetadata(props) {
326
- const client = _chunkUNL4JWZScjs.clientOf.call(void 0, options);
355
+ const client = _chunkJ2IHOBDXcjs.clientOf.call(void 0, options);
327
356
  try {
328
357
  const { resolved, params, locale, search } = await request(props);
329
358
  if (resolved.kind === "redirect" || resolved.kind === "notFound") return {};
330
- const bundle = await _chunkUNL4JWZScjs.getBundle.call(void 0, { client, locale, slots: options.slots });
359
+ const bundle = await _chunkJ2IHOBDXcjs.getBundle.call(void 0, { client, locale, slots: options.slots });
331
360
  const settings = bundle.site.settings;
332
361
  if (resolved.kind === "page") {
333
- const shared = await _chunkUNL4JWZScjs.getBundle.call(void 0, {
362
+ const shared = await _chunkJ2IHOBDXcjs.getBundle.call(void 0, {
334
363
  client,
335
364
  locale,
336
365
  page: resolved.slug,
@@ -338,7 +367,7 @@ function createBuilderRoute(options) {
338
367
  });
339
368
  const page = shared.page;
340
369
  if (page === void 0 || "redirectTo" in page) return {};
341
- return _chunkUNL4JWZScjs.metadataOf.call(void 0, page, {
370
+ return _chunkJ2IHOBDXcjs.metadataOf.call(void 0, page, {
342
371
  settings: shared.site.settings,
343
372
  mediaOrigin: _nullishCoalesce(options.mediaOrigin, () => ( "")),
344
373
  storeUrl: options.storeUrl,
@@ -346,7 +375,7 @@ function createBuilderRoute(options) {
346
375
  routeLocale: options.locale === void 0 && typeof params.locale === "string" ? params.locale : void 0
347
376
  });
348
377
  }
349
- return _chunkUNL4JWZScjs.templateMetadataOf.call(void 0, resolved.name, {
378
+ return _chunkJ2IHOBDXcjs.templateMetadataOf.call(void 0, resolved.name, {
350
379
  settings,
351
380
  storeUrl: options.storeUrl,
352
381
  mediaOrigin: _nullishCoalesce(options.mediaOrigin, () => ( "")),
@@ -378,18 +407,23 @@ async function BuilderTemplate({
378
407
  ...client
379
408
  }) {
380
409
  try {
381
- const { part } = await _chunkUNL4JWZScjs.loadBuilderTemplate.call(void 0, {
410
+ const { part, meta } = await _chunkJ2IHOBDXcjs.loadBuilderTemplate.call(void 0, {
382
411
  ...client,
383
412
  name,
384
413
  locale,
385
414
  ...packs === void 0 ? {} : { packs }
386
415
  });
387
416
  const templateContext = _nullishCoalesce(context, () => ( { route: { path: "", params: {}, query: {} } }));
388
- const view = _react.createElement.call(void 0, _builderreact.BuilderTemplateView, { name, part, context: templateContext });
389
- const Root = _chunkUNL4JWZScjs.templateRootOf.call(void 0, packs, name);
417
+ const view = _react.createElement.call(void 0, _builderreact.BuilderTemplateView, {
418
+ name,
419
+ part,
420
+ context: templateContext,
421
+ frame: _optionalChain([meta, 'optionalAccess', _12 => _12.frame])
422
+ });
423
+ const Root = _chunkJ2IHOBDXcjs.templateRootOf.call(void 0, packs, name);
390
424
  return Root === void 0 ? view : _react.createElement.call(void 0, Root, { context: templateContext, document: part.document, children: view });
391
425
  } catch (error) {
392
- if (error instanceof _builder.BuilderUnavailableError || _optionalChain([error, 'optionalAccess', _10 => _10.name]) === "BuilderUnavailableError")
426
+ if (error instanceof _builder.BuilderUnavailableError || _optionalChain([error, 'optionalAccess', _13 => _13.name]) === "BuilderUnavailableError")
393
427
  return null;
394
428
  throw error;
395
429
  }
@@ -419,7 +453,7 @@ function createBuilderPage(options) {
419
453
  const slug = slugOf(options, params);
420
454
  const currency = await currencyOf(options, params);
421
455
  const { currency: _currency, ...rest } = options;
422
- const loaded = await _chunkUNL4JWZScjs.loadBuilderPage.call(void 0, {
456
+ const loaded = await _chunkJ2IHOBDXcjs.loadBuilderPage.call(void 0, {
423
457
  ...rest,
424
458
  slug,
425
459
  locale: await localeOf(options, params),
@@ -439,12 +473,12 @@ function createBuilderPage(options) {
439
473
  const params = await props.params;
440
474
  const slug = slugOf(options, params);
441
475
  const locale = await localeOf(options, params);
442
- const client = _chunkUNL4JWZScjs.clientOf.call(void 0, options);
476
+ const client = _chunkJ2IHOBDXcjs.clientOf.call(void 0, options);
443
477
  try {
444
- const bundle = await _chunkUNL4JWZScjs.getBundle.call(void 0, { client, locale, page: slug, slots: options.slots });
478
+ const bundle = await _chunkJ2IHOBDXcjs.getBundle.call(void 0, { client, locale, page: slug, slots: options.slots });
445
479
  const page = bundle.page;
446
- if (page === void 0 || _chunkUNL4JWZScjs.isRedirect.call(void 0, page)) return {};
447
- return _chunkUNL4JWZScjs.metadataOf.call(void 0, page, {
480
+ if (page === void 0 || _chunkJ2IHOBDXcjs.isRedirect.call(void 0, page)) return {};
481
+ return _chunkJ2IHOBDXcjs.metadataOf.call(void 0, page, {
448
482
  settings: bundle.site.settings,
449
483
  mediaOrigin: _nullishCoalesce(options.mediaOrigin, () => ( "")),
450
484
  storeUrl: options.storeUrl,
@@ -467,4 +501,4 @@ function createBuilderPage(options) {
467
501
 
468
502
 
469
503
 
470
- exports.BuilderTemplate = BuilderTemplate; exports.BuilderUnavailablePageError = BuilderUnavailablePageError; exports.DEFAULT_CATALOG_TEMPLATE_PATHS = DEFAULT_CATALOG_TEMPLATE_PATHS; exports.DEFAULT_STORE_TEMPLATE_PATHS = DEFAULT_STORE_TEMPLATE_PATHS; exports.canonicalFor = _chunkUNL4JWZScjs.canonicalFor; exports.createBuilderPage = createBuilderPage; exports.createBuilderRoute = createBuilderRoute;
504
+ exports.BuilderTemplate = BuilderTemplate; exports.BuilderUnavailablePageError = BuilderUnavailablePageError; exports.DEFAULT_CATALOG_TEMPLATE_PATHS = DEFAULT_CATALOG_TEMPLATE_PATHS; exports.DEFAULT_STORE_TEMPLATE_PATHS = DEFAULT_STORE_TEMPLATE_PATHS; exports.canonicalFor = _chunkJ2IHOBDXcjs.canonicalFor; exports.createBuilderPage = createBuilderPage; exports.createBuilderRoute = createBuilderRoute;
package/dist/next.d.cts CHANGED
@@ -39,6 +39,11 @@ type CreateBuilderRouteOptions = Omit<BuilderRouteConfig, 'site' | 'loaders'> &
39
39
  storeUrl?: string;
40
40
  mediaOrigin?: string;
41
41
  pagePath?: PagePathResolver;
42
+ /**
43
+ * Emit the site-level JSON-LD (Organization, WebSite, LocalBusiness; each only when its `seo.structuredData` switch
44
+ * is on) on the home page. Default true; pass `false` when the store already emits its own.
45
+ */
46
+ siteJsonLd?: boolean;
42
47
  /** Seconds in the `Retry-After` of an unavailable template. Default 30. */
43
48
  retryAfterSeconds?: number;
44
49
  /**
@@ -89,7 +94,8 @@ type BuilderTemplateProps = ClientOptions & {
89
94
  /**
90
95
  * A published template drawn on its own: `app/(store)/not-found.tsx` is `<BuilderTemplate name="not-found" ... />`, which
91
96
  * Next renders inside the layout, so the header and footer stay around it. A template that cannot be read draws
92
- * nothing rather than failing the 404 (the layout's parts still render).
97
+ * nothing rather than failing the 404 (the layout's parts still render). A template whose meta has `frame: 'none'`
98
+ * hides those parts with CSS (the layout draws them, so they stay in the HTML).
93
99
  */
94
100
  declare function BuilderTemplate({ name, packs, locale, context, ...client }: BuilderTemplateProps): Promise<ReactNode>;
95
101
 
package/dist/next.d.ts CHANGED
@@ -39,6 +39,11 @@ type CreateBuilderRouteOptions = Omit<BuilderRouteConfig, 'site' | 'loaders'> &
39
39
  storeUrl?: string;
40
40
  mediaOrigin?: string;
41
41
  pagePath?: PagePathResolver;
42
+ /**
43
+ * Emit the site-level JSON-LD (Organization, WebSite, LocalBusiness; each only when its `seo.structuredData` switch
44
+ * is on) on the home page. Default true; pass `false` when the store already emits its own.
45
+ */
46
+ siteJsonLd?: boolean;
42
47
  /** Seconds in the `Retry-After` of an unavailable template. Default 30. */
43
48
  retryAfterSeconds?: number;
44
49
  /**
@@ -89,7 +94,8 @@ type BuilderTemplateProps = ClientOptions & {
89
94
  /**
90
95
  * A published template drawn on its own: `app/(store)/not-found.tsx` is `<BuilderTemplate name="not-found" ... />`, which
91
96
  * Next renders inside the layout, so the header and footer stay around it. A template that cannot be read draws
92
- * nothing rather than failing the 404 (the layout's parts still render).
97
+ * nothing rather than failing the 404 (the layout's parts still render). A template whose meta has `frame: 'none'`
98
+ * hides those parts with CSS (the layout draws them, so they stay in the HTML).
93
99
  */
94
100
  declare function BuilderTemplate({ name, packs, locale, context, ...client }: BuilderTemplateProps): Promise<ReactNode>;
95
101
 
package/dist/next.js CHANGED
@@ -6,13 +6,15 @@ import {
6
6
  getBundle,
7
7
  isOwnPath,
8
8
  isRedirect,
9
+ jsonLdString,
9
10
  loadBuilderPage,
10
11
  loadBuilderPageByPath,
11
12
  loadBuilderTemplate,
12
13
  metadataOf,
14
+ siteJsonLdOf,
13
15
  templateMetadataOf,
14
16
  templateRootOf
15
- } from "./chunk-G6I4RIXU.js";
17
+ } from "./chunk-HE6MD2RZ.js";
16
18
 
17
19
  // src/next/index.ts
18
20
  import { createElement as createElement2 } from "react";
@@ -49,7 +51,7 @@ import {
49
51
  BuilderRouteScope,
50
52
  BuilderTemplateView
51
53
  } from "@usethrottle/builder-react";
52
- import { jsx, jsxs } from "react/jsx-runtime";
54
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
53
55
  var DEFAULT_CATALOG_TEMPLATE_PATHS = {
54
56
  shop: "/shop",
55
57
  collection: "/collections/{handle}",
@@ -176,7 +178,7 @@ function createBuilderRoute(options) {
176
178
  if (path === "/") {
177
179
  try {
178
180
  const home = await loadBuilderPage({ ...read, slug: "home" });
179
- if (home.kind === "redirect") return redirectTo(home.redirectTo);
181
+ if (home.kind === "redirect") return pageRedirectTo(home.redirectTo);
180
182
  return { kind: "page", slug: "home", page: home, path, own: false };
181
183
  } catch (error) {
182
184
  if (!isNotFound(error)) throw error;
@@ -187,16 +189,16 @@ function createBuilderRoute(options) {
187
189
  if (matched === void 0 && handle === void 0 && path !== "/" && PAGE_PATH_RE.test(path)) {
188
190
  try {
189
191
  const found = await loadBuilderPageByPath({ ...read, path });
190
- if (found.kind === "redirect") return redirectTo(found.redirectTo);
192
+ if (found.kind === "redirect") return pageRedirectTo(found.redirectTo);
191
193
  return { kind: "page", slug: found.slug, page: found, path, own: true };
192
194
  } catch (error) {
193
- if (!isNotFound(error)) throw error;
195
+ if (!isNotFound(error) && !isNamed(error, "BuilderValidationError")) throw error;
194
196
  }
195
197
  }
196
198
  if (handle !== void 0) {
197
199
  try {
198
200
  const found = await loadBuilderPage({ ...read, slug: handle });
199
- if (found.kind === "redirect") return redirectTo(found.redirectTo);
201
+ if (found.kind === "redirect") return pageRedirectTo(found.redirectTo);
200
202
  if (isOwnPath(found.path)) return { kind: "redirect", to: found.path, permanent: true };
201
203
  return { kind: "page", slug: handle, page: found, path, own: false };
202
204
  } catch (error) {
@@ -255,6 +257,10 @@ function createBuilderRoute(options) {
255
257
  };
256
258
  }
257
259
  }
260
+ function pageRedirectTo(to) {
261
+ const path = sitePath(to);
262
+ return path === null ? { kind: "notFound" } : { kind: "redirect", to: path, permanent: true };
263
+ }
258
264
  function redirectTo(to) {
259
265
  const path = sitePath(to) ?? (/^https?:\/\/[^\s\\]+$/iu.test(to) ? to : null);
260
266
  return path === null ? { kind: "notFound" } : { kind: "redirect", to: path, permanent: true };
@@ -293,20 +299,43 @@ function createBuilderRoute(options) {
293
299
  return { resolved, params, locale, search: search === "" ? "" : `?${search}` };
294
300
  }
295
301
  function templateBody(resolved) {
296
- const view = /* @__PURE__ */ jsx(BuilderTemplateView, { name: resolved.name, part: resolved.part, context: resolved.context });
302
+ const view = /* @__PURE__ */ jsx(
303
+ BuilderTemplateView,
304
+ {
305
+ name: resolved.name,
306
+ part: resolved.part,
307
+ context: resolved.context,
308
+ frame: resolved.meta?.frame
309
+ }
310
+ );
297
311
  const Root = templateRootOf(packs, resolved.name);
298
312
  if (Root === void 0) return view;
299
313
  return /* @__PURE__ */ jsx(Root, { context: resolved.context, document: resolved.part.document, children: view });
300
314
  }
301
315
  async function Page(props) {
302
- const { resolved } = await request(props);
316
+ const { resolved, locale } = await request(props);
303
317
  switch (resolved.kind) {
304
318
  case "redirect":
305
319
  return resolved.permanent ? permanentRedirect(resolved.to) : redirect(resolved.to);
306
320
  case "notFound":
307
321
  return notFound();
308
- case "page":
309
- return /* @__PURE__ */ jsx(BuilderRouteScope, { ...resolved.own ? { allowPath: resolved.path } : {}, children: /* @__PURE__ */ jsx(BuilderPageView, { page: resolved.page }) });
322
+ case "page": {
323
+ const view = /* @__PURE__ */ jsx(BuilderRouteScope, { ...resolved.own ? { allowPath: resolved.path } : {}, children: /* @__PURE__ */ jsx(BuilderPageView, { page: resolved.page }) });
324
+ if (options.siteJsonLd === false || resolved.path !== "/") return view;
325
+ const bundle = await getBundle({ client: clientOf(options), locale, slots: options.slots });
326
+ const catalogOn = bundle.site.catalogInstalled !== false;
327
+ const search = { ...DEFAULT_CATALOG_TEMPLATE_PATHS, ...options.catalogRoutes }.search;
328
+ const entries = siteJsonLdOf(bundle.site.settings, {
329
+ storeUrl: options.storeUrl,
330
+ mediaOrigin: options.mediaOrigin ?? "",
331
+ searchPath: catalogOn && search !== void 0 && !search.includes("{") ? search : null
332
+ });
333
+ if (entries.length === 0) return view;
334
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
335
+ entries.map((entry) => /* @__PURE__ */ jsx("script", { type: "application/ld+json", children: jsonLdString(entry) }, String(entry["@id"]))),
336
+ view
337
+ ] });
338
+ }
310
339
  case "template":
311
340
  if (resolved.unavailable) {
312
341
  if (options.unavailable === "error") throw new BuilderUnavailablePageError(resolved.name);
@@ -378,14 +407,19 @@ async function BuilderTemplate({
378
407
  ...client
379
408
  }) {
380
409
  try {
381
- const { part } = await loadBuilderTemplate({
410
+ const { part, meta } = await loadBuilderTemplate({
382
411
  ...client,
383
412
  name,
384
413
  locale,
385
414
  ...packs === void 0 ? {} : { packs }
386
415
  });
387
416
  const templateContext = context ?? { route: { path: "", params: {}, query: {} } };
388
- const view = createElement(BuilderTemplateView2, { name, part, context: templateContext });
417
+ const view = createElement(BuilderTemplateView2, {
418
+ name,
419
+ part,
420
+ context: templateContext,
421
+ frame: meta?.frame
422
+ });
389
423
  const Root = templateRootOf(packs, name);
390
424
  return Root === void 0 ? view : createElement(Root, { context: templateContext, document: part.document, children: view });
391
425
  } catch (error) {
package/dist/server.cjs CHANGED
@@ -22,7 +22,8 @@
22
22
 
23
23
 
24
24
 
25
- var _chunkUNL4JWZScjs = require('./chunk-UNL4JWZS.cjs');
25
+
26
+ var _chunkJ2IHOBDXcjs = require('./chunk-J2IHOBDX.cjs');
26
27
 
27
28
  // src/server/load-site.ts
28
29
  var _builder = require('@usethrottle/builder');
@@ -32,23 +33,23 @@ function siteThemeOf(site) {
32
33
  }
33
34
  async function loadSite(options) {
34
35
  const { locale, slots = [], packs = [], page, mediaOrigin = "", currency } = options;
35
- const client = _chunkUNL4JWZScjs.clientOf.call(void 0, options);
36
+ const client = _chunkJ2IHOBDXcjs.clientOf.call(void 0, options);
36
37
  let bundle;
37
38
  try {
38
- bundle = await _chunkUNL4JWZScjs.getBundle.call(void 0, { client, locale, slots, page });
39
+ bundle = await _chunkJ2IHOBDXcjs.getBundle.call(void 0, { client, locale, slots, page });
39
40
  } catch (error) {
40
41
  if (!(error instanceof _builder.BuilderUnavailableError) || client.mode === "build") throw error;
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`);
42
+ _chunkJ2IHOBDXcjs.warnOnce.call(void 0, "site-unavailable", `The Builder could not be read (${error.reason}); the store renders without its Builder header, footer and slots`);
42
43
  return { status: "unavailable", locale };
43
44
  }
44
- const registry = _chunkUNL4JWZScjs.createRendererRegistry.call(void 0, packs);
45
+ const registry = _chunkJ2IHOBDXcjs.createRendererRegistry.call(void 0, packs);
45
46
  const names = Object.keys(bundle.slots);
46
47
  const withShared = (loaded) => ({
47
48
  ...loaded,
48
49
  ...(_nullishCoalesce(loaded.savedSections, () => ( bundle.savedSections))) === void 0 ? {} : { savedSections: _nullishCoalesce(loaded.savedSections, () => ( bundle.savedSections)) }
49
50
  });
50
51
  const documents = [bundle.header, bundle.footer, ...names.map((n) => bundle.slots[n])].map(withShared);
51
- const data = await _chunkUNL4JWZScjs.staticDataFor.call(void 0, documents, registry, locale, currency);
52
+ const data = await _chunkJ2IHOBDXcjs.staticDataFor.call(void 0, documents, registry, locale, currency);
52
53
  return {
53
54
  status: "ok",
54
55
  locale,
@@ -58,9 +59,9 @@ async function loadSite(options) {
58
59
  mediaOrigin,
59
60
  settings: bundle.site.settings,
60
61
  ...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)]))
62
+ header: _chunkJ2IHOBDXcjs.partOf.call(void 0, bundle.header, data, bundle),
63
+ footer: _chunkJ2IHOBDXcjs.partOf.call(void 0, bundle.footer, data, bundle),
64
+ slots: Object.fromEntries(names.map((name) => [name, _chunkJ2IHOBDXcjs.partOf.call(void 0, bundle.slots[name], data, bundle)]))
64
65
  };
65
66
  }
66
67
 
@@ -98,7 +99,7 @@ var pathnameOf = (url) => {
98
99
  }
99
100
  };
100
101
  async function builderSitemapParts(options, extras = {}) {
101
- const origin = _chunkUNL4JWZScjs.originOf.call(void 0, options.storeUrl);
102
+ const origin = _chunkJ2IHOBDXcjs.originOf.call(void 0, options.storeUrl);
102
103
  const entries = await pageEntries(options, origin);
103
104
  if (origin === void 0) return { parts: [] };
104
105
  const rules = sitemapRulesOf(await settingsOf(options));
@@ -114,7 +115,7 @@ async function builderSitemapParts(options, extras = {}) {
114
115
  entries.push({ url: loc, ...when === void 0 || Number.isNaN(when.getTime()) ? {} : { lastModified: when } });
115
116
  }
116
117
  } 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
+ _chunkJ2IHOBDXcjs.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
  }
119
120
  }
120
121
  const parts = [];
@@ -128,19 +129,19 @@ async function builderSitemap(options, extras = {}) {
128
129
  }
129
130
  async function settingsOf(options) {
130
131
  try {
131
- return (await _chunkUNL4JWZScjs.clientOf.call(void 0, options).site({ locale: _nullishCoalesce(options.locale, () => ( "en")) })).settings;
132
+ return (await _chunkJ2IHOBDXcjs.clientOf.call(void 0, options).site({ locale: _nullishCoalesce(options.locale, () => ( "en")) })).settings;
132
133
  } catch (e3) {
133
134
  return {};
134
135
  }
135
136
  }
136
137
  async function pageEntries(options, origin) {
137
138
  if (options.client === void 0 && (options.builderKey === void 0 || options.builderKey === "")) {
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");
139
+ _chunkJ2IHOBDXcjs.warnOnce.call(void 0, "sitemap-no-key", "builderSitemap has no builderKey (is THROTTLE_BUILDER_KEY set?); the sitemap leaves out the Builder pages");
139
140
  return [];
140
141
  }
141
- const client = _chunkUNL4JWZScjs.clientOf.call(void 0, options);
142
+ const client = _chunkJ2IHOBDXcjs.clientOf.call(void 0, options);
142
143
  if (origin === void 0) {
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.");
144
+ _chunkJ2IHOBDXcjs.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.");
144
145
  return [];
145
146
  }
146
147
  const locale = _nullishCoalesce(options.locale, () => ( "en"));
@@ -150,19 +151,19 @@ async function pageEntries(options, origin) {
150
151
  const rules = sitemapRulesOf(settings);
151
152
  if (!rules.pages) return [];
152
153
  const indexable = await withoutNoindex(client, pages, locale);
153
- const { list } = _chunkUNL4JWZScjs.siteLocales.call(void 0, settings);
154
+ const { list } = _chunkJ2IHOBDXcjs.siteLocales.call(void 0, settings);
154
155
  const prefixes = options.localeRoute !== true ? [void 0] : list.length > 0 ? list : [locale];
155
156
  return indexable.flatMap((page) => {
156
- const path = _chunkUNL4JWZScjs.pagePathOf.call(void 0, settings, page, options.pagePath);
157
+ const path = _chunkJ2IHOBDXcjs.pagePathOf.call(void 0, settings, page, options.pagePath);
157
158
  if (path === null || excluded(rules.exclude, path, page.slug)) return [];
158
159
  return prefixes.flatMap((prefix) => {
159
- const url = safeLoc(`${origin}${_chunkUNL4JWZScjs.localized.call(void 0, path, prefix)}`, origin);
160
+ const url = safeLoc(`${origin}${_chunkJ2IHOBDXcjs.localized.call(void 0, path, prefix)}`, origin);
160
161
  return url === null ? [] : [{ url, lastModified: new Date(page.updatedAt) }];
161
162
  });
162
163
  });
163
164
  } catch (error) {
164
165
  if (!(error instanceof _builder.BuilderUnavailableError) || client.mode === "build") throw error;
165
- _chunkUNL4JWZScjs.warnOnce.call(void 0, "sitemap-unavailable", `The Builder could not be read (${error.reason}); the sitemap leaves out its pages`);
166
+ _chunkJ2IHOBDXcjs.warnOnce.call(void 0, "sitemap-unavailable", `The Builder could not be read (${error.reason}); the sitemap leaves out its pages`);
166
167
  return [];
167
168
  }
168
169
  }
@@ -176,14 +177,14 @@ async function withoutNoindex(client, pages, locale) {
176
177
  slice.map(
177
178
  (page) => client.pages.get(page.slug, { locale }).catch((error) => {
178
179
  if (error instanceof _builder.BuilderNotFoundError) return "gone";
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`);
180
+ _chunkJ2IHOBDXcjs.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`);
180
181
  return void 0;
181
182
  })
182
183
  )
183
184
  );
184
185
  slice.forEach((page, index) => {
185
186
  const answer = answers[index];
186
- if (answer === "gone" || answer !== void 0 && (_chunkUNL4JWZScjs.isRedirect.call(void 0, answer) || _chunkUNL4JWZScjs.pageSeoOf.call(void 0, answer).noindex)) skip.add(page.slug);
187
+ if (answer === "gone" || answer !== void 0 && (_chunkJ2IHOBDXcjs.isRedirect.call(void 0, answer) || _chunkJ2IHOBDXcjs.pageSeoOf.call(void 0, answer).noindex)) skip.add(page.slug);
187
188
  });
188
189
  }
189
190
  return pages.filter((page) => !skip.has(page.slug));
@@ -232,7 +233,7 @@ var validDisallow = (value) => validLine(value) && value.trim() !== "/";
232
233
  function siteOriginOf(site, options = {}) {
233
234
  const settings = _nullishCoalesce(site.settings, () => ( {}));
234
235
  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
+ return _nullishCoalesce(_nullishCoalesce(_chunkJ2IHOBDXcjs.originOf.call(void 0, typeof seo.canonicalBase === "string" ? seo.canonicalBase : void 0), () => ( _chunkJ2IHOBDXcjs.originOf.call(void 0, options.storeUrl))), () => ( _chunkJ2IHOBDXcjs.originOf.call(void 0, typeof settings.storeUrl === "string" ? settings.storeUrl : void 0)));
236
237
  }
237
238
  function builderRobots(site, options = {}) {
238
239
  const settings = _nullishCoalesce(site.settings, () => ( {}));
@@ -257,7 +258,7 @@ function builderRobotsResponse(site, options = {}) {
257
258
 
258
259
  // src/server/static-params.ts
259
260
  async function builderStaticParams(options) {
260
- const client = _chunkUNL4JWZScjs.clientOf.call(void 0, options);
261
+ const client = _chunkJ2IHOBDXcjs.clientOf.call(void 0, options);
261
262
  if (client.mode !== "build")
262
263
  throw new TypeError(
263
264
  'builderStaticParams generates every page of a frozen release: give it a client made with createBuilderClient({ mode: "build" }). A live store keeps its pages dynamic.'
@@ -292,4 +293,5 @@ async function builderStaticParams(options) {
292
293
 
293
294
 
294
295
 
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;
296
+
297
+ exports.BuilderNotFoundError = _builder.BuilderNotFoundError; exports.BuilderUnavailableError = _builder.BuilderUnavailableError; exports.DEFAULT_ROBOTS_DISALLOW = DEFAULT_ROBOTS_DISALLOW; exports.SITEMAP_MAX_URLS = SITEMAP_MAX_URLS; exports.breadcrumbJsonLd = _chunkJ2IHOBDXcjs.breadcrumbJsonLd; exports.builderRobots = builderRobots; exports.builderRobotsResponse = builderRobotsResponse; exports.builderSitemap = builderSitemap; exports.builderSitemapParts = builderSitemapParts; exports.builderStaticParams = builderStaticParams; exports.faqJsonLd = _chunkJ2IHOBDXcjs.faqJsonLd; exports.getBundle = _chunkJ2IHOBDXcjs.getBundle; exports.isOwnPath = _chunkJ2IHOBDXcjs.isOwnPath; exports.jsonLdString = _chunkJ2IHOBDXcjs.jsonLdString; exports.loadBuilderPage = _chunkJ2IHOBDXcjs.loadBuilderPage; exports.loadBuilderPageByPath = _chunkJ2IHOBDXcjs.loadBuilderPageByPath; exports.loadBuilderTemplate = _chunkJ2IHOBDXcjs.loadBuilderTemplate; exports.loadOwnPagePaths = _chunkJ2IHOBDXcjs.loadOwnPagePaths; exports.loadSite = loadSite; exports.localBusinessJsonLd = _chunkJ2IHOBDXcjs.localBusinessJsonLd; exports.organizationJsonLd = _chunkJ2IHOBDXcjs.organizationJsonLd; exports.siteOriginOf = siteOriginOf; exports.videoJsonLd = _chunkJ2IHOBDXcjs.videoJsonLd; exports.webSiteJsonLd = _chunkJ2IHOBDXcjs.webSiteJsonLd;