TypeScript Config SDK Reference
AutoblocksConfig
This is the base class your config will inherit from.
name | required | default | description |
---|---|---|---|
value | true | The initial value for the config |
type RemoteConfigSchema = {
my_val: string;
}
const config = new AutoblocksConfig<RemoteConfigSchema>({
my_val: 'initial-val',
});
// Usage
config.value.my_val
activateFromRemote
Retrieves the value of a remote config and overrides the initial value of the config class.
name | required | default | description |
---|---|---|---|
config | true | The remote config to activate. See examples below. | |
parser | true | The function to use when parsing the remote config and setting the value of the config class. | |
apiKey | false | AUTOBLOCKS_API_KEY environment variable | Your Autoblocks API key. |
refreshInterval | false | { seconds: 10 } | How often to refresh the latest config. Only relevant if latest is set to true . |
refreshTimeout | false | { seconds: 30 } | How long to wait for the latest config to refresh before timing out. A refresh timeout will not raise an uncaught exception. An error will be logged and the background refresh process will continue to run at its configured interval. |
activateTimeout | false | { seconds: 30 } | How long to wait for the remote config to activate before timing out. |
import { AutoblocksConfig } from '@autoblocks/client/configs';
import { z } from 'zod';
const zRemoteConfigSchema = z.object({
my_val: z.string().min(1),
});
type RemoteConfigSchema = z.infer<typeof zRemoteConfigSchema>;
const config = new AutoblocksConfig<RemoteConfigSchema>({
my_val: 'initial-val',
});
await config.activateFromRemote({
config: {
id: 'my-remote-config',
version: {
major: 1,
latest: true,
}
},
parser: zRemoteConfigSchema.parse,
});
// Usage
config.value.my_val
We are using Zod
for schema validation in this example. You can use any schema validation library you prefer.