Skip to content

Commit 3d7b5f0

Browse files
author
naman-contentstack
committed
feat: add asset management package for AM2.0 support
1 parent 0654d88 commit 3d7b5f0

38 files changed

+2518
-46
lines changed

.talismanrc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
fileignoreconfig:
22
- filename: package-lock.json
3-
checksum: 45100667793fc7dfaae3e24787871257e7f29e06df69ba10ec05b358d59ff15d
4-
- filename: pnpm-lock.yaml
5-
checksum: 87d001c32b1d7f9df30a289c277e0ea13cfd8a0e2e5fa5118956ff4183683e5c
3+
checksum: 601217277684d397a213756ac3bf9e0048c5bd1637dbc8ad1dff0fb864354557
4+
- filename: packages/contentstack-asset-management/src/utils/export-helpers.ts
5+
checksum: 1a533a4e4d56a952f61ced63aa6f1bc8fbb3855fd7acecdd9fd40dd71e5fab6d
6+
- filename: packages/contentstack-export/src/export/modules/stack.ts
7+
checksum: 82f7df78993942debb79e690c8c27d0998157428ef506d0b07ea31d5a1f71aba
8+
- filename: packages/contentstack-asset-management/src/export/base.ts
9+
checksum: fcae2679bdeb93a6786cb290b60ba98f222a9c682552c6474370d17bf59ae1b4
10+
- filename: packages/contentstack-asset-management/src/utils/asset-management-api-adapter.ts
11+
checksum: 6f5e11d3685b6093d6c4def7fc4199f673d9a56e5fbc2858ed72f69d764f1260
12+
- filename: packages/contentstack-asset-management/src/types/export-types.ts
13+
checksum: d00ca608006d864f516e21b76d552c0ecf52ff89b3dcb361ed11ac600abed989
14+
- filename: packages/contentstack-asset-management/test/unit/utils/export-helpers.test.ts
15+
checksum: 0e8751163491fc45e7ae3999282d336ae1ab8a9f88e601cbb85b4f44e8db96b8
16+
- filename: packages/contentstack-asset-management/test/unit/utils/asset-management-api-adapter.test.ts
17+
checksum: fb076af66b4ffa5cf4a8e43d70dd5aa76d97ce30e0fb519dbdcbb316585ab4e2
618
version: '1.0'

package-lock.json

Lines changed: 118 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lib/
2+
node_modules/
3+
*.tsbuildinfo
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# @contentstack/cli-asset-management
2+
3+
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/).
4+
5+
[![License](https://img.shields.io/npm/l/@contentstack/cli)](https://github.com/contentstack/cli/blob/main/LICENSE)
6+
7+
<!-- toc -->
8+
* [@contentstack/cli-asset-management](#contentstackcli-asset-management)
9+
* [Overview](#overview)
10+
* [Usage](#usage)
11+
* [Exports](#exports)
12+
<!-- tocstop -->
13+
14+
# Overview
15+
16+
This package provides:
17+
18+
- **AssetManagementAdapter** – HTTP client for the Asset Management API (spaces, assets, folders, fields, asset types).
19+
- **exportSpaceStructure** – Exports space metadata and full workspace structure (metadata, folders, assets, fields, asset types) for linked workspaces.
20+
- **Types**`AssetManagementExportOptions`, `LinkedWorkspace`, `IAssetManagementAdapter`, and related types for export/import integration.
21+
22+
# Usage
23+
24+
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:
25+
26+
```ts
27+
import { exportSpaceStructure } from '@contentstack/cli-asset-management';
28+
29+
await exportSpaceStructure({
30+
linkedWorkspaces,
31+
exportDir,
32+
branchName: 'main',
33+
assetManagementUrl,
34+
org_uid,
35+
context,
36+
progressManager,
37+
progressProcessName,
38+
updateStatus,
39+
downloadAsset, // optional
40+
});
41+
```
42+
43+
# Exports
44+
45+
| Export | Description |
46+
|--------|-------------|
47+
| `exportSpaceStructure` | Async function to export space structure for given linked workspaces. |
48+
| `AssetManagementAdapter` | Class to call the Asset Management API (getSpace, getWorkspaceFields, getWorkspaceAssets, etc.). |
49+
| Types from `./types` | `AssetManagementExportOptions`, `ExportSpaceOptions`, `ChunkedJsonWriteOptions`, `LinkedWorkspace`, `SpaceResponse`, `FieldsResponse`, `AssetTypesResponse`, and related API types. |
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "@contentstack/cli-asset-management",
3+
"version": "1.0.0",
4+
"description": "Asset Management 2.0 API adapter for export and import",
5+
"main": "lib/index.js",
6+
"types": "lib/index.d.ts",
7+
"files": [
8+
"lib",
9+
"oclif.manifest.json"
10+
],
11+
"scripts": {
12+
"prepack": "pnpm compile && oclif manifest && oclif readme",
13+
"compile": "tsc -b tsconfig.json",
14+
"clean": "rm -rf ./lib ./node_modules tsconfig.build.tsbuildinfo",
15+
"test": "mocha --require ts-node/register --forbid-only \"test/**/*.test.ts\"",
16+
"test:unit:report": "nyc --extension .ts mocha --require ts-node/register --forbid-only \"test/unit/**/*.test.ts\""
17+
},
18+
"keywords": [
19+
"contentstack",
20+
"asset-management",
21+
"cli"
22+
],
23+
"license": "MIT",
24+
"dependencies": {
25+
"@contentstack/cli-utilities": "~2.0.0-beta"
26+
},
27+
"oclif": {
28+
"commands": "./lib/commands",
29+
"bin": "csdx",
30+
"devPlugins": [
31+
"@oclif/plugin-help"
32+
],
33+
"repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-asset-management/<%- commandPath %>"
34+
},
35+
"devDependencies": {
36+
"@types/chai": "^4.3.11",
37+
"@types/mocha": "^10.0.6",
38+
"@types/node": "^20.17.50",
39+
"@types/sinon": "^17.0.2",
40+
"chai": "^4.4.1",
41+
"mocha": "^10.8.2",
42+
"nyc": "^15.1.0",
43+
"sinon": "^17.0.1",
44+
"ts-node": "^10.9.2",
45+
"typescript": "^5.8.3"
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Main process name for Asset Management 2.0 export (single progress bar).
3+
* Use this when adding/starting the process and for all ticks.
4+
*/
5+
export const AM_MAIN_PROCESS_NAME = 'Asset Management 2.0';
6+
7+
/**
8+
* Process names for Asset Management 2.0 export progress (for tick labels).
9+
*/
10+
export const PROCESS_NAMES = {
11+
AM_SPACE_METADATA: 'Space metadata',
12+
AM_FOLDERS: 'Folders',
13+
AM_ASSETS: 'Assets',
14+
AM_FIELDS: 'Fields',
15+
AM_ASSET_TYPES: 'Asset types',
16+
AM_DOWNLOADS: 'Asset downloads',
17+
} as const;
18+
19+
/**
20+
* Status messages for each process (exporting, fetching, failed).
21+
*/
22+
export const PROCESS_STATUS = {
23+
[PROCESS_NAMES.AM_SPACE_METADATA]: {
24+
EXPORTING: 'Exporting space metadata...',
25+
FAILED: 'Failed to export space metadata.',
26+
},
27+
[PROCESS_NAMES.AM_FOLDERS]: {
28+
FETCHING: 'Fetching folders...',
29+
FAILED: 'Failed to fetch folders.',
30+
},
31+
[PROCESS_NAMES.AM_ASSETS]: {
32+
FETCHING: 'Fetching assets...',
33+
FAILED: 'Failed to fetch assets.',
34+
},
35+
[PROCESS_NAMES.AM_FIELDS]: {
36+
FETCHING: 'Fetching fields...',
37+
FAILED: 'Failed to fetch fields.',
38+
},
39+
[PROCESS_NAMES.AM_ASSET_TYPES]: {
40+
FETCHING: 'Fetching asset types...',
41+
FAILED: 'Failed to fetch asset types.',
42+
},
43+
[PROCESS_NAMES.AM_DOWNLOADS]: {
44+
DOWNLOADING: 'Downloading asset files...',
45+
FAILED: 'Failed to download assets.',
46+
},
47+
} as const;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { log } from '@contentstack/cli-utilities';
2+
3+
import type { AssetManagementAPIConfig } from '../types/asset-management-api';
4+
import type { ExportContext } from '../types/export-types';
5+
import { AssetManagementExportAdapter } from './base';
6+
import { getArrayFromResponse } from '../utils/export-helpers';
7+
import { PROCESS_NAMES } from '../constants/index';
8+
9+
export default class ExportAssetTypes extends AssetManagementExportAdapter {
10+
constructor(apiConfig: AssetManagementAPIConfig, exportContext: ExportContext) {
11+
super(apiConfig, exportContext);
12+
}
13+
14+
async start(spaceUid: string): Promise<void> {
15+
await this.init();
16+
const assetTypesData = await this.getWorkspaceAssetTypes(spaceUid);
17+
const items = getArrayFromResponse(assetTypesData, 'asset_types');
18+
const dir = this.getAssetTypesDir();
19+
log.debug(
20+
items.length === 0
21+
? 'No asset types, wrote empty asset-types'
22+
: `Writing ${items.length} shared asset types`,
23+
this.exportContext.context,
24+
);
25+
await this.writeItemsToChunkedJson(dir, 'asset-types.json', 'asset_types', ['uid', 'title', 'category', 'file_extension'], items);
26+
this.tick(true, PROCESS_NAMES.AM_ASSET_TYPES, null);
27+
}
28+
}

0 commit comments

Comments
 (0)