-
Notifications
You must be signed in to change notification settings - Fork 4
SP-2354: Add export and import bookmarks commands #404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Roberto Welzel Filho (roberto-welzel)
merged 6 commits into
main
from
sp-2354-export-import-bookmarks
Aug 7, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8a506ce
SP-2354: Add export and import bookmarks commands
roberto-welzel 7db5035
SP-2354: Fix SonarCloud quality gate issues
roberto-welzel 2f75b9c
SP-2354: Use try/await/catch and preserve error cause
roberto-welzel 4e39c05
SP-2354: Fix remaining SonarCloud issues
roberto-welzel f733b8b
SP-2354: Remove error cause for codebase consistency
roberto-welzel 09db219
SP-2354: Add documentation, CODEOWNERS, and command graph
roberto-welzel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Bookmark Commands | ||
|
|
||
| ## Export Bookmarks | ||
|
|
||
| Export all bookmarks for a package. The exported file can then be imported into another team using the `import bookmarks` command. | ||
|
|
||
| ``` | ||
| content-cli export bookmarks -p <profile> --packageKey <packageKey> | ||
| ``` | ||
|
|
||
| By default, the export is saved to `bookmarks-<packageKey>.json` in the current directory. Use `-f` to specify a custom output path: | ||
|
|
||
| ``` | ||
| content-cli export bookmarks -p <profile> --packageKey <packageKey> -f my-bookmarks.json | ||
| ``` | ||
|
|
||
| ## Import Bookmarks | ||
|
|
||
| Import bookmarks into a package from a previously exported JSON file. | ||
|
|
||
| ``` | ||
| content-cli import bookmarks -p <profile> --packageKey <packageKey> -f bookmarks-<packageKey>.json | ||
| ``` | ||
|
|
||
| The import result is printed to the console showing the status of each entry (CREATED or SKIPPED). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { HttpClient } from "../../core/http/http-client"; | ||
| import { Context } from "../../core/command/cli-context"; | ||
| import { FatalError } from "../../core/utils/logger"; | ||
| import { BookmarksExport, BookmarksImportRequest, BookmarksImportResult } from "./bookmarks.interfaces"; | ||
|
|
||
| export class BookmarksApi { | ||
|
|
||
| private readonly httpClient: () => HttpClient; | ||
|
|
||
| constructor(context: Context) { | ||
| this.httpClient = () => context.httpClient; | ||
| } | ||
|
|
||
| public async exportBookmarks(packageKey: string): Promise<BookmarksExport> { | ||
| try { | ||
| return await this.httpClient().get(`/package-manager/api/packages/${encodeURIComponent(packageKey)}/bookmarks/export`); | ||
| } catch (e) { | ||
| throw new FatalError(`Problem exporting bookmarks for package ${packageKey}: ${e}`); | ||
| } | ||
| } | ||
|
|
||
| public async importBookmarks(packageKey: string, payload: BookmarksImportRequest): Promise<BookmarksImportResult> { | ||
| try { | ||
| return await this.httpClient().post(`/package-manager/api/packages/${encodeURIComponent(packageKey)}/bookmarks/import`, payload); | ||
| } catch (e) { | ||
| throw new FatalError(`Problem importing bookmarks for package ${packageKey}: ${e}`); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { Context } from "../../core/command/cli-context"; | ||
| import { BookmarksApi } from "./bookmarks-api"; | ||
| import { fileService, FileService } from "../../core/utils/file-service"; | ||
| import { logger } from "../../core/utils/logger"; | ||
|
|
||
| export class BookmarksCommandService { | ||
|
|
||
| private readonly bookmarksApi: BookmarksApi; | ||
|
|
||
| constructor(context: Context) { | ||
| this.bookmarksApi = new BookmarksApi(context); | ||
| } | ||
|
|
||
| public async exportBookmarks(packageKey: string, file?: string): Promise<void> { | ||
| const exportData = await this.bookmarksApi.exportBookmarks(packageKey); | ||
|
|
||
| const fileName = file ?? `bookmarks-${packageKey}.json`; | ||
| fileService.writeToFileWithGivenName(JSON.stringify(exportData, null, 4), fileName); | ||
| logger.info(FileService.fileDownloadedMessage + fileName); | ||
| } | ||
|
|
||
| public async importBookmarks(packageKey: string, file: string): Promise<void> { | ||
| const payload = fileService.readFileToJson(file); | ||
|
tneum-celonis marked this conversation as resolved.
|
||
| const result = await this.bookmarksApi.importBookmarks(packageKey, payload); | ||
| logger.info(`Bookmarks imported successfully: ${JSON.stringify(result, null, 4)}`); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| export interface BookmarkEntry { | ||
| assetKey: string; | ||
| assetType: string; | ||
| bookmark: BookmarkDetails; | ||
| preference: BookmarkPreference; | ||
| } | ||
|
|
||
| export interface BookmarkDetails { | ||
| name: string; | ||
| ownerId: string; | ||
| sharedByLink: boolean; | ||
| published: boolean; | ||
| } | ||
|
|
||
| export interface BookmarkPreference { | ||
| configuration: string; | ||
| shareable: boolean; | ||
| mode: string; | ||
| userId: string; | ||
| } | ||
|
|
||
| export interface BookmarksExport { | ||
| packageKey: string; | ||
| entries: BookmarkEntry[]; | ||
| } | ||
|
|
||
| export interface BookmarksImportRequest { | ||
| entries: BookmarkEntry[]; | ||
| } | ||
|
|
||
| export interface BookmarksImportResultEntry { | ||
| assetKey: string; | ||
| status: string; | ||
| reason: string | null; | ||
| } | ||
|
|
||
| export interface BookmarksImportResult { | ||
| packageKey: string; | ||
| entries: BookmarksImportResultEntry[]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { Configurator, IModule } from "../../core/command/module-handler"; | ||
| import { Context } from "../../core/command/cli-context"; | ||
| import { Command, OptionValues } from "commander"; | ||
| import { BookmarksCommandService } from "./bookmarks-command.service"; | ||
|
|
||
| class Module extends IModule { | ||
|
|
||
| public register(context: Context, configurator: Configurator): void { | ||
| const exportCommand = configurator.command("export"); | ||
| exportCommand.command("bookmarks") | ||
| .description("Export bookmarks for a package") | ||
| .requiredOption("--packageKey <packageKey>", "Key of the package to export bookmarks from") | ||
| .option("-f, --file <file>", "Output file path (defaults to bookmarks-<packageKey>.json)") | ||
| .action(this.exportBookmarks); | ||
|
|
||
| const importCommand = configurator.command("import"); | ||
| importCommand.command("bookmarks") | ||
| .description("Import bookmarks into a package") | ||
| .requiredOption("--packageKey <packageKey>", "Key of the package to import bookmarks into") | ||
| .requiredOption("-f, --file <file>", "Bookmarks JSON file to import") | ||
| .action(this.importBookmarks); | ||
| } | ||
|
|
||
| private async exportBookmarks(context: Context, _command: Command, options: OptionValues): Promise<void> { | ||
| await new BookmarksCommandService(context).exportBookmarks(options.packageKey, options.file); | ||
| } | ||
|
|
||
| private async importBookmarks(context: Context, _command: Command, options: OptionValues): Promise<void> { | ||
| await new BookmarksCommandService(context).importBookmarks(options.packageKey, options.file); | ||
| } | ||
| } | ||
|
|
||
| export = Module; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.