diff --git a/packages/contentstack-asset-management/README.md b/packages/contentstack-asset-management/README.md new file mode 100644 index 000000000..955ec5e2c --- /dev/null +++ b/packages/contentstack-asset-management/README.md @@ -0,0 +1,49 @@ +# @contentstack/cli-asset-management + +Asset Management 2.0 API adapter for Contentstack CLI export and import. Used by the export and import plugins when Asset Management (AM 2.0) is enabled. To learn how to export and import content in Contentstack, refer to the [Migration guide](https://www.contentstack.com/docs/developers/cli/migration/). + +[![License](https://img.shields.io/npm/l/@contentstack/cli)](https://github.com/contentstack/cli/blob/main/LICENSE) + + +* [@contentstack/cli-asset-management](#contentstackcli-asset-management) +* [Overview](#overview) +* [Usage](#usage) +* [Exports](#exports) + + +# Overview + +This package provides: + +- **AssetManagementAdapter** – HTTP client for the Asset Management API (spaces, assets, folders, fields, asset types). +- **exportSpaceStructure** – Exports space metadata and full workspace structure (metadata, folders, assets, fields, asset types) for linked workspaces. +- **Types** – `AssetManagementExportOptions`, `LinkedWorkspace`, `IAssetManagementAdapter`, and related types for export/import integration. + +# Usage + +This package is consumed by the export and import plugins. When using the export CLI with the `--asset-management` flag (or when the host app enables AM 2.0), the export plugin calls `exportSpaceStructure` with linked workspaces and options: + +```ts +import { exportSpaceStructure } from '@contentstack/cli-asset-management'; + +await exportSpaceStructure({ + linkedWorkspaces, + exportDir, + branchName: 'main', + assetManagementUrl, + org_uid, + context, + progressManager, + progressProcessName, + updateStatus, + downloadAsset, // optional +}); +``` + +# Exports + +| Export | Description | +|--------|-------------| +| `exportSpaceStructure` | Async function to export space structure for given linked workspaces. | +| `AssetManagementAdapter` | Class to call the Asset Management API (getSpace, getWorkspaceFields, getWorkspaceAssets, etc.). | +| Types from `./types` | `AssetManagementExportOptions`, `ExportSpaceOptions`, `ChunkedJsonWriteOptions`, `LinkedWorkspace`, `SpaceResponse`, `FieldsResponse`, `AssetTypesResponse`, and related API types. | \ No newline at end of file diff --git a/packages/contentstack-asset-management/src/import/workspaces.ts b/packages/contentstack-asset-management/src/import/workspaces.ts index 381771d30..369afe15e 100644 --- a/packages/contentstack-asset-management/src/import/workspaces.ts +++ b/packages/contentstack-asset-management/src/import/workspaces.ts @@ -66,20 +66,6 @@ export default class ImportWorkspace extends CSAssetsImportAdapter { assetsImporter.setProcessName(spaceProcessName); } - // Map source default space → existing target default space (cross-org migration). - // The caller supplies the uid of the pre-existing target default space; we upload - // source assets into it instead of creating a new space. - if (isDefault && targetDefaultSpaceUid) { - const newSpaceUid = targetDefaultSpaceUid; - const resolvedWorkspaceUid = targetDefaultWorkspaceUid ?? workspaceUid; - log.info( - `Source default space "${oldSpaceUid}" mapped to existing target default space "${newSpaceUid}".`, - this.importContext.context, - ); - const { uidMap, urlMap } = await assetsImporter.start(newSpaceUid, spaceDir); - return { oldSpaceUid, newSpaceUid, workspaceUid: resolvedWorkspaceUid, isDefault: true, uidMap, urlMap }; - } - // Reuse: target org already has a space with the same uid as the export directory. if (existingSpaceUids.has(oldSpaceUid)) { log.info( @@ -100,6 +86,20 @@ export default class ImportWorkspace extends CSAssetsImportAdapter { urlMap, }; } + + // Map source default space → existing target default space (cross-org migration). + // The caller supplies the uid of the pre-existing target default space; we upload + // source assets into it instead of creating a new space. + if (isDefault && targetDefaultSpaceUid) { + const newSpaceUid = targetDefaultSpaceUid; + const resolvedWorkspaceUid = targetDefaultWorkspaceUid ?? workspaceUid; + log.info( + `Source default space "${oldSpaceUid}" mapped to existing target default space "${newSpaceUid}".`, + this.importContext.context, + ); + const { uidMap, urlMap } = await assetsImporter.start(newSpaceUid, spaceDir); + return { oldSpaceUid, newSpaceUid, workspaceUid: resolvedWorkspaceUid, isDefault: true, uidMap, urlMap }; + } // Create new space with exact exported title log.debug(`Creating space "${exportedTitle}" (old uid: ${oldSpaceUid})`, this.importContext.context);