The Vect SDK provides a safe and easy way to access the parameters you manage in app.vect.io, allowing you to read parameters and react to changes in a fault-tolerant way.

Getting Started

Installation

(PKG_CREDS=<pkg-creds> && \\
VERSION=<version> && \\
npm remove @vect-io/vect-sdk && npm add <https://[email protected]/artifactory/prod-v2022-1-npm-local/%40vect-io/vect-sdk/-/%40vect-io/vect-sdk-$VERSION.tgz> )

<aside> 💡 npm can be replaced with yarn . For pnpm, use npm add -g

</aside>

Initializing

Initialize your Vect repository client:

import { VectRepository } from '@vect-io/vect-sdk';

const vectRepo = new VectRepository({
  repoPath: 'acme-com/acme-v2022-1',
  apiKey: { apiKeyName: 'acme-v2022-1', apiKey: 'hfrT7feFHW89FHAoRABVaw12D' },
});

Accessing Parameters

In order to subscribe to a file, use vectRepo.watchFile to keep the parameters up to date and cached for fault tolerance.

Get Accessor

To access the current state of a file:

const getLatest = await vectRepo.watchFile('foo/bar/baz.json').initGetLatest();
console.log(`foo/bar/baz.json: ${getLatest()}`);

getLatest then returns the latest update of watchFile instantly without a network request. initGetLatest waits for the initial GET request to resolve.

undefined is returned if the file doesn’t exist in Vect.

Callback Accessor

To run a callback on init and updates to a file:

vectRepo.watchFile('foo/bar/baz.json', { callback: (params) => console.log(`foo/bar/baz.json: ${params}`) });

The callback accepts the file content (as returned by getLatest), and runs on each change.