@bettercms-ai/sdk 1.8.1 → 1.10.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/index.d.cts CHANGED
@@ -444,13 +444,21 @@ declare class BetterCMSError extends Error {
444
444
  * vanilla embed and the React component never drift.
445
445
  */
446
446
 
447
- /** Field types the delivery API serializes (superset of the admin builder). */
448
- type DeliveryFormFieldType = "text" | "email" | "phone" | "url" | "number" | "date" | "textarea" | "select" | "checkbox" | "consent" | "hidden";
447
+ /**
448
+ * Field types the delivery API serializes. Must stay equal to the authoring
449
+ * vocabulary in `packages/db/src/schema/forms.ts` — this list is what every site
450
+ * renderer switches on, so a type missing HERE renders as a plain text input on
451
+ * every published site while the builder happily offers it. `radio`/`checkboxes`
452
+ * were exactly that gap.
453
+ */
454
+ type DeliveryFormFieldType = "text" | "email" | "phone" | "url" | "number" | "date" | "textarea" | "select" | "radio" | "checkboxes" | "checkbox" | "consent" | "hidden";
449
455
  interface DeliveryFormField {
450
456
  key: string;
451
457
  label: string;
452
458
  type: DeliveryFormFieldType;
453
459
  placeholder?: string;
460
+ /** Hint rendered under the control. */
461
+ helpText?: string;
454
462
  required?: boolean;
455
463
  options?: string[];
456
464
  defaultValue?: string;
@@ -460,6 +468,8 @@ interface DeliveryFormField {
460
468
  equals: string;
461
469
  };
462
470
  }
471
+ /** The pick-many type, whose value is an array rather than a scalar. */
472
+ declare function isMultiValueField(type: DeliveryFormFieldType): boolean;
463
473
  /** A form as delivered to a published/imported site. Mirrors the delivery `/forms` payload. */
464
474
  interface DeliveryForm {
465
475
  id: string;
@@ -471,8 +481,13 @@ interface DeliveryForm {
471
481
  turnstileEnabled?: boolean;
472
482
  honeypotField?: string | null;
473
483
  }
474
- type FormValue = string | boolean;
484
+ /** `string[]` is the `checkboxes` (pick-many) value; every other type is scalar. */
485
+ type FormValue = string | boolean | string[];
475
486
  type FormValues = Record<string, FormValue>;
487
+ /** Read a `checkboxes` value defensively — stored data may predate the array shape. */
488
+ declare function asStringArray(value: FormValue | undefined): string[];
489
+ /** Add/remove `option` from a `checkboxes` value, preserving the field's option order. */
490
+ declare function toggleOption(value: FormValue | undefined, option: string, on: boolean): string[];
476
491
  /**
477
492
  * Conditional visibility. A `showIf` field is shown only when its trigger field's
478
493
  * current value equals the target; non-conditional fields are always shown. The
@@ -481,8 +496,9 @@ type FormValues = Record<string, FormValue>;
481
496
  */
482
497
  declare function shouldShowField(field: DeliveryFormField, values: FormValues): boolean;
483
498
  /**
484
- * Build the initial value map: checkbox/consent default to false, every other field
485
- * to its `defaultValue`, with `prefill` (e.g. URL query params) taking precedence.
499
+ * Build the initial value map: checkbox/consent default to false, checkboxes to an
500
+ * empty array, every other field to its `defaultValue`, with `prefill` (e.g. URL
501
+ * query params) taking precedence.
486
502
  */
487
503
  declare function formInitialValues(form: DeliveryForm, prefill?: Record<string, string>): FormValues;
488
504
  interface SubmitFormOptions {
@@ -850,6 +866,60 @@ declare function decodeStega(value: string): {
850
866
  /** Remove any stega payload, returning the clean string. */
851
867
  declare function stripStega(value: string): string;
852
868
 
869
+ /**
870
+ * Reading a rich-text field, for any site.
871
+ *
872
+ * A `text` field delivers a bare string. A `richtext` field delivers the canonical envelope
873
+ * `{ format, value, html }`. Those are different shapes, and switching a field's type in the
874
+ * CMS switches which one your site receives — the Visual Editor offers exactly that switch,
875
+ * so it happens on live projects. A template that interpolates the value directly then
876
+ * renders `[object Object]` (or, in React, throws `Objects are not valid as a React child`).
877
+ *
878
+ * No payload can be both structured and safe to interpolate, which is why every headless CMS
879
+ * requires a renderer for rich text. These are ours:
880
+ *
881
+ * plain(v) → text, for <title>, meta descriptions, JSON-LD, alt text, aria-label
882
+ * rich(v) → HTML, for `set:html` / `dangerouslySetInnerHTML`
883
+ *
884
+ * Both accept a bare string, so a field can be switched in the CMS without touching the site.
885
+ *
886
+ * <h1 set:html={rich(page.heroTitle)} /> // Astro
887
+ * <h1 dangerouslySetInnerHTML={{ __html: rich(f.heroTitle) }}/> // React
888
+ * seo({ title: plain(page.heroTitle) })
889
+ */
890
+ /** The canonical rich-text envelope returned by the Delivery API. */
891
+ interface RichTextValue {
892
+ readonly format?: string;
893
+ readonly value?: unknown;
894
+ /** Server-rendered, sanitized HTML. Computed on write. */
895
+ readonly html?: string;
896
+ }
897
+ /**
898
+ * A field that may arrive as either shape. Type author-editable text fields with this and the
899
+ * compiler routes you through `plain()`/`rich()`, so a type switch in the CMS can never reach
900
+ * production as `[object Object]`.
901
+ */
902
+ type TextOrRich = string | RichTextValue | null | undefined;
903
+ /** True when the value is a rich-text envelope rather than a bare string. */
904
+ declare function isRichText(value: unknown): value is RichTextValue;
905
+ /**
906
+ * Plain text for an attribute context — `<title>`, meta description, JSON-LD, `alt`.
907
+ * Strips tags and decodes the entities that survive stripping, so the result is text the
908
+ * consumer can escape once without double-escaping.
909
+ */
910
+ declare function plain(value: TextOrRich): string;
911
+ /**
912
+ * Renderable HTML. Rich text keeps its inline marks (the server sanitizes `html` on write);
913
+ * a bare string is escaped, so a plain field can never inject markup.
914
+ *
915
+ * A lone wrapping block is unwrapped: a field switched from `text` stores its value as
916
+ * `<p>…</p>`, but it renders inside the element that already is the block — and
917
+ * `<h1><p>…</p></h1>` is invalid, the parser closes the heading at the `<p>` and the text
918
+ * falls out of it. Values with real block structure (several paragraphs, a list) are left
919
+ * alone, so a body field still renders as a document.
920
+ */
921
+ declare function rich(value: TextOrRich, fallback?: string): string;
922
+
853
923
  /**
854
924
  * resolveSeo — framework-agnostic page-over-site SEO merge for headless consumers.
855
925
  *
@@ -1121,4 +1191,4 @@ declare function inviteMember(client: BetterCMSAdminClient, workspaceId: string,
1121
1191
  declare function updateMemberRole(client: BetterCMSAdminClient, workspaceId: string, memberId: string, role: MemberRole): Promise<Member>;
1122
1192
  declare function removeMember(client: BetterCMSAdminClient, workspaceId: string, memberId: string): Promise<void>;
1123
1193
 
1124
- export { type AddPageFieldsInput, type ApiKeyUsage, type ApiKeyWithRaw, type AuthResult, BetterCMSError as BCMSClientError, ErrorCodes as BCMSErrorCodes, BetterCMS, BetterCMSAdminClient, type BetterCMSAdminOptions, BetterCMSDeliveryClient, BetterCMSError, BetterCMSManagementClient, type BetterCMSManagementOptions, type BetterCMSReadClient, type BetterCMSSiteOptions, type CreateApiKeyInput, type CreateClientOptions, type CreateEntryInput, type CreateFormInput, type CreateManagedPageInput, type CreateModelInput, type CreatePageInput, type CreateWorkspaceInput, type DeliveryForm, type DeliveryFormField, type DeliveryFormFieldType, ErrorCodes, type FormFieldInput, type FormListOptions, type FormSubmitError, type FormValue, type FormValues, type GetEntryOptions, type ListContentAllOptions, type ListContentOptions, type ListEntriesFilter, type ListEntriesOptions, type ListPagesOptions, type ManagedComponent, type ManagedComponentInput, type ManagedContentEntry, type ManagedContentModel, type ManagedForm, type ManagedFormInput, type ManagedPage, type ManagementClient, type MediaListOptions, type MediaMetadata, type Member, type MemberRole, type PageListOptions, type PendingInvite, type ResolvedSeo, type SearchHit, type SearchOptions, type SeoInput, type SeoMeta, type SeoMetaInput, type SetPageContentInput, type StegaPayload, type SubmissionListOptions, type SubmitFormOptions, type SubmitFormResult, type UpdateApiKeyInput, type UpdateEntryInput, type UpdateFormInput, type UpdateModelInput, type UpdatePageInput, type UpdateWorkspaceInput, type UploadAssetInput, type UploadedAsset, type WriteContentInput, addModelFields, addPageFields, createApiKey, createClient, createEntry, createForm, createManagedPage, createModel, createPage, createWorkspace, decodeStega, deleteForm, deleteMedia, deletePage, deleteSubmission, deleteWorkspace, encodeStega, formInitialValues, getApiKeyUsage, getEntry, getForm, getManagedPage, getMedia, getMember, getModel, getPage, getSubmission, getWorkspace, inviteMember, listApiKeys, listEntries, listForms, listManagedPages, listMedia, listMembers, listModels, listPages, listSubmissions, listWorkspaces, publishPage, regenerateApiKey, removeMember, resolveSeo, revokeApiKey, search, setPageContent, shouldShowField, signIn, signInWithGithub, signInWithGoogle, signUp, stripStega, submitForm, updateApiKey, updateEntry, updateForm, updateMemberRole, updateModel, updatePage, updateWorkspace, uploadMedia };
1194
+ export { type AddPageFieldsInput, type ApiKeyUsage, type ApiKeyWithRaw, type AuthResult, BetterCMSError as BCMSClientError, ErrorCodes as BCMSErrorCodes, BetterCMS, BetterCMSAdminClient, type BetterCMSAdminOptions, BetterCMSDeliveryClient, BetterCMSError, BetterCMSManagementClient, type BetterCMSManagementOptions, type BetterCMSReadClient, type BetterCMSSiteOptions, type CreateApiKeyInput, type CreateClientOptions, type CreateEntryInput, type CreateFormInput, type CreateManagedPageInput, type CreateModelInput, type CreatePageInput, type CreateWorkspaceInput, type DeliveryForm, type DeliveryFormField, type DeliveryFormFieldType, ErrorCodes, type FormFieldInput, type FormListOptions, type FormSubmitError, type FormValue, type FormValues, type GetEntryOptions, type ListContentAllOptions, type ListContentOptions, type ListEntriesFilter, type ListEntriesOptions, type ListPagesOptions, type ManagedComponent, type ManagedComponentInput, type ManagedContentEntry, type ManagedContentModel, type ManagedForm, type ManagedFormInput, type ManagedPage, type ManagementClient, type MediaListOptions, type MediaMetadata, type Member, type MemberRole, type PageListOptions, type PendingInvite, type ResolvedSeo, type RichTextValue, type SearchHit, type SearchOptions, type SeoInput, type SeoMeta, type SeoMetaInput, type SetPageContentInput, type StegaPayload, type SubmissionListOptions, type SubmitFormOptions, type SubmitFormResult, type TextOrRich, type UpdateApiKeyInput, type UpdateEntryInput, type UpdateFormInput, type UpdateModelInput, type UpdatePageInput, type UpdateWorkspaceInput, type UploadAssetInput, type UploadedAsset, type WriteContentInput, addModelFields, addPageFields, asStringArray, createApiKey, createClient, createEntry, createForm, createManagedPage, createModel, createPage, createWorkspace, decodeStega, deleteForm, deleteMedia, deletePage, deleteSubmission, deleteWorkspace, encodeStega, formInitialValues, getApiKeyUsage, getEntry, getForm, getManagedPage, getMedia, getMember, getModel, getPage, getSubmission, getWorkspace, inviteMember, isMultiValueField, isRichText, listApiKeys, listEntries, listForms, listManagedPages, listMedia, listMembers, listModels, listPages, listSubmissions, listWorkspaces, plain, publishPage, regenerateApiKey, removeMember, resolveSeo, revokeApiKey, rich, search, setPageContent, shouldShowField, signIn, signInWithGithub, signInWithGoogle, signUp, stripStega, submitForm, toggleOption, updateApiKey, updateEntry, updateForm, updateMemberRole, updateModel, updatePage, updateWorkspace, uploadMedia };
package/dist/index.d.ts CHANGED
@@ -444,13 +444,21 @@ declare class BetterCMSError extends Error {
444
444
  * vanilla embed and the React component never drift.
445
445
  */
446
446
 
447
- /** Field types the delivery API serializes (superset of the admin builder). */
448
- type DeliveryFormFieldType = "text" | "email" | "phone" | "url" | "number" | "date" | "textarea" | "select" | "checkbox" | "consent" | "hidden";
447
+ /**
448
+ * Field types the delivery API serializes. Must stay equal to the authoring
449
+ * vocabulary in `packages/db/src/schema/forms.ts` — this list is what every site
450
+ * renderer switches on, so a type missing HERE renders as a plain text input on
451
+ * every published site while the builder happily offers it. `radio`/`checkboxes`
452
+ * were exactly that gap.
453
+ */
454
+ type DeliveryFormFieldType = "text" | "email" | "phone" | "url" | "number" | "date" | "textarea" | "select" | "radio" | "checkboxes" | "checkbox" | "consent" | "hidden";
449
455
  interface DeliveryFormField {
450
456
  key: string;
451
457
  label: string;
452
458
  type: DeliveryFormFieldType;
453
459
  placeholder?: string;
460
+ /** Hint rendered under the control. */
461
+ helpText?: string;
454
462
  required?: boolean;
455
463
  options?: string[];
456
464
  defaultValue?: string;
@@ -460,6 +468,8 @@ interface DeliveryFormField {
460
468
  equals: string;
461
469
  };
462
470
  }
471
+ /** The pick-many type, whose value is an array rather than a scalar. */
472
+ declare function isMultiValueField(type: DeliveryFormFieldType): boolean;
463
473
  /** A form as delivered to a published/imported site. Mirrors the delivery `/forms` payload. */
464
474
  interface DeliveryForm {
465
475
  id: string;
@@ -471,8 +481,13 @@ interface DeliveryForm {
471
481
  turnstileEnabled?: boolean;
472
482
  honeypotField?: string | null;
473
483
  }
474
- type FormValue = string | boolean;
484
+ /** `string[]` is the `checkboxes` (pick-many) value; every other type is scalar. */
485
+ type FormValue = string | boolean | string[];
475
486
  type FormValues = Record<string, FormValue>;
487
+ /** Read a `checkboxes` value defensively — stored data may predate the array shape. */
488
+ declare function asStringArray(value: FormValue | undefined): string[];
489
+ /** Add/remove `option` from a `checkboxes` value, preserving the field's option order. */
490
+ declare function toggleOption(value: FormValue | undefined, option: string, on: boolean): string[];
476
491
  /**
477
492
  * Conditional visibility. A `showIf` field is shown only when its trigger field's
478
493
  * current value equals the target; non-conditional fields are always shown. The
@@ -481,8 +496,9 @@ type FormValues = Record<string, FormValue>;
481
496
  */
482
497
  declare function shouldShowField(field: DeliveryFormField, values: FormValues): boolean;
483
498
  /**
484
- * Build the initial value map: checkbox/consent default to false, every other field
485
- * to its `defaultValue`, with `prefill` (e.g. URL query params) taking precedence.
499
+ * Build the initial value map: checkbox/consent default to false, checkboxes to an
500
+ * empty array, every other field to its `defaultValue`, with `prefill` (e.g. URL
501
+ * query params) taking precedence.
486
502
  */
487
503
  declare function formInitialValues(form: DeliveryForm, prefill?: Record<string, string>): FormValues;
488
504
  interface SubmitFormOptions {
@@ -850,6 +866,60 @@ declare function decodeStega(value: string): {
850
866
  /** Remove any stega payload, returning the clean string. */
851
867
  declare function stripStega(value: string): string;
852
868
 
869
+ /**
870
+ * Reading a rich-text field, for any site.
871
+ *
872
+ * A `text` field delivers a bare string. A `richtext` field delivers the canonical envelope
873
+ * `{ format, value, html }`. Those are different shapes, and switching a field's type in the
874
+ * CMS switches which one your site receives — the Visual Editor offers exactly that switch,
875
+ * so it happens on live projects. A template that interpolates the value directly then
876
+ * renders `[object Object]` (or, in React, throws `Objects are not valid as a React child`).
877
+ *
878
+ * No payload can be both structured and safe to interpolate, which is why every headless CMS
879
+ * requires a renderer for rich text. These are ours:
880
+ *
881
+ * plain(v) → text, for <title>, meta descriptions, JSON-LD, alt text, aria-label
882
+ * rich(v) → HTML, for `set:html` / `dangerouslySetInnerHTML`
883
+ *
884
+ * Both accept a bare string, so a field can be switched in the CMS without touching the site.
885
+ *
886
+ * <h1 set:html={rich(page.heroTitle)} /> // Astro
887
+ * <h1 dangerouslySetInnerHTML={{ __html: rich(f.heroTitle) }}/> // React
888
+ * seo({ title: plain(page.heroTitle) })
889
+ */
890
+ /** The canonical rich-text envelope returned by the Delivery API. */
891
+ interface RichTextValue {
892
+ readonly format?: string;
893
+ readonly value?: unknown;
894
+ /** Server-rendered, sanitized HTML. Computed on write. */
895
+ readonly html?: string;
896
+ }
897
+ /**
898
+ * A field that may arrive as either shape. Type author-editable text fields with this and the
899
+ * compiler routes you through `plain()`/`rich()`, so a type switch in the CMS can never reach
900
+ * production as `[object Object]`.
901
+ */
902
+ type TextOrRich = string | RichTextValue | null | undefined;
903
+ /** True when the value is a rich-text envelope rather than a bare string. */
904
+ declare function isRichText(value: unknown): value is RichTextValue;
905
+ /**
906
+ * Plain text for an attribute context — `<title>`, meta description, JSON-LD, `alt`.
907
+ * Strips tags and decodes the entities that survive stripping, so the result is text the
908
+ * consumer can escape once without double-escaping.
909
+ */
910
+ declare function plain(value: TextOrRich): string;
911
+ /**
912
+ * Renderable HTML. Rich text keeps its inline marks (the server sanitizes `html` on write);
913
+ * a bare string is escaped, so a plain field can never inject markup.
914
+ *
915
+ * A lone wrapping block is unwrapped: a field switched from `text` stores its value as
916
+ * `<p>…</p>`, but it renders inside the element that already is the block — and
917
+ * `<h1><p>…</p></h1>` is invalid, the parser closes the heading at the `<p>` and the text
918
+ * falls out of it. Values with real block structure (several paragraphs, a list) are left
919
+ * alone, so a body field still renders as a document.
920
+ */
921
+ declare function rich(value: TextOrRich, fallback?: string): string;
922
+
853
923
  /**
854
924
  * resolveSeo — framework-agnostic page-over-site SEO merge for headless consumers.
855
925
  *
@@ -1121,4 +1191,4 @@ declare function inviteMember(client: BetterCMSAdminClient, workspaceId: string,
1121
1191
  declare function updateMemberRole(client: BetterCMSAdminClient, workspaceId: string, memberId: string, role: MemberRole): Promise<Member>;
1122
1192
  declare function removeMember(client: BetterCMSAdminClient, workspaceId: string, memberId: string): Promise<void>;
1123
1193
 
1124
- export { type AddPageFieldsInput, type ApiKeyUsage, type ApiKeyWithRaw, type AuthResult, BetterCMSError as BCMSClientError, ErrorCodes as BCMSErrorCodes, BetterCMS, BetterCMSAdminClient, type BetterCMSAdminOptions, BetterCMSDeliveryClient, BetterCMSError, BetterCMSManagementClient, type BetterCMSManagementOptions, type BetterCMSReadClient, type BetterCMSSiteOptions, type CreateApiKeyInput, type CreateClientOptions, type CreateEntryInput, type CreateFormInput, type CreateManagedPageInput, type CreateModelInput, type CreatePageInput, type CreateWorkspaceInput, type DeliveryForm, type DeliveryFormField, type DeliveryFormFieldType, ErrorCodes, type FormFieldInput, type FormListOptions, type FormSubmitError, type FormValue, type FormValues, type GetEntryOptions, type ListContentAllOptions, type ListContentOptions, type ListEntriesFilter, type ListEntriesOptions, type ListPagesOptions, type ManagedComponent, type ManagedComponentInput, type ManagedContentEntry, type ManagedContentModel, type ManagedForm, type ManagedFormInput, type ManagedPage, type ManagementClient, type MediaListOptions, type MediaMetadata, type Member, type MemberRole, type PageListOptions, type PendingInvite, type ResolvedSeo, type SearchHit, type SearchOptions, type SeoInput, type SeoMeta, type SeoMetaInput, type SetPageContentInput, type StegaPayload, type SubmissionListOptions, type SubmitFormOptions, type SubmitFormResult, type UpdateApiKeyInput, type UpdateEntryInput, type UpdateFormInput, type UpdateModelInput, type UpdatePageInput, type UpdateWorkspaceInput, type UploadAssetInput, type UploadedAsset, type WriteContentInput, addModelFields, addPageFields, createApiKey, createClient, createEntry, createForm, createManagedPage, createModel, createPage, createWorkspace, decodeStega, deleteForm, deleteMedia, deletePage, deleteSubmission, deleteWorkspace, encodeStega, formInitialValues, getApiKeyUsage, getEntry, getForm, getManagedPage, getMedia, getMember, getModel, getPage, getSubmission, getWorkspace, inviteMember, listApiKeys, listEntries, listForms, listManagedPages, listMedia, listMembers, listModels, listPages, listSubmissions, listWorkspaces, publishPage, regenerateApiKey, removeMember, resolveSeo, revokeApiKey, search, setPageContent, shouldShowField, signIn, signInWithGithub, signInWithGoogle, signUp, stripStega, submitForm, updateApiKey, updateEntry, updateForm, updateMemberRole, updateModel, updatePage, updateWorkspace, uploadMedia };
1194
+ export { type AddPageFieldsInput, type ApiKeyUsage, type ApiKeyWithRaw, type AuthResult, BetterCMSError as BCMSClientError, ErrorCodes as BCMSErrorCodes, BetterCMS, BetterCMSAdminClient, type BetterCMSAdminOptions, BetterCMSDeliveryClient, BetterCMSError, BetterCMSManagementClient, type BetterCMSManagementOptions, type BetterCMSReadClient, type BetterCMSSiteOptions, type CreateApiKeyInput, type CreateClientOptions, type CreateEntryInput, type CreateFormInput, type CreateManagedPageInput, type CreateModelInput, type CreatePageInput, type CreateWorkspaceInput, type DeliveryForm, type DeliveryFormField, type DeliveryFormFieldType, ErrorCodes, type FormFieldInput, type FormListOptions, type FormSubmitError, type FormValue, type FormValues, type GetEntryOptions, type ListContentAllOptions, type ListContentOptions, type ListEntriesFilter, type ListEntriesOptions, type ListPagesOptions, type ManagedComponent, type ManagedComponentInput, type ManagedContentEntry, type ManagedContentModel, type ManagedForm, type ManagedFormInput, type ManagedPage, type ManagementClient, type MediaListOptions, type MediaMetadata, type Member, type MemberRole, type PageListOptions, type PendingInvite, type ResolvedSeo, type RichTextValue, type SearchHit, type SearchOptions, type SeoInput, type SeoMeta, type SeoMetaInput, type SetPageContentInput, type StegaPayload, type SubmissionListOptions, type SubmitFormOptions, type SubmitFormResult, type TextOrRich, type UpdateApiKeyInput, type UpdateEntryInput, type UpdateFormInput, type UpdateModelInput, type UpdatePageInput, type UpdateWorkspaceInput, type UploadAssetInput, type UploadedAsset, type WriteContentInput, addModelFields, addPageFields, asStringArray, createApiKey, createClient, createEntry, createForm, createManagedPage, createModel, createPage, createWorkspace, decodeStega, deleteForm, deleteMedia, deletePage, deleteSubmission, deleteWorkspace, encodeStega, formInitialValues, getApiKeyUsage, getEntry, getForm, getManagedPage, getMedia, getMember, getModel, getPage, getSubmission, getWorkspace, inviteMember, isMultiValueField, isRichText, listApiKeys, listEntries, listForms, listManagedPages, listMedia, listMembers, listModels, listPages, listSubmissions, listWorkspaces, plain, publishPage, regenerateApiKey, removeMember, resolveSeo, revokeApiKey, rich, search, setPageContent, shouldShowField, signIn, signInWithGithub, signInWithGoogle, signUp, stripStega, submitForm, toggleOption, updateApiKey, updateEntry, updateForm, updateMemberRole, updateModel, updatePage, updateWorkspace, uploadMedia };
package/dist/index.js CHANGED
@@ -1150,6 +1150,30 @@ function stripStega(value) {
1150
1150
  return value.replace(FRAME, "");
1151
1151
  }
1152
1152
 
1153
+ // src/richtext.ts
1154
+ function isRichText(value) {
1155
+ return typeof value === "object" && value !== null && !Array.isArray(value) && ("html" in value || "format" in value);
1156
+ }
1157
+ function plain(value) {
1158
+ if (typeof value === "string") return value;
1159
+ if (!isRichText(value) || typeof value.html !== "string") return "";
1160
+ return decodeEntities(value.html.replace(/<[^>]+>/g, "")).trim();
1161
+ }
1162
+ function rich(value, fallback = "") {
1163
+ const html = (typeof value === "string" ? escapeHtml(value) : isRichText(value) ? value.html ?? "" : "").trim();
1164
+ return html ? unwrapLoneBlock(html) : escapeHtml(fallback);
1165
+ }
1166
+ function unwrapLoneBlock(html) {
1167
+ const m = html.match(/^<(p|div|h[1-6])(?:\s[^>]*)?>([\s\S]*)<\/\1>$/i);
1168
+ return m && !new RegExp(`</${m[1]}>`, "i").test(m[2]) ? m[2] : html;
1169
+ }
1170
+ function escapeHtml(s) {
1171
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1172
+ }
1173
+ function decodeEntities(s) {
1174
+ return s.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#0?39;/g, "'").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&");
1175
+ }
1176
+
1153
1177
  // src/seo.ts
1154
1178
  function jsonLdNodes(schema) {
1155
1179
  if (!schema) return [];
@@ -1433,16 +1457,33 @@ async function removeMember(client, workspaceId, memberId) {
1433
1457
  }
1434
1458
 
1435
1459
  // src/forms.ts
1460
+ function isMultiValueField(type) {
1461
+ return type === "checkboxes";
1462
+ }
1463
+ function asStringArray(value) {
1464
+ if (Array.isArray(value)) return value;
1465
+ return value ? [String(value)] : [];
1466
+ }
1467
+ function toggleOption(value, option, on) {
1468
+ const current = asStringArray(value);
1469
+ if (on) return current.includes(option) ? current : [...current, option];
1470
+ return current.filter((v) => v !== option);
1471
+ }
1436
1472
  var DEFAULT_BASE_URL5 = "https://api.bettercms.ai";
1437
1473
  function shouldShowField(field, values) {
1438
1474
  if (!field.showIf) return true;
1439
- return String(values[field.showIf.field] ?? "") === field.showIf.equals;
1475
+ const trigger = values[field.showIf.field];
1476
+ if (Array.isArray(trigger)) return trigger.includes(field.showIf.equals);
1477
+ return String(trigger ?? "") === field.showIf.equals;
1440
1478
  }
1441
1479
  function formInitialValues(form, prefill = {}) {
1442
1480
  const values = {};
1443
1481
  for (const field of form.fields) {
1444
1482
  if (field.type === "checkbox" || field.type === "consent") {
1445
1483
  values[field.key] = false;
1484
+ } else if (field.type === "checkboxes") {
1485
+ const seed = prefill[field.key] ?? field.defaultValue ?? "";
1486
+ values[field.key] = seed ? seed.split(",").map((v) => v.trim()).filter(Boolean) : [];
1446
1487
  } else {
1447
1488
  values[field.key] = prefill[field.key] ?? field.defaultValue ?? "";
1448
1489
  }
@@ -1491,6 +1532,7 @@ export {
1491
1532
  ErrorCodes,
1492
1533
  addModelFields,
1493
1534
  addPageFields,
1535
+ asStringArray,
1494
1536
  createApiKey,
1495
1537
  createClient,
1496
1538
  createEntry,
@@ -1522,6 +1564,8 @@ export {
1522
1564
  default2 as imageUrlBuilder,
1523
1565
  inviteMember,
1524
1566
  isBlock,
1567
+ isMultiValueField,
1568
+ isRichText,
1525
1569
  listApiKeys,
1526
1570
  listEntries,
1527
1571
  listForms2 as listForms,
@@ -1532,11 +1576,13 @@ export {
1532
1576
  listPages,
1533
1577
  listSubmissions,
1534
1578
  listWorkspaces,
1579
+ plain,
1535
1580
  publishPage,
1536
1581
  regenerateApiKey,
1537
1582
  removeMember,
1538
1583
  resolveSeo,
1539
1584
  revokeApiKey,
1585
+ rich,
1540
1586
  search,
1541
1587
  setPageContent,
1542
1588
  shouldShowField,
@@ -1546,6 +1592,7 @@ export {
1546
1592
  signUp,
1547
1593
  stripStega,
1548
1594
  submitForm,
1595
+ toggleOption,
1549
1596
  updateApiKey,
1550
1597
  updateEntry,
1551
1598
  updateForm2 as updateForm,