@bettercms-ai/next 0.40.1 → 0.42.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/field.tsx","../src/image.tsx","../src/button.tsx","../src/icon.tsx","../src/field-attrs.ts","../src/section-root.ts"],"sourcesContent":["/**\n * <BcmsField> — tag an entry field's rendered value with its identity so the\n * BetterCMS visual editor can bind click-to-edit deterministically (mirrors\n * Sanity's `data-sanity` / BaseHub's `data-basehub`). Entry-backed templates\n * hand-render field values (`f.title`, `f.body.html`), so the field `path` is\n * declared here by the author — the delivery payload carries no source-map.\n *\n * Server-safe (no hooks): renders in a Next Server Component. When the child is ONE\n * DOM element (`<h1>`, `<p>`), the attributes go on that element and nothing is added to\n * the page: `.hero > h1` and every animation target stay what the author wrote. Text,\n * several children, or a component (which may not pass unknown props on) are wrapped in a\n * `display:contents` span as before; pass `as` to carry the attributes on a real wrapper.\n * Twin: BcmsField.astro in @bettercms-ai/astro.\n *\n * `path` follows the editor grammar: `title` · `hero.title` · `columns[0].links[2].href`\n * (dotted keys and any number of `[n]` indices). For images, put the attributes on the\n * `<img>` itself (`kind=\"image\"` reflection patches `.src`), not on a wrapper:\n * <img src={imageValueUrl(f.cover, { w: 1200 })} data-bcms-field=\"cover\" data-bcms-kind=\"image\" />\n * `imageValueUrl` (re-exported from this package) applies the value's per-placement `crop` and\n * `focal`; `.url` alone would drop them. For a cover-fit box add\n * `style={{ objectPosition: imageValueObjectPosition(f.cover) ?? undefined }}`.\n */\nimport { Children, cloneElement, isValidElement, type ElementType, type ReactElement, type ReactNode } from \"react\";\n\nexport interface BcmsFieldProps {\n /** Field path in the editor grammar, e.g. `title` or `facts[2].label`. */\n path: string;\n /** Kind hint the editor's reflection branches on. Omit for plain text/number. */\n kind?: \"richtext\" | \"image\";\n /** Wrapper element. Without it: no wrapper around a single DOM element, a `display:contents` span around anything else. */\n as?: ElementType;\n children: ReactNode;\n}\n\nexport function BcmsField({ path, kind, as, children }: BcmsFieldProps) {\n const Tag = as ?? \"span\";\n const only = as ? [] : Children.toArray(children);\n const sole = only.length === 1 && isValidElement(only[0]) && typeof only[0].type === \"string\" ? (only[0] as ReactElement<Record<string, unknown>>) : null;\n // An element that already declares a field keeps its own address: wrapped, as before.\n if (sole && sole.props[\"data-bcms-field\"] === undefined && sole.props[\"data-bcms-layout-field\"] === undefined) {\n return cloneElement(sole, { \"data-bcms-field\": path, \"data-bcms-kind\": kind });\n }\n return (\n <Tag\n data-bcms-field={path}\n data-bcms-kind={kind}\n style={as ? undefined : { display: \"contents\" }}\n >\n {children}\n </Tag>\n );\n}\n","/**\n * <BcmsImage> — render an image field as one responsive `<img>` on the BetterCMS media transform\n * endpoint, declared so the visual editor binds it and a publish writes the new picture into it.\n * The same markup as the Astro SDK's <BcmsImage>.\n *\n * <BcmsImage path=\"hero.image\" src={page.hero.image} sizes=\"(min-width: 800px) 50vw, 100vw\" />\n *\n * `src` is an image VALUE (`{ url, altText, width?, focal?, crop? }`), a media url or an asset id.\n * The value's per-placement crop and focal point ride every url, and the focal point is also the\n * `object-position` (inert without `object-fit`). With `sizes` and no `width` the srcset is a WIDTH\n * ladder, never wider than the picture; with a pixel `width` it is 1x/2x. The value's `altText` is\n * the alt unless `alt` says otherwise. Any other prop reaches the `<img>` as written.\n *\n * A plain `<img>`, deliberately: `next/image` refuses a remote host the app has not allow-listed,\n * so an editor's replacement would break the build. Server-safe (no hooks).\n */\nimport type { ImageFit, ImageFormat, ImageSource } from \"@bettercms-ai/image-url\";\nimport { imageCore } from \"@bettercms-ai/sdk/bindings\";\nimport type { CSSProperties, ImgHTMLAttributes } from \"react\";\n\n/** What delivery adds to an image value beside its url: the facts this component reads. */\ntype ImageFacts = { altText?: string | null; alt?: string | null; width?: number | null; height?: number | null; focalX?: number | null; focalY?: number | null };\n\nexport interface BcmsImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, \"src\" | \"srcSet\" | \"width\" | \"height\"> {\n src: ImageSource | (Exclude<ImageSource, string> & ImageFacts);\n /** The field this image renders, in the editor grammar (`cover`, `hero.image`). */\n path?: string;\n width?: number;\n height?: number;\n format?: ImageFormat;\n quality?: number;\n fit?: ImageFit;\n /** Focal point override, 0–1. Normally omitted: the value and the asset carry their own. */\n focalX?: number | null;\n focalY?: number | null;\n /** Media host for a `src` that is only an asset id. Defaults to the platform's. */\n baseUrl?: string;\n}\n\n/** The widths a `sizes` image offers: phone to desktop, and never an upscale of the picture. */\nexport function BcmsImage({\n src,\n path,\n alt,\n width,\n height,\n format = \"webp\",\n quality,\n fit,\n sizes,\n loading = \"lazy\",\n focalX,\n focalY,\n baseUrl,\n style,\n ...rest\n}: BcmsImageProps) {\n const { src: src1x, srcset: srcSet, alt: resolvedAlt, css } = imageCore(src, { alt, width, height, format, quality, fit, sizes, focalX, focalY, baseUrl });\n const merged: CSSProperties = { ...css, ...style };\n\n return (\n <img\n src={src1x}\n srcSet={srcSet}\n alt={resolvedAlt}\n data-bcms-field={path}\n data-bcms-kind={path ? \"image\" : undefined}\n width={width}\n height={height}\n sizes={sizes}\n loading={loading}\n style={Object.keys(merged).length > 0 ? merged : undefined}\n {...rest}\n />\n );\n}\n","/**\n * <BcmsButton> — render a `button` field ({ label, href, variant?, size?, arrow?, icon?,\n * newTab?, fullWidth? }) as one editable button, with the hooks the BetterCMS visual editor repaints and\n * in-place publishing writes. The same markup as the Astro SDK's <BcmsButton>:\n *\n * <a data-bcms-button=\"<path>\" data-variant data-size [data-full-width] href [target rel] data-bcms-props=\"<path>.href|url|href\">\n * [<svg class=\"bcms-btn-icon\">]<span data-bcms-field=\"<path>.label\">Label</span>[<svg class=\"bcms-btn-arrow\">]\n * </a>\n *\n * A value with `action: \"code\"` (no href: the site's script handles the click) renders the same\n * children in `<button type=\"button\" data-bcms-button=\"<path>\" data-variant data-size>`.\n *\n * Style it by `data-variant` and `data-size` in your own CSS. A full-width button also carries\n * `display:flex;width:100%;justify-content:center` inline, so it stretches with no rule of yours.\n * Server-safe (no hooks).\n *\n * <BcmsButton path=\"hero.cta\" value={page.hero.cta} className=\"btn\" />\n */\nimport { formatPropsAttribute, readButtonValue } from \"@bettercms-ai/types\";\nimport { ICON_MARKUP, ICON_VIEWBOX } from \"@bettercms-ai/icons/markup\";\n\n/**\n * One icon as an `<svg>` drawn from the markup table the block renderer already ships, so a button\n * costs no per-icon module: the icon map pulled every icon into a client bundle.\n */\nconst ButtonIcon = ({ name, className }: { name: keyof typeof ICON_MARKUP; className: string }) => (\n <svg data-bcms-icon={name} className={className} viewBox={ICON_VIEWBOX} width=\"1em\" height=\"1em\" fill=\"none\" aria-hidden focusable=\"false\" dangerouslySetInnerHTML={{ __html: ICON_MARKUP[name] }} />\n);\n\n/** A full-width button stretches across its column, label centred: the hosted renderer's `bcms-btn-full`. */\nconst FULL_WIDTH_STYLE = { display: \"flex\", width: \"100%\", justifyContent: \"center\" } as const;\n\nexport interface BcmsButtonProps {\n /** The field path in the editor grammar, e.g. `cta` or `hero.cta`. */\n path: string;\n /** The stored value. Missing keys render as the defaults (Primary, medium, no arrow, no icon). */\n value: unknown;\n className?: string;\n}\n\nexport function BcmsButton({ path, value, className }: BcmsButtonProps) {\n const b = readButtonValue(value);\n if (!b.label) return null;\n const content = (\n <>\n {/* Direct children of the root, as the editor and in-place publishing find them. */}\n {b.icon && <ButtonIcon name={b.icon} className=\"bcms-btn-icon\" />}\n <span data-bcms-field={`${path}.label`} data-bcms-kind=\"text\">\n {b.label}\n </span>\n {b.arrow && <ButtonIcon name=\"arrow-right\" className=\"bcms-btn-arrow\" />}\n </>\n );\n // `action: \"code\"`: your own handler owns the click (delegate on `[data-bcms-button]`), so no href.\n if (b.action === \"code\") {\n return (\n <button type=\"button\" className={className} data-bcms-button={path} data-variant={b.variant} data-size={b.size} {...(b.fullWidth ? { \"data-full-width\": \"\", style: FULL_WIDTH_STYLE } : {})}>\n {content}\n </button>\n );\n }\n return (\n <a\n className={className}\n href={b.href || \"#\"}\n data-bcms-button={path}\n data-variant={b.variant}\n data-size={b.size}\n {...(b.fullWidth ? { \"data-full-width\": \"\", style: FULL_WIDTH_STYLE } : {})}\n data-bcms-props={formatPropsAttribute([{ address: `${path}.href`, kind: \"url\", attr: \"href\" }])}\n {...(b.newTab ? { target: \"_blank\", rel: \"noopener noreferrer\" } : {})}\n >\n {content}\n </a>\n );\n}\n","/**\n * <BcmsIcon> — render an `icon` field's value (V2 D65), every stored form:\n *\n * a set name → <svg data-bcms-icon=\"name\">, from the markup table the block renderer ships\n * a library icon that → <span data-bcms-icon-url> masked in the text colour (it recolours with the text)\n * follows the text\n * any other url → <img> (a multicolour SVG or an image keeps its colours)\n *\n * A `label` makes the icon an image with that name; without one it is decorative (aria-hidden). Server-safe (no hooks).\n *\n * <BcmsIcon value={card.icon} className=\"size-5\" />\n */\nimport { iconSrc } from \"@bettercms-ai/types\";\nimport { ICON_MARKUP, ICON_VIEWBOX } from \"@bettercms-ai/icons/markup\";\n\nexport interface BcmsIconProps {\n /** The stored icon value: a set name, an image URL or an icon object. */\n value: unknown;\n className?: string;\n}\n\nexport function BcmsIcon({ value, className }: BcmsIconProps) {\n const src = iconSrc(value);\n if (!src) return null;\n const a11y = src.label ? { role: \"img\", \"aria-label\": src.label } : { \"aria-hidden\": true as const };\n if (\"name\" in src) {\n const markup = (ICON_MARKUP as Record<string, string>)[src.name];\n if (!markup) return null;\n return <svg data-bcms-icon={src.name} className={className} viewBox={ICON_VIEWBOX} width=\"1em\" height=\"1em\" fill=\"none\" focusable=\"false\" {...a11y} dangerouslySetInnerHTML={{ __html: markup }} />;\n }\n if (src.followsText) {\n const mask = `url(${JSON.stringify(src.url)}) center / contain no-repeat`;\n return <span data-bcms-icon-url={src.url} className={className} style={{ display: \"inline-block\", width: \"1em\", height: \"1em\", backgroundColor: \"currentColor\", mask, WebkitMask: mask }} {...a11y} />;\n }\n return <img src={src.url} alt={src.label ?? \"\"} className={className} width={16} height={16} style={{ width: \"1em\", height: \"1em\", objectFit: \"contain\" }} />;\n}\n","/**\n * C3 — `fieldAttrs(path, fieldStyles)`: the props a site's OWN element spreads to bind a PAGE FIELD\n * and apply that field's stored style, so the BetterCMS editor offers its width and spacing handles\n * and its Align / Size / Weight controls.\n *\n * const page = await client.getPage(\"home\");\n * <h1 className=\"title\" {...fieldAttrs(\"hero-title\", page?.fieldStyles)}>{entry.data[\"hero-title\"]}</h1>\n *\n * `data-bcms-style` is the site's promise that \"this element's inline style is\n * `fieldStyleToCss(fieldStyles[path])`\"; the editor offers a field's handles only where it is\n * present. Present even when the field has no style (then there is no `style` prop at all).\n * Twin: `fieldAttrs` in @bettercms-ai/astro (a CSS string there).\n */\nimport type { CSSProperties } from \"react\";\nimport { fieldStyleToCss, type FieldStyle, type FieldStyles } from \"@bettercms-ai/types\";\n\nexport interface FieldAttrs {\n \"data-bcms-field\": string;\n /** The marker's revision: \"2\" promises `size` (zoom) too. Section roots keep \"\". */\n \"data-bcms-style\": \"2\";\n /** `fieldStyleToCss(fieldStyles[path])`; absent when the field has no style. */\n style?: CSSProperties;\n}\n\n/** The stored style for `path`, by OWN key only — a path like `constructor` never reads the prototype. */\nexport function fieldStyleOf(path: string, fieldStyles: FieldStyles | Record<string, unknown> | null | undefined): FieldStyle | undefined {\n if (!fieldStyles || typeof fieldStyles !== \"object\" || !Object.prototype.hasOwnProperty.call(fieldStyles, path)) return undefined;\n const style = (fieldStyles as Record<string, unknown>)[path];\n return style && typeof style === \"object\" ? (style as FieldStyle) : undefined;\n}\n\nexport function fieldAttrs(path: string, fieldStyles?: FieldStyles | Record<string, unknown> | null): FieldAttrs {\n const css = fieldStyleToCss(fieldStyleOf(path, fieldStyles));\n return { \"data-bcms-field\": path, \"data-bcms-style\": \"2\", ...(css ? { style: css as CSSProperties } : {}) };\n}\n\n/**\n * P7 — `entryAttrs(entry)` and `entryField(entry, path)`: the attributes a site's OWN card spreads to\n * declare a collection ENTRY, so the editor binds it without guessing from the rendered text.\n *\n * <article {...entryAttrs(post)}><h3 {...entryField(post, \"title\")}>{post.fields.title}</h3></article>\n *\n * The field address is ABSOLUTE (`entry:<id>:<path>`). With a `transform` the value is shown\n * changed (a date formatted, text truncated), so it is declared as `data-bcms-entry-from`: the\n * editor knows where it is but cannot re-render it. Twin: same helpers in @bettercms-ai/astro.\n */\nexport type EntryRef = { id?: string } | string;\nexport type EntryTransform = \"format\" | \"truncate\" | \"rendition\" | \"route\";\n/** One key is present: `data-bcms-entry-field`, or `data-bcms-entry-from` when transformed; none without an id. */\nexport interface EntryFieldAttrs {\n \"data-bcms-entry-field\"?: string;\n \"data-bcms-entry-from\"?: string;\n}\n\nfunction entryIdOf(entry: EntryRef): string | null {\n const id = typeof entry === \"string\" ? entry : entry?.id;\n return typeof id === \"string\" && id.trim() !== \"\" ? id : null;\n}\n\n/** An entry with no id (a snapshot written before ids were kept) renders unbound, never fails the build. */\nexport function entryAttrs(entry: EntryRef): { \"data-bcms-entry\"?: string } {\n const id = entryIdOf(entry);\n return id ? { \"data-bcms-entry\": id } : {};\n}\n\nexport function entryField(entry: EntryRef, path: string, opts?: { transform?: EntryTransform }): EntryFieldAttrs {\n const id = entryIdOf(entry);\n if (typeof path !== \"string\" || path.trim() === \"\") throw new Error(`entryField: no field path given for entry ${id ?? \"(no id)\"}`);\n if (!id) return {};\n const address = `entry:${id}:${path}`;\n return opts?.transform ? { \"data-bcms-entry-from\": `${address}|${opts.transform}` } : { \"data-bcms-entry-field\": address };\n}\n","/**\n * C3/C4 — `sectionRootAttrs(block)`: the props a site's OWN section root spreads so the\n * BetterCMS editor offers that section's spacing and style handles.\n *\n * <section className=\"hero\" {...sectionRootAttrs(block)}>…</section>\n *\n * The editor shows those handles on a site-rendered page only when EVERY root the site stamps\n * with `data-bcms-block` also carries `data-bcms-style`, which is the site's promise that \"this\n * root's inline style is `blockStyleToCss(block.style)`\" — the same declarations `<BcmsBlocks>`\n * puts on its own wrapper. The marker is present even when the style is EMPTY (then there is no\n * `style` prop at all): an unstyled section is the one an author is about to give its first\n * spacing edit. Twin: `sectionRootAttrs` in @bettercms-ai/astro (style as a string there).\n */\nimport type { CSSProperties } from \"react\";\nimport { blockStyleToColumnCss, blockStyleToCss, hideOnAttr, type BlockStyle } from \"@bettercms-ai/types\";\n\nexport interface SectionRootBlock {\n id?: string | null;\n style?: BlockStyle | Record<string, unknown> | null;\n}\n\nexport interface SectionRootAttrs {\n \"data-bcms-block\"?: string;\n \"data-bcms-style\": \"\";\n /** `\"mobile tablet\"` when `style.hideOn` hides it there; the site ships `RESPONSIVE_CSS` for it. */\n \"data-bcms-hide\"?: string;\n /** `blockStyleToCss(block.style)`; absent when the block has no style. */\n style?: CSSProperties;\n}\n\nexport function sectionRootAttrs(block: SectionRootBlock | null | undefined): SectionRootAttrs {\n const css = blockStyleToCss((block?.style ?? undefined) as BlockStyle | undefined);\n const id = typeof block?.id === \"string\" && block.id !== \"\" ? block.id : undefined;\n const hide = hideOnAttr(block?.style);\n return {\n ...(id !== undefined ? { \"data-bcms-block\": id } : {}),\n \"data-bcms-style\": \"\",\n ...(hide ? { \"data-bcms-hide\": hide } : {}),\n ...(css ? { style: css as CSSProperties } : {}),\n };\n}\n\nexport interface SectionColumnAttrs {\n \"data-bcms-column\": \"\";\n /** `blockStyleToColumnCss(block.style)`; absent when the section has no column. */\n style?: CSSProperties;\n}\n\n/**\n * C3 — `sectionColumnAttrs(block)`: the props a site's own INNER container spreads so the section's\n * content WIDTH ships (`style.contentWidth`, placed by `contentAlign`). The column BetterCMS draws as\n * `.bcms-block-inner`, never on the root (its background stays full-bleed); `data-bcms-column` is the\n * site's promise that this box's inline style is that column. Twin: @bettercms-ai/astro.\n */\nexport function sectionColumnAttrs(block: SectionRootBlock | null | undefined): SectionColumnAttrs {\n const css = blockStyleToColumnCss((block?.style ?? undefined) as BlockStyle | undefined);\n return { \"data-bcms-column\": \"\", ...(css ? { style: css as CSSProperties } : {}) };\n}\n"],"mappings":";AAsBA,SAAS,UAAU,cAAc,sBAA2E;AAqBxG;AATG,S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AAO,KAAK,MAAM,KAAK;AACzE,QAAM,OAAO,WAAW,OAAO,KAAK;AACpC,SAAO;AAAA,IACL,GAAI,OAAO,SAAY,EAAE,mBAAmB,GAAG,IAAI,CAAC;AAAA,IACpD,mBAAmB;AAAA,IACnB,GAAI,OAAO,EAAE,kBAAkB,KAAK,IAAI,CAAC;AAAA,IACzC,GAAI,MAAM,EAAE,OAAO,IAAqB,IAAI,CAAC;AAAA,EAC/C;AACF;AAcO,SAAS,mBAAmB,OAAgE;AACjG,QAAM,MAAM,sBAAuB,OAAO,SAAS,MAAoC;AACvF,SAAO,EAAE,oBAAoB,IAAI,GAAI,MAAM,EAAE,OAAO,IAAqB,IAAI,CAAC,EAAG;AACnF;","names":["jsx","jsx","ICON_MARKUP","ICON_VIEWBOX","jsx"]}
1
+ {"version":3,"sources":["../src/field.tsx","../src/image.tsx","../src/button.tsx","../src/icon.tsx","../src/field-attrs.ts","../src/section-root.ts"],"sourcesContent":["/**\n * <BcmsField> — tag an entry field's rendered value with its identity so the\n * BetterCMS visual editor can bind click-to-edit deterministically (mirrors\n * Sanity's `data-sanity` / BaseHub's `data-basehub`). Entry-backed templates\n * hand-render field values (`f.title`, `f.body.html`), so the field `path` is\n * declared here by the author — the delivery payload carries no source-map.\n *\n * Server-safe (no hooks): renders in a Next Server Component. When the child is ONE\n * DOM element (`<h1>`, `<p>`), the attributes go on that element and nothing is added to\n * the page: `.hero > h1` and every animation target stay what the author wrote. Text,\n * several children, or a component (which may not pass unknown props on) are wrapped in a\n * `display:contents` span as before; pass `as` to carry the attributes on a real wrapper.\n * Twin: BcmsField.astro in @bettercms-ai/astro.\n *\n * `path` follows the editor grammar: `title` · `hero.title` · `columns[0].links[2].href`\n * (dotted keys and any number of `[n]` indices). For images, put the attributes on the\n * `<img>` itself (`kind=\"image\"` reflection patches `.src`), not on a wrapper:\n * <img src={imageValueUrl(f.cover, { w: 1200 })} data-bcms-field=\"cover\" data-bcms-kind=\"image\" />\n * `imageValueUrl` (re-exported from this package) applies the value's per-placement `crop` and\n * `focal`; `.url` alone would drop them. For a cover-fit box add\n * `style={{ objectPosition: imageValueObjectPosition(f.cover) ?? undefined }}`.\n */\nimport { Children, cloneElement, isValidElement, type ElementType, type ReactElement, type ReactNode } from \"react\";\n\nexport interface BcmsFieldProps {\n /** Field path in the editor grammar, e.g. `title` or `facts[2].label`. */\n path: string;\n /** Kind hint the editor's reflection branches on. Omit for plain text/number. */\n kind?: \"richtext\" | \"image\";\n /** Wrapper element. Without it: no wrapper around a single DOM element, a `display:contents` span around anything else. */\n as?: ElementType;\n children: ReactNode;\n}\n\nexport function BcmsField({ path, kind, as, children }: BcmsFieldProps) {\n const Tag = as ?? \"span\";\n const only = as ? [] : Children.toArray(children);\n const sole = only.length === 1 && isValidElement(only[0]) && typeof only[0].type === \"string\" ? (only[0] as ReactElement<Record<string, unknown>>) : null;\n // An element that already declares a field keeps its own address: wrapped, as before.\n if (sole && sole.props[\"data-bcms-field\"] === undefined && sole.props[\"data-bcms-layout-field\"] === undefined) {\n return cloneElement(sole, { \"data-bcms-field\": path, \"data-bcms-kind\": kind });\n }\n return (\n <Tag\n data-bcms-field={path}\n data-bcms-kind={kind}\n style={as ? undefined : { display: \"contents\" }}\n >\n {children}\n </Tag>\n );\n}\n","/**\n * <BcmsImage> — render an image field as one responsive `<img>` on the BetterCMS media transform\n * endpoint, declared so the visual editor binds it and a publish writes the new picture into it.\n * The same markup as the Astro SDK's <BcmsImage>.\n *\n * <BcmsImage path=\"hero.image\" src={page.hero.image} sizes=\"(min-width: 800px) 50vw, 100vw\" />\n *\n * `src` is an image VALUE (`{ url, altText, width?, focal?, crop? }`), a media url or an asset id.\n * The value's per-placement crop and focal point ride every url, and the focal point is also the\n * `object-position` (inert without `object-fit`). With `sizes` and no `width` the srcset is a WIDTH\n * ladder, never wider than the picture; with a pixel `width` it is 1x/2x. The value's `altText` is\n * the alt unless `alt` says otherwise. Any other prop reaches the `<img>` as written.\n *\n * A plain `<img>`, deliberately: `next/image` refuses a remote host the app has not allow-listed,\n * so an editor's replacement would break the build. Server-safe (no hooks).\n */\nimport type { ImageFit, ImageFormat, ImageSource } from \"@bettercms-ai/image-url\";\nimport { imageCore } from \"@bettercms-ai/sdk/bindings\";\nimport type { CSSProperties, ImgHTMLAttributes } from \"react\";\n\n/** What delivery adds to an image value beside its url: the facts this component reads. */\ntype ImageFacts = { altText?: string | null; alt?: string | null; width?: number | null; height?: number | null; focalX?: number | null; focalY?: number | null };\n\nexport interface BcmsImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, \"src\" | \"srcSet\" | \"width\" | \"height\"> {\n src: ImageSource | (Exclude<ImageSource, string> & ImageFacts);\n /** The field this image renders, in the editor grammar (`cover`, `hero.image`). */\n path?: string;\n width?: number;\n height?: number;\n format?: ImageFormat;\n quality?: number;\n fit?: ImageFit;\n /** Focal point override, 0–1. Normally omitted: the value and the asset carry their own. */\n focalX?: number | null;\n focalY?: number | null;\n /** Media host for a `src` that is only an asset id. Defaults to the platform's. */\n baseUrl?: string;\n}\n\n/** The widths a `sizes` image offers: phone to desktop, and never an upscale of the picture. */\nexport function BcmsImage({\n src,\n path,\n alt,\n width,\n height,\n format = \"webp\",\n quality,\n fit,\n sizes,\n loading = \"lazy\",\n focalX,\n focalY,\n baseUrl,\n style,\n ...rest\n}: BcmsImageProps) {\n const { src: src1x, srcset: srcSet, alt: resolvedAlt, css } = imageCore(src, { alt, width, height, format, quality, fit, sizes, focalX, focalY, baseUrl });\n const merged: CSSProperties = { ...css, ...style };\n\n return (\n <img\n src={src1x}\n srcSet={srcSet}\n alt={resolvedAlt}\n data-bcms-field={path}\n data-bcms-kind={path ? \"image\" : undefined}\n width={width}\n height={height}\n sizes={sizes}\n loading={loading}\n style={Object.keys(merged).length > 0 ? merged : undefined}\n {...rest}\n />\n );\n}\n","/**\n * <BcmsButton> — render a `button` field ({ label, href, variant?, size?, arrow?, icon?,\n * newTab?, fullWidth? }) as one editable button, with the hooks the BetterCMS visual editor repaints and\n * in-place publishing writes. The same markup as the Astro SDK's <BcmsButton>:\n *\n * <a data-bcms-button=\"<path>\" data-variant data-size [data-full-width] href [target rel] data-bcms-props=\"<path>.href|url|href\">\n * [<svg class=\"bcms-btn-icon\">]<span data-bcms-field=\"<path>.label\">Label</span>[<svg class=\"bcms-btn-arrow\">]\n * </a>\n *\n * A value with `action: \"code\"` (no href: the site's script handles the click) renders the same\n * children in `<button type=\"button\" data-bcms-button=\"<path>\" data-variant data-size>`.\n *\n * Style it by `data-variant` and `data-size` in your own CSS. A full-width button also carries\n * `display:flex;width:100%;justify-content:center` inline, so it stretches with no rule of yours.\n * Server-safe (no hooks).\n *\n * <BcmsButton path=\"hero.cta\" value={page.hero.cta} className=\"btn\" />\n */\nimport { formatPropsAttribute, readButtonValue } from \"@bettercms-ai/types\";\nimport { ICON_MARKUP, ICON_VIEWBOX } from \"@bettercms-ai/icons/markup\";\n\n/**\n * One icon as an `<svg>` drawn from the markup table the block renderer already ships, so a button\n * costs no per-icon module: the icon map pulled every icon into a client bundle.\n */\nconst ButtonIcon = ({ name, className }: { name: keyof typeof ICON_MARKUP; className: string }) => (\n <svg data-bcms-icon={name} className={className} viewBox={ICON_VIEWBOX} width=\"1em\" height=\"1em\" fill=\"none\" aria-hidden focusable=\"false\" dangerouslySetInnerHTML={{ __html: ICON_MARKUP[name] }} />\n);\n\n/** A full-width button stretches across its column, label centred: the hosted renderer's `bcms-btn-full`. */\nconst FULL_WIDTH_STYLE = { display: \"flex\", width: \"100%\", justifyContent: \"center\" } as const;\n\nexport interface BcmsButtonProps {\n /** The field path in the editor grammar, e.g. `cta` or `hero.cta`. */\n path: string;\n /** The stored value. Missing keys render as the defaults (Primary, medium, no arrow, no icon). */\n value: unknown;\n className?: string;\n}\n\nexport function BcmsButton({ path, value, className }: BcmsButtonProps) {\n const b = readButtonValue(value);\n if (!b.label) return null;\n const content = (\n <>\n {/* Direct children of the root, as the editor and in-place publishing find them. */}\n {b.icon && <ButtonIcon name={b.icon} className=\"bcms-btn-icon\" />}\n <span data-bcms-field={`${path}.label`} data-bcms-kind=\"text\">\n {b.label}\n </span>\n {b.arrow && <ButtonIcon name=\"arrow-right\" className=\"bcms-btn-arrow\" />}\n </>\n );\n // `action: \"code\"`: your own handler owns the click (delegate on `[data-bcms-button]`), so no href.\n if (b.action === \"code\") {\n return (\n <button type=\"button\" className={className} data-bcms-button={path} data-variant={b.variant} data-size={b.size} {...(b.fullWidth ? { \"data-full-width\": \"\", style: FULL_WIDTH_STYLE } : {})}>\n {content}\n </button>\n );\n }\n return (\n <a\n className={className}\n href={b.href || \"#\"}\n data-bcms-button={path}\n data-variant={b.variant}\n data-size={b.size}\n {...(b.fullWidth ? { \"data-full-width\": \"\", style: FULL_WIDTH_STYLE } : {})}\n data-bcms-props={formatPropsAttribute([{ address: `${path}.href`, kind: \"url\", attr: \"href\" }])}\n {...(b.newTab ? { target: \"_blank\", rel: \"noopener noreferrer\" } : {})}\n >\n {content}\n </a>\n );\n}\n","/**\n * <BcmsIcon> — render an `icon` field's value (V2 D65), every stored form:\n *\n * a set name → <svg data-bcms-icon=\"name\">, from the markup table the block renderer ships\n * a library icon that → <span data-bcms-icon-url> masked in the text colour (it recolours with the text)\n * follows the text\n * any other url → <img> (a multicolour SVG or an image keeps its colours)\n *\n * A `label` makes the icon an image with that name; without one it is decorative (aria-hidden). Server-safe (no hooks).\n *\n * <BcmsIcon value={card.icon} className=\"size-5\" />\n */\nimport { iconSrc } from \"@bettercms-ai/types\";\nimport { ICON_MARKUP, ICON_VIEWBOX } from \"@bettercms-ai/icons/markup\";\n\nexport interface BcmsIconProps {\n /** The stored icon value: a set name, an image URL or an icon object. */\n value: unknown;\n className?: string;\n}\n\nexport function BcmsIcon({ value, className }: BcmsIconProps) {\n const src = iconSrc(value);\n if (!src) return null;\n const a11y = src.label ? { role: \"img\", \"aria-label\": src.label } : { \"aria-hidden\": true as const };\n if (\"name\" in src) {\n const markup = (ICON_MARKUP as Record<string, string>)[src.name];\n if (!markup) return null;\n return <svg data-bcms-icon={src.name} className={className} viewBox={ICON_VIEWBOX} width=\"1em\" height=\"1em\" fill=\"none\" focusable=\"false\" {...a11y} dangerouslySetInnerHTML={{ __html: markup }} />;\n }\n if (src.followsText) {\n const mask = `url(${JSON.stringify(src.url)}) center / contain no-repeat`;\n return <span data-bcms-icon-url={src.url} className={className} style={{ display: \"inline-block\", width: \"1em\", height: \"1em\", backgroundColor: \"currentColor\", mask, WebkitMask: mask }} {...a11y} />;\n }\n return <img src={src.url} alt={src.label ?? \"\"} className={className} width={16} height={16} style={{ width: \"1em\", height: \"1em\", objectFit: \"contain\" }} />;\n}\n","/**\n * C3 — `fieldAttrs(path, fieldStyles)`: the props a site's OWN element spreads to bind a PAGE FIELD\n * and apply that field's stored style, so the BetterCMS editor offers its width and spacing handles\n * and its Align / Size / Weight controls.\n *\n * const page = await client.getPage(\"home\");\n * <h1 className=\"title\" {...fieldAttrs(\"hero-title\", page?.fieldStyles)}>{entry.data[\"hero-title\"]}</h1>\n *\n * `data-bcms-style` is the site's promise that \"this element's inline style is\n * `fieldStyleToCss(fieldStyles[path])`\"; the editor offers a field's handles only where it is\n * present. Present even when the field has no style (then there is no `style` prop at all).\n * Twin: `fieldAttrs` in @bettercms-ai/astro (a CSS string there).\n */\nimport type { CSSProperties } from \"react\";\nimport { fieldStyleToCss, type FieldStyle, type FieldStyles } from \"@bettercms-ai/types\";\n\nexport interface FieldAttrs {\n \"data-bcms-field\": string;\n /** The marker's revision: \"2\" promises `size` (zoom) too. Section roots keep \"\". */\n \"data-bcms-style\": \"2\";\n /** `fieldStyleToCss(fieldStyles[path])`; absent when the field has no style. */\n style?: CSSProperties;\n}\n\n/** The stored style for `path`, by OWN key only — a path like `constructor` never reads the prototype. */\nexport function fieldStyleOf(path: string, fieldStyles: FieldStyles | Record<string, unknown> | null | undefined): FieldStyle | undefined {\n if (!fieldStyles || typeof fieldStyles !== \"object\" || !Object.prototype.hasOwnProperty.call(fieldStyles, path)) return undefined;\n const style = (fieldStyles as Record<string, unknown>)[path];\n return style && typeof style === \"object\" ? (style as FieldStyle) : undefined;\n}\n\nexport function fieldAttrs(path: string, fieldStyles?: FieldStyles | Record<string, unknown> | null): FieldAttrs {\n const css = fieldStyleToCss(fieldStyleOf(path, fieldStyles));\n return { \"data-bcms-field\": path, \"data-bcms-style\": \"2\", ...(css ? { style: css as CSSProperties } : {}) };\n}\n\n/**\n * P7 — `entryAttrs(entry)` and `entryField(entry, path)`: the attributes a site's OWN card spreads to\n * declare a collection ENTRY, so the editor binds it without guessing from the rendered text.\n *\n * <article {...entryAttrs(post)}><h3 {...entryField(post, \"title\")}>{post.fields.title}</h3></article>\n *\n * The field address is ABSOLUTE (`entry:<id>:<path>`). With a `transform` the value is shown\n * changed (a date formatted, text truncated), so it is declared as `data-bcms-entry-from`: the\n * editor knows where it is but cannot re-render it. Twin: same helpers in @bettercms-ai/astro.\n */\nexport type EntryRef = { id?: string } | string;\nexport type EntryTransform = \"format\" | \"truncate\" | \"rendition\" | \"route\";\n/** One key is present: `data-bcms-entry-field`, or `data-bcms-entry-from` when transformed; none without an id. */\nexport interface EntryFieldAttrs {\n \"data-bcms-entry-field\"?: string;\n \"data-bcms-entry-from\"?: string;\n}\n\nfunction entryIdOf(entry: EntryRef): string | null {\n const id = typeof entry === \"string\" ? entry : entry?.id;\n return typeof id === \"string\" && id.trim() !== \"\" ? id : null;\n}\n\n/** An entry with no id (a snapshot written before ids were kept) renders unbound, never fails the build. */\nexport function entryAttrs(entry: EntryRef): { \"data-bcms-entry\"?: string } {\n const id = entryIdOf(entry);\n return id ? { \"data-bcms-entry\": id } : {};\n}\n\nexport function entryField(entry: EntryRef, path: string, opts?: { transform?: EntryTransform }): EntryFieldAttrs {\n const id = entryIdOf(entry);\n if (typeof path !== \"string\" || path.trim() === \"\") throw new Error(`entryField: no field path given for entry ${id ?? \"(no id)\"}`);\n if (!id) return {};\n const address = `entry:${id}:${path}`;\n return opts?.transform ? { \"data-bcms-entry-from\": `${address}|${opts.transform}` } : { \"data-bcms-entry-field\": address };\n}\n","/**\n * C3/C4 — `sectionRootAttrs(block)`: the props a site's OWN section root spreads so the\n * BetterCMS editor offers that section's spacing and style handles.\n *\n * <section className=\"hero\" {...sectionRootAttrs(block)}>…</section>\n *\n * The editor shows those handles on a site-rendered page only when EVERY root the site stamps\n * with `data-bcms-block` also carries `data-bcms-style`, which is the site's promise that \"this\n * root's inline style is `blockStyleToCss(block.style)`\" — the same declarations `<BcmsBlocks>`\n * puts on its own wrapper. The marker is present even when the style is EMPTY (then there is no\n * `style` prop at all): an unstyled section is the one an author is about to give its first\n * spacing edit. Twin: `sectionRootAttrs` in @bettercms-ai/astro (style as a string there).\n */\nimport type { CSSProperties } from \"react\";\nimport { blockStyleToColumnCss, blockStyleToCss, hideOnAttr, sectionIdentityAttrs, type BlockStyle } from \"@bettercms-ai/types\";\n\nexport interface SectionRootBlock {\n id?: string | null;\n style?: BlockStyle | Record<string, unknown> | null;\n}\n\nexport interface SectionRootAttrs {\n /**\n * The section's Anchor ID (`style.anchor`), present only when one is set, so a root with its own\n * `id` keeps it otherwise. The section's CSS class (`style.cssClass`) is NOT spread: it would\n * replace the root's own class. Read it with `sectionIdentityAttrs(block.style).className` and\n * join it into the root's class list.\n */\n id?: string;\n \"data-bcms-block\"?: string;\n \"data-bcms-style\": \"\";\n /** `\"mobile tablet\"` when `style.hideOn` hides it there; the site ships `RESPONSIVE_CSS` for it. */\n \"data-bcms-hide\"?: string;\n /** `blockStyleToCss(block.style)`; absent when the block has no style. */\n style?: CSSProperties;\n}\n\nexport function sectionRootAttrs(block: SectionRootBlock | null | undefined): SectionRootAttrs {\n const css = blockStyleToCss((block?.style ?? undefined) as BlockStyle | undefined);\n const id = typeof block?.id === \"string\" && block.id !== \"\" ? block.id : undefined;\n const hide = hideOnAttr(block?.style);\n const anchor = sectionIdentityAttrs(block?.style).id;\n return {\n ...(anchor ? { id: anchor } : {}),\n ...(id !== undefined ? { \"data-bcms-block\": id } : {}),\n \"data-bcms-style\": \"\",\n ...(hide ? { \"data-bcms-hide\": hide } : {}),\n ...(css ? { style: css as CSSProperties } : {}),\n };\n}\n\nexport interface SectionColumnAttrs {\n \"data-bcms-column\": \"\";\n /** `blockStyleToColumnCss(block.style)`; absent when the section has no column. */\n style?: CSSProperties;\n}\n\n/**\n * C3 — `sectionColumnAttrs(block)`: the props a site's own INNER container spreads so the section's\n * content WIDTH ships (`style.contentWidth`, placed by `contentAlign`). The column BetterCMS draws as\n * `.bcms-block-inner`, never on the root (its background stays full-bleed); `data-bcms-column` is the\n * site's promise that this box's inline style is that column. Twin: @bettercms-ai/astro.\n */\nexport function sectionColumnAttrs(block: SectionRootBlock | null | undefined): SectionColumnAttrs {\n const css = blockStyleToColumnCss((block?.style ?? undefined) as BlockStyle | undefined);\n return { \"data-bcms-column\": \"\", ...(css ? { style: css as CSSProperties } : {}) };\n}\n"],"mappings":";AAsBA,SAAS,UAAU,cAAc,sBAA2E;AAqBxG;AATG,SAAS,UAAU,EAAE,MAAM,MAAM,IAAI,SAAS,GAAmB;AACtE,QAAM,MAAM,MAAM;AAClB,QAAM,OAAO,KAAK,CAAC,IAAI,SAAS,QAAQ,QAAQ;AAChD,QAAM,OAAO,KAAK,WAAW,KAAK,eAAe,KAAK,CAAC,CAAC,KAAK,OAAO,KAAK,CAAC,EAAE,SAAS,WAAY,KAAK,CAAC,IAA8C;AAErJ,MAAI,QAAQ,KAAK,MAAM,iBAAiB,MAAM,UAAa,KAAK,MAAM,wBAAwB,MAAM,QAAW;AAC7G,WAAO,aAAa,MAAM,EAAE,mBAAmB,MAAM,kBAAkB,KAAK,CAAC;AAAA,EAC/E;AACA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,mBAAiB;AAAA,MACjB,kBAAgB;AAAA,MAChB,OAAO,KAAK,SAAY,EAAE,SAAS,WAAW;AAAA,MAE7C;AAAA;AAAA,EACH;AAEJ;;;AClCA,SAAS,iBAAiB;AA4CtB,gBAAAA,YAAA;AArBG,SAAS,UAAU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89,27 @@ interface GetEntryOptions extends ReadOptions {
89
89
  /** Signed preview token (from `POST .../preview-token`). */
90
90
  previewToken?: string;
91
91
  }
92
+ type FilterValue = string | number | boolean;
93
+ type FilterOps = Partial<Record<"eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "contains", FilterValue>> & {
94
+ in?: FilterValue[];
95
+ };
96
+ /**
97
+ * Field filters, ANDed, as the delivery list takes them: `{ category: "news" }`,
98
+ * `{ startsAt: { gte: "2026-01-01" } }`, `{ tags: ["a", "b"] }` (an `in` list). The same shape as
99
+ * `@bettercms-ai/sdk`'s `listEntries({ filter })`. `slug`, `status`, `publishedAt` and `locale` are
100
+ * system fields; any other key is a field of the model, checked by the server.
101
+ */
102
+ type EntryFilter = Record<string, FilterValue | FilterValue[] | FilterOps | undefined>;
92
103
  /** Options for `listEntries`. */
93
104
  interface ListEntriesOptions extends ReadOptions {
94
105
  /** 1-based page number. Default: 1. */
95
106
  page?: number;
96
107
  /** Items per page (max 100). Default: 20. */
97
108
  perPage?: number;
109
+ /** Field filters, ANDed. */
110
+ filter?: EntryFilter;
111
+ /** `"-publishedAt"` or `["startsAt", "title"]`: a leading `-` sorts descending. Default: newest published first. */
112
+ sort?: string | string[];
98
113
  }
99
114
  /** Paginated result returned by `listEntries`. */
100
115
  interface EntryList<TFields> {
@@ -211,6 +226,13 @@ interface SectionRootBlock {
211
226
  style?: BlockStyle | Record<string, unknown> | null;
212
227
  }
213
228
  interface SectionRootAttrs {
229
+ /**
230
+ * The section's Anchor ID (`style.anchor`), present only when one is set, so a root with its own
231
+ * `id` keeps it otherwise. The section's CSS class (`style.cssClass`) is NOT spread: it would
232
+ * replace the root's own class. Read it with `sectionIdentityAttrs(block.style).className` and
233
+ * join it into the root's class list.
234
+ */
235
+ id?: string;
214
236
  "data-bcms-block"?: string;
215
237
  "data-bcms-style": "";
216
238
  /** `"mobile tablet"` when `style.hideOn` hides it there; the site ships `RESPONSIVE_CSS` for it. */
@@ -877,22 +899,6 @@ declare function defineBetterCMSLive(config: BetterCMSLiveConfig): {
877
899
  liveSrc: string;
878
900
  };
879
901
 
880
- /**
881
- * createRevalidateRoute — App Router POST handler for the backend's revalidation webhook: every
882
- * tag and every page path the publish changed is revalidated. This is the production live path
883
- * (publish → backend webhook → revalidate the ISR cache).
884
- *
885
- * import { createRevalidateRoute } from "@bettercms-ai/next";
886
- * export const { POST } = createRevalidateRoute();
887
- *
888
- * The `X-BetterCMS-Signature` HMAC-SHA256 header is verified against the raw body with `secret`,
889
- * else `BCMS_REVALIDATE_SECRET` (the one name, matching the project's revalidation secret).
890
- *
891
- * The same route answers a deploy target in "revalidate" mode (a site hosted elsewhere): that call
892
- * signs with `X-BCMS-Signature` and names the changed `paths` and `tags` at the top level, and
893
- * neither means everything the site caches. Read as nothing, it answered 200 with nothing refreshed, and the
894
- * platform took the publish as delivered.
895
- */
896
902
  interface RevalidateRouteConfig {
897
903
  /** Shared secret matching the project's revalidation webhook secret. Defaults to `BCMS_REVALIDATE_SECRET`. */
898
904
  secret?: string;
package/dist/index.js CHANGED
@@ -46,6 +46,18 @@ function statusToCode(status) {
46
46
  if (status === 422) return "VALIDATION_ERROR";
47
47
  return "INTERNAL_ERROR";
48
48
  }
49
+ function appendListQuery(params, opts) {
50
+ const text = (v) => Array.isArray(v) ? v.join(",") : String(v);
51
+ for (const [field, cond] of Object.entries(opts?.filter ?? {})) {
52
+ if (cond == null) continue;
53
+ if (Array.isArray(cond)) params.set(`filter[${field}][in]`, text(cond));
54
+ else if (typeof cond === "object") {
55
+ for (const [op, v] of Object.entries(cond)) if (v != null) params.set(`filter[${field}][${op}]`, text(v));
56
+ } else params.set(`filter[${field}]`, text(cond));
57
+ }
58
+ const sort = Array.isArray(opts?.sort) ? opts.sort.join(",") : opts?.sort;
59
+ if (sort) params.set("sort", sort);
60
+ }
49
61
  function mapEntry(raw) {
50
62
  return {
51
63
  id: raw.id,
@@ -179,6 +191,7 @@ function createBetterCMS(options = {}) {
179
191
  if (opts?.perPage != null) params.set("perPage", String(opts.perPage));
180
192
  if (opts?.depth != null) params.set("depth", String(opts.depth));
181
193
  if (opts?.select?.length) params.set("select", opts.select.join(","));
194
+ appendListQuery(params, opts);
182
195
  if (config.projectId) params.set("projectId", config.projectId);
183
196
  if (config.branch && config.branch !== "main") params.set("branch", config.branch);
184
197
  const url = `${baseUrl}/${config.workspace}/content-entries?${params}`;
@@ -289,12 +302,14 @@ import { RESPONSIVE_CSS } from "@bettercms-ai/types";
289
302
  import { linkHref } from "@bettercms-ai/types";
290
303
 
291
304
  // src/section-root.ts
292
- import { blockStyleToColumnCss, blockStyleToCss, hideOnAttr } from "@bettercms-ai/types";
305
+ import { blockStyleToColumnCss, blockStyleToCss, hideOnAttr, sectionIdentityAttrs } from "@bettercms-ai/types";
293
306
  function sectionRootAttrs(block) {
294
307
  const css = blockStyleToCss(block?.style ?? void 0);
295
308
  const id = typeof block?.id === "string" && block.id !== "" ? block.id : void 0;
296
309
  const hide = hideOnAttr(block?.style);
310
+ const anchor = sectionIdentityAttrs(block?.style).id;
297
311
  return {
312
+ ...anchor ? { id: anchor } : {},
298
313
  ...id !== void 0 ? { "data-bcms-block": id } : {},
299
314
  "data-bcms-style": "",
300
315
  ...hide ? { "data-bcms-hide": hide } : {},
@@ -930,14 +945,7 @@ function defineBetterCMSLive(config) {
930
945
  }
931
946
 
932
947
  // src/revalidate-route.ts
933
- async function signatureValid(secret, body, header) {
934
- const hex = /^sha256=([0-9a-f]{64})$/.exec(header)?.[1];
935
- if (!hex) return false;
936
- const utf8 = new TextEncoder();
937
- const key = await crypto.subtle.importKey("raw", utf8.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["verify"]);
938
- const signature = Uint8Array.from(hex.match(/../g), (byte) => parseInt(byte, 16));
939
- return crypto.subtle.verify("HMAC", key, signature, utf8.encode(body));
940
- }
948
+ import { verifyWebhookSignature } from "@bettercms-ai/sdk/webhook";
941
949
  function slugPath(slug) {
942
950
  if (slug.startsWith("//") || /[\s?#\\]/.test(slug)) return null;
943
951
  if (slug.startsWith("/")) return slug;
@@ -949,7 +957,7 @@ function createRevalidateRoute(config = {}) {
949
957
  const secret = config.secret ?? process.env.BCMS_REVALIDATE_SECRET;
950
958
  if (secret) {
951
959
  const header = request.headers.get("x-bettercms-signature") ?? request.headers.get("x-bcms-signature") ?? "";
952
- if (!await signatureValid(secret, body, header)) {
960
+ if (!await verifyWebhookSignature(body, header, secret)) {
953
961
  return new Response("Invalid signature", { status: 401 });
954
962
  }
955
963
  }