(feat) initializeServerApp support for App Hosting auto init (#9151) · firebase/firebase-js-sdk@d91169f (original) (raw)

`@@ -37,6 +37,7 @@ import {

`

37

37

`_apps,

`

38

38

`_components,

`

39

39

`_isFirebaseApp,

`

``

40

`+

_isFirebaseServerAppSettings,

`

40

41

`_registerComponent,

`

41

42

`_serverApps

`

42

43

`} from './internal';

`

`@@ -106,6 +107,10 @@ export const SDK_VERSION = version;

`

106

107

` *

`

107

108

` * @returns The initialized app.

`

108

109

` *

`

``

110

`` +

``

``

111

`+

`

``

112

`` +

``

``

113

`+

`

109

114

` * @public

`

110

115

` */

`

111

116

`export function initializeApp(

`

`@@ -118,6 +123,9 @@ export function initializeApp(

`

118

123

` * @param options - Options to configure the app's services.

`

119

124

` * @param config - FirebaseApp Configuration

`

120

125

` *

`

``

126

`+

`

``

127

`+

`

``

128

`` +

``

121

129

` * @public

`

122

130

` */

`

123

131

`export function initializeApp(

`

`@@ -220,41 +228,75 @@ export function initializeApp(

`

220

228

` *

`

221

229

`` * @param options - Firebase.AppOptions to configure the app's services, or a

``

222

230

`` * a FirebaseApp instance which contains the AppOptions within.

``

223

``

`` -

``

``

231

`` +

``

224

232

` *

`

225

233

`` * @returns The initialized FirebaseServerApp.

``

226

234

` *

`

``

235

`+

`

``

236

`+

`

``

237

`+

`

``

238

`+

`

``

239

`+

`

227

240

` * @public

`

228

241

` */

`

229

242

`export function initializeServerApp(

`

230

243

`options: FirebaseOptions | FirebaseApp,

`

231

``

`-

config: FirebaseServerAppSettings

`

``

244

`+

config?: FirebaseServerAppSettings

`

232

245

`): FirebaseServerApp;

`

233

246

``

``

247

`+

/**

`

``

248

`+

`

``

249

`+

`

``

250

`` +

``

``

251

`+

`

``

252

`` +

``

``

253

`+

`

``

254

`+

`

``

255

`+

`

``

256

`+

`

``

257

`` +

``

``

258

`+

`

``

259

`+

`

``

260

`+

`

``

261

`+

*/

`

234

262

`export function initializeServerApp(

`

235

``

`-

_options: FirebaseOptions | FirebaseApp,

`

236

``

`-

_serverAppConfig: FirebaseServerAppSettings

`

``

263

`+

config?: FirebaseServerAppSettings

`

``

264

`+

): FirebaseServerApp;

`

``

265

`+

export function initializeServerApp(

`

``

266

`+

_options?: FirebaseApp | FirebaseServerAppSettings | FirebaseOptions,

`

``

267

`+

_serverAppConfig: FirebaseServerAppSettings = {}

`

237

268

`): FirebaseServerApp {

`

238

269

`if (isBrowser() && !isWebWorker()) {

`

239

270

`// FirebaseServerApp isn't designed to be run in browsers.

`

240

271

`throw ERROR_FACTORY.create(AppError.INVALID_SERVER_APP_ENVIRONMENT);

`

241

272

`}

`

242

273

``

243

``

`-

if (_serverAppConfig.automaticDataCollectionEnabled === undefined) {

`

244

``

`-

_serverAppConfig.automaticDataCollectionEnabled = true;

`

``

274

`+

let firebaseOptions: FirebaseOptions | undefined;

`

``

275

`+

let serverAppSettings: FirebaseServerAppSettings = _serverAppConfig || {};

`

``

276

+

``

277

`+

if (_options) {

`

``

278

`+

if (_isFirebaseApp(_options)) {

`

``

279

`+

firebaseOptions = _options.options;

`

``

280

`+

} else if (_isFirebaseServerAppSettings(_options)) {

`

``

281

`+

serverAppSettings = _options;

`

``

282

`+

} else {

`

``

283

`+

firebaseOptions = _options;

`

``

284

`+

}

`

245

285

`}

`

246

286

``

247

``

`-

let appOptions: FirebaseOptions;

`

248

``

`-

if (_isFirebaseApp(_options)) {

`

249

``

`-

appOptions = _options.options;

`

250

``

`-

} else {

`

251

``

`-

appOptions = _options;

`

``

287

`+

if (serverAppSettings.automaticDataCollectionEnabled === undefined) {

`

``

288

`+

serverAppSettings.automaticDataCollectionEnabled = true;

`

``

289

`+

}

`

``

290

+

``

291

`+

firebaseOptions ||= getDefaultAppConfig();

`

``

292

`+

if (!firebaseOptions) {

`

``

293

`+

throw ERROR_FACTORY.create(AppError.NO_OPTIONS);

`

252

294

`}

`

253

295

``

254

296

`// Build an app name based on a hash of the configuration options.

`

255

297

`const nameObj = {

`

256

``

`-

..._serverAppConfig,

`

257

``

`-

...appOptions

`

``

298

`+

...serverAppSettings,

`

``

299

`+

...firebaseOptions

`

258

300

`};

`

259

301

``

260

302

`// However, Do not mangle the name based on releaseOnDeref, since it will vary between the

`

`@@ -270,7 +312,7 @@ export function initializeServerApp(

`

270

312

`);

`

271

313

`};

`

272

314

``

273

``

`-

if (_serverAppConfig.releaseOnDeref !== undefined) {

`

``

315

`+

if (serverAppSettings.releaseOnDeref !== undefined) {

`

274

316

`if (typeof FinalizationRegistry === 'undefined') {

`

275

317

`throw ERROR_FACTORY.create(

`

276

318

`AppError.FINALIZATION_REGISTRY_NOT_SUPPORTED,

`

`@@ -283,7 +325,7 @@ export function initializeServerApp(

`

283

325

`const existingApp = _serverApps.get(nameString) as FirebaseServerApp;

`

284

326

`if (existingApp) {

`

285

327

`(existingApp as FirebaseServerAppImpl).incRefCount(

`

286

``

`-

_serverAppConfig.releaseOnDeref

`

``

328

`+

serverAppSettings.releaseOnDeref

`

287

329

`);

`

288

330

`return existingApp;

`

289

331

`}

`

`@@ -294,8 +336,8 @@ export function initializeServerApp(

`

294

336

`}

`

295

337

``

296

338

`const newApp = new FirebaseServerAppImpl(

`

297

``

`-

appOptions,

`

298

``

`-

_serverAppConfig,

`

``

339

`+

firebaseOptions,

`

``

340

`+

serverAppSettings,

`

299

341

`nameString,

`

300

342

`container

`

301

343

`);

`