UNPKG

2.03 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.PublicGalleryAPI = void 0;
4const HttpClient_1 = require("typed-rest-client/HttpClient");
5const GalleryInterfaces_1 = require("azure-devops-node-api/interfaces/GalleryInterfaces");
6const Serialization_1 = require("azure-devops-node-api/Serialization");
7class PublicGalleryAPI {
8 constructor(baseUrl, apiVersion = '3.0-preview.1') {
9 this.baseUrl = baseUrl;
10 this.apiVersion = apiVersion;
11 this.client = new HttpClient_1.HttpClient('vsce');
12 }
13 post(url, data, additionalHeaders) {
14 return this.client.post(`${this.baseUrl}/_apis/public${url}`, data, additionalHeaders);
15 }
16 async extensionQuery({ pageNumber = 1, pageSize = 1, flags = [], criteria = [], assetTypes = [], }) {
17 const data = JSON.stringify({
18 filters: [{ pageNumber, pageSize, criteria }],
19 assetTypes,
20 flags: flags.reduce((memo, flag) => memo | flag, 0),
21 });
22 const res = await this.post('/gallery/extensionquery', data, {
23 Accept: `application/json;api-version=${this.apiVersion}`,
24 'Content-Type': 'application/json',
25 });
26 const raw = JSON.parse(await res.readBody());
27 if (raw.errorCode !== undefined) {
28 throw new Error(raw.message);
29 }
30 return Serialization_1.ContractSerializer.deserialize(raw.results[0].extensions, GalleryInterfaces_1.TypeInfo.PublishedExtension, false, false);
31 }
32 async getExtension(extensionId, flags = []) {
33 const query = { criteria: [{ filterType: GalleryInterfaces_1.ExtensionQueryFilterType.Name, value: extensionId }], flags };
34 const extensions = await this.extensionQuery(query);
35 return extensions.filter(({ publisher: { publisherName: publisher }, extensionName: name }) => extensionId.toLowerCase() === `${publisher}.${name}`.toLowerCase())[0];
36 }
37}
38exports.PublicGalleryAPI = PublicGalleryAPI;
39//# sourceMappingURL=publicgalleryapi.js.map
\No newline at end of file