@forge/api 2.12.0-next.1-experimental-58938ba → 2.12.0-next.2-experimental-2a9dda4

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,6 +1,6 @@
1
1
  # @forge/api
2
2
 
3
- ## 2.12.0-next.1-experimental-58938ba
3
+ ## 2.12.0-next.2-experimental-2a9dda4
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -10,8 +10,15 @@
10
10
 
11
11
  - 82ea466c: Add metrics for NodeJS runtime
12
12
  - eb084dba: Added capabilities for enabling Custom entities
13
+ - 659107b4: Implement getting webtrigger URL in Node runtime
13
14
  - Updated dependencies [eb084dba]
14
- - @forge/storage@1.3.2-experimental-58938ba
15
+ - @forge/storage@1.3.2-experimental-2a9dda4
16
+
17
+ ## 2.12.0-next.2
18
+
19
+ ### Patch Changes
20
+
21
+ - 659107b: Implement getting webtrigger URL in Node runtime
15
22
 
16
23
  ## 2.12.0-next.1
17
24
 
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/api/fetch.ts"],"names":[],"mappings":";AAAA,OAAc,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAW,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAS9B,aAAK,aAAa,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,GAAG,EAAE,OAAO,EAAE,WAAW,GAAG,SAAS,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AACrG,aAAK,gBAAgB,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAChD,aAAK,cAAc,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,GAAG,WAAW,CAAC;AAuBvE,eAAO,MAAM,gBAAgB,aAAc,gBAAgB,UAAU,cAAc,KAAG,aAsCrF,CAAC;AAuBF,wBAAgB,iBAAiB,IAAI,QAAQ,CAoB5C;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,QAAQ,CAEvD"}
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/api/fetch.ts"],"names":[],"mappings":";AAAA,OAAc,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAW,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAS9B,aAAK,aAAa,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,GAAG,EAAE,OAAO,EAAE,WAAW,GAAG,SAAS,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AACrG,aAAK,gBAAgB,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAChD,aAAK,cAAc,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,GAAG,WAAW,CAAC;AAuBvE,eAAO,MAAM,gBAAgB,aAAc,gBAAgB,UAAU,cAAc,KAAG,aAkCnF,CAAC;AAuBJ,wBAAgB,iBAAiB,IAAI,QAAQ,CAoB5C;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,QAAQ,CAEvD"}
package/out/api/fetch.js CHANGED
@@ -27,37 +27,27 @@ const metricName = (provider, remote) => {
27
27
  }
28
28
  return `api.${providerToMetric[provider]}.${remoteToMetric[remote]}`;
29
29
  };
30
- const createProxyFetch = (provider, remote) => {
31
- return async (url, options) => {
32
- const { proxy, metrics } = (0, runtime_1.getRuntime)();
33
- const request = new node_fetch_1.Request(url, options);
34
- const metric = metricName(provider, remote);
35
- const timer = metrics.timing(metric, { proxy: 'true' }).measure();
36
- metrics.counter(metric).incr();
37
- try {
38
- const proxyRequest = new node_fetch_1.Request(`${proxy.url}/fpp/provider/${provider}/remote/${remote}`, request);
39
- proxyRequest.headers.set('Forge-Proxy-Target-Relative', request.url);
40
- proxyRequest.headers.set('Forge-Proxy-Authorization', `Bearer ${proxy.token}`);
41
- const requestStart = perf_hooks_1.performance.now();
42
- const response = await (0, node_fetch_1.default)(proxyRequest);
43
- const requestEnd = perf_hooks_1.performance.now();
44
- const proxyUpstreamLatency = parseInt(response.headers.get(FORGE_PROXY_UPSTREAM_LATENCY_HEADER) || '');
45
- if (proxyUpstreamLatency) {
46
- metrics.timing('proxy-success-overhead').set(requestEnd - requestStart - proxyUpstreamLatency);
47
- }
48
- if (response.headers.has('forge-proxy-error')) {
49
- if (response.headers.get('forge-proxy-error') === 'NEEDS_AUTHENTICATION_ERR') {
50
- throw new errors_1.NeedsAuthenticationError('Authentication Required', ATLASSIAN_TOKEN_SERVICE_KEY);
51
- }
52
- throw new errors_1.ProxyRequestError(response.status, response.headers.get('forge-proxy-error'));
53
- }
54
- return response;
55
- }
56
- finally {
57
- timer.stop();
30
+ const createProxyFetch = (provider, remote) => (0, runtime_1.wrapInMetrics)(metricName(provider, remote), async (url, options) => {
31
+ const { proxy, metrics } = (0, runtime_1.getRuntime)();
32
+ const request = new node_fetch_1.Request(url, options);
33
+ const proxyRequest = new node_fetch_1.Request(`${proxy.url}/fpp/provider/${provider}/remote/${remote}`, request);
34
+ proxyRequest.headers.set('Forge-Proxy-Target-Relative', request.url);
35
+ proxyRequest.headers.set('Forge-Proxy-Authorization', `Bearer ${proxy.token}`);
36
+ const requestStart = perf_hooks_1.performance.now();
37
+ const response = await (0, node_fetch_1.default)(proxyRequest);
38
+ const requestEnd = perf_hooks_1.performance.now();
39
+ const proxyUpstreamLatency = parseInt(response.headers.get(FORGE_PROXY_UPSTREAM_LATENCY_HEADER) || '');
40
+ if (proxyUpstreamLatency) {
41
+ metrics.timing('proxy-success-overhead').set(requestEnd - requestStart - proxyUpstreamLatency);
42
+ }
43
+ if (response.headers.has('forge-proxy-error')) {
44
+ if (response.headers.get('forge-proxy-error') === 'NEEDS_AUTHENTICATION_ERR') {
45
+ throw new errors_1.NeedsAuthenticationError('Authentication Required', ATLASSIAN_TOKEN_SERVICE_KEY);
58
46
  }
59
- };
60
- };
47
+ throw new errors_1.ProxyRequestError(response.status, response.headers.get('forge-proxy-error'));
48
+ }
49
+ return response;
50
+ }, { tags: { proxy: 'true' } });
61
51
  exports.createProxyFetch = createProxyFetch;
62
52
  const throwNotImplementedError = () => {
63
53
  throw new Error('not implemented');
@@ -1,10 +1,18 @@
1
- import type { Metrics } from '@forge/util/packages/metrics-interface';
1
+ import type { Metrics, Tags } from '@forge/util/packages/metrics-interface';
2
2
  export declare type ForgeRuntime = {
3
3
  proxy: {
4
4
  token: string;
5
5
  url: string;
6
6
  };
7
7
  contextAri: string;
8
+ appContext: {
9
+ appId: string;
10
+ environmentId: string;
11
+ appVersion: string;
12
+ functionKey: string;
13
+ moduleType: string;
14
+ moduleKey: string;
15
+ };
8
16
  allowedEgress: string[];
9
17
  lambdaContext: {
10
18
  awsRequestId: string;
@@ -12,4 +20,7 @@ export declare type ForgeRuntime = {
12
20
  metrics: Metrics;
13
21
  };
14
22
  export declare function getRuntime(): ForgeRuntime;
23
+ export declare function wrapInMetrics<Args extends unknown[], Ret>(name: string, fn: (...args: Args) => Promise<Ret>, { tags }?: {
24
+ tags?: Tags;
25
+ }): (...args: Args) => Promise<Ret>;
15
26
  //# sourceMappingURL=runtime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/api/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AAOtE,oBAAY,YAAY,GAAG;IACzB,KAAK,EAAE;QACL,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,EAAE;QACb,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,wBAAgB,UAAU,IAAI,YAAY,CAOzC"}
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/api/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,wCAAwC,CAAC;AAO5E,oBAAY,YAAY,GAAG;IACzB,KAAK,EAAE;QACL,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE;QACV,KAAK,EAAE,MAAM,CAAC;QACd,aAAa,EAAE,MAAM,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,EAAE;QACb,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,wBAAgB,UAAU,IAAI,YAAY,CAOzC;AAED,wBAAgB,aAAa,CAAC,IAAI,SAAS,OAAO,EAAE,EAAE,GAAG,EACvD,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,GAAG,CAAC,EACnC,EAAE,IAAI,EAAE,GAAE;IAAE,IAAI,CAAC,EAAE,IAAI,CAAA;CAAO,GAC7B,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,GAAG,CAAC,CAWjC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRuntime = void 0;
3
+ exports.wrapInMetrics = exports.getRuntime = void 0;
4
4
  function getRuntime() {
5
5
  const runtime = global.__forge_runtime__;
6
6
  if (!runtime) {
@@ -9,3 +9,17 @@ function getRuntime() {
9
9
  return runtime;
10
10
  }
11
11
  exports.getRuntime = getRuntime;
12
+ function wrapInMetrics(name, fn, { tags } = {}) {
13
+ return async (...args) => {
14
+ const { metrics } = getRuntime();
15
+ metrics.counter(name, tags).incr();
16
+ const timer = metrics.timing(name, tags).measure();
17
+ try {
18
+ return await fn(...args);
19
+ }
20
+ finally {
21
+ timer.stop();
22
+ }
23
+ };
24
+ }
25
+ exports.wrapInMetrics = wrapInMetrics;
@@ -1,4 +1,5 @@
1
- export declare const createRequestStargateAsApp: () => any;
1
+ import { createProxyFetch } from '../api/fetch';
2
+ export declare const createRequestStargateAsApp: () => ReturnType<typeof createProxyFetch>;
2
3
  export declare const getContextAri: () => any;
3
4
  export declare const getFetchAPI: () => import("..").FetchAPI;
4
5
  //# sourceMappingURL=fetch-and-storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-and-storage.d.ts","sourceRoot":"","sources":["../../src/runtime/fetch-and-storage.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,0BAA0B,WACiD,CAAC;AAEzF,eAAO,MAAM,aAAa,WAQzB,CAAC;AAEF,eAAO,MAAM,WAAW,6BAOvB,CAAC"}
1
+ {"version":3,"file":"fetch-and-storage.d.ts","sourceRoot":"","sources":["../../src/runtime/fetch-and-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA2C,MAAM,cAAc,CAAC;AAGzF,eAAO,MAAM,0BAA0B,EAAE,MAAM,UAAU,CAAC,OAAO,gBAAgB,CACO,CAAC;AAEzF,eAAO,MAAM,aAAa,WAQzB,CAAC;AAEF,eAAO,MAAM,WAAW,6BAOvB,CAAC"}
@@ -3,4 +3,4 @@ interface WebTriggerAPI {
3
3
  }
4
4
  export declare const webTrigger: WebTriggerAPI;
5
5
  export {};
6
- //# sourceMappingURL=index.d.ts.map
6
+ //# sourceMappingURL=webTrigger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webTrigger.d.ts","sourceRoot":"","sources":["../src/webTrigger.ts"],"names":[],"mappings":"AAGA,UAAU,aAAa;IACrB,MAAM,EAAE,CAAC,mBAAmB,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1D;AA2CD,eAAO,MAAM,UAAU,EAAE,aAGxB,CAAC"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.webTrigger = void 0;
4
+ const runtime_1 = require("./api/runtime");
5
+ const fetch_and_storage_1 = require("./runtime/fetch-and-storage");
6
+ const proxyGetWebTriggerURL = (0, runtime_1.wrapInMetrics)('api.getWebTriggerUrl', async (webTriggerModuleKey) => {
7
+ var _a, _b;
8
+ const runtime = (0, runtime_1.getRuntime)();
9
+ const response = await (0, fetch_and_storage_1.createRequestStargateAsApp)()('/graphql', {
10
+ method: 'POST',
11
+ headers: { 'Content-Type': 'application/json' },
12
+ body: JSON.stringify({
13
+ query: `
14
+ mutation forge_app_createWebTriggerUrl($input: WebTriggerUrlInput!) {
15
+ createWebTriggerUrl(input: $input) {
16
+ url
17
+ }
18
+ }
19
+ `,
20
+ variables: {
21
+ input: {
22
+ appId: runtime.appContext.appId,
23
+ envId: runtime.appContext.environmentId,
24
+ triggerKey: webTriggerModuleKey,
25
+ contextId: runtime.contextAri
26
+ }
27
+ }
28
+ })
29
+ });
30
+ if (!response.ok) {
31
+ throw new Error(`Internal error occurred: Failed to get web trigger URL: ${response.statusText}.`);
32
+ }
33
+ const responseBody = await response.json();
34
+ if (!((_b = (_a = responseBody === null || responseBody === void 0 ? void 0 : responseBody.data) === null || _a === void 0 ? void 0 : _a.createWebTriggerUrl) === null || _b === void 0 ? void 0 : _b.url)) {
35
+ throw new Error(`Internal error occurred: Failed to get web trigger URL.`);
36
+ }
37
+ return responseBody.data.createWebTriggerUrl.url;
38
+ });
39
+ exports.webTrigger = {
40
+ getUrl: async (webTriggerModuleKey) => { var _a, _b, _c; return ((_c = (_b = (_a = global.api) === null || _a === void 0 ? void 0 : _a.webTrigger) === null || _b === void 0 ? void 0 : _b.getUrl) !== null && _c !== void 0 ? _c : proxyGetWebTriggerURL)(webTriggerModuleKey); }
41
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/api",
3
- "version": "2.12.0-next.1-experimental-58938ba",
3
+ "version": "2.12.0-next.2-experimental-2a9dda4",
4
4
  "description": "Forge API methods",
5
5
  "author": "Atlassian",
6
6
  "license": "UNLICENSED",
@@ -12,6 +12,7 @@
12
12
  "compile": "tsc -b -v"
13
13
  },
14
14
  "devDependencies": {
15
+ "@forge/runtime": "4.3.0-next.0-experimental-2a9dda4",
15
16
  "@forge/util": "1.2.1",
16
17
  "nock": "^10.0.6",
17
18
  "@types/node": "^12.12.63"
@@ -19,7 +20,7 @@
19
20
  "dependencies": {
20
21
  "@forge/auth": "0.0.1",
21
22
  "@forge/egress": "1.1.2",
22
- "@forge/storage": "1.3.2-experimental-58938ba",
23
+ "@forge/storage": "1.3.2-experimental-2a9dda4",
23
24
  "@types/node-fetch": "^2.5.7",
24
25
  "node-fetch": "2.6.7"
25
26
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/webTrigger/index.ts"],"names":[],"mappings":"AAAA,UAAU,aAAa;IACrB,MAAM,EAAE,CAAC,mBAAmB,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1D;AAED,eAAO,MAAM,UAAU,EAAE,aAIxB,CAAC"}
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.webTrigger = void 0;
4
- exports.webTrigger = {
5
- getUrl: async (webTriggerModuleKey) => {
6
- return global.api.webTrigger.getUrl(webTriggerModuleKey);
7
- }
8
- };