| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643 |
1×
1×
1×
1×
1×
1×
1×
3×
3×
3×
3×
1×
2×
2×
2×
2×
2×
2×
2×
2×
2×
1×
1×
1×
1×
7×
7×
6×
4×
4×
4×
1×
1×
1×
1×
3×
3×
3×
2×
2×
2×
2×
2×
1×
4×
4×
4×
21×
4×
9×
9×
3×
1×
1×
3×
3×
3×
5×
3×
1×
9×
5×
1×
1×
1×
1×
9×
9×
4×
4×
4×
4×
2×
4×
4×
9×
8×
8×
4×
4×
8×
20×
9×
1×
5×
10×
10×
9×
9×
5×
5×
5×
5×
5×
5×
1×
6×
6×
6×
1×
1×
1×
1×
1×
5×
2×
2×
1×
1×
1×
1×
2×
2×
2×
2×
1×
1×
7×
1×
1×
1×
1×
1×
3×
1×
1×
1×
1×
1×
1×
1×
4×
4×
4×
3×
3×
3×
3×
3×
3×
1×
1×
2×
1×
3×
3×
1×
13×
13×
1×
1×
4×
3×
3×
1×
1×
1×
1×
1×
1×
1×
18×
18×
18×
1×
1×
17×
2×
2×
1×
15×
15×
5×
5×
10×
2×
2×
8×
5×
5×
3×
1×
1×
2×
1×
1×
1×
1×
1×
5×
5×
5×
5×
14×
5×
5×
1×
2×
2×
2×
2×
2×
1×
2×
2×
1×
1×
1×
2×
2×
1×
1×
1×
1×
1×
1×
2×
2×
2×
2×
2×
2×
2×
2×
2×
1×
3×
3×
1×
1×
1×
4×
4×
1×
1×
1×
1×
3×
3×
2×
2×
1×
1×
3×
1×
4×
4×
2×
2×
2×
2×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
| 'use strict';
const _ = require('lodash');
const url = require('url');
const fs = require('fs');
const backend = require('./lib/backend');
const util = require('./lib/util');
const pager = require('./lib/pager');
const oauth1 = require('./lib/oauth1a');
// The main receiver. This method is the primary handler for any gateway
// or library usage.
const elementHandler = (element) => (event, context) => {
console.log('Received event:', JSON.stringify(event, null, 2));
const verror = verifyElement(element);
if (verror != null) {
return context.fail(util.failure(500, verror));
}
const start = new Date().getTime();
const apiCtx = util.apiGateway(context);
const outCtx = {
succeed: o => {
const end = new Date().getTime();
console.log("success in", (end - start));
return apiCtx.succeed(o);
},
fail: e => {
const end = new Date().getTime();
console.log("fail in", (end - start));
apiCtx.fail(e);
},
done: (e, o) => {
const end = new Date().getTime();
console.log("done in", (end - start));
apiCtx.done(e, o);
}
};
try {
convert(event, element, (error, output) => {
if (util.notNull(error)) { return outCtx.fail(util.failure(400, error)); }
pager.page(backend.send)(outCtx, output);
});
} catch (e) {
console.warn(e);
outCtx.fail(util.failure(500, e));
}
};
const verifyElement = (element) => {
const versionTag = element.version;
// Only for initial version only: versionTag is allowed to be null /
// empty
if (versionTag == null) { return null; }
if (!_.isString(versionTag)) { return "version is not a string"; }
const dot = versionTag.indexOf('.');
const major = dot == -1 ? versionTag : versionTag.substr(0, dot);
if (major == '1') { return null; }
return `Incorrect version: ${major}`;
}
// This package should no longer provide the node handler directly:
// instead, it should be used as a dependency for the actual per-element
// handler packages. Each of those handler packages should contain
// nothing more than:
//
// 1. a dependency to this package,
// 2. the per-element element.json file (in data/element.json)
// 3. the following code in its main.js (also included here for
// backwards compatibility)
//
// const celib = // .. require this package
// const element = require('./data/element.json');
// exports.handler = celib.handler(element);
//
let mainHandler;
Iif(fs.existsSync(`${__dirname}/data/element.json`)) {
const element = require('./data/element.json');
mainHandler = elementHandler(element);
}
// Convert an API Gateway-style input into an http options object that
// can be used to make a backend request.
const convert = (input, element, cb) => {
// This algorithm is (very roughly) based on
// RequestHelper::generateRequestValues()
const resources = element.resources || [];
const rmp = findBestResource(resources, input);
if (_.isEmpty(rmp)) { return cb("No matching resource in builder JSON"); }
const rsrc = rmp[0];
const mpath = rmp[1];
input.mappedPaths = mpath;
let output = pseudoInstance(input, element, rsrc, mpath);
return cb(null, output);
}
// Find the resource that best serves the given request, according to
// its path and method.
const findBestResource = (resources, input) => {
let inputPath = util.constructPath(input.operation.path, v => input.paths[v]);
input.constructedPath = inputPath;
// TODO: consistency: More closely match the Ant Path matching in
// Voldemort
let curly = /{[^}]*}/g;
let rSort = _.orderBy(resources, [r =>(r.path || '').replace(curly, '{}').length], ['desc'])
for (let r of rSort) {
let mp = util.matchPath(r.path, inputPath);
if (util.notNull(mp) &&
(r.method || 'GET').toUpperCase() ==
(input.operation.method || 'GET').toUpperCase()) { return [r, mp]; }
}
return null;
}
// Extract values from the input, element and instance
const extractValues = (input, output, element, rsrc, mpath) => {
const parameters = element.parameters || [];
const rparams = rsrc.parameters || [];
let values = {};
parameters.concat(rparams).forEach(p => values[`${p.vendorName}:${p.vendorType}`] = {
parameter: p,
value: getInputValue(p, output, element, input, mpath)
});
return values;
}
// A Lambda doesn't actually use an element instance. However, certain
// properties normally associated with an instance (for example, the
// oauth user token) may come in on the request somewhere. We set up
// these values here.
const pseudoInstance = (input, element, rsrc, mpath) => {
// Instance resources are REST APIs by default.
let output = {
headers: {
"Content-Type": 'application/json',
"Accept": 'application/json'
},
input: input,
original_input: _.cloneDeep(input),
element: element,
resource: rsrc,
findConfig: function(key) { return findConfigValue(key, this, element); },
getConfig: function() { return getConfigMap(this, element); },
finalize: function(in2) {
Eif (!util.notNull(in2)) { in2 = {}; }
return updateInput(in2, this, element, rsrc, mpath);
},
convertResponse: function(resp) { return convertResponse(this, resp); }
};
// Magical replacement: replace each 'x-vendor-Something' header with
// a 'Something' header. Do this first, so that specific parameters or
// hooks can override them later.
const prefix = 'x-vendor-';
for (let k of Object.keys(input.headers || {})) {
Eif (k.toLowerCase().startsWith(prefix)) {
let realk = k.substr(prefix.length);
Iif (_.isEmpty(output.headers)) { output.headers = {}; }
if(realk.startsWith('oauth_')) {
realk = realk.replace(/_/g, '.');
}
output.headers[realk] = input.headers[k];
input.headers[realk] = input.headers[k];
}
}
// Also, if a header comes in whose key matches a configuration key,
// set the output's configuration for that value. We later use the
// "findConfig" function to pull these back up. In this sense,
// "output.configuration" acts as a bank for configuration data that
// would normally be on an instance.
for (let k of Object.keys(input.headers || {})) {
let kr;
if(k.toLowerCase().includes('oauth')){
kr = k.replace(/_/g, '.');
}
else {
kr = k;
}
for (let c of (element.configuration || [])) {
Iif (util.notEmpty(c.key) && kr.toLowerCase() === c.key.toLowerCase()) {
if (_.isEmpty(output.configuration)) { output.configuration = {}; }
output.configuration[c.key] = input.headers[k];
delete input.headers[k];
}
}
}
return output;
}
// Create the output from the extracted values
const updateOutput = (output, input, values, element, rsrc) => {
for (let k of Object.keys(values)) {
let v = values[k];
if(util.notNull(v.value)){
Iif(typeof(v.value) === 'number' && isNaN(v.value)){ break;}
setOutputValue(v.parameter, v.value, input, output);
}
}
//if the output has bodyField, then merge the body and bodyField to body and remove bodyField
Eif(!_.isNull(output.bodyField)) {
Iif (_.isNull(output.body)) { output.body = {}; }
output.body = _.extend(output.body, output.bodyField);
delete output.bodyField;
}
output.pathname = util.constructPath(rsrc.vendorPath, v => output.paths ? output.paths[v] : `{${v}}`);
output.constructedPath = output.pathname
}
// Set up the proper security headers and signatures on the output.
const secureOutput = (output, element, rsrc) => {
Iif ((element.protocolType || 'http') !== 'http') return;
const authType = (element.authentication || {}).type
if (authType === 'oauth2') {
Eif (!util.notNull(output.headers)) { output.headers = {}; }
Eif (!util.notNull(output.headers["authorization"])) {
let userToken = output.findConfig('oauth.user.token');
Eif (util.notNull(userToken)) {
output.headers["authorization"] = `Bearer ${userToken}`;
}
}
} else if (authType === 'oauth1') {
let url;
if (output.pathname.startsWith('http:') ||
output.pathname.startsWith('https:')) {
url = output.pathname;
} else {
let baseUrl = output.findConfig('base.url');
Iif (util.notNull(baseUrl)) { url = baseUrl + output.pathname; }
else { url = output.pathname; }
}
let method = output.resource.vendorMethod || output.resource.method;
let oauthParams = oauth1.signReqParams(url, output.form || {},
output.findConfig('oauth.authorization.url'),
output.findConfig('oauth.token.url'), method,
output.findConfig('oauth.api.key'), output.findConfig('oauth.api.secret'),
output.findConfig('oauth.user.token'),
output.findConfig('oauth.user.token.secret'), output.query || {});
let headerOrQuery = output.findConfig('oauth.request.authorization.type');
if ((headerOrQuery || 'query').toLowerCase() == 'query') {
Eif (!util.notNull(output.query)) { output.query = {}; }
for (let k of Object.keys(oauthParams)) {
output.query[k] = oauthParams[k]
}
} else {
Eif (output.findConfig('oauth.signature.encoded')) {
oauthParams['oauth_signature'] =
encodeURIComponent(oauthParams['oauth_signature']);
}
let auth = `OAuth oauth_nonce="${oauthParams.oauth_nonce || ''}",` +
`oauth_timestamp="${oauthParams.oauth_timestamp || ''}",` +
`oauth_version="${oauthParams.oauth_version || ''}",` +
`oauth_signature_method="${oauthParams.oauth_version || ''}",` +
`oauth_consumer_key="${oauthParams.oauth_consumer_key || ''}",` +
`oauth_token="${oauthParams.oauth_token || ''}",` +
`oauth_signature="${oauthParams.oauth_signature || ''}"`;
Eif (!util.notNull(output.headers)) { output.headers = {}; }
output.headers.Authorization = auth;
}
} else if (authType === 'basic') {
Eif (!util.notNull(output.headers)) { output.headers = {}; }
Eif (!util.notNull(output.headers["authorization"])) {
let user = output.findConfig('username');
let pass = output.findConfig('password');
Eif (user && pass) {
output.headers["authorization"] = 'Basic ' +
util.encodeBase64(user + ':' + pass);
}
}
}
}
// Finalize the output object so that it's in the correct form to be
// used as http options.
const finalizeOutput = (output, element, rsrc) => {
Iif ((element.protocolType || 'http') !== 'http') return;
let baseUrl = output.findConfig('base.url');
if (util.notNull(baseUrl)) {
let parsedObj = url.parse(baseUrl + output.pathname)
output.protocol = parsedObj.protocol;
output.hostname = parsedObj.hostname;
Iif (util.notNull(parsedObj.port)) output.port = parsedObj.port;
output.pathname = parsedObj.pathname;
output.method = rsrc.vendorMethod || rsrc.method;
} else {
return "No base URL found in configuration";
}
}
// Run all the non-legacy request hooks in-process.
const runPreRequestHooks = (input, mpath, output, element, rsrc) => {
for (let hook of (rsrc.hooks || []).concat(element.hooks || [])) {
if (hook.type !== 'preRequest') { continue; }
if (!util.notNull(hook.isLegacy)) { hook.isLegacy = true; }
if (hook.isLegacy) { continue; }
if (hook.mimeType !== 'application/javascript') {
console.warn("can't execute non-javascript hook");
continue;
}
// TODO: `safeAddQueryAttributeList`, `safeAddConvertObjectToMap`,
// configuration and full vendor_url construction (see
// ScriptHook::buildHookContext())
// When the hook succeeds, this is what we do.
const done = data => {
let o;
if(util.notNull(data)) {
if (util.notNull(o = data.continue)) { output.shouldContinue = data.continue; }
if (util.notNull(o = data.response_status_code)) { output.statusCode = o; }
if (util.notNull(o = data.response_body)) {output.responseBody = o;}
if (util.notNull(o = data.request_vendor_body)) {output.body = o;}
if (util.notNull(o = data.request_vendor_headers)) {output.headers = o;}
if (util.notNull(o = data.request_vendor_path)) {
//If the request_vendor_path is passed from pre-hook, regenerate the vendorPath
output.constructPath = o;
output.pathname = o;
finalizeOutput(output, element, rsrc);
}
if (util.notNull(o = data.request_vendor_parameters)) {output.query = o;}
if (util.notNull(o = data.request_vendor_method)) {
output.method = o.toUpperCase();
}
}
}
output.continue = true;
// When the hook fails, this is what we do.
const fail = error => console.warn("preRequest hook failure", error);
let cont = true;
let test = null;
let fn = new Function('request_body', 'request_body_map', 'request_headers', 'request_path',
'request_parameters', 'request_method', 'request_vendor_parameters',
'request_vendor_path', 'request_vendor_headers',
'request_vendor_body', 'request_vendor_url',
'request_vendor_method', 'request_expression',
'configuration', 'done', 'fail','contin', 'request_vendor_body_map', hook.body);
fn(input.body, input.body, input.headers, input.constructedPath, input.queryParameters,
(input.operation || {}).method, output.query, output.constructedPath,
output.headers, output.body, output.url, output.method,
input.query, output.getConfig(), done, fail, output.continue, output.body);
}
}
// Keep our derived used-by-http values up to date.
const deriveOutput = (output, element) => {
Iif ((element.protocolType || 'http') !== 'http') return;
output.path = output.pathname + url.format({query: output.query});
}
// Find an input specified by a parameter.
const getInputValue = (param, output, element, input, mpath) => {
const type = param.type;
switch (type) {
case 'body': return input.body;
case 'value': return param.name;
case 'configuration':
return output.findConfig(param.name);
case 'path':
const paths = mpath || {};
return paths[param.name];
case 'query':
const qp = input.queryParameters || {};
// Sometimes query params come in the body?
// Looking at you Hubspot
return qp[param.name] || input.body[param.name];
case 'header':
const hp = input.headers || {};
return hp[param.name];
case 'multipart':
return {
Key: input.body['x-s3-filename'],
Bucket: input.body['x-s3-bucketname']
};
default: console.warn("Unrecognized input parameter type", type);
}
}
// Set an output specified by a parameter.
const setOutputValue = (param, value, input, output) => {
const vname = param.vendorName;
const vtype = param.vendorType;
if (vtype === 'body' && param.type !== 'multipart') {
Iif(param.type === 'value') {
output.replBody = param.name;
}
output.body = value;
} else if(param.type === 'multipart') {
output.file = value;
// If the vendor expects the upload as a body
// Tell our reqHandler to perform this as an encoded
// file upload
if(vtype === 'body') {
output.reqHandler = 'encodedUpload';
}
} else Eif (util.notEmpty(vname)) {
if (vtype === 'path') {
Eif (_.isEmpty(output.paths)) { output.paths = {}; }
output.paths[vname] = value;
} else if (vtype === 'query') {
Eif (_.isEmpty(output.query)) { output.query = {}; }
output.query[vname] = value;
} else if (vtype === 'header') {
Iif (_.isEmpty(output.headers)) { output.headers = {}; }
output.headers[vname] = value;
} else if (vtype === 'bodyField') {
Eif (_.isEmpty(output.bodyField)) { output.bodyField = {}; }
output.bodyField[vname] = value;
} else if(vtype === 'bodyToken') {
Eif (_.isEmpty(output.bodyTokens)) { output.bodyTokens = {}; }
Eif(param.type !== 'body') {
output.bodyTokens[vname] = util.getDeepPropValue(param.name, output);
} else {
output.bodyTokens[vname] = input.body;
}
} else Eif(vtype === 'no-op') {
// Don't do anything?
} else {
console.warn("unrecognized output parameter type", vtype);
}
}
}
// Find a configuration value from its key, either from the output
// configuration (if it exists), or from the element's default value.
const findConfigValue = (key, output, element) => {
const eConfig = element.configuration || [];
const oConfig = output.configuration || {};
let oValue = oConfig[key];
Iif (util.notNull(oValue)) { return oValue; }
let configItem = _.find(eConfig, c => c.key === key);
Eif (util.notNull(configItem)) {
return util.constructPath(configItem.defaultValue, v => output.findConfig(v) || `{${v}}`);
}
return null;
}
// Find all configuration keys and values, from the output configuration
// (if it exists), or from the element's default value.
const getConfigMap = (output, element) => {
const oConfig = _.clone(output.configuration || {});
for (let ec of element.configuration || []) {
Eif (!util.notNull(oConfig[ec.key])) {
oConfig[ec.key] = util.constructPath(ec.defaultValue,
v => output.findConfig(v) || `{${v}}`)
}
}
return oConfig;
}
// Updates the output for a given set of input values. During paging,
// individual page inputs (especially the input query parameters for
// 'page' and 'pageSize') will be set for each page.
const updateInput = (input, output, element, rsrc, mpath) => {
// only update values that are given in the input
output.input = _.merge(_.cloneDeep(output.original_input), input);
// Hydrate the the continuationToken
// Similar to LambdRequest::hydrate in the java
if( util.notNull(output.input.queryParameters)
&& output.input.queryParameters.hasOwnProperty('continuationToken')
&& util.notNull(_.get(output.input.queryParameters, 'continuationToken'))
) {
Eif(!util.notNull(output.query)) { output.query = {} }
output.input.queryParameters['nextPage'] = _.get(output.input.queryParameters, 'continuationToken');
output.input.queryParameters['page'] = _.get(output.input.queryParameters, 'continuationToken');
}
//If a pageSize is not passed or not present, set the default pageSize to 10
//as the pageSize can be used in prehook
if ((output.resource.parameters || []).filter(p =>
(p.name === 'page' || p.name === 'pageSize') &&
p.type === 'query').length > 0) {
let qParams = output.input.queryParameters || {};
Eif(qParams.pageSize === null || qParams.pageSize === undefined || isNaN(qParams.pageSize)){
qParams.pageSize = 10; //default the pageSize to 10
}
Eif(qParams.page === null || qParams.page === undefined || isNaN(qParams.page)){
qParams.page = 1; //default the pageSize to 1
}
output.input.queryParameters = qParams;
}
let values = extractValues(output.input, output, element, rsrc, mpath);
updateOutput(output, output.input, values, element, rsrc);
finalizeOutput(output, element, rsrc);
runPreRequestHooks(output.input, mpath, output, element, rsrc);
secureOutput(output, element, rsrc);
convertRequest(output);
deriveOutput(output, element);
output.runPreRequestHooks = (out) => { runPreRequestHooks(output.input, mpath, out, element, rsrc); }
return output;
}
const convertRequest = (output) => {
const rootKey = (output.resource.rootKey || '').split('|')[0];
if (util.notEmpty(rootKey) && util.notNull(output.body)) {
const body = output.body;
output.body = _.set({}, rootKey, body)
}
}
// Tweaks a response to be more Cloud-Elements like by applying rootKey
// transformations. During paging, this is applied to each individual
// paged response, and not the final merged response.
const convertResponse = (output, response) => {
// We run the post request hooks first, since they might actually
// set the response body to match the rootKey
try {
runPostRequestHooks(output, response);
} catch (ex) {
response.originalBody = response.body;
response.body = {errors: "postRequestHook failure: " + ex.toString()}
response.statusCode = 500;
return response;
}
const rootKey = (output.resource.rootKey || '').split('|')[1];
if (util.notEmpty(rootKey) && (response.statusCode >= 200 && response.statusCode <= 207)) {
let rootKeyRes = _.get(response.body, rootKey);
//Set the response body only when it is undefined
if(rootKeyRes !== undefined) {
response.originalBody = response.body;
response.body = rootKeyRes;
}
}
return response;
}
// Run all the non-legacy request hooks in-process.
const runPostRequestHooks = (output, response) => {
const rsrc = output.resource || {};
for (let hook of (rsrc.hooks || []).concat(output.element.hooks || [])) {
Iif (hook.type !== 'postRequest') { continue; }
Iif (!util.notNull(hook.isLegacy)) { hook.isLegacy = true; }
Iif (hook.isLegacy) { continue; }
if (hook.mimeType !== 'application/javascript') {
console.warn("can't execute non-javascript hook");
continue;
}
// When the hook succeeds, this is what we do.
const done = data => {
let o;
if (util.notNull(data)) {
if (util.notNull(data.response_body)) { response.body = data.response_body; }
if (util.notNull(data.response_headers)) { response.headers = data.response_headers; }
if (util.notNull(data.response_status_code)) {
response.statusCode = data.response_status_code;
}
}
}
// When the hook fails, this is what we do.
const fail = error => console.warn("postRequest hook failure", error);
let fn = new Function('response_body', 'response_body_raw',
'response_body_map', 'response_headers', 'response_status_code',
'response_iserror', 'response_body_raw_map', 'response_error',
'request_body', 'request_headers', 'request_path',
'request_parameters', 'request_method', 'request_vendor_parameters',
'request_vendor_path', 'request_vendor_headers',
'request_vendor_body', 'request_vendor_url',
'request_vendor_method', 'configuration', 'done', 'fail', hook.body);
const body = response.body || {};
const headers = response.headers || {};
const raw_body_map = _.map(body, JSON.stringify)
const code = response.statusCode || 0;
const input = output.input || {};
const mpath = input.mappedPaths || {};
fn(body, JSON.stringify(body), body, headers, code,
code >= 200 && code <= 207, raw_body_map, response.status,
input.body, input.headers, input.constructedPath, input.queryParameters,
(input.operation || {}).method, output.query, output.constructedPath,
output.headers, output.body, output.url, output.method,
output.getConfig(), done, fail);
}
}
module.exports = {
handler: elementHandler,
mainHandler: mainHandler,
convert: convert,
verifyElement: verifyElement,
convertResponse: convertResponse,
convertRequest: convertRequest,
getConfigMap: getConfigMap,
secureOutput: secureOutput,
findBestResource: findBestResource,
extractValues: extractValues,
pseudoInstance: pseudoInstance,
updateOutput: updateOutput,
finalizeOutput: finalizeOutput,
runPreRequestHooks: runPreRequestHooks,
deriveOutput: deriveOutput,
getInputValue: getInputValue,
setOutputValue: setOutputValue,
findConfigValue: findConfigValue,
updateInput: updateInput,
runPostRequestHooks: runPostRequestHooks,
}
|