Skip to content

Commit b575cd2

Browse files
authored
Merge pull request #136 from contentstack/enhc/DX-7310
Added branches support for entry variant and variant group
2 parents 1bf6732 + 2242e99 commit b575cd2

6 files changed

Lines changed: 22 additions & 5 deletions

File tree

packages/contentstack-export/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dependencies": {
88
"@contentstack/cli-command": "~2.0.0-beta.7",
99
"@contentstack/cli-utilities": "~2.0.0-beta.8",
10-
"@contentstack/cli-variants": "~2.0.0-beta.13",
10+
"@contentstack/cli-variants": "~2.0.0-beta.14",
1111
"@contentstack/cli-asset-management": "~1.0.0-beta.2",
1212
"@oclif/core": "^4.8.0",
1313
"async": "^3.2.6",

packages/contentstack-import/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"@contentstack/cli-audit": "~2.0.0-beta.12",
99
"@contentstack/cli-command": "~2.0.0-beta.7",
1010
"@contentstack/cli-utilities": "~2.0.0-beta.8",
11-
"@contentstack/cli-variants": "~2.0.0-beta.13",
11+
"@contentstack/cli-variants": "~2.0.0-beta.14",
1212
"@contentstack/cli-asset-management": "~1.0.0-beta.2",
1313
"@oclif/core": "^4.3.0",
1414
"big-json": "^3.2.0",

packages/contentstack-variants/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-variants",
3-
"version": "2.0.0-beta.13",
3+
"version": "2.0.0-beta.14",
44
"description": "Variants plugin",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

packages/contentstack-variants/src/export/experiences.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export default class ExportExperiences extends PersonalizationAdapter<ExportConf
1616
headers: { 'X-Project-Uid': exportConfig.project_id },
1717
cmaConfig: {
1818
baseURL: exportConfig.region.cma + `/v3`,
19-
headers: { api_key: exportConfig.apiKey },
19+
headers: {
20+
api_key: exportConfig.apiKey,
21+
...(exportConfig.branchName ? { branch: exportConfig.branchName } : {}),
22+
},
2023
},
2124
});
2225
this.exportConfig = exportConfig;

packages/contentstack-variants/src/import/experiences.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
5050
headers: { 'X-Project-Uid': config.modules.personalize.project_id },
5151
cmaConfig: {
5252
baseURL: config.region.cma + `/v3`,
53-
headers: { api_key: config.apiKey },
53+
headers: {
54+
api_key: config.apiKey,
55+
...(config.branchName ? { branch: config.branchName } : {}),
56+
},
5457
},
5558
};
5659
super(Object.assign(config, conf));

packages/contentstack-variants/src/utils/personalization-api-adapter.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
155155
this.cmaAPIClient?.headers({ authtoken: token });
156156
}
157157
}
158+
159+
// Ensure the CMA client targets the configured branch. Variant groups, CT
160+
// links and other stack-CMA endpoints are branch-scoped, so without this
161+
// header the requests would fall back to the default (main) branch even
162+
// when the import/export is running against a non-main branch.
163+
const branchName = (this.config as any)?.branchName;
164+
if (this.adapterConfig.cmaConfig && branchName) {
165+
log.debug(`Setting branch header for CMA client: ${branchName}`, this.exportConfig?.context);
166+
this.cmaAPIClient?.headers({ branch: branchName });
167+
}
168+
158169
log.debug('Personalization adapter initialization completed', this.exportConfig?.context);
159170
} catch (error: any) {
160171
log.debug(`Personalization adapter initialization failed: ${error}`, this.exportConfig?.context);

0 commit comments

Comments
 (0)