@forge/tunnel 5.0.2-next.2 → 5.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/CHANGELOG.md +18 -0
- package/out/command/interactors/function-change-watcher.js +6 -9
- package/out/command/interactors/multi-compiler-watcher.js +3 -13
- package/out/command/interactors/tunnel-interactor.js +47 -48
- package/out/command/start-tunnel-command.js +38 -55
- package/out/graphql/tunnel-graphql-client.js +0 -1
- package/out/sandbox/node-sandbox.js +2 -4
- package/out/sandbox/sandbox-runner.js +2 -1
- package/out/servers/csp-reporter-server.js +3 -7
- package/out/servers/custom-ui-tunnel-server.js +5 -8
- package/out/servers/dev-server.js +33 -44
- package/out/servers/native-ui-tunnel-server.js +3 -10
- package/out/servers/resource-tunnel-server.js +30 -35
- package/out/services/create-tunnel-service.js +3 -5
- package/out/services/local-invocation-service.js +9 -11
- package/out/services/register-tunnel-service.js +0 -3
- package/out/util/sandboxes-container.js +4 -2
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @forge/tunnel
|
|
2
2
|
|
|
3
|
+
## 5.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [092b932]
|
|
8
|
+
- Updated dependencies [937db7a]
|
|
9
|
+
- @forge/runtime@5.7.0
|
|
10
|
+
- @forge/cli-shared@4.0.1
|
|
11
|
+
- @forge/bundler@4.15.11
|
|
12
|
+
|
|
13
|
+
## 5.0.2-next.3
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [937db7a]
|
|
18
|
+
- @forge/cli-shared@4.0.1-next.2
|
|
19
|
+
- @forge/bundler@4.15.11-next.2
|
|
20
|
+
|
|
3
21
|
## 5.0.2-next.2
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -10,16 +10,15 @@ const runtime_1 = require("@forge/runtime");
|
|
|
10
10
|
const util_1 = require("../../util");
|
|
11
11
|
exports.MEMORY_LIMIT = 256;
|
|
12
12
|
class LocalFunctionHost {
|
|
13
|
-
configFile;
|
|
14
|
-
logger;
|
|
15
|
-
snapshot;
|
|
16
|
-
createSandbox;
|
|
17
|
-
snapshotLogs = [];
|
|
18
13
|
constructor(configFile, logger, snapshot, createSandbox) {
|
|
19
14
|
this.configFile = configFile;
|
|
20
15
|
this.logger = logger;
|
|
21
16
|
this.snapshot = snapshot;
|
|
22
17
|
this.createSandbox = createSandbox;
|
|
18
|
+
this.snapshotLogs = [];
|
|
19
|
+
this.onRuntimeLog = (event) => {
|
|
20
|
+
this.logger.info((0, util_1.formatRuntimeLog)(event));
|
|
21
|
+
};
|
|
23
22
|
}
|
|
24
23
|
async generateBundleFiles(bundle, withSnapshot) {
|
|
25
24
|
await fs_1.promises.mkdir((0, path_1.dirname)(bundle.bundleFilePath), { recursive: true });
|
|
@@ -49,12 +48,13 @@ class LocalFunctionHost {
|
|
|
49
48
|
this.snapshotLogs = [];
|
|
50
49
|
}
|
|
51
50
|
const bundles = Object.keys(bundledCode.output).map((bundlePath) => {
|
|
51
|
+
var _a;
|
|
52
52
|
const sourceMapPath = `${bundlePath}.map`;
|
|
53
53
|
return {
|
|
54
54
|
bundleFilePath: (0, path_1.resolve)(directory, bundlePath),
|
|
55
55
|
bundleFileContent: bundledCode.output[bundlePath],
|
|
56
56
|
bundleFileSourceMapPath: (0, path_1.resolve)(directory, sourceMapPath),
|
|
57
|
-
bundleFileSourceMap: bundledCode.sourceMap
|
|
57
|
+
bundleFileSourceMap: (_a = bundledCode.sourceMap) === null || _a === void 0 ? void 0 : _a[sourceMapPath]
|
|
58
58
|
};
|
|
59
59
|
});
|
|
60
60
|
const manifestFilePath = (0, path_1.resolve)(directory, cli_shared_1.manifestFileName);
|
|
@@ -84,9 +84,6 @@ class LocalFunctionHost {
|
|
|
84
84
|
async stopWatching() {
|
|
85
85
|
runtime_1.StaticInvocationEventEmitter.removeAllListeners();
|
|
86
86
|
}
|
|
87
|
-
onRuntimeLog = (event) => {
|
|
88
|
-
this.logger.info((0, util_1.formatRuntimeLog)(event));
|
|
89
|
-
};
|
|
90
87
|
async initializeSandboxes(srcPath, tunnelOptions) {
|
|
91
88
|
try {
|
|
92
89
|
const handlers = await this.configFile.getAppHandlers();
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MultiCompilerWatcher = void 0;
|
|
4
4
|
class MultiCompilerWatcher {
|
|
5
|
-
servers;
|
|
6
5
|
constructor(servers) {
|
|
7
6
|
this.servers = servers;
|
|
8
7
|
}
|
|
@@ -15,18 +14,9 @@ class MultiCompilerWatcher {
|
|
|
15
14
|
output: {}
|
|
16
15
|
};
|
|
17
16
|
for (const result of results) {
|
|
18
|
-
multiResult.output = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
multiResult.sourceMap = {
|
|
23
|
-
...multiResult.sourceMap,
|
|
24
|
-
...result.sourceMap
|
|
25
|
-
};
|
|
26
|
-
multiResult.metadata = {
|
|
27
|
-
...multiResult.metadata,
|
|
28
|
-
...result.metadata
|
|
29
|
-
};
|
|
17
|
+
multiResult.output = Object.assign(Object.assign({}, multiResult.output), result.output);
|
|
18
|
+
multiResult.sourceMap = Object.assign(Object.assign({}, multiResult.sourceMap), result.sourceMap);
|
|
19
|
+
multiResult.metadata = Object.assign(Object.assign({}, multiResult.metadata), result.metadata);
|
|
30
20
|
}
|
|
31
21
|
return multiResult;
|
|
32
22
|
}
|
|
@@ -7,9 +7,55 @@ const bundler_1 = require("@forge/bundler");
|
|
|
7
7
|
const cli_shared_1 = require("@forge/cli-shared");
|
|
8
8
|
const multi_compiler_watcher_1 = require("./multi-compiler-watcher");
|
|
9
9
|
class TunnelInteractor {
|
|
10
|
-
logger;
|
|
11
10
|
constructor(logger) {
|
|
12
11
|
this.logger = logger;
|
|
12
|
+
this.watchApp = async (startTunnelResult, tunnelOptions = {}) => {
|
|
13
|
+
const { localPort, inspectorAddress, reloadSandboxes, devServers } = startTunnelResult;
|
|
14
|
+
if (inspectorAddress) {
|
|
15
|
+
this.logger.info(cli_shared_1.Text.tunnel.startedInspector(inspectorAddress));
|
|
16
|
+
}
|
|
17
|
+
const onBundlingStart = async () => {
|
|
18
|
+
try {
|
|
19
|
+
this.logger.info('');
|
|
20
|
+
this.logger.info(cli_shared_1.Text.bundle.detectedChanges);
|
|
21
|
+
await (0, bundler_1.runLinter)();
|
|
22
|
+
this.logger.info(cli_shared_1.Text.tunnel.preBundleTask(cli_shared_1.Text.tunnel.bundlingHeader));
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
throw err;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const onBundlingFinish = async (err, output) => {
|
|
29
|
+
if (err) {
|
|
30
|
+
this.logger.error(err);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (output) {
|
|
34
|
+
await reloadSandboxes(output, tunnelOptions);
|
|
35
|
+
}
|
|
36
|
+
this.logger.info('');
|
|
37
|
+
this.logger.info(cli_shared_1.Text.tunnel.startedServer(localPort, this.logger.debugEnabled) + '\n');
|
|
38
|
+
};
|
|
39
|
+
if (devServers.length > 0) {
|
|
40
|
+
const multiCompiler = new multi_compiler_watcher_1.MultiCompilerWatcher(devServers);
|
|
41
|
+
await (0, bundler_1.runLinter)();
|
|
42
|
+
this.logger.info(cli_shared_1.Text.tunnel.preBundleTask(cli_shared_1.Text.tunnel.bundlingHeader));
|
|
43
|
+
try {
|
|
44
|
+
const output = await multiCompiler.compileAndWatch({
|
|
45
|
+
onChange: {
|
|
46
|
+
onBuildWillStart: onBundlingStart,
|
|
47
|
+
onBuildFinished: onBundlingFinish
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
await reloadSandboxes(output, tunnelOptions);
|
|
51
|
+
this.logger.info('');
|
|
52
|
+
this.logger.info(cli_shared_1.Text.tunnel.startedServer(localPort, this.logger.debugEnabled) + '\n');
|
|
53
|
+
}
|
|
54
|
+
catch (_) {
|
|
55
|
+
}
|
|
56
|
+
return multiCompiler;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
13
59
|
}
|
|
14
60
|
handleUserExitEvent(stopFunction, bundleMonitor) {
|
|
15
61
|
return new Promise((resolve, reject) => {
|
|
@@ -42,52 +88,5 @@ class TunnelInteractor {
|
|
|
42
88
|
process.on('SIGTERM', tunnelCleanupListener);
|
|
43
89
|
});
|
|
44
90
|
}
|
|
45
|
-
watchApp = async (startTunnelResult, tunnelOptions = {}) => {
|
|
46
|
-
const { localPort, inspectorAddress, reloadSandboxes, devServers } = startTunnelResult;
|
|
47
|
-
if (inspectorAddress) {
|
|
48
|
-
this.logger.info(cli_shared_1.Text.tunnel.startedInspector(inspectorAddress));
|
|
49
|
-
}
|
|
50
|
-
const onBundlingStart = async () => {
|
|
51
|
-
try {
|
|
52
|
-
this.logger.info('');
|
|
53
|
-
this.logger.info(cli_shared_1.Text.bundle.detectedChanges);
|
|
54
|
-
await (0, bundler_1.runLinter)();
|
|
55
|
-
this.logger.info(cli_shared_1.Text.tunnel.preBundleTask(cli_shared_1.Text.tunnel.bundlingHeader));
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
throw err;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const onBundlingFinish = async (err, output) => {
|
|
62
|
-
if (err) {
|
|
63
|
-
this.logger.error(err);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (output) {
|
|
67
|
-
await reloadSandboxes(output, tunnelOptions);
|
|
68
|
-
}
|
|
69
|
-
this.logger.info('');
|
|
70
|
-
this.logger.info(cli_shared_1.Text.tunnel.startedServer(localPort, this.logger.debugEnabled) + '\n');
|
|
71
|
-
};
|
|
72
|
-
if (devServers.length > 0) {
|
|
73
|
-
const multiCompiler = new multi_compiler_watcher_1.MultiCompilerWatcher(devServers);
|
|
74
|
-
await (0, bundler_1.runLinter)();
|
|
75
|
-
this.logger.info(cli_shared_1.Text.tunnel.preBundleTask(cli_shared_1.Text.tunnel.bundlingHeader));
|
|
76
|
-
try {
|
|
77
|
-
const output = await multiCompiler.compileAndWatch({
|
|
78
|
-
onChange: {
|
|
79
|
-
onBuildWillStart: onBundlingStart,
|
|
80
|
-
onBuildFinished: onBundlingFinish
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
await reloadSandboxes(output, tunnelOptions);
|
|
84
|
-
this.logger.info('');
|
|
85
|
-
this.logger.info(cli_shared_1.Text.tunnel.startedServer(localPort, this.logger.debugEnabled) + '\n');
|
|
86
|
-
}
|
|
87
|
-
catch (_) {
|
|
88
|
-
}
|
|
89
|
-
return multiCompiler;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
91
|
}
|
|
93
92
|
exports.TunnelInteractor = TunnelInteractor;
|
|
@@ -8,16 +8,6 @@ const node_cache_1 = tslib_1.__importDefault(require("node-cache"));
|
|
|
8
8
|
const servers_1 = require("../servers");
|
|
9
9
|
const index_1 = require("../index");
|
|
10
10
|
class StartTunnelCommand {
|
|
11
|
-
getAppConfig;
|
|
12
|
-
devServer;
|
|
13
|
-
tunnelFactory;
|
|
14
|
-
tunnelClient;
|
|
15
|
-
functionHost;
|
|
16
|
-
inspector;
|
|
17
|
-
logger;
|
|
18
|
-
configFile;
|
|
19
|
-
tunnelServers = {};
|
|
20
|
-
cspReporterServer;
|
|
21
11
|
constructor(getAppConfig, devServer, tunnelFactory, tunnelClient, functionHost, inspector, logger, configFile) {
|
|
22
12
|
this.getAppConfig = getAppConfig;
|
|
23
13
|
this.devServer = devServer;
|
|
@@ -27,51 +17,44 @@ class StartTunnelCommand {
|
|
|
27
17
|
this.inspector = inspector;
|
|
28
18
|
this.logger = logger;
|
|
29
19
|
this.configFile = configFile;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
tunnelUrl: faasTunnelUrl
|
|
20
|
+
this.tunnelServers = {};
|
|
21
|
+
this.stopServices = async (appId, environmentKey) => {
|
|
22
|
+
var _a;
|
|
23
|
+
await Promise.all([
|
|
24
|
+
this.functionHost.stopWatching(),
|
|
25
|
+
this.tunnelClient.unregisterTunnels(appId, environmentKey),
|
|
26
|
+
this.tunnelFactory.closeTunnel(),
|
|
27
|
+
this.devServer.stop(),
|
|
28
|
+
this.inspector.stopServer(),
|
|
29
|
+
...Object.values(this.tunnelServers).map((server) => server.stop()),
|
|
30
|
+
(_a = this.cspReporterServer) === null || _a === void 0 ? void 0 : _a.stop()
|
|
31
|
+
]);
|
|
32
|
+
};
|
|
33
|
+
this.startFaaSTunnelServer = async ({ port, tunnelConfigPath }) => {
|
|
34
|
+
const { permissions = {}, remotes = [] } = await this.configFile.readConfig();
|
|
35
|
+
const serverInfo = await this.devServer.start(port, permissions, remotes);
|
|
36
|
+
const faasTunnelUrl = await this.tunnelFactory.establishTunnel({ port: serverInfo.port, tunnelConfigPath });
|
|
37
|
+
return Object.assign(Object.assign({}, serverInfo), { tunnelUrl: faasTunnelUrl });
|
|
49
38
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
permissions,
|
|
70
|
-
remotes
|
|
71
|
-
});
|
|
72
|
-
return this.tunnelServers[key].start();
|
|
73
|
-
}));
|
|
74
|
-
};
|
|
39
|
+
this.startResourceBasedTunnelsServers = async (resourceDetails, options) => {
|
|
40
|
+
var _a, _b, _c;
|
|
41
|
+
const portMap = (_a = options.resourcePortMap) !== null && _a !== void 0 ? _a : JSON.parse((_b = process.env.RESOURCE_PORT_MAP) !== null && _b !== void 0 ? _b : '{}');
|
|
42
|
+
const { permissions = {}, remotes = [] } = await this.configFile.readConfig();
|
|
43
|
+
const cspReporterPort = parseInt((_c = process.env.CSP_REPORTER_PORT) !== null && _c !== void 0 ? _c : '4000', 10);
|
|
44
|
+
if (resourceDetails.length === 0)
|
|
45
|
+
return [];
|
|
46
|
+
this.cspReporterServer = new servers_1.CspReporterServer(cspReporterPort, this.logger, new node_cache_1.default());
|
|
47
|
+
await this.cspReporterServer.start();
|
|
48
|
+
return await Promise.all(resourceDetails.map(async (rd) => {
|
|
49
|
+
const { key, resourceType } = rd;
|
|
50
|
+
const port = portMap[key];
|
|
51
|
+
const tunnelServer = resourceType === 'nativeUI' ? servers_1.NativeUITunnelServer : servers_1.CustomUITunnelServer;
|
|
52
|
+
this.tunnelServers[key] = new tunnelServer(Object.assign(Object.assign({}, rd), { port, host: options.host, logger: this.logger, cspReporterServerPort: cspReporterPort, permissions,
|
|
53
|
+
remotes }));
|
|
54
|
+
return this.tunnelServers[key].start();
|
|
55
|
+
}));
|
|
56
|
+
};
|
|
57
|
+
}
|
|
75
58
|
async execute(options) {
|
|
76
59
|
const { id: appId } = await this.getAppConfig();
|
|
77
60
|
const { port, environmentKey } = options;
|
|
@@ -116,7 +99,7 @@ class StartTunnelCommand {
|
|
|
116
99
|
try {
|
|
117
100
|
await this.stopServices(appId, environmentKey);
|
|
118
101
|
}
|
|
119
|
-
catch { }
|
|
102
|
+
catch (_a) { }
|
|
120
103
|
throw e;
|
|
121
104
|
}
|
|
122
105
|
}
|
|
@@ -9,9 +9,6 @@ const uuid_1 = require("uuid");
|
|
|
9
9
|
const runtime_1 = require("@forge/runtime");
|
|
10
10
|
const RUNNER = (0, path_1.join)(__dirname, '..', '..', 'out', 'sandbox', 'sandbox-runner.js');
|
|
11
11
|
class NodeSandbox {
|
|
12
|
-
name;
|
|
13
|
-
process;
|
|
14
|
-
callbacks;
|
|
15
12
|
constructor({ appPath, modName, handler, debugPort }) {
|
|
16
13
|
this.name = `${modName}.${handler}`;
|
|
17
14
|
const fileName = `${appPath}/${modName}.cjs`;
|
|
@@ -28,9 +25,10 @@ class NodeSandbox {
|
|
|
28
25
|
this.handleOutput(message);
|
|
29
26
|
});
|
|
30
27
|
this.process.on('message', (message) => {
|
|
28
|
+
var _a;
|
|
31
29
|
const requestId = message.requestId;
|
|
32
30
|
const result = message.result;
|
|
33
|
-
this.callbacks.get(requestId)
|
|
31
|
+
(_a = this.callbacks.get(requestId)) === null || _a === void 0 ? void 0 : _a(result);
|
|
34
32
|
});
|
|
35
33
|
}
|
|
36
34
|
handleOutput(output) {
|
|
@@ -3,7 +3,8 @@ const [_nodeBinary, _thisScript, fileName, handlerName] = process.argv;
|
|
|
3
3
|
global.__forge_tunnel__ = true;
|
|
4
4
|
const handler = require(fileName)[handlerName];
|
|
5
5
|
process.on('message', async ({ lambdaEvent, lambdaContext }) => {
|
|
6
|
+
var _a;
|
|
6
7
|
const requestId = lambdaContext.awsRequestId;
|
|
7
8
|
const result = await handler(lambdaEvent, lambdaContext);
|
|
8
|
-
process.send
|
|
9
|
+
(_a = process.send) === null || _a === void 0 ? void 0 : _a.call(process, { requestId, result });
|
|
9
10
|
});
|
|
@@ -5,12 +5,6 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const express_1 = tslib_1.__importDefault(require("express"));
|
|
6
6
|
const cli_shared_1 = require("@forge/cli-shared");
|
|
7
7
|
class CspReporterServer {
|
|
8
|
-
port;
|
|
9
|
-
logger;
|
|
10
|
-
cache;
|
|
11
|
-
app;
|
|
12
|
-
server;
|
|
13
|
-
static TTL_IN_SECONDS = 30;
|
|
14
8
|
constructor(port, logger, cache) {
|
|
15
9
|
this.port = port;
|
|
16
10
|
this.logger = logger;
|
|
@@ -41,8 +35,10 @@ class CspReporterServer {
|
|
|
41
35
|
}
|
|
42
36
|
async stop() {
|
|
43
37
|
return new Promise((resolve, reject) => {
|
|
44
|
-
|
|
38
|
+
var _a;
|
|
39
|
+
(_a = this.server) === null || _a === void 0 ? void 0 : _a.close((err) => (err ? reject(err) : resolve()));
|
|
45
40
|
});
|
|
46
41
|
}
|
|
47
42
|
}
|
|
48
43
|
exports.CspReporterServer = CspReporterServer;
|
|
44
|
+
CspReporterServer.TTL_IN_SECONDS = 30;
|
|
@@ -14,19 +14,15 @@ var ConnectionErrorCode;
|
|
|
14
14
|
ConnectionErrorCode["REFUSED"] = "ECONNREFUSED";
|
|
15
15
|
})(ConnectionErrorCode || (ConnectionErrorCode = {}));
|
|
16
16
|
class CustomUITunnelServer extends resource_tunnel_server_1.ResourceTunnelServer {
|
|
17
|
-
tunnelArgs;
|
|
18
|
-
app;
|
|
19
|
-
server;
|
|
20
|
-
proxy;
|
|
21
|
-
socket;
|
|
22
17
|
constructor(tunnelArgs) {
|
|
18
|
+
var _a, _b;
|
|
23
19
|
super(tunnelArgs);
|
|
24
20
|
this.tunnelArgs = tunnelArgs;
|
|
25
21
|
const { tunnel, permissions, remotes } = tunnelArgs;
|
|
26
22
|
this.app = (0, express_1.default)();
|
|
27
23
|
this.app.use(this.getCustomUIHtmlTransformMiddleware(permissions, remotes));
|
|
28
24
|
if (tunnel) {
|
|
29
|
-
net_1.default.setDefaultAutoSelectFamily
|
|
25
|
+
(_b = (_a = net_1.default).setDefaultAutoSelectFamily) === null || _b === void 0 ? void 0 : _b.call(_a, true);
|
|
30
26
|
const { port: tunnelPort } = tunnel;
|
|
31
27
|
this.proxy = (0, http_proxy_middleware_1.createProxyMiddleware)({
|
|
32
28
|
target: `http://${this.tunnelArgs.host}:${tunnelPort}`,
|
|
@@ -84,7 +80,7 @@ class CustomUITunnelServer extends resource_tunnel_server_1.ResourceTunnelServer
|
|
|
84
80
|
return this.app;
|
|
85
81
|
}
|
|
86
82
|
handleProxyDestinationNotStarted(err, reqUrl, res, tunnelPort) {
|
|
87
|
-
if (err
|
|
83
|
+
if ((err === null || err === void 0 ? void 0 : err.code) !== ConnectionErrorCode.REFUSED || (reqUrl !== '/' && reqUrl !== 'index.html')) {
|
|
88
84
|
this.logger.error(err);
|
|
89
85
|
return;
|
|
90
86
|
}
|
|
@@ -95,8 +91,9 @@ class CustomUITunnelServer extends resource_tunnel_server_1.ResourceTunnelServer
|
|
|
95
91
|
res.end(cli_shared_1.Text.tunnel.error.serverNotStartedOnPort(tunnelPort));
|
|
96
92
|
}
|
|
97
93
|
handleWebsocketUpgrade(req, socket, head) {
|
|
94
|
+
var _a;
|
|
98
95
|
this.socket = socket;
|
|
99
|
-
if (this.proxy
|
|
96
|
+
if ((_a = this.proxy) === null || _a === void 0 ? void 0 : _a.upgrade) {
|
|
100
97
|
return this.proxy.upgrade(req, socket, head);
|
|
101
98
|
}
|
|
102
99
|
}
|
|
@@ -19,19 +19,44 @@ async function stopServer(server) {
|
|
|
19
19
|
}
|
|
20
20
|
exports.stopServer = stopServer;
|
|
21
21
|
class LocalDevelopmentServer {
|
|
22
|
-
invocationService;
|
|
23
|
-
logger;
|
|
24
|
-
configFile;
|
|
25
|
-
fileSystemReader;
|
|
26
|
-
app;
|
|
27
|
-
httpServer;
|
|
28
|
-
permissions;
|
|
29
|
-
remotes;
|
|
30
22
|
constructor(invocationService, logger, configFile, fileSystemReader) {
|
|
31
23
|
this.invocationService = invocationService;
|
|
32
24
|
this.logger = logger;
|
|
33
25
|
this.configFile = configFile;
|
|
34
26
|
this.fileSystemReader = fileSystemReader;
|
|
27
|
+
this.handleInvocation = async (req, res) => {
|
|
28
|
+
var _a, _b, _c, _d, _e, _f;
|
|
29
|
+
const request = req.body;
|
|
30
|
+
const envVars = (0, runtime_1.getUserVars)();
|
|
31
|
+
(_a = request.variables) === null || _a === void 0 ? void 0 : _a.forEach((item) => {
|
|
32
|
+
if (!envVars.find((i) => i.key === item.key)) {
|
|
33
|
+
envVars.push(item);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
request.variables = [...envVars].sort((a, b) => a.key.localeCompare(b.key));
|
|
37
|
+
const allowList = (_f = (_e = (_d = (_c = (_b = this.permissions) === null || _b === void 0 ? void 0 : _b.external) === null || _c === void 0 ? void 0 : _c.fetch) === null || _d === void 0 ? void 0 : _d.backend) === null || _e === void 0 ? void 0 : _e.map((item) => {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
if (typeof item === 'string')
|
|
40
|
+
return item;
|
|
41
|
+
return (_b = (_a = this.remotes) === null || _a === void 0 ? void 0 : _a.find((remote) => remote.key === item.remote)) === null || _b === void 0 ? void 0 : _b.baseUrl;
|
|
42
|
+
}).filter((item) => typeof item === 'string')) !== null && _f !== void 0 ? _f : undefined;
|
|
43
|
+
request._meta = Object.assign(Object.assign({}, request._meta), { fetchAllowList: allowList });
|
|
44
|
+
try {
|
|
45
|
+
const invokeResults = await this.invocationService.invoke(request.handler, request);
|
|
46
|
+
if ((await this.configFile.runtimeType()) === cli_shared_1.RuntimeType.nodejs && !invokeResults.success) {
|
|
47
|
+
return res.status(500).send(invokeResults.error);
|
|
48
|
+
}
|
|
49
|
+
res.json(invokeResults);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
try {
|
|
53
|
+
res.status(500).send((0, util_1.toLambdaError)(error));
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
this.logger.error(e);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
35
60
|
this.app = (0, express_1.default)();
|
|
36
61
|
this.app.use(express_1.default.json({ limit: '6mb' }));
|
|
37
62
|
this.app.post(`/:fnKey`, this.handleInvocation);
|
|
@@ -96,41 +121,5 @@ class LocalDevelopmentServer {
|
|
|
96
121
|
getApp() {
|
|
97
122
|
return this.app;
|
|
98
123
|
}
|
|
99
|
-
handleInvocation = async (req, res) => {
|
|
100
|
-
const request = req.body;
|
|
101
|
-
const envVars = (0, runtime_1.getUserVars)();
|
|
102
|
-
request.variables?.forEach((item) => {
|
|
103
|
-
if (!envVars.find((i) => i.key === item.key)) {
|
|
104
|
-
envVars.push(item);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
request.variables = [...envVars].sort((a, b) => a.key.localeCompare(b.key));
|
|
108
|
-
const allowList = this.permissions?.external?.fetch?.backend
|
|
109
|
-
?.map((item) => {
|
|
110
|
-
if (typeof item === 'string')
|
|
111
|
-
return item;
|
|
112
|
-
return this.remotes?.find((remote) => remote.key === item.remote)?.baseUrl;
|
|
113
|
-
})
|
|
114
|
-
.filter((item) => typeof item === 'string') ?? undefined;
|
|
115
|
-
request._meta = {
|
|
116
|
-
...request._meta,
|
|
117
|
-
fetchAllowList: allowList
|
|
118
|
-
};
|
|
119
|
-
try {
|
|
120
|
-
const invokeResults = await this.invocationService.invoke(request.handler, request);
|
|
121
|
-
if ((await this.configFile.runtimeType()) === cli_shared_1.RuntimeType.nodejs && !invokeResults.success) {
|
|
122
|
-
return res.status(500).send(invokeResults.error);
|
|
123
|
-
}
|
|
124
|
-
res.json(invokeResults);
|
|
125
|
-
}
|
|
126
|
-
catch (error) {
|
|
127
|
-
try {
|
|
128
|
-
res.status(500).send((0, util_1.toLambdaError)(error));
|
|
129
|
-
}
|
|
130
|
-
catch (e) {
|
|
131
|
-
this.logger.error(e);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
124
|
}
|
|
136
125
|
exports.LocalDevelopmentServer = LocalDevelopmentServer;
|
|
@@ -8,26 +8,19 @@ const resource_tunnel_server_1 = require("./resource-tunnel-server");
|
|
|
8
8
|
const cli_shared_1 = require("@forge/cli-shared");
|
|
9
9
|
const url_1 = require("url");
|
|
10
10
|
class NativeUITunnelServer extends resource_tunnel_server_1.ResourceTunnelServer {
|
|
11
|
-
tunnelArgs;
|
|
12
|
-
server;
|
|
13
11
|
constructor(tunnelArgs) {
|
|
14
12
|
super(tunnelArgs);
|
|
15
13
|
this.tunnelArgs = tunnelArgs;
|
|
16
14
|
const { key, path, port, permissions, remotes } = tunnelArgs;
|
|
17
15
|
const entrypoint = { name: key, path, functions: [] };
|
|
18
16
|
const config = (0, bundler_1.getNativeUiBuildConfig)([entrypoint]);
|
|
19
|
-
const compiler = (0, bundler_1.getCompiler)({
|
|
20
|
-
...config,
|
|
21
|
-
infrastructureLogging: {
|
|
17
|
+
const compiler = (0, bundler_1.getCompiler)(Object.assign(Object.assign({}, config), { infrastructureLogging: {
|
|
22
18
|
level: 'error'
|
|
23
|
-
},
|
|
24
|
-
stats: 'errors-only',
|
|
25
|
-
watchOptions: {
|
|
19
|
+
}, stats: 'errors-only', watchOptions: {
|
|
26
20
|
aggregateTimeout: 200,
|
|
27
21
|
poll: 1000,
|
|
28
22
|
ignored: '**/node_modules'
|
|
29
|
-
}
|
|
30
|
-
});
|
|
23
|
+
} }));
|
|
31
24
|
this.server = new webpack_dev_server_1.default({
|
|
32
25
|
port,
|
|
33
26
|
host: process.env.FORGE_DEV_TUNNEL ? 'localhost' : '0.0.0.0',
|
|
@@ -5,12 +5,31 @@ const cli_shared_1 = require("@forge/cli-shared");
|
|
|
5
5
|
const csp_1 = require("@forge/csp");
|
|
6
6
|
const express_intercept_1 = require("express-intercept");
|
|
7
7
|
class ResourceTunnelServer {
|
|
8
|
-
port;
|
|
9
|
-
key;
|
|
10
|
-
path;
|
|
11
|
-
logger;
|
|
12
|
-
cspReporterServerPort;
|
|
13
8
|
constructor({ port, key, path, cspReporterServerPort, logger }) {
|
|
9
|
+
this.getCspHeader = (existingCsp) => new csp_1.CSPInjectionService()
|
|
10
|
+
.getInjectableCSP({
|
|
11
|
+
existingCSPDetails: existingCsp,
|
|
12
|
+
microsEnv: (0, cli_shared_1.getEnvironment)(cli_shared_1.CDNEnvironments),
|
|
13
|
+
tunnelCSPReporterUri: `http://localhost:${this.cspReporterServerPort}`
|
|
14
|
+
})
|
|
15
|
+
.join('; ');
|
|
16
|
+
this.injectGlobalBridgeScript = (htmlContent) => new cli_shared_1.BridgeScriptService().injectBridgeCore(htmlContent, () => {
|
|
17
|
+
throw new Error('Malformed HTML document');
|
|
18
|
+
});
|
|
19
|
+
this.injectIframeResizerScript = (htmlContent) => new cli_shared_1.IframeResizerScriptService().injectIframeResizer(htmlContent, () => {
|
|
20
|
+
throw new Error('Malformed HTML document');
|
|
21
|
+
});
|
|
22
|
+
this.getCustomUIHtmlTransformMiddleware = (permissions, remotes) => (0, express_intercept_1.responseHandler)()
|
|
23
|
+
.if((res) => /html/i.test(res.get('content-type')))
|
|
24
|
+
.replaceBuffer((body, _, res) => {
|
|
25
|
+
if (!res)
|
|
26
|
+
return body;
|
|
27
|
+
const htmlContentWithIframeResizerScript = this.injectIframeResizerScript(body);
|
|
28
|
+
const htmlContentWithBridgeScript = this.injectGlobalBridgeScript(htmlContentWithIframeResizerScript);
|
|
29
|
+
const cspDetails = new csp_1.CSPProcessingService({ info: () => { } }).getCspDetails(htmlContentWithBridgeScript, ResourceTunnelServer.transformPermissionsWithRemotes(permissions, remotes));
|
|
30
|
+
res.setHeader('Content-Security-Policy', this.getCspHeader(cspDetails));
|
|
31
|
+
return htmlContentWithBridgeScript;
|
|
32
|
+
});
|
|
14
33
|
this.port = port;
|
|
15
34
|
this.key = key;
|
|
16
35
|
this.path = path;
|
|
@@ -18,43 +37,19 @@ class ResourceTunnelServer {
|
|
|
18
37
|
this.cspReporterServerPort = cspReporterServerPort;
|
|
19
38
|
}
|
|
20
39
|
static transformPermissionsWithRemotes(permissions, remotes) {
|
|
21
|
-
|
|
22
|
-
|
|
40
|
+
var _a, _b, _c, _d, _e;
|
|
41
|
+
const client = (_d = (_c = (_b = (_a = permissions.external) === null || _a === void 0 ? void 0 : _a.fetch) === null || _b === void 0 ? void 0 : _b.client) === null || _c === void 0 ? void 0 : _c.map((item) => {
|
|
42
|
+
var _a;
|
|
23
43
|
if (typeof item === 'string')
|
|
24
44
|
return item;
|
|
25
|
-
return remotes
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
return { ...permissions, external: { ...permissions.external, fetch: { ...permissions.external?.fetch, client } } };
|
|
45
|
+
return (_a = remotes === null || remotes === void 0 ? void 0 : remotes.find((remote) => remote.key === item.remote)) === null || _a === void 0 ? void 0 : _a.baseUrl;
|
|
46
|
+
}).filter((item) => typeof item === 'string')) !== null && _d !== void 0 ? _d : undefined;
|
|
47
|
+
return Object.assign(Object.assign({}, permissions), { external: Object.assign(Object.assign({}, permissions.external), { fetch: Object.assign(Object.assign({}, (_e = permissions.external) === null || _e === void 0 ? void 0 : _e.fetch), { client }) }) });
|
|
29
48
|
}
|
|
30
49
|
logFileServed(reqUrl, textDecorator) {
|
|
31
50
|
if (reqUrl !== '/' && reqUrl !== '/index.html')
|
|
32
51
|
return;
|
|
33
52
|
this.logger.info(cli_shared_1.LogColor.trace(textDecorator('index.html')));
|
|
34
53
|
}
|
|
35
|
-
getCspHeader = (existingCsp) => new csp_1.CSPInjectionService()
|
|
36
|
-
.getInjectableCSP({
|
|
37
|
-
existingCSPDetails: existingCsp,
|
|
38
|
-
microsEnv: (0, cli_shared_1.getEnvironment)(cli_shared_1.CDNEnvironments),
|
|
39
|
-
tunnelCSPReporterUri: `http://localhost:${this.cspReporterServerPort}`
|
|
40
|
-
})
|
|
41
|
-
.join('; ');
|
|
42
|
-
injectGlobalBridgeScript = (htmlContent) => new cli_shared_1.BridgeScriptService().injectBridgeCore(htmlContent, () => {
|
|
43
|
-
throw new Error('Malformed HTML document');
|
|
44
|
-
});
|
|
45
|
-
injectIframeResizerScript = (htmlContent) => new cli_shared_1.IframeResizerScriptService().injectIframeResizer(htmlContent, () => {
|
|
46
|
-
throw new Error('Malformed HTML document');
|
|
47
|
-
});
|
|
48
|
-
getCustomUIHtmlTransformMiddleware = (permissions, remotes) => (0, express_intercept_1.responseHandler)()
|
|
49
|
-
.if((res) => /html/i.test(res.get('content-type')))
|
|
50
|
-
.replaceBuffer((body, _, res) => {
|
|
51
|
-
if (!res)
|
|
52
|
-
return body;
|
|
53
|
-
const htmlContentWithIframeResizerScript = this.injectIframeResizerScript(body);
|
|
54
|
-
const htmlContentWithBridgeScript = this.injectGlobalBridgeScript(htmlContentWithIframeResizerScript);
|
|
55
|
-
const cspDetails = new csp_1.CSPProcessingService({ info: () => { } }).getCspDetails(htmlContentWithBridgeScript, ResourceTunnelServer.transformPermissionsWithRemotes(permissions, remotes));
|
|
56
|
-
res.setHeader('Content-Security-Policy', this.getCspHeader(cspDetails));
|
|
57
|
-
return htmlContentWithBridgeScript;
|
|
58
|
-
});
|
|
59
54
|
}
|
|
60
55
|
exports.ResourceTunnelServer = ResourceTunnelServer;
|
|
@@ -34,8 +34,6 @@ class NgrokError extends cli_shared_1.BaseError {
|
|
|
34
34
|
}
|
|
35
35
|
exports.NgrokError = NgrokError;
|
|
36
36
|
class NgrokCreateTunnelService {
|
|
37
|
-
logger;
|
|
38
|
-
endpoint;
|
|
39
37
|
constructor(logger) {
|
|
40
38
|
this.logger = logger;
|
|
41
39
|
}
|
|
@@ -45,7 +43,7 @@ class NgrokCreateTunnelService {
|
|
|
45
43
|
try {
|
|
46
44
|
const options = {
|
|
47
45
|
addr: port,
|
|
48
|
-
configPath: tunnelConfigPath
|
|
46
|
+
configPath: tunnelConfigPath !== null && tunnelConfigPath !== void 0 ? tunnelConfigPath : defaultConfigPath,
|
|
49
47
|
onStatusChange: (status) => {
|
|
50
48
|
this.logger.debug(cli_shared_1.Text.tunnel.tunnelStatusChange(status));
|
|
51
49
|
},
|
|
@@ -56,7 +54,7 @@ class NgrokCreateTunnelService {
|
|
|
56
54
|
try {
|
|
57
55
|
ngrokErrorMessage = JSON.parse(ngrokErrorMessage);
|
|
58
56
|
}
|
|
59
|
-
catch { }
|
|
57
|
+
catch (_a) { }
|
|
60
58
|
}
|
|
61
59
|
this.logger.debug(data);
|
|
62
60
|
}
|
|
@@ -75,7 +73,7 @@ class NgrokCreateTunnelService {
|
|
|
75
73
|
await ngrok.disconnect();
|
|
76
74
|
await ngrok.kill();
|
|
77
75
|
}
|
|
78
|
-
catch { }
|
|
76
|
+
catch (_a) { }
|
|
79
77
|
this.endpoint = undefined;
|
|
80
78
|
}
|
|
81
79
|
}
|
|
@@ -8,15 +8,13 @@ const runtime_1 = require("@forge/runtime");
|
|
|
8
8
|
const cli_shared_1 = require("@forge/cli-shared");
|
|
9
9
|
const DEFAULT_INVOCATION_TIMEOUT = 25;
|
|
10
10
|
class LocalInvocationService {
|
|
11
|
-
configFile;
|
|
12
|
-
logger;
|
|
13
|
-
inspector;
|
|
14
11
|
constructor(configFile, logger, inspector) {
|
|
15
12
|
this.configFile = configFile;
|
|
16
13
|
this.logger = logger;
|
|
17
14
|
this.inspector = inspector;
|
|
18
15
|
}
|
|
19
16
|
async invoke(handler, request) {
|
|
17
|
+
var _a;
|
|
20
18
|
this.logger.info('');
|
|
21
19
|
this.logger.info((0, util_1.formatInvocation)(handler, request));
|
|
22
20
|
const sandbox = util_1.SandboxesContainer.get()[handler];
|
|
@@ -40,9 +38,9 @@ class LocalInvocationService {
|
|
|
40
38
|
variables.push({ key: 'FUNCTION_IS_SNAPSHOTTED', value: isSnapshotEnabled.toString(), secure: false });
|
|
41
39
|
}
|
|
42
40
|
const requestId = (0, util_1.getRequestId)(request, (0, uuid_1.v4)());
|
|
43
|
-
const timeout = request._meta.timeout
|
|
41
|
+
const timeout = (_a = request._meta.timeout) !== null && _a !== void 0 ? _a : DEFAULT_INVOCATION_TIMEOUT;
|
|
44
42
|
const xenInvocationRequest = (0, runtime_1.xenInvocationRequestFactory)({
|
|
45
|
-
request: {
|
|
43
|
+
request: Object.assign(Object.assign({}, request), { variables }),
|
|
46
44
|
ctx: { requestId, traceId: requestId, timeout }
|
|
47
45
|
});
|
|
48
46
|
const invocationLimits = (0, runtime_1.perInvocationLimitsTrackerFactory)(xenInvocationRequest);
|
|
@@ -60,11 +58,11 @@ class LocalInvocationService {
|
|
|
60
58
|
LocalInvocationService.printMetrics(reportMetrics, metrics, this.logger);
|
|
61
59
|
return reportMetrics ? { body, metrics, success, error } : body;
|
|
62
60
|
}
|
|
63
|
-
static INTERNAL_METRICS = ['execute.setup-request-context', 'invoke.setup-isolate'];
|
|
64
|
-
static printMetrics = (shouldReportMetrics, metrics, logger) => {
|
|
65
|
-
if (shouldReportMetrics && metrics?.length) {
|
|
66
|
-
logger.debug(`Metrics: ${JSON.stringify(metrics.filter((m) => !LocalInvocationService.INTERNAL_METRICS.includes(m.name)), null, 2)}`);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
61
|
}
|
|
70
62
|
exports.LocalInvocationService = LocalInvocationService;
|
|
63
|
+
LocalInvocationService.INTERNAL_METRICS = ['execute.setup-request-context', 'invoke.setup-isolate'];
|
|
64
|
+
LocalInvocationService.printMetrics = (shouldReportMetrics, metrics, logger) => {
|
|
65
|
+
if (shouldReportMetrics && (metrics === null || metrics === void 0 ? void 0 : metrics.length)) {
|
|
66
|
+
logger.debug(`Metrics: ${JSON.stringify(metrics.filter((m) => !LocalInvocationService.INTERNAL_METRICS.includes(m.name)), null, 2)}`);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
@@ -3,13 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RegisterTunnelServiceImpl = void 0;
|
|
4
4
|
const ONE_DAY = 1000 * 60 * 60 * 24;
|
|
5
5
|
class RegisterTunnelServiceImpl {
|
|
6
|
-
tunnelClient;
|
|
7
6
|
constructor(tunnelClient) {
|
|
8
7
|
this.tunnelClient = tunnelClient;
|
|
9
8
|
this.keepAliveActive = true;
|
|
10
9
|
}
|
|
11
|
-
keepAliveHandler;
|
|
12
|
-
keepAliveActive;
|
|
13
10
|
async registerTunnels(appId, environmentKey, tunnelDefinitions) {
|
|
14
11
|
if (!this.keepAliveActive) {
|
|
15
12
|
return;
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SandboxesContainer = void 0;
|
|
4
4
|
class SandboxesContainer {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
constructor() {
|
|
6
|
+
this.sandboxes = {};
|
|
7
|
+
}
|
|
7
8
|
static get() {
|
|
8
9
|
return this.instance.sandboxes;
|
|
9
10
|
}
|
|
@@ -12,3 +13,4 @@ class SandboxesContainer {
|
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
exports.SandboxesContainer = SandboxesContainer;
|
|
16
|
+
SandboxesContainer.instance = new SandboxesContainer();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/tunnel",
|
|
3
|
-
"version": "5.0.2
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "Tunnel functionality for Forge CLI",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"compile": "tsc -b -v"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@forge/bundler": "4.15.11
|
|
15
|
-
"@forge/cli-shared": "4.0.1
|
|
14
|
+
"@forge/bundler": "4.15.11",
|
|
15
|
+
"@forge/cli-shared": "4.0.1",
|
|
16
16
|
"@forge/csp": "3.2.1",
|
|
17
|
-
"@forge/runtime": "5.7.0
|
|
17
|
+
"@forge/runtime": "5.7.0",
|
|
18
18
|
"express": "^4.18.3",
|
|
19
19
|
"express-intercept": "^1.1.0",
|
|
20
20
|
"http-proxy-middleware": "^2.0.6",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@atlassian/xen-test-util": "^4.2.0",
|
|
30
|
-
"@forge/manifest": "7.2.0
|
|
30
|
+
"@forge/manifest": "7.2.0",
|
|
31
31
|
"@types/express": "^4.17.21",
|
|
32
32
|
"@types/jest": "^29.5.12",
|
|
33
33
|
"@types/node": "14.18.63",
|