@bettercms-ai/sdk 1.10.0 → 1.11.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
@@ -274,6 +274,14 @@ interface CreateModelInput {
274
274
  description?: string;
275
275
  fields?: ContentModelField[];
276
276
  projectId?: string;
277
+ /**
278
+ * 'model' (default) = a collection with entries of its own. 'block' = a type instantiable
279
+ * only inside another model's `modular` field; entry creation against it is refused.
280
+ *
281
+ * CREATE-ONLY, and absent from UpdateModelInput on purpose: flipping a populated model into
282
+ * a block would orphan every entry it already has.
283
+ */
284
+ kind?: "model" | "block";
277
285
  }
278
286
  interface UpdateModelInput {
279
287
  name?: string;
@@ -584,6 +592,27 @@ interface ManagedComponentInput {
584
592
  blockJson?: unknown[];
585
593
  props?: unknown[];
586
594
  }
595
+ /**
596
+ * A set of sections that repeat across the project's pages, proposed as one component.
597
+ * Derived per request from the pages' DRAFT blocks — never stored.
598
+ */
599
+ interface ExtractionCandidate {
600
+ /** Identifies the shape. Pass it back to `extractComponent`; it is re-verified server-side. */
601
+ hash: string;
602
+ blockType: string;
603
+ uses: number;
604
+ suggestedName: string;
605
+ blockJson: unknown[];
606
+ /** The leaves that differ between copies, which become the component's editable props. */
607
+ props: unknown[];
608
+ sites: {
609
+ pageId: string;
610
+ title: string;
611
+ slug: string;
612
+ blockId: string;
613
+ overrides: Record<string, unknown>;
614
+ }[];
615
+ }
587
616
 
588
617
  /**
589
618
  * Management API SDK methods — AI content + SEO actions (Option B, portable skill).
@@ -687,6 +716,18 @@ declare class BetterCMSManagementClient extends BetterCMSDeliveryClient {
687
716
  getComponent(id: string): Promise<ManagedComponent>;
688
717
  createComponent(input: ManagedComponentInput): Promise<ManagedComponent>;
689
718
  updateComponent(id: string, input: ManagedComponentInput): Promise<ManagedComponent>;
719
+ /** Sections repeating across the project's pages, proposed as components. */
720
+ listExtractionCandidates(projectId?: string): Promise<ExtractionCandidate[]>;
721
+ /** Fold one candidate into a component and repoint every occurrence at it. */
722
+ extractComponent(input: {
723
+ hash: string;
724
+ name: string;
725
+ slug: string;
726
+ projectId?: string;
727
+ }): Promise<{
728
+ component: ManagedComponent;
729
+ replaced: number;
730
+ }>;
690
731
  /** Write, rewrite, or translate a piece of copy. Returns the suggested text. */
691
732
  writeContent(input: WriteContentInput): Promise<string>;
692
733
  /** Generate SEO metadata for a piece of content (title, description, keywords, JSON-LD). */
@@ -887,12 +928,42 @@ declare function stripStega(value: string): string;
887
928
  * <h1 dangerouslySetInnerHTML={{ __html: rich(f.heroTitle) }}/> // React
888
929
  * seo({ title: plain(page.heroTitle) })
889
930
  */
931
+ /**
932
+ * A block in a Body field's `doc`. Bounded vocabulary — the server only emits what it can
933
+ * parse back, so an unknown `type` means your SDK is older than the content, not that the
934
+ * content is malformed. Handle the default case rather than exhausting on it.
935
+ */
936
+ type DocBlock = {
937
+ /**
938
+ * Stable within THIS document only — never a global key. Two different entries both have a
939
+ * block called "0.0". A cross-document anchor is (entryId, fieldKey, id).
940
+ *
941
+ * Ids on content authored before block ids existed are derived from position, so they SHIFT
942
+ * when that document is edited. Do not persist an id as a bookmark unless you know it came
943
+ * from the editor rather than from the positional fallback.
944
+ */
945
+ readonly id: string;
946
+ readonly type: string;
947
+ readonly [key: string]: unknown;
948
+ };
949
+ /** The `doc` rendition of a Body field — a versioned block array. */
950
+ type DocValue = {
951
+ readonly version: 1;
952
+ readonly blocks: readonly DocBlock[];
953
+ };
890
954
  /** The canonical rich-text envelope returned by the Delivery API. */
891
955
  interface RichTextValue {
892
956
  readonly format?: string;
893
957
  readonly value?: unknown;
894
958
  /** Server-rendered, sanitized HTML. Computed on write. */
895
959
  readonly html?: string;
960
+ /**
961
+ * Structured blocks — present on `document` (Body) fields only, and NOT guaranteed even
962
+ * there: it is derived at write time, so an entry saved before this existed carries none
963
+ * until its next save. There is no backfill. Always branch on its absence; `html` is the
964
+ * field that is always there.
965
+ */
966
+ readonly doc?: DocValue;
896
967
  }
897
968
  /**
898
969
  * A field that may arrive as either shape. Type author-editable text fields with this and the
@@ -1191,4 +1262,4 @@ declare function inviteMember(client: BetterCMSAdminClient, workspaceId: string,
1191
1262
  declare function updateMemberRole(client: BetterCMSAdminClient, workspaceId: string, memberId: string, role: MemberRole): Promise<Member>;
1192
1263
  declare function removeMember(client: BetterCMSAdminClient, workspaceId: string, memberId: string): Promise<void>;
1193
1264
 
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 };
1265
+ 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 ExtractionCandidate, 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
@@ -274,6 +274,14 @@ interface CreateModelInput {
274
274
  description?: string;
275
275
  fields?: ContentModelField[];
276
276
  projectId?: string;
277
+ /**
278
+ * 'model' (default) = a collection with entries of its own. 'block' = a type instantiable
279
+ * only inside another model's `modular` field; entry creation against it is refused.
280
+ *
281
+ * CREATE-ONLY, and absent from UpdateModelInput on purpose: flipping a populated model into
282
+ * a block would orphan every entry it already has.
283
+ */
284
+ kind?: "model" | "block";
277
285
  }
278
286
  interface UpdateModelInput {
279
287
  name?: string;
@@ -584,6 +592,27 @@ interface ManagedComponentInput {
584
592
  blockJson?: unknown[];
585
593
  props?: unknown[];
586
594
  }
595
+ /**
596
+ * A set of sections that repeat across the project's pages, proposed as one component.
597
+ * Derived per request from the pages' DRAFT blocks — never stored.
598
+ */
599
+ interface ExtractionCandidate {
600
+ /** Identifies the shape. Pass it back to `extractComponent`; it is re-verified server-side. */
601
+ hash: string;
602
+ blockType: string;
603
+ uses: number;
604
+ suggestedName: string;
605
+ blockJson: unknown[];
606
+ /** The leaves that differ between copies, which become the component's editable props. */
607
+ props: unknown[];
608
+ sites: {
609
+ pageId: string;
610
+ title: string;
611
+ slug: string;
612
+ blockId: string;
613
+ overrides: Record<string, unknown>;
614
+ }[];
615
+ }
587
616
 
588
617
  /**
589
618
  * Management API SDK methods — AI content + SEO actions (Option B, portable skill).
@@ -687,6 +716,18 @@ declare class BetterCMSManagementClient extends BetterCMSDeliveryClient {
687
716
  getComponent(id: string): Promise<ManagedComponent>;
688
717
  createComponent(input: ManagedComponentInput): Promise<ManagedComponent>;
689
718
  updateComponent(id: string, input: ManagedComponentInput): Promise<ManagedComponent>;
719
+ /** Sections repeating across the project's pages, proposed as components. */
720
+ listExtractionCandidates(projectId?: string): Promise<ExtractionCandidate[]>;
721
+ /** Fold one candidate into a component and repoint every occurrence at it. */
722
+ extractComponent(input: {
723
+ hash: string;
724
+ name: string;
725
+ slug: string;
726
+ projectId?: string;
727
+ }): Promise<{
728
+ component: ManagedComponent;
729
+ replaced: number;
730
+ }>;
690
731
  /** Write, rewrite, or translate a piece of copy. Returns the suggested text. */
691
732
  writeContent(input: WriteContentInput): Promise<string>;
692
733
  /** Generate SEO metadata for a piece of content (title, description, keywords, JSON-LD). */
@@ -887,12 +928,42 @@ declare function stripStega(value: string): string;
887
928
  * <h1 dangerouslySetInnerHTML={{ __html: rich(f.heroTitle) }}/> // React
888
929
  * seo({ title: plain(page.heroTitle) })
889
930
  */
931
+ /**
932
+ * A block in a Body field's `doc`. Bounded vocabulary — the server only emits what it can
933
+ * parse back, so an unknown `type` means your SDK is older than the content, not that the
934
+ * content is malformed. Handle the default case rather than exhausting on it.
935
+ */
936
+ type DocBlock = {
937
+ /**
938
+ * Stable within THIS document only — never a global key. Two different entries both have a
939
+ * block called "0.0". A cross-document anchor is (entryId, fieldKey, id).
940
+ *
941
+ * Ids on content authored before block ids existed are derived from position, so they SHIFT
942
+ * when that document is edited. Do not persist an id as a bookmark unless you know it came
943
+ * from the editor rather than from the positional fallback.
944
+ */
945
+ readonly id: string;
946
+ readonly type: string;
947
+ readonly [key: string]: unknown;
948
+ };
949
+ /** The `doc` rendition of a Body field — a versioned block array. */
950
+ type DocValue = {
951
+ readonly version: 1;
952
+ readonly blocks: readonly DocBlock[];
953
+ };
890
954
  /** The canonical rich-text envelope returned by the Delivery API. */
891
955
  interface RichTextValue {
892
956
  readonly format?: string;
893
957
  readonly value?: unknown;
894
958
  /** Server-rendered, sanitized HTML. Computed on write. */
895
959
  readonly html?: string;
960
+ /**
961
+ * Structured blocks — present on `document` (Body) fields only, and NOT guaranteed even
962
+ * there: it is derived at write time, so an entry saved before this existed carries none
963
+ * until its next save. There is no backfill. Always branch on its absence; `html` is the
964
+ * field that is always there.
965
+ */
966
+ readonly doc?: DocValue;
896
967
  }
897
968
  /**
898
969
  * A field that may arrive as either shape. Type author-editable text fields with this and the
@@ -1191,4 +1262,4 @@ declare function inviteMember(client: BetterCMSAdminClient, workspaceId: string,
1191
1262
  declare function updateMemberRole(client: BetterCMSAdminClient, workspaceId: string, memberId: string, role: MemberRole): Promise<Member>;
1192
1263
  declare function removeMember(client: BetterCMSAdminClient, workspaceId: string, memberId: string): Promise<void>;
1193
1264
 
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 };
1265
+ 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 ExtractionCandidate, 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
@@ -664,6 +664,21 @@ async function createComponent(client, input) {
664
664
  });
665
665
  return res.data;
666
666
  }
667
+ async function listExtractionCandidates(client, projectId) {
668
+ const qs3 = projectId ? `?projectId=${encodeURIComponent(projectId)}` : "";
669
+ const res = await client.fetchJSON(
670
+ client.url(`/management/components/extraction-candidates${qs3}`),
671
+ { method: "GET" }
672
+ );
673
+ return res.data;
674
+ }
675
+ async function extractComponent(client, input) {
676
+ const res = await client.fetchJSON(
677
+ client.url("/management/components/extract"),
678
+ { method: "POST", body: JSON.stringify(input) }
679
+ );
680
+ return { component: res.data, replaced: res.replaced };
681
+ }
667
682
  async function updateComponent(client, id, input) {
668
683
  const res = await client.fetchJSON(
669
684
  client.url(`/management/components/${id}`),
@@ -852,6 +867,14 @@ var BetterCMSManagementClient = class extends BetterCMSDeliveryClient {
852
867
  updateComponent(id, input) {
853
868
  return updateComponent(this, id, input);
854
869
  }
870
+ /** Sections repeating across the project's pages, proposed as components. */
871
+ listExtractionCandidates(projectId) {
872
+ return listExtractionCandidates(this, projectId);
873
+ }
874
+ /** Fold one candidate into a component and repoint every occurrence at it. */
875
+ extractComponent(input) {
876
+ return extractComponent(this, input);
877
+ }
855
878
  // ── AI (Option B): write/rewrite/translate copy + generate SEO meta (BYOK-metered) ──
856
879
  /** Write, rewrite, or translate a piece of copy. Returns the suggested text. */
857
880
  writeContent(input) {