@openfn/language-commcare 3.2.4 → 3.2.5

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 CHANGED
@@ -8,7 +8,7 @@
8
8
  "callback"
9
9
  ],
10
10
  "docs": {
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.",
11
+ "description": "Make a GET request to CommCare. Use this to fetch resources directly from Commcare REST API.\nYou can pass Commcare query parameters as an object of key value pairs, which will map to parameters\nin the URL.\nThe 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.",
12
12
  "tags": [
13
13
  {
14
14
  "title": "public",
@@ -23,22 +23,17 @@
23
23
  {
24
24
  "title": "example",
25
25
  "description": "get(\"/case/12345\")",
26
- "caption": "Get a specific case by id"
26
+ "caption": "Get a resource by Id. Equivalent to GET `<baseUrl>/case/12345`"
27
27
  },
28
28
  {
29
29
  "title": "example",
30
30
  "description": "get(\"/case\", { offset:0, limit: 20 })",
31
- "caption": "Get exactly 20 cases"
31
+ "caption": "Get a resource with exactly 20 items. Equivalent to `<baseUrl>/case?offset=0&limit=20`"
32
32
  },
33
33
  {
34
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"
35
+ "description": "get(\"/case\", {}, (state) => {\n state.cases.push(...state.data) // adds all cases to the cases array\n return state;\n})",
36
+ "caption": "Get all items in a resource, and add them to state. Equivalent to `<baseUrl>/case`"
42
37
  },
43
38
  {
44
39
  "title": "param",
@@ -98,12 +93,12 @@
98
93
  "callback"
99
94
  ],
100
95
  "docs": {
101
- "description": "Make a POST request to any CommCare endpoint.",
96
+ "description": "Make a POST request to CommCare. Use this to send resources directly to Commcare REST API.\nYou can pass Commcare body data as a JSON object.",
102
97
  "tags": [
103
98
  {
104
99
  "title": "example",
105
100
  "description": "post(\"/user\", { \"username\":\"test\", \"password\":\"somepassword\" })",
106
- "caption": "Post a user object to to the /user endpoint"
101
+ "caption": "Create a user resource.Equivalent to `<baseUrl>/user`"
107
102
  },
108
103
  {
109
104
  "title": "function",
@@ -126,7 +121,7 @@
126
121
  },
127
122
  {
128
123
  "title": "param",
129
- "description": "Object or JSON to use as the request body",
124
+ "description": "Object or JSON to create a resource",
130
125
  "type": {
131
126
  "type": "NameExpression",
132
127
  "name": "object"
@@ -180,7 +175,7 @@
180
175
  "params"
181
176
  ],
182
177
  "docs": {
183
- "description": "Bulk upload data to CommCare. Accepts an array of objects, converts them into\nan XLS representation, and uploads.",
178
+ "description": "Bulk upload data to CommCare. Use this to send multiple items for a single resource at once to Commcare. It accepts an array of objects, converts them into\nan XLS representation, and uploads.",
184
179
  "tags": [
185
180
  {
186
181
  "title": "public",
@@ -194,8 +189,8 @@
194
189
  },
195
190
  {
196
191
  "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"
192
+ "description": "submitXls([{ name: 'Mamadou', phone: '000000' }], {\n case_type: 'student',\n search_field: 'external_id',\n create_new_cases: 'on',\n});",
193
+ "caption": "Upload a single row of data for a resource."
199
194
  },
200
195
  {
201
196
  "title": "param",
@@ -217,7 +212,7 @@
217
212
  },
218
213
  {
219
214
  "title": "state",
220
- "description": "data - the response from the CommCare Server"
215
+ "description": "{CommcareHttpState}"
221
216
  },
222
217
  {
223
218
  "title": "returns",
@@ -237,7 +232,7 @@
237
232
  "data"
238
233
  ],
239
234
  "docs": {
240
- "description": "Submit forms to CommCare. Accepts an array of JSON\nobjects, converts them into XML, and submits to CommCare as an x-form.",
235
+ "description": "Submit forms to CommCare. Use this to send forms directly to Commcare REST API. Accepts an array of JSON\nobjects, converts them into XML, and submits to CommCare as an x-form.",
241
236
  "tags": [
242
237
  {
243
238
  "title": "public",
@@ -251,8 +246,8 @@
251
246
  },
252
247
  {
253
248
  "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"
249
+ "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);",
250
+ "caption": "Submit a form resource."
256
251
  },
257
252
  {
258
253
  "title": "param",
@@ -265,7 +260,7 @@
265
260
  },
266
261
  {
267
262
  "title": "state",
268
- "description": "data - the response from the CommCare Server"
263
+ "description": "{CommcareHttpState}"
269
264
  },
270
265
  {
271
266
  "title": "returns",
@@ -296,8 +291,8 @@
296
291
  },
297
292
  {
298
293
  "title": "example",
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"
294
+ "description": "fetchReportData(\n \"abcde\",\n { limit: 10 },\n \"https://www.example.com/api/\"\n)",
295
+ "caption": "Get 10 records from a report and post them to example.com. Equivalent to `<baseUrl>/configurablereportdata/abcde?limit=10`"
301
296
  },
302
297
  {
303
298
  "title": "function",
@@ -331,6 +326,10 @@
331
326
  },
332
327
  "name": "postUrl"
333
328
  },
329
+ {
330
+ "title": "state",
331
+ "description": "{CommcareHttpState}"
332
+ },
334
333
  {
335
334
  "title": "returns",
336
335
  "description": null,
@@ -352,12 +351,12 @@
352
351
  "options"
353
352
  ],
354
353
  "docs": {
355
- "description": "Make a general HTTP request against the Commcare server.",
354
+ "description": "Make a general HTTP request against the Commcare server. Use this to make any request to Commcare REST API.",
356
355
  "tags": [
357
356
  {
358
357
  "title": "example",
359
358
  "description": "request(\"GET\", \"/a/asri/api/v0.5/case\");",
360
- "caption": "Make a GET request to get cases"
359
+ "caption": "Get a resource. Equivalent to `<baseUrl>/a/asri/api/v0.5/case`"
361
360
  },
362
361
  {
363
362
  "title": "function",
@@ -443,13 +442,13 @@
443
442
  },
444
443
  {
445
444
  "title": "example",
446
- "description": "bulk(\n'case-data',\n [\n {name: 'Mamadou', phone: '000000'},\n ],\n {\n case_type: 'student',\n search_field: 'external_id',\n create_new_cases: 'on',\n }\n)",
447
- "caption": "Upload a single row of data for case-data"
445
+ "description": "bulk('case-data', [{ name: 'Mamadou', phone: '000000' }], {\n case_type: 'student',\n search_field: 'external_id',\n create_new_cases: 'on',\n});",
446
+ "caption": "Upload a single row of a case-data resource"
448
447
  },
449
448
  {
450
449
  "title": "example",
451
- "description": "bulk(\n 'lookup-table',\n {\n types: [{\n\n 'DELETE(Y/N)':'N',\n table_id: 'fruit',\n 'is_global?':'yes',\n 'field 1': 'type',\n 'field 2': 'name',\n }],\n fruit: [{\n UID: '',\n 'DELETE(Y/N)':'N',\n 'field:type': 'citrus',\n 'field:name': 'Orange',\n }],\n },\n{replace: false}\n)",
452
- "caption": "Upload a single row of data for a lookup-table"
450
+ "description": "bulk(\n 'lookup-table',\n {\n types: [\n {\n 'DELETE(Y/N)': 'N',\n table_id: 'fruit',\n 'is_global?': 'yes',\n 'field 1': 'type',\n 'field 2': 'name',\n },\n ],\n fruit: [\n {\n UID: '',\n 'DELETE(Y/N)': 'N',\n 'field:type': 'citrus',\n 'field:name': 'Orange',\n },\n ],\n },\n { replace: false }\n);",
451
+ "caption": "Upload a single row of a lookup-table resource"
453
452
  },
454
453
  {
455
454
  "title": "param",
@@ -507,7 +506,7 @@
507
506
  },
508
507
  {
509
508
  "title": "state",
510
- "description": "data - the response from the CommCare Server"
509
+ "description": "{CommcareHttpState}"
511
510
  },
512
511
  {
513
512
  "title": "returns",
@@ -62,6 +62,7 @@
62
62
  "additionalProperties": true,
63
63
  "required": [
64
64
  "hostUrl",
65
- "domain"
65
+ "domain",
66
+ "appId"
66
67
  ]
67
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-commcare",
3
- "version": "3.2.4",
3
+ "version": "3.2.5",
4
4
  "description": "Commcare Language Pack for OpenFn",
5
5
  "homepage": "https://docs.openfn.org",
6
6
  "repository": {
@@ -19,20 +19,21 @@
19
19
  */
20
20
  export function execute(...operations: Operations): Operation;
21
21
  /**
22
- * Make a GET request to any CommCare endpoint. The response body will be returned to `state.data` as JSON.
22
+ * Make a GET request to CommCare. Use this to fetch resources directly from Commcare REST API.
23
+ * You can pass Commcare query parameters as an object of key value pairs, which will map to parameters
24
+ * in the URL.
25
+ * The response body will be returned to `state.data` as JSON.
23
26
  * Paginated responses will be fully downloaded and returned as a single array, _unless_ an `offset` is passed.
24
27
  * @public
25
28
  * @function
26
- * @example <caption>Get a specific case by id</caption>
29
+ * @example <caption>Get a resource by Id. Equivalent to GET `<baseUrl>/case/12345`</caption>
27
30
  * get("/case/12345")
28
- * @example <caption>Get exactly 20 cases</caption>
31
+ * @example <caption>Get a resource with exactly 20 items. Equivalent to `<baseUrl>/case?offset=0&limit=20`</caption>
29
32
  * 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
+ * @example <caption>Get all items in a resource, and add them to state. Equivalent to `<baseUrl>/case`</caption>
33
34
  * get("/case", {}, (state) => {
34
- * state.cases.push(...state.data) // adds 50 cases to the cases array
35
- * return state;
35
+ * state.cases.push(...state.data) // adds all cases to the cases array
36
+ * return state;
36
37
  * })
37
38
  * @param {string} path - Path to resource
38
39
  * @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}.
@@ -42,13 +43,14 @@ export function execute(...operations: Operations): Operation;
42
43
  */
43
44
  export function get(path: string, params?: any, callback?: Function): Operation;
44
45
  /**
45
- * Make a POST request to any CommCare endpoint.
46
- * @example <caption>Post a user object to to the /user endpoint</caption>
46
+ * Make a POST request to CommCare. Use this to send resources directly to Commcare REST API.
47
+ * You can pass Commcare body data as a JSON object.
48
+ * @example <caption>Create a user resource.Equivalent to `<baseUrl>/user`</caption>
47
49
  * post("/user", { "username":"test", "password":"somepassword" })
48
50
  * @function
49
51
  * @public
50
52
  * @param {string} path - Path to resource
51
- * @param {object} data - Object or JSON to use as the request body
53
+ * @param {object} data - Object or JSON to create a resource
52
54
  * @param {Object} [params] - Optional request params
53
55
  * @param {function} [callback] - Optional callback to handle the response
54
56
  * @returns {Operation}
@@ -56,44 +58,39 @@ export function get(path: string, params?: any, callback?: Function): Operation;
56
58
  */
57
59
  export function post(path: string, data: object, params?: any, callback?: Function): Operation;
58
60
  /**
59
- * Bulk upload data to CommCare. Accepts an array of objects, converts them into
61
+ * Bulk upload data to CommCare. Use this to send multiple items for a single resource at once to Commcare. It accepts an array of objects, converts them into
60
62
  * an XLS representation, and uploads.
61
63
  * @public
62
64
  * @function
63
- * @example <caption>Upload a single row of data</caption>
64
- * submitXls(
65
- * [
66
- * {name: 'Mamadou', phone: '000000'},
67
- * ],
68
- * {
69
- * case_type: 'student',
70
- * search_field: 'external_id',
71
- * create_new_cases: 'on',
72
- * }
73
- * )
65
+ * @example <caption>Upload a single row of data for a resource.</caption>
66
+ * submitXls([{ name: 'Mamadou', phone: '000000' }], {
67
+ * case_type: 'student',
68
+ * search_field: 'external_id',
69
+ * create_new_cases: 'on',
70
+ * });
74
71
  * @param {array} data - Array of objects to upload
75
72
  * @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
73
+ * @state {CommcareHttpState}
77
74
  * @returns {Operation}
78
75
  */
79
76
  export function submitXls(data: any[], params: any): Operation;
80
77
  /**
81
- * Submit forms to CommCare. Accepts an array of JSON
78
+ * Submit forms to CommCare. Use this to send forms directly to Commcare REST API. Accepts an array of JSON
82
79
  * objects, converts them into XML, and submits to CommCare as an x-form.
83
80
  * @public
84
81
  * @function
85
- * @example <caption>Submit a form to CommCare</caption>
86
- * submit(
87
- * fields(
88
- * field("@", (state) => ({
89
- * "xmlns": `http://openrosa.org/formdesigner/${state.formId}`
90
- * }),
91
- * field("question1", (state) => state.data.answer1),
92
- * field("question2", (state) => state.data.answer2),
93
- * )
82
+ * @example <caption>Submit a form resource.</caption>
83
+ * submit(
84
+ * fields(
85
+ * field('@', state => ({
86
+ * xmlns: `http://openrosa.org/formdesigner/${state.formId}`,
87
+ * })),
88
+ * field('question1', state => state.data.answer1),
89
+ * field('question2', state => state.data.answer2)
94
90
  * )
91
+ * );
95
92
  * @param {Object} data - The form as a JSON object
96
- * @state data - the response from the CommCare Server
93
+ * @state {CommcareHttpState}
97
94
  * @returns {Operation}
98
95
  */
99
96
  export function submit(data: any): Operation;
@@ -101,9 +98,9 @@ export function submit(data: any): Operation;
101
98
  * Make a GET request to CommCare's Reports API
102
99
  * and POST the response somewhere else.
103
100
  * @public
104
- * @example <caption>Fetch 10 records from a report and post them to example.com</caption>
101
+ * @example <caption>Get 10 records from a report and post them to example.com. Equivalent to `<baseUrl>/configurablereportdata/abcde?limit=10`</caption>
105
102
  * fetchReportData(
106
- * "9aab0eeb88555a7b4568676883e7379a",
103
+ * "abcde",
107
104
  * { limit: 10 },
108
105
  * "https://www.example.com/api/"
109
106
  * )
@@ -111,12 +108,13 @@ export function submit(data: any): Operation;
111
108
  * @param {String} reportId - API name of the report.
112
109
  * @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
110
  * @param {String} postUrl - URL to which the response object will be posted.
111
+ * @state {CommcareHttpState}
114
112
  * @returns {Operation}
115
113
  */
116
114
  export function fetchReportData(reportId: string, params: any, postUrl: string): Operation;
117
115
  /**
118
- * Make a general HTTP request against the Commcare server.
119
- * @example <caption>Make a GET request to get cases</caption>
116
+ * Make a general HTTP request against the Commcare server. Use this to make any request to Commcare REST API.
117
+ * @example <caption>Get a resource. Equivalent to `<baseUrl>/a/asri/api/v0.5/case`</caption>
120
118
  * request("GET", "/a/asri/api/v0.5/case");
121
119
  * @function
122
120
  * @public
@@ -133,45 +131,42 @@ export function request(method: string, path: string, body: object, options?: Re
133
131
  * an XLS representation, and uploads.
134
132
  * @public
135
133
  * @function
136
- * @example <caption>Upload a single row of data for case-data</caption>
134
+ * @example <caption>Upload a single row of a case-data resource</caption>
135
+ * bulk('case-data', [{ name: 'Mamadou', phone: '000000' }], {
136
+ * case_type: 'student',
137
+ * search_field: 'external_id',
138
+ * create_new_cases: 'on',
139
+ * });
140
+ * @example <caption>Upload a single row of a lookup-table resource</caption>
137
141
  * bulk(
138
- * 'case-data',
139
- * [
140
- * {name: 'Mamadou', phone: '000000'},
141
- * ],
142
- * {
143
- * case_type: 'student',
144
- * search_field: 'external_id',
145
- * create_new_cases: 'on',
146
- * }
147
- * )
148
- * @example <caption>Upload a single row of data for a lookup-table</caption>
149
- * bulk(
150
- * 'lookup-table',
151
- * {
152
- * types: [{
153
- *
154
- * 'DELETE(Y/N)':'N',
155
- * table_id: 'fruit',
156
- * 'is_global?':'yes',
157
- * 'field 1': 'type',
158
- * 'field 2': 'name',
159
- * }],
160
- * fruit: [{
161
- * UID: '',
162
- * 'DELETE(Y/N)':'N',
163
- * 'field:type': 'citrus',
164
- * 'field:name': 'Orange',
165
- * }],
142
+ * 'lookup-table',
143
+ * {
144
+ * types: [
145
+ * {
146
+ * 'DELETE(Y/N)': 'N',
147
+ * table_id: 'fruit',
148
+ * 'is_global?': 'yes',
149
+ * 'field 1': 'type',
150
+ * 'field 2': 'name',
151
+ * },
152
+ * ],
153
+ * fruit: [
154
+ * {
155
+ * UID: '',
156
+ * 'DELETE(Y/N)': 'N',
157
+ * 'field:type': 'citrus',
158
+ * 'field:name': 'Orange',
159
+ * },
160
+ * ],
166
161
  * },
167
- * {replace: false}
168
- * )
162
+ * { replace: false }
163
+ * );
169
164
  * @param {('case-data'|'lookup-table')} type - The type of data being processed.
170
165
  * @param {(Object|Object[])} data - An object or an array of objects to upload.
171
166
  * - If type is `'case-data'`, this should be an object array of objects.
172
167
  * - If type is `'lookup-table'`, this should be an object.
173
168
  * @param {Object} params - Input parameters, see {@link https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143946459/Bulk+Upload+Case+Data CommCare docs} for case-data and {@link https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143946023/Bulk+upload+Lookup+Tables Commcare Docs} for lookup-table.
174
- * @state data - the response from the CommCare Server
169
+ * @state {CommcareHttpState}
175
170
  * @returns {Operation}
176
171
  */
177
172
  export function bulk(type: ('case-data' | 'lookup-table'), data: (any | any[]), params: any): Operation;