open-index/open-npm huggingface dataset:
npm package: @pataflags/sdk-js
Description: - Basic use
Latest version: 0.2.0


#Basic configuration

- Basic use

        const apiKey = 'YOUR_API_KEY';
        const user = { id: 1 };
        const options = {};
        const client = PFClient.initialize(apiKey, user, options);
        client.onUpdated((features) => console.log(features));
        client.onError((error) => console.log(error));
    
        client.evaluate();
    
- Initialize with user context

        // ...
        
        const user = { id: 1, context: { country: 'eu', gender: 'male', isPremium: true }};
        
        // ...

- Add fallback when request takes more than 200 milliseconds

        // ...
        
        const options = { fallback: { feature1: true, feature4: true }, timeout: 200 };
        
        // ...

#Cache strategies

- Network Only (default)

    When network is success will return features from network
    
        // ...
        
        const options = { strategy: 'networkOnly' };
        
        // ...
        
    Combining with fallback, when network fails will return features from fallback
    
        // ...
        
        const options = { strategy: 'networkOnly', fallback: { feature1: true, feature4: true } };
        
        // ...
        
- Network First (tolerant with connection fails)

    When network is success will return features from network, if network fails will return features from last evaluation stored in cache, if cache is empty will return features from fallback
    
        // ...
        
        const options = { strategy: 'networkFirst' };
        
        // OR
        
        const options = { strategy: 'networkFirst', fallback: { feature1: true, feature4: true } };
        
        // ...
        
- Stale while revalidate (bootstrapping 0 milliseconds)

    It will return instant features from last evaluation stored in cache while try to revalidate cache from network in background, if cache is empty will return features from fallback
        
        // ...
        
        const options = { strategy: 'staleWhileRevalidate' };
        
        // OR
        
        const options = { strategy: 'staleWhileRevalidate', fallback: { feature1: true, feature4: true } };
        
        // ...
        
- Cache only (offline mode)

    It will return features from cache, if cache is empty will return features from fallback
    
        // ...
        
        const options = { strategy: 'cacheOnly' };
        
        // OR
        
        const options = { strategy: 'cacheOnly', fallback: { feature1: true, feature4: true } };
        
        // ...