@openfn/language-dagu 1.1.2 → 1.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/ast.json CHANGED
@@ -70,7 +70,13 @@
70
70
  "tags": [
71
71
  {
72
72
  "title": "example",
73
- "description": "post(\"Patient/CheckPrescription\", { \"prescriptionRowGuid\": \"3fa85f64-5717-4562-b3fc-2c963f66afa6\" });"
73
+ "description": "post(\"Patient/CheckPrescription\", { \"prescriptionRowGuid\": \"3fa85f64-5717-4562-b3fc-2c963f66afa6\" });",
74
+ "caption": "Post JSON body"
75
+ },
76
+ {
77
+ "title": "example",
78
+ "description": "post(\"Patient/Prescription/History\", { start: 0, length: 10, draw: 1, additionalParameters: { filter: [] } }, { contentType: \"form\" });",
79
+ "caption": "Post as form data"
74
80
  },
75
81
  {
76
82
  "title": "function",
package/dist/index.cjs CHANGED
@@ -112,18 +112,22 @@ var request = async (configuration = {}, method, path, options) => {
112
112
  const { baseUrl } = configuration;
113
113
  if (!access_token)
114
114
  access_token = await getAccessToken(configuration, options.headers);
115
- const { query = {}, body = {} } = options;
115
+ const { query = {}, body = {}, contentType, headers = {} } = options;
116
+ let requestBody = body;
117
+ let requestHeaders = { ...headers };
118
+ if (contentType === "form") {
119
+ requestBody = (0, import_util.encodeFormBody)(body);
120
+ } else {
121
+ requestHeaders["content-type"] = "application/json";
122
+ }
123
+ requestHeaders["Authorization"] = `Bearer ${access_token}`;
116
124
  const opts = {
125
+ ...options,
117
126
  parseAs: "json",
118
127
  baseUrl,
119
- headers: {
120
- "content-type": "application/json",
121
- Authorization: `Bearer ${access_token}`,
122
- ...options.headers
123
- },
124
- body,
125
- query,
126
- ...options
128
+ headers: requestHeaders,
129
+ body: requestBody,
130
+ query
127
131
  };
128
132
  const safePath = import_node_path.default.join(path);
129
133
  return (0, import_util.request)(method, safePath, opts).then(import_util.logResponse);
package/dist/index.js CHANGED
@@ -35,7 +35,8 @@ import { expandReferences } from "@openfn/language-common/util";
35
35
  import { composeNextState } from "@openfn/language-common";
36
36
  import {
37
37
  request as commonRequest,
38
- logResponse
38
+ logResponse,
39
+ encodeFormBody
39
40
  } from "@openfn/language-common/util";
40
41
  import nodepath from "path";
41
42
  var access_token;
@@ -69,18 +70,22 @@ var request = async (configuration = {}, method, path, options) => {
69
70
  const { baseUrl } = configuration;
70
71
  if (!access_token)
71
72
  access_token = await getAccessToken(configuration, options.headers);
72
- const { query = {}, body = {} } = options;
73
+ const { query = {}, body = {}, contentType, headers = {} } = options;
74
+ let requestBody = body;
75
+ let requestHeaders = { ...headers };
76
+ if (contentType === "form") {
77
+ requestBody = encodeFormBody(body);
78
+ } else {
79
+ requestHeaders["content-type"] = "application/json";
80
+ }
81
+ requestHeaders["Authorization"] = `Bearer ${access_token}`;
73
82
  const opts = {
83
+ ...options,
74
84
  parseAs: "json",
75
85
  baseUrl,
76
- headers: {
77
- "content-type": "application/json",
78
- Authorization: `Bearer ${access_token}`,
79
- ...options.headers
80
- },
81
- body,
82
- query,
83
- ...options
86
+ headers: requestHeaders,
87
+ body: requestBody,
88
+ query
84
89
  };
85
90
  const safePath = nodepath.join(path);
86
91
  return commonRequest(method, safePath, opts).then(logResponse);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-dagu",
3
- "version": "1.1.2",
3
+ "version": "1.2.1",
4
4
  "description": "OpenFn dagu adaptor",
5
5
  "type": "module",
6
6
  "exports": {
@@ -20,7 +20,7 @@
20
20
  "configuration-schema.json"
21
21
  ],
22
22
  "dependencies": {
23
- "@openfn/language-common": "3.2.3"
23
+ "@openfn/language-common": "3.3.1"
24
24
  },
25
25
  "devDependencies": {
26
26
  "assertion-error": "2.0.0",
@@ -28,7 +28,7 @@
28
28
  "deep-eql": "4.1.1",
29
29
  "mocha": "^10.7.3",
30
30
  "rimraf": "3.0.2",
31
- "undici": "^7.19.2"
31
+ "undici": "^7.24.7"
32
32
  },
33
33
  "repository": {
34
34
  "type": "git",
@@ -10,8 +10,8 @@
10
10
  * @typedef {Object} RequestOptions
11
11
  * @public
12
12
  * @property {object|string} body - body data to append to the request. JSON will be converted to a string (but a content-type header will not be attached to the request).
13
+ * @property {string} contentType - Set to `'form'` to send the body as multipart FormData instead of JSON. The `content-type` header will be set automatically (including the multipart boundary).
13
14
  * @property {object} errors - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors for this code.
14
- * @property {object} form - Pass a JSON object to be serialised into a multipart HTML form (as FormData) in the body.
15
15
  * @property {object} query - An object of query parameters to be encoded into the URL.
16
16
  * @property {object} headers - An object of headers to append to the request.
17
17
  * @property {string} parseAs - Parse the response body as json, text or stream. By default will use the response headers.
@@ -32,8 +32,10 @@
32
32
  export function get(path: string, options: RequestOptions): Operation;
33
33
  /**
34
34
  * Make a POST request
35
- * @example
35
+ * @example <caption>Post JSON body</caption>
36
36
  * post("Patient/CheckPrescription", { "prescriptionRowGuid": "3fa85f64-5717-4562-b3fc-2c963f66afa6" });
37
+ * @example <caption>Post as form data</caption>
38
+ * post("Patient/Prescription/History", { start: 0, length: 10, draw: 1, additionalParameters: { filter: [] } }, { contentType: "form" });
37
39
  * @function
38
40
  * @public
39
41
  * @param {string} path - Path to resource