-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow multiple CHEFS forms to be configured
FE can pull from multiple data sources. BE has dynamic basic auth based on the requested form ID
- Loading branch information
1 parent
7620356
commit 01e7998
Showing
16 changed files
with
183 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// @ts-expect-error api-problem lacks a defined interface; code still works fine | ||
import Problem from 'api-problem'; | ||
|
||
import { getChefsApiKey } from '../components/utils'; | ||
|
||
import type { NextFunction, Request, Response } from 'express'; | ||
|
||
/** | ||
* @function requireChefsFormConfigData | ||
* Rejects the request if there is no form ID present in the request | ||
* or if the given Form ID/Api Key is not configured | ||
* @param {object} req Express request object | ||
* @param {object} _res Express response object | ||
* @param {function} next The next callback function | ||
* @returns {function} Express middleware function | ||
* @throws The error encountered upon failure | ||
*/ | ||
export const requireChefsFormConfigData = (req: Request, _res: Response, next: NextFunction) => { | ||
const params = { ...req.query, ...req.params }; | ||
|
||
if (!params.formId) { | ||
throw new Problem(400, { | ||
detail: 'Form ID not present in request.', | ||
instance: req.originalUrl | ||
}); | ||
} | ||
|
||
if (!getChefsApiKey(params.formId as string)) { | ||
throw new Problem(412, { | ||
detail: 'Form not present or misconfigured.', | ||
instance: req.originalUrl | ||
}); | ||
} | ||
|
||
next(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export type ChefsFormConfig = { | ||
form1: ChefsFormConfigData; | ||
form2: ChefsFormConfigData; | ||
}; | ||
|
||
export type ChefsFormConfigData = { | ||
name: string; | ||
formId: string; | ||
formApiKey: string; | ||
}; |
Oops, something went wrong.