GithubHelp home page GithubHelp logo

configcat / common-js Goto Github PK

View Code? Open in Web Editor NEW
10.0 5.0 10.0 1006 KB

Common Javascript library for ConfigCat. ConfigCat is a hosted feature flag service: https://configcat.com. Manage feature toggles across frontend, backend, mobile, desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs.

Home Page: https://configcat.com

License: MIT License

TypeScript 99.96% Shell 0.04%
configcat feature-flags feature-flag feature-toggles feature-toggle javascript typescript configuration configuration-management featureflags remote-config

common-js's Introduction

ConfigCat Common library for JavaScript

Common JS CI codecov Known Vulnerabilities Tree Shaking License
NPM

ConfigCat Common library for JavaScript is a shared package that provides the common ConfigCat SDK logic for ConfigCat SDK for Node.js and ConfigCat SDK for JavaScript.

ConfigCat is a feature flag, feature toggle, and configuration management service that lets you launch new features and change your software configuration remotely without actually (re)deploying code. ConfigCat even helps you do controlled roll-outs like canary releases and blue-green deployments.

ConfigCat is a hosted feature flag service. Manage feature toggles across frontend, backend, mobile, desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs.

Installing

npm install

Running the tests

npm test

Need help?

https://configcat.com/support

Contributing

Contributions are welcome. For more info please read the Contribution Guideline.

About ConfigCat

Troubleshooting

Make sure you have the proper Node.js version installed

You might run into errors caused by the wrong version of Node.js. To make sure you are using the recommended Node.js version follow these steps.

  1. Have nvm (Node Version Manager - https://github.com/nvm-sh/nvm ) installed:
  2. Run nvm install. This will install the compatible version of Node.js.
  3. Run nvm use. This will use the compatible version of Node.js.

common-js's People

Contributors

adams85 avatar configcat-developer avatar dave-irvine avatar ddemydenko avatar dependabot[bot] avatar endret avatar exchange321 avatar jdgarcia avatar kp-cat avatar lajos88 avatar laliconfigcat avatar mr-sige avatar sigewuzhere avatar takuyahara avatar z4kn4fein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

common-js's Issues

Passing NaN as pollIntervalSeconds interval causes setTimeout infinity call

Describe the bug

Passing NaN as pollIntervalSeconds interval causes setTimeout infinity call, that in turn millions requests to config-cat CDN

To reproduce

Pass undefined casted to Number as parameter

const myConfig = new Map();
myConfig.set('pollIntervalSeconds', undefined);
new AutoPollOptions("APIKEY", "common", "1.0.0", { pollIntervalSeconds: +(myConfig.get('pollIntervalSeconds')) }, null);

Expected behavior

Configcat client should validate this wrong parameter and throw an exception

Here is recursive with 0 seconds duration
https://github.com/configcat/common-js/blob/master/src/AutoPollConfigService.ts#L91

e.Equals is not a function

My team is occasionally seeing end users run into an e.Equals is not a function exception:

grafik

Do you have any idea what may be causing this? Is there a workaround?

Tearing down / stopping polling

How would I cleanly tear down a client instance? For context, I am writing a react hooks integration for our project and I can't find a way to remove the timers that the Autopoller creates. If I were to create an instance of configcat in a component I would be unable to clean it up on unmount, leading to memory leaks.

I'd expect to be able to do something like:

const ConfigCat = ({ children }) => {
  const clientRef = useRef(configcat.createClient());
  useEffect(() => {
    // on unmount stop polling and cleanup
    return () => clientRef.current.cleanup();
  }, [clientRef.current]);
  return (
    <ConfigCatContext.Provider value={clientRef.current}>
      {children}
    </ConfigCatContext.Provider>
  );
}

Unnecessary 'util' dependency breaks Expo compatibility

The following line adds a Node.js dependency that could be easily replaced:

import { isUndefined } from "util";

Removing this import and defining the following function would make ConfigCat compatible with Expo applications:

function isUndefined(obj: any): boolean {
    return obj === undefined;
}

I've tested ConfigCat with these changes, and the modified version works nicely on Expo.

Please consider making this change. Thank you.

Odd? values in DataGovernance enum

Describe the bug

Hello, I'm currently working on updating the Ember addon we published for ConfigCat.
I ran into some TypeScript error: when trying to build a typed options object for the ConfigCat Client, I noticed some difference between the DataGovernance exported here

export enum DataGovernance {
and the value expected by the documentation here https://configcat.com/docs/sdk-reference/js#auto-polling-default
Which are the correct values?:

  • 0 or 1
  • Global or EuOnly?

To reproduce

TypeScript Sandbox https://www.typescriptlang.org/play?#code/PQKhAIGEHsDsBcBO0A254AsCm4XQMYCG8AlnONAGbrbj5yUkDmAdAFYDO5jKWHdceIRKwRTcAE9oAV0ThKWYrJyUUhJv0KwAJuA5Z4pWBvAB3EphE0cMWIyaRiUACIA5FuBDAAUFgAeAA7QiPDgWLDSALbgzsSEAOLQAG5YiLBa+DgA3t7geeCgEADKWLz4oZb8JNRSsvKK8MryaiaEiDgB0gBGKCQc2Lrw0OCEKGhMeF2jLq7gsNDafB5eufnxk9MAvOAADAA0q3mF4CVlFRh94NWSMnIKSu3N6pqPnT19A+jDkG5zC3wUWAoCRXWDWcAAUQAqssfPlIdIAPJAkHbACM3gAvt4cSJ4KlKIRMuBEQFSHB+Dl4do4okUmkMlgAFwxWnJVLpWCZADcWJx9FgHFC0DJZEFOxZpPJgvA2yp+RpQjpHMZLIA5OtoFMUGq+fyKcLRRS0ZKjTK5YdwIqEuyGVzmbssUA

Expected behavior

From my point of view, I wonder if the enum values should be Global/EuOnly instead

Screenshots

None

Race condition with `client.dispose()`

Describe the bug

We have a fast running node script which hangs because of the configcat client, even though we call it's dispose function at the end.

Digging into the issue, we see that the dispose method calls clearTimeout(this.timerId), where timerId is undefined. At this time, it's still invoking refreshLogic for the first time. After refreshLogic finishes, it sets a timeout to refresh again, even after the client has been disposed. This causes the process to hang.

To reproduce

Run this script with node:

const configcat = require('configcat-node').createClient('<<SDK KEY>>)
configcat.dispose()

Expected behavior

Node process should exit. Instead it hangs.

With autopoll initial tryReadFromCache takes 5 seconds

Describe the bug

We're using a toggle immediately after loading our application and noticed a 5 second delay of our application loading. After debugging the problem I noticed that although the configcat cdn replies within 30ms, the first client.getValueAsync still takes almost 5 seconds (default config value for maxInitWaitTimeSeconds).

Our configuration: configcat-js v5.7.2 with AutoPoll:

import { createClientWithAutoPoll, createConsoleLogger } from 'configcat-js'
const logger = createConsoleLogger(LogLevel.Off)
const client = createClientWithAutoPoll('our-key', {
    logger,
    pollIntervalSeconds: 300,
    requestTimeoutMs: 5000,
  })

const getValue =  <T>(featureName: string, defaultValue: T, context: any) => client.getValueAsync(featureName, defaultValue, context)

Expected behavior

Since loading the config takes about 25ms and evaluation of most settings about 15ms I would expect a responsetime of approx 40ms.

Cause of the issue:

  • AutoPollConfigService.tryReadFromCache checks for timeStamp of the cache (line 85) and will keep waiting for a cache update until maxInitWaitTimeStamp has passed;
  • AutoPollConfigService.startRefreshWorker calls refreshLogic with forceUpdateCache = false (line 64), therefore ConfigServiceBase.refreshLogicBaseAsync will not update the cache if the configuration hasn't changed since the last visit to our website. Since cache is persisted in localstorage it will still have the old timestamp.

Suggested solution:

Code change in AutoPollConfigService.ts to force cache update on startup:

line 20:

this.startRefreshWorker(autoPollConfig.pollIntervalSeconds * 1000, true);

startRefreshWorker:

    private startRefreshWorker(delay: number, forceUpdateCache = false) {
        this.refreshLogic(forceUpdateCache).then((_) => {
            if (this.disposed) {
                return;
            }
            this.timerId = setTimeout(
                () => {
                    this.startRefreshWorker(delay);
                },
                delay);
        });
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.