-
Notifications
You must be signed in to change notification settings - Fork 308
/
hubsite-data-get.ts
132 lines (106 loc) · 3.86 KB
/
hubsite-data-get.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import request from '../../../../request';
import commands from '../../commands';
import {
CommandOption, CommandValidate
} from '../../../../Command';
import SpoCommand from '../../../base/SpoCommand';
import GlobalOptions from '../../../../GlobalOptions';
const vorpal: Vorpal = require('../../../../vorpal-init');
interface CommandArgs {
options: Options;
}
interface Options extends GlobalOptions {
webUrl: string;
forceRefresh?: boolean;
}
class SpoHubSiteDataGetCommand extends SpoCommand {
public get name(): string {
return `${commands.HUBSITE_DATA_GET}`;
}
public get description(): string {
return 'Get hub site data for the specified site';
}
public getTelemetryProperties(args: CommandArgs): any {
const telemetryProps: any = super.getTelemetryProperties(args);
telemetryProps.forceRefresh = args.options.forceRefresh === true;
return telemetryProps;
}
public commandAction(cmd: CommandInstance, args: CommandArgs, cb: () => void): void {
if (this.verbose) {
cmd.log('Retrieving hub site data...');
}
const forceRefresh: boolean = args.options.forceRefresh === true;
const requestOptions: any = {
url: `${args.options.webUrl}/_api/web/HubSiteData(${forceRefresh})`,
headers: {
accept: 'application/json;odata=nometadata'
},
json: true
};
request
.get(requestOptions)
.then((res: any): void => {
if (res['odata.null'] !== true) {
cmd.log(JSON.parse(res.value));
}
else {
if (this.verbose) {
cmd.log(`${args.options.webUrl} is not connected to a hub site and is not a hub site itself`);
}
}
if (this.verbose) {
cmd.log(vorpal.chalk.green('DONE'));
}
cb();
}, (err: any): void => this.handleRejectedODataJsonPromise(err, cmd, cb));
}
public options(): CommandOption[] {
const options: CommandOption[] = [
{
option: '-u, --webUrl <webUrl>',
description: 'URL of the site for which to retrieve hub site data'
},
{
option: '-f, --forceRefresh',
description: `Set, to refresh the server cache with the latest updates`
}
];
const parentOptions: CommandOption[] = super.options();
return options.concat(parentOptions);
}
public validate(): CommandValidate {
return (args: CommandArgs): boolean | string => {
if (!args.options.webUrl) {
return 'Required parameter webUrl missing';
}
const isValidSharePointUrl: boolean | string = SpoCommand.isValidSharePointUrl(args.options.webUrl);
if (isValidSharePointUrl !== true) {
return isValidSharePointUrl;
}
return true;
};
}
public commandHelp(args: {}, log: (help: string) => void): void {
const chalk = vorpal.chalk;
log(vorpal.find(this.name).helpInformation());
log(
` Remarks:
${chalk.yellow('Attention:')} This command is based on a SharePoint API that is currently
in preview and is subject to change once the API reached general
availability.
By default, the hub site data is returned from the server's cache.
To refresh the data with the latest updates, use the ${chalk.blue('-f, --forceRefresh')}
option. Use this option, if you just made changes and need to see them right
away.
If the specified site is not connected to a hub site site and is not a hub
site itself, no data will be retrieved.
Examples:
Get information about the hub site data for a site with URL ${chalk.grey('https://contoso.sharepoint.com/sites/project-x')}
${this.name} --webUrl https://contoso.sharepoint.com/sites/project-x
More information:
SharePoint hub sites new in Office 365
https://techcommunity.microsoft.com/t5/SharePoint-Blog/SharePoint-hub-sites-new-in-Office-365/ba-p/109547
`);
}
}
module.exports = new SpoHubSiteDataGetCommand();