GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

446 lines
17 KiB

2 months ago
  1. import { ErrorFactory, contains, deepExtend, createSubscribe, isBrowser } from '@firebase/util';
  2. import { __assign } from 'tslib';
  3. import { Component } from '@firebase/component';
  4. import * as modularAPIs from '@firebase/app';
  5. import { deleteApp, _addComponent, _addOrOverwriteComponent, _DEFAULT_ENTRY_NAME, registerVersion } from '@firebase/app';
  6. import { Logger } from '@firebase/logger';
  7. /**
  8. * @license
  9. * Copyright 2020 Google LLC
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. */
  23. /**
  24. * Global context object for a collection of services using
  25. * a shared authentication state.
  26. *
  27. * marked as internal because it references internal types exported from @firebase/app
  28. * @internal
  29. */
  30. var FirebaseAppImpl = /** @class */ (function () {
  31. function FirebaseAppImpl(_delegate, firebase) {
  32. var _this = this;
  33. this._delegate = _delegate;
  34. this.firebase = firebase;
  35. // add itself to container
  36. _addComponent(_delegate, new Component('app-compat', function () { return _this; }, "PUBLIC" /* ComponentType.PUBLIC */));
  37. this.container = _delegate.container;
  38. }
  39. Object.defineProperty(FirebaseAppImpl.prototype, "automaticDataCollectionEnabled", {
  40. get: function () {
  41. return this._delegate.automaticDataCollectionEnabled;
  42. },
  43. set: function (val) {
  44. this._delegate.automaticDataCollectionEnabled = val;
  45. },
  46. enumerable: false,
  47. configurable: true
  48. });
  49. Object.defineProperty(FirebaseAppImpl.prototype, "name", {
  50. get: function () {
  51. return this._delegate.name;
  52. },
  53. enumerable: false,
  54. configurable: true
  55. });
  56. Object.defineProperty(FirebaseAppImpl.prototype, "options", {
  57. get: function () {
  58. return this._delegate.options;
  59. },
  60. enumerable: false,
  61. configurable: true
  62. });
  63. FirebaseAppImpl.prototype.delete = function () {
  64. var _this = this;
  65. return new Promise(function (resolve) {
  66. _this._delegate.checkDestroyed();
  67. resolve();
  68. }).then(function () {
  69. _this.firebase.INTERNAL.removeApp(_this.name);
  70. return deleteApp(_this._delegate);
  71. });
  72. };
  73. /**
  74. * Return a service instance associated with this app (creating it
  75. * on demand), identified by the passed instanceIdentifier.
  76. *
  77. * NOTE: Currently storage and functions are the only ones that are leveraging this
  78. * functionality. They invoke it by calling:
  79. *
  80. * ```javascript
  81. * firebase.app().storage('STORAGE BUCKET ID')
  82. * ```
  83. *
  84. * The service name is passed to this already
  85. * @internal
  86. */
  87. FirebaseAppImpl.prototype._getService = function (name, instanceIdentifier) {
  88. var _a;
  89. if (instanceIdentifier === void 0) { instanceIdentifier = _DEFAULT_ENTRY_NAME; }
  90. this._delegate.checkDestroyed();
  91. // Initialize instance if InstatiationMode is `EXPLICIT`.
  92. var provider = this._delegate.container.getProvider(name);
  93. if (!provider.isInitialized() &&
  94. ((_a = provider.getComponent()) === null || _a === void 0 ? void 0 : _a.instantiationMode) === "EXPLICIT" /* InstantiationMode.EXPLICIT */) {
  95. provider.initialize();
  96. }
  97. // getImmediate will always succeed because _getService is only called for registered components.
  98. return provider.getImmediate({
  99. identifier: instanceIdentifier
  100. });
  101. };
  102. /**
  103. * Remove a service instance from the cache, so we will create a new instance for this service
  104. * when people try to get it again.
  105. *
  106. * NOTE: currently only firestore uses this functionality to support firestore shutdown.
  107. *
  108. * @param name The service name
  109. * @param instanceIdentifier instance identifier in case multiple instances are allowed
  110. * @internal
  111. */
  112. FirebaseAppImpl.prototype._removeServiceInstance = function (name, instanceIdentifier) {
  113. if (instanceIdentifier === void 0) { instanceIdentifier = _DEFAULT_ENTRY_NAME; }
  114. this._delegate.container
  115. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  116. .getProvider(name)
  117. .clearInstance(instanceIdentifier);
  118. };
  119. /**
  120. * @param component the component being added to this app's container
  121. * @internal
  122. */
  123. FirebaseAppImpl.prototype._addComponent = function (component) {
  124. _addComponent(this._delegate, component);
  125. };
  126. FirebaseAppImpl.prototype._addOrOverwriteComponent = function (component) {
  127. _addOrOverwriteComponent(this._delegate, component);
  128. };
  129. FirebaseAppImpl.prototype.toJSON = function () {
  130. return {
  131. name: this.name,
  132. automaticDataCollectionEnabled: this.automaticDataCollectionEnabled,
  133. options: this.options
  134. };
  135. };
  136. return FirebaseAppImpl;
  137. }());
  138. // TODO: investigate why the following needs to be commented out
  139. // Prevent dead-code elimination of these methods w/o invalid property
  140. // copying.
  141. // (FirebaseAppImpl.prototype.name && FirebaseAppImpl.prototype.options) ||
  142. // FirebaseAppImpl.prototype.delete ||
  143. // console.log('dc');
  144. /**
  145. * @license
  146. * Copyright 2019 Google LLC
  147. *
  148. * Licensed under the Apache License, Version 2.0 (the "License");
  149. * you may not use this file except in compliance with the License.
  150. * You may obtain a copy of the License at
  151. *
  152. * http://www.apache.org/licenses/LICENSE-2.0
  153. *
  154. * Unless required by applicable law or agreed to in writing, software
  155. * distributed under the License is distributed on an "AS IS" BASIS,
  156. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  157. * See the License for the specific language governing permissions and
  158. * limitations under the License.
  159. */
  160. var _a;
  161. var ERRORS = (_a = {},
  162. _a["no-app" /* AppError.NO_APP */] = "No Firebase App '{$appName}' has been created - " +
  163. 'call Firebase App.initializeApp()',
  164. _a["invalid-app-argument" /* AppError.INVALID_APP_ARGUMENT */] = 'firebase.{$appName}() takes either no argument or a ' +
  165. 'Firebase App instance.',
  166. _a);
  167. var ERROR_FACTORY = new ErrorFactory('app-compat', 'Firebase', ERRORS);
  168. /**
  169. * @license
  170. * Copyright 2019 Google LLC
  171. *
  172. * Licensed under the Apache License, Version 2.0 (the "License");
  173. * you may not use this file except in compliance with the License.
  174. * You may obtain a copy of the License at
  175. *
  176. * http://www.apache.org/licenses/LICENSE-2.0
  177. *
  178. * Unless required by applicable law or agreed to in writing, software
  179. * distributed under the License is distributed on an "AS IS" BASIS,
  180. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  181. * See the License for the specific language governing permissions and
  182. * limitations under the License.
  183. */
  184. /**
  185. * Because auth can't share code with other components, we attach the utility functions
  186. * in an internal namespace to share code.
  187. * This function return a firebase namespace object without
  188. * any utility functions, so it can be shared between the regular firebaseNamespace and
  189. * the lite version.
  190. */
  191. function createFirebaseNamespaceCore(firebaseAppImpl) {
  192. var apps = {};
  193. // // eslint-disable-next-line @typescript-eslint/no-explicit-any
  194. // const components = new Map<string, Component<any>>();
  195. // A namespace is a plain JavaScript Object.
  196. var namespace = {
  197. // Hack to prevent Babel from modifying the object returned
  198. // as the firebase namespace.
  199. // @ts-ignore
  200. __esModule: true,
  201. initializeApp: initializeAppCompat,
  202. // @ts-ignore
  203. app: app,
  204. registerVersion: modularAPIs.registerVersion,
  205. setLogLevel: modularAPIs.setLogLevel,
  206. onLog: modularAPIs.onLog,
  207. // @ts-ignore
  208. apps: null,
  209. SDK_VERSION: modularAPIs.SDK_VERSION,
  210. INTERNAL: {
  211. registerComponent: registerComponentCompat,
  212. removeApp: removeApp,
  213. useAsService: useAsService,
  214. modularAPIs: modularAPIs
  215. }
  216. };
  217. // Inject a circular default export to allow Babel users who were previously
  218. // using:
  219. //
  220. // import firebase from 'firebase';
  221. // which becomes: var firebase = require('firebase').default;
  222. //
  223. // instead of
  224. //
  225. // import * as firebase from 'firebase';
  226. // which becomes: var firebase = require('firebase');
  227. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  228. namespace['default'] = namespace;
  229. // firebase.apps is a read-only getter.
  230. Object.defineProperty(namespace, 'apps', {
  231. get: getApps
  232. });
  233. /**
  234. * Called by App.delete() - but before any services associated with the App
  235. * are deleted.
  236. */
  237. function removeApp(name) {
  238. delete apps[name];
  239. }
  240. /**
  241. * Get the App object for a given name (or DEFAULT).
  242. */
  243. function app(name) {
  244. name = name || modularAPIs._DEFAULT_ENTRY_NAME;
  245. if (!contains(apps, name)) {
  246. throw ERROR_FACTORY.create("no-app" /* AppError.NO_APP */, { appName: name });
  247. }
  248. return apps[name];
  249. }
  250. // @ts-ignore
  251. app['App'] = firebaseAppImpl;
  252. /**
  253. * Create a new App instance (name must be unique).
  254. *
  255. * This function is idempotent. It can be called more than once and return the same instance using the same options and config.
  256. */
  257. function initializeAppCompat(options, rawConfig) {
  258. if (rawConfig === void 0) { rawConfig = {}; }
  259. var app = modularAPIs.initializeApp(options, rawConfig);
  260. if (contains(apps, app.name)) {
  261. return apps[app.name];
  262. }
  263. var appCompat = new firebaseAppImpl(app, namespace);
  264. apps[app.name] = appCompat;
  265. return appCompat;
  266. }
  267. /*
  268. * Return an array of all the non-deleted FirebaseApps.
  269. */
  270. function getApps() {
  271. // Make a copy so caller cannot mutate the apps list.
  272. return Object.keys(apps).map(function (name) { return apps[name]; });
  273. }
  274. function registerComponentCompat(component) {
  275. var componentName = component.name;
  276. var componentNameWithoutCompat = componentName.replace('-compat', '');
  277. if (modularAPIs._registerComponent(component) &&
  278. component.type === "PUBLIC" /* ComponentType.PUBLIC */) {
  279. // create service namespace for public components
  280. // The Service namespace is an accessor function ...
  281. var serviceNamespace = function (appArg) {
  282. if (appArg === void 0) { appArg = app(); }
  283. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  284. if (typeof appArg[componentNameWithoutCompat] !== 'function') {
  285. // Invalid argument.
  286. // This happens in the following case: firebase.storage('gs:/')
  287. throw ERROR_FACTORY.create("invalid-app-argument" /* AppError.INVALID_APP_ARGUMENT */, {
  288. appName: componentName
  289. });
  290. }
  291. // Forward service instance lookup to the FirebaseApp.
  292. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  293. return appArg[componentNameWithoutCompat]();
  294. };
  295. // ... and a container for service-level properties.
  296. if (component.serviceProps !== undefined) {
  297. deepExtend(serviceNamespace, component.serviceProps);
  298. }
  299. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  300. namespace[componentNameWithoutCompat] = serviceNamespace;
  301. // Patch the FirebaseAppImpl prototype
  302. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  303. firebaseAppImpl.prototype[componentNameWithoutCompat] =
  304. // TODO: The eslint disable can be removed and the 'ignoreRestArgs'
  305. // option added to the no-explicit-any rule when ESlint releases it.
  306. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  307. function () {
  308. var args = [];
  309. for (var _i = 0; _i < arguments.length; _i++) {
  310. args[_i] = arguments[_i];
  311. }
  312. var serviceFxn = this._getService.bind(this, componentName);
  313. return serviceFxn.apply(this, component.multipleInstances ? args : []);
  314. };
  315. }
  316. return component.type === "PUBLIC" /* ComponentType.PUBLIC */
  317. ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
  318. namespace[componentNameWithoutCompat]
  319. : null;
  320. }
  321. // Map the requested service to a registered service name
  322. // (used to map auth to serverAuth service when needed).
  323. function useAsService(app, name) {
  324. if (name === 'serverAuth') {
  325. return null;
  326. }
  327. var useService = name;
  328. return useService;
  329. }
  330. return namespace;
  331. }
  332. /**
  333. * @license
  334. * Copyright 2019 Google LLC
  335. *
  336. * Licensed under the Apache License, Version 2.0 (the "License");
  337. * you may not use this file except in compliance with the License.
  338. * You may obtain a copy of the License at
  339. *
  340. * http://www.apache.org/licenses/LICENSE-2.0
  341. *
  342. * Unless required by applicable law or agreed to in writing, software
  343. * distributed under the License is distributed on an "AS IS" BASIS,
  344. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  345. * See the License for the specific language governing permissions and
  346. * limitations under the License.
  347. */
  348. /**
  349. * Return a firebase namespace object.
  350. *
  351. * In production, this will be called exactly once and the result
  352. * assigned to the 'firebase' global. It may be called multiple times
  353. * in unit tests.
  354. */
  355. function createFirebaseNamespace() {
  356. var namespace = createFirebaseNamespaceCore(FirebaseAppImpl);
  357. namespace.INTERNAL = __assign(__assign({}, namespace.INTERNAL), { createFirebaseNamespace: createFirebaseNamespace, extendNamespace: extendNamespace, createSubscribe: createSubscribe, ErrorFactory: ErrorFactory, deepExtend: deepExtend });
  358. /**
  359. * Patch the top-level firebase namespace with additional properties.
  360. *
  361. * firebase.INTERNAL.extendNamespace()
  362. */
  363. function extendNamespace(props) {
  364. deepExtend(namespace, props);
  365. }
  366. return namespace;
  367. }
  368. var firebase$1 = createFirebaseNamespace();
  369. /**
  370. * @license
  371. * Copyright 2019 Google LLC
  372. *
  373. * Licensed under the Apache License, Version 2.0 (the "License");
  374. * you may not use this file except in compliance with the License.
  375. * You may obtain a copy of the License at
  376. *
  377. * http://www.apache.org/licenses/LICENSE-2.0
  378. *
  379. * Unless required by applicable law or agreed to in writing, software
  380. * distributed under the License is distributed on an "AS IS" BASIS,
  381. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  382. * See the License for the specific language governing permissions and
  383. * limitations under the License.
  384. */
  385. var logger = new Logger('@firebase/app-compat');
  386. var name = "@firebase/app-compat";
  387. var version = "0.2.1";
  388. /**
  389. * @license
  390. * Copyright 2019 Google LLC
  391. *
  392. * Licensed under the Apache License, Version 2.0 (the "License");
  393. * you may not use this file except in compliance with the License.
  394. * You may obtain a copy of the License at
  395. *
  396. * http://www.apache.org/licenses/LICENSE-2.0
  397. *
  398. * Unless required by applicable law or agreed to in writing, software
  399. * distributed under the License is distributed on an "AS IS" BASIS,
  400. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  401. * See the License for the specific language governing permissions and
  402. * limitations under the License.
  403. */
  404. function registerCoreComponents(variant) {
  405. // Register `app` package.
  406. registerVersion(name, version, variant);
  407. }
  408. /**
  409. * @license
  410. * Copyright 2020 Google LLC
  411. *
  412. * Licensed under the Apache License, Version 2.0 (the "License");
  413. * you may not use this file except in compliance with the License.
  414. * You may obtain a copy of the License at
  415. *
  416. * http://www.apache.org/licenses/LICENSE-2.0
  417. *
  418. * Unless required by applicable law or agreed to in writing, software
  419. * distributed under the License is distributed on an "AS IS" BASIS,
  420. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  421. * See the License for the specific language governing permissions and
  422. * limitations under the License.
  423. */
  424. // Firebase Lite detection
  425. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  426. if (isBrowser() && self.firebase !== undefined) {
  427. logger.warn("\n Warning: Firebase is already defined in the global scope. Please make sure\n Firebase library is only loaded once.\n ");
  428. // eslint-disable-next-line
  429. var sdkVersion = self.firebase.SDK_VERSION;
  430. if (sdkVersion && sdkVersion.indexOf('LITE') >= 0) {
  431. logger.warn("\n Warning: You are trying to load Firebase while using Firebase Performance standalone script.\n You should load Firebase Performance with this instance of Firebase to avoid loading duplicate code.\n ");
  432. }
  433. }
  434. var firebase = firebase$1;
  435. registerCoreComponents();
  436. export { firebase as default };
  437. //# sourceMappingURL=index.esm5.js.map