@openfn/language-common 2.4.0 → 2.5.0

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
@@ -198,8 +198,8 @@ var makeBasicAuthHeader = (username, password) => {
198
198
  const credentials = buff.toString("base64");
199
199
  return { Authorization: `Basic ${credentials}` };
200
200
  };
201
- var logResponse = (response, query = {}) => {
202
- const { method, url, statusCode, duration } = response;
201
+ var logResponse = (response) => {
202
+ const { method, url, statusCode, duration, query } = response;
203
203
  if (method && url && duration && statusCode) {
204
204
  const urlWithQuery = Object.keys(query || {}).length ? `${url}?${new URLSearchParams(query).toString()}` : url;
205
205
  const message = `${method} ${urlWithQuery} - ${statusCode} in ${duration}ms`;
@@ -311,12 +311,13 @@ async function request(method, fullUrlOrPath, options2 = {}) {
311
311
  maxRedirections
312
312
  } = options2;
313
313
  const client = getClient(baseUrl, { tls });
314
+ const queryParams = {
315
+ ...optionQuery,
316
+ ...urlQuery
317
+ };
314
318
  const response = await client.request({
315
319
  path: path2,
316
- query: {
317
- ...optionQuery,
318
- ...urlQuery
319
- },
320
+ query: queryParams,
320
321
  method,
321
322
  headers,
322
323
  body: encodeRequestBody(body),
@@ -331,7 +332,7 @@ async function request(method, fullUrlOrPath, options2 = {}) {
331
332
  const responseBody = await readResponseBody(response, parseAs);
332
333
  const endTime = Date.now();
333
334
  const duration = endTime - startTime;
334
- return {
335
+ const requestResponse = {
335
336
  url,
336
337
  method,
337
338
  statusCode: response.statusCode,
@@ -340,6 +341,10 @@ async function request(method, fullUrlOrPath, options2 = {}) {
340
341
  body: responseBody,
341
342
  duration
342
343
  };
344
+ if (Object.keys(queryParams).length > 0) {
345
+ requestResponse.query = queryParams;
346
+ }
347
+ return requestResponse;
343
348
  }
344
349
  function encodeRequestBody(body) {
345
350
  if (!body) {
@@ -979,8 +984,8 @@ var req = function(method, url, options2) {
979
984
  function get3(url, options2) {
980
985
  return req("GET", url, options2);
981
986
  }
982
- function post2(path2, data, options2) {
983
- return req("POST", path2, { body: data, ...options2 });
987
+ function post2(url, data, options2) {
988
+ return req("POST", url, { body: data, ...options2 });
984
989
  }
985
990
 
986
991
  // src/dateFns.js
package/dist/index.js CHANGED
@@ -134,8 +134,8 @@ var makeBasicAuthHeader = (username, password) => {
134
134
  const credentials = buff.toString("base64");
135
135
  return { Authorization: `Basic ${credentials}` };
136
136
  };
137
- var logResponse = (response, query = {}) => {
138
- const { method, url, statusCode, duration } = response;
137
+ var logResponse = (response) => {
138
+ const { method, url, statusCode, duration, query } = response;
139
139
  if (method && url && duration && statusCode) {
140
140
  const urlWithQuery = Object.keys(query || {}).length ? `${url}?${new URLSearchParams(query).toString()}` : url;
141
141
  const message = `${method} ${urlWithQuery} - ${statusCode} in ${duration}ms`;
@@ -247,12 +247,13 @@ async function request(method, fullUrlOrPath, options2 = {}) {
247
247
  maxRedirections
248
248
  } = options2;
249
249
  const client = getClient(baseUrl, { tls });
250
+ const queryParams = {
251
+ ...optionQuery,
252
+ ...urlQuery
253
+ };
250
254
  const response = await client.request({
251
255
  path: path2,
252
- query: {
253
- ...optionQuery,
254
- ...urlQuery
255
- },
256
+ query: queryParams,
256
257
  method,
257
258
  headers,
258
259
  body: encodeRequestBody(body),
@@ -267,7 +268,7 @@ async function request(method, fullUrlOrPath, options2 = {}) {
267
268
  const responseBody = await readResponseBody(response, parseAs);
268
269
  const endTime = Date.now();
269
270
  const duration = endTime - startTime;
270
- return {
271
+ const requestResponse = {
271
272
  url,
272
273
  method,
273
274
  statusCode: response.statusCode,
@@ -276,6 +277,10 @@ async function request(method, fullUrlOrPath, options2 = {}) {
276
277
  body: responseBody,
277
278
  duration
278
279
  };
280
+ if (Object.keys(queryParams).length > 0) {
281
+ requestResponse.query = queryParams;
282
+ }
283
+ return requestResponse;
279
284
  }
280
285
  function encodeRequestBody(body) {
281
286
  if (!body) {
@@ -915,8 +920,8 @@ var req = function(method, url, options2) {
915
920
  function get3(url, options2) {
916
921
  return req("GET", url, options2);
917
922
  }
918
- function post2(path2, data, options2) {
919
- return req("POST", path2, { body: data, ...options2 });
923
+ function post2(url, data, options2) {
924
+ return req("POST", url, { body: data, ...options2 });
920
925
  }
921
926
 
922
927
  // src/dateFns.js
package/dist/util.cjs CHANGED
@@ -103,8 +103,8 @@ var makeBasicAuthHeader = (username, password) => {
103
103
  const credentials = buff.toString("base64");
104
104
  return { Authorization: `Basic ${credentials}` };
105
105
  };
106
- var logResponse = (response, query = {}) => {
107
- const { method, url, statusCode, duration } = response;
106
+ var logResponse = (response) => {
107
+ const { method, url, statusCode, duration, query } = response;
108
108
  if (method && url && duration && statusCode) {
109
109
  const urlWithQuery = Object.keys(query || {}).length ? `${url}?${new URLSearchParams(query).toString()}` : url;
110
110
  const message = `${method} ${urlWithQuery} - ${statusCode} in ${duration}ms`;
@@ -216,12 +216,13 @@ async function request(method, fullUrlOrPath, options = {}) {
216
216
  maxRedirections
217
217
  } = options;
218
218
  const client = getClient(baseUrl, { tls });
219
+ const queryParams = {
220
+ ...optionQuery,
221
+ ...urlQuery
222
+ };
219
223
  const response = await client.request({
220
224
  path: path2,
221
- query: {
222
- ...optionQuery,
223
- ...urlQuery
224
- },
225
+ query: queryParams,
225
226
  method,
226
227
  headers,
227
228
  body: encodeRequestBody(body),
@@ -236,7 +237,7 @@ async function request(method, fullUrlOrPath, options = {}) {
236
237
  const responseBody = await readResponseBody(response, parseAs);
237
238
  const endTime = Date.now();
238
239
  const duration = endTime - startTime;
239
- return {
240
+ const requestResponse = {
240
241
  url,
241
242
  method,
242
243
  statusCode: response.statusCode,
@@ -245,6 +246,10 @@ async function request(method, fullUrlOrPath, options = {}) {
245
246
  body: responseBody,
246
247
  duration
247
248
  };
249
+ if (Object.keys(queryParams).length > 0) {
250
+ requestResponse.query = queryParams;
251
+ }
252
+ return requestResponse;
248
253
  }
249
254
  function encodeRequestBody(body) {
250
255
  if (!body) {
package/dist/util.js CHANGED
@@ -54,8 +54,8 @@ var makeBasicAuthHeader = (username, password) => {
54
54
  const credentials = buff.toString("base64");
55
55
  return { Authorization: `Basic ${credentials}` };
56
56
  };
57
- var logResponse = (response, query = {}) => {
58
- const { method, url, statusCode, duration } = response;
57
+ var logResponse = (response) => {
58
+ const { method, url, statusCode, duration, query } = response;
59
59
  if (method && url && duration && statusCode) {
60
60
  const urlWithQuery = Object.keys(query || {}).length ? `${url}?${new URLSearchParams(query).toString()}` : url;
61
61
  const message = `${method} ${urlWithQuery} - ${statusCode} in ${duration}ms`;
@@ -167,12 +167,13 @@ async function request(method, fullUrlOrPath, options = {}) {
167
167
  maxRedirections
168
168
  } = options;
169
169
  const client = getClient(baseUrl, { tls });
170
+ const queryParams = {
171
+ ...optionQuery,
172
+ ...urlQuery
173
+ };
170
174
  const response = await client.request({
171
175
  path: path2,
172
- query: {
173
- ...optionQuery,
174
- ...urlQuery
175
- },
176
+ query: queryParams,
176
177
  method,
177
178
  headers,
178
179
  body: encodeRequestBody(body),
@@ -187,7 +188,7 @@ async function request(method, fullUrlOrPath, options = {}) {
187
188
  const responseBody = await readResponseBody(response, parseAs);
188
189
  const endTime = Date.now();
189
190
  const duration = endTime - startTime;
190
- return {
191
+ const requestResponse = {
191
192
  url,
192
193
  method,
193
194
  statusCode: response.statusCode,
@@ -196,6 +197,10 @@ async function request(method, fullUrlOrPath, options = {}) {
196
197
  body: responseBody,
197
198
  duration
198
199
  };
200
+ if (Object.keys(queryParams).length > 0) {
201
+ requestResponse.query = queryParams;
202
+ }
203
+ return requestResponse;
199
204
  }
200
205
  function encodeRequestBody(body) {
201
206
  if (!body) {
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@openfn/language-common",
3
- "version": "2.4.0",
3
+ "label": "Common",
4
+ "version": "2.5.0",
4
5
  "description": "Common Expressions for OpenFn",
5
6
  "homepage": "https://docs.openfn.org",
6
7
  "repository": {
@@ -46,7 +47,6 @@
46
47
  "devDependencies": {
47
48
  "chai": "4.3.6",
48
49
  "deep-eql": "4.1.1",
49
- "esno": "^0.16.3",
50
50
  "nock": "13.2.9",
51
51
  "rimraf": "^3.0.2"
52
52
  },
package/types/http.d.ts CHANGED
@@ -3,14 +3,14 @@
3
3
  * easily add commonly used options. The return object is chainable so you can set
4
4
  * as many options as you want.
5
5
  * Pass an object to set your own options.
6
- * @param {CommonRequestOptions} options - options to pass to the request
6
+ * @param {OptionsHelpers} opts - options to pass to the request
7
7
  * @returns {OptionsHelpers}
8
8
  * @function
9
9
  * @public
10
- * @example <caption>Get with a query an oath token</caption>
11
- * get($.data.url, http.options({ query: $.query }).oath($.configuration.access_token))
10
+ * @example <caption>Get with a query an oauth token</caption>
11
+ * http.get($.data.url, http.options({ query: $.query }).oauth($.configuration.access_token))
12
12
  */
13
- export function options(opts?: {}): any;
13
+ export function options(opts?: any): any;
14
14
  /**
15
15
  * Make a GET request.
16
16
  * @public
@@ -38,17 +38,18 @@ export function get(url: string, options: CommonRequestOptions): Operation;
38
38
  * @public
39
39
  * @function
40
40
  * @example <caption>Post a JSON object (setting the content-type header)</caption>
41
- * http.post(
42
- * 'https://jsonplaceholder.typicode.com/todos',
43
- * $.data,
44
- * options().json(),
45
- * })
41
+ * http.post(
42
+ * "https://jsonplaceholder.typicode.com/todos",
43
+ * $.data,
44
+ * http.options().json()
45
+ * );
46
46
  * @param {string} url - URL to access
47
+ * @param {object} data - Body data to append to the request.
47
48
  * @param {CommonRequestOptions} options - Request options
48
49
  * @state {CommonHttpState}
49
50
  * @returns {Operation}
50
51
  */
51
- export function post(path: any, data: any, options: CommonRequestOptions): Operation;
52
+ export function post(url: string, data: object, options: CommonRequestOptions): Operation;
52
53
  export { req as request };
53
54
  /**
54
55
  * Helper functions provided by `http.options`.
@@ -27,7 +27,7 @@ export function request(method: any, fullUrlOrPath: any, options?: {}): Promise<
27
27
  export function makeBasicAuthHeader(username: any, password: any): {
28
28
  Authorization: string;
29
29
  };
30
- export function logResponse(response: any, query?: {}): any;
30
+ export function logResponse(response: any): any;
31
31
  export function enableMockClient(baseUrl: any): import("undici/types/mock-interceptor").Interceptable;
32
32
  export const ERROR_ABSOLUTE_URL: "Absolute URLs not suppored";
33
33
  export function assertRelativeUrl(path: any): void;