@openfn/language-dhis2 3.2.7 → 3.2.8
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/dist/index.cjs +185 -53
- package/dist/index.js +166 -39
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -45,6 +45,7 @@ __export(src_exports, {
|
|
|
45
45
|
http: () => import_language_common3.http,
|
|
46
46
|
lastReferenceValue: () => import_language_common3.lastReferenceValue,
|
|
47
47
|
merge: () => import_language_common3.merge,
|
|
48
|
+
metadata: () => metadata_default,
|
|
48
49
|
patch: () => patch,
|
|
49
50
|
sourceValue: () => import_language_common3.sourceValue,
|
|
50
51
|
update: () => update,
|
|
@@ -52,36 +53,45 @@ __export(src_exports, {
|
|
|
52
53
|
});
|
|
53
54
|
module.exports = __toCommonJS(src_exports);
|
|
54
55
|
|
|
55
|
-
// src/
|
|
56
|
-
var
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
56
|
+
// ../../tools/metadata/src/create-mock.js
|
|
57
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
58
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
59
|
+
|
|
60
|
+
// ../../tools/metadata/src/model.js
|
|
61
|
+
var createEntity = (name, type, props = {}, children) => {
|
|
62
|
+
const { label, datatype, value, ...meta } = props;
|
|
63
|
+
const e = {
|
|
64
|
+
name,
|
|
65
|
+
type,
|
|
66
|
+
addChild: function(e2, name2) {
|
|
67
|
+
if (!this.children) {
|
|
68
|
+
this.children = name2 ? {} : [];
|
|
69
|
+
}
|
|
70
|
+
if (name2) {
|
|
71
|
+
if (isArray(this.children)) {
|
|
72
|
+
throw new Error("Cannot add a named entity to child array");
|
|
73
|
+
}
|
|
74
|
+
this.children[name2] = e2;
|
|
75
|
+
} else {
|
|
76
|
+
this.children.push(e2);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
if (label) {
|
|
81
|
+
e.label = label;
|
|
82
|
+
}
|
|
83
|
+
if (datatype) {
|
|
84
|
+
e.datatype = datatype;
|
|
85
|
+
}
|
|
86
|
+
if (children) {
|
|
87
|
+
e.children = children;
|
|
88
|
+
}
|
|
89
|
+
e.meta = meta || {};
|
|
90
|
+
return e;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// src/meta/helper.js
|
|
94
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
85
95
|
|
|
86
96
|
// src/Utils.js
|
|
87
97
|
var import_language_common = require("@openfn/language-common");
|
|
@@ -127,11 +137,11 @@ function handleResponse(result, state, callback) {
|
|
|
127
137
|
function prettyJson(data) {
|
|
128
138
|
return JSON.stringify(data, null, 2);
|
|
129
139
|
}
|
|
130
|
-
var
|
|
140
|
+
var isArray2 = (variable) => !!variable && variable.constructor === Array;
|
|
131
141
|
function nestArray(data, key) {
|
|
132
|
-
return
|
|
142
|
+
return isArray2(data) ? { [key]: data } : data;
|
|
133
143
|
}
|
|
134
|
-
function generateUrl(configuration, options, resourceType,
|
|
144
|
+
function generateUrl(configuration, options, resourceType, path2 = null) {
|
|
135
145
|
let { hostUrl, apiVersion } = configuration;
|
|
136
146
|
const urlString = "/" + resourceType;
|
|
137
147
|
if (options == null ? void 0 : options.apiVersion)
|
|
@@ -139,13 +149,134 @@ function generateUrl(configuration, options, resourceType, path = null) {
|
|
|
139
149
|
const apiMessage = apiVersion ? `Using DHIS2 api version ${apiVersion}` : "Using latest available version of the DHIS2 api on this server.";
|
|
140
150
|
console.log(apiMessage);
|
|
141
151
|
const url = buildUrl(urlString, hostUrl, apiVersion);
|
|
142
|
-
if (
|
|
143
|
-
return `${url}/${
|
|
152
|
+
if (path2)
|
|
153
|
+
return `${url}/${path2}`;
|
|
144
154
|
return url;
|
|
145
155
|
}
|
|
146
156
|
|
|
157
|
+
// src/meta/helper.js
|
|
158
|
+
var createHelper = (configuration = {}) => {
|
|
159
|
+
const { username, password } = configuration;
|
|
160
|
+
const get2 = (url) => (0, import_axios.default)({
|
|
161
|
+
url,
|
|
162
|
+
headers: { "Content-Type": "application/json" },
|
|
163
|
+
responseType: "json",
|
|
164
|
+
auth: { username, password },
|
|
165
|
+
params: { paging: false }
|
|
166
|
+
});
|
|
167
|
+
const getResourceTypes = async () => {
|
|
168
|
+
return [
|
|
169
|
+
"dataElementGroups",
|
|
170
|
+
"dataElementGroupSets",
|
|
171
|
+
"dataElements",
|
|
172
|
+
"dataSetNotificationTemplates",
|
|
173
|
+
"dataSets",
|
|
174
|
+
"dataValueSets",
|
|
175
|
+
"enrollments",
|
|
176
|
+
"events",
|
|
177
|
+
"organisationUnitProfile",
|
|
178
|
+
"organisationUnits",
|
|
179
|
+
"programs",
|
|
180
|
+
"trackedEntityAttributes",
|
|
181
|
+
"trackedEntityInstances"
|
|
182
|
+
];
|
|
183
|
+
};
|
|
184
|
+
const getOrgUnits = async () => {
|
|
185
|
+
const url = generateUrl(configuration, {}, "organisationUnits");
|
|
186
|
+
const response = await get2(url);
|
|
187
|
+
return response.data;
|
|
188
|
+
};
|
|
189
|
+
const getPrograms = () => {
|
|
190
|
+
};
|
|
191
|
+
const getTrackedEntityTypes = async () => {
|
|
192
|
+
const url = generateUrl(configuration, {}, "trackedEntityTypes");
|
|
193
|
+
const response = await get2(url);
|
|
194
|
+
return response.data;
|
|
195
|
+
};
|
|
196
|
+
const getAttributes = async () => {
|
|
197
|
+
const url = generateUrl(configuration, {}, "attributes");
|
|
198
|
+
const response = await get2(url);
|
|
199
|
+
return response.data;
|
|
200
|
+
};
|
|
201
|
+
return {
|
|
202
|
+
getResourceTypes,
|
|
203
|
+
getOrgUnits,
|
|
204
|
+
getTrackedEntityTypes,
|
|
205
|
+
getAttributes
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
var helper_default = createHelper;
|
|
209
|
+
|
|
210
|
+
// src/meta/metadata.js
|
|
211
|
+
var metadata = async (configuration = {}, helper) => {
|
|
212
|
+
var _a, _b;
|
|
213
|
+
if (!helper) {
|
|
214
|
+
helper = helper_default(configuration);
|
|
215
|
+
}
|
|
216
|
+
const children = {};
|
|
217
|
+
const units = await helper.getOrgUnits();
|
|
218
|
+
children.orgUnits = units.organisationUnits.map(
|
|
219
|
+
(unit) => createEntity(unit.id, "orgUnit", {
|
|
220
|
+
datatype: "string",
|
|
221
|
+
label: unit.displayName
|
|
222
|
+
})
|
|
223
|
+
);
|
|
224
|
+
children.resourceTypes = await helper.getResourceTypes();
|
|
225
|
+
const types = await helper.getTrackedEntityTypes() ?? [];
|
|
226
|
+
children.trackedEntityTypes = ((_a = types.trackedEntityTypes) == null ? void 0 : _a.map(
|
|
227
|
+
(type) => createEntity(type.id, "trackedEntityType", {
|
|
228
|
+
datatype: "string",
|
|
229
|
+
label: type.displayName
|
|
230
|
+
})
|
|
231
|
+
)) ?? [];
|
|
232
|
+
const attributes = await helper.getAttributes() ?? [];
|
|
233
|
+
children.attributes = ((_b = attributes.attributes) == null ? void 0 : _b.map(
|
|
234
|
+
(attr2) => createEntity(attr2.id, "attribute", {
|
|
235
|
+
datatype: "string",
|
|
236
|
+
label: attr2.displayName
|
|
237
|
+
})
|
|
238
|
+
)) ?? [];
|
|
239
|
+
return {
|
|
240
|
+
type: "model",
|
|
241
|
+
name: "dhis2",
|
|
242
|
+
children
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
var metadata_default = metadata;
|
|
246
|
+
|
|
247
|
+
// src/Adaptor.js
|
|
248
|
+
var Adaptor_exports = {};
|
|
249
|
+
__export(Adaptor_exports, {
|
|
250
|
+
alterState: () => import_language_common3.alterState,
|
|
251
|
+
attr: () => attr,
|
|
252
|
+
create: () => create,
|
|
253
|
+
dataPath: () => import_language_common3.dataPath,
|
|
254
|
+
dataValue: () => import_language_common3.dataValue,
|
|
255
|
+
dateFns: () => import_language_common3.dateFns,
|
|
256
|
+
destroy: () => destroy,
|
|
257
|
+
discover: () => discover,
|
|
258
|
+
dv: () => dv,
|
|
259
|
+
each: () => import_language_common3.each,
|
|
260
|
+
execute: () => execute,
|
|
261
|
+
field: () => import_language_common3.field,
|
|
262
|
+
fields: () => import_language_common3.fields,
|
|
263
|
+
findAttributeValue: () => findAttributeValue,
|
|
264
|
+
fn: () => import_language_common3.fn,
|
|
265
|
+
get: () => get,
|
|
266
|
+
http: () => import_language_common3.http,
|
|
267
|
+
lastReferenceValue: () => import_language_common3.lastReferenceValue,
|
|
268
|
+
merge: () => import_language_common3.merge,
|
|
269
|
+
patch: () => patch,
|
|
270
|
+
sourceValue: () => import_language_common3.sourceValue,
|
|
271
|
+
update: () => update,
|
|
272
|
+
upsert: () => upsert
|
|
273
|
+
});
|
|
274
|
+
var import_axios3 = __toESM(require("axios"), 1);
|
|
275
|
+
var import_lodash = __toESM(require("lodash"), 1);
|
|
276
|
+
var import_language_common2 = require("@openfn/language-common");
|
|
277
|
+
|
|
147
278
|
// src/Client.js
|
|
148
|
-
var
|
|
279
|
+
var import_axios2 = __toESM(require("axios"), 1);
|
|
149
280
|
var import_qs = __toESM(require("qs"), 1);
|
|
150
281
|
function request({ username, password }, axiosRequest) {
|
|
151
282
|
const { method, url, params } = axiosRequest;
|
|
@@ -155,7 +286,7 @@ function request({ username, password }, axiosRequest) {
|
|
|
155
286
|
const safeRedirect = ["get", "head", "options", "trace"].includes(
|
|
156
287
|
method.toLowerCase()
|
|
157
288
|
);
|
|
158
|
-
return (0,
|
|
289
|
+
return (0, import_axios2.default)({
|
|
159
290
|
headers: { "Content-Type": "application/json" },
|
|
160
291
|
responseType: "json",
|
|
161
292
|
maxRedirects: safeRedirect ? 5 : 0,
|
|
@@ -191,7 +322,7 @@ function configMigrationHelper(state) {
|
|
|
191
322
|
}
|
|
192
323
|
return state;
|
|
193
324
|
}
|
|
194
|
-
|
|
325
|
+
import_axios3.default.interceptors.response.use(
|
|
195
326
|
function(response) {
|
|
196
327
|
var _a, _b;
|
|
197
328
|
const contentType = (_a = response.headers["content-type"]) == null ? void 0 : _a.split(";")[0];
|
|
@@ -257,23 +388,23 @@ function create(resourceType, data, options = {}, callback = false) {
|
|
|
257
388
|
});
|
|
258
389
|
};
|
|
259
390
|
}
|
|
260
|
-
function update(resourceType,
|
|
391
|
+
function update(resourceType, path2, data, options = {}, callback = false) {
|
|
261
392
|
return (state) => {
|
|
262
393
|
console.log(`Preparing update operation...`);
|
|
263
394
|
resourceType = (0, import_language_common2.expandReferences)(resourceType)(state);
|
|
264
|
-
|
|
395
|
+
path2 = (0, import_language_common2.expandReferences)(path2)(state);
|
|
265
396
|
data = (0, import_language_common2.expandReferences)(data)(state);
|
|
266
397
|
options = (0, import_language_common2.expandReferences)(options)(state);
|
|
267
398
|
const { params, requestConfig } = options;
|
|
268
399
|
const { configuration } = state;
|
|
269
400
|
return request(configuration, {
|
|
270
401
|
method: "put",
|
|
271
|
-
url: generateUrl(configuration, options, resourceType,
|
|
402
|
+
url: generateUrl(configuration, options, resourceType, path2),
|
|
272
403
|
params,
|
|
273
404
|
data,
|
|
274
405
|
...requestConfig
|
|
275
406
|
}).then((result) => {
|
|
276
|
-
Log.success(`Updated ${resourceType} at ${
|
|
407
|
+
Log.success(`Updated ${resourceType} at ${path2}`);
|
|
277
408
|
return handleResponse(result, state, callback);
|
|
278
409
|
});
|
|
279
410
|
};
|
|
@@ -314,8 +445,8 @@ function upsert(resourceType, query, data, options = {}, callback = false) {
|
|
|
314
445
|
} else if (resources.length <= 0) {
|
|
315
446
|
return create(resourceType, data, options)(state);
|
|
316
447
|
} else {
|
|
317
|
-
const
|
|
318
|
-
return update(resourceType,
|
|
448
|
+
const path2 = resources[0][selectId(resourceType)];
|
|
449
|
+
return update(resourceType, path2, data, options)(state);
|
|
319
450
|
}
|
|
320
451
|
}).then((result) => {
|
|
321
452
|
Log.success(`Performed a "composed upsert" on ${resourceType}`);
|
|
@@ -328,7 +459,7 @@ function discover(httpMethod, endpoint) {
|
|
|
328
459
|
console.log(
|
|
329
460
|
`Discovering query/import parameters for ${httpMethod} on ${endpoint}`
|
|
330
461
|
);
|
|
331
|
-
return
|
|
462
|
+
return import_axios3.default.get(
|
|
332
463
|
"https://dhis2.github.io/dhis2-api-specification/spec/metadata_openapi.json",
|
|
333
464
|
{
|
|
334
465
|
transformResponse: [
|
|
@@ -389,44 +520,44 @@ ${prettyJson(
|
|
|
389
520
|
});
|
|
390
521
|
};
|
|
391
522
|
}
|
|
392
|
-
function patch(resourceType,
|
|
523
|
+
function patch(resourceType, path2, data, options = {}, callback = false) {
|
|
393
524
|
return (state) => {
|
|
394
525
|
console.log("Preparing patch operation...");
|
|
395
526
|
resourceType = (0, import_language_common2.expandReferences)(resourceType)(state);
|
|
396
|
-
|
|
527
|
+
path2 = (0, import_language_common2.expandReferences)(path2)(state);
|
|
397
528
|
data = (0, import_language_common2.expandReferences)(data)(state);
|
|
398
529
|
options = (0, import_language_common2.expandReferences)(options)(state);
|
|
399
530
|
const { params, requestConfig } = options;
|
|
400
531
|
const { configuration } = state;
|
|
401
532
|
return request(configuration, {
|
|
402
533
|
method: "patch",
|
|
403
|
-
url: generateUrl(configuration, options, resourceType,
|
|
534
|
+
url: generateUrl(configuration, options, resourceType, path2),
|
|
404
535
|
params,
|
|
405
536
|
data,
|
|
406
537
|
...requestConfig
|
|
407
538
|
}).then((result) => {
|
|
408
|
-
Log.success(`Patched ${resourceType} at ${
|
|
539
|
+
Log.success(`Patched ${resourceType} at ${path2}`);
|
|
409
540
|
return handleResponse(result, state, callback);
|
|
410
541
|
});
|
|
411
542
|
};
|
|
412
543
|
}
|
|
413
|
-
function destroy(resourceType,
|
|
544
|
+
function destroy(resourceType, path2, data = null, options = {}, callback = false) {
|
|
414
545
|
return (state) => {
|
|
415
546
|
console.log("Preparing destroy operation...");
|
|
416
547
|
resourceType = (0, import_language_common2.expandReferences)(resourceType)(state);
|
|
417
|
-
|
|
548
|
+
path2 = (0, import_language_common2.expandReferences)(path2)(state);
|
|
418
549
|
data = (0, import_language_common2.expandReferences)(data)(state);
|
|
419
550
|
options = (0, import_language_common2.expandReferences)(options)(state);
|
|
420
551
|
const { params, requestConfig } = options;
|
|
421
552
|
const { configuration } = state;
|
|
422
553
|
return request({
|
|
423
554
|
method: "delete",
|
|
424
|
-
url: generateUrl(configuration, options, resourceType,
|
|
555
|
+
url: generateUrl(configuration, options, resourceType, path2),
|
|
425
556
|
params,
|
|
426
557
|
data,
|
|
427
558
|
...requestConfig
|
|
428
559
|
}).then((result) => {
|
|
429
|
-
Log.success(`Deleted ${resourceType} at ${
|
|
560
|
+
Log.success(`Deleted ${resourceType} at ${path2}`);
|
|
430
561
|
return handleResponse(result, state, callback);
|
|
431
562
|
});
|
|
432
563
|
};
|
|
@@ -467,6 +598,7 @@ var src_default = Adaptor_exports;
|
|
|
467
598
|
http,
|
|
468
599
|
lastReferenceValue,
|
|
469
600
|
merge,
|
|
601
|
+
metadata,
|
|
470
602
|
patch,
|
|
471
603
|
sourceValue,
|
|
472
604
|
update,
|
package/dist/index.js
CHANGED
|
@@ -4,39 +4,41 @@ var __export = (target, all) => {
|
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
// src/
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
7
|
+
// ../../tools/metadata/src/model.js
|
|
8
|
+
var createEntity = (name, type, props = {}, children) => {
|
|
9
|
+
const { label, datatype, value, ...meta } = props;
|
|
10
|
+
const e = {
|
|
11
|
+
name,
|
|
12
|
+
type,
|
|
13
|
+
addChild: function(e2, name2) {
|
|
14
|
+
if (!this.children) {
|
|
15
|
+
this.children = name2 ? {} : [];
|
|
16
|
+
}
|
|
17
|
+
if (name2) {
|
|
18
|
+
if (isArray(this.children)) {
|
|
19
|
+
throw new Error("Cannot add a named entity to child array");
|
|
20
|
+
}
|
|
21
|
+
this.children[name2] = e2;
|
|
22
|
+
} else {
|
|
23
|
+
this.children.push(e2);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
if (label) {
|
|
28
|
+
e.label = label;
|
|
29
|
+
}
|
|
30
|
+
if (datatype) {
|
|
31
|
+
e.datatype = datatype;
|
|
32
|
+
}
|
|
33
|
+
if (children) {
|
|
34
|
+
e.children = children;
|
|
35
|
+
}
|
|
36
|
+
e.meta = meta || {};
|
|
37
|
+
return e;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/meta/helper.js
|
|
41
|
+
import axios from "axios";
|
|
40
42
|
|
|
41
43
|
// src/Utils.js
|
|
42
44
|
import { composeNextState } from "@openfn/language-common";
|
|
@@ -82,9 +84,9 @@ function handleResponse(result, state, callback) {
|
|
|
82
84
|
function prettyJson(data) {
|
|
83
85
|
return JSON.stringify(data, null, 2);
|
|
84
86
|
}
|
|
85
|
-
var
|
|
87
|
+
var isArray2 = (variable) => !!variable && variable.constructor === Array;
|
|
86
88
|
function nestArray(data, key) {
|
|
87
|
-
return
|
|
89
|
+
return isArray2(data) ? { [key]: data } : data;
|
|
88
90
|
}
|
|
89
91
|
function generateUrl(configuration, options, resourceType, path = null) {
|
|
90
92
|
let { hostUrl, apiVersion } = configuration;
|
|
@@ -99,8 +101,132 @@ function generateUrl(configuration, options, resourceType, path = null) {
|
|
|
99
101
|
return url;
|
|
100
102
|
}
|
|
101
103
|
|
|
104
|
+
// src/meta/helper.js
|
|
105
|
+
var createHelper = (configuration = {}) => {
|
|
106
|
+
const { username, password } = configuration;
|
|
107
|
+
const get2 = (url) => axios({
|
|
108
|
+
url,
|
|
109
|
+
headers: { "Content-Type": "application/json" },
|
|
110
|
+
responseType: "json",
|
|
111
|
+
auth: { username, password },
|
|
112
|
+
params: { paging: false }
|
|
113
|
+
});
|
|
114
|
+
const getResourceTypes = async () => {
|
|
115
|
+
return [
|
|
116
|
+
"dataElementGroups",
|
|
117
|
+
"dataElementGroupSets",
|
|
118
|
+
"dataElements",
|
|
119
|
+
"dataSetNotificationTemplates",
|
|
120
|
+
"dataSets",
|
|
121
|
+
"dataValueSets",
|
|
122
|
+
"enrollments",
|
|
123
|
+
"events",
|
|
124
|
+
"organisationUnitProfile",
|
|
125
|
+
"organisationUnits",
|
|
126
|
+
"programs",
|
|
127
|
+
"trackedEntityAttributes",
|
|
128
|
+
"trackedEntityInstances"
|
|
129
|
+
];
|
|
130
|
+
};
|
|
131
|
+
const getOrgUnits = async () => {
|
|
132
|
+
const url = generateUrl(configuration, {}, "organisationUnits");
|
|
133
|
+
const response = await get2(url);
|
|
134
|
+
return response.data;
|
|
135
|
+
};
|
|
136
|
+
const getPrograms = () => {
|
|
137
|
+
};
|
|
138
|
+
const getTrackedEntityTypes = async () => {
|
|
139
|
+
const url = generateUrl(configuration, {}, "trackedEntityTypes");
|
|
140
|
+
const response = await get2(url);
|
|
141
|
+
return response.data;
|
|
142
|
+
};
|
|
143
|
+
const getAttributes = async () => {
|
|
144
|
+
const url = generateUrl(configuration, {}, "attributes");
|
|
145
|
+
const response = await get2(url);
|
|
146
|
+
return response.data;
|
|
147
|
+
};
|
|
148
|
+
return {
|
|
149
|
+
getResourceTypes,
|
|
150
|
+
getOrgUnits,
|
|
151
|
+
getTrackedEntityTypes,
|
|
152
|
+
getAttributes
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
var helper_default = createHelper;
|
|
156
|
+
|
|
157
|
+
// src/meta/metadata.js
|
|
158
|
+
var metadata = async (configuration = {}, helper) => {
|
|
159
|
+
var _a, _b;
|
|
160
|
+
if (!helper) {
|
|
161
|
+
helper = helper_default(configuration);
|
|
162
|
+
}
|
|
163
|
+
const children = {};
|
|
164
|
+
const units = await helper.getOrgUnits();
|
|
165
|
+
children.orgUnits = units.organisationUnits.map(
|
|
166
|
+
(unit) => createEntity(unit.id, "orgUnit", {
|
|
167
|
+
datatype: "string",
|
|
168
|
+
label: unit.displayName
|
|
169
|
+
})
|
|
170
|
+
);
|
|
171
|
+
children.resourceTypes = await helper.getResourceTypes();
|
|
172
|
+
const types = await helper.getTrackedEntityTypes() ?? [];
|
|
173
|
+
children.trackedEntityTypes = ((_a = types.trackedEntityTypes) == null ? void 0 : _a.map(
|
|
174
|
+
(type) => createEntity(type.id, "trackedEntityType", {
|
|
175
|
+
datatype: "string",
|
|
176
|
+
label: type.displayName
|
|
177
|
+
})
|
|
178
|
+
)) ?? [];
|
|
179
|
+
const attributes = await helper.getAttributes() ?? [];
|
|
180
|
+
children.attributes = ((_b = attributes.attributes) == null ? void 0 : _b.map(
|
|
181
|
+
(attr2) => createEntity(attr2.id, "attribute", {
|
|
182
|
+
datatype: "string",
|
|
183
|
+
label: attr2.displayName
|
|
184
|
+
})
|
|
185
|
+
)) ?? [];
|
|
186
|
+
return {
|
|
187
|
+
type: "model",
|
|
188
|
+
name: "dhis2",
|
|
189
|
+
children
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
var metadata_default = metadata;
|
|
193
|
+
|
|
194
|
+
// src/Adaptor.js
|
|
195
|
+
var Adaptor_exports = {};
|
|
196
|
+
__export(Adaptor_exports, {
|
|
197
|
+
alterState: () => alterState,
|
|
198
|
+
attr: () => attr,
|
|
199
|
+
create: () => create,
|
|
200
|
+
dataPath: () => dataPath,
|
|
201
|
+
dataValue: () => dataValue,
|
|
202
|
+
dateFns: () => dateFns,
|
|
203
|
+
destroy: () => destroy,
|
|
204
|
+
discover: () => discover,
|
|
205
|
+
dv: () => dv,
|
|
206
|
+
each: () => each,
|
|
207
|
+
execute: () => execute,
|
|
208
|
+
field: () => field,
|
|
209
|
+
fields: () => fields,
|
|
210
|
+
findAttributeValue: () => findAttributeValue,
|
|
211
|
+
fn: () => fn,
|
|
212
|
+
get: () => get,
|
|
213
|
+
http: () => http,
|
|
214
|
+
lastReferenceValue: () => lastReferenceValue,
|
|
215
|
+
merge: () => merge,
|
|
216
|
+
patch: () => patch,
|
|
217
|
+
sourceValue: () => sourceValue,
|
|
218
|
+
update: () => update,
|
|
219
|
+
upsert: () => upsert
|
|
220
|
+
});
|
|
221
|
+
import axios3 from "axios";
|
|
222
|
+
import _ from "lodash";
|
|
223
|
+
import {
|
|
224
|
+
execute as commonExecute,
|
|
225
|
+
expandReferences
|
|
226
|
+
} from "@openfn/language-common";
|
|
227
|
+
|
|
102
228
|
// src/Client.js
|
|
103
|
-
import
|
|
229
|
+
import axios2 from "axios";
|
|
104
230
|
import Qs from "qs";
|
|
105
231
|
function request({ username, password }, axiosRequest) {
|
|
106
232
|
const { method, url, params } = axiosRequest;
|
|
@@ -110,7 +236,7 @@ function request({ username, password }, axiosRequest) {
|
|
|
110
236
|
const safeRedirect = ["get", "head", "options", "trace"].includes(
|
|
111
237
|
method.toLowerCase()
|
|
112
238
|
);
|
|
113
|
-
return
|
|
239
|
+
return axios2({
|
|
114
240
|
headers: { "Content-Type": "application/json" },
|
|
115
241
|
responseType: "json",
|
|
116
242
|
maxRedirects: safeRedirect ? 5 : 0,
|
|
@@ -159,7 +285,7 @@ function configMigrationHelper(state) {
|
|
|
159
285
|
}
|
|
160
286
|
return state;
|
|
161
287
|
}
|
|
162
|
-
|
|
288
|
+
axios3.interceptors.response.use(
|
|
163
289
|
function(response) {
|
|
164
290
|
var _a, _b;
|
|
165
291
|
const contentType = (_a = response.headers["content-type"]) == null ? void 0 : _a.split(";")[0];
|
|
@@ -296,7 +422,7 @@ function discover(httpMethod, endpoint) {
|
|
|
296
422
|
console.log(
|
|
297
423
|
`Discovering query/import parameters for ${httpMethod} on ${endpoint}`
|
|
298
424
|
);
|
|
299
|
-
return
|
|
425
|
+
return axios3.get(
|
|
300
426
|
"https://dhis2.github.io/dhis2-api-specification/spec/metadata_openapi.json",
|
|
301
427
|
{
|
|
302
428
|
transformResponse: [
|
|
@@ -435,6 +561,7 @@ export {
|
|
|
435
561
|
http,
|
|
436
562
|
lastReferenceValue,
|
|
437
563
|
merge,
|
|
564
|
+
metadata_default as metadata,
|
|
438
565
|
patch,
|
|
439
566
|
sourceValue,
|
|
440
567
|
update,
|