@firebase/app 0.10.13 → 0.10.14
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/dist/esm/index.esm2017.js +4 -4
- package/dist/esm/index.esm2017.js.map +1 -1
- package/dist/index.cjs.js +424 -628
- package/dist/index.cjs.js.map +1 -1
- package/package.json +7 -6
- package/dist/esm/index.esm5.js +0 -1359
- package/dist/esm/index.esm5.js.map +0 -1
package/dist/esm/index.esm5.js
DELETED
|
@@ -1,1359 +0,0 @@
|
|
|
1
|
-
import { Component, ComponentContainer } from '@firebase/component';
|
|
2
|
-
import { __values, __assign, __extends, __awaiter, __generator, __spreadArray, __read } from 'tslib';
|
|
3
|
-
import { Logger, setUserLogHandler, setLogLevel as setLogLevel$1 } from '@firebase/logger';
|
|
4
|
-
import { ErrorFactory, getDefaultAppConfig, deepEqual, isBrowser, isWebWorker, FirebaseError, base64urlEncodeWithoutPadding, isIndexedDBAvailable, validateIndexedDBOpenable } from '@firebase/util';
|
|
5
|
-
export { FirebaseError } from '@firebase/util';
|
|
6
|
-
import { openDB } from 'idb';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @license
|
|
10
|
-
* Copyright 2019 Google LLC
|
|
11
|
-
*
|
|
12
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
-
* you may not use this file except in compliance with the License.
|
|
14
|
-
* You may obtain a copy of the License at
|
|
15
|
-
*
|
|
16
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
-
*
|
|
18
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
-
* See the License for the specific language governing permissions and
|
|
22
|
-
* limitations under the License.
|
|
23
|
-
*/
|
|
24
|
-
var PlatformLoggerServiceImpl = /** @class */ (function () {
|
|
25
|
-
function PlatformLoggerServiceImpl(container) {
|
|
26
|
-
this.container = container;
|
|
27
|
-
}
|
|
28
|
-
// In initial implementation, this will be called by installations on
|
|
29
|
-
// auth token refresh, and installations will send this string.
|
|
30
|
-
PlatformLoggerServiceImpl.prototype.getPlatformInfoString = function () {
|
|
31
|
-
var providers = this.container.getProviders();
|
|
32
|
-
// Loop through providers and get library/version pairs from any that are
|
|
33
|
-
// version components.
|
|
34
|
-
return providers
|
|
35
|
-
.map(function (provider) {
|
|
36
|
-
if (isVersionServiceProvider(provider)) {
|
|
37
|
-
var service = provider.getImmediate();
|
|
38
|
-
return "".concat(service.library, "/").concat(service.version);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
.filter(function (logString) { return logString; })
|
|
45
|
-
.join(' ');
|
|
46
|
-
};
|
|
47
|
-
return PlatformLoggerServiceImpl;
|
|
48
|
-
}());
|
|
49
|
-
/**
|
|
50
|
-
*
|
|
51
|
-
* @param provider check if this provider provides a VersionService
|
|
52
|
-
*
|
|
53
|
-
* NOTE: Using Provider<'app-version'> is a hack to indicate that the provider
|
|
54
|
-
* provides VersionService. The provider is not necessarily a 'app-version'
|
|
55
|
-
* provider.
|
|
56
|
-
*/
|
|
57
|
-
function isVersionServiceProvider(provider) {
|
|
58
|
-
var component = provider.getComponent();
|
|
59
|
-
return (component === null || component === void 0 ? void 0 : component.type) === "VERSION" /* ComponentType.VERSION */;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
var name$q = "@firebase/app";
|
|
63
|
-
var version$1 = "0.10.13";
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @license
|
|
67
|
-
* Copyright 2019 Google LLC
|
|
68
|
-
*
|
|
69
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
70
|
-
* you may not use this file except in compliance with the License.
|
|
71
|
-
* You may obtain a copy of the License at
|
|
72
|
-
*
|
|
73
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
74
|
-
*
|
|
75
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
76
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
77
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
78
|
-
* See the License for the specific language governing permissions and
|
|
79
|
-
* limitations under the License.
|
|
80
|
-
*/
|
|
81
|
-
var logger = new Logger('@firebase/app');
|
|
82
|
-
|
|
83
|
-
var name$p = "@firebase/app-compat";
|
|
84
|
-
|
|
85
|
-
var name$o = "@firebase/analytics-compat";
|
|
86
|
-
|
|
87
|
-
var name$n = "@firebase/analytics";
|
|
88
|
-
|
|
89
|
-
var name$m = "@firebase/app-check-compat";
|
|
90
|
-
|
|
91
|
-
var name$l = "@firebase/app-check";
|
|
92
|
-
|
|
93
|
-
var name$k = "@firebase/auth";
|
|
94
|
-
|
|
95
|
-
var name$j = "@firebase/auth-compat";
|
|
96
|
-
|
|
97
|
-
var name$i = "@firebase/database";
|
|
98
|
-
|
|
99
|
-
var name$h = "@firebase/data-connect";
|
|
100
|
-
|
|
101
|
-
var name$g = "@firebase/database-compat";
|
|
102
|
-
|
|
103
|
-
var name$f = "@firebase/functions";
|
|
104
|
-
|
|
105
|
-
var name$e = "@firebase/functions-compat";
|
|
106
|
-
|
|
107
|
-
var name$d = "@firebase/installations";
|
|
108
|
-
|
|
109
|
-
var name$c = "@firebase/installations-compat";
|
|
110
|
-
|
|
111
|
-
var name$b = "@firebase/messaging";
|
|
112
|
-
|
|
113
|
-
var name$a = "@firebase/messaging-compat";
|
|
114
|
-
|
|
115
|
-
var name$9 = "@firebase/performance";
|
|
116
|
-
|
|
117
|
-
var name$8 = "@firebase/performance-compat";
|
|
118
|
-
|
|
119
|
-
var name$7 = "@firebase/remote-config";
|
|
120
|
-
|
|
121
|
-
var name$6 = "@firebase/remote-config-compat";
|
|
122
|
-
|
|
123
|
-
var name$5 = "@firebase/storage";
|
|
124
|
-
|
|
125
|
-
var name$4 = "@firebase/storage-compat";
|
|
126
|
-
|
|
127
|
-
var name$3 = "@firebase/firestore";
|
|
128
|
-
|
|
129
|
-
var name$2 = "@firebase/vertexai-preview";
|
|
130
|
-
|
|
131
|
-
var name$1 = "@firebase/firestore-compat";
|
|
132
|
-
|
|
133
|
-
var name = "firebase";
|
|
134
|
-
var version = "10.14.1";
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* @license
|
|
138
|
-
* Copyright 2019 Google LLC
|
|
139
|
-
*
|
|
140
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
141
|
-
* you may not use this file except in compliance with the License.
|
|
142
|
-
* You may obtain a copy of the License at
|
|
143
|
-
*
|
|
144
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
145
|
-
*
|
|
146
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
147
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
148
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
149
|
-
* See the License for the specific language governing permissions and
|
|
150
|
-
* limitations under the License.
|
|
151
|
-
*/
|
|
152
|
-
var _a$1;
|
|
153
|
-
/**
|
|
154
|
-
* The default app name
|
|
155
|
-
*
|
|
156
|
-
* @internal
|
|
157
|
-
*/
|
|
158
|
-
var DEFAULT_ENTRY_NAME = '[DEFAULT]';
|
|
159
|
-
var PLATFORM_LOG_STRING = (_a$1 = {},
|
|
160
|
-
_a$1[name$q] = 'fire-core',
|
|
161
|
-
_a$1[name$p] = 'fire-core-compat',
|
|
162
|
-
_a$1[name$n] = 'fire-analytics',
|
|
163
|
-
_a$1[name$o] = 'fire-analytics-compat',
|
|
164
|
-
_a$1[name$l] = 'fire-app-check',
|
|
165
|
-
_a$1[name$m] = 'fire-app-check-compat',
|
|
166
|
-
_a$1[name$k] = 'fire-auth',
|
|
167
|
-
_a$1[name$j] = 'fire-auth-compat',
|
|
168
|
-
_a$1[name$i] = 'fire-rtdb',
|
|
169
|
-
_a$1[name$h] = 'fire-data-connect',
|
|
170
|
-
_a$1[name$g] = 'fire-rtdb-compat',
|
|
171
|
-
_a$1[name$f] = 'fire-fn',
|
|
172
|
-
_a$1[name$e] = 'fire-fn-compat',
|
|
173
|
-
_a$1[name$d] = 'fire-iid',
|
|
174
|
-
_a$1[name$c] = 'fire-iid-compat',
|
|
175
|
-
_a$1[name$b] = 'fire-fcm',
|
|
176
|
-
_a$1[name$a] = 'fire-fcm-compat',
|
|
177
|
-
_a$1[name$9] = 'fire-perf',
|
|
178
|
-
_a$1[name$8] = 'fire-perf-compat',
|
|
179
|
-
_a$1[name$7] = 'fire-rc',
|
|
180
|
-
_a$1[name$6] = 'fire-rc-compat',
|
|
181
|
-
_a$1[name$5] = 'fire-gcs',
|
|
182
|
-
_a$1[name$4] = 'fire-gcs-compat',
|
|
183
|
-
_a$1[name$3] = 'fire-fst',
|
|
184
|
-
_a$1[name$1] = 'fire-fst-compat',
|
|
185
|
-
_a$1[name$2] = 'fire-vertex',
|
|
186
|
-
_a$1['fire-js'] = 'fire-js',
|
|
187
|
-
_a$1[name] = 'fire-js-all',
|
|
188
|
-
_a$1);
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* @license
|
|
192
|
-
* Copyright 2019 Google LLC
|
|
193
|
-
*
|
|
194
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
195
|
-
* you may not use this file except in compliance with the License.
|
|
196
|
-
* You may obtain a copy of the License at
|
|
197
|
-
*
|
|
198
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
199
|
-
*
|
|
200
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
201
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
202
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
203
|
-
* See the License for the specific language governing permissions and
|
|
204
|
-
* limitations under the License.
|
|
205
|
-
*/
|
|
206
|
-
/**
|
|
207
|
-
* @internal
|
|
208
|
-
*/
|
|
209
|
-
var _apps = new Map();
|
|
210
|
-
/**
|
|
211
|
-
* @internal
|
|
212
|
-
*/
|
|
213
|
-
var _serverApps = new Map();
|
|
214
|
-
/**
|
|
215
|
-
* Registered components.
|
|
216
|
-
*
|
|
217
|
-
* @internal
|
|
218
|
-
*/
|
|
219
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
220
|
-
var _components = new Map();
|
|
221
|
-
/**
|
|
222
|
-
* @param component - the component being added to this app's container
|
|
223
|
-
*
|
|
224
|
-
* @internal
|
|
225
|
-
*/
|
|
226
|
-
function _addComponent(app, component) {
|
|
227
|
-
try {
|
|
228
|
-
app.container.addComponent(component);
|
|
229
|
-
}
|
|
230
|
-
catch (e) {
|
|
231
|
-
logger.debug("Component ".concat(component.name, " failed to register with FirebaseApp ").concat(app.name), e);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
*
|
|
236
|
-
* @internal
|
|
237
|
-
*/
|
|
238
|
-
function _addOrOverwriteComponent(app, component) {
|
|
239
|
-
app.container.addOrOverwriteComponent(component);
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
*
|
|
243
|
-
* @param component - the component to register
|
|
244
|
-
* @returns whether or not the component is registered successfully
|
|
245
|
-
*
|
|
246
|
-
* @internal
|
|
247
|
-
*/
|
|
248
|
-
function _registerComponent(component) {
|
|
249
|
-
var e_1, _a, e_2, _b;
|
|
250
|
-
var componentName = component.name;
|
|
251
|
-
if (_components.has(componentName)) {
|
|
252
|
-
logger.debug("There were multiple attempts to register component ".concat(componentName, "."));
|
|
253
|
-
return false;
|
|
254
|
-
}
|
|
255
|
-
_components.set(componentName, component);
|
|
256
|
-
try {
|
|
257
|
-
// add the component to existing app instances
|
|
258
|
-
for (var _c = __values(_apps.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
259
|
-
var app = _d.value;
|
|
260
|
-
_addComponent(app, component);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
264
|
-
finally {
|
|
265
|
-
try {
|
|
266
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
267
|
-
}
|
|
268
|
-
finally { if (e_1) throw e_1.error; }
|
|
269
|
-
}
|
|
270
|
-
try {
|
|
271
|
-
for (var _e = __values(_serverApps.values()), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
272
|
-
var serverApp = _f.value;
|
|
273
|
-
_addComponent(serverApp, component);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
277
|
-
finally {
|
|
278
|
-
try {
|
|
279
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
280
|
-
}
|
|
281
|
-
finally { if (e_2) throw e_2.error; }
|
|
282
|
-
}
|
|
283
|
-
return true;
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
*
|
|
287
|
-
* @param app - FirebaseApp instance
|
|
288
|
-
* @param name - service name
|
|
289
|
-
*
|
|
290
|
-
* @returns the provider for the service with the matching name
|
|
291
|
-
*
|
|
292
|
-
* @internal
|
|
293
|
-
*/
|
|
294
|
-
function _getProvider(app, name) {
|
|
295
|
-
var heartbeatController = app.container
|
|
296
|
-
.getProvider('heartbeat')
|
|
297
|
-
.getImmediate({ optional: true });
|
|
298
|
-
if (heartbeatController) {
|
|
299
|
-
void heartbeatController.triggerHeartbeat();
|
|
300
|
-
}
|
|
301
|
-
return app.container.getProvider(name);
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
*
|
|
305
|
-
* @param app - FirebaseApp instance
|
|
306
|
-
* @param name - service name
|
|
307
|
-
* @param instanceIdentifier - service instance identifier in case the service supports multiple instances
|
|
308
|
-
*
|
|
309
|
-
* @internal
|
|
310
|
-
*/
|
|
311
|
-
function _removeServiceInstance(app, name, instanceIdentifier) {
|
|
312
|
-
if (instanceIdentifier === void 0) { instanceIdentifier = DEFAULT_ENTRY_NAME; }
|
|
313
|
-
_getProvider(app, name).clearInstance(instanceIdentifier);
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
*
|
|
317
|
-
* @param obj - an object of type FirebaseApp or FirebaseOptions.
|
|
318
|
-
*
|
|
319
|
-
* @returns true if the provide object is of type FirebaseApp.
|
|
320
|
-
*
|
|
321
|
-
* @internal
|
|
322
|
-
*/
|
|
323
|
-
function _isFirebaseApp(obj) {
|
|
324
|
-
return obj.options !== undefined;
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
*
|
|
328
|
-
* @param obj - an object of type FirebaseApp.
|
|
329
|
-
*
|
|
330
|
-
* @returns true if the provided object is of type FirebaseServerAppImpl.
|
|
331
|
-
*
|
|
332
|
-
* @internal
|
|
333
|
-
*/
|
|
334
|
-
function _isFirebaseServerApp(obj) {
|
|
335
|
-
return obj.settings !== undefined;
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Test only
|
|
339
|
-
*
|
|
340
|
-
* @internal
|
|
341
|
-
*/
|
|
342
|
-
function _clearComponents() {
|
|
343
|
-
_components.clear();
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* @license
|
|
348
|
-
* Copyright 2019 Google LLC
|
|
349
|
-
*
|
|
350
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
351
|
-
* you may not use this file except in compliance with the License.
|
|
352
|
-
* You may obtain a copy of the License at
|
|
353
|
-
*
|
|
354
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
355
|
-
*
|
|
356
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
357
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
358
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
359
|
-
* See the License for the specific language governing permissions and
|
|
360
|
-
* limitations under the License.
|
|
361
|
-
*/
|
|
362
|
-
var _a;
|
|
363
|
-
var ERRORS = (_a = {},
|
|
364
|
-
_a["no-app" /* AppError.NO_APP */] = "No Firebase App '{$appName}' has been created - " +
|
|
365
|
-
'call initializeApp() first',
|
|
366
|
-
_a["bad-app-name" /* AppError.BAD_APP_NAME */] = "Illegal App name: '{$appName}'",
|
|
367
|
-
_a["duplicate-app" /* AppError.DUPLICATE_APP */] = "Firebase App named '{$appName}' already exists with different options or config",
|
|
368
|
-
_a["app-deleted" /* AppError.APP_DELETED */] = "Firebase App named '{$appName}' already deleted",
|
|
369
|
-
_a["server-app-deleted" /* AppError.SERVER_APP_DELETED */] = 'Firebase Server App has been deleted',
|
|
370
|
-
_a["no-options" /* AppError.NO_OPTIONS */] = 'Need to provide options, when not being deployed to hosting via source.',
|
|
371
|
-
_a["invalid-app-argument" /* AppError.INVALID_APP_ARGUMENT */] = 'firebase.{$appName}() takes either no argument or a ' +
|
|
372
|
-
'Firebase App instance.',
|
|
373
|
-
_a["invalid-log-argument" /* AppError.INVALID_LOG_ARGUMENT */] = 'First argument to `onLog` must be null or a function.',
|
|
374
|
-
_a["idb-open" /* AppError.IDB_OPEN */] = 'Error thrown when opening IndexedDB. Original error: {$originalErrorMessage}.',
|
|
375
|
-
_a["idb-get" /* AppError.IDB_GET */] = 'Error thrown when reading from IndexedDB. Original error: {$originalErrorMessage}.',
|
|
376
|
-
_a["idb-set" /* AppError.IDB_WRITE */] = 'Error thrown when writing to IndexedDB. Original error: {$originalErrorMessage}.',
|
|
377
|
-
_a["idb-delete" /* AppError.IDB_DELETE */] = 'Error thrown when deleting from IndexedDB. Original error: {$originalErrorMessage}.',
|
|
378
|
-
_a["finalization-registry-not-supported" /* AppError.FINALIZATION_REGISTRY_NOT_SUPPORTED */] = 'FirebaseServerApp deleteOnDeref field defined but the JS runtime does not support FinalizationRegistry.',
|
|
379
|
-
_a["invalid-server-app-environment" /* AppError.INVALID_SERVER_APP_ENVIRONMENT */] = 'FirebaseServerApp is not for use in browser environments.',
|
|
380
|
-
_a);
|
|
381
|
-
var ERROR_FACTORY = new ErrorFactory('app', 'Firebase', ERRORS);
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* @license
|
|
385
|
-
* Copyright 2019 Google LLC
|
|
386
|
-
*
|
|
387
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
388
|
-
* you may not use this file except in compliance with the License.
|
|
389
|
-
* You may obtain a copy of the License at
|
|
390
|
-
*
|
|
391
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
392
|
-
*
|
|
393
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
394
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
395
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
396
|
-
* See the License for the specific language governing permissions and
|
|
397
|
-
* limitations under the License.
|
|
398
|
-
*/
|
|
399
|
-
var FirebaseAppImpl = /** @class */ (function () {
|
|
400
|
-
function FirebaseAppImpl(options, config, container) {
|
|
401
|
-
var _this = this;
|
|
402
|
-
this._isDeleted = false;
|
|
403
|
-
this._options = __assign({}, options);
|
|
404
|
-
this._config = __assign({}, config);
|
|
405
|
-
this._name = config.name;
|
|
406
|
-
this._automaticDataCollectionEnabled =
|
|
407
|
-
config.automaticDataCollectionEnabled;
|
|
408
|
-
this._container = container;
|
|
409
|
-
this.container.addComponent(new Component('app', function () { return _this; }, "PUBLIC" /* ComponentType.PUBLIC */));
|
|
410
|
-
}
|
|
411
|
-
Object.defineProperty(FirebaseAppImpl.prototype, "automaticDataCollectionEnabled", {
|
|
412
|
-
get: function () {
|
|
413
|
-
this.checkDestroyed();
|
|
414
|
-
return this._automaticDataCollectionEnabled;
|
|
415
|
-
},
|
|
416
|
-
set: function (val) {
|
|
417
|
-
this.checkDestroyed();
|
|
418
|
-
this._automaticDataCollectionEnabled = val;
|
|
419
|
-
},
|
|
420
|
-
enumerable: false,
|
|
421
|
-
configurable: true
|
|
422
|
-
});
|
|
423
|
-
Object.defineProperty(FirebaseAppImpl.prototype, "name", {
|
|
424
|
-
get: function () {
|
|
425
|
-
this.checkDestroyed();
|
|
426
|
-
return this._name;
|
|
427
|
-
},
|
|
428
|
-
enumerable: false,
|
|
429
|
-
configurable: true
|
|
430
|
-
});
|
|
431
|
-
Object.defineProperty(FirebaseAppImpl.prototype, "options", {
|
|
432
|
-
get: function () {
|
|
433
|
-
this.checkDestroyed();
|
|
434
|
-
return this._options;
|
|
435
|
-
},
|
|
436
|
-
enumerable: false,
|
|
437
|
-
configurable: true
|
|
438
|
-
});
|
|
439
|
-
Object.defineProperty(FirebaseAppImpl.prototype, "config", {
|
|
440
|
-
get: function () {
|
|
441
|
-
this.checkDestroyed();
|
|
442
|
-
return this._config;
|
|
443
|
-
},
|
|
444
|
-
enumerable: false,
|
|
445
|
-
configurable: true
|
|
446
|
-
});
|
|
447
|
-
Object.defineProperty(FirebaseAppImpl.prototype, "container", {
|
|
448
|
-
get: function () {
|
|
449
|
-
return this._container;
|
|
450
|
-
},
|
|
451
|
-
enumerable: false,
|
|
452
|
-
configurable: true
|
|
453
|
-
});
|
|
454
|
-
Object.defineProperty(FirebaseAppImpl.prototype, "isDeleted", {
|
|
455
|
-
get: function () {
|
|
456
|
-
return this._isDeleted;
|
|
457
|
-
},
|
|
458
|
-
set: function (val) {
|
|
459
|
-
this._isDeleted = val;
|
|
460
|
-
},
|
|
461
|
-
enumerable: false,
|
|
462
|
-
configurable: true
|
|
463
|
-
});
|
|
464
|
-
/**
|
|
465
|
-
* This function will throw an Error if the App has already been deleted -
|
|
466
|
-
* use before performing API actions on the App.
|
|
467
|
-
*/
|
|
468
|
-
FirebaseAppImpl.prototype.checkDestroyed = function () {
|
|
469
|
-
if (this.isDeleted) {
|
|
470
|
-
throw ERROR_FACTORY.create("app-deleted" /* AppError.APP_DELETED */, { appName: this._name });
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
return FirebaseAppImpl;
|
|
474
|
-
}());
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
* @license
|
|
478
|
-
* Copyright 2023 Google LLC
|
|
479
|
-
*
|
|
480
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
481
|
-
* you may not use this file except in compliance with the License.
|
|
482
|
-
* You may obtain a copy of the License at
|
|
483
|
-
*
|
|
484
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
485
|
-
*
|
|
486
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
487
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
488
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
489
|
-
* See the License for the specific language governing permissions and
|
|
490
|
-
* limitations under the License.
|
|
491
|
-
*/
|
|
492
|
-
var FirebaseServerAppImpl = /** @class */ (function (_super) {
|
|
493
|
-
__extends(FirebaseServerAppImpl, _super);
|
|
494
|
-
function FirebaseServerAppImpl(options, serverConfig, name, container) {
|
|
495
|
-
var _this = this;
|
|
496
|
-
// Build configuration parameters for the FirebaseAppImpl base class.
|
|
497
|
-
var automaticDataCollectionEnabled = serverConfig.automaticDataCollectionEnabled !== undefined
|
|
498
|
-
? serverConfig.automaticDataCollectionEnabled
|
|
499
|
-
: false;
|
|
500
|
-
// Create the FirebaseAppSettings object for the FirebaseAppImp constructor.
|
|
501
|
-
var config = {
|
|
502
|
-
name: name,
|
|
503
|
-
automaticDataCollectionEnabled: automaticDataCollectionEnabled
|
|
504
|
-
};
|
|
505
|
-
if (options.apiKey !== undefined) {
|
|
506
|
-
// Construct the parent FirebaseAppImp object.
|
|
507
|
-
_this = _super.call(this, options, config, container) || this;
|
|
508
|
-
}
|
|
509
|
-
else {
|
|
510
|
-
var appImpl = options;
|
|
511
|
-
_this = _super.call(this, appImpl.options, config, container) || this;
|
|
512
|
-
}
|
|
513
|
-
// Now construct the data for the FirebaseServerAppImpl.
|
|
514
|
-
_this._serverConfig = __assign({ automaticDataCollectionEnabled: automaticDataCollectionEnabled }, serverConfig);
|
|
515
|
-
_this._finalizationRegistry = null;
|
|
516
|
-
if (typeof FinalizationRegistry !== 'undefined') {
|
|
517
|
-
_this._finalizationRegistry = new FinalizationRegistry(function () {
|
|
518
|
-
_this.automaticCleanup();
|
|
519
|
-
});
|
|
520
|
-
}
|
|
521
|
-
_this._refCount = 0;
|
|
522
|
-
_this.incRefCount(_this._serverConfig.releaseOnDeref);
|
|
523
|
-
// Do not retain a hard reference to the dref object, otherwise the FinalizationRegistry
|
|
524
|
-
// will never trigger.
|
|
525
|
-
_this._serverConfig.releaseOnDeref = undefined;
|
|
526
|
-
serverConfig.releaseOnDeref = undefined;
|
|
527
|
-
registerVersion(name$q, version$1, 'serverapp');
|
|
528
|
-
return _this;
|
|
529
|
-
}
|
|
530
|
-
FirebaseServerAppImpl.prototype.toJSON = function () {
|
|
531
|
-
return undefined;
|
|
532
|
-
};
|
|
533
|
-
Object.defineProperty(FirebaseServerAppImpl.prototype, "refCount", {
|
|
534
|
-
get: function () {
|
|
535
|
-
return this._refCount;
|
|
536
|
-
},
|
|
537
|
-
enumerable: false,
|
|
538
|
-
configurable: true
|
|
539
|
-
});
|
|
540
|
-
// Increment the reference count of this server app. If an object is provided, register it
|
|
541
|
-
// with the finalization registry.
|
|
542
|
-
FirebaseServerAppImpl.prototype.incRefCount = function (obj) {
|
|
543
|
-
if (this.isDeleted) {
|
|
544
|
-
return;
|
|
545
|
-
}
|
|
546
|
-
this._refCount++;
|
|
547
|
-
if (obj !== undefined && this._finalizationRegistry !== null) {
|
|
548
|
-
this._finalizationRegistry.register(obj, this);
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
// Decrement the reference count.
|
|
552
|
-
FirebaseServerAppImpl.prototype.decRefCount = function () {
|
|
553
|
-
if (this.isDeleted) {
|
|
554
|
-
return 0;
|
|
555
|
-
}
|
|
556
|
-
return --this._refCount;
|
|
557
|
-
};
|
|
558
|
-
// Invoked by the FinalizationRegistry callback to note that this app should go through its
|
|
559
|
-
// reference counts and delete itself if no reference count remain. The coordinating logic that
|
|
560
|
-
// handles this is in deleteApp(...).
|
|
561
|
-
FirebaseServerAppImpl.prototype.automaticCleanup = function () {
|
|
562
|
-
void deleteApp(this);
|
|
563
|
-
};
|
|
564
|
-
Object.defineProperty(FirebaseServerAppImpl.prototype, "settings", {
|
|
565
|
-
get: function () {
|
|
566
|
-
this.checkDestroyed();
|
|
567
|
-
return this._serverConfig;
|
|
568
|
-
},
|
|
569
|
-
enumerable: false,
|
|
570
|
-
configurable: true
|
|
571
|
-
});
|
|
572
|
-
/**
|
|
573
|
-
* This function will throw an Error if the App has already been deleted -
|
|
574
|
-
* use before performing API actions on the App.
|
|
575
|
-
*/
|
|
576
|
-
FirebaseServerAppImpl.prototype.checkDestroyed = function () {
|
|
577
|
-
if (this.isDeleted) {
|
|
578
|
-
throw ERROR_FACTORY.create("server-app-deleted" /* AppError.SERVER_APP_DELETED */);
|
|
579
|
-
}
|
|
580
|
-
};
|
|
581
|
-
return FirebaseServerAppImpl;
|
|
582
|
-
}(FirebaseAppImpl));
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* @license
|
|
586
|
-
* Copyright 2019 Google LLC
|
|
587
|
-
*
|
|
588
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
589
|
-
* you may not use this file except in compliance with the License.
|
|
590
|
-
* You may obtain a copy of the License at
|
|
591
|
-
*
|
|
592
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
593
|
-
*
|
|
594
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
595
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
596
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
597
|
-
* See the License for the specific language governing permissions and
|
|
598
|
-
* limitations under the License.
|
|
599
|
-
*/
|
|
600
|
-
/**
|
|
601
|
-
* The current SDK version.
|
|
602
|
-
*
|
|
603
|
-
* @public
|
|
604
|
-
*/
|
|
605
|
-
var SDK_VERSION = version;
|
|
606
|
-
function initializeApp(_options, rawConfig) {
|
|
607
|
-
var e_1, _a;
|
|
608
|
-
if (rawConfig === void 0) { rawConfig = {}; }
|
|
609
|
-
var options = _options;
|
|
610
|
-
if (typeof rawConfig !== 'object') {
|
|
611
|
-
var name_1 = rawConfig;
|
|
612
|
-
rawConfig = { name: name_1 };
|
|
613
|
-
}
|
|
614
|
-
var config = __assign({ name: DEFAULT_ENTRY_NAME, automaticDataCollectionEnabled: false }, rawConfig);
|
|
615
|
-
var name = config.name;
|
|
616
|
-
if (typeof name !== 'string' || !name) {
|
|
617
|
-
throw ERROR_FACTORY.create("bad-app-name" /* AppError.BAD_APP_NAME */, {
|
|
618
|
-
appName: String(name)
|
|
619
|
-
});
|
|
620
|
-
}
|
|
621
|
-
options || (options = getDefaultAppConfig());
|
|
622
|
-
if (!options) {
|
|
623
|
-
throw ERROR_FACTORY.create("no-options" /* AppError.NO_OPTIONS */);
|
|
624
|
-
}
|
|
625
|
-
var existingApp = _apps.get(name);
|
|
626
|
-
if (existingApp) {
|
|
627
|
-
// return the existing app if options and config deep equal the ones in the existing app.
|
|
628
|
-
if (deepEqual(options, existingApp.options) &&
|
|
629
|
-
deepEqual(config, existingApp.config)) {
|
|
630
|
-
return existingApp;
|
|
631
|
-
}
|
|
632
|
-
else {
|
|
633
|
-
throw ERROR_FACTORY.create("duplicate-app" /* AppError.DUPLICATE_APP */, { appName: name });
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
var container = new ComponentContainer(name);
|
|
637
|
-
try {
|
|
638
|
-
for (var _b = __values(_components.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
639
|
-
var component = _c.value;
|
|
640
|
-
container.addComponent(component);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
644
|
-
finally {
|
|
645
|
-
try {
|
|
646
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
647
|
-
}
|
|
648
|
-
finally { if (e_1) throw e_1.error; }
|
|
649
|
-
}
|
|
650
|
-
var newApp = new FirebaseAppImpl(options, config, container);
|
|
651
|
-
_apps.set(name, newApp);
|
|
652
|
-
return newApp;
|
|
653
|
-
}
|
|
654
|
-
function initializeServerApp(_options, _serverAppConfig) {
|
|
655
|
-
var e_2, _a;
|
|
656
|
-
if (isBrowser() && !isWebWorker()) {
|
|
657
|
-
// FirebaseServerApp isn't designed to be run in browsers.
|
|
658
|
-
throw ERROR_FACTORY.create("invalid-server-app-environment" /* AppError.INVALID_SERVER_APP_ENVIRONMENT */);
|
|
659
|
-
}
|
|
660
|
-
if (_serverAppConfig.automaticDataCollectionEnabled === undefined) {
|
|
661
|
-
_serverAppConfig.automaticDataCollectionEnabled = false;
|
|
662
|
-
}
|
|
663
|
-
var appOptions;
|
|
664
|
-
if (_isFirebaseApp(_options)) {
|
|
665
|
-
appOptions = _options.options;
|
|
666
|
-
}
|
|
667
|
-
else {
|
|
668
|
-
appOptions = _options;
|
|
669
|
-
}
|
|
670
|
-
// Build an app name based on a hash of the configuration options.
|
|
671
|
-
var nameObj = __assign(__assign({}, _serverAppConfig), appOptions);
|
|
672
|
-
// However, Do not mangle the name based on releaseOnDeref, since it will vary between the
|
|
673
|
-
// construction of FirebaseServerApp instances. For example, if the object is the request headers.
|
|
674
|
-
if (nameObj.releaseOnDeref !== undefined) {
|
|
675
|
-
delete nameObj.releaseOnDeref;
|
|
676
|
-
}
|
|
677
|
-
var hashCode = function (s) {
|
|
678
|
-
return __spreadArray([], __read(s), false).reduce(function (hash, c) { return (Math.imul(31, hash) + c.charCodeAt(0)) | 0; }, 0);
|
|
679
|
-
};
|
|
680
|
-
if (_serverAppConfig.releaseOnDeref !== undefined) {
|
|
681
|
-
if (typeof FinalizationRegistry === 'undefined') {
|
|
682
|
-
throw ERROR_FACTORY.create("finalization-registry-not-supported" /* AppError.FINALIZATION_REGISTRY_NOT_SUPPORTED */, {});
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
var nameString = '' + hashCode(JSON.stringify(nameObj));
|
|
686
|
-
var existingApp = _serverApps.get(nameString);
|
|
687
|
-
if (existingApp) {
|
|
688
|
-
existingApp.incRefCount(_serverAppConfig.releaseOnDeref);
|
|
689
|
-
return existingApp;
|
|
690
|
-
}
|
|
691
|
-
var container = new ComponentContainer(nameString);
|
|
692
|
-
try {
|
|
693
|
-
for (var _b = __values(_components.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
694
|
-
var component = _c.value;
|
|
695
|
-
container.addComponent(component);
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
699
|
-
finally {
|
|
700
|
-
try {
|
|
701
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
702
|
-
}
|
|
703
|
-
finally { if (e_2) throw e_2.error; }
|
|
704
|
-
}
|
|
705
|
-
var newApp = new FirebaseServerAppImpl(appOptions, _serverAppConfig, nameString, container);
|
|
706
|
-
_serverApps.set(nameString, newApp);
|
|
707
|
-
return newApp;
|
|
708
|
-
}
|
|
709
|
-
/**
|
|
710
|
-
* Retrieves a {@link @firebase/app#FirebaseApp} instance.
|
|
711
|
-
*
|
|
712
|
-
* When called with no arguments, the default app is returned. When an app name
|
|
713
|
-
* is provided, the app corresponding to that name is returned.
|
|
714
|
-
*
|
|
715
|
-
* An exception is thrown if the app being retrieved has not yet been
|
|
716
|
-
* initialized.
|
|
717
|
-
*
|
|
718
|
-
* @example
|
|
719
|
-
* ```javascript
|
|
720
|
-
* // Return the default app
|
|
721
|
-
* const app = getApp();
|
|
722
|
-
* ```
|
|
723
|
-
*
|
|
724
|
-
* @example
|
|
725
|
-
* ```javascript
|
|
726
|
-
* // Return a named app
|
|
727
|
-
* const otherApp = getApp("otherApp");
|
|
728
|
-
* ```
|
|
729
|
-
*
|
|
730
|
-
* @param name - Optional name of the app to return. If no name is
|
|
731
|
-
* provided, the default is `"[DEFAULT]"`.
|
|
732
|
-
*
|
|
733
|
-
* @returns The app corresponding to the provided app name.
|
|
734
|
-
* If no app name is provided, the default app is returned.
|
|
735
|
-
*
|
|
736
|
-
* @public
|
|
737
|
-
*/
|
|
738
|
-
function getApp(name) {
|
|
739
|
-
if (name === void 0) { name = DEFAULT_ENTRY_NAME; }
|
|
740
|
-
var app = _apps.get(name);
|
|
741
|
-
if (!app && name === DEFAULT_ENTRY_NAME && getDefaultAppConfig()) {
|
|
742
|
-
return initializeApp();
|
|
743
|
-
}
|
|
744
|
-
if (!app) {
|
|
745
|
-
throw ERROR_FACTORY.create("no-app" /* AppError.NO_APP */, { appName: name });
|
|
746
|
-
}
|
|
747
|
-
return app;
|
|
748
|
-
}
|
|
749
|
-
/**
|
|
750
|
-
* A (read-only) array of all initialized apps.
|
|
751
|
-
* @public
|
|
752
|
-
*/
|
|
753
|
-
function getApps() {
|
|
754
|
-
return Array.from(_apps.values());
|
|
755
|
-
}
|
|
756
|
-
/**
|
|
757
|
-
* Renders this app unusable and frees the resources of all associated
|
|
758
|
-
* services.
|
|
759
|
-
*
|
|
760
|
-
* @example
|
|
761
|
-
* ```javascript
|
|
762
|
-
* deleteApp(app)
|
|
763
|
-
* .then(function() {
|
|
764
|
-
* console.log("App deleted successfully");
|
|
765
|
-
* })
|
|
766
|
-
* .catch(function(error) {
|
|
767
|
-
* console.log("Error deleting app:", error);
|
|
768
|
-
* });
|
|
769
|
-
* ```
|
|
770
|
-
*
|
|
771
|
-
* @public
|
|
772
|
-
*/
|
|
773
|
-
function deleteApp(app) {
|
|
774
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
775
|
-
var cleanupProviders, name, firebaseServerApp;
|
|
776
|
-
return __generator(this, function (_a) {
|
|
777
|
-
switch (_a.label) {
|
|
778
|
-
case 0:
|
|
779
|
-
cleanupProviders = false;
|
|
780
|
-
name = app.name;
|
|
781
|
-
if (_apps.has(name)) {
|
|
782
|
-
cleanupProviders = true;
|
|
783
|
-
_apps.delete(name);
|
|
784
|
-
}
|
|
785
|
-
else if (_serverApps.has(name)) {
|
|
786
|
-
firebaseServerApp = app;
|
|
787
|
-
if (firebaseServerApp.decRefCount() <= 0) {
|
|
788
|
-
_serverApps.delete(name);
|
|
789
|
-
cleanupProviders = true;
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
if (!cleanupProviders) return [3 /*break*/, 2];
|
|
793
|
-
return [4 /*yield*/, Promise.all(app.container
|
|
794
|
-
.getProviders()
|
|
795
|
-
.map(function (provider) { return provider.delete(); }))];
|
|
796
|
-
case 1:
|
|
797
|
-
_a.sent();
|
|
798
|
-
app.isDeleted = true;
|
|
799
|
-
_a.label = 2;
|
|
800
|
-
case 2: return [2 /*return*/];
|
|
801
|
-
}
|
|
802
|
-
});
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* Registers a library's name and version for platform logging purposes.
|
|
807
|
-
* @param library - Name of 1p or 3p library (e.g. firestore, angularfire)
|
|
808
|
-
* @param version - Current version of that library.
|
|
809
|
-
* @param variant - Bundle variant, e.g., node, rn, etc.
|
|
810
|
-
*
|
|
811
|
-
* @public
|
|
812
|
-
*/
|
|
813
|
-
function registerVersion(libraryKeyOrName, version, variant) {
|
|
814
|
-
var _a;
|
|
815
|
-
// TODO: We can use this check to whitelist strings when/if we set up
|
|
816
|
-
// a good whitelist system.
|
|
817
|
-
var library = (_a = PLATFORM_LOG_STRING[libraryKeyOrName]) !== null && _a !== void 0 ? _a : libraryKeyOrName;
|
|
818
|
-
if (variant) {
|
|
819
|
-
library += "-".concat(variant);
|
|
820
|
-
}
|
|
821
|
-
var libraryMismatch = library.match(/\s|\//);
|
|
822
|
-
var versionMismatch = version.match(/\s|\//);
|
|
823
|
-
if (libraryMismatch || versionMismatch) {
|
|
824
|
-
var warning = [
|
|
825
|
-
"Unable to register library \"".concat(library, "\" with version \"").concat(version, "\":")
|
|
826
|
-
];
|
|
827
|
-
if (libraryMismatch) {
|
|
828
|
-
warning.push("library name \"".concat(library, "\" contains illegal characters (whitespace or \"/\")"));
|
|
829
|
-
}
|
|
830
|
-
if (libraryMismatch && versionMismatch) {
|
|
831
|
-
warning.push('and');
|
|
832
|
-
}
|
|
833
|
-
if (versionMismatch) {
|
|
834
|
-
warning.push("version name \"".concat(version, "\" contains illegal characters (whitespace or \"/\")"));
|
|
835
|
-
}
|
|
836
|
-
logger.warn(warning.join(' '));
|
|
837
|
-
return;
|
|
838
|
-
}
|
|
839
|
-
_registerComponent(new Component("".concat(library, "-version"), function () { return ({ library: library, version: version }); }, "VERSION" /* ComponentType.VERSION */));
|
|
840
|
-
}
|
|
841
|
-
/**
|
|
842
|
-
* Sets log handler for all Firebase SDKs.
|
|
843
|
-
* @param logCallback - An optional custom log handler that executes user code whenever
|
|
844
|
-
* the Firebase SDK makes a logging call.
|
|
845
|
-
*
|
|
846
|
-
* @public
|
|
847
|
-
*/
|
|
848
|
-
function onLog(logCallback, options) {
|
|
849
|
-
if (logCallback !== null && typeof logCallback !== 'function') {
|
|
850
|
-
throw ERROR_FACTORY.create("invalid-log-argument" /* AppError.INVALID_LOG_ARGUMENT */);
|
|
851
|
-
}
|
|
852
|
-
setUserLogHandler(logCallback, options);
|
|
853
|
-
}
|
|
854
|
-
/**
|
|
855
|
-
* Sets log level for all Firebase SDKs.
|
|
856
|
-
*
|
|
857
|
-
* All of the log types above the current log level are captured (i.e. if
|
|
858
|
-
* you set the log level to `info`, errors are logged, but `debug` and
|
|
859
|
-
* `verbose` logs are not).
|
|
860
|
-
*
|
|
861
|
-
* @public
|
|
862
|
-
*/
|
|
863
|
-
function setLogLevel(logLevel) {
|
|
864
|
-
setLogLevel$1(logLevel);
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
/**
|
|
868
|
-
* @license
|
|
869
|
-
* Copyright 2021 Google LLC
|
|
870
|
-
*
|
|
871
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
872
|
-
* you may not use this file except in compliance with the License.
|
|
873
|
-
* You may obtain a copy of the License at
|
|
874
|
-
*
|
|
875
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
876
|
-
*
|
|
877
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
878
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
879
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
880
|
-
* See the License for the specific language governing permissions and
|
|
881
|
-
* limitations under the License.
|
|
882
|
-
*/
|
|
883
|
-
var DB_NAME = 'firebase-heartbeat-database';
|
|
884
|
-
var DB_VERSION = 1;
|
|
885
|
-
var STORE_NAME = 'firebase-heartbeat-store';
|
|
886
|
-
var dbPromise = null;
|
|
887
|
-
function getDbPromise() {
|
|
888
|
-
if (!dbPromise) {
|
|
889
|
-
dbPromise = openDB(DB_NAME, DB_VERSION, {
|
|
890
|
-
upgrade: function (db, oldVersion) {
|
|
891
|
-
// We don't use 'break' in this switch statement, the fall-through
|
|
892
|
-
// behavior is what we want, because if there are multiple versions between
|
|
893
|
-
// the old version and the current version, we want ALL the migrations
|
|
894
|
-
// that correspond to those versions to run, not only the last one.
|
|
895
|
-
// eslint-disable-next-line default-case
|
|
896
|
-
switch (oldVersion) {
|
|
897
|
-
case 0:
|
|
898
|
-
try {
|
|
899
|
-
db.createObjectStore(STORE_NAME);
|
|
900
|
-
}
|
|
901
|
-
catch (e) {
|
|
902
|
-
// Safari/iOS browsers throw occasional exceptions on
|
|
903
|
-
// db.createObjectStore() that may be a bug. Avoid blocking
|
|
904
|
-
// the rest of the app functionality.
|
|
905
|
-
console.warn(e);
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
}).catch(function (e) {
|
|
910
|
-
throw ERROR_FACTORY.create("idb-open" /* AppError.IDB_OPEN */, {
|
|
911
|
-
originalErrorMessage: e.message
|
|
912
|
-
});
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
return dbPromise;
|
|
916
|
-
}
|
|
917
|
-
function readHeartbeatsFromIndexedDB(app) {
|
|
918
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
919
|
-
var db, tx, result, e_1, idbGetError;
|
|
920
|
-
return __generator(this, function (_a) {
|
|
921
|
-
switch (_a.label) {
|
|
922
|
-
case 0:
|
|
923
|
-
_a.trys.push([0, 4, , 5]);
|
|
924
|
-
return [4 /*yield*/, getDbPromise()];
|
|
925
|
-
case 1:
|
|
926
|
-
db = _a.sent();
|
|
927
|
-
tx = db.transaction(STORE_NAME);
|
|
928
|
-
return [4 /*yield*/, tx.objectStore(STORE_NAME).get(computeKey(app))];
|
|
929
|
-
case 2:
|
|
930
|
-
result = _a.sent();
|
|
931
|
-
// We already have the value but tx.done can throw,
|
|
932
|
-
// so we need to await it here to catch errors
|
|
933
|
-
return [4 /*yield*/, tx.done];
|
|
934
|
-
case 3:
|
|
935
|
-
// We already have the value but tx.done can throw,
|
|
936
|
-
// so we need to await it here to catch errors
|
|
937
|
-
_a.sent();
|
|
938
|
-
return [2 /*return*/, result];
|
|
939
|
-
case 4:
|
|
940
|
-
e_1 = _a.sent();
|
|
941
|
-
if (e_1 instanceof FirebaseError) {
|
|
942
|
-
logger.warn(e_1.message);
|
|
943
|
-
}
|
|
944
|
-
else {
|
|
945
|
-
idbGetError = ERROR_FACTORY.create("idb-get" /* AppError.IDB_GET */, {
|
|
946
|
-
originalErrorMessage: e_1 === null || e_1 === void 0 ? void 0 : e_1.message
|
|
947
|
-
});
|
|
948
|
-
logger.warn(idbGetError.message);
|
|
949
|
-
}
|
|
950
|
-
return [3 /*break*/, 5];
|
|
951
|
-
case 5: return [2 /*return*/];
|
|
952
|
-
}
|
|
953
|
-
});
|
|
954
|
-
});
|
|
955
|
-
}
|
|
956
|
-
function writeHeartbeatsToIndexedDB(app, heartbeatObject) {
|
|
957
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
958
|
-
var db, tx, objectStore, e_2, idbGetError;
|
|
959
|
-
return __generator(this, function (_a) {
|
|
960
|
-
switch (_a.label) {
|
|
961
|
-
case 0:
|
|
962
|
-
_a.trys.push([0, 4, , 5]);
|
|
963
|
-
return [4 /*yield*/, getDbPromise()];
|
|
964
|
-
case 1:
|
|
965
|
-
db = _a.sent();
|
|
966
|
-
tx = db.transaction(STORE_NAME, 'readwrite');
|
|
967
|
-
objectStore = tx.objectStore(STORE_NAME);
|
|
968
|
-
return [4 /*yield*/, objectStore.put(heartbeatObject, computeKey(app))];
|
|
969
|
-
case 2:
|
|
970
|
-
_a.sent();
|
|
971
|
-
return [4 /*yield*/, tx.done];
|
|
972
|
-
case 3:
|
|
973
|
-
_a.sent();
|
|
974
|
-
return [3 /*break*/, 5];
|
|
975
|
-
case 4:
|
|
976
|
-
e_2 = _a.sent();
|
|
977
|
-
if (e_2 instanceof FirebaseError) {
|
|
978
|
-
logger.warn(e_2.message);
|
|
979
|
-
}
|
|
980
|
-
else {
|
|
981
|
-
idbGetError = ERROR_FACTORY.create("idb-set" /* AppError.IDB_WRITE */, {
|
|
982
|
-
originalErrorMessage: e_2 === null || e_2 === void 0 ? void 0 : e_2.message
|
|
983
|
-
});
|
|
984
|
-
logger.warn(idbGetError.message);
|
|
985
|
-
}
|
|
986
|
-
return [3 /*break*/, 5];
|
|
987
|
-
case 5: return [2 /*return*/];
|
|
988
|
-
}
|
|
989
|
-
});
|
|
990
|
-
});
|
|
991
|
-
}
|
|
992
|
-
function computeKey(app) {
|
|
993
|
-
return "".concat(app.name, "!").concat(app.options.appId);
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
/**
|
|
997
|
-
* @license
|
|
998
|
-
* Copyright 2021 Google LLC
|
|
999
|
-
*
|
|
1000
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1001
|
-
* you may not use this file except in compliance with the License.
|
|
1002
|
-
* You may obtain a copy of the License at
|
|
1003
|
-
*
|
|
1004
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1005
|
-
*
|
|
1006
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1007
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1008
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1009
|
-
* See the License for the specific language governing permissions and
|
|
1010
|
-
* limitations under the License.
|
|
1011
|
-
*/
|
|
1012
|
-
var MAX_HEADER_BYTES = 1024;
|
|
1013
|
-
// 30 days
|
|
1014
|
-
var STORED_HEARTBEAT_RETENTION_MAX_MILLIS = 30 * 24 * 60 * 60 * 1000;
|
|
1015
|
-
var HeartbeatServiceImpl = /** @class */ (function () {
|
|
1016
|
-
function HeartbeatServiceImpl(container) {
|
|
1017
|
-
var _this = this;
|
|
1018
|
-
this.container = container;
|
|
1019
|
-
/**
|
|
1020
|
-
* In-memory cache for heartbeats, used by getHeartbeatsHeader() to generate
|
|
1021
|
-
* the header string.
|
|
1022
|
-
* Stores one record per date. This will be consolidated into the standard
|
|
1023
|
-
* format of one record per user agent string before being sent as a header.
|
|
1024
|
-
* Populated from indexedDB when the controller is instantiated and should
|
|
1025
|
-
* be kept in sync with indexedDB.
|
|
1026
|
-
* Leave public for easier testing.
|
|
1027
|
-
*/
|
|
1028
|
-
this._heartbeatsCache = null;
|
|
1029
|
-
var app = this.container.getProvider('app').getImmediate();
|
|
1030
|
-
this._storage = new HeartbeatStorageImpl(app);
|
|
1031
|
-
this._heartbeatsCachePromise = this._storage.read().then(function (result) {
|
|
1032
|
-
_this._heartbeatsCache = result;
|
|
1033
|
-
return result;
|
|
1034
|
-
});
|
|
1035
|
-
}
|
|
1036
|
-
/**
|
|
1037
|
-
* Called to report a heartbeat. The function will generate
|
|
1038
|
-
* a HeartbeatsByUserAgent object, update heartbeatsCache, and persist it
|
|
1039
|
-
* to IndexedDB.
|
|
1040
|
-
* Note that we only store one heartbeat per day. So if a heartbeat for today is
|
|
1041
|
-
* already logged, subsequent calls to this function in the same day will be ignored.
|
|
1042
|
-
*/
|
|
1043
|
-
HeartbeatServiceImpl.prototype.triggerHeartbeat = function () {
|
|
1044
|
-
var _a, _b;
|
|
1045
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1046
|
-
var platformLogger, agent, date_1, _c, e_1;
|
|
1047
|
-
return __generator(this, function (_d) {
|
|
1048
|
-
switch (_d.label) {
|
|
1049
|
-
case 0:
|
|
1050
|
-
_d.trys.push([0, 3, , 4]);
|
|
1051
|
-
platformLogger = this.container
|
|
1052
|
-
.getProvider('platform-logger')
|
|
1053
|
-
.getImmediate();
|
|
1054
|
-
agent = platformLogger.getPlatformInfoString();
|
|
1055
|
-
date_1 = getUTCDateString();
|
|
1056
|
-
if (!(((_a = this._heartbeatsCache) === null || _a === void 0 ? void 0 : _a.heartbeats) == null)) return [3 /*break*/, 2];
|
|
1057
|
-
_c = this;
|
|
1058
|
-
return [4 /*yield*/, this._heartbeatsCachePromise];
|
|
1059
|
-
case 1:
|
|
1060
|
-
_c._heartbeatsCache = _d.sent();
|
|
1061
|
-
// If we failed to construct a heartbeats cache, then return immediately.
|
|
1062
|
-
if (((_b = this._heartbeatsCache) === null || _b === void 0 ? void 0 : _b.heartbeats) == null) {
|
|
1063
|
-
return [2 /*return*/];
|
|
1064
|
-
}
|
|
1065
|
-
_d.label = 2;
|
|
1066
|
-
case 2:
|
|
1067
|
-
// Do not store a heartbeat if one is already stored for this day
|
|
1068
|
-
// or if a header has already been sent today.
|
|
1069
|
-
if (this._heartbeatsCache.lastSentHeartbeatDate === date_1 ||
|
|
1070
|
-
this._heartbeatsCache.heartbeats.some(function (singleDateHeartbeat) { return singleDateHeartbeat.date === date_1; })) {
|
|
1071
|
-
return [2 /*return*/];
|
|
1072
|
-
}
|
|
1073
|
-
else {
|
|
1074
|
-
// There is no entry for this date. Create one.
|
|
1075
|
-
this._heartbeatsCache.heartbeats.push({ date: date_1, agent: agent });
|
|
1076
|
-
}
|
|
1077
|
-
// Remove entries older than 30 days.
|
|
1078
|
-
this._heartbeatsCache.heartbeats =
|
|
1079
|
-
this._heartbeatsCache.heartbeats.filter(function (singleDateHeartbeat) {
|
|
1080
|
-
var hbTimestamp = new Date(singleDateHeartbeat.date).valueOf();
|
|
1081
|
-
var now = Date.now();
|
|
1082
|
-
return now - hbTimestamp <= STORED_HEARTBEAT_RETENTION_MAX_MILLIS;
|
|
1083
|
-
});
|
|
1084
|
-
return [2 /*return*/, this._storage.overwrite(this._heartbeatsCache)];
|
|
1085
|
-
case 3:
|
|
1086
|
-
e_1 = _d.sent();
|
|
1087
|
-
logger.warn(e_1);
|
|
1088
|
-
return [3 /*break*/, 4];
|
|
1089
|
-
case 4: return [2 /*return*/];
|
|
1090
|
-
}
|
|
1091
|
-
});
|
|
1092
|
-
});
|
|
1093
|
-
};
|
|
1094
|
-
/**
|
|
1095
|
-
* Returns a base64 encoded string which can be attached to the heartbeat-specific header directly.
|
|
1096
|
-
* It also clears all heartbeats from memory as well as in IndexedDB.
|
|
1097
|
-
*
|
|
1098
|
-
* NOTE: Consuming product SDKs should not send the header if this method
|
|
1099
|
-
* returns an empty string.
|
|
1100
|
-
*/
|
|
1101
|
-
HeartbeatServiceImpl.prototype.getHeartbeatsHeader = function () {
|
|
1102
|
-
var _a;
|
|
1103
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1104
|
-
var date, _b, heartbeatsToSend, unsentEntries, headerString, e_2;
|
|
1105
|
-
return __generator(this, function (_c) {
|
|
1106
|
-
switch (_c.label) {
|
|
1107
|
-
case 0:
|
|
1108
|
-
_c.trys.push([0, 6, , 7]);
|
|
1109
|
-
if (!(this._heartbeatsCache === null)) return [3 /*break*/, 2];
|
|
1110
|
-
return [4 /*yield*/, this._heartbeatsCachePromise];
|
|
1111
|
-
case 1:
|
|
1112
|
-
_c.sent();
|
|
1113
|
-
_c.label = 2;
|
|
1114
|
-
case 2:
|
|
1115
|
-
// If it's still null or the array is empty, there is no data to send.
|
|
1116
|
-
if (((_a = this._heartbeatsCache) === null || _a === void 0 ? void 0 : _a.heartbeats) == null ||
|
|
1117
|
-
this._heartbeatsCache.heartbeats.length === 0) {
|
|
1118
|
-
return [2 /*return*/, ''];
|
|
1119
|
-
}
|
|
1120
|
-
date = getUTCDateString();
|
|
1121
|
-
_b = extractHeartbeatsForHeader(this._heartbeatsCache.heartbeats), heartbeatsToSend = _b.heartbeatsToSend, unsentEntries = _b.unsentEntries;
|
|
1122
|
-
headerString = base64urlEncodeWithoutPadding(JSON.stringify({ version: 2, heartbeats: heartbeatsToSend }));
|
|
1123
|
-
// Store last sent date to prevent another being logged/sent for the same day.
|
|
1124
|
-
this._heartbeatsCache.lastSentHeartbeatDate = date;
|
|
1125
|
-
if (!(unsentEntries.length > 0)) return [3 /*break*/, 4];
|
|
1126
|
-
// Store any unsent entries if they exist.
|
|
1127
|
-
this._heartbeatsCache.heartbeats = unsentEntries;
|
|
1128
|
-
// This seems more likely than emptying the array (below) to lead to some odd state
|
|
1129
|
-
// since the cache isn't empty and this will be called again on the next request,
|
|
1130
|
-
// and is probably safest if we await it.
|
|
1131
|
-
return [4 /*yield*/, this._storage.overwrite(this._heartbeatsCache)];
|
|
1132
|
-
case 3:
|
|
1133
|
-
// This seems more likely than emptying the array (below) to lead to some odd state
|
|
1134
|
-
// since the cache isn't empty and this will be called again on the next request,
|
|
1135
|
-
// and is probably safest if we await it.
|
|
1136
|
-
_c.sent();
|
|
1137
|
-
return [3 /*break*/, 5];
|
|
1138
|
-
case 4:
|
|
1139
|
-
this._heartbeatsCache.heartbeats = [];
|
|
1140
|
-
// Do not wait for this, to reduce latency.
|
|
1141
|
-
void this._storage.overwrite(this._heartbeatsCache);
|
|
1142
|
-
_c.label = 5;
|
|
1143
|
-
case 5: return [2 /*return*/, headerString];
|
|
1144
|
-
case 6:
|
|
1145
|
-
e_2 = _c.sent();
|
|
1146
|
-
logger.warn(e_2);
|
|
1147
|
-
return [2 /*return*/, ''];
|
|
1148
|
-
case 7: return [2 /*return*/];
|
|
1149
|
-
}
|
|
1150
|
-
});
|
|
1151
|
-
});
|
|
1152
|
-
};
|
|
1153
|
-
return HeartbeatServiceImpl;
|
|
1154
|
-
}());
|
|
1155
|
-
function getUTCDateString() {
|
|
1156
|
-
var today = new Date();
|
|
1157
|
-
// Returns date format 'YYYY-MM-DD'
|
|
1158
|
-
return today.toISOString().substring(0, 10);
|
|
1159
|
-
}
|
|
1160
|
-
function extractHeartbeatsForHeader(heartbeatsCache, maxSize) {
|
|
1161
|
-
var e_3, _a;
|
|
1162
|
-
if (maxSize === void 0) { maxSize = MAX_HEADER_BYTES; }
|
|
1163
|
-
// Heartbeats grouped by user agent in the standard format to be sent in
|
|
1164
|
-
// the header.
|
|
1165
|
-
var heartbeatsToSend = [];
|
|
1166
|
-
// Single date format heartbeats that are not sent.
|
|
1167
|
-
var unsentEntries = heartbeatsCache.slice();
|
|
1168
|
-
var _loop_1 = function (singleDateHeartbeat) {
|
|
1169
|
-
// Look for an existing entry with the same user agent.
|
|
1170
|
-
var heartbeatEntry = heartbeatsToSend.find(function (hb) { return hb.agent === singleDateHeartbeat.agent; });
|
|
1171
|
-
if (!heartbeatEntry) {
|
|
1172
|
-
// If no entry for this user agent exists, create one.
|
|
1173
|
-
heartbeatsToSend.push({
|
|
1174
|
-
agent: singleDateHeartbeat.agent,
|
|
1175
|
-
dates: [singleDateHeartbeat.date]
|
|
1176
|
-
});
|
|
1177
|
-
if (countBytes(heartbeatsToSend) > maxSize) {
|
|
1178
|
-
// If the header would exceed max size, remove the added heartbeat
|
|
1179
|
-
// entry and stop adding to the header.
|
|
1180
|
-
heartbeatsToSend.pop();
|
|
1181
|
-
return "break";
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
else {
|
|
1185
|
-
heartbeatEntry.dates.push(singleDateHeartbeat.date);
|
|
1186
|
-
// If the header would exceed max size, remove the added date
|
|
1187
|
-
// and stop adding to the header.
|
|
1188
|
-
if (countBytes(heartbeatsToSend) > maxSize) {
|
|
1189
|
-
heartbeatEntry.dates.pop();
|
|
1190
|
-
return "break";
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
// Pop unsent entry from queue. (Skipped if adding the entry exceeded
|
|
1194
|
-
// quota and the loop breaks early.)
|
|
1195
|
-
unsentEntries = unsentEntries.slice(1);
|
|
1196
|
-
};
|
|
1197
|
-
try {
|
|
1198
|
-
for (var heartbeatsCache_1 = __values(heartbeatsCache), heartbeatsCache_1_1 = heartbeatsCache_1.next(); !heartbeatsCache_1_1.done; heartbeatsCache_1_1 = heartbeatsCache_1.next()) {
|
|
1199
|
-
var singleDateHeartbeat = heartbeatsCache_1_1.value;
|
|
1200
|
-
var state_1 = _loop_1(singleDateHeartbeat);
|
|
1201
|
-
if (state_1 === "break")
|
|
1202
|
-
break;
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1206
|
-
finally {
|
|
1207
|
-
try {
|
|
1208
|
-
if (heartbeatsCache_1_1 && !heartbeatsCache_1_1.done && (_a = heartbeatsCache_1.return)) _a.call(heartbeatsCache_1);
|
|
1209
|
-
}
|
|
1210
|
-
finally { if (e_3) throw e_3.error; }
|
|
1211
|
-
}
|
|
1212
|
-
return {
|
|
1213
|
-
heartbeatsToSend: heartbeatsToSend,
|
|
1214
|
-
unsentEntries: unsentEntries
|
|
1215
|
-
};
|
|
1216
|
-
}
|
|
1217
|
-
var HeartbeatStorageImpl = /** @class */ (function () {
|
|
1218
|
-
function HeartbeatStorageImpl(app) {
|
|
1219
|
-
this.app = app;
|
|
1220
|
-
this._canUseIndexedDBPromise = this.runIndexedDBEnvironmentCheck();
|
|
1221
|
-
}
|
|
1222
|
-
HeartbeatStorageImpl.prototype.runIndexedDBEnvironmentCheck = function () {
|
|
1223
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1224
|
-
return __generator(this, function (_a) {
|
|
1225
|
-
if (!isIndexedDBAvailable()) {
|
|
1226
|
-
return [2 /*return*/, false];
|
|
1227
|
-
}
|
|
1228
|
-
else {
|
|
1229
|
-
return [2 /*return*/, validateIndexedDBOpenable()
|
|
1230
|
-
.then(function () { return true; })
|
|
1231
|
-
.catch(function () { return false; })];
|
|
1232
|
-
}
|
|
1233
|
-
});
|
|
1234
|
-
});
|
|
1235
|
-
};
|
|
1236
|
-
/**
|
|
1237
|
-
* Read all heartbeats.
|
|
1238
|
-
*/
|
|
1239
|
-
HeartbeatStorageImpl.prototype.read = function () {
|
|
1240
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1241
|
-
var canUseIndexedDB, idbHeartbeatObject;
|
|
1242
|
-
return __generator(this, function (_a) {
|
|
1243
|
-
switch (_a.label) {
|
|
1244
|
-
case 0: return [4 /*yield*/, this._canUseIndexedDBPromise];
|
|
1245
|
-
case 1:
|
|
1246
|
-
canUseIndexedDB = _a.sent();
|
|
1247
|
-
if (!!canUseIndexedDB) return [3 /*break*/, 2];
|
|
1248
|
-
return [2 /*return*/, { heartbeats: [] }];
|
|
1249
|
-
case 2: return [4 /*yield*/, readHeartbeatsFromIndexedDB(this.app)];
|
|
1250
|
-
case 3:
|
|
1251
|
-
idbHeartbeatObject = _a.sent();
|
|
1252
|
-
if (idbHeartbeatObject === null || idbHeartbeatObject === void 0 ? void 0 : idbHeartbeatObject.heartbeats) {
|
|
1253
|
-
return [2 /*return*/, idbHeartbeatObject];
|
|
1254
|
-
}
|
|
1255
|
-
else {
|
|
1256
|
-
return [2 /*return*/, { heartbeats: [] }];
|
|
1257
|
-
}
|
|
1258
|
-
case 4: return [2 /*return*/];
|
|
1259
|
-
}
|
|
1260
|
-
});
|
|
1261
|
-
});
|
|
1262
|
-
};
|
|
1263
|
-
// overwrite the storage with the provided heartbeats
|
|
1264
|
-
HeartbeatStorageImpl.prototype.overwrite = function (heartbeatsObject) {
|
|
1265
|
-
var _a;
|
|
1266
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1267
|
-
var canUseIndexedDB, existingHeartbeatsObject;
|
|
1268
|
-
return __generator(this, function (_b) {
|
|
1269
|
-
switch (_b.label) {
|
|
1270
|
-
case 0: return [4 /*yield*/, this._canUseIndexedDBPromise];
|
|
1271
|
-
case 1:
|
|
1272
|
-
canUseIndexedDB = _b.sent();
|
|
1273
|
-
if (!!canUseIndexedDB) return [3 /*break*/, 2];
|
|
1274
|
-
return [2 /*return*/];
|
|
1275
|
-
case 2: return [4 /*yield*/, this.read()];
|
|
1276
|
-
case 3:
|
|
1277
|
-
existingHeartbeatsObject = _b.sent();
|
|
1278
|
-
return [2 /*return*/, writeHeartbeatsToIndexedDB(this.app, {
|
|
1279
|
-
lastSentHeartbeatDate: (_a = heartbeatsObject.lastSentHeartbeatDate) !== null && _a !== void 0 ? _a : existingHeartbeatsObject.lastSentHeartbeatDate,
|
|
1280
|
-
heartbeats: heartbeatsObject.heartbeats
|
|
1281
|
-
})];
|
|
1282
|
-
}
|
|
1283
|
-
});
|
|
1284
|
-
});
|
|
1285
|
-
};
|
|
1286
|
-
// add heartbeats
|
|
1287
|
-
HeartbeatStorageImpl.prototype.add = function (heartbeatsObject) {
|
|
1288
|
-
var _a;
|
|
1289
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1290
|
-
var canUseIndexedDB, existingHeartbeatsObject;
|
|
1291
|
-
return __generator(this, function (_b) {
|
|
1292
|
-
switch (_b.label) {
|
|
1293
|
-
case 0: return [4 /*yield*/, this._canUseIndexedDBPromise];
|
|
1294
|
-
case 1:
|
|
1295
|
-
canUseIndexedDB = _b.sent();
|
|
1296
|
-
if (!!canUseIndexedDB) return [3 /*break*/, 2];
|
|
1297
|
-
return [2 /*return*/];
|
|
1298
|
-
case 2: return [4 /*yield*/, this.read()];
|
|
1299
|
-
case 3:
|
|
1300
|
-
existingHeartbeatsObject = _b.sent();
|
|
1301
|
-
return [2 /*return*/, writeHeartbeatsToIndexedDB(this.app, {
|
|
1302
|
-
lastSentHeartbeatDate: (_a = heartbeatsObject.lastSentHeartbeatDate) !== null && _a !== void 0 ? _a : existingHeartbeatsObject.lastSentHeartbeatDate,
|
|
1303
|
-
heartbeats: __spreadArray(__spreadArray([], __read(existingHeartbeatsObject.heartbeats), false), __read(heartbeatsObject.heartbeats), false)
|
|
1304
|
-
})];
|
|
1305
|
-
}
|
|
1306
|
-
});
|
|
1307
|
-
});
|
|
1308
|
-
};
|
|
1309
|
-
return HeartbeatStorageImpl;
|
|
1310
|
-
}());
|
|
1311
|
-
/**
|
|
1312
|
-
* Calculate bytes of a HeartbeatsByUserAgent array after being wrapped
|
|
1313
|
-
* in a platform logging header JSON object, stringified, and converted
|
|
1314
|
-
* to base 64.
|
|
1315
|
-
*/
|
|
1316
|
-
function countBytes(heartbeatsCache) {
|
|
1317
|
-
// base64 has a restricted set of characters, all of which should be 1 byte.
|
|
1318
|
-
return base64urlEncodeWithoutPadding(
|
|
1319
|
-
// heartbeatsCache wrapper properties
|
|
1320
|
-
JSON.stringify({ version: 2, heartbeats: heartbeatsCache })).length;
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
/**
|
|
1324
|
-
* @license
|
|
1325
|
-
* Copyright 2019 Google LLC
|
|
1326
|
-
*
|
|
1327
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1328
|
-
* you may not use this file except in compliance with the License.
|
|
1329
|
-
* You may obtain a copy of the License at
|
|
1330
|
-
*
|
|
1331
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1332
|
-
*
|
|
1333
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1334
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1335
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1336
|
-
* See the License for the specific language governing permissions and
|
|
1337
|
-
* limitations under the License.
|
|
1338
|
-
*/
|
|
1339
|
-
function registerCoreComponents(variant) {
|
|
1340
|
-
_registerComponent(new Component('platform-logger', function (container) { return new PlatformLoggerServiceImpl(container); }, "PRIVATE" /* ComponentType.PRIVATE */));
|
|
1341
|
-
_registerComponent(new Component('heartbeat', function (container) { return new HeartbeatServiceImpl(container); }, "PRIVATE" /* ComponentType.PRIVATE */));
|
|
1342
|
-
// Register `app` package.
|
|
1343
|
-
registerVersion(name$q, version$1, variant);
|
|
1344
|
-
// BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
|
|
1345
|
-
registerVersion(name$q, version$1, 'esm5');
|
|
1346
|
-
// Register platform SDK identifier (no version).
|
|
1347
|
-
registerVersion('fire-js', '');
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
/**
|
|
1351
|
-
* Firebase App
|
|
1352
|
-
*
|
|
1353
|
-
* @remarks This package coordinates the communication between the different Firebase components
|
|
1354
|
-
* @packageDocumentation
|
|
1355
|
-
*/
|
|
1356
|
-
registerCoreComponents('');
|
|
1357
|
-
|
|
1358
|
-
export { SDK_VERSION, DEFAULT_ENTRY_NAME as _DEFAULT_ENTRY_NAME, _addComponent, _addOrOverwriteComponent, _apps, _clearComponents, _components, _getProvider, _isFirebaseApp, _isFirebaseServerApp, _registerComponent, _removeServiceInstance, _serverApps, deleteApp, getApp, getApps, initializeApp, initializeServerApp, onLog, registerVersion, setLogLevel };
|
|
1359
|
-
//# sourceMappingURL=index.esm5.js.map
|