@openfn/language-dhis2 3.2.6 → 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/ast.json CHANGED
@@ -30,12 +30,16 @@
30
30
  },
31
31
  "name": "resourceType"
32
32
  },
33
+ {
34
+ "title": "magic",
35
+ "description": "resourceType $.children.resourceTypes[*]"
36
+ },
33
37
  {
34
38
  "title": "param",
35
- "description": "Data that will be used to create a given instance of resource. To create a single instance of a resource, `data` must be a javascript object, and to create multiple instances of a resources, `data` must be an array of javascript objects.",
39
+ "description": "Object which defines data that will be used to create a given instance of resource. To create a single instance of a resource, `data` must be a javascript object, and to create multiple instances of a resources, `data` must be an array of javascript objects.",
36
40
  "type": {
37
41
  "type": "NameExpression",
38
- "name": "Object"
42
+ "name": "Dhis2Data"
39
43
  },
40
44
  "name": "data"
41
45
  },
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/Adaptor.js
56
- var Adaptor_exports = {};
57
- __export(Adaptor_exports, {
58
- alterState: () => import_language_common3.alterState,
59
- attr: () => attr,
60
- create: () => create,
61
- dataPath: () => import_language_common3.dataPath,
62
- dataValue: () => import_language_common3.dataValue,
63
- dateFns: () => import_language_common3.dateFns,
64
- destroy: () => destroy,
65
- discover: () => discover,
66
- dv: () => dv,
67
- each: () => import_language_common3.each,
68
- execute: () => execute,
69
- field: () => import_language_common3.field,
70
- fields: () => import_language_common3.fields,
71
- findAttributeValue: () => findAttributeValue,
72
- fn: () => import_language_common3.fn,
73
- get: () => get,
74
- http: () => import_language_common3.http,
75
- lastReferenceValue: () => import_language_common3.lastReferenceValue,
76
- merge: () => import_language_common3.merge,
77
- patch: () => patch,
78
- sourceValue: () => import_language_common3.sourceValue,
79
- update: () => update,
80
- upsert: () => upsert
81
- });
82
- var import_axios2 = __toESM(require("axios"), 1);
83
- var import_lodash = __toESM(require("lodash"), 1);
84
- var import_language_common2 = require("@openfn/language-common");
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 isArray = (variable) => !!variable && variable.constructor === Array;
140
+ var isArray2 = (variable) => !!variable && variable.constructor === Array;
131
141
  function nestArray(data, key) {
132
- return isArray(data) ? { [key]: data } : data;
142
+ return isArray2(data) ? { [key]: data } : data;
133
143
  }
134
- function generateUrl(configuration, options, resourceType, path = null) {
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 (path)
143
- return `${url}/${path}`;
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 import_axios = __toESM(require("axios"), 1);
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, import_axios.default)({
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
- import_axios2.default.interceptors.response.use(
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, path, data, options = {}, callback = false) {
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
- path = (0, import_language_common2.expandReferences)(path)(state);
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, path),
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 ${path}`);
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 path = resources[0][selectId(resourceType)];
318
- return update(resourceType, path, data, options)(state);
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 import_axios2.default.get(
462
+ return import_axios3.default.get(
332
463
  "https://dhis2.github.io/dhis2-api-specification/spec/metadata_openapi.json",
333
464
  {
334
465
  transformResponse: [
@@ -344,9 +475,7 @@ function discover(httpMethod, endpoint) {
344
475
  let param = tempData.components.parameters[paramRef];
345
476
  if (param.schema["$ref"]) {
346
477
  let schemaRefIndex = param.schema["$ref"].lastIndexOf("/") + 1;
347
- let schemaRef = param.schema["$ref"].slice(
348
- schemaRefIndex
349
- );
478
+ let schemaRef = param.schema["$ref"].slice(schemaRefIndex);
350
479
  param.schema = tempData.components.schemas[schemaRef];
351
480
  }
352
481
  param.schema = JSON.stringify(param.schema);
@@ -391,44 +520,44 @@ ${prettyJson(
391
520
  });
392
521
  };
393
522
  }
394
- function patch(resourceType, path, data, options = {}, callback = false) {
523
+ function patch(resourceType, path2, data, options = {}, callback = false) {
395
524
  return (state) => {
396
525
  console.log("Preparing patch operation...");
397
526
  resourceType = (0, import_language_common2.expandReferences)(resourceType)(state);
398
- path = (0, import_language_common2.expandReferences)(path)(state);
527
+ path2 = (0, import_language_common2.expandReferences)(path2)(state);
399
528
  data = (0, import_language_common2.expandReferences)(data)(state);
400
529
  options = (0, import_language_common2.expandReferences)(options)(state);
401
530
  const { params, requestConfig } = options;
402
531
  const { configuration } = state;
403
532
  return request(configuration, {
404
533
  method: "patch",
405
- url: generateUrl(configuration, options, resourceType, path),
534
+ url: generateUrl(configuration, options, resourceType, path2),
406
535
  params,
407
536
  data,
408
537
  ...requestConfig
409
538
  }).then((result) => {
410
- Log.success(`Patched ${resourceType} at ${path}`);
539
+ Log.success(`Patched ${resourceType} at ${path2}`);
411
540
  return handleResponse(result, state, callback);
412
541
  });
413
542
  };
414
543
  }
415
- function destroy(resourceType, path, data = null, options = {}, callback = false) {
544
+ function destroy(resourceType, path2, data = null, options = {}, callback = false) {
416
545
  return (state) => {
417
546
  console.log("Preparing destroy operation...");
418
547
  resourceType = (0, import_language_common2.expandReferences)(resourceType)(state);
419
- path = (0, import_language_common2.expandReferences)(path)(state);
548
+ path2 = (0, import_language_common2.expandReferences)(path2)(state);
420
549
  data = (0, import_language_common2.expandReferences)(data)(state);
421
550
  options = (0, import_language_common2.expandReferences)(options)(state);
422
551
  const { params, requestConfig } = options;
423
552
  const { configuration } = state;
424
553
  return request({
425
554
  method: "delete",
426
- url: generateUrl(configuration, options, resourceType, path),
555
+ url: generateUrl(configuration, options, resourceType, path2),
427
556
  params,
428
557
  data,
429
558
  ...requestConfig
430
559
  }).then((result) => {
431
- Log.success(`Deleted ${resourceType} at ${path}`);
560
+ Log.success(`Deleted ${resourceType} at ${path2}`);
432
561
  return handleResponse(result, state, callback);
433
562
  });
434
563
  };
@@ -469,6 +598,7 @@ var src_default = Adaptor_exports;
469
598
  http,
470
599
  lastReferenceValue,
471
600
  merge,
601
+ metadata,
472
602
  patch,
473
603
  sourceValue,
474
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/Adaptor.js
8
- var Adaptor_exports = {};
9
- __export(Adaptor_exports, {
10
- alterState: () => alterState,
11
- attr: () => attr,
12
- create: () => create,
13
- dataPath: () => dataPath,
14
- dataValue: () => dataValue,
15
- dateFns: () => dateFns,
16
- destroy: () => destroy,
17
- discover: () => discover,
18
- dv: () => dv,
19
- each: () => each,
20
- execute: () => execute,
21
- field: () => field,
22
- fields: () => fields,
23
- findAttributeValue: () => findAttributeValue,
24
- fn: () => fn,
25
- get: () => get,
26
- http: () => http,
27
- lastReferenceValue: () => lastReferenceValue,
28
- merge: () => merge,
29
- patch: () => patch,
30
- sourceValue: () => sourceValue,
31
- update: () => update,
32
- upsert: () => upsert
33
- });
34
- import axios2 from "axios";
35
- import _ from "lodash";
36
- import {
37
- execute as commonExecute,
38
- expandReferences
39
- } from "@openfn/language-common";
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 isArray = (variable) => !!variable && variable.constructor === Array;
87
+ var isArray2 = (variable) => !!variable && variable.constructor === Array;
86
88
  function nestArray(data, key) {
87
- return isArray(data) ? { [key]: data } : data;
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 axios from "axios";
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 axios({
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
- axios2.interceptors.response.use(
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 axios2.get(
425
+ return axios3.get(
300
426
  "https://dhis2.github.io/dhis2-api-specification/spec/metadata_openapi.json",
301
427
  {
302
428
  transformResponse: [
@@ -312,9 +438,7 @@ function discover(httpMethod, endpoint) {
312
438
  let param = tempData.components.parameters[paramRef];
313
439
  if (param.schema["$ref"]) {
314
440
  let schemaRefIndex = param.schema["$ref"].lastIndexOf("/") + 1;
315
- let schemaRef = param.schema["$ref"].slice(
316
- schemaRefIndex
317
- );
441
+ let schemaRef = param.schema["$ref"].slice(schemaRefIndex);
318
442
  param.schema = tempData.components.schemas[schemaRef];
319
443
  }
320
444
  param.schema = JSON.stringify(param.schema);
@@ -437,6 +561,7 @@ export {
437
561
  http,
438
562
  lastReferenceValue,
439
563
  merge,
564
+ metadata_default as metadata,
440
565
  patch,
441
566
  sourceValue,
442
567
  update,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-dhis2",
3
- "version": "3.2.6",
3
+ "version": "3.2.8",
4
4
  "description": "DHIS2 Language Pack for OpenFn",
5
5
  "homepage": "https://docs.openfn.org",
6
6
  "repository": {
@@ -28,16 +28,19 @@
28
28
  "@openfn/language-common": "^1.7.5",
29
29
  "axios": "^0.24.0",
30
30
  "lodash": "^4.17.19",
31
- "qs": "^6.10.3"
31
+ "qs": "^6.11.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@openfn/buildtools": "^1.0.2",
35
+ "@openfn/metadata": "^1.0.0",
36
+ "@openfn/parse-jsdoc": "^1.0.0",
35
37
  "@openfn/simple-ast": "0.4.1",
36
38
  "assertion-error": "2.0.0",
37
39
  "chai": "4.3.6",
38
40
  "chai-http": "4.3.0",
39
41
  "deep-eql": "4.1.1",
40
42
  "esno": "^0.16.3",
43
+ "jsonpath": "^1.1.1",
41
44
  "mocha": "7.2.0",
42
45
  "nock": "13.2.9",
43
46
  "rimraf": "3.0.2"
@@ -47,9 +50,9 @@
47
50
  "scripts": {
48
51
  "build": "pnpm clean && build-adaptor dhis2",
49
52
  "clean": "rimraf dist types docs",
50
- "integration-test": "mocha --experimental-specifier-resolution=node --no-warnings test/integration.js",
53
+ "integration-test": "mocha --experimental-specifier-resolution=node --no-warnings test/integration.cjs",
51
54
  "pack": "pnpm pack --pack-destination ../../dist",
52
- "test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings test/index.js",
53
- "test": "mocha --experimental-specifier-resolution=node --no-warnings test/index.js"
55
+ "test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings --exclude test/integration.cjs --recursive --timeout 10000",
56
+ "test": "mocha --experimental-specifier-resolution=node --no-warnings --exclude test/integration.cjs --recursive --timeout 10000"
54
57
  }
55
58
  }
@@ -16,7 +16,8 @@ export function execute(...operations: Operations): Operation;
16
16
  * @public
17
17
  * @function
18
18
  * @param {string} resourceType - Type of resource to create. E.g. `trackedEntityInstances`, `programs`, `events`, ...
19
- * @param {Object} data - Data that will be used to create a given instance of resource. To create a single instance of a resource, `data` must be a javascript object, and to create multiple instances of a resources, `data` must be an array of javascript objects.
19
+ * @magic resourceType $.children.resourceTypes[*]
20
+ * @param {Dhis2Data} data - Object which defines data that will be used to create a given instance of resource. To create a single instance of a resource, `data` must be a javascript object, and to create multiple instances of a resources, `data` must be an array of javascript objects.
20
21
  * @param {Object} [options] - Optional `options` to define URL parameters via params (E.g. `filter`, `dimension` and other import parameters), request config (E.g. `auth`) and the DHIS2 apiVersion.
21
22
  * @param {function} [callback] - Optional callback to handle the response
22
23
  * @returns {Operation}
@@ -111,7 +112,7 @@ export function execute(...operations: Operations): Operation;
111
112
  * incidentDate: '2013-09-17',
112
113
  * });
113
114
  */
114
- export function create(resourceType: string, data: any, options?: any, callback?: Function): Operation;
115
+ export function create(resourceType: string, data: Dhis2Data, options?: any, callback?: Function): Operation;
115
116
  /**
116
117
  * Update data. A generic helper function to update a resource object of any type.
117
118
  * Updating an object requires to send `all required fields` or the `full body`
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import './types';
2
+ import * as Adaptor from './Adaptor';
1
3
  export default Adaptor;
2
- export * from "./Adaptor";
3
- import * as Adaptor from "./Adaptor";
4
+ export * from './Adaptor';
@@ -0,0 +1,28 @@
1
+ export declare type Dhis2Attribute = {
2
+ /**
3
+ * The attribute id
4
+ * @magic $.children.attributes[*]
5
+ */
6
+ attribute: string;
7
+ value: any;
8
+ };
9
+ export declare type Dhis2Data = {
10
+ /**
11
+ * The id of an organisation unit
12
+ * @magic $.children.orgUnits[*]
13
+ */
14
+ orgUnit?: string;
15
+ /**
16
+ * Tracked instance id
17
+ */
18
+ trackedEntityInstance?: string;
19
+ /**
20
+ * Tracked instance type
21
+ * @magic $.children.trackedEntityTypes[*]
22
+ */
23
+ trackedEntityType?: string;
24
+ /**
25
+ * List of attributes
26
+ */
27
+ attributes?: Dhis2Attribute[];
28
+ };