-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
40 lines (33 loc) · 912 Bytes
/
index.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
const fetch = require("node-fetch");
const semver = require("semver");
/**
* Pact Broker Client that can be used to interact with a running
* pact broker instance.
*/
class PactBrokerClient extends Object {
/**
* @param {string} url
*/
constructor(url) {
super();
this.url = url;
}
/**
*
* @param {string} pacticipant
* @param {string=} minVersion
* @return {string[]}
*/
async getVersions(pacticipant, minVersion) {
const response = await fetch(`${this.url}/pacticipants/${pacticipant}/versions`);
const json = await response.json()
let versions = json._embedded.versions.map(versionInfo => versionInfo.number).sort((a, b) => semver.lt(a, b));
if (!!minVersion) {
versions = versions.filter(version => semver.lte(minVersion, version));
}
return versions;
}
async in() {}
async out() {}
}
module.exports = PactBrokerClient;