@aeriajs/builtins 0.0.162 → 0.0.164
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/authentication.d.ts +3 -1
- package/dist/authentication.js +5 -10
- package/dist/authentication.mjs +5 -10
- package/dist/collections/file/description.d.ts +2 -2
- package/dist/collections/file/description.js +12 -7
- package/dist/collections/file/description.mjs +12 -7
- package/dist/collections/file/index.d.ts +10 -10
- package/dist/collections/file/insert.d.ts +2 -2
- package/dist/collections/log/index.d.ts +2 -18
- package/dist/collections/user/createAccount.d.ts +110 -8
- package/dist/collections/user/createAccount.js +16 -10
- package/dist/collections/user/createAccount.mjs +16 -10
- package/dist/collections/user/description.d.ts +3 -3
- package/dist/collections/user/description.js +12 -6
- package/dist/collections/user/description.mjs +12 -6
- package/dist/collections/user/getCurrentUser.d.ts +3 -3
- package/dist/collections/user/index.d.ts +249 -67
- package/dist/collections/user/index.js +15 -14
- package/dist/collections/user/index.mjs +15 -14
- package/dist/functions/describe.d.ts +1 -1
- package/dist/index.d.ts +261 -95
- package/package.json +6 -6
package/dist/authentication.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RouteContext, SchemaWithId, TokenRecipient } from '@aeriajs/types';
|
|
2
2
|
import type { description } from './collections/user/description.js';
|
|
3
|
-
|
|
3
|
+
type User = SchemaWithId<typeof description>;
|
|
4
|
+
export type TokenableUser = Pick<User, '_id' | 'name' | 'email' | 'roles' | 'active'>;
|
|
4
5
|
export type SuccessfulAuthentication = {
|
|
5
6
|
user: TokenableUser & {
|
|
6
7
|
_id: null;
|
|
@@ -25,3 +26,4 @@ export declare const defaultSuccessfulAuthentication: () => Promise<{
|
|
|
25
26
|
content: string;
|
|
26
27
|
};
|
|
27
28
|
}>;
|
|
29
|
+
export {};
|
package/dist/authentication.js
CHANGED
|
@@ -24,16 +24,11 @@ const successfulAuthentication = async (user, context) => {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
if (context.config.tokenUserProperties) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
...a,
|
|
33
|
-
[prop]: obj[prop],
|
|
34
|
-
};
|
|
35
|
-
}, {});
|
|
36
|
-
tokenContent.userinfo = pick(user, context.config.tokenUserProperties);
|
|
27
|
+
const userinfo = {};
|
|
28
|
+
for (const prop of context.config.tokenUserProperties) {
|
|
29
|
+
userinfo[prop] = user[prop];
|
|
30
|
+
}
|
|
31
|
+
tokenContent.userinfo = userinfo;
|
|
37
32
|
}
|
|
38
33
|
const token = await (0, core_1.signToken)(tokenContent);
|
|
39
34
|
return {
|
package/dist/authentication.mjs
CHANGED
|
@@ -21,16 +21,11 @@ export const successfulAuthentication = async (user, context) => {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
if (context.config.tokenUserProperties) {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
...a,
|
|
30
|
-
[prop]: obj[prop]
|
|
31
|
-
};
|
|
32
|
-
}, {});
|
|
33
|
-
tokenContent.userinfo = pick(user, context.config.tokenUserProperties);
|
|
24
|
+
const userinfo = {};
|
|
25
|
+
for (const prop of context.config.tokenUserProperties) {
|
|
26
|
+
userinfo[prop] = user[prop];
|
|
27
|
+
}
|
|
28
|
+
tokenContent.userinfo = userinfo;
|
|
34
29
|
}
|
|
35
30
|
const token = await signToken(tokenContent);
|
|
36
31
|
return {
|
|
@@ -28,10 +28,10 @@ export declare const description: {
|
|
|
28
28
|
readonly type: "boolean";
|
|
29
29
|
};
|
|
30
30
|
readonly link: {
|
|
31
|
-
readonly getter: (
|
|
31
|
+
readonly getter: (doc: object) => Promise<string | undefined>;
|
|
32
32
|
};
|
|
33
33
|
readonly download_link: {
|
|
34
|
-
readonly getter: (
|
|
34
|
+
readonly getter: (doc: object) => Promise<string | undefined>;
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
37
|
readonly actions: {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.description = void 0;
|
|
4
|
+
const mongodb_1 = require("mongodb");
|
|
4
5
|
const core_1 = require("@aeriajs/core");
|
|
5
6
|
const entrypoint_1 = require("@aeriajs/entrypoint");
|
|
6
|
-
const link = async (
|
|
7
|
+
const link = async (fileId) => {
|
|
7
8
|
const config = await (0, entrypoint_1.getConfig)();
|
|
8
|
-
return `${config.publicUrl || ''}/file/${
|
|
9
|
+
return `${config.publicUrl || ''}/file/${fileId}`;
|
|
9
10
|
};
|
|
10
|
-
const timestamp = (lastModified) => lastModified
|
|
11
|
+
const timestamp = (lastModified) => lastModified instanceof Date
|
|
11
12
|
? new Date(lastModified).getTime()
|
|
12
13
|
: 'fresh';
|
|
13
14
|
exports.description = (0, core_1.defineDescription)({
|
|
@@ -44,13 +45,17 @@ exports.description = (0, core_1.defineDescription)({
|
|
|
44
45
|
type: 'boolean',
|
|
45
46
|
},
|
|
46
47
|
link: {
|
|
47
|
-
getter: async (
|
|
48
|
-
|
|
48
|
+
getter: async (doc) => {
|
|
49
|
+
if ('_id' in doc && 'last_modified' in doc && doc._id instanceof mongodb_1.ObjectId) {
|
|
50
|
+
return `${await link(doc._id)}/${timestamp(doc.last_modified)}`;
|
|
51
|
+
}
|
|
49
52
|
},
|
|
50
53
|
},
|
|
51
54
|
download_link: {
|
|
52
|
-
getter: async (
|
|
53
|
-
|
|
55
|
+
getter: async (doc) => {
|
|
56
|
+
if ('_id' in doc && 'last_modified' in doc && doc._id instanceof mongodb_1.ObjectId) {
|
|
57
|
+
return `${await link(doc._id)}/download/${timestamp(doc.last_modified)}`;
|
|
58
|
+
}
|
|
54
59
|
},
|
|
55
60
|
},
|
|
56
61
|
},
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
import { ObjectId } from "mongodb";
|
|
2
3
|
import { defineDescription } from "@aeriajs/core";
|
|
3
4
|
import { getConfig } from "@aeriajs/entrypoint";
|
|
4
|
-
const link = async (
|
|
5
|
+
const link = async (fileId) => {
|
|
5
6
|
const config = await getConfig();
|
|
6
|
-
return `${config.publicUrl || ""}/file/${
|
|
7
|
+
return `${config.publicUrl || ""}/file/${fileId}`;
|
|
7
8
|
};
|
|
8
|
-
const timestamp = (lastModified) => lastModified ? new Date(lastModified).getTime() : "fresh";
|
|
9
|
+
const timestamp = (lastModified) => lastModified instanceof Date ? new Date(lastModified).getTime() : "fresh";
|
|
9
10
|
export const description = defineDescription({
|
|
10
11
|
$id: "file",
|
|
11
12
|
icon: "paperclip",
|
|
@@ -40,13 +41,17 @@ export const description = defineDescription({
|
|
|
40
41
|
type: "boolean"
|
|
41
42
|
},
|
|
42
43
|
link: {
|
|
43
|
-
getter: async (
|
|
44
|
-
|
|
44
|
+
getter: async (doc) => {
|
|
45
|
+
if ("_id" in doc && "last_modified" in doc && doc._id instanceof ObjectId) {
|
|
46
|
+
return `${await link(doc._id)}/${timestamp(doc.last_modified)}`;
|
|
47
|
+
}
|
|
45
48
|
}
|
|
46
49
|
},
|
|
47
50
|
download_link: {
|
|
48
|
-
getter: async (
|
|
49
|
-
|
|
51
|
+
getter: async (doc) => {
|
|
52
|
+
if ("_id" in doc && "last_modified" in doc && doc._id instanceof ObjectId) {
|
|
53
|
+
return `${await link(doc._id)}/download/${timestamp(doc.last_modified)}`;
|
|
54
|
+
}
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
57
|
},
|
|
@@ -127,10 +127,10 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
|
|
|
127
127
|
readonly type: "boolean";
|
|
128
128
|
};
|
|
129
129
|
readonly link: {
|
|
130
|
-
readonly getter: (
|
|
130
|
+
readonly getter: (doc: object) => Promise<string | undefined>;
|
|
131
131
|
};
|
|
132
132
|
readonly download_link: {
|
|
133
|
-
readonly getter: (
|
|
133
|
+
readonly getter: (doc: object) => Promise<string | undefined>;
|
|
134
134
|
};
|
|
135
135
|
};
|
|
136
136
|
readonly actions: {
|
|
@@ -184,10 +184,10 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
|
|
|
184
184
|
readonly type: "boolean";
|
|
185
185
|
};
|
|
186
186
|
readonly link: {
|
|
187
|
-
readonly getter: (
|
|
187
|
+
readonly getter: (doc: object) => Promise<string | undefined>;
|
|
188
188
|
};
|
|
189
189
|
readonly download_link: {
|
|
190
|
-
readonly getter: (
|
|
190
|
+
readonly getter: (doc: object) => Promise<string | undefined>;
|
|
191
191
|
};
|
|
192
192
|
};
|
|
193
193
|
readonly actions: {
|
|
@@ -279,10 +279,10 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
|
|
|
279
279
|
readonly type: "boolean";
|
|
280
280
|
};
|
|
281
281
|
readonly link: {
|
|
282
|
-
readonly getter: (
|
|
282
|
+
readonly getter: (doc: object) => Promise<string | undefined>;
|
|
283
283
|
};
|
|
284
284
|
readonly download_link: {
|
|
285
|
-
readonly getter: (
|
|
285
|
+
readonly getter: (doc: object) => Promise<string | undefined>;
|
|
286
286
|
};
|
|
287
287
|
};
|
|
288
288
|
readonly actions: {
|
|
@@ -330,10 +330,10 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
|
|
|
330
330
|
readonly type: "boolean";
|
|
331
331
|
};
|
|
332
332
|
readonly link: {
|
|
333
|
-
readonly getter: (
|
|
333
|
+
readonly getter: (doc: object) => Promise<string | undefined>;
|
|
334
334
|
};
|
|
335
335
|
readonly download_link: {
|
|
336
|
-
readonly getter: (
|
|
336
|
+
readonly getter: (doc: object) => Promise<string | undefined>;
|
|
337
337
|
};
|
|
338
338
|
};
|
|
339
339
|
readonly actions: {
|
|
@@ -387,10 +387,10 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
|
|
|
387
387
|
readonly type: "boolean";
|
|
388
388
|
};
|
|
389
389
|
readonly link: {
|
|
390
|
-
readonly getter: (
|
|
390
|
+
readonly getter: (doc: object) => Promise<string | undefined>;
|
|
391
391
|
};
|
|
392
392
|
readonly download_link: {
|
|
393
|
-
readonly getter: (
|
|
393
|
+
readonly getter: (doc: object) => Promise<string | undefined>;
|
|
394
394
|
};
|
|
395
395
|
};
|
|
396
396
|
readonly actions: {
|
|
@@ -34,10 +34,10 @@ export declare const insert: (payload: {
|
|
|
34
34
|
readonly type: "boolean";
|
|
35
35
|
};
|
|
36
36
|
readonly link: {
|
|
37
|
-
readonly getter: (
|
|
37
|
+
readonly getter: (doc: object) => Promise<string | undefined>;
|
|
38
38
|
};
|
|
39
39
|
readonly download_link: {
|
|
40
|
-
readonly getter: (
|
|
40
|
+
readonly getter: (doc: object) => Promise<string | undefined>;
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
43
|
readonly actions: {
|
|
@@ -28,15 +28,7 @@ export declare const log: Omit<import("@aeriajs/types").Collection<{
|
|
|
28
28
|
};
|
|
29
29
|
functions: {
|
|
30
30
|
readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions) => Promise<import("@aeriajs/types").GetReturnType<import("@aeriajs/types").SchemaWithId<any>>>;
|
|
31
|
-
readonly getAll: (payload: import("@aeriajs/types").GetAllPayload<import("@aeriajs/types").SchemaWithId<any>> | undefined, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetAllOptions) => Promise<
|
|
32
|
-
readonly _tag: "Error";
|
|
33
|
-
readonly error: import("@aeriajs/types").ACError.InvalidLimit | import("@aeriajs/types").ACError.OwnershipError;
|
|
34
|
-
readonly result: undefined;
|
|
35
|
-
} | {
|
|
36
|
-
readonly _tag: "Result";
|
|
37
|
-
readonly error: undefined;
|
|
38
|
-
readonly result: import("@aeriajs/types").SchemaWithId<any>[];
|
|
39
|
-
}>;
|
|
31
|
+
readonly getAll: (payload: import("@aeriajs/types").GetAllPayload<import("@aeriajs/types").SchemaWithId<any>> | undefined, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetAllOptions) => Promise<import("@aeriajs/types").Result.Either<any, any>>;
|
|
40
32
|
readonly insert: (payload: import("@aeriajs/types").InsertPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").InsertOptions) => Promise<import("@aeriajs/types").InsertReturnType<import("@aeriajs/types").SchemaWithId<any>>>;
|
|
41
33
|
};
|
|
42
34
|
exposedFunctions: {
|
|
@@ -101,15 +93,7 @@ export declare const log: Omit<import("@aeriajs/types").Collection<{
|
|
|
101
93
|
};
|
|
102
94
|
functions: {
|
|
103
95
|
readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions) => Promise<import("@aeriajs/types").GetReturnType<import("@aeriajs/types").SchemaWithId<any>>>;
|
|
104
|
-
readonly getAll: (payload: import("@aeriajs/types").GetAllPayload<import("@aeriajs/types").SchemaWithId<any>> | undefined, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetAllOptions) => Promise<
|
|
105
|
-
readonly _tag: "Error";
|
|
106
|
-
readonly error: import("@aeriajs/types").ACError.InvalidLimit | import("@aeriajs/types").ACError.OwnershipError;
|
|
107
|
-
readonly result: undefined;
|
|
108
|
-
} | {
|
|
109
|
-
readonly _tag: "Result";
|
|
110
|
-
readonly error: undefined;
|
|
111
|
-
readonly result: import("@aeriajs/types").SchemaWithId<any>[];
|
|
112
|
-
}>;
|
|
96
|
+
readonly getAll: (payload: import("@aeriajs/types").GetAllPayload<import("@aeriajs/types").SchemaWithId<any>> | undefined, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetAllOptions) => Promise<import("@aeriajs/types").Result.Either<any, any>>;
|
|
113
97
|
readonly insert: (payload: import("@aeriajs/types").InsertPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").InsertOptions) => Promise<import("@aeriajs/types").InsertReturnType<import("@aeriajs/types").SchemaWithId<any>>>;
|
|
114
98
|
};
|
|
115
99
|
contracts: {
|
|
@@ -1,13 +1,115 @@
|
|
|
1
1
|
import type { Context, SchemaWithId } from '@aeriajs/types';
|
|
2
2
|
import type { description } from './description.js';
|
|
3
|
-
import {
|
|
4
|
-
export declare
|
|
3
|
+
import { HTTPStatus, ACError } from '@aeriajs/types';
|
|
4
|
+
export declare enum CreateAccountError {
|
|
5
|
+
SignupDisallowed = "SIGNUP_DISALLOWED"
|
|
6
|
+
}
|
|
7
|
+
export declare const createAccount: (payload: Partial<SchemaWithId<typeof description>>, context: Context<typeof description>) => Promise<import("@aeriajs/types").Result.Error<{
|
|
8
|
+
readonly code: CreateAccountError;
|
|
9
|
+
} & {
|
|
10
|
+
httpStatus: HTTPStatus.Forbidden;
|
|
11
|
+
}> | import("@aeriajs/types").Result.Error<{
|
|
5
12
|
readonly code: ACError.MalformedInput;
|
|
6
|
-
readonly details: import("@aeriajs/types").
|
|
13
|
+
readonly details: import("@aeriajs/types").PropertyValidationError | import("@aeriajs/types").ValidationError;
|
|
7
14
|
} & {
|
|
8
15
|
httpStatus: HTTPStatus.BadRequest;
|
|
9
|
-
}> | {
|
|
10
|
-
readonly
|
|
11
|
-
readonly
|
|
12
|
-
readonly
|
|
13
|
-
|
|
16
|
+
}> | import("@aeriajs/types").InsertReturnType<SchemaWithId<{
|
|
17
|
+
readonly $id: "user";
|
|
18
|
+
readonly icon: "users";
|
|
19
|
+
readonly required: readonly ["name", "roles", "email"];
|
|
20
|
+
readonly form: readonly ["name", "active", "roles", "email", "phone_number", "picture_file"];
|
|
21
|
+
readonly indexes: readonly ["name"];
|
|
22
|
+
readonly properties: {
|
|
23
|
+
readonly name: {
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
};
|
|
26
|
+
readonly given_name: {
|
|
27
|
+
readonly getter: (doc: object) => string | undefined;
|
|
28
|
+
};
|
|
29
|
+
readonly family_name: {
|
|
30
|
+
readonly getter: (doc: object) => string | undefined;
|
|
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: (doc: object) => string | undefined;
|
|
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: {
|
|
71
|
+
readonly type: "string";
|
|
72
|
+
readonly format: "date-time";
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
readonly presets: readonly ["crud", "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
|
+
};
|
|
85
|
+
};
|
|
86
|
+
readonly individualActions: {
|
|
87
|
+
readonly changePassword: {
|
|
88
|
+
readonly label: "change_password";
|
|
89
|
+
readonly icon: "key";
|
|
90
|
+
readonly translate: true;
|
|
91
|
+
readonly route: {
|
|
92
|
+
readonly name: "/dashboard/user/changepass";
|
|
93
|
+
readonly fetchItem: true;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
readonly copyActivationLink: {
|
|
97
|
+
readonly label: "copy_activation_link";
|
|
98
|
+
readonly icon: "link";
|
|
99
|
+
readonly translate: true;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
readonly filters: readonly ["name", "roles", "email", "phone_number"];
|
|
103
|
+
readonly table: readonly ["name", "roles", "picture_file", "active", "updated_at"];
|
|
104
|
+
readonly tableMeta: readonly ["email"];
|
|
105
|
+
readonly formLayout: {
|
|
106
|
+
readonly fields: {
|
|
107
|
+
readonly given_name: {
|
|
108
|
+
readonly span: 3;
|
|
109
|
+
};
|
|
110
|
+
readonly family_name: {
|
|
111
|
+
readonly span: 3;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
}>>>;
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAccount = void 0;
|
|
3
|
+
exports.createAccount = exports.CreateAccountError = void 0;
|
|
4
4
|
const types_1 = require("@aeriajs/types");
|
|
5
5
|
const validation_1 = require("@aeriajs/validation");
|
|
6
6
|
const bcrypt = require("bcrypt");
|
|
7
|
+
var CreateAccountError;
|
|
8
|
+
(function (CreateAccountError) {
|
|
9
|
+
CreateAccountError["SignupDisallowed"] = "SIGNUP_DISALLOWED";
|
|
10
|
+
})(CreateAccountError || (exports.CreateAccountError = CreateAccountError = {}));
|
|
7
11
|
const createAccount = async (payload, context) => {
|
|
8
12
|
const userCandidate = Object.assign({}, payload);
|
|
9
13
|
if (!context.config.security.allowSignup) {
|
|
10
|
-
|
|
14
|
+
return context.error(types_1.HTTPStatus.Forbidden, {
|
|
15
|
+
code: CreateAccountError.SignupDisallowed,
|
|
16
|
+
});
|
|
11
17
|
}
|
|
12
18
|
delete userCandidate._id;
|
|
13
19
|
delete userCandidate.roles;
|
|
@@ -40,8 +46,9 @@ const createAccount = async (payload, context) => {
|
|
|
40
46
|
details: error,
|
|
41
47
|
});
|
|
42
48
|
}
|
|
49
|
+
let roles = [], defaults = {};
|
|
43
50
|
if (context.config.security.signupDefaults) {
|
|
44
|
-
|
|
51
|
+
({ roles = [], ...defaults } = context.config.security.signupDefaults);
|
|
45
52
|
}
|
|
46
53
|
if (user.password) {
|
|
47
54
|
user.password = await bcrypt.hash(user.password, 10);
|
|
@@ -51,13 +58,12 @@ const createAccount = async (payload, context) => {
|
|
|
51
58
|
self_registered: true,
|
|
52
59
|
});
|
|
53
60
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
return context.collections.user.functions.insert({
|
|
62
|
+
what: {
|
|
63
|
+
...user,
|
|
64
|
+
...defaults,
|
|
65
|
+
roles,
|
|
66
|
+
},
|
|
57
67
|
});
|
|
58
|
-
if (!newUser) {
|
|
59
|
-
throw new Error();
|
|
60
|
-
}
|
|
61
|
-
return types_1.Result.result(newUser);
|
|
62
68
|
};
|
|
63
69
|
exports.createAccount = createAccount;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
2
|
+
import { HTTPStatus, ACError } from "@aeriajs/types";
|
|
3
3
|
import { validate } from "@aeriajs/validation";
|
|
4
4
|
import * as bcrypt from "bcrypt";
|
|
5
|
+
export var CreateAccountError = /* @__PURE__ */ ((CreateAccountError2) => {
|
|
6
|
+
CreateAccountError2["SignupDisallowed"] = "SIGNUP_DISALLOWED";
|
|
7
|
+
return CreateAccountError2;
|
|
8
|
+
})(CreateAccountError || {});
|
|
5
9
|
export const createAccount = async (payload, context) => {
|
|
6
10
|
const userCandidate = Object.assign({}, payload);
|
|
7
11
|
if (!context.config.security.allowSignup) {
|
|
8
|
-
|
|
12
|
+
return context.error(HTTPStatus.Forbidden, {
|
|
13
|
+
code: "SIGNUP_DISALLOWED" /* SignupDisallowed */
|
|
14
|
+
});
|
|
9
15
|
}
|
|
10
16
|
delete userCandidate._id;
|
|
11
17
|
delete userCandidate.roles;
|
|
@@ -38,8 +44,9 @@ export const createAccount = async (payload, context) => {
|
|
|
38
44
|
details: error
|
|
39
45
|
});
|
|
40
46
|
}
|
|
47
|
+
let roles = [], defaults = {};
|
|
41
48
|
if (context.config.security.signupDefaults) {
|
|
42
|
-
|
|
49
|
+
({ roles = [], ...defaults } = context.config.security.signupDefaults);
|
|
43
50
|
}
|
|
44
51
|
if (user.password) {
|
|
45
52
|
user.password = await bcrypt.hash(user.password, 10);
|
|
@@ -49,12 +56,11 @@ export const createAccount = async (payload, context) => {
|
|
|
49
56
|
self_registered: true
|
|
50
57
|
});
|
|
51
58
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
return context.collections.user.functions.insert({
|
|
60
|
+
what: {
|
|
61
|
+
...user,
|
|
62
|
+
...defaults,
|
|
63
|
+
roles
|
|
64
|
+
}
|
|
55
65
|
});
|
|
56
|
-
if (!newUser) {
|
|
57
|
-
throw new Error();
|
|
58
|
-
}
|
|
59
|
-
return Result.result(newUser);
|
|
60
66
|
};
|
|
@@ -13,10 +13,10 @@ export declare const description: {
|
|
|
13
13
|
readonly type: "string";
|
|
14
14
|
};
|
|
15
15
|
readonly given_name: {
|
|
16
|
-
readonly getter: (
|
|
16
|
+
readonly getter: (doc: object) => string | undefined;
|
|
17
17
|
};
|
|
18
18
|
readonly family_name: {
|
|
19
|
-
readonly getter: (
|
|
19
|
+
readonly getter: (doc: object) => string | undefined;
|
|
20
20
|
};
|
|
21
21
|
readonly active: {
|
|
22
22
|
readonly type: "boolean";
|
|
@@ -47,7 +47,7 @@ export declare const description: {
|
|
|
47
47
|
readonly accept: readonly ["image/*"];
|
|
48
48
|
};
|
|
49
49
|
readonly picture: {
|
|
50
|
-
readonly getter: (
|
|
50
|
+
readonly getter: (doc: object) => string | undefined;
|
|
51
51
|
};
|
|
52
52
|
readonly group: {
|
|
53
53
|
readonly type: "string";
|
|
@@ -28,13 +28,17 @@ exports.description = (0, core_1.defineDescription)({
|
|
|
28
28
|
type: 'string',
|
|
29
29
|
},
|
|
30
30
|
given_name: {
|
|
31
|
-
getter: (
|
|
32
|
-
|
|
31
|
+
getter: (doc) => {
|
|
32
|
+
if ('name' in doc && typeof doc.name === 'string') {
|
|
33
|
+
return doc.name.split(' ')[0];
|
|
34
|
+
}
|
|
33
35
|
},
|
|
34
36
|
},
|
|
35
37
|
family_name: {
|
|
36
|
-
getter: (
|
|
37
|
-
|
|
38
|
+
getter: (doc) => {
|
|
39
|
+
if ('name' in doc && typeof doc.name === 'string') {
|
|
40
|
+
return doc.name.split(' ')[1];
|
|
41
|
+
}
|
|
38
42
|
},
|
|
39
43
|
},
|
|
40
44
|
active: {
|
|
@@ -66,8 +70,10 @@ exports.description = (0, core_1.defineDescription)({
|
|
|
66
70
|
accept: ['image/*'],
|
|
67
71
|
},
|
|
68
72
|
picture: {
|
|
69
|
-
getter: (
|
|
70
|
-
|
|
73
|
+
getter: (doc) => {
|
|
74
|
+
if ('picture_file' in doc && doc.picture_file instanceof Object && 'link' in doc.picture_file && typeof doc.picture_file.link === 'string') {
|
|
75
|
+
return doc.picture_file.link;
|
|
76
|
+
}
|
|
71
77
|
},
|
|
72
78
|
},
|
|
73
79
|
group: {
|
|
@@ -22,13 +22,17 @@ export const description = defineDescription({
|
|
|
22
22
|
type: "string"
|
|
23
23
|
},
|
|
24
24
|
given_name: {
|
|
25
|
-
getter: (
|
|
26
|
-
|
|
25
|
+
getter: (doc) => {
|
|
26
|
+
if ("name" in doc && typeof doc.name === "string") {
|
|
27
|
+
return doc.name.split(" ")[0];
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
30
|
},
|
|
29
31
|
family_name: {
|
|
30
|
-
getter: (
|
|
31
|
-
|
|
32
|
+
getter: (doc) => {
|
|
33
|
+
if ("name" in doc && typeof doc.name === "string") {
|
|
34
|
+
return doc.name.split(" ")[1];
|
|
35
|
+
}
|
|
32
36
|
}
|
|
33
37
|
},
|
|
34
38
|
active: {
|
|
@@ -60,8 +64,10 @@ export const description = defineDescription({
|
|
|
60
64
|
accept: ["image/*"]
|
|
61
65
|
},
|
|
62
66
|
picture: {
|
|
63
|
-
getter: (
|
|
64
|
-
|
|
67
|
+
getter: (doc) => {
|
|
68
|
+
if ("picture_file" in doc && doc.picture_file instanceof Object && "link" in doc.picture_file && typeof doc.picture_file.link === "string") {
|
|
69
|
+
return doc.picture_file.link;
|
|
70
|
+
}
|
|
65
71
|
}
|
|
66
72
|
},
|
|
67
73
|
group: {
|
|
@@ -19,10 +19,10 @@ export declare const getCurrentUser: (_payload: undefined, context: Context<type
|
|
|
19
19
|
readonly type: "string";
|
|
20
20
|
};
|
|
21
21
|
readonly given_name: {
|
|
22
|
-
readonly getter: (
|
|
22
|
+
readonly getter: (doc: object) => string | undefined;
|
|
23
23
|
};
|
|
24
24
|
readonly family_name: {
|
|
25
|
-
readonly getter: (
|
|
25
|
+
readonly getter: (doc: object) => string | undefined;
|
|
26
26
|
};
|
|
27
27
|
readonly active: {
|
|
28
28
|
readonly type: "boolean";
|
|
@@ -53,7 +53,7 @@ export declare const getCurrentUser: (_payload: undefined, context: Context<type
|
|
|
53
53
|
readonly accept: readonly ["image/*"];
|
|
54
54
|
};
|
|
55
55
|
readonly picture: {
|
|
56
|
-
readonly getter: (
|
|
56
|
+
readonly getter: (doc: object) => string | undefined;
|
|
57
57
|
};
|
|
58
58
|
readonly group: {
|
|
59
59
|
readonly type: "string";
|