@adnbn/plugin-remote-config
Version:
Remote config plugin for Addon Bone
34 lines (26 loc) • 865 B
text/typescript
import {getEnv} from "adnbn";
import isURL from "validator/lib/isURL";
import {RemoteConfig} from "./types";
export interface Options {
url?: string;
ttl: number;
config: RemoteConfig;
}
export default (): Options => {
let options: Partial<Options> = {};
try {
//@ts-expect-error: __REMOTE_CONFIG_OPTIONS__ is a virtual variable generated by the bundler `plugin/index.ts`
options = __REMOTE_CONFIG_OPTIONS__;
} catch (e) {
console.error(
"Failed to load @adnbn/plugin-remote-config parameters. Make sure the plugin is properly configured in the adnbn configuration file."
);
}
let {url, ttl = 1440, config = {}} = options;
if (typeof url === "string") {
url = isURL(url) ? url : getEnv(url);
} else {
url = undefined;
}
return {ttl, config, url};
};