@bettercms-ai/sdk 1.41.2 → 1.42.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 +2 -65
- package/dist/index.d.ts +2 -65
- package/dist/{read-CZB0cP-f.d.ts → read-CGBWVZQA.d.ts} +64 -1
- package/dist/{read-DWArctXs.d.cts → read-HyRuGRBt.d.cts} +64 -1
- package/dist/read.cjs +48 -0
- package/dist/read.cjs.map +1 -1
- package/dist/read.d.cts +1 -1
- package/dist/read.d.ts +1 -1
- package/dist/read.js +44 -0
- package/dist/read.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ export { ApiError, ApiKey, ApiKeyPermission, ApiKeyTokenType, AssertEqual, AuthS
|
|
|
4
4
|
import { D as DeliveryFormField } from './read-client-TTj8g07j.cjs';
|
|
5
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';
|
|
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, R as ResolvedHolder,
|
|
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';
|
|
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
|
|
|
@@ -989,69 +989,6 @@ declare function resolveStega(node: StegaNode): {
|
|
|
989
989
|
element: StegaNode;
|
|
990
990
|
} | null;
|
|
991
991
|
|
|
992
|
-
/**
|
|
993
|
-
* The published content snapshot, read where the site RUNS — not bundled into it.
|
|
994
|
-
*
|
|
995
|
-
* Every BetterCMS build gets the published content as `bcms-content.json` in the project root,
|
|
996
|
-
* and a server app hosted on BetterCMS runs with `BCMS_CONTENT_FILE` pointing at a copy the
|
|
997
|
-
* platform rewrites on every publish. Read through this, a server-rendered page shows a publish
|
|
998
|
-
* within seconds and the publish never rebuilds the site. Import the JSON instead (a JSON import,
|
|
999
|
-
* `import.meta.glob`) and the bundle holds a frozen copy no publish can reach: the platform then
|
|
1000
|
-
* has to rebuild the whole site for every edit.
|
|
1001
|
-
*
|
|
1002
|
-
* - On a hosted server: `BCMS_CONTENT_FILE`, re-read when it changes (its time is asked on every call).
|
|
1003
|
-
* - At build time and in local dev: `<cwd>/bcms-content.json`, the snapshot the build was given.
|
|
1004
|
-
* - Anywhere without a filesystem (a browser, an edge runtime): `null`.
|
|
1005
|
-
*
|
|
1006
|
-
* A file that cannot be read keeps the last good copy; never throws into a render.
|
|
1007
|
-
* No `node:fs` import at module scope, so the SDK stays safe to bundle for the browser.
|
|
1008
|
-
*/
|
|
1009
|
-
/** The snapshot's shape (`bcms-content/v1`, written by the platform's content fetch). */
|
|
1010
|
-
interface PublishedContent {
|
|
1011
|
-
generatedAt?: string;
|
|
1012
|
-
apiUrl?: string | null;
|
|
1013
|
-
workspace?: string;
|
|
1014
|
-
projectId?: string | null;
|
|
1015
|
-
/**
|
|
1016
|
-
* Published entries by model slug, each row AS THE DELIVERY API SERVES IT: `id`, `slug`, `status`,
|
|
1017
|
-
* `publishedAt`, `updatedAt`, `locale`, `translationOf`, `_meta`, and the field values under
|
|
1018
|
-
* `data`. Read a value through {@link publishedEntry}, which answers either spelling.
|
|
1019
|
-
*/
|
|
1020
|
-
collections?: Record<string, Array<Record<string, unknown> & {
|
|
1021
|
-
slug?: string;
|
|
1022
|
-
data?: Record<string, unknown>;
|
|
1023
|
-
}>>;
|
|
1024
|
-
pages?: unknown[];
|
|
1025
|
-
components?: unknown[];
|
|
1026
|
-
forms?: unknown[];
|
|
1027
|
-
layout?: unknown;
|
|
1028
|
-
[key: string]: unknown;
|
|
1029
|
-
}
|
|
1030
|
-
/** Where the published content is read from here, or null where there is no filesystem. */
|
|
1031
|
-
declare function publishedContentFile(): string | null;
|
|
1032
|
-
/**
|
|
1033
|
-
* The published content snapshot, or null when there is none here (no file, no filesystem).
|
|
1034
|
-
* Call it per render — it is cached and cheap — never once at module scope, which would freeze it.
|
|
1035
|
-
*/
|
|
1036
|
-
declare function readPublishedContent<T extends PublishedContent = PublishedContent>(): T | null;
|
|
1037
|
-
/**
|
|
1038
|
-
* One published entry by its slug, searched across every collection (first match wins, in the
|
|
1039
|
-
* snapshot's model order). Not keyed by model slug: a page's backing model is named by the CMS.
|
|
1040
|
-
*
|
|
1041
|
-
* 🔴 THE VALUES ARE ON THE ENTRY: `publishedEntry("home")?.title`. The snapshot holds each row as
|
|
1042
|
-
* the delivery API serves it, values under `data`, and this used to hand that row back as it was
|
|
1043
|
-
* while its own doc (and the skill that names it) said "the row carries its field values" — so
|
|
1044
|
-
* `entry.title` was `undefined` and every field of a server-rendered page fell back to the copy in
|
|
1045
|
-
* the code, on every publish. Both spellings are answered: the values at the top level and the
|
|
1046
|
-
* row's own keys (`id`, `slug`, `status`, `data`, `_meta`, …) beside them, the row's winning where
|
|
1047
|
-
* a field is named like one — that field is read through `.data`, as before.
|
|
1048
|
-
*/
|
|
1049
|
-
declare function publishedEntry<T extends Record<string, unknown> = Record<string, unknown>>(slug: string): (T & {
|
|
1050
|
-
slug: string;
|
|
1051
|
-
}) | null;
|
|
1052
|
-
/** Test seam: forget the cached snapshot. */
|
|
1053
|
-
declare function resetPublishedContentCache(): void;
|
|
1054
|
-
|
|
1055
992
|
/**
|
|
1056
993
|
* Admin pages methods.
|
|
1057
994
|
* @see openspec/changes/flo-6-backend-sdk-admin/specs/sdk-admin-client/spec.md
|
|
@@ -1327,4 +1264,4 @@ interface WebhookListResponse {
|
|
|
1327
1264
|
};
|
|
1328
1265
|
}
|
|
1329
1266
|
|
|
1330
|
-
export { type AddPageFieldsInput, type ApiKeyUsage, type ApiKeyWithRaw, type AuthResult, BetterCMS, BetterCMSAdminClient, type BetterCMSAdminOptions, BetterCMSDeliveryClient, BetterCMSManagementClient, type BetterCMSManagementOptions, type BetterCMSSiteOptions, type CommandManagedLayoutInput, type CreateApiKeyInput, type CreateEntryInput, type CreateFormInput, type CreateManagedPageInput, type CreateModelInput, type CreatePageInput, type CreateWebhookInput, type CreateWorkspaceInput, DeliveryFormField, type ExtractionCandidate, type FormFieldInput, type FormListOptions, type GetManagedLayoutOptions, type ListContentAllOptions, type ListContentOptions, type ListEntriesFilter, type ManagedComponent, type ManagedComponentInput, type ManagedComponentSummary, type ManagedContentEntry, type ManagedContentModel, type ManagedForm, type ManagedFormInput, type ManagedLayoutClient, type ManagedLayoutDocument, type ManagedMediaAsset, type ManagedPage, type ManagementClient, type MediaListOptions, type MediaMetadata, type Member, type MemberRole, type ModelFieldset, type PageCreateReport, type PageListOptions, type PendingInvite, type PublishManagedLayoutInput,
|
|
1267
|
+
export { type AddPageFieldsInput, type ApiKeyUsage, type ApiKeyWithRaw, type AuthResult, BetterCMS, BetterCMSAdminClient, type BetterCMSAdminOptions, BetterCMSDeliveryClient, BetterCMSManagementClient, type BetterCMSManagementOptions, type BetterCMSSiteOptions, type CommandManagedLayoutInput, type CreateApiKeyInput, type CreateEntryInput, type CreateFormInput, type CreateManagedPageInput, type CreateModelInput, type CreatePageInput, type CreateWebhookInput, type CreateWorkspaceInput, DeliveryFormField, type ExtractionCandidate, type FormFieldInput, type FormListOptions, type GetManagedLayoutOptions, type ListContentAllOptions, type ListContentOptions, type ListEntriesFilter, type ManagedComponent, type ManagedComponentInput, type ManagedComponentSummary, type ManagedContentEntry, type ManagedContentModel, type ManagedForm, type ManagedFormInput, type ManagedLayoutClient, type ManagedLayoutDocument, type ManagedMediaAsset, type ManagedPage, type ManagementClient, type MediaListOptions, type MediaMetadata, type Member, type MemberRole, type ModelFieldset, type PageCreateReport, type PageListOptions, type PendingInvite, type PublishManagedLayoutInput, STEGA_OPEN, type SeoMeta, type SeoMetaInput, type SetPageContentInput, type StegaNode, type StegaPayload, type SubmissionListOptions, type UpdateApiKeyInput, type UpdateAssetInput, type UpdateEntryInput, type UpdateFormInput, type UpdateModelInput, type UpdatePageInput, type UpdateWebhookInput, type UpdateWorkspaceInput, type UploadAssetInput, type UploadedAsset, type Webhook, type WebhookAdvancedConfig, type WebhookEvent, type WebhookListResponse, type WebhookWithSecret, type WriteContentInput, addModelFields, addPageFields, commandManagedLayout, createApiKey, createEntry, createForm, createManagedPage, createModel, createPage, createWorkspace, decodeStega, deleteForm, deleteMedia, deletePage, deleteSubmission, deleteWorkspace, encodeStega, getApiKeyUsage, getEntry, getForm, getManagedLayout, getManagedPage, getMedia, getMember, getModel, getPage, getSubmission, getWorkspace, inviteMember, listApiKeys, listEntries, listForms, listManagedPages, listMedia, listMembers, listModels, listPages, listSubmissions, listWorkspaces, publishManagedLayout, publishPage, regenerateApiKey, removeMember, resolveStega, revokeApiKey, setPageContent, signIn, signInWithGithub, signInWithGoogle, signUp, stegaClean, stripStega, updateApiKey, updateEntry, updateForm, updateMemberRole, updateModel, updatePage, updatePageModel, updateWorkspace, uploadMedia };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { ApiError, ApiKey, ApiKeyPermission, ApiKeyTokenType, AssertEqual, AuthS
|
|
|
4
4
|
import { D as DeliveryFormField } from './read-client-TTj8g07j.js';
|
|
5
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';
|
|
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, R as ResolvedHolder,
|
|
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';
|
|
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
|
|
|
@@ -989,69 +989,6 @@ declare function resolveStega(node: StegaNode): {
|
|
|
989
989
|
element: StegaNode;
|
|
990
990
|
} | null;
|
|
991
991
|
|
|
992
|
-
/**
|
|
993
|
-
* The published content snapshot, read where the site RUNS — not bundled into it.
|
|
994
|
-
*
|
|
995
|
-
* Every BetterCMS build gets the published content as `bcms-content.json` in the project root,
|
|
996
|
-
* and a server app hosted on BetterCMS runs with `BCMS_CONTENT_FILE` pointing at a copy the
|
|
997
|
-
* platform rewrites on every publish. Read through this, a server-rendered page shows a publish
|
|
998
|
-
* within seconds and the publish never rebuilds the site. Import the JSON instead (a JSON import,
|
|
999
|
-
* `import.meta.glob`) and the bundle holds a frozen copy no publish can reach: the platform then
|
|
1000
|
-
* has to rebuild the whole site for every edit.
|
|
1001
|
-
*
|
|
1002
|
-
* - On a hosted server: `BCMS_CONTENT_FILE`, re-read when it changes (its time is asked on every call).
|
|
1003
|
-
* - At build time and in local dev: `<cwd>/bcms-content.json`, the snapshot the build was given.
|
|
1004
|
-
* - Anywhere without a filesystem (a browser, an edge runtime): `null`.
|
|
1005
|
-
*
|
|
1006
|
-
* A file that cannot be read keeps the last good copy; never throws into a render.
|
|
1007
|
-
* No `node:fs` import at module scope, so the SDK stays safe to bundle for the browser.
|
|
1008
|
-
*/
|
|
1009
|
-
/** The snapshot's shape (`bcms-content/v1`, written by the platform's content fetch). */
|
|
1010
|
-
interface PublishedContent {
|
|
1011
|
-
generatedAt?: string;
|
|
1012
|
-
apiUrl?: string | null;
|
|
1013
|
-
workspace?: string;
|
|
1014
|
-
projectId?: string | null;
|
|
1015
|
-
/**
|
|
1016
|
-
* Published entries by model slug, each row AS THE DELIVERY API SERVES IT: `id`, `slug`, `status`,
|
|
1017
|
-
* `publishedAt`, `updatedAt`, `locale`, `translationOf`, `_meta`, and the field values under
|
|
1018
|
-
* `data`. Read a value through {@link publishedEntry}, which answers either spelling.
|
|
1019
|
-
*/
|
|
1020
|
-
collections?: Record<string, Array<Record<string, unknown> & {
|
|
1021
|
-
slug?: string;
|
|
1022
|
-
data?: Record<string, unknown>;
|
|
1023
|
-
}>>;
|
|
1024
|
-
pages?: unknown[];
|
|
1025
|
-
components?: unknown[];
|
|
1026
|
-
forms?: unknown[];
|
|
1027
|
-
layout?: unknown;
|
|
1028
|
-
[key: string]: unknown;
|
|
1029
|
-
}
|
|
1030
|
-
/** Where the published content is read from here, or null where there is no filesystem. */
|
|
1031
|
-
declare function publishedContentFile(): string | null;
|
|
1032
|
-
/**
|
|
1033
|
-
* The published content snapshot, or null when there is none here (no file, no filesystem).
|
|
1034
|
-
* Call it per render — it is cached and cheap — never once at module scope, which would freeze it.
|
|
1035
|
-
*/
|
|
1036
|
-
declare function readPublishedContent<T extends PublishedContent = PublishedContent>(): T | null;
|
|
1037
|
-
/**
|
|
1038
|
-
* One published entry by its slug, searched across every collection (first match wins, in the
|
|
1039
|
-
* snapshot's model order). Not keyed by model slug: a page's backing model is named by the CMS.
|
|
1040
|
-
*
|
|
1041
|
-
* 🔴 THE VALUES ARE ON THE ENTRY: `publishedEntry("home")?.title`. The snapshot holds each row as
|
|
1042
|
-
* the delivery API serves it, values under `data`, and this used to hand that row back as it was
|
|
1043
|
-
* while its own doc (and the skill that names it) said "the row carries its field values" — so
|
|
1044
|
-
* `entry.title` was `undefined` and every field of a server-rendered page fell back to the copy in
|
|
1045
|
-
* the code, on every publish. Both spellings are answered: the values at the top level and the
|
|
1046
|
-
* row's own keys (`id`, `slug`, `status`, `data`, `_meta`, …) beside them, the row's winning where
|
|
1047
|
-
* a field is named like one — that field is read through `.data`, as before.
|
|
1048
|
-
*/
|
|
1049
|
-
declare function publishedEntry<T extends Record<string, unknown> = Record<string, unknown>>(slug: string): (T & {
|
|
1050
|
-
slug: string;
|
|
1051
|
-
}) | null;
|
|
1052
|
-
/** Test seam: forget the cached snapshot. */
|
|
1053
|
-
declare function resetPublishedContentCache(): void;
|
|
1054
|
-
|
|
1055
992
|
/**
|
|
1056
993
|
* Admin pages methods.
|
|
1057
994
|
* @see openspec/changes/flo-6-backend-sdk-admin/specs/sdk-admin-client/spec.md
|
|
@@ -1327,4 +1264,4 @@ interface WebhookListResponse {
|
|
|
1327
1264
|
};
|
|
1328
1265
|
}
|
|
1329
1266
|
|
|
1330
|
-
export { type AddPageFieldsInput, type ApiKeyUsage, type ApiKeyWithRaw, type AuthResult, BetterCMS, BetterCMSAdminClient, type BetterCMSAdminOptions, BetterCMSDeliveryClient, BetterCMSManagementClient, type BetterCMSManagementOptions, type BetterCMSSiteOptions, type CommandManagedLayoutInput, type CreateApiKeyInput, type CreateEntryInput, type CreateFormInput, type CreateManagedPageInput, type CreateModelInput, type CreatePageInput, type CreateWebhookInput, type CreateWorkspaceInput, DeliveryFormField, type ExtractionCandidate, type FormFieldInput, type FormListOptions, type GetManagedLayoutOptions, type ListContentAllOptions, type ListContentOptions, type ListEntriesFilter, type ManagedComponent, type ManagedComponentInput, type ManagedComponentSummary, type ManagedContentEntry, type ManagedContentModel, type ManagedForm, type ManagedFormInput, type ManagedLayoutClient, type ManagedLayoutDocument, type ManagedMediaAsset, type ManagedPage, type ManagementClient, type MediaListOptions, type MediaMetadata, type Member, type MemberRole, type ModelFieldset, type PageCreateReport, type PageListOptions, type PendingInvite, type PublishManagedLayoutInput,
|
|
1267
|
+
export { type AddPageFieldsInput, type ApiKeyUsage, type ApiKeyWithRaw, type AuthResult, BetterCMS, BetterCMSAdminClient, type BetterCMSAdminOptions, BetterCMSDeliveryClient, BetterCMSManagementClient, type BetterCMSManagementOptions, type BetterCMSSiteOptions, type CommandManagedLayoutInput, type CreateApiKeyInput, type CreateEntryInput, type CreateFormInput, type CreateManagedPageInput, type CreateModelInput, type CreatePageInput, type CreateWebhookInput, type CreateWorkspaceInput, DeliveryFormField, type ExtractionCandidate, type FormFieldInput, type FormListOptions, type GetManagedLayoutOptions, type ListContentAllOptions, type ListContentOptions, type ListEntriesFilter, type ManagedComponent, type ManagedComponentInput, type ManagedComponentSummary, type ManagedContentEntry, type ManagedContentModel, type ManagedForm, type ManagedFormInput, type ManagedLayoutClient, type ManagedLayoutDocument, type ManagedMediaAsset, type ManagedPage, type ManagementClient, type MediaListOptions, type MediaMetadata, type Member, type MemberRole, type ModelFieldset, type PageCreateReport, type PageListOptions, type PendingInvite, type PublishManagedLayoutInput, STEGA_OPEN, type SeoMeta, type SeoMetaInput, type SetPageContentInput, type StegaNode, type StegaPayload, type SubmissionListOptions, type UpdateApiKeyInput, type UpdateAssetInput, type UpdateEntryInput, type UpdateFormInput, type UpdateModelInput, type UpdatePageInput, type UpdateWebhookInput, type UpdateWorkspaceInput, type UploadAssetInput, type UploadedAsset, type Webhook, type WebhookAdvancedConfig, type WebhookEvent, type WebhookListResponse, type WebhookWithSecret, type WriteContentInput, addModelFields, addPageFields, commandManagedLayout, createApiKey, createEntry, createForm, createManagedPage, createModel, createPage, createWorkspace, decodeStega, deleteForm, deleteMedia, deletePage, deleteSubmission, deleteWorkspace, encodeStega, getApiKeyUsage, getEntry, getForm, getManagedLayout, getManagedPage, getMedia, getMember, getModel, getPage, getSubmission, getWorkspace, inviteMember, listApiKeys, listEntries, listForms, listManagedPages, listMedia, listMembers, listModels, listPages, listSubmissions, listWorkspaces, publishManagedLayout, publishPage, regenerateApiKey, removeMember, resolveStega, revokeApiKey, setPageContent, signIn, signInWithGithub, signInWithGoogle, signUp, stegaClean, stripStega, updateApiKey, updateEntry, updateForm, updateMemberRole, updateModel, updatePage, updatePageModel, updateWorkspace, uploadMedia };
|
|
@@ -188,4 +188,67 @@ interface SearchOptions {
|
|
|
188
188
|
/** Search a published site. Resolves with hits, or [] on an empty query / network error. */
|
|
189
189
|
declare function search(opts: SearchOptions): Promise<SearchHit[]>;
|
|
190
190
|
|
|
191
|
-
|
|
191
|
+
/**
|
|
192
|
+
* The published content snapshot, read where the site RUNS — not bundled into it.
|
|
193
|
+
*
|
|
194
|
+
* Every BetterCMS build gets the published content as `bcms-content.json` in the project root,
|
|
195
|
+
* and a server app hosted on BetterCMS runs with `BCMS_CONTENT_FILE` pointing at a copy the
|
|
196
|
+
* platform rewrites on every publish. Read through this, a server-rendered page shows a publish
|
|
197
|
+
* within seconds and the publish never rebuilds the site. Import the JSON instead (a JSON import,
|
|
198
|
+
* `import.meta.glob`) and the bundle holds a frozen copy no publish can reach: the platform then
|
|
199
|
+
* has to rebuild the whole site for every edit.
|
|
200
|
+
*
|
|
201
|
+
* - On a hosted server: `BCMS_CONTENT_FILE`, re-read when it changes (its time is asked on every call).
|
|
202
|
+
* - At build time and in local dev: `<cwd>/bcms-content.json`, the snapshot the build was given.
|
|
203
|
+
* - Anywhere without a filesystem (a browser, an edge runtime): `null`.
|
|
204
|
+
*
|
|
205
|
+
* A file that cannot be read keeps the last good copy; never throws into a render.
|
|
206
|
+
* No `node:fs` import at module scope, so the SDK stays safe to bundle for the browser.
|
|
207
|
+
*/
|
|
208
|
+
/** The snapshot's shape (`bcms-content/v1`, written by the platform's content fetch). */
|
|
209
|
+
interface PublishedContent {
|
|
210
|
+
generatedAt?: string;
|
|
211
|
+
apiUrl?: string | null;
|
|
212
|
+
workspace?: string;
|
|
213
|
+
projectId?: string | null;
|
|
214
|
+
/**
|
|
215
|
+
* Published entries by model slug, each row AS THE DELIVERY API SERVES IT: `id`, `slug`, `status`,
|
|
216
|
+
* `publishedAt`, `updatedAt`, `locale`, `translationOf`, `_meta`, and the field values under
|
|
217
|
+
* `data`. Read a value through {@link publishedEntry}, which answers either spelling.
|
|
218
|
+
*/
|
|
219
|
+
collections?: Record<string, Array<Record<string, unknown> & {
|
|
220
|
+
slug?: string;
|
|
221
|
+
data?: Record<string, unknown>;
|
|
222
|
+
}>>;
|
|
223
|
+
pages?: unknown[];
|
|
224
|
+
components?: unknown[];
|
|
225
|
+
forms?: unknown[];
|
|
226
|
+
layout?: unknown;
|
|
227
|
+
[key: string]: unknown;
|
|
228
|
+
}
|
|
229
|
+
/** Where the published content is read from here, or null where there is no filesystem. */
|
|
230
|
+
declare function publishedContentFile(): string | null;
|
|
231
|
+
/**
|
|
232
|
+
* The published content snapshot, or null when there is none here (no file, no filesystem).
|
|
233
|
+
* Call it per render — it is cached and cheap — never once at module scope, which would freeze it.
|
|
234
|
+
*/
|
|
235
|
+
declare function readPublishedContent<T extends PublishedContent = PublishedContent>(): T | null;
|
|
236
|
+
/**
|
|
237
|
+
* One published entry by its slug, searched across every collection (first match wins, in the
|
|
238
|
+
* snapshot's model order). Not keyed by model slug: a page's backing model is named by the CMS.
|
|
239
|
+
*
|
|
240
|
+
* 🔴 THE VALUES ARE ON THE ENTRY: `publishedEntry("home")?.title`. The snapshot holds each row as
|
|
241
|
+
* the delivery API serves it, values under `data`, and this used to hand that row back as it was
|
|
242
|
+
* while its own doc (and the skill that names it) said "the row carries its field values" — so
|
|
243
|
+
* `entry.title` was `undefined` and every field of a server-rendered page fell back to the copy in
|
|
244
|
+
* the code, on every publish. Both spellings are answered: the values at the top level and the
|
|
245
|
+
* row's own keys (`id`, `slug`, `status`, `data`, `_meta`, …) beside them, the row's winning where
|
|
246
|
+
* a field is named like one — that field is read through `.data`, as before.
|
|
247
|
+
*/
|
|
248
|
+
declare function publishedEntry<T extends Record<string, unknown> = Record<string, unknown>>(slug: string): (T & {
|
|
249
|
+
slug: string;
|
|
250
|
+
}) | null;
|
|
251
|
+
/** Test seam: forget the cached snapshot. */
|
|
252
|
+
declare function resetPublishedContentCache(): void;
|
|
253
|
+
|
|
254
|
+
export { PORTABLE_TEXT_FORMAT as P, type ResolvedHolder as R, type SearchHit as S, type TextOrRich as T, type PublishedContent as a, type RichTextValue as b, type SearchOptions as c, portableText as d, embeds as e, publishedContentFile as f, publishedEntry as g, resetPublishedContentCache as h, isRichText as i, resolved as j, rich as k, lines as l, plain as p, readPublishedContent as r, search as s };
|
|
@@ -188,4 +188,67 @@ interface SearchOptions {
|
|
|
188
188
|
/** Search a published site. Resolves with hits, or [] on an empty query / network error. */
|
|
189
189
|
declare function search(opts: SearchOptions): Promise<SearchHit[]>;
|
|
190
190
|
|
|
191
|
-
|
|
191
|
+
/**
|
|
192
|
+
* The published content snapshot, read where the site RUNS — not bundled into it.
|
|
193
|
+
*
|
|
194
|
+
* Every BetterCMS build gets the published content as `bcms-content.json` in the project root,
|
|
195
|
+
* and a server app hosted on BetterCMS runs with `BCMS_CONTENT_FILE` pointing at a copy the
|
|
196
|
+
* platform rewrites on every publish. Read through this, a server-rendered page shows a publish
|
|
197
|
+
* within seconds and the publish never rebuilds the site. Import the JSON instead (a JSON import,
|
|
198
|
+
* `import.meta.glob`) and the bundle holds a frozen copy no publish can reach: the platform then
|
|
199
|
+
* has to rebuild the whole site for every edit.
|
|
200
|
+
*
|
|
201
|
+
* - On a hosted server: `BCMS_CONTENT_FILE`, re-read when it changes (its time is asked on every call).
|
|
202
|
+
* - At build time and in local dev: `<cwd>/bcms-content.json`, the snapshot the build was given.
|
|
203
|
+
* - Anywhere without a filesystem (a browser, an edge runtime): `null`.
|
|
204
|
+
*
|
|
205
|
+
* A file that cannot be read keeps the last good copy; never throws into a render.
|
|
206
|
+
* No `node:fs` import at module scope, so the SDK stays safe to bundle for the browser.
|
|
207
|
+
*/
|
|
208
|
+
/** The snapshot's shape (`bcms-content/v1`, written by the platform's content fetch). */
|
|
209
|
+
interface PublishedContent {
|
|
210
|
+
generatedAt?: string;
|
|
211
|
+
apiUrl?: string | null;
|
|
212
|
+
workspace?: string;
|
|
213
|
+
projectId?: string | null;
|
|
214
|
+
/**
|
|
215
|
+
* Published entries by model slug, each row AS THE DELIVERY API SERVES IT: `id`, `slug`, `status`,
|
|
216
|
+
* `publishedAt`, `updatedAt`, `locale`, `translationOf`, `_meta`, and the field values under
|
|
217
|
+
* `data`. Read a value through {@link publishedEntry}, which answers either spelling.
|
|
218
|
+
*/
|
|
219
|
+
collections?: Record<string, Array<Record<string, unknown> & {
|
|
220
|
+
slug?: string;
|
|
221
|
+
data?: Record<string, unknown>;
|
|
222
|
+
}>>;
|
|
223
|
+
pages?: unknown[];
|
|
224
|
+
components?: unknown[];
|
|
225
|
+
forms?: unknown[];
|
|
226
|
+
layout?: unknown;
|
|
227
|
+
[key: string]: unknown;
|
|
228
|
+
}
|
|
229
|
+
/** Where the published content is read from here, or null where there is no filesystem. */
|
|
230
|
+
declare function publishedContentFile(): string | null;
|
|
231
|
+
/**
|
|
232
|
+
* The published content snapshot, or null when there is none here (no file, no filesystem).
|
|
233
|
+
* Call it per render — it is cached and cheap — never once at module scope, which would freeze it.
|
|
234
|
+
*/
|
|
235
|
+
declare function readPublishedContent<T extends PublishedContent = PublishedContent>(): T | null;
|
|
236
|
+
/**
|
|
237
|
+
* One published entry by its slug, searched across every collection (first match wins, in the
|
|
238
|
+
* snapshot's model order). Not keyed by model slug: a page's backing model is named by the CMS.
|
|
239
|
+
*
|
|
240
|
+
* 🔴 THE VALUES ARE ON THE ENTRY: `publishedEntry("home")?.title`. The snapshot holds each row as
|
|
241
|
+
* the delivery API serves it, values under `data`, and this used to hand that row back as it was
|
|
242
|
+
* while its own doc (and the skill that names it) said "the row carries its field values" — so
|
|
243
|
+
* `entry.title` was `undefined` and every field of a server-rendered page fell back to the copy in
|
|
244
|
+
* the code, on every publish. Both spellings are answered: the values at the top level and the
|
|
245
|
+
* row's own keys (`id`, `slug`, `status`, `data`, `_meta`, …) beside them, the row's winning where
|
|
246
|
+
* a field is named like one — that field is read through `.data`, as before.
|
|
247
|
+
*/
|
|
248
|
+
declare function publishedEntry<T extends Record<string, unknown> = Record<string, unknown>>(slug: string): (T & {
|
|
249
|
+
slug: string;
|
|
250
|
+
}) | null;
|
|
251
|
+
/** Test seam: forget the cached snapshot. */
|
|
252
|
+
declare function resetPublishedContentCache(): void;
|
|
253
|
+
|
|
254
|
+
export { PORTABLE_TEXT_FORMAT as P, type ResolvedHolder as R, type SearchHit as S, type TextOrRich as T, type PublishedContent as a, type RichTextValue as b, type SearchOptions as c, portableText as d, embeds as e, publishedContentFile as f, publishedEntry as g, resetPublishedContentCache as h, isRichText as i, resolved as j, rich as k, lines as l, plain as p, readPublishedContent as r, search as s };
|
package/dist/read.cjs
CHANGED
|
@@ -28,6 +28,10 @@ __export(read_exports, {
|
|
|
28
28
|
lines: () => lines,
|
|
29
29
|
plain: () => plain,
|
|
30
30
|
portableText: () => portableText,
|
|
31
|
+
publishedContentFile: () => publishedContentFile,
|
|
32
|
+
publishedEntry: () => publishedEntry,
|
|
33
|
+
readPublishedContent: () => readPublishedContent,
|
|
34
|
+
resetPublishedContentCache: () => resetPublishedContentCache,
|
|
31
35
|
rich: () => rich,
|
|
32
36
|
search: () => search,
|
|
33
37
|
shouldShowField: () => shouldShowField,
|
|
@@ -499,6 +503,46 @@ function escapeHtml(s) {
|
|
|
499
503
|
function decodeEntities(s) {
|
|
500
504
|
return s.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/�?39;/g, "'").replace(/ /g, " ").replace(/&/g, "&");
|
|
501
505
|
}
|
|
506
|
+
|
|
507
|
+
// src/published-content.ts
|
|
508
|
+
var cache = null;
|
|
509
|
+
function publishedContentFile() {
|
|
510
|
+
const proc = globalThis.process;
|
|
511
|
+
if (typeof proc?.getBuiltinModule !== "function") return null;
|
|
512
|
+
return proc.env?.BCMS_CONTENT_FILE || `${proc.cwd?.() ?? "."}/bcms-content.json`;
|
|
513
|
+
}
|
|
514
|
+
function readPublishedContent() {
|
|
515
|
+
const file = publishedContentFile();
|
|
516
|
+
if (!file) return null;
|
|
517
|
+
const proc = globalThis.process;
|
|
518
|
+
const fs = proc.getBuiltinModule("node:fs");
|
|
519
|
+
try {
|
|
520
|
+
const stamp = fs.statSync(file).mtimeMs;
|
|
521
|
+
if (cache && cache.file === file && cache.stamp === stamp) return cache.content;
|
|
522
|
+
cache = { file, stamp, content: JSON.parse(fs.readFileSync(file, "utf8")) };
|
|
523
|
+
} catch {
|
|
524
|
+
if (!cache || cache.file !== file) cache = { file, stamp: -1, content: null };
|
|
525
|
+
}
|
|
526
|
+
return cache.content;
|
|
527
|
+
}
|
|
528
|
+
var flat = /* @__PURE__ */ new WeakMap();
|
|
529
|
+
function publishedEntry(slug) {
|
|
530
|
+
const collections = readPublishedContent()?.collections ?? {};
|
|
531
|
+
for (const rows of Object.values(collections)) {
|
|
532
|
+
if (!Array.isArray(rows)) continue;
|
|
533
|
+
const hit = rows.find((row) => row?.slug === slug);
|
|
534
|
+
if (!hit) continue;
|
|
535
|
+
const data = hit.data;
|
|
536
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) return hit;
|
|
537
|
+
let entry = flat.get(hit);
|
|
538
|
+
if (!entry) flat.set(hit, entry = { ...data, ...hit });
|
|
539
|
+
return entry;
|
|
540
|
+
}
|
|
541
|
+
return null;
|
|
542
|
+
}
|
|
543
|
+
function resetPublishedContentCache() {
|
|
544
|
+
cache = null;
|
|
545
|
+
}
|
|
502
546
|
// Annotate the CommonJS export names for ESM import in node:
|
|
503
547
|
0 && (module.exports = {
|
|
504
548
|
asStringArray,
|
|
@@ -509,6 +553,10 @@ function decodeEntities(s) {
|
|
|
509
553
|
lines,
|
|
510
554
|
plain,
|
|
511
555
|
portableText,
|
|
556
|
+
publishedContentFile,
|
|
557
|
+
publishedEntry,
|
|
558
|
+
readPublishedContent,
|
|
559
|
+
resetPublishedContentCache,
|
|
512
560
|
rich,
|
|
513
561
|
search,
|
|
514
562
|
shouldShowField,
|