@openfn/language-ihris 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.
@@ -0,0 +1,36 @@
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 of the iHRIS FHIR server",
15
+ "format": "uri",
16
+ "minLength": 1,
17
+ "examples": ["https://ihris.example.com"]
18
+ },
19
+ "username": {
20
+ "title": "Username",
21
+ "type": "string",
22
+ "description": "Username for basic authentication",
23
+ "examples": ["ihris_user"]
24
+ },
25
+ "password": {
26
+ "title": "Password",
27
+ "type": "string",
28
+ "description": "Password for basic authentication",
29
+ "writeOnly": true,
30
+ "examples": ["@some(!)Str0ngp4ss0w0rd"]
31
+ }
32
+ },
33
+ "type": "object",
34
+ "additionalProperties": true,
35
+ "required": ["baseUrl", "username", "password"]
36
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,241 @@
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_common.as,
29
+ b: () => import_language_fhir_4.b,
30
+ builders: () => import_language_fhir_4.builders,
31
+ combine: () => import_language_common.combine,
32
+ cursor: () => import_language_common.cursor,
33
+ dataPath: () => import_language_common.dataPath,
34
+ dataValue: () => import_language_common.dataValue,
35
+ dateFns: () => import_language_common.dateFns,
36
+ default: () => src_default,
37
+ each: () => import_language_common.each,
38
+ field: () => import_language_common.field,
39
+ fields: () => import_language_common.fields,
40
+ fn: () => import_language_common.fn,
41
+ fnIf: () => import_language_common.fnIf,
42
+ group: () => import_language_common.group,
43
+ http: () => http_exports,
44
+ lastReferenceValue: () => import_language_common.lastReferenceValue,
45
+ map: () => import_language_common.map,
46
+ merge: () => import_language_common.merge,
47
+ scrubEmojis: () => import_language_common.scrubEmojis,
48
+ sourceValue: () => import_language_common.sourceValue,
49
+ util: () => import_language_common.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_common.as,
57
+ b: () => import_language_fhir_4.b,
58
+ builders: () => import_language_fhir_4.builders,
59
+ combine: () => import_language_common.combine,
60
+ cursor: () => import_language_common.cursor,
61
+ dataPath: () => import_language_common.dataPath,
62
+ dataValue: () => import_language_common.dataValue,
63
+ dateFns: () => import_language_common.dateFns,
64
+ each: () => import_language_common.each,
65
+ field: () => import_language_common.field,
66
+ fields: () => import_language_common.fields,
67
+ fn: () => import_language_common.fn,
68
+ fnIf: () => import_language_common.fnIf,
69
+ group: () => import_language_common.group,
70
+ lastReferenceValue: () => import_language_common.lastReferenceValue,
71
+ map: () => import_language_common.map,
72
+ merge: () => import_language_common.merge,
73
+ scrubEmojis: () => import_language_common.scrubEmojis,
74
+ sourceValue: () => import_language_common.sourceValue,
75
+ util: () => import_language_common.util
76
+ });
77
+ var import_language_common = require("@openfn/language-common");
78
+ var import_language_fhir_4 = require("@openfn/language-fhir-4");
79
+
80
+ // src/http.js
81
+ var http_exports = {};
82
+ __export(http_exports, {
83
+ get: () => get,
84
+ post: () => post,
85
+ put: () => put,
86
+ request: () => request2
87
+ });
88
+ var import_util2 = require("@openfn/language-common/util");
89
+
90
+ // src/Utils.js
91
+ var import_language_common2 = require("@openfn/language-common");
92
+ var import_util = require("@openfn/language-common/util");
93
+ var import_node_path = __toESM(require("path"), 1);
94
+ var cookie;
95
+ var prepareNextState = (state, response) => {
96
+ const { body, ...responseWithoutBody } = response;
97
+ if (!state.references) {
98
+ state.references = [];
99
+ }
100
+ return {
101
+ ...(0, import_language_common2.composeNextState)(state, body),
102
+ response: responseWithoutBody
103
+ };
104
+ };
105
+ var authorize = async (configuration) => {
106
+ const { username, password, baseUrl } = configuration;
107
+ const options = {
108
+ body: JSON.stringify({ username, password }),
109
+ headers: {
110
+ "Content-Type": "application/json"
111
+ },
112
+ method: "POST",
113
+ baseUrl,
114
+ parseAs: "json"
115
+ };
116
+ try {
117
+ const response = await (0, import_util.request)("POST", "/auth/login", options);
118
+ if (response.headers["set-cookie"]) {
119
+ return response.headers["set-cookie"].split(";")[0];
120
+ }
121
+ throw new Error("No authentication cookie received from server");
122
+ } catch (err) {
123
+ console.error("Error authenticating with iHRIS");
124
+ console.log(err.body);
125
+ throw err;
126
+ }
127
+ };
128
+ var request = async (configuration = {}, method, path, options = {}) => {
129
+ var _a;
130
+ const { baseUrl, username, password } = configuration;
131
+ const { headers = {}, parseAs = "json", ...otherOptions } = options;
132
+ let authHeaders = {};
133
+ let cookieHeader = { "Cookie": ((_a = options.headers) == null ? void 0 : _a.Cookie) || cookie };
134
+ authHeaders = cookieHeader;
135
+ const opts = {
136
+ parseAs,
137
+ baseUrl,
138
+ ...otherOptions,
139
+ headers: {
140
+ "content-type": "application/fhir+json",
141
+ ...authHeaders,
142
+ ...headers
143
+ }
144
+ };
145
+ const safePath = import_node_path.default.join(path);
146
+ if (!opts.headers.Cookie && !cookie && username && password) {
147
+ cookie = await authorize(configuration);
148
+ opts.headers.Cookie = cookie;
149
+ }
150
+ return (0, import_util.request)(method, safePath, opts).then(import_util.logResponse);
151
+ };
152
+
153
+ // src/http.js
154
+ function get(resource, options = {}) {
155
+ return async (state) => {
156
+ const [resolvedResource, resolvedOptions] = (0, import_util2.expandReferences)(
157
+ state,
158
+ resource,
159
+ options
160
+ );
161
+ const response = await request(
162
+ state.configuration,
163
+ "GET",
164
+ resolvedResource,
165
+ resolvedOptions
166
+ );
167
+ return prepareNextState(state, response);
168
+ };
169
+ }
170
+ function post(resource, body, options = {}) {
171
+ return async (state) => {
172
+ const [resolvedResource, resolvedBody, resolvedOptions] = (0, import_util2.expandReferences)(state, resource, body, options);
173
+ const response = await request(
174
+ state.configuration,
175
+ "POST",
176
+ resolvedResource,
177
+ {
178
+ body: resolvedBody,
179
+ ...resolvedOptions
180
+ }
181
+ );
182
+ return prepareNextState(state, response);
183
+ };
184
+ }
185
+ function put(resource, body, options = {}) {
186
+ return async (state) => {
187
+ const [resolvedResource, resolvedBody, resolvedOptions] = (0, import_util2.expandReferences)(state, resource, body, options);
188
+ const response = await request(
189
+ state.configuration,
190
+ "PUT",
191
+ resolvedResource,
192
+ {
193
+ body: resolvedBody,
194
+ ...resolvedOptions
195
+ }
196
+ );
197
+ return prepareNextState(state, response);
198
+ };
199
+ }
200
+ function request2(method, path, body, options = {}) {
201
+ return async (state) => {
202
+ const [resolvedMethod, resolvedPath, resolvedBody, resolvedOptions] = (0, import_util2.expandReferences)(state, method, path, body, options);
203
+ const response = await request(
204
+ state.configuration,
205
+ resolvedMethod,
206
+ resolvedPath,
207
+ {
208
+ body: resolvedBody,
209
+ ...resolvedOptions
210
+ }
211
+ );
212
+ return prepareNextState(state, response);
213
+ };
214
+ }
215
+
216
+ // src/index.js
217
+ var src_default = Adaptor_exports;
218
+ // Annotate the CommonJS export names for ESM import in node:
219
+ 0 && (module.exports = {
220
+ as,
221
+ b,
222
+ builders,
223
+ combine,
224
+ cursor,
225
+ dataPath,
226
+ dataValue,
227
+ dateFns,
228
+ each,
229
+ field,
230
+ fields,
231
+ fn,
232
+ fnIf,
233
+ group,
234
+ http,
235
+ lastReferenceValue,
236
+ map,
237
+ merge,
238
+ scrubEmojis,
239
+ sourceValue,
240
+ util
241
+ });
package/dist/index.js ADDED
@@ -0,0 +1,217 @@
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
+ b: () => b,
12
+ builders: () => builders,
13
+ combine: () => combine,
14
+ cursor: () => cursor,
15
+ dataPath: () => dataPath,
16
+ dataValue: () => dataValue,
17
+ dateFns: () => dateFns,
18
+ each: () => each,
19
+ field: () => field,
20
+ fields: () => fields,
21
+ fn: () => fn,
22
+ fnIf: () => fnIf,
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
+ as,
33
+ combine,
34
+ cursor,
35
+ dataPath,
36
+ dataValue,
37
+ dateFns,
38
+ each,
39
+ field,
40
+ fields,
41
+ fn,
42
+ fnIf,
43
+ group,
44
+ lastReferenceValue,
45
+ map,
46
+ merge,
47
+ scrubEmojis,
48
+ sourceValue,
49
+ util
50
+ } from "@openfn/language-common";
51
+ import { builders, b } from "@openfn/language-fhir-4";
52
+
53
+ // src/http.js
54
+ var http_exports = {};
55
+ __export(http_exports, {
56
+ get: () => get,
57
+ post: () => post,
58
+ put: () => put,
59
+ request: () => request2
60
+ });
61
+ import { expandReferences } from "@openfn/language-common/util";
62
+
63
+ // src/Utils.js
64
+ import { composeNextState } from "@openfn/language-common";
65
+ import {
66
+ request as commonRequest,
67
+ logResponse
68
+ } from "@openfn/language-common/util";
69
+ import nodepath from "path";
70
+ var cookie;
71
+ var prepareNextState = (state, response) => {
72
+ const { body, ...responseWithoutBody } = response;
73
+ if (!state.references) {
74
+ state.references = [];
75
+ }
76
+ return {
77
+ ...composeNextState(state, body),
78
+ response: responseWithoutBody
79
+ };
80
+ };
81
+ var authorize = async (configuration) => {
82
+ const { username, password, baseUrl } = configuration;
83
+ const options = {
84
+ body: JSON.stringify({ username, password }),
85
+ headers: {
86
+ "Content-Type": "application/json"
87
+ },
88
+ method: "POST",
89
+ baseUrl,
90
+ parseAs: "json"
91
+ };
92
+ try {
93
+ const response = await commonRequest("POST", "/auth/login", options);
94
+ if (response.headers["set-cookie"]) {
95
+ return response.headers["set-cookie"].split(";")[0];
96
+ }
97
+ throw new Error("No authentication cookie received from server");
98
+ } catch (err) {
99
+ console.error("Error authenticating with iHRIS");
100
+ console.log(err.body);
101
+ throw err;
102
+ }
103
+ };
104
+ var request = async (configuration = {}, method, path, options = {}) => {
105
+ var _a;
106
+ const { baseUrl, username, password } = configuration;
107
+ const { headers = {}, parseAs = "json", ...otherOptions } = options;
108
+ let authHeaders = {};
109
+ let cookieHeader = { "Cookie": ((_a = options.headers) == null ? void 0 : _a.Cookie) || cookie };
110
+ authHeaders = cookieHeader;
111
+ const opts = {
112
+ parseAs,
113
+ baseUrl,
114
+ ...otherOptions,
115
+ headers: {
116
+ "content-type": "application/fhir+json",
117
+ ...authHeaders,
118
+ ...headers
119
+ }
120
+ };
121
+ const safePath = nodepath.join(path);
122
+ if (!opts.headers.Cookie && !cookie && username && password) {
123
+ cookie = await authorize(configuration);
124
+ opts.headers.Cookie = cookie;
125
+ }
126
+ return commonRequest(method, safePath, opts).then(logResponse);
127
+ };
128
+
129
+ // src/http.js
130
+ function get(resource, options = {}) {
131
+ return async (state) => {
132
+ const [resolvedResource, resolvedOptions] = expandReferences(
133
+ state,
134
+ resource,
135
+ options
136
+ );
137
+ const response = await request(
138
+ state.configuration,
139
+ "GET",
140
+ resolvedResource,
141
+ resolvedOptions
142
+ );
143
+ return prepareNextState(state, response);
144
+ };
145
+ }
146
+ function post(resource, body, options = {}) {
147
+ return async (state) => {
148
+ const [resolvedResource, resolvedBody, resolvedOptions] = expandReferences(state, resource, body, options);
149
+ const response = await request(
150
+ state.configuration,
151
+ "POST",
152
+ resolvedResource,
153
+ {
154
+ body: resolvedBody,
155
+ ...resolvedOptions
156
+ }
157
+ );
158
+ return prepareNextState(state, response);
159
+ };
160
+ }
161
+ function put(resource, body, options = {}) {
162
+ return async (state) => {
163
+ const [resolvedResource, resolvedBody, resolvedOptions] = expandReferences(state, resource, body, options);
164
+ const response = await request(
165
+ state.configuration,
166
+ "PUT",
167
+ resolvedResource,
168
+ {
169
+ body: resolvedBody,
170
+ ...resolvedOptions
171
+ }
172
+ );
173
+ return prepareNextState(state, response);
174
+ };
175
+ }
176
+ function request2(method, path, body, options = {}) {
177
+ return async (state) => {
178
+ const [resolvedMethod, resolvedPath, resolvedBody, resolvedOptions] = expandReferences(state, method, path, body, options);
179
+ const response = await request(
180
+ state.configuration,
181
+ resolvedMethod,
182
+ resolvedPath,
183
+ {
184
+ body: resolvedBody,
185
+ ...resolvedOptions
186
+ }
187
+ );
188
+ return prepareNextState(state, response);
189
+ };
190
+ }
191
+
192
+ // src/index.js
193
+ var src_default = Adaptor_exports;
194
+ export {
195
+ as,
196
+ b,
197
+ builders,
198
+ combine,
199
+ cursor,
200
+ dataPath,
201
+ dataValue,
202
+ dateFns,
203
+ src_default as default,
204
+ each,
205
+ field,
206
+ fields,
207
+ fn,
208
+ fnIf,
209
+ group,
210
+ http_exports as http,
211
+ lastReferenceValue,
212
+ map,
213
+ merge,
214
+ scrubEmojis,
215
+ sourceValue,
216
+ util
217
+ };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@openfn/language-ihris",
3
+ "version": "1.0.0",
4
+ "description": "OpenFn adaptor for iHRIS ",
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.1.2",
24
+ "@openfn/language-fhir-4": "0.2.2"
25
+ },
26
+ "devDependencies": {
27
+ "assertion-error": "2.0.0",
28
+ "chai": "4.3.6",
29
+ "deep-eql": "4.1.1",
30
+ "mocha": "^10.7.3",
31
+ "rimraf": "3.0.2",
32
+ "undici": "^5.22.1"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/openfn/adaptors.git"
37
+ },
38
+ "types": "types/index.d.ts",
39
+ "main": "dist/index.cjs",
40
+ "scripts": {
41
+ "build": "pnpm clean && build-adaptor ihris",
42
+ "test": "mocha --experimental-specifier-resolution=node --no-warnings",
43
+ "test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings",
44
+ "clean": "rimraf dist types docs",
45
+ "pack": "pnpm pack --pack-destination ../../dist",
46
+ "lint": "eslint src"
47
+ }
48
+ }
@@ -0,0 +1,2 @@
1
+ export { as, combine, cursor, dataPath, dataValue, dateFns, each, field, fields, fn, fnIf, group, lastReferenceValue, map, merge, scrubEmojis, sourceValue, util } from "@openfn/language-common";
2
+ export { builders, b } from "@openfn/language-fhir-4";
@@ -0,0 +1,3 @@
1
+ export function prepareNextState(state: any, response: any): any;
2
+ export function authorize(configuration: any): Promise<any>;
3
+ export function request(configuration: {}, method: any, path: any, options?: {}): Promise<any>;