-
Notifications
You must be signed in to change notification settings - Fork 16
Export import support for composable studio #2246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shafeeqd959
merged 7 commits into
feat/composable-studio-support
from
export-import/composable-studio
Nov 26, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1ad38d9
added delay after create entries
shafeeqd959 014f0ee
added export and import support for composable studio project
shafeeqd959 83d017e
restricted authentication to basiz auth
shafeeqd959 77cdc90
updated test cases
shafeeqd959 c1de49f
updated talismanrc
shafeeqd959 0a79eb0
updated talismanrc
shafeeqd959 e315e30
updated error handling
shafeeqd959 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
packages/contentstack-export/src/export/modules/composable-studio.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| import { resolve as pResolve } from 'node:path'; | ||
| import { | ||
| cliux, | ||
| isAuthenticated, | ||
| log, | ||
| messageHandler, | ||
| handleAndLogError, | ||
| HttpClient, | ||
| authenticationHandler, | ||
| } from '@contentstack/cli-utilities'; | ||
|
|
||
| import { fsUtil, getOrgUid } from '../../utils'; | ||
| import { ModuleClassParams, ComposableStudioConfig, ExportConfig, ComposableStudioProject } from '../../types'; | ||
|
|
||
| export default class ExportComposableStudio { | ||
| protected composableStudioConfig: ComposableStudioConfig; | ||
| protected composableStudioProject: ComposableStudioProject | null = null; | ||
| protected apiClient: HttpClient; | ||
| public composableStudioPath: string; | ||
| public exportConfig: ExportConfig; | ||
|
|
||
| constructor({ exportConfig }: Omit<ModuleClassParams, 'stackAPIClient' | 'moduleName'>) { | ||
| this.exportConfig = exportConfig; | ||
| this.composableStudioConfig = exportConfig.modules['composable-studio']; | ||
| this.exportConfig.context.module = 'composable-studio'; | ||
|
|
||
| // Initialize HttpClient with Composable Studio API base URL | ||
| this.apiClient = new HttpClient(); | ||
| this.apiClient.baseUrl(this.composableStudioConfig.apiBaseUrl); | ||
| } | ||
|
|
||
| async start(): Promise<void> { | ||
| log.debug('Starting Composable Studio project export process...', this.exportConfig.context); | ||
|
|
||
| if (!isAuthenticated()) { | ||
| cliux.print( | ||
| 'WARNING!!! To export Composable Studio projects, you must be logged in. Please check csdx auth:login --help to log in', | ||
| { color: 'yellow' }, | ||
| ); | ||
| return Promise.resolve(); | ||
| } | ||
|
|
||
| this.composableStudioPath = pResolve( | ||
| this.exportConfig.data, | ||
| this.exportConfig.branchName || '', | ||
| this.composableStudioConfig.dirName, | ||
| ); | ||
| log.debug(`Composable Studio folder path: ${this.composableStudioPath}`, this.exportConfig.context); | ||
|
|
||
| await fsUtil.makeDirectory(this.composableStudioPath); | ||
| log.debug('Created Composable Studio directory', this.exportConfig.context); | ||
|
|
||
| this.exportConfig.org_uid = this.exportConfig.org_uid || (await getOrgUid(this.exportConfig)); | ||
| log.debug(`Organization UID: ${this.exportConfig.org_uid}`, this.exportConfig.context); | ||
|
|
||
| await this.exportProjects(); | ||
| log.debug('Composable Studio project export process completed', this.exportConfig.context); | ||
| } | ||
|
|
||
| /** | ||
| * Export Composable Studio projects connected to the current stack | ||
| */ | ||
| async exportProjects(): Promise<void> { | ||
| log.debug('Starting Composable Studio project export...', this.exportConfig.context); | ||
|
|
||
| try { | ||
| // Get authentication details - following personalization-api-adapter pattern | ||
| log.debug('Initializing Composable Studio API authentication...', this.exportConfig.context); | ||
| await authenticationHandler.getAuthDetails(); | ||
| const token = authenticationHandler.accessToken; | ||
| log.debug( | ||
| `Authentication type: ${authenticationHandler.isOauthEnabled ? 'OAuth' : 'Token'}`, | ||
| this.exportConfig.context, | ||
| ); | ||
|
|
||
| // Set authentication headers based on auth type | ||
| if (authenticationHandler.isOauthEnabled) { | ||
| log.debug('Setting OAuth authorization header', this.exportConfig.context); | ||
| this.apiClient.headers({ authorization: token }); | ||
| } else { | ||
| log.debug('Setting authtoken header', this.exportConfig.context); | ||
| this.apiClient.headers({ authtoken: token }); | ||
| } | ||
|
|
||
| // Set organization_uid header | ||
| this.apiClient.headers({ | ||
| organization_uid: this.exportConfig.org_uid, | ||
| Accept: 'application/json', | ||
| }); | ||
|
|
||
| const apiUrl = '/projects'; | ||
| log.debug( | ||
| `Fetching projects from: ${this.composableStudioConfig.apiBaseUrl}${apiUrl}`, | ||
| this.exportConfig.context, | ||
| ); | ||
|
|
||
| // Make API call to fetch projects using HttpClient | ||
| const response = await this.apiClient.get(apiUrl); | ||
|
|
||
| if (response.status < 200 || response.status >= 300) { | ||
| throw new Error(`API call failed with status ${response.status}: ${JSON.stringify(response.data)}`); | ||
| } | ||
|
|
||
| const data = response.data; | ||
| log.debug(`Fetched ${data.projects?.length || 0} total projects`, this.exportConfig.context); | ||
|
|
||
| // Filter projects connected to this stack | ||
| const connectedProject = data.projects?.filter( | ||
| (project: ComposableStudioProject) => project.connectedStackApiKey === this.exportConfig.apiKey, | ||
| ); | ||
|
|
||
| if (!connectedProject || connectedProject.length === 0) { | ||
| log.info(messageHandler.parse('COMPOSABLE_STUDIO_NOT_FOUND'), this.exportConfig.context); | ||
| return; | ||
| } | ||
|
|
||
| // Use the first connected project (stacks should have only one project) | ||
| this.composableStudioProject = connectedProject[0]; | ||
| log.debug(`Found Composable Studio project: ${this.composableStudioProject.name}`, this.exportConfig.context); | ||
|
|
||
| // Write the project to file | ||
| const composableStudioFilePath = pResolve(this.composableStudioPath, this.composableStudioConfig.fileName); | ||
| log.debug(`Writing Composable Studio project to: ${composableStudioFilePath}`, this.exportConfig.context); | ||
|
|
||
| fsUtil.writeFile(composableStudioFilePath, this.composableStudioProject as unknown as Record<string, unknown>); | ||
|
|
||
| log.success( | ||
| messageHandler.parse('COMPOSABLE_STUDIO_EXPORT_COMPLETE', this.composableStudioProject.name), | ||
| this.exportConfig.context, | ||
| ); | ||
| } catch (error: any) { | ||
| log.debug('Error occurred while exporting Composable Studio project', this.exportConfig.context); | ||
| handleAndLogError(error, { | ||
| ...this.exportConfig.context, | ||
| }); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.