diff --git a/packages/backend/src/apps/va-facilities/actions/index.js b/packages/backend/src/apps/va-facilities/actions/index.js new file mode 100644 index 0000000000..6b2e169ffb --- /dev/null +++ b/packages/backend/src/apps/va-facilities/actions/index.js @@ -0,0 +1,3 @@ +import listFacilities from './list-facilities/index.js'; + +export default [listFacilities]; diff --git a/packages/backend/src/apps/va-facilities/actions/list-facilities/index.js b/packages/backend/src/apps/va-facilities/actions/list-facilities/index.js new file mode 100644 index 0000000000..5a0bb58dc9 --- /dev/null +++ b/packages/backend/src/apps/va-facilities/actions/list-facilities/index.js @@ -0,0 +1,131 @@ +import defineAction from '../../../../helpers/define-action.js'; + +export default defineAction({ + name: 'Facilities', + key: 'list-facilities', + description: 'search facilities based on various criteria', + arguments: [ + { + label: 'Facility Ids', + key: 'facilityIds', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Zip', + key: 'zip', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'State', + key: 'state', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Lat', + key: 'lat', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'long', + key: 'long', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'radius', + key: 'radius', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Bbox[]', + key: 'bbox', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Visn', + key: 'visn', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Type', + key: 'type', + type: 'dropdown', + required: false, + description: '', + options: [ + { label: 'health', value: 'health' }, + { label: 'cemetery', value: 'cemetery' }, + { label: 'benefits', value: 'benefits' }, + { label: 'vet_center', value: 'vet_center' }, + ], + variables: true, + }, + { + label: 'Services', + key: 'services', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Page', + key: 'page', + type: 'string', + required: false, + description: '', + variables: true, + }, + { + label: 'Per Page', + key: 'per_page', + type: 'string', + required: false, + description: '', + variables: true, + }, + ], + + async run($) { + const { page, per_page, ...restParams } = $.step.parameters; + + const filteredParams = Object.fromEntries( + Object.entries(restParams).filter(([key, value]) => value) + ); + const finalPage = page || '1'; + const finalPerPage = per_page || '25'; + + const params = new URLSearchParams({ + page: finalPage, + per_page: finalPerPage, + ...filteredParams, + }); + + console.log(params); + const response = await $.http.get(`/facilities?${params.toString()}`); + $.setActionItem({ raw: response.data }); + }, +}); diff --git a/packages/backend/src/apps/va-facilities/assets/favicon.svg b/packages/backend/src/apps/va-facilities/assets/favicon.svg new file mode 100644 index 0000000000..811e8f1ec4 --- /dev/null +++ b/packages/backend/src/apps/va-facilities/assets/favicon.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/packages/backend/src/apps/va-facilities/auth/index.js b/packages/backend/src/apps/va-facilities/auth/index.js new file mode 100644 index 0000000000..b8d66aff08 --- /dev/null +++ b/packages/backend/src/apps/va-facilities/auth/index.js @@ -0,0 +1,33 @@ +import verifyCredentials from './verify-credentials.js'; +import isStillVerified from './is-still-verified.js'; + +export default { + fields: [ + { + key: 'screenName', + label: 'Screen Name', + type: 'string', + required: true, + readOnly: false, + value: null, + placeholder: null, + description: + 'Screen name of your connection to be used on Automatisch UI.', + clickToCopy: false, + }, + { + key: 'apiKey', + label: 'API Key', + type: 'string', + required: true, + readOnly: false, + value: null, + placeholder: null, + description: 'VA Facilities API key of your account.', + clickToCopy: false, + }, + ], + + verifyCredentials, + isStillVerified, +}; diff --git a/packages/backend/src/apps/va-facilities/auth/is-still-verified.js b/packages/backend/src/apps/va-facilities/auth/is-still-verified.js new file mode 100644 index 0000000000..6663679aab --- /dev/null +++ b/packages/backend/src/apps/va-facilities/auth/is-still-verified.js @@ -0,0 +1,8 @@ +import verifyCredentials from './verify-credentials.js'; + +const isStillVerified = async ($) => { + await verifyCredentials($); + return true; +}; + +export default isStillVerified; diff --git a/packages/backend/src/apps/va-facilities/auth/verify-credentials.js b/packages/backend/src/apps/va-facilities/auth/verify-credentials.js new file mode 100644 index 0000000000..049e51cd5a --- /dev/null +++ b/packages/backend/src/apps/va-facilities/auth/verify-credentials.js @@ -0,0 +1,11 @@ +const verifyCredentials = async ($) => { + console.log($) + await $.http.get('/facilities?page=1&per_page=5'); + + await $.auth.set({ + screenName: $.auth.data.screenName, + apiKey: $.auth.data.apiKey, + }); +}; + +export default verifyCredentials; diff --git a/packages/backend/src/apps/va-facilities/common/add-auth-header.js b/packages/backend/src/apps/va-facilities/common/add-auth-header.js new file mode 100644 index 0000000000..d106f30560 --- /dev/null +++ b/packages/backend/src/apps/va-facilities/common/add-auth-header.js @@ -0,0 +1,9 @@ +const addAuthHeader = ($, requestConfig) => { + if ($.auth.data?.apiKey) { + requestConfig.headers.apikey = $.auth.data.apiKey; + } + + return requestConfig; +}; + +export default addAuthHeader; diff --git a/packages/backend/src/apps/va-facilities/index.js b/packages/backend/src/apps/va-facilities/index.js new file mode 100644 index 0000000000..c74071eee1 --- /dev/null +++ b/packages/backend/src/apps/va-facilities/index.js @@ -0,0 +1,18 @@ +import defineApp from '../../helpers/define-app.js'; +import addAuthHeader from './common/add-auth-header.js'; +import auth from './auth/index.js'; +import actions from './actions/index.js'; + +export default defineApp({ + name: 'Va Facilities', + key: 'va-facilities', + iconUrl: '{BASE_URL}/apps/va-facilities/assets/favicon.svg', + authDocUrl: '', + supportsConnections: true, + baseUrl: 'https://developer.va.gov/', + apiBaseUrl: 'https://api.va.gov/services/va_facilities/v1/', + primaryColor: '#6f42c1', + beforeRequest: [addAuthHeader], + auth, + actions, +});