Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
feat: adds support for exporting webhooks & collections
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed May 31, 2022
1 parent 5851315 commit e3f6cc2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
23 changes: 13 additions & 10 deletions lib/core/core.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
LanguageVariantContracts,
ContentItemContracts,
AssetFolderModels,
AssetFolderContracts,
AssetFolderContracts
} from '@kentico/kontent-management';

export interface ICliFileConfig {
Expand All @@ -41,6 +41,8 @@ export type ItemType =
| 'asset'
| 'assetFolder'
| 'workflowStep'
| 'collection'
| 'webhook'
| 'binaryFile';

export type ActionType = ItemType | 'publish' | 'changeWorkflowStep';
Expand Down Expand Up @@ -94,13 +96,14 @@ export interface IPackageMetadata {

export interface IPackageDataOverview {
taxonomiesCount: number;
contentTypeSnippetsCount: number;
contentTypesCount: number;
contentItemsCount: number;
languageVariantsCount: number;
languagesCount: number;
assetsCount: number;
assetFoldersCount: number;
workflowStepsCount: number;
contentTypeSnippetsCount: number;
contentTypesCount: number;
contentItemsCount: number;
languageVariantsCount: number;
languagesCount: number;
assetsCount: number;
assetFoldersCount: number;
workflowStepsCount: number;
webhooksCount: number;
collectionsCount: number;
}

4 changes: 4 additions & 0 deletions lib/export/export.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
TaxonomyContracts,
ProjectContracts,
WorkflowContracts,
WebhookContracts,
CollectionContracts,
} from '@kentico/kontent-management';

import { IProcessedItem, IPackageMetadata, ItemType } from '../core';
Expand All @@ -31,6 +33,8 @@ export interface IExportData {
languageVariants: LanguageVariantContracts.ILanguageVariantModelContract[];
languages: LanguageContracts.ILanguageModelContract[];
assets: AssetContracts.IAssetModelContract[];
webhooks: WebhookContracts.IWebhookContract[];
collections: CollectionContracts.ICollectionContract[];
assetFolders: AssetFolderContracts.IAssetFolderContract[];
}

Expand Down
26 changes: 23 additions & 3 deletions lib/export/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
LanguageContracts,
AssetFolderContracts,
ProjectContracts,
WorkflowContracts
WorkflowContracts,
WebhookContracts,
CollectionContracts
} from '@kentico/kontent-management';

import { IExportAllResult, IExportConfig, IExportData } from './export.models';
Expand All @@ -33,11 +35,13 @@ export class ExportService {
assetFolder: this.config.exportFilter?.includes('assetFolder') ?? true,
binaryFile: this.config.exportFilter?.includes('binaryFile') ?? true,
contentItem: this.config.exportFilter?.includes('contentItem') ?? true,
collections: this.config.exportFilter?.includes('collection') ?? true,
contentType: this.config.exportFilter?.includes('contentType') ?? true,
contentTypeSnippet: this.config.exportFilter?.includes('contentTypeSnippet') ?? true,
language: this.config.exportFilter?.includes('language') ?? true,
languageVariant: this.config.exportFilter?.includes('languageVariant') ?? true,
taxonomy: this.config.exportFilter?.includes('taxonomy') ?? true,
webhooks: this.config.exportFilter?.includes('webhook') ?? true,
workflowSteps: this.config.exportFilter?.includes('workflowStep') ?? true
};

Expand All @@ -59,8 +63,10 @@ export class ExportService {
contentTypes: exportItems.contentType ? contentTypes : [],
contentTypeSnippets: exportItems.contentTypeSnippet ? await this.exportContentTypeSnippetsAsync() : [],
taxonomies: exportItems.taxonomy ? await this.exportTaxonomiesAsync() : [],
webhooks: exportItems.webhooks ? await this.exportWebhooksAsync() : [],
workflowSteps: exportItems.taxonomy ? await this.exportWorkflowStepsAsync() : [],
contentItems: exportItems.contentItem ? await this.exportContentItemsAsync() : [],
collections: exportItems.collections ? await this.exportCollectionsAsync() : [],
languageVariants: exportItems.languageVariant
? await this.exportLanguageVariantsAsync(contentItems.map((m) => m.id))
: [],
Expand All @@ -86,7 +92,9 @@ export class ExportService {
languageVariantsCount: data.languageVariants.length,
languagesCount: data.languages.length,
taxonomiesCount: data.taxonomies.length,
workflowStepsCount: data.workflowSteps.length
workflowStepsCount: data.workflowSteps.length,
webhooksCount: data.webhooks.length,
collectionsCount: data.collections.length
}
},
validation: projectValidation,
Expand Down Expand Up @@ -136,11 +144,23 @@ export class ExportService {
}

public async exportTaxonomiesAsync(): Promise<TaxonomyContracts.ITaxonomyContract[]> {
const response = await this.client.listTaxonomies().toPromise();
const response = await this.client.listTaxonomies().toAllPromise();
response.data.items.forEach((m) => this.processItem(m.name, 'taxonomy', m));
return response.data.items.map((m) => m._raw);
}

public async exportWebhooksAsync(): Promise<WebhookContracts.IWebhookContract[]> {
const response = await this.client.listWebhooks().toPromise();
response.data.webhooks.forEach((m) => this.processItem(m.name, 'webhook', m));
return response.data.webhooks.map((m) => m._raw);
}

public async exportCollectionsAsync(): Promise<CollectionContracts.ICollectionContract[]> {
const response = await this.client.listCollections().toPromise();
response.data.collections.forEach((m) => this.processItem(m.name, 'collection', m));
return response.data.collections.map((m) => m._raw);
}

public async exportContentTypeSnippetsAsync(): Promise<ContentTypeSnippetContracts.IContentTypeSnippetContract[]> {
const response = await this.client
.listContentTypeSnippets()
Expand Down
6 changes: 5 additions & 1 deletion lib/zip/zip.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class ZipService {
private readonly filesName: string = 'files';
private readonly assetFoldersName: string = 'assetFolders.json';
private readonly workflowStepsName: string = 'workflowSteps.json';
private readonly webhooksName: string = 'webhooks.json';
private readonly collectionsName: string = 'collections.json';
private readonly validationName: string = 'validation.json';

private readonly httpService: HttpService = new HttpService();
Expand Down Expand Up @@ -81,6 +83,8 @@ export class ZipService {
zip.file(this.contentTypeSnippetsName, JSON.stringify(exportData.data.contentTypeSnippets));
zip.file(this.assetFoldersName, JSON.stringify(exportData.data.assetFolders));
zip.file(this.workflowStepsName, JSON.stringify(exportData.data.workflowSteps));
zip.file(this.webhooksName, JSON.stringify(exportData.data.webhooks));
zip.file(this.collectionsName, JSON.stringify(exportData.data.collections));

const assetsFolder = zip.folder(this.filesName);

Expand Down Expand Up @@ -192,7 +196,7 @@ export class ZipService {
url = url.replace('#', '%23');

if (enableLog) {
console.log(`Start asset download: ${url}`);
console.log(`Asset download: ${url}`);
}

return (
Expand Down

0 comments on commit e3f6cc2

Please sign in to comment.