From 7e1dd72a1450a9982b340afda62d34379d1b3f16 Mon Sep 17 00:00:00 2001 From: adams85 <31276480+adams85@users.noreply.github.com> Date: Wed, 18 Sep 2024 15:09:04 +0200 Subject: [PATCH] fix(config-cat): Revise readme (#1054) Signed-off-by: Adam Simon Signed-off-by: Adam Simon Co-authored-by: Adam Simon Co-authored-by: Adam Simon --- libs/providers/config-cat-web/README.md | 32 ++++++++++++++----- .../config-cat-web/package-lock.json | 22 ++++++------- libs/providers/config-cat-web/package.json | 2 +- libs/providers/config-cat/README.md | 30 +++++++++++++---- libs/providers/config-cat/package-lock.json | 22 ++++++------- libs/providers/config-cat/package.json | 2 +- package-lock.json | 28 ++++++++-------- package.json | 4 +-- 8 files changed, 87 insertions(+), 55 deletions(-) diff --git a/libs/providers/config-cat-web/README.md b/libs/providers/config-cat-web/README.md index 9de3e6420..0f1dd4c11 100644 --- a/libs/providers/config-cat-web/README.md +++ b/libs/providers/config-cat-web/README.md @@ -1,6 +1,6 @@ # ConfigCat Web Provider -This provider is an implementation for [ConfigCat](https://configcat.com) a managed feature flag service. +This is an OpenFeature provider implementation for using [ConfigCat](https://configcat.com), a managed feature flag service in JavaScript frontend applications. ## Installation @@ -14,10 +14,10 @@ The OpenFeature SDK is required as peer dependency. The minimum required version of `@openfeature/web-sdk` currently is `1.0.0`. -The minimum required version of `configcat-js-ssr` currently is `8.4.1`. +The minimum required version of `configcat-js-ssr` currently is `8.4.3`. ``` -$ npm install @openfeature/client-sdk configcat-js-ssr +$ npm install @openfeature/web-sdk configcat-js-ssr ``` ## Usage @@ -32,29 +32,45 @@ The ConfigCat Web Provider only supports the `AutoPolling` mode because it cache ### Example using the default configuration ```javascript +import { OpenFeature } from "@openfeature/web-sdk"; import { ConfigCatWebProvider } from '@openfeature/config-cat-web-provider'; +// Create and set the provider. const provider = ConfigCatWebProvider.create(''); -OpenFeature.setProvider(provider); +await OpenFeature.setProviderAndWait(provider); + +// Create a client instance to evaluate feature flags. +const client = OpenFeature.getClient(); + +const value = await client.getBooleanValue('isAwesomeFeatureEnabled', false); +console.log(`isAwesomeFeatureEnabled: ${value}`); + +// On application shutdown, clean up the OpenFeature provider and the underlying ConfigCat client. +await OpenFeature.clearProviders(); ``` -### Example using different polling options and a setupHook +### Example using custom configuration ```javascript +import { OpenFeature } from "@openfeature/web-sdk"; import { ConfigCatWebProvider } from '@openfeature/config-cat-web-provider'; +import { createConsoleLogger, LogLevel } from 'configcat-js-ssr'; +// Create and set the provider. const provider = ConfigCatWebProvider.create('', { + logger: createConsoleLogger(LogLevel.Info), setupHooks: (hooks) => hooks.on('clientReady', () => console.log('Client is ready!')), }); +await OpenFeature.setProviderAndWait(provider); -OpenFeature.setProvider(provider); +// ... ``` ## Evaluation Context -The OpenFeature Evaluation Context is mapped to the [ConfigCat user object](https://configcat.com/docs/advanced/user-object/). +The OpenFeature Evaluation Context is mapped to the [ConfigCat User Object](https://configcat.com/docs/advanced/user-object/). -The [ConfigCat user object](https://configcat.com/docs/advanced/user-object/) has three known attributes, +The [ConfigCat User Object](https://configcat.com/docs/advanced/user-object/) has three predefined attributes, and allows for additional attributes. The following shows how the attributes are mapped: diff --git a/libs/providers/config-cat-web/package-lock.json b/libs/providers/config-cat-web/package-lock.json index 4e23b1e29..10339899e 100644 --- a/libs/providers/config-cat-web/package-lock.json +++ b/libs/providers/config-cat-web/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.2", "peerDependencies": { "@openfeature/web-sdk": "^1.0.0", - "configcat-js-ssr": "^8.4.2" + "configcat-js-ssr": "^8.4.3" } }, "node_modules/@openfeature/core": { @@ -57,22 +57,22 @@ } }, "node_modules/configcat-common": { - "version": "9.3.0", - "resolved": "https://registry.npmjs.org/configcat-common/-/configcat-common-9.3.0.tgz", - "integrity": "sha512-WgpCanLPsT0ig4eLEo2BCZvo0sqtGIkRREnxNAX3Hubw0FzyQ7JUbiliw7ZlBNgda5jaO2nvcs3man+PDdfyLQ==", + "version": "9.3.1", + "resolved": "https://registry.npmjs.org/configcat-common/-/configcat-common-9.3.1.tgz", + "integrity": "sha512-yVkIbluksD/kZfVyKjLIOpwLrq3/ZRM7Lwrsz89JmbpQ6VtbnelrTQynSPElTtKjrPRZx56v3IZYk3nWTnnM6A==", "peer": true, "dependencies": { "tslib": "^2.4.1" } }, "node_modules/configcat-js-ssr": { - "version": "8.4.2", - "resolved": "https://registry.npmjs.org/configcat-js-ssr/-/configcat-js-ssr-8.4.2.tgz", - "integrity": "sha512-ksn7aV428kVg/XmzHGVLIYn5ds6b8VVpVHPTgmJ2CXcHeXJ+NeoyRWYgO+Zz3HzMxlKW1IMVthZAk62PajlelQ==", + "version": "8.4.3", + "resolved": "https://registry.npmjs.org/configcat-js-ssr/-/configcat-js-ssr-8.4.3.tgz", + "integrity": "sha512-9tNM61cgJOE9C1MO8wBK1QglrnlT8VpiAW/KgGdFdOuIPs3ky62EThgAE+HYSRYEv4JrRNB4i7G0v1Qgbf18Hw==", "peer": true, "dependencies": { "axios": "^1.7.4", - "configcat-common": "9.3.0", + "configcat-common": "9.3.1", "tslib": "^2.4.1" } }, @@ -147,9 +147,9 @@ "peer": true }, "node_modules/tslib": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", - "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", + "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==", "peer": true } } diff --git a/libs/providers/config-cat-web/package.json b/libs/providers/config-cat-web/package.json index 82bedda64..e888e7682 100644 --- a/libs/providers/config-cat-web/package.json +++ b/libs/providers/config-cat-web/package.json @@ -7,6 +7,6 @@ }, "peerDependencies": { "@openfeature/web-sdk": "^1.0.0", - "configcat-js-ssr": "^8.4.2" + "configcat-js-ssr": "^8.4.3" } } diff --git a/libs/providers/config-cat/README.md b/libs/providers/config-cat/README.md index 0615f2160..dc842aeca 100644 --- a/libs/providers/config-cat/README.md +++ b/libs/providers/config-cat/README.md @@ -1,6 +1,6 @@ # ConfigCat Provider -This provider is an implementation for [ConfigCat](https://configcat.com) a managed feature flag service. +This is an OpenFeature provider implementation for using [ConfigCat](https://configcat.com), a managed feature flag service in Node.js applications. ## Installation @@ -14,7 +14,7 @@ The OpenFeature SDK is required as peer dependency. The minimum required version of `@openfeature/server-sdk` currently is `1.13.5`. -The minimum required version of `configcat-node` currently is `11.0.0`. +The minimum required version of `configcat-node` currently is `11.3.1`. ``` $ npm install @openfeature/server-sdk configcat-node @@ -31,29 +31,45 @@ The available options can be found in the [ConfigCat Node.js SDK](https://config ### Example using the default configuration ```javascript +import { OpenFeature } from "@openfeature/server-sdk"; import { ConfigCatProvider } from '@openfeature/config-cat-provider'; +// Create and set the provider. const provider = ConfigCatProvider.create(''); -OpenFeature.setProvider(provider); +await OpenFeature.setProviderAndWait(provider); + +// Obtain a client instance and evaluate feature flags. +const client = OpenFeature.getClient(); + +const value = await client.getBooleanValue('isAwesomeFeatureEnabled', false); +console.log(`isAwesomeFeatureEnabled: ${value}`); + +// On application shutdown, clean up the OpenFeature provider and the underlying ConfigCat client. +await OpenFeature.clearProviders(); ``` -### Example using different polling options and a setupHook +### Example using a different polling mode and custom configuration ```javascript +import { OpenFeature } from "@openfeature/server-sdk"; import { ConfigCatProvider } from '@openfeature/config-cat-provider'; +import { createConsoleLogger, LogLevel, PollingMode } from 'configcat-node'; +// Create and set the provider. const provider = ConfigCatProvider.create('', PollingMode.LazyLoad, { + logger: createConsoleLogger(LogLevel.Info), setupHooks: (hooks) => hooks.on('clientReady', () => console.log('Client is ready!')), }); +await OpenFeature.setProviderAndWait(provider); -OpenFeature.setProvider(provider); +// ... ``` ## Evaluation Context -The OpenFeature Evaluation Context is mapped to the [ConfigCat user object](https://configcat.com/docs/advanced/user-object/). +The OpenFeature Evaluation Context is mapped to the [ConfigCat User Object](https://configcat.com/docs/advanced/user-object/). -The [ConfigCat user object](https://configcat.com/docs/advanced/user-object/) has three known attributes, +The [ConfigCat User Object](https://configcat.com/docs/advanced/user-object/) has three predefined attributes, and allows for additional attributes. The following shows how the attributes are mapped: diff --git a/libs/providers/config-cat/package-lock.json b/libs/providers/config-cat/package-lock.json index 7eb647fdb..f6193fbdb 100644 --- a/libs/providers/config-cat/package-lock.json +++ b/libs/providers/config-cat/package-lock.json @@ -9,7 +9,7 @@ "version": "0.7.1", "peerDependencies": { "@openfeature/server-sdk": "^1.13.5", - "configcat-node": "^11.0.0" + "configcat-node": "^11.3.1" } }, "node_modules/@openfeature/core": { @@ -31,21 +31,21 @@ } }, "node_modules/configcat-common": { - "version": "9.3.0", - "resolved": "https://registry.npmjs.org/configcat-common/-/configcat-common-9.3.0.tgz", - "integrity": "sha512-WgpCanLPsT0ig4eLEo2BCZvo0sqtGIkRREnxNAX3Hubw0FzyQ7JUbiliw7ZlBNgda5jaO2nvcs3man+PDdfyLQ==", + "version": "9.3.1", + "resolved": "https://registry.npmjs.org/configcat-common/-/configcat-common-9.3.1.tgz", + "integrity": "sha512-yVkIbluksD/kZfVyKjLIOpwLrq3/ZRM7Lwrsz89JmbpQ6VtbnelrTQynSPElTtKjrPRZx56v3IZYk3nWTnnM6A==", "peer": true, "dependencies": { "tslib": "^2.4.1" } }, "node_modules/configcat-node": { - "version": "11.3.0", - "resolved": "https://registry.npmjs.org/configcat-node/-/configcat-node-11.3.0.tgz", - "integrity": "sha512-Mo2K6WzsT8ggesdxgL1a9cwX5VSqns7u4TcumAP11UuIEFpaB8I5utNmOircVT7pZeyT6aFTP7kRhKdSU6C+/A==", + "version": "11.3.1", + "resolved": "https://registry.npmjs.org/configcat-node/-/configcat-node-11.3.1.tgz", + "integrity": "sha512-7XJbgBpcxlwzlRLmvCtHTkO247Ban2ZkBqlmk+T0wVEt5tXfltgd53SYLYpw7RBWX0ma/QyP5E+/k/UDdMrOCw==", "peer": true, "dependencies": { - "configcat-common": "9.3.0", + "configcat-common": "9.3.1", "tslib": "^2.4.1", "tunnel": "0.0.6" }, @@ -54,9 +54,9 @@ } }, "node_modules/tslib": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", - "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", + "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==", "peer": true }, "node_modules/tunnel": { diff --git a/libs/providers/config-cat/package.json b/libs/providers/config-cat/package.json index 434d2b590..6a76e966c 100644 --- a/libs/providers/config-cat/package.json +++ b/libs/providers/config-cat/package.json @@ -7,6 +7,6 @@ }, "peerDependencies": { "@openfeature/server-sdk": "^1.13.5", - "configcat-node": "^11.0.0" + "configcat-node": "^11.3.1" } } diff --git a/package-lock.json b/package-lock.json index a94519c26..ef5c5bd09 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,8 +22,8 @@ "@swc/helpers": "0.5.11", "ajv": "^8.12.0", "axios": "1.7.4", - "configcat-js-ssr": "^8.3.0", - "configcat-node": "^11.3.0", + "configcat-js-ssr": "^8.4.3", + "configcat-node": "^11.3.1", "copy-anything": "^3.0.5", "flagsmith": "^4.0.0", "imurmurhash": "^0.1.4", @@ -6779,29 +6779,29 @@ } }, "node_modules/configcat-common": { - "version": "9.3.0", - "resolved": "https://registry.npmjs.org/configcat-common/-/configcat-common-9.3.0.tgz", - "integrity": "sha512-WgpCanLPsT0ig4eLEo2BCZvo0sqtGIkRREnxNAX3Hubw0FzyQ7JUbiliw7ZlBNgda5jaO2nvcs3man+PDdfyLQ==", + "version": "9.3.1", + "resolved": "https://registry.npmjs.org/configcat-common/-/configcat-common-9.3.1.tgz", + "integrity": "sha512-yVkIbluksD/kZfVyKjLIOpwLrq3/ZRM7Lwrsz89JmbpQ6VtbnelrTQynSPElTtKjrPRZx56v3IZYk3nWTnnM6A==", "dependencies": { "tslib": "^2.4.1" } }, "node_modules/configcat-js-ssr": { - "version": "8.4.1", - "resolved": "https://registry.npmjs.org/configcat-js-ssr/-/configcat-js-ssr-8.4.1.tgz", - "integrity": "sha512-MWYgtaBkWzAbIPy0hA0M1UV1JSqzXhk1m25f1HFbQMoP/ybX/lDrGUiCMyDosPjcV82qjul8MTiDWIIgOfabPw==", + "version": "8.4.3", + "resolved": "https://registry.npmjs.org/configcat-js-ssr/-/configcat-js-ssr-8.4.3.tgz", + "integrity": "sha512-9tNM61cgJOE9C1MO8wBK1QglrnlT8VpiAW/KgGdFdOuIPs3ky62EThgAE+HYSRYEv4JrRNB4i7G0v1Qgbf18Hw==", "dependencies": { - "axios": "^1.6.8", - "configcat-common": "9.3.0", + "axios": "^1.7.4", + "configcat-common": "9.3.1", "tslib": "^2.4.1" } }, "node_modules/configcat-node": { - "version": "11.3.0", - "resolved": "https://registry.npmjs.org/configcat-node/-/configcat-node-11.3.0.tgz", - "integrity": "sha512-Mo2K6WzsT8ggesdxgL1a9cwX5VSqns7u4TcumAP11UuIEFpaB8I5utNmOircVT7pZeyT6aFTP7kRhKdSU6C+/A==", + "version": "11.3.1", + "resolved": "https://registry.npmjs.org/configcat-node/-/configcat-node-11.3.1.tgz", + "integrity": "sha512-7XJbgBpcxlwzlRLmvCtHTkO247Ban2ZkBqlmk+T0wVEt5tXfltgd53SYLYpw7RBWX0ma/QyP5E+/k/UDdMrOCw==", "dependencies": { - "configcat-common": "9.3.0", + "configcat-common": "9.3.1", "tslib": "^2.4.1", "tunnel": "0.0.6" }, diff --git a/package.json b/package.json index d2120ac7f..8ec726aa3 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,8 @@ "@swc/helpers": "0.5.11", "ajv": "^8.12.0", "axios": "1.7.4", - "configcat-js-ssr": "^8.3.0", - "configcat-node": "^11.3.0", + "configcat-js-ssr": "^8.4.3", + "configcat-node": "^11.3.1", "copy-anything": "^3.0.5", "flagsmith": "^4.0.0", "imurmurhash": "^0.1.4",