@firebase/remote-config 0.3.1-canary.ba40cde9c → 0.3.1-canary.dbfe09e9d

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.
Files changed (35) hide show
  1. package/dist/{index.esm.js → esm/index.esm.js} +1 -1
  2. package/dist/esm/index.esm.js.map +1 -0
  3. package/dist/{index.esm2017.js → esm/index.esm2017.js} +1 -1
  4. package/dist/esm/index.esm2017.js.map +1 -0
  5. package/dist/esm/package.json +1 -0
  6. package/dist/esm/src/api.d.ts +115 -0
  7. package/dist/esm/src/api2.d.ts +40 -0
  8. package/dist/esm/src/client/caching_client.d.ts +45 -0
  9. package/dist/esm/src/client/remote_config_fetch_client.d.ts +123 -0
  10. package/dist/esm/src/client/rest_client.d.ts +40 -0
  11. package/dist/esm/src/client/retrying_client.d.ts +49 -0
  12. package/dist/esm/src/constants.d.ts +17 -0
  13. package/dist/esm/src/errors.d.ts +62 -0
  14. package/dist/esm/src/index.d.ts +13 -0
  15. package/dist/esm/src/language.d.ts +26 -0
  16. package/dist/esm/src/public_types.d.ts +128 -0
  17. package/dist/esm/src/register.d.ts +2 -0
  18. package/dist/esm/src/remote_config.d.ts +79 -0
  19. package/dist/esm/src/storage/storage.d.ts +76 -0
  20. package/dist/esm/src/storage/storage_cache.d.ts +48 -0
  21. package/dist/esm/src/value.d.ts +26 -0
  22. package/dist/esm/test/client/caching_client.test.d.ts +17 -0
  23. package/dist/esm/test/client/rest_client.test.d.ts +17 -0
  24. package/dist/esm/test/client/retrying_client.test.d.ts +17 -0
  25. package/dist/esm/test/errors.test.d.ts +17 -0
  26. package/dist/esm/test/language.test.d.ts +17 -0
  27. package/dist/esm/test/remote_config.test.d.ts +17 -0
  28. package/dist/esm/test/setup.d.ts +17 -0
  29. package/dist/esm/test/storage/storage.test.d.ts +17 -0
  30. package/dist/esm/test/storage/storage_cache.test.d.ts +17 -0
  31. package/dist/esm/test/value.test.d.ts +17 -0
  32. package/dist/index.cjs.js +1 -1
  33. package/package.json +18 -11
  34. package/dist/index.esm.js.map +0 -1
  35. package/dist/index.esm2017.js.map +0 -1
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2019 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { StorageCache } from '../storage/storage_cache';
18
+ import { FetchResponse, RemoteConfigFetchClient, FetchRequest } from './remote_config_fetch_client';
19
+ import { Storage } from '../storage/storage';
20
+ import { Logger } from '@firebase/logger';
21
+ /**
22
+ * Implements the {@link RemoteConfigClient} abstraction with success response caching.
23
+ *
24
+ * <p>Comparable to the browser's Cache API for responses, but the Cache API requires a Service
25
+ * Worker, which requires HTTPS, which would significantly complicate SDK installation. Also, the
26
+ * Cache API doesn't support matching entries by time.
27
+ */
28
+ export declare class CachingClient implements RemoteConfigFetchClient {
29
+ private readonly client;
30
+ private readonly storage;
31
+ private readonly storageCache;
32
+ private readonly logger;
33
+ constructor(client: RemoteConfigFetchClient, storage: Storage, storageCache: StorageCache, logger: Logger);
34
+ /**
35
+ * Returns true if the age of the cached fetched configs is less than or equal to
36
+ * {@link Settings#minimumFetchIntervalInSeconds}.
37
+ *
38
+ * <p>This is comparable to passing `headers = { 'Cache-Control': max-age <maxAge> }` to the
39
+ * native Fetch API.
40
+ *
41
+ * <p>Visible for testing.
42
+ */
43
+ isCachedDataFresh(cacheMaxAgeMillis: number, lastSuccessfulFetchTimestampMillis: number | undefined): boolean;
44
+ fetch(request: FetchRequest): Promise<FetchResponse>;
45
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2019 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * Defines a client, as in https://en.wikipedia.org/wiki/Client%E2%80%93server_model, for the
19
+ * Remote Config server (https://firebase.google.com/docs/reference/remote-config/rest).
20
+ *
21
+ * <p>Abstracts throttle, response cache and network implementation details.
22
+ *
23
+ * <p>Modeled after the native {@link GlobalFetch} interface, which is relatively modern and
24
+ * convenient, but simplified for Remote Config's use case.
25
+ *
26
+ * Disambiguation: {@link GlobalFetch} interface and the Remote Config service define "fetch"
27
+ * methods. The RestClient uses the former to make HTTP calls. This interface abstracts the latter.
28
+ */
29
+ export interface RemoteConfigFetchClient {
30
+ /**
31
+ * @throws if response status is not 200 or 304.
32
+ */
33
+ fetch(request: FetchRequest): Promise<FetchResponse>;
34
+ }
35
+ /**
36
+ * Defines a self-descriptive reference for config key-value pairs.
37
+ */
38
+ export interface FirebaseRemoteConfigObject {
39
+ [key: string]: string;
40
+ }
41
+ /**
42
+ * Shims a minimal AbortSignal.
43
+ *
44
+ * <p>AbortController's AbortSignal conveniently decouples fetch timeout logic from other aspects
45
+ * of networking, such as retries. Firebase doesn't use AbortController enough to justify a
46
+ * polyfill recommendation, like we do with the Fetch API, but this minimal shim can easily be
47
+ * swapped out if/when we do.
48
+ */
49
+ export declare class RemoteConfigAbortSignal {
50
+ listeners: Array<() => void>;
51
+ addEventListener(listener: () => void): void;
52
+ abort(): void;
53
+ }
54
+ /**
55
+ * Defines per-request inputs for the Remote Config fetch request.
56
+ *
57
+ * <p>Modeled after the native {@link Request} interface, but simplified for Remote Config's
58
+ * use case.
59
+ */
60
+ export interface FetchRequest {
61
+ /**
62
+ * Uses cached config if it is younger than this age.
63
+ *
64
+ * <p>Required because it's defined by settings, which always have a value.
65
+ *
66
+ * <p>Comparable to passing `headers = { 'Cache-Control': max-age <maxAge> }` to the native
67
+ * Fetch API.
68
+ */
69
+ cacheMaxAgeMillis: number;
70
+ /**
71
+ * An event bus for the signal to abort a request.
72
+ *
73
+ * <p>Required because all requests should be abortable.
74
+ *
75
+ * <p>Comparable to the native
76
+ * Fetch API's "signal" field on its request configuration object
77
+ * https://fetch.spec.whatwg.org/#dom-requestinit-signal.
78
+ *
79
+ * <p>Disambiguation: Remote Config commonly refers to API inputs as
80
+ * "signals". See the private ConfigFetchRequestBody interface for those:
81
+ * http://google3/firebase/remote_config/web/src/core/rest_client.ts?l=14&rcl=255515243.
82
+ */
83
+ signal: RemoteConfigAbortSignal;
84
+ /**
85
+ * The ETag header value from the last response.
86
+ *
87
+ * <p>Optional in case this is the first request.
88
+ *
89
+ * <p>Comparable to passing `headers = { 'If-None-Match': <eTag> }` to the native Fetch API.
90
+ */
91
+ eTag?: string;
92
+ }
93
+ /**
94
+ * Defines a successful response (200 or 304).
95
+ *
96
+ * <p>Modeled after the native {@link Response} interface, but simplified for Remote Config's
97
+ * use case.
98
+ */
99
+ export interface FetchResponse {
100
+ /**
101
+ * The HTTP status, which is useful for differentiating success responses with data from
102
+ * those without.
103
+ *
104
+ * <p>{@link RemoteConfigClient} is modeled after the native {@link GlobalFetch} interface, so
105
+ * HTTP status is first-class.
106
+ *
107
+ * <p>Disambiguation: the fetch response returns a legacy "state" value that is redundant with the
108
+ * HTTP status code. The former is normalized into the latter.
109
+ */
110
+ status: number;
111
+ /**
112
+ * Defines the ETag response header value.
113
+ *
114
+ * <p>Only defined for 200 and 304 responses.
115
+ */
116
+ eTag?: string;
117
+ /**
118
+ * Defines the map of parameters returned as "entries" in the fetch response body.
119
+ *
120
+ * <p>Only defined for 200 responses.
121
+ */
122
+ config?: FirebaseRemoteConfigObject;
123
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2019 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { FetchResponse, RemoteConfigFetchClient, FetchRequest } from './remote_config_fetch_client';
18
+ import { _FirebaseInstallationsInternal } from '@firebase/installations';
19
+ /**
20
+ * Implements the Client abstraction for the Remote Config REST API.
21
+ */
22
+ export declare class RestClient implements RemoteConfigFetchClient {
23
+ private readonly firebaseInstallations;
24
+ private readonly sdkVersion;
25
+ private readonly namespace;
26
+ private readonly projectId;
27
+ private readonly apiKey;
28
+ private readonly appId;
29
+ constructor(firebaseInstallations: _FirebaseInstallationsInternal, sdkVersion: string, namespace: string, projectId: string, apiKey: string, appId: string);
30
+ /**
31
+ * Fetches from the Remote Config REST API.
32
+ *
33
+ * @throws a {@link ErrorCode.FETCH_NETWORK} error if {@link GlobalFetch#fetch} can't
34
+ * connect to the network.
35
+ * @throws a {@link ErrorCode.FETCH_PARSE} error if {@link Response#json} can't parse the
36
+ * fetch response.
37
+ * @throws a {@link ErrorCode.FETCH_STATUS} error if the service returns an HTTP error status.
38
+ */
39
+ fetch(request: FetchRequest): Promise<FetchResponse>;
40
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2019 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { RemoteConfigAbortSignal, RemoteConfigFetchClient, FetchResponse, FetchRequest } from './remote_config_fetch_client';
18
+ import { ThrottleMetadata, Storage } from '../storage/storage';
19
+ /**
20
+ * Supports waiting on a backoff by:
21
+ *
22
+ * <ul>
23
+ * <li>Promisifying setTimeout, so we can set a timeout in our Promise chain</li>
24
+ * <li>Listening on a signal bus for abort events, just like the Fetch API</li>
25
+ * <li>Failing in the same way the Fetch API fails, so timing out a live request and a throttled
26
+ * request appear the same.</li>
27
+ * </ul>
28
+ *
29
+ * <p>Visible for testing.
30
+ */
31
+ export declare function setAbortableTimeout(signal: RemoteConfigAbortSignal, throttleEndTimeMillis: number): Promise<void>;
32
+ /**
33
+ * Decorates a Client with retry logic.
34
+ *
35
+ * <p>Comparable to CachingClient, but uses backoff logic instead of cache max age and doesn't cache
36
+ * responses (because the SDK has no use for error responses).
37
+ */
38
+ export declare class RetryingClient implements RemoteConfigFetchClient {
39
+ private readonly client;
40
+ private readonly storage;
41
+ constructor(client: RemoteConfigFetchClient, storage: Storage);
42
+ fetch(request: FetchRequest): Promise<FetchResponse>;
43
+ /**
44
+ * A recursive helper for attempting a fetch request repeatedly.
45
+ *
46
+ * @throws any non-retriable errors.
47
+ */
48
+ attemptFetch(request: FetchRequest, { throttleEndTimeMillis, backoffCount }: ThrottleMetadata): Promise<FetchResponse>;
49
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export declare const RC_COMPONENT_NAME = "remote-config";
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2019 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { ErrorFactory } from '@firebase/util';
18
+ export declare const enum ErrorCode {
19
+ REGISTRATION_WINDOW = "registration-window",
20
+ REGISTRATION_PROJECT_ID = "registration-project-id",
21
+ REGISTRATION_API_KEY = "registration-api-key",
22
+ REGISTRATION_APP_ID = "registration-app-id",
23
+ STORAGE_OPEN = "storage-open",
24
+ STORAGE_GET = "storage-get",
25
+ STORAGE_SET = "storage-set",
26
+ STORAGE_DELETE = "storage-delete",
27
+ FETCH_NETWORK = "fetch-client-network",
28
+ FETCH_TIMEOUT = "fetch-timeout",
29
+ FETCH_THROTTLE = "fetch-throttle",
30
+ FETCH_PARSE = "fetch-client-parse",
31
+ FETCH_STATUS = "fetch-status",
32
+ INDEXED_DB_UNAVAILABLE = "indexed-db-unavailable"
33
+ }
34
+ interface ErrorParams {
35
+ [ErrorCode.STORAGE_OPEN]: {
36
+ originalErrorMessage: string | undefined;
37
+ };
38
+ [ErrorCode.STORAGE_GET]: {
39
+ originalErrorMessage: string | undefined;
40
+ };
41
+ [ErrorCode.STORAGE_SET]: {
42
+ originalErrorMessage: string | undefined;
43
+ };
44
+ [ErrorCode.STORAGE_DELETE]: {
45
+ originalErrorMessage: string | undefined;
46
+ };
47
+ [ErrorCode.FETCH_NETWORK]: {
48
+ originalErrorMessage: string;
49
+ };
50
+ [ErrorCode.FETCH_THROTTLE]: {
51
+ throttleEndTimeMillis: number;
52
+ };
53
+ [ErrorCode.FETCH_PARSE]: {
54
+ originalErrorMessage: string;
55
+ };
56
+ [ErrorCode.FETCH_STATUS]: {
57
+ httpStatus: number;
58
+ };
59
+ }
60
+ export declare const ERROR_FACTORY: ErrorFactory<ErrorCode, ErrorParams>;
61
+ export declare function hasErrorCode(e: Error, errorCode: ErrorCode): boolean;
62
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Firebase Remote Config
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ declare global {
7
+ interface Window {
8
+ FIREBASE_REMOTE_CONFIG_URL_BASE: string;
9
+ }
10
+ }
11
+ export * from './api';
12
+ export * from './api2';
13
+ export * from './public_types';
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2019 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * Attempts to get the most accurate browser language setting.
19
+ *
20
+ * <p>Adapted from getUserLanguage in packages/auth/src/utils.js for TypeScript.
21
+ *
22
+ * <p>Defers default language specification to server logic for consistency.
23
+ *
24
+ * @param navigatorLanguage Enables tests to override read-only {@link NavigatorLanguage}.
25
+ */
26
+ export declare function getUserLanguage(navigatorLanguage?: NavigatorLanguage): string;
@@ -0,0 +1,128 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { FirebaseApp } from '@firebase/app';
18
+ /**
19
+ * The Firebase Remote Config service interface.
20
+ *
21
+ * @public
22
+ */
23
+ export interface RemoteConfig {
24
+ /**
25
+ * The {@link @firebase/app#FirebaseApp} this `RemoteConfig` instance is associated with.
26
+ */
27
+ app: FirebaseApp;
28
+ /**
29
+ * Defines configuration for the Remote Config SDK.
30
+ */
31
+ settings: RemoteConfigSettings;
32
+ /**
33
+ * Object containing default values for configs.
34
+ */
35
+ defaultConfig: {
36
+ [key: string]: string | number | boolean;
37
+ };
38
+ /**
39
+ * The Unix timestamp in milliseconds of the last <i>successful</i> fetch, or negative one if
40
+ * the {@link RemoteConfig} instance either hasn't fetched or initialization
41
+ * is incomplete.
42
+ */
43
+ fetchTimeMillis: number;
44
+ /**
45
+ * The status of the last fetch <i>attempt</i>.
46
+ */
47
+ lastFetchStatus: FetchStatus;
48
+ }
49
+ /**
50
+ * Indicates the source of a value.
51
+ *
52
+ * <ul>
53
+ * <li>"static" indicates the value was defined by a static constant.</li>
54
+ * <li>"default" indicates the value was defined by default config.</li>
55
+ * <li>"remote" indicates the value was defined by fetched config.</li>
56
+ * </ul>
57
+ *
58
+ * @public
59
+ */
60
+ export declare type ValueSource = 'static' | 'default' | 'remote';
61
+ /**
62
+ * Wraps a value with metadata and type-safe getters.
63
+ *
64
+ * @public
65
+ */
66
+ export interface Value {
67
+ /**
68
+ * Gets the value as a boolean.
69
+ *
70
+ * The following values (case insensitive) are interpreted as true:
71
+ * "1", "true", "t", "yes", "y", "on". Other values are interpreted as false.
72
+ */
73
+ asBoolean(): boolean;
74
+ /**
75
+ * Gets the value as a number. Comparable to calling <code>Number(value) || 0</code>.
76
+ */
77
+ asNumber(): number;
78
+ /**
79
+ * Gets the value as a string.
80
+ */
81
+ asString(): string;
82
+ /**
83
+ * Gets the {@link ValueSource} for the given key.
84
+ */
85
+ getSource(): ValueSource;
86
+ }
87
+ /**
88
+ * Defines configuration options for the Remote Config SDK.
89
+ *
90
+ * @public
91
+ */
92
+ export interface RemoteConfigSettings {
93
+ /**
94
+ * Defines the maximum age in milliseconds of an entry in the config cache before
95
+ * it is considered stale. Defaults to 43200000 (Twelve hours).
96
+ */
97
+ minimumFetchIntervalMillis: number;
98
+ /**
99
+ * Defines the maximum amount of milliseconds to wait for a response when fetching
100
+ * configuration from the Remote Config server. Defaults to 60000 (One minute).
101
+ */
102
+ fetchTimeoutMillis: number;
103
+ }
104
+ /**
105
+ * Summarizes the outcome of the last attempt to fetch config from the Firebase Remote Config server.
106
+ *
107
+ * <ul>
108
+ * <li>"no-fetch-yet" indicates the {@link RemoteConfig} instance has not yet attempted
109
+ * to fetch config, or that SDK initialization is incomplete.</li>
110
+ * <li>"success" indicates the last attempt succeeded.</li>
111
+ * <li>"failure" indicates the last attempt failed.</li>
112
+ * <li>"throttle" indicates the last attempt was rate-limited.</li>
113
+ * </ul>
114
+ *
115
+ * @public
116
+ */
117
+ export declare type FetchStatus = 'no-fetch-yet' | 'success' | 'failure' | 'throttle';
118
+ /**
119
+ * Defines levels of Remote Config logging.
120
+ *
121
+ * @public
122
+ */
123
+ export declare type LogLevel = 'debug' | 'error' | 'silent';
124
+ declare module '@firebase/component' {
125
+ interface NameServiceMapping {
126
+ 'remote-config': RemoteConfig;
127
+ }
128
+ }
@@ -0,0 +1,2 @@
1
+ import '@firebase/installations';
2
+ export declare function registerRemoteConfig(): void;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2019 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { FirebaseApp } from '@firebase/app';
18
+ import { RemoteConfig as RemoteConfigType, FetchStatus, RemoteConfigSettings } from './public_types';
19
+ import { StorageCache } from './storage/storage_cache';
20
+ import { RemoteConfigFetchClient } from './client/remote_config_fetch_client';
21
+ import { Storage } from './storage/storage';
22
+ import { Logger } from '@firebase/logger';
23
+ /**
24
+ * Encapsulates business logic mapping network and storage dependencies to the public SDK API.
25
+ *
26
+ * See {@link https://github.com/FirebasePrivate/firebase-js-sdk/blob/master/packages/firebase/index.d.ts|interface documentation} for method descriptions.
27
+ */
28
+ export declare class RemoteConfig implements RemoteConfigType {
29
+ readonly app: FirebaseApp;
30
+ /**
31
+ * @internal
32
+ */
33
+ readonly _client: RemoteConfigFetchClient;
34
+ /**
35
+ * @internal
36
+ */
37
+ readonly _storageCache: StorageCache;
38
+ /**
39
+ * @internal
40
+ */
41
+ readonly _storage: Storage;
42
+ /**
43
+ * @internal
44
+ */
45
+ readonly _logger: Logger;
46
+ /**
47
+ * Tracks completion of initialization promise.
48
+ * @internal
49
+ */
50
+ _isInitializationComplete: boolean;
51
+ /**
52
+ * De-duplicates initialization calls.
53
+ * @internal
54
+ */
55
+ _initializePromise?: Promise<void>;
56
+ settings: RemoteConfigSettings;
57
+ defaultConfig: {
58
+ [key: string]: string | number | boolean;
59
+ };
60
+ get fetchTimeMillis(): number;
61
+ get lastFetchStatus(): FetchStatus;
62
+ constructor(app: FirebaseApp,
63
+ /**
64
+ * @internal
65
+ */
66
+ _client: RemoteConfigFetchClient,
67
+ /**
68
+ * @internal
69
+ */
70
+ _storageCache: StorageCache,
71
+ /**
72
+ * @internal
73
+ */
74
+ _storage: Storage,
75
+ /**
76
+ * @internal
77
+ */
78
+ _logger: Logger);
79
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2019 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { FetchStatus } from '@firebase/remote-config-types';
18
+ import { FetchResponse, FirebaseRemoteConfigObject } from '../client/remote_config_fetch_client';
19
+ /**
20
+ * A general-purpose store keyed by app + namespace + {@link
21
+ * ProjectNamespaceKeyFieldValue}.
22
+ *
23
+ * <p>The Remote Config SDK can be used with multiple app installations, and each app can interact
24
+ * with multiple namespaces, so this store uses app (ID + name) and namespace as common parent keys
25
+ * for a set of key-value pairs. See {@link Storage#createCompositeKey}.
26
+ *
27
+ * <p>Visible for testing.
28
+ */
29
+ export declare const APP_NAMESPACE_STORE = "app_namespace_store";
30
+ /**
31
+ * Encapsulates metadata concerning throttled fetch requests.
32
+ */
33
+ export interface ThrottleMetadata {
34
+ backoffCount: number;
35
+ throttleEndTimeMillis: number;
36
+ }
37
+ /**
38
+ * Provides type-safety for the "key" field used by {@link APP_NAMESPACE_STORE}.
39
+ *
40
+ * <p>This seems like a small price to avoid potentially subtle bugs caused by a typo.
41
+ */
42
+ declare type ProjectNamespaceKeyFieldValue = 'active_config' | 'active_config_etag' | 'last_fetch_status' | 'last_successful_fetch_timestamp_millis' | 'last_successful_fetch_response' | 'settings' | 'throttle_metadata';
43
+ export declare function openDatabase(): Promise<IDBDatabase>;
44
+ /**
45
+ * Abstracts data persistence.
46
+ */
47
+ export declare class Storage {
48
+ private readonly appId;
49
+ private readonly appName;
50
+ private readonly namespace;
51
+ private readonly openDbPromise;
52
+ /**
53
+ * @param appId enables storage segmentation by app (ID + name).
54
+ * @param appName enables storage segmentation by app (ID + name).
55
+ * @param namespace enables storage segmentation by namespace.
56
+ */
57
+ constructor(appId: string, appName: string, namespace: string, openDbPromise?: Promise<IDBDatabase>);
58
+ getLastFetchStatus(): Promise<FetchStatus | undefined>;
59
+ setLastFetchStatus(status: FetchStatus): Promise<void>;
60
+ getLastSuccessfulFetchTimestampMillis(): Promise<number | undefined>;
61
+ setLastSuccessfulFetchTimestampMillis(timestamp: number): Promise<void>;
62
+ getLastSuccessfulFetchResponse(): Promise<FetchResponse | undefined>;
63
+ setLastSuccessfulFetchResponse(response: FetchResponse): Promise<void>;
64
+ getActiveConfig(): Promise<FirebaseRemoteConfigObject | undefined>;
65
+ setActiveConfig(config: FirebaseRemoteConfigObject): Promise<void>;
66
+ getActiveConfigEtag(): Promise<string | undefined>;
67
+ setActiveConfigEtag(etag: string): Promise<void>;
68
+ getThrottleMetadata(): Promise<ThrottleMetadata | undefined>;
69
+ setThrottleMetadata(metadata: ThrottleMetadata): Promise<void>;
70
+ deleteThrottleMetadata(): Promise<void>;
71
+ get<T>(key: ProjectNamespaceKeyFieldValue): Promise<T | undefined>;
72
+ set<T>(key: ProjectNamespaceKeyFieldValue, value: T): Promise<void>;
73
+ delete(key: ProjectNamespaceKeyFieldValue): Promise<void>;
74
+ createCompositeKey(key: ProjectNamespaceKeyFieldValue): string;
75
+ }
76
+ export {};