meadow-endpoints 2.0.12 → 3.0.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/Dockerfile +32 -0
- package/README.md +30 -1
- package/{DebugHarness.js → debug/Harness.js} +0 -0
- package/package.json +27 -7
- package/source/Meadow-Authenticator.js +21 -11
- package/source/Meadow-Authorizers.js +23 -7
- package/source/Meadow-CommonServices.js +20 -15
- package/source/Meadow-Endpoints.js +58 -45
- package/source/Meadow-MarshallSessionData.js +64 -0
- package/source/crud/Meadow-Endpoint-Count.js +1 -1
- package/source/crud/Meadow-Endpoint-ReadDistinctList.js +146 -0
- package/source/crud/Meadow-Endpoint-ReadLiteList.js +8 -2
- package/source/crud/Meadow-Endpoint-ReadSelectList.js +6 -1
- package/source/crud/Meadow-Endpoint-Reads.js +6 -1
- package/source/crud/Meadow-Endpoint-ReadsBy.js +5 -0
- package/source/crud/Meadow-Marshal-DistinctList.js +55 -0
- package/test/MeadowEndpoints_basic_tests.js +80 -4
- package/test/MeadowEndpoints_disabledAuth_tests.js +1325 -0
- package/test/MeadowEndpoints_trustedSession_tests.js +1731 -0
- package/.travis.yml +0 -21
- package/0001-Don-t-call-response.send-on-huge-record-sets.-Use-JS.patch +0 -209
- package/0001-Register-wildcard-matches-that-have-parameter-count-.patch +0 -38
- package/0002-Bump-package-version.patch +0 -24
- package/0002-Fix-indent.patch +0 -47
- package/0003-Bump-package-version-for-publication.patch +0 -24
- package/cloud9setup.sh +0 -25
- package/source/crud/Meadow-Filter-Parse.js +0 -206
package/Dockerfile
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Use the codercom/code-server image
|
|
2
|
+
FROM codercom/code-server:latest
|
|
3
|
+
MAINTAINER steven velozo
|
|
4
|
+
|
|
5
|
+
VOLUME /home/coder/.config
|
|
6
|
+
VOLUME /home/coder/.vscode
|
|
7
|
+
|
|
8
|
+
RUN echo "...installing debian dependencies..."
|
|
9
|
+
RUN sudo apt update
|
|
10
|
+
RUN sudo apt install vim curl tmux -y
|
|
11
|
+
|
|
12
|
+
RUN echo "Building RETOLD development image..."
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
RUN echo "...mapping library specific volumes..."
|
|
16
|
+
# Volume mappings for RETOLD:Meadow Endpoints library
|
|
17
|
+
VOLUME /home/coder/meadow-endpoints
|
|
18
|
+
# VOLUME /home/coder/meadow-endpoints/node_modules
|
|
19
|
+
|
|
20
|
+
SHELL ["/bin/bash", "-c"]
|
|
21
|
+
USER coder
|
|
22
|
+
|
|
23
|
+
RUN echo "...installing node version manager..."
|
|
24
|
+
# Because there is a .bashrc chicken/egg problem, we will create one here to simulate logging in. This is not great.
|
|
25
|
+
RUN touch ~/.bashrc && chmod +x ~/.bashrc
|
|
26
|
+
RUN curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
|
|
27
|
+
|
|
28
|
+
RUN echo "...installing node version 14 as the default..."
|
|
29
|
+
RUN . ~/.nvm/nvm.sh && source ~/.bashrc && nvm install 14
|
|
30
|
+
RUN . ~/.nvm/nvm.sh && source ~/.bashrc && nvm alias default 14
|
|
31
|
+
|
|
32
|
+
WORKDIR /home/coder/meadow-endpoints
|
package/README.md
CHANGED
|
@@ -16,4 +16,33 @@ The design philosophy is not to cover every possible use case, but to cover the
|
|
|
16
16
|
|
|
17
17
|
To best use this library, it should be in conjunction with [stricture](https://github.com/stevenvelozo/stricture) and [orator](https://github.com/stevenvelozo/orator).
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
### Docker Development Environment
|
|
21
|
+
|
|
22
|
+
1. Run this command to build this image:
|
|
23
|
+
```
|
|
24
|
+
docker build ./ -t retold/meadow-endpoints:local
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
alternatively you can use npm to run this
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
npm run docker-dev-build-image
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
2. Run this command to build the local container:
|
|
34
|
+
```
|
|
35
|
+
docker run -it --name meadow-endpoints-dev -p 127.0.0.1:12343:8080 -v "$PWD/.config:/home/coder/.config" -v "$PWD:/home/coder/meadow-endpoints" -u "$(id -u):$(id -g)" -e "DOCKER_USER=$USER" retold/meadow-endpoints:local
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
alternatively you can use npm to run this
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
npm run docker-dev-run
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
3. Go to http://localhost:12343/ in a web browser
|
|
45
|
+
|
|
46
|
+
4. The password is "retold"
|
|
47
|
+
|
|
48
|
+
5. Right now you (may) need to delete the `node_modules` folders and regenerate it for Linux.
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meadow-endpoints",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Automatic API endpoints for Meadow data.",
|
|
5
5
|
"main": "source/Meadow-Endpoints.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"start": "node source/Meadow-Endpoints.js",
|
|
8
8
|
"coverage": "nyc npm run test && nyc report --reporter=lcov",
|
|
9
|
-
"test": "./node_modules/mocha
|
|
9
|
+
"test": "./node_modules/.bin/mocha --exit -u tdd -R spec",
|
|
10
|
+
"docker-dev-build-image": "docker build ./ -t retold/meadow-endpoints:local",
|
|
11
|
+
"docker-dev-run": "docker run -it -d --name meadow-endpoints-dev -p 127.0.0.1:12343:8080 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/meadow-endpoints\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" retold/meadow-endpoints:local"
|
|
12
|
+
},
|
|
13
|
+
"mocha": {
|
|
14
|
+
"diff": true,
|
|
15
|
+
"extension": [
|
|
16
|
+
"js"
|
|
17
|
+
],
|
|
18
|
+
"package": "./package.json",
|
|
19
|
+
"reporter": "spec",
|
|
20
|
+
"slow": "75",
|
|
21
|
+
"timeout": "5000",
|
|
22
|
+
"ui": "tdd",
|
|
23
|
+
"watch-files": [
|
|
24
|
+
"source/**/*.js",
|
|
25
|
+
"test/**/*.js"
|
|
26
|
+
],
|
|
27
|
+
"watch-ignore": [
|
|
28
|
+
"lib/vendor"
|
|
29
|
+
]
|
|
10
30
|
},
|
|
11
31
|
"repository": {
|
|
12
32
|
"type": "git",
|
|
@@ -24,18 +44,18 @@
|
|
|
24
44
|
"homepage": "https://github.com/stevenvelozo/meadow-endpoints",
|
|
25
45
|
"devDependencies": {
|
|
26
46
|
"chai": "4.1.2",
|
|
27
|
-
"
|
|
28
|
-
"coveralls": "3.0.2",
|
|
47
|
+
"chance": "^1.1.8",
|
|
29
48
|
"fable": "^2.0.1",
|
|
30
|
-
"mocha": "
|
|
49
|
+
"mocha": "9.2.2",
|
|
50
|
+
"mysql2": "1.6.1",
|
|
31
51
|
"nyc": "^15.1.0",
|
|
32
52
|
"supertest": "3.1.0"
|
|
33
53
|
},
|
|
34
54
|
"dependencies": {
|
|
35
55
|
"async": "2.6.1",
|
|
36
56
|
"JSONStream": "^1.3.5",
|
|
37
|
-
"meadow": "~1.0.
|
|
38
|
-
"
|
|
57
|
+
"meadow": "~1.0.32",
|
|
58
|
+
"meadow-filter": "^1.0.1",
|
|
39
59
|
"orator": "~2.0.2",
|
|
40
60
|
"underscore": "1.9.1"
|
|
41
61
|
}
|
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Check that a user is logged in
|
|
2
|
+
* Check that a user is logged in, if enabled
|
|
3
3
|
*
|
|
4
|
-
* @method
|
|
4
|
+
* @method getAuthenticator
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
const getAuthenticator = (pAuthenticatorMode) =>
|
|
7
7
|
{
|
|
8
|
-
if (
|
|
8
|
+
if (pAuthenticatorMode === 'Disabled')
|
|
9
9
|
{
|
|
10
|
-
pRequest
|
|
10
|
+
return (pRequest, pResponse, fNext) =>
|
|
11
|
+
{
|
|
12
|
+
pRequest.EndpointAuthenticated = true;
|
|
13
|
+
fNext();
|
|
14
|
+
};
|
|
11
15
|
}
|
|
12
|
-
|
|
16
|
+
return (pRequest, pResponse, fNext) =>
|
|
13
17
|
{
|
|
14
|
-
pRequest.
|
|
15
|
-
|
|
18
|
+
if (!pRequest.UserSession.LoggedIn)
|
|
19
|
+
{
|
|
20
|
+
pRequest.EndpointAuthenticated = false;
|
|
21
|
+
}
|
|
22
|
+
else
|
|
23
|
+
{
|
|
24
|
+
pRequest.EndpointAuthenticated = true;
|
|
25
|
+
}
|
|
16
26
|
|
|
17
|
-
|
|
18
|
-
|
|
27
|
+
fNext();
|
|
28
|
+
}
|
|
19
29
|
};
|
|
20
30
|
|
|
21
|
-
module.exports =
|
|
31
|
+
module.exports = getAuthenticator;
|
|
@@ -19,6 +19,8 @@ var MeadowAuthorizers = function()
|
|
|
19
19
|
return {new: createNew};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
const _AuthorizationMode = pMeadow.fable.settings.MeadowAuthorizationMode || 'Disabled';
|
|
23
|
+
|
|
22
24
|
// An object to hold modifications to specific authorizers.
|
|
23
25
|
var _AuthorizerFunctions = {};
|
|
24
26
|
|
|
@@ -44,12 +46,14 @@ var MeadowAuthorizers = function()
|
|
|
44
46
|
_AuthorizerFunctions[pAuthorizerHash] = fAuthorizer;
|
|
45
47
|
};
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
if (_AuthorizationMode === 'SimpleOwnership')
|
|
50
|
+
{
|
|
51
|
+
// Map in the authorizers for simple ownership mode
|
|
52
|
+
setAuthorizer('Allow', require(__dirname+'/authorizers/Meadow-Authorizer-Allow.js'));
|
|
53
|
+
setAuthorizer('Deny', require(__dirname+'/authorizers/Meadow-Authorizer-Deny.js'));
|
|
54
|
+
setAuthorizer('Mine', require(__dirname+'/authorizers/Meadow-Authorizer-Mine.js'));
|
|
55
|
+
setAuthorizer('MyCustomer', require(__dirname+'/authorizers/Meadow-Authorizer-MyCustomer.js'));
|
|
56
|
+
}
|
|
53
57
|
|
|
54
58
|
|
|
55
59
|
/**
|
|
@@ -65,6 +69,13 @@ var MeadowAuthorizers = function()
|
|
|
65
69
|
pRequest.MeadowAuthorization = true;
|
|
66
70
|
}
|
|
67
71
|
|
|
72
|
+
// authorize all behaviors if authorization is disabled
|
|
73
|
+
if (_AuthorizationMode === 'Disabled')
|
|
74
|
+
{
|
|
75
|
+
return fComplete();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//FIXME: Get rid of this...
|
|
68
79
|
if (pRequest.Satchel &&
|
|
69
80
|
pRequest.Satchel.AuthorizeOverride)
|
|
70
81
|
return fComplete(false);
|
|
@@ -125,10 +136,15 @@ var MeadowAuthorizers = function()
|
|
|
125
136
|
pRequest.MeadowAuthorization = true;
|
|
126
137
|
}
|
|
127
138
|
|
|
139
|
+
// authorize all behaviors if authorization is disabled
|
|
140
|
+
if (_AuthorizationMode === 'Disabled')
|
|
141
|
+
{
|
|
142
|
+
return fComplete();
|
|
143
|
+
}
|
|
144
|
+
|
|
128
145
|
// Attach authorizer hash in case the invoked authorizer needs the endpoint context
|
|
129
146
|
pRequest.EndpointHash = pRequestHash;
|
|
130
147
|
|
|
131
|
-
|
|
132
148
|
// See if there is an authorizer collection for the role of the user
|
|
133
149
|
var tmpRoleAuthorizer = pRequest.DAL.schemaFull.authorizer[pRequest.DAL.getRoleName(pRequest.UserSession.UserRoleIndex)];
|
|
134
150
|
if (!tmpRoleAuthorizer)
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
var MeadowCommonServices = function()
|
|
10
10
|
{
|
|
11
|
-
function createNew(pMeadow)
|
|
11
|
+
function createNew(pMeadow, pAuthenticationMode)
|
|
12
12
|
{
|
|
13
13
|
// If a valid fable object isn't passed in, return a constructor
|
|
14
14
|
if ((typeof(pMeadow) !== 'object') || !('fable' in pMeadow))
|
|
@@ -17,6 +17,7 @@ var MeadowCommonServices = function()
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
var _Meadow = pMeadow;
|
|
20
|
+
const _AuthenticationMode = pAuthenticationMode;
|
|
20
21
|
var _Log = _Meadow.fable.log;
|
|
21
22
|
|
|
22
23
|
var libRestify = require('restify');
|
|
@@ -106,21 +107,25 @@ var MeadowCommonServices = function()
|
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
// Check that the user has a valid ID.
|
|
109
|
-
|
|
110
|
-
if (tmpIDUser < 1)
|
|
110
|
+
if (_AuthenticationMode !== 'Disabled')
|
|
111
111
|
{
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
112
|
+
//TODO: do we need this code anymore?
|
|
113
|
+
const tmpIDUser = pRequest.UserSession.UserID;
|
|
114
|
+
if (tmpIDUser < 1)
|
|
115
|
+
{
|
|
116
|
+
_Log.warn('Invalid session when attempting to get a secured resource - IDUser is not valid.', {SessionID:pRequest.UserSession.SessionID, RequestID:pRequest.RequestUUID, RequestURL:pRequest.url, Action:'APISecurity'}, pRequest);
|
|
117
|
+
sendNotAuthorized('You must be authenticated to access this resource.', pRequest, pResponse, fNext);
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Check that the authentication level is valid.
|
|
122
|
+
if (pRequest.UserSession.UserRoleIndex < pRequest.EndpointAuthorizationRequirement)
|
|
123
|
+
{
|
|
124
|
+
_Log.warn('Invalid permission level when attempting to get a secured resource.', {SessionID:pRequest.UserSession.SessionID, RequestID:pRequest.RequestUUID, RequestURL:pRequest.url, Action:'APISecurity', RequiredUserLevel:pRequest.EndpointAuthorizationRequirement, ActualUserLevel:pRequest.UserSession.UserRoleIndex}, pRequest);
|
|
125
|
+
// TODO: Send the proper http status code
|
|
126
|
+
sendNotAuthorized('You must be appropriately authenticated to access this resource.', pRequest, pResponse, fNext);
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
124
129
|
}
|
|
125
130
|
|
|
126
131
|
return true;
|
|
@@ -7,9 +7,6 @@
|
|
|
7
7
|
* @module Meadow
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
//Meadow needs to connect some general route handlers, this ensures it is done lazily, and only once.
|
|
11
|
-
var _AttachedRequestHandlers = false;
|
|
12
|
-
|
|
13
10
|
/**
|
|
14
11
|
* Meadow Data Broker Library
|
|
15
12
|
*
|
|
@@ -31,7 +28,9 @@ var MeadowEndpoints = function()
|
|
|
31
28
|
var libAsync = require('async');
|
|
32
29
|
var libRestRouteParse = require('./Restify-RouteParser.js');
|
|
33
30
|
|
|
34
|
-
|
|
31
|
+
const _AuthenticationMode = _Fable.settings.MeadowAuthenticationMode || 'Disabled';
|
|
32
|
+
|
|
33
|
+
var _CommonServices = require('./Meadow-CommonServices.js').new(pMeadow, _AuthenticationMode);
|
|
35
34
|
|
|
36
35
|
// This holds any changed behaviors.
|
|
37
36
|
var _BehaviorModifications = require('./Meadow-BehaviorModifications.js').new(pMeadow);
|
|
@@ -40,7 +39,7 @@ var MeadowEndpoints = function()
|
|
|
40
39
|
var _Authorizers = require('./Meadow-Authorizers.js').new(pMeadow);
|
|
41
40
|
|
|
42
41
|
// This checks that the user is authenticated. In the future, it will be overloadable.
|
|
43
|
-
var _Authenticator = require('./Meadow-Authenticator.js');
|
|
42
|
+
var _Authenticator = require('./Meadow-Authenticator.js')(_AuthenticationMode);
|
|
44
43
|
|
|
45
44
|
// The default endpoints
|
|
46
45
|
var _Endpoints = (
|
|
@@ -56,6 +55,7 @@ var MeadowEndpoints = function()
|
|
|
56
55
|
|
|
57
56
|
ReadSelectList: require('./crud/Meadow-Endpoint-ReadSelectList.js'),
|
|
58
57
|
ReadLiteList: require('./crud/Meadow-Endpoint-ReadLiteList.js'),
|
|
58
|
+
ReadDistinctList: require('./crud/Meadow-Endpoint-ReadDistinctList.js'),
|
|
59
59
|
|
|
60
60
|
Update: require('./crud/Meadow-Endpoint-Update.js'),
|
|
61
61
|
Updates: require('./crud/Meadow-Endpoint-BulkUpdate.js'),
|
|
@@ -172,6 +172,10 @@ var MeadowEndpoints = function()
|
|
|
172
172
|
// GET [/1.0/SomeEndpoint/LiteExtended/:ExtraColumns/:Begin/:Cap]
|
|
173
173
|
// GET [/1.0/SomeEndpoint/LiteExtended/:ExtraColumns/FilteredTo/:Filter]
|
|
174
174
|
// GET [/1.0/SomeEndpoint/LiteExtended/:ExtraColumns/FilteredTo/:Filter/:Begin/:Cap]
|
|
175
|
+
// GET [/1.0/SomeEndpoint/Distinct/:Columns]
|
|
176
|
+
// GET [/1.0/SomeEndpoint/Distinct/:Columns/:Begin/:Cap]
|
|
177
|
+
// GET [/1.0/SomeEndpoint/Distinct/:Columns/FilteredTo/:Filter]
|
|
178
|
+
// GET [/1.0/SomeEndpoint/Distinct/:Columns/FilteredTo/:Filter/:Begin/:Cap]
|
|
175
179
|
|
|
176
180
|
Update: true,
|
|
177
181
|
// PUT [/1.0/SomeEndpoint]
|
|
@@ -290,35 +294,40 @@ var MeadowEndpoints = function()
|
|
|
290
294
|
var connectRoutes = function(pRestServer)
|
|
291
295
|
{
|
|
292
296
|
// TODO: Pull version from the config file.
|
|
293
|
-
|
|
297
|
+
const tmpEndpointVersion = _Fable.settings.MeadowEndpointVersion || '1.0';
|
|
294
298
|
// TODO: Allow the user to override the endpoint "name" eventually.
|
|
295
|
-
|
|
299
|
+
const tmpEndpointName = _Meadow.scope;
|
|
296
300
|
|
|
297
|
-
_Fable.log.trace('Creating endpoint', {Version:tmpEndpointVersion, Name:tmpEndpointName});
|
|
301
|
+
_Fable.log.trace('Creating endpoint', { Version: tmpEndpointVersion, Name: tmpEndpointName });
|
|
298
302
|
|
|
299
|
-
|
|
303
|
+
const tmpEndpointPrefix = `/${tmpEndpointVersion}/${tmpEndpointName}`;
|
|
304
|
+
|
|
305
|
+
if (!pRestServer._AttachedMeadowEndpointsRequestHandlers)
|
|
300
306
|
{
|
|
301
|
-
|
|
307
|
+
pRestServer._AttachedMeadowEndpointsRequestHandlers = true;
|
|
302
308
|
// Connect the common services to the route
|
|
303
309
|
pRestServer.use(wireCommonServices);
|
|
304
310
|
|
|
305
311
|
// Build formattedParams route parameters
|
|
306
312
|
pRestServer.use(formatRouteParams);
|
|
313
|
+
|
|
314
|
+
// Marshall session data in, if needed / configured
|
|
315
|
+
pRestServer.use(require('./Meadow-MarshallSessionData')(_Fable));
|
|
307
316
|
}
|
|
308
317
|
|
|
309
318
|
// These special schema services must come in the route table before the READ because they
|
|
310
319
|
// technically block out the routes for the IDRecord 'Schema' (e.g. /1.0/EntityName/Schema)
|
|
311
320
|
if (_EnabledBehaviors.Schema)
|
|
312
321
|
{
|
|
313
|
-
pRestServer.get(
|
|
322
|
+
pRestServer.get(`${tmpEndpointPrefix}/Schema`, _EndpointAuthenticators.Schema, wireState, _Endpoints.Schema);
|
|
314
323
|
}
|
|
315
324
|
if (_EnabledBehaviors.New)
|
|
316
325
|
{
|
|
317
|
-
pRestServer.get(
|
|
326
|
+
pRestServer.get(`${tmpEndpointPrefix}/Schema/New`, _EndpointAuthenticators.New, wireState, _Endpoints.New);
|
|
318
327
|
}
|
|
319
328
|
if (_EnabledBehaviors.Validate)
|
|
320
329
|
{
|
|
321
|
-
pRestServer.post(
|
|
330
|
+
pRestServer.post(`${tmpEndpointPrefix}/Schema/Validate`, _CommonServices.bodyParser(), _EndpointAuthenticators.Validate, wireState, _Endpoints.Validate);
|
|
322
331
|
}
|
|
323
332
|
|
|
324
333
|
// Custom single record endpoints
|
|
@@ -326,52 +335,56 @@ var MeadowEndpoints = function()
|
|
|
326
335
|
// Standard CRUD and Count endpoints
|
|
327
336
|
if (_EnabledBehaviors.Create)
|
|
328
337
|
{
|
|
329
|
-
pRestServer.post(
|
|
330
|
-
pRestServer.post(
|
|
338
|
+
pRestServer.post(`${tmpEndpointPrefix}`, _CommonServices.bodyParser(), _EndpointAuthenticators.Create, wireState, _Endpoints.Create);
|
|
339
|
+
pRestServer.post(`${tmpEndpointPrefix}s`, _CommonServices.bodyParser(), _EndpointAuthenticators.Create, wireState, _Endpoints.Creates);
|
|
331
340
|
}
|
|
332
341
|
if (_EnabledBehaviors.Read)
|
|
333
342
|
{
|
|
334
|
-
pRestServer.get(
|
|
335
|
-
pRestServer.get(
|
|
343
|
+
pRestServer.get(`${tmpEndpointPrefix}/Max/:ColumnName`, _EndpointAuthenticators.Read, wireState, _Endpoints.ReadMax);
|
|
344
|
+
pRestServer.get(`${tmpEndpointPrefix}/:IDRecord`, _EndpointAuthenticators.Read, wireState, _Endpoints.Read);
|
|
336
345
|
}
|
|
337
346
|
if (_EnabledBehaviors.Reads)
|
|
338
347
|
{
|
|
339
|
-
pRestServer.get(
|
|
340
|
-
pRestServer.get(
|
|
341
|
-
pRestServer.get(
|
|
342
|
-
pRestServer.get(
|
|
343
|
-
pRestServer.get(
|
|
344
|
-
pRestServer.get(
|
|
345
|
-
pRestServer.get(
|
|
346
|
-
pRestServer.get(
|
|
347
|
-
pRestServer.get(
|
|
348
|
-
pRestServer.get(
|
|
349
|
-
pRestServer.get(
|
|
350
|
-
pRestServer.get(
|
|
351
|
-
pRestServer.get(
|
|
352
|
-
pRestServer.get(
|
|
353
|
-
pRestServer.get(
|
|
354
|
-
pRestServer.get(
|
|
355
|
-
pRestServer.get(
|
|
356
|
-
pRestServer.get(
|
|
348
|
+
pRestServer.get(`${tmpEndpointPrefix}s`, _EndpointAuthenticators.Reads, wireState, _Endpoints.Reads);
|
|
349
|
+
pRestServer.get(`${tmpEndpointPrefix}s/By/:ByField/:ByValue`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadsBy);
|
|
350
|
+
pRestServer.get(`${tmpEndpointPrefix}s/By/:ByField/:ByValue/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadsBy);
|
|
351
|
+
pRestServer.get(`${tmpEndpointPrefix}s/FilteredTo/:Filter`, _EndpointAuthenticators.Reads, wireState, _Endpoints.Reads);
|
|
352
|
+
pRestServer.get(`${tmpEndpointPrefix}s/FilteredTo/:Filter/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.Reads);
|
|
353
|
+
pRestServer.get(`${tmpEndpointPrefix}Select`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadSelectList);
|
|
354
|
+
pRestServer.get(`${tmpEndpointPrefix}Select/FilteredTo/:Filter`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadSelectList);
|
|
355
|
+
pRestServer.get(`${tmpEndpointPrefix}Select/FilteredTo/:Filter/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadSelectList);
|
|
356
|
+
pRestServer.get(`${tmpEndpointPrefix}Select/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadSelectList);
|
|
357
|
+
pRestServer.get(`${tmpEndpointPrefix}s/Lite`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
|
|
358
|
+
pRestServer.get(`${tmpEndpointPrefix}s/Lite/FilteredTo/:Filter`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
|
|
359
|
+
pRestServer.get(`${tmpEndpointPrefix}s/Lite/FilteredTo/:Filter/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
|
|
360
|
+
pRestServer.get(`${tmpEndpointPrefix}s/Lite/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
|
|
361
|
+
pRestServer.get(`${tmpEndpointPrefix}s/LiteExtended/:ExtraColumns`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
|
|
362
|
+
pRestServer.get(`${tmpEndpointPrefix}s/LiteExtended/:ExtraColumns/FilteredTo/:Filter`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
|
|
363
|
+
pRestServer.get(`${tmpEndpointPrefix}s/LiteExtended/:ExtraColumns/FilteredTo/:Filter/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
|
|
364
|
+
pRestServer.get(`${tmpEndpointPrefix}s/LiteExtended/:ExtraColumns/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadLiteList);
|
|
365
|
+
pRestServer.get(`${tmpEndpointPrefix}s/Distinct/:Columns`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadDistinctList);
|
|
366
|
+
pRestServer.get(`${tmpEndpointPrefix}s/Distinct/:Columns/FilteredTo/:Filter`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadDistinctList);
|
|
367
|
+
pRestServer.get(`${tmpEndpointPrefix}s/Distinct/:Columns/FilteredTo/:Filter/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadDistinctList);
|
|
368
|
+
pRestServer.get(`${tmpEndpointPrefix}s/Distinct/:Columns/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.ReadDistinctList);
|
|
369
|
+
pRestServer.get(`${tmpEndpointPrefix}s/:Begin/:Cap`, _EndpointAuthenticators.Reads, wireState, _Endpoints.Reads);
|
|
357
370
|
}
|
|
358
371
|
if (_EnabledBehaviors.Update)
|
|
359
372
|
{
|
|
360
|
-
pRestServer.put(
|
|
361
|
-
pRestServer.put(
|
|
362
|
-
pRestServer.put(
|
|
363
|
-
pRestServer.put(
|
|
373
|
+
pRestServer.put(`${tmpEndpointPrefix}`, _CommonServices.bodyParser(), _EndpointAuthenticators.Update, wireState, _Endpoints.Update);
|
|
374
|
+
pRestServer.put(`${tmpEndpointPrefix}s`, _CommonServices.bodyParser(), _EndpointAuthenticators.Update, wireState, _Endpoints.Updates);
|
|
375
|
+
pRestServer.put(`${tmpEndpointPrefix}/Upsert`, _CommonServices.bodyParser(), _EndpointAuthenticators.Update, wireState, _Endpoints.Upsert);
|
|
376
|
+
pRestServer.put(`${tmpEndpointPrefix}/Upserts`, _CommonServices.bodyParser(), _EndpointAuthenticators.Update, wireState, _Endpoints.Upserts);
|
|
364
377
|
}
|
|
365
378
|
if (_EnabledBehaviors.Delete)
|
|
366
379
|
{
|
|
367
|
-
pRestServer.del(
|
|
368
|
-
pRestServer.del(
|
|
380
|
+
pRestServer.del(`${tmpEndpointPrefix}`, _CommonServices.bodyParser(), _EndpointAuthenticators.Delete, wireState, _Endpoints.Delete);
|
|
381
|
+
pRestServer.del(`${tmpEndpointPrefix}/:IDRecord`, _EndpointAuthenticators.Delete, wireState, _Endpoints.Delete);
|
|
369
382
|
}
|
|
370
383
|
if (_EnabledBehaviors.Count)
|
|
371
384
|
{
|
|
372
|
-
pRestServer.get(
|
|
373
|
-
pRestServer.get(
|
|
374
|
-
pRestServer.get(
|
|
385
|
+
pRestServer.get(`${tmpEndpointPrefix}s/Count`, _EndpointAuthenticators.Count, wireState, _Endpoints.Count);
|
|
386
|
+
pRestServer.get(`${tmpEndpointPrefix}s/Count/By/:ByField/:ByValue`, _EndpointAuthenticators.Count, wireState, _Endpoints.CountBy);
|
|
387
|
+
pRestServer.get(`${tmpEndpointPrefix}s/Count/FilteredTo/:Filter`, _EndpointAuthenticators.Count, wireState, _Endpoints.Count);
|
|
375
388
|
}
|
|
376
389
|
};
|
|
377
390
|
|
|
@@ -493,7 +506,7 @@ var MeadowEndpoints = function()
|
|
|
493
506
|
|
|
494
507
|
connectRoutes: connectRoutes,
|
|
495
508
|
|
|
496
|
-
parseFilter: require(
|
|
509
|
+
parseFilter: require('meadow-filter').parse,
|
|
497
510
|
|
|
498
511
|
// Expose the DAL
|
|
499
512
|
DAL: _Meadow,
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Meadow Session Marshaller - Extract session data based on configuration.
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
*
|
|
6
|
+
* @author Alex Decker <alex.decker@headlight.com>
|
|
7
|
+
* @module Meadow
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
module.exports = (pFable) =>
|
|
11
|
+
{
|
|
12
|
+
const _Fable = pFable;
|
|
13
|
+
const _SessionDataSource = _Fable.settings.MeadowEndpointsSessionDataSource || 'Request';
|
|
14
|
+
|
|
15
|
+
return (pRequest, pResponse, fNext) =>
|
|
16
|
+
{
|
|
17
|
+
let session;
|
|
18
|
+
|
|
19
|
+
switch (_SessionDataSource)
|
|
20
|
+
{
|
|
21
|
+
default:
|
|
22
|
+
_Fable.log.warn(`Unknown session source configured: ${_SessionDataSource} - defaulting to Request for backward compatibility`);
|
|
23
|
+
case 'Request':
|
|
24
|
+
// noop - already set by orator-session
|
|
25
|
+
session = pRequest.UserSession;
|
|
26
|
+
break;
|
|
27
|
+
case 'None':
|
|
28
|
+
break;
|
|
29
|
+
case 'Header':
|
|
30
|
+
try
|
|
31
|
+
{
|
|
32
|
+
const sessionStr = pRequest.headers['x-trusted-session'];
|
|
33
|
+
if (!sessionStr)
|
|
34
|
+
{
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
session = JSON.parse(sessionStr);
|
|
38
|
+
}
|
|
39
|
+
catch (pError)
|
|
40
|
+
{
|
|
41
|
+
_Fable.log.error('Error marshalling session data from header.', { Error: pError.message, Stack: pError.stack });
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!session)
|
|
47
|
+
{
|
|
48
|
+
// blank session so things don't break, for now
|
|
49
|
+
session =
|
|
50
|
+
{
|
|
51
|
+
SessionID: '',
|
|
52
|
+
UserID: 0,
|
|
53
|
+
UserRole: '',
|
|
54
|
+
UserRoleIndex: 0,
|
|
55
|
+
LoggedIn: false,
|
|
56
|
+
DeviceID: '',
|
|
57
|
+
CustomerID: 0,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
pRequest.UserSession = session;
|
|
62
|
+
fNext();
|
|
63
|
+
}
|
|
64
|
+
};
|