From 53548200e2b78c28d86472f09347041ac81cc5eb Mon Sep 17 00:00:00 2001 From: Artur Jankowski Date: Fri, 1 Mar 2024 16:45:43 +0100 Subject: [PATCH] feat: Add support for `vanity_name` when creating `shared-links` --- src/commands/folders/share.js | 2 +- src/commands/shared-links/create.js | 7 +++++-- src/modules/shared-links.js | 3 +++ test/commands/files.test.js | 5 ++++- test/commands/folders.test.js | 5 ++++- test/commands/shared-links.test.js | 3 +++ test/fixtures/files/put_files_id_shared_link.json | 2 +- test/fixtures/folders/put_folders_id_shared_link.json | 2 +- test/fixtures/output/files_share_json.txt | 2 +- test/fixtures/output/files_share_yaml.txt | 2 +- test/fixtures/output/folders_share_json.txt | 2 +- test/fixtures/output/folders_share_yaml.txt | 2 +- 12 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/commands/folders/share.js b/src/commands/folders/share.js index 0270c06d..8987bbac 100644 --- a/src/commands/folders/share.js +++ b/src/commands/folders/share.js @@ -26,7 +26,7 @@ FoldersShareCommand.aliases = [ ]; FoldersShareCommand.description = 'Create a shared link for a folder'; -FoldersShareCommand.examples = ['box folders:share 22222 --access company']; +FoldersShareCommand.examples = ['box folders:share 22222 --access company --vanity-name my-custom-name-123']; FoldersShareCommand._endpoint = 'put_folders_id create_shared_link'; FoldersShareCommand.flags = { diff --git a/src/commands/shared-links/create.js b/src/commands/shared-links/create.js index 4e3931d9..85b09937 100644 --- a/src/commands/shared-links/create.js +++ b/src/commands/shared-links/create.js @@ -17,7 +17,7 @@ class SharedLinksCreateCommand extends BoxCommand { SharedLinksCreateCommand.aliases = ['shared-links:update']; SharedLinksCreateCommand.description = 'Create a shared link for a Box item'; -SharedLinksCreateCommand.examples = ['box shared-links:create 22222 folder --access company']; +SharedLinksCreateCommand.examples = ['box shared-links:create 22222 folder --access company --vanity-name my-custom-name-123']; const sharedLinkFlags = { ...BoxCommand.flags, @@ -30,7 +30,10 @@ const sharedLinkFlags = { 'can-download': flags.boolean({ description: 'Whether the shared link allows downloads', allowNo: true - }) + }), + 'vanity-name': flags.string({ + description: 'Defines a custom vanity name to use in the shared link URL. It should be between 12 and 30 characters. This field can contains only letters, numbers and hyphens.' + }), }; const sharedLinkFileFlags = { diff --git a/src/modules/shared-links.js b/src/modules/shared-links.js index 5784bd38..594c8f2e 100644 --- a/src/modules/shared-links.js +++ b/src/modules/shared-links.js @@ -36,6 +36,9 @@ class SharedLinksModule { if (flags.hasOwnProperty('can-download')) { updates.shared_link.permissions.can_download = flags['can-download']; } + if (flags['vanity-name']) { + updates.shared_link.vanity_name = flags['vanity-name']; + } if (args.itemType === 'file') { if (flags.hasOwnProperty('can-edit')) { diff --git a/test/commands/files.test.js b/test/commands/files.test.js index 662da8ae..b6348f3b 100644 --- a/test/commands/files.test.js +++ b/test/commands/files.test.js @@ -1036,6 +1036,7 @@ describe('Files', () => { ], function(command) { describe(command, () => { let fileId = '1234567890', + vanityName = 'my-custom-name-123', unsharedDate = '2030-11-18T19:44:17+00:00', createSharedLinkFixture = getFixture('files/put_files_id_shared_link'), jsonOutput = getFixture('output/files_share_json.txt'), @@ -1044,7 +1045,8 @@ describe('Files', () => { shared_link: { permissions: {can_download: true, can_edit: true}, access: 'test', - password: 'test' + password: 'test', + vanity_name: vanityName } }; test @@ -1059,6 +1061,7 @@ describe('Files', () => { '--access=test', '--password=test', '--can-download', + `--vanity-name=${vanityName}`, '--can-edit', '--json', '--token=test' diff --git a/test/commands/folders.test.js b/test/commands/folders.test.js index c8982535..f5f51153 100644 --- a/test/commands/folders.test.js +++ b/test/commands/folders.test.js @@ -893,6 +893,7 @@ describe('Folders', () => { describe(command, () => { let folderId = '0', + vanityName = 'my-custom-name-123', createSharedLinkFixture = getFixture('folders/put_folders_id_shared_link'), unshareDate = '2030-03-04T12:34:56+00:00', jsonOutput = getFixture('output/folders_share_json.txt'), @@ -902,7 +903,8 @@ describe('Folders', () => { shared_link: { permissions: { can_download: true }, access: 'test', - password: 'test' + password: 'test', + vanity_name: vanityName } }; @@ -918,6 +920,7 @@ describe('Folders', () => { '--access=test', '--password=test', '--can-download', + `--vanity-name=${vanityName}`, '--json', '--token=test' ]) diff --git a/test/commands/shared-links.test.js b/test/commands/shared-links.test.js index a9c0b9ce..b9073add 100644 --- a/test/commands/shared-links.test.js +++ b/test/commands/shared-links.test.js @@ -50,6 +50,7 @@ describe('Shared-Links', () => { describe('shared-links:create', () => { let fileId = '1234567890', + vanityName = 'my-custom-name-123', createFileSharedLinkFixture = getFixture( 'files/put_files_id_shared_link' ), @@ -59,6 +60,7 @@ describe('Shared-Links', () => { let fileSharedLinkBody = { shared_link: { permissions: { can_download: true, can_edit: true }, + vanity_name: vanityName }, }; @@ -75,6 +77,7 @@ describe('Shared-Links', () => { 'file', '--can-download', '--can-edit', + `--vanity-name=${vanityName}`, '--token=test', ]) .it('should create a shared link for a Box file (YAML Output)', (ctx) => { diff --git a/test/fixtures/files/put_files_id_shared_link.json b/test/fixtures/files/put_files_id_shared_link.json index b5ca5b7e..8f79adc5 100644 --- a/test/fixtures/files/put_files_id_shared_link.json +++ b/test/fixtures/files/put_files_id_shared_link.json @@ -4,7 +4,7 @@ "shared_link": { "url": "https://blosserdemoaccount.box.com/s/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p", "download_url": "https://blosserdemoaccount.box.com/shared/static/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p.png", - "vanity_url": null, + "vanity_url": "https://app.box.com/v/my-custom-name-123", "effective_access": "open", "is_password_enabled": true, "unshared_at": null, diff --git a/test/fixtures/folders/put_folders_id_shared_link.json b/test/fixtures/folders/put_folders_id_shared_link.json index 834d3f15..8de9faea 100644 --- a/test/fixtures/folders/put_folders_id_shared_link.json +++ b/test/fixtures/folders/put_folders_id_shared_link.json @@ -4,7 +4,7 @@ "shared_link": { "url": "https://blosserdemoaccount.box.com/s/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p", "download_url": "https://blosserdemoaccount.box.com/shared/static/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p.png", - "vanity_url": null, + "vanity_url": "https://app.box.com/v/my-custom-name-123", "effective_access": "open", "is_password_enabled": true, "unshared_at": null, diff --git a/test/fixtures/output/files_share_json.txt b/test/fixtures/output/files_share_json.txt index b5ca5b7e..8f79adc5 100644 --- a/test/fixtures/output/files_share_json.txt +++ b/test/fixtures/output/files_share_json.txt @@ -4,7 +4,7 @@ "shared_link": { "url": "https://blosserdemoaccount.box.com/s/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p", "download_url": "https://blosserdemoaccount.box.com/shared/static/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p.png", - "vanity_url": null, + "vanity_url": "https://app.box.com/v/my-custom-name-123", "effective_access": "open", "is_password_enabled": true, "unshared_at": null, diff --git a/test/fixtures/output/files_share_yaml.txt b/test/fixtures/output/files_share_yaml.txt index 6f7980dd..765d9ed3 100644 --- a/test/fixtures/output/files_share_yaml.txt +++ b/test/fixtures/output/files_share_yaml.txt @@ -4,7 +4,7 @@ Shared Link: URL: 'https://blosserdemoaccount.box.com/s/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p' Download URL: >- https://blosserdemoaccount.box.com/shared/static/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p.png - Vanity URL: null + Vanity URL: 'https://app.box.com/v/my-custom-name-123' Effective Access: open Is Password Enabled: true Unshared At: null diff --git a/test/fixtures/output/folders_share_json.txt b/test/fixtures/output/folders_share_json.txt index 834d3f15..8de9faea 100644 --- a/test/fixtures/output/folders_share_json.txt +++ b/test/fixtures/output/folders_share_json.txt @@ -4,7 +4,7 @@ "shared_link": { "url": "https://blosserdemoaccount.box.com/s/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p", "download_url": "https://blosserdemoaccount.box.com/shared/static/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p.png", - "vanity_url": null, + "vanity_url": "https://app.box.com/v/my-custom-name-123", "effective_access": "open", "is_password_enabled": true, "unshared_at": null, diff --git a/test/fixtures/output/folders_share_yaml.txt b/test/fixtures/output/folders_share_yaml.txt index c2f3a4a9..f497deb2 100644 --- a/test/fixtures/output/folders_share_yaml.txt +++ b/test/fixtures/output/folders_share_yaml.txt @@ -4,7 +4,7 @@ Shared Link: URL: 'https://blosserdemoaccount.box.com/s/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p' Download URL: >- https://blosserdemoaccount.box.com/shared/static/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p.png - Vanity URL: null + Vanity URL: 'https://app.box.com/v/my-custom-name-123' Effective Access: open Is Password Enabled: true Unshared At: null