@aeriajs/security 0.0.136 → 0.0.137
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 +17 -4
- package/dist/immutability.js +10 -6
- package/dist/immutability.mjs +7 -2
- package/dist/ownership.d.ts +6 -6
- package/dist/pagination.d.ts +7 -6
- package/dist/types.d.ts +2 -10
- package/dist/use.d.ts +10 -5
- package/dist/use.js +5 -6
- package/dist/use.mjs +6 -7
- package/package.json +4 -4
package/dist/immutability.d.ts
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
import type { Context } from '@aeriajs/types';
|
|
2
|
-
import type {
|
|
1
|
+
import type { Context, CollectionHookProps } from '@aeriajs/types';
|
|
2
|
+
import type { CollectionHookReadPayload, CollectionHookWritePayload } from './types.js';
|
|
3
3
|
import { ACError } from '@aeriajs/types';
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const checkImmutabilityRead: (props: CollectionHookProps<CollectionHookReadPayload>, context: Context) => Promise<{
|
|
5
5
|
readonly _tag: "Result";
|
|
6
6
|
readonly error: undefined;
|
|
7
|
-
readonly result:
|
|
7
|
+
readonly result: any;
|
|
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
|
+
}>;
|
|
17
|
+
export declare const checkImmutabilityWrite: (props: CollectionHookProps<CollectionHookWritePayload>, context: Context) => Promise<{
|
|
18
|
+
readonly _tag: "Result";
|
|
19
|
+
readonly error: undefined;
|
|
20
|
+
readonly result: any;
|
|
8
21
|
} | {
|
|
9
22
|
readonly _tag: "Error";
|
|
10
23
|
readonly error: ACError.ResourceNotFound;
|
package/dist/immutability.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.checkImmutabilityWrite = exports.checkImmutabilityRead = void 0;
|
|
4
4
|
const types_1 = require("@aeriajs/types");
|
|
5
|
-
const checkImmutability = async (props, context) => {
|
|
5
|
+
const checkImmutability = async (docId, props, context) => {
|
|
6
6
|
if (!context.description.immutable) {
|
|
7
7
|
return types_1.Result.result(props.payload);
|
|
8
8
|
}
|
|
9
|
-
const docId = 'filters' in props.payload
|
|
10
|
-
? props.payload.filters._id
|
|
11
|
-
: props.payload.what._id;
|
|
12
9
|
if (docId) {
|
|
13
10
|
if (typeof context.description.immutable === 'function') {
|
|
14
11
|
const doc = await context.collection.model.findOne({
|
|
@@ -26,4 +23,11 @@ const checkImmutability = async (props, context) => {
|
|
|
26
23
|
}
|
|
27
24
|
return types_1.Result.result(props.payload);
|
|
28
25
|
};
|
|
29
|
-
|
|
26
|
+
const checkImmutabilityRead = async (props, context) => {
|
|
27
|
+
return checkImmutability(props.payload.filters._id, props, context);
|
|
28
|
+
};
|
|
29
|
+
exports.checkImmutabilityRead = checkImmutabilityRead;
|
|
30
|
+
const checkImmutabilityWrite = async (props, context) => {
|
|
31
|
+
return checkImmutability(props.payload.what._id, props, context);
|
|
32
|
+
};
|
|
33
|
+
exports.checkImmutabilityWrite = checkImmutabilityWrite;
|
package/dist/immutability.mjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { Result, ACError } from "@aeriajs/types";
|
|
3
|
-
|
|
3
|
+
const checkImmutability = async (docId, props, context) => {
|
|
4
4
|
if (!context.description.immutable) {
|
|
5
5
|
return Result.result(props.payload);
|
|
6
6
|
}
|
|
7
|
-
const docId = "filters" in props.payload ? props.payload.filters._id : props.payload.what._id;
|
|
8
7
|
if (docId) {
|
|
9
8
|
if (typeof context.description.immutable === "function") {
|
|
10
9
|
const doc = await context.collection.model.findOne({
|
|
@@ -20,3 +19,9 @@ export const checkImmutability = async (props, context) => {
|
|
|
20
19
|
}
|
|
21
20
|
return Result.result(props.payload);
|
|
22
21
|
};
|
|
22
|
+
export const checkImmutabilityRead = async (props, context) => {
|
|
23
|
+
return checkImmutability(props.payload.filters._id, props, context);
|
|
24
|
+
};
|
|
25
|
+
export const checkImmutabilityWrite = async (props, context) => {
|
|
26
|
+
return checkImmutability(props.payload.what._id, props, context);
|
|
27
|
+
};
|
package/dist/ownership.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { Context,
|
|
2
|
-
import type {
|
|
1
|
+
import type { Context, CollectionHookProps } from '@aeriajs/types';
|
|
2
|
+
import type { CollectionHookReadPayload, CollectionHookWritePayload } from './types.js';
|
|
3
3
|
import { ACError } from '@aeriajs/types';
|
|
4
|
-
export declare const checkOwnershipRead: (props:
|
|
4
|
+
export declare const checkOwnershipRead: <T extends CollectionHookReadPayload>(props: CollectionHookProps<T>, context: Context) => Promise<{
|
|
5
5
|
readonly _tag: "Result";
|
|
6
6
|
readonly error: undefined;
|
|
7
|
-
readonly result:
|
|
7
|
+
readonly result: {} & T;
|
|
8
8
|
}>;
|
|
9
|
-
export declare const checkOwnershipWrite: (props:
|
|
9
|
+
export declare const checkOwnershipWrite: <T extends CollectionHookWritePayload>(props: CollectionHookProps<T>, context: Context) => Promise<{
|
|
10
10
|
readonly _tag: "Result";
|
|
11
11
|
readonly error: undefined;
|
|
12
|
-
readonly result:
|
|
12
|
+
readonly result: {} & T;
|
|
13
13
|
} | {
|
|
14
14
|
readonly _tag: "Error";
|
|
15
15
|
readonly error: ACError.OwnershipError;
|
package/dist/pagination.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CollectionHookProps } from '@aeriajs/types';
|
|
2
|
+
import type { CollectionHookReadPayload } from './types.js';
|
|
2
3
|
import { ACError } from '@aeriajs/types';
|
|
3
|
-
export declare const checkPagination: (props:
|
|
4
|
-
readonly _tag: "Result";
|
|
5
|
-
readonly error: undefined;
|
|
6
|
-
readonly result: SecurityCheckReadPayload;
|
|
7
|
-
} | {
|
|
4
|
+
export declare const checkPagination: <T extends CollectionHookReadPayload>(props: CollectionHookProps<T>) => Promise<{
|
|
8
5
|
readonly _tag: "Error";
|
|
9
6
|
readonly error: ACError.InvalidLimit;
|
|
10
7
|
readonly result: undefined;
|
|
8
|
+
} | {
|
|
9
|
+
readonly _tag: "Result";
|
|
10
|
+
readonly error: undefined;
|
|
11
|
+
readonly result: T;
|
|
11
12
|
}>;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export type SecurityCheckReadPayload = {
|
|
1
|
+
export type CollectionHookReadPayload = {
|
|
3
2
|
filters: Record<string, any>;
|
|
4
3
|
sort?: Record<string, any>;
|
|
5
4
|
limit?: number;
|
|
6
5
|
offset?: number;
|
|
7
6
|
};
|
|
8
|
-
export type
|
|
7
|
+
export type CollectionHookWritePayload = {
|
|
9
8
|
what: Record<string, any>;
|
|
10
9
|
};
|
|
11
|
-
export type SecurityCheckProps<TPayload extends Record<string, any> = any> = {
|
|
12
|
-
propertyName?: string;
|
|
13
|
-
parentId?: string;
|
|
14
|
-
childId?: string;
|
|
15
|
-
payload: TPayload;
|
|
16
|
-
};
|
|
17
|
-
export type SecurityCheck = (props: SecurityCheckProps, context: Context) => Promise<Result.Either<ACError, GetAllPayload<any> | InsertPayload<any>>>;
|
package/dist/use.d.ts
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
import type { Context, Description
|
|
1
|
+
import type { Context, Description } from '@aeriajs/types';
|
|
2
|
+
import type { CollectionHookReadPayload, CollectionHookWritePayload } from './types.js';
|
|
2
3
|
export declare const useSecurity: <TDescription extends Description>(context: Context<TDescription>) => {
|
|
3
|
-
beforeRead: <TPayload extends Partial<
|
|
4
|
+
beforeRead: <TPayload extends Partial<CollectionHookReadPayload>>(payload?: TPayload) => Promise<{
|
|
4
5
|
readonly _tag: "Error";
|
|
5
6
|
readonly error: import("@aeriajs/types").ACError;
|
|
6
7
|
readonly result: undefined;
|
|
7
8
|
} | {
|
|
8
9
|
readonly _tag: "Result";
|
|
9
10
|
readonly error: undefined;
|
|
10
|
-
readonly result:
|
|
11
|
+
readonly result: {
|
|
12
|
+
filters: {};
|
|
13
|
+
} & TPayload;
|
|
11
14
|
}>;
|
|
12
|
-
beforeWrite: <TPayload extends
|
|
15
|
+
beforeWrite: <TPayload extends CollectionHookWritePayload>(payload?: TPayload) => Promise<{
|
|
13
16
|
readonly _tag: "Error";
|
|
14
17
|
readonly error: import("@aeriajs/types").ACError;
|
|
15
18
|
readonly result: undefined;
|
|
16
19
|
} | {
|
|
17
20
|
readonly _tag: "Result";
|
|
18
21
|
readonly error: undefined;
|
|
19
|
-
readonly result:
|
|
22
|
+
readonly result: {
|
|
23
|
+
what: {};
|
|
24
|
+
} & TPayload;
|
|
20
25
|
}>;
|
|
21
26
|
};
|
package/dist/use.js
CHANGED
|
@@ -4,9 +4,7 @@ exports.useSecurity = void 0;
|
|
|
4
4
|
const types_1 = require("@aeriajs/types");
|
|
5
5
|
const index_js_1 = require("./index.js");
|
|
6
6
|
const chainFunctions = async (_props, context, functions) => {
|
|
7
|
-
const props = Object.assign({
|
|
8
|
-
filters: {},
|
|
9
|
-
}, _props);
|
|
7
|
+
const props = Object.assign({}, _props);
|
|
10
8
|
for (const fn of functions) {
|
|
11
9
|
if (!fn) {
|
|
12
10
|
continue;
|
|
@@ -21,8 +19,9 @@ const chainFunctions = async (_props, context, functions) => {
|
|
|
21
19
|
};
|
|
22
20
|
const useSecurity = (context) => {
|
|
23
21
|
const beforeRead = async (payload) => {
|
|
24
|
-
const newPayload = Object.assign({
|
|
25
|
-
|
|
22
|
+
const newPayload = Object.assign({
|
|
23
|
+
filters: {},
|
|
24
|
+
}, payload);
|
|
26
25
|
const props = {
|
|
27
26
|
payload: newPayload,
|
|
28
27
|
};
|
|
@@ -42,7 +41,7 @@ const useSecurity = (context) => {
|
|
|
42
41
|
};
|
|
43
42
|
return chainFunctions(props, context, [
|
|
44
43
|
index_js_1.checkOwnershipWrite,
|
|
45
|
-
index_js_1.
|
|
44
|
+
index_js_1.checkImmutabilityWrite,
|
|
46
45
|
]);
|
|
47
46
|
};
|
|
48
47
|
return {
|
package/dist/use.mjs
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { Result } from "@aeriajs/types";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
checkImmutabilityWrite,
|
|
5
5
|
checkOwnershipRead,
|
|
6
6
|
checkOwnershipWrite,
|
|
7
7
|
checkPagination
|
|
8
8
|
} from "./index.mjs";
|
|
9
9
|
const chainFunctions = async (_props, context, functions) => {
|
|
10
|
-
const props = Object.assign({
|
|
11
|
-
filters: {}
|
|
12
|
-
}, _props);
|
|
10
|
+
const props = Object.assign({}, _props);
|
|
13
11
|
for (const fn of functions) {
|
|
14
12
|
if (!fn) {
|
|
15
13
|
continue;
|
|
@@ -24,8 +22,9 @@ const chainFunctions = async (_props, context, functions) => {
|
|
|
24
22
|
};
|
|
25
23
|
export const useSecurity = (context) => {
|
|
26
24
|
const beforeRead = async (payload) => {
|
|
27
|
-
const newPayload = Object.assign({
|
|
28
|
-
|
|
25
|
+
const newPayload = Object.assign({
|
|
26
|
+
filters: {}
|
|
27
|
+
}, payload);
|
|
29
28
|
const props = {
|
|
30
29
|
payload: newPayload
|
|
31
30
|
};
|
|
@@ -43,7 +42,7 @@ export const useSecurity = (context) => {
|
|
|
43
42
|
};
|
|
44
43
|
return chainFunctions(props, context, [
|
|
45
44
|
checkOwnershipWrite,
|
|
46
|
-
|
|
45
|
+
checkImmutabilityWrite
|
|
47
46
|
]);
|
|
48
47
|
};
|
|
49
48
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/security",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.137",
|
|
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.137",
|
|
32
|
+
"@aeriajs/common": "^0.0.86",
|
|
33
|
+
"@aeriajs/types": "^0.0.74",
|
|
34
34
|
"mongodb": "^6.5.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|