1.0.6 • Published 5 months ago
smoothsail-node-sdk v1.0.6
Using the Node SDK
- Install the SmoothSail Node SDK in your project by running
npm i smoothsail-node-sdk
. - Import the
SmoothSailConfig
file into whichever files you will be evaluating flags in.
import { SmoothSailConfig } from "smoothsail-node-sdk";
Set up an environment variable for the
SECRET_KEY
. This should be the same secret used for SmoothSail's Manager.Use the
SmoothSailConfig
class constructor to instantiate aconfig
object. The constructor takes two arguments:
- (string) SDK Key, from SmoothSail's dashboard UI
- (string) Address of SmoothSail's SDK Service
// shown as hard-coded but recommend having these as environment variables
const config = new SmoothSailConfig("SDK key", "SDK Service address");
- Instantiate a
SmoothSailClient
by callingconfig.connect()
. Note that this is an asynchronous action so you will need to useasync/await
to perform this step.
const config = new SmoothSailConfig("SDK key", "bearer address");
let client;
// instantiate SmoothSailClient
(async () => {
client = await config.connect();
})();
- Use the
SmoothSailClient.prototype.evaluateFlag()
method to evaluate flags.SmoothSailClient.prototype.evaluateFlag()
takes 3 arguments:
- (string) Flag Key,
fKey
from SmoothSail's dashboard UI - (object) User Context object
- (boolean) Default value for flag evaluation, optional argument
let testUserContext = {
user_name: "John Smith",
"beta-tester": true,
};
router.get("/", async (req, res) => {
if (client.evaluateFlag("flag-1", testUserContext, true)) {
// execute process for beta tester
} else {
// execute stable process
}
})