@openfn/language-openhim 0.3.15 → 1.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 +680 -1
- package/dist/index.cjs +261 -54
- package/dist/index.js +239 -31
- package/package.json +11 -12
- package/types/Adaptor.d.ts +201 -4
- package/types/Util.d.ts +2 -0
- package/types/http.d.ts +139 -0
- package/types/index.d.ts +1 -0
- package/types/Client.d.ts +0 -6
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
5
|
var __export = (target, all) => {
|
|
8
6
|
for (var name in all)
|
|
@@ -16,84 +14,279 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
14
|
}
|
|
17
15
|
return to;
|
|
18
16
|
};
|
|
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
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
18
|
|
|
25
19
|
// src/index.js
|
|
26
20
|
var src_exports = {};
|
|
27
21
|
__export(src_exports, {
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
as: () => import_language_common3.as,
|
|
23
|
+
createChannel: () => createChannel,
|
|
24
|
+
createEncounter: () => createEncounter,
|
|
25
|
+
createTask: () => createTask,
|
|
26
|
+
cursor: () => import_language_common3.cursor,
|
|
27
|
+
dataPath: () => import_language_common3.dataPath,
|
|
28
|
+
dataValue: () => import_language_common3.dataValue,
|
|
29
|
+
dateFns: () => import_language_common3.dateFns,
|
|
30
30
|
default: () => src_default,
|
|
31
|
-
|
|
31
|
+
each: () => import_language_common3.each,
|
|
32
32
|
execute: () => execute,
|
|
33
|
-
field: () =>
|
|
34
|
-
fields: () =>
|
|
35
|
-
fn: () =>
|
|
36
|
-
fnIf: () =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
field: () => import_language_common3.field,
|
|
34
|
+
fields: () => import_language_common3.fields,
|
|
35
|
+
fn: () => import_language_common3.fn,
|
|
36
|
+
fnIf: () => import_language_common3.fnIf,
|
|
37
|
+
getChannels: () => getChannels,
|
|
38
|
+
getClients: () => getClients,
|
|
39
|
+
getTasks: () => getTasks,
|
|
40
|
+
getTransactions: () => getTransactions,
|
|
41
|
+
http: () => http_exports,
|
|
42
|
+
lastReferenceValue: () => import_language_common3.lastReferenceValue,
|
|
43
|
+
map: () => import_language_common3.map,
|
|
44
|
+
merge: () => import_language_common3.merge,
|
|
45
|
+
registerClient: () => registerClient,
|
|
46
|
+
sourceValue: () => import_language_common3.sourceValue,
|
|
47
|
+
updateClient: () => updateClient
|
|
40
48
|
});
|
|
41
49
|
module.exports = __toCommonJS(src_exports);
|
|
42
50
|
|
|
43
51
|
// src/Adaptor.js
|
|
44
52
|
var Adaptor_exports = {};
|
|
45
53
|
__export(Adaptor_exports, {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
as: () => import_language_common3.as,
|
|
55
|
+
createChannel: () => createChannel,
|
|
56
|
+
createEncounter: () => createEncounter,
|
|
57
|
+
createTask: () => createTask,
|
|
58
|
+
cursor: () => import_language_common3.cursor,
|
|
59
|
+
dataPath: () => import_language_common3.dataPath,
|
|
60
|
+
dataValue: () => import_language_common3.dataValue,
|
|
61
|
+
dateFns: () => import_language_common3.dateFns,
|
|
62
|
+
each: () => import_language_common3.each,
|
|
49
63
|
execute: () => execute,
|
|
50
|
-
field: () =>
|
|
51
|
-
fields: () =>
|
|
52
|
-
fn: () =>
|
|
53
|
-
fnIf: () =>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
field: () => import_language_common3.field,
|
|
65
|
+
fields: () => import_language_common3.fields,
|
|
66
|
+
fn: () => import_language_common3.fn,
|
|
67
|
+
fnIf: () => import_language_common3.fnIf,
|
|
68
|
+
getChannels: () => getChannels,
|
|
69
|
+
getClients: () => getClients,
|
|
70
|
+
getTasks: () => getTasks,
|
|
71
|
+
getTransactions: () => getTransactions,
|
|
72
|
+
lastReferenceValue: () => import_language_common3.lastReferenceValue,
|
|
73
|
+
map: () => import_language_common3.map,
|
|
74
|
+
merge: () => import_language_common3.merge,
|
|
75
|
+
registerClient: () => registerClient,
|
|
76
|
+
sourceValue: () => import_language_common3.sourceValue,
|
|
77
|
+
updateClient: () => updateClient
|
|
57
78
|
});
|
|
79
|
+
var import_language_common2 = require("@openfn/language-common");
|
|
80
|
+
var import_util2 = require("@openfn/language-common/util");
|
|
81
|
+
|
|
82
|
+
// src/Util.js
|
|
58
83
|
var import_language_common = require("@openfn/language-common");
|
|
59
84
|
var import_util = require("@openfn/language-common/util");
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
}
|
|
85
|
+
var prepareNextState = (state, response) => {
|
|
86
|
+
const { body, ...responseWithoutBody } = response;
|
|
87
|
+
if (!state.references) {
|
|
88
|
+
state.references = [];
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
...(0, import_language_common.composeNextState)(state, body),
|
|
92
|
+
response: responseWithoutBody
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
var request = async (configuration = {}, method, path, options) => {
|
|
96
|
+
const { apiUrl, username, password } = configuration;
|
|
97
|
+
const { query = {}, body = {}, headers = {}, parseAs = "json" } = options;
|
|
98
|
+
const authHeaders = (0, import_util.makeBasicAuthHeader)(username, password);
|
|
99
|
+
const opts = {
|
|
100
|
+
parseAs,
|
|
101
|
+
baseUrl: `${apiUrl}`,
|
|
102
|
+
body,
|
|
103
|
+
query,
|
|
104
|
+
headers: {
|
|
105
|
+
"content-type": "application/json",
|
|
106
|
+
...headers,
|
|
107
|
+
...authHeaders
|
|
108
|
+
},
|
|
109
|
+
...options
|
|
110
|
+
};
|
|
111
|
+
return (0, import_util.request)(method, path, opts).then(import_util.logResponse);
|
|
112
|
+
};
|
|
73
113
|
|
|
74
114
|
// src/Adaptor.js
|
|
75
|
-
var
|
|
76
|
-
var import_language_common2 = require("@openfn/language-common");
|
|
115
|
+
var import_language_common3 = require("@openfn/language-common");
|
|
77
116
|
function execute(...operations) {
|
|
78
117
|
const initialState = {
|
|
79
118
|
references: [],
|
|
80
119
|
data: null
|
|
81
120
|
};
|
|
82
121
|
return (state) => {
|
|
83
|
-
return (0,
|
|
122
|
+
return (0, import_language_common2.execute)(...operations)({ ...initialState, ...state });
|
|
84
123
|
};
|
|
85
124
|
}
|
|
86
|
-
function
|
|
87
|
-
return (state) => {
|
|
88
|
-
const [body] = (0,
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
125
|
+
function createEncounter(encounterData) {
|
|
126
|
+
return async (state) => {
|
|
127
|
+
const [body] = (0, import_util2.expandReferences)(state, encounterData);
|
|
128
|
+
const response = await request(
|
|
129
|
+
state.configuration,
|
|
130
|
+
"POST",
|
|
131
|
+
"/chw/encounter",
|
|
132
|
+
{
|
|
133
|
+
body,
|
|
134
|
+
parseAs: "text"
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
return prepareNextState(state, response);
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function getTransactions(options = {}) {
|
|
141
|
+
return async (state) => {
|
|
142
|
+
const [resolvedoptions] = (0, import_util2.expandReferences)(state, options);
|
|
143
|
+
const { transactionId } = resolvedoptions;
|
|
144
|
+
delete resolvedoptions.transactionId;
|
|
145
|
+
const response = await request(
|
|
146
|
+
state.configuration,
|
|
147
|
+
"GET",
|
|
148
|
+
transactionId ? `/transactions/${transactionId}` : "/transactions",
|
|
149
|
+
{
|
|
150
|
+
query: {
|
|
151
|
+
...resolvedoptions
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
return prepareNextState(state, response);
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function getClients(clientId) {
|
|
159
|
+
return async (state) => {
|
|
160
|
+
const [resolvedClientId] = (0, import_util2.expandReferences)(state, clientId);
|
|
161
|
+
const response = await request(
|
|
162
|
+
state.configuration,
|
|
163
|
+
"GET",
|
|
164
|
+
resolvedClientId ? `/clients/${resolvedClientId}` : "/clients",
|
|
165
|
+
{}
|
|
166
|
+
);
|
|
167
|
+
return prepareNextState(state, response);
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function registerClient(body) {
|
|
171
|
+
return async (state) => {
|
|
172
|
+
const [resolvedBody] = (0, import_util2.expandReferences)(state, body);
|
|
173
|
+
const response = await request(
|
|
174
|
+
state.configuration,
|
|
175
|
+
"POST",
|
|
176
|
+
"/clients",
|
|
177
|
+
{
|
|
178
|
+
body: resolvedBody,
|
|
179
|
+
parseAs: "text"
|
|
180
|
+
}
|
|
181
|
+
);
|
|
182
|
+
return prepareNextState(state, response);
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function updateClient(body) {
|
|
186
|
+
return async (state) => {
|
|
187
|
+
const [resolvedBody] = (0, import_util2.expandReferences)(state, body);
|
|
188
|
+
const { _id } = resolvedBody;
|
|
189
|
+
const response = await request(
|
|
190
|
+
state.configuration,
|
|
191
|
+
"PUT",
|
|
192
|
+
`/clients/${_id}`,
|
|
193
|
+
{
|
|
194
|
+
body: resolvedBody,
|
|
195
|
+
parseAs: "text"
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
return prepareNextState(state, response);
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function getChannels(channelId) {
|
|
202
|
+
return async (state) => {
|
|
203
|
+
const [resolvedChannelId] = (0, import_util2.expandReferences)(state, channelId);
|
|
204
|
+
const response = await request(
|
|
205
|
+
state.configuration,
|
|
206
|
+
"GET",
|
|
207
|
+
resolvedChannelId ? `/channels/${resolvedChannelId}` : "/channels",
|
|
208
|
+
{}
|
|
209
|
+
);
|
|
210
|
+
return prepareNextState(state, response);
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function createChannel(body) {
|
|
214
|
+
return async (state) => {
|
|
215
|
+
const [resolvedBody] = (0, import_util2.expandReferences)(state, body);
|
|
216
|
+
const response = await request(
|
|
217
|
+
state.configuration,
|
|
218
|
+
"POST",
|
|
219
|
+
"/channels",
|
|
220
|
+
{
|
|
221
|
+
body: resolvedBody,
|
|
222
|
+
parseAs: "text"
|
|
223
|
+
}
|
|
224
|
+
);
|
|
225
|
+
return prepareNextState(state, response);
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function getTasks(options) {
|
|
229
|
+
return async (state) => {
|
|
230
|
+
const [resolvedoptions] = (0, import_util2.expandReferences)(state, options);
|
|
231
|
+
const { taskId } = resolvedoptions;
|
|
232
|
+
delete resolvedoptions.taskId;
|
|
233
|
+
const response = await request(
|
|
234
|
+
state.configuration,
|
|
235
|
+
"GET",
|
|
236
|
+
taskId ? `/tasks/${taskId}` : "/tasks",
|
|
237
|
+
{
|
|
238
|
+
query: resolvedoptions
|
|
239
|
+
}
|
|
240
|
+
);
|
|
241
|
+
return prepareNextState(state, response);
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function createTask(body) {
|
|
245
|
+
return async (state) => {
|
|
246
|
+
const [resolvedBody] = (0, import_util2.expandReferences)(state, body);
|
|
247
|
+
const response = await request(state.configuration, "POST", "/tasks", {
|
|
248
|
+
body: resolvedBody,
|
|
249
|
+
parseAs: "text"
|
|
96
250
|
});
|
|
251
|
+
return prepareNextState(state, response);
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/http.js
|
|
256
|
+
var http_exports = {};
|
|
257
|
+
__export(http_exports, {
|
|
258
|
+
_delete: () => _delete,
|
|
259
|
+
get: () => get,
|
|
260
|
+
post: () => post,
|
|
261
|
+
put: () => put,
|
|
262
|
+
request: () => request2
|
|
263
|
+
});
|
|
264
|
+
var import_util3 = require("@openfn/language-common/util");
|
|
265
|
+
function get(path, options) {
|
|
266
|
+
return request2("GET", path, null, options);
|
|
267
|
+
}
|
|
268
|
+
function post(path, body, options) {
|
|
269
|
+
return request2("POST", path, body, options);
|
|
270
|
+
}
|
|
271
|
+
function put(path, body, options) {
|
|
272
|
+
return request2("PUT", path, body, options);
|
|
273
|
+
}
|
|
274
|
+
function _delete(path, options) {
|
|
275
|
+
return request2("DELETE", path, null, options);
|
|
276
|
+
}
|
|
277
|
+
function request2(method, path, body, options = {}) {
|
|
278
|
+
return async (state) => {
|
|
279
|
+
const [resolvedMethod, resolvedPath, resolvedBody, resolvedoptions] = (0, import_util3.expandReferences)(state, method, path, body, options);
|
|
280
|
+
const response = await request(
|
|
281
|
+
state.configuration,
|
|
282
|
+
resolvedMethod,
|
|
283
|
+
resolvedPath,
|
|
284
|
+
{
|
|
285
|
+
body: resolvedBody,
|
|
286
|
+
...resolvedoptions
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
return prepareNextState(state, response);
|
|
97
290
|
};
|
|
98
291
|
}
|
|
99
292
|
|
|
@@ -101,15 +294,29 @@ function encounter(encounterData) {
|
|
|
101
294
|
var src_default = Adaptor_exports;
|
|
102
295
|
// Annotate the CommonJS export names for ESM import in node:
|
|
103
296
|
0 && (module.exports = {
|
|
297
|
+
as,
|
|
298
|
+
createChannel,
|
|
299
|
+
createEncounter,
|
|
300
|
+
createTask,
|
|
301
|
+
cursor,
|
|
104
302
|
dataPath,
|
|
105
303
|
dataValue,
|
|
106
|
-
|
|
304
|
+
dateFns,
|
|
305
|
+
each,
|
|
107
306
|
execute,
|
|
108
307
|
field,
|
|
109
308
|
fields,
|
|
110
309
|
fn,
|
|
111
310
|
fnIf,
|
|
311
|
+
getChannels,
|
|
312
|
+
getClients,
|
|
313
|
+
getTasks,
|
|
314
|
+
getTransactions,
|
|
315
|
+
http,
|
|
112
316
|
lastReferenceValue,
|
|
317
|
+
map,
|
|
113
318
|
merge,
|
|
114
|
-
|
|
319
|
+
registerClient,
|
|
320
|
+
sourceValue,
|
|
321
|
+
updateClient
|
|
115
322
|
});
|
package/dist/index.js
CHANGED
|
@@ -7,46 +7,86 @@ var __export = (target, all) => {
|
|
|
7
7
|
// src/Adaptor.js
|
|
8
8
|
var Adaptor_exports = {};
|
|
9
9
|
__export(Adaptor_exports, {
|
|
10
|
+
as: () => as,
|
|
11
|
+
createChannel: () => createChannel,
|
|
12
|
+
createEncounter: () => createEncounter,
|
|
13
|
+
createTask: () => createTask,
|
|
14
|
+
cursor: () => cursor,
|
|
10
15
|
dataPath: () => dataPath,
|
|
11
16
|
dataValue: () => dataValue,
|
|
12
|
-
|
|
17
|
+
dateFns: () => dateFns,
|
|
18
|
+
each: () => each,
|
|
13
19
|
execute: () => execute,
|
|
14
20
|
field: () => field,
|
|
15
21
|
fields: () => fields,
|
|
16
22
|
fn: () => fn,
|
|
17
23
|
fnIf: () => fnIf,
|
|
24
|
+
getChannels: () => getChannels,
|
|
25
|
+
getClients: () => getClients,
|
|
26
|
+
getTasks: () => getTasks,
|
|
27
|
+
getTransactions: () => getTransactions,
|
|
18
28
|
lastReferenceValue: () => lastReferenceValue,
|
|
29
|
+
map: () => map,
|
|
19
30
|
merge: () => merge,
|
|
20
|
-
|
|
31
|
+
registerClient: () => registerClient,
|
|
32
|
+
sourceValue: () => sourceValue,
|
|
33
|
+
updateClient: () => updateClient
|
|
21
34
|
});
|
|
22
35
|
import { execute as commonExecute } from "@openfn/language-common";
|
|
23
36
|
import { expandReferences } from "@openfn/language-common/util";
|
|
24
37
|
|
|
25
|
-
// src/
|
|
26
|
-
import
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
38
|
+
// src/Util.js
|
|
39
|
+
import { composeNextState } from "@openfn/language-common";
|
|
40
|
+
import {
|
|
41
|
+
request as commonRequest,
|
|
42
|
+
logResponse,
|
|
43
|
+
makeBasicAuthHeader
|
|
44
|
+
} from "@openfn/language-common/util";
|
|
45
|
+
var prepareNextState = (state, response) => {
|
|
46
|
+
const { body, ...responseWithoutBody } = response;
|
|
47
|
+
if (!state.references) {
|
|
48
|
+
state.references = [];
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
...composeNextState(state, body),
|
|
52
|
+
response: responseWithoutBody
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
var request = async (configuration = {}, method, path, options) => {
|
|
56
|
+
const { apiUrl, username, password } = configuration;
|
|
57
|
+
const { query = {}, body = {}, headers = {}, parseAs = "json" } = options;
|
|
58
|
+
const authHeaders = makeBasicAuthHeader(username, password);
|
|
59
|
+
const opts = {
|
|
60
|
+
parseAs,
|
|
61
|
+
baseUrl: `${apiUrl}`,
|
|
62
|
+
body,
|
|
63
|
+
query,
|
|
64
|
+
headers: {
|
|
65
|
+
"content-type": "application/json",
|
|
66
|
+
...headers,
|
|
67
|
+
...authHeaders
|
|
68
|
+
},
|
|
69
|
+
...options
|
|
70
|
+
};
|
|
71
|
+
return commonRequest(method, path, opts).then(logResponse);
|
|
72
|
+
};
|
|
37
73
|
|
|
38
74
|
// src/Adaptor.js
|
|
39
|
-
import { resolve as resolveUrl } from "url";
|
|
40
75
|
import {
|
|
41
|
-
fn,
|
|
42
76
|
fnIf,
|
|
77
|
+
dataPath,
|
|
78
|
+
dataValue,
|
|
79
|
+
dateFns,
|
|
80
|
+
cursor,
|
|
81
|
+
each,
|
|
43
82
|
field,
|
|
44
83
|
fields,
|
|
45
|
-
|
|
84
|
+
fn,
|
|
85
|
+
lastReferenceValue,
|
|
46
86
|
merge,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
87
|
+
sourceValue,
|
|
88
|
+
as,
|
|
89
|
+
map
|
|
50
90
|
} from "@openfn/language-common";
|
|
51
91
|
function execute(...operations) {
|
|
52
92
|
const initialState = {
|
|
@@ -57,33 +97,201 @@ function execute(...operations) {
|
|
|
57
97
|
return commonExecute(...operations)({ ...initialState, ...state });
|
|
58
98
|
};
|
|
59
99
|
}
|
|
60
|
-
function
|
|
61
|
-
return (state) => {
|
|
100
|
+
function createEncounter(encounterData) {
|
|
101
|
+
return async (state) => {
|
|
62
102
|
const [body] = expandReferences(state, encounterData);
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
103
|
+
const response = await request(
|
|
104
|
+
state.configuration,
|
|
105
|
+
"POST",
|
|
106
|
+
"/chw/encounter",
|
|
107
|
+
{
|
|
108
|
+
body,
|
|
109
|
+
parseAs: "text"
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
return prepareNextState(state, response);
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function getTransactions(options = {}) {
|
|
116
|
+
return async (state) => {
|
|
117
|
+
const [resolvedoptions] = expandReferences(state, options);
|
|
118
|
+
const { transactionId } = resolvedoptions;
|
|
119
|
+
delete resolvedoptions.transactionId;
|
|
120
|
+
const response = await request(
|
|
121
|
+
state.configuration,
|
|
122
|
+
"GET",
|
|
123
|
+
transactionId ? `/transactions/${transactionId}` : "/transactions",
|
|
124
|
+
{
|
|
125
|
+
query: {
|
|
126
|
+
...resolvedoptions
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
return prepareNextState(state, response);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function getClients(clientId) {
|
|
134
|
+
return async (state) => {
|
|
135
|
+
const [resolvedClientId] = expandReferences(state, clientId);
|
|
136
|
+
const response = await request(
|
|
137
|
+
state.configuration,
|
|
138
|
+
"GET",
|
|
139
|
+
resolvedClientId ? `/clients/${resolvedClientId}` : "/clients",
|
|
140
|
+
{}
|
|
141
|
+
);
|
|
142
|
+
return prepareNextState(state, response);
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function registerClient(body) {
|
|
146
|
+
return async (state) => {
|
|
147
|
+
const [resolvedBody] = expandReferences(state, body);
|
|
148
|
+
const response = await request(
|
|
149
|
+
state.configuration,
|
|
150
|
+
"POST",
|
|
151
|
+
"/clients",
|
|
152
|
+
{
|
|
153
|
+
body: resolvedBody,
|
|
154
|
+
parseAs: "text"
|
|
155
|
+
}
|
|
156
|
+
);
|
|
157
|
+
return prepareNextState(state, response);
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function updateClient(body) {
|
|
161
|
+
return async (state) => {
|
|
162
|
+
const [resolvedBody] = expandReferences(state, body);
|
|
163
|
+
const { _id } = resolvedBody;
|
|
164
|
+
const response = await request(
|
|
165
|
+
state.configuration,
|
|
166
|
+
"PUT",
|
|
167
|
+
`/clients/${_id}`,
|
|
168
|
+
{
|
|
169
|
+
body: resolvedBody,
|
|
170
|
+
parseAs: "text"
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
return prepareNextState(state, response);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function getChannels(channelId) {
|
|
177
|
+
return async (state) => {
|
|
178
|
+
const [resolvedChannelId] = expandReferences(state, channelId);
|
|
179
|
+
const response = await request(
|
|
180
|
+
state.configuration,
|
|
181
|
+
"GET",
|
|
182
|
+
resolvedChannelId ? `/channels/${resolvedChannelId}` : "/channels",
|
|
183
|
+
{}
|
|
184
|
+
);
|
|
185
|
+
return prepareNextState(state, response);
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function createChannel(body) {
|
|
189
|
+
return async (state) => {
|
|
190
|
+
const [resolvedBody] = expandReferences(state, body);
|
|
191
|
+
const response = await request(
|
|
192
|
+
state.configuration,
|
|
193
|
+
"POST",
|
|
194
|
+
"/channels",
|
|
195
|
+
{
|
|
196
|
+
body: resolvedBody,
|
|
197
|
+
parseAs: "text"
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
return prepareNextState(state, response);
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function getTasks(options) {
|
|
204
|
+
return async (state) => {
|
|
205
|
+
const [resolvedoptions] = expandReferences(state, options);
|
|
206
|
+
const { taskId } = resolvedoptions;
|
|
207
|
+
delete resolvedoptions.taskId;
|
|
208
|
+
const response = await request(
|
|
209
|
+
state.configuration,
|
|
210
|
+
"GET",
|
|
211
|
+
taskId ? `/tasks/${taskId}` : "/tasks",
|
|
212
|
+
{
|
|
213
|
+
query: resolvedoptions
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
return prepareNextState(state, response);
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function createTask(body) {
|
|
220
|
+
return async (state) => {
|
|
221
|
+
const [resolvedBody] = expandReferences(state, body);
|
|
222
|
+
const response = await request(state.configuration, "POST", "/tasks", {
|
|
223
|
+
body: resolvedBody,
|
|
224
|
+
parseAs: "text"
|
|
70
225
|
});
|
|
226
|
+
return prepareNextState(state, response);
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// src/http.js
|
|
231
|
+
var http_exports = {};
|
|
232
|
+
__export(http_exports, {
|
|
233
|
+
_delete: () => _delete,
|
|
234
|
+
get: () => get,
|
|
235
|
+
post: () => post,
|
|
236
|
+
put: () => put,
|
|
237
|
+
request: () => request2
|
|
238
|
+
});
|
|
239
|
+
import { expandReferences as expandReferences2 } from "@openfn/language-common/util";
|
|
240
|
+
function get(path, options) {
|
|
241
|
+
return request2("GET", path, null, options);
|
|
242
|
+
}
|
|
243
|
+
function post(path, body, options) {
|
|
244
|
+
return request2("POST", path, body, options);
|
|
245
|
+
}
|
|
246
|
+
function put(path, body, options) {
|
|
247
|
+
return request2("PUT", path, body, options);
|
|
248
|
+
}
|
|
249
|
+
function _delete(path, options) {
|
|
250
|
+
return request2("DELETE", path, null, options);
|
|
251
|
+
}
|
|
252
|
+
function request2(method, path, body, options = {}) {
|
|
253
|
+
return async (state) => {
|
|
254
|
+
const [resolvedMethod, resolvedPath, resolvedBody, resolvedoptions] = expandReferences2(state, method, path, body, options);
|
|
255
|
+
const response = await request(
|
|
256
|
+
state.configuration,
|
|
257
|
+
resolvedMethod,
|
|
258
|
+
resolvedPath,
|
|
259
|
+
{
|
|
260
|
+
body: resolvedBody,
|
|
261
|
+
...resolvedoptions
|
|
262
|
+
}
|
|
263
|
+
);
|
|
264
|
+
return prepareNextState(state, response);
|
|
71
265
|
};
|
|
72
266
|
}
|
|
73
267
|
|
|
74
268
|
// src/index.js
|
|
75
269
|
var src_default = Adaptor_exports;
|
|
76
270
|
export {
|
|
271
|
+
as,
|
|
272
|
+
createChannel,
|
|
273
|
+
createEncounter,
|
|
274
|
+
createTask,
|
|
275
|
+
cursor,
|
|
77
276
|
dataPath,
|
|
78
277
|
dataValue,
|
|
278
|
+
dateFns,
|
|
79
279
|
src_default as default,
|
|
80
|
-
|
|
280
|
+
each,
|
|
81
281
|
execute,
|
|
82
282
|
field,
|
|
83
283
|
fields,
|
|
84
284
|
fn,
|
|
85
285
|
fnIf,
|
|
286
|
+
getChannels,
|
|
287
|
+
getClients,
|
|
288
|
+
getTasks,
|
|
289
|
+
getTransactions,
|
|
290
|
+
http_exports as http,
|
|
86
291
|
lastReferenceValue,
|
|
292
|
+
map,
|
|
87
293
|
merge,
|
|
88
|
-
|
|
294
|
+
registerClient,
|
|
295
|
+
sourceValue,
|
|
296
|
+
updateClient
|
|
89
297
|
};
|