@hitchy/plugin-odem-rest 0.9.2 → 0.9.3
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/api/services/odem-rest/cors.js +18 -18
- package/index.js +21 -21
- package/package.json +8 -8
|
@@ -33,7 +33,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
33
33
|
* Generates function for use as a routing policy filtering CORS-related
|
|
34
34
|
* aspects of requests without relation to some particular model.
|
|
35
35
|
*
|
|
36
|
-
* @returns {
|
|
36
|
+
* @returns {Hitchy.Core.RequestPolicyHandler} generated function suitable for registering as routing policy handler
|
|
37
37
|
*/
|
|
38
38
|
static getCommonRequestFilter() {
|
|
39
39
|
return ( req, res, next ) => {
|
|
@@ -56,7 +56,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
56
56
|
* Generates function for use as a routing policy filtering CORS-related
|
|
57
57
|
* aspects of requests for all models' schemata.
|
|
58
58
|
*
|
|
59
|
-
* @returns {
|
|
59
|
+
* @returns {Hitchy.Core.RequestPolicyHandler} generated function suitable for registering as routing policy handler
|
|
60
60
|
*/
|
|
61
61
|
static getRequestFilterForSchemata() {
|
|
62
62
|
return ( req, res, next ) => {
|
|
@@ -76,13 +76,13 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
76
76
|
* Generates function for use as a routing policy filtering CORS-related
|
|
77
77
|
* aspects of requests in scope of provided model.
|
|
78
78
|
*
|
|
79
|
-
* @param {
|
|
80
|
-
* @returns {
|
|
79
|
+
* @param {Class<Model>} model class of particular model
|
|
80
|
+
* @returns {Hitchy.Core.RequestPolicyHandler} generated function suitable for registering as routing policy handler
|
|
81
81
|
*/
|
|
82
82
|
static getRequestFilterForModel( model ) {
|
|
83
83
|
return ( req, res, next ) => {
|
|
84
84
|
if ( !res.headersSent ) {
|
|
85
|
-
if ( Services.OdemSchema.mayBeExposed( req, model ) ) {
|
|
85
|
+
if ( Services.OdemSchema.mayBeExposed( req.user, model ) ) {
|
|
86
86
|
this.handleMethods( model, null, req, res, Accepted.model.methods );
|
|
87
87
|
|
|
88
88
|
if ( res.hasHeader( "Access-Control-Allow-Origin" ) ) {
|
|
@@ -104,13 +104,13 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
104
104
|
* Generates function for use as a routing policy filtering CORS-related
|
|
105
105
|
* aspects of requests in scope of provided model.
|
|
106
106
|
*
|
|
107
|
-
* @param {
|
|
108
|
-
* @returns {
|
|
107
|
+
* @param {Class<Model>} model class of particular model
|
|
108
|
+
* @returns {Hitchy.Core.RequestPolicyHandler} generated function suitable for registering as routing policy handler
|
|
109
109
|
*/
|
|
110
110
|
static getRequestFilterForModelSchema( model ) {
|
|
111
111
|
return ( req, res, next ) => {
|
|
112
112
|
if ( !res.headersSent ) {
|
|
113
|
-
if ( Services.OdemSchema.mayBeExposed( req, model ) ) {
|
|
113
|
+
if ( Services.OdemSchema.mayBeExposed( req.user, model ) ) {
|
|
114
114
|
this.handleMethods( model, null, req, res, Accepted.schema.methods );
|
|
115
115
|
|
|
116
116
|
if ( res.hasHeader( "Access-Control-Allow-Origin" ) ) {
|
|
@@ -132,13 +132,13 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
132
132
|
* Generates function for use as a routing policy filtering CORS-related
|
|
133
133
|
* aspects of requests in scope of provided model.
|
|
134
134
|
*
|
|
135
|
-
* @param {
|
|
136
|
-
* @returns {
|
|
135
|
+
* @param {Class<Model>} model class of particular model
|
|
136
|
+
* @returns {Hitchy.Core.RequestPolicyHandler} generated function suitable for registering as routing policy handler
|
|
137
137
|
*/
|
|
138
138
|
static getRequestFilterForModelItem( model ) {
|
|
139
139
|
return ( req, res, next ) => {
|
|
140
140
|
if ( !res.headersSent && req.params.uuid !== ".schema" ) {
|
|
141
|
-
if ( Services.OdemSchema.mayBeExposed( req, model ) ) {
|
|
141
|
+
if ( Services.OdemSchema.mayBeExposed( req.user, model ) ) {
|
|
142
142
|
this.handleMethods( model, req.params.uuid, req, res, Accepted.item.methods );
|
|
143
143
|
|
|
144
144
|
if ( res.hasHeader( "Access-Control-Allow-Origin" ) ) {
|
|
@@ -159,7 +159,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
159
159
|
/**
|
|
160
160
|
* Ends preflight requests.
|
|
161
161
|
*
|
|
162
|
-
* @returns {
|
|
162
|
+
* @returns {Hitchy.Core.RequestPolicyHandler} generated function suitable for registering as routing policy handler
|
|
163
163
|
*/
|
|
164
164
|
static finishPreflight() {
|
|
165
165
|
return ( req, res, next ) => {
|
|
@@ -175,10 +175,10 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
175
175
|
* Injects response header describing available request methods for URL
|
|
176
176
|
* processing selected model and optionally addressed item.
|
|
177
177
|
*
|
|
178
|
-
* @param {
|
|
178
|
+
* @param {Class<Model>} model implementation of model selected by request URL
|
|
179
179
|
* @param {string} item UUID of model's item addressed in request URL
|
|
180
|
-
* @param {
|
|
181
|
-
* @param {
|
|
180
|
+
* @param {Hitchy.Core.IncomingMessage} req request descriptor
|
|
181
|
+
* @param {Hitchy.Core.ServerResponse} res response manager
|
|
182
182
|
* @param {string[]} accepted comma-separated list of methods to accept by default
|
|
183
183
|
* @returns {void}
|
|
184
184
|
* @protected
|
|
@@ -212,10 +212,10 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
212
212
|
* Injects response header describing available request headers for URL
|
|
213
213
|
* processing selected model and optionally addressed item.
|
|
214
214
|
*
|
|
215
|
-
* @param {
|
|
215
|
+
* @param {Class<Model>} model implementation of model selected by request URL
|
|
216
216
|
* @param {string} item UUID of model's item addressed in request URL
|
|
217
|
-
* @param {
|
|
218
|
-
* @param {
|
|
217
|
+
* @param {Hitchy.Core.IncomingMessage} req request descriptor
|
|
218
|
+
* @param {Hitchy.Core.ServerResponse} res response manager
|
|
219
219
|
* @param {string[]} accepted comma-separated list of accepted headers
|
|
220
220
|
* @returns {void}
|
|
221
221
|
* @protected
|
package/index.js
CHANGED
|
@@ -98,7 +98,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
98
98
|
* @param {Map<string,function(IncomingMessage,ServerResponse):Promise>} routes maps
|
|
99
99
|
* route patterns into function handling requests matching that pattern
|
|
100
100
|
* @param {string} urlPrefix common prefix to use on every route regarding any model-related processing
|
|
101
|
-
* @param {Object<string,
|
|
101
|
+
* @param {Object<string,Class<Model>>} models lists all currently available models
|
|
102
102
|
* @returns {void}
|
|
103
103
|
*/
|
|
104
104
|
function addGlobalRoutes( routes, urlPrefix, models ) {
|
|
@@ -128,8 +128,8 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
128
128
|
const model = models[modelKeys[i]];
|
|
129
129
|
|
|
130
130
|
if ( model.prototype instanceof BaseModel &&
|
|
131
|
-
OdemSchema.mayBeExposed( req, model ) &&
|
|
132
|
-
OdemSchema.mayBePromoted( req, model ) ) {
|
|
131
|
+
OdemSchema.mayBeExposed( req.user, model ) &&
|
|
132
|
+
OdemSchema.mayBePromoted( req.user, model ) ) {
|
|
133
133
|
const slug = pascalToKebab( model.name );
|
|
134
134
|
|
|
135
135
|
result[slug] = OdemSchema.extractPublicData( model );
|
|
@@ -200,7 +200,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
200
200
|
* @returns {void}
|
|
201
201
|
*/
|
|
202
202
|
function reqSuccess( req, res ) {
|
|
203
|
-
if ( Schema.mayBeExposed( req, Model ) ) {
|
|
203
|
+
if ( Schema.mayBeExposed( req.user, Model ) ) {
|
|
204
204
|
res.status( 200 ).send();
|
|
205
205
|
} else {
|
|
206
206
|
res.status( 403 ).send();
|
|
@@ -230,7 +230,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
230
230
|
async function reqFetchSchema( req, res ) {
|
|
231
231
|
logDebug( "got request fetching schema" );
|
|
232
232
|
|
|
233
|
-
if ( !Schema.mayBeExposed( req, Model ) ) {
|
|
233
|
+
if ( !Schema.mayBeExposed( req.user, Model ) ) {
|
|
234
234
|
res.status( 403 ).json( { error: "access forbidden by model" } );
|
|
235
235
|
return;
|
|
236
236
|
}
|
|
@@ -254,7 +254,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
254
254
|
async function reqCheckItem( req, res ) {
|
|
255
255
|
logDebug( "got request checking if some item exists" );
|
|
256
256
|
|
|
257
|
-
if ( !Schema.mayBeExposed( req, Model ) ) {
|
|
257
|
+
if ( !Schema.mayBeExposed( req.user, Model ) ) {
|
|
258
258
|
res.status( 403 ).json( { error: "access forbidden by model" } );
|
|
259
259
|
return;
|
|
260
260
|
}
|
|
@@ -292,7 +292,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
292
292
|
async function reqFetchItem( req, res ) {
|
|
293
293
|
logDebug( "got request fetching some item" );
|
|
294
294
|
|
|
295
|
-
if ( !Schema.mayBeExposed( req, Model ) ) {
|
|
295
|
+
if ( !Schema.mayBeExposed( req.user, Model ) ) {
|
|
296
296
|
res.status( 403 ).json( { error: "access forbidden by model" } );
|
|
297
297
|
return;
|
|
298
298
|
}
|
|
@@ -311,7 +311,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
311
311
|
const item = new Model( uuid ).withContext( this );
|
|
312
312
|
|
|
313
313
|
await item.load()
|
|
314
|
-
.then( loaded => res.json( Schema.filterItem( serializeItem( loaded, true ), req, Model, "read" ) ) )
|
|
314
|
+
.then( loaded => res.json( Schema.filterItem( serializeItem( loaded, true ), req.user, Model, "read" ) ) )
|
|
315
315
|
.catch( error => {
|
|
316
316
|
logError( "fetching %s:", routeName, error );
|
|
317
317
|
|
|
@@ -339,7 +339,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
339
339
|
async function reqFetchItems( req, res ) {
|
|
340
340
|
logDebug( "got request fetching items" );
|
|
341
341
|
|
|
342
|
-
if ( !Schema.mayBeExposed( req, Model ) ) {
|
|
342
|
+
if ( !Schema.mayBeExposed( req.user, Model ) ) {
|
|
343
343
|
res.status( 403 ).json( { error: "access forbidden by model" } );
|
|
344
344
|
return;
|
|
345
345
|
}
|
|
@@ -455,14 +455,14 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
455
455
|
|
|
456
456
|
const meta = count || req.headers["x-count"] ? {} : null;
|
|
457
457
|
|
|
458
|
-
await Model.find( Schema.checkQuery( parsedQuery, req, Model ), { offset, limit, sortBy, sortAscendingly: !descending }, {
|
|
458
|
+
await Model.find( Schema.checkQuery( parsedQuery, req.user, Model ), { offset, limit, sortBy, sortAscendingly: !descending }, {
|
|
459
459
|
metaCollector: meta,
|
|
460
460
|
loadRecords,
|
|
461
461
|
context: this,
|
|
462
462
|
} )
|
|
463
463
|
.then( matches => {
|
|
464
464
|
const result = {
|
|
465
|
-
items: matches.map( item => Schema.filterItem( serializeItem( item, false ), req, Model, "list" ) ),
|
|
465
|
+
items: matches.map( item => Schema.filterItem( serializeItem( item, false ), req.user, Model, "list" ) ),
|
|
466
466
|
};
|
|
467
467
|
|
|
468
468
|
if ( meta ) {
|
|
@@ -501,7 +501,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
501
501
|
}, { loadRecords, metaCollector: meta, context: this } )
|
|
502
502
|
.then( matches => {
|
|
503
503
|
const result = {
|
|
504
|
-
items: matches.map( item => Schema.filterItem( serializeItem( item, false ), req, Model, "list" ) ),
|
|
504
|
+
items: matches.map( item => Schema.filterItem( serializeItem( item, false ), req.user, Model, "list" ) ),
|
|
505
505
|
};
|
|
506
506
|
|
|
507
507
|
if ( meta ) {
|
|
@@ -528,7 +528,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
528
528
|
async function reqCreateItem( req, res ) {
|
|
529
529
|
logDebug( "got request creating item" );
|
|
530
530
|
|
|
531
|
-
if ( !Schema.mayBeExposed( req, Model ) ) {
|
|
531
|
+
if ( !Schema.mayBeExposed( req.user, Model ) ) {
|
|
532
532
|
res.status( 403 ).json( { error: "access forbidden by model" } );
|
|
533
533
|
return;
|
|
534
534
|
}
|
|
@@ -549,7 +549,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
549
549
|
return undefined;
|
|
550
550
|
}
|
|
551
551
|
|
|
552
|
-
const filtered = Schema.filterItem( record, req, Model, "create" );
|
|
552
|
+
const filtered = Schema.filterItem( record, req.user, Model, "create" );
|
|
553
553
|
const definedProps = Model.schema.props;
|
|
554
554
|
const definedComputed = Model.schema.computed;
|
|
555
555
|
|
|
@@ -581,7 +581,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
581
581
|
async function reqModifyItem( req, res ) {
|
|
582
582
|
logDebug( "got request to modify some item" );
|
|
583
583
|
|
|
584
|
-
if ( !Schema.mayBeExposed( req, Model ) ) {
|
|
584
|
+
if ( !Schema.mayBeExposed( req.user, Model ) ) {
|
|
585
585
|
res.status( 403 ).json( { error: "access forbidden by model" } );
|
|
586
586
|
return;
|
|
587
587
|
}
|
|
@@ -612,7 +612,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
612
612
|
] )
|
|
613
613
|
.then( ( [ loaded, record ] ) => {
|
|
614
614
|
if ( record ) {
|
|
615
|
-
const filtered = Schema.filterItem( record, req, Model, "write" );
|
|
615
|
+
const filtered = Schema.filterItem( record, req.user, Model, "write" );
|
|
616
616
|
const definedProps = Model.schema.props;
|
|
617
617
|
const definedComputed = Model.schema.computed;
|
|
618
618
|
|
|
@@ -625,7 +625,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
625
625
|
|
|
626
626
|
return loaded.save()
|
|
627
627
|
.then( saved => {
|
|
628
|
-
res.json( Schema.filterItem( serializeItem( saved, false ), req, Model, "read" ) );
|
|
628
|
+
res.json( Schema.filterItem( serializeItem( saved, false ), req.user, Model, "read" ) );
|
|
629
629
|
} );
|
|
630
630
|
} );
|
|
631
631
|
} )
|
|
@@ -646,7 +646,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
646
646
|
async function reqReplaceItem( req, res ) {
|
|
647
647
|
logDebug( "got request replacing some item" );
|
|
648
648
|
|
|
649
|
-
if ( !Schema.mayBeExposed( req, Model ) ) {
|
|
649
|
+
if ( !Schema.mayBeExposed( req.user, Model ) ) {
|
|
650
650
|
res.status( 403 ).json( { error: "access forbidden by model" } );
|
|
651
651
|
return;
|
|
652
652
|
}
|
|
@@ -672,7 +672,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
672
672
|
|
|
673
673
|
const computedNames = Object.keys( Model.schema.computed );
|
|
674
674
|
const numComputedNames = computedNames.length;
|
|
675
|
-
const filtered = Schema.filterItem( record, req, Model, "write" );
|
|
675
|
+
const filtered = Schema.filterItem( record, req.user, Model, "write" );
|
|
676
676
|
|
|
677
677
|
// update properties, drop those missing in provided record
|
|
678
678
|
for ( let i = 0; i < numPropNames; i++ ) {
|
|
@@ -692,7 +692,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
692
692
|
} );
|
|
693
693
|
} )
|
|
694
694
|
.then( saved => {
|
|
695
|
-
res.json( Schema.filterItem( serializeItem( saved, false ), req, Model, "read" ) );
|
|
695
|
+
res.json( Schema.filterItem( serializeItem( saved, false ), req.user, Model, "read" ) );
|
|
696
696
|
} )
|
|
697
697
|
.catch( error => {
|
|
698
698
|
logError( "updating %s:", routeName, error );
|
|
@@ -710,7 +710,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
710
710
|
async function reqRemoveItem( req, res ) {
|
|
711
711
|
logDebug( "got request removing some item" );
|
|
712
712
|
|
|
713
|
-
if ( !Schema.mayBeExposed( req, Model ) ) {
|
|
713
|
+
if ( !Schema.mayBeExposed( req.user, Model ) ) {
|
|
714
714
|
res.status( 403 ).json( { error: "access forbidden by model" } );
|
|
715
715
|
return;
|
|
716
716
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hitchy/plugin-odem-rest",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "HTTP REST API for Hitchy's document-oriented database",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,18 +20,18 @@
|
|
|
20
20
|
"bugs": "https://gitlab.com/hitchy/plugin-odem-rest/-/issues",
|
|
21
21
|
"homepage": "https://gitlab.com/hitchy/plugin-odem-rest#plugin-odem-rest",
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@hitchy/core": "1.
|
|
24
|
-
"@hitchy/plugin-odem": "^0.
|
|
25
|
-
"@hitchy/plugin-auth": "0.6.
|
|
23
|
+
"@hitchy/core": "^1.5.5",
|
|
24
|
+
"@hitchy/plugin-odem": "^0.14.0",
|
|
25
|
+
"@hitchy/plugin-auth": "^0.6.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@hitchy/types": "^0.1.3",
|
|
29
|
-
"@hitchy/core": "^1.
|
|
30
|
-
"@hitchy/server-dev-tools": "^0.
|
|
29
|
+
"@hitchy/core": "^1.5.5",
|
|
30
|
+
"@hitchy/server-dev-tools": "^0.9.6",
|
|
31
31
|
"c8": "^10.1.3",
|
|
32
|
-
"eslint": "^9.
|
|
32
|
+
"eslint": "^9.39.2",
|
|
33
33
|
"eslint-config-cepharum": "^2.0.2",
|
|
34
|
-
"mocha": "^11.
|
|
34
|
+
"mocha": "^11.7.5",
|
|
35
35
|
"should": "^13.2.3",
|
|
36
36
|
"should-http": "^0.1.1"
|
|
37
37
|
},
|