import { ModuleWithProviders, NgModule, Optional, SkipSelf, LOCALE_ID, } from '@angular/core'; import { MatSnackBarModule } from '@angular/material/snack-bar'; import { MatDialogModule } from '@angular/material/dialog'; import { PlatformModule } from '@angular/cdk/platform'; import { MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material/form-field'; import { AngularFireModule } from '@angular/fire/compat'; import { AngularFireMessagingModule } from '@angular/fire/compat/messaging'; import { AuthModule, LogLevel } from 'angular-auth-oidc-client'; import { TranslateModule } from '@ngx-translate/core'; import { environment } from 'projects/core/src/environment'; import { MwAppConfigService, MW_APP_CONFIG } from 'projects/core/src/config'; import { MwHttpModule } from 'projects/core/src/http'; import { MwAuthModule } from 'projects/core/src/auth'; import { MwNotificationService, MwLocaleService, MwIconLoaderService, MwCoreDateTimeService, } from './services'; import { MwCoreStoreModule } from './store'; import { MwPlatformService } from './services'; import { MwI18nModule } from './i18n/i18n.module'; import { MwErrorHandlerModule } from './error-handler'; import { Config } from './config'; import { SharedMfeInjectTokens } from './shared-mfe-inject-tokens.providers'; import { MwMonitorService } from './error-handler/monitor.service'; export function localeFactory(localeService: MwLocaleService): MwLocaleService { localeService.registerLocales(); return localeService; } @NgModule({ imports: [ AuthModule.forRoot({ config: { authority: `${new URL(environment.tokenEndpoint).origin}`, redirectUrl: window.location.origin, postLogoutRedirectUri: window.location.origin, clientId: environment.clientId, scope: 'openid profile api offline_access', responseType: 'code', silentRenew: true, useRefreshToken: true, logLevel: LogLevel.Error, unauthorizedRoute: '/unauthorized', customParamsAuthRequest: { version: environment.version, }, customParamsCodeRequest: { client_secret: environment.clientSecret, }, customParamsRefreshTokenRequest: { client_secret: environment.clientSecret, }, }, }), TranslateModule, PlatformModule, MatSnackBarModule, MatDialogModule, AngularFireModule.initializeApp(environment.firebase), AngularFireMessagingModule, MwCoreStoreModule, MwI18nModule, MwAuthModule, MwHttpModule.forRoot({ baseUrl: environment.baseUrl, }), MwErrorHandlerModule, ], }) export class MwCoreModule { constructor( @Optional() @SkipSelf() parentModule: MwCoreModule, readonly monitorService: MwMonitorService ) { if (parentModule) { throw new Error( 'CoreModule is already loaded. Import it in the AppModule only!' ); } } static forRoot(config: Config): ModuleWithProviders { return { ngModule: MwCoreModule, providers: [ MwNotificationService, MwPlatformService, MwLocaleService, MwIconLoaderService, MwAppConfigService, MwCoreDateTimeService, { provide: LOCALE_ID, useFactory: localeFactory, deps: [MwLocaleService], }, { provide: MW_APP_CONFIG, useValue: config, }, { provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: { appearance: 'fill', }, }, { provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: { appearance: config.defaultFormFieldAppearance || 'fill', floatLabel: config.floatLabel || 'always', }, }, ...SharedMfeInjectTokens, ], }; } }