Skip to content

Commit 2b412d7

Browse files
authored
Add Remote Config SDK (#2193)
1 parent fd35262 commit 2b412d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4208
-7
lines changed

config/karma.saucelabs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function getSauceLabsBrowsers(packageName) {
7676
*/
7777
function getPackageLabels() {
7878
const match = testConfigFile.match(
79-
/([a-zA-Z]+)\/([a-zA-Z]+)\/karma\.conf\.js/
79+
/([a-zA-Z]+)\/([a-zA-Z-]+)\/karma\.conf\.js/
8080
);
8181
return {
8282
type: match[1],

packages/firebase/index.d.ts

Lines changed: 199 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,23 @@ declare namespace firebase {
10991099
app?: firebase.app.App
11001100
): firebase.performance.Performance;
11011101

1102+
/**
1103+
* Gets the {@link firebase.remoteConfig.RemoteConfig `RemoteConfig`} instance.
1104+
*
1105+
* @webonly
1106+
*
1107+
* @example
1108+
* ```javascript
1109+
* // Get the RemoteConfig instance for the default app
1110+
* const defaultRemoteConfig = firebase.remoteConfig();
1111+
* ```
1112+
*
1113+
* @param app The app to create a Remote Config service for. If not passed, uses the default app.
1114+
*/
1115+
function remoteConfig(
1116+
app?: firebase.app.App
1117+
): firebase.remoteConfig.RemoteConfig;
1118+
11021119
/**
11031120
* Gets the {@link firebase.analytics.Analytics `Analytics`} service.
11041121
*
@@ -1116,7 +1133,6 @@ declare namespace firebase {
11161133
* @param app The app to create an analytics service for.
11171134
* If not passed, uses the default app.
11181135
*/
1119-
11201136
function analytics(app?: firebase.app.App): firebase.analytics.Analytics;
11211137
}
11221138

@@ -1270,6 +1286,19 @@ declare namespace firebase.app {
12701286
* ```
12711287
*/
12721288
performance(): firebase.performance.Performance;
1289+
/**
1290+
* Gets the {@link firebase.remoteConfig.RemoteConfig `RemoteConfig`} instance.
1291+
*
1292+
* @webonly
1293+
*
1294+
* @example
1295+
* ```javascript
1296+
* const rc = app.remoteConfig();
1297+
* // The above is shorthand for:
1298+
* // const rc = firebase.remoteConfig(app);
1299+
* ```
1300+
*/
1301+
remoteConfig(): firebase.remoteConfig.RemoteConfig;
12731302
/**
12741303
* Gets the {@link firebase.analytics.Analytics `Analytics`} service for the
12751304
* current app. If the current app is not the default one, throws an error.
@@ -1433,6 +1462,175 @@ declare namespace firebase.performance {
14331462
}
14341463
}
14351464

1465+
/**
1466+
* @webonly
1467+
*/
1468+
declare namespace firebase.remoteConfig {
1469+
/**
1470+
* The Firebase Remote Config service interface.
1471+
*
1472+
* Do not call this constructor directly. Instead, use
1473+
* {@link firebase.remoteConfig `firebase.remoteConfig()`}.
1474+
*/
1475+
export interface RemoteConfig {
1476+
/**
1477+
* Defines configuration for the Remote Config SDK.
1478+
*/
1479+
settings: Settings;
1480+
1481+
/**
1482+
* Object containing default values for conigs.
1483+
*/
1484+
defaultConfig: { [key: string]: string | number | boolean };
1485+
1486+
/**
1487+
* The Unix timestamp in milliseconds of the last <i>successful</i> fetch, or negative one if
1488+
* the {@link RemoteConfig} instance either hasn't fetched or initialization
1489+
* is incomplete.
1490+
*/
1491+
fetchTimeMillis: number;
1492+
1493+
/**
1494+
* The status of the last fetch <i>attempt</i>.
1495+
*/
1496+
lastFetchStatus: FetchStatus;
1497+
1498+
/**
1499+
* Makes the last fetched config available to the getters.
1500+
* Returns a promise which resolves to true if the current call activated the fetched configs.
1501+
* If the fetched configs were already activated, the promise will resolve to false.
1502+
*/
1503+
activate(): Promise<boolean>;
1504+
1505+
/**
1506+
* Ensures the last activated config are available to the getters.
1507+
*/
1508+
ensureInitialized(): Promise<void>;
1509+
1510+
/**
1511+
* Fetches and caches configuration from the Remote Config service.
1512+
*/
1513+
fetch(): Promise<void>;
1514+
1515+
/**
1516+
* Performs fetch and activate operations, as a convenience.
1517+
* Returns a promise which resolves to true if the current call activated the fetched configs.
1518+
* If the fetched configs were already activated, the promise will resolve to false.
1519+
*/
1520+
fetchAndActivate(): Promise<boolean>;
1521+
1522+
/**
1523+
* Gets all config.
1524+
*/
1525+
getAll(): { [key: string]: Value };
1526+
1527+
/**
1528+
* Gets the value for the given key as a boolean.
1529+
*
1530+
* Convenience method for calling <code>remoteConfig.getValue(key).asBoolean()</code>.
1531+
*/
1532+
getBoolean(key: string): boolean;
1533+
1534+
/**
1535+
* Gets the value for the given key as a number.
1536+
*
1537+
* Convenience method for calling <code>remoteConfig.getValue(key).asNumber()</code>.
1538+
*/
1539+
getNumber(key: string): number;
1540+
1541+
/**
1542+
* Gets the value for the given key as a String.
1543+
*
1544+
* Convenience method for calling <code>remoteConfig.getValue(key).asString()</code>.
1545+
*/
1546+
getString(key: string): string;
1547+
1548+
/**
1549+
* Gets the {@link Value} for the given key.
1550+
*/
1551+
getValue(key: string): Value;
1552+
1553+
/**
1554+
* Defines the log level to use.
1555+
*/
1556+
setLogLevel(logLevel: LogLevel): void;
1557+
}
1558+
1559+
/**
1560+
* Indicates the source of a value.
1561+
*
1562+
* <ul>
1563+
* <li>"static" indicates the value was defined by a static constant.</li>
1564+
* <li>"default" indicates the value was defined by default config.</li>
1565+
* <li>"remote" indicates the value was defined by fetched config.</li>
1566+
* </ul>
1567+
*/
1568+
export type ValueSource = 'static' | 'default' | 'remote';
1569+
1570+
/**
1571+
* Wraps a value with metadata and type-safe getters.
1572+
*/
1573+
export interface Value {
1574+
/**
1575+
* Gets the value as a boolean.
1576+
*
1577+
* The following values (case insensitive) are interpreted as true:
1578+
* "1", "true", "t", "yes", "y", "on". Other values are interpreted as false.
1579+
*/
1580+
asBoolean(): boolean;
1581+
1582+
/**
1583+
* Gets the value as a number. Comparable to calling <code>Number(value) || 0</code>.
1584+
*/
1585+
asNumber(): number;
1586+
1587+
/**
1588+
* Gets the value as a string.
1589+
*/
1590+
asString(): string;
1591+
1592+
/**
1593+
* Gets the {@link ValueSource} for the given key.
1594+
*/
1595+
getSource(): ValueSource;
1596+
}
1597+
1598+
/**
1599+
* Defines configuration options for the Remote Config SDK.
1600+
*/
1601+
export interface Settings {
1602+
/**
1603+
* Defines the maximum age in milliseconds of an entry in the config cache before
1604+
* it is considered stale. Defaults to 43200000 (Twelve hours).
1605+
*/
1606+
minimumFetchIntervalMillis: number;
1607+
1608+
/**
1609+
* Defines the maximum amount of milliseconds to wait for a response when fetching
1610+
* configuration from the Remote Config server. Defaults to 60000 (One minute).
1611+
*/
1612+
fetchTimeoutMillis: number;
1613+
}
1614+
1615+
/**
1616+
* Summarizes the outcome of the last attempt to fetch config from the Firebase Remote Config server.
1617+
*
1618+
* <ul>
1619+
* <li>"no-fetch-yet" indicates the {@link RemoteConfig} instance has not yet attempted
1620+
* to fetch config, or that SDK initialization is incomplete.</li>
1621+
* <li>"success" indicates the last attempt succeeded.</li>
1622+
* <li>"failure" indicates the last attempt failed.</li>
1623+
* <li>"throttle" indicates the last attempt was rate-limited.</li>
1624+
* </ul>
1625+
*/
1626+
export type FetchStatus = 'no-fetch-yet' | 'success' | 'failure' | 'throttle';
1627+
1628+
/**
1629+
* Defines levels of Remote Config logging.
1630+
*/
1631+
export type LogLevel = 'debug' | 'error' | 'silent';
1632+
}
1633+
14361634
/**
14371635
* @webonly
14381636
*/

packages/firebase/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"firebase",
1313
"realtime",
1414
"storage",
15-
"performance"
15+
"performance",
16+
"remote-config"
1617
],
1718
"files": [
1819
"**/dist/",
@@ -48,6 +49,7 @@
4849
"@firebase/polyfill": "0.3.22",
4950
"@firebase/storage": "0.3.12",
5051
"@firebase/performance": "0.2.19",
52+
"@firebase/remote-config": "0.1.0",
5153
"@firebase/util": "0.2.28"
5254
},
5355
"devDependencies": {
@@ -73,6 +75,7 @@
7375
"installations",
7476
"messaging",
7577
"storage",
76-
"performance"
78+
"performance",
79+
"remote-config"
7780
]
7881
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2017 Google Inc.
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+
import '@firebase/remote-config';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "firebase/remote-config",
3+
"main": "dist/index.cjs.js",
4+
"module": "dist/index.esm.js",
5+
"typings": "../empty-import.d.ts"
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @firebase/remoteconfig-types
2+
3+
**This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.**

0 commit comments

Comments
 (0)