import type { MigrationModule } from '@kontent-ai/data-ops'; import { contentTypeElementsBuilder } from '@kontent-ai/management-sdk'; const CODE_BLOCK_WIDGET_TYPE = 'code'; function buildCodeBlockWidgetType() { return { name: 'Code block - Widget', codename: CODE_BLOCK_WIDGET_TYPE, external_id: CODE_BLOCK_WIDGET_TYPE, elements: [ contentTypeElementsBuilder.textElement({ type: 'text', name: 'Code', codename: 'code', external_id: `${CODE_BLOCK_WIDGET_TYPE}_code`, is_required: true, is_non_localizable: true, }), ], }; } async function contentTypeExists(apiClient: any, codename: string) { try { await apiClient.viewContentType().byTypeCodename(codename).toPromise(); return true; } catch { return false; } } const migration: MigrationModule = { order: new Date('2026-05-21T11:40:00.000Z'), run: async (apiClient) => { if (!(await contentTypeExists(apiClient, CODE_BLOCK_WIDGET_TYPE))) { await apiClient.addContentType().withData(buildCodeBlockWidgetType).toPromise(); } }, rollback: async () => { // No-op: this content type can already exist from manual production setup. }, }; export default migration;