forked from firebase/flutterfire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
45 lines (39 loc) · 1.08 KB
/
api.js
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
const axios = require('axios');
// Fetch the plugins latest version from the pub API
async function fetchPluginVersion(plugin) {
try {
const response = await axios.get(`https://pub.dev/api/packages/${plugin}`);
const versions = response.data.versions;
if (!Array.isArray(versions)) {
return '';
}
return versions[versions.length - 1].version;
} catch (e) {
console.log(`Failed to load version for plugin "${plugin}".`);
return '';
}
}
// Fetch the plugins latest version documentation reference from the API
function fetchPluginApiReference(plugin, version = 'latest') {
return axios
.get(`https://pub.dev/documentation/${plugin}/${version}/index.json`, {
maxRedirects: 0,
})
.then(response => {
if (response.headers['content-type'] === 'application/json') {
return response.data.map(entity => ({
...entity,
version,
plugin,
}));
}
return null;
})
.catch(() => {
return null;
});
}
module.exports = {
fetchPluginVersion,
fetchPluginApiReference,
};