Skip to content

Commit

Permalink
feat(application-system): Add validated config (#15872)
Browse files Browse the repository at this point in the history
* feat(application-system): Add validated config

* Add sharedConfig to appModule

* Cleanup

* PR comment

* PR comment fixes

* Remove unused import

* SharedTemplateAPIModule no longer dynamically registered

* local fallback for attachment bucket

* Add error logging

* Modules that no longer need to be dynamic are no longer dynamic

* Update readme

* Post merge conflict fix

* Cleanup

* fix shared.utils

* Cleanup

* Fixes

* Fix test

* fix tests

* Fix lint

* Update social-insurance-administration.service to static module

* Remove unused import

* transition parental leave module to static

* Transition children residence change to static module

* cleanup shared utils

* fix test

* coderabbit suggestion

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
norda-gunni and kodiakhq[bot] authored Oct 9, 2024
1 parent c836d9d commit fb6d2cf
Show file tree
Hide file tree
Showing 105 changed files with 1,346 additions and 1,648 deletions.
2 changes: 2 additions & 0 deletions apps/application-system/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { RightsPortalClientConfig } from '@island.is/clients/icelandic-health-in
import { FriggClientConfig } from '@island.is/clients/mms/frigg'
import { smsModuleConfig } from '@island.is/nova-sms'
import { emailModuleConfig } from '@island.is/email-service'
import { sharedModuleConfig } from '@island.is/application/template-api-modules'

@Module({
imports: [
Expand Down Expand Up @@ -117,6 +118,7 @@ import { emailModuleConfig } from '@island.is/email-service'
FriggClientConfig,
smsModuleConfig,
emailModuleConfig,
sharedModuleConfig,
],
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { environment } from '../../../environments'
import { ApplicationAccessService } from './tools/applicationAccess.service'

import { LoggingModule } from '@island.is/logging'
import { TemplateApiApplicationService } from './template-api.service'
import { AwsModule } from '@island.is/nest/aws'
import { ApplicationApiCoreModule } from '@island.is/application/api/core'
import { FeatureFlagModule } from '@island.is/nest/feature-flags'
Expand All @@ -35,10 +34,7 @@ import { ApplicationActionService } from './application-action.service'
PaymentModule,
AuditModule.forRoot(environment.audit),
AuthModule.register(environment.auth),
TemplateAPIModule.register({
...environment.templateApi,
applicationService: TemplateApiApplicationService,
}),
TemplateAPIModule.register(environment.templateApi),
ApplicationApiCoreModule,
createBullModule(),
ApplicationFilesModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { MockFeatureFlagService } from './mockFeatureFlagService'
import * as uuid from 'uuidv4'
import jwt from 'jsonwebtoken'
import { coreHistoryMessages } from '@island.is/application/core'
import { sharedModuleConfig } from '@island.is/application/template-api-modules'

let app: INestApplication

Expand Down Expand Up @@ -56,6 +57,35 @@ class MockContentfulRepository {
}
}

const mockConfig = {
clientLocationOrigin: 'http://localhost:4242',
baseApiUrl: 'http://localhost:4444',
attachmentBucket: 'attachmentBucket',
templateApi: {
clientLocationOrigin: 'http://localhost:4242/umsoknir',
email: {
sender: 'Devland.is',
address: '[email protected]',
},
jwtSecret: 'supersecret',
xRoadBasePathWithEnv: '',
baseApiUrl: 'http://localhost:4444',
presignBucket: '',
attachmentBucket: 'island-is-dev-storage-application-system',
generalPetition: {
endorsementApiBasePath: 'http://localhost:4246',
},
userProfile: {
serviceBasePath: 'http://localhost:3366',
},
islykill: {
cert: '',
passphrase: '',
basePath: '',
},
},
}

let server: request.SuperTest<request.Test>
// eslint-disable-next-line local-rules/disallow-kennitalas
const nationalId = '1234564321'
Expand All @@ -74,6 +104,8 @@ beforeAll(async () => {
.useClass(MockFeatureFlagService)
.overrideProvider(EmailService)
.useClass(MockEmailService)
.overrideProvider(sharedModuleConfig.KEY)
.useValue(mockConfig)
.overrideGuard(IdsUserGuard)
.useValue(mockAuthGuard),
})
Expand Down
22 changes: 7 additions & 15 deletions libs/application/template-api-modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,20 @@ Start by creating `{your_template_name}.module.ts` and `{your_template_name}.ser
Example of a template API module:

```typescript
import { DynamicModule } from '@nestjs/common'
import { Module } from '@nestjs/common'

// This is a shared module that gives you access to common methods
import { SharedTemplateAPIModule } from '../../shared'

// The base config that template api modules are registered with by default
// (configurable inside `template-api.module.ts`)
import { BaseTemplateAPIModuleConfig } from '../../../types'

// Here you import your module service
import { ReferenceTemplateService } from './reference-template.service'

export class ReferenceTemplateModule {
static register(config: BaseTemplateAPIModuleConfig): DynamicModule {
return {
module: ReferenceTemplateModule,
imports: [SharedTemplateAPIModule.register(config)],
providers: [ReferenceTemplateService],
exports: [ReferenceTemplateService],
}
}
}
@Module({
imports: [SharedTemplateAPIModule],
providers: [ReferenceTemplateService],
exports: [ReferenceTemplateService],
})
export class ReferenceTemplateModule {}
```

Create your service class that extends the `BaseTemplateApiService` and provide the application type to the `super` constructor. \
Expand Down
1 change: 1 addition & 0 deletions libs/application/template-api-modules/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { TemplateAPIModule } from './modules/template-api.module'
export { TemplateAPIService } from './modules/template-api.service'
export { sharedModuleConfig } from './modules/shared'
export { BaseTemplateAPIModuleConfig as TemplateAPIConfig } from './types'
export {
BaseTemplateApiApplicationService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { ApplicationApiCoreModule } from '@island.is/application/api/core'
import { HistoryModule } from '@island.is/application/api/history'
import { DynamicModule } from '@nestjs/common'
import { Module } from '@nestjs/common'
import { ApplicationService } from './application.service'

export class ApplicationModule {
static register(): DynamicModule {
return {
module: ApplicationModule,
imports: [ApplicationApiCoreModule, HistoryModule],
providers: [ApplicationService],
exports: [ApplicationService],
}
}
}
@Module({
imports: [ApplicationApiCoreModule, HistoryModule],
providers: [ApplicationService],
exports: [ApplicationService],
})
export class ApplicationModule {}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { DynamicModule } from '@nestjs/common'
import { Module } from '@nestjs/common'
import { DirectorateOfImmigrationService } from './directorate-of-immigration.service'
import { DirectorateOfImmigrationClientModule } from '@island.is/clients/directorate-of-immigration'
export class DirectorateOfImmigrationModule {
static register(): DynamicModule {
return {
module: DirectorateOfImmigrationModule,
imports: [DirectorateOfImmigrationClientModule],
providers: [DirectorateOfImmigrationService],
exports: [DirectorateOfImmigrationService],
}
}
}

@Module({
imports: [DirectorateOfImmigrationClientModule],
providers: [DirectorateOfImmigrationService],
exports: [DirectorateOfImmigrationService],
})
export class DirectorateOfImmigrationModule {}
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { DynamicModule } from '@nestjs/common'
import { Module } from '@nestjs/common'
import { DrivingLicenseProviderService } from './driving-license.service'
import { DrivingLicenseApiModule } from '@island.is/clients/driving-license'
import { DrivingLicenseBookModule } from '@island.is/api/domains/driving-license-book'

export class DrivingLicenseModule {
static register(): DynamicModule {
return {
module: DrivingLicenseModule,
imports: [DrivingLicenseApiModule, DrivingLicenseBookModule],
providers: [DrivingLicenseProviderService],
exports: [DrivingLicenseProviderService],
}
}
}
@Module({
imports: [DrivingLicenseApiModule, DrivingLicenseBookModule],
providers: [DrivingLicenseProviderService],
exports: [DrivingLicenseProviderService],
})
export class DrivingLicenseModule {}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { DynamicModule } from '@nestjs/common'
import { Module } from '@nestjs/common'
import { InnaClientModule } from '@island.is/clients/inna'
import { InnaService } from './inna.service'
export class InnaModule {
static register(): DynamicModule {
return {
module: InnaModule,
imports: [InnaClientModule],
providers: [InnaService],
exports: [InnaService],
}
}
}

@Module({
imports: [InnaClientModule],
providers: [InnaService],
exports: [InnaService],
})
export class InnaModule {}
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { DynamicModule } from '@nestjs/common'
import { Module } from '@nestjs/common'
import { HealthInsuranceService } from './health-insurance.service'
import {
RightsPortalClientConfig,
RightsPortalClientModule,
} from '@island.is/clients/icelandic-health-insurance/rights-portal'
import { ConfigModule } from '@nestjs/config'

export class HealthInsuranceModule {
static register(): DynamicModule {
return {
module: HealthInsuranceModule,
imports: [
RightsPortalClientModule,
ConfigModule.forRoot({
isGlobal: true,
load: [RightsPortalClientConfig],
}),
],
providers: [HealthInsuranceService],
exports: [HealthInsuranceService],
}
}
}
@Module({
imports: [
RightsPortalClientModule,
ConfigModule.forRoot({
isGlobal: true,
load: [RightsPortalClientConfig],
}),
],
providers: [HealthInsuranceService],
exports: [HealthInsuranceService],
})
export class HealthInsuranceModule {}
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { DynamicModule } from '@nestjs/common'
import { BaseTemplateAPIModuleConfig } from '../../../../types'
import { Module } from '@nestjs/common'
import { IdentityClientModule } from '@island.is/clients/identity'
import { IdentityService } from './identity.service'

export class IdentityModule {
static register(config: BaseTemplateAPIModuleConfig): DynamicModule {
return {
module: IdentityModule,
imports: [IdentityClientModule],
providers: [IdentityService],
exports: [IdentityService],
}
}
}
@Module({
imports: [IdentityClientModule],
providers: [IdentityService],
exports: [IdentityService],
})
export class IdentityModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import { HealthInsuranceService } from './health-insurance/health-insurance.serv
import { InnaService } from './education/inna.service'
import { InnaModule } from './education/inna.module'

export const dynamicModules = [UserProfileModule]

export const modules = [
NationalRegistryModule,
PaymentApiModule,
UserProfileModule,
IdentityModule,
DrivingLicenseModule,
ApplicationModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import { DynamicModule } from '@nestjs/common'
import { BaseTemplateAPIModuleConfig } from '../../../../types'
import { Module } from '@nestjs/common'
import { NationalRegistryClientModule } from '@island.is/clients/national-registry-v2'
import { NationalRegistryService } from './national-registry.service'
import { AssetsModule } from '@island.is/api/domains/assets'
import { ConfigModule } from '@nestjs/config'
import { AssetsClientConfig } from '@island.is/clients/assets'

export class NationalRegistryModule {
static register(config: BaseTemplateAPIModuleConfig): DynamicModule {
return {
module: NationalRegistryModule,
imports: [
NationalRegistryClientModule,
AssetsModule,
ConfigModule.forRoot({
isGlobal: true,
load: [AssetsClientConfig],
}),
],
providers: [NationalRegistryService],
exports: [NationalRegistryService],
}
}
}
@Module({
imports: [
NationalRegistryClientModule,
AssetsModule,
ConfigModule.forRoot({
isGlobal: true,
load: [AssetsClientConfig],
}),
],
providers: [NationalRegistryService],
exports: [NationalRegistryService],
})
export class NationalRegistryModule {}
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { DynamicModule } from '@nestjs/common'
import { Module } from '@nestjs/common'
import { PassportService } from './passport.service'
import { PassportsClientModule } from '@island.is/clients/passports'

export class PassportModule {
static register(): DynamicModule {
return {
module: PassportModule,
imports: [PassportsClientModule],
providers: [PassportService],
exports: [PassportService],
}
}
}
@Module({
imports: [PassportsClientModule],
providers: [PassportService],
exports: [PassportService],
})
export class PassportModule {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DynamicModule } from '@nestjs/common'
import { BaseTemplateAPIModuleConfig } from '../../../../types'
import { Module } from '@nestjs/common'

import {
ChargeFjsV2ClientConfig,
Expand All @@ -10,20 +9,16 @@ import { XRoadConfig } from '@island.is/nest/config'
import { PaymentModule } from '@island.is/application/api/payment'
import { PaymentService } from './payment.service'

export class PaymentApiModule {
static register(config: BaseTemplateAPIModuleConfig): DynamicModule {
return {
module: PaymentModule,
imports: [
ChargeFjsV2ClientModule,
PaymentModule,
ConfigModule.forRoot({
isGlobal: true,
load: [XRoadConfig, ChargeFjsV2ClientConfig],
}),
],
providers: [PaymentService],
exports: [PaymentService],
}
}
}
@Module({
imports: [
ChargeFjsV2ClientModule,
PaymentModule,
ConfigModule.forRoot({
isGlobal: true,
load: [XRoadConfig, ChargeFjsV2ClientConfig],
}),
],
providers: [PaymentService],
exports: [PaymentService],
})
export class PaymentApiModule {}
Loading

0 comments on commit fb6d2cf

Please sign in to comment.