@bettercms-ai/sdk 1.42.0 → 1.43.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/README.md +19 -0
- package/dist/index.cjs +49 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -1
- package/dist/{read-CGBWVZQA.d.ts → read-BGBG_JvH.d.ts} +3 -3
- package/dist/{read-HyRuGRBt.d.cts → read-CDoVuCrS.d.cts} +3 -3
- package/dist/{read-client-TTj8g07j.d.cts → read-client-DHQb3lve.d.cts} +46 -2
- package/dist/{read-client-TTj8g07j.d.ts → read-client-DHQb3lve.d.ts} +46 -2
- package/dist/read.cjs +48 -2
- package/dist/read.cjs.map +1 -1
- package/dist/read.d.cts +3 -3
- package/dist/read.d.ts +3 -3
- package/dist/read.js +44 -1
- package/dist/read.js.map +1 -1
- package/dist/sections.d.cts +1 -1
- package/dist/sections.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as _bettercms_ai_types from '@bettercms-ai/types';
|
|
2
2
|
import { ContentPageResult, Content, DeliveredLayout, ContentModelField, Fieldset, ComponentPreview, LayoutStructureDocument, LayoutDataDocument, PageLayoutOverrideDocument, ManagementLayoutCommand, AuthUser, AuthSession, SignInInput, SignUpInput, Page, MediaAsset, FormField, Form, FormSubmission, Workspace, ApiKey, ApiKeyPermission, ApiKeyTokenType } from '@bettercms-ai/types';
|
|
3
|
-
export { ApiError, ApiKey, ApiKeyPermission, ApiKeyTokenType, AssertEqual, AuthSession, AuthUser, BetterCMSErrorCode, BlockType, ButtonBlock, ButtonProps, ColumnsBlock, ColumnsProps, Content, ContentBlock, ContentEntry, ContentModel, ContentModelField, ContentPageResult, ContentResponse, DeepReadonly, DeliveryComponent, DeliveryEntry, DeliveryList, DeliveryPage, EmbedCard, Form, FormBlock, FormField, FormProps, FormSubmission, HeadingBlock, HeadingProps, ImageBlock, ImageProps, MediaAsset, Page, PageMetaJson, PaginatedResult, Perspective, Redirect, ResolvedAuthor, ResolvedPost, RichTextEmbeds, RichTextResolved, SignInInput, SignUpInput, SiteSeoDefaults, SpacerBlock, SpacerProps, TextBlock, TextProps, VideoBlock, VideoProps, Workspace, getBlockType, isBlock } from '@bettercms-ai/types';
|
|
4
|
-
import { D as DeliveryFormField } from './read-client-
|
|
5
|
-
export { a as BCMSClientError, E as BCMSErrorCodes, a as BetterCMSError, B as BetterCMSReadClient, C as CreateClientOptions, b as DeliveryForm, c as DeliveryFormFieldType, E as ErrorCodes, F as FormSubmitError, d as FormValue, e as FormValues, G as GetEntryOptions, L as ListEntriesOptions, f as ListPagesOptions, S as SubmitFormOptions, g as SubmitFormResult, h as
|
|
3
|
+
export { ApiError, ApiKey, ApiKeyPermission, ApiKeyTokenType, AssertEqual, AuthSession, AuthUser, BetterCMSErrorCode, BlockType, ButtonBlock, ButtonProps, ColumnsBlock, ColumnsProps, Content, ContentBlock, ContentEntry, ContentModel, ContentModelField, ContentPageResult, ContentResponse, DeepReadonly, DeliveryComponent, DeliveryEntry, DeliveryList, DeliveryPage, EmbedCard, Form, FormBlock, FormField, FormProps, FormSubmission, HeadingBlock, HeadingProps, ImageBlock, ImageProps, MediaAsset, Page, PageMetaJson, PaginatedResult, Perspective, Redirect, ResolvedAuthor, ResolvedPost, RichTextEmbeds, RichTextResolved, SignInInput, SignUpInput, SiteSeoDefaults, SpacerBlock, SpacerProps, TextBlock, TextProps, VideoBlock, VideoProps, Workspace, fileFieldLimits, getBlockType, isBlock } from '@bettercms-ai/types';
|
|
4
|
+
import { D as DeliveryFormField } from './read-client-DHQb3lve.cjs';
|
|
5
|
+
export { a as BCMSClientError, E as BCMSErrorCodes, a as BetterCMSError, B as BetterCMSReadClient, C as CreateClientOptions, b as DeliveryForm, c as DeliveryFormFieldType, E as ErrorCodes, F as FormSubmitError, d as FormValue, e as FormValues, G as GetEntryOptions, L as ListEntriesOptions, f as ListPagesOptions, S as SubmitFormOptions, g as SubmitFormResult, U as UploadFormFileOptions, h as UploadedFormFile, i as asStringArray, j as createClient, k as fileFieldRefusal, l as formInitialValues, m as isMultiValueField, s as shouldShowField, n as submitForm, t as toggleOption, u as uploadFormFile } from './read-client-DHQb3lve.cjs';
|
|
6
6
|
export { C as CONTENT_APPLIED, a as ContentAppliedMessage, E as EDITOR_FRAME_NAME, c as contentApplied, i as inEditor, o as onContentApplied } from './in-editor-D1vXPgJh.cjs';
|
|
7
|
-
export { P as PORTABLE_TEXT_FORMAT, a as PublishedContent, R as ResolvedHolder, b as RichTextValue, S as SearchHit, c as SearchOptions, T as TextOrRich, e as embeds, i as isRichText, l as lines, p as plain, d as portableText, f as publishedContentFile, g as publishedEntry, r as readPublishedContent, h as resetPublishedContentCache, j as resolved, k as rich, s as search } from './read-
|
|
7
|
+
export { P as PORTABLE_TEXT_FORMAT, a as PublishedContent, R as ResolvedHolder, b as RichTextValue, S as SearchHit, c as SearchOptions, T as TextOrRich, e as embeds, i as isRichText, l as lines, p as plain, d as portableText, f as publishedContentFile, g as publishedEntry, r as readPublishedContent, h as resetPublishedContentCache, j as resolved, k as rich, s as search } from './read-CDoVuCrS.cjs';
|
|
8
8
|
export { ResolvedSeo, SeoInput, SeoLocation, entrySeoInput, resolveSeo } from './seo.cjs';
|
|
9
9
|
export { ImageFit, ImageFormat, ImageSource, ImageUrlBuilder, ImageUrlOptions, imageUrl, default as imageUrlBuilder, imageValueObjectPosition, imageValueUrl } from '@bettercms-ai/image-url';
|
|
10
10
|
|
|
@@ -520,6 +520,11 @@ interface ManagedComponentSummary {
|
|
|
520
520
|
builtin?: boolean;
|
|
521
521
|
/** Whose block it is: one page's own (`page`), a deliberately `shared` one, or the `project`'s. */
|
|
522
522
|
ownership?: "page" | "shared" | "project";
|
|
523
|
+
/** How many draft pages place it and the first few paths; absent on builtins and workspace lists. */
|
|
524
|
+
usedOn?: {
|
|
525
|
+
pages: number;
|
|
526
|
+
paths: string[];
|
|
527
|
+
};
|
|
523
528
|
}
|
|
524
529
|
/**
|
|
525
530
|
* A set of sections that repeat across the project's pages, proposed as one component.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as _bettercms_ai_types from '@bettercms-ai/types';
|
|
2
2
|
import { ContentPageResult, Content, DeliveredLayout, ContentModelField, Fieldset, ComponentPreview, LayoutStructureDocument, LayoutDataDocument, PageLayoutOverrideDocument, ManagementLayoutCommand, AuthUser, AuthSession, SignInInput, SignUpInput, Page, MediaAsset, FormField, Form, FormSubmission, Workspace, ApiKey, ApiKeyPermission, ApiKeyTokenType } from '@bettercms-ai/types';
|
|
3
|
-
export { ApiError, ApiKey, ApiKeyPermission, ApiKeyTokenType, AssertEqual, AuthSession, AuthUser, BetterCMSErrorCode, BlockType, ButtonBlock, ButtonProps, ColumnsBlock, ColumnsProps, Content, ContentBlock, ContentEntry, ContentModel, ContentModelField, ContentPageResult, ContentResponse, DeepReadonly, DeliveryComponent, DeliveryEntry, DeliveryList, DeliveryPage, EmbedCard, Form, FormBlock, FormField, FormProps, FormSubmission, HeadingBlock, HeadingProps, ImageBlock, ImageProps, MediaAsset, Page, PageMetaJson, PaginatedResult, Perspective, Redirect, ResolvedAuthor, ResolvedPost, RichTextEmbeds, RichTextResolved, SignInInput, SignUpInput, SiteSeoDefaults, SpacerBlock, SpacerProps, TextBlock, TextProps, VideoBlock, VideoProps, Workspace, getBlockType, isBlock } from '@bettercms-ai/types';
|
|
4
|
-
import { D as DeliveryFormField } from './read-client-
|
|
5
|
-
export { a as BCMSClientError, E as BCMSErrorCodes, a as BetterCMSError, B as BetterCMSReadClient, C as CreateClientOptions, b as DeliveryForm, c as DeliveryFormFieldType, E as ErrorCodes, F as FormSubmitError, d as FormValue, e as FormValues, G as GetEntryOptions, L as ListEntriesOptions, f as ListPagesOptions, S as SubmitFormOptions, g as SubmitFormResult, h as
|
|
3
|
+
export { ApiError, ApiKey, ApiKeyPermission, ApiKeyTokenType, AssertEqual, AuthSession, AuthUser, BetterCMSErrorCode, BlockType, ButtonBlock, ButtonProps, ColumnsBlock, ColumnsProps, Content, ContentBlock, ContentEntry, ContentModel, ContentModelField, ContentPageResult, ContentResponse, DeepReadonly, DeliveryComponent, DeliveryEntry, DeliveryList, DeliveryPage, EmbedCard, Form, FormBlock, FormField, FormProps, FormSubmission, HeadingBlock, HeadingProps, ImageBlock, ImageProps, MediaAsset, Page, PageMetaJson, PaginatedResult, Perspective, Redirect, ResolvedAuthor, ResolvedPost, RichTextEmbeds, RichTextResolved, SignInInput, SignUpInput, SiteSeoDefaults, SpacerBlock, SpacerProps, TextBlock, TextProps, VideoBlock, VideoProps, Workspace, fileFieldLimits, getBlockType, isBlock } from '@bettercms-ai/types';
|
|
4
|
+
import { D as DeliveryFormField } from './read-client-DHQb3lve.js';
|
|
5
|
+
export { a as BCMSClientError, E as BCMSErrorCodes, a as BetterCMSError, B as BetterCMSReadClient, C as CreateClientOptions, b as DeliveryForm, c as DeliveryFormFieldType, E as ErrorCodes, F as FormSubmitError, d as FormValue, e as FormValues, G as GetEntryOptions, L as ListEntriesOptions, f as ListPagesOptions, S as SubmitFormOptions, g as SubmitFormResult, U as UploadFormFileOptions, h as UploadedFormFile, i as asStringArray, j as createClient, k as fileFieldRefusal, l as formInitialValues, m as isMultiValueField, s as shouldShowField, n as submitForm, t as toggleOption, u as uploadFormFile } from './read-client-DHQb3lve.js';
|
|
6
6
|
export { C as CONTENT_APPLIED, a as ContentAppliedMessage, E as EDITOR_FRAME_NAME, c as contentApplied, i as inEditor, o as onContentApplied } from './in-editor-D1vXPgJh.js';
|
|
7
|
-
export { P as PORTABLE_TEXT_FORMAT, a as PublishedContent, R as ResolvedHolder, b as RichTextValue, S as SearchHit, c as SearchOptions, T as TextOrRich, e as embeds, i as isRichText, l as lines, p as plain, d as portableText, f as publishedContentFile, g as publishedEntry, r as readPublishedContent, h as resetPublishedContentCache, j as resolved, k as rich, s as search } from './read-
|
|
7
|
+
export { P as PORTABLE_TEXT_FORMAT, a as PublishedContent, R as ResolvedHolder, b as RichTextValue, S as SearchHit, c as SearchOptions, T as TextOrRich, e as embeds, i as isRichText, l as lines, p as plain, d as portableText, f as publishedContentFile, g as publishedEntry, r as readPublishedContent, h as resetPublishedContentCache, j as resolved, k as rich, s as search } from './read-BGBG_JvH.js';
|
|
8
8
|
export { ResolvedSeo, SeoInput, SeoLocation, entrySeoInput, resolveSeo } from './seo.js';
|
|
9
9
|
export { ImageFit, ImageFormat, ImageSource, ImageUrlBuilder, ImageUrlOptions, imageUrl, default as imageUrlBuilder, imageValueObjectPosition, imageValueUrl } from '@bettercms-ai/image-url';
|
|
10
10
|
|
|
@@ -520,6 +520,11 @@ interface ManagedComponentSummary {
|
|
|
520
520
|
builtin?: boolean;
|
|
521
521
|
/** Whose block it is: one page's own (`page`), a deliberately `shared` one, or the `project`'s. */
|
|
522
522
|
ownership?: "page" | "shared" | "project";
|
|
523
|
+
/** How many draft pages place it and the first few paths; absent on builtins and workspace lists. */
|
|
524
|
+
usedOn?: {
|
|
525
|
+
pages: number;
|
|
526
|
+
paths: string[];
|
|
527
|
+
};
|
|
523
528
|
}
|
|
524
529
|
/**
|
|
525
530
|
* A set of sections that repeat across the project's pages, proposed as one component.
|
package/dist/index.js
CHANGED
|
@@ -1924,6 +1924,7 @@ async function removeMember(client, workspaceId, memberId) {
|
|
|
1924
1924
|
}
|
|
1925
1925
|
|
|
1926
1926
|
// src/forms.ts
|
|
1927
|
+
import { fileExtension, fileFieldLimits } from "@bettercms-ai/types";
|
|
1927
1928
|
function isMultiValueField(type) {
|
|
1928
1929
|
return type === "checkboxes";
|
|
1929
1930
|
}
|
|
@@ -1937,6 +1938,41 @@ function toggleOption(value, option, on) {
|
|
|
1937
1938
|
return current.filter((v) => v !== option);
|
|
1938
1939
|
}
|
|
1939
1940
|
var DEFAULT_BASE_URL5 = "https://api.bettercms.ai";
|
|
1941
|
+
function fileFieldRefusal(limits, file) {
|
|
1942
|
+
const ext = fileExtension(file.name);
|
|
1943
|
+
if (!ext || !limits.accept.includes(ext)) {
|
|
1944
|
+
return `This type of file is not accepted here. Accepted: ${limits.accept.map((e) => `.${e}`).join(", ")}.`;
|
|
1945
|
+
}
|
|
1946
|
+
if (file.size === 0) return "This file is empty.";
|
|
1947
|
+
if (file.size > limits.maxSizeMb * 1024 * 1024) return `This file is larger than ${limits.maxSizeMb} MB.`;
|
|
1948
|
+
return null;
|
|
1949
|
+
}
|
|
1950
|
+
async function uploadFormFile(opts) {
|
|
1951
|
+
const baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL5).replace(/\/+$/, "");
|
|
1952
|
+
const doFetch = opts.fetchImpl ?? globalThis.fetch;
|
|
1953
|
+
let res;
|
|
1954
|
+
try {
|
|
1955
|
+
res = await doFetch(
|
|
1956
|
+
`${baseUrl}/api/v1/forms/public/${encodeURIComponent(opts.formId)}/uploads?field=${encodeURIComponent(opts.fieldKey)}`,
|
|
1957
|
+
{
|
|
1958
|
+
method: "POST",
|
|
1959
|
+
headers: { "Content-Type": "application/octet-stream", "X-Bcms-Filename": encodeURIComponent(opts.file.name) },
|
|
1960
|
+
body: opts.file
|
|
1961
|
+
}
|
|
1962
|
+
);
|
|
1963
|
+
} catch (err) {
|
|
1964
|
+
throw new BetterCMSError(
|
|
1965
|
+
`Network error: ${err instanceof Error ? err.message : String(err)}`,
|
|
1966
|
+
0,
|
|
1967
|
+
ErrorCodes.NETWORK_ERROR
|
|
1968
|
+
);
|
|
1969
|
+
}
|
|
1970
|
+
if (!res.ok) throw await BetterCMSError.from(res);
|
|
1971
|
+
const json = await res.json().catch(() => ({}));
|
|
1972
|
+
const data = json.data;
|
|
1973
|
+
if (!data?.id) throw new BetterCMSError("The file could not be saved. Please try again.", res.status, ErrorCodes.INTERNAL_ERROR);
|
|
1974
|
+
return { id: data.id, name: data.name ?? opts.file.name, size: data.size ?? opts.file.size };
|
|
1975
|
+
}
|
|
1940
1976
|
function shouldShowField(field, values) {
|
|
1941
1977
|
if (!field.showIf) return true;
|
|
1942
1978
|
const trigger = values[field.showIf.field];
|
|
@@ -1947,6 +1983,10 @@ function formInitialValues(form, prefill = {}) {
|
|
|
1947
1983
|
const values = {};
|
|
1948
1984
|
for (const field of form.fields) {
|
|
1949
1985
|
if (field.type === "step") continue;
|
|
1986
|
+
if (field.type === "file") {
|
|
1987
|
+
values[field.key] = [];
|
|
1988
|
+
continue;
|
|
1989
|
+
}
|
|
1950
1990
|
if (field.type === "checkbox" || field.type === "consent") {
|
|
1951
1991
|
values[field.key] = false;
|
|
1952
1992
|
} else if (field.type === "checkboxes") {
|
|
@@ -2034,6 +2074,8 @@ export {
|
|
|
2034
2074
|
embeds,
|
|
2035
2075
|
encodeStega,
|
|
2036
2076
|
entrySeoInput,
|
|
2077
|
+
fileFieldLimits,
|
|
2078
|
+
fileFieldRefusal,
|
|
2037
2079
|
formInitialValues,
|
|
2038
2080
|
getApiKeyUsage,
|
|
2039
2081
|
getBlockType,
|
|
@@ -2102,6 +2144,7 @@ export {
|
|
|
2102
2144
|
updatePage,
|
|
2103
2145
|
updatePageModel,
|
|
2104
2146
|
updateWorkspace,
|
|
2147
|
+
uploadFormFile,
|
|
2105
2148
|
uploadMedia
|
|
2106
2149
|
};
|
|
2107
2150
|
//# sourceMappingURL=index.js.map
|