@usethrottle/builder-react 0.0.0-stage → 0.1.0

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 ADDED
@@ -0,0 +1,95 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+
4
+
5
+
6
+ var _chunkRWDLDDSFcjs = require('./chunk-RWDLDDSF.cjs');
7
+
8
+ // src/next/index.ts
9
+ var _react = require('react');
10
+ var _navigation = require('next/navigation');
11
+ var _builder = require('@usethrottle/builder');
12
+ var _builderreact = require('@usethrottle/builder-react');
13
+
14
+ // src/safe-path.ts
15
+ var _builderschema = require('@usethrottle/builder-schema');
16
+ var UNSAFE = /[\x00-\x20\x7f-\xa0\\\u1680\u2000-\u200f\u2028\u2029\u202f\u205f\u3000\ufeff]/;
17
+ var LEADING = /^\/(?![/\\])/;
18
+ function plainPath(path) {
19
+ return !UNSAFE.test(path) && (path === "/" || LEADING.test(path));
20
+ }
21
+ function sitePath(to) {
22
+ if (typeof to !== "string" || !plainPath(to)) return null;
23
+ let decoded;
24
+ try {
25
+ decoded = decodeURIComponent(to);
26
+ } catch (e) {
27
+ return null;
28
+ }
29
+ if (!plainPath(decoded)) return null;
30
+ return _builderschema.safeUrl.call(void 0, to, "href", { mediaOrigin: "" });
31
+ }
32
+
33
+ // src/next/index.ts
34
+ function slugOf(options, params) {
35
+ if ("slug" in options) return options.slug;
36
+ const value = params[options.fromParams];
37
+ const slug = Array.isArray(value) ? value.join("/") : value;
38
+ if (slug === void 0 || slug === "") _navigation.notFound.call(void 0, );
39
+ return slug;
40
+ }
41
+ async function localeOf(options, params) {
42
+ if (typeof options.locale === "function") return options.locale(params);
43
+ if (options.locale !== void 0) return options.locale;
44
+ const fromRoute = params.locale;
45
+ return typeof fromRoute === "string" ? fromRoute : "en";
46
+ }
47
+ function createBuilderPage(options) {
48
+ async function Page(props) {
49
+ const params = await props.params;
50
+ const slug = slugOf(options, params);
51
+ const loaded = await _chunkRWDLDDSFcjs.loadBuilderPage.call(void 0, {
52
+ ...options,
53
+ slug,
54
+ locale: await localeOf(options, params)
55
+ }).catch((error) => {
56
+ if (error instanceof _builder.BuilderNotFoundError) _navigation.notFound.call(void 0, );
57
+ throw error;
58
+ });
59
+ if (loaded.kind === "redirect") {
60
+ const path = sitePath(loaded.redirectTo);
61
+ if (path === null) _navigation.notFound.call(void 0, );
62
+ _navigation.permanentRedirect.call(void 0, path);
63
+ }
64
+ return _react.createElement.call(void 0, _builderreact.BuilderPageView, { page: loaded });
65
+ }
66
+ async function generateMetadata(props) {
67
+ const params = await props.params;
68
+ const slug = slugOf(options, params);
69
+ const locale = await localeOf(options, params);
70
+ try {
71
+ const bundle = await _chunkRWDLDDSFcjs.getBundle.call(void 0, { client: _chunkRWDLDDSFcjs.clientOf.call(void 0, options), locale, page: slug, slots: options.slots });
72
+ const page = bundle.page;
73
+ if (page === void 0 || _chunkRWDLDDSFcjs.isRedirect.call(void 0, page)) return {};
74
+ const site = bundle.site.settings;
75
+ const seo = typeof site.seo === "object" && site.seo !== null ? site.seo : {};
76
+ const brand = typeof site.brand === "object" && site.brand !== null ? site.brand : {};
77
+ const template = typeof seo.titleTemplate === "string" ? seo.titleTemplate : "{page}";
78
+ const store = typeof brand.storeName === "string" ? brand.storeName : "";
79
+ const own = typeof page.description === "string" ? page.description : void 0;
80
+ const fallback = typeof seo.defaultDescription === "string" ? seo.defaultDescription : void 0;
81
+ const description = _nullishCoalesce(own, () => ( fallback));
82
+ return {
83
+ title: template.replace("{page}", page.title).replace("{store}", store),
84
+ ...description === void 0 || description === "" ? {} : { description }
85
+ };
86
+ } catch (error) {
87
+ if (error instanceof _builder.BuilderNotFoundError || error instanceof _builder.BuilderUnavailableError) return {};
88
+ throw error;
89
+ }
90
+ }
91
+ return { Page, generateMetadata };
92
+ }
93
+
94
+
95
+ exports.createBuilderPage = createBuilderPage;
@@ -0,0 +1,41 @@
1
+ import { ReactNode } from 'react';
2
+ import { Metadata } from 'next';
3
+ import { C as ClientOptions, W as WidgetPack } from './bundle-x5Vxd-xE.cjs';
4
+ import '@usethrottle/builder-schema';
5
+ import '@usethrottle/builder';
6
+
7
+ type Params = Record<string, string | string[] | undefined>;
8
+ type CreateBuilderPageOptions = ({
9
+ slug: string;
10
+ } | {
11
+ fromParams: string;
12
+ }) & ClientOptions & {
13
+ packs?: readonly WidgetPack[];
14
+ /** The locale of the page; by default `params.locale` when the route has one, else `en`. */
15
+ locale?: string | ((params: Params) => string | Promise<string>);
16
+ /** The slots the layout reads, so the page read can share the layout's. */
17
+ slots?: readonly string[];
18
+ };
19
+ type PageProps = {
20
+ params: Promise<Params> | Params;
21
+ };
22
+ /**
23
+ * The route of a Builder page, for `app/pages/[handle]/page.tsx`:
24
+ *
25
+ * ```ts
26
+ * const { Page, generateMetadata } = createBuilderPage({ fromParams: 'handle', packs, builderKey });
27
+ * export default Page;
28
+ * export { generateMetadata };
29
+ * ```
30
+ *
31
+ * `Page` reads the page, answers `notFound()` for an unpublished one and a
32
+ * permanent redirect for a renamed slug, and lets `BuilderUnavailableError`
33
+ * reach the store's error boundary. It renders through `BuilderProvider`, so the
34
+ * route needs one above it (the layout has it).
35
+ */
36
+ declare function createBuilderPage(options: CreateBuilderPageOptions): {
37
+ Page: (props: PageProps) => Promise<ReactNode>;
38
+ generateMetadata: (props: PageProps) => Promise<Metadata>;
39
+ };
40
+
41
+ export { type CreateBuilderPageOptions, createBuilderPage };
package/dist/next.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { ReactNode } from 'react';
2
+ import { Metadata } from 'next';
3
+ import { C as ClientOptions, W as WidgetPack } from './bundle-x5Vxd-xE.js';
4
+ import '@usethrottle/builder-schema';
5
+ import '@usethrottle/builder';
6
+
7
+ type Params = Record<string, string | string[] | undefined>;
8
+ type CreateBuilderPageOptions = ({
9
+ slug: string;
10
+ } | {
11
+ fromParams: string;
12
+ }) & ClientOptions & {
13
+ packs?: readonly WidgetPack[];
14
+ /** The locale of the page; by default `params.locale` when the route has one, else `en`. */
15
+ locale?: string | ((params: Params) => string | Promise<string>);
16
+ /** The slots the layout reads, so the page read can share the layout's. */
17
+ slots?: readonly string[];
18
+ };
19
+ type PageProps = {
20
+ params: Promise<Params> | Params;
21
+ };
22
+ /**
23
+ * The route of a Builder page, for `app/pages/[handle]/page.tsx`:
24
+ *
25
+ * ```ts
26
+ * const { Page, generateMetadata } = createBuilderPage({ fromParams: 'handle', packs, builderKey });
27
+ * export default Page;
28
+ * export { generateMetadata };
29
+ * ```
30
+ *
31
+ * `Page` reads the page, answers `notFound()` for an unpublished one and a
32
+ * permanent redirect for a renamed slug, and lets `BuilderUnavailableError`
33
+ * reach the store's error boundary. It renders through `BuilderProvider`, so the
34
+ * route needs one above it (the layout has it).
35
+ */
36
+ declare function createBuilderPage(options: CreateBuilderPageOptions): {
37
+ Page: (props: PageProps) => Promise<ReactNode>;
38
+ generateMetadata: (props: PageProps) => Promise<Metadata>;
39
+ };
40
+
41
+ export { type CreateBuilderPageOptions, createBuilderPage };
package/dist/next.js ADDED
@@ -0,0 +1,95 @@
1
+ import {
2
+ clientOf,
3
+ getBundle,
4
+ isRedirect,
5
+ loadBuilderPage
6
+ } from "./chunk-DRQNR5GN.js";
7
+
8
+ // src/next/index.ts
9
+ import { createElement } from "react";
10
+ import { notFound, permanentRedirect } from "next/navigation";
11
+ import { BuilderNotFoundError, BuilderUnavailableError } from "@usethrottle/builder";
12
+ import { BuilderPageView } from "@usethrottle/builder-react";
13
+
14
+ // src/safe-path.ts
15
+ import { safeUrl } from "@usethrottle/builder-schema";
16
+ var UNSAFE = /[\x00-\x20\x7f-\xa0\\\u1680\u2000-\u200f\u2028\u2029\u202f\u205f\u3000\ufeff]/;
17
+ var LEADING = /^\/(?![/\\])/;
18
+ function plainPath(path) {
19
+ return !UNSAFE.test(path) && (path === "/" || LEADING.test(path));
20
+ }
21
+ function sitePath(to) {
22
+ if (typeof to !== "string" || !plainPath(to)) return null;
23
+ let decoded;
24
+ try {
25
+ decoded = decodeURIComponent(to);
26
+ } catch {
27
+ return null;
28
+ }
29
+ if (!plainPath(decoded)) return null;
30
+ return safeUrl(to, "href", { mediaOrigin: "" });
31
+ }
32
+
33
+ // src/next/index.ts
34
+ function slugOf(options, params) {
35
+ if ("slug" in options) return options.slug;
36
+ const value = params[options.fromParams];
37
+ const slug = Array.isArray(value) ? value.join("/") : value;
38
+ if (slug === void 0 || slug === "") notFound();
39
+ return slug;
40
+ }
41
+ async function localeOf(options, params) {
42
+ if (typeof options.locale === "function") return options.locale(params);
43
+ if (options.locale !== void 0) return options.locale;
44
+ const fromRoute = params.locale;
45
+ return typeof fromRoute === "string" ? fromRoute : "en";
46
+ }
47
+ function createBuilderPage(options) {
48
+ async function Page(props) {
49
+ const params = await props.params;
50
+ const slug = slugOf(options, params);
51
+ const loaded = await loadBuilderPage({
52
+ ...options,
53
+ slug,
54
+ locale: await localeOf(options, params)
55
+ }).catch((error) => {
56
+ if (error instanceof BuilderNotFoundError) notFound();
57
+ throw error;
58
+ });
59
+ if (loaded.kind === "redirect") {
60
+ const path = sitePath(loaded.redirectTo);
61
+ if (path === null) notFound();
62
+ permanentRedirect(path);
63
+ }
64
+ return createElement(BuilderPageView, { page: loaded });
65
+ }
66
+ async function generateMetadata(props) {
67
+ const params = await props.params;
68
+ const slug = slugOf(options, params);
69
+ const locale = await localeOf(options, params);
70
+ try {
71
+ const bundle = await getBundle({ client: clientOf(options), locale, page: slug, slots: options.slots });
72
+ const page = bundle.page;
73
+ if (page === void 0 || isRedirect(page)) return {};
74
+ const site = bundle.site.settings;
75
+ const seo = typeof site.seo === "object" && site.seo !== null ? site.seo : {};
76
+ const brand = typeof site.brand === "object" && site.brand !== null ? site.brand : {};
77
+ const template = typeof seo.titleTemplate === "string" ? seo.titleTemplate : "{page}";
78
+ const store = typeof brand.storeName === "string" ? brand.storeName : "";
79
+ const own = typeof page.description === "string" ? page.description : void 0;
80
+ const fallback = typeof seo.defaultDescription === "string" ? seo.defaultDescription : void 0;
81
+ const description = own ?? fallback;
82
+ return {
83
+ title: template.replace("{page}", page.title).replace("{store}", store),
84
+ ...description === void 0 || description === "" ? {} : { description }
85
+ };
86
+ } catch (error) {
87
+ if (error instanceof BuilderNotFoundError || error instanceof BuilderUnavailableError) return {};
88
+ throw error;
89
+ }
90
+ }
91
+ return { Page, generateMetadata };
92
+ }
93
+ export {
94
+ createBuilderPage
95
+ };
@@ -0,0 +1,74 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+ var _chunkRWDLDDSFcjs = require('./chunk-RWDLDDSF.cjs');
10
+
11
+ // src/server/load-site.ts
12
+ var _builder = require('@usethrottle/builder');
13
+ async function loadSite(options) {
14
+ const { locale, slots = [], packs = [], page, mediaOrigin = "" } = options;
15
+ const client = _chunkRWDLDDSFcjs.clientOf.call(void 0, options);
16
+ let bundle;
17
+ try {
18
+ bundle = await _chunkRWDLDDSFcjs.getBundle.call(void 0, { client, locale, slots, page });
19
+ } catch (error) {
20
+ if (!(error instanceof _builder.BuilderUnavailableError)) throw error;
21
+ _chunkRWDLDDSFcjs.warnOnce.call(void 0, "site-unavailable", `The Builder could not be read (${error.reason}); the store renders without its Builder header, footer and slots`);
22
+ return { status: "unavailable", locale };
23
+ }
24
+ const registry = _chunkRWDLDDSFcjs.createRendererRegistry.call(void 0, packs);
25
+ const names = Object.keys(bundle.slots);
26
+ const documents = [bundle.header.document, bundle.footer.document, ...names.map((n) => bundle.slots[n].document)];
27
+ const data = await _chunkRWDLDDSFcjs.staticDataFor.call(void 0, documents, registry, locale);
28
+ return {
29
+ status: "ok",
30
+ locale,
31
+ generation: bundle.generation,
32
+ siteVersion: bundle.site.siteVersion,
33
+ mediaOrigin,
34
+ settings: bundle.site.settings,
35
+ header: _chunkRWDLDDSFcjs.partOf.call(void 0, bundle.header, data),
36
+ footer: _chunkRWDLDDSFcjs.partOf.call(void 0, bundle.footer, data),
37
+ slots: Object.fromEntries(names.map((name) => [name, _chunkRWDLDDSFcjs.partOf.call(void 0, bundle.slots[name], data)]))
38
+ };
39
+ }
40
+
41
+ // src/server/sitemap.ts
42
+
43
+ async function builderSitemap(options) {
44
+ const client = _chunkRWDLDDSFcjs.clientOf.call(void 0, options);
45
+ try {
46
+ const pages = await client.pages.list();
47
+ let origin = options.storeUrl;
48
+ if (origin === void 0) {
49
+ const stored = (await client.site()).settings.storeUrl;
50
+ origin = typeof stored === "string" ? stored : void 0;
51
+ }
52
+ if (origin === void 0) {
53
+ _chunkRWDLDDSFcjs.warnOnce.call(void 0, "sitemap-origin", "builderSitemap needs a storeUrl: pass one, or set it in the Builder site settings");
54
+ return [];
55
+ }
56
+ const base = origin.replace(/\/+$/u, "");
57
+ return pages.map((page) => ({ url: `${base}${page.path}`, lastModified: new Date(page.updatedAt) }));
58
+ } catch (error) {
59
+ if (!(error instanceof _builder.BuilderUnavailableError)) throw error;
60
+ _chunkRWDLDDSFcjs.warnOnce.call(void 0, "sitemap-unavailable", `The Builder could not be read (${error.reason}); the sitemap leaves out its pages`);
61
+ return [];
62
+ }
63
+ }
64
+
65
+ // src/server/index.ts
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+ exports.BuilderNotFoundError = _builder.BuilderNotFoundError; exports.BuilderUnavailableError = _builder.BuilderUnavailableError; exports.builderSitemap = builderSitemap; exports.getBundle = _chunkRWDLDDSFcjs.getBundle; exports.loadBuilderPage = _chunkRWDLDDSFcjs.loadBuilderPage; exports.loadSite = loadSite;
@@ -0,0 +1,59 @@
1
+ import { C as ClientOptions, W as WidgetPack, b as LoadedSite, L as LoadedPage, a as LoadedRedirect } from './bundle-x5Vxd-xE.cjs';
2
+ export { B as BundleAsk, g as getBundle } from './bundle-x5Vxd-xE.cjs';
3
+ export { BuilderNotFoundError, BuilderUnavailableError } from '@usethrottle/builder';
4
+ import 'react';
5
+ import '@usethrottle/builder-schema';
6
+
7
+ type LoadSiteOptions = ClientOptions & {
8
+ locale: string;
9
+ /** The slots the store renders (`product.above`, `product.below`, `shop.above`, `shop.below`, ...). */
10
+ slots?: readonly string[];
11
+ /** The page this request renders, when the caller knows it, so its read is the same read. */
12
+ page?: string;
13
+ /**
14
+ * The origin Throttle serves public media from (`https://...`). Images on any
15
+ * other origin, or over http, are refused. Without it no image shows.
16
+ */
17
+ mediaOrigin?: string;
18
+ packs?: readonly WidgetPack[];
19
+ };
20
+ /**
21
+ * Reads the site design once for a request: settings, header, footer and the
22
+ * named slots, with the non-perShopper data of their widgets resolved.
23
+ *
24
+ * When the Builder cannot answer and there is no last good answer it returns
25
+ * `{ status: 'unavailable' }` and logs once per process: the store's header,
26
+ * footer and slots then render nothing and the catalog pages keep working
27
+ * (ruling R8). Any other error (a bad key, a programming error) is thrown.
28
+ */
29
+ declare function loadSite(options: LoadSiteOptions): Promise<LoadedSite>;
30
+
31
+ type LoadBuilderPageOptions = ClientOptions & {
32
+ slug: string;
33
+ locale: string;
34
+ packs?: readonly WidgetPack[];
35
+ /** The slots the layout reads, so this read can share the layout's. */
36
+ slots?: readonly string[];
37
+ };
38
+ /**
39
+ * Reads one published page for a request. Data of the page's non-perShopper
40
+ * sources is resolved here, each distinct binding once, into `initialData`;
41
+ * perShopper data is never read on the server and is not in the result.
42
+ *
43
+ * Rejects with `BuilderNotFoundError` for an unpublished page and
44
+ * `BuilderUnavailableError` when the Builder cannot answer: a page has no
45
+ * "render nothing" fallback, so the store's error boundary takes it.
46
+ */
47
+ declare function loadBuilderPage(options: LoadBuilderPageOptions): Promise<LoadedPage | LoadedRedirect>;
48
+
49
+ type BuilderSitemapOptions = ClientOptions & {
50
+ /** The store's origin (`https://shop.example.com`). Read from the site settings when omitted. */
51
+ storeUrl?: string;
52
+ };
53
+ /** The published pages as sitemap entries. An unavailable Builder gives an empty list, never a failed sitemap. */
54
+ declare function builderSitemap(options: BuilderSitemapOptions): Promise<{
55
+ url: string;
56
+ lastModified: Date;
57
+ }[]>;
58
+
59
+ export { type BuilderSitemapOptions, type LoadBuilderPageOptions, type LoadSiteOptions, LoadedPage, LoadedRedirect, LoadedSite, builderSitemap, loadBuilderPage, loadSite };
@@ -0,0 +1,59 @@
1
+ import { C as ClientOptions, W as WidgetPack, b as LoadedSite, L as LoadedPage, a as LoadedRedirect } from './bundle-x5Vxd-xE.js';
2
+ export { B as BundleAsk, g as getBundle } from './bundle-x5Vxd-xE.js';
3
+ export { BuilderNotFoundError, BuilderUnavailableError } from '@usethrottle/builder';
4
+ import 'react';
5
+ import '@usethrottle/builder-schema';
6
+
7
+ type LoadSiteOptions = ClientOptions & {
8
+ locale: string;
9
+ /** The slots the store renders (`product.above`, `product.below`, `shop.above`, `shop.below`, ...). */
10
+ slots?: readonly string[];
11
+ /** The page this request renders, when the caller knows it, so its read is the same read. */
12
+ page?: string;
13
+ /**
14
+ * The origin Throttle serves public media from (`https://...`). Images on any
15
+ * other origin, or over http, are refused. Without it no image shows.
16
+ */
17
+ mediaOrigin?: string;
18
+ packs?: readonly WidgetPack[];
19
+ };
20
+ /**
21
+ * Reads the site design once for a request: settings, header, footer and the
22
+ * named slots, with the non-perShopper data of their widgets resolved.
23
+ *
24
+ * When the Builder cannot answer and there is no last good answer it returns
25
+ * `{ status: 'unavailable' }` and logs once per process: the store's header,
26
+ * footer and slots then render nothing and the catalog pages keep working
27
+ * (ruling R8). Any other error (a bad key, a programming error) is thrown.
28
+ */
29
+ declare function loadSite(options: LoadSiteOptions): Promise<LoadedSite>;
30
+
31
+ type LoadBuilderPageOptions = ClientOptions & {
32
+ slug: string;
33
+ locale: string;
34
+ packs?: readonly WidgetPack[];
35
+ /** The slots the layout reads, so this read can share the layout's. */
36
+ slots?: readonly string[];
37
+ };
38
+ /**
39
+ * Reads one published page for a request. Data of the page's non-perShopper
40
+ * sources is resolved here, each distinct binding once, into `initialData`;
41
+ * perShopper data is never read on the server and is not in the result.
42
+ *
43
+ * Rejects with `BuilderNotFoundError` for an unpublished page and
44
+ * `BuilderUnavailableError` when the Builder cannot answer: a page has no
45
+ * "render nothing" fallback, so the store's error boundary takes it.
46
+ */
47
+ declare function loadBuilderPage(options: LoadBuilderPageOptions): Promise<LoadedPage | LoadedRedirect>;
48
+
49
+ type BuilderSitemapOptions = ClientOptions & {
50
+ /** The store's origin (`https://shop.example.com`). Read from the site settings when omitted. */
51
+ storeUrl?: string;
52
+ };
53
+ /** The published pages as sitemap entries. An unavailable Builder gives an empty list, never a failed sitemap. */
54
+ declare function builderSitemap(options: BuilderSitemapOptions): Promise<{
55
+ url: string;
56
+ lastModified: Date;
57
+ }[]>;
58
+
59
+ export { type BuilderSitemapOptions, type LoadBuilderPageOptions, type LoadSiteOptions, LoadedPage, LoadedRedirect, LoadedSite, builderSitemap, loadBuilderPage, loadSite };
package/dist/server.js ADDED
@@ -0,0 +1,74 @@
1
+ import {
2
+ clientOf,
3
+ createRendererRegistry,
4
+ getBundle,
5
+ loadBuilderPage,
6
+ partOf,
7
+ staticDataFor,
8
+ warnOnce
9
+ } from "./chunk-DRQNR5GN.js";
10
+
11
+ // src/server/load-site.ts
12
+ import { BuilderUnavailableError } from "@usethrottle/builder";
13
+ async function loadSite(options) {
14
+ const { locale, slots = [], packs = [], page, mediaOrigin = "" } = options;
15
+ const client = clientOf(options);
16
+ let bundle;
17
+ try {
18
+ bundle = await getBundle({ client, locale, slots, page });
19
+ } catch (error) {
20
+ if (!(error instanceof BuilderUnavailableError)) throw error;
21
+ warnOnce("site-unavailable", `The Builder could not be read (${error.reason}); the store renders without its Builder header, footer and slots`);
22
+ return { status: "unavailable", locale };
23
+ }
24
+ const registry = createRendererRegistry(packs);
25
+ const names = Object.keys(bundle.slots);
26
+ const documents = [bundle.header.document, bundle.footer.document, ...names.map((n) => bundle.slots[n].document)];
27
+ const data = await staticDataFor(documents, registry, locale);
28
+ return {
29
+ status: "ok",
30
+ locale,
31
+ generation: bundle.generation,
32
+ siteVersion: bundle.site.siteVersion,
33
+ mediaOrigin,
34
+ settings: bundle.site.settings,
35
+ header: partOf(bundle.header, data),
36
+ footer: partOf(bundle.footer, data),
37
+ slots: Object.fromEntries(names.map((name) => [name, partOf(bundle.slots[name], data)]))
38
+ };
39
+ }
40
+
41
+ // src/server/sitemap.ts
42
+ import { BuilderUnavailableError as BuilderUnavailableError2 } from "@usethrottle/builder";
43
+ async function builderSitemap(options) {
44
+ const client = clientOf(options);
45
+ try {
46
+ const pages = await client.pages.list();
47
+ let origin = options.storeUrl;
48
+ if (origin === void 0) {
49
+ const stored = (await client.site()).settings.storeUrl;
50
+ origin = typeof stored === "string" ? stored : void 0;
51
+ }
52
+ if (origin === void 0) {
53
+ warnOnce("sitemap-origin", "builderSitemap needs a storeUrl: pass one, or set it in the Builder site settings");
54
+ return [];
55
+ }
56
+ const base = origin.replace(/\/+$/u, "");
57
+ return pages.map((page) => ({ url: `${base}${page.path}`, lastModified: new Date(page.updatedAt) }));
58
+ } catch (error) {
59
+ if (!(error instanceof BuilderUnavailableError2)) throw error;
60
+ warnOnce("sitemap-unavailable", `The Builder could not be read (${error.reason}); the sitemap leaves out its pages`);
61
+ return [];
62
+ }
63
+ }
64
+
65
+ // src/server/index.ts
66
+ import { BuilderNotFoundError, BuilderUnavailableError as BuilderUnavailableError3 } from "@usethrottle/builder";
67
+ export {
68
+ BuilderNotFoundError,
69
+ BuilderUnavailableError3 as BuilderUnavailableError,
70
+ builderSitemap,
71
+ getBundle,
72
+ loadBuilderPage,
73
+ loadSite
74
+ };
package/package.json CHANGED
@@ -1,6 +1,98 @@
1
1
  {
2
2
  "name": "@usethrottle/builder-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Renders a published Throttle Builder page document as React in a merchant's store: responsive CSS, header, footer, slots and the site design provider.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "require": {
17
+ "types": "./dist/index.d.cts",
18
+ "default": "./dist/index.cjs"
19
+ }
20
+ },
21
+ "./server": {
22
+ "import": {
23
+ "types": "./dist/server.d.ts",
24
+ "default": "./dist/server.js"
25
+ },
26
+ "require": {
27
+ "types": "./dist/server.d.cts",
28
+ "default": "./dist/server.cjs"
29
+ }
30
+ },
31
+ "./next": {
32
+ "import": {
33
+ "types": "./dist/next.d.ts",
34
+ "default": "./dist/next.js"
35
+ },
36
+ "require": {
37
+ "types": "./dist/next.d.cts",
38
+ "default": "./dist/next.cjs"
39
+ }
40
+ },
41
+ "./package.json": "./package.json"
42
+ },
43
+ "files": [
44
+ "dist",
45
+ "CLAUDE.md"
46
+ ],
47
+ "sideEffects": false,
48
+ "engines": {
49
+ "node": ">=20"
50
+ },
51
+ "keywords": [
52
+ "throttle",
53
+ "usethrottle",
54
+ "builder",
55
+ "page-builder",
56
+ "react",
57
+ "nextjs"
58
+ ],
59
+ "dependencies": {
60
+ "@usethrottle/builder": "^0.1.0",
61
+ "@usethrottle/builder-schema": "^0.1.0",
62
+ "@usethrottle/ui": "^0.1.1"
63
+ },
64
+ "peerDependencies": {
65
+ "next": ">=15",
66
+ "react": ">=18",
67
+ "react-dom": ">=18"
68
+ },
69
+ "peerDependenciesMeta": {
70
+ "next": {
71
+ "optional": true
72
+ }
73
+ },
74
+ "devDependencies": {
75
+ "@testing-library/react": "^16.1.0",
76
+ "@types/node": "^20.0.0",
77
+ "@types/react": "^19.1.0",
78
+ "@types/react-dom": "^19.1.0",
79
+ "jsdom": "^25.0.1",
80
+ "next": "15.5.15",
81
+ "playwright": "^1.62.1",
82
+ "react": "19.2.5",
83
+ "react-dom": "19.2.5",
84
+ "tsup": "^8.0.0",
85
+ "typescript": "^5.7.0",
86
+ "vitest": "^2.1.9"
87
+ },
88
+ "publishConfig": {
89
+ "access": "public"
90
+ },
91
+ "scripts": {
92
+ "build": "tsup",
93
+ "dev": "node scripts/playground.mjs",
94
+ "test": "vitest run",
95
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
96
+ "size": "node scripts/size.mjs"
97
+ }
6
98
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.