@forge/tunnel 6.3.0-next.7 → 6.3.0-next.8

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @forge/tunnel
2
2
 
3
+ ## 6.3.0-next.8
4
+
5
+ ### Minor Changes
6
+
7
+ - 4947176: Adding self managed tunnel support
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [4947176]
12
+ - @forge/cli-shared@8.8.0-next.6
13
+ - @forge/bundler@6.1.9-next.8
14
+
3
15
  ## 6.3.0-next.7
4
16
 
5
17
  ### Patch Changes
@@ -6,6 +6,7 @@ export declare class TunnelInteractor {
6
6
  private readonly logger;
7
7
  private readonly statsigService;
8
8
  constructor(logger: Logger, statsigService: StatsigService);
9
+ private logTunnelStatus;
9
10
  handleUserExitEvent(stopFunction: () => Promise<void>, bundleMonitor: WatcherMonitor | undefined, manifestFileWatcher: FSWatcher): Promise<void>;
10
11
  watchAndWarnOnManifestChanges(manifestFilePath: string): chokidar.FSWatcher;
11
12
  watchApp: (startTunnelResult: StartTunnelResult, tunnelOptions?: TunnelOptions) => Promise<WatcherMonitor | undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"tunnel-interactor.d.ts","sourceRoot":"","sources":["../../../src/command/interactors/tunnel-interactor.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAyC,MAAM,EAAQ,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACvH,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,QAAQ,EAAE,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE/C,qBAAa,gBAAgB;IAGzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFzB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;gBAE7B,MAAM,EAAE,MAAM,EAC/B,cAAc,EAAE,cAAc;IAKzB,mBAAmB,CACxB,YAAY,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EACjC,aAAa,EAAE,cAAc,GAAG,SAAS,EACzC,mBAAmB,EAAE,SAAS,GAC7B,OAAO,CAAC,IAAI,CAAC;IAsCT,6BAA6B,CAAC,gBAAgB,EAAE,MAAM;IAUtD,QAAQ,sBACM,iBAAiB,kBACrB,aAAa,KAC3B,QAAQ,cAAc,GAAG,SAAS,CAAC,CAwDpC;CACH"}
1
+ {"version":3,"file":"tunnel-interactor.d.ts","sourceRoot":"","sources":["../../../src/command/interactors/tunnel-interactor.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAyC,MAAM,EAAQ,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACvH,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,QAAQ,EAAE,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE/C,qBAAa,gBAAgB;IAGzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFzB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;gBAE7B,MAAM,EAAE,MAAM,EAC/B,cAAc,EAAE,cAAc;IAKhC,OAAO,CAAC,eAAe;IAShB,mBAAmB,CACxB,YAAY,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EACjC,aAAa,EAAE,cAAc,GAAG,SAAS,EACzC,mBAAmB,EAAE,SAAS,GAC7B,OAAO,CAAC,IAAI,CAAC;IAsCT,6BAA6B,CAAC,gBAAgB,EAAE,MAAM;IAUtD,QAAQ,sBACM,iBAAiB,kBACrB,aAAa,KAC3B,QAAQ,cAAc,GAAG,SAAS,CAAC,CAsDpC;CACH"}
@@ -15,6 +15,13 @@ class TunnelInteractor {
15
15
  this.logger = logger;
16
16
  this.statsigService = statsigService;
17
17
  }
18
+ logTunnelStatus(localPort, tunnelOptions) {
19
+ this.logger.info('');
20
+ this.logger.info(cli_shared_1.Text.tunnel.startedServer(localPort, this.logger.debugEnabled) + '\n');
21
+ if (tunnelOptions.url) {
22
+ this.logger.warn(cli_shared_1.Text.tunnel.selfManagedTunnel(tunnelOptions.url, localPort));
23
+ }
24
+ }
18
25
  handleUserExitEvent(stopFunction, bundleMonitor, manifestFileWatcher) {
19
26
  return new Promise((resolve, reject) => {
20
27
  const rl = readline_1.default.createInterface({
@@ -74,8 +81,7 @@ class TunnelInteractor {
74
81
  if (kind === 'runtime') {
75
82
  await reloadSandboxes(output, tunnelOptions);
76
83
  }
77
- this.logger.info('');
78
- this.logger.info(cli_shared_1.Text.tunnel.startedServer(localPort, this.logger.debugEnabled) + '\n');
84
+ this.logTunnelStatus(localPort, tunnelOptions);
79
85
  };
80
86
  const multiCompiler = new multi_compiler_watcher_1.MultiCompilerWatcher(faasServer, uiServers);
81
87
  if (tunnelOptions.verify) {
@@ -88,8 +94,7 @@ class TunnelInteractor {
88
94
  onUIChange: { onBuildWillStart, onBuildFinished: onBuildFinished('ui') }
89
95
  }, tunnelOptions);
90
96
  await reloadSandboxes(output, tunnelOptions);
91
- this.logger.info('');
92
- this.logger.info(cli_shared_1.Text.tunnel.startedServer(localPort, this.logger.debugEnabled) + '\n');
97
+ this.logTunnelStatus(localPort, tunnelOptions);
93
98
  }
94
99
  catch (_) {
95
100
  }
@@ -9,6 +9,7 @@ export interface StartTunnelOptions {
9
9
  host: string;
10
10
  environmentKey: string;
11
11
  resourcePortMap: Record<string, number>;
12
+ url?: string;
12
13
  }
13
14
  export interface StartTunnelResult {
14
15
  localPort: number;
@@ -29,6 +30,8 @@ export declare class StartTunnelCommand {
29
30
  private tunnelServers;
30
31
  private cspReporterServer;
31
32
  constructor(getAppConfig: AppConfigProvider, devServer: DevelopmentServer, tunnelFactory: CreateTunnelService, tunnelClient: RegisterTunnelService, functionHost: FunctionChangeWatcher, logger: Logger, configFile: ConfigFile);
33
+ private validateTunnelUrl;
34
+ private validateTunnelPort;
32
35
  private stopServices;
33
36
  stopDockerComposeStack: (composeFiles?: Record<string, string>) => Promise<void>;
34
37
  private deleteDockerComposeFile;
@@ -1 +1 @@
1
- {"version":3,"file":"start-tunnel-command.d.ts","sourceRoot":"","sources":["../../src/command/start-tunnel-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,EAAmB,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAI1G,OAAO,EACL,iBAAiB,EAKlB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAMzE,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,UAAU,EAAE,iBAAiB,CAAC;IAC9B,SAAS,EAAE,iBAAiB,EAAE,CAAC;IAC/B,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,eAAe,CAAC,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1F;AAED,qBAAa,kBAAkB;IAK3B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAA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O,CAAC,uBAAuB,CAY7B;IAEF,OAAO,CAAC,qBAAqB,CA+B3B;IAEF,OAAO,CAAC,gCAAgC,CAiCtC;IAEW,OAAO,CAClB,OAAO,EAAE,kBAAkB,EAC3B,4BAA4B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpD,OAAO,CAAC,iBAAiB,CAAC;CA0D9B"}
@@ -2,13 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StartTunnelCommand = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const cli_shared_1 = require("@forge/cli-shared");
5
6
  const node_cache_1 = tslib_1.__importDefault(require("node-cache"));
6
7
  const portfinder_1 = require("portfinder");
7
8
  const servers_1 = require("../servers");
8
9
  const docker_compose_1 = require("docker-compose");
9
- const cli_shared_1 = require("@forge/cli-shared");
10
10
  const path = tslib_1.__importStar(require("path"));
11
11
  const fs = tslib_1.__importStar(require("fs"));
12
+ class InvalidTunnelConfigError extends cli_shared_1.UserError {
13
+ constructor(message) {
14
+ super(message);
15
+ }
16
+ }
12
17
  class StartTunnelCommand {
13
18
  getAppConfig;
14
19
  devServer;
@@ -28,6 +33,29 @@ class StartTunnelCommand {
28
33
  this.logger = logger;
29
34
  this.configFile = configFile;
30
35
  }
36
+ validateTunnelUrl(tunnelUrl) {
37
+ if (!tunnelUrl) {
38
+ return;
39
+ }
40
+ let parsedUrl;
41
+ try {
42
+ parsedUrl = new URL(tunnelUrl);
43
+ }
44
+ catch (error) {
45
+ throw new InvalidTunnelConfigError(cli_shared_1.Text.tunnel.error.invalidSelfManagedTunnelUrl(tunnelUrl));
46
+ }
47
+ if (parsedUrl.protocol !== 'https:') {
48
+ throw new InvalidTunnelConfigError(cli_shared_1.Text.tunnel.error.invalidSelfManagedTunnelUrlProtocol(parsedUrl.protocol));
49
+ }
50
+ }
51
+ validateTunnelPort(port) {
52
+ if (port === undefined) {
53
+ return;
54
+ }
55
+ if (port < 1 || port > 65535) {
56
+ throw new InvalidTunnelConfigError(cli_shared_1.Text.tunnel.error.invalidSelfManagedTunnelPort(port.toString()));
57
+ }
58
+ }
31
59
  stopServices = async (appId, environmentKey, containersDockerComposeFiles) => {
32
60
  await Promise.all([
33
61
  this.functionHost.stopWatching(),
@@ -70,16 +98,22 @@ class StartTunnelCommand {
70
98
  }
71
99
  }
72
100
  };
73
- startFaaSTunnelServer = async ({ port, appId, environmentKey }) => {
101
+ startFaaSTunnelServer = async ({ port, appId, environmentKey, tunnelUrl }) => {
74
102
  const { permissions = {}, remotes = [] } = await this.configFile.readConfig();
75
103
  const serverInfo = await this.devServer.start(port, permissions, remotes);
76
- const { id, token, url } = await this.tunnelClient.setupTunnel(appId, environmentKey);
77
- const faasTunnelUrl = await this.tunnelFactory.establishTunnel({
78
- port: serverInfo.port,
79
- id,
80
- token,
81
- tunnelUrl: url
82
- });
104
+ let faasTunnelUrl;
105
+ if (tunnelUrl) {
106
+ faasTunnelUrl = new URL(tunnelUrl);
107
+ }
108
+ else {
109
+ const { id, token, url } = await this.tunnelClient.setupTunnel(appId, environmentKey);
110
+ faasTunnelUrl = await this.tunnelFactory.establishTunnel({
111
+ port: serverInfo.port,
112
+ id,
113
+ token,
114
+ tunnelUrl: url
115
+ });
116
+ }
83
117
  return {
84
118
  ...serverInfo,
85
119
  tunnelUrl: faasTunnelUrl
@@ -111,13 +145,16 @@ class StartTunnelCommand {
111
145
  };
112
146
  async execute(options, containersDockerComposeFiles) {
113
147
  const { id: appId } = await this.getAppConfig();
114
- const { port, environmentKey } = options;
148
+ const { port, environmentKey, url } = options;
149
+ this.validateTunnelUrl(url);
150
+ this.validateTunnelPort(port);
115
151
  const allResources = await this.configFile.getResources();
116
152
  try {
117
153
  const faasTunnelServer = await this.startFaaSTunnelServer({
118
154
  port,
119
155
  appId,
120
- environmentKey
156
+ environmentKey,
157
+ tunnelUrl: url
121
158
  });
122
159
  const customUITunnelsServers = await this.startResourceBasedTunnelsServers(allResources, options);
123
160
  const tunnelDefinitions = {
@@ -129,6 +166,10 @@ class StartTunnelCommand {
129
166
  };
130
167
  await this.tunnelClient.registerTunnels(appId, environmentKey, tunnelDefinitions);
131
168
  const stopFunction = async () => this.stopServices(appId, environmentKey, containersDockerComposeFiles);
169
+ this.devServer.setErrorHandler?.(async (error) => {
170
+ await this.stopServices(appId, environmentKey, containersDockerComposeFiles);
171
+ await (0, cli_shared_1.exitOnError)(this.logger, error);
172
+ });
132
173
  const reloadSandboxes = async (bundledCode, tunnelOptions) => {
133
174
  await this.functionHost.stopWatching();
134
175
  await this.functionHost.startWatching(bundledCode, tunnelOptions);
@@ -4,16 +4,19 @@ import http from 'http';
4
4
  import { URL } from 'url';
5
5
  import express from 'express';
6
6
  import { BundlerWatch, BundlerOutput } from '@forge/bundler';
7
- import { ConfigFile, FileSystemReader, I18nResourceBundlingService, Logger, StatsigService, TunnelOptions } from '@forge/cli-shared';
7
+ import { AppEnvironmentsGraphqlClient, ConfigFile, FileSystemReader, I18nResourceBundlingService, Logger, StatsigService, TunnelOptions, UserError } from '@forge/cli-shared';
8
8
  import { ExternalRequestBody } from '@forge/runtime';
9
9
  import { Permissions, Remotes } from '@forge/manifest';
10
10
  export interface ProxyServerError extends Error {
11
11
  code?: string;
12
12
  }
13
+ export declare class TunnelInvocationValidationError extends UserError {
14
+ }
13
15
  export interface DevelopmentServer {
14
16
  start(port?: number, permissions?: Permissions, remotes?: Remotes): Promise<StartDevServerResult>;
15
17
  stop(): Promise<void>;
16
18
  compileAndWatch(hooks: BundlerWatch, tunnelOptions?: TunnelOptions): Promise<BundlerOutput>;
19
+ setErrorHandler?: (handler: (err: Error) => Promise<void>) => void;
17
20
  }
18
21
  export interface StartDevServerResult {
19
22
  port: number;
@@ -32,14 +35,22 @@ export declare class LocalDevelopmentServer implements DevelopmentServer {
32
35
  private readonly fileSystemReader;
33
36
  private readonly statsigService;
34
37
  private readonly i18nResourceBundlingService;
38
+ private readonly appEnvironmentClient;
35
39
  private app;
36
40
  private httpServer;
37
- constructor(invocationService: InvocationService, logger: Logger, configFile: ConfigFile, fileSystemReader: FileSystemReader, statsigService: StatsigService, i18nResourceBundlingService: I18nResourceBundlingService);
41
+ private tunnelOptions;
42
+ private environmentId;
43
+ private appId;
44
+ onFatalError?: (err: Error) => Promise<void>;
45
+ constructor(invocationService: InvocationService, logger: Logger, configFile: ConfigFile, fileSystemReader: FileSystemReader, statsigService: StatsigService, i18nResourceBundlingService: I18nResourceBundlingService, appEnvironmentClient: AppEnvironmentsGraphqlClient);
38
46
  start(port?: number, _permissions?: Permissions, _remotes?: Remotes): Promise<StartDevServerResult>;
39
47
  stop(): Promise<void>;
40
48
  compileAndWatch(watch: BundlerWatch, tunnelOptions?: TunnelOptions): Promise<BundlerOutput>;
41
49
  getApp(): express.Application;
50
+ setErrorHandler(handler: (err: Error) => Promise<void>): void;
42
51
  handleInvocation: express.Handler;
43
52
  configureProxyMiddleware: express.Handler;
53
+ validateApp(request: ExternalRequestBody): Promise<void>;
54
+ private setEnvironmentAndAppId;
44
55
  }
45
56
  //# sourceMappingURL=dev-server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../../src/servers/dev-server.ts"],"names":[],"mappings":";;AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAKL,YAAY,EACZ,aAAa,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,UAAU,EAEV,gBAAgB,EAChB,2BAA2B,EAC3B,MAAM,EACN,cAAc,EAEd,aAAa,EAEd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAe,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAKvD,MAAM,WAAW,gBAAiB,SAAQ,KAAK;IAC7C,IAAI,CAAC,E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M,EAAE,MAAM,EACd,UAAU,EAAE,UAAU,EACtB,gBAAgB,EAAE,gBAAgB,EAClC,cAAc,EAAE,cAAc,EAC9B,2BAA2B,EAAE,2BAA2B,EACxD,oBAAoB,EAAE,4BAA4B;IAexD,KAAK,CAAC,IAAI,SAAI,EAAE,YAAY,CAAC,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAY9F,IAAI;IAIJ,eAAe,CAC1B,KAAK,EAAE,YAAY,EACnB,aAAa,GAAE,aAA2C,GACzD,OAAO,CAAC,aAAa,CAAC;IAgClB,MAAM,IAAI,OAAO,CAAC,WAAW;IAO7B,eAAe,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAI7D,gBAAgB,EAAE,OAAO,CAAC,OAAO,CA6BtC;IAEK,wBAAwB,EAAE,OAAO,CAAC,OAAO,CAkC9C;IASW,WAAW,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;YAqBvD,sBAAsB;CAUrC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LocalDevelopmentServer = exports.stopServer = void 0;
3
+ exports.LocalDevelopmentServer = exports.stopServer = exports.TunnelInvocationValidationError = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const express_1 = tslib_1.__importDefault(require("express"));
6
6
  const bundler_1 = require("@forge/bundler");
@@ -8,6 +8,10 @@ const cli_shared_1 = require("@forge/cli-shared");
8
8
  const runtime_1 = require("@forge/runtime");
9
9
  const util_1 = require("../util");
10
10
  const http_proxy_middleware_1 = require("http-proxy-middleware");
11
+ const ari_1 = require("@forge/util/packages/ari");
12
+ class TunnelInvocationValidationError extends cli_shared_1.UserError {
13
+ }
14
+ exports.TunnelInvocationValidationError = TunnelInvocationValidationError;
11
15
  async function stopServer(server) {
12
16
  if (!server) {
13
17
  return;
@@ -24,15 +28,21 @@ class LocalDevelopmentServer {
24
28
  fileSystemReader;
25
29
  statsigService;
26
30
  i18nResourceBundlingService;
31
+ appEnvironmentClient;
27
32
  app;
28
33
  httpServer;
29
- constructor(invocationService, logger, configFile, fileSystemReader, statsigService, i18nResourceBundlingService) {
34
+ tunnelOptions;
35
+ environmentId;
36
+ appId;
37
+ onFatalError;
38
+ constructor(invocationService, logger, configFile, fileSystemReader, statsigService, i18nResourceBundlingService, appEnvironmentClient) {
30
39
  this.invocationService = invocationService;
31
40
  this.logger = logger;
32
41
  this.configFile = configFile;
33
42
  this.fileSystemReader = fileSystemReader;
34
43
  this.statsigService = statsigService;
35
44
  this.i18nResourceBundlingService = i18nResourceBundlingService;
45
+ this.appEnvironmentClient = appEnvironmentClient;
36
46
  this.app = (0, express_1.default)();
37
47
  this.app.disable('x-powered-by');
38
48
  this.app.disable('etag');
@@ -53,7 +63,8 @@ class LocalDevelopmentServer {
53
63
  await stopServer(this.httpServer);
54
64
  }
55
65
  async compileAndWatch(watch, tunnelOptions = cli_shared_1.defaultNoDebugTunnelOptions) {
56
- const watchMode = tunnelOptions.debug ? 'debug' : 'watch';
66
+ this.tunnelOptions = tunnelOptions;
67
+ const watchMode = this.tunnelOptions.debug ? 'debug' : 'watch';
57
68
  const handlers = await this.configFile.getAppHandlers();
58
69
  const entryPoints = (0, bundler_1.getEntryPoints)(handlers);
59
70
  if (!entryPoints.length) {
@@ -74,6 +85,9 @@ class LocalDevelopmentServer {
74
85
  getApp() {
75
86
  return this.app;
76
87
  }
88
+ setErrorHandler(handler) {
89
+ this.onFatalError = handler;
90
+ }
77
91
  handleInvocation = async (req, res) => {
78
92
  const request = req.body;
79
93
  const envVars = (0, runtime_1.getUserVars)();
@@ -82,6 +96,7 @@ class LocalDevelopmentServer {
82
96
  envVars.push(item);
83
97
  }
84
98
  });
99
+ await this.validateApp(request);
85
100
  request.variables = [...envVars].sort((a, b) => a.key.localeCompare(b.key));
86
101
  try {
87
102
  const invokeResults = await this.invocationService.invoke(request.handler, request);
@@ -130,5 +145,33 @@ class LocalDevelopmentServer {
130
145
  }
131
146
  })(req, res, next);
132
147
  };
148
+ async validateApp(request) {
149
+ try {
150
+ if (!(await this.statsigService.isSelfManagedTunnelEnabled())) {
151
+ return;
152
+ }
153
+ await this.setEnvironmentAndAppId();
154
+ const requestAppId = request?._meta?.appContext?.appId;
155
+ if (requestAppId && requestAppId !== this.appId) {
156
+ throw new TunnelInvocationValidationError(cli_shared_1.Text.tunnel.error.invalidInvokeRequestForAppId(requestAppId));
157
+ }
158
+ const requestEnvId = request?._meta?.appContext?.environmentId;
159
+ if (requestEnvId && requestEnvId !== this.environmentId) {
160
+ throw new TunnelInvocationValidationError(cli_shared_1.Text.tunnel.error.invalidInvokeRequestForAppEnv(requestEnvId));
161
+ }
162
+ }
163
+ catch (error) {
164
+ await this.onFatalError?.(error);
165
+ }
166
+ }
167
+ async setEnvironmentAndAppId() {
168
+ if (this.environmentId && this.appId) {
169
+ return;
170
+ }
171
+ const config = await this.configFile.readConfig();
172
+ this.appId = ari_1.EcosystemAppAri.parse(config.app.id).appId;
173
+ const environmentKey = this.tunnelOptions?.environment || 'default';
174
+ this.environmentId = await this.appEnvironmentClient.getAppEnvironmentId(config.app.id, environmentKey);
175
+ }
133
176
  }
134
177
  exports.LocalDevelopmentServer = LocalDevelopmentServer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/tunnel",
3
- "version": "6.3.0-next.7",
3
+ "version": "6.3.0-next.8",
4
4
  "description": "Tunnel functionality for Forge CLI",
5
5
  "author": "Atlassian",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
@@ -11,10 +11,11 @@
11
11
  "compile": "tsc -b -v"
12
12
  },
13
13
  "dependencies": {
14
- "@forge/bundler": "6.1.9-next.7",
15
- "@forge/cli-shared": "8.8.0-next.5",
14
+ "@forge/bundler": "6.1.9-next.8",
15
+ "@forge/cli-shared": "8.8.0-next.6",
16
16
  "@forge/csp": "5.1.1-next.0",
17
17
  "@forge/runtime": "6.1.0-next.0",
18
+ "@forge/util": "^2.0.0",
18
19
  "cheerio": "^1.1.0",
19
20
  "chokidar": "^3.6.0",
20
21
  "cloudflared": "^0.7.0",
@@ -32,7 +33,7 @@
32
33
  },
33
34
  "devDependencies": {
34
35
  "@atlassian/xen-test-util": "^4.2.0",
35
- "@forge/manifest": "10.7.0-next.3",
36
+ "@forge/manifest": "10.7.0-next.4",
36
37
  "@types/express": "^4.17.21",
37
38
  "@types/jest": "^29.5.14",
38
39
  "@types/node": "20.19.1",