Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions packages/contentstack-asset-management/README.md
Original file line number Diff line number Diff line change
@@ -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)

<!-- toc -->
* [@contentstack/cli-asset-management](#contentstackcli-asset-management)
* [Overview](#overview)
* [Usage](#usage)
* [Exports](#exports)
<!-- tocstop -->

# 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. |
28 changes: 14 additions & 14 deletions packages/contentstack-asset-management/src/import/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down
Loading