@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
71 lines (69 loc) • 2.46 kB
JavaScript
import { defer, of } from 'rxjs';
import { map, mergeMap, switchMap } from 'rxjs/operators';
/**
* Node extension install class.
*/
export class NodeExtensionInstall {
appContext;
static installUrl = 'features/extensions/{0}/versions/{1}/install';
/**
* Initializes a new instance of the NodeExtensionInstall class.
*
* @param appContext the application context.
*/
constructor(appContext) {
this.appContext = appContext;
}
/**
* Install a node package of extensions. (elevate the desktop gateway if required.)
*
* @param nodeName the name of node.
* @param extension the name of extension.
* @param version the version of extension.
* @param options the node request options (optional).
*/
install(nodeName, extension, version, options) {
const install = defer(() => this.installCall(nodeName, extension, version, options));
let result = null;
return this.appContext.gateway.checkCondition()
.pipe(mergeMap(data => {
result = data;
if (result.isServiceMode) {
if (result.isGatewayAdmin) {
return install;
}
// cannot support this user.
return of(null);
}
if (result.isGatewayProcessElevated) {
return install;
}
// on-demand elevate and install.
return this.appContext.gateway.elevate()
.pipe(switchMap(elevated => {
if (elevated) {
result.isGatewayProcessElevated = true;
return install;
}
// user rejected to elevate.
return of(result);
}));
}), map(installed => {
result.response = installed;
return result;
}));
}
/**
* Install a node package of extensions.(doesn't handle elevation for the desktop mode.)
*
* @param nodeName the name of node.
* @param extension the name of extension.
* @param version the version of extension.
* @param options the node request options (optional).
*/
installCall(nodeName, extension, version, options) {
const url = NodeExtensionInstall.installUrl.format(extension, version);
return this.appContext.node.post(nodeName, url, null, options);
}
}
//# sourceMappingURL=node-extension-install.js.map