Skip to content

Add encodeFormBody utility and form data content type support #1607

Merged
josephjclark merged 22 commits intorelease/nextfrom
dagu-form
Mar 30, 2026
Merged

Add encodeFormBody utility and form data content type support #1607
josephjclark merged 22 commits intorelease/nextfrom
dagu-form

Conversation

@mtuchi
Copy link
Copy Markdown
Collaborator

@mtuchi mtuchi commented Mar 23, 2026

Summary

This pr add form data encoding support across the adaptors by adding a shared encodeFormBody utility to @openfn/language-common and use it into @openfn/language-dagu and @openfn/language-http.

Details

@openfn/language-common

  • Added encodeFormBody(data) to src/util/http.js — encodes a plain object into a FormData instance
  • Added unit tests for encodeFormBody including edge cases (null/undefined skip, Blob passthrough)

@openfn/language-dagu

  • Added contentType support to RequestOptions, enabling requests to be sent as multipart/form-data using encodeFormBody under the hood

@openfn/language-http

  • Use the shared encodeFormBody utility from@openfn/language-common for form data encoding.

AI Usage

Please disclose how you've used AI in this work (it's cool, we just want to
know!):

  • I have used Claude Code
  • I have used another model
  • I have not used AI

You can read more details in our
Responsible AI Policy

Review Checklist

Before merging, the reviewer should check the following items:

  • Does the PR do what it claims to do?
  • If this is a new adaptor, added the adaptor on marketing website ?
  • If this PR includes breaking changes, do we need to update any jobs in
    production? Is it safe to release?
  • Are there any unit tests?
  • Is there a changeset associated with this PR? Should there be? Note that
    dev only changes don't need a changeset.
  • Have you ticked a box under AI Usage?

@mtuchi
Copy link
Copy Markdown
Collaborator Author

mtuchi commented Mar 23, 2026

@PiusKariuki this should fix your problem, You will need to pass contentType: 'form' as your request option

post(
  `/Patient/Prescription/History`,
  {
    start: 0,
    length: -1,
    draw: 1,
    additionalParameters: {
      filter: [
        { fieldName: 'prescriberName', operator: 'Eq', value: 'Dr Super User' },
      ],
    },
  },
  {
    contentType: 'form',
  },
)

@mtuchi mtuchi self-assigned this Mar 25, 2026
@mtuchi mtuchi changed the title Support form content type in dagu Add encodeFormBody utility and form data content type support Mar 26, 2026
@mtuchi mtuchi requested a review from josephjclark March 26, 2026 15:12
@mtuchi
Copy link
Copy Markdown
Collaborator Author

mtuchi commented Mar 26, 2026

SurveyCTO have it's own version of encodeFormBody, Technically the new version of encodeFormBody from common should replace this function, but there are not enough unit test or integration test to do the swap. will discuss with joe next steps for surveyCTO if the pr is approved

Copy link
Copy Markdown
Collaborator

@josephjclark josephjclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The blob stuff makes me nervous. I can see how we're trying to make it easy to encode form data but I don't actually think it's working 🤔

Let's make the form encoding super simple. Just pass blobs through. You'll probably need to stringify objects, otherwise just ensure strings

To enable files and binaries we need a helper function like createBlob(data, type, filename). This will have to return some kind of wrapped object (maybe a class instance) which the encoder knows how to handle

@mtuchi
Copy link
Copy Markdown
Collaborator Author

mtuchi commented Mar 30, 2026

Hiya @josephjclark , i have removed the blob stuff and open a ticket for adding createBlob in common/util

@mtuchi mtuchi requested a review from josephjclark March 30, 2026 12:04
@mtuchi
Copy link
Copy Markdown
Collaborator Author

mtuchi commented Mar 30, 2026

Hiya @josephjclark , i have removed the mode option from encodeFormBody. Now you can just use encodeFormBody(data). But i am still supporting Blob and File which will be appended as-is.

The idea is, User should still be able to pass a Blob or File as-is

const blob = new Blob([ArrayBuffer], { type: "image/png" )
encodeFormBody({blob})

what do you think of this approach ?

* http:rewrite integration tests to ues koa

* add tests of posting formdata

* add a skipped test

* add test showing current behaviour
@josephjclark josephjclark changed the base branch from main to release/next March 30, 2026 15:42
@josephjclark josephjclark merged commit 295655f into release/next Mar 30, 2026
3 checks passed
@josephjclark josephjclark deleted the dagu-form branch March 30, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

3 participants