Files
marketplaces/src/app/features/admin/notifications/services/admin-notifications-gateway.token.ts

10 lines
508 B
TypeScript
Raw Normal View History

import { InjectionToken, inject } from '@angular/core';
import { AdminNotificationsGateway } from './admin-notifications-gateway.interface';
feat: real API gateways for all remaining local-only domains (F17-F39) Block 3 of the frontend backlog. 18 gateways were hardcoded to their local (mock/localStorage) implementation with no seam to a real backend at all - this closes that gap for everything with a documented contract to build against. 10 core gateways, token now resolves environment.useMockData ? local : api, same pattern already proven on fx-quote earlier this session: permission, analytics, cart (server-cart), finance, vk-id (identity), connector (integrations), marketplace (registry), offer, seller, mall-content 8 admin gateways, same pattern: orders, products, users, transactions, monitoring, moderation, notifications, dashboard-metrics Endpoints came from the matching contract doc where one exists (Phase 1-10, Track A, Track S - cited per file). Three domains have no dedicated contract doc yet (transactions, monitoring, moderation) - those gateways call the established /api/admin/v2/{resource} convention used throughout the rest of docs/backend/, flagged in each file's own comment as inferred rather than specified, for whoever writes that contract to confirm or correct. One real fix along the way: offer-api.gateway.ts's publish() translates a 422 + details[] response (contract §7's actual failure mode) into the interface's { ok: false, errors } shape, rather than letting an HTTP error leak past a caller that expects a value back. Media repository (mock-media-repository.service.ts) deliberately NOT swapped - no backend contract exists for it anywhere in docs/backend/, and inventing endpoint shapes with zero grounding is worse than leaving it mock. Regression this surfaced, fixed as part of the same change: three spec files stubbed a gateway's concrete Local class directly via useValue. That worked by accident while the token unconditionally resolved to the local class; once the token became conditional on useMockData, those specs silently injected the real (unmocked) API gateway instead and failed. Fixed by providing the token instead of the class - the pattern the ADMIN_CATEGORIES_GATEWAY entry in the same spec file already used correctly, because categories was already token-swapped before this session: - admin-analytics.facade.spec.ts (orders/products/moderation gateways) - admin-order-watcher.service.spec.ts (orders gateway, 3 call sites) Verified: 115/115 unit tests, 5/5 E2E, arch:check clean, production build succeeds. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 14:29:50 +04:00
import { AdminNotificationsApiGateway } from './admin-notifications-api.gateway';
feat: real API gateways for all remaining local-only domains (F17-F39) Block 3 of the frontend backlog. 18 gateways were hardcoded to their local (mock/localStorage) implementation with no seam to a real backend at all - this closes that gap for everything with a documented contract to build against. 10 core gateways, token now resolves environment.useMockData ? local : api, same pattern already proven on fx-quote earlier this session: permission, analytics, cart (server-cart), finance, vk-id (identity), connector (integrations), marketplace (registry), offer, seller, mall-content 8 admin gateways, same pattern: orders, products, users, transactions, monitoring, moderation, notifications, dashboard-metrics Endpoints came from the matching contract doc where one exists (Phase 1-10, Track A, Track S - cited per file). Three domains have no dedicated contract doc yet (transactions, monitoring, moderation) - those gateways call the established /api/admin/v2/{resource} convention used throughout the rest of docs/backend/, flagged in each file's own comment as inferred rather than specified, for whoever writes that contract to confirm or correct. One real fix along the way: offer-api.gateway.ts's publish() translates a 422 + details[] response (contract §7's actual failure mode) into the interface's { ok: false, errors } shape, rather than letting an HTTP error leak past a caller that expects a value back. Media repository (mock-media-repository.service.ts) deliberately NOT swapped - no backend contract exists for it anywhere in docs/backend/, and inventing endpoint shapes with zero grounding is worse than leaving it mock. Regression this surfaced, fixed as part of the same change: three spec files stubbed a gateway's concrete Local class directly via useValue. That worked by accident while the token unconditionally resolved to the local class; once the token became conditional on useMockData, those specs silently injected the real (unmocked) API gateway instead and failed. Fixed by providing the token instead of the class - the pattern the ADMIN_CATEGORIES_GATEWAY entry in the same spec file already used correctly, because categories was already token-swapped before this session: - admin-analytics.facade.spec.ts (orders/products/moderation gateways) - admin-order-watcher.service.spec.ts (orders gateway, 3 call sites) Verified: 115/115 unit tests, 5/5 E2E, arch:check clean, production build succeeds. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 14:29:50 +04:00
/** Swap point for docs/backend/PHASE-2-ORDERS-NOTIFICATIONS-CONTRACT.md §7. */
export const ADMIN_NOTIFICATIONS_GATEWAY = new InjectionToken<AdminNotificationsGateway>('ADMIN_NOTIFICATIONS_GATEWAY', {
providedIn: 'root',
refactor(di): keep mock gateways out of production builds (FH-E.6) 21 DI tokens selected their implementation like this: factory: () => (environment.useMockData ? inject(XLocal) : inject(XApi)) That reads as a toggle and is not one. Naming both classes in the factory keeps both reachable, so every mock shipped regardless of the flag - and `useMockData` is false in both environment files, so none of them were ever the selected implementation in the first place. Verified: a fixture string from partner-hierarchy-local.gateway.ts was present in a production bundle. Token factories now inject the API gateway unconditionally. Mock overrides move to src/app/mock-gateway.providers.ts, swapped for a production copy that imports nothing, via the same fileReplacements mechanism mock-data.interceptor.production.ts already uses. Dev behaviour is unchanged - flip useMockData in environment.ts exactly as before. useExisting rather than useClass: the local gateways are already providedIn: 'root' singletons, and an app-level provider for the token wins over its tree-shakable default. scan-bundle.sh gains two patterns so this cannot come back: any *LocalGateway class name, and known fixture literals. Verified in both directions - clean against the real dist, exit 1 against a planted OfferLocalGateway. Result: zero LocalGateway classes and zero fixtures in the production bundle, down from 21 classes and 75 kB of source. Initial bundle is unchanged at 1.55 MB because these all sat in lazy chunks; the win is that production can no longer serve seeded fixtures as real data, not bytes off the critical path. Not addressed here: MediaRepository is still bound to MockMediaRepository unconditionally in app.config.ts. That one cannot be deleted - no real implementation exists yet - so it is a missing API gateway, not dead weight. Tracked separately. 256 tests pass. Build green, boundaries and cycles green. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 15:59:11 +04:00
factory: () => inject(AdminNotificationsApiGateway),
});