@openfn/language-lamisplus 0.1.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,45 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "properties": {
4
+ "baseUrl": {
5
+ "title": "Base URL",
6
+ "anyOf": [
7
+ {
8
+ "type": "string"
9
+ },
10
+ {
11
+ "type": "null"
12
+ }
13
+ ],
14
+ "description": "The base URL (http://www.example.com)",
15
+ "format": "uri",
16
+ "minLength": 1,
17
+ "examples": [
18
+ "https://example.com"
19
+ ]
20
+ },
21
+ "email": {
22
+ "title": "Email",
23
+ "type": "string",
24
+ "description": "Email",
25
+ "examples": [
26
+ "test@openfn.org"
27
+ ]
28
+ },
29
+ "password": {
30
+ "title": "Password",
31
+ "type": "string",
32
+ "description": "Password",
33
+ "writeOnly": true,
34
+ "examples": [
35
+ "@some(!)Str0ngp4ss0w0rd"
36
+ ]
37
+ }
38
+ },
39
+ "type": "object",
40
+ "additionalProperties": true,
41
+ "required": [
42
+ "password",
43
+ "email"
44
+ ]
45
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,257 @@
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
+ as: () => import_language_common3.as,
29
+ combine: () => import_language_common3.combine,
30
+ cursor: () => import_language_common3.cursor,
31
+ dataPath: () => import_language_common3.dataPath,
32
+ dataValue: () => import_language_common3.dataValue,
33
+ dateFns: () => import_language_common3.dateFns,
34
+ default: () => src_default,
35
+ each: () => import_language_common3.each,
36
+ execute: () => execute,
37
+ field: () => import_language_common3.field,
38
+ fields: () => import_language_common3.fields,
39
+ fn: () => import_language_common3.fn,
40
+ fnIf: () => import_language_common3.fnIf,
41
+ getPatients: () => getPatients,
42
+ group: () => import_language_common3.group,
43
+ http: () => http_exports,
44
+ lastReferenceValue: () => import_language_common3.lastReferenceValue,
45
+ map: () => import_language_common3.map,
46
+ merge: () => import_language_common3.merge,
47
+ scrubEmojis: () => import_language_common3.scrubEmojis,
48
+ sourceValue: () => import_language_common3.sourceValue,
49
+ util: () => import_language_common3.util
50
+ });
51
+ module.exports = __toCommonJS(src_exports);
52
+
53
+ // src/Adaptor.js
54
+ var Adaptor_exports = {};
55
+ __export(Adaptor_exports, {
56
+ as: () => import_language_common3.as,
57
+ combine: () => import_language_common3.combine,
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,
63
+ execute: () => execute,
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
+ getPatients: () => getPatients,
69
+ group: () => import_language_common3.group,
70
+ lastReferenceValue: () => import_language_common3.lastReferenceValue,
71
+ map: () => import_language_common3.map,
72
+ merge: () => import_language_common3.merge,
73
+ scrubEmojis: () => import_language_common3.scrubEmojis,
74
+ sourceValue: () => import_language_common3.sourceValue,
75
+ util: () => import_language_common3.util
76
+ });
77
+ var import_language_common2 = require("@openfn/language-common");
78
+ var import_util2 = require("@openfn/language-common/util");
79
+
80
+ // src/Utils.js
81
+ var import_language_common = require("@openfn/language-common");
82
+ var import_util = require("@openfn/language-common/util");
83
+ var import_node_path = __toESM(require("path"), 1);
84
+ var prepareNextState = (state, response) => {
85
+ const { body, ...responseWithoutBody } = response;
86
+ if (!state.references) {
87
+ state.references = [];
88
+ }
89
+ return {
90
+ ...(0, import_language_common.composeNextState)(state, response.body),
91
+ response: responseWithoutBody
92
+ };
93
+ };
94
+ async function login(state) {
95
+ const { configuration = {} } = state;
96
+ const { baseUrl, password, email } = configuration;
97
+ const url = `${baseUrl}/`;
98
+ const body = {
99
+ email,
100
+ password
101
+ };
102
+ const headers = {
103
+ "content-type": "application/json"
104
+ };
105
+ const response = await request(
106
+ state.configuration,
107
+ "POST",
108
+ "core/api/v1/auth/login",
109
+ { headers, body }
110
+ );
111
+ const auth = { Authorization: `Bearer ${response.body.accessToken}` };
112
+ return { ...state, configuration: { ...configuration, auth } };
113
+ }
114
+ var request = (configuration = {}, method, path, options) => {
115
+ const { auth, baseUrl } = configuration;
116
+ const headers = typeof auth === "object" && !!auth.Authorization ? { ...auth } : {};
117
+ const errors = {
118
+ 404: "Page not found"
119
+ };
120
+ const opts = {
121
+ parseAs: "json",
122
+ errors,
123
+ baseUrl,
124
+ ...options,
125
+ headers: {
126
+ "content-type": "application/json",
127
+ ...headers
128
+ }
129
+ };
130
+ const safePath = import_node_path.default.join(path);
131
+ return (0, import_util.request)(method, safePath, opts);
132
+ };
133
+
134
+ // src/Adaptor.js
135
+ var import_language_common3 = require("@openfn/language-common");
136
+ function execute(...operations) {
137
+ const initialState = {
138
+ references: [],
139
+ data: null
140
+ };
141
+ return (state) => {
142
+ var _a, _b;
143
+ const shouldAuth = ((_a = state == null ? void 0 : state.configuration) == null ? void 0 : _a.email) && ((_b = state == null ? void 0 : state.configuration) == null ? void 0 : _b.password);
144
+ if (shouldAuth) {
145
+ operations.splice(0, 0, login);
146
+ }
147
+ return (0, import_language_common2.execute)(...operations)({
148
+ ...initialState,
149
+ ...state
150
+ });
151
+ };
152
+ }
153
+ function getPatients(query = {}) {
154
+ return async (state) => {
155
+ const [resolvedQuery] = (0, import_util2.expandReferences)(state, query);
156
+ const response = await request(
157
+ state.configuration,
158
+ "GET",
159
+ "plugin/ehr/api/v1/patient",
160
+ {
161
+ query: resolvedQuery
162
+ }
163
+ );
164
+ const { body, statusCode } = response;
165
+ if (statusCode !== "200") {
166
+ }
167
+ return (0, import_language_common2.composeNextState)(state, body.data.patients);
168
+ };
169
+ }
170
+
171
+ // src/http.js
172
+ var http_exports = {};
173
+ __export(http_exports, {
174
+ get: () => get,
175
+ post: () => post,
176
+ request: () => request2
177
+ });
178
+ var import_util3 = require("@openfn/language-common/util");
179
+ function get(path, options) {
180
+ return async (state) => {
181
+ const [resolvedPath, resolvedOptions = {}] = (0, import_util3.expandReferences)(
182
+ state,
183
+ path,
184
+ options
185
+ );
186
+ const response = await request(
187
+ state.configuration,
188
+ "GET",
189
+ resolvedPath,
190
+ resolvedOptions
191
+ );
192
+ return prepareNextState(state, response);
193
+ };
194
+ }
195
+ function post(path, data, options) {
196
+ return async (state) => {
197
+ const [resolvedPath, resolvedData, resolvedOptions = {}] = (0, import_util3.expandReferences)(
198
+ state,
199
+ path,
200
+ data,
201
+ options
202
+ );
203
+ const optionsObject = {
204
+ data: resolvedData,
205
+ ...resolvedOptions
206
+ };
207
+ const response = await request(
208
+ state.configuration,
209
+ "POST",
210
+ resolvedPath,
211
+ optionsObject
212
+ );
213
+ return prepareNextState(state, response);
214
+ };
215
+ }
216
+ function request2(method, path, body, options = {}) {
217
+ return async (state) => {
218
+ const [resolvedMethod, resolvedPath, resolvedBody, resolvedoptions] = (0, import_util3.expandReferences)(state, method, path, body, options);
219
+ const response = await request(
220
+ state.configuration,
221
+ resolvedMethod,
222
+ resolvedPath,
223
+ {
224
+ body: resolvedBody,
225
+ ...resolvedoptions
226
+ }
227
+ );
228
+ return prepareNextState(state, response);
229
+ };
230
+ }
231
+
232
+ // src/index.js
233
+ var src_default = Adaptor_exports;
234
+ // Annotate the CommonJS export names for ESM import in node:
235
+ 0 && (module.exports = {
236
+ as,
237
+ combine,
238
+ cursor,
239
+ dataPath,
240
+ dataValue,
241
+ dateFns,
242
+ each,
243
+ execute,
244
+ field,
245
+ fields,
246
+ fn,
247
+ fnIf,
248
+ getPatients,
249
+ group,
250
+ http,
251
+ lastReferenceValue,
252
+ map,
253
+ merge,
254
+ scrubEmojis,
255
+ sourceValue,
256
+ util
257
+ });
package/dist/index.js ADDED
@@ -0,0 +1,233 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/Adaptor.js
8
+ var Adaptor_exports = {};
9
+ __export(Adaptor_exports, {
10
+ as: () => as,
11
+ combine: () => combine,
12
+ cursor: () => cursor,
13
+ dataPath: () => dataPath,
14
+ dataValue: () => dataValue,
15
+ dateFns: () => dateFns,
16
+ each: () => each,
17
+ execute: () => execute,
18
+ field: () => field,
19
+ fields: () => fields,
20
+ fn: () => fn,
21
+ fnIf: () => fnIf,
22
+ getPatients: () => getPatients,
23
+ group: () => group,
24
+ lastReferenceValue: () => lastReferenceValue,
25
+ map: () => map,
26
+ merge: () => merge,
27
+ scrubEmojis: () => scrubEmojis,
28
+ sourceValue: () => sourceValue,
29
+ util: () => util
30
+ });
31
+ import {
32
+ execute as commonExecute,
33
+ composeNextState as composeNextState2
34
+ } from "@openfn/language-common";
35
+ import { expandReferences } from "@openfn/language-common/util";
36
+
37
+ // src/Utils.js
38
+ import { composeNextState } from "@openfn/language-common";
39
+ import { request as commonRequest } from "@openfn/language-common/util";
40
+ import nodepath from "path";
41
+ var prepareNextState = (state, response) => {
42
+ const { body, ...responseWithoutBody } = response;
43
+ if (!state.references) {
44
+ state.references = [];
45
+ }
46
+ return {
47
+ ...composeNextState(state, response.body),
48
+ response: responseWithoutBody
49
+ };
50
+ };
51
+ async function login(state) {
52
+ const { configuration = {} } = state;
53
+ const { baseUrl, password, email } = configuration;
54
+ const url = `${baseUrl}/`;
55
+ const body = {
56
+ email,
57
+ password
58
+ };
59
+ const headers = {
60
+ "content-type": "application/json"
61
+ };
62
+ const response = await request(
63
+ state.configuration,
64
+ "POST",
65
+ "core/api/v1/auth/login",
66
+ { headers, body }
67
+ );
68
+ const auth = { Authorization: `Bearer ${response.body.accessToken}` };
69
+ return { ...state, configuration: { ...configuration, auth } };
70
+ }
71
+ var request = (configuration = {}, method, path, options) => {
72
+ const { auth, baseUrl } = configuration;
73
+ const headers = typeof auth === "object" && !!auth.Authorization ? { ...auth } : {};
74
+ const errors = {
75
+ 404: "Page not found"
76
+ };
77
+ const opts = {
78
+ parseAs: "json",
79
+ errors,
80
+ baseUrl,
81
+ ...options,
82
+ headers: {
83
+ "content-type": "application/json",
84
+ ...headers
85
+ }
86
+ };
87
+ const safePath = nodepath.join(path);
88
+ return commonRequest(method, safePath, opts);
89
+ };
90
+
91
+ // src/Adaptor.js
92
+ import {
93
+ as,
94
+ combine,
95
+ cursor,
96
+ dataPath,
97
+ dataValue,
98
+ dateFns,
99
+ each,
100
+ field,
101
+ fields,
102
+ fn,
103
+ fnIf,
104
+ group,
105
+ lastReferenceValue,
106
+ map,
107
+ merge,
108
+ scrubEmojis,
109
+ sourceValue,
110
+ util
111
+ } from "@openfn/language-common";
112
+ function execute(...operations) {
113
+ const initialState = {
114
+ references: [],
115
+ data: null
116
+ };
117
+ return (state) => {
118
+ var _a, _b;
119
+ const shouldAuth = ((_a = state == null ? void 0 : state.configuration) == null ? void 0 : _a.email) && ((_b = state == null ? void 0 : state.configuration) == null ? void 0 : _b.password);
120
+ if (shouldAuth) {
121
+ operations.splice(0, 0, login);
122
+ }
123
+ return commonExecute(...operations)({
124
+ ...initialState,
125
+ ...state
126
+ });
127
+ };
128
+ }
129
+ function getPatients(query = {}) {
130
+ return async (state) => {
131
+ const [resolvedQuery] = expandReferences(state, query);
132
+ const response = await request(
133
+ state.configuration,
134
+ "GET",
135
+ "plugin/ehr/api/v1/patient",
136
+ {
137
+ query: resolvedQuery
138
+ }
139
+ );
140
+ const { body, statusCode } = response;
141
+ if (statusCode !== "200") {
142
+ }
143
+ return composeNextState2(state, body.data.patients);
144
+ };
145
+ }
146
+
147
+ // src/http.js
148
+ var http_exports = {};
149
+ __export(http_exports, {
150
+ get: () => get,
151
+ post: () => post,
152
+ request: () => request2
153
+ });
154
+ import { expandReferences as expandReferences2 } from "@openfn/language-common/util";
155
+ function get(path, options) {
156
+ return async (state) => {
157
+ const [resolvedPath, resolvedOptions = {}] = expandReferences2(
158
+ state,
159
+ path,
160
+ options
161
+ );
162
+ const response = await request(
163
+ state.configuration,
164
+ "GET",
165
+ resolvedPath,
166
+ resolvedOptions
167
+ );
168
+ return prepareNextState(state, response);
169
+ };
170
+ }
171
+ function post(path, data, options) {
172
+ return async (state) => {
173
+ const [resolvedPath, resolvedData, resolvedOptions = {}] = expandReferences2(
174
+ state,
175
+ path,
176
+ data,
177
+ options
178
+ );
179
+ const optionsObject = {
180
+ data: resolvedData,
181
+ ...resolvedOptions
182
+ };
183
+ const response = await request(
184
+ state.configuration,
185
+ "POST",
186
+ resolvedPath,
187
+ optionsObject
188
+ );
189
+ return prepareNextState(state, response);
190
+ };
191
+ }
192
+ function request2(method, path, body, options = {}) {
193
+ return async (state) => {
194
+ const [resolvedMethod, resolvedPath, resolvedBody, resolvedoptions] = expandReferences2(state, method, path, body, options);
195
+ const response = await request(
196
+ state.configuration,
197
+ resolvedMethod,
198
+ resolvedPath,
199
+ {
200
+ body: resolvedBody,
201
+ ...resolvedoptions
202
+ }
203
+ );
204
+ return prepareNextState(state, response);
205
+ };
206
+ }
207
+
208
+ // src/index.js
209
+ var src_default = Adaptor_exports;
210
+ export {
211
+ as,
212
+ combine,
213
+ cursor,
214
+ dataPath,
215
+ dataValue,
216
+ dateFns,
217
+ src_default as default,
218
+ each,
219
+ execute,
220
+ field,
221
+ fields,
222
+ fn,
223
+ fnIf,
224
+ getPatients,
225
+ group,
226
+ http_exports as http,
227
+ lastReferenceValue,
228
+ map,
229
+ merge,
230
+ scrubEmojis,
231
+ sourceValue,
232
+ util
233
+ };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@openfn/language-lamisplus",
3
+ "version": "0.1.0",
4
+ "description": "OpenFn lamisplus adaptor",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "types": "./types/index.d.ts",
10
+ "require": "./dist/index.cjs"
11
+ },
12
+ "./package.json": "./package.json"
13
+ },
14
+ "author": "Open Function Group",
15
+ "license": "LGPLv3",
16
+ "files": [
17
+ "dist/",
18
+ "types/",
19
+ "ast.json",
20
+ "configuration-schema.json"
21
+ ],
22
+ "dependencies": {
23
+ "@openfn/language-common": "3.2.3"
24
+ },
25
+ "devDependencies": {
26
+ "assertion-error": "2.0.0",
27
+ "chai": "4.3.6",
28
+ "deep-eql": "4.1.1",
29
+ "mocha": "^10.7.3",
30
+ "rimraf": "3.0.2",
31
+ "undici": "^5.22.1"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/openfn/adaptors.git"
36
+ },
37
+ "types": "types/index.d.ts",
38
+ "main": "dist/index.cjs",
39
+ "scripts": {
40
+ "build": "pnpm clean && build-adaptor lamisplus",
41
+ "test": "mocha --experimental-specifier-resolution=node --no-warnings",
42
+ "test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings",
43
+ "clean": "rimraf dist types docs",
44
+ "pack": "pnpm pack --pack-destination ../../dist",
45
+ "lint": "eslint src"
46
+ }
47
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * State object
3
+ * @typedef {Object} HttpState
4
+ * @property data - the parsed response body
5
+ * @property response - the response from the HTTP server, including headers, statusCode, body, etc
6
+ * @property references - an array of all previous data objects used in the Job
7
+ **/
8
+ /**
9
+ * Options provided to the HTTP request
10
+ * @typedef {Object} RequestOptions
11
+ * @public
12
+ * @property {object|string} body - body data to append to the request. JSON will be converted to a string (but a content-type header will not be attached to the request).
13
+ * @property {object} errors - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors for this code.
14
+ * @property {object} form - Pass a JSON object to be serialised into a multipart HTML form (as FormData) in the body.
15
+ * @property {object} query - An object of query parameters to be encoded into the URL.
16
+ * @property {object} headers - An object of headers to append to the request.
17
+ * @property {string} parseAs - Parse the response body as json, text or stream. By default will use the response headers.
18
+ * @property {number} timeout - Request timeout in ms. Default: 300 seconds.
19
+ * @property {object} tls - TLS/SSL authentication options. See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions
20
+ */
21
+ /**
22
+ * Execute a sequence of operations.
23
+ * Wraps `language-common/execute`, and prepends initial state for http.
24
+ * @private
25
+ * @param {Operations} operations - Operations to be performed.
26
+ * @returns {Operation}
27
+ */
28
+ export function execute(...operations: Operations): Operation;
29
+ /**
30
+ * Get Patient resources from LAMISPlus
31
+ * @public
32
+ * @example Get all patients
33
+ * getPatients()
34
+ * @example Get a single patient
35
+ * getPatients({ size: 1})
36
+ * @function
37
+ * @param {string} query - Query params, eg size, page
38
+ * @returns {Operation}
39
+ */
40
+ export function getPatients(query?: string): Operation;
41
+ /**
42
+ * State object
43
+ */
44
+ export type HttpState = {
45
+ /**
46
+ * - the parsed response body
47
+ */
48
+ data: any;
49
+ /**
50
+ * - the response from the HTTP server, including headers, statusCode, body, etc
51
+ */
52
+ response: any;
53
+ /**
54
+ * - an array of all previous data objects used in the Job
55
+ */
56
+ references: any;
57
+ };
58
+ /**
59
+ * Options provided to the HTTP request
60
+ */
61
+ export type RequestOptions = any;
62
+ export { as, combine, cursor, dataPath, dataValue, dateFns, each, field, fields, fn, fnIf, group, lastReferenceValue, map, merge, scrubEmojis, sourceValue, util } from "@openfn/language-common";
@@ -0,0 +1,3 @@
1
+ export function login(state: any): Promise<any>;
2
+ export function prepareNextState(state: any, response: any): any;
3
+ export function request(configuration: {}, method: any, path: any, options: any): any;
@@ -0,0 +1,33 @@
1
+ export function get(path: any, options: any): (state: any) => Promise<any>;
2
+ /**
3
+ * Make a POST request to a LAMISPlus endpoint
4
+ * @public
5
+ * @function
6
+ * @example <caption>Create a patient</caption>
7
+ * http.post(
8
+ * '/plugin/ehr/api/v1/patient/',
9
+ * {
10
+ * name: 'John doe',
11
+ * },
12
+ * );
13
+ * @param {string} path - path to resource
14
+ * @param {any} data - the body data in JSON format
15
+ * @param {HTTPRequestOptions} [options={}] - An object containing query params and headers for the request
16
+ * @state {HttpState}
17
+ * @returns {operation}
18
+ */
19
+ export function post(path: string, data: any, options?: HTTPRequestOptions): operation;
20
+ /**
21
+ * Make a general HTTP request
22
+ * @example
23
+ * request("POST", "patient", { "name": "Bukayo" });
24
+ * @function
25
+ * @public
26
+ * @param {string} method - HTTP method to use
27
+ * @param {string} path - Path to resource
28
+ * @param {object} body - Object which will be attached to the POST body
29
+ * @param {RequestOptions} options - Optional request options
30
+ * @returns {Operation}
31
+ * @state {HttpState}
32
+ */
33
+ export function request(method: string, path: string, body: object, options?: RequestOptions): Operation;
@@ -0,0 +1,4 @@
1
+ export default Adaptor;
2
+ export * from "./Adaptor";
3
+ export * as http from "./http.js";
4
+ import * as Adaptor from "./Adaptor";