@sharnix/agent 1.0.8 → 1.0.9
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 +28 -9
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -175,18 +175,37 @@ function connect() {
|
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
async function createShareLink() {
|
|
178
|
+
let orgs;
|
|
178
179
|
try {
|
|
179
|
-
|
|
180
|
-
if (!orgs.length) return;
|
|
181
|
-
const orgSlug = creds.orgSlug || orgs[0].slug;
|
|
182
|
-
const result = await api('POST', `/api/v1/orgs/${orgSlug}/tunnels/${tunnelId}/links`, {
|
|
183
|
-
permission: 'read-only',
|
|
184
|
-
label: label || 'Shared via agent',
|
|
185
|
-
});
|
|
186
|
-
console.log(` Share link : ${result.url}`);
|
|
187
|
-
console.log(` Permission : read-only\n`);
|
|
180
|
+
orgs = await api('GET', '/api/v1/orgs');
|
|
188
181
|
} catch (err) {
|
|
189
182
|
console.error(` Could not create share link: ${err.message}`);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (!orgs.length) return;
|
|
186
|
+
const orgSlug = creds.orgSlug || orgs[0].slug;
|
|
187
|
+
|
|
188
|
+
// The relay inserts the tunnel row from an async handler triggered by our WS REGISTER.
|
|
189
|
+
// The HTTP POST below can arrive before that insert completes, yielding tunnel_not_found.
|
|
190
|
+
// Retry briefly on that specific error; surface any other error immediately.
|
|
191
|
+
const delays = [400, 800, 1500, 2500];
|
|
192
|
+
for (let attempt = 0; ; attempt++) {
|
|
193
|
+
try {
|
|
194
|
+
const result = await api('POST', `/api/v1/orgs/${orgSlug}/tunnels/${tunnelId}/links`, {
|
|
195
|
+
permission: 'read-only',
|
|
196
|
+
label: label || 'Shared via agent',
|
|
197
|
+
});
|
|
198
|
+
console.log(` Share link : ${result.url}`);
|
|
199
|
+
console.log(` Permission : read-only\n`);
|
|
200
|
+
return;
|
|
201
|
+
} catch (err) {
|
|
202
|
+
if (err.message === 'tunnel_not_found' && attempt < delays.length) {
|
|
203
|
+
await new Promise((r) => setTimeout(r, delays[attempt]));
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
console.error(` Could not create share link: ${err.message}`);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
190
209
|
}
|
|
191
210
|
}
|
|
192
211
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharnix/agent",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
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",
|