From 1352322dcb5d91b7138a348f5b7c0d3bd0385e24 Mon Sep 17 00:00:00 2001 From: naman-contentstack Date: Sun, 7 Jun 2026 03:02:55 +0530 Subject: [PATCH 1/2] refactor: move default space mapping logic to correct position in import workflow --- .../src/import/workspaces.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) 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); From 6c8a833ee06e6c7b981fae40ebae5b5c4f0be432 Mon Sep 17 00:00:00 2001 From: naman-contentstack Date: Tue, 9 Jun 2026 14:45:33 +0530 Subject: [PATCH 2/2] revert: readme file --- .../contentstack-asset-management/README.md | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 packages/contentstack-asset-management/README.md 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