@openfn/language-http 6.4.0 → 6.4.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.
Files changed (3) hide show
  1. package/ast.json +214 -65
  2. package/package.json +2 -2
  3. package/types/Adaptor.d.ts +28 -29
package/ast.json CHANGED
@@ -1,5 +1,112 @@
1
1
  {
2
2
  "operations": [
3
+ {
4
+ "name": "execute",
5
+ "params": [
6
+ "operations"
7
+ ],
8
+ "docs": {
9
+ "description": "Options provided to the HTTP request",
10
+ "tags": [
11
+ {
12
+ "title": "typedef",
13
+ "description": null,
14
+ "type": {
15
+ "type": "NameExpression",
16
+ "name": "Object"
17
+ },
18
+ "name": "RequestOptions"
19
+ },
20
+ {
21
+ "title": "public",
22
+ "description": null,
23
+ "type": null
24
+ },
25
+ {
26
+ "title": "property",
27
+ "description": "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).",
28
+ "type": {
29
+ "type": "UnionType",
30
+ "elements": [
31
+ {
32
+ "type": "NameExpression",
33
+ "name": "object"
34
+ },
35
+ {
36
+ "type": "NameExpression",
37
+ "name": "string"
38
+ }
39
+ ]
40
+ },
41
+ "name": "body"
42
+ },
43
+ {
44
+ "title": "property",
45
+ "description": "Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors for this code.",
46
+ "type": {
47
+ "type": "NameExpression",
48
+ "name": "object"
49
+ },
50
+ "name": "errors"
51
+ },
52
+ {
53
+ "title": "property",
54
+ "description": "Pass a JSON object to be serialised into a multipart HTML form (as FormData) in the body.",
55
+ "type": {
56
+ "type": "NameExpression",
57
+ "name": "object"
58
+ },
59
+ "name": "form"
60
+ },
61
+ {
62
+ "title": "property",
63
+ "description": "An object of query parameters to be encoded into the URL.",
64
+ "type": {
65
+ "type": "NameExpression",
66
+ "name": "object"
67
+ },
68
+ "name": "query"
69
+ },
70
+ {
71
+ "title": "property",
72
+ "description": "An object of headers to append to the request.",
73
+ "type": {
74
+ "type": "NameExpression",
75
+ "name": "object"
76
+ },
77
+ "name": "headers"
78
+ },
79
+ {
80
+ "title": "property",
81
+ "description": "Parse the response body as json, text or stream. By default will use the response headers.",
82
+ "type": {
83
+ "type": "NameExpression",
84
+ "name": "string"
85
+ },
86
+ "name": "parseAs"
87
+ },
88
+ {
89
+ "title": "property",
90
+ "description": "Request timeout in ms. Default: 300 seconds.",
91
+ "type": {
92
+ "type": "NameExpression",
93
+ "name": "number"
94
+ },
95
+ "name": "timeout"
96
+ },
97
+ {
98
+ "title": "property",
99
+ "description": "TLS/SSL authentication options. See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions",
100
+ "type": {
101
+ "type": "NameExpression",
102
+ "name": "object"
103
+ },
104
+ "name": "tls"
105
+ }
106
+ ]
107
+ },
108
+ "valid": false
109
+ },
3
110
  {
4
111
  "name": "request",
5
112
  "params": [
@@ -61,6 +168,10 @@
61
168
  },
62
169
  "name": "callback"
63
170
  },
171
+ {
172
+ "title": "state",
173
+ "description": "{HttpState}"
174
+ },
64
175
  {
65
176
  "title": "returns",
66
177
  "description": null,
@@ -124,6 +235,10 @@
124
235
  },
125
236
  "name": "callback"
126
237
  },
238
+ {
239
+ "title": "state",
240
+ "description": "{HttpState}"
241
+ },
127
242
  {
128
243
  "title": "returns",
129
244
  "description": null,
@@ -187,6 +302,10 @@
187
302
  },
188
303
  "name": "callback"
189
304
  },
305
+ {
306
+ "title": "state",
307
+ "description": "{HttpState}"
308
+ },
190
309
  {
191
310
  "title": "returns",
192
311
  "description": null,
@@ -250,6 +369,10 @@
250
369
  },
251
370
  "name": "callback"
252
371
  },
372
+ {
373
+ "title": "state",
374
+ "description": "{HttpState}"
375
+ },
253
376
  {
254
377
  "title": "returns",
255
378
  "description": null,
@@ -313,6 +436,10 @@
313
436
  },
314
437
  "name": "callback"
315
438
  },
439
+ {
440
+ "title": "state",
441
+ "description": "{HttpState}"
442
+ },
316
443
  {
317
444
  "title": "returns",
318
445
  "description": null,
@@ -376,6 +503,10 @@
376
503
  },
377
504
  "name": "callback"
378
505
  },
506
+ {
507
+ "title": "state",
508
+ "description": "{HttpState}"
509
+ },
379
510
  {
380
511
  "title": "returns",
381
512
  "description": null,
@@ -444,6 +575,14 @@
444
575
  },
445
576
  "name": "callback"
446
577
  },
578
+ {
579
+ "title": "state",
580
+ "description": "data - the parsed XML as a JSON object"
581
+ },
582
+ {
583
+ "title": "state",
584
+ "description": "references - an array of all previous data objects used in the Job"
585
+ },
447
586
  {
448
587
  "title": "returns",
449
588
  "description": null,
@@ -472,15 +611,15 @@
472
611
  "description": null,
473
612
  "type": null
474
613
  },
475
- {
476
- "title": "example",
477
- "description": "fn(state => {\n // do some things to state\n return state;\n});"
478
- },
479
614
  {
480
615
  "title": "function",
481
616
  "description": null,
482
617
  "name": null
483
618
  },
619
+ {
620
+ "title": "example",
621
+ "description": "fn(state => {\n // do some things to state\n return state;\n});"
622
+ },
484
623
  {
485
624
  "title": "param",
486
625
  "description": "is the function",
@@ -516,15 +655,15 @@
516
655
  "description": null,
517
656
  "type": null
518
657
  },
519
- {
520
- "title": "example",
521
- "description": "fnIf((state) => state?.data?.name, get(\"https://example.com\"));"
522
- },
523
658
  {
524
659
  "title": "function",
525
660
  "description": null,
526
661
  "name": null
527
662
  },
663
+ {
664
+ "title": "example",
665
+ "description": "fnIf((state) => state?.data?.name, get(\"https://example.com\"));"
666
+ },
528
667
  {
529
668
  "title": "param",
530
669
  "description": "The condition that returns true",
@@ -568,15 +707,15 @@
568
707
  "description": null,
569
708
  "type": null
570
709
  },
571
- {
572
- "title": "example",
573
- "description": "sourceValue('$.key')"
574
- },
575
710
  {
576
711
  "title": "function",
577
712
  "description": null,
578
713
  "name": null
579
714
  },
715
+ {
716
+ "title": "example",
717
+ "description": "sourceValue('$.key')"
718
+ },
580
719
  {
581
720
  "title": "param",
582
721
  "description": "JSONPath referencing a point in `state`.",
@@ -611,15 +750,15 @@
611
750
  "description": null,
612
751
  "type": null
613
752
  },
614
- {
615
- "title": "example",
616
- "description": "dataPath('key')"
617
- },
618
753
  {
619
754
  "title": "function",
620
755
  "description": null,
621
756
  "name": null
622
757
  },
758
+ {
759
+ "title": "example",
760
+ "description": "dataPath('key')"
761
+ },
623
762
  {
624
763
  "title": "param",
625
764
  "description": "JSONPath referencing a point in `data`.",
@@ -654,15 +793,15 @@
654
793
  "description": null,
655
794
  "type": null
656
795
  },
657
- {
658
- "title": "example",
659
- "description": "dataValue('key')"
660
- },
661
796
  {
662
797
  "title": "function",
663
798
  "description": null,
664
799
  "name": null
665
800
  },
801
+ {
802
+ "title": "example",
803
+ "description": "dataValue('key')"
804
+ },
666
805
  {
667
806
  "title": "param",
668
807
  "description": "JSONPath referencing a point in `data`.",
@@ -697,15 +836,15 @@
697
836
  "description": null,
698
837
  "type": null
699
838
  },
700
- {
701
- "title": "example",
702
- "description": "lastReferenceValue('key')"
703
- },
704
839
  {
705
840
  "title": "function",
706
841
  "description": null,
707
842
  "name": null
708
843
  },
844
+ {
845
+ "title": "example",
846
+ "description": "lastReferenceValue('key')"
847
+ },
709
848
  {
710
849
  "title": "param",
711
850
  "description": "JSONPath referencing a point in `references`.",
@@ -741,15 +880,15 @@
741
880
  "description": null,
742
881
  "type": null
743
882
  },
744
- {
745
- "title": "example",
746
- "description": "each(\"$.[*]\",\n create(\"SObject\",\n field(\"FirstName\", sourceValue(\"$.firstName\"))\n )\n)"
747
- },
748
883
  {
749
884
  "title": "function",
750
885
  "description": null,
751
886
  "name": null
752
887
  },
888
+ {
889
+ "title": "example",
890
+ "description": "each(\"$.[*]\",\n create(\"SObject\",\n field(\"FirstName\", sourceValue(\"$.firstName\"))\n )\n)"
891
+ },
753
892
  {
754
893
  "title": "param",
755
894
  "description": "JSONPath referencing a point in `state`.",
@@ -793,15 +932,15 @@
793
932
  "description": null,
794
933
  "type": null
795
934
  },
796
- {
797
- "title": "example",
798
- "description": "combine(\n create('foo'),\n delete('bar')\n)"
799
- },
800
935
  {
801
936
  "title": "function",
802
937
  "description": null,
803
938
  "name": null
804
939
  },
940
+ {
941
+ "title": "example",
942
+ "description": "combine(\n create('foo'),\n delete('bar')\n)"
943
+ },
805
944
  {
806
945
  "title": "param",
807
946
  "description": "Operations to be performed.",
@@ -837,15 +976,15 @@
837
976
  "description": null,
838
977
  "type": null
839
978
  },
840
- {
841
- "title": "example",
842
- "description": "field('destination_field_name__c', 'value')"
843
- },
844
979
  {
845
980
  "title": "function",
846
981
  "description": null,
847
982
  "name": null
848
983
  },
984
+ {
985
+ "title": "example",
986
+ "description": "field('destination_field_name__c', 'value')"
987
+ },
849
988
  {
850
989
  "title": "param",
851
990
  "description": "Name of the field",
@@ -889,15 +1028,15 @@
889
1028
  "description": null,
890
1029
  "type": null
891
1030
  },
892
- {
893
- "title": "example",
894
- "description": "fields(list_of_fields)"
895
- },
896
1031
  {
897
1032
  "title": "function",
898
1033
  "description": null,
899
1034
  "name": null
900
1035
  },
1036
+ {
1037
+ "title": "example",
1038
+ "description": "fields(list_of_fields)"
1039
+ },
901
1040
  {
902
1041
  "title": "param",
903
1042
  "description": "a list of fields",
@@ -942,6 +1081,11 @@
942
1081
  "description": null,
943
1082
  "name": null
944
1083
  },
1084
+ {
1085
+ "title": "public",
1086
+ "description": null,
1087
+ "type": null
1088
+ },
945
1089
  {
946
1090
  "title": "param",
947
1091
  "description": null,
@@ -996,6 +1140,11 @@
996
1140
  "description": null,
997
1141
  "name": null
998
1142
  },
1143
+ {
1144
+ "title": "public",
1145
+ "description": null,
1146
+ "type": null
1147
+ },
999
1148
  {
1000
1149
  "title": "param",
1001
1150
  "description": "The array of objects to be grouped.",
@@ -1058,15 +1207,15 @@
1058
1207
  "description": null,
1059
1208
  "type": null
1060
1209
  },
1061
- {
1062
- "title": "example",
1063
- "description": "field(\"destination_string__c\", function(state) {\n return arrayToString(dataValue(\"path_of_array\")(state), ', ')\n})"
1064
- },
1065
1210
  {
1066
1211
  "title": "function",
1067
1212
  "description": null,
1068
1213
  "name": null
1069
1214
  },
1215
+ {
1216
+ "title": "example",
1217
+ "description": "field(\"destination_string__c\", function(state) {\n return arrayToString(dataValue(\"path_of_array\")(state), ', ')\n})"
1218
+ },
1070
1219
  {
1071
1220
  "title": "param",
1072
1221
  "description": "Array of toString'able primatives.",
@@ -1110,15 +1259,15 @@
1110
1259
  "description": null,
1111
1260
  "type": null
1112
1261
  },
1113
- {
1114
- "title": "example",
1115
- "description": "each(function(state) {\n return toArray( dataValue(\"path_of_array\")(state) )\n}, ...)"
1116
- },
1117
1262
  {
1118
1263
  "title": "function",
1119
1264
  "description": null,
1120
1265
  "name": null
1121
1266
  },
1267
+ {
1268
+ "title": "example",
1269
+ "description": "each(function(state) {\n return toArray( dataValue(\"path_of_array\")(state) )\n}, ...)"
1270
+ },
1122
1271
  {
1123
1272
  "title": "param",
1124
1273
  "description": "Data required to be in an array",
@@ -1153,15 +1302,15 @@
1153
1302
  "description": null,
1154
1303
  "type": null
1155
1304
  },
1156
- {
1157
- "title": "example",
1158
- "description": "field(\"destination_string__c\", humanProper(state.data.path_to_string))"
1159
- },
1160
1305
  {
1161
1306
  "title": "function",
1162
1307
  "description": null,
1163
1308
  "name": null
1164
1309
  },
1310
+ {
1311
+ "title": "example",
1312
+ "description": "field(\"destination_string__c\", humanProper(state.data.path_to_string))"
1313
+ },
1165
1314
  {
1166
1315
  "title": "param",
1167
1316
  "description": "String that needs converting",
@@ -1264,15 +1413,15 @@
1264
1413
  "description": null,
1265
1414
  "type": null
1266
1415
  },
1267
- {
1268
- "title": "example",
1269
- "description": "scrubEmojis('Dove🕊️⭐ 29')"
1270
- },
1271
1416
  {
1272
1417
  "title": "function",
1273
1418
  "description": null,
1274
1419
  "name": null
1275
1420
  },
1421
+ {
1422
+ "title": "example",
1423
+ "description": "scrubEmojis('Dove🕊️⭐ 29')"
1424
+ },
1276
1425
  {
1277
1426
  "title": "param",
1278
1427
  "description": "String that needs to be cleaned",
@@ -1317,15 +1466,15 @@
1317
1466
  "description": null,
1318
1467
  "type": null
1319
1468
  },
1320
- {
1321
- "title": "example",
1322
- "description": "chunk([1,2,3,4,5], 2)"
1323
- },
1324
1469
  {
1325
1470
  "title": "function",
1326
1471
  "description": null,
1327
1472
  "name": null
1328
1473
  },
1474
+ {
1475
+ "title": "example",
1476
+ "description": "chunk([1,2,3,4,5], 2)"
1477
+ },
1329
1478
  {
1330
1479
  "title": "param",
1331
1480
  "description": "Array to be chunked",
@@ -1444,6 +1593,11 @@
1444
1593
  "description": null,
1445
1594
  "type": null
1446
1595
  },
1596
+ {
1597
+ "title": "function",
1598
+ "description": null,
1599
+ "name": null
1600
+ },
1447
1601
  {
1448
1602
  "title": "example",
1449
1603
  "description": "cursor($.cursor, { defaultValue: 'today' })",
@@ -1454,11 +1608,6 @@
1454
1608
  "description": "cursor(22)",
1455
1609
  "caption": "Use a pagination cursor"
1456
1610
  },
1457
- {
1458
- "title": "function",
1459
- "description": null,
1460
- "name": null
1461
- },
1462
1611
  {
1463
1612
  "title": "param",
1464
1613
  "description": "the cursor value. Usually an ISO date, natural language date, or page number",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-http",
3
- "version": "6.4.0",
3
+ "version": "6.4.1",
4
4
  "description": "An HTTP request language package for use with Open Function",
5
5
  "homepage": "https://docs.openfn.org",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "dependencies": {
28
28
  "cheerio": "1.0.0-rc.12",
29
29
  "cheerio-tableparser": "^1.0.1",
30
- "@openfn/language-common": "1.15.0"
30
+ "@openfn/language-common": "1.15.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@openfn/simple-ast": "0.4.1",
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Options provided to the HTTP request
3
3
  * @typedef {Object} RequestOptions
4
+ * @public
4
5
  * @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
6
  * @property {object} errors - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors for this code.
6
7
  * @property {object} form - Pass a JSON object to be serialised into a multipart HTML form (as FormData) in the body.
@@ -11,14 +12,20 @@
11
12
  * @property {object} tls - TLS/SSL authentication options. See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions
12
13
  */
13
14
  /**
14
- * Execute a sequence of operations.
15
+ * State object
16
+ * @typedef {Object} HttpState
17
+ * @property data - the parsed response body
18
+ * @property response - the response from the HTTP server, including headers, statusCode, body, etc
19
+ * @property references - an array of all previous data objects used in the Job
20
+ **/
21
+ /**
22
+ * Execute a sequence of operations
15
23
  * Wraps `language-common/execute`, and prepends initial state for http.
16
24
  * @example
17
25
  * execute(
18
26
  * create('foo'),
19
27
  * delete('bar')
20
28
  * )(state)
21
- * @private
22
29
  * @param {Operations} operations - Operations to be performed.
23
30
  * @returns {Operation}
24
31
  */
@@ -40,6 +47,7 @@ export function execute(...operations: Operations): Operation;
40
47
  * @param {string} path - Path to resource
41
48
  * @param {RequestOptions} params - Query, Headers and Authentication parameters
42
49
  * @param {function} callback - (Optional) Callback function
50
+ * @state {HttpState}
43
51
  * @returns {Operation}
44
52
  */
45
53
  export function request(method: string, path: string, params: RequestOptions, callback: Function): Operation;
@@ -55,6 +63,7 @@ export function request(method: string, path: string, params: RequestOptions, ca
55
63
  * @param {string} path - Path to resource
56
64
  * @param {RequestOptions} params - Query, Headers and Authentication parameters
57
65
  * @param {function} callback - (Optional) Callback function
66
+ * @state {HttpState}
58
67
  * @returns {Operation}
59
68
  */
60
69
  export function get(path: string, params: RequestOptions, callback: Function): Operation;
@@ -70,6 +79,7 @@ export function get(path: string, params: RequestOptions, callback: Function): O
70
79
  * @param {string} path - Path to resource
71
80
  * @param {RequestOptions} params - Body, Query, Headers and Authentication parameters
72
81
  * @param {function} callback - (Optional) Callback function
82
+ * @state {HttpState}
73
83
  * @returns {operation}
74
84
  */
75
85
  export function post(path: string, params: RequestOptions, callback: Function): operation;
@@ -85,6 +95,7 @@ export function post(path: string, params: RequestOptions, callback: Function):
85
95
  * @param {string} path - Path to resource
86
96
  * @param {RequestOptions} params - Body, Query, Headers and Auth parameters
87
97
  * @param {function} callback - (Optional) Callback function
98
+ * @state {HttpState}
88
99
  * @returns {Operation}
89
100
  */
90
101
  export function put(path: string, params: RequestOptions, callback: Function): Operation;
@@ -100,6 +111,7 @@ export function put(path: string, params: RequestOptions, callback: Function): O
100
111
  * @param {string} path - Path to resource
101
112
  * @param {RequestOptions} params - Body, Query, Headers and Auth parameters
102
113
  * @param {function} callback - (Optional) Callback function
114
+ * @state {HttpState}
103
115
  * @returns {Operation}
104
116
  */
105
117
  export function patch(path: string, params: RequestOptions, callback: Function): Operation;
@@ -114,6 +126,7 @@ export function patch(path: string, params: RequestOptions, callback: Function):
114
126
  * @param {string} path - Path to resource
115
127
  * @param {RequestOptions} params - Body, Query, Headers and Auth parameters
116
128
  * @param {function} callback - (Optional) Callback function
129
+ * @state {HttpState}
117
130
  * @returns {Operation}
118
131
  */
119
132
  export function del(path: string, params: RequestOptions, callback: Function): Operation;
@@ -139,44 +152,30 @@ export function del(path: string, params: RequestOptions, callback: Function): O
139
152
  * @param {String} body - data string to be parsed
140
153
  * @param {function} script - script for extracting data
141
154
  * @param {function} callback - (Optional) Callback function
155
+ * @state data - the parsed XML as a JSON object
156
+ * @state references - an array of all previous data objects used in the Job
142
157
  * @returns {Operation}
143
158
  */
144
159
  export function parseXML(body: string, script: Function, callback: Function): Operation;
145
160
  /**
146
161
  * Options provided to the HTTP request
147
162
  */
148
- export type RequestOptions = {
149
- /**
150
- * - 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).
151
- */
152
- body: object | string;
153
- /**
154
- * - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors for this code.
155
- */
156
- errors: object;
157
- /**
158
- * - Pass a JSON object to be serialised into a multipart HTML form (as FormData) in the body.
159
- */
160
- form: object;
161
- /**
162
- * - An object of query parameters to be encoded into the URL.
163
- */
164
- query: object;
165
- /**
166
- * - An object of headers to append to the request.
167
- */
168
- headers: object;
163
+ export type RequestOptions = any;
164
+ /**
165
+ * State object
166
+ */
167
+ export type HttpState = {
169
168
  /**
170
- * - Parse the response body as json, text or stream. By default will use the response headers.
169
+ * - the parsed response body
171
170
  */
172
- parseAs: string;
171
+ data: any;
173
172
  /**
174
- * - Request timeout in ms. Default: 300 seconds.
173
+ * - the response from the HTTP server, including headers, statusCode, body, etc
175
174
  */
176
- timeout: number;
175
+ response: any;
177
176
  /**
178
- * - TLS/SSL authentication options. See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions
177
+ * - an array of all previous data objects used in the Job
179
178
  */
180
- tls: object;
179
+ references: any;
181
180
  };
182
181
  export { alterState, arrayToString, combine, cursor, dataPath, dataValue, dateFns, each, field, fields, fn, fnIf, chunk, group, humanProper, lastReferenceValue, merge, scrubEmojis, sourceValue, splitKeys, toArray, parseCsv } from "@openfn/language-common";