@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
package/.t4g/agent-memory.db
CHANGED
|
Binary file
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
+
## [21.5.0](https://github.com/tech4good-lab/angular-schematics/compare/v21.4.0...v21.5.0) (2026-07-22)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* **ng-add:** add Firestore logging environment and security rules templates ([d5151c0](https://github.com/tech4good-lab/angular-schematics/commit/d5151c0f3ac63d5cd935cdf07a9fd970ac27f16a))
|
|
6
|
+
* **ng-add:** scaffold BigQuery views, queries, guide, and CLI scripts ([b4c2b7b](https://github.com/tech4good-lab/angular-schematics/commit/b4c2b7b44d6144cb9bf07be43431ef288d460206))
|
|
7
|
+
* **ng-add:** support object serialization in telemetry interactions ([ac14a3a](https://github.com/tech4good-lab/angular-schematics/commit/ac14a3ac290b12528eb52bc1ecb4233b93f3bc9a))
|
|
8
|
+
* **ng-add:** support revisitable consent page ([602ee5e](https://github.com/tech4good-lab/angular-schematics/commit/602ee5eaa25249e324b70aea2dce75d1c3a2b67b))
|
|
9
|
+
* **ng-add:** update consent component template and legal text ([bdf6926](https://github.com/tech4good-lab/angular-schematics/commit/bdf69262974346530f5137535042f38b4b1c54e9))
|
|
10
|
+
|
|
11
|
+
### Code Refactoring
|
|
12
|
+
|
|
13
|
+
* **ng-add:** update core time analytics service and analytics guide templates ([7781f43](https://github.com/tech4good-lab/angular-schematics/commit/7781f43ba79f20e98b3fe73bea2854f1bdd8e89c))
|
|
14
|
+
|
|
15
|
+
### Build System
|
|
16
|
+
|
|
17
|
+
* **ng-add:** bump template dependency for release ([5b644cd](https://github.com/tech4good-lab/angular-schematics/commit/5b644cd9990e0eb8b9c636a35ab1be8c49877464))
|
|
18
|
+
## [21.4.0](https://github.com/tech4good-lab/angular-schematics/compare/v21.3.0...v21.4.0) (2026-07-08)
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **entity:** add firestore.rules dev stub generation ([ad20a5f](https://github.com/tech4good-lab/angular-schematics/commit/ad20a5f67ad765111972c852b62f6bacf4dce795))
|
|
23
|
+
* **entity:** remove inDirectory prompt and add store path warning/redirect ([bee2496](https://github.com/tech4good-lab/angular-schematics/commit/bee2496edc99dfec5dbdb99c42f16dc35e629d44))
|
|
24
|
+
* **ng-add:** integrate scoped logging service templates ([26cf441](https://github.com/tech4good-lab/angular-schematics/commit/26cf4414c57a1342aa7440252276e2ef35b9ff88))
|
|
25
|
+
* **ng-add:** split email into userPrivates out of the box ([584b6bc](https://github.com/tech4good-lab/angular-schematics/commit/584b6bc33f8ec235992986229dafc1a59a1e5012))
|
|
26
|
+
* **shared:** add insertBefore utility to statements-adder ([9427c7a](https://github.com/tech4good-lab/angular-schematics/commit/9427c7a7ca1f75e8ed6bb487d13a6918dc3848e0))
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* **entity:** default path to core/store and resolve relative imports ([8ba7965](https://github.com/tech4good-lab/angular-schematics/commit/8ba796521aebf70e56e4444d44fa57ad2b8874fc))
|
|
31
|
+
* **ng-add:** update app component layout and dev status bar flex behavior ([65d7958](https://github.com/tech4good-lab/angular-schematics/commit/65d79581816cd798f83e77b83b180edc4f4403f1))
|
|
32
|
+
* **shared:** detect redeployment immediately if DOM hash differs on startup ([c7517e5](https://github.com/tech4good-lab/angular-schematics/commit/c7517e58ab7b0ae7321ca8cdde697e8053b4bc0b))
|
|
33
|
+
|
|
34
|
+
### Build System
|
|
35
|
+
|
|
36
|
+
* **ng-add:** add deploy scripts to package template ([49d8340](https://github.com/tech4good-lab/angular-schematics/commit/49d834034bb76c300788f73f81eda116b5147582))
|
|
37
|
+
* **ng-add:** bump template dependency for release ([a43065d](https://github.com/tech4good-lab/angular-schematics/commit/a43065d82657626257c49ade148d74844e97c5e2))
|
|
38
|
+
|
|
39
|
+
### Chores
|
|
40
|
+
|
|
41
|
+
* **ng-add:** ignore .impeccable directory in gitignore template ([3e4c5b8](https://github.com/tech4good-lab/angular-schematics/commit/3e4c5b829b3a02852615c844ae9d517dd79ca0c4))
|
|
1
42
|
## [21.3.0](https://github.com/tech4good-lab/angular-schematics/compare/v21.2.0...v21.3.0) (2026-07-03)
|
|
2
43
|
|
|
3
44
|
### Features
|
package/package.json
CHANGED
package/src/entity/index.js
CHANGED
|
@@ -16,7 +16,7 @@ function addInserts(options) {
|
|
|
16
16
|
const allcapsName = core_1.strings.classify(options.name).toUpperCase();
|
|
17
17
|
context.logger.info(`names: ${classifiedName}, ${camelizedName}`);
|
|
18
18
|
// app.model.ts changes
|
|
19
|
-
const appModelPath = '
|
|
19
|
+
const appModelPath = '/src/app/core/store/app.model.ts';
|
|
20
20
|
const appModelText = (0, statements_adder_1.getSourceText)(host, appModelPath);
|
|
21
21
|
context.logger.info(`appModelPath: ${appModelPath}`);
|
|
22
22
|
const entityModelPath = `/${options.path}/` +
|
|
@@ -33,7 +33,7 @@ function addInserts(options) {
|
|
|
33
33
|
` ${classifiedName} |`
|
|
34
34
|
]);
|
|
35
35
|
// firebase.mock.service.ts changes
|
|
36
|
-
const fbMockPath = '
|
|
36
|
+
const fbMockPath = '/src/app/core/firebase/firebase.mock.service.ts';
|
|
37
37
|
const fbMockText = (0, statements_adder_1.getSourceText)(host, fbMockPath);
|
|
38
38
|
const entityMockPath = `/${options.path}/` +
|
|
39
39
|
dasherizedName + '/' +
|
|
@@ -55,12 +55,28 @@ function addInserts(options) {
|
|
|
55
55
|
` ${camelizedName}s?: any[];`,
|
|
56
56
|
` if (${camelizedName}s) service.DB['${camelizedName}s'].init(${camelizedName}s);`
|
|
57
57
|
]);
|
|
58
|
+
// firestore.rules changes
|
|
59
|
+
const rulesPath = '/firestore.rules';
|
|
60
|
+
let rulesInsertChanges = [];
|
|
61
|
+
if (host.exists(rulesPath)) {
|
|
62
|
+
const rulesText = (0, statements_adder_1.getSourceText)(host, rulesPath);
|
|
63
|
+
if (rulesText.includes('// ─── Default deny')) {
|
|
64
|
+
rulesInsertChanges.push((0, statements_adder_1.insertBefore)(rulesText, rulesPath, '// ─── Default deny', `// ─── ${classifiedName}s (DEV STUB — replace in /feature-harden-implement) ───────────────────\n` +
|
|
65
|
+
` match /${camelizedName}s/{docId} {\n` +
|
|
66
|
+
` allow read, write: if request.auth != null;\n` +
|
|
67
|
+
` }\n\n `));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
58
70
|
context.logger.info(`about to start committing`);
|
|
59
71
|
// For each of the files and corresponding set of changes, commit to the tree
|
|
60
|
-
[
|
|
72
|
+
const fileChanges = [
|
|
61
73
|
[appModelPath, insertChangesInAppModel],
|
|
62
74
|
[fbMockPath, insertChangesInFbMock],
|
|
63
|
-
]
|
|
75
|
+
];
|
|
76
|
+
if (rulesInsertChanges.length > 0) {
|
|
77
|
+
fileChanges.push([rulesPath, rulesInsertChanges]);
|
|
78
|
+
}
|
|
79
|
+
fileChanges.forEach(([filePath, insertChanges]) => {
|
|
64
80
|
const declarationRecorder = host.beginUpdate(filePath);
|
|
65
81
|
for (const change of insertChanges) {
|
|
66
82
|
if (change instanceof change_1.InsertChange) {
|
|
@@ -74,11 +90,6 @@ function addInserts(options) {
|
|
|
74
90
|
}
|
|
75
91
|
function entity(options) {
|
|
76
92
|
return async (tree, context) => {
|
|
77
|
-
// Make sure the command is executed in the directory where the component should be generated
|
|
78
|
-
if (!options.inDirectory) {
|
|
79
|
-
context.logger.info("Please navigate to the directory where you want to generate the entity.");
|
|
80
|
-
return (0, schematics_1.noop)();
|
|
81
|
-
}
|
|
82
93
|
const workspace = await (0, workspace_1.getWorkspace)(tree);
|
|
83
94
|
const project = workspace.projects.get(options.project);
|
|
84
95
|
if (!project) {
|
|
@@ -87,6 +98,28 @@ function entity(options) {
|
|
|
87
98
|
if (options.path === undefined) {
|
|
88
99
|
options.path = (0, workspace_1.buildDefaultPath)(project);
|
|
89
100
|
}
|
|
101
|
+
if (options.path && !options.path.includes('src/app/core/store')) {
|
|
102
|
+
context.logger.warn('WARNING: Entity is being generated outside of src/app/core/store. We recommend generating entities in src/app/core/store.');
|
|
103
|
+
let redirect = false;
|
|
104
|
+
if (options.mockRedirect) {
|
|
105
|
+
redirect = true;
|
|
106
|
+
}
|
|
107
|
+
else if (process.stdout.isTTY && options.interactive !== false) {
|
|
108
|
+
const inquirer = await (new Function('return import("inquirer")')()).then((m) => m.default);
|
|
109
|
+
const answers = await inquirer.prompt([
|
|
110
|
+
{
|
|
111
|
+
type: 'confirm',
|
|
112
|
+
name: 'redirect',
|
|
113
|
+
message: 'Would you like to generate this in src/app/core/store instead?',
|
|
114
|
+
default: true
|
|
115
|
+
}
|
|
116
|
+
]);
|
|
117
|
+
redirect = answers.redirect;
|
|
118
|
+
}
|
|
119
|
+
if (redirect) {
|
|
120
|
+
options.path = 'src/app/core/store';
|
|
121
|
+
}
|
|
122
|
+
}
|
|
90
123
|
const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
|
|
91
124
|
options.name = parsedPath.name;
|
|
92
125
|
options.path = parsedPath.path;
|
package/src/entity/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AA2HA,wBAuDC;AAlLD,2DAIoC;AAEpC,+DAA0E;AAC1E,yEAA4E;AAC5E,uEAAmE;AACnE,qEAAuF;AACvF,+CAA+C;AAE/C,iEAAuF;AAEvF,SAAS,UAAU,CAAC,OAAY;IAC9B,OAAO,CAAC,IAAU,EAAE,OAAyB,EAAE,EAAE;QAE/C,MAAM,cAAc,GAAG,cAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,aAAa,GAAG,cAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACrD,MAAM,cAAc,GAAG,cAAO,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACvD,MAAM,WAAW,GAAG,cAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QACjE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,cAAc,KAAK,aAAa,EAAE,CAAC,CAAC;QAElE,uBAAuB;QACvB,MAAM,YAAY,GAAG,kCAAkC,CAAC;QACxD,MAAM,YAAY,GAAG,IAAA,gCAAa,EAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QACvD,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,YAAY,EAAE,CAAC,CAAC;QAErD,MAAM,eAAe,GACnB,IAAI,OAAO,CAAC,IAAI,GAAG;YACnB,cAAc,GAAG,GAAG;YACpB,cAAc,GAAG,QAAQ,CAAC;QAC5B,OAAO,C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EAAgE;wBACzE,OAAO,EAAE,IAAI;qBACd;iBACF,CAAC,CAAC;gBACH,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;YAC9B,CAAC;YAED,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO,CAAC,IAAI,GAAG,oBAAoB,CAAC;YACtC,CAAC;QACH,CAAC;QAED,MAAM,UAAU,GAAG,IAAA,sBAAS,EAAC,OAAO,CAAC,IAAc,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QACnE,OAAO,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;QAC/B,OAAO,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;QAE/B,MAAM,cAAc,GAAG,IAAA,kBAAK,EAAC,IAAA,gBAAG,EAAC,SAAS,CAAC,EAAE;YAC3C,IAAA,2BAAc,EAAC;gBACb,GAAG,cAAO;gBACV,GAAG,OAAO;aACX,CAAC;YACF,IAAA,iBAAI,EAAC,UAAU,CAAC,IAAI,CAAC;SACtB,CAAC,CAAC;QAEH,OAAO,IAAA,kBAAK,EAAC;YACX,UAAU,CAAC,OAAO,CAAC;YACnB,IAAA,sBAAS,EAAC,cAAc,CAAC;SAC1B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
package/src/entity/index_spec.js
CHANGED
|
@@ -65,7 +65,6 @@ describe('entity', () => {
|
|
|
65
65
|
const tree = await runner.runSchematic('entity', {
|
|
66
66
|
name: 'session',
|
|
67
67
|
project: 'test-app',
|
|
68
|
-
inDirectory: true,
|
|
69
68
|
path: 'src/app/core/store',
|
|
70
69
|
}, createWorkspaceTree());
|
|
71
70
|
// Verify the expected entity files are generated
|
|
@@ -77,7 +76,6 @@ describe('entity', () => {
|
|
|
77
76
|
const tree = await runner.runSchematic('entity', {
|
|
78
77
|
name: 'session',
|
|
79
78
|
project: 'test-app',
|
|
80
|
-
inDirectory: true,
|
|
81
79
|
path: 'src/app/core/store',
|
|
82
80
|
}, createWorkspaceTree());
|
|
83
81
|
const appModel = tree.readContent('/src/app/core/store/app.model.ts');
|
|
@@ -90,7 +88,6 @@ describe('entity', () => {
|
|
|
90
88
|
const tree = await runner.runSchematic('entity', {
|
|
91
89
|
name: 'session',
|
|
92
90
|
project: 'test-app',
|
|
93
|
-
inDirectory: true,
|
|
94
91
|
path: 'src/app/core/store',
|
|
95
92
|
}, createWorkspaceTree());
|
|
96
93
|
const fbMock = tree.readContent('/src/app/core/firebase/firebase.mock.service.ts');
|
|
@@ -105,15 +102,52 @@ describe('entity', () => {
|
|
|
105
102
|
expect(fbMock).toContain('sessions,');
|
|
106
103
|
expect(fbMock).toContain('sessions?: any[]');
|
|
107
104
|
});
|
|
108
|
-
it('should
|
|
105
|
+
it('should warn when path is outside src/app/core/store', async () => {
|
|
106
|
+
let warningMessage = '';
|
|
107
|
+
runner.logger.subscribe(entry => {
|
|
108
|
+
if (entry.level === 'warn') {
|
|
109
|
+
warningMessage = entry.message;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
await runner.runSchematic('entity', {
|
|
113
|
+
name: 'session',
|
|
114
|
+
project: 'test-app',
|
|
115
|
+
path: 'src/app/some-other-place',
|
|
116
|
+
}, createWorkspaceTree());
|
|
117
|
+
expect(warningMessage).toContain('outside of src/app/core/store');
|
|
118
|
+
});
|
|
119
|
+
it('should redirect path to src/app/core/store when mockRedirect is true', async () => {
|
|
109
120
|
const tree = await runner.runSchematic('entity', {
|
|
110
121
|
name: 'session',
|
|
111
122
|
project: 'test-app',
|
|
112
|
-
|
|
113
|
-
|
|
123
|
+
path: 'src/app/some-other-place',
|
|
124
|
+
mockRedirect: true,
|
|
114
125
|
}, createWorkspaceTree());
|
|
115
|
-
//
|
|
116
|
-
expect(tree.files).
|
|
126
|
+
// Verify files generated in redirected path
|
|
127
|
+
expect(tree.files).toContain('/src/app/core/store/session/session.model.ts');
|
|
128
|
+
expect(tree.files).toContain('/src/app/core/store/session/session.store.ts');
|
|
129
|
+
expect(tree.files).toContain('/src/app/core/store/session/session.mock.ts');
|
|
130
|
+
expect(tree.files).not.toContain('/src/app/some-other-place/session/session.model.ts');
|
|
131
|
+
});
|
|
132
|
+
it('should add dev stub security rules to firestore.rules if the file exists', async () => {
|
|
133
|
+
const workspace = createWorkspaceTree();
|
|
134
|
+
workspace.create('/firestore.rules', [
|
|
135
|
+
"rules_version = '2';",
|
|
136
|
+
"service cloud.firestore {",
|
|
137
|
+
" match /databases/{database}/documents {",
|
|
138
|
+
" // ─── Default deny ───",
|
|
139
|
+
" }",
|
|
140
|
+
"}",
|
|
141
|
+
].join('\n'));
|
|
142
|
+
const tree = await runner.runSchematic('entity', {
|
|
143
|
+
name: 'session',
|
|
144
|
+
project: 'test-app',
|
|
145
|
+
path: 'src/app/core/store',
|
|
146
|
+
}, workspace);
|
|
147
|
+
const rules = tree.readContent('/firestore.rules');
|
|
148
|
+
expect(rules).toContain('Sessions (DEV STUB — replace in /feature-harden-implement)');
|
|
149
|
+
expect(rules).toContain('match /sessions/{docId}');
|
|
150
|
+
expect(rules).toContain('allow read, write: if request.auth != null;');
|
|
117
151
|
});
|
|
118
152
|
});
|
|
119
153
|
//# sourceMappingURL=index_spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index_spec.js","sourceRoot":"","sources":["index_spec.ts"],"names":[],"mappings":";;;AAAA,2DAAkD;AAClD,gEAAuF;AACvF,mDAA6B;AAE7B,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;AAElE;;;;GAIG;AACH,SAAS,mBAAmB;IAC1B,MAAM,IAAI,GAAG,IAAI,sBAAY,CAAC,iBAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IAE5C,gDAAgD;IAChD,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC;QAC1C,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE;YACR,UAAU,EAAE;gBACV,WAAW,EAAE,aAAa;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},
|
|
35
35
|
"x-prompt": "What name would you like to use for the entity?"
|
|
36
|
-
},
|
|
37
|
-
"inDirectory": {
|
|
38
|
-
"type": "boolean",
|
|
39
|
-
"default": true,
|
|
40
|
-
"x-prompt": "Are you currently in the directory where you want to generate the entity? (typically directly in src/app/core/store)"
|
|
41
36
|
}
|
|
42
37
|
},
|
|
43
38
|
"required": [
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
"projects": {
|
|
3
3
|
"default": "<%= dasherize(project) %>-dev",
|
|
4
4
|
"dev": "<%= dasherize(project) %>-dev",
|
|
5
|
-
"prod": "<%= dasherize(project) %>-prod"
|
|
5
|
+
"prod": "<%= dasherize(project) %>-prod",
|
|
6
|
+
"log": "<%= dasherize(project) %>-log"
|
|
6
7
|
},
|
|
7
8
|
"targets": {},
|
|
8
9
|
"etags": {}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
-- Query: active_time_by_route
|
|
2
|
+
-- Description: Analyzes the distribution of active engagement time (in seconds) spent
|
|
3
|
+
-- on different routes. Computes total visits, mean active seconds, and percentiles
|
|
4
|
+
-- (Min, Q1, Median, Q3, Max) for each route.
|
|
5
|
+
|
|
6
|
+
WITH route_visit_times AS (
|
|
7
|
+
SELECT
|
|
8
|
+
route,
|
|
9
|
+
-- Convert milliseconds to seconds
|
|
10
|
+
total_active_ms / 1000.0 AS active_seconds
|
|
11
|
+
FROM
|
|
12
|
+
`analytics.events_flat`
|
|
13
|
+
WHERE
|
|
14
|
+
event_type = 'route_visit'
|
|
15
|
+
AND total_active_ms > 0
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
SELECT
|
|
19
|
+
route,
|
|
20
|
+
COUNT(*) AS total_visits,
|
|
21
|
+
ROUND(AVG(active_seconds), 2) AS mean_active_seconds,
|
|
22
|
+
|
|
23
|
+
-- APPROX_QUANTILES returns a 5-element array: [Min, 25th (Q1), 50th (Median), 75th (Q3), Max]
|
|
24
|
+
ROUND(APPROX_QUANTILES(active_seconds, 4)[OFFSET(0)], 2) AS min_active_seconds,
|
|
25
|
+
ROUND(APPROX_QUANTILES(active_seconds, 4)[OFFSET(1)], 2) AS q1_active_seconds,
|
|
26
|
+
ROUND(APPROX_QUANTILES(active_seconds, 4)[OFFSET(2)], 2) AS median_active_seconds,
|
|
27
|
+
ROUND(APPROX_QUANTILES(active_seconds, 4)[OFFSET(3)], 2) AS q3_active_seconds,
|
|
28
|
+
ROUND(APPROX_QUANTILES(active_seconds, 4)[OFFSET(4)], 2) AS max_active_seconds
|
|
29
|
+
FROM
|
|
30
|
+
route_visit_times
|
|
31
|
+
GROUP BY
|
|
32
|
+
route
|
|
33
|
+
ORDER BY
|
|
34
|
+
total_visits DESC;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Firestore Entity Exporter
|
|
4
|
+
|
|
5
|
+
This script exports any specified Firestore collection to a local JSON or CSV file.
|
|
6
|
+
Useful for pulling low-volume, PII-sensitive collections (like user responses)
|
|
7
|
+
on-demand to run Jupyter notebook analyses without storing them persistently in BigQuery.
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
# Export to JSON
|
|
11
|
+
python bigquery/scripts/export_entities.py --collection <collection-name> --output data.json
|
|
12
|
+
|
|
13
|
+
# Export to CSV
|
|
14
|
+
python bigquery/scripts/export_entities.py --collection <collection-name> --output data.csv
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import argparse
|
|
18
|
+
import csv
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
import sys
|
|
22
|
+
from datetime import datetime
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
import firebase_admin
|
|
26
|
+
from firebase_admin import credentials, firestore
|
|
27
|
+
from google.api_core.datetime_helpers import DatetimeWithNanoseconds
|
|
28
|
+
except ImportError:
|
|
29
|
+
print("Error: Required packages missing. Please install dependencies:")
|
|
30
|
+
print(" pip install firebase-admin google-api-core")
|
|
31
|
+
sys.exit(1)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def parse_value(val):
|
|
35
|
+
"""Recursively converts Firestore Timestamp objects and other non-JSON-serializable types."""
|
|
36
|
+
if isinstance(val, DatetimeWithNanoseconds):
|
|
37
|
+
return val.isoformat()
|
|
38
|
+
elif isinstance(val, datetime):
|
|
39
|
+
return val.isoformat()
|
|
40
|
+
elif isinstance(val, dict):
|
|
41
|
+
return {k: parse_value(v) for k, v in val.items()}
|
|
42
|
+
elif isinstance(val, list):
|
|
43
|
+
return [parse_value(x) for x in val]
|
|
44
|
+
return val
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def main():
|
|
48
|
+
parser = argparse.ArgumentParser(description="Export Firestore collections to JSON or CSV.")
|
|
49
|
+
parser.add_argument(
|
|
50
|
+
"--collection",
|
|
51
|
+
required=True,
|
|
52
|
+
help="Name of the Firestore collection to export",
|
|
53
|
+
)
|
|
54
|
+
parser.add_argument(
|
|
55
|
+
"--output",
|
|
56
|
+
required=True,
|
|
57
|
+
help="Local file path for the export (must end in .json or .csv)",
|
|
58
|
+
)
|
|
59
|
+
parser.add_argument(
|
|
60
|
+
"--credentials",
|
|
61
|
+
help="Path to the Firebase service account key JSON file. "
|
|
62
|
+
"If omitted, falls back to GOOGLE_APPLICATION_CREDENTIALS env var.",
|
|
63
|
+
)
|
|
64
|
+
args = parser.parse_args()
|
|
65
|
+
|
|
66
|
+
# 1. Initialize Firebase App
|
|
67
|
+
if not firebase_admin._apps:
|
|
68
|
+
try:
|
|
69
|
+
if args.credentials:
|
|
70
|
+
cred = credentials.Certificate(args.credentials)
|
|
71
|
+
firebase_admin.initialize_app(cred)
|
|
72
|
+
elif os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"):
|
|
73
|
+
cred = credentials.Certificate(os.environ["GOOGLE_APPLICATION_CREDENTIALS"])
|
|
74
|
+
firebase_admin.initialize_app(cred)
|
|
75
|
+
else:
|
|
76
|
+
# Attempt to load Application Default Credentials
|
|
77
|
+
firebase_admin.initialize_app()
|
|
78
|
+
except Exception as e:
|
|
79
|
+
print("Authentication Error: Could not initialize Firebase Admin SDK.")
|
|
80
|
+
print("Please either:")
|
|
81
|
+
print(" 1. Download a service account JSON file from Firebase Console -> Project Settings -> Service accounts.")
|
|
82
|
+
print(" 2. Pass it using --credentials /path/to/key.json")
|
|
83
|
+
print(" 3. Or run: export GOOGLE_APPLICATION_CREDENTIALS='/path/to/key.json'")
|
|
84
|
+
print(f"Details: {e}")
|
|
85
|
+
sys.exit(1)
|
|
86
|
+
|
|
87
|
+
db = firestore.client()
|
|
88
|
+
collection_ref = db.collection(args.collection)
|
|
89
|
+
|
|
90
|
+
print(f"Fetching documents from collection '{args.collection}'...")
|
|
91
|
+
docs = list(collection_ref.stream())
|
|
92
|
+
print(f"Retrieved {len(docs)} documents.")
|
|
93
|
+
|
|
94
|
+
if not docs:
|
|
95
|
+
print("No documents found. Exiting.")
|
|
96
|
+
return
|
|
97
|
+
|
|
98
|
+
# 2. Extract and format data
|
|
99
|
+
flat_data = []
|
|
100
|
+
headers = set()
|
|
101
|
+
|
|
102
|
+
for doc in docs:
|
|
103
|
+
doc_dict = doc.to_dict()
|
|
104
|
+
doc_dict["__id"] = doc.id # Include primary document ID
|
|
105
|
+
parsed_dict = parse_value(doc_dict)
|
|
106
|
+
flat_data.append(parsed_dict)
|
|
107
|
+
headers.update(parsed_dict.keys())
|
|
108
|
+
|
|
109
|
+
# Sort headers to ensure consistent column ordering in CSV, placing __id first
|
|
110
|
+
headers = sorted(list(headers))
|
|
111
|
+
if "__id" in headers:
|
|
112
|
+
headers.remove("__id")
|
|
113
|
+
headers.insert(0, "__id")
|
|
114
|
+
|
|
115
|
+
# 3. Write output
|
|
116
|
+
output_path = args.output
|
|
117
|
+
ext = os.path.splitext(output_path)[1].lower()
|
|
118
|
+
|
|
119
|
+
if ext == ".json":
|
|
120
|
+
with open(output_path, "w", encoding="utf-8") as f:
|
|
121
|
+
json.dump(flat_data, f, indent=2, ensure_ascii=False)
|
|
122
|
+
print(f"Successfully exported data to JSON: {output_path}")
|
|
123
|
+
|
|
124
|
+
elif ext == ".csv":
|
|
125
|
+
with open(output_path, "w", encoding="utf-8", newline="") as f:
|
|
126
|
+
writer = csv.DictWriter(f, fieldnames=headers, extrasaction="ignore")
|
|
127
|
+
writer.writeheader()
|
|
128
|
+
for row in flat_data:
|
|
129
|
+
csv_row = {}
|
|
130
|
+
for k, v in row.items():
|
|
131
|
+
if isinstance(v, (dict, list)):
|
|
132
|
+
csv_row[k] = json.dumps(v, ensure_ascii=False)
|
|
133
|
+
else:
|
|
134
|
+
csv_row[k] = v
|
|
135
|
+
writer.writerow(csv_row)
|
|
136
|
+
print(f"Successfully exported data to CSV: {output_path}")
|
|
137
|
+
else:
|
|
138
|
+
print(f"Error: Unknown output format '{ext}'. Must be .json or .csv.")
|
|
139
|
+
sys.exit(1)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
if __name__ == "__main__":
|
|
143
|
+
main()
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
BigQuery Query Runner
|
|
4
|
+
|
|
5
|
+
Runs a specified SQL query file against Google BigQuery and exports the results
|
|
6
|
+
to JSON, CSV, or a local SQLite database.
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
# Export to JSON
|
|
10
|
+
python bigquery/scripts/run_query.py --project <your-gcp-project-id> --query bigquery/queries/active_time_by_route.sql --output output.json
|
|
11
|
+
|
|
12
|
+
# Export to CSV
|
|
13
|
+
python bigquery/scripts/run_query.py --project <your-gcp-project-id> --query bigquery/queries/active_time_by_route.sql --output output.csv
|
|
14
|
+
|
|
15
|
+
# Export to SQLite
|
|
16
|
+
python bigquery/scripts/run_query.py --project <your-gcp-project-id> --query bigquery/queries/active_time_by_route.sql --output metrics.db --table active_time
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import argparse
|
|
20
|
+
import csv
|
|
21
|
+
import json
|
|
22
|
+
import os
|
|
23
|
+
import sqlite3
|
|
24
|
+
import sys
|
|
25
|
+
|
|
26
|
+
try:
|
|
27
|
+
from google.cloud import bigquery
|
|
28
|
+
except ImportError:
|
|
29
|
+
print("Error: Required package 'google-cloud-bigquery' missing. Please install it:")
|
|
30
|
+
print(" pip install google-cloud-bigquery")
|
|
31
|
+
sys.exit(1)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def main():
|
|
35
|
+
parser = argparse.ArgumentParser(description="Run BigQuery SQL queries and export results.")
|
|
36
|
+
parser.add_argument(
|
|
37
|
+
"--query",
|
|
38
|
+
required=True,
|
|
39
|
+
help="Path to the SQL file to run (e.g., bigquery/queries/active_time_by_route.sql)",
|
|
40
|
+
)
|
|
41
|
+
parser.add_argument(
|
|
42
|
+
"--output",
|
|
43
|
+
required=True,
|
|
44
|
+
help="Local file path for the export (must end in .json, .csv, or .db/.sqlite)",
|
|
45
|
+
)
|
|
46
|
+
parser.add_argument(
|
|
47
|
+
"--project",
|
|
48
|
+
required=True,
|
|
49
|
+
help="GCP Project ID to run the query against (e.g., <your-gcp-project-id>)",
|
|
50
|
+
)
|
|
51
|
+
parser.add_argument(
|
|
52
|
+
"--table",
|
|
53
|
+
help="Target table name when exporting to a SQLite database. Required if output is SQLite.",
|
|
54
|
+
)
|
|
55
|
+
parser.add_argument(
|
|
56
|
+
"--credentials",
|
|
57
|
+
help="Path to the Google service account key JSON file. "
|
|
58
|
+
"If omitted, falls back to GOOGLE_APPLICATION_CREDENTIALS env var.",
|
|
59
|
+
)
|
|
60
|
+
args = parser.parse_args()
|
|
61
|
+
|
|
62
|
+
# 1. Validate inputs
|
|
63
|
+
if not os.path.exists(args.query):
|
|
64
|
+
print(f"Error: Query file not found at {args.query}")
|
|
65
|
+
sys.exit(1)
|
|
66
|
+
|
|
67
|
+
output_ext = os.path.splitext(args.output)[1].lower()
|
|
68
|
+
is_sqlite = output_ext in [".db", ".sqlite", ".sqlite3"]
|
|
69
|
+
if is_sqlite and not args.table:
|
|
70
|
+
print("Error: --table argument is required when exporting to a SQLite database.")
|
|
71
|
+
sys.exit(1)
|
|
72
|
+
|
|
73
|
+
with open(args.query, "r", encoding="utf-8") as f:
|
|
74
|
+
query_string = f.read()
|
|
75
|
+
|
|
76
|
+
# 2. Initialize BigQuery Client
|
|
77
|
+
try:
|
|
78
|
+
if args.credentials:
|
|
79
|
+
client = bigquery.Client.from_service_account_json(args.credentials, project=args.project)
|
|
80
|
+
else:
|
|
81
|
+
client = bigquery.Client(project=args.project)
|
|
82
|
+
except Exception as e:
|
|
83
|
+
print("Authentication Error: Could not initialize BigQuery Client.")
|
|
84
|
+
print("Please check your credentials or run:")
|
|
85
|
+
print(" export GOOGLE_APPLICATION_CREDENTIALS='/path/to/key.json'")
|
|
86
|
+
print(f"Details: {e}")
|
|
87
|
+
sys.exit(1)
|
|
88
|
+
|
|
89
|
+
# 3. Execute Query
|
|
90
|
+
print(f"Executing query '{args.query}' in project '{args.project}'...")
|
|
91
|
+
try:
|
|
92
|
+
query_job = client.query(query_string)
|
|
93
|
+
results = query_job.result() # Waits for query to complete
|
|
94
|
+
print("Query completed successfully. Fetching rows...")
|
|
95
|
+
except Exception as e:
|
|
96
|
+
print(f"Query Execution Error: {e}")
|
|
97
|
+
sys.exit(1)
|
|
98
|
+
|
|
99
|
+
# Convert rows to a list of dicts for export
|
|
100
|
+
rows = [dict(row) for row in results]
|
|
101
|
+
if not rows:
|
|
102
|
+
print("Query returned 0 rows. Exiting.")
|
|
103
|
+
return
|
|
104
|
+
|
|
105
|
+
# 4. Write Output
|
|
106
|
+
if output_ext == ".json":
|
|
107
|
+
with open(args.output, "w", encoding="utf-8") as f:
|
|
108
|
+
json.dump(rows, f, indent=2, default=str)
|
|
109
|
+
print(f"Successfully exported {len(rows)} rows to JSON: {args.output}")
|
|
110
|
+
|
|
111
|
+
elif output_ext == ".csv":
|
|
112
|
+
headers = list(rows[0].keys())
|
|
113
|
+
with open(args.output, "w", encoding="utf-8", newline="") as f:
|
|
114
|
+
writer = csv.DictWriter(f, fieldnames=headers)
|
|
115
|
+
writer.writeheader()
|
|
116
|
+
for row in rows:
|
|
117
|
+
# Stringify nested structures
|
|
118
|
+
row_clean = {k: (json.dumps(v) if isinstance(v, (dict, list)) else v) for k, v in row.items()}
|
|
119
|
+
writer.writerow(row_clean)
|
|
120
|
+
print(f"Successfully exported {len(rows)} rows to CSV: {args.output}")
|
|
121
|
+
|
|
122
|
+
elif is_sqlite:
|
|
123
|
+
headers = list(rows[0].keys())
|
|
124
|
+
conn = sqlite3.connect(args.output)
|
|
125
|
+
cursor = conn.cursor()
|
|
126
|
+
|
|
127
|
+
# Dynamic table creation based on BigQuery results schema
|
|
128
|
+
# Maps common types, defaults everything else to TEXT
|
|
129
|
+
columns_def = []
|
|
130
|
+
for key, val in rows[0].items():
|
|
131
|
+
if isinstance(val, int):
|
|
132
|
+
col_type = "INTEGER"
|
|
133
|
+
elif isinstance(val, float):
|
|
134
|
+
col_type = "REAL"
|
|
135
|
+
else:
|
|
136
|
+
col_type = "TEXT"
|
|
137
|
+
columns_def.append(f"`{key}` {col_type}")
|
|
138
|
+
|
|
139
|
+
create_table_sql = f"CREATE TABLE IF NOT EXISTS `{args.table}` ({', '.join(columns_def)})"
|
|
140
|
+
cursor.execute(create_table_sql)
|
|
141
|
+
|
|
142
|
+
# Insert rows
|
|
143
|
+
insert_placeholders = ", ".join(["?"] * len(headers))
|
|
144
|
+
insert_sql = f"INSERT INTO `{args.table}` ({', '.join([f'`{h}`' for h in headers])}) VALUES ({insert_placeholders})"
|
|
145
|
+
|
|
146
|
+
insert_data = []
|
|
147
|
+
for row in rows:
|
|
148
|
+
row_data = []
|
|
149
|
+
for header in headers:
|
|
150
|
+
val = row[header]
|
|
151
|
+
if isinstance(val, (dict, list)):
|
|
152
|
+
row_data.append(json.dumps(val))
|
|
153
|
+
else:
|
|
154
|
+
row_data.append(val)
|
|
155
|
+
insert_data.append(tuple(row_data))
|
|
156
|
+
|
|
157
|
+
cursor.executemany(insert_sql, insert_data)
|
|
158
|
+
conn.commit()
|
|
159
|
+
conn.close()
|
|
160
|
+
print(f"Successfully imported {len(rows)} rows into SQLite table '{args.table}': {args.output}")
|
|
161
|
+
else:
|
|
162
|
+
print(f"Error: Unknown output format '{output_ext}'. Must be .json, .csv, or .db/.sqlite.")
|
|
163
|
+
sys.exit(1)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
if __name__ == "__main__":
|
|
167
|
+
main()
|