@featbit/js-client-sdk 2.0.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -201
- package/README.md +162 -150
- package/dist/esm/Configuration.d.ts +35 -0
- package/dist/esm/Configuration.d.ts.map +1 -0
- package/dist/esm/Configuration.js +179 -0
- package/dist/esm/Configuration.js.map +1 -0
- package/dist/esm/Context.d.ts +23 -0
- package/dist/esm/Context.d.ts.map +1 -0
- package/dist/esm/Context.js +49 -0
- package/dist/esm/Context.js.map +1 -0
- package/dist/esm/FbClientBuilder.d.ts +90 -0
- package/dist/esm/FbClientBuilder.d.ts.map +1 -0
- package/dist/esm/FbClientBuilder.js +133 -0
- package/dist/esm/FbClientBuilder.js.map +1 -0
- package/dist/esm/FbClientCore.d.ts +56 -0
- package/dist/esm/FbClientCore.d.ts.map +1 -0
- package/dist/esm/FbClientCore.js +283 -0
- package/dist/esm/FbClientCore.js.map +1 -0
- package/dist/esm/IContextProperty.d.ts +5 -0
- package/dist/esm/IContextProperty.d.ts.map +1 -0
- package/dist/esm/IContextProperty.js +3 -0
- package/dist/esm/IContextProperty.js.map +1 -0
- package/dist/esm/IDataKind.d.ts +12 -0
- package/dist/esm/IDataKind.d.ts.map +1 -0
- package/dist/esm/IDataKind.js +3 -0
- package/dist/esm/IDataKind.js.map +1 -0
- package/dist/esm/IFbClient.d.ts +30 -0
- package/dist/esm/IFbClient.d.ts.map +1 -0
- package/dist/esm/IFbClient.js +3 -0
- package/dist/esm/IFbClient.js.map +1 -0
- package/dist/esm/IFbClientCore.d.ts +240 -0
- package/dist/esm/IFbClientCore.d.ts.map +1 -0
- package/dist/esm/IFbClientCore.js +3 -0
- package/dist/esm/IFbClientCore.js.map +1 -0
- package/dist/esm/IVersionedData.d.ts +18 -0
- package/dist/esm/IVersionedData.d.ts.map +1 -0
- package/dist/esm/IVersionedData.js +3 -0
- package/dist/esm/IVersionedData.js.map +1 -0
- package/dist/esm/bootstrap/IBootstrapProvider.d.ts +5 -0
- package/dist/esm/bootstrap/IBootstrapProvider.d.ts.map +1 -0
- package/dist/esm/bootstrap/IBootstrapProvider.js +3 -0
- package/dist/esm/bootstrap/IBootstrapProvider.js.map +1 -0
- package/dist/esm/bootstrap/JsonBootstrapProvider.d.ts +9 -0
- package/dist/esm/bootstrap/JsonBootstrapProvider.d.ts.map +1 -0
- package/dist/esm/bootstrap/JsonBootstrapProvider.js +29 -0
- package/dist/esm/bootstrap/JsonBootstrapProvider.js.map +1 -0
- package/dist/esm/bootstrap/NullBootstrapProvider.d.ts +8 -0
- package/dist/esm/bootstrap/NullBootstrapProvider.d.ts.map +1 -0
- package/dist/esm/bootstrap/NullBootstrapProvider.js +19 -0
- package/dist/esm/bootstrap/NullBootstrapProvider.js.map +1 -0
- package/dist/esm/bootstrap/index.d.ts +4 -0
- package/dist/esm/bootstrap/index.d.ts.map +1 -0
- package/dist/esm/bootstrap/index.js +20 -0
- package/dist/esm/bootstrap/index.js.map +1 -0
- package/dist/esm/constants.d.ts +3 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +6 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/data-sources/DataSourceUpdates.d.ts +17 -0
- package/dist/esm/data-sources/DataSourceUpdates.d.ts.map +1 -0
- package/dist/esm/data-sources/DataSourceUpdates.js +84 -0
- package/dist/esm/data-sources/DataSourceUpdates.js.map +1 -0
- package/dist/esm/data-sources/createStreamListeners.d.ts +19 -0
- package/dist/esm/data-sources/createStreamListeners.d.ts.map +1 -0
- package/dist/esm/data-sources/createStreamListeners.js +49 -0
- package/dist/esm/data-sources/createStreamListeners.js.map +1 -0
- package/dist/esm/data-sources/index.d.ts +3 -0
- package/dist/esm/data-sources/index.d.ts.map +1 -0
- package/dist/esm/data-sources/index.js +19 -0
- package/dist/esm/data-sources/index.js.map +1 -0
- package/dist/esm/data-sync/DataSyncMode.d.ts +5 -0
- package/dist/esm/data-sync/DataSyncMode.d.ts.map +1 -0
- package/dist/esm/data-sync/DataSyncMode.js +9 -0
- package/dist/esm/data-sync/DataSyncMode.js.map +1 -0
- package/dist/esm/data-sync/IDataSynchronizer.d.ts +15 -0
- package/dist/esm/data-sync/IDataSynchronizer.d.ts.map +1 -0
- package/dist/esm/data-sync/IDataSynchronizer.js +3 -0
- package/dist/esm/data-sync/IDataSynchronizer.js.map +1 -0
- package/dist/esm/data-sync/IRequestor.d.ts +11 -0
- package/dist/esm/data-sync/IRequestor.d.ts.map +1 -0
- package/dist/esm/data-sync/IRequestor.js +3 -0
- package/dist/esm/data-sync/IRequestor.js.map +1 -0
- package/dist/esm/data-sync/NullDataSynchronizer.d.ts +8 -0
- package/dist/esm/data-sync/NullDataSynchronizer.d.ts.map +1 -0
- package/dist/esm/data-sync/NullDataSynchronizer.js +15 -0
- package/dist/esm/data-sync/NullDataSynchronizer.js.map +1 -0
- package/dist/esm/data-sync/PollingDataSynchronizer.d.ts +23 -0
- package/dist/esm/data-sync/PollingDataSynchronizer.d.ts.map +1 -0
- package/dist/esm/data-sync/PollingDataSynchronizer.js +87 -0
- package/dist/esm/data-sync/PollingDataSynchronizer.js.map +1 -0
- package/dist/esm/data-sync/Requestor.d.ts +20 -0
- package/dist/esm/data-sync/Requestor.d.ts.map +1 -0
- package/dist/esm/data-sync/Requestor.js +56 -0
- package/dist/esm/data-sync/Requestor.js.map +1 -0
- package/dist/esm/data-sync/WebSocketDataSynchronizer.d.ts +20 -0
- package/dist/esm/data-sync/WebSocketDataSynchronizer.d.ts.map +1 -0
- package/dist/esm/data-sync/WebSocketDataSynchronizer.js +55 -0
- package/dist/esm/data-sync/WebSocketDataSynchronizer.js.map +1 -0
- package/dist/esm/data-sync/index.d.ts +10 -0
- package/dist/esm/data-sync/index.d.ts.map +1 -0
- package/dist/esm/data-sync/index.js +26 -0
- package/dist/esm/data-sync/index.js.map +1 -0
- package/dist/esm/data-sync/types.d.ts +17 -0
- package/dist/esm/data-sync/types.d.ts.map +1 -0
- package/dist/esm/data-sync/types.js +9 -0
- package/dist/esm/data-sync/types.js.map +1 -0
- package/dist/esm/data-sync/utils.d.ts +3 -0
- package/dist/esm/data-sync/utils.d.ts.map +1 -0
- package/dist/esm/data-sync/utils.js +33 -0
- package/dist/esm/data-sync/utils.js.map +1 -0
- package/dist/esm/errors.d.ts +16 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +41 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/evaluation/EvalResult.d.ts +20 -0
- package/dist/esm/evaluation/EvalResult.d.ts.map +1 -0
- package/dist/esm/evaluation/EvalResult.js +33 -0
- package/dist/esm/evaluation/EvalResult.js.map +1 -0
- package/dist/esm/evaluation/Evaluator.d.ts +15 -0
- package/dist/esm/evaluation/Evaluator.d.ts.map +1 -0
- package/dist/esm/evaluation/Evaluator.js +28 -0
- package/dist/esm/evaluation/Evaluator.js.map +1 -0
- package/dist/esm/evaluation/IEvalDetail.d.ts +21 -0
- package/dist/esm/evaluation/IEvalDetail.d.ts.map +1 -0
- package/dist/esm/evaluation/IEvalDetail.js +3 -0
- package/dist/esm/evaluation/IEvalDetail.js.map +1 -0
- package/dist/esm/evaluation/ReasonKinds.d.ts +11 -0
- package/dist/esm/evaluation/ReasonKinds.d.ts.map +1 -0
- package/dist/esm/evaluation/ReasonKinds.js +15 -0
- package/dist/esm/evaluation/ReasonKinds.js.map +1 -0
- package/dist/esm/evaluation/data/IFlag.d.ts +26 -0
- package/dist/esm/evaluation/data/IFlag.d.ts.map +1 -0
- package/dist/esm/evaluation/data/IFlag.js +12 -0
- package/dist/esm/evaluation/data/IFlag.js.map +1 -0
- package/dist/esm/evaluation/data/index.d.ts +2 -0
- package/dist/esm/evaluation/data/index.d.ts.map +1 -0
- package/dist/esm/evaluation/data/index.js +18 -0
- package/dist/esm/evaluation/data/index.js.map +1 -0
- package/dist/esm/evaluation/index.d.ts +6 -0
- package/dist/esm/evaluation/index.d.ts.map +1 -0
- package/dist/esm/evaluation/index.js +22 -0
- package/dist/esm/evaluation/index.js.map +1 -0
- package/dist/esm/events/DefaultEventProcessor.d.ts +16 -0
- package/dist/esm/events/DefaultEventProcessor.d.ts.map +1 -0
- package/dist/esm/events/DefaultEventProcessor.js +79 -0
- package/dist/esm/events/DefaultEventProcessor.js.map +1 -0
- package/dist/esm/events/DefaultEventQueue.d.ts +18 -0
- package/dist/esm/events/DefaultEventQueue.d.ts.map +1 -0
- package/dist/esm/events/DefaultEventQueue.js +42 -0
- package/dist/esm/events/DefaultEventQueue.js.map +1 -0
- package/dist/esm/events/DefaultEventSender.d.ts +10 -0
- package/dist/esm/events/DefaultEventSender.d.ts.map +1 -0
- package/dist/esm/events/DefaultEventSender.js +67 -0
- package/dist/esm/events/DefaultEventSender.js.map +1 -0
- package/dist/esm/events/DefaultEventSerializer.d.ts +6 -0
- package/dist/esm/events/DefaultEventSerializer.d.ts.map +1 -0
- package/dist/esm/events/DefaultEventSerializer.js +14 -0
- package/dist/esm/events/DefaultEventSerializer.js.map +1 -0
- package/dist/esm/events/EventDispatcher.d.ts +17 -0
- package/dist/esm/events/EventDispatcher.d.ts.map +1 -0
- package/dist/esm/events/EventDispatcher.js +127 -0
- package/dist/esm/events/EventDispatcher.js.map +1 -0
- package/dist/esm/events/EventSerializer.d.ts +5 -0
- package/dist/esm/events/EventSerializer.d.ts.map +1 -0
- package/dist/esm/events/EventSerializer.js +3 -0
- package/dist/esm/events/EventSerializer.js.map +1 -0
- package/dist/esm/events/IEventProcessor.d.ts +7 -0
- package/dist/esm/events/IEventProcessor.d.ts.map +1 -0
- package/dist/esm/events/IEventProcessor.js +3 -0
- package/dist/esm/events/IEventProcessor.js.map +1 -0
- package/dist/esm/events/IEventQueue.d.ts +11 -0
- package/dist/esm/events/IEventQueue.d.ts.map +1 -0
- package/dist/esm/events/IEventQueue.js +3 -0
- package/dist/esm/events/IEventQueue.js.map +1 -0
- package/dist/esm/events/IEventSender.d.ts +13 -0
- package/dist/esm/events/IEventSender.d.ts.map +1 -0
- package/dist/esm/events/IEventSender.js +10 -0
- package/dist/esm/events/IEventSender.js.map +1 -0
- package/dist/esm/events/NullEventProcessor.d.ts +8 -0
- package/dist/esm/events/NullEventProcessor.d.ts.map +1 -0
- package/dist/esm/events/NullEventProcessor.js +16 -0
- package/dist/esm/events/NullEventProcessor.js.map +1 -0
- package/dist/esm/events/event.d.ts +44 -0
- package/dist/esm/events/event.d.ts.map +1 -0
- package/dist/esm/events/event.js +115 -0
- package/dist/esm/events/event.js.map +1 -0
- package/dist/esm/events/index.d.ts +12 -0
- package/dist/esm/events/index.d.ts.map +1 -0
- package/dist/esm/events/index.js +28 -0
- package/dist/esm/events/index.js.map +1 -0
- package/dist/esm/index.d.ts +20 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +36 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/integrations/TestLogger.d.ts +10 -0
- package/dist/esm/integrations/TestLogger.d.ts.map +1 -0
- package/dist/esm/integrations/TestLogger.js +25 -0
- package/dist/esm/integrations/TestLogger.js.map +1 -0
- package/dist/esm/integrations/index.d.ts +3 -0
- package/dist/esm/integrations/index.d.ts.map +1 -0
- package/dist/esm/integrations/index.js +21 -0
- package/dist/esm/integrations/index.js.map +1 -0
- package/dist/esm/integrations/test_data/FlagBuilder.d.ts +19 -0
- package/dist/esm/integrations/test_data/FlagBuilder.d.ts.map +1 -0
- package/dist/esm/integrations/test_data/FlagBuilder.js +56 -0
- package/dist/esm/integrations/test_data/FlagBuilder.js.map +1 -0
- package/dist/esm/integrations/test_data/TestData.d.ts +18 -0
- package/dist/esm/integrations/test_data/TestData.d.ts.map +1 -0
- package/dist/esm/integrations/test_data/TestData.js +38 -0
- package/dist/esm/integrations/test_data/TestData.js.map +1 -0
- package/dist/esm/integrations/test_data/TestDataSynchronizer.d.ts +21 -0
- package/dist/esm/integrations/test_data/TestDataSynchronizer.d.ts.map +1 -0
- package/dist/esm/integrations/test_data/TestDataSynchronizer.js +50 -0
- package/dist/esm/integrations/test_data/TestDataSynchronizer.js.map +1 -0
- package/dist/esm/integrations/test_data/index.d.ts +5 -0
- package/dist/esm/integrations/test_data/index.d.ts.map +1 -0
- package/dist/esm/integrations/test_data/index.js +13 -0
- package/dist/esm/integrations/test_data/index.js.map +1 -0
- package/dist/esm/logging/BasicLogger.d.ts +34 -0
- package/dist/esm/logging/BasicLogger.d.ts.map +1 -0
- package/dist/esm/logging/BasicLogger.js +101 -0
- package/dist/esm/logging/BasicLogger.js.map +1 -0
- package/dist/esm/logging/IBasicLoggerOptions.d.ts +43 -0
- package/dist/esm/logging/IBasicLoggerOptions.d.ts.map +1 -0
- package/dist/esm/logging/IBasicLoggerOptions.js +3 -0
- package/dist/esm/logging/IBasicLoggerOptions.js.map +1 -0
- package/dist/esm/logging/ILogger.d.ts +47 -0
- package/dist/esm/logging/ILogger.d.ts.map +1 -0
- package/dist/esm/logging/ILogger.js +3 -0
- package/dist/esm/logging/ILogger.js.map +1 -0
- package/dist/esm/logging/LogLevel.d.ts +10 -0
- package/dist/esm/logging/LogLevel.d.ts.map +1 -0
- package/dist/esm/logging/LogLevel.js +3 -0
- package/dist/esm/logging/LogLevel.js.map +1 -0
- package/dist/esm/logging/SafeLogger.d.ts +28 -0
- package/dist/esm/logging/SafeLogger.d.ts.map +1 -0
- package/dist/esm/logging/SafeLogger.js +63 -0
- package/dist/esm/logging/SafeLogger.js.map +1 -0
- package/dist/esm/logging/format.d.ts +12 -0
- package/dist/esm/logging/format.d.ts.map +1 -0
- package/dist/esm/logging/format.js +156 -0
- package/dist/esm/logging/format.js.map +1 -0
- package/dist/esm/logging/index.d.ts +7 -0
- package/dist/esm/logging/index.d.ts.map +1 -0
- package/dist/esm/logging/index.js +23 -0
- package/dist/esm/logging/index.js.map +1 -0
- package/dist/esm/options/ClientContext.d.ts +28 -0
- package/dist/esm/options/ClientContext.d.ts.map +1 -0
- package/dist/esm/options/ClientContext.js +21 -0
- package/dist/esm/options/ClientContext.js.map +1 -0
- package/dist/esm/options/IClientContext.d.ts +45 -0
- package/dist/esm/options/IClientContext.d.ts.map +1 -0
- package/dist/esm/options/IClientContext.js +3 -0
- package/dist/esm/options/IClientContext.js.map +1 -0
- package/dist/esm/options/IOptions.d.ts +101 -0
- package/dist/esm/options/IOptions.d.ts.map +1 -0
- package/dist/esm/options/IOptions.js +3 -0
- package/dist/esm/options/IOptions.js.map +1 -0
- package/dist/esm/options/IUser.d.ts +7 -0
- package/dist/esm/options/IUser.d.ts.map +1 -0
- package/dist/esm/options/IUser.js +3 -0
- package/dist/esm/options/IUser.js.map +1 -0
- package/dist/esm/options/IValidatedOptions.d.ts +27 -0
- package/dist/esm/options/IValidatedOptions.d.ts.map +1 -0
- package/dist/esm/options/IValidatedOptions.js +3 -0
- package/dist/esm/options/IValidatedOptions.js.map +1 -0
- package/dist/esm/options/OptionMessages.d.ts +14 -0
- package/dist/esm/options/OptionMessages.d.ts.map +1 -0
- package/dist/esm/options/OptionMessages.js +33 -0
- package/dist/esm/options/OptionMessages.js.map +1 -0
- package/dist/esm/options/UserBuilder.d.ts +17 -0
- package/dist/esm/options/UserBuilder.d.ts.map +1 -0
- package/dist/esm/options/UserBuilder.js +35 -0
- package/dist/esm/options/UserBuilder.js.map +1 -0
- package/dist/esm/options/Validators.d.ts +111 -0
- package/dist/esm/options/Validators.d.ts.map +1 -0
- package/dist/esm/options/Validators.js +247 -0
- package/dist/esm/options/Validators.js.map +1 -0
- package/dist/esm/options/index.d.ts +9 -0
- package/dist/esm/options/index.d.ts.map +1 -0
- package/dist/esm/options/index.js +25 -0
- package/dist/esm/options/index.js.map +1 -0
- package/dist/esm/platform/IInfo.d.ts +73 -0
- package/dist/esm/platform/IInfo.d.ts.map +1 -0
- package/dist/esm/platform/IInfo.js +3 -0
- package/dist/esm/platform/IInfo.js.map +1 -0
- package/dist/esm/platform/IPlatform.d.ts +19 -0
- package/dist/esm/platform/IPlatform.d.ts.map +1 -0
- package/dist/esm/platform/IPlatform.js +3 -0
- package/dist/esm/platform/IPlatform.js.map +1 -0
- package/dist/esm/platform/IStore.d.ts +110 -0
- package/dist/esm/platform/IStore.d.ts.map +1 -0
- package/dist/esm/platform/IStore.js +3 -0
- package/dist/esm/platform/IStore.js.map +1 -0
- package/dist/esm/platform/IWebSocket.d.ts +21 -0
- package/dist/esm/platform/IWebSocket.d.ts.map +1 -0
- package/dist/esm/platform/IWebSocket.js +3 -0
- package/dist/esm/platform/IWebSocket.js.map +1 -0
- package/dist/esm/platform/browser/BrowserInfo.d.ts +7 -0
- package/dist/esm/platform/browser/BrowserInfo.d.ts.map +1 -0
- package/dist/esm/platform/browser/BrowserInfo.js +24 -0
- package/dist/esm/platform/browser/BrowserInfo.js.map +1 -0
- package/dist/esm/platform/browser/BrowserPlatform.d.ts +12 -0
- package/dist/esm/platform/browser/BrowserPlatform.d.ts.map +1 -0
- package/dist/esm/platform/browser/BrowserPlatform.js +17 -0
- package/dist/esm/platform/browser/BrowserPlatform.js.map +1 -0
- package/dist/esm/platform/browser/BrowserRequests.d.ts +5 -0
- package/dist/esm/platform/browser/BrowserRequests.d.ts.map +1 -0
- package/dist/esm/platform/browser/BrowserRequests.js +9 -0
- package/dist/esm/platform/browser/BrowserRequests.js.map +1 -0
- package/dist/esm/platform/browser/BrowserWebSocket.d.ts +38 -0
- package/dist/esm/platform/browser/BrowserWebSocket.d.ts.map +1 -0
- package/dist/esm/platform/browser/BrowserWebSocket.js +129 -0
- package/dist/esm/platform/browser/BrowserWebSocket.js.map +1 -0
- package/dist/esm/platform/browser/FbClient.d.ts +30 -0
- package/dist/esm/platform/browser/FbClient.d.ts.map +1 -0
- package/dist/esm/platform/browser/FbClient.js +47 -0
- package/dist/esm/platform/browser/FbClient.js.map +1 -0
- package/dist/esm/platform/browser/LocalStorageStore.d.ts +26 -0
- package/dist/esm/platform/browser/LocalStorageStore.d.ts.map +1 -0
- package/dist/esm/platform/browser/LocalStorageStore.js +122 -0
- package/dist/esm/platform/browser/LocalStorageStore.js.map +1 -0
- package/dist/esm/platform/index.d.ts +5 -0
- package/dist/esm/platform/index.d.ts.map +1 -0
- package/dist/esm/platform/index.js +21 -0
- package/dist/esm/platform/index.js.map +1 -0
- package/dist/esm/platform/requests.d.ts +64 -0
- package/dist/esm/platform/requests.d.ts.map +1 -0
- package/dist/esm/platform/requests.js +7 -0
- package/dist/esm/platform/requests.js.map +1 -0
- package/dist/esm/store/DataKinds.d.ts +5 -0
- package/dist/esm/store/DataKinds.d.ts.map +1 -0
- package/dist/esm/store/DataKinds.js +9 -0
- package/dist/esm/store/DataKinds.js.map +1 -0
- package/dist/esm/store/IDataSourceUpdates.d.ts +48 -0
- package/dist/esm/store/IDataSourceUpdates.d.ts.map +1 -0
- package/dist/esm/store/IDataSourceUpdates.js +3 -0
- package/dist/esm/store/IDataSourceUpdates.js.map +1 -0
- package/dist/esm/store/InMemoryStore.d.ts +24 -0
- package/dist/esm/store/InMemoryStore.d.ts.map +1 -0
- package/dist/esm/store/InMemoryStore.js +96 -0
- package/dist/esm/store/InMemoryStore.js.map +1 -0
- package/dist/esm/store/index.d.ts +6 -0
- package/dist/esm/store/index.d.ts.map +1 -0
- package/dist/esm/store/index.js +22 -0
- package/dist/esm/store/index.js.map +1 -0
- package/dist/esm/store/serialization.d.ts +23 -0
- package/dist/esm/store/serialization.d.ts.map +1 -0
- package/dist/esm/store/serialization.js +37 -0
- package/dist/esm/store/serialization.js.map +1 -0
- package/dist/esm/store/store.d.ts +30 -0
- package/dist/esm/store/store.d.ts.map +1 -0
- package/dist/esm/store/store.js +6 -0
- package/dist/esm/store/store.js.map +1 -0
- package/dist/esm/utils/Emits.d.ts +30 -0
- package/dist/esm/utils/Emits.d.ts.map +1 -0
- package/dist/esm/utils/Emits.js +64 -0
- package/dist/esm/utils/Emits.js.map +1 -0
- package/dist/esm/utils/EventEmitter.d.ts +22 -0
- package/dist/esm/utils/EventEmitter.d.ts.map +1 -0
- package/dist/esm/utils/EventEmitter.js +108 -0
- package/dist/esm/utils/EventEmitter.js.map +1 -0
- package/dist/esm/utils/IEventEmitter.d.ts +16 -0
- package/dist/esm/utils/IEventEmitter.d.ts.map +1 -0
- package/dist/esm/utils/IEventEmitter.js +3 -0
- package/dist/esm/utils/IEventEmitter.js.map +1 -0
- package/dist/esm/utils/Regex.d.ts +7 -0
- package/dist/esm/utils/Regex.d.ts.map +1 -0
- package/dist/esm/utils/Regex.js +22 -0
- package/dist/esm/utils/Regex.js.map +1 -0
- package/dist/esm/utils/ValueConverters.d.ts +13 -0
- package/dist/esm/utils/ValueConverters.d.ts.map +1 -0
- package/dist/esm/utils/ValueConverters.js +46 -0
- package/dist/esm/utils/ValueConverters.js.map +1 -0
- package/dist/esm/utils/VoidFunction.d.ts +2 -0
- package/dist/esm/utils/VoidFunction.d.ts.map +1 -0
- package/dist/esm/utils/VoidFunction.js +3 -0
- package/dist/esm/utils/VoidFunction.js.map +1 -0
- package/dist/esm/utils/canonicalizeUri.d.ts +2 -0
- package/dist/esm/utils/canonicalizeUri.d.ts.map +1 -0
- package/dist/esm/utils/canonicalizeUri.js +9 -0
- package/dist/esm/utils/canonicalizeUri.js.map +1 -0
- package/dist/esm/utils/http.d.ts +12 -0
- package/dist/esm/utils/http.d.ts.map +1 -0
- package/dist/esm/utils/http.js +26 -0
- package/dist/esm/utils/http.js.map +1 -0
- package/dist/esm/utils/index.d.ts +5 -0
- package/dist/esm/utils/index.d.ts.map +1 -0
- package/dist/esm/utils/index.js +21 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/isNullOrUndefined.d.ts +2 -0
- package/dist/esm/utils/isNullOrUndefined.d.ts.map +1 -0
- package/dist/esm/utils/isNullOrUndefined.js +8 -0
- package/dist/esm/utils/isNullOrUndefined.js.map +1 -0
- package/dist/esm/utils/serializeUser.d.ts +3 -0
- package/dist/esm/utils/serializeUser.d.ts.map +1 -0
- package/dist/esm/utils/serializeUser.js +24 -0
- package/dist/esm/utils/serializeUser.js.map +1 -0
- package/dist/esm/utils/sleep.d.ts +3 -0
- package/dist/esm/utils/sleep.d.ts.map +1 -0
- package/dist/esm/utils/sleep.js +18 -0
- package/dist/esm/utils/sleep.js.map +1 -0
- package/dist/esm/version.d.ts +3 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +6 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/umd/featbit-js-client-sdk-3.0.0.js +2 -0
- package/dist/umd/featbit-js-client-sdk-3.0.0.js.map +1 -0
- package/dist/umd/featbit-js-client-sdk.js +2 -0
- package/dist/umd/featbit-js-client-sdk.js.map +1 -0
- package/package.json +22 -24
- package/src/Configuration.ts +234 -0
- package/src/Context.ts +62 -0
- package/src/FbClientBuilder.ts +161 -0
- package/src/FbClientCore.ts +389 -0
- package/src/IContextProperty.ts +4 -0
- package/src/IDataKind.ts +11 -0
- package/src/IFbClient.ts +30 -0
- package/src/IFbClientCore.ts +291 -0
- package/src/IVersionedData.ts +18 -0
- package/src/bootstrap/IBootstrapProvider.ts +5 -0
- package/src/bootstrap/JsonBootstrapProvider.ts +35 -0
- package/src/bootstrap/NullBootstrapProvider.ts +21 -0
- package/src/bootstrap/index.ts +3 -0
- package/src/constants.ts +2 -6
- package/src/data-sources/DataSourceUpdates.ts +93 -0
- package/src/data-sources/createStreamListeners.ts +66 -0
- package/src/data-sources/index.ts +2 -0
- package/src/data-sync/DataSyncMode.ts +4 -0
- package/src/data-sync/IDataSynchronizer.ts +15 -0
- package/src/data-sync/IRequestor.ts +10 -0
- package/src/data-sync/NullDataSynchronizer.ts +15 -0
- package/src/data-sync/PollingDataSynchronizer.ts +111 -0
- package/src/data-sync/Requestor.ts +61 -0
- package/src/data-sync/WebSocketDataSynchronizer.ts +74 -0
- package/src/data-sync/index.ts +9 -0
- package/src/data-sync/types.ts +20 -0
- package/src/data-sync/utils.ts +32 -0
- package/src/errors.ts +41 -0
- package/src/evaluation/EvalResult.ts +36 -0
- package/src/evaluation/Evaluator.ts +27 -0
- package/src/evaluation/IEvalDetail.ts +24 -0
- package/src/evaluation/ReasonKinds.ts +10 -0
- package/src/evaluation/data/IFlag.ts +29 -0
- package/src/evaluation/data/index.ts +1 -0
- package/src/evaluation/index.ts +5 -0
- package/src/events/DefaultEventProcessor.ts +84 -0
- package/src/events/DefaultEventQueue.ts +50 -0
- package/src/events/DefaultEventSender.ts +75 -0
- package/src/events/DefaultEventSerializer.ts +12 -0
- package/src/events/EventDispatcher.ts +128 -0
- package/src/events/EventSerializer.ts +5 -0
- package/src/events/IEventProcessor.ts +9 -0
- package/src/events/IEventQueue.ts +17 -0
- package/src/events/IEventSender.ts +14 -0
- package/src/events/NullEventProcessor.ts +16 -0
- package/src/events/event.ts +130 -0
- package/src/events/index.ts +11 -0
- package/src/index.ts +19 -4
- package/src/integrations/TestLogger.ts +25 -0
- package/src/integrations/index.ts +2 -0
- package/src/integrations/test_data/FlagBuilder.ts +60 -0
- package/src/integrations/test_data/TestData.ts +58 -0
- package/src/integrations/test_data/TestDataSynchronizer.ts +50 -0
- package/src/integrations/test_data/index.ts +5 -0
- package/src/logging/BasicLogger.ts +108 -0
- package/src/logging/IBasicLoggerOptions.ts +46 -0
- package/src/logging/ILogger.ts +49 -0
- package/src/logging/LogLevel.ts +9 -0
- package/src/logging/SafeLogger.ts +70 -0
- package/src/logging/format.ts +154 -0
- package/src/logging/index.ts +6 -0
- package/src/options/ClientContext.ts +40 -0
- package/src/options/IClientContext.ts +54 -0
- package/src/options/IOptions.ts +124 -0
- package/src/options/IUser.ts +7 -0
- package/src/options/IValidatedOptions.ts +30 -0
- package/src/options/OptionMessages.ts +36 -0
- package/src/options/UserBuilder.ts +36 -0
- package/src/options/Validators.ts +301 -0
- package/src/options/index.ts +8 -0
- package/src/platform/IInfo.ts +82 -0
- package/src/platform/IPlatform.ts +21 -0
- package/src/platform/IStore.ts +119 -0
- package/src/platform/IWebSocket.ts +23 -0
- package/src/platform/browser/BrowserInfo.ts +25 -0
- package/src/platform/browser/BrowserPlatform.ts +20 -0
- package/src/platform/browser/BrowserRequests.ts +7 -0
- package/src/platform/browser/BrowserWebSocket.ts +143 -0
- package/src/platform/browser/FbClient.ts +59 -0
- package/src/platform/browser/LocalStorageStore.ts +153 -0
- package/src/platform/index.ts +4 -0
- package/src/platform/requests.ts +77 -0
- package/src/store/DataKinds.ts +7 -0
- package/src/store/IDataSourceUpdates.ts +49 -0
- package/src/store/InMemoryStore.ts +115 -0
- package/src/store/index.ts +5 -0
- package/src/store/serialization.ts +52 -0
- package/src/store/store.ts +38 -0
- package/src/utils/Emits.ts +76 -0
- package/src/utils/EventEmitter.ts +129 -0
- package/src/utils/IEventEmitter.ts +15 -0
- package/src/utils/Regex.ts +22 -0
- package/src/utils/ValueConverters.ts +56 -0
- package/src/utils/VoidFunction.ts +1 -0
- package/src/utils/canonicalizeUri.ts +4 -0
- package/src/utils/http.ts +40 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/isNullOrUndefined.ts +3 -0
- package/src/utils/serializeUser.ts +28 -0
- package/src/utils/sleep.ts +6 -0
- package/src/version.ts +1 -0
- package/esm/constants.d.ts +0 -6
- package/esm/constants.js +0 -7
- package/esm/constants.js.map +0 -1
- package/esm/events.d.ts +0 -14
- package/esm/events.js +0 -27
- package/esm/events.js.map +0 -1
- package/esm/featbit.d.ts +0 -34
- package/esm/featbit.js +0 -382
- package/esm/featbit.js.map +0 -1
- package/esm/index.d.ts +0 -4
- package/esm/index.js +0 -5
- package/esm/index.js.map +0 -1
- package/esm/logger.d.ts +0 -4
- package/esm/logger.js +0 -20
- package/esm/logger.js.map +0 -1
- package/esm/network.service.d.ts +0 -27
- package/esm/network.service.js +0 -288
- package/esm/network.service.js.map +0 -1
- package/esm/optionMessages.d.ts +0 -5
- package/esm/optionMessages.js +0 -16
- package/esm/optionMessages.js.map +0 -1
- package/esm/queue.d.ts +0 -8
- package/esm/queue.js +0 -35
- package/esm/queue.js.map +0 -1
- package/esm/store.d.ts +0 -20
- package/esm/store.js +0 -143
- package/esm/store.js.map +0 -1
- package/esm/throttleutil.d.ts +0 -9
- package/esm/throttleutil.js +0 -133
- package/esm/throttleutil.js.map +0 -1
- package/esm/types.d.ts +0 -94
- package/esm/types.js +0 -24
- package/esm/types.js.map +0 -1
- package/esm/umd.d.ts +0 -2
- package/esm/utils.d.ts +0 -11
- package/esm/utils.js +0 -142
- package/esm/utils.js.map +0 -1
- package/src/events.ts +0 -29
- package/src/featbit.ts +0 -343
- package/src/logger.ts +0 -13
- package/src/network.service.ts +0 -223
- package/src/optionMessages.ts +0 -13
- package/src/queue.ts +0 -23
- package/src/store.ts +0 -169
- package/src/throttleutil.ts +0 -72
- package/src/types.ts +0 -113
- package/src/umd.ts +0 -15
- package/src/utils.ts +0 -173
- package/umd/featbit-js-client-sdk-2.0.1.js +0 -2
- package/umd/featbit-js-client-sdk-2.0.1.js.map +0 -1
- package/umd/featbit-js-client-sdk.js +0 -2
- package/umd/featbit-js-client-sdk.js.map +0 -1
package/src/store.ts
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import {featureFlagEvaluatedTopic} from "./constants";
|
|
2
|
-
import {eventHub} from "./events";
|
|
3
|
-
import {logger} from "./logger";
|
|
4
|
-
import {
|
|
5
|
-
FeatureFlagUpdateOperation, FeatureFlagValue,
|
|
6
|
-
IDataStore,
|
|
7
|
-
IFeatureFlag,
|
|
8
|
-
IFeatureFlagChange,
|
|
9
|
-
InsightType
|
|
10
|
-
} from "./types";
|
|
11
|
-
import {parseVariation} from "./utils";
|
|
12
|
-
|
|
13
|
-
const DataStoreStorageKey = 'fb-datastore';
|
|
14
|
-
|
|
15
|
-
class Store {
|
|
16
|
-
private _userId: string | null = null;
|
|
17
|
-
|
|
18
|
-
private _store: IDataStore = {
|
|
19
|
-
featureFlags: {} as { [key: string]: IFeatureFlag }
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
constructor() { }
|
|
23
|
-
|
|
24
|
-
set userId(id: string) {
|
|
25
|
-
this._userId = id;
|
|
26
|
-
this._loadFromStorage();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getFeatureFlag(key: string): IFeatureFlag {
|
|
30
|
-
return this._store.featureFlags[key];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
getVariation(key: string): FeatureFlagValue {
|
|
34
|
-
const featureFlag = this._store.featureFlags[key];
|
|
35
|
-
|
|
36
|
-
if (!featureFlag) {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
eventHub.emit(featureFlagEvaluatedTopic, {
|
|
41
|
-
insightType: InsightType.featureFlagUsage,
|
|
42
|
-
id: featureFlag.id,
|
|
43
|
-
timestamp: Date.now(),
|
|
44
|
-
sendToExperiment: featureFlag.sendToExperiment,
|
|
45
|
-
variation: featureFlag.variationOptions.find(o => o.value === featureFlag.variation)
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const { variationType, variation } = featureFlag;
|
|
49
|
-
|
|
50
|
-
return parseVariation(variationType, variation);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
setFullData(data: IDataStore) {
|
|
54
|
-
this._store = {
|
|
55
|
-
featureFlags: {} as { [key: string]: IFeatureFlag }
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
this._dumpToStorage(this._store);
|
|
59
|
-
this.updateBulkFromRemote(data);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
getFeatureFlags(): { [key: string]: IFeatureFlag } {
|
|
63
|
-
return this._store.featureFlags;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
updateStorageBulk(data: IDataStore, storageKey: string, onlyInsertNewElement: boolean) {
|
|
67
|
-
let dataStoreStr = localStorage.getItem(storageKey);
|
|
68
|
-
let store: IDataStore | null = null;
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
if (dataStoreStr && dataStoreStr.trim().length > 0) {
|
|
72
|
-
store = JSON.parse(dataStoreStr);
|
|
73
|
-
}
|
|
74
|
-
} catch (err) {
|
|
75
|
-
logger.logDebug(`error while loading local data store: ${storageKey}` + err);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (!!store) {
|
|
79
|
-
const { featureFlags } = data;
|
|
80
|
-
|
|
81
|
-
Object.keys(featureFlags).forEach(id => {
|
|
82
|
-
const remoteFf = featureFlags[id];
|
|
83
|
-
const localFf = store!.featureFlags[id];
|
|
84
|
-
|
|
85
|
-
const predicate = !localFf || !onlyInsertNewElement;
|
|
86
|
-
if (predicate) {
|
|
87
|
-
store!.featureFlags[remoteFf.id] = Object.assign({}, remoteFf);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
this._dumpToStorage(store, storageKey);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
updateBulkFromRemote(data: IDataStore) {
|
|
96
|
-
const storageKey = `${DataStoreStorageKey}-${this._userId}`;
|
|
97
|
-
|
|
98
|
-
this.updateStorageBulk(data, storageKey, false);
|
|
99
|
-
|
|
100
|
-
this._loadFromStorage();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private _emitUpdateEvents(updatedFeatureFlags: any[]): void {
|
|
104
|
-
if (updatedFeatureFlags.length > 0) {
|
|
105
|
-
updatedFeatureFlags.forEach(({ id, operation, data }) => eventHub.emit(`ff_${operation}:${data.id}`, data));
|
|
106
|
-
eventHub.emit(`ff_${FeatureFlagUpdateOperation.update}`, updatedFeatureFlags.map(item => item.data));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
private _dumpToStorage(store?: IDataStore, localStorageKey?: string): void {
|
|
111
|
-
if (store) {
|
|
112
|
-
const storageKey = localStorageKey || `${DataStoreStorageKey}-${this._userId}`;
|
|
113
|
-
localStorage.setItem(storageKey, JSON.stringify(store));
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
const storageKey = `${DataStoreStorageKey}-${this._userId}`;
|
|
117
|
-
localStorage.setItem(storageKey, JSON.stringify(this._store));
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private _loadFromStorage(): void {
|
|
121
|
-
try {
|
|
122
|
-
const storageKey = `${DataStoreStorageKey}-${this._userId}`;
|
|
123
|
-
let dataStoreStr = localStorage.getItem(storageKey);
|
|
124
|
-
|
|
125
|
-
let shouldDumpToStorage = false;
|
|
126
|
-
|
|
127
|
-
if (dataStoreStr && dataStoreStr.trim().length > 0) {
|
|
128
|
-
// compare _store and dataStoreStr data and send notification if different
|
|
129
|
-
const storageData: IDataStore = JSON.parse(dataStoreStr);
|
|
130
|
-
|
|
131
|
-
const updatedFeatureFlags = Object.keys(storageData.featureFlags).filter(key => {
|
|
132
|
-
const storageFf = storageData.featureFlags[key];
|
|
133
|
-
const ff = this._store.featureFlags[key];
|
|
134
|
-
return !ff || storageFf.variation !== ff.variation || storageFf.variationType !== ff.variationType;
|
|
135
|
-
}).map(key => {
|
|
136
|
-
const storageFf = storageData.featureFlags[key];
|
|
137
|
-
const ff = this._store.featureFlags[key];
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
id: key,
|
|
141
|
-
operation: FeatureFlagUpdateOperation.update,
|
|
142
|
-
sendToExperiment: storageFf.sendToExperiment,
|
|
143
|
-
data: {
|
|
144
|
-
id: key,
|
|
145
|
-
oldValue: ff ? parseVariation(ff.variationType, ff.variation): undefined,
|
|
146
|
-
newValue: parseVariation(storageFf.variationType, storageFf.variation)
|
|
147
|
-
} as IFeatureFlagChange
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
this._store = storageData;
|
|
152
|
-
this._emitUpdateEvents(updatedFeatureFlags);
|
|
153
|
-
} else {
|
|
154
|
-
this._store = {
|
|
155
|
-
featureFlags: {} as { [key: string]: IFeatureFlag }
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (shouldDumpToStorage) {
|
|
160
|
-
this._dumpToStorage();
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
} catch (err) {
|
|
164
|
-
logger.logDebug('error while loading local data store: ' + err);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export default new Store();
|
package/src/throttleutil.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { uuid } from "./utils";
|
|
2
|
-
|
|
3
|
-
const API_CALL_RESULTS : {[key: string]: string} = {};
|
|
4
|
-
const FOOT_PRINTS: string[] = [];
|
|
5
|
-
let _throttleWait: number = 0; // send immediately
|
|
6
|
-
|
|
7
|
-
class ThrottleUtil {
|
|
8
|
-
private _key: string;
|
|
9
|
-
|
|
10
|
-
constructor(){
|
|
11
|
-
this._key = uuid();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
setKey(key: string) {
|
|
15
|
-
this._key = key || this._key;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
throttle(fn: Function, ms: number) {
|
|
19
|
-
let timer:any = 0
|
|
20
|
-
return function(...args) {
|
|
21
|
-
clearTimeout(timer)
|
|
22
|
-
timer = setTimeout(fn.bind(null, ...args), ms || 0)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
throttleAsync (callback: any): any {
|
|
27
|
-
let waiting = false;
|
|
28
|
-
|
|
29
|
-
let getFootprint = (args: any): string => {
|
|
30
|
-
const params = args.map(arg => {
|
|
31
|
-
if (
|
|
32
|
-
typeof arg === 'object' &&
|
|
33
|
-
typeof arg !== "function" &&
|
|
34
|
-
arg !== null
|
|
35
|
-
) {
|
|
36
|
-
if (Array.isArray(arg)) {
|
|
37
|
-
return arg.map(a => ({...a, ...{timestamp: null}}))
|
|
38
|
-
} else {
|
|
39
|
-
return {...arg, ...{timestamp: null}};
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return arg;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
return this._key + JSON.stringify(params);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
return async function (...args) {
|
|
50
|
-
const footprint = getFootprint(args);
|
|
51
|
-
const idx = FOOT_PRINTS.findIndex(f => f === footprint);
|
|
52
|
-
if (!waiting || idx === -1) {
|
|
53
|
-
waiting = true;
|
|
54
|
-
if (idx === -1) {
|
|
55
|
-
FOOT_PRINTS.push(footprint);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
API_CALL_RESULTS[footprint] = await callback.apply(null, args);
|
|
59
|
-
|
|
60
|
-
setTimeout(function () {
|
|
61
|
-
waiting = false;
|
|
62
|
-
}, _throttleWait);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return API_CALL_RESULTS[footprint];
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export default new ThrottleUtil();
|
|
71
|
-
|
|
72
|
-
|
package/src/types.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
export type FeatureFlagValue = any;
|
|
2
|
-
|
|
3
|
-
export interface IFeatureFlagSet {
|
|
4
|
-
[key: string]: FeatureFlagValue;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface IFeatureFlagChange {
|
|
8
|
-
id: string,
|
|
9
|
-
oldValue: FeatureFlagValue,
|
|
10
|
-
newValue: FeatureFlagValue
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface IOption {
|
|
14
|
-
secret: string,
|
|
15
|
-
anonymous?: boolean,
|
|
16
|
-
bootstrap?: IFeatureFlag[],
|
|
17
|
-
streamingUri?: string,
|
|
18
|
-
eventsUri?: string,
|
|
19
|
-
|
|
20
|
-
// deprecated, this option will be removed in the future, please use streamingUri and eventsUri instead
|
|
21
|
-
api?: string,
|
|
22
|
-
|
|
23
|
-
appType?: string,
|
|
24
|
-
user?: IUser,
|
|
25
|
-
enableDataSync?: boolean
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface IUser {
|
|
29
|
-
name: string,
|
|
30
|
-
keyId: string,
|
|
31
|
-
customizedProperties?: ICustomizedProperty[]
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface ICustomizedProperty {
|
|
35
|
-
name: string,
|
|
36
|
-
value: string | number | boolean
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface IVariationOption {
|
|
40
|
-
id: number,
|
|
41
|
-
value: FeatureFlagValue
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface IFeatureFlagVariation {
|
|
45
|
-
id?: string,
|
|
46
|
-
sendToExperiment?: boolean
|
|
47
|
-
timestamp?: number,
|
|
48
|
-
variation?: {
|
|
49
|
-
id: number,
|
|
50
|
-
value: FeatureFlagValue,
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface IFeatureFlagVariationBuffer {
|
|
55
|
-
id: string,
|
|
56
|
-
timestamp: number,
|
|
57
|
-
variationValue: FeatureFlagValue
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export enum InsightType {
|
|
61
|
-
featureFlagUsage = 1,
|
|
62
|
-
customEvent = 2,
|
|
63
|
-
pageView = 3,
|
|
64
|
-
click = 4
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export enum VariationDataType {
|
|
68
|
-
string = 'string',
|
|
69
|
-
boolean = 'boolean',
|
|
70
|
-
number = 'number',
|
|
71
|
-
json = 'json',
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface IInsight extends IFeatureFlagVariation, ICustomEvent {
|
|
75
|
-
insightType: InsightType
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export interface IFeatureFlagBase {
|
|
79
|
-
id: string, // the keyname
|
|
80
|
-
variation: FeatureFlagValue,
|
|
81
|
-
variationType: VariationDataType
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export interface IFeatureFlag extends IFeatureFlagBase{
|
|
85
|
-
sendToExperiment: boolean,
|
|
86
|
-
timestamp: number,
|
|
87
|
-
variationOptions: IVariationOption[]
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export interface IDataStore {
|
|
91
|
-
featureFlags: { [key: string]: IFeatureFlag }
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export enum StreamResponseEventType {
|
|
95
|
-
full = 'full',
|
|
96
|
-
patch = 'patch'
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export enum FeatureFlagUpdateOperation {
|
|
100
|
-
update = 'update'
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export interface IStreamResponse {
|
|
104
|
-
eventType: StreamResponseEventType,
|
|
105
|
-
userKeyId: string,
|
|
106
|
-
featureFlags: IFeatureFlag[]
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export interface ICustomEvent {
|
|
110
|
-
type?: string,
|
|
111
|
-
eventName: string,
|
|
112
|
-
numericValue?: number
|
|
113
|
-
}
|
package/src/umd.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// This file is only for umd version
|
|
2
|
-
|
|
3
|
-
const html = document.querySelector('html');
|
|
4
|
-
const waittime = 500;
|
|
5
|
-
if (html) {
|
|
6
|
-
html.style.visibility = 'hidden';
|
|
7
|
-
setTimeout(() => html.style.visibility = 'visible', waittime);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
import fbClient from './featbit';
|
|
11
|
-
import { logger } from './logger';
|
|
12
|
-
|
|
13
|
-
logger.logDebug(`version: __VERSION__`);
|
|
14
|
-
|
|
15
|
-
export { fbClient }
|
package/src/utils.ts
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import {FeatureFlagValue, IOption, IUser, VariationDataType} from "./types";
|
|
2
|
-
import {logger} from "./logger";
|
|
3
|
-
import OptionMessages from "./optionMessages";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// generate default user info
|
|
7
|
-
export function generateorGetGuid(): string {
|
|
8
|
-
let guid = localStorage.getItem("fb-guid");
|
|
9
|
-
if (guid) {
|
|
10
|
-
return guid;
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
const id = uuid();
|
|
14
|
-
localStorage.setItem("fb-guid", id);
|
|
15
|
-
return id;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function serializeUser(user: IUser | undefined): string {
|
|
20
|
-
if (!user) {
|
|
21
|
-
return '';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const builtInProperties = `${user.keyId},${user.name}`;
|
|
25
|
-
|
|
26
|
-
const customizedProperties = user.customizedProperties?.map(p => `${p.name}:${p.value}`).join(',');
|
|
27
|
-
|
|
28
|
-
return `${builtInProperties},${customizedProperties}`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function isNumeric(str: string) {
|
|
32
|
-
if (typeof str != "string") return false // we only process strings!
|
|
33
|
-
// @ts-ignore
|
|
34
|
-
return !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
|
|
35
|
-
!isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function parseVariation(type: VariationDataType, value: string): FeatureFlagValue {
|
|
39
|
-
switch (type) {
|
|
40
|
-
case VariationDataType.string:
|
|
41
|
-
return value;
|
|
42
|
-
case VariationDataType.boolean:
|
|
43
|
-
if (value === 'true') {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (value === 'false') {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
logger.log(`expected boolean value, but got ${value}`);
|
|
52
|
-
return value;
|
|
53
|
-
case VariationDataType.number:
|
|
54
|
-
if (isNumeric(value)) {
|
|
55
|
-
return +value;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
logger.log(`expected numeric value, but got ${value}`);
|
|
59
|
-
return value;
|
|
60
|
-
case VariationDataType.json:
|
|
61
|
-
try {
|
|
62
|
-
return JSON.parse(value);
|
|
63
|
-
}
|
|
64
|
-
catch (e) {
|
|
65
|
-
logger.log(`expected json value, but got ${value}`);
|
|
66
|
-
return value;
|
|
67
|
-
}
|
|
68
|
-
default:
|
|
69
|
-
logger.log(`unexpected variation type ${type} for ${value}`);
|
|
70
|
-
return value;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function uuid(): string {
|
|
75
|
-
let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
76
|
-
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
77
|
-
return v.toString(16);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
return uuid;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function validateUser(user: IUser): string | null {
|
|
84
|
-
if (!user) {
|
|
85
|
-
return OptionMessages.mandatory('user')
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const { keyId, name } = user;
|
|
89
|
-
|
|
90
|
-
if (keyId === undefined || keyId === null || keyId.trim() === '') {
|
|
91
|
-
return OptionMessages.mandatory('user.keyId');
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (name === undefined || name === null || name.trim() === '') {
|
|
95
|
-
return OptionMessages.mandatory('user.name');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export function isNullOrUndefinedOrWhiteSpace(value?: string): boolean {
|
|
102
|
-
return value === null || value === undefined || value.trim() === '';
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function validateOption(option: IOption): string | null {
|
|
106
|
-
if (option === undefined || option === null) {
|
|
107
|
-
return OptionMessages.mandatory('option')
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const { streamingUri, eventsUri, secret, anonymous, user, enableDataSync } = option;
|
|
111
|
-
|
|
112
|
-
const streamingUriMissing = isNullOrUndefinedOrWhiteSpace(streamingUri);
|
|
113
|
-
const eventsUriMissing = isNullOrUndefinedOrWhiteSpace(eventsUri);
|
|
114
|
-
|
|
115
|
-
if (enableDataSync && (streamingUriMissing || eventsUriMissing))
|
|
116
|
-
{
|
|
117
|
-
if (eventsUriMissing) {
|
|
118
|
-
return OptionMessages.partialEndpoint('eventsUri');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (streamingUriMissing) {
|
|
122
|
-
return OptionMessages.partialEndpoint('streamingUri');
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (enableDataSync && isNullOrUndefinedOrWhiteSpace(secret)) {
|
|
127
|
-
return OptionMessages.invalidParam('secret');
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// validate user
|
|
131
|
-
if (!!anonymous === false && !user) {
|
|
132
|
-
return OptionMessages.mandatory('user');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (user) {
|
|
136
|
-
return validateUser(user);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/********************** encode text begin *****************************/
|
|
143
|
-
const alphabet = {
|
|
144
|
-
"0": "Q",
|
|
145
|
-
"1": "B",
|
|
146
|
-
"2": "W",
|
|
147
|
-
"3": "S",
|
|
148
|
-
"4": "P",
|
|
149
|
-
"5": "H",
|
|
150
|
-
"6": "D",
|
|
151
|
-
"7": "X",
|
|
152
|
-
"8": "Z",
|
|
153
|
-
"9": "U",
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function encodeNumber(param: number, length: number): string {
|
|
157
|
-
var s = "000000000000" + param;
|
|
158
|
-
const numberWithLeadingZeros = s.slice(s.length - length);
|
|
159
|
-
return numberWithLeadingZeros.split('').map(n => alphabet[n]).join('');
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// generate connection token
|
|
163
|
-
export function generateConnectionToken(text: string): string {
|
|
164
|
-
text = text.replace(/=*$/, '');
|
|
165
|
-
const timestamp = Date.now();
|
|
166
|
-
const timestampCode = encodeNumber(timestamp, timestamp.toString().length);
|
|
167
|
-
// get random number less than the length of the text as the start point, and it must be greater or equal to 2
|
|
168
|
-
const start = Math.max(Math.floor(Math.random() * text.length), 2);
|
|
169
|
-
|
|
170
|
-
return `${encodeNumber(start, 3)}${encodeNumber(timestampCode.length, 2)}${text.slice(0, start)}${timestampCode}${text.slice(start)}`;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/********************** encode text end *****************************/
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var r in n)("object"==typeof exports?exports:t)[r]=n[r]}}(this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{fbClient:()=>q});var n,r,i,o,a=new(function(){function t(t){this.events=t||{}}return t.prototype.subscribe=function(t,e){var n=this;return(this.events[t]||(this.events[t]=[])).push(e),{unsubscribe:function(){return n.events[t]&&n.events[t].splice(n.events[t].indexOf(e)>>>0,1)}}},t.prototype.unsubscribe=function(t,e){this.events[t]&&this.events[t].splice(this.events[t].indexOf(e)>>>0,1)},t.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];(this.events[t]||[]).forEach((function(t){return t.apply(void 0,e)}))},t}()),u={logDebug:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e]},log:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];console.log.apply(console,t)}},s="insights.flush",c="featureflag.evaluated.topic",l="featureflag.evaluated.buffer.topic",f="network.websocket.reconnect",p="fb-user";!function(t){t[t.featureFlagUsage=1]="featureFlagUsage",t[t.customEvent=2]="customEvent",t[t.pageView=3]="pageView",t[t.click=4]="click"}(n||(n={})),function(t){t.string="string",t.boolean="boolean",t.number="number",t.json="json"}(r||(r={})),function(t){t.full="full",t.patch="patch"}(i||(i={})),function(t){t.update="update"}(o||(o={}));const d=function(){function t(){}return t.partialEndpoint=function(t){return"You have set custom uris without specifying the ".concat(t," URI; connections may not work properly")},t.invalidParam=function(t){return"The ".concat(t," option is not passed in or its value is invalid")},t.mandatory=function(t){return"".concat(t," is mandatory")},t}();function h(t){var e;if(!t)return"";var n="".concat(t.keyId,",").concat(t.name),r=null===(e=t.customizedProperties)||void 0===e?void 0:e.map((function(t){return"".concat(t.name,":").concat(t.value)})).join(",");return"".concat(n,",").concat(r)}function v(t,e){switch(t){case r.string:return e;case r.boolean:return"true"===e||"false"!==e&&(u.log("expected boolean value, but got ".concat(e)),e);case r.number:return"string"!=typeof(n=e)||isNaN(n)||isNaN(parseFloat(n))?(u.log("expected numeric value, but got ".concat(e)),e):+e;case r.json:try{return JSON.parse(e)}catch(t){return u.log("expected json value, but got ".concat(e)),e}default:return u.log("unexpected variation type ".concat(t," for ").concat(e)),e}var n}function g(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}))}function y(t){if(!t)return d.mandatory("user");var e=t.keyId,n=t.name;return null==e||""===e.trim()?d.mandatory("user.keyId"):null==n||""===n.trim()?d.mandatory("user.name"):null}function m(t){return null==t||""===t.trim()}var b={0:"Q",1:"B",2:"W",3:"S",4:"P",5:"H",6:"D",7:"X",8:"Z",9:"U"};function w(t,e){var n="000000000000"+t;return n.slice(n.length-e).split("").map((function(t){return b[t]})).join("")}var x="fb-datastore",_=function(){function t(){this._userId=null,this._store={featureFlags:{}}}return Object.defineProperty(t.prototype,"userId",{set:function(t){this._userId=t,this._loadFromStorage()},enumerable:!1,configurable:!0}),t.prototype.getFeatureFlag=function(t){return this._store.featureFlags[t]},t.prototype.getVariation=function(t){var e=this._store.featureFlags[t];if(e)return a.emit(c,{insightType:n.featureFlagUsage,id:e.id,timestamp:Date.now(),sendToExperiment:e.sendToExperiment,variation:e.variationOptions.find((function(t){return t.value===e.variation}))}),v(e.variationType,e.variation)},t.prototype.setFullData=function(t){this._store={featureFlags:{}},this._dumpToStorage(this._store),this.updateBulkFromRemote(t)},t.prototype.getFeatureFlags=function(){return this._store.featureFlags},t.prototype.updateStorageBulk=function(t,e,n){var r=localStorage.getItem(e),i=null;try{r&&r.trim().length>0&&(i=JSON.parse(r))}catch(t){u.logDebug("error while loading local data store: ".concat(e)+t)}if(i){var o=t.featureFlags;Object.keys(o).forEach((function(t){var e=o[t];(!i.featureFlags[t]||!n)&&(i.featureFlags[e.id]=Object.assign({},e))})),this._dumpToStorage(i,e)}},t.prototype.updateBulkFromRemote=function(t){var e="".concat(x,"-").concat(this._userId);this.updateStorageBulk(t,e,!1),this._loadFromStorage()},t.prototype._emitUpdateEvents=function(t){t.length>0&&(t.forEach((function(t){t.id;var e=t.operation,n=t.data;return a.emit("ff_".concat(e,":").concat(n.id),n)})),a.emit("ff_".concat(o.update),t.map((function(t){return t.data}))))},t.prototype._dumpToStorage=function(t,e){if(t){var n=e||"".concat(x,"-").concat(this._userId);localStorage.setItem(n,JSON.stringify(t))}else{var r="".concat(x,"-").concat(this._userId);localStorage.setItem(r,JSON.stringify(this._store))}},t.prototype._loadFromStorage=function(){var t=this;try{var e="".concat(x,"-").concat(this._userId),n=localStorage.getItem(e);if(n&&n.trim().length>0){var r=JSON.parse(n),i=Object.keys(r.featureFlags).filter((function(e){var n=r.featureFlags[e],i=t._store.featureFlags[e];return!i||n.variation!==i.variation||n.variationType!==i.variationType})).map((function(e){var n=r.featureFlags[e],i=t._store.featureFlags[e];return{id:e,operation:o.update,sendToExperiment:n.sendToExperiment,data:{id:e,oldValue:i?v(i.variationType,i.variation):void 0,newValue:v(n.variationType,n.variation)}}}));this._store=r,this._emitUpdateEvents(i)}else this._store={featureFlags:{}}}catch(t){u.logDebug("error while loading local data store: "+t)}},t}();const k=new _;var T=function(){return T=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},T.apply(this,arguments)},S={},F=[];const E=new(function(){function t(){this._key=g()}return t.prototype.setKey=function(t){this._key=t||this._key},t.prototype.throttle=function(t,e){var n=0;return function(){for(var r=[],i=0;i<arguments.length;i++)r[i]=arguments[i];clearTimeout(n),n=setTimeout(t.bind.apply(t,function(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}([null],r,!1)),e||0)}},t.prototype.throttleAsync=function(t){var e=this,n=!1;return function(){for(var r=[],i=0;i<arguments.length;i++)r[i]=arguments[i];return o=this,a=void 0,s=function(){var i,o,a,u;return function(t,e){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){a.label=u[1];break}if(6===u[0]&&a.label<i[1]){a.label=i[1],i=u;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(u);break}i[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}(this,(function(s){switch(s.label){case 0:return i=function(t){var n=t.map((function(t){return"object"==typeof t&&"function"!=typeof t&&null!==t?Array.isArray(t)?t.map((function(t){return T(T({},t),{timestamp:null})})):T(T({},t),{timestamp:null}):t}));return e._key+JSON.stringify(n)}(r),o=F.findIndex((function(t){return t===i})),n&&-1!==o?[3,2]:(n=!0,-1===o&&F.push(i),a=S,u=i,[4,t.apply(null,r)]);case 1:a[u]=s.sent(),setTimeout((function(){n=!1}),0),s.label=2;case 2:return[2,S[i]]}}))},new((u=void 0)||(u=Promise))((function(t,e){function n(t){try{i(s.next(t))}catch(t){e(t)}}function r(t){try{i(s.throw(t))}catch(t){e(t)}}function i(e){var i;e.done?t(e.value):(i=e.value,i instanceof u?i:new u((function(t){t(i)}))).then(n,r)}i((s=s.apply(o,a||[])).next())}));var o,a,u,s}},t}());var O=function(){return O=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},O.apply(this,arguments)},D=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function a(t){try{s(r.next(t))}catch(t){o(t)}}function u(t){try{s(r.throw(t))}catch(t){o(t)}}function s(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},I=function(t,e){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){a.label=u[1];break}if(6===u[0]&&a.label<i[1]){a.label=i[1],i=u;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(u);break}i[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},j=[250,500,1e3,2e3,4e3,8e3],P=new(function(){function t(){var t=this;this.retryCounter=0,this.sendInsights=E.throttleAsync((function(e){return D(t,void 0,void 0,(function(){var t,r,i=this;return I(this,(function(o){switch(o.label){case 0:if(!this.secret||!this.user||!e||0===e.length)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),t=[{user:this.__getUserInfo(),variations:e.filter((function(t){return t.insightType===n.featureFlagUsage})).map((function(t){return{featureFlagKey:t.id,sendToExperiment:t.sendToExperiment,timestamp:t.timestamp,variation:{id:t.variation.id,value:t.variation.value}}})),metrics:e.filter((function(t){return t.insightType!==n.featureFlagUsage})).map((function(t){return{route:location.pathname,timestamp:t.timestamp,numericValue:null===t.numericValue||void 0===t.numericValue?1:t.numericValue,appType:i.appType,eventName:t.eventName,type:t.type}}))}],[4,U("".concat(this.eventsUri,"/api/public/insight/track"),t,{Authorization:this.secret})];case 2:return o.sent(),[3,4];case 3:return r=o.sent(),u.logDebug(r),[3,4];case 4:return[2]}}))}))}))}return t.prototype.init=function(t,e,n,r){this.streamingUri=t,this.eventsUri=e,this.secret=n,this.appType=r},t.prototype.identify=function(t,e){var n;this.user=O({},t),E.setKey(null===(n=this.user)||void 0===n?void 0:n.keyId),e&&this.socket&&this.sendUserIdentifyMessage(0)},t.prototype.sendUserIdentifyMessage=function(t){var e,n,r=this.user,i={messageType:"data-sync",data:{user:{name:r.name,keyId:r.keyId,customizedProperties:r.customizedProperties},timestamp:t}};try{(null===(e=this.socket)||void 0===e?void 0:e.readyState)===WebSocket.OPEN?(u.logDebug("sending user identify message"),null===(n=this.socket)||void 0===n||n.send(JSON.stringify(i))):u.logDebug("didn't send user identify message because socket not open")}catch(t){u.logDebug(t)}},t.prototype.reconnect=function(){this.socket=null;var t=j[Math.min(this.retryCounter++,j.length-1)];setTimeout((function(){u.logDebug("emit reconnect event"),a.emit(f,{})}),t),u.logDebug(t)},t.prototype.sendPingMessage=function(){var t=this,e={messageType:"ping",data:null};setTimeout((function(){var n;try{(null===(n=t.socket)||void 0===n?void 0:n.readyState)===WebSocket.OPEN?(u.logDebug("sending ping"),t.socket.send(JSON.stringify(e)),t.sendPingMessage()):(u.logDebug("socket closed at ".concat(new Date)),t.reconnect())}catch(t){u.logDebug(t)}}),18e3)},t.prototype.createConnection=function(t,e){var n=this;if(n.socket)e({});else{var r=Date.now(),i="".concat(this.streamingUri,"/streaming?type=client&token=").concat(function(t){t=t.replace(/=*$/,"");var e=Date.now(),n=w(e,e.toString().length),r=Math.max(Math.floor(Math.random()*t.length),2);return"".concat(w(r,3)).concat(w(n.length,2)).concat(t.slice(0,r)).concat(n).concat(t.slice(r))}(this.secret));n.socket=new WebSocket(i),n.socket.addEventListener("open",(function(e){n.retryCounter=0,u.logDebug("Connection time: ".concat(Date.now()-r," ms")),n.sendUserIdentifyMessage(t),n.sendPingMessage()})),n.socket.addEventListener("close",(function(t){u.logDebug("close"),4003!==t.code&&n.reconnect()})),n.socket.addEventListener("error",(function(t){u.logDebug("error")})),n.socket.addEventListener("message",(function(t){var n=JSON.parse(t.data);"data-sync"===n.messageType&&(e(n.data),n.data.featureFlags.length>0&&u.logDebug("socket push update time(ms): ",Date.now()-n.data.featureFlags[0].timestamp))}))}},t.prototype.__getUserInfo=function(){var t=this.user;return{name:t.name,keyId:t.keyId,customizedProperties:t.customizedProperties}},t}());function U(t,e,n){return void 0===t&&(t=""),void 0===e&&(e={}),void 0===n&&(n={}),D(this,void 0,void 0,(function(){var r,i;return I(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,fetch(t,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},n),body:JSON.stringify(e)})];case 1:return[2,200===(r=o.sent()).status?r.json():{}];case 2:return i=o.sent(),u.logDebug(i),[2,{}];case 3:return[2]}}))}))}var N=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=""),this.flushLimit=t,this.arriveflushLimitTopic=e,this.queue=[]}return t.prototype.add=function(t){this.queue.push(t),this.flushLimit>0&&this.queue.length>=this.flushLimit&&a.emit(this.arriveflushLimitTopic,{})},t.prototype.flush=function(){var t=function(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}([],this.queue,!0);return this.queue=[],t},t}(),M=function(){return M=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},M.apply(this,arguments)},V=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function a(t){try{s(r.next(t))}catch(t){o(t)}}function u(t){try{s(r.throw(t))}catch(t){o(t)}}function s(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},A=function(t,e){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){a.label=u[1];break}if(6===u[0]&&a.label<i[1]){a.label=i[1],i=u;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(u);break}i[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},C=function(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))};function L(){var t=function(){var t=localStorage.getItem("fb-guid");if(t)return t;var e=g();return localStorage.setItem("fb-guid",e),e}();return{name:t,keyId:t}}function z(t){return Object.keys(t).map((function(e){var n=t[e],i=n.id,o=n.variation,a=t[e].variationType||r.string;return{id:i,variation:v(a,o),variationType:a}}))}var J=function(){function t(){var t=this;this._readyEventEmitted=!1,this._insightsQueue=new N(1,s),this._featureFlagEvaluationBuffer=new N,this._option={secret:"",api:"",streamingUri:"",eventsUri:"",enableDataSync:!0,appType:"javascript"},this._readyPromise=new Promise((function(e,r){t.on("ready",(function(){var r=k.getFeatureFlags();if(e(z(r)),t._option.enableDataSync){var i=t._featureFlagEvaluationBuffer.flush().map((function(t){var e=r[t.id];if(!e)return u.log("Called unexisting feature flag: ".concat(t.id)),null;var i=e.variationOptions.find((function(e){return e.value===t.variationValue}));return i?u.logDebug("Sent buffered insight for feature flag: ".concat(t.id," with variation: ").concat(i.value)):u.log("Sent buffered insight for feature flag: ".concat(t.id," with unexisting default variation: ").concat(t.variationValue)),{insightType:n.featureFlagUsage,id:e.id,timestamp:t.timestamp,sendToExperiment:e.sendToExperiment,variation:i||{id:-1,value:t.variationValue}}}));P.sendInsights(i.filter((function(t){return!!t})))}}))})),a.subscribe(f,(function(){return V(t,void 0,void 0,(function(){var t;return A(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),u.logDebug("reconnecting"),[4,this.dataSync()];case 1:return e.sent(),this._readyEventEmitted||(this._readyEventEmitted=!0,a.emit("ready",z(k.getFeatureFlags()))),[3,3];case 2:return t=e.sent(),u.log("data sync error",t),[3,3];case 3:return[2]}}))}))})),a.subscribe(l,(function(e){t._featureFlagEvaluationBuffer.add(e)})),a.subscribe(s,(function(){t._option.enableDataSync&&P.sendInsights(t._insightsQueue.flush())})),a.subscribe(c,(function(e){t._insightsQueue.add(e)})),a.subscribe("insights.topic",(function(e){t._insightsQueue.add(e)}))}return t.prototype.on=function(t,e){a.subscribe(t,e)},t.prototype.off=function(t,e){a.unsubscribe(t,e)},t.prototype.waitUntilReady=function(){return this._readyPromise},t.prototype.init=function(t){var e;return V(this,void 0,void 0,(function(){var n;return A(this,(function(r){switch(r.label){case 0:return n=function(t){if(null==t)return d.mandatory("option");var e=t.streamingUri,n=t.eventsUri,r=t.secret,i=t.anonymous,o=t.user,a=t.enableDataSync,u=m(e),s=m(n);if(a&&(u||s)){if(s)return d.partialEndpoint("eventsUri");if(u)return d.partialEndpoint("streamingUri")}return a&&m(r)?d.invalidParam("secret"):0!=!!i||o?o?y(o):null:d.mandatory("user")}(M(M({},this._option),t)),null!==n?(u.log(n),[2]):(this._option=M(M(M({},this._option),t),{api:null===(e=t.api||this._option.api)||void 0===e?void 0:e.replace(/\/$/,"")}),this._option.enableDataSync&&P.init(this._option.streamingUri,this._option.eventsUri,this._option.secret,this._option.appType),[4,this.identify(t.user||L())]);case 1:return r.sent(),[2]}}))}))},t.prototype.identify=function(t){var e;return V(this,void 0,void 0,(function(){var n,r;return A(this,(function(i){switch(i.label){case 0:return null!==(n=y(t))?(u.log(n),[2]):(t.customizedProperties=null===(e=t.customizedProperties)||void 0===e?void 0:e.map((function(t){return{name:t.name,value:"".concat(t.value)}})),r=h(t)!==localStorage.getItem(p),this._option.user=Object.assign({},t),localStorage.setItem(p,h(this._option.user)),k.userId=this._option.user.keyId,P.identify(this._option.user,r),[4,this.bootstrap(this._option.bootstrap,r)]);case 1:return i.sent(),[2]}}))}))},t.prototype.logout=function(){return V(this,void 0,void 0,(function(){var t;return A(this,(function(e){switch(e.label){case 0:return t=L(),[4,this.identify(t)];case 1:return e.sent(),[2,t]}}))}))},t.prototype.bootstrap=function(t,e){return V(this,void 0,void 0,(function(){var n,i;return A(this,(function(o){switch(o.label){case 0:if((t=t||this._option.bootstrap)&&t.length>0&&(n={featureFlags:t.reduce((function(t,e){var n=e.id,i=e.variation,o=e.timestamp,a=e.variationOptions,u=e.sendToExperiment,s=e.variationType;return t[n]={id:n,variation:i,timestamp:o,variationOptions:a||[{id:1,value:i}],sendToExperiment:u,variationType:s||r.string},t}),{})},k.setFullData(n),u.logDebug("bootstrapped with full data")),!this._option.enableDataSync)return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,this.dataSync(e)];case 2:return o.sent(),[3,4];case 3:return i=o.sent(),u.log("data sync error",i),[3,4];case 4:return this._readyEventEmitted||(this._readyEventEmitted=!0,a.emit("ready",z(k.getFeatureFlags()))),[2]}}))}))},t.prototype.dataSync=function(t){return V(this,void 0,void 0,(function(){var e=this;return A(this,(function(n){return[2,new Promise((function(n,o){var a=t?0:Math.max.apply(Math,C(C([],Object.values(k.getFeatureFlags()).map((function(t){return t.timestamp})),!1),[0],!1));P.createConnection(a,(function(t){var o;if(t&&t.userKeyId===(null===(o=e._option.user)||void 0===o?void 0:o.keyId)){var a=t.featureFlags;switch(t.eventType){case i.full:case i.patch:var s={featureFlags:a.reduce((function(t,e){var n=e.id,i=e.variation,o=e.timestamp,a=e.variationOptions,u=e.sendToExperiment,s=e.variationType;return t[n]={id:n,variation:i,timestamp:o,variationOptions:a,sendToExperiment:u,variationType:s||r.string},t}),{})};t.eventType===i.full?(k.setFullData(s),u.logDebug("synchonized with full data")):(k.updateBulkFromRemote(s),u.logDebug("synchonized with partial data"));break;default:u.logDebug("invalid stream event type: "+t.eventType)}}n()}))}))]}))}))},t.prototype.variation=function(t,e){var n=B(t,e);return void 0===n?e:n},t.prototype.boolVariation=function(t,e){var n=B(t,e);return void 0===n?e:"true"===(null==n?void 0:n.toLocaleLowerCase())},t.prototype.getUser=function(){return M({},this._option.user)},t.prototype.sendCustomEvent=function(t){var e=this;(t||[]).forEach((function(t){return e._insightsQueue.add(M({insightType:n.customEvent,timestamp:Date.now(),type:"CustomEvent"},t))}))},t.prototype.sendFeatureFlagInsight=function(t,e){this.variation(t,e)},t.prototype.getAllFeatureFlags=function(){var t=k.getFeatureFlags();return Object.values(t).reduce((function(t,e){return t[e.id]=v(e.variationType,e.variation),t}),{})},t}(),B=function(t,e){var n=k.getVariation(t);return void 0===n&&a.emit(l,{id:t,timestamp:Date.now(),variationValue:"".concat(e)}),n};const q=new J;var Q=document.querySelector("html");return Q&&(Q.style.visibility="hidden",setTimeout((function(){return Q.style.visibility="visible"}),500)),u.logDebug("version: 2.0.1"),e})()));
|
|
2
|
-
//# sourceMappingURL=featbit-js-client-sdk-2.0.1.js.map
|