import * as CSITypes from '@stackbit/types'; import { UserCommandSpawner, CommandRunner, DocumentSpecifier } from '@stackbit/types'; import { Config, ImageModel, Model, Preset, PresetMap } from '@stackbit/sdk'; import * as ContentStoreTypes from './types'; import { OnFilesChangeResponse, SearchFilter } from './types'; import { GitService } from './services'; export type HandleConfigAssets = ({ models, presets }: { models?: T[]; presets?: PresetMap; }) => Promise<{ models: T[]; presets: PresetMap; }>; export interface ContentSourceOptions { logger: CSITypes.Logger; userLogger: CSITypes.Logger; isLocalDev: boolean; isDevServer: boolean; staticAssetsPublicPath: string; webhookUrl?: string; runCommand: CommandRunner; git: GitService; userCommandSpawner?: UserCommandSpawner; onSchemaChangeCallback: () => void; onContentChangeCallback: (contentChanges: ContentStoreTypes.ContentChangeResult) => void; onActionStateChangeCallback: (actionResult: ContentStoreTypes.CustomActionStateChange) => void; handleConfigAssets: HandleConfigAssets; devAppRestartNeeded?: () => void; } export declare class ContentStore { private readonly logger; private readonly userLogger; private readonly userCommandSpawner?; private readonly isLocalDev; private readonly isDevServer; private readonly staticAssetsPublicPath; private readonly webhookUrl?; private readonly runCommand; private readonly git; private readonly onSchemaChangeCallback; private readonly onContentChangeCallback; private readonly onActionStateChangeCallback; private readonly handleConfigAssets; private readonly devAppRestartNeeded?; private contentSources; private contentSourceDataById; private presetsContentSource?; private contentUpdatesWatchTimer; private stackbitConfig; private yamlModels; private configModels; private modelExtensions; private presets; private siteMapEntryGroups; private processingContentSourcesPromise; private contentStoreEventQueue; private treeViews; private customActionRunStateMap; private contentEngine?; private referenceMap; constructor(options: ContentSourceOptions); init({ stackbitConfig }: { stackbitConfig: Config | null; }): Promise; onStackbitConfigChange({ stackbitConfig }: { stackbitConfig: Config | null; }): Promise; /** * This method is called when contentUpdatesWatchTimer receives timeout. * This happens when the user is not using the Stackbit app for some time * but container is not hibernated. * It then notifies all content sources to stop watching for content * changes, which in turn stops polling CMS for content changes and helps * reducing the CMS API usage. */ private handleTimerTimeout; /** * This method is called when user interacts with Stackbit application. * It is used to reset contentUpdatesWatchTimer. When the timer is over * all content sources are notified to stop watching for content updates. */ keepAlive(): Promise; destroy(): Promise; onFilesChange(updatedFiles: string[], dryRun?: boolean): Promise; private loadYamlModels; private mergeConfigModels; private loadPresetsFromConfig; private loadPresetsFromContentSource; /** * If any content sources implement the `getContentEngineConfig` method then this function gets all * of these plugin definitions and creates the content engine. */ private createContentEngineIfNeeded; /** * This function reloads the data of the specified content-sources, while * reusing the cached data of the rest of the content-sources, then processes * the content sources' data by merging it with models defined in * stackbit.config.js and yaml-model files. * * This function is wrapped by `deferWhileRunning` ensuring this method is * invoked one at a time. * * @param {boolean} init Flag specifying if the content sources need to be initialized or reset. * The content sources need to be (re-)initialized only when the stackbit.config.js was reloaded. * In all other cases content sources can be reset. * @param {string[] | undefined} invalidateSchemaForContentSourceIds Array of content source IDs to reload. * If not provided or set to "undefined", will reload all content sources. * If set to empty array will not reload any content sources and only process their cached data. * @private */ private loadContentSourcesAndProcessData; private processContentStoreEvents; private pushContentSourceEvent; private clearEventsForContentSourceId; private loadContentSourceData; private onContentChange; private processData; private calculateReferenceMap; getReferenceMap(): ContentStoreTypes.ReferenceMap; getContentSourceMeta(): { srcType: string; srcProjectId: string; srcVersion: string; csiVersion: string; supportsUnpublish: boolean; supportsArchive: boolean; supportsUnarchive: boolean; supportsScheduledActions: boolean; supportsDocumentVersions: boolean; supportsAssetsEditing: boolean; }[]; getAssetSources(): CSITypes.DistributiveOmit[]; getModels({ user }?: { user?: ContentStoreTypes.User; }): Record>>; getLocales(): ContentStoreTypes.ContentStoreLocale[]; getGlobalActions({ pageUrl, user, locale, currentPageDocument }: { pageUrl?: string; user?: ContentStoreTypes.User; locale?: string; currentPageDocument?: ContentStoreTypes.APICustomActionDocumentSpecifier; }): Promise<(ContentStoreTypes.APICustomActionGlobal | ContentStoreTypes.APICustomActionBulk | ContentStoreTypes.APICustomActionModel)[]>; getCustomActions(getActionRequest: ContentStoreTypes.APIGetCustomActionRequest): Promise; getRunningCustomActionsForUser(getRunningActionsRequest: ContentStoreTypes.APIGetRunningCustomActionsRequest): Promise; runCustomAction(runActionRequest: ContentStoreTypes.APIRunCustomActionRequest): Promise; getPresets({ locale }?: { locale?: string; }): Record; getContentSourceEnvironment({ srcProjectId, srcType }: { srcProjectId: string; srcType: string; }): string; usesContentSourcePresets(): boolean; hasAccess({ srcType, srcProjectId, user }: { srcType?: string; srcProjectId?: string; user?: ContentStoreTypes.User; }): Promise; hasChanges({ srcType, srcProjectId, documents }: { srcType?: string; srcProjectId?: string; documents?: { srcType: string; srcProjectId: string; srcObjectId: string; }[]; }): { hasChanges: boolean; changedObjects: { srcType: string; srcProjectId: string; srcObjectId: string; }[]; }; getSiteMapEntries({ locale, user }?: { locale?: string; user?: ContentStoreTypes.User; }): CSITypes.SiteMapEntry[]; getTreeViews({ user }?: { user?: ContentStoreTypes.User; }): CSITypes.TreeViewNode[]; getSiteMapEntriesForDocument({ srcType, srcProjectId, srcDocumentId, locale }: { srcType: string; srcProjectId: string; srcDocumentId: string; locale?: string; }): CSITypes.SiteMapEntry[]; getDocument({ srcDocumentId, srcProjectId, srcType, user }: { srcDocumentId: string; srcProjectId: string; srcType: string; user?: ContentStoreTypes.User; }): ContentStoreTypes.Document | undefined; getDocumentsByContext({ context, srcProjectId, srcType }: { context: any; srcProjectId?: string; srcType: string; }): ContentStoreTypes.Document[]; getDocuments({ locale, user }?: { locale?: string; user?: ContentStoreTypes.User; }): ContentStoreTypes.Document[]; getApiDocuments({ documentSpecs, user }?: { documentSpecs?: DocumentSpecifier[]; user?: ContentStoreTypes.User; }): { documents: ContentStoreTypes.APIDocument[]; }; getCSIDocuments({ documentSpecs, srcType, srcProjectId, limit, offset }?: { documentSpecs?: DocumentSpecifier[]; srcType?: string; srcProjectId?: string; limit?: number; offset?: number; }): { total: number; offset: number; documents: CSITypes.Document[]; }; getStagedChanges({ scope, locale, shallow, objects, user }: { scope: 'all' | 'code' | 'content'; locale?: string; shallow?: boolean; objects: { srcObjectId: string; srcProjectId: string; srcType: string; srcEnvironment?: string; }[]; user?: ContentStoreTypes.User; }): Promise; getAsset({ srcAssetId, srcProjectId, srcType }: { srcAssetId: string; srcProjectId: string; srcType: string; }): ContentStoreTypes.Asset | undefined; getAssets({ locale, user }?: { locale?: string; user?: ContentStoreTypes.User; }): ContentStoreTypes.Asset[]; getLocalizedApiObjects({ locale, objectIds, user }: { locale?: string; objectIds?: string[]; user?: ContentStoreTypes.User; }): ContentStoreTypes.APIObject[]; getApiAssets(options?: { srcType?: string; srcProjectId?: string; pageSize?: number; pageNum?: number; searchQuery?: string; user?: ContentStoreTypes.User; } | { pageSize?: number; pageNum?: number; searchQuery?: string; user?: ContentStoreTypes.User; assetSpecs?: DocumentSpecifier[]; version?: 'v2'; locale?: string; }): { assets: ContentStoreTypes.APIAsset[] | ContentStoreTypes.Asset[]; pageSize: number; pageNum: number; totalPages: number; }; getApiAssetsV2({ assetSpecs, user, pageSize, pageNum, searchQuery, locale }?: { srcType?: string; srcProjectId?: string; pageSize?: number; pageNum?: number; searchQuery?: string; user?: ContentStoreTypes.User; assetSpecs?: DocumentSpecifier[]; locale?: string; }): { assets: ContentStoreTypes.Asset[]; pageSize: number; pageNum: number; totalPages: number; }; createAndLinkDocument({ srcType, srcProjectId, srcDocumentId, fieldPath, modelName, refSrcType, refProjectId, object, index, locale, user }: { srcType: string; srcProjectId: string; srcDocumentId: string; fieldPath: (string | number)[]; modelName?: string; refSrcType?: string; refProjectId?: string; object?: Record; index?: number; locale?: string; user?: ContentStoreTypes.User; }): Promise<{ srcDocumentId: string; createdDocumentId: string; }>; createPreset({ preset, thumbnailAsset, user }: { preset: Preset; thumbnailAsset: ContentStoreTypes.UploadAssetData; user?: ContentStoreTypes.User; }): Promise<{ srcDocumentId: string; }>; deletePreset({ presetId, user }: { presetId: string; user?: ContentStoreTypes.User; }): Promise; uploadAndLinkAsset({ srcType, srcProjectId, srcDocumentId, fieldPath, asset, index, locale, user }: { srcType: string; srcProjectId: string; srcDocumentId: string; fieldPath: (string | number)[]; asset: ContentStoreTypes.UploadAssetData; index?: number; locale?: string; user?: ContentStoreTypes.User; }): Promise<{ srcDocumentId: string; }>; createDocument({ srcType, srcProjectId, modelName, object, locale, defaultLocaleDocumentId, user }: { srcType: string; srcProjectId: string; modelName: string; object?: Record; locale?: string; defaultLocaleDocumentId?: string; user?: ContentStoreTypes.User; }): Promise<{ srcDocumentId: string; }>; updateDocument({ srcType, srcProjectId, srcDocumentId, updateOperations, user }: { srcType: string; srcProjectId: string; srcDocumentId: string; updateOperations: ContentStoreTypes.UpdateOperation[]; user?: ContentStoreTypes.User; }): Promise<{ srcDocumentId: string; }>; updateAsset({ srcType, srcProjectId, srcAssetId, updateOperations, user }: { srcType: string; srcProjectId: string; srcAssetId: string; updateOperations: ContentStoreTypes.UpdateOperation[]; user?: ContentStoreTypes.User; }): Promise<{ srcAssetId: string; }>; duplicateDocument({ srcType, srcProjectId, srcDocumentId, object, locale, user }: { srcType: string; srcProjectId: string; srcDocumentId: string; object?: Record; locale?: string; user?: ContentStoreTypes.User; }): Promise<{ srcDocumentId: string; }>; private getCreateDocumentThunk; private updateDocumentHooked; uploadAssets({ srcType, srcProjectId, assets, locale, user }: { srcType: string; srcProjectId: string; assets: ContentStoreTypes.UploadAssetData[]; locale?: string; user?: ContentStoreTypes.User; }): Promise; deleteDocument({ srcType, srcProjectId, srcDocumentId, user }: { srcType: string; srcProjectId: string; srcDocumentId: string; user?: ContentStoreTypes.User; }): Promise; archiveDocument({ srcType, srcProjectId, srcDocumentId, user }: { srcType: string; srcProjectId: string; srcDocumentId: string; user?: ContentStoreTypes.User; }): Promise; unarchiveDocument({ srcType, srcProjectId, srcDocumentId, user }: { srcType: string; srcProjectId: string; srcDocumentId: string; user?: ContentStoreTypes.User; }): Promise; getScheduledActions(): CSITypes.ScheduledActionWithSource[]; updateScheduledAction({ srcType, srcProjectId, scheduledActionId, documentIds, name, executeAt, user }: { srcType: string; srcProjectId: string; scheduledActionId: string; name?: string; documentIds?: string[]; executeAt?: string; user?: ContentStoreTypes.User; }): Promise<{ updatedScheduledActionId: string; }>; cancelScheduledAction({ srcType, srcProjectId, scheduledActionId, user }: { srcType: string; srcProjectId: string; scheduledActionId: string; user?: ContentStoreTypes.User; }): Promise<{ cancelledScheduledActionId: string; }>; createScheduledAction({ srcType, srcProjectId, documentIds, name, action, executeAt, user }: { srcType: string; srcProjectId: string; documentIds: string[]; name: string; action: CSITypes.ScheduledActionActionType; executeAt: string; user?: ContentStoreTypes.User; }): Promise<{ newScheduledActionId: string; }>; validateDocuments({ objects, locale, user }: { objects: { srcType: string; srcProjectId: string; srcObjectId: string; }[]; locale?: string; user?: ContentStoreTypes.User; }): Promise<{ errors: ContentStoreTypes.ValidationError[]; }>; searchDocuments(data: { query?: string; filter?: SearchFilter; models: Array<{ srcProjectId: string; srcType: string; modelName: string; }>; locale?: string; user?: ContentStoreTypes.User; }): Promise<{ total: number; items: ContentStoreTypes.Document[]; }>; getDocumentVersions({ srcType, srcProjectId, documentId, locale, user }: { srcType: string; srcProjectId: string; documentId: string; locale?: string; user?: ContentStoreTypes.User; }): Promise<{ versions: ContentStoreTypes.APIDocumentVersion[]; }>; getDocumentForVersion({ srcType, srcProjectId, documentId, versionId, locale, user }: { srcType: string; srcProjectId: string; documentId: string; versionId: string; locale?: string; user?: ContentStoreTypes.User; }): Promise<{ version: ContentStoreTypes.APIDocumentVersionWithDocument; }>; publishDocuments({ objects, user }: { objects: { srcType: string; srcProjectId: string; srcObjectId: string; }[]; user?: ContentStoreTypes.User; }): Promise; unpublishDocuments({ objects, user }: { objects: { srcType: string; srcProjectId: string; srcObjectId: string; }[]; user?: ContentStoreTypes.User; }): Promise; private getContentSourceDataByIdOrThrow; onWebhook({ srcType, srcProjectId, data, headers }: { srcType: string; srcProjectId: string; data: unknown; headers: Record; }): Promise; getWebhookUrl(contentSourceType: string, projectId: string): string | undefined; pullContent(): Promise<{ didPull: boolean; }>; } //# sourceMappingURL=content-store.d.ts.map