apps/gateway/src/middleware/idempotency.ts
Metadata
- Purpose: Gateway middleware for cross-cutting concerns.
- Domain:
applications - Language:
ts - Bytes: 950
- Lines: 28
- Content hash (short):
960b30a3 - Source (start): apps/gateway/src/middleware/idempotency.ts:1
- Source (end): apps/gateway/src/middleware/idempotency.ts:28
Indexed Symbols
No indexed functions/methods detected in this file.
Markdown Headings (if applicable)
No markdown headings detected.
Source Preview
import type { FastifyPluginAsync } from "fastify";
import { getIdempotencyRecord, putIdempotencyRecord, type IdempotencyRecord } from "../services/idempotency-repository.js";
type IdempotencyContext = {
workspaceId: string;
key: string;
route: string;
method: string;
};
export const idempotencyPlugin: FastifyPluginAsync = async (app) => {
app.decorate("idempotencyStore", {
get: (context: IdempotencyContext) =>
getIdempotencyRecord(context.workspaceId, context.key, context.route, context.method),
set: (context: IdempotencyContext, value: IdempotencyRecord) =>
putIdempotencyRecord(context.workspaceId, context.key, context.route, context.method, value)
});
};
declare module "fastify" {
interface FastifyInstance {
idempotencyStore: {
get(context: IdempotencyContext): Promise<IdempotencyRecord | null>;
set(context: IdempotencyContext, value: IdempotencyRecord): Promise<void>;
};