forked from jsnbuchanan/crowd-funder-for-time-pwa
- Add type-safe deep link parameter validation using Zod - Implement consistent error handling across all deep link routes - Add support for query parameters in deep links - Create comprehensive deep linking documentation - Add logging for deep link operations Security: - Validate all deep link parameters before processing - Sanitize and type-check query parameters - Add error boundaries around deep link handling - Implement route-specific parameter validation Testing: - Add parameter validation tests - Add error handling tests - Test query parameter support
46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
TypeScript
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]>;
|
|
};
|