@bettercms-ai/sdk 1.42.1 → 1.43.1

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
@@ -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-TTj8g07j.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, h as asStringArray, i as createClient, j as formInitialValues, k as isMultiValueField, s as shouldShowField, l as submitForm, t as toggleOption } from './read-client-TTj8g07j.cjs';
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-HyRuGRBt.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-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
 
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-TTj8g07j.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, h as asStringArray, i as createClient, j as formInitialValues, k as isMultiValueField, s as shouldShowField, l as submitForm, t as toggleOption } from './read-client-TTj8g07j.js';
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-CGBWVZQA.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-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
 
package/dist/index.js CHANGED
@@ -594,7 +594,12 @@ var MIME_BY_EXT = {
594
594
  avif: "image/avif",
595
595
  mp4: "video/mp4",
596
596
  webm: "video/webm",
597
+ mov: "video/quicktime",
597
598
  pdf: "application/pdf",
599
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
600
+ // A Lottie animation; the server refuses any other JSON.
601
+ json: "application/json",
602
+ riv: "application/x-rive",
598
603
  // mp3/ogg were server-allowed all along; the SDK sent application/octet-stream for them,
599
604
  // which the allowlist then refused — so an agent could never upload audio.
600
605
  mp3: "audio/mpeg",
@@ -1924,6 +1929,7 @@ async function removeMember(client, workspaceId, memberId) {
1924
1929
  }
1925
1930
 
1926
1931
  // src/forms.ts
1932
+ import { fileExtension, fileFieldLimits } from "@bettercms-ai/types";
1927
1933
  function isMultiValueField(type) {
1928
1934
  return type === "checkboxes";
1929
1935
  }
@@ -1937,6 +1943,41 @@ function toggleOption(value, option, on) {
1937
1943
  return current.filter((v) => v !== option);
1938
1944
  }
1939
1945
  var DEFAULT_BASE_URL5 = "https://api.bettercms.ai";
1946
+ function fileFieldRefusal(limits, file) {
1947
+ const ext = fileExtension(file.name);
1948
+ if (!ext || !limits.accept.includes(ext)) {
1949
+ return `This type of file is not accepted here. Accepted: ${limits.accept.map((e) => `.${e}`).join(", ")}.`;
1950
+ }
1951
+ if (file.size === 0) return "This file is empty.";
1952
+ if (file.size > limits.maxSizeMb * 1024 * 1024) return `This file is larger than ${limits.maxSizeMb} MB.`;
1953
+ return null;
1954
+ }
1955
+ async function uploadFormFile(opts) {
1956
+ const baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL5).replace(/\/+$/, "");
1957
+ const doFetch = opts.fetchImpl ?? globalThis.fetch;
1958
+ let res;
1959
+ try {
1960
+ res = await doFetch(
1961
+ `${baseUrl}/api/v1/forms/public/${encodeURIComponent(opts.formId)}/uploads?field=${encodeURIComponent(opts.fieldKey)}`,
1962
+ {
1963
+ method: "POST",
1964
+ headers: { "Content-Type": "application/octet-stream", "X-Bcms-Filename": encodeURIComponent(opts.file.name) },
1965
+ body: opts.file
1966
+ }
1967
+ );
1968
+ } catch (err) {
1969
+ throw new BetterCMSError(
1970
+ `Network error: ${err instanceof Error ? err.message : String(err)}`,
1971
+ 0,
1972
+ ErrorCodes.NETWORK_ERROR
1973
+ );
1974
+ }
1975
+ if (!res.ok) throw await BetterCMSError.from(res);
1976
+ const json = await res.json().catch(() => ({}));
1977
+ const data = json.data;
1978
+ if (!data?.id) throw new BetterCMSError("The file could not be saved. Please try again.", res.status, ErrorCodes.INTERNAL_ERROR);
1979
+ return { id: data.id, name: data.name ?? opts.file.name, size: data.size ?? opts.file.size };
1980
+ }
1940
1981
  function shouldShowField(field, values) {
1941
1982
  if (!field.showIf) return true;
1942
1983
  const trigger = values[field.showIf.field];
@@ -1947,6 +1988,10 @@ function formInitialValues(form, prefill = {}) {
1947
1988
  const values = {};
1948
1989
  for (const field of form.fields) {
1949
1990
  if (field.type === "step") continue;
1991
+ if (field.type === "file") {
1992
+ values[field.key] = [];
1993
+ continue;
1994
+ }
1950
1995
  if (field.type === "checkbox" || field.type === "consent") {
1951
1996
  values[field.key] = false;
1952
1997
  } else if (field.type === "checkboxes") {
@@ -2034,6 +2079,8 @@ export {
2034
2079
  embeds,
2035
2080
  encodeStega,
2036
2081
  entrySeoInput,
2082
+ fileFieldLimits,
2083
+ fileFieldRefusal,
2037
2084
  formInitialValues,
2038
2085
  getApiKeyUsage,
2039
2086
  getBlockType,
@@ -2102,6 +2149,7 @@ export {
2102
2149
  updatePage,
2103
2150
  updatePageModel,
2104
2151
  updateWorkspace,
2152
+ uploadFormFile,
2105
2153
  uploadMedia
2106
2154
  };
2107
2155
  //# sourceMappingURL=index.js.map