meadow-endpoints 2.0.21 → 2.0.23
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/.babelrc +6 -0
- package/.browserslistrc +1 -0
- package/.gulpfile-quackage-config.json +8 -0
- package/.gulpfile-quackage.js +2 -0
- package/package.json +3 -3
- package/source/crud/Meadow-Endpoint-ReadLiteList.js +5 -0
- package/source/crud/Meadow-Marshal-LiteList.js +2 -1
- package/source/crud/Meadow-Operation-Update.js +1 -1
- package/test/MeadowEndpoints_basic_tests.js +114 -0
package/.babelrc
ADDED
package/.browserslistrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
since 2022
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"EntrypointInputSourceFile": "/home/alex/dev/clean/meadow-endpoints/source/Meadow-Endpoints.js",
|
|
3
|
+
"LibraryObjectName": "MeadowEndpoints",
|
|
4
|
+
"LibraryOutputFolder": "/home/alex/dev/clean/meadow-endpoints/dist/",
|
|
5
|
+
"LibraryUniminifiedFileName": "meadow-endpoints.js",
|
|
6
|
+
"LibraryMinifiedFileName": "meadow-endpoints.min.js",
|
|
7
|
+
"BrowserifyIgnore": []
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meadow-endpoints",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.23",
|
|
4
4
|
"description": "Automatic API endpoints for Meadow data.",
|
|
5
5
|
"main": "source/Meadow-Endpoints.js",
|
|
6
6
|
"scripts": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"homepage": "https://github.com/stevenvelozo/meadow-endpoints",
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"chai": "4.1.2",
|
|
47
|
-
"chance": "^1.1.
|
|
47
|
+
"chance": "^1.1.13",
|
|
48
48
|
"fable": "^2.0.1",
|
|
49
49
|
"mocha": "9.2.2",
|
|
50
50
|
"mysql2": "1.6.1",
|
|
@@ -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.10",
|
|
59
59
|
"orator": "~2.0.2",
|
|
60
60
|
"underscore": "1.9.1"
|
|
61
61
|
}
|
|
@@ -111,6 +111,11 @@ var doAPIReadLiteEndpoint = function(pRequest, pResponse, fNext)
|
|
|
111
111
|
// It looks like this record was not authorized. Send an error.
|
|
112
112
|
return fStageComplete({Code:405,Message:'UNAUTHORIZED ACCESS IS NOT ALLOWED'});
|
|
113
113
|
},
|
|
114
|
+
// 2.7: INJECT: Post-operation behavior (e.g. field cleansing)
|
|
115
|
+
function (fStageComplete)
|
|
116
|
+
{
|
|
117
|
+
pRequest.BehaviorModifications.runBehavior('ReadsLite-PostOperation', pRequest, fStageComplete);
|
|
118
|
+
},
|
|
114
119
|
// 3. Marshalling of records into the hash list, using underscore templates.
|
|
115
120
|
function (fStageComplete)
|
|
116
121
|
{
|
|
@@ -30,7 +30,8 @@ var marshalLiteList = (pRecords, pRequest, pFieldList) =>
|
|
|
30
30
|
{
|
|
31
31
|
if (pField.indexOf('ID') === 0 ||
|
|
32
32
|
pField.indexOf('GUID') === 0 ||
|
|
33
|
-
pField == 'CreatingIDUser'
|
|
33
|
+
pField == 'CreatingIDUser' || // we should always include owner info
|
|
34
|
+
pField == 'Error') // we should propagate errors through (ex. bulk upsert)
|
|
34
35
|
{
|
|
35
36
|
tmpFieldList.push(pField);
|
|
36
37
|
}
|
|
@@ -111,7 +111,7 @@ var doUpdate = function(pRecordToModify, pRequest, pResponse, fCallback, pOption
|
|
|
111
111
|
{
|
|
112
112
|
if (!pRecord)
|
|
113
113
|
{
|
|
114
|
-
return fStageComplete('Error updating a record.');
|
|
114
|
+
return fStageComplete(pError || 'Error updating a record.');
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
pRequest.Record = pRecord;
|
|
@@ -608,6 +608,91 @@ suite
|
|
|
608
608
|
}
|
|
609
609
|
);
|
|
610
610
|
test
|
|
611
|
+
(
|
|
612
|
+
'readsLite: ReadsLite-PostOperation behavior fires and can modify records',
|
|
613
|
+
function(fDone)
|
|
614
|
+
{
|
|
615
|
+
_MeadowEndpoints.behaviorModifications.setBehavior('ReadsLite-PostOperation',
|
|
616
|
+
function(pRequest, fComplete)
|
|
617
|
+
{
|
|
618
|
+
// Simulate field cleansing by removing Type from all records
|
|
619
|
+
pRequest.Records.forEach(function(pRecord)
|
|
620
|
+
{
|
|
621
|
+
delete pRecord.Type;
|
|
622
|
+
});
|
|
623
|
+
fComplete(false);
|
|
624
|
+
});
|
|
625
|
+
libSuperTest('http://localhost:9080/')
|
|
626
|
+
.get('1.0/FableTests/LiteExtended/Type,Name')
|
|
627
|
+
.end(
|
|
628
|
+
function (pError, pResponse)
|
|
629
|
+
{
|
|
630
|
+
var tmpResults = JSON.parse(pResponse.text);
|
|
631
|
+
Expect(tmpResults.length).to.equal(6);
|
|
632
|
+
// Type was requested via LiteExtended but removed by PostOperation behavior
|
|
633
|
+
Expect(tmpResults[0]).to.not.have.property('Type');
|
|
634
|
+
Expect(tmpResults[4]).to.not.have.property('Type');
|
|
635
|
+
// Name was not removed and should still be present
|
|
636
|
+
Expect(tmpResults[4].Name).to.equal('Gertrude');
|
|
637
|
+
// Clean up
|
|
638
|
+
_MeadowEndpoints.behaviorModifications.setBehavior('ReadsLite-PostOperation', null);
|
|
639
|
+
fDone();
|
|
640
|
+
}
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
);
|
|
644
|
+
test
|
|
645
|
+
(
|
|
646
|
+
'readsLite: ReadsLite-PostOperation behavior fires for standard Lite endpoint',
|
|
647
|
+
function(fDone)
|
|
648
|
+
{
|
|
649
|
+
var tmpBehaviorFired = false;
|
|
650
|
+
_MeadowEndpoints.behaviorModifications.setBehavior('ReadsLite-PostOperation',
|
|
651
|
+
function(pRequest, fComplete)
|
|
652
|
+
{
|
|
653
|
+
tmpBehaviorFired = true;
|
|
654
|
+
fComplete(false);
|
|
655
|
+
});
|
|
656
|
+
libSuperTest('http://localhost:9080/')
|
|
657
|
+
.get('1.0/FableTests/Lite')
|
|
658
|
+
.end(
|
|
659
|
+
function (pError, pResponse)
|
|
660
|
+
{
|
|
661
|
+
var tmpResults = JSON.parse(pResponse.text);
|
|
662
|
+
Expect(tmpResults.length).to.equal(6);
|
|
663
|
+
Expect(tmpBehaviorFired).to.equal(true);
|
|
664
|
+
// Clean up
|
|
665
|
+
_MeadowEndpoints.behaviorModifications.setBehavior('ReadsLite-PostOperation', null);
|
|
666
|
+
fDone();
|
|
667
|
+
}
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
);
|
|
671
|
+
test
|
|
672
|
+
(
|
|
673
|
+
'readsLite: ReadsLite-PostOperation error halts response',
|
|
674
|
+
function(fDone)
|
|
675
|
+
{
|
|
676
|
+
_MeadowEndpoints.behaviorModifications.setBehavior('ReadsLite-PostOperation',
|
|
677
|
+
function(pRequest, fComplete)
|
|
678
|
+
{
|
|
679
|
+
fComplete({Code:403,Message:'SENSITIVE FIELD ACCESS DENIED'});
|
|
680
|
+
});
|
|
681
|
+
libSuperTest('http://localhost:9080/')
|
|
682
|
+
.get('1.0/FableTests/LiteExtended/Type,Name')
|
|
683
|
+
.end(
|
|
684
|
+
function (pError, pResponse)
|
|
685
|
+
{
|
|
686
|
+
var tmpResult = JSON.parse(pResponse.text);
|
|
687
|
+
Expect(tmpResult).to.have.property('Error');
|
|
688
|
+
// Clean up
|
|
689
|
+
_MeadowEndpoints.behaviorModifications.setBehavior('ReadsLite-PostOperation', null);
|
|
690
|
+
fDone();
|
|
691
|
+
}
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
);
|
|
695
|
+
test
|
|
611
696
|
(
|
|
612
697
|
'readsby: get all records by Type',
|
|
613
698
|
function(fDone)
|
|
@@ -2496,6 +2581,35 @@ suite
|
|
|
2496
2581
|
);
|
|
2497
2582
|
}
|
|
2498
2583
|
);
|
|
2584
|
+
test
|
|
2585
|
+
(
|
|
2586
|
+
'problematic bulk upserts',
|
|
2587
|
+
function(fDone)
|
|
2588
|
+
{
|
|
2589
|
+
_MeadowEndpoints.behaviorModifications.setTemplate('SelectList', '<%= Record.Name %>|<%=Record.Type%>');
|
|
2590
|
+
var tmpRecords = [
|
|
2591
|
+
{GUIDAnimal:'0xHAXXXX', TypeOh:'Triceratops'},
|
|
2592
|
+
{GUIDAnimal:'0xDavison', Nameology:'Davison', Type:'Dog'},
|
|
2593
|
+
{GUIDAnimal:'0xMartino', Name:'Martin', Type:'Dog'}, // this one still works
|
|
2594
|
+
];
|
|
2595
|
+
_MockSessionValidUser.UserRoleIndex = 2;
|
|
2596
|
+
libSuperTest('http://localhost:9080/')
|
|
2597
|
+
.put('1.0/FableTest/Upserts')
|
|
2598
|
+
.send(tmpRecords)
|
|
2599
|
+
.end(
|
|
2600
|
+
function(pError, pResponse)
|
|
2601
|
+
{
|
|
2602
|
+
// Expect response to be the record we just created.
|
|
2603
|
+
var tmpResult = JSON.parse(pResponse.text);
|
|
2604
|
+
console.log(JSON.stringify(tmpResult,null,4));
|
|
2605
|
+
Expect(tmpResult[0].Error).to.be.a('string');
|
|
2606
|
+
Expect(tmpResult[1].Error).to.be.a('string');
|
|
2607
|
+
Expect(tmpResult[2].Error).to.not.exist;
|
|
2608
|
+
fDone();
|
|
2609
|
+
}
|
|
2610
|
+
);
|
|
2611
|
+
}
|
|
2612
|
+
);
|
|
2499
2613
|
}
|
|
2500
2614
|
);
|
|
2501
2615
|
}
|