sharerare 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 fsdrlabs
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.
package/README.md CHANGED
@@ -1,3 +1,72 @@
1
- # Temporary Holding Version
1
+ # sharerare
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Send files between devices on the same network, from the terminal. The files go directly from one device to the other over an encrypted WebRTC link. They never touch a server.
4
+
5
+ It works together with the web app at [sharerare.fsdrlabs.tech](https://sharerare.fsdrlabs.tech): a terminal running `sharerare` shows up as a device in the browser, and sees what browsers share.
6
+
7
+ ```bash
8
+ npx sharerare send report.pdf
9
+ ```
10
+
11
+ Requires Node.js 22 or newer. Prebuilt for macOS, Linux and Windows (x64 and ARM); nothing to compile.
12
+
13
+ ## Commands
14
+
15
+ ```bash
16
+ sharerare send report.pdf photos.zip # share until Ctrl+C
17
+ sharerare note "https://example.com" # share a note or a link
18
+ echo "build 4512 is green" | sharerare note
19
+ sharerare ls # devices nearby and what they share
20
+ sharerare get report.pdf # download by name, or part of a name
21
+ sharerare get --all --from iPhone -o ~/Downloads
22
+ sharerare get --all --zip # everything as one .zip
23
+ sharerare cat notes.md # print a shared text file or note
24
+ ```
25
+
26
+ `get` writes each file as `name.part` and renames it when it is complete. An existing file is never overwritten: a second `report.pdf` is saved as `report (1).pdf`.
27
+
28
+ `cat` prints to the terminal and refuses binary files there; redirect it instead (`sharerare cat photo.jpg > photo.jpg`), or use `get`.
29
+
30
+ ## When a device doesn't show up
31
+
32
+ Devices that reach the internet through the same router find each other by themselves. When they don't (a phone on mobile data, a VPN, a guest network), pair them:
33
+
34
+ ```bash
35
+ sharerare send report.pdf --pair
36
+ ```
37
+
38
+ This draws a QR code in the terminal. Scan it with a phone and the page opens already paired. You can also type the six-character code into "Pair a device" on the other device, or join another device's code from the terminal:
39
+
40
+ ```bash
41
+ sharerare get --all --code K7M2QX
42
+ ```
43
+
44
+ `--hidden` keeps the terminal off the network so only paired devices see it.
45
+
46
+ ## Over the internet (opt-in)
47
+
48
+ By default links only form on the local network: no STUN or TURN server is used, so a device can't be reached from outside it. With `--internet`, a device you paired with that has "Allow links over the internet" turned on can link to you directly across networks. Each side then learns the other's public IP address. Bytes still go device to device; there is no relay, so this fails on networks that block direct connections (common on mobile data).
49
+
50
+ ## Options
51
+
52
+ | Option | |
53
+ |---|---|
54
+ | `--pair` | `send`/`note`: show a QR code and a code for pairing |
55
+ | `--code <CODE>` | Join another device's pairing code |
56
+ | `--hidden` | Don't appear on the network; only paired devices see you |
57
+ | `--internet` | Allow direct links over the internet with paired devices that allow it too |
58
+ | `--from <device>` | `get`/`cat`: only from this device |
59
+ | `-o, --out <dir>` | `get`: folder to save into |
60
+ | `--zip [name.zip]` | `get`: save as one .zip (a folder per device when there are several) |
61
+ | `--name <name>` | How this device appears to others (default: host name) |
62
+ | `--url <url>` | Use another Sharerare site (or set `SHARERARE_URL`) |
63
+ | `--wait <seconds>` | How long to look for devices (default 15) |
64
+ | `--json` | `ls`: machine-readable output |
65
+
66
+ ## What the pairing service sees
67
+
68
+ The site at sharerare.fsdrlabs.tech introduces devices to each other. It sees your public IP address (to group devices on the same network), a random id per run, and WebRTC connection setup data. It never sees file names, file contents, notes or device names: those travel only over the direct link.
69
+
70
+ ## Licence
71
+
72
+ MIT. Includes [uqr](https://github.com/unjs/uqr) (MIT) for the QR code.
package/cli/lan.js ADDED
@@ -0,0 +1,90 @@
1
+ // Helpers for the command-line client. Pure, so they can be unit tested.
2
+ import path from 'node:path';
3
+
4
+ // Is this address on a local network? Private IPv4, IPv6 unique-local and
5
+ // link-local, and mDNS names (browsers hide their local addresses behind
6
+ // those). Everything else is a public address.
7
+ export function isLanAddress(address) {
8
+ if (typeof address !== 'string' || !address) return false;
9
+ const a = address.toLowerCase().split('%')[0];
10
+ if (a.endsWith('.local')) return true;
11
+ if (/^\d+\.\d+\.\d+\.\d+$/.test(a)) {
12
+ const [x, y] = a.split('.').map(Number);
13
+ return x === 10 || (x === 192 && y === 168) || (x === 172 && y >= 16 && y <= 31) || (x === 169 && y === 254);
14
+ }
15
+ if (a.includes(':')) {
16
+ const first = parseInt(a.split(':')[0] || '0', 16);
17
+ return (first & 0xfe00) === 0xfc00 || (first & 0xffc0) === 0xfe80; // fc00::/7, fe80::/10
18
+ }
19
+ return false;
20
+ }
21
+
22
+ // The address inside an ICE candidate line ("candidate:1 1 UDP 2122 192.168.1.7 5000 typ host").
23
+ export function candidateAddress(line) {
24
+ const parts = String(line || '').replace(/^a=/, '').trim().split(/\s+/);
25
+ return parts[0]?.startsWith('candidate:') && parts.length >= 8 ? parts[4] : null;
26
+ }
27
+
28
+ // A browser never offers its public address here, because it has no STUN
29
+ // server to learn it from and hides local ones behind mDNS. A native client
30
+ // sees every address of the machine, so it must leave the public ones out
31
+ // itself: with a public IPv6 address two paired devices could otherwise link
32
+ // across the internet.
33
+ export const isLanCandidate = (line) => {
34
+ const address = candidateAddress(line);
35
+ return address !== null && isLanAddress(address) && /\btyp host\b/.test(line);
36
+ };
37
+
38
+ // With --internet, a paired device may also use the address a STUN server
39
+ // reported (srflx) or one learned during the checks (prflx). A relay never.
40
+ export const isAllowedCandidate = (line, { internet = false } = {}) => {
41
+ if (isLanCandidate(line)) return true;
42
+ if (!internet) return false;
43
+ return candidateAddress(line) !== null && /\btyp (host|srflx|prflx)\b/.test(line);
44
+ };
45
+
46
+ export const filterSdp = (sdp, options) => String(sdp).split(/\r?\n/)
47
+ .filter((line) => !line.startsWith('a=candidate:') || isAllowedCandidate(line.slice(2), options))
48
+ .join('\r\n');
49
+
50
+ export const lanOnlySdp = (sdp) => filterSdp(sdp, { internet: false });
51
+
52
+ // Does this look like text? (For "cat" to a terminal.)
53
+ export const looksBinary = (bytes) => {
54
+ const sample = bytes.subarray(0, 8000);
55
+ for (const b of sample) if (b === 0) return true;
56
+ return false;
57
+ };
58
+
59
+ // A file name from another device is untrusted: keep only its last path
60
+ // segment and drop anything that could escape the folder or confuse a terminal.
61
+ export function safeName(name) {
62
+ let base = String(name ?? '').replace(/[\u0000-\u001f\u007f]/g, '').split(/[\\/]/).pop().trim();
63
+ base = base.replace(/^\.+/, '').slice(0, 200);
64
+ return base || 'file';
65
+ }
66
+
67
+ // Never overwrite: "report.pdf" -> "report (1).pdf".
68
+ export function freePath(dir, name, exists) {
69
+ const { name: stem, ext } = path.parse(name);
70
+ let candidate = path.join(dir, name);
71
+ for (let n = 1; exists(candidate) || exists(`${candidate}.part`); n++) candidate = path.join(dir, `${stem} (${n})${ext}`);
72
+ return candidate;
73
+ }
74
+
75
+ export function fmtSize(bytes) {
76
+ const units = ['B', 'KB', 'MB', 'GB', 'TB'];
77
+ let value = bytes;
78
+ let unit = 0;
79
+ while (value >= 1000 && unit < units.length - 1) { value /= 1024; unit++; }
80
+ return `${unit === 0 || value >= 100 ? Math.round(value) : value.toFixed(1).replace(/\.0$/, '')} ${units[unit]}`;
81
+ }
82
+
83
+ const TYPES = {
84
+ pdf: 'application/pdf', zip: 'application/zip', json: 'application/json', txt: 'text/plain', md: 'text/markdown',
85
+ csv: 'text/csv', html: 'text/html', png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif',
86
+ webp: 'image/webp', svg: 'image/svg+xml', mp4: 'video/mp4', mov: 'video/quicktime', mp3: 'audio/mpeg',
87
+ m4a: 'audio/mp4', wav: 'audio/wav', doc: 'application/msword', xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
88
+ docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
89
+ };
90
+ export const typeOf = (name) => TYPES[path.extname(name).slice(1).toLowerCase()] || 'application/octet-stream';