diff --git a/src/index.ts b/src/index.ts index bdb7b9d..592bec2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,6 +26,7 @@ export type { IAppCache, IAppCacheKeys } from './helpers/cache'; * Export classes and utils */ export { FumeServer } from './server'; +export { FumeConfigSchema } from './serverConfigSchema'; export { FhirClient } from './helpers/fhirServer'; export const fumeUtils = { duplicate, diff --git a/src/serverConfig.ts b/src/serverConfig.ts index 45a170c..fbc553f 100644 --- a/src/serverConfig.ts +++ b/src/serverConfig.ts @@ -3,25 +3,10 @@ * Project name: FUME */ -import z from 'zod'; import * as dotenv from 'dotenv'; import { IConfig } from './types'; +import { FumeConfigSchema } from './serverConfigSchema'; dotenv.config(); - -export const configSchema = z.object({ - SERVER_PORT: z.preprocess((a) => typeof a === 'string' ? parseInt(a) : a, z.number().int('Must be an integer').positive('Must be positive').default(42420)), - SERVER_STATELESS: z.preprocess((a) => a === 'true', z.boolean().default(false)), - FHIR_SERVER_BASE: z.string().min(1).url().default('http://hapi-fhir.outburn.co.il/fhir'), - FHIR_SERVER_AUTH_TYPE: z.string().default('NONE'), - FHIR_SERVER_UN: z.string().default(''), - FHIR_SERVER_PW: z.string().default(''), - FHIR_SERVER_TIMEOUT: z.preprocess((a) => typeof a === 'string' ? parseInt(a) : a, z.number().int('Must be an integer').positive('Must be positive').default(30000)), - FHIR_VERSION: z.string().min(1).default('4.0.1'), - SEARCH_BUNDLE_PAGE_SIZE: z.preprocess((a) => typeof a === 'string' ? parseInt(a) : a, z.number().int('Must be an integer').positive('Must be positive').default(20)), - FHIR_PACKAGES: z.string().default(''), - EXCLUDE_FHIR_PACKAGES: z.string().default('') -}); - -export const config: IConfig = configSchema.parse(process.env); +export const config: IConfig = FumeConfigSchema.parse(process.env); export default config; diff --git a/src/serverConfigSchema.test.ts b/src/serverConfigSchema.test.ts new file mode 100644 index 0000000..a52d2a2 --- /dev/null +++ b/src/serverConfigSchema.test.ts @@ -0,0 +1,26 @@ +/** + * © Copyright Outburn Ltd. 2022-2023 All Rights Reserved + * Project name: FUME + */ + +import { FumeConfigSchema } from './serverConfigSchema'; +import { test } from '@jest/globals'; + +describe('FumeConfigSchema', () => { + test('Check schema defaults', async () => { + const config = FumeConfigSchema.parse({}); + expect(config).toStrictEqual({ + EXCLUDE_FHIR_PACKAGES: '', + FHIR_PACKAGES: '', + FHIR_SERVER_AUTH_TYPE: 'NONE', + FHIR_SERVER_BASE: 'http://hapi-fhir.outburn.co.il/fhir', + FHIR_SERVER_PW: '', + FHIR_SERVER_TIMEOUT: 30000, + FHIR_SERVER_UN: '', + FHIR_VERSION: '4.0.1', + SEARCH_BUNDLE_PAGE_SIZE: 20, + SERVER_PORT: 42420, + SERVER_STATELESS: false + }); + }); +}); diff --git a/src/serverConfigSchema.ts b/src/serverConfigSchema.ts new file mode 100644 index 0000000..fcf78db --- /dev/null +++ b/src/serverConfigSchema.ts @@ -0,0 +1,15 @@ +import { z } from 'zod'; + +export const FumeConfigSchema = z.object({ + SERVER_PORT: z.preprocess((a) => typeof a === 'string' ? parseInt(a) : a, z.number().int('Must be an integer').positive('Must be positive').default(42420)), + SERVER_STATELESS: z.preprocess((a) => a === 'true', z.boolean().default(false)), + FHIR_SERVER_BASE: z.string().min(1).url().default('http://hapi-fhir.outburn.co.il/fhir'), + FHIR_SERVER_AUTH_TYPE: z.string().default('NONE'), + FHIR_SERVER_UN: z.string().default(''), + FHIR_SERVER_PW: z.string().default(''), + FHIR_SERVER_TIMEOUT: z.preprocess((a) => typeof a === 'string' ? parseInt(a) : a, z.number().int('Must be an integer').positive('Must be positive').default(30000)), + FHIR_VERSION: z.string().min(1).default('4.0.1'), + SEARCH_BUNDLE_PAGE_SIZE: z.preprocess((a) => typeof a === 'string' ? parseInt(a) : a, z.number().int('Must be an integer').positive('Must be positive').default(20)), + FHIR_PACKAGES: z.string().default(''), + EXCLUDE_FHIR_PACKAGES: z.string().default('') +});