@bettercms-ai/sdk 1.9.0 → 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 {
@@ -1175,4 +1191,4 @@ declare function inviteMember(client: BetterCMSAdminClient, workspaceId: string,
1175
1191
  declare function updateMemberRole(client: BetterCMSAdminClient, workspaceId: string, memberId: string, role: MemberRole): Promise<Member>;
1176
1192
  declare function removeMember(client: BetterCMSAdminClient, workspaceId: string, memberId: string): Promise<void>;
1177
1193
 
1178
- 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, 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, 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, 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 {
@@ -1175,4 +1191,4 @@ declare function inviteMember(client: BetterCMSAdminClient, workspaceId: string,
1175
1191
  declare function updateMemberRole(client: BetterCMSAdminClient, workspaceId: string, memberId: string, role: MemberRole): Promise<Member>;
1176
1192
  declare function removeMember(client: BetterCMSAdminClient, workspaceId: string, memberId: string): Promise<void>;
1177
1193
 
1178
- 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, 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, 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, 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
@@ -1457,16 +1457,33 @@ async function removeMember(client, workspaceId, memberId) {
1457
1457
  }
1458
1458
 
1459
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
+ }
1460
1472
  var DEFAULT_BASE_URL5 = "https://api.bettercms.ai";
1461
1473
  function shouldShowField(field, values) {
1462
1474
  if (!field.showIf) return true;
1463
- 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;
1464
1478
  }
1465
1479
  function formInitialValues(form, prefill = {}) {
1466
1480
  const values = {};
1467
1481
  for (const field of form.fields) {
1468
1482
  if (field.type === "checkbox" || field.type === "consent") {
1469
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) : [];
1470
1487
  } else {
1471
1488
  values[field.key] = prefill[field.key] ?? field.defaultValue ?? "";
1472
1489
  }
@@ -1515,6 +1532,7 @@ export {
1515
1532
  ErrorCodes,
1516
1533
  addModelFields,
1517
1534
  addPageFields,
1535
+ asStringArray,
1518
1536
  createApiKey,
1519
1537
  createClient,
1520
1538
  createEntry,
@@ -1546,6 +1564,7 @@ export {
1546
1564
  default2 as imageUrlBuilder,
1547
1565
  inviteMember,
1548
1566
  isBlock,
1567
+ isMultiValueField,
1549
1568
  isRichText,
1550
1569
  listApiKeys,
1551
1570
  listEntries,
@@ -1573,6 +1592,7 @@ export {
1573
1592
  signUp,
1574
1593
  stripStega,
1575
1594
  submitForm,
1595
+ toggleOption,
1576
1596
  updateApiKey,
1577
1597
  updateEntry,
1578
1598
  updateForm2 as updateForm,