Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kentico/kontent-backup-manager

Package Overview
Dependencies
Maintainers
9
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kentico/kontent-backup-manager - npm Package Compare versions

Comparing version 1.14.0 to 1.15.0

15

_commonjs/package.json
{
"name": "@kentico/kontent-backup-manager",
"version": "1.14.0",
"version": "1.15.0",
"description": "This utility enables backup & restore of Kentico Kontent projects",

@@ -17,2 +17,3 @@ "preferGlobal": true,

"scripts": {
"test": "echo \"no global test configured\"",
"release": "standard-version",

@@ -46,16 +47,16 @@ "tsc-local": "./node_modules/.bin/tsc",

"@kentico/kontent-management": "0.4.8",
"jszip": "3.5.0",
"jszip": "3.6.0",
"rxjs": "6.6.3",
"yargs": "16.2.0",
"flatted": "3.1.0"
"flatted": "3.1.1"
},
"devDependencies": {
"@types/jszip": "3.4.1",
"@types/node": "14.14.20",
"@types/yargs": "15.0.12",
"standard-version": "9.1.0",
"@types/node": "14.14.31",
"@types/yargs": "16.0.0",
"standard-version": "9.1.1",
"ts-node": "9.1.1",
"tslint": "6.1.3",
"typescript": "4.1.3"
"typescript": "4.1.5"
}
}

@@ -8,2 +8,3 @@ import { AssetContracts, AssetModels, ContentItemModels, ContentTypeContracts, ContentTypeModels, ContentTypeSnippetContracts, ContentTypeSnippetModels, LanguageContracts, LanguageModels, LanguageVariantModels, TaxonomyContracts, TaxonomyModels, LanguageVariantContracts, ContentItemContracts, AssetFolderModels, AssetFolderContracts } from '@kentico/kontent-management';

enableLog: boolean;
enablePublish: boolean;
force: boolean;

@@ -14,3 +15,4 @@ baseUrl?: string;

export declare type CliAction = 'backup' | 'restore' | 'clean';
export declare type ItemType = 'taxonomy' | 'contentType' | 'contentTypeSnippet' | 'contentItem' | 'languageVariant' | 'language' | 'asset' | 'assetFolder' | 'binaryFile';
export declare type ItemType = 'taxonomy' | 'contentType' | 'contentTypeSnippet' | 'contentItem' | 'languageVariant' | 'language' | 'asset' | 'assetFolder' | 'workflowStep' | 'binaryFile';
export declare type ActionType = ItemType | 'publish' | 'changeWorkflowStep';
export declare type ValidImportModel = ContentTypeModels.ContentType | TaxonomyModels.Taxonomy | ContentTypeSnippetModels.ContentTypeSnippet | LanguageVariantModels.ContentItemLanguageVariant | ContentItemModels.ContentItem | LanguageModels.LanguageModel | AssetModels.Asset | AssetFolderModels.AssetFolder;

@@ -20,3 +22,3 @@ export declare type ValidImportContract = ContentTypeContracts.IContentTypeContract | TaxonomyContracts.ITaxonomyContract | ContentTypeSnippetContracts.IContentTypeSnippetContract | ContentItemContracts.IContentItemModelContract | TaxonomyContracts.ITaxonomyContract | AssetContracts.IAssetModelContract | LanguageVariantContracts.ILanguageVariantModelContract | LanguageContracts.ILanguageModelContract | AssetFolderContracts.IAssetFolderContract;

title: string;
type: ItemType;
type: ActionType;
data: any;

@@ -49,2 +51,3 @@ }

assetFoldersCount: number;
workflowStepsCount: number;
}

@@ -1,2 +0,2 @@

import { AssetContracts, AssetFolderContracts, ContentItemContracts, ContentTypeContracts, ContentTypeSnippetContracts, LanguageContracts, LanguageVariantContracts, TaxonomyContracts, ProjectContracts } from '@kentico/kontent-management';
import { AssetContracts, AssetFolderContracts, ContentItemContracts, ContentTypeContracts, ContentTypeSnippetContracts, LanguageContracts, LanguageVariantContracts, TaxonomyContracts, ProjectContracts, WorkflowContracts } from '@kentico/kontent-management';
import { IProcessedItem, IPackageMetadata, ItemType } from '../core';

@@ -11,2 +11,3 @@ export interface IExportConfig {

export interface IExportData {
workflowSteps: WorkflowContracts.IWorkflowStepContract[];
taxonomies: TaxonomyContracts.ITaxonomyContract[];

@@ -13,0 +14,0 @@ contentTypeSnippets: ContentTypeSnippetContracts.IContentTypeSnippetContract[];

@@ -1,2 +0,2 @@

import { ContentItemContracts, ContentTypeContracts, ContentTypeSnippetContracts, LanguageVariantContracts, TaxonomyContracts, AssetContracts, LanguageContracts, AssetFolderContracts, ProjectContracts } from '@kentico/kontent-management';
import { ContentItemContracts, ContentTypeContracts, ContentTypeSnippetContracts, LanguageVariantContracts, TaxonomyContracts, AssetContracts, LanguageContracts, AssetFolderContracts, ProjectContracts, WorkflowContracts } from '@kentico/kontent-management';
import { IExportAllResult, IExportConfig } from './export.models';

@@ -12,2 +12,3 @@ export declare class ExportService {

exportLanguagesAsync(): Promise<LanguageContracts.ILanguageModelContract[]>;
exportWorkflowStepsAsync(): Promise<WorkflowContracts.IWorkflowStepContract[]>;
exportTaxonomiesAsync(): Promise<TaxonomyContracts.ITaxonomyContract[]>;

@@ -14,0 +15,0 @@ exportContentTypeSnippetsAsync(): Promise<ContentTypeSnippetContracts.IContentTypeSnippetContract[]>;

@@ -52,8 +52,8 @@ "use strict";

ExportService.prototype.exportAllAsync = function () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
return __awaiter(this, void 0, void 0, function () {
var exportItems, contentTypes, projectValidation, contentItems, _u, data, _v, _w, _x, _y, _z, _0, _1;
var _2;
return __generator(this, function (_3) {
switch (_3.label) {
var exportItems, contentTypes, projectValidation, contentItems, _w, data, _x, _y, _z, _0, _1, _2, _3, _4;
var _5;
return __generator(this, function (_6) {
switch (_6.label) {
case 0:

@@ -69,21 +69,22 @@ exportItems = {

languageVariant: (_r = (_q = this.config.exportFilter) === null || _q === void 0 ? void 0 : _q.includes('languageVariant')) !== null && _r !== void 0 ? _r : true,
taxonomy: (_t = (_s = this.config.exportFilter) === null || _s === void 0 ? void 0 : _s.includes('taxonomy')) !== null && _t !== void 0 ? _t : true
taxonomy: (_t = (_s = this.config.exportFilter) === null || _s === void 0 ? void 0 : _s.includes('taxonomy')) !== null && _t !== void 0 ? _t : true,
workflowSteps: (_v = (_u = this.config.exportFilter) === null || _u === void 0 ? void 0 : _u.includes('workflowStep')) !== null && _v !== void 0 ? _v : true,
};
return [4 /*yield*/, this.exportContentTypesAsync({ processItem: exportItems.contentType })];
case 1:
contentTypes = _3.sent();
contentTypes = _6.sent();
return [4 /*yield*/, this.exportProjectValidationAsync()];
case 2:
projectValidation = _3.sent();
projectValidation = _6.sent();
if (!(exportItems.contentItem || exportItems.languageVariant)) return [3 /*break*/, 4];
return [4 /*yield*/, this.exportContentItemsAsync()];
case 3:
_u = _3.sent();
_w = _6.sent();
return [3 /*break*/, 5];
case 4:
_u = [];
_3.label = 5;
_w = [];
_6.label = 5;
case 5:
contentItems = _u;
_2 = {
contentItems = _w;
_5 = {
contentTypes: exportItems.contentType ? contentTypes : []

@@ -94,70 +95,80 @@ };

case 6:
_v = _3.sent();
_x = _6.sent();
return [3 /*break*/, 8];
case 7:
_v = [];
_3.label = 8;
_x = [];
_6.label = 8;
case 8:
_2.contentTypeSnippets = _v;
_5.contentTypeSnippets = _x;
if (!exportItems.taxonomy) return [3 /*break*/, 10];
return [4 /*yield*/, this.exportTaxonomiesAsync()];
case 9:
_w = _3.sent();
_y = _6.sent();
return [3 /*break*/, 11];
case 10:
_w = [];
_3.label = 11;
_y = [];
_6.label = 11;
case 11:
_2.taxonomies = _w;
if (!exportItems.contentItem) return [3 /*break*/, 13];
return [4 /*yield*/, this.exportContentItemsAsync()];
_5.taxonomies = _y;
if (!exportItems.taxonomy) return [3 /*break*/, 13];
return [4 /*yield*/, this.exportWorkflowStepsAsync()];
case 12:
_x = _3.sent();
_z = _6.sent();
return [3 /*break*/, 14];
case 13:
_x = [];
_3.label = 14;
_z = [];
_6.label = 14;
case 14:
_2.contentItems = _x;
if (!exportItems.languageVariant) return [3 /*break*/, 16];
return [4 /*yield*/, this.exportLanguageVariantsAsync(contentItems.map(function (m) { return m.id; }))];
_5.workflowSteps = _z;
if (!exportItems.contentItem) return [3 /*break*/, 16];
return [4 /*yield*/, this.exportContentItemsAsync()];
case 15:
_y = _3.sent();
_0 = _6.sent();
return [3 /*break*/, 17];
case 16:
_y = [];
_3.label = 17;
_0 = [];
_6.label = 17;
case 17:
_2.languageVariants = _y;
if (!exportItems.asset) return [3 /*break*/, 19];
return [4 /*yield*/, this.exportAssetsAsync()];
_5.contentItems = _0;
if (!exportItems.languageVariant) return [3 /*break*/, 19];
return [4 /*yield*/, this.exportLanguageVariantsAsync(contentItems.map(function (m) { return m.id; }))];
case 18:
_z = _3.sent();
_1 = _6.sent();
return [3 /*break*/, 20];
case 19:
_z = [];
_3.label = 20;
_1 = [];
_6.label = 20;
case 20:
_2.assets = _z;
if (!exportItems.language) return [3 /*break*/, 22];
return [4 /*yield*/, this.exportLanguagesAsync()];
_5.languageVariants = _1;
if (!exportItems.asset) return [3 /*break*/, 22];
return [4 /*yield*/, this.exportAssetsAsync()];
case 21:
_0 = _3.sent();
_2 = _6.sent();
return [3 /*break*/, 23];
case 22:
_0 = [];
_3.label = 23;
_2 = [];
_6.label = 23;
case 23:
_2.languages = _0;
if (!exportItems.assetFolder) return [3 /*break*/, 25];
return [4 /*yield*/, this.exportAssetFoldersAsync()];
_5.assets = _2;
if (!exportItems.language) return [3 /*break*/, 25];
return [4 /*yield*/, this.exportLanguagesAsync()];
case 24:
_1 = _3.sent();
_3 = _6.sent();
return [3 /*break*/, 26];
case 25:
_1 = [];
_3.label = 26;
_3 = [];
_6.label = 26;
case 26:
data = (_2.assetFolders = _1,
_2);
_5.languages = _3;
if (!exportItems.assetFolder) return [3 /*break*/, 28];
return [4 /*yield*/, this.exportAssetFoldersAsync()];
case 27:
_4 = _6.sent();
return [3 /*break*/, 29];
case 28:
_4 = [];
_6.label = 29;
case 29:
data = (_5.assetFolders = _4,
_5);
return [2 /*return*/, {

@@ -177,3 +188,4 @@ metadata: {

languagesCount: data.languages.length,
taxonomiesCount: data.taxonomies.length
taxonomiesCount: data.taxonomies.length,
workflowStepsCount: data.workflowSteps.length,
}

@@ -258,2 +270,17 @@ },

};
ExportService.prototype.exportWorkflowStepsAsync = function () {
return __awaiter(this, void 0, void 0, function () {
var response;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client.listWorkflowSteps().toPromise()];
case 1:
response = _a.sent();
response.data.forEach(function (m) { return _this.processItem(m.name, 'workflowStep', m); });
return [2 /*return*/, response.data.map(function (m) { return m._raw; })];
}
});
});
};
ExportService.prototype.exportTaxonomiesAsync = function () {

@@ -260,0 +287,0 @@ return __awaiter(this, void 0, void 0, function () {

@@ -1,5 +0,6 @@

import { AssetContracts, AssetFolderContracts, ContentItemContracts, ContentTypeContracts, ContentTypeSnippetContracts, LanguageContracts, LanguageVariantContracts, TaxonomyContracts, ProjectContracts } from '@kentico/kontent-management';
import { AssetContracts, AssetFolderContracts, ContentItemContracts, ContentTypeContracts, ContentTypeSnippetContracts, LanguageContracts, LanguageVariantContracts, TaxonomyContracts, ProjectContracts, WorkflowContracts } from '@kentico/kontent-management';
import { IProcessedItem, ItemType, IPackageMetadata } from '../core';
export interface IImportConfig {
workflowIdForImportedItems?: string;
enablePublish: boolean;
baseUrl?: string;

@@ -48,2 +49,3 @@ projectId: string;

assets: AssetContracts.IAssetModelContract[];
workflowSteps: WorkflowContracts.IWorkflowStepContract[];
};

@@ -50,0 +52,0 @@ metadata: IPackageMetadata;

@@ -8,2 +8,3 @@ import { IImportItemResult, ValidImportContract, ValidImportModel } from '../core';

private readonly client;
private readonly publishedWorkflowStepName;
/**

@@ -26,2 +27,4 @@ * Maximum allowed size of asset in Bytes.

private importContentItemAsync;
private publishLanguageVariantsAsync;
private moveLanguageVariantsToCustomWorkflowStepAsync;
private importLanguageVariantsAsync;

@@ -37,2 +40,3 @@ private importContentTypeSnippetsAsync;

private mapAssetFolder;
private getPublishedWorkflowStep;
}

@@ -48,2 +48,3 @@ "use strict";

this.defaultWorkflowId = '00000000-0000-0000-0000-000000000000';
this.publishedWorkflowStepName = 'Published';
/**

@@ -187,3 +188,3 @@ * Maximum allowed size of asset in Bytes.

case 21:
if (!sourceData.importData.languageVariants) return [3 /*break*/, 23];
if (!sourceData.importData.languageVariants) return [3 /*break*/, 27];
return [4 /*yield*/, this.importLanguageVariantsAsync(sourceData.importData.languageVariants, importedItems)];

@@ -193,9 +194,20 @@ case 22:

importedItems.push.apply(importedItems, importedLanguageVariants);
return [3 /*break*/, 24];
if (!this.config.enablePublish) return [3 /*break*/, 24];
return [4 /*yield*/, this.publishLanguageVariantsAsync(sourceData.importData.languageVariants, sourceData.importData.workflowSteps)];
case 23:
_a.sent();
_a.label = 24;
case 24:
if (!this.config.workflowIdForImportedItems) return [3 /*break*/, 26];
return [4 /*yield*/, this.moveLanguageVariantsToCustomWorkflowStepAsync(this.config.workflowIdForImportedItems, sourceData.importData.languageVariants)];
case 25:
_a.sent();
_a.label = 26;
case 26: return [3 /*break*/, 28];
case 27:
if (this.config.enableLog) {
console.log("Skipping language variants");
}
_a.label = 24;
case 24:
_a.label = 28;
case 28:
if (this.config.enableLog) {

@@ -219,2 +231,3 @@ console.log("Finished importing data");

core_1.translationHelper.replaceIdReferencesWithCodenames(source.importData.languageVariants, source.importData, {});
core_1.translationHelper.replaceIdReferencesWithCodenames(source.importData.workflowSteps, source.importData, {});
};

@@ -717,13 +730,130 @@ ImportService.prototype.removeSkippedItemsFromImport = function (source) {

};
ImportService.prototype.publishLanguageVariantsAsync = function (languageVariants, workflowSteps) {
return __awaiter(this, void 0, void 0, function () {
var publishedWorkflowStep, itemsToPublish, _loop_13, this_13, _i, itemsToPublish_1, itemToPublish;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
publishedWorkflowStep = this.getPublishedWorkflowStep(workflowSteps);
if (!publishedWorkflowStep) {
// published workflow step was not found
return [2 /*return*/];
}
itemsToPublish = languageVariants.filter(function (m) { return m.workflow_step.id === publishedWorkflowStep.id; });
if (!itemsToPublish.length) {
// no items to publish
return [2 /*return*/];
}
_loop_13 = function (itemToPublish) {
var itemCodename, languageCodename;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
itemCodename = itemToPublish.item.codename;
languageCodename = itemToPublish.language.codename;
if (!itemCodename) {
throw Error("Missing item codename for item");
}
if (!languageCodename) {
throw Error("Missing language codename for item");
}
return [4 /*yield*/, this_13.client
.publishLanguageVariant()
.byItemCodename(itemCodename)
.byLanguageCodename(languageCodename)
.withoutData()
.toPromise()
.then(function (response) {
_this.processItem(itemCodename + " (" + languageCodename + ")", 'publish', response.data);
})
.catch(function (error) { return _this.handleImportError(error); })];
case 1:
_a.sent();
return [2 /*return*/];
}
});
};
this_13 = this;
_i = 0, itemsToPublish_1 = itemsToPublish;
_a.label = 1;
case 1:
if (!(_i < itemsToPublish_1.length)) return [3 /*break*/, 4];
itemToPublish = itemsToPublish_1[_i];
return [5 /*yield**/, _loop_13(itemToPublish)];
case 2:
_a.sent();
_a.label = 3;
case 3:
_i++;
return [3 /*break*/, 1];
case 4: return [2 /*return*/];
}
});
});
};
ImportService.prototype.moveLanguageVariantsToCustomWorkflowStepAsync = function (workflowStepId, languageVariants) {
return __awaiter(this, void 0, void 0, function () {
var _loop_14, this_14, _i, languageVariants_1, item;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_loop_14 = function (item) {
var itemCodename, languageCodename;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
itemCodename = item.item.codename;
languageCodename = item.language.codename;
if (!itemCodename) {
throw Error("Missing item codename for item");
}
if (!languageCodename) {
throw Error("Missing language codename for item");
}
return [4 /*yield*/, this_14.client
.changeWorkflowStepOfLanguageVariant()
.byItemCodename(itemCodename)
.byLanguageCodename(languageCodename)
.byWorkflowStepId(workflowStepId)
.toPromise()
.then(function (response) {
_this.processItem(itemCodename + " (" + languageCodename + ")", 'changeWorkflowStep', response.data);
})
.catch(function (error) { return _this.handleImportError(error); })];
case 1:
_a.sent();
return [2 /*return*/];
}
});
};
this_14 = this;
_i = 0, languageVariants_1 = languageVariants;
_a.label = 1;
case 1:
if (!(_i < languageVariants_1.length)) return [3 /*break*/, 4];
item = languageVariants_1[_i];
return [5 /*yield**/, _loop_14(item)];
case 2:
_a.sent();
_a.label = 3;
case 3:
_i++;
return [3 /*break*/, 1];
case 4: return [2 /*return*/];
}
});
});
};
ImportService.prototype.importLanguageVariantsAsync = function (languageVariants, currentItems) {
var _a;
return __awaiter(this, void 0, void 0, function () {
var importedItems, _loop_13, this_13, _i, languageVariants_1, languageVariant;
var importedItems, _loop_15, this_15, _i, languageVariants_2, languageVariant;
var _this = this;
return __generator(this, function (_b) {
switch (_b.label) {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
importedItems = [];
_loop_13 = function (languageVariant) {
var itemCodename, languageCodename, newWorkflowId;
_loop_15 = function (languageVariant) {
var itemCodename, languageCodename;
return __generator(this, function (_a) {

@@ -742,5 +872,3 @@ switch (_a.label) {

core_1.idTranslateHelper.replaceIdReferencesWithNewId(languageVariant, currentItems);
newWorkflowId = (_a = this_13.config.workflowIdForImportedItems) !== null && _a !== void 0 ? _a : this_13.defaultWorkflowId;
languageVariant.workflow_step.id = newWorkflowId;
return [4 /*yield*/, this_13.client
return [4 /*yield*/, this_15.client
.upsertLanguageVariant()

@@ -767,12 +895,12 @@ .byItemCodename(itemCodename)

};
this_13 = this;
_i = 0, languageVariants_1 = languageVariants;
_b.label = 1;
this_15 = this;
_i = 0, languageVariants_2 = languageVariants;
_a.label = 1;
case 1:
if (!(_i < languageVariants_1.length)) return [3 /*break*/, 4];
languageVariant = languageVariants_1[_i];
return [5 /*yield**/, _loop_13(languageVariant)];
if (!(_i < languageVariants_2.length)) return [3 /*break*/, 4];
languageVariant = languageVariants_2[_i];
return [5 /*yield**/, _loop_15(languageVariant)];
case 2:
_b.sent();
_b.label = 3;
_a.sent();
_a.label = 3;
case 3:

@@ -788,3 +916,3 @@ _i++;

return __awaiter(this, void 0, void 0, function () {
var importedItems, _loop_14, this_14, _i, contentTypeSnippets_1, contentTypeSnippet;
var importedItems, _loop_16, this_16, _i, contentTypeSnippets_1, contentTypeSnippet;
var _this = this;

@@ -795,6 +923,6 @@ return __generator(this, function (_a) {

importedItems = [];
_loop_14 = function (contentTypeSnippet) {
_loop_16 = function (contentTypeSnippet) {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this_14.client
case 0: return [4 /*yield*/, this_16.client
.addContentTypeSnippet()

@@ -826,3 +954,3 @@ .withData(function (builder) {

};
this_14 = this;
this_16 = this;
_i = 0, contentTypeSnippets_1 = contentTypeSnippets;

@@ -833,3 +961,3 @@ _a.label = 1;

contentTypeSnippet = contentTypeSnippets_1[_i];
return [5 /*yield**/, _loop_14(contentTypeSnippet)];
return [5 /*yield**/, _loop_16(contentTypeSnippet)];
case 2:

@@ -848,3 +976,3 @@ _a.sent();

return __awaiter(this, void 0, void 0, function () {
var importedItems, _loop_15, this_15, _i, taxonomies_1, taxonomy;
var importedItems, _loop_17, this_17, _i, taxonomies_1, taxonomy;
var _this = this;

@@ -855,6 +983,6 @@ return __generator(this, function (_a) {

importedItems = [];
_loop_15 = function (taxonomy) {
_loop_17 = function (taxonomy) {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this_15.client
case 0: return [4 /*yield*/, this_17.client
.addTaxonomy()

@@ -879,3 +1007,3 @@ .withData(taxonomy)

};
this_15 = this;
this_17 = this;
_i = 0, taxonomies_1 = taxonomies;

@@ -886,3 +1014,3 @@ _a.label = 1;

taxonomy = taxonomies_1[_i];
return [5 /*yield**/, _loop_15(taxonomy)];
return [5 /*yield**/, _loop_17(taxonomy)];
case 2:

@@ -938,3 +1066,3 @@ _a.sent();

ImportService.prototype.flattenAssetFolders = function (importedAssetFolders, originalItems, items) {
var _loop_16 = function (assetFolder) {
var _loop_18 = function (assetFolder) {
var originalFolder = originalItems.find(function (m) { return m.external_id === assetFolder.externalId; });

@@ -951,9 +1079,9 @@ if (!originalFolder) {

if (assetFolder.folders.length) {
this_16.flattenAssetFolders(assetFolder.folders, originalItems, items);
this_18.flattenAssetFolders(assetFolder.folders, originalItems, items);
}
};
var this_16 = this;
var this_18 = this;
for (var _i = 0, importedAssetFolders_1 = importedAssetFolders; _i < importedAssetFolders_1.length; _i++) {
var assetFolder = importedAssetFolders_1[_i];
_loop_16(assetFolder);
_loop_18(assetFolder);
}

@@ -979,2 +1107,6 @@ };

};
ImportService.prototype.getPublishedWorkflowStep = function (workflowSteps) {
var _this = this;
return workflowSteps.find(function (m) { return m.name === _this.publishedWorkflowStepName; });
};
return ImportService;

@@ -981,0 +1113,0 @@ }());

@@ -144,2 +144,3 @@ #!/usr/bin/env node

},
enablePublish: config.enablePublish,
baseUrl: config.baseUrl,

@@ -245,6 +246,6 @@ fixLanguages: true,

var getConfig = function () { return __awaiter(void 0, void 0, void 0, function () {
var configFilename, configFile, action, apiKey, enableLog, force, projectId, baseUrl, zipFilename, exportFilter, exportFilterMapped, config;
var _a, _b, _c;
return __generator(this, function (_d) {
switch (_d.label) {
var configFilename, configFile, action, apiKey, enableLog, force, enablePublish, projectId, baseUrl, zipFilename, exportFilter, exportFilterMapped, config;
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:

@@ -255,3 +256,3 @@ configFilename = argv.config;

case 1:
configFile = _d.sent();
configFile = _e.sent();
return [2 /*return*/, JSON.parse(configFile.toString())];

@@ -263,5 +264,6 @@ case 2:

force = (_b = argv.force) !== null && _b !== void 0 ? _b : true;
enablePublish = (_c = argv.enablePublish) !== null && _c !== void 0 ? _c : true;
projectId = argv.projectId;
baseUrl = argv.baseUrl;
zipFilename = (_c = argv.zipFilename) !== null && _c !== void 0 ? _c : getDefaultBackupFilename();
zipFilename = (_d = argv.zipFilename) !== null && _d !== void 0 ? _d : getDefaultBackupFilename();
exportFilter = argv.exportFilter;

@@ -281,2 +283,3 @@ exportFilterMapped = exportFilter ? exportFilter.split(',').map(function (m) { return m.trim(); }).map(function (m) {

config = {
enablePublish: enablePublish,
action: action,

@@ -283,0 +286,0 @@ apiKey: apiKey,

@@ -59,2 +59,3 @@ "use strict";

},
enablePublish: true,
projectId: 'targetProjectId',

@@ -61,0 +62,0 @@ apiKey: 'targetProjectId',

@@ -17,2 +17,3 @@ import { IExportAllResult } from '../export';

private readonly assetFoldersName;
private readonly workflowStepsName;
private readonly validationName;

@@ -19,0 +20,0 @@ constructor(config: IZipServiceConfig);

@@ -56,2 +56,3 @@ "use strict";

this.assetFoldersName = 'assetFolders.json';
this.workflowStepsName = 'workflowSteps.json';
this.validationName = 'validation.json';

@@ -100,15 +101,18 @@ this.delayBetweenAssetRequestsMs = (_a = config === null || config === void 0 ? void 0 : config.delayBetweenAssetDownloadRequestsMs) !== null && _a !== void 0 ? _a : 150;

case 8:
_a.importData = (_b.taxonomies = _c.sent(),
_b.taxonomies = _c.sent();
return [4 /*yield*/, this.readAndParseJsonFile(unzippedFile, this.workflowStepsName)];
case 9:
_a.importData = (_b.workflowSteps = _c.sent(),
_b);
return [4 /*yield*/, this.readAndParseJsonFile(unzippedFile, this.assetFoldersName)];
case 9:
case 10:
_a.assetFolders = _c.sent();
return [4 /*yield*/, this.extractBinaryFilesAsync(unzippedFile, assets)];
case 10:
case 11:
_a.binaryFiles = _c.sent();
return [4 /*yield*/, this.readAndParseJsonFile(unzippedFile, this.validationName)];
case 11:
case 12:
_a.validation = _c.sent();
return [4 /*yield*/, this.readAndParseJsonFile(unzippedFile, this.metadataName)];
case 12:
case 13:
result = (_a.metadata = _c.sent(),

@@ -144,2 +148,3 @@ _a);

zip.file(this.assetFoldersName, JSON.stringify(exportData.data.assetFolders));
zip.file(this.workflowStepsName, JSON.stringify(exportData.data.workflowSteps));
assetsFolder = zip.folder(this.filesName);

@@ -146,0 +151,0 @@ if (!assetsFolder) {

@@ -5,2 +5,11 @@ # Changelog

## [1.15.0](https://github.com/Kentico/kontent-backup-manager-js/compare/v1.14.0...v1.15.0) (2021-02-24)
### Features
* adds support for exporting workflow steps ([f2878a2](https://github.com/Kentico/kontent-backup-manager-js/commit/f2878a20ff6b76cf047831be356cc7f0e07146f7))
* adds support for preserving publish & fixes custom workflow step assignment ([ac1e8a0](https://github.com/Kentico/kontent-backup-manager-js/commit/ac1e8a068050fe98543c312a36430abbc7b9a395))
* updates deps ([b8aff5a](https://github.com/Kentico/kontent-backup-manager-js/commit/b8aff5ae86702ce2878cb0eb11de32b9bb38fd5b))
## [1.14.0](https://github.com/Kentico/kontent-backup-manager-js/compare/v1.13.0...v1.14.0) (2021-01-08)

@@ -7,0 +16,0 @@

{
"name": "@kentico/kontent-backup-manager",
"version": "1.14.0",
"version": "1.15.0",
"description": "This utility enables backup & restore of Kentico Kontent projects",

@@ -17,2 +17,3 @@ "preferGlobal": true,

"scripts": {
"test": "echo \"no global test configured\"",
"release": "standard-version",

@@ -46,16 +47,16 @@ "tsc-local": "./node_modules/.bin/tsc",

"@kentico/kontent-management": "0.4.8",
"jszip": "3.5.0",
"jszip": "3.6.0",
"rxjs": "6.6.3",
"yargs": "16.2.0",
"flatted": "3.1.0"
"flatted": "3.1.1"
},
"devDependencies": {
"@types/jszip": "3.4.1",
"@types/node": "14.14.20",
"@types/yargs": "15.0.12",
"standard-version": "9.1.0",
"@types/node": "14.14.31",
"@types/yargs": "16.0.0",
"standard-version": "9.1.1",
"ts-node": "9.1.1",
"tslint": "6.1.3",
"typescript": "4.1.3"
"typescript": "4.1.5"
}
}

@@ -39,2 +39,3 @@ [![npm version](https://badge.fury.io/js/%40kentico%2Fkontent-backup-manager.svg)](https://badge.fury.io/js/%40kentico%2Fkontent-backup-manager)

* binaryFile
* workflowSteps (only export)

@@ -41,0 +42,0 @@ ### Execution

@@ -26,2 +26,3 @@ import {

enableLog: boolean;
enablePublish: boolean;
force: boolean;

@@ -42,4 +43,7 @@ baseUrl?: string;

| 'assetFolder'
| 'workflowStep'
| 'binaryFile';
export type ActionType = ItemType | 'publish' | 'changeWorkflowStep';
export type ValidImportModel =

@@ -68,3 +72,3 @@ | ContentTypeModels.ContentType

title: string;
type: ItemType;
type: ActionType;
data: any;

@@ -102,3 +106,4 @@ }

assetFoldersCount: number;
workflowStepsCount: number;
}

@@ -11,2 +11,3 @@ import {

ProjectContracts,
WorkflowContracts,
} from '@kentico/kontent-management';

@@ -25,2 +26,3 @@

export interface IExportData {
workflowSteps: WorkflowContracts.IWorkflowStepContract[];
taxonomies: TaxonomyContracts.ITaxonomyContract[];

@@ -27,0 +29,0 @@ contentTypeSnippets: ContentTypeSnippetContracts.IContentTypeSnippetContract[];

@@ -12,3 +12,4 @@ import {

AssetFolderContracts,
ProjectContracts
ProjectContracts,
WorkflowContracts
} from '@kentico/kontent-management';

@@ -41,3 +42,4 @@

languageVariant: this.config.exportFilter?.includes('languageVariant') ?? true,
taxonomy: this.config.exportFilter?.includes('taxonomy') ?? true
taxonomy: this.config.exportFilter?.includes('taxonomy') ?? true,
workflowSteps: this.config.exportFilter?.includes('workflowStep') ?? true,
};

@@ -53,2 +55,3 @@

taxonomies: exportItems.taxonomy ? await this.exportTaxonomiesAsync() : [],
workflowSteps: exportItems.taxonomy ? await this.exportWorkflowStepsAsync() : [],
contentItems: exportItems.contentItem ? await this.exportContentItemsAsync() : [],

@@ -78,3 +81,4 @@ languageVariants: exportItems.languageVariant

languagesCount: data.languages.length,
taxonomiesCount: data.taxonomies.length
taxonomiesCount: data.taxonomies.length,
workflowStepsCount: data.workflowSteps.length,
}

@@ -122,2 +126,8 @@ },

public async exportWorkflowStepsAsync(): Promise<WorkflowContracts.IWorkflowStepContract[]> {
const response = await this.client.listWorkflowSteps().toPromise();
response.data.forEach((m) => this.processItem(m.name, 'workflowStep', m));
return response.data.map((m) => m._raw);
}
public async exportTaxonomiesAsync(): Promise<TaxonomyContracts.ITaxonomyContract[]> {

@@ -124,0 +134,0 @@ const response = await this.client.listTaxonomies().toPromise();

@@ -11,2 +11,3 @@ import {

ProjectContracts,
WorkflowContracts,
} from '@kentico/kontent-management';

@@ -18,2 +19,3 @@

workflowIdForImportedItems?: string;
enablePublish: boolean
baseUrl?: string;

@@ -68,2 +70,3 @@ projectId: string;

assets: AssetContracts.IAssetModelContract[];
workflowSteps: WorkflowContracts.IWorkflowStepContract[];
};

@@ -70,0 +73,0 @@ metadata: IPackageMetadata;

@@ -20,3 +20,4 @@ import { HttpService } from '@kentico/kontent-core';

TaxonomyContracts,
TaxonomyModels
TaxonomyModels,
WorkflowContracts
} from '@kentico/kontent-management';

@@ -27,3 +28,3 @@

IImportItemResult,
ItemType,
ActionType,
translationHelper,

@@ -39,2 +40,3 @@ ValidImportContract,

private readonly client: IManagementClient;
private readonly publishedWorkflowStepName: string = 'Published';

@@ -178,2 +180,10 @@ /**

importedItems.push(...importedLanguageVariants);
if (this.config.enablePublish) {
await this.publishLanguageVariantsAsync(sourceData.importData.languageVariants, sourceData.importData.workflowSteps);
}
if (this.config.workflowIdForImportedItems) {
await this.moveLanguageVariantsToCustomWorkflowStepAsync(this.config.workflowIdForImportedItems, sourceData.importData.languageVariants);
}
} else {

@@ -203,2 +213,3 @@ if (this.config.enableLog) {

translationHelper.replaceIdReferencesWithCodenames(source.importData.languageVariants, source.importData, {});
translationHelper.replaceIdReferencesWithCodenames(source.importData.workflowSteps, source.importData, {});
}

@@ -615,2 +626,71 @@

private async publishLanguageVariantsAsync(
languageVariants: LanguageVariantContracts.ILanguageVariantModelContract[],
workflowSteps: WorkflowContracts.IWorkflowStepContract[]
): Promise<void> {
const publishedWorkflowStep = this.getPublishedWorkflowStep(workflowSteps);
if (!publishedWorkflowStep) {
// published workflow step was not found
return;
}
const itemsToPublish = languageVariants.filter(m => m.workflow_step.id === publishedWorkflowStep.id);
if (!itemsToPublish.length) {
// no items to publish
return;
}
for (const itemToPublish of itemsToPublish) {
const itemCodename: string | undefined = itemToPublish.item.codename;
const languageCodename: string | undefined = itemToPublish.language.codename;
if (!itemCodename) {
throw Error(`Missing item codename for item`);
}
if (!languageCodename) {
throw Error(`Missing language codename for item`);
}
await this.client
.publishLanguageVariant()
.byItemCodename(itemCodename)
.byLanguageCodename(languageCodename)
.withoutData()
.toPromise()
.then((response) => {
this.processItem(`${itemCodename} (${languageCodename})`, 'publish', response.data);
})
.catch((error) => this.handleImportError(error));
}
}
private async moveLanguageVariantsToCustomWorkflowStepAsync(workflowStepId: string,
languageVariants: LanguageVariantContracts.ILanguageVariantModelContract[]
): Promise<void> {
for (const item of languageVariants) {
const itemCodename: string | undefined = item.item.codename;
const languageCodename: string | undefined = item.language.codename;
if (!itemCodename) {
throw Error(`Missing item codename for item`);
}
if (!languageCodename) {
throw Error(`Missing language codename for item`);
}
await this.client
.changeWorkflowStepOfLanguageVariant()
.byItemCodename(itemCodename)
.byLanguageCodename(languageCodename)
.byWorkflowStepId(workflowStepId)
.toPromise()
.then((response) => {
this.processItem(`${itemCodename} (${languageCodename})`, 'changeWorkflowStep', response.data);
})
.catch((error) => this.handleImportError(error));
}
}
private async importLanguageVariantsAsync(

@@ -644,6 +724,2 @@ languageVariants: LanguageVariantContracts.ILanguageVariantModelContract[],

// set workflow id (there is no API to create workflows programatically)
const newWorkflowId: string = this.config.workflowIdForImportedItems ?? this.defaultWorkflowId;
languageVariant.workflow_step.id = newWorkflowId;
await this.client

@@ -734,3 +810,3 @@ .upsertLanguageVariant()

private processItem(title: string, type: ItemType, data: any): void {
private processItem(title: string, type: ActionType, data: any): void {
if (!this.config.onImport) {

@@ -828,2 +904,6 @@ return;

}
private getPublishedWorkflowStep(workflowSteps: WorkflowContracts.IWorkflowStepContract[]): WorkflowContracts.IWorkflowStepContract | undefined {
return workflowSteps.find(m => m.name === this.publishedWorkflowStepName);
}
}

@@ -94,2 +94,3 @@ #!/usr/bin/env node

},
enablePublish: config.enablePublish,
baseUrl: config.baseUrl,

@@ -199,2 +200,3 @@ fixLanguages: true,

const force: boolean | undefined = (argv.force as boolean | undefined) ?? true;
const enablePublish: boolean | undefined = (argv.enablePublish as boolean | undefined) ?? true;
const projectId: string | undefined = argv.projectId as string | undefined;

@@ -223,2 +225,3 @@ const baseUrl: string | undefined = argv.baseUrl as string | undefined;

const config: ICliFileConfig = {
enablePublish,
action,

@@ -225,0 +228,0 @@ apiKey,

@@ -20,2 +20,3 @@ import { ImportService } from 'src';

},
enablePublish: true,
projectId: 'targetProjectId',

@@ -22,0 +23,0 @@ apiKey: 'targetProjectId',

@@ -23,2 +23,3 @@ import { AssetContracts } from '@kentico/kontent-management';

private readonly assetFoldersName: string = 'assetFolders.json';
private readonly workflowStepsName: string = 'workflowSteps.json';
private readonly validationName: string = 'validation.json';

@@ -41,3 +42,3 @@

const assets = await this.readAndParseJsonFile(unzippedFile, this.assetsName);
const result = {
const result: IImportSource = {
importData: {

@@ -51,2 +52,3 @@ assets,

taxonomies: await this.readAndParseJsonFile(unzippedFile, this.taxonomiesName),
workflowSteps: await this.readAndParseJsonFile(unzippedFile, this.workflowStepsName),
},

@@ -83,2 +85,3 @@ assetFolders: await this.readAndParseJsonFile(unzippedFile, this.assetFoldersName),

zip.file(this.assetFoldersName, JSON.stringify(exportData.data.assetFolders));
zip.file(this.workflowStepsName, JSON.stringify(exportData.data.workflowSteps));

@@ -85,0 +88,0 @@ const assetsFolder = zip.folder(this.filesName);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc