Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Adding app-check entry point
  • Loading branch information
jamesdaniels committed Sep 10, 2021
commit 0f70c554297069c39e15deaef95bae3501b75a42
65 changes: 65 additions & 0 deletions src/app-check/app-check.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { NgModule, Optional, NgZone, InjectionToken, ModuleWithProviders, PLATFORM_ID } from '@angular/core';
import { AppCheck as FirebaseAppCheck } from 'firebase/app-check';
import { ɵgetDefaultInstanceOf, ɵmemoizeInstance, ɵAngularFireSchedulers, VERSION } from '@angular/fire';
import { AppCheck, AppCheckInstances, APP_CHECK_PROVIDER_NAME } from './app-check';
import { FirebaseApps, FirebaseApp } from '@angular/fire/app';
import { registerVersion } from 'firebase/app';

export const PROVIDED_APP_CHECK_INSTANCES = new InjectionToken<AppCheck[]>('angularfire2.app-check-instances');

export function defaultAppCheckInstanceFactory(provided: FirebaseAppCheck[]|undefined, defaultApp: FirebaseApp) {
const defaultAppCheck = ɵgetDefaultInstanceOf<FirebaseAppCheck>(APP_CHECK_PROVIDER_NAME, provided, defaultApp);
return new AppCheck(defaultAppCheck);
}

export function appCheckInstanceFactory(fn: () => FirebaseAppCheck) {
return (zone: NgZone) => {
return ɵmemoizeInstance<FirebaseAppCheck>(fn, zone);
};
}

const APP_CHECK_INSTANCES_PROVIDER = {
provide: AppCheckInstances,
deps: [
[new Optional(), PROVIDED_APP_CHECK_INSTANCES ],
]
};

const DEFAULT_APP_CHECK_INSTANCE_PROVIDER = {
provide: AppCheck,
useFactory: defaultAppCheckInstanceFactory,
deps: [
[new Optional(), PROVIDED_APP_CHECK_INSTANCES ],
FirebaseApp,
PLATFORM_ID,
]
};

@NgModule({
providers: [
DEFAULT_APP_CHECK_INSTANCE_PROVIDER,
APP_CHECK_INSTANCES_PROVIDER,
]
})
export class AppCheckModule {
constructor() {
registerVersion('angularfire', VERSION.full, 'app-check');
}
}

export function provideAppCheck(fn: () => FirebaseAppCheck): ModuleWithProviders<AppCheckModule> {
return {
ngModule: AppCheckModule,
providers: [{
provide: PROVIDED_APP_CHECK_INSTANCES,
useFactory: appCheckInstanceFactory(fn),
multi: true,
deps: [
NgZone,
PLATFORM_ID,
ɵAngularFireSchedulers,
FirebaseApps,
]
}]
};
}
31 changes: 31 additions & 0 deletions src/app-check/app-check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { AppCheck as FirebaseAppCheck } from 'firebase/app-check';
import { ɵgetAllInstancesOf } from '@angular/fire';
import { from, timer } from 'rxjs';
import { concatMap, distinct } from 'rxjs/operators';

export const APP_CHECK_PROVIDER_NAME = 'app-check';

// see notes in core/firebase.app.module.ts for why we're building the class like this
// tslint:disable-next-line:no-empty-interface
export interface AppCheck extends FirebaseAppCheck {}

export class AppCheck {
constructor(appCheck: FirebaseAppCheck) {
return appCheck;
}
}

// tslint:disable-next-line:no-empty-interface
export interface AppCheckInstances extends Array<FirebaseAppCheck> {}

export class AppCheckInstances {
// tslint:disable-next-line:ban-types
constructor() {
return ɵgetAllInstancesOf<FirebaseAppCheck>(APP_CHECK_PROVIDER_NAME);
}
}

export const appCheckInstance$ = timer(0, 300).pipe(
concatMap(() => from(ɵgetAllInstancesOf<FirebaseAppCheck>(APP_CHECK_PROVIDER_NAME))),
distinct(),
);
14 changes: 14 additions & 0 deletions src/app-check/firebase.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/app-check/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "../../node_modules/ng-packagr/package.schema.json",
"ngPackage": {
"lib": {
"umdModuleIds": {
"firebase/app-check": "firebase-app-check"
},
"entryFile": "public_api.ts"
}
}
}
3 changes: 3 additions & 0 deletions src/app-check/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { AppCheck, AppCheckInstances, appCheckInstance$ } from './app-check';
export { provideAppCheck, AppCheckModule } from './app-check.module';
export * from './firebase';
2 changes: 2 additions & 0 deletions src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ɵgetDefaultInstanceOf, ɵmemoizeInstance, ɵAngularFireSchedulers, VER
import { Auth, AuthInstances, AUTH_PROVIDER_NAME } from './auth';
import { FirebaseApps, FirebaseApp } from '@angular/fire/app';
import { registerVersion } from 'firebase/app';
import { AppCheckInstances } from '@angular/fire/app-check';

export const PROVIDED_AUTH_INSTANCES = new InjectionToken<Auth[]>('angularfire2.auth-instances');

Expand Down Expand Up @@ -59,6 +60,7 @@ export function provideAuth(fn: () => FirebaseAuth): ModuleWithProviders<AuthMod
PLATFORM_ID,
ɵAngularFireSchedulers,
FirebaseApps,
[new Optional(), AppCheckInstances ],
]
}]
};
Expand Down
3 changes: 2 additions & 1 deletion src/database/database.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NgModule, Optional, NgZone, InjectionToken, ModuleWithProviders } from '@angular/core';
import { Database as FirebaseDatabase } from 'firebase/database';

import { AuthInstances } from '@angular/fire/auth';
import { ɵgetDefaultInstanceOf, ɵmemoizeInstance, ɵAngularFireSchedulers, VERSION } from '@angular/fire';
import { Database, DatabaseInstances, DATABASE_PROVIDER_NAME } from './database';
import { FirebaseApps, FirebaseApp } from '@angular/fire/app';
import { registerVersion } from 'firebase/app';
import { AppCheckInstances } from '@angular/fire/app-check';

export const PROVIDED_DATABASE_INSTANCES = new InjectionToken<Database[]>('angularfire2.database-instances');

Expand Down Expand Up @@ -62,6 +62,7 @@ export function provideDatabase(fn: () => FirebaseDatabase): ModuleWithProviders
FirebaseApps,
// Database+Auth work better if Auth is loaded first
[new Optional(), AuthInstances ],
[new Optional(), AppCheckInstances ],
]
}]
};
Expand Down
2 changes: 2 additions & 0 deletions src/firestore/firestore.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ɵmemoizeInstance, ɵgetDefaultInstanceOf, ɵAngularFireSchedulers, VER
import { Firestore, FirestoreInstances, FIRESTORE_PROVIDER_NAME } from './firestore';
import { FirebaseApps, FirebaseApp } from '@angular/fire/app';
import { registerVersion } from 'firebase/app';
import { AppCheckInstances } from '@angular/fire/app-check';

export const PROVIDED_FIRESTORE_INSTANCES = new InjectionToken<Firestore[]>('angularfire2.firestore-instances');

Expand Down Expand Up @@ -63,6 +64,7 @@ export function provideFirestore(fn: () => FirebaseFirestore): ModuleWithProvide
FirebaseApps,
// Firestore+Auth work better if Auth is loaded first
[new Optional(), AuthInstances ],
[new Optional(), AppCheckInstances ],
]
}]
};
Expand Down
2 changes: 2 additions & 0 deletions src/functions/functions.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Functions, FunctionsInstances, FUNCTIONS_PROVIDER_NAME } from './functi
import { FirebaseApps, FirebaseApp } from '@angular/fire/app';
import { AuthInstances } from '@angular/fire/auth';
import { registerVersion } from 'firebase/app';
import { AppCheckInstances } from '@angular/fire/app-check';

export const PROVIDED_FUNCTIONS_INSTANCES = new InjectionToken<Functions[]>('angularfire2.functions-instances');

Expand Down Expand Up @@ -61,6 +62,7 @@ export function provideFunctions(fn: () => FirebaseFunctions): ModuleWithProvide
FirebaseApps,
// Defensively load Auth first, if provided
[new Optional(), AuthInstances ],
[new Optional(), AppCheckInstances ],
]
}]
};
Expand Down
2 changes: 2 additions & 0 deletions src/storage/storage.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Storage, StorageInstances, STORAGE_PROVIDER_NAME } from './storage';
import { FirebaseApps, FirebaseApp } from '@angular/fire/app';
import { AuthInstances } from '@angular/fire/auth';
import { registerVersion } from 'firebase/app';
import { AppCheckInstances } from '@angular/fire/app-check';

export const PROVIDED_STORAGE_INSTANCES = new InjectionToken<Storage[]>('angularfire2.storage-instances');

Expand Down Expand Up @@ -61,6 +62,7 @@ export function provideStorage(fn: () => FirebaseStorage): ModuleWithProviders<S
FirebaseApps,
// Defensively load Auth first, if provided
[new Optional(), AuthInstances ],
[new Optional(), AppCheckInstances ],
]
}]
};
Expand Down
3 changes: 2 additions & 1 deletion tools/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as glob from 'glob';

// TODO infer these from the package.json
const MODULES = [
'core', 'app', 'compat', 'analytics', 'auth', 'database', 'firestore', 'functions',
'core', 'app', 'app-check', 'compat', 'analytics', 'auth', 'database', 'firestore', 'functions',
'remote-config', 'storage', 'messaging', 'performance', 'compat/analytics',
'compat/auth-guard', 'compat/auth', 'compat/database', 'compat/firestore',
'compat/functions', 'compat/remote-config', 'compat/storage', 'compat/messaging',
Expand Down Expand Up @@ -60,6 +60,7 @@ ${zoneWrapped.map(([importName, exportName]) => `export const ${exportName} = ɵ
return Promise.all([
reexport('analytics', 'firebase', 'firebase/analytics', tsKeys<typeof import('firebase/analytics')>()),
reexport('app', 'firebase', 'firebase/app', tsKeys<typeof import('firebase/app')>()),
reexport('app-check', 'firebase', 'firebase/app-check', tsKeys<typeof import('firebase/app-check')>()),
reexport('auth', 'rxfire', 'rxfire/auth', tsKeys<typeof import('rxfire/auth')>()),
reexport('auth', 'firebase', 'firebase/auth', tsKeys<typeof import('firebase/auth')>(), {
debugErrorMap: null,
Expand Down