Skip to content

Commit 3502fba

Browse files
committed
update deps to azure-devops-node-api
fixes #332
1 parent 165f96d commit 3502fba

File tree

9 files changed

+65
-88
lines changed

9 files changed

+65
-88
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"node": ">= 8"
3535
},
3636
"dependencies": {
37+
"azure-devops-node-api": "^7.2.0",
3738
"chalk": "^2.4.2",
3839
"cheerio": "^1.0.0-rc.1",
3940
"commander": "^2.8.1",
@@ -49,8 +50,8 @@
4950
"read": "^1.0.7",
5051
"semver": "^5.1.0",
5152
"tmp": "0.0.29",
53+
"typed-rest-client": "1.2.0",
5254
"url-join": "^1.1.0",
53-
"vso-node-api": "6.1.2-preview",
5455
"yauzl": "^2.3.1",
5556
"yazl": "^2.2.2"
5657
},

src/main.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as program from 'commander';
22
import { packageCommand, ls } from './package';
3-
import { publish, list, unpublish } from './publish';
3+
import { publish, unpublish } from './publish';
44
import { show } from './show';
55
import { search } from './search';
66
import { listPublishers, createPublisher, deletePublisher, loginPublisher, logoutPublisher } from './store';
@@ -88,11 +88,6 @@ module.exports = function (argv: string[]): void {
8888
.option('-p, --pat <token>', 'Personal Access Token')
8989
.action((id, { pat }) => main(unpublish({ id, pat })));
9090

91-
program
92-
.command('list <publisher>')
93-
.description('Lists all extensions published by the given publisher')
94-
.action(publisher => main(list(publisher)));
95-
9691
program
9792
.command('ls-publishers')
9893
.description('List all known publishers')

src/publicgalleryapi.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { HttpClient, HttpClientResponse } from 'vso-node-api/HttpClient';
2-
import { PublishedExtension, ExtensionQueryFlags, FilterCriteria, SortOrderType,
3-
SortByType, ExtensionQueryFilterType, TypeInfo} from 'vso-node-api/interfaces/GalleryInterfaces';
4-
import { IHeaders } from 'vso-node-api/interfaces/common/VsoBaseInterfaces';
5-
import { ContractSerializer } from 'vso-node-api/Serialization';
1+
import { HttpClient, HttpClientResponse } from 'typed-rest-client/HttpClient';
2+
import {
3+
PublishedExtension, ExtensionQueryFlags, FilterCriteria, SortOrderType,
4+
SortByType, ExtensionQueryFilterType, TypeInfo
5+
} from 'azure-devops-node-api/interfaces/GalleryInterfaces';
6+
import { IHeaders } from 'azure-devops-node-api/interfaces/common/VsoBaseInterfaces';
7+
import { ContractSerializer } from 'azure-devops-node-api/Serialization';
68

79
export interface ExtensionQuery {
810
pageNumber?: number;
@@ -21,7 +23,7 @@ export class PublicGalleryAPI {
2123
this.client = new HttpClient('vsce');
2224
}
2325

24-
post(url: string, data: string, additionalHeaders?: IHeaders): Promise<HttpClientResponse> {
26+
private post(url: string, data: string, additionalHeaders?: IHeaders): Promise<HttpClientResponse> {
2527
return this.client.post(`${this.baseUrl}/_apis/public${url}`, data, additionalHeaders);
2628
}
2729

@@ -35,17 +37,17 @@ export class PublicGalleryAPI {
3537
assetTypes = [],
3638
}: ExtensionQuery): Promise<PublishedExtension[]> {
3739
return this.post('/gallery/extensionquery', JSON.stringify({
38-
filters: [{pageNumber, pageSize, criteria}],
40+
filters: [{ pageNumber, pageSize, criteria }],
3941
assetTypes,
4042
flags: flags.reduce((memo, flag) => memo | flag, 0)
4143
}), {
42-
Accept: `application/json;api-version=${this.apiVersion}`,
43-
'Content-Type': 'application/json',
44-
})
44+
Accept: `application/json;api-version=${this.apiVersion}`,
45+
'Content-Type': 'application/json',
46+
})
4547
.then(res => res.readBody())
4648
.then(data => JSON.parse(data))
47-
.then(({results: [result = {}] = []}) => result)
48-
.then(({extensions = []}) =>
49+
.then(({ results: [result = {}] = [] }) => result)
50+
.then(({ extensions = [] }) =>
4951
ContractSerializer.deserialize(extensions, TypeInfo.PublishedExtension, false, false)
5052
);
5153
}
@@ -55,9 +57,9 @@ export class PublicGalleryAPI {
5557
criteria: [{ filterType: ExtensionQueryFilterType.Name, value: extensionId }],
5658
flags,
5759
})
58-
.then(result => result.filter(({publisher: {publisherName}, extensionName}) =>
59-
extensionId.toLowerCase() === `${publisherName}.${extensionName}`.toLowerCase())
60-
)
61-
.then(([extension]) => extension);
60+
.then(result => result.filter(({ publisher: { publisherName }, extensionName }) =>
61+
extensionId.toLowerCase() === `${publisherName}.${extensionName}`.toLowerCase())
62+
)
63+
.then(([extension]) => extension);
6264
}
6365
}

src/publish.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as fs from 'fs';
2-
import { ExtensionQueryFlags, PublishedExtension, ExtensionQueryFilterType, PagingDirection, SortByType, SortOrderType } from 'vso-node-api/interfaces/GalleryInterfaces';
2+
import { ExtensionQueryFlags, PublishedExtension, ExtensionQueryFilterType, PagingDirection, SortByType, SortOrderType } from 'azure-devops-node-api/interfaces/GalleryInterfaces';
33
import { pack, readManifest, IPackage } from './package';
44
import * as tmp from 'tmp';
55
import { getPublisher } from './store';
@@ -52,16 +52,16 @@ function readManifestFromPackage(packagePath: string): Promise<Manifest> {
5252
});
5353
}
5454

55-
function _publish(packagePath: string, pat: string, manifest: Manifest): Promise<void> {
56-
const api = getGalleryAPI(pat);
55+
async function _publish(packagePath: string, pat: string, manifest: Manifest): Promise<void> {
56+
const api = await getGalleryAPI(pat);
5757

5858
const packageStream = fs.createReadStream(packagePath);
5959

6060
const name = `${manifest.publisher}.${manifest.name}`;
6161
const fullName = `${name}@${manifest.version}`;
6262
console.log(`Publishing ${fullName}...`);
6363

64-
return api.getExtension(manifest.publisher, manifest.name, null, ExtensionQueryFlags.IncludeVersions)
64+
return api.getExtension(null, manifest.publisher, manifest.name, null, ExtensionQueryFlags.IncludeVersions)
6565
.catch<PublishedExtension>(err => err.statusCode === 404 ? null : Promise.reject(err))
6666
.then(extension => {
6767
if (extension && extension.versions.some(v => v.version === manifest.version)) {
@@ -164,25 +164,6 @@ export function publish(options: IPublishOptions = {}): Promise<any> {
164164
});
165165
}
166166

167-
export function list(publisher: string): Promise<any> {
168-
validatePublisher(publisher);
169-
170-
return getPublisher(publisher)
171-
.then(p => p.pat)
172-
.then(getGalleryAPI)
173-
.then(api => {
174-
const criteria = [{ filterType: ExtensionQueryFilterType.InstallationTarget, value: 'Microsoft.VisualStudio.Code' }];
175-
const filters = [{ criteria, direction: PagingDirection.Forward, pageNumber: 0, pageSize: 1000, pagingToken: null, sortBy: SortByType.Relevance, sortOrder: SortOrderType.Default }];
176-
const query = { filters, flags: ExtensionQueryFlags.IncludeLatestVersionOnly | ExtensionQueryFlags.IncludeVersionProperties, assetTypes: [] };
177-
178-
return api.queryExtensions(query).then(result => {
179-
return result.results[0].extensions
180-
.filter(e => e.publisher.publisherName === publisher)
181-
.forEach(e => console.log(`${e.extensionName} @ ${e.versions[0].version}`));
182-
});
183-
});
184-
}
185-
186167
export interface IUnpublishOptions extends IPublishOptions {
187168
id?: string;
188169
}

src/search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getPublicGalleryAPI } from './util';
2-
import { ExtensionQueryFilterType } from 'vso-node-api/interfaces/GalleryInterfaces';
2+
import { ExtensionQueryFilterType } from 'azure-devops-node-api/interfaces/GalleryInterfaces';
33
import { tableView, wordTrim } from './viewutils';
44

55
const pageSize = 100;

src/show.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getPublicGalleryAPI, log } from './util';
2-
import { ExtensionQueryFlags, PublishedExtension } from 'vso-node-api/interfaces/GalleryInterfaces';
2+
import { ExtensionQueryFlags, PublishedExtension } from 'azure-devops-node-api/interfaces/GalleryInterfaces';
33
import { ViewTable, formatDate, formatDateTime, ratingStars, tableView, indentRow, wordWrap, icons } from './viewutils';
44

55
const limitVersions = 6;

src/store.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async function requestPAT(store: IStore, publisherName: string): Promise<IPublis
6060
// If the caller of the `getRoleAssignments` API has any of the roles
6161
// (Creator, Owner, Contributor, Reader) on the publisher, we get a 200,
6262
// otherwise we get a 403.
63-
const api = getSecurityRolesAPI(pat);
63+
const api = await getSecurityRolesAPI(pat);
6464
await api.getRoleAssignments('gallery.publisher', publisherName);
6565

6666
return await addPublisherToStore(store, { name: publisherName, pat });
@@ -113,8 +113,8 @@ export function createPublisher(publisherName: string): Promise<any> {
113113
return read(`Publisher human-friendly name: `, { default: publisherName }).then(displayName => {
114114
return read(`E-mail: `).then(email => {
115115
return read(`Personal Access Token:`, { silent: true, replace: '*' })
116-
.then(pat => {
117-
const api = getGalleryAPI(pat);
116+
.then(async pat => {
117+
const api = await getGalleryAPI(pat);
118118
const raw = {
119119
publisherName,
120120
displayName,
@@ -127,8 +127,8 @@ export function createPublisher(publisherName: string): Promise<any> {
127127
emailAddress: [email]
128128
};
129129

130-
return api.createPublisher(raw)
131-
.then(() => ({ name: publisherName, pat }));
130+
await api.createPublisher(raw);
131+
return { name: publisherName, pat };
132132
})
133133
.then(publisher => load().then(store => addPublisherToStore(store, publisher)));
134134
});

src/util.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as _read from 'read';
2-
import { WebApi, getBasicHandler } from 'vso-node-api/WebApi';
3-
import { IGalleryApi } from 'vso-node-api/GalleryApi';
2+
import { WebApi, getPersonalAccessTokenHandler } from 'azure-devops-node-api/WebApi';
3+
import { IGalleryApi, GalleryApi } from 'azure-devops-node-api/GalleryApi';
44
import * as denodeify from 'denodeify';
55
import chalk from 'chalk';
66
import { PublicGalleryAPI } from './publicgalleryapi';
7-
import { ISecurityRolesApi } from 'vso-node-api/SecurityRolesApi';
7+
import { ISecurityRolesApi } from 'azure-devops-node-api/SecurityRolesApi';
88

99
const __read = denodeify<_read.Options, string>(_read);
1010
export function read(prompt: string, options: _read.Options = {}): Promise<string> {
@@ -21,16 +21,19 @@ export function getPublishedUrl(extension: string): string {
2121
return `${marketplaceUrl}/items?itemName=${extension}`;
2222
}
2323

24-
export function getGalleryAPI(pat: string): IGalleryApi {
25-
const authHandler = getBasicHandler('oauth', pat);
26-
const vsoapi = new WebApi('oauth', authHandler);
27-
return vsoapi.getGalleryApi(marketplaceUrl);
24+
export async function getGalleryAPI(pat: string): Promise<IGalleryApi> {
25+
// from https://github.com/Microsoft/tfs-cli/blob/master/app/exec/extension/default.ts#L287-L292
26+
const authHandler = getPersonalAccessTokenHandler(pat);
27+
return new GalleryApi(marketplaceUrl, [authHandler]);
28+
29+
// const vsoapi = new WebApi(marketplaceUrl, authHandler);
30+
// return await vsoapi.getGalleryApi();
2831
}
2932

30-
export function getSecurityRolesAPI(pat: string): ISecurityRolesApi {
31-
const authHandler = getBasicHandler('oauth', pat);
32-
const vsoapi = new WebApi('oauth', authHandler);
33-
return vsoapi.getSecurityRolesApi(marketplaceUrl);
33+
export async function getSecurityRolesAPI(pat: string): Promise<ISecurityRolesApi> {
34+
const authHandler = getPersonalAccessTokenHandler(pat);
35+
const vsoapi = new WebApi(marketplaceUrl, authHandler);
36+
return await vsoapi.getSecurityRolesApi();
3437
}
3538

3639
export function getPublicGalleryAPI() {

yarn.lock

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ atob@^2.1.1:
202202
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
203203
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==
204204

205+
azure-devops-node-api@^7.2.0:
206+
version "7.2.0"
207+
resolved "https://registry.yarnpkg.com/azure-devops-node-api/-/azure-devops-node-api-7.2.0.tgz#131d4e01cf12ebc6e45569b5e0c5c249e4114d6d"
208+
integrity sha512-pMfGJ6gAQ7LRKTHgiRF+8iaUUeGAI0c8puLaqHLc7B8AR7W6GJLozK9RFeUHFjEGybC9/EB3r67WPd7e46zQ8w==
209+
dependencies:
210+
os "0.1.1"
211+
tunnel "0.0.4"
212+
typed-rest-client "1.2.0"
213+
underscore "1.8.3"
214+
205215
babel-runtime@^6.9.2:
206216
version "6.26.0"
207217
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
@@ -1592,6 +1602,11 @@ os-tmpdir@^1.0.0, os-tmpdir@~1.0.1:
15921602
resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274"
15931603
integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=
15941604

1605+
1606+
version "0.1.1"
1607+
resolved "https://registry.yarnpkg.com/os/-/os-0.1.1.tgz#208845e89e193ad4d971474b93947736a56d13f3"
1608+
integrity sha1-IIhF6J4ZOtTZcUdLk5R3NqVtE/M=
1609+
15951610
osenv@^0.1.3, osenv@^0.1.4:
15961611
version "0.1.5"
15971612
resolved "https://registry.yarnpkg.com/osenv/-/osenv-0.1.5.tgz#85cdfafaeb28e8677f416e287592b5f3f49ea410"
@@ -1724,11 +1739,6 @@ pump@^3.0.0:
17241739
end-of-stream "^1.1.0"
17251740
once "^1.3.1"
17261741

1727-
q@^1.0.1:
1728-
version "1.5.1"
1729-
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
1730-
integrity sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=
1731-
17321742
randomatic@^3.0.0:
17331743
version "3.1.1"
17341744
resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-3.1.1.tgz#b776efc59375984e36c537b2f51a1f0aff0da1ed"
@@ -2214,10 +2224,10 @@ [email protected]:
22142224
resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.4.tgz#2d3785a158c174c9a16dc2c046ec5fc5f1742213"
22152225
integrity sha1-LTeFoVjBdMmhbcLARuxfxfF0IhM=
22162226

2217-
typed-rest-client@^0.9.0:
2218-
version "0.9.0"
2219-
resolved "https://registry.yarnpkg.com/typed-rest-client/-/typed-rest-client-0.9.0.tgz#f768cc0dc3f4e950f06e04825c36b3e7834aa1f2"
2220-
integrity sha1-92jMDcP06VDwbgSCXDaz54NKofI=
2227+
typed-rest-client@1.2.0:
2228+
version "1.2.0"
2229+
resolved "https://registry.yarnpkg.com/typed-rest-client/-/typed-rest-client-1.2.0.tgz#723085d203f38d7d147271e5ed3a75488eb44a02"
2230+
integrity sha512-FrUshzZ1yxH8YwGR29PWWnfksLEILbWJydU7zfIRkyH7kAEzB62uMAl2WY6EyolWpLpVHeJGgQm45/MaruaHpw==
22212231
dependencies:
22222232
tunnel "0.0.4"
22232233
underscore "1.8.3"
@@ -2237,11 +2247,6 @@ [email protected]:
22372247
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.8.3.tgz#4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022"
22382248
integrity sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=
22392249

2240-
underscore@^1.8.3:
2241-
version "1.9.1"
2242-
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.9.1.tgz#06dce34a0e68a7babc29b365b8e74b8925203961"
2243-
integrity sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg==
2244-
22452250
union-value@^1.0.0:
22462251
version "1.0.0"
22472252
resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.0.tgz#5c71c34cb5bad5dcebe3ea0cd08207ba5aa1aea4"
@@ -2288,16 +2293,6 @@ validate-npm-package-license@^3.0.1:
22882293
spdx-correct "^3.0.0"
22892294
spdx-expression-parse "^3.0.0"
22902295

2291-
2292-
version "6.1.2-preview"
2293-
resolved "https://registry.yarnpkg.com/vso-node-api/-/vso-node-api-6.1.2-preview.tgz#aab3546df2451ecd894e071bb99b5df19c5fa78f"
2294-
integrity sha1-qrNUbfJFHs2JTgcbuZtd8Zxfp48=
2295-
dependencies:
2296-
q "^1.0.1"
2297-
tunnel "0.0.4"
2298-
typed-rest-client "^0.9.0"
2299-
underscore "^1.8.3"
2300-
23012296
which-module@^2.0.0:
23022297
version "2.0.0"
23032298
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"

0 commit comments

Comments
 (0)