@bettercms-ai/sdk 1.16.0 → 1.18.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 +34 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _bettercms_ai_types from '@bettercms-ai/types';
|
|
2
|
-
import { ContentPageResult, Content, DeliveredLayout, ContentModelField, BetterCMSErrorCode, LayoutStructureDocument, LayoutDataDocument, PageLayoutOverrideDocument, ManagementLayoutCommand, AuthUser, AuthSession, SignInInput, SignUpInput, Perspective, DeliveryEntry, DeliveryList, DeliveryPage, PageMetaJson, SiteSeoDefaults, Page, MediaAsset, 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, DeliveryEntry, DeliveryList, DeliveryPage, Form, FormBlock, FormField, FormProps, FormSubmission, HeadingBlock, HeadingProps, ImageBlock, ImageProps, MediaAsset, Page, PageMetaJson, PaginatedResult, Perspective, Redirect, SignInInput, SignUpInput, SiteSeoDefaults, SpacerBlock, SpacerProps, TextBlock, TextProps, VideoBlock, VideoProps, Workspace, getBlockType, isBlock } from '@bettercms-ai/types';
|
|
2
|
+
import { ContentPageResult, Content, DeliveredLayout, ContentModelField, BetterCMSErrorCode, LayoutStructureDocument, LayoutDataDocument, PageLayoutOverrideDocument, ManagementLayoutCommand, AuthUser, AuthSession, SignInInput, SignUpInput, Perspective, DeliveryEntry, DeliveryList, DeliveryPage, DeliveryComponent, PageMetaJson, SiteSeoDefaults, Page, MediaAsset, 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, Form, FormBlock, FormField, FormProps, FormSubmission, HeadingBlock, HeadingProps, ImageBlock, ImageProps, MediaAsset, Page, PageMetaJson, PaginatedResult, Perspective, Redirect, SignInInput, SignUpInput, SiteSeoDefaults, SpacerBlock, SpacerProps, TextBlock, TextProps, VideoBlock, VideoProps, Workspace, getBlockType, isBlock } from '@bettercms-ai/types';
|
|
4
4
|
export { ImageFit, ImageFormat, ImageSource, ImageUrlBuilder, ImageUrlOptions, imageUrl, default as imageUrlBuilder } from '@bettercms-ai/image-url';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1007,6 +1007,12 @@ interface BetterCMSReadClient {
|
|
|
1007
1007
|
listEntries<T = Record<string, unknown>>(opts?: ListEntriesOptions): Promise<DeliveryList<DeliveryEntry<T>>>;
|
|
1008
1008
|
getPage(slug: string): Promise<DeliveryPage | null>;
|
|
1009
1009
|
listPages(opts?: ListPagesOptions): Promise<DeliveryList<DeliveryPage>>;
|
|
1010
|
+
/**
|
|
1011
|
+
* The workspace's reusable component definitions, for resolving `component` blocks.
|
|
1012
|
+
* Under `perspective: "drafts"` this is the DRAFT definition — what makes an SSR render
|
|
1013
|
+
* of a draft page look like the page the editor is showing.
|
|
1014
|
+
*/
|
|
1015
|
+
listComponents(): Promise<DeliveryComponent[]>;
|
|
1010
1016
|
/** Fetch the project-scoped Global Layout for the active perspective. */
|
|
1011
1017
|
getLayout(): Promise<DeliveredLayout | null>;
|
|
1012
1018
|
listForms(opts?: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _bettercms_ai_types from '@bettercms-ai/types';
|
|
2
|
-
import { ContentPageResult, Content, DeliveredLayout, ContentModelField, BetterCMSErrorCode, LayoutStructureDocument, LayoutDataDocument, PageLayoutOverrideDocument, ManagementLayoutCommand, AuthUser, AuthSession, SignInInput, SignUpInput, Perspective, DeliveryEntry, DeliveryList, DeliveryPage, PageMetaJson, SiteSeoDefaults, Page, MediaAsset, 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, DeliveryEntry, DeliveryList, DeliveryPage, Form, FormBlock, FormField, FormProps, FormSubmission, HeadingBlock, HeadingProps, ImageBlock, ImageProps, MediaAsset, Page, PageMetaJson, PaginatedResult, Perspective, Redirect, SignInInput, SignUpInput, SiteSeoDefaults, SpacerBlock, SpacerProps, TextBlock, TextProps, VideoBlock, VideoProps, Workspace, getBlockType, isBlock } from '@bettercms-ai/types';
|
|
2
|
+
import { ContentPageResult, Content, DeliveredLayout, ContentModelField, BetterCMSErrorCode, LayoutStructureDocument, LayoutDataDocument, PageLayoutOverrideDocument, ManagementLayoutCommand, AuthUser, AuthSession, SignInInput, SignUpInput, Perspective, DeliveryEntry, DeliveryList, DeliveryPage, DeliveryComponent, PageMetaJson, SiteSeoDefaults, Page, MediaAsset, 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, Form, FormBlock, FormField, FormProps, FormSubmission, HeadingBlock, HeadingProps, ImageBlock, ImageProps, MediaAsset, Page, PageMetaJson, PaginatedResult, Perspective, Redirect, SignInInput, SignUpInput, SiteSeoDefaults, SpacerBlock, SpacerProps, TextBlock, TextProps, VideoBlock, VideoProps, Workspace, getBlockType, isBlock } from '@bettercms-ai/types';
|
|
4
4
|
export { ImageFit, ImageFormat, ImageSource, ImageUrlBuilder, ImageUrlOptions, imageUrl, default as imageUrlBuilder } from '@bettercms-ai/image-url';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1007,6 +1007,12 @@ interface BetterCMSReadClient {
|
|
|
1007
1007
|
listEntries<T = Record<string, unknown>>(opts?: ListEntriesOptions): Promise<DeliveryList<DeliveryEntry<T>>>;
|
|
1008
1008
|
getPage(slug: string): Promise<DeliveryPage | null>;
|
|
1009
1009
|
listPages(opts?: ListPagesOptions): Promise<DeliveryList<DeliveryPage>>;
|
|
1010
|
+
/**
|
|
1011
|
+
* The workspace's reusable component definitions, for resolving `component` blocks.
|
|
1012
|
+
* Under `perspective: "drafts"` this is the DRAFT definition — what makes an SSR render
|
|
1013
|
+
* of a draft page look like the page the editor is showing.
|
|
1014
|
+
*/
|
|
1015
|
+
listComponents(): Promise<DeliveryComponent[]>;
|
|
1010
1016
|
/** Fetch the project-scoped Global Layout for the active perspective. */
|
|
1011
1017
|
getLayout(): Promise<DeliveredLayout | null>;
|
|
1012
1018
|
listForms(opts?: {
|
package/dist/index.js
CHANGED
|
@@ -1130,6 +1130,16 @@ function unwrap(json) {
|
|
|
1130
1130
|
}
|
|
1131
1131
|
return json;
|
|
1132
1132
|
}
|
|
1133
|
+
function tokenSlug(token) {
|
|
1134
|
+
try {
|
|
1135
|
+
const part = token.split(".")[1];
|
|
1136
|
+
if (!part) return null;
|
|
1137
|
+
const json = atob(part.replace(/-/g, "+").replace(/_/g, "/"));
|
|
1138
|
+
return JSON.parse(json).entrySlug ?? null;
|
|
1139
|
+
} catch {
|
|
1140
|
+
return null;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1133
1143
|
function createRequestCache() {
|
|
1134
1144
|
const inflight = /* @__PURE__ */ new Map();
|
|
1135
1145
|
const settled = /* @__PURE__ */ new Map();
|
|
@@ -1230,6 +1240,23 @@ function createClient(options) {
|
|
|
1230
1240
|
return unwrap(await fetchJSON(url));
|
|
1231
1241
|
},
|
|
1232
1242
|
async getPage(slug) {
|
|
1243
|
+
if (draft && previewToken && tokenSlug(previewToken) === slug) {
|
|
1244
|
+
const url = `${apiUrl}/api/v1/preview/${encodeURIComponent(slug)}${qs({
|
|
1245
|
+
token: previewToken,
|
|
1246
|
+
stega: stega ? "1" : void 0
|
|
1247
|
+
})}`;
|
|
1248
|
+
const d = unwrap(await fetchJSON(url));
|
|
1249
|
+
return {
|
|
1250
|
+
slug: d.slug,
|
|
1251
|
+
title: d.title,
|
|
1252
|
+
metaTitle: d.metaTitle ?? null,
|
|
1253
|
+
metaDescription: d.metaDescription ?? null,
|
|
1254
|
+
metaJson: d.metaJson ?? null,
|
|
1255
|
+
blocks: d.blockJson ?? [],
|
|
1256
|
+
updatedAt: d.updatedAt ?? null,
|
|
1257
|
+
publishedAt: d.publishedAt ?? null
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1233
1260
|
let page = 1;
|
|
1234
1261
|
for (; ; ) {
|
|
1235
1262
|
const list = await this.listPages({ page, perPage: 100 });
|
|
@@ -1246,6 +1273,13 @@ function createClient(options) {
|
|
|
1246
1273
|
})}`;
|
|
1247
1274
|
return unwrap(await fetchJSON(url));
|
|
1248
1275
|
},
|
|
1276
|
+
async listComponents() {
|
|
1277
|
+
const url = `${base}/components${qs({
|
|
1278
|
+
perspective: draft ? "draft" : void 0,
|
|
1279
|
+
token: draft ? previewToken : void 0
|
|
1280
|
+
})}`;
|
|
1281
|
+
return unwrap(await fetchJSON(url));
|
|
1282
|
+
},
|
|
1249
1283
|
async getLayout() {
|
|
1250
1284
|
const url = `${base}/layout${draft ? "?perspective=draft" : ""}`;
|
|
1251
1285
|
try {
|