@openfn/language-opencrvs 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,50 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "properties": {
4
+ "domain": {
5
+ "title": "Your Domain",
6
+ "type": "string",
7
+ "description": "OpenCRVS domain",
8
+ "format": "uri",
9
+ "minLength": 1,
10
+ "examples": [
11
+ "openfn.opencrvs.dev"
12
+ ]
13
+ },
14
+ "clientId": {
15
+ "title": "Client Id",
16
+ "type": "string",
17
+ "minLength": 1,
18
+ "description": "Your OpenCRVS client id",
19
+ "examples": [
20
+ "the-long-uuid-provided-by-opencrvs"
21
+ ]
22
+ },
23
+ "clientSecret": {
24
+ "title": "Client Secret",
25
+ "type": "string",
26
+ "description": "Client Secret",
27
+ "minLength": 1,
28
+ "examples": [
29
+ "the-long-secret-key-provided-by-opencrvs"
30
+ ]
31
+ },
32
+ "access_token": {
33
+ "title": "Access Token",
34
+ "type": "string",
35
+ "description": "Your OpenCRVS access token",
36
+ "writeOnly": true,
37
+ "minLength": 1,
38
+ "examples": [
39
+ "the-long-access-token-from-your-auth"
40
+ ]
41
+ }
42
+ },
43
+ "type": "object",
44
+ "additionalProperties": true,
45
+ "required": [
46
+ "domain",
47
+ "clientId",
48
+ "clientSecret"
49
+ ]
50
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,344 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.js
20
+ var src_exports = {};
21
+ __export(src_exports, {
22
+ builders: () => import_language_fhir_4.builders,
23
+ combine: () => import_language_common3.combine,
24
+ createBirthNotification: () => createBirthNotification,
25
+ cursor: () => import_language_common3.cursor,
26
+ dataPath: () => import_language_common3.dataPath,
27
+ dataValue: () => import_language_common3.dataValue,
28
+ dateFns: () => import_language_common3.dateFns,
29
+ default: () => src_default,
30
+ each: () => import_language_common3.each,
31
+ execute: () => execute,
32
+ field: () => import_language_common3.field,
33
+ fields: () => import_language_common3.fields,
34
+ fn: () => import_language_common3.fn,
35
+ fnIf: () => import_language_common3.fnIf,
36
+ group: () => import_language_common3.group,
37
+ http: () => http_exports,
38
+ lastReferenceValue: () => import_language_common3.lastReferenceValue,
39
+ merge: () => import_language_common3.merge,
40
+ queryEvents: () => queryEvents,
41
+ scrubEmojis: () => import_language_common3.scrubEmojis,
42
+ sourceValue: () => import_language_common3.sourceValue,
43
+ util: () => import_language_common3.util
44
+ });
45
+ module.exports = __toCommonJS(src_exports);
46
+
47
+ // src/Adaptor.js
48
+ var Adaptor_exports = {};
49
+ __export(Adaptor_exports, {
50
+ builders: () => import_language_fhir_4.builders,
51
+ combine: () => import_language_common3.combine,
52
+ createBirthNotification: () => createBirthNotification,
53
+ cursor: () => import_language_common3.cursor,
54
+ dataPath: () => import_language_common3.dataPath,
55
+ dataValue: () => import_language_common3.dataValue,
56
+ dateFns: () => import_language_common3.dateFns,
57
+ each: () => import_language_common3.each,
58
+ execute: () => execute,
59
+ field: () => import_language_common3.field,
60
+ fields: () => import_language_common3.fields,
61
+ fn: () => import_language_common3.fn,
62
+ fnIf: () => import_language_common3.fnIf,
63
+ group: () => import_language_common3.group,
64
+ lastReferenceValue: () => import_language_common3.lastReferenceValue,
65
+ merge: () => import_language_common3.merge,
66
+ queryEvents: () => queryEvents,
67
+ scrubEmojis: () => import_language_common3.scrubEmojis,
68
+ sourceValue: () => import_language_common3.sourceValue,
69
+ util: () => import_language_common3.util
70
+ });
71
+ var import_util2 = require("@openfn/language-common/util");
72
+
73
+ // src/Utils.js
74
+ var import_language_common = require("@openfn/language-common");
75
+ var import_util = require("@openfn/language-common/util");
76
+ var authorize = async (state) => {
77
+ const auth = state.configuration;
78
+ if (auth.access_token) {
79
+ return state;
80
+ }
81
+ const clientId = auth.clientId;
82
+ const clientSecret = auth.clientSecret;
83
+ const headers = {
84
+ Accept: "*/*",
85
+ "Content-type": "application/json"
86
+ };
87
+ if (clientId && clientSecret) {
88
+ const options = {
89
+ headers,
90
+ method: "POST",
91
+ parseAs: "json",
92
+ baseUrl: `https://auth.${auth.domain}`,
93
+ query: {
94
+ grant_type: "client_credentials",
95
+ client_secret: clientSecret,
96
+ client_id: clientId
97
+ }
98
+ };
99
+ return (0, import_util.request)("POST", "/token", options).then((response) => {
100
+ return {
101
+ ...state,
102
+ configuration: {
103
+ ...state.configuration,
104
+ access_token: response.body.access_token
105
+ }
106
+ };
107
+ });
108
+ } else {
109
+ throw new Error(
110
+ "Invalid authorization credentials. Include clientId and clientSecret in state.configuration"
111
+ );
112
+ }
113
+ };
114
+ var prepareNextState = (state, response, callback = (s) => s) => {
115
+ const { body, ...responseWithoutBody } = response;
116
+ const nextState = {
117
+ ...(0, import_language_common.composeNextState)(state, body),
118
+ response: responseWithoutBody
119
+ };
120
+ return callback(nextState);
121
+ };
122
+ async function request(configuration, method, path, opts) {
123
+ const { domain, access_token } = configuration;
124
+ const { body = {}, params = {}, parseAs = "json" } = opts;
125
+ (0, import_util.assertRelativeUrl)(path);
126
+ const options = {
127
+ body,
128
+ headers: {
129
+ Authorization: `Bearer ${access_token}`,
130
+ "Content-type": "application/json"
131
+ },
132
+ query: params,
133
+ parseAs,
134
+ baseUrl: `https://gateway.${domain}`
135
+ };
136
+ return (0, import_util.request)(method, path, options).then(import_util.logResponse);
137
+ }
138
+
139
+ // src/Adaptor.js
140
+ var import_language_common2 = require("@openfn/language-common");
141
+
142
+ // src/query.js
143
+ var searchEventsQuery = `
144
+ query searchEvents(
145
+ $advancedSearchParameters: AdvancedSearchParametersInput!
146
+ $sort: String
147
+ $count: Int
148
+ $skip: Int
149
+ ) {
150
+ searchEvents(
151
+ advancedSearchParameters: $advancedSearchParameters
152
+ sort: $sort
153
+ count: $count
154
+ skip: $skip
155
+ ) {
156
+ totalItems
157
+ results {
158
+ id
159
+ type
160
+ registration {
161
+ status
162
+ contactNumber
163
+ trackingId
164
+ registrationNumber
165
+ registeredLocationId
166
+ duplicates
167
+ assignment {
168
+ practitionerId
169
+ firstName
170
+ lastName
171
+ officeName
172
+ __typename
173
+ }
174
+ createdAt
175
+ modifiedAt
176
+ __typename
177
+ }
178
+ operationHistories {
179
+ operationType
180
+ operatedOn
181
+ operatorRole
182
+ operatorName {
183
+ firstNames
184
+ familyName
185
+ use
186
+ __typename
187
+ }
188
+ operatorOfficeName
189
+ operatorOfficeAlias
190
+ notificationFacilityName
191
+ notificationFacilityAlias
192
+ rejectReason
193
+ rejectComment
194
+ __typename
195
+ }
196
+ ... on BirthEventSearchSet {
197
+ dateOfBirth
198
+ childName {
199
+ firstNames
200
+ familyName
201
+ use
202
+ __typename
203
+ }
204
+ __typename
205
+ }
206
+ ... on DeathEventSearchSet {
207
+ dateOfDeath
208
+ deceasedName {
209
+ firstNames
210
+ familyName
211
+ use
212
+ __typename
213
+ }
214
+ __typename
215
+ }
216
+ __typename
217
+ }
218
+ __typename
219
+ }
220
+ }
221
+ `;
222
+
223
+ // src/Adaptor.js
224
+ var import_language_common3 = require("@openfn/language-common");
225
+ var import_language_fhir_4 = require("@openfn/language-fhir-4");
226
+ function execute(...operations) {
227
+ const initialState = {
228
+ references: [],
229
+ data: null
230
+ };
231
+ return (state) => {
232
+ return (0, import_language_common2.execute)(
233
+ authorize,
234
+ ...operations
235
+ )({
236
+ ...initialState,
237
+ ...state
238
+ });
239
+ };
240
+ }
241
+ function createBirthNotification(body) {
242
+ return async (state) => {
243
+ const [resolvedBody] = (0, import_util2.expandReferences)(state, body);
244
+ const response = await request(
245
+ state.configuration,
246
+ "POST",
247
+ "/notification",
248
+ {
249
+ body: {
250
+ resourceType: "Bundle",
251
+ type: "document",
252
+ meta: {
253
+ lastUpdated: new Date().toISOString()
254
+ },
255
+ entry: resolvedBody
256
+ }
257
+ }
258
+ );
259
+ return prepareNextState(state, response);
260
+ };
261
+ }
262
+ function queryEvents(variables, options = {}) {
263
+ return async (state) => {
264
+ var _a, _b, _c, _d;
265
+ const [resolvedVariables, resolvedOptions] = (0, import_util2.expandReferences)(
266
+ state,
267
+ variables,
268
+ options
269
+ );
270
+ const response = await request(
271
+ state.configuration,
272
+ "POST",
273
+ "/graphql",
274
+ {
275
+ body: {
276
+ operationName: "searchEvents",
277
+ query: searchEventsQuery,
278
+ variables: { advancedSearchParameters: resolvedVariables },
279
+ count: resolvedOptions.count || 10,
280
+ skip: resolvedOptions.skip,
281
+ ...resolvedOptions
282
+ }
283
+ }
284
+ );
285
+ const body = ((_a = response.body) == null ? void 0 : _a.errors) ? response.body : (_d = (_c = (_b = response.body) == null ? void 0 : _b.data) == null ? void 0 : _c.searchEvents) == null ? void 0 : _d.results;
286
+ return prepareNextState(state, {
287
+ ...response,
288
+ body
289
+ });
290
+ };
291
+ }
292
+
293
+ // src/http.js
294
+ var http_exports = {};
295
+ __export(http_exports, {
296
+ post: () => post,
297
+ request: () => request2
298
+ });
299
+ var import_util3 = require("@openfn/language-common/util");
300
+ function post(path, body, options) {
301
+ return request2("POST", path, body, options);
302
+ }
303
+ function request2(method, path, body, options = {}) {
304
+ return async (state) => {
305
+ const [resolvedMethod, resolvedPath, resolvedBody, resolvedoptions] = (0, import_util3.expandReferences)(state, method, path, body, options);
306
+ const response = await request(
307
+ state.configuration,
308
+ resolvedMethod,
309
+ resolvedPath,
310
+ {
311
+ body: resolvedBody,
312
+ ...resolvedoptions
313
+ }
314
+ );
315
+ return prepareNextState(state, response);
316
+ };
317
+ }
318
+
319
+ // src/index.js
320
+ var src_default = Adaptor_exports;
321
+ // Annotate the CommonJS export names for ESM import in node:
322
+ 0 && (module.exports = {
323
+ builders,
324
+ combine,
325
+ createBirthNotification,
326
+ cursor,
327
+ dataPath,
328
+ dataValue,
329
+ dateFns,
330
+ each,
331
+ execute,
332
+ field,
333
+ fields,
334
+ fn,
335
+ fnIf,
336
+ group,
337
+ http,
338
+ lastReferenceValue,
339
+ merge,
340
+ queryEvents,
341
+ scrubEmojis,
342
+ sourceValue,
343
+ util
344
+ });
package/dist/index.js ADDED
@@ -0,0 +1,325 @@
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
+ builders: () => builders,
11
+ combine: () => combine,
12
+ createBirthNotification: () => createBirthNotification,
13
+ cursor: () => cursor,
14
+ dataPath: () => dataPath,
15
+ dataValue: () => dataValue,
16
+ dateFns: () => dateFns,
17
+ each: () => each,
18
+ execute: () => execute,
19
+ field: () => field,
20
+ fields: () => fields,
21
+ fn: () => fn,
22
+ fnIf: () => fnIf,
23
+ group: () => group,
24
+ lastReferenceValue: () => lastReferenceValue,
25
+ merge: () => merge,
26
+ queryEvents: () => queryEvents,
27
+ scrubEmojis: () => scrubEmojis,
28
+ sourceValue: () => sourceValue,
29
+ util: () => util
30
+ });
31
+ import { expandReferences } from "@openfn/language-common/util";
32
+
33
+ // src/Utils.js
34
+ import { composeNextState } from "@openfn/language-common";
35
+ import {
36
+ request as commonRequest,
37
+ logResponse,
38
+ assertRelativeUrl
39
+ } from "@openfn/language-common/util";
40
+ var authorize = async (state) => {
41
+ const auth = state.configuration;
42
+ if (auth.access_token) {
43
+ return state;
44
+ }
45
+ const clientId = auth.clientId;
46
+ const clientSecret = auth.clientSecret;
47
+ const headers = {
48
+ Accept: "*/*",
49
+ "Content-type": "application/json"
50
+ };
51
+ if (clientId && clientSecret) {
52
+ const options = {
53
+ headers,
54
+ method: "POST",
55
+ parseAs: "json",
56
+ baseUrl: `https://auth.${auth.domain}`,
57
+ query: {
58
+ grant_type: "client_credentials",
59
+ client_secret: clientSecret,
60
+ client_id: clientId
61
+ }
62
+ };
63
+ return commonRequest("POST", "/token", options).then((response) => {
64
+ return {
65
+ ...state,
66
+ configuration: {
67
+ ...state.configuration,
68
+ access_token: response.body.access_token
69
+ }
70
+ };
71
+ });
72
+ } else {
73
+ throw new Error(
74
+ "Invalid authorization credentials. Include clientId and clientSecret in state.configuration"
75
+ );
76
+ }
77
+ };
78
+ var prepareNextState = (state, response, callback = (s) => s) => {
79
+ const { body, ...responseWithoutBody } = response;
80
+ const nextState = {
81
+ ...composeNextState(state, body),
82
+ response: responseWithoutBody
83
+ };
84
+ return callback(nextState);
85
+ };
86
+ async function request(configuration, method, path, opts) {
87
+ const { domain, access_token } = configuration;
88
+ const { body = {}, params = {}, parseAs = "json" } = opts;
89
+ assertRelativeUrl(path);
90
+ const options = {
91
+ body,
92
+ headers: {
93
+ Authorization: `Bearer ${access_token}`,
94
+ "Content-type": "application/json"
95
+ },
96
+ query: params,
97
+ parseAs,
98
+ baseUrl: `https://gateway.${domain}`
99
+ };
100
+ return commonRequest(method, path, options).then(logResponse);
101
+ }
102
+
103
+ // src/Adaptor.js
104
+ import { execute as commonExecute } from "@openfn/language-common";
105
+
106
+ // src/query.js
107
+ var searchEventsQuery = `
108
+ query searchEvents(
109
+ $advancedSearchParameters: AdvancedSearchParametersInput!
110
+ $sort: String
111
+ $count: Int
112
+ $skip: Int
113
+ ) {
114
+ searchEvents(
115
+ advancedSearchParameters: $advancedSearchParameters
116
+ sort: $sort
117
+ count: $count
118
+ skip: $skip
119
+ ) {
120
+ totalItems
121
+ results {
122
+ id
123
+ type
124
+ registration {
125
+ status
126
+ contactNumber
127
+ trackingId
128
+ registrationNumber
129
+ registeredLocationId
130
+ duplicates
131
+ assignment {
132
+ practitionerId
133
+ firstName
134
+ lastName
135
+ officeName
136
+ __typename
137
+ }
138
+ createdAt
139
+ modifiedAt
140
+ __typename
141
+ }
142
+ operationHistories {
143
+ operationType
144
+ operatedOn
145
+ operatorRole
146
+ operatorName {
147
+ firstNames
148
+ familyName
149
+ use
150
+ __typename
151
+ }
152
+ operatorOfficeName
153
+ operatorOfficeAlias
154
+ notificationFacilityName
155
+ notificationFacilityAlias
156
+ rejectReason
157
+ rejectComment
158
+ __typename
159
+ }
160
+ ... on BirthEventSearchSet {
161
+ dateOfBirth
162
+ childName {
163
+ firstNames
164
+ familyName
165
+ use
166
+ __typename
167
+ }
168
+ __typename
169
+ }
170
+ ... on DeathEventSearchSet {
171
+ dateOfDeath
172
+ deceasedName {
173
+ firstNames
174
+ familyName
175
+ use
176
+ __typename
177
+ }
178
+ __typename
179
+ }
180
+ __typename
181
+ }
182
+ __typename
183
+ }
184
+ }
185
+ `;
186
+
187
+ // src/Adaptor.js
188
+ import {
189
+ combine,
190
+ cursor,
191
+ dataPath,
192
+ dataValue,
193
+ dateFns,
194
+ each,
195
+ field,
196
+ fields,
197
+ fn,
198
+ fnIf,
199
+ group,
200
+ lastReferenceValue,
201
+ merge,
202
+ scrubEmojis,
203
+ sourceValue,
204
+ util
205
+ } from "@openfn/language-common";
206
+ import { builders } from "@openfn/language-fhir-4";
207
+ function execute(...operations) {
208
+ const initialState = {
209
+ references: [],
210
+ data: null
211
+ };
212
+ return (state) => {
213
+ return commonExecute(
214
+ authorize,
215
+ ...operations
216
+ )({
217
+ ...initialState,
218
+ ...state
219
+ });
220
+ };
221
+ }
222
+ function createBirthNotification(body) {
223
+ return async (state) => {
224
+ const [resolvedBody] = expandReferences(state, body);
225
+ const response = await request(
226
+ state.configuration,
227
+ "POST",
228
+ "/notification",
229
+ {
230
+ body: {
231
+ resourceType: "Bundle",
232
+ type: "document",
233
+ meta: {
234
+ lastUpdated: new Date().toISOString()
235
+ },
236
+ entry: resolvedBody
237
+ }
238
+ }
239
+ );
240
+ return prepareNextState(state, response);
241
+ };
242
+ }
243
+ function queryEvents(variables, options = {}) {
244
+ return async (state) => {
245
+ var _a, _b, _c, _d;
246
+ const [resolvedVariables, resolvedOptions] = expandReferences(
247
+ state,
248
+ variables,
249
+ options
250
+ );
251
+ const response = await request(
252
+ state.configuration,
253
+ "POST",
254
+ "/graphql",
255
+ {
256
+ body: {
257
+ operationName: "searchEvents",
258
+ query: searchEventsQuery,
259
+ variables: { advancedSearchParameters: resolvedVariables },
260
+ count: resolvedOptions.count || 10,
261
+ skip: resolvedOptions.skip,
262
+ ...resolvedOptions
263
+ }
264
+ }
265
+ );
266
+ const body = ((_a = response.body) == null ? void 0 : _a.errors) ? response.body : (_d = (_c = (_b = response.body) == null ? void 0 : _b.data) == null ? void 0 : _c.searchEvents) == null ? void 0 : _d.results;
267
+ return prepareNextState(state, {
268
+ ...response,
269
+ body
270
+ });
271
+ };
272
+ }
273
+
274
+ // src/http.js
275
+ var http_exports = {};
276
+ __export(http_exports, {
277
+ post: () => post,
278
+ request: () => request2
279
+ });
280
+ import { expandReferences as expandReferences2 } from "@openfn/language-common/util";
281
+ function post(path, body, options) {
282
+ return request2("POST", path, body, options);
283
+ }
284
+ function request2(method, path, body, options = {}) {
285
+ return async (state) => {
286
+ const [resolvedMethod, resolvedPath, resolvedBody, resolvedoptions] = expandReferences2(state, method, path, body, options);
287
+ const response = await request(
288
+ state.configuration,
289
+ resolvedMethod,
290
+ resolvedPath,
291
+ {
292
+ body: resolvedBody,
293
+ ...resolvedoptions
294
+ }
295
+ );
296
+ return prepareNextState(state, response);
297
+ };
298
+ }
299
+
300
+ // src/index.js
301
+ var src_default = Adaptor_exports;
302
+ export {
303
+ builders,
304
+ combine,
305
+ createBirthNotification,
306
+ cursor,
307
+ dataPath,
308
+ dataValue,
309
+ dateFns,
310
+ src_default as default,
311
+ each,
312
+ execute,
313
+ field,
314
+ fields,
315
+ fn,
316
+ fnIf,
317
+ group,
318
+ http_exports as http,
319
+ lastReferenceValue,
320
+ merge,
321
+ queryEvents,
322
+ scrubEmojis,
323
+ sourceValue,
324
+ util
325
+ };