Skip to content

Commit 38164bc

Browse files
authored
feat: Add support for vanity_name when creating shared-links (#524)
1 parent f7b1b44 commit 38164bc

13 files changed

Lines changed: 30 additions & 12 deletions

File tree

‎src/commands/files/share.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ FilesShareCommand.aliases = [
2626
];
2727

2828
FilesShareCommand.description = 'Create a shared link for a file';
29-
FilesShareCommand.examples = ['box files:share 11111 --access company'];
29+
FilesShareCommand.examples = ['box files:share 11111 --access company --vanity-name my-custom-name-123'];
3030
FilesShareCommand._endpoint = 'put_files_id create_shared_link';
3131

3232
FilesShareCommand.flags = {

‎src/commands/folders/share.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ FoldersShareCommand.aliases = [
2626
];
2727

2828
FoldersShareCommand.description = 'Create a shared link for a folder';
29-
FoldersShareCommand.examples = ['box folders:share 22222 --access company'];
29+
FoldersShareCommand.examples = ['box folders:share 22222 --access company --vanity-name my-custom-name-123'];
3030
FoldersShareCommand._endpoint = 'put_folders_id create_shared_link';
3131

3232
FoldersShareCommand.flags = {

‎src/commands/shared-links/create.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class SharedLinksCreateCommand extends BoxCommand {
1717
SharedLinksCreateCommand.aliases = ['shared-links:update'];
1818

1919
SharedLinksCreateCommand.description = 'Create a shared link for a Box item';
20-
SharedLinksCreateCommand.examples = ['box shared-links:create 22222 folder --access company'];
20+
SharedLinksCreateCommand.examples = ['box shared-links:create 22222 folder --access company --vanity-name my-custom-name-123'];
2121

2222
const sharedLinkFlags = {
2323
...BoxCommand.flags,
@@ -30,7 +30,10 @@ const sharedLinkFlags = {
3030
'can-download': flags.boolean({
3131
description: 'Whether the shared link allows downloads',
3232
allowNo: true
33-
})
33+
}),
34+
'vanity-name': flags.string({
35+
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.'
36+
}),
3437
};
3538

3639
const sharedLinkFileFlags = {

‎src/modules/shared-links.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class SharedLinksModule {
3636
if (flags.hasOwnProperty('can-download')) {
3737
updates.shared_link.permissions.can_download = flags['can-download'];
3838
}
39+
if (flags['vanity-name']) {
40+
updates.shared_link.vanity_name = flags['vanity-name'];
41+
}
3942

4043
if (args.itemType === 'file') {
4144
if (flags.hasOwnProperty('can-edit')) {

‎test/commands/files.test.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@ describe('Files', () => {
10361036
], function(command) {
10371037
describe(command, () => {
10381038
let fileId = '1234567890',
1039+
vanityName = 'my-custom-name-123',
10391040
unsharedDate = '2030-11-18T19:44:17+00:00',
10401041
createSharedLinkFixture = getFixture('files/put_files_id_shared_link'),
10411042
jsonOutput = getFixture('output/files_share_json.txt'),
@@ -1044,7 +1045,8 @@ describe('Files', () => {
10441045
shared_link: {
10451046
permissions: {can_download: true, can_edit: true},
10461047
access: 'test',
1047-
password: 'test'
1048+
password: 'test',
1049+
vanity_name: vanityName
10481050
}
10491051
};
10501052
test
@@ -1059,6 +1061,7 @@ describe('Files', () => {
10591061
'--access=test',
10601062
'--password=test',
10611063
'--can-download',
1064+
`--vanity-name=${vanityName}`,
10621065
'--can-edit',
10631066
'--json',
10641067
'--token=test'
@@ -1078,6 +1081,7 @@ describe('Files', () => {
10781081
'--access=test',
10791082
'--password=test',
10801083
'--can-download',
1084+
`--vanity-name=${vanityName}`,
10811085
'--can-edit',
10821086
'--token=test'
10831087
])

‎test/commands/folders.test.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ describe('Folders', () => {
893893

894894
describe(command, () => {
895895
let folderId = '0',
896+
vanityName = 'my-custom-name-123',
896897
createSharedLinkFixture = getFixture('folders/put_folders_id_shared_link'),
897898
unshareDate = '2030-03-04T12:34:56+00:00',
898899
jsonOutput = getFixture('output/folders_share_json.txt'),
@@ -902,7 +903,8 @@ describe('Folders', () => {
902903
shared_link: {
903904
permissions: { can_download: true },
904905
access: 'test',
905-
password: 'test'
906+
password: 'test',
907+
vanity_name: vanityName
906908
}
907909
};
908910

@@ -918,6 +920,7 @@ describe('Folders', () => {
918920
'--access=test',
919921
'--password=test',
920922
'--can-download',
923+
`--vanity-name=${vanityName}`,
921924
'--json',
922925
'--token=test'
923926
])
@@ -937,6 +940,7 @@ describe('Folders', () => {
937940
'--access=test',
938941
'--password=test',
939942
'--can-download',
943+
`--vanity-name=${vanityName}`,
940944
'--token=test'
941945
])
942946
.it('should create a shared link for a Box item with access, password and can-download flags passed (YAML Output)', ctx => {

‎test/commands/shared-links.test.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe('Shared-Links', () => {
5050

5151
describe('shared-links:create', () => {
5252
let fileId = '1234567890',
53+
vanityName = 'my-custom-name-123',
5354
createFileSharedLinkFixture = getFixture(
5455
'files/put_files_id_shared_link'
5556
),
@@ -59,6 +60,7 @@ describe('Shared-Links', () => {
5960
let fileSharedLinkBody = {
6061
shared_link: {
6162
permissions: { can_download: true, can_edit: true },
63+
vanity_name: vanityName
6264
},
6365
};
6466

@@ -75,6 +77,7 @@ describe('Shared-Links', () => {
7577
'file',
7678
'--can-download',
7779
'--can-edit',
80+
`--vanity-name=${vanityName}`,
7881
'--token=test',
7982
])
8083
.it('should create a shared link for a Box file (YAML Output)', (ctx) => {
@@ -94,6 +97,7 @@ describe('Shared-Links', () => {
9497
'file',
9598
'--can-download',
9699
'--can-edit',
100+
`--vanity-name=${vanityName}`,
97101
'--token=test',
98102
'--json',
99103
])

‎test/fixtures/files/put_files_id_shared_link.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"shared_link": {
55
"url": "https://blosserdemoaccount.box.com/s/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p",
66
"download_url": "https://blosserdemoaccount.box.com/shared/static/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p.png",
7-
"vanity_url": null,
7+
"vanity_url": "https://app.box.com/v/my-custom-name-123",
88
"effective_access": "open",
99
"is_password_enabled": true,
1010
"unshared_at": null,

‎test/fixtures/folders/put_folders_id_shared_link.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"shared_link": {
55
"url": "https://blosserdemoaccount.box.com/s/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p",
66
"download_url": "https://blosserdemoaccount.box.com/shared/static/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p.png",
7-
"vanity_url": null,
7+
"vanity_url": "https://app.box.com/v/my-custom-name-123",
88
"effective_access": "open",
99
"is_password_enabled": true,
1010
"unshared_at": null,

‎test/fixtures/output/files_share_json.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"shared_link": {
55
"url": "https://blosserdemoaccount.box.com/s/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p",
66
"download_url": "https://blosserdemoaccount.box.com/shared/static/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p.png",
7-
"vanity_url": null,
7+
"vanity_url": "https://app.box.com/v/my-custom-name-123",
88
"effective_access": "open",
99
"is_password_enabled": true,
1010
"unshared_at": null,

0 commit comments

Comments
 (0)