Skip to content

Commit fc669e9

Browse files
committed
fix compat type issues
1 parent 85f73ab commit fc669e9

File tree

4 files changed

+135
-9
lines changed

4 files changed

+135
-9
lines changed

common/api-review/app-check-exp.api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export function onTokenChanged(appCheckInstance: AppCheck, observer: PartialObse
7070
// @public
7171
export function onTokenChanged(appCheckInstance: AppCheck, onNext: (tokenResult: AppCheckTokenResult) => void, onError?: (error: Error) => void, onCompletion?: () => void): Unsubscribe;
7272

73+
export { PartialObserver }
74+
7375
// @public
7476
export class ReCaptchaV3Provider implements AppCheckProvider {
7577
constructor(_siteKey: string);
@@ -82,6 +84,8 @@ export class ReCaptchaV3Provider implements AppCheckProvider {
8284
// @public
8385
export function setTokenAutoRefreshEnabled(appCheckInstance: AppCheck, isTokenAutoRefreshEnabled: boolean): void;
8486

87+
export { Unsubscribe }
88+
8589

8690
// (No @packageDocumentation comment for this package)
8791

packages-exp/app-check-compat/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1515
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1616
"build": "rollup -c",
17-
"build:release": "rollup -c rollup.config.release.js",
17+
"build:release": "rollup -c rollup.config.release.js && yarn add-compat-overloads",
1818
"build:deps": "lerna run --scope @firebase/app-check-compat --include-dependencies build",
1919
"dev": "rollup -c -w",
2020
"test": "run-p lint test:browser",
2121
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:browser",
22-
"test:browser": "karma start --single-run --nocache"
22+
"test:browser": "karma start --single-run --nocache",
23+
"add-compat-overloads": "ts-node-script ../../scripts/exp/create-overloads.ts -i ../app-check-exp/dist/app-check-exp-public.d.ts -o dist/src/index.d.ts -a -r AppCheck:FirebaseAppCheck -r FirebaseApp:FirebaseAppCompat --moduleToEnhance @firebase/app-check"
2324
},
2425
"peerDependencies": {
2526
"@firebase/app-compat": "0.x"

packages-exp/app-check-exp/src/api.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ declare module '@firebase/component' {
4141
}
4242

4343
export { ReCaptchaV3Provider, CustomProvider } from './providers';
44+
export { PartialObserver, Unsubscribe }; // from @firebase/util
4445

4546
/**
4647
* Activate App Check for the given app. Can be called only once per app.
@@ -214,18 +215,18 @@ export function onTokenChanged(
214215
let nextFn: NextFn<AppCheckTokenResult> = () => {};
215216
let errorFn: ErrorFn = () => {};
216217
if ((onNextOrObserver as PartialObserver<AppCheckTokenResult>).next != null) {
217-
nextFn = (onNextOrObserver as PartialObserver<AppCheckTokenResult>).next!.bind(
218-
onNextOrObserver
219-
);
218+
nextFn = (
219+
onNextOrObserver as PartialObserver<AppCheckTokenResult>
220+
).next!.bind(onNextOrObserver);
220221
} else {
221222
nextFn = onNextOrObserver as NextFn<AppCheckTokenResult>;
222223
}
223224
if (
224225
(onNextOrObserver as PartialObserver<AppCheckTokenResult>).error != null
225226
) {
226-
errorFn = (onNextOrObserver as PartialObserver<AppCheckTokenResult>).error!.bind(
227-
onNextOrObserver
228-
);
227+
errorFn = (
228+
onNextOrObserver as PartialObserver<AppCheckTokenResult>
229+
).error!.bind(onNextOrObserver);
229230
} else if (onError) {
230231
errorFn = onError;
231232
}

packages-exp/firebase-exp/compat/index.d.ts

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,8 @@ declare namespace firebase {
12741274
* If not passed, uses the default app.
12751275
*/
12761276
function analytics(app?: firebase.app.App): firebase.analytics.Analytics;
1277+
1278+
function appCheck(app?: firebase.app.App): firebase.appCheck.AppCheck;
12771279
}
12781280

12791281
declare namespace firebase.app {
@@ -1471,6 +1473,123 @@ declare namespace firebase.app {
14711473
* ```
14721474
*/
14731475
analytics(): firebase.analytics.Analytics;
1476+
appCheck(): firebase.appCheck.AppCheck;
1477+
}
1478+
}
1479+
1480+
declare namespace firebase.appCheck {
1481+
/**
1482+
* Result returned by
1483+
* {@link firebase.appCheck.AppCheck.getToken `firebase.appCheck().getToken()`}.
1484+
*/
1485+
interface AppCheckTokenResult {
1486+
token: string;
1487+
}
1488+
/**
1489+
* The Firebase AppCheck service interface.
1490+
*
1491+
* Do not call this constructor directly. Instead, use
1492+
* {@link firebase.appCheck `firebase.appCheck()`}.
1493+
*/
1494+
export interface AppCheck {
1495+
/**
1496+
* Activate AppCheck
1497+
* @param siteKeyOrProvider reCAPTCHA v3 site key (public key) or
1498+
* custom token provider.
1499+
* @param isTokenAutoRefreshEnabled If true, the SDK automatically
1500+
* refreshes App Check tokens as needed. If undefined, defaults to the
1501+
* value of `app.automaticDataCollectionEnabled`, which defaults to
1502+
* false and can be set in the app config.
1503+
*/
1504+
activate(
1505+
siteKeyOrProvider: string | AppCheckProvider,
1506+
isTokenAutoRefreshEnabled?: boolean
1507+
): void;
1508+
1509+
/**
1510+
*
1511+
* @param isTokenAutoRefreshEnabled If true, the SDK automatically
1512+
* refreshes App Check tokens as needed. This overrides any value set
1513+
* during `activate()`.
1514+
*/
1515+
setTokenAutoRefreshEnabled(isTokenAutoRefreshEnabled: boolean): void;
1516+
/**
1517+
* Get the current App Check token. Attaches to the most recent
1518+
* in-flight request if one is present. Returns null if no token
1519+
* is present and no token requests are in-flight.
1520+
*
1521+
* @param forceRefresh - If true, will always try to fetch a fresh token.
1522+
* If false, will use a cached token if found in storage.
1523+
*/
1524+
getToken(
1525+
forceRefresh?: boolean
1526+
): Promise<firebase.appCheck.AppCheckTokenResult>;
1527+
1528+
/**
1529+
* Registers a listener to changes in the token state. There can be more
1530+
* than one listener registered at the same time for one or more
1531+
* App Check instances. The listeners call back on the UI thread whenever
1532+
* the current token associated with this App Check instance changes.
1533+
*
1534+
* @param observer An object with `next`, `error`, and `complete`
1535+
* properties. `next` is called with an
1536+
* {@link firebase.appCheck.AppCheckTokenResult `AppCheckTokenResult`}
1537+
* whenever the token changes. `error` is optional and is called if an
1538+
* error is thrown by the listener (the `next` function). `complete`
1539+
* is unused, as the token stream is unending.
1540+
*
1541+
* @returns A function that unsubscribes this listener.
1542+
*/
1543+
onTokenChanged(observer: {
1544+
next: (tokenResult: firebase.appCheck.AppCheckTokenResult) => void;
1545+
error?: (error: Error) => void;
1546+
complete?: () => void;
1547+
}): Unsubscribe;
1548+
1549+
/**
1550+
* Registers a listener to changes in the token state. There can be more
1551+
* than one listener registered at the same time for one or more
1552+
* App Check instances. The listeners call back on the UI thread whenever
1553+
* the current token associated with this App Check instance changes.
1554+
*
1555+
* @param onNext When the token changes, this function is called with aa
1556+
* {@link firebase.appCheck.AppCheckTokenResult `AppCheckTokenResult`}.
1557+
* @param onError Optional. Called if there is an error thrown by the
1558+
* listener (the `onNext` function).
1559+
* @param onCompletion Currently unused, as the token stream is unending.
1560+
* @returns A function that unsubscribes this listener.
1561+
*/
1562+
onTokenChanged(
1563+
onNext: (tokenResult: firebase.appCheck.AppCheckTokenResult) => void,
1564+
onError?: (error: Error) => void,
1565+
onCompletion?: () => void
1566+
): Unsubscribe;
1567+
}
1568+
1569+
/**
1570+
* An App Check provider. This can be either the built-in reCAPTCHA
1571+
* provider or a custom provider. For more on custom providers, see
1572+
* https://firebase.google.com/docs/app-check/web-custom-provider
1573+
*/
1574+
interface AppCheckProvider {
1575+
/**
1576+
* Returns an AppCheck token.
1577+
*/
1578+
getToken(): Promise<AppCheckToken>;
1579+
}
1580+
1581+
/**
1582+
* The token returned from an {@link firebase.appCheck.AppCheckProvider `AppCheckProvider`}.
1583+
*/
1584+
interface AppCheckToken {
1585+
/**
1586+
* The token string in JWT format.
1587+
*/
1588+
readonly token: string;
1589+
/**
1590+
* The local timestamp after which the token will expire.
1591+
*/
1592+
readonly expireTimeMillis: number;
14741593
}
14751594
}
14761595

@@ -4419,7 +4538,8 @@ declare namespace firebase.auth {
44194538
* @hidden
44204539
*/
44214540
class RecaptchaVerifier_Instance
4422-
implements firebase.auth.ApplicationVerifier {
4541+
implements firebase.auth.ApplicationVerifier
4542+
{
44234543
constructor(
44244544
container: any | string,
44254545
parameters?: Object | null,

0 commit comments

Comments
 (0)