@openfn/language-commcare 3.0.0 → 3.1.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 +164 -176
- package/dist/index.cjs +16 -10
- package/dist/index.js +16 -10
- package/package.json +1 -1
- package/types/Adaptor.d.ts +73 -69
package/ast.json
CHANGED
|
@@ -1,139 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"operations": [
|
|
3
|
-
{
|
|
4
|
-
"name": "execute",
|
|
5
|
-
"params": [
|
|
6
|
-
"operations"
|
|
7
|
-
],
|
|
8
|
-
"docs": {
|
|
9
|
-
"description": "Queries provided to the GET request",
|
|
10
|
-
"tags": [
|
|
11
|
-
{
|
|
12
|
-
"title": "typedef",
|
|
13
|
-
"description": null,
|
|
14
|
-
"type": {
|
|
15
|
-
"type": "NameExpression",
|
|
16
|
-
"name": "Object"
|
|
17
|
-
},
|
|
18
|
-
"name": "RequestQueries"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"title": "public",
|
|
22
|
-
"description": null,
|
|
23
|
-
"type": null
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"title": "property",
|
|
27
|
-
"description": "The maximum number of records to return. Default: 20. Maximum: 5000.",
|
|
28
|
-
"type": {
|
|
29
|
-
"type": "NameExpression",
|
|
30
|
-
"name": "number"
|
|
31
|
-
},
|
|
32
|
-
"name": "limit"
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"title": "property",
|
|
36
|
-
"description": "The number of records to offset in the results. Default: 0",
|
|
37
|
-
"type": {
|
|
38
|
-
"type": "NameExpression",
|
|
39
|
-
"name": "number"
|
|
40
|
-
},
|
|
41
|
-
"name": "offset"
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
"title": "property",
|
|
45
|
-
"description": "Optional form XML namespace. See the [Commcare Docs](https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143979045/Finding+a+Form%27s+XMLNS)",
|
|
46
|
-
"type": {
|
|
47
|
-
"type": "NameExpression",
|
|
48
|
-
"name": "string"
|
|
49
|
-
},
|
|
50
|
-
"name": "xmlns"
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
"title": "property",
|
|
54
|
-
"description": "Optional date (and time). Will return only forms that have had data modified since the passed in date.",
|
|
55
|
-
"type": {
|
|
56
|
-
"type": "NameExpression",
|
|
57
|
-
"name": "string"
|
|
58
|
-
},
|
|
59
|
-
"name": "indexed_on_start"
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
"title": "property",
|
|
63
|
-
"description": "Optional date (and time). Will return only forms that have had data modified before the passed in date.",
|
|
64
|
-
"type": {
|
|
65
|
-
"type": "NameExpression",
|
|
66
|
-
"name": "string"
|
|
67
|
-
},
|
|
68
|
-
"name": "indexed_on_end"
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
"title": "property",
|
|
72
|
-
"description": "Optional date (and time). Will return only forms that were received after the passed in date.",
|
|
73
|
-
"type": {
|
|
74
|
-
"type": "NameExpression",
|
|
75
|
-
"name": "string"
|
|
76
|
-
},
|
|
77
|
-
"name": "received_on_start"
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
"title": "property",
|
|
81
|
-
"description": "Optional date (and time). Will return only forms that were received before the passed in date.",
|
|
82
|
-
"type": {
|
|
83
|
-
"type": "NameExpression",
|
|
84
|
-
"name": "string"
|
|
85
|
-
},
|
|
86
|
-
"name": "received_on_end"
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
"title": "property",
|
|
90
|
-
"description": "The returned records will be limited to the application defined",
|
|
91
|
-
"type": {
|
|
92
|
-
"type": "NameExpression",
|
|
93
|
-
"name": "string"
|
|
94
|
-
},
|
|
95
|
-
"name": "app_id"
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
"title": "property",
|
|
99
|
-
"description": "A case UUID. Will only return forms which updated that case.",
|
|
100
|
-
"type": {
|
|
101
|
-
"type": "NameExpression",
|
|
102
|
-
"name": "string"
|
|
103
|
-
},
|
|
104
|
-
"name": "case_id"
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
"title": "property",
|
|
108
|
-
"description": "Optional user of group UUID used when getting cases",
|
|
109
|
-
"type": {
|
|
110
|
-
"type": "NameExpression",
|
|
111
|
-
"name": "string"
|
|
112
|
-
},
|
|
113
|
-
"name": "owner_id"
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
"title": "property",
|
|
117
|
-
"description": "Optional UUID for all cases last modified by that user",
|
|
118
|
-
"type": {
|
|
119
|
-
"type": "NameExpression",
|
|
120
|
-
"name": "string"
|
|
121
|
-
},
|
|
122
|
-
"name": "user_id"
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
"title": "property",
|
|
126
|
-
"description": "Optional case type to get all matching cases",
|
|
127
|
-
"type": {
|
|
128
|
-
"type": "NameExpression",
|
|
129
|
-
"name": "string"
|
|
130
|
-
},
|
|
131
|
-
"name": "type"
|
|
132
|
-
}
|
|
133
|
-
]
|
|
134
|
-
},
|
|
135
|
-
"valid": false
|
|
136
|
-
},
|
|
137
3
|
{
|
|
138
4
|
"name": "get",
|
|
139
5
|
"params": [
|
|
@@ -142,27 +8,37 @@
|
|
|
142
8
|
"callback"
|
|
143
9
|
],
|
|
144
10
|
"docs": {
|
|
145
|
-
"description": "Make a GET request to any
|
|
11
|
+
"description": "Make a GET request to any CommCare endpoint. The response body will be returned to `state.data` as JSON.\nPaginated responses will be fully downloaded and returned as a single array, _unless_ an `offset` is passed.",
|
|
146
12
|
"tags": [
|
|
147
13
|
{
|
|
148
14
|
"title": "public",
|
|
149
15
|
"description": null,
|
|
150
16
|
"type": null
|
|
151
17
|
},
|
|
18
|
+
{
|
|
19
|
+
"title": "function",
|
|
20
|
+
"description": null,
|
|
21
|
+
"name": null
|
|
22
|
+
},
|
|
152
23
|
{
|
|
153
24
|
"title": "example",
|
|
154
|
-
"description": "get(\"case\"
|
|
155
|
-
"caption": "Get a
|
|
25
|
+
"description": "get(\"/case/12345\")",
|
|
26
|
+
"caption": "Get a specific case by id"
|
|
156
27
|
},
|
|
157
28
|
{
|
|
158
29
|
"title": "example",
|
|
159
|
-
"description": "get(\"case
|
|
160
|
-
"caption": "Get
|
|
30
|
+
"description": "get(\"/case\", { offset:0, limit: 20 })",
|
|
31
|
+
"caption": "Get exactly 20 cases"
|
|
161
32
|
},
|
|
162
33
|
{
|
|
163
|
-
"title": "
|
|
164
|
-
"description":
|
|
165
|
-
"
|
|
34
|
+
"title": "example",
|
|
35
|
+
"description": "get(\"/form\", { app_id: \"02bf50ab803a89ea4963799362874f0c\" })",
|
|
36
|
+
"caption": "Get forms by app id"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"title": "example",
|
|
40
|
+
"description": "get(\"/case\", {}, (state) => {\n state.cases.push(...state.data) // adds 50 cases to the cases array\n return state;\n})",
|
|
41
|
+
"caption": "Get all cases, 50 at a time, and add them to state"
|
|
166
42
|
},
|
|
167
43
|
{
|
|
168
44
|
"title": "param",
|
|
@@ -175,16 +51,19 @@
|
|
|
175
51
|
},
|
|
176
52
|
{
|
|
177
53
|
"title": "param",
|
|
178
|
-
"description": "
|
|
54
|
+
"description": "Input parameters for the request. These vary by endpoint, see {@link https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143957366/Data+APIs CommCare docs}.",
|
|
179
55
|
"type": {
|
|
180
|
-
"type": "
|
|
181
|
-
"
|
|
56
|
+
"type": "OptionalType",
|
|
57
|
+
"expression": {
|
|
58
|
+
"type": "NameExpression",
|
|
59
|
+
"name": "Object"
|
|
60
|
+
}
|
|
182
61
|
},
|
|
183
62
|
"name": "params"
|
|
184
63
|
},
|
|
185
64
|
{
|
|
186
65
|
"title": "param",
|
|
187
|
-
"description": "
|
|
66
|
+
"description": "Optional callback function. Invoked once per page of data retrieved.",
|
|
188
67
|
"type": {
|
|
189
68
|
"type": "OptionalType",
|
|
190
69
|
"expression": {
|
|
@@ -194,6 +73,10 @@
|
|
|
194
73
|
},
|
|
195
74
|
"name": "callback"
|
|
196
75
|
},
|
|
76
|
+
{
|
|
77
|
+
"title": "state",
|
|
78
|
+
"description": "{CommcareHttpState}"
|
|
79
|
+
},
|
|
197
80
|
{
|
|
198
81
|
"title": "returns",
|
|
199
82
|
"description": null,
|
|
@@ -215,11 +98,12 @@
|
|
|
215
98
|
"callback"
|
|
216
99
|
],
|
|
217
100
|
"docs": {
|
|
218
|
-
"description": "Make a
|
|
101
|
+
"description": "Make a POST request to any CommCare endpoint.",
|
|
219
102
|
"tags": [
|
|
220
103
|
{
|
|
221
104
|
"title": "example",
|
|
222
|
-
"description": "post(
|
|
105
|
+
"description": "post(\"/user\", { \"username\":\"test\", \"password\":\"somepassword\" })",
|
|
106
|
+
"caption": "Post a user object to to the /user endpoint"
|
|
223
107
|
},
|
|
224
108
|
{
|
|
225
109
|
"title": "function",
|
|
@@ -242,7 +126,7 @@
|
|
|
242
126
|
},
|
|
243
127
|
{
|
|
244
128
|
"title": "param",
|
|
245
|
-
"description": "Object or JSON
|
|
129
|
+
"description": "Object or JSON to use as the request body",
|
|
246
130
|
"type": {
|
|
247
131
|
"type": "NameExpression",
|
|
248
132
|
"name": "object"
|
|
@@ -251,10 +135,13 @@
|
|
|
251
135
|
},
|
|
252
136
|
{
|
|
253
137
|
"title": "param",
|
|
254
|
-
"description": "Optional request params
|
|
138
|
+
"description": "Optional request params",
|
|
255
139
|
"type": {
|
|
256
|
-
"type": "
|
|
257
|
-
"
|
|
140
|
+
"type": "OptionalType",
|
|
141
|
+
"expression": {
|
|
142
|
+
"type": "NameExpression",
|
|
143
|
+
"name": "Object"
|
|
144
|
+
}
|
|
258
145
|
},
|
|
259
146
|
"name": "params"
|
|
260
147
|
},
|
|
@@ -277,6 +164,10 @@
|
|
|
277
164
|
"type": "NameExpression",
|
|
278
165
|
"name": "Operation"
|
|
279
166
|
}
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"title": "state",
|
|
170
|
+
"description": "{CommcareHttpState}"
|
|
280
171
|
}
|
|
281
172
|
]
|
|
282
173
|
},
|
|
@@ -285,44 +176,49 @@
|
|
|
285
176
|
{
|
|
286
177
|
"name": "submitXls",
|
|
287
178
|
"params": [
|
|
288
|
-
"
|
|
179
|
+
"data",
|
|
289
180
|
"params"
|
|
290
181
|
],
|
|
291
182
|
"docs": {
|
|
292
|
-
"description": "
|
|
183
|
+
"description": "Bulk upload data to CommCare. Accepts an array of objects, converts them into\nan XLS representation, and uploads.",
|
|
293
184
|
"tags": [
|
|
294
185
|
{
|
|
295
186
|
"title": "public",
|
|
296
187
|
"description": null,
|
|
297
188
|
"type": null
|
|
298
189
|
},
|
|
299
|
-
{
|
|
300
|
-
"title": "example",
|
|
301
|
-
"description": "submitXls(\n [\n {name: 'Mamadou', phone: '000000'},\n ],\n {\n case_type: 'student',\n search_field: 'external_id',\n create_new_cases: 'on',\n }\n)"
|
|
302
|
-
},
|
|
303
190
|
{
|
|
304
191
|
"title": "function",
|
|
305
192
|
"description": null,
|
|
306
193
|
"name": null
|
|
307
194
|
},
|
|
195
|
+
{
|
|
196
|
+
"title": "example",
|
|
197
|
+
"description": "submitXls(\n [\n {name: 'Mamadou', phone: '000000'},\n ],\n {\n case_type: 'student',\n search_field: 'external_id',\n create_new_cases: 'on',\n }\n)",
|
|
198
|
+
"caption": "Upload a single row of data"
|
|
199
|
+
},
|
|
308
200
|
{
|
|
309
201
|
"title": "param",
|
|
310
|
-
"description": "
|
|
202
|
+
"description": "Array of objects to upload",
|
|
311
203
|
"type": {
|
|
312
204
|
"type": "NameExpression",
|
|
313
|
-
"name": "
|
|
205
|
+
"name": "array"
|
|
314
206
|
},
|
|
315
|
-
"name": "
|
|
207
|
+
"name": "data"
|
|
316
208
|
},
|
|
317
209
|
{
|
|
318
210
|
"title": "param",
|
|
319
|
-
"description": "
|
|
211
|
+
"description": "Input parameters, see {@link https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143946459/Bulk+Upload+Case+Data CommCare docs}.",
|
|
320
212
|
"type": {
|
|
321
213
|
"type": "NameExpression",
|
|
322
|
-
"name": "
|
|
214
|
+
"name": "Object"
|
|
323
215
|
},
|
|
324
216
|
"name": "params"
|
|
325
217
|
},
|
|
218
|
+
{
|
|
219
|
+
"title": "state",
|
|
220
|
+
"description": "data - the response from the CommCare Server"
|
|
221
|
+
},
|
|
326
222
|
{
|
|
327
223
|
"title": "returns",
|
|
328
224
|
"description": null,
|
|
@@ -338,33 +234,38 @@
|
|
|
338
234
|
{
|
|
339
235
|
"name": "submit",
|
|
340
236
|
"params": [
|
|
341
|
-
"
|
|
237
|
+
"data"
|
|
342
238
|
],
|
|
343
239
|
"docs": {
|
|
344
|
-
"description": "Submit form
|
|
240
|
+
"description": "Submit forms to CommCare. Accepts an array of JSON\nobjects, converts them into XML, and submits to CommCare as an x-form.",
|
|
345
241
|
"tags": [
|
|
346
242
|
{
|
|
347
243
|
"title": "public",
|
|
348
244
|
"description": null,
|
|
349
245
|
"type": null
|
|
350
246
|
},
|
|
351
|
-
{
|
|
352
|
-
"title": "example",
|
|
353
|
-
"description": "submit(\n fields(\n field(\"@\", function(state) {\n return {\n \"xmlns\": \"http://openrosa.org/formdesigner/form-id-here\"\n };\n }),\n field(\"question1\", dataValue(\"answer1\")),\n field(\"question2\", \"Some answer here.\")\n )\n )"
|
|
354
|
-
},
|
|
355
247
|
{
|
|
356
248
|
"title": "function",
|
|
357
249
|
"description": null,
|
|
358
250
|
"name": null
|
|
359
251
|
},
|
|
252
|
+
{
|
|
253
|
+
"title": "example",
|
|
254
|
+
"description": "submit(\n fields(\n field(\"@\", (state) => ({\n \"xmlns\": `http://openrosa.org/formdesigner/${state.formId}`\n }),\n field(\"question1\", (state) => state.data.answer1),\n field(\"question2\", (state) => state.data.answer2),\n )\n )",
|
|
255
|
+
"caption": "Submit a form to CommCare"
|
|
256
|
+
},
|
|
360
257
|
{
|
|
361
258
|
"title": "param",
|
|
362
|
-
"description": "
|
|
259
|
+
"description": "The form as a JSON object",
|
|
363
260
|
"type": {
|
|
364
261
|
"type": "NameExpression",
|
|
365
262
|
"name": "Object"
|
|
366
263
|
},
|
|
367
|
-
"name": "
|
|
264
|
+
"name": "data"
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
"title": "state",
|
|
268
|
+
"description": "data - the response from the CommCare Server"
|
|
368
269
|
},
|
|
369
270
|
{
|
|
370
271
|
"title": "returns",
|
|
@@ -386,7 +287,7 @@
|
|
|
386
287
|
"postUrl"
|
|
387
288
|
],
|
|
388
289
|
"docs": {
|
|
389
|
-
"description": "Make a GET request to CommCare's Reports API\nand POST the response
|
|
290
|
+
"description": "Make a GET request to CommCare's Reports API\nand POST the response somewhere else.",
|
|
390
291
|
"tags": [
|
|
391
292
|
{
|
|
392
293
|
"title": "public",
|
|
@@ -395,7 +296,8 @@
|
|
|
395
296
|
},
|
|
396
297
|
{
|
|
397
298
|
"title": "example",
|
|
398
|
-
"description": "fetchReportData(
|
|
299
|
+
"description": "fetchReportData(\n \"9aab0eeb88555a7b4568676883e7379a\",\n { limit: 10 },\n \"https://www.example.com/api/\"\n)",
|
|
300
|
+
"caption": "Fetch 10 records from a report and post them to example.com"
|
|
399
301
|
},
|
|
400
302
|
{
|
|
401
303
|
"title": "function",
|
|
@@ -413,16 +315,16 @@
|
|
|
413
315
|
},
|
|
414
316
|
{
|
|
415
317
|
"title": "param",
|
|
416
|
-
"description": "
|
|
318
|
+
"description": "Input parameters for the request, see {@link https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143957341/Download+Report+Data Commcare docs}.",
|
|
417
319
|
"type": {
|
|
418
320
|
"type": "NameExpression",
|
|
419
|
-
"name": "
|
|
321
|
+
"name": "Object"
|
|
420
322
|
},
|
|
421
323
|
"name": "params"
|
|
422
324
|
},
|
|
423
325
|
{
|
|
424
326
|
"title": "param",
|
|
425
|
-
"description": "
|
|
327
|
+
"description": "URL to which the response object will be posted.",
|
|
426
328
|
"type": {
|
|
427
329
|
"type": "NameExpression",
|
|
428
330
|
"name": "String"
|
|
@@ -1014,6 +916,92 @@
|
|
|
1014
916
|
]
|
|
1015
917
|
},
|
|
1016
918
|
"valid": true
|
|
919
|
+
},
|
|
920
|
+
{
|
|
921
|
+
"name": "cursor",
|
|
922
|
+
"params": [
|
|
923
|
+
"value",
|
|
924
|
+
"options"
|
|
925
|
+
],
|
|
926
|
+
"docs": {
|
|
927
|
+
"description": "Sets a cursor property on state.\nSupports natural language dates like `now`, `today`, `yesterday`, `n hours ago`, `n days ago`, and `start`,\nwhich will be converted relative to the environment (ie, the Lightning or CLI locale). Custom timezones\nare not yet supported.\nYou can provide a formatter to customise the final cursor value, which is useful for normalising\ndifferent inputs. The custom formatter runs after natural language date conversion.\nSee the usage guide at {@link https://docs.openfn.org/documentation/jobs/job-writing-guide#using-cursors}",
|
|
928
|
+
"tags": [
|
|
929
|
+
{
|
|
930
|
+
"title": "public",
|
|
931
|
+
"description": null,
|
|
932
|
+
"type": null
|
|
933
|
+
},
|
|
934
|
+
{
|
|
935
|
+
"title": "function",
|
|
936
|
+
"description": null,
|
|
937
|
+
"name": null
|
|
938
|
+
},
|
|
939
|
+
{
|
|
940
|
+
"title": "example",
|
|
941
|
+
"description": "cursor($.cursor, { defaultValue: 'today' })",
|
|
942
|
+
"caption": "Use a cursor from state if present, or else use the default value"
|
|
943
|
+
},
|
|
944
|
+
{
|
|
945
|
+
"title": "example",
|
|
946
|
+
"description": "cursor(22)",
|
|
947
|
+
"caption": "Use a pagination cursor"
|
|
948
|
+
},
|
|
949
|
+
{
|
|
950
|
+
"title": "param",
|
|
951
|
+
"description": "the cursor value. Usually an ISO date, natural language date, or page number",
|
|
952
|
+
"type": {
|
|
953
|
+
"type": "NameExpression",
|
|
954
|
+
"name": "any"
|
|
955
|
+
},
|
|
956
|
+
"name": "value"
|
|
957
|
+
},
|
|
958
|
+
{
|
|
959
|
+
"title": "param",
|
|
960
|
+
"description": "options to control the cursor.",
|
|
961
|
+
"type": {
|
|
962
|
+
"type": "NameExpression",
|
|
963
|
+
"name": "object"
|
|
964
|
+
},
|
|
965
|
+
"name": "options"
|
|
966
|
+
},
|
|
967
|
+
{
|
|
968
|
+
"title": "param",
|
|
969
|
+
"description": "set the cursor key. Will persist through the whole run.",
|
|
970
|
+
"type": {
|
|
971
|
+
"type": "NameExpression",
|
|
972
|
+
"name": "string"
|
|
973
|
+
},
|
|
974
|
+
"name": "options.key"
|
|
975
|
+
},
|
|
976
|
+
{
|
|
977
|
+
"title": "param",
|
|
978
|
+
"description": "the value to use if value is falsy",
|
|
979
|
+
"type": {
|
|
980
|
+
"type": "NameExpression",
|
|
981
|
+
"name": "any"
|
|
982
|
+
},
|
|
983
|
+
"name": "options.defaultValue"
|
|
984
|
+
},
|
|
985
|
+
{
|
|
986
|
+
"title": "param",
|
|
987
|
+
"description": "custom formatter for the final cursor value",
|
|
988
|
+
"type": {
|
|
989
|
+
"type": "NameExpression",
|
|
990
|
+
"name": "Function"
|
|
991
|
+
},
|
|
992
|
+
"name": "options.format"
|
|
993
|
+
},
|
|
994
|
+
{
|
|
995
|
+
"title": "returns",
|
|
996
|
+
"description": null,
|
|
997
|
+
"type": {
|
|
998
|
+
"type": "NameExpression",
|
|
999
|
+
"name": "Operation"
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
]
|
|
1003
|
+
},
|
|
1004
|
+
"valid": false
|
|
1017
1005
|
}
|
|
1018
1006
|
]
|
|
1019
1007
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -28,8 +28,10 @@ __export(src_exports, {
|
|
|
28
28
|
alterState: () => import_language_common3.alterState,
|
|
29
29
|
arrayToString: () => import_language_common3.arrayToString,
|
|
30
30
|
combine: () => import_language_common3.combine,
|
|
31
|
+
cursor: () => import_language_common3.cursor,
|
|
31
32
|
dataPath: () => import_language_common3.dataPath,
|
|
32
33
|
dataValue: () => import_language_common3.dataValue,
|
|
34
|
+
dateFns: () => import_language_common3.dateFns,
|
|
33
35
|
default: () => src_default,
|
|
34
36
|
each: () => import_language_common3.each,
|
|
35
37
|
execute: () => execute,
|
|
@@ -55,8 +57,10 @@ __export(Adaptor_exports, {
|
|
|
55
57
|
alterState: () => import_language_common3.alterState,
|
|
56
58
|
arrayToString: () => import_language_common3.arrayToString,
|
|
57
59
|
combine: () => import_language_common3.combine,
|
|
60
|
+
cursor: () => import_language_common3.cursor,
|
|
58
61
|
dataPath: () => import_language_common3.dataPath,
|
|
59
62
|
dataValue: () => import_language_common3.dataValue,
|
|
63
|
+
dateFns: () => import_language_common3.dateFns,
|
|
60
64
|
each: () => import_language_common3.each,
|
|
61
65
|
execute: () => execute,
|
|
62
66
|
fetchReportData: () => fetchReportData,
|
|
@@ -227,10 +231,10 @@ function post(path, data, params = {}, callback = (s) => s) {
|
|
|
227
231
|
}
|
|
228
232
|
};
|
|
229
233
|
}
|
|
230
|
-
function submitXls(
|
|
234
|
+
function submitXls(data, params) {
|
|
231
235
|
return async (state) => {
|
|
232
236
|
const { domain } = state.configuration;
|
|
233
|
-
const [json] = (0, import_util2.expandReferences)(state,
|
|
237
|
+
const [json] = (0, import_util2.expandReferences)(state, data);
|
|
234
238
|
const { case_type, search_field, create_new_cases } = params;
|
|
235
239
|
const path = `/a/${domain}/importer/excel/bulk_upload_api/`;
|
|
236
240
|
const workbook = import_xlsx.default.utils.book_new();
|
|
@@ -238,15 +242,15 @@ function submitXls(formData, params) {
|
|
|
238
242
|
const ws_name = "SheetJS";
|
|
239
243
|
import_xlsx.default.utils.book_append_sheet(workbook, worksheet, ws_name);
|
|
240
244
|
const buffer = import_xlsx.default.write(workbook, { type: "buffer", bookType: "xls" });
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
245
|
+
const form = new FormData();
|
|
246
|
+
form.append("file", new import_node_buffer.Blob([buffer]), "output.xls");
|
|
247
|
+
form.append("case_type", case_type);
|
|
248
|
+
form.append("search_field", search_field);
|
|
249
|
+
form.append("create_new_cases", create_new_cases);
|
|
246
250
|
try {
|
|
247
251
|
const response = await request(state.configuration, path, {
|
|
248
252
|
method: "POST",
|
|
249
|
-
data
|
|
253
|
+
data: form
|
|
250
254
|
});
|
|
251
255
|
return prepareNextState(state, response);
|
|
252
256
|
} catch (e) {
|
|
@@ -254,9 +258,9 @@ function submitXls(formData, params) {
|
|
|
254
258
|
}
|
|
255
259
|
};
|
|
256
260
|
}
|
|
257
|
-
function submit(
|
|
261
|
+
function submit(data) {
|
|
258
262
|
return async (state) => {
|
|
259
|
-
const [jsonBody] = (0, import_util2.expandReferences)(state,
|
|
263
|
+
const [jsonBody] = (0, import_util2.expandReferences)(state, data);
|
|
260
264
|
const body = (0, import_js2xmlparser.default)("data", jsonBody);
|
|
261
265
|
const { domain, appId } = state.configuration;
|
|
262
266
|
const path = `/a/${domain}/receiver/${appId}/`;
|
|
@@ -298,8 +302,10 @@ var src_default = Adaptor_exports;
|
|
|
298
302
|
alterState,
|
|
299
303
|
arrayToString,
|
|
300
304
|
combine,
|
|
305
|
+
cursor,
|
|
301
306
|
dataPath,
|
|
302
307
|
dataValue,
|
|
308
|
+
dateFns,
|
|
303
309
|
each,
|
|
304
310
|
execute,
|
|
305
311
|
fetchReportData,
|
package/dist/index.js
CHANGED
|
@@ -10,8 +10,10 @@ __export(Adaptor_exports, {
|
|
|
10
10
|
alterState: () => alterState,
|
|
11
11
|
arrayToString: () => arrayToString,
|
|
12
12
|
combine: () => combine,
|
|
13
|
+
cursor: () => cursor,
|
|
13
14
|
dataPath: () => dataPath,
|
|
14
15
|
dataValue: () => dataValue,
|
|
16
|
+
dateFns: () => dateFns,
|
|
15
17
|
each: () => each,
|
|
16
18
|
execute: () => execute,
|
|
17
19
|
fetchReportData: () => fetchReportData,
|
|
@@ -92,8 +94,10 @@ async function request(configuration, path, opts) {
|
|
|
92
94
|
import {
|
|
93
95
|
fn,
|
|
94
96
|
fnIf,
|
|
97
|
+
cursor,
|
|
95
98
|
alterState,
|
|
96
99
|
arrayToString,
|
|
100
|
+
dateFns,
|
|
97
101
|
combine,
|
|
98
102
|
dataPath,
|
|
99
103
|
dataValue,
|
|
@@ -201,10 +205,10 @@ function post(path, data, params = {}, callback = (s) => s) {
|
|
|
201
205
|
}
|
|
202
206
|
};
|
|
203
207
|
}
|
|
204
|
-
function submitXls(
|
|
208
|
+
function submitXls(data, params) {
|
|
205
209
|
return async (state) => {
|
|
206
210
|
const { domain } = state.configuration;
|
|
207
|
-
const [json] = expandReferences(state,
|
|
211
|
+
const [json] = expandReferences(state, data);
|
|
208
212
|
const { case_type, search_field, create_new_cases } = params;
|
|
209
213
|
const path = `/a/${domain}/importer/excel/bulk_upload_api/`;
|
|
210
214
|
const workbook = xlsx.utils.book_new();
|
|
@@ -212,15 +216,15 @@ function submitXls(formData, params) {
|
|
|
212
216
|
const ws_name = "SheetJS";
|
|
213
217
|
xlsx.utils.book_append_sheet(workbook, worksheet, ws_name);
|
|
214
218
|
const buffer = xlsx.write(workbook, { type: "buffer", bookType: "xls" });
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
219
|
+
const form = new FormData();
|
|
220
|
+
form.append("file", new Blob([buffer]), "output.xls");
|
|
221
|
+
form.append("case_type", case_type);
|
|
222
|
+
form.append("search_field", search_field);
|
|
223
|
+
form.append("create_new_cases", create_new_cases);
|
|
220
224
|
try {
|
|
221
225
|
const response = await request(state.configuration, path, {
|
|
222
226
|
method: "POST",
|
|
223
|
-
data
|
|
227
|
+
data: form
|
|
224
228
|
});
|
|
225
229
|
return prepareNextState(state, response);
|
|
226
230
|
} catch (e) {
|
|
@@ -228,9 +232,9 @@ function submitXls(formData, params) {
|
|
|
228
232
|
}
|
|
229
233
|
};
|
|
230
234
|
}
|
|
231
|
-
function submit(
|
|
235
|
+
function submit(data) {
|
|
232
236
|
return async (state) => {
|
|
233
|
-
const [jsonBody] = expandReferences(state,
|
|
237
|
+
const [jsonBody] = expandReferences(state, data);
|
|
234
238
|
const body = js2xmlparser("data", jsonBody);
|
|
235
239
|
const { domain, appId } = state.configuration;
|
|
236
240
|
const path = `/a/${domain}/receiver/${appId}/`;
|
|
@@ -271,8 +275,10 @@ export {
|
|
|
271
275
|
alterState,
|
|
272
276
|
arrayToString,
|
|
273
277
|
combine,
|
|
278
|
+
cursor,
|
|
274
279
|
dataPath,
|
|
275
280
|
dataValue,
|
|
281
|
+
dateFns,
|
|
276
282
|
src_default as default,
|
|
277
283
|
each,
|
|
278
284
|
execute,
|
package/package.json
CHANGED
package/types/Adaptor.d.ts
CHANGED
|
@@ -1,27 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @typedef {Object}
|
|
4
|
-
* @
|
|
5
|
-
* @property
|
|
6
|
-
* @property
|
|
7
|
-
* @property {string} xmlns - Optional form XML namespace. See the [Commcare Docs](https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143979045/Finding+a+Form%27s+XMLNS)
|
|
8
|
-
* @property {string} indexed_on_start - Optional date (and time). Will return only forms that have had data modified since the passed in date.
|
|
9
|
-
* @property {string} indexed_on_end - Optional date (and time). Will return only forms that have had data modified before the passed in date.
|
|
10
|
-
* @property {string} received_on_start - Optional date (and time). Will return only forms that were received after the passed in date.
|
|
11
|
-
* @property {string} received_on_end - Optional date (and time). Will return only forms that were received before the passed in date.
|
|
12
|
-
* @property {string} app_id - The returned records will be limited to the application defined
|
|
13
|
-
* @property {string} case_id - A case UUID. Will only return forms which updated that case.
|
|
14
|
-
* @property {string} owner_id - Optional user of group UUID used when getting cases
|
|
15
|
-
* @property {string} user_id - Optional UUID for all cases last modified by that user
|
|
16
|
-
* @property {string} type - Optional case type to get all matching cases
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* Queries provided to the submitXls request
|
|
20
|
-
* @typedef {Object} RequestOptions
|
|
21
|
-
* @public
|
|
22
|
-
* @property {string} case_type - Optional case type
|
|
23
|
-
* @property {string} search_field - Optional search field
|
|
24
|
-
* @property {string} create_new_cases - Optional for allowing to create new cases. Default `:on`
|
|
2
|
+
* State object
|
|
3
|
+
* @typedef {Object} CommcareHttpState
|
|
4
|
+
* @property data - The response body (as JSON)
|
|
5
|
+
* @property response - The HTTP response from the CommCare server (excluding the body)
|
|
6
|
+
* @property references - An array of all previous data objects used in the Job
|
|
25
7
|
*/
|
|
26
8
|
/**
|
|
27
9
|
* Execute a sequence of operations.
|
|
@@ -37,39 +19,48 @@
|
|
|
37
19
|
*/
|
|
38
20
|
export function execute(...operations: Operations): Operation;
|
|
39
21
|
/**
|
|
40
|
-
* Make a GET request to any
|
|
41
|
-
*
|
|
42
|
-
* is paginated.
|
|
43
|
-
* A `response` key will be added to state with the HTTP response and a `meta` key
|
|
22
|
+
* Make a GET request to any CommCare endpoint. The response body will be returned to `state.data` as JSON.
|
|
23
|
+
* Paginated responses will be fully downloaded and returned as a single array, _unless_ an `offset` is passed.
|
|
44
24
|
* @public
|
|
45
|
-
* @example <caption>Get a list of cases</caption>
|
|
46
|
-
* get("case", { limit: 20 })
|
|
47
|
-
* @example <caption>Get a specific case </caption>
|
|
48
|
-
* get("case/12345")
|
|
49
25
|
* @function
|
|
26
|
+
* @example <caption>Get a specific case by id</caption>
|
|
27
|
+
* get("/case/12345")
|
|
28
|
+
* @example <caption>Get exactly 20 cases</caption>
|
|
29
|
+
* get("/case", { offset:0, limit: 20 })
|
|
30
|
+
* @example <caption>Get forms by app id</caption>
|
|
31
|
+
* get("/form", { app_id: "02bf50ab803a89ea4963799362874f0c" })
|
|
32
|
+
* @example <caption>Get all cases, 50 at a time, and add them to state</caption>
|
|
33
|
+
* get("/case", {}, (state) => {
|
|
34
|
+
* state.cases.push(...state.data) // adds 50 cases to the cases array
|
|
35
|
+
* return state;
|
|
36
|
+
* })
|
|
50
37
|
* @param {string} path - Path to resource
|
|
51
|
-
* @param {
|
|
52
|
-
* @param {function} [callback] -
|
|
38
|
+
* @param {Object} [params] - Input parameters for the request. These vary by endpoint, see {@link https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143957366/Data+APIs CommCare docs}.
|
|
39
|
+
* @param {function} [callback] - Optional callback function. Invoked once per page of data retrieved.
|
|
40
|
+
* @state {CommcareHttpState}
|
|
53
41
|
* @returns {Operation}
|
|
54
42
|
*/
|
|
55
|
-
export function get(path: string, params?:
|
|
43
|
+
export function get(path: string, params?: any, callback?: Function): Operation;
|
|
56
44
|
/**
|
|
57
|
-
* Make a
|
|
58
|
-
* @example
|
|
59
|
-
* post(
|
|
45
|
+
* Make a POST request to any CommCare endpoint.
|
|
46
|
+
* @example <caption>Post a user object to to the /user endpoint</caption>
|
|
47
|
+
* post("/user", { "username":"test", "password":"somepassword" })
|
|
60
48
|
* @function
|
|
61
49
|
* @public
|
|
62
50
|
* @param {string} path - Path to resource
|
|
63
|
-
* @param {object} data - Object or JSON
|
|
64
|
-
* @param {Object} params - Optional request params
|
|
51
|
+
* @param {object} data - Object or JSON to use as the request body
|
|
52
|
+
* @param {Object} [params] - Optional request params
|
|
65
53
|
* @param {function} [callback] - Optional callback to handle the response
|
|
66
54
|
* @returns {Operation}
|
|
55
|
+
* @state {CommcareHttpState}
|
|
67
56
|
*/
|
|
68
57
|
export function post(path: string, data: object, params?: any, callback?: Function): Operation;
|
|
69
58
|
/**
|
|
70
|
-
*
|
|
59
|
+
* Bulk upload data to CommCare. Accepts an array of objects, converts them into
|
|
60
|
+
* an XLS representation, and uploads.
|
|
71
61
|
* @public
|
|
72
|
-
* @
|
|
62
|
+
* @function
|
|
63
|
+
* @example <caption>Upload a single row of data</caption>
|
|
73
64
|
* submitXls(
|
|
74
65
|
* [
|
|
75
66
|
* {name: 'Mamadou', phone: '000000'},
|
|
@@ -80,51 +71,64 @@ export function post(path: string, data: object, params?: any, callback?: Functi
|
|
|
80
71
|
* create_new_cases: 'on',
|
|
81
72
|
* }
|
|
82
73
|
* )
|
|
83
|
-
* @
|
|
84
|
-
* @param {Object}
|
|
85
|
-
* @
|
|
74
|
+
* @param {array} data - Array of objects to upload
|
|
75
|
+
* @param {Object} params - Input parameters, see {@link https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143946459/Bulk+Upload+Case+Data CommCare docs}.
|
|
76
|
+
* @state data - the response from the CommCare Server
|
|
86
77
|
* @returns {Operation}
|
|
87
78
|
*/
|
|
88
|
-
export function submitXls(
|
|
79
|
+
export function submitXls(data: any[], params: any): Operation;
|
|
89
80
|
/**
|
|
90
|
-
* Submit
|
|
81
|
+
* Submit forms to CommCare. Accepts an array of JSON
|
|
82
|
+
* objects, converts them into XML, and submits to CommCare as an x-form.
|
|
91
83
|
* @public
|
|
92
|
-
* @
|
|
84
|
+
* @function
|
|
85
|
+
* @example <caption>Submit a form to CommCare</caption>
|
|
93
86
|
* submit(
|
|
94
87
|
* fields(
|
|
95
|
-
* field("@",
|
|
96
|
-
*
|
|
97
|
-
* "xmlns": "http://openrosa.org/formdesigner/form-id-here"
|
|
98
|
-
* };
|
|
88
|
+
* field("@", (state) => ({
|
|
89
|
+
* "xmlns": `http://openrosa.org/formdesigner/${state.formId}`
|
|
99
90
|
* }),
|
|
100
|
-
* field("question1",
|
|
101
|
-
* field("question2",
|
|
91
|
+
* field("question1", (state) => state.data.answer1),
|
|
92
|
+
* field("question2", (state) => state.data.answer2),
|
|
102
93
|
* )
|
|
103
94
|
* )
|
|
104
|
-
* @
|
|
105
|
-
* @
|
|
95
|
+
* @param {Object} data - The form as a JSON object
|
|
96
|
+
* @state data - the response from the CommCare Server
|
|
106
97
|
* @returns {Operation}
|
|
107
98
|
*/
|
|
108
|
-
export function submit(
|
|
99
|
+
export function submit(data: any): Operation;
|
|
109
100
|
/**
|
|
110
101
|
* Make a GET request to CommCare's Reports API
|
|
111
|
-
* and POST the response
|
|
102
|
+
* and POST the response somewhere else.
|
|
112
103
|
* @public
|
|
113
|
-
* @example
|
|
114
|
-
* fetchReportData(
|
|
104
|
+
* @example <caption>Fetch 10 records from a report and post them to example.com</caption>
|
|
105
|
+
* fetchReportData(
|
|
106
|
+
* "9aab0eeb88555a7b4568676883e7379a",
|
|
107
|
+
* { limit: 10 },
|
|
108
|
+
* "https://www.example.com/api/"
|
|
109
|
+
* )
|
|
115
110
|
* @function
|
|
116
111
|
* @param {String} reportId - API name of the report.
|
|
117
|
-
* @param {
|
|
118
|
-
* @param {String} postUrl -
|
|
112
|
+
* @param {Object} params - Input parameters for the request, see {@link https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143957341/Download+Report+Data Commcare docs}.
|
|
113
|
+
* @param {String} postUrl - URL to which the response object will be posted.
|
|
119
114
|
* @returns {Operation}
|
|
120
115
|
*/
|
|
121
|
-
export function fetchReportData(reportId: string, params:
|
|
122
|
-
/**
|
|
123
|
-
* Queries provided to the GET request
|
|
124
|
-
*/
|
|
125
|
-
export type RequestQueries = any;
|
|
116
|
+
export function fetchReportData(reportId: string, params: any, postUrl: string): Operation;
|
|
126
117
|
/**
|
|
127
|
-
*
|
|
118
|
+
* State object
|
|
128
119
|
*/
|
|
129
|
-
export type
|
|
130
|
-
|
|
120
|
+
export type CommcareHttpState = {
|
|
121
|
+
/**
|
|
122
|
+
* - The response body (as JSON)
|
|
123
|
+
*/
|
|
124
|
+
data: any;
|
|
125
|
+
/**
|
|
126
|
+
* - The HTTP response from the CommCare server (excluding the body)
|
|
127
|
+
*/
|
|
128
|
+
response: any;
|
|
129
|
+
/**
|
|
130
|
+
* - An array of all previous data objects used in the Job
|
|
131
|
+
*/
|
|
132
|
+
references: any;
|
|
133
|
+
};
|
|
134
|
+
export { fn, fnIf, cursor, alterState, arrayToString, dateFns, combine, dataPath, dataValue, each, field, fields, http, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
|