diff --git a/packages/contentstack-export/src/export/modules/entries.ts b/packages/contentstack-export/src/export/modules/entries.ts index 0f2f7ed75e..a1695aa9e1 100644 --- a/packages/contentstack-export/src/export/modules/entries.ts +++ b/packages/contentstack-export/src/export/modules/entries.ts @@ -1,6 +1,7 @@ import * as path from 'path'; import { ContentstackClient, FsUtility } from '@contentstack/cli-utilities'; import { LogType, Export, ExportProjects } from '@contentstack/cli-variants'; +import VariantEntries from '@contentstack/cli-variants/lib/export/variant-entries'; import BaseClass, { ApiOptions } from './base-class'; import { log, formatError, fsUtil } from '../../utils'; @@ -20,7 +21,7 @@ export default class EntriesExport extends BaseClass { batchLimit?: number; exportVersions: boolean; }; - private variantEntries; + private variantEntries!: VariantEntries; private entriesDirPath: string; private localesFilePath: string; private schemaFilePath: string; @@ -47,7 +48,6 @@ export default class EntriesExport extends BaseClass { 'schema.json', ); this.projectInstance = new ExportProjects(this.exportConfig); - this.variantEntries = new Export.VariantEntries(this.exportConfig, log as LogType); } async start() { @@ -62,12 +62,19 @@ export default class EntriesExport extends BaseClass { // NOTE Check if variant is enabled in specific stack if (this.exportConfig.personalizationEnabled) { + let project_id; try { const project = await this.projectInstance.projects({ connectedStackApiKey: this.exportConfig.apiKey }); if (project && project[0]?.uid) { + project_id = project[0].uid; this.exportVariantEntry = true; } + + this.variantEntries = new Export.VariantEntries( + Object.assign(this.exportConfig, { project_id }), + log as LogType, + ); } catch (_error) {} } diff --git a/packages/contentstack-variants/src/export/variant-entries.ts b/packages/contentstack-variants/src/export/variant-entries.ts index 4b1f9bba1f..9b19a36af2 100644 --- a/packages/contentstack-variants/src/export/variant-entries.ts +++ b/packages/contentstack-variants/src/export/variant-entries.ts @@ -15,7 +15,13 @@ export default class VariantEntries extends VariantAdapter, - headers: { organization_uid: config.org_uid, authtoken: config.auth_token }, + headers: { + api_key: config.apiKey, + branch: config.branchName, + authtoken: config.auth_token, + organization_uid: config.org_uid, + 'X-Project-Uid': config.project_id, + }, }; super(Object.assign(config, conf)); this.entriesDirPath = resolve(config.data, config.branchName || '', config.modules.entries.dirName); diff --git a/packages/contentstack-variants/src/utils/variant-api-adapter.ts b/packages/contentstack-variants/src/utils/variant-api-adapter.ts index 2ad81c39d2..78b0f2b8bf 100644 --- a/packages/contentstack-variants/src/utils/variant-api-adapter.ts +++ b/packages/contentstack-variants/src/utils/variant-api-adapter.ts @@ -26,10 +26,11 @@ import messages from '../messages'; import { AdapterHelper } from './adapter-helper'; export class VariantHttpClient extends AdapterHelper implements VariantInterface { + public baseURL: string constructor(config: APIConfig, options?: HttpClientOptions) { super(config, options); - const baseURL = config.baseURL?.includes('http') ? `${config.baseURL}/v3` : `https://${config.baseURL}/v3`; - this.apiClient.baseUrl(baseURL); + this.baseURL = config.baseURL?.includes('http') ? `${config.baseURL}/v3` : `https://${config.baseURL}/v3`; + this.apiClient.baseUrl(this.baseURL); } async variantEntry(options: VariantOptions) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f5a9cff9c0..1db7dabc50 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -56,7 +56,7 @@ importers: rimraf: ^2.7.1 shelljs: ^0.8.4 short-uuid: ^4.2.2 - sinon: ^15.0.1 + sinon: ^15.0.u1 tmp: ^0.2.2 ts-node: ^10.9.1 tslib: ^2.4.1