/** * Angular Module configuration — DI tokens, factory, module definition. * * Phase 4: extracted from angular/index.ts. */ import type { ConsentConfig } from '../types'; import { ConsentServiceBase } from './service'; /** * Konfiguration fuer ConsentModule.forRoot() */ export interface ConsentModuleConfig extends ConsentConfig {} /** * Token fuer Dependency Injection * Verwendung mit Angular @Inject(): * * @example * ```typescript * constructor(@Inject(CONSENT_CONFIG) private config: ConsentConfig) {} * ``` */ export const CONSENT_CONFIG = 'CONSENT_CONFIG'; export const CONSENT_SERVICE = 'CONSENT_SERVICE'; /** * Factory fuer ConsentService * * @example * ```typescript * // app.module.ts * providers: [ * { provide: CONSENT_CONFIG, useValue: { apiEndpoint: '...', siteId: '...' } }, * { provide: CONSENT_SERVICE, useFactory: consentServiceFactory, deps: [CONSENT_CONFIG] }, * ] * ``` */ export function consentServiceFactory( config: ConsentConfig ): ConsentServiceBase { return new ConsentServiceBase(config); } /** * ConsentModule - Angular Module * * Dies ist eine Template-Definition. Fuer echte Angular-Nutzung * muss ein separates Angular Library Package erstellt werden. * * @example * ```typescript * // In einem Angular Library Package: * @NgModule({ * declarations: [ConsentBannerComponent, ConsentGateDirective], * exports: [ConsentBannerComponent, ConsentGateDirective], * }) * export class ConsentModule { * static forRoot(config: ConsentModuleConfig): ModuleWithProviders { * return { * ngModule: ConsentModule, * providers: [ * { provide: CONSENT_CONFIG, useValue: config }, * { provide: CONSENT_SERVICE, useFactory: consentServiceFactory, deps: [CONSENT_CONFIG] }, * ], * }; * } * } * ``` */ export const ConsentModuleDefinition = { /** * Providers fuer Root-Module */ forRoot: (config: ConsentModuleConfig) => ({ provide: CONSENT_CONFIG, useValue: config, }), };