From fd144bb13457c29102e60f2075243f52b1ce6d0b Mon Sep 17 00:00:00 2001 From: Todd Baert Date: Thu, 29 Sep 2022 13:22:55 -0400 Subject: [PATCH] feat: experimental web support (#200) Signed-off-by: Todd Baert --- README.md | 2 +- package.json | 8 +++----- src/open-feature.ts | 6 +++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f4f297e2b..c82e0a1d0 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This is the JavaScript implementation of [OpenFeature](https://openfeature.dev), We support multiple data types for flags (numbers, strings, booleans, objects) as well as hooks, which can alter the lifecycle of a flag evaluation. -This library is intended to be used in server-side contexts and has not been evaluated for use client-side or on mobile devices. +**This library is intended to be used in server-side contexts and has only experimental support for web usage.** ## Installation diff --git a/package.json b/package.json index 1d708dfa6..b4c05c4a6 100644 --- a/package.json +++ b/package.json @@ -36,11 +36,9 @@ "dist/" ], "exports": { - "node": { - "import": "./dist/esm/index.js", - "require": "./dist/cjs/index.js", - "default": "./dist/esm/index.js" - } + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js", + "default": "./dist/cjs/index.js" }, "devDependencies": { "@types/jest": "^28.1.4", diff --git a/src/open-feature.ts b/src/open-feature.ts index 7c15a9df8..94428b2ab 100644 --- a/src/open-feature.ts +++ b/src/open-feature.ts @@ -9,7 +9,7 @@ const GLOBAL_OPENFEATURE_API_KEY = Symbol.for('@openfeature/js.api'); type OpenFeatureGlobal = { [GLOBAL_OPENFEATURE_API_KEY]?: OpenFeatureAPI; }; -const _global = global as OpenFeatureGlobal; +const _globalThis = globalThis as OpenFeatureGlobal; class OpenFeatureAPI implements GlobalApi { private _provider: Provider = NOOP_PROVIDER; @@ -18,13 +18,13 @@ class OpenFeatureAPI implements GlobalApi { private _logger: Logger = new DefaultLogger(); static getInstance(): OpenFeatureAPI { - const globalApi = _global[GLOBAL_OPENFEATURE_API_KEY]; + const globalApi = _globalThis[GLOBAL_OPENFEATURE_API_KEY]; if (globalApi) { return globalApi; } const instance = new OpenFeatureAPI(); - _global[GLOBAL_OPENFEATURE_API_KEY] = instance; + _globalThis[GLOBAL_OPENFEATURE_API_KEY] = instance; return instance; }