2015-07-24 00:18:52 +03:00
|
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
import VsoBaseInterfaces = require('./interfaces/common/VsoBaseInterfaces');
|
|
|
|
import basem = require('./ClientApiBases');
|
|
|
|
import buildm = require('./BuildApi');
|
2017-03-23 22:52:28 +03:00
|
|
|
import chatm = require('./ChatApi');
|
2016-09-02 19:38:29 +03:00
|
|
|
import contributionsm = require("./ContributionsApi");
|
2015-07-24 00:18:52 +03:00
|
|
|
import corem = require('./CoreApi');
|
2017-03-23 22:52:28 +03:00
|
|
|
import dashboardm = require('./DashboardApi');
|
|
|
|
import delegatedauthorizationm = require('./DelegatedAuthorizationApi');
|
2016-09-02 19:38:29 +03:00
|
|
|
import extmgmtm = require("./ExtensionManagementApi");
|
|
|
|
import featuremgmtm = require("./FeatureManagementApi");
|
2015-07-24 00:18:52 +03:00
|
|
|
import filecontainerm = require('./FileContainerApi');
|
2015-08-11 22:27:06 +03:00
|
|
|
import gallerym = require('./GalleryApi');
|
2015-07-24 00:18:52 +03:00
|
|
|
import gitm = require('./GitApi');
|
2017-03-23 22:52:28 +03:00
|
|
|
import identitiesm = require('./IdentitiesApi');
|
|
|
|
import locationsm = require('./LocationsApi');
|
|
|
|
import notificationm = require('./NotificationApi');
|
|
|
|
import organizationm = require('./OrganizationApi');
|
|
|
|
import policym = require('./PolicyApi');
|
|
|
|
import profilem = require('./ProfileApi');
|
|
|
|
import releasem = require('./ReleaseApi');
|
|
|
|
import securityrolesm = require('./SecurityRolesApi');
|
|
|
|
import servicehooksm = require('./ServiceHooksApi');
|
2015-07-24 00:18:52 +03:00
|
|
|
import taskagentm = require('./TaskAgentApi');
|
|
|
|
import taskm = require('./TaskApi');
|
|
|
|
import testm = require('./TestApi');
|
|
|
|
import tfvcm = require('./TfvcApi');
|
2017-03-23 22:52:28 +03:00
|
|
|
import tokenm = require('./TokenApi');
|
|
|
|
import workm = require('./WorkApi');
|
2015-07-24 00:18:52 +03:00
|
|
|
import workitemtrackingm = require('./WorkItemTrackingApi');
|
|
|
|
import basicm = require('./handlers/basiccreds');
|
|
|
|
import bearm = require('./handlers/bearertoken');
|
2016-07-06 16:54:51 +03:00
|
|
|
import ntlmm = require('./handlers/ntlm');
|
2016-07-28 05:16:44 +03:00
|
|
|
import patm = require('./handlers/personalaccesstoken');
|
2015-07-24 00:18:52 +03:00
|
|
|
|
2017-04-06 05:19:47 +03:00
|
|
|
import * as rm from 'typed-rest-client/RestClient';
|
|
|
|
//import * as hm from 'typed-rest-client/HttpClient';
|
|
|
|
import vsom = require('./VsoClient');
|
2017-04-06 05:31:59 +03:00
|
|
|
import lim = require("./interfaces/LocationsInterfaces");
|
2017-04-06 05:19:47 +03:00
|
|
|
|
2015-08-04 18:54:10 +03:00
|
|
|
/**
|
|
|
|
* Methods to return handler objects (see handlers folder)
|
|
|
|
*/
|
|
|
|
|
2017-06-15 23:40:58 +03:00
|
|
|
export function getBasicHandler(username: string, password: string): VsoBaseInterfaces.IRequestHandler {
|
2015-08-04 18:54:10 +03:00
|
|
|
return new basicm.BasicCredentialHandler(username, password);
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:40:58 +03:00
|
|
|
export function getNtlmHandler(username: string, password: string, workstation?: string, domain?: string): VsoBaseInterfaces.IRequestHandler {
|
2016-07-06 16:54:51 +03:00
|
|
|
return new ntlmm.NtlmCredentialHandler(username, password, workstation, domain);
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:40:58 +03:00
|
|
|
export function getBearerHandler(token: string): VsoBaseInterfaces.IRequestHandler {
|
2015-08-04 18:54:10 +03:00
|
|
|
return new bearm.BearerCredentialHandler(token);
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:40:58 +03:00
|
|
|
export function getPersonalAccessTokenHandler(token: string): VsoBaseInterfaces.IRequestHandler {
|
2016-07-28 05:16:44 +03:00
|
|
|
return new patm.PersonalAccessTokenCredentialHandler(token);
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:40:58 +03:00
|
|
|
export function getHandlerFromToken(token: string): VsoBaseInterfaces.IRequestHandler {
|
|
|
|
if (token.length === 52) {
|
|
|
|
return getPersonalAccessTokenHandler(token);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return getBearerHandler(token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-24 00:18:52 +03:00
|
|
|
// ---------------------------------------------------------------------------
|
2015-07-24 00:34:31 +03:00
|
|
|
// Factory to return client apis
|
2017-06-05 21:59:40 +03:00
|
|
|
// When new APIs are added, a method must be added here to instantiate the API
|
2015-07-24 00:18:52 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
export class WebApi {
|
|
|
|
|
|
|
|
serverUrl: string;
|
|
|
|
authHandler: VsoBaseInterfaces.IRequestHandler;
|
2017-04-06 05:19:47 +03:00
|
|
|
rest: rm.RestClient;
|
|
|
|
vsoClient: vsom.VsoClient;
|
2017-07-20 23:04:00 +03:00
|
|
|
options: VsoBaseInterfaces.IRequestOptions;
|
2015-07-24 00:18:52 +03:00
|
|
|
|
|
|
|
/*
|
2015-07-24 00:34:31 +03:00
|
|
|
* Factory to return client apis and handlers
|
2017-03-09 16:11:52 +03:00
|
|
|
* @param defaultUrl default server url to use when creating new apis from factory methods
|
|
|
|
* @param authHandler default authentication credentials to use when creating new apis from factory methods
|
2015-07-24 00:18:52 +03:00
|
|
|
*/
|
2017-07-14 05:22:04 +03:00
|
|
|
constructor(defaultUrl: string, authHandler: VsoBaseInterfaces.IRequestHandler, options?: VsoBaseInterfaces.IRequestOptions) {
|
2017-03-09 16:11:52 +03:00
|
|
|
this.serverUrl = defaultUrl;
|
2015-07-24 00:18:52 +03:00
|
|
|
this.authHandler = authHandler;
|
2017-07-14 05:22:04 +03:00
|
|
|
this.options = options;
|
|
|
|
this.rest = new rm.RestClient('vsts-node-api', null, [this.authHandler], options);
|
|
|
|
this.vsoClient = new vsom.VsoClient(defaultUrl, this.rest);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 16:11:52 +03:00
|
|
|
/**
|
|
|
|
* Convenience factory to create with a bearer token.
|
|
|
|
* @param defaultServerUrl default server url to use when creating new apis from factory methods
|
|
|
|
* @param defaultAuthHandler default authentication credentials to use when creating new apis from factory methods
|
2017-07-14 05:22:04 +03:00
|
|
|
*/
|
|
|
|
public static createWithBearerToken(defaultUrl: string, token: string, options?: VsoBaseInterfaces.IRequestOptions) {
|
2017-03-09 16:11:52 +03:00
|
|
|
let bearerHandler = getBearerHandler(token);
|
2017-07-14 05:22:04 +03:00
|
|
|
return new this(defaultUrl, bearerHandler, options);
|
|
|
|
}
|
2017-03-09 16:11:52 +03:00
|
|
|
|
2017-07-14 05:22:04 +03:00
|
|
|
public async connect(): Promise<lim.ConnectionData> {
|
2017-04-06 05:31:59 +03:00
|
|
|
return new Promise<lim.ConnectionData>(async (resolve, reject) => {
|
2017-04-06 05:19:47 +03:00
|
|
|
try {
|
2017-04-06 05:31:59 +03:00
|
|
|
let res: rm.IRestResponse<lim.ConnectionData>;
|
|
|
|
res = await this.rest.get<lim.ConnectionData>(this.vsoClient.resolveUrl('/_apis/connectionData'));
|
2017-04-06 05:19:47 +03:00
|
|
|
resolve(res.result);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
reject(err);
|
|
|
|
}
|
|
|
|
});
|
2017-07-14 05:22:04 +03:00
|
|
|
}
|
2017-04-06 05:19:47 +03:00
|
|
|
|
2015-07-24 00:34:31 +03:00
|
|
|
/**
|
|
|
|
* Each factory method can take a serverUrl and a list of handlers
|
|
|
|
* if these aren't provided, the default url and auth handler given to the constructor for this class will be used
|
|
|
|
*/
|
2017-03-09 16:11:52 +03:00
|
|
|
public getBuildApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): buildm.IBuildApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
|
|
|
handlers = handlers || [this.authHandler];
|
2017-07-14 05:22:04 +03:00
|
|
|
return new buildm.BuildApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2015-07-24 00:34:31 +03:00
|
|
|
/**
|
2016-07-28 04:27:13 +03:00
|
|
|
* Each API has a method here to create the client.
|
2015-07-24 00:34:31 +03:00
|
|
|
*/
|
2017-03-23 22:52:28 +03:00
|
|
|
|
|
|
|
public getChatApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): chatm.IChatApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new chatm.ChatApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 16:11:52 +03:00
|
|
|
public getCoreApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): corem.ICoreApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new corem.CoreApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2017-03-23 22:52:28 +03:00
|
|
|
public getContributionsApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): contributionsm.IContributionsApi {
|
2017-03-09 16:11:52 +03:00
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new contributionsm.ContributionsApi(serverUrl, handlers, this.options);
|
2016-09-02 19:38:29 +03:00
|
|
|
}
|
|
|
|
|
2017-03-23 22:52:28 +03:00
|
|
|
public getDashboardApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): dashboardm.IDashboardApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new dashboardm.DashboardApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public getDelegatedAuthorizationApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): delegatedauthorizationm.IDelegatedAuthorizationApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new delegatedauthorizationm.DelegatedAuthorizationApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 16:11:52 +03:00
|
|
|
public getExtensionManagementApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): extmgmtm.IExtensionManagementApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new extmgmtm.ExtensionManagementApi(serverUrl, handlers, this.options);
|
2016-09-02 19:38:29 +03:00
|
|
|
}
|
|
|
|
|
2017-03-23 22:52:28 +03:00
|
|
|
public getFeatureManagementApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): featuremgmtm.IFeatureManagementApi {
|
2017-03-09 16:11:52 +03:00
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new featuremgmtm.FeatureManagementApi(serverUrl, handlers, this.options);
|
2016-09-02 19:38:29 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 16:11:52 +03:00
|
|
|
public getFileContainerApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): filecontainerm.IFileContainerApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new filecontainerm.FileContainerApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 16:11:52 +03:00
|
|
|
public getGalleryApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): gallerym.IGalleryApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new gallerym.GalleryApi(serverUrl, handlers, this.options);
|
2015-08-11 22:27:06 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 16:11:52 +03:00
|
|
|
public getGitApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): gitm.IGitApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new gitm.GitApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2017-07-14 05:22:04 +03:00
|
|
|
public getIdentitiesApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): identitiesm.IIdentitiesApi {
|
2017-03-23 22:52:28 +03:00
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new identitiesm.IdentitiesApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public getLocationsApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): locationsm.ILocationsApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new locationsm.LocationsApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public getNotificationApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): notificationm.INotificationApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new notificationm.NotificationApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public getOrganizationApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): organizationm.IOrganizationApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new organizationm.OrganizationApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public getPolicyApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): policym.IPolicyApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new policym.PolicyApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public getProfileApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): profilem.IProfileApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new profilem.ProfileApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public getSecurityRolesApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): securityrolesm.ISecurityRolesApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new securityrolesm.SecurityRolesApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public getServiceHooksApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): servicehooksm.IServiceHooksApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new servicehooksm.ServiceHooksApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public getReleaseApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): releasem.IReleaseApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new releasem.ReleaseApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 16:11:52 +03:00
|
|
|
public getTaskApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): taskm.ITaskApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new taskm.TaskApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 16:11:52 +03:00
|
|
|
public getTaskAgentApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): taskagentm.ITaskAgentApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new taskagentm.TaskAgentApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 16:11:52 +03:00
|
|
|
public getTestApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): testm.ITestApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new testm.TestApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 16:11:52 +03:00
|
|
|
public getTfvcApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): tfvcm.ITfvcApi {
|
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new tfvcm.TfvcApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2017-03-23 22:52:28 +03:00
|
|
|
public getWorkApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): workm.IWorkApi {
|
2017-03-09 16:11:52 +03:00
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new workm.WorkApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2017-03-23 22:52:28 +03:00
|
|
|
public getWorkItemTrackingApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): workitemtrackingm.IWorkItemTrackingApi {
|
2017-03-09 16:11:52 +03:00
|
|
|
serverUrl = serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new workitemtrackingm.WorkItemTrackingApi(serverUrl, handlers, this.options);
|
2015-08-20 18:55:10 +03:00
|
|
|
}
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|