@openfn/language-divoc 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.
- package/LICENSE +674 -0
- package/LICENSE.LESSER +165 -0
- package/README.md +25 -0
- package/ast.json +574 -0
- package/configuration-schema.json +22 -0
- package/dist/index.cjs +141 -0
- package/dist/index.js +121 -0
- package/package.json +48 -0
- package/types/Adaptor.d.ts +90 -0
- package/types/Utils.d.ts +3 -0
- package/types/index.d.ts +3 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
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
|
+
certifyVaccination: () => certifyVaccination,
|
|
23
|
+
cursor: () => import_language_common3.cursor,
|
|
24
|
+
dataPath: () => import_language_common3.dataPath,
|
|
25
|
+
dataValue: () => import_language_common3.dataValue,
|
|
26
|
+
dateFns: () => import_language_common3.dateFns,
|
|
27
|
+
default: () => src_default,
|
|
28
|
+
each: () => import_language_common3.each,
|
|
29
|
+
execute: () => execute,
|
|
30
|
+
field: () => import_language_common3.field,
|
|
31
|
+
fields: () => import_language_common3.fields,
|
|
32
|
+
fn: () => import_language_common3.fn,
|
|
33
|
+
lastReferenceValue: () => import_language_common3.lastReferenceValue,
|
|
34
|
+
merge: () => import_language_common3.merge,
|
|
35
|
+
sourceValue: () => import_language_common3.sourceValue
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
|
|
39
|
+
// src/Adaptor.js
|
|
40
|
+
var Adaptor_exports = {};
|
|
41
|
+
__export(Adaptor_exports, {
|
|
42
|
+
certifyVaccination: () => certifyVaccination,
|
|
43
|
+
cursor: () => import_language_common3.cursor,
|
|
44
|
+
dataPath: () => import_language_common3.dataPath,
|
|
45
|
+
dataValue: () => import_language_common3.dataValue,
|
|
46
|
+
dateFns: () => import_language_common3.dateFns,
|
|
47
|
+
each: () => import_language_common3.each,
|
|
48
|
+
execute: () => execute,
|
|
49
|
+
field: () => import_language_common3.field,
|
|
50
|
+
fields: () => import_language_common3.fields,
|
|
51
|
+
fn: () => import_language_common3.fn,
|
|
52
|
+
lastReferenceValue: () => import_language_common3.lastReferenceValue,
|
|
53
|
+
merge: () => import_language_common3.merge,
|
|
54
|
+
sourceValue: () => import_language_common3.sourceValue
|
|
55
|
+
});
|
|
56
|
+
var import_language_common2 = require("@openfn/language-common");
|
|
57
|
+
var import_util2 = require("@openfn/language-common/util");
|
|
58
|
+
|
|
59
|
+
// src/Utils.js
|
|
60
|
+
var import_language_common = require("@openfn/language-common");
|
|
61
|
+
var import_util = require("@openfn/language-common/util");
|
|
62
|
+
var prepareNextState = (state, response) => {
|
|
63
|
+
const { body, ...responseWithoutBody } = response;
|
|
64
|
+
if (!state.references) {
|
|
65
|
+
state.references = [];
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
...(0, import_language_common.composeNextState)(state, response.body),
|
|
69
|
+
response: responseWithoutBody
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
var configureAuth = (auth, headers = {}) => {
|
|
73
|
+
if ("access_token" in auth) {
|
|
74
|
+
Object.assign(headers, {
|
|
75
|
+
Authorization: `Bearer ${auth.access_token}`
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
throw new Error("Invalid authorization credentials. Include an access token");
|
|
79
|
+
}
|
|
80
|
+
return headers;
|
|
81
|
+
};
|
|
82
|
+
var request = async (configuration, path, opts) => {
|
|
83
|
+
const { baseUrl } = configuration;
|
|
84
|
+
const { method, data, params = {}, headers: customHeaders = {}, contentType, parseAs = "json" } = opts;
|
|
85
|
+
const headers = configureAuth(configuration, customHeaders);
|
|
86
|
+
if (contentType) {
|
|
87
|
+
headers["content-type"] = contentType;
|
|
88
|
+
}
|
|
89
|
+
const options = {
|
|
90
|
+
body: data,
|
|
91
|
+
headers,
|
|
92
|
+
query: params,
|
|
93
|
+
parseAs,
|
|
94
|
+
maxRedirections: 1,
|
|
95
|
+
baseUrl
|
|
96
|
+
};
|
|
97
|
+
return (0, import_util.request)(method, path, options).then(import_util.logResponse);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// src/Adaptor.js
|
|
101
|
+
var import_language_common3 = require("@openfn/language-common");
|
|
102
|
+
function execute(...operations) {
|
|
103
|
+
const initialState = {
|
|
104
|
+
references: [],
|
|
105
|
+
data: null
|
|
106
|
+
};
|
|
107
|
+
return (state) => {
|
|
108
|
+
return (0, import_language_common2.execute)(...operations)({ ...initialState, ...state });
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function certifyVaccination(data) {
|
|
112
|
+
return async (state) => {
|
|
113
|
+
const [resolvedData] = (0, import_util2.expandReferences)(state, data);
|
|
114
|
+
const { baseUrl } = state.configuration;
|
|
115
|
+
const options = {
|
|
116
|
+
method: "POST",
|
|
117
|
+
data: resolvedData
|
|
118
|
+
};
|
|
119
|
+
const response = await request({ ...state.configuration }, "/v1/certify", options);
|
|
120
|
+
return prepareNextState(state, response);
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/index.js
|
|
125
|
+
var src_default = Adaptor_exports;
|
|
126
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
127
|
+
0 && (module.exports = {
|
|
128
|
+
certifyVaccination,
|
|
129
|
+
cursor,
|
|
130
|
+
dataPath,
|
|
131
|
+
dataValue,
|
|
132
|
+
dateFns,
|
|
133
|
+
each,
|
|
134
|
+
execute,
|
|
135
|
+
field,
|
|
136
|
+
fields,
|
|
137
|
+
fn,
|
|
138
|
+
lastReferenceValue,
|
|
139
|
+
merge,
|
|
140
|
+
sourceValue
|
|
141
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
certifyVaccination: () => certifyVaccination,
|
|
11
|
+
cursor: () => cursor,
|
|
12
|
+
dataPath: () => dataPath,
|
|
13
|
+
dataValue: () => dataValue,
|
|
14
|
+
dateFns: () => dateFns,
|
|
15
|
+
each: () => each,
|
|
16
|
+
execute: () => execute,
|
|
17
|
+
field: () => field,
|
|
18
|
+
fields: () => fields,
|
|
19
|
+
fn: () => fn,
|
|
20
|
+
lastReferenceValue: () => lastReferenceValue,
|
|
21
|
+
merge: () => merge,
|
|
22
|
+
sourceValue: () => sourceValue
|
|
23
|
+
});
|
|
24
|
+
import { execute as commonExecute } from "@openfn/language-common";
|
|
25
|
+
import { expandReferences } from "@openfn/language-common/util";
|
|
26
|
+
|
|
27
|
+
// src/Utils.js
|
|
28
|
+
import { composeNextState } from "@openfn/language-common";
|
|
29
|
+
import { request as commonRequest, logResponse } from "@openfn/language-common/util";
|
|
30
|
+
var prepareNextState = (state, response) => {
|
|
31
|
+
const { body, ...responseWithoutBody } = response;
|
|
32
|
+
if (!state.references) {
|
|
33
|
+
state.references = [];
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
...composeNextState(state, response.body),
|
|
37
|
+
response: responseWithoutBody
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
var configureAuth = (auth, headers = {}) => {
|
|
41
|
+
if ("access_token" in auth) {
|
|
42
|
+
Object.assign(headers, {
|
|
43
|
+
Authorization: `Bearer ${auth.access_token}`
|
|
44
|
+
});
|
|
45
|
+
} else {
|
|
46
|
+
throw new Error("Invalid authorization credentials. Include an access token");
|
|
47
|
+
}
|
|
48
|
+
return headers;
|
|
49
|
+
};
|
|
50
|
+
var request = async (configuration, path, opts) => {
|
|
51
|
+
const { baseUrl } = configuration;
|
|
52
|
+
const { method, data, params = {}, headers: customHeaders = {}, contentType, parseAs = "json" } = opts;
|
|
53
|
+
const headers = configureAuth(configuration, customHeaders);
|
|
54
|
+
if (contentType) {
|
|
55
|
+
headers["content-type"] = contentType;
|
|
56
|
+
}
|
|
57
|
+
const options = {
|
|
58
|
+
body: data,
|
|
59
|
+
headers,
|
|
60
|
+
query: params,
|
|
61
|
+
parseAs,
|
|
62
|
+
maxRedirections: 1,
|
|
63
|
+
baseUrl
|
|
64
|
+
};
|
|
65
|
+
return commonRequest(method, path, options).then(logResponse);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/Adaptor.js
|
|
69
|
+
import {
|
|
70
|
+
dataPath,
|
|
71
|
+
dataValue,
|
|
72
|
+
dateFns,
|
|
73
|
+
cursor,
|
|
74
|
+
each,
|
|
75
|
+
field,
|
|
76
|
+
fields,
|
|
77
|
+
fn,
|
|
78
|
+
lastReferenceValue,
|
|
79
|
+
merge,
|
|
80
|
+
sourceValue
|
|
81
|
+
} from "@openfn/language-common";
|
|
82
|
+
function execute(...operations) {
|
|
83
|
+
const initialState = {
|
|
84
|
+
references: [],
|
|
85
|
+
data: null
|
|
86
|
+
};
|
|
87
|
+
return (state) => {
|
|
88
|
+
return commonExecute(...operations)({ ...initialState, ...state });
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function certifyVaccination(data) {
|
|
92
|
+
return async (state) => {
|
|
93
|
+
const [resolvedData] = expandReferences(state, data);
|
|
94
|
+
const { baseUrl } = state.configuration;
|
|
95
|
+
const options = {
|
|
96
|
+
method: "POST",
|
|
97
|
+
data: resolvedData
|
|
98
|
+
};
|
|
99
|
+
const response = await request({ ...state.configuration }, "/v1/certify", options);
|
|
100
|
+
return prepareNextState(state, response);
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/index.js
|
|
105
|
+
var src_default = Adaptor_exports;
|
|
106
|
+
export {
|
|
107
|
+
certifyVaccination,
|
|
108
|
+
cursor,
|
|
109
|
+
dataPath,
|
|
110
|
+
dataValue,
|
|
111
|
+
dateFns,
|
|
112
|
+
src_default as default,
|
|
113
|
+
each,
|
|
114
|
+
execute,
|
|
115
|
+
field,
|
|
116
|
+
fields,
|
|
117
|
+
fn,
|
|
118
|
+
lastReferenceValue,
|
|
119
|
+
merge,
|
|
120
|
+
sourceValue
|
|
121
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openfn/language-divoc",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "OpenFn divoc 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": "2.3.1"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"assertion-error": "2.0.0",
|
|
27
|
+
"chai": "4.3.6",
|
|
28
|
+
"deep-eql": "4.1.1",
|
|
29
|
+
"esno": "^0.16.3",
|
|
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 divoc",
|
|
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,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State object
|
|
3
|
+
* @typedef {Object} DivocHttpState
|
|
4
|
+
* @property data - The response body (as JSON)
|
|
5
|
+
* @property response - The HTTP response from the DIVOC server (excluding the body)
|
|
6
|
+
* @property references - An array of the previous data object used in the job
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Executes a sequence of operations
|
|
10
|
+
* Wraps 'language-common/execute` and prepends initial state object for DIVOC
|
|
11
|
+
* @private
|
|
12
|
+
* @example
|
|
13
|
+
* execute(certifyVaccination({}))(state)
|
|
14
|
+
* @param {Operations} operations
|
|
15
|
+
* @returns {operation}
|
|
16
|
+
*/
|
|
17
|
+
export function execute(...operations: Operations): operation;
|
|
18
|
+
/**
|
|
19
|
+
* Certify a vaccination
|
|
20
|
+
* @public
|
|
21
|
+
* @function
|
|
22
|
+
* @example <caption>Certify a vaccination object</caption>
|
|
23
|
+
* certifyVaccination({
|
|
24
|
+
"preEnrollmentCode": "string",
|
|
25
|
+
"recipient": {
|
|
26
|
+
"name": "string",
|
|
27
|
+
"dob": "2025-03-20",
|
|
28
|
+
"age": "string",
|
|
29
|
+
"gender": "string",
|
|
30
|
+
"nationality": "string",
|
|
31
|
+
"identity": "string",
|
|
32
|
+
"contact": [
|
|
33
|
+
"string"
|
|
34
|
+
],
|
|
35
|
+
"address": {
|
|
36
|
+
"addressLine1": "string",
|
|
37
|
+
"addressLine2": "string",
|
|
38
|
+
"district": "string",
|
|
39
|
+
"state": "string",
|
|
40
|
+
"pincode": 0
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"vaccination": {
|
|
44
|
+
"name": "string",
|
|
45
|
+
"batch": "string",
|
|
46
|
+
"manufacturer": "string",
|
|
47
|
+
"date": "2025-03-20T06:08:22.394Z",
|
|
48
|
+
"effectiveStart": "2025-03-20",
|
|
49
|
+
"effectiveUntil": "2025-03-20",
|
|
50
|
+
"dose": 1,
|
|
51
|
+
"totalDoses": 2
|
|
52
|
+
},
|
|
53
|
+
"vaccinator": {
|
|
54
|
+
"name": "string"
|
|
55
|
+
},
|
|
56
|
+
"facility": {
|
|
57
|
+
"name": "string",
|
|
58
|
+
"address": {
|
|
59
|
+
"addressLine1": "string",
|
|
60
|
+
"addressLine2": "string",
|
|
61
|
+
"district": "string",
|
|
62
|
+
"state": "string",
|
|
63
|
+
"pincode": 0
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"meta": {}
|
|
67
|
+
});
|
|
68
|
+
@param {Object} data - Vaccinationobject
|
|
69
|
+
@state {DivocHttpState}
|
|
70
|
+
@returns {Operation}
|
|
71
|
+
*/
|
|
72
|
+
export function certifyVaccination(data: any): Operation;
|
|
73
|
+
/**
|
|
74
|
+
* State object
|
|
75
|
+
*/
|
|
76
|
+
export type DivocHttpState = {
|
|
77
|
+
/**
|
|
78
|
+
* - The response body (as JSON)
|
|
79
|
+
*/
|
|
80
|
+
data: any;
|
|
81
|
+
/**
|
|
82
|
+
* - The HTTP response from the DIVOC server (excluding the body)
|
|
83
|
+
*/
|
|
84
|
+
response: any;
|
|
85
|
+
/**
|
|
86
|
+
* - An array of the previous data object used in the job
|
|
87
|
+
*/
|
|
88
|
+
references: any;
|
|
89
|
+
};
|
|
90
|
+
export { dataPath, dataValue, dateFns, cursor, each, field, fields, fn, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
|
package/types/Utils.d.ts
ADDED
package/types/index.d.ts
ADDED