@openfn/language-godata 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "properties": {
4
+ "apiUrl": {
5
+ "title": "API URL",
6
+ "type": "string",
7
+ "description": "Godata API URL",
8
+ "default": "https://www.who-godata.com/api",
9
+ "format": "uri",
10
+ "minLength": 1
11
+ },
12
+ "email": {
13
+ "title": "Email",
14
+ "type": "string",
15
+ "description": "Your Godata login email",
16
+ "writeOnly": true,
17
+ "minLength": 1
18
+ },
19
+ "password": {
20
+ "title": "Password",
21
+ "type": "string",
22
+ "description": "Your Godata login password",
23
+ "writeOnly": true,
24
+ "minLength": 1
25
+ }
26
+ },
27
+ "type": "object",
28
+ "additionalProperties": true,
29
+ "required": [
30
+ "apiUrl",
31
+ "email",
32
+ "password"
33
+ ]
34
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,678 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+
25
+ // src/index.js
26
+ var src_exports = {};
27
+ __export(src_exports, {
28
+ alterState: () => import_language_common2.alterState,
29
+ axios: () => import_axios.default,
30
+ dataPath: () => import_language_common2.dataPath,
31
+ dataValue: () => import_language_common2.dataValue,
32
+ default: () => src_default,
33
+ each: () => import_language_common2.each,
34
+ execute: () => execute,
35
+ field: () => import_language_common2.field,
36
+ fields: () => import_language_common2.fields,
37
+ getCase: () => getCase,
38
+ getContact: () => getContact,
39
+ getLocation: () => getLocation,
40
+ getOutbreak: () => getOutbreak,
41
+ getReferenceData: () => getReferenceData,
42
+ lastReferenceValue: () => import_language_common2.lastReferenceValue,
43
+ listCases: () => listCases,
44
+ listContacts: () => listContacts,
45
+ listLocations: () => listLocations,
46
+ listOutbreaks: () => listOutbreaks,
47
+ listReferenceData: () => listReferenceData,
48
+ merge: () => import_language_common2.merge,
49
+ sourceValue: () => import_language_common2.sourceValue,
50
+ upsertCase: () => upsertCase,
51
+ upsertContact: () => upsertContact,
52
+ upsertLocation: () => upsertLocation,
53
+ upsertOutbreak: () => upsertOutbreak,
54
+ upsertReferenceData: () => upsertReferenceData
55
+ });
56
+ module.exports = __toCommonJS(src_exports);
57
+
58
+ // src/Adaptor.js
59
+ var Adaptor_exports = {};
60
+ __export(Adaptor_exports, {
61
+ alterState: () => import_language_common2.alterState,
62
+ axios: () => import_axios.default,
63
+ dataPath: () => import_language_common2.dataPath,
64
+ dataValue: () => import_language_common2.dataValue,
65
+ each: () => import_language_common2.each,
66
+ execute: () => execute,
67
+ field: () => import_language_common2.field,
68
+ fields: () => import_language_common2.fields,
69
+ getCase: () => getCase,
70
+ getContact: () => getContact,
71
+ getLocation: () => getLocation,
72
+ getOutbreak: () => getOutbreak,
73
+ getReferenceData: () => getReferenceData,
74
+ lastReferenceValue: () => import_language_common2.lastReferenceValue,
75
+ listCases: () => listCases,
76
+ listContacts: () => listContacts,
77
+ listLocations: () => listLocations,
78
+ listOutbreaks: () => listOutbreaks,
79
+ listReferenceData: () => listReferenceData,
80
+ merge: () => import_language_common2.merge,
81
+ sourceValue: () => import_language_common2.sourceValue,
82
+ upsertCase: () => upsertCase,
83
+ upsertContact: () => upsertContact,
84
+ upsertLocation: () => upsertLocation,
85
+ upsertOutbreak: () => upsertOutbreak,
86
+ upsertReferenceData: () => upsertReferenceData
87
+ });
88
+ var import_language_common = require("@openfn/language-common");
89
+ var import_axios = __toESM(require("axios"), 1);
90
+ var import_language_common2 = require("@openfn/language-common");
91
+ function execute(...operations) {
92
+ const initialState = {
93
+ references: [],
94
+ data: null
95
+ };
96
+ return (state) => {
97
+ return (0, import_language_common.execute)(
98
+ login,
99
+ ...operations
100
+ )({ ...initialState, ...state }).catch((e) => {
101
+ console.error(e);
102
+ process.exit(1);
103
+ });
104
+ };
105
+ }
106
+ function login(state) {
107
+ const { apiUrl, password, email } = state.configuration;
108
+ return (0, import_axios.default)({
109
+ method: "post",
110
+ url: `${apiUrl}/users/login`,
111
+ data: {
112
+ email,
113
+ password
114
+ }
115
+ }).then((response) => {
116
+ console.log("Authentication succeeded.");
117
+ const { id } = response.data;
118
+ return {
119
+ ...state,
120
+ configuration: { ...state.configuration, apiUrl, access_token: id }
121
+ };
122
+ });
123
+ }
124
+ function listContacts(id, callback) {
125
+ return (state) => {
126
+ const { apiUrl, access_token } = state.configuration;
127
+ return (0, import_axios.default)({
128
+ method: "GET",
129
+ baseURL: apiUrl,
130
+ url: `/outbreaks/${id}/contacts`,
131
+ params: {
132
+ access_token
133
+ }
134
+ }).then((response) => {
135
+ const nextState = (0, import_language_common.composeNextState)(state, response.data);
136
+ if (callback)
137
+ return callback(nextState);
138
+ return nextState;
139
+ }).catch((error) => {
140
+ return error;
141
+ });
142
+ };
143
+ }
144
+ function getContact(id, query, callback) {
145
+ return (state) => {
146
+ const { apiUrl, access_token } = state.configuration;
147
+ const filter = JSON.stringify(query);
148
+ return (0, import_axios.default)({
149
+ baseURL: apiUrl,
150
+ url: `/outbreaks/${id}/contacts`,
151
+ method: "GET",
152
+ params: {
153
+ filter,
154
+ access_token
155
+ }
156
+ }).then((response) => {
157
+ const nextState = (0, import_language_common.composeNextState)(state, response.data);
158
+ if (callback)
159
+ return callback(nextState);
160
+ return nextState;
161
+ }).catch((error) => {
162
+ return error;
163
+ });
164
+ };
165
+ }
166
+ function upsertContact(id, externalId, goDataContact, callback) {
167
+ return (state) => {
168
+ const { apiUrl, access_token } = state.configuration;
169
+ const data = (0, import_language_common.expandReferences)(goDataContact)(state);
170
+ const query = { where: {} };
171
+ query.where[externalId] = data[externalId];
172
+ const filter = JSON.stringify(query);
173
+ return (0, import_axios.default)({
174
+ baseURL: apiUrl,
175
+ url: `/outbreaks/${id}/contacts`,
176
+ method: "GET",
177
+ params: {
178
+ filter,
179
+ access_token
180
+ }
181
+ }).then((response) => {
182
+ if (response.data.length > 1) {
183
+ console.log("Multiple contacts found. Aborting upsert.");
184
+ console.log(response.data.length, "contacts");
185
+ } else if (response.data.length === 1) {
186
+ console.log("Contact found. Performing update.");
187
+ const contactId = response.data[0].id;
188
+ return (0, import_axios.default)({
189
+ method: "PUT",
190
+ baseURL: apiUrl,
191
+ url: `/outbreaks/${id}/contacts/${contactId}`,
192
+ params: {
193
+ access_token
194
+ },
195
+ data
196
+ }).then((response2) => {
197
+ const nextState = (0, import_language_common.composeNextState)(state, response2.data);
198
+ if (callback)
199
+ return callback(nextState);
200
+ return nextState;
201
+ }).catch((error) => {
202
+ return error;
203
+ });
204
+ } else {
205
+ console.log("No contact found. Performing create.");
206
+ return (0, import_axios.default)({
207
+ method: "POST",
208
+ baseURL: apiUrl,
209
+ url: `/outbreaks/${id}/contacts/`,
210
+ params: {
211
+ access_token
212
+ },
213
+ data
214
+ }).then((response2) => {
215
+ const nextState = (0, import_language_common.composeNextState)(state, response2.data);
216
+ if (callback)
217
+ return callback(nextState);
218
+ return nextState;
219
+ }).catch((error) => {
220
+ return error;
221
+ });
222
+ }
223
+ }).catch((error) => {
224
+ return error;
225
+ });
226
+ };
227
+ }
228
+ function listOutbreaks(callback) {
229
+ return (state) => {
230
+ const { apiUrl, access_token } = state.configuration;
231
+ return (0, import_axios.default)({
232
+ method: "GET",
233
+ baseURL: apiUrl,
234
+ url: "/outbreaks",
235
+ params: {
236
+ access_token
237
+ }
238
+ }).then((response) => {
239
+ const nextState = (0, import_language_common.composeNextState)(state, response.data);
240
+ if (callback)
241
+ return callback(nextState);
242
+ return nextState;
243
+ }).catch((error) => {
244
+ return error;
245
+ });
246
+ };
247
+ }
248
+ function getOutbreak(query, callback) {
249
+ return (state) => {
250
+ const { apiUrl, access_token } = state.configuration;
251
+ const filter = JSON.stringify(query);
252
+ return (0, import_axios.default)({
253
+ method: "GET",
254
+ baseURL: apiUrl,
255
+ url: "/outbreaks",
256
+ params: {
257
+ filter,
258
+ access_token
259
+ }
260
+ }).then((response) => {
261
+ const nextState = (0, import_language_common.composeNextState)(state, response.data);
262
+ if (callback)
263
+ return callback(nextState);
264
+ return nextState;
265
+ }).catch((error) => {
266
+ return error;
267
+ });
268
+ };
269
+ }
270
+ function upsertOutbreak(outbreak, callback) {
271
+ return (state) => {
272
+ const { apiUrl, access_token } = state.configuration;
273
+ const { externalId, data } = (0, import_language_common.expandReferences)(outbreak)(state);
274
+ const filter = JSON.stringify({ where: { id: externalId } });
275
+ return (0, import_axios.default)({
276
+ method: "GET",
277
+ baseURL: apiUrl,
278
+ url: "/outbreaks",
279
+ params: {
280
+ filter,
281
+ access_token
282
+ }
283
+ }).then((response) => {
284
+ if (response.data.length > 0) {
285
+ console.log("Outbreak found. Performing update.");
286
+ const outbreakId = response.data[0].id;
287
+ return (0, import_axios.default)({
288
+ method: "PUT",
289
+ baseURL: apiUrl,
290
+ url: `/outbreaks/${outbreakId}`,
291
+ params: {
292
+ access_token
293
+ },
294
+ data
295
+ }).then((response2) => {
296
+ const nextState = (0, import_language_common.composeNextState)(state, response2.data);
297
+ if (callback)
298
+ return callback(nextState);
299
+ return nextState;
300
+ }).catch((error) => {
301
+ return error;
302
+ });
303
+ } else {
304
+ console.log("No outbreak found. Performing create.");
305
+ return (0, import_axios.default)({
306
+ method: "POST",
307
+ baseURL: apiUrl,
308
+ url: "/outbreaks",
309
+ params: {
310
+ access_token
311
+ },
312
+ data
313
+ }).then((response2) => {
314
+ const nextState = (0, import_language_common.composeNextState)(state, response2.data);
315
+ if (callback)
316
+ return callback(nextState);
317
+ return nextState;
318
+ }).catch((error) => {
319
+ return error;
320
+ });
321
+ }
322
+ }).catch((error) => {
323
+ return error;
324
+ });
325
+ };
326
+ }
327
+ function listCases(id, callback) {
328
+ return (state) => {
329
+ const { apiUrl, access_token } = state.configuration;
330
+ return (0, import_axios.default)({
331
+ method: "GET",
332
+ baseURL: apiUrl,
333
+ url: `/outbreaks/${id}/cases`,
334
+ params: {
335
+ access_token
336
+ }
337
+ }).then((response) => {
338
+ const nextState = (0, import_language_common.composeNextState)(state, response.data);
339
+ if (callback)
340
+ return callback(nextState);
341
+ return nextState;
342
+ }).catch((error) => {
343
+ return error;
344
+ });
345
+ };
346
+ }
347
+ function getCase(id, query, callback) {
348
+ return (state) => {
349
+ const { apiUrl, access_token } = state.configuration;
350
+ const filter = JSON.stringify(query);
351
+ return (0, import_axios.default)({
352
+ baseURL: apiUrl,
353
+ url: `/outbreaks/${id}/cases`,
354
+ method: "GET",
355
+ params: {
356
+ filter,
357
+ access_token
358
+ }
359
+ }).then((response) => {
360
+ const nextState = (0, import_language_common.composeNextState)(state, response.data);
361
+ if (callback)
362
+ return callback(nextState);
363
+ return nextState;
364
+ }).catch((error) => {
365
+ return error;
366
+ });
367
+ };
368
+ }
369
+ function upsertCase(id, externalId, goDataCase, callback) {
370
+ return (state) => {
371
+ const { apiUrl, access_token } = state.configuration;
372
+ const data = (0, import_language_common.expandReferences)(goDataCase)(state);
373
+ const query = { where: {} };
374
+ query.where[externalId] = data[externalId];
375
+ const filter = JSON.stringify(query);
376
+ return (0, import_axios.default)({
377
+ baseURL: apiUrl,
378
+ url: `/outbreaks/${id}/cases`,
379
+ method: "GET",
380
+ params: {
381
+ filter,
382
+ access_token
383
+ }
384
+ }).then((response) => {
385
+ if (response.data.length > 1) {
386
+ console.log(response.data.length, "cases found; aborting upsert.");
387
+ } else if (response.data.length === 1) {
388
+ console.log("Case found. Performing update.");
389
+ const caseId = response.data[0].id;
390
+ data["id"] = caseId;
391
+ delete data.visualId;
392
+ return (0, import_axios.default)({
393
+ method: "PUT",
394
+ baseURL: apiUrl,
395
+ url: `/outbreaks/${id}/cases/${caseId}`,
396
+ params: {
397
+ access_token
398
+ },
399
+ data
400
+ }).then((response2) => {
401
+ const nextState = (0, import_language_common.composeNextState)(state, response2.data);
402
+ if (callback)
403
+ return callback(nextState);
404
+ return nextState;
405
+ }).catch((error) => {
406
+ return error;
407
+ });
408
+ } else {
409
+ console.log("No case found. Performing create.");
410
+ return (0, import_axios.default)({
411
+ method: "POST",
412
+ baseURL: apiUrl,
413
+ url: `/outbreaks/${id}/cases/`,
414
+ params: {
415
+ access_token
416
+ },
417
+ data
418
+ }).then((response2) => {
419
+ const nextState = (0, import_language_common.composeNextState)(state, response2.data);
420
+ if (callback)
421
+ return callback(nextState);
422
+ return nextState;
423
+ }).catch((error) => {
424
+ return error;
425
+ });
426
+ }
427
+ }).catch((error) => {
428
+ return error;
429
+ });
430
+ };
431
+ }
432
+ function listLocations(callback) {
433
+ return (state) => {
434
+ const { apiUrl, access_token } = state.configuration;
435
+ return (0, import_axios.default)({
436
+ method: "GET",
437
+ baseURL: apiUrl,
438
+ url: "/locations",
439
+ params: {
440
+ access_token
441
+ }
442
+ }).then((response) => {
443
+ const nextState = (0, import_language_common.composeNextState)(state, response.data);
444
+ if (callback)
445
+ return callback(nextState);
446
+ return nextState;
447
+ }).catch((error) => {
448
+ return error;
449
+ });
450
+ };
451
+ }
452
+ function getLocation(query, callback) {
453
+ return (state) => {
454
+ const { apiUrl, access_token } = state.configuration;
455
+ const filter = JSON.stringify(query);
456
+ return (0, import_axios.default)({
457
+ method: "GET",
458
+ baseURL: apiUrl,
459
+ url: "/locations",
460
+ params: {
461
+ filter,
462
+ access_token
463
+ }
464
+ }).then((response) => {
465
+ const nextState = (0, import_language_common.composeNextState)(state, response.data);
466
+ if (callback)
467
+ return callback(nextState);
468
+ return nextState;
469
+ }).catch((error) => {
470
+ return error;
471
+ });
472
+ };
473
+ }
474
+ function upsertLocation(externalId, goDataLocation, callback) {
475
+ return (state) => {
476
+ const { apiUrl, access_token } = state.configuration;
477
+ const data = (0, import_language_common.expandReferences)(goDataLocation)(state);
478
+ const query = { where: {} };
479
+ query.where[externalId] = data[externalId];
480
+ const filter = JSON.stringify(query);
481
+ return (0, import_axios.default)({
482
+ method: "GET",
483
+ baseURL: apiUrl,
484
+ url: "/locations",
485
+ params: {
486
+ filter,
487
+ access_token
488
+ }
489
+ }).then((response) => {
490
+ if (response.data.length > 1) {
491
+ console.log(
492
+ response.data.length,
493
+ "locations found; aborting upsert."
494
+ );
495
+ return response;
496
+ } else if (response.data.length === 1) {
497
+ console.log("Location found. Performing update.");
498
+ const locationId = response.data[0].id;
499
+ return (0, import_axios.default)({
500
+ method: "PUT",
501
+ baseURL: apiUrl,
502
+ url: `/locations/${locationId}`,
503
+ params: {
504
+ access_token
505
+ },
506
+ data
507
+ }).then((response2) => {
508
+ const nextState = (0, import_language_common.composeNextState)(state, response2.data);
509
+ if (callback)
510
+ return callback(nextState);
511
+ return nextState;
512
+ }).catch((error) => {
513
+ return error;
514
+ });
515
+ } else {
516
+ console.log("No location found. Performing create.");
517
+ return (0, import_axios.default)({
518
+ method: "POST",
519
+ baseURL: apiUrl,
520
+ url: "/locations",
521
+ params: {
522
+ access_token
523
+ },
524
+ data
525
+ }).then((response2) => {
526
+ const nextState = (0, import_language_common.composeNextState)(state, response2.data);
527
+ if (callback)
528
+ return callback(nextState);
529
+ return nextState;
530
+ }).catch((error) => {
531
+ return error;
532
+ });
533
+ }
534
+ }).catch((error) => {
535
+ return error;
536
+ });
537
+ };
538
+ }
539
+ function listReferenceData(callback) {
540
+ return (state) => {
541
+ const { apiUrl, access_token } = state.configuration;
542
+ return (0, import_axios.default)({
543
+ method: "GET",
544
+ baseURL: apiUrl,
545
+ url: "/reference-data",
546
+ params: {
547
+ access_token
548
+ }
549
+ }).then((response) => {
550
+ const nextState = (0, import_language_common.composeNextState)(state, response.data);
551
+ if (callback)
552
+ return callback(nextState);
553
+ return nextState;
554
+ }).catch((error) => {
555
+ return error;
556
+ });
557
+ };
558
+ }
559
+ function getReferenceData(query, callback) {
560
+ return (state) => {
561
+ const { apiUrl, access_token } = state.configuration;
562
+ const filter = JSON.stringify(query);
563
+ return (0, import_axios.default)({
564
+ method: "GET",
565
+ baseURL: apiUrl,
566
+ url: "/reference-data",
567
+ params: {
568
+ filter,
569
+ access_token
570
+ }
571
+ }).then((response) => {
572
+ const nextState = (0, import_language_common.composeNextState)(state, response.data);
573
+ if (callback)
574
+ return callback(nextState);
575
+ return nextState;
576
+ }).catch((error) => {
577
+ return error;
578
+ });
579
+ };
580
+ }
581
+ function upsertReferenceData(externalId, goDataReferenceData, callback) {
582
+ return (state) => {
583
+ const { apiUrl, access_token } = state.configuration;
584
+ const data = (0, import_language_common.expandReferences)(goDataReferenceData)(state);
585
+ const query = { where: {} };
586
+ query.where[externalId] = data[externalId];
587
+ const filter = JSON.stringify(query);
588
+ return (0, import_axios.default)({
589
+ method: "GET",
590
+ baseURL: apiUrl,
591
+ url: "/reference-data",
592
+ params: {
593
+ filter,
594
+ access_token
595
+ }
596
+ }).then((response) => {
597
+ if (response.data.length > 1) {
598
+ console.log(
599
+ response.data.length,
600
+ "reference data found; aborting upsert."
601
+ );
602
+ return response;
603
+ } else if (response.data.length === 1) {
604
+ console.log("Reference data found. Performing update.");
605
+ const referenceDataId = response.data[0].id;
606
+ console.log("referenceDataId", referenceDataId);
607
+ return (0, import_axios.default)({
608
+ method: "PUT",
609
+ baseURL: apiUrl,
610
+ url: `/reference-data/${referenceDataId}`,
611
+ params: {
612
+ access_token
613
+ },
614
+ data
615
+ }).then((response2) => {
616
+ const nextState = (0, import_language_common.composeNextState)(state, response2.data);
617
+ if (callback)
618
+ return callback(nextState);
619
+ return nextState;
620
+ }).catch((error) => {
621
+ return error;
622
+ });
623
+ } else {
624
+ console.log("No reference data found. Performing create.");
625
+ return (0, import_axios.default)({
626
+ method: "POST",
627
+ baseURL: apiUrl,
628
+ url: "/reference-data",
629
+ params: {
630
+ access_token
631
+ },
632
+ data
633
+ }).then((response2) => {
634
+ const nextState = (0, import_language_common.composeNextState)(state, response2.data);
635
+ if (callback)
636
+ return callback(nextState);
637
+ return nextState;
638
+ }).catch((error) => {
639
+ return error;
640
+ });
641
+ }
642
+ }).catch((error) => {
643
+ return error;
644
+ });
645
+ };
646
+ }
647
+
648
+ // src/index.js
649
+ var src_default = Adaptor_exports;
650
+ // Annotate the CommonJS export names for ESM import in node:
651
+ 0 && (module.exports = {
652
+ alterState,
653
+ axios,
654
+ dataPath,
655
+ dataValue,
656
+ each,
657
+ execute,
658
+ field,
659
+ fields,
660
+ getCase,
661
+ getContact,
662
+ getLocation,
663
+ getOutbreak,
664
+ getReferenceData,
665
+ lastReferenceValue,
666
+ listCases,
667
+ listContacts,
668
+ listLocations,
669
+ listOutbreaks,
670
+ listReferenceData,
671
+ merge,
672
+ sourceValue,
673
+ upsertCase,
674
+ upsertContact,
675
+ upsertLocation,
676
+ upsertOutbreak,
677
+ upsertReferenceData
678
+ });