import { Component, ContentType, Field, LocalisedString, Project } from 'contensis-core-api'; import { Node as DeliveryNode } from 'contensis-delivery-api'; import { Entry, ICreateTag, ICreateTagGroup, Node as ManagementNode, Node, Role, Tag, TagGroup, Workflow } from 'contensis-management-api'; import { ApiKey, WebhookSubscription } from './Contensis'; import { MigrateContentModelsResponse, MigrateModelsResult, MigrateResultStatus, MigrateStatus, Model, MigrateModelsPreview, SearchQueryOptions } from '../models'; import CopyFieldService from '../services/CopyFieldService'; import { LoggerLevels } from '../util/logger'; export type CallbackConfiguration = { id: string; uri?: string; }; export type MigrateRequest = { source?: SourceCms; target?: TargetCms; callback?: CallbackConfiguration; concurrency?: number; readOnlyFields?: boolean; transformContentTypes?: { [contentTypeId: string]: string; }; transformGuids?: boolean; copyField?: CopyField; updateField?: UpdateField; duplicate?: Duplicate; migrate?: Migrate; models?: (string | ContentType | Component)[]; query?: SearchQueryOptions; zenQL?: string; entries?: Entry[]; nodes?: Partial[]; tagGroups?: ICreateTagGroup[]; tags?: ICreateTag[]; webhooks?: Partial[]; /** * When updating an existing entry, fields absent from the payload keep * their target values instead of being replaced. Not valid for asset * entries, copyField/updateField operations or model-migration default entries. */ partialEntries?: boolean; ignoreErrors?: boolean; noCache?: boolean; /** Don't publish entries in migrate operations */ noPublish?: boolean; /** Exclude default entries and nodes when migrating content models */ includeDefaults?: false; /** Strip field validations when migrating content models */ includeValidations?: false; outputProgress?: boolean; outputLogs?: LoggerLevels; /** Stop migrating entries with linked content at a specific level */ stopLevel?: number; } & Migrate; export type SourceCms = CmsConfiguration & { project: string; }; export type TargetCms = CmsConfiguration & { syncProjects?: string[]; targetProjects: string[]; }; export type CmsConfiguration = { url: string; clientId?: string; sharedSecret?: string; username?: string; password?: string; refreshToken?: string; assetHostname?: string; language?: string; }; export type MigrateOperations = OperationEntities & { duplicate: OperationEntities; migrate: OperationEntities; }; export type OperationEntities = { components: string[]; contentTypes: string[]; models: string[] | (ContentType | Component)[]; combined: string[]; }; export type Migrate = { contentTypes?: string[]; components?: string[]; }; export type Duplicate = { contentTypes: DuplicateContentType[]; components: DuplicateContentType[]; }; export type DuplicateContentType = { source: string; targets: DuplicateContentTypeTarget[]; }; export type DuplicateContentTypeTarget = { id: string; name: string; description: string; defaultLanguage: string; }; export type CopyField = { contentTypeId: string; fieldId: string; destinationId: string; /** * liquidjs template allowing manipulation of results * https://github.com/contensis/cli/blob/main/packages/contensis-cli/docs/copy_field_templates.md */ template?: string; rootUri?: string; }; export type UpdateField = { fieldId: string; find: string; replace: string; }; type StatusCount = { [projectId: string]: { [contentTypeId: string]: string; }; }; export type SimpleMigrationResult = { committed: boolean; contentTypes: StatusCount; components: StatusCount; errors?: MappedError[]; }; export type MigrateResult = { [MigrateResultStatus.created]: number; [MigrateResultStatus.updated]: number; [MigrateResultStatus.published]: number; [MigrateResultStatus.deleted]: number; [MigrateResultStatus.errors]: number; }; type TotalCount = { totalCount: number; }; export type MigrateStatusTotals = { [status: string]: number; }; export type MigrateEntries = { [projectId: string]: { [contentTypeId: string]: number; totalCount: number; }; }; type EntriesToMigrate = { [projectId: string]: ProjectEntriesToMigrate; }; type ProjectEntriesToMigrate = ContentTypeEntriesToMigrate & TotalCount; export type ContentTypeEntriesToMigrate = { [contentTypeId: string]: MigrateStatusTotals; }; export type EntriesResult = { query: SearchQueryOptions; zenQL: string; entries?: MigrateEntries; existing?: MigrateEntries; entriesToMigrate: EntriesToMigrate; migrateResult?: MigrateResult; errors?: MappedError[]; error?: AppError; }; export type EntriesMigrationResult = EntriesResult & NodesResult & TagsResult; export type ContentTypesResult = { query: { modelIds?: string[]; contentTypeIds?: string[]; componentIds?: string[]; }; errors?: { [id: string]: MappedError[]; }; status: { [id in MigrateStatus]: MigrateContentModelsResponse; }; } & (({ committed: false; } & MigrateModelsPreview) | { committed: true; modelsResult?: MigrateModelsResult; }); export type GetResponse = { [alias: string]: { apiKeys?: ApiKey[]; projects?: Project[]; project?: Project; roles?: Role[]; workflows?: Workflow[]; assetTypes?: string[]; contentTypes?: ContentType[]; components?: Component[]; models?: Model[]; error?: AppError; errors?: [string, AppError][]; }; }; export type MigrateNodes = { [projectId: string]: { nodes?: ManagementNode[]; tree?: DeliveryNode; totalCount: number; }; }; export type ProjectNodesToMigrate = MigrateStatusTotals & TotalCount; type MigrateNodeId = { diff?: string; displayName: string; entryId?: string; id: string; path: string; parentId?: string; status: MigrateStatus; }; type MigrateNodeIds = { [originalId: string]: MigrateNodeId; }; export type NodesResult = { nodes: { [projectId: string]: { paths?: string[]; totalCount: number; }; }; existing: MigrateNodes; nodesToMigrate: { [projectId: string]: ProjectNodesToMigrate | MigrateNodeIds; nodeIds: MigrateNodeIds; }; nodesResult?: MigrateResult; errors?: MappedError[]; error?: AppError; }; export type CopyFieldResult = EntriesResult & { copyField: { projectId: string; contentTypeId: string; field?: Field; targetField: { [projectId: string]: Field | undefined; }; transformType: CopyFieldService['transformType']; }; }; export type UpdateFieldResult = EntriesResult & { updateField: { projectId: string; fieldId?: string; find: string; replace: string; }; }; export type MigrateTagGroups = { [projectId: string]: { groups?: TagGroup[]; totalCount: number; }; }; export type ProjectMigrateTagGroup = { diff?: string; error?: string; status: MigrateStatus; }; export type MigrateTagGroupProjects = { [projectId: string]: ProjectMigrateTagGroup | string | undefined; }; export type MigrateTagGroupIds = { [groupId: string]: { diff?: string; name?: string; description?: string; } & MigrateTagGroupProjects; }; export type TagGroupsResult = { groups: { [projectId: string]: { [groupId: string]: TagGroup['tagCount']; totalCount: number; }; }; existing: MigrateTagGroups; groupsToMigrate: { [projectId: string]: (MigrateStatusTotals & TotalCount) | MigrateTagGroupIds; groupIds: MigrateTagGroupIds; }; groupsResult?: MigrateResult; errors?: MappedError[]; error?: AppError; }; export type MigrateTags = { [projectId: string]: { tags?: Tag[]; totalCount: number; }; }; export type ProjectMigrateTag = ProjectMigrateTagGroup & { id: string; }; export type MigrateTagProjects = { [projectId: string]: ProjectMigrateTag; }; export type MigrateTagIds = { [groupId: string]: { [tagId: string]: { value: string; label: LocalisedString; } & MigrateTagProjects; }; }; export type TagsResult = TagGroupsResult & { tags: { [projectId: string]: { [groupId: string]: TagGroup['tagCount']; totalCount: number; }; }; existing: MigrateTags; tagsToMigrate: { [projectId: string]: (MigrateStatusTotals & TotalCount) | MigrateTagIds; tagIds: MigrateTagIds; }; tagsResult?: MigrateResult; errors?: MappedError[]; error?: AppError; }; export type MigrateWebhooks = { [projectId: string]: { webhooks?: WebhookSubscription[]; totalCount: number; }; }; type MigrateWebhookId = { diff?: string; id: string; name: string; description?: string; enabled?: boolean; method?: string; url?: string; headers?: any; topics?: any; status: MigrateStatus; error?: string; }; type MigrateWebhookIds = { [originalId: string]: MigrateWebhookId; }; export type WebhooksResult = { webhooks: MigrateWebhooks; existing: MigrateWebhooks; webhooksToMigrate: { [projectId: string]: ProjectNodesToMigrate | MigrateWebhookIds; webhookIds: MigrateWebhookIds; }; webhooksResult?: MigrateResult; errors?: MappedError[]; error?: AppError; }; export {};