@aeriajs/security 0.0.85 → 0.0.87
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 +2 -2
- package/dist/immutability.js +3 -3
- package/dist/immutability.mjs +4 -4
- package/dist/ownership.d.ts +2 -2
- package/dist/ownership.js +1 -1
- package/dist/ownership.mjs +2 -2
- package/dist/pagination.d.ts +2 -2
- package/dist/pagination.js +1 -1
- package/dist/pagination.mjs +2 -2
- package/dist/types.d.ts +2 -2
- package/dist/use.d.ts +2 -2
- package/package.json +4 -4
package/dist/immutability.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Context } from '@aeriajs/types';
|
|
2
2
|
import type { SecurityCheckProps, SecurityCheckReadPayload, SecurityCheckWritePayload } from './types.js';
|
|
3
|
-
import {
|
|
4
|
-
export declare const checkImmutability: (props: SecurityCheckProps<SecurityCheckReadPayload | SecurityCheckWritePayload>, context: Context) => Promise<import("@aeriajs/types").Right<SecurityCheckReadPayload | SecurityCheckWritePayload> | import("@aeriajs/types").Left<
|
|
3
|
+
import { ACError } from '@aeriajs/types';
|
|
4
|
+
export declare const checkImmutability: (props: SecurityCheckProps<SecurityCheckReadPayload | SecurityCheckWritePayload>, context: Context) => Promise<import("@aeriajs/types").Right<SecurityCheckReadPayload | SecurityCheckWritePayload> | import("@aeriajs/types").Left<ACError.ImmutabilityParentNotFound> | import("@aeriajs/types").Left<ACError.ImmutabilityIncorrectChild> | import("@aeriajs/types").Left<ACError.ImmutabilityTargetImmutable>>;
|
package/dist/immutability.js
CHANGED
|
@@ -20,12 +20,12 @@ const internalCheckImmutability = async (props, context) => {
|
|
|
20
20
|
_id: new mongodb_1.ObjectId(parentId),
|
|
21
21
|
});
|
|
22
22
|
if (!currentDocument) {
|
|
23
|
-
return (0, common_1.left)(types_1.
|
|
23
|
+
return (0, common_1.left)(types_1.ACError.ImmutabilityParentNotFound);
|
|
24
24
|
}
|
|
25
25
|
if (childId) {
|
|
26
26
|
if ((Array.isArray(currentDocument[propertyName]) && !currentDocument[propertyName].some((child) => child.toString() === childId))
|
|
27
27
|
|| (!Array.isArray(currentDocument[propertyName]) && currentDocument[propertyName] && currentDocument[propertyName] !== childId.toString())) {
|
|
28
|
-
return (0, common_1.left)(types_1.
|
|
28
|
+
return (0, common_1.left)(types_1.ACError.ImmutabilityIncorrectChild);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
const fulfilled = currentDocument[propertyName]
|
|
@@ -33,7 +33,7 @@ const internalCheckImmutability = async (props, context) => {
|
|
|
33
33
|
if (immutable
|
|
34
34
|
&& fulfilled
|
|
35
35
|
&& (property.inline || (currentDocument[propertyName]).toString() !== source[propertyName])) {
|
|
36
|
-
return (0, common_1.left)(types_1.
|
|
36
|
+
return (0, common_1.left)(types_1.ACError.ImmutabilityTargetImmutable);
|
|
37
37
|
}
|
|
38
38
|
return (0, common_1.right)(props.payload);
|
|
39
39
|
};
|
package/dist/immutability.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
2
|
+
import { ACError } from "@aeriajs/types";
|
|
3
3
|
import { ObjectId } from "mongodb";
|
|
4
4
|
import { left, right, isLeft } from "@aeriajs/common";
|
|
5
5
|
const internalCheckImmutability = async (props, context) => {
|
|
@@ -20,16 +20,16 @@ const internalCheckImmutability = async (props, context) => {
|
|
|
20
20
|
_id: new ObjectId(parentId)
|
|
21
21
|
});
|
|
22
22
|
if (!currentDocument) {
|
|
23
|
-
return left(
|
|
23
|
+
return left(ACError.ImmutabilityParentNotFound);
|
|
24
24
|
}
|
|
25
25
|
if (childId) {
|
|
26
26
|
if (Array.isArray(currentDocument[propertyName]) && !currentDocument[propertyName].some((child) => child.toString() === childId) || !Array.isArray(currentDocument[propertyName]) && currentDocument[propertyName] && currentDocument[propertyName] !== childId.toString()) {
|
|
27
|
-
return left(
|
|
27
|
+
return left(ACError.ImmutabilityIncorrectChild);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
const fulfilled = currentDocument[propertyName] && (typeof currentDocument[propertyName] === "object" && !Object.keys(currentDocument[propertyName]).length);
|
|
31
31
|
if (immutable && fulfilled && (property.inline || currentDocument[propertyName].toString() !== source[propertyName])) {
|
|
32
|
-
return left(
|
|
32
|
+
return left(ACError.ImmutabilityTargetImmutable);
|
|
33
33
|
}
|
|
34
34
|
return right(props.payload);
|
|
35
35
|
};
|
package/dist/ownership.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context, InsertPayload } from '@aeriajs/types';
|
|
2
2
|
import type { SecurityCheckProps, SecurityCheckReadPayload } from './types.js';
|
|
3
|
-
import {
|
|
3
|
+
import { ACError } from '@aeriajs/types';
|
|
4
4
|
export declare const checkOwnershipRead: (props: SecurityCheckProps<SecurityCheckReadPayload>, context: Context) => Promise<import("@aeriajs/types").Right<SecurityCheckReadPayload>>;
|
|
5
|
-
export declare const checkOwnershipWrite: (props: SecurityCheckProps<InsertPayload<any>>, context: Context) => Promise<import("@aeriajs/types").Right<InsertPayload<any>> | import("@aeriajs/types").Left<
|
|
5
|
+
export declare const checkOwnershipWrite: (props: SecurityCheckProps<InsertPayload<any>>, context: Context) => Promise<import("@aeriajs/types").Right<InsertPayload<any>> | import("@aeriajs/types").Left<ACError.OwnershipError>>;
|
package/dist/ownership.js
CHANGED
|
@@ -27,7 +27,7 @@ const checkOwnershipWrite = async (props, context) => {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
if ((!payload.what.owner && !parentId) && context.description.owned) {
|
|
30
|
-
return (0, common_1.left)(types_1.
|
|
30
|
+
return (0, common_1.left)(types_1.ACError.OwnershipError);
|
|
31
31
|
}
|
|
32
32
|
return (0, common_1.right)(payload);
|
|
33
33
|
};
|
package/dist/ownership.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
2
|
+
import { ACError } from "@aeriajs/types";
|
|
3
3
|
import { left, right } from "@aeriajs/common";
|
|
4
4
|
export const checkOwnershipRead = async (props, context) => {
|
|
5
5
|
const { token, description } = context;
|
|
@@ -23,7 +23,7 @@ export const checkOwnershipWrite = async (props, context) => {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
if (!payload.what.owner && !parentId && context.description.owned) {
|
|
26
|
-
return left(
|
|
26
|
+
return left(ACError.OwnershipError);
|
|
27
27
|
}
|
|
28
28
|
return right(payload);
|
|
29
29
|
};
|
package/dist/pagination.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { SecurityCheckProps, SecurityCheckReadPayload } from './types.js';
|
|
2
|
-
import {
|
|
3
|
-
export declare const checkPagination: (props: SecurityCheckProps<SecurityCheckReadPayload>) => Promise<import("@aeriajs/types").Right<SecurityCheckReadPayload> | import("@aeriajs/types").Left<
|
|
2
|
+
import { ACError } from '@aeriajs/types';
|
|
3
|
+
export declare const checkPagination: (props: SecurityCheckProps<SecurityCheckReadPayload>) => Promise<import("@aeriajs/types").Right<SecurityCheckReadPayload> | import("@aeriajs/types").Left<ACError.InvalidLimit>>;
|
package/dist/pagination.js
CHANGED
|
@@ -7,7 +7,7 @@ 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 (0, common_1.left)(types_1.
|
|
10
|
+
return (0, common_1.left)(types_1.ACError.InvalidLimit);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
return (0, common_1.right)(payload);
|
package/dist/pagination.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
2
|
+
import { ACError } from "@aeriajs/types";
|
|
3
3
|
import { left, right } 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 left(
|
|
8
|
+
return left(ACError.InvalidLimit);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
return right(payload);
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context, Either, GetAllPayload, InsertPayload,
|
|
1
|
+
import type { Context, Either, GetAllPayload, InsertPayload, ACError } from '@aeriajs/types';
|
|
2
2
|
export type SecurityCheckReadPayload = {
|
|
3
3
|
filters: Record<string, any>;
|
|
4
4
|
sort?: Record<string, any>;
|
|
@@ -14,4 +14,4 @@ export type SecurityCheckProps<TPayload extends Record<string, any> = any> = {
|
|
|
14
14
|
childId?: string;
|
|
15
15
|
payload: TPayload;
|
|
16
16
|
};
|
|
17
|
-
export type SecurityCheck = (props: SecurityCheckProps, context: Context) => Promise<Either<
|
|
17
|
+
export type SecurityCheck = (props: SecurityCheckProps, context: Context) => Promise<Either<ACError, GetAllPayload<any> | InsertPayload<any>>>;
|
package/dist/use.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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<import("@aeriajs/types").Left<import("@aeriajs/types").
|
|
4
|
-
beforeWrite: <TPayload_1 extends Partial<InsertPayload<any>>>(payload?: TPayload_1 | undefined) => Promise<import("@aeriajs/types").Left<import("@aeriajs/types").
|
|
3
|
+
beforeRead: <TPayload extends Partial<GetAllPayload<any>>>(payload?: TPayload) => Promise<import("@aeriajs/types").Left<import("@aeriajs/types").ACError> | import("@aeriajs/types").Right<any>>;
|
|
4
|
+
beforeWrite: <TPayload_1 extends Partial<InsertPayload<any>>>(payload?: TPayload_1 | undefined) => Promise<import("@aeriajs/types").Left<import("@aeriajs/types").ACError> | import("@aeriajs/types").Right<any>>;
|
|
5
5
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/security",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.87",
|
|
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.87",
|
|
32
|
+
"@aeriajs/common": "^0.0.53",
|
|
33
|
+
"@aeriajs/types": "^0.0.50",
|
|
34
34
|
"mongodb": "^6.5.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|