@openfn/language-http 4.0.1 → 4.0.2
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.js → index.cjs} +95 -93
- package/package.json +2 -2
|
@@ -1,47 +1,73 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2
7
|
var __export = (target, all) => {
|
|
3
8
|
for (var name in all)
|
|
4
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
10
|
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
|
|
25
|
+
// src/index.js
|
|
26
|
+
var src_exports = {};
|
|
27
|
+
__export(src_exports, {
|
|
28
|
+
Adaptor: () => Adaptor_exports,
|
|
29
|
+
default: () => src_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(src_exports);
|
|
6
32
|
|
|
7
33
|
// src/Adaptor.js
|
|
8
34
|
var Adaptor_exports = {};
|
|
9
35
|
__export(Adaptor_exports, {
|
|
10
|
-
alterState: () => alterState,
|
|
11
|
-
arrayToString: () => arrayToString,
|
|
36
|
+
alterState: () => import_language_common2.alterState,
|
|
37
|
+
arrayToString: () => import_language_common2.arrayToString,
|
|
12
38
|
axios: () => axios,
|
|
13
|
-
combine: () => combine,
|
|
14
|
-
dataPath: () => dataPath,
|
|
15
|
-
dataValue: () => dataValue,
|
|
16
|
-
dateFns: () => dateFns,
|
|
39
|
+
combine: () => import_language_common2.combine,
|
|
40
|
+
dataPath: () => import_language_common2.dataPath,
|
|
41
|
+
dataValue: () => import_language_common2.dataValue,
|
|
42
|
+
dateFns: () => import_language_common2.dateFns,
|
|
17
43
|
del: () => del,
|
|
18
|
-
each: () => each,
|
|
44
|
+
each: () => import_language_common2.each,
|
|
19
45
|
execute: () => execute,
|
|
20
|
-
field: () => field,
|
|
21
|
-
fields: () => fields,
|
|
22
|
-
fn: () => fn,
|
|
46
|
+
field: () => import_language_common2.field,
|
|
47
|
+
fields: () => import_language_common2.fields,
|
|
48
|
+
fn: () => import_language_common2.fn,
|
|
23
49
|
get: () => get,
|
|
24
|
-
http: () =>
|
|
25
|
-
humanProper: () => humanProper,
|
|
26
|
-
lastReferenceValue: () => lastReferenceValue,
|
|
27
|
-
merge: () => merge,
|
|
50
|
+
http: () => import_language_common2.http,
|
|
51
|
+
humanProper: () => import_language_common2.humanProper,
|
|
52
|
+
lastReferenceValue: () => import_language_common2.lastReferenceValue,
|
|
53
|
+
merge: () => import_language_common2.merge,
|
|
28
54
|
parseCSV: () => parseCSV,
|
|
29
55
|
parseXML: () => parseXML,
|
|
30
56
|
patch: () => patch,
|
|
31
57
|
post: () => post,
|
|
32
58
|
put: () => put,
|
|
33
59
|
request: () => request,
|
|
34
|
-
scrubEmojis: () => scrubEmojis,
|
|
35
|
-
sourceValue: () => sourceValue,
|
|
36
|
-
splitKeys: () => splitKeys,
|
|
37
|
-
toArray: () => toArray
|
|
60
|
+
scrubEmojis: () => import_language_common2.scrubEmojis,
|
|
61
|
+
sourceValue: () => import_language_common2.sourceValue,
|
|
62
|
+
splitKeys: () => import_language_common2.splitKeys,
|
|
63
|
+
toArray: () => import_language_common2.toArray
|
|
38
64
|
});
|
|
39
65
|
|
|
40
66
|
// src/Utils.js
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var { isEmpty } =
|
|
67
|
+
var import_form_data = __toESM(require("form-data"), 1);
|
|
68
|
+
var import_fp = __toESM(require("lodash/fp"), 1);
|
|
69
|
+
var import_fast_safe_stringify = __toESM(require("fast-safe-stringify"), 1);
|
|
70
|
+
var { isEmpty } = import_fp.default;
|
|
45
71
|
function setUrl(configuration, path) {
|
|
46
72
|
const baseUrl = configuration == null ? void 0 : configuration.baseUrl;
|
|
47
73
|
if (isValidHttpUrl(path))
|
|
@@ -83,7 +109,7 @@ function assembleError({ response, error, params }) {
|
|
|
83
109
|
return error;
|
|
84
110
|
delete response.request;
|
|
85
111
|
delete response.connection;
|
|
86
|
-
return new Error(
|
|
112
|
+
return new Error((0, import_fast_safe_stringify.default)(response, null, 2));
|
|
87
113
|
}
|
|
88
114
|
function tryJson(data) {
|
|
89
115
|
if (typeof data === "string") {
|
|
@@ -103,7 +129,7 @@ function mapToAxiosConfig(requestConfig) {
|
|
|
103
129
|
headers = { ...headers, "Accept-Encoding": "gzip, deflate" };
|
|
104
130
|
}
|
|
105
131
|
if (!isEmpty(formData)) {
|
|
106
|
-
form = new
|
|
132
|
+
form = new import_form_data.default();
|
|
107
133
|
Object.entries(formData).forEach((element) => {
|
|
108
134
|
form.append(element[0], element[1]);
|
|
109
135
|
});
|
|
@@ -142,50 +168,26 @@ function mapToAxiosConfig(requestConfig) {
|
|
|
142
168
|
}
|
|
143
169
|
|
|
144
170
|
// src/Adaptor.js
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
import fs from "fs";
|
|
155
|
-
import parse from "csv-parse";
|
|
156
|
-
import tough from "tough-cookie";
|
|
157
|
-
import {
|
|
158
|
-
alterState,
|
|
159
|
-
arrayToString,
|
|
160
|
-
combine,
|
|
161
|
-
dataPath,
|
|
162
|
-
dataValue,
|
|
163
|
-
dateFns,
|
|
164
|
-
each,
|
|
165
|
-
field,
|
|
166
|
-
fields,
|
|
167
|
-
fn,
|
|
168
|
-
http as http2,
|
|
169
|
-
humanProper,
|
|
170
|
-
lastReferenceValue,
|
|
171
|
-
merge,
|
|
172
|
-
scrubEmojis,
|
|
173
|
-
sourceValue,
|
|
174
|
-
splitKeys,
|
|
175
|
-
toArray
|
|
176
|
-
} from "@openfn/language-common";
|
|
177
|
-
var { axios } = http;
|
|
171
|
+
var import_language_common = require("@openfn/language-common");
|
|
172
|
+
var import_request = __toESM(require("request"), 1);
|
|
173
|
+
var import_cheerio = __toESM(require("cheerio"), 1);
|
|
174
|
+
var import_cheerio_tableparser = __toESM(require("cheerio-tableparser"), 1);
|
|
175
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
176
|
+
var import_csv_parse = __toESM(require("csv-parse"), 1);
|
|
177
|
+
var import_tough_cookie = __toESM(require("tough-cookie"), 1);
|
|
178
|
+
var import_language_common2 = require("@openfn/language-common");
|
|
179
|
+
var { axios } = import_language_common.http;
|
|
178
180
|
function execute(...operations) {
|
|
179
181
|
const initialState = {
|
|
180
182
|
references: [],
|
|
181
183
|
data: null
|
|
182
184
|
};
|
|
183
185
|
return (state) => {
|
|
184
|
-
return
|
|
186
|
+
return (0, import_language_common.execute)(...operations)({ ...initialState, ...state });
|
|
185
187
|
};
|
|
186
188
|
}
|
|
187
|
-
var cookiejar = new
|
|
188
|
-
var Cookie =
|
|
189
|
+
var cookiejar = new import_tough_cookie.default.CookieJar();
|
|
190
|
+
var Cookie = import_tough_cookie.default.Cookie;
|
|
189
191
|
axios.interceptors.request.use((config) => {
|
|
190
192
|
cookiejar == null ? void 0 : cookiejar.getCookies(config.url, (err, cookies) => {
|
|
191
193
|
config.headers.cookie = cookies == null ? void 0 : cookies.join("; ");
|
|
@@ -237,7 +239,7 @@ function handleResponse(state, response) {
|
|
|
237
239
|
};
|
|
238
240
|
const respWithCookies = handleCookies(compatibleResp);
|
|
239
241
|
return {
|
|
240
|
-
...composeNextState(state, respWithCookies.data),
|
|
242
|
+
...(0, import_language_common.composeNextState)(state, respWithCookies.data),
|
|
241
243
|
response: respWithCookies
|
|
242
244
|
};
|
|
243
245
|
}
|
|
@@ -248,83 +250,83 @@ function handleCallback(state, callback) {
|
|
|
248
250
|
}
|
|
249
251
|
function get(path, params, callback) {
|
|
250
252
|
return (state) => {
|
|
251
|
-
const resolvedPath = expandReferences(path)(state);
|
|
252
|
-
const resolvedParams = http.expandRequestReferences(params)(state);
|
|
253
|
+
const resolvedPath = (0, import_language_common.expandReferences)(path)(state);
|
|
254
|
+
const resolvedParams = import_language_common.http.expandRequestReferences(params)(state);
|
|
253
255
|
const url = setUrl(state.configuration, resolvedPath);
|
|
254
256
|
const auth = setAuth(
|
|
255
257
|
state.configuration,
|
|
256
258
|
(resolvedParams == null ? void 0 : resolvedParams.authentication) ?? (resolvedParams == null ? void 0 : resolvedParams.auth)
|
|
257
259
|
);
|
|
258
260
|
const config = mapToAxiosConfig({ ...resolvedParams, url, auth });
|
|
259
|
-
return http.get(config)(state).then((response) => handleResponse(state, response)).then((nextState) => handleCallback(nextState, callback));
|
|
261
|
+
return import_language_common.http.get(config)(state).then((response) => handleResponse(state, response)).then((nextState) => handleCallback(nextState, callback));
|
|
260
262
|
};
|
|
261
263
|
}
|
|
262
264
|
function post(path, params, callback) {
|
|
263
265
|
return (state) => {
|
|
264
|
-
const resolvedPath = expandReferences(path)(state);
|
|
265
|
-
const resolvedParams = http.expandRequestReferences(params)(state);
|
|
266
|
+
const resolvedPath = (0, import_language_common.expandReferences)(path)(state);
|
|
267
|
+
const resolvedParams = import_language_common.http.expandRequestReferences(params)(state);
|
|
266
268
|
const url = setUrl(state.configuration, resolvedPath);
|
|
267
269
|
const auth = setAuth(
|
|
268
270
|
state.configuration,
|
|
269
271
|
(resolvedParams == null ? void 0 : resolvedParams.authentication) ?? (resolvedParams == null ? void 0 : resolvedParams.auth)
|
|
270
272
|
);
|
|
271
273
|
const config = mapToAxiosConfig({ ...resolvedParams, url, auth });
|
|
272
|
-
return http.post(config)(state).then((response) => handleResponse(state, response)).then((nextState) => handleCallback(nextState, callback));
|
|
274
|
+
return import_language_common.http.post(config)(state).then((response) => handleResponse(state, response)).then((nextState) => handleCallback(nextState, callback));
|
|
273
275
|
};
|
|
274
276
|
}
|
|
275
277
|
function put(path, params, callback) {
|
|
276
278
|
return (state) => {
|
|
277
|
-
const resolvedPath = expandReferences(path)(state);
|
|
278
|
-
const resolvedParams = http.expandRequestReferences(params)(state);
|
|
279
|
+
const resolvedPath = (0, import_language_common.expandReferences)(path)(state);
|
|
280
|
+
const resolvedParams = import_language_common.http.expandRequestReferences(params)(state);
|
|
279
281
|
const url = setUrl(state.configuration, resolvedPath);
|
|
280
282
|
const auth = setAuth(
|
|
281
283
|
state.configuration,
|
|
282
284
|
(resolvedParams == null ? void 0 : resolvedParams.authentication) ?? (resolvedParams == null ? void 0 : resolvedParams.auth)
|
|
283
285
|
);
|
|
284
286
|
const config = mapToAxiosConfig({ ...resolvedParams, url, auth });
|
|
285
|
-
return http.put(config)(state).then((response) => handleResponse(state, response)).then((nextState) => handleCallback(nextState, callback));
|
|
287
|
+
return import_language_common.http.put(config)(state).then((response) => handleResponse(state, response)).then((nextState) => handleCallback(nextState, callback));
|
|
286
288
|
};
|
|
287
289
|
}
|
|
288
290
|
function patch(path, params, callback) {
|
|
289
291
|
return (state) => {
|
|
290
|
-
const resolvedPath = expandReferences(path)(state);
|
|
291
|
-
const resolvedParams = http.expandRequestReferences(params)(state);
|
|
292
|
+
const resolvedPath = (0, import_language_common.expandReferences)(path)(state);
|
|
293
|
+
const resolvedParams = import_language_common.http.expandRequestReferences(params)(state);
|
|
292
294
|
const url = setUrl(state.configuration, resolvedPath);
|
|
293
295
|
const auth = setAuth(
|
|
294
296
|
state.configuration,
|
|
295
297
|
(resolvedParams == null ? void 0 : resolvedParams.authentication) ?? (resolvedParams == null ? void 0 : resolvedParams.auth)
|
|
296
298
|
);
|
|
297
299
|
const config = mapToAxiosConfig({ ...resolvedParams, url, auth });
|
|
298
|
-
return http.patch(config)(state).then((response) => handleResponse(state, response)).then((nextState) => handleCallback(nextState, callback));
|
|
300
|
+
return import_language_common.http.patch(config)(state).then((response) => handleResponse(state, response)).then((nextState) => handleCallback(nextState, callback));
|
|
299
301
|
};
|
|
300
302
|
}
|
|
301
303
|
function del(path, params, callback) {
|
|
302
304
|
return (state) => {
|
|
303
|
-
const resolvedPath = expandReferences(path)(state);
|
|
304
|
-
const resolvedParams = http.expandRequestReferences(params)(state);
|
|
305
|
+
const resolvedPath = (0, import_language_common.expandReferences)(path)(state);
|
|
306
|
+
const resolvedParams = import_language_common.http.expandRequestReferences(params)(state);
|
|
305
307
|
const url = setUrl(state.configuration, resolvedPath);
|
|
306
308
|
const auth = setAuth(
|
|
307
309
|
state.configuration,
|
|
308
310
|
(resolvedParams == null ? void 0 : resolvedParams.authentication) ?? resolvedParams.auth
|
|
309
311
|
);
|
|
310
312
|
const config = mapToAxiosConfig({ ...resolvedParams, url, auth });
|
|
311
|
-
return http.delete(config)(state).then((response) => handleResponse(state, response)).then((nextState) => handleCallback(nextState, callback));
|
|
313
|
+
return import_language_common.http.delete(config)(state).then((response) => handleResponse(state, response)).then((nextState) => handleCallback(nextState, callback));
|
|
312
314
|
};
|
|
313
315
|
}
|
|
314
316
|
function parseXML(body, script) {
|
|
315
317
|
return (state) => {
|
|
316
|
-
const $ =
|
|
317
|
-
|
|
318
|
+
const $ = import_cheerio.default.load(body);
|
|
319
|
+
(0, import_cheerio_tableparser.default)($);
|
|
318
320
|
if (script) {
|
|
319
321
|
const result = script($);
|
|
320
322
|
try {
|
|
321
323
|
const r = JSON.parse(result);
|
|
322
|
-
return composeNextState(state, r);
|
|
324
|
+
return (0, import_language_common.composeNextState)(state, r);
|
|
323
325
|
} catch (e) {
|
|
324
|
-
return composeNextState(state, { body: result });
|
|
326
|
+
return (0, import_language_common.composeNextState)(state, { body: result });
|
|
325
327
|
}
|
|
326
328
|
} else {
|
|
327
|
-
return composeNextState(state, { body });
|
|
329
|
+
return (0, import_language_common.composeNextState)(state, { body });
|
|
328
330
|
}
|
|
329
331
|
};
|
|
330
332
|
}
|
|
@@ -333,24 +335,24 @@ function parseCSV(target, config) {
|
|
|
333
335
|
return new Promise((resolve, reject) => {
|
|
334
336
|
var csvData = [];
|
|
335
337
|
try {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
+
import_fs.default.readFileSync(target);
|
|
339
|
+
import_fs.default.createReadStream(target).pipe((0, import_csv_parse.default)(config)).on("data", (csvrow) => {
|
|
338
340
|
console.log(csvrow);
|
|
339
341
|
csvData.push(csvrow);
|
|
340
342
|
}).on("end", () => {
|
|
341
343
|
console.log(csvData);
|
|
342
|
-
resolve(composeNextState(state, csvData));
|
|
344
|
+
resolve((0, import_language_common.composeNextState)(state, csvData));
|
|
343
345
|
});
|
|
344
346
|
} catch (err) {
|
|
345
347
|
var csvString;
|
|
346
348
|
if (typeof target === "string") {
|
|
347
349
|
csvString = target;
|
|
348
350
|
} else {
|
|
349
|
-
csvString = expandReferences(target)(state);
|
|
351
|
+
csvString = (0, import_language_common.expandReferences)(target)(state);
|
|
350
352
|
}
|
|
351
|
-
csvData =
|
|
353
|
+
csvData = (0, import_csv_parse.default)(csvString, config, (err2, output) => {
|
|
352
354
|
console.log(output);
|
|
353
|
-
resolve(composeNextState(state, output));
|
|
355
|
+
resolve((0, import_language_common.composeNextState)(state, output));
|
|
354
356
|
});
|
|
355
357
|
}
|
|
356
358
|
});
|
|
@@ -358,9 +360,9 @@ function parseCSV(target, config) {
|
|
|
358
360
|
}
|
|
359
361
|
function request(params) {
|
|
360
362
|
return (state) => {
|
|
361
|
-
const resolvedParams = http.expandRequestReferences(params)(state);
|
|
363
|
+
const resolvedParams = import_language_common.http.expandRequestReferences(params)(state);
|
|
362
364
|
return new Promise((resolve, reject) => {
|
|
363
|
-
|
|
365
|
+
(0, import_request.default)(resolvedParams, (error, response, body) => {
|
|
364
366
|
error = assembleError({ error, response, resolvedParams });
|
|
365
367
|
error && reject(error);
|
|
366
368
|
console.log(
|
|
@@ -375,7 +377,7 @@ function request(params) {
|
|
|
375
377
|
|
|
376
378
|
// src/index.js
|
|
377
379
|
var src_default = Adaptor_exports;
|
|
378
|
-
export
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
};
|
|
380
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
381
|
+
0 && (module.exports = {
|
|
382
|
+
Adaptor
|
|
383
|
+
});
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-http",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "An HTTP request language package for use with Open Function",
|
|
5
5
|
"homepage": "https://docs.openfn.org",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/openfn/adaptors.git"
|
|
9
9
|
},
|
|
10
|
-
"main": "dist/index.
|
|
10
|
+
"main": "dist/index.cjs",
|
|
11
11
|
"type": "module",
|
|
12
12
|
"types": "types/index.d.ts",
|
|
13
13
|
"author": "Open Function Group",
|