@forge/cli-shared 9.3.1-next.1-experimental-0b00ed8 → 9.3.1-next.2-experimental-f4ce0ae

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.
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpFileUploader = exports.UploadFileEmptyError = exports.UploadFileNotFoundError = exports.CannotUploadFileError = void 0;
4
- const tslib_1 = require("tslib");
5
- const http_1 = tslib_1.__importDefault(require("http"));
6
- const https_1 = tslib_1.__importDefault(require("https"));
7
- const url_1 = require("url");
8
4
  const ui_1 = require("../ui");
5
+ const node_request_1 = require("./node-request");
9
6
  class CannotUploadFileError extends Error {
10
7
  }
11
8
  exports.CannotUploadFileError = CannotUploadFileError;
@@ -15,7 +12,6 @@ exports.UploadFileNotFoundError = UploadFileNotFoundError;
15
12
  class UploadFileEmptyError extends Error {
16
13
  }
17
14
  exports.UploadFileEmptyError = UploadFileEmptyError;
18
- const NODE_REQUEST_TIMEOUT_MS = 30_000;
19
15
  const validateFileContents = (filePath, fileContents) => {
20
16
  if (!fileContents) {
21
17
  throw new UploadFileNotFoundError(ui_1.Text.upload.error.notFound(filePath));
@@ -30,33 +26,6 @@ const checkResponse = async (response) => {
30
26
  throw new CannotUploadFileError(ui_1.Text.upload.error.status(response.status, await response.text()));
31
27
  }
32
28
  };
33
- const uploadWithNodeRequest = (url, headers, fileContents) => {
34
- return new Promise((resolve, reject) => {
35
- const parsedUrl = new url_1.URL(url);
36
- const transport = parsedUrl.protocol === 'https:' ? https_1.default : http_1.default;
37
- const request = transport.request(parsedUrl, {
38
- method: 'PUT',
39
- headers
40
- }, (response) => {
41
- const chunks = [];
42
- response.on('data', (chunk) => chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)));
43
- response.on('end', () => {
44
- const body = Buffer.concat(chunks).toString('utf-8');
45
- resolve(new Response(body, {
46
- status: response.statusCode ?? 500,
47
- statusText: response.statusMessage,
48
- headers: response.headers
49
- }));
50
- });
51
- });
52
- request.setTimeout(NODE_REQUEST_TIMEOUT_MS, () => {
53
- request.destroy(new Error(`Request timed out after ${NODE_REQUEST_TIMEOUT_MS}ms`));
54
- });
55
- request.on('error', reject);
56
- request.write(fileContents);
57
- request.end();
58
- });
59
- };
60
29
  class HttpFileUploader {
61
30
  fileSystem;
62
31
  constructor(fileSystem) {
@@ -69,7 +38,12 @@ class HttpFileUploader {
69
38
  'Content-Type': 'application/zip',
70
39
  'Content-Length': validFileContents.length.toString()
71
40
  };
72
- const response = await uploadWithNodeRequest(url, headers, validFileContents);
41
+ const response = await (0, node_request_1.sendWithNodeRequest)({
42
+ method: 'PUT',
43
+ url,
44
+ headers,
45
+ body: validFileContents
46
+ });
73
47
  await checkResponse(response);
74
48
  }
75
49
  }
@@ -1,5 +1,6 @@
1
1
  export * from './file-uploader';
2
2
  export * from './global-edge-http-client';
3
3
  export * from './feedback-post-client';
4
+ export * from './node-request';
4
5
  export * from './trace';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/http-client/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/http-client/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC"}
@@ -4,4 +4,5 @@ const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./file-uploader"), exports);
5
5
  tslib_1.__exportStar(require("./global-edge-http-client"), exports);
6
6
  tslib_1.__exportStar(require("./feedback-post-client"), exports);
7
+ tslib_1.__exportStar(require("./node-request"), exports);
7
8
  tslib_1.__exportStar(require("./trace"), exports);
@@ -0,0 +1,10 @@
1
+ import http from 'http';
2
+ export declare const toHeaders: (rawHeaders: http.IncomingHttpHeaders) => Headers;
3
+ export declare const sendWithNodeRequest: ({ method, url, headers, body, timeoutMs }: {
4
+ method: string;
5
+ url: string;
6
+ headers?: Record<string, string>;
7
+ body?: Buffer | Uint8Array | string;
8
+ timeoutMs?: number;
9
+ }) => Promise<Response>;
10
+ //# sourceMappingURL=node-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-request.d.ts","sourceRoot":"","sources":["../../src/http-client/node-request.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAQxB,eAAO,MAAM,SAAS,GAAI,YAAY,IAAI,CAAC,mBAAmB,KAAG,OAYhE,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,2CAMjC;IACD,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,KAAG,OAAO,CAAC,QAAQ,CAsCnB,CAAC"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendWithNodeRequest = exports.toHeaders = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const http_1 = tslib_1.__importDefault(require("http"));
6
+ const https_1 = tslib_1.__importDefault(require("https"));
7
+ const url_1 = require("url");
8
+ const DEFAULT_HTTP_ERROR_STATUS = 500;
9
+ const DEFAULT_NODE_REQUEST_TIMEOUT_MS = 30_000;
10
+ const NO_BODY_STATUS_CODES = new Set([204, 205, 304]);
11
+ const toHeaders = (rawHeaders) => {
12
+ const headers = new Headers();
13
+ Object.entries(rawHeaders).forEach(([key, value]) => {
14
+ if (Array.isArray(value)) {
15
+ value.forEach((headerValue) => headers.append(key, headerValue));
16
+ return;
17
+ }
18
+ if (typeof value === 'string') {
19
+ headers.set(key, value);
20
+ }
21
+ });
22
+ return headers;
23
+ };
24
+ exports.toHeaders = toHeaders;
25
+ const sendWithNodeRequest = ({ method, url, headers, body, timeoutMs = DEFAULT_NODE_REQUEST_TIMEOUT_MS }) => {
26
+ return new Promise((resolve, reject) => {
27
+ const parsedUrl = new url_1.URL(url);
28
+ const transport = parsedUrl.protocol === 'https:' ? https_1.default : http_1.default;
29
+ const request = transport.request(parsedUrl, {
30
+ method,
31
+ headers
32
+ }, (response) => {
33
+ const chunks = [];
34
+ response.on('data', (chunk) => chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)));
35
+ response.on('error', reject);
36
+ response.on('end', () => {
37
+ const responseBody = Buffer.concat(chunks).toString('utf8');
38
+ const status = response.statusCode ?? DEFAULT_HTTP_ERROR_STATUS;
39
+ const body = NO_BODY_STATUS_CODES.has(status) ? undefined : responseBody;
40
+ resolve(new Response(body, {
41
+ status,
42
+ statusText: response.statusMessage,
43
+ headers: (0, exports.toHeaders)(response.headers)
44
+ }));
45
+ });
46
+ });
47
+ request.setTimeout(timeoutMs, () => {
48
+ request.destroy(new Error(`Request timed out after ${timeoutMs}ms`));
49
+ });
50
+ request.on('error', reject);
51
+ if (body !== undefined) {
52
+ request.write(body);
53
+ }
54
+ request.end();
55
+ });
56
+ };
57
+ exports.sendWithNodeRequest = sendWithNodeRequest;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/cli-shared",
3
- "version": "9.3.1-next.1-experimental-0b00ed8",
3
+ "version": "9.3.1-next.2-experimental-f4ce0ae",
4
4
  "description": "Common functionality for Forge CLI",
5
5
  "author": "Atlassian",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
@@ -12,7 +12,7 @@
12
12
  "generate-graphql-types": "graphql-codegen --config src/graphql/codegen.yml"
13
13
  },
14
14
  "dependencies": {
15
- "@forge/manifest": "13.3.0-experimental-0b00ed8",
15
+ "@forge/manifest": "13.3.1-next.0-experimental-f4ce0ae",
16
16
  "@forge/util": "3.0.0",
17
17
  "@forge/i18n": "1.0.0",
18
18
  "@sentry/node": "7.106.0",
@@ -39,7 +39,6 @@
39
39
  "inquirer-autocomplete-prompt": "^2.0.1",
40
40
  "io-ts": "^2.2.22",
41
41
  "keytar": "^7.9.0",
42
- "node-fetch": "2.7.0",
43
42
  "ora": "^5.4.1",
44
43
  "recursive-readdir": "^2.2.3",
45
44
  "semver": "^7.6.0",
@@ -66,7 +65,6 @@
66
65
  "@types/inquirer-autocomplete-prompt": "^1.3.5",
67
66
  "@types/jest": "^29.5.14",
68
67
  "@types/node": "20.19.1",
69
- "@types/node-fetch": "^2.6.12",
70
68
  "@types/recursive-readdir": "^2.2.4",
71
69
  "@types/tmp": "^0.2.6",
72
70
  "jest-matcher-specific-error": "^1.0.0",