Skip to content
Open
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
18 changes: 15 additions & 3 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
fileignoreconfig:
- filename: package-lock.json
checksum: 45100667793fc7dfaae3e24787871257e7f29e06df69ba10ec05b358d59ff15d
- filename: pnpm-lock.yaml
checksum: 87d001c32b1d7f9df30a289c277e0ea13cfd8a0e2e5fa5118956ff4183683e5c
checksum: 601217277684d397a213756ac3bf9e0048c5bd1637dbc8ad1dff0fb864354557
- filename: packages/contentstack-asset-management/src/utils/export-helpers.ts
checksum: 1a533a4e4d56a952f61ced63aa6f1bc8fbb3855fd7acecdd9fd40dd71e5fab6d
- filename: packages/contentstack-export/src/export/modules/stack.ts
checksum: 82f7df78993942debb79e690c8c27d0998157428ef506d0b07ea31d5a1f71aba
- filename: packages/contentstack-asset-management/src/export/base.ts
checksum: fcae2679bdeb93a6786cb290b60ba98f222a9c682552c6474370d17bf59ae1b4
- filename: packages/contentstack-asset-management/src/utils/asset-management-api-adapter.ts
checksum: 6f5e11d3685b6093d6c4def7fc4199f673d9a56e5fbc2858ed72f69d764f1260
- filename: packages/contentstack-asset-management/src/types/export-types.ts
checksum: d00ca608006d864f516e21b76d552c0ecf52ff89b3dcb361ed11ac600abed989
- filename: packages/contentstack-asset-management/test/unit/utils/export-helpers.test.ts
checksum: 0e8751163491fc45e7ae3999282d336ae1ab8a9f88e601cbb85b4f44e8db96b8
- filename: packages/contentstack-asset-management/test/unit/utils/asset-management-api-adapter.test.ts
checksum: fb076af66b4ffa5cf4a8e43d70dd5aa76d97ce30e0fb519dbdcbb316585ab4e2
version: '1.0'
128 changes: 118 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/contentstack-asset-management/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib/
node_modules/
*.tsbuildinfo
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. |
47 changes: 47 additions & 0 deletions packages/contentstack-asset-management/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@contentstack/cli-asset-management",
"version": "1.0.0",
"description": "Asset Management 2.0 API adapter for export and import",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib",
"oclif.manifest.json"
],
"scripts": {
"prepack": "pnpm compile && oclif manifest && oclif readme",
"compile": "tsc -b tsconfig.json",
"clean": "rm -rf ./lib ./node_modules tsconfig.build.tsbuildinfo",
"test": "mocha --require ts-node/register --forbid-only \"test/**/*.test.ts\"",
"test:unit:report": "nyc --extension .ts mocha --require ts-node/register --forbid-only \"test/unit/**/*.test.ts\""
},
"keywords": [
"contentstack",
"asset-management",
"cli"
],
"license": "MIT",
"dependencies": {
"@contentstack/cli-utilities": "~2.0.0-beta"
},
"oclif": {
"commands": "./lib/commands",
"bin": "csdx",
"devPlugins": [
"@oclif/plugin-help"
],
"repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-asset-management/<%- commandPath %>"
},
"devDependencies": {
"@types/chai": "^4.3.11",
"@types/mocha": "^10.0.6",
"@types/node": "^20.17.50",
"@types/sinon": "^17.0.2",
"chai": "^4.4.1",
"mocha": "^10.8.2",
"nyc": "^15.1.0",
"sinon": "^17.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.8.3"
}
}
47 changes: 47 additions & 0 deletions packages/contentstack-asset-management/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Main process name for Asset Management 2.0 export (single progress bar).
* Use this when adding/starting the process and for all ticks.
*/
export const AM_MAIN_PROCESS_NAME = 'Asset Management 2.0';

/**
* Process names for Asset Management 2.0 export progress (for tick labels).
*/
export const PROCESS_NAMES = {
AM_SPACE_METADATA: 'Space metadata',
AM_FOLDERS: 'Folders',
AM_ASSETS: 'Assets',
AM_FIELDS: 'Fields',
AM_ASSET_TYPES: 'Asset types',
AM_DOWNLOADS: 'Asset downloads',
} as const;

/**
* Status messages for each process (exporting, fetching, failed).
*/
export const PROCESS_STATUS = {
[PROCESS_NAMES.AM_SPACE_METADATA]: {
EXPORTING: 'Exporting space metadata...',
FAILED: 'Failed to export space metadata.',
},
[PROCESS_NAMES.AM_FOLDERS]: {
FETCHING: 'Fetching folders...',
FAILED: 'Failed to fetch folders.',
},
[PROCESS_NAMES.AM_ASSETS]: {
FETCHING: 'Fetching assets...',
FAILED: 'Failed to fetch assets.',
},
[PROCESS_NAMES.AM_FIELDS]: {
FETCHING: 'Fetching fields...',
FAILED: 'Failed to fetch fields.',
},
[PROCESS_NAMES.AM_ASSET_TYPES]: {
FETCHING: 'Fetching asset types...',
FAILED: 'Failed to fetch asset types.',
},
[PROCESS_NAMES.AM_DOWNLOADS]: {
DOWNLOADING: 'Downloading asset files...',
FAILED: 'Failed to download assets.',
},
} as const;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { log } from '@contentstack/cli-utilities';

import type { AssetManagementAPIConfig } from '../types/asset-management-api';
import type { ExportContext } from '../types/export-types';
import { AssetManagementExportAdapter } from './base';
import { getArrayFromResponse } from '../utils/export-helpers';
import { PROCESS_NAMES } from '../constants/index';

export default class ExportAssetTypes extends AssetManagementExportAdapter {
constructor(apiConfig: AssetManagementAPIConfig, exportContext: ExportContext) {
super(apiConfig, exportContext);
}

async start(spaceUid: string): Promise<void> {
await this.init();
const assetTypesData = await this.getWorkspaceAssetTypes(spaceUid);
const items = getArrayFromResponse(assetTypesData, 'asset_types');
const dir = this.getAssetTypesDir();
log.debug(
items.length === 0
? 'No asset types, wrote empty asset-types'
: `Writing ${items.length} shared asset types`,
this.exportContext.context,
);
await this.writeItemsToChunkedJson(dir, 'asset-types.json', 'asset_types', ['uid', 'title', 'category', 'file_extension'], items);
this.tick(true, PROCESS_NAMES.AM_ASSET_TYPES, null);
}
}
Loading