@openfn/language-satusehat 1.1.2 → 2.0.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.
- package/ast.json +278 -45
- package/dist/index.cjs +15 -10
- package/dist/index.js +11 -11
- package/package.json +3 -3
- package/types/Adaptor.d.ts +7 -4
package/ast.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"callback"
|
|
9
9
|
],
|
|
10
10
|
"docs": {
|
|
11
|
-
"description": "Make a
|
|
11
|
+
"description": "Make a GET request to Satusehat",
|
|
12
12
|
"tags": [
|
|
13
13
|
{
|
|
14
14
|
"title": "public",
|
|
@@ -62,6 +62,234 @@
|
|
|
62
62
|
]
|
|
63
63
|
},
|
|
64
64
|
"valid": true
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "post",
|
|
68
|
+
"params": [
|
|
69
|
+
"path",
|
|
70
|
+
"data",
|
|
71
|
+
"params",
|
|
72
|
+
"callback"
|
|
73
|
+
],
|
|
74
|
+
"docs": {
|
|
75
|
+
"description": "Make a POST request to Satusehat",
|
|
76
|
+
"tags": [
|
|
77
|
+
{
|
|
78
|
+
"title": "example",
|
|
79
|
+
"description": "post(\n \"Organization\",\n { \"resourceType\": \"Organization\", \"active\": true,\n }\n);"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"title": "function",
|
|
83
|
+
"description": null,
|
|
84
|
+
"name": null
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"title": "public",
|
|
88
|
+
"description": null,
|
|
89
|
+
"type": null
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"title": "param",
|
|
93
|
+
"description": "Path to resource",
|
|
94
|
+
"type": {
|
|
95
|
+
"type": "NameExpression",
|
|
96
|
+
"name": "string"
|
|
97
|
+
},
|
|
98
|
+
"name": "path"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"title": "param",
|
|
102
|
+
"description": "Object or JSON which defines data that will be used to create a given instance of resource",
|
|
103
|
+
"type": {
|
|
104
|
+
"type": "NameExpression",
|
|
105
|
+
"name": "object"
|
|
106
|
+
},
|
|
107
|
+
"name": "data"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"title": "param",
|
|
111
|
+
"description": "Optional request params.",
|
|
112
|
+
"type": {
|
|
113
|
+
"type": "NameExpression",
|
|
114
|
+
"name": "Object"
|
|
115
|
+
},
|
|
116
|
+
"name": "params"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"title": "param",
|
|
120
|
+
"description": "Optional callback to handle the response",
|
|
121
|
+
"type": {
|
|
122
|
+
"type": "OptionalType",
|
|
123
|
+
"expression": {
|
|
124
|
+
"type": "NameExpression",
|
|
125
|
+
"name": "function"
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"name": "callback"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"title": "returns",
|
|
132
|
+
"description": null,
|
|
133
|
+
"type": {
|
|
134
|
+
"type": "NameExpression",
|
|
135
|
+
"name": "Operation"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
},
|
|
140
|
+
"valid": true
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"name": "put",
|
|
144
|
+
"params": [
|
|
145
|
+
"path",
|
|
146
|
+
"data",
|
|
147
|
+
"params",
|
|
148
|
+
"callback"
|
|
149
|
+
],
|
|
150
|
+
"docs": {
|
|
151
|
+
"description": "Make a PUT request to Satusehat",
|
|
152
|
+
"tags": [
|
|
153
|
+
{
|
|
154
|
+
"title": "example",
|
|
155
|
+
"description": "put(\n \"Organization/123\",\n { \"resourceType\": \"Organization\", \"active\": false,\n }\n);"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"title": "function",
|
|
159
|
+
"description": null,
|
|
160
|
+
"name": null
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"title": "public",
|
|
164
|
+
"description": null,
|
|
165
|
+
"type": null
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"title": "param",
|
|
169
|
+
"description": "Path to resource and exact item to be updated",
|
|
170
|
+
"type": {
|
|
171
|
+
"type": "NameExpression",
|
|
172
|
+
"name": "string"
|
|
173
|
+
},
|
|
174
|
+
"name": "path"
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"title": "param",
|
|
178
|
+
"description": "Object or JSON which defines data that will be used to update a given instance of resource",
|
|
179
|
+
"type": {
|
|
180
|
+
"type": "NameExpression",
|
|
181
|
+
"name": "object"
|
|
182
|
+
},
|
|
183
|
+
"name": "data"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"title": "param",
|
|
187
|
+
"description": "Optional request params.",
|
|
188
|
+
"type": {
|
|
189
|
+
"type": "NameExpression",
|
|
190
|
+
"name": "Object"
|
|
191
|
+
},
|
|
192
|
+
"name": "params"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"title": "param",
|
|
196
|
+
"description": "Optional callback to handle the response",
|
|
197
|
+
"type": {
|
|
198
|
+
"type": "OptionalType",
|
|
199
|
+
"expression": {
|
|
200
|
+
"type": "NameExpression",
|
|
201
|
+
"name": "function"
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
"name": "callback"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"title": "returns",
|
|
208
|
+
"description": null,
|
|
209
|
+
"type": {
|
|
210
|
+
"type": "NameExpression",
|
|
211
|
+
"name": "Operation"
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
]
|
|
215
|
+
},
|
|
216
|
+
"valid": true
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"name": "patch",
|
|
220
|
+
"params": [
|
|
221
|
+
"path",
|
|
222
|
+
"data",
|
|
223
|
+
"params",
|
|
224
|
+
"callback"
|
|
225
|
+
],
|
|
226
|
+
"docs": {
|
|
227
|
+
"description": "Make a PATCH request to Satusehat",
|
|
228
|
+
"tags": [
|
|
229
|
+
{
|
|
230
|
+
"title": "example",
|
|
231
|
+
"description": "patch(\n \"Organization/123\",\n [{\n\"op\": \"replace\", // Operation - `replace` is the only one used to change a specific property or element\n \"path\": \"/language\", // Path - The name of property/element of resource to be replaced\n \"value\": \"id\" // Value- The value to be replaced\n}]\n\n);"
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"title": "function",
|
|
235
|
+
"description": null,
|
|
236
|
+
"name": null
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
"title": "public",
|
|
240
|
+
"description": null,
|
|
241
|
+
"type": null
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
"title": "param",
|
|
245
|
+
"description": "Path to resource and exact item to be partially updated",
|
|
246
|
+
"type": {
|
|
247
|
+
"type": "NameExpression",
|
|
248
|
+
"name": "string"
|
|
249
|
+
},
|
|
250
|
+
"name": "path"
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
"title": "param",
|
|
254
|
+
"description": "An array of objects which defines data that will be used to partially update a given instance of resource",
|
|
255
|
+
"type": {
|
|
256
|
+
"type": "NameExpression",
|
|
257
|
+
"name": "Array"
|
|
258
|
+
},
|
|
259
|
+
"name": "data"
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
"title": "param",
|
|
263
|
+
"description": "Optional request params.",
|
|
264
|
+
"type": {
|
|
265
|
+
"type": "NameExpression",
|
|
266
|
+
"name": "Object"
|
|
267
|
+
},
|
|
268
|
+
"name": "params"
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
"title": "param",
|
|
272
|
+
"description": "Optional callback to handle the response",
|
|
273
|
+
"type": {
|
|
274
|
+
"type": "OptionalType",
|
|
275
|
+
"expression": {
|
|
276
|
+
"type": "NameExpression",
|
|
277
|
+
"name": "function"
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
"name": "callback"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
"title": "returns",
|
|
284
|
+
"description": null,
|
|
285
|
+
"type": {
|
|
286
|
+
"type": "NameExpression",
|
|
287
|
+
"name": "Operation"
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
]
|
|
291
|
+
},
|
|
292
|
+
"valid": true
|
|
65
293
|
}
|
|
66
294
|
],
|
|
67
295
|
"exports": [],
|
|
@@ -79,15 +307,15 @@
|
|
|
79
307
|
"description": null,
|
|
80
308
|
"type": null
|
|
81
309
|
},
|
|
82
|
-
{
|
|
83
|
-
"title": "example",
|
|
84
|
-
"description": "fn(state => {\n // do some things to state\n return state;\n});"
|
|
85
|
-
},
|
|
86
310
|
{
|
|
87
311
|
"title": "function",
|
|
88
312
|
"description": null,
|
|
89
313
|
"name": null
|
|
90
314
|
},
|
|
315
|
+
{
|
|
316
|
+
"title": "example",
|
|
317
|
+
"description": "fn(state => {\n // do some things to state\n return state;\n});"
|
|
318
|
+
},
|
|
91
319
|
{
|
|
92
320
|
"title": "param",
|
|
93
321
|
"description": "is the function",
|
|
@@ -123,15 +351,15 @@
|
|
|
123
351
|
"description": null,
|
|
124
352
|
"type": null
|
|
125
353
|
},
|
|
126
|
-
{
|
|
127
|
-
"title": "example",
|
|
128
|
-
"description": "fnIf((state) => state?.data?.name, get(\"https://example.com\"));"
|
|
129
|
-
},
|
|
130
354
|
{
|
|
131
355
|
"title": "function",
|
|
132
356
|
"description": null,
|
|
133
357
|
"name": null
|
|
134
358
|
},
|
|
359
|
+
{
|
|
360
|
+
"title": "example",
|
|
361
|
+
"description": "fnIf((state) => state?.data?.name, get(\"https://example.com\"));"
|
|
362
|
+
},
|
|
135
363
|
{
|
|
136
364
|
"title": "param",
|
|
137
365
|
"description": "The condition that returns true",
|
|
@@ -175,15 +403,15 @@
|
|
|
175
403
|
"description": null,
|
|
176
404
|
"type": null
|
|
177
405
|
},
|
|
178
|
-
{
|
|
179
|
-
"title": "example",
|
|
180
|
-
"description": "sourceValue('$.key')"
|
|
181
|
-
},
|
|
182
406
|
{
|
|
183
407
|
"title": "function",
|
|
184
408
|
"description": null,
|
|
185
409
|
"name": null
|
|
186
410
|
},
|
|
411
|
+
{
|
|
412
|
+
"title": "example",
|
|
413
|
+
"description": "sourceValue('$.key')"
|
|
414
|
+
},
|
|
187
415
|
{
|
|
188
416
|
"title": "param",
|
|
189
417
|
"description": "JSONPath referencing a point in `state`.",
|
|
@@ -218,15 +446,15 @@
|
|
|
218
446
|
"description": null,
|
|
219
447
|
"type": null
|
|
220
448
|
},
|
|
221
|
-
{
|
|
222
|
-
"title": "example",
|
|
223
|
-
"description": "dataPath('key')"
|
|
224
|
-
},
|
|
225
449
|
{
|
|
226
450
|
"title": "function",
|
|
227
451
|
"description": null,
|
|
228
452
|
"name": null
|
|
229
453
|
},
|
|
454
|
+
{
|
|
455
|
+
"title": "example",
|
|
456
|
+
"description": "dataPath('key')"
|
|
457
|
+
},
|
|
230
458
|
{
|
|
231
459
|
"title": "param",
|
|
232
460
|
"description": "JSONPath referencing a point in `data`.",
|
|
@@ -261,15 +489,15 @@
|
|
|
261
489
|
"description": null,
|
|
262
490
|
"type": null
|
|
263
491
|
},
|
|
264
|
-
{
|
|
265
|
-
"title": "example",
|
|
266
|
-
"description": "dataValue('key')"
|
|
267
|
-
},
|
|
268
492
|
{
|
|
269
493
|
"title": "function",
|
|
270
494
|
"description": null,
|
|
271
495
|
"name": null
|
|
272
496
|
},
|
|
497
|
+
{
|
|
498
|
+
"title": "example",
|
|
499
|
+
"description": "dataValue('key')"
|
|
500
|
+
},
|
|
273
501
|
{
|
|
274
502
|
"title": "param",
|
|
275
503
|
"description": "JSONPath referencing a point in `data`.",
|
|
@@ -304,15 +532,15 @@
|
|
|
304
532
|
"description": null,
|
|
305
533
|
"type": null
|
|
306
534
|
},
|
|
307
|
-
{
|
|
308
|
-
"title": "example",
|
|
309
|
-
"description": "lastReferenceValue('key')"
|
|
310
|
-
},
|
|
311
535
|
{
|
|
312
536
|
"title": "function",
|
|
313
537
|
"description": null,
|
|
314
538
|
"name": null
|
|
315
539
|
},
|
|
540
|
+
{
|
|
541
|
+
"title": "example",
|
|
542
|
+
"description": "lastReferenceValue('key')"
|
|
543
|
+
},
|
|
316
544
|
{
|
|
317
545
|
"title": "param",
|
|
318
546
|
"description": "JSONPath referencing a point in `references`.",
|
|
@@ -348,15 +576,15 @@
|
|
|
348
576
|
"description": null,
|
|
349
577
|
"type": null
|
|
350
578
|
},
|
|
351
|
-
{
|
|
352
|
-
"title": "example",
|
|
353
|
-
"description": "each(\"$.[*]\",\n create(\"SObject\",\n field(\"FirstName\", sourceValue(\"$.firstName\"))\n )\n)"
|
|
354
|
-
},
|
|
355
579
|
{
|
|
356
580
|
"title": "function",
|
|
357
581
|
"description": null,
|
|
358
582
|
"name": null
|
|
359
583
|
},
|
|
584
|
+
{
|
|
585
|
+
"title": "example",
|
|
586
|
+
"description": "each(\"$.[*]\",\n create(\"SObject\",\n field(\"FirstName\", sourceValue(\"$.firstName\"))\n )\n)"
|
|
587
|
+
},
|
|
360
588
|
{
|
|
361
589
|
"title": "param",
|
|
362
590
|
"description": "JSONPath referencing a point in `state`.",
|
|
@@ -400,15 +628,15 @@
|
|
|
400
628
|
"description": null,
|
|
401
629
|
"type": null
|
|
402
630
|
},
|
|
403
|
-
{
|
|
404
|
-
"title": "example",
|
|
405
|
-
"description": "combine(\n create('foo'),\n delete('bar')\n)"
|
|
406
|
-
},
|
|
407
631
|
{
|
|
408
632
|
"title": "function",
|
|
409
633
|
"description": null,
|
|
410
634
|
"name": null
|
|
411
635
|
},
|
|
636
|
+
{
|
|
637
|
+
"title": "example",
|
|
638
|
+
"description": "combine(\n create('foo'),\n delete('bar')\n)"
|
|
639
|
+
},
|
|
412
640
|
{
|
|
413
641
|
"title": "param",
|
|
414
642
|
"description": "Operations to be performed.",
|
|
@@ -444,15 +672,15 @@
|
|
|
444
672
|
"description": null,
|
|
445
673
|
"type": null
|
|
446
674
|
},
|
|
447
|
-
{
|
|
448
|
-
"title": "example",
|
|
449
|
-
"description": "field('destination_field_name__c', 'value')"
|
|
450
|
-
},
|
|
451
675
|
{
|
|
452
676
|
"title": "function",
|
|
453
677
|
"description": null,
|
|
454
678
|
"name": null
|
|
455
679
|
},
|
|
680
|
+
{
|
|
681
|
+
"title": "example",
|
|
682
|
+
"description": "field('destination_field_name__c', 'value')"
|
|
683
|
+
},
|
|
456
684
|
{
|
|
457
685
|
"title": "param",
|
|
458
686
|
"description": "Name of the field",
|
|
@@ -496,15 +724,15 @@
|
|
|
496
724
|
"description": null,
|
|
497
725
|
"type": null
|
|
498
726
|
},
|
|
499
|
-
{
|
|
500
|
-
"title": "example",
|
|
501
|
-
"description": "fields(list_of_fields)"
|
|
502
|
-
},
|
|
503
727
|
{
|
|
504
728
|
"title": "function",
|
|
505
729
|
"description": null,
|
|
506
730
|
"name": null
|
|
507
731
|
},
|
|
732
|
+
{
|
|
733
|
+
"title": "example",
|
|
734
|
+
"description": "fields(list_of_fields)"
|
|
735
|
+
},
|
|
508
736
|
{
|
|
509
737
|
"title": "param",
|
|
510
738
|
"description": "a list of fields",
|
|
@@ -549,6 +777,11 @@
|
|
|
549
777
|
"description": null,
|
|
550
778
|
"name": null
|
|
551
779
|
},
|
|
780
|
+
{
|
|
781
|
+
"title": "public",
|
|
782
|
+
"description": null,
|
|
783
|
+
"type": null
|
|
784
|
+
},
|
|
552
785
|
{
|
|
553
786
|
"title": "param",
|
|
554
787
|
"description": null,
|
|
@@ -593,15 +826,15 @@
|
|
|
593
826
|
"description": null,
|
|
594
827
|
"type": null
|
|
595
828
|
},
|
|
596
|
-
{
|
|
597
|
-
"title": "example",
|
|
598
|
-
"description": "field(\"destination_string__c\", function(state) {\n return arrayToString(dataValue(\"path_of_array\")(state), ', ')\n})"
|
|
599
|
-
},
|
|
600
829
|
{
|
|
601
830
|
"title": "function",
|
|
602
831
|
"description": null,
|
|
603
832
|
"name": null
|
|
604
833
|
},
|
|
834
|
+
{
|
|
835
|
+
"title": "example",
|
|
836
|
+
"description": "field(\"destination_string__c\", function(state) {\n return arrayToString(dataValue(\"path_of_array\")(state), ', ')\n})"
|
|
837
|
+
},
|
|
605
838
|
{
|
|
606
839
|
"title": "param",
|
|
607
840
|
"description": "Array of toString'able primatives.",
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,6 +16,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
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
|
+
));
|
|
17
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
24
|
|
|
19
25
|
// src/index.js
|
|
@@ -70,6 +76,7 @@ var import_util2 = require("@openfn/language-common/util");
|
|
|
70
76
|
|
|
71
77
|
// src/Utils.js
|
|
72
78
|
var import_language_common = require("@openfn/language-common");
|
|
79
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
73
80
|
var import_util = require("@openfn/language-common/util");
|
|
74
81
|
var generateUserAgent = () => {
|
|
75
82
|
return `nodejs/${process.version} @openfn/language-satusehat`;
|
|
@@ -140,15 +147,17 @@ async function request(configuration, path, opts) {
|
|
|
140
147
|
"User-Agent": generateUserAgent(),
|
|
141
148
|
"content-type": contentType
|
|
142
149
|
};
|
|
150
|
+
(0, import_util.assertRelativeUrl)(path);
|
|
151
|
+
const safePath = import_node_path.default.join("fhir-r4/v1", path);
|
|
143
152
|
const options = {
|
|
144
153
|
body: data,
|
|
145
154
|
headers,
|
|
146
155
|
query: params,
|
|
147
156
|
parseAs,
|
|
148
157
|
maxRedirections: 1,
|
|
149
|
-
baseUrl
|
|
158
|
+
baseUrl
|
|
150
159
|
};
|
|
151
|
-
return (0, import_util.request)(method,
|
|
160
|
+
return (0, import_util.request)(method, safePath, options).then(import_util.logResponse);
|
|
152
161
|
}
|
|
153
162
|
|
|
154
163
|
// src/Adaptor.js
|
|
@@ -176,13 +185,12 @@ function get(path, params = {}, callback = (s) => s) {
|
|
|
176
185
|
params
|
|
177
186
|
);
|
|
178
187
|
try {
|
|
179
|
-
const response = await request(state.configuration,
|
|
188
|
+
const response = await request(state.configuration, resolvedPath, {
|
|
180
189
|
method: "GET",
|
|
181
190
|
params: resolvedParams
|
|
182
191
|
});
|
|
183
192
|
return prepareNextState(state, response, callback);
|
|
184
193
|
} catch (e) {
|
|
185
|
-
console.error(JSON.stringify(e.body, null, 2));
|
|
186
194
|
throw e;
|
|
187
195
|
}
|
|
188
196
|
};
|
|
@@ -196,14 +204,13 @@ function post(path, data, params = {}, callback = (s) => s) {
|
|
|
196
204
|
params
|
|
197
205
|
);
|
|
198
206
|
try {
|
|
199
|
-
const response = await request(state.configuration,
|
|
207
|
+
const response = await request(state.configuration, resolvedPath, {
|
|
200
208
|
method: "POST",
|
|
201
209
|
data: resolvedData,
|
|
202
210
|
params: resolvedParams
|
|
203
211
|
});
|
|
204
212
|
return prepareNextState(state, response, callback);
|
|
205
213
|
} catch (e) {
|
|
206
|
-
console.error(JSON.stringify(e.body, null, 2));
|
|
207
214
|
throw e;
|
|
208
215
|
}
|
|
209
216
|
};
|
|
@@ -217,14 +224,13 @@ function put(path, data, params = {}, callback = (s) => s) {
|
|
|
217
224
|
params
|
|
218
225
|
);
|
|
219
226
|
try {
|
|
220
|
-
const response = await request(state.configuration,
|
|
227
|
+
const response = await request(state.configuration, resolvedPath, {
|
|
221
228
|
method: "PUT",
|
|
222
229
|
data: resolvedData,
|
|
223
230
|
params: resolvedParams
|
|
224
231
|
});
|
|
225
232
|
return prepareNextState(state, response, callback);
|
|
226
233
|
} catch (e) {
|
|
227
|
-
console.error(JSON.stringify(e.body, null, 2));
|
|
228
234
|
throw e;
|
|
229
235
|
}
|
|
230
236
|
};
|
|
@@ -238,7 +244,7 @@ function patch(path, data, params = {}, callback = (s) => s) {
|
|
|
238
244
|
params
|
|
239
245
|
);
|
|
240
246
|
try {
|
|
241
|
-
const response = await request(state.configuration,
|
|
247
|
+
const response = await request(state.configuration, resolvedPath, {
|
|
242
248
|
method: "PATCH",
|
|
243
249
|
data: JSON.stringify(resolvedData),
|
|
244
250
|
params: resolvedParams,
|
|
@@ -246,7 +252,6 @@ function patch(path, data, params = {}, callback = (s) => s) {
|
|
|
246
252
|
});
|
|
247
253
|
return prepareNextState(state, response, callback);
|
|
248
254
|
} catch (e) {
|
|
249
|
-
console.error(JSON.stringify(e.body, null, 2));
|
|
250
255
|
throw e;
|
|
251
256
|
}
|
|
252
257
|
};
|
package/dist/index.js
CHANGED
|
@@ -32,9 +32,11 @@ import { expandReferences } from "@openfn/language-common/util";
|
|
|
32
32
|
|
|
33
33
|
// src/Utils.js
|
|
34
34
|
import { composeNextState } from "@openfn/language-common";
|
|
35
|
+
import nodepath from "path";
|
|
35
36
|
import {
|
|
36
37
|
request as commonRequest,
|
|
37
|
-
logResponse
|
|
38
|
+
logResponse,
|
|
39
|
+
assertRelativeUrl
|
|
38
40
|
} from "@openfn/language-common/util";
|
|
39
41
|
var generateUserAgent = () => {
|
|
40
42
|
return `nodejs/${process.version} @openfn/language-satusehat`;
|
|
@@ -105,15 +107,17 @@ async function request(configuration, path, opts) {
|
|
|
105
107
|
"User-Agent": generateUserAgent(),
|
|
106
108
|
"content-type": contentType
|
|
107
109
|
};
|
|
110
|
+
assertRelativeUrl(path);
|
|
111
|
+
const safePath = nodepath.join("fhir-r4/v1", path);
|
|
108
112
|
const options = {
|
|
109
113
|
body: data,
|
|
110
114
|
headers,
|
|
111
115
|
query: params,
|
|
112
116
|
parseAs,
|
|
113
117
|
maxRedirections: 1,
|
|
114
|
-
baseUrl
|
|
118
|
+
baseUrl
|
|
115
119
|
};
|
|
116
|
-
return commonRequest(method,
|
|
120
|
+
return commonRequest(method, safePath, options).then(logResponse);
|
|
117
121
|
}
|
|
118
122
|
|
|
119
123
|
// src/Adaptor.js
|
|
@@ -156,13 +160,12 @@ function get(path, params = {}, callback = (s) => s) {
|
|
|
156
160
|
params
|
|
157
161
|
);
|
|
158
162
|
try {
|
|
159
|
-
const response = await request(state.configuration,
|
|
163
|
+
const response = await request(state.configuration, resolvedPath, {
|
|
160
164
|
method: "GET",
|
|
161
165
|
params: resolvedParams
|
|
162
166
|
});
|
|
163
167
|
return prepareNextState(state, response, callback);
|
|
164
168
|
} catch (e) {
|
|
165
|
-
console.error(JSON.stringify(e.body, null, 2));
|
|
166
169
|
throw e;
|
|
167
170
|
}
|
|
168
171
|
};
|
|
@@ -176,14 +179,13 @@ function post(path, data, params = {}, callback = (s) => s) {
|
|
|
176
179
|
params
|
|
177
180
|
);
|
|
178
181
|
try {
|
|
179
|
-
const response = await request(state.configuration,
|
|
182
|
+
const response = await request(state.configuration, resolvedPath, {
|
|
180
183
|
method: "POST",
|
|
181
184
|
data: resolvedData,
|
|
182
185
|
params: resolvedParams
|
|
183
186
|
});
|
|
184
187
|
return prepareNextState(state, response, callback);
|
|
185
188
|
} catch (e) {
|
|
186
|
-
console.error(JSON.stringify(e.body, null, 2));
|
|
187
189
|
throw e;
|
|
188
190
|
}
|
|
189
191
|
};
|
|
@@ -197,14 +199,13 @@ function put(path, data, params = {}, callback = (s) => s) {
|
|
|
197
199
|
params
|
|
198
200
|
);
|
|
199
201
|
try {
|
|
200
|
-
const response = await request(state.configuration,
|
|
202
|
+
const response = await request(state.configuration, resolvedPath, {
|
|
201
203
|
method: "PUT",
|
|
202
204
|
data: resolvedData,
|
|
203
205
|
params: resolvedParams
|
|
204
206
|
});
|
|
205
207
|
return prepareNextState(state, response, callback);
|
|
206
208
|
} catch (e) {
|
|
207
|
-
console.error(JSON.stringify(e.body, null, 2));
|
|
208
209
|
throw e;
|
|
209
210
|
}
|
|
210
211
|
};
|
|
@@ -218,7 +219,7 @@ function patch(path, data, params = {}, callback = (s) => s) {
|
|
|
218
219
|
params
|
|
219
220
|
);
|
|
220
221
|
try {
|
|
221
|
-
const response = await request(state.configuration,
|
|
222
|
+
const response = await request(state.configuration, resolvedPath, {
|
|
222
223
|
method: "PATCH",
|
|
223
224
|
data: JSON.stringify(resolvedData),
|
|
224
225
|
params: resolvedParams,
|
|
@@ -226,7 +227,6 @@ function patch(path, data, params = {}, callback = (s) => s) {
|
|
|
226
227
|
});
|
|
227
228
|
return prepareNextState(state, response, callback);
|
|
228
229
|
} catch (e) {
|
|
229
|
-
console.error(JSON.stringify(e.body, null, 2));
|
|
230
230
|
throw e;
|
|
231
231
|
}
|
|
232
232
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-satusehat",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "OpenFn
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "OpenFn Satusehat adaptor",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"configuration-schema.json"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@openfn/language-common": "
|
|
22
|
+
"@openfn/language-common": "2.0.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"assertion-error": "2.0.0",
|
package/types/Adaptor.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
export function execute(...operations: Operations): Operation;
|
|
14
14
|
/**
|
|
15
|
-
* Make a
|
|
15
|
+
* Make a GET request to Satusehat
|
|
16
16
|
* @public
|
|
17
17
|
* @example
|
|
18
18
|
* get("Organization", {"name": "somename"})
|
|
@@ -24,7 +24,7 @@ export function execute(...operations: Operations): Operation;
|
|
|
24
24
|
*/
|
|
25
25
|
export function get(path: string, params?: object, callback?: Function): Operation;
|
|
26
26
|
/**
|
|
27
|
-
* Make a
|
|
27
|
+
* Make a POST request to Satusehat
|
|
28
28
|
* @example
|
|
29
29
|
* post(
|
|
30
30
|
* "Organization",
|
|
@@ -32,6 +32,7 @@ export function get(path: string, params?: object, callback?: Function): Operati
|
|
|
32
32
|
* }
|
|
33
33
|
* );
|
|
34
34
|
* @function
|
|
35
|
+
* @public
|
|
35
36
|
* @param {string} path - Path to resource
|
|
36
37
|
* @param {object} data - Object or JSON which defines data that will be used to create a given instance of resource
|
|
37
38
|
* @param {Object} params - Optional request params.
|
|
@@ -40,7 +41,7 @@ export function get(path: string, params?: object, callback?: Function): Operati
|
|
|
40
41
|
*/
|
|
41
42
|
export function post(path: string, data: object, params?: any, callback?: Function): Operation;
|
|
42
43
|
/**
|
|
43
|
-
* Make a
|
|
44
|
+
* Make a PUT request to Satusehat
|
|
44
45
|
* @example
|
|
45
46
|
* put(
|
|
46
47
|
* "Organization/123",
|
|
@@ -48,6 +49,7 @@ export function post(path: string, data: object, params?: any, callback?: Functi
|
|
|
48
49
|
* }
|
|
49
50
|
* );
|
|
50
51
|
* @function
|
|
52
|
+
* @public
|
|
51
53
|
* @param {string} path - Path to resource and exact item to be updated
|
|
52
54
|
* @param {object} data - Object or JSON which defines data that will be used to update a given instance of resource
|
|
53
55
|
* @param {Object} params - Optional request params.
|
|
@@ -56,7 +58,7 @@ export function post(path: string, data: object, params?: any, callback?: Functi
|
|
|
56
58
|
*/
|
|
57
59
|
export function put(path: string, data: object, params?: any, callback?: Function): Operation;
|
|
58
60
|
/**
|
|
59
|
-
* Make a
|
|
61
|
+
* Make a PATCH request to Satusehat
|
|
60
62
|
* @example
|
|
61
63
|
* patch(
|
|
62
64
|
* "Organization/123",
|
|
@@ -68,6 +70,7 @@ export function put(path: string, data: object, params?: any, callback?: Functio
|
|
|
68
70
|
*
|
|
69
71
|
* );
|
|
70
72
|
* @function
|
|
73
|
+
* @public
|
|
71
74
|
* @param {string} path - Path to resource and exact item to be partially updated
|
|
72
75
|
* @param {Array} data - An array of objects which defines data that will be used to partially update a given instance of resource
|
|
73
76
|
* @param {Object} params - Optional request params.
|