@openfn/language-dhis2 6.1.0 → 6.3.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 +91 -1
- package/dist/index.cjs +29 -18
- package/dist/index.js +29 -19
- package/package.json +1 -1
- package/types/Adaptor.d.ts +19 -1
package/ast.json
CHANGED
|
@@ -330,6 +330,43 @@
|
|
|
330
330
|
},
|
|
331
331
|
"name": "options"
|
|
332
332
|
},
|
|
333
|
+
{
|
|
334
|
+
"title": "param",
|
|
335
|
+
"description": "The parameters for the request.",
|
|
336
|
+
"type": {
|
|
337
|
+
"type": "OptionalType",
|
|
338
|
+
"expression": {
|
|
339
|
+
"type": "NameExpression",
|
|
340
|
+
"name": "Object"
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
"name": "options.params"
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
"title": "param",
|
|
347
|
+
"description": "The configuration for the request, including headers, etc.",
|
|
348
|
+
"type": {
|
|
349
|
+
"type": "OptionalType",
|
|
350
|
+
"expression": {
|
|
351
|
+
"type": "NameExpression",
|
|
352
|
+
"name": "Object"
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
"name": "options.requestConfig"
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
"title": "param",
|
|
359
|
+
"description": "Optional flag to indicate if the response should be returned as a Base64 encoded string.",
|
|
360
|
+
"type": {
|
|
361
|
+
"type": "OptionalType",
|
|
362
|
+
"expression": {
|
|
363
|
+
"type": "NameExpression",
|
|
364
|
+
"name": "boolean"
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
"name": "options.asBase64",
|
|
368
|
+
"default": "false"
|
|
369
|
+
},
|
|
333
370
|
{
|
|
334
371
|
"title": "param",
|
|
335
372
|
"description": "Optional callback to handle the response",
|
|
@@ -382,7 +419,7 @@
|
|
|
382
419
|
}
|
|
383
420
|
]
|
|
384
421
|
},
|
|
385
|
-
"valid":
|
|
422
|
+
"valid": false
|
|
386
423
|
},
|
|
387
424
|
{
|
|
388
425
|
"name": "post",
|
|
@@ -854,6 +891,59 @@
|
|
|
854
891
|
},
|
|
855
892
|
"valid": true
|
|
856
893
|
},
|
|
894
|
+
{
|
|
895
|
+
"name": "findAttributeValueById",
|
|
896
|
+
"params": [
|
|
897
|
+
"trackedEntity",
|
|
898
|
+
"attributeUid"
|
|
899
|
+
],
|
|
900
|
+
"docs": {
|
|
901
|
+
"description": "Gets an attribute value by its uid",
|
|
902
|
+
"tags": [
|
|
903
|
+
{
|
|
904
|
+
"title": "public",
|
|
905
|
+
"description": null,
|
|
906
|
+
"type": null
|
|
907
|
+
},
|
|
908
|
+
{
|
|
909
|
+
"title": "example",
|
|
910
|
+
"description": "findAttributeValueById(state.tei, 'y1w2R6leVmh')"
|
|
911
|
+
},
|
|
912
|
+
{
|
|
913
|
+
"title": "function",
|
|
914
|
+
"description": null,
|
|
915
|
+
"name": null
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
"title": "param",
|
|
919
|
+
"description": "A tracked entity instance (TEI) object",
|
|
920
|
+
"type": {
|
|
921
|
+
"type": "NameExpression",
|
|
922
|
+
"name": "Object"
|
|
923
|
+
},
|
|
924
|
+
"name": "trackedEntity"
|
|
925
|
+
},
|
|
926
|
+
{
|
|
927
|
+
"title": "param",
|
|
928
|
+
"description": "The uid to search for in the TEI's attributes",
|
|
929
|
+
"type": {
|
|
930
|
+
"type": "NameExpression",
|
|
931
|
+
"name": "string"
|
|
932
|
+
},
|
|
933
|
+
"name": "attributeUid"
|
|
934
|
+
},
|
|
935
|
+
{
|
|
936
|
+
"title": "returns",
|
|
937
|
+
"description": null,
|
|
938
|
+
"type": {
|
|
939
|
+
"type": "NameExpression",
|
|
940
|
+
"name": "string"
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
]
|
|
944
|
+
},
|
|
945
|
+
"valid": true
|
|
946
|
+
},
|
|
857
947
|
{
|
|
858
948
|
"name": "findAttributeValue",
|
|
859
949
|
"params": [
|
package/dist/index.cjs
CHANGED
|
@@ -41,6 +41,7 @@ __export(src_exports, {
|
|
|
41
41
|
field: () => import_language_common3.field,
|
|
42
42
|
fields: () => import_language_common3.fields,
|
|
43
43
|
findAttributeValue: () => findAttributeValue,
|
|
44
|
+
findAttributeValueById: () => findAttributeValueById,
|
|
44
45
|
fn: () => import_language_common3.fn,
|
|
45
46
|
fnIf: () => import_language_common3.fnIf,
|
|
46
47
|
get: () => get,
|
|
@@ -222,6 +223,7 @@ __export(Adaptor_exports, {
|
|
|
222
223
|
field: () => import_language_common3.field,
|
|
223
224
|
fields: () => import_language_common3.fields,
|
|
224
225
|
findAttributeValue: () => findAttributeValue,
|
|
226
|
+
findAttributeValueById: () => findAttributeValueById,
|
|
225
227
|
fn: () => import_language_common3.fn,
|
|
226
228
|
fnIf: () => import_language_common3.fnIf,
|
|
227
229
|
get: () => get,
|
|
@@ -247,27 +249,27 @@ function request({ username, password, pat }, axiosRequest) {
|
|
|
247
249
|
const { method, url, params } = axiosRequest;
|
|
248
250
|
console.log(`Sending ${method} request to ${url}`);
|
|
249
251
|
if (params)
|
|
250
|
-
console.log(`
|
|
252
|
+
console.log(`with params: `, params);
|
|
251
253
|
const safeRedirect = ["get", "head", "options", "trace"].includes(
|
|
252
254
|
method.toLowerCase()
|
|
253
255
|
);
|
|
254
|
-
const headers = {
|
|
256
|
+
const headers = {
|
|
257
|
+
"Content-Type": "application/json"
|
|
258
|
+
};
|
|
255
259
|
let auth;
|
|
256
260
|
if (pat) {
|
|
257
261
|
headers.Authorization = `ApiToken ${pat}`;
|
|
258
262
|
} else {
|
|
259
263
|
auth = { username, password };
|
|
260
264
|
}
|
|
261
|
-
return (0, import_axios2.default)(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
);
|
|
265
|
+
return (0, import_axios2.default)({
|
|
266
|
+
headers,
|
|
267
|
+
responseType: "json",
|
|
268
|
+
auth,
|
|
269
|
+
maxRedirects: safeRedirect ? 5 : 0,
|
|
270
|
+
paramsSerializer: (params2) => import_qs.default.stringify(params2, { arrayFormat: "repeat" }),
|
|
271
|
+
...axiosRequest
|
|
272
|
+
});
|
|
271
273
|
}
|
|
272
274
|
|
|
273
275
|
// src/Adaptor.js
|
|
@@ -308,7 +310,7 @@ import_axios3.default.interceptors.response.use(
|
|
|
308
310
|
var _a, _b;
|
|
309
311
|
const contentType = (_a = response.headers["content-type"]) == null ? void 0 : _a.split(";")[0];
|
|
310
312
|
const acceptHeaders = response.config.headers["Accept"].split(";")[0].split(",");
|
|
311
|
-
if (response.config.method === "get") {
|
|
313
|
+
if (response.config.method === "get" && response.config.responseType != "arraybuffer") {
|
|
312
314
|
if (indexOf(acceptHeaders, contentType) === -1) {
|
|
313
315
|
const newError = {
|
|
314
316
|
status: 404,
|
|
@@ -414,21 +416,25 @@ function update(resourceType, path, data, options = {}, callback = (s) => s) {
|
|
|
414
416
|
});
|
|
415
417
|
};
|
|
416
418
|
}
|
|
417
|
-
function get(resourceType, query, options = {}, callback =
|
|
419
|
+
function get(resourceType, query, options = {}, callback = (s) => s) {
|
|
418
420
|
return (state) => {
|
|
419
421
|
console.log("Preparing get operation...");
|
|
420
422
|
const [resolvedResourceType, resolvedQuery, resolvedOptions] = (0, import_util.expandReferences)(state, resourceType, query, options);
|
|
421
|
-
const { params, requestConfig } = resolvedOptions;
|
|
423
|
+
const { params, requestConfig, asBase64 = false } = resolvedOptions;
|
|
422
424
|
const { configuration } = state;
|
|
423
425
|
return request(configuration, {
|
|
424
426
|
method: "get",
|
|
425
427
|
url: generateUrl(configuration, resolvedOptions, resolvedResourceType),
|
|
426
|
-
params: {
|
|
427
|
-
|
|
428
|
+
params: {
|
|
429
|
+
...resolvedQuery,
|
|
430
|
+
...params
|
|
431
|
+
},
|
|
432
|
+
responseType: asBase64 ? "arraybuffer" : "json",
|
|
428
433
|
...requestConfig
|
|
429
434
|
}).then((result) => {
|
|
430
435
|
console.log(`Retrieved ${resolvedResourceType}`);
|
|
431
|
-
|
|
436
|
+
const response = asBase64 ? { data: (0, import_util.encode)(result.data) } : result;
|
|
437
|
+
return handleResponse(response, state, callback);
|
|
432
438
|
});
|
|
433
439
|
};
|
|
434
440
|
}
|
|
@@ -614,6 +620,10 @@ function destroy(resourceType, path, data = null, options = {}, callback = false
|
|
|
614
620
|
});
|
|
615
621
|
};
|
|
616
622
|
}
|
|
623
|
+
function findAttributeValueById(trackedEntity, attributeUid) {
|
|
624
|
+
var _a, _b;
|
|
625
|
+
return (_b = (_a = trackedEntity == null ? void 0 : trackedEntity.attributes) == null ? void 0 : _a.find((a) => (a == null ? void 0 : a.attribute) == attributeUid)) == null ? void 0 : _b.value;
|
|
626
|
+
}
|
|
617
627
|
function findAttributeValue(trackedEntity, attributeDisplayName) {
|
|
618
628
|
var _a, _b;
|
|
619
629
|
return (_b = (_a = trackedEntity == null ? void 0 : trackedEntity.attributes) == null ? void 0 : _a.find(
|
|
@@ -677,6 +687,7 @@ var src_default = Adaptor_exports;
|
|
|
677
687
|
field,
|
|
678
688
|
fields,
|
|
679
689
|
findAttributeValue,
|
|
690
|
+
findAttributeValueById,
|
|
680
691
|
fn,
|
|
681
692
|
fnIf,
|
|
682
693
|
get,
|
package/dist/index.js
CHANGED
|
@@ -169,6 +169,7 @@ __export(Adaptor_exports, {
|
|
|
169
169
|
field: () => field,
|
|
170
170
|
fields: () => fields,
|
|
171
171
|
findAttributeValue: () => findAttributeValue,
|
|
172
|
+
findAttributeValueById: () => findAttributeValueById,
|
|
172
173
|
fn: () => fn,
|
|
173
174
|
fnIf: () => fnIf,
|
|
174
175
|
get: () => get,
|
|
@@ -184,7 +185,7 @@ __export(Adaptor_exports, {
|
|
|
184
185
|
});
|
|
185
186
|
import axios3 from "axios";
|
|
186
187
|
import { execute as commonExecute } from "@openfn/language-common";
|
|
187
|
-
import { expandReferences } from "@openfn/language-common/util";
|
|
188
|
+
import { expandReferences, encode } from "@openfn/language-common/util";
|
|
188
189
|
import _ from "lodash";
|
|
189
190
|
|
|
190
191
|
// src/Client.js
|
|
@@ -194,27 +195,27 @@ function request({ username, password, pat }, axiosRequest) {
|
|
|
194
195
|
const { method, url, params } = axiosRequest;
|
|
195
196
|
console.log(`Sending ${method} request to ${url}`);
|
|
196
197
|
if (params)
|
|
197
|
-
console.log(`
|
|
198
|
+
console.log(`with params: `, params);
|
|
198
199
|
const safeRedirect = ["get", "head", "options", "trace"].includes(
|
|
199
200
|
method.toLowerCase()
|
|
200
201
|
);
|
|
201
|
-
const headers = {
|
|
202
|
+
const headers = {
|
|
203
|
+
"Content-Type": "application/json"
|
|
204
|
+
};
|
|
202
205
|
let auth;
|
|
203
206
|
if (pat) {
|
|
204
207
|
headers.Authorization = `ApiToken ${pat}`;
|
|
205
208
|
} else {
|
|
206
209
|
auth = { username, password };
|
|
207
210
|
}
|
|
208
|
-
return axios2(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
);
|
|
211
|
+
return axios2({
|
|
212
|
+
headers,
|
|
213
|
+
responseType: "json",
|
|
214
|
+
auth,
|
|
215
|
+
maxRedirects: safeRedirect ? 5 : 0,
|
|
216
|
+
paramsSerializer: (params2) => Qs.stringify(params2, { arrayFormat: "repeat" }),
|
|
217
|
+
...axiosRequest
|
|
218
|
+
});
|
|
218
219
|
}
|
|
219
220
|
|
|
220
221
|
// src/Adaptor.js
|
|
@@ -271,7 +272,7 @@ axios3.interceptors.response.use(
|
|
|
271
272
|
var _a, _b;
|
|
272
273
|
const contentType = (_a = response.headers["content-type"]) == null ? void 0 : _a.split(";")[0];
|
|
273
274
|
const acceptHeaders = response.config.headers["Accept"].split(";")[0].split(",");
|
|
274
|
-
if (response.config.method === "get") {
|
|
275
|
+
if (response.config.method === "get" && response.config.responseType != "arraybuffer") {
|
|
275
276
|
if (indexOf(acceptHeaders, contentType) === -1) {
|
|
276
277
|
const newError = {
|
|
277
278
|
status: 404,
|
|
@@ -377,21 +378,25 @@ function update(resourceType, path, data, options = {}, callback = (s) => s) {
|
|
|
377
378
|
});
|
|
378
379
|
};
|
|
379
380
|
}
|
|
380
|
-
function get(resourceType, query, options = {}, callback =
|
|
381
|
+
function get(resourceType, query, options = {}, callback = (s) => s) {
|
|
381
382
|
return (state) => {
|
|
382
383
|
console.log("Preparing get operation...");
|
|
383
384
|
const [resolvedResourceType, resolvedQuery, resolvedOptions] = expandReferences(state, resourceType, query, options);
|
|
384
|
-
const { params, requestConfig } = resolvedOptions;
|
|
385
|
+
const { params, requestConfig, asBase64 = false } = resolvedOptions;
|
|
385
386
|
const { configuration } = state;
|
|
386
387
|
return request(configuration, {
|
|
387
388
|
method: "get",
|
|
388
389
|
url: generateUrl(configuration, resolvedOptions, resolvedResourceType),
|
|
389
|
-
params: {
|
|
390
|
-
|
|
390
|
+
params: {
|
|
391
|
+
...resolvedQuery,
|
|
392
|
+
...params
|
|
393
|
+
},
|
|
394
|
+
responseType: asBase64 ? "arraybuffer" : "json",
|
|
391
395
|
...requestConfig
|
|
392
396
|
}).then((result) => {
|
|
393
397
|
console.log(`Retrieved ${resolvedResourceType}`);
|
|
394
|
-
|
|
398
|
+
const response = asBase64 ? { data: encode(result.data) } : result;
|
|
399
|
+
return handleResponse(response, state, callback);
|
|
395
400
|
});
|
|
396
401
|
};
|
|
397
402
|
}
|
|
@@ -577,6 +582,10 @@ function destroy(resourceType, path, data = null, options = {}, callback = false
|
|
|
577
582
|
});
|
|
578
583
|
};
|
|
579
584
|
}
|
|
585
|
+
function findAttributeValueById(trackedEntity, attributeUid) {
|
|
586
|
+
var _a, _b;
|
|
587
|
+
return (_b = (_a = trackedEntity == null ? void 0 : trackedEntity.attributes) == null ? void 0 : _a.find((a) => (a == null ? void 0 : a.attribute) == attributeUid)) == null ? void 0 : _b.value;
|
|
588
|
+
}
|
|
580
589
|
function findAttributeValue(trackedEntity, attributeDisplayName) {
|
|
581
590
|
var _a, _b;
|
|
582
591
|
return (_b = (_a = trackedEntity == null ? void 0 : trackedEntity.attributes) == null ? void 0 : _a.find(
|
|
@@ -640,6 +649,7 @@ export {
|
|
|
640
649
|
field,
|
|
641
650
|
fields,
|
|
642
651
|
findAttributeValue,
|
|
652
|
+
findAttributeValueById,
|
|
643
653
|
fn,
|
|
644
654
|
fnIf,
|
|
645
655
|
get,
|
package/package.json
CHANGED
package/types/Adaptor.d.ts
CHANGED
|
@@ -276,6 +276,9 @@ export function update(resourceType: string, path: string, data: any, options?:
|
|
|
276
276
|
* @param {string} resourceType - The type of resource to get(use its `plural` name). E.g. `dataElements`, `tracker/trackedEntities`,`organisationUnits`, etc.
|
|
277
277
|
* @param {Object} query - A query object that will limit what resources are retrieved when converted into request params.
|
|
278
278
|
* @param {Object} [options] - Optional `options` to define URL parameters via params beyond filters, request configuration (e.g. `auth`) and DHIS2 api version to use.
|
|
279
|
+
* @param {Object} [options.params] - The parameters for the request.
|
|
280
|
+
* @param {Object} [options.requestConfig] - The configuration for the request, including headers, etc.
|
|
281
|
+
* @param {boolean} [options.asBase64=false] - Optional flag to indicate if the response should be returned as a Base64 encoded string.
|
|
279
282
|
* @param {function} [callback] - Optional callback to handle the response
|
|
280
283
|
* @returns {Operation} state
|
|
281
284
|
* @example <caption>Get all data values for the 'pBOMPrpg1QX' dataset</caption>
|
|
@@ -298,7 +301,11 @@ export function update(resourceType: string, path: string, data: any, options?:
|
|
|
298
301
|
* trackedEntity:['F8yKM85NbxW'],
|
|
299
302
|
* });
|
|
300
303
|
*/
|
|
301
|
-
export function get(resourceType: string, query: any, options?:
|
|
304
|
+
export function get(resourceType: string, query: any, options?: {
|
|
305
|
+
params?: any;
|
|
306
|
+
requestConfig?: any;
|
|
307
|
+
asBase64?: boolean;
|
|
308
|
+
}, callback?: Function): Operation;
|
|
302
309
|
/**
|
|
303
310
|
* Post data. Generic helper method for posting data of any kind to DHIS2.
|
|
304
311
|
* This can be used to create `DataValueSets`,`events`,`trackers`,etc.
|
|
@@ -398,6 +405,17 @@ export function destroy(resourceType: string, path: string, data?: any, options?
|
|
|
398
405
|
operationName: string;
|
|
399
406
|
resourceType: string;
|
|
400
407
|
}, callback?: Function): Operation;
|
|
408
|
+
/**
|
|
409
|
+
* Gets an attribute value by its uid
|
|
410
|
+
* @public
|
|
411
|
+
* @example
|
|
412
|
+
* findAttributeValueById(state.tei, 'y1w2R6leVmh')
|
|
413
|
+
* @function
|
|
414
|
+
* @param {Object} trackedEntity - A tracked entity instance (TEI) object
|
|
415
|
+
* @param {string} attributeUid - The uid to search for in the TEI's attributes
|
|
416
|
+
* @returns {string}
|
|
417
|
+
*/
|
|
418
|
+
export function findAttributeValueById(trackedEntity: any, attributeUid: string): string;
|
|
401
419
|
/**
|
|
402
420
|
* Gets an attribute value by its case-insensitive display name
|
|
403
421
|
* @public
|