|
1 | 1 | import merge from 'merge'; |
2 | 2 | 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'; |
4 | 12 | import defaultConfig from '../config'; |
5 | 13 | import { readFile } from './file-helper'; |
6 | 14 | import { askExportDir, askAPIKey } from './interactive'; |
7 | 15 | import login from './basic-login'; |
8 | 16 | import { filter, includes } from 'lodash'; |
9 | 17 | import { ExportConfig } from '../types'; |
10 | 18 |
|
11 | | -const setupConfig = async (exportCmdFlags: any): Promise<ExportConfig> => { |
| 19 | +const setupConfig = async (exportCmdFlags: any, context?: any): Promise<ExportConfig> => { |
12 | 20 | let config = merge({}, defaultConfig); |
13 | 21 |
|
14 | 22 | // Track authentication method |
@@ -97,7 +105,7 @@ const setupConfig = async (exportCmdFlags: any): Promise<ExportConfig> => { |
97 | 105 |
|
98 | 106 | if (exportCmdFlags['branch-alias']) { |
99 | 107 | config.branchAlias = exportCmdFlags['branch-alias']; |
100 | | - } |
| 108 | + } |
101 | 109 | if (exportCmdFlags['branch']) { |
102 | 110 | config.branchName = exportCmdFlags['branch']; |
103 | 111 | } |
@@ -133,10 +141,36 @@ const setupConfig = async (exportCmdFlags: any): Promise<ExportConfig> => { |
133 | 141 | } |
134 | 142 | } |
135 | 143 |
|
136 | | - // Add authentication details to config for context tracking |
| 144 | + // Add authentication details to config for context tracking |
137 | 145 | config.authenticationMethod = authenticationMethod; |
138 | 146 | log.debug('Export configuration setup completed.', { ...config }); |
139 | 147 |
|
| 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 | + |
140 | 174 | return config; |
141 | 175 | }; |
142 | 176 |
|
|
0 commit comments