@contentstack/cli-variants 0.0.1-alpha → 1.1.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.
- package/lib/export/attributes.d.ts +2 -2
- package/lib/export/attributes.js +5 -4
- package/lib/export/audiences.d.ts +2 -2
- package/lib/export/audiences.js +5 -4
- package/lib/export/events.d.ts +2 -2
- package/lib/export/events.js +5 -4
- package/lib/export/experiences.d.ts +2 -2
- package/lib/export/experiences.js +20 -5
- package/lib/export/projects.d.ts +2 -2
- package/lib/export/projects.js +9 -6
- package/lib/export/variant-entries.js +1 -1
- package/lib/import/attribute.d.ts +1 -1
- package/lib/import/attribute.js +21 -10
- package/lib/import/audiences.d.ts +2 -2
- package/lib/import/audiences.js +21 -14
- package/lib/import/events.d.ts +1 -1
- package/lib/import/events.js +15 -8
- package/lib/import/experiences.d.ts +12 -5
- package/lib/import/experiences.js +86 -21
- package/lib/import/project.js +12 -11
- package/lib/import/variant-entries.d.ts +1 -1
- package/lib/import/variant-entries.js +28 -22
- package/lib/messages/index.d.ts +1 -1
- package/lib/messages/index.js +3 -2
- package/lib/types/export-config.d.ts +3 -3
- package/lib/types/import-config.d.ts +1 -1
- package/lib/types/personalization-api-adapter.d.ts +14 -1
- package/lib/types/variant-api-adapter.d.ts +3 -2
- package/lib/types/variant-entry.d.ts +2 -3
- package/lib/utils/attributes-helper.js +2 -2
- package/lib/utils/audiences-helper.js +14 -3
- package/lib/utils/error-helper.js +6 -6
- package/lib/utils/logger.js +5 -4
- package/lib/utils/personalization-api-adapter.d.ts +6 -2
- package/lib/utils/personalization-api-adapter.js +90 -23
- package/lib/utils/variant-api-adapter.d.ts +5 -4
- package/lib/utils/variant-api-adapter.js +29 -10
- package/package.json +2 -2
- package/src/export/attributes.ts +11 -7
- package/src/export/audiences.ts +7 -6
- package/src/export/events.ts +7 -6
- package/src/export/experiences.ts +24 -7
- package/src/export/projects.ts +11 -8
- package/src/export/variant-entries.ts +1 -2
- package/src/import/attribute.ts +31 -13
- package/src/import/audiences.ts +37 -19
- package/src/import/events.ts +25 -11
- package/src/import/experiences.ts +120 -30
- package/src/import/project.ts +13 -13
- package/src/import/variant-entries.ts +70 -37
- package/src/messages/index.ts +3 -2
- package/src/types/export-config.ts +3 -3
- package/src/types/import-config.ts +1 -1
- package/src/types/personalization-api-adapter.ts +14 -1
- package/src/types/variant-api-adapter.ts +3 -1
- package/src/types/variant-entry.ts +2 -3
- package/src/utils/attributes-helper.ts +2 -2
- package/src/utils/audiences-helper.ts +12 -2
- package/src/utils/error-helper.ts +6 -6
- package/src/utils/logger.ts +5 -4
- package/src/utils/personalization-api-adapter.ts +71 -18
- package/src/utils/variant-api-adapter.ts +21 -7
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
ContentstackClient,
|
|
8
8
|
ContentstackConfig,
|
|
9
9
|
managementSDKClient,
|
|
10
|
+
authenticationHandler,
|
|
10
11
|
} from '@contentstack/cli-utilities';
|
|
11
12
|
|
|
12
13
|
import {
|
|
@@ -37,6 +38,16 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
|
|
|
37
38
|
this.apiClient.baseUrl(this.baseURL);
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
async init(): Promise<void> {
|
|
42
|
+
await authenticationHandler.getAuthDetails();
|
|
43
|
+
const token = authenticationHandler.accessToken;
|
|
44
|
+
if (authenticationHandler.isOauthEnabled) {
|
|
45
|
+
this.apiClient.headers({ authorization: token });
|
|
46
|
+
} else {
|
|
47
|
+
this.apiClient.headers({ authtoken: token });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
40
51
|
async variantEntry(options: VariantOptions) {
|
|
41
52
|
// TODO single entry variant
|
|
42
53
|
return { entry: {} };
|
|
@@ -124,7 +135,7 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
|
|
|
124
135
|
}
|
|
125
136
|
|
|
126
137
|
const data = await this.apiClient.get(endpoint);
|
|
127
|
-
const response = this.handleVariantAPIRes(data) as { entries: VariantEntryStruct[]; count: number };
|
|
138
|
+
const response = (await this.handleVariantAPIRes(data)) as { entries: VariantEntryStruct[]; count: number };
|
|
128
139
|
|
|
129
140
|
if (callback) {
|
|
130
141
|
callback(response.entries);
|
|
@@ -184,6 +195,7 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
|
|
|
184
195
|
});
|
|
185
196
|
|
|
186
197
|
try {
|
|
198
|
+
this.apiClient.headers({ api_version: undefined });
|
|
187
199
|
const res = await this.apiClient.put<VariantEntryStruct>(endpoint, { entry: input });
|
|
188
200
|
const data = this.handleVariantAPIRes(res);
|
|
189
201
|
|
|
@@ -214,8 +226,7 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
|
|
|
214
226
|
const { entry_uid, content_type_uid } = options;
|
|
215
227
|
let endpoint = `content_types/${content_type_uid}/entries/${entry_uid}/publish`;
|
|
216
228
|
|
|
217
|
-
const onSuccess = (response: any) =>
|
|
218
|
-
resolve({ response, apiData: { entryUid: entry_uid, variantUid }, log });
|
|
229
|
+
const onSuccess = (response: any) => resolve({ response, apiData: { entryUid: entry_uid, variantUid }, log });
|
|
219
230
|
const onReject = (error: any) =>
|
|
220
231
|
reject({
|
|
221
232
|
error,
|
|
@@ -244,15 +255,18 @@ export class VariantHttpClient<C> extends AdapterHelper<C, HttpClient> implement
|
|
|
244
255
|
* @returns The variant API response data.
|
|
245
256
|
* @throws If the API response status is not within the success range, an error message is thrown.
|
|
246
257
|
*/
|
|
247
|
-
handleVariantAPIRes(
|
|
258
|
+
async handleVariantAPIRes(
|
|
248
259
|
res: APIResponse,
|
|
249
|
-
): VariantEntryStruct | { entries: VariantEntryStruct[]; count: number } | string | any {
|
|
260
|
+
): Promise<VariantEntryStruct | { entries: VariantEntryStruct[]; count: number } | string | any> {
|
|
250
261
|
const { status, data } = res;
|
|
251
262
|
|
|
252
263
|
if (status >= 200 && status < 300) {
|
|
253
264
|
return data;
|
|
254
265
|
}
|
|
255
266
|
|
|
267
|
+
// Refresh the access token if the response status is 401
|
|
268
|
+
await authenticationHandler.refreshAccessToken(res);
|
|
269
|
+
|
|
256
270
|
const errorMsg = data?.errors
|
|
257
271
|
? formatErrors(data.errors)
|
|
258
272
|
: data?.error_message || data?.message || 'Something went wrong while processing entry variant request!';
|
|
@@ -290,9 +304,9 @@ export class VariantManagementSDK<T>
|
|
|
290
304
|
return Promise.resolve({} as VariantEntryStruct);
|
|
291
305
|
}
|
|
292
306
|
|
|
293
|
-
handleVariantAPIRes(
|
|
307
|
+
async handleVariantAPIRes(
|
|
294
308
|
res: APIResponse,
|
|
295
|
-
): VariantEntryStruct | { entries: VariantEntryStruct[]; count: number } | string {
|
|
309
|
+
): Promise<VariantEntryStruct | { entries: VariantEntryStruct[]; count: number } | string> {
|
|
296
310
|
return res.data;
|
|
297
311
|
}
|
|
298
312
|
|