arri 0.0.5 → 0.0.6
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/chunks/browser.cjs +21 -0
- package/dist/chunks/browser.mjs +19 -0
- package/dist/chunks/index.cjs +83 -0
- package/dist/chunks/index.mjs +81 -0
- package/dist/chunks/index2.cjs +230 -0
- package/dist/chunks/index2.mjs +219 -0
- package/dist/chunks/index3.cjs +8853 -0
- package/dist/chunks/index3.mjs +8831 -0
- package/dist/chunks/xdg-open.cjs +1071 -0
- package/dist/chunks/xdg-open.mjs +1069 -0
- package/dist/cli.cjs +52951 -0
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.mts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.mjs +52904 -0
- package/dist/codegen.cjs +844 -0
- package/dist/{codegen/index.d.mts → codegen.d.cts} +2 -2
- package/dist/{codegen/index.d.ts → codegen.d.mts} +2 -2
- package/dist/{codegen/index.d.cts → codegen.d.ts} +2 -2
- package/dist/codegen.mjs +826 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{codegen/index.mjs → shared/arri.34695f7b.mjs} +17 -824
- package/dist/{codegen/index.cjs → shared/arri.38ad6cd0.cjs} +97 -920
- package/dist/shared/{arri.215ad025.mjs → arri.b4c5ce27.mjs} +148 -1
- package/dist/shared/{arri.e2731572.cjs → arri.d77f4d0e.cjs} +156 -0
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* eslint-env browser */
|
|
4
|
+
|
|
5
|
+
const clipboard = {};
|
|
6
|
+
|
|
7
|
+
clipboard.write = async text => {
|
|
8
|
+
await navigator.clipboard.writeText(text);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
clipboard.read = async () => navigator.clipboard.readText();
|
|
12
|
+
|
|
13
|
+
clipboard.readSync = () => {
|
|
14
|
+
throw new Error('`.readSync()` is not supported in browsers!');
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
clipboard.writeSync = () => {
|
|
18
|
+
throw new Error('`.writeSync()` is not supported in browsers!');
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.default = clipboard;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* eslint-env browser */
|
|
2
|
+
|
|
3
|
+
const clipboard = {};
|
|
4
|
+
|
|
5
|
+
clipboard.write = async text => {
|
|
6
|
+
await navigator.clipboard.writeText(text);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
clipboard.read = async () => navigator.clipboard.readText();
|
|
10
|
+
|
|
11
|
+
clipboard.readSync = () => {
|
|
12
|
+
throw new Error('`.readSync()` is not supported in browsers!');
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
clipboard.writeSync = () => {
|
|
16
|
+
throw new Error('`.writeSync()` is not supported in browsers!');
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { clipboard as default };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const cli = require('../cli.cjs');
|
|
5
|
+
require('node:tty');
|
|
6
|
+
require('node:path');
|
|
7
|
+
require('stream');
|
|
8
|
+
require('../shared/arri.d77f4d0e.cjs');
|
|
9
|
+
require('os');
|
|
10
|
+
require('path');
|
|
11
|
+
require('util');
|
|
12
|
+
require('events');
|
|
13
|
+
require('fs');
|
|
14
|
+
require('node:process');
|
|
15
|
+
require('node:url');
|
|
16
|
+
require('node:stream');
|
|
17
|
+
require('crypto');
|
|
18
|
+
require('node:fs/promises');
|
|
19
|
+
require('node:os');
|
|
20
|
+
require('module');
|
|
21
|
+
require('perf_hooks');
|
|
22
|
+
require('vm');
|
|
23
|
+
require('url');
|
|
24
|
+
require('assert');
|
|
25
|
+
require('process');
|
|
26
|
+
require('v8');
|
|
27
|
+
require('tty');
|
|
28
|
+
require('node:module');
|
|
29
|
+
require('node:assert');
|
|
30
|
+
require('node:v8');
|
|
31
|
+
require('node:util');
|
|
32
|
+
require('../shared/arri.38ad6cd0.cjs');
|
|
33
|
+
require('fs/promises');
|
|
34
|
+
require('node:http');
|
|
35
|
+
require('node:https');
|
|
36
|
+
require('node:net');
|
|
37
|
+
require('http');
|
|
38
|
+
require('https');
|
|
39
|
+
require('node:child_process');
|
|
40
|
+
|
|
41
|
+
async function startTunnel(opts) {
|
|
42
|
+
const {
|
|
43
|
+
installCloudflared,
|
|
44
|
+
startCloudflaredTunnel,
|
|
45
|
+
cloudflaredBinPath,
|
|
46
|
+
cloudflaredNotice
|
|
47
|
+
} = await import('./index2.cjs');
|
|
48
|
+
const url = opts.url || `${opts.protocol || "http"}://${opts.hostname ?? "localhost"}:${opts.port ?? 3e3}`;
|
|
49
|
+
cli.consola.start(`Starting cloudflared tunnel to ${url}`);
|
|
50
|
+
if (!fs.existsSync(cloudflaredBinPath)) {
|
|
51
|
+
cli.consola.log(cloudflaredNotice);
|
|
52
|
+
const canInstall = await cli.consola.prompt(
|
|
53
|
+
`Do you agree with the above terms and wish to install the binary from GitHub?`,
|
|
54
|
+
{
|
|
55
|
+
type: "confirm"
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
if (!canInstall) {
|
|
59
|
+
cli.consola.fail("Skipping tunnel setup.");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
await installCloudflared();
|
|
63
|
+
}
|
|
64
|
+
const args = [
|
|
65
|
+
["--url", url],
|
|
66
|
+
opts.verifyTLS ? void 0 : ["--no-tls-verify", ""]
|
|
67
|
+
].filter(Boolean);
|
|
68
|
+
const tunnel = await startCloudflaredTunnel(Object.fromEntries(args));
|
|
69
|
+
const cleanup = async () => {
|
|
70
|
+
await tunnel.stop();
|
|
71
|
+
};
|
|
72
|
+
for (const signal of ["SIGINT", "SIGUSR1", "SIGUSR2"]) {
|
|
73
|
+
process.once(signal, cleanup);
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
getURL: async () => await tunnel.url,
|
|
77
|
+
close: async () => {
|
|
78
|
+
await cleanup();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
exports.startTunnel = startTunnel;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { c as consola } from '../cli.mjs';
|
|
3
|
+
import 'node:tty';
|
|
4
|
+
import 'node:path';
|
|
5
|
+
import 'stream';
|
|
6
|
+
import '../shared/arri.b4c5ce27.mjs';
|
|
7
|
+
import 'os';
|
|
8
|
+
import 'path';
|
|
9
|
+
import 'util';
|
|
10
|
+
import 'events';
|
|
11
|
+
import 'fs';
|
|
12
|
+
import 'node:process';
|
|
13
|
+
import 'node:url';
|
|
14
|
+
import 'node:stream';
|
|
15
|
+
import 'crypto';
|
|
16
|
+
import 'node:fs/promises';
|
|
17
|
+
import 'node:os';
|
|
18
|
+
import 'module';
|
|
19
|
+
import 'perf_hooks';
|
|
20
|
+
import 'vm';
|
|
21
|
+
import 'url';
|
|
22
|
+
import 'assert';
|
|
23
|
+
import 'process';
|
|
24
|
+
import 'v8';
|
|
25
|
+
import 'tty';
|
|
26
|
+
import 'node:module';
|
|
27
|
+
import 'node:assert';
|
|
28
|
+
import 'node:v8';
|
|
29
|
+
import 'node:util';
|
|
30
|
+
import '../shared/arri.34695f7b.mjs';
|
|
31
|
+
import 'fs/promises';
|
|
32
|
+
import 'node:http';
|
|
33
|
+
import 'node:https';
|
|
34
|
+
import 'node:net';
|
|
35
|
+
import 'http';
|
|
36
|
+
import 'https';
|
|
37
|
+
import 'node:child_process';
|
|
38
|
+
|
|
39
|
+
async function startTunnel(opts) {
|
|
40
|
+
const {
|
|
41
|
+
installCloudflared,
|
|
42
|
+
startCloudflaredTunnel,
|
|
43
|
+
cloudflaredBinPath,
|
|
44
|
+
cloudflaredNotice
|
|
45
|
+
} = await import('./index2.mjs');
|
|
46
|
+
const url = opts.url || `${opts.protocol || "http"}://${opts.hostname ?? "localhost"}:${opts.port ?? 3e3}`;
|
|
47
|
+
consola.start(`Starting cloudflared tunnel to ${url}`);
|
|
48
|
+
if (!existsSync(cloudflaredBinPath)) {
|
|
49
|
+
consola.log(cloudflaredNotice);
|
|
50
|
+
const canInstall = await consola.prompt(
|
|
51
|
+
`Do you agree with the above terms and wish to install the binary from GitHub?`,
|
|
52
|
+
{
|
|
53
|
+
type: "confirm"
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
if (!canInstall) {
|
|
57
|
+
consola.fail("Skipping tunnel setup.");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
await installCloudflared();
|
|
61
|
+
}
|
|
62
|
+
const args = [
|
|
63
|
+
["--url", url],
|
|
64
|
+
opts.verifyTLS ? void 0 : ["--no-tls-verify", ""]
|
|
65
|
+
].filter(Boolean);
|
|
66
|
+
const tunnel = await startCloudflaredTunnel(Object.fromEntries(args));
|
|
67
|
+
const cleanup = async () => {
|
|
68
|
+
await tunnel.stop();
|
|
69
|
+
};
|
|
70
|
+
for (const signal of ["SIGINT", "SIGUSR1", "SIGUSR2"]) {
|
|
71
|
+
process.once(signal, cleanup);
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
getURL: async () => await tunnel.url,
|
|
75
|
+
close: async () => {
|
|
76
|
+
await cleanup();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { startTunnel };
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const os = require('node:os');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const https = require('node:https');
|
|
7
|
+
const childProcess = require('node:child_process');
|
|
8
|
+
const cli = require('../cli.cjs');
|
|
9
|
+
require('node:tty');
|
|
10
|
+
require('stream');
|
|
11
|
+
require('../shared/arri.d77f4d0e.cjs');
|
|
12
|
+
require('os');
|
|
13
|
+
require('path');
|
|
14
|
+
require('util');
|
|
15
|
+
require('events');
|
|
16
|
+
require('fs');
|
|
17
|
+
require('node:process');
|
|
18
|
+
require('node:url');
|
|
19
|
+
require('node:stream');
|
|
20
|
+
require('crypto');
|
|
21
|
+
require('node:fs/promises');
|
|
22
|
+
require('module');
|
|
23
|
+
require('perf_hooks');
|
|
24
|
+
require('vm');
|
|
25
|
+
require('url');
|
|
26
|
+
require('assert');
|
|
27
|
+
require('process');
|
|
28
|
+
require('v8');
|
|
29
|
+
require('tty');
|
|
30
|
+
require('node:module');
|
|
31
|
+
require('node:assert');
|
|
32
|
+
require('node:v8');
|
|
33
|
+
require('node:util');
|
|
34
|
+
require('../shared/arri.38ad6cd0.cjs');
|
|
35
|
+
require('fs/promises');
|
|
36
|
+
require('node:http');
|
|
37
|
+
require('node:net');
|
|
38
|
+
require('http');
|
|
39
|
+
require('https');
|
|
40
|
+
|
|
41
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
42
|
+
|
|
43
|
+
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
44
|
+
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
45
|
+
const https__default = /*#__PURE__*/_interopDefaultCompat(https);
|
|
46
|
+
|
|
47
|
+
const CLOUDFLARED_VERSION = process.env.CLOUDFLARED_VERSION || "2023.7.3";
|
|
48
|
+
const RELEASE_BASE = "https://github.com/cloudflare/cloudflared/releases/";
|
|
49
|
+
const cloudflaredBinPath = cli.path.join(
|
|
50
|
+
os.tmpdir(),
|
|
51
|
+
"node-untun",
|
|
52
|
+
process.platform === "win32" ? `cloudflared.${CLOUDFLARED_VERSION}.exe` : `cloudflared.${CLOUDFLARED_VERSION}`
|
|
53
|
+
);
|
|
54
|
+
const cloudflaredNotice = `
|
|
55
|
+
\u{1F525} Your installation of cloudflared software constitutes a symbol of your signature
|
|
56
|
+
indicating that you accept the terms of the Cloudflare License, Terms and Privacy Policy.
|
|
57
|
+
|
|
58
|
+
\u276F License: \`https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/license/\`
|
|
59
|
+
\u276F Terms: \`https://www.cloudflare.com/terms/\`
|
|
60
|
+
\u276F Privacy Policy: \`https://www.cloudflare.com/privacypolicy/\`
|
|
61
|
+
`;
|
|
62
|
+
const connRegex = /connection[ =]([\da-z-]+)/i;
|
|
63
|
+
const ipRegex = /ip=([\d.]+)/;
|
|
64
|
+
const locationRegex = /location=([A-Z]+)/;
|
|
65
|
+
const indexRegex = /connIndex=(\d)/;
|
|
66
|
+
|
|
67
|
+
const LINUX_URL = {
|
|
68
|
+
arm64: "cloudflared-linux-arm64",
|
|
69
|
+
arm: "cloudflared-linux-arm",
|
|
70
|
+
x64: "cloudflared-linux-amd64",
|
|
71
|
+
ia32: "cloudflared-linux-386"
|
|
72
|
+
};
|
|
73
|
+
const MACOS_URL = {
|
|
74
|
+
arm64: "cloudflared-darwin-amd64.tgz",
|
|
75
|
+
x64: "cloudflared-darwin-amd64.tgz"
|
|
76
|
+
};
|
|
77
|
+
const WINDOWS_URL = {
|
|
78
|
+
x64: "cloudflared-windows-amd64.exe",
|
|
79
|
+
ia32: "cloudflared-windows-386.exe"
|
|
80
|
+
};
|
|
81
|
+
function resolveBase(version) {
|
|
82
|
+
if (version === "latest") {
|
|
83
|
+
return `${RELEASE_BASE}latest/download/`;
|
|
84
|
+
}
|
|
85
|
+
return `${RELEASE_BASE}download/${version}/`;
|
|
86
|
+
}
|
|
87
|
+
function installCloudflared(to = cloudflaredBinPath, version = CLOUDFLARED_VERSION) {
|
|
88
|
+
switch (process.platform) {
|
|
89
|
+
case "linux": {
|
|
90
|
+
return installLinux(to, version);
|
|
91
|
+
}
|
|
92
|
+
case "darwin": {
|
|
93
|
+
return installMacos(to, version);
|
|
94
|
+
}
|
|
95
|
+
case "win32": {
|
|
96
|
+
return installWindows(to, version);
|
|
97
|
+
}
|
|
98
|
+
default: {
|
|
99
|
+
throw new Error("Unsupported platform: " + process.platform);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function installLinux(to, version = CLOUDFLARED_VERSION) {
|
|
104
|
+
const file = LINUX_URL[process.arch];
|
|
105
|
+
if (file === void 0) {
|
|
106
|
+
throw new Error("Unsupported architecture: " + process.arch);
|
|
107
|
+
}
|
|
108
|
+
await download(resolveBase(version) + file, to);
|
|
109
|
+
fs__default.chmodSync(to, "755");
|
|
110
|
+
return to;
|
|
111
|
+
}
|
|
112
|
+
async function installMacos(to, version = CLOUDFLARED_VERSION) {
|
|
113
|
+
const file = MACOS_URL[process.arch];
|
|
114
|
+
if (file === void 0) {
|
|
115
|
+
throw new Error("Unsupported architecture: " + process.arch);
|
|
116
|
+
}
|
|
117
|
+
await download(resolveBase(version) + file, `${to}.tgz`);
|
|
118
|
+
process.env.DEBUG && console.log(`Extracting to ${to}`);
|
|
119
|
+
childProcess.execSync(`tar -xzf ${path__default.basename(`${to}.tgz`)}`, { cwd: path__default.dirname(to) });
|
|
120
|
+
fs__default.unlinkSync(`${to}.tgz`);
|
|
121
|
+
fs__default.renameSync(`${path__default.dirname(to)}/cloudflared`, to);
|
|
122
|
+
return to;
|
|
123
|
+
}
|
|
124
|
+
async function installWindows(to, version = CLOUDFLARED_VERSION) {
|
|
125
|
+
const file = WINDOWS_URL[process.arch];
|
|
126
|
+
if (file === void 0) {
|
|
127
|
+
throw new Error("Unsupported architecture: " + process.arch);
|
|
128
|
+
}
|
|
129
|
+
await download(resolveBase(version) + file, to);
|
|
130
|
+
return to;
|
|
131
|
+
}
|
|
132
|
+
function download(url, to, redirect = 0) {
|
|
133
|
+
if (redirect === 0) {
|
|
134
|
+
process.env.DEBUG && console.log(`Downloading ${url} to ${to}`);
|
|
135
|
+
} else {
|
|
136
|
+
process.env.DEBUG && console.log(`Redirecting to ${url}`);
|
|
137
|
+
}
|
|
138
|
+
return new Promise((resolve, reject) => {
|
|
139
|
+
if (!fs__default.existsSync(path__default.dirname(to))) {
|
|
140
|
+
fs__default.mkdirSync(path__default.dirname(to), { recursive: true });
|
|
141
|
+
}
|
|
142
|
+
let done = true;
|
|
143
|
+
const file = fs__default.createWriteStream(to);
|
|
144
|
+
const request = https__default.get(url, (res) => {
|
|
145
|
+
if (res.statusCode === 302 && res.headers.location !== void 0) {
|
|
146
|
+
const redirection = res.headers.location;
|
|
147
|
+
done = false;
|
|
148
|
+
file.close(() => resolve(download(redirection, to, redirect + 1)));
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
res.pipe(file);
|
|
152
|
+
});
|
|
153
|
+
file.on("finish", () => {
|
|
154
|
+
if (done) {
|
|
155
|
+
file.close(() => resolve(to));
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
request.on("error", (err) => {
|
|
159
|
+
fs__default.unlink(to, () => reject(err));
|
|
160
|
+
});
|
|
161
|
+
file.on("error", (err) => {
|
|
162
|
+
fs__default.unlink(to, () => reject(err));
|
|
163
|
+
});
|
|
164
|
+
request.end();
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function startCloudflaredTunnel(options = {}) {
|
|
169
|
+
const args = ["tunnel"];
|
|
170
|
+
for (const [key, value] of Object.entries(options)) {
|
|
171
|
+
if (typeof value === "string") {
|
|
172
|
+
args.push(`${key}`, value);
|
|
173
|
+
} else if (typeof value === "number") {
|
|
174
|
+
args.push(`${key}`, value.toString());
|
|
175
|
+
} else if (value === null) {
|
|
176
|
+
args.push(`${key}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (args.length === 1) {
|
|
180
|
+
args.push("--url", "localhost:8080");
|
|
181
|
+
}
|
|
182
|
+
const child = childProcess.spawn(cloudflaredBinPath, args, {
|
|
183
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
184
|
+
});
|
|
185
|
+
if (process.env.DEBUG) {
|
|
186
|
+
child.stdout.pipe(process.stdout);
|
|
187
|
+
child.stderr.pipe(process.stderr);
|
|
188
|
+
}
|
|
189
|
+
const urlRegex = /\|\s+(https?:\/\/\S+)/;
|
|
190
|
+
let urlResolver = () => void 0;
|
|
191
|
+
let urlRejector = () => void 0;
|
|
192
|
+
const url = new Promise(
|
|
193
|
+
(...pair) => [urlResolver, urlRejector] = pair
|
|
194
|
+
);
|
|
195
|
+
const connectionResolvers = [];
|
|
196
|
+
const connectionRejectors = [];
|
|
197
|
+
const connections = [];
|
|
198
|
+
for (let i = 0; i < 1; i++) {
|
|
199
|
+
connections.push(
|
|
200
|
+
new Promise(
|
|
201
|
+
(...pair) => [connectionResolvers[i], connectionRejectors[i]] = pair
|
|
202
|
+
)
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
const parser = (data) => {
|
|
206
|
+
const str = data.toString();
|
|
207
|
+
const urlMatch = str.match(urlRegex);
|
|
208
|
+
urlMatch && urlResolver(urlMatch[1]);
|
|
209
|
+
const connMatch = str.match(connRegex);
|
|
210
|
+
const ipMatch = str.match(ipRegex);
|
|
211
|
+
const locationMatch = str.match(locationRegex);
|
|
212
|
+
const indexMatch = str.match(indexRegex);
|
|
213
|
+
if (connMatch && ipMatch && locationMatch && indexMatch) {
|
|
214
|
+
const [, id] = connMatch;
|
|
215
|
+
const [, ip] = ipMatch;
|
|
216
|
+
const [, location] = locationMatch;
|
|
217
|
+
const [, idx] = indexMatch;
|
|
218
|
+
connectionResolvers[+idx]?.({ id, ip, location });
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
child.stdout.on("data", parser).on("error", urlRejector);
|
|
222
|
+
child.stderr.on("data", parser).on("error", urlRejector);
|
|
223
|
+
const stop = () => child.kill("SIGINT");
|
|
224
|
+
return { url, connections, child, stop };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
exports.cloudflaredBinPath = cloudflaredBinPath;
|
|
228
|
+
exports.cloudflaredNotice = cloudflaredNotice;
|
|
229
|
+
exports.installCloudflared = installCloudflared;
|
|
230
|
+
exports.startCloudflaredTunnel = startCloudflaredTunnel;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { tmpdir } from 'node:os';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path$1 from 'node:path';
|
|
4
|
+
import https from 'node:https';
|
|
5
|
+
import { execSync, spawn } from 'node:child_process';
|
|
6
|
+
import { p as path } from '../cli.mjs';
|
|
7
|
+
import 'node:tty';
|
|
8
|
+
import 'stream';
|
|
9
|
+
import '../shared/arri.b4c5ce27.mjs';
|
|
10
|
+
import 'os';
|
|
11
|
+
import 'path';
|
|
12
|
+
import 'util';
|
|
13
|
+
import 'events';
|
|
14
|
+
import 'fs';
|
|
15
|
+
import 'node:process';
|
|
16
|
+
import 'node:url';
|
|
17
|
+
import 'node:stream';
|
|
18
|
+
import 'crypto';
|
|
19
|
+
import 'node:fs/promises';
|
|
20
|
+
import 'module';
|
|
21
|
+
import 'perf_hooks';
|
|
22
|
+
import 'vm';
|
|
23
|
+
import 'url';
|
|
24
|
+
import 'assert';
|
|
25
|
+
import 'process';
|
|
26
|
+
import 'v8';
|
|
27
|
+
import 'tty';
|
|
28
|
+
import 'node:module';
|
|
29
|
+
import 'node:assert';
|
|
30
|
+
import 'node:v8';
|
|
31
|
+
import 'node:util';
|
|
32
|
+
import '../shared/arri.34695f7b.mjs';
|
|
33
|
+
import 'fs/promises';
|
|
34
|
+
import 'node:http';
|
|
35
|
+
import 'node:net';
|
|
36
|
+
import 'http';
|
|
37
|
+
import 'https';
|
|
38
|
+
|
|
39
|
+
const CLOUDFLARED_VERSION = process.env.CLOUDFLARED_VERSION || "2023.7.3";
|
|
40
|
+
const RELEASE_BASE = "https://github.com/cloudflare/cloudflared/releases/";
|
|
41
|
+
const cloudflaredBinPath = path.join(
|
|
42
|
+
tmpdir(),
|
|
43
|
+
"node-untun",
|
|
44
|
+
process.platform === "win32" ? `cloudflared.${CLOUDFLARED_VERSION}.exe` : `cloudflared.${CLOUDFLARED_VERSION}`
|
|
45
|
+
);
|
|
46
|
+
const cloudflaredNotice = `
|
|
47
|
+
\u{1F525} Your installation of cloudflared software constitutes a symbol of your signature
|
|
48
|
+
indicating that you accept the terms of the Cloudflare License, Terms and Privacy Policy.
|
|
49
|
+
|
|
50
|
+
\u276F License: \`https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/license/\`
|
|
51
|
+
\u276F Terms: \`https://www.cloudflare.com/terms/\`
|
|
52
|
+
\u276F Privacy Policy: \`https://www.cloudflare.com/privacypolicy/\`
|
|
53
|
+
`;
|
|
54
|
+
const connRegex = /connection[ =]([\da-z-]+)/i;
|
|
55
|
+
const ipRegex = /ip=([\d.]+)/;
|
|
56
|
+
const locationRegex = /location=([A-Z]+)/;
|
|
57
|
+
const indexRegex = /connIndex=(\d)/;
|
|
58
|
+
|
|
59
|
+
const LINUX_URL = {
|
|
60
|
+
arm64: "cloudflared-linux-arm64",
|
|
61
|
+
arm: "cloudflared-linux-arm",
|
|
62
|
+
x64: "cloudflared-linux-amd64",
|
|
63
|
+
ia32: "cloudflared-linux-386"
|
|
64
|
+
};
|
|
65
|
+
const MACOS_URL = {
|
|
66
|
+
arm64: "cloudflared-darwin-amd64.tgz",
|
|
67
|
+
x64: "cloudflared-darwin-amd64.tgz"
|
|
68
|
+
};
|
|
69
|
+
const WINDOWS_URL = {
|
|
70
|
+
x64: "cloudflared-windows-amd64.exe",
|
|
71
|
+
ia32: "cloudflared-windows-386.exe"
|
|
72
|
+
};
|
|
73
|
+
function resolveBase(version) {
|
|
74
|
+
if (version === "latest") {
|
|
75
|
+
return `${RELEASE_BASE}latest/download/`;
|
|
76
|
+
}
|
|
77
|
+
return `${RELEASE_BASE}download/${version}/`;
|
|
78
|
+
}
|
|
79
|
+
function installCloudflared(to = cloudflaredBinPath, version = CLOUDFLARED_VERSION) {
|
|
80
|
+
switch (process.platform) {
|
|
81
|
+
case "linux": {
|
|
82
|
+
return installLinux(to, version);
|
|
83
|
+
}
|
|
84
|
+
case "darwin": {
|
|
85
|
+
return installMacos(to, version);
|
|
86
|
+
}
|
|
87
|
+
case "win32": {
|
|
88
|
+
return installWindows(to, version);
|
|
89
|
+
}
|
|
90
|
+
default: {
|
|
91
|
+
throw new Error("Unsupported platform: " + process.platform);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function installLinux(to, version = CLOUDFLARED_VERSION) {
|
|
96
|
+
const file = LINUX_URL[process.arch];
|
|
97
|
+
if (file === void 0) {
|
|
98
|
+
throw new Error("Unsupported architecture: " + process.arch);
|
|
99
|
+
}
|
|
100
|
+
await download(resolveBase(version) + file, to);
|
|
101
|
+
fs.chmodSync(to, "755");
|
|
102
|
+
return to;
|
|
103
|
+
}
|
|
104
|
+
async function installMacos(to, version = CLOUDFLARED_VERSION) {
|
|
105
|
+
const file = MACOS_URL[process.arch];
|
|
106
|
+
if (file === void 0) {
|
|
107
|
+
throw new Error("Unsupported architecture: " + process.arch);
|
|
108
|
+
}
|
|
109
|
+
await download(resolveBase(version) + file, `${to}.tgz`);
|
|
110
|
+
process.env.DEBUG && console.log(`Extracting to ${to}`);
|
|
111
|
+
execSync(`tar -xzf ${path$1.basename(`${to}.tgz`)}`, { cwd: path$1.dirname(to) });
|
|
112
|
+
fs.unlinkSync(`${to}.tgz`);
|
|
113
|
+
fs.renameSync(`${path$1.dirname(to)}/cloudflared`, to);
|
|
114
|
+
return to;
|
|
115
|
+
}
|
|
116
|
+
async function installWindows(to, version = CLOUDFLARED_VERSION) {
|
|
117
|
+
const file = WINDOWS_URL[process.arch];
|
|
118
|
+
if (file === void 0) {
|
|
119
|
+
throw new Error("Unsupported architecture: " + process.arch);
|
|
120
|
+
}
|
|
121
|
+
await download(resolveBase(version) + file, to);
|
|
122
|
+
return to;
|
|
123
|
+
}
|
|
124
|
+
function download(url, to, redirect = 0) {
|
|
125
|
+
if (redirect === 0) {
|
|
126
|
+
process.env.DEBUG && console.log(`Downloading ${url} to ${to}`);
|
|
127
|
+
} else {
|
|
128
|
+
process.env.DEBUG && console.log(`Redirecting to ${url}`);
|
|
129
|
+
}
|
|
130
|
+
return new Promise((resolve, reject) => {
|
|
131
|
+
if (!fs.existsSync(path$1.dirname(to))) {
|
|
132
|
+
fs.mkdirSync(path$1.dirname(to), { recursive: true });
|
|
133
|
+
}
|
|
134
|
+
let done = true;
|
|
135
|
+
const file = fs.createWriteStream(to);
|
|
136
|
+
const request = https.get(url, (res) => {
|
|
137
|
+
if (res.statusCode === 302 && res.headers.location !== void 0) {
|
|
138
|
+
const redirection = res.headers.location;
|
|
139
|
+
done = false;
|
|
140
|
+
file.close(() => resolve(download(redirection, to, redirect + 1)));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
res.pipe(file);
|
|
144
|
+
});
|
|
145
|
+
file.on("finish", () => {
|
|
146
|
+
if (done) {
|
|
147
|
+
file.close(() => resolve(to));
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
request.on("error", (err) => {
|
|
151
|
+
fs.unlink(to, () => reject(err));
|
|
152
|
+
});
|
|
153
|
+
file.on("error", (err) => {
|
|
154
|
+
fs.unlink(to, () => reject(err));
|
|
155
|
+
});
|
|
156
|
+
request.end();
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function startCloudflaredTunnel(options = {}) {
|
|
161
|
+
const args = ["tunnel"];
|
|
162
|
+
for (const [key, value] of Object.entries(options)) {
|
|
163
|
+
if (typeof value === "string") {
|
|
164
|
+
args.push(`${key}`, value);
|
|
165
|
+
} else if (typeof value === "number") {
|
|
166
|
+
args.push(`${key}`, value.toString());
|
|
167
|
+
} else if (value === null) {
|
|
168
|
+
args.push(`${key}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (args.length === 1) {
|
|
172
|
+
args.push("--url", "localhost:8080");
|
|
173
|
+
}
|
|
174
|
+
const child = spawn(cloudflaredBinPath, args, {
|
|
175
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
176
|
+
});
|
|
177
|
+
if (process.env.DEBUG) {
|
|
178
|
+
child.stdout.pipe(process.stdout);
|
|
179
|
+
child.stderr.pipe(process.stderr);
|
|
180
|
+
}
|
|
181
|
+
const urlRegex = /\|\s+(https?:\/\/\S+)/;
|
|
182
|
+
let urlResolver = () => void 0;
|
|
183
|
+
let urlRejector = () => void 0;
|
|
184
|
+
const url = new Promise(
|
|
185
|
+
(...pair) => [urlResolver, urlRejector] = pair
|
|
186
|
+
);
|
|
187
|
+
const connectionResolvers = [];
|
|
188
|
+
const connectionRejectors = [];
|
|
189
|
+
const connections = [];
|
|
190
|
+
for (let i = 0; i < 1; i++) {
|
|
191
|
+
connections.push(
|
|
192
|
+
new Promise(
|
|
193
|
+
(...pair) => [connectionResolvers[i], connectionRejectors[i]] = pair
|
|
194
|
+
)
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
const parser = (data) => {
|
|
198
|
+
const str = data.toString();
|
|
199
|
+
const urlMatch = str.match(urlRegex);
|
|
200
|
+
urlMatch && urlResolver(urlMatch[1]);
|
|
201
|
+
const connMatch = str.match(connRegex);
|
|
202
|
+
const ipMatch = str.match(ipRegex);
|
|
203
|
+
const locationMatch = str.match(locationRegex);
|
|
204
|
+
const indexMatch = str.match(indexRegex);
|
|
205
|
+
if (connMatch && ipMatch && locationMatch && indexMatch) {
|
|
206
|
+
const [, id] = connMatch;
|
|
207
|
+
const [, ip] = ipMatch;
|
|
208
|
+
const [, location] = locationMatch;
|
|
209
|
+
const [, idx] = indexMatch;
|
|
210
|
+
connectionResolvers[+idx]?.({ id, ip, location });
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
child.stdout.on("data", parser).on("error", urlRejector);
|
|
214
|
+
child.stderr.on("data", parser).on("error", urlRejector);
|
|
215
|
+
const stop = () => child.kill("SIGINT");
|
|
216
|
+
return { url, connections, child, stop };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export { cloudflaredBinPath, cloudflaredNotice, installCloudflared, startCloudflaredTunnel };
|