meadow-endpoints 2.0.17 → 2.0.20
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meadow-endpoints",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.20",
|
|
4
4
|
"description": "Automatic API endpoints for Meadow data.",
|
|
5
5
|
"main": "source/Meadow-Endpoints.js",
|
|
6
6
|
"scripts": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"async": "2.6.1",
|
|
56
56
|
"JSONStream": "^1.3.5",
|
|
57
57
|
"meadow": "~1.0.32",
|
|
58
|
-
"meadow-filter": "^1.0.
|
|
58
|
+
"meadow-filter": "^1.0.5",
|
|
59
59
|
"orator": "~2.0.2",
|
|
60
60
|
"underscore": "1.9.1"
|
|
61
61
|
}
|
|
@@ -418,6 +418,17 @@ var MeadowEndpoints = function()
|
|
|
418
418
|
return fCallback();
|
|
419
419
|
};
|
|
420
420
|
|
|
421
|
+
var _InvokeSetupCallback;
|
|
422
|
+
var getInvokeSetupCallback = function()
|
|
423
|
+
{
|
|
424
|
+
return _InvokeSetupCallback;
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
var setInvokeSetupCallback = function(fCallback)
|
|
428
|
+
{
|
|
429
|
+
_InvokeSetupCallback = fCallback;
|
|
430
|
+
};
|
|
431
|
+
|
|
421
432
|
/**
|
|
422
433
|
* Invoke a meadow endpoint programmatically
|
|
423
434
|
*
|
|
@@ -470,6 +481,10 @@ var MeadowEndpoints = function()
|
|
|
470
481
|
//internal invoke mark as authenticated (because this is not called via webservice)
|
|
471
482
|
pRequest.EndpointAuthenticated = true;
|
|
472
483
|
|
|
484
|
+
if (_InvokeSetupCallback && typeof(_InvokeSetupCallback) == 'function')
|
|
485
|
+
{
|
|
486
|
+
_InvokeSetupCallback(pRequest, pResponse, typeof(pOptions) === 'object' && pOptions);
|
|
487
|
+
}
|
|
473
488
|
return fStageComplete();
|
|
474
489
|
},
|
|
475
490
|
function(fStageComplete)
|
|
@@ -514,6 +529,8 @@ var MeadowEndpoints = function()
|
|
|
514
529
|
// Expose the DAL
|
|
515
530
|
DAL: _Meadow,
|
|
516
531
|
|
|
532
|
+
getInvokeSetupCallback: getInvokeSetupCallback,
|
|
533
|
+
setInvokeSetupCallback: setInvokeSetupCallback,
|
|
517
534
|
invokeEndpoint: invokeEndpoint,
|
|
518
535
|
|
|
519
536
|
// Factory
|
|
@@ -60,6 +60,7 @@ var doUpdate = function(pRecordToModify, pRequest, pResponse, fCallback, pOption
|
|
|
60
60
|
//send the original record to the Authorizer so it can verify ownership/etc
|
|
61
61
|
// TODO: Because the authorizer looks in the request for the record, we need to fix this somehow to work asynchronously.
|
|
62
62
|
pRequest.UpdatingRecord = pRecordToModify;
|
|
63
|
+
pRequest.OriginalRecord = pOriginalRecord;
|
|
63
64
|
pRequest.Record = pOriginalRecord;
|
|
64
65
|
|
|
65
66
|
pRequest.Authorizers.authorizeRequest('Update', pRequest, function(err)
|
|
@@ -14,6 +14,7 @@ var libAsync = require('async');
|
|
|
14
14
|
|
|
15
15
|
var doCreate = require('./Meadow-Operation-Create.js');
|
|
16
16
|
var doUpdate = require('./Meadow-Operation-Update.js');
|
|
17
|
+
const util = require("util");
|
|
17
18
|
|
|
18
19
|
var doUpsert = function(pRecordToUpsert, pRequest, pResponse, fCallback)
|
|
19
20
|
{
|
|
@@ -92,11 +93,29 @@ var doUpsert = function(pRecordToUpsert, pRequest, pResponse, fCallback)
|
|
|
92
93
|
{
|
|
93
94
|
if (pError)
|
|
94
95
|
{
|
|
95
|
-
|
|
96
|
+
let errorMessage;
|
|
97
|
+
// attempt to unwrap the error
|
|
98
|
+
if (pError instanceof Error) {
|
|
99
|
+
errorMessage = pError.message;
|
|
100
|
+
} else if (pError && pError.Message) {
|
|
101
|
+
errorMessage = pError.Message;
|
|
102
|
+
} else {
|
|
103
|
+
errorMessage = pError;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
pRecordToUpsert.Error = 'Error upserting record: '+errorMessage;
|
|
96
107
|
pRequest.RecordUpsertError = true;
|
|
97
108
|
pRequest.RecordUpsertErrorMessage = pError;
|
|
98
109
|
pRequest.UpsertedRecords.push(pRecordToUpsert);
|
|
99
|
-
|
|
110
|
+
// use nodejs util to pretty print our error message
|
|
111
|
+
const prettyPrintedError = util.inspect(pError, {
|
|
112
|
+
maxArrayLength: 10,
|
|
113
|
+
compact: true,
|
|
114
|
+
showHidden: true,
|
|
115
|
+
depth: 3,
|
|
116
|
+
maxStringLength: 200,
|
|
117
|
+
});
|
|
118
|
+
pRequest.CommonServices.log.error('Error upserting record: '+prettyPrintedError, {SessionID:pRequest.UserSession.SessionID, RequestID:pRequest.RequestUUID, RequestURL:pRequest.url, Action:pRequest.DAL.scope+'-'+pRequest.MeadowOperation, Stack: pError.stack }, pRequest);
|
|
100
119
|
}
|
|
101
120
|
|
|
102
121
|
return fCallback();
|
|
@@ -1156,8 +1156,7 @@ suite
|
|
|
1156
1156
|
{
|
|
1157
1157
|
// Expect response to be the record we just created.
|
|
1158
1158
|
var tmpResult = JSON.parse(pResponse.text);
|
|
1159
|
-
|
|
1160
|
-
Expect(tmpResult.Valid).to.be.false;
|
|
1159
|
+
Expect(tmpResult.Error).to.equal('Record validate failure - a valid JSON object is required.');
|
|
1161
1160
|
fDone();
|
|
1162
1161
|
}
|
|
1163
1162
|
);
|
|
@@ -1538,6 +1537,35 @@ suite
|
|
|
1538
1537
|
{
|
|
1539
1538
|
var tmpCreatedRecordGUID;
|
|
1540
1539
|
|
|
1540
|
+
test
|
|
1541
|
+
(
|
|
1542
|
+
'invoke: setup method is called',
|
|
1543
|
+
function(fDone)
|
|
1544
|
+
{
|
|
1545
|
+
_MockSessionValidUser.UserRoleIndex = 2;
|
|
1546
|
+
let setupCallCount = 0;
|
|
1547
|
+
let passedRequest, passedResponse, passedOriginalRequest;
|
|
1548
|
+
_MeadowEndpoints.setInvokeSetupCallback((req, res, origReq) =>
|
|
1549
|
+
{
|
|
1550
|
+
++setupCallCount;
|
|
1551
|
+
passedRequest = req;
|
|
1552
|
+
passedResponse = res;
|
|
1553
|
+
passedOriginalRequest = origReq;
|
|
1554
|
+
});
|
|
1555
|
+
const originalRequest = {UserSession: _MockSessionValidUser};
|
|
1556
|
+
_MeadowEndpoints.invokeEndpoint('Read', {IDRecord: 2}, originalRequest,
|
|
1557
|
+
function(pError, pResponse)
|
|
1558
|
+
{
|
|
1559
|
+
Expect(setupCallCount).to.equal(1);
|
|
1560
|
+
Expect(passedOriginalRequest).to.equal(originalRequest);
|
|
1561
|
+
Expect(passedRequest).to.be.an('object');
|
|
1562
|
+
Expect(passedResponse).to.be.an('object');
|
|
1563
|
+
|
|
1564
|
+
fDone();
|
|
1565
|
+
}
|
|
1566
|
+
);
|
|
1567
|
+
}
|
|
1568
|
+
);
|
|
1541
1569
|
test
|
|
1542
1570
|
(
|
|
1543
1571
|
'invoke create: create a record',
|