@contentstack/cli-variants 1.2.1 → 1.3.0

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 +27 -10
  2. package/lib/export/audiences.js +28 -10
  3. package/lib/export/events.js +28 -10
  4. package/lib/export/experiences.js +48 -13
  5. package/lib/export/projects.js +24 -6
  6. package/lib/export/variant-entries.js +25 -4
  7. package/lib/import/attribute.d.ts +2 -3
  8. package/lib/import/attribute.js +16 -8
  9. package/lib/import/audiences.d.ts +2 -3
  10. package/lib/import/audiences.js +21 -8
  11. package/lib/import/events.d.ts +3 -4
  12. package/lib/import/events.js +16 -9
  13. package/lib/import/experiences.d.ts +2 -3
  14. package/lib/import/experiences.js +60 -17
  15. package/lib/import/project.d.ts +2 -3
  16. package/lib/import/project.js +11 -6
  17. package/lib/import/variant-entries.js +62 -25
  18. package/lib/types/export-config.d.ts +2 -1
  19. package/lib/types/utils.d.ts +11 -0
  20. package/lib/utils/attributes-helper.js +17 -1
  21. package/lib/utils/audiences-helper.js +37 -6
  22. package/lib/utils/events-helper.js +17 -4
  23. package/lib/utils/personalization-api-adapter.d.ts +2 -1
  24. package/lib/utils/personalization-api-adapter.js +119 -27
  25. package/lib/utils/variant-api-adapter.d.ts +4 -1
  26. package/lib/utils/variant-api-adapter.js +91 -17
  27. package/package.json +8 -5
  28. package/src/export/attributes.ts +34 -10
  29. package/src/export/audiences.ts +35 -7
  30. package/src/export/events.ts +35 -7
  31. package/src/export/experiences.ts +74 -24
  32. package/src/export/projects.ts +31 -7
  33. package/src/export/variant-entries.ts +47 -12
  34. package/src/import/attribute.ts +22 -9
  35. package/src/import/audiences.ts +28 -10
  36. package/src/import/events.ts +21 -10
  37. package/src/import/experiences.ts +74 -20
  38. package/src/import/project.ts +22 -8
  39. package/src/import/variant-entries.ts +116 -40
  40. package/src/types/export-config.ts +2 -1
  41. package/src/types/utils.ts +12 -0
  42. package/src/utils/attributes-helper.ts +21 -2
  43. package/src/utils/audiences-helper.ts +41 -1
  44. package/src/utils/events-helper.ts +19 -1
  45. package/src/utils/personalization-api-adapter.ts +95 -19
  46. package/src/utils/variant-api-adapter.ts +79 -8
@@ -26,33 +26,47 @@ const cli_utilities_1 = require("@contentstack/cli-utilities");
26
26
  const error_helper_1 = require("./error-helper");
27
27
  class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
28
28
  constructor(options) {
29
+ var _a;
29
30
  super(options);
31
+ cli_utilities_1.log.debug('PersonalizationAdapter initialized', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
30
32
  }
31
33
  init() {
32
34
  return __awaiter(this, void 0, void 0, function* () {
33
- var _a, _b;
35
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
36
+ cli_utilities_1.log.debug('Initializing personalization adapter...', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
34
37
  yield cli_utilities_1.authenticationHandler.getAuthDetails();
35
38
  const token = cli_utilities_1.authenticationHandler.accessToken;
39
+ cli_utilities_1.log.debug(`Authentication type: ${cli_utilities_1.authenticationHandler.isOauthEnabled ? 'OAuth' : 'Token'}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
36
40
  if (cli_utilities_1.authenticationHandler.isOauthEnabled) {
41
+ cli_utilities_1.log.debug('Setting OAuth authorization header', (_c = this.exportConfig) === null || _c === void 0 ? void 0 : _c.context);
37
42
  this.apiClient.headers({ authorization: token });
38
43
  if (this.adapterConfig.cmaConfig) {
39
- (_a = this.cmaAPIClient) === null || _a === void 0 ? void 0 : _a.headers({ authorization: token });
44
+ cli_utilities_1.log.debug('Setting OAuth authorization header for CMA client', (_d = this.exportConfig) === null || _d === void 0 ? void 0 : _d.context);
45
+ (_e = this.cmaAPIClient) === null || _e === void 0 ? void 0 : _e.headers({ authorization: token });
40
46
  }
41
47
  }
42
48
  else {
49
+ cli_utilities_1.log.debug('Setting authtoken header', (_f = this.exportConfig) === null || _f === void 0 ? void 0 : _f.context);
43
50
  this.apiClient.headers({ authtoken: token });
44
51
  if (this.adapterConfig.cmaConfig) {
45
- (_b = this.cmaAPIClient) === null || _b === void 0 ? void 0 : _b.headers({ authtoken: token });
52
+ cli_utilities_1.log.debug('Setting authtoken header for CMA client', (_g = this.exportConfig) === null || _g === void 0 ? void 0 : _g.context);
53
+ (_h = this.cmaAPIClient) === null || _h === void 0 ? void 0 : _h.headers({ authtoken: token });
46
54
  }
47
55
  }
56
+ cli_utilities_1.log.debug('Personalization adapter initialization completed', (_j = this.exportConfig) === null || _j === void 0 ? void 0 : _j.context);
48
57
  });
49
58
  }
50
59
  projects(options) {
51
60
  return __awaiter(this, void 0, void 0, function* () {
61
+ var _a, _b, _c;
62
+ cli_utilities_1.log.debug(`Fetching projects for stack API key: ${options.connectedStackApiKey}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
52
63
  yield this.init();
53
64
  const getProjectEndPoint = `/projects?connectedStackApiKey=${options.connectedStackApiKey}`;
65
+ cli_utilities_1.log.debug(`Making API call to: ${getProjectEndPoint}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
54
66
  const data = yield this.apiClient.get(getProjectEndPoint);
55
- return (yield this.handleVariantAPIRes(data));
67
+ const result = (yield this.handleVariantAPIRes(data));
68
+ cli_utilities_1.log.debug(`Fetched ${(result === null || result === void 0 ? void 0 : result.length) || 0} projects`, (_c = this.exportConfig) === null || _c === void 0 ? void 0 : _c.context);
69
+ return result;
56
70
  });
57
71
  }
58
72
  /**
@@ -67,8 +81,12 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
67
81
  */
68
82
  createProject(project) {
69
83
  return __awaiter(this, void 0, void 0, function* () {
84
+ var _a, _b;
85
+ cli_utilities_1.log.debug(`Creating project: ${project.name}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
70
86
  const data = yield this.apiClient.post('/projects', project);
71
- return (yield this.handleVariantAPIRes(data));
87
+ const result = (yield this.handleVariantAPIRes(data));
88
+ cli_utilities_1.log.debug(`Project created successfully: ${result.uid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
89
+ return result;
72
90
  });
73
91
  }
74
92
  /**
@@ -82,102 +100,155 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
82
100
  */
83
101
  createAttribute(attribute) {
84
102
  return __awaiter(this, void 0, void 0, function* () {
103
+ var _a, _b;
104
+ cli_utilities_1.log.debug(`Creating attribute: ${attribute.name}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
85
105
  const data = yield this.apiClient.post('/attributes', attribute);
86
- return (yield this.handleVariantAPIRes(data));
106
+ const result = (yield this.handleVariantAPIRes(data));
107
+ cli_utilities_1.log.debug(`Attribute created successfully: ${result.uid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
108
+ return result;
87
109
  });
88
110
  }
89
111
  getExperiences() {
90
112
  return __awaiter(this, void 0, void 0, function* () {
113
+ var _a, _b;
114
+ cli_utilities_1.log.debug('Fetching experiences from personalization API', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
91
115
  const getExperiencesEndPoint = `/experiences`;
92
116
  const data = yield this.apiClient.get(getExperiencesEndPoint);
93
- return (yield this.handleVariantAPIRes(data));
117
+ const result = (yield this.handleVariantAPIRes(data));
118
+ cli_utilities_1.log.debug(`Fetched ${(result === null || result === void 0 ? void 0 : result.length) || 0} experiences`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
119
+ return result;
94
120
  });
95
121
  }
96
122
  getExperience(experienceUid) {
97
123
  return __awaiter(this, void 0, void 0, function* () {
98
- var _a, _b, _c, _d;
124
+ var _a, _b, _c, _d, _e, _f;
125
+ cli_utilities_1.log.debug(`Fetching experience: ${experienceUid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
99
126
  const getExperiencesEndPoint = `/experiences/${experienceUid}`;
100
- if ((_b = (_a = this.apiClient).requestConfig) === null || _b === void 0 ? void 0 : _b.call(_a).data) {
101
- (_d = (_c = this.apiClient).requestConfig) === null || _d === void 0 ? true : delete _d.call(_c).data; // explicitly prevent any accidental body
127
+ if ((_c = (_b = this.apiClient).requestConfig) === null || _c === void 0 ? void 0 : _c.call(_b).data) {
128
+ (_e = (_d = this.apiClient).requestConfig) === null || _e === void 0 ? true : delete _e.call(_d).data; // explicitly prevent any accidental body
102
129
  }
103
130
  const data = yield this.apiClient.get(getExperiencesEndPoint);
104
- return (yield this.handleVariantAPIRes(data));
131
+ const result = (yield this.handleVariantAPIRes(data));
132
+ cli_utilities_1.log.debug(`Experience fetched successfully: ${result === null || result === void 0 ? void 0 : result.uid}`, (_f = this.exportConfig) === null || _f === void 0 ? void 0 : _f.context);
133
+ return result;
105
134
  });
106
135
  }
107
136
  getExperienceVersions(experienceUid) {
108
137
  return __awaiter(this, void 0, void 0, function* () {
109
- var _a, _b, _c, _d;
138
+ var _a, _b, _c, _d, _e, _f;
139
+ cli_utilities_1.log.debug(`Fetching versions for experience: ${experienceUid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
110
140
  const getExperiencesVersionsEndPoint = `/experiences/${experienceUid}/versions`;
111
- if ((_b = (_a = this.apiClient).requestConfig) === null || _b === void 0 ? void 0 : _b.call(_a).data) {
112
- (_d = (_c = this.apiClient).requestConfig) === null || _d === void 0 ? true : delete _d.call(_c).data; // explicitly prevent any accidental body
141
+ if ((_c = (_b = this.apiClient).requestConfig) === null || _c === void 0 ? void 0 : _c.call(_b).data) {
142
+ (_e = (_d = this.apiClient).requestConfig) === null || _e === void 0 ? true : delete _e.call(_d).data; // explicitly prevent any accidental body
113
143
  }
114
144
  const data = yield this.apiClient.get(getExperiencesVersionsEndPoint);
115
- return (yield this.handleVariantAPIRes(data));
145
+ const result = (yield this.handleVariantAPIRes(data));
146
+ cli_utilities_1.log.debug(`Experience versions fetched successfully for: ${experienceUid}`, (_f = this.exportConfig) === null || _f === void 0 ? void 0 : _f.context);
147
+ return result;
116
148
  });
117
149
  }
118
150
  createExperienceVersion(experienceUid, input) {
119
151
  return __awaiter(this, void 0, void 0, function* () {
152
+ var _a, _b;
153
+ cli_utilities_1.log.debug(`Creating experience version for: ${experienceUid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
120
154
  const createExperiencesVersionsEndPoint = `/experiences/${experienceUid}/versions`;
121
155
  const data = yield this.apiClient.post(createExperiencesVersionsEndPoint, input);
122
- return (yield this.handleVariantAPIRes(data));
156
+ const result = (yield this.handleVariantAPIRes(data));
157
+ cli_utilities_1.log.debug(`Experience version created successfully for: ${experienceUid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
158
+ return result;
123
159
  });
124
160
  }
125
161
  updateExperienceVersion(experienceUid, versionId, input) {
126
162
  return __awaiter(this, void 0, void 0, function* () {
163
+ var _a, _b, _c;
164
+ cli_utilities_1.log.debug(`Updating experience version: ${versionId} for experience: ${experienceUid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
127
165
  // loop through input and remove shortId from variant
128
166
  if (input === null || input === void 0 ? void 0 : input.variants) {
129
167
  input.variants = input.variants.map((_a) => {
130
168
  var { shortUid } = _a, rest = __rest(_a, ["shortUid"]);
131
169
  return rest;
132
170
  });
171
+ cli_utilities_1.log.debug(`Processed ${input.variants.length} variants for update`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
133
172
  }
134
173
  const updateExperiencesVersionsEndPoint = `/experiences/${experienceUid}/versions/${versionId}`;
135
174
  const data = yield this.apiClient.put(updateExperiencesVersionsEndPoint, input);
136
- return (yield this.handleVariantAPIRes(data));
175
+ const result = (yield this.handleVariantAPIRes(data));
176
+ cli_utilities_1.log.debug(`Experience version updated successfully: ${versionId}`, (_c = this.exportConfig) === null || _c === void 0 ? void 0 : _c.context);
177
+ return result;
137
178
  });
138
179
  }
139
180
  getVariantGroup(input) {
140
181
  return __awaiter(this, void 0, void 0, function* () {
182
+ var _a, _b, _c;
183
+ cli_utilities_1.log.debug(`Fetching variant group for experience: ${input.experienceUid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
141
184
  if (this.cmaAPIClient) {
142
185
  const getVariantGroupEndPoint = `/variant_groups`;
143
186
  const data = yield this.cmaAPIClient
144
187
  .queryParams({ experience_uid: input.experienceUid })
145
188
  .get(getVariantGroupEndPoint);
146
- return (yield this.handleVariantAPIRes(data));
189
+ const result = (yield this.handleVariantAPIRes(data));
190
+ cli_utilities_1.log.debug(`Variant group fetched successfully for experience: ${input.experienceUid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
191
+ return result;
192
+ }
193
+ else {
194
+ cli_utilities_1.log.debug('CMA API client not available for variant group fetch', (_c = this.exportConfig) === null || _c === void 0 ? void 0 : _c.context);
147
195
  }
148
196
  });
149
197
  }
150
198
  updateVariantGroup(input) {
151
199
  return __awaiter(this, void 0, void 0, function* () {
200
+ var _a, _b, _c;
201
+ cli_utilities_1.log.debug(`Updating variant group: ${input.uid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
152
202
  if (this.cmaAPIClient) {
153
203
  const updateVariantGroupEndPoint = `/variant_groups/${input.uid}`;
154
204
  const data = yield this.cmaAPIClient.put(updateVariantGroupEndPoint, input);
155
- return (yield this.handleVariantAPIRes(data));
205
+ const result = (yield this.handleVariantAPIRes(data));
206
+ cli_utilities_1.log.debug(`Variant group updated successfully: ${input.uid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
207
+ return result;
208
+ }
209
+ else {
210
+ cli_utilities_1.log.debug('CMA API client not available for variant group update', (_c = this.exportConfig) === null || _c === void 0 ? void 0 : _c.context);
156
211
  }
157
212
  });
158
213
  }
159
214
  getEvents() {
160
215
  return __awaiter(this, void 0, void 0, function* () {
216
+ var _a, _b;
217
+ cli_utilities_1.log.debug('Fetching events from personalization API', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
161
218
  const data = yield this.apiClient.get('/events');
162
- return (yield this.handleVariantAPIRes(data));
219
+ const result = (yield this.handleVariantAPIRes(data));
220
+ cli_utilities_1.log.debug(`Fetched ${(result === null || result === void 0 ? void 0 : result.length) || 0} events`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
221
+ return result;
163
222
  });
164
223
  }
165
224
  createEvents(event) {
166
225
  return __awaiter(this, void 0, void 0, function* () {
226
+ var _a, _b;
227
+ cli_utilities_1.log.debug(`Creating event: ${event.key}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
167
228
  const data = yield this.apiClient.post('/events', event);
168
- return (yield this.handleVariantAPIRes(data));
229
+ const result = (yield this.handleVariantAPIRes(data));
230
+ cli_utilities_1.log.debug(`Event created successfully: ${result.uid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
231
+ return result;
169
232
  });
170
233
  }
171
234
  getAudiences() {
172
235
  return __awaiter(this, void 0, void 0, function* () {
236
+ var _a, _b;
237
+ cli_utilities_1.log.debug('Fetching audiences from personalization API', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
173
238
  const data = yield this.apiClient.get('/audiences');
174
- return (yield this.handleVariantAPIRes(data));
239
+ const result = (yield this.handleVariantAPIRes(data));
240
+ cli_utilities_1.log.debug(`Fetched ${(result === null || result === void 0 ? void 0 : result.length) || 0} audiences`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
241
+ return result;
175
242
  });
176
243
  }
177
244
  getAttributes() {
178
245
  return __awaiter(this, void 0, void 0, function* () {
246
+ var _a, _b;
247
+ cli_utilities_1.log.debug('Fetching attributes from personalization API', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
179
248
  const data = yield this.apiClient.get('/attributes');
180
- return (yield this.handleVariantAPIRes(data));
249
+ const result = (yield this.handleVariantAPIRes(data));
250
+ cli_utilities_1.log.debug(`Fetched ${(result === null || result === void 0 ? void 0 : result.length) || 0} attributes`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
251
+ return result;
181
252
  });
182
253
  }
183
254
  /**
@@ -190,8 +261,12 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
190
261
  */
191
262
  createAudience(audience) {
192
263
  return __awaiter(this, void 0, void 0, function* () {
264
+ var _a, _b;
265
+ cli_utilities_1.log.debug(`Creating audience: ${audience.name}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
193
266
  const data = yield this.apiClient.post('/audiences', audience);
194
- return (yield this.handleVariantAPIRes(data));
267
+ const result = (yield this.handleVariantAPIRes(data));
268
+ cli_utilities_1.log.debug(`Audience created successfully: ${result.uid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
269
+ return result;
195
270
  });
196
271
  }
197
272
  /**
@@ -204,8 +279,12 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
204
279
  */
205
280
  createExperience(experience) {
206
281
  return __awaiter(this, void 0, void 0, function* () {
282
+ var _a, _b;
283
+ cli_utilities_1.log.debug(`Creating experience: ${experience.name}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
207
284
  const data = yield this.apiClient.post('/experiences', experience);
208
- return (yield this.handleVariantAPIRes(data));
285
+ const result = (yield this.handleVariantAPIRes(data));
286
+ cli_utilities_1.log.debug(`Experience created successfully: ${result.uid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
287
+ return result;
209
288
  });
210
289
  }
211
290
  /**
@@ -215,9 +294,13 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
215
294
  */
216
295
  updateCTsInExperience(experience, experienceUid) {
217
296
  return __awaiter(this, void 0, void 0, function* () {
297
+ var _a, _b;
298
+ cli_utilities_1.log.debug(`Updating content types in experience: ${experienceUid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
218
299
  const updateCTInExpEndPoint = `/experiences/${experienceUid}/cms-integration/variant-group`;
219
300
  const data = yield this.apiClient.post(updateCTInExpEndPoint, experience);
220
- return (yield this.handleVariantAPIRes(data));
301
+ const result = (yield this.handleVariantAPIRes(data));
302
+ cli_utilities_1.log.debug(`Content types updated successfully in experience: ${experienceUid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
303
+ return result;
221
304
  });
222
305
  }
223
306
  /**
@@ -227,9 +310,13 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
227
310
  */
228
311
  getCTsFromExperience(experienceUid) {
229
312
  return __awaiter(this, void 0, void 0, function* () {
313
+ var _a, _b;
314
+ cli_utilities_1.log.debug(`Fetching content types from experience: ${experienceUid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
230
315
  const getCTFromExpEndPoint = `/experiences/${experienceUid}/cms-integration/variant-group`;
231
316
  const data = yield this.apiClient.get(getCTFromExpEndPoint);
232
- return (yield this.handleVariantAPIRes(data));
317
+ const result = (yield this.handleVariantAPIRes(data));
318
+ cli_utilities_1.log.debug(`Content types fetched successfully from experience: ${experienceUid}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
319
+ return result;
233
320
  });
234
321
  }
235
322
  /**
@@ -240,15 +327,20 @@ class PersonalizationAdapter extends adapter_helper_1.AdapterHelper {
240
327
  */
241
328
  handleVariantAPIRes(res) {
242
329
  return __awaiter(this, void 0, void 0, function* () {
330
+ var _a, _b, _c, _d;
243
331
  const { status, data } = res;
332
+ cli_utilities_1.log.debug(`API response status: ${status}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
244
333
  if (status >= 200 && status < 300) {
334
+ cli_utilities_1.log.debug('API request successful', (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
245
335
  return data;
246
336
  }
337
+ cli_utilities_1.log.debug(`API request failed with status: ${status}`, (_c = this.exportConfig) === null || _c === void 0 ? void 0 : _c.context);
247
338
  // Refresh the access token if it has expired
248
339
  yield cli_utilities_1.authenticationHandler.refreshAccessToken(res);
249
340
  const errorMsg = (data === null || data === void 0 ? void 0 : data.errors)
250
341
  ? (0, error_helper_1.formatErrors)(data.errors)
251
342
  : (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) || data;
343
+ cli_utilities_1.log.debug(`API error: ${errorMsg}`, (_d = this.exportConfig) === null || _d === void 0 ? void 0 : _d.context);
252
344
  throw errorMsg;
253
345
  });
254
346
  }
@@ -1,9 +1,10 @@
1
1
  import { HttpClient, HttpClientOptions, ContentstackClient, ContentstackConfig } from '@contentstack/cli-utilities';
2
- import { APIConfig, AdapterType, AnyProperty, VariantOptions, VariantsOption, VariantInterface, VariantEntryStruct, CreateVariantEntryDto, CreateVariantEntryOptions, APIResponse, PublishVariantEntryDto, PublishVariantEntryOptions } from '../types';
2
+ import { APIConfig, AdapterType, AnyProperty, ExportConfig, VariantOptions, VariantsOption, VariantInterface, VariantEntryStruct, CreateVariantEntryDto, CreateVariantEntryOptions, APIResponse, PublishVariantEntryDto, PublishVariantEntryOptions } from '../types';
3
3
  import messages from '../messages';
4
4
  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
+ exportConfig?: ExportConfig;
7
8
  constructor(config: APIConfig, options?: HttpClientOptions);
8
9
  init(): Promise<void>;
9
10
  variantEntry(options: VariantOptions): Promise<{
@@ -56,6 +57,7 @@ export declare class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> i
56
57
  }
57
58
  export declare class VariantManagementSDK<T> extends AdapterHelper<T, ContentstackClient> implements VariantInterface<T, ContentstackClient> {
58
59
  apiClient: ContentstackClient;
60
+ exportConfig?: any;
59
61
  init(): Promise<void>;
60
62
  variantEntry(options: VariantOptions): Promise<{
61
63
  entry: {};
@@ -74,6 +76,7 @@ export declare class VariantManagementSDK<T> extends AdapterHelper<T, Contentsta
74
76
  export declare class VariantAdapter<T> {
75
77
  protected variantInstance: T;
76
78
  readonly messages: typeof messages;
79
+ exportConfig?: any;
77
80
  constructor(config: ContentstackConfig & AnyProperty & AdapterType<T, ContentstackConfig>);
78
81
  constructor(config: APIConfig & AdapterType<T, APIConfig & AnyProperty>, options?: HttpClientOptions);
79
82
  }
@@ -32,25 +32,33 @@ const adapter_helper_1 = require("./adapter-helper");
32
32
  const error_helper_1 = require("./error-helper");
33
33
  class VariantHttpClient extends adapter_helper_1.AdapterHelper {
34
34
  constructor(config, options) {
35
- var _a;
35
+ var _a, _b;
36
36
  super(config, options);
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
+ cli_utilities_1.log.debug(`VariantHttpClient initialized with base URL: ${this.baseURL}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
39
40
  }
40
41
  init() {
41
42
  return __awaiter(this, void 0, void 0, function* () {
43
+ var _a, _b, _c, _d, _e;
44
+ cli_utilities_1.log.debug('Initializing VariantHttpClient...', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
42
45
  yield cli_utilities_1.authenticationHandler.getAuthDetails();
43
46
  const token = cli_utilities_1.authenticationHandler.accessToken;
47
+ cli_utilities_1.log.debug(`Authentication type: ${cli_utilities_1.authenticationHandler.isOauthEnabled ? 'OAuth' : 'Token'}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
44
48
  if (cli_utilities_1.authenticationHandler.isOauthEnabled) {
49
+ cli_utilities_1.log.debug('Setting OAuth authorization header', (_c = this.exportConfig) === null || _c === void 0 ? void 0 : _c.context);
45
50
  this.apiClient.headers({ authorization: token });
46
51
  }
47
52
  else {
53
+ cli_utilities_1.log.debug('Setting authtoken header', (_d = this.exportConfig) === null || _d === void 0 ? void 0 : _d.context);
48
54
  this.apiClient.headers({ authtoken: token });
49
55
  }
56
+ cli_utilities_1.log.debug('VariantHttpClient initialization completed', (_e = this.exportConfig) === null || _e === void 0 ? void 0 : _e.context);
50
57
  });
51
58
  }
52
59
  variantEntry(options) {
53
60
  return __awaiter(this, void 0, void 0, function* () {
61
+ cli_utilities_1.log.debug('VariantEntry method called (placeholder implementation)', { module: 'variant-api-adapter' });
54
62
  // TODO single entry variant
55
63
  return { entry: {} };
56
64
  });
@@ -70,18 +78,25 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
70
78
  */
71
79
  variantEntries(options_1) {
72
80
  return __awaiter(this, arguments, void 0, function* (options, entries = []) {
81
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
73
82
  const variantConfig = this.config.modules.variantEntry;
74
83
  const { callback, entry_uid, getAllData, returnResult, content_type_uid, locale, skip = variantConfig.query.skip || 0, limit = variantConfig.query.limit || 100, include_variant = variantConfig.query.include_variant || true, include_count = variantConfig.query.include_count || true, include_publish_details = variantConfig.query.include_publish_details || true, } = options;
84
+ cli_utilities_1.log.debug(`Fetching variant entries for content type: ${content_type_uid}, entry: ${entry_uid}, locale: ${locale}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
85
+ cli_utilities_1.log.debug(`Query parameters - skip: ${skip}, limit: ${limit}, include_variant: ${include_variant}, include_count: ${include_count}, include_publish_details: ${include_publish_details}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
75
86
  if (variantConfig.serveMockData && callback) {
87
+ cli_utilities_1.log.debug('Using mock data for variant entries', (_c = this.exportConfig) === null || _c === void 0 ? void 0 : _c.context);
76
88
  let data = [];
77
89
  if ((0, fs_1.existsSync)(variantConfig.mockDataPath)) {
90
+ cli_utilities_1.log.debug(`Loading mock data from: ${variantConfig.mockDataPath}`, (_d = this.exportConfig) === null || _d === void 0 ? void 0 : _d.context);
78
91
  data = require(variantConfig.mockDataPath);
79
92
  }
80
93
  callback(data);
81
94
  return;
82
95
  }
83
- if (!locale)
96
+ if (!locale) {
97
+ cli_utilities_1.log.debug('No locale provided, skipping variant entries fetch', (_e = this.exportConfig) === null || _e === void 0 ? void 0 : _e.context);
84
98
  return;
99
+ }
85
100
  const start = Date.now();
86
101
  let endpoint = `/content_types/${content_type_uid}/entries/${entry_uid}/variants?locale=${locale}`;
87
102
  if (skip) {
@@ -110,12 +125,18 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
110
125
  if (query) {
111
126
  endpoint = endpoint.concat(query);
112
127
  }
128
+ cli_utilities_1.log.debug(`Making API call to: ${endpoint}`, (_f = this.exportConfig) === null || _f === void 0 ? void 0 : _f.context);
113
129
  const data = yield this.apiClient.get(endpoint);
114
130
  const response = (yield this.handleVariantAPIRes(data));
131
+ if ((_g = response === null || response === void 0 ? void 0 : response.entries) === null || _g === void 0 ? void 0 : _g.length) {
132
+ cli_utilities_1.log.debug(`Received ${(_h = response.entries) === null || _h === void 0 ? void 0 : _h.length} variant entries out of total ${response.count}`, (_j = this.exportConfig) === null || _j === void 0 ? void 0 : _j.context);
133
+ }
115
134
  if (callback) {
135
+ cli_utilities_1.log.debug('Executing callback with variant entries', (_k = this.exportConfig) === null || _k === void 0 ? void 0 : _k.context);
116
136
  callback(response.entries);
117
137
  }
118
138
  else {
139
+ cli_utilities_1.log.debug('Adding variant entries to collection', (_l = this.exportConfig) === null || _l === void 0 ? void 0 : _l.context);
119
140
  entries = entries.concat(response.entries);
120
141
  }
121
142
  if (getAllData && skip + limit < response.count) {
@@ -123,16 +144,20 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
123
144
  const exeTime = end - start;
124
145
  if (exeTime < 1000) {
125
146
  // 1 API call per second
147
+ cli_utilities_1.log.debug(`Rate limiting: waiting ${1000 - exeTime}ms before next request`, (_m = this.exportConfig) === null || _m === void 0 ? void 0 : _m.context);
126
148
  yield this.delay(1000 - exeTime);
127
149
  }
128
150
  if (!options.skip) {
129
151
  options['skip'] = 0;
130
152
  }
131
153
  options.skip += limit;
154
+ cli_utilities_1.log.debug(`Continuing to fetch variant entries with skip: ${options.skip}`, (_o = this.exportConfig) === null || _o === void 0 ? void 0 : _o.context);
132
155
  return yield this.variantEntries(options, entries);
133
156
  }
134
- if (returnResult)
157
+ if (returnResult) {
158
+ cli_utilities_1.log.debug('Returning variant entries result', (_p = this.exportConfig) === null || _p === void 0 ? void 0 : _p.context);
135
159
  return { entries };
160
+ }
136
161
  });
137
162
  }
138
163
  /**
@@ -145,20 +170,31 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
145
170
  */
146
171
  createVariantEntry(input, options, apiParams) {
147
172
  return __awaiter(this, void 0, void 0, function* () {
173
+ var _a, _b;
148
174
  const { reject, resolve, variantUid, log } = apiParams;
149
175
  const variantConfig = this.config.modules.variantEntry;
150
176
  const { locale = variantConfig.query.locale || 'en-us', variant_id, entry_uid, content_type_uid } = options;
177
+ log.debug(`Creating variant entry for content type: ${content_type_uid}, entry: ${entry_uid}, variant: ${variant_id}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
151
178
  let endpoint = `content_types/${content_type_uid}/entries/${entry_uid}/variants/${variant_id}?locale=${locale}`;
152
179
  const query = this.constructQuery((0, omit_1.default)(variantConfig.query, ['locale']));
153
180
  if (query) {
154
181
  endpoint = endpoint.concat(query);
155
182
  }
156
- const onSuccess = (response) => resolve({ response, apiData: { variantUid, entryUid: entry_uid }, log });
157
- const onReject = (error) => reject({
158
- error,
159
- apiData: { variantUid, entryUid: entry_uid },
160
- log,
161
- });
183
+ log.debug(`Making API call to: ${endpoint}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
184
+ const onSuccess = (response) => {
185
+ var _a;
186
+ log.debug(`Variant entry created successfully: ${variantUid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
187
+ resolve({ response, apiData: { variantUid, entryUid: entry_uid }, log });
188
+ };
189
+ const onReject = (error) => {
190
+ var _a;
191
+ log.debug(`Failed to create variant entry: ${variantUid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
192
+ reject({
193
+ error,
194
+ apiData: { variantUid, entryUid: entry_uid },
195
+ log,
196
+ });
197
+ };
162
198
  try {
163
199
  this.apiClient.headers({ api_version: undefined });
164
200
  const res = yield this.apiClient.put(endpoint, { entry: input });
@@ -185,15 +221,26 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
185
221
  */
186
222
  publishVariantEntry(input, options, apiParams) {
187
223
  return __awaiter(this, void 0, void 0, function* () {
224
+ var _a, _b;
188
225
  const { reject, resolve, log, variantUid } = apiParams;
189
226
  const { entry_uid, content_type_uid } = options;
227
+ log.debug(`Publishing variant entry for content type: ${content_type_uid}, entry: ${entry_uid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
190
228
  let endpoint = `content_types/${content_type_uid}/entries/${entry_uid}/publish`;
191
- const onSuccess = (response) => resolve({ response, apiData: { entryUid: entry_uid, variantUid, locales: input.entry.locales }, log });
192
- const onReject = (error) => reject({
193
- error,
194
- apiData: { entryUid: entry_uid, variantUid, locales: input.entry.locales },
195
- log,
196
- });
229
+ log.debug(`Making API call to: ${endpoint}`, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
230
+ const onSuccess = (response) => {
231
+ var _a;
232
+ log.debug(`Variant entry published successfully: ${entry_uid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
233
+ resolve({ response, apiData: { entryUid: entry_uid, variantUid, locales: input.entry.locales }, log });
234
+ };
235
+ const onReject = (error) => {
236
+ var _a;
237
+ log.debug(`Failed to publish variant entry: ${entry_uid}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
238
+ reject({
239
+ error,
240
+ apiData: { entryUid: entry_uid, variantUid, locales: input.entry.locales },
241
+ log,
242
+ });
243
+ };
197
244
  try {
198
245
  this.apiClient.headers({ api_version: 3.2 });
199
246
  const res = yield this.apiClient.post(endpoint, input);
@@ -218,15 +265,20 @@ class VariantHttpClient extends adapter_helper_1.AdapterHelper {
218
265
  */
219
266
  handleVariantAPIRes(res) {
220
267
  return __awaiter(this, void 0, void 0, function* () {
268
+ var _a, _b, _c, _d;
221
269
  const { status, data } = res;
270
+ cli_utilities_1.log.debug(`API response status: ${status}`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
222
271
  if (status >= 200 && status < 300) {
272
+ cli_utilities_1.log.debug('API request successful', (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
223
273
  return data;
224
274
  }
275
+ cli_utilities_1.log.debug(`API request failed with status: ${status}`, (_c = this.exportConfig) === null || _c === void 0 ? void 0 : _c.context);
225
276
  // Refresh the access token if the response status is 401
226
277
  yield cli_utilities_1.authenticationHandler.refreshAccessToken(res);
227
278
  const errorMsg = (data === null || data === void 0 ? void 0 : data.errors)
228
279
  ? (0, error_helper_1.formatErrors)(data.errors)
229
280
  : (data === null || data === void 0 ? void 0 : data.error_message) || (data === null || data === void 0 ? void 0 : data.message) || data;
281
+ cli_utilities_1.log.debug(`API error: ${errorMsg}`, (_d = this.exportConfig) === null || _d === void 0 ? void 0 : _d.context);
230
282
  throw errorMsg;
231
283
  });
232
284
  }
@@ -235,47 +287,69 @@ exports.VariantHttpClient = VariantHttpClient;
235
287
  class VariantManagementSDK extends adapter_helper_1.AdapterHelper {
236
288
  init() {
237
289
  return __awaiter(this, void 0, void 0, function* () {
290
+ var _a, _b;
291
+ cli_utilities_1.log.debug('Initializing VariantManagementSDK...', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
238
292
  this.apiClient = yield (0, cli_utilities_1.managementSDKClient)(this.config);
293
+ cli_utilities_1.log.debug('VariantManagementSDK initialized successfully', (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
239
294
  });
240
295
  }
241
296
  variantEntry(options) {
242
297
  return __awaiter(this, void 0, void 0, function* () {
298
+ var _a;
299
+ cli_utilities_1.log.debug('VariantEntry method called (SDK placeholder implementation)', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
243
300
  // TODO SDK implementation
244
301
  return { entry: {} };
245
302
  });
246
303
  }
247
304
  variantEntries(options) {
248
305
  return __awaiter(this, void 0, void 0, function* () {
306
+ var _a;
307
+ cli_utilities_1.log.debug('VariantEntries method called (SDK placeholder implementation)', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
249
308
  // TODO SDK implementation
250
309
  return { entries: [{}] };
251
310
  });
252
311
  }
253
312
  createVariantEntry(input, options, apiParams) {
313
+ var _a;
314
+ cli_utilities_1.log.debug('CreateVariantEntry method called (SDK placeholder implementation)', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
254
315
  // FIXME placeholder
255
316
  return Promise.resolve({});
256
317
  }
257
318
  handleVariantAPIRes(res) {
258
319
  return __awaiter(this, void 0, void 0, function* () {
320
+ var _a;
321
+ cli_utilities_1.log.debug('HandleVariantAPIRes method called (SDK implementation)', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
259
322
  return res.data;
260
323
  });
261
324
  }
262
- constructQuery(query) { }
325
+ constructQuery(query) {
326
+ var _a;
327
+ cli_utilities_1.log.debug('ConstructQuery method called (SDK placeholder implementation)', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
328
+ }
263
329
  delay(ms) {
264
- return __awaiter(this, void 0, void 0, function* () { });
330
+ return __awaiter(this, void 0, void 0, function* () {
331
+ var _a;
332
+ cli_utilities_1.log.debug(`Delay method called for ${ms}ms (SDK placeholder implementation)`, (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
333
+ });
265
334
  }
266
335
  }
267
336
  exports.VariantManagementSDK = VariantManagementSDK;
268
337
  class VariantAdapter {
269
338
  constructor(config, options) {
339
+ var _a, _b, _c, _d;
340
+ cli_utilities_1.log.debug('Initializing VariantAdapter...', (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context);
270
341
  if (config.httpClient) {
342
+ cli_utilities_1.log.debug('Using HTTP client variant instance', (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.context);
271
343
  const { httpClient, Adapter } = config, restConfig = __rest(config, ["httpClient", "Adapter"]);
272
344
  this.variantInstance = new Adapter(restConfig, options);
273
345
  }
274
346
  else {
347
+ cli_utilities_1.log.debug('Using SDK variant instance', (_c = this.exportConfig) === null || _c === void 0 ? void 0 : _c.context);
275
348
  const { Adapter } = config, restConfig = __rest(config, ["Adapter"]);
276
349
  this.variantInstance = new Adapter(restConfig);
277
350
  }
278
351
  this.messages = messages_1.default;
352
+ cli_utilities_1.log.debug('VariantAdapter initialized successfully', (_d = this.exportConfig) === null || _d === void 0 ? void 0 : _d.context);
279
353
  }
280
354
  }
281
355
  exports.VariantAdapter = VariantAdapter;