@tech4good/angular-schematics 17.0.4 → 18.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/package.json +4 -4
- package/src/collection.json +0 -16
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.ts.template +22 -8
- package/src/component/index.js +2 -45
- package/src/component/index.js.map +1 -1
- package/src/component/schema.json +0 -5
- package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +12 -0
- package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +1 -0
- package/src/entity/files/__name@dasherize__/__name@dasherize__.store.ts.template +41 -0
- package/src/entity/index.js +29 -50
- package/src/entity/index.js.map +1 -1
- package/src/init/files/.firebaserc.template +8 -0
- package/src/init/files/README.md.template +6 -6
- package/src/init/files/angular.json.template +18 -11
- package/src/init/files/package.json.template +29 -30
- package/src/init/files/src/app/admin/{waitlist/waitlist.animations.ts.template → admin-panel/admin-panel.animations.ts.template} +1 -1
- package/src/init/files/src/app/admin/{waitlist/waitlist.component.html.template → admin-panel/admin-panel.component.html.template} +3 -3
- package/src/init/files/src/app/admin/{waitlist/waitlist.component.scss.template → admin-panel/admin-panel.component.scss.template} +1 -1
- package/src/init/files/src/app/admin/admin-panel/admin-panel.component.spec.ts.template +25 -0
- package/src/init/files/src/app/admin/admin-panel/admin-panel.component.ts.template +99 -0
- package/src/init/files/src/app/app.component.html.template +1 -0
- package/src/init/files/src/app/app.component.ts.template +14 -8
- package/src/init/files/src/app/app.config.ts.template +63 -0
- package/src/init/files/src/app/app.routes.ts.template +32 -0
- package/src/init/files/src/app/core/analytics/log.service.ts.template +122 -89
- package/src/init/files/src/app/core/analytics/time-analytics.service.ts.template +9 -17
- package/src/init/files/src/app/core/auth/auth.guard.ts.template +25 -22
- package/src/init/files/src/app/core/firebase/cached-listeners.service.ts.template +291 -0
- package/src/init/files/src/app/core/firebase/database.service.ts.template +56 -0
- package/src/init/files/src/app/core/firebase/firebase.mock.service.ts.template +276 -0
- package/src/init/files/src/app/core/firebase/firebase.service.ts.template +265 -215
- package/src/init/files/src/app/core/local-storage/session.service.ts.template +3 -4
- package/src/init/files/src/app/core/store/app.model.ts.template +19 -0
- package/src/init/files/src/app/core/store/app.store.ts.template +1074 -0
- package/src/init/files/src/app/core/store/auth/auth.mock.ts.template +20 -0
- package/src/init/files/src/app/core/store/auth/auth.store.ts.template +136 -0
- package/src/init/files/src/app/core/store/batch-write.firebase.service.ts.template +58 -0
- package/src/init/files/src/app/core/store/batch-write.mock.service.ts.template +105 -0
- package/src/init/files/src/app/core/store/batch-write.service.ts.template +126 -0
- package/src/init/files/src/app/core/store/user/user.mock.ts.template +24 -0
- package/src/init/files/src/app/core/store/user/user.model.ts.template +1 -1
- package/src/init/files/src/app/core/store/user/user.store.ts.template +41 -0
- package/src/init/files/src/app/core/store/user-context/user-context.mock.ts.template +24 -0
- package/src/init/files/src/app/core/store/user-context/user-context.model.ts.template +1 -0
- package/src/init/files/src/app/core/store/user-context/user-context.store.ts.template +41 -0
- package/src/init/files/src/app/core/utils/rand.utils.ts.template +13 -0
- package/src/init/files/src/app/{onboarding → first-time}/consent/consent.component.html.template +8 -13
- package/src/init/files/src/app/first-time/consent/consent.component.ts.template +90 -0
- package/src/init/files/src/app/first-time/early-access/early-access.animations.ts.template +4 -0
- package/src/init/files/src/app/first-time/early-access/early-access.component.html.template +69 -0
- package/src/init/files/src/app/{onboarding/waiting/waiting.component.scss.template → first-time/early-access/early-access.component.scss.template} +1 -1
- package/src/init/files/src/app/first-time/early-access/early-access.component.spec.ts.template +25 -0
- package/src/init/files/src/app/first-time/early-access/early-access.component.ts.template +194 -0
- package/src/init/files/src/app/first-time/early-access/early-access.model.ts.template +7 -0
- package/src/init/files/src/app/{general → first-time}/landing/landing.component.html.template +1 -1
- package/src/init/files/src/app/first-time/landing/landing.component.ts.template +44 -0
- package/src/init/files/src/app/first-time/login/login.component.html.template +10 -0
- package/src/init/files/src/app/first-time/login/login.component.ts.template +45 -0
- package/src/init/files/src/app/first-time/onboarding/onboarding.animations.ts.template +4 -0
- package/src/init/files/src/app/first-time/onboarding/onboarding.component.html.template +2 -0
- package/src/init/files/src/app/first-time/onboarding/onboarding.component.scss.template +5 -0
- package/src/init/files/src/app/{admin/waitlist/waitlist.component.spec.ts.template → first-time/onboarding/onboarding.component.spec.ts.template} +6 -6
- package/src/init/files/src/app/first-time/onboarding/onboarding.component.ts.template +41 -0
- package/src/init/files/src/app/main/home/home.component.html.template +5 -0
- package/src/init/files/src/app/main/home/home.component.ts.template +51 -0
- package/src/init/files/src/app/shared/navbar/navbar.component.html.template +15 -0
- package/src/init/files/src/app/shared/navbar/navbar.component.scss.template +43 -0
- package/src/init/files/src/app/shared/navbar/navbar.component.spec.ts.template +25 -0
- package/src/init/files/src/app/shared/navbar/navbar.component.ts.template +40 -0
- package/src/init/files/src/app/shared/redeployment-warning/redeployment-warning.component.html.template +9 -0
- package/src/init/files/src/app/shared/{components/redeployment-warning → redeployment-warning}/redeployment-warning.component.ts.template +17 -6
- package/src/init/files/src/app/shared/{components/redeployment-warning → redeployment-warning}/redeployment-warning.service.ts.template +2 -2
- package/src/init/files/src/assets/images/close-x.svg +3 -0
- package/src/init/files/src/environments/environment.ts.template +1 -0
- package/src/init/files/src/index.html.template +1 -1
- package/src/init/files/tsconfig.json.template +0 -1
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.actions.ts.template +0 -26
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.effects.ts.template +0 -48
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.model.ts.template +0 -0
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.selectors.ts.template +0 -20
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.state.ts.template +0 -13
- package/src/container/files/__name@dasherize__/__name@dasherize__.animations.ts.template +0 -4
- package/src/container/files/__name@dasherize__/__name@dasherize__.component.html.template +0 -3
- package/src/container/files/__name@dasherize__/__name@dasherize__.component.scss.template +0 -5
- package/src/container/files/__name@dasherize__/__name@dasherize__.component.spec.ts.template +0 -25
- package/src/container/files/__name@dasherize__/__name@dasherize__.component.ts.template +0 -90
- package/src/container/index.d.ts +0 -2
- package/src/container/index.js +0 -127
- package/src/container/index.js.map +0 -1
- package/src/container/index_spec.d.ts +0 -1
- package/src/container/index_spec.js +0 -23
- package/src/container/index_spec.js.map +0 -1
- package/src/container/schema.json +0 -50
- package/src/entity/files/__name@dasherize__/__name@dasherize__.actions.ts.template +0 -249
- package/src/entity/files/__name@dasherize__/__name@dasherize__.effects.ts.template +0 -131
- package/src/entity/files/__name@dasherize__/__name@dasherize__.reducer.spec.ts.template +0 -13
- package/src/entity/files/__name@dasherize__/__name@dasherize__.reducer.ts.template +0 -51
- package/src/entity/files/__name@dasherize__/__name@dasherize__.service.ts.template +0 -50
- package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.actions.ts.template +0 -270
- package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.effects.ts.template +0 -131
- package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.model.ts.template +0 -3
- package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.reducer.spec.ts.template +0 -13
- package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.reducer.ts.template +0 -51
- package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.service.ts.template +0 -50
- package/src/entity-in-example/index.d.ts +0 -2
- package/src/entity-in-example/index.js +0 -141
- package/src/entity-in-example/index.js.map +0 -1
- package/src/entity-in-example/index_spec.d.ts +0 -1
- package/src/entity-in-example/index_spec.js +0 -23
- package/src/entity-in-example/index_spec.js.map +0 -1
- package/src/entity-in-example/schema.json +0 -45
- package/src/init/files/CHANGELOG.md.template +0 -10
- package/src/init/files/src/app/admin/admin-routing.module.ts.template +0 -17
- package/src/init/files/src/app/admin/admin.module.spec.ts.template +0 -13
- package/src/init/files/src/app/admin/admin.module.ts.template +0 -28
- package/src/init/files/src/app/admin/waitlist/+state/waitlist.actions.ts.template +0 -23
- package/src/init/files/src/app/admin/waitlist/+state/waitlist.effects.ts.template +0 -50
- package/src/init/files/src/app/admin/waitlist/+state/waitlist.model.ts.template +0 -0
- package/src/init/files/src/app/admin/waitlist/+state/waitlist.selectors.ts.template +0 -39
- package/src/init/files/src/app/admin/waitlist/+state/waitlist.state.ts.template +0 -13
- package/src/init/files/src/app/admin/waitlist/waitlist.component.ts.template +0 -141
- package/src/init/files/src/app/app-routing.module.ts.template +0 -26
- package/src/init/files/src/app/app.module.ts.template +0 -34
- package/src/init/files/src/app/core/core.module.ts.template +0 -75
- package/src/init/files/src/app/core/setup/firebase-setup.ts.template +0 -25
- package/src/init/files/src/app/core/setup/module-import-guard.ts.template +0 -5
- package/src/init/files/src/app/core/snackbar/snackbar.actions.ts.template +0 -24
- package/src/init/files/src/app/core/snackbar/snackbar.effects.ts.template +0 -41
- package/src/init/files/src/app/core/store/app-state/app-state.actions.ts.template +0 -249
- package/src/init/files/src/app/core/store/app-state/app-state.effects.ts.template +0 -131
- package/src/init/files/src/app/core/store/app-state/app-state.model.ts.template +0 -8
- package/src/init/files/src/app/core/store/app-state/app-state.reducer.spec.ts.template +0 -13
- package/src/init/files/src/app/core/store/app-state/app-state.reducer.ts.template +0 -51
- package/src/init/files/src/app/core/store/app-state/app-state.service.ts.template +0 -50
- package/src/init/files/src/app/core/store/app.actions.ts.template +0 -92
- package/src/init/files/src/app/core/store/app.effects.ts.template +0 -175
- package/src/init/files/src/app/core/store/app.reducer.ts.template +0 -36
- package/src/init/files/src/app/core/store/app.selectors.ts.template +0 -42
- package/src/init/files/src/app/core/store/auth/auth.actions.ts.template +0 -77
- package/src/init/files/src/app/core/store/auth/auth.effects.ts.template +0 -163
- package/src/init/files/src/app/core/store/auth/auth.reducer.spec.ts.template +0 -13
- package/src/init/files/src/app/core/store/auth/auth.reducer.ts.template +0 -26
- package/src/init/files/src/app/core/store/auth/auth.selectors.ts.template +0 -25
- package/src/init/files/src/app/core/store/cached-load-connections.service.ts.template +0 -405
- package/src/init/files/src/app/core/store/cached-selectors.service.ts.template +0 -376
- package/src/init/files/src/app/core/store/effects.helpers.ts.template +0 -66
- package/src/init/files/src/app/core/store/user/user.actions.ts.template +0 -248
- package/src/init/files/src/app/core/store/user/user.effects.ts.template +0 -148
- package/src/init/files/src/app/core/store/user/user.reducer.spec.ts.template +0 -13
- package/src/init/files/src/app/core/store/user/user.reducer.ts.template +0 -50
- package/src/init/files/src/app/core/store/user/user.service.ts.template +0 -50
- package/src/init/files/src/app/core/store/user-context/user-context.actions.ts.template +0 -248
- package/src/init/files/src/app/core/store/user-context/user-context.effects.ts.template +0 -131
- package/src/init/files/src/app/core/store/user-context/user-context.reducer.spec.ts.template +0 -13
- package/src/init/files/src/app/core/store/user-context/user-context.reducer.ts.template +0 -51
- package/src/init/files/src/app/core/store/user-context/user-context.service.ts.template +0 -50
- package/src/init/files/src/app/core/utils/string-case.utils.ts.template +0 -96
- package/src/init/files/src/app/general/general-routing.module.ts.template +0 -25
- package/src/init/files/src/app/general/general.module.spec.ts.template +0 -13
- package/src/init/files/src/app/general/general.module.ts.template +0 -36
- package/src/init/files/src/app/general/home/+state/home.actions.ts.template +0 -26
- package/src/init/files/src/app/general/home/+state/home.effects.ts.template +0 -48
- package/src/init/files/src/app/general/home/+state/home.model.ts.template +0 -0
- package/src/init/files/src/app/general/home/+state/home.selectors.ts.template +0 -20
- package/src/init/files/src/app/general/home/+state/home.state.ts.template +0 -13
- package/src/init/files/src/app/general/home/home.component.html.template +0 -5
- package/src/init/files/src/app/general/home/home.component.ts.template +0 -88
- package/src/init/files/src/app/general/landing/+state/landing.actions.ts.template +0 -26
- package/src/init/files/src/app/general/landing/+state/landing.effects.ts.template +0 -48
- package/src/init/files/src/app/general/landing/+state/landing.model.ts.template +0 -0
- package/src/init/files/src/app/general/landing/+state/landing.selectors.ts.template +0 -20
- package/src/init/files/src/app/general/landing/+state/landing.state.ts.template +0 -13
- package/src/init/files/src/app/general/landing/landing.component.ts.template +0 -98
- package/src/init/files/src/app/general/login/login.component.html.template +0 -11
- package/src/init/files/src/app/general/login/login.component.ts.template +0 -80
- package/src/init/files/src/app/onboarding/consent/+state/consent.actions.ts.template +0 -23
- package/src/init/files/src/app/onboarding/consent/+state/consent.effects.ts.template +0 -47
- package/src/init/files/src/app/onboarding/consent/+state/consent.model.ts.template +0 -0
- package/src/init/files/src/app/onboarding/consent/+state/consent.selectors.ts.template +0 -20
- package/src/init/files/src/app/onboarding/consent/+state/consent.state.ts.template +0 -13
- package/src/init/files/src/app/onboarding/consent/consent.component.ts.template +0 -151
- package/src/init/files/src/app/onboarding/onboarding-routing.module.ts.template +0 -19
- package/src/init/files/src/app/onboarding/onboarding.module.spec.ts.template +0 -13
- package/src/init/files/src/app/onboarding/onboarding.module.ts.template +0 -32
- package/src/init/files/src/app/onboarding/waiting/+state/waiting.actions.ts.template +0 -26
- package/src/init/files/src/app/onboarding/waiting/+state/waiting.effects.ts.template +0 -52
- package/src/init/files/src/app/onboarding/waiting/+state/waiting.model.ts.template +0 -9
- package/src/init/files/src/app/onboarding/waiting/+state/waiting.selectors.ts.template +0 -42
- package/src/init/files/src/app/onboarding/waiting/+state/waiting.state.ts.template +0 -13
- package/src/init/files/src/app/onboarding/waiting/waiting.animations.ts.template +0 -4
- package/src/init/files/src/app/onboarding/waiting/waiting.component.html.template +0 -57
- package/src/init/files/src/app/onboarding/waiting/waiting.component.spec.ts.template +0 -25
- package/src/init/files/src/app/onboarding/waiting/waiting.component.ts.template +0 -281
- package/src/init/files/src/app/shared/components/redeployment-warning/redeployment-warning.component.html.template +0 -10
- package/src/init/files/src/app/shared/shared.module.ts.template +0 -87
- package/src/init/files/src/main.ts.template +0 -12
- package/src/module/files/__name@dasherize__/__name@dasherize__-routing.module.ts.template +0 -15
- package/src/module/files/__name@dasherize__/__name@dasherize__.module.spec.ts.template +0 -13
- package/src/module/files/__name@dasherize__/__name@dasherize__.module.ts.template +0 -24
- package/src/module/index.d.ts +0 -2
- package/src/module/index.js +0 -97
- package/src/module/index.js.map +0 -1
- package/src/module/index_spec.d.ts +0 -1
- package/src/module/index_spec.js +0 -23
- package/src/module/index_spec.js.map +0 -1
- package/src/module/schema.json +0 -38
- /package/src/init/files/src/app/{onboarding → first-time}/consent/consent.animations.ts.template +0 -0
- /package/src/init/files/src/app/{onboarding → first-time}/consent/consent.component.scss.template +0 -0
- /package/src/init/files/src/app/{onboarding → first-time}/consent/consent.component.spec.ts.template +0 -0
- /package/src/init/files/src/app/{general → first-time}/landing/landing.animations.ts.template +0 -0
- /package/src/init/files/src/app/{general → first-time}/landing/landing.component.scss.template +0 -0
- /package/src/init/files/src/app/{general → first-time}/landing/landing.component.spec.ts.template +0 -0
- /package/src/init/files/src/app/{general → first-time}/login/login.component.scss.template +0 -0
- /package/src/init/files/src/app/{general → first-time}/login/login.component.spec.ts.template +0 -0
- /package/src/init/files/src/app/{general → main}/home/home.animations.ts.template +0 -0
- /package/src/init/files/src/app/{general → main}/home/home.component.scss.template +0 -0
- /package/src/init/files/src/app/{general → main}/home/home.component.spec.ts.template +0 -0
- /package/src/init/files/src/app/shared/{components/redeployment-warning → redeployment-warning}/redeployment-warning.component.scss.template +0 -0
- /package/src/init/files/src/app/shared/{components/redeployment-warning → redeployment-warning}/redeployment-warning.component.spec.ts.template +0 -0
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
2
|
-
import { Router } from '@angular/router';
|
|
3
|
-
import { Action } from '@ngrx/store';
|
|
4
|
-
import { Actions, createEffect, ofType } from '@ngrx/effects';
|
|
5
|
-
import { of, Observable, merge } from 'rxjs';
|
|
6
|
-
import { tap, filter, mergeMap, map, first } from 'rxjs/operators';
|
|
7
|
-
import { pipe, forkJoin } from 'rxjs';
|
|
8
|
-
import { EffectsHelpers } from './effects.helpers';
|
|
9
|
-
import { FirebaseService } from '../firebase/firebase.service';
|
|
10
|
-
import { Store, select } from '@ngrx/store';
|
|
11
|
-
import * as fromStore from './app.reducer';
|
|
12
|
-
|
|
13
|
-
import { GeneralActionTypes, Unsubscribe, ActionSetResult, ActionSet, ActionSetResponse, ActionFlow, RouterNavigate } from './app.actions';
|
|
14
|
-
import { CachedLoadConnectionsService } from './cached-load-connections.service';
|
|
15
|
-
|
|
16
|
-
@Injectable()
|
|
17
|
-
export class AppEffects {
|
|
18
|
-
/** Process the router navigate action to use the Angular Router. */
|
|
19
|
-
routerNavigate$: Observable<Action> = createEffect(
|
|
20
|
-
() => this.actions$.pipe(
|
|
21
|
-
ofType(GeneralActionTypes.ROUTER_NAVIGATE),
|
|
22
|
-
tap((action: RouterNavigate) => {
|
|
23
|
-
this.router.navigate(action.commands, action.extras);
|
|
24
|
-
}),
|
|
25
|
-
),
|
|
26
|
-
{ dispatch: false },
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
/** Process the unsubscribe action. */
|
|
30
|
-
unsubscribe$: Observable<Action> = createEffect(
|
|
31
|
-
() => this.actions$.pipe(
|
|
32
|
-
ofType(GeneralActionTypes.UNSUBSCRIBE),
|
|
33
|
-
tap((action: Unsubscribe) => {
|
|
34
|
-
this.cachedConnections.disconnect(action);
|
|
35
|
-
}),
|
|
36
|
-
),
|
|
37
|
-
{ dispatch: false },
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
/** Process a generic action flow. */
|
|
41
|
-
actionFlow$: Observable<Action> = createEffect(
|
|
42
|
-
() => this.actions$.pipe(
|
|
43
|
-
ofType<ActionFlow>(GeneralActionTypes.ACTION_FLOW),
|
|
44
|
-
// should have at least one action
|
|
45
|
-
filter((af) => af.payload.actionSets.length > 0),
|
|
46
|
-
mergeMap((actionFlow: ActionFlow) => {
|
|
47
|
-
const responseFilters = [];
|
|
48
|
-
|
|
49
|
-
// Set loading subject to true
|
|
50
|
-
if (actionFlow.payload.loading$) {
|
|
51
|
-
actionFlow.payload.loading$.next(true);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Dispatch the primary actions and listen to the responses
|
|
55
|
-
const responseObsArr = actionFlow.payload.actionSets.map((actionSet) => {
|
|
56
|
-
// Set a correlationId
|
|
57
|
-
let correlationId;
|
|
58
|
-
if (!actionSet.action['correlationId']) {
|
|
59
|
-
correlationId = this.db.createId();
|
|
60
|
-
actionSet.action['correlationId'] = correlationId;
|
|
61
|
-
} else {
|
|
62
|
-
correlationId = actionSet.action['correlationId'];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Dispatch the action
|
|
66
|
-
this.store.dispatch(actionSet.action);
|
|
67
|
-
|
|
68
|
-
// If no filter, then responseAction is undefined
|
|
69
|
-
if (!actionSet.responseActionTypes) {
|
|
70
|
-
return of(Object.assign({}, actionSet, {
|
|
71
|
-
result: ActionSetResult.NONE,
|
|
72
|
-
responseAction: undefined,
|
|
73
|
-
}));
|
|
74
|
-
} else {
|
|
75
|
-
let successResponseTypeArr = [];
|
|
76
|
-
if (Array.isArray(actionSet.responseActionTypes.success)) {
|
|
77
|
-
successResponseTypeArr = actionSet.responseActionTypes.success;
|
|
78
|
-
} else if (actionSet.responseActionTypes.success) {
|
|
79
|
-
successResponseTypeArr = [actionSet.responseActionTypes.success];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let failureResponseTypeArr = [];
|
|
83
|
-
if (Array.isArray(actionSet.responseActionTypes.failure)) {
|
|
84
|
-
failureResponseTypeArr = actionSet.responseActionTypes.failure;
|
|
85
|
-
} else if (actionSet.responseActionTypes.failure) {
|
|
86
|
-
failureResponseTypeArr = [actionSet.responseActionTypes.failure];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const filterTypes = [
|
|
90
|
-
...successResponseTypeArr,
|
|
91
|
-
...failureResponseTypeArr,
|
|
92
|
-
];
|
|
93
|
-
|
|
94
|
-
// listen for either success or fail action
|
|
95
|
-
return this.actions$.pipe(
|
|
96
|
-
ofType(...filterTypes),
|
|
97
|
-
this.eh.hasCorrelationId(correlationId),
|
|
98
|
-
first(),
|
|
99
|
-
map((responseAction) => {
|
|
100
|
-
if (successResponseTypeArr.includes(responseAction.type)) {
|
|
101
|
-
return Object.assign({}, actionSet, {
|
|
102
|
-
result: ActionSetResult.SUCCESS,
|
|
103
|
-
responseAction,
|
|
104
|
-
});
|
|
105
|
-
} else {
|
|
106
|
-
return Object.assign({}, actionSet, {
|
|
107
|
-
result: ActionSetResult.FAILURE,
|
|
108
|
-
responseAction,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}),
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
// Call successActionFn or failActionFn depending on the results
|
|
117
|
-
// If no actions, we should run the success callback
|
|
118
|
-
if (responseObsArr.length === 0) {
|
|
119
|
-
// If there are no actions, just run the success callback
|
|
120
|
-
if (actionFlow.payload.successActionFn) {
|
|
121
|
-
return actionFlow.payload.successActionFn([]);
|
|
122
|
-
} else {
|
|
123
|
-
return [];
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
return forkJoin(responseObsArr).pipe(
|
|
127
|
-
mergeMap((actionSetResponses) => {
|
|
128
|
-
// Set the loading subject to false
|
|
129
|
-
if (actionFlow.payload.loading$) {
|
|
130
|
-
actionFlow.payload.loading$.next(false);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Figure out if it's a success or failure and emit the things necessary
|
|
134
|
-
if (actionSetResponses.some((r) => r.result === ActionSetResult.FAILURE)) {
|
|
135
|
-
// Emit all the callbacks for individual action sets
|
|
136
|
-
const actionSetCallbacks = actionSetResponses.reduce((obs, asr) => {
|
|
137
|
-
if (!asr.callbacks) {
|
|
138
|
-
return obs;
|
|
139
|
-
} else if (asr.result === ActionSetResult.FAILURE && asr.callbacks.onFailure) {
|
|
140
|
-
return merge(obs, asr.callbacks.onFailure);
|
|
141
|
-
} else if (asr.result === ActionSetResult.SUCCESS && asr.callbacks.onSuccessButOtherFailure) {
|
|
142
|
-
return merge(obs, asr.callbacks.onSuccessButOtherFailure);
|
|
143
|
-
} else {
|
|
144
|
-
return obs;
|
|
145
|
-
}
|
|
146
|
-
}, []);
|
|
147
|
-
|
|
148
|
-
if (actionFlow.payload.failActionFn) {
|
|
149
|
-
return merge(actionSetCallbacks, actionFlow.payload.failActionFn(actionSetResponses));
|
|
150
|
-
} else {
|
|
151
|
-
return actionSetCallbacks;
|
|
152
|
-
}
|
|
153
|
-
} else {
|
|
154
|
-
if (actionFlow.payload.successActionFn) {
|
|
155
|
-
return actionFlow.payload.successActionFn(actionSetResponses);
|
|
156
|
-
} else {
|
|
157
|
-
return [];
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}),
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
}),
|
|
164
|
-
),
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
constructor(
|
|
168
|
-
private actions$: Actions,
|
|
169
|
-
private router: Router,
|
|
170
|
-
private cachedConnections: CachedLoadConnectionsService,
|
|
171
|
-
private eh: EffectsHelpers,
|
|
172
|
-
private db: FirebaseService,
|
|
173
|
-
private store: Store<fromStore.State>,
|
|
174
|
-
) {}
|
|
175
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ActionReducer,
|
|
3
|
-
ActionReducerMap,
|
|
4
|
-
createFeatureSelector,
|
|
5
|
-
createSelector,
|
|
6
|
-
MetaReducer,
|
|
7
|
-
} from '@ngrx/store';
|
|
8
|
-
import { environment } from '../../../environments/environment';
|
|
9
|
-
import { routerReducer, RouterReducerState } from '@ngrx/router-store';
|
|
10
|
-
|
|
11
|
-
import * as fromAuth from './auth/auth.reducer';
|
|
12
|
-
|
|
13
|
-
// Entity Reducers
|
|
14
|
-
import * as fromAppState from './app-state/app-state.reducer';
|
|
15
|
-
import * as fromUserContext from './user-context/user-context.reducer';
|
|
16
|
-
import * as fromUser from './user/user.reducer';
|
|
17
|
-
|
|
18
|
-
export interface State {
|
|
19
|
-
auth: fromAuth.State;
|
|
20
|
-
router: RouterReducerState;
|
|
21
|
-
// Entity State
|
|
22
|
-
appState: fromAppState.State;
|
|
23
|
-
userContext: fromUserContext.State;
|
|
24
|
-
user: fromUser.State;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const reducers: ActionReducerMap<State> = {
|
|
28
|
-
router: routerReducer,
|
|
29
|
-
auth: fromAuth.reducer,
|
|
30
|
-
// Entity Reducers
|
|
31
|
-
appState: fromAppState.reducer,
|
|
32
|
-
userContext: fromUserContext.reducer,
|
|
33
|
-
user: fromUser.reducer,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const metaReducers: MetaReducer<State>[] = !environment.production ? [] : [];
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
2
|
-
import { CachedSelectorsService } from './cached-selectors.service';
|
|
3
|
-
|
|
4
|
-
import { AuthSelectorsService } from './auth/auth.selectors';
|
|
5
|
-
|
|
6
|
-
// Entity Selectors
|
|
7
|
-
import { AppStateService } from './app-state/app-state.service';
|
|
8
|
-
import { UserContextService } from './user-context/user-context.service';
|
|
9
|
-
import { UserService } from './user/user.service';
|
|
10
|
-
|
|
11
|
-
@Injectable({
|
|
12
|
-
providedIn: 'root',
|
|
13
|
-
})
|
|
14
|
-
export class EntitySelectorService {
|
|
15
|
-
constructor(
|
|
16
|
-
private cachedSelectors: CachedSelectorsService,
|
|
17
|
-
private auth: AuthSelectorsService,
|
|
18
|
-
// Entity Selectors
|
|
19
|
-
private appState: AppStateService,
|
|
20
|
-
private userContext: UserContextService,
|
|
21
|
-
private user: UserService,
|
|
22
|
-
) { }
|
|
23
|
-
|
|
24
|
-
public createId = this.cachedSelectors.createId;
|
|
25
|
-
public release = this.cachedSelectors.release;
|
|
26
|
-
|
|
27
|
-
public selectAuthUser = this.auth.selectAuthUser;
|
|
28
|
-
|
|
29
|
-
// Entity Selectors
|
|
30
|
-
public getAppState = this.appState.getAppState;
|
|
31
|
-
public getAppStates = this.appState.getAppStates;
|
|
32
|
-
public selectAppState = this.appState.selectAppState;
|
|
33
|
-
public selectAppStates = this.appState.selectAppStates;
|
|
34
|
-
public getUserContext = this.userContext.getUserContext;
|
|
35
|
-
public getUserContexts = this.userContext.getUserContexts;
|
|
36
|
-
public selectUserContext = this.userContext.selectUserContext;
|
|
37
|
-
public selectUserContexts = this.userContext.selectUserContexts;
|
|
38
|
-
public selectUser = this.user.selectUser;
|
|
39
|
-
public selectUsers = this.user.selectUsers;
|
|
40
|
-
public getUser = this.user.getUser;
|
|
41
|
-
public getUsers = this.user.getUsers;
|
|
42
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { Action } from '@ngrx/store';
|
|
2
|
-
import { User } from '../user/user.model';
|
|
3
|
-
|
|
4
|
-
export const LOAD = '[Auth] load currentUser';
|
|
5
|
-
export const LOADED = '[Auth] loaded';
|
|
6
|
-
|
|
7
|
-
export const LOGIN = '[Auth] login';
|
|
8
|
-
export const LOGIN_SUCCESS = '[Auth] login success';
|
|
9
|
-
export const LOGIN_FAIL = '[Auth] login fail';
|
|
10
|
-
|
|
11
|
-
export const LOGOUT = '[Auth] logout';
|
|
12
|
-
export const LOGOUT_SUCCESS = '[Auth] logout success';
|
|
13
|
-
export const LOGOUT_FAIL = '[Auth] logout fail';
|
|
14
|
-
|
|
15
|
-
export class LoadAuth implements Action {
|
|
16
|
-
readonly type = LOAD;
|
|
17
|
-
constructor(public correlationId?: string) {}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class LoadedAuth implements Action {
|
|
21
|
-
readonly type = LOADED;
|
|
22
|
-
constructor(
|
|
23
|
-
public payload: {
|
|
24
|
-
user: User,
|
|
25
|
-
},
|
|
26
|
-
public correlationId?: string,
|
|
27
|
-
) {}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class Login implements Action {
|
|
31
|
-
readonly type = LOGIN;
|
|
32
|
-
constructor(
|
|
33
|
-
public payload: {
|
|
34
|
-
provider: string,
|
|
35
|
-
scope?: string,
|
|
36
|
-
doNotRoute?: boolean,
|
|
37
|
-
},
|
|
38
|
-
public correlationId?: string,
|
|
39
|
-
) { }
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class LoginSuccess implements Action {
|
|
43
|
-
readonly type = LOGIN_SUCCESS;
|
|
44
|
-
constructor(public payload: any, public correlationId?: string) { }
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export class LoginFail implements Action {
|
|
48
|
-
readonly type = LOGIN_FAIL;
|
|
49
|
-
constructor(public error: any, public correlationId?: string) {}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export class Logout implements Action {
|
|
53
|
-
readonly type = LOGOUT;
|
|
54
|
-
constructor(public payload?: {
|
|
55
|
-
doNotRoute?: boolean,
|
|
56
|
-
}, public correlationId?: string) { }
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export class LogoutSuccess implements Action {
|
|
60
|
-
readonly type = LOGOUT_SUCCESS;
|
|
61
|
-
constructor(public correlationId?: string) {}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export class LogoutFail implements Action {
|
|
65
|
-
readonly type = LOGOUT_FAIL;
|
|
66
|
-
constructor(public error?: any, public correlationId?: string) {}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export type AuthActions =
|
|
70
|
-
LoadAuth |
|
|
71
|
-
LoadedAuth |
|
|
72
|
-
Login |
|
|
73
|
-
LoginSuccess |
|
|
74
|
-
LoginFail |
|
|
75
|
-
Logout |
|
|
76
|
-
LogoutSuccess |
|
|
77
|
-
LogoutFail;
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
2
|
-
import { from, Observable, of } from 'rxjs';
|
|
3
|
-
import { Action } from '@ngrx/store';
|
|
4
|
-
import { Actions, createEffect, ofType } from '@ngrx/effects';
|
|
5
|
-
import { Router } from '@angular/router';
|
|
6
|
-
import { select, Store } from '@ngrx/store';
|
|
7
|
-
import * as fromStore from '../app.reducer';
|
|
8
|
-
import * as fromAuth from './auth.reducer';
|
|
9
|
-
import { FirebaseService } from '../../firebase/firebase.service';
|
|
10
|
-
import { ActionFlow, RouterNavigate } from '../app.actions';
|
|
11
|
-
import * as firebase from 'firebase/compat/app';
|
|
12
|
-
|
|
13
|
-
import { switchMap, mergeMap, map, catchError, tap, take, pluck } from 'rxjs/operators';
|
|
14
|
-
import { LOAD, LOGIN, LOGIN_SUCCESS, LOGIN_FAIL, LOGOUT, LOGOUT_SUCCESS, LOGOUT_FAIL, Login, LoginSuccess, LoginFail, Logout, LogoutSuccess, LogoutFail, LoadAuth, LoadedAuth } from './auth.actions';
|
|
15
|
-
import { User, AccessState } from '../user/user.model';
|
|
16
|
-
import { UserActionTypes, AddUser, UpdateUser } from '../user/user.actions';
|
|
17
|
-
|
|
18
|
-
@Injectable()
|
|
19
|
-
export class AuthEffects {
|
|
20
|
-
/** Process the logout action. */
|
|
21
|
-
Logout$: Observable<Action> = createEffect(
|
|
22
|
-
() => this.actions$.pipe(
|
|
23
|
-
ofType(LOGOUT),
|
|
24
|
-
mergeMap((action: Logout) => {
|
|
25
|
-
return this.db.logout().pipe(
|
|
26
|
-
mergeMap(() => [
|
|
27
|
-
...(action.payload.doNotRoute ? [] : [
|
|
28
|
-
// Change this to where you want to navigate to after logout
|
|
29
|
-
new RouterNavigate(['/landing']),
|
|
30
|
-
]),
|
|
31
|
-
new LogoutSuccess(action.correlationId),
|
|
32
|
-
]),
|
|
33
|
-
catchError((error) => of(new LogoutFail(error, action.correlationId))),
|
|
34
|
-
);
|
|
35
|
-
}),
|
|
36
|
-
),
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
/** Process the load auth action. */
|
|
40
|
-
LoadAuth$: Observable<Action> = createEffect(
|
|
41
|
-
() => this.actions$.pipe(
|
|
42
|
-
ofType<LoadAuth>(LOAD),
|
|
43
|
-
switchMap(() => this.db.afUser()),
|
|
44
|
-
switchMap((afUser: any) => {
|
|
45
|
-
if (afUser) {
|
|
46
|
-
// Note that using this.db.queryObjValueChanges doesn't work since it first returns
|
|
47
|
-
// undefined from the cache which messes up the logic (results in it doing a Logout)
|
|
48
|
-
return this.db.queryListValueChanges<User>('users', [['__id', '==', afUser.uid]]).pipe(
|
|
49
|
-
map((users: User[]) => {
|
|
50
|
-
if (users && users.length > 0) {
|
|
51
|
-
return new LoadedAuth({ user: users[0] });
|
|
52
|
-
} else {
|
|
53
|
-
// This should not happen. If there is no entry in DB despite
|
|
54
|
-
// having a FireAuth user, make them login again to create an entry
|
|
55
|
-
return new Logout({ doNotRoute: true });
|
|
56
|
-
}
|
|
57
|
-
}),
|
|
58
|
-
);
|
|
59
|
-
} else {
|
|
60
|
-
return [new LoadedAuth({ user: undefined })];
|
|
61
|
-
}
|
|
62
|
-
}),
|
|
63
|
-
),
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
/** Process the login action. */
|
|
67
|
-
Login$: Observable<Action> = createEffect(
|
|
68
|
-
() => this.actions$.pipe(
|
|
69
|
-
ofType<Login>(LOGIN),
|
|
70
|
-
switchMap((action) => {
|
|
71
|
-
return this.db.login(action.payload.provider, action.payload.scope).pipe(
|
|
72
|
-
map((results) => {
|
|
73
|
-
const afUser = results.user;
|
|
74
|
-
const dbUser = results.dbUser;
|
|
75
|
-
|
|
76
|
-
let userActionSet;
|
|
77
|
-
|
|
78
|
-
const userParams = {
|
|
79
|
-
email: afUser.email,
|
|
80
|
-
name: afUser.displayName || afUser.email,
|
|
81
|
-
photoURL: afUser.photoURL,
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
if (dbUser) {
|
|
85
|
-
// update user
|
|
86
|
-
userActionSet = {
|
|
87
|
-
action: new UpdateUser(dbUser.__id, Object.assign({}, userParams, {
|
|
88
|
-
tokens: Object.assign({}, dbUser.tokens || {}, this.getToken(results.credential)),
|
|
89
|
-
})),
|
|
90
|
-
responseActionTypes: {
|
|
91
|
-
success: UserActionTypes.UPDATE_SUCCESS,
|
|
92
|
-
failure: UserActionTypes.UPDATE_FAIL,
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
} else {
|
|
96
|
-
// add user
|
|
97
|
-
userActionSet = {
|
|
98
|
-
action: new AddUser(Object.assign({}, userParams, {
|
|
99
|
-
__id: afUser.uid,
|
|
100
|
-
tokens: this.getToken(results.credential),
|
|
101
|
-
isAdmin: false,
|
|
102
|
-
consented: false,
|
|
103
|
-
accessState: AccessState.CONSENT,
|
|
104
|
-
})),
|
|
105
|
-
responseActionTypes: {
|
|
106
|
-
success: UserActionTypes.ADD_SUCCESS,
|
|
107
|
-
failure: UserActionTypes.ADD_FAIL,
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return new ActionFlow({
|
|
113
|
-
actionSets: [userActionSet],
|
|
114
|
-
successActionFn: (actionSetResponses) => {
|
|
115
|
-
return [
|
|
116
|
-
// Don't route if there is a doNotRoute parameter passed in
|
|
117
|
-
...(action.payload.doNotRoute ? [] : [
|
|
118
|
-
// Change this to where you want to navigate to after login
|
|
119
|
-
new RouterNavigate(
|
|
120
|
-
['/home'],
|
|
121
|
-
{ queryParamsHandling: 'preserve' },
|
|
122
|
-
)
|
|
123
|
-
]),
|
|
124
|
-
new LoginSuccess({ ...action.payload, ...results }, action.correlationId),
|
|
125
|
-
];
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
}),
|
|
129
|
-
catchError((error) => of(new LoginFail(error, action.correlationId))),
|
|
130
|
-
);
|
|
131
|
-
}),
|
|
132
|
-
),
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
/** Process the login fail action. */
|
|
136
|
-
loginFail$: Observable<Action> = createEffect(
|
|
137
|
-
() => this.actions$.pipe(
|
|
138
|
-
ofType<LoginFail>(LOGIN_FAIL),
|
|
139
|
-
tap((action: LoginFail) => {
|
|
140
|
-
switch (action.error.code) {
|
|
141
|
-
case 'auth/account-exists-with-different-credential': {
|
|
142
|
-
this.db.loginLink(action.error);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}),
|
|
146
|
-
),
|
|
147
|
-
{ dispatch: false },
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
getToken(credential) {
|
|
151
|
-
const tokenHash = {};
|
|
152
|
-
tokenHash[credential.providerId] = credential.accessToken;
|
|
153
|
-
|
|
154
|
-
return tokenHash;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
constructor(
|
|
158
|
-
private actions$: Actions,
|
|
159
|
-
private store: Store<fromStore.State>,
|
|
160
|
-
private router: Router,
|
|
161
|
-
private db: FirebaseService,
|
|
162
|
-
) {}
|
|
163
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { reducer, initialState } from './auth.reducer';
|
|
2
|
-
|
|
3
|
-
describe('Auth Reducer', () => {
|
|
4
|
-
describe('unknown action', () => {
|
|
5
|
-
it('should return the initial state', () => {
|
|
6
|
-
const action = {} as any;
|
|
7
|
-
|
|
8
|
-
const result = reducer(initialState, action);
|
|
9
|
-
|
|
10
|
-
expect(result).toBe(initialState);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Action } from '@ngrx/store';
|
|
2
|
-
import { User } from '../user/user.model';
|
|
3
|
-
import * as actions from './auth.actions';
|
|
4
|
-
import * as fromStore from '../app.reducer';
|
|
5
|
-
|
|
6
|
-
export interface State {
|
|
7
|
-
user: User;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const initialState: State = {
|
|
11
|
-
user: null,
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export function reducer(state = initialState, action: actions.AuthActions) {
|
|
15
|
-
switch (action.type) {
|
|
16
|
-
case actions.LOADED:
|
|
17
|
-
return {
|
|
18
|
-
user: action.payload.user,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
default:
|
|
22
|
-
return state;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const selectUser = (state: fromStore.State) => state.auth.user;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
import { filter } from 'rxjs/operators';
|
|
4
|
-
|
|
5
|
-
import { Store, select } from '@ngrx/store';
|
|
6
|
-
import * as fromStore from '../app.reducer';
|
|
7
|
-
import * as fromAuth from './auth.reducer';
|
|
8
|
-
|
|
9
|
-
import { User } from '../user/user.model';
|
|
10
|
-
|
|
11
|
-
@Injectable({
|
|
12
|
-
providedIn: 'root',
|
|
13
|
-
})
|
|
14
|
-
export class AuthSelectorsService {
|
|
15
|
-
constructor(
|
|
16
|
-
private store: Store<fromStore.State>,
|
|
17
|
-
) { }
|
|
18
|
-
|
|
19
|
-
public selectAuthUser = (): Observable<User> => {
|
|
20
|
-
return this.store.pipe(
|
|
21
|
-
select(fromAuth.selectUser),
|
|
22
|
-
filter((user) => user !== null),
|
|
23
|
-
);
|
|
24
|
-
};
|
|
25
|
-
}
|