diff --git a/apps/ehr/src/telemed/state/appointment/appointment.queries.ts b/apps/ehr/src/telemed/state/appointment/appointment.queries.ts index fa5a33a81..489d71a9f 100644 --- a/apps/ehr/src/telemed/state/appointment/appointment.queries.ts +++ b/apps/ehr/src/telemed/state/appointment/appointment.queries.ts @@ -2,16 +2,16 @@ import { useAuth0 } from '@auth0/auth0-react'; import { Appointment, Bundle, + Coding, DocumentReference, Encounter, FhirResource, InsurancePlan, Location, + Medication, Patient, QuestionnaireResponse, RelatedPerson, - Coding, - Medication, } from 'fhir/r4b'; import { DateTime } from 'luxon'; import { enqueueSnackbar } from 'notistack'; @@ -21,6 +21,7 @@ import { ChartDataRequestedFields, GetMedicationOrdersResponse, INVENTORY_MEDICATION_TYPE_CODE, + IcdSearchRequestParams, InstructionType, MEDICATION_IDENTIFIER_NAME_SYSTEM, MeetingData, @@ -33,14 +34,13 @@ import { createSmsModel, filterResources, relatedPersonAndCommunicationMaps, - IcdSearchRequestParams, } from 'utils'; import { APPOINTMENT_REFRESH_INTERVAL, CHAT_REFETCH_INTERVAL, QUERY_STALE_TIME } from '../../../constants'; import { useApiClients } from '../../../hooks/useAppClients'; import { useAuthToken } from '../../../hooks/useAuthToken'; import useEvolveUser, { EvolveUser } from '../../../hooks/useEvolveUser'; import { getSelectors } from '../../../shared/store/getSelectors'; -import { PromiseReturnType, OystehrTelemedAPIClient } from '../../data'; +import { OystehrTelemedAPIClient, PromiseReturnType } from '../../data'; import { useGetAppointmentAccessibility } from '../../hooks'; import { useZapEHRAPIClient } from '../../hooks/useOystehrAPIClient'; import { createRefreshableAppointmentData, extractReviewAndSignAppointmentData } from '../../utils'; diff --git a/apps/intake/src/global.d.ts b/apps/intake/src/global.d.ts index b66328784..dab356e7f 100644 --- a/apps/intake/src/global.d.ts +++ b/apps/intake/src/global.d.ts @@ -2,3 +2,9 @@ declare module 'object.hasown' { // eslint-disable-next-line @typescript-eslint/no-empty-function export const shim = (): void => {}; } + +declare global { + interface Window { + global: any; + } +} diff --git a/apps/intake/src/hooks/useSetLastActiveTime.ts b/apps/intake/src/hooks/useSetLastActiveTime.ts index 6b755563c..9b9b840d8 100644 --- a/apps/intake/src/hooks/useSetLastActiveTime.ts +++ b/apps/intake/src/hooks/useSetLastActiveTime.ts @@ -1,7 +1,7 @@ -import { useEffect } from 'react'; -import { zapehrApi } from '../api'; import { DateTime } from 'luxon'; +import { useEffect } from 'react'; import { ZambdaClient } from 'ui-components/lib/hooks/useUCZambdaClient'; +import { zapehrApi } from '../api'; // Update last active time for paperwork-in-progress flag every minute export function useSetLastActiveTime( @@ -10,7 +10,7 @@ export function useSetLastActiveTime( zambdaClient: ZambdaClient | null ): void { useEffect(() => { - let interval: NodeJS.Timeout; + let interval: ReturnType; try { if (zambdaClient && appointmentID && paperworkPage) { interval = setInterval(async () => { diff --git a/apps/intake/src/index.tsx b/apps/intake/src/index.tsx index d6696fc5e..4af11255c 100644 --- a/apps/intake/src/index.tsx +++ b/apps/intake/src/index.tsx @@ -6,6 +6,8 @@ import App from './App'; import './index.css'; import './lib/i18n'; +window.global ||= window; // https://stackoverflow.com/questions/72795666/how-to-fix-vite-build-parser-error-unexpected-token-in-third-party-dependenc + // polyfill for fixing missing hasOwn Object property in some browsers // https://www.npmjs.com/package/object.hasown if (!Object.hasOwn) { diff --git a/apps/intake/src/telemed/components/CallSettings/MicrophoneSettings.tsx b/apps/intake/src/telemed/components/CallSettings/MicrophoneSettings.tsx index bc2d2fd52..4014d9891 100644 --- a/apps/intake/src/telemed/components/CallSettings/MicrophoneSettings.tsx +++ b/apps/intake/src/telemed/components/CallSettings/MicrophoneSettings.tsx @@ -1,12 +1,12 @@ -import { FC, useCallback, useEffect, useRef, useState } from 'react'; -import { Box, Card, FormControl, IconButton, InputLabel, MenuItem, Select, Typography } from '@mui/material'; -import KeyboardVoiceOutlinedIcon from '@mui/icons-material/KeyboardVoiceOutlined'; +import GraphicEqIcon from '@mui/icons-material/GraphicEq'; import KeyboardVoiceIcon from '@mui/icons-material/KeyboardVoice'; -import ReplayIcon from '@mui/icons-material/Replay'; -import PlayArrowIcon from '@mui/icons-material/PlayArrow'; +import KeyboardVoiceOutlinedIcon from '@mui/icons-material/KeyboardVoiceOutlined'; import PauseIcon from '@mui/icons-material/Pause'; +import PlayArrowIcon from '@mui/icons-material/PlayArrow'; +import ReplayIcon from '@mui/icons-material/Replay'; import StopIcon from '@mui/icons-material/Stop'; -import GraphicEqIcon from '@mui/icons-material/GraphicEq'; +import { Box, Card, FormControl, IconButton, InputLabel, MenuItem, Select, Typography } from '@mui/material'; +import { FC, useCallback, useEffect, useRef, useState } from 'react'; import { otherColors } from '../../../IntakeThemeProvider'; type MicrophoneSettingsProps = { @@ -77,7 +77,7 @@ export const MicrophoneSettings: FC = (props) => { }, [audioChunks]); useEffect(() => { - let timeout: NodeJS.Timeout | null = null; + let timeout: ReturnType | null = null; if (recordingStatus === 'recording') { timeout = setTimeout(() => { stopRecording(); diff --git a/apps/intake/src/telemed/pages/VideoChatPage.tsx b/apps/intake/src/telemed/pages/VideoChatPage.tsx index 4a0ceaf30..5cbb240e5 100644 --- a/apps/intake/src/telemed/pages/VideoChatPage.tsx +++ b/apps/intake/src/telemed/pages/VideoChatPage.tsx @@ -1,15 +1,13 @@ -window.global ||= window; // https://stackoverflow.com/questions/72795666/how-to-fix-vite-build-parser-error-unexpected-token-in-third-party-dependenc - import { Container } from '@mui/material'; import { DeviceLabels, GlobalStyles, MeetingProvider, lightTheme, - useMeetingManager, + useAudioInputs, useAudioVideo, useLocalVideo, - useAudioInputs, + useMeetingManager, useVideoInputs, } from 'amazon-chime-sdk-component-library-react'; import { MeetingSessionConfiguration } from 'amazon-chime-sdk-js'; @@ -21,7 +19,7 @@ import { intakeFlowPageRoute } from '../../App'; import { CallSideCard, LoadingSpinner } from '../components'; import { useAppointmentStore } from '../features/appointments'; import { CustomContainer, useIntakeCommonStore } from '../features/common'; -import { VideoRoom, useJoinCall, useVideoCallStore, useCallSettingsStore } from '../features/video-call'; +import { VideoRoom, useCallSettingsStore, useJoinCall, useVideoCallStore } from '../features/video-call'; import { useZapEHRAPIClient } from '../utils'; const VideoChatPage: FC = () => { diff --git a/package-lock.json b/package-lock.json index 42f19b025..0a102b3f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31740,6 +31740,10 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/zambda-utils": { + "resolved": "packages/zambda-utils", + "link": true + }, "node_modules/zen-observable": { "version": "0.8.15", "license": "MIT" @@ -31800,7 +31804,9 @@ "fast-json-patch": "^3.1.1", "luxon": "^3.4.3", "query-string": "^8.1.0", - "short-uuid": "^4.2.2" + "short-uuid": "^4.2.2", + "utils": "*", + "zambda-utils": "*" }, "devDependencies": { "@types/luxon": "^3.3.2", @@ -31875,7 +31881,8 @@ "esbuild": "^0.20.2", "i18next": "^23.11.1", "mixpanel": "^0.18.0", - "utils": "*" + "utils": "*", + "zambda-utils": "*" }, "devDependencies": { "@types/diacritics": "^1.3.3" @@ -32346,31 +32353,11 @@ }, "packages/utils": { "version": "0.0.1", - "dependencies": { - "axios": "1.6.2" - }, "devDependencies": {} }, - "packages/utils/node_modules/axios": { - "version": "1.6.2", - "license": "MIT", - "dependencies": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, - "packages/utils/node_modules/form-data": { - "version": "4.0.0", - "license": "MIT", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } + "packages/zambda-utils": { + "version": "0.0.1", + "devDependencies": {} } } } diff --git a/packages/ehr/zambdas/package.json b/packages/ehr/zambdas/package.json index b9956bf2a..caae827a7 100644 --- a/packages/ehr/zambdas/package.json +++ b/packages/ehr/zambdas/package.json @@ -43,7 +43,9 @@ "fast-json-patch": "^3.1.1", "luxon": "^3.4.3", "query-string": "^8.1.0", - "short-uuid": "^4.2.2" + "short-uuid": "^4.2.2", + "utils": "*", + "zambda-utils": "*" }, "devDependencies": { "@types/luxon": "^3.3.2", diff --git a/packages/ehr/zambdas/scripts/helpers.ts b/packages/ehr/zambdas/scripts/helpers.ts index 59d97c2cc..38cdc6963 100644 --- a/packages/ehr/zambdas/scripts/helpers.ts +++ b/packages/ehr/zambdas/scripts/helpers.ts @@ -15,7 +15,7 @@ import { Resource, Substance, } from 'fhir/r4b'; -import { createOystehrClientFromSecrets, Secrets } from 'utils'; +import { createOystehrClient, getSecret, Secrets, SecretsKeys } from 'utils'; import { getAuth0Token } from '../src/shared'; export const fhirApiUrlFromAuth0Audience = (auth0Audience: string): string => { @@ -209,3 +209,9 @@ export const createOystehrClientFromConfig = async (config: Secrets): Promise { console.group('validateRequestParameters'); - // if (getSecret(SecretsKeys.PROJECT_API, input.secrets) === undefined) { - // throw new Error('"PROJECT_API" configuration not provided'); - // } - if (!input.body) { throw new Error('No request body provided'); } diff --git a/packages/ehr/zambdas/src/get-claims/validateRequestParameters.ts b/packages/ehr/zambdas/src/get-claims/validateRequestParameters.ts index f1fbdf467..771c1bf96 100644 --- a/packages/ehr/zambdas/src/get-claims/validateRequestParameters.ts +++ b/packages/ehr/zambdas/src/get-claims/validateRequestParameters.ts @@ -1,6 +1,5 @@ -import { ClaimsQueueGetRequest } from 'utils'; +import { ClaimsQueueGetRequest, SecretsKeys, getSecret } from 'utils'; import { ZambdaInput } from '../types'; -import { SecretsKeys, getSecret } from '../shared'; export function validateRequestParameters(input: ZambdaInput): ClaimsQueueGetRequest & Pick { console.group('validateRequestParameters'); diff --git a/packages/ehr/zambdas/src/get-conversation/index.ts b/packages/ehr/zambdas/src/get-conversation/index.ts index 821b68b2f..15841563c 100644 --- a/packages/ehr/zambdas/src/get-conversation/index.ts +++ b/packages/ehr/zambdas/src/get-conversation/index.ts @@ -4,14 +4,16 @@ import { Bundle, Communication, Device, Patient, Practitioner, RelatedPerson } f import { DateTime } from 'luxon'; import { Secrets, + SecretsKeys, chunkThings, getFirstName, getFullestAvailableName, getLastName, getMessageFromComm, getMessageHasBeenRead, + getSecret, } from 'utils'; -import { SecretsKeys, getAuth0Token, getSecret } from '../shared'; +import { getAuth0Token } from '../shared'; import { topLevelCatch } from '../shared/errors'; import { createOystehrClient } from '../shared/helpers'; import { ZambdaInput } from '../types'; diff --git a/packages/ehr/zambdas/src/get-medication-orders/validateRequestParameters.ts b/packages/ehr/zambdas/src/get-medication-orders/validateRequestParameters.ts index 55261b3d1..c7b274434 100644 --- a/packages/ehr/zambdas/src/get-medication-orders/validateRequestParameters.ts +++ b/packages/ehr/zambdas/src/get-medication-orders/validateRequestParameters.ts @@ -1,13 +1,9 @@ -import { ZambdaInput } from '../types'; import { GetMedicationOrdersInput } from 'utils'; +import { ZambdaInput } from '../types'; export function validateRequestParameters(input: ZambdaInput): GetMedicationOrdersInput & Pick { console.group('validateRequestParameters'); - // if (getSecret(SecretsKeys.PROJECT_API, input.secrets) === undefined) { - // throw new Error('"PROJECT_API" configuration not provided'); - // } - if (!input.body) { throw new Error('No request body provided'); } diff --git a/packages/ehr/zambdas/src/get-patient-instructions/index.ts b/packages/ehr/zambdas/src/get-patient-instructions/index.ts index 37b2e4e94..6c038e581 100644 --- a/packages/ehr/zambdas/src/get-patient-instructions/index.ts +++ b/packages/ehr/zambdas/src/get-patient-instructions/index.ts @@ -1,5 +1,5 @@ import { APIGatewayProxyResult } from 'aws-lambda'; -import { SecretsKeys, getSecret } from '../shared'; +import { SecretsKeys, getSecret } from 'utils'; import { makeCommunicationDTO } from '../shared/chart-data/chart-data-helpers'; import { checkOrCreateM2MClientToken, createOystehrClient } from '../shared/helpers'; import { ZambdaInput } from '../types'; diff --git a/packages/ehr/zambdas/src/get-patient-profile-photo-url/index.ts b/packages/ehr/zambdas/src/get-patient-profile-photo-url/index.ts index 223b11b97..d480cdb8d 100644 --- a/packages/ehr/zambdas/src/get-patient-profile-photo-url/index.ts +++ b/packages/ehr/zambdas/src/get-patient-profile-photo-url/index.ts @@ -1,11 +1,10 @@ import { APIGatewayProxyResult } from 'aws-lambda'; -import { Secrets } from 'utils'; -import { getSecret, SecretsKeys } from '../shared'; +import { getSecret, Secrets, SecretsKeys } from 'utils'; import { topLevelCatch } from '../shared/errors'; import { checkOrCreateM2MClientToken } from '../shared/helpers'; +import { createPresignedUrl } from '../shared/z3Utils'; import { ZambdaInput } from '../types'; import { validateRequestParameters } from './validateRequestParameters'; -import { createPresignedUrl } from '../shared/z3Utils'; const logIt = (msg: string): void => { console.log(`PatientProfilePhoto: ${msg}`); diff --git a/packages/ehr/zambdas/src/icd-search/index.ts b/packages/ehr/zambdas/src/icd-search/index.ts index 708a2b042..93ba939e7 100644 --- a/packages/ehr/zambdas/src/icd-search/index.ts +++ b/packages/ehr/zambdas/src/icd-search/index.ts @@ -1,6 +1,5 @@ import { APIGatewayProxyResult } from 'aws-lambda'; -import { IcdSearchResponse } from 'utils'; -import { SecretsKeys, getSecret } from '../shared'; +import { IcdSearchResponse, SecretsKeys, getSecret } from 'utils'; import { ZambdaInput } from '../types'; import { validateRequestParameters } from './validateRequestParameters'; diff --git a/packages/ehr/zambdas/src/init-telemed-session/index.ts b/packages/ehr/zambdas/src/init-telemed-session/index.ts index 81d72254e..f9ef64dc1 100644 --- a/packages/ehr/zambdas/src/init-telemed-session/index.ts +++ b/packages/ehr/zambdas/src/init-telemed-session/index.ts @@ -1,8 +1,7 @@ import Oystehr from '@oystehr/sdk'; import { APIGatewayProxyResult } from 'aws-lambda'; import { Appointment, Encounter } from 'fhir/r4b'; -import { InitTelemedSessionResponse, MeetingData, Secrets } from 'utils'; -import { SecretsKeys, getSecret } from '../shared'; +import { InitTelemedSessionResponse, MeetingData, Secrets, SecretsKeys, getSecret } from 'utils'; import { checkOrCreateM2MClientToken, createOystehrClient, getVideoRoomResourceExtension } from '../shared/helpers'; import { ZambdaInput } from '../types'; import { validateRequestParameters } from './validateRequestParameters'; diff --git a/packages/ehr/zambdas/src/init-telemed-session/video-room-creation.ts b/packages/ehr/zambdas/src/init-telemed-session/video-room-creation.ts index b46905368..f3cbc017a 100644 --- a/packages/ehr/zambdas/src/init-telemed-session/video-room-creation.ts +++ b/packages/ehr/zambdas/src/init-telemed-session/video-room-creation.ts @@ -1,8 +1,8 @@ import Oystehr from '@oystehr/sdk'; import { Appointment, Encounter, RelatedPerson } from 'fhir/r4b'; import { DateTime } from 'luxon'; -import { Secrets } from 'utils'; -import { SecretsKeys, getAuth0Token, getSecret } from '../shared'; +import { Secrets, SecretsKeys, getSecret } from 'utils'; +import { getAuth0Token } from '../shared'; import { getPatientFromAppointment } from '../shared/appointment/helpers'; import { getVideoRoomResourceExtension } from '../shared/helpers'; import { getRelatedPersonForPatient } from '../shared/patients'; diff --git a/packages/ehr/zambdas/src/shared/helpers.ts b/packages/ehr/zambdas/src/shared/helpers.ts index 0310278a4..74467f5c6 100644 --- a/packages/ehr/zambdas/src/shared/helpers.ts +++ b/packages/ehr/zambdas/src/shared/helpers.ts @@ -9,7 +9,7 @@ import { Secrets, TELEMED_VIDEO_ROOM_CODE, } from 'utils'; -import { getAuth0Token as getM2MClientToken } from './getAuth0Token'; +import { getAuth0Token } from './getAuth0Token'; import { SecretsKeys, getSecret } from './secrets'; export function createOystehrClient(token: string, secrets: Secrets | null): Oystehr { @@ -26,7 +26,7 @@ export function createOystehrClient(token: string, secrets: Secrets | null): Oys export async function checkOrCreateM2MClientToken(token: string, secrets: Secrets | null): Promise { if (!token) { console.log('getting m2m token for service calls...'); - return await getM2MClientToken(secrets); + return await getAuth0Token(secrets); } else { console.log('already have a token, no need to update'); } diff --git a/packages/ehr/zambdas/src/shared/index.ts b/packages/ehr/zambdas/src/shared/index.ts index d0898cb15..714c16334 100644 --- a/packages/ehr/zambdas/src/shared/index.ts +++ b/packages/ehr/zambdas/src/shared/index.ts @@ -2,6 +2,5 @@ export * from './accessPolicies'; export * from './encounter'; export * from './getAuth0Token'; export * from './lambda'; -export * from './secrets'; -export * from './users.helper'; export * from './resources.helpers'; +export * from './users.helper'; diff --git a/packages/ehr/zambdas/src/shared/secrets.ts b/packages/ehr/zambdas/src/shared/secrets.ts deleted file mode 100644 index 8b54a80ea..000000000 --- a/packages/ehr/zambdas/src/shared/secrets.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Secrets } from 'utils'; - -// Throws if secret could not be found -export const getSecret = (secretKey: string, secrets: Secrets | null): string => { - let value: string | undefined; - if (secrets != null) { - value = secrets[secretKey]; - } else { - value = process.env[secretKey]; - } - - if (value == null) { - throw new Error(`Secret or Environment Variable with key ${secretKey} was not set.`); - } - - return value; -}; - -export enum SecretsKeys { - AUTH0_ENDPOINT = 'AUTH0_ENDPOINT', - AUTH0_CLIENT = 'AUTH0_CLIENT', - AUTH0_SECRET = 'AUTH0_SECRET', - AUTH0_AUDIENCE = 'AUTH0_AUDIENCE', - FHIR_API = 'FHIR_API', - PROJECT_API = 'PROJECT_API', - PROJECT_ID = 'PROJECT_ID', - ENVIRONMENT = 'ENVIRONMENT', - SENDGRID_API_KEY = 'SENDGRID_API_KEY', - ORGANIZATION_ID = 'ORGANIZATION_ID', - SENDGRID_EMAIL_BCC = 'SENDGRID_EMAIL_BCC', - IN_PERSON_SENDGRID_CONFIRMATION_EMAIL_TEMPLATE_ID = 'IN_PERSON_SENDGRID_CONFIRMATION_EMAIL_TEMPLATE_ID', - IN_PERSON_SENDGRID_CANCELLATION_EMAIL_TEMPLATE_ID = 'IN_PERSON_SENDGRID_CANCELLATION_EMAIL_TEMPLATE_ID', - IN_PERSON_SENDGRID_ERROR_EMAIL_TEMPLATE_ID = 'IN_PERSON_SENDGRID_ERROR_EMAIL_TEMPLATE_ID', - IN_PERSON_SENDGRID_ISSUE_REPORT_EMAIL_TEMPLATE_ID = 'IN_PERSON_SENDGRID_ISSUE_REPORT_EMAIL_TEMPLATE_ID', - INTAKE_ISSUE_REPORT_EMAIL_GROUP_ID = 'INTAKE_ISSUE_REPORT_EMAIL_GROUP_ID', - NLM_API_KEY = 'NLM_API_KEY', -} diff --git a/packages/ehr/zambdas/src/sign-appointment/validateRequestParameters.ts b/packages/ehr/zambdas/src/sign-appointment/validateRequestParameters.ts index 5094cd76b..cfeeed518 100644 --- a/packages/ehr/zambdas/src/sign-appointment/validateRequestParameters.ts +++ b/packages/ehr/zambdas/src/sign-appointment/validateRequestParameters.ts @@ -1,5 +1,4 @@ -import { SignAppointmentInput } from 'utils'; -import { SecretsKeys, getSecret } from '../shared'; +import { SecretsKeys, SignAppointmentInput, getSecret } from 'utils'; import { ZambdaInput } from '../types'; export function validateRequestParameters(input: ZambdaInput): SignAppointmentInput & { userToken: string } { diff --git a/packages/ehr/zambdas/src/sync-user/index.ts b/packages/ehr/zambdas/src/sync-user/index.ts index c4c45ef59..053364a32 100644 --- a/packages/ehr/zambdas/src/sync-user/index.ts +++ b/packages/ehr/zambdas/src/sync-user/index.ts @@ -10,7 +10,6 @@ import { allLicensesForPractitioner, getPractitionerNPIIdentitifier, } from 'utils'; -import { SecretsKeys, getSecret } from '../shared'; import { checkOrCreateM2MClientToken, createOystehrClient } from '../shared/helpers'; import { makeQualificationForPractitioner } from '../shared/practitioners'; import { ZambdaInput } from '../types'; diff --git a/packages/ehr/zambdas/src/unassign-practitioner/validateRequestParameters.ts b/packages/ehr/zambdas/src/unassign-practitioner/validateRequestParameters.ts index 959b01441..cb40f508d 100644 --- a/packages/ehr/zambdas/src/unassign-practitioner/validateRequestParameters.ts +++ b/packages/ehr/zambdas/src/unassign-practitioner/validateRequestParameters.ts @@ -1,5 +1,4 @@ -import { UnassignPractitionerInput } from 'utils'; -import { SecretsKeys, getSecret } from '../shared'; +import { SecretsKeys, UnassignPractitionerInput, getSecret } from 'utils'; import { ZambdaInput } from '../types'; export function validateRequestParameters(input: ZambdaInput): UnassignPractitionerInput & { userToken: string } { diff --git a/packages/intake/zambdas/package.json b/packages/intake/zambdas/package.json index ebd5710cd..e596d3492 100644 --- a/packages/intake/zambdas/package.json +++ b/packages/intake/zambdas/package.json @@ -44,7 +44,8 @@ "esbuild": "^0.20.2", "i18next": "^23.11.1", "mixpanel": "^0.18.0", - "utils": "*" + "utils": "*", + "zambda-utils": "*" }, "devDependencies": { "@types/diacritics": "^1.3.3" diff --git a/packages/intake/zambdas/scripts/configure-zapehr-secrets.ts b/packages/intake/zambdas/scripts/configure-zapehr-secrets.ts index 0dca8cb02..37f160a84 100644 --- a/packages/intake/zambdas/scripts/configure-zapehr-secrets.ts +++ b/packages/intake/zambdas/scripts/configure-zapehr-secrets.ts @@ -1,7 +1,7 @@ import Oystehr from '@oystehr/sdk'; -import { getAccessToken } from '../src/shared/auth'; import fs from 'fs'; import { Secrets } from 'utils'; +import { getAuth0Token } from '../src/shared'; const projectApiUrlFromAuth0Audience = (auth0Audience: string): string => { switch (auth0Audience) { @@ -21,7 +21,7 @@ const projectApiUrlFromAuth0Audience = (auth0Audience: string): string => { }; const setupSecrets = async (config: Secrets): Promise => { - const token = await getAccessToken(config); + const token = await getAuth0Token(config); if (!token) { throw new Error('Failed to fetch auth token.'); diff --git a/packages/intake/zambdas/scripts/copy-uc-locations.ts b/packages/intake/zambdas/scripts/copy-uc-locations.ts index 2b66d6fa7..9e6d93e03 100644 --- a/packages/intake/zambdas/scripts/copy-uc-locations.ts +++ b/packages/intake/zambdas/scripts/copy-uc-locations.ts @@ -1,9 +1,9 @@ -import fs from 'fs'; -import { getAccessToken } from '../src/shared/auth'; -import { createOystehrClient } from '../src/shared/helpers'; -import { randomUUID } from 'crypto'; import { BatchInputPostRequest, BatchInputPutRequest } from '@oystehr/sdk'; +import { randomUUID } from 'crypto'; import { Location, Practitioner, PractitionerRole } from 'fhir/r4b'; +import fs from 'fs'; +import { getAuth0Token } from '../src/shared'; +import { createOystehrClient } from '../src/shared/helpers'; const directorsAreSame = (practitioner1: Practitioner, practitioner2: Practitioner | undefined): boolean => { if (!practitioner1 || !practitioner2) { @@ -69,8 +69,8 @@ const filterDirectorListForInclusion = (listToFilter: Practitioner[], sourceList }; const copyLocations = async (fromConfig: any, toConfig: any, isDryRun = true): Promise => { - const fromEnvToken = await getAccessToken(fromConfig); - const toEnvToken = await getAccessToken(toConfig); + const fromEnvToken = await getAuth0Token(fromConfig); + const toEnvToken = await getAuth0Token(toConfig); if (!fromEnvToken || !toEnvToken) { throw new Error('Failed to fetch auth token.'); diff --git a/packages/intake/zambdas/scripts/create-stub-zambda.ts b/packages/intake/zambdas/scripts/create-stub-zambda.ts index efeec1a77..5faca10ec 100644 --- a/packages/intake/zambdas/scripts/create-stub-zambda.ts +++ b/packages/intake/zambdas/scripts/create-stub-zambda.ts @@ -1,7 +1,7 @@ -import fs from 'fs'; import Oystehr, { ZambdaFunction } from '@oystehr/sdk'; -import { getAccessToken } from '../src/shared/auth'; +import fs from 'fs'; import { ZambdaTriggerType } from 'utils'; +import { getAuth0Token } from '../src/shared'; const projectApiUrlFromAuth0Audience = (auth0Audience: string): string => { switch (auth0Audience) { @@ -27,7 +27,7 @@ const stubsToWrite: { name: string; triggerMethod: ZambdaTriggerType }[] = [ ]; const writeStub = async (config: any): Promise => { - const token = await getAccessToken(config); + const token = await getAuth0Token(config); if (!token) { throw new Error('Failed to fetch auth token.'); diff --git a/packages/intake/zambdas/scripts/deploy-zambdas.ts b/packages/intake/zambdas/scripts/deploy-zambdas.ts index 4617dbc94..c3ac0c0e8 100644 --- a/packages/intake/zambdas/scripts/deploy-zambdas.ts +++ b/packages/intake/zambdas/scripts/deploy-zambdas.ts @@ -2,7 +2,7 @@ import Oystehr, { BatchInputDeleteRequest, BatchInputPostRequest } from '@oysteh import { Subscription } from 'fhir/r4b'; import fs from 'fs'; import { SubscriptionZambdaDetails, Task_Send_Messages_Url } from 'utils'; -import { getAccessToken } from '../src/shared/auth'; +import { getAuth0Token } from '../src/shared'; interface DeployZambda { type: 'http_open' | 'http_auth' | 'subscription' | 'cron'; @@ -228,7 +228,7 @@ const projectApiUrlFromAuth0Audience = (auth0Audience: string): string => { }; const updateZambdas = async (config: any, env: string): Promise => { - const token = await getAccessToken(config); + const token = await getAuth0Token(config); if (!token) { throw new Error('Failed to fetch auth token.'); diff --git a/packages/intake/zambdas/scripts/setup-default-locations.ts b/packages/intake/zambdas/scripts/setup-default-locations.ts index d6e699f3d..bf6e1c5f5 100644 --- a/packages/intake/zambdas/scripts/setup-default-locations.ts +++ b/packages/intake/zambdas/scripts/setup-default-locations.ts @@ -1,5 +1,4 @@ -import Oystehr from '@oystehr/sdk'; -import FhirClient from '@oystehr/sdk'; +import { default as FhirClient, default as Oystehr } from '@oystehr/sdk'; import { FhirResource, Location, Practitioner, Resource } from 'fhir/r4b'; import { allPhysicalLocations, @@ -15,7 +14,7 @@ import { TIMEZONE_EXTENSION_URL, VirtualLocationBody, } from 'utils'; -import { getAccessToken } from '../src/shared'; +import { getAuth0Token } from '../src/shared'; import { createOystehrClient } from '../src/shared/helpers'; export const checkLocations = async (fhirClient: FhirClient): Promise => { @@ -147,7 +146,7 @@ const createPhysicalLocation = async ( // Create Practitioners const createPractitionerForEligibilityCheck = async (config: any): Promise => { - const envToken = await getAccessToken(config); + const envToken = await getAuth0Token(config); const oystehr = await createOystehrClient(envToken, config); ELIGIBILITY_PRACTITIONER_TYPES.forEach(async (type) => { diff --git a/packages/intake/zambdas/scripts/setup-questionnaires.ts b/packages/intake/zambdas/scripts/setup-questionnaires.ts index d3c7da312..2c29ada3c 100644 --- a/packages/intake/zambdas/scripts/setup-questionnaires.ts +++ b/packages/intake/zambdas/scripts/setup-questionnaires.ts @@ -1,11 +1,11 @@ +import { BatchInputDeleteRequest, BatchInputPostRequest } from '@oystehr/sdk'; +import { Questionnaire } from 'fhir/r4b'; import fs from 'fs'; -import { getAccessToken } from '../src/shared/auth'; +import { getAuth0Token } from '../src/shared'; import { createOystehrClient } from '../src/shared/helpers'; -import { Questionnaire } from 'fhir/r4b'; -import { BatchInputPostRequest, BatchInputDeleteRequest } from '@oystehr/sdk'; const writeQuestionnaires = async (envConfig: any): Promise => { - const token = await getAccessToken(envConfig); + const token = await getAuth0Token(envConfig); if (!token) { throw new Error('Failed to fetch auth token.'); diff --git a/packages/intake/zambdas/scripts/update-permissions-for-users.ts b/packages/intake/zambdas/scripts/update-permissions-for-users.ts index bc917c0db..9137b7dc0 100644 --- a/packages/intake/zambdas/scripts/update-permissions-for-users.ts +++ b/packages/intake/zambdas/scripts/update-permissions-for-users.ts @@ -1,9 +1,9 @@ -import fetch from 'node-fetch'; -import { getAccessToken } from '../src/shared/auth'; import fs from 'fs'; +import fetch from 'node-fetch'; +import { getAuth0Token } from '../src/shared'; const updatePermissionsFromZambdaList = async (zambdaList: string[], config: any): Promise => { - const auth0Token = await getAccessToken(config); + const auth0Token = await getAuth0Token(config); if (auth0Token === null) { throw new Error('could not get Auth0 token'); } diff --git a/packages/intake/zambdas/src/appointment/get-past-visits/index.ts b/packages/intake/zambdas/src/appointment/get-past-visits/index.ts index 11d8ee311..09499ce55 100644 --- a/packages/intake/zambdas/src/appointment/get-past-visits/index.ts +++ b/packages/intake/zambdas/src/appointment/get-past-visits/index.ts @@ -1,21 +1,21 @@ import { APIGatewayProxyResult } from 'aws-lambda'; import { Appointment, Location, Patient } from 'fhir/r4b'; import { - GetPastVisitsResponse, - SecretsKeys, AppointmentInformationIntake, - ZambdaInput, + AppointmentStatus, + appointmentTypeMap, createOystehrClient, getParticipantIdFromAppointment, + GetPastVisitsResponse, getPatientsForUser, getSecret, - mapStatusToTelemed, - appointmentTypeMap, getVisitStatus, - AppointmentStatus, + mapStatusToTelemed, + SecretsKeys, + ZambdaInput, } from 'utils'; import { checkOrCreateM2MClientToken, getUser } from '../../shared'; -import { mapEncountersToAppointmentIds, getFhirResources } from './helpers'; +import { getFhirResources, mapEncountersToAppointmentIds } from './helpers'; import { validateRequestParameters } from './validateRequestParameters'; // Lifting up value to outside of the handler allows it to stay in memory across warm lambda invocations diff --git a/packages/intake/zambdas/src/appointment/get-visit-details/index.ts b/packages/intake/zambdas/src/appointment/get-visit-details/index.ts index dd19ee5bd..281fa9a1b 100644 --- a/packages/intake/zambdas/src/appointment/get-visit-details/index.ts +++ b/packages/intake/zambdas/src/appointment/get-visit-details/index.ts @@ -1,13 +1,7 @@ import { APIGatewayProxyResult } from 'aws-lambda'; -import { - createOystehrClient, - getEncounterForAppointment, - getSecret, - GetVisitDetailsResponse, - SecretsKeys, - ZambdaInput, -} from 'utils'; +import { createOystehrClient, getEncounterForAppointment, GetVisitDetailsResponse, ZambdaInput } from 'utils'; +import { getSecret, SecretsKeys } from 'utils'; import { checkOrCreateM2MClientToken } from '../../shared'; import { getMedications, getPaymentDataRequest, getPresignedURLs } from './helpers'; import { validateRequestParameters } from './validateRequestParameters'; diff --git a/packages/intake/zambdas/src/appointment/helpers.ts b/packages/intake/zambdas/src/appointment/helpers.ts index 96d17ad4d..0061b6497 100644 --- a/packages/intake/zambdas/src/appointment/helpers.ts +++ b/packages/intake/zambdas/src/appointment/helpers.ts @@ -1,12 +1,12 @@ import Oystehr from '@oystehr/sdk'; import { Coding, Extension, Questionnaire } from 'fhir/r4b'; import { + getSecret, OtherParticipantsExtension, Secrets, SecretsKeys, ServiceMode, TELEMED_VIDEO_ROOM_CODE, - getSecret, } from 'utils'; export const getCurrentQuestionnaireForServiceType = async ( diff --git a/packages/intake/zambdas/src/appointment/prebook-cancel-appointment/index.ts b/packages/intake/zambdas/src/appointment/prebook-cancel-appointment/index.ts index a43a133e2..5d6a02031 100644 --- a/packages/intake/zambdas/src/appointment/prebook-cancel-appointment/index.ts +++ b/packages/intake/zambdas/src/appointment/prebook-cancel-appointment/index.ts @@ -14,7 +14,6 @@ import { FHIR_ZAPEHR_URL, POST_TELEMED_APPOINTMENT_CANT_BE_CANCELED_ERROR, Secrets, - SecretsKeys, ZambdaInput, formatPhoneNumberDisplay, getAppointmentResourceById, @@ -23,18 +22,18 @@ import { getPatientContactEmail, getPatientFirstName, getRelatedPersonForPatient, - getSecret, isPostTelemedAppointment, topLevelCatch, } from 'utils'; -import { captureSentryException, configSentry, sendInPersonCancellationEmail } from '../../shared'; -import { getAccessToken, getUser } from '../../shared/auth'; +import { captureSentryException, configSentry, getAuth0Token, sendInPersonCancellationEmail } from '../../shared'; +import { getUser } from '../../shared/auth'; import { getEncounterDetails } from '../../shared/getEncounterDetails'; import { createOystehrClient, getLocationInformation } from '../../shared/helpers'; import { AuditableZambdaEndpoints, createAuditEvent } from '../../shared/userAuditLog'; import { validateBundleAndExtractAppointment } from '../../shared/validateBundleAndExtractAppointment'; import { validateRequestParameters } from './validateRequestParameters'; +import { SecretsKeys, getSecret } from 'utils'; export interface CancelAppointmentInput { appointmentID: string; cancellationReason: CancellationReasonOptionsInPerson; @@ -74,7 +73,7 @@ export const index = wrapHandler(async (input: ZambdaInput): Promise { currentCanonicalQuestionnaireUrl: string; diff --git a/packages/intake/zambdas/src/appointment/prebook-get-appointments/index.ts b/packages/intake/zambdas/src/appointment/prebook-get-appointments/index.ts index ed5347e91..f3d333139 100644 --- a/packages/intake/zambdas/src/appointment/prebook-get-appointments/index.ts +++ b/packages/intake/zambdas/src/appointment/prebook-get-appointments/index.ts @@ -1,20 +1,20 @@ -import '../../../instrument.mjs'; import { wrapHandler } from '@sentry/aws-serverless'; -import { captureSentryException, configSentry } from '../../shared'; import { APIGatewayProxyResult } from 'aws-lambda'; import { Encounter, Appointment as FhirAppointment, Location, Patient, QuestionnaireResponse, Slot } from 'fhir/r4b'; import { DateTime } from 'luxon'; import { - VisitStatusLabel, NO_READ_ACCESS_TO_PATIENT_ERROR, SLUG_SYSTEM, Secrets, + VisitStatusLabel, ZambdaInput, - getVisitStatus, getPatientsForUser, + getVisitStatus, topLevelCatch, } from 'utils'; -import { getAccessToken, getUser } from '../../shared/auth'; +import '../../../instrument.mjs'; +import { captureSentryException, configSentry, getAuth0Token } from '../../shared'; +import { getUser } from '../../shared/auth'; import { checkPaperworkComplete, createOystehrClient } from '../../shared/helpers'; import { validateRequestParameters } from './validateRequestParameters'; @@ -55,7 +55,7 @@ export const index = wrapHandler(async (input: ZambdaInput): Promise if (!zapehrToken) { console.log('getting m2m token for service calls'); - zapehrToken = await getM2MClientToken(input.secrets); + zapehrToken = await getAuth0Token(input.secrets); } else { console.log('already have a token, no need to update'); } diff --git a/packages/intake/zambdas/src/check-in/index.ts b/packages/intake/zambdas/src/check-in/index.ts index acd3aa23d..3c1548ff0 100644 --- a/packages/intake/zambdas/src/check-in/index.ts +++ b/packages/intake/zambdas/src/check-in/index.ts @@ -11,13 +11,13 @@ import { getPatchBinary, getTaskResource, Secrets, - topLevelCatch, TaskIndicator, + topLevelCatch, ZambdaInput, } from 'utils'; import '../../instrument.mjs'; -import { captureSentryException, configSentry } from '../shared'; -import { getAccessToken, getUser } from '../shared/auth'; +import { captureSentryException, configSentry, getAuth0Token } from '../shared'; +import { getUser } from '../shared/auth'; import { checkPaperworkComplete, createOystehrClient, @@ -54,7 +54,7 @@ export const index = wrapHandler(async (input: ZambdaInput): Promise const getOptionsInput = validateInput(input); console.log('get options input:', getOptionsInput); - console.group('getM2MClientToken'); + console.group('getAuth0Token'); if (!zapehrToken) { console.log('getting token'); - zapehrToken = await getM2MClientToken(secrets); + zapehrToken = await getAuth0Token(secrets); } else { console.log('already have token'); } console.groupEnd(); - console.debug('getM2MClientToken success'); + console.debug('getAuth0Token success'); console.group('createOystehrClient'); const oystehr = createOystehrClient( diff --git a/packages/intake/zambdas/src/get-appointment-details/index.ts b/packages/intake/zambdas/src/get-appointment-details/index.ts index ed2526490..0c2251350 100644 --- a/packages/intake/zambdas/src/get-appointment-details/index.ts +++ b/packages/intake/zambdas/src/get-appointment-details/index.ts @@ -1,23 +1,22 @@ -import '../../instrument.mjs'; import { wrapHandler } from '@sentry/aws-serverless'; -import { captureSentryException, configSentry } from '../shared'; import { APIGatewayProxyResult } from 'aws-lambda'; -import { validateRequestParameters } from './validateRequestParameters'; -import { createOystehrClient, getLocationInformation } from '../shared/helpers'; -import { Appointment as FhirAppointment, FhirResource, HealthcareService, Practitioner, Location } from 'fhir/r4b'; -import { getAccessToken } from '../shared/auth'; +import { Appointment as FhirAppointment, FhirResource, HealthcareService, Location, Practitioner } from 'fhir/r4b'; +import { DateTime } from 'luxon'; import { - Secrets, - ZambdaInput, - topLevelCatch, - AvailableLocationInformation, APPOINTMENT_NOT_FOUND_ERROR, + AvailableLocationInformation, SCHEDULE_NOT_FOUND_ERROR, - SecretsKeys, - getSecret, + Secrets, + ZambdaInput, getAvailableSlotsForSchedule, + topLevelCatch, } from 'utils'; -import { DateTime } from 'luxon'; +import '../../instrument.mjs'; + +import { SecretsKeys, getSecret } from 'utils'; +import { captureSentryException, configSentry, getAuth0Token } from '../shared'; +import { createOystehrClient, getLocationInformation } from '../shared/helpers'; +import { validateRequestParameters } from './validateRequestParameters'; export interface GetAppointmentDetailInput { appointmentID: string; @@ -56,7 +55,7 @@ export const index = wrapHandler(async (input: ZambdaInput): Promise if (!zapehrToken) { console.log('getting token'); - zapehrToken = await getM2MClientToken(secrets); + zapehrToken = await getAuth0Token(secrets); } else { console.log('already have token'); } diff --git a/packages/intake/zambdas/src/get-patients/index.ts b/packages/intake/zambdas/src/get-patients/index.ts index 27b98b30a..1637e7e1a 100644 --- a/packages/intake/zambdas/src/get-patients/index.ts +++ b/packages/intake/zambdas/src/get-patients/index.ts @@ -1,9 +1,8 @@ -import '../../instrument.mjs'; import { wrapHandler } from '@sentry/aws-serverless'; -import { captureSentryException, configSentry } from '../shared'; import { APIGatewayProxyResult } from 'aws-lambda'; import { PatientInfo, Secrets, ZambdaInput, getPatientsForUser, topLevelCatch } from 'utils'; -import { getAccessToken } from '../shared'; +import '../../instrument.mjs'; +import { captureSentryException, configSentry, getAuth0Token } from '../shared'; import { getUser } from '../shared/auth'; import { createOystehrClient } from '../shared/helpers'; import { validateRequestParameters } from './validateRequestParameters'; @@ -27,7 +26,7 @@ export const index = wrapHandler(async (input: ZambdaInput): Promise => { @@ -20,7 +20,7 @@ export const index = async (input: ZambdaInput): Promise if (!zapehrToken) { console.log('getting m2m token for service calls'); - zapehrToken = await getM2MClientToken(input.secrets); + zapehrToken = await getAuth0Token(input.secrets); } else { console.log('already have a token, no need to update'); } diff --git a/packages/intake/zambdas/src/get-wait-status/index.ts b/packages/intake/zambdas/src/get-wait-status/index.ts index 0ebc3c920..40c2e5d33 100644 --- a/packages/intake/zambdas/src/get-wait-status/index.ts +++ b/packages/intake/zambdas/src/get-wait-status/index.ts @@ -12,7 +12,7 @@ import { getSecret, mapStatusToTelemed, } from 'utils'; -import { getM2MClientToken } from '../shared'; +import { getAuth0Token } from '../shared'; import { estimatedTimeStatesGroups } from '../shared/appointment/constants'; import { getUser } from '../shared/auth'; import { getVideoEncounterForAppointment } from '../shared/encounters'; @@ -69,7 +69,7 @@ export const index = async (input: ZambdaInput): Promise if (!zapehrToken) { console.log('getting m2m token for service calls'); - zapehrToken = await getM2MClientToken(secrets); // keeping token externally for reuse + zapehrToken = await getAuth0Token(secrets); // keeping token externally for reuse } else { console.log('already have a token, no need to update'); // TODO: wonder if we need to check if it's expired at some point? diff --git a/packages/intake/zambdas/src/join-call/index.ts b/packages/intake/zambdas/src/join-call/index.ts index 199f24b42..903bfc760 100644 --- a/packages/intake/zambdas/src/join-call/index.ts +++ b/packages/intake/zambdas/src/join-call/index.ts @@ -23,7 +23,7 @@ import { userHasAccessToPatient, } from 'utils'; import { - getM2MClientToken, + getAuth0Token, getUser, getVideoEncounterForAppointment, searchInvitedParticipantResourcesByEncounterId, @@ -86,7 +86,7 @@ export const index = async (input: ZambdaInput): Promise if (!zapehrToken) { console.log('getting m2m token for service calls'); - zapehrToken = await getM2MClientToken(secrets); // keeping token externally for reuse + zapehrToken = await getAuth0Token(secrets); // keeping token externally for reuse } else { console.log('already have a token, no need to update'); } diff --git a/packages/intake/zambdas/src/paperwork/get-paperwork/index.ts b/packages/intake/zambdas/src/paperwork/get-paperwork/index.ts index a976e25ee..307eab0ae 100644 --- a/packages/intake/zambdas/src/paperwork/get-paperwork/index.ts +++ b/packages/intake/zambdas/src/paperwork/get-paperwork/index.ts @@ -20,6 +20,7 @@ import { PaperworkSupportingInfo, PersonSex, SLUG_SYSTEM, + ScheduleType, Secrets, ServiceMode, UCGetPaperworkResponse, @@ -34,10 +35,10 @@ import { serviceModeForHealthcareService, topLevelCatch, userHasAccessToPatient, - ScheduleType, } from 'utils'; import '../../../instrument.mjs'; -import { getM2MClientToken, getUser } from '../../shared/auth'; +import { getAuth0Token } from '../../shared'; +import { getUser } from '../../shared/auth'; import { createOystehrClient, getOtherOfficesForLocation } from '../../shared/helpers'; import { validateRequestParameters } from './validateRequestParameters'; @@ -76,7 +77,7 @@ export const index = wrapHandler(async (input: ZambdaInput): Promise if (!zapehrM2MClientToken) { console.log('getting m2m token for service calls'); - zapehrM2MClientToken = await getM2MClientToken(secrets); // keeping token externally for reuse + zapehrM2MClientToken = await getAuth0Token(secrets); // keeping token externally for reuse } else { console.log('already have a token, no need to update'); } diff --git a/packages/intake/zambdas/src/payment-methods/list/index.ts b/packages/intake/zambdas/src/payment-methods/list/index.ts index 3c4a02343..ca6943bca 100644 --- a/packages/intake/zambdas/src/payment-methods/list/index.ts +++ b/packages/intake/zambdas/src/payment-methods/list/index.ts @@ -1,7 +1,7 @@ import { User } from '@oystehr/sdk'; import { APIGatewayProxyResult } from 'aws-lambda'; -import { ZambdaInput, lambdaResponse, getSecret, SecretsKeys } from 'utils'; -import { getM2MClientToken, getUser } from '../../shared'; +import { SecretsKeys, ZambdaInput, getSecret, lambdaResponse } from 'utils'; +import { getAuth0Token, getUser } from '../../shared'; import { postPaymentMethodListRequest } from '../helpers'; import { validateRequestParameters } from './validateRequestParameters'; @@ -40,7 +40,7 @@ export const index = async (input: ZambdaInput): Promise if (!zapehrM2MClientToken) { console.log('getting m2m token for service calls'); - zapehrM2MClientToken = await getM2MClientToken(secrets); // keeping token externally for reuse + zapehrM2MClientToken = await getAuth0Token(secrets); // keeping token externally for reuse } else { console.log('already have a token, no need to update'); } diff --git a/packages/intake/zambdas/src/payment-methods/set-default/index.ts b/packages/intake/zambdas/src/payment-methods/set-default/index.ts index 6b30d7998..aac833029 100644 --- a/packages/intake/zambdas/src/payment-methods/set-default/index.ts +++ b/packages/intake/zambdas/src/payment-methods/set-default/index.ts @@ -1,7 +1,7 @@ import { User } from '@oystehr/sdk'; import { APIGatewayProxyResult } from 'aws-lambda'; -import { ZambdaInput, lambdaResponse, getSecret, SecretsKeys } from 'utils'; -import { getM2MClientToken, getUser } from '../../shared'; +import { SecretsKeys, ZambdaInput, getSecret, lambdaResponse } from 'utils'; +import { getAuth0Token, getUser } from '../../shared'; import { postPaymentMethodSetDefaultRequest } from '../helpers'; import { validateRequestParameters } from './validateRequestParameters'; @@ -41,7 +41,7 @@ export const index = async (input: ZambdaInput): Promise if (!zapehrM2MClientToken) { console.log('getting m2m token for service calls'); - zapehrM2MClientToken = await getM2MClientToken(secrets); // keeping token externally for reuse + zapehrM2MClientToken = await getAuth0Token(secrets); // keeping token externally for reuse } else { console.log('already have a token, no need to update'); } diff --git a/packages/intake/zambdas/src/payment-methods/setup/index.ts b/packages/intake/zambdas/src/payment-methods/setup/index.ts index 155d0d489..ad8b9f408 100644 --- a/packages/intake/zambdas/src/payment-methods/setup/index.ts +++ b/packages/intake/zambdas/src/payment-methods/setup/index.ts @@ -1,7 +1,7 @@ import { User } from '@oystehr/sdk'; import { APIGatewayProxyResult } from 'aws-lambda'; -import { ZambdaInput, lambdaResponse, getSecret, SecretsKeys } from 'utils'; -import { getM2MClientToken, getUser } from '../../shared'; +import { SecretsKeys, ZambdaInput, getSecret, lambdaResponse } from 'utils'; +import { getAuth0Token, getUser } from '../../shared'; import { postPaymentMethodSetupRequest } from '../helpers'; import { validateRequestParameters } from './validateRequestParameters'; @@ -41,7 +41,7 @@ export const index = async (input: ZambdaInput): Promise if (!zapehrM2MClientToken) { console.log('getting m2m token for service calls'); - zapehrM2MClientToken = await getM2MClientToken(secrets); // keeping token externally for reuse + zapehrM2MClientToken = await getAuth0Token(secrets); // keeping token externally for reuse } else { console.log('already have a token, no need to update'); } diff --git a/packages/intake/zambdas/src/send-message-cron/index.ts b/packages/intake/zambdas/src/send-message-cron/index.ts index d6efc489f..3faaae66c 100644 --- a/packages/intake/zambdas/src/send-message-cron/index.ts +++ b/packages/intake/zambdas/src/send-message-cron/index.ts @@ -3,9 +3,9 @@ import { wrapHandler } from '@sentry/aws-serverless'; import { APIGatewayProxyResult } from 'aws-lambda'; import { Appointment, Encounter, Location, Patient, QuestionnaireResponse } from 'fhir/r4b'; import { DateTime } from 'luxon'; -import { DATETIME_FULL_NO_YEAR, getSecret, Secrets, SecretsKeys, topLevelCatch, ZambdaInput } from 'utils'; +import { DATETIME_FULL_NO_YEAR, Secrets, SecretsKeys, ZambdaInput, getSecret, topLevelCatch } from 'utils'; import '../../instrument.mjs'; -import { captureSentryException, configSentry, getAccessToken } from '../shared'; +import { captureSentryException, configSentry, getAuth0Token } from '../shared'; import { getMessageRecipientForAppointment } from '../shared/communication'; import { createOystehrClient } from '../shared/helpers'; @@ -16,7 +16,7 @@ export const index = wrapHandler(async (input: ZambdaInput): Promise { @@ -38,28 +39,10 @@ export async function getPersonForPatient(patientID: string, oystehr: Oystehr): export type AuthType = 'regular'; -export async function getAccessToken(secrets: Secrets | null): Promise { - const clientIdKey = SecretsKeys.AUTH0_CLIENT; - const secretIdKey = SecretsKeys.AUTH0_SECRET; - - return getAuth0Token({ secretIdKey, clientIdKey, secrets }); -} - -export async function getM2MClientToken(secrets: Secrets | null): Promise { - const clientIdKey = SecretsKeys.AUTH0_CLIENT; - const secretIdKey = SecretsKeys.AUTH0_SECRET; - - return getAuth0Token({ - clientIdKey, - secretIdKey, - secrets, - }); -} - export async function checkOrCreateM2MClientToken(token: string, secrets: Secrets | null): Promise { if (!token) { console.log('getting token'); - return await getM2MClientToken(secrets); + return await getAuth0Token(secrets); } else { console.log('already have token'); return token; diff --git a/packages/utils/lib/auth/getAuth0Token.ts b/packages/intake/zambdas/src/shared/getAuth0Token.ts similarity index 52% rename from packages/utils/lib/auth/getAuth0Token.ts rename to packages/intake/zambdas/src/shared/getAuth0Token.ts index d60c2e8de..01f13f108 100644 --- a/packages/utils/lib/auth/getAuth0Token.ts +++ b/packages/intake/zambdas/src/shared/getAuth0Token.ts @@ -1,41 +1,31 @@ -import axios from 'axios'; -import { Secrets, getSecret, SecretsKeys } from 'utils'; - -export interface GetAuthTokenInput { - clientIdKey: SecretsKeys; - secretIdKey: SecretsKeys; - secrets: Secrets | null; -} - -// Throws if it can't get a token because this is a fatal error -export async function getAuth0Token(input: GetAuthTokenInput): Promise { - const { clientIdKey, secretIdKey, secrets } = input; +import fetch from 'node-fetch'; +import { getSecret, Secrets, SecretsKeys } from 'utils'; +export async function getAuth0Token(secrets: Secrets | null): Promise { const AUTH0_ENDPOINT = getSecret(SecretsKeys.AUTH0_ENDPOINT, secrets); + const AUTH0_CLIENT = getSecret(SecretsKeys.AUTH0_CLIENT, secrets); + const AUTH0_SECRET = getSecret(SecretsKeys.AUTH0_SECRET, secrets); const AUTH0_AUDIENCE = getSecret(SecretsKeys.AUTH0_AUDIENCE, secrets); - const AUTH0_CLIENT = getSecret(clientIdKey, secrets); - const AUTH0_SECRET = getSecret(secretIdKey, secrets); console.group(`Fetch from ${AUTH0_ENDPOINT}`); - return await axios({ - url: AUTH0_ENDPOINT, - method: 'post', + return await fetch(AUTH0_ENDPOINT, { + method: 'POST', headers: { 'content-type': 'application/json', }, - data: { + body: JSON.stringify({ grant_type: 'client_credentials', client_id: AUTH0_CLIENT, client_secret: AUTH0_SECRET, audience: AUTH0_AUDIENCE, - }, + }), }) .then((response: any) => { - if (response.statusText != 'OK') { + if (!response.ok) { console.error('response issue', response); throw new Error(response); } console.log('Got a response from auth0'); - return response.data; + return response.json(); }) .then((response: any) => { console.groupEnd(); @@ -43,7 +33,7 @@ export async function getAuth0Token(input: GetAuthTokenInput): Promise { return response.access_token; }) .catch((error: any) => { - console.error('error', JSON.stringify(error)); + console.error('error', error); throw new Error(error.message); }); } diff --git a/packages/intake/zambdas/src/shared/helpers.ts b/packages/intake/zambdas/src/shared/helpers.ts index 81e8b0a11..ff124bb24 100644 --- a/packages/intake/zambdas/src/shared/helpers.ts +++ b/packages/intake/zambdas/src/shared/helpers.ts @@ -18,10 +18,10 @@ import { HOURS_OF_OPERATION_FORMAT, OVERRIDE_DATE_FORMAT, pickFirstValueFromAnswerItem, + ScheduleType, Secrets, SecretsKeys, SLUG_SYSTEM, - ScheduleType, } from 'utils'; export function createOystehrClient(token: string, secrets: Secrets | null): Oystehr { diff --git a/packages/intake/zambdas/src/shared/index.ts b/packages/intake/zambdas/src/shared/index.ts index bf437fc65..aff716155 100644 --- a/packages/intake/zambdas/src/shared/index.ts +++ b/packages/intake/zambdas/src/shared/index.ts @@ -1,9 +1,10 @@ -export * from './auth'; -export * from './validation'; -export * from './sentry'; export * from './audit'; +export * from './auth'; export * from './communication'; -export * from './encounters'; -export * from './insurances'; export * from './coverage'; +export * from './encounters'; export * from './fhir'; +export * from './getAuth0Token'; +export * from './insurances'; +export * from './sentry'; +export * from './validation'; diff --git a/packages/intake/zambdas/src/shared/secrets.ts b/packages/intake/zambdas/src/shared/secrets.ts deleted file mode 100644 index fecec9c29..000000000 --- a/packages/intake/zambdas/src/shared/secrets.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { Secrets } from 'utils'; - -// Throws if secret could not be found -export const getSecret = (secretKey: string, secrets: Secrets | null): string => { - let value: string | undefined; - if (secrets != null) { - value = secrets[secretKey]; - } else { - value = process.env[secretKey]; - } - - if (value == null) { - throw new Error(`Secret or Environment Variable with key ${secretKey} was not set.`); - } - - return value; -}; - -export enum SecretsKeys { - AUTH0_ENDPOINT = 'AUTH0_ENDPOINT', - AUTH0_CLIENT = 'AUTH0_CLIENT', - AUTH0_SECRET = 'AUTH0_SECRET', - AUTH0_AUDIENCE = 'AUTH0_AUDIENCE', - FHIR_API = 'FHIR_API', - PROJECT_API = 'PROJECT_API', - ENVIRONMENT = 'ENVIRONMENT', - SENDGRID_API_KEY = 'SENDGRID_API_KEY', - SENDGRID_EMAIL_BCC = 'SENDGRID_EMAIL_BCC', - IN_PERSON_SENDGRID_CONFIRMATION_EMAIL_TEMPLATE_ID = 'IN_PERSON_SENDGRID_CONFIRMATION_EMAIL_TEMPLATE_ID', - IN_PERSON_SENDGRID_SPANISH_CONFIRMATION_EMAIL_TEMPLATE_ID = 'IN_PERSON_SENDGRID_SPANISH_CONFIRMATION_EMAIL_TEMPLATE_ID', - IN_PERSON_SENDGRID_CANCELLATION_EMAIL_TEMPLATE_ID = 'IN_PERSON_SENDGRID_CANCELLATION_EMAIL_TEMPLATE_ID', - IN_PERSON_SENDGRID_SPANISH_CANCELLATION_EMAIL_TEMPLATE_ID = 'IN_PERSON_SENDGRID_SPANISH_CANCELLATION_EMAIL_TEMPLATE_ID', - IN_PERSON_SENDGRID_ERROR_EMAIL_TEMPLATE_ID = 'IN_PERSON_SENDGRID_ERROR_EMAIL_TEMPLATE_ID', - ORGANIZATION_ID = 'ORGANIZATION_ID', - WEBSITE_URL = 'WEBSITE_URL', -} diff --git a/packages/intake/zambdas/src/shared/userAuditLog.ts b/packages/intake/zambdas/src/shared/userAuditLog.ts index f8626d9d2..b981dcf7d 100644 --- a/packages/intake/zambdas/src/shared/userAuditLog.ts +++ b/packages/intake/zambdas/src/shared/userAuditLog.ts @@ -1,7 +1,7 @@ import Oystehr from '@oystehr/sdk'; import { AuditEvent } from 'fhir/r4b'; import { DateTime } from 'luxon'; -import { Secrets, SecretsKeys, getSecret, ZambdaInput } from 'utils'; +import { Secrets, SecretsKeys, ZambdaInput, getSecret } from 'utils'; export enum AuditableZambdaEndpoints { appointmentCancel = 'cancel-appointment', diff --git a/packages/intake/zambdas/src/subscriptions/questionnaire-response/sub-intake-harvest/helpers.ts b/packages/intake/zambdas/src/subscriptions/questionnaire-response/sub-intake-harvest/helpers.ts index e7702e206..806af1e3c 100644 --- a/packages/intake/zambdas/src/subscriptions/questionnaire-response/sub-intake-harvest/helpers.ts +++ b/packages/intake/zambdas/src/subscriptions/questionnaire-response/sub-intake-harvest/helpers.ts @@ -24,6 +24,7 @@ import { codingsEqual, CONSENT_CODE, ConsentSigner, + consolidateOperations, ContactTelecomConfig, coverageFieldPaths, createConsentResource, @@ -65,6 +66,7 @@ import { PHOTO_ID_FRONT_ID, PRACTICE_NAME_URL, PRIVATE_EXTENSION_BASE_URL, + RELATED_PERSON_SAME_AS_PATIENT_ADDRESS_URL, relatedPersonFieldPaths, SCHOOL_WORK_NOTE_SCHOOL_ID, SCHOOL_WORK_NOTE_TEMPLATE_CODE, @@ -73,8 +75,6 @@ import { SecretsKeys, SUBSCRIBER_RELATIONSHIP_CODE_MAP, uploadPDF, - consolidateOperations, - RELATED_PERSON_SAME_AS_PATIENT_ADDRESS_URL, } from 'utils'; import { v4 as uuid } from 'uuid'; import { createOrUpdateFlags } from '../../../paperwork/sharedHelpers'; diff --git a/packages/intake/zambdas/src/subscriptions/questionnaire-response/sub-intake-harvest/index.ts b/packages/intake/zambdas/src/subscriptions/questionnaire-response/sub-intake-harvest/index.ts index c14c61b85..b3ab06110 100644 --- a/packages/intake/zambdas/src/subscriptions/questionnaire-response/sub-intake-harvest/index.ts +++ b/packages/intake/zambdas/src/subscriptions/questionnaire-response/sub-intake-harvest/index.ts @@ -23,17 +23,17 @@ import { ZambdaInput, } from 'utils'; import '../../../../instrument.mjs'; -import { captureSentryException, configSentry, getAccessToken } from '../../../shared'; +import { captureSentryException, configSentry, getAuth0Token } from '../../../shared'; import { createOystehrClient } from '../../../shared/helpers'; import { createConflictResolutionTask, createConsentResources, createDocumentResources, + createInsuranceResources, createMasterRecordPatchOperations, flagPaperworkEdit, hasConflictingUpdates, PatientMasterRecordResources, - createInsuranceResources, searchInsuranceInformation, } from './helpers'; import { validateRequestParameters } from './validateRequestParameters'; @@ -54,7 +54,7 @@ export const index = wrapHandler(async (input: ZambdaInput): Promise { const ref = task.focus?.reference; diff --git a/packages/intake/zambdas/src/subscriptions/task/sub-cancellation-email/index.ts b/packages/intake/zambdas/src/subscriptions/task/sub-cancellation-email/index.ts index f2411316c..d6dd03f42 100644 --- a/packages/intake/zambdas/src/subscriptions/task/sub-cancellation-email/index.ts +++ b/packages/intake/zambdas/src/subscriptions/task/sub-cancellation-email/index.ts @@ -4,7 +4,7 @@ import { Appointment, Location, Patient, Task } from 'fhir/r4b'; import { DateTime } from 'luxon'; import { DATETIME_FULL_NO_YEAR, Secrets, TaskStatus, ZambdaInput, getPatientContactEmail, topLevelCatch } from 'utils'; import '../../../../instrument.mjs'; -import { captureSentryException, configSentry, getAccessToken, sendInPersonCancellationEmail } from '../../../shared'; +import { captureSentryException, configSentry, getAuth0Token, sendInPersonCancellationEmail } from '../../../shared'; import { createOystehrClient } from '../../../shared/helpers'; import { validateRequestParameters } from '../validateRequestParameters'; @@ -28,7 +28,7 @@ export const index = wrapHandler(async (input: ZambdaInput): Promise if (!zapehrToken) { console.log('getting token'); - zapehrToken = await getM2MClientToken(secrets); + zapehrToken = await getAuth0Token(secrets); } else { console.log('already have token'); } diff --git a/packages/intake/zambdas/src/video-chat-invites/cancel-invite/index.ts b/packages/intake/zambdas/src/video-chat-invites/cancel-invite/index.ts index b45fe75a7..b802d3811 100644 --- a/packages/intake/zambdas/src/video-chat-invites/cancel-invite/index.ts +++ b/packages/intake/zambdas/src/video-chat-invites/cancel-invite/index.ts @@ -12,7 +12,7 @@ import { lambdaResponse, } from 'utils'; import { - getM2MClientToken, + getAuth0Token, getUser, getVideoEncounterForAppointment, searchInvitedParticipantResourcesByEncounterId, @@ -55,7 +55,7 @@ export const index = async (input: ZambdaInput): Promise if (!zapehrToken) { console.log('getting m2m token for service calls'); - zapehrToken = await getM2MClientToken(secrets); // keeping token externally for reuse + zapehrToken = await getAuth0Token(secrets); // keeping token externally for reuse } else { console.log('already have a token, no need to update'); } diff --git a/packages/intake/zambdas/src/video-chat-invites/create-invite/index.ts b/packages/intake/zambdas/src/video-chat-invites/create-invite/index.ts index 04e02c26c..2eeeec580 100644 --- a/packages/intake/zambdas/src/video-chat-invites/create-invite/index.ts +++ b/packages/intake/zambdas/src/video-chat-invites/create-invite/index.ts @@ -16,7 +16,7 @@ import { lambdaResponse, } from 'utils'; import { - getM2MClientToken, + getAuth0Token, getUser, getVideoEncounterForAppointment, sendSms, @@ -62,7 +62,7 @@ export const index = async (input: ZambdaInput): Promise if (!zapehrToken) { console.log('getting m2m token for service calls'); - zapehrToken = await getM2MClientToken(secrets); // keeping token externally for reuse + zapehrToken = await getAuth0Token(secrets); // keeping token externally for reuse } else { console.log('already have a token, no need to update'); } diff --git a/packages/intake/zambdas/src/video-chat-invites/list-invites/index.ts b/packages/intake/zambdas/src/video-chat-invites/list-invites/index.ts index 5ac2207ed..5a645bcee 100644 --- a/packages/intake/zambdas/src/video-chat-invites/list-invites/index.ts +++ b/packages/intake/zambdas/src/video-chat-invites/list-invites/index.ts @@ -3,9 +3,9 @@ import { APIGatewayProxyResult } from 'aws-lambda'; import { Appointment } from 'fhir/r4b'; import { JSONPath } from 'jsonpath-plus'; import { - SecretsKeys, ListInvitedParticipantsInput, ListInvitedParticipantsResponse, + SecretsKeys, ZambdaInput, createOystehrClient, getAppointmentResourceById, @@ -13,7 +13,7 @@ import { lambdaResponse, } from 'utils'; import { - getM2MClientToken, + getAuth0Token, getUser, getVideoEncounterForAppointment, searchInvitedParticipantResourcesByEncounterId, @@ -56,7 +56,7 @@ export const index = async (input: ZambdaInput): Promise if (!zapehrToken) { console.log('getting m2m token for service calls'); - zapehrToken = await getM2MClientToken(secrets); // keeping token externally for reuse + zapehrToken = await getAuth0Token(secrets); // keeping token externally for reuse } else { console.log('already have a token, no need to update'); } diff --git a/packages/intake/zambdas/tests/appointment.test.ts b/packages/intake/zambdas/tests/appointment.test.ts index 4c805e0b8..1fda99a58 100644 --- a/packages/intake/zambdas/tests/appointment.test.ts +++ b/packages/intake/zambdas/tests/appointment.test.ts @@ -1,7 +1,7 @@ import Oystehr from '@oystehr/sdk'; import { Appointment } from 'fhir/r4b'; import { AUTH0_AUDIENCE, AUTH0_CLIENT, AUTH0_ENDPOINT, AUTH0_SECRET, FHIR_API, PROJECT_API } from '../.env/local.json'; -import { getAccessToken } from '../src/shared'; +import { getAuth0Token } from '../src/shared'; import { contact, healthcareContacts, patient } from './appointment-validation.test'; export const DEFAULT_TEST_TIMEOUT = 100000; export const location = '71bc5925-65d6-471f-abd0-be357043172a'; @@ -11,7 +11,7 @@ describe('appointments tests', () => { jest.setTimeout(DEFAULT_TEST_TIMEOUT); beforeAll(async () => { - token = await getAccessToken({ + token = await getAuth0Token({ AUTH0_ENDPOINT: AUTH0_ENDPOINT, AUTH0_CLIENT: AUTH0_CLIENT, AUTH0_SECRET: AUTH0_SECRET, diff --git a/packages/intake/zambdas/tests/paperwork.test.ts b/packages/intake/zambdas/tests/paperwork.test.ts index 73396edee..13cc6a520 100644 --- a/packages/intake/zambdas/tests/paperwork.test.ts +++ b/packages/intake/zambdas/tests/paperwork.test.ts @@ -1,7 +1,7 @@ import Oystehr from '@oystehr/sdk'; import { Account, Consent, Coverage, RelatedPerson } from 'fhir/r4b'; -import { AUTH0_AUDIENCE, AUTH0_CLIENT, AUTH0_ENDPOINT, AUTH0_SECRET, PROJECT_API, FHIR_API } from '../.env/local.json'; -import { getAccessToken } from '../src/shared'; +import { AUTH0_AUDIENCE, AUTH0_CLIENT, AUTH0_ENDPOINT, AUTH0_SECRET, FHIR_API, PROJECT_API } from '../.env/local.json'; +import { getAuth0Token } from '../src/shared'; export const insuranceData = { additionalInfo: '', @@ -52,7 +52,7 @@ describe('paperwork tests', () => { let token = null; jest.setTimeout(DEFAULT_TEST_TIMEOUT); beforeAll(async () => { - token = await getAccessToken({ + token = await getAuth0Token({ AUTH0_ENDPOINT: AUTH0_ENDPOINT, AUTH0_CLIENT: AUTH0_CLIENT, AUTH0_SECRET: AUTH0_SECRET, diff --git a/packages/intake/zambdas/tests/qr-filter.test.ts b/packages/intake/zambdas/tests/qr-filter.test.ts index d87b92d23..15d0986fe 100644 --- a/packages/intake/zambdas/tests/qr-filter.test.ts +++ b/packages/intake/zambdas/tests/qr-filter.test.ts @@ -1,13 +1,13 @@ +import { IntakeQuestionnaireItem, getQuestionnaireItemsAndProgress, recursiveGroupTransform } from 'utils'; import { - FHIR_API, - AUTH0_ENDPOINT, + AUTH0_AUDIENCE, AUTH0_CLIENT, + AUTH0_ENDPOINT, AUTH0_SECRET, - AUTH0_AUDIENCE, + FHIR_API, IN_PERSON_PREVISIT_QUESTIONNAIRE, } from '../.env/local.json'; -import { IntakeQuestionnaireItem, getQuestionnaireItemsAndProgress, recursiveGroupTransform } from 'utils'; -import { getAccessToken } from '../src/shared'; +import { getAuth0Token } from '../src/shared'; import { createOystehrClient } from '../src/shared/helpers'; import QRData from './data/quetionnaire-responses.json'; @@ -28,7 +28,7 @@ describe('qr recursive filter validation tests', () => { jest.setTimeout(100000); beforeAll(async () => { - const token = await getAccessToken(SECRETS); + const token = await getAuth0Token(SECRETS); const oystehr = createOystehrClient(token, SECRETS); // get paperwork questions and validation schema diff --git a/packages/intake/zambdas/tests/questionnaire-validation.test.ts b/packages/intake/zambdas/tests/questionnaire-validation.test.ts index 7721deaa8..b49d25e19 100644 --- a/packages/intake/zambdas/tests/questionnaire-validation.test.ts +++ b/packages/intake/zambdas/tests/questionnaire-validation.test.ts @@ -1,15 +1,15 @@ +import { IntakeQuestionnaireItem, getQuestionnaireItemsAndProgress, makeValidationSchema } from 'utils'; +import { AnyObjectSchema, AnySchema } from 'yup'; import { - FHIR_API, - AUTH0_ENDPOINT, + AUTH0_AUDIENCE, AUTH0_CLIENT, + AUTH0_ENDPOINT, AUTH0_SECRET, - AUTH0_AUDIENCE, + FHIR_API, IN_PERSON_PREVISIT_QUESTIONNAIRE, } from '../.env/local.json'; -import { IntakeQuestionnaireItem, getQuestionnaireItemsAndProgress, makeValidationSchema } from 'utils'; -import { getAccessToken } from '../src/shared'; +import { getAuth0Token } from '../src/shared'; import { createOystehrClient } from '../src/shared/helpers'; -import { AnyObjectSchema, AnySchema } from 'yup'; import QRData from './data/quetionnaire-responses.json'; // import { QuestionnaireResponseItem, QuestionnaireResponseItemAnswer } from 'fhir/r4b'; @@ -217,7 +217,7 @@ describe('qr page validation tests', () => { jest.setTimeout(100000); beforeAll(async () => { - const token = await getAccessToken(SECRETS); + const token = await getAuth0Token(SECRETS); const oystehr = createOystehrClient(token, SECRETS); // get paperwork questions @@ -317,7 +317,7 @@ describe('full qr validation tests', () => { jest.setTimeout(100000); beforeAll(async () => { - const token = await getAccessToken(SECRETS); + const token = await getAuth0Token(SECRETS); const oystehr = createOystehrClient(token, SECRETS); // get paperwork questions and validation schema @@ -390,7 +390,7 @@ describe('QR item type tests', () => { jest.setTimeout(100000); beforeAll(async () => { - const token = await getAccessToken(SECRETS); + const token = await getAuth0Token(SECRETS); const oystehr = createOystehrClient(token, SECRETS); // get paperwork questions and validation schema diff --git a/packages/utils/lib/auth/index.ts b/packages/utils/lib/auth/index.ts index c635673df..edf5416ce 100644 --- a/packages/utils/lib/auth/index.ts +++ b/packages/utils/lib/auth/index.ts @@ -1,2 +1 @@ -export * from './getAuth0Token'; export * from './user-auth.helper'; diff --git a/packages/utils/lib/helpers/helpers.ts b/packages/utils/lib/helpers/helpers.ts index 7a9e401eb..71f4f53e6 100644 --- a/packages/utils/lib/helpers/helpers.ts +++ b/packages/utils/lib/helpers/helpers.ts @@ -1,12 +1,8 @@ import Oystehr, { OystehrConfig } from '@oystehr/sdk'; import { Appointment, Extension, QuestionnaireResponse, Resource } from 'fhir/r4b'; import { DateTime } from 'luxon'; -import { Secrets } from '../secrets'; -import { getSecret } from '../secrets'; -import { SecretsKeys } from '../secrets'; import { OTTEHR_MODULE } from '../fhir'; import { UpdateQuestionnaireResponseParams } from '../types'; -import path from 'path'; export function createOystehrClient(token: string, fhirAPI: string, projectAPI: string): Oystehr { const FHIR_API = fhirAPI.replace(/\/r4/g, ''); @@ -19,12 +15,6 @@ export function createOystehrClient(token: string, fhirAPI: string, projectAPI: return new Oystehr(CLIENT_CONFIG); } -export function createOystehrClientFromSecrets(token: string, secrets: Secrets | null): Oystehr { - const FHIR_API = getSecret(SecretsKeys.FHIR_API, secrets).replace(/\/r4/g, ''); - const PROJECT_API = getSecret(SecretsKeys.PROJECT_API, secrets); - return createOystehrClient(token, FHIR_API, PROJECT_API); -} - export function getParticipantIdFromAppointment( appointment: Appointment, participant: 'Patient' | 'Practitioner' @@ -399,17 +389,3 @@ export function updateQuestionnaireResponse({ ], }; } -export const performEffectWithEnvFile = async ( - pkg: 'intake' | 'ehr', - callback: (config: any) => void -): Promise => { - const env = process.argv[2]; - try { - const configPath = path.resolve(__dirname, `../../../${pkg}/zambdas/.env/${env}.json`); - const config = await import(configPath); - await callback(config); - } catch (e) { - console.error(e); - throw new Error(`can't import config for the environment: '${env}'`); - } -}; diff --git a/packages/utils/lib/main.ts b/packages/utils/lib/main.ts index 2570dd103..62f808294 100644 --- a/packages/utils/lib/main.ts +++ b/packages/utils/lib/main.ts @@ -3,7 +3,6 @@ export * from './fhir'; export * from './frontend'; export * from './helpers'; export * from './lambda'; -export * from './secrets'; export * from './store'; export * from './telemed'; export * from './types'; diff --git a/packages/utils/package.json b/packages/utils/package.json index 92d30e9e3..0c36a99c7 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -13,7 +13,5 @@ "coverage": "vitest run --coverage" }, "devDependencies": {}, - "dependencies": { - "axios": "1.6.2" - } + "dependencies": {} } diff --git a/packages/zambda-utils/lib/main.ts b/packages/zambda-utils/lib/main.ts new file mode 100644 index 000000000..d147aa60b --- /dev/null +++ b/packages/zambda-utils/lib/main.ts @@ -0,0 +1 @@ +export * from './secrets'; diff --git a/packages/utils/lib/secrets/index.ts b/packages/zambda-utils/lib/secrets/index.ts similarity index 94% rename from packages/utils/lib/secrets/index.ts rename to packages/zambda-utils/lib/secrets/index.ts index 61d162a4c..b1f39e239 100644 --- a/packages/utils/lib/secrets/index.ts +++ b/packages/zambda-utils/lib/secrets/index.ts @@ -69,4 +69,7 @@ export enum SecretsKeys { S3_BUCKET_SECRET_ACCESS_KEY = 'S3_BUCKET_SECRET_ACCESS_KEY', IN_PERSON_SENDGRID_SPANISH_CANCELLATION_EMAIL_TEMPLATE_ID = 'IN_PERSON_SENDGRID_SPANISH_CANCELLATION_EMAIL_TEMPLATE_ID', IN_PERSON_SENDGRID_SPANISH_CONFIRMATION_EMAIL_TEMPLATE_ID = 'IN_PERSON_SENDGRID_SPANISH_CONFIRMATION_EMAIL_TEMPLATE_ID', + IN_PERSON_SENDGRID_ISSUE_REPORT_EMAIL_TEMPLATE_ID = 'IN_PERSON_SENDGRID_ISSUE_REPORT_EMAIL_TEMPLATE_ID', + INTAKE_ISSUE_REPORT_EMAIL_GROUP_ID = 'INTAKE_ISSUE_REPORT_EMAIL_GROUP_ID', + NLM_API_KEY = 'NLM_API_KEY', } diff --git a/packages/zambda-utils/lib/vite-env.d.ts b/packages/zambda-utils/lib/vite-env.d.ts new file mode 100644 index 000000000..11f02fe2a --- /dev/null +++ b/packages/zambda-utils/lib/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/packages/zambda-utils/package.json b/packages/zambda-utils/package.json new file mode 100644 index 000000000..ff3cf8364 --- /dev/null +++ b/packages/zambda-utils/package.json @@ -0,0 +1,17 @@ +{ + "name": "zambda-utils", + "private": true, + "version": "0.0.1", + "main": "lib/main.ts", + "types": "lib/main.ts", + "scripts": { + "start": "vite", + "build": "tsc && vite build", + "lint": "eslint lib --ext ts,tsx --report-unused-disable-directives --max-warnings 0", + "preview": "vite preview", + "test": "vitest", + "coverage": "vitest run --coverage" + }, + "devDependencies": {}, + "dependencies": {} +} diff --git a/packages/zambda-utils/tsconfig.json b/packages/zambda-utils/tsconfig.json new file mode 100644 index 000000000..5f1a9efcf --- /dev/null +++ b/packages/zambda-utils/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "types": ["node"], + }, + "include": ["lib"], + "references": [{ "path": "./tsconfig.node.json" }] +} diff --git a/packages/zambda-utils/tsconfig.node.json b/packages/zambda-utils/tsconfig.node.json new file mode 100644 index 000000000..b6c645688 --- /dev/null +++ b/packages/zambda-utils/tsconfig.node.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "module": "es2022", + "moduleResolution": "bundler", + "allowSyntheticDefaultImports": true + }, + "include": ["vite.config.ts"] +} diff --git a/packages/zambda-utils/vite.config.ts b/packages/zambda-utils/vite.config.ts new file mode 100644 index 000000000..ff62153a1 --- /dev/null +++ b/packages/zambda-utils/vite.config.ts @@ -0,0 +1,14 @@ +import react from '@vitejs/plugin-react'; +import { resolve } from 'path'; +import { defineConfig } from 'vite'; + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [react()], + build: { + lib: { + entry: resolve(__dirname, 'lib/main.ts'), + formats: ['es'], + }, + }, +});