@contentstack/cli-variants 0.0.1-alpha
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/lib/export/attributes.d.ts +15 -0
- package/lib/export/attributes.js +62 -0
- package/lib/export/audiences.d.ts +15 -0
- package/lib/export/audiences.js +63 -0
- package/lib/export/events.d.ts +15 -0
- package/lib/export/events.js +63 -0
- package/lib/export/experiences.d.ts +9 -0
- package/lib/export/experiences.js +99 -0
- package/lib/export/index.d.ts +9 -0
- package/lib/export/index.js +21 -0
- package/lib/export/projects.d.ts +9 -0
- package/lib/export/projects.js +73 -0
- package/lib/export/variant-entries.d.ts +18 -0
- package/lib/export/variant-entries.js +109 -0
- package/lib/import/attribute.d.ts +17 -0
- package/lib/import/attribute.js +64 -0
- package/lib/import/audiences.d.ts +19 -0
- package/lib/import/audiences.js +71 -0
- package/lib/import/events.d.ts +17 -0
- package/lib/import/events.js +62 -0
- package/lib/import/experiences.d.ts +46 -0
- package/lib/import/experiences.js +214 -0
- package/lib/import/index.d.ts +14 -0
- package/lib/import/index.js +21 -0
- package/lib/import/project.d.ts +13 -0
- package/lib/import/project.js +74 -0
- package/lib/import/variant-entries.d.ts +98 -0
- package/lib/import/variant-entries.js +407 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +21 -0
- package/lib/messages/index.d.ts +35 -0
- package/lib/messages/index.js +55 -0
- package/lib/types/adapter-helper.d.ts +8 -0
- package/lib/types/adapter-helper.js +2 -0
- package/lib/types/content-types.d.ts +19 -0
- package/lib/types/content-types.js +2 -0
- package/lib/types/export-config.d.ts +264 -0
- package/lib/types/export-config.js +2 -0
- package/lib/types/import-config.d.ts +92 -0
- package/lib/types/import-config.js +2 -0
- package/lib/types/index.d.ts +8 -0
- package/lib/types/index.js +24 -0
- package/lib/types/personalization-api-adapter.d.ts +152 -0
- package/lib/types/personalization-api-adapter.js +2 -0
- package/lib/types/utils.d.ts +7 -0
- package/lib/types/utils.js +2 -0
- package/lib/types/variant-api-adapter.d.ts +49 -0
- package/lib/types/variant-api-adapter.js +2 -0
- package/lib/types/variant-entry.d.ts +47 -0
- package/lib/types/variant-entry.js +2 -0
- package/lib/utils/adapter-helper.d.ts +30 -0
- package/lib/utils/adapter-helper.js +95 -0
- package/lib/utils/attributes-helper.d.ts +7 -0
- package/lib/utils/attributes-helper.js +37 -0
- package/lib/utils/audiences-helper.d.ts +8 -0
- package/lib/utils/audiences-helper.js +49 -0
- package/lib/utils/error-helper.d.ts +6 -0
- package/lib/utils/error-helper.js +27 -0
- package/lib/utils/events-helper.d.ts +8 -0
- package/lib/utils/events-helper.js +27 -0
- package/lib/utils/helper.d.ts +4 -0
- package/lib/utils/helper.js +51 -0
- package/lib/utils/index.d.ts +9 -0
- package/lib/utils/index.js +25 -0
- package/lib/utils/logger.d.ts +3 -0
- package/lib/utils/logger.js +175 -0
- package/lib/utils/personalization-api-adapter.d.ts +73 -0
- package/lib/utils/personalization-api-adapter.js +184 -0
- package/lib/utils/variant-api-adapter.d.ts +79 -0
- package/lib/utils/variant-api-adapter.js +263 -0
- package/package.json +38 -0
- package/src/export/attributes.ts +55 -0
- package/src/export/audiences.ts +57 -0
- package/src/export/events.ts +57 -0
- package/src/export/experiences.ts +80 -0
- package/src/export/index.ts +11 -0
- package/src/export/projects.ts +45 -0
- package/src/export/variant-entries.ts +88 -0
- package/src/import/attribute.ts +60 -0
- package/src/import/audiences.ts +69 -0
- package/src/import/events.ts +58 -0
- package/src/import/experiences.ts +224 -0
- package/src/import/index.ts +16 -0
- package/src/import/project.ts +71 -0
- package/src/import/variant-entries.ts +483 -0
- package/src/index.ts +5 -0
- package/src/messages/index.ts +63 -0
- package/src/types/adapter-helper.ts +10 -0
- package/src/types/content-types.ts +41 -0
- package/src/types/export-config.ts +292 -0
- package/src/types/import-config.ts +95 -0
- package/src/types/index.ts +8 -0
- package/src/types/personalization-api-adapter.ts +197 -0
- package/src/types/utils.ts +8 -0
- package/src/types/variant-api-adapter.ts +56 -0
- package/src/types/variant-entry.ts +61 -0
- package/src/utils/adapter-helper.ts +79 -0
- package/src/utils/attributes-helper.ts +31 -0
- package/src/utils/audiences-helper.ts +50 -0
- package/src/utils/error-helper.ts +26 -0
- package/src/utils/events-helper.ts +26 -0
- package/src/utils/helper.ts +34 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/logger.ts +160 -0
- package/src/utils/personalization-api-adapter.ts +188 -0
- package/src/utils/variant-api-adapter.ts +326 -0
- package/test/unit/export/variant-entries.test.ts +80 -0
- package/test/unit/import/variant-entries.test.ts +200 -0
- package/test/unit/mock/contents/content_types/CT-1.json +7 -0
- package/test/unit/mock/contents/entries/CT-1/en-us/variants/E-1/9b0da6xd7et72y-6gv7he23.json +12 -0
- package/test/unit/mock/contents/entries/CT-1/en-us/variants/E-1/index.json +3 -0
- package/test/unit/mock/contents/entries/CT-1/en-us/variants/E-2/9b0da6xd7et72y-6gv7he23.json +12 -0
- package/test/unit/mock/contents/entries/CT-1/en-us/variants/E-2/index.json +3 -0
- package/test/unit/mock/contents/mapper/assets/uid-mapping.json +6 -0
- package/test/unit/mock/contents/mapper/assets/url-mapping.json +6 -0
- package/test/unit/mock/contents/mapper/entries/data-for-variant-entry.json +6 -0
- package/test/unit/mock/contents/mapper/entries/empty-data/data-for-variant-entry.json +1 -0
- package/test/unit/mock/contents/mapper/entries/uid-mapping.json +6 -0
- package/test/unit/mock/contents/mapper/marketplace_apps/uid-mapping.json +3 -0
- package/test/unit/mock/contents/mapper/personalization/experiences/variants-uid-mapping.json +5 -0
- package/test/unit/mock/contents/mapper/taxonomies/terms/success.json +1 -0
- package/test/unit/mock/export-config.json +48 -0
- package/test/unit/mock/import-config.json +63 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import VariantAdapter, { VariantHttpClient } from '../utils/variant-api-adapter';
|
|
2
|
+
import { ImportConfig, ContentTypeStruct, VariantEntryStruct, ImportHelperMethodsConfig, EntryDataForVariantEntries } from '../types';
|
|
3
|
+
export default class VariantEntries extends VariantAdapter<VariantHttpClient<ImportConfig>> {
|
|
4
|
+
readonly config: ImportConfig & {
|
|
5
|
+
helpers?: ImportHelperMethodsConfig;
|
|
6
|
+
};
|
|
7
|
+
entriesDirPath: string;
|
|
8
|
+
entriesMapperPath: string;
|
|
9
|
+
variantEntryBasePath: string;
|
|
10
|
+
variantIdList: Record<string, unknown>;
|
|
11
|
+
personalizationConfig: ImportConfig['modules']['personalization'];
|
|
12
|
+
taxonomies: Record<string, unknown>;
|
|
13
|
+
assetUrlMapper: Record<string, any>;
|
|
14
|
+
assetUidMapper: Record<string, any>;
|
|
15
|
+
entriesUidMapper: Record<string, any>;
|
|
16
|
+
private installedExtensions;
|
|
17
|
+
private failedVariantPath;
|
|
18
|
+
private failedVariantEntries;
|
|
19
|
+
private environments;
|
|
20
|
+
constructor(config: ImportConfig & {
|
|
21
|
+
helpers?: ImportHelperMethodsConfig;
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* This TypeScript function asynchronously imports backupDir from a JSON file and processes the entries
|
|
25
|
+
* for variant entries.
|
|
26
|
+
* @returns If the file at the specified file path exists and contains backupDir, the function will parse
|
|
27
|
+
* the JSON backupDir and iterate over each entry to import variant entries using the
|
|
28
|
+
* `importVariantEntries` method. If the `entriesForVariants` array is empty, the function will log a
|
|
29
|
+
* message indicating that no entries were found and return.
|
|
30
|
+
*/
|
|
31
|
+
import(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* The function `importVariantEntries` asynchronously imports variant entries using file system
|
|
34
|
+
* utility in TypeScript.
|
|
35
|
+
* @param {EntryDataForVariantEntries} entriesForVariant - EntryDataForVariantEntries {
|
|
36
|
+
*/
|
|
37
|
+
importVariantEntries(entriesForVariant: EntryDataForVariantEntries): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* The function `handleConcurrency` processes variant entries in batches with a specified concurrency
|
|
40
|
+
* level and handles API calls for creating variant entries.
|
|
41
|
+
* @param {VariantEntryStruct[]} variantEntries - The `variantEntries` parameter is an array of
|
|
42
|
+
* `VariantEntryStruct` objects. It seems like this function is handling concurrency for processing
|
|
43
|
+
* these entries in batches. The function chunks the `variantEntries` array into smaller batches and
|
|
44
|
+
* then processes each batch asynchronously using `Promise.allSettled`. It also
|
|
45
|
+
* @param {EntryDataForVariantEntries} entriesForVariant - The `entriesForVariant` parameter seems to
|
|
46
|
+
* be an object containing the following properties:
|
|
47
|
+
* @returns The `handleConcurrency` function processes variant entries in batches, creating variant
|
|
48
|
+
* entries using the `createVariantEntry` method and handling the API response using
|
|
49
|
+
* `Promise.allSettled`. The function also includes logic to handle variant IDs and delays between
|
|
50
|
+
* batch processing.
|
|
51
|
+
*/
|
|
52
|
+
handleConcurrency(contentType: ContentTypeStruct, variantEntries: VariantEntryStruct[], entriesForVariant: EntryDataForVariantEntries): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Serializes the change set of a entry variant.
|
|
55
|
+
* @param variantEntry - The entry variant to serialize.
|
|
56
|
+
* @returns The serialized change set as a record.
|
|
57
|
+
*/
|
|
58
|
+
serializeChangeSet(variantEntry: VariantEntryStruct): Record<string, any>;
|
|
59
|
+
/**
|
|
60
|
+
* The function `handleVariantEntryRelationalData` processes relational data for a entry variant
|
|
61
|
+
* based on the provided content type and configuration helpers.
|
|
62
|
+
* @param {ContentTypeStruct} contentType - The `contentType` parameter in the
|
|
63
|
+
* `handleVariantEntryRelationalData` function is of type `ContentTypeStruct`. It is used to define
|
|
64
|
+
* the structure of the content type being processed within the function. This parameter likely
|
|
65
|
+
* contains information about the schema and configuration of the content type.
|
|
66
|
+
* @param {VariantEntryStruct} variantEntry - The `variantEntry` parameter in the
|
|
67
|
+
* `handleVariantEntryRelationalData` function is a data structure that represents a entry variant.
|
|
68
|
+
* It is of type `VariantEntryStruct` and contains information related to a specific entry variant.
|
|
69
|
+
* This function is responsible for performing various operations on the `variantEntry`
|
|
70
|
+
* @returns The function `handleVariantEntryRelationalData` returns the `variantEntry` after
|
|
71
|
+
* performing various lookups and replacements on it based on the provided `contentType` and
|
|
72
|
+
* `config.helpers`.
|
|
73
|
+
*/
|
|
74
|
+
handleVariantEntryRelationalData(contentType: ContentTypeStruct, variantEntry: VariantEntryStruct): VariantEntryStruct;
|
|
75
|
+
/**
|
|
76
|
+
* Updates the file fields of a entry variant to support lookup asset logic.
|
|
77
|
+
* Lookup asset expects file fields to be an object instead of a string. So here we are updating the file fields to be an object. Object has two keys: `uid` and `filename`. `uid` is the asset UID and `filename` is the name of the file. Used a dummy value for the filename. This is a temporary fix and will be updated in the future.
|
|
78
|
+
* @param variantEntry - The entry variant to update.
|
|
79
|
+
*/
|
|
80
|
+
updateFileFields(variantEntry: VariantEntryStruct): void;
|
|
81
|
+
/**
|
|
82
|
+
* Publishes variant entries in batch for a given entry UID and content type.
|
|
83
|
+
* @param batch - An array of VariantEntryStruct objects representing the variant entries to be published.
|
|
84
|
+
* @param entryUid - The UID of the entry for which the variant entries are being published.
|
|
85
|
+
* @param content_type - The UID of the content type of the entry.
|
|
86
|
+
* @returns A Promise that resolves when all variant entries have been published.
|
|
87
|
+
*/
|
|
88
|
+
publishVariantEntries(batch: VariantEntryStruct[], entryUid: string, content_type: string): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Serializes the publish entries of a variant.
|
|
91
|
+
* @param variantEntry - The entry variant to serialize.
|
|
92
|
+
* @returns An object containing the serialized publish entries.
|
|
93
|
+
*/
|
|
94
|
+
serializePublishEntries(variantEntry: VariantEntryStruct): {
|
|
95
|
+
environments: Array<string>;
|
|
96
|
+
locales: Array<string>;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const omit_1 = __importDefault(require("lodash/omit"));
|
|
39
|
+
const chunk_1 = __importDefault(require("lodash/chunk"));
|
|
40
|
+
const entries_1 = __importDefault(require("lodash/entries"));
|
|
41
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
42
|
+
const forEach_1 = __importDefault(require("lodash/forEach"));
|
|
43
|
+
const indexOf_1 = __importDefault(require("lodash/indexOf"));
|
|
44
|
+
const path_1 = require("path");
|
|
45
|
+
const fs_1 = require("fs");
|
|
46
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
47
|
+
const variant_api_adapter_1 = __importStar(require("../utils/variant-api-adapter"));
|
|
48
|
+
const utils_1 = require("../utils");
|
|
49
|
+
class VariantEntries extends variant_api_adapter_1.default {
|
|
50
|
+
constructor(config) {
|
|
51
|
+
const conf = {
|
|
52
|
+
config,
|
|
53
|
+
httpClient: true,
|
|
54
|
+
baseURL: config.host,
|
|
55
|
+
Adapter: (variant_api_adapter_1.VariantHttpClient),
|
|
56
|
+
headers: {
|
|
57
|
+
api_key: config.apiKey,
|
|
58
|
+
branch: config.branchName,
|
|
59
|
+
authtoken: config.auth_token,
|
|
60
|
+
organization_uid: config.org_uid,
|
|
61
|
+
'X-Project-Uid': config.modules.personalization.project_id,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
super(Object.assign((0, omit_1.default)(config, ['helpers']), conf));
|
|
65
|
+
this.config = config;
|
|
66
|
+
this.entriesMapperPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(config.backupDir), (0, cli_utilities_1.sanitizePath)(config.branchName || ''), 'mapper', 'entries');
|
|
67
|
+
this.personalizationConfig = this.config.modules.personalization;
|
|
68
|
+
this.entriesDirPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(config.backupDir), (0, cli_utilities_1.sanitizePath)(config.branchName || ''), (0, cli_utilities_1.sanitizePath)(config.modules.entries.dirName));
|
|
69
|
+
this.failedVariantPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.entriesMapperPath), 'failed-entry-variants.json');
|
|
70
|
+
this.failedVariantEntries = new Map();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* This TypeScript function asynchronously imports backupDir from a JSON file and processes the entries
|
|
74
|
+
* for variant entries.
|
|
75
|
+
* @returns If the file at the specified file path exists and contains backupDir, the function will parse
|
|
76
|
+
* the JSON backupDir and iterate over each entry to import variant entries using the
|
|
77
|
+
* `importVariantEntries` method. If the `entriesForVariants` array is empty, the function will log a
|
|
78
|
+
* message indicating that no entries were found and return.
|
|
79
|
+
*/
|
|
80
|
+
import() {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const filePath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.entriesMapperPath), 'data-for-variant-entry.json');
|
|
83
|
+
const variantIdPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', (0, cli_utilities_1.sanitizePath)(this.personalizationConfig.dirName), (0, cli_utilities_1.sanitizePath)(this.personalizationConfig.experiences.dirName), 'variants-uid-mapping.json');
|
|
84
|
+
if (!(0, fs_1.existsSync)(filePath)) {
|
|
85
|
+
(0, utils_1.log)(this.config, this.messages.IMPORT_ENTRY_NOT_FOUND, 'info');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!(0, fs_1.existsSync)(variantIdPath)) {
|
|
89
|
+
(0, utils_1.log)(this.config, this.messages.EMPTY_VARIANT_UID_DATA, 'error');
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const entriesForVariants = utils_1.fsUtil.readFile(filePath, true);
|
|
93
|
+
if ((0, isEmpty_1.default)(entriesForVariants)) {
|
|
94
|
+
(0, utils_1.log)(this.config, this.messages.IMPORT_ENTRY_NOT_FOUND, 'info');
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const entriesUidMapperPath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.entriesMapperPath), 'uid-mapping.json');
|
|
98
|
+
const assetUidMapperPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', 'assets', 'uid-mapping.json');
|
|
99
|
+
const assetUrlMapperPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', 'assets', 'url-mapping.json');
|
|
100
|
+
const taxonomiesPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', (0, cli_utilities_1.sanitizePath)(this.config.modules.taxonomies.dirName), 'terms', 'success.json');
|
|
101
|
+
const marketplaceAppMapperPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', 'marketplace_apps', 'uid-mapping.json');
|
|
102
|
+
const envPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'environments', 'environments.json');
|
|
103
|
+
// NOTE Read and store list of variant IDs
|
|
104
|
+
this.variantIdList = (utils_1.fsUtil.readFile(variantIdPath, true) || {});
|
|
105
|
+
if ((0, isEmpty_1.default)(this.variantIdList)) {
|
|
106
|
+
(0, utils_1.log)(this.config, this.messages.EMPTY_VARIANT_UID_DATA, 'info');
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// NOTE entry relational data lookup dependencies.
|
|
110
|
+
this.entriesUidMapper = (utils_1.fsUtil.readFile(entriesUidMapperPath, true) || {});
|
|
111
|
+
this.installedExtensions = (utils_1.fsUtil.readFile(marketplaceAppMapperPath) || { extension_uid: {} })
|
|
112
|
+
.extension_uid;
|
|
113
|
+
this.taxonomies = (utils_1.fsUtil.readFile(taxonomiesPath, true) || {});
|
|
114
|
+
this.assetUidMapper = (utils_1.fsUtil.readFile(assetUidMapperPath, true) || {});
|
|
115
|
+
this.assetUrlMapper = (utils_1.fsUtil.readFile(assetUrlMapperPath, true) || {});
|
|
116
|
+
this.environments = (utils_1.fsUtil.readFile(envPath, true) || {});
|
|
117
|
+
for (const entriesForVariant of entriesForVariants) {
|
|
118
|
+
yield this.importVariantEntries(entriesForVariant);
|
|
119
|
+
}
|
|
120
|
+
(0, utils_1.log)(this.config, 'All the entries variants have been imported & published successfully', 'success');
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The function `importVariantEntries` asynchronously imports variant entries using file system
|
|
125
|
+
* utility in TypeScript.
|
|
126
|
+
* @param {EntryDataForVariantEntries} entriesForVariant - EntryDataForVariantEntries {
|
|
127
|
+
*/
|
|
128
|
+
importVariantEntries(entriesForVariant) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
const variantEntry = this.config.modules.variantEntry;
|
|
131
|
+
const { content_type, locale, entry_uid } = entriesForVariant;
|
|
132
|
+
const ctConfig = this.config.modules['content-types'];
|
|
133
|
+
const contentType = JSON.parse((0, fs_1.readFileSync)((0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), (0, cli_utilities_1.sanitizePath)(ctConfig.dirName), `${(0, cli_utilities_1.sanitizePath)(content_type)}.json`), 'utf8'));
|
|
134
|
+
const variantEntryBasePath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.entriesDirPath), (0, cli_utilities_1.sanitizePath)(content_type), (0, cli_utilities_1.sanitizePath)(locale), (0, cli_utilities_1.sanitizePath)(variantEntry.dirName), (0, cli_utilities_1.sanitizePath)(entry_uid));
|
|
135
|
+
const fs = new cli_utilities_1.FsUtility({ basePath: variantEntryBasePath });
|
|
136
|
+
for (const _ in fs.indexFileContent) {
|
|
137
|
+
try {
|
|
138
|
+
const variantEntries = (yield fs.readChunkFiles.next());
|
|
139
|
+
if (variantEntries === null || variantEntries === void 0 ? void 0 : variantEntries.length) {
|
|
140
|
+
yield this.handleConcurrency(contentType, variantEntries, entriesForVariant);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
(0, utils_1.log)(this.config, error, 'error');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The function `handleConcurrency` processes variant entries in batches with a specified concurrency
|
|
151
|
+
* level and handles API calls for creating variant entries.
|
|
152
|
+
* @param {VariantEntryStruct[]} variantEntries - The `variantEntries` parameter is an array of
|
|
153
|
+
* `VariantEntryStruct` objects. It seems like this function is handling concurrency for processing
|
|
154
|
+
* these entries in batches. The function chunks the `variantEntries` array into smaller batches and
|
|
155
|
+
* then processes each batch asynchronously using `Promise.allSettled`. It also
|
|
156
|
+
* @param {EntryDataForVariantEntries} entriesForVariant - The `entriesForVariant` parameter seems to
|
|
157
|
+
* be an object containing the following properties:
|
|
158
|
+
* @returns The `handleConcurrency` function processes variant entries in batches, creating variant
|
|
159
|
+
* entries using the `createVariantEntry` method and handling the API response using
|
|
160
|
+
* `Promise.allSettled`. The function also includes logic to handle variant IDs and delays between
|
|
161
|
+
* batch processing.
|
|
162
|
+
*/
|
|
163
|
+
handleConcurrency(contentType, variantEntries, entriesForVariant) {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
let batchNo = 0;
|
|
166
|
+
const variantEntryConfig = this.config.modules.variantEntry;
|
|
167
|
+
const { content_type, locale, entry_uid } = entriesForVariant;
|
|
168
|
+
const entryUid = this.entriesUidMapper[entry_uid];
|
|
169
|
+
const batches = (0, chunk_1.default)(variantEntries, variantEntryConfig.apiConcurrency || 5);
|
|
170
|
+
if ((0, isEmpty_1.default)(batches))
|
|
171
|
+
return;
|
|
172
|
+
for (const [, batch] of (0, entries_1.default)(batches)) {
|
|
173
|
+
batchNo += 1;
|
|
174
|
+
const allPromise = [];
|
|
175
|
+
const start = Date.now();
|
|
176
|
+
for (let [, variantEntry] of (0, entries_1.default)(batch)) {
|
|
177
|
+
const onSuccess = ({ response, apiData: { entryUid, variantUid }, log }) => {
|
|
178
|
+
log(this.config, `Created entry variant: '${variantUid}' of entry uid ${entryUid}`, 'info');
|
|
179
|
+
};
|
|
180
|
+
const onReject = ({ error, apiData, log }) => {
|
|
181
|
+
const { entryUid, variantUid } = apiData;
|
|
182
|
+
this.failedVariantEntries.set(variantUid, apiData);
|
|
183
|
+
log(this.config, `Failed to create entry variant: '${variantUid}' of entry uid ${entryUid}`, 'error');
|
|
184
|
+
log(this.config, error, 'error');
|
|
185
|
+
};
|
|
186
|
+
// NOTE Find new variant Id by old Id
|
|
187
|
+
const variant_id = this.variantIdList[variantEntry.variant_id];
|
|
188
|
+
// NOTE Replace all the relation data UID's
|
|
189
|
+
variantEntry = this.handleVariantEntryRelationalData(contentType, variantEntry);
|
|
190
|
+
const changeSet = this.serializeChangeSet(variantEntry);
|
|
191
|
+
const createVariantReq = Object.assign({ _variant: variantEntry._variant }, changeSet);
|
|
192
|
+
if (variant_id) {
|
|
193
|
+
const promise = this.variantInstance.createVariantEntry(createVariantReq, {
|
|
194
|
+
locale,
|
|
195
|
+
entry_uid: entryUid,
|
|
196
|
+
variant_id,
|
|
197
|
+
content_type_uid: content_type,
|
|
198
|
+
}, {
|
|
199
|
+
reject: onReject.bind(this),
|
|
200
|
+
resolve: onSuccess.bind(this),
|
|
201
|
+
variantUid: variantEntry.uid,
|
|
202
|
+
log: utils_1.log,
|
|
203
|
+
});
|
|
204
|
+
allPromise.push(promise);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
(0, utils_1.log)(this.config, this.messages.VARIANT_ID_NOT_FOUND, 'error');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// NOTE Handle the API response here
|
|
211
|
+
yield Promise.allSettled(allPromise);
|
|
212
|
+
// NOTE publish all the entries
|
|
213
|
+
yield this.publishVariantEntries(batch, entryUid, content_type);
|
|
214
|
+
const end = Date.now();
|
|
215
|
+
const exeTime = end - start;
|
|
216
|
+
this.variantInstance.delay(1000 - exeTime);
|
|
217
|
+
}
|
|
218
|
+
utils_1.fsUtil.writeFile(this.failedVariantPath, this.failedVariantEntries);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Serializes the change set of a entry variant.
|
|
223
|
+
* @param variantEntry - The entry variant to serialize.
|
|
224
|
+
* @returns The serialized change set as a record.
|
|
225
|
+
*/
|
|
226
|
+
serializeChangeSet(variantEntry) {
|
|
227
|
+
var _a, _b;
|
|
228
|
+
let changeSet = {};
|
|
229
|
+
if ((_b = (_a = variantEntry === null || variantEntry === void 0 ? void 0 : variantEntry._variant) === null || _a === void 0 ? void 0 : _a._change_set) === null || _b === void 0 ? void 0 : _b.length) {
|
|
230
|
+
variantEntry._variant._change_set.forEach((key) => {
|
|
231
|
+
key = key.split('.')[0];
|
|
232
|
+
if (variantEntry[key]) {
|
|
233
|
+
changeSet[key] = variantEntry[key];
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return changeSet;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The function `handleVariantEntryRelationalData` processes relational data for a entry variant
|
|
241
|
+
* based on the provided content type and configuration helpers.
|
|
242
|
+
* @param {ContentTypeStruct} contentType - The `contentType` parameter in the
|
|
243
|
+
* `handleVariantEntryRelationalData` function is of type `ContentTypeStruct`. It is used to define
|
|
244
|
+
* the structure of the content type being processed within the function. This parameter likely
|
|
245
|
+
* contains information about the schema and configuration of the content type.
|
|
246
|
+
* @param {VariantEntryStruct} variantEntry - The `variantEntry` parameter in the
|
|
247
|
+
* `handleVariantEntryRelationalData` function is a data structure that represents a entry variant.
|
|
248
|
+
* It is of type `VariantEntryStruct` and contains information related to a specific entry variant.
|
|
249
|
+
* This function is responsible for performing various operations on the `variantEntry`
|
|
250
|
+
* @returns The function `handleVariantEntryRelationalData` returns the `variantEntry` after
|
|
251
|
+
* performing various lookups and replacements on it based on the provided `contentType` and
|
|
252
|
+
* `config.helpers`.
|
|
253
|
+
*/
|
|
254
|
+
handleVariantEntryRelationalData(contentType, variantEntry) {
|
|
255
|
+
if (this.config.helpers) {
|
|
256
|
+
const { lookUpTerms, lookupAssets, lookupExtension, lookupEntries, restoreJsonRteEntryRefs } = this.config.helpers;
|
|
257
|
+
// FIXME Not sure why do we even need lookupExtension in entries [Ref taken from entries import]
|
|
258
|
+
// Feel free to remove this flow if it's not valid
|
|
259
|
+
// NOTE Find and replace extension's UID
|
|
260
|
+
if (lookupExtension) {
|
|
261
|
+
lookupExtension(this.config, contentType.schema, this.config.preserveStackVersion, this.installedExtensions);
|
|
262
|
+
}
|
|
263
|
+
// NOTE Find and replace RTE Ref UIDs
|
|
264
|
+
variantEntry = restoreJsonRteEntryRefs(variantEntry, variantEntry, contentType.schema, {
|
|
265
|
+
uidMapper: this.entriesUidMapper,
|
|
266
|
+
mappedAssetUids: this.assetUidMapper,
|
|
267
|
+
mappedAssetUrls: this.assetUrlMapper,
|
|
268
|
+
});
|
|
269
|
+
// NOTE Find and replace Entry Ref UIDs
|
|
270
|
+
variantEntry = lookupEntries({
|
|
271
|
+
entry: variantEntry,
|
|
272
|
+
content_type: contentType,
|
|
273
|
+
}, this.entriesUidMapper, (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.entriesMapperPath), (0, cli_utilities_1.sanitizePath)(contentType.uid), (0, cli_utilities_1.sanitizePath)(variantEntry.locale)));
|
|
274
|
+
// NOTE: will remove term if term doesn't exists in taxonomy
|
|
275
|
+
// FIXME: Validate if taxonomy support available for variant entries,
|
|
276
|
+
// if not, feel free to remove this lookup flow.
|
|
277
|
+
lookUpTerms(contentType.schema, variantEntry, this.taxonomies, this.config);
|
|
278
|
+
// update file fields of entry variants to support lookup asset logic
|
|
279
|
+
this.updateFileFields(variantEntry);
|
|
280
|
+
// NOTE Find and replace asset's UID
|
|
281
|
+
variantEntry = lookupAssets({
|
|
282
|
+
entry: variantEntry,
|
|
283
|
+
content_type: contentType,
|
|
284
|
+
}, this.assetUidMapper, this.assetUrlMapper, (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.entriesDirPath), (0, cli_utilities_1.sanitizePath)(contentType.uid)), this.installedExtensions);
|
|
285
|
+
}
|
|
286
|
+
return variantEntry;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Updates the file fields of a entry variant to support lookup asset logic.
|
|
290
|
+
* Lookup asset expects file fields to be an object instead of a string. So here we are updating the file fields to be an object. Object has two keys: `uid` and `filename`. `uid` is the asset UID and `filename` is the name of the file. Used a dummy value for the filename. This is a temporary fix and will be updated in the future.
|
|
291
|
+
* @param variantEntry - The entry variant to update.
|
|
292
|
+
*/
|
|
293
|
+
updateFileFields(variantEntry) {
|
|
294
|
+
var _a;
|
|
295
|
+
const setValue = (currentObj, keys) => {
|
|
296
|
+
if (!currentObj || keys.length === 0)
|
|
297
|
+
return;
|
|
298
|
+
const [firstKey, ...restKeys] = keys;
|
|
299
|
+
if (Array.isArray(currentObj)) {
|
|
300
|
+
for (const item of currentObj) {
|
|
301
|
+
setValue(item, [firstKey, ...restKeys]);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
else if (currentObj && typeof currentObj === 'object') {
|
|
305
|
+
if (firstKey in currentObj) {
|
|
306
|
+
if (keys.length === 1) {
|
|
307
|
+
currentObj[firstKey] = { uid: currentObj[firstKey], filename: 'dummy.jpeg' };
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
setValue(currentObj[firstKey], restKeys);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
const pathsToUpdate = (_a = variantEntry === null || variantEntry === void 0 ? void 0 : variantEntry._metadata) === null || _a === void 0 ? void 0 : _a.references.filter((ref) => ref._content_type_uid === 'sys_assets').map((ref) => ref.path);
|
|
316
|
+
if (pathsToUpdate) {
|
|
317
|
+
pathsToUpdate.forEach((path) => setValue(variantEntry, path.split('.')));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Publishes variant entries in batch for a given entry UID and content type.
|
|
322
|
+
* @param batch - An array of VariantEntryStruct objects representing the variant entries to be published.
|
|
323
|
+
* @param entryUid - The UID of the entry for which the variant entries are being published.
|
|
324
|
+
* @param content_type - The UID of the content type of the entry.
|
|
325
|
+
* @returns A Promise that resolves when all variant entries have been published.
|
|
326
|
+
*/
|
|
327
|
+
publishVariantEntries(batch, entryUid, content_type) {
|
|
328
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
329
|
+
var _a;
|
|
330
|
+
const allPromise = [];
|
|
331
|
+
for (let [, variantEntry] of (0, entries_1.default)(batch)) {
|
|
332
|
+
const variantUid = variantEntry.uid;
|
|
333
|
+
const oldVariantUid = variantEntry.variant_id || '';
|
|
334
|
+
const newVariantUid = this.variantIdList[oldVariantUid];
|
|
335
|
+
if (!newVariantUid) {
|
|
336
|
+
(0, utils_1.log)(this.config, `${this.messages.VARIANT_ID_NOT_FOUND}. Skipping entry variant publish for ${variantUid}`, 'info');
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
if (this.failedVariantEntries.has(variantUid)) {
|
|
340
|
+
(0, utils_1.log)(this.config, `${this.messages.VARIANT_UID_NOT_FOUND}. Skipping entry variant publish for ${variantUid}`, 'info');
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
if ((_a = this.environments) === null || _a === void 0 ? void 0 : _a.length) {
|
|
344
|
+
(0, utils_1.log)(this.config, 'No environment found! Skipping entry variant publishing...', 'info');
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const onSuccess = ({ response, apiData: { entryUid, variantUid }, log }) => {
|
|
348
|
+
log(this.config, `Entry variant: '${variantUid}' of entry uid ${entryUid} published successfully!`, 'info');
|
|
349
|
+
};
|
|
350
|
+
const onReject = ({ error, apiData: { entryUid, variantUid }, log }) => {
|
|
351
|
+
log(this.config, `Failed to publish entry variant: '${variantUid}' of entry uid ${entryUid}`, 'error');
|
|
352
|
+
log(this.config, (0, utils_1.formatError)(error), 'error');
|
|
353
|
+
};
|
|
354
|
+
const { environments, locales } = this.serializePublishEntries(variantEntry);
|
|
355
|
+
if ((environments === null || environments === void 0 ? void 0 : environments.length) === 0 || (locales === null || locales === void 0 ? void 0 : locales.length) === 0) {
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
const publishReq = {
|
|
359
|
+
entry: {
|
|
360
|
+
environments,
|
|
361
|
+
locales,
|
|
362
|
+
publish_with_base_entry: false,
|
|
363
|
+
variants: [{ uid: newVariantUid, version: 1 }],
|
|
364
|
+
},
|
|
365
|
+
locale: variantEntry.locale,
|
|
366
|
+
version: 1,
|
|
367
|
+
};
|
|
368
|
+
const promise = this.variantInstance.publishVariantEntry(publishReq, {
|
|
369
|
+
entry_uid: entryUid,
|
|
370
|
+
content_type_uid: content_type,
|
|
371
|
+
}, {
|
|
372
|
+
reject: onReject.bind(this),
|
|
373
|
+
resolve: onSuccess.bind(this),
|
|
374
|
+
log: utils_1.log,
|
|
375
|
+
variantUid,
|
|
376
|
+
});
|
|
377
|
+
allPromise.push(promise);
|
|
378
|
+
}
|
|
379
|
+
yield Promise.allSettled(allPromise);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Serializes the publish entries of a variant.
|
|
384
|
+
* @param variantEntry - The entry variant to serialize.
|
|
385
|
+
* @returns An object containing the serialized publish entries.
|
|
386
|
+
*/
|
|
387
|
+
serializePublishEntries(variantEntry) {
|
|
388
|
+
var _a;
|
|
389
|
+
const requestObject = {
|
|
390
|
+
environments: [],
|
|
391
|
+
locales: [],
|
|
392
|
+
};
|
|
393
|
+
if (variantEntry.publish_details && ((_a = variantEntry.publish_details) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
394
|
+
(0, forEach_1.default)(variantEntry.publish_details, (pubObject) => {
|
|
395
|
+
if (this.environments.hasOwnProperty(pubObject.environment) &&
|
|
396
|
+
(0, indexOf_1.default)(requestObject.environments, this.environments[pubObject.environment].name) === -1) {
|
|
397
|
+
requestObject.environments.push(this.environments[pubObject.environment].name);
|
|
398
|
+
}
|
|
399
|
+
if (pubObject.locale && (0, indexOf_1.default)(requestObject.locales, pubObject.locale) === -1) {
|
|
400
|
+
requestObject.locales.push(pubObject.locale);
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
return requestObject;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
exports.default = VariantEntries;
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./utils"), exports);
|
|
19
|
+
__exportStar(require("./export"), exports);
|
|
20
|
+
__exportStar(require("./import"), exports);
|
|
21
|
+
__exportStar(require("./messages"), exports);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
declare const errors: {
|
|
2
|
+
CREATE_FAILURE: string;
|
|
3
|
+
};
|
|
4
|
+
declare const commonMsg: {
|
|
5
|
+
CREATE_SUCCESS: string;
|
|
6
|
+
};
|
|
7
|
+
declare const migrationMsg: {
|
|
8
|
+
IMPORT_MSG: string;
|
|
9
|
+
};
|
|
10
|
+
declare const variantEntry: {
|
|
11
|
+
IMPORT_ENTRY_NOT_FOUND: string;
|
|
12
|
+
EMPTY_VARIANT_UID_DATA: string;
|
|
13
|
+
VARIANT_ID_NOT_FOUND: string;
|
|
14
|
+
VARIANT_UID_NOT_FOUND: string;
|
|
15
|
+
};
|
|
16
|
+
declare const expImportMsg: {
|
|
17
|
+
UPDATING_CT_IN_EXP: string;
|
|
18
|
+
UPDATED_CT_IN_EXP: string;
|
|
19
|
+
VALIDATE_VARIANT_AND_VARIANT_GRP: string;
|
|
20
|
+
PERSONALIZATION_JOB_FAILURE: string;
|
|
21
|
+
};
|
|
22
|
+
declare const messages: typeof errors & typeof commonMsg & typeof migrationMsg & typeof variantEntry & typeof expImportMsg;
|
|
23
|
+
/**
|
|
24
|
+
* The function `` is a TypeScript function that replaces placeholders in a message string with
|
|
25
|
+
* values from a provided object.
|
|
26
|
+
* @param {string} msg - The `msg` parameter is a string that represents the message template with
|
|
27
|
+
* placeholders for dynamic values.
|
|
28
|
+
* @param args - The `args` parameter is an object that contains key-value pairs where the key is a
|
|
29
|
+
* string and the value is also a string. These key-value pairs are used to replace placeholders in the
|
|
30
|
+
* `msg` string with the corresponding values.
|
|
31
|
+
* @returns the formatted message with the provided arguments replaced in the placeholders.
|
|
32
|
+
*/
|
|
33
|
+
declare function $t(msg: string, args: Record<string, string>): string;
|
|
34
|
+
export default messages;
|
|
35
|
+
export { $t, errors, commonMsg };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.commonMsg = exports.errors = void 0;
|
|
7
|
+
exports.$t = $t;
|
|
8
|
+
const memoize_1 = __importDefault(require("lodash/memoize"));
|
|
9
|
+
const errors = {
|
|
10
|
+
CREATE_FAILURE: '{module} creation failed!',
|
|
11
|
+
};
|
|
12
|
+
exports.errors = errors;
|
|
13
|
+
const commonMsg = {
|
|
14
|
+
CREATE_SUCCESS: '{module} created successfully!',
|
|
15
|
+
};
|
|
16
|
+
exports.commonMsg = commonMsg;
|
|
17
|
+
const migrationMsg = {
|
|
18
|
+
IMPORT_MSG: 'Migrating {module}...',
|
|
19
|
+
};
|
|
20
|
+
const variantEntry = {
|
|
21
|
+
IMPORT_ENTRY_NOT_FOUND: 'Entries data not found to import variant entries',
|
|
22
|
+
EMPTY_VARIANT_UID_DATA: 'Empty variants entry mapper found!',
|
|
23
|
+
VARIANT_ID_NOT_FOUND: 'Variant ID not found',
|
|
24
|
+
VARIANT_UID_NOT_FOUND: 'Entry Variant UID not found',
|
|
25
|
+
};
|
|
26
|
+
const expImportMsg = {
|
|
27
|
+
UPDATING_CT_IN_EXP: 'Updating content types in experiences...',
|
|
28
|
+
UPDATED_CT_IN_EXP: 'Successfully updated content types in experiences!',
|
|
29
|
+
VALIDATE_VARIANT_AND_VARIANT_GRP: 'Validating variant group and variants creation...',
|
|
30
|
+
PERSONALIZATION_JOB_FAILURE: 'Something went wrong with personalization background job! Failed to fetch some variant & variant groups',
|
|
31
|
+
};
|
|
32
|
+
const messages = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, errors), commonMsg), migrationMsg), variantEntry), expImportMsg);
|
|
33
|
+
/**
|
|
34
|
+
* The function `` is a TypeScript function that replaces placeholders in a message string with
|
|
35
|
+
* values from a provided object.
|
|
36
|
+
* @param {string} msg - The `msg` parameter is a string that represents the message template with
|
|
37
|
+
* placeholders for dynamic values.
|
|
38
|
+
* @param args - The `args` parameter is an object that contains key-value pairs where the key is a
|
|
39
|
+
* string and the value is also a string. These key-value pairs are used to replace placeholders in the
|
|
40
|
+
* `msg` string with the corresponding values.
|
|
41
|
+
* @returns the formatted message with the provided arguments replaced in the placeholders.
|
|
42
|
+
*/
|
|
43
|
+
function $t(msg, args) {
|
|
44
|
+
const transfer = (0, memoize_1.default)(function (msg, args) {
|
|
45
|
+
if (!msg)
|
|
46
|
+
return '';
|
|
47
|
+
for (const key of Object.keys(args)) {
|
|
48
|
+
const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
49
|
+
msg = msg.replace(new RegExp(`{${escapedKey}}`, 'g'), args[key] || escapedKey);
|
|
50
|
+
}
|
|
51
|
+
return msg;
|
|
52
|
+
});
|
|
53
|
+
return transfer(msg, args);
|
|
54
|
+
}
|
|
55
|
+
exports.default = messages;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import messages from "../messages";
|
|
2
|
+
export interface AdapterHelperInterface<T, Client> {
|
|
3
|
+
readonly config: T;
|
|
4
|
+
readonly apiClient: Client;
|
|
5
|
+
readonly messages: typeof messages;
|
|
6
|
+
delay(ms: number): Promise<void>;
|
|
7
|
+
constructQuery(query: Record<string, any>): string | void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AnyProperty } from './utils';
|
|
2
|
+
import { ImportConfig } from './import-config';
|
|
3
|
+
export type ContentTypeStruct = {
|
|
4
|
+
uid: string;
|
|
5
|
+
title: string;
|
|
6
|
+
description: string;
|
|
7
|
+
schema: AnyProperty[];
|
|
8
|
+
options: AnyProperty;
|
|
9
|
+
} & AnyProperty;
|
|
10
|
+
export type ImportHelperMethodsConfig = {
|
|
11
|
+
lookupAssets: (data: Record<string, any>, mappedAssetUids: Record<string, any>, mappedAssetUrls: Record<string, any>, assetUidMapperPath: string, installedExtensions: Record<string, any>[]) => any;
|
|
12
|
+
lookupExtension?: (config: ImportConfig, schema: any, preserveStackVersion: any, installedExtensions: any) => void;
|
|
13
|
+
restoreJsonRteEntryRefs: (entry: Record<string, any>, sourceStackEntry: any, ctSchema: any, { uidMapper, mappedAssetUids, mappedAssetUrls }: any) => Record<string, any>;
|
|
14
|
+
lookupEntries: (data: {
|
|
15
|
+
content_type: any;
|
|
16
|
+
entry: any;
|
|
17
|
+
}, mappedUids: Record<string, any>, uidMapperPath: string) => any;
|
|
18
|
+
lookUpTerms: (ctSchema: Record<string, any>[], entry: any, taxonomiesAndTermData: Record<string, any>, importConfig: ImportConfig) => void;
|
|
19
|
+
};
|