@tech4good/angular-schematics 21.3.0 → 21.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.
- package/.t4g/agent-memory.db +0 -0
- package/CHANGELOG.md +41 -0
- package/package.json +1 -1
- package/src/entity/index.js +42 -9
- package/src/entity/index.js.map +1 -1
- package/src/entity/index_spec.js +42 -8
- package/src/entity/index_spec.js.map +1 -1
- package/src/entity/schema.json +0 -5
- package/src/ng-add/files/.firebaserc.template +2 -1
- package/src/ng-add/files/.gitignore.template +1 -0
- package/src/ng-add/files/angular.json.template +3 -0
- package/src/ng-add/files/bigquery/queries/active_time_by_route.sql.template +34 -0
- package/src/ng-add/files/bigquery/scripts/export_entities.py.template +143 -0
- package/src/ng-add/files/bigquery/scripts/run_query.py.template +167 -0
- package/src/ng-add/files/bigquery/views/events_flat.sql.template +60 -0
- package/src/ng-add/files/bigquery/views/logs_latest.sql.template +34 -0
- package/src/ng-add/files/docs-infra/analytics-guide.md.template +170 -0
- package/src/ng-add/files/firebase.logs.json.template +5 -0
- package/src/ng-add/files/firestore.indexes.json.template +89 -0
- package/src/ng-add/files/firestore.logs.rules.spec.ts.template +100 -0
- package/src/ng-add/files/firestore.logs.rules.template +8 -0
- package/src/ng-add/files/firestore.rules.spec.ts.template +88 -1
- package/src/ng-add/files/firestore.rules.template +9 -0
- package/src/ng-add/files/jest.config.ts.template +1 -1
- package/src/ng-add/files/package.json.template +6 -3
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.spec.ts.template +3 -3
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.spec.ts.template +0 -1
- package/src/ng-add/files/src/app/app.component.html.template +1 -1
- package/src/ng-add/files/src/app/app.component.scss.template +9 -1
- package/src/ng-add/files/src/app/app.component.spec.ts.template +2 -2
- package/src/ng-add/files/src/app/auth-routing.spec.ts.template +1 -1
- package/src/ng-add/files/src/app/core/analytics/log.service.ts.template +27 -5
- package/src/ng-add/files/src/app/core/analytics/time-analytics.service.spec.ts.template +147 -4
- package/src/ng-add/files/src/app/core/analytics/time-analytics.service.ts.template +355 -149
- package/src/ng-add/files/src/app/core/auth/guards/require-auth-and-consent.guard.ts.template +3 -1
- package/src/ng-add/files/src/app/core/firebase/cached-listeners.service.ts.template +53 -51
- package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +6 -0
- package/src/ng-add/files/src/app/core/firebase/simulate-load.spec.ts.template +2 -2
- package/src/ng-add/files/src/app/core/firebase/simulate-stream.spec.ts.template +14 -14
- package/src/ng-add/files/src/app/core/firebase/stream-multiplexer.ts.template +50 -48
- package/src/ng-add/files/src/app/core/logging/logging.service.spec.ts.template +118 -0
- package/src/ng-add/files/src/app/core/logging/logging.service.ts.template +168 -0
- package/src/ng-add/files/src/app/core/store/app.model.ts.template +3 -1
- package/src/ng-add/files/src/app/core/store/app.store.ts.template +11 -9
- package/src/ng-add/files/src/app/core/store/auth/auth.mock.ts.template +5 -4
- package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +13 -4
- package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +0 -4
- package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +0 -1
- package/src/ng-add/files/src/app/core/store/user-private/user-private.mock.ts.template +15 -0
- package/src/ng-add/files/src/app/core/store/user-private/user-private.model.ts.template +9 -0
- package/src/ng-add/files/src/app/core/store/user-private/user-private.store.ts.template +41 -0
- package/src/ng-add/files/src/app/first-time/consent/consent.component.html.template +172 -48
- package/src/ng-add/files/src/app/first-time/consent/consent.component.scss.template +31 -0
- package/src/ng-add/files/src/app/first-time/consent/consent.component.spec.ts.template +31 -3
- package/src/ng-add/files/src/app/first-time/consent/consent.component.ts.template +12 -11
- package/src/ng-add/files/src/app/first-time/consent/consent.guard.ts.template +0 -6
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.spec.ts.template +0 -1
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +1 -1
- package/src/ng-add/files/src/app/first-time/early-access/early-access.guard.ts.template +7 -1
- package/src/ng-add/files/src/app/first-time/first-time-routing.spec.ts.template +7 -6
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +3 -3
- package/src/ng-add/files/src/app/first-time/landing/landing.component.scss.template +1 -1
- package/src/ng-add/files/src/app/first-time/onboarding/onboarding.component.ts.template +3 -3
- package/src/ng-add/files/src/app/main/home/home.component.spec.ts.template +1 -1
- package/src/ng-add/files/src/app/main/home/home.component.ts.template +4 -4
- package/src/ng-add/files/src/app/shared/dev-status-bar/dev-status-bar.component.scss.template +1 -0
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.spec.ts.template +41 -5
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.ts.template +25 -2
- package/src/ng-add/files/src/environments/environment.test.ts.template +1 -1
- package/src/shared/statements-adder.d.ts +1 -0
- package/src/shared/statements-adder.js +8 -0
- package/src/shared/statements-adder.js.map +1 -1
- package/src/ng-add/files/src/app/core/firebase/query-logger.ts.template +0 -11
- package/tech4good-angular-schematics-21.0.0.tgz +0 -0
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
:host {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
2
4
|
height: 100%;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.content-container {
|
|
8
|
+
flex: 1;
|
|
9
|
+
min-height: 0;
|
|
3
10
|
width: 100%;
|
|
4
11
|
position: relative;
|
|
5
12
|
display: flex;
|
|
@@ -11,6 +18,7 @@
|
|
|
11
18
|
flex: 1;
|
|
12
19
|
overflow: auto;
|
|
13
20
|
min-height: 0;
|
|
21
|
+
height: 100%;
|
|
14
22
|
}
|
|
15
23
|
|
|
16
24
|
app-redeployment-warning {
|
|
@@ -8,7 +8,7 @@ import { BatchWriteMockService } from 'src/app/core/store/batch-write.mock.servi
|
|
|
8
8
|
import { BATCH_WRITE_SERVICE } from 'src/app/core/store/batch-write.service';
|
|
9
9
|
import { LOG_SERVICE, LogInDevService } from './core/analytics/log.service';
|
|
10
10
|
|
|
11
|
-
/** Sets up the testing environment for AppComponent using render
|
|
11
|
+
/** Sets up the testing environment for AppComponent using render. */
|
|
12
12
|
async function setup() {
|
|
13
13
|
const user = userEvent.setup();
|
|
14
14
|
const checkedSpy = jest.fn();
|
|
@@ -36,4 +36,4 @@ describe('AppComponent', () => {
|
|
|
36
36
|
const { fixture } = await setup();
|
|
37
37
|
expect(fixture.componentInstance).toBeTruthy();
|
|
38
38
|
});
|
|
39
|
-
});
|
|
39
|
+
});
|
|
@@ -31,7 +31,7 @@ describe('Core Auth Routing', () => {
|
|
|
31
31
|
providers: [
|
|
32
32
|
provideRouter(routes),
|
|
33
33
|
{ provide: AuthService, useValue: mockAuthService },
|
|
34
|
-
{ provide: AuthStore, useValue: { user: mockUserSignal } },
|
|
34
|
+
{ provide: AuthStore, useValue: { user: mockUserSignal, isLoadingLogin: signal(false) } },
|
|
35
35
|
{ provide: DATABASE_SERVICE, useClass: FirebaseMockService },
|
|
36
36
|
{ provide: BATCH_WRITE_SERVICE, useClass: BatchWriteMockService },
|
|
37
37
|
{ provide: LOG_SERVICE, useClass: LogInDevService },
|
|
@@ -6,6 +6,8 @@ import { TimeAtRoute } from './time-analytics.service';
|
|
|
6
6
|
|
|
7
7
|
interface LogData extends TimeAtRoute {
|
|
8
8
|
interactions?: Array<{ 0: number; 1: string; 2: string; 3: string; }>;
|
|
9
|
+
_createdAt?: number;
|
|
10
|
+
_updatedAt?: number;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
/**
|
|
@@ -33,11 +35,16 @@ export class LogInDevService {
|
|
|
33
35
|
LOG_IN_DEV = true;
|
|
34
36
|
|
|
35
37
|
constructor() { }
|
|
36
|
-
|
|
38
|
+
|
|
37
39
|
rawLog(data: LogData) {
|
|
38
40
|
if (this.LOG_IN_DEV) {
|
|
39
41
|
const logId = getLogId(data);
|
|
40
|
-
|
|
42
|
+
const updatedData = {
|
|
43
|
+
...data,
|
|
44
|
+
_createdAt: data._createdAt || data.startTime,
|
|
45
|
+
_updatedAt: Date.now(),
|
|
46
|
+
};
|
|
47
|
+
console.log('LOGGING', logId, updatedData);
|
|
41
48
|
}
|
|
42
49
|
}
|
|
43
50
|
|
|
@@ -45,7 +52,12 @@ export class LogInDevService {
|
|
|
45
52
|
if (this.LOG_IN_DEV) {
|
|
46
53
|
const logId = getLogId(data);
|
|
47
54
|
if (data !== null) {
|
|
48
|
-
|
|
55
|
+
const updatedData = {
|
|
56
|
+
...data,
|
|
57
|
+
_createdAt: data._createdAt || data.startTime,
|
|
58
|
+
_updatedAt: Date.now(),
|
|
59
|
+
};
|
|
60
|
+
console.log('BEACON LOGGING', logId, updatedData);
|
|
49
61
|
}
|
|
50
62
|
}
|
|
51
63
|
}
|
|
@@ -130,7 +142,12 @@ export class LogDBService {
|
|
|
130
142
|
// e.g. for storing things in localStorage and saving next time we load
|
|
131
143
|
// the browser
|
|
132
144
|
const docRef = doc(this.log, logType, logId);
|
|
133
|
-
|
|
145
|
+
const updatedData = {
|
|
146
|
+
...data,
|
|
147
|
+
_createdAt: data._createdAt || data.startTime,
|
|
148
|
+
_updatedAt: Date.now(),
|
|
149
|
+
};
|
|
150
|
+
setDoc(docRef, updatedData);
|
|
134
151
|
}
|
|
135
152
|
}
|
|
136
153
|
|
|
@@ -140,9 +157,14 @@ export class LogDBService {
|
|
|
140
157
|
|
|
141
158
|
if (data !== null) {
|
|
142
159
|
if (!isDevMode() && environment['firebaseLogs'] && environment['firebaseLogs']['projectId']) {
|
|
160
|
+
const updatedData = {
|
|
161
|
+
...data,
|
|
162
|
+
_createdAt: data._createdAt || data.startTime,
|
|
163
|
+
_updatedAt: Date.now(),
|
|
164
|
+
};
|
|
143
165
|
navigator.sendBeacon(
|
|
144
166
|
`https://firestore.googleapis.com/v1/projects/${environment['firebaseLogs']['projectId']}/databases/(default)/documents:commit`,
|
|
145
|
-
reformatLogForBeacon(
|
|
167
|
+
reformatLogForBeacon(updatedData, logType, logId),
|
|
146
168
|
);
|
|
147
169
|
}
|
|
148
170
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
import { signal, Injector } from '@angular/core';
|
|
2
3
|
import { Router, NavigationEnd, Event as RouterEvent } from '@angular/router';
|
|
3
|
-
import { Subject, of } from 'rxjs';
|
|
4
|
+
import { Subject, BehaviorSubject, of } from 'rxjs';
|
|
4
5
|
import { TimeAnalyticsService } from './time-analytics.service';
|
|
5
6
|
import { DATABASE_SERVICE } from '../firebase/database.service';
|
|
6
7
|
import { LOG_SERVICE } from './log.service';
|
|
@@ -63,7 +64,7 @@ describe('TimeAnalyticsService', () => {
|
|
|
63
64
|
|
|
64
65
|
// 2. Now a delayed subscriber comes in.
|
|
65
66
|
let capturedRoute: string | undefined;
|
|
66
|
-
|
|
67
|
+
|
|
67
68
|
// Note: currentRoute$ is a private property. We can access it via bracket notation for testing,
|
|
68
69
|
// or test the public behavior. Since we specifically want to verify the RxJS shareReplay caching
|
|
69
70
|
// on `currentRoute$`, we will inspect it directly.
|
|
@@ -117,7 +118,7 @@ describe('TimeAnalyticsService', () => {
|
|
|
117
118
|
expect(savedLog.__sessionId).toEqual('test-session-id');
|
|
118
119
|
expect(savedLog.__deviceId).toEqual('test-device-id');
|
|
119
120
|
expect(savedLog.startTime).toEqual(1000);
|
|
120
|
-
|
|
121
|
+
|
|
121
122
|
// Total active time should be 2000 ms (from T=1000 to T=3000)
|
|
122
123
|
const activeTime = savedLog.time.find((t: any) => t.type === 'active');
|
|
123
124
|
expect(activeTime).toBeDefined();
|
|
@@ -136,5 +137,147 @@ describe('TimeAnalyticsService', () => {
|
|
|
136
137
|
// Cleanup
|
|
137
138
|
dateSpy.mockRestore();
|
|
138
139
|
});
|
|
139
|
-
});
|
|
140
140
|
|
|
141
|
+
it('should serialize objects as JSON strings when tracking interactions', () => {
|
|
142
|
+
let currentTime = 1000;
|
|
143
|
+
const dateSpy = jest.spyOn(Date, 'now').mockImplementation(() => currentTime);
|
|
144
|
+
const logService = TestBed.inject(LOG_SERVICE) as any;
|
|
145
|
+
|
|
146
|
+
// Start logging
|
|
147
|
+
service.startTimeLogging();
|
|
148
|
+
|
|
149
|
+
// 1. User routes to /home
|
|
150
|
+
currentTime = 1000;
|
|
151
|
+
routerEvents$.next(new NavigationEnd(1, '/home', '/home'));
|
|
152
|
+
document.dispatchEvent(new Event('click'));
|
|
153
|
+
|
|
154
|
+
// 2. User interacts again on /home at T=2000 to accumulate active time
|
|
155
|
+
currentTime = 2000;
|
|
156
|
+
document.dispatchEvent(new Event('click'));
|
|
157
|
+
|
|
158
|
+
// 3. User tracks interaction with object payload
|
|
159
|
+
currentTime = 2500;
|
|
160
|
+
const payload = { key: 'value', count: 123 };
|
|
161
|
+
service.trackInteraction('category', 'action', payload);
|
|
162
|
+
|
|
163
|
+
// 4. User interacts again on /home at T=3000
|
|
164
|
+
currentTime = 3000;
|
|
165
|
+
document.dispatchEvent(new Event('click'));
|
|
166
|
+
|
|
167
|
+
// 5. User routes away to save the log
|
|
168
|
+
currentTime = 4000;
|
|
169
|
+
routerEvents$.next(new NavigationEnd(2, '/profile', '/profile'));
|
|
170
|
+
document.dispatchEvent(new Event('click'));
|
|
171
|
+
|
|
172
|
+
// Verify interaction was serialized
|
|
173
|
+
expect(logService.rawLog).toHaveBeenCalledTimes(1);
|
|
174
|
+
const savedLog = logService.rawLog.mock.calls[0][0];
|
|
175
|
+
|
|
176
|
+
expect(savedLog.interactions).toBeDefined();
|
|
177
|
+
expect(savedLog.interactions.length).toEqual(1);
|
|
178
|
+
expect(savedLog.interactions[0]).toEqual({
|
|
179
|
+
0: 2500,
|
|
180
|
+
1: 'category',
|
|
181
|
+
2: 'action',
|
|
182
|
+
3: JSON.stringify(payload),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
dateSpy.mockRestore();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('should track active time per registered state signal and flush log to DB when state changes', () => {
|
|
189
|
+
let currentTime = 1000;
|
|
190
|
+
const dateSpy = jest.spyOn(Date, 'now').mockImplementation(() => currentTime);
|
|
191
|
+
const logService = TestBed.inject(LOG_SERVICE) as any;
|
|
192
|
+
|
|
193
|
+
service.startTimeLogging();
|
|
194
|
+
|
|
195
|
+
// 1. User routes to /practice at T=1000
|
|
196
|
+
currentTime = 1000;
|
|
197
|
+
routerEvents$.next(new NavigationEnd(1, '/practice', '/practice'));
|
|
198
|
+
|
|
199
|
+
const problemSignal = signal<string | null>('prob-1');
|
|
200
|
+
service.registerState('problemId', problemSignal, TestBed.inject(Injector));
|
|
201
|
+
TestBed.flushEffects();
|
|
202
|
+
|
|
203
|
+
// Initial click at T=1000
|
|
204
|
+
document.dispatchEvent(new Event('click'));
|
|
205
|
+
|
|
206
|
+
// 2. User interacts again on prob-1 at T=2000
|
|
207
|
+
currentTime = 2000;
|
|
208
|
+
document.dispatchEvent(new Event('click'));
|
|
209
|
+
|
|
210
|
+
// 3. User changes state to prob-2 at T=3000
|
|
211
|
+
currentTime = 3000;
|
|
212
|
+
problemSignal.set('prob-2');
|
|
213
|
+
TestBed.flushEffects();
|
|
214
|
+
document.dispatchEvent(new Event('click'));
|
|
215
|
+
|
|
216
|
+
// rawLog should be called for prob-1
|
|
217
|
+
expect(logService.rawLog).toHaveBeenCalledTimes(1);
|
|
218
|
+
const prob1Log = logService.rawLog.mock.calls[0][0];
|
|
219
|
+
expect(prob1Log.route).toEqual('/practice');
|
|
220
|
+
expect(prob1Log.state).toEqual({ problemId: 'prob-1' });
|
|
221
|
+
expect(prob1Log.time.find((t: any) => t.type === 'active').total).toEqual(1000);
|
|
222
|
+
|
|
223
|
+
// 4. User interacts again on prob-2 at T=4000
|
|
224
|
+
currentTime = 4000;
|
|
225
|
+
document.dispatchEvent(new Event('click'));
|
|
226
|
+
|
|
227
|
+
// 5. User routes away to /profile at T=5000
|
|
228
|
+
currentTime = 5000;
|
|
229
|
+
routerEvents$.next(new NavigationEnd(2, '/profile', '/profile'));
|
|
230
|
+
document.dispatchEvent(new Event('click'));
|
|
231
|
+
|
|
232
|
+
// rawLog should be called for prob-2
|
|
233
|
+
expect(logService.rawLog).toHaveBeenCalledTimes(2);
|
|
234
|
+
const prob2Log = logService.rawLog.mock.calls[1][0];
|
|
235
|
+
expect(prob2Log.route).toEqual('/practice');
|
|
236
|
+
expect(prob2Log.state).toEqual({ problemId: 'prob-2' });
|
|
237
|
+
expect(prob2Log.time.find((t: any) => t.type === 'active').total).toEqual(2000);
|
|
238
|
+
|
|
239
|
+
dateSpy.mockRestore();
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('should support registering Angular signals via registerState', () => {
|
|
243
|
+
let currentTime = 1000;
|
|
244
|
+
const dateSpy = jest.spyOn(Date, 'now').mockImplementation(() => currentTime);
|
|
245
|
+
const logService = TestBed.inject(LOG_SERVICE) as any;
|
|
246
|
+
|
|
247
|
+
service.startTimeLogging();
|
|
248
|
+
|
|
249
|
+
currentTime = 1000;
|
|
250
|
+
routerEvents$.next(new NavigationEnd(1, '/practice', '/practice'));
|
|
251
|
+
|
|
252
|
+
const problemSignal = signal<string | null>('prob-100');
|
|
253
|
+
service.registerState('problemId', problemSignal, TestBed.inject(Injector));
|
|
254
|
+
TestBed.flushEffects();
|
|
255
|
+
|
|
256
|
+
document.dispatchEvent(new Event('click'));
|
|
257
|
+
|
|
258
|
+
currentTime = 2000;
|
|
259
|
+
document.dispatchEvent(new Event('click'));
|
|
260
|
+
|
|
261
|
+
// Update signal value and flush Angular signal effects
|
|
262
|
+
currentTime = 3000;
|
|
263
|
+
problemSignal.set('prob-200');
|
|
264
|
+
TestBed.flushEffects();
|
|
265
|
+
document.dispatchEvent(new Event('click'));
|
|
266
|
+
|
|
267
|
+
// Should flush log for prob-100
|
|
268
|
+
expect(logService.rawLog).toHaveBeenCalledTimes(1);
|
|
269
|
+
const log1 = logService.rawLog.mock.calls[0][0];
|
|
270
|
+
expect(log1.state).toEqual({ problemId: 'prob-100' });
|
|
271
|
+
|
|
272
|
+
currentTime = 4000;
|
|
273
|
+
routerEvents$.next(new NavigationEnd(2, '/profile', '/profile'));
|
|
274
|
+
document.dispatchEvent(new Event('click'));
|
|
275
|
+
|
|
276
|
+
// Should flush log for prob-200
|
|
277
|
+
expect(logService.rawLog).toHaveBeenCalledTimes(2);
|
|
278
|
+
const log2 = logService.rawLog.mock.calls[1][0];
|
|
279
|
+
expect(log2.state).toEqual({ problemId: 'prob-200' });
|
|
280
|
+
|
|
281
|
+
dateSpy.mockRestore();
|
|
282
|
+
});
|
|
283
|
+
});
|