@bettercms-ai/sdk 1.9.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.cjs +47 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -6
- package/dist/index.d.ts +93 -6
- package/dist/index.js +44 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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;
|
|
@@ -444,13 +452,21 @@ declare class BetterCMSError extends Error {
|
|
|
444
452
|
* vanilla embed and the React component never drift.
|
|
445
453
|
*/
|
|
446
454
|
|
|
447
|
-
/**
|
|
448
|
-
|
|
455
|
+
/**
|
|
456
|
+
* Field types the delivery API serializes. Must stay equal to the authoring
|
|
457
|
+
* vocabulary in `packages/db/src/schema/forms.ts` — this list is what every site
|
|
458
|
+
* renderer switches on, so a type missing HERE renders as a plain text input on
|
|
459
|
+
* every published site while the builder happily offers it. `radio`/`checkboxes`
|
|
460
|
+
* were exactly that gap.
|
|
461
|
+
*/
|
|
462
|
+
type DeliveryFormFieldType = "text" | "email" | "phone" | "url" | "number" | "date" | "textarea" | "select" | "radio" | "checkboxes" | "checkbox" | "consent" | "hidden";
|
|
449
463
|
interface DeliveryFormField {
|
|
450
464
|
key: string;
|
|
451
465
|
label: string;
|
|
452
466
|
type: DeliveryFormFieldType;
|
|
453
467
|
placeholder?: string;
|
|
468
|
+
/** Hint rendered under the control. */
|
|
469
|
+
helpText?: string;
|
|
454
470
|
required?: boolean;
|
|
455
471
|
options?: string[];
|
|
456
472
|
defaultValue?: string;
|
|
@@ -460,6 +476,8 @@ interface DeliveryFormField {
|
|
|
460
476
|
equals: string;
|
|
461
477
|
};
|
|
462
478
|
}
|
|
479
|
+
/** The pick-many type, whose value is an array rather than a scalar. */
|
|
480
|
+
declare function isMultiValueField(type: DeliveryFormFieldType): boolean;
|
|
463
481
|
/** A form as delivered to a published/imported site. Mirrors the delivery `/forms` payload. */
|
|
464
482
|
interface DeliveryForm {
|
|
465
483
|
id: string;
|
|
@@ -471,8 +489,13 @@ interface DeliveryForm {
|
|
|
471
489
|
turnstileEnabled?: boolean;
|
|
472
490
|
honeypotField?: string | null;
|
|
473
491
|
}
|
|
474
|
-
|
|
492
|
+
/** `string[]` is the `checkboxes` (pick-many) value; every other type is scalar. */
|
|
493
|
+
type FormValue = string | boolean | string[];
|
|
475
494
|
type FormValues = Record<string, FormValue>;
|
|
495
|
+
/** Read a `checkboxes` value defensively — stored data may predate the array shape. */
|
|
496
|
+
declare function asStringArray(value: FormValue | undefined): string[];
|
|
497
|
+
/** Add/remove `option` from a `checkboxes` value, preserving the field's option order. */
|
|
498
|
+
declare function toggleOption(value: FormValue | undefined, option: string, on: boolean): string[];
|
|
476
499
|
/**
|
|
477
500
|
* Conditional visibility. A `showIf` field is shown only when its trigger field's
|
|
478
501
|
* current value equals the target; non-conditional fields are always shown. The
|
|
@@ -481,8 +504,9 @@ type FormValues = Record<string, FormValue>;
|
|
|
481
504
|
*/
|
|
482
505
|
declare function shouldShowField(field: DeliveryFormField, values: FormValues): boolean;
|
|
483
506
|
/**
|
|
484
|
-
* Build the initial value map: checkbox/consent default to false,
|
|
485
|
-
* to its `defaultValue`, with `prefill` (e.g. URL
|
|
507
|
+
* Build the initial value map: checkbox/consent default to false, checkboxes to an
|
|
508
|
+
* empty array, every other field to its `defaultValue`, with `prefill` (e.g. URL
|
|
509
|
+
* query params) taking precedence.
|
|
486
510
|
*/
|
|
487
511
|
declare function formInitialValues(form: DeliveryForm, prefill?: Record<string, string>): FormValues;
|
|
488
512
|
interface SubmitFormOptions {
|
|
@@ -568,6 +592,27 @@ interface ManagedComponentInput {
|
|
|
568
592
|
blockJson?: unknown[];
|
|
569
593
|
props?: unknown[];
|
|
570
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
|
+
}
|
|
571
616
|
|
|
572
617
|
/**
|
|
573
618
|
* Management API SDK methods — AI content + SEO actions (Option B, portable skill).
|
|
@@ -671,6 +716,18 @@ declare class BetterCMSManagementClient extends BetterCMSDeliveryClient {
|
|
|
671
716
|
getComponent(id: string): Promise<ManagedComponent>;
|
|
672
717
|
createComponent(input: ManagedComponentInput): Promise<ManagedComponent>;
|
|
673
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
|
+
}>;
|
|
674
731
|
/** Write, rewrite, or translate a piece of copy. Returns the suggested text. */
|
|
675
732
|
writeContent(input: WriteContentInput): Promise<string>;
|
|
676
733
|
/** Generate SEO metadata for a piece of content (title, description, keywords, JSON-LD). */
|
|
@@ -871,12 +928,42 @@ declare function stripStega(value: string): string;
|
|
|
871
928
|
* <h1 dangerouslySetInnerHTML={{ __html: rich(f.heroTitle) }}/> // React
|
|
872
929
|
* seo({ title: plain(page.heroTitle) })
|
|
873
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
|
+
};
|
|
874
954
|
/** The canonical rich-text envelope returned by the Delivery API. */
|
|
875
955
|
interface RichTextValue {
|
|
876
956
|
readonly format?: string;
|
|
877
957
|
readonly value?: unknown;
|
|
878
958
|
/** Server-rendered, sanitized HTML. Computed on write. */
|
|
879
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;
|
|
880
967
|
}
|
|
881
968
|
/**
|
|
882
969
|
* A field that may arrive as either shape. Type author-editable text fields with this and the
|
|
@@ -1175,4 +1262,4 @@ declare function inviteMember(client: BetterCMSAdminClient, workspaceId: string,
|
|
|
1175
1262
|
declare function updateMemberRole(client: BetterCMSAdminClient, workspaceId: string, memberId: string, role: MemberRole): Promise<Member>;
|
|
1176
1263
|
declare function removeMember(client: BetterCMSAdminClient, workspaceId: string, memberId: string): Promise<void>;
|
|
1177
1264
|
|
|
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 };
|
|
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;
|
|
@@ -444,13 +452,21 @@ declare class BetterCMSError extends Error {
|
|
|
444
452
|
* vanilla embed and the React component never drift.
|
|
445
453
|
*/
|
|
446
454
|
|
|
447
|
-
/**
|
|
448
|
-
|
|
455
|
+
/**
|
|
456
|
+
* Field types the delivery API serializes. Must stay equal to the authoring
|
|
457
|
+
* vocabulary in `packages/db/src/schema/forms.ts` — this list is what every site
|
|
458
|
+
* renderer switches on, so a type missing HERE renders as a plain text input on
|
|
459
|
+
* every published site while the builder happily offers it. `radio`/`checkboxes`
|
|
460
|
+
* were exactly that gap.
|
|
461
|
+
*/
|
|
462
|
+
type DeliveryFormFieldType = "text" | "email" | "phone" | "url" | "number" | "date" | "textarea" | "select" | "radio" | "checkboxes" | "checkbox" | "consent" | "hidden";
|
|
449
463
|
interface DeliveryFormField {
|
|
450
464
|
key: string;
|
|
451
465
|
label: string;
|
|
452
466
|
type: DeliveryFormFieldType;
|
|
453
467
|
placeholder?: string;
|
|
468
|
+
/** Hint rendered under the control. */
|
|
469
|
+
helpText?: string;
|
|
454
470
|
required?: boolean;
|
|
455
471
|
options?: string[];
|
|
456
472
|
defaultValue?: string;
|
|
@@ -460,6 +476,8 @@ interface DeliveryFormField {
|
|
|
460
476
|
equals: string;
|
|
461
477
|
};
|
|
462
478
|
}
|
|
479
|
+
/** The pick-many type, whose value is an array rather than a scalar. */
|
|
480
|
+
declare function isMultiValueField(type: DeliveryFormFieldType): boolean;
|
|
463
481
|
/** A form as delivered to a published/imported site. Mirrors the delivery `/forms` payload. */
|
|
464
482
|
interface DeliveryForm {
|
|
465
483
|
id: string;
|
|
@@ -471,8 +489,13 @@ interface DeliveryForm {
|
|
|
471
489
|
turnstileEnabled?: boolean;
|
|
472
490
|
honeypotField?: string | null;
|
|
473
491
|
}
|
|
474
|
-
|
|
492
|
+
/** `string[]` is the `checkboxes` (pick-many) value; every other type is scalar. */
|
|
493
|
+
type FormValue = string | boolean | string[];
|
|
475
494
|
type FormValues = Record<string, FormValue>;
|
|
495
|
+
/** Read a `checkboxes` value defensively — stored data may predate the array shape. */
|
|
496
|
+
declare function asStringArray(value: FormValue | undefined): string[];
|
|
497
|
+
/** Add/remove `option` from a `checkboxes` value, preserving the field's option order. */
|
|
498
|
+
declare function toggleOption(value: FormValue | undefined, option: string, on: boolean): string[];
|
|
476
499
|
/**
|
|
477
500
|
* Conditional visibility. A `showIf` field is shown only when its trigger field's
|
|
478
501
|
* current value equals the target; non-conditional fields are always shown. The
|
|
@@ -481,8 +504,9 @@ type FormValues = Record<string, FormValue>;
|
|
|
481
504
|
*/
|
|
482
505
|
declare function shouldShowField(field: DeliveryFormField, values: FormValues): boolean;
|
|
483
506
|
/**
|
|
484
|
-
* Build the initial value map: checkbox/consent default to false,
|
|
485
|
-
* to its `defaultValue`, with `prefill` (e.g. URL
|
|
507
|
+
* Build the initial value map: checkbox/consent default to false, checkboxes to an
|
|
508
|
+
* empty array, every other field to its `defaultValue`, with `prefill` (e.g. URL
|
|
509
|
+
* query params) taking precedence.
|
|
486
510
|
*/
|
|
487
511
|
declare function formInitialValues(form: DeliveryForm, prefill?: Record<string, string>): FormValues;
|
|
488
512
|
interface SubmitFormOptions {
|
|
@@ -568,6 +592,27 @@ interface ManagedComponentInput {
|
|
|
568
592
|
blockJson?: unknown[];
|
|
569
593
|
props?: unknown[];
|
|
570
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
|
+
}
|
|
571
616
|
|
|
572
617
|
/**
|
|
573
618
|
* Management API SDK methods — AI content + SEO actions (Option B, portable skill).
|
|
@@ -671,6 +716,18 @@ declare class BetterCMSManagementClient extends BetterCMSDeliveryClient {
|
|
|
671
716
|
getComponent(id: string): Promise<ManagedComponent>;
|
|
672
717
|
createComponent(input: ManagedComponentInput): Promise<ManagedComponent>;
|
|
673
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
|
+
}>;
|
|
674
731
|
/** Write, rewrite, or translate a piece of copy. Returns the suggested text. */
|
|
675
732
|
writeContent(input: WriteContentInput): Promise<string>;
|
|
676
733
|
/** Generate SEO metadata for a piece of content (title, description, keywords, JSON-LD). */
|
|
@@ -871,12 +928,42 @@ declare function stripStega(value: string): string;
|
|
|
871
928
|
* <h1 dangerouslySetInnerHTML={{ __html: rich(f.heroTitle) }}/> // React
|
|
872
929
|
* seo({ title: plain(page.heroTitle) })
|
|
873
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
|
+
};
|
|
874
954
|
/** The canonical rich-text envelope returned by the Delivery API. */
|
|
875
955
|
interface RichTextValue {
|
|
876
956
|
readonly format?: string;
|
|
877
957
|
readonly value?: unknown;
|
|
878
958
|
/** Server-rendered, sanitized HTML. Computed on write. */
|
|
879
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;
|
|
880
967
|
}
|
|
881
968
|
/**
|
|
882
969
|
* A field that may arrive as either shape. Type author-editable text fields with this and the
|
|
@@ -1175,4 +1262,4 @@ declare function inviteMember(client: BetterCMSAdminClient, workspaceId: string,
|
|
|
1175
1262
|
declare function updateMemberRole(client: BetterCMSAdminClient, workspaceId: string, memberId: string, role: MemberRole): Promise<Member>;
|
|
1176
1263
|
declare function removeMember(client: BetterCMSAdminClient, workspaceId: string, memberId: string): Promise<void>;
|
|
1177
1264
|
|
|
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 };
|
|
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) {
|
|
@@ -1457,16 +1480,33 @@ async function removeMember(client, workspaceId, memberId) {
|
|
|
1457
1480
|
}
|
|
1458
1481
|
|
|
1459
1482
|
// src/forms.ts
|
|
1483
|
+
function isMultiValueField(type) {
|
|
1484
|
+
return type === "checkboxes";
|
|
1485
|
+
}
|
|
1486
|
+
function asStringArray(value) {
|
|
1487
|
+
if (Array.isArray(value)) return value;
|
|
1488
|
+
return value ? [String(value)] : [];
|
|
1489
|
+
}
|
|
1490
|
+
function toggleOption(value, option, on) {
|
|
1491
|
+
const current = asStringArray(value);
|
|
1492
|
+
if (on) return current.includes(option) ? current : [...current, option];
|
|
1493
|
+
return current.filter((v) => v !== option);
|
|
1494
|
+
}
|
|
1460
1495
|
var DEFAULT_BASE_URL5 = "https://api.bettercms.ai";
|
|
1461
1496
|
function shouldShowField(field, values) {
|
|
1462
1497
|
if (!field.showIf) return true;
|
|
1463
|
-
|
|
1498
|
+
const trigger = values[field.showIf.field];
|
|
1499
|
+
if (Array.isArray(trigger)) return trigger.includes(field.showIf.equals);
|
|
1500
|
+
return String(trigger ?? "") === field.showIf.equals;
|
|
1464
1501
|
}
|
|
1465
1502
|
function formInitialValues(form, prefill = {}) {
|
|
1466
1503
|
const values = {};
|
|
1467
1504
|
for (const field of form.fields) {
|
|
1468
1505
|
if (field.type === "checkbox" || field.type === "consent") {
|
|
1469
1506
|
values[field.key] = false;
|
|
1507
|
+
} else if (field.type === "checkboxes") {
|
|
1508
|
+
const seed = prefill[field.key] ?? field.defaultValue ?? "";
|
|
1509
|
+
values[field.key] = seed ? seed.split(",").map((v) => v.trim()).filter(Boolean) : [];
|
|
1470
1510
|
} else {
|
|
1471
1511
|
values[field.key] = prefill[field.key] ?? field.defaultValue ?? "";
|
|
1472
1512
|
}
|
|
@@ -1515,6 +1555,7 @@ export {
|
|
|
1515
1555
|
ErrorCodes,
|
|
1516
1556
|
addModelFields,
|
|
1517
1557
|
addPageFields,
|
|
1558
|
+
asStringArray,
|
|
1518
1559
|
createApiKey,
|
|
1519
1560
|
createClient,
|
|
1520
1561
|
createEntry,
|
|
@@ -1546,6 +1587,7 @@ export {
|
|
|
1546
1587
|
default2 as imageUrlBuilder,
|
|
1547
1588
|
inviteMember,
|
|
1548
1589
|
isBlock,
|
|
1590
|
+
isMultiValueField,
|
|
1549
1591
|
isRichText,
|
|
1550
1592
|
listApiKeys,
|
|
1551
1593
|
listEntries,
|
|
@@ -1573,6 +1615,7 @@ export {
|
|
|
1573
1615
|
signUp,
|
|
1574
1616
|
stripStega,
|
|
1575
1617
|
submitForm,
|
|
1618
|
+
toggleOption,
|
|
1576
1619
|
updateApiKey,
|
|
1577
1620
|
updateEntry,
|
|
1578
1621
|
updateForm2 as updateForm,
|