@openfn/language-commcare 2.0.0 → 2.2.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 +140 -6
- package/dist/index.cjs +10 -5
- package/dist/index.js +10 -5
- package/package.json +2 -2
- package/types/Adaptor.d.ts +107 -29
package/ast.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"callback"
|
|
9
9
|
],
|
|
10
10
|
"docs": {
|
|
11
|
-
"description": "Make a
|
|
11
|
+
"description": "Make a GET request to any commcare endpoint. The returned objects will be written to state.data.\nA `response` key will be added to state with the HTTP response and a `meta` key",
|
|
12
12
|
"tags": [
|
|
13
13
|
{
|
|
14
14
|
"title": "public",
|
|
@@ -17,9 +17,14 @@
|
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
"title": "example",
|
|
20
|
-
"description": "get(\
|
|
20
|
+
"description": "get(\"case\", { limit: 20 })",
|
|
21
21
|
"caption": "Get a list of cases"
|
|
22
22
|
},
|
|
23
|
+
{
|
|
24
|
+
"title": "example",
|
|
25
|
+
"description": "get(\"case/12345\")",
|
|
26
|
+
"caption": "Get a specific case"
|
|
27
|
+
},
|
|
23
28
|
{
|
|
24
29
|
"title": "function",
|
|
25
30
|
"description": null,
|
|
@@ -37,6 +42,82 @@
|
|
|
37
42
|
{
|
|
38
43
|
"title": "param",
|
|
39
44
|
"description": "Optional request params such as limit and offset.",
|
|
45
|
+
"type": {
|
|
46
|
+
"type": "NameExpression",
|
|
47
|
+
"name": "RequestQueries"
|
|
48
|
+
},
|
|
49
|
+
"name": "params"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"title": "param",
|
|
53
|
+
"description": "Optional callback to handle the response",
|
|
54
|
+
"type": {
|
|
55
|
+
"type": "OptionalType",
|
|
56
|
+
"expression": {
|
|
57
|
+
"type": "NameExpression",
|
|
58
|
+
"name": "function"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"name": "callback"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"title": "returns",
|
|
65
|
+
"description": null,
|
|
66
|
+
"type": {
|
|
67
|
+
"type": "NameExpression",
|
|
68
|
+
"name": "Operation"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
"valid": true
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"name": "post",
|
|
77
|
+
"params": [
|
|
78
|
+
"path",
|
|
79
|
+
"data",
|
|
80
|
+
"params",
|
|
81
|
+
"callback"
|
|
82
|
+
],
|
|
83
|
+
"docs": {
|
|
84
|
+
"description": "Make a post request to commcare",
|
|
85
|
+
"tags": [
|
|
86
|
+
{
|
|
87
|
+
"title": "example",
|
|
88
|
+
"description": "post( \"user\", { \"username\":\"test\", \"password\":\"somepassword\" })"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"title": "function",
|
|
92
|
+
"description": null,
|
|
93
|
+
"name": null
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"title": "public",
|
|
97
|
+
"description": null,
|
|
98
|
+
"type": null
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"title": "param",
|
|
102
|
+
"description": "Path to resource",
|
|
103
|
+
"type": {
|
|
104
|
+
"type": "NameExpression",
|
|
105
|
+
"name": "string"
|
|
106
|
+
},
|
|
107
|
+
"name": "path"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"title": "param",
|
|
111
|
+
"description": "Object or JSON which defines data that will be used to create a given instance of resource",
|
|
112
|
+
"type": {
|
|
113
|
+
"type": "NameExpression",
|
|
114
|
+
"name": "object"
|
|
115
|
+
},
|
|
116
|
+
"name": "data"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"title": "param",
|
|
120
|
+
"description": "Optional request params.",
|
|
40
121
|
"type": {
|
|
41
122
|
"type": "NameExpression",
|
|
42
123
|
"name": "Object"
|
|
@@ -101,10 +182,10 @@
|
|
|
101
182
|
},
|
|
102
183
|
{
|
|
103
184
|
"title": "param",
|
|
104
|
-
"description": "Request params including case type
|
|
185
|
+
"description": "Request params including case type.",
|
|
105
186
|
"type": {
|
|
106
187
|
"type": "NameExpression",
|
|
107
|
-
"name": "
|
|
188
|
+
"name": "RequestOptions"
|
|
108
189
|
},
|
|
109
190
|
"name": "params"
|
|
110
191
|
},
|
|
@@ -198,10 +279,10 @@
|
|
|
198
279
|
},
|
|
199
280
|
{
|
|
200
281
|
"title": "param",
|
|
201
|
-
"description": "Query params, incl: limit, offset, and custom report filters.",
|
|
282
|
+
"description": "Query params, incl: limit, offset, and any custom report filters.",
|
|
202
283
|
"type": {
|
|
203
284
|
"type": "NameExpression",
|
|
204
|
-
"name": "
|
|
285
|
+
"name": "RequestQueries"
|
|
205
286
|
},
|
|
206
287
|
"name": "params"
|
|
207
288
|
},
|
|
@@ -272,6 +353,59 @@
|
|
|
272
353
|
},
|
|
273
354
|
"valid": true
|
|
274
355
|
},
|
|
356
|
+
{
|
|
357
|
+
"name": "fnIf",
|
|
358
|
+
"params": [
|
|
359
|
+
"condition",
|
|
360
|
+
"operation"
|
|
361
|
+
],
|
|
362
|
+
"docs": {
|
|
363
|
+
"description": "A custom operation that will only execute the function if the condition returns true",
|
|
364
|
+
"tags": [
|
|
365
|
+
{
|
|
366
|
+
"title": "public",
|
|
367
|
+
"description": null,
|
|
368
|
+
"type": null
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
"title": "example",
|
|
372
|
+
"description": "fnIf((state) => state?.data?.name, get(\"https://example.com\"));"
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
"title": "function",
|
|
376
|
+
"description": null,
|
|
377
|
+
"name": null
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
"title": "param",
|
|
381
|
+
"description": "The condition that returns true",
|
|
382
|
+
"type": {
|
|
383
|
+
"type": "NameExpression",
|
|
384
|
+
"name": "Boolean"
|
|
385
|
+
},
|
|
386
|
+
"name": "condition"
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
"title": "param",
|
|
390
|
+
"description": "The operation needed to be executed.",
|
|
391
|
+
"type": {
|
|
392
|
+
"type": "NameExpression",
|
|
393
|
+
"name": "Operation"
|
|
394
|
+
},
|
|
395
|
+
"name": "operation"
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
"title": "returns",
|
|
399
|
+
"description": null,
|
|
400
|
+
"type": {
|
|
401
|
+
"type": "NameExpression",
|
|
402
|
+
"name": "Operation"
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
]
|
|
406
|
+
},
|
|
407
|
+
"valid": true
|
|
408
|
+
},
|
|
275
409
|
{
|
|
276
410
|
"name": "sourceValue",
|
|
277
411
|
"params": [
|
package/dist/index.cjs
CHANGED
|
@@ -37,6 +37,7 @@ __export(src_exports, {
|
|
|
37
37
|
field: () => import_language_common3.field,
|
|
38
38
|
fields: () => import_language_common3.fields,
|
|
39
39
|
fn: () => import_language_common3.fn,
|
|
40
|
+
fnIf: () => import_language_common3.fnIf,
|
|
40
41
|
get: () => get,
|
|
41
42
|
http: () => import_language_common3.http,
|
|
42
43
|
lastReferenceValue: () => import_language_common3.lastReferenceValue,
|
|
@@ -62,6 +63,7 @@ __export(Adaptor_exports, {
|
|
|
62
63
|
field: () => import_language_common3.field,
|
|
63
64
|
fields: () => import_language_common3.fields,
|
|
64
65
|
fn: () => import_language_common3.fn,
|
|
66
|
+
fnIf: () => import_language_common3.fnIf,
|
|
65
67
|
get: () => get,
|
|
66
68
|
http: () => import_language_common3.http,
|
|
67
69
|
lastReferenceValue: () => import_language_common3.lastReferenceValue,
|
|
@@ -158,7 +160,10 @@ function get(path, params = {}, callback = (s) => s) {
|
|
|
158
160
|
);
|
|
159
161
|
return prepareNextState(state, response, callback);
|
|
160
162
|
} catch (e) {
|
|
161
|
-
|
|
163
|
+
if (e.statusCode === 404) {
|
|
164
|
+
e.body = { error: `Resource ${path} not found` };
|
|
165
|
+
}
|
|
166
|
+
throw e.body.error ?? e;
|
|
162
167
|
}
|
|
163
168
|
};
|
|
164
169
|
}
|
|
@@ -240,16 +245,15 @@ function fetchReportData(reportId, params, postUrl) {
|
|
|
240
245
|
method: "GET",
|
|
241
246
|
contentType: "application/json"
|
|
242
247
|
});
|
|
243
|
-
|
|
248
|
+
await request(state.configuration, postUrl, {
|
|
244
249
|
method: "POST",
|
|
245
250
|
params,
|
|
246
251
|
data: reportData,
|
|
247
252
|
contentType: "application/json"
|
|
248
253
|
});
|
|
249
|
-
delete result.response;
|
|
250
254
|
console.log("fetchReportData succeeded.");
|
|
251
|
-
console.log("Posted to: "
|
|
252
|
-
return
|
|
255
|
+
console.log("Posted to: ", postUrl);
|
|
256
|
+
return state;
|
|
253
257
|
};
|
|
254
258
|
}
|
|
255
259
|
|
|
@@ -268,6 +272,7 @@ var src_default = Adaptor_exports;
|
|
|
268
272
|
field,
|
|
269
273
|
fields,
|
|
270
274
|
fn,
|
|
275
|
+
fnIf,
|
|
271
276
|
get,
|
|
272
277
|
http,
|
|
273
278
|
lastReferenceValue,
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ __export(Adaptor_exports, {
|
|
|
18
18
|
field: () => field,
|
|
19
19
|
fields: () => fields,
|
|
20
20
|
fn: () => fn,
|
|
21
|
+
fnIf: () => fnIf,
|
|
21
22
|
get: () => get,
|
|
22
23
|
http: () => http,
|
|
23
24
|
lastReferenceValue: () => lastReferenceValue,
|
|
@@ -90,6 +91,7 @@ async function request(configuration, path, opts) {
|
|
|
90
91
|
// src/Adaptor.js
|
|
91
92
|
import {
|
|
92
93
|
fn,
|
|
94
|
+
fnIf,
|
|
93
95
|
alterState,
|
|
94
96
|
arrayToString,
|
|
95
97
|
combine,
|
|
@@ -132,7 +134,10 @@ function get(path, params = {}, callback = (s) => s) {
|
|
|
132
134
|
);
|
|
133
135
|
return prepareNextState(state, response, callback);
|
|
134
136
|
} catch (e) {
|
|
135
|
-
|
|
137
|
+
if (e.statusCode === 404) {
|
|
138
|
+
e.body = { error: `Resource ${path} not found` };
|
|
139
|
+
}
|
|
140
|
+
throw e.body.error ?? e;
|
|
136
141
|
}
|
|
137
142
|
};
|
|
138
143
|
}
|
|
@@ -214,16 +219,15 @@ function fetchReportData(reportId, params, postUrl) {
|
|
|
214
219
|
method: "GET",
|
|
215
220
|
contentType: "application/json"
|
|
216
221
|
});
|
|
217
|
-
|
|
222
|
+
await request(state.configuration, postUrl, {
|
|
218
223
|
method: "POST",
|
|
219
224
|
params,
|
|
220
225
|
data: reportData,
|
|
221
226
|
contentType: "application/json"
|
|
222
227
|
});
|
|
223
|
-
delete result.response;
|
|
224
228
|
console.log("fetchReportData succeeded.");
|
|
225
|
-
console.log("Posted to: "
|
|
226
|
-
return
|
|
229
|
+
console.log("Posted to: ", postUrl);
|
|
230
|
+
return state;
|
|
227
231
|
};
|
|
228
232
|
}
|
|
229
233
|
|
|
@@ -242,6 +246,7 @@ export {
|
|
|
242
246
|
field,
|
|
243
247
|
fields,
|
|
244
248
|
fn,
|
|
249
|
+
fnIf,
|
|
245
250
|
get,
|
|
246
251
|
http,
|
|
247
252
|
lastReferenceValue,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-commcare",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Commcare Language Pack for OpenFn",
|
|
5
5
|
"homepage": "https://docs.openfn.org",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"lodash-fp": "^0.10.4",
|
|
23
23
|
"sinon": "^18.0.0",
|
|
24
24
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.19.3/xlsx-0.19.3.tgz",
|
|
25
|
-
"@openfn/language-common": "1.
|
|
25
|
+
"@openfn/language-common": "1.14.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@openfn/simple-ast": "^0.4.1",
|
package/types/Adaptor.d.ts
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Queries provided to the GET request
|
|
3
|
+
* @typedef {Object} RequestQueries
|
|
4
|
+
* @property {number} limit - The maximum number of records to return. Default: 20. Maximum: 5000.
|
|
5
|
+
* @property {number} offset - The number of records to offset in the results. Default: 0
|
|
6
|
+
* @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)
|
|
7
|
+
* @property {string} indexed_on_start - Optional date (and time). Will return only forms that have had data modified since the passed in date.
|
|
8
|
+
* @property {string} indexed_on_end - Optional date (and time). Will return only forms that have had data modified before the passed in date.
|
|
9
|
+
* @property {string} received_on_start - Optional date (and time). Will return only forms that were received after the passed in date.
|
|
10
|
+
* @property {string} received_on_end - Optional date (and time). Will return only forms that were received before the passed in date.
|
|
11
|
+
* @property {string} app_id - The returned records will be limited to the application defined
|
|
12
|
+
* @property {string} case_id - A case UUID. Will only return forms which updated that case.
|
|
13
|
+
* @property {string} owner_id - Optional user of group UUID used when getting cases
|
|
14
|
+
* @property {string} user_id - Optional UUID for all cases last modified by that user
|
|
15
|
+
* @property {string} type - Optional case type to get all matching cases
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Queries provided to the submitXls request
|
|
19
|
+
* @typedef {Object} RequestOptions
|
|
20
|
+
* @property {string} case_type - Optional case type
|
|
21
|
+
* @property {string} search_field - Optional search field
|
|
22
|
+
* @property {string} create_new_cases - Optional for allowing to create new cases. Default `:on`
|
|
23
|
+
*/
|
|
1
24
|
/**
|
|
2
25
|
* Execute a sequence of operations.
|
|
3
26
|
* Wraps `language-common/execute`, and prepends initial state for commcare.
|
|
@@ -12,41 +35,26 @@
|
|
|
12
35
|
*/
|
|
13
36
|
export function execute(...operations: Operations): Operation;
|
|
14
37
|
/**
|
|
15
|
-
* Make a
|
|
16
|
-
*
|
|
38
|
+
* Make a GET request to any commcare endpoint. The returned objects will be written to state.data.
|
|
39
|
+
* A `response` key will be added to state with the HTTP response and a `meta` key
|
|
17
40
|
* @public
|
|
18
41
|
* @example <caption>Get a list of cases</caption>
|
|
19
|
-
* get(
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* limit: 1,
|
|
23
|
-
* offset:0,
|
|
24
|
-
* }
|
|
25
|
-
* )
|
|
26
|
-
* * @example <caption>Get a specific case </caption>
|
|
27
|
-
* get(
|
|
28
|
-
* "case/12345"
|
|
29
|
-
* {
|
|
30
|
-
* limit: 1,
|
|
31
|
-
* offset:0,
|
|
32
|
-
* }
|
|
33
|
-
* )
|
|
42
|
+
* get("case", { limit: 20 })
|
|
43
|
+
* @example <caption>Get a specific case </caption>
|
|
44
|
+
* get("case/12345")
|
|
34
45
|
* @function
|
|
35
46
|
* @param {string} path - Path to resource
|
|
36
|
-
* @param {
|
|
47
|
+
* @param {RequestQueries} params - Optional request params such as limit and offset.
|
|
37
48
|
* @param {function} [callback] - Optional callback to handle the response
|
|
38
49
|
* @returns {Operation}
|
|
39
50
|
*/
|
|
40
|
-
export function get(path: string, params?:
|
|
51
|
+
export function get(path: string, params?: RequestQueries, callback?: Function): Operation;
|
|
41
52
|
/**
|
|
42
53
|
* Make a post request to commcare
|
|
43
54
|
* @example
|
|
44
|
-
* post(
|
|
45
|
-
* "user",
|
|
46
|
-
* {"username":"test",
|
|
47
|
-
* "password":"somepassword"}
|
|
48
|
-
* );
|
|
55
|
+
* post( "user", { "username":"test", "password":"somepassword" })
|
|
49
56
|
* @function
|
|
57
|
+
* @public
|
|
50
58
|
* @param {string} path - Path to resource
|
|
51
59
|
* @param {object} data - Object or JSON which defines data that will be used to create a given instance of resource
|
|
52
60
|
* @param {Object} params - Optional request params.
|
|
@@ -70,10 +78,10 @@ export function post(path: string, data: object, params?: any, callback?: Functi
|
|
|
70
78
|
* )
|
|
71
79
|
* @function
|
|
72
80
|
* @param {Object} formData - Object including form data.
|
|
73
|
-
* @param {
|
|
81
|
+
* @param {RequestOptions} params - Request params including case type.
|
|
74
82
|
* @returns {Operation}
|
|
75
83
|
*/
|
|
76
|
-
export function submitXls(formData: any, params:
|
|
84
|
+
export function submitXls(formData: any, params: RequestOptions): Operation;
|
|
77
85
|
/**
|
|
78
86
|
* Submit form data
|
|
79
87
|
* @public
|
|
@@ -102,9 +110,79 @@ export function submit(formData: any): Operation;
|
|
|
102
110
|
* fetchReportData(reportId, params, postUrl)
|
|
103
111
|
* @function
|
|
104
112
|
* @param {String} reportId - API name of the report.
|
|
105
|
-
* @param {
|
|
113
|
+
* @param {RequestQueries} params - Query params, incl: limit, offset, and any custom report filters.
|
|
106
114
|
* @param {String} postUrl - Url to which the response object will be posted.
|
|
107
115
|
* @returns {Operation}
|
|
108
116
|
*/
|
|
109
|
-
export function fetchReportData(reportId: string, params:
|
|
110
|
-
|
|
117
|
+
export function fetchReportData(reportId: string, params: RequestQueries, postUrl: string): Operation;
|
|
118
|
+
/**
|
|
119
|
+
* Queries provided to the GET request
|
|
120
|
+
*/
|
|
121
|
+
export type RequestQueries = {
|
|
122
|
+
/**
|
|
123
|
+
* - The maximum number of records to return. Default: 20. Maximum: 5000.
|
|
124
|
+
*/
|
|
125
|
+
limit: number;
|
|
126
|
+
/**
|
|
127
|
+
* - The number of records to offset in the results. Default: 0
|
|
128
|
+
*/
|
|
129
|
+
offset: number;
|
|
130
|
+
/**
|
|
131
|
+
* - Optional form XML namespace. See the [Commcare Docs](https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143979045/Finding+a+Form%27s+XMLNS)
|
|
132
|
+
*/
|
|
133
|
+
xmlns: string;
|
|
134
|
+
/**
|
|
135
|
+
* - Optional date (and time). Will return only forms that have had data modified since the passed in date.
|
|
136
|
+
*/
|
|
137
|
+
indexed_on_start: string;
|
|
138
|
+
/**
|
|
139
|
+
* - Optional date (and time). Will return only forms that have had data modified before the passed in date.
|
|
140
|
+
*/
|
|
141
|
+
indexed_on_end: string;
|
|
142
|
+
/**
|
|
143
|
+
* - Optional date (and time). Will return only forms that were received after the passed in date.
|
|
144
|
+
*/
|
|
145
|
+
received_on_start: string;
|
|
146
|
+
/**
|
|
147
|
+
* - Optional date (and time). Will return only forms that were received before the passed in date.
|
|
148
|
+
*/
|
|
149
|
+
received_on_end: string;
|
|
150
|
+
/**
|
|
151
|
+
* - The returned records will be limited to the application defined
|
|
152
|
+
*/
|
|
153
|
+
app_id: string;
|
|
154
|
+
/**
|
|
155
|
+
* - A case UUID. Will only return forms which updated that case.
|
|
156
|
+
*/
|
|
157
|
+
case_id: string;
|
|
158
|
+
/**
|
|
159
|
+
* - Optional user of group UUID used when getting cases
|
|
160
|
+
*/
|
|
161
|
+
owner_id: string;
|
|
162
|
+
/**
|
|
163
|
+
* - Optional UUID for all cases last modified by that user
|
|
164
|
+
*/
|
|
165
|
+
user_id: string;
|
|
166
|
+
/**
|
|
167
|
+
* - Optional case type to get all matching cases
|
|
168
|
+
*/
|
|
169
|
+
type: string;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Queries provided to the submitXls request
|
|
173
|
+
*/
|
|
174
|
+
export type RequestOptions = {
|
|
175
|
+
/**
|
|
176
|
+
* - Optional case type
|
|
177
|
+
*/
|
|
178
|
+
case_type: string;
|
|
179
|
+
/**
|
|
180
|
+
* - Optional search field
|
|
181
|
+
*/
|
|
182
|
+
search_field: string;
|
|
183
|
+
/**
|
|
184
|
+
* - Optional for allowing to create new cases. Default `:on`
|
|
185
|
+
*/
|
|
186
|
+
create_new_cases: string;
|
|
187
|
+
};
|
|
188
|
+
export { fn, fnIf, alterState, arrayToString, combine, dataPath, dataValue, each, field, fields, http, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
|