forked from jsnbuchanan/crowd-funder-for-time-pwa
Changes: - Add detailed JSDoc headers to deep linking files - Document type system and validation strategy - Add architecture overview and error handling docs - Include usage examples and integration points - Improve code organization comments This improves maintainability by documenting the deep linking system's architecture, type safety, and integration points.
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
/**
|
|
* @file Deep Link Type Definitions and Validation Schemas
|
|
* @author Matthew Raymer
|
|
*
|
|
* This file defines the type system and validation schemas for deep linking in the TimeSafari app.
|
|
* It uses Zod for runtime validation while providing TypeScript types for compile-time checking.
|
|
*
|
|
* Type Strategy:
|
|
* 1. Define base URL schema to validate the fundamental deep link structure
|
|
* 2. Define route-specific parameter schemas with exact validation rules
|
|
* 3. Generate TypeScript types from Zod schemas for type safety
|
|
* 4. Export both schemas and types for use in deep link handling
|
|
*
|
|
* Usage:
|
|
* - Import schemas for runtime validation in deep link handlers
|
|
* - Import types for type-safe parameter handling in components
|
|
* - Use DeepLinkParams type for type-safe access to route parameters
|
|
*
|
|
* @example
|
|
* // Runtime validation
|
|
* const params = deepLinkSchemas.claim.parse({ id: "123", view: "details" });
|
|
*
|
|
* // Type-safe parameter access
|
|
* function handleClaimParams(params: DeepLinkParams["claim"]) {
|
|
* // TypeScript knows params.id exists and params.view is optional
|
|
* }
|
|
*/
|
|
import { z } from "zod";
|
|
|
|
// Base URL validation schema
|
|
const baseUrlSchema = z.object({
|
|
scheme: z.literal("timesafari"),
|
|
path: z.string(),
|
|
queryParams: z.record(z.string()).optional()
|
|
});
|
|
|
|
// Parameter validation schemas for each route type
|
|
export const deepLinkSchemas = {
|
|
claim: z.object({
|
|
id: z.string().min(1),
|
|
view: z.enum(["details", "certificate", "raw"]).optional()
|
|
}),
|
|
|
|
contact: z.object({
|
|
did: z.string().regex(/^did:/),
|
|
action: z.enum(["edit", "import"]).optional(),
|
|
jwt: z.string().optional()
|
|
}),
|
|
|
|
project: z.object({
|
|
id: z.string().min(1),
|
|
view: z.enum(["details", "edit"]).optional()
|
|
}),
|
|
|
|
invite: z.object({
|
|
jwt: z.string().min(1),
|
|
type: z.enum(["one", "many"]).optional()
|
|
}),
|
|
|
|
gift: z.object({
|
|
id: z.string().min(1),
|
|
action: z.enum(["confirm", "details"]).optional()
|
|
}),
|
|
|
|
offer: z.object({
|
|
id: z.string().min(1),
|
|
view: z.enum(["details"]).optional()
|
|
})
|
|
};
|
|
|
|
export type DeepLinkParams = {
|
|
[K in keyof typeof deepLinkSchemas]: z.infer<typeof deepLinkSchemas[K]>;
|
|
};
|