@vibecook/truffle 0.2.3 → 0.3.22

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.
@@ -0,0 +1,49 @@
1
+ import { NapiNode, type NapiPeerEvent } from '@vibecook/truffle-native';
2
+ export interface CreateMeshNodeOptions {
3
+ /** Node name (becomes the Tailscale hostname prefix). */
4
+ name: string;
5
+ /** Override sidecar path. If omitted, auto-resolved. */
6
+ sidecarPath?: string;
7
+ /** State directory for Tailscale. */
8
+ stateDir?: string;
9
+ /** Tailscale auth key (for headless/CI setups). */
10
+ authKey?: string;
11
+ /** Whether this node is ephemeral (removed from tailnet on stop). */
12
+ ephemeral?: boolean;
13
+ /** WebSocket listener port (0 = auto). */
14
+ wsPort?: number;
15
+ /**
16
+ * Auto-open the Tailscale auth URL in the default browser.
17
+ * Defaults to true. Set to false to handle auth manually.
18
+ */
19
+ autoAuth?: boolean;
20
+ /**
21
+ * Custom URL opener. Overrides the default browser opener.
22
+ * Useful in Electron where you'd use `shell.openExternal()`.
23
+ */
24
+ openUrl?: (url: string) => void;
25
+ /** Called when Tailscale auth is required. Receives the auth URL. */
26
+ onAuthRequired?: (url: string) => void;
27
+ /** Called for peer change events (join, leave, update, ws_connected, etc.). */
28
+ onPeerChange?: (event: NapiPeerEvent) => void;
29
+ }
30
+ /**
31
+ * Create and start a Truffle node with sensible defaults.
32
+ *
33
+ * - Auto-resolves the sidecar binary path
34
+ * - Auto-opens the Tailscale auth URL in the browser (configurable)
35
+ * - Provides auth and peer lifecycle callbacks
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const node = await createMeshNode({
40
+ * name: 'my-app',
41
+ * onPeerChange: (event) => console.log('Peer event:', event),
42
+ * });
43
+ *
44
+ * const peers = await node.getPeers();
45
+ * await node.send('peer-id', 'chat', Buffer.from(JSON.stringify({ text: 'hello' })));
46
+ * ```
47
+ */
48
+ export declare function createMeshNode(options: CreateMeshNodeOptions): Promise<NapiNode>;
49
+ //# sourceMappingURL=create-mesh-node.d.ts.map
@@ -0,0 +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,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qCAAqC;IACrC,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;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2CtF"}
@@ -0,0 +1,67 @@
1
+ import { execSync } from 'node:child_process';
2
+ import { NapiNode } from '@vibecook/truffle-native';
3
+ import { resolveSidecarPath } from './sidecar.js';
4
+ /**
5
+ * Open a URL in the system's default browser.
6
+ */
7
+ function defaultOpenUrl(url) {
8
+ try {
9
+ if (process.platform === 'darwin') {
10
+ execSync(`open "${url}"`);
11
+ }
12
+ else if (process.platform === 'win32') {
13
+ execSync(`start "" "${url}"`);
14
+ }
15
+ else {
16
+ execSync(`xdg-open "${url}"`);
17
+ }
18
+ }
19
+ catch {
20
+ // Silently fail
21
+ }
22
+ }
23
+ /**
24
+ * Create and start a Truffle node with sensible defaults.
25
+ *
26
+ * - Auto-resolves the sidecar binary path
27
+ * - Auto-opens the Tailscale auth URL in the browser (configurable)
28
+ * - Provides auth and peer lifecycle callbacks
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const node = await createMeshNode({
33
+ * name: 'my-app',
34
+ * onPeerChange: (event) => console.log('Peer event:', event),
35
+ * });
36
+ *
37
+ * const peers = await node.getPeers();
38
+ * await node.send('peer-id', 'chat', Buffer.from(JSON.stringify({ text: 'hello' })));
39
+ * ```
40
+ */
41
+ export async function createMeshNode(options) {
42
+ const { name, autoAuth = true, openUrl: customOpenUrl, onAuthRequired, onPeerChange, sidecarPath, stateDir, authKey, ephemeral, wsPort, } = options;
43
+ const resolvedSidecarPath = sidecarPath ?? resolveSidecarPath();
44
+ const node = new NapiNode();
45
+ const config = {
46
+ name,
47
+ sidecarPath: resolvedSidecarPath,
48
+ stateDir,
49
+ authKey,
50
+ ephemeral,
51
+ wsPort,
52
+ };
53
+ await node.start(config);
54
+ // Subscribe to peer events for auth handling and user callback
55
+ node.onPeerChange((event) => {
56
+ if (event.eventType === 'auth_required' && event.authUrl) {
57
+ if (autoAuth) {
58
+ const opener = customOpenUrl ?? defaultOpenUrl;
59
+ opener(event.authUrl);
60
+ }
61
+ onAuthRequired?.(event.authUrl);
62
+ }
63
+ onPeerChange?.(event);
64
+ });
65
+ return node;
66
+ }
67
+ //# sourceMappingURL=create-mesh-node.js.map
@@ -0,0 +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,c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AAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACxB,CAAC;YACD,cAAc,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;QAED,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { NapiMeshNode, NapiFileTransferAdapter, NapiMessageBus, NapiStoreSyncAdapter, } from '@vibecook/truffle-native';
2
- export type { NapiMeshNodeConfig, NapiMeshTimingConfig, NapiBaseDevice, NapiIncomingMessage, NapiTailnetPeer, NapiMeshEvent, NapiFileTransferAdapterConfig, NapiFileTransferOffer, NapiAdapterTransferInfo, NapiBusMessage, NapiFileTransferEvent, NapiStoreSyncConfig, NapiOutgoingSyncMessage, NapiDeviceSlice, } from '@vibecook/truffle-native';
1
+ export { NapiNode, NapiFileTransfer } from '@vibecook/truffle-native';
2
+ export type { NapiNodeConfig, NapiNodeIdentity, NapiPeer, NapiPingResult, NapiHealthInfo, NapiPeerEvent, NapiNamespacedMessage, NapiFileOffer, NapiTransferResult, NapiTransferProgress, NapiFileTransferEvent, } from '@vibecook/truffle-native';
3
3
  export { resolveSidecarPath } from './sidecar.js';
4
+ export { createMeshNode, type CreateMeshNodeOptions } from './create-mesh-node.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,cAAc,EACd,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAGlC,YAAY,EACV,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,6BAA6B,EAC7B,qBAAqB,EACrB,uBAAuB,EACvB,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACvB,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAGtE,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGlD,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // Re-export classes (values) from the native Rust addon
2
- export { NapiMeshNode, NapiFileTransferAdapter, NapiMessageBus, NapiStoreSyncAdapter, } from '@vibecook/truffle-native';
2
+ export { NapiNode, NapiFileTransfer } from '@vibecook/truffle-native';
3
3
  // Sidecar binary resolution
4
4
  export { resolveSidecarPath } from './sidecar.js';
5
+ // High-level API
6
+ export { createMeshNode } from './create-mesh-node.js';
5
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,cAAc,EACd,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAoBlC,4BAA4B;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAiBtE,4BAA4B;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,iBAAiB;AACjB,OAAO,EAAE,cAAc,EAA8B,MAAM,uBAAuB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibecook/truffle",
3
- "version": "0.2.3",
3
+ "version": "0.3.22",
4
4
  "description": "Mesh networking for local-first apps, built on Tailscale",
5
5
  "license": "MIT",
6
6
  "author": "James Yong",
@@ -43,23 +43,23 @@
43
43
  "bin",
44
44
  "scripts"
45
45
  ],
46
+ "scripts": {
47
+ "build": "tsc",
48
+ "clean": "rm -rf dist",
49
+ "typecheck": "tsc --noEmit",
50
+ "postinstall": "node scripts/postinstall.cjs"
51
+ },
46
52
  "dependencies": {
47
- "@vibecook/truffle-native": "0.2.3"
53
+ "@vibecook/truffle-native": "workspace:*"
48
54
  },
49
55
  "optionalDependencies": {
50
- "@vibecook/truffle-sidecar-darwin-arm64": "0.1.0",
51
- "@vibecook/truffle-sidecar-darwin-x64": "0.1.0",
52
- "@vibecook/truffle-sidecar-linux-x64": "0.1.0",
53
- "@vibecook/truffle-sidecar-linux-arm64": "0.1.0",
54
- "@vibecook/truffle-sidecar-win32-x64": "0.1.0"
56
+ "@vibecook/truffle-sidecar-darwin-arm64": "^0.3.0",
57
+ "@vibecook/truffle-sidecar-darwin-x64": "^0.3.0",
58
+ "@vibecook/truffle-sidecar-linux-x64": "^0.3.0",
59
+ "@vibecook/truffle-sidecar-linux-arm64": "^0.3.0",
60
+ "@vibecook/truffle-sidecar-win32-x64": "^0.3.0"
55
61
  },
56
62
  "devDependencies": {
57
63
  "typescript": "^5.7.0"
58
- },
59
- "scripts": {
60
- "build": "tsc",
61
- "clean": "rm -rf dist",
62
- "typecheck": "tsc --noEmit",
63
- "postinstall": "node scripts/postinstall.cjs"
64
64
  }
65
- }
65
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 James Yong
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.