@aeriajs/builtins 0.0.70 → 0.0.72
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/collections/file/download.js +2 -3
- package/dist/collections/file/download.mjs +3 -3
- package/dist/collections/file/index.d.ts +2 -2
- package/dist/collections/file/insert.js +2 -3
- package/dist/collections/file/insert.mjs +3 -3
- package/dist/collections/file/remove.js +2 -3
- package/dist/collections/file/remove.mjs +3 -3
- package/dist/collections/file/removeAll.js +3 -4
- package/dist/collections/file/removeAll.mjs +3 -3
- package/dist/collections/log/index.d.ts +1 -1
- package/dist/collections/resourceUsage/index.d.ts +1 -1
- package/dist/collections/user/activate.d.ts +1 -1
- package/dist/collections/user/activate.js +2 -3
- package/dist/collections/user/activate.mjs +3 -3
- package/dist/collections/user/authenticate.d.ts +1 -1
- package/dist/collections/user/authenticate.js +17 -15
- package/dist/collections/user/authenticate.mjs +12 -10
- package/dist/collections/user/createAccount.js +6 -6
- package/dist/collections/user/createAccount.mjs +6 -5
- package/dist/collections/user/description.d.ts +1 -2
- package/dist/collections/user/description.js +1 -2
- package/dist/collections/user/description.mjs +3 -4
- package/dist/collections/user/getInfo.js +2 -3
- package/dist/collections/user/getInfo.mjs +3 -3
- package/dist/collections/user/index.d.ts +22 -41
- package/dist/collections/user/insert.d.ts +1 -2
- package/dist/collections/user/insert.js +4 -1
- package/dist/collections/user/insert.mjs +5 -2
- package/dist/functions/describe.d.ts +1 -2
- package/dist/index.d.ts +26 -45
- package/package.json +13 -13
|
@@ -12,7 +12,7 @@ var FileReadError;
|
|
|
12
12
|
FileReadError["DocumentNotFound"] = "DOCUMENT_NOT_FOUND";
|
|
13
13
|
FileReadError["FileNotFound"] = "FILE_NOT_FOUND";
|
|
14
14
|
})(FileReadError || (exports.FileReadError = FileReadError = {}));
|
|
15
|
-
|
|
15
|
+
exports.download = (0, core_1.defineExposedFunction)(async (payload, context) => {
|
|
16
16
|
const { fileId, options = [] } = payload;
|
|
17
17
|
const file = await context.collection.model.findOne({
|
|
18
18
|
_id: new core_1.ObjectId(fileId),
|
|
@@ -74,5 +74,4 @@ const download = async (payload, context) => {
|
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
return fs_1.default.createReadStream(file.absolute_path);
|
|
77
|
-
};
|
|
78
|
-
exports.download = download;
|
|
77
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { ObjectId } from "@aeriajs/core";
|
|
2
|
+
import { defineExposedFunction, ObjectId } from "@aeriajs/core";
|
|
3
3
|
import { left } from "@aeriajs/common";
|
|
4
4
|
import fs from "fs";
|
|
5
5
|
export var FileReadError = /* @__PURE__ */ ((FileReadError2) => {
|
|
@@ -7,7 +7,7 @@ export var FileReadError = /* @__PURE__ */ ((FileReadError2) => {
|
|
|
7
7
|
FileReadError2["FileNotFound"] = "FILE_NOT_FOUND";
|
|
8
8
|
return FileReadError2;
|
|
9
9
|
})(FileReadError || {});
|
|
10
|
-
export const download = async (payload, context) => {
|
|
10
|
+
export const download = defineExposedFunction(async (payload, context) => {
|
|
11
11
|
const { fileId, options = [] } = payload;
|
|
12
12
|
const file = await context.collection.model.findOne({
|
|
13
13
|
_id: new ObjectId(fileId)
|
|
@@ -62,4 +62,4 @@ export const download = async (payload, context) => {
|
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
return fs.createReadStream(file.absolute_path);
|
|
65
|
-
};
|
|
65
|
+
});
|
|
@@ -28,7 +28,7 @@ export declare const tempFile: Omit<import("@aeriajs/types").Collection<{
|
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
-
}>, "description" | "functions" | "item" | "security" | "accessControl"> & {
|
|
31
|
+
}>, "description" | "functions" | "item" | "security" | "accessControl" | "exposedFunctions"> & {
|
|
32
32
|
item: import("@aeriajs/types").SchemaWithId<{
|
|
33
33
|
readonly $id: "tempFile";
|
|
34
34
|
readonly temporary: {
|
|
@@ -499,7 +499,7 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
|
|
|
499
499
|
};
|
|
500
500
|
}>) => Promise<any>;
|
|
501
501
|
};
|
|
502
|
-
}>, "description" | "functions" | "item" | "security" | "accessControl"> & {
|
|
502
|
+
}>, "description" | "functions" | "item" | "security" | "accessControl" | "exposedFunctions"> & {
|
|
503
503
|
item: import("@aeriajs/types").SchemaWithId<{
|
|
504
504
|
readonly $id: "file";
|
|
505
505
|
readonly owned: "always";
|
|
@@ -4,7 +4,7 @@ exports.insert = void 0;
|
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
5
|
const promises_1 = require("fs/promises");
|
|
6
6
|
const core_1 = require("@aeriajs/core");
|
|
7
|
-
|
|
7
|
+
exports.insert = (0, core_1.defineExposedFunction)(async (payload, context) => {
|
|
8
8
|
if (!context.token.authenticated) {
|
|
9
9
|
throw new Error('');
|
|
10
10
|
}
|
|
@@ -40,5 +40,4 @@ const insert = async (payload, context) => {
|
|
|
40
40
|
...payload,
|
|
41
41
|
what,
|
|
42
42
|
}, context);
|
|
43
|
-
};
|
|
44
|
-
exports.insert = insert;
|
|
43
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { createHash } from "crypto";
|
|
3
3
|
import { writeFile, unlink } from "fs/promises";
|
|
4
|
-
import { insert as originalInsert } from "@aeriajs/core";
|
|
5
|
-
export const insert = async (payload, context) => {
|
|
4
|
+
import { defineExposedFunction, insert as originalInsert } from "@aeriajs/core";
|
|
5
|
+
export const insert = defineExposedFunction(async (payload, context) => {
|
|
6
6
|
if (!context.token.authenticated) {
|
|
7
7
|
throw new Error("");
|
|
8
8
|
}
|
|
@@ -39,4 +39,4 @@ export const insert = async (payload, context) => {
|
|
|
39
39
|
...payload,
|
|
40
40
|
what
|
|
41
41
|
}, context);
|
|
42
|
-
};
|
|
42
|
+
});
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.remove = void 0;
|
|
7
7
|
const core_1 = require("@aeriajs/core");
|
|
8
8
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
-
|
|
9
|
+
exports.remove = (0, core_1.defineExposedFunction)(async (payload, context) => {
|
|
10
10
|
const file = await context.collection.model.findOne({
|
|
11
11
|
_id: payload.filters._id,
|
|
12
12
|
}, {
|
|
@@ -24,5 +24,4 @@ const remove = async (payload, context) => {
|
|
|
24
24
|
console.trace(err);
|
|
25
25
|
}
|
|
26
26
|
return (0, core_1.remove)(payload, context);
|
|
27
|
-
};
|
|
28
|
-
exports.remove = remove;
|
|
27
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { remove as originalRemove } from "@aeriajs/core";
|
|
2
|
+
import { defineExposedFunction, remove as originalRemove } from "@aeriajs/core";
|
|
3
3
|
import fs from "fs/promises";
|
|
4
|
-
export const remove = async (payload, context) => {
|
|
4
|
+
export const remove = defineExposedFunction(async (payload, context) => {
|
|
5
5
|
const file = await context.collection.model.findOne({
|
|
6
6
|
_id: payload.filters._id
|
|
7
7
|
}, {
|
|
@@ -18,4 +18,4 @@ export const remove = async (payload, context) => {
|
|
|
18
18
|
console.trace(err);
|
|
19
19
|
}
|
|
20
20
|
return originalRemove(payload, context);
|
|
21
|
-
};
|
|
21
|
+
});
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.removeAll = void 0;
|
|
7
7
|
const core_1 = require("@aeriajs/core");
|
|
8
8
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
-
|
|
9
|
+
exports.removeAll = (0, core_1.defineExposedFunction)(async (payload, context) => {
|
|
10
10
|
const files = context.collection.model.find({
|
|
11
11
|
_id: {
|
|
12
12
|
$in: payload.filters,
|
|
@@ -25,6 +25,5 @@ const removeAll = async (payload, context) => {
|
|
|
25
25
|
console.trace(err);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
return (0, core_1.
|
|
29
|
-
};
|
|
30
|
-
exports.removeAll = removeAll;
|
|
28
|
+
return (0, core_1.remove)(payload, context);
|
|
29
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
2
|
+
import { defineExposedFunction, remove as originalRemoveAll } from "@aeriajs/core";
|
|
3
3
|
import fs from "fs/promises";
|
|
4
|
-
export const removeAll = async (payload, context) => {
|
|
4
|
+
export const removeAll = defineExposedFunction(async (payload, context) => {
|
|
5
5
|
const files = context.collection.model.find({
|
|
6
6
|
_id: {
|
|
7
7
|
$in: payload.filters
|
|
@@ -20,4 +20,4 @@ export const removeAll = async (payload, context) => {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
return originalRemoveAll(payload, context);
|
|
23
|
-
};
|
|
23
|
+
});
|
|
@@ -31,7 +31,7 @@ export declare const log: Omit<import("@aeriajs/types").Collection<{
|
|
|
31
31
|
readonly getAll: <TContext_1 extends import("@aeriajs/types").Context>(_payload: import("@aeriajs/types").GetAllPayload<import("@aeriajs/types").SchemaWithId<any>> | undefined, context: TContext_1, options?: import("@aeriajs/core").GetAllOptions | undefined) => Promise<import("@aeriajs/types").SchemaWithId<TContext_1["description"]>[]>;
|
|
32
32
|
readonly insert: <TContext_2 extends import("@aeriajs/types").Context>(payload: import("@aeriajs/types").InsertPayload<import("@aeriajs/types").SchemaWithId<TContext_2["description"]>>, context: TContext_2, options?: import("@aeriajs/core").InsertOptions | undefined) => Promise<import("@aeriajs/types").Left<import("@aeriajs/types").ACErrors | import("@aeriajs/types").ValidationError> | import("@aeriajs/types").Right<import("@aeriajs/types").SchemaWithId<TContext_2["description"]>>>;
|
|
33
33
|
};
|
|
34
|
-
}>, "description" | "functions" | "item" | "security" | "accessControl"> & {
|
|
34
|
+
}>, "description" | "functions" | "item" | "security" | "accessControl" | "exposedFunctions"> & {
|
|
35
35
|
item: import("@aeriajs/types").SchemaWithId<{
|
|
36
36
|
readonly $id: "log";
|
|
37
37
|
readonly required: readonly ["context", "message"];
|
|
@@ -33,7 +33,7 @@ export declare const resourceUsage: Omit<import("@aeriajs/types").Collection<{
|
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
|
-
}>, "description" | "functions" | "item" | "security" | "accessControl"> & {
|
|
36
|
+
}>, "description" | "functions" | "item" | "security" | "accessControl" | "exposedFunctions"> & {
|
|
37
37
|
item: import("@aeriajs/types").SchemaWithId<{
|
|
38
38
|
readonly $id: "resourceUsage";
|
|
39
39
|
readonly required: readonly ["usage"];
|
|
@@ -7,4 +7,4 @@ export declare enum ActivationErrors {
|
|
|
7
7
|
}
|
|
8
8
|
export declare const activate: (payload: {
|
|
9
9
|
password: string;
|
|
10
|
-
}, context: Context<typeof description>) => Promise<import("@aeriajs/types").
|
|
10
|
+
}, context: Context<typeof description>) => Promise<import("@aeriajs/types").Left<ActivationErrors.InvalidLink> | import("@aeriajs/types").Left<ActivationErrors.UserNotFound> | import("@aeriajs/types").Left<ActivationErrors.AlreadyActiveUser> | import("@aeriajs/types").GenericResponse | import("@aeriajs/types").Right<true>>;
|
|
@@ -13,7 +13,7 @@ var ActivationErrors;
|
|
|
13
13
|
ActivationErrors["AlreadyActiveUser"] = "ALREADY_ACTIVE_USER";
|
|
14
14
|
ActivationErrors["InvalidLink"] = "INVALID_LINK";
|
|
15
15
|
})(ActivationErrors || (exports.ActivationErrors = ActivationErrors = {}));
|
|
16
|
-
|
|
16
|
+
exports.activate = (0, core_1.defineExposedFunction)(async (payload, context) => {
|
|
17
17
|
const { u: userId, t: token, } = context.request.query;
|
|
18
18
|
if (!userId || !token) {
|
|
19
19
|
return (0, common_1.left)(ActivationErrors.InvalidLink);
|
|
@@ -61,5 +61,4 @@ const activate = async (payload, context) => {
|
|
|
61
61
|
return context.response.writeHead(302, {
|
|
62
62
|
location: '/user/activation',
|
|
63
63
|
});
|
|
64
|
-
};
|
|
65
|
-
exports.activate = activate;
|
|
64
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { ObjectId } from "@aeriajs/core";
|
|
2
|
+
import { defineExposedFunction, ObjectId } from "@aeriajs/core";
|
|
3
3
|
import { left, right } from "@aeriajs/common";
|
|
4
4
|
import bcrypt from "bcrypt";
|
|
5
5
|
export var ActivationErrors = /* @__PURE__ */ ((ActivationErrors2) => {
|
|
@@ -8,7 +8,7 @@ export var ActivationErrors = /* @__PURE__ */ ((ActivationErrors2) => {
|
|
|
8
8
|
ActivationErrors2["InvalidLink"] = "INVALID_LINK";
|
|
9
9
|
return ActivationErrors2;
|
|
10
10
|
})(ActivationErrors || {});
|
|
11
|
-
export const activate = async (payload, context) => {
|
|
11
|
+
export const activate = defineExposedFunction(async (payload, context) => {
|
|
12
12
|
const {
|
|
13
13
|
u: userId,
|
|
14
14
|
t: token
|
|
@@ -65,4 +65,4 @@ export const activate = async (payload, context) => {
|
|
|
65
65
|
return context.response.writeHead(302, {
|
|
66
66
|
location: "/user/activation"
|
|
67
67
|
});
|
|
68
|
-
};
|
|
68
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Context, SchemaWithId, TokenRecipient } from '@aeriajs/types';
|
|
2
2
|
import type { description } from './description.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type ObjectId } from '@aeriajs/core';
|
|
4
4
|
type Props = {
|
|
5
5
|
email: string;
|
|
6
6
|
password: string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.authenticate = exports.getDefaultUser = exports.AuthenticationErrors = void 0;
|
|
4
|
-
const bcrypt_1 = require("bcrypt");
|
|
5
4
|
const core_1 = require("@aeriajs/core");
|
|
5
|
+
const bcrypt_1 = require("bcrypt");
|
|
6
|
+
const core_2 = require("@aeriajs/core");
|
|
6
7
|
const common_1 = require("@aeriajs/common");
|
|
7
8
|
var AuthenticationErrors;
|
|
8
9
|
(function (AuthenticationErrors) {
|
|
@@ -25,17 +26,15 @@ const getUser = async (userId, context) => {
|
|
|
25
26
|
roles: leanUser.roles,
|
|
26
27
|
userinfo: {},
|
|
27
28
|
};
|
|
28
|
-
if (context.config.security) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
}
|
|
29
|
+
if (context.config.security.authenticationRateLimiting) {
|
|
30
|
+
//
|
|
31
|
+
}
|
|
32
|
+
if (context.config.security.logSuccessfulAuthentications) {
|
|
33
|
+
await context.log('successful authentication', {
|
|
34
|
+
email: leanUser.email,
|
|
35
|
+
roles: leanUser.roles,
|
|
36
|
+
_id: leanUser._id,
|
|
37
|
+
});
|
|
39
38
|
}
|
|
40
39
|
if (context.config.tokenUserProperties) {
|
|
41
40
|
const pick = (obj, properties) => properties.reduce((a, prop) => {
|
|
@@ -49,7 +48,7 @@ const getUser = async (userId, context) => {
|
|
|
49
48
|
}, {});
|
|
50
49
|
tokenContent.userinfo = pick(leanUser, context.config.tokenUserProperties);
|
|
51
50
|
}
|
|
52
|
-
const token = await (0,
|
|
51
|
+
const token = await (0, core_2.signToken)(tokenContent);
|
|
53
52
|
return {
|
|
54
53
|
user: leanUser,
|
|
55
54
|
token: {
|
|
@@ -59,7 +58,7 @@ const getUser = async (userId, context) => {
|
|
|
59
58
|
};
|
|
60
59
|
};
|
|
61
60
|
const getDefaultUser = async () => {
|
|
62
|
-
const token = await (0,
|
|
61
|
+
const token = await (0, core_2.signToken)({
|
|
63
62
|
_id: null,
|
|
64
63
|
roles: ['root'],
|
|
65
64
|
userinfo: {},
|
|
@@ -86,7 +85,7 @@ const authenticate = async (props, context) => {
|
|
|
86
85
|
return (0, common_1.left)(AuthenticationErrors.Unauthenticated);
|
|
87
86
|
}
|
|
88
87
|
const decodedToken = token
|
|
89
|
-
? await (0,
|
|
88
|
+
? await (0, core_2.decodeToken)(token.content)
|
|
90
89
|
: context.token;
|
|
91
90
|
return (0, common_1.right)(decodedToken.sub
|
|
92
91
|
? await getUser(decodedToken.sub, context)
|
|
@@ -118,3 +117,6 @@ const authenticate = async (props, context) => {
|
|
|
118
117
|
return (0, common_1.right)(await getUser(user._id, context));
|
|
119
118
|
};
|
|
120
119
|
exports.authenticate = authenticate;
|
|
120
|
+
(0, core_1.defineFunctionAttributes)(exports.authenticate, {
|
|
121
|
+
exposed: true,
|
|
122
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
import { defineFunctionAttributes } from "@aeriajs/core";
|
|
2
3
|
import { compare as bcryptCompare } from "bcrypt";
|
|
3
4
|
import { signToken, decodeToken } from "@aeriajs/core";
|
|
4
5
|
import { left, right } from "@aeriajs/common";
|
|
@@ -23,16 +24,14 @@ const getUser = async (userId, context) => {
|
|
|
23
24
|
roles: leanUser.roles,
|
|
24
25
|
userinfo: {}
|
|
25
26
|
};
|
|
26
|
-
if (context.config.security) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
}
|
|
27
|
+
if (context.config.security.authenticationRateLimiting) {
|
|
28
|
+
}
|
|
29
|
+
if (context.config.security.logSuccessfulAuthentications) {
|
|
30
|
+
await context.log("successful authentication", {
|
|
31
|
+
email: leanUser.email,
|
|
32
|
+
roles: leanUser.roles,
|
|
33
|
+
_id: leanUser._id
|
|
34
|
+
});
|
|
36
35
|
}
|
|
37
36
|
if (context.config.tokenUserProperties) {
|
|
38
37
|
const pick = (obj, properties) => properties.reduce((a, prop) => {
|
|
@@ -112,3 +111,6 @@ export const authenticate = async (props, context) => {
|
|
|
112
111
|
}
|
|
113
112
|
return right(await getUser(user._id, context));
|
|
114
113
|
};
|
|
114
|
+
defineFunctionAttributes(authenticate, {
|
|
115
|
+
exposed: true
|
|
116
|
+
});
|
|
@@ -4,12 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createAccount = void 0;
|
|
7
|
+
const core_1 = require("@aeriajs/core");
|
|
7
8
|
const common_1 = require("@aeriajs/common");
|
|
8
9
|
const validation_1 = require("@aeriajs/validation");
|
|
9
10
|
const bcrypt_1 = __importDefault(require("bcrypt"));
|
|
10
|
-
|
|
11
|
+
exports.createAccount = (0, core_1.defineExposedFunction)(async (payload, context) => {
|
|
11
12
|
const user = Object.assign({}, payload);
|
|
12
|
-
if (!context.config.allowSignup) {
|
|
13
|
+
if (!context.config.security.allowSignup) {
|
|
13
14
|
throw new Error('signup disallowed');
|
|
14
15
|
}
|
|
15
16
|
const validationEither = (0, validation_1.validate)(user, {
|
|
@@ -43,8 +44,8 @@ const createAccount = async (payload, context) => {
|
|
|
43
44
|
if ((0, common_1.isLeft)(validationEither)) {
|
|
44
45
|
return (0, common_1.left)((0, common_1.unwrapEither)(validationEither));
|
|
45
46
|
}
|
|
46
|
-
if (context.config.signupDefaults) {
|
|
47
|
-
Object.assign(user, context.config.signupDefaults);
|
|
47
|
+
if (context.config.security.signupDefaults) {
|
|
48
|
+
Object.assign(user, context.config.security.signupDefaults);
|
|
48
49
|
}
|
|
49
50
|
if (user.password) {
|
|
50
51
|
user.password = await bcrypt_1.default.hash(user.password, 10);
|
|
@@ -62,5 +63,4 @@ const createAccount = async (payload, context) => {
|
|
|
62
63
|
throw new Error();
|
|
63
64
|
}
|
|
64
65
|
return (0, common_1.right)(newUser);
|
|
65
|
-
};
|
|
66
|
-
exports.createAccount = createAccount;
|
|
66
|
+
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
import { defineExposedFunction } from "@aeriajs/core";
|
|
2
3
|
import { isLeft, unwrapEither, left, right } from "@aeriajs/common";
|
|
3
4
|
import { validate } from "@aeriajs/validation";
|
|
4
5
|
import bcrypt from "bcrypt";
|
|
5
|
-
export const createAccount = async (payload, context) => {
|
|
6
|
+
export const createAccount = defineExposedFunction(async (payload, context) => {
|
|
6
7
|
const user = Object.assign({}, payload);
|
|
7
|
-
if (!context.config.allowSignup) {
|
|
8
|
+
if (!context.config.security.allowSignup) {
|
|
8
9
|
throw new Error("signup disallowed");
|
|
9
10
|
}
|
|
10
11
|
const validationEither = validate(user, {
|
|
@@ -38,8 +39,8 @@ export const createAccount = async (payload, context) => {
|
|
|
38
39
|
if (isLeft(validationEither)) {
|
|
39
40
|
return left(unwrapEither(validationEither));
|
|
40
41
|
}
|
|
41
|
-
if (context.config.signupDefaults) {
|
|
42
|
-
Object.assign(user, context.config.signupDefaults);
|
|
42
|
+
if (context.config.security.signupDefaults) {
|
|
43
|
+
Object.assign(user, context.config.security.signupDefaults);
|
|
43
44
|
}
|
|
44
45
|
if (user.password) {
|
|
45
46
|
user.password = await bcrypt.hash(user.password, 10);
|
|
@@ -57,4 +58,4 @@ export const createAccount = async (payload, context) => {
|
|
|
57
58
|
throw new Error();
|
|
58
59
|
}
|
|
59
60
|
return right(newUser);
|
|
60
|
-
};
|
|
61
|
+
});
|
|
@@ -72,7 +72,6 @@ export declare const description: {
|
|
|
72
72
|
readonly picture: "picture_file";
|
|
73
73
|
readonly information: "email";
|
|
74
74
|
readonly active: "active";
|
|
75
|
-
readonly translateBadge: true;
|
|
76
75
|
};
|
|
77
76
|
};
|
|
78
77
|
readonly individualActions: {
|
|
@@ -84,8 +83,8 @@ export declare const description: {
|
|
|
84
83
|
readonly 'route:/dashboard/user/changepass': {
|
|
85
84
|
readonly name: "change_password";
|
|
86
85
|
readonly icon: "key";
|
|
87
|
-
readonly translate: true;
|
|
88
86
|
readonly fetchItem: true;
|
|
87
|
+
readonly translate: true;
|
|
89
88
|
};
|
|
90
89
|
};
|
|
91
90
|
readonly icon: "users";
|
|
@@ -104,7 +104,6 @@ exports.description = (0, core_1.defineDescription)({
|
|
|
104
104
|
picture: 'picture_file',
|
|
105
105
|
information: 'email',
|
|
106
106
|
active: 'active',
|
|
107
|
-
translateBadge: true,
|
|
108
107
|
},
|
|
109
108
|
},
|
|
110
109
|
individualActions: {
|
|
@@ -116,8 +115,8 @@ exports.description = (0, core_1.defineDescription)({
|
|
|
116
115
|
'route:/dashboard/user/changepass': {
|
|
117
116
|
name: 'change_password',
|
|
118
117
|
icon: 'key',
|
|
119
|
-
translate: true,
|
|
120
118
|
fetchItem: true,
|
|
119
|
+
translate: true,
|
|
121
120
|
},
|
|
122
121
|
},
|
|
123
122
|
icon: 'users',
|
|
@@ -97,8 +97,7 @@ export const description = defineDescription({
|
|
|
97
97
|
badge: "roles",
|
|
98
98
|
picture: "picture_file",
|
|
99
99
|
information: "email",
|
|
100
|
-
active: "active"
|
|
101
|
-
translateBadge: true
|
|
100
|
+
active: "active"
|
|
102
101
|
}
|
|
103
102
|
},
|
|
104
103
|
individualActions: {
|
|
@@ -110,8 +109,8 @@ export const description = defineDescription({
|
|
|
110
109
|
"route:/dashboard/user/changepass": {
|
|
111
110
|
name: "change_password",
|
|
112
111
|
icon: "key",
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
fetchItem: true,
|
|
113
|
+
translate: true
|
|
115
114
|
}
|
|
116
115
|
},
|
|
117
116
|
icon: "users",
|
|
@@ -13,7 +13,7 @@ var ActivationErrors;
|
|
|
13
13
|
ActivationErrors["AlreadyActiveUser"] = "ALREADY_ACTIVE_USER";
|
|
14
14
|
ActivationErrors["InvalidLink"] = "INVALID_LINK";
|
|
15
15
|
})(ActivationErrors || (exports.ActivationErrors = ActivationErrors = {}));
|
|
16
|
-
|
|
16
|
+
exports.getInfo = (0, core_1.defineExposedFunction)(async (payload, context) => {
|
|
17
17
|
const { userId, token, } = payload;
|
|
18
18
|
if (!userId || !token) {
|
|
19
19
|
return (0, common_1.left)(ActivationErrors.InvalidLink);
|
|
@@ -35,5 +35,4 @@ const getInfo = async (payload, context) => {
|
|
|
35
35
|
name: user.name,
|
|
36
36
|
email: user.email,
|
|
37
37
|
});
|
|
38
|
-
};
|
|
39
|
-
exports.getInfo = getInfo;
|
|
38
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { ObjectId } from "@aeriajs/core";
|
|
2
|
+
import { defineExposedFunction, ObjectId } from "@aeriajs/core";
|
|
3
3
|
import { left, right } from "@aeriajs/common";
|
|
4
4
|
import bcrypt from "bcrypt";
|
|
5
5
|
export var ActivationErrors = /* @__PURE__ */ ((ActivationErrors2) => {
|
|
@@ -8,7 +8,7 @@ export var ActivationErrors = /* @__PURE__ */ ((ActivationErrors2) => {
|
|
|
8
8
|
ActivationErrors2["InvalidLink"] = "INVALID_LINK";
|
|
9
9
|
return ActivationErrors2;
|
|
10
10
|
})(ActivationErrors || {});
|
|
11
|
-
export const getInfo = async (payload, context) => {
|
|
11
|
+
export const getInfo = defineExposedFunction(async (payload, context) => {
|
|
12
12
|
const {
|
|
13
13
|
userId,
|
|
14
14
|
token
|
|
@@ -33,4 +33,4 @@ export const getInfo = async (payload, context) => {
|
|
|
33
33
|
name: user.name,
|
|
34
34
|
email: user.email
|
|
35
35
|
});
|
|
36
|
-
};
|
|
36
|
+
});
|