UNPKG

22.7 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var component = require('@firebase/component');
6var tslib = require('tslib');
7var logger$1 = require('@firebase/logger');
8var util = require('@firebase/util');
9
10/**
11 * @license
12 * Copyright 2019 Google LLC
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License");
15 * you may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
25 */
26var PlatformLoggerServiceImpl = /** @class */ (function () {
27 function PlatformLoggerServiceImpl(container) {
28 this.container = container;
29 }
30 // In initial implementation, this will be called by installations on
31 // auth token refresh, and installations will send this string.
32 PlatformLoggerServiceImpl.prototype.getPlatformInfoString = function () {
33 var providers = this.container.getProviders();
34 // Loop through providers and get library/version pairs from any that are
35 // version components.
36 return providers
37 .map(function (provider) {
38 if (isVersionServiceProvider(provider)) {
39 var service = provider.getImmediate();
40 return service.library + "/" + service.version;
41 }
42 else {
43 return null;
44 }
45 })
46 .filter(function (logString) { return logString; })
47 .join(' ');
48 };
49 return PlatformLoggerServiceImpl;
50}());
51/**
52 *
53 * @param provider check if this provider provides a VersionService
54 *
55 * NOTE: Using Provider<'app-version'> is a hack to indicate that the provider
56 * provides VersionService. The provider is not necessarily a 'app-version'
57 * provider.
58 */
59function isVersionServiceProvider(provider) {
60 var component = provider.getComponent();
61 return (component === null || component === void 0 ? void 0 : component.type) === "VERSION" /* VERSION */;
62}
63
64var name$o = "@firebase/app";
65var version$1 = "0.7.10";
66
67/**
68 * @license
69 * Copyright 2019 Google LLC
70 *
71 * Licensed under the Apache License, Version 2.0 (the "License");
72 * you may not use this file except in compliance with the License.
73 * You may obtain a copy of the License at
74 *
75 * http://www.apache.org/licenses/LICENSE-2.0
76 *
77 * Unless required by applicable law or agreed to in writing, software
78 * distributed under the License is distributed on an "AS IS" BASIS,
79 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
80 * See the License for the specific language governing permissions and
81 * limitations under the License.
82 */
83var logger = new logger$1.Logger('@firebase/app');
84
85var name$n = "@firebase/app-compat";
86
87var name$m = "@firebase/analytics-compat";
88
89var name$l = "@firebase/analytics";
90
91var name$k = "@firebase/app-check-compat";
92
93var name$j = "@firebase/app-check";
94
95var name$i = "@firebase/auth";
96
97var name$h = "@firebase/auth-compat";
98
99var name$g = "@firebase/database";
100
101var name$f = "@firebase/database-compat";
102
103var name$e = "@firebase/functions";
104
105var name$d = "@firebase/functions-compat";
106
107var name$c = "@firebase/installations";
108
109var name$b = "@firebase/installations-compat";
110
111var name$a = "@firebase/messaging";
112
113var name$9 = "@firebase/messaging-compat";
114
115var name$8 = "@firebase/performance";
116
117var name$7 = "@firebase/performance-compat";
118
119var name$6 = "@firebase/remote-config";
120
121var name$5 = "@firebase/remote-config-compat";
122
123var name$4 = "@firebase/storage";
124
125var name$3 = "@firebase/storage-compat";
126
127var name$2 = "@firebase/firestore";
128
129var name$1 = "@firebase/firestore-compat";
130
131var name = "firebase";
132var version = "9.6.0";
133
134/**
135 * @license
136 * Copyright 2019 Google LLC
137 *
138 * Licensed under the Apache License, Version 2.0 (the "License");
139 * you may not use this file except in compliance with the License.
140 * You may obtain a copy of the License at
141 *
142 * http://www.apache.org/licenses/LICENSE-2.0
143 *
144 * Unless required by applicable law or agreed to in writing, software
145 * distributed under the License is distributed on an "AS IS" BASIS,
146 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
147 * See the License for the specific language governing permissions and
148 * limitations under the License.
149 */
150var _a$1;
151/**
152 * The default app name
153 *
154 * @internal
155 */
156var DEFAULT_ENTRY_NAME = '[DEFAULT]';
157var PLATFORM_LOG_STRING = (_a$1 = {},
158 _a$1[name$o] = 'fire-core',
159 _a$1[name$n] = 'fire-core-compat',
160 _a$1[name$l] = 'fire-analytics',
161 _a$1[name$m] = 'fire-analytics-compat',
162 _a$1[name$j] = 'fire-app-check',
163 _a$1[name$k] = 'fire-app-check-compat',
164 _a$1[name$i] = 'fire-auth',
165 _a$1[name$h] = 'fire-auth-compat',
166 _a$1[name$g] = 'fire-rtdb',
167 _a$1[name$f] = 'fire-rtdb-compat',
168 _a$1[name$e] = 'fire-fn',
169 _a$1[name$d] = 'fire-fn-compat',
170 _a$1[name$c] = 'fire-iid',
171 _a$1[name$b] = 'fire-iid-compat',
172 _a$1[name$a] = 'fire-fcm',
173 _a$1[name$9] = 'fire-fcm-compat',
174 _a$1[name$8] = 'fire-perf',
175 _a$1[name$7] = 'fire-perf-compat',
176 _a$1[name$6] = 'fire-rc',
177 _a$1[name$5] = 'fire-rc-compat',
178 _a$1[name$4] = 'fire-gcs',
179 _a$1[name$3] = 'fire-gcs-compat',
180 _a$1[name$2] = 'fire-fst',
181 _a$1[name$1] = 'fire-fst-compat',
182 _a$1['fire-js'] = 'fire-js',
183 _a$1[name] = 'fire-js-all',
184 _a$1);
185
186/**
187 * @license
188 * Copyright 2019 Google LLC
189 *
190 * Licensed under the Apache License, Version 2.0 (the "License");
191 * you may not use this file except in compliance with the License.
192 * You may obtain a copy of the License at
193 *
194 * http://www.apache.org/licenses/LICENSE-2.0
195 *
196 * Unless required by applicable law or agreed to in writing, software
197 * distributed under the License is distributed on an "AS IS" BASIS,
198 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
199 * See the License for the specific language governing permissions and
200 * limitations under the License.
201 */
202/**
203 * @internal
204 */
205var _apps = new Map();
206/**
207 * Registered components.
208 *
209 * @internal
210 */
211// eslint-disable-next-line @typescript-eslint/no-explicit-any
212var _components = new Map();
213/**
214 * @param component - the component being added to this app's container
215 *
216 * @internal
217 */
218function _addComponent(app, component) {
219 try {
220 app.container.addComponent(component);
221 }
222 catch (e) {
223 logger.debug("Component " + component.name + " failed to register with FirebaseApp " + app.name, e);
224 }
225}
226/**
227 *
228 * @internal
229 */
230function _addOrOverwriteComponent(app, component) {
231 app.container.addOrOverwriteComponent(component);
232}
233/**
234 *
235 * @param component - the component to register
236 * @returns whether or not the component is registered successfully
237 *
238 * @internal
239 */
240function _registerComponent(component) {
241 var e_1, _a;
242 var componentName = component.name;
243 if (_components.has(componentName)) {
244 logger.debug("There were multiple attempts to register component " + componentName + ".");
245 return false;
246 }
247 _components.set(componentName, component);
248 try {
249 // add the component to existing app instances
250 for (var _b = tslib.__values(_apps.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
251 var app = _c.value;
252 _addComponent(app, component);
253 }
254 }
255 catch (e_1_1) { e_1 = { error: e_1_1 }; }
256 finally {
257 try {
258 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
259 }
260 finally { if (e_1) throw e_1.error; }
261 }
262 return true;
263}
264/**
265 *
266 * @param app - FirebaseApp instance
267 * @param name - service name
268 *
269 * @returns the provider for the service with the matching name
270 *
271 * @internal
272 */
273function _getProvider(app, name) {
274 return app.container.getProvider(name);
275}
276/**
277 *
278 * @param app - FirebaseApp instance
279 * @param name - service name
280 * @param instanceIdentifier - service instance identifier in case the service supports multiple instances
281 *
282 * @internal
283 */
284function _removeServiceInstance(app, name, instanceIdentifier) {
285 if (instanceIdentifier === void 0) { instanceIdentifier = DEFAULT_ENTRY_NAME; }
286 _getProvider(app, name).clearInstance(instanceIdentifier);
287}
288/**
289 * Test only
290 *
291 * @internal
292 */
293function _clearComponents() {
294 _components.clear();
295}
296
297/**
298 * @license
299 * Copyright 2019 Google LLC
300 *
301 * Licensed under the Apache License, Version 2.0 (the "License");
302 * you may not use this file except in compliance with the License.
303 * You may obtain a copy of the License at
304 *
305 * http://www.apache.org/licenses/LICENSE-2.0
306 *
307 * Unless required by applicable law or agreed to in writing, software
308 * distributed under the License is distributed on an "AS IS" BASIS,
309 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
310 * See the License for the specific language governing permissions and
311 * limitations under the License.
312 */
313var _a;
314var ERRORS = (_a = {},
315 _a["no-app" /* NO_APP */] = "No Firebase App '{$appName}' has been created - " +
316 'call Firebase App.initializeApp()',
317 _a["bad-app-name" /* BAD_APP_NAME */] = "Illegal App name: '{$appName}",
318 _a["duplicate-app" /* DUPLICATE_APP */] = "Firebase App named '{$appName}' already exists with different options or config",
319 _a["app-deleted" /* APP_DELETED */] = "Firebase App named '{$appName}' already deleted",
320 _a["invalid-app-argument" /* INVALID_APP_ARGUMENT */] = 'firebase.{$appName}() takes either no argument or a ' +
321 'Firebase App instance.',
322 _a["invalid-log-argument" /* INVALID_LOG_ARGUMENT */] = 'First argument to `onLog` must be null or a function.',
323 _a);
324var ERROR_FACTORY = new util.ErrorFactory('app', 'Firebase', ERRORS);
325
326/**
327 * @license
328 * Copyright 2019 Google LLC
329 *
330 * Licensed under the Apache License, Version 2.0 (the "License");
331 * you may not use this file except in compliance with the License.
332 * You may obtain a copy of the License at
333 *
334 * http://www.apache.org/licenses/LICENSE-2.0
335 *
336 * Unless required by applicable law or agreed to in writing, software
337 * distributed under the License is distributed on an "AS IS" BASIS,
338 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
339 * See the License for the specific language governing permissions and
340 * limitations under the License.
341 */
342var FirebaseAppImpl = /** @class */ (function () {
343 function FirebaseAppImpl(options, config, container) {
344 var _this = this;
345 this._isDeleted = false;
346 this._options = tslib.__assign({}, options);
347 this._config = tslib.__assign({}, config);
348 this._name = config.name;
349 this._automaticDataCollectionEnabled =
350 config.automaticDataCollectionEnabled;
351 this._container = container;
352 this.container.addComponent(new component.Component('app', function () { return _this; }, "PUBLIC" /* PUBLIC */));
353 }
354 Object.defineProperty(FirebaseAppImpl.prototype, "automaticDataCollectionEnabled", {
355 get: function () {
356 this.checkDestroyed();
357 return this._automaticDataCollectionEnabled;
358 },
359 set: function (val) {
360 this.checkDestroyed();
361 this._automaticDataCollectionEnabled = val;
362 },
363 enumerable: false,
364 configurable: true
365 });
366 Object.defineProperty(FirebaseAppImpl.prototype, "name", {
367 get: function () {
368 this.checkDestroyed();
369 return this._name;
370 },
371 enumerable: false,
372 configurable: true
373 });
374 Object.defineProperty(FirebaseAppImpl.prototype, "options", {
375 get: function () {
376 this.checkDestroyed();
377 return this._options;
378 },
379 enumerable: false,
380 configurable: true
381 });
382 Object.defineProperty(FirebaseAppImpl.prototype, "config", {
383 get: function () {
384 this.checkDestroyed();
385 return this._config;
386 },
387 enumerable: false,
388 configurable: true
389 });
390 Object.defineProperty(FirebaseAppImpl.prototype, "container", {
391 get: function () {
392 return this._container;
393 },
394 enumerable: false,
395 configurable: true
396 });
397 Object.defineProperty(FirebaseAppImpl.prototype, "isDeleted", {
398 get: function () {
399 return this._isDeleted;
400 },
401 set: function (val) {
402 this._isDeleted = val;
403 },
404 enumerable: false,
405 configurable: true
406 });
407 /**
408 * This function will throw an Error if the App has already been deleted -
409 * use before performing API actions on the App.
410 */
411 FirebaseAppImpl.prototype.checkDestroyed = function () {
412 if (this.isDeleted) {
413 throw ERROR_FACTORY.create("app-deleted" /* APP_DELETED */, { appName: this._name });
414 }
415 };
416 return FirebaseAppImpl;
417}());
418
419/**
420 * @license
421 * Copyright 2019 Google LLC
422 *
423 * Licensed under the Apache License, Version 2.0 (the "License");
424 * you may not use this file except in compliance with the License.
425 * You may obtain a copy of the License at
426 *
427 * http://www.apache.org/licenses/LICENSE-2.0
428 *
429 * Unless required by applicable law or agreed to in writing, software
430 * distributed under the License is distributed on an "AS IS" BASIS,
431 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
432 * See the License for the specific language governing permissions and
433 * limitations under the License.
434 */
435/**
436 * The current SDK version.
437 *
438 * @public
439 */
440var SDK_VERSION = version;
441function initializeApp(options, rawConfig) {
442 var e_1, _a;
443 if (rawConfig === void 0) { rawConfig = {}; }
444 if (typeof rawConfig !== 'object') {
445 var name_1 = rawConfig;
446 rawConfig = { name: name_1 };
447 }
448 var config = tslib.__assign({ name: DEFAULT_ENTRY_NAME, automaticDataCollectionEnabled: false }, rawConfig);
449 var name = config.name;
450 if (typeof name !== 'string' || !name) {
451 throw ERROR_FACTORY.create("bad-app-name" /* BAD_APP_NAME */, {
452 appName: String(name)
453 });
454 }
455 var existingApp = _apps.get(name);
456 if (existingApp) {
457 // return the existing app if options and config deep equal the ones in the existing app.
458 if (util.deepEqual(options, existingApp.options) &&
459 util.deepEqual(config, existingApp.config)) {
460 return existingApp;
461 }
462 else {
463 throw ERROR_FACTORY.create("duplicate-app" /* DUPLICATE_APP */, { appName: name });
464 }
465 }
466 var container = new component.ComponentContainer(name);
467 try {
468 for (var _b = tslib.__values(_components.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
469 var component$1 = _c.value;
470 container.addComponent(component$1);
471 }
472 }
473 catch (e_1_1) { e_1 = { error: e_1_1 }; }
474 finally {
475 try {
476 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
477 }
478 finally { if (e_1) throw e_1.error; }
479 }
480 var newApp = new FirebaseAppImpl(options, config, container);
481 _apps.set(name, newApp);
482 return newApp;
483}
484/**
485 * Retrieves a {@link @firebase/app#FirebaseApp} instance.
486 *
487 * When called with no arguments, the default app is returned. When an app name
488 * is provided, the app corresponding to that name is returned.
489 *
490 * An exception is thrown if the app being retrieved has not yet been
491 * initialized.
492 *
493 * @example
494 * ```javascript
495 * // Return the default app
496 * const app = getApp();
497 * ```
498 *
499 * @example
500 * ```javascript
501 * // Return a named app
502 * const otherApp = getApp("otherApp");
503 * ```
504 *
505 * @param name - Optional name of the app to return. If no name is
506 * provided, the default is `"[DEFAULT]"`.
507 *
508 * @returns The app corresponding to the provided app name.
509 * If no app name is provided, the default app is returned.
510 *
511 * @public
512 */
513function getApp(name) {
514 if (name === void 0) { name = DEFAULT_ENTRY_NAME; }
515 var app = _apps.get(name);
516 if (!app) {
517 throw ERROR_FACTORY.create("no-app" /* NO_APP */, { appName: name });
518 }
519 return app;
520}
521/**
522 * A (read-only) array of all initialized apps.
523 * @public
524 */
525function getApps() {
526 return Array.from(_apps.values());
527}
528/**
529 * Renders this app unusable and frees the resources of all associated
530 * services.
531 *
532 * @example
533 * ```javascript
534 * deleteApp(app)
535 * .then(function() {
536 * console.log("App deleted successfully");
537 * })
538 * .catch(function(error) {
539 * console.log("Error deleting app:", error);
540 * });
541 * ```
542 *
543 * @public
544 */
545function deleteApp(app) {
546 return tslib.__awaiter(this, void 0, void 0, function () {
547 var name;
548 return tslib.__generator(this, function (_a) {
549 switch (_a.label) {
550 case 0:
551 name = app.name;
552 if (!_apps.has(name)) return [3 /*break*/, 2];
553 _apps.delete(name);
554 return [4 /*yield*/, Promise.all(app.container
555 .getProviders()
556 .map(function (provider) { return provider.delete(); }))];
557 case 1:
558 _a.sent();
559 app.isDeleted = true;
560 _a.label = 2;
561 case 2: return [2 /*return*/];
562 }
563 });
564 });
565}
566/**
567 * Registers a library's name and version for platform logging purposes.
568 * @param library - Name of 1p or 3p library (e.g. firestore, angularfire)
569 * @param version - Current version of that library.
570 * @param variant - Bundle variant, e.g., node, rn, etc.
571 *
572 * @public
573 */
574function registerVersion(libraryKeyOrName, version, variant) {
575 var _a;
576 // TODO: We can use this check to whitelist strings when/if we set up
577 // a good whitelist system.
578 var library = (_a = PLATFORM_LOG_STRING[libraryKeyOrName]) !== null && _a !== void 0 ? _a : libraryKeyOrName;
579 if (variant) {
580 library += "-" + variant;
581 }
582 var libraryMismatch = library.match(/\s|\//);
583 var versionMismatch = version.match(/\s|\//);
584 if (libraryMismatch || versionMismatch) {
585 var warning = [
586 "Unable to register library \"" + library + "\" with version \"" + version + "\":"
587 ];
588 if (libraryMismatch) {
589 warning.push("library name \"" + library + "\" contains illegal characters (whitespace or \"/\")");
590 }
591 if (libraryMismatch && versionMismatch) {
592 warning.push('and');
593 }
594 if (versionMismatch) {
595 warning.push("version name \"" + version + "\" contains illegal characters (whitespace or \"/\")");
596 }
597 logger.warn(warning.join(' '));
598 return;
599 }
600 _registerComponent(new component.Component(library + "-version", function () { return ({ library: library, version: version }); }, "VERSION" /* VERSION */));
601}
602/**
603 * Sets log handler for all Firebase SDKs.
604 * @param logCallback - An optional custom log handler that executes user code whenever
605 * the Firebase SDK makes a logging call.
606 *
607 * @public
608 */
609function onLog(logCallback, options) {
610 if (logCallback !== null && typeof logCallback !== 'function') {
611 throw ERROR_FACTORY.create("invalid-log-argument" /* INVALID_LOG_ARGUMENT */);
612 }
613 logger$1.setUserLogHandler(logCallback, options);
614}
615/**
616 * Sets log level for all Firebase SDKs.
617 *
618 * All of the log types above the current log level are captured (i.e. if
619 * you set the log level to `info`, errors are logged, but `debug` and
620 * `verbose` logs are not).
621 *
622 * @public
623 */
624function setLogLevel(logLevel) {
625 logger$1.setLogLevel(logLevel);
626}
627
628/**
629 * @license
630 * Copyright 2019 Google LLC
631 *
632 * Licensed under the Apache License, Version 2.0 (the "License");
633 * you may not use this file except in compliance with the License.
634 * You may obtain a copy of the License at
635 *
636 * http://www.apache.org/licenses/LICENSE-2.0
637 *
638 * Unless required by applicable law or agreed to in writing, software
639 * distributed under the License is distributed on an "AS IS" BASIS,
640 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
641 * See the License for the specific language governing permissions and
642 * limitations under the License.
643 */
644function registerCoreComponents(variant) {
645 _registerComponent(new component.Component('platform-logger', function (container) { return new PlatformLoggerServiceImpl(container); }, "PRIVATE" /* PRIVATE */));
646 // Register `app` package.
647 registerVersion(name$o, version$1, variant);
648 // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
649 registerVersion(name$o, version$1, 'cjs5');
650 // Register platform SDK identifier (no version).
651 registerVersion('fire-js', '');
652}
653
654/**
655 * Firebase App
656 *
657 * @remarks This package coordinates the communication between the different Firebase components
658 * @packageDocumentation
659 */
660registerCoreComponents('node');
661
662Object.defineProperty(exports, 'FirebaseError', {
663 enumerable: true,
664 get: function () { return util.FirebaseError; }
665});
666exports.SDK_VERSION = SDK_VERSION;
667exports._DEFAULT_ENTRY_NAME = DEFAULT_ENTRY_NAME;
668exports._addComponent = _addComponent;
669exports._addOrOverwriteComponent = _addOrOverwriteComponent;
670exports._apps = _apps;
671exports._clearComponents = _clearComponents;
672exports._components = _components;
673exports._getProvider = _getProvider;
674exports._registerComponent = _registerComponent;
675exports._removeServiceInstance = _removeServiceInstance;
676exports.deleteApp = deleteApp;
677exports.getApp = getApp;
678exports.getApps = getApps;
679exports.initializeApp = initializeApp;
680exports.onLog = onLog;
681exports.registerVersion = registerVersion;
682exports.setLogLevel = setLogLevel;
683//# sourceMappingURL=index.cjs.js.map