Initial import of verae-middleware from zapier monorepo
This commit is contained in:
commit
0c807706f3
67 changed files with 6630 additions and 0 deletions
61
src/routes/timestampRoutes.js
Normal file
61
src/routes/timestampRoutes.js
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* @module routes/timestampRoutes
|
||||
*/
|
||||
|
||||
import { Router } from 'express';
|
||||
import { asyncHandler, AppError } from '../errors.js';
|
||||
import {
|
||||
createTimestamp,
|
||||
createTimestampAndWait,
|
||||
createBatchTimestamp,
|
||||
} from '../services/timestampService.js';
|
||||
|
||||
export const timestampRoutes = Router();
|
||||
|
||||
timestampRoutes.post(
|
||||
'/',
|
||||
asyncHandler(async (req, res) => {
|
||||
const { data, hashAlg, sha256, publicMetadata, privateMetadata } = req.body ?? {};
|
||||
if (!data && !sha256) {
|
||||
throw new AppError('data or sha256 is required', { status: 400, code: 'VALIDATION_ERROR' });
|
||||
}
|
||||
const result = await createTimestamp(req.auth, {
|
||||
data,
|
||||
hashAlg,
|
||||
sha256,
|
||||
publicMetadata,
|
||||
privateMetadata,
|
||||
});
|
||||
res.status(202).json(result);
|
||||
}),
|
||||
);
|
||||
|
||||
timestampRoutes.post(
|
||||
'/wait',
|
||||
asyncHandler(async (req, res) => {
|
||||
const { data, hashAlg, sha256, publicMetadata, privateMetadata } = req.body ?? {};
|
||||
if (!data && !sha256) {
|
||||
throw new AppError('data or sha256 is required', { status: 400, code: 'VALIDATION_ERROR' });
|
||||
}
|
||||
const result = await createTimestampAndWait(req.auth, {
|
||||
data,
|
||||
hashAlg,
|
||||
sha256,
|
||||
publicMetadata,
|
||||
privateMetadata,
|
||||
});
|
||||
res.json(result);
|
||||
}),
|
||||
);
|
||||
|
||||
timestampRoutes.post(
|
||||
'/batch',
|
||||
asyncHandler(async (req, res) => {
|
||||
const { items } = req.body ?? {};
|
||||
if (!Array.isArray(items) || items.length === 0) {
|
||||
throw new AppError('items array is required', { status: 400, code: 'VALIDATION_ERROR' });
|
||||
}
|
||||
const result = await createBatchTimestamp(req.auth, { items });
|
||||
res.status(202).json(result);
|
||||
}),
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue