@firebase/remote-config 0.7.0-canary.f06cbf99b → 0.7.0-canary.f5fc6bf76
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/dist/esm/index.esm.js +6 -85
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/src/errors.d.ts +1 -5
- package/dist/esm/src/public_types.d.ts +0 -19
- package/dist/esm/src/remote_config.d.ts +1 -11
- package/dist/esm/src/storage/storage.d.ts +1 -3
- package/dist/index.cjs.js +6 -85
- package/dist/index.cjs.js.map +1 -1
- package/dist/remote-config-public.d.ts +0 -20
- package/dist/remote-config.d.ts +0 -20
- package/dist/src/errors.d.ts +1 -5
- package/dist/src/global_index.d.ts +1 -20
- package/dist/src/public_types.d.ts +0 -19
- package/dist/src/remote_config.d.ts +1 -11
- package/dist/src/storage/storage.d.ts +1 -3
- package/package.json +7 -7
- package/dist/esm/src/abt/experiment.d.ts +0 -13
- package/dist/src/abt/experiment.d.ts +0 -13
package/dist/esm/index.esm.js
CHANGED
|
@@ -5,7 +5,7 @@ import { LogLevel, Logger } from '@firebase/logger';
|
|
|
5
5
|
import '@firebase/installations';
|
|
6
6
|
|
|
7
7
|
const name = "@firebase/remote-config";
|
|
8
|
-
const version = "0.7.0-canary.
|
|
8
|
+
const version = "0.7.0-canary.f5fc6bf76";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @license
|
|
@@ -105,8 +105,7 @@ const ERROR_DESCRIPTION_MAP = {
|
|
|
105
105
|
["stream-error" /* ErrorCode.CONFIG_UPDATE_STREAM_ERROR */]: 'The stream was not able to connect to the backend: {$originalErrorMessage}.',
|
|
106
106
|
["realtime-unavailable" /* ErrorCode.CONFIG_UPDATE_UNAVAILABLE */]: 'The Realtime service is unavailable: {$originalErrorMessage}',
|
|
107
107
|
["update-message-invalid" /* ErrorCode.CONFIG_UPDATE_MESSAGE_INVALID */]: 'The stream invalidation message was unparsable: {$originalErrorMessage}',
|
|
108
|
-
["update-not-fetched" /* ErrorCode.CONFIG_UPDATE_NOT_FETCHED */]: 'Unable to fetch the latest config: {$originalErrorMessage}'
|
|
109
|
-
["analytics-unavailable" /* ErrorCode.ANALYTICS_UNAVAILABLE */]: 'Connection to Firebase Analytics failed: {$originalErrorMessage}'
|
|
108
|
+
["update-not-fetched" /* ErrorCode.CONFIG_UPDATE_NOT_FETCHED */]: 'Unable to fetch the latest config: {$originalErrorMessage}'
|
|
110
109
|
};
|
|
111
110
|
const ERROR_FACTORY = new ErrorFactory('remoteconfig' /* service */, 'Remote Config' /* service name */, ERROR_DESCRIPTION_MAP);
|
|
112
111
|
// Note how this is like typeof/instanceof, but for ErrorCode.
|
|
@@ -163,64 +162,6 @@ class Value {
|
|
|
163
162
|
}
|
|
164
163
|
}
|
|
165
164
|
|
|
166
|
-
class Experiment {
|
|
167
|
-
constructor(rc) {
|
|
168
|
-
this.storage = rc._storage;
|
|
169
|
-
this.logger = rc._logger;
|
|
170
|
-
this.analyticsProvider = rc._analyticsProvider;
|
|
171
|
-
}
|
|
172
|
-
async updateActiveExperiments(latestExperiments) {
|
|
173
|
-
const currentActiveExperiments = (await this.storage.getActiveExperiments()) || new Set();
|
|
174
|
-
const experimentInfoMap = this.createExperimentInfoMap(latestExperiments);
|
|
175
|
-
this.addActiveExperiments(experimentInfoMap);
|
|
176
|
-
this.removeInactiveExperiments(currentActiveExperiments, experimentInfoMap);
|
|
177
|
-
return this.storage.setActiveExperiments(new Set(experimentInfoMap.keys()));
|
|
178
|
-
}
|
|
179
|
-
createExperimentInfoMap(latestExperiments) {
|
|
180
|
-
const experimentInfoMap = new Map();
|
|
181
|
-
for (const experiment of latestExperiments) {
|
|
182
|
-
experimentInfoMap.set(experiment.experimentId, experiment);
|
|
183
|
-
}
|
|
184
|
-
return experimentInfoMap;
|
|
185
|
-
}
|
|
186
|
-
addActiveExperiments(experimentInfoMap) {
|
|
187
|
-
const customProperty = {};
|
|
188
|
-
for (const [experimentId, experimentInfo] of experimentInfoMap.entries()) {
|
|
189
|
-
customProperty[`firebase${experimentId}`] = experimentInfo.variantId;
|
|
190
|
-
}
|
|
191
|
-
this.addExperimentToAnalytics(customProperty);
|
|
192
|
-
}
|
|
193
|
-
removeInactiveExperiments(currentActiveExperiments, experimentInfoMap) {
|
|
194
|
-
const customProperty = {};
|
|
195
|
-
for (const experimentId of currentActiveExperiments) {
|
|
196
|
-
if (!experimentInfoMap.has(experimentId)) {
|
|
197
|
-
customProperty[`firebase${experimentId}`] = null;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
this.addExperimentToAnalytics(customProperty);
|
|
201
|
-
}
|
|
202
|
-
addExperimentToAnalytics(customProperty) {
|
|
203
|
-
if (Object.keys(customProperty).length === 0) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
try {
|
|
207
|
-
const analytics = this.analyticsProvider.getImmediate({ optional: true });
|
|
208
|
-
if (analytics) {
|
|
209
|
-
analytics.setUserProperties(customProperty);
|
|
210
|
-
analytics.logEvent(`set_firebase_experiment_state`);
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
this.logger.warn(`Analytics import failed. Verify if you have imported Firebase Analytics in your app code.`);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
catch (error) {
|
|
217
|
-
throw ERROR_FACTORY.create("analytics-unavailable" /* ErrorCode.ANALYTICS_UNAVAILABLE */, {
|
|
218
|
-
originalErrorMessage: error?.message
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
165
|
/**
|
|
225
166
|
* @license
|
|
226
167
|
* Copyright 2020 Google LLC
|
|
@@ -298,15 +239,10 @@ async function activate(remoteConfig) {
|
|
|
298
239
|
// config.
|
|
299
240
|
return false;
|
|
300
241
|
}
|
|
301
|
-
const experiment = new Experiment(rc);
|
|
302
|
-
const updateActiveExperiments = lastSuccessfulFetchResponse.experiments
|
|
303
|
-
? experiment.updateActiveExperiments(lastSuccessfulFetchResponse.experiments)
|
|
304
|
-
: Promise.resolve();
|
|
305
242
|
await Promise.all([
|
|
306
243
|
rc._storageCache.setActiveConfig(lastSuccessfulFetchResponse.config),
|
|
307
244
|
rc._storage.setActiveConfigEtag(lastSuccessfulFetchResponse.eTag),
|
|
308
|
-
rc._storage.setActiveConfigTemplateVersion(lastSuccessfulFetchResponse.templateVersion)
|
|
309
|
-
updateActiveExperiments
|
|
245
|
+
rc._storage.setActiveConfigTemplateVersion(lastSuccessfulFetchResponse.templateVersion)
|
|
310
246
|
]);
|
|
311
247
|
return true;
|
|
312
248
|
}
|
|
@@ -761,7 +697,6 @@ class RestClient {
|
|
|
761
697
|
let config;
|
|
762
698
|
let state;
|
|
763
699
|
let templateVersion;
|
|
764
|
-
let experiments;
|
|
765
700
|
// JSON parsing throws SyntaxError if the response body isn't a JSON string.
|
|
766
701
|
// Requesting application/json and checking for a 200 ensures there's JSON data.
|
|
767
702
|
if (response.status === 200) {
|
|
@@ -777,7 +712,6 @@ class RestClient {
|
|
|
777
712
|
config = responseBody['entries'];
|
|
778
713
|
state = responseBody['state'];
|
|
779
714
|
templateVersion = responseBody['templateVersion'];
|
|
780
|
-
experiments = responseBody['experimentDescriptions'];
|
|
781
715
|
}
|
|
782
716
|
// Normalizes based on legacy state.
|
|
783
717
|
if (state === 'INSTANCE_STATE_UNSPECIFIED') {
|
|
@@ -789,7 +723,6 @@ class RestClient {
|
|
|
789
723
|
else if (state === 'NO_TEMPLATE' || state === 'EMPTY_CONFIG') {
|
|
790
724
|
// These cases can be fixed remotely, so normalize to safe value.
|
|
791
725
|
config = {};
|
|
792
|
-
experiments = [];
|
|
793
726
|
}
|
|
794
727
|
// Normalize to exception-based control flow for non-success cases.
|
|
795
728
|
// Encapsulates HTTP specifics in this class as much as possible. Status is still the best for
|
|
@@ -800,7 +733,7 @@ class RestClient {
|
|
|
800
733
|
httpStatus: status
|
|
801
734
|
});
|
|
802
735
|
}
|
|
803
|
-
return { status, eTag: responseEtag, config, templateVersion
|
|
736
|
+
return { status, eTag: responseEtag, config, templateVersion };
|
|
804
737
|
}
|
|
805
738
|
}
|
|
806
739
|
|
|
@@ -966,18 +899,13 @@ class RemoteConfig {
|
|
|
966
899
|
/**
|
|
967
900
|
* @internal
|
|
968
901
|
*/
|
|
969
|
-
_realtimeHandler
|
|
970
|
-
/**
|
|
971
|
-
* @internal
|
|
972
|
-
*/
|
|
973
|
-
_analyticsProvider) {
|
|
902
|
+
_realtimeHandler) {
|
|
974
903
|
this.app = app;
|
|
975
904
|
this._client = _client;
|
|
976
905
|
this._storageCache = _storageCache;
|
|
977
906
|
this._storage = _storage;
|
|
978
907
|
this._logger = _logger;
|
|
979
908
|
this._realtimeHandler = _realtimeHandler;
|
|
980
|
-
this._analyticsProvider = _analyticsProvider;
|
|
981
909
|
/**
|
|
982
910
|
* Tracks completion of initialization promise.
|
|
983
911
|
* @internal
|
|
@@ -1098,12 +1026,6 @@ class Storage {
|
|
|
1098
1026
|
setActiveConfigEtag(etag) {
|
|
1099
1027
|
return this.set('active_config_etag', etag);
|
|
1100
1028
|
}
|
|
1101
|
-
getActiveExperiments() {
|
|
1102
|
-
return this.get('active_experiments');
|
|
1103
|
-
}
|
|
1104
|
-
setActiveExperiments(experiments) {
|
|
1105
|
-
return this.set('active_experiments', experiments);
|
|
1106
|
-
}
|
|
1107
1029
|
getThrottleMetadata() {
|
|
1108
1030
|
return this.get('throttle_metadata');
|
|
1109
1031
|
}
|
|
@@ -2094,7 +2016,6 @@ function registerRemoteConfig() {
|
|
|
2094
2016
|
const installations = container
|
|
2095
2017
|
.getProvider('installations-internal')
|
|
2096
2018
|
.getImmediate();
|
|
2097
|
-
const analyticsProvider = container.getProvider('analytics-internal');
|
|
2098
2019
|
// Normalizes optional inputs.
|
|
2099
2020
|
const { projectId, apiKey, appId } = app.options;
|
|
2100
2021
|
if (!projectId) {
|
|
@@ -2121,7 +2042,7 @@ function registerRemoteConfig() {
|
|
|
2121
2042
|
const retryingClient = new RetryingClient(restClient, storage);
|
|
2122
2043
|
const cachingClient = new CachingClient(retryingClient, storage, storageCache, logger);
|
|
2123
2044
|
const realtimeHandler = new RealtimeHandler(installations, storage, SDK_VERSION, namespace, projectId, apiKey, appId, logger, storageCache, cachingClient);
|
|
2124
|
-
const remoteConfigInstance = new RemoteConfig(app, cachingClient, storageCache, storage, logger, realtimeHandler
|
|
2045
|
+
const remoteConfigInstance = new RemoteConfig(app, cachingClient, storageCache, storage, logger, realtimeHandler);
|
|
2125
2046
|
// Starts warming cache.
|
|
2126
2047
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
2127
2048
|
ensureInitialized(remoteConfigInstance);
|