spaps-types
Version:
Shared TypeScript types for SPAPS ecosystem
32 lines (31 loc) • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.secureMessageMetadataSchema = exports.secureMessageSchema = exports.createSecureMessageRequestSchema = void 0;
const zod_1 = require("zod");
const defaultMetadataSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
exports.secureMessageMetadataSchema = defaultMetadataSchema;
/**
* Factory for secure message creation payload schemas.
* Consumers can pass a custom metadata schema to get typed inference.
*/
const createSecureMessageRequestSchema = (metadataSchema = defaultMetadataSchema) => zod_1.z.object({
patientId: zod_1.z.string().uuid('patientId must be a valid UUID'),
practitionerId: zod_1.z.string().uuid('practitionerId must be a valid UUID'),
content: zod_1.z.string().min(1, 'content is required'),
metadata: metadataSchema.optional()
});
exports.createSecureMessageRequestSchema = createSecureMessageRequestSchema;
/**
* Factory for secure message response schemas.
* Allows callers to reuse a metadata schema so inference stays in sync across stack.
*/
const secureMessageSchema = (metadataSchema = defaultMetadataSchema) => zod_1.z.object({
id: zod_1.z.string(),
application_id: zod_1.z.string(),
patient_id: zod_1.z.string(),
practitioner_id: zod_1.z.string(),
content: zod_1.z.string(),
metadata: metadataSchema,
created_at: zod_1.z.string()
});
exports.secureMessageSchema = secureMessageSchema;