balena-request 13.3.1 → 13.3.2

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,3 +1,15 @@
1
+ - commits:
2
+ - subject: Fix always following redirects when followRedirect = false
3
+ hash: 34db7e138eabfcfcfd822133b391c738d01de323
4
+ body: ""
5
+ footer:
6
+ Change-type: patch
7
+ change-type: patch
8
+ author: Thodoris Greasidis
9
+ nested: []
10
+ version: 13.3.2
11
+ title: ""
12
+ date: 2024-07-12T08:40:03.970Z
1
13
  - commits:
2
14
  - subject: Update balena-auth to 6.0.1
3
15
  hash: 1d3cd469288f2dd0e1ed70a292778b70bd518528
@@ -10,7 +22,7 @@
10
22
  nested: []
11
23
  version: 13.3.1
12
24
  title: ""
13
- date: 2024-02-23T10:45:59.451Z
25
+ date: 2024-02-23T10:50:39.931Z
14
26
  - commits:
15
27
  - subject: Increase TOKEN_REFRESH_INTERVAL from 1 hours to 1 day
16
28
  hash: b841794b35ef310f831a37df9003418e9b90c99a
package/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file
4
4
  automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
5
5
  This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## 13.3.2 - 2024-07-12
8
+
9
+ * Fix always following redirects when followRedirect = false [Thodoris Greasidis]
10
+
7
11
  ## 13.3.1 - 2024-02-23
8
12
 
9
13
  * Update balena-auth to 6.0.1 [Thodoris Greasidis]
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { BalenaRequestOptions, BalenaRequestResponse } from './request';
3
2
  import type { getRequestAsync } from './utils';
4
3
  import type * as Stream from 'stream';
package/build/progress.js CHANGED
@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
15
15
  limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.estimate = void 0;
18
+ exports.estimate = estimate;
19
19
  const tslib_1 = require("tslib");
20
20
  const utils = require("./utils");
21
21
  /**
@@ -160,4 +160,3 @@ function estimate(requestAsync, isBrowser) {
160
160
  });
161
161
  };
162
162
  }
163
- exports.estimate = estimate;
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import type BalenaAuth from 'balena-auth';
4
2
  import type * as Stream from 'stream';
5
3
  import * as urlLib from 'url';
@@ -73,5 +71,5 @@ export declare function getRequest({ auth, debug, retries, isBrowser, intercepto
73
71
  send: <T = any>(options: BalenaRequestOptions) => Promise<BalenaRequestResponse<T>>;
74
72
  stream: (options: BalenaRequestOptions) => Promise<BalenaRequestStreamResult>;
75
73
  interceptors: Interceptor[];
76
- refreshToken: ({ baseUrl, }: Pick<BalenaRequestOptions, 'baseUrl'>) => Promise<string>;
74
+ refreshToken: ({ baseUrl, }: Pick<BalenaRequestOptions, "baseUrl">) => Promise<string>;
77
75
  };
package/build/request.js CHANGED
@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
15
15
  limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getRequest = void 0;
18
+ exports.getRequest = getRequest;
19
19
  const tslib_1 = require("tslib");
20
20
  const urlLib = require("url");
21
21
  const errors = require("balena-errors");
@@ -328,8 +328,8 @@ function getRequest({ auth, debug = false, retries = 0, isBrowser = false, inter
328
328
  * request.refreshToken
329
329
  * baseUrl: 'https://api.balena-cloud.com'
330
330
  */
331
- function refreshToken({ baseUrl, }) {
332
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
331
+ function refreshToken(_a) {
332
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ baseUrl, }) {
333
333
  // Only refresh if we have balena-auth
334
334
  if (auth == null) {
335
335
  throw new Error('Auth module not provided in initializer');
@@ -365,4 +365,3 @@ function getRequest({ auth, debug = false, retries = 0, isBrowser = false, inter
365
365
  };
366
366
  return exports;
367
367
  }
368
- exports.getRequest = getRequest;
package/build/utils.js CHANGED
@@ -15,7 +15,16 @@ See the License for the specific language governing permissions and
15
15
  limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getRequestAsync = exports.getBody = exports.debugRequest = exports.getResponseLength = exports.isResponseCompressed = exports.isErrorCode = exports.getErrorMessageFromResponse = exports.getAuthorizationHeader = exports.shouldRefreshKey = exports.TOKEN_REFRESH_INTERVAL = void 0;
18
+ exports.TOKEN_REFRESH_INTERVAL = void 0;
19
+ exports.shouldRefreshKey = shouldRefreshKey;
20
+ exports.getAuthorizationHeader = getAuthorizationHeader;
21
+ exports.getErrorMessageFromResponse = getErrorMessageFromResponse;
22
+ exports.isErrorCode = isErrorCode;
23
+ exports.isResponseCompressed = isResponseCompressed;
24
+ exports.getResponseLength = getResponseLength;
25
+ exports.debugRequest = debugRequest;
26
+ exports.getBody = getBody;
27
+ exports.getRequestAsync = getRequestAsync;
19
28
  const tslib_1 = require("tslib");
20
29
  const { fetch: normalFetch, Headers: HeadersPonyfill } =
21
30
  // eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -48,8 +57,8 @@ exports.TOKEN_REFRESH_INTERVAL = 24 * 60 * 60 * 1000; // 1 day in milliseconds
48
57
  * console.log('Updating token!')
49
58
  */
50
59
  function shouldRefreshKey(auth) {
51
- var _a;
52
60
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
61
+ var _a;
53
62
  const hasKey = yield auth.hasKey();
54
63
  if (!hasKey) {
55
64
  return false;
@@ -62,7 +71,6 @@ function shouldRefreshKey(auth) {
62
71
  return age >= exports.TOKEN_REFRESH_INTERVAL;
63
72
  });
64
73
  }
65
- exports.shouldRefreshKey = shouldRefreshKey;
66
74
  /**
67
75
  * @summary Get authorization header content
68
76
  * @function
@@ -92,7 +100,6 @@ function getAuthorizationHeader(auth) {
92
100
  return `Bearer ${key}`;
93
101
  });
94
102
  }
95
- exports.getAuthorizationHeader = getAuthorizationHeader;
96
103
  /**
97
104
  * @summary Get error message from response
98
105
  * @function
@@ -126,7 +133,6 @@ function getErrorMessageFromResponse(response) {
126
133
  }
127
134
  return response.body;
128
135
  }
129
- exports.getErrorMessageFromResponse = getErrorMessageFromResponse;
130
136
  /**
131
137
  * @summary Check if the status code represents an error
132
138
  * @function
@@ -142,7 +148,6 @@ exports.getErrorMessageFromResponse = getErrorMessageFromResponse;
142
148
  function isErrorCode(statusCode) {
143
149
  return statusCode >= 400;
144
150
  }
145
- exports.isErrorCode = isErrorCode;
146
151
  /**
147
152
  * @summary Check whether a response body is compressed
148
153
  * @function
@@ -158,7 +163,6 @@ exports.isErrorCode = isErrorCode;
158
163
  function isResponseCompressed(response) {
159
164
  return response.headers.get('Content-Encoding') === 'gzip';
160
165
  }
161
- exports.isResponseCompressed = isResponseCompressed;
162
166
  /**
163
167
  * @summary Get response compressed/uncompressed length
164
168
  * @function
@@ -180,7 +184,6 @@ function getResponseLength(response) {
180
184
  compressed: parseInt(response.headers.get('X-Transfer-Length'), 10) || undefined,
181
185
  };
182
186
  }
183
- exports.getResponseLength = getResponseLength;
184
187
  /**
185
188
  * @summary Print debug information about a request/response.
186
189
  * @function
@@ -201,7 +204,6 @@ exports.getResponseLength = getResponseLength;
201
204
  function debugRequest(options, response) {
202
205
  return console.error(Object.assign({ statusCode: response.statusCode, duration: response.duration }, options));
203
206
  }
204
- exports.debugRequest = debugRequest;
205
207
  // fetch adapter
206
208
  const UNSUPPORTED_REQUEST_PARAMS = [
207
209
  'qsParseOptions',
@@ -270,7 +272,17 @@ const processRequestOptions = function (options) {
270
272
  throw new Error(`The ${key} param is not supported. Value: ${unsupportedOptionValue}`);
271
273
  }
272
274
  }
273
- const opts = Object.assign({ timeout: options.timeout, retries: options.retries, method: options.method, compress: options.gzip, signal: options.signal, body, headers: new HeadersPonyfill(headers), mode: 'cors' }, (options.followRedirect && { redirect: 'follow' }));
275
+ const opts = {
276
+ timeout: options.timeout,
277
+ retries: options.retries,
278
+ method: options.method,
279
+ compress: options.gzip,
280
+ signal: options.signal,
281
+ body,
282
+ headers: new HeadersPonyfill(headers),
283
+ mode: 'cors',
284
+ redirect: options.followRedirect === false ? 'manual' : 'follow',
285
+ };
274
286
  return [url, opts];
275
287
  };
276
288
  /**
@@ -316,7 +328,6 @@ function getBody(response, responseFormat) {
316
328
  throw new errors.BalenaInvalidParameterError('responseFormat', responseFormat);
317
329
  });
318
330
  }
319
- exports.getBody = getBody;
320
331
  const isFile = (value) => {
321
332
  return (value instanceof Blob &&
322
333
  value.name != null &&
@@ -333,8 +344,8 @@ const getForm = () => {
333
344
  };
334
345
  // This is the actual implementation that hides the internal `retriesRemaining` parameter
335
346
  function requestAsync(fetch, options, retriesRemaining) {
336
- var _a;
337
347
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
348
+ var _a;
338
349
  const [url, opts] = processRequestOptions(options);
339
350
  if (retriesRemaining == null) {
340
351
  retriesRemaining = opts.retries;
@@ -466,4 +477,3 @@ function handleAbortIfNotSupported(signal, response) {
466
477
  function getRequestAsync($fetch = normalFetch) {
467
478
  return (options) => requestAsync($fetch, options);
468
479
  }
469
- exports.getRequestAsync = getRequestAsync;
package/lib/utils.ts CHANGED
@@ -313,7 +313,7 @@ const processRequestOptions = function (options: BalenaRequestOptions) {
313
313
  body,
314
314
  headers: new HeadersPonyfill(headers),
315
315
  mode: 'cors',
316
- ...(options.followRedirect && { redirect: 'follow' }),
316
+ redirect: options.followRedirect === false ? 'manual' : 'follow',
317
317
  };
318
318
 
319
319
  return [url, opts] as const;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "balena-request",
3
- "version": "13.3.1",
3
+ "version": "13.3.2",
4
4
  "description": "Balena HTTP client",
5
5
  "main": "build/request.js",
6
6
  "types": "build/request.d.ts",
@@ -82,6 +82,6 @@
82
82
  "balena-auth": "^6.0.1"
83
83
  },
84
84
  "versionist": {
85
- "publishedAt": "2024-02-23T10:45:59.590Z"
85
+ "publishedAt": "2024-07-12T08:40:04.114Z"
86
86
  }
87
87
  }