diff --git a/package.json b/package.json index ccd96b1..35b1ea8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vso-client", - "version": "0.2.5", + "version": "0.2.6", "description": "Visual Studio Online Client", "main": "./public/vso-client.js", "scripts": { diff --git a/public/vso-client.js b/public/vso-client.js index c333f5a..21f9d56 100644 --- a/public/vso-client.js +++ b/public/vso-client.js @@ -8,7 +8,7 @@ request = require("request"); azure = require('azure'); -apiVersion = '1.0'; +apiVersion = '2.0'; spsUri = 'https://app.vssps.visualstudio.com'; @@ -125,12 +125,12 @@ exports.Client = (function() { this.url = url; this.collection = collection; apiUrl = url; - this.client = requestJson.newClient(apiUrl, options != null ? options.clientOptions : void 0); + this.client = requestJson.createClient(apiUrl, options != null ? options.clientOptions : void 0); if (authentication === AuthenticationCredential || authentication.type === "Credential") { this.client.setBasicAuth(authentication.username, authentication.password); } else if (authentication === AuthenticationOAuth || authentication.type === "OAuth") { spsUrl = (options != null ? options.spsUri : void 0) || spsUri; - this.clientSPS = requestJson.newClient(spsUrl, options != null ? options.clientOptions : void 0); + this.clientSPS = requestJson.createClient(spsUrl, options != null ? options.clientOptions : void 0); this.client.headers.Authorization = "bearer " + authentication.accessToken; this.clientSPS.headers.Authorization = "bearer " + authentication.accessToken; } else if (authentication === AuthenticationWrap || authentication.type === "Wrap") { @@ -224,7 +224,11 @@ exports.Client = (function() { basePath = ""; if (!(options != null ? options.excludeCollection : void 0)) { if (options != null ? options.projectName : void 0) { - basePath = '/' + this.collection + '/' + (encodeURI(options.projectName)); + if (options != null ? options.teamName : void 0){ + basePath = '/' + this.collection + '/' + (encodeURI(options.projectName))+ '/' + (encodeURI(options.teamName)); + } else{ + basePath = '/' + this.collection + '/' + (encodeURI(options.projectName)); + } } else { basePath = '/' + this.collection; } @@ -330,7 +334,7 @@ exports.Client = (function() { } }; - Client.prototype.getProjects = function(stateFilter, pageSize, skip, callback) { + Client.prototype.getProjects = function(stateFilter, pageSize, skip, callback) { var path; if (typeof stateFilter === 'function') { callback = stateFilter; @@ -416,6 +420,29 @@ exports.Client = (function() { })(this)); }; + Client.prototype.getIterations = function(projectName, teamName, callback) { + var path; + if (this.apiVersion === "1.0-preview.1") { + return callback("Not Supported!", null); + } else { + path = this.buildApiPath("work/TeamSettings/Iterations", null, { + projectName: projectName, + teamName: teamName + }); + return this.client.get(path,this.getOptions(), (function(_this) { + return function(err, res, body) { + if (err) { + return callback(err, body); + } else if (res.statusCode === 404) { + return callback((body != null ? body.message : void 0) || "Error getting Iterations", body); + } else { + return _this.parseReplyData(err, res, body, callback); + } + }; + })(this)); + } + }; + Client.prototype.getTeam = function(projectId, teamId, callback) { var path; path = this.buildApiPath('projects/' + projectId + '/teams/' + teamId); @@ -960,6 +987,27 @@ exports.Client = (function() { })(this)); }; + Client.prototype.getWorkItemTypesNames = function(projectName, callback) { + var path; + this.checkAndRequireMinimumVersion("1.0-preview.2"); + path = this.buildApiPath('wit/workitemtypes', null, { + projectName: projectName + }); + return this.client.get(path, this.getOptions(), (function(_this) { + return function(err, res, body) { + return _this.parseReplyData(err, res, body, function(err, results){ + let names; + if(err) { + return callback(err, results); + } else { + names = _.map(results, 'name'); + return callback(err, names); + } + }); + }; + })(this)); + }; + Client.prototype.getWorkItemType = function(projectName, workItemType, callback) { var path; this.checkAndRequireMinimumVersion("1.0-preview.2"); @@ -984,6 +1032,25 @@ exports.Client = (function() { })(this)); }; + Client.prototype.getWorkItemRelationTypesNames = function(callback) { + var path; + this.checkAndRequireMinimumVersion("1.0-preview.2"); + path = this.buildApiPath('wit/workitemrelationtypes'); + return this.client.get(path, this.getOptions(), (function(_this) { + return function(err, res, body) { + return _this.parseReplyData(err, res, body, function(err, results){ + let names; + if(err) { + return callback(err, results); + } else { + names = _.map(results, 'name'); + return callback(err, names); + } + }); + }; + })(this)); + }; + Client.prototype.getWorkItemRelationType = function(relationName, callback) { var path; this.checkAndRequireMinimumVersion("1.0-preview.2"); @@ -1032,6 +1099,30 @@ exports.Client = (function() { })(this)); }; + Client.prototype.getWorkItemFieldsShort = function(callback) { + var path; + this.checkAndRequireMinimumVersion("1.0-preview.2"); + path = this.buildApiPath('wit/fields'); + return this.client.get(path, this.getOptions(), (function(_this) { + return function(err, res, body) { + return _this.parseReplyData(err, res, body, function(err, results){ + let short; + if(err) { + return callback(err, results); + } else { + short = _.map(results, (data, result) => { + return { + name: data.name, + nameReference: data.referenceName + } + }); + return callback(err, short); + } + }); + }; + })(this)); + }; + Client.prototype.getWorkItemField = function(referenceName, callback) { var path; this.checkAndRequireMinimumVersion("1.0-preview.2"); @@ -1934,6 +2025,51 @@ exports.Client = (function() { })(this)); }; + Client.prototype.batchRequest = function(methods, callback) { + var path; + if (this.apiVersion === "1.0-preview.1") { + return callback("Not Supported!", null); + } else { + path = this.buildApiPath("wit/$batch", null, null); + return this.client.post(path, methods, this.getOptions(), (function(_this) { + return function(err, res, body) { + if(body && body.value!=null && Array.isArray(body.value)) { + var bd = { results:[], errors:0, count:0 }; + body.value.map(function(b){ + if (b!=null & b.code == 404){ + var bdy = null; + try { bdy = JSON.parse(b.body); } + catch(e) { bdy = b.body != null ? b.body : null; } + bd.results.push((bdy != null ? bdy : void 0) || { "code":404, "count":1, "value":"Error with your batch of WorkItem Actions" }); + bd.errors++; + } else { + if(b.code == 400) { bd.errors++; } + try { bd.results.push(JSON.parse(b.body)); } + catch(e) { bd.results.push(b.body); } + } + }); + if (err) { + return callback(err.toString(), b); + } else if (res.statusCode === 404) { + return callback((body != null ? body.message : void 0) || "Error with your batch of WorkItem Actions", body); + } else { + bd.count = bd.results.length; + return _this.parseReplyData(err, res, bd, callback); + } + } else { + if (err) { + return callback(err.toString(), body); + } else if (res.statusCode === 404) { + return callback((body != null ? body.message : void 0) || "Error with your batch of WorkItem Actions", body); + } else { + return _this.parseReplyData(err, res, body, callback); + } + } + }; + })(this)); + } + }; + return Client; -})(); +})()