@aeriajs/security 0.0.95 → 0.0.96
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.d.ts +13 -1
- package/dist/immutability.js +6 -6
- package/dist/immutability.mjs +6 -6
- package/dist/ownership.d.ts +14 -2
- package/dist/ownership.js +4 -4
- package/dist/ownership.mjs +5 -5
- package/dist/pagination.d.ts +9 -1
- package/dist/pagination.js +2 -2
- package/dist/pagination.mjs +3 -3
- package/dist/rateLimiting.d.ts +26 -22
- package/dist/rateLimiting.js +2 -1
- package/dist/rateLimiting.mjs +2 -1
- package/dist/types.d.ts +3 -2
- package/dist/use.d.ts +18 -2
- package/dist/use.js +4 -5
- package/dist/use.mjs +5 -6
- package/package.json +4 -4
package/dist/immutability.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import type { Context } from '@aeriajs/types';
|
|
2
2
|
import type { SecurityCheckProps, SecurityCheckReadPayload, SecurityCheckWritePayload } from './types.js';
|
|
3
3
|
import { ACError } from '@aeriajs/types';
|
|
4
|
-
export declare const checkImmutability: (props: SecurityCheckProps<SecurityCheckReadPayload | SecurityCheckWritePayload>, context: Context) => Promise<
|
|
4
|
+
export declare const checkImmutability: (props: SecurityCheckProps<SecurityCheckReadPayload | SecurityCheckWritePayload>, context: Context) => Promise<{
|
|
5
|
+
readonly _tag: "Result";
|
|
6
|
+
readonly error: undefined;
|
|
7
|
+
readonly result: SecurityCheckReadPayload | SecurityCheckWritePayload;
|
|
8
|
+
} | {
|
|
9
|
+
readonly _tag: "Error";
|
|
10
|
+
readonly error: ACError.ResourceNotFound;
|
|
11
|
+
readonly result: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
readonly _tag: "Error";
|
|
14
|
+
readonly error: ACError.TargetImmutable;
|
|
15
|
+
readonly result: undefined;
|
|
16
|
+
}>;
|
package/dist/immutability.js
CHANGED
|
@@ -5,7 +5,7 @@ const types_1 = require("@aeriajs/types");
|
|
|
5
5
|
const common_1 = require("@aeriajs/common");
|
|
6
6
|
const checkImmutability = async (props, context) => {
|
|
7
7
|
if (!context.description.immutable) {
|
|
8
|
-
return
|
|
8
|
+
return common_1.Result.result(props.payload);
|
|
9
9
|
}
|
|
10
10
|
const docId = 'filters' in props.payload
|
|
11
11
|
? props.payload.filters._id
|
|
@@ -16,15 +16,15 @@ const checkImmutability = async (props, context) => {
|
|
|
16
16
|
_id: docId,
|
|
17
17
|
});
|
|
18
18
|
if (!doc) {
|
|
19
|
-
return
|
|
19
|
+
return common_1.Result.error(types_1.ACError.ResourceNotFound);
|
|
20
20
|
}
|
|
21
21
|
const isImmutable = await context.description.immutable(doc);
|
|
22
22
|
return isImmutable
|
|
23
|
-
?
|
|
24
|
-
:
|
|
23
|
+
? common_1.Result.error(types_1.ACError.TargetImmutable)
|
|
24
|
+
: common_1.Result.result(props.payload);
|
|
25
25
|
}
|
|
26
|
-
return
|
|
26
|
+
return common_1.Result.error(types_1.ACError.TargetImmutable);
|
|
27
27
|
}
|
|
28
|
-
return
|
|
28
|
+
return common_1.Result.result(props.payload);
|
|
29
29
|
};
|
|
30
30
|
exports.checkImmutability = checkImmutability;
|
package/dist/immutability.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { ACError } from "@aeriajs/types";
|
|
3
|
-
import {
|
|
3
|
+
import { Result } from "@aeriajs/common";
|
|
4
4
|
export const checkImmutability = async (props, context) => {
|
|
5
5
|
if (!context.description.immutable) {
|
|
6
|
-
return
|
|
6
|
+
return Result.result(props.payload);
|
|
7
7
|
}
|
|
8
8
|
const docId = "filters" in props.payload ? props.payload.filters._id : props.payload.what._id;
|
|
9
9
|
if (docId) {
|
|
@@ -12,12 +12,12 @@ export const checkImmutability = async (props, context) => {
|
|
|
12
12
|
_id: docId
|
|
13
13
|
});
|
|
14
14
|
if (!doc) {
|
|
15
|
-
return
|
|
15
|
+
return Result.error(ACError.ResourceNotFound);
|
|
16
16
|
}
|
|
17
17
|
const isImmutable = await context.description.immutable(doc);
|
|
18
|
-
return isImmutable ?
|
|
18
|
+
return isImmutable ? Result.error(ACError.TargetImmutable) : Result.result(props.payload);
|
|
19
19
|
}
|
|
20
|
-
return
|
|
20
|
+
return Result.error(ACError.TargetImmutable);
|
|
21
21
|
}
|
|
22
|
-
return
|
|
22
|
+
return Result.result(props.payload);
|
|
23
23
|
};
|
package/dist/ownership.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import type { Context, InsertPayload } from '@aeriajs/types';
|
|
2
2
|
import type { SecurityCheckProps, SecurityCheckReadPayload } from './types.js';
|
|
3
3
|
import { ACError } from '@aeriajs/types';
|
|
4
|
-
export declare const checkOwnershipRead: (props: SecurityCheckProps<SecurityCheckReadPayload>, context: Context) => Promise<
|
|
5
|
-
|
|
4
|
+
export declare const checkOwnershipRead: (props: SecurityCheckProps<SecurityCheckReadPayload>, context: Context) => Promise<{
|
|
5
|
+
readonly _tag: "Result";
|
|
6
|
+
readonly error: undefined;
|
|
7
|
+
readonly result: SecurityCheckReadPayload;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const checkOwnershipWrite: (props: SecurityCheckProps<InsertPayload<any>>, context: Context) => Promise<{
|
|
10
|
+
readonly _tag: "Result";
|
|
11
|
+
readonly error: undefined;
|
|
12
|
+
readonly result: InsertPayload<any>;
|
|
13
|
+
} | {
|
|
14
|
+
readonly _tag: "Error";
|
|
15
|
+
readonly error: ACError.OwnershipError;
|
|
16
|
+
readonly result: undefined;
|
|
17
|
+
}>;
|
package/dist/ownership.js
CHANGED
|
@@ -11,7 +11,7 @@ const checkOwnershipRead = async (props, context) => {
|
|
|
11
11
|
payload.filters.owner = token.sub;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
return
|
|
14
|
+
return common_1.Result.result(payload);
|
|
15
15
|
};
|
|
16
16
|
exports.checkOwnershipRead = checkOwnershipRead;
|
|
17
17
|
const checkOwnershipWrite = async (props, context) => {
|
|
@@ -23,12 +23,12 @@ const checkOwnershipWrite = async (props, context) => {
|
|
|
23
23
|
payload.what.owner = token.sub;
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
-
return
|
|
26
|
+
return common_1.Result.result(payload);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
if ((!payload.what.owner && !parentId) && context.description.owned) {
|
|
30
|
-
return
|
|
30
|
+
return common_1.Result.error(types_1.ACError.OwnershipError);
|
|
31
31
|
}
|
|
32
|
-
return
|
|
32
|
+
return common_1.Result.result(payload);
|
|
33
33
|
};
|
|
34
34
|
exports.checkOwnershipWrite = checkOwnershipWrite;
|
package/dist/ownership.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { ACError } from "@aeriajs/types";
|
|
3
|
-
import {
|
|
3
|
+
import { Result } from "@aeriajs/common";
|
|
4
4
|
export const checkOwnershipRead = async (props, context) => {
|
|
5
5
|
const { token, description } = context;
|
|
6
6
|
const payload = Object.assign({}, props.payload);
|
|
@@ -9,7 +9,7 @@ export const checkOwnershipRead = async (props, context) => {
|
|
|
9
9
|
payload.filters.owner = token.sub;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
return
|
|
12
|
+
return Result.result(payload);
|
|
13
13
|
};
|
|
14
14
|
export const checkOwnershipWrite = async (props, context) => {
|
|
15
15
|
const { token, description } = context;
|
|
@@ -19,11 +19,11 @@ export const checkOwnershipWrite = async (props, context) => {
|
|
|
19
19
|
if (!payload.what._id || description.owned === "always") {
|
|
20
20
|
payload.what.owner = token.sub;
|
|
21
21
|
} else {
|
|
22
|
-
return
|
|
22
|
+
return Result.result(payload);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
if (!payload.what.owner && !parentId && context.description.owned) {
|
|
26
|
-
return
|
|
26
|
+
return Result.error(ACError.OwnershipError);
|
|
27
27
|
}
|
|
28
|
-
return
|
|
28
|
+
return Result.result(payload);
|
|
29
29
|
};
|
package/dist/pagination.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
import type { SecurityCheckProps, SecurityCheckReadPayload } from './types.js';
|
|
2
2
|
import { ACError } from '@aeriajs/types';
|
|
3
|
-
export declare const checkPagination: (props: SecurityCheckProps<SecurityCheckReadPayload>) => Promise<
|
|
3
|
+
export declare const checkPagination: (props: SecurityCheckProps<SecurityCheckReadPayload>) => Promise<{
|
|
4
|
+
readonly _tag: "Result";
|
|
5
|
+
readonly error: undefined;
|
|
6
|
+
readonly result: SecurityCheckReadPayload;
|
|
7
|
+
} | {
|
|
8
|
+
readonly _tag: "Error";
|
|
9
|
+
readonly error: ACError.InvalidLimit;
|
|
10
|
+
readonly result: undefined;
|
|
11
|
+
}>;
|
package/dist/pagination.js
CHANGED
|
@@ -7,9 +7,9 @@ const checkPagination = async (props) => {
|
|
|
7
7
|
const { payload } = props;
|
|
8
8
|
if (payload.limit) {
|
|
9
9
|
if (payload.limit <= 0 || payload.limit > 150) {
|
|
10
|
-
return
|
|
10
|
+
return common_1.Result.error(types_1.ACError.InvalidLimit);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
return
|
|
13
|
+
return common_1.Result.result(payload);
|
|
14
14
|
};
|
|
15
15
|
exports.checkPagination = checkPagination;
|
package/dist/pagination.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { ACError } from "@aeriajs/types";
|
|
3
|
-
import {
|
|
3
|
+
import { Result } from "@aeriajs/common";
|
|
4
4
|
export const checkPagination = async (props) => {
|
|
5
5
|
const { payload } = props;
|
|
6
6
|
if (payload.limit) {
|
|
7
7
|
if (payload.limit <= 0 || payload.limit > 150) {
|
|
8
|
-
return
|
|
8
|
+
return Result.error(ACError.InvalidLimit);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
return
|
|
11
|
+
return Result.result(payload);
|
|
12
12
|
};
|
package/dist/rateLimiting.d.ts
CHANGED
|
@@ -34,28 +34,32 @@ export declare const getOrCreateUsageEntry: (params: RateLimitingParams, context
|
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
}>>, "_id">>>;
|
|
37
|
-
export declare const limitRate: (params: RateLimitingParams, context: RouteContext) => Promise<import("
|
|
38
|
-
readonly hits: {
|
|
39
|
-
readonly type: "integer";
|
|
40
|
-
};
|
|
41
|
-
readonly points: {
|
|
42
|
-
readonly type: "integer";
|
|
43
|
-
};
|
|
44
|
-
readonly last_reach: {
|
|
45
|
-
readonly type: "string";
|
|
46
|
-
readonly format: "date-time";
|
|
47
|
-
};
|
|
48
|
-
readonly last_maximum_reach: {
|
|
49
|
-
readonly type: "string";
|
|
50
|
-
readonly format: "date-time";
|
|
51
|
-
};
|
|
52
|
-
}>> & {
|
|
53
|
-
hits: number;
|
|
54
|
-
points: number;
|
|
55
|
-
last_reach: Date;
|
|
56
|
-
last_maximum_reach: Date;
|
|
57
|
-
}, never>> | import("@aeriajs/types").EndpointError<{
|
|
37
|
+
export declare const limitRate: (params: RateLimitingParams, context: RouteContext) => Promise<import("../../types/dist/result").Result.Error<{
|
|
58
38
|
readonly code: RateLimitingError.LimitReached;
|
|
59
39
|
} & {
|
|
60
40
|
httpStatus: HTTPStatus.TooManyRequests;
|
|
61
|
-
}
|
|
41
|
+
}> | {
|
|
42
|
+
readonly _tag: "Result";
|
|
43
|
+
readonly error: undefined;
|
|
44
|
+
readonly result: import("@aeriajs/types").PackReferences<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
|
|
45
|
+
readonly hits: {
|
|
46
|
+
readonly type: "integer";
|
|
47
|
+
};
|
|
48
|
+
readonly points: {
|
|
49
|
+
readonly type: "integer";
|
|
50
|
+
};
|
|
51
|
+
readonly last_reach: {
|
|
52
|
+
readonly type: "string";
|
|
53
|
+
readonly format: "date-time";
|
|
54
|
+
};
|
|
55
|
+
readonly last_maximum_reach: {
|
|
56
|
+
readonly type: "string";
|
|
57
|
+
readonly format: "date-time";
|
|
58
|
+
};
|
|
59
|
+
}>> & {
|
|
60
|
+
hits: number;
|
|
61
|
+
points: number;
|
|
62
|
+
last_reach: Date;
|
|
63
|
+
last_maximum_reach: Date;
|
|
64
|
+
}, never>>;
|
|
65
|
+
}>;
|
package/dist/rateLimiting.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
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");
|
|
5
6
|
const buildEntryFilter = (params, context) => {
|
|
6
7
|
if (params.strategy === 'ip') {
|
|
7
8
|
const address = context.response.socket.remoteAddress;
|
|
@@ -65,6 +66,6 @@ const limitRate = async (params, context) => {
|
|
|
65
66
|
if (!newEntry) {
|
|
66
67
|
throw new Error();
|
|
67
68
|
}
|
|
68
|
-
return newEntry.usage[resourceName];
|
|
69
|
+
return common_1.Result.result(newEntry.usage[resourceName]);
|
|
69
70
|
};
|
|
70
71
|
exports.limitRate = limitRate;
|
package/dist/rateLimiting.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { HTTPStatus, RateLimitingError } from "@aeriajs/types";
|
|
3
|
+
import { Result } from "@aeriajs/common";
|
|
3
4
|
const buildEntryFilter = (params, context) => {
|
|
4
5
|
if (params.strategy === "ip") {
|
|
5
6
|
const address = context.response.socket.remoteAddress;
|
|
@@ -70,5 +71,5 @@ export const limitRate = async (params, context) => {
|
|
|
70
71
|
if (!newEntry) {
|
|
71
72
|
throw new Error();
|
|
72
73
|
}
|
|
73
|
-
return newEntry.usage[resourceName];
|
|
74
|
+
return Result.result(newEntry.usage[resourceName]);
|
|
74
75
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Context,
|
|
1
|
+
import type { Context, GetAllPayload, InsertPayload, ACError } from '@aeriajs/types';
|
|
2
|
+
import type { Result } from '@aeriajs/common';
|
|
2
3
|
export type SecurityCheckReadPayload = {
|
|
3
4
|
filters: Record<string, any>;
|
|
4
5
|
sort?: Record<string, any>;
|
|
@@ -14,4 +15,4 @@ export type SecurityCheckProps<TPayload extends Record<string, any> = any> = {
|
|
|
14
15
|
childId?: string;
|
|
15
16
|
payload: TPayload;
|
|
16
17
|
};
|
|
17
|
-
export type SecurityCheck = (props: SecurityCheckProps, context: Context) => Promise<Either<ACError, GetAllPayload<any> | InsertPayload<any>>>;
|
|
18
|
+
export type SecurityCheck = (props: SecurityCheckProps, context: Context) => Promise<Result.Either<ACError, GetAllPayload<any> | InsertPayload<any>>>;
|
package/dist/use.d.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import type { Context, Description, GetAllPayload, InsertPayload } from '@aeriajs/types';
|
|
2
2
|
export declare const useSecurity: <TDescription extends Description>(context: Context<TDescription>) => {
|
|
3
|
-
beforeRead: <TPayload extends Partial<GetAllPayload<any>>>(payload?: TPayload) => Promise<
|
|
4
|
-
|
|
3
|
+
beforeRead: <TPayload extends Partial<GetAllPayload<any>>>(payload?: TPayload) => Promise<{
|
|
4
|
+
readonly _tag: "Error";
|
|
5
|
+
readonly error: any;
|
|
6
|
+
readonly result: undefined;
|
|
7
|
+
} | {
|
|
8
|
+
readonly _tag: "Result";
|
|
9
|
+
readonly error: undefined;
|
|
10
|
+
readonly result: any;
|
|
11
|
+
}>;
|
|
12
|
+
beforeWrite: <TPayload_1 extends Partial<InsertPayload<any>>>(payload?: TPayload_1 | undefined) => Promise<{
|
|
13
|
+
readonly _tag: "Error";
|
|
14
|
+
readonly error: any;
|
|
15
|
+
readonly result: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
readonly _tag: "Result";
|
|
18
|
+
readonly error: undefined;
|
|
19
|
+
readonly result: any;
|
|
20
|
+
}>;
|
|
5
21
|
};
|
package/dist/use.js
CHANGED
|
@@ -11,14 +11,13 @@ const chainFunctions = async (_props, context, functions) => {
|
|
|
11
11
|
if (!fn) {
|
|
12
12
|
continue;
|
|
13
13
|
}
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
return
|
|
14
|
+
const { error, result } = await fn(props, context);
|
|
15
|
+
if (error) {
|
|
16
|
+
return common_1.Result.error(error);
|
|
17
17
|
}
|
|
18
|
-
const result = (0, common_1.unwrapEither)(resultEither);
|
|
19
18
|
Object.assign(props.payload, result);
|
|
20
19
|
}
|
|
21
|
-
return
|
|
20
|
+
return common_1.Result.result(props.payload);
|
|
22
21
|
};
|
|
23
22
|
const useSecurity = (context) => {
|
|
24
23
|
const options = context.description.options
|
package/dist/use.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { deepMerge,
|
|
2
|
+
import { deepMerge, Result } from "@aeriajs/common";
|
|
3
3
|
import {
|
|
4
4
|
checkImmutability,
|
|
5
5
|
checkOwnershipRead,
|
|
@@ -14,14 +14,13 @@ const chainFunctions = async (_props, context, functions) => {
|
|
|
14
14
|
if (!fn) {
|
|
15
15
|
continue;
|
|
16
16
|
}
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
return
|
|
17
|
+
const { error, result } = await fn(props, context);
|
|
18
|
+
if (error) {
|
|
19
|
+
return Result.error(error);
|
|
20
20
|
}
|
|
21
|
-
const result = unwrapEither(resultEither);
|
|
22
21
|
Object.assign(props.payload, result);
|
|
23
22
|
}
|
|
24
|
-
return
|
|
23
|
+
return Result.result(props.payload);
|
|
25
24
|
};
|
|
26
25
|
export const useSecurity = (context) => {
|
|
27
26
|
const options = context.description.options ? Object.assign({}, context.description.options) : {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/security",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.96",
|
|
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.96",
|
|
32
|
+
"@aeriajs/common": "^0.0.60",
|
|
33
|
+
"@aeriajs/types": "^0.0.56",
|
|
34
34
|
"mongodb": "^6.5.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|