Skip to content

Commit 8e36c93

Browse files
committed
rewrite the internal interface
1 parent 3d3d36c commit 8e36c93

File tree

3 files changed

+86
-21
lines changed

3 files changed

+86
-21
lines changed

packages-exp/installations-exp/src/functions/config.ts

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,43 @@
1717

1818
import { _registerComponent } from '@firebase/app-exp';
1919
import { _FirebaseService } from '@firebase/app-types-exp';
20-
import { Component, ComponentType } from '@firebase/component';
21-
import { getInstallations, deleteInstallations } from '../api/index';
20+
import {
21+
Component,
22+
ComponentType,
23+
InstanceFactory,
24+
ComponentContainer
25+
} from '@firebase/component';
26+
import {
27+
getInstallations,
28+
deleteInstallations,
29+
getId,
30+
getToken,
31+
onIdChange
32+
} from '../api/index';
33+
import { FirebaseInstallationsInternal } from '../interfaces/installation-internal';
2234

23-
export function registerInstallations(): void {
24-
const installationsName = 'installations-exp';
35+
const installationsName = 'installations-exp';
2536

26-
_registerComponent(
27-
new Component(
28-
installationsName,
29-
container => {
30-
const app = container.getProvider('app-exp').getImmediate();
37+
const factory: InstanceFactory<'installations-exp'> = (
38+
container: ComponentContainer
39+
) => {
40+
const app = container.getProvider('app-exp').getImmediate();
3141

32-
// Throws if app isn't configured properly.
33-
const installations = getInstallations(app);
34-
const installationsService: _FirebaseService = {
35-
app,
36-
delete: () => deleteInstallations(installations)
37-
};
42+
// Throws if app isn't configured properly.
43+
const installations = getInstallations(app);
44+
const installationsService: FirebaseInstallationsInternal = {
45+
app,
46+
getId: () => getId(installations),
47+
getToken: (forceRefresh?: boolean) => getToken(installations, forceRefresh),
48+
delete: () => deleteInstallations(installations),
49+
onIdChange: (callback: (fid: string) => void) =>
50+
onIdChange(installations, callback)
51+
};
52+
return installationsService;
53+
};
3854

39-
return installationsService;
40-
},
41-
ComponentType.PUBLIC
42-
)
55+
export function registerInstallations(): void {
56+
_registerComponent(
57+
new Component(installationsName, factory, ComponentType.PUBLIC)
4358
);
4459
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
18+
import { _FirebaseService, FirebaseApp } from '@firebase/app-types-exp';
19+
20+
/**
21+
* An interface for Firebase internal SDKs use only.
22+
*/
23+
export interface FirebaseInstallationsInternal extends _FirebaseService {
24+
/**
25+
* FirebaseApp instance which carries Firebase app configurations.
26+
*/
27+
app: FirebaseApp;
28+
29+
/**
30+
* Creates a Firebase Installation if there isn't one for the app and
31+
* returns the Installation ID.
32+
*/
33+
getId(): Promise<string>;
34+
35+
/**
36+
* Returns an Authentication Token for the current Firebase Installation.
37+
*/
38+
getToken(forceRefresh?: boolean): Promise<string>;
39+
40+
/**
41+
* Deletes the Firebase Installation and all associated data.
42+
*/
43+
delete(): Promise<void>;
44+
45+
/**
46+
* Sets a new callback that will get called when Installlation ID changes.
47+
* Returns an unsubscribe function that will remove the callback when called.
48+
*/
49+
onIdChange(callback: (installationId: string) => void): () => void;
50+
}

packages-exp/installations-types-exp/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { Provider } from '@firebase/component';
19-
import { _FirebaseService } from '@firebase/app-types-exp';
19+
import { FirebaseInstallationsInternal } from '../installations-exp/src/interfaces/installation-internal';
2020

2121
export interface FirebaseInstallations {
2222
/**
@@ -52,6 +52,6 @@ export type FirebaseInstallationsName = 'installations-exp';
5252

5353
declare module '@firebase/component' {
5454
interface NameServiceMapping {
55-
'installations-exp': _FirebaseService;
55+
'installations-exp': FirebaseInstallationsInternal;
5656
}
5757
}

0 commit comments

Comments
 (0)