@tech4good/angular-schematics 21.6.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 +28 -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 +14 -6
- package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +12 -6
- package/src/entity/files/__name@dasherize__/__name@dasherize__.store.ts.template +18 -10
- package/src/entity/index.js +4 -49
- package/src/entity/index.js.map +1 -1
- 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 +3 -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 +54 -24
- 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 +108 -29
- 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/functions/package.json.template +1 -0
- package/src/ng-add/files/functions/src/email.ts.template +23 -0
- package/src/ng-add/files/jest.config.ts.template +3 -2
- package/src/ng-add/files/package.json.template +39 -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.spec.ts.template +4 -5
- 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 +1 -1
- 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 +1 -2
- package/src/ng-add/files/src/app/app.config.ts.template +21 -15
- package/src/ng-add/files/src/app/auth-routing.spec.ts.template +4 -5
- 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 +9 -23
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.spec.ts.template +3 -14
- 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 +19 -67
- package/src/ng-add/files/src/app/core/store/auth/auth.store.spec.ts.template +102 -12
- package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +32 -237
- package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +17 -12
- package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +6 -7
- 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 +5 -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/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/early-access/early-access.component.spec.ts.template +15 -15
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +11 -3
- 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.spec.ts.template +17 -1
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.ts.template +15 -0
- package/src/ng-add/files/src/app/first-time/first-time-routing.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +15 -0
- package/src/ng-add/files/src/app/first-time/landing/landing.component.spec.ts.template +2 -0
- package/src/ng-add/files/src/app/first-time/login/login.component.spec.ts.template +21 -3
- package/src/ng-add/files/src/app/first-time/login/login.component.ts.template +26 -0
- 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.spec.ts.template +2 -2
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.spec.ts.template +2 -2
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.spec.ts.template +4 -4
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.spec.ts.template +2 -2
- 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 -1
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.spec.ts.template +4 -4
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.spec.ts.template +2 -2
- 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/.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 -500
- package/src/ng-add/files/src/app/core/firebase/database.service.ts.template +0 -73
- package/src/ng-add/files/src/app/core/firebase/email-link-context.service.spec.ts.template +0 -59
- package/src/ng-add/files/src/app/core/firebase/email-link-context.service.ts.template +0 -147
- package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +0 -453
- package/src/ng-add/files/src/app/core/firebase/firebase.service.spec.ts.template +0 -116
- package/src/ng-add/files/src/app/core/firebase/firebase.service.ts.template +0 -639
- 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 -1320
- 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
- package/src/ng-add/index_spec.d.ts +0 -1
- package/src/ng-add/index_spec.js +0 -108
- package/src/ng-add/index_spec.js.map +0 -1
|
@@ -1,256 +1,51 @@
|
|
|
1
1
|
import { Injector, computed, inject } from '@angular/core';
|
|
2
|
-
import { signalStore,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { AuthSession, DATABASE_SERVICE } from '../../firebase/database.service';
|
|
6
|
-
import { CachedListenersService } from '../../firebase/cached-listeners.service';
|
|
7
|
-
import { EMPTY, of, pipe, from, firstValueFrom } from 'rxjs';
|
|
8
|
-
import { tap, catchError, switchMap } from 'rxjs/operators';
|
|
2
|
+
import { signalStore, withMethods, withComputed } from '@ngrx/signals';
|
|
3
|
+
import { withAuthSession } from '@tech4good/platform-auth';
|
|
4
|
+
import { firstValueFrom } from 'rxjs';
|
|
9
5
|
import { Router } from '@angular/router';
|
|
10
6
|
import { MatDialog } from '@angular/material/dialog';
|
|
11
7
|
import { UserStore } from '../user/user.store';
|
|
12
|
-
import { UserContextStore } from '../user-context/user-context.store';
|
|
13
8
|
import { GuestDeletionDialogComponent } from 'src/app/main/account-profile/guest-deletion-dialog.component';
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
afUser: AuthSession | null;
|
|
17
|
-
isLoadingLogin: boolean;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const initialState: State = {
|
|
21
|
-
afUser: null,
|
|
22
|
-
isLoadingLogin: false,
|
|
23
|
-
};
|
|
24
|
-
|
|
10
|
+
/** Shared auth mechanics, with this app's user selector, dialog and navigation. */
|
|
25
11
|
export const AuthStore = signalStore(
|
|
26
12
|
{ providedIn: 'root' },
|
|
27
|
-
|
|
13
|
+
withAuthSession(),
|
|
28
14
|
withComputed((store, userStore = inject(UserStore)) => ({
|
|
29
15
|
user: computed(() => {
|
|
30
16
|
const afUser = store.afUser();
|
|
31
|
-
if (!afUser) return null;
|
|
17
|
+
if (!afUser || store.authStatus() !== 'ready') return null;
|
|
32
18
|
return userStore.selectEntity(afUser.uid) || null;
|
|
33
19
|
}),
|
|
34
20
|
})),
|
|
35
|
-
withMethods(
|
|
36
|
-
(
|
|
37
|
-
store
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* loads it into the UserStore, and starts a real-time stream for updates.
|
|
50
|
-
*
|
|
51
|
-
* This is extracted as a shared helper so that both direct login methods
|
|
52
|
-
* (loginAnonymously, signInWithGoogle, etc.) and the reactive loadAuth
|
|
53
|
-
* pipeline can reuse the same logic without duplication.
|
|
54
|
-
*/
|
|
55
|
-
async function provisionAndLoadUser(session: AuthSession): Promise<void> {
|
|
56
|
-
await db.ensureUserProfile(session);
|
|
57
|
-
await userStore.load([['__id', '==', session.uid]], {});
|
|
58
|
-
userStore.stream([['__id', '==', session.uid]], {}, injector);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function trackRefreshProvisioning(session: AuthSession): Promise<void> {
|
|
62
|
-
const provisioning = provisionAndLoadUser(session);
|
|
63
|
-
refreshProvisioning.add(provisioning);
|
|
64
|
-
void provisioning.then(
|
|
65
|
-
() => refreshProvisioning.delete(provisioning),
|
|
66
|
-
() => refreshProvisioning.delete(provisioning),
|
|
67
|
-
);
|
|
68
|
-
return provisioning;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async function awaitRefreshProvisioning(): Promise<void> {
|
|
72
|
-
while (refreshProvisioning.size) {
|
|
73
|
-
await Promise.allSettled([...refreshProvisioning]);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
loadAuth: rxMethod<void>(
|
|
79
|
-
pipe(
|
|
80
|
-
// 1. Listen for changes in the authenticated Firebase user.
|
|
81
|
-
// This emits immediately if a user is already signed in (from local cache/cookie),
|
|
82
|
-
// or emits whenever they log in or out.
|
|
83
|
-
switchMap(() =>
|
|
84
|
-
db.afUser().pipe(
|
|
85
|
-
catchError((e) => {
|
|
86
|
-
console.error(e);
|
|
87
|
-
return EMPTY;
|
|
88
|
-
}),
|
|
89
|
-
),
|
|
90
|
-
),
|
|
91
|
-
|
|
92
|
-
// 2. Provision a single profile for each new Firebase UID, then load it.
|
|
93
|
-
//
|
|
94
|
-
// IMPORTANT: This reactive path primarily handles page refresh and
|
|
95
|
-
// re-authentication scenarios where the user is already authenticated
|
|
96
|
-
// from cache. During page refresh, both Firebase Auth and Firestore are
|
|
97
|
-
// initialized from IndexedDB simultaneously, so the auth token is
|
|
98
|
-
// guaranteed to be available when Firestore operations run.
|
|
99
|
-
//
|
|
100
|
-
// For fresh logins (loginAnonymously, signInWithGoogle, etc.), the login
|
|
101
|
-
// methods provision directly after Firebase has completed the sign-in.
|
|
102
|
-
// Ignore this listener while that direct flow is in progress: Angular
|
|
103
|
-
// Fire can publish the auth-state change before Firestore has applied
|
|
104
|
-
// the new credentials, so duplicate provisioning here can be denied.
|
|
105
|
-
//
|
|
106
|
-
// This architecture avoids the race condition where Angular Fire's
|
|
107
|
-
// scheduled auth notification arrives before Firestore's internal
|
|
108
|
-
// CredentialsProvider has processed the new token, which would cause
|
|
109
|
-
// "Missing or insufficient permissions" errors on fresh logins.
|
|
110
|
-
switchMap((afUser) => {
|
|
111
|
-
if (afUser) {
|
|
112
|
-
if (isEndingSession) return EMPTY;
|
|
113
|
-
if (store.isLoadingLogin()) return of(afUser);
|
|
114
|
-
return from(trackRefreshProvisioning(afUser)).pipe(
|
|
115
|
-
switchMap(() => of(afUser)),
|
|
116
|
-
catchError((e) => {
|
|
117
|
-
console.error('[AuthStore loadAuth] streamEntity error:', e);
|
|
118
|
-
return EMPTY;
|
|
119
|
-
}),
|
|
120
|
-
);
|
|
121
|
-
} else {
|
|
122
|
-
// If signed out, just pass null down.
|
|
123
|
-
return of(null);
|
|
124
|
-
}
|
|
125
|
-
}),
|
|
126
|
-
|
|
127
|
-
// 3. Keep the Firebase session available to guards and UI.
|
|
128
|
-
tap((afUser: State['afUser']) => {
|
|
129
|
-
if (!afUser) {
|
|
130
|
-
patchState(store, { afUser: null });
|
|
131
|
-
} else {
|
|
132
|
-
patchState(store, { afUser });
|
|
133
|
-
}
|
|
134
|
-
}),
|
|
135
|
-
),
|
|
136
|
-
),
|
|
137
|
-
async signInWithGoogle(): Promise<void> {
|
|
138
|
-
patchState(store, { isLoadingLogin: true });
|
|
139
|
-
try {
|
|
140
|
-
const session = await db.signInWithGoogle();
|
|
141
|
-
// Provision user directly after auth completes, where the auth token
|
|
142
|
-
// is guaranteed to be valid and Firestore's CredentialsProvider has it.
|
|
143
|
-
await provisionAndLoadUser(session);
|
|
144
|
-
patchState(store, { afUser: session });
|
|
145
|
-
} finally {
|
|
146
|
-
patchState(store, { isLoadingLogin: false });
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
async loginAnonymously(): Promise<void> {
|
|
150
|
-
patchState(store, { isLoadingLogin: true });
|
|
151
|
-
try {
|
|
152
|
-
const session = await db.signInAnonymously();
|
|
153
|
-
// Provision user directly after anonymous auth completes, where the
|
|
154
|
-
// auth token is guaranteed to be valid. This avoids the race condition
|
|
155
|
-
// where loadAuth's reactive path fires before Firestore's internal
|
|
156
|
-
// auth state has been updated with the new anonymous token.
|
|
157
|
-
await provisionAndLoadUser(session);
|
|
158
|
-
patchState(store, { afUser: session });
|
|
159
|
-
} finally {
|
|
160
|
-
patchState(store, { isLoadingLogin: false });
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
async linkGoogle(): Promise<void> {
|
|
164
|
-
const session = await db.linkGoogle();
|
|
165
|
-
// Re-provision after linking to update the profile with Google info.
|
|
166
|
-
await provisionAndLoadUser(session);
|
|
167
|
-
patchState(store, { afUser: session });
|
|
168
|
-
},
|
|
169
|
-
async sendEmailSignInLink(email: string): Promise<void> {
|
|
170
|
-
patchState(store, { isLoadingLogin: true });
|
|
171
|
-
try {
|
|
172
|
-
await db.sendEmailSignInLink(email);
|
|
173
|
-
} finally {
|
|
174
|
-
patchState(store, { isLoadingLogin: false });
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
async sendEmailLinkForCurrentAccount(): Promise<void> {
|
|
178
|
-
await db.sendEmailLinkForCurrentAccount();
|
|
179
|
-
},
|
|
180
|
-
getStoredEmailForEmailLink(): string | null {
|
|
181
|
-
return db.getStoredEmailForEmailLink();
|
|
182
|
-
},
|
|
183
|
-
async completeEmailSignInLink(url: string, email: string): Promise<AuthSession> {
|
|
184
|
-
patchState(store, { isLoadingLogin: true });
|
|
185
|
-
try {
|
|
186
|
-
const session = await db.completeEmailSignInLink(url, email);
|
|
187
|
-
// Provision user directly after email link auth completes.
|
|
188
|
-
await provisionAndLoadUser(session);
|
|
189
|
-
patchState(store, { afUser: session });
|
|
190
|
-
return session;
|
|
191
|
-
} finally {
|
|
192
|
-
patchState(store, { isLoadingLogin: false });
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
resetAllStores(): void {
|
|
196
|
-
cachedListeners.teardownAllStreams();
|
|
197
|
-
userStore.reset();
|
|
198
|
-
const userContextStore = injector.get(UserContextStore, null);
|
|
199
|
-
if (userContextStore) userContextStore.reset();
|
|
200
|
-
},
|
|
201
|
-
async deleteAnonymousAccount(): Promise<void> {
|
|
202
|
-
isEndingSession = true;
|
|
203
|
-
try {
|
|
204
|
-
await awaitRefreshProvisioning();
|
|
205
|
-
// Tear down streams and reset in-memory store states & load-time caches
|
|
206
|
-
this.resetAllStores();
|
|
207
|
-
await db.deleteAnonymousAccount();
|
|
208
|
-
// Deleting the Firebase Auth user on the server does not immediately
|
|
209
|
-
// clear the browser's Firebase session. Clear it before navigating so
|
|
210
|
-
// the landing-page guard does not wait for the now-deleted profile.
|
|
211
|
-
await db.logout();
|
|
212
|
-
patchState(store, { afUser: null });
|
|
213
|
-
await router.navigate(['/landing']);
|
|
214
|
-
} finally {
|
|
215
|
-
isEndingSession = false;
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
async logout(params?: { doNotRoute: boolean }): Promise<void> {
|
|
219
|
-
try {
|
|
220
|
-
const session = store.afUser();
|
|
221
|
-
if (session?.isAnonymous) {
|
|
222
|
-
const dialog = injector.get(MatDialog, null);
|
|
223
|
-
if (dialog) {
|
|
224
|
-
const result = await firstValueFrom(dialog.open(GuestDeletionDialogComponent).afterClosed());
|
|
225
|
-
if (result === 'save') {
|
|
226
|
-
await router.navigate(['/account']);
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
if (result !== true) return;
|
|
230
|
-
}
|
|
231
|
-
await this.deleteAnonymousAccount();
|
|
21
|
+
withMethods((store, router = inject(Router), injector = inject(Injector)) => ({
|
|
22
|
+
async deleteAnonymousAccount(): Promise<void> {
|
|
23
|
+
await store.deleteGuestAccount();
|
|
24
|
+
await router.navigate(['/landing']);
|
|
25
|
+
},
|
|
26
|
+
async logout(params?: { doNotRoute: boolean }): Promise<void> {
|
|
27
|
+
try {
|
|
28
|
+
const session = store.afUser();
|
|
29
|
+
if (session?.isAnonymous) {
|
|
30
|
+
const dialog = injector.get(MatDialog, null);
|
|
31
|
+
if (dialog) {
|
|
32
|
+
const result = await firstValueFrom(dialog.open(GuestDeletionDialogComponent).afterClosed());
|
|
33
|
+
if (result === 'save') {
|
|
34
|
+
await router.navigate(['/account']);
|
|
232
35
|
return;
|
|
233
36
|
}
|
|
234
|
-
|
|
235
|
-
isEndingSession = true;
|
|
236
|
-
try {
|
|
237
|
-
await awaitRefreshProvisioning();
|
|
238
|
-
// Tear down all active Firestore streams and clear in-memory entity stores BEFORE signing out.
|
|
239
|
-
this.resetAllStores();
|
|
240
|
-
await db.logout();
|
|
241
|
-
patchState(store, { afUser: null });
|
|
242
|
-
if (!params || !params.doNotRoute) {
|
|
243
|
-
router.navigate(['/landing']);
|
|
244
|
-
}
|
|
245
|
-
} finally {
|
|
246
|
-
isEndingSession = false;
|
|
247
|
-
}
|
|
248
|
-
} catch (e) {
|
|
249
|
-
console.error(e);
|
|
250
|
-
throw e;
|
|
37
|
+
if (result !== true) return;
|
|
251
38
|
}
|
|
252
|
-
|
|
253
|
-
|
|
39
|
+
await this.deleteAnonymousAccount();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
await store.signOut();
|
|
44
|
+
if (!params || !params.doNotRoute) await router.navigate(['/landing']);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.error(e);
|
|
47
|
+
throw e;
|
|
48
|
+
}
|
|
254
49
|
},
|
|
255
|
-
),
|
|
50
|
+
})),
|
|
256
51
|
);
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { withEntitiesForMockDB } from '
|
|
1
|
+
import { dataTimestampNow } from '@tech4good/platform-data';
|
|
2
|
+
import { defineEntityMock, withEntitiesForMockDB } from '@tech4good/platform-data/testing';
|
|
3
3
|
import { signalStore } from '@ngrx/signals';
|
|
4
|
-
import { User, AccessState } from './user.model';
|
|
4
|
+
import { User, AccessState, userEntity } from './user.model';
|
|
5
5
|
|
|
6
|
+
/** Mock backend storage; frontend entity stores read from it through MockDataService. */
|
|
6
7
|
export const UserMockDB = signalStore(
|
|
7
8
|
{ providedIn: 'root' },
|
|
8
|
-
withEntitiesForMockDB<User>(
|
|
9
|
+
withEntitiesForMockDB<User>(userEntity.collection),
|
|
9
10
|
);
|
|
10
11
|
|
|
12
|
+
/** Build a complete stored record for tests, allowing domain fields and metadata to be overridden. */
|
|
11
13
|
export function createMockUser(overrides?: Partial<User>): User {
|
|
12
14
|
return {
|
|
13
15
|
__id: 'mock-user-id',
|
|
@@ -15,8 +17,8 @@ export function createMockUser(overrides?: Partial<User>): User {
|
|
|
15
17
|
isAdmin: false,
|
|
16
18
|
accessState: AccessState.DONE,
|
|
17
19
|
consented: true,
|
|
18
|
-
_createdAt:
|
|
19
|
-
_updatedAt:
|
|
20
|
+
_createdAt: dataTimestampNow(),
|
|
21
|
+
_updatedAt: dataTimestampNow(),
|
|
20
22
|
_deleted: false,
|
|
21
23
|
...overrides,
|
|
22
24
|
};
|
|
@@ -28,8 +30,8 @@ export const MOCK_USER_WAITING: User = {
|
|
|
28
30
|
accessState: AccessState.WAITING,
|
|
29
31
|
isAdmin: false,
|
|
30
32
|
consented: false,
|
|
31
|
-
_createdAt:
|
|
32
|
-
_updatedAt:
|
|
33
|
+
_createdAt: dataTimestampNow(),
|
|
34
|
+
_updatedAt: dataTimestampNow(),
|
|
33
35
|
_deleted: false,
|
|
34
36
|
};
|
|
35
37
|
|
|
@@ -39,8 +41,8 @@ export const MOCK_USER_DONE: User = {
|
|
|
39
41
|
accessState: AccessState.DONE,
|
|
40
42
|
isAdmin: false,
|
|
41
43
|
consented: false,
|
|
42
|
-
_createdAt:
|
|
43
|
-
_updatedAt:
|
|
44
|
+
_createdAt: dataTimestampNow(),
|
|
45
|
+
_updatedAt: dataTimestampNow(),
|
|
44
46
|
_deleted: false,
|
|
45
47
|
};
|
|
46
48
|
|
|
@@ -56,9 +58,12 @@ export const USER_DB: User[] = [
|
|
|
56
58
|
isAdmin: true,
|
|
57
59
|
consented: true,
|
|
58
60
|
accessState: AccessState.DONE,
|
|
59
|
-
_createdAt:
|
|
60
|
-
_updatedAt:
|
|
61
|
+
_createdAt: dataTimestampNow(),
|
|
62
|
+
_updatedAt: dataTimestampNow(),
|
|
61
63
|
_deleted: false,
|
|
62
64
|
},
|
|
63
65
|
...MOCK_USER_LIST,
|
|
64
66
|
];
|
|
67
|
+
|
|
68
|
+
/** Discovered mock wiring; tests can replace seeds through provideAppMocks({ collections: ... }). */
|
|
69
|
+
export const userMock = defineEntityMock(userEntity, { store: UserMockDB, seeds: USER_DB });
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineEntity, DataEntity, DataTimestamp } from '@tech4good/platform-data';
|
|
2
2
|
|
|
3
3
|
/** user data */
|
|
4
|
-
export interface User {
|
|
5
|
-
__id: string;
|
|
6
|
-
_createdAt?: Timestamp;
|
|
7
|
-
_updatedAt?: Timestamp;
|
|
8
|
-
_deleted?: boolean;
|
|
4
|
+
export interface User extends DataEntity {
|
|
9
5
|
name: string;
|
|
10
6
|
photoURL?: string | null;
|
|
11
7
|
isAdmin: boolean;
|
|
12
8
|
accessState: AccessState;
|
|
13
9
|
consented: boolean;
|
|
14
|
-
joinedWaitlistAt?:
|
|
10
|
+
joinedWaitlistAt?: DataTimestamp;
|
|
15
11
|
/** Admin-only: routes where auth guards are bypassed for testing/debugging. */
|
|
16
12
|
adminOverridePaths?: string[];
|
|
17
13
|
}
|
|
@@ -22,3 +18,6 @@ export enum AccessState {
|
|
|
22
18
|
CONSENT = '03 - consent', // on consent form
|
|
23
19
|
DONE = 'done', // finished with the access flow
|
|
24
20
|
}
|
|
21
|
+
|
|
22
|
+
/** Collection identity discovered by t4g-entities; keep the name literal and this export in the model file. */
|
|
23
|
+
export const userEntity = defineEntity<User>({ collection: 'users' });
|
|
@@ -1,41 +1,45 @@
|
|
|
1
1
|
import { inject, effect, WritableSignal } from '@angular/core';
|
|
2
2
|
import { signalStore, patchState, withState, withMethods } from '@ngrx/signals';
|
|
3
3
|
import { withEntities, removeEntity, updateEntity, setEntity, removeEntities, setEntities } from '@ngrx/signals/entities';
|
|
4
|
-
import { EntityLoadQuery, EntityStreamQuery, selectEntities, processLoadQueries, withEntitiesAndDBMethods } from '
|
|
5
|
-
import { QueryParams, QueryOptions
|
|
6
|
-
import {
|
|
4
|
+
import { EntityLoadQuery, EntityStreamQuery, selectEntities, processLoadQueries, withEntitiesAndDBMethods } from '@tech4good/platform-data';
|
|
5
|
+
import { QueryParams, QueryOptions } from '@tech4good/platform-data';
|
|
6
|
+
import { DataEntity } from '@tech4good/platform-data';
|
|
7
|
+
import { User, userEntity } from '../user/user.model';
|
|
7
8
|
|
|
9
|
+
/** Nested one-shot load descriptor; construction alone does not fetch records. */
|
|
8
10
|
export class LoadUser extends EntityLoadQuery<User> {
|
|
9
11
|
constructor(
|
|
10
12
|
store,
|
|
11
13
|
queryParams: QueryParams,
|
|
12
14
|
queryOptions: QueryOptions,
|
|
13
|
-
loadQueries?: (entity: User) => EntityLoadQuery<
|
|
15
|
+
loadQueries?: (entity: User) => EntityLoadQuery<DataEntity>[],
|
|
14
16
|
) {
|
|
15
|
-
super(
|
|
17
|
+
super(userEntity.collection, store, queryParams, queryOptions, loadQueries);
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
static create(store, queryParams: QueryParams, queryOptions: QueryOptions, loadQueries?: (entity: User) => EntityLoadQuery<
|
|
20
|
+
static create(store, queryParams: QueryParams, queryOptions: QueryOptions, loadQueries?: (entity: User) => EntityLoadQuery<DataEntity>[]): LoadUser {
|
|
19
21
|
return new LoadUser(store, queryParams, queryOptions, loadQueries);
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
/** Nested live-query descriptor, scoped to the calling component by its injector. */
|
|
23
26
|
export class StreamUser extends EntityStreamQuery<User> {
|
|
24
27
|
constructor(
|
|
25
28
|
store,
|
|
26
29
|
queryParams: QueryParams,
|
|
27
30
|
queryOptions: QueryOptions,
|
|
28
|
-
streamQueries?: (entity: User) => EntityStreamQuery<
|
|
31
|
+
streamQueries?: (entity: User) => EntityStreamQuery<DataEntity>[],
|
|
29
32
|
) {
|
|
30
|
-
super(
|
|
33
|
+
super(userEntity.collection, store, queryParams, queryOptions, streamQueries);
|
|
31
34
|
}
|
|
32
35
|
|
|
33
|
-
static create(store, queryParams: QueryParams, queryOptions: QueryOptions, streamQueries?: (entity: User) => EntityStreamQuery<
|
|
36
|
+
static create(store, queryParams: QueryParams, queryOptions: QueryOptions, streamQueries?: (entity: User) => EntityStreamQuery<DataEntity>[]): StreamUser {
|
|
34
37
|
return new StreamUser(store, queryParams, queryOptions, streamQueries);
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
|
|
41
|
+
/** One shared root store for this collection. The app explicitly chooses when to clear its records. */
|
|
38
42
|
export const UserStore = signalStore(
|
|
39
43
|
{ providedIn: 'root' },
|
|
40
|
-
withEntitiesAndDBMethods<User>(
|
|
44
|
+
withEntitiesAndDBMethods<User>(userEntity.collection),
|
|
41
45
|
);
|
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { UserContext } from './user-context.model';
|
|
3
|
-
import { withEntitiesForMockDB } from '
|
|
1
|
+
import { dataTimestampNow } from '@tech4good/platform-data';
|
|
2
|
+
import { UserContext, userContextEntity } from './user-context.model';
|
|
3
|
+
import { defineEntityMock, withEntitiesForMockDB } from '@tech4good/platform-data/testing';
|
|
4
4
|
import { signalStore } from '@ngrx/signals';
|
|
5
5
|
import { USER_DB } from '../user/user.mock';
|
|
6
6
|
|
|
7
|
+
/** Mock backend storage; frontend entity stores read from it through MockDataService. */
|
|
7
8
|
export const UserContextMockDB = signalStore(
|
|
8
9
|
{ providedIn: 'root' },
|
|
9
|
-
withEntitiesForMockDB<UserContext>(
|
|
10
|
+
withEntitiesForMockDB<UserContext>(userContextEntity.collection),
|
|
10
11
|
);
|
|
11
12
|
|
|
13
|
+
/** Build a complete stored record for tests, allowing domain fields and metadata to be overridden. */
|
|
14
|
+
export function createMockUserContext(overrides?: Partial<UserContext>): UserContext {
|
|
15
|
+
return {
|
|
16
|
+
__id: 'mock-context-id', __userId: 'mock-user-id', questionOne: '', questionTwo: '',
|
|
17
|
+
_createdAt: dataTimestampNow(), _updatedAt: dataTimestampNow(), _deleted: false,
|
|
18
|
+
...overrides,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
12
22
|
export const MOCK_USERCONTEXT_WAITING: UserContext = {
|
|
13
23
|
__id: 'uc-waiting',
|
|
14
24
|
__userId: 'u1',
|
|
15
25
|
questionOne: 'Response to question one',
|
|
16
26
|
questionTwo: 'Response to question two',
|
|
17
|
-
_createdAt:
|
|
18
|
-
_updatedAt:
|
|
27
|
+
_createdAt: dataTimestampNow(),
|
|
28
|
+
_updatedAt: dataTimestampNow(),
|
|
19
29
|
_deleted: false,
|
|
20
30
|
};
|
|
21
31
|
|
|
@@ -29,11 +39,13 @@ export const USERCONTEXT_DB = [
|
|
|
29
39
|
__userId: USER_DB[0].__id,
|
|
30
40
|
questionOne: 'test',
|
|
31
41
|
questionTwo: 'test',
|
|
32
|
-
_createdAt:
|
|
33
|
-
_updatedAt:
|
|
42
|
+
_createdAt: dataTimestampNow(),
|
|
43
|
+
_updatedAt: dataTimestampNow(),
|
|
34
44
|
_deleted: false,
|
|
35
45
|
},
|
|
36
46
|
...MOCK_USERCONTEXT_LIST,
|
|
37
47
|
];
|
|
38
48
|
|
|
39
49
|
|
|
50
|
+
/** Discovered mock wiring; tests can replace seeds through provideAppMocks({ collections: ... }). */
|
|
51
|
+
export const userContextMock = defineEntityMock(userContextEntity, { store: UserContextMockDB, seeds: USERCONTEXT_DB });
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineEntity, DataEntity } from '@tech4good/platform-data';
|
|
2
2
|
|
|
3
|
-
export interface UserContext {
|
|
4
|
-
__id: string;
|
|
3
|
+
export interface UserContext extends DataEntity {
|
|
5
4
|
__userId: string;
|
|
6
5
|
questionOne: string;
|
|
7
6
|
questionTwo: string;
|
|
8
|
-
_createdAt?: Timestamp;
|
|
9
|
-
_updatedAt?: Timestamp;
|
|
10
|
-
_deleted?: boolean;
|
|
11
7
|
}
|
|
8
|
+
|
|
9
|
+
/** Collection identity discovered by t4g-entities; keep the name literal and this export in the model file. */
|
|
10
|
+
export const userContextEntity = defineEntity<UserContext>({ collection: 'userContexts' });
|
|
@@ -1,41 +1,45 @@
|
|
|
1
1
|
import { inject, effect, WritableSignal } from '@angular/core';
|
|
2
2
|
import { signalStore, patchState, withState, withMethods } from '@ngrx/signals';
|
|
3
3
|
import { withEntities, removeEntity, updateEntity, setEntity, removeEntities, setEntities } from '@ngrx/signals/entities';
|
|
4
|
-
import { EntityLoadQuery, EntityStreamQuery, selectEntities, processLoadQueries, withEntitiesAndDBMethods } from '
|
|
5
|
-
import { QueryParams, QueryOptions
|
|
6
|
-
import {
|
|
4
|
+
import { EntityLoadQuery, EntityStreamQuery, selectEntities, processLoadQueries, withEntitiesAndDBMethods } from '@tech4good/platform-data';
|
|
5
|
+
import { QueryParams, QueryOptions } from '@tech4good/platform-data';
|
|
6
|
+
import { DataEntity } from '@tech4good/platform-data';
|
|
7
|
+
import { UserContext, userContextEntity } from './user-context.model';
|
|
7
8
|
|
|
9
|
+
/** Nested one-shot load descriptor; construction alone does not fetch records. */
|
|
8
10
|
export class LoadUserContext extends EntityLoadQuery<UserContext> {
|
|
9
11
|
constructor(
|
|
10
12
|
store,
|
|
11
13
|
queryParams: QueryParams,
|
|
12
14
|
queryOptions: QueryOptions,
|
|
13
|
-
loadQueries?: (entity: UserContext) => EntityLoadQuery<
|
|
15
|
+
loadQueries?: (entity: UserContext) => EntityLoadQuery<DataEntity>[],
|
|
14
16
|
) {
|
|
15
|
-
super(
|
|
17
|
+
super(userContextEntity.collection, store, queryParams, queryOptions, loadQueries);
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
static create(store, queryParams: QueryParams, queryOptions: QueryOptions, loadQueries?: (entity: UserContext) => EntityLoadQuery<
|
|
20
|
+
static create(store, queryParams: QueryParams, queryOptions: QueryOptions, loadQueries?: (entity: UserContext) => EntityLoadQuery<DataEntity>[]): LoadUserContext {
|
|
19
21
|
return new LoadUserContext(store, queryParams, queryOptions, loadQueries);
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
/** Nested live-query descriptor, scoped to the calling component by its injector. */
|
|
23
26
|
export class StreamUserContext extends EntityStreamQuery<UserContext> {
|
|
24
27
|
constructor(
|
|
25
28
|
store,
|
|
26
29
|
queryParams: QueryParams,
|
|
27
30
|
queryOptions: QueryOptions,
|
|
28
|
-
streamQueries?: (entity: UserContext) => EntityStreamQuery<
|
|
31
|
+
streamQueries?: (entity: UserContext) => EntityStreamQuery<DataEntity>[],
|
|
29
32
|
) {
|
|
30
|
-
super(
|
|
33
|
+
super(userContextEntity.collection, store, queryParams, queryOptions, streamQueries);
|
|
31
34
|
}
|
|
32
35
|
|
|
33
|
-
static create(store, queryParams: QueryParams, queryOptions: QueryOptions, streamQueries?: (entity: UserContext) => EntityStreamQuery<
|
|
36
|
+
static create(store, queryParams: QueryParams, queryOptions: QueryOptions, streamQueries?: (entity: UserContext) => EntityStreamQuery<DataEntity>[]): StreamUserContext {
|
|
34
37
|
return new StreamUserContext(store, queryParams, queryOptions, streamQueries);
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
|
|
41
|
+
/** One shared root store for this collection. The app explicitly chooses when to clear its records. */
|
|
38
42
|
export const UserContextStore = signalStore(
|
|
39
43
|
{ providedIn: 'root' },
|
|
40
|
-
withEntitiesAndDBMethods<UserContext>(
|
|
44
|
+
withEntitiesAndDBMethods<UserContext>(userContextEntity.collection),
|
|
41
45
|
);
|
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { UserPrivate } from './user-private.model';
|
|
3
|
-
import { withEntitiesForMockDB } from '
|
|
1
|
+
import { dataTimestampNow } from '@tech4good/platform-data';
|
|
2
|
+
import { UserPrivate, userPrivateEntity } from './user-private.model';
|
|
3
|
+
import { defineEntityMock, withEntitiesForMockDB } from '@tech4good/platform-data/testing';
|
|
4
4
|
import { signalStore } from '@ngrx/signals';
|
|
5
5
|
|
|
6
|
+
/** Mock backend storage; frontend entity stores read from it through MockDataService. */
|
|
6
7
|
export const UserPrivateMockDB = signalStore(
|
|
7
8
|
{ providedIn: 'root' },
|
|
8
|
-
withEntitiesForMockDB<UserPrivate>(
|
|
9
|
+
withEntitiesForMockDB<UserPrivate>(userPrivateEntity.collection),
|
|
9
10
|
);
|
|
10
11
|
|
|
12
|
+
/** Build a complete stored record for tests, allowing domain fields and metadata to be overridden. */
|
|
13
|
+
export function createMockUserPrivate(overrides?: Partial<UserPrivate>): UserPrivate {
|
|
14
|
+
return {
|
|
15
|
+
__id: 'mock-user-id', email: 'user@example.test',
|
|
16
|
+
_createdAt: dataTimestampNow(), _updatedAt: dataTimestampNow(), _deleted: false,
|
|
17
|
+
...overrides,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
11
21
|
export const USERPRIVATE_DB: UserPrivate[] = [
|
|
12
|
-
{ __id: '1', email: 'a@sample.com' },
|
|
13
|
-
{ __id: 'u1', email: 'alice@example.com' },
|
|
14
|
-
{ __id: 'u2', email: 'bob@example.com' },
|
|
22
|
+
createMockUserPrivate({ __id: '1', email: 'a@sample.com' }),
|
|
23
|
+
createMockUserPrivate({ __id: 'u1', email: 'alice@example.com' }),
|
|
24
|
+
createMockUserPrivate({ __id: 'u2', email: 'bob@example.com' }),
|
|
15
25
|
];
|
|
26
|
+
|
|
27
|
+
/** Discovered mock wiring; tests can replace seeds through provideAppMocks({ collections: ... }). */
|
|
28
|
+
export const userPrivateMock = defineEntityMock(userPrivateEntity, { store: UserPrivateMockDB, seeds: USERPRIVATE_DB });
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineEntity, DataEntity } from '@tech4good/platform-data';
|
|
2
2
|
|
|
3
|
-
export interface UserPrivate {
|
|
4
|
-
__id: string;
|
|
5
|
-
_createdAt?: Timestamp;
|
|
6
|
-
_updatedAt?: Timestamp;
|
|
7
|
-
_deleted?: boolean;
|
|
3
|
+
export interface UserPrivate extends DataEntity {
|
|
8
4
|
email: string;
|
|
9
5
|
emailLinkEnabled?: boolean;
|
|
10
6
|
}
|
|
7
|
+
|
|
8
|
+
/** Collection identity discovered by t4g-entities; keep the name literal and this export in the model file. */
|
|
9
|
+
export const userPrivateEntity = defineEntity<UserPrivate>({ collection: 'userPrivates' });
|