@contentstack/cli-variants 1.0.0 → 1.1.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.
Files changed (46) hide show
  1. package/lib/export/attributes.js +2 -1
  2. package/lib/export/audiences.js +2 -1
  3. package/lib/export/events.js +2 -1
  4. package/lib/export/experiences.js +3 -2
  5. package/lib/export/projects.js +2 -1
  6. package/lib/export/variant-entries.js +1 -1
  7. package/lib/import/attribute.js +2 -1
  8. package/lib/import/audiences.js +2 -1
  9. package/lib/import/events.js +2 -1
  10. package/lib/import/experiences.js +3 -2
  11. package/lib/import/project.js +3 -2
  12. package/lib/import/variant-entries.js +18 -12
  13. package/lib/messages/index.d.ts +1 -0
  14. package/lib/messages/index.js +2 -1
  15. package/lib/types/personalization-api-adapter.d.ts +1 -1
  16. package/lib/types/variant-api-adapter.d.ts +3 -2
  17. package/lib/types/variant-entry.d.ts +0 -1
  18. package/lib/utils/attributes-helper.js +2 -2
  19. package/lib/utils/error-helper.js +6 -6
  20. package/lib/utils/logger.js +5 -4
  21. package/lib/utils/personalization-api-adapter.d.ts +2 -1
  22. package/lib/utils/personalization-api-adapter.js +54 -26
  23. package/lib/utils/variant-api-adapter.d.ts +5 -4
  24. package/lib/utils/variant-api-adapter.js +28 -10
  25. package/package.json +2 -2
  26. package/src/export/attributes.ts +6 -2
  27. package/src/export/audiences.ts +2 -1
  28. package/src/export/events.ts +2 -1
  29. package/src/export/experiences.ts +3 -2
  30. package/src/export/projects.ts +2 -1
  31. package/src/export/variant-entries.ts +1 -2
  32. package/src/import/attribute.ts +2 -2
  33. package/src/import/audiences.ts +2 -2
  34. package/src/import/events.ts +2 -2
  35. package/src/import/experiences.ts +3 -3
  36. package/src/import/project.ts +4 -4
  37. package/src/import/variant-entries.ts +23 -15
  38. package/src/messages/index.ts +2 -1
  39. package/src/types/personalization-api-adapter.ts +1 -1
  40. package/src/types/variant-api-adapter.ts +3 -1
  41. package/src/types/variant-entry.ts +0 -1
  42. package/src/utils/attributes-helper.ts +2 -2
  43. package/src/utils/error-helper.ts +6 -6
  44. package/src/utils/logger.ts +5 -4
  45. package/src/utils/personalization-api-adapter.ts +45 -22
  46. package/src/utils/variant-api-adapter.ts +19 -5
@@ -22,16 +22,37 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.PersonalizationAdapter = void 0;
24
24
  const adapter_helper_1 = require("./adapter-helper");
25
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
25
26
  const error_helper_1 = require("./error-helper");
26
27
  class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
27
28
  constructor(options) {
28
29
  super(options);
29
30
  }
31
+ init() {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ var _a, _b;
34
+ yield cli_utilities_1.authenticationHandler.getAuthDetails();
35
+ const token = cli_utilities_1.authenticationHandler.accessToken;
36
+ if (cli_utilities_1.authenticationHandler.isOauthEnabled) {
37
+ this.apiClient.headers({ authorization: token });
38
+ if (this.adapterConfig.cmaConfig) {
39
+ (_a = this.cmaAPIClient) === null || _a === void 0 ? void 0 : _a.headers({ authorization: token });
40
+ }
41
+ }
42
+ else {
43
+ this.apiClient.headers({ authtoken: token });
44
+ if (this.adapterConfig.cmaConfig) {
45
+ (_b = this.cmaAPIClient) === null || _b === void 0 ? void 0 : _b.headers({ authtoken: token });
46
+ }
47
+ }
48
+ });
49
+ }
30
50
  projects(options) {
31
51
  return __awaiter(this, void 0, void 0, function* () {
52
+ yield this.init();
32
53
  const getProjectEndPoint = `/projects?connectedStackApiKey=${options.connectedStackApiKey}`;
33
54
  const data = yield this.apiClient.get(getProjectEndPoint);
34
- return this.handleVariantAPIRes(data);
55
+ return (yield this.handleVariantAPIRes(data));
35
56
  });
36
57
  }
37
58
  /**
@@ -47,7 +68,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
47
68
  createProject(project) {
48
69
  return __awaiter(this, void 0, void 0, function* () {
49
70
  const data = yield this.apiClient.post('/projects', project);
50
- return this.handleVariantAPIRes(data);
71
+ return (yield this.handleVariantAPIRes(data));
51
72
  });
52
73
  }
53
74
  /**
@@ -62,35 +83,35 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
62
83
  createAttribute(attribute) {
63
84
  return __awaiter(this, void 0, void 0, function* () {
64
85
  const data = yield this.apiClient.post('/attributes', attribute);
65
- return this.handleVariantAPIRes(data);
86
+ return (yield this.handleVariantAPIRes(data));
66
87
  });
67
88
  }
68
89
  getExperiences() {
69
90
  return __awaiter(this, void 0, void 0, function* () {
70
91
  const getExperiencesEndPoint = `/experiences`;
71
92
  const data = yield this.apiClient.get(getExperiencesEndPoint);
72
- return this.handleVariantAPIRes(data);
93
+ return (yield this.handleVariantAPIRes(data));
73
94
  });
74
95
  }
75
96
  getExperience(experienceUid) {
76
97
  return __awaiter(this, void 0, void 0, function* () {
77
98
  const getExperiencesEndPoint = `/experiences/${experienceUid}`;
78
99
  const data = yield this.apiClient.get(getExperiencesEndPoint);
79
- return this.handleVariantAPIRes(data);
100
+ return (yield this.handleVariantAPIRes(data));
80
101
  });
81
102
  }
82
103
  getExperienceVersions(experienceUid) {
83
104
  return __awaiter(this, void 0, void 0, function* () {
84
105
  const getExperiencesVersionsEndPoint = `/experiences/${experienceUid}/versions`;
85
106
  const data = yield this.apiClient.get(getExperiencesVersionsEndPoint);
86
- return this.handleVariantAPIRes(data);
107
+ return (yield this.handleVariantAPIRes(data));
87
108
  });
88
109
  }
89
110
  createExperienceVersion(experienceUid, input) {
90
111
  return __awaiter(this, void 0, void 0, function* () {
91
112
  const createExperiencesVersionsEndPoint = `/experiences/${experienceUid}/versions`;
92
113
  const data = yield this.apiClient.post(createExperiencesVersionsEndPoint, input);
93
- return this.handleVariantAPIRes(data);
114
+ return (yield this.handleVariantAPIRes(data));
94
115
  });
95
116
  }
96
117
  updateExperienceVersion(experienceUid, versionId, input) {
@@ -104,7 +125,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
104
125
  }
105
126
  const updateExperiencesVersionsEndPoint = `/experiences/${experienceUid}/versions/${versionId}`;
106
127
  const data = yield this.apiClient.put(updateExperiencesVersionsEndPoint, input);
107
- return this.handleVariantAPIRes(data);
128
+ return (yield this.handleVariantAPIRes(data));
108
129
  });
109
130
  }
110
131
  getVariantGroup(input) {
@@ -114,7 +135,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
114
135
  const data = yield this.cmaAPIClient
115
136
  .queryParams({ experience_uid: input.experienceUid })
116
137
  .get(getVariantGroupEndPoint);
117
- return this.handleVariantAPIRes(data);
138
+ return (yield this.handleVariantAPIRes(data));
118
139
  }
119
140
  });
120
141
  }
@@ -123,32 +144,32 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
123
144
  if (this.cmaAPIClient) {
124
145
  const updateVariantGroupEndPoint = `/variant_groups/${input.uid}`;
125
146
  const data = yield this.cmaAPIClient.put(updateVariantGroupEndPoint, input);
126
- return this.handleVariantAPIRes(data);
147
+ return (yield this.handleVariantAPIRes(data));
127
148
  }
128
149
  });
129
150
  }
130
151
  getEvents() {
131
152
  return __awaiter(this, void 0, void 0, function* () {
132
153
  const data = yield this.apiClient.get('/events');
133
- return this.handleVariantAPIRes(data);
154
+ return (yield this.handleVariantAPIRes(data));
134
155
  });
135
156
  }
136
157
  createEvents(event) {
137
158
  return __awaiter(this, void 0, void 0, function* () {
138
159
  const data = yield this.apiClient.post('/events', event);
139
- return this.handleVariantAPIRes(data);
160
+ return (yield this.handleVariantAPIRes(data));
140
161
  });
141
162
  }
142
163
  getAudiences() {
143
164
  return __awaiter(this, void 0, void 0, function* () {
144
165
  const data = yield this.apiClient.get('/audiences');
145
- return this.handleVariantAPIRes(data);
166
+ return (yield this.handleVariantAPIRes(data));
146
167
  });
147
168
  }
148
169
  getAttributes() {
149
170
  return __awaiter(this, void 0, void 0, function* () {
150
171
  const data = yield this.apiClient.get('/attributes');
151
- return this.handleVariantAPIRes(data);
172
+ return (yield this.handleVariantAPIRes(data));
152
173
  });
153
174
  }
154
175
  /**
@@ -162,7 +183,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
162
183
  createAudience(audience) {
163
184
  return __awaiter(this, void 0, void 0, function* () {
164
185
  const data = yield this.apiClient.post('/audiences', audience);
165
- return this.handleVariantAPIRes(data);
186
+ return (yield this.handleVariantAPIRes(data));
166
187
  });
167
188
  }
168
189
  /**
@@ -176,7 +197,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
176
197
  createExperience(experience) {
177
198
  return __awaiter(this, void 0, void 0, function* () {
178
199
  const data = yield this.apiClient.post('/experiences', experience);
179
- return this.handleVariantAPIRes(data);
200
+ return (yield this.handleVariantAPIRes(data));
180
201
  });
181
202
  }
182
203
  /**
@@ -188,7 +209,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
188
209
  return __awaiter(this, void 0, void 0, function* () {
189
210
  const updateCTInExpEndPoint = `/experiences/${experienceUid}/cms-integration/variant-group`;
190
211
  const data = yield this.apiClient.post(updateCTInExpEndPoint, experience);
191
- return this.handleVariantAPIRes(data);
212
+ return (yield this.handleVariantAPIRes(data));
192
213
  });
193
214
  }
194
215
  /**
@@ -200,7 +221,7 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
200
221
  return __awaiter(this, void 0, void 0, function* () {
201
222
  const getCTFromExpEndPoint = `/experiences/${experienceUid}/cms-integration/variant-group`;
202
223
  const data = yield this.apiClient.get(getCTFromExpEndPoint);
203
- return this.handleVariantAPIRes(data);
224
+ return (yield this.handleVariantAPIRes(data));
204
225
  });
205
226
  }
206
227
  /**
@@ -210,14 +231,21 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
210
231
  * @throws If the API response status is not within the success range, an error message is thrown.
211
232
  */
212
233
  handleVariantAPIRes(res) {
213
- const { status, data } = res;
214
- if (status >= 200 && status < 300) {
215
- return data;
216
- }
217
- const errorMsg = (data === null || data === void 0 ? void 0 : data.errors)
218
- ? (0, error_helper_1.formatErrors)(data.errors)
219
- : (data === null || data === void 0 ? void 0 : data.error) || (data === null || data === void 0 ? void 0 : data.error_message) || (data === null || data === void 0 ? void 0 : data.message) || 'Something went wrong while processing variant entries request!';
220
- throw errorMsg;
234
+ return __awaiter(this, void 0, void 0, function* () {
235
+ const { status, data } = res;
236
+ if (status >= 200 && status < 300) {
237
+ return data;
238
+ }
239
+ // Refresh the access token if it has expired
240
+ yield cli_utilities_1.authenticationHandler.refreshAccessToken(res);
241
+ const errorMsg = (data === null || data === void 0 ? void 0 : data.errors)
242
+ ? (0, error_helper_1.formatErrors)(data.errors)
243
+ : (data === null || data === void 0 ? void 0 : data.error) ||
244
+ (data === null || data === void 0 ? void 0 : data.error_message) ||
245
+ (data === null || data === void 0 ? void 0 : data.message) ||
246
+ 'Something went wrong while processing variant entries request!';
247
+ throw errorMsg;
248
+ });
221
249
  }
222
250
  }
223
251
  exports.PersonalizationAdapter = PersonalizationAdapter;
@@ -5,6 +5,7 @@ import { AdapterHelper } from './adapter-helper';
5
5
  export declare class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implements VariantInterface<C, HttpClient> {
6
6
  baseURL: string;
7
7
  constructor(config: APIConfig, options?: HttpClientOptions);
8
+ init(): Promise<void>;
8
9
  variantEntry(options: VariantOptions): Promise<{
9
10
  entry: {};
10
11
  }>;
@@ -48,10 +49,10 @@ export declare class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> i
48
49
  * @returns The variant API response data.
49
50
  * @throws If the API response status is not within the success range, an error message is thrown.
50
51
  */
51
- handleVariantAPIRes(res: APIResponse): VariantEntryStruct | {
52
+ handleVariantAPIRes(res: APIResponse): Promise<VariantEntryStruct | {
52
53
  entries: VariantEntryStruct[];
53
54
  count: number;
54
- } | string | any;
55
+ } | string | any>;
55
56
  }
56
57
  export declare class VariantManagementSDK<T> extends AdapterHelper<T, ContentstackClient> implements VariantInterface<T, ContentstackClient> {
57
58
  apiClient: ContentstackClient;
@@ -63,10 +64,10 @@ export declare class VariantManagementSDK<T> extends AdapterHelper<T, Contentsta
63
64
  entries: {}[];
64
65
  }>;
65
66
  createVariantEntry(input: CreateVariantEntryDto, options: CreateVariantEntryOptions, apiParams: Record<string, any>): Promise<VariantEntryStruct | string | void>;
66
- handleVariantAPIRes(res: APIResponse): VariantEntryStruct | {
67
+ handleVariantAPIRes(res: APIResponse): Promise<VariantEntryStruct | {
67
68
  entries: VariantEntryStruct[];
68
69
  count: number;
69
- } | string;
70
+ } | string>;
70
71
  constructQuery(query: Record<string, any>): string | void;
71
72
  delay(ms: number): Promise<void>;
72
73
  }
@@ -37,6 +37,18 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
37
37
  this.baseURL = ((_a = config.baseURL) === null || _a === void 0 ? void 0 : _a.includes('http')) ? `${config.baseURL}/v3` : `https://${config.baseURL}/v3`;
38
38
  this.apiClient.baseUrl(this.baseURL);
39
39
  }
40
+ init() {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ yield cli_utilities_1.authenticationHandler.getAuthDetails();
43
+ const token = cli_utilities_1.authenticationHandler.accessToken;
44
+ if (cli_utilities_1.authenticationHandler.isOauthEnabled) {
45
+ this.apiClient.headers({ authorization: token });
46
+ }
47
+ else {
48
+ this.apiClient.headers({ authtoken: token });
49
+ }
50
+ });
51
+ }
40
52
  variantEntry(options) {
41
53
  return __awaiter(this, void 0, void 0, function* () {
42
54
  // TODO single entry variant
@@ -99,7 +111,7 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
99
111
  endpoint = endpoint.concat(query);
100
112
  }
101
113
  const data = yield this.apiClient.get(endpoint);
102
- const response = this.handleVariantAPIRes(data);
114
+ const response = (yield this.handleVariantAPIRes(data));
103
115
  if (callback) {
104
116
  callback(response.entries);
105
117
  }
@@ -205,14 +217,18 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
205
217
  * @throws If the API response status is not within the success range, an error message is thrown.
206
218
  */
207
219
  handleVariantAPIRes(res) {
208
- const { status, data } = res;
209
- if (status >= 200 && status < 300) {
210
- return data;
211
- }
212
- const errorMsg = (data === null || data === void 0 ? void 0 : data.errors)
213
- ? (0, error_helper_1.formatErrors)(data.errors)
214
- : (data === null || data === void 0 ? void 0 : data.error_message) || (data === null || data === void 0 ? void 0 : data.message) || 'Something went wrong while processing entry variant request!';
215
- throw errorMsg;
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ const { status, data } = res;
222
+ if (status >= 200 && status < 300) {
223
+ return data;
224
+ }
225
+ // Refresh the access token if the response status is 401
226
+ yield cli_utilities_1.authenticationHandler.refreshAccessToken(res);
227
+ const errorMsg = (data === null || data === void 0 ? void 0 : data.errors)
228
+ ? (0, error_helper_1.formatErrors)(data.errors)
229
+ : (data === null || data === void 0 ? void 0 : data.error_message) || (data === null || data === void 0 ? void 0 : data.message) || 'Something went wrong while processing entry variant request!';
230
+ throw errorMsg;
231
+ });
216
232
  }
217
233
  }
218
234
  exports.VariantHttpClient = VariantHttpClient;
@@ -239,7 +255,9 @@ class VariantManagementSDK extends adapter_helper_1.AdapterHelper {
239
255
  return Promise.resolve({});
240
256
  }
241
257
  handleVariantAPIRes(res) {
242
- return res.data;
258
+ return __awaiter(this, void 0, void 0, function* () {
259
+ return res.data;
260
+ });
243
261
  }
244
262
  constructQuery(query) { }
245
263
  delay(ms) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-variants",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Variants plugin",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -30,7 +30,7 @@
30
30
  "typescript": "^5.4.2"
31
31
  },
32
32
  "dependencies": {
33
- "@contentstack/cli-utilities": "^1.5.12",
33
+ "@contentstack/cli-utilities": "^1.8.0",
34
34
  "lodash": "^4.17.21",
35
35
  "mkdirp": "^1.0.4",
36
36
  "winston": "^3.7.2"
@@ -14,7 +14,7 @@ export default class ExportAttributes extends PersonalizationAdapter<ExportConfi
14
14
  super({
15
15
  config: exportConfig,
16
16
  baseURL: exportConfig.modules.personalize.baseURL[exportConfig.region.name],
17
- headers: { authtoken: exportConfig.auth_token, 'X-Project-Uid': exportConfig.project_id },
17
+ headers: { 'X-Project-Uid': exportConfig.project_id },
18
18
  });
19
19
  this.personalizeConfig = exportConfig.modules.personalize;
20
20
  this.attributesConfig = exportConfig.modules.attributes;
@@ -30,6 +30,7 @@ export default class ExportAttributes extends PersonalizationAdapter<ExportConfi
30
30
  async start() {
31
31
  try {
32
32
  log(this.exportConfig, 'Starting attributes export', 'info');
33
+ await this.init();
33
34
  await fsUtil.makeDirectory(this.attributesFolderPath);
34
35
  this.attributes = (await this.getAttributes()) as AttributeStruct[];
35
36
 
@@ -37,7 +38,10 @@ export default class ExportAttributes extends PersonalizationAdapter<ExportConfi
37
38
  log(this.exportConfig, 'No Attributes found with the given project!', 'info');
38
39
  } else {
39
40
  this.sanitizeAttribs();
40
- fsUtil.writeFile(pResolve(sanitizePath(this.attributesFolderPath), sanitizePath(this.attributesConfig.fileName)), this.attributes);
41
+ fsUtil.writeFile(
42
+ pResolve(sanitizePath(this.attributesFolderPath), sanitizePath(this.attributesConfig.fileName)),
43
+ this.attributes,
44
+ );
41
45
  log(this.exportConfig, 'All the attributes have been exported successfully!', 'success');
42
46
  }
43
47
  } catch (error) {
@@ -14,7 +14,7 @@ export default class ExportAudiences extends PersonalizationAdapter<ExportConfig
14
14
  super({
15
15
  config: exportConfig,
16
16
  baseURL: exportConfig.modules.personalize.baseURL[exportConfig.region.name],
17
- headers: { authtoken: exportConfig.auth_token, 'X-Project-Uid': exportConfig.project_id },
17
+ headers: { 'X-Project-Uid': exportConfig.project_id },
18
18
  });
19
19
  this.personalizeConfig = exportConfig.modules.personalize;
20
20
  this.audiencesConfig = exportConfig.modules.audiences;
@@ -30,6 +30,7 @@ export default class ExportAudiences extends PersonalizationAdapter<ExportConfig
30
30
  async start() {
31
31
  try {
32
32
  log(this.exportConfig, 'Starting audiences export', 'info');
33
+ await this.init();
33
34
  await fsUtil.makeDirectory(this.audiencesFolderPath);
34
35
  this.audiences = (await this.getAudiences()) as AudienceStruct[];
35
36
 
@@ -14,7 +14,7 @@ export default class ExportEvents extends PersonalizationAdapter<ExportConfig> {
14
14
  super({
15
15
  config: exportConfig,
16
16
  baseURL: exportConfig.modules.personalize.baseURL[exportConfig.region.name],
17
- headers: { authtoken: exportConfig.auth_token, 'X-Project-Uid': exportConfig.project_id },
17
+ headers: { 'X-Project-Uid': exportConfig.project_id },
18
18
  });
19
19
  this.personalizeConfig = exportConfig.modules.personalize;
20
20
  this.eventsConfig = exportConfig.modules.events;
@@ -30,6 +30,7 @@ export default class ExportEvents extends PersonalizationAdapter<ExportConfig> {
30
30
  async start() {
31
31
  try {
32
32
  log(this.exportConfig, 'Starting events export', 'info');
33
+ await this.init();
33
34
  await fsUtil.makeDirectory(this.eventsFolderPath);
34
35
  this.events = (await this.getEvents()) as EventStruct[];
35
36
 
@@ -11,10 +11,10 @@ export default class ExportExperiences extends PersonalizationAdapter<ExportConf
11
11
  super({
12
12
  config: exportConfig,
13
13
  baseURL: exportConfig.modules.personalize.baseURL[exportConfig.region.name],
14
- headers: { authtoken: exportConfig.auth_token, 'X-Project-Uid': exportConfig.project_id },
14
+ headers: { 'X-Project-Uid': exportConfig.project_id },
15
15
  cmaConfig: {
16
16
  baseURL: exportConfig.region.cma + `/v3`,
17
- headers: { authtoken: exportConfig.auth_token, api_key: exportConfig.apiKey },
17
+ headers: { api_key: exportConfig.apiKey },
18
18
  },
19
19
  });
20
20
  this.exportConfig = exportConfig;
@@ -33,6 +33,7 @@ export default class ExportExperiences extends PersonalizationAdapter<ExportConf
33
33
  // loop through experiences and get content types attached to it
34
34
  // write experiences in to a file
35
35
  log(this.exportConfig, 'Starting experiences export', 'info');
36
+ await this.init();
36
37
  await fsUtil.makeDirectory(this.experiencesFolderPath);
37
38
  await fsUtil.makeDirectory(path.resolve(sanitizePath(this.experiencesFolderPath), 'versions'));
38
39
  const experiences: Array<ExperienceStruct> = (await this.getExperiences()) || [];
@@ -11,7 +11,7 @@ export default class ExportProjects extends PersonalizationAdapter<ExportConfig>
11
11
  super({
12
12
  config: exportConfig,
13
13
  baseURL: exportConfig.modules.personalize.baseURL[exportConfig.region.name],
14
- headers: { authtoken: exportConfig.auth_token, organization_uid: exportConfig.org_uid },
14
+ headers: { organization_uid: exportConfig.org_uid },
15
15
  });
16
16
  this.exportConfig = exportConfig;
17
17
  this.personalizeConfig = exportConfig.modules.personalize;
@@ -26,6 +26,7 @@ export default class ExportProjects extends PersonalizationAdapter<ExportConfig>
26
26
  async start() {
27
27
  try {
28
28
  log(this.exportConfig, 'Starting projects export', 'info');
29
+ await this.init();
29
30
  await fsUtil.makeDirectory(this.projectFolderPath);
30
31
  const project = await this.projects({ connectedStackApiKey: this.exportConfig.apiKey });
31
32
  if (!project || project?.length < 1) {
@@ -19,7 +19,6 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Exp
19
19
  headers: {
20
20
  api_key: config.apiKey,
21
21
  branch: config.branchName,
22
- authtoken: config.auth_token,
23
22
  organization_uid: config.org_uid,
24
23
  'X-Project-Uid': config.project_id,
25
24
  },
@@ -36,7 +35,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Exp
36
35
  async exportVariantEntry(options: { locale: string; contentTypeUid: string; entries: Record<string, any>[] }) {
37
36
  const variantEntry = this.config.modules.variantEntry;
38
37
  const { entries, locale, contentTypeUid: content_type_uid } = options;
39
-
38
+ await this.variantInstance.init();
40
39
  for (let index = 0; index < entries.length; index++) {
41
40
  const entry = entries[index];
42
41
  const variantEntryBasePath = join(sanitizePath(this.entriesDirPath), sanitizePath(content_type_uid), sanitizePath(locale), sanitizePath(variantEntry.dirName), sanitizePath(entry.uid));
@@ -16,7 +16,7 @@ export default class Attribute extends PersonalizationAdapter<ImportConfig> {
16
16
  const conf: APIConfig = {
17
17
  config,
18
18
  baseURL: config.modules.personalize.baseURL[config.region.name],
19
- headers: { 'X-Project-Uid': config.modules.personalize.project_id, authtoken: config.auth_token },
19
+ headers: { 'X-Project-Uid': config.modules.personalize.project_id },
20
20
  };
21
21
  super(Object.assign(config, conf));
22
22
  this.personalizeConfig = this.config.modules.personalize;
@@ -36,7 +36,7 @@ export default class Attribute extends PersonalizationAdapter<ImportConfig> {
36
36
  */
37
37
  async import() {
38
38
  this.log(this.config, this.$t(this.messages.IMPORT_MSG, { module: 'Attributes' }), 'info');
39
-
39
+ await this.init();
40
40
  await fsUtil.makeDirectory(this.attrMapperDirPath);
41
41
  const { dirName, fileName } = this.attributeConfig;
42
42
  const attributesPath = resolve(
@@ -18,7 +18,7 @@ export default class Audiences extends PersonalizationAdapter<ImportConfig> {
18
18
  const conf: APIConfig = {
19
19
  config,
20
20
  baseURL: config.modules.personalize.baseURL[config.region.name],
21
- headers: { 'X-Project-Uid': config.modules.personalize.project_id, authtoken: config.auth_token },
21
+ headers: { 'X-Project-Uid': config.modules.personalize.project_id },
22
22
  };
23
23
  super(Object.assign(config, conf));
24
24
  this.personalizeConfig = this.config.modules.personalize;
@@ -44,7 +44,7 @@ export default class Audiences extends PersonalizationAdapter<ImportConfig> {
44
44
  */
45
45
  async import() {
46
46
  this.log(this.config, this.$t(this.messages.IMPORT_MSG, { module: 'Audiences' }), 'info');
47
-
47
+ await this.init();
48
48
  await fsUtil.makeDirectory(this.audienceMapperDirPath);
49
49
  const { dirName, fileName } = this.audienceConfig;
50
50
  const audiencesPath = resolve(
@@ -16,7 +16,7 @@ export default class Events extends PersonalizationAdapter<ImportConfig> {
16
16
  const conf: APIConfig = {
17
17
  config,
18
18
  baseURL: config.modules.personalize.baseURL[config.region.name],
19
- headers: { 'X-Project-Uid': config.modules.personalize.project_id, authtoken: config.auth_token },
19
+ headers: { 'X-Project-Uid': config.modules.personalize.project_id },
20
20
  };
21
21
  super(Object.assign(config, conf));
22
22
  this.personalizeConfig = this.config.modules.personalize;
@@ -36,7 +36,7 @@ export default class Events extends PersonalizationAdapter<ImportConfig> {
36
36
  */
37
37
  async import() {
38
38
  this.log(this.config, this.$t(this.messages.IMPORT_MSG, { module: 'Events' }), 'info');
39
-
39
+ await this.init();
40
40
  await fsUtil.makeDirectory(this.eventMapperDirPath);
41
41
  const { dirName, fileName } = this.eventsConfig;
42
42
  const eventsPath = resolve(
@@ -45,10 +45,10 @@ 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, authtoken: config.auth_token },
48
+ headers: { 'X-Project-Uid': config.modules.personalize.project_id},
49
49
  cmaConfig: {
50
50
  baseURL: config.region.cma + `/v3`,
51
- headers: { authtoken: config.auth_token, api_key: config.apiKey },
51
+ headers: { api_key: config.apiKey },
52
52
  },
53
53
  };
54
54
  super(Object.assign(config, conf));
@@ -107,7 +107,7 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
107
107
  */
108
108
  async import() {
109
109
  this.log(this.config, this.$t(this.messages.IMPORT_MSG, { module: 'Experiences' }), 'info');
110
-
110
+ await this.init();
111
111
  await fsUtil.makeDirectory(this.expMapperDirPath);
112
112
 
113
113
  if (existsSync(this.experiencesPath)) {
@@ -10,7 +10,7 @@ export default class Project extends PersonalizationAdapter<ImportConfig> {
10
10
  const conf: APIConfig = {
11
11
  config,
12
12
  baseURL: config.modules.personalize.baseURL[config.region.name],
13
- headers: { organization_uid: config.org_uid, authtoken: config.auth_token },
13
+ headers: { organization_uid: config.org_uid },
14
14
  };
15
15
  super(Object.assign(config, conf));
16
16
  this.projectMapperFolderPath = pResolve(
@@ -29,7 +29,7 @@ export default class Project extends PersonalizationAdapter<ImportConfig> {
29
29
  const personalize = this.config.modules.personalize;
30
30
  const { dirName, fileName } = personalize.projects;
31
31
  const projectPath = join(sanitizePath(this.config.data), sanitizePath(personalize.dirName), sanitizePath(dirName), sanitizePath(fileName));
32
-
32
+
33
33
  if (existsSync(projectPath)) {
34
34
  const projects = JSON.parse(readFileSync(projectPath, 'utf8')) as CreateProjectInput[];
35
35
 
@@ -38,7 +38,7 @@ export default class Project extends PersonalizationAdapter<ImportConfig> {
38
38
  this.log(this.config, 'No project found!', 'info');
39
39
  return;
40
40
  }
41
-
41
+ await this.init();
42
42
  for (const project of projects) {
43
43
  const createProject = async (newName: void | string): Promise<ProjectStruct> => {
44
44
  return await this.createProject({
@@ -46,7 +46,7 @@ export default class Project extends PersonalizationAdapter<ImportConfig> {
46
46
  description: project.description,
47
47
  connectedStackApiKey: this.config.apiKey,
48
48
  }).catch(async (error) => {
49
- if (error === 'personalization.PROJECTS.DUPLICATE_NAME' || error === 'personalize.PROJECTS.DUPLICATE_NAME') {
49
+ if (error.includes('personalization.PROJECTS.DUPLICATE_NAME') || error.includes('personalize.PROJECTS.DUPLICATE_NAME')) {
50
50
  const projectName = await askProjectName('Copy Of ' + (newName || project.name));
51
51
  return await createProject(projectName);
52
52
  }