TypeScript Config SDK Reference

AutoblocksConfig

This is the base class your config will inherit from.

namerequireddefaultdescription
valuetrueThe 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.

namerequireddefaultdescription
configtrueThe remote config to activate. See examples below.
parsertrueThe function to use when parsing the remote config and setting the value of the config class.
apiKeyfalseAUTOBLOCKS_API_KEY environment variableYour Autoblocks API key.
refreshIntervalfalse{ seconds: 10 }How often to refresh the latest config. Only relevant if latest is set to true.
refreshTimeoutfalse{ 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.
activateTimeoutfalse{ 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