-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-filter.js
51 lines (44 loc) · 1.17 KB
/
make-filter.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
46
47
48
49
50
51
/**
* @copyright Copyright 2016-2021 Kevin Locke <kevin@kevinlocke.name>
* @license MIT
*/
/** Values of support_level which have been observed in Procore docs,
* in order of increasing support.
*/
export const supportLevels = [
'internal',
'alpha',
'beta',
'production',
];
export default function makeEndpointFilter(
minSupportLevel,
includeBetaPrograms,
) {
const minIndex = supportLevels.indexOf(minSupportLevel);
if (minIndex === -1) {
throw new RangeError(`Unrecognized minSupportLevel '${minSupportLevel}'`);
}
if (!(includeBetaPrograms instanceof Set)) {
includeBetaPrograms = new Set(includeBetaPrograms);
}
return function endpointFilter({
support_level: supportLevel,
beta_programs: betaPrograms,
internal_only: internalOnly,
}) {
if (internalOnly && minIndex > 0) {
return false;
}
for (const betaProgram of betaPrograms) {
if (includeBetaPrograms.has(betaProgram)) {
return true;
}
}
const supportIndex = supportLevels.indexOf(supportLevel);
if (supportIndex === -1) {
this.warn('Unrecognized support_level:', supportLevel);
}
return supportIndex >= minIndex;
};
}