@aeriajs/builtins 0.0.154 → 0.0.155

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.
@@ -1,17 +1,68 @@
1
1
  import type { Description, RouteContext } from '@aeriajs/types';
2
- import { Result } from '@aeriajs/types';
2
+ import { Result, ACError } from '@aeriajs/types';
3
3
  import { authenticate } from '../collections/user/authenticate.js';
4
- type Payload = {
5
- collections?: string[];
6
- noSerialize?: boolean;
7
- roles?: boolean;
8
- revalidate?: boolean;
9
- router?: boolean;
10
- };
11
- export declare const describe: (contextOrPayload: RouteContext | Payload) => Promise<import("@aeriajs/types").GenericResponse | {
4
+ declare const Payload: Pick<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
5
+ readonly collections: {
6
+ readonly type: "array";
7
+ readonly items: {
8
+ readonly type: "string";
9
+ };
10
+ };
11
+ readonly noSerialize: {
12
+ readonly type: "boolean";
13
+ };
14
+ readonly revalidate: {
15
+ readonly type: "boolean";
16
+ };
17
+ readonly roles: {
18
+ readonly type: "boolean";
19
+ };
20
+ readonly router: {
21
+ readonly type: "boolean";
22
+ };
23
+ }>> & {
24
+ roles: boolean;
25
+ revalidate: boolean;
26
+ collections: string[];
27
+ noSerialize: boolean;
28
+ router: boolean;
29
+ }, never>, never> & Partial<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
30
+ readonly collections: {
31
+ readonly type: "array";
32
+ readonly items: {
33
+ readonly type: "string";
34
+ };
35
+ };
36
+ readonly noSerialize: {
37
+ readonly type: "boolean";
38
+ };
39
+ readonly revalidate: {
40
+ readonly type: "boolean";
41
+ };
42
+ readonly roles: {
43
+ readonly type: "boolean";
44
+ };
45
+ readonly router: {
46
+ readonly type: "boolean";
47
+ };
48
+ }>> & {
49
+ roles: boolean;
50
+ revalidate: boolean;
51
+ collections: string[];
52
+ noSerialize: boolean;
53
+ router: boolean;
54
+ }, never>>;
55
+ export declare const describe: (contextOrPayload: RouteContext | typeof Payload) => Promise<import("@aeriajs/types").GenericResponse | {
56
+ readonly _tag: "Error";
57
+ readonly error: {
58
+ readonly code: ACError.MalformedInput;
59
+ readonly details: import("@aeriajs/types").ValidationError | import("@aeriajs/types").PropertyValidationError;
60
+ };
61
+ readonly result: undefined;
62
+ } | {
12
63
  readonly _tag: "Error";
13
64
  readonly error: ({
14
- readonly code: import("@aeriajs/types").ACError.AuthorizationError;
65
+ readonly code: ACError.AuthorizationError;
15
66
  } & {
16
67
  httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
17
68
  }) | ({
@@ -5,12 +5,48 @@ const core_1 = require("@aeriajs/core");
5
5
  const entrypoint_1 = require("@aeriajs/entrypoint");
6
6
  const types_1 = require("@aeriajs/types");
7
7
  const common_1 = require("@aeriajs/common");
8
+ const validation_1 = require("@aeriajs/validation");
8
9
  const authenticate_js_1 = require("../collections/user/authenticate.js");
10
+ const [Payload, validatePayload] = (0, validation_1.validator)({
11
+ type: 'object',
12
+ required: [],
13
+ properties: {
14
+ collections: {
15
+ type: 'array',
16
+ items: {
17
+ type: 'string',
18
+ },
19
+ },
20
+ noSerialize: {
21
+ type: 'boolean',
22
+ },
23
+ revalidate: {
24
+ type: 'boolean',
25
+ },
26
+ roles: {
27
+ type: 'boolean',
28
+ },
29
+ router: {
30
+ type: 'boolean',
31
+ },
32
+ },
33
+ });
9
34
  const describe = async (contextOrPayload) => {
10
35
  const result = {};
11
- const props = 'request' in contextOrPayload
12
- ? contextOrPayload.request.payload
13
- : contextOrPayload;
36
+ let props;
37
+ if ('request' in contextOrPayload) {
38
+ const { error, result: validatedPayload } = validatePayload(contextOrPayload.request.payload);
39
+ if (error) {
40
+ return (0, common_1.endpointError)({
41
+ code: types_1.ACError.MalformedInput,
42
+ details: error,
43
+ });
44
+ }
45
+ props = validatedPayload;
46
+ }
47
+ else {
48
+ props = contextOrPayload;
49
+ }
14
50
  if ('request' in contextOrPayload && props.revalidate) {
15
51
  const { error, result: auth } = await (0, authenticate_js_1.authenticate)({
16
52
  revalidate: true,
@@ -1,12 +1,49 @@
1
1
  "use strict";
2
2
  import { createContext, preloadDescription, getEndpoints } from "@aeriajs/core";
3
3
  import { getCollections, getAvailableRoles } from "@aeriajs/entrypoint";
4
- import { Result } from "@aeriajs/types";
5
- import { serialize } from "@aeriajs/common";
4
+ import { Result, ACError } from "@aeriajs/types";
5
+ import { serialize, endpointError } from "@aeriajs/common";
6
+ import { validator } from "@aeriajs/validation";
6
7
  import { authenticate } from "../collections/user/authenticate.mjs";
8
+ const [Payload, validatePayload] = validator({
9
+ type: "object",
10
+ required: [],
11
+ properties: {
12
+ collections: {
13
+ type: "array",
14
+ items: {
15
+ type: "string"
16
+ }
17
+ },
18
+ noSerialize: {
19
+ type: "boolean"
20
+ },
21
+ revalidate: {
22
+ type: "boolean"
23
+ },
24
+ roles: {
25
+ type: "boolean"
26
+ },
27
+ router: {
28
+ type: "boolean"
29
+ }
30
+ }
31
+ });
7
32
  export const describe = async (contextOrPayload) => {
8
33
  const result = {};
9
- const props = "request" in contextOrPayload ? contextOrPayload.request.payload : contextOrPayload;
34
+ let props;
35
+ if ("request" in contextOrPayload) {
36
+ const { error, result: validatedPayload } = validatePayload(contextOrPayload.request.payload);
37
+ if (error) {
38
+ return endpointError({
39
+ code: ACError.MalformedInput,
40
+ details: error
41
+ });
42
+ }
43
+ props = validatedPayload;
44
+ } else {
45
+ props = contextOrPayload;
46
+ }
10
47
  if ("request" in contextOrPayload && props.revalidate) {
11
48
  const { error, result: auth } = await authenticate({
12
49
  revalidate: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/builtins",
3
- "version": "0.0.154",
3
+ "version": "0.0.155",
4
4
  "description": "## Installation",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -45,11 +45,11 @@
45
45
  "mongodb": "^6.5.0"
46
46
  },
47
47
  "peerDependencies": {
48
- "@aeriajs/core": "^0.0.154",
49
- "@aeriajs/common": "^0.0.93",
50
- "@aeriajs/entrypoint": "^0.0.95",
48
+ "@aeriajs/core": "^0.0.155",
49
+ "@aeriajs/common": "^0.0.94",
50
+ "@aeriajs/entrypoint": "^0.0.96",
51
51
  "@aeriajs/types": "^0.0.80",
52
- "@aeriajs/validation": "^0.0.96"
52
+ "@aeriajs/validation": "^0.0.97"
53
53
  },
54
54
  "scripts": {
55
55
  "test": "echo skipping",