Add canonical historical event archive, OT derivation client, API endpoints and tests#31
Add canonical historical event archive, OT derivation client, API endpoints and tests#31
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ce063674db
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const result = createRecord(req.body); | ||
| export const postRecord = async (req, res) => { | ||
| try { | ||
| const result = createRecord(req.body); |
There was a problem hiding this comment.
Roll back record mutation when history archiving fails
postRecord persists the record before the archive call, then maps any archive exception to a 500 response. If OT derivation throws (for example when ONEGODIAN_API_BASE_URL is unset), clients see a failed create but the QRVID is already stored, so retries immediately hit QRVID_CONFLICT while the record remains active. This creates externally visible write/response inconsistency and needs transactional handling (or compensating rollback) around the archive dependency.
Useful? React with 👍 / 👎.
| return res.status(result.statusCode).json(result.error); | ||
| } | ||
|
|
||
| await createHistoricalEvent({ |
There was a problem hiding this comment.
Handle archive conflict result before returning success
createHistoricalEvent reports conflicts as { ok: false, statusCode: 409 }, but this call ignores the returned result and always continues to 201 once record creation succeeds. In conflict scenarios (e.g., duplicate deterministic event_id), the API reports success while silently dropping the historical event, which breaks archive completeness guarantees.
Useful? React with 👍 / 👎.
Motivation
onegodian-api.Description
src/services/historicalEventArchive.jsimplementing normalization, deterministicevent_idgeneration, in-memory storage, listing, retrieval, and a migration helper that preserves UTC chronology.src/services/otCanonicalClient.jsto derive OT calendar fields with support for a pluggable resolver and a network fallback toONEGODIAN_API_BASE_URL.src/controllers/api/v1Controller.jsto emit archive events on record creation/revocation and to expose endpoints for create, migrate, list, and get byevent_id, and updatesrc/routes/api/v1Routes.jsaccordingly.src/schemas/enforcementSchemas.jsandsrc/services/schemaRegistry.js), updateopenapi/openapi.yaml, README examples, andpackage.jsoncheckscript to include new files.test/enforcement.test.jsto inject a deterministic OT resolver, reset the archive between tests, and validate creation, listing, migration, and validation errors.Testing
npm run checkto syntactically validate server and new service files and the script completed successfully.npm test(which usesnode --test) and executed the updatedtest/enforcement.test.jsassertions for archive creation, listing, migration, and error handling, and all tests passed.Codex Task