@openfn/language-maximo 0.3.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 +84 -0
- package/ast.json +423 -0
- package/configuration-schema.json +32 -0
- package/dist/index.cjs +308 -0
- package/dist/index.js +282 -0
- package/package.json +55 -0
- package/types/Adaptor.d.ts +54 -0
- package/types/index.d.ts +3 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
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
|
+
alterState: () => import_language_common2.alterState,
|
|
29
|
+
create: () => create,
|
|
30
|
+
dataPath: () => import_language_common2.dataPath,
|
|
31
|
+
dataValue: () => import_language_common2.dataValue,
|
|
32
|
+
default: () => src_default,
|
|
33
|
+
each: () => import_language_common2.each,
|
|
34
|
+
execute: () => execute,
|
|
35
|
+
fetch: () => fetch,
|
|
36
|
+
field: () => import_language_common2.field,
|
|
37
|
+
fields: () => import_language_common2.fields,
|
|
38
|
+
fn: () => import_language_common2.fn,
|
|
39
|
+
lastReferenceValue: () => import_language_common2.lastReferenceValue,
|
|
40
|
+
merge: () => import_language_common2.merge,
|
|
41
|
+
sourceValue: () => import_language_common2.sourceValue,
|
|
42
|
+
update: () => update,
|
|
43
|
+
update75: () => update75
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(src_exports);
|
|
46
|
+
|
|
47
|
+
// src/Adaptor.js
|
|
48
|
+
var Adaptor_exports = {};
|
|
49
|
+
__export(Adaptor_exports, {
|
|
50
|
+
alterState: () => import_language_common2.alterState,
|
|
51
|
+
create: () => create,
|
|
52
|
+
dataPath: () => import_language_common2.dataPath,
|
|
53
|
+
dataValue: () => import_language_common2.dataValue,
|
|
54
|
+
each: () => import_language_common2.each,
|
|
55
|
+
execute: () => execute,
|
|
56
|
+
fetch: () => fetch,
|
|
57
|
+
field: () => import_language_common2.field,
|
|
58
|
+
fields: () => import_language_common2.fields,
|
|
59
|
+
fn: () => import_language_common2.fn,
|
|
60
|
+
lastReferenceValue: () => import_language_common2.lastReferenceValue,
|
|
61
|
+
merge: () => import_language_common2.merge,
|
|
62
|
+
sourceValue: () => import_language_common2.sourceValue,
|
|
63
|
+
update: () => update,
|
|
64
|
+
update75: () => update75
|
|
65
|
+
});
|
|
66
|
+
var import_language_common = require("@openfn/language-common");
|
|
67
|
+
var import_request = __toESM(require("request"), 1);
|
|
68
|
+
var import_url = require("url");
|
|
69
|
+
var import_base_64 = __toESM(require("base-64"), 1);
|
|
70
|
+
var import_utf8 = __toESM(require("utf8"), 1);
|
|
71
|
+
var import_language_common2 = require("@openfn/language-common");
|
|
72
|
+
function execute(...operations) {
|
|
73
|
+
const initialState = {
|
|
74
|
+
references: [],
|
|
75
|
+
data: null
|
|
76
|
+
};
|
|
77
|
+
return (state) => {
|
|
78
|
+
return (0, import_language_common.execute)(...operations)({ ...initialState, ...state });
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function fetch(params) {
|
|
82
|
+
return (state) => {
|
|
83
|
+
function assembleError({ response, error }) {
|
|
84
|
+
if (response && [200, 201, 202].indexOf(response.statusCode) > -1)
|
|
85
|
+
return false;
|
|
86
|
+
if (error)
|
|
87
|
+
return error;
|
|
88
|
+
return new Error(`Server responded with ${response.statusCode}`);
|
|
89
|
+
}
|
|
90
|
+
const { endpoint, query, postUrl } = (0, import_language_common.expandReferences)(params)(state);
|
|
91
|
+
const { username, password, baseUrl } = state.configuration;
|
|
92
|
+
const authy = username + ":" + password;
|
|
93
|
+
const bytes = import_utf8.default.encode(authy);
|
|
94
|
+
const encoded = import_base_64.default.encode(bytes);
|
|
95
|
+
const url = (0, import_url.resolve)(baseUrl + "/", endpoint);
|
|
96
|
+
console.log("Fetching data from URL: " + url);
|
|
97
|
+
console.log("Applying query: " + JSON.stringify(query));
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
(0, import_request.default)(
|
|
100
|
+
{
|
|
101
|
+
url,
|
|
102
|
+
qs: query,
|
|
103
|
+
headers: {
|
|
104
|
+
maxauth: encoded
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
function(error, response, getResponseBody) {
|
|
108
|
+
error = assembleError({ error, response });
|
|
109
|
+
if (error) {
|
|
110
|
+
console.error("GET failed.");
|
|
111
|
+
console.log(response);
|
|
112
|
+
reject(error);
|
|
113
|
+
} else {
|
|
114
|
+
console.log("GET succeeded.");
|
|
115
|
+
console.log("Response body: " + getResponseBody);
|
|
116
|
+
import_request.default.post(
|
|
117
|
+
{
|
|
118
|
+
url: postUrl,
|
|
119
|
+
json: JSON.parse(getResponseBody)
|
|
120
|
+
},
|
|
121
|
+
function(error2, response2, postResponseBody) {
|
|
122
|
+
error2 = assembleError({ error: error2, response: response2 });
|
|
123
|
+
if (error2) {
|
|
124
|
+
console.error("POST failed.");
|
|
125
|
+
reject(error2);
|
|
126
|
+
} else {
|
|
127
|
+
console.log("POST succeeded.");
|
|
128
|
+
resolve(getResponseBody);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
}).then((response) => {
|
|
136
|
+
console.log("Success:", response);
|
|
137
|
+
let result = typeof response === "object" ? response : JSON.parse(response);
|
|
138
|
+
return { ...state, references: [result, ...state.references] };
|
|
139
|
+
}).then((data) => {
|
|
140
|
+
const nextState = { ...state, response: { body: data } };
|
|
141
|
+
return nextState;
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function create(params) {
|
|
146
|
+
return (state) => {
|
|
147
|
+
function assembleError({ response, error }) {
|
|
148
|
+
if (response && [200, 201, 202].indexOf(response.statusCode) > -1)
|
|
149
|
+
return false;
|
|
150
|
+
if (error)
|
|
151
|
+
return error;
|
|
152
|
+
return new Error(`Server responded with ${response.statusCode}`);
|
|
153
|
+
}
|
|
154
|
+
const { endpoint, body } = (0, import_language_common.expandReferences)(params)(state);
|
|
155
|
+
const { username, password, baseUrl } = state.configuration;
|
|
156
|
+
const authy = username + ":" + password;
|
|
157
|
+
const bytes = import_utf8.default.encode(authy);
|
|
158
|
+
const encoded = import_base_64.default.encode(bytes);
|
|
159
|
+
const url = (0, import_url.resolve)(baseUrl + "/", endpoint);
|
|
160
|
+
console.log("Creating data at URL: " + url);
|
|
161
|
+
console.log("Post body:");
|
|
162
|
+
console.log(JSON.stringify(body, null, 4) + "\n");
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
164
|
+
import_request.default.post(
|
|
165
|
+
{
|
|
166
|
+
url,
|
|
167
|
+
json: body,
|
|
168
|
+
headers: {
|
|
169
|
+
maxauth: encoded
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
function(error, response, body2) {
|
|
173
|
+
error = assembleError({ error, response });
|
|
174
|
+
if (error) {
|
|
175
|
+
reject(error);
|
|
176
|
+
console.log(body2);
|
|
177
|
+
} else {
|
|
178
|
+
console.log(response);
|
|
179
|
+
console.log("Printing response body...\n");
|
|
180
|
+
console.log(JSON.stringify(body2, null, 4) + "\n");
|
|
181
|
+
console.log("POST succeeded.");
|
|
182
|
+
resolve(body2);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
}).then((data) => {
|
|
187
|
+
const nextState = { ...state, response: { body: data } };
|
|
188
|
+
return nextState;
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function update(params) {
|
|
193
|
+
return (state) => {
|
|
194
|
+
function assembleError({ response, error }) {
|
|
195
|
+
if (response && [200, 201, 202].indexOf(response.statusCode) > -1)
|
|
196
|
+
return false;
|
|
197
|
+
if (error)
|
|
198
|
+
return error;
|
|
199
|
+
return new Error(`Server responded with ${response.statusCode}`);
|
|
200
|
+
}
|
|
201
|
+
const { endpoint, body } = (0, import_language_common.expandReferences)(params)(state);
|
|
202
|
+
const { username, password, baseUrl } = state.configuration;
|
|
203
|
+
const authy = username + ":" + password;
|
|
204
|
+
const bytes = import_utf8.default.encode(authy);
|
|
205
|
+
const encoded = import_base_64.default.encode(bytes);
|
|
206
|
+
const url = (0, import_url.resolve)(baseUrl + "/", endpoint);
|
|
207
|
+
console.log("Performing update at URL: " + url);
|
|
208
|
+
console.log("Update data:");
|
|
209
|
+
console.log(JSON.stringify(body, null, 4) + "\n");
|
|
210
|
+
return new Promise((resolve, reject) => {
|
|
211
|
+
import_request.default.post(
|
|
212
|
+
{
|
|
213
|
+
url,
|
|
214
|
+
json: body,
|
|
215
|
+
headers: {
|
|
216
|
+
maxauth: encoded,
|
|
217
|
+
"x-methodoverride": "PATCH",
|
|
218
|
+
patchtype: "MERGE"
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
function(error, response, body2) {
|
|
222
|
+
error = assembleError({ error, response });
|
|
223
|
+
if (error) {
|
|
224
|
+
reject(error);
|
|
225
|
+
console.log(body2);
|
|
226
|
+
} else {
|
|
227
|
+
console.log("Printing response body...\n");
|
|
228
|
+
console.log(JSON.stringify(body2, null, 4) + "\n");
|
|
229
|
+
console.log("Update succeeded.");
|
|
230
|
+
resolve(body2);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
);
|
|
234
|
+
}).then((data) => {
|
|
235
|
+
const nextState = { ...state, response: { body: data } };
|
|
236
|
+
return nextState;
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function update75(params) {
|
|
241
|
+
return (state) => {
|
|
242
|
+
function assembleError({ response, error }) {
|
|
243
|
+
if (response && [200, 201, 202].indexOf(response.statusCode) > -1)
|
|
244
|
+
return false;
|
|
245
|
+
if (error)
|
|
246
|
+
return error;
|
|
247
|
+
return new Error(`Server responded with ${response.statusCode}`);
|
|
248
|
+
}
|
|
249
|
+
const { endpoint, body } = (0, import_language_common.expandReferences)(params)(state);
|
|
250
|
+
const { username, password, baseUrl } = state.configuration;
|
|
251
|
+
const authy = username + ":" + password;
|
|
252
|
+
const bytes = import_utf8.default.encode(authy);
|
|
253
|
+
const encoded = import_base_64.default.encode(bytes);
|
|
254
|
+
const url = (0, import_url.resolve)(baseUrl + "/", endpoint);
|
|
255
|
+
console.log("Performing update at URL: " + url);
|
|
256
|
+
console.log("Update data:");
|
|
257
|
+
console.log(JSON.stringify(body, null, 4) + "\n");
|
|
258
|
+
return new Promise((resolve, reject) => {
|
|
259
|
+
import_request.default.post(
|
|
260
|
+
{
|
|
261
|
+
url,
|
|
262
|
+
form: body,
|
|
263
|
+
headers: {
|
|
264
|
+
maxauth: encoded,
|
|
265
|
+
"x-methodoverride": "PATCH",
|
|
266
|
+
patchtype: "MERGE"
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
function(error, response, body2) {
|
|
270
|
+
error = assembleError({ error, response });
|
|
271
|
+
if (error) {
|
|
272
|
+
reject(error);
|
|
273
|
+
console.log(body2);
|
|
274
|
+
} else {
|
|
275
|
+
console.log("Printing update response body...\n");
|
|
276
|
+
console.log(JSON.stringify(body2, null, 4) + "\n");
|
|
277
|
+
console.log("Update succeeded.");
|
|
278
|
+
resolve(body2);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
);
|
|
282
|
+
}).then((data) => {
|
|
283
|
+
const nextState = { ...state, response: { body: data } };
|
|
284
|
+
return nextState;
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// src/index.js
|
|
290
|
+
var src_default = Adaptor_exports;
|
|
291
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
292
|
+
0 && (module.exports = {
|
|
293
|
+
alterState,
|
|
294
|
+
create,
|
|
295
|
+
dataPath,
|
|
296
|
+
dataValue,
|
|
297
|
+
each,
|
|
298
|
+
execute,
|
|
299
|
+
fetch,
|
|
300
|
+
field,
|
|
301
|
+
fields,
|
|
302
|
+
fn,
|
|
303
|
+
lastReferenceValue,
|
|
304
|
+
merge,
|
|
305
|
+
sourceValue,
|
|
306
|
+
update,
|
|
307
|
+
update75
|
|
308
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
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
|
+
alterState: () => alterState,
|
|
11
|
+
create: () => create,
|
|
12
|
+
dataPath: () => dataPath,
|
|
13
|
+
dataValue: () => dataValue,
|
|
14
|
+
each: () => each,
|
|
15
|
+
execute: () => execute,
|
|
16
|
+
fetch: () => fetch,
|
|
17
|
+
field: () => field,
|
|
18
|
+
fields: () => fields,
|
|
19
|
+
fn: () => fn,
|
|
20
|
+
lastReferenceValue: () => lastReferenceValue,
|
|
21
|
+
merge: () => merge,
|
|
22
|
+
sourceValue: () => sourceValue,
|
|
23
|
+
update: () => update,
|
|
24
|
+
update75: () => update75
|
|
25
|
+
});
|
|
26
|
+
import {
|
|
27
|
+
execute as commonExecute,
|
|
28
|
+
expandReferences
|
|
29
|
+
} from "@openfn/language-common";
|
|
30
|
+
import request from "request";
|
|
31
|
+
import { resolve as resolveUrl } from "url";
|
|
32
|
+
import base64 from "base-64";
|
|
33
|
+
import utf8 from "utf8";
|
|
34
|
+
import {
|
|
35
|
+
field,
|
|
36
|
+
fields,
|
|
37
|
+
sourceValue,
|
|
38
|
+
fn,
|
|
39
|
+
alterState,
|
|
40
|
+
each,
|
|
41
|
+
merge,
|
|
42
|
+
dataPath,
|
|
43
|
+
dataValue,
|
|
44
|
+
lastReferenceValue
|
|
45
|
+
} from "@openfn/language-common";
|
|
46
|
+
function execute(...operations) {
|
|
47
|
+
const initialState = {
|
|
48
|
+
references: [],
|
|
49
|
+
data: null
|
|
50
|
+
};
|
|
51
|
+
return (state) => {
|
|
52
|
+
return commonExecute(...operations)({ ...initialState, ...state });
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function fetch(params) {
|
|
56
|
+
return (state) => {
|
|
57
|
+
function assembleError({ response, error }) {
|
|
58
|
+
if (response && [200, 201, 202].indexOf(response.statusCode) > -1)
|
|
59
|
+
return false;
|
|
60
|
+
if (error)
|
|
61
|
+
return error;
|
|
62
|
+
return new Error(`Server responded with ${response.statusCode}`);
|
|
63
|
+
}
|
|
64
|
+
const { endpoint, query, postUrl } = expandReferences(params)(state);
|
|
65
|
+
const { username, password, baseUrl } = state.configuration;
|
|
66
|
+
const authy = username + ":" + password;
|
|
67
|
+
const bytes = utf8.encode(authy);
|
|
68
|
+
const encoded = base64.encode(bytes);
|
|
69
|
+
const url = resolveUrl(baseUrl + "/", endpoint);
|
|
70
|
+
console.log("Fetching data from URL: " + url);
|
|
71
|
+
console.log("Applying query: " + JSON.stringify(query));
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
request(
|
|
74
|
+
{
|
|
75
|
+
url,
|
|
76
|
+
qs: query,
|
|
77
|
+
headers: {
|
|
78
|
+
maxauth: encoded
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
function(error, response, getResponseBody) {
|
|
82
|
+
error = assembleError({ error, response });
|
|
83
|
+
if (error) {
|
|
84
|
+
console.error("GET failed.");
|
|
85
|
+
console.log(response);
|
|
86
|
+
reject(error);
|
|
87
|
+
} else {
|
|
88
|
+
console.log("GET succeeded.");
|
|
89
|
+
console.log("Response body: " + getResponseBody);
|
|
90
|
+
request.post(
|
|
91
|
+
{
|
|
92
|
+
url: postUrl,
|
|
93
|
+
json: JSON.parse(getResponseBody)
|
|
94
|
+
},
|
|
95
|
+
function(error2, response2, postResponseBody) {
|
|
96
|
+
error2 = assembleError({ error: error2, response: response2 });
|
|
97
|
+
if (error2) {
|
|
98
|
+
console.error("POST failed.");
|
|
99
|
+
reject(error2);
|
|
100
|
+
} else {
|
|
101
|
+
console.log("POST succeeded.");
|
|
102
|
+
resolve(getResponseBody);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
}).then((response) => {
|
|
110
|
+
console.log("Success:", response);
|
|
111
|
+
let result = typeof response === "object" ? response : JSON.parse(response);
|
|
112
|
+
return { ...state, references: [result, ...state.references] };
|
|
113
|
+
}).then((data) => {
|
|
114
|
+
const nextState = { ...state, response: { body: data } };
|
|
115
|
+
return nextState;
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function create(params) {
|
|
120
|
+
return (state) => {
|
|
121
|
+
function assembleError({ response, error }) {
|
|
122
|
+
if (response && [200, 201, 202].indexOf(response.statusCode) > -1)
|
|
123
|
+
return false;
|
|
124
|
+
if (error)
|
|
125
|
+
return error;
|
|
126
|
+
return new Error(`Server responded with ${response.statusCode}`);
|
|
127
|
+
}
|
|
128
|
+
const { endpoint, body } = expandReferences(params)(state);
|
|
129
|
+
const { username, password, baseUrl } = state.configuration;
|
|
130
|
+
const authy = username + ":" + password;
|
|
131
|
+
const bytes = utf8.encode(authy);
|
|
132
|
+
const encoded = base64.encode(bytes);
|
|
133
|
+
const url = resolveUrl(baseUrl + "/", endpoint);
|
|
134
|
+
console.log("Creating data at URL: " + url);
|
|
135
|
+
console.log("Post body:");
|
|
136
|
+
console.log(JSON.stringify(body, null, 4) + "\n");
|
|
137
|
+
return new Promise((resolve, reject) => {
|
|
138
|
+
request.post(
|
|
139
|
+
{
|
|
140
|
+
url,
|
|
141
|
+
json: body,
|
|
142
|
+
headers: {
|
|
143
|
+
maxauth: encoded
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
function(error, response, body2) {
|
|
147
|
+
error = assembleError({ error, response });
|
|
148
|
+
if (error) {
|
|
149
|
+
reject(error);
|
|
150
|
+
console.log(body2);
|
|
151
|
+
} else {
|
|
152
|
+
console.log(response);
|
|
153
|
+
console.log("Printing response body...\n");
|
|
154
|
+
console.log(JSON.stringify(body2, null, 4) + "\n");
|
|
155
|
+
console.log("POST succeeded.");
|
|
156
|
+
resolve(body2);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
}).then((data) => {
|
|
161
|
+
const nextState = { ...state, response: { body: data } };
|
|
162
|
+
return nextState;
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function update(params) {
|
|
167
|
+
return (state) => {
|
|
168
|
+
function assembleError({ response, error }) {
|
|
169
|
+
if (response && [200, 201, 202].indexOf(response.statusCode) > -1)
|
|
170
|
+
return false;
|
|
171
|
+
if (error)
|
|
172
|
+
return error;
|
|
173
|
+
return new Error(`Server responded with ${response.statusCode}`);
|
|
174
|
+
}
|
|
175
|
+
const { endpoint, body } = expandReferences(params)(state);
|
|
176
|
+
const { username, password, baseUrl } = state.configuration;
|
|
177
|
+
const authy = username + ":" + password;
|
|
178
|
+
const bytes = utf8.encode(authy);
|
|
179
|
+
const encoded = base64.encode(bytes);
|
|
180
|
+
const url = resolveUrl(baseUrl + "/", endpoint);
|
|
181
|
+
console.log("Performing update at URL: " + url);
|
|
182
|
+
console.log("Update data:");
|
|
183
|
+
console.log(JSON.stringify(body, null, 4) + "\n");
|
|
184
|
+
return new Promise((resolve, reject) => {
|
|
185
|
+
request.post(
|
|
186
|
+
{
|
|
187
|
+
url,
|
|
188
|
+
json: body,
|
|
189
|
+
headers: {
|
|
190
|
+
maxauth: encoded,
|
|
191
|
+
"x-methodoverride": "PATCH",
|
|
192
|
+
patchtype: "MERGE"
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
function(error, response, body2) {
|
|
196
|
+
error = assembleError({ error, response });
|
|
197
|
+
if (error) {
|
|
198
|
+
reject(error);
|
|
199
|
+
console.log(body2);
|
|
200
|
+
} else {
|
|
201
|
+
console.log("Printing response body...\n");
|
|
202
|
+
console.log(JSON.stringify(body2, null, 4) + "\n");
|
|
203
|
+
console.log("Update succeeded.");
|
|
204
|
+
resolve(body2);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
}).then((data) => {
|
|
209
|
+
const nextState = { ...state, response: { body: data } };
|
|
210
|
+
return nextState;
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function update75(params) {
|
|
215
|
+
return (state) => {
|
|
216
|
+
function assembleError({ response, error }) {
|
|
217
|
+
if (response && [200, 201, 202].indexOf(response.statusCode) > -1)
|
|
218
|
+
return false;
|
|
219
|
+
if (error)
|
|
220
|
+
return error;
|
|
221
|
+
return new Error(`Server responded with ${response.statusCode}`);
|
|
222
|
+
}
|
|
223
|
+
const { endpoint, body } = expandReferences(params)(state);
|
|
224
|
+
const { username, password, baseUrl } = state.configuration;
|
|
225
|
+
const authy = username + ":" + password;
|
|
226
|
+
const bytes = utf8.encode(authy);
|
|
227
|
+
const encoded = base64.encode(bytes);
|
|
228
|
+
const url = resolveUrl(baseUrl + "/", endpoint);
|
|
229
|
+
console.log("Performing update at URL: " + url);
|
|
230
|
+
console.log("Update data:");
|
|
231
|
+
console.log(JSON.stringify(body, null, 4) + "\n");
|
|
232
|
+
return new Promise((resolve, reject) => {
|
|
233
|
+
request.post(
|
|
234
|
+
{
|
|
235
|
+
url,
|
|
236
|
+
form: body,
|
|
237
|
+
headers: {
|
|
238
|
+
maxauth: encoded,
|
|
239
|
+
"x-methodoverride": "PATCH",
|
|
240
|
+
patchtype: "MERGE"
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
function(error, response, body2) {
|
|
244
|
+
error = assembleError({ error, response });
|
|
245
|
+
if (error) {
|
|
246
|
+
reject(error);
|
|
247
|
+
console.log(body2);
|
|
248
|
+
} else {
|
|
249
|
+
console.log("Printing update response body...\n");
|
|
250
|
+
console.log(JSON.stringify(body2, null, 4) + "\n");
|
|
251
|
+
console.log("Update succeeded.");
|
|
252
|
+
resolve(body2);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
);
|
|
256
|
+
}).then((data) => {
|
|
257
|
+
const nextState = { ...state, response: { body: data } };
|
|
258
|
+
return nextState;
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// src/index.js
|
|
264
|
+
var src_default = Adaptor_exports;
|
|
265
|
+
export {
|
|
266
|
+
alterState,
|
|
267
|
+
create,
|
|
268
|
+
dataPath,
|
|
269
|
+
dataValue,
|
|
270
|
+
src_default as default,
|
|
271
|
+
each,
|
|
272
|
+
execute,
|
|
273
|
+
fetch,
|
|
274
|
+
field,
|
|
275
|
+
fields,
|
|
276
|
+
fn,
|
|
277
|
+
lastReferenceValue,
|
|
278
|
+
merge,
|
|
279
|
+
sourceValue,
|
|
280
|
+
update,
|
|
281
|
+
update75
|
|
282
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openfn/language-maximo",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "An IBM Maximo EAM Language Pack for OpenFn",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"author": "Open Function Group",
|
|
7
|
+
"license": "LGPLv3",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/",
|
|
10
|
+
"types/",
|
|
11
|
+
"ast.json",
|
|
12
|
+
"configuration-schema.json"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@openfn/language-common": "^1.7.5",
|
|
16
|
+
"base-64": "^0.1.0",
|
|
17
|
+
"request": "^2.88.2",
|
|
18
|
+
"utf8": "^2.1.2"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@openfn/buildtools": "^1.0.2",
|
|
22
|
+
"@openfn/simple-ast": "0.4.1",
|
|
23
|
+
"assertion-error": "^2.0.0",
|
|
24
|
+
"babel-cli": "^6.26.0",
|
|
25
|
+
"babel-core": "^6.26.3",
|
|
26
|
+
"babel-preset-es2015": "^6.24.1",
|
|
27
|
+
"babel-preset-stage-0": "^6.24.1",
|
|
28
|
+
"chai": "^4.3.7",
|
|
29
|
+
"deep-eql": "^4.1.2",
|
|
30
|
+
"esno": "^0.16.3",
|
|
31
|
+
"mocha": "^10.1.0",
|
|
32
|
+
"nock": "^13.2.9",
|
|
33
|
+
"rimraf": "^3.0.2"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/openfn/adaptors.git"
|
|
38
|
+
},
|
|
39
|
+
"type": "module",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"import": "./dist/index.js",
|
|
43
|
+
"require": "./dist/index.cjs"
|
|
44
|
+
},
|
|
45
|
+
"./package.json": "./package.json"
|
|
46
|
+
},
|
|
47
|
+
"types": "types/index.d.ts",
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "pnpm clean && build-adaptor maximo",
|
|
50
|
+
"test": "mocha --experimental-specifier-resolution=node --no-warnings",
|
|
51
|
+
"test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings",
|
|
52
|
+
"clean": "rimraf dist types docs",
|
|
53
|
+
"pack": "pnpm pack --pack-destination ../../dist"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** @module Adaptor */
|
|
2
|
+
/**
|
|
3
|
+
* Execute a sequence of operations.
|
|
4
|
+
* Wraps `@openfn/language-common/execute`, and prepends initial state for http.
|
|
5
|
+
* @example
|
|
6
|
+
* execute(
|
|
7
|
+
* create('foo'),
|
|
8
|
+
* delete('bar')
|
|
9
|
+
* )(state)
|
|
10
|
+
* @function
|
|
11
|
+
* @param {Operations} operations - Operations to be performed.
|
|
12
|
+
* @returns {Operation}
|
|
13
|
+
*/
|
|
14
|
+
export function execute(...operations: Operations): Operation;
|
|
15
|
+
/**
|
|
16
|
+
* Make a GET request and POST it somewhere else
|
|
17
|
+
* @example
|
|
18
|
+
* fetch({
|
|
19
|
+
* endpoint: 'maxrest/rest/os/mxinventory',
|
|
20
|
+
* query: {
|
|
21
|
+
* ITEMNUM: '01226',
|
|
22
|
+
* _format: 'json',
|
|
23
|
+
* },
|
|
24
|
+
* postUrl: 'https://www.openfn.org/inbox/not-real',
|
|
25
|
+
* });
|
|
26
|
+
* @function
|
|
27
|
+
* @param {object} params - data to make the fetch
|
|
28
|
+
* @returns {Operation}
|
|
29
|
+
*/
|
|
30
|
+
export function fetch(params: object): Operation;
|
|
31
|
+
export function create(params: any): (state: any) => Promise<any>;
|
|
32
|
+
/**
|
|
33
|
+
* Make an update in Maximo 7.6 and beyond
|
|
34
|
+
* @example
|
|
35
|
+
* execute(
|
|
36
|
+
* update(params)
|
|
37
|
+
* )(state)
|
|
38
|
+
* @function
|
|
39
|
+
* @param {object} params - data to make the update
|
|
40
|
+
* @returns {Operation}
|
|
41
|
+
*/
|
|
42
|
+
export function update(params: object): Operation;
|
|
43
|
+
/**
|
|
44
|
+
* Make an upadte in Maximo 7.5
|
|
45
|
+
* @example
|
|
46
|
+
* execute(
|
|
47
|
+
* update75(params)
|
|
48
|
+
* )(state)
|
|
49
|
+
* @function
|
|
50
|
+
* @param {object} params - data to make the update
|
|
51
|
+
* @returns {Operation}
|
|
52
|
+
*/
|
|
53
|
+
export function update75(params: object): Operation;
|
|
54
|
+
export { field, fields, sourceValue, fn, alterState, each, merge, dataPath, dataValue, lastReferenceValue } from "@openfn/language-common";
|
package/types/index.d.ts
ADDED