Browse Source

fix(deep-links): standardize DID parameter name and add route mapping docs

- Change DID schema parameter from 'id' to 'did' for consistency
- Add documentation for deep link route mapping functionality
pull/132/head
Matthew Raymer 1 month ago
parent
commit
7d260365be
  1. 56
      src/services/deepLinks.ts
  2. 2
      src/types/deepLinks.ts

56
src/services/deepLinks.ts

@ -70,6 +70,31 @@ export class DeepLinkHandler {
this.router = router; this.router = router;
} }
/**
* Maps deep link routes to their corresponding Vue router names and optional parameter keys.
*
* The paramKey is used to extract the parameter from the route path,
* because "router.replace" expects the right parameter name for the route.
* The default is "id".
*/
private readonly ROUTE_MAP: Record<
string,
{ name: string; paramKey?: string }
> = {
"user-profile": { name: "user-profile" },
"project-details": { name: "project-details" },
"onboard-meeting-setup": { name: "onboard-meeting-setup" },
"invite-one-accept": { name: "invite-one-accept" },
"contact-import": { name: "contact-import" },
"confirm-gift": { name: "confirm-gift" },
claim: { name: "claim" },
"claim-cert": { name: "claim-cert" },
"claim-add-raw": { name: "claim-add-raw" },
"contact-edit": { name: "contact-edit", paramKey: "did" },
contacts: { name: "contacts" },
did: { name: "did", paramKey: "did" },
};
/** /**
* Parses deep link URL into path, params and query components. * Parses deep link URL into path, params and query components.
* Validates URL structure using Zod schemas. * Validates URL structure using Zod schemas.
@ -101,11 +126,15 @@ export class DeepLinkHandler {
}); });
} }
return { const params: Record<string, string> = {};
path: routePath, if (param) {
params: param ? { id: param } : {}, if (this.ROUTE_MAP[routePath].paramKey) {
query, params[this.ROUTE_MAP[routePath].paramKey] = param;
}; } else {
params["id"] = param;
}
}
return { path: routePath, params, query };
} }
/** /**
@ -153,28 +182,13 @@ export class DeepLinkHandler {
params: Record<string, string>, params: Record<string, string>,
query: Record<string, string>, query: Record<string, string>,
): Promise<void> { ): Promise<void> {
const routeMap: Record<string, string> = {
"user-profile": "user-profile",
"project-details": "project-details",
"onboard-meeting-setup": "onboard-meeting-setup",
"invite-one-accept": "invite-one-accept",
"contact-import": "contact-import",
"confirm-gift": "confirm-gift",
claim: "claim",
"claim-cert": "claim-cert",
"claim-add-raw": "claim-add-raw",
"contact-edit": "contact-edit",
contacts: "contacts",
did: "did",
};
// First try to validate the route path // First try to validate the route path
let routeName: string; let routeName: string;
try { try {
// Validate route exists // Validate route exists
const validRoute = routeSchema.parse(path) as DeepLinkRoute; const validRoute = routeSchema.parse(path) as DeepLinkRoute;
routeName = routeMap[validRoute]; routeName = this.ROUTE_MAP[validRoute].name;
} catch (error) { } catch (error) {
// Log the invalid route attempt // Log the invalid route attempt
logConsoleAndDb(`[DeepLink] Invalid route path: ${path}`, true); logConsoleAndDb(`[DeepLink] Invalid route path: ${path}`, true);

2
src/types/deepLinks.ts

@ -94,7 +94,7 @@ export const deepLinkSchemas = {
contacts: z.string(), // JSON string of contacts array contacts: z.string(), // JSON string of contacts array
}), }),
did: z.object({ did: z.object({
id: z.string(), did: z.string(),
}), }),
}; };

Loading…
Cancel
Save