@openfn/language-common 2.2.0 → 2.2.1

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
@@ -142,6 +142,25 @@ var import_http_status_codes = require("http-status-codes");
142
142
  var import_node_stream = require("stream");
143
143
  var import_node_querystring = __toESM(require("querystring"), 1);
144
144
  var import_node_path = __toESM(require("path"), 1);
145
+
146
+ // src/util/throw-error.js
147
+ var throw_error_default = (code, { description, fix, ...extras } = {}) => {
148
+ const message = description ? `${code}: ${description}` : code;
149
+ const e = new Error(message);
150
+ e.code = code;
151
+ if (description) {
152
+ e.description = description;
153
+ }
154
+ if (fix) {
155
+ e.fix = fix;
156
+ }
157
+ for (const key in extras) {
158
+ e[key] = extras[key];
159
+ }
160
+ throw e;
161
+ };
162
+
163
+ // src/util/http.js
145
164
  var clients = /* @__PURE__ */ new Map();
146
165
  var makeBasicAuthHeader = (username, password) => {
147
166
  const buff = Buffer.from(`${username}:${password}`);
@@ -303,16 +322,29 @@ function encodeRequestBody(body) {
303
322
  throw new Error("Unsupported body type");
304
323
  }
305
324
  async function readResponseBody(response, parseAs) {
306
- const contentType = response.headers["content-type"];
307
- switch (parseAs) {
308
- case "json":
309
- return response.body.json();
310
- case "text":
311
- return response.body.text();
312
- case "stream":
313
- return response.body;
314
- default:
315
- return contentType && contentType.includes("application/json") ? response.body.json() : response.body.text();
325
+ try {
326
+ const contentType = response.headers["content-type"];
327
+ if (+response.headers["content-length"] === 0) {
328
+ return void 0;
329
+ }
330
+ switch (parseAs) {
331
+ case "json":
332
+ return await response.body.json();
333
+ case "text":
334
+ return response.body.text();
335
+ case "stream":
336
+ return response.body;
337
+ default:
338
+ return contentType && contentType.includes("application/json") ? await response.body.json() : response.body.text();
339
+ }
340
+ } catch (error) {
341
+ throw_error_default(response.statusCode, {
342
+ description: "Error parsing the response body",
343
+ parseAs,
344
+ contentType: response.headers["content-type"],
345
+ bodyLength: +response.headers["content-length"],
346
+ error: error.message
347
+ });
316
348
  }
317
349
  }
318
350
  var get = (url, options2) => request("GET", url, options2);
@@ -396,23 +428,6 @@ var parse_date_default = (d, startDate) => {
396
428
  return d;
397
429
  };
398
430
 
399
- // src/util/throw-error.js
400
- var throw_error_default = (code, { description, fix, ...extras } = {}) => {
401
- const message = description ? `${code}: ${description}` : code;
402
- const e = new Error(message);
403
- e.code = code;
404
- if (description) {
405
- e.description = description;
406
- }
407
- if (fix) {
408
- e.fix = fix;
409
- }
410
- for (const key in extras) {
411
- e[key] = extras[key];
412
- }
413
- throw e;
414
- };
415
-
416
431
  // src/util/base64.js
417
432
  var encode = (data) => Buffer.from(data, "utf-8").toString("base64");
418
433
  var decode = (base64Data) => Buffer.from(base64Data, "base64").toString("utf-8");
package/dist/index.js CHANGED
@@ -81,6 +81,25 @@ import { getReasonPhrase } from "http-status-codes";
81
81
  import { Readable } from "stream";
82
82
  import querystring from "querystring";
83
83
  import path from "path";
84
+
85
+ // src/util/throw-error.js
86
+ var throw_error_default = (code, { description, fix, ...extras } = {}) => {
87
+ const message = description ? `${code}: ${description}` : code;
88
+ const e = new Error(message);
89
+ e.code = code;
90
+ if (description) {
91
+ e.description = description;
92
+ }
93
+ if (fix) {
94
+ e.fix = fix;
95
+ }
96
+ for (const key in extras) {
97
+ e[key] = extras[key];
98
+ }
99
+ throw e;
100
+ };
101
+
102
+ // src/util/http.js
84
103
  var clients = /* @__PURE__ */ new Map();
85
104
  var makeBasicAuthHeader = (username, password) => {
86
105
  const buff = Buffer.from(`${username}:${password}`);
@@ -242,16 +261,29 @@ function encodeRequestBody(body) {
242
261
  throw new Error("Unsupported body type");
243
262
  }
244
263
  async function readResponseBody(response, parseAs) {
245
- const contentType = response.headers["content-type"];
246
- switch (parseAs) {
247
- case "json":
248
- return response.body.json();
249
- case "text":
250
- return response.body.text();
251
- case "stream":
252
- return response.body;
253
- default:
254
- return contentType && contentType.includes("application/json") ? response.body.json() : response.body.text();
264
+ try {
265
+ const contentType = response.headers["content-type"];
266
+ if (+response.headers["content-length"] === 0) {
267
+ return void 0;
268
+ }
269
+ switch (parseAs) {
270
+ case "json":
271
+ return await response.body.json();
272
+ case "text":
273
+ return response.body.text();
274
+ case "stream":
275
+ return response.body;
276
+ default:
277
+ return contentType && contentType.includes("application/json") ? await response.body.json() : response.body.text();
278
+ }
279
+ } catch (error) {
280
+ throw_error_default(response.statusCode, {
281
+ description: "Error parsing the response body",
282
+ parseAs,
283
+ contentType: response.headers["content-type"],
284
+ bodyLength: +response.headers["content-length"],
285
+ error: error.message
286
+ });
255
287
  }
256
288
  }
257
289
  var get = (url, options2) => request("GET", url, options2);
@@ -335,23 +367,6 @@ var parse_date_default = (d, startDate) => {
335
367
  return d;
336
368
  };
337
369
 
338
- // src/util/throw-error.js
339
- var throw_error_default = (code, { description, fix, ...extras } = {}) => {
340
- const message = description ? `${code}: ${description}` : code;
341
- const e = new Error(message);
342
- e.code = code;
343
- if (description) {
344
- e.description = description;
345
- }
346
- if (fix) {
347
- e.fix = fix;
348
- }
349
- for (const key in extras) {
350
- e[key] = extras[key];
351
- }
352
- throw e;
353
- };
354
-
355
370
  // src/util/base64.js
356
371
  var encode = (data) => Buffer.from(data, "utf-8").toString("base64");
357
372
  var decode = (base64Data) => Buffer.from(base64Data, "base64").toString("utf-8");
package/dist/util.cjs CHANGED
@@ -53,6 +53,25 @@ var import_http_status_codes = require("http-status-codes");
53
53
  var import_node_stream = require("stream");
54
54
  var import_node_querystring = __toESM(require("querystring"), 1);
55
55
  var import_node_path = __toESM(require("path"), 1);
56
+
57
+ // src/util/throw-error.js
58
+ var throw_error_default = (code, { description, fix, ...extras } = {}) => {
59
+ const message = description ? `${code}: ${description}` : code;
60
+ const e = new Error(message);
61
+ e.code = code;
62
+ if (description) {
63
+ e.description = description;
64
+ }
65
+ if (fix) {
66
+ e.fix = fix;
67
+ }
68
+ for (const key in extras) {
69
+ e[key] = extras[key];
70
+ }
71
+ throw e;
72
+ };
73
+
74
+ // src/util/http.js
56
75
  var clients = /* @__PURE__ */ new Map();
57
76
  var makeBasicAuthHeader = (username, password) => {
58
77
  const buff = Buffer.from(`${username}:${password}`);
@@ -214,16 +233,29 @@ function encodeRequestBody(body) {
214
233
  throw new Error("Unsupported body type");
215
234
  }
216
235
  async function readResponseBody(response, parseAs) {
217
- const contentType = response.headers["content-type"];
218
- switch (parseAs) {
219
- case "json":
220
- return response.body.json();
221
- case "text":
222
- return response.body.text();
223
- case "stream":
224
- return response.body;
225
- default:
226
- return contentType && contentType.includes("application/json") ? response.body.json() : response.body.text();
236
+ try {
237
+ const contentType = response.headers["content-type"];
238
+ if (+response.headers["content-length"] === 0) {
239
+ return void 0;
240
+ }
241
+ switch (parseAs) {
242
+ case "json":
243
+ return await response.body.json();
244
+ case "text":
245
+ return response.body.text();
246
+ case "stream":
247
+ return response.body;
248
+ default:
249
+ return contentType && contentType.includes("application/json") ? await response.body.json() : response.body.text();
250
+ }
251
+ } catch (error) {
252
+ throw_error_default(response.statusCode, {
253
+ description: "Error parsing the response body",
254
+ parseAs,
255
+ contentType: response.headers["content-type"],
256
+ bodyLength: +response.headers["content-length"],
257
+ error: error.message
258
+ });
227
259
  }
228
260
  }
229
261
  var get = (url, options) => request("GET", url, options);
@@ -307,23 +339,6 @@ var parse_date_default = (d, startDate) => {
307
339
  return d;
308
340
  };
309
341
 
310
- // src/util/throw-error.js
311
- var throw_error_default = (code, { description, fix, ...extras } = {}) => {
312
- const message = description ? `${code}: ${description}` : code;
313
- const e = new Error(message);
314
- e.code = code;
315
- if (description) {
316
- e.description = description;
317
- }
318
- if (fix) {
319
- e.fix = fix;
320
- }
321
- for (const key in extras) {
322
- e[key] = extras[key];
323
- }
324
- throw e;
325
- };
326
-
327
342
  // src/util/base64.js
328
343
  var encode = (data) => Buffer.from(data, "utf-8").toString("base64");
329
344
  var decode = (base64Data) => Buffer.from(base64Data, "base64").toString("utf-8");
package/dist/util.js CHANGED
@@ -4,6 +4,25 @@ import { getReasonPhrase } from "http-status-codes";
4
4
  import { Readable } from "stream";
5
5
  import querystring from "querystring";
6
6
  import path from "path";
7
+
8
+ // src/util/throw-error.js
9
+ var throw_error_default = (code, { description, fix, ...extras } = {}) => {
10
+ const message = description ? `${code}: ${description}` : code;
11
+ const e = new Error(message);
12
+ e.code = code;
13
+ if (description) {
14
+ e.description = description;
15
+ }
16
+ if (fix) {
17
+ e.fix = fix;
18
+ }
19
+ for (const key in extras) {
20
+ e[key] = extras[key];
21
+ }
22
+ throw e;
23
+ };
24
+
25
+ // src/util/http.js
7
26
  var clients = /* @__PURE__ */ new Map();
8
27
  var makeBasicAuthHeader = (username, password) => {
9
28
  const buff = Buffer.from(`${username}:${password}`);
@@ -165,16 +184,29 @@ function encodeRequestBody(body) {
165
184
  throw new Error("Unsupported body type");
166
185
  }
167
186
  async function readResponseBody(response, parseAs) {
168
- const contentType = response.headers["content-type"];
169
- switch (parseAs) {
170
- case "json":
171
- return response.body.json();
172
- case "text":
173
- return response.body.text();
174
- case "stream":
175
- return response.body;
176
- default:
177
- return contentType && contentType.includes("application/json") ? response.body.json() : response.body.text();
187
+ try {
188
+ const contentType = response.headers["content-type"];
189
+ if (+response.headers["content-length"] === 0) {
190
+ return void 0;
191
+ }
192
+ switch (parseAs) {
193
+ case "json":
194
+ return await response.body.json();
195
+ case "text":
196
+ return response.body.text();
197
+ case "stream":
198
+ return response.body;
199
+ default:
200
+ return contentType && contentType.includes("application/json") ? await response.body.json() : response.body.text();
201
+ }
202
+ } catch (error) {
203
+ throw_error_default(response.statusCode, {
204
+ description: "Error parsing the response body",
205
+ parseAs,
206
+ contentType: response.headers["content-type"],
207
+ bodyLength: +response.headers["content-length"],
208
+ error: error.message
209
+ });
178
210
  }
179
211
  }
180
212
  var get = (url, options) => request("GET", url, options);
@@ -258,23 +290,6 @@ var parse_date_default = (d, startDate) => {
258
290
  return d;
259
291
  };
260
292
 
261
- // src/util/throw-error.js
262
- var throw_error_default = (code, { description, fix, ...extras } = {}) => {
263
- const message = description ? `${code}: ${description}` : code;
264
- const e = new Error(message);
265
- e.code = code;
266
- if (description) {
267
- e.description = description;
268
- }
269
- if (fix) {
270
- e.fix = fix;
271
- }
272
- for (const key in extras) {
273
- e[key] = extras[key];
274
- }
275
- throw e;
276
- };
277
-
278
293
  // src/util/base64.js
279
294
  var encode = (data) => Buffer.from(data, "utf-8").toString("base64");
280
295
  var decode = (base64Data) => Buffer.from(base64Data, "base64").toString("utf-8");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-common",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "Common Expressions for OpenFn",
5
5
  "homepage": "https://docs.openfn.org",
6
6
  "repository": {