@openfn/language-ghana-nia 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 +29 -0
- package/ast.json +683 -0
- package/configuration-schema.json +29 -0
- package/dist/index.cjs +233 -0
- package/dist/index.js +209 -0
- package/package.json +49 -0
- package/types/Adaptor.d.ts +76 -0
- package/types/index.d.ts +3 -0
- package/types/mock.d.ts +10 -0
- package/types/util.d.ts +3 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
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
|
+
cursor: () => import_language_common3.cursor,
|
|
29
|
+
dataPath: () => import_language_common3.dataPath,
|
|
30
|
+
dataValue: () => import_language_common3.dataValue,
|
|
31
|
+
dateFns: () => import_language_common3.dateFns,
|
|
32
|
+
default: () => src_default,
|
|
33
|
+
each: () => import_language_common3.each,
|
|
34
|
+
execute: () => execute,
|
|
35
|
+
field: () => import_language_common3.field,
|
|
36
|
+
fields: () => import_language_common3.fields,
|
|
37
|
+
fn: () => import_language_common3.fn,
|
|
38
|
+
fnIf: () => import_language_common3.fnIf,
|
|
39
|
+
get: () => get,
|
|
40
|
+
lastReferenceValue: () => import_language_common3.lastReferenceValue,
|
|
41
|
+
merge: () => import_language_common3.merge,
|
|
42
|
+
post: () => post,
|
|
43
|
+
registerChild: () => registerChild,
|
|
44
|
+
sourceValue: () => import_language_common3.sourceValue
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(src_exports);
|
|
47
|
+
|
|
48
|
+
// src/Adaptor.js
|
|
49
|
+
var Adaptor_exports = {};
|
|
50
|
+
__export(Adaptor_exports, {
|
|
51
|
+
cursor: () => import_language_common3.cursor,
|
|
52
|
+
dataPath: () => import_language_common3.dataPath,
|
|
53
|
+
dataValue: () => import_language_common3.dataValue,
|
|
54
|
+
dateFns: () => import_language_common3.dateFns,
|
|
55
|
+
each: () => import_language_common3.each,
|
|
56
|
+
execute: () => execute,
|
|
57
|
+
field: () => import_language_common3.field,
|
|
58
|
+
fields: () => import_language_common3.fields,
|
|
59
|
+
fn: () => import_language_common3.fn,
|
|
60
|
+
fnIf: () => import_language_common3.fnIf,
|
|
61
|
+
get: () => get,
|
|
62
|
+
lastReferenceValue: () => import_language_common3.lastReferenceValue,
|
|
63
|
+
merge: () => import_language_common3.merge,
|
|
64
|
+
post: () => post,
|
|
65
|
+
registerChild: () => registerChild,
|
|
66
|
+
sourceValue: () => import_language_common3.sourceValue
|
|
67
|
+
});
|
|
68
|
+
var import_language_common2 = require("@openfn/language-common");
|
|
69
|
+
|
|
70
|
+
// src/util.js
|
|
71
|
+
var import_undici = __toESM(require("undici"), 1);
|
|
72
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
73
|
+
var import_util = require("@openfn/language-common/util");
|
|
74
|
+
var import_language_common = require("@openfn/language-common");
|
|
75
|
+
var client;
|
|
76
|
+
var getClient = (baseUrl) => {
|
|
77
|
+
if (baseUrl) {
|
|
78
|
+
const url = new URL(baseUrl);
|
|
79
|
+
client = new import_undici.default.Client(url.origin);
|
|
80
|
+
}
|
|
81
|
+
return client;
|
|
82
|
+
};
|
|
83
|
+
var setMockClient = (mockClient) => {
|
|
84
|
+
client = mockClient;
|
|
85
|
+
};
|
|
86
|
+
var prepareNextState = async (state, response) => {
|
|
87
|
+
const { body, ...responseWithoutBody } = response;
|
|
88
|
+
const result = await body.json();
|
|
89
|
+
if (!state.references) {
|
|
90
|
+
state.references = [];
|
|
91
|
+
}
|
|
92
|
+
const nextState = {
|
|
93
|
+
...(0, import_language_common.composeNextState)(state, result),
|
|
94
|
+
response: responseWithoutBody
|
|
95
|
+
};
|
|
96
|
+
return nextState;
|
|
97
|
+
};
|
|
98
|
+
var request = (path, options) => {
|
|
99
|
+
return async (state) => {
|
|
100
|
+
const { baseUrl, merchantKey } = state.configuration;
|
|
101
|
+
getClient(baseUrl);
|
|
102
|
+
const basePath = baseUrl ? new URL(baseUrl).pathname : "/";
|
|
103
|
+
const [resolvedPath, resolvedoptions] = (0, import_util.expandReferences)(
|
|
104
|
+
state,
|
|
105
|
+
path,
|
|
106
|
+
options
|
|
107
|
+
);
|
|
108
|
+
const {
|
|
109
|
+
data,
|
|
110
|
+
headers = {
|
|
111
|
+
"content-type": "application/json",
|
|
112
|
+
NIa_merchantKey: merchantKey
|
|
113
|
+
},
|
|
114
|
+
method = "POST",
|
|
115
|
+
query,
|
|
116
|
+
...otherOptions
|
|
117
|
+
} = resolvedoptions;
|
|
118
|
+
const safePath = resolvedPath ? import_node_path.default.join(basePath, resolvedPath) : basePath;
|
|
119
|
+
const args = {
|
|
120
|
+
path: safePath,
|
|
121
|
+
data,
|
|
122
|
+
headers: {
|
|
123
|
+
...headers
|
|
124
|
+
},
|
|
125
|
+
method,
|
|
126
|
+
query,
|
|
127
|
+
...otherOptions
|
|
128
|
+
};
|
|
129
|
+
if (data) {
|
|
130
|
+
args.body = JSON.stringify(data);
|
|
131
|
+
}
|
|
132
|
+
const response = await client.request(args);
|
|
133
|
+
if (response.statusCode >= 400) {
|
|
134
|
+
(0, import_util.throwError)("NIA_ERROR", {
|
|
135
|
+
code: response.statusCode,
|
|
136
|
+
description: response.statusMessage,
|
|
137
|
+
body: await response.body.text()
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
(0, import_util.logResponse)(response);
|
|
141
|
+
return prepareNextState(state, response);
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/mock.js
|
|
146
|
+
var import_undici2 = require("undici");
|
|
147
|
+
var niaResponseSample = {
|
|
148
|
+
data: {
|
|
149
|
+
babyPin: "GH-6326223626-3"
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
function createServer(url = "https://selfie.imsgh.org:2035") {
|
|
153
|
+
const agent = new import_undici2.MockAgent();
|
|
154
|
+
agent.disableNetConnect();
|
|
155
|
+
const mockPool = agent.get(url);
|
|
156
|
+
const sendNiaData = (req) => {
|
|
157
|
+
return {
|
|
158
|
+
statusCode: 200,
|
|
159
|
+
responseOptions: {
|
|
160
|
+
headers: { "Content-Type": "application/json" }
|
|
161
|
+
},
|
|
162
|
+
data: JSON.stringify(niaResponseSample)
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
mockPool.intercept({ method: "post", path: /awopa\/api\/v1\/baby\/registration/ }).reply(sendNiaData).persist();
|
|
166
|
+
return {
|
|
167
|
+
agent,
|
|
168
|
+
request: ({ method, path, data, ...rest }) => {
|
|
169
|
+
const opts = {
|
|
170
|
+
method,
|
|
171
|
+
path,
|
|
172
|
+
origin: url,
|
|
173
|
+
headers: {},
|
|
174
|
+
...rest
|
|
175
|
+
};
|
|
176
|
+
if (data) {
|
|
177
|
+
opts.body = JSON.stringify(data);
|
|
178
|
+
}
|
|
179
|
+
return mockPool.request(opts);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/Adaptor.js
|
|
185
|
+
var import_language_common3 = require("@openfn/language-common");
|
|
186
|
+
function execute(...operations) {
|
|
187
|
+
const initialState = {
|
|
188
|
+
references: [],
|
|
189
|
+
data: null,
|
|
190
|
+
configuration: {}
|
|
191
|
+
};
|
|
192
|
+
return (state) => {
|
|
193
|
+
if (!state.configuration.baseUrl) {
|
|
194
|
+
const client2 = createServer();
|
|
195
|
+
setMockClient(client2);
|
|
196
|
+
}
|
|
197
|
+
return (0, import_language_common2.execute)(...operations)({ ...initialState, ...state });
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function get(path, query) {
|
|
201
|
+
return request(path, { query, method: "GET" });
|
|
202
|
+
}
|
|
203
|
+
function post(path, data) {
|
|
204
|
+
return request(path, { data, method: "POST" });
|
|
205
|
+
}
|
|
206
|
+
function registerChild(data) {
|
|
207
|
+
return request("/awopa/api/v1/baby/registration", {
|
|
208
|
+
method: "POST",
|
|
209
|
+
data
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/index.js
|
|
214
|
+
var src_default = Adaptor_exports;
|
|
215
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
216
|
+
0 && (module.exports = {
|
|
217
|
+
cursor,
|
|
218
|
+
dataPath,
|
|
219
|
+
dataValue,
|
|
220
|
+
dateFns,
|
|
221
|
+
each,
|
|
222
|
+
execute,
|
|
223
|
+
field,
|
|
224
|
+
fields,
|
|
225
|
+
fn,
|
|
226
|
+
fnIf,
|
|
227
|
+
get,
|
|
228
|
+
lastReferenceValue,
|
|
229
|
+
merge,
|
|
230
|
+
post,
|
|
231
|
+
registerChild,
|
|
232
|
+
sourceValue
|
|
233
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
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
|
+
cursor: () => cursor,
|
|
11
|
+
dataPath: () => dataPath,
|
|
12
|
+
dataValue: () => dataValue,
|
|
13
|
+
dateFns: () => dateFns,
|
|
14
|
+
each: () => each,
|
|
15
|
+
execute: () => execute,
|
|
16
|
+
field: () => field,
|
|
17
|
+
fields: () => fields,
|
|
18
|
+
fn: () => fn,
|
|
19
|
+
fnIf: () => fnIf,
|
|
20
|
+
get: () => get,
|
|
21
|
+
lastReferenceValue: () => lastReferenceValue,
|
|
22
|
+
merge: () => merge,
|
|
23
|
+
post: () => post,
|
|
24
|
+
registerChild: () => registerChild,
|
|
25
|
+
sourceValue: () => sourceValue
|
|
26
|
+
});
|
|
27
|
+
import { execute as commonExecute } from "@openfn/language-common";
|
|
28
|
+
|
|
29
|
+
// src/util.js
|
|
30
|
+
import undici from "undici";
|
|
31
|
+
import nodepath from "path";
|
|
32
|
+
import {
|
|
33
|
+
throwError,
|
|
34
|
+
logResponse,
|
|
35
|
+
expandReferences
|
|
36
|
+
} from "@openfn/language-common/util";
|
|
37
|
+
import { composeNextState } from "@openfn/language-common";
|
|
38
|
+
var client;
|
|
39
|
+
var getClient = (baseUrl) => {
|
|
40
|
+
if (baseUrl) {
|
|
41
|
+
const url = new URL(baseUrl);
|
|
42
|
+
client = new undici.Client(url.origin);
|
|
43
|
+
}
|
|
44
|
+
return client;
|
|
45
|
+
};
|
|
46
|
+
var setMockClient = (mockClient) => {
|
|
47
|
+
client = mockClient;
|
|
48
|
+
};
|
|
49
|
+
var prepareNextState = async (state, response) => {
|
|
50
|
+
const { body, ...responseWithoutBody } = response;
|
|
51
|
+
const result = await body.json();
|
|
52
|
+
if (!state.references) {
|
|
53
|
+
state.references = [];
|
|
54
|
+
}
|
|
55
|
+
const nextState = {
|
|
56
|
+
...composeNextState(state, result),
|
|
57
|
+
response: responseWithoutBody
|
|
58
|
+
};
|
|
59
|
+
return nextState;
|
|
60
|
+
};
|
|
61
|
+
var request = (path, options) => {
|
|
62
|
+
return async (state) => {
|
|
63
|
+
const { baseUrl, merchantKey } = state.configuration;
|
|
64
|
+
getClient(baseUrl);
|
|
65
|
+
const basePath = baseUrl ? new URL(baseUrl).pathname : "/";
|
|
66
|
+
const [resolvedPath, resolvedoptions] = expandReferences(
|
|
67
|
+
state,
|
|
68
|
+
path,
|
|
69
|
+
options
|
|
70
|
+
);
|
|
71
|
+
const {
|
|
72
|
+
data,
|
|
73
|
+
headers = {
|
|
74
|
+
"content-type": "application/json",
|
|
75
|
+
NIa_merchantKey: merchantKey
|
|
76
|
+
},
|
|
77
|
+
method = "POST",
|
|
78
|
+
query,
|
|
79
|
+
...otherOptions
|
|
80
|
+
} = resolvedoptions;
|
|
81
|
+
const safePath = resolvedPath ? nodepath.join(basePath, resolvedPath) : basePath;
|
|
82
|
+
const args = {
|
|
83
|
+
path: safePath,
|
|
84
|
+
data,
|
|
85
|
+
headers: {
|
|
86
|
+
...headers
|
|
87
|
+
},
|
|
88
|
+
method,
|
|
89
|
+
query,
|
|
90
|
+
...otherOptions
|
|
91
|
+
};
|
|
92
|
+
if (data) {
|
|
93
|
+
args.body = JSON.stringify(data);
|
|
94
|
+
}
|
|
95
|
+
const response = await client.request(args);
|
|
96
|
+
if (response.statusCode >= 400) {
|
|
97
|
+
throwError("NIA_ERROR", {
|
|
98
|
+
code: response.statusCode,
|
|
99
|
+
description: response.statusMessage,
|
|
100
|
+
body: await response.body.text()
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
logResponse(response);
|
|
104
|
+
return prepareNextState(state, response);
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// src/mock.js
|
|
109
|
+
import { MockAgent } from "undici";
|
|
110
|
+
var niaResponseSample = {
|
|
111
|
+
data: {
|
|
112
|
+
babyPin: "GH-6326223626-3"
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
function createServer(url = "https://selfie.imsgh.org:2035") {
|
|
116
|
+
const agent = new MockAgent();
|
|
117
|
+
agent.disableNetConnect();
|
|
118
|
+
const mockPool = agent.get(url);
|
|
119
|
+
const sendNiaData = (req) => {
|
|
120
|
+
return {
|
|
121
|
+
statusCode: 200,
|
|
122
|
+
responseOptions: {
|
|
123
|
+
headers: { "Content-Type": "application/json" }
|
|
124
|
+
},
|
|
125
|
+
data: JSON.stringify(niaResponseSample)
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
mockPool.intercept({ method: "post", path: /awopa\/api\/v1\/baby\/registration/ }).reply(sendNiaData).persist();
|
|
129
|
+
return {
|
|
130
|
+
agent,
|
|
131
|
+
request: ({ method, path, data, ...rest }) => {
|
|
132
|
+
const opts = {
|
|
133
|
+
method,
|
|
134
|
+
path,
|
|
135
|
+
origin: url,
|
|
136
|
+
headers: {},
|
|
137
|
+
...rest
|
|
138
|
+
};
|
|
139
|
+
if (data) {
|
|
140
|
+
opts.body = JSON.stringify(data);
|
|
141
|
+
}
|
|
142
|
+
return mockPool.request(opts);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/Adaptor.js
|
|
148
|
+
import {
|
|
149
|
+
fn,
|
|
150
|
+
fnIf,
|
|
151
|
+
each,
|
|
152
|
+
merge,
|
|
153
|
+
field,
|
|
154
|
+
fields,
|
|
155
|
+
cursor,
|
|
156
|
+
dateFns,
|
|
157
|
+
dataPath,
|
|
158
|
+
dataValue,
|
|
159
|
+
sourceValue,
|
|
160
|
+
lastReferenceValue
|
|
161
|
+
} from "@openfn/language-common";
|
|
162
|
+
function execute(...operations) {
|
|
163
|
+
const initialState = {
|
|
164
|
+
references: [],
|
|
165
|
+
data: null,
|
|
166
|
+
configuration: {}
|
|
167
|
+
};
|
|
168
|
+
return (state) => {
|
|
169
|
+
if (!state.configuration.baseUrl) {
|
|
170
|
+
const client2 = createServer();
|
|
171
|
+
setMockClient(client2);
|
|
172
|
+
}
|
|
173
|
+
return commonExecute(...operations)({ ...initialState, ...state });
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function get(path, query) {
|
|
177
|
+
return request(path, { query, method: "GET" });
|
|
178
|
+
}
|
|
179
|
+
function post(path, data) {
|
|
180
|
+
return request(path, { data, method: "POST" });
|
|
181
|
+
}
|
|
182
|
+
function registerChild(data) {
|
|
183
|
+
return request("/awopa/api/v1/baby/registration", {
|
|
184
|
+
method: "POST",
|
|
185
|
+
data
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// src/index.js
|
|
190
|
+
var src_default = Adaptor_exports;
|
|
191
|
+
export {
|
|
192
|
+
cursor,
|
|
193
|
+
dataPath,
|
|
194
|
+
dataValue,
|
|
195
|
+
dateFns,
|
|
196
|
+
src_default as default,
|
|
197
|
+
each,
|
|
198
|
+
execute,
|
|
199
|
+
field,
|
|
200
|
+
fields,
|
|
201
|
+
fn,
|
|
202
|
+
fnIf,
|
|
203
|
+
get,
|
|
204
|
+
lastReferenceValue,
|
|
205
|
+
merge,
|
|
206
|
+
post,
|
|
207
|
+
registerChild,
|
|
208
|
+
sourceValue
|
|
209
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openfn/language-ghana-nia",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "OpenFn ghana-nia 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
|
+
"undici": "^5.22.1",
|
|
24
|
+
"@openfn/language-common": "2.3.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"assertion-error": "2.0.0",
|
|
28
|
+
"chai": "4.3.6",
|
|
29
|
+
"deep-eql": "4.1.1",
|
|
30
|
+
"esno": "^0.16.3",
|
|
31
|
+
"mocha": "^10.7.3",
|
|
32
|
+
"rimraf": "3.0.2",
|
|
33
|
+
"undici": "^5.22.1"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/openfn/adaptors.git"
|
|
38
|
+
},
|
|
39
|
+
"types": "types/index.d.ts",
|
|
40
|
+
"main": "dist/index.cjs",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "pnpm clean && build-adaptor ghana-nia",
|
|
43
|
+
"test": "mocha --experimental-specifier-resolution=node --no-warnings",
|
|
44
|
+
"test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings",
|
|
45
|
+
"clean": "rimraf dist types docs",
|
|
46
|
+
"pack": "pnpm pack --pack-destination ../../dist",
|
|
47
|
+
"lint": "eslint src"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executes an operation.
|
|
3
|
+
* @function
|
|
4
|
+
* @private
|
|
5
|
+
* @param {Operation} operations - Operations
|
|
6
|
+
* @returns {State}
|
|
7
|
+
*/
|
|
8
|
+
export function execute(...operations: Operation): State;
|
|
9
|
+
/**
|
|
10
|
+
/**
|
|
11
|
+
* State object
|
|
12
|
+
* @typedef {Object} HttpState
|
|
13
|
+
* @property data - the parsed response body
|
|
14
|
+
* @property response - the response from the HTTP server, including headers, statusCode, body, etc
|
|
15
|
+
* @property references - an array of all previous data objects used in the Job
|
|
16
|
+
**/
|
|
17
|
+
/**
|
|
18
|
+
* Make a GET request
|
|
19
|
+
* @example
|
|
20
|
+
* get("patient");
|
|
21
|
+
* @function
|
|
22
|
+
* @public
|
|
23
|
+
* @param {string} path - Path to resource
|
|
24
|
+
* @param {object} query - An object of query parameters to be encoded into the URL.
|
|
25
|
+
* @returns {Operation}
|
|
26
|
+
* @state {HttpState}
|
|
27
|
+
*/
|
|
28
|
+
export function get(path: string, query: object): Operation;
|
|
29
|
+
/**
|
|
30
|
+
* Make a POST request
|
|
31
|
+
* @example
|
|
32
|
+
* post("patient", { "name":"Bukayo" });
|
|
33
|
+
* @function
|
|
34
|
+
* @public
|
|
35
|
+
* @param {string} path - Path to resource
|
|
36
|
+
* @param {object} data - 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).
|
|
37
|
+
* @returns {Operation}
|
|
38
|
+
* @state {HttpState}
|
|
39
|
+
*/
|
|
40
|
+
export function post(path: string, data: object): Operation;
|
|
41
|
+
/**
|
|
42
|
+
* Generate a national ID
|
|
43
|
+
* @example
|
|
44
|
+
* registerChild({
|
|
45
|
+
* child: {},
|
|
46
|
+
* mother: {},
|
|
47
|
+
* father: {},
|
|
48
|
+
* health_facility: {},
|
|
49
|
+
* birth_informant: {}
|
|
50
|
+
* })
|
|
51
|
+
* @function
|
|
52
|
+
* @public
|
|
53
|
+
* @param {object} data - 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).
|
|
54
|
+
* @returns {Operation}
|
|
55
|
+
* @state {HttpState}
|
|
56
|
+
*/
|
|
57
|
+
export function registerChild(data: object): Operation;
|
|
58
|
+
/**
|
|
59
|
+
* /**
|
|
60
|
+
* State object
|
|
61
|
+
*/
|
|
62
|
+
export type HttpState = {
|
|
63
|
+
/**
|
|
64
|
+
* - the parsed response body
|
|
65
|
+
*/
|
|
66
|
+
data: any;
|
|
67
|
+
/**
|
|
68
|
+
* - the response from the HTTP server, including headers, statusCode, body, etc
|
|
69
|
+
*/
|
|
70
|
+
response: any;
|
|
71
|
+
/**
|
|
72
|
+
* - an array of all previous data objects used in the Job
|
|
73
|
+
*/
|
|
74
|
+
references: any;
|
|
75
|
+
};
|
|
76
|
+
export { fn, fnIf, each, merge, field, fields, cursor, dateFns, dataPath, dataValue, sourceValue, lastReferenceValue } from "@openfn/language-common";
|
package/types/index.d.ts
ADDED
package/types/mock.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function createServer(url?: string): {
|
|
2
|
+
agent: MockAgent<MockAgent.Options>;
|
|
3
|
+
request: ({ method, path, data, ...rest }: {
|
|
4
|
+
[x: string]: any;
|
|
5
|
+
method: any;
|
|
6
|
+
path: any;
|
|
7
|
+
data: any;
|
|
8
|
+
}) => Promise<import("undici/types/dispatcher").default.ResponseData>;
|
|
9
|
+
};
|
|
10
|
+
import { MockAgent } from "undici/types";
|
package/types/util.d.ts
ADDED