import { ContentStoreTypes } from '@stackbit/cms-core'; import { CollectionItemWithModel, SiteMap, Collections, Schema } from '@stackbit/dev-common'; import { Preset } from '@stackbit/sdk'; import * as StackbitTypes from '@stackbit/types'; export type APIMethodName = APIMethod['method']; export type APIMethodForMethod = U extends { method: T } ? U : never; export type APIMethodByMethod = APIMethodForMethod; export type APIMethodDataForMethod = APIMethodByMethod['data']; export type APIMethodResultForMethod = APIMethodByMethod['result']; export type APIMethod = | APIMethodHasAccess | APIMethodCreateDocument | APIMethodCreateAndLinkDocument | APIMethodCreateAndCrossLinkDocument | APIMethodUploadAndLinkAsset | APIMethodDuplicateDocument | APIMethodUpdateDocument | APIMethodUpdateAsset | APIMethodValidateDocuments | APIMethodDeleteDocument | APIMethodGetAssets | APIMethodUploadAssets | APIMethodCreatePreset | APIMethodDeletePreset | APIMethodSearchDocuments | APIMethodOnWebhook | APIMethodGetTreeViews | APIMethodGetSiteMap | APIMethodGetCollections | APIMethodGetSchema | APIMethodGetObjects | APIMethodGetObjectsWithAnnotations | APIMethodGetDocuments | APIMethodGetCSIDocuments | APIMethodGetScheduledActions | APIMethodCreateScheduledAction | APIMethodCancelScheduledAction | APIMethodUpdateScheduledAction | APIMethodGetCustomActions | APIMethodGetRunningCustomActions | APIMethodRunCustomAction | APIMethodGetDocumentVersions | APIMethodGetDocumentForVersion | APIMethodGetStagedChanges | APIMethodArchiveDocument | APIMethodUnarchiveDocument | APIMethodPublishDocuments | APIMethodUnpublishDocuments | APIMethodPullContent; export type APIMethodInterface = { [M in APIMethod as M['method']]: (data: M['data']) => Promise; }; export type APIMethodHasAccess = { method: 'hasAccess'; data: { srcType?: string; srcProjectId?: string; }; result: { hasConnection: boolean; hasPermissions: boolean; contentSources: { srcType: string; srcProjectId: string; hasConnection: boolean; hasPermissions: boolean; }[]; }; }; export type APIMethodCreateDocument = { method: 'createDocument'; data: { srcType: string; srcProjectId: string; modelName: string; object?: Record; locale?: string; defaultLocaleDocumentId?: string; }; result: { srcDocumentId: string }; }; export type APIMethodCreateAndLinkDocument = { method: 'createAndLinkDocument'; data: { srcType: string; srcProjectId: string; srcDocumentId: string; fieldPath: (string | number)[]; modelName: string; object?: Record; index?: number; locale?: string; }; result: { srcDocumentId: string; createdDocumentId: string }; }; export type APIMethodCreateAndCrossLinkDocument = { method: 'createAndCrossLinkDocument'; data: APIMethodCreateAndLinkDocument['data'] & { refSrcType: string; refProjectId: string; }; result: { srcDocumentId: string; createdDocumentId: string }; }; export type APIMethodUploadAndLinkAsset = { method: 'uploadAndLinkAsset'; data: { srcType: string; srcProjectId: string; srcDocumentId: string; fieldPath: (string | number)[]; asset: ContentStoreTypes.UploadAssetData; index?: number; locale?: string; }; result: { srcDocumentId: string }; }; export type APIMethodDuplicateDocument = { method: 'duplicateDocument'; data: { srcType: string; srcProjectId: string; srcDocumentId: string; object?: Record; locale?: string; }; result: { srcDocumentId: string }; }; export type APIMethodUpdateDocument = { method: 'updateDocument'; data: { srcType: string; srcProjectId: string; srcDocumentId: string; updateOperations: ContentStoreTypes.UpdateOperation[]; }; result: { srcDocumentId: string }; }; export type APIMethodDeleteDocument = { method: 'deleteDocument'; data: { srcType: string; srcProjectId: string; srcDocumentId: string; }; result: void; }; export type APIMethodArchiveDocument = { method: 'archiveDocument'; data: { srcType: string; srcProjectId: string; srcDocumentId: string; }; result: void; }; export type APIMethodUnarchiveDocument = { method: 'unarchiveDocument'; data: { srcType: string; srcProjectId: string; srcDocumentId: string; }; result: void; }; export type APIMethodGetScheduledActions = { method: 'getScheduledActions'; data: void; result: { scheduledActions: StackbitTypes.ScheduledActionWithSource[]; }; }; export type APIMethodCreateScheduledAction = { method: 'createScheduledAction'; data: { srcType: string; srcProjectId: string; documentIds: string[]; name: string; executeAt: string; action: StackbitTypes.ScheduledActionWithSource['action']; user?: ContentStoreTypes.User; }; result: { newScheduledActionId: string }; }; export type APIMethodCancelScheduledAction = { method: 'cancelScheduledAction'; data: { srcType: string; srcProjectId: string; scheduledActionId: string; user?: ContentStoreTypes.User; }; result: { cancelledScheduledActionId: string }; }; export type APIMethodUpdateScheduledAction = { method: 'updateScheduledAction'; data: { srcType: string; srcProjectId: string; scheduledActionId: string; documentIds?: string[]; name?: string; executeAt?: string; user?: ContentStoreTypes.User; }; result: { updatedScheduledActionId: string }; }; export type APIMethodValidateDocuments = { method: 'validateDocuments'; data: { objects: { srcType: string; srcProjectId: string; srcObjectId: string }[]; locale?: string; }; result: { errors: ContentStoreTypes.ValidationError[]; }; }; export type APIMethodPublishDocuments = { method: 'publishDocuments'; data: { objects: { srcType: string; srcProjectId: string; srcObjectId: string }[]; }; result: void; }; export type APIMethodUnpublishDocuments = { method: 'unpublishDocuments'; data: { objects: { srcType: string; srcProjectId: string; srcObjectId: string }[]; }; result: void; }; export type APIMethodGetAssets = { method: 'getAssets'; data: { srcType?: string; srcProjectId?: string; pageSize?: number; pageNum?: number; searchQuery?: string; user?: ContentStoreTypes.User; assetSpecs?: StackbitTypes.DocumentSpecifier[]; version?: 'v2'; }; result: { assets: ContentStoreTypes.APIAsset[] | ContentStoreTypes.Asset[]; pageSize: number; pageNum: number; totalPages: number; }; }; export type APIMethodUploadAssets = { method: 'uploadAssets'; data: { srcType: string; srcProjectId: string; assets: ContentStoreTypes.UploadAssetData[]; locale?: string; user?: ContentStoreTypes.User; }; result: ContentStoreTypes.APIAsset[]; }; export type APIMethodUpdateAsset = { method: 'updateAsset'; data: { srcType: string; srcProjectId: string; srcAssetId: string; updateOperations: ContentStoreTypes.UpdateOperation[]; }; result: { srcAssetId: string }; }; export type APIMethodCreatePreset = { method: 'createPreset'; data: { label: string; metadata: any; thumbnail: { url?: string; data?: string; metadata: { name: string; type: string; }; }; fieldDataPath: string[]; user?: ContentStoreTypes.User; dryRun: boolean; }; result: { files: string[]; preset: Preset; }; }; export type APIMethodDeletePreset = { method: 'deletePreset'; data: { presetId: string; user?: ContentStoreTypes.User; }; result: { changes: { filePath: string; description: string; }[]; filesRemoved: string[]; }; }; export type APIMethodSearchDocuments = { method: 'searchDocuments'; data: { query?: string; models: Array<{ srcProjectId: string; srcType: string; modelName: string; }>; locale?: string; filter: ContentStoreTypes.SearchFilter; user?: ContentStoreTypes.User; }; result: { items: CollectionItemWithModel[]; total: number; }; }; export type APIMethodGetDocumentVersions = { method: 'getDocumentVersions'; data: { srcType: string; srcProjectId: string; documentId: string; locale?: string; user?: ContentStoreTypes.User; }; result: { versions: ContentStoreTypes.APIDocumentVersion[] }; }; export type APIMethodGetDocumentForVersion = { method: 'getDocumentForVersion'; data: { srcType: string; srcProjectId: string; documentId: string; versionId: string; locale?: string; user?: ContentStoreTypes.User; }; result: { version: ContentStoreTypes.APIDocumentVersionWithDocument }; }; export type APIMethodOnWebhook = { method: 'onWebhook'; data: { srcType: string; srcProjectId: string; data: unknown; headers: Record; }; result: void; }; export type APIMethodGetCustomActions = { method: 'getCustomActions'; data: ContentStoreTypes.APIGetCustomActionRequest; result: ContentStoreTypes.APICustomAction[]; }; export type APIMethodGetRunningCustomActions = { method: 'getRunningCustomActions'; data: ContentStoreTypes.APIGetRunningCustomActionsRequest; result: ContentStoreTypes.APICustomAction[]; }; export type APIMethodRunCustomAction = { method: 'runCustomAction'; data: ContentStoreTypes.APIRunCustomActionRequest; result: ContentStoreTypes.APIRunCustomActionResponse; }; export type APIMethodGetTreeViews = { method: 'getTreeViews'; data: { user?: ContentStoreTypes.User }; result: StackbitTypes.TreeViewNode[]; }; export type APIMethodGetSiteMap = { method: 'getSiteMap'; data: { locale?: string; user?: ContentStoreTypes.User; }; result: SiteMap; }; export type APIMethodGetCollections = { method: 'getCollections'; data: { locale?: string; user?: ContentStoreTypes.User; }; result: Collections; }; export type APIMethodGetSchema = { method: 'getSchema'; data: { locale?: string; user?: ContentStoreTypes.User; }; result: Schema; }; export type APIMethodGetDocuments = { method: 'getDocuments'; data: { documentSpecs?: StackbitTypes.DocumentSpecifier[]; user?: ContentStoreTypes.User; }; result: { documents: ContentStoreTypes.APIDocument[] }; }; export type APIMethodGetCSIDocuments = { method: 'getCSIDocuments'; data: { documentSpecs?: StackbitTypes.DocumentSpecifier[]; srcType?: string; srcProjectId?: string; limit?: number; offset?: number; }; result: { total: number; offset: number; documents: StackbitTypes.Document[]; }; }; export type APIMethodGetObjects = { method: 'getObjects'; data: { objectIds?: string[]; locale?: string; user?: ContentStoreTypes.User; }; result: { objects: ContentStoreTypes.APIObject[] }; }; export type APIMethodGetObjectsWithAnnotations = { method: 'getObjectsWithAnnotations'; data: { annotationTree: any; clientAnnotationErrors: any; resolveAllReferences?: boolean; sourcemaps?: any; locale?: string; user?: ContentStoreTypes.User; }; result: { objects: ContentStoreTypes.APIObject[]; pathMap: any; errors: any[]; }; }; export type APIMethodGetStagedChanges = { method: 'getStagedChanges'; data: { objects: { srcObjectId: string; srcProjectId: string; srcType: string; srcEnvironment?: string }[]; locale?: string; env: string; scope: ContentStoreTypes.PublishProjectScope; shallow?: boolean; }; result: { changes: ContentStoreTypes.StagedChange[] }; }; export type APIMethodPullContent = { method: 'pullContent'; data: void; result: { didPull: boolean }; };