@contentstack/cli-variants 1.1.2 → 1.1.4
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/experiences.js +17 -7
- package/lib/export/projects.js +17 -7
- package/lib/export/variant-entries.js +17 -7
- package/lib/import/experiences.js +10 -5
- package/lib/import/project.js +2 -1
- package/lib/import/variant-entries.js +17 -7
- package/lib/utils/adapter-helper.js +17 -7
- package/lib/utils/logger.js +17 -7
- package/lib/utils/variant-api-adapter.js +2 -2
- package/package.json +10 -10
- package/src/import/experiences.ts +12 -4
- package/src/import/project.ts +11 -3
- package/src/utils/variant-api-adapter.ts +2 -2
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
package/lib/export/projects.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -110,8 +110,12 @@ class Experiences extends utils_1.PersonalizationAdapter {
|
|
|
110
110
|
const jobRes = yield this.validateVariantGroupAndVariantsCreated();
|
|
111
111
|
utils_1.fsUtil.writeFile(this.cmsVariantPath, this.cmsVariants);
|
|
112
112
|
utils_1.fsUtil.writeFile(this.cmsVariantGroupPath, this.cmsVariantGroups);
|
|
113
|
-
if (jobRes)
|
|
113
|
+
if (jobRes) {
|
|
114
114
|
this.log(this.config, this.$t(this.messages.CREATE_SUCCESS, { module: 'Variant & Variant groups' }), 'info');
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
this.personalizeConfig.importData = false;
|
|
118
|
+
}
|
|
115
119
|
if (this.personalizeConfig.importData) {
|
|
116
120
|
this.log(this.config, this.messages.UPDATING_CT_IN_EXP, 'info');
|
|
117
121
|
yield this.attachCTsInExperience();
|
|
@@ -193,11 +197,12 @@ class Experiences extends utils_1.PersonalizationAdapter {
|
|
|
193
197
|
var _a;
|
|
194
198
|
try {
|
|
195
199
|
const promises = this.pendingVariantAndVariantGrpForExperience.map((expUid) => __awaiter(this, void 0, void 0, function* () {
|
|
196
|
-
var _a, _b, _c, _d;
|
|
200
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
197
201
|
const expRes = yield this.getExperience(expUid);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
this.
|
|
202
|
+
const variants = (_b = (_a = expRes === null || expRes === void 0 ? void 0 : expRes._cms) === null || _a === void 0 ? void 0 : _a.variants) !== null && _b !== void 0 ? _b : {};
|
|
203
|
+
if ((expRes === null || expRes === void 0 ? void 0 : expRes._cms) && ((_c = expRes === null || expRes === void 0 ? void 0 : expRes._cms) === null || _c === void 0 ? void 0 : _c.variantGroup) && Object.keys(variants).length > 0) {
|
|
204
|
+
this.cmsVariants[expUid] = (_e = (_d = expRes._cms) === null || _d === void 0 ? void 0 : _d.variants) !== null && _e !== void 0 ? _e : {};
|
|
205
|
+
this.cmsVariantGroups[expUid] = (_g = (_f = expRes._cms) === null || _f === void 0 ? void 0 : _f.variantGroup) !== null && _g !== void 0 ? _g : {};
|
|
201
206
|
return expUid; // Return the expUid for filtering later
|
|
202
207
|
}
|
|
203
208
|
}));
|
package/lib/import/project.js
CHANGED
|
@@ -49,7 +49,8 @@ class Project extends utils_1.PersonalizationAdapter {
|
|
|
49
49
|
description: project.description,
|
|
50
50
|
connectedStackApiKey: this.config.apiKey,
|
|
51
51
|
}).catch((error) => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
if (error.includes('personalization.PROJECTS.DUPLICATE_NAME') ||
|
|
52
|
+
if (error.includes('personalization.PROJECTS.DUPLICATE_NAME') ||
|
|
53
|
+
error.includes('personalize.PROJECTS.DUPLICATE_NAME')) {
|
|
53
54
|
const projectName = yield (0, utils_1.askProjectName)('Copy Of ' + (newName || project.name));
|
|
54
55
|
return yield createProject(projectName);
|
|
55
56
|
}
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
package/lib/utils/logger.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
@@ -162,7 +162,7 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
|
|
|
162
162
|
try {
|
|
163
163
|
this.apiClient.headers({ api_version: undefined });
|
|
164
164
|
const res = yield this.apiClient.put(endpoint, { entry: input });
|
|
165
|
-
const data = this.handleVariantAPIRes(res);
|
|
165
|
+
const data = yield this.handleVariantAPIRes(res);
|
|
166
166
|
if (res.status >= 200 && res.status < 300) {
|
|
167
167
|
onSuccess(data);
|
|
168
168
|
}
|
|
@@ -197,7 +197,7 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
|
|
|
197
197
|
try {
|
|
198
198
|
this.apiClient.headers({ api_version: 3.2 });
|
|
199
199
|
const res = yield this.apiClient.post(endpoint, input);
|
|
200
|
-
const data = this.handleVariantAPIRes(res);
|
|
200
|
+
const data = yield this.handleVariantAPIRes(res);
|
|
201
201
|
if (res.status >= 200 && res.status < 300) {
|
|
202
202
|
onSuccess(data);
|
|
203
203
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-variants",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "Variants plugin",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -18,21 +18,21 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@contentstack/cli-dev-dependencies": "^1.2.4",
|
|
21
|
-
"@oclif/test": "^
|
|
22
|
-
"@types/chai": "^4.3.
|
|
23
|
-
"@types/node": "^20.
|
|
24
|
-
"chai": "^4.
|
|
25
|
-
"mocha": "^10.
|
|
21
|
+
"@oclif/test": "^4.1.3",
|
|
22
|
+
"@types/chai": "^4.3.20",
|
|
23
|
+
"@types/node": "^20.17.9",
|
|
24
|
+
"chai": "^4.5.0",
|
|
25
|
+
"mocha": "^10.8.2",
|
|
26
26
|
"nyc": "^15.1.0",
|
|
27
|
-
"sinon": "^
|
|
27
|
+
"sinon": "^19.0.2",
|
|
28
28
|
"ts-node": "^10.9.2",
|
|
29
|
-
"tslib": "^2.
|
|
30
|
-
"typescript": "^5.
|
|
29
|
+
"tslib": "^2.8.1",
|
|
30
|
+
"typescript": "^5.6.3"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@contentstack/cli-utilities": "^1.8.0",
|
|
34
34
|
"lodash": "^4.17.21",
|
|
35
35
|
"mkdirp": "^1.0.4",
|
|
36
|
-
"winston": "^3.
|
|
36
|
+
"winston": "^3.17.0"
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -45,7 +45,7 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
|
|
|
45
45
|
const conf: APIConfig = {
|
|
46
46
|
config,
|
|
47
47
|
baseURL: config.modules.personalize.baseURL[config.region.name],
|
|
48
|
-
headers: { 'X-Project-Uid': config.modules.personalize.project_id},
|
|
48
|
+
headers: { 'X-Project-Uid': config.modules.personalize.project_id },
|
|
49
49
|
cmaConfig: {
|
|
50
50
|
baseURL: config.region.cma + `/v3`,
|
|
51
51
|
headers: { api_key: config.apiKey },
|
|
@@ -141,8 +141,11 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
|
|
|
141
141
|
const jobRes = await this.validateVariantGroupAndVariantsCreated();
|
|
142
142
|
fsUtil.writeFile(this.cmsVariantPath, this.cmsVariants);
|
|
143
143
|
fsUtil.writeFile(this.cmsVariantGroupPath, this.cmsVariantGroups);
|
|
144
|
-
if (jobRes)
|
|
144
|
+
if (jobRes) {
|
|
145
145
|
this.log(this.config, this.$t(this.messages.CREATE_SUCCESS, { module: 'Variant & Variant groups' }), 'info');
|
|
146
|
+
} else {
|
|
147
|
+
this.personalizeConfig.importData = false;
|
|
148
|
+
}
|
|
146
149
|
|
|
147
150
|
if (this.personalizeConfig.importData) {
|
|
148
151
|
this.log(this.config, this.messages.UPDATING_CT_IN_EXP, 'info');
|
|
@@ -162,7 +165,11 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
|
|
|
162
165
|
* function import experience versions from a JSON file and creates them in the project.
|
|
163
166
|
*/
|
|
164
167
|
async importExperienceVersions(experience: ExperienceStruct, oldExperienceUid: string) {
|
|
165
|
-
const versionsPath = resolve(
|
|
168
|
+
const versionsPath = resolve(
|
|
169
|
+
sanitizePath(this.experiencesDirPath),
|
|
170
|
+
'versions',
|
|
171
|
+
`${sanitizePath(oldExperienceUid)}.json`,
|
|
172
|
+
);
|
|
166
173
|
|
|
167
174
|
if (!existsSync(versionsPath)) {
|
|
168
175
|
return;
|
|
@@ -231,7 +238,8 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
|
|
|
231
238
|
try {
|
|
232
239
|
const promises = this.pendingVariantAndVariantGrpForExperience.map(async (expUid) => {
|
|
233
240
|
const expRes = await this.getExperience(expUid);
|
|
234
|
-
|
|
241
|
+
const variants = expRes?._cms?.variants ?? {};
|
|
242
|
+
if (expRes?._cms && expRes?._cms?.variantGroup && Object.keys(variants).length > 0) {
|
|
235
243
|
this.cmsVariants[expUid] = expRes._cms?.variants ?? {};
|
|
236
244
|
this.cmsVariantGroups[expUid] = expRes._cms?.variantGroup ?? {};
|
|
237
245
|
return expUid; // Return the expUid for filtering later
|
package/src/import/project.ts
CHANGED
|
@@ -28,8 +28,13 @@ export default class Project extends PersonalizationAdapter<ImportConfig> {
|
|
|
28
28
|
async import() {
|
|
29
29
|
const personalize = this.config.modules.personalize;
|
|
30
30
|
const { dirName, fileName } = personalize.projects;
|
|
31
|
-
const projectPath = join(
|
|
32
|
-
|
|
31
|
+
const projectPath = join(
|
|
32
|
+
sanitizePath(this.config.data),
|
|
33
|
+
sanitizePath(personalize.dirName),
|
|
34
|
+
sanitizePath(dirName),
|
|
35
|
+
sanitizePath(fileName),
|
|
36
|
+
);
|
|
37
|
+
|
|
33
38
|
if (existsSync(projectPath)) {
|
|
34
39
|
const projects = JSON.parse(readFileSync(projectPath, 'utf8')) as CreateProjectInput[];
|
|
35
40
|
|
|
@@ -46,7 +51,10 @@ export default class Project extends PersonalizationAdapter<ImportConfig> {
|
|
|
46
51
|
description: project.description,
|
|
47
52
|
connectedStackApiKey: this.config.apiKey,
|
|
48
53
|
}).catch(async (error) => {
|
|
49
|
-
if (
|
|
54
|
+
if (
|
|
55
|
+
error.includes('personalization.PROJECTS.DUPLICATE_NAME') ||
|
|
56
|
+
error.includes('personalize.PROJECTS.DUPLICATE_NAME')
|
|
57
|
+
) {
|
|
50
58
|
const projectName = await askProjectName('Copy Of ' + (newName || project.name));
|
|
51
59
|
return await createProject(projectName);
|
|
52
60
|
}
|
|
@@ -197,7 +197,7 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
|
|
|
197
197
|
try {
|
|
198
198
|
this.apiClient.headers({ api_version: undefined });
|
|
199
199
|
const res = await this.apiClient.put<VariantEntryStruct>(endpoint, { entry: input });
|
|
200
|
-
const data = this.handleVariantAPIRes(res);
|
|
200
|
+
const data = await this.handleVariantAPIRes(res);
|
|
201
201
|
|
|
202
202
|
if (res.status >= 200 && res.status < 300) {
|
|
203
203
|
onSuccess(data);
|
|
@@ -238,7 +238,7 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
|
|
|
238
238
|
try {
|
|
239
239
|
this.apiClient.headers({ api_version: 3.2 });
|
|
240
240
|
const res = await this.apiClient.post<any>(endpoint, input);
|
|
241
|
-
const data = this.handleVariantAPIRes(res);
|
|
241
|
+
const data = await this.handleVariantAPIRes(res);
|
|
242
242
|
|
|
243
243
|
if (res.status >= 200 && res.status < 300) {
|
|
244
244
|
onSuccess(data);
|