@openfn/language-commcare 2.0.0 → 2.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 +87 -6
- package/dist/index.cjs +7 -5
- package/dist/index.js +7 -5
- package/package.json +2 -2
- package/types/Adaptor.d.ts +106 -28
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
|
},
|
package/dist/index.cjs
CHANGED
|
@@ -158,7 +158,10 @@ function get(path, params = {}, callback = (s) => s) {
|
|
|
158
158
|
);
|
|
159
159
|
return prepareNextState(state, response, callback);
|
|
160
160
|
} catch (e) {
|
|
161
|
-
|
|
161
|
+
if (e.statusCode === 404) {
|
|
162
|
+
e.body = { error: `Resource ${path} not found` };
|
|
163
|
+
}
|
|
164
|
+
throw e.body.error ?? e;
|
|
162
165
|
}
|
|
163
166
|
};
|
|
164
167
|
}
|
|
@@ -240,16 +243,15 @@ function fetchReportData(reportId, params, postUrl) {
|
|
|
240
243
|
method: "GET",
|
|
241
244
|
contentType: "application/json"
|
|
242
245
|
});
|
|
243
|
-
|
|
246
|
+
await request(state.configuration, postUrl, {
|
|
244
247
|
method: "POST",
|
|
245
248
|
params,
|
|
246
249
|
data: reportData,
|
|
247
250
|
contentType: "application/json"
|
|
248
251
|
});
|
|
249
|
-
delete result.response;
|
|
250
252
|
console.log("fetchReportData succeeded.");
|
|
251
|
-
console.log("Posted to: "
|
|
252
|
-
return
|
|
253
|
+
console.log("Posted to: ", postUrl);
|
|
254
|
+
return state;
|
|
253
255
|
};
|
|
254
256
|
}
|
|
255
257
|
|
package/dist/index.js
CHANGED
|
@@ -132,7 +132,10 @@ function get(path, params = {}, callback = (s) => s) {
|
|
|
132
132
|
);
|
|
133
133
|
return prepareNextState(state, response, callback);
|
|
134
134
|
} catch (e) {
|
|
135
|
-
|
|
135
|
+
if (e.statusCode === 404) {
|
|
136
|
+
e.body = { error: `Resource ${path} not found` };
|
|
137
|
+
}
|
|
138
|
+
throw e.body.error ?? e;
|
|
136
139
|
}
|
|
137
140
|
};
|
|
138
141
|
}
|
|
@@ -214,16 +217,15 @@ function fetchReportData(reportId, params, postUrl) {
|
|
|
214
217
|
method: "GET",
|
|
215
218
|
contentType: "application/json"
|
|
216
219
|
});
|
|
217
|
-
|
|
220
|
+
await request(state.configuration, postUrl, {
|
|
218
221
|
method: "POST",
|
|
219
222
|
params,
|
|
220
223
|
data: reportData,
|
|
221
224
|
contentType: "application/json"
|
|
222
225
|
});
|
|
223
|
-
delete result.response;
|
|
224
226
|
console.log("fetchReportData succeeded.");
|
|
225
|
-
console.log("Posted to: "
|
|
226
|
-
return
|
|
227
|
+
console.log("Posted to: ", postUrl);
|
|
228
|
+
return state;
|
|
227
229
|
};
|
|
228
230
|
}
|
|
229
231
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-commcare",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.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.13.
|
|
25
|
+
"@openfn/language-common": "1.13.5"
|
|
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:
|
|
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
|
+
};
|
|
110
188
|
export { fn, alterState, arrayToString, combine, dataPath, dataValue, each, field, fields, http, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
|