@aeriajs/builtins 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.
@@ -6,22 +6,26 @@ type Payload = {
6
6
  revalidate?: boolean;
7
7
  router?: boolean;
8
8
  };
9
- export declare const describe: (contextOrPayload: RouteContext | Payload) => Promise<import("@aeriajs/types").GenericResponse | import("@aeriajs/types").EndpointError<{
10
- readonly code: import("@aeriajs/types").ACError.AuthorizationError;
11
- } & {
12
- httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
13
- }> | import("@aeriajs/types").EndpointError<{
14
- readonly code: import("../collections/user/authenticate.js").AuthenticationError.InvalidCredentials;
15
- } & {
16
- httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
17
- }> | import("@aeriajs/types").EndpointError<{
18
- readonly code: import("../collections/user/authenticate.js").AuthenticationError.InactiveUser;
19
- } & {
20
- httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
21
- }> | {
9
+ export declare const describe: (contextOrPayload: RouteContext | Payload) => Promise<import("@aeriajs/types").GenericResponse | {
10
+ readonly _tag: "Error";
11
+ readonly error: ({
12
+ readonly code: import("@aeriajs/types").ACError.AuthorizationError;
13
+ } & {
14
+ httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
15
+ }) | ({
16
+ readonly code: import("../collections/user/authenticate.js").AuthenticationError.InvalidCredentials;
17
+ } & {
18
+ httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
19
+ }) | ({
20
+ readonly code: import("../collections/user/authenticate.js").AuthenticationError.InactiveUser;
21
+ } & {
22
+ httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
23
+ });
24
+ readonly result: undefined;
25
+ } | {
22
26
  descriptions: Record<string, Description>;
23
27
  roles?: string[] | undefined;
24
- auth?: undefined;
28
+ auth?: Partial<unknown> | undefined;
25
29
  router?: any;
26
30
  }>;
27
31
  export {};
@@ -11,14 +11,14 @@ const describe = async (contextOrPayload) => {
11
11
  ? contextOrPayload.request.payload
12
12
  : contextOrPayload;
13
13
  if ('request' in contextOrPayload && props.revalidate) {
14
- const auth = await (0, authenticate_js_1.authenticate)({
14
+ const { error, result: auth } = await (0, authenticate_js_1.authenticate)({
15
15
  revalidate: true,
16
16
  }, await (0, core_1.createContext)({
17
17
  collectionName: 'user',
18
18
  parentContext: contextOrPayload,
19
19
  }));
20
- if ((0, common_1.isError)(auth)) {
21
- return auth;
20
+ if (error) {
21
+ return common_1.Result.error(error);
22
22
  }
23
23
  result.auth = JSON.parse(JSON.stringify(auth));
24
24
  }
@@ -1,20 +1,20 @@
1
1
  "use strict";
2
2
  import { createContext, preloadDescription, getEndpoints } from "@aeriajs/core";
3
3
  import { getCollections, getAvailableRoles } from "@aeriajs/entrypoint";
4
- import { serialize, isError } from "@aeriajs/common";
4
+ import { serialize, Result } from "@aeriajs/common";
5
5
  import { authenticate } from "../collections/user/authenticate.mjs";
6
6
  export const describe = async (contextOrPayload) => {
7
7
  const result = {};
8
8
  const props = "request" in contextOrPayload ? contextOrPayload.request.payload : contextOrPayload;
9
9
  if ("request" in contextOrPayload && props.revalidate) {
10
- const auth = await authenticate({
10
+ const { error, result: auth } = await authenticate({
11
11
  revalidate: true
12
12
  }, await createContext({
13
13
  collectionName: "user",
14
14
  parentContext: contextOrPayload
15
15
  }));
16
- if (isError(auth)) {
17
- return auth;
16
+ if (error) {
17
+ return Result.error(error);
18
18
  }
19
19
  result.auth = JSON.parse(JSON.stringify(auth));
20
20
  }