@sharnix/agent 1.0.1 → 1.0.2
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/index.js +19 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -23,6 +23,7 @@ const has = (flag) => args.includes(flag);
|
|
|
23
23
|
const port = parseInt(get('--port') || get('-p') || '3000', 10);
|
|
24
24
|
const label = get('--label') || get('-l') || null;
|
|
25
25
|
const agentName = get('--name') || 'local-dev';
|
|
26
|
+
const shareOnStart = has('--share');
|
|
26
27
|
|
|
27
28
|
if (has('--help') || has('-h')) {
|
|
28
29
|
console.log(`
|
|
@@ -36,6 +37,7 @@ if (has('--help') || has('-h')) {
|
|
|
36
37
|
--port, -p <n> Local port to forward (default: 3000)
|
|
37
38
|
--label, -l <s> Human-readable label for this tunnel
|
|
38
39
|
--name <s> Agent name used on first setup (default: local-dev)
|
|
40
|
+
--share Create a read-only share link on connect and print the URL
|
|
39
41
|
--help, -h Show this message
|
|
40
42
|
|
|
41
43
|
Environment:
|
|
@@ -145,6 +147,7 @@ function connect() {
|
|
|
145
147
|
console.log(` Dashboard → relay.sharnix.com/app/tunnels/${tunnelId}`);
|
|
146
148
|
console.log(` MCP agent → "create a share link for my tunnel"\n`);
|
|
147
149
|
console.log(` Press Ctrl+C to disconnect.\n`);
|
|
150
|
+
if (shareOnStart) await createShareLink();
|
|
148
151
|
});
|
|
149
152
|
|
|
150
153
|
ws.on('message', async (data) => {
|
|
@@ -166,6 +169,22 @@ function connect() {
|
|
|
166
169
|
});
|
|
167
170
|
}
|
|
168
171
|
|
|
172
|
+
async function createShareLink() {
|
|
173
|
+
try {
|
|
174
|
+
const orgs = await api('GET', '/api/v1/orgs');
|
|
175
|
+
if (!orgs.length) return;
|
|
176
|
+
const orgSlug = creds.orgSlug || orgs[0].slug;
|
|
177
|
+
const result = await api('POST', `/api/v1/orgs/${orgSlug}/tunnels/${tunnelId}/links`, {
|
|
178
|
+
permission: 'read-only',
|
|
179
|
+
label: label || 'Shared via agent',
|
|
180
|
+
});
|
|
181
|
+
console.log(` Share link : ${result.url}`);
|
|
182
|
+
console.log(` Permission : read-only\n`);
|
|
183
|
+
} catch (err) {
|
|
184
|
+
console.error(` Could not create share link: ${err.message}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
169
188
|
function startHeartbeat() {
|
|
170
189
|
clearInterval(heartbeatTimer);
|
|
171
190
|
heartbeatTimer = setInterval(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharnix/agent",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Tunnel your local app through Sharnix — share previews with one command",
|
|
5
5
|
"keywords": ["tunnel", "preview", "sharing", "localhost", "sharnix"],
|
|
6
6
|
"homepage": "https://relay.sharnix.com",
|