Skip to content

anime-skip/remote-config-client-ts

Repository files navigation

@anime-skip/remote-config

A client library for anime-skip/remote-config

  • Synchronous access
  • Configurable caching

Usage

npm i @anime-skip/remote-config

Then initialize the client:

import { initRemoteConfig } from '@anime-skip/remote-config';

export const remoteConfig = initRemoteConfig({
  baseUrl: 'https://remote-config.anime-skip.com',
  app: 'Anime Skip Player',
});

// Access configuration from the object
console.log(remoteConfig.someField);

This library uses fetch, so if you're using this on a node server you'll need to install a polyfill

Configuration

createClient({
  //...

  // Refresh the config every 60s
  interval: 60 * 1000,

  // Set an initial config while the config is loading for the first time
  defaultConfig: {
    someField: 'Some value',
  },

  // Override the default logging behavior of console.warn
  warn: someWarnMethod,
});

Methods

get()

An alternative method for accessing the remote config:

remoteConfig.get('someField') === remoteConfig.someField;

Method names can conflict with remote config fields. In that case, you can use get(...) to grab the value instead of accessing it directly through the remoteConfig object.

remoteConfig.get('get');

all()

Get all the remote config as a plain JS object without these methods on it:

console.log(remoteConfig.all());

waitForConfig()

Returns a Promise<void> for when the remote config is loaded from the server after being initialized

await remoteConfig.waitForConfig();
// Access the values from the remote server
console.log(remoteConfig.someField);

fetchNow()

Fetch and cache the latest config from the server. After the promise has been resolved, you access the config through the object like usual.

await remoteConfig.fetchNow();
// Access the newer value
console.log(remoteConfig.someField);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages