@johnhenry/browsermesh-primitives 0.3.0 → 0.3.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.
- package/README.md +4 -0
- package/package.json +1 -1
- package/src/index.d.ts +3 -0
- package/src/index.mjs +3 -0
- package/src/mesh-address.mjs +56 -0
package/README.md
CHANGED
|
@@ -95,6 +95,10 @@ console.log(set.has('item')) // true
|
|
|
95
95
|
|
|
96
96
|
### Wire Format
|
|
97
97
|
|
|
98
|
+
- `parseMeshRequest(url)` — shared browser-safe parsing of `mesh://` and
|
|
99
|
+
`*.mesh.local` addresses into `{ podId, path }`, preserving ID case and
|
|
100
|
+
query strings and excluding fragments. Discovery re-exports the same helper.
|
|
101
|
+
|
|
98
102
|
- `messageTypeRegistry` -- extensible registry of message types
|
|
99
103
|
- `encodeMeshMessage(msg)` / `decodeMeshMessage(bytes)` -- binary serialization
|
|
100
104
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnhenry/browsermesh-primitives",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Shared primitives for browser mesh networking — wire format, identity (Ed25519), CRDTs, capabilities, trust model, and ACL engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.mjs",
|
package/src/index.d.ts
CHANGED
|
@@ -381,3 +381,6 @@ export declare const PAD_TRAILER_BYTES: 4;
|
|
|
381
381
|
export declare function paddedLength(length: number, opts?: { buckets?: number[] }): number;
|
|
382
382
|
export declare function padTo(bytes: Uint8Array, opts?: { buckets?: number[] }): Uint8Array;
|
|
383
383
|
export declare function unpad(padded: Uint8Array): Uint8Array;
|
|
384
|
+
|
|
385
|
+
/** Parse a case-sensitive mesh:// or *.mesh.local address. */
|
|
386
|
+
export declare function parseMeshRequest(url: string): { podId: string; path: string } | null;
|
package/src/index.mjs
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Shared browser-safe mesh address parsing. Pod IDs are case sensitive.
|
|
2
|
+
const MESH_PROTOCOL = 'mesh://'
|
|
3
|
+
const MESH_LOCAL_SUFFIX = '.mesh.local'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parse a mesh URL into { podId, path } or null.
|
|
7
|
+
* Supports:
|
|
8
|
+
* - mesh://podId/path
|
|
9
|
+
* - https://podId.mesh.local/path
|
|
10
|
+
* - http://podId.mesh.local/path
|
|
11
|
+
*
|
|
12
|
+
* @param {string} urlStr
|
|
13
|
+
* @returns {{ podId: string, path: string } | null}
|
|
14
|
+
*/
|
|
15
|
+
export function parseMeshRequest(urlStr) {
|
|
16
|
+
if (!urlStr || typeof urlStr !== 'string') return null
|
|
17
|
+
|
|
18
|
+
// --- mesh:// protocol ---
|
|
19
|
+
if (urlStr.startsWith(MESH_PROTOCOL)) {
|
|
20
|
+
const rest = urlStr.slice(MESH_PROTOCOL.length)
|
|
21
|
+
if (!rest) return null
|
|
22
|
+
|
|
23
|
+
const fragment = rest.indexOf('#')
|
|
24
|
+
const address = fragment < 0 ? rest : rest.slice(0, fragment)
|
|
25
|
+
const slashIdx = address.search(/[/?]/)
|
|
26
|
+
let podId, path
|
|
27
|
+
if (slashIdx === -1) {
|
|
28
|
+
podId = address
|
|
29
|
+
path = '/'
|
|
30
|
+
} else {
|
|
31
|
+
podId = address.slice(0, slashIdx)
|
|
32
|
+
path = address.slice(slashIdx) || '/'
|
|
33
|
+
if (path.startsWith('?')) path = '/' + path
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!podId) return null
|
|
37
|
+
return { podId, path }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// --- https://podId.mesh.local/path or http://podId.mesh.local/path ---
|
|
41
|
+
// Extract hostname from the raw string to preserve case (URL() lowercases hostnames).
|
|
42
|
+
const httpMatch = urlStr.match(/^https?:\/\/([^/?#]+)([^#]*)/)
|
|
43
|
+
if (!httpMatch) return null
|
|
44
|
+
|
|
45
|
+
const rawHost = httpMatch[1] // preserves original case
|
|
46
|
+
const lowerHost = rawHost.toLowerCase()
|
|
47
|
+
if (!lowerHost.endsWith(MESH_LOCAL_SUFFIX)) return null
|
|
48
|
+
|
|
49
|
+
const podId = rawHost.slice(0, -MESH_LOCAL_SUFFIX.length)
|
|
50
|
+
if (!podId) return null
|
|
51
|
+
|
|
52
|
+
const suffix = httpMatch[2] || '/'
|
|
53
|
+
const path = suffix.startsWith('?') ? '/' + suffix : suffix
|
|
54
|
+
return { podId, path }
|
|
55
|
+
}
|
|
56
|
+
|