|
| 1 | +import { z } from 'zod' |
| 2 | +import { |
| 3 | + SQS_MAX_BATCH_ENTRIES, |
| 4 | + sqsBatchEntryIdSchema, |
| 5 | + sqsBatchResultErrorEntrySchema, |
| 6 | + sqsConnectionFields, |
| 7 | + sqsQueueUrlField, |
| 8 | +} from '@/lib/api/contracts/tools/aws/sqs-shared' |
| 9 | +import type { |
| 10 | + ContractBody, |
| 11 | + ContractBodyInput, |
| 12 | + ContractJsonResponse, |
| 13 | +} from '@/lib/api/contracts/types' |
| 14 | +import { defineRouteContract } from '@/lib/api/contracts/types' |
| 15 | + |
| 16 | +const ChangeMessageVisibilityBatchSchema = z.object({ |
| 17 | + ...sqsConnectionFields, |
| 18 | + queueUrl: sqsQueueUrlField, |
| 19 | + entries: z |
| 20 | + .array( |
| 21 | + z.object({ |
| 22 | + id: sqsBatchEntryIdSchema, |
| 23 | + receiptHandle: z.string().min(1, 'Receipt handle is required'), |
| 24 | + visibilityTimeout: z |
| 25 | + .number() |
| 26 | + .int() |
| 27 | + .min(0, 'visibilityTimeout must be at least 0') |
| 28 | + .max(43200, 'visibilityTimeout cannot exceed 43200 seconds (12 hours)') |
| 29 | + .nullish(), |
| 30 | + }) |
| 31 | + ) |
| 32 | + .min(1, 'At least one entry is required') |
| 33 | + .max(SQS_MAX_BATCH_ENTRIES, `A batch can hold at most ${SQS_MAX_BATCH_ENTRIES} entries`), |
| 34 | +}) |
| 35 | + |
| 36 | +const ChangeMessageVisibilityBatchResponseSchema = z.object({ |
| 37 | + message: z.string(), |
| 38 | + successful: z.array(z.object({ id: z.string().nullable() })), |
| 39 | + failed: z.array(sqsBatchResultErrorEntrySchema), |
| 40 | + successCount: z.number(), |
| 41 | + failureCount: z.number(), |
| 42 | +}) |
| 43 | + |
| 44 | +export const awsSqsChangeMessageVisibilityBatchContract = defineRouteContract({ |
| 45 | + method: 'POST', |
| 46 | + path: '/api/tools/sqs/change-message-visibility-batch', |
| 47 | + body: ChangeMessageVisibilityBatchSchema, |
| 48 | + response: { mode: 'json', schema: ChangeMessageVisibilityBatchResponseSchema }, |
| 49 | +}) |
| 50 | +export type AwsSqsChangeMessageVisibilityBatchRequest = ContractBodyInput< |
| 51 | + typeof awsSqsChangeMessageVisibilityBatchContract |
| 52 | +> |
| 53 | +export type AwsSqsChangeMessageVisibilityBatchBody = ContractBody< |
| 54 | + typeof awsSqsChangeMessageVisibilityBatchContract |
| 55 | +> |
| 56 | +export type AwsSqsChangeMessageVisibilityBatchResponse = ContractJsonResponse< |
| 57 | + typeof awsSqsChangeMessageVisibilityBatchContract |
| 58 | +> |
0 commit comments