@johnhenry/browsermesh-discovery 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/sw-routing.mjs +2 -50
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnhenry/browsermesh-discovery",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "DHT, peer discovery, naming, swarm coordination, and stealth networking for BrowserMesh",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
@@ -19,7 +19,7 @@
19
19
  "directory": "packages/browsermesh-discovery"
20
20
  },
21
21
  "peerDependencies": {
22
- "@johnhenry/browsermesh-primitives": ">=0.2.0 <1.0.0"
22
+ "@johnhenry/browsermesh-primitives": ">=0.3.1 <1.0.0"
23
23
  },
24
24
  "scripts": {
25
25
  "test": "node --import ./test/_setup-globals.mjs --test test/*.test.mjs"
@@ -28,56 +28,8 @@
28
28
  * node --import ./web/test/_setup-globals.mjs --test web/test/clawser-mesh-sw-routing.test.mjs
29
29
  */
30
30
 
31
- const MESH_PROTOCOL = 'mesh://'
32
- const MESH_LOCAL_SUFFIX = '.mesh.local'
33
-
34
- /**
35
- * Parse a mesh URL into { podId, path } or null.
36
- * Supports:
37
- * - mesh://podId/path
38
- * - https://podId.mesh.local/path
39
- * - http://podId.mesh.local/path
40
- *
41
- * @param {string} urlStr
42
- * @returns {{ podId: string, path: string } | null}
43
- */
44
- export function parseMeshRequest(urlStr) {
45
- if (!urlStr || typeof urlStr !== 'string') return null
46
-
47
- // --- mesh:// protocol ---
48
- if (urlStr.startsWith(MESH_PROTOCOL)) {
49
- const rest = urlStr.slice(MESH_PROTOCOL.length)
50
- if (!rest) return null
51
-
52
- const slashIdx = rest.indexOf('/')
53
- let podId, path
54
- if (slashIdx === -1) {
55
- podId = rest
56
- path = '/'
57
- } else {
58
- podId = rest.slice(0, slashIdx)
59
- path = rest.slice(slashIdx) || '/'
60
- }
61
-
62
- if (!podId) return null
63
- return { podId, path }
64
- }
65
-
66
- // --- https://podId.mesh.local/path or http://podId.mesh.local/path ---
67
- // Extract hostname from the raw string to preserve case (URL() lowercases hostnames).
68
- const httpMatch = urlStr.match(/^https?:\/\/([^/?#]+)(\/[^?#]*)?/)
69
- if (!httpMatch) return null
70
-
71
- const rawHost = httpMatch[1] // preserves original case
72
- const lowerHost = rawHost.toLowerCase()
73
- if (!lowerHost.endsWith(MESH_LOCAL_SUFFIX)) return null
74
-
75
- const podId = rawHost.slice(0, -MESH_LOCAL_SUFFIX.length)
76
- if (!podId) return null
77
-
78
- const path = httpMatch[2] || '/'
79
- return { podId, path }
80
- }
31
+ import { parseMeshRequest } from '@johnhenry/browsermesh-primitives'
32
+ export { parseMeshRequest }
81
33
 
82
34
  /**
83
35
  * Routes mesh:// and *.mesh.local fetch requests to a mesh RPC handler.