@forge/runtime 5.6.1-next.0 → 5.6.1

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,20 @@
1
1
  # @forge/runtime
2
2
 
3
+ ## 5.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - eb06eca: Break more dependencies between SDK and runtime
8
+ - f8a4714: Use InMemoryMetrics from the Node monorepo
9
+ - Updated dependencies [f8a4714]
10
+ - @forge/util@1.4.3
11
+
12
+ ## 5.6.1-next.1
13
+
14
+ ### Patch Changes
15
+
16
+ - eb06eca: Break more dependencies between SDK and runtime
17
+
3
18
  ## 5.6.1-next.0
4
19
 
5
20
  ### Patch Changes
@@ -45,6 +45,14 @@ const AppManifestRequiredFields = t.type({
45
45
  });
46
46
  const AppManifestType = t.intersection([AppManifestRequiredFields, AppManifestOptionalFields]);
47
47
  class AppManifest {
48
+ static FILE_NAME = 'manifest.yml';
49
+ static async fromFile(filePath) {
50
+ const fullPath = path_1.default.join(filePath, AppManifest.FILE_NAME);
51
+ const manifestContents = (0, fs_1.readFileSync)(fullPath, 'utf-8');
52
+ const manifest = yaml_1.default.parse(manifestContents);
53
+ return new AppManifest(manifest);
54
+ }
55
+ manifest;
48
56
  constructor(manifest) {
49
57
  if (!AppManifestType.is(manifest)) {
50
58
  throw new Error('invalid manifest');
@@ -53,32 +61,23 @@ class AppManifest {
53
61
  this.manifest = manifest;
54
62
  }
55
63
  }
56
- static async fromFile(filePath) {
57
- const fullPath = path_1.default.join(filePath, AppManifest.FILE_NAME);
58
- const manifestContents = (0, fs_1.readFileSync)(fullPath, 'utf-8');
59
- const manifest = yaml_1.default.parse(manifestContents);
60
- return new AppManifest(manifest);
61
- }
62
64
  getHostForRemote(remote) {
63
- var _a;
64
- const found = (_a = this.manifest.remotes) === null || _a === void 0 ? void 0 : _a.find(({ key }) => key === remote);
65
- return found === null || found === void 0 ? void 0 : found.baseUrl;
65
+ const found = this.manifest.remotes?.find(({ key }) => key === remote);
66
+ return found?.baseUrl;
66
67
  }
67
68
  getDefaultRemoteForProvider(provider) {
68
69
  const providerConfig = this.getExternalAuthProviderConfig(provider);
69
- const remotes = providerConfig === null || providerConfig === void 0 ? void 0 : providerConfig.remotes;
70
+ const remotes = providerConfig?.remotes;
70
71
  if (remotes && remotes.length > 0) {
71
72
  return remotes[0];
72
73
  }
73
74
  return undefined;
74
75
  }
75
76
  getExternalAuthProviderConfig(provider) {
76
- var _a;
77
- return (_a = this.manifest.providers) === null || _a === void 0 ? void 0 : _a.auth.find((v) => v.key === provider);
77
+ return this.manifest.providers?.auth.find((v) => v.key === provider);
78
78
  }
79
79
  getEgressAllowlist() {
80
80
  return this.manifest.egress || [];
81
81
  }
82
82
  }
83
83
  exports.AppManifest = AppManifest;
84
- AppManifest.FILE_NAME = 'manifest.yml';
package/out/context.js CHANGED
@@ -31,18 +31,21 @@ function createPrincipal(cfg) {
31
31
  }
32
32
  exports.createPrincipal = createPrincipal;
33
33
  function createLicenseContext(cfg) {
34
- var _a;
35
34
  const { license } = cfg.meta;
36
35
  if (license) {
37
36
  return {
38
37
  license: {
39
- isActive: (_a = license.isActive) !== null && _a !== void 0 ? _a : false
38
+ isActive: license.isActive ?? false
40
39
  }
41
40
  };
42
41
  }
43
42
  }
44
43
  exports.createLicenseContext = createLicenseContext;
45
44
  function setupRequestContext(cfg) {
46
- return Object.assign(Object.assign({ principal: createPrincipal(cfg) }, createLicenseContext(cfg)), createInstallationContext(cfg));
45
+ return {
46
+ principal: createPrincipal(cfg),
47
+ ...createLicenseContext(cfg),
48
+ ...createInstallationContext(cfg)
49
+ };
47
50
  }
48
51
  exports.setupRequestContext = setupRequestContext;
@@ -10,12 +10,13 @@ exports.XEN_RUNTIME_ENABLE_NETWORK_LIMITS = 'xen-runtime-enable-network-limits';
10
10
  exports.XEN_RUNTIME_SHOULD_BLOCK_EXTERNAL_FETCH = 'xen-runtime-should-block-external-fetch';
11
11
  exports.XEN_RUNTIME_SHOULD_REPORT_METRICS = 'xen-runtime-should-report-metrics';
12
12
  class FeatureFlags {
13
- constructor(flags) {
14
- this.flags = flags;
15
- }
13
+ flags;
16
14
  static fromRequestMetaData(metaData) {
17
15
  return new FeatureFlags(metaData.featureFlags || []);
18
16
  }
17
+ constructor(flags) {
18
+ this.flags = flags;
19
+ }
19
20
  isFeatureFlagEnabled(flag) {
20
21
  return this.flags.includes(flag);
21
22
  }
@@ -6,9 +6,9 @@ exports.Limit = {
6
6
  FetchRequestLimit: 'forge-fetch-request-count'
7
7
  };
8
8
  class PerInvocationLimitsTracker {
9
+ limits = {};
10
+ limitCount = {};
9
11
  constructor(limits) {
10
- this.limits = {};
11
- this.limitCount = {};
12
12
  this.limits = limits || {};
13
13
  }
14
14
  incrementCount(limitKey, by = 1) {
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/metrics/metrics.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAa,MAAM,wCAAwC,CAAC;AAElF,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAGtE,oBAAY,UAAU;IACpB,WAAW,UAAU;IACrB,aAAa,YAAY;IACzB,WAAW,UAAU;CACtB;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,IAAI,EAAE,IAAI,CAAC;CACZ;AAKD,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,OAAO;IAEvC,OAAO,IAAI,OAAO;IAIlB,cAAc,IAAI,MAAM,EAAE;IAIjC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,GAAE,MAAM,GAAG,SAAqB,GAAG,MAAM,EAAE;IAuCrE,aAAa,CAAC,GAAG,EAAE,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EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CASjD,CAAC"}
@@ -10,7 +10,11 @@ var MetricType;
10
10
  MetricType["CounterMetric"] = "counter";
11
11
  MetricType["GaugeMetric"] = "gauge";
12
12
  })(MetricType = exports.MetricType || (exports.MetricType = {}));
13
+ function isInMemoryMetrics(metrics) {
14
+ return metrics.constructor.name === in_memory_metrics_1.InMemoryMetrics.name;
15
+ }
13
16
  class MetricsCollector {
17
+ _metrics;
14
18
  constructor(_metrics) {
15
19
  this._metrics = _metrics;
16
20
  }
@@ -21,7 +25,7 @@ class MetricsCollector {
21
25
  return MetricsCollector.collect(this._metrics);
22
26
  }
23
27
  static collect(metrics, prefix = undefined) {
24
- if (!(metrics instanceof in_memory_metrics_1.InMemoryMetrics)) {
28
+ if (!isInMemoryMetrics(metrics)) {
25
29
  return [];
26
30
  }
27
31
  const addPrefix = (p, value) => {
@@ -62,37 +62,24 @@ function processArgForLogConsole(arg) {
62
62
  }
63
63
  const className = type === 'object' ? arg.constructor.name : undefined;
64
64
  const subtype = inspectorSubtypeEntries.find((a) => a[1](arg));
65
- return Object.assign(Object.assign(Object.assign({ type }, (className ? { className } : undefined)), (subtype ? { subtype: subtype[0] } : undefined)), { value: arg, description: (0, util_1.inspect)(arg) });
65
+ return {
66
+ type,
67
+ ...(className ? { className } : undefined),
68
+ ...(subtype ? { subtype: subtype[0] } : undefined),
69
+ value: arg,
70
+ description: (0, util_1.inspect)(arg)
71
+ };
66
72
  }
67
73
  class ChromeInspector {
68
- constructor() {
69
- this.frontendMsgsForNewSandbox = [];
70
- this.sendMessageToFrontend = (message) => {
71
- const wss = this.wss;
72
- if (!wss) {
73
- return;
74
- }
75
- if (VERBOSE_LOG) {
76
- log('Message to frontend:\n' + message);
77
- }
78
- wss.clients.forEach((ws) => ws.send(message));
79
- };
80
- this.stopSession = () => {
81
- const wss = this.wss;
82
- if (!wss) {
83
- return;
84
- }
85
- if (CLOSE_CONNECTION_ON_SESSION_STOP) {
86
- wss.clients.forEach((ws) => ws.close());
87
- }
88
- const callbacks = this.callbacks;
89
- if (!callbacks) {
90
- return;
91
- }
92
- this.callbacks = undefined;
93
- callbacks.onSessionStop();
94
- };
95
- }
74
+ static DENY_CODE = 1011;
75
+ static DENY_REASON = 'Only one frontend is allowed';
76
+ static FORCE_RESET_FRONTEND_STATE_EVENTS = [
77
+ '{"method":"Runtime.executionContextsCleared"}',
78
+ '{"method":"Inspector.targetReloadedAfterCrash"}'
79
+ ];
80
+ wss;
81
+ callbacks;
82
+ frontendMsgsForNewSandbox = [];
96
83
  startServer(port = 0) {
97
84
  const wss = new ws_1.default.Server({ port });
98
85
  wss.on('connection', (ws) => {
@@ -203,6 +190,31 @@ class ChromeInspector {
203
190
  throw Error('Unable to find port for inspector server');
204
191
  }
205
192
  }
193
+ sendMessageToFrontend = (message) => {
194
+ const wss = this.wss;
195
+ if (!wss) {
196
+ return;
197
+ }
198
+ if (VERBOSE_LOG) {
199
+ log('Message to frontend:\n' + message);
200
+ }
201
+ wss.clients.forEach((ws) => ws.send(message));
202
+ };
203
+ stopSession = () => {
204
+ const wss = this.wss;
205
+ if (!wss) {
206
+ return;
207
+ }
208
+ if (CLOSE_CONNECTION_ON_SESSION_STOP) {
209
+ wss.clients.forEach((ws) => ws.close());
210
+ }
211
+ const callbacks = this.callbacks;
212
+ if (!callbacks) {
213
+ return;
214
+ }
215
+ this.callbacks = undefined;
216
+ callbacks.onSessionStop();
217
+ };
206
218
  forceResetFrontendState() {
207
219
  for (const evt of ChromeInspector.FORCE_RESET_FRONTEND_STATE_EVENTS) {
208
220
  this.sendMessageToFrontend(evt);
@@ -231,12 +243,6 @@ class ChromeInspector {
231
243
  }
232
244
  }
233
245
  exports.ChromeInspector = ChromeInspector;
234
- ChromeInspector.DENY_CODE = 1011;
235
- ChromeInspector.DENY_REASON = 'Only one frontend is allowed';
236
- ChromeInspector.FORCE_RESET_FRONTEND_STATE_EVENTS = [
237
- '{"method":"Runtime.executionContextsCleared"}',
238
- '{"method":"Inspector.targetReloadedAfterCrash"}'
239
- ];
240
246
  exports.notImplementedInspector = {
241
247
  startServer: () => {
242
248
  throw new Error('Not implemented');
@@ -6,10 +6,13 @@ const feature_flag_1 = require("../feature-flag");
6
6
  const ari_1 = require("@forge/util/packages/ari");
7
7
  const __1 = require("..");
8
8
  class XenInvocationRequestImpl {
9
+ request;
10
+ invocationId;
11
+ featureFlags;
12
+ serviceTokens = [];
9
13
  constructor(request, invocationId) {
10
14
  this.request = request;
11
15
  this.invocationId = invocationId;
12
- this.serviceTokens = [];
13
16
  this.serviceTokens = this.buildServiceTokens(request._meta.tokens);
14
17
  }
15
18
  buildServiceTokens(tokens) {
@@ -77,11 +80,10 @@ class XenInvocationRequestImpl {
77
80
  return this.request._meta.appToken;
78
81
  }
79
82
  getProxy() {
80
- var _a;
81
83
  if (!this.isFeatureFlagEnabled(feature_flag_1.XEN_RUNTIME_ENABLE_EGRESS_PROXY)) {
82
84
  return undefined;
83
85
  }
84
- return (_a = this.request._meta) === null || _a === void 0 ? void 0 : _a.proxy;
86
+ return this.request._meta?.proxy;
85
87
  }
86
88
  getAllTokens() {
87
89
  return this.serviceTokens;
@@ -115,12 +117,9 @@ function xenInvocationRequestFactory(invocation) {
115
117
  }
116
118
  exports.xenInvocationRequestFactory = xenInvocationRequestFactory;
117
119
  class InvocationRequest {
118
- constructor(sandboxConfig, xenInvocationRequest, manifest) {
119
- this.sandboxConfig = sandboxConfig;
120
- this.xenInvocationRequest = xenInvocationRequest;
121
- this.manifest = manifest;
122
- this.thirdPartyAuthTokenReferences = this.getThirdPartyTokenReferences();
123
- }
120
+ sandboxConfig;
121
+ xenInvocationRequest;
122
+ manifest;
124
123
  static async setup(sandboxConfig, xenInvocationRequest) {
125
124
  const manifest = await app_manifest_1.AppManifest.fromFile(sandboxConfig.appPath);
126
125
  return this.setupSync(sandboxConfig, xenInvocationRequest, manifest);
@@ -128,6 +127,13 @@ class InvocationRequest {
128
127
  static setupSync(sandboxConfig, xenInvocationRequest, manifest) {
129
128
  return new InvocationRequest(sandboxConfig, xenInvocationRequest, manifest);
130
129
  }
130
+ thirdPartyAuthTokenReferences;
131
+ constructor(sandboxConfig, xenInvocationRequest, manifest) {
132
+ this.sandboxConfig = sandboxConfig;
133
+ this.xenInvocationRequest = xenInvocationRequest;
134
+ this.manifest = manifest;
135
+ this.thirdPartyAuthTokenReferences = this.getThirdPartyTokenReferences();
136
+ }
131
137
  getAppAri() {
132
138
  return this.manifest.manifest.app.id;
133
139
  }
@@ -225,16 +231,16 @@ class InvocationRequest {
225
231
  return serviceTokens ? serviceTokens[0] : undefined;
226
232
  }
227
233
  getAtlassianServiceToken() {
228
- var _a;
229
234
  const atlassianTokens = this.getAllTokens(this.getAtlassianTokenServiceKey());
230
- return (_a = this.pickTokenToUse(atlassianTokens)) === null || _a === void 0 ? void 0 : _a.token;
235
+ return this.pickTokenToUse(atlassianTokens)?.token;
231
236
  }
232
237
  getAppTokenKey() {
233
238
  return '__atlassian-app-token';
234
239
  }
235
240
  getThirdPartyTokenReferenceList(serviceKey) {
236
- var _a;
237
- return (((_a = this.thirdPartyAuthTokenReferences) === null || _a === void 0 ? void 0 : _a.filter((ref) => ref.serviceKey === serviceKey).map((service) => service.reference)) || []);
241
+ return (this.thirdPartyAuthTokenReferences
242
+ ?.filter((ref) => ref.serviceKey === serviceKey)
243
+ .map((service) => service.reference) || []);
238
244
  }
239
245
  getThirdPartyTokenReferences() {
240
246
  return this.getThirdPartyTokens().map(({ service, token }, index) => {
@@ -250,8 +256,7 @@ class InvocationRequest {
250
256
  return this.getAllTokens().filter(({ service }) => service !== this.getAtlassianTokenServiceKey());
251
257
  }
252
258
  getThirdPartyToken(serviceKey) {
253
- var _a, _b;
254
- return (_b = (_a = this.thirdPartyAuthTokenReferences) === null || _a === void 0 ? void 0 : _a.find((ref) => ref.reference === serviceKey || ref.serviceKey === serviceKey)) === null || _b === void 0 ? void 0 : _b.token;
259
+ return this.thirdPartyAuthTokenReferences?.find((ref) => ref.reference === serviceKey || ref.serviceKey === serviceKey)?.token;
255
260
  }
256
261
  getAppVersion() {
257
262
  return this.xenInvocationRequest.getAppVersion();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/runtime",
3
- "version": "5.6.1-next.0",
3
+ "version": "5.6.1",
4
4
  "description": "A Node.js runtime for Atlassian app functions",
5
5
  "author": "Atlassian",
6
6
  "license": "UNLICENSED",
@@ -26,7 +26,7 @@
26
26
  "typescript": "4.8.4"
27
27
  },
28
28
  "dependencies": {
29
- "@forge/util": "1.4.3-next.0",
29
+ "@forge/util": "1.4.3",
30
30
  "fp-ts": "^2.16.2",
31
31
  "io-ts": "^2.2.21",
32
32
  "io-ts-reporters": "^2.0.1",