UNPKG

@microsoft/windows-admin-center-sdk

Version:

Microsoft - Windows Admin Center Shell

132 lines (130 loc) 4.66 kB
import { Net } from './net'; import { UriBuilder } from './uri-builder'; /** Represents the defined API versions. */ export var ApiVersion; (function (ApiVersion) { /** Gets the API version for 2018-04-01. */ // eslint-disable-next-line @typescript-eslint/naming-convention ApiVersion["v2018_04_01"] = "2018-04-01"; /** Gets the API version for 2019-02-01. */ // eslint-disable-next-line @typescript-eslint/naming-convention ApiVersion["v2019_02_01"] = "2019-02-01"; /** Gets the intial API version (2018-04-01). */ ApiVersion["Initial"] = "2018-04-01"; /** Gets the latest API version (2019-02-01). */ ApiVersion["Latest"] = "2019-02-01"; })(ApiVersion || (ApiVersion = {})); /** Represents an object that can build URL to the gateway. */ export class GatewayUrlBuilder { builder; /** * Initializes a new instance of the GatewayUrlBuilder class. * @param uri The string or URL to initialize the builder from. */ constructor(uri) { this.builder = new UriBuilder(uri); this.builder.appendSegment('api'); this.builder.setQueryParameter('api-version', ApiVersion.Latest); } /** * Indicates the builder should use a specified API version. * @param apiVersion The API version to use. * @returns The original builder. */ useApiVersion(apiVersion) { this.builder.setQueryParameter('api-version', apiVersion); return this; } /** * Creates and returns a builder for a specific node. * @param name The name of the node to create a builder for. * @returns A new node URL builder. */ node(name) { if (!name) { const message = MsftSme.getStrings().MsftSmeShell.Core.Error.ArgumentNullError.message; throw new Error(message.format('NodeUrlBuilder/node', 'name')); } return new NodeUrlBuilder(this.builder.clone(), name); } } /** Represents an object that can build URLs for a particular node. */ export class NodeUrlBuilder { builder; /** * Initializes a new instance of the NodeUrlBuilder class. * @param builder The current UriBuilder. * @param node The name of the node the URL is being built for. */ constructor(builder, node) { this.builder = builder; this.builder.appendSegment('nodes'); this.builder.appendSegment(node); } /** Makes the current URL builder relative from this point forward. */ makeRelative() { const newBuilder = new UriBuilder(); newBuilder.fragment = this.builder.fragment; newBuilder.query = this.builder.query; this.builder = newBuilder; return this; } /** Gets a builder for the file transfer feature. **/ fileTransfer() { return new FileTransferUrlBuilder(this.builder.clone()); } } /** Represents an object that builds the file URL for an API. */ export class ApiUrlBuilder { builder; /** * Initializes a new instance of the ApiUrlBuilder class. * @param builder The current UriBuilder. */ constructor(builder) { this.builder = builder; } /** Builds and returns the current URL. */ build() { return this.builder.toString(); } } /** Represents an object that can build URLs for a particular feature. */ export class FeatureUrlBuilder { builder; /** * Initializes a new instance of the FeatureUrlBuilder class. * @param builder The current UriBuilder. * @param node The name of the feature the URL is being built for. */ constructor(builder, name) { this.builder = builder; this.builder.appendSegment('features'); this.builder.appendSegment(name); } } /** Represents an object that can build URLs for file transfers. */ export class FileTransferUrlBuilder extends FeatureUrlBuilder { /** * Initializes a new instance of the FileTransferUrlBuilder class. * @param builder The current UriBuilder. */ constructor(builder) { super(builder, 'fileTransfer'); } /** * Adds the specified file path to the URL. * @param path The path of the file to use. */ file(path) { if (!path) { const message = MsftSme.getStrings().MsftSmeShell.Core.Error.ArgumentNullError.message; throw new Error(message.format('FileTransferUrlBuilder/file', 'path')); } const temp = this.builder.clone(); temp.appendSegment('files'); temp.appendSegment(Net.toSegmentedBase64Url(path)); return new ApiUrlBuilder(temp); } } //# sourceMappingURL=gateway-url-builder.js.map