@bettercms-ai/sdk 1.6.0 → 1.8.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
@@ -559,17 +559,55 @@ interface ManagedComponentInput {
559
559
  props?: unknown[];
560
560
  }
561
561
 
562
+ /**
563
+ * Management API SDK methods — AI content + SEO actions (Option B, portable skill).
564
+ *
565
+ * These call /api/v1/management/ai/* (key-auth, content:manage scope). Stateless: they
566
+ * return a *suggestion* the caller applies with the content/page methods. The MCP server
567
+ * wraps these as the `write_content` / `generate_seo_meta` tools.
568
+ */
569
+
570
+ interface WriteContentInput {
571
+ /** write = draft from a brief, rewrite = improve existing copy, translate = needs targetLang. */
572
+ action: "write" | "rewrite" | "translate";
573
+ /** The source text (a brief for 'write', the copy to change otherwise). */
574
+ text: string;
575
+ instructions?: string;
576
+ /** Required for 'translate', e.g. "Spanish". */
577
+ targetLang?: string;
578
+ context?: string;
579
+ }
580
+ interface SeoMetaInput {
581
+ /** The content to derive SEO metadata from. */
582
+ text: string;
583
+ context?: string;
584
+ }
585
+ interface SeoMeta {
586
+ metaTitle: string;
587
+ metaDescription: string;
588
+ keywords: string[];
589
+ jsonLd?: Record<string, unknown>;
590
+ }
591
+
562
592
  interface BetterCMSManagementOptions {
563
593
  /** Base URL of the Management API. Defaults to https://api.bettercms.ai/v1 */
564
594
  baseUrl?: string;
565
595
  /** A content:manage scoped API key. */
566
596
  apiKey: string;
597
+ /**
598
+ * Target project (id or slug), sent as the X-BCMS-Project header.
599
+ * REQUIRED for workspace-scoped keys — content writes (createEntry, createPage,
600
+ * createModel, …) must land in a project. Project-scoped keys (`bcms_proj_…`)
601
+ * don't need it; if set, it must match the key's own project.
602
+ */
603
+ project?: string;
567
604
  /** Request timeout per attempt in ms. Defaults to 10000. */
568
605
  timeout?: number;
569
606
  }
570
607
  declare class BetterCMSManagementClient extends BetterCMSDeliveryClient {
571
608
  readonly timeout: number;
572
609
  private readonly _apiKey;
610
+ private readonly _project?;
573
611
  constructor(options: BetterCMSManagementOptions);
574
612
  headers(): Record<string, string>;
575
613
  /** Management API URL: baseUrl + path (path is workspace-scoped via the key). */
@@ -623,6 +661,10 @@ declare class BetterCMSManagementClient extends BetterCMSDeliveryClient {
623
661
  getComponent(id: string): Promise<ManagedComponent>;
624
662
  createComponent(input: ManagedComponentInput): Promise<ManagedComponent>;
625
663
  updateComponent(id: string, input: ManagedComponentInput): Promise<ManagedComponent>;
664
+ /** Write, rewrite, or translate a piece of copy. Returns the suggested text. */
665
+ writeContent(input: WriteContentInput): Promise<string>;
666
+ /** Generate SEO metadata for a piece of content (title, description, keywords, JSON-LD). */
667
+ generateSeoMeta(input: SeoMetaInput): Promise<SeoMeta>;
626
668
  }
627
669
 
628
670
  interface AuthResult {
@@ -1069,4 +1111,4 @@ declare function inviteMember(client: BetterCMSAdminClient, workspaceId: string,
1069
1111
  declare function updateMemberRole(client: BetterCMSAdminClient, workspaceId: string, memberId: string, role: MemberRole): Promise<Member>;
1070
1112
  declare function removeMember(client: BetterCMSAdminClient, workspaceId: string, memberId: string): Promise<void>;
1071
1113
 
1072
- 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 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, 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 };
1114
+ 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 };
package/dist/index.d.ts CHANGED
@@ -559,17 +559,55 @@ interface ManagedComponentInput {
559
559
  props?: unknown[];
560
560
  }
561
561
 
562
+ /**
563
+ * Management API SDK methods — AI content + SEO actions (Option B, portable skill).
564
+ *
565
+ * These call /api/v1/management/ai/* (key-auth, content:manage scope). Stateless: they
566
+ * return a *suggestion* the caller applies with the content/page methods. The MCP server
567
+ * wraps these as the `write_content` / `generate_seo_meta` tools.
568
+ */
569
+
570
+ interface WriteContentInput {
571
+ /** write = draft from a brief, rewrite = improve existing copy, translate = needs targetLang. */
572
+ action: "write" | "rewrite" | "translate";
573
+ /** The source text (a brief for 'write', the copy to change otherwise). */
574
+ text: string;
575
+ instructions?: string;
576
+ /** Required for 'translate', e.g. "Spanish". */
577
+ targetLang?: string;
578
+ context?: string;
579
+ }
580
+ interface SeoMetaInput {
581
+ /** The content to derive SEO metadata from. */
582
+ text: string;
583
+ context?: string;
584
+ }
585
+ interface SeoMeta {
586
+ metaTitle: string;
587
+ metaDescription: string;
588
+ keywords: string[];
589
+ jsonLd?: Record<string, unknown>;
590
+ }
591
+
562
592
  interface BetterCMSManagementOptions {
563
593
  /** Base URL of the Management API. Defaults to https://api.bettercms.ai/v1 */
564
594
  baseUrl?: string;
565
595
  /** A content:manage scoped API key. */
566
596
  apiKey: string;
597
+ /**
598
+ * Target project (id or slug), sent as the X-BCMS-Project header.
599
+ * REQUIRED for workspace-scoped keys — content writes (createEntry, createPage,
600
+ * createModel, …) must land in a project. Project-scoped keys (`bcms_proj_…`)
601
+ * don't need it; if set, it must match the key's own project.
602
+ */
603
+ project?: string;
567
604
  /** Request timeout per attempt in ms. Defaults to 10000. */
568
605
  timeout?: number;
569
606
  }
570
607
  declare class BetterCMSManagementClient extends BetterCMSDeliveryClient {
571
608
  readonly timeout: number;
572
609
  private readonly _apiKey;
610
+ private readonly _project?;
573
611
  constructor(options: BetterCMSManagementOptions);
574
612
  headers(): Record<string, string>;
575
613
  /** Management API URL: baseUrl + path (path is workspace-scoped via the key). */
@@ -623,6 +661,10 @@ declare class BetterCMSManagementClient extends BetterCMSDeliveryClient {
623
661
  getComponent(id: string): Promise<ManagedComponent>;
624
662
  createComponent(input: ManagedComponentInput): Promise<ManagedComponent>;
625
663
  updateComponent(id: string, input: ManagedComponentInput): Promise<ManagedComponent>;
664
+ /** Write, rewrite, or translate a piece of copy. Returns the suggested text. */
665
+ writeContent(input: WriteContentInput): Promise<string>;
666
+ /** Generate SEO metadata for a piece of content (title, description, keywords, JSON-LD). */
667
+ generateSeoMeta(input: SeoMetaInput): Promise<SeoMeta>;
626
668
  }
627
669
 
628
670
  interface AuthResult {
@@ -1069,4 +1111,4 @@ declare function inviteMember(client: BetterCMSAdminClient, workspaceId: string,
1069
1111
  declare function updateMemberRole(client: BetterCMSAdminClient, workspaceId: string, memberId: string, role: MemberRole): Promise<Member>;
1070
1112
  declare function removeMember(client: BetterCMSAdminClient, workspaceId: string, memberId: string): Promise<void>;
1071
1113
 
1072
- 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 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, 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 };
1114
+ 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 };
package/dist/index.js CHANGED
@@ -649,6 +649,22 @@ async function updateComponent(client, id, input) {
649
649
  return res.data;
650
650
  }
651
651
 
652
+ // src/methods/management/ai.ts
653
+ async function writeContent(client, input) {
654
+ const res = await client.fetchJSON(client.url("/management/ai/content"), {
655
+ method: "POST",
656
+ body: JSON.stringify(input)
657
+ });
658
+ return res.data.suggestion;
659
+ }
660
+ async function generateSeoMeta(client, input) {
661
+ const res = await client.fetchJSON(client.url("/management/ai/seo-meta"), {
662
+ method: "POST",
663
+ body: JSON.stringify(input)
664
+ });
665
+ return res.data;
666
+ }
667
+
652
668
  // src/management-client.ts
653
669
  var DEFAULT_BASE_URL2 = "https://api.bettercms.ai/v1";
654
670
  var DEFAULT_TIMEOUT2 = 1e4;
@@ -657,15 +673,18 @@ var RETRY_DELAYS2 = [1e3, 2e3, 4e3];
657
673
  var BetterCMSManagementClient = class extends BetterCMSDeliveryClient {
658
674
  timeout;
659
675
  _apiKey;
676
+ _project;
660
677
  constructor(options) {
661
678
  super({ workspace: "", baseUrl: options.baseUrl ?? DEFAULT_BASE_URL2 });
662
679
  this._apiKey = options.apiKey;
680
+ this._project = options.project;
663
681
  this.timeout = options.timeout ?? DEFAULT_TIMEOUT2;
664
682
  }
665
683
  headers() {
666
684
  return {
667
685
  "Content-Type": "application/json",
668
- "X-API-Key": this._apiKey
686
+ "X-API-Key": this._apiKey,
687
+ ...this._project ? { "X-BCMS-Project": this._project } : {}
669
688
  };
670
689
  }
671
690
  /** Management API URL: baseUrl + path (path is workspace-scoped via the key). */
@@ -810,6 +829,15 @@ var BetterCMSManagementClient = class extends BetterCMSDeliveryClient {
810
829
  updateComponent(id, input) {
811
830
  return updateComponent(this, id, input);
812
831
  }
832
+ // ── AI (Option B): write/rewrite/translate copy + generate SEO meta (BYOK-metered) ──
833
+ /** Write, rewrite, or translate a piece of copy. Returns the suggested text. */
834
+ writeContent(input) {
835
+ return writeContent(this, input);
836
+ }
837
+ /** Generate SEO metadata for a piece of content (title, description, keywords, JSON-LD). */
838
+ generateSeoMeta(input) {
839
+ return generateSeoMeta(this, input);
840
+ }
813
841
  };
814
842
  function sleep2(ms) {
815
843
  return new Promise((resolve) => setTimeout(resolve, ms));