Skip to content

Add canonical historical event archive, OT derivation client, API endpoints and tests#31

Open
ohi-stack wants to merge 1 commit intomainfrom
codex/normalize-historical-records-schema
Open

Add canonical historical event archive, OT derivation client, API endpoints and tests#31
ohi-stack wants to merge 1 commit intomainfrom
codex/normalize-historical-records-schema

Conversation

@ohi-stack
Copy link
Copy Markdown
Owner

Motivation

  • Introduce a canonical historical archive to record dual-dated events for issuance and revocation and to support migration of legacy chronology without altering provided UTC timestamps.
  • Provide deterministic event IDs and derive missing OT (onegodian) calendar fields via an injected resolver or the onegodian-api.

Description

  • Add src/services/historicalEventArchive.js implementing normalization, deterministic event_id generation, in-memory storage, listing, retrieval, and a migration helper that preserves UTC chronology.
  • Add src/services/otCanonicalClient.js to derive OT calendar fields with support for a pluggable resolver and a network fallback to ONEGODIAN_API_BASE_URL.
  • Wire the archive into the API by updating src/controllers/api/v1Controller.js to emit archive events on record creation/revocation and to expose endpoints for create, migrate, list, and get by event_id, and update src/routes/api/v1Routes.js accordingly.
  • Extend validation (src/schemas/enforcementSchemas.js and src/services/schemaRegistry.js), update openapi/openapi.yaml, README examples, and package.json check script to include new files.
  • Add tests and test harness support in test/enforcement.test.js to inject a deterministic OT resolver, reset the archive between tests, and validate creation, listing, migration, and validation errors.

Testing

  • Ran npm run check to syntactically validate server and new service files and the script completed successfully.
  • Ran npm test (which uses node --test) and executed the updated test/enforcement.test.js assertions for archive creation, listing, migration, and error handling, and all tests passed.

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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({
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant