-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat(app): add strict schema validation endpoint
1 parent
84f21fd
commit aca2b83
Showing
11 changed files
with
220 additions
and
7 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
7 changes: 7 additions & 0 deletions
7
packages/app/documents/__tests__/__fixtures__/alertOnlyDocument.json
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,7 @@ | ||
{ | ||
"severity": "normal", | ||
"title": "Forward stream data temporarily unavailable from AWS cloud", | ||
"start": "2023-12-26 12:00:00-05:00", | ||
"expiration": "2024-01-01 12:00:00-05:00", | ||
"body": "<p>As of 9:00 AM Tuesday, December 26, 2023, granule ingest into AWS cloud was paused due to an ongoing operations issue. Users who use search interfaces, including Giovanni, will have issues discovering cloud-enabled data that have been archived in the past couple of days. This is not impacting users who directly access and download data from on-premises archive hosts at the GES DISC. We plan to resolve this issue and resume granule ingest by Sunday, December 31, 2023, though this is subject to change.</p>\n" | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "meditor", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "next dev", | ||
|
63 changes: 63 additions & 0 deletions
63
packages/app/pages/api/models/[modelName]/validate/index.ts
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,63 @@ | ||
import { getLoggedInUser } from 'auth/user' | ||
import { strictValidateDocument } from 'documents/service' | ||
import { getModelWithWorkflow, userCanAccessModel } from 'models/service' | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
import { respondAsJson } from 'utils/api' | ||
import { apiError, ErrorCode, HttpException } from 'utils/errors' | ||
import { safeParseJSON } from 'utils/json' | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
const modelName = decodeURIComponent(req.query.modelName.toString()) | ||
const user = await getLoggedInUser(req, res) | ||
|
||
if (!userCanAccessModel(modelName, user)) { | ||
return apiError( | ||
new HttpException( | ||
ErrorCode.ForbiddenError, | ||
'User does not have access to the requested model' | ||
), | ||
res | ||
) | ||
} | ||
|
||
switch (req.method) { | ||
//* GET returns the model's schema that will be used to valide the document. | ||
case 'GET': { | ||
const [modelWithWorkflowError, modelWithWorkflow] = | ||
await getModelWithWorkflow(modelName, undefined, { | ||
populateMacroTemplates: true, | ||
}) | ||
|
||
if (modelWithWorkflowError) { | ||
return apiError(modelWithWorkflowError, res) | ||
} | ||
|
||
return respondAsJson(JSON.parse(modelWithWorkflow.schema), req, res) | ||
} | ||
|
||
//* Unlike most POST endpoints, this allows unauthenticated access. | ||
case 'POST': { | ||
const [parsingError, parsedDocument] = safeParseJSON(req.body) | ||
|
||
if (parsingError) { | ||
return apiError(parsingError, res) | ||
} | ||
|
||
const [validationError, validDocument] = await strictValidateDocument( | ||
parsedDocument, | ||
modelName | ||
) | ||
|
||
if (validationError) { | ||
return apiError(validationError, res) | ||
} | ||
|
||
return respondAsJson(validDocument, req, res, { | ||
httpStatusCode: 200, | ||
}) | ||
} | ||
|
||
default: | ||
return res.status(405).end() | ||
} | ||
} |
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