diff --git a/src/commands/export.ts b/src/commands/export.ts index 1c6f5d40..29feb7da 100644 --- a/src/commands/export.ts +++ b/src/commands/export.ts @@ -5,20 +5,20 @@ import JSZip from "jszip"; import packageFile from "../../package.json" assert { type: "json" }; import { RegisterCommand } from "../types/yargs.js"; import { serially } from "../utils/requests.js"; -import { assetFoldersExportEntity } from "./export/entities/assetFolders.js"; -import { assetsExportEntity } from "./export/entities/assets.js"; -import { collectionsExportEntity } from "./export/entities/collections.js"; -import { contentItemsExportEntity } from "./export/entities/contentItems.js"; -import { contentTypesExportEntity } from "./export/entities/contentTypes.js"; -import { contentTypesSnippetsExportEntity } from "./export/entities/contentTypesSnippets.js"; -import { languagesExportEntity } from "./export/entities/languages.js"; -import { languageVariantsExportEntity } from "./export/entities/languageVariants.js"; -import { previewUrlsExportEntity } from "./export/entities/previewUrls.js"; -import { rolesExportEntity } from "./export/entities/roles.js"; -import { spacesExportEntity } from "./export/entities/spaces.js"; -import { taxonomiesExportEntity } from "./export/entities/taxonomies.js"; -import { workflowsExportEntity } from "./export/entities/workflows.js"; -import { EntityDefinition } from "./export/entityDefinition.js"; +import { assetFoldersExportEntity } from "./importExportEntities/entities/assetFolders.js"; +import { assetsExportEntity } from "./importExportEntities/entities/assets.js"; +import { collectionsExportEntity } from "./importExportEntities/entities/collections.js"; +import { contentItemsExportEntity } from "./importExportEntities/entities/contentItems.js"; +import { contentTypesExportEntity } from "./importExportEntities/entities/contentTypes.js"; +import { contentTypesSnippetsExportEntity } from "./importExportEntities/entities/contentTypesSnippets.js"; +import { languagesExportEntity } from "./importExportEntities/entities/languages.js"; +import { languageVariantsExportEntity } from "./importExportEntities/entities/languageVariants.js"; +import { previewUrlsExportEntity } from "./importExportEntities/entities/previewUrls.js"; +import { rolesExportEntity } from "./importExportEntities/entities/roles.js"; +import { spacesExportEntity } from "./importExportEntities/entities/spaces.js"; +import { taxonomiesExportEntity } from "./importExportEntities/entities/taxonomies.js"; +import { workflowsExportEntity } from "./importExportEntities/entities/workflows.js"; +import { EntityDefinition } from "./importExportEntities/entityDefinition.js"; const zip = new JSZip(); diff --git a/src/commands/export/entities/languages.ts b/src/commands/export/entities/languages.ts deleted file mode 100644 index 09dbb65f..00000000 --- a/src/commands/export/entities/languages.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { LanguageContracts } from "@kontent-ai/management-sdk"; - -import { EntityDefinition } from "../entityDefinition.js"; - -export const languagesExportEntity: EntityDefinition> = { - name: "languages", - fetchEntities: client => client.listLanguages().toAllPromise().then(res => res.data.items.map(l => l._raw)), - serializeEntities: collections => JSON.stringify(collections), - }; - \ No newline at end of file diff --git a/src/commands/export/entities/previewUrls.ts b/src/commands/export/entities/previewUrls.ts deleted file mode 100644 index 867b9dd6..00000000 --- a/src/commands/export/entities/previewUrls.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PreviewContracts } from "@kontent-ai/management-sdk"; - -import { EntityDefinition } from "../entityDefinition.js"; - -export const previewUrlsExportEntity: EntityDefinition = { - name: "previewUrls", - fetchEntities: client => client.getPreviewConfiguration().toPromise().then(res => res.rawData), - serializeEntities: collections => JSON.stringify(collections), - }; \ No newline at end of file diff --git a/src/commands/export/entities/roles.ts b/src/commands/export/entities/roles.ts deleted file mode 100644 index 6a61f033..00000000 --- a/src/commands/export/entities/roles.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { RoleContracts } from "@kontent-ai/management-sdk"; - -import { EntityDefinition } from "../entityDefinition.js"; - -export const rolesExportEntity: EntityDefinition> = { - name: "roles", - fetchEntities: client => client.listRoles().toPromise().then(res => res.rawData.roles), - serializeEntities: collections => JSON.stringify(collections), - }; \ No newline at end of file diff --git a/src/commands/export/entities/workflows.ts b/src/commands/export/entities/workflows.ts deleted file mode 100644 index 251efff0..00000000 --- a/src/commands/export/entities/workflows.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { WorkflowContracts } from "@kontent-ai/management-sdk"; - -import { EntityDefinition } from "../entityDefinition.js"; - -export const workflowsExportEntity: EntityDefinition = { - name: "workflows", - fetchEntities: client => client.listWorkflows().toPromise().then(res => res.rawData), - serializeEntities: collections => JSON.stringify(collections), - }; \ No newline at end of file diff --git a/src/commands/export/entities/assetFolders.ts b/src/commands/importExportEntities/entities/assetFolders.ts similarity index 74% rename from src/commands/export/entities/assetFolders.ts rename to src/commands/importExportEntities/entities/assetFolders.ts index d5e64a4e..292cb4d0 100644 --- a/src/commands/export/entities/assetFolders.ts +++ b/src/commands/importExportEntities/entities/assetFolders.ts @@ -6,4 +6,6 @@ export const assetFoldersExportEntity: EntityDefinition client.listAssetFolders().toPromise().then(res => res.rawData.folders), serializeEntities: JSON.stringify, + importEntities: () => { throw new Error("Not supported yet.")}, + deserializeEntities: () => { throw new Error("Not supported yet.")}, }; diff --git a/src/commands/export/entities/assets.ts b/src/commands/importExportEntities/entities/assets.ts similarity index 87% rename from src/commands/export/entities/assets.ts rename to src/commands/importExportEntities/entities/assets.ts index a5d730af..19084b73 100644 --- a/src/commands/export/entities/assets.ts +++ b/src/commands/importExportEntities/entities/assets.ts @@ -15,6 +15,8 @@ export const assetsExportEntity: EntityDefinition () => saveAsset(assetsZip, a))) }, + importEntities: () => { throw new Error("Not supported yet.")}, + deserializeEntities: () => { throw new Error("Not supported yet.")}, }; const saveAsset = async (zip: JSZip, asset: AssetContracts.IAssetModelContract) => { diff --git a/src/commands/export/entities/collections.ts b/src/commands/importExportEntities/entities/collections.ts similarity index 76% rename from src/commands/export/entities/collections.ts rename to src/commands/importExportEntities/entities/collections.ts index c5918a23..6e5f2fa5 100644 --- a/src/commands/export/entities/collections.ts +++ b/src/commands/importExportEntities/entities/collections.ts @@ -6,4 +6,6 @@ export const collectionsExportEntity: EntityDefinition client.listCollections().toPromise().then(res => res.rawData.collections), serializeEntities: collections => JSON.stringify(collections), + importEntities: () => { throw new Error("Not supported yet.")}, + deserializeEntities: () => { throw new Error("Not supported yet.")}, }; diff --git a/src/commands/export/entities/contentItems.ts b/src/commands/importExportEntities/entities/contentItems.ts similarity index 76% rename from src/commands/export/entities/contentItems.ts rename to src/commands/importExportEntities/entities/contentItems.ts index 7f6c647b..2c28c66c 100644 --- a/src/commands/export/entities/contentItems.ts +++ b/src/commands/importExportEntities/entities/contentItems.ts @@ -6,4 +6,6 @@ export const contentItemsExportEntity: EntityDefinition client.listContentItems().toAllPromise().then(res => res.data.items.map(i => i._raw)), serializeEntities: collections => JSON.stringify(collections), -}; \ No newline at end of file + importEntities: () => { throw new Error("Not supported yet.")}, + deserializeEntities: () => { throw new Error("Not supported yet.")}, +}; diff --git a/src/commands/export/entities/contentTypes.ts b/src/commands/importExportEntities/entities/contentTypes.ts similarity index 76% rename from src/commands/export/entities/contentTypes.ts rename to src/commands/importExportEntities/entities/contentTypes.ts index be4060d8..9ef50a37 100644 --- a/src/commands/export/entities/contentTypes.ts +++ b/src/commands/importExportEntities/entities/contentTypes.ts @@ -9,4 +9,6 @@ export const contentTypesExportEntity: EntityDefinition res.data.items.map(t => t._raw)), serializeEntities: collections => JSON.stringify(collections), -}; \ No newline at end of file + importEntities: () => { throw new Error("Not supported yet.")}, + deserializeEntities: () => { throw new Error("Not supported yet.")}, +}; diff --git a/src/commands/export/entities/contentTypesSnippets.ts b/src/commands/importExportEntities/entities/contentTypesSnippets.ts similarity index 78% rename from src/commands/export/entities/contentTypesSnippets.ts rename to src/commands/importExportEntities/entities/contentTypesSnippets.ts index b22f48f3..9622d31f 100644 --- a/src/commands/export/entities/contentTypesSnippets.ts +++ b/src/commands/importExportEntities/entities/contentTypesSnippets.ts @@ -9,4 +9,6 @@ export const contentTypesSnippetsExportEntity: EntityDefinition res.data.items.map(s => s._raw)), serializeEntities: collections => JSON.stringify(collections), -}; \ No newline at end of file + importEntities: () => { throw new Error("Not supported yet.")}, + deserializeEntities: () => { throw new Error("Not supported yet.")}, +}; diff --git a/src/commands/export/entities/languageVariants.ts b/src/commands/importExportEntities/entities/languageVariants.ts similarity index 85% rename from src/commands/export/entities/languageVariants.ts rename to src/commands/importExportEntities/entities/languageVariants.ts index fa24b5ab..8f890db8 100644 --- a/src/commands/export/entities/languageVariants.ts +++ b/src/commands/importExportEntities/entities/languageVariants.ts @@ -19,4 +19,6 @@ export const languageVariantsExportEntity: EntityDefinition arr); }, serializeEntities: collections => JSON.stringify(collections), -}; \ No newline at end of file + importEntities: () => { throw new Error("Not supported yet.")}, + deserializeEntities: () => { throw new Error("Not supported yet.")}, +}; diff --git a/src/commands/importExportEntities/entities/languages.ts b/src/commands/importExportEntities/entities/languages.ts new file mode 100644 index 00000000..783f5f24 --- /dev/null +++ b/src/commands/importExportEntities/entities/languages.ts @@ -0,0 +1,11 @@ +import { LanguageContracts } from "@kontent-ai/management-sdk"; + +import { EntityDefinition } from "../entityDefinition.js"; + +export const languagesExportEntity: EntityDefinition> = { + name: "languages", + fetchEntities: client => client.listLanguages().toAllPromise().then(res => res.data.items.map(l => l._raw)), + serializeEntities: collections => JSON.stringify(collections), + importEntities: () => { throw new Error("Not supported yet.")}, + deserializeEntities: () => { throw new Error("Not supported yet.")}, +}; diff --git a/src/commands/importExportEntities/entities/previewUrls.ts b/src/commands/importExportEntities/entities/previewUrls.ts new file mode 100644 index 00000000..024a1ec6 --- /dev/null +++ b/src/commands/importExportEntities/entities/previewUrls.ts @@ -0,0 +1,11 @@ +import { PreviewContracts } from "@kontent-ai/management-sdk"; + +import { EntityDefinition } from "../entityDefinition.js"; + +export const previewUrlsExportEntity: EntityDefinition = { + name: "previewUrls", + fetchEntities: client => client.getPreviewConfiguration().toPromise().then(res => res.rawData), + serializeEntities: collections => JSON.stringify(collections), + importEntities: () => { throw new Error("Not supported yet.")}, + deserializeEntities: () => { throw new Error("Not supported yet.")}, +}; diff --git a/src/commands/importExportEntities/entities/roles.ts b/src/commands/importExportEntities/entities/roles.ts new file mode 100644 index 00000000..0509f77b --- /dev/null +++ b/src/commands/importExportEntities/entities/roles.ts @@ -0,0 +1,11 @@ +import { RoleContracts } from "@kontent-ai/management-sdk"; + +import { EntityDefinition } from "../entityDefinition.js"; + +export const rolesExportEntity: EntityDefinition> = { + name: "roles", + fetchEntities: client => client.listRoles().toPromise().then(res => res.rawData.roles), + serializeEntities: collections => JSON.stringify(collections), + importEntities: () => { throw new Error("Not supported yet.")}, + deserializeEntities: () => { throw new Error("Not supported yet.")}, +}; diff --git a/src/commands/export/entities/spaces.ts b/src/commands/importExportEntities/entities/spaces.ts similarity index 73% rename from src/commands/export/entities/spaces.ts rename to src/commands/importExportEntities/entities/spaces.ts index f529cd46..c0299acc 100644 --- a/src/commands/export/entities/spaces.ts +++ b/src/commands/importExportEntities/entities/spaces.ts @@ -6,4 +6,6 @@ export const spacesExportEntity: EntityDefinition client.listSpaces().toPromise().then(res => res.rawData), serializeEntities: spaces => JSON.stringify(spaces), + importEntities: () => { throw new Error("Not supported yet.")}, + deserializeEntities: () => { throw new Error("Not supported yet.")}, } diff --git a/src/commands/export/entities/taxonomies.ts b/src/commands/importExportEntities/entities/taxonomies.ts similarity index 76% rename from src/commands/export/entities/taxonomies.ts rename to src/commands/importExportEntities/entities/taxonomies.ts index 87a07549..42a25714 100644 --- a/src/commands/export/entities/taxonomies.ts +++ b/src/commands/importExportEntities/entities/taxonomies.ts @@ -6,4 +6,6 @@ export const taxonomiesExportEntity: EntityDefinition client.listTaxonomies().toAllPromise().then(res => res.data.items.map(t => t._raw)), serializeEntities: taxonomies => JSON.stringify(taxonomies), + importEntities: () => { throw new Error("Not supported yet.")}, + deserializeEntities: () => { throw new Error("Not supported yet.")}, }; diff --git a/src/commands/importExportEntities/entities/workflows.ts b/src/commands/importExportEntities/entities/workflows.ts new file mode 100644 index 00000000..fd6f99e3 --- /dev/null +++ b/src/commands/importExportEntities/entities/workflows.ts @@ -0,0 +1,11 @@ +import { WorkflowContracts } from "@kontent-ai/management-sdk"; + +import { EntityDefinition } from "../entityDefinition.js"; + +export const workflowsExportEntity: EntityDefinition = { + name: "workflows", + fetchEntities: client => client.listWorkflows().toPromise().then(res => res.rawData), + serializeEntities: collections => JSON.stringify(collections), + importEntities: () => { throw new Error("Not supported yet.")}, + deserializeEntities: () => { throw new Error("Not supported yet.")}, +}; diff --git a/src/commands/export/entityDefinition.ts b/src/commands/importExportEntities/entityDefinition.ts similarity index 70% rename from src/commands/export/entityDefinition.ts rename to src/commands/importExportEntities/entityDefinition.ts index e12d42c0..87db5424 100644 --- a/src/commands/export/entityDefinition.ts +++ b/src/commands/importExportEntities/entityDefinition.ts @@ -6,4 +6,6 @@ export type EntityDefinition = Readonly<{ fetchEntities: (client: ManagementClient) => Promise; serializeEntities: (entities: T) => string; addOtherFiles?: (loadedEntities: T, zip: JSZip) => Promise; + deserializeEntities: (serialized: string) => T; + importEntities: (client: ManagementClient, entities: T, zip: JSZip) => Promise; }>;