/
search.ts
83 lines (79 loc) · 2.14 KB
/
search.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import axios, { Canceler } from 'axios';
export { Canceler };
/**
* In the `.vscode/extensions.json` we'll need to use `${publisher.publisherName}.${extensionName}`.
*
* @example
* {
* "publisher": {
* "publisherId": "d16f4e39-2ffb-44e3-9c0d-79d873570e3a",
* "publisherName": "esbenp",
* "displayName": "Esben Petersen",
* "flags": "none"
* },
* "extensionId": "96fa4707-6983-4489-b7c5-d5ffdfdcce90",
* "extensionName": "prettier-vscode",
* "displayName": "Prettier - Code formatter",
* "flags": "validated, public",
* "lastUpdated": "2018-08-09T12:05:04.413Z",
* "publishedDate": "2017-01-10T19:52:02.703Z",
* "releaseDate": "2017-01-10T19:52:02.703Z",
* "shortDescription": "VS Code plugin for prettier/prettier",
* "deploymentType": 0
* }
*/
export type Extension = {
publisher: {
publisherId: string;
publisherName: string;
displayName: string;
flags: string;
};
extensionId: string;
extensionName: string;
displayName: string;
flags: string;
lastUpdated: string;
publishedDate: string;
releaseDate: string;
shortDescription: string;
deploymentType: number;
};
export type SearchRequest = {
cancel: Canceler;
request: Promise<Extension[] | void>;
};
export function search(value: string): SearchRequest {
const { token, cancel } = axios.CancelToken.source();
const options = {
cancelToken: token,
url:
'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery',
method: 'post',
headers: {
accept: 'application/json;api-version=5.0-preview.1;excludeUrls=true'
},
data: {
filters: [
{
criteria: [
// which visual studio app? code
{ filterType: 8, value: 'Microsoft.VisualStudio.Code' },
// our search value
{ filterType: 10, value }
],
pageSize: 10,
pageNumber: 1
}
]
}
};
const request = axios(options)
.then(({ data }) => data.results[0].extensions as Extension[])
.catch((error) => {
if (!axios.isCancel(error)) {
throw error;
}
});
return { request, cancel };
}