@openfn/language-openhim 0.3.16 → 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/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,261 @@ 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
- dataPath: () => import_language_common2.dataPath,
29
- dataValue: () => import_language_common2.dataValue,
22
+ as: () => import_language_common3.as,
23
+ createChannel: () => createChannel,
24
+ createClient: () => createClient,
25
+ createEncounter: () => createEncounter,
26
+ createTask: () => createTask,
27
+ cursor: () => import_language_common3.cursor,
28
+ dataPath: () => import_language_common3.dataPath,
29
+ dataValue: () => import_language_common3.dataValue,
30
+ dateFns: () => import_language_common3.dateFns,
30
31
  default: () => src_default,
31
- encounter: () => encounter,
32
+ each: () => import_language_common3.each,
32
33
  execute: () => execute,
33
- field: () => import_language_common2.field,
34
- fields: () => import_language_common2.fields,
35
- fn: () => import_language_common2.fn,
36
- fnIf: () => import_language_common2.fnIf,
37
- lastReferenceValue: () => import_language_common2.lastReferenceValue,
38
- merge: () => import_language_common2.merge,
39
- sourceValue: () => import_language_common2.sourceValue
34
+ field: () => import_language_common3.field,
35
+ fields: () => import_language_common3.fields,
36
+ fn: () => import_language_common3.fn,
37
+ fnIf: () => import_language_common3.fnIf,
38
+ getChannels: () => getChannels,
39
+ getClients: () => getClients,
40
+ getTasks: () => getTasks,
41
+ getTransactions: () => getTransactions,
42
+ http: () => http_exports,
43
+ lastReferenceValue: () => import_language_common3.lastReferenceValue,
44
+ map: () => import_language_common3.map,
45
+ merge: () => import_language_common3.merge,
46
+ sourceValue: () => import_language_common3.sourceValue
40
47
  });
41
48
  module.exports = __toCommonJS(src_exports);
42
49
 
43
50
  // src/Adaptor.js
44
51
  var Adaptor_exports = {};
45
52
  __export(Adaptor_exports, {
46
- dataPath: () => import_language_common2.dataPath,
47
- dataValue: () => import_language_common2.dataValue,
48
- encounter: () => encounter,
53
+ as: () => import_language_common3.as,
54
+ createChannel: () => createChannel,
55
+ createClient: () => createClient,
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: () => import_language_common2.field,
51
- fields: () => import_language_common2.fields,
52
- fn: () => import_language_common2.fn,
53
- fnIf: () => import_language_common2.fnIf,
54
- lastReferenceValue: () => import_language_common2.lastReferenceValue,
55
- merge: () => import_language_common2.merge,
56
- sourceValue: () => import_language_common2.sourceValue
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
+ sourceValue: () => import_language_common3.sourceValue
57
76
  });
77
+ var import_language_common2 = require("@openfn/language-common");
78
+ var import_util2 = require("@openfn/language-common/util");
79
+
80
+ // src/Util.js
58
81
  var import_language_common = require("@openfn/language-common");
59
82
  var import_util = require("@openfn/language-common/util");
60
-
61
- // src/Client.js
62
- var import_superagent = __toESM(require("superagent"), 1);
63
- function post({ username, password, body, url }) {
64
- return new Promise((resolve, reject) => {
65
- import_superagent.default.post(url).type("json").accept("json").auth(username, password).send(JSON.stringify(body)).end((error, res) => {
66
- if (!!error || !res.ok) {
67
- reject(error);
68
- }
69
- resolve(res);
70
- });
71
- });
72
- }
83
+ var prepareNextState = (state, response) => {
84
+ const { body, ...responseWithoutBody } = response;
85
+ if (!state.references) {
86
+ state.references = [];
87
+ }
88
+ return {
89
+ ...(0, import_language_common.composeNextState)(state, body),
90
+ response: responseWithoutBody
91
+ };
92
+ };
93
+ var request = async (configuration = {}, method, path, options) => {
94
+ const { apiUrl, username, password } = configuration;
95
+ const { query = {}, body = {}, headers = {}, parseAs = "json" } = options;
96
+ const authHeaders = (0, import_util.makeBasicAuthHeader)(username, password);
97
+ const opts = {
98
+ parseAs,
99
+ baseUrl: `${apiUrl}`,
100
+ body,
101
+ query,
102
+ headers: {
103
+ "content-type": "application/json",
104
+ ...headers,
105
+ ...authHeaders
106
+ },
107
+ ...options
108
+ };
109
+ return (0, import_util.request)(method, path, opts).then(import_util.logResponse);
110
+ };
73
111
 
74
112
  // src/Adaptor.js
75
- var import_url = require("url");
76
- var import_language_common2 = require("@openfn/language-common");
113
+ var import_language_common3 = require("@openfn/language-common");
77
114
  function execute(...operations) {
78
115
  const initialState = {
79
116
  references: [],
80
117
  data: null
81
118
  };
82
119
  return (state) => {
83
- return (0, import_language_common.execute)(...operations)({ ...initialState, ...state });
120
+ return (0, import_language_common2.execute)(...operations)({ ...initialState, ...state });
84
121
  };
85
122
  }
86
- function encounter(encounterData) {
87
- return (state) => {
88
- const [body] = (0, import_util.expandReferences)(state, encounterData);
89
- const { username, password, apiUrl } = state.configuration;
90
- const url = (0, import_url.resolve)(apiUrl + "/", "chw/encounter");
91
- console.log("Posting encounter:");
92
- console.log(JSON.stringify(body, null, 2));
93
- return post({ username, password, body, url }).then((result) => {
94
- console.log("Success:", result);
95
- return { ...state, references: [result, ...state.references] };
123
+ function createEncounter(encounterData) {
124
+ return async (state) => {
125
+ const [body] = (0, import_util2.expandReferences)(state, encounterData);
126
+ const response = await request(
127
+ state.configuration,
128
+ "POST",
129
+ "/chw/encounter",
130
+ {
131
+ body,
132
+ parseAs: "text"
133
+ }
134
+ );
135
+ return prepareNextState(state, response);
136
+ };
137
+ }
138
+ function getTransactions(options = {}) {
139
+ return async (state) => {
140
+ const [resolvedoptions] = (0, import_util2.expandReferences)(state, options);
141
+ const { transactionId } = resolvedoptions;
142
+ delete resolvedoptions.transactionId;
143
+ const response = await request(
144
+ state.configuration,
145
+ "GET",
146
+ transactionId ? `/transactions/${transactionId}` : "/transactions",
147
+ {
148
+ query: {
149
+ ...resolvedoptions
150
+ }
151
+ }
152
+ );
153
+ return prepareNextState(state, response);
154
+ };
155
+ }
156
+ function getClients(clientId) {
157
+ return async (state) => {
158
+ const [resolvedClientId] = (0, import_util2.expandReferences)(state, clientId);
159
+ const response = await request(
160
+ state.configuration,
161
+ "GET",
162
+ resolvedClientId ? `/clients/${resolvedClientId}` : "/clients",
163
+ {}
164
+ );
165
+ return prepareNextState(state, response);
166
+ };
167
+ }
168
+ function createClient(body) {
169
+ return async (state) => {
170
+ const [resolvedBody] = (0, import_util2.expandReferences)(state, body);
171
+ const response = await request(
172
+ state.configuration,
173
+ "POST",
174
+ "/clients",
175
+ {
176
+ body: resolvedBody,
177
+ parseAs: "text"
178
+ }
179
+ );
180
+ return prepareNextState(state, response);
181
+ };
182
+ }
183
+ function getChannels(channelId) {
184
+ return async (state) => {
185
+ const [resolvedChannelId] = (0, import_util2.expandReferences)(state, channelId);
186
+ const response = await request(
187
+ state.configuration,
188
+ "GET",
189
+ resolvedChannelId ? `/channels/${resolvedChannelId}` : "/channels",
190
+ {}
191
+ );
192
+ return prepareNextState(state, response);
193
+ };
194
+ }
195
+ function createChannel(body) {
196
+ return async (state) => {
197
+ const [resolvedBody] = (0, import_util2.expandReferences)(state, body);
198
+ const response = await request(
199
+ state.configuration,
200
+ "POST",
201
+ "/channels",
202
+ {
203
+ body: resolvedBody,
204
+ parseAs: "text"
205
+ }
206
+ );
207
+ return prepareNextState(state, response);
208
+ };
209
+ }
210
+ function getTasks(options) {
211
+ return async (state) => {
212
+ const [resolvedoptions] = (0, import_util2.expandReferences)(state, options);
213
+ const { taskId } = resolvedoptions;
214
+ delete resolvedoptions.taskId;
215
+ const response = await request(
216
+ state.configuration,
217
+ "GET",
218
+ taskId ? `/tasks/${taskId}` : "/tasks",
219
+ {
220
+ query: resolvedoptions
221
+ }
222
+ );
223
+ return prepareNextState(state, response);
224
+ };
225
+ }
226
+ function createTask(body) {
227
+ return async (state) => {
228
+ const [resolvedBody] = (0, import_util2.expandReferences)(state, body);
229
+ const response = await request(state.configuration, "POST", "/tasks", {
230
+ body: resolvedBody,
231
+ parseAs: "text"
96
232
  });
233
+ return prepareNextState(state, response);
234
+ };
235
+ }
236
+
237
+ // src/http.js
238
+ var http_exports = {};
239
+ __export(http_exports, {
240
+ _delete: () => _delete,
241
+ get: () => get,
242
+ post: () => post,
243
+ put: () => put,
244
+ request: () => request2
245
+ });
246
+ var import_util3 = require("@openfn/language-common/util");
247
+ function get(path, options) {
248
+ return request2("GET", path, null, options);
249
+ }
250
+ function post(path, body, options) {
251
+ return request2("POST", path, body, options);
252
+ }
253
+ function put(path, body, options) {
254
+ return request2("PUT", path, body, options);
255
+ }
256
+ function _delete(path, options) {
257
+ return request2("DELETE", path, null, options);
258
+ }
259
+ function request2(method, path, body, options = {}) {
260
+ return async (state) => {
261
+ const [resolvedMethod, resolvedPath, resolvedBody, resolvedoptions] = (0, import_util3.expandReferences)(state, method, path, body, options);
262
+ const response = await request(
263
+ state.configuration,
264
+ resolvedMethod,
265
+ resolvedPath,
266
+ {
267
+ body: resolvedBody,
268
+ ...resolvedoptions
269
+ }
270
+ );
271
+ return prepareNextState(state, response);
97
272
  };
98
273
  }
99
274
 
@@ -101,15 +276,28 @@ function encounter(encounterData) {
101
276
  var src_default = Adaptor_exports;
102
277
  // Annotate the CommonJS export names for ESM import in node:
103
278
  0 && (module.exports = {
279
+ as,
280
+ createChannel,
281
+ createClient,
282
+ createEncounter,
283
+ createTask,
284
+ cursor,
104
285
  dataPath,
105
286
  dataValue,
106
- encounter,
287
+ dateFns,
288
+ each,
107
289
  execute,
108
290
  field,
109
291
  fields,
110
292
  fn,
111
293
  fnIf,
294
+ getChannels,
295
+ getClients,
296
+ getTasks,
297
+ getTransactions,
298
+ http,
112
299
  lastReferenceValue,
300
+ map,
113
301
  merge,
114
302
  sourceValue
115
303
  });
package/dist/index.js CHANGED
@@ -7,46 +7,85 @@ 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
+ createClient: () => createClient,
13
+ createEncounter: () => createEncounter,
14
+ createTask: () => createTask,
15
+ cursor: () => cursor,
10
16
  dataPath: () => dataPath,
11
17
  dataValue: () => dataValue,
12
- encounter: () => encounter,
18
+ dateFns: () => dateFns,
19
+ each: () => each,
13
20
  execute: () => execute,
14
21
  field: () => field,
15
22
  fields: () => fields,
16
23
  fn: () => fn,
17
24
  fnIf: () => fnIf,
25
+ getChannels: () => getChannels,
26
+ getClients: () => getClients,
27
+ getTasks: () => getTasks,
28
+ getTransactions: () => getTransactions,
18
29
  lastReferenceValue: () => lastReferenceValue,
30
+ map: () => map,
19
31
  merge: () => merge,
20
32
  sourceValue: () => sourceValue
21
33
  });
22
34
  import { execute as commonExecute } from "@openfn/language-common";
23
35
  import { expandReferences } from "@openfn/language-common/util";
24
36
 
25
- // src/Client.js
26
- import request from "superagent";
27
- function post({ username, password, body, url }) {
28
- return new Promise((resolve, reject) => {
29
- request.post(url).type("json").accept("json").auth(username, password).send(JSON.stringify(body)).end((error, res) => {
30
- if (!!error || !res.ok) {
31
- reject(error);
32
- }
33
- resolve(res);
34
- });
35
- });
36
- }
37
+ // src/Util.js
38
+ import { composeNextState } from "@openfn/language-common";
39
+ import {
40
+ request as commonRequest,
41
+ logResponse,
42
+ makeBasicAuthHeader
43
+ } from "@openfn/language-common/util";
44
+ var prepareNextState = (state, response) => {
45
+ const { body, ...responseWithoutBody } = response;
46
+ if (!state.references) {
47
+ state.references = [];
48
+ }
49
+ return {
50
+ ...composeNextState(state, body),
51
+ response: responseWithoutBody
52
+ };
53
+ };
54
+ var request = async (configuration = {}, method, path, options) => {
55
+ const { apiUrl, username, password } = configuration;
56
+ const { query = {}, body = {}, headers = {}, parseAs = "json" } = options;
57
+ const authHeaders = makeBasicAuthHeader(username, password);
58
+ const opts = {
59
+ parseAs,
60
+ baseUrl: `${apiUrl}`,
61
+ body,
62
+ query,
63
+ headers: {
64
+ "content-type": "application/json",
65
+ ...headers,
66
+ ...authHeaders
67
+ },
68
+ ...options
69
+ };
70
+ return commonRequest(method, path, opts).then(logResponse);
71
+ };
37
72
 
38
73
  // src/Adaptor.js
39
- import { resolve as resolveUrl } from "url";
40
74
  import {
41
- fn,
42
75
  fnIf,
76
+ dataPath,
77
+ dataValue,
78
+ dateFns,
79
+ cursor,
80
+ each,
43
81
  field,
44
82
  fields,
45
- sourceValue,
83
+ fn,
84
+ lastReferenceValue,
46
85
  merge,
47
- dataPath,
48
- dataValue,
49
- lastReferenceValue
86
+ sourceValue,
87
+ as,
88
+ map
50
89
  } from "@openfn/language-common";
51
90
  function execute(...operations) {
52
91
  const initialState = {
@@ -57,33 +96,184 @@ function execute(...operations) {
57
96
  return commonExecute(...operations)({ ...initialState, ...state });
58
97
  };
59
98
  }
60
- function encounter(encounterData) {
61
- return (state) => {
99
+ function createEncounter(encounterData) {
100
+ return async (state) => {
62
101
  const [body] = expandReferences(state, encounterData);
63
- const { username, password, apiUrl } = state.configuration;
64
- const url = resolveUrl(apiUrl + "/", "chw/encounter");
65
- console.log("Posting encounter:");
66
- console.log(JSON.stringify(body, null, 2));
67
- return post({ username, password, body, url }).then((result) => {
68
- console.log("Success:", result);
69
- return { ...state, references: [result, ...state.references] };
102
+ const response = await request(
103
+ state.configuration,
104
+ "POST",
105
+ "/chw/encounter",
106
+ {
107
+ body,
108
+ parseAs: "text"
109
+ }
110
+ );
111
+ return prepareNextState(state, response);
112
+ };
113
+ }
114
+ function getTransactions(options = {}) {
115
+ return async (state) => {
116
+ const [resolvedoptions] = expandReferences(state, options);
117
+ const { transactionId } = resolvedoptions;
118
+ delete resolvedoptions.transactionId;
119
+ const response = await request(
120
+ state.configuration,
121
+ "GET",
122
+ transactionId ? `/transactions/${transactionId}` : "/transactions",
123
+ {
124
+ query: {
125
+ ...resolvedoptions
126
+ }
127
+ }
128
+ );
129
+ return prepareNextState(state, response);
130
+ };
131
+ }
132
+ function getClients(clientId) {
133
+ return async (state) => {
134
+ const [resolvedClientId] = expandReferences(state, clientId);
135
+ const response = await request(
136
+ state.configuration,
137
+ "GET",
138
+ resolvedClientId ? `/clients/${resolvedClientId}` : "/clients",
139
+ {}
140
+ );
141
+ return prepareNextState(state, response);
142
+ };
143
+ }
144
+ function createClient(body) {
145
+ return async (state) => {
146
+ const [resolvedBody] = expandReferences(state, body);
147
+ const response = await request(
148
+ state.configuration,
149
+ "POST",
150
+ "/clients",
151
+ {
152
+ body: resolvedBody,
153
+ parseAs: "text"
154
+ }
155
+ );
156
+ return prepareNextState(state, response);
157
+ };
158
+ }
159
+ function getChannels(channelId) {
160
+ return async (state) => {
161
+ const [resolvedChannelId] = expandReferences(state, channelId);
162
+ const response = await request(
163
+ state.configuration,
164
+ "GET",
165
+ resolvedChannelId ? `/channels/${resolvedChannelId}` : "/channels",
166
+ {}
167
+ );
168
+ return prepareNextState(state, response);
169
+ };
170
+ }
171
+ function createChannel(body) {
172
+ return async (state) => {
173
+ const [resolvedBody] = expandReferences(state, body);
174
+ const response = await request(
175
+ state.configuration,
176
+ "POST",
177
+ "/channels",
178
+ {
179
+ body: resolvedBody,
180
+ parseAs: "text"
181
+ }
182
+ );
183
+ return prepareNextState(state, response);
184
+ };
185
+ }
186
+ function getTasks(options) {
187
+ return async (state) => {
188
+ const [resolvedoptions] = expandReferences(state, options);
189
+ const { taskId } = resolvedoptions;
190
+ delete resolvedoptions.taskId;
191
+ const response = await request(
192
+ state.configuration,
193
+ "GET",
194
+ taskId ? `/tasks/${taskId}` : "/tasks",
195
+ {
196
+ query: resolvedoptions
197
+ }
198
+ );
199
+ return prepareNextState(state, response);
200
+ };
201
+ }
202
+ function createTask(body) {
203
+ return async (state) => {
204
+ const [resolvedBody] = expandReferences(state, body);
205
+ const response = await request(state.configuration, "POST", "/tasks", {
206
+ body: resolvedBody,
207
+ parseAs: "text"
70
208
  });
209
+ return prepareNextState(state, response);
210
+ };
211
+ }
212
+
213
+ // src/http.js
214
+ var http_exports = {};
215
+ __export(http_exports, {
216
+ _delete: () => _delete,
217
+ get: () => get,
218
+ post: () => post,
219
+ put: () => put,
220
+ request: () => request2
221
+ });
222
+ import { expandReferences as expandReferences2 } from "@openfn/language-common/util";
223
+ function get(path, options) {
224
+ return request2("GET", path, null, options);
225
+ }
226
+ function post(path, body, options) {
227
+ return request2("POST", path, body, options);
228
+ }
229
+ function put(path, body, options) {
230
+ return request2("PUT", path, body, options);
231
+ }
232
+ function _delete(path, options) {
233
+ return request2("DELETE", path, null, options);
234
+ }
235
+ function request2(method, path, body, options = {}) {
236
+ return async (state) => {
237
+ const [resolvedMethod, resolvedPath, resolvedBody, resolvedoptions] = expandReferences2(state, method, path, body, options);
238
+ const response = await request(
239
+ state.configuration,
240
+ resolvedMethod,
241
+ resolvedPath,
242
+ {
243
+ body: resolvedBody,
244
+ ...resolvedoptions
245
+ }
246
+ );
247
+ return prepareNextState(state, response);
71
248
  };
72
249
  }
73
250
 
74
251
  // src/index.js
75
252
  var src_default = Adaptor_exports;
76
253
  export {
254
+ as,
255
+ createChannel,
256
+ createClient,
257
+ createEncounter,
258
+ createTask,
259
+ cursor,
77
260
  dataPath,
78
261
  dataValue,
262
+ dateFns,
79
263
  src_default as default,
80
- encounter,
264
+ each,
81
265
  execute,
82
266
  field,
83
267
  fields,
84
268
  fn,
85
269
  fnIf,
270
+ getChannels,
271
+ getClients,
272
+ getTasks,
273
+ getTransactions,
274
+ http_exports as http,
86
275
  lastReferenceValue,
276
+ map,
87
277
  merge,
88
278
  sourceValue
89
279
  };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@openfn/language-openhim",
3
3
  "label": "OpenHIM",
4
- "version": "0.3.16",
5
- "description": "openhim Language Pack for OpenFn",
4
+ "version": "2.0.0",
5
+ "description": "OpenFn adaptor for OpenHIM",
6
6
  "main": "dist/index.cjs",
7
7
  "author": "Open Function Group",
8
8
  "license": "LGPLv3",
@@ -14,21 +14,20 @@
14
14
  ],
15
15
  "dependencies": {
16
16
  "JSONPath": "^0.10.0",
17
- "lodash-fp": "^0.10.2",
18
- "superagent": "^3.7.0",
19
- "@openfn/language-common": "3.0.1"
17
+ "lodash-fp": "^0.10.4",
18
+ "@openfn/language-common": "3.0.2"
20
19
  },
21
20
  "devDependencies": {
22
- "assertion-error": "^1.0.1",
21
+ "assertion-error": "^1.1.0",
23
22
  "babel-cli": "^6.26.0",
24
- "babel-core": "^6.1.2",
25
- "babel-preset-es2015": "^6.1.2",
26
- "babel-preset-stage-0": "^6.3.13",
27
- "chai": "^3.4.0",
23
+ "babel-core": "^6.26.3",
24
+ "babel-preset-es2015": "^6.24.1",
25
+ "babel-preset-stage-0": "^6.24.1",
26
+ "chai": "4.3.6",
28
27
  "deep-eql": "^0.1.3",
28
+ "mocha": "^10.8.2",
29
29
  "rimraf": "^3.0.2",
30
- "sinon": "^1.17.2",
31
- "superagent-mock": "^1.10.0"
30
+ "sinon": "^1.17.7"
32
31
  },
33
32
  "repository": {
34
33
  "type": "git",