@aeriajs/builtins 0.0.88 → 0.0.90

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,5 +1,4 @@
1
- import type { RouteContext } from '@aeriajs/types';
2
- import type { Description } from '@aeriajs/types';
1
+ import type { Description, RouteContext } from '@aeriajs/types';
3
2
  type Payload = {
4
3
  collections?: string[];
5
4
  noSerialize?: boolean;
@@ -7,126 +6,138 @@ type Payload = {
7
6
  revalidate?: boolean;
8
7
  router?: boolean;
9
8
  };
10
- export declare const describe: (contextOrPayload: RouteContext | Payload) => Promise<import("@aeriajs/types").GenericResponse | import("@aeriajs/types").Left<import("../collections/user/authenticate.js").AuthenticationErrors> | {
11
- descriptions: Record<string, Description>;
12
- roles?: string[] | undefined;
13
- auth?: Partial<{
14
- user: Pick<import("@aeriajs/types").SchemaWithId<{
15
- readonly $id: "user";
16
- readonly required: readonly ["name", "roles", "email"];
17
- readonly form: readonly ["name", "active", "roles", "email", "phone_number", "picture_file"];
18
- readonly indexes: readonly ["name"];
19
- readonly freshItem: {
20
- readonly active: true;
21
- };
22
- readonly properties: {
23
- readonly name: {
24
- readonly type: "string";
25
- };
26
- readonly given_name: {
27
- readonly getter: (document: any) => string;
28
- };
29
- readonly family_name: {
30
- readonly getter: (document: any) => string;
31
- };
32
- readonly active: {
33
- readonly type: "boolean";
34
- };
35
- readonly roles: {
36
- readonly type: "array";
37
- readonly items: {
38
- readonly type: "string";
39
- };
40
- readonly uniqueItems: true;
41
- };
42
- readonly email: {
43
- readonly type: "string";
44
- readonly inputType: "email";
45
- readonly unique: true;
46
- };
47
- readonly password: {
48
- readonly type: "string";
49
- readonly inputType: "password";
50
- readonly hidden: true;
51
- };
52
- readonly phone_number: {
53
- readonly type: "string";
54
- readonly mask: "(##) #####-####";
55
- };
56
- readonly picture_file: {
57
- readonly $ref: "file";
58
- readonly accept: readonly ["image/*"];
59
- };
60
- readonly picture: {
61
- readonly getter: (value: any) => any;
62
- };
63
- readonly group: {
64
- readonly type: "string";
65
- };
66
- readonly self_registered: {
67
- readonly type: "boolean";
68
- readonly readOnly: true;
69
- };
70
- readonly updated_at: {
9
+ export declare const describe: (contextOrPayload: RouteContext | Payload) => Promise<import("@aeriajs/types").GenericResponse | (({
10
+ user: Pick<import("@aeriajs/types").SchemaWithId<{
11
+ readonly $id: "user";
12
+ readonly required: readonly ["name", "roles", "email"];
13
+ readonly form: readonly ["name", "active", "roles", "email", "phone_number", "picture_file"];
14
+ readonly indexes: readonly ["name"];
15
+ readonly freshItem: {
16
+ readonly active: true;
17
+ };
18
+ readonly properties: {
19
+ readonly name: {
20
+ readonly type: "string";
21
+ };
22
+ readonly given_name: {
23
+ readonly getter: (document: any) => string;
24
+ };
25
+ readonly family_name: {
26
+ readonly getter: (document: any) => string;
27
+ };
28
+ readonly active: {
29
+ readonly type: "boolean";
30
+ };
31
+ readonly roles: {
32
+ readonly type: "array";
33
+ readonly items: {
71
34
  readonly type: "string";
72
- readonly format: "date-time";
73
35
  };
36
+ readonly uniqueItems: true;
74
37
  };
75
- readonly presets: readonly ["crud", "view", "duplicate"];
76
- readonly layout: {
77
- readonly name: "grid";
78
- readonly options: {
79
- readonly title: "name";
80
- readonly badge: "roles";
81
- readonly picture: "picture_file";
82
- readonly information: "email";
83
- readonly active: "active";
84
- };
38
+ readonly email: {
39
+ readonly type: "string";
40
+ readonly inputType: "email";
41
+ readonly unique: true;
85
42
  };
86
- readonly individualActions: {
87
- readonly 'ui:spawnEdit': {
88
- readonly label: "action.edit";
89
- readonly icon: "pencil";
90
- readonly translate: true;
91
- };
92
- readonly 'route:/dashboard/user/changepass': {
93
- readonly label: "change_password";
94
- readonly icon: "key";
95
- readonly fetchItem: true;
96
- readonly translate: true;
97
- };
43
+ readonly password: {
44
+ readonly type: "string";
45
+ readonly inputType: "password";
46
+ readonly hidden: true;
98
47
  };
99
- readonly icon: "users";
100
- readonly filters: readonly ["name", "roles", "email", "phone_number"];
101
- readonly table: readonly ["name", "roles", "picture_file", "active", "updated_at"];
102
- readonly tableMeta: readonly ["email"];
103
- readonly formLayout: {
104
- readonly fields: {
105
- readonly given_name: {
106
- readonly span: 3;
107
- };
108
- readonly family_name: {
109
- readonly span: 3;
110
- };
111
- };
48
+ readonly phone_number: {
49
+ readonly type: "string";
50
+ readonly mask: "(##) #####-####";
51
+ };
52
+ readonly picture_file: {
53
+ readonly $ref: "file";
54
+ readonly accept: readonly ["image/*"];
55
+ };
56
+ readonly picture: {
57
+ readonly getter: (value: any) => any;
58
+ };
59
+ readonly group: {
60
+ readonly type: "string";
61
+ };
62
+ readonly self_registered: {
63
+ readonly type: "boolean";
64
+ readonly readOnly: true;
65
+ };
66
+ readonly updated_at: {
67
+ readonly type: "string";
68
+ readonly format: "date-time";
112
69
  };
113
- }>, "name" | "roles" | "email" | "active"> & {
114
- _id: import("@aeriajs/core").ObjectId | null;
115
70
  };
116
- token: import("@aeriajs/types").TokenRecipient;
117
- } | {
118
- user: {
119
- _id: null;
120
- name: string;
121
- email: string;
122
- roles: string[];
123
- active: boolean;
71
+ readonly presets: readonly ["crud", "view", "duplicate"];
72
+ readonly layout: {
73
+ readonly name: "grid";
74
+ readonly options: {
75
+ readonly title: "name";
76
+ readonly badge: "roles";
77
+ readonly picture: "picture_file";
78
+ readonly information: "email";
79
+ readonly active: "active";
80
+ };
124
81
  };
125
- token: {
126
- type: string;
127
- content: string;
82
+ readonly individualActions: {
83
+ readonly 'ui:spawnEdit': {
84
+ readonly label: "action.edit";
85
+ readonly icon: "pencil";
86
+ readonly translate: true;
87
+ };
88
+ readonly 'route:/dashboard/user/changepass': {
89
+ readonly label: "change_password";
90
+ readonly icon: "key";
91
+ readonly fetchItem: true;
92
+ readonly translate: true;
93
+ };
128
94
  };
129
- }> | undefined;
95
+ readonly icon: "users";
96
+ readonly filters: readonly ["name", "roles", "email", "phone_number"];
97
+ readonly table: readonly ["name", "roles", "picture_file", "active", "updated_at"];
98
+ readonly tableMeta: readonly ["email"];
99
+ readonly formLayout: {
100
+ readonly fields: {
101
+ readonly given_name: {
102
+ readonly span: 3;
103
+ };
104
+ readonly family_name: {
105
+ readonly span: 3;
106
+ };
107
+ };
108
+ };
109
+ }>, "name" | "roles" | "email" | "active"> & {
110
+ _id: import("@aeriajs/core").ObjectId | null;
111
+ };
112
+ token: import("@aeriajs/types").TokenRecipient;
113
+ } | import("@aeriajs/types").EndpointError<{
114
+ readonly code: import("@aeriajs/types").ACError.AuthorizationError;
115
+ } & {
116
+ httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
117
+ }> | {
118
+ user: {
119
+ _id: null;
120
+ name: string;
121
+ email: string;
122
+ roles: string[];
123
+ active: boolean;
124
+ };
125
+ token: {
126
+ type: string;
127
+ content: string;
128
+ };
129
+ } | import("@aeriajs/types").EndpointError<{
130
+ readonly code: import("../collections/user/authenticate.js").AuthenticationError.InvalidCredentials;
131
+ } & {
132
+ httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
133
+ }> | import("@aeriajs/types").EndpointError<{
134
+ readonly code: import("../collections/user/authenticate.js").AuthenticationError.InactiveUser;
135
+ } & {
136
+ httpStatus: import("@aeriajs/types").HTTPStatus.Unauthorized;
137
+ }>) & import("@aeriajs/types").EndpointError<import("@aeriajs/types").EndpointErrorContent>) | {
138
+ descriptions: Record<string, Description>;
139
+ roles?: string[] | undefined;
140
+ auth?: undefined;
130
141
  router?: any;
131
142
  }>;
132
143
  export {};
@@ -11,17 +11,15 @@ const describe = async (contextOrPayload) => {
11
11
  ? contextOrPayload.request.payload
12
12
  : contextOrPayload;
13
13
  if ('request' in contextOrPayload && props.revalidate) {
14
- const authEither = await (0, authenticate_js_1.authenticate)({
14
+ const 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.isLeft)(authEither)) {
21
- const error = (0, common_1.unwrapEither)(authEither);
22
- return (0, common_1.left)(error);
20
+ if ((0, common_1.isError)(auth)) {
21
+ return auth;
23
22
  }
24
- const auth = (0, common_1.unwrapEither)(authEither);
25
23
  result.auth = JSON.parse(JSON.stringify(auth));
26
24
  }
27
25
  const collections = await (0, entrypoint_1.getCollections)();
@@ -1,23 +1,21 @@
1
1
  "use strict";
2
2
  import { createContext, preloadDescription, getEndpoints } from "@aeriajs/core";
3
3
  import { getCollections, getAvailableRoles } from "@aeriajs/entrypoint";
4
- import { serialize, isLeft, left, unwrapEither } from "@aeriajs/common";
4
+ import { serialize, isError } 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 authEither = await authenticate({
10
+ const auth = await authenticate({
11
11
  revalidate: true
12
12
  }, await createContext({
13
13
  collectionName: "user",
14
14
  parentContext: contextOrPayload
15
15
  }));
16
- if (isLeft(authEither)) {
17
- const error = unwrapEither(authEither);
18
- return left(error);
16
+ if (isError(auth)) {
17
+ return auth;
19
18
  }
20
- const auth = unwrapEither(authEither);
21
19
  result.auth = JSON.parse(JSON.stringify(auth));
22
20
  }
23
21
  const collections = await getCollections();