Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anime-skip/remote-config-client-ts
https://github.com/anime-skip/remote-config-client-ts
Last synced: 28 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/anime-skip/remote-config-client-ts
- Owner: anime-skip
- License: mit
- Created: 2021-11-28T18:48:22.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-28T20:11:20.000Z (about 3 years ago)
- Last Synced: 2024-11-07T18:43:10.985Z (3 months ago)
- Language: TypeScript
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `@anime-skip/remote-config`
A client library for [`anime-skip/remote-config`](https://github.com/anime-skip/remote-config)
- Synchronous access
- Configurable caching## Usage
```bash
npm i @anime-skip/remote-config
```Then initialize the client:
```ts
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
```ts
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:
```ts
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.
>
> ```ts
> remoteConfig.get('get');
> ```#### `all()`
Get all the remote config as a plain JS object without these methods on it:
```ts
console.log(remoteConfig.all());
```#### `waitForConfig()`
Returns a `Promise` for when the remote config is loaded from the server after being initialized
```ts
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.
```ts
await remoteConfig.fetchNow();
// Access the newer value
console.log(remoteConfig.someField);
```