@openfn/language-common 3.1.1 → 3.2.0

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/dist/index.cjs CHANGED
@@ -241,7 +241,8 @@ var getDispatcher = (origin, options2 = {}) => {
241
241
  }).compose(
242
242
  import_undici.interceptors.redirect({
243
243
  maxRedirections: agentOpts.maxRedirections
244
- })
244
+ }),
245
+ import_undici.interceptors.decompress()
245
246
  );
246
247
  agents.set(key, agent);
247
248
  }
@@ -379,7 +380,8 @@ async function request(method, fullUrlOrPath, options2 = {}) {
379
380
  timeout = 3e5,
380
381
  tls = {},
381
382
  parseAs = "auto",
382
- maxRedirections
383
+ maxRedirections,
384
+ throwOnUnhandledRedirect = true
383
385
  } = options2;
384
386
  const dispatcher = getDispatcher(baseUrl, { tls, maxRedirections });
385
387
  const queryParams = {
@@ -398,6 +400,16 @@ async function request(method, fullUrlOrPath, options2 = {}) {
398
400
  });
399
401
  const statusText = (0, import_http_status_codes.getReasonPhrase)(response.statusCode);
400
402
  await assertOK(response, errors, url, method, startTime);
403
+ const hasRedirectStatus = [300, 301, 302, 303, 304, 305, 307, 308].includes(
404
+ response.statusCode
405
+ );
406
+ if (hasRedirectStatus && maxRedirections === void 0 && throwOnUnhandledRedirect) {
407
+ throw_error_default(response.statusCode, {
408
+ statusMessage: statusText,
409
+ description: `Response has redirect status, but 'maxRedirections' is not set`,
410
+ fix: `Set 'maxRedirections' to enable auto-redirect.Example: request('GET', '${fullUrlOrPath}', { maxRedirections: 5 })`
411
+ });
412
+ }
401
413
  const responseBody = await readResponseBody(response, parseAs);
402
414
  const endTime = Date.now();
403
415
  const duration = endTime - startTime;
package/dist/index.js CHANGED
@@ -176,7 +176,8 @@ var getDispatcher = (origin, options2 = {}) => {
176
176
  }).compose(
177
177
  interceptors.redirect({
178
178
  maxRedirections: agentOpts.maxRedirections
179
- })
179
+ }),
180
+ interceptors.decompress()
180
181
  );
181
182
  agents.set(key, agent);
182
183
  }
@@ -314,7 +315,8 @@ async function request(method, fullUrlOrPath, options2 = {}) {
314
315
  timeout = 3e5,
315
316
  tls = {},
316
317
  parseAs = "auto",
317
- maxRedirections
318
+ maxRedirections,
319
+ throwOnUnhandledRedirect = true
318
320
  } = options2;
319
321
  const dispatcher = getDispatcher(baseUrl, { tls, maxRedirections });
320
322
  const queryParams = {
@@ -333,6 +335,16 @@ async function request(method, fullUrlOrPath, options2 = {}) {
333
335
  });
334
336
  const statusText = getReasonPhrase(response.statusCode);
335
337
  await assertOK(response, errors, url, method, startTime);
338
+ const hasRedirectStatus = [300, 301, 302, 303, 304, 305, 307, 308].includes(
339
+ response.statusCode
340
+ );
341
+ if (hasRedirectStatus && maxRedirections === void 0 && throwOnUnhandledRedirect) {
342
+ throw_error_default(response.statusCode, {
343
+ statusMessage: statusText,
344
+ description: `Response has redirect status, but 'maxRedirections' is not set`,
345
+ fix: `Set 'maxRedirections' to enable auto-redirect.Example: request('GET', '${fullUrlOrPath}', { maxRedirections: 5 })`
346
+ });
347
+ }
336
348
  const responseBody = await readResponseBody(response, parseAs);
337
349
  const endTime = Date.now();
338
350
  const duration = endTime - startTime;
package/dist/util.cjs CHANGED
@@ -148,7 +148,8 @@ var getDispatcher = (origin, options = {}) => {
148
148
  }).compose(
149
149
  import_undici.interceptors.redirect({
150
150
  maxRedirections: agentOpts.maxRedirections
151
- })
151
+ }),
152
+ import_undici.interceptors.decompress()
152
153
  );
153
154
  agents.set(key, agent);
154
155
  }
@@ -286,7 +287,8 @@ async function request(method, fullUrlOrPath, options = {}) {
286
287
  timeout = 3e5,
287
288
  tls = {},
288
289
  parseAs = "auto",
289
- maxRedirections
290
+ maxRedirections,
291
+ throwOnUnhandledRedirect = true
290
292
  } = options;
291
293
  const dispatcher = getDispatcher(baseUrl, { tls, maxRedirections });
292
294
  const queryParams = {
@@ -305,6 +307,16 @@ async function request(method, fullUrlOrPath, options = {}) {
305
307
  });
306
308
  const statusText = (0, import_http_status_codes.getReasonPhrase)(response.statusCode);
307
309
  await assertOK(response, errors, url, method, startTime);
310
+ const hasRedirectStatus = [300, 301, 302, 303, 304, 305, 307, 308].includes(
311
+ response.statusCode
312
+ );
313
+ if (hasRedirectStatus && maxRedirections === void 0 && throwOnUnhandledRedirect) {
314
+ throw_error_default(response.statusCode, {
315
+ statusMessage: statusText,
316
+ description: `Response has redirect status, but 'maxRedirections' is not set`,
317
+ fix: `Set 'maxRedirections' to enable auto-redirect.Example: request('GET', '${fullUrlOrPath}', { maxRedirections: 5 })`
318
+ });
319
+ }
308
320
  const responseBody = await readResponseBody(response, parseAs);
309
321
  const endTime = Date.now();
310
322
  const duration = endTime - startTime;
package/dist/util.js CHANGED
@@ -98,7 +98,8 @@ var getDispatcher = (origin, options = {}) => {
98
98
  }).compose(
99
99
  interceptors.redirect({
100
100
  maxRedirections: agentOpts.maxRedirections
101
- })
101
+ }),
102
+ interceptors.decompress()
102
103
  );
103
104
  agents.set(key, agent);
104
105
  }
@@ -236,7 +237,8 @@ async function request(method, fullUrlOrPath, options = {}) {
236
237
  timeout = 3e5,
237
238
  tls = {},
238
239
  parseAs = "auto",
239
- maxRedirections
240
+ maxRedirections,
241
+ throwOnUnhandledRedirect = true
240
242
  } = options;
241
243
  const dispatcher = getDispatcher(baseUrl, { tls, maxRedirections });
242
244
  const queryParams = {
@@ -255,6 +257,16 @@ async function request(method, fullUrlOrPath, options = {}) {
255
257
  });
256
258
  const statusText = getReasonPhrase(response.statusCode);
257
259
  await assertOK(response, errors, url, method, startTime);
260
+ const hasRedirectStatus = [300, 301, 302, 303, 304, 305, 307, 308].includes(
261
+ response.statusCode
262
+ );
263
+ if (hasRedirectStatus && maxRedirections === void 0 && throwOnUnhandledRedirect) {
264
+ throw_error_default(response.statusCode, {
265
+ statusMessage: statusText,
266
+ description: `Response has redirect status, but 'maxRedirections' is not set`,
267
+ fix: `Set 'maxRedirections' to enable auto-redirect.Example: request('GET', '${fullUrlOrPath}', { maxRedirections: 5 })`
268
+ });
269
+ }
258
270
  const responseBody = await readResponseBody(response, parseAs);
259
271
  const endTime = Date.now();
260
272
  const duration = endTime - startTime;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openfn/language-common",
3
3
  "label": "Common",
4
- "version": "3.1.1",
4
+ "version": "3.2.0",
5
5
  "description": "Common Expressions for OpenFn",
6
6
  "homepage": "https://docs.openfn.org",
7
7
  "repository": {
@@ -47,8 +47,11 @@
47
47
  "devDependencies": {
48
48
  "chai": "4.3.6",
49
49
  "deep-eql": "4.1.1",
50
+ "koa": "^3.0.3",
51
+ "koa-compress": "^5.1.1",
50
52
  "nock": "13.2.9",
51
- "rimraf": "^3.0.2"
53
+ "rimraf": "^3.0.2",
54
+ "zlib": "^1.0.5"
52
55
  },
53
56
  "main": "dist/index.cjs",
54
57
  "scripts": {