@tech4good/angular-schematics 13.3.0 → 13.5.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.
Files changed (59) hide show
  1. package/package.json +1 -1
  2. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.actions.ts.template +2 -4
  3. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.effects.ts.template +1 -1
  4. package/src/container/files/__name@dasherize__/__name@dasherize__.component.ts.template +2 -4
  5. package/src/init/files/{.eslintrc.json → .eslintrc.json.template} +0 -0
  6. package/src/init/files/{.gitattributes → .gitattributes.template} +0 -0
  7. package/src/init/files/.gitignore.template +55 -0
  8. package/src/init/files/angular.json.template +1 -1
  9. package/src/init/files/package.json.template +1 -1
  10. package/src/init/files/src/app/app-routing.module.ts.template +19 -0
  11. package/src/init/files/src/app/{app.component.html → app.component.html.template} +0 -0
  12. package/src/init/files/src/app/{app.component.scss → app.component.scss.template} +0 -0
  13. package/src/init/files/src/app/app.component.ts.template +41 -0
  14. package/src/init/files/src/app/app.module.ts.template +34 -0
  15. package/src/init/files/src/app/core/analytics/log.service.ts.template +35 -0
  16. package/src/init/files/src/app/core/analytics/time-analytics.service.ts.template +223 -0
  17. package/src/init/files/src/app/core/core.module.ts.template +71 -0
  18. package/src/init/files/src/app/core/firebase/firebase.service.ts.template +284 -0
  19. package/src/init/files/src/app/core/router/routing-state.service.ts.template +28 -0
  20. package/src/init/files/src/app/core/setup/firebase-setup.ts.template +25 -0
  21. package/src/init/files/src/app/core/setup/module-import-guard.ts.template +5 -0
  22. package/src/init/files/src/app/core/snackbar/snackbar.actions.ts.template +24 -0
  23. package/src/init/files/src/app/core/snackbar/snackbar.effects.ts.template +41 -0
  24. package/src/init/files/src/app/core/store/app.actions.ts.template +92 -0
  25. package/src/init/files/src/app/core/store/app.effects.ts.template +167 -0
  26. package/src/init/files/src/app/core/store/app.reducer.ts.template +30 -0
  27. package/src/init/files/src/app/core/store/app.selectors.ts.template +30 -0
  28. package/src/init/files/src/app/core/store/auth/auth.actions.ts.template +75 -0
  29. package/src/init/files/src/app/core/store/auth/auth.effects.ts.template +164 -0
  30. package/src/init/files/src/app/core/store/auth/auth.reducer.spec.ts.template +13 -0
  31. package/src/init/files/src/app/core/store/auth/auth.reducer.ts.template +26 -0
  32. package/src/init/files/src/app/core/store/auth/auth.selectors.ts.template +21 -0
  33. package/src/init/files/src/app/core/store/cached-load-connections.service.ts.template +404 -0
  34. package/src/init/files/src/app/core/store/cached-selectors.service.ts.template +376 -0
  35. package/src/init/files/src/app/core/store/effects.helpers.ts.template +66 -0
  36. package/src/init/files/src/app/core/store/user/user.actions.ts.template +269 -0
  37. package/src/init/files/src/app/core/store/user/user.effects.ts.template +131 -0
  38. package/src/init/files/src/app/core/store/user/user.model.ts.template +15 -0
  39. package/src/init/files/src/app/core/store/user/user.reducer.spec.ts.template +13 -0
  40. package/src/init/files/src/app/core/store/user/user.reducer.ts.template +50 -0
  41. package/src/init/files/src/app/core/store/user/user.service.ts.template +50 -0
  42. package/src/init/files/src/app/core/utils/string-case.utils.ts.template +96 -0
  43. package/src/init/files/src/app/general/e404/{e404.component.html → e404.component.html.template} +0 -0
  44. package/src/init/files/src/app/general/e404/{e404.component.scss → e404.component.scss.template} +0 -0
  45. package/src/init/files/src/app/general/e404/e404.component.spec.ts.template +25 -0
  46. package/src/init/files/src/app/general/e404/e404.component.ts.template +28 -0
  47. package/src/init/files/src/app/general/general-routing.module.ts.template +21 -0
  48. package/src/init/files/src/app/general/general.module.spec.ts.template +13 -0
  49. package/src/init/files/src/app/general/general.module.ts.template +30 -0
  50. package/src/init/files/src/app/general/login/{login.component.html → login.component.html.template} +0 -0
  51. package/src/init/files/src/app/general/login/{login.component.scss → login.component.scss.template} +0 -0
  52. package/src/init/files/src/app/general/login/login.component.spec.ts.template +25 -0
  53. package/src/init/files/src/app/general/login/login.component.ts.template +72 -0
  54. package/src/init/files/src/app/shared/shared.module.ts.template +81 -0
  55. package/src/init/files/src/environments/environment.prod.ts.template +5 -0
  56. package/src/init/files/src/environments/environment.ts.template +18 -0
  57. package/src/init/files/src/styles/{_variables.scss → _variables.scss.template} +0 -0
  58. package/src/init/files/src/{styles.scss → styles.scss.template} +0 -0
  59. package/src/init/files/tsconfig.json.template +31 -0
@@ -0,0 +1,30 @@
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 fromUser from './user/user.reducer';
15
+
16
+ export interface State {
17
+ auth: fromAuth.State;
18
+ router: RouterReducerState;
19
+ // Entity State
20
+ user: fromUser.State;
21
+ }
22
+
23
+ export const reducers: ActionReducerMap<State> = {
24
+ router: routerReducer,
25
+ auth: fromAuth.reducer,
26
+ // Entity Reducers
27
+ user: fromUser.reducer,
28
+ };
29
+
30
+ export const metaReducers: MetaReducer<State>[] = !environment.production ? [] : [];
@@ -0,0 +1,30 @@
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 { UserService } from './user/user.service';
8
+
9
+ @Injectable({
10
+ providedIn: 'root',
11
+ })
12
+ export class EntitySelectorService {
13
+ constructor(
14
+ private cachedSelectors: CachedSelectorsService,
15
+ private auth: AuthSelectorsService,
16
+ // Entity Selectors
17
+ private user: UserService,
18
+ ) { }
19
+
20
+ public createId = this.cachedSelectors.createId;
21
+ public release = this.cachedSelectors.release;
22
+
23
+ public selectAuthUser = this.auth.selectAuthUser;
24
+
25
+ // Entity Selectors
26
+ public selectUser = this.user.selectUser;
27
+ public selectUser = this.user.selectUser;
28
+ public getUser = this.user.getUser;
29
+ public getUsers = this.user.getUsers;
30
+ }
@@ -0,0 +1,75 @@
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 correlationId?: string) { }
55
+ }
56
+
57
+ export class LogoutSuccess implements Action {
58
+ readonly type = LOGOUT_SUCCESS;
59
+ constructor(public correlationId?: string) {}
60
+ }
61
+
62
+ export class LogoutFail implements Action {
63
+ readonly type = LOGOUT_FAIL;
64
+ constructor(public error?: any, public correlationId?: string) {}
65
+ }
66
+
67
+ export type AuthActions =
68
+ LoadAuth |
69
+ LoadedAuth |
70
+ Login |
71
+ LoginSuccess |
72
+ LoginFail |
73
+ Logout |
74
+ LogoutSuccess |
75
+ LogoutFail;
@@ -0,0 +1,164 @@
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 } 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
+ new LoadAuth(),
28
+ new LogoutSuccess(action.correlationId),
29
+ new RouterNavigate(['/login']),
30
+ ]),
31
+ catchError((error) => of(new LogoutFail(error, action.correlationId))),
32
+ );
33
+ }),
34
+ ),
35
+ );
36
+
37
+ /** Process the load auth action. */
38
+ LoadAuth$: Observable<Action> = createEffect(
39
+ () => this.actions$.pipe(
40
+ ofType<LoadAuth>(LOAD),
41
+ switchMap(() => this.db.afUser().pipe(take(1))),
42
+ mergeMap((afUser: any) => {
43
+ if (afUser) {
44
+ return this.db.queryObjValueChanges<User>('users', afUser.uid).pipe(
45
+ take(1),
46
+ map((user: User) => {
47
+ if (user) {
48
+ return new LoadedAuth({ user });
49
+ } else {
50
+ // If no entry in DB, make them login again to create an entry
51
+ return new Logout();
52
+ }
53
+ }),
54
+ );
55
+ } else {
56
+ return [new LoadedAuth({ user: undefined })];
57
+ }
58
+ }),
59
+ ),
60
+ );
61
+
62
+ /** Process the login action. */
63
+ Login$: Observable<Action> = createEffect(
64
+ () => this.actions$.pipe(
65
+ ofType<Login>(LOGIN),
66
+ switchMap((action) => {
67
+ return this.db.login(action.payload.provider, action.payload.scope).pipe(
68
+ map((results) => {
69
+ const afUser = results.user;
70
+ const dbUser = results.dbUser;
71
+
72
+ let userActionSet;
73
+
74
+ const userParams = {
75
+ email: afUser.email,
76
+ name: afUser.displayName || afUser.email,
77
+ photoURL: afUser.photoURL,
78
+ };
79
+
80
+ if (dbUser) {
81
+ // update user
82
+ userActionSet = {
83
+ action: new UpdateUser(dbUser.__id, Object.assign({}, userParams, {
84
+ tokens: Object.assign({}, dbUser.tokens || {}, this.getToken(results.credential)),
85
+ })),
86
+ responseActionTypes: {
87
+ success: UserActionTypes.UPDATE_SUCCESS,
88
+ failure: UserActionTypes.UPDATE_FAIL,
89
+ },
90
+ };
91
+ } else {
92
+ // add user
93
+ userActionSet = {
94
+ action: new AddUser(Object.assign({}, userParams, {
95
+ __id: afUser.uid,
96
+ tokens: this.getToken(results.credential),
97
+ })),
98
+ responseActionTypes: {
99
+ success: UserActionTypes.ADD_SUCCESS,
100
+ failure: UserActionTypes.ADD_FAIL,
101
+ },
102
+ };
103
+ }
104
+
105
+ if (action.payload.doNotRoute) {
106
+ return new ActionFlow({
107
+ actionSets: [userActionSet],
108
+ successActionFn: (actionSetResponses) => {
109
+ return [
110
+ new LoadAuth(),
111
+ // don't route anywhere
112
+ new LoginSuccess({ ...action.payload, ...results }, action.correlationId),
113
+ ];
114
+ },
115
+ });
116
+ } else {
117
+ return new ActionFlow({
118
+ actionSets: [userActionSet],
119
+ successActionFn: (actionSetResponses) => {
120
+ return [
121
+ new LoadAuth(),
122
+ // Change this to where you want to navigate to after login
123
+ new RouterNavigate(['/login']),
124
+ new LoginSuccess({ ...action.payload, ...results }, action.correlationId),
125
+ ];
126
+ },
127
+ });
128
+ }
129
+ }),
130
+ catchError((error) => of(new LoginFail(error, action.correlationId))),
131
+ );
132
+ }),
133
+ ),
134
+ );
135
+
136
+ /** Process the login fail action. */
137
+ loginFail$: Observable<Action> = createEffect(
138
+ () => this.actions$.pipe(
139
+ ofType<LoginFail>(LOGIN_FAIL),
140
+ tap((action: LoginFail) => {
141
+ switch (action.error.code) {
142
+ case 'auth/account-exists-with-different-credential': {
143
+ this.db.loginLink(action.error);
144
+ }
145
+ }
146
+ }),
147
+ ),
148
+ { dispatch: false },
149
+ );
150
+
151
+ getToken(credential) {
152
+ const tokenHash = {};
153
+ tokenHash[credential.providerId] = credential.accessToken;
154
+
155
+ return tokenHash;
156
+ }
157
+
158
+ constructor(
159
+ private actions$: Actions,
160
+ private store: Store<fromStore.State>,
161
+ private router: Router,
162
+ private db: FirebaseService,
163
+ ) {}
164
+ }
@@ -0,0 +1,13 @@
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
+ });
@@ -0,0 +1,26 @@
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 ? null : Object.assign({}, action.payload.user),
19
+ };
20
+
21
+ default:
22
+ return state;
23
+ }
24
+ }
25
+
26
+ export const selectUser = (state: fromStore.State) => state.auth.user;
@@ -0,0 +1,21 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { Observable } from 'rxjs';
3
+
4
+ import { Store, select } from '@ngrx/store';
5
+ import * as fromStore from '../app.reducer';
6
+ import * as fromAuth from './auth.reducer';
7
+
8
+ import { User } from '../user/user.model';
9
+
10
+ @Injectable({
11
+ providedIn: 'root',
12
+ })
13
+ export class AuthSelectorsService {
14
+ constructor(
15
+ private store: Store<fromStore.State>,
16
+ ) { }
17
+
18
+ public selectAuthUser = (): Observable<User> => {
19
+ return this.store.pipe(select(fromAuth.selectUser));
20
+ };
21
+ }