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

Commit

Permalink
feat: adds ability to skip validation endpoint in project export
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed May 3, 2022
1 parent 8615809 commit 0870404
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Install package globally:
| **action** | Action. Possible values are: `restore` & `backup` & `clean` **(required)** |
| zipFilename | Name of zip used for export / restoring data. (e.g. 'kontent-backup'). |
| enableLog | Indicates if default logging is enabled (useful to indicate progress)
| skipValidation | Skips validation endpoint during project export
| force | If enabled, project will we exported / restored even if there are data inconsistencies. Enabled by default. |
| baseUrl | Custom base URL for Management API calls. |
| enablePublish | Indicates if language variants published on the source project are also published on target. Enabled by default |
Expand Down
3 changes: 2 additions & 1 deletion lib/core/core.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export interface ICliFileConfig {
enablePublish: boolean;
force: boolean;
baseUrl?: string;
exportFilter?: ItemType[]
exportFilter?: ItemType[];
skipValidation?: boolean;
}

export type CliAction = 'backup' | 'restore' | 'clean';
Expand Down
3 changes: 2 additions & 1 deletion lib/export/export.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface IExportConfig {
baseUrl?: string;
onExport?: (item: IProcessedItem) => void;
exportFilter?: ItemType[];
skipValidation: boolean;
}

export interface IExportData {
Expand All @@ -36,5 +37,5 @@ export interface IExportData {
export interface IExportAllResult {
metadata: IPackageMetadata;
data: IExportData;
validation: ProjectContracts.IProjectReportResponseContract;
validation: ProjectContracts.IProjectReportResponseContract | {};
}
37 changes: 21 additions & 16 deletions lib/export/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,22 @@ export class ExportService {
language: this.config.exportFilter?.includes('language') ?? true,
languageVariant: this.config.exportFilter?.includes('languageVariant') ?? true,
taxonomy: this.config.exportFilter?.includes('taxonomy') ?? true,
workflowSteps: this.config.exportFilter?.includes('workflowStep') ?? true,
workflowSteps: this.config.exportFilter?.includes('workflowStep') ?? true
};

let projectValidation: undefined | ProjectContracts.IProjectReportResponseContract = undefined;

if (!this.config.skipValidation) {
projectValidation = await this.exportProjectValidationAsync();
console.log(`Project validation - ${projectValidation.type_issues.length} type issues, ${projectValidation.variant_issues.length} variant issues`);
} else {
console.log('Skipping project validation endpoint');
}

const contentTypes = await this.exportContentTypesAsync({ processItem: exportItems.contentType });
const projectValidation = await this.exportProjectValidationAsync();
const contentItems = exportItems.contentItem || exportItems.languageVariant ? await this.exportContentItemsAsync() : []

const contentItems =
exportItems.contentItem || exportItems.languageVariant ? await this.exportContentItemsAsync() : [];

const data: IExportData = {
contentTypes: exportItems.contentType ? contentTypes : [],
Expand All @@ -64,8 +74,9 @@ export class ExportService {
version,
timestamp: new Date(),
projectId: this.config.projectId,
isInconsistentExport:
projectValidation.type_issues.length > 0 || projectValidation.variant_issues.length > 0,
isInconsistentExport: projectValidation
? projectValidation.type_issues.length > 0 || projectValidation.variant_issues.length > 0
: false,
dataOverview: {
assetFoldersCount: data.assetFolders.length,
assetsCount: data.assets.length,
Expand All @@ -75,10 +86,10 @@ export class ExportService {
languageVariantsCount: data.languageVariants.length,
languagesCount: data.languages.length,
taxonomiesCount: data.taxonomies.length,
workflowStepsCount: data.workflowSteps.length,
workflowStepsCount: data.workflowSteps.length
}
},
validation: projectValidation,
validation: projectValidation ?? {},
data
};
}
Expand Down Expand Up @@ -176,16 +187,10 @@ export class ExportService {
const languageVariants: LanguageVariantContracts.ILanguageVariantModelWithComponentsContract[] = [];

for (const contentItemId of contentItemIds) {
const response = await this.client
.listLanguageVariantsOfItem()
.byItemId(contentItemId)
.toPromise();

const response = await this.client.listLanguageVariantsOfItem().byItemId(contentItemId).toPromise();

languageVariants.push(...response.data.items.map((m) => m._raw));
response.data.items.forEach((m) =>
this.processItem(m.item.id?.toString() ?? '-', 'languageVariant', m)
);
languageVariants.push(...response.data.items.map((m) => m._raw));
response.data.items.forEach((m) => this.processItem(m.item.id?.toString() ?? '-', 'languageVariant', m));
}

return languageVariants;
Expand Down
7 changes: 6 additions & 1 deletion lib/node/cli/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const argv = yargs(process.argv.slice(2))
)
.alias('p', 'projectId')
.describe('p', 'ProjectId')
.alias('sv', 'skipValidation')
.describe('sv', 'Skips validation endpoint during export')
.alias('k', 'apiKey')
.describe('k', 'Management API Key')
.alias('a', 'action')
Expand Down Expand Up @@ -57,6 +59,7 @@ const backupAsync = async (config: ICliFileConfig) => {
projectId: config.projectId,
baseUrl: config.baseUrl,
exportFilter: config.exportFilter,
skipValidation: config.skipValidation ?? false,
onExport: (item) => {
if (config.enableLog) {
console.log(`Exported: ${item.title} | ${item.type}`);
Expand Down Expand Up @@ -236,6 +239,7 @@ const getConfig = async () => {
const enableLog: boolean | undefined = (resolvedArgs.enableLog as boolean | undefined) ?? true;
const force: boolean | undefined = (resolvedArgs.force as boolean | undefined) ?? true;
const enablePublish: boolean | undefined = (resolvedArgs.enablePublish as boolean | undefined) ?? true;
const skipValidation: boolean = (resolvedArgs.skipValidation as boolean | undefined) ?? false;
const projectId: string | undefined = resolvedArgs.projectId as string | undefined;
const baseUrl: string | undefined = resolvedArgs.baseUrl as string | undefined;
const zipFilename: string | undefined =
Expand Down Expand Up @@ -273,7 +277,8 @@ const getConfig = async () => {
projectId,
zipFilename,
baseUrl,
exportFilter: exportFilterMapped
exportFilter: exportFilterMapped,
skipValidation
};

return config;
Expand Down
1 change: 1 addition & 0 deletions lib/samples/export-sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const run = async () => {
const exportService = new ExportService({
apiKey: 'sourceProjectApiKey',
projectId: 'sourceProjectId',
skipValidation: false,
onExport: item => {
// called when any content is exported
console.log(`Exported: ${item.title} | ${item.type}`);
Expand Down

0 comments on commit 0870404

Please sign in to comment.