meadow-endpoints 2.0.18 → 2.0.21
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.21",
|
|
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
|
}
|
|
@@ -43,7 +43,7 @@ var doAPIDeleteEndpoint = function(pRequest, pResponse, fNext)
|
|
|
43
43
|
tmpIDRecord = pRequest.body[pRequest.DAL.defaultIdentifier];
|
|
44
44
|
}
|
|
45
45
|
// Although the delete request does allow multiple deletes, we require an identifier.
|
|
46
|
-
if (tmpIDRecord < 1)
|
|
46
|
+
if (!parseInt(tmpIDRecord) || tmpIDRecord < 1)
|
|
47
47
|
{
|
|
48
48
|
return pRequest.CommonServices.sendError('Record delete failure - a valid record ID is required in the passed-in record.', pRequest, pResponse, fNext);
|
|
49
49
|
}
|
|
@@ -41,7 +41,7 @@ var doAPIUpdateEndpoint = function(pRequest, pResponse, fNext)
|
|
|
41
41
|
{
|
|
42
42
|
return pRequest.CommonServices.sendError('Record update failure - a valid record is required.', pRequest, pResponse, fNext);
|
|
43
43
|
}
|
|
44
|
-
if (pRequest.body[pRequest.DAL.defaultIdentifier] < 1)
|
|
44
|
+
if (!parseInt(pRequest.body[pRequest.DAL.defaultIdentifier]) || pRequest.body[pRequest.DAL.defaultIdentifier] < 1)
|
|
45
45
|
{
|
|
46
46
|
return pRequest.CommonServices.sendError('Record update failure - a valid record ID is required in the passed-in record.', pRequest, pResponse, fNext);
|
|
47
47
|
}
|
|
@@ -18,7 +18,7 @@ var doUpdate = function(pRecordToModify, pRequest, pResponse, fCallback, pOption
|
|
|
18
18
|
pRequest.MeadowOperation = (typeof(pRequest.MeadowOperation) === 'string') ? pRequest.MeadowOperation : 'Update';
|
|
19
19
|
|
|
20
20
|
// If there is not a default identifier or cached record, fail
|
|
21
|
-
if ((pRecordToModify[pRequest.DAL.defaultIdentifier] < 1) && (typeof(pOptionalCachedUpdatingRecord) === 'undefined'))
|
|
21
|
+
if ((!parseInt(pRecordToModify[pRequest.DAL.defaultIdentifier]) || pRecordToModify[pRequest.DAL.defaultIdentifier] < 1) && (typeof(pOptionalCachedUpdatingRecord) === 'undefined'))
|
|
22
22
|
{
|
|
23
23
|
return fCallback('Record update failure - a valid record ID is required in the passed-in record.');
|
|
24
24
|
}
|
|
@@ -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();
|
|
@@ -961,6 +961,48 @@ suite
|
|
|
961
961
|
}
|
|
962
962
|
);
|
|
963
963
|
test
|
|
964
|
+
(
|
|
965
|
+
'update: update a record with a missing ID',
|
|
966
|
+
function(fDone)
|
|
967
|
+
{
|
|
968
|
+
// Update animal but don't provide ID
|
|
969
|
+
var tmpRecord = { Type:'Corgi' };
|
|
970
|
+
libSuperTest('http://localhost:9080/')
|
|
971
|
+
.del('1.0/FableTest')
|
|
972
|
+
.send(tmpRecord)
|
|
973
|
+
.end(
|
|
974
|
+
function(pError, pResponse)
|
|
975
|
+
{
|
|
976
|
+
// Expect response to be the count of deleted records.
|
|
977
|
+
var tmpResult = JSON.parse(pResponse.text);
|
|
978
|
+
Expect(tmpResult.Error).to.contain('a valid record ID is required');
|
|
979
|
+
fDone();
|
|
980
|
+
}
|
|
981
|
+
);
|
|
982
|
+
}
|
|
983
|
+
);
|
|
984
|
+
test
|
|
985
|
+
(
|
|
986
|
+
'update: update a record with a malformed ID',
|
|
987
|
+
function(fDone)
|
|
988
|
+
{
|
|
989
|
+
// Update animal but don't provide ID
|
|
990
|
+
var tmpRecord = { IDAnimal: { ID: 3 }, Type:'Corgi' };
|
|
991
|
+
libSuperTest('http://localhost:9080/')
|
|
992
|
+
.del('1.0/FableTest')
|
|
993
|
+
.send(tmpRecord)
|
|
994
|
+
.end(
|
|
995
|
+
function(pError, pResponse)
|
|
996
|
+
{
|
|
997
|
+
// Expect response to be the count of deleted records.
|
|
998
|
+
var tmpResult = JSON.parse(pResponse.text);
|
|
999
|
+
Expect(tmpResult.Error).to.contain('a valid record ID is required');
|
|
1000
|
+
fDone();
|
|
1001
|
+
}
|
|
1002
|
+
);
|
|
1003
|
+
}
|
|
1004
|
+
);
|
|
1005
|
+
test
|
|
964
1006
|
(
|
|
965
1007
|
'update: update a record',
|
|
966
1008
|
function(fDone)
|
|
@@ -1006,7 +1048,28 @@ suite
|
|
|
1006
1048
|
);
|
|
1007
1049
|
test
|
|
1008
1050
|
(
|
|
1009
|
-
'delete: delete a record with a
|
|
1051
|
+
'delete: delete a record with a missing ID',
|
|
1052
|
+
function(fDone)
|
|
1053
|
+
{
|
|
1054
|
+
// Delete animal but don't provide ID
|
|
1055
|
+
var tmpRecord = { Type: 'Corgi' };
|
|
1056
|
+
libSuperTest('http://localhost:9080/')
|
|
1057
|
+
.del('1.0/FableTest')
|
|
1058
|
+
.send(tmpRecord)
|
|
1059
|
+
.end(
|
|
1060
|
+
function(pError, pResponse)
|
|
1061
|
+
{
|
|
1062
|
+
// Expect response to be the count of deleted records.
|
|
1063
|
+
var tmpResult = JSON.parse(pResponse.text);
|
|
1064
|
+
Expect(tmpResult.Error).to.contain('a valid record ID is required');
|
|
1065
|
+
fDone();
|
|
1066
|
+
}
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
);
|
|
1070
|
+
test
|
|
1071
|
+
(
|
|
1072
|
+
'delete: delete a record with a bad ID',
|
|
1010
1073
|
function(fDone)
|
|
1011
1074
|
{
|
|
1012
1075
|
// Delete animal 3 ("Red")
|
|
@@ -1156,8 +1219,7 @@ suite
|
|
|
1156
1219
|
{
|
|
1157
1220
|
// Expect response to be the record we just created.
|
|
1158
1221
|
var tmpResult = JSON.parse(pResponse.text);
|
|
1159
|
-
|
|
1160
|
-
Expect(tmpResult.Valid).to.be.false;
|
|
1222
|
+
Expect(tmpResult.Error).to.equal('Record validate failure - a valid JSON object is required.');
|
|
1161
1223
|
fDone();
|
|
1162
1224
|
}
|
|
1163
1225
|
);
|