@aeriajs/security 0.0.45 → 0.0.47
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/dist/define.mjs +3 -2
- package/dist/immutability.mjs +47 -323
- package/dist/index.mjs +1 -0
- package/dist/ownership.mjs +26 -177
- package/dist/pagination.mjs +10 -147
- package/dist/rateLimiting.mjs +64 -238
- package/dist/types.mjs +1 -1
- package/dist/use.mjs +53 -261
- package/package.json +5 -5
package/dist/use.mjs
CHANGED
|
@@ -1,266 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function _ts_generator(thisArg, body) {
|
|
31
|
-
var f, y, t, g, _ = {
|
|
32
|
-
label: 0,
|
|
33
|
-
sent: function() {
|
|
34
|
-
if (t[0] & 1) throw t[1];
|
|
35
|
-
return t[1];
|
|
36
|
-
},
|
|
37
|
-
trys: [],
|
|
38
|
-
ops: []
|
|
39
|
-
};
|
|
40
|
-
return g = {
|
|
41
|
-
next: verb(0),
|
|
42
|
-
"throw": verb(1),
|
|
43
|
-
"return": verb(2)
|
|
44
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
45
|
-
return this;
|
|
46
|
-
}), g;
|
|
47
|
-
function verb(n) {
|
|
48
|
-
return function(v) {
|
|
49
|
-
return step([
|
|
50
|
-
n,
|
|
51
|
-
v
|
|
52
|
-
]);
|
|
53
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
import { deepMerge, right, isLeft, unwrapEither } from "@aeriajs/common";
|
|
3
|
+
import {
|
|
4
|
+
checkImmutability,
|
|
5
|
+
checkOwnershipRead,
|
|
6
|
+
checkOwnershipWrite,
|
|
7
|
+
checkPagination
|
|
8
|
+
} from "./index.mjs";
|
|
9
|
+
const chainFunctions = async (_props, context, functions) => {
|
|
10
|
+
const props = Object.assign({
|
|
11
|
+
filters: {}
|
|
12
|
+
}, _props);
|
|
13
|
+
for (const fn of functions) {
|
|
14
|
+
const resultEither = await fn(props, context);
|
|
15
|
+
if (isLeft(resultEither)) {
|
|
16
|
+
return resultEither;
|
|
54
17
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
value: op[1],
|
|
72
|
-
done: false
|
|
73
|
-
};
|
|
74
|
-
case 5:
|
|
75
|
-
_.label++;
|
|
76
|
-
y = op[1];
|
|
77
|
-
op = [
|
|
78
|
-
0
|
|
79
|
-
];
|
|
80
|
-
continue;
|
|
81
|
-
case 7:
|
|
82
|
-
op = _.ops.pop();
|
|
83
|
-
_.trys.pop();
|
|
84
|
-
continue;
|
|
85
|
-
default:
|
|
86
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
87
|
-
_ = 0;
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
91
|
-
_.label = op[1];
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
95
|
-
_.label = t[1];
|
|
96
|
-
t = op;
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
if (t && _.label < t[2]) {
|
|
100
|
-
_.label = t[2];
|
|
101
|
-
_.ops.push(op);
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
if (t[2]) _.ops.pop();
|
|
105
|
-
_.trys.pop();
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
op = body.call(thisArg, _);
|
|
109
|
-
} catch (e) {
|
|
110
|
-
op = [
|
|
111
|
-
6,
|
|
112
|
-
e
|
|
113
|
-
];
|
|
114
|
-
y = 0;
|
|
115
|
-
} finally{
|
|
116
|
-
f = t = 0;
|
|
117
|
-
}
|
|
118
|
-
if (op[0] & 5) throw op[1];
|
|
119
|
-
return {
|
|
120
|
-
value: op[0] ? op[1] : void 0,
|
|
121
|
-
done: true
|
|
122
|
-
};
|
|
18
|
+
const result = unwrapEither(resultEither);
|
|
19
|
+
Object.assign(props.payload, result);
|
|
20
|
+
}
|
|
21
|
+
return right(props.payload);
|
|
22
|
+
};
|
|
23
|
+
export const useSecurity = (context) => {
|
|
24
|
+
const options = context.description.options ? Object.assign({}, context.description.options) : {};
|
|
25
|
+
const beforeRead = async (payload) => {
|
|
26
|
+
const newPayload = Object.assign({}, payload);
|
|
27
|
+
newPayload.filters ??= {};
|
|
28
|
+
if (options.queryPreset) {
|
|
29
|
+
Object.assign(newPayload, deepMerge(
|
|
30
|
+
newPayload,
|
|
31
|
+
options.queryPreset
|
|
32
|
+
));
|
|
123
33
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
import { checkImmutability, checkOwnershipRead, checkOwnershipWrite, checkPagination } from "./index.mjs";
|
|
127
|
-
var chainFunctions = function() {
|
|
128
|
-
var _ref = _async_to_generator(function(_props, context, functions) {
|
|
129
|
-
var props, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, fn, resultEither, result, err;
|
|
130
|
-
return _ts_generator(this, function(_state) {
|
|
131
|
-
switch(_state.label){
|
|
132
|
-
case 0:
|
|
133
|
-
props = Object.assign({
|
|
134
|
-
filters: {}
|
|
135
|
-
}, _props);
|
|
136
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
137
|
-
_state.label = 1;
|
|
138
|
-
case 1:
|
|
139
|
-
_state.trys.push([
|
|
140
|
-
1,
|
|
141
|
-
6,
|
|
142
|
-
7,
|
|
143
|
-
8
|
|
144
|
-
]);
|
|
145
|
-
_iterator = functions[Symbol.iterator]();
|
|
146
|
-
_state.label = 2;
|
|
147
|
-
case 2:
|
|
148
|
-
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
149
|
-
3,
|
|
150
|
-
5
|
|
151
|
-
];
|
|
152
|
-
fn = _step.value;
|
|
153
|
-
return [
|
|
154
|
-
4,
|
|
155
|
-
fn(props, context)
|
|
156
|
-
];
|
|
157
|
-
case 3:
|
|
158
|
-
resultEither = _state.sent();
|
|
159
|
-
if (isLeft(resultEither)) {
|
|
160
|
-
return [
|
|
161
|
-
2,
|
|
162
|
-
resultEither
|
|
163
|
-
];
|
|
164
|
-
}
|
|
165
|
-
result = unwrapEither(resultEither);
|
|
166
|
-
Object.assign(props.payload, result);
|
|
167
|
-
_state.label = 4;
|
|
168
|
-
case 4:
|
|
169
|
-
_iteratorNormalCompletion = true;
|
|
170
|
-
return [
|
|
171
|
-
3,
|
|
172
|
-
2
|
|
173
|
-
];
|
|
174
|
-
case 5:
|
|
175
|
-
return [
|
|
176
|
-
3,
|
|
177
|
-
8
|
|
178
|
-
];
|
|
179
|
-
case 6:
|
|
180
|
-
err = _state.sent();
|
|
181
|
-
_didIteratorError = true;
|
|
182
|
-
_iteratorError = err;
|
|
183
|
-
return [
|
|
184
|
-
3,
|
|
185
|
-
8
|
|
186
|
-
];
|
|
187
|
-
case 7:
|
|
188
|
-
try {
|
|
189
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
190
|
-
_iterator.return();
|
|
191
|
-
}
|
|
192
|
-
} finally{
|
|
193
|
-
if (_didIteratorError) {
|
|
194
|
-
throw _iteratorError;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return [
|
|
198
|
-
7
|
|
199
|
-
];
|
|
200
|
-
case 8:
|
|
201
|
-
return [
|
|
202
|
-
2,
|
|
203
|
-
right(props.payload)
|
|
204
|
-
];
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
return function chainFunctions(_props, context, functions) {
|
|
209
|
-
return _ref.apply(this, arguments);
|
|
34
|
+
const props = {
|
|
35
|
+
payload: newPayload
|
|
210
36
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
props = {
|
|
224
|
-
payload: newPayload
|
|
225
|
-
};
|
|
226
|
-
return [
|
|
227
|
-
2,
|
|
228
|
-
chainFunctions(props, context, [
|
|
229
|
-
checkPagination,
|
|
230
|
-
checkOwnershipRead
|
|
231
|
-
])
|
|
232
|
-
];
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
return function beforeRead(payload) {
|
|
236
|
-
return _ref.apply(this, arguments);
|
|
237
|
-
};
|
|
238
|
-
}();
|
|
239
|
-
var beforeWrite = function() {
|
|
240
|
-
var _ref = _async_to_generator(function(payload) {
|
|
241
|
-
var newPayload, props;
|
|
242
|
-
return _ts_generator(this, function(_state) {
|
|
243
|
-
newPayload = Object.assign({
|
|
244
|
-
what: {}
|
|
245
|
-
}, payload);
|
|
246
|
-
props = {
|
|
247
|
-
payload: newPayload
|
|
248
|
-
};
|
|
249
|
-
return [
|
|
250
|
-
2,
|
|
251
|
-
chainFunctions(props, context, [
|
|
252
|
-
checkOwnershipWrite,
|
|
253
|
-
checkImmutability
|
|
254
|
-
])
|
|
255
|
-
];
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
return function beforeWrite(payload) {
|
|
259
|
-
return _ref.apply(this, arguments);
|
|
260
|
-
};
|
|
261
|
-
}();
|
|
262
|
-
return {
|
|
263
|
-
beforeRead: beforeRead,
|
|
264
|
-
beforeWrite: beforeWrite
|
|
37
|
+
return chainFunctions(props, context, [
|
|
38
|
+
checkPagination,
|
|
39
|
+
checkOwnershipRead
|
|
40
|
+
]);
|
|
41
|
+
};
|
|
42
|
+
const beforeWrite = async (payload) => {
|
|
43
|
+
const newPayload = Object.assign({
|
|
44
|
+
what: {}
|
|
45
|
+
}, payload);
|
|
46
|
+
const props = {
|
|
47
|
+
payload: newPayload
|
|
265
48
|
};
|
|
49
|
+
return chainFunctions(props, context, [
|
|
50
|
+
checkOwnershipWrite,
|
|
51
|
+
checkImmutability
|
|
52
|
+
]);
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
beforeRead,
|
|
56
|
+
beforeWrite
|
|
57
|
+
};
|
|
266
58
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/security",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@aeriajs/api": "^0.0.
|
|
26
|
-
"@aeriajs/common": "^0.0.
|
|
27
|
-
"@aeriajs/types": "^0.0.
|
|
25
|
+
"@aeriajs/api": "^0.0.47",
|
|
26
|
+
"@aeriajs/common": "^0.0.24",
|
|
27
|
+
"@aeriajs/types": "^0.0.21",
|
|
28
28
|
"mongodb": "^6.1.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"lint:fix": "eslint src --fix",
|
|
37
37
|
"build": "pnpm build:cjs && pnpm build:esm",
|
|
38
38
|
"build:cjs": "tsc",
|
|
39
|
-
"build:esm": "
|
|
39
|
+
"build:esm": "esbuild './src/**/*.ts' --outdir=dist --out-extension:.js=.mjs && pnpm build:esm-transform",
|
|
40
40
|
"build:esm-transform": "pnpm -w esm-transform $PWD/dist"
|
|
41
41
|
}
|
|
42
42
|
}
|