@tech4good/angular-schematics 21.5.0 → 21.7.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/CHANGELOG.md +44 -0
- package/README.md +266 -1
- package/package.json +34 -7
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.spec.ts.template +4 -5
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.ts.template +1 -1
- package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +16 -7
- package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +13 -6
- package/src/entity/files/__name@dasherize__/__name@dasherize__.store.ts.template +18 -10
- package/src/entity/index.js +61 -49
- package/src/entity/index.js.map +1 -1
- package/src/entity/schema.json +4 -0
- package/src/guard/files/__name@dasherize__.guard.spec.ts.template +0 -1
- package/src/ng-add/files/.github/workflows/angular-github-ci.yml.template +3 -0
- package/src/ng-add/files/.gitignore.template +5 -0
- package/src/ng-add/files/analytics/datasets.js.template +206 -0
- package/src/ng-add/files/analytics/entity_sources.js.template +58 -0
- package/src/ng-add/files/analytics/entity_sources.test.js.template +57 -0
- package/src/ng-add/files/analytics/lib/api_query.js.template +87 -0
- package/src/ng-add/files/analytics/lib/api_query.test.js.template +84 -0
- package/src/ng-add/files/analytics/lib/bigquery_query_compatibility.test.js.template +53 -0
- package/src/ng-add/files/analytics/lib/dataset_schema.js.template +53 -0
- package/src/ng-add/files/analytics/lib/dataset_schema.test.js.template +34 -0
- package/src/ng-add/files/analytics/lib/entity_sync.js.template +397 -0
- package/src/ng-add/files/analytics/lib/entity_sync.test.js.template +212 -0
- package/src/ng-add/files/analytics/lib/identifier_salt.js.template +57 -0
- package/src/ng-add/files/analytics/lib/identifier_salt.test.js.template +36 -0
- package/src/ng-add/files/analytics/lib/snapshot_files.js.template +46 -0
- package/src/ng-add/files/analytics/lib/snapshot_files.test.js.template +67 -0
- package/src/ng-add/files/analytics/lib/sqlite.js.template +92 -0
- package/src/ng-add/files/analytics/lib/upload_entities.js.template +81 -0
- package/src/ng-add/files/analytics/lib/upload_entities.test.js.template +86 -0
- package/src/ng-add/files/analytics/proxy.conf.json.template +7 -0
- package/src/ng-add/files/analytics/scripts/refresh_snapshot.js.template +518 -0
- package/src/ng-add/files/analytics/scripts/start.js.template +88 -0
- package/src/ng-add/files/analytics/server/server.js.template +212 -0
- package/src/ng-add/files/angular.json.template +80 -1
- package/src/ng-add/files/bigquery/queries/active_time_by_route.sql.template +27 -8
- package/src/ng-add/files/bigquery/queries/active_user_windows.sql.template +67 -0
- package/src/ng-add/files/bigquery/queries/dashboard_route_visits.sql.template +47 -0
- package/src/ng-add/files/bigquery/queries/data_quality.sql.template +323 -0
- package/src/ng-add/files/bigquery/queries/onboarding_funnel.sql.template +512 -0
- package/src/ng-add/files/bigquery/queries/onboarding_stage_observations.sql.template +134 -0
- package/src/ng-add/files/bigquery/queries/weekly_retention_cohorts.sql.template +90 -0
- package/src/ng-add/files/bigquery/scripts/export_entities.js.template +120 -0
- package/src/ng-add/files/bigquery/scripts/init_views.js.template +57 -0
- package/src/ng-add/files/bigquery/scripts/run_query.js.template +141 -0
- package/src/ng-add/files/bigquery/views/events_flat.sql.template +27 -12
- package/src/ng-add/files/bigquery/views/logs_latest.sql.template +16 -3
- package/src/ng-add/files/docs-infra/analytics-guide.md.template +270 -25
- package/src/ng-add/files/docs-infra/analytics-workbench-guide.md.template +307 -0
- package/src/ng-add/files/docs-infra/authentication-architecture.md.template +300 -0
- package/src/ng-add/files/docs-infra/email-infrastructure.md.template +43 -0
- package/src/ng-add/files/docs-infra/firestore-index-checker.md.template +87 -0
- package/src/ng-add/files/docs-infra/infrastructure-guide.md.template +123 -38
- package/src/ng-add/files/docs-infra/load-system-architecture.md.template +15 -1
- package/src/ng-add/files/docs-infra/querying-strategy.md.template +14 -0
- package/src/ng-add/files/docs-infra/stream-system-architecture.md.template +21 -7
- package/src/ng-add/files/eslint.config.js.template +22 -3
- package/src/ng-add/files/firebase.json.template +6 -0
- package/src/ng-add/files/firestore.indexes.json.template +23 -0
- package/src/ng-add/files/firestore.rules.spec.ts.template +84 -15
- package/src/ng-add/files/firestore.rules.template +29 -17
- package/src/ng-add/files/functions/.gitignore.template +3 -0
- package/src/ng-add/files/functions/package.json.template +13 -0
- package/src/ng-add/files/functions/src/email.ts.template +23 -0
- package/src/ng-add/files/functions/src/index.ts.template +44 -0
- package/src/ng-add/files/functions/tsconfig.json.template +13 -0
- package/src/ng-add/files/jest.config.ts.template +3 -2
- package/src/ng-add/files/package.json.template +41 -16
- package/src/ng-add/files/projects/analytics/src/app/analytics-api.service.ts.template +130 -0
- package/src/ng-add/files/projects/analytics/src/app/app.component.html.template +77 -0
- package/src/ng-add/files/projects/analytics/src/app/app.component.scss.template +240 -0
- package/src/ng-add/files/projects/analytics/src/app/app.component.ts.template +96 -0
- package/src/ng-add/files/projects/analytics/src/app/app.routes.ts.template +11 -0
- package/src/ng-add/files/projects/analytics/src/app/dashboard-pages.spec.ts.template +151 -0
- package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.html.template +39 -0
- package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.scss.template +1 -0
- package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.ts.template +95 -0
- package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.html.template +47 -0
- package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.scss.template +1 -0
- package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.ts.template +120 -0
- package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.html.template +40 -0
- package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.scss.template +1 -0
- package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.ts.template +98 -0
- package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.html.template +35 -0
- package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.scss.template +1 -0
- package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.ts.template +84 -0
- package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.html.template +42 -0
- package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.scss.template +1 -0
- package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.ts.template +110 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/analytics-utils.ts.template +43 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/chart-theme.ts.template +42 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-layout.scss.template +239 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.html.template +76 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.scss.template +128 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.spec.ts.template +31 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.ts.template +153 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.html.template +16 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.scss.template +63 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.ts.template +52 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.html.template +5 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.scss.template +56 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.spec.ts.template +30 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.ts.template +15 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.html.template +9 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.scss.template +43 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.ts.template +62 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.html.template +9 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.scss.template +33 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.ts.template +82 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.html.template +15 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.scss.template +45 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.ts.template +55 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.html.template +18 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.scss.template +45 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.ts.template +15 -0
- package/src/ng-add/files/projects/analytics/src/app/vega-chart/vega-chart.component.ts.template +121 -0
- package/src/ng-add/files/projects/analytics/src/index.html.template +19 -0
- package/src/ng-add/files/projects/analytics/src/main.ts.template +16 -0
- package/src/ng-add/files/projects/analytics/src/styles.scss.template +28 -0
- package/src/ng-add/files/projects/analytics/tsconfig.app.json.template +13 -0
- package/src/ng-add/files/projects/analytics/tsconfig.spec.json.template +15 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.html.template +3 -1
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.spec.ts.template +10 -13
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.ts.template +2 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.spec.ts.template +11 -12
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.ts.template +7 -7
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.spec.ts.template +8 -10
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.ts.template +3 -2
- package/src/ng-add/files/src/app/app.component.html.template +3 -3
- package/src/ng-add/files/src/app/app.component.scss.template +1 -1
- package/src/ng-add/files/src/app/app.component.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/app.component.ts.template +3 -2
- package/src/ng-add/files/src/app/app.config.ts.template +21 -15
- package/src/ng-add/files/src/app/app.routes.ts.template +6 -0
- package/src/ng-add/files/src/app/auth-routing.spec.ts.template +13 -9
- package/src/ng-add/files/src/app/core/analytics/time-analytics.service.spec.ts.template +46 -29
- package/src/ng-add/files/src/app/core/analytics/time-analytics.service.ts.template +27 -18
- package/src/ng-add/files/src/app/core/auth/auth.providers.spec.ts.template +112 -0
- package/src/ng-add/files/src/app/core/auth/auth.providers.ts.template +48 -0
- package/src/ng-add/files/src/app/core/auth/auth.service.ts.template +14 -23
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.spec.ts.template +27 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.ts.template +3 -2
- package/src/ng-add/files/src/app/core/auth/guards/require-auth-and-consent.guard.ts.template +7 -2
- package/src/ng-add/files/src/app/core/firebase/data.providers.prod.ts.template +21 -0
- package/src/ng-add/files/src/app/core/firebase/data.providers.ts.template +13 -0
- package/src/ng-add/files/src/app/core/local-storage/session.service.spec.ts.template +43 -0
- package/src/ng-add/files/src/app/core/local-storage/session.service.ts.template +7 -0
- package/src/ng-add/files/src/app/core/store/app-data.spec.ts.template +76 -0
- package/src/ng-add/files/src/app/core/store/auth/auth.mock.ts.template +20 -82
- package/src/ng-add/files/src/app/core/store/auth/auth.store.spec.ts.template +217 -0
- package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +36 -172
- package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +18 -15
- package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +7 -8
- package/src/ng-add/files/src/app/core/store/user/user.store.ts.template +14 -10
- package/src/ng-add/files/src/app/core/store/user-context/user-context.mock.ts.template +20 -8
- package/src/ng-add/files/src/app/core/store/user-context/user-context.model.ts.template +5 -6
- package/src/ng-add/files/src/app/core/store/user-context/user-context.store.ts.template +14 -10
- package/src/ng-add/files/src/app/core/store/user-private/user-private.mock.ts.template +20 -7
- package/src/ng-add/files/src/app/core/store/user-private/user-private.model.ts.template +6 -6
- package/src/ng-add/files/src/app/core/store/user-private/user-private.store.ts.template +14 -10
- package/src/ng-add/files/src/app/core/testing/app-mocks.ts.template +42 -0
- package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.html.template +4 -0
- package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.scss.template +1 -0
- package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.ts.template +38 -0
- package/src/ng-add/files/src/app/first-time/consent/consent.component.html.template +2 -1
- package/src/ng-add/files/src/app/first-time/consent/consent.component.scss.template +7 -3
- package/src/ng-add/files/src/app/first-time/consent/consent.component.spec.ts.template +31 -11
- package/src/ng-add/files/src/app/first-time/consent/consent.component.ts.template +16 -1
- package/src/ng-add/files/src/app/first-time/consent/consent.guard.ts.template +5 -1
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.spec.ts.template +27 -16
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +102 -49
- package/src/ng-add/files/src/app/first-time/early-access/early-access.guard.ts.template +5 -1
- package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.html.template +2 -1
- package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.scss.template +7 -3
- package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.spec.ts.template +20 -6
- package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.ts.template +2 -0
- package/src/ng-add/files/src/app/first-time/early-access/waitlist-view/waitlist-view.component.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.html.template +18 -0
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.scss.template +2 -0
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.spec.ts.template +56 -0
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.ts.template +91 -0
- package/src/ng-add/files/src/app/first-time/first-time-routing.spec.ts.template +11 -7
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.html.template +19 -7
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.scss.template +51 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +44 -5
- package/src/ng-add/files/src/app/first-time/landing/landing.component.html.template +2 -1
- package/src/ng-add/files/src/app/first-time/landing/landing.component.scss.template +12 -8
- package/src/ng-add/files/src/app/first-time/landing/landing.component.spec.ts.template +33 -10
- package/src/ng-add/files/src/app/first-time/landing/landing.component.ts.template +6 -19
- package/src/ng-add/files/src/app/first-time/login/login.component.html.template +58 -6
- package/src/ng-add/files/src/app/first-time/login/login.component.scss.template +151 -22
- package/src/ng-add/files/src/app/first-time/login/login.component.spec.ts.template +30 -32
- package/src/ng-add/files/src/app/first-time/login/login.component.ts.template +85 -31
- package/src/ng-add/files/src/app/first-time/onboarding/onboarding.component.spec.ts.template +4 -2
- package/src/ng-add/files/src/app/first-time/onboarding/onboarding.component.ts.template +1 -1
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.html.template +12 -0
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.scss.template +39 -0
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.spec.ts.template +68 -0
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.ts.template +20 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.html.template +24 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.scss.template +50 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.spec.ts.template +65 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.ts.template +59 -0
- package/src/ng-add/files/src/app/main/account-profile/guest-deletion-dialog.component.ts.template +51 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.html.template +50 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.scss.template +137 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.spec.ts.template +57 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.ts.template +59 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.html.template +133 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.scss.template +207 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.spec.ts.template +74 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.ts.template +130 -0
- package/src/ng-add/files/src/app/main/home/home.component.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/main/home/home.component.ts.template +1 -6
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.html.template +15 -0
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.scss.template +79 -0
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.spec.ts.template +59 -0
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.ts.template +44 -0
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.html.template +45 -15
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.scss.template +103 -19
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.spec.ts.template +73 -9
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.ts.template +46 -18
- package/src/ng-add/files/src/environments/environment.prod.ts.template +1 -0
- package/src/ng-add/files/src/environments/environment.test.ts.template +1 -0
- package/src/ng-add/files/src/environments/environment.ts.template +1 -1
- package/src/ng-add/files/tsconfig.spec.json.template +3 -1
- package/src/ng-add/index.js +7 -0
- package/src/ng-add/index.js.map +1 -1
- package/src/shared/entity-registry.d.ts +8 -0
- package/src/shared/entity-registry.js +28 -0
- package/src/shared/entity-registry.js.map +1 -0
- package/tsconfig.json +2 -2
- package/.agents/skills/publish-npm/SKILL.md +0 -37
- package/.agents/skills/publish-npm/eval.yaml +0 -32
- package/.agents/skills/publish-npm/fixtures/package-v21.json.template +0 -8
- package/.husky/commit-msg +0 -1
- package/.husky/pre-commit +0 -1
- package/.t4g/agent-memory.db +0 -0
- package/src/component/index_spec.d.ts +0 -1
- package/src/component/index_spec.js +0 -68
- package/src/component/index_spec.js.map +0 -1
- package/src/entity/index_spec.d.ts +0 -1
- package/src/entity/index_spec.js +0 -153
- package/src/entity/index_spec.js.map +0 -1
- package/src/guard/index_spec.d.ts +0 -1
- package/src/guard/index_spec.js +0 -64
- package/src/guard/index_spec.js.map +0 -1
- package/src/ng-add/files/bigquery/scripts/export_entities.py.template +0 -143
- package/src/ng-add/files/bigquery/scripts/run_query.py.template +0 -167
- package/src/ng-add/files/src/app/core/firebase/cached-listeners.service.ts.template +0 -494
- package/src/ng-add/files/src/app/core/firebase/database.service.ts.template +0 -56
- package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +0 -366
- package/src/ng-add/files/src/app/core/firebase/firebase.service.ts.template +0 -342
- package/src/ng-add/files/src/app/core/firebase/simulate-load.spec.ts.template +0 -104
- package/src/ng-add/files/src/app/core/firebase/simulate-stream.spec.ts.template +0 -127
- package/src/ng-add/files/src/app/core/firebase/simulation.mock.ts.template +0 -38
- package/src/ng-add/files/src/app/core/firebase/stream-multiplexer.ts.template +0 -445
- package/src/ng-add/files/src/app/core/logging/logging.service.spec.ts.template +0 -118
- package/src/ng-add/files/src/app/core/logging/logging.service.ts.template +0 -168
- package/src/ng-add/files/src/app/core/store/app.model.ts.template +0 -21
- package/src/ng-add/files/src/app/core/store/app.store.spec.ts.template +0 -920
- package/src/ng-add/files/src/app/core/store/app.store.ts.template +0 -1317
- package/src/ng-add/files/src/app/core/store/batch-write.firebase.service.ts.template +0 -58
- package/src/ng-add/files/src/app/core/store/batch-write.mock.service.ts.template +0 -105
- package/src/ng-add/files/src/app/core/store/batch-write.service.ts.template +0 -126
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.html.template +0 -9
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.scss.template +0 -46
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.spec.ts.template +0 -69
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.ts.template +0 -39
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.spec.ts.template +0 -122
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.ts.template +0 -88
|
@@ -6,9 +6,10 @@ import {
|
|
|
6
6
|
assertSucceeds,
|
|
7
7
|
initializeTestEnvironment,
|
|
8
8
|
RulesTestEnvironment,
|
|
9
|
+
TokenOptions,
|
|
9
10
|
} from '@firebase/rules-unit-testing';
|
|
10
11
|
import { readFileSync } from 'fs';
|
|
11
|
-
import { doc, setDoc, updateDoc, getDoc, deleteDoc, collection, addDoc, query, where, getDocs } from 'firebase/firestore';
|
|
12
|
+
import { doc, setDoc, updateDoc, getDoc, deleteDoc, collection, addDoc, query, where, getDocs, writeBatch } from 'firebase/firestore';
|
|
12
13
|
|
|
13
14
|
let testEnv: RulesTestEnvironment;
|
|
14
15
|
|
|
@@ -21,6 +22,12 @@ beforeAll(async () => {
|
|
|
21
22
|
port: 8080,
|
|
22
23
|
},
|
|
23
24
|
});
|
|
25
|
+
const authenticatedContext = testEnv.authenticatedContext.bind(testEnv);
|
|
26
|
+
testEnv.authenticatedContext = (uid: string, options: TokenOptions = {}) => authenticatedContext(uid, {
|
|
27
|
+
email_verified: true,
|
|
28
|
+
firebase: { sign_in_provider: 'password' },
|
|
29
|
+
...options,
|
|
30
|
+
});
|
|
24
31
|
});
|
|
25
32
|
|
|
26
33
|
afterEach(async () => {
|
|
@@ -45,18 +52,34 @@ describe('Firestore Security Rules', () => {
|
|
|
45
52
|
|
|
46
53
|
it('should allow user to create their own profile', async () => {
|
|
47
54
|
const aliceDb = testEnv.authenticatedContext('alice').firestore();
|
|
55
|
+
await assertSucceeds(setDoc(doc(aliceDb, 'users/alice'), { name: 'Alice', isAdmin: false }));
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should allow anonymous users to provision their own profile', async () => {
|
|
59
|
+
const guestDb = testEnv.authenticatedContext('guest', {
|
|
60
|
+
email_verified: false,
|
|
61
|
+
firebase: { sign_in_provider: 'anonymous' },
|
|
62
|
+
}).firestore();
|
|
48
63
|
await assertSucceeds(
|
|
49
|
-
setDoc(doc(
|
|
64
|
+
setDoc(doc(guestDb, 'users/guest'), { name: 'Guest', isAdmin: false }),
|
|
50
65
|
);
|
|
51
66
|
});
|
|
52
67
|
|
|
53
|
-
it('should deny user from
|
|
54
|
-
const
|
|
68
|
+
it('should deny an unverified password user from provisioning a profile', async () => {
|
|
69
|
+
const unverifiedDb = testEnv.authenticatedContext('unverified', {
|
|
70
|
+
email_verified: false,
|
|
71
|
+
firebase: { sign_in_provider: 'password' },
|
|
72
|
+
}).firestore();
|
|
55
73
|
await assertFails(
|
|
56
|
-
setDoc(doc(
|
|
74
|
+
setDoc(doc(unverifiedDb, 'users/unverified'), { name: 'Unverified', isAdmin: false }),
|
|
57
75
|
);
|
|
58
76
|
});
|
|
59
77
|
|
|
78
|
+
it('should deny user from creating profile with isAdmin=true', async () => {
|
|
79
|
+
const aliceDb = testEnv.authenticatedContext('alice').firestore();
|
|
80
|
+
await assertFails(setDoc(doc(aliceDb, 'users/alice'), { name: 'Alice', isAdmin: true }));
|
|
81
|
+
});
|
|
82
|
+
|
|
60
83
|
it('should deny user from updating their own isAdmin flag', async () => {
|
|
61
84
|
await testEnv.withSecurityRulesDisabled(async (context) => {
|
|
62
85
|
await setDoc(doc(context.firestore(), 'users/alice'), { name: 'Alice', isAdmin: false });
|
|
@@ -67,18 +90,30 @@ describe('Firestore Security Rules', () => {
|
|
|
67
90
|
|
|
68
91
|
it('should deny user from modifying adminOverridePaths', async () => {
|
|
69
92
|
await testEnv.withSecurityRulesDisabled(async (context) => {
|
|
70
|
-
await setDoc(doc(context.firestore(), 'users/alice'), {
|
|
93
|
+
await setDoc(doc(context.firestore(), 'users/alice'), {
|
|
94
|
+
name: 'Alice',
|
|
95
|
+
adminOverridePaths: [],
|
|
96
|
+
});
|
|
71
97
|
});
|
|
72
98
|
const aliceDb = testEnv.authenticatedContext('alice').firestore();
|
|
73
|
-
await assertFails(
|
|
99
|
+
await assertFails(
|
|
100
|
+
updateDoc(doc(aliceDb, 'users/alice'), { adminOverridePaths: ['some/path'] }),
|
|
101
|
+
);
|
|
74
102
|
});
|
|
75
103
|
|
|
76
104
|
it('should allow user to transition accessState from 01 to 02 and set joinedWaitlistAt', async () => {
|
|
77
105
|
await testEnv.withSecurityRulesDisabled(async (context) => {
|
|
78
|
-
await setDoc(doc(context.firestore(), 'users/alice'), {
|
|
106
|
+
await setDoc(doc(context.firestore(), 'users/alice'), {
|
|
107
|
+
accessState: '01 - submit interest',
|
|
108
|
+
});
|
|
79
109
|
});
|
|
80
110
|
const aliceDb = testEnv.authenticatedContext('alice').firestore();
|
|
81
|
-
await assertSucceeds(
|
|
111
|
+
await assertSucceeds(
|
|
112
|
+
updateDoc(doc(aliceDb, 'users/alice'), {
|
|
113
|
+
accessState: '02 - waiting',
|
|
114
|
+
joinedWaitlistAt: 123456789,
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
82
117
|
});
|
|
83
118
|
|
|
84
119
|
it('should deny user from transitioning accessState from 02 to 03', async () => {
|
|
@@ -108,7 +143,10 @@ describe('Firestore Security Rules', () => {
|
|
|
108
143
|
|
|
109
144
|
it('should deny user from modifying joinedWaitlistAt after it is set', async () => {
|
|
110
145
|
await testEnv.withSecurityRulesDisabled(async (context) => {
|
|
111
|
-
await setDoc(doc(context.firestore(), 'users/alice'), {
|
|
146
|
+
await setDoc(doc(context.firestore(), 'users/alice'), {
|
|
147
|
+
accessState: '02 - waiting',
|
|
148
|
+
joinedWaitlistAt: 123,
|
|
149
|
+
});
|
|
112
150
|
});
|
|
113
151
|
const aliceDb = testEnv.authenticatedContext('alice').firestore();
|
|
114
152
|
await assertFails(updateDoc(doc(aliceDb, 'users/alice'), { joinedWaitlistAt: 456 }));
|
|
@@ -151,12 +189,45 @@ describe('Firestore Security Rules', () => {
|
|
|
151
189
|
});
|
|
152
190
|
|
|
153
191
|
describe('UserContexts Collection', () => {
|
|
192
|
+
it('should allow the no-waitlist interest submission as one atomic batch', async () => {
|
|
193
|
+
await testEnv.withSecurityRulesDisabled(async (context) => {
|
|
194
|
+
await setDoc(doc(context.firestore(), 'users/alice'), {
|
|
195
|
+
accessState: '01 - submit interest',
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
const aliceDb = testEnv.authenticatedContext('alice').firestore();
|
|
199
|
+
const batch = writeBatch(aliceDb);
|
|
200
|
+
batch.update(doc(aliceDb, 'users/alice'), {
|
|
201
|
+
accessState: '03 - consent',
|
|
202
|
+
joinedWaitlistAt: 123456789,
|
|
203
|
+
});
|
|
204
|
+
batch.set(doc(aliceDb, 'userContexts/context-alice'), {
|
|
205
|
+
__userId: 'alice',
|
|
206
|
+
questionOne: 'Example context',
|
|
207
|
+
questionTwo: 'Example needs',
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
await assertSucceeds(batch.commit());
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('should deny unverified non-anonymous users from app data', async () => {
|
|
214
|
+
const unverifiedDb = testEnv.authenticatedContext('unverified', {
|
|
215
|
+
email_verified: false,
|
|
216
|
+
firebase: { sign_in_provider: 'password' },
|
|
217
|
+
}).firestore();
|
|
218
|
+
await assertFails(
|
|
219
|
+
setDoc(doc(unverifiedDb, 'userContexts/context-unverified'), {
|
|
220
|
+
__userId: 'unverified',
|
|
221
|
+
}),
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
|
|
154
225
|
it('should allow user to create their own context', async () => {
|
|
155
226
|
const aliceDb = testEnv.authenticatedContext('alice').firestore();
|
|
156
227
|
await assertSucceeds(
|
|
157
228
|
setDoc(doc(aliceDb, 'userContexts/ctx1'), {
|
|
158
229
|
__userId: 'alice',
|
|
159
|
-
})
|
|
230
|
+
}),
|
|
160
231
|
);
|
|
161
232
|
});
|
|
162
233
|
|
|
@@ -165,7 +236,7 @@ describe('Firestore Security Rules', () => {
|
|
|
165
236
|
await assertFails(
|
|
166
237
|
setDoc(doc(aliceDb, 'userContexts/ctx1'), {
|
|
167
238
|
__userId: 'bob',
|
|
168
|
-
})
|
|
239
|
+
}),
|
|
169
240
|
);
|
|
170
241
|
});
|
|
171
242
|
|
|
@@ -199,9 +270,7 @@ describe('Firestore Security Rules', () => {
|
|
|
199
270
|
await setDoc(doc(context.firestore(), 'userContexts/ctx1'), { __userId: 'alice' });
|
|
200
271
|
});
|
|
201
272
|
const aliceDb = testEnv.authenticatedContext('alice').firestore();
|
|
202
|
-
await assertFails(
|
|
203
|
-
updateDoc(doc(aliceDb, 'userContexts/ctx1'), { __userId: 'bob' })
|
|
204
|
-
);
|
|
273
|
+
await assertFails(updateDoc(doc(aliceDb, 'userContexts/ctx1'), { __userId: 'bob' }));
|
|
205
274
|
});
|
|
206
275
|
|
|
207
276
|
it('should allow user to delete their own context', async () => {
|
|
@@ -3,7 +3,16 @@ service cloud.firestore {
|
|
|
3
3
|
match /databases/{database}/documents {
|
|
4
4
|
|
|
5
5
|
function isAdmin() {
|
|
6
|
-
return
|
|
6
|
+
return exists(/databases/$(database)/documents/users/$(request.auth.uid)) &&
|
|
7
|
+
get(/databases/$(database)/documents/users/$(request.auth.uid)).data.isAdmin == true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function isVerifiedOrAnonymous() {
|
|
11
|
+
return request.auth != null && (
|
|
12
|
+
request.auth.token.firebase.sign_in_provider == 'anonymous' ||
|
|
13
|
+
request.auth.token.firebase.sign_in_provider == 'google.com' ||
|
|
14
|
+
('email_verified' in request.auth.token && request.auth.token.email_verified == true)
|
|
15
|
+
);
|
|
7
16
|
}
|
|
8
17
|
|
|
9
18
|
// ─── Users ───────────────────────────────────────────────────────────
|
|
@@ -12,40 +21,43 @@ service cloud.firestore {
|
|
|
12
21
|
// Update: only the user themselves or admins. Regular users are restricted from modifying state bypasses or sensitive lists.
|
|
13
22
|
// Delete: only the user themselves or admins.
|
|
14
23
|
match /users/{userId} {
|
|
15
|
-
allow create: if
|
|
24
|
+
allow create: if isVerifiedOrAnonymous()
|
|
16
25
|
&& request.auth.uid == userId
|
|
17
26
|
&& (!('isAdmin' in request.resource.data) || request.resource.data.isAdmin == false || isAdmin());
|
|
18
|
-
allow read: if
|
|
19
|
-
allow update: if
|
|
27
|
+
allow read: if isVerifiedOrAnonymous();
|
|
28
|
+
allow update: if isVerifiedOrAnonymous()
|
|
20
29
|
&& (isAdmin() || (
|
|
21
30
|
request.auth.uid == userId
|
|
22
31
|
// Cannot grant themselves admin privileges
|
|
23
|
-
&& (!('isAdmin' in request.resource.data) || request.resource.data.isAdmin == resource.data.isAdmin)
|
|
32
|
+
&& (!('isAdmin' in request.resource.data) || !('isAdmin' in resource.data) || request.resource.data.isAdmin == resource.data.isAdmin)
|
|
24
33
|
// Cannot alter adminOverridePaths
|
|
25
|
-
&& (!('adminOverridePaths' in request.resource.data) || request.resource.data.adminOverridePaths == resource.data.adminOverridePaths)
|
|
34
|
+
&& (!('adminOverridePaths' in request.resource.data) || !('adminOverridePaths' in resource.data) || request.resource.data.adminOverridePaths == resource.data.adminOverridePaths)
|
|
26
35
|
// Must follow accessState transitions if changing accessState
|
|
27
36
|
&& (!('accessState' in request.resource.data)
|
|
37
|
+
|| !('accessState' in resource.data)
|
|
28
38
|
|| request.resource.data.accessState == resource.data.accessState
|
|
29
39
|
|| (resource.data.accessState == '01 - submit interest' && request.resource.data.accessState == '02 - waiting')
|
|
40
|
+
|| (resource.data.accessState == '01 - submit interest' && request.resource.data.accessState == '03 - consent')
|
|
30
41
|
|| (resource.data.accessState == '03 - consent' && request.resource.data.accessState == 'done')
|
|
31
42
|
)
|
|
32
|
-
// Cannot modify joinedWaitlistAt unless transitioning
|
|
43
|
+
// Cannot modify joinedWaitlistAt unless transitioning from submit interest
|
|
33
44
|
&& (!('joinedWaitlistAt' in request.resource.data)
|
|
45
|
+
|| !('joinedWaitlistAt' in resource.data)
|
|
34
46
|
|| request.resource.data.joinedWaitlistAt == resource.data.joinedWaitlistAt
|
|
35
|
-
|| (resource.data.accessState == '01 - submit interest' && request.resource.data.accessState == '02 - waiting')
|
|
47
|
+
|| (resource.data.accessState == '01 - submit interest' && (request.resource.data.accessState == '02 - waiting' || request.resource.data.accessState == '03 - consent'))
|
|
36
48
|
)
|
|
37
49
|
));
|
|
38
|
-
allow delete: if
|
|
50
|
+
allow delete: if isVerifiedOrAnonymous()
|
|
39
51
|
&& (request.auth.uid == userId || isAdmin());
|
|
40
52
|
}
|
|
41
53
|
|
|
42
54
|
// ─── User Privates ───────────────────────────────────────────────────
|
|
43
55
|
// Create/Read/Update/Delete: only the user themselves (document ID == auth.uid) or admins
|
|
44
56
|
match /userPrivates/{userId} {
|
|
45
|
-
allow create: if
|
|
46
|
-
allow read: if
|
|
47
|
-
allow update: if
|
|
48
|
-
allow delete: if
|
|
57
|
+
allow create: if isVerifiedOrAnonymous() && request.auth.uid == userId;
|
|
58
|
+
allow read: if isVerifiedOrAnonymous() && (request.auth.uid == userId || isAdmin());
|
|
59
|
+
allow update: if isVerifiedOrAnonymous() && (request.auth.uid == userId || isAdmin());
|
|
60
|
+
allow delete: if isVerifiedOrAnonymous() && (request.auth.uid == userId || isAdmin());
|
|
49
61
|
}
|
|
50
62
|
|
|
51
63
|
// ─── User Contexts ───────────────────────────────────────────────────
|
|
@@ -54,17 +66,17 @@ service cloud.firestore {
|
|
|
54
66
|
// Update: only the user themselves or admins. Prevent transferring context.
|
|
55
67
|
// Delete: only the user themselves or admins
|
|
56
68
|
match /userContexts/{contextId} {
|
|
57
|
-
allow create: if
|
|
69
|
+
allow create: if isVerifiedOrAnonymous()
|
|
58
70
|
&& request.resource.data.__userId == request.auth.uid;
|
|
59
|
-
allow read: if
|
|
71
|
+
allow read: if isVerifiedOrAnonymous()
|
|
60
72
|
&& (resource.data.__userId == request.auth.uid || isAdmin());
|
|
61
|
-
allow update: if
|
|
73
|
+
allow update: if isVerifiedOrAnonymous()
|
|
62
74
|
&& (isAdmin() || (
|
|
63
75
|
resource.data.__userId == request.auth.uid
|
|
64
76
|
// Prevent users from transferring their userContext to another user
|
|
65
77
|
&& (!('__userId' in request.resource.data) || request.resource.data.__userId == resource.data.__userId)
|
|
66
78
|
));
|
|
67
|
-
allow delete: if
|
|
79
|
+
allow delete: if isVerifiedOrAnonymous()
|
|
68
80
|
&& (resource.data.__userId == request.auth.uid || isAdmin());
|
|
69
81
|
}
|
|
70
82
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "<%= dasherize(project) %>-functions",
|
|
3
|
+
"private": true,
|
|
4
|
+
"main": "lib/index.js",
|
|
5
|
+
"engines": { "node": "22" },
|
|
6
|
+
"scripts": { "build": "tsc", "test": "npm run build" },
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@tech4good/platform-email": "0.1.0-alpha.0",
|
|
9
|
+
"firebase-admin": "^13.10.0",
|
|
10
|
+
"firebase-functions": "^7.3.0"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": { "typescript": "~5.8.3" }
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineSecret } from 'firebase-functions/params';
|
|
2
|
+
import { createResendEmailSender, type EmailSender } from '@tech4good/platform-email';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Firebase Secret Manager binding for the Resend API key.
|
|
6
|
+
* Attach `secrets: [resendApiKey]` to any Cloud Function that sends email.
|
|
7
|
+
*/
|
|
8
|
+
export const resendApiKey = defineSecret('RESEND_API_KEY');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates a server-side Resend email sender configured for <%= classify(project) %>.
|
|
12
|
+
*
|
|
13
|
+
* Defaults to safe dry-run logging when `RESEND_API_KEY` is unset (such as in local emulators).
|
|
14
|
+
* Override `EMAIL_FROM` and `EMAIL_REPLY_TO` in `functions/.env.<project-id>`.
|
|
15
|
+
*/
|
|
16
|
+
export function createAppEmailSender(): EmailSender {
|
|
17
|
+
return createResendEmailSender({
|
|
18
|
+
apiKey: resendApiKey.value(),
|
|
19
|
+
defaultFrom: process.env['EMAIL_FROM'] || '<%= classify(project) %> <notifications@mail.tech4good.dev>',
|
|
20
|
+
defaultReplyTo: process.env['EMAIL_REPLY_TO'],
|
|
21
|
+
allowDryRunWhenUnconfigured: true,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { initializeApp } from 'firebase-admin/app';
|
|
2
|
+
import { getAuth } from 'firebase-admin/auth';
|
|
3
|
+
import { getFirestore } from 'firebase-admin/firestore';
|
|
4
|
+
import { HttpsError, onCall } from 'firebase-functions/v2/https';
|
|
5
|
+
|
|
6
|
+
initializeApp();
|
|
7
|
+
|
|
8
|
+
// Add application-owned collections keyed by __userId when the project introduces them.
|
|
9
|
+
const QUERY_COLLECTIONS = ['userContexts'] as const;
|
|
10
|
+
|
|
11
|
+
async function deleteQueryInBatches(collectionName: typeof QUERY_COLLECTIONS[number], uid: string): Promise<void> {
|
|
12
|
+
const firestore = getFirestore();
|
|
13
|
+
const snapshot = await firestore.collection(collectionName).where('__userId', '==', uid).get();
|
|
14
|
+
for (let start = 0; start < snapshot.docs.length; start += 450) {
|
|
15
|
+
const batch = firestore.batch();
|
|
16
|
+
snapshot.docs.slice(start, start + 450).forEach((document) => batch.delete(document.ref));
|
|
17
|
+
await batch.commit();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Permanently removes an anonymous account and its currently-owned application data. */
|
|
22
|
+
export const deleteAnonymousAccount = onCall(async (request) => {
|
|
23
|
+
if (!request.auth || request.auth.token.firebase?.sign_in_provider !== 'anonymous') {
|
|
24
|
+
throw new HttpsError('permission-denied', 'Only an anonymous account can delete itself here.');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const uid = request.auth.uid;
|
|
28
|
+
const firestore = getFirestore();
|
|
29
|
+
for (const collectionName of QUERY_COLLECTIONS) await deleteQueryInBatches(collectionName, uid);
|
|
30
|
+
|
|
31
|
+
const batch = firestore.batch();
|
|
32
|
+
[
|
|
33
|
+
firestore.doc(`users/${uid}`),
|
|
34
|
+
firestore.doc(`userPrivates/${uid}`),
|
|
35
|
+
].forEach((reference) => batch.delete(reference));
|
|
36
|
+
await batch.commit();
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
await getAuth().deleteUser(uid);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if ((error as { code?: string }).code !== 'auth/user-not-found') throw error;
|
|
42
|
+
}
|
|
43
|
+
return { deleted: true };
|
|
44
|
+
});
|
|
@@ -45,7 +45,7 @@ const config: Config = {
|
|
|
45
45
|
],
|
|
46
46
|
},
|
|
47
47
|
transformIgnorePatterns: [
|
|
48
|
-
'node_modules/(?!.*\\.mjs$|@angular|@ngrx|rxjs|crypto-es)',
|
|
48
|
+
'node_modules/(?!.*\\.mjs$|@angular|@ngrx|rxjs|crypto-es|vega-embed|vega|vega-lite|json-stringify-pretty-compact|d3-.*)',
|
|
49
49
|
],
|
|
50
50
|
moduleNameMapper: {
|
|
51
51
|
'^src/(.*)$': '<rootDir>/src/$1',
|
|
@@ -59,6 +59,7 @@ const config: Config = {
|
|
|
59
59
|
testPathIgnorePatterns: [
|
|
60
60
|
'/node_modules/',
|
|
61
61
|
'/dist/',
|
|
62
|
+
'<rootDir>/analytics/',
|
|
62
63
|
'<rootDir>/src/environments/environment.test.ts',
|
|
63
64
|
...(process.env['JEST_RULES'] ? [] : ['<rootDir>/firestore.rules.spec.ts', '<rootDir>/firestore.logs.rules.spec.ts'])
|
|
64
65
|
],
|
|
@@ -78,4 +79,4 @@ const config: Config = {
|
|
|
78
79
|
},
|
|
79
80
|
};
|
|
80
81
|
|
|
81
|
-
export default config;
|
|
82
|
+
export default config;
|
|
@@ -4,23 +4,40 @@
|
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"ng": "ng",
|
|
7
|
-
"start": "ng serve",
|
|
8
|
-
"build": "ng build",
|
|
9
|
-
"watch": "ng build --watch --configuration development",
|
|
10
|
-
"test": "jest",
|
|
11
|
-
"test:watch": "jest --watch",
|
|
12
|
-
"test:coverage": "jest --coverage",
|
|
7
|
+
"start": "t4g-entities --watch -- ng serve",
|
|
8
|
+
"build": "t4g-entities && ng build",
|
|
9
|
+
"watch": "t4g-entities --watch -- ng build --watch --configuration development",
|
|
10
|
+
"test": "t4g-entities && jest",
|
|
11
|
+
"test:watch": "t4g-entities --watch -- jest --watch",
|
|
12
|
+
"test:coverage": "t4g-entities && jest --coverage",
|
|
13
13
|
"test:rules": "firebase emulators:exec --only firestore 'JEST_RULES=1 jest firestore.rules.spec.ts firestore.logs.rules.spec.ts'",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"deploy:
|
|
14
|
+
"check:indexes": "t4g-check-firestore-indexes",
|
|
15
|
+
"fix:indexes": "t4g-check-firestore-indexes --fix",
|
|
16
|
+
"lint": "t4g-entities && ng lint <%= dasherize(project) %> && ng lint analytics",
|
|
17
|
+
"lintfix": "ng lint <%= dasherize(project) %> --fix && ng lint analytics --fix",
|
|
18
|
+
"code-check": "t4g-entities && ngc --noEmit && sass src:dist/css-check --no-source-map && rm -rf dist/css-check && npm run lintfix",
|
|
19
|
+
"analyze": "t4g-entities && ng build --stats-json && esbuild-visualizer --metadata dist/<%= dasherize(project) %>/stats.json --filename dist/<%= dasherize(project) %>/bundle-analysis.html && open dist/<%= dasherize(project) %>/bundle-analysis.html",
|
|
20
|
+
"deploy:dev": "t4g-entities && npm --prefix functions run build && ng build --configuration development && firebase deploy --project dev",
|
|
21
|
+
"deploy:prod": "t4g-entities && npm --prefix functions run build && ng build --configuration production && firebase deploy --project prod",
|
|
22
|
+
"deploy:functions:dev": "npm --prefix functions run build && firebase deploy --only functions --project dev",
|
|
23
|
+
"deploy:functions:prod": "npm --prefix functions run build && firebase deploy --only functions --project prod",
|
|
24
|
+
"deploy:logs": "firebase deploy --only firestore:rules --project log --config firebase.logs.json",
|
|
25
|
+
"bigquery:init": "node bigquery/scripts/init_views.js",
|
|
26
|
+
"analytics": "node analytics/scripts/start.js",
|
|
27
|
+
"analytics:serve": "ng serve analytics --host 127.0.0.1 --port 4320 --proxy-config analytics/proxy.conf.json",
|
|
28
|
+
"analytics:server": "node analytics/server/server.js",
|
|
29
|
+
"analytics:refresh": "node analytics/scripts/refresh_snapshot.js",
|
|
30
|
+
"analytics:build": "ng build analytics",
|
|
31
|
+
"analytics:test": "node --test analytics/*.test.js analytics/**/*.test.js",
|
|
32
|
+
"generate:entities": "t4g-entities",
|
|
33
|
+
"check:entities": "t4g-entities --check"
|
|
21
34
|
},
|
|
22
35
|
"private": true,
|
|
23
36
|
"dependencies": {
|
|
37
|
+
"@tech4good/platform-auth": "0.1.0-alpha.0",
|
|
38
|
+
"@tech4good/platform-data": "0.1.0-alpha.0",
|
|
39
|
+
"@tech4good/platform-logging": "0.1.0-alpha.0",
|
|
40
|
+
"@tech4good/platform-ui": "0.1.0-alpha.0",
|
|
24
41
|
"@angular/animations": "^21.2.15",
|
|
25
42
|
"@angular/cdk": "^21.2.13",
|
|
26
43
|
"@angular/common": "^21.2.15",
|
|
@@ -42,7 +59,10 @@
|
|
|
42
59
|
"globalthis": "^1.0.4",
|
|
43
60
|
"proxy-polyfill": "^0.3.2",
|
|
44
61
|
"rxjs": "~7.8.0",
|
|
45
|
-
"tslib": "^2.3.0"
|
|
62
|
+
"tslib": "^2.3.0",
|
|
63
|
+
"vega": "^6.1.2",
|
|
64
|
+
"vega-embed": "^7.1.0",
|
|
65
|
+
"vega-lite": "^6.4.2"
|
|
46
66
|
},
|
|
47
67
|
"devDependencies": {
|
|
48
68
|
"@angular-eslint/builder": "^21.4.0",
|
|
@@ -54,9 +74,13 @@
|
|
|
54
74
|
"@angular/cli": "^21.2.13",
|
|
55
75
|
"@angular/compiler-cli": "^21.2.15",
|
|
56
76
|
"@firebase/rules-unit-testing": "^5.0.1",
|
|
77
|
+
"@google-cloud/bigquery": "^8.3.1",
|
|
78
|
+
"@google-cloud/firestore": "^8.6.0",
|
|
79
|
+
"firebase-admin": "^14.2.0",
|
|
57
80
|
"firebase-tools": "^14.27.0",
|
|
58
81
|
"@ngx-env/builder": "^21.0.1",
|
|
59
|
-
"@tech4good/angular-schematics": "
|
|
82
|
+
"@tech4good/angular-schematics": "^<%= schematicsVersion %>",
|
|
83
|
+
"@tech4good/platform-tooling": "0.1.0-alpha.2",
|
|
60
84
|
"@types/estree": "^1.0.0",
|
|
61
85
|
"@types/jest": "^30.0.0",
|
|
62
86
|
"@types/node": "^18.19.47",
|
|
@@ -76,7 +100,8 @@
|
|
|
76
100
|
"whatwg-fetch": "^3.6.20",
|
|
77
101
|
"ts-jest": "^29.3.4",
|
|
78
102
|
"ts-jest-mock-import-meta": "^1.3.0",
|
|
79
|
-
"ts-node": "^10.9.2"
|
|
103
|
+
"ts-node": "^10.9.2",
|
|
104
|
+
"sqlite3": "^6.0.1"
|
|
80
105
|
},
|
|
81
106
|
"overrides": {
|
|
82
107
|
"firebase": "$firebase",
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data access layer for the analytics dashboard UI.
|
|
3
|
+
* Fetches dataset rows and status health checks from the local Express backend.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { HttpClient } from '@angular/common/http';
|
|
7
|
+
import { Injectable, computed, inject, signal } from '@angular/core';
|
|
8
|
+
import { BehaviorSubject, Observable, catchError, of, tap, timer } from 'rxjs';
|
|
9
|
+
import { switchMap } from 'rxjs/operators';
|
|
10
|
+
|
|
11
|
+
/** Metadata describing the overall database snapshot */
|
|
12
|
+
export interface SnapshotMetadata {
|
|
13
|
+
snapshot_id: string;
|
|
14
|
+
created_at: string;
|
|
15
|
+
source_project: string;
|
|
16
|
+
git_sha: string;
|
|
17
|
+
schema_version: number;
|
|
18
|
+
query_bundle_hash: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Metadata describing an individual dataset within a snapshot */
|
|
22
|
+
export interface DatasetMetadata {
|
|
23
|
+
dataset_id: string;
|
|
24
|
+
source_query: string;
|
|
25
|
+
query_hash: string;
|
|
26
|
+
grain: string;
|
|
27
|
+
privacy: string;
|
|
28
|
+
row_count: number;
|
|
29
|
+
refresh_duration_ms: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Overall status response returned by `/api/status` */
|
|
33
|
+
export interface AnalyticsStatus {
|
|
34
|
+
available: boolean;
|
|
35
|
+
message?: string;
|
|
36
|
+
snapshot?: SnapshotMetadata;
|
|
37
|
+
datasets: DatasetMetadata[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Response payload returned by `/api/datasets/:id` */
|
|
41
|
+
export interface DatasetResponse {
|
|
42
|
+
datasetId: string;
|
|
43
|
+
snapshotId: string;
|
|
44
|
+
grain: string;
|
|
45
|
+
privacy: string;
|
|
46
|
+
rows: Array<Record<string, unknown>>;
|
|
47
|
+
totalRows: number;
|
|
48
|
+
limit: number;
|
|
49
|
+
offset: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Injectable({ providedIn: 'root' })
|
|
53
|
+
export class AnalyticsApiService {
|
|
54
|
+
private readonly http = inject(HttpClient);
|
|
55
|
+
readonly reloadSubject = new BehaviorSubject<void>(undefined);
|
|
56
|
+
|
|
57
|
+
/** Latest status response received from the local server. */
|
|
58
|
+
readonly serverStatus = signal<AnalyticsStatus | null>(null);
|
|
59
|
+
|
|
60
|
+
/** Snapshot ID currently loaded and rendered by the dashboard UI. */
|
|
61
|
+
readonly loadedSnapshotId = signal<string | null>(null);
|
|
62
|
+
|
|
63
|
+
/** Reactive signal controlling whether admin/developer traffic is included in analytics queries */
|
|
64
|
+
readonly includeAdmin = signal<boolean>(false);
|
|
65
|
+
|
|
66
|
+
/** Toggles admin traffic inclusion on/off and triggers a dashboard data reload */
|
|
67
|
+
toggleIncludeAdmin(): void {
|
|
68
|
+
this.includeAdmin.update((value) => !value);
|
|
69
|
+
this.reloadSubject.next();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Evaluates to true when the server has a newer snapshot pointer than what is currently rendered. */
|
|
73
|
+
readonly hasNewSnapshot = computed(() => {
|
|
74
|
+
const serverId = this.serverStatus()?.snapshot?.snapshot_id;
|
|
75
|
+
const loadedId = this.loadedSnapshotId();
|
|
76
|
+
return !!serverId && !!loadedId && serverId !== loadedId;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
constructor() {
|
|
80
|
+
// Poll for background snapshot refreshes
|
|
81
|
+
timer(0, 15000)
|
|
82
|
+
.pipe(
|
|
83
|
+
switchMap(() => this.status().pipe(catchError(() => of(null)))),
|
|
84
|
+
)
|
|
85
|
+
.subscribe((status) => {
|
|
86
|
+
if (status) {
|
|
87
|
+
this.serverStatus.set(status);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Fetches status metadata from `/api/status` */
|
|
93
|
+
status(): Observable<AnalyticsStatus> {
|
|
94
|
+
return this.http.get<AnalyticsStatus>('/api/status').pipe(
|
|
95
|
+
tap((status) => {
|
|
96
|
+
if (status.available) {
|
|
97
|
+
this.serverStatus.set(status);
|
|
98
|
+
}
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Fetches dataset rows and pagination metrics from `/api/datasets/:id`.
|
|
105
|
+
* Automatically appends the current `includeAdmin` toggle state as a query
|
|
106
|
+
* parameter so the server returns the appropriate traffic variant.
|
|
107
|
+
*/
|
|
108
|
+
dataset(id: string): Observable<DatasetResponse> {
|
|
109
|
+
const includeAdmin = this.includeAdmin() ? '1' : '0';
|
|
110
|
+
return this.http.get<DatasetResponse>(
|
|
111
|
+
`/api/datasets/${encodeURIComponent(id)}?includeAdmin=${includeAdmin}`,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Marks a snapshot ID as rendered in the current view */
|
|
116
|
+
markLoaded(snapshotId?: string): void {
|
|
117
|
+
if (snapshotId) {
|
|
118
|
+
this.loadedSnapshotId.set(snapshotId);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Triggers a dashboard data reload when a new snapshot is detected */
|
|
123
|
+
reload(): void {
|
|
124
|
+
const serverId = this.serverStatus()?.snapshot?.snapshot_id;
|
|
125
|
+
if (serverId) {
|
|
126
|
+
this.loadedSnapshotId.set(serverId);
|
|
127
|
+
}
|
|
128
|
+
this.reloadSubject.next();
|
|
129
|
+
}
|
|
130
|
+
}
|