From 7d260365be957c0674aaf4ce5ce88967406ec046 Mon Sep 17 00:00:00 2001
From: Matthew Raymer <matthew.raymer@anomalistdesign.com>
Date: Tue, 22 Apr 2025 06:57:14 +0000
Subject: [PATCH] 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
---
 src/services/deepLinks.ts | 56 ++++++++++++++++++++++++---------------
 src/types/deepLinks.ts    |  2 +-
 2 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/src/services/deepLinks.ts b/src/services/deepLinks.ts
index 20e8cce0..ac8d480f 100644
--- a/src/services/deepLinks.ts
+++ b/src/services/deepLinks.ts
@@ -70,6 +70,31 @@ export class DeepLinkHandler {
     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.
    * Validates URL structure using Zod schemas.
@@ -101,11 +126,15 @@ export class DeepLinkHandler {
       });
     }
 
-    return {
-      path: routePath,
-      params: param ? { id: param } : {},
-      query,
-    };
+    const params: Record<string, string> = {};
+    if (param) {
+      if (this.ROUTE_MAP[routePath].paramKey) {
+        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>,
     query: Record<string, string>,
   ): 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
     let routeName: string;
 
     try {
       // Validate route exists
       const validRoute = routeSchema.parse(path) as DeepLinkRoute;
-      routeName = routeMap[validRoute];
+      routeName = this.ROUTE_MAP[validRoute].name;
     } catch (error) {
       // Log the invalid route attempt
       logConsoleAndDb(`[DeepLink] Invalid route path: ${path}`, true);
diff --git a/src/types/deepLinks.ts b/src/types/deepLinks.ts
index a8564d6d..0c046045 100644
--- a/src/types/deepLinks.ts
+++ b/src/types/deepLinks.ts
@@ -94,7 +94,7 @@ export const deepLinkSchemas = {
     contacts: z.string(), // JSON string of contacts array
   }),
   did: z.object({
-    id: z.string(),
+    did: z.string(),
   }),
 };