|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2023 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +import { |
| 19 | + FirebaseAppCheckInternal, |
| 20 | + AppCheckInternalComponentName |
| 21 | +} from '@firebase/app-check-interop-types'; |
| 22 | +import { FirebaseApp } from '@firebase/app-types'; |
| 23 | +import { |
| 24 | + FirebaseAuthInternal, |
| 25 | + FirebaseAuthInternalName |
| 26 | +} from '@firebase/auth-interop-types'; |
| 27 | +import { |
| 28 | + Component, |
| 29 | + ComponentContainer, |
| 30 | + ComponentType, |
| 31 | + Provider |
| 32 | +} from '@firebase/component'; |
| 33 | + |
| 34 | +import { Database } from '../api.standalone'; |
| 35 | +import { repoManagerDatabaseFromApp } from '../api/Database'; |
| 36 | +import { setSDKVersion } from '../core/version'; |
| 37 | + |
| 38 | +/** |
| 39 | + * Used by console to create a database based on the app, |
| 40 | + * passed database URL and a custom auth implementation. |
| 41 | + * @internal |
| 42 | + * @param app - A valid FirebaseApp-like object |
| 43 | + * @param url - A valid Firebase databaseURL |
| 44 | + * @param version - custom version e.g. firebase-admin version |
| 45 | + * @param customAppCheckImpl - custom app check implementation |
| 46 | + * @param customAuthImpl - custom auth implementation |
| 47 | + */ |
| 48 | +export function _initStandalone({ |
| 49 | + app, |
| 50 | + url, |
| 51 | + version, |
| 52 | + customAuthImpl, |
| 53 | + customAppCheckImpl, |
| 54 | + nodeAdmin = false |
| 55 | +}: { |
| 56 | + app: FirebaseApp; |
| 57 | + url: string; |
| 58 | + version: string; |
| 59 | + customAuthImpl: FirebaseAuthInternal; |
| 60 | + customAppCheckImpl?: FirebaseAppCheckInternal; |
| 61 | + nodeAdmin?: boolean; |
| 62 | +}): Database { |
| 63 | + setSDKVersion(version); |
| 64 | + |
| 65 | + /** |
| 66 | + * ComponentContainer('database-standalone') is just a placeholder that doesn't perform |
| 67 | + * any actual function. |
| 68 | + */ |
| 69 | + const componentContainer = new ComponentContainer('database-standalone'); |
| 70 | + const authProvider = new Provider<FirebaseAuthInternalName>( |
| 71 | + 'auth-internal', |
| 72 | + componentContainer |
| 73 | + ); |
| 74 | + let appCheckProvider: Provider<AppCheckInternalComponentName>; |
| 75 | + if (customAppCheckImpl) { |
| 76 | + appCheckProvider = new Provider<AppCheckInternalComponentName>( |
| 77 | + 'app-check-internal', |
| 78 | + componentContainer |
| 79 | + ); |
| 80 | + appCheckProvider.setComponent( |
| 81 | + new Component( |
| 82 | + 'app-check-internal', |
| 83 | + () => customAppCheckImpl, |
| 84 | + ComponentType.PRIVATE |
| 85 | + ) |
| 86 | + ); |
| 87 | + } |
| 88 | + authProvider.setComponent( |
| 89 | + new Component('auth-internal', () => customAuthImpl, ComponentType.PRIVATE) |
| 90 | + ); |
| 91 | + |
| 92 | + return repoManagerDatabaseFromApp( |
| 93 | + app, |
| 94 | + authProvider, |
| 95 | + appCheckProvider, |
| 96 | + url, |
| 97 | + nodeAdmin |
| 98 | + ); |
| 99 | +} |
0 commit comments