@vibecook/truffle 0.6.0 → 0.7.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/dist/serve.js ADDED
@@ -0,0 +1,347 @@
1
+ // Declarative HTTP serving over the tailnet (RFC 023 §6.2, Phase 3).
2
+ //
3
+ // `mesh.serve(config)` is the one ergonomic verb for publishing a local
4
+ // service or a static directory to the whole tailnet, mirroring the
5
+ // `tailscale serve` mental model. It is sugar over the shipped proxy engine
6
+ // (`mesh.proxy()` / Rust `Node::proxy()`): a serve handle maps 1:1 to a proxy
7
+ // `id`, and every config shape below normalizes to one `NapiProxyConfig`.
8
+ //
9
+ // The docs rule (RFC 023 §5, D2): you wrote the request handler →
10
+ // `mesh.http.createServer`; it's a directory or another process → `serve`.
11
+ //
12
+ // Three config shapes, one function:
13
+ // • { port, target } — forward a whole port to a backend
14
+ // • { port, dir, fallback? } — serve a static directory (SPA)
15
+ // • { port, routes } — mixed path routes (SPA + APIs)
16
+ //
17
+ // TLS defaults ON here (unlike `createServer`): the audience is browsers, and
18
+ // this preserves the shipped engine's always-TLS behavior (RFC 023 D5).
19
+ import { EventEmitter } from 'node:events';
20
+ import { resolve as resolvePath } from 'node:path';
21
+ /**
22
+ * A running serve, 1:1 with a proxy `id`. An `EventEmitter` for runtime
23
+ * errors:
24
+ *
25
+ * - `'serveError'` — `(info: ServeErrorInfo)`. Always emitted; safe to leave
26
+ * unlistened. Prefer this for programmatic handling.
27
+ * - `'error'` — `(info: ServeErrorInfo)`. Emitted **only when a listener is
28
+ * attached** (an unlistened EventEmitter `'error'` throws and would crash
29
+ * the process). Same payload as `'serveError'`.
30
+ * - `'close'` — the proxy stopped (via {@link close} or a sidecar-side stop).
31
+ * Fires once.
32
+ */
33
+ export class ServeHandle extends EventEmitter {
34
+ /** The proxy id backing this serve. */
35
+ id;
36
+ /**
37
+ * The normalized, frozen config that created this handle — every default
38
+ * filled and every `dir` resolved to an absolute path. Persist it and
39
+ * replay `mesh.serve(handle.config)` to recreate an identical serve
40
+ * (RFC 023 D16); the library never persists on its own.
41
+ */
42
+ config;
43
+ #url = '';
44
+ #port = 0;
45
+ #proxy;
46
+ #retire;
47
+ #closed = false;
48
+ #closeEmitted = false;
49
+ /** @internal Constructed by {@link createServeNamespace}. */
50
+ constructor(id, config, proxy, retire) {
51
+ super();
52
+ this.id = id;
53
+ this.config = config;
54
+ this.#proxy = proxy;
55
+ this.#retire = retire;
56
+ }
57
+ /** Public serving URL from the `add()` result (`https://name.tailnet.ts.net[:port]`). */
58
+ get url() {
59
+ return this.#url;
60
+ }
61
+ /** Tailnet port the serve is listening on (resolved from the `add()` result). */
62
+ get port() {
63
+ return this.#port;
64
+ }
65
+ /** @internal Fill url/port from the `NapiProxyInfo` once `add()` resolves. */
66
+ _start(url, port) {
67
+ this.#url = url;
68
+ this.#port = port;
69
+ }
70
+ /** @internal Route a `'error'` proxy event to this handle. */
71
+ _onError(code, message) {
72
+ const info = { code: code ?? '', message: message ?? '' };
73
+ // 'serveError' never crashes an unlistened emitter; mirror onto the
74
+ // conventional 'error' only when someone is listening.
75
+ this.emit('serveError', info);
76
+ if (this.listenerCount('error') > 0)
77
+ this.emit('error', info);
78
+ }
79
+ /** @internal Route a `'stopped'` proxy event to this handle. */
80
+ _onStopped() {
81
+ if (this.#closed)
82
+ return;
83
+ this.#closed = true;
84
+ this.#retire();
85
+ this.#emitClose();
86
+ }
87
+ /**
88
+ * Stop serving and release the tailnet port (`proxy.remove(id)`). Emits
89
+ * `'close'` once. Idempotent.
90
+ */
91
+ async close() {
92
+ if (this.#closed)
93
+ return;
94
+ this.#closed = true;
95
+ this.#retire();
96
+ try {
97
+ await this.#proxy.remove(this.id);
98
+ }
99
+ finally {
100
+ this.#emitClose();
101
+ }
102
+ }
103
+ #emitClose() {
104
+ if (this.#closeEmitted)
105
+ return;
106
+ this.#closeEmitted = true;
107
+ this.emit('close');
108
+ }
109
+ }
110
+ /**
111
+ * Normalize any {@link ServeConfig} shape into the single `NapiProxyConfig`
112
+ * the proxy engine consumes. Pure and deterministic; exported so the shape
113
+ * can be asserted directly. Throws on a `funnel` key (reserved), a malformed
114
+ * shape, or a non-http(s) `target`.
115
+ */
116
+ export function normalizeServeConfig(config) {
117
+ return canonicalToNapi(canonicalServeConfig(config));
118
+ }
119
+ /**
120
+ * Build the `mesh.serve` verb over a lazy proxy getter. `getProxy` is called
121
+ * per serve (NapiProxy handles are per-call); proxy events are node-global,
122
+ * so one `onEvent` subscription — installed on the first serve — routes
123
+ * runtime errors and stops to every live handle by id.
124
+ */
125
+ export function createServeNamespace(getProxy) {
126
+ const handles = new Map();
127
+ let eventProxy = null;
128
+ function routeEvent(ev) {
129
+ const handle = handles.get(ev.id);
130
+ if (!handle)
131
+ return;
132
+ if (ev.eventType === 'error') {
133
+ handle._onError(ev.code, ev.message);
134
+ }
135
+ else if (ev.eventType === 'stopped') {
136
+ handle._onStopped();
137
+ }
138
+ // 'started' carries url/listenPort, but the add() result already gives us
139
+ // those synchronously — nothing to route.
140
+ }
141
+ function ensureSubscribed(proxy) {
142
+ if (eventProxy)
143
+ return;
144
+ // Retain the subscribed handle so the native subscription outlives GC of
145
+ // this NapiProxy. Events are node-global (all handles share one Arc<Node>).
146
+ eventProxy = proxy;
147
+ proxy.onEvent(routeEvent);
148
+ }
149
+ return async function serve(config) {
150
+ const canonical = canonicalServeConfig(config); // throws: funnel / bad shape
151
+ const napiConfig = canonicalToNapi(canonical); // throws: non-http(s) target
152
+ const replayConfig = deepFreeze(canonical);
153
+ const id = napiConfig.id;
154
+ if (handles.has(id)) {
155
+ throw new Error(`serve: id ${JSON.stringify(id)} is already serving on this node — ` +
156
+ 'pass a distinct `id` (the default is `serve-${port}`, so two serves ' +
157
+ 'on the same port collide).');
158
+ }
159
+ const proxy = getProxy();
160
+ // Subscribe and register the handle before add() resolves, so a runtime
161
+ // error emitted the instant the listener starts is routed, not dropped.
162
+ ensureSubscribed(proxy);
163
+ const handle = new ServeHandle(id, replayConfig, proxy, () => {
164
+ if (handles.get(id) === handle)
165
+ handles.delete(id);
166
+ });
167
+ handles.set(id, handle);
168
+ try {
169
+ const info = await proxy.add(napiConfig);
170
+ handle._start(info.url, info.listenPort);
171
+ return handle;
172
+ }
173
+ catch (err) {
174
+ if (handles.get(id) === handle)
175
+ handles.delete(id);
176
+ throw err;
177
+ }
178
+ };
179
+ }
180
+ // ─── normalization ────────────────────────────────────────────────────────
181
+ /**
182
+ * Fill defaults, resolve dirs to absolute, and validate — producing a
183
+ * canonical {@link ServeConfig} that is its own replayable form. Idempotent:
184
+ * `canonicalServeConfig(canonicalServeConfig(x))` normalizes identically, so
185
+ * replaying `handle.config` reproduces the original `NapiProxyConfig`.
186
+ */
187
+ function canonicalServeConfig(config) {
188
+ if (!config || typeof config !== 'object') {
189
+ throw new TypeError('serve: config must be an object');
190
+ }
191
+ const c = config;
192
+ if (c.funnel !== undefined) {
193
+ throw new Error('funnel is not supported yet — RFC 023 §9.6 reserves it for a future phase');
194
+ }
195
+ if (!Number.isInteger(c.port) || c.port < 0 || c.port > 65535) {
196
+ throw new TypeError(`serve: invalid port ${String(c.port)} (expected an integer 0–65535)`);
197
+ }
198
+ const shapes = Number(c.target !== undefined) + Number(c.dir !== undefined) + Number(c.routes !== undefined);
199
+ if (shapes !== 1) {
200
+ throw new TypeError(`serve: config must have exactly one of \`target\`, \`dir\`, or \`routes\` (got ${shapes === 0 ? 'none' : 'several'})`);
201
+ }
202
+ const id = c.id ?? `serve-${c.port}`;
203
+ const common = {
204
+ port: c.port,
205
+ id,
206
+ name: c.name ?? id,
207
+ tls: c.tls ?? true,
208
+ };
209
+ if (c.allow !== undefined)
210
+ common.allow = [...c.allow];
211
+ if (c.allowNonLoopback !== undefined)
212
+ common.allowNonLoopback = c.allowNonLoopback;
213
+ if (c.target !== undefined) {
214
+ return { ...common, target: c.target };
215
+ }
216
+ if (c.dir !== undefined) {
217
+ const out = { ...common, dir: resolvePath(c.dir) };
218
+ if (c.fallback !== undefined)
219
+ out.fallback = c.fallback;
220
+ return out;
221
+ }
222
+ const routesIn = c.routes;
223
+ if (Object.keys(routesIn).length === 0) {
224
+ throw new TypeError('serve: `routes` must have at least one entry');
225
+ }
226
+ const routes = {};
227
+ for (const [prefix, value] of Object.entries(routesIn)) {
228
+ routes[prefix] = canonicalRouteValue(value);
229
+ }
230
+ return { ...common, routes };
231
+ }
232
+ /** Canonicalize one route value: string stays a URL; object resolves its dir. */
233
+ function canonicalRouteValue(value) {
234
+ if (typeof value === 'string')
235
+ return value;
236
+ if (!value || typeof value !== 'object') {
237
+ throw new TypeError('serve: a route value must be a URL string or a route object');
238
+ }
239
+ const hasTarget = value.target !== undefined;
240
+ const hasDir = value.dir !== undefined;
241
+ if (hasTarget === hasDir) {
242
+ throw new TypeError('serve: each route object needs exactly one of `target` or `dir`');
243
+ }
244
+ const out = {};
245
+ if (hasTarget) {
246
+ out.target = value.target;
247
+ if (value.stripPrefix !== undefined)
248
+ out.stripPrefix = value.stripPrefix;
249
+ }
250
+ else {
251
+ out.dir = resolvePath(value.dir);
252
+ if (value.fallback !== undefined)
253
+ out.fallback = value.fallback;
254
+ }
255
+ if (value.allow !== undefined)
256
+ out.allow = [...value.allow];
257
+ return out;
258
+ }
259
+ /** Convert a canonical config (defaults filled, dirs absolute) to NAPI shape. */
260
+ function canonicalToNapi(config) {
261
+ const c = config;
262
+ const napi = {
263
+ id: c.id,
264
+ name: c.name,
265
+ listenPort: c.port,
266
+ // Ignored when `routes` is present; the NAPI field is required (RFC 023).
267
+ targetPort: 0,
268
+ tls: c.tls,
269
+ };
270
+ if (c.allow !== undefined)
271
+ napi.allow = [...c.allow];
272
+ if (c.allowNonLoopback !== undefined)
273
+ napi.allowNonLoopback = c.allowNonLoopback;
274
+ if (c.target !== undefined) {
275
+ const { host, port, scheme } = parseTargetUrl(c.target);
276
+ napi.targetHost = host;
277
+ napi.targetPort = port;
278
+ napi.targetScheme = scheme;
279
+ return napi;
280
+ }
281
+ const routes = [];
282
+ if (c.dir !== undefined) {
283
+ const route = { prefix: '/', dir: c.dir };
284
+ if (c.fallback !== undefined)
285
+ route.fallback = c.fallback;
286
+ routes.push(route);
287
+ }
288
+ else {
289
+ for (const [prefix, value] of Object.entries(c.routes)) {
290
+ routes.push(routeValueToNapi(prefix, value));
291
+ }
292
+ }
293
+ napi.routes = routes;
294
+ return napi;
295
+ }
296
+ /** Convert a canonical route value to a `NapiProxyRoute`. */
297
+ function routeValueToNapi(prefix, value) {
298
+ const route = { prefix };
299
+ if (typeof value === 'string') {
300
+ route.targetUrl = value;
301
+ return route;
302
+ }
303
+ if (value.target !== undefined) {
304
+ route.targetUrl = value.target;
305
+ if (value.stripPrefix !== undefined)
306
+ route.stripPrefix = value.stripPrefix;
307
+ }
308
+ else {
309
+ route.dir = value.dir;
310
+ if (value.fallback !== undefined)
311
+ route.fallback = value.fallback;
312
+ }
313
+ if (value.allow !== undefined)
314
+ route.allow = [...value.allow];
315
+ return route;
316
+ }
317
+ /**
318
+ * Parse an http(s) target URL into host/port/scheme. A bare `host:port`
319
+ * (no scheme) is rejected: WHATWG URL reads `localhost` as a scheme, so it
320
+ * fails the http(s) check with a pointer to add `http://`.
321
+ */
322
+ function parseTargetUrl(target) {
323
+ let url;
324
+ try {
325
+ url = new URL(target);
326
+ }
327
+ catch {
328
+ throw new TypeError(`serve: invalid target URL ${JSON.stringify(target)} — pass a full http(s) URL, e.g. "http://localhost:3000"`);
329
+ }
330
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
331
+ throw new TypeError(`serve: target must be an http:// or https:// URL, got ${JSON.stringify(target)} ` +
332
+ '(a bare "host:port" is read as a URL scheme — include http://)');
333
+ }
334
+ const scheme = url.protocol.slice(0, -1);
335
+ const port = url.port ? Number(url.port) : scheme === 'https' ? 443 : 80;
336
+ return { host: url.hostname, port, scheme };
337
+ }
338
+ /** Recursively freeze an object graph (config + nested routes/arrays). */
339
+ function deepFreeze(value) {
340
+ if (value && typeof value === 'object' && !Object.isFrozen(value)) {
341
+ for (const child of Object.values(value))
342
+ deepFreeze(child);
343
+ Object.freeze(value);
344
+ }
345
+ return value;
346
+ }
347
+ //# sourceMappingURL=serve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,EAAE;AACF,wEAAwE;AACxE,oEAAoE;AACpE,4EAA4E;AAC5E,8EAA8E;AAC9E,0EAA0E;AAC1E,EAAE;AACF,kEAAkE;AAClE,2EAA2E;AAC3E,EAAE;AACF,qCAAqC;AACrC,+EAA+E;AAC/E,4EAA4E;AAC5E,4EAA4E;AAC5E,EAAE;AACF,8EAA8E;AAC9E,wEAAwE;AAExE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AAwGnD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,WAAY,SAAQ,YAAY;IAC3C,uCAAuC;IAC9B,EAAE,CAAS;IACpB;;;;;OAKG;IACM,MAAM,CAAc;IAE7B,IAAI,GAAG,EAAE,CAAC;IACV,KAAK,GAAG,CAAC,CAAC;IACV,MAAM,CAAY;IAClB,OAAO,CAAa;IACpB,OAAO,GAAG,KAAK,CAAC;IAChB,aAAa,GAAG,KAAK,CAAC;IAEtB,6DAA6D;IAC7D,YAAY,EAAU,EAAE,MAAmB,EAAE,KAAgB,EAAE,MAAkB;QAC/E,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,yFAAyF;IACzF,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,iFAAiF;IACjF,IAAI,IAAI;QACN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AC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACzE,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC9C,CAAC;AAED,0EAA0E;AAC1E,SAAS,UAAU,CAAI,KAAQ;IAC7B,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAClE,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;YAAE,UAAU,CAAC,KAAK,CAAC,CAAC;QAC5D,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
package/dist/ws.d.ts CHANGED
@@ -31,7 +31,8 @@ export interface TruffleWsServer extends WsServerInstance {
31
31
  export interface TruffleWsServerOptions {
32
32
  /**
33
33
  * Mesh port to listen on. `0` binds an ephemeral port (read it back from
34
- * `server.port`). Ports 443 and 9417 are reserved by the mesh and rejected.
34
+ * `server.port`). The session WebSocket port (default 9417) is reserved
35
+ * and rejected.
35
36
  */
36
37
  port: number;
37
38
  /**
@@ -39,6 +40,12 @@ export interface TruffleWsServerOptions {
39
40
  * whose URL path matches are accepted; others get a `400`-style socket close.
40
41
  */
41
42
  path?: string;
43
+ /**
44
+ * Terminate TLS in the sidecar with automatic MagicDNS certificates so
45
+ * browsers can connect via `wss://name.tailnet.ts.net` (RFC 023 §7.1).
46
+ * Same prerequisites as `mesh.http.createServer({ tls: true })`.
47
+ */
48
+ tls?: boolean;
42
49
  }
43
50
  /** WebSocket-over-mesh namespace bound to a mesh node's `net` namespace. */
44
51
  export interface TruffleWs {
package/dist/ws.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings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CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CACzE;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,GAAE,QAAmB,GAAG,SAAS,CAgGvF"}
package/dist/ws.js CHANGED
@@ -13,7 +13,7 @@
13
13
  // lazy async functions that `await import('ws')` on first use and throw a
14
14
  // clear, actionable error when it's missing.
15
15
  import http from 'node:http';
16
- import { MeshAgent } from './http.js';
16
+ import { MeshAgent, createMeshHttpServer } from './http.js';
17
17
  import { peerLikeToQuery } from './peer.js';
18
18
  /**
19
19
  * Hostname placed in the `ws://` URL when the caller's peer reference can't be
@@ -93,10 +93,12 @@ export function createWsNamespace(net, load = importWs) {
93
93
  }
94
94
  async function createServer(options) {
95
95
  const { WebSocketServer } = await loadWs();
96
- // A throwaway http.Server does the HTTP/WebSocket upgrade parsing; a
97
- // noServer WebSocketServer completes the handshake. We never `.listen()`
98
- // this http server on a host port — mesh connections are fed in by hand.
99
- const httpServer = http.createServer();
96
+ // A mesh-listening http.Server (the shared RFC 023 engine) does the
97
+ // HTTP/WebSocket upgrade parsing; a noServer WebSocketServer completes
98
+ // the handshake — the seams `ws` documents for custom transports.
99
+ const httpServer = options.tls
100
+ ? createMeshHttpServer(net, { tls: true })
101
+ : createMeshHttpServer(net);
100
102
  const wss = new WebSocketServer({ noServer: true, path: options.path });
101
103
  httpServer.on('upgrade', (req, socket, head) => {
102
104
  // `ws`'s own path check: true when no `path` was set, else on a match.
@@ -110,31 +112,26 @@ export function createWsNamespace(net, load = importWs) {
110
112
  });
111
113
  });
112
114
  });
113
- // Each mesh TCP connection becomes an http.Server 'connection' — exactly
114
- // what a real listening socket would emit — so http parses it and, on an
115
- // Upgrade request, fires the 'upgrade' handler above.
116
- const meshServer = net.createServer((sock) => httpServer.emit('connection', sock));
117
115
  await new Promise((resolve, reject) => {
118
116
  const onError = (err) => reject(err);
119
- meshServer.once('error', onError);
120
- meshServer.listen(options.port, () => {
121
- meshServer.removeListener('error', onError);
117
+ httpServer.once('error', onError);
118
+ httpServer.listen(options.port, () => {
119
+ httpServer.removeListener('error', onError);
122
120
  resolve();
123
121
  });
124
122
  });
125
123
  const server = wss;
126
124
  Object.defineProperty(server, 'port', {
127
- value: meshServer.port ?? options.port,
125
+ value: httpServer.port ?? options.port,
128
126
  enumerable: true,
129
127
  });
130
- // close() also tears down the mesh listener and any live client sockets;
131
- // the http.Server holds no listening socket, so there's nothing to close
132
- // there. Keep ws's void-returning signature so the type stays a ws Server.
128
+ // close() also tears down the mesh listener and any live client sockets.
129
+ // Keep ws's void-returning signature so the type stays a ws Server.
133
130
  const closeWs = wss.close.bind(wss);
134
131
  server.close = (callback) => {
135
132
  for (const client of wss.clients)
136
133
  client.close();
137
- meshServer.close();
134
+ httpServer.close();
138
135
  closeWs(callback);
139
136
  };
140
137
  return server;
package/dist/ws.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ws.js","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,EAAE;AACF,+EAA+E;AAC/E,6EAA6E;AAC7E,4EAA4E;AAC5E,+EAA+E;AAC/E,qEAAqE;AACrE,+EAA+E;AAC/E,iDAAiD;AACjD,EAAE;AACF,gFAAgF;AAChF,+EAA+E;AAC/E,0EAA0E;AAC1E,6CAA6C;AAE7C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,eAAe,EAAiB,MAAM,WAAW,CAAC;AAU3D;;;;;;;GAOG;AACH,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAE3C;;;;;;;GAOG;AACH,MAAM,OAAO,GAAG,eAAe,CAAC;AAiBhC,MAAM,QAAQ,GAAa,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAuB,CAAC;AAEpE;;;;;;;GAOG;AACH,MAAM,WAAY,SAA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ACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibecook/truffle",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
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
  "sidecar-checksums.json"
45
45
  ],
46
46
  "dependencies": {
47
- "@vibecook/truffle-native": "0.6.0"
47
+ "@vibecook/truffle-native": "0.7.1"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "ws": ">=8"
@@ -55,11 +55,11 @@
55
55
  }
56
56
  },
57
57
  "optionalDependencies": {
58
- "@vibecook/truffle-sidecar-darwin-arm64": "0.6.0",
59
- "@vibecook/truffle-sidecar-darwin-x64": "0.6.0",
60
- "@vibecook/truffle-sidecar-linux-x64": "0.6.0",
61
- "@vibecook/truffle-sidecar-linux-arm64": "0.6.0",
62
- "@vibecook/truffle-sidecar-win32-x64": "0.6.0"
58
+ "@vibecook/truffle-sidecar-darwin-x64": "0.7.1",
59
+ "@vibecook/truffle-sidecar-linux-x64": "0.7.1",
60
+ "@vibecook/truffle-sidecar-linux-arm64": "0.7.1",
61
+ "@vibecook/truffle-sidecar-darwin-arm64": "0.7.1",
62
+ "@vibecook/truffle-sidecar-win32-x64": "0.7.1"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@types/ws": "^8.5.13",
@@ -27,5 +27,19 @@
27
27
  "tsnet-sidecar-linux-amd64": "60685581e7d8d54e543e42c85aadefe191d5cda94e346385e89ad1043a0ed690",
28
28
  "tsnet-sidecar-linux-arm64": "411937ec5dc12f2842846454e8da5698e81db30e37caef6bb9d722e803cf7ad1",
29
29
  "tsnet-sidecar-windows-amd64.exe": "3e779b259750e8d48b49e9bcb78b01a0eb32e0c83b85370d505a750a36adb3bb"
30
+ },
31
+ "0.6.0": {
32
+ "tsnet-sidecar-darwin-arm64": "82b843b953e38b939269ba5f7573193e9513497cade39c587fb76656d3a2eaff",
33
+ "tsnet-sidecar-darwin-amd64": "bc86cfb15989462faa084d59fda407cdae464f177ef2e65b699b200fb81758ce",
34
+ "tsnet-sidecar-linux-amd64": "790c5f21f95e3619243b3c32fda55550cc84f52edca11dbd594ce6fc993a534c",
35
+ "tsnet-sidecar-linux-arm64": "32cd2a2d2227df22b91ef9148cced19b7a22b1766c6c254402483216a57eb65e",
36
+ "tsnet-sidecar-windows-amd64.exe": "4e4fdc43607c9aa695e32b334dc6dd96feb2b8e5b2ed4aef0a2a92d8531c6e1a"
37
+ },
38
+ "0.7.0": {
39
+ "tsnet-sidecar-darwin-arm64": "6882d2f160ea4c3805bc80843d80efff9969d02b112a747dfc9b34e79ea40fdc",
40
+ "tsnet-sidecar-darwin-amd64": "570018a4eadccfc48239b45823535e4c87ccc655349f26f979dd457a932665d0",
41
+ "tsnet-sidecar-linux-amd64": "db35c4562d449134ec5359da33e33ed90faa66298165f855d1cfc4957ebd04f8",
42
+ "tsnet-sidecar-linux-arm64": "a01815517ce9921820c79c19d98c012a9fad5e5140bef463590d756fe82d4ff3",
43
+ "tsnet-sidecar-windows-amd64.exe": "1f04c899bdc1d40139486d531eb15a1ecbae0a5142d450c4ba66a1a59d8428c1"
30
44
  }
31
45
  }