@openfn/language-dhis2 3.2.12 → 4.0.2
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 +57 -42
- package/dist/index.js +57 -42
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -314,39 +314,39 @@ import_axios3.default.interceptors.response.use(
|
|
|
314
314
|
return response;
|
|
315
315
|
},
|
|
316
316
|
function(error) {
|
|
317
|
-
var _a, _b, _c, _d
|
|
317
|
+
var _a, _b, _c, _d;
|
|
318
318
|
if ((_a = error.config) == null ? void 0 : _a.auth)
|
|
319
319
|
error.config.auth = "--REDACTED--";
|
|
320
320
|
if ((_b = error.config) == null ? void 0 : _b.data)
|
|
321
321
|
error.config.data = "--REDACTED--";
|
|
322
|
-
const details = (
|
|
322
|
+
const details = (_c = error.response) == null ? void 0 : _c.data;
|
|
323
323
|
Log.error(error.message || "That didn't work.");
|
|
324
324
|
if (details)
|
|
325
325
|
console.log(JSON.stringify(details, null, 2));
|
|
326
326
|
return Promise.reject({
|
|
327
327
|
request: error.config,
|
|
328
|
-
|
|
329
|
-
response: (
|
|
328
|
+
message: error.message,
|
|
329
|
+
response: (_d = error.response) == null ? void 0 : _d.data
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
332
|
);
|
|
333
333
|
function create(resourceType, data, options = {}, callback = false) {
|
|
334
334
|
return (state) => {
|
|
335
335
|
console.log(`Preparing create operation...`);
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const { params, requestConfig } =
|
|
336
|
+
const resolvedResourceType = (0, import_language_common2.expandReferences)(resourceType)(state);
|
|
337
|
+
const resolvedData = (0, import_language_common2.expandReferences)(data)(state);
|
|
338
|
+
const resolvedOptions = (0, import_language_common2.expandReferences)(options)(state);
|
|
339
|
+
const { params, requestConfig } = resolvedOptions;
|
|
340
340
|
const { configuration } = state;
|
|
341
341
|
return request(configuration, {
|
|
342
342
|
method: "post",
|
|
343
|
-
url: generateUrl(configuration,
|
|
343
|
+
url: generateUrl(configuration, resolvedOptions, resolvedResourceType),
|
|
344
344
|
params,
|
|
345
|
-
data: nestArray(
|
|
345
|
+
data: nestArray(resolvedData, resolvedResourceType),
|
|
346
346
|
...requestConfig
|
|
347
347
|
}).then((result) => {
|
|
348
348
|
const details = `with response ${JSON.stringify(result.data, null, 2)}`;
|
|
349
|
-
Log.success(`Created ${
|
|
349
|
+
Log.success(`Created ${resolvedResourceType} ${details}`);
|
|
350
350
|
const { location } = result.headers;
|
|
351
351
|
if (location)
|
|
352
352
|
console.log(`Record available @ ${location}`);
|
|
@@ -357,20 +357,25 @@ function create(resourceType, data, options = {}, callback = false) {
|
|
|
357
357
|
function update(resourceType, path, data, options = {}, callback = false) {
|
|
358
358
|
return (state) => {
|
|
359
359
|
console.log(`Preparing update operation...`);
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const { params, requestConfig } =
|
|
360
|
+
const resolvedResourceType = (0, import_language_common2.expandReferences)(resourceType)(state);
|
|
361
|
+
const resolvedPath = (0, import_language_common2.expandReferences)(path)(state);
|
|
362
|
+
const resolvedData = (0, import_language_common2.expandReferences)(data)(state);
|
|
363
|
+
const resolvedOptions = (0, import_language_common2.expandReferences)(options)(state);
|
|
364
|
+
const { params, requestConfig } = resolvedOptions;
|
|
365
365
|
const { configuration } = state;
|
|
366
366
|
return request(configuration, {
|
|
367
367
|
method: "put",
|
|
368
|
-
url: generateUrl(
|
|
368
|
+
url: generateUrl(
|
|
369
|
+
configuration,
|
|
370
|
+
resolvedOptions,
|
|
371
|
+
resolvedResourceType,
|
|
372
|
+
path
|
|
373
|
+
),
|
|
369
374
|
params,
|
|
370
|
-
data,
|
|
375
|
+
data: resolvedData,
|
|
371
376
|
...requestConfig
|
|
372
377
|
}).then((result) => {
|
|
373
|
-
Log.success(`Updated ${
|
|
378
|
+
Log.success(`Updated ${resolvedResourceType} at ${resolvedPath}`);
|
|
374
379
|
return handleResponse(result, state, callback);
|
|
375
380
|
});
|
|
376
381
|
};
|
|
@@ -378,19 +383,19 @@ function update(resourceType, path, data, options = {}, callback = false) {
|
|
|
378
383
|
function get(resourceType, query, options = {}, callback = false) {
|
|
379
384
|
return (state) => {
|
|
380
385
|
console.log("Preparing get operation...");
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
const { params, requestConfig } =
|
|
386
|
+
const resolvedResourceType = (0, import_language_common2.expandReferences)(resourceType)(state);
|
|
387
|
+
const resolvedQuery = (0, import_language_common2.expandReferences)(query)(state);
|
|
388
|
+
const resolvedOptions = (0, import_language_common2.expandReferences)(options)(state);
|
|
389
|
+
const { params, requestConfig } = resolvedOptions;
|
|
385
390
|
const { configuration } = state;
|
|
386
391
|
return request(configuration, {
|
|
387
392
|
method: "get",
|
|
388
|
-
url: generateUrl(configuration,
|
|
389
|
-
params: { ...
|
|
393
|
+
url: generateUrl(configuration, resolvedOptions, resolvedResourceType),
|
|
394
|
+
params: { ...resolvedQuery, ...params },
|
|
390
395
|
responseType: "json",
|
|
391
396
|
...requestConfig
|
|
392
397
|
}).then((result) => {
|
|
393
|
-
Log.success(`Retrieved ${
|
|
398
|
+
Log.success(`Retrieved ${resolvedResourceType}`);
|
|
394
399
|
return handleResponse(result, state, callback);
|
|
395
400
|
});
|
|
396
401
|
};
|
|
@@ -489,20 +494,25 @@ ${prettyJson(
|
|
|
489
494
|
function patch(resourceType, path, data, options = {}, callback = false) {
|
|
490
495
|
return (state) => {
|
|
491
496
|
console.log("Preparing patch operation...");
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
const { params, requestConfig } =
|
|
497
|
+
const resolvedResourceType = (0, import_language_common2.expandReferences)(resourceType)(state);
|
|
498
|
+
const resolvedPath = (0, import_language_common2.expandReferences)(path)(state);
|
|
499
|
+
const resolvedData = (0, import_language_common2.expandReferences)(data)(state);
|
|
500
|
+
const resolvedOptions = (0, import_language_common2.expandReferences)(options)(state);
|
|
501
|
+
const { params, requestConfig } = resolvedOptions;
|
|
497
502
|
const { configuration } = state;
|
|
498
503
|
return request(configuration, {
|
|
499
504
|
method: "patch",
|
|
500
|
-
url: generateUrl(
|
|
505
|
+
url: generateUrl(
|
|
506
|
+
configuration,
|
|
507
|
+
resolvedOptions,
|
|
508
|
+
resolvedResourceType,
|
|
509
|
+
resolvedPath
|
|
510
|
+
),
|
|
501
511
|
params,
|
|
502
|
-
data,
|
|
512
|
+
data: resolvedData,
|
|
503
513
|
...requestConfig
|
|
504
514
|
}).then((result) => {
|
|
505
|
-
Log.success(`Patched ${
|
|
515
|
+
Log.success(`Patched ${resolvedResourceType} at ${resolvedPath}`);
|
|
506
516
|
return handleResponse(result, state, callback);
|
|
507
517
|
});
|
|
508
518
|
};
|
|
@@ -510,20 +520,25 @@ function patch(resourceType, path, data, options = {}, callback = false) {
|
|
|
510
520
|
function destroy(resourceType, path, data = null, options = {}, callback = false) {
|
|
511
521
|
return (state) => {
|
|
512
522
|
console.log("Preparing destroy operation...");
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
const { params, requestConfig } =
|
|
523
|
+
const resolvedResourceType = (0, import_language_common2.expandReferences)(resourceType)(state);
|
|
524
|
+
const resolvedPath = (0, import_language_common2.expandReferences)(path)(state);
|
|
525
|
+
const resolvedData = (0, import_language_common2.expandReferences)(data)(state);
|
|
526
|
+
const resolvedOptions = (0, import_language_common2.expandReferences)(options)(state);
|
|
527
|
+
const { params, requestConfig } = resolvedOptions;
|
|
518
528
|
const { configuration } = state;
|
|
519
529
|
return request({
|
|
520
530
|
method: "delete",
|
|
521
|
-
url: generateUrl(
|
|
531
|
+
url: generateUrl(
|
|
532
|
+
configuration,
|
|
533
|
+
resolvedOptions,
|
|
534
|
+
resolvedResourceType,
|
|
535
|
+
resolvedPath
|
|
536
|
+
),
|
|
522
537
|
params,
|
|
523
|
-
|
|
538
|
+
resolvedData,
|
|
524
539
|
...requestConfig
|
|
525
540
|
}).then((result) => {
|
|
526
|
-
Log.success(`Deleted ${
|
|
541
|
+
Log.success(`Deleted ${resolvedResourceType} at ${resolvedPath}`);
|
|
527
542
|
return handleResponse(result, state, callback);
|
|
528
543
|
});
|
|
529
544
|
};
|
package/dist/index.js
CHANGED
|
@@ -281,39 +281,39 @@ axios3.interceptors.response.use(
|
|
|
281
281
|
return response;
|
|
282
282
|
},
|
|
283
283
|
function(error) {
|
|
284
|
-
var _a, _b, _c, _d
|
|
284
|
+
var _a, _b, _c, _d;
|
|
285
285
|
if ((_a = error.config) == null ? void 0 : _a.auth)
|
|
286
286
|
error.config.auth = "--REDACTED--";
|
|
287
287
|
if ((_b = error.config) == null ? void 0 : _b.data)
|
|
288
288
|
error.config.data = "--REDACTED--";
|
|
289
|
-
const details = (
|
|
289
|
+
const details = (_c = error.response) == null ? void 0 : _c.data;
|
|
290
290
|
Log.error(error.message || "That didn't work.");
|
|
291
291
|
if (details)
|
|
292
292
|
console.log(JSON.stringify(details, null, 2));
|
|
293
293
|
return Promise.reject({
|
|
294
294
|
request: error.config,
|
|
295
|
-
|
|
296
|
-
response: (
|
|
295
|
+
message: error.message,
|
|
296
|
+
response: (_d = error.response) == null ? void 0 : _d.data
|
|
297
297
|
});
|
|
298
298
|
}
|
|
299
299
|
);
|
|
300
300
|
function create(resourceType, data, options = {}, callback = false) {
|
|
301
301
|
return (state) => {
|
|
302
302
|
console.log(`Preparing create operation...`);
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
const { params, requestConfig } =
|
|
303
|
+
const resolvedResourceType = expandReferences(resourceType)(state);
|
|
304
|
+
const resolvedData = expandReferences(data)(state);
|
|
305
|
+
const resolvedOptions = expandReferences(options)(state);
|
|
306
|
+
const { params, requestConfig } = resolvedOptions;
|
|
307
307
|
const { configuration } = state;
|
|
308
308
|
return request(configuration, {
|
|
309
309
|
method: "post",
|
|
310
|
-
url: generateUrl(configuration,
|
|
310
|
+
url: generateUrl(configuration, resolvedOptions, resolvedResourceType),
|
|
311
311
|
params,
|
|
312
|
-
data: nestArray(
|
|
312
|
+
data: nestArray(resolvedData, resolvedResourceType),
|
|
313
313
|
...requestConfig
|
|
314
314
|
}).then((result) => {
|
|
315
315
|
const details = `with response ${JSON.stringify(result.data, null, 2)}`;
|
|
316
|
-
Log.success(`Created ${
|
|
316
|
+
Log.success(`Created ${resolvedResourceType} ${details}`);
|
|
317
317
|
const { location } = result.headers;
|
|
318
318
|
if (location)
|
|
319
319
|
console.log(`Record available @ ${location}`);
|
|
@@ -324,20 +324,25 @@ function create(resourceType, data, options = {}, callback = false) {
|
|
|
324
324
|
function update(resourceType, path, data, options = {}, callback = false) {
|
|
325
325
|
return (state) => {
|
|
326
326
|
console.log(`Preparing update operation...`);
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const { params, requestConfig } =
|
|
327
|
+
const resolvedResourceType = expandReferences(resourceType)(state);
|
|
328
|
+
const resolvedPath = expandReferences(path)(state);
|
|
329
|
+
const resolvedData = expandReferences(data)(state);
|
|
330
|
+
const resolvedOptions = expandReferences(options)(state);
|
|
331
|
+
const { params, requestConfig } = resolvedOptions;
|
|
332
332
|
const { configuration } = state;
|
|
333
333
|
return request(configuration, {
|
|
334
334
|
method: "put",
|
|
335
|
-
url: generateUrl(
|
|
335
|
+
url: generateUrl(
|
|
336
|
+
configuration,
|
|
337
|
+
resolvedOptions,
|
|
338
|
+
resolvedResourceType,
|
|
339
|
+
path
|
|
340
|
+
),
|
|
336
341
|
params,
|
|
337
|
-
data,
|
|
342
|
+
data: resolvedData,
|
|
338
343
|
...requestConfig
|
|
339
344
|
}).then((result) => {
|
|
340
|
-
Log.success(`Updated ${
|
|
345
|
+
Log.success(`Updated ${resolvedResourceType} at ${resolvedPath}`);
|
|
341
346
|
return handleResponse(result, state, callback);
|
|
342
347
|
});
|
|
343
348
|
};
|
|
@@ -345,19 +350,19 @@ function update(resourceType, path, data, options = {}, callback = false) {
|
|
|
345
350
|
function get(resourceType, query, options = {}, callback = false) {
|
|
346
351
|
return (state) => {
|
|
347
352
|
console.log("Preparing get operation...");
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
const { params, requestConfig } =
|
|
353
|
+
const resolvedResourceType = expandReferences(resourceType)(state);
|
|
354
|
+
const resolvedQuery = expandReferences(query)(state);
|
|
355
|
+
const resolvedOptions = expandReferences(options)(state);
|
|
356
|
+
const { params, requestConfig } = resolvedOptions;
|
|
352
357
|
const { configuration } = state;
|
|
353
358
|
return request(configuration, {
|
|
354
359
|
method: "get",
|
|
355
|
-
url: generateUrl(configuration,
|
|
356
|
-
params: { ...
|
|
360
|
+
url: generateUrl(configuration, resolvedOptions, resolvedResourceType),
|
|
361
|
+
params: { ...resolvedQuery, ...params },
|
|
357
362
|
responseType: "json",
|
|
358
363
|
...requestConfig
|
|
359
364
|
}).then((result) => {
|
|
360
|
-
Log.success(`Retrieved ${
|
|
365
|
+
Log.success(`Retrieved ${resolvedResourceType}`);
|
|
361
366
|
return handleResponse(result, state, callback);
|
|
362
367
|
});
|
|
363
368
|
};
|
|
@@ -456,20 +461,25 @@ ${prettyJson(
|
|
|
456
461
|
function patch(resourceType, path, data, options = {}, callback = false) {
|
|
457
462
|
return (state) => {
|
|
458
463
|
console.log("Preparing patch operation...");
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
const { params, requestConfig } =
|
|
464
|
+
const resolvedResourceType = expandReferences(resourceType)(state);
|
|
465
|
+
const resolvedPath = expandReferences(path)(state);
|
|
466
|
+
const resolvedData = expandReferences(data)(state);
|
|
467
|
+
const resolvedOptions = expandReferences(options)(state);
|
|
468
|
+
const { params, requestConfig } = resolvedOptions;
|
|
464
469
|
const { configuration } = state;
|
|
465
470
|
return request(configuration, {
|
|
466
471
|
method: "patch",
|
|
467
|
-
url: generateUrl(
|
|
472
|
+
url: generateUrl(
|
|
473
|
+
configuration,
|
|
474
|
+
resolvedOptions,
|
|
475
|
+
resolvedResourceType,
|
|
476
|
+
resolvedPath
|
|
477
|
+
),
|
|
468
478
|
params,
|
|
469
|
-
data,
|
|
479
|
+
data: resolvedData,
|
|
470
480
|
...requestConfig
|
|
471
481
|
}).then((result) => {
|
|
472
|
-
Log.success(`Patched ${
|
|
482
|
+
Log.success(`Patched ${resolvedResourceType} at ${resolvedPath}`);
|
|
473
483
|
return handleResponse(result, state, callback);
|
|
474
484
|
});
|
|
475
485
|
};
|
|
@@ -477,20 +487,25 @@ function patch(resourceType, path, data, options = {}, callback = false) {
|
|
|
477
487
|
function destroy(resourceType, path, data = null, options = {}, callback = false) {
|
|
478
488
|
return (state) => {
|
|
479
489
|
console.log("Preparing destroy operation...");
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
const { params, requestConfig } =
|
|
490
|
+
const resolvedResourceType = expandReferences(resourceType)(state);
|
|
491
|
+
const resolvedPath = expandReferences(path)(state);
|
|
492
|
+
const resolvedData = expandReferences(data)(state);
|
|
493
|
+
const resolvedOptions = expandReferences(options)(state);
|
|
494
|
+
const { params, requestConfig } = resolvedOptions;
|
|
485
495
|
const { configuration } = state;
|
|
486
496
|
return request({
|
|
487
497
|
method: "delete",
|
|
488
|
-
url: generateUrl(
|
|
498
|
+
url: generateUrl(
|
|
499
|
+
configuration,
|
|
500
|
+
resolvedOptions,
|
|
501
|
+
resolvedResourceType,
|
|
502
|
+
resolvedPath
|
|
503
|
+
),
|
|
489
504
|
params,
|
|
490
|
-
|
|
505
|
+
resolvedData,
|
|
491
506
|
...requestConfig
|
|
492
507
|
}).then((result) => {
|
|
493
|
-
Log.success(`Deleted ${
|
|
508
|
+
Log.success(`Deleted ${resolvedResourceType} at ${resolvedPath}`);
|
|
494
509
|
return handleResponse(result, state, callback);
|
|
495
510
|
});
|
|
496
511
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-dhis2",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "DHIS2 Language Pack for OpenFn",
|
|
5
5
|
"homepage": "https://docs.openfn.org",
|
|
6
6
|
"repository": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"configuration-schema.json"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@openfn/language-common": "^1.
|
|
27
|
+
"@openfn/language-common": "^1.8.1",
|
|
28
28
|
"axios": "^0.24.0",
|
|
29
29
|
"lodash": "^4.17.19",
|
|
30
30
|
"qs": "^6.11.0"
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"integration-test": "mocha --experimental-specifier-resolution=node --no-warnings test/integration.cjs",
|
|
49
49
|
"pack": "pnpm pack --pack-destination ../../dist",
|
|
50
50
|
"test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings --exclude test/integration.cjs --recursive --timeout 10000",
|
|
51
|
-
"test": "mocha --experimental-specifier-resolution=node --no-warnings --exclude test/integration.cjs --recursive --timeout 10000"
|
|
51
|
+
"test": "mocha --experimental-specifier-resolution=node --no-warnings --exclude test/integration.cjs --recursive --timeout 10000",
|
|
52
|
+
"lint": "eslint src"
|
|
52
53
|
}
|
|
53
54
|
}
|