import type { Options } from '@contentful/rich-text-html-renderer'; import type { Document } from '@contentful/rich-text-types'; import type { QueryOptions } from 'contentful-management/types'; import type { Observable, ReplaySubject } from 'rxjs'; import type { ContentTypeField, Asset as ContentfulAsset, ContentType as ContentfulContentType, ContentfulCollection as ContentfulContentfulCollection, Entry as ContentfulEntry, EntryCollection as ContentfulEntryCollection, Locale as ContentfulLocale, DeletedAsset, DeletedEntry, EntryFields, EntrySkeletonType, LocaleCode, ResolvedField } from 'contentful'; import type { ListrTaskObject } from 'listr'; import type { FileManager } from './lib/file-manager.js'; import type { HookManager } from './lib/hook-manager.js'; import type { Stats } from './lib/stats.js'; export type Field = ContentTypeField; export type { Ignore } from 'ignore'; export type KeyValueMap = Record; export type Locale = ContentfulLocale; export type ContentType = ContentfulContentType; export type EntryRaw = ContentfulEntry; export type AssetRaw = ContentfulAsset<'WITH_ALL_LOCALES'>; export type NodeRaw = EntryRaw | AssetRaw; export type Asset = ContentfulAsset; export type Entry = ContentfulEntry; export type Node = Entry | Asset; export type EntryFieldRaw = { [FieldName in keyof EntrySkeletonType['fields']]: { [LocaleName in LocaleCode]?: ResolvedField; }; }; export type EntryField = { [FieldName in keyof EntrySkeletonType['fields']]: ResolvedField; }; export type EntryCollection = { includes?: { Entry?: EntryRaw[]; Asset?: AssetRaw[]; }; } & ContentfulEntryCollection; export type ContentfulCollection = ContentfulContentfulCollection; export type ContentfulRichtextOptions = Options; export type FormatObject = KeyValueMap; export type RichTextConfig = boolean | ContentfulRichtextOptions | ((document: Document, transformContext: TransformContext, runtimeContext: RuntimeContext) => unknown); export type ContentfulConfig = { spaceId: string; environmentId: string; managementToken: string; previewAccessToken: string; accessToken: string; host?: string; preview?: boolean; sync?: boolean; query?: QueryOptions; }; export type ContentfulRcConfig = { managementToken: string; activeSpaceId: string; activeEnvironmentId: string; host: string; }; export type ConfigHook = (config: Config) => Config | Promise; export type RuntimeHook = (runtimeContext: RuntimeContext) => Promise> | Partial | void; export type TransformHook = (transformContext: TransformContext, runtimeContext?: RuntimeContext, prev?: T) => Promise | T; export type ValidateHook = (transformContext: TransformContext, runtimeContext?: RuntimeContext) => Promise | boolean; export type Hooks = { config?: ConfigHook; before?: RuntimeHook; after?: RuntimeHook; transform?: TransformHook; mapDirectory?: TransformHook; mapFilename?: TransformHook; mapMetaFields?: TransformHook; mapAssetLink?: TransformHook; mapEntryLink?: TransformHook; }; export type Config = Partial & Hooks & { rootDir?: string; directory: string; managedDirectories?: string[]; verbose?: boolean; ignoreErrors?: boolean; plugins?: Array<[string, KeyValueMap] | PluginInfo | string>; resolvedPlugins?: Hooks[]; preset?: string; richTextRenderer?: RichTextConfig; format?: string | FormatObject | TransformHook; validate?: ValidateHook; }; export type PluginInfo = { options: KeyValueMap; resolve: string; }; export type PluginModule = { default?: PluginSource; } & Partial; export type PluginSource = Hooks | ((options?: KeyValueMap) => Promise | Hooks); export type FieldSettings = KeyValueMap>; export type ContentfulData = { fieldSettings: FieldSettings; locales: Locale[]; contentTypes: ContentType[]; entries: EntryRaw[]; assets: AssetRaw[]; deletedEntries?: DeletedEntry[]; deletedAssets?: DeletedAsset[]; }; export type LocalizedContent = { [x: string]: any; assets: Asset[]; entries: Entry[]; assetMap: Map; entryMap: Map; }; export type StatsKey = string; export type Converter = { parse: (string: string) => T; stringify: (obj: T) => string; }; export type MarkdownConverter = { parse: (string: string) => T; stringify: (obj: T, additional?: string) => string; }; type Entries = Array<{ [K in keyof T]: [K, T[K]]; }[keyof T]>; export type RuntimeContext = { [x: string]: any; config: Config; defaultLocale: string; data: Partial; localized: Map; fileManager: FileManager; stats: Stats; hooks: HookManager; helper: { [x: string]: any; array: { mapAsync: (iterable: T[], callback: (value: T, index?: number, iterable?: T[]) => U | Promise) => Promise; forEachAsync: (iterable: T[], callback: (value: T, index?: number, iterable?: T[]) => void | Promise) => Promise; filterAsync: (iterable: T[], callback: (value: T, index?: number, array?: T[]) => boolean | Promise) => Promise; reduceAsync: (iterable: T[], callback: (previousValue: U, currentValue: T, currentIndex?: number, array?: T[]) => U | Promise, initialValue?: U) => Promise; }; object: { isObject: (something: any) => boolean; getEntries: (obj: T) => Entries; fromEntries: >(entries: Entries) => T; omitKeys: (obj: T, ...keys: K[]) => T; removeEmpty: (iterable: T) => T; snakeCaseKeys: (iterable: T) => T; groupBy: , K extends keyof T>(array: T[], key: K) => Record; }; }; converter: { yaml: Converter; json: Converter; markdown: Converter; toml: Converter; }; observables?: Record>; }; export type Task = ListrTaskObject; export type RunResult = { observables: Record>; localized: Record; }; export type TransformHelper = { collectValues: (key: any, options?: CollectOptions) => T[]; collectParentValues: (key: any, options?: CollectOptions) => T[]; waitFor: (id: string, waitTimeout?: number) => Promise; }; export type TransformContext = LocalizedContent & { [x: string]: any; id: string; content?: KeyValueMap; entry: Entry; asset?: Asset; contentTypeId: string; locale: Locale; fieldId?: string; fieldContent?: unknown; fieldSettings?: Field; requiredFields?: string[]; utils: TransformHelper; observable: Observable; }; export type ObservableContext = Readonly & { error?: Error; }>; export type StatsEntry = { id: string; contentTypeId: string; locale: string; message?: string; error?: Error; } & KeyValueMap; export type MapAssetLink = { mimeType: string; url: string; title: string; description: string; width?: number; height?: number; fileSize?: number; }; export type Link = EntryFields.Link; export type RichTextData = { target?: Link; }; export type CollectOptions = { reverse?: boolean; entry?: Entry; entryMap?: Map; linkField?: string; getId?: (entry: Entry) => string; getNextId?: (entry: Entry) => string; getValue?: (entry: Entry) => any; }; export type CollectionResponse = EntryCollection | ContentfulCollection; export type PagedGetOptions = { method: string; skip?: number; aggregatedResponse?: CollectionResponse; query?: QueryOptions; include?: number; }; export type SyncOptions = { initial?: true; nextSyncToken?: string; resolveLinks?: boolean; }; export type ErrorEntry = { spaceId: string; environmentId: string; entryId: string; contentTypeId: string; locale: Locale; missingFields: string[]; }; export type SandboxContext = { module?: NodeModule; exports: Record; process: { env: NodeJS.ProcessEnv; }; require: NodeRequire; __dirname: string; __filename: string; };