@vibecook/truffle 0.3.25 → 0.4.0
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.
|
@@ -1,10 +1,36 @@
|
|
|
1
1
|
import { NapiNode, type NapiPeerEvent } from '@vibecook/truffle-native';
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link createMeshNode}. RFC 017 shape — `appId` is required,
|
|
4
|
+
* `deviceName` / `deviceId` are optional overrides that the underlying
|
|
5
|
+
* `NodeBuilder` defaults when absent (OS hostname / auto-generated ULID).
|
|
6
|
+
*/
|
|
2
7
|
export interface CreateMeshNodeOptions {
|
|
3
|
-
/**
|
|
4
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Required. Application namespace identifier. Two apps with different
|
|
10
|
+
* `appId`s cannot see each other as peers.
|
|
11
|
+
*
|
|
12
|
+
* Format: `^[a-z][a-z0-9-]{1,31}$` (lowercase letters, digits, hyphens,
|
|
13
|
+
* 2–32 characters, must start with a letter).
|
|
14
|
+
*/
|
|
15
|
+
appId: string;
|
|
16
|
+
/**
|
|
17
|
+
* Optional human-readable device name. Defaults to the OS hostname.
|
|
18
|
+
* May contain any Unicode characters; truffle derives a Tailscale-safe
|
|
19
|
+
* hostname from this automatically.
|
|
20
|
+
*/
|
|
21
|
+
deviceName?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Optional stable per-device ULID. If omitted, one is generated on
|
|
24
|
+
* first run and persisted inside `stateDir`. Provide your own if you
|
|
25
|
+
* want to federate identity with an existing user system.
|
|
26
|
+
*/
|
|
27
|
+
deviceId?: string;
|
|
5
28
|
/** Override sidecar path. If omitted, auto-resolved. */
|
|
6
29
|
sidecarPath?: string;
|
|
7
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* State directory for Tailscale. Defaults to
|
|
32
|
+
* `{userDataDir}/truffle/{appId}/{slug(deviceName)}`.
|
|
33
|
+
*/
|
|
8
34
|
stateDir?: string;
|
|
9
35
|
/** Tailscale auth key (for headless/CI setups). */
|
|
10
36
|
authKey?: string;
|
|
@@ -37,12 +63,13 @@ export interface CreateMeshNodeOptions {
|
|
|
37
63
|
* @example
|
|
38
64
|
* ```ts
|
|
39
65
|
* const node = await createMeshNode({
|
|
40
|
-
*
|
|
66
|
+
* appId: 'playground',
|
|
67
|
+
* deviceName: 'alice-mbp',
|
|
41
68
|
* onPeerChange: (event) => console.log('Peer event:', event),
|
|
42
69
|
* });
|
|
43
70
|
*
|
|
44
71
|
* const peers = await node.getPeers();
|
|
45
|
-
* await node.send(
|
|
72
|
+
* await node.send(peers[0].deviceId, 'chat', Buffer.from(JSON.stringify({ text: 'hello' })));
|
|
46
73
|
* ```
|
|
47
74
|
*/
|
|
48
75
|
export declare function createMeshNode(options: CreateMeshNodeOptions): Promise<NapiNode>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-mesh-node.d.ts","sourceRoot":"","sources":["../src/create-mesh-node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAuB,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAG7F,MAAM,WAAW,qBAAqB;IACpC,
|
|
1
|
+
{"version":3,"file":"create-mesh-node.d.ts","sourceRoot":"","sources":["../src/create-mesh-node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAuB,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAG7F;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qEAAqE;IACrE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,qEAAqE;IACrE,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,+EAA+E;IAC/E,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CAC/C;AAmBD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuDtF"}
|
package/dist/create-mesh-node.js
CHANGED
|
@@ -30,16 +30,17 @@ function defaultOpenUrl(url) {
|
|
|
30
30
|
* @example
|
|
31
31
|
* ```ts
|
|
32
32
|
* const node = await createMeshNode({
|
|
33
|
-
*
|
|
33
|
+
* appId: 'playground',
|
|
34
|
+
* deviceName: 'alice-mbp',
|
|
34
35
|
* onPeerChange: (event) => console.log('Peer event:', event),
|
|
35
36
|
* });
|
|
36
37
|
*
|
|
37
38
|
* const peers = await node.getPeers();
|
|
38
|
-
* await node.send(
|
|
39
|
+
* await node.send(peers[0].deviceId, 'chat', Buffer.from(JSON.stringify({ text: 'hello' })));
|
|
39
40
|
* ```
|
|
40
41
|
*/
|
|
41
42
|
export async function createMeshNode(options) {
|
|
42
|
-
const {
|
|
43
|
+
const { appId, deviceName, deviceId, autoAuth = true, openUrl: customOpenUrl, onAuthRequired, onPeerChange, sidecarPath, stateDir, authKey, ephemeral, wsPort, } = options;
|
|
43
44
|
const resolvedSidecarPath = sidecarPath ?? resolveSidecarPath();
|
|
44
45
|
const node = new NapiNode();
|
|
45
46
|
// IMPORTANT: install the auth-required callback BEFORE calling `start()`.
|
|
@@ -58,7 +59,9 @@ export async function createMeshNode(options) {
|
|
|
58
59
|
onAuthRequired?.(url);
|
|
59
60
|
});
|
|
60
61
|
const config = {
|
|
61
|
-
|
|
62
|
+
appId,
|
|
63
|
+
deviceName,
|
|
64
|
+
deviceId,
|
|
62
65
|
sidecarPath: resolvedSidecarPath,
|
|
63
66
|
stateDir,
|
|
64
67
|
authKey,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-mesh-node.js","sourceRoot":"","sources":["../src/create-mesh-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAA2C,MAAM,0BAA0B,CAAC;AAC7F,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"create-mesh-node.js","sourceRoot":"","sources":["../src/create-mesh-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAA2C,MAAM,0BAA0B,CAAC;AAC7F,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAyDlD;;GAEG;AACH,SAAS,cAAc,CAAC,GAAW;IACjC,IAAI,CAAC;QACH,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAClC,QAAQ,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC;QAC5B,CAAC;aAAM,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YACxC,QAAQ,CAAC,aAAa,GAAG,GAAG,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,aAAa,GAAG,GAAG,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,gBAAgB;IAClB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAA8B;IACjE,MAAM,EACJ,KAAK,EACL,UAAU,EACV,QAAQ,EACR,QAAQ,GAAG,IAAI,EACf,OAAO,EAAE,aAAa,EACtB,cAAc,EACd,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,OAAO,EACP,SAAS,EACT,MAAM,GACP,GAAG,OAAO,CAAC;IAEZ,MAAM,mBAAmB,GAAG,WAAW,IAAI,kBAAkB,EAAE,CAAC;IAEhE,MAAM,IAAI,GAAG,IAAI,QAAQ,EAAE,CAAC;IAE5B,0EAA0E;IAC1E,wEAAwE;IACxE,iEAAiE;IACjE,wEAAwE;IACxE,gEAAgE;IAChE,EAAE;IACF,0EAA0E;IAC1E,4DAA4D;IAC5D,IAAI,CAAC,cAAc,CAAC,CAAC,GAAW,EAAE,EAAE;QAClC,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,MAAM,GAAG,aAAa,IAAI,cAAc,CAAC;YAC/C,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC;QACD,cAAc,EAAE,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAmB;QAC7B,KAAK;QACL,UAAU;QACV,QAAQ;QACR,WAAW,EAAE,mBAAmB;QAChC,QAAQ;QACR,OAAO;QACP,SAAS;QACT,MAAM;KACP,CAAC;IAEF,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAEzB,0EAA0E;IAC1E,IAAI,YAAY,EAAE,CAAC;QACjB,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibecook/truffle",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Mesh networking for local-first apps, built on Tailscale",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "James Yong",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"scripts"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@vibecook/truffle-native": "0.
|
|
47
|
+
"@vibecook/truffle-native": "0.4.0"
|
|
48
48
|
},
|
|
49
49
|
"optionalDependencies": {
|
|
50
50
|
"@vibecook/truffle-sidecar-darwin-arm64": "^0.3.0",
|