Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync staging with develop #533

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ jobs:
CSB_2024_FRF_OPEN: true
CSB_2024_PRF_OPEN: true
CSB_2024_CRF_OPEN: true
FORMIO_2022_FRF_SUBSTRING: ${{ secrets.FORMIO_2022_FRF_SUBSTRING }}
FORMIO_2022_PRF_SUBSTRING: ${{ secrets.FORMIO_2022_PRF_SUBSTRING }}
FORMIO_2022_CRF_SUBSTRING: ${{ secrets.FORMIO_2022_CRF_SUBSTRING }}
FORMIO_2023_FRF_SUBSTRING: ${{ secrets.FORMIO_2023_FRF_SUBSTRING }}
FORMIO_2023_PRF_SUBSTRING: ${{ secrets.FORMIO_2023_PRF_SUBSTRING }}
FORMIO_2023_CRF_SUBSTRING: ${{ secrets.FORMIO_2023_CRF_SUBSTRING }}
FORMIO_2024_FRF_SUBSTRING: ${{ secrets.FORMIO_2024_FRF_SUBSTRING }}
FORMIO_2024_PRF_SUBSTRING: ${{ secrets.FORMIO_2024_PRF_SUBSTRING }}
FORMIO_2024_CRF_SUBSTRING: ${{ secrets.FORMIO_2024_CRF_SUBSTRING }}
FORMIO_2022_FRF_PATH: ${{ secrets.FORMIO_2022_FRF_PATH }}
FORMIO_2022_PRF_PATH: ${{ secrets.FORMIO_2022_PRF_PATH }}
FORMIO_2022_CRF_PATH: ${{ secrets.FORMIO_2022_CRF_PATH }}
Expand Down Expand Up @@ -145,6 +154,15 @@ jobs:
cf set-env $APP_NAME "CSB_2024_FRF_OPEN" "$CSB_2024_FRF_OPEN" > /dev/null
cf set-env $APP_NAME "CSB_2024_PRF_OPEN" "$CSB_2024_PRF_OPEN" > /dev/null
cf set-env $APP_NAME "CSB_2024_CRF_OPEN" "$CSB_2024_CRF_OPEN" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_FRF_SUBSTRING" "$FORMIO_2022_FRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_PRF_SUBSTRING" "$FORMIO_2022_PRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_CRF_SUBSTRING" "$FORMIO_2022_CRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2023_FRF_SUBSTRING" "$FORMIO_2023_FRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2023_PRF_SUBSTRING" "$FORMIO_2023_PRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2023_CRF_SUBSTRING" "$FORMIO_2023_CRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2024_FRF_SUBSTRING" "$FORMIO_2024_FRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2024_PRF_SUBSTRING" "$FORMIO_2024_PRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2024_CRF_SUBSTRING" "$FORMIO_2024_CRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_FRF_PATH" "$FORMIO_2022_FRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_PRF_PATH" "$FORMIO_2022_PRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_CRF_PATH" "$FORMIO_2022_CRF_PATH" > /dev/null
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ jobs:
CSB_2024_FRF_OPEN: true
CSB_2024_PRF_OPEN: true
CSB_2024_CRF_OPEN: true
FORMIO_2022_FRF_SUBSTRING: ${{ secrets.FORMIO_2022_FRF_SUBSTRING }}
FORMIO_2022_PRF_SUBSTRING: ${{ secrets.FORMIO_2022_PRF_SUBSTRING }}
FORMIO_2022_CRF_SUBSTRING: ${{ secrets.FORMIO_2022_CRF_SUBSTRING }}
FORMIO_2023_FRF_SUBSTRING: ${{ secrets.FORMIO_2023_FRF_SUBSTRING }}
FORMIO_2023_PRF_SUBSTRING: ${{ secrets.FORMIO_2023_PRF_SUBSTRING }}
FORMIO_2023_CRF_SUBSTRING: ${{ secrets.FORMIO_2023_CRF_SUBSTRING }}
FORMIO_2024_FRF_SUBSTRING: ${{ secrets.FORMIO_2024_FRF_SUBSTRING }}
FORMIO_2024_PRF_SUBSTRING: ${{ secrets.FORMIO_2024_PRF_SUBSTRING }}
FORMIO_2024_CRF_SUBSTRING: ${{ secrets.FORMIO_2024_CRF_SUBSTRING }}
FORMIO_2022_FRF_PATH: ${{ secrets.FORMIO_2022_FRF_PATH }}
FORMIO_2022_PRF_PATH: ${{ secrets.FORMIO_2022_PRF_PATH }}
FORMIO_2022_CRF_PATH: ${{ secrets.FORMIO_2022_CRF_PATH }}
Expand Down Expand Up @@ -145,6 +154,15 @@ jobs:
cf set-env $APP_NAME "CSB_2024_FRF_OPEN" "$CSB_2024_FRF_OPEN" > /dev/null
cf set-env $APP_NAME "CSB_2024_PRF_OPEN" "$CSB_2024_PRF_OPEN" > /dev/null
cf set-env $APP_NAME "CSB_2024_CRF_OPEN" "$CSB_2024_CRF_OPEN" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_FRF_SUBSTRING" "$FORMIO_2022_FRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_PRF_SUBSTRING" "$FORMIO_2022_PRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_CRF_SUBSTRING" "$FORMIO_2022_CRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2023_FRF_SUBSTRING" "$FORMIO_2023_FRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2023_PRF_SUBSTRING" "$FORMIO_2023_PRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2023_CRF_SUBSTRING" "$FORMIO_2023_CRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2024_FRF_SUBSTRING" "$FORMIO_2024_FRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2024_PRF_SUBSTRING" "$FORMIO_2024_PRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2024_CRF_SUBSTRING" "$FORMIO_2024_CRF_SUBSTRING" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_FRF_PATH" "$FORMIO_2022_FRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_PRF_PATH" "$FORMIO_2022_PRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_CRF_PATH" "$FORMIO_2022_CRF_PATH" > /dev/null
Expand Down
9 changes: 9 additions & 0 deletions app/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ CSB_2023_CRF_OPEN=true
CSB_2024_FRF_OPEN=true
CSB_2024_PRF_OPEN=true
CSB_2024_CRF_OPEN=true
FORMIO_2022_FRF_SUBSTRING=
FORMIO_2022_PRF_SUBSTRING=
FORMIO_2022_CRF_SUBSTRING=
FORMIO_2023_FRF_SUBSTRING=
FORMIO_2023_PRF_SUBSTRING=
FORMIO_2023_CRF_SUBSTRING=
FORMIO_2024_FRF_SUBSTRING=
FORMIO_2024_PRF_SUBSTRING=
FORMIO_2024_CRF_SUBSTRING=
FORMIO_2022_FRF_PATH=
FORMIO_2022_PRF_PATH=
FORMIO_2022_CRF_PATH=
Expand Down
37 changes: 34 additions & 3 deletions app/server/app/config/formio.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ const {
CSB_2024_FRF_OPEN,
CSB_2024_PRF_OPEN,
CSB_2024_CRF_OPEN,
FORMIO_BASE_URL,
FORMIO_PROJECT_NAME,
FORMIO_API_KEY,
FORMIO_2022_FRF_SUBSTRING,
FORMIO_2022_PRF_SUBSTRING,
FORMIO_2022_CRF_SUBSTRING,
FORMIO_2023_FRF_SUBSTRING,
FORMIO_2023_PRF_SUBSTRING,
FORMIO_2023_CRF_SUBSTRING,
FORMIO_2024_FRF_SUBSTRING,
FORMIO_2024_PRF_SUBSTRING,
FORMIO_2024_CRF_SUBSTRING,
FORMIO_2022_FRF_PATH,
FORMIO_2022_PRF_PATH,
FORMIO_2022_CRF_PATH,
Expand All @@ -29,6 +35,9 @@ const {
FORMIO_2024_PRF_PATH,
FORMIO_2024_CRF_PATH,
FORMIO_2024_CHANGE_PATH,
FORMIO_BASE_URL,
FORMIO_PROJECT_NAME,
FORMIO_API_KEY,
} = process.env;

const formioProjectUrl = `${FORMIO_BASE_URL}/${FORMIO_PROJECT_NAME}`;
Expand Down Expand Up @@ -57,6 +66,27 @@ const formUrl = {
},
};

/**
* Stores intro text substring found within each form by rebate year.
*/
const formIntroSubstring = {
2022: {
frf: FORMIO_2022_FRF_SUBSTRING,
prf: FORMIO_2022_PRF_SUBSTRING,
crf: FORMIO_2022_CRF_SUBSTRING,
},
2023: {
frf: FORMIO_2023_FRF_SUBSTRING,
prf: FORMIO_2023_PRF_SUBSTRING,
crf: FORMIO_2023_CRF_SUBSTRING,
},
2024: {
frf: FORMIO_2024_FRF_SUBSTRING,
prf: FORMIO_2024_PRF_SUBSTRING,
crf: FORMIO_2024_CRF_SUBSTRING,
},
};

/**
* Stores whether the submission period is open for each form by rebate year.
*/
Expand Down Expand Up @@ -138,6 +168,7 @@ module.exports = {
axiosFormio,
formioProjectUrl,
formUrl,
formIntroSubstring,
submissionPeriodOpen,
formioCSBMetadata,
formioExampleMongoId,
Expand Down
9 changes: 9 additions & 0 deletions app/server/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ const requiredEnvironmentVariables = [
"CSB_2024_FRF_OPEN",
"CSB_2024_PRF_OPEN",
"CSB_2024_CRF_OPEN",
"FORMIO_2022_FRF_SUBSTRING",
"FORMIO_2022_PRF_SUBSTRING",
"FORMIO_2022_CRF_SUBSTRING",
"FORMIO_2023_FRF_SUBSTRING",
"FORMIO_2023_PRF_SUBSTRING",
// "FORMIO_2023_CRF_SUBSTRING",
"FORMIO_2024_FRF_SUBSTRING",
"FORMIO_2024_PRF_SUBSTRING",
// "FORMIO_2024_CRF_SUBSTRING",
"FORMIO_2022_FRF_PATH",
"FORMIO_2022_PRF_PATH",
"FORMIO_2022_CRF_PATH",
Expand Down
83 changes: 67 additions & 16 deletions app/server/app/routes/status.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@
const express = require("express");
// ---
const { axiosFormio, formUrl } = require("../config/formio");
const {
axiosFormio,
formUrl,
formIntroSubstring,
} = require("../config/formio");
const { getSamEntities } = require("../utilities/bap");

/**
* Verify that schema has type of form and a title exists
* (confirming Formio returned a valid schema).
* Return the intro text from the "Welcome" section of a form.
*/
function verifySchema(schema) {
return schema.type === "form" && !!schema.title;
function getFormIntroText(schema) {
const intro = schema.components.find((c) => c.title === "Welcome");
if (!intro) return "";

const result = intro.components.reduce((string, component) => {
const { type, tag, content } = component;
const text = type === "htmlelement" && tag !== "style" && content;
if (text)
string += text
.replace(/"/g, "'") // convert double quotes to single quotes
.replace(/\r?\n/g, "") // remove new line characters
.replace(/\s\s+/g, " "); // remove double spaces
return string;
}, "");

return result;
}

/**
* Verify the schema has a type of form, a title exists, and the form's intro
* text contains the correct value (confirming Formio returns the valid schema).
*/
function verifySchema({ schema, substring }) {
return (
schema.type === "form" &&
!!schema.title &&
getFormIntroText(schema).includes(substring)
);
}

const router = express.Router();
Expand All @@ -33,11 +62,13 @@ router.get("/bap/sam", (req, res) => {
});

router.get("/formio/2022/frf", (req, res) => {
const substring = formIntroSubstring["2022"].frf;

axiosFormio(req)
.get(formUrl["2022"].frf)
.then((axiosRes) => axiosRes.data)
.then((schema) => {
return res.json({ status: verifySchema(schema) });
return res.json({ status: verifySchema({ schema, substring }) });
})
.catch((_error) => {
// NOTE: error is logged in axiosFormio response interceptor
Expand All @@ -46,11 +77,13 @@ router.get("/formio/2022/frf", (req, res) => {
});

router.get("/formio/2022/prf", (req, res) => {
const substring = formIntroSubstring["2022"].prf;

axiosFormio(req)
.get(formUrl["2022"].prf)
.then((axiosRes) => axiosRes.data)
.then((schema) => {
return res.json({ status: verifySchema(schema) });
return res.json({ status: verifySchema({ schema, substring }) });
})
.catch((_error) => {
// NOTE: error is logged in axiosFormio response interceptor
Expand All @@ -59,11 +92,13 @@ router.get("/formio/2022/prf", (req, res) => {
});

router.get("/formio/2022/crf", (req, res) => {
const substring = formIntroSubstring["2022"].crf;

axiosFormio(req)
.get(formUrl["2022"].crf)
.then((axiosRes) => axiosRes.data)
.then((schema) => {
return res.json({ status: verifySchema(schema) });
return res.json({ status: verifySchema({ schema, substring }) });
})
.catch((_error) => {
// NOTE: error is logged in axiosFormio response interceptor
Expand All @@ -72,11 +107,13 @@ router.get("/formio/2022/crf", (req, res) => {
});

router.get("/formio/2023/frf", (req, res) => {
const substring = formIntroSubstring["2023"].frf;

axiosFormio(req)
.get(formUrl["2023"].frf)
.then((axiosRes) => axiosRes.data)
.then((schema) => {
return res.json({ status: verifySchema(schema) });
return res.json({ status: verifySchema({ schema, substring }) });
})
.catch((_error) => {
// NOTE: error is logged in axiosFormio response interceptor
Expand All @@ -85,11 +122,13 @@ router.get("/formio/2023/frf", (req, res) => {
});

router.get("/formio/2023/prf", (req, res) => {
const substring = formIntroSubstring["2023"].prf;

axiosFormio(req)
.get(formUrl["2023"].prf)
.then((axiosRes) => axiosRes.data)
.then((schema) => {
return res.json({ status: verifySchema(schema) });
return res.json({ status: verifySchema({ schema, substring }) });
})
.catch((_error) => {
// NOTE: error is logged in axiosFormio response interceptor
Expand All @@ -98,11 +137,13 @@ router.get("/formio/2023/prf", (req, res) => {
});

// router.get("/formio/2023/crf", (req, res) => {
// const substring = formIntroSubstring["2023"].crf;
//
// axiosFormio(req)
// .get(formUrl["2023"].crf)
// .then((axiosRes) => axiosRes.data)
// .then((schema) => {
// return res.json({ status: verifySchema(schema) });
// return res.json({ status: verifySchema({ schema, substring }) });
// })
// .catch((_error) => {
// // NOTE: error is logged in axiosFormio response interceptor
Expand All @@ -111,11 +152,13 @@ router.get("/formio/2023/prf", (req, res) => {
// });

router.get("/formio/2023/change", (req, res) => {
const substring = "";

axiosFormio(req)
.get(formUrl["2023"].change)
.then((axiosRes) => axiosRes.data)
.then((schema) => {
return res.json({ status: verifySchema(schema) });
return res.json({ status: verifySchema({ schema, substring }) });
})
.catch((_error) => {
// NOTE: error is logged in axiosFormio response interceptor
Expand All @@ -124,11 +167,13 @@ router.get("/formio/2023/change", (req, res) => {
});

router.get("/formio/2024/frf", (req, res) => {
const substring = formIntroSubstring["2024"].frf;

axiosFormio(req)
.get(formUrl["2024"].frf)
.then((axiosRes) => axiosRes.data)
.then((schema) => {
return res.json({ status: verifySchema(schema) });
return res.json({ status: verifySchema({ schema, substring }) });
})
.catch((_error) => {
// NOTE: error is logged in axiosFormio response interceptor
Expand All @@ -137,11 +182,13 @@ router.get("/formio/2024/frf", (req, res) => {
});

router.get("/formio/2024/prf", (req, res) => {
const substring = formIntroSubstring["2024"].prf;

axiosFormio(req)
.get(formUrl["2024"].prf)
.then((axiosRes) => axiosRes.data)
.then((schema) => {
return res.json({ status: verifySchema(schema) });
return res.json({ status: verifySchema({ schema, substring }) });
})
.catch((_error) => {
// NOTE: error is logged in axiosFormio response interceptor
Expand All @@ -150,11 +197,13 @@ router.get("/formio/2024/prf", (req, res) => {
});

// router.get("/formio/2024/crf", (req, res) => {
// const substring = formIntroSubstring["2024"].crf;
//
// axiosFormio(req)
// .get(formUrl["2024"].crf)
// .then((axiosRes) => axiosRes.data)
// .then((schema) => {
// return res.json({ status: verifySchema(schema) });
// return res.json({ status: verifySchema({ schema, substring }) });
// })
// .catch((_error) => {
// // NOTE: error is logged in axiosFormio response interceptor
Expand All @@ -163,11 +212,13 @@ router.get("/formio/2024/prf", (req, res) => {
// });

router.get("/formio/2024/change", (req, res) => {
const substring = "";

axiosFormio(req)
.get(formUrl["2024"].change)
.then((axiosRes) => axiosRes.data)
.then((schema) => {
return res.json({ status: verifySchema(schema) });
return res.json({ status: verifySchema({ schema, substring }) });
})
.catch((_error) => {
// NOTE: error is logged in axiosFormio response interceptor
Expand Down
Loading