Configeek JavaScript IC SDK for Internet Computer can be installed as an npm package.
Install the npm package and embed Configeek JavaScript IC SDK into your project.
npm install configeek-ic-js
Import Configeek JavaScript IC SDK into your code.
import {Configeek} from "configeek-ic-js";
//or
const {Configeek} = require("configeek-ic-js")
Configeek JavaScript IC SDK must be initialized in order to use any method available.
The only exception is Configeek.isInitialized
getter which can be used to check if SDK is initialized.
Project API key is needed to initialise Configeek JavaScript IC SDK.
It can be found in your project settings at https://configeek.app.
const config: InitConfig = {
apiKey: "<API_KEY>",
}
Configeek.init(config)
InitConfig
has the following interface:
export type InitConfig = {
/**
* Project API key
*/
apiKey: string,
/**
* Whether to fetch the configuration periodically. `false` by default
*/
periodicFetchingEnabled?: boolean
/**
* Callback that notifies about updated keys in configuration
* @param {{ updatedKeys: Array<string> }} result
*/
onConfigurationUpdatedCallback?: (result: { updatedKeys: Array<string> }) => void
/**
* Periodic fetch interval. `300000` by default (5 minutes in milliseconds). One minute minimal.
*/
fetchIntervalMillis?: number
/**
* Actor configuration. Used when Configeek library is used in a project running on local replica.
*/
localReplicaConfig?: ReplicaConfig
}
All configuration related data stored in browser's localStorage
This method returns the configuration or undefined
if configuration is not yet initialized.
const allConfiguration: Record<string, string> | undefined = Configeek.getAll()
This method returns the value of the configuration key or undefined
if there is no such key or configuration is not yet initialized/loaded or can't be loaded.
const myKeyValue: string | undefined = Configeek.getValue("myKey")
Periodical fetching can be used to monitor configuration changes automatically without manual fetch.
const enabled: boolean = Configeek.isPeriodicFetchingEnabled
Configeek.startPeriodicFetching()
Configeek.stopPeriodicFetching()
Configuration can be fetched manually at any time (after initialization)
Configeek.fetchConfig()
Sometimes it is worth to delete all data related to configuration.
This method stops periodical fetching and removes all data stored in localStorage
.
Configeek.destroy()
In order not to mix configuration from development environment with configuration from production environment we suggest separating development (DEV) and production (PROD) environments by creating additional project in Configeek portal.
Initialization in the code would look like this:
const CONFIGEEK_PROJECT_API_KEY_PROD = "ABCD"
const CONFIGEEK_PROJECT_API_KEY_DEV = "EFGH"
if (process.env.NODE_ENV === "development") {
Configeek.init({apiKey: CONFIGEEK_PROJECT_API_KEY_DEV})
} else {
Configeek.init({apiKey: CONFIGEEK_PROJECT_API_KEY_PROD})
}