Skip to content

Commit 53b9674

Browse files
author
Your Name
committed
added support for orgplan check in export and import
1 parent 402a4b2 commit 53b9674

11 files changed

Lines changed: 90 additions & 29 deletions

File tree

.talismanrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ fileignoreconfig:
1212
checksum: 8cafd5994d3ec13ba9af74c80b330bfd14721ea4e0359b456598964a6c2913ce
1313
- filename: packages/contentstack-seed/tests/contentstack.test.ts
1414
checksum: 04196568bf29f4693e968079867e87d96219b022bfee0f4697dce1b9bc161ac3
15+
- filename: packages/contentstack-export/src/utils/export-config-handler.ts
16+
checksum: 362c1042a70958b52e73a7a3096152cf0259c55095c8b2c6f308b8f5fb90614e
17+
- filename: packages/contentstack-import/src/utils/import-config-handler.ts
18+
checksum: f310186b5ea1fc756bd200dbe01967bc07e5490dc5ed17018f0ca4b35f0fd86f
1519
version: '1.0'

packages/contentstack-export/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@
9393
"shortCommandName": {
9494
"cm:stacks:export": "EXPRT",
9595
"cm:export": "O-EXPRT"
96-
}
96+
},
97+
"planProtectedFeatures": ["assetsScan"]
9798
},
9899
"repository": "https://github.com/contentstack/cli"
99100
}

packages/contentstack-export/src/commands/cm/stacks/export.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export default class ExportCommand extends Command {
120120
let exportDir: string = pathValidator('logs');
121121
try {
122122
const { flags } = await this.parse(ExportCommand);
123-
const exportConfig = await setupExportConfig(flags);
123+
const exportConfig = await setupExportConfig(flags, this.context);
124124

125125
// Store apiKey in configHandler for session.json (return value not needed)
126126
createLogContext(

packages/contentstack-export/src/types/export-config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { FeatureStatus } from '@contentstack/cli-utilities';
12
import { Context, Modules, Region } from '.';
23
import DefaultConfig from './default-config';
34

@@ -36,6 +37,7 @@ export default interface ExportConfig extends DefaultConfig {
3637
skipStackSettings?: boolean;
3738
skipDependencies?: boolean;
3839
authenticationMethod?: string;
40+
planStatus?: Record<string, FeatureStatus>;
3941
}
4042

4143
type branch = {

packages/contentstack-export/src/utils/export-config-handler.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import merge from 'merge';
22
import * as path from 'path';
3-
import { configHandler, isAuthenticated,cliux, sanitizePath, log } from '@contentstack/cli-utilities';
3+
import {
4+
configHandler,
5+
isAuthenticated,
6+
cliux,
7+
sanitizePath,
8+
log,
9+
FeatureCtx,
10+
isFeatureEnabled,
11+
} from '@contentstack/cli-utilities';
412
import defaultConfig from '../config';
513
import { readFile } from './file-helper';
614
import { askExportDir, askAPIKey } from './interactive';
715
import login from './basic-login';
816
import { filter, includes } from 'lodash';
917
import { ExportConfig } from '../types';
1018

11-
const setupConfig = async (exportCmdFlags: any): Promise<ExportConfig> => {
19+
const setupConfig = async (exportCmdFlags: any, context?: any): Promise<ExportConfig> => {
1220
let config = merge({}, defaultConfig);
1321

1422
// Track authentication method
@@ -97,7 +105,7 @@ const setupConfig = async (exportCmdFlags: any): Promise<ExportConfig> => {
97105

98106
if (exportCmdFlags['branch-alias']) {
99107
config.branchAlias = exportCmdFlags['branch-alias'];
100-
}
108+
}
101109
if (exportCmdFlags['branch']) {
102110
config.branchName = exportCmdFlags['branch'];
103111
}
@@ -133,10 +141,36 @@ const setupConfig = async (exportCmdFlags: any): Promise<ExportConfig> => {
133141
}
134142
}
135143

136-
// Add authentication details to config for context tracking
144+
// Add authentication details to config for context tracking
137145
config.authenticationMethod = authenticationMethod;
138146
log.debug('Export configuration setup completed.', { ...config });
139147

148+
// Deferred plan check — credentials now available after setupExportConfig
149+
const deferredFeatures: string[] = context?.planCheckRequired ?? [];
150+
if (deferredFeatures.length > 0) {
151+
const planCtx: FeatureCtx = {
152+
apiKey: config.apiKey,
153+
managementToken: config.management_token,
154+
authToken: config.auth_token,
155+
};
156+
for (const featureUid of deferredFeatures) {
157+
try {
158+
const status = await isFeatureEnabled(featureUid, planCtx);
159+
if (context) {
160+
context.planStatus[featureUid] = status;
161+
}
162+
163+
log.debug(`[export] Deferred plan status fetched for "${featureUid}".`);
164+
} catch (error) {
165+
log.warn(`[export] Could not fetch deferred plan status for "${featureUid}": ${(error as Error).message}`);
166+
}
167+
}
168+
}
169+
170+
if (context?.planStatus) {
171+
config.planStatus = context.planStatus;
172+
}
173+
140174
return config;
141175
};
142176

packages/contentstack-import/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585
"shortCommandName": {
8686
"cm:stacks:import": "IMPRT",
8787
"cm:import": "O-IMPRT"
88-
}
88+
},
89+
"planProtectedFeatures": ["assetsScan"]
8990
},
9091
"repository": "https://github.com/contentstack/cli"
9192
}

packages/contentstack-import/src/commands/cm/stacks/import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export default class ImportCommand extends Command {
154154
let importConfig: ImportConfig;
155155
try {
156156
const { flags } = await this.parse(ImportCommand);
157-
importConfig = await setupImportConfig(flags);
157+
importConfig = await setupImportConfig(flags, this.context);
158158
// Prepare the context object
159159
createLogContext(
160160
this.context?.info?.command || 'cm:stacks:export',

packages/contentstack-import/src/import/module-importer.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ class ModuleImporter {
3434
const stackDetails: Record<string, unknown> = await this.stackAPIClient.fetch();
3535
this.importConfig.stackName = stackDetails.name as string;
3636
this.importConfig.org_uid = stackDetails.org_uid as string;
37-
38-
const assetScanningEnabled = await this.detectAssetScanning(this.importConfig.org_uid);
39-
if (assetScanningEnabled) {
40-
this.importConfig.assetScanningEnabled = true;
41-
this.importConfig.skipAssetsPublish = true;
42-
}
4337
}
4438

4539
await this.resolveImportPath();
@@ -215,16 +209,6 @@ class ModuleImporter {
215209
log.error(`Audit failed with following error. ${error}`, this.importConfig.context);
216210
}
217211
}
218-
219-
private async detectAssetScanning(orgUid: string): Promise<boolean> {
220-
try {
221-
const orgDetails = await this.managementAPIClient.organization(orgUid).fetch({ include_plan: true });
222-
const features: Array<{ uid: string; enabled?: boolean }> = orgDetails?.plan?.features || [];
223-
return features.some((f) => (f.uid === 'assetsScan' || f.uid === 'amAssetsScan') && f.enabled === true);
224-
} catch {
225-
return false;
226-
}
227-
}
228212
}
229213

230214
export default ModuleImporter;

packages/contentstack-import/src/import/modules/assets.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,15 @@ export default class ImportAssets extends BaseClass {
5353
*/
5454
async start(): Promise<void> {
5555
try {
56-
// NOTE Step 1: Import folders and create uid mapping file
56+
if (this.importConfig.assetScanningEnabled) {
57+
log.info('Assets Scanning is enabled in this stack', this.importConfig.context);
58+
log.warn('Assets publishing will be skipped', this.importConfig.context);
59+
}
60+
// NOTE Step 1: Import folders and create uid mapping file
5761
log.debug('Starting folder import process...', this.importConfig.context);
5862
await this.importFolders();
5963

60-
// NOTE Step 2: Import versioned assets and create it mapping files (uid, url)
64+
// NOTE Step 2: Import versioned assets and create it mapping files (uid, url)
6165
if (this.assetConfig.includeVersionedAssets) {
6266
const versionsPath = `${this.assetsPath}/versions`;
6367
if (existsSync(versionsPath)) {
@@ -68,11 +72,11 @@ export default class ImportAssets extends BaseClass {
6872
}
6973
}
7074

71-
// NOTE Step 3: Import Assets and create it mapping files (uid, url)
75+
// NOTE Step 3: Import Assets and create it mapping files (uid, url)
7276
log.debug('Starting assets import...', this.importConfig.context);
7377
await this.importAssets();
7478

75-
// NOTE Step 4: Publish assets
79+
// NOTE Step 4: Publish assets
7680
if (!this.importConfig.skipAssetsPublish) {
7781
log.debug('Starting assets publishing...', this.importConfig.context);
7882
await this.publish();

packages/contentstack-import/src/types/import-config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { FeatureStatus } from '@contentstack/cli-utilities';
12
import { Context, Modules, Region } from '.';
23
import DefaultConfig from './default-config';
34

@@ -60,6 +61,7 @@ export default interface ImportConfig extends DefaultConfig, ExternalConfig {
6061
personalizeProjectName?: string;
6162
'exclude-global-modules': false;
6263
context: Context;
64+
planStatus?: Record<string, FeatureStatus>;
6365
}
6466

6567
type branch = {

0 commit comments

Comments
 (0)