@openfn/language-common 2.3.0 → 2.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.
package/dist/index.cjs CHANGED
@@ -200,6 +200,9 @@ var enableMockClient = (baseUrl) => {
200
200
  return client;
201
201
  };
202
202
  var assertOK = async (response, errorMap, fullUrl, method, startTime) => {
203
+ if (errorMap === false) {
204
+ return;
205
+ }
203
206
  const errMapMessage = errorMap[response.statusCode];
204
207
  const isError = typeof errMapMessage === "boolean" ? errMapMessage : errMapMessage || response.statusCode >= 400;
205
208
  if (isError) {
@@ -324,9 +327,11 @@ function encodeRequestBody(body) {
324
327
  throw new Error("Unsupported body type");
325
328
  }
326
329
  async function readResponseBody(response, parseAs) {
330
+ var _a;
331
+ const contentLength = ((_a = response.body) == null ? void 0 : _a.readableLength) ?? 0;
332
+ const contentType = response.headers["content-type"];
327
333
  try {
328
- const contentType = response.headers["content-type"];
329
- if (+response.headers["content-length"] === 0) {
334
+ if (Number.isNaN(contentLength) || contentLength === 0) {
330
335
  return void 0;
331
336
  }
332
337
  switch (parseAs) {
@@ -344,7 +349,7 @@ async function readResponseBody(response, parseAs) {
344
349
  description: "Error parsing the response body",
345
350
  parseAs,
346
351
  contentType: response.headers["content-type"],
347
- bodyLength: +response.headers["content-length"],
352
+ bodyLength: contentLength,
348
353
  error: error.message
349
354
  });
350
355
  }
package/dist/index.js CHANGED
@@ -138,6 +138,9 @@ var enableMockClient = (baseUrl) => {
138
138
  return client;
139
139
  };
140
140
  var assertOK = async (response, errorMap, fullUrl, method, startTime) => {
141
+ if (errorMap === false) {
142
+ return;
143
+ }
141
144
  const errMapMessage = errorMap[response.statusCode];
142
145
  const isError = typeof errMapMessage === "boolean" ? errMapMessage : errMapMessage || response.statusCode >= 400;
143
146
  if (isError) {
@@ -262,9 +265,11 @@ function encodeRequestBody(body) {
262
265
  throw new Error("Unsupported body type");
263
266
  }
264
267
  async function readResponseBody(response, parseAs) {
268
+ var _a;
269
+ const contentLength = ((_a = response.body) == null ? void 0 : _a.readableLength) ?? 0;
270
+ const contentType = response.headers["content-type"];
265
271
  try {
266
- const contentType = response.headers["content-type"];
267
- if (+response.headers["content-length"] === 0) {
272
+ if (Number.isNaN(contentLength) || contentLength === 0) {
268
273
  return void 0;
269
274
  }
270
275
  switch (parseAs) {
@@ -282,7 +287,7 @@ async function readResponseBody(response, parseAs) {
282
287
  description: "Error parsing the response body",
283
288
  parseAs,
284
289
  contentType: response.headers["content-type"],
285
- bodyLength: +response.headers["content-length"],
290
+ bodyLength: contentLength,
286
291
  error: error.message
287
292
  });
288
293
  }
package/dist/util.cjs CHANGED
@@ -109,6 +109,9 @@ var enableMockClient = (baseUrl) => {
109
109
  return client;
110
110
  };
111
111
  var assertOK = async (response, errorMap, fullUrl, method, startTime) => {
112
+ if (errorMap === false) {
113
+ return;
114
+ }
112
115
  const errMapMessage = errorMap[response.statusCode];
113
116
  const isError = typeof errMapMessage === "boolean" ? errMapMessage : errMapMessage || response.statusCode >= 400;
114
117
  if (isError) {
@@ -233,9 +236,11 @@ function encodeRequestBody(body) {
233
236
  throw new Error("Unsupported body type");
234
237
  }
235
238
  async function readResponseBody(response, parseAs) {
239
+ var _a;
240
+ const contentLength = ((_a = response.body) == null ? void 0 : _a.readableLength) ?? 0;
241
+ const contentType = response.headers["content-type"];
236
242
  try {
237
- const contentType = response.headers["content-type"];
238
- if (+response.headers["content-length"] === 0) {
243
+ if (Number.isNaN(contentLength) || contentLength === 0) {
239
244
  return void 0;
240
245
  }
241
246
  switch (parseAs) {
@@ -253,7 +258,7 @@ async function readResponseBody(response, parseAs) {
253
258
  description: "Error parsing the response body",
254
259
  parseAs,
255
260
  contentType: response.headers["content-type"],
256
- bodyLength: +response.headers["content-length"],
261
+ bodyLength: contentLength,
257
262
  error: error.message
258
263
  });
259
264
  }
package/dist/util.js CHANGED
@@ -60,6 +60,9 @@ var enableMockClient = (baseUrl) => {
60
60
  return client;
61
61
  };
62
62
  var assertOK = async (response, errorMap, fullUrl, method, startTime) => {
63
+ if (errorMap === false) {
64
+ return;
65
+ }
63
66
  const errMapMessage = errorMap[response.statusCode];
64
67
  const isError = typeof errMapMessage === "boolean" ? errMapMessage : errMapMessage || response.statusCode >= 400;
65
68
  if (isError) {
@@ -184,9 +187,11 @@ function encodeRequestBody(body) {
184
187
  throw new Error("Unsupported body type");
185
188
  }
186
189
  async function readResponseBody(response, parseAs) {
190
+ var _a;
191
+ const contentLength = ((_a = response.body) == null ? void 0 : _a.readableLength) ?? 0;
192
+ const contentType = response.headers["content-type"];
187
193
  try {
188
- const contentType = response.headers["content-type"];
189
- if (+response.headers["content-length"] === 0) {
194
+ if (Number.isNaN(contentLength) || contentLength === 0) {
190
195
  return void 0;
191
196
  }
192
197
  switch (parseAs) {
@@ -204,7 +209,7 @@ async function readResponseBody(response, parseAs) {
204
209
  description: "Error parsing the response body",
205
210
  parseAs,
206
211
  contentType: response.headers["content-type"],
207
- bodyLength: +response.headers["content-length"],
212
+ bodyLength: contentLength,
208
213
  error: error.message
209
214
  });
210
215
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-common",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "description": "Common Expressions for OpenFn",
5
5
  "homepage": "https://docs.openfn.org",
6
6
  "repository": {
@@ -39,12 +39,11 @@
39
39
  "csvtojson": "^2.0.10",
40
40
  "date-fns": "^2.25.0",
41
41
  "http-status-codes": "^2.3.0",
42
- "jsonpath-plus": "^10.2.0",
42
+ "jsonpath-plus": "^10.3.0",
43
43
  "lodash": "^4.17.21",
44
- "undici": "^5.28.4"
44
+ "undici": "^5.28.5"
45
45
  },
46
46
  "devDependencies": {
47
- "@openfn/simple-ast": "0.4.1",
48
47
  "chai": "4.3.6",
49
48
  "deep-eql": "4.1.1",
50
49
  "esno": "^0.16.3",
package/types/http.d.ts CHANGED
@@ -61,7 +61,7 @@ export type CommonRequestOptions = {
61
61
  /**
62
62
  * - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors.
63
63
  */
64
- errors: object;
64
+ errors: object | boolean;
65
65
  /**
66
66
  * - Pass a JSON object to be serialised into a multipart HTML form (as FormData) in the body.
67
67
  */
@@ -94,7 +94,7 @@ export type CommonHttpState = any;
94
94
  /**
95
95
  * Options provided to the HTTP request
96
96
  * @typedef {Object} CommonRequestOptions
97
- * @property {object} errors - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors.
97
+ * @property {object|boolean} errors - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors.
98
98
  * @property {object} form - Pass a JSON object to be serialised into a multipart HTML form (as FormData) in the body.
99
99
  * @property {object} query - An object of query parameters to be encoded into the URL.
100
100
  * @property {object} headers - An object of headers to append to the request.
@@ -1,2 +1,6 @@
1
- export function encode(data: string | object, options?: object): string;
2
- export function decode(base64Data: string, options?: object): string | object;
1
+ export function encode(data: string | object, options?: {
2
+ parseJson?: boolean;
3
+ }): string;
4
+ export function decode(base64Data: string, options?: {
5
+ parseJson?: boolean;
6
+ }): string | object;