@forge/bundler 4.10.4-next.1 → 4.10.4-next.11
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 +94 -0
- package/out/stubs/http-node.d.ts.map +1 -1
- package/out/stubs/http-node.js +110 -10
- package/out/stubs/{http-impl.d.ts → http-sandbox-impl.d.ts} +5 -16
- package/out/stubs/http-sandbox-impl.d.ts.map +1 -0
- package/out/stubs/{http-impl.js → http-sandbox-impl.js} +56 -84
- package/out/stubs/http-sandbox.d.ts +12 -1
- package/out/stubs/http-sandbox.d.ts.map +1 -1
- package/out/stubs/http-sandbox.js +25 -14
- package/out/stubs/http-shared.d.ts +15 -0
- package/out/stubs/http-shared.d.ts.map +1 -0
- package/out/stubs/http-shared.js +23 -0
- package/package.json +10 -10
- package/out/stubs/http-impl.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,99 @@
|
|
|
1
1
|
# @forge/bundler
|
|
2
2
|
|
|
3
|
+
## 4.10.4-next.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 48a4ea41: Renovate
|
|
8
|
+
- Updated dependencies [48a4ea41]
|
|
9
|
+
- @forge/cli-shared@3.17.0-next.6
|
|
10
|
+
- @forge/lint@3.6.3-next.7
|
|
11
|
+
|
|
12
|
+
## 4.10.4-next.10
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 88be9538: Use HTTP polyfill to call proxy
|
|
17
|
+
- Updated dependencies [88be9538]
|
|
18
|
+
- @forge/runtime@4.4.5-next.1
|
|
19
|
+
- @forge/api@2.18.3-next.1
|
|
20
|
+
|
|
21
|
+
## 4.10.4-next.9
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [07eb84dc]
|
|
26
|
+
- @forge/cli-shared@3.17.0-next.5
|
|
27
|
+
- @forge/lint@3.6.3-next.6
|
|
28
|
+
|
|
29
|
+
## 4.10.4-next.8
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [665f1b2f]
|
|
34
|
+
- @forge/cli-shared@3.17.0-next.4
|
|
35
|
+
- @forge/lint@3.6.3-next.5
|
|
36
|
+
|
|
37
|
+
## 4.10.4-next.7
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- Updated dependencies [467d04a4]
|
|
42
|
+
- @forge/cli-shared@3.17.0-next.3
|
|
43
|
+
- @forge/lint@3.6.3-next.4
|
|
44
|
+
|
|
45
|
+
## 4.10.4-next.6
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [d6728272]
|
|
50
|
+
- @forge/cli-shared@3.17.0-next.2
|
|
51
|
+
- @forge/lint@3.6.3-next.3
|
|
52
|
+
|
|
53
|
+
## 4.10.4-next.5
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- 79b19f24: Bumping dependencies via Renovate:
|
|
58
|
+
|
|
59
|
+
- prettier
|
|
60
|
+
|
|
61
|
+
## 4.10.4-next.4
|
|
62
|
+
|
|
63
|
+
### Patch Changes
|
|
64
|
+
|
|
65
|
+
- @forge/cli-shared@3.16.1-next.1
|
|
66
|
+
- @forge/lint@3.6.3-next.2
|
|
67
|
+
|
|
68
|
+
## 4.10.4-next.3
|
|
69
|
+
|
|
70
|
+
### Patch Changes
|
|
71
|
+
|
|
72
|
+
- 7ade714: Bumping dependencies via Renovate:
|
|
73
|
+
|
|
74
|
+
- @typescript-eslint/eslint-plugin
|
|
75
|
+
- @typescript-eslint/parser
|
|
76
|
+
- @typescript-eslint/typescript-estree
|
|
77
|
+
|
|
78
|
+
- Updated dependencies [7ade714]
|
|
79
|
+
- @forge/lint@3.6.3-next.1
|
|
80
|
+
|
|
81
|
+
## 4.10.4-next.2
|
|
82
|
+
|
|
83
|
+
### Patch Changes
|
|
84
|
+
|
|
85
|
+
- 8105c45: Bumping dependencies via Renovate:
|
|
86
|
+
|
|
87
|
+
- @types/jest
|
|
88
|
+
- jest
|
|
89
|
+
- jest-environment-jsdom
|
|
90
|
+
|
|
91
|
+
- Updated dependencies [8105c45]
|
|
92
|
+
- @forge/cli-shared@3.16.1-next.0
|
|
93
|
+
- @forge/runtime@4.4.5-next.0
|
|
94
|
+
- @forge/lint@3.6.3-next.0
|
|
95
|
+
- @forge/api@2.18.3-next.0
|
|
96
|
+
|
|
3
97
|
## 4.10.4-next.1
|
|
4
98
|
|
|
5
99
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-node.d.ts","sourceRoot":"","sources":["../../src/stubs/http-node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http-node.d.ts","sourceRoot":"","sources":["../../src/stubs/http-node.ts"],"names":[],"mappings":"AAqQA,wBAAgB,YAAY,SAG3B;AAED,wBAAgB,YAAY,SAG3B"}
|
package/out/stubs/http-node.js
CHANGED
|
@@ -1,37 +1,137 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.restoreHttps = exports.replaceHttps = void 0;
|
|
4
|
+
const http_1 = require("http");
|
|
5
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
4
6
|
const url_1 = require("url");
|
|
5
|
-
const
|
|
7
|
+
const http_shared_1 = require("./http-shared");
|
|
8
|
+
const api_1 = require("@forge/api");
|
|
6
9
|
const https = require('https');
|
|
10
|
+
const FORGE_PROXY_UPSTREAM_LATENCY_HEADER = 'forge-proxy-upstream-latency';
|
|
11
|
+
const FORGE_PROXY_RELATIVE_LOCATION_HEADER = 'forge-proxy-relative-location';
|
|
12
|
+
const REDIRECT_STATUS = new Set([300, 301, 302, 303, 307, 308]);
|
|
7
13
|
const originalHttpsRequest = https.request;
|
|
8
14
|
const originalHttpsGet = https.get;
|
|
9
15
|
function parseArgs(args) {
|
|
10
16
|
const result = {
|
|
11
17
|
options: {}
|
|
12
18
|
};
|
|
13
|
-
if (args.length > 0 && (0,
|
|
14
|
-
const url = (0,
|
|
19
|
+
if (args.length > 0 && (0, http_shared_1.isStringOrURL)(args[0])) {
|
|
20
|
+
const url = (0, http_shared_1.isString)(args[0]) ? new url_1.URL(args[0]) : args[0];
|
|
15
21
|
result.options = (0, url_1.urlToHttpOptions)(url);
|
|
16
22
|
args.shift();
|
|
17
23
|
}
|
|
18
|
-
if (args.length > 0 && (0,
|
|
24
|
+
if (args.length > 0 && (0, http_shared_1.isRequestOptions)(args[0])) {
|
|
19
25
|
result.options = Object.assign(result.options, args[0]);
|
|
20
26
|
args.shift();
|
|
21
27
|
}
|
|
22
|
-
if (args.length > 0 && (0,
|
|
28
|
+
if (args.length > 0 && (0, http_shared_1.isCallback)(args[0])) {
|
|
23
29
|
result.callback = args[0];
|
|
24
30
|
args.shift();
|
|
25
31
|
}
|
|
26
32
|
return result;
|
|
27
33
|
}
|
|
34
|
+
const AUTH_PROVIDERS = ['app', 'user', 'none'];
|
|
35
|
+
function isAuthProvider(provider) {
|
|
36
|
+
return AUTH_PROVIDERS.includes(provider);
|
|
37
|
+
}
|
|
38
|
+
const REMOTE_APIS = ['jira', 'confluence', 'stargate', 'bitbucket'];
|
|
39
|
+
function isRemoteAPI(remote) {
|
|
40
|
+
return REMOTE_APIS.includes(remote);
|
|
41
|
+
}
|
|
42
|
+
function getProxyPath(args) {
|
|
43
|
+
switch (args.type) {
|
|
44
|
+
case 'egress':
|
|
45
|
+
return '/egress';
|
|
46
|
+
case 'fpp':
|
|
47
|
+
return `/fpp/provider/${args.provider}/remote/${args.remote}`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const providerToMetric = {
|
|
51
|
+
app: 'asApp',
|
|
52
|
+
user: 'asUser'
|
|
53
|
+
};
|
|
54
|
+
const remoteToMetric = {
|
|
55
|
+
jira: 'requestJira',
|
|
56
|
+
confluence: 'requestConfluence',
|
|
57
|
+
bitbucket: 'requestBitbucket',
|
|
58
|
+
stargate: 'requestAtlassian'
|
|
59
|
+
};
|
|
60
|
+
const METRICS_TAGS = { proxy: 'true' };
|
|
61
|
+
function getMetricsName(args) {
|
|
62
|
+
switch (args.type) {
|
|
63
|
+
case 'egress':
|
|
64
|
+
return 'api.fetch';
|
|
65
|
+
case 'fpp':
|
|
66
|
+
const { provider, remote } = args;
|
|
67
|
+
if (provider === 'none') {
|
|
68
|
+
return `api.${remoteToMetric[remote]}`;
|
|
69
|
+
}
|
|
70
|
+
return `api.${providerToMetric[provider]}.${remoteToMetric[remote]}`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function getSingleString(values) {
|
|
74
|
+
if (typeof values === 'string') {
|
|
75
|
+
return values;
|
|
76
|
+
}
|
|
77
|
+
if (Array.isArray(values)) {
|
|
78
|
+
return values[0];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function getSingleHeader(response, header) {
|
|
82
|
+
return getSingleString(response.headers[header]);
|
|
83
|
+
}
|
|
28
84
|
function request(...args) {
|
|
29
|
-
var _a;
|
|
85
|
+
var _a, _b;
|
|
30
86
|
const { options, callback } = parseArgs(args);
|
|
31
|
-
|
|
32
|
-
|
|
87
|
+
let proxyArgs = { type: 'egress' };
|
|
88
|
+
const host = (_a = options.host) !== null && _a !== void 0 ? _a : options.hostname;
|
|
89
|
+
if ((options === null || options === void 0 ? void 0 : options.agent) === 'FORGE_PRODUCT_REQUEST') {
|
|
90
|
+
delete options.agent;
|
|
91
|
+
if (host && isRemoteAPI(host)) {
|
|
92
|
+
const authorization = getSingleString((_b = options.headers) === null || _b === void 0 ? void 0 : _b.authorization);
|
|
93
|
+
if (authorization === null || authorization === void 0 ? void 0 : authorization.startsWith('Forge ')) {
|
|
94
|
+
const [, provider] = authorization.split(' ');
|
|
95
|
+
if (isAuthProvider(provider)) {
|
|
96
|
+
proxyArgs = { type: 'fpp', provider, remote: host };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const { metrics, proxy } = (0, api_1.getRuntime)();
|
|
102
|
+
const metricsName = getMetricsName(proxyArgs);
|
|
103
|
+
const headers = Object.assign(Object.assign({}, options.headers), { 'forge-proxy-authorization': `Bearer ${proxy.token}` });
|
|
104
|
+
if (proxy.host) {
|
|
105
|
+
headers['Host'] = proxy.host;
|
|
106
|
+
}
|
|
107
|
+
switch (proxyArgs.type) {
|
|
108
|
+
case 'egress':
|
|
109
|
+
headers['forge-proxy-target'] = (0, http_shared_1.formatUrl)(options);
|
|
110
|
+
break;
|
|
111
|
+
case 'fpp':
|
|
112
|
+
headers['forge-proxy-target'] = options.path;
|
|
113
|
+
break;
|
|
33
114
|
}
|
|
34
|
-
|
|
115
|
+
const proxyOptions = Object.assign(Object.assign(Object.assign({}, options), (0, url_1.urlToHttpOptions)(new url_1.URL(`${proxy.url}${getProxyPath(proxyArgs)}`))), { headers });
|
|
116
|
+
metrics.counter(metricsName, METRICS_TAGS).incr();
|
|
117
|
+
const originalRequest = proxyOptions.protocol === 'http:' ? http_1.request : originalHttpsRequest;
|
|
118
|
+
const requestStart = perf_hooks_1.performance.now();
|
|
119
|
+
return originalRequest(proxyOptions, (response) => {
|
|
120
|
+
const requestEnd = perf_hooks_1.performance.now();
|
|
121
|
+
metrics.timing(metricsName, METRICS_TAGS).set(requestEnd - requestStart);
|
|
122
|
+
const upstreamLatencyHeader = getSingleHeader(response, FORGE_PROXY_UPSTREAM_LATENCY_HEADER);
|
|
123
|
+
if (upstreamLatencyHeader !== undefined) {
|
|
124
|
+
const proxyUpstreamLatency = parseInt(upstreamLatencyHeader);
|
|
125
|
+
metrics.timing('proxy-success-overhead', METRICS_TAGS).set(requestEnd - requestStart - proxyUpstreamLatency);
|
|
126
|
+
}
|
|
127
|
+
if (response.statusCode && REDIRECT_STATUS.has(response.statusCode)) {
|
|
128
|
+
const relativeLocation = getSingleHeader(response, FORGE_PROXY_RELATIVE_LOCATION_HEADER);
|
|
129
|
+
if (relativeLocation) {
|
|
130
|
+
response.headers['location'] = `https://${host}${relativeLocation}`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
callback === null || callback === void 0 ? void 0 : callback(response);
|
|
134
|
+
});
|
|
35
135
|
}
|
|
36
136
|
function get(...args) {
|
|
37
137
|
const { options, callback } = parseArgs(args);
|
|
@@ -45,7 +145,7 @@ function replaceHttps() {
|
|
|
45
145
|
}
|
|
46
146
|
exports.replaceHttps = replaceHttps;
|
|
47
147
|
function restoreHttps() {
|
|
48
|
-
https.request =
|
|
148
|
+
https.request = originalHttpsRequest;
|
|
49
149
|
https.get = originalHttpsGet;
|
|
50
150
|
}
|
|
51
151
|
exports.restoreHttps = restoreHttps;
|
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
|
|
4
|
-
import { IncomingMessage } from 'http';
|
|
5
|
-
import { RequestOptions, AgentOptions } from 'https';
|
|
3
|
+
import { RequestOptions } from 'https';
|
|
6
4
|
import { Writable } from 'readable-stream';
|
|
7
5
|
import { URL } from 'url';
|
|
8
6
|
import { FetchOptions } from '@forge/api';
|
|
9
|
-
|
|
7
|
+
import { Callback } from './http-shared';
|
|
8
|
+
interface ChainableOptions {
|
|
10
9
|
timeout?: number;
|
|
11
10
|
headers: {
|
|
12
11
|
[key: string]: string;
|
|
13
12
|
};
|
|
14
13
|
}
|
|
15
|
-
export type Callback = (res: IncomingMessage) => void;
|
|
16
|
-
export type Arg = RequestOptions | string | URL | Callback;
|
|
17
|
-
export declare const isCallback: (options: Arg) => options is Callback;
|
|
18
|
-
export declare const isString: (options: Arg) => options is string;
|
|
19
|
-
export declare const isURL: (options: Arg) => options is URL;
|
|
20
|
-
export declare const isStringOrURL: (options: Arg) => options is string | URL;
|
|
21
|
-
export declare const isRequestOptions: (options: Arg) => options is RequestOptions;
|
|
22
14
|
export declare class Request extends Writable {
|
|
23
15
|
private reqBody;
|
|
24
16
|
private chainableOptions;
|
|
@@ -27,7 +19,6 @@ export declare class Request extends Writable {
|
|
|
27
19
|
setTimeout(value: number, callback?: () => void): Request;
|
|
28
20
|
private fetch;
|
|
29
21
|
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
|
30
|
-
static formatUrl(options: RequestOptions): string;
|
|
31
22
|
static urlFromFetchArgs(options: RequestOptions | string | URL): string;
|
|
32
23
|
static convertToForgeFetchArgs(options: RequestOptions | string | URL, chainableOptions: ChainableOptions): {
|
|
33
24
|
url: string;
|
|
@@ -35,7 +26,5 @@ export declare class Request extends Writable {
|
|
|
35
26
|
};
|
|
36
27
|
abort(): void;
|
|
37
28
|
}
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=http-impl.d.ts.map
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=http-sandbox-impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-sandbox-impl.d.ts","sourceRoot":"","sources":["../../src/stubs/http-sandbox-impl.ts"],"names":[],"mappings":";;AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAY,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,EAAe,YAAY,EAAS,MAAM,YAAY,CAAC;AAE9D,OAAO,EAAE,QAAQ,EAA6C,MAAM,eAAe,CAAC;AAEpF,UAAU,gBAAgB;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE;QACP,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACvB,CAAC;CACH;AAED,qBAAa,OAAQ,SAAQ,QAAQ;IACnC,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,gBAAgB,CAAmB;gBAE/B,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,EAAE,QAAQ,CAAC,EAAE,QAAQ;IAahE,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAM/C,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO;IAQhE,OAAO,CAAC,KAAK;IAsBN,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI;IAe3F,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,GAAG,MAAM;IAiBvE,MAAM,CAAC,uBAAuB,CAC5B,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,EACtC,gBAAgB,EAAE,gBAAgB,GACjC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,YAAY,CAAA;KAAE;IAuBtC,KAAK;CAGN"}
|
|
@@ -1,71 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Request = void 0;
|
|
4
4
|
const readable_stream_1 = require("readable-stream");
|
|
5
5
|
const api_1 = require("@forge/api");
|
|
6
|
-
const
|
|
7
|
-
'age',
|
|
8
|
-
'authorization',
|
|
9
|
-
'content-length',
|
|
10
|
-
'content-type',
|
|
11
|
-
'etag',
|
|
12
|
-
'expires',
|
|
13
|
-
'from',
|
|
14
|
-
'host',
|
|
15
|
-
'if-modified-since',
|
|
16
|
-
'if-unmodified-since',
|
|
17
|
-
'last-modified',
|
|
18
|
-
'location',
|
|
19
|
-
'max-forwards',
|
|
20
|
-
'proxy-authorization',
|
|
21
|
-
'referer',
|
|
22
|
-
'retry-after',
|
|
23
|
-
'server',
|
|
24
|
-
'user-agent'
|
|
25
|
-
]);
|
|
26
|
-
class Response extends readable_stream_1.Readable {
|
|
27
|
-
constructor(content, response) {
|
|
28
|
-
super();
|
|
29
|
-
this.statusCode = response.status;
|
|
30
|
-
this.statusMessage = response.statusText;
|
|
31
|
-
this.headers = {};
|
|
32
|
-
this.headersDistinct = {};
|
|
33
|
-
const rawHeaders = response.headers.raw();
|
|
34
|
-
for (const [name, values] of Object.entries(rawHeaders)) {
|
|
35
|
-
if (name === 'content-encoding') {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
let value;
|
|
39
|
-
if (HEADERS_DISCARD_DUPLICATES.has(name)) {
|
|
40
|
-
value = values[0];
|
|
41
|
-
}
|
|
42
|
-
else if (name === 'set-cookie') {
|
|
43
|
-
value = values;
|
|
44
|
-
}
|
|
45
|
-
else if (name === 'cookie') {
|
|
46
|
-
value = values.join('; ');
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
value = values.join(', ');
|
|
50
|
-
}
|
|
51
|
-
this.headers[name] = value;
|
|
52
|
-
this.headersDistinct[name] = values;
|
|
53
|
-
}
|
|
54
|
-
this._read = () => { };
|
|
55
|
-
this.push(Buffer.from(content));
|
|
56
|
-
this.push(null);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const isCallback = (options) => typeof options === 'function';
|
|
60
|
-
exports.isCallback = isCallback;
|
|
61
|
-
const isString = (options) => typeof options === 'string';
|
|
62
|
-
exports.isString = isString;
|
|
63
|
-
const isURL = (options) => typeof options === 'object' && options.constructor.name === 'URL';
|
|
64
|
-
exports.isURL = isURL;
|
|
65
|
-
const isStringOrURL = (options) => (0, exports.isString)(options) || (0, exports.isURL)(options);
|
|
66
|
-
exports.isStringOrURL = isStringOrURL;
|
|
67
|
-
const isRequestOptions = (options) => !(0, exports.isStringOrURL)(options) && !(0, exports.isCallback)(options);
|
|
68
|
-
exports.isRequestOptions = isRequestOptions;
|
|
6
|
+
const http_shared_1 = require("./http-shared");
|
|
69
7
|
class Request extends readable_stream_1.Writable {
|
|
70
8
|
constructor(options, callback) {
|
|
71
9
|
super();
|
|
@@ -126,25 +64,16 @@ class Request extends readable_stream_1.Writable {
|
|
|
126
64
|
callback(err);
|
|
127
65
|
}
|
|
128
66
|
}
|
|
129
|
-
static formatUrl(options) {
|
|
130
|
-
var _a, _b;
|
|
131
|
-
const protocol = 'https:';
|
|
132
|
-
const auth = options.auth ? `${options.auth}@` : '';
|
|
133
|
-
const host = (_a = options.hostname) !== null && _a !== void 0 ? _a : options.host;
|
|
134
|
-
const port = options.port ? `:${options.port}` : '';
|
|
135
|
-
const path = (_b = options.path) !== null && _b !== void 0 ? _b : '/';
|
|
136
|
-
return `${protocol}//${auth}${host}${port}${path}`;
|
|
137
|
-
}
|
|
138
67
|
static urlFromFetchArgs(options) {
|
|
139
|
-
if ((0,
|
|
68
|
+
if ((0, http_shared_1.isString)(options)) {
|
|
140
69
|
return options;
|
|
141
70
|
}
|
|
142
|
-
else if ((0,
|
|
71
|
+
else if ((0, http_shared_1.isURL)(options)) {
|
|
143
72
|
return options.toString();
|
|
144
73
|
}
|
|
145
74
|
else {
|
|
146
75
|
try {
|
|
147
|
-
return
|
|
76
|
+
return (0, http_shared_1.formatUrl)(options);
|
|
148
77
|
}
|
|
149
78
|
catch (err) {
|
|
150
79
|
console.error('Unable to make request with unrecognised URL options:', options);
|
|
@@ -154,7 +83,7 @@ class Request extends readable_stream_1.Writable {
|
|
|
154
83
|
}
|
|
155
84
|
static convertToForgeFetchArgs(options, chainableOptions) {
|
|
156
85
|
const url = Request.urlFromFetchArgs(options);
|
|
157
|
-
if ((0,
|
|
86
|
+
if ((0, http_shared_1.isStringOrURL)(options)) {
|
|
158
87
|
return { url, init: chainableOptions };
|
|
159
88
|
}
|
|
160
89
|
else {
|
|
@@ -178,13 +107,56 @@ class Request extends readable_stream_1.Writable {
|
|
|
178
107
|
}
|
|
179
108
|
}
|
|
180
109
|
exports.Request = Request;
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
110
|
+
const HEADERS_DISCARD_DUPLICATES = new Set([
|
|
111
|
+
'age',
|
|
112
|
+
'authorization',
|
|
113
|
+
'content-length',
|
|
114
|
+
'content-type',
|
|
115
|
+
'etag',
|
|
116
|
+
'expires',
|
|
117
|
+
'from',
|
|
118
|
+
'host',
|
|
119
|
+
'if-modified-since',
|
|
120
|
+
'if-unmodified-since',
|
|
121
|
+
'last-modified',
|
|
122
|
+
'location',
|
|
123
|
+
'max-forwards',
|
|
124
|
+
'proxy-authorization',
|
|
125
|
+
'referer',
|
|
126
|
+
'retry-after',
|
|
127
|
+
'server',
|
|
128
|
+
'user-agent'
|
|
129
|
+
]);
|
|
130
|
+
class Response extends readable_stream_1.Readable {
|
|
131
|
+
constructor(content, response) {
|
|
132
|
+
super();
|
|
133
|
+
this.statusCode = response.status;
|
|
134
|
+
this.statusMessage = response.statusText;
|
|
135
|
+
this.headers = {};
|
|
136
|
+
this.headersDistinct = {};
|
|
137
|
+
const rawHeaders = response.headers.raw();
|
|
138
|
+
for (const [name, values] of Object.entries(rawHeaders)) {
|
|
139
|
+
if (name === 'content-encoding') {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
let value;
|
|
143
|
+
if (HEADERS_DISCARD_DUPLICATES.has(name)) {
|
|
144
|
+
value = values[0];
|
|
145
|
+
}
|
|
146
|
+
else if (name === 'set-cookie') {
|
|
147
|
+
value = values;
|
|
148
|
+
}
|
|
149
|
+
else if (name === 'cookie') {
|
|
150
|
+
value = values.join('; ');
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
value = values.join(', ');
|
|
154
|
+
}
|
|
155
|
+
this.headers[name] = value;
|
|
156
|
+
this.headersDistinct[name] = values;
|
|
186
157
|
}
|
|
187
|
-
|
|
158
|
+
this._read = () => { };
|
|
159
|
+
this.push(Buffer.from(content));
|
|
160
|
+
this.push(null);
|
|
188
161
|
}
|
|
189
162
|
}
|
|
190
|
-
exports.Agent = Agent;
|
|
@@ -1,2 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import { AgentOptions, IncomingMessage } from 'http';
|
|
5
|
+
import { RequestOptions } from 'https';
|
|
6
|
+
import { URL } from 'url';
|
|
7
|
+
import { Request } from './http-sandbox-impl';
|
|
8
|
+
export declare function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): Request;
|
|
9
|
+
export declare function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): Request;
|
|
10
|
+
export declare class Agent {
|
|
11
|
+
constructor(options: AgentOptions);
|
|
12
|
+
}
|
|
2
13
|
//# sourceMappingURL=http-sandbox.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-sandbox.d.ts","sourceRoot":"","sources":["../../src/stubs/http-sandbox.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"http-sandbox.d.ts","sourceRoot":"","sources":["../../src/stubs/http-sandbox.ts"],"names":[],"mappings":";;;AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAG1B,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAElH;AAED,wBAAgB,GAAG,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAO9G;AAID,qBAAa,KAAK;gBACJ,OAAO,EAAE,YAAY;CAOlC"}
|
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
exports.Agent = exports.get = exports.request = void 0;
|
|
4
|
+
const http_shared_1 = require("./http-shared");
|
|
5
|
+
const http_sandbox_impl_1 = require("./http-sandbox-impl");
|
|
6
|
+
function request(options, callback) {
|
|
7
|
+
return new http_sandbox_impl_1.Request(options, callback);
|
|
8
|
+
}
|
|
9
|
+
exports.request = request;
|
|
10
|
+
function get(options, callback) {
|
|
11
|
+
if ((0, http_shared_1.isRequestOptions)(options)) {
|
|
12
|
+
options = Object.assign(Object.assign({}, options), { method: 'GET' });
|
|
13
|
+
}
|
|
14
|
+
const result = new http_sandbox_impl_1.Request(options, callback);
|
|
15
|
+
result.end();
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
exports.get = get;
|
|
19
|
+
const NUM_SUPPORTED_AGENT_OPTIONS = 1;
|
|
20
|
+
class Agent {
|
|
21
|
+
constructor(options) {
|
|
22
|
+
if (Object.keys(options).length > NUM_SUPPORTED_AGENT_OPTIONS) {
|
|
23
|
+
console.warn("Forge only supports 'keepAlive' as an option to http.Agent");
|
|
11
24
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Agent: http_impl_1.Agent
|
|
17
|
-
};
|
|
25
|
+
return { keepAlive: options.keepAlive };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.Agent = Agent;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import { IncomingMessage } from 'http';
|
|
5
|
+
import { RequestOptions } from 'https';
|
|
6
|
+
import { URL } from 'url';
|
|
7
|
+
export type Callback = (res: IncomingMessage) => void;
|
|
8
|
+
export type Arg = RequestOptions | string | URL | Callback;
|
|
9
|
+
export declare const isCallback: (options: Arg) => options is Callback;
|
|
10
|
+
export declare const isString: (options: Arg) => options is string;
|
|
11
|
+
export declare const isURL: (options: Arg) => options is URL;
|
|
12
|
+
export declare const isStringOrURL: (options: Arg) => options is string | URL;
|
|
13
|
+
export declare const isRequestOptions: (options: Arg) => options is RequestOptions;
|
|
14
|
+
export declare function formatUrl(options: RequestOptions): string;
|
|
15
|
+
//# sourceMappingURL=http-shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-shared.d.ts","sourceRoot":"","sources":["../../src/stubs/http-shared.ts"],"names":[],"mappings":";;;AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,CAAC;AAEtD,MAAM,MAAM,GAAG,GAAG,cAAc,GAAG,MAAM,GAAG,GAAG,GAAG,QAAQ,CAAC;AAE3D,eAAO,MAAM,UAAU,YAAa,GAAG,wBAAuD,CAAC;AAC/F,eAAO,MAAM,QAAQ,YAAa,GAAG,sBAAmD,CAAC;AACzF,eAAO,MAAM,KAAK,YAAa,GAAG,mBACiC,CAAC;AAEpE,eAAO,MAAM,aAAa,YAAa,GAAG,4BAAiE,CAAC;AAE5G,eAAO,MAAM,gBAAgB,YAAa,GAAG,8BACI,CAAC;AAElD,wBAAgB,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAQzD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatUrl = exports.isRequestOptions = exports.isStringOrURL = exports.isURL = exports.isString = exports.isCallback = void 0;
|
|
4
|
+
const isCallback = (options) => typeof options === 'function';
|
|
5
|
+
exports.isCallback = isCallback;
|
|
6
|
+
const isString = (options) => typeof options === 'string';
|
|
7
|
+
exports.isString = isString;
|
|
8
|
+
const isURL = (options) => typeof options === 'object' && options.constructor.name === 'URL';
|
|
9
|
+
exports.isURL = isURL;
|
|
10
|
+
const isStringOrURL = (options) => (0, exports.isString)(options) || (0, exports.isURL)(options);
|
|
11
|
+
exports.isStringOrURL = isStringOrURL;
|
|
12
|
+
const isRequestOptions = (options) => !(0, exports.isStringOrURL)(options) && !(0, exports.isCallback)(options);
|
|
13
|
+
exports.isRequestOptions = isRequestOptions;
|
|
14
|
+
function formatUrl(options) {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
const protocol = 'https:';
|
|
17
|
+
const auth = options.auth ? `${options.auth}@` : '';
|
|
18
|
+
const host = (_a = options.hostname) !== null && _a !== void 0 ? _a : options.host;
|
|
19
|
+
const port = options.port ? `:${options.port}` : '';
|
|
20
|
+
const path = (_b = options.path) !== null && _b !== void 0 ? _b : '/';
|
|
21
|
+
return `${protocol}//${auth}${host}${port}${path}`;
|
|
22
|
+
}
|
|
23
|
+
exports.formatUrl = formatUrl;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/bundler",
|
|
3
|
-
"version": "4.10.4-next.
|
|
3
|
+
"version": "4.10.4-next.11",
|
|
4
4
|
"description": "Default bundler for Forge apps",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "Atlassian",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"@babel/plugin-transform-optional-chaining": "^7.22.6",
|
|
20
20
|
"@babel/plugin-transform-react-jsx": "^7.22.5",
|
|
21
21
|
"@babel/preset-typescript": "^7.22.5",
|
|
22
|
-
"@forge/api": "2.18.
|
|
22
|
+
"@forge/api": "2.18.3-next.1",
|
|
23
23
|
"@forge/babel-plugin-transform-ui": "1.1.4",
|
|
24
|
-
"@forge/cli-shared": "3.
|
|
25
|
-
"@forge/lint": "3.6.
|
|
26
|
-
"@forge/runtime": "4.4.
|
|
24
|
+
"@forge/cli-shared": "3.17.0-next.6",
|
|
25
|
+
"@forge/lint": "3.6.3-next.7",
|
|
26
|
+
"@forge/runtime": "4.4.5-next.1",
|
|
27
27
|
"@forge/util": "1.3.0",
|
|
28
28
|
"assert": "^1.5.0",
|
|
29
29
|
"babel-loader": "^8.3.0",
|
|
@@ -55,18 +55,18 @@
|
|
|
55
55
|
"whatwg-url": "^7.1.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@atlassian/xen-test-util": "^1.
|
|
59
|
-
"@types/jest": "^29.
|
|
58
|
+
"@atlassian/xen-test-util": "^2.1.3",
|
|
59
|
+
"@types/jest": "^29.5.3",
|
|
60
60
|
"@types/node": "14.18.53",
|
|
61
61
|
"@types/react": "^17.0.53",
|
|
62
62
|
"@types/readable-stream": "^2.3.15",
|
|
63
63
|
"@types/webpack-bundle-analyzer": "^4.6.0",
|
|
64
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
65
|
-
"@typescript-eslint/parser": "^5.
|
|
64
|
+
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
65
|
+
"@typescript-eslint/parser": "^5.62.0",
|
|
66
66
|
"eslint": "^7.32.0",
|
|
67
67
|
"eslint-config-prettier": "^6.15.0",
|
|
68
68
|
"eslint-plugin-prettier": "^3.4.1",
|
|
69
|
-
"prettier": "2.
|
|
69
|
+
"prettier": "2.8.8"
|
|
70
70
|
},
|
|
71
71
|
"engines": {
|
|
72
72
|
"node": ">=12.13.1"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-impl.d.ts","sourceRoot":"","sources":["../../src/stubs/http-impl.ts"],"names":[],"mappings":";;;AAMA,OAAO,EAAuB,eAAe,EAAE,MAAM,MAAM,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErD,OAAO,EAAY,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAe,YAAY,EAAS,MAAM,YAAY,CAAC;AAwE9D,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE;QACP,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACvB,CAAC;CACH;AAED,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,CAAC;AAEtD,MAAM,MAAM,GAAG,GAAG,cAAc,GAAG,MAAM,GAAG,GAAG,GAAG,QAAQ,CAAC;AAE3D,eAAO,MAAM,UAAU,YAAa,GAAG,wBAAuD,CAAC;AAC/F,eAAO,MAAM,QAAQ,YAAa,GAAG,sBAAmD,CAAC;AACzF,eAAO,MAAM,KAAK,YAAa,GAAG,mBACiC,CAAC;AAEpE,eAAO,MAAM,aAAa,YAAa,GAAG,4BAAiE,CAAC;AAE5G,eAAO,MAAM,gBAAgB,YAAa,GAAG,8BACI,CAAC;AAElD,qBAAa,OAAQ,SAAQ,QAAQ;IACnC,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,gBAAgB,CAAmB;gBAE/B,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,EAAE,QAAQ,CAAC,EAAE,QAAQ;IAahE,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAM/C,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO;IAQhE,OAAO,CAAC,KAAK;IAsBN,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI;IAe3F,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM;IAUjD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,GAAG,MAAM;IAiBvE,MAAM,CAAC,uBAAuB,CAC5B,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,EACtC,gBAAgB,EAAE,gBAAgB,GACjC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,YAAY,CAAA;KAAE;IAuBtC,KAAK;CAGN;AAID,qBAAa,KAAK;gBACJ,OAAO,EAAE,YAAY;CAOlC"}
|