balena-request 12.0.3 → 12.0.4

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: Refactor the interceptors to stop using .reduce()
3
+ hash: bb3ebd421cff85803bc80ead121b83e8ed103499
4
+ body: ""
5
+ footer:
6
+ Change-type: patch
7
+ change-type: patch
8
+ author: Thodoris Greasidis
9
+ nested: []
10
+ version: 12.0.4
11
+ title: ""
12
+ date: 2023-08-23T07:58:50.227Z
1
13
  - commits:
2
14
  - subject: Avoid deep imports from balena-auth
3
15
  hash: c11642a930772b968ff736583358d04a0b9321f4
@@ -17,7 +29,7 @@
17
29
  nested: []
18
30
  version: 12.0.3
19
31
  title: ""
20
- date: 2023-08-09T12:12:01.266Z
32
+ date: 2023-08-09T12:18:22.918Z
21
33
  - commits:
22
34
  - subject: Make `url` a normal dependency
23
35
  hash: 1598cca9808180f2df2455bd8514b2647ea88f47
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
+ ## 12.0.4 - 2023-08-23
8
+
9
+ * Refactor the interceptors to stop using .reduce() [Thodoris Greasidis]
10
+
7
11
  ## 12.0.3 - 2023-08-09
8
12
 
9
13
  * Avoid deep imports from balena-auth [Thodoris Greasidis]
package/build/request.js CHANGED
@@ -95,28 +95,25 @@ function getRequest({ auth, debug = false, retries = 0, isBrowser = false, inter
95
95
  const interceptResponse = (response) => interceptResponseOrError(Promise.resolve(response));
96
96
  const interceptResponseError = (responseError) => interceptResponseOrError(Promise.reject(responseError));
97
97
  const interceptRequestOrError = (initialPromise) => tslib_1.__awaiter(this, void 0, void 0, function* () {
98
- return exports.interceptors.reduce(function (promise, { request, requestError }) {
98
+ let promise = initialPromise;
99
+ for (const { request, requestError } of exports.interceptors) {
99
100
  if (request != null || requestError != null) {
100
- return promise.then(request, requestError);
101
+ promise = promise.then(request, requestError);
101
102
  }
102
- else {
103
- return promise;
104
- }
105
- }, initialPromise);
103
+ }
104
+ return promise;
106
105
  });
107
106
  const interceptResponseOrError = function (initialPromise) {
108
107
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
109
- return exports.interceptors
108
+ let promise = initialPromise;
109
+ for (const { response, responseError } of exports.interceptors
110
110
  .slice()
111
- .reverse()
112
- .reduce(function (promise, { response, responseError }) {
111
+ .reverse()) {
113
112
  if (response != null || responseError != null) {
114
- return promise.then(response, responseError);
113
+ promise = promise.then(response, responseError);
115
114
  }
116
- else {
117
- return promise;
118
- }
119
- }, initialPromise);
115
+ }
116
+ return promise;
120
117
  });
121
118
  };
122
119
  /**
package/lib/request.ts CHANGED
@@ -189,28 +189,28 @@ export function getRequest({
189
189
  const interceptResponseError = (responseError: errors.BalenaRequestError) =>
190
190
  interceptResponseOrError(Promise.reject(responseError));
191
191
 
192
- const interceptRequestOrError = async (initialPromise: Promise<any>) =>
193
- exports.interceptors.reduce(function (promise, { request, requestError }) {
192
+ const interceptRequestOrError = async (initialPromise: Promise<any>) => {
193
+ let promise = initialPromise;
194
+ for (const { request, requestError } of exports.interceptors) {
194
195
  if (request != null || requestError != null) {
195
- return promise.then(request, requestError);
196
- } else {
197
- return promise;
196
+ promise = promise.then(request, requestError);
198
197
  }
199
- }, initialPromise);
198
+ }
199
+ return promise;
200
+ };
200
201
 
201
202
  const interceptResponseOrError = async function (
202
203
  initialPromise: Promise<any>,
203
204
  ) {
204
- return exports.interceptors
205
+ let promise = initialPromise;
206
+ for (const { response, responseError } of exports.interceptors
205
207
  .slice()
206
- .reverse()
207
- .reduce(function (promise, { response, responseError }) {
208
- if (response != null || responseError != null) {
209
- return promise.then(response, responseError);
210
- } else {
211
- return promise;
212
- }
213
- }, initialPromise);
208
+ .reverse()) {
209
+ if (response != null || responseError != null) {
210
+ promise = promise.then(response, responseError);
211
+ }
212
+ }
213
+ return promise;
214
214
  };
215
215
 
216
216
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "balena-request",
3
- "version": "12.0.3",
3
+ "version": "12.0.4",
4
4
  "description": "Balena HTTP client",
5
5
  "main": "build/request.js",
6
6
  "types": "build/request.d.ts",
@@ -80,6 +80,6 @@
80
80
  "balena-auth": "^5.1.0"
81
81
  },
82
82
  "versionist": {
83
- "publishedAt": "2023-08-09T12:12:01.537Z"
83
+ "publishedAt": "2023-08-23T07:58:50.434Z"
84
84
  }
85
85
  }