@openfn/language-http 5.1.0 → 6.0.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/ast.json +135 -9
- package/dist/index.cjs +112 -284
- package/dist/index.js +83 -250
- package/package.json +9 -15
- package/types/Adaptor.d.ts +82 -27
- package/types/Utils.d.ts +2 -9
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var Adaptor_exports = {};
|
|
|
9
9
|
__export(Adaptor_exports, {
|
|
10
10
|
alterState: () => alterState,
|
|
11
11
|
arrayToString: () => arrayToString,
|
|
12
|
-
|
|
12
|
+
chunk: () => chunk,
|
|
13
13
|
combine: () => combine,
|
|
14
14
|
dataPath: () => dataPath,
|
|
15
15
|
dataValue: () => dataValue,
|
|
@@ -21,7 +21,6 @@ __export(Adaptor_exports, {
|
|
|
21
21
|
fields: () => fields,
|
|
22
22
|
fn: () => fn,
|
|
23
23
|
get: () => get,
|
|
24
|
-
http: () => http2,
|
|
25
24
|
humanProper: () => humanProper,
|
|
26
25
|
lastReferenceValue: () => lastReferenceValue,
|
|
27
26
|
merge: () => merge,
|
|
@@ -30,128 +29,90 @@ __export(Adaptor_exports, {
|
|
|
30
29
|
patch: () => patch,
|
|
31
30
|
post: () => post,
|
|
32
31
|
put: () => put,
|
|
33
|
-
request: () =>
|
|
32
|
+
request: () => request2,
|
|
34
33
|
scrubEmojis: () => scrubEmojis,
|
|
35
34
|
sourceValue: () => sourceValue,
|
|
36
35
|
splitKeys: () => splitKeys,
|
|
37
36
|
toArray: () => toArray
|
|
38
37
|
});
|
|
38
|
+
import {
|
|
39
|
+
execute as commonExecute,
|
|
40
|
+
composeNextState as composeNextState2,
|
|
41
|
+
expandReferences as expandReferences2
|
|
42
|
+
} from "@openfn/language-common";
|
|
43
|
+
import cheerio from "cheerio";
|
|
44
|
+
import cheerioTableparser from "cheerio-tableparser";
|
|
39
45
|
|
|
40
46
|
// src/Utils.js
|
|
41
|
-
import
|
|
42
|
-
import
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
function isValidHttpUrl(string) {
|
|
54
|
-
let url;
|
|
55
|
-
try {
|
|
56
|
-
url = new URL(string);
|
|
57
|
-
} catch (_2) {
|
|
58
|
-
return false;
|
|
47
|
+
import { composeNextState } from "@openfn/language-common";
|
|
48
|
+
import {
|
|
49
|
+
request as commonRequest,
|
|
50
|
+
expandReferences,
|
|
51
|
+
logResponse,
|
|
52
|
+
makeBasicAuthHeader
|
|
53
|
+
} from "@openfn/language-common/util";
|
|
54
|
+
function addBasicAuth(configuration = {}, headers) {
|
|
55
|
+
const { username, password } = configuration;
|
|
56
|
+
if (username && password) {
|
|
57
|
+
Object.assign(headers, makeBasicAuthHeader(username, password));
|
|
59
58
|
}
|
|
60
|
-
return url.protocol === "http:" || url.protocol === "https:";
|
|
61
59
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
username: configuration.username,
|
|
68
|
-
password: configuration.password
|
|
69
|
-
};
|
|
70
|
-
else
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
function assembleError({ response, error, params }) {
|
|
74
|
-
var _a;
|
|
75
|
-
if (response) {
|
|
76
|
-
const customCodes = (_a = params == null ? void 0 : params.options) == null ? void 0 : _a.successCodes;
|
|
77
|
-
const status = (response == null ? void 0 : response.status) || (response == null ? void 0 : response.statusCode);
|
|
78
|
-
if ((customCodes || [200, 201, 202]).indexOf(status) > -1) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
60
|
+
function encodeFormBody(data) {
|
|
61
|
+
const form = new FormData();
|
|
62
|
+
for (const [key, value] of Object.entries(data)) {
|
|
63
|
+
form.append(key, value);
|
|
81
64
|
}
|
|
82
|
-
|
|
83
|
-
return error;
|
|
84
|
-
delete response.request;
|
|
85
|
-
delete response.connection;
|
|
86
|
-
return new Error(safeStringify(response, null, 2));
|
|
65
|
+
return form;
|
|
87
66
|
}
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
67
|
+
function request(method, path, params, callback = (s) => s) {
|
|
68
|
+
return (state) => {
|
|
69
|
+
var _a;
|
|
70
|
+
const [resolvedPath, resolvedParams = {}] = expandReferences(
|
|
71
|
+
state,
|
|
72
|
+
path,
|
|
73
|
+
params
|
|
74
|
+
);
|
|
75
|
+
let { body, headers = {} } = resolvedParams;
|
|
76
|
+
if (resolvedParams.json) {
|
|
77
|
+
console.warn(
|
|
78
|
+
"WARNING: The `json` option has been deprecated. Use `body` instead"
|
|
79
|
+
);
|
|
80
|
+
body = resolvedParams.json;
|
|
94
81
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
function mapToAxiosConfig(requestConfig) {
|
|
99
|
-
let form = null;
|
|
100
|
-
const formData = (requestConfig == null ? void 0 : requestConfig.formData) || (requestConfig == null ? void 0 : requestConfig.form);
|
|
101
|
-
let headers = requestConfig == null ? void 0 : requestConfig.headers;
|
|
102
|
-
if ((requestConfig == null ? void 0 : requestConfig.gzip) === true) {
|
|
103
|
-
headers = { ...headers, "Accept-Encoding": "gzip, deflate" };
|
|
104
|
-
}
|
|
105
|
-
if (!isEmpty(formData)) {
|
|
106
|
-
form = new FormData();
|
|
107
|
-
Object.entries(formData).forEach((element) => {
|
|
108
|
-
form.append(element[0], element[1]);
|
|
109
|
-
});
|
|
110
|
-
const formHeaders = form.getHeaders();
|
|
111
|
-
headers = { ...headers, ...formHeaders };
|
|
112
|
-
}
|
|
113
|
-
if (requestConfig == null ? void 0 : requestConfig.json) {
|
|
114
|
-
headers = { ...headers, "Content-type": "application/json" };
|
|
115
|
-
if (typeof (requestConfig == null ? void 0 : requestConfig.json) === "object") {
|
|
116
|
-
requestConfig = { ...requestConfig, body: requestConfig == null ? void 0 : requestConfig.json };
|
|
82
|
+
if (resolvedParams.form) {
|
|
83
|
+
body = encodeFormBody(resolvedParams.form);
|
|
117
84
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return
|
|
138
|
-
|
|
139
|
-
|
|
85
|
+
const baseUrl = (_a = state.configuration) == null ? void 0 : _a.baseUrl;
|
|
86
|
+
addBasicAuth(state.configuration, headers);
|
|
87
|
+
const maxRedirections = resolvedParams.maxRedirections ?? (resolvedParams.followAllRedirects === false ? 0 : 5);
|
|
88
|
+
const tls = resolvedParams.tls ?? resolvedParams.agentOptions;
|
|
89
|
+
if (resolvedParams.agentOptions) {
|
|
90
|
+
console.warn(
|
|
91
|
+
"WARNING: The `agentOptions` option has been deprecated. Use `tls` instead"
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const options = {
|
|
95
|
+
...resolvedParams,
|
|
96
|
+
headers,
|
|
97
|
+
baseUrl,
|
|
98
|
+
body,
|
|
99
|
+
tls,
|
|
100
|
+
maxRedirections
|
|
101
|
+
};
|
|
102
|
+
return commonRequest(method, resolvedPath, options).then((response) => {
|
|
103
|
+
logResponse(response);
|
|
104
|
+
return {
|
|
105
|
+
...composeNextState(state, response.body),
|
|
106
|
+
response
|
|
107
|
+
};
|
|
108
|
+
}).then(callback).catch((err) => {
|
|
109
|
+
logResponse(err);
|
|
110
|
+
throw err;
|
|
111
|
+
});
|
|
140
112
|
};
|
|
141
|
-
return finalConfig;
|
|
142
113
|
}
|
|
143
114
|
|
|
144
115
|
// src/Adaptor.js
|
|
145
|
-
import {
|
|
146
|
-
execute as commonExecute,
|
|
147
|
-
expandReferences,
|
|
148
|
-
composeNextState,
|
|
149
|
-
http
|
|
150
|
-
} from "@openfn/language-common";
|
|
151
|
-
import nodeRequest from "request";
|
|
152
|
-
import cheerio from "cheerio";
|
|
153
|
-
import cheerioTableparser from "cheerio-tableparser";
|
|
154
|
-
import tough from "tough-cookie";
|
|
155
116
|
import {
|
|
156
117
|
alterState,
|
|
157
118
|
arrayToString,
|
|
@@ -163,7 +124,7 @@ import {
|
|
|
163
124
|
field,
|
|
164
125
|
fields,
|
|
165
126
|
fn,
|
|
166
|
-
|
|
127
|
+
chunk,
|
|
167
128
|
humanProper,
|
|
168
129
|
lastReferenceValue,
|
|
169
130
|
merge,
|
|
@@ -173,7 +134,6 @@ import {
|
|
|
173
134
|
toArray,
|
|
174
135
|
parseCsv
|
|
175
136
|
} from "@openfn/language-common";
|
|
176
|
-
var { axios } = http;
|
|
177
137
|
function execute(...operations) {
|
|
178
138
|
const initialState = {
|
|
179
139
|
references: [],
|
|
@@ -183,175 +143,49 @@ function execute(...operations) {
|
|
|
183
143
|
return commonExecute(...operations)({ ...initialState, ...state });
|
|
184
144
|
};
|
|
185
145
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
axios.interceptors.request.use((config) => {
|
|
189
|
-
cookiejar == null ? void 0 : cookiejar.getCookies(config.url, (err, cookies) => {
|
|
190
|
-
config.headers.cookie = cookies == null ? void 0 : cookies.join("; ");
|
|
191
|
-
});
|
|
192
|
-
return config;
|
|
193
|
-
});
|
|
194
|
-
function handleCookies(response) {
|
|
195
|
-
var _a, _b;
|
|
196
|
-
const { config, data, headers } = response;
|
|
197
|
-
if (config.keepCookie) {
|
|
198
|
-
let cookies;
|
|
199
|
-
let keepCookies = [];
|
|
200
|
-
if (headers["set-cookie"]) {
|
|
201
|
-
if (headers["set-cookie"] instanceof Array) {
|
|
202
|
-
cookies = (_a = headers["set-cookie"]) == null ? void 0 : _a.map(Cookie.parse);
|
|
203
|
-
} else {
|
|
204
|
-
cookies = [Cookie.parse(headers["set-cookie"])];
|
|
205
|
-
}
|
|
206
|
-
(_b = headers["set-cookie"]) == null ? void 0 : _b.forEach((c) => {
|
|
207
|
-
cookiejar.setCookie(Cookie.parse(c), config.url, (err, cookie) => {
|
|
208
|
-
keepCookies == null ? void 0 : keepCookies.push(cookie == null ? void 0 : cookie.cookieString());
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
const extendableData = Array.isArray(data) ? { body: data } : data;
|
|
213
|
-
return {
|
|
214
|
-
...response,
|
|
215
|
-
data: {
|
|
216
|
-
...extendableData,
|
|
217
|
-
__cookie: (keepCookies == null ? void 0 : keepCookies.length) === 1 ? keepCookies[0] : keepCookies,
|
|
218
|
-
__headers: response.headers
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
return response;
|
|
223
|
-
}
|
|
224
|
-
function handleResponse(state, response) {
|
|
225
|
-
console.log(
|
|
226
|
-
response.config.method.toUpperCase(),
|
|
227
|
-
"request succeeded with",
|
|
228
|
-
response.status,
|
|
229
|
-
"\u2713"
|
|
230
|
-
);
|
|
231
|
-
const { method, path, host, protocol, _headers } = response.request;
|
|
232
|
-
response.request = { method, path, host, protocol, _headers };
|
|
233
|
-
const compatibleResp = {
|
|
234
|
-
...response,
|
|
235
|
-
httpStatus: response.status,
|
|
236
|
-
message: response.statusText,
|
|
237
|
-
data: tryJson(response.data)
|
|
238
|
-
};
|
|
239
|
-
const respWithCookies = handleCookies(compatibleResp);
|
|
240
|
-
return {
|
|
241
|
-
...composeNextState(state, respWithCookies.data),
|
|
242
|
-
response: respWithCookies
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
function handleCallback(state, callback) {
|
|
246
|
-
if (callback)
|
|
247
|
-
return callback(state);
|
|
248
|
-
return state;
|
|
146
|
+
function request2(method, path, params, callback) {
|
|
147
|
+
return request(method, path, params, callback);
|
|
249
148
|
}
|
|
250
149
|
function get(path, params, callback) {
|
|
251
|
-
return (
|
|
252
|
-
const resolvedPath = expandReferences(path)(state);
|
|
253
|
-
const resolvedParams = http.expandRequestReferences(params)(state);
|
|
254
|
-
const url = setUrl(state.configuration, resolvedPath);
|
|
255
|
-
const auth = setAuth(
|
|
256
|
-
state.configuration,
|
|
257
|
-
(resolvedParams == null ? void 0 : resolvedParams.authentication) ?? (resolvedParams == null ? void 0 : resolvedParams.auth)
|
|
258
|
-
);
|
|
259
|
-
const config = mapToAxiosConfig({ ...resolvedParams, url, auth });
|
|
260
|
-
return http.get(config)(state).then((response) => handleResponse(state, response)).then((nextState) => handleCallback(nextState, callback));
|
|
261
|
-
};
|
|
150
|
+
return request("GET", path, params, callback);
|
|
262
151
|
}
|
|
263
152
|
function post(path, params, callback) {
|
|
264
|
-
return (
|
|
265
|
-
const resolvedPath = expandReferences(path)(state);
|
|
266
|
-
const resolvedParams = http.expandRequestReferences(params)(state);
|
|
267
|
-
const url = setUrl(state.configuration, resolvedPath);
|
|
268
|
-
const auth = setAuth(
|
|
269
|
-
state.configuration,
|
|
270
|
-
(resolvedParams == null ? void 0 : resolvedParams.authentication) ?? (resolvedParams == null ? void 0 : resolvedParams.auth)
|
|
271
|
-
);
|
|
272
|
-
const config = mapToAxiosConfig({ ...resolvedParams, url, auth });
|
|
273
|
-
return http.post(config)(state).then((response) => handleResponse(state, response)).then((nextState) => handleCallback(nextState, callback));
|
|
274
|
-
};
|
|
153
|
+
return request("POST", path, params, callback);
|
|
275
154
|
}
|
|
276
155
|
function put(path, params, callback) {
|
|
277
|
-
return (
|
|
278
|
-
const resolvedPath = expandReferences(path)(state);
|
|
279
|
-
const resolvedParams = http.expandRequestReferences(params)(state);
|
|
280
|
-
const url = setUrl(state.configuration, resolvedPath);
|
|
281
|
-
const auth = setAuth(
|
|
282
|
-
state.configuration,
|
|
283
|
-
(resolvedParams == null ? void 0 : resolvedParams.authentication) ?? (resolvedParams == null ? void 0 : resolvedParams.auth)
|
|
284
|
-
);
|
|
285
|
-
const config = mapToAxiosConfig({ ...resolvedParams, url, auth });
|
|
286
|
-
return http.put(config)(state).then((response) => handleResponse(state, response)).then((nextState) => handleCallback(nextState, callback));
|
|
287
|
-
};
|
|
156
|
+
return request("PUT", path, params, callback);
|
|
288
157
|
}
|
|
289
158
|
function patch(path, params, callback) {
|
|
290
|
-
return (
|
|
291
|
-
const resolvedPath = expandReferences(path)(state);
|
|
292
|
-
const resolvedParams = http.expandRequestReferences(params)(state);
|
|
293
|
-
const url = setUrl(state.configuration, resolvedPath);
|
|
294
|
-
const auth = setAuth(
|
|
295
|
-
state.configuration,
|
|
296
|
-
(resolvedParams == null ? void 0 : resolvedParams.authentication) ?? (resolvedParams == null ? void 0 : resolvedParams.auth)
|
|
297
|
-
);
|
|
298
|
-
const config = mapToAxiosConfig({ ...resolvedParams, url, auth });
|
|
299
|
-
return http.patch(config)(state).then((response) => handleResponse(state, response)).then((nextState) => handleCallback(nextState, callback));
|
|
300
|
-
};
|
|
159
|
+
return request("PATCH", path, params, callback);
|
|
301
160
|
}
|
|
302
161
|
function del(path, params, callback) {
|
|
303
|
-
return (
|
|
304
|
-
const resolvedPath = expandReferences(path)(state);
|
|
305
|
-
const resolvedParams = http.expandRequestReferences(params)(state);
|
|
306
|
-
const url = setUrl(state.configuration, resolvedPath);
|
|
307
|
-
const auth = setAuth(
|
|
308
|
-
state.configuration,
|
|
309
|
-
(resolvedParams == null ? void 0 : resolvedParams.authentication) ?? resolvedParams.auth
|
|
310
|
-
);
|
|
311
|
-
const config = mapToAxiosConfig({ ...resolvedParams, url, auth });
|
|
312
|
-
return http.delete(config)(state).then((response) => handleResponse(state, response)).then((nextState) => handleCallback(nextState, callback));
|
|
313
|
-
};
|
|
162
|
+
return request("DELETE", path, params, callback);
|
|
314
163
|
}
|
|
315
164
|
function parseXML(body, script) {
|
|
316
165
|
return (state) => {
|
|
317
|
-
const
|
|
166
|
+
const resolvedBody = expandReferences2(body)(state);
|
|
167
|
+
const $ = cheerio.load(resolvedBody);
|
|
318
168
|
cheerioTableparser($);
|
|
319
169
|
if (script) {
|
|
320
170
|
const result = script($);
|
|
321
171
|
try {
|
|
322
172
|
const r = JSON.parse(result);
|
|
323
|
-
return
|
|
173
|
+
return composeNextState2(state, r);
|
|
324
174
|
} catch (e) {
|
|
325
|
-
return
|
|
175
|
+
return composeNextState2(state, { body: result });
|
|
326
176
|
}
|
|
327
177
|
} else {
|
|
328
|
-
return
|
|
178
|
+
return composeNextState2(state, { body: resolvedBody });
|
|
329
179
|
}
|
|
330
180
|
};
|
|
331
181
|
}
|
|
332
|
-
function request(params) {
|
|
333
|
-
return (state) => {
|
|
334
|
-
const resolvedParams = http.expandRequestReferences(params)(state);
|
|
335
|
-
return new Promise((resolve, reject) => {
|
|
336
|
-
nodeRequest(resolvedParams, (err, response, body) => {
|
|
337
|
-
const error = assembleError({ error: err, response, resolvedParams });
|
|
338
|
-
error && reject(error);
|
|
339
|
-
console.log(
|
|
340
|
-
"\u2713 Request succeeded. (The response body available in state.)"
|
|
341
|
-
);
|
|
342
|
-
const resp = tryJson(body);
|
|
343
|
-
resolve(resp);
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
182
|
|
|
349
183
|
// src/index.js
|
|
350
184
|
var src_default = Adaptor_exports;
|
|
351
185
|
export {
|
|
352
186
|
alterState,
|
|
353
187
|
arrayToString,
|
|
354
|
-
|
|
188
|
+
chunk,
|
|
355
189
|
combine,
|
|
356
190
|
dataPath,
|
|
357
191
|
dataValue,
|
|
@@ -364,7 +198,6 @@ export {
|
|
|
364
198
|
fields,
|
|
365
199
|
fn,
|
|
366
200
|
get,
|
|
367
|
-
http2 as http,
|
|
368
201
|
humanProper,
|
|
369
202
|
lastReferenceValue,
|
|
370
203
|
merge,
|
|
@@ -373,7 +206,7 @@ export {
|
|
|
373
206
|
patch,
|
|
374
207
|
post,
|
|
375
208
|
put,
|
|
376
|
-
request,
|
|
209
|
+
request2 as request,
|
|
377
210
|
scrubEmojis,
|
|
378
211
|
sourceValue,
|
|
379
212
|
splitKeys,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-http",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "An HTTP request language package for use with Open Function",
|
|
5
5
|
"homepage": "https://docs.openfn.org",
|
|
6
6
|
"repository": {
|
|
@@ -25,32 +25,26 @@
|
|
|
25
25
|
"configuration-schema.json"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@openfn/language-common": "1.
|
|
29
|
-
"cheerio": "
|
|
30
|
-
"cheerio-tableparser": "^1.0.1"
|
|
31
|
-
"csv-parse": "^4.10.1",
|
|
32
|
-
"fast-safe-stringify": "^2.0.7",
|
|
33
|
-
"form-data": "^3.0.0",
|
|
34
|
-
"lodash": "^4.17.19",
|
|
35
|
-
"request": "^2.88.2",
|
|
36
|
-
"tough-cookie": "^4.0.0"
|
|
28
|
+
"@openfn/language-common": "^1.12.0",
|
|
29
|
+
"cheerio": "1.0.0-rc.12",
|
|
30
|
+
"cheerio-tableparser": "^1.0.1"
|
|
37
31
|
},
|
|
38
32
|
"devDependencies": {
|
|
39
|
-
"@openfn/buildtools": "^1.0.2",
|
|
40
33
|
"@openfn/simple-ast": "0.4.1",
|
|
41
|
-
"chai": "4.3.
|
|
34
|
+
"chai": "^4.3.10",
|
|
42
35
|
"deep-eql": "4.1.1",
|
|
43
36
|
"esno": "^0.16.3",
|
|
44
37
|
"mocha": "9.2.2",
|
|
45
|
-
"
|
|
46
|
-
"rimraf": "^3.0.2"
|
|
38
|
+
"mocha-suppress-logs": "^0.4.1",
|
|
39
|
+
"rimraf": "^3.0.2",
|
|
40
|
+
"@openfn/buildtools": "^1.0.2"
|
|
47
41
|
},
|
|
48
42
|
"main": "dist/index.cjs",
|
|
49
43
|
"scripts": {
|
|
50
44
|
"clean": "rimraf dist types docs",
|
|
51
45
|
"build": "pnpm clean && build-adaptor http",
|
|
52
46
|
"pack": "pnpm pack --pack-destination ../../dist",
|
|
53
|
-
"test": "mocha --experimental-specifier-resolution=node --no-warnings",
|
|
47
|
+
"test": "mocha --require mocha-suppress-logs --experimental-specifier-resolution=node --no-warnings",
|
|
54
48
|
"test:watch": "mocha -w",
|
|
55
49
|
"lint": "eslint src"
|
|
56
50
|
}
|
package/types/Adaptor.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options provided to the HTTP request
|
|
3
|
+
* @typedef {Object} RequestOptions
|
|
4
|
+
* @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).
|
|
5
|
+
* @property {object} errors - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors for this code.
|
|
6
|
+
* @property {object} form - Pass a JSON object to be serialised into a multipart HTML form (as FormData) in the body.
|
|
7
|
+
* @property {object} query - An object of query parameters to be encoded into the URL.
|
|
8
|
+
* @property {object} headers - An object of headers to append to the request.
|
|
9
|
+
* @property {string} parseAs - Parse the response body as json, text or stream. By default will use the response headers.
|
|
10
|
+
* @property {number} timeout - Request timeout in ms. Default: 300 seconds.
|
|
11
|
+
* @property {object} tls - TLS/SSL authentication options. See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions
|
|
12
|
+
*/
|
|
1
13
|
/**
|
|
2
14
|
* Execute a sequence of operations.
|
|
3
15
|
* Wraps `language-common/execute`, and prepends initial state for http.
|
|
@@ -11,22 +23,41 @@
|
|
|
11
23
|
* @returns {Operation}
|
|
12
24
|
*/
|
|
13
25
|
export function execute(...operations: Operations): Operation;
|
|
26
|
+
/**
|
|
27
|
+
* Make a HTTP request
|
|
28
|
+
* @public
|
|
29
|
+
* @example
|
|
30
|
+
* request(
|
|
31
|
+
* 'GET',
|
|
32
|
+
* '/myEndpoint',
|
|
33
|
+
* {
|
|
34
|
+
* query: {foo: 'bar', a: 1},
|
|
35
|
+
* headers: {'content-type': 'application/json'},
|
|
36
|
+
* }
|
|
37
|
+
* )
|
|
38
|
+
* @function
|
|
39
|
+
* @param {string} method - The HTTP method to use
|
|
40
|
+
* @param {string} path - Path to resource
|
|
41
|
+
* @param {RequestOptions} params - Query, Headers and Authentication parameters
|
|
42
|
+
* @param {function} callback - (Optional) Callback function
|
|
43
|
+
* @returns {Operation}
|
|
44
|
+
*/
|
|
45
|
+
export function request(method: string, path: string, params: RequestOptions, callback: Function): Operation;
|
|
14
46
|
/**
|
|
15
47
|
* Make a GET request
|
|
16
48
|
* @public
|
|
17
49
|
* @example
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* })
|
|
50
|
+
* get('/myEndpoint', {
|
|
51
|
+
* query: {foo: 'bar', a: 1},
|
|
52
|
+
* headers: {'content-type': 'application/json'},
|
|
53
|
+
* })
|
|
23
54
|
* @function
|
|
24
55
|
* @param {string} path - Path to resource
|
|
25
|
-
* @param {
|
|
56
|
+
* @param {RequestOptions} params - Query, Headers and Authentication parameters
|
|
26
57
|
* @param {function} callback - (Optional) Callback function
|
|
27
58
|
* @returns {Operation}
|
|
28
59
|
*/
|
|
29
|
-
export function get(path: string, params:
|
|
60
|
+
export function get(path: string, params: RequestOptions, callback: Function): Operation;
|
|
30
61
|
/**
|
|
31
62
|
* Make a POST request
|
|
32
63
|
* @public
|
|
@@ -34,15 +65,14 @@ export function get(path: string, params: object, callback: Function): Operation
|
|
|
34
65
|
* post('/myEndpoint', {
|
|
35
66
|
* body: {'foo': 'bar'},
|
|
36
67
|
* headers: {'content-type': 'application/json'},
|
|
37
|
-
* authentication: {username: 'user', password: 'pass'}
|
|
38
68
|
* })
|
|
39
69
|
* @function
|
|
40
70
|
* @param {string} path - Path to resource
|
|
41
|
-
* @param {
|
|
71
|
+
* @param {RequestOptions} params - Body, Query, Headers and Authentication parameters
|
|
42
72
|
* @param {function} callback - (Optional) Callback function
|
|
43
73
|
* @returns {operation}
|
|
44
74
|
*/
|
|
45
|
-
export function post(path: string, params:
|
|
75
|
+
export function post(path: string, params: RequestOptions, callback: Function): operation;
|
|
46
76
|
/**
|
|
47
77
|
* Make a PUT request
|
|
48
78
|
* @public
|
|
@@ -50,15 +80,14 @@ export function post(path: string, params: object, callback: Function): operatio
|
|
|
50
80
|
* put('/myEndpoint', {
|
|
51
81
|
* body: {'foo': 'bar'},
|
|
52
82
|
* headers: {'content-type': 'application/json'},
|
|
53
|
-
* authentication: {username: 'user', password: 'pass'}
|
|
54
83
|
* })
|
|
55
84
|
* @function
|
|
56
85
|
* @param {string} path - Path to resource
|
|
57
|
-
* @param {
|
|
86
|
+
* @param {RequestOptions} params - Body, Query, Headers and Auth parameters
|
|
58
87
|
* @param {function} callback - (Optional) Callback function
|
|
59
88
|
* @returns {Operation}
|
|
60
89
|
*/
|
|
61
|
-
export function put(path: string, params:
|
|
90
|
+
export function put(path: string, params: RequestOptions, callback: Function): Operation;
|
|
62
91
|
/**
|
|
63
92
|
* Make a PATCH request
|
|
64
93
|
* @public
|
|
@@ -66,15 +95,14 @@ export function put(path: string, params: object, callback: Function): Operation
|
|
|
66
95
|
* patch('/myEndpoint', {
|
|
67
96
|
* body: {'foo': 'bar'},
|
|
68
97
|
* headers: {'content-type': 'application/json'},
|
|
69
|
-
* authentication: {username: 'user', password: 'pass'}
|
|
70
98
|
* })
|
|
71
99
|
* @function
|
|
72
100
|
* @param {string} path - Path to resource
|
|
73
|
-
* @param {
|
|
101
|
+
* @param {RequestOptions} params - Body, Query, Headers and Auth parameters
|
|
74
102
|
* @param {function} callback - (Optional) Callback function
|
|
75
103
|
* @returns {Operation}
|
|
76
104
|
*/
|
|
77
|
-
export function patch(path: string, params:
|
|
105
|
+
export function patch(path: string, params: RequestOptions, callback: Function): Operation;
|
|
78
106
|
/**
|
|
79
107
|
* Make a DELETE request
|
|
80
108
|
* @public
|
|
@@ -84,11 +112,11 @@ export function patch(path: string, params: object, callback: Function): Operati
|
|
|
84
112
|
* })
|
|
85
113
|
* @function
|
|
86
114
|
* @param {string} path - Path to resource
|
|
87
|
-
* @param {
|
|
115
|
+
* @param {RequestOptions} params - Body, Query, Headers and Auth parameters
|
|
88
116
|
* @param {function} callback - (Optional) Callback function
|
|
89
117
|
* @returns {Operation}
|
|
90
118
|
*/
|
|
91
|
-
export function del(path: string, params:
|
|
119
|
+
export function del(path: string, params: RequestOptions, callback: Function): Operation;
|
|
92
120
|
/**
|
|
93
121
|
* Parse XML with the Cheerio parser
|
|
94
122
|
* @public
|
|
@@ -103,13 +131,40 @@ export function del(path: string, params: object, callback: Function): Operation
|
|
|
103
131
|
*/
|
|
104
132
|
export function parseXML(body: string, script: Function): Operation;
|
|
105
133
|
/**
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* request(params);
|
|
109
|
-
* @function
|
|
110
|
-
* @param {object} params - Query, Headers and Authentication parameters
|
|
111
|
-
* @returns {Operation}
|
|
134
|
+
* Options provided to the HTTP request
|
|
112
135
|
*/
|
|
113
|
-
export
|
|
114
|
-
|
|
115
|
-
|
|
136
|
+
export type RequestOptions = {
|
|
137
|
+
/**
|
|
138
|
+
* - 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).
|
|
139
|
+
*/
|
|
140
|
+
body: object | string;
|
|
141
|
+
/**
|
|
142
|
+
* - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors for this code.
|
|
143
|
+
*/
|
|
144
|
+
errors: object;
|
|
145
|
+
/**
|
|
146
|
+
* - Pass a JSON object to be serialised into a multipart HTML form (as FormData) in the body.
|
|
147
|
+
*/
|
|
148
|
+
form: object;
|
|
149
|
+
/**
|
|
150
|
+
* - An object of query parameters to be encoded into the URL.
|
|
151
|
+
*/
|
|
152
|
+
query: object;
|
|
153
|
+
/**
|
|
154
|
+
* - An object of headers to append to the request.
|
|
155
|
+
*/
|
|
156
|
+
headers: object;
|
|
157
|
+
/**
|
|
158
|
+
* - Parse the response body as json, text or stream. By default will use the response headers.
|
|
159
|
+
*/
|
|
160
|
+
parseAs: string;
|
|
161
|
+
/**
|
|
162
|
+
* - Request timeout in ms. Default: 300 seconds.
|
|
163
|
+
*/
|
|
164
|
+
timeout: number;
|
|
165
|
+
/**
|
|
166
|
+
* - TLS/SSL authentication options. See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions
|
|
167
|
+
*/
|
|
168
|
+
tls: object;
|
|
169
|
+
};
|
|
170
|
+
export { alterState, arrayToString, combine, dataPath, dataValue, dateFns, each, field, fields, fn, chunk, humanProper, lastReferenceValue, merge, scrubEmojis, sourceValue, splitKeys, toArray, parseCsv } from "@openfn/language-common";
|
package/types/Utils.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
export function
|
|
2
|
-
export function
|
|
3
|
-
export function assembleError({ response, error, params }: {
|
|
4
|
-
response: any;
|
|
5
|
-
error: any;
|
|
6
|
-
params: any;
|
|
7
|
-
}): any;
|
|
8
|
-
export function tryJson(data: any): any;
|
|
9
|
-
export function mapToAxiosConfig(requestConfig: any): any;
|
|
1
|
+
export function addBasicAuth(configuration: {}, headers: any): void;
|
|
2
|
+
export function request(method: any, path: any, params: any, callback?: (s: any) => any): (state: any) => any;
|