@openfn/language-commcare 4.3.0 → 4.3.3
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 +28 -16
- package/dist/index.cjs +16 -0
- package/dist/index.js +16 -0
- package/package.json +4 -4
- package/types/Adaptor.d.ts +21 -17
package/ast.json
CHANGED
|
@@ -8,8 +8,12 @@
|
|
|
8
8
|
"callback"
|
|
9
9
|
],
|
|
10
10
|
"docs": {
|
|
11
|
-
"description": "Make a GET request to CommCare
|
|
11
|
+
"description": "Make a GET request to CommCare's legacy v0.5 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
|
+
{
|
|
14
|
+
"title": "deprecated",
|
|
15
|
+
"description": "This function only works against CommCare's legacy v0.5 API (path: `/a/domain/api/v0.5/...`).\nFor current CommCare APIs, use {@link #http_get} instead."
|
|
16
|
+
},
|
|
13
17
|
{
|
|
14
18
|
"title": "public",
|
|
15
19
|
"description": null,
|
|
@@ -23,21 +27,21 @@
|
|
|
23
27
|
{
|
|
24
28
|
"title": "example",
|
|
25
29
|
"description": "get(\"/case/12345\")",
|
|
26
|
-
"caption": "Get a resource by Id. Equivalent to GET
|
|
30
|
+
"caption": "Get a resource by Id. Equivalent to GET `/a/domain/api/v0.5/case/12345`"
|
|
27
31
|
},
|
|
28
32
|
{
|
|
29
33
|
"title": "example",
|
|
30
34
|
"description": "get(\"/case\", { offset:0, limit: 20 })",
|
|
31
|
-
"caption": "Get a resource with exactly 20 items. Equivalent to
|
|
35
|
+
"caption": "Get a resource with exactly 20 items. Equivalent to `/a/domain/api/v0.5/case?offset=0&limit=20`"
|
|
32
36
|
},
|
|
33
37
|
{
|
|
34
38
|
"title": "example",
|
|
35
39
|
"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
|
|
40
|
+
"caption": "Get all items in a resource, and add them to state. Equivalent to `/a/domain/api/v0.5/case`"
|
|
37
41
|
},
|
|
38
42
|
{
|
|
39
43
|
"title": "param",
|
|
40
|
-
"description": "Path to resource",
|
|
44
|
+
"description": "Path to a v0.5 resource (e.g. `case`, `form`)",
|
|
41
45
|
"type": {
|
|
42
46
|
"type": "NameExpression",
|
|
43
47
|
"name": "string"
|
|
@@ -46,7 +50,7 @@
|
|
|
46
50
|
},
|
|
47
51
|
{
|
|
48
52
|
"title": "param",
|
|
49
|
-
"description": "Input parameters for the request. These vary by endpoint,
|
|
53
|
+
"description": "Input parameters for the request. These vary by endpoint, see {@link https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143957366/Data+APIs CommCare v0.5 docs}.",
|
|
50
54
|
"type": {
|
|
51
55
|
"type": "OptionalType",
|
|
52
56
|
"expression": {
|
|
@@ -93,12 +97,16 @@
|
|
|
93
97
|
"callback"
|
|
94
98
|
],
|
|
95
99
|
"docs": {
|
|
96
|
-
"description": "Make a POST request to CommCare
|
|
100
|
+
"description": "Make a POST request to CommCare's legacy v0.5 API.\nYou can pass Commcare body data as a JSON object.",
|
|
97
101
|
"tags": [
|
|
102
|
+
{
|
|
103
|
+
"title": "deprecated",
|
|
104
|
+
"description": "This function only works against CommCare's legacy v0.5 API (path: `/a/domain/api/v0.5/...`).\nFor current CommCare APIs, use {@link #http_post} instead."
|
|
105
|
+
},
|
|
98
106
|
{
|
|
99
107
|
"title": "example",
|
|
100
108
|
"description": "post(\"/user\", { \"username\":\"test\", \"password\":\"somepassword\" })",
|
|
101
|
-
"caption": "Create a user resource.Equivalent to
|
|
109
|
+
"caption": "Create a user resource. Equivalent to `/a/domain/api/v0.5/user`"
|
|
102
110
|
},
|
|
103
111
|
{
|
|
104
112
|
"title": "function",
|
|
@@ -112,7 +120,7 @@
|
|
|
112
120
|
},
|
|
113
121
|
{
|
|
114
122
|
"title": "param",
|
|
115
|
-
"description": "Path to resource",
|
|
123
|
+
"description": "Path to a v0.5 resource (e.g. `user`, `case`)",
|
|
116
124
|
"type": {
|
|
117
125
|
"type": "NameExpression",
|
|
118
126
|
"name": "string"
|
|
@@ -282,7 +290,7 @@
|
|
|
282
290
|
"postUrl"
|
|
283
291
|
],
|
|
284
292
|
"docs": {
|
|
285
|
-
"description": "Make a GET request to CommCare's Reports API
|
|
293
|
+
"description": "Make a GET request to CommCare's Reports API (v0.5) and POST the response somewhere else.",
|
|
286
294
|
"tags": [
|
|
287
295
|
{
|
|
288
296
|
"title": "public",
|
|
@@ -292,7 +300,7 @@
|
|
|
292
300
|
{
|
|
293
301
|
"title": "example",
|
|
294
302
|
"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
|
|
303
|
+
"caption": "Get 10 records from a report and post them to example.com. Equivalent to `/a/domain/api/v0.5/configurablereportdata/abcde?limit=10`"
|
|
296
304
|
},
|
|
297
305
|
{
|
|
298
306
|
"title": "function",
|
|
@@ -310,7 +318,7 @@
|
|
|
310
318
|
},
|
|
311
319
|
{
|
|
312
320
|
"title": "param",
|
|
313
|
-
"description": "Input parameters for the request, see {@link https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143957341/Download+Report+Data
|
|
321
|
+
"description": "Input parameters for the request, see {@link https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143957341/Download+Report+Data CommCare v0.5 docs}.",
|
|
314
322
|
"type": {
|
|
315
323
|
"type": "NameExpression",
|
|
316
324
|
"name": "Object"
|
|
@@ -351,17 +359,21 @@
|
|
|
351
359
|
"params"
|
|
352
360
|
],
|
|
353
361
|
"docs": {
|
|
354
|
-
"description": "Make a general HTTP request against the
|
|
362
|
+
"description": "Make a general HTTP request against the CommCare server.",
|
|
355
363
|
"tags": [
|
|
364
|
+
{
|
|
365
|
+
"title": "deprecated",
|
|
366
|
+
"description": "Use {@link #http_request} instead."
|
|
367
|
+
},
|
|
356
368
|
{
|
|
357
369
|
"title": "example",
|
|
358
370
|
"description": "request(\"GET\", \"/a/asri/api/v0.5/case\");",
|
|
359
|
-
"caption": "Get a resource
|
|
371
|
+
"caption": "Get a resource at a v0.5 path"
|
|
360
372
|
},
|
|
361
373
|
{
|
|
362
374
|
"title": "example",
|
|
363
|
-
"description": "request(\"GET\", \"/case\", {}, { offset:0, limit: 20 })",
|
|
364
|
-
"caption": "Get a resource using query parameters
|
|
375
|
+
"description": "request(\"GET\", \"/a/asri/api/v0.5/case\", {}, { offset:0, limit: 20 })",
|
|
376
|
+
"caption": "Get a resource using query parameters"
|
|
365
377
|
},
|
|
366
378
|
{
|
|
367
379
|
"title": "function",
|
package/dist/index.cjs
CHANGED
|
@@ -154,6 +154,13 @@ async function request(configuration, path, opts) {
|
|
|
154
154
|
|
|
155
155
|
// src/Adaptor.js
|
|
156
156
|
var import_language_common3 = require("@openfn/language-common");
|
|
157
|
+
var hasWarnedDeprecated = false;
|
|
158
|
+
function warnDeprecated(message) {
|
|
159
|
+
if (!hasWarnedDeprecated) {
|
|
160
|
+
hasWarnedDeprecated = true;
|
|
161
|
+
console.warn(message);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
157
164
|
function execute(...operations) {
|
|
158
165
|
const initialState = {
|
|
159
166
|
references: [],
|
|
@@ -164,6 +171,9 @@ function execute(...operations) {
|
|
|
164
171
|
};
|
|
165
172
|
}
|
|
166
173
|
function get(path, params = {}, callback = (s) => s) {
|
|
174
|
+
warnDeprecated(
|
|
175
|
+
"DEPRECATION WARNING: get() only works with CommCare's legacy v0.5 API (/a/domain/api/v0.5/...). Use http.get() for current CommCare APIs. get() will be removed in a future major version."
|
|
176
|
+
);
|
|
167
177
|
return async (state) => {
|
|
168
178
|
var _a, _b;
|
|
169
179
|
const { domain } = state.configuration;
|
|
@@ -225,6 +235,9 @@ function get(path, params = {}, callback = (s) => s) {
|
|
|
225
235
|
};
|
|
226
236
|
}
|
|
227
237
|
function post(path, data, params = {}, callback = (s) => s) {
|
|
238
|
+
warnDeprecated(
|
|
239
|
+
"DEPRECATION WARNING: post() only works with CommCare's legacy v0.5 API (/a/domain/api/v0.5/...). Use http.post() for current CommCare APIs. post() will be removed in a future major version."
|
|
240
|
+
);
|
|
228
241
|
return async (state) => {
|
|
229
242
|
const { domain } = state.configuration;
|
|
230
243
|
const [resolvedPath, resolvedData, resolvedParams] = (0, import_util2.expandReferences)(
|
|
@@ -314,6 +327,9 @@ function fetchReportData(reportId, params, postUrl) {
|
|
|
314
327
|
};
|
|
315
328
|
}
|
|
316
329
|
function request2(method, path, body, params = {}) {
|
|
330
|
+
warnDeprecated(
|
|
331
|
+
"DEPRECATION WARNING: request() is designed around the legacy v0.5 API. Use http.request() instead. request() will be removed in a future major version."
|
|
332
|
+
);
|
|
317
333
|
return async (state) => {
|
|
318
334
|
const [resolvedMethod, resolvedPath, resolvedBody, resolvedParams] = (0, import_util2.expandReferences)(state, method, path, body, params);
|
|
319
335
|
const response = await request(state.configuration, resolvedPath, {
|
package/dist/index.js
CHANGED
|
@@ -125,6 +125,13 @@ import {
|
|
|
125
125
|
merge,
|
|
126
126
|
sourceValue
|
|
127
127
|
} from "@openfn/language-common";
|
|
128
|
+
var hasWarnedDeprecated = false;
|
|
129
|
+
function warnDeprecated(message) {
|
|
130
|
+
if (!hasWarnedDeprecated) {
|
|
131
|
+
hasWarnedDeprecated = true;
|
|
132
|
+
console.warn(message);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
128
135
|
function execute(...operations) {
|
|
129
136
|
const initialState = {
|
|
130
137
|
references: [],
|
|
@@ -135,6 +142,9 @@ function execute(...operations) {
|
|
|
135
142
|
};
|
|
136
143
|
}
|
|
137
144
|
function get(path, params = {}, callback = (s) => s) {
|
|
145
|
+
warnDeprecated(
|
|
146
|
+
"DEPRECATION WARNING: get() only works with CommCare's legacy v0.5 API (/a/domain/api/v0.5/...). Use http.get() for current CommCare APIs. get() will be removed in a future major version."
|
|
147
|
+
);
|
|
138
148
|
return async (state) => {
|
|
139
149
|
var _a, _b;
|
|
140
150
|
const { domain } = state.configuration;
|
|
@@ -196,6 +206,9 @@ function get(path, params = {}, callback = (s) => s) {
|
|
|
196
206
|
};
|
|
197
207
|
}
|
|
198
208
|
function post(path, data, params = {}, callback = (s) => s) {
|
|
209
|
+
warnDeprecated(
|
|
210
|
+
"DEPRECATION WARNING: post() only works with CommCare's legacy v0.5 API (/a/domain/api/v0.5/...). Use http.post() for current CommCare APIs. post() will be removed in a future major version."
|
|
211
|
+
);
|
|
199
212
|
return async (state) => {
|
|
200
213
|
const { domain } = state.configuration;
|
|
201
214
|
const [resolvedPath, resolvedData, resolvedParams] = expandReferences(
|
|
@@ -285,6 +298,9 @@ function fetchReportData(reportId, params, postUrl) {
|
|
|
285
298
|
};
|
|
286
299
|
}
|
|
287
300
|
function request2(method, path, body, params = {}) {
|
|
301
|
+
warnDeprecated(
|
|
302
|
+
"DEPRECATION WARNING: request() is designed around the legacy v0.5 API. Use http.request() instead. request() will be removed in a future major version."
|
|
303
|
+
);
|
|
288
304
|
return async (state) => {
|
|
289
305
|
const [resolvedMethod, resolvedPath, resolvedBody, resolvedParams] = expandReferences(state, method, path, body, params);
|
|
290
306
|
const response = await request(state.configuration, resolvedPath, {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-commcare",
|
|
3
3
|
"label": "CommCare",
|
|
4
|
-
"version": "4.3.
|
|
4
|
+
"version": "4.3.3",
|
|
5
5
|
"description": "OpenFn adaptor for CommCare (Dimagi)",
|
|
6
6
|
"homepage": "https://docs.openfn.org",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/
|
|
9
|
+
"url": "https://github.com/OpenFn/adaptors.git"
|
|
10
10
|
},
|
|
11
11
|
"main": "dist/index.cjs",
|
|
12
12
|
"author": "Open Function Group",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"configuration-schema.json"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"@openfn/language-common": "3.3.5",
|
|
21
22
|
"JSONPath": "^0.10.0",
|
|
22
23
|
"js2xmlparser": "^1.0.0",
|
|
23
24
|
"lodash-fp": "^0.10.4",
|
|
24
|
-
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
|
|
25
|
-
"@openfn/language-common": "3.3.4"
|
|
25
|
+
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"assertion-error": "^1.1.0",
|
package/types/Adaptor.d.ts
CHANGED
|
@@ -20,37 +20,41 @@
|
|
|
20
20
|
*/
|
|
21
21
|
export function execute(...operations: Operations): Operation;
|
|
22
22
|
/**
|
|
23
|
-
* Make a GET request to CommCare
|
|
23
|
+
* Make a GET request to CommCare's legacy v0.5 API.
|
|
24
24
|
* You can pass Commcare query parameters as an object of key value pairs, which will map to parameters
|
|
25
25
|
* in the URL.
|
|
26
26
|
* The response body will be returned to `state.data` as JSON.
|
|
27
27
|
* Paginated responses will be fully downloaded and returned as a single array, _unless_ an `offset` is passed.
|
|
28
|
+
* @deprecated This function only works against CommCare's legacy v0.5 API (path: `/a/domain/api/v0.5/...`).
|
|
29
|
+
* For current CommCare APIs, use {@link #http_get} instead.
|
|
28
30
|
* @public
|
|
29
31
|
* @function
|
|
30
|
-
* @example <caption>Get a resource by Id. Equivalent to GET
|
|
32
|
+
* @example <caption>Get a resource by Id. Equivalent to GET `/a/domain/api/v0.5/case/12345`</caption>
|
|
31
33
|
* get("/case/12345")
|
|
32
|
-
* @example <caption>Get a resource with exactly 20 items. Equivalent to
|
|
34
|
+
* @example <caption>Get a resource with exactly 20 items. Equivalent to `/a/domain/api/v0.5/case?offset=0&limit=20`</caption>
|
|
33
35
|
* get("/case", { offset:0, limit: 20 })
|
|
34
|
-
* @example <caption>Get all items in a resource, and add them to state. Equivalent to
|
|
36
|
+
* @example <caption>Get all items in a resource, and add them to state. Equivalent to `/a/domain/api/v0.5/case`</caption>
|
|
35
37
|
* get("/case", {}, (state) => {
|
|
36
38
|
* state.cases.push(...state.data) // adds all cases to the cases array
|
|
37
39
|
* return state;
|
|
38
40
|
* })
|
|
39
|
-
* @param {string} path - Path to resource
|
|
40
|
-
* @param {Object} [params] - Input parameters for the request. These vary by endpoint,
|
|
41
|
+
* @param {string} path - Path to a v0.5 resource (e.g. `case`, `form`)
|
|
42
|
+
* @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 v0.5 docs}.
|
|
41
43
|
* @param {function} [callback] - Optional callback function. Invoked once per page of data retrieved.
|
|
42
44
|
* @state {CommcareHttpState}
|
|
43
45
|
* @returns {Operation}
|
|
44
46
|
*/
|
|
45
47
|
export function get(path: string, params?: any, callback?: Function): Operation;
|
|
46
48
|
/**
|
|
47
|
-
* Make a POST request to CommCare
|
|
49
|
+
* Make a POST request to CommCare's legacy v0.5 API.
|
|
48
50
|
* You can pass Commcare body data as a JSON object.
|
|
49
|
-
* @
|
|
51
|
+
* @deprecated This function only works against CommCare's legacy v0.5 API (path: `/a/domain/api/v0.5/...`).
|
|
52
|
+
* For current CommCare APIs, use {@link #http_post} instead.
|
|
53
|
+
* @example <caption>Create a user resource. Equivalent to `/a/domain/api/v0.5/user`</caption>
|
|
50
54
|
* post("/user", { "username":"test", "password":"somepassword" })
|
|
51
55
|
* @function
|
|
52
56
|
* @public
|
|
53
|
-
* @param {string} path - Path to resource
|
|
57
|
+
* @param {string} path - Path to a v0.5 resource (e.g. `user`, `case`)
|
|
54
58
|
* @param {object} data - Object or JSON to create a resource
|
|
55
59
|
* @param {Object} [params] - Optional request params
|
|
56
60
|
* @param {function} [callback] - Optional callback to handle the response
|
|
@@ -96,10 +100,9 @@ export function submitXls(data: any[], params: any): Operation;
|
|
|
96
100
|
*/
|
|
97
101
|
export function submit(data: any): Operation;
|
|
98
102
|
/**
|
|
99
|
-
* Make a GET request to CommCare's Reports API
|
|
100
|
-
* and POST the response somewhere else.
|
|
103
|
+
* Make a GET request to CommCare's Reports API (v0.5) and POST the response somewhere else.
|
|
101
104
|
* @public
|
|
102
|
-
* @example <caption>Get 10 records from a report and post them to example.com. Equivalent to
|
|
105
|
+
* @example <caption>Get 10 records from a report and post them to example.com. Equivalent to `/a/domain/api/v0.5/configurablereportdata/abcde?limit=10`</caption>
|
|
103
106
|
* fetchReportData(
|
|
104
107
|
* "abcde",
|
|
105
108
|
* { limit: 10 },
|
|
@@ -107,18 +110,19 @@ export function submit(data: any): Operation;
|
|
|
107
110
|
* )
|
|
108
111
|
* @function
|
|
109
112
|
* @param {String} reportId - API name of the report.
|
|
110
|
-
* @param {Object} params - Input parameters for the request, see {@link https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143957341/Download+Report+Data
|
|
113
|
+
* @param {Object} params - Input parameters for the request, see {@link https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143957341/Download+Report+Data CommCare v0.5 docs}.
|
|
111
114
|
* @param {String} postUrl - URL to which the response object will be posted.
|
|
112
115
|
* @state {CommcareHttpState}
|
|
113
116
|
* @returns {Operation}
|
|
114
117
|
*/
|
|
115
118
|
export function fetchReportData(reportId: string, params: any, postUrl: string): Operation;
|
|
116
119
|
/**
|
|
117
|
-
* Make a general HTTP request against the
|
|
118
|
-
* @
|
|
120
|
+
* Make a general HTTP request against the CommCare server.
|
|
121
|
+
* @deprecated Use {@link #http_request} instead.
|
|
122
|
+
* @example <caption>Get a resource at a v0.5 path</caption>
|
|
119
123
|
* request("GET", "/a/asri/api/v0.5/case");
|
|
120
|
-
* @example <caption>Get a resource using query parameters
|
|
121
|
-
* request("GET", "/case", {}, { offset:0, limit: 20 })
|
|
124
|
+
* @example <caption>Get a resource using query parameters</caption>
|
|
125
|
+
* request("GET", "/a/asri/api/v0.5/case", {}, { offset:0, limit: 20 })
|
|
122
126
|
* @function
|
|
123
127
|
* @public
|
|
124
128
|
* @param {string} method - HTTP method to use
|