From 217cb646983647b342fcc0cd260f0c6dac947f7c Mon Sep 17 00:00:00 2001 From: Halli1414 <42970319+Halli1414@users.noreply.github.com> Date: Thu, 13 Jun 2024 12:53:41 +0000 Subject: [PATCH] chore(application-system): Refactor env config (#15096) * Data Protection config refactor * remove unused variable * Criminal Record client config refactor * HealthInsurance client config refactor * remove logging * Vmst client config refactor * Data Protection config refactor * remove unused variable * Criminal Record client config refactor * Vmst refactor * clean up * Health insurance client config refactor * client path fix * Revert "Vmst client config refactor" This reverts commit d2855b7e0fc0745320d188ce5a24119ad4745e3e. * basePath update * vmst client refactor round 2 * Data Protection config refactor * remove unused variable * Criminal Record client config refactor * Vmst refactor * clean up * Health insurance client config refactor * client path fix * Data Protection config refactor * remove unused variable * Criminal Record client config refactor * HealthInsurance client config refactor * Vmst client config refactor * Revert "Vmst client config refactor" This reverts commit d2855b7e0fc0745320d188ce5a24119ad4745e3e. * vmst client refactor round 2 * Doublicate key clean up * fallback value for env * Fallback for env variables * chore: nx format:write update dirty files * Update tests to use new module config * Propper mock values * Force feature deploy * clean up * typo fix and other minor clean up --------- Co-authored-by: andes-it Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- apps/api/src/app/app.module.ts | 26 ++-- apps/api/src/app/environments/environment.ts | 25 ---- .../api/src/app/app.module.ts | 8 ++ .../api/src/environments/environment.ts | 48 -------- .../src/lib/criminalRecord.module.ts | 28 ++--- .../src/lib/criminalRecord.spec.ts | 28 +++-- .../src/lib/directorate-of-labour.module.ts | 50 ++------ .../lib/api-domains-health-insurance.spec.ts | 26 ++-- .../src/lib/healthInsurance.module.ts | 37 ++---- .../accident-notification.module.ts | 4 +- .../criminal-record-submission.module.ts | 2 +- .../data-protection-complaint.module.ts | 4 +- .../health-insurance.module.ts | 4 +- .../operatingLicense.module.ts | 2 +- .../parental-leave/parental-leave.module.ts | 22 +--- .../src/lib/types/index.ts | 7 -- .../src/lib/apiConfiguration.ts | 13 +- libs/clients/criminal-record/src/index.ts | 1 + .../src/lib/apiConfiguration.ts | 25 ++++ .../src/lib/criminalRecordApi.config.ts | 17 +++ .../src/lib/criminalRecordApi.module.ts | 67 +++-------- .../data-protection-complaint/src/index.ts | 2 +- .../src/lib/apiConfiguration.ts | 26 ++++ .../data-protection-complaint/src/lib/apis.ts | 23 ++++ .../src/lib/config/config.ts | 2 - ...data-protection-complaint-client.config.ts | 25 ++++ .../lib/data-protection-complaint.module.ts | 112 ++++-------------- .../health-insurance/src/index.ts | 4 +- .../src/lib/apiConfiguration.ts | 29 +++++ .../health-insurance/src/lib/apis.ts | 9 ++ .../lib/clients-health-insurance-v2.config.ts | 31 +++-- .../lib/clients-health-insurance-v2.module.ts | 56 ++------- libs/clients/vmst/src/index.ts | 1 + libs/clients/vmst/src/lib/apiConfiguration.ts | 30 +++++ libs/clients/vmst/src/lib/apis.ts | 23 ++++ libs/clients/vmst/src/lib/vmst.config.ts | 27 +++++ libs/clients/vmst/src/lib/vmst.module.ts | 65 ++-------- 37 files changed, 405 insertions(+), 504 deletions(-) create mode 100644 libs/clients/criminal-record/src/lib/apiConfiguration.ts create mode 100644 libs/clients/criminal-record/src/lib/criminalRecordApi.config.ts create mode 100644 libs/clients/data-protection-complaint/src/lib/apiConfiguration.ts create mode 100644 libs/clients/data-protection-complaint/src/lib/apis.ts create mode 100644 libs/clients/data-protection-complaint/src/lib/data-protection-complaint-client.config.ts create mode 100644 libs/clients/icelandic-health-insurance/health-insurance/src/lib/apiConfiguration.ts create mode 100644 libs/clients/icelandic-health-insurance/health-insurance/src/lib/apis.ts create mode 100644 libs/clients/vmst/src/lib/apiConfiguration.ts create mode 100644 libs/clients/vmst/src/lib/apis.ts create mode 100644 libs/clients/vmst/src/lib/vmst.config.ts diff --git a/apps/api/src/app/app.module.ts b/apps/api/src/app/app.module.ts index 3fbf0f5b2c94..42f08b552804 100644 --- a/apps/api/src/app/app.module.ts +++ b/apps/api/src/app/app.module.ts @@ -185,6 +185,9 @@ import { import { HousingBenefitsConfig } from '@island.is/clients/hms-housing-benefits' import { UserProfileClientConfig } from '@island.is/clients/user-profile' import { UltravioletRadiationClientConfig } from '@island.is/clients/ultraviolet-radiation' +import { CriminalRecordClientConfig } from '@island.is/clients/criminal-record' +import { HealthInsuranceV2ClientConfig } from '@island.is/clients/icelandic-health-insurance/health-insurance' +import { VmstClientConfig } from '@island.is/clients/vmst' const environment = getConfig @@ -223,7 +226,7 @@ const environment = getConfig baseApiUrl: environment.applicationSystem.baseApiUrl!, }), LicenseServiceModule, - DirectorateOfLabourModule.register(), + DirectorateOfLabourModule, FileUploadModule, DocumentModule, DocumentProviderModule.register({ @@ -246,15 +249,7 @@ const environment = getConfig }), CmsTranslationsModule, TerminusModule, - HealthInsuranceModule.register({ - clientV2Config: { - xRoadBaseUrl: environment.healthInsuranceV2.xRoadBaseUrl!, - xRoadProviderId: environment.healthInsuranceV2.xRoadProviderId!, - xRoadClientId: environment.healthInsuranceV2.xRoadClientId!, - username: environment.healthInsuranceV2.username!, - password: environment.healthInsuranceV2.password!, - }, - }), + HealthInsuranceModule, UserProfileModule.register({ islykill: { cert: environment.islykill.cert!, @@ -309,13 +304,7 @@ const environment = getConfig ApiDomainsPaymentModule, PaymentScheduleModule, ProblemModule, - CriminalRecordModule.register({ - clientConfig: { - xroadBaseUrl: environment.xroad.baseUrl!, - xroadClientId: environment.xroad.clientId!, - xroadPath: environment.criminalRecord.xroadPath!, - }, - }), + CriminalRecordModule, MunicipalitiesFinancialAidModule, FishingLicenseModule, MortgageCertificateModule, @@ -414,6 +403,9 @@ const environment = getConfig LicenseConfig, UserProfileClientConfig, UltravioletRadiationClientConfig, + VmstClientConfig, + HealthInsuranceV2ClientConfig, + CriminalRecordClientConfig, ], }), ], diff --git a/apps/api/src/app/environments/environment.ts b/apps/api/src/app/environments/environment.ts index dcf935a98db5..588fbe19ccfe 100644 --- a/apps/api/src/app/environments/environment.ts +++ b/apps/api/src/app/environments/environment.ts @@ -23,9 +23,6 @@ const prodConfig = () => ({ : process.env.XROAD_DRIVING_LICENSE_V2_PATH, }, }, - criminalRecord: { - xroadPath: process.env.XROAD_CRIMINAL_RECORD_PATH, - }, education: { xroadLicenseServiceId: process.env.XROAD_MMS_LICENSE_SERVICE_ID, xroadGradeServiceId: process.env.XROAD_MMS_GRADE_SERVICE_ID, @@ -42,13 +39,6 @@ const prodConfig = () => ({ clientID: process.env.XROAD_CLIENT_ID, xroadID: process.env.XROAD_HEALTH_INSURANCE_ID, }, - healthInsuranceV2: { - xRoadBaseUrl: process.env.XROAD_BASE_PATH, - xRoadClientId: process.env.XROAD_CLIENT_ID, - xRoadProviderId: process.env.XROAD_HEALTH_INSURANCE_ID, - username: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_USERNAME, - password: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_PASSWORD, - }, auth: { issuer: process.env.IDENTITY_SERVER_ISSUER_URL, audience: ['@island.is', '@admin.island.is'], @@ -129,11 +119,6 @@ const devConfig = () => ({ 'r1/IS-DEV/GOV/10005/Logreglan-Protected/RafraentOkuskirteini-v2', }, }, - criminalRecord: { - xroadPath: - process.env.XROAD_CRIMINAL_RECORD_PATH ?? - 'r1/IS-DEV/GOV/10005/Logreglan-Protected/Sakavottord-PDF-v2', - }, education: { xroadLicenseServiceId: 'IS-DEV/GOV/10066/MMS-Protected/license-api-v1', xroadGradeServiceId: 'IS-DEV/GOV/10066/MMS-Protected/grade-api-v1', @@ -152,16 +137,6 @@ const devConfig = () => ({ clientID: process.env.XROAD_CLIENT_ID ?? '', xroadID: process.env.XROAD_HEALTH_INSURANCE_ID ?? '', }, - healthInsuranceV2: { - xRoadBaseUrl: process.env.XROAD_BASE_PATH ?? 'http://localhost:8080', - xRoadClientId: - process.env.XROAD_CLIENT_ID ?? 'IS-DEV/GOV/10000/island-is-client', - xRoadProviderId: - process.env.XROAD_HEALTH_INSURANCE_ID ?? - 'IS-DEV/GOV/10007/SJUKRA-Protected', - username: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_USERNAME ?? '', - password: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_PASSWORD ?? '', - }, auth: { issuer: 'https://identity-server.dev01.devland.is', audience: ['@island.is', '@admin.island.is'], diff --git a/apps/application-system/api/src/app/app.module.ts b/apps/application-system/api/src/app/app.module.ts index d81eb4cafd50..f410c2afc1cc 100644 --- a/apps/application-system/api/src/app/app.module.ts +++ b/apps/application-system/api/src/app/app.module.ts @@ -38,6 +38,10 @@ import { SignatureCollectionClientConfig } from '@island.is/clients/signature-co import { InnaClientConfig } from '@island.is/clients/inna' import { OfficialJournalOfIcelandClientConfig } from '@island.is/clients/official-journal-of-iceland' import { OfficialJournalOfIcelandApplicationClientConfig } from '@island.is/clients/official-journal-of-iceland/application' +import { DataProtectionComplaintClientConfig } from '@island.is/clients/data-protection-complaint' +import { CriminalRecordClientConfig } from '@island.is/clients/criminal-record' +import { HealthInsuranceV2ClientConfig } from '@island.is/clients/icelandic-health-insurance/health-insurance' +import { VmstClientConfig } from '@island.is/clients/vmst' @Module({ imports: [ @@ -79,6 +83,10 @@ import { OfficialJournalOfIcelandApplicationClientConfig } from '@island.is/clie InnaClientConfig, OfficialJournalOfIcelandClientConfig, OfficialJournalOfIcelandApplicationClientConfig, + DataProtectionComplaintClientConfig, + CriminalRecordClientConfig, + HealthInsuranceV2ClientConfig, + VmstClientConfig, ], }), ], diff --git a/apps/application-system/api/src/environments/environment.ts b/apps/application-system/api/src/environments/environment.ts index 6de3ad51ee9a..ebf09a8ed504 100644 --- a/apps/application-system/api/src/environments/environment.ts +++ b/apps/application-system/api/src/environments/environment.ts @@ -37,38 +37,11 @@ const devConfig = { password: process.env.NOVA_PASSWORD, acceptUnauthorized: true, }, - criminalRecord: { - clientConfig: { - xroadClientId: - process.env.XROAD_CLIENT_ID ?? 'IS-DEV/GOV/10000/island-is-client', - xroadBaseUrl: process.env.XROAD_BASE_PATH ?? 'http://localhost:8081', - xroadPath: - process.env.XROAD_CRIMINAL_RECORD_PATH ?? - 'r1/IS-DEV/GOV/10005/Logreglan-Protected/Sakavottord-PDF-v2', - }, - }, presignBucket: process.env.FILE_SERVICE_PRESIGN_BUCKET, attachmentBucket: process.env.APPLICATION_ATTACHMENT_BUCKET, generalPetition: { endorsementsApiBasePath: 'http://localhost:4246', }, - healthInsuranceV2: { - xRoadBaseUrl: process.env.XROAD_BASE_PATH ?? 'http://localhost:8080', - xRoadProviderId: - process.env.XROAD_HEALTH_INSURANCE_ID ?? - 'IS-DEV/GOV/10007/SJUKRA-Protected', - xRoadClientId: - process.env.XROAD_CLIENT_ID ?? 'IS-DEV/GOV/10000/island-is-client', - username: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_USERNAME ?? '', - password: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_PASSWORD ?? '', - }, - dataProtectionComplaint: { - password: process.env.DATA_PROTECTION_COMPLAINT_API_PASSWORD, - username: process.env.DATA_PROTECTION_COMPLAINT_API_USERNAME, - XRoadProviderId: process.env.DATA_PROTECTION_COMPLAINT_XROAD_PROVIDER_ID, - xRoadClientId: process.env.XROAD_CLIENT_ID, - xRoadBaseUrl: process.env.XROAD_BASE_PATH ?? 'http://localhost:8080', - }, userProfile: { serviceBasePath: 'http://localhost:3366', }, @@ -123,30 +96,9 @@ const prodConfig = { }, presignBucket: process.env.FILE_SERVICE_PRESIGN_BUCKET, attachmentBucket: process.env.APPLICATION_ATTACHMENT_BUCKET, - criminalRecord: { - clientConfig: { - xroadClientId: process.env.XROAD_CLIENT_ID, - xroadBaseUrl: process.env.XROAD_BASE_PATH, - xroadPath: process.env.XROAD_CRIMINAL_RECORD_PATH, - }, - }, generalPetition: { endorsementsApiBasePath: process.env.ENDORSEMENTS_API_BASE_PATH, }, - healthInsuranceV2: { - xRoadBaseUrl: process.env.XROAD_BASE_PATH, - xRoadProviderId: process.env.XROAD_HEALTH_INSURANCE_ID, - xRoadClientId: process.env.XROAD_CLIENT_ID, - username: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_USERNAME, - password: process.env.XROAD_HEALTH_INSURANCE_V2_XROAD_PASSWORD, - }, - dataProtectionComplaint: { - password: process.env.DATA_PROTECTION_COMPLAINT_API_PASSWORD, - username: process.env.DATA_PROTECTION_COMPLAINT_API_USERNAME, - XRoadProviderId: process.env.DATA_PROTECTION_COMPLAINT_XROAD_PROVIDER_ID, - xRoadClientId: process.env.XROAD_CLIENT_ID, - xRoadBaseUrl: process.env.XROAD_BASE_PATH, - }, userProfile: { serviceBasePath: process.env.SERVICE_USER_PROFILE_URL, }, diff --git a/libs/api/domains/criminal-record/src/lib/criminalRecord.module.ts b/libs/api/domains/criminal-record/src/lib/criminalRecord.module.ts index e4b23a534f13..95bb0706eb7f 100644 --- a/libs/api/domains/criminal-record/src/lib/criminalRecord.module.ts +++ b/libs/api/domains/criminal-record/src/lib/criminalRecord.module.ts @@ -1,23 +1,11 @@ -import { Module, DynamicModule } from '@nestjs/common' +import { Module } from '@nestjs/common' import { CriminalRecordService } from './criminalRecord.service' -import { - CriminalRecordApiModule, - CriminalRecordApiConfig, -} from '@island.is/clients/criminal-record' +import { CriminalRecordApiModule } from '@island.is/clients/criminal-record' -export interface Config { - clientConfig: CriminalRecordApiConfig -} - -@Module({}) -export class CriminalRecordModule { - static register(config: Config): DynamicModule { - return { - module: CriminalRecordModule, - providers: [CriminalRecordService], - imports: [CriminalRecordApiModule.register(config.clientConfig)], - exports: [CriminalRecordService], - } - } -} +@Module({ + providers: [CriminalRecordService], + exports: [CriminalRecordService], + imports: [CriminalRecordApiModule], +}) +export class CriminalRecordModule {} diff --git a/libs/api/domains/criminal-record/src/lib/criminalRecord.spec.ts b/libs/api/domains/criminal-record/src/lib/criminalRecord.spec.ts index 1c2da333cbe2..611134764e53 100644 --- a/libs/api/domains/criminal-record/src/lib/criminalRecord.spec.ts +++ b/libs/api/domains/criminal-record/src/lib/criminalRecord.spec.ts @@ -7,7 +7,8 @@ import { requestHandlers, } from './__mock-data__/requestHandlers' import { startMocking } from '@island.is/shared/mocking' -import { createLogger } from 'winston' +import { ConfigModule } from '@nestjs/config' +import { defineConfig } from '@island.is/nest/config' startMocking(requestHandlers) @@ -17,15 +18,24 @@ describe('CriminalRecordService', () => { beforeEach(async () => { const module = await Test.createTestingModule({ imports: [ - CriminalRecordApiModule.register({ - xroadBaseUrl: 'http://localhost', - xroadClientId: '', - xroadPath: 'v2', - fetchOptions: { - logger: createLogger({ - silent: true, + CriminalRecordApiModule, + ConfigModule.forRoot({ + isGlobal: true, + load: [ + defineConfig({ + name: 'CriminalRecordClient', + load: () => ({ + xRoadServicePath: 'v2', + }), }), - }, + defineConfig({ + name: 'XRoadConfig', + load: () => ({ + xRoadBasePath: 'http://localhost', + xRoadClient: '', + }), + }), + ], }), ], providers: [CriminalRecordService, { provide: 'CONFIG', useValue: {} }], diff --git a/libs/api/domains/directorate-of-labour/src/lib/directorate-of-labour.module.ts b/libs/api/domains/directorate-of-labour/src/lib/directorate-of-labour.module.ts index 1b0f07bea649..c34b7061029d 100644 --- a/libs/api/domains/directorate-of-labour/src/lib/directorate-of-labour.module.ts +++ b/libs/api/domains/directorate-of-labour/src/lib/directorate-of-labour.module.ts @@ -1,45 +1,15 @@ -import { DynamicModule, Module } from '@nestjs/common' - +import { Module } from '@nestjs/common' import { VMSTModule } from '@island.is/clients/vmst' -import { - createXRoadAPIPath, - XRoadMemberClass, -} from '@island.is/shared/utils/server' - import { DirectorateOfLabourRepository } from './directorate-of-labour.repository' import { DirectorateOfLabourResolver } from './directorate-of-labour.resolver' import { DirectorateOfLabourService } from './directorate-of-labour.service' -const XROAD_BASE_PATH_WITH_ENV = process.env.XROAD_BASE_PATH_WITH_ENV ?? '' -const XROAD_VMST_MEMBER_CODE = process.env.XROAD_VMST_MEMBER_CODE ?? '' -const XROAD_VMST_API_PATH = process.env.XROAD_VMST_API_PATH ?? '' -const XROAD_VMST_API_KEY = process.env.XROAD_VMST_API_KEY ?? '' -const XROAD_CLIENT_ID = process.env.XROAD_CLIENT_ID ?? '' -const XROAD_VMST_MEMBER_CLASS = XRoadMemberClass.GovernmentInstitution - -@Module({}) -export class DirectorateOfLabourModule { - static register(): DynamicModule { - return { - module: DirectorateOfLabourModule, - providers: [ - DirectorateOfLabourResolver, - DirectorateOfLabourService, - DirectorateOfLabourRepository, - ], - imports: [ - VMSTModule.register({ - xRoadPath: createXRoadAPIPath( - XROAD_BASE_PATH_WITH_ENV, - XROAD_VMST_MEMBER_CLASS, - XROAD_VMST_MEMBER_CODE, - XROAD_VMST_API_PATH, - ), - xRoadClient: XROAD_CLIENT_ID, - apiKey: XROAD_VMST_API_KEY, - }), - ], - exports: [], - } - } -} +@Module({ + providers: [ + DirectorateOfLabourResolver, + DirectorateOfLabourService, + DirectorateOfLabourRepository, + ], + imports: [VMSTModule], +}) +export class DirectorateOfLabourModule {} diff --git a/libs/api/domains/health-insurance/src/lib/api-domains-health-insurance.spec.ts b/libs/api/domains/health-insurance/src/lib/api-domains-health-insurance.spec.ts index 039c22883181..3d5e03e428a9 100644 --- a/libs/api/domains/health-insurance/src/lib/api-domains-health-insurance.spec.ts +++ b/libs/api/domains/health-insurance/src/lib/api-domains-health-insurance.spec.ts @@ -2,10 +2,12 @@ import { apiDomainsHealthInsurance } from './api-domains-health-insurance' import { Test } from '@nestjs/testing' import { HealthInsuranceService } from './healthInsurance.service' import { - HealthInsuranceV2Client, - HealthInsuranceV2Options, + HealthInsuranceV2ClientConfig, + HealthInsuranceV2ClientModule, } from '@island.is/clients/icelandic-health-insurance/health-insurance' import { logger, LOGGER_PROVIDER } from '@island.is/logging' +import { ConfigModule } from '@nestjs/config' +import { XRoadConfig } from '@island.is/nest/config' describe('apiDomainsHealthInsurance', () => { it('should work', () => { @@ -14,22 +16,16 @@ describe('apiDomainsHealthInsurance', () => { }) describe('healthInsuranceTest', () => { - interface HealthInsuranceOptions { - clientV2Config: HealthInsuranceV2Options - } - const options: HealthInsuranceOptions = { - clientV2Config: { - xRoadBaseUrl: 'http://localhost:8080', - password: '', - username: '', - xRoadClientId: '', - xRoadProviderId: '', - }, - } let service: HealthInsuranceService beforeEach(async () => { const moduleRef = await Test.createTestingModule({ - imports: [HealthInsuranceV2Client.register(options.clientV2Config)], + imports: [ + HealthInsuranceV2ClientModule, + ConfigModule.forRoot({ + isGlobal: true, + load: [HealthInsuranceV2ClientConfig, XRoadConfig], + }), + ], providers: [ { provide: LOGGER_PROVIDER, diff --git a/libs/api/domains/health-insurance/src/lib/healthInsurance.module.ts b/libs/api/domains/health-insurance/src/lib/healthInsurance.module.ts index aeb20d6905de..504e527e4261 100644 --- a/libs/api/domains/health-insurance/src/lib/healthInsurance.module.ts +++ b/libs/api/domains/health-insurance/src/lib/healthInsurance.module.ts @@ -1,31 +1,20 @@ -import { DynamicModule } from '@nestjs/common' +import { Module } from '@nestjs/common' import { HealthInsuranceAccidentNotificationResolver, HealthInsuranceResolver, } from './graphql' import { HealthInsuranceService } from './healthInsurance.service' -import { - HealthInsuranceV2Client, - HealthInsuranceV2Options, -} from '@island.is/clients/icelandic-health-insurance/health-insurance' +import { HealthInsuranceV2ClientModule } from '@island.is/clients/icelandic-health-insurance/health-insurance' import { AccidentNotificationService } from './accident-notification.service' -export interface HealthInsuranceOptions { - clientV2Config: HealthInsuranceV2Options -} - -export class HealthInsuranceModule { - static register(options: HealthInsuranceOptions): DynamicModule { - return { - module: HealthInsuranceModule, - imports: [HealthInsuranceV2Client.register(options.clientV2Config)], - providers: [ - HealthInsuranceService, - AccidentNotificationService, - HealthInsuranceResolver, - HealthInsuranceAccidentNotificationResolver, - ], - exports: [], - } - } -} +@Module({ + imports: [HealthInsuranceV2ClientModule], + providers: [ + HealthInsuranceService, + AccidentNotificationService, + HealthInsuranceResolver, + HealthInsuranceAccidentNotificationResolver, + ], + exports: [], +}) +export class HealthInsuranceModule {} diff --git a/libs/application/template-api-modules/src/lib/modules/templates/accident-notification/accident-notification.module.ts b/libs/application/template-api-modules/src/lib/modules/templates/accident-notification/accident-notification.module.ts index 7b993b3b280f..c3d21f0fbc8f 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/accident-notification/accident-notification.module.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/accident-notification/accident-notification.module.ts @@ -3,7 +3,7 @@ import { SharedTemplateAPIModule } from '../../shared' import { BaseTemplateAPIModuleConfig } from '../../../types' import { ACCIDENT_NOTIFICATION_CONFIG } from './config' import { AccidentNotificationService } from './accident-notification.service' -import { HealthInsuranceV2Client } from '@island.is/clients/icelandic-health-insurance/health-insurance' +import { HealthInsuranceV2ClientModule } from '@island.is/clients/icelandic-health-insurance/health-insurance' import { ApplicationAttachmentService } from './attachments/applicationAttachment.service' import { AccidentNotificationAttachmentProvider } from './attachments/applicationAttachmentProvider' import { S3 } from 'aws-sdk' @@ -26,7 +26,7 @@ export class AccidentNotificationModule { module: AccidentNotificationModule, imports: [ SharedTemplateAPIModule.register(config), - HealthInsuranceV2Client.register(config.healthInsuranceV2), + HealthInsuranceV2ClientModule, ], providers: [ { diff --git a/libs/application/template-api-modules/src/lib/modules/templates/criminal-record-submission/criminal-record-submission.module.ts b/libs/application/template-api-modules/src/lib/modules/templates/criminal-record-submission/criminal-record-submission.module.ts index 83a5179096b7..a9734b91c4e4 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/criminal-record-submission/criminal-record-submission.module.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/criminal-record-submission/criminal-record-submission.module.ts @@ -14,7 +14,7 @@ export class CriminalRecordSubmissionModule { module: CriminalRecordSubmissionModule, imports: [ SharedTemplateAPIModule.register(baseConfig), - CriminalRecordModule.register(baseConfig.criminalRecord), + CriminalRecordModule, SyslumennClientModule, ], providers: [CriminalRecordSubmissionService], diff --git a/libs/application/template-api-modules/src/lib/modules/templates/data-protection-complaint/data-protection-complaint.module.ts b/libs/application/template-api-modules/src/lib/modules/templates/data-protection-complaint/data-protection-complaint.module.ts index 01cb4d43d2e2..631204c5000c 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/data-protection-complaint/data-protection-complaint.module.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/data-protection-complaint/data-protection-complaint.module.ts @@ -22,9 +22,7 @@ export class DataProtectionComplaintModule { imports: [ SharedTemplateAPIModule.register(config), FileStorageModule, - ClientsDataProtectionComplaintModule.register( - config.dataProtectionComplaint, - ), + ClientsDataProtectionComplaintModule, ], providers: [ ApplicationAttachmentProvider, diff --git a/libs/application/template-api-modules/src/lib/modules/templates/health-insurance/health-insurance.module.ts b/libs/application/template-api-modules/src/lib/modules/templates/health-insurance/health-insurance.module.ts index 2465965400d7..a6bdf74fd03a 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/health-insurance/health-insurance.module.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/health-insurance/health-insurance.module.ts @@ -9,7 +9,7 @@ import { BaseTemplateAPIModuleConfig } from '../../../types' // Here you import your module service import { HealthInsuranceService } from './health-insurance.service' -import { HealthInsuranceV2Client } from '@island.is/clients/icelandic-health-insurance/health-insurance' +import { HealthInsuranceV2ClientModule } from '@island.is/clients/icelandic-health-insurance/health-insurance' import { BucketService } from './bucket/bucket.service' export class HealthInsuranceModule { @@ -17,7 +17,7 @@ export class HealthInsuranceModule { return { module: HealthInsuranceModule, imports: [ - HealthInsuranceV2Client.register(config.healthInsuranceV2), + HealthInsuranceV2ClientModule, SharedTemplateAPIModule.register(config), ], providers: [HealthInsuranceService, BucketService], diff --git a/libs/application/template-api-modules/src/lib/modules/templates/operating-license/operatingLicense.module.ts b/libs/application/template-api-modules/src/lib/modules/templates/operating-license/operatingLicense.module.ts index 843b4f90ae8f..4610e3de6d46 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/operating-license/operatingLicense.module.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/operating-license/operatingLicense.module.ts @@ -14,7 +14,7 @@ export class OperatingLicenseModule { imports: [ SyslumennClientModule, SharedTemplateAPIModule.register(config), - CriminalRecordModule.register(config.criminalRecord), + CriminalRecordModule, FinanceClientModule, JudicialAdministrationClientModule, ], diff --git a/libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.module.ts b/libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.module.ts index 371ab3284a7a..bc370c831460 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.module.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.module.ts @@ -1,11 +1,5 @@ import { DynamicModule } from '@nestjs/common' - import { VMSTModule } from '@island.is/clients/vmst' -import { - createXRoadAPIPath, - XRoadMemberClass, -} from '@island.is/shared/utils/server' - import { BaseTemplateAPIModuleConfig } from '../../../types' import { SharedTemplateAPIModule } from '../../shared' import { ParentalLeaveService } from './parental-leave.service' @@ -18,26 +12,12 @@ import { } from '@island.is/clients/national-registry-v2' import { APPLICATION_ATTACHMENT_BUCKET } from './constants' -const XROAD_VMST_MEMBER_CODE = process.env.XROAD_VMST_MEMBER_CODE ?? '' -const XROAD_VMST_API_PATH = process.env.XROAD_VMST_API_PATH ?? '' -const XROAD_CLIENT_ID = process.env.XROAD_CLIENT_ID ?? '' -const XROAD_VMST_API_KEY = process.env.XROAD_VMST_API_KEY ?? '' - export class ParentalLeaveModule { static register(config: BaseTemplateAPIModuleConfig): DynamicModule { return { module: ParentalLeaveModule, imports: [ - VMSTModule.register({ - xRoadPath: createXRoadAPIPath( - config.xRoadBasePathWithEnv, - XRoadMemberClass.GovernmentInstitution, - XROAD_VMST_MEMBER_CODE, - XROAD_VMST_API_PATH, - ), - xRoadClient: XROAD_CLIENT_ID, - apiKey: XROAD_VMST_API_KEY, - }), + VMSTModule, SharedTemplateAPIModule.register(config), SmsModule.register(config.smsOptions), ApplicationApiCoreModule, diff --git a/libs/application/template-api-modules/src/lib/types/index.ts b/libs/application/template-api-modules/src/lib/types/index.ts index ce2afb90cd13..9d3696b512a2 100644 --- a/libs/application/template-api-modules/src/lib/types/index.ts +++ b/libs/application/template-api-modules/src/lib/types/index.ts @@ -1,15 +1,11 @@ import { Injectable, Type } from '@nestjs/common' -import { Config as CriminalRecordConfig } from '@island.is/api/domains/criminal-record' import { Application, ApplicationWithAttachments, } from '@island.is/application/types' import { User } from '@island.is/auth-nest-tools' -import { DataProtectionComplaintClientConfig } from '@island.is/clients/data-protection-complaint' -import { HealthInsuranceV2Options } from '@island.is/clients/icelandic-health-insurance/health-insurance' import { IslykillApiModuleConfig } from '@island.is/clients/islykill' -import { PaymentScheduleServiceOptions } from '@island.is/clients/payment-schedule' import { Message } from '@island.is/email-service' import type { Locale } from '@island.is/shared/types' @@ -36,14 +32,11 @@ export interface BaseTemplateAPIModuleConfig { password: string acceptUnauthorized?: boolean } - criminalRecord: CriminalRecordConfig attachmentBucket: string presignBucket: string generalPetition: { endorsementsApiBasePath: string } - healthInsuranceV2: HealthInsuranceV2Options - dataProtectionComplaint: DataProtectionComplaintClientConfig applicationService: Type userProfile: { serviceBasePath: string diff --git a/libs/clients/althingi-ombudsman/src/lib/apiConfiguration.ts b/libs/clients/althingi-ombudsman/src/lib/apiConfiguration.ts index 474d7717b658..f321975b8dde 100644 --- a/libs/clients/althingi-ombudsman/src/lib/apiConfiguration.ts +++ b/libs/clients/althingi-ombudsman/src/lib/apiConfiguration.ts @@ -1,9 +1,5 @@ import { createEnhancedFetch } from '@island.is/clients/middlewares' -import { - ConfigType, - IdsClientConfig, - XRoadConfig, -} from '@island.is/nest/config' +import { ConfigType, XRoadConfig } from '@island.is/nest/config' import { AlthingiOmbudsmanClientConfig } from './clients-althingi-ombudsman.config' import { Configuration } from '../gen/fetch/dev' @@ -12,7 +8,6 @@ export const ApiConfiguration = { useFactory: ( xRoadConfig: ConfigType, config: ConfigType, - idsClientConfig: ConfigType, ) => new Configuration({ fetchApi: createEnhancedFetch({ @@ -26,9 +21,5 @@ export const ApiConfiguration = { 'X-Road-Client': xRoadConfig.xRoadClient, }, }), - inject: [ - XRoadConfig.KEY, - AlthingiOmbudsmanClientConfig.KEY, - IdsClientConfig.KEY, - ], + inject: [XRoadConfig.KEY, AlthingiOmbudsmanClientConfig.KEY], } diff --git a/libs/clients/criminal-record/src/index.ts b/libs/clients/criminal-record/src/index.ts index 7d4c8aa33427..73105ddb07fd 100644 --- a/libs/clients/criminal-record/src/index.ts +++ b/libs/clients/criminal-record/src/index.ts @@ -3,3 +3,4 @@ export * from './lib/criminalRecordApi.module' export * from './lib/criminalRecordApi.types' export { CriminalRecordApi } from './lib/criminalRecordApi.service' +export { CriminalRecordClientConfig } from './lib/criminalRecordApi.config' diff --git a/libs/clients/criminal-record/src/lib/apiConfiguration.ts b/libs/clients/criminal-record/src/lib/apiConfiguration.ts new file mode 100644 index 000000000000..34451056ec17 --- /dev/null +++ b/libs/clients/criminal-record/src/lib/apiConfiguration.ts @@ -0,0 +1,25 @@ +import { ConfigType, XRoadConfig } from '@island.is/nest/config' +import { CriminalRecordClientConfig } from './criminalRecordApi.config' +import { Configuration } from '../../gen/fetch' +import { createEnhancedFetch } from '@island.is/clients/middlewares' + +export const ApiConfiguration = { + provide: 'CriminalRecordClientApiConfiguration', + useFactory: ( + xRoadConfig: ConfigType, + config: ConfigType, + ) => + new Configuration({ + fetchApi: createEnhancedFetch({ + name: 'clients-criminal-record', + organizationSlug: 'rikislogreglustjori', + }), + basePath: `${xRoadConfig.xRoadBasePath}/${config.xRoadServicePath}`, + headers: { + 'X-Road-Client': xRoadConfig.xRoadClient, + 'Content-Type': 'application/json', + Accept: 'application/json', + }, + }), + inject: [XRoadConfig.KEY, CriminalRecordClientConfig.KEY], +} diff --git a/libs/clients/criminal-record/src/lib/criminalRecordApi.config.ts b/libs/clients/criminal-record/src/lib/criminalRecordApi.config.ts new file mode 100644 index 000000000000..7afb400a90b9 --- /dev/null +++ b/libs/clients/criminal-record/src/lib/criminalRecordApi.config.ts @@ -0,0 +1,17 @@ +import { defineConfig } from '@island.is/nest/config' +import * as z from 'zod' +const schema = z.object({ + xRoadServicePath: z.string(), +}) + +export const CriminalRecordClientConfig = defineConfig>({ + name: 'CriminalRecordClient', + load(env) { + return { + xRoadServicePath: env.required( + 'XROAD_CRIMINAL_RECORD_PATH', + 'r1/IS-DEV/GOV/10005/Logreglan-Protected/Sakavottord-PDF-v2', + ), + } + }, +}) diff --git a/libs/clients/criminal-record/src/lib/criminalRecordApi.module.ts b/libs/clients/criminal-record/src/lib/criminalRecordApi.module.ts index b14d43d398a6..1c205dc22154 100644 --- a/libs/clients/criminal-record/src/lib/criminalRecordApi.module.ts +++ b/libs/clients/criminal-record/src/lib/criminalRecordApi.module.ts @@ -1,54 +1,19 @@ -import { DynamicModule } from '@nestjs/common' -import { - createEnhancedFetch, - EnhancedFetchOptions, -} from '@island.is/clients/middlewares' +import { Module } from '@nestjs/common' import { CriminalRecordApi } from './criminalRecordApi.service' -import { CrimeCertificateApi, Configuration } from '../../gen/fetch' +import { Configuration, CrimeCertificateApi } from '../../gen/fetch' +import { ApiConfiguration } from './apiConfiguration' -export interface CriminalRecordApiConfig { - xroadBaseUrl: string - xroadClientId: string - xroadPath: string - fetchOptions?: Partial -} - -const configFactory = (config: CriminalRecordApiConfig, basePath: string) => ({ - fetchApi: createEnhancedFetch({ - name: 'clients-criminal-record', - organizationSlug: 'rikislogreglustjori', - ...config.fetchOptions, - }), - headers: { - 'X-Road-Client': config.xroadClientId, - 'Content-Type': 'application/json', - Accept: 'application/json', - }, - basePath, +@Module({ + providers: [ + ApiConfiguration, + { + provide: CriminalRecordApi, + useFactory: (configuration: Configuration) => { + return new CriminalRecordApi(new CrimeCertificateApi(configuration)) + }, + inject: [ApiConfiguration.provide], + }, + ], + exports: [CriminalRecordApi], }) - -export class CriminalRecordApiModule { - static register(config: CriminalRecordApiConfig): DynamicModule { - return { - module: CriminalRecordApiModule, - providers: [ - { - provide: CriminalRecordApi, - useFactory: () => { - const api = new CrimeCertificateApi( - new Configuration( - configFactory( - config, - `${config.xroadBaseUrl}/${config.xroadPath}`, - ), - ), - ) - - return new CriminalRecordApi(api) - }, - }, - ], - exports: [CriminalRecordApi], - } - } -} +export class CriminalRecordApiModule {} diff --git a/libs/clients/data-protection-complaint/src/index.ts b/libs/clients/data-protection-complaint/src/index.ts index ee1489664d88..763106640e32 100644 --- a/libs/clients/data-protection-complaint/src/index.ts +++ b/libs/clients/data-protection-complaint/src/index.ts @@ -9,4 +9,4 @@ export { DocumentInfo, } from './gen/fetch' export { TokenMiddleware } from './lib/data-protection-complaint-client.middleware' -export { DataProtectionComplaintClientConfig } from './lib/config/' +export { DataProtectionComplaintClientConfig } from './lib/data-protection-complaint-client.config' diff --git a/libs/clients/data-protection-complaint/src/lib/apiConfiguration.ts b/libs/clients/data-protection-complaint/src/lib/apiConfiguration.ts new file mode 100644 index 000000000000..5d8d873f4a18 --- /dev/null +++ b/libs/clients/data-protection-complaint/src/lib/apiConfiguration.ts @@ -0,0 +1,26 @@ +import { ConfigType, XRoadConfig } from '@island.is/nest/config' +import { DataProtectionComplaintClientConfig } from './data-protection-complaint-client.config' +import { Configuration } from '../gen/fetch' +import { createEnhancedFetch } from '@island.is/clients/middlewares' + +export const ApiConfiguration = { + provide: 'DataProtectionClientApiConfiguration', + useFactory: ( + xRoadConfig: ConfigType, + config: ConfigType, + ) => + new Configuration({ + fetchApi: createEnhancedFetch({ + name: 'data-protection-complaint-client', + organizationSlug: 'personuvernd', + logErrorResponseBody: true, + timeout: 60 * 1000, // 60 sec + }), + basePath: `${xRoadConfig.xRoadBasePath}/r1/${config.XRoadProviderId}`, + headers: { + 'X-Road-Client': xRoadConfig.xRoadClient, + Accept: 'application/json', + }, + }), + inject: [XRoadConfig.KEY, DataProtectionComplaintClientConfig.KEY], +} diff --git a/libs/clients/data-protection-complaint/src/lib/apis.ts b/libs/clients/data-protection-complaint/src/lib/apis.ts new file mode 100644 index 000000000000..d68ec30f55d3 --- /dev/null +++ b/libs/clients/data-protection-complaint/src/lib/apis.ts @@ -0,0 +1,23 @@ +import { + CaseApi, + ClientsApi, + Configuration, + DocumentApi, + MemoApi, + SecurityApi, +} from '../gen/fetch' +import { ApiConfiguration } from './apiConfiguration' + +export const exportedApis = [ + DocumentApi, + CaseApi, + SecurityApi, + MemoApi, + ClientsApi, +].map((Api) => ({ + provide: Api, + useFactory: (configuration: Configuration) => { + return new Api(configuration) + }, + inject: [ApiConfiguration.provide], +})) diff --git a/libs/clients/data-protection-complaint/src/lib/config/config.ts b/libs/clients/data-protection-complaint/src/lib/config/config.ts index 04771bfd5c3f..6040aae65d5a 100644 --- a/libs/clients/data-protection-complaint/src/lib/config/config.ts +++ b/libs/clients/data-protection-complaint/src/lib/config/config.ts @@ -2,7 +2,5 @@ export const CLIENT_CONFIG = 'CLIENT_CONFIG' export interface DataProtectionComplaintClientConfig { username: string password: string - xRoadBaseUrl: string XRoadProviderId: string - xRoadClientId: string } diff --git a/libs/clients/data-protection-complaint/src/lib/data-protection-complaint-client.config.ts b/libs/clients/data-protection-complaint/src/lib/data-protection-complaint-client.config.ts new file mode 100644 index 000000000000..2e3b6b6df78f --- /dev/null +++ b/libs/clients/data-protection-complaint/src/lib/data-protection-complaint-client.config.ts @@ -0,0 +1,25 @@ +import { defineConfig } from '@island.is/nest/config' +import * as z from 'zod' + +const schema = z.object({ + username: z.string(), + password: z.string(), + XRoadProviderId: z.string(), +}) + +export const DataProtectionComplaintClientConfig = defineConfig< + z.infer +>({ + name: 'DataProtectionComplaintClient', + schema, + load(env) { + return { + password: env.required('DATA_PROTECTION_COMPLAINT_API_PASSWORD', ''), + username: env.required('DATA_PROTECTION_COMPLAINT_API_USERNAME', ''), + XRoadProviderId: env.required( + 'DATA_PROTECTION_COMPLAINT_XROAD_PROVIDER_ID', + '', + ), + } + }, +}) diff --git a/libs/clients/data-protection-complaint/src/lib/data-protection-complaint.module.ts b/libs/clients/data-protection-complaint/src/lib/data-protection-complaint.module.ts index c0eae63e2d38..6fe914b8ae45 100644 --- a/libs/clients/data-protection-complaint/src/lib/data-protection-complaint.module.ts +++ b/libs/clients/data-protection-complaint/src/lib/data-protection-complaint.module.ts @@ -1,93 +1,25 @@ -import { DynamicModule } from '@nestjs/common' -import { - CaseApi, - ClientsApi, - Configuration, - DocumentApi, - MemoApi, - SecurityApi, -} from '../gen/fetch' +import { Module } from '@nestjs/common' +import { SecurityApi } from '../gen/fetch' -import { logger } from '@island.is/logging' -import { createEnhancedFetch } from '@island.is/clients/middlewares' import { TokenMiddleware } from './data-protection-complaint-client.middleware' -import { CLIENT_CONFIG, DataProtectionComplaintClientConfig } from './config' +import { exportedApis } from './apis' +import { ApiConfiguration } from './apiConfiguration' +import { ConfigType } from '@island.is/nest/config' +import { DataProtectionComplaintClientConfig } from './data-protection-complaint-client.config' -export class ClientsDataProtectionComplaintModule { - static register(config: DataProtectionComplaintClientConfig): DynamicModule { - if (!config.xRoadBaseUrl) { - logger.error('DataProtectionClient xRoadPath not provided.') - } - if (!config.password) { - logger.error('DataProtectionClient password not provided.') - } - if (!config.username) { - logger.error('DataProtectionClient username not provided.') - } - if (!config.xRoadClientId) { - logger.error('DataProtectionClient xRoadClientId not provided.') - } - if (!config.XRoadProviderId) { - logger.error('DataProtectionClient XRoadProviderId not provided.') - } - - const basePath = `${config.xRoadBaseUrl}/r1/${config.XRoadProviderId}` - const exportedApis = [ - DocumentApi, - CaseApi, - SecurityApi, - MemoApi, - ClientsApi, - ] - return { - module: ClientsDataProtectionComplaintModule, - providers: [ - { - provide: CLIENT_CONFIG, - useFactory: () => config, - }, - { - provide: SecurityApi, - useFactory: () => { - return new SecurityApi( - new Configuration({ - fetchApi: createEnhancedFetch({ - name: 'data-protection-complaint-client', - organizationSlug: 'personuvernd', - logErrorResponseBody: true, - timeout: 60 * 1000, // 60 sec - }), - basePath: basePath, - headers: { - 'X-Road-Client': config.xRoadClientId, - Accept: 'application/json', - }, - }), - ) - }, - }, - TokenMiddleware, - ...exportedApis.map((Api) => ({ - provide: Api, - useFactory: () => { - return new Api( - new Configuration({ - fetchApi: createEnhancedFetch({ - name: 'data-protection-complaint-client', - logErrorResponseBody: true, - timeout: 60 * 1000, // 60 sec - }), - basePath: basePath, - headers: { - 'X-Road-Client': config.xRoadClientId, - Accept: 'application/json', - }, - }), - ) - }, - })), - ], - exports: [...exportedApis, TokenMiddleware], - } - } -} +@Module({ + exports: [...exportedApis, TokenMiddleware], + providers: [ + ApiConfiguration, + { + provide: TokenMiddleware, + useFactory: ( + config: ConfigType, + securityApi, + ) => new TokenMiddleware(config, securityApi), + inject: [DataProtectionComplaintClientConfig.KEY, SecurityApi], + }, + ...exportedApis, + ], +}) +export class ClientsDataProtectionComplaintModule {} diff --git a/libs/clients/icelandic-health-insurance/health-insurance/src/index.ts b/libs/clients/icelandic-health-insurance/health-insurance/src/index.ts index c5a4fab73a86..037c7eae8b9c 100644 --- a/libs/clients/icelandic-health-insurance/health-insurance/src/index.ts +++ b/libs/clients/icelandic-health-insurance/health-insurance/src/index.ts @@ -1,3 +1,3 @@ -export { HealthInsuranceV2Client } from './lib/clients-health-insurance-v2.module' +export { HealthInsuranceV2ClientModule } from './lib/clients-health-insurance-v2.module' export { DocumentApi, Configuration, PersonApi } from '../gen/fetch' -export { HealthInsuranceV2Options } from './lib/clients-health-insurance-v2.config' +export { HealthInsuranceV2ClientConfig } from './lib/clients-health-insurance-v2.config' diff --git a/libs/clients/icelandic-health-insurance/health-insurance/src/lib/apiConfiguration.ts b/libs/clients/icelandic-health-insurance/health-insurance/src/lib/apiConfiguration.ts new file mode 100644 index 000000000000..a2ae482ffe3e --- /dev/null +++ b/libs/clients/icelandic-health-insurance/health-insurance/src/lib/apiConfiguration.ts @@ -0,0 +1,29 @@ +import { ConfigType, XRoadConfig } from '@island.is/nest/config' +import { createEnhancedFetch } from '@island.is/clients/middlewares' +import { Configuration } from '../../gen/fetch' +import { HealthInsuranceV2ClientConfig } from './clients-health-insurance-v2.config' + +export const ApiConfiguration = { + provide: 'HealthInsuranceV2ClientApiConfiguration', + useFactory: ( + xRoadConfig: ConfigType, + config: ConfigType, + ) => + new Configuration({ + fetchApi: createEnhancedFetch({ + name: 'clients-health-insurance', + organizationSlug: 'sjukratryggingar', + logErrorResponseBody: true, + timeout: 20000, // needed because the external service is taking a while to respond to submitting the document + }), + basePath: `${xRoadConfig.xRoadBasePath}/r1/${config.xRoadServicePath}/islandis`, + headers: { + 'X-Road-Client': xRoadConfig.xRoadClient, + userName: `${config.username}`, + password: `${config.password}`, + Accept: 'application/json', + 'Content-Type': 'application/json', + }, + }), + inject: [XRoadConfig.KEY, HealthInsuranceV2ClientConfig.KEY], +} diff --git a/libs/clients/icelandic-health-insurance/health-insurance/src/lib/apis.ts b/libs/clients/icelandic-health-insurance/health-insurance/src/lib/apis.ts new file mode 100644 index 000000000000..147cbbed733b --- /dev/null +++ b/libs/clients/icelandic-health-insurance/health-insurance/src/lib/apis.ts @@ -0,0 +1,9 @@ +import { Configuration, DocumentApi, PersonApi } from '../../gen/fetch' +import { ApiConfiguration } from './apiConfiguration' +export const exportedApis = [DocumentApi, PersonApi].map((Api) => ({ + provide: Api, + useFactory: (configuration: Configuration) => { + return new Api(configuration) + }, + inject: [ApiConfiguration.provide], +})) diff --git a/libs/clients/icelandic-health-insurance/health-insurance/src/lib/clients-health-insurance-v2.config.ts b/libs/clients/icelandic-health-insurance/health-insurance/src/lib/clients-health-insurance-v2.config.ts index 65027011cb20..d27d11bb823d 100644 --- a/libs/clients/icelandic-health-insurance/health-insurance/src/lib/clients-health-insurance-v2.config.ts +++ b/libs/clients/icelandic-health-insurance/health-insurance/src/lib/clients-health-insurance-v2.config.ts @@ -1,7 +1,24 @@ -export interface HealthInsuranceV2Options { - xRoadBaseUrl: string - xRoadProviderId: string - xRoadClientId: string - username: string - password: string -} +import { defineConfig } from '@island.is/nest/config' +import { z } from 'zod' + +const schema = z.object({ + xRoadServicePath: z.string(), + username: z.string(), + password: z.string(), +}) +export const HealthInsuranceV2ClientConfig = defineConfig< + z.infer +>({ + name: 'HealthInsuranceClient', + schema, + load(env) { + return { + xRoadServicePath: env.required( + 'XROAD_HEALTH_INSURANCE_ID', + 'IS-DEV/GOV/10007/SJUKRA-Protected', + ), + username: env.required('XROAD_HEALTH_INSURANCE_V2_XROAD_USERNAME', ''), + password: env.required('XROAD_HEALTH_INSURANCE_V2_XROAD_PASSWORD', ''), + } + }, +}) diff --git a/libs/clients/icelandic-health-insurance/health-insurance/src/lib/clients-health-insurance-v2.module.ts b/libs/clients/icelandic-health-insurance/health-insurance/src/lib/clients-health-insurance-v2.module.ts index 828548a611da..6f5a991659b4 100644 --- a/libs/clients/icelandic-health-insurance/health-insurance/src/lib/clients-health-insurance-v2.module.ts +++ b/libs/clients/icelandic-health-insurance/health-insurance/src/lib/clients-health-insurance-v2.module.ts @@ -1,49 +1,9 @@ -import { DynamicModule } from '@nestjs/common' -import { Configuration, DocumentApi, PersonApi } from '../../gen/fetch' -import { HealthInsuranceV2Options } from './clients-health-insurance-v2.config' -import { createEnhancedFetch } from '@island.is/clients/middlewares' +import { Module } from '@nestjs/common' +import { ApiConfiguration } from './apiConfiguration' +import { exportedApis } from './apis' -export class HealthInsuranceV2Client { - static register(options: HealthInsuranceV2Options): DynamicModule { - const { password, username, xRoadBaseUrl, xRoadClientId, xRoadProviderId } = - options - const basePath = `${xRoadBaseUrl}/r1/${xRoadProviderId}/islandis` - - const configuration = new Configuration({ - fetchApi: createEnhancedFetch({ - name: 'clients-health-insurance', - organizationSlug: 'sjukratryggingar', - logErrorResponseBody: true, - timeout: 20000, // needed because the external service is taking a while to respond to submitting the document - }), - basePath: basePath, - headers: { - 'X-Road-Client': xRoadClientId, - userName: `${username}`, - password: `${password}`, - Accept: 'application/json', - 'Content-Type': 'application/json', - }, - }) - - return { - module: HealthInsuranceV2Client, - imports: [], - providers: [ - { - provide: DocumentApi, - useFactory: () => { - return new DocumentApi(configuration) - }, - }, - { - provide: PersonApi, - useFactory: () => { - return new PersonApi(configuration) - }, - }, - ], - exports: [DocumentApi, PersonApi], - } - } -} +@Module({ + exports: [...exportedApis], + providers: [ApiConfiguration, ...exportedApis], +}) +export class HealthInsuranceV2ClientModule {} diff --git a/libs/clients/vmst/src/index.ts b/libs/clients/vmst/src/index.ts index fe8e5041a35b..fc6ebb160dcf 100644 --- a/libs/clients/vmst/src/index.ts +++ b/libs/clients/vmst/src/index.ts @@ -1,2 +1,3 @@ export { VMSTModule } from './lib/vmst.module' export * from '../gen/fetch' +export * from './lib/vmst.config' diff --git a/libs/clients/vmst/src/lib/apiConfiguration.ts b/libs/clients/vmst/src/lib/apiConfiguration.ts new file mode 100644 index 000000000000..e3833f0ad5d1 --- /dev/null +++ b/libs/clients/vmst/src/lib/apiConfiguration.ts @@ -0,0 +1,30 @@ +import { ConfigType, XRoadConfig } from '@island.is/nest/config' +import { isRunningOnEnvironment } from '@island.is/shared/utils' +import { VmstClientConfig } from './vmst.config' +import { Configuration } from '../../gen/fetch' +import { createWrappedFetchWithLogging } from './utils' +import { createXRoadAPIPath } from '@island.is/shared/utils/server' + +const isRunningOnProduction = isRunningOnEnvironment('production') + +export const ApiConfiguration = { + provide: 'VmstClientApiConfiguration', + useFactory: ( + xRoadConfig: ConfigType, + config: ConfigType, + ) => + new Configuration({ + fetchApi: isRunningOnProduction ? fetch : createWrappedFetchWithLogging, + basePath: createXRoadAPIPath( + config.xroadBasePathWithEnv, + config.vmstMemberClass, + config.vmstMemberCode, + config.vmstApiPath, + ), + headers: { + 'api-key': config.apiKey, + 'X-Road-Client': xRoadConfig.xRoadClient, + }, + }), + inject: [XRoadConfig.KEY, VmstClientConfig.KEY], +} diff --git a/libs/clients/vmst/src/lib/apis.ts b/libs/clients/vmst/src/lib/apis.ts new file mode 100644 index 000000000000..422a19775d39 --- /dev/null +++ b/libs/clients/vmst/src/lib/apis.ts @@ -0,0 +1,23 @@ +import { + ParentalLeaveApi, + PensionApi, + PregnancyApi, + UnionApi, + ApplicationInformationApi, + Configuration, +} from '../../gen/fetch' +import { ApiConfiguration } from './apiConfiguration' + +export const exportedApis = [ + ParentalLeaveApi, + PensionApi, + PregnancyApi, + UnionApi, + ApplicationInformationApi, +].map((Api) => ({ + provide: Api, + useFactory: (configuration: Configuration) => { + return new Api(configuration) + }, + inject: [ApiConfiguration.provide], +})) diff --git a/libs/clients/vmst/src/lib/vmst.config.ts b/libs/clients/vmst/src/lib/vmst.config.ts new file mode 100644 index 000000000000..4cb018c15208 --- /dev/null +++ b/libs/clients/vmst/src/lib/vmst.config.ts @@ -0,0 +1,27 @@ +import { defineConfig } from '@island.is/nest/config' +import { XRoadMemberClass } from '@island.is/shared/utils/server' +import * as z from 'zod' + +const schema = z.object({ + apiKey: z.string(), + vmstMemberCode: z.string(), + vmstMemberClass: z.nativeEnum(XRoadMemberClass), + vmstApiPath: z.string(), + xroadBasePathWithEnv: z.string(), +}) + +const XROAD_VMST_MEMBER_CLASS = XRoadMemberClass.GovernmentInstitution + +export const VmstClientConfig = defineConfig>({ + name: 'VmstClient', + schema, + load(env) { + return { + apiKey: env.required('XROAD_VMST_API_KEY', ''), + vmstMemberCode: env.required('XROAD_VMST_MEMBER_CODE', ''), + vmstMemberClass: XROAD_VMST_MEMBER_CLASS, + vmstApiPath: env.required('XROAD_VMST_API_PATH', ''), + xroadBasePathWithEnv: env.required('XROAD_BASE_PATH_WITH_ENV', ''), + } + }, +}) diff --git a/libs/clients/vmst/src/lib/vmst.module.ts b/libs/clients/vmst/src/lib/vmst.module.ts index 8ca975ef5fb5..f9e378ca4207 100644 --- a/libs/clients/vmst/src/lib/vmst.module.ts +++ b/libs/clients/vmst/src/lib/vmst.module.ts @@ -1,63 +1,14 @@ -import { DynamicModule } from '@nestjs/common' -import fetch from 'isomorphic-fetch' - -import { logger } from '@island.is/logging' -import { isRunningOnEnvironment } from '@island.is/shared/utils' - -import { - Configuration, - ParentalLeaveApi, - PensionApi, - PregnancyApi, - UnionApi, - ApplicationInformationApi, -} from '../../gen/fetch' -import { createWrappedFetchWithLogging } from './utils' - -const isRunningOnProduction = isRunningOnEnvironment('production') +import { Module } from '@nestjs/common' +import { exportedApis } from './apis' +import { ApiConfiguration } from './apiConfiguration' export interface VMSTModuleConfig { apiKey: string xRoadPath: string xRoadClient: string } - -export class VMSTModule { - static register(config: VMSTModuleConfig): DynamicModule { - if (!config.apiKey) { - logger.error('VMSTModule XROAD_VMST_API_KEY not provided.') - } - - if (!config.xRoadClient) { - logger.error('VMSTModule XROAD_CLIENT_ID not provided.') - } - - const headers = { - 'api-key': config.apiKey, - 'X-Road-Client': config.xRoadClient, - } - - const providerConfiguration = new Configuration({ - fetchApi: isRunningOnProduction ? fetch : createWrappedFetchWithLogging, - basePath: config.xRoadPath, - headers, - }) - - const exportedApis = [ - ParentalLeaveApi, - PensionApi, - PregnancyApi, - UnionApi, - ApplicationInformationApi, - ] - - return { - module: VMSTModule, - providers: exportedApis.map((Api) => ({ - provide: Api, - useFactory: () => new Api(providerConfiguration), - })), - exports: exportedApis, - } - } -} +@Module({ + exports: [...exportedApis], + providers: [ApiConfiguration, ...exportedApis], +}) +export class VMSTModule {}