@kontent-ai/migration-toolkit 1.4.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -4
- package/dist/es2022/core/helpers/workflow-helper.d.ts +1 -0
- package/dist/es2022/core/helpers/workflow-helper.js +6 -4
- package/dist/es2022/core/helpers/workflow-helper.js.map +1 -1
- package/dist/es2022/core/logs/loggers.js +13 -22
- package/dist/es2022/core/logs/loggers.js.map +1 -1
- package/dist/es2022/core/models/core.models.d.ts +16 -6
- package/dist/es2022/core/models/migration.schema.d.ts +247 -0
- package/dist/es2022/core/models/migration.schema.js +12 -2
- package/dist/es2022/core/models/migration.schema.js.map +1 -1
- package/dist/es2022/core/utils/array.utils.js.map +1 -1
- package/dist/es2022/core/utils/binary-data.utils.js +2 -6
- package/dist/es2022/core/utils/binary-data.utils.js.map +1 -1
- package/dist/es2022/core/utils/confirm.utils.js +10 -14
- package/dist/es2022/core/utils/confirm.utils.js.map +1 -1
- package/dist/es2022/core/utils/error.utils.js +35 -27
- package/dist/es2022/core/utils/error.utils.js.map +1 -1
- package/dist/es2022/core/utils/http.utils.js +7 -11
- package/dist/es2022/core/utils/http.utils.js.map +1 -1
- package/dist/es2022/core/utils/management-client-utils.d.ts +2 -1
- package/dist/es2022/core/utils/management-client-utils.js +11 -1
- package/dist/es2022/core/utils/management-client-utils.js.map +1 -1
- package/dist/es2022/core/utils/run.utils.js +12 -10
- package/dist/es2022/core/utils/run.utils.js.map +1 -1
- package/dist/es2022/export/context/export-context-fetcher.js +2 -1
- package/dist/es2022/export/context/export-context-fetcher.js.map +1 -1
- package/dist/es2022/export/export-manager.js +8 -0
- package/dist/es2022/export/export-manager.js.map +1 -1
- package/dist/es2022/export/export.models.d.ts +2 -1
- package/dist/es2022/import/comparers/asset-comparer.d.ts +2 -1
- package/dist/es2022/import/comparers/asset-comparer.js +9 -17
- package/dist/es2022/import/comparers/asset-comparer.js.map +1 -1
- package/dist/es2022/import/context/import-context-fetcher.js +120 -40
- package/dist/es2022/import/context/import-context-fetcher.js.map +1 -1
- package/dist/es2022/import/import.models.d.ts +2 -1
- package/dist/es2022/import/importers/assets-importer.js +25 -7
- package/dist/es2022/import/importers/assets-importer.js.map +1 -1
- package/dist/es2022/import/importers/language-variant-importer.js +95 -87
- package/dist/es2022/import/importers/language-variant-importer.js.map +1 -1
- package/dist/es2022/import/importers/workflow-importer.d.ts +41 -4
- package/dist/es2022/import/importers/workflow-importer.js +158 -17
- package/dist/es2022/import/importers/workflow-importer.js.map +1 -1
- package/dist/es2022/metadata.js +2 -2
- package/dist/es2022/node/cli/app.js +8 -12
- package/dist/es2022/node/cli/app.js.map +1 -1
- package/dist/es2022/node/cli/args/args-fetcher.js +9 -10
- package/dist/es2022/node/cli/args/args-fetcher.js.map +1 -1
- package/dist/es2022/toolkit/migrate.d.ts +1 -3
- package/dist/es2022/toolkit/migrate.js.map +1 -1
- package/dist/es2022/translation/extraction/items-extraction.processor.js +17 -17
- package/dist/es2022/translation/extraction/items-extraction.processor.js.map +1 -1
- package/dist/es2022/zip/zip-packager.js +13 -18
- package/dist/es2022/zip/zip-packager.js.map +1 -1
- package/dist/es2022/zip/zip-transformer.js +3 -1
- package/dist/es2022/zip/zip-transformer.js.map +1 -1
- package/lib/core/helpers/workflow-helper.ts +8 -8
- package/lib/core/logs/loggers.ts +14 -22
- package/lib/core/models/core.models.ts +23 -4
- package/lib/core/models/migration.schema.ts +13 -2
- package/lib/core/utils/array.utils.ts +2 -10
- package/lib/core/utils/binary-data.utils.ts +2 -7
- package/lib/core/utils/confirm.utils.ts +18 -24
- package/lib/core/utils/error.utils.ts +50 -30
- package/lib/core/utils/http.utils.ts +14 -15
- package/lib/core/utils/management-client-utils.ts +188 -176
- package/lib/core/utils/run.utils.ts +27 -18
- package/lib/export/context/export-context-fetcher.ts +2 -1
- package/lib/export/export-manager.ts +14 -3
- package/lib/export/export.models.ts +3 -1
- package/lib/import/comparers/asset-comparer.ts +16 -24
- package/lib/import/context/import-context-fetcher.ts +179 -85
- package/lib/import/import.models.ts +2 -0
- package/lib/import/importers/assets-importer.ts +41 -25
- package/lib/import/importers/language-variant-importer.ts +119 -111
- package/lib/import/importers/workflow-importer.ts +228 -20
- package/lib/metadata.ts +2 -2
- package/lib/node/cli/app.ts +11 -12
- package/lib/node/cli/args/args-fetcher.ts +12 -14
- package/lib/toolkit/migrate.ts +1 -3
- package/lib/translation/extraction/items-extraction.processor.ts +93 -93
- package/lib/zip/zip-packager.ts +26 -28
- package/lib/zip/zip-transformer.ts +3 -1
- package/package.json +13 -12
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { match } from 'ts-pattern';
|
|
1
2
|
import { ContentItemModels, ElementContracts, LanguageVariantModels, ManagementClient, WorkflowModels } from '@kontent-ai/management-sdk';
|
|
2
3
|
import {
|
|
3
4
|
Logger,
|
|
@@ -8,12 +9,15 @@ import {
|
|
|
8
9
|
MigrationElement,
|
|
9
10
|
MigrationItemVersion,
|
|
10
11
|
workflowHelper,
|
|
11
|
-
findRequired
|
|
12
|
+
findRequired,
|
|
13
|
+
isNotUndefined,
|
|
14
|
+
LanguageVariantSchedulesStateValues,
|
|
15
|
+
LanguageVariantStateInTargetEnvironmentByCodename
|
|
12
16
|
} from '../../core/index.js';
|
|
13
17
|
import chalk from 'chalk';
|
|
14
18
|
import { ImportContext } from '../import.models.js';
|
|
15
19
|
import { importTransforms } from '../../translation/index.js';
|
|
16
|
-
import { workflowImporter } from './workflow-importer.js';
|
|
20
|
+
import { workflowImporter as workflowImporterInit } from './workflow-importer.js';
|
|
17
21
|
import { throwErrorForMigrationItem } from '../utils/import.utils.js';
|
|
18
22
|
|
|
19
23
|
export function languageVariantImporter(config: {
|
|
@@ -22,6 +26,12 @@ export function languageVariantImporter(config: {
|
|
|
22
26
|
readonly importContext: ImportContext;
|
|
23
27
|
readonly client: Readonly<ManagementClient>;
|
|
24
28
|
}) {
|
|
29
|
+
const workflowImporter = workflowImporterInit({
|
|
30
|
+
logger: config.logger,
|
|
31
|
+
managementClient: config.client,
|
|
32
|
+
workflows: config.importContext.environmentData.workflows
|
|
33
|
+
});
|
|
34
|
+
|
|
25
35
|
const upsertLanguageVariantAsync = async (data: {
|
|
26
36
|
readonly workflow: Readonly<WorkflowModels.Workflow>;
|
|
27
37
|
readonly logSpinner: LogSpinnerData;
|
|
@@ -86,7 +96,7 @@ export function languageVariantImporter(config: {
|
|
|
86
96
|
if (draftVersions.length > 1) {
|
|
87
97
|
throwErrorForMigrationItem(
|
|
88
98
|
migrationItem,
|
|
89
|
-
`There can be only 1 draft version. There are '${
|
|
99
|
+
`There can be only 1 draft version. There are '${draftVersions.length}' draft versions for the item.`
|
|
90
100
|
);
|
|
91
101
|
}
|
|
92
102
|
|
|
@@ -101,7 +111,7 @@ export function languageVariantImporter(config: {
|
|
|
101
111
|
readonly migrationItem: MigrationItem;
|
|
102
112
|
readonly migrationItemVersion: MigrationItemVersion;
|
|
103
113
|
readonly preparedContentItem: Readonly<ContentItemModels.ContentItem>;
|
|
104
|
-
readonly
|
|
114
|
+
readonly createNewVersion?: boolean;
|
|
105
115
|
}): Promise<Readonly<LanguageVariantModels.ContentItemLanguageVariant>> => {
|
|
106
116
|
// validate workflow
|
|
107
117
|
const { step, workflow } = workflowHelper(config.importContext.environmentData.workflows).getWorkflowAndStepByCodenames({
|
|
@@ -109,16 +119,13 @@ export function languageVariantImporter(config: {
|
|
|
109
119
|
stepCodename: data.migrationItemVersion.workflow_step.codename
|
|
110
120
|
});
|
|
111
121
|
|
|
112
|
-
//
|
|
113
|
-
if (data.
|
|
114
|
-
await
|
|
122
|
+
// create new version if necessary. This is needed when both draft & published version are imported
|
|
123
|
+
if (data.createNewVersion) {
|
|
124
|
+
await workflowImporter.createNewVersionOfLanguageVariantAsync({
|
|
115
125
|
logSpinner: data.logSpinner,
|
|
116
|
-
|
|
117
|
-
migrationItem: data.migrationItem,
|
|
118
|
-
workflow
|
|
126
|
+
migrationItem: data.migrationItem
|
|
119
127
|
});
|
|
120
128
|
}
|
|
121
|
-
|
|
122
129
|
// upsert language variant
|
|
123
130
|
const languageVariant = await upsertLanguageVariantAsync({
|
|
124
131
|
logSpinner: data.logSpinner,
|
|
@@ -129,15 +136,19 @@ export function languageVariantImporter(config: {
|
|
|
129
136
|
});
|
|
130
137
|
|
|
131
138
|
// set workflow accordingly (publish, move to workflow step, archive ...)
|
|
132
|
-
await workflowImporter({
|
|
133
|
-
logger: config.logger,
|
|
134
|
-
managementClient: config.client,
|
|
135
|
-
workflows: config.importContext.environmentData.workflows
|
|
136
|
-
}).setWorkflowOfLanguageVariantAsync({
|
|
139
|
+
await workflowImporter.setWorkflowOfLanguageVariantAsync({
|
|
137
140
|
logSpinner: data.logSpinner,
|
|
138
141
|
migrationItem: data.migrationItem,
|
|
139
142
|
workflowCodename: workflow.codename,
|
|
140
|
-
stepCodename: step.codename
|
|
143
|
+
stepCodename: step.codename,
|
|
144
|
+
migrationItemVersion: data.migrationItemVersion
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// set scheduling
|
|
148
|
+
await workflowImporter.setScheduledStateOfLanguageVariantAsync({
|
|
149
|
+
logSpinner: data.logSpinner,
|
|
150
|
+
migrationItem: data.migrationItem,
|
|
151
|
+
migrationItemVersion: data.migrationItemVersion
|
|
141
152
|
});
|
|
142
153
|
|
|
143
154
|
return languageVariant;
|
|
@@ -150,127 +161,124 @@ export function languageVariantImporter(config: {
|
|
|
150
161
|
): Promise<readonly LanguageVariantModels.ContentItemLanguageVariant[]> => {
|
|
151
162
|
const { draftVersion, publishedVersion } = categorizeVersions(migrationItem);
|
|
152
163
|
|
|
153
|
-
let publishedLanguageVariant: Readonly<LanguageVariantModels.ContentItemLanguageVariant> | undefined;
|
|
154
|
-
let draftLanguageVariant: Readonly<LanguageVariantModels.ContentItemLanguageVariant> | undefined;
|
|
155
|
-
let lastWorkflowStepCodenameInTargetEnvironment: string | undefined;
|
|
156
|
-
|
|
157
|
-
const workflow = workflowHelper(config.importContext.environmentData.workflows).getWorkflowByCodename(
|
|
158
|
-
migrationItem.system.workflow.codename
|
|
159
|
-
);
|
|
160
|
-
|
|
161
164
|
// get initial state of language variant from target env
|
|
162
|
-
const
|
|
165
|
+
const targetVariantState = config.importContext.getLanguageVariantStateInTargetEnvironment(
|
|
163
166
|
migrationItem.system.codename,
|
|
164
167
|
migrationItem.system.language.codename
|
|
165
168
|
);
|
|
166
169
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
170
|
+
// prepare language variant for import (unpublish, create new version, un-schedule ...)
|
|
171
|
+
await prepareTargetEnvironmentVariantForImportAsync({
|
|
172
|
+
logSpinner,
|
|
173
|
+
migrationItem,
|
|
174
|
+
targetVariantState
|
|
175
|
+
});
|
|
171
176
|
|
|
172
177
|
// first import published version if it exists
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
const publishedLanguageVariant: Readonly<LanguageVariantModels.ContentItemLanguageVariant> | undefined = publishedVersion
|
|
179
|
+
? await importVersionAsync({
|
|
180
|
+
logSpinner: logSpinner,
|
|
181
|
+
migrationItem: migrationItem,
|
|
182
|
+
preparedContentItem: preparedContentItem,
|
|
183
|
+
migrationItemVersion: publishedVersion
|
|
184
|
+
})
|
|
185
|
+
: undefined;
|
|
186
|
+
|
|
187
|
+
// if target env contains published version & imported version not, unpublish it from the target env
|
|
188
|
+
if (targetVariantState.publishedLanguageVariant && !publishedVersion) {
|
|
189
|
+
await workflowImporter.unpublishLanguageVariantAsync({
|
|
190
|
+
logSpinner,
|
|
191
|
+
migrationItem
|
|
180
192
|
});
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (draftVersion) {
|
|
187
|
-
draftLanguageVariant = await importVersionAsync({
|
|
188
|
-
logSpinner: logSpinner,
|
|
189
|
-
migrationItem: migrationItem,
|
|
190
|
-
preparedContentItem: preparedContentItem,
|
|
191
|
-
migrationItemVersion: draftVersion,
|
|
192
|
-
workflowStepCodenameInTargetEnvironment: lastWorkflowStepCodenameInTargetEnvironment
|
|
193
|
+
await workflowImporter.moveToDraftStepAsync({
|
|
194
|
+
logSpinner,
|
|
195
|
+
migrationItem
|
|
193
196
|
});
|
|
194
197
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
.byLanguageCodename(migrationItem.system.language.codename)
|
|
207
|
-
.toPromise();
|
|
208
|
-
},
|
|
209
|
-
action: 'createNewVersion',
|
|
210
|
-
type: 'languageVariant',
|
|
211
|
-
logSpinner: logSpinner,
|
|
212
|
-
itemName: `${migrationItem.system.codename} (${migrationItem.system.language.codename})`
|
|
213
|
-
});
|
|
198
|
+
const draftLanguageVariant: Readonly<LanguageVariantModels.ContentItemLanguageVariant> | undefined = draftVersion
|
|
199
|
+
? await importVersionAsync({
|
|
200
|
+
logSpinner: logSpinner,
|
|
201
|
+
migrationItem: migrationItem,
|
|
202
|
+
preparedContentItem: preparedContentItem,
|
|
203
|
+
migrationItemVersion: draftVersion,
|
|
204
|
+
createNewVersion: publishedLanguageVariant ? true : false
|
|
205
|
+
})
|
|
206
|
+
: undefined;
|
|
207
|
+
|
|
208
|
+
return [publishedLanguageVariant, draftLanguageVariant].filter(isNotUndefined);
|
|
214
209
|
};
|
|
215
210
|
|
|
216
|
-
const
|
|
217
|
-
logSpinner: LogSpinnerData
|
|
218
|
-
migrationItem: MigrationItem
|
|
219
|
-
|
|
220
|
-
): Promise<void> => {
|
|
221
|
-
const
|
|
211
|
+
const cancelScheduledStateAsync = async (data: {
|
|
212
|
+
readonly logSpinner: LogSpinnerData;
|
|
213
|
+
readonly migrationItem: MigrationItem;
|
|
214
|
+
readonly scheduledState: LanguageVariantSchedulesStateValues;
|
|
215
|
+
}): Promise<void> => {
|
|
216
|
+
const changeWorkflowData = {
|
|
217
|
+
logSpinner: data.logSpinner,
|
|
218
|
+
migrationItem: data.migrationItem
|
|
219
|
+
};
|
|
222
220
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
codename: workflow.codename
|
|
234
|
-
},
|
|
235
|
-
step_identifier: {
|
|
236
|
-
codename: firstWorkflowStep.codename
|
|
237
|
-
}
|
|
238
|
-
})
|
|
239
|
-
.toPromise();
|
|
240
|
-
},
|
|
241
|
-
action: 'changeWorkflowStep',
|
|
242
|
-
type: 'languageVariant',
|
|
243
|
-
logSpinner: logSpinner,
|
|
244
|
-
itemName: `${migrationItem.system.codename} (${migrationItem.system.language.codename}) -> ${firstWorkflowStep.codename}`
|
|
245
|
-
});
|
|
246
|
-
}
|
|
221
|
+
await match(data.scheduledState)
|
|
222
|
+
.with('scheduledPublish', async () => {
|
|
223
|
+
// cancel scheduled publish if language variant is scheduled to be published
|
|
224
|
+
await workflowImporter.cancelScheduledPublishAsync(changeWorkflowData);
|
|
225
|
+
})
|
|
226
|
+
.with('scheduledUnpublish', async () => {
|
|
227
|
+
// cancel scheduled unpublish if language variant is scheduled to be unpublished
|
|
228
|
+
await workflowImporter.cancelScheduledUnpublishAsync(changeWorkflowData);
|
|
229
|
+
})
|
|
230
|
+
.otherwise(() => {});
|
|
247
231
|
};
|
|
248
232
|
|
|
249
|
-
const
|
|
233
|
+
const prepareTargetEnvironmentVariantForImportAsync = async (data: {
|
|
250
234
|
readonly logSpinner: LogSpinnerData;
|
|
251
235
|
readonly migrationItem: MigrationItem;
|
|
252
|
-
readonly
|
|
253
|
-
readonly workflow: Readonly<WorkflowModels.Workflow>;
|
|
236
|
+
readonly targetVariantState: LanguageVariantStateInTargetEnvironmentByCodename;
|
|
254
237
|
}): Promise<void> => {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
238
|
+
if (!data.targetVariantState) {
|
|
239
|
+
// no need to prepare language variant as it doesn't exist in target environment
|
|
240
|
+
return;
|
|
258
241
|
}
|
|
259
242
|
|
|
260
|
-
//
|
|
261
|
-
if
|
|
262
|
-
|
|
243
|
+
// when language variant exists in target env, we need to prepare it for import by unscheduling, moving to draft etc...
|
|
244
|
+
// we use draft language variant if it exists, otherwise we use published language variant
|
|
245
|
+
const languageVariantToPrepare = data.targetVariantState.draftLanguageVariant ?? data.targetVariantState.publishedLanguageVariant;
|
|
246
|
+
|
|
247
|
+
if (!languageVariantToPrepare) {
|
|
248
|
+
return;
|
|
263
249
|
}
|
|
250
|
+
|
|
251
|
+
// there is likely a bug which causes /published endpoint to return invalid scheduled state
|
|
252
|
+
// use conditions below to determine scheduled state to use - this will be fixed in future
|
|
253
|
+
if (languageVariantToPrepare.workflowState?.scheduledState) {
|
|
254
|
+
await cancelScheduledStateAsync({
|
|
255
|
+
logSpinner: data.logSpinner,
|
|
256
|
+
migrationItem: data.migrationItem,
|
|
257
|
+
scheduledState: languageVariantToPrepare.workflowState.scheduledState
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const changeWorkflowData = {
|
|
262
|
+
logSpinner: data.logSpinner,
|
|
263
|
+
migrationItem: data.migrationItem
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
await match(languageVariantToPrepare.workflowState?.workflowState)
|
|
267
|
+
.with('published', async () => {
|
|
268
|
+
// create new version if language variant is published
|
|
269
|
+
await workflowImporter.createNewVersionOfLanguageVariantAsync(changeWorkflowData);
|
|
270
|
+
})
|
|
271
|
+
.with('archived', async () => {
|
|
272
|
+
// move to draft step if language variant is archived
|
|
273
|
+
await workflowImporter.moveToDraftStepAsync(changeWorkflowData);
|
|
274
|
+
})
|
|
275
|
+
.otherwise(() => {});
|
|
264
276
|
};
|
|
265
277
|
|
|
266
278
|
const isPublishedWorkflowStep = (stepCodename: string, workflow: Readonly<WorkflowModels.Workflow>): boolean => {
|
|
267
279
|
return workflow.publishedStep.codename === stepCodename;
|
|
268
280
|
};
|
|
269
281
|
|
|
270
|
-
const isArchivedWorkflowStep = (stepCodename: string, workflow: Readonly<WorkflowModels.Workflow>): boolean => {
|
|
271
|
-
return workflow.archivedStep.codename === stepCodename;
|
|
272
|
-
};
|
|
273
|
-
|
|
274
282
|
const getElementContract = (
|
|
275
283
|
migrationItem: MigrationItem,
|
|
276
284
|
element: MigrationElement,
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { ManagementClient, SharedModels, WorkflowModels } from '@kontent-ai/management-sdk';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Logger,
|
|
4
|
+
runMapiRequestAsync,
|
|
5
|
+
LogSpinnerData,
|
|
6
|
+
MigrationItem,
|
|
7
|
+
workflowHelper as workflowHelperInit,
|
|
8
|
+
MigrationItemVersion
|
|
9
|
+
} from '../../core/index.js';
|
|
10
|
+
import { match } from 'ts-pattern';
|
|
3
11
|
|
|
4
12
|
export function workflowImporter(config: {
|
|
5
|
-
logger: Logger;
|
|
6
|
-
managementClient: Readonly<ManagementClient>;
|
|
7
|
-
workflows: readonly Readonly<WorkflowModels.Workflow>[];
|
|
13
|
+
readonly logger: Logger;
|
|
14
|
+
readonly managementClient: Readonly<ManagementClient>;
|
|
15
|
+
readonly workflows: readonly Readonly<WorkflowModels.Workflow>[];
|
|
8
16
|
}) {
|
|
17
|
+
const workflowHelper = workflowHelperInit(config.workflows);
|
|
18
|
+
|
|
9
19
|
const publishLanguageVariantAsync = async (data: {
|
|
10
20
|
readonly logSpinner: LogSpinnerData;
|
|
11
21
|
readonly migrationItem: MigrationItem;
|
|
@@ -64,12 +74,70 @@ export function workflowImporter(config: {
|
|
|
64
74
|
}
|
|
65
75
|
};
|
|
66
76
|
|
|
77
|
+
const schedulePublishLanguageVariantAsync = async (data: {
|
|
78
|
+
readonly logSpinner: LogSpinnerData;
|
|
79
|
+
readonly migrationItem: MigrationItem;
|
|
80
|
+
readonly schedule: {
|
|
81
|
+
readonly publish_time: string;
|
|
82
|
+
readonly publish_display_timezone: string;
|
|
83
|
+
};
|
|
84
|
+
}): Promise<void> => {
|
|
85
|
+
await runMapiRequestAsync({
|
|
86
|
+
logger: config.logger,
|
|
87
|
+
func: async () =>
|
|
88
|
+
(
|
|
89
|
+
await config.managementClient
|
|
90
|
+
.publishLanguageVariant()
|
|
91
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
92
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
93
|
+
.withData({
|
|
94
|
+
scheduled_to: data.schedule.publish_time,
|
|
95
|
+
display_timezone: data.schedule.publish_display_timezone
|
|
96
|
+
})
|
|
97
|
+
.toPromise()
|
|
98
|
+
).data,
|
|
99
|
+
action: 'schedulePublish',
|
|
100
|
+
type: 'languageVariant',
|
|
101
|
+
logSpinner: data.logSpinner,
|
|
102
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename})`
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const scheduleUnpublishLanguageVariantAsync = async (data: {
|
|
107
|
+
readonly logSpinner: LogSpinnerData;
|
|
108
|
+
readonly migrationItem: MigrationItem;
|
|
109
|
+
readonly schedule: {
|
|
110
|
+
readonly unpublish_time: string;
|
|
111
|
+
readonly unpublish_display_timezone: string;
|
|
112
|
+
};
|
|
113
|
+
}): Promise<void> => {
|
|
114
|
+
await runMapiRequestAsync({
|
|
115
|
+
logger: config.logger,
|
|
116
|
+
func: async () =>
|
|
117
|
+
(
|
|
118
|
+
await config.managementClient
|
|
119
|
+
.unpublishLanguageVariant()
|
|
120
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
121
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
122
|
+
.withData({
|
|
123
|
+
scheduled_to: data.schedule.unpublish_time,
|
|
124
|
+
display_timezone: data.schedule.unpublish_display_timezone
|
|
125
|
+
})
|
|
126
|
+
.toPromise()
|
|
127
|
+
).data,
|
|
128
|
+
action: 'scheduleUnpublish',
|
|
129
|
+
type: 'languageVariant',
|
|
130
|
+
logSpinner: data.logSpinner,
|
|
131
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename})`
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
|
|
67
135
|
const archiveLanguageVariantAsync = async (data: {
|
|
68
136
|
readonly logSpinner: LogSpinnerData;
|
|
69
137
|
readonly workflowCodename: string;
|
|
70
138
|
readonly migrationItem: MigrationItem;
|
|
71
139
|
}): Promise<void> => {
|
|
72
|
-
const workflow = workflowHelper
|
|
140
|
+
const workflow = workflowHelper.getWorkflowByCodename(data.workflowCodename);
|
|
73
141
|
await runMapiRequestAsync({
|
|
74
142
|
logger: config.logger,
|
|
75
143
|
func: async () =>
|
|
@@ -101,7 +169,7 @@ export function workflowImporter(config: {
|
|
|
101
169
|
readonly stepCodename: string;
|
|
102
170
|
readonly migrationItem: MigrationItem;
|
|
103
171
|
}): Promise<void> => {
|
|
104
|
-
const { workflow, step } = workflowHelper
|
|
172
|
+
const { workflow, step } = workflowHelper.getWorkflowAndStepByCodenames({
|
|
105
173
|
workflowCodename: data.workflowCodename,
|
|
106
174
|
stepCodename: data.stepCodename
|
|
107
175
|
});
|
|
@@ -131,29 +199,169 @@ export function workflowImporter(config: {
|
|
|
131
199
|
});
|
|
132
200
|
};
|
|
133
201
|
|
|
202
|
+
const createNewVersionOfLanguageVariantAsync = async (data: {
|
|
203
|
+
readonly logSpinner: LogSpinnerData;
|
|
204
|
+
readonly migrationItem: MigrationItem;
|
|
205
|
+
}): Promise<void> => {
|
|
206
|
+
await runMapiRequestAsync({
|
|
207
|
+
logger: config.logger,
|
|
208
|
+
func: async () => {
|
|
209
|
+
await config.managementClient
|
|
210
|
+
.createNewVersionOfLanguageVariant()
|
|
211
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
212
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
213
|
+
.toPromise();
|
|
214
|
+
},
|
|
215
|
+
action: 'createNewVersion',
|
|
216
|
+
type: 'languageVariant',
|
|
217
|
+
logSpinner: data.logSpinner,
|
|
218
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename})`
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const cancelScheduledPublishAsync = async (data: {
|
|
223
|
+
readonly logSpinner: LogSpinnerData;
|
|
224
|
+
readonly migrationItem: MigrationItem;
|
|
225
|
+
}): Promise<void> => {
|
|
226
|
+
await runMapiRequestAsync({
|
|
227
|
+
logger: config.logger,
|
|
228
|
+
func: async () => {
|
|
229
|
+
await config.managementClient
|
|
230
|
+
.cancelSheduledPublishingOfLanguageVariant()
|
|
231
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
232
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
233
|
+
.toPromise();
|
|
234
|
+
},
|
|
235
|
+
action: 'cancelScheduledPublish',
|
|
236
|
+
type: 'languageVariant',
|
|
237
|
+
logSpinner: data.logSpinner,
|
|
238
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename}) -> Cancel scheduled publish`
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const cancelScheduledUnpublishAsync = async (data: {
|
|
243
|
+
readonly logSpinner: LogSpinnerData;
|
|
244
|
+
readonly migrationItem: MigrationItem;
|
|
245
|
+
}): Promise<void> => {
|
|
246
|
+
await runMapiRequestAsync({
|
|
247
|
+
logger: config.logger,
|
|
248
|
+
func: async () => {
|
|
249
|
+
await config.managementClient
|
|
250
|
+
.cancelSheduledUnpublishingOfLanguageVariant()
|
|
251
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
252
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
253
|
+
.toPromise();
|
|
254
|
+
},
|
|
255
|
+
action: 'cancelScheduledUnpublish',
|
|
256
|
+
type: 'languageVariant',
|
|
257
|
+
logSpinner: data.logSpinner,
|
|
258
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename}) -> Cancel scheduled unpublish`
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const moveToDraftStepAsync = async (data: {
|
|
263
|
+
readonly logSpinner: LogSpinnerData;
|
|
264
|
+
readonly migrationItem: MigrationItem;
|
|
265
|
+
}): Promise<void> => {
|
|
266
|
+
const workflow = workflowHelper.getWorkflowByCodename(data.migrationItem.system.workflow.codename);
|
|
267
|
+
const firstWorkflowStep = workflow.steps?.[0];
|
|
268
|
+
|
|
269
|
+
if (firstWorkflowStep) {
|
|
270
|
+
await runMapiRequestAsync({
|
|
271
|
+
logger: config.logger,
|
|
272
|
+
func: async () => {
|
|
273
|
+
await config.managementClient
|
|
274
|
+
.changeWorkflowOfLanguageVariant()
|
|
275
|
+
.byItemCodename(data.migrationItem.system.codename)
|
|
276
|
+
.byLanguageCodename(data.migrationItem.system.language.codename)
|
|
277
|
+
.withData({
|
|
278
|
+
workflow_identifier: {
|
|
279
|
+
codename: workflow.codename
|
|
280
|
+
},
|
|
281
|
+
step_identifier: {
|
|
282
|
+
codename: firstWorkflowStep.codename
|
|
283
|
+
}
|
|
284
|
+
})
|
|
285
|
+
.toPromise();
|
|
286
|
+
},
|
|
287
|
+
action: 'changeWorkflowStep',
|
|
288
|
+
type: 'languageVariant',
|
|
289
|
+
logSpinner: data.logSpinner,
|
|
290
|
+
itemName: `${data.migrationItem.system.codename} (${data.migrationItem.system.language.codename}) -> ${firstWorkflowStep.codename}`
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const setScheduledStateOfLanguageVariantAsync = async (data: {
|
|
296
|
+
readonly logSpinner: LogSpinnerData;
|
|
297
|
+
readonly migrationItem: MigrationItem;
|
|
298
|
+
readonly migrationItemVersion: MigrationItemVersion;
|
|
299
|
+
}): Promise<void> => {
|
|
300
|
+
if (!data.migrationItemVersion.schedule) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// set scheduling
|
|
305
|
+
if (data.migrationItemVersion.schedule.unpublish_time && data.migrationItemVersion.schedule.unpublish_display_timezone) {
|
|
306
|
+
await scheduleUnpublishLanguageVariantAsync({
|
|
307
|
+
logSpinner: data.logSpinner,
|
|
308
|
+
migrationItem: data.migrationItem,
|
|
309
|
+
schedule: {
|
|
310
|
+
unpublish_time: data.migrationItemVersion.schedule.unpublish_time,
|
|
311
|
+
unpublish_display_timezone: data.migrationItemVersion.schedule.unpublish_display_timezone
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (data.migrationItemVersion.schedule.publish_time && data.migrationItemVersion.schedule.publish_display_timezone) {
|
|
317
|
+
await schedulePublishLanguageVariantAsync({
|
|
318
|
+
logSpinner: data.logSpinner,
|
|
319
|
+
migrationItem: data.migrationItem,
|
|
320
|
+
schedule: {
|
|
321
|
+
publish_time: data.migrationItemVersion.schedule.publish_time,
|
|
322
|
+
publish_display_timezone: data.migrationItemVersion.schedule.publish_display_timezone
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
134
328
|
const setWorkflowOfLanguageVariantAsync = async (data: {
|
|
135
329
|
readonly logSpinner: LogSpinnerData;
|
|
136
330
|
readonly workflowCodename: string;
|
|
137
331
|
readonly stepCodename: string;
|
|
138
332
|
readonly migrationItem: MigrationItem;
|
|
333
|
+
readonly migrationItemVersion: MigrationItemVersion;
|
|
139
334
|
}): Promise<void> => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
335
|
+
return await match(data.stepCodename)
|
|
336
|
+
.returnType<Promise<void>>()
|
|
337
|
+
.when(
|
|
338
|
+
(stepCodename) => workflowHelper.isPublishedStepByCodename(stepCodename),
|
|
339
|
+
async () => await publishLanguageVariantAsync(data)
|
|
340
|
+
)
|
|
341
|
+
.when(
|
|
342
|
+
(stepCodename) => workflowHelper.isArchivedStepByCodename(stepCodename),
|
|
343
|
+
async () => await archiveLanguageVariantAsync(data)
|
|
344
|
+
)
|
|
345
|
+
.when(
|
|
346
|
+
(stepCodename) => workflowHelper.isScheduledStepByCodename(stepCodename),
|
|
347
|
+
async () => {
|
|
348
|
+
// do nothing for scheduled step
|
|
349
|
+
return await Promise.resolve();
|
|
350
|
+
}
|
|
351
|
+
)
|
|
352
|
+
.otherwise(async () => await changeWorkflowOfLanguageVariantAsync(data));
|
|
153
353
|
};
|
|
154
354
|
|
|
155
355
|
return {
|
|
356
|
+
setScheduledStateOfLanguageVariantAsync,
|
|
156
357
|
setWorkflowOfLanguageVariantAsync,
|
|
157
|
-
publishLanguageVariantAsync
|
|
358
|
+
publishLanguageVariantAsync,
|
|
359
|
+
unpublishLanguageVariantAsync,
|
|
360
|
+
archiveLanguageVariantAsync,
|
|
361
|
+
changeWorkflowOfLanguageVariantAsync,
|
|
362
|
+
moveToDraftStepAsync,
|
|
363
|
+
createNewVersionOfLanguageVariantAsync,
|
|
364
|
+
cancelScheduledPublishAsync,
|
|
365
|
+
cancelScheduledUnpublishAsync
|
|
158
366
|
};
|
|
159
367
|
}
|
package/lib/metadata.ts
CHANGED
package/lib/node/cli/app.ts
CHANGED
|
@@ -7,25 +7,24 @@ import { importActionAsync } from './actions/import-action.js';
|
|
|
7
7
|
import { migrateActionAsync } from './actions/migrate-action.js';
|
|
8
8
|
import { argumentsFetcherAsync } from './args/args-fetcher.js';
|
|
9
9
|
import { cliArgs } from './commands.js';
|
|
10
|
+
import { match } from 'ts-pattern';
|
|
10
11
|
|
|
11
|
-
//
|
|
12
|
+
// Need to register --help commands
|
|
12
13
|
cliArgs.registerCommands();
|
|
13
14
|
|
|
14
15
|
const run = async () => {
|
|
15
16
|
const argsFetcher = await argumentsFetcherAsync();
|
|
16
17
|
const action = argsFetcher.getCliAction();
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
message: `Invalid action '${chalk.red(action)}'`
|
|
28
|
-
});
|
|
19
|
+
return await match(action)
|
|
20
|
+
.with('export', async () => await exportActionAsync(argsFetcher))
|
|
21
|
+
.with('import', async () => await importActionAsync(argsFetcher))
|
|
22
|
+
.with('migrate', async () => await migrateActionAsync(argsFetcher))
|
|
23
|
+
.otherwise(() =>
|
|
24
|
+
exitProgram({
|
|
25
|
+
message: `Invalid action '${chalk.red(action)}'`
|
|
26
|
+
})
|
|
27
|
+
);
|
|
29
28
|
};
|
|
30
29
|
|
|
31
30
|
run().catch((err) => {
|