@openfn/language-dhis2 3.0.0-3 → 3.0.0-4

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
@@ -41,7 +41,7 @@
41
41
  },
42
42
  {
43
43
  "title": "param",
44
- "description": "Optional `options` to define URL parameters (E.g. `filters`, `dimensions` and `import parameters`), axios configurations (E.g. `auth`) and DHIS 2 api version to use.",
44
+ "description": "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.",
45
45
  "type": {
46
46
  "type": "OptionalType",
47
47
  "expression": {
@@ -181,7 +181,7 @@
181
181
  },
182
182
  {
183
183
  "title": "param",
184
- "description": "Optional `options` to define URL parameters (E.g. `filters`, `dimensions` and `import parameters`), axios configurations (E.g. `auth`) and DHIS 2 api version to use.",
184
+ "description": "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.",
185
185
  "type": {
186
186
  "type": "OptionalType",
187
187
  "expression": {
@@ -274,7 +274,7 @@
274
274
  "name": "get",
275
275
  "params": [
276
276
  "resourceType",
277
- "filters",
277
+ "query",
278
278
  "options",
279
279
  "callback"
280
280
  ],
@@ -302,16 +302,16 @@
302
302
  },
303
303
  {
304
304
  "title": "param",
305
- "description": "Filters to limit what resources are retrieved.",
305
+ "description": "A query object that will limit what resources are retrieved when converted into request params.",
306
306
  "type": {
307
307
  "type": "NameExpression",
308
308
  "name": "Object"
309
309
  },
310
- "name": "filters"
310
+ "name": "query"
311
311
  },
312
312
  {
313
313
  "title": "param",
314
- "description": "Optional `options` to define URL parameters beyond filters, request configuration (e.g. `auth`) and DHIS2 api version to use.",
314
+ "description": "Optional `options` to define URL parameters via params beyond filters, request configuration (e.g. `auth`) and DHIS2 api version to use.",
315
315
  "type": {
316
316
  "type": "OptionalType",
317
317
  "expression": {
@@ -353,7 +353,7 @@
353
353
  },
354
354
  {
355
355
  "title": "example",
356
- "description": "get('trackedEntityInstances', {\n ou: 'DiszpKrYNg8',\n filters: ['flGbXLXCrEo:Eq:124'],\n});",
356
+ "description": "get('trackedEntityInstances', {\n ou: 'DiszpKrYNg8',\n filter: ['flGbXLXCrEo:Eq:124', 'w75KJ2mc4zz:Eq:John'],\n});",
357
357
  "caption": "a single tracked entity instance by a unique external ID"
358
358
  }
359
359
  ]
@@ -420,7 +420,6 @@
420
420
  "resourceType",
421
421
  "path",
422
422
  "data",
423
- "params",
424
423
  "options",
425
424
  "callback"
426
425
  ],
@@ -466,7 +465,7 @@
466
465
  },
467
466
  {
468
467
  "title": "param",
469
- "description": "Optional `update` parameters e.g. `{preheatCache: true, strategy: 'UPDATE', mergeMode: 'REPLACE'}`. Run `discover` or see {@link https://docs.dhis2.org/2.34/en/dhis2_developer_manual/web-api.html#create-update-parameters DHIS2 documentation}",
468
+ "description": "Optional configuration, including params for the update ({preheatCache: true, strategy: 'UPDATE', mergeMode: 'REPLACE'}). Defaults to `{operationName: 'patch', apiVersion: state.configuration.apiVersion, responseType: 'json'}`",
470
469
  "type": {
471
470
  "type": "OptionalType",
472
471
  "expression": {
@@ -474,43 +473,6 @@
474
473
  "name": "Object"
475
474
  }
476
475
  },
477
- "name": "params"
478
- },
479
- {
480
- "title": "param",
481
- "description": "Optional options for update method. Defaults to `{operationName: 'patch', apiVersion: state.configuration.apiVersion, responseType: 'json'}`",
482
- "type": {
483
- "type": "OptionalType",
484
- "expression": {
485
- "type": "RecordType",
486
- "fields": [
487
- {
488
- "type": "FieldType",
489
- "key": "apiVersion",
490
- "value": {
491
- "type": "NameExpression",
492
- "name": "number"
493
- }
494
- },
495
- {
496
- "type": "FieldType",
497
- "key": "operationName",
498
- "value": {
499
- "type": "NameExpression",
500
- "name": "string"
501
- }
502
- },
503
- {
504
- "type": "FieldType",
505
- "key": "responseType",
506
- "value": {
507
- "type": "NameExpression",
508
- "name": "string"
509
- }
510
- }
511
- ]
512
- }
513
- },
514
476
  "name": "options"
515
477
  },
516
478
  {
@@ -548,7 +510,6 @@
548
510
  "resourceType",
549
511
  "path",
550
512
  "data",
551
- "params",
552
513
  "options",
553
514
  "callback"
554
515
  ],
@@ -597,19 +558,7 @@
597
558
  },
598
559
  {
599
560
  "title": "param",
600
- "description": "Optional `update` parameters e.g. `{preheatCache: true, strategy: 'UPDATE', mergeMode: 'REPLACE'}`. Run `discover` or see {@link https://docs.dhis2.org/2.34/en/dhis2_developer_manual/web-api.html#create-update-parameters DHIS2 documentation}",
601
- "type": {
602
- "type": "OptionalType",
603
- "expression": {
604
- "type": "NameExpression",
605
- "name": "Object"
606
- }
607
- },
608
- "name": "params"
609
- },
610
- {
611
- "title": "param",
612
- "description": "Optional `options` for `del` operation. Defaults to `{operationName: 'delete', apiVersion: state.configuration.apiVersion, responseType: 'json'}`",
561
+ "description": "Optional `options` for `del` operation including params e.g. `{preheatCache: true, strategy: 'UPDATE', mergeMode: 'REPLACE'}`. Run `discover` or see {@link https://docs.dhis2.org/2.34/en/dhis2_developer_manual/web-api.html#create-update-parameters DHIS2 documentation}. Defaults to `{operationName: 'delete', apiVersion: state.configuration.apiVersion, responseType: 'json'}`",
613
562
  "type": {
614
563
  "type": "OptionalType",
615
564
  "expression": {
package/lib/Adaptor.js CHANGED
@@ -82,10 +82,10 @@ Object.defineProperty(exports, "http", {
82
82
 
83
83
  var _axios = _interopRequireDefault(require("axios"));
84
84
 
85
- var _languageCommon = require("@openfn/language-common");
86
-
87
85
  var _lodash = require("lodash");
88
86
 
87
+ var _languageCommon = require("@openfn/language-common");
88
+
89
89
  var _Utils = require("./Utils");
90
90
 
91
91
  var _Client = require("./Client");
@@ -199,7 +199,7 @@ _axios.default.interceptors.response.use(function (response) {
199
199
  * @function
200
200
  * @param {string} resourceType - Type of resource to create. E.g. `trackedEntityInstances`, `programs`, `events`, ...
201
201
  * @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.
202
- * @param {Object} [options] - Optional `options` to define URL parameters (E.g. `filters`, `dimensions` and `import parameters`), axios configurations (E.g. `auth`) and DHIS 2 api version to use.
202
+ * @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.
203
203
  * @param {function} [callback] - Optional callback to handle the response
204
204
  * @returns {Operation}
205
205
  * @example <caption>a program</caption>
@@ -295,7 +295,7 @@ _axios.default.interceptors.response.use(function (response) {
295
295
  */
296
296
 
297
297
 
298
- function create(resourceType, data, options, callback) {
298
+ function create(resourceType, data, options = {}, callback = false) {
299
299
  return state => {
300
300
  console.log(`Preparing create operation...`);
301
301
  resourceType = (0, _languageCommon.expandReferences)(resourceType)(state);
@@ -304,14 +304,14 @@ function create(resourceType, data, options, callback) {
304
304
  const {
305
305
  params,
306
306
  requestConfig
307
- } = options || {};
307
+ } = options;
308
308
  const {
309
309
  configuration
310
310
  } = state;
311
311
  return (0, _Client.request)(configuration, {
312
312
  method: 'post',
313
313
  url: (0, _Utils.generateUrl)(configuration, options, resourceType),
314
- params: params && (0, _Utils.buildUrlParams)(params),
314
+ params,
315
315
  data: (0, _Utils.nestArray)(data, resourceType),
316
316
  ...requestConfig
317
317
  }).then(result => {
@@ -329,7 +329,7 @@ function create(resourceType, data, options, callback) {
329
329
  * @param {string} resourceType - The type of resource to be updated. E.g. `dataElements`, `organisationUnits`, etc.
330
330
  * @param {string} path - The `id` or `path` to the `object` to be updated. E.g. `FTRrcoaog83` or `FTRrcoaog83/{collection-name}/{object-id}`
331
331
  * @param {Object} data - Data to update. It requires to send `all required fields` or the `full body`. If you want `partial updates`, use `patch` operation.
332
- * @param {Object} [options] - Optional `options` to define URL parameters (E.g. `filters`, `dimensions` and `import parameters`), axios configurations (E.g. `auth`) and DHIS 2 api version to use.
332
+ * @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.
333
333
  * @param {function} [callback] - Optional callback to handle the response
334
334
  * @returns {Operation}
335
335
  * @example <caption>a program</caption>
@@ -456,7 +456,7 @@ function create(resourceType, data, options, callback) {
456
456
  */
457
457
 
458
458
 
459
- function update(resourceType, path, data, options, callback) {
459
+ function update(resourceType, path, data, options = {}, callback = false) {
460
460
  return state => {
461
461
  console.log(`Preparing update operation...`);
462
462
  resourceType = (0, _languageCommon.expandReferences)(resourceType)(state);
@@ -466,14 +466,14 @@ function update(resourceType, path, data, options, callback) {
466
466
  const {
467
467
  params,
468
468
  requestConfig
469
- } = options || {};
469
+ } = options;
470
470
  const {
471
471
  configuration
472
472
  } = state;
473
473
  return (0, _Client.request)(configuration, {
474
474
  method: 'put',
475
- url: `${(0, _Utils.generateUrl)(configuration, options, resourceType)}/${path}`,
476
- params: params && (0, _Utils.buildUrlParams)(params),
475
+ url: (0, _Utils.generateUrl)(configuration, options, resourceType, path),
476
+ params,
477
477
  data,
478
478
  ...requestConfig
479
479
  }).then(result => {
@@ -489,8 +489,8 @@ function update(resourceType, path, data, options, callback) {
489
489
  * @public
490
490
  * @function
491
491
  * @param {string} resourceType - The type of resource to get(use its `plural` name). E.g. `dataElements`, `trackedEntityInstances`,`organisationUnits`, etc.
492
- * @param {Object} filters - Filters to limit what resources are retrieved.
493
- * @param {Object} [options] - Optional `options` to define URL parameters beyond filters, request configuration (e.g. `auth`) and DHIS2 api version to use.
492
+ * @param {Object} query - A query object that will limit what resources are retrieved when converted into request params.
493
+ * @param {Object} [options] - Optional `options` to define URL parameters via params beyond filters, request configuration (e.g. `auth`) and DHIS2 api version to use.
494
494
  * @param {function} [callback] - Optional callback to handle the response
495
495
  * @returns {Operation} state
496
496
  * @example <caption>all data values for the 'pBOMPrpg1QX' dataset</caption>
@@ -505,30 +505,30 @@ function update(resourceType, path, data, options, callback) {
505
505
  * @example <caption>a single tracked entity instance by a unique external ID</caption>
506
506
  * get('trackedEntityInstances', {
507
507
  * ou: 'DiszpKrYNg8',
508
- * filters: ['flGbXLXCrEo:Eq:124'],
508
+ * filter: ['flGbXLXCrEo:Eq:124', 'w75KJ2mc4zz:Eq:John'],
509
509
  * });
510
510
  */
511
511
 
512
512
 
513
- function get(resourceType, filters, options, callback) {
513
+ function get(resourceType, query, options = {}, callback = false) {
514
514
  return state => {
515
- console.log(`Preparing get operation...`);
515
+ console.log('Preparing get operation...');
516
516
  resourceType = (0, _languageCommon.expandReferences)(resourceType)(state);
517
- filters = (0, _languageCommon.expandReferences)(filters)(state);
517
+ query = (0, _languageCommon.expandReferences)(query)(state);
518
518
  options = (0, _languageCommon.expandReferences)(options)(state);
519
519
  const {
520
520
  params,
521
521
  requestConfig
522
- } = options || {};
522
+ } = options;
523
523
  const {
524
524
  configuration
525
525
  } = state;
526
526
  return (0, _Client.request)(configuration, {
527
527
  method: 'get',
528
528
  url: (0, _Utils.generateUrl)(configuration, options, resourceType),
529
- params: (0, _Utils.buildUrlParams)({ ...filters,
529
+ params: { ...query,
530
530
  ...params
531
- }),
531
+ },
532
532
  responseType: 'json',
533
533
  ...requestConfig
534
534
  }).then(result => {
@@ -560,7 +560,7 @@ function get(resourceType, filters, options, callback) {
560
560
  // * { ou: 'TSyzvBiovKh' }
561
561
  // * );
562
562
  // */
563
- // export function upsert(resourceType, data, options, callback) {
563
+ // export function upsert(resourceType, data, options = {}, callback = false) {
564
564
  // return state => {
565
565
  // console.log(`Preparing upsert via 'get' then 'create' OR 'update'...`);
566
566
  // return get(
@@ -652,8 +652,7 @@ function discover(httpMethod, endpoint) {
652
652
  * @param {string} resourceType - The type of resource to be updated. E.g. `dataElements`, `organisationUnits`, etc.
653
653
  * @param {string} path - The `id` or `path` to the `object` to be updated. E.g. `FTRrcoaog83` or `FTRrcoaog83/{collection-name}/{object-id}`
654
654
  * @param {Object} data - Data to update. Include only the fields you want to update. E.g. `{name: "New Name"}`
655
- * @param {Object} [params] - Optional `update` parameters e.g. `{preheatCache: true, strategy: 'UPDATE', mergeMode: 'REPLACE'}`. Run `discover` or see {@link https://docs.dhis2.org/2.34/en/dhis2_developer_manual/web-api.html#create-update-parameters DHIS2 documentation}
656
- * @param {{apiVersion: number,operationName: string,responseType: string}} [options] - Optional options for update method. Defaults to `{operationName: 'patch', apiVersion: state.configuration.apiVersion, responseType: 'json'}`
655
+ * @param {Object} [options] - Optional configuration, including params for the update ({preheatCache: true, strategy: 'UPDATE', mergeMode: 'REPLACE'}). Defaults to `{operationName: 'patch', apiVersion: state.configuration.apiVersion, responseType: 'json'}`
657
656
  * @param {function} [callback] - Optional callback to handle the response
658
657
  * @returns {Operation}
659
658
  * @example <caption>a dataElement</caption>
@@ -663,52 +662,30 @@ function discover(httpMethod, endpoint) {
663
662
  // I need to investigate on this. But I think DHIS 2 forces to send all properties back when we do an update. If that's confirmed then this may be needed.
664
663
 
665
664
 
666
- function patch(resourceType, path, data, params, options, callback) {
665
+ function patch(resourceType, path, data, options = {}, callback = false) {
667
666
  return state => {
668
- var _options$operationNam, _options, _options$responseType, _options2, _queryParams, _queryParams2, _options$apiVersion, _options3, _CONTENT_TYPES$respon;
669
-
667
+ console.log('Preparing patch operation...');
670
668
  resourceType = (0, _languageCommon.expandReferences)(resourceType)(state);
671
669
  path = (0, _languageCommon.expandReferences)(path)(state);
672
- const body = (0, _languageCommon.expandReferences)(data)(state);
673
- params = (0, _languageCommon.expandReferences)(params)(state);
670
+ data = (0, _languageCommon.expandReferences)(data)(state);
674
671
  options = (0, _languageCommon.expandReferences)(options)(state);
675
- const operationName = (_options$operationNam = (_options = options) === null || _options === void 0 ? void 0 : _options.operationName) !== null && _options$operationNam !== void 0 ? _options$operationNam : 'patch';
676
672
  const {
677
- username,
678
- password,
679
- hostUrl
680
- } = state.configuration;
681
- const responseType = (_options$responseType = (_options2 = options) === null || _options2 === void 0 ? void 0 : _options2.responseType) !== null && _options$responseType !== void 0 ? _options$responseType : 'json';
682
- let queryParams = params;
683
- const filters = (_queryParams = queryParams) === null || _queryParams === void 0 ? void 0 : _queryParams.filters;
684
- (_queryParams2 = queryParams) === null || _queryParams2 === void 0 ? true : delete _queryParams2.filters;
685
- queryParams = new URLSearchParams(queryParams);
686
- filters === null || filters === void 0 ? void 0 : filters.map(f => queryParams.append('filter', f));
687
- const apiVersion = (_options$apiVersion = (_options3 = options) === null || _options3 === void 0 ? void 0 : _options3.apiVersion) !== null && _options$apiVersion !== void 0 ? _options$apiVersion : state.configuration.apiVersion;
688
- const url = (0, _Utils.buildUrl)('/' + resourceType + '/' + path, hostUrl, apiVersion);
689
- const headers = {
690
- Accept: (_CONTENT_TYPES$respon = _Utils.CONTENT_TYPES[responseType]) !== null && _CONTENT_TYPES$respon !== void 0 ? _CONTENT_TYPES$respon : 'application/json'
691
- };
692
- return _axios.default.request({
693
- method: 'PATCH',
694
- url,
695
- auth: {
696
- username,
697
- password
698
- },
699
- params: queryParams,
700
- data: body,
701
- headers
673
+ params,
674
+ requestConfig
675
+ } = options;
676
+ const {
677
+ configuration
678
+ } = state;
679
+ return (0, _Client.request)(configuration, {
680
+ method: 'patch',
681
+ url: (0, _Utils.generateUrl)(configuration, options, resourceType, path),
682
+ params,
683
+ data,
684
+ ...requestConfig
702
685
  }).then(result => {
703
- let resultObject = {
704
- status: result.status,
705
- statusText: result.statusText
706
- };
686
+ _Utils.Log.success(`Patched ${resourceType} at ${path}`);
707
687
 
708
- _Utils.Log.success(`${operationName} succeeded. Updated ${resourceType}.\nSummary:\n${(0, _Utils.prettyJson)(resultObject)}`);
709
-
710
- if (callback) return callback((0, _languageCommon.composeNextState)(state, resultObject));
711
- return (0, _languageCommon.composeNextState)(state, resultObject);
688
+ return (0, _Utils.handleResponse)(result, state, callback);
712
689
  });
713
690
  };
714
691
  }
@@ -719,57 +696,38 @@ function patch(resourceType, path, data, params, options, callback) {
719
696
  * @param {string} resourceType - The type of resource to be deleted. E.g. `trackedEntityInstances`, `organisationUnits`, etc.
720
697
  * @param {string} path - Can be an `id` of an `object` or `path` to the `nested object` to `delete`.
721
698
  * @param {Object} [data] - Optional. This is useful when you want to remove multiple objects from a collection in one request. You can send `data` as, for example, `{"identifiableObjects": [{"id": "IDA"}, {"id": "IDB"}, {"id": "IDC"}]}`. See more {@link https://docs.dhis2.org/2.34/en/dhis2_developer_manual/web-api.html#deleting-objects on DHIS2 API docs}
722
- * @param {Object} [params] - Optional `update` parameters e.g. `{preheatCache: true, strategy: 'UPDATE', mergeMode: 'REPLACE'}`. Run `discover` or see {@link https://docs.dhis2.org/2.34/en/dhis2_developer_manual/web-api.html#create-update-parameters DHIS2 documentation}
723
- * @param {{apiVersion: number,operationName: string,resourceType: string}} [options] - Optional `options` for `del` operation. Defaults to `{operationName: 'delete', apiVersion: state.configuration.apiVersion, responseType: 'json'}`
699
+ * @param {{apiVersion: number,operationName: string,resourceType: string}} [options] - Optional `options` for `del` operation including params e.g. `{preheatCache: true, strategy: 'UPDATE', mergeMode: 'REPLACE'}`. Run `discover` or see {@link https://docs.dhis2.org/2.34/en/dhis2_developer_manual/web-api.html#create-update-parameters DHIS2 documentation}. Defaults to `{operationName: 'delete', apiVersion: state.configuration.apiVersion, responseType: 'json'}`
724
700
  * @param {function} [callback] - Optional callback to handle the response
725
701
  * @returns {Operation}
726
702
  * @example <caption>a tracked entity instance</caption>
727
703
  * destroy('trackedEntityInstances', 'LcRd6Nyaq7T');
728
704
  */
729
- // TODO: @Elias, can this be implemented using the same pattern as update but without data?
730
705
 
731
706
 
732
- function destroy(resourceType, path, data, params, options, callback) {
707
+ function destroy(resourceType, path, data = null, options = {}, callback = false) {
733
708
  return state => {
734
- var _options$operationNam2, _options4, _options$responseType2, _options5, _queryParams3, _queryParams4, _options$apiVersion2, _options6, _CONTENT_TYPES$respon2;
735
-
709
+ console.log('Preparing destroy operation...');
736
710
  resourceType = (0, _languageCommon.expandReferences)(resourceType)(state);
737
711
  path = (0, _languageCommon.expandReferences)(path)(state);
738
- const body = (0, _languageCommon.expandReferences)(data)(state);
739
- params = (0, _languageCommon.expandReferences)(params)(state);
712
+ data = (0, _languageCommon.expandReferences)(data)(state);
740
713
  options = (0, _languageCommon.expandReferences)(options)(state);
741
- const operationName = (_options$operationNam2 = (_options4 = options) === null || _options4 === void 0 ? void 0 : _options4.operationName) !== null && _options$operationNam2 !== void 0 ? _options$operationNam2 : 'delete';
742
714
  const {
743
- username,
744
- password,
745
- hostUrl
746
- } = state.configuration;
747
- const responseType = (_options$responseType2 = (_options5 = options) === null || _options5 === void 0 ? void 0 : _options5.responseType) !== null && _options$responseType2 !== void 0 ? _options$responseType2 : 'json';
748
- let queryParams = params;
749
- const filters = (_queryParams3 = queryParams) === null || _queryParams3 === void 0 ? void 0 : _queryParams3.filters;
750
- (_queryParams4 = queryParams) === null || _queryParams4 === void 0 ? true : delete _queryParams4.filters;
751
- queryParams = new URLSearchParams(queryParams);
752
- filters === null || filters === void 0 ? void 0 : filters.map(f => queryParams.append('filter', f));
753
- const apiVersion = (_options$apiVersion2 = (_options6 = options) === null || _options6 === void 0 ? void 0 : _options6.apiVersion) !== null && _options$apiVersion2 !== void 0 ? _options$apiVersion2 : state.configuration.apiVersion;
754
- const headers = {
755
- Accept: (_CONTENT_TYPES$respon2 = _Utils.CONTENT_TYPES[responseType]) !== null && _CONTENT_TYPES$respon2 !== void 0 ? _CONTENT_TYPES$respon2 : 'application/json'
756
- };
757
- const url = (0, _Utils.buildUrl)('/' + resourceType + '/' + path, hostUrl, apiVersion);
758
- return _axios.default.request({
759
- method: 'DELETE',
760
- url,
761
- auth: {
762
- username,
763
- password
764
- },
765
- params: queryParams,
766
- data: body,
767
- headers
715
+ params,
716
+ requestConfig
717
+ } = options;
718
+ const {
719
+ configuration
720
+ } = state;
721
+ return (0, _Client.request)({
722
+ method: 'delete',
723
+ url: (0, _Utils.generateUrl)(configuration, options, resourceType, path),
724
+ params,
725
+ data,
726
+ ...requestConfig
768
727
  }).then(result => {
769
- _Utils.Log.success(`${operationName} succeeded. DELETED ${resourceType}.\nSummary:\n${(0, _Utils.prettyJson)(result.data)}`);
728
+ _Utils.Log.success(`Deleted ${resourceType} at ${path}`);
770
729
 
771
- if (callback) return callback((0, _languageCommon.composeNextState)(state, result.data));
772
- return (0, _languageCommon.composeNextState)(state, result.data);
730
+ return (0, _Utils.handleResponse)(result, state, callback);
773
731
  });
774
732
  };
775
733
  }
package/lib/Client.js CHANGED
@@ -29,7 +29,7 @@ function request({
29
29
  params
30
30
  } = axiosRequest;
31
31
  console.log(`Sending ${method} request to ${url}`);
32
- if (params) console.log(` with params: ${params}`); // NOTE: We don't follow redirects for unsafe methods: https://github.com/axios/axios/issues/2460
32
+ if (params) console.log(` with params:`, params); // NOTE: We don't follow redirects for unsafe methods: https://github.com/axios/axios/issues/2460
33
33
 
34
34
  const safeRedirect = ['get', 'head', 'options', 'trace'].includes(method.toLowerCase());
35
35
  return (0, _axios.default)({
package/lib/Utils.js CHANGED
@@ -8,7 +8,6 @@ exports.handleResponse = handleResponse;
8
8
  exports.prettyJson = prettyJson;
9
9
  exports.nestArray = nestArray;
10
10
  exports.generateUrl = generateUrl;
11
- exports.buildUrlParams = buildUrlParams;
12
11
  exports.Log = exports.CONTENT_TYPES = void 0;
13
12
 
14
13
  var _languageCommon = require("@openfn/language-common");
@@ -65,7 +64,7 @@ function nestArray(data, key) {
65
64
  } : data;
66
65
  }
67
66
 
68
- function generateUrl(configuration, options, resourceType) {
67
+ function generateUrl(configuration, options, resourceType, path = null) {
69
68
  let {
70
69
  hostUrl,
71
70
  apiVersion
@@ -75,18 +74,7 @@ function generateUrl(configuration, options, resourceType) {
75
74
  if (options === null || options === void 0 ? void 0 : options.apiVersion) apiVersion = options.apiVersion;
76
75
  const apiMessage = apiVersion ? `Using DHIS2 api version ${apiVersion}` : 'Using latest available version of the DHIS2 api on this server.';
77
76
  console.log(apiMessage);
78
- return buildUrl(urlString, hostUrl, apiVersion);
79
- }
80
-
81
- function buildUrlParams(params) {
82
- const filters = params === null || params === void 0 ? void 0 : params.filters;
83
- const dimensions = params === null || params === void 0 ? void 0 : params.dimensions; // We remove filters and dimensions before building standard search params.
84
-
85
- params === null || params === void 0 ? true : delete params.filters;
86
- params === null || params === void 0 ? true : delete params.dimensions;
87
- const urlParams = new URLSearchParams(params); // Then we re-apply the filters and dimensions in this dhis2-specific way.
88
-
89
- filters === null || filters === void 0 ? void 0 : filters.map(f => urlParams.append('filter', f));
90
- dimensions === null || dimensions === void 0 ? void 0 : dimensions.map(d => urlParams.append('dimension', d));
91
- return urlParams;
77
+ const url = buildUrl(urlString, hostUrl, apiVersion);
78
+ if (path) return `${url}/${path}`;
79
+ return url;
92
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-dhis2",
3
- "version": "3.0.0-3",
3
+ "version": "3.0.0-4",
4
4
  "description": "DHIS2 Language Pack for OpenFn",
5
5
  "homepage": "https://docs.openfn.org",
6
6
  "repository": {
@@ -39,7 +39,7 @@
39
39
  "@babel/preset-env": "^7.9.5",
40
40
  "@babel/preset-stage-0": "^7.8.3",
41
41
  "@babel/register": "^7.9.0",
42
- "@openfn/simple-ast": "^0.3.0",
42
+ "@openfn/simple-ast": "^0.4.0",
43
43
  "assertion-error": "^1.0.1",
44
44
  "chai": "^3.4.0",
45
45
  "chai-http": "^4.3.0",