@meshwhisper/cli 0.1.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.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,194 @@
1
+ #!/usr/bin/env node
2
+ // ============================================================
3
+ // MeshWhisper CLI
4
+ // Developer tooling. Usage:
5
+ // npx @meshwhisper/cli init
6
+ // ============================================================
7
+ import * as fs from 'node:fs';
8
+ import * as path from 'node:path';
9
+ import * as readline from 'node:readline/promises';
10
+ import { stdin as input, stdout as output } from 'node:process';
11
+ import pc from 'picocolors';
12
+ // ============================================================
13
+ // Helpers
14
+ // ============================================================
15
+ function randomHex(bytes) {
16
+ const buf = new Uint8Array(bytes);
17
+ globalThis.crypto.getRandomValues(buf);
18
+ return Buffer.from(buf).toString('hex');
19
+ }
20
+ function randomBase64(bytes) {
21
+ const buf = new Uint8Array(bytes);
22
+ globalThis.crypto.getRandomValues(buf);
23
+ return Buffer.from(buf).toString('base64');
24
+ }
25
+ function printBanner() {
26
+ console.log('');
27
+ console.log(pc.bold(pc.cyan(' MeshWhisper CLI')));
28
+ console.log(pc.dim(' Serverless P2P E2EE messaging SDK'));
29
+ console.log('');
30
+ }
31
+ function printStep(n, text) {
32
+ console.log(pc.bold(pc.green(` ${n}.`)) + ' ' + text);
33
+ }
34
+ function printNote(text) {
35
+ console.log(pc.dim(` ${text}`));
36
+ }
37
+ // ============================================================
38
+ // Commands
39
+ // ============================================================
40
+ async function cmdInit() {
41
+ printBanner();
42
+ console.log(pc.bold(' Initializing a new MeshWhisper project\n'));
43
+ const rl = readline.createInterface({ input, output });
44
+ // Detect package.json to guess the bundle ID
45
+ let detectedBundleId = 'com.example.myapp';
46
+ try {
47
+ const pkgRaw = fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8');
48
+ const pkg = JSON.parse(pkgRaw);
49
+ if (pkg.name) {
50
+ // Convert "my-app" → "com.example.my-app" as a suggestion
51
+ detectedBundleId = `com.example.${pkg.name.replace(/^@[^/]+\//, '')}`;
52
+ }
53
+ }
54
+ catch { /* no package.json — ignore */ }
55
+ const bundleId = (await rl.question(pc.bold(' App bundle ID') + pc.dim(` (e.g. ${detectedBundleId}): `))).trim() || detectedBundleId;
56
+ const nodeChoice = (await rl.question(pc.bold(' Node') + pc.dim(' [mesh/self-hosted] (default: mesh): '))).trim().toLowerCase() || 'mesh';
57
+ let nodeConfig = '"mesh"';
58
+ let selfHostedUrl = '';
59
+ if (nodeChoice === 'self-hosted' || nodeChoice === 'self') {
60
+ selfHostedUrl = (await rl.question(pc.bold(' Node WebSocket URL') + pc.dim(' (e.g. wss://msg.myapp.com): '))).trim();
61
+ nodeConfig = selfHostedUrl ? `"${selfHostedUrl}"` : '"mesh"';
62
+ }
63
+ rl.close();
64
+ const developerKey = randomBase64(32);
65
+ const salt = randomHex(32);
66
+ console.log('');
67
+ printStep(1, 'Generated developer key and salt');
68
+ printNote('Keep these in your environment variables — do not commit them.');
69
+ // Print env block
70
+ console.log('');
71
+ console.log(pc.bgBlack(pc.white(' .env ')));
72
+ console.log('');
73
+ console.log(` MESHWHISPER_DEVELOPER_KEY=${developerKey}`);
74
+ console.log(` MESHWHISPER_SALT=${salt}`);
75
+ if (selfHostedUrl) {
76
+ console.log(` MESHWHISPER_NODE_URL=${selfHostedUrl}`);
77
+ }
78
+ console.log('');
79
+ // Print SDK init snippet
80
+ printStep(2, 'Add this to your app entry point');
81
+ console.log('');
82
+ console.log(pc.bgBlack(pc.white(' TypeScript / JavaScript ')));
83
+ console.log('');
84
+ const snippet = `import { MeshWhisper } from '@meshwhisper/sdk';
85
+
86
+ const mw = await MeshWhisper.init({
87
+ namespace: '${bundleId}',
88
+ node: ${nodeConfig},
89
+ developerKey: process.env.MESHWHISPER_DEVELOPER_KEY,
90
+ });
91
+
92
+ // Send a message
93
+ await MeshWhisper.send(recipientId, new TextEncoder().encode('Hello!'));
94
+
95
+ // Receive messages
96
+ MeshWhisper.onMessage((message) => {
97
+ const text = new TextDecoder().decode(new Uint8Array(message.payload));
98
+ console.log('Received:', text);
99
+ });
100
+ `;
101
+ snippet.split('\n').forEach((line) => console.log(' ' + pc.cyan(line)));
102
+ if (nodeChoice === 'self-hosted' || nodeChoice === 'self') {
103
+ printStep(3, 'Deploy your MeshWhisper Node');
104
+ console.log('');
105
+ printNote('Use the provided Dockerfile in the @meshwhisper/node package:');
106
+ console.log('');
107
+ console.log(` docker build -t meshwhisper-node ./node_modules/@meshwhisper/node`);
108
+ console.log(` docker run -p 443:8080 \\`);
109
+ console.log(` -e PORT=8080 \\`);
110
+ console.log(` -e PUSH_WEBHOOK_URL=https://your-push-server/notify \\`);
111
+ console.log(` meshwhisper-node`);
112
+ console.log('');
113
+ printNote('Or use docker compose up with the generated docker-compose.yml.');
114
+ writeDockerCompose(selfHostedUrl);
115
+ }
116
+ console.log('');
117
+ console.log(pc.bold(pc.green(' Done!')));
118
+ console.log(pc.dim(' Docs: https://meshwhisper.io/docs'));
119
+ console.log('');
120
+ }
121
+ function writeDockerCompose(nodeUrl) {
122
+ const compose = `# Generated by meshwhisper init
123
+ # docker compose up
124
+
125
+ services:
126
+ node:
127
+ build:
128
+ context: .
129
+ dockerfile: node/Dockerfile
130
+ ports:
131
+ - "8080:8080"
132
+ environment:
133
+ PORT: "8080"
134
+ BLOB_TTL_HOURS: "72"
135
+ MEDIA_TTL_HOURS: "168"
136
+ # BASE_URL: https://msg.myapp.com
137
+ PUSH_WEBHOOK_URL: "http://push:4000/notify"
138
+ restart: unless-stopped
139
+ healthcheck:
140
+ test: ["CMD", "wget", "-qO-", "http://localhost:8080/health"]
141
+ interval: 30s
142
+ timeout: 5s
143
+ retries: 3
144
+
145
+ push:
146
+ build:
147
+ context: .
148
+ dockerfile: push-service/Dockerfile
149
+ environment:
150
+ PUSH_PORT: "4000"
151
+ # APNs — uncomment and fill in for iOS push support
152
+ # APNS_KEY_ID: XXXXXXXXXX
153
+ # APNS_TEAM_ID: YYYYYYYYYY
154
+ # APNS_KEY_PATH: /run/secrets/apns_key
155
+ # APNS_BUNDLE_ID: com.example.myapp
156
+ # FCM — uncomment and fill in for Android push support
157
+ # FCM_SERVICE_ACCOUNT_PATH: /run/secrets/fcm_service_account
158
+ # FCM_PROJECT_ID: my-firebase-project
159
+ restart: unless-stopped
160
+ `;
161
+ const outPath = path.join(process.cwd(), 'docker-compose.yml');
162
+ if (fs.existsSync(outPath)) {
163
+ console.log('');
164
+ printNote(`docker-compose.yml already exists — skipping. Delete it and re-run to regenerate.`);
165
+ }
166
+ else {
167
+ fs.writeFileSync(outPath, compose, 'utf-8');
168
+ console.log('');
169
+ printNote(`Wrote docker-compose.yml`);
170
+ }
171
+ }
172
+ // ============================================================
173
+ // Entry point
174
+ // ============================================================
175
+ const [, , command, ...args] = process.argv;
176
+ switch (command) {
177
+ case 'init':
178
+ await cmdInit();
179
+ break;
180
+ case undefined:
181
+ case '--help':
182
+ case '-h':
183
+ printBanner();
184
+ console.log(' Usage:');
185
+ console.log('');
186
+ console.log(' npx @meshwhisper/cli init Initialize a new project');
187
+ console.log('');
188
+ break;
189
+ default:
190
+ console.error(pc.red(` Unknown command: ${command}`));
191
+ console.error(` Run ${pc.bold('meshwhisper --help')} for usage.`);
192
+ process.exit(1);
193
+ }
194
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,+DAA+D;AAC/D,kBAAkB;AAClB,4BAA4B;AAC5B,8BAA8B;AAC9B,+DAA+D;AAE/D,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,KAAK,IAAI,KAAK,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,MAAM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;QACE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,sBAAsB,OAAO,EAAE,CAAC,CAAC,CAAC;QACvD,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,CAAC;QACnE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@meshwhisper/cli",
3
+ "version": "0.1.0",
4
+ "description": "MeshWhisper CLI — developer tooling for MeshWhisper projects",
5
+ "type": "module",
6
+ "bin": {
7
+ "meshwhisper": "dist/index.js"
8
+ },
9
+ "files": ["dist"],
10
+ "publishConfig": { "access": "public" },
11
+ "scripts": {
12
+ "prepublishOnly": "npm run build",
13
+ "build": "tsc",
14
+ "dev": "tsx src/index.ts"
15
+ },
16
+ "dependencies": {
17
+ "picocolors": "^1.1.0"
18
+ },
19
+ "devDependencies": {
20
+ "@types/node": "^22.0.0",
21
+ "tsx": "^4.21.0",
22
+ "typescript": "^5.7.0"
23
+ },
24
+ "license": "MIT"
25
+ }