@openfn/language-common
Advanced tools
+18
-1
@@ -129,2 +129,3 @@ var __create = Object.create; | ||
| encode: () => encode, | ||
| encodeFormBody: () => encodeFormBody, | ||
| expandReferences: () => expandReferences, | ||
@@ -431,2 +432,18 @@ generateAgentKey: () => generateAgentKey, | ||
| } | ||
| function encodeFormBody(data) { | ||
| const form = new import_undici.FormData(); | ||
| for (const [key, value] of Object.entries(data)) { | ||
| if (value === null || value === void 0) | ||
| continue; | ||
| if (value instanceof Blob || value instanceof File) { | ||
| form.append(key, value); | ||
| } else { | ||
| form.append( | ||
| key, | ||
| typeof value === "object" ? JSON.stringify(value) : String(value) | ||
| ); | ||
| } | ||
| } | ||
| return form; | ||
| } | ||
| function encodeRequestBody(body) { | ||
@@ -440,3 +457,3 @@ if (!body) { | ||
| if (typeof body === "object") { | ||
| if (Symbol.asyncIterator in Object(body) || Symbol.iterator in Object(body) || body instanceof FormData) { | ||
| if (Symbol.asyncIterator in Object(body) || Symbol.iterator in Object(body) || body instanceof import_undici.FormData) { | ||
| return body; | ||
@@ -443,0 +460,0 @@ } |
+18
-1
@@ -64,2 +64,3 @@ var __defProp = Object.defineProperty; | ||
| encode: () => encode, | ||
| encodeFormBody: () => encodeFormBody, | ||
| expandReferences: () => expandReferences, | ||
@@ -129,3 +130,3 @@ generateAgentKey: () => generateAgentKey, | ||
| // src/util/http.js | ||
| import { MockAgent, Agent, interceptors } from "undici"; | ||
| import { MockAgent, Agent, interceptors, FormData } from "undici"; | ||
| import _2 from "lodash"; | ||
@@ -367,2 +368,18 @@ var agents = /* @__PURE__ */ new Map(); | ||
| } | ||
| function encodeFormBody(data) { | ||
| const form = new FormData(); | ||
| for (const [key, value] of Object.entries(data)) { | ||
| if (value === null || value === void 0) | ||
| continue; | ||
| if (value instanceof Blob || value instanceof File) { | ||
| form.append(key, value); | ||
| } else { | ||
| form.append( | ||
| key, | ||
| typeof value === "object" ? JSON.stringify(value) : String(value) | ||
| ); | ||
| } | ||
| } | ||
| return form; | ||
| } | ||
| function encodeRequestBody(body) { | ||
@@ -369,0 +386,0 @@ if (!body) { |
+19
-1
@@ -35,2 +35,3 @@ var __create = Object.create; | ||
| encode: () => encode, | ||
| encodeFormBody: () => encodeFormBody, | ||
| expandReferences: () => expandReferences, | ||
@@ -338,2 +339,18 @@ generateAgentKey: () => generateAgentKey, | ||
| } | ||
| function encodeFormBody(data) { | ||
| const form = new import_undici.FormData(); | ||
| for (const [key, value] of Object.entries(data)) { | ||
| if (value === null || value === void 0) | ||
| continue; | ||
| if (value instanceof Blob || value instanceof File) { | ||
| form.append(key, value); | ||
| } else { | ||
| form.append( | ||
| key, | ||
| typeof value === "object" ? JSON.stringify(value) : String(value) | ||
| ); | ||
| } | ||
| } | ||
| return form; | ||
| } | ||
| function encodeRequestBody(body) { | ||
@@ -347,3 +364,3 @@ if (!body) { | ||
| if (typeof body === "object") { | ||
| if (Symbol.asyncIterator in Object(body) || Symbol.iterator in Object(body) || body instanceof FormData) { | ||
| if (Symbol.asyncIterator in Object(body) || Symbol.iterator in Object(body) || body instanceof import_undici.FormData) { | ||
| return body; | ||
@@ -482,2 +499,3 @@ } | ||
| encode, | ||
| encodeFormBody, | ||
| expandReferences, | ||
@@ -484,0 +502,0 @@ generateAgentKey, |
+18
-1
@@ -50,3 +50,3 @@ // src/util/http.js | ||
| // src/util/http.js | ||
| import { MockAgent, Agent, interceptors } from "undici"; | ||
| import { MockAgent, Agent, interceptors, FormData } from "undici"; | ||
| import _2 from "lodash"; | ||
@@ -288,2 +288,18 @@ var agents = /* @__PURE__ */ new Map(); | ||
| } | ||
| function encodeFormBody(data) { | ||
| const form = new FormData(); | ||
| for (const [key, value] of Object.entries(data)) { | ||
| if (value === null || value === void 0) | ||
| continue; | ||
| if (value instanceof Blob || value instanceof File) { | ||
| form.append(key, value); | ||
| } else { | ||
| form.append( | ||
| key, | ||
| typeof value === "object" ? JSON.stringify(value) : String(value) | ||
| ); | ||
| } | ||
| } | ||
| return form; | ||
| } | ||
| function encodeRequestBody(body) { | ||
@@ -430,2 +446,3 @@ if (!body) { | ||
| encode, | ||
| encodeFormBody, | ||
| expandReferences, | ||
@@ -432,0 +449,0 @@ generateAgentKey, |
+2
-2
| { | ||
| "name": "@openfn/language-common", | ||
| "label": "Common", | ||
| "version": "3.2.3", | ||
| "version": "3.3.0", | ||
| "description": "Common Expressions for OpenFn", | ||
@@ -50,3 +50,3 @@ "homepage": "https://docs.openfn.org", | ||
| "deep-eql": "4.1.1", | ||
| "koa": "^3.0.3", | ||
| "koa": "^3.1.2", | ||
| "koa-compress": "^5.1.1", | ||
@@ -53,0 +53,0 @@ "nock": "13.2.9", |
+13
-0
@@ -27,2 +27,14 @@ /** | ||
| }>; | ||
| /** | ||
| * Encodes a plain object into a `FormData` instance. | ||
| * | ||
| * - Primitives are converted to strings | ||
| * - Objects and arrays are JSON stringified | ||
| * - `Blob` and `File` values are appended as-is | ||
| * - Null and undefined values are skipped | ||
| * | ||
| * @param {Object} data - The object to encode | ||
| * @returns {FormData} | ||
| */ | ||
| export function encodeFormBody(data: any): FormData; | ||
| export function makeBasicAuthHeader(username: any, password: any): { | ||
@@ -79,1 +91,2 @@ Authorization: string; | ||
| }>; | ||
| import { FormData } from "undici/types/formdata.js"; |
222837
1.06%5842
1.42%