@firebase/app 0.7.17 → 0.7.18-20222320822
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/CHANGELOG.md +6 -0
- package/dist/app/src/errors.d.ts +17 -1
- package/dist/app/src/heartbeatService.d.ts +84 -0
- package/dist/app/src/heartbeatService.test.d.ts +23 -0
- package/dist/app/src/indexeddb.d.ts +21 -0
- package/dist/app/src/public-types.d.ts +2 -1
- package/dist/app/src/types.d.ts +33 -0
- package/dist/esm/app/src/errors.d.ts +17 -1
- package/dist/esm/app/src/heartbeatService.d.ts +84 -0
- package/dist/esm/app/src/heartbeatService.test.d.ts +23 -0
- package/dist/esm/app/src/indexeddb.d.ts +21 -0
- package/dist/esm/app/src/public-types.d.ts +2 -1
- package/dist/esm/app/src/types.d.ts +33 -0
- package/dist/esm/index.esm2017.js +339 -4
- package/dist/esm/index.esm2017.js.map +1 -1
- package/dist/esm/index.esm5.js +464 -4
- package/dist/esm/index.esm5.js.map +1 -1
- package/dist/index.cjs.js +462 -2
- package/dist/index.cjs.js.map +1 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @firebase/app
|
|
2
2
|
|
|
3
|
+
## 0.7.18-20222320822
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`1588990b7`](https://github.com/firebase/firebase-js-sdk/commit/1588990b7fb06b6fa545c0d478663e137ec0ea07) [#5723](https://github.com/firebase/firebase-js-sdk/pull/5723) - Add heartbeat controller for platform logging.
|
|
8
|
+
|
|
3
9
|
## 0.7.17
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/app/src/errors.d.ts
CHANGED
|
@@ -21,7 +21,11 @@ export declare const enum AppError {
|
|
|
21
21
|
DUPLICATE_APP = "duplicate-app",
|
|
22
22
|
APP_DELETED = "app-deleted",
|
|
23
23
|
INVALID_APP_ARGUMENT = "invalid-app-argument",
|
|
24
|
-
INVALID_LOG_ARGUMENT = "invalid-log-argument"
|
|
24
|
+
INVALID_LOG_ARGUMENT = "invalid-log-argument",
|
|
25
|
+
STORAGE_OPEN = "storage-open",
|
|
26
|
+
STORAGE_GET = "storage-get",
|
|
27
|
+
STORAGE_WRITE = "storage-set",
|
|
28
|
+
STORAGE_DELETE = "storage-delete"
|
|
25
29
|
}
|
|
26
30
|
interface ErrorParams {
|
|
27
31
|
[AppError.NO_APP]: {
|
|
@@ -39,6 +43,18 @@ interface ErrorParams {
|
|
|
39
43
|
[AppError.INVALID_APP_ARGUMENT]: {
|
|
40
44
|
appName: string;
|
|
41
45
|
};
|
|
46
|
+
[AppError.STORAGE_OPEN]: {
|
|
47
|
+
originalErrorMessage?: string;
|
|
48
|
+
};
|
|
49
|
+
[AppError.STORAGE_GET]: {
|
|
50
|
+
originalErrorMessage?: string;
|
|
51
|
+
};
|
|
52
|
+
[AppError.STORAGE_WRITE]: {
|
|
53
|
+
originalErrorMessage?: string;
|
|
54
|
+
};
|
|
55
|
+
[AppError.STORAGE_DELETE]: {
|
|
56
|
+
originalErrorMessage?: string;
|
|
57
|
+
};
|
|
42
58
|
}
|
|
43
59
|
export declare const ERROR_FACTORY: ErrorFactory<AppError, ErrorParams>;
|
|
44
60
|
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2021 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 { ComponentContainer } from '@firebase/component';
|
|
18
|
+
import { FirebaseApp } from './public-types';
|
|
19
|
+
import { HeartbeatsByUserAgent, HeartbeatService, HeartbeatStorage, SingleDateHeartbeat } from './types';
|
|
20
|
+
export declare class HeartbeatServiceImpl implements HeartbeatService {
|
|
21
|
+
private readonly container;
|
|
22
|
+
/**
|
|
23
|
+
* The persistence layer for heartbeats
|
|
24
|
+
* Leave public for easier testing.
|
|
25
|
+
*/
|
|
26
|
+
_storage: HeartbeatStorageImpl;
|
|
27
|
+
/**
|
|
28
|
+
* In-memory cache for heartbeats, used by getHeartbeatsHeader() to generate
|
|
29
|
+
* the header string.
|
|
30
|
+
* Stores one record per date. This will be consolidated into the standard
|
|
31
|
+
* format of one record per user agent string before being sent as a header.
|
|
32
|
+
* Populated from indexedDB when the controller is instantiated and should
|
|
33
|
+
* be kept in sync with indexedDB.
|
|
34
|
+
* Leave public for easier testing.
|
|
35
|
+
*/
|
|
36
|
+
_heartbeatsCache: SingleDateHeartbeat[] | null;
|
|
37
|
+
/**
|
|
38
|
+
* the initialization promise for populating heartbeatCache.
|
|
39
|
+
* If getHeartbeatsHeader() is called before the promise resolves
|
|
40
|
+
* (hearbeatsCache == null), it should wait for this promise
|
|
41
|
+
* Leave public for easier testing.
|
|
42
|
+
*/
|
|
43
|
+
_heartbeatsCachePromise: Promise<SingleDateHeartbeat[]>;
|
|
44
|
+
constructor(container: ComponentContainer);
|
|
45
|
+
/**
|
|
46
|
+
* Called to report a heartbeat. The function will generate
|
|
47
|
+
* a HeartbeatsByUserAgent object, update heartbeatsCache, and persist it
|
|
48
|
+
* to IndexedDB.
|
|
49
|
+
* Note that we only store one heartbeat per day. So if a heartbeat for today is
|
|
50
|
+
* already logged, subsequent calls to this function in the same day will be ignored.
|
|
51
|
+
*/
|
|
52
|
+
triggerHeartbeat(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Returns a base64 encoded string which can be attached to the heartbeat-specific header directly.
|
|
55
|
+
* It also clears all heartbeats from memory as well as in IndexedDB.
|
|
56
|
+
*
|
|
57
|
+
* NOTE: It will read heartbeats from the heartbeatsCache, instead of from indexedDB to reduce latency
|
|
58
|
+
*/
|
|
59
|
+
getHeartbeatsHeader(): Promise<string>;
|
|
60
|
+
}
|
|
61
|
+
export declare function extractHeartbeatsForHeader(heartbeatsCache: SingleDateHeartbeat[], maxSize?: number): {
|
|
62
|
+
heartbeatsToSend: HeartbeatsByUserAgent[];
|
|
63
|
+
unsentEntries: SingleDateHeartbeat[];
|
|
64
|
+
};
|
|
65
|
+
export declare class HeartbeatStorageImpl implements HeartbeatStorage {
|
|
66
|
+
app: FirebaseApp;
|
|
67
|
+
private _canUseIndexedDBPromise;
|
|
68
|
+
constructor(app: FirebaseApp);
|
|
69
|
+
runIndexedDBEnvironmentCheck(): Promise<boolean>;
|
|
70
|
+
/**
|
|
71
|
+
* Read all heartbeats.
|
|
72
|
+
*/
|
|
73
|
+
read(): Promise<SingleDateHeartbeat[]>;
|
|
74
|
+
overwrite(heartbeats: SingleDateHeartbeat[]): Promise<void>;
|
|
75
|
+
add(heartbeats: SingleDateHeartbeat[]): Promise<void>;
|
|
76
|
+
delete(heartbeats: SingleDateHeartbeat[]): Promise<void>;
|
|
77
|
+
deleteAll(): Promise<void>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Calculate bytes of a HeartbeatsByUserAgent array after being wrapped
|
|
81
|
+
* in a platform logging header JSON object, stringified, and converted
|
|
82
|
+
* to base 64.
|
|
83
|
+
*/
|
|
84
|
+
export declare function countBytes(heartbeatsCache: HeartbeatsByUserAgent[]): number;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2021 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 '../test/setup';
|
|
18
|
+
import { PlatformLoggerService } from './types';
|
|
19
|
+
declare module '@firebase/component' {
|
|
20
|
+
interface NameServiceMapping {
|
|
21
|
+
'platform-logger': PlatformLoggerService;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2021 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 './public-types';
|
|
18
|
+
import { HeartbeatsInIndexedDB } from './types';
|
|
19
|
+
export declare function readHeartbeatsFromIndexedDB(app: FirebaseApp): Promise<HeartbeatsInIndexedDB | undefined>;
|
|
20
|
+
export declare function writeHeartbeatsToIndexedDB(app: FirebaseApp, heartbeatObject: HeartbeatsInIndexedDB): Promise<void>;
|
|
21
|
+
export declare function deleteHeartbeatsFromIndexedDB(app: FirebaseApp): Promise<void>;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import { ComponentContainer } from '@firebase/component';
|
|
18
|
-
import { PlatformLoggerService, VersionService } from './types';
|
|
18
|
+
import { PlatformLoggerService, VersionService, HeartbeatService } from './types';
|
|
19
19
|
/**
|
|
20
20
|
* A {@link @firebase/app#FirebaseApp} holds the initialization information for a collection of
|
|
21
21
|
* services.
|
|
@@ -151,6 +151,7 @@ declare module '@firebase/component' {
|
|
|
151
151
|
interface NameServiceMapping {
|
|
152
152
|
'app': FirebaseApp;
|
|
153
153
|
'app-version': VersionService;
|
|
154
|
+
'heartbeat': HeartbeatService;
|
|
154
155
|
'platform-logger': PlatformLoggerService;
|
|
155
156
|
}
|
|
156
157
|
}
|
package/dist/app/src/types.d.ts
CHANGED
|
@@ -21,3 +21,36 @@ export interface VersionService {
|
|
|
21
21
|
export interface PlatformLoggerService {
|
|
22
22
|
getPlatformInfoString(): string;
|
|
23
23
|
}
|
|
24
|
+
export interface HeartbeatService {
|
|
25
|
+
/**
|
|
26
|
+
* Called to report a heartbeat. The function will generate
|
|
27
|
+
* a HeartbeatsByUserAgent object, update heartbeatsCache, and persist it
|
|
28
|
+
* to IndexedDB.
|
|
29
|
+
* Note that we only store one heartbeat per day. So if a heartbeat for today is
|
|
30
|
+
* already logged, subsequent calls to this function in the same day will be ignored.
|
|
31
|
+
*/
|
|
32
|
+
triggerHeartbeat(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Returns a base64 encoded string which can be attached to the heartbeat-specific header directly.
|
|
35
|
+
* It also clears all heartbeats from memory as well as in IndexedDB.
|
|
36
|
+
*/
|
|
37
|
+
getHeartbeatsHeader(): Promise<string>;
|
|
38
|
+
}
|
|
39
|
+
export interface HeartbeatsByUserAgent {
|
|
40
|
+
userAgent: string;
|
|
41
|
+
dates: string[];
|
|
42
|
+
}
|
|
43
|
+
export interface SingleDateHeartbeat {
|
|
44
|
+
userAgent: string;
|
|
45
|
+
date: string;
|
|
46
|
+
}
|
|
47
|
+
export interface HeartbeatStorage {
|
|
48
|
+
overwrite(heartbeats: SingleDateHeartbeat[]): Promise<void>;
|
|
49
|
+
add(heartbeats: SingleDateHeartbeat[]): Promise<void>;
|
|
50
|
+
delete(heartbeats: SingleDateHeartbeat[]): Promise<void>;
|
|
51
|
+
deleteAll(): Promise<void>;
|
|
52
|
+
read(): Promise<SingleDateHeartbeat[]>;
|
|
53
|
+
}
|
|
54
|
+
export interface HeartbeatsInIndexedDB {
|
|
55
|
+
heartbeats: SingleDateHeartbeat[];
|
|
56
|
+
}
|
|
@@ -21,7 +21,11 @@ export declare const enum AppError {
|
|
|
21
21
|
DUPLICATE_APP = "duplicate-app",
|
|
22
22
|
APP_DELETED = "app-deleted",
|
|
23
23
|
INVALID_APP_ARGUMENT = "invalid-app-argument",
|
|
24
|
-
INVALID_LOG_ARGUMENT = "invalid-log-argument"
|
|
24
|
+
INVALID_LOG_ARGUMENT = "invalid-log-argument",
|
|
25
|
+
STORAGE_OPEN = "storage-open",
|
|
26
|
+
STORAGE_GET = "storage-get",
|
|
27
|
+
STORAGE_WRITE = "storage-set",
|
|
28
|
+
STORAGE_DELETE = "storage-delete"
|
|
25
29
|
}
|
|
26
30
|
interface ErrorParams {
|
|
27
31
|
[AppError.NO_APP]: {
|
|
@@ -39,6 +43,18 @@ interface ErrorParams {
|
|
|
39
43
|
[AppError.INVALID_APP_ARGUMENT]: {
|
|
40
44
|
appName: string;
|
|
41
45
|
};
|
|
46
|
+
[AppError.STORAGE_OPEN]: {
|
|
47
|
+
originalErrorMessage?: string;
|
|
48
|
+
};
|
|
49
|
+
[AppError.STORAGE_GET]: {
|
|
50
|
+
originalErrorMessage?: string;
|
|
51
|
+
};
|
|
52
|
+
[AppError.STORAGE_WRITE]: {
|
|
53
|
+
originalErrorMessage?: string;
|
|
54
|
+
};
|
|
55
|
+
[AppError.STORAGE_DELETE]: {
|
|
56
|
+
originalErrorMessage?: string;
|
|
57
|
+
};
|
|
42
58
|
}
|
|
43
59
|
export declare const ERROR_FACTORY: ErrorFactory<AppError, ErrorParams>;
|
|
44
60
|
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2021 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 { ComponentContainer } from '@firebase/component';
|
|
18
|
+
import { FirebaseApp } from './public-types';
|
|
19
|
+
import { HeartbeatsByUserAgent, HeartbeatService, HeartbeatStorage, SingleDateHeartbeat } from './types';
|
|
20
|
+
export declare class HeartbeatServiceImpl implements HeartbeatService {
|
|
21
|
+
private readonly container;
|
|
22
|
+
/**
|
|
23
|
+
* The persistence layer for heartbeats
|
|
24
|
+
* Leave public for easier testing.
|
|
25
|
+
*/
|
|
26
|
+
_storage: HeartbeatStorageImpl;
|
|
27
|
+
/**
|
|
28
|
+
* In-memory cache for heartbeats, used by getHeartbeatsHeader() to generate
|
|
29
|
+
* the header string.
|
|
30
|
+
* Stores one record per date. This will be consolidated into the standard
|
|
31
|
+
* format of one record per user agent string before being sent as a header.
|
|
32
|
+
* Populated from indexedDB when the controller is instantiated and should
|
|
33
|
+
* be kept in sync with indexedDB.
|
|
34
|
+
* Leave public for easier testing.
|
|
35
|
+
*/
|
|
36
|
+
_heartbeatsCache: SingleDateHeartbeat[] | null;
|
|
37
|
+
/**
|
|
38
|
+
* the initialization promise for populating heartbeatCache.
|
|
39
|
+
* If getHeartbeatsHeader() is called before the promise resolves
|
|
40
|
+
* (hearbeatsCache == null), it should wait for this promise
|
|
41
|
+
* Leave public for easier testing.
|
|
42
|
+
*/
|
|
43
|
+
_heartbeatsCachePromise: Promise<SingleDateHeartbeat[]>;
|
|
44
|
+
constructor(container: ComponentContainer);
|
|
45
|
+
/**
|
|
46
|
+
* Called to report a heartbeat. The function will generate
|
|
47
|
+
* a HeartbeatsByUserAgent object, update heartbeatsCache, and persist it
|
|
48
|
+
* to IndexedDB.
|
|
49
|
+
* Note that we only store one heartbeat per day. So if a heartbeat for today is
|
|
50
|
+
* already logged, subsequent calls to this function in the same day will be ignored.
|
|
51
|
+
*/
|
|
52
|
+
triggerHeartbeat(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Returns a base64 encoded string which can be attached to the heartbeat-specific header directly.
|
|
55
|
+
* It also clears all heartbeats from memory as well as in IndexedDB.
|
|
56
|
+
*
|
|
57
|
+
* NOTE: It will read heartbeats from the heartbeatsCache, instead of from indexedDB to reduce latency
|
|
58
|
+
*/
|
|
59
|
+
getHeartbeatsHeader(): Promise<string>;
|
|
60
|
+
}
|
|
61
|
+
export declare function extractHeartbeatsForHeader(heartbeatsCache: SingleDateHeartbeat[], maxSize?: number): {
|
|
62
|
+
heartbeatsToSend: HeartbeatsByUserAgent[];
|
|
63
|
+
unsentEntries: SingleDateHeartbeat[];
|
|
64
|
+
};
|
|
65
|
+
export declare class HeartbeatStorageImpl implements HeartbeatStorage {
|
|
66
|
+
app: FirebaseApp;
|
|
67
|
+
private _canUseIndexedDBPromise;
|
|
68
|
+
constructor(app: FirebaseApp);
|
|
69
|
+
runIndexedDBEnvironmentCheck(): Promise<boolean>;
|
|
70
|
+
/**
|
|
71
|
+
* Read all heartbeats.
|
|
72
|
+
*/
|
|
73
|
+
read(): Promise<SingleDateHeartbeat[]>;
|
|
74
|
+
overwrite(heartbeats: SingleDateHeartbeat[]): Promise<void>;
|
|
75
|
+
add(heartbeats: SingleDateHeartbeat[]): Promise<void>;
|
|
76
|
+
delete(heartbeats: SingleDateHeartbeat[]): Promise<void>;
|
|
77
|
+
deleteAll(): Promise<void>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Calculate bytes of a HeartbeatsByUserAgent array after being wrapped
|
|
81
|
+
* in a platform logging header JSON object, stringified, and converted
|
|
82
|
+
* to base 64.
|
|
83
|
+
*/
|
|
84
|
+
export declare function countBytes(heartbeatsCache: HeartbeatsByUserAgent[]): number;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2021 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 '../test/setup';
|
|
18
|
+
import { PlatformLoggerService } from './types';
|
|
19
|
+
declare module '@firebase/component' {
|
|
20
|
+
interface NameServiceMapping {
|
|
21
|
+
'platform-logger': PlatformLoggerService;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2021 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 './public-types';
|
|
18
|
+
import { HeartbeatsInIndexedDB } from './types';
|
|
19
|
+
export declare function readHeartbeatsFromIndexedDB(app: FirebaseApp): Promise<HeartbeatsInIndexedDB | undefined>;
|
|
20
|
+
export declare function writeHeartbeatsToIndexedDB(app: FirebaseApp, heartbeatObject: HeartbeatsInIndexedDB): Promise<void>;
|
|
21
|
+
export declare function deleteHeartbeatsFromIndexedDB(app: FirebaseApp): Promise<void>;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import { ComponentContainer } from '@firebase/component';
|
|
18
|
-
import { PlatformLoggerService, VersionService } from './types';
|
|
18
|
+
import { PlatformLoggerService, VersionService, HeartbeatService } from './types';
|
|
19
19
|
/**
|
|
20
20
|
* A {@link @firebase/app#FirebaseApp} holds the initialization information for a collection of
|
|
21
21
|
* services.
|
|
@@ -151,6 +151,7 @@ declare module '@firebase/component' {
|
|
|
151
151
|
interface NameServiceMapping {
|
|
152
152
|
'app': FirebaseApp;
|
|
153
153
|
'app-version': VersionService;
|
|
154
|
+
'heartbeat': HeartbeatService;
|
|
154
155
|
'platform-logger': PlatformLoggerService;
|
|
155
156
|
}
|
|
156
157
|
}
|
|
@@ -21,3 +21,36 @@ export interface VersionService {
|
|
|
21
21
|
export interface PlatformLoggerService {
|
|
22
22
|
getPlatformInfoString(): string;
|
|
23
23
|
}
|
|
24
|
+
export interface HeartbeatService {
|
|
25
|
+
/**
|
|
26
|
+
* Called to report a heartbeat. The function will generate
|
|
27
|
+
* a HeartbeatsByUserAgent object, update heartbeatsCache, and persist it
|
|
28
|
+
* to IndexedDB.
|
|
29
|
+
* Note that we only store one heartbeat per day. So if a heartbeat for today is
|
|
30
|
+
* already logged, subsequent calls to this function in the same day will be ignored.
|
|
31
|
+
*/
|
|
32
|
+
triggerHeartbeat(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Returns a base64 encoded string which can be attached to the heartbeat-specific header directly.
|
|
35
|
+
* It also clears all heartbeats from memory as well as in IndexedDB.
|
|
36
|
+
*/
|
|
37
|
+
getHeartbeatsHeader(): Promise<string>;
|
|
38
|
+
}
|
|
39
|
+
export interface HeartbeatsByUserAgent {
|
|
40
|
+
userAgent: string;
|
|
41
|
+
dates: string[];
|
|
42
|
+
}
|
|
43
|
+
export interface SingleDateHeartbeat {
|
|
44
|
+
userAgent: string;
|
|
45
|
+
date: string;
|
|
46
|
+
}
|
|
47
|
+
export interface HeartbeatStorage {
|
|
48
|
+
overwrite(heartbeats: SingleDateHeartbeat[]): Promise<void>;
|
|
49
|
+
add(heartbeats: SingleDateHeartbeat[]): Promise<void>;
|
|
50
|
+
delete(heartbeats: SingleDateHeartbeat[]): Promise<void>;
|
|
51
|
+
deleteAll(): Promise<void>;
|
|
52
|
+
read(): Promise<SingleDateHeartbeat[]>;
|
|
53
|
+
}
|
|
54
|
+
export interface HeartbeatsInIndexedDB {
|
|
55
|
+
heartbeats: SingleDateHeartbeat[];
|
|
56
|
+
}
|