From b59f16e16ea97f4dac199a55e029578d2e9c761e Mon Sep 17 00:00:00 2001 From: duyhungtnn Date: Wed, 5 Feb 2025 13:30:15 +0700 Subject: [PATCH 1/6] docs: node.js SDK - local evaluation --- docs/sdk/server-side/node-js/index.md | 60 ++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/docs/sdk/server-side/node-js/index.md b/docs/sdk/server-side/node-js/index.md index 3d90c26..1a69f84 100644 --- a/docs/sdk/server-side/node-js/index.md +++ b/docs/sdk/server-side/node-js/index.md @@ -55,7 +55,12 @@ import { initialize } from '@bucketeer/node-server-sdk'; -### Configuring client +### Initializing client + +The SDK supports local and remote evaluations. + +- [Local evaluation](#evaluating-users-within-sdk-locally): Evaluates end users within SDK locally +- [Remote evaluation](#remote-evaluation): Evaluate end users on the server Configure the SDK config and user configuration. :::info @@ -78,29 +83,74 @@ const config = { +#### Custom configuration + :::info Custom configuration Depending on your use, you may want to change the optional configurations available. -- **pollingIntervalForRegisterEvents** (Default is 1 minute) +- **pollingIntervalForRegisterEvents** (Default is 1 minute - specify in milliseconds) - **logger** (Default is `logger.DefaultLogger`) +- **enableLocalEvaluation** (Default is false) +- **cachePollingInterval** (Default is 1 minute - specify in milliseconds) + +For more information, please check the Option implementation [here](https://github.com/bucketeer-io/node-server-sdk/blob/master/src/config.ts). ::: -### Initializing client +#### Remote evaluation -Initialize the client by passing the configurations in the previous step. +To evaluate users on the server side you must create an API Key using the `Client SDK` role. ```js showLineNumbers -const client = initialize(config); + const config = { + host: HOST, + token: TOKEN, + tag: FEATURE_TAG, + } + const client = initialize(config); ``` +Once the SDK is configured, please check this [section](#evaluating-user) to learn how to get the variation for a user. + +#### Evaluating users within SDK locally + +By evaluating users locally you can improve response time significantly.
+To evaluate them you must create an API Key using the `Server SDK` role. + +The SDK will poll the Feature Flags and Segment Users from the server, and cache them in memory. + +:::caution + +The Server SDK API Key has access to all Feature Flags and Segment Users in the environment.
+Keep in mind that it might contain sensitive information, so be careful when sharing the key with others. + +::: + +When initializing the SDK you must enable the local evaluation setting. + + + + +```js showLineNumbers + const config = { + host: HOST, + token: TOKEN, + tag: FEATURE_TAG, + enableLocalEvaluation: true, + } + const client = initialize(config); +``` + +Once the SDK is configured, please check this [section](#evaluating-user) to learn how to get the variation for a user. + + ## Supported features ### Evaluating user From ebb344c4e842cecc372e16ea93577b9764424697 Mon Sep 17 00:00:00 2001 From: duyhungtnn Date: Wed, 5 Feb 2025 13:43:04 +0700 Subject: [PATCH 2/6] fix: missing tab item --- docs/sdk/server-side/node-js/index.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/sdk/server-side/node-js/index.md b/docs/sdk/server-side/node-js/index.md index 1a69f84..37e85ec 100644 --- a/docs/sdk/server-side/node-js/index.md +++ b/docs/sdk/server-side/node-js/index.md @@ -148,6 +148,9 @@ When initializing the SDK you must enable the local evaluation setting. const client = initialize(config); ``` + + + Once the SDK is configured, please check this [section](#evaluating-user) to learn how to get the variation for a user. From d66615962abe5c5d48f883a9aa8010e29b464c28 Mon Sep 17 00:00:00 2001 From: duyhungtnn Date: Wed, 5 Feb 2025 13:52:10 +0700 Subject: [PATCH 3/6] chore: fix missing . --- docs/sdk/server-side/node-js/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sdk/server-side/node-js/index.md b/docs/sdk/server-side/node-js/index.md index 37e85ec..6b880a5 100644 --- a/docs/sdk/server-side/node-js/index.md +++ b/docs/sdk/server-side/node-js/index.md @@ -59,8 +59,8 @@ import { initialize } from '@bucketeer/node-server-sdk'; The SDK supports local and remote evaluations. -- [Local evaluation](#evaluating-users-within-sdk-locally): Evaluates end users within SDK locally -- [Remote evaluation](#remote-evaluation): Evaluate end users on the server +- [Local evaluation](#evaluating-users-within-sdk-locally): Evaluates end users within SDK locally. +- [Remote evaluation](#remote-evaluation): Evaluate end users on the server. Configure the SDK config and user configuration. :::info From b9e894f13bbc531c7a233fc19b867a270b54771b Mon Sep 17 00:00:00 2001 From: duyhungtnn Date: Wed, 5 Feb 2025 13:57:00 +0700 Subject: [PATCH 4/6] chore: add cachePollingInterval in code example --- docs/sdk/server-side/node-js/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/sdk/server-side/node-js/index.md b/docs/sdk/server-side/node-js/index.md index 6b880a5..5d41e8e 100644 --- a/docs/sdk/server-side/node-js/index.md +++ b/docs/sdk/server-side/node-js/index.md @@ -143,7 +143,8 @@ When initializing the SDK you must enable the local evaluation setting. host: HOST, token: TOKEN, tag: FEATURE_TAG, - enableLocalEvaluation: true, + enableLocalEvaluation: true, // <--- Enable the local evaluation + cachePollingInterval: 10 * 60000, // <--- Change the default interval if needed } const client = initialize(config); ``` From 7b4b510e1500c99b6fdc3be30bb296997d9dc2a5 Mon Sep 17 00:00:00 2001 From: duyhungtnn Date: Wed, 5 Feb 2025 15:15:46 +0700 Subject: [PATCH 5/6] Update docs/sdk/server-side/node-js/index.md Co-authored-by: Alessandro Yuichi Okimoto --- docs/sdk/server-side/node-js/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/sdk/server-side/node-js/index.md b/docs/sdk/server-side/node-js/index.md index 5d41e8e..e2ef0c6 100644 --- a/docs/sdk/server-side/node-js/index.md +++ b/docs/sdk/server-side/node-js/index.md @@ -140,9 +140,9 @@ When initializing the SDK you must enable the local evaluation setting. ```js showLineNumbers const config = { - host: HOST, - token: TOKEN, - tag: FEATURE_TAG, + host: 'YOUR_API_ENDPOINT', + token:'YOUR_API_KEY', + tag: 'YOUR_FEATURE_TAG', enableLocalEvaluation: true, // <--- Enable the local evaluation cachePollingInterval: 10 * 60000, // <--- Change the default interval if needed } From cb156f35862d31f90ffc4109634828265164b932 Mon Sep 17 00:00:00 2001 From: duyhungtnn Date: Wed, 5 Feb 2025 15:16:19 +0700 Subject: [PATCH 6/6] Update index.md --- docs/sdk/server-side/node-js/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/sdk/server-side/node-js/index.md b/docs/sdk/server-side/node-js/index.md index e2ef0c6..8b72430 100644 --- a/docs/sdk/server-side/node-js/index.md +++ b/docs/sdk/server-side/node-js/index.md @@ -107,9 +107,9 @@ To evaluate users on the server side you must create an API Key using the `Clien ```js showLineNumbers const config = { - host: HOST, - token: TOKEN, - tag: FEATURE_TAG, + host: 'YOUR_API_ENDPOINT', + token:'YOUR_API_KEY', + tag: 'YOUR_FEATURE_TAG', } const client = initialize(config); ```