@aeriajs/security 0.0.108 → 0.0.110
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/immutability.js +6 -7
- package/dist/immutability.mjs +1 -2
- package/dist/ownership.js +4 -5
- package/dist/ownership.mjs +1 -2
- package/dist/pagination.js +2 -3
- package/dist/pagination.mjs +1 -2
- package/dist/rateLimiting.d.ts +2 -2
- package/dist/rateLimiting.js +1 -2
- package/dist/rateLimiting.mjs +1 -2
- package/dist/types.d.ts +1 -2
- package/dist/use.d.ts +2 -2
- package/dist/use.js +3 -2
- package/dist/use.mjs +2 -1
- package/package.json +4 -4
package/dist/immutability.js
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkImmutability = void 0;
|
|
4
4
|
const types_1 = require("@aeriajs/types");
|
|
5
|
-
const common_1 = require("@aeriajs/common");
|
|
6
5
|
const checkImmutability = async (props, context) => {
|
|
7
6
|
if (!context.description.immutable) {
|
|
8
|
-
return
|
|
7
|
+
return types_1.Result.result(props.payload);
|
|
9
8
|
}
|
|
10
9
|
const docId = 'filters' in props.payload
|
|
11
10
|
? props.payload.filters._id
|
|
@@ -16,15 +15,15 @@ const checkImmutability = async (props, context) => {
|
|
|
16
15
|
_id: docId,
|
|
17
16
|
});
|
|
18
17
|
if (!doc) {
|
|
19
|
-
return
|
|
18
|
+
return types_1.Result.error(types_1.ACError.ResourceNotFound);
|
|
20
19
|
}
|
|
21
20
|
const isImmutable = await context.description.immutable(doc);
|
|
22
21
|
return isImmutable
|
|
23
|
-
?
|
|
24
|
-
:
|
|
22
|
+
? types_1.Result.error(types_1.ACError.TargetImmutable)
|
|
23
|
+
: types_1.Result.result(props.payload);
|
|
25
24
|
}
|
|
26
|
-
return
|
|
25
|
+
return types_1.Result.error(types_1.ACError.TargetImmutable);
|
|
27
26
|
}
|
|
28
|
-
return
|
|
27
|
+
return types_1.Result.result(props.payload);
|
|
29
28
|
};
|
|
30
29
|
exports.checkImmutability = checkImmutability;
|
package/dist/immutability.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { ACError } from "@aeriajs/types";
|
|
3
|
-
import { Result } from "@aeriajs/common";
|
|
2
|
+
import { Result, ACError } from "@aeriajs/types";
|
|
4
3
|
export const checkImmutability = async (props, context) => {
|
|
5
4
|
if (!context.description.immutable) {
|
|
6
5
|
return Result.result(props.payload);
|
package/dist/ownership.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkOwnershipWrite = exports.checkOwnershipRead = void 0;
|
|
4
4
|
const types_1 = require("@aeriajs/types");
|
|
5
|
-
const common_1 = require("@aeriajs/common");
|
|
6
5
|
const checkOwnershipRead = async (props, context) => {
|
|
7
6
|
const { token, description } = context;
|
|
8
7
|
const payload = Object.assign({}, props.payload);
|
|
@@ -11,7 +10,7 @@ const checkOwnershipRead = async (props, context) => {
|
|
|
11
10
|
payload.filters.owner = token.sub;
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
|
-
return
|
|
13
|
+
return types_1.Result.result(payload);
|
|
15
14
|
};
|
|
16
15
|
exports.checkOwnershipRead = checkOwnershipRead;
|
|
17
16
|
const checkOwnershipWrite = async (props, context) => {
|
|
@@ -23,12 +22,12 @@ const checkOwnershipWrite = async (props, context) => {
|
|
|
23
22
|
payload.what.owner = token.sub;
|
|
24
23
|
}
|
|
25
24
|
else {
|
|
26
|
-
return
|
|
25
|
+
return types_1.Result.result(payload);
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
28
|
if ((!payload.what.owner && !parentId) && context.description.owned) {
|
|
30
|
-
return
|
|
29
|
+
return types_1.Result.error(types_1.ACError.OwnershipError);
|
|
31
30
|
}
|
|
32
|
-
return
|
|
31
|
+
return types_1.Result.result(payload);
|
|
33
32
|
};
|
|
34
33
|
exports.checkOwnershipWrite = checkOwnershipWrite;
|
package/dist/ownership.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { ACError } from "@aeriajs/types";
|
|
3
|
-
import { Result } from "@aeriajs/common";
|
|
2
|
+
import { Result, ACError } from "@aeriajs/types";
|
|
4
3
|
export const checkOwnershipRead = async (props, context) => {
|
|
5
4
|
const { token, description } = context;
|
|
6
5
|
const payload = Object.assign({}, props.payload);
|
package/dist/pagination.js
CHANGED
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkPagination = void 0;
|
|
4
4
|
const types_1 = require("@aeriajs/types");
|
|
5
|
-
const common_1 = require("@aeriajs/common");
|
|
6
5
|
const checkPagination = async (props) => {
|
|
7
6
|
const { payload } = props;
|
|
8
7
|
if (payload.limit) {
|
|
9
8
|
if (payload.limit <= 0 || payload.limit > 150) {
|
|
10
|
-
return
|
|
9
|
+
return types_1.Result.error(types_1.ACError.InvalidLimit);
|
|
11
10
|
}
|
|
12
11
|
}
|
|
13
|
-
return
|
|
12
|
+
return types_1.Result.result(payload);
|
|
14
13
|
};
|
|
15
14
|
exports.checkPagination = checkPagination;
|
package/dist/pagination.mjs
CHANGED
package/dist/rateLimiting.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RouteContext, RateLimitingParams } from '@aeriajs/types';
|
|
2
|
-
import { HTTPStatus, RateLimitingError } from '@aeriajs/types';
|
|
2
|
+
import { Result, HTTPStatus, RateLimitingError } from '@aeriajs/types';
|
|
3
3
|
export declare const getOrCreateUsageEntry: (params: RateLimitingParams, context: RouteContext) => Promise<import("@aeriajs/types").WithId<Omit<import("@aeriajs/types").PackReferences<import("@aeriajs/types").SchemaWithId<{
|
|
4
4
|
readonly $id: "resourceUsage";
|
|
5
5
|
readonly required: readonly ["usage"];
|
|
@@ -34,7 +34,7 @@ export declare const getOrCreateUsageEntry: (params: RateLimitingParams, context
|
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
}>>, "_id">>>;
|
|
37
|
-
export declare const limitRate: (params: RateLimitingParams, context: RouteContext) => Promise<
|
|
37
|
+
export declare const limitRate: (params: RateLimitingParams, context: RouteContext) => Promise<Result.Error<{
|
|
38
38
|
readonly code: RateLimitingError.LimitReached;
|
|
39
39
|
} & {
|
|
40
40
|
httpStatus: HTTPStatus.TooManyRequests;
|
package/dist/rateLimiting.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.limitRate = exports.getOrCreateUsageEntry = void 0;
|
|
4
4
|
const types_1 = require("@aeriajs/types");
|
|
5
|
-
const common_1 = require("@aeriajs/common");
|
|
6
5
|
const buildEntryFilter = (params, context) => {
|
|
7
6
|
if (params.strategy === 'ip') {
|
|
8
7
|
const address = context.response.socket.remoteAddress;
|
|
@@ -66,6 +65,6 @@ const limitRate = async (params, context) => {
|
|
|
66
65
|
if (!newEntry) {
|
|
67
66
|
throw new Error();
|
|
68
67
|
}
|
|
69
|
-
return
|
|
68
|
+
return types_1.Result.result(newEntry.usage[resourceName]);
|
|
70
69
|
};
|
|
71
70
|
exports.limitRate = limitRate;
|
package/dist/rateLimiting.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { HTTPStatus, RateLimitingError } from "@aeriajs/types";
|
|
3
|
-
import { Result } from "@aeriajs/common";
|
|
2
|
+
import { Result, HTTPStatus, RateLimitingError } from "@aeriajs/types";
|
|
4
3
|
const buildEntryFilter = (params, context) => {
|
|
5
4
|
if (params.strategy === "ip") {
|
|
6
5
|
const address = context.response.socket.remoteAddress;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Context, GetAllPayload, InsertPayload, ACError } from '@aeriajs/types';
|
|
2
|
-
import type { Result } from '@aeriajs/common';
|
|
1
|
+
import type { Result, Context, GetAllPayload, InsertPayload, ACError } from '@aeriajs/types';
|
|
3
2
|
export type SecurityCheckReadPayload = {
|
|
4
3
|
filters: Record<string, any>;
|
|
5
4
|
sort?: Record<string, any>;
|
package/dist/use.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Context, Description, GetAllPayload, InsertPayload } from '@aeriaj
|
|
|
2
2
|
export declare const useSecurity: <TDescription extends Description>(context: Context<TDescription>) => {
|
|
3
3
|
beforeRead: <TPayload extends Partial<GetAllPayload<any>>>(payload?: TPayload) => Promise<{
|
|
4
4
|
readonly _tag: "Error";
|
|
5
|
-
readonly error:
|
|
5
|
+
readonly error: import("@aeriajs/types").ACError;
|
|
6
6
|
readonly result: undefined;
|
|
7
7
|
} | {
|
|
8
8
|
readonly _tag: "Result";
|
|
@@ -11,7 +11,7 @@ export declare const useSecurity: <TDescription extends Description>(context: Co
|
|
|
11
11
|
}>;
|
|
12
12
|
beforeWrite: <TPayload_1 extends Partial<InsertPayload<any>>>(payload?: TPayload_1 | undefined) => Promise<{
|
|
13
13
|
readonly _tag: "Error";
|
|
14
|
-
readonly error:
|
|
14
|
+
readonly error: import("@aeriajs/types").ACError;
|
|
15
15
|
readonly result: undefined;
|
|
16
16
|
} | {
|
|
17
17
|
readonly _tag: "Result";
|
package/dist/use.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSecurity = void 0;
|
|
4
|
+
const types_1 = require("@aeriajs/types");
|
|
4
5
|
const common_1 = require("@aeriajs/common");
|
|
5
6
|
const index_js_1 = require("./index.js");
|
|
6
7
|
const chainFunctions = async (_props, context, functions) => {
|
|
@@ -13,11 +14,11 @@ const chainFunctions = async (_props, context, functions) => {
|
|
|
13
14
|
}
|
|
14
15
|
const { error, result } = await fn(props, context);
|
|
15
16
|
if (error) {
|
|
16
|
-
return
|
|
17
|
+
return types_1.Result.error(error);
|
|
17
18
|
}
|
|
18
19
|
Object.assign(props.payload, result);
|
|
19
20
|
}
|
|
20
|
-
return
|
|
21
|
+
return types_1.Result.result(props.payload);
|
|
21
22
|
};
|
|
22
23
|
const useSecurity = (context) => {
|
|
23
24
|
const options = context.description.options
|
package/dist/use.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/security",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.110",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"mongodb": "^6.5.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@aeriajs/core": "^0.0.
|
|
32
|
-
"@aeriajs/common": "^0.0.
|
|
33
|
-
"@aeriajs/types": "^0.0.
|
|
31
|
+
"@aeriajs/core": "^0.0.110",
|
|
32
|
+
"@aeriajs/common": "^0.0.69",
|
|
33
|
+
"@aeriajs/types": "^0.0.61",
|
|
34
34
|
"mongodb": "^6.5.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|