@aeriajs/security 0.0.136 → 0.0.138

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/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from './define.js';
2
- export * from './immutability.js';
3
- export * from './ownership.js';
4
- export * from './pagination.js';
2
+ export * from './middleware.js';
3
+ export * from './middlewares/index.js';
5
4
  export * from './rateLimiting.js';
6
5
  export * from './use.js';
package/dist/index.js CHANGED
@@ -15,8 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./define.js"), exports);
18
- __exportStar(require("./immutability.js"), exports);
19
- __exportStar(require("./ownership.js"), exports);
20
- __exportStar(require("./pagination.js"), exports);
18
+ __exportStar(require("./middleware.js"), exports);
19
+ __exportStar(require("./middlewares/index.js"), exports);
21
20
  __exportStar(require("./rateLimiting.js"), exports);
22
21
  __exportStar(require("./use.js"), exports);
package/dist/index.mjs CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  export * from "./define.mjs";
3
- export * from "./immutability.mjs";
4
- export * from "./ownership.mjs";
5
- export * from "./pagination.mjs";
3
+ export * from "./middleware.mjs";
4
+ export * from "./middlewares/index.mjs";
6
5
  export * from "./rateLimiting.mjs";
7
6
  export * from "./use.mjs";
@@ -0,0 +1,2 @@
1
+ import type { Middleware, MiddlewareNext, GenericMiddlewareNext, Context } from '@aeriajs/types';
2
+ export declare const iterableMiddlewares: <TReturn, TPayload, TReturnNext extends GenericMiddlewareNext<TReturn, TPayload> = MiddlewareNext>(middlewares: Middleware<TReturn, TPayload, TReturnNext>[], end?: (_: unknown, initial: TReturn) => TReturn) => (payload: TPayload, initial: TReturn, context: Context) => TReturn | Promise<TReturn>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.iterableMiddlewares = void 0;
4
+ const iterableMiddlewares = function (middlewares, end = (_, initial) => initial) {
5
+ const [first, ...subsequent] = middlewares;
6
+ const it = function* () {
7
+ for (const middleware of subsequent.concat([end])) {
8
+ yield (payload, initial, context) => {
9
+ const { value: next } = it.next();
10
+ return middleware(payload, initial, context, next);
11
+ };
12
+ }
13
+ }();
14
+ return (payload, initial, context) => {
15
+ const { value: next } = it.next();
16
+ return first(payload, initial, context, next);
17
+ };
18
+ };
19
+ exports.iterableMiddlewares = iterableMiddlewares;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ export const iterableMiddlewares = function(middlewares, end = (_, initial) => initial) {
3
+ const [first, ...subsequent] = middlewares;
4
+ const it = function* () {
5
+ for (const middleware of subsequent.concat([end])) {
6
+ yield (payload, initial, context) => {
7
+ const { value: next } = it.next();
8
+ return middleware(payload, initial, context, next);
9
+ };
10
+ }
11
+ }();
12
+ return (payload, initial, context) => {
13
+ const { value: next } = it.next();
14
+ return first(payload, initial, context, next);
15
+ };
16
+ };
@@ -0,0 +1,13 @@
1
+ import type { Context, CollectionHookProps, GenericMiddlewareNext } from '@aeriajs/types';
2
+ import type { CollectionHookReadPayload, CollectionHookWritePayload } from '../types.js';
3
+ import { Result, ACError } from '@aeriajs/types';
4
+ export declare const checkImmutabilityRead: <T extends CollectionHookReadPayload>(props: CollectionHookProps<T>, initial: Result.Either<unknown, T>, context: Context, next: GenericMiddlewareNext<Result.Result<T>, CollectionHookProps<T>>) => Promise<Result.Result<T> | {
5
+ readonly _tag: "Error";
6
+ readonly error: ACError.TargetImmutable | ACError.ResourceNotFound;
7
+ readonly result: undefined;
8
+ }>;
9
+ export declare const checkImmutabilityWrite: <T extends CollectionHookWritePayload>(props: CollectionHookProps<T>, initial: Result.Either<unknown, T>, context: Context, next: GenericMiddlewareNext<Result.Result<T>, CollectionHookProps<T>>) => Promise<Result.Result<T> | {
10
+ readonly _tag: "Error";
11
+ readonly error: ACError.TargetImmutable | ACError.ResourceNotFound;
12
+ readonly result: undefined;
13
+ }>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkImmutabilityWrite = exports.checkImmutabilityRead = void 0;
4
+ const types_1 = require("@aeriajs/types");
5
+ const common_1 = require("@aeriajs/common");
6
+ const checkImmutability = async (docId, props, context) => {
7
+ if (!context.description.immutable) {
8
+ return types_1.Result.result(props.payload);
9
+ }
10
+ if (docId) {
11
+ if (typeof context.description.immutable === 'function') {
12
+ const doc = await context.collection.model.findOne({
13
+ _id: docId,
14
+ });
15
+ if (!doc) {
16
+ return types_1.Result.error(types_1.ACError.ResourceNotFound);
17
+ }
18
+ const isImmutable = await context.description.immutable(doc);
19
+ return isImmutable
20
+ ? types_1.Result.error(types_1.ACError.TargetImmutable)
21
+ : types_1.Result.result(props.payload);
22
+ }
23
+ return types_1.Result.error(types_1.ACError.TargetImmutable);
24
+ }
25
+ return types_1.Result.result(props.payload);
26
+ };
27
+ const checkImmutabilityRead = async (props, initial, context, next) => {
28
+ const originalPayload = (0, common_1.throwIfError)(initial);
29
+ const { result: payload, error } = await checkImmutability(originalPayload.filters._id, props, context);
30
+ if (error) {
31
+ return types_1.Result.error(error);
32
+ }
33
+ return next(payload, types_1.Result.result(payload), context);
34
+ };
35
+ exports.checkImmutabilityRead = checkImmutabilityRead;
36
+ const checkImmutabilityWrite = async (props, initial, context, next) => {
37
+ const originalPayload = (0, common_1.throwIfError)(initial);
38
+ const { result: payload, error } = await checkImmutability(originalPayload.what._id, props, context);
39
+ if (error) {
40
+ return types_1.Result.error(error);
41
+ }
42
+ return next(payload, types_1.Result.result(payload), context);
43
+ };
44
+ exports.checkImmutabilityWrite = checkImmutabilityWrite;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ import { Result, ACError } from "@aeriajs/types";
3
+ import { throwIfError } from "@aeriajs/common";
4
+ const checkImmutability = async (docId, props, context) => {
5
+ if (!context.description.immutable) {
6
+ return Result.result(props.payload);
7
+ }
8
+ if (docId) {
9
+ if (typeof context.description.immutable === "function") {
10
+ const doc = await context.collection.model.findOne({
11
+ _id: docId
12
+ });
13
+ if (!doc) {
14
+ return Result.error(ACError.ResourceNotFound);
15
+ }
16
+ const isImmutable = await context.description.immutable(doc);
17
+ return isImmutable ? Result.error(ACError.TargetImmutable) : Result.result(props.payload);
18
+ }
19
+ return Result.error(ACError.TargetImmutable);
20
+ }
21
+ return Result.result(props.payload);
22
+ };
23
+ export const checkImmutabilityRead = async (props, initial, context, next) => {
24
+ const originalPayload = throwIfError(initial);
25
+ const { result: payload, error } = await checkImmutability(originalPayload.filters._id, props, context);
26
+ if (error) {
27
+ return Result.error(error);
28
+ }
29
+ return next(payload, Result.result(payload), context);
30
+ };
31
+ export const checkImmutabilityWrite = async (props, initial, context, next) => {
32
+ const originalPayload = throwIfError(initial);
33
+ const { result: payload, error } = await checkImmutability(originalPayload.what._id, props, context);
34
+ if (error) {
35
+ return Result.error(error);
36
+ }
37
+ return next(payload, Result.result(payload), context);
38
+ };
@@ -0,0 +1,3 @@
1
+ export * from './immutability.js';
2
+ export * from './ownership.js';
3
+ export * from './pagination.js';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./immutability.js"), exports);
18
+ __exportStar(require("./ownership.js"), exports);
19
+ __exportStar(require("./pagination.js"), exports);
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ export * from "./immutability.mjs";
3
+ export * from "./ownership.mjs";
4
+ export * from "./pagination.mjs";
@@ -0,0 +1,9 @@
1
+ import type { GenericMiddlewareNext, Context, CollectionHookProps } from '@aeriajs/types';
2
+ import type { CollectionHookReadPayload, CollectionHookWritePayload } from '../types.js';
3
+ import { Result, ACError } from '@aeriajs/types';
4
+ export declare const checkOwnershipRead: <T extends CollectionHookReadPayload>(props: CollectionHookProps<T>, initial: Result.Either<unknown, T>, context: Context, next: GenericMiddlewareNext<Result.Result<T>, CollectionHookProps<T>>) => Promise<Result.Result<T>>;
5
+ export declare const checkOwnershipWrite: <T extends CollectionHookWritePayload>(props: CollectionHookProps<T>, initial: Result.Either<unknown, T>, context: Context, next: GenericMiddlewareNext<Result.Result<T>, CollectionHookProps<T>>) => Promise<Result.Result<T> | {
6
+ readonly _tag: "Error";
7
+ readonly error: ACError.OwnershipError;
8
+ readonly result: undefined;
9
+ }>;
@@ -2,32 +2,33 @@
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 checkOwnershipRead = async (props, context) => {
5
+ const common_1 = require("@aeriajs/common");
6
+ const checkOwnershipRead = async (props, initial, context, next) => {
6
7
  const { token, description } = context;
7
- const payload = Object.assign({}, props.payload);
8
+ const payload = (0, common_1.throwIfError)(initial);
8
9
  if (token.authenticated && description.owned) {
9
10
  if (!token.roles.includes('root')) {
10
11
  payload.filters.owner = token.sub;
11
12
  }
12
13
  }
13
- return types_1.Result.result(payload);
14
+ return next(props, types_1.Result.result(payload), context);
14
15
  };
15
16
  exports.checkOwnershipRead = checkOwnershipRead;
16
- const checkOwnershipWrite = async (props, context) => {
17
+ const checkOwnershipWrite = async (props, initial, context, next) => {
17
18
  const { token, description } = context;
18
19
  const { parentId } = props;
19
- const payload = Object.assign({}, props.payload);
20
+ const payload = (0, common_1.throwIfError)(initial);
20
21
  if (token.authenticated && description.owned) {
21
22
  if (!payload.what._id || description.owned === 'always') {
22
23
  payload.what.owner = token.sub;
23
24
  }
24
25
  else {
25
- return types_1.Result.result(payload);
26
+ return next(props, types_1.Result.result(payload), context);
26
27
  }
27
28
  }
28
29
  if ((!payload.what.owner && !parentId) && context.description.owned) {
29
30
  return types_1.Result.error(types_1.ACError.OwnershipError);
30
31
  }
31
- return types_1.Result.result(payload);
32
+ return next(props, types_1.Result.result(payload), context);
32
33
  };
33
34
  exports.checkOwnershipWrite = checkOwnershipWrite;
@@ -1,28 +1,29 @@
1
1
  "use strict";
2
2
  import { Result, ACError } from "@aeriajs/types";
3
- export const checkOwnershipRead = async (props, context) => {
3
+ import { throwIfError } from "@aeriajs/common";
4
+ export const checkOwnershipRead = async (props, initial, context, next) => {
4
5
  const { token, description } = context;
5
- const payload = Object.assign({}, props.payload);
6
+ const payload = throwIfError(initial);
6
7
  if (token.authenticated && description.owned) {
7
8
  if (!token.roles.includes("root")) {
8
9
  payload.filters.owner = token.sub;
9
10
  }
10
11
  }
11
- return Result.result(payload);
12
+ return next(props, Result.result(payload), context);
12
13
  };
13
- export const checkOwnershipWrite = async (props, context) => {
14
+ export const checkOwnershipWrite = async (props, initial, context, next) => {
14
15
  const { token, description } = context;
15
16
  const { parentId } = props;
16
- const payload = Object.assign({}, props.payload);
17
+ const payload = throwIfError(initial);
17
18
  if (token.authenticated && description.owned) {
18
19
  if (!payload.what._id || description.owned === "always") {
19
20
  payload.what.owner = token.sub;
20
21
  } else {
21
- return Result.result(payload);
22
+ return next(props, Result.result(payload), context);
22
23
  }
23
24
  }
24
25
  if (!payload.what.owner && !parentId && context.description.owned) {
25
26
  return Result.error(ACError.OwnershipError);
26
27
  }
27
- return Result.result(payload);
28
+ return next(props, Result.result(payload), context);
28
29
  };
@@ -0,0 +1,8 @@
1
+ import type { CollectionHookProps, GenericMiddlewareNext, Context } from '@aeriajs/types';
2
+ import type { CollectionHookReadPayload } from '../types.js';
3
+ import { Result, ACError } from '@aeriajs/types';
4
+ export declare const checkPagination: <T extends CollectionHookReadPayload>(props: CollectionHookProps<T>, initial: Result.Either<unknown, T>, context: Context, next: GenericMiddlewareNext<Result.Result<T>, CollectionHookProps<T>>) => Promise<Result.Result<T> | {
5
+ readonly _tag: "Error";
6
+ readonly error: ACError.InvalidLimit;
7
+ readonly result: undefined;
8
+ }>;
@@ -2,13 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkPagination = void 0;
4
4
  const types_1 = require("@aeriajs/types");
5
- const checkPagination = async (props) => {
6
- const { payload } = props;
5
+ const common_1 = require("@aeriajs/common");
6
+ const checkPagination = async (props, initial, context, next) => {
7
+ const payload = (0, common_1.throwIfError)(initial);
7
8
  if (payload.limit) {
8
9
  if (payload.limit <= 0 || payload.limit > 150) {
9
10
  return types_1.Result.error(types_1.ACError.InvalidLimit);
10
11
  }
11
12
  }
12
- return types_1.Result.result(payload);
13
+ return next(props, types_1.Result.result(payload), context);
13
14
  };
14
15
  exports.checkPagination = checkPagination;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ import { Result, ACError } from "@aeriajs/types";
3
+ import { throwIfError } from "@aeriajs/common";
4
+ export const checkPagination = async (props, initial, context, next) => {
5
+ const payload = throwIfError(initial);
6
+ if (payload.limit) {
7
+ if (payload.limit <= 0 || payload.limit > 150) {
8
+ return Result.error(ACError.InvalidLimit);
9
+ }
10
+ }
11
+ return next(props, Result.result(payload), context);
12
+ };
package/dist/types.d.ts CHANGED
@@ -1,17 +1,9 @@
1
- import type { Result, Context, GetAllPayload, InsertPayload, ACError } from '@aeriajs/types';
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 SecurityCheckWritePayload = {
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,7 @@
1
- import type { Context, Description, GetAllPayload, InsertPayload } from '@aeriajs/types';
1
+ import type { Context, Description, ACError } from '@aeriajs/types';
2
+ import type { CollectionHookReadPayload, CollectionHookWritePayload } from './types.js';
3
+ import { Result } from '@aeriajs/types';
2
4
  export declare const useSecurity: <TDescription extends Description>(context: Context<TDescription>) => {
3
- beforeRead: <TPayload extends Partial<GetAllPayload<any>>>(payload?: TPayload) => Promise<{
4
- readonly _tag: "Error";
5
- readonly error: import("@aeriajs/types").ACError;
6
- readonly result: undefined;
7
- } | {
8
- readonly _tag: "Result";
9
- readonly error: undefined;
10
- readonly result: any;
11
- }>;
12
- beforeWrite: <TPayload extends Partial<InsertPayload<any>>>(payload?: TPayload) => Promise<{
13
- readonly _tag: "Error";
14
- readonly error: import("@aeriajs/types").ACError;
15
- readonly result: undefined;
16
- } | {
17
- readonly _tag: "Result";
18
- readonly error: undefined;
19
- readonly result: any;
20
- }>;
5
+ secureReadPayload: <TPayload extends Partial<CollectionHookReadPayload>>(payload?: TPayload) => Promise<Result.Either<ACError.InvalidLimit, TPayload & CollectionHookReadPayload>>;
6
+ secureWritePayload: <TPayload extends CollectionHookWritePayload>(payload?: TPayload) => Promise<Result.Either<ACError, TPayload>>;
21
7
  };
package/dist/use.js CHANGED
@@ -2,52 +2,39 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useSecurity = void 0;
4
4
  const types_1 = require("@aeriajs/types");
5
- const index_js_1 = require("./index.js");
6
- const chainFunctions = async (_props, context, functions) => {
7
- const props = Object.assign({
8
- filters: {},
9
- }, _props);
10
- for (const fn of functions) {
11
- if (!fn) {
12
- continue;
13
- }
14
- const { error, result } = await fn(props, context);
15
- if (error) {
16
- return types_1.Result.error(error);
17
- }
18
- Object.assign(props.payload, result);
19
- }
20
- return types_1.Result.result(props.payload);
21
- };
5
+ const middleware_js_1 = require("./middleware.js");
6
+ const index_js_1 = require("./middlewares/index.js");
22
7
  const useSecurity = (context) => {
23
- const beforeRead = async (payload) => {
24
- const newPayload = Object.assign({}, payload);
25
- newPayload.filters ??= {};
8
+ const secureReadPayload = async (payload) => {
9
+ const newPayload = Object.assign({
10
+ filters: {},
11
+ }, payload);
26
12
  const props = {
27
13
  payload: newPayload,
28
14
  };
29
- return chainFunctions(props, context, [
30
- index_js_1.checkPagination,
31
- context.description.owned === 'on-write'
32
- ? null
33
- : index_js_1.checkOwnershipRead,
34
- ]);
15
+ const middlewares = [index_js_1.checkPagination];
16
+ if (context.description.owned !== 'on-write') {
17
+ middlewares.push(index_js_1.checkOwnershipRead);
18
+ }
19
+ const start = (0, middleware_js_1.iterableMiddlewares)(middlewares);
20
+ return start(props, types_1.Result.result(newPayload), context);
35
21
  };
36
- const beforeWrite = async (payload) => {
22
+ const secureWritePayload = async (payload) => {
37
23
  const newPayload = Object.assign({
38
24
  what: {},
39
25
  }, payload);
40
26
  const props = {
41
27
  payload: newPayload,
42
28
  };
43
- return chainFunctions(props, context, [
29
+ const start = (0, middleware_js_1.iterableMiddlewares)([
44
30
  index_js_1.checkOwnershipWrite,
45
- index_js_1.checkImmutability,
31
+ index_js_1.checkImmutabilityWrite,
46
32
  ]);
33
+ return start(props, types_1.Result.result(newPayload), context);
47
34
  };
48
35
  return {
49
- beforeRead,
50
- beforeWrite,
36
+ secureReadPayload,
37
+ secureWritePayload,
51
38
  };
52
39
  };
53
40
  exports.useSecurity = useSecurity;
package/dist/use.mjs CHANGED
@@ -1,53 +1,42 @@
1
1
  "use strict";
2
2
  import { Result } from "@aeriajs/types";
3
+ import { iterableMiddlewares } from "./middleware.mjs";
3
4
  import {
4
- checkImmutability,
5
+ checkImmutabilityWrite,
5
6
  checkOwnershipRead,
6
7
  checkOwnershipWrite,
7
8
  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
- if (!fn) {
15
- continue;
16
- }
17
- const { error, result } = await fn(props, context);
18
- if (error) {
19
- return Result.error(error);
20
- }
21
- Object.assign(props.payload, result);
22
- }
23
- return Result.result(props.payload);
24
- };
9
+ } from "./middlewares/index.mjs";
25
10
  export const useSecurity = (context) => {
26
- const beforeRead = async (payload) => {
27
- const newPayload = Object.assign({}, payload);
28
- newPayload.filters ??= {};
11
+ const secureReadPayload = async (payload) => {
12
+ const newPayload = Object.assign({
13
+ filters: {}
14
+ }, payload);
29
15
  const props = {
30
16
  payload: newPayload
31
17
  };
32
- return chainFunctions(props, context, [
33
- checkPagination,
34
- context.description.owned === "on-write" ? null : checkOwnershipRead
35
- ]);
18
+ const middlewares = [checkPagination];
19
+ if (context.description.owned !== "on-write") {
20
+ middlewares.push(checkOwnershipRead);
21
+ }
22
+ const start = iterableMiddlewares(middlewares);
23
+ return start(props, Result.result(newPayload), context);
36
24
  };
37
- const beforeWrite = async (payload) => {
25
+ const secureWritePayload = async (payload) => {
38
26
  const newPayload = Object.assign({
39
27
  what: {}
40
28
  }, payload);
41
29
  const props = {
42
30
  payload: newPayload
43
31
  };
44
- return chainFunctions(props, context, [
32
+ const start = iterableMiddlewares([
45
33
  checkOwnershipWrite,
46
- checkImmutability
34
+ checkImmutabilityWrite
47
35
  ]);
36
+ return start(props, Result.result(newPayload), context);
48
37
  };
49
38
  return {
50
- beforeRead,
51
- beforeWrite
39
+ secureReadPayload,
40
+ secureWritePayload
52
41
  };
53
42
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/security",
3
- "version": "0.0.136",
3
+ "version": "0.0.138",
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.136",
32
- "@aeriajs/common": "^0.0.85",
33
- "@aeriajs/types": "^0.0.73",
31
+ "@aeriajs/core": "^0.0.138",
32
+ "@aeriajs/common": "^0.0.87",
33
+ "@aeriajs/types": "^0.0.75",
34
34
  "mongodb": "^6.5.0"
35
35
  },
36
36
  "scripts": {
@@ -1,16 +0,0 @@
1
- import type { Context } from '@aeriajs/types';
2
- import type { SecurityCheckProps, SecurityCheckReadPayload, SecurityCheckWritePayload } from './types.js';
3
- import { ACError } from '@aeriajs/types';
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
- }>;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkImmutability = void 0;
4
- const types_1 = require("@aeriajs/types");
5
- const checkImmutability = async (props, context) => {
6
- if (!context.description.immutable) {
7
- return types_1.Result.result(props.payload);
8
- }
9
- const docId = 'filters' in props.payload
10
- ? props.payload.filters._id
11
- : props.payload.what._id;
12
- if (docId) {
13
- if (typeof context.description.immutable === 'function') {
14
- const doc = await context.collection.model.findOne({
15
- _id: docId,
16
- });
17
- if (!doc) {
18
- return types_1.Result.error(types_1.ACError.ResourceNotFound);
19
- }
20
- const isImmutable = await context.description.immutable(doc);
21
- return isImmutable
22
- ? types_1.Result.error(types_1.ACError.TargetImmutable)
23
- : types_1.Result.result(props.payload);
24
- }
25
- return types_1.Result.error(types_1.ACError.TargetImmutable);
26
- }
27
- return types_1.Result.result(props.payload);
28
- };
29
- exports.checkImmutability = checkImmutability;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- import { Result, ACError } from "@aeriajs/types";
3
- export const checkImmutability = async (props, context) => {
4
- if (!context.description.immutable) {
5
- return Result.result(props.payload);
6
- }
7
- const docId = "filters" in props.payload ? props.payload.filters._id : props.payload.what._id;
8
- if (docId) {
9
- if (typeof context.description.immutable === "function") {
10
- const doc = await context.collection.model.findOne({
11
- _id: docId
12
- });
13
- if (!doc) {
14
- return Result.error(ACError.ResourceNotFound);
15
- }
16
- const isImmutable = await context.description.immutable(doc);
17
- return isImmutable ? Result.error(ACError.TargetImmutable) : Result.result(props.payload);
18
- }
19
- return Result.error(ACError.TargetImmutable);
20
- }
21
- return Result.result(props.payload);
22
- };
@@ -1,17 +0,0 @@
1
- import type { Context, InsertPayload } from '@aeriajs/types';
2
- import type { SecurityCheckProps, SecurityCheckReadPayload } from './types.js';
3
- import { ACError } from '@aeriajs/types';
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
- }>;
@@ -1,11 +0,0 @@
1
- import type { SecurityCheckProps, SecurityCheckReadPayload } from './types.js';
2
- import { ACError } from '@aeriajs/types';
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
- }>;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- import { Result, ACError } from "@aeriajs/types";
3
- export const checkPagination = async (props) => {
4
- const { payload } = props;
5
- if (payload.limit) {
6
- if (payload.limit <= 0 || payload.limit > 150) {
7
- return Result.error(ACError.InvalidLimit);
8
- }
9
- }
10
- return Result.result(payload);
11
- };