mirror of
https://github.com/Unleash/unleash.git
synced 2024-10-18 20:09:08 +02:00
c1aab06798
This sets up the typescript compiler. Allowing gradual migration to typescript. Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai> Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com> Co-authored-by: Fredrik Oseberg <fredrik.oseberg@getunleash.ai> Co-authored-by: Clint Checkett <clintchecketts@churchofjesuschrist.org> fixes: #676
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const fetch = require('node-fetch');
|
|
const { addonDefinitionSchema } = require('./addon-schema');
|
|
|
|
class Addon {
|
|
constructor(definition, { getLogger }) {
|
|
this.logger = getLogger(`addon/${definition.name}`);
|
|
const { error } = addonDefinitionSchema.validate(definition);
|
|
if (error) {
|
|
this.logger.warn(
|
|
`Could not load addon provider ${definition.name}`,
|
|
error,
|
|
);
|
|
throw error;
|
|
}
|
|
this._name = definition.name;
|
|
this._definition = definition;
|
|
}
|
|
|
|
get name() {
|
|
return this._name;
|
|
}
|
|
|
|
get definition() {
|
|
return this._definition;
|
|
}
|
|
|
|
async fetchRetry(url, options = {}, retries = 1, backoff = 300) {
|
|
const retryCodes = [408, 500, 502, 503, 504, 522, 524];
|
|
const res = await fetch(url, options);
|
|
if (res.ok) {
|
|
return res;
|
|
}
|
|
if (retries > 0 && retryCodes.includes(res.status)) {
|
|
setTimeout(() => {
|
|
return this.fetchRetry(url, options, retries - 1, backoff * 2);
|
|
}, backoff);
|
|
}
|
|
return res;
|
|
}
|
|
}
|
|
|
|
module.exports = Addon;
|