110 lines
2.8 KiB
TypeScript
110 lines
2.8 KiB
TypeScript
import { z } from 'zod'
|
|
|
|
// Request body schema
|
|
export const deviceCommandBody = z.object({
|
|
merchantName: z.string(),
|
|
floorName: z.string(),
|
|
unitNumber: z.string(),
|
|
deviceName: z.string(),
|
|
roomName: z.string(),
|
|
deviceType: z.string(),
|
|
commandType: z.string(),
|
|
towerNumber: z.string(),
|
|
timestamp: z.string(),
|
|
nonce: z.string(),
|
|
payload: z.object({
|
|
action: z.string(),
|
|
}),
|
|
})
|
|
export type DeviceCommandBody = z.infer<typeof deviceCommandBody>
|
|
|
|
// Request query schema for GET endpoint
|
|
export const deviceQueryParams = z.object({
|
|
merchantName: z.string(),
|
|
floorName: z.string(),
|
|
unitNumber: z.string(),
|
|
deviceName: z.string(),
|
|
roomName: z.string(),
|
|
deviceType: z.string(),
|
|
commandType: z.string(),
|
|
towerNumber: z.string(),
|
|
timestamp: z.string(),
|
|
nonce: z.string(),
|
|
})
|
|
export type DeviceQueryParams = z.infer<typeof deviceQueryParams>
|
|
|
|
// Response schemas
|
|
export const deviceCommandResponseSchema = {
|
|
200: z.object({
|
|
status: z.literal('success'),
|
|
message: z.literal('Command accepted'),
|
|
receivedAt: z.string().datetime(),
|
|
}),
|
|
400: z.object({
|
|
status: z.literal('invalid_request'),
|
|
message: z.literal('Invalid request format'),
|
|
}),
|
|
401: z.union([
|
|
z.object({
|
|
status: z.literal('invalid_signature'),
|
|
message: z.literal('Signature mismatch'),
|
|
}),
|
|
z.object({
|
|
status: z.literal('invalid_api_key'),
|
|
message: z.literal('API Key is not valid'),
|
|
}),
|
|
]),
|
|
403: z.object({
|
|
status: z.literal('replay_attack_detected'),
|
|
message: z.literal('Timestamp or nonce is invalid/has been reused'),
|
|
}),
|
|
404: z.object({
|
|
status: z.literal('not_found'),
|
|
message: z.literal('Device status not found'),
|
|
}),
|
|
500: z.object({
|
|
status: z.literal('internal_error'),
|
|
message: z.literal('Server error'),
|
|
}),
|
|
}
|
|
|
|
// Query response schema
|
|
export const deviceQueryResponseSchema = {
|
|
200: z.object({
|
|
status: z.literal('success'),
|
|
message: z.literal('command accepted'),
|
|
data: z.object({
|
|
floor: z.string(),
|
|
unit: z.string(),
|
|
device: z.string(),
|
|
room: z.string(),
|
|
devType: z.string(),
|
|
code: z.string(),
|
|
tower: z.string(),
|
|
payload: z.string(),
|
|
}),
|
|
}),
|
|
400: z.object({
|
|
status: z.literal('invalid_request'),
|
|
message: z.literal('Invalid request format'),
|
|
}),
|
|
401: z.union([
|
|
z.object({
|
|
status: z.literal('invalid_signature'),
|
|
message: z.literal('Signature mismatch'),
|
|
}),
|
|
z.object({
|
|
status: z.literal('invalid_api_key'),
|
|
message: z.literal('API Key is not valid'),
|
|
}),
|
|
]),
|
|
403: z.object({
|
|
status: z.literal('replay_attack_detected'),
|
|
message: z.literal('Timestamp or nonce is invalid/has been reused'),
|
|
}),
|
|
500: z.object({
|
|
status: z.literal('internal_error'),
|
|
message: z.literal('Server error'),
|
|
}),
|
|
}
|