@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.
- package/dist/collections/file/download.d.ts +6 -5
- package/dist/collections/file/download.js +8 -9
- package/dist/collections/file/download.mjs +7 -8
- package/dist/collections/file/index.d.ts +14 -6
- package/dist/collections/file/insert.d.ts +1 -1
- package/dist/collections/log/index.d.ts +6 -6
- package/dist/collections/user/activate.d.ts +15 -2
- package/dist/collections/user/activate.js +21 -13
- package/dist/collections/user/activate.mjs +20 -12
- package/dist/collections/user/authenticate.d.ts +17 -5
- package/dist/collections/user/authenticate.js +26 -18
- package/dist/collections/user/authenticate.mjs +23 -15
- package/dist/collections/user/createAccount.d.ts +1 -1
- package/dist/collections/user/createAccount.js +6 -2
- package/dist/collections/user/createAccount.mjs +7 -3
- package/dist/collections/user/getCurrentUser.d.ts +4 -4
- package/dist/collections/user/getCurrentUser.js +10 -10
- package/dist/collections/user/getCurrentUser.mjs +10 -10
- package/dist/collections/user/getInfo.d.ts +18 -5
- package/dist/collections/user/getInfo.js +22 -14
- package/dist/collections/user/getInfo.mjs +21 -13
- package/dist/collections/user/index.d.ts +118 -64
- package/dist/collections/user/index.js +3 -10
- package/dist/collections/user/index.mjs +3 -10
- package/dist/collections/user/insert.d.ts +1 -1
- package/dist/functions/describe.d.ts +124 -113
- package/dist/functions/describe.js +3 -5
- package/dist/functions/describe.mjs +4 -6
- package/dist/index.d.ts +138 -76
- package/package.json +6 -6
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Context } from '@aeriajs/types';
|
|
3
3
|
import type { description } from './description.js';
|
|
4
|
+
import { HTTPStatus, ACError } from '@aeriajs/types';
|
|
4
5
|
import * as fs from 'fs';
|
|
5
|
-
export declare enum FileReadError {
|
|
6
|
-
DocumentNotFound = "DOCUMENT_NOT_FOUND",
|
|
7
|
-
FileNotFound = "FILE_NOT_FOUND"
|
|
8
|
-
}
|
|
9
6
|
export declare const download: (payload: {
|
|
10
7
|
fileId: string;
|
|
11
8
|
options: readonly ('picture' | 'download')[];
|
|
12
9
|
noHeaders?: boolean;
|
|
13
|
-
}, context: Context<typeof description>) => Promise<import("@aeriajs/types").
|
|
10
|
+
}, context: Context<typeof description>) => Promise<import("@aeriajs/types").EndpointError<{
|
|
11
|
+
readonly code: ACError.ResourceNotFound;
|
|
12
|
+
} & {
|
|
13
|
+
httpStatus: HTTPStatus.NotFound;
|
|
14
|
+
}> | fs.ReadStream>;
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.download =
|
|
3
|
+
exports.download = void 0;
|
|
4
|
+
const types_1 = require("@aeriajs/types");
|
|
4
5
|
const core_1 = require("@aeriajs/core");
|
|
5
|
-
const common_1 = require("@aeriajs/common");
|
|
6
6
|
const fs = require("fs");
|
|
7
|
-
var FileReadError;
|
|
8
|
-
(function (FileReadError) {
|
|
9
|
-
FileReadError["DocumentNotFound"] = "DOCUMENT_NOT_FOUND";
|
|
10
|
-
FileReadError["FileNotFound"] = "FILE_NOT_FOUND";
|
|
11
|
-
})(FileReadError || (exports.FileReadError = FileReadError = {}));
|
|
12
7
|
const download = async (payload, context) => {
|
|
13
8
|
const { fileId, options = [] } = payload;
|
|
14
9
|
const file = await context.collection.model.findOne({
|
|
@@ -26,7 +21,9 @@ const download = async (payload, context) => {
|
|
|
26
21
|
'content-type': 'application/json',
|
|
27
22
|
});
|
|
28
23
|
}
|
|
29
|
-
return (
|
|
24
|
+
return context.error(types_1.HTTPStatus.NotFound, {
|
|
25
|
+
code: types_1.ACError.ResourceNotFound,
|
|
26
|
+
});
|
|
30
27
|
}
|
|
31
28
|
let stat;
|
|
32
29
|
try {
|
|
@@ -36,7 +33,9 @@ const download = async (payload, context) => {
|
|
|
36
33
|
context.response.writeHead(404, {
|
|
37
34
|
'content-type': 'application/json',
|
|
38
35
|
});
|
|
39
|
-
return (
|
|
36
|
+
return context.error(types_1.HTTPStatus.NotFound, {
|
|
37
|
+
code: types_1.ACError.ResourceNotFound,
|
|
38
|
+
});
|
|
40
39
|
}
|
|
41
40
|
const range = context.request.headers.range;
|
|
42
41
|
if (typeof range === 'string') {
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
import { HTTPStatus, ACError } from "@aeriajs/types";
|
|
2
3
|
import { ObjectId } from "@aeriajs/core";
|
|
3
|
-
import { left } from "@aeriajs/common";
|
|
4
4
|
import * as fs from "fs";
|
|
5
|
-
export var FileReadError = /* @__PURE__ */ ((FileReadError2) => {
|
|
6
|
-
FileReadError2["DocumentNotFound"] = "DOCUMENT_NOT_FOUND";
|
|
7
|
-
FileReadError2["FileNotFound"] = "FILE_NOT_FOUND";
|
|
8
|
-
return FileReadError2;
|
|
9
|
-
})(FileReadError || {});
|
|
10
5
|
export const download = async (payload, context) => {
|
|
11
6
|
const { fileId, options = [] } = payload;
|
|
12
7
|
const file = await context.collection.model.findOne({
|
|
@@ -24,7 +19,9 @@ export const download = async (payload, context) => {
|
|
|
24
19
|
"content-type": "application/json"
|
|
25
20
|
});
|
|
26
21
|
}
|
|
27
|
-
return
|
|
22
|
+
return context.error(HTTPStatus.NotFound, {
|
|
23
|
+
code: ACError.ResourceNotFound
|
|
24
|
+
});
|
|
28
25
|
}
|
|
29
26
|
let stat;
|
|
30
27
|
try {
|
|
@@ -33,7 +30,9 @@ export const download = async (payload, context) => {
|
|
|
33
30
|
context.response.writeHead(404, {
|
|
34
31
|
"content-type": "application/json"
|
|
35
32
|
});
|
|
36
|
-
return
|
|
33
|
+
return context.error(HTTPStatus.NotFound, {
|
|
34
|
+
code: ACError.ResourceNotFound
|
|
35
|
+
});
|
|
37
36
|
}
|
|
38
37
|
const range = context.request.headers.range;
|
|
39
38
|
if (typeof range === "string") {
|
|
@@ -142,7 +142,7 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
|
|
|
142
142
|
};
|
|
143
143
|
};
|
|
144
144
|
functions: {
|
|
145
|
-
readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<
|
|
145
|
+
readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<any>;
|
|
146
146
|
readonly insert: (payload: {
|
|
147
147
|
what: {
|
|
148
148
|
content: string;
|
|
@@ -245,7 +245,7 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
|
|
|
245
245
|
readonly ask: true;
|
|
246
246
|
};
|
|
247
247
|
};
|
|
248
|
-
}>) => Promise<import("@aeriajs/types").
|
|
248
|
+
}>) => Promise<import("@aeriajs/types").InsertReturnType<import("@aeriajs/types").SchemaWithId<{
|
|
249
249
|
readonly $id: "file";
|
|
250
250
|
readonly owned: "always";
|
|
251
251
|
readonly presets: readonly ["owned"];
|
|
@@ -348,7 +348,11 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
|
|
|
348
348
|
readonly ask: true;
|
|
349
349
|
};
|
|
350
350
|
};
|
|
351
|
-
}>) => Promise<import("@aeriajs/types").
|
|
351
|
+
}>) => Promise<import("@aeriajs/types").EndpointError<{
|
|
352
|
+
readonly code: import("@aeriajs/types").ACError.ResourceNotFound;
|
|
353
|
+
} & {
|
|
354
|
+
httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
|
|
355
|
+
}> | import("fs").ReadStream>;
|
|
352
356
|
readonly remove: (payload: import("@aeriajs/types").RemovePayload<import("@aeriajs/types").SchemaWithId<{
|
|
353
357
|
readonly $id: "file";
|
|
354
358
|
readonly owned: "always";
|
|
@@ -608,7 +612,7 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
|
|
|
608
612
|
};
|
|
609
613
|
};
|
|
610
614
|
functions: {
|
|
611
|
-
readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<
|
|
615
|
+
readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<any>;
|
|
612
616
|
readonly insert: (payload: {
|
|
613
617
|
what: {
|
|
614
618
|
content: string;
|
|
@@ -711,7 +715,7 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
|
|
|
711
715
|
readonly ask: true;
|
|
712
716
|
};
|
|
713
717
|
};
|
|
714
|
-
}>) => Promise<import("@aeriajs/types").
|
|
718
|
+
}>) => Promise<import("@aeriajs/types").InsertReturnType<import("@aeriajs/types").SchemaWithId<{
|
|
715
719
|
readonly $id: "file";
|
|
716
720
|
readonly owned: "always";
|
|
717
721
|
readonly presets: readonly ["owned"];
|
|
@@ -814,7 +818,11 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
|
|
|
814
818
|
readonly ask: true;
|
|
815
819
|
};
|
|
816
820
|
};
|
|
817
|
-
}>) => Promise<import("@aeriajs/types").
|
|
821
|
+
}>) => Promise<import("@aeriajs/types").EndpointError<{
|
|
822
|
+
readonly code: import("@aeriajs/types").ACError.ResourceNotFound;
|
|
823
|
+
} & {
|
|
824
|
+
httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
|
|
825
|
+
}> | import("fs").ReadStream>;
|
|
818
826
|
readonly remove: (payload: import("@aeriajs/types").RemovePayload<import("@aeriajs/types").SchemaWithId<{
|
|
819
827
|
readonly $id: "file";
|
|
820
828
|
readonly owned: "always";
|
|
@@ -4,7 +4,7 @@ export declare const insert: (payload: {
|
|
|
4
4
|
what: {
|
|
5
5
|
content: string;
|
|
6
6
|
} & Pick<PackReferences<SchemaWithId<typeof description>>, '_id' | 'name' | 'owner' | 'absolute_path'>;
|
|
7
|
-
}, context: Context<typeof description>) => Promise<import("@aeriajs/types").
|
|
7
|
+
}, context: Context<typeof description>) => Promise<import("@aeriajs/types").InsertReturnType<SchemaWithId<{
|
|
8
8
|
readonly $id: "file";
|
|
9
9
|
readonly owned: "always";
|
|
10
10
|
readonly presets: readonly ["owned"];
|
|
@@ -27,9 +27,9 @@ export declare const log: Omit<import("@aeriajs/types").Collection<{
|
|
|
27
27
|
readonly filters: readonly ["context", "message", "owner"];
|
|
28
28
|
};
|
|
29
29
|
functions: {
|
|
30
|
-
readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<
|
|
31
|
-
readonly getAll: (_payload: import("@aeriajs/types").GetAllPayload<import("@aeriajs/types").SchemaWithId<
|
|
32
|
-
readonly insert: (payload: import("@aeriajs/types").InsertPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").InsertOptions | undefined) => Promise<import("@aeriajs/types").
|
|
30
|
+
readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<any>;
|
|
31
|
+
readonly getAll: (_payload: import("@aeriajs/types").GetAllPayload<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>> | undefined, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetAllOptions | undefined) => Promise<import("@aeriajs/types").SchemaWithId<any>[]>;
|
|
32
|
+
readonly insert: (payload: import("@aeriajs/types").InsertPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").InsertOptions | undefined) => Promise<import("@aeriajs/types").InsertReturnType<import("@aeriajs/types").SchemaWithId<any>>>;
|
|
33
33
|
};
|
|
34
34
|
exposedFunctions: {
|
|
35
35
|
readonly get: true;
|
|
@@ -92,9 +92,9 @@ export declare const log: Omit<import("@aeriajs/types").Collection<{
|
|
|
92
92
|
readonly filters: readonly ["context", "message", "owner"];
|
|
93
93
|
};
|
|
94
94
|
functions: {
|
|
95
|
-
readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<
|
|
96
|
-
readonly getAll: (_payload: import("@aeriajs/types").GetAllPayload<import("@aeriajs/types").SchemaWithId<
|
|
97
|
-
readonly insert: (payload: import("@aeriajs/types").InsertPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").InsertOptions | undefined) => Promise<import("@aeriajs/types").
|
|
95
|
+
readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<any>;
|
|
96
|
+
readonly getAll: (_payload: import("@aeriajs/types").GetAllPayload<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>> | undefined, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetAllOptions | undefined) => Promise<import("@aeriajs/types").SchemaWithId<any>[]>;
|
|
97
|
+
readonly insert: (payload: import("@aeriajs/types").InsertPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").InsertOptions | undefined) => Promise<import("@aeriajs/types").InsertReturnType<import("@aeriajs/types").SchemaWithId<any>>>;
|
|
98
98
|
};
|
|
99
99
|
contracts: {
|
|
100
100
|
readonly get?: import("@aeriajs/types").Contract | undefined;
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import type { Context } from '@aeriajs/types';
|
|
2
2
|
import type { description } from './description.js';
|
|
3
|
-
|
|
3
|
+
import { HTTPStatus } from '@aeriajs/types';
|
|
4
|
+
export declare enum ActivationError {
|
|
4
5
|
UserNotFound = "USER_NOT_FOUND",
|
|
5
6
|
AlreadyActiveUser = "ALREADY_ACTIVE_USER",
|
|
6
7
|
InvalidLink = "INVALID_LINK"
|
|
7
8
|
}
|
|
8
9
|
export declare const activate: (payload: {
|
|
9
10
|
password: string;
|
|
10
|
-
}, context: Context<typeof description>) => Promise<import("@aeriajs/types").GenericResponse | import("@aeriajs/types").
|
|
11
|
+
}, context: Context<typeof description>) => Promise<import("@aeriajs/types").GenericResponse | import("@aeriajs/types").EndpointError<{
|
|
12
|
+
readonly code: ActivationError.InvalidLink;
|
|
13
|
+
} & {
|
|
14
|
+
httpStatus: HTTPStatus.NotFound;
|
|
15
|
+
}> | import("@aeriajs/types").EndpointError<{
|
|
16
|
+
readonly code: ActivationError.UserNotFound;
|
|
17
|
+
} & {
|
|
18
|
+
httpStatus: HTTPStatus.NotFound;
|
|
19
|
+
}> | import("@aeriajs/types").EndpointError<{
|
|
20
|
+
readonly code: ActivationError.AlreadyActiveUser;
|
|
21
|
+
} & {
|
|
22
|
+
httpStatus: HTTPStatus.Forbidden;
|
|
23
|
+
}> | undefined>;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.activate = exports.
|
|
3
|
+
exports.activate = exports.ActivationError = void 0;
|
|
4
4
|
const core_1 = require("@aeriajs/core");
|
|
5
|
-
const
|
|
5
|
+
const types_1 = require("@aeriajs/types");
|
|
6
6
|
const bcrypt = require("bcrypt");
|
|
7
|
-
var
|
|
8
|
-
(function (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
})(
|
|
7
|
+
var ActivationError;
|
|
8
|
+
(function (ActivationError) {
|
|
9
|
+
ActivationError["UserNotFound"] = "USER_NOT_FOUND";
|
|
10
|
+
ActivationError["AlreadyActiveUser"] = "ALREADY_ACTIVE_USER";
|
|
11
|
+
ActivationError["InvalidLink"] = "INVALID_LINK";
|
|
12
|
+
})(ActivationError || (exports.ActivationError = ActivationError = {}));
|
|
13
13
|
const activate = async (payload, context) => {
|
|
14
14
|
const { u: userId, t: token, } = context.request.query;
|
|
15
15
|
if (!userId || !token) {
|
|
16
|
-
return (
|
|
16
|
+
return context.error(types_1.HTTPStatus.NotFound, {
|
|
17
|
+
code: ActivationError.InvalidLink,
|
|
18
|
+
});
|
|
17
19
|
}
|
|
18
20
|
const user = await context.collection.model.findOne({
|
|
19
21
|
_id: new core_1.ObjectId(userId),
|
|
@@ -23,14 +25,20 @@ const activate = async (payload, context) => {
|
|
|
23
25
|
},
|
|
24
26
|
});
|
|
25
27
|
if (!user) {
|
|
26
|
-
return (
|
|
28
|
+
return context.error(types_1.HTTPStatus.NotFound, {
|
|
29
|
+
code: ActivationError.UserNotFound,
|
|
30
|
+
});
|
|
27
31
|
}
|
|
28
32
|
if (user.active) {
|
|
29
|
-
return (
|
|
33
|
+
return context.error(types_1.HTTPStatus.Forbidden, {
|
|
34
|
+
code: ActivationError.AlreadyActiveUser,
|
|
35
|
+
});
|
|
30
36
|
}
|
|
31
37
|
const equal = await bcrypt.compare(user._id.toString(), token);
|
|
32
38
|
if (!equal) {
|
|
33
|
-
return (
|
|
39
|
+
return context.error(types_1.HTTPStatus.NotFound, {
|
|
40
|
+
code: ActivationError.InvalidLink,
|
|
41
|
+
});
|
|
34
42
|
}
|
|
35
43
|
if (!user.password) {
|
|
36
44
|
if (!payload.password) {
|
|
@@ -46,7 +54,7 @@ const activate = async (payload, context) => {
|
|
|
46
54
|
password: await bcrypt.hash(payload.password, 10),
|
|
47
55
|
},
|
|
48
56
|
});
|
|
49
|
-
return
|
|
57
|
+
return;
|
|
50
58
|
}
|
|
51
59
|
await context.collection.model.updateOne({
|
|
52
60
|
_id: user._id,
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { ObjectId } from "@aeriajs/core";
|
|
3
|
-
import {
|
|
3
|
+
import { HTTPStatus } from "@aeriajs/types";
|
|
4
4
|
import * as bcrypt from "bcrypt";
|
|
5
|
-
export var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return
|
|
10
|
-
})(
|
|
5
|
+
export var ActivationError = /* @__PURE__ */ ((ActivationError2) => {
|
|
6
|
+
ActivationError2["UserNotFound"] = "USER_NOT_FOUND";
|
|
7
|
+
ActivationError2["AlreadyActiveUser"] = "ALREADY_ACTIVE_USER";
|
|
8
|
+
ActivationError2["InvalidLink"] = "INVALID_LINK";
|
|
9
|
+
return ActivationError2;
|
|
10
|
+
})(ActivationError || {});
|
|
11
11
|
export const activate = async (payload, context) => {
|
|
12
12
|
const {
|
|
13
13
|
u: userId,
|
|
14
14
|
t: token
|
|
15
15
|
} = context.request.query;
|
|
16
16
|
if (!userId || !token) {
|
|
17
|
-
return
|
|
17
|
+
return context.error(HTTPStatus.NotFound, {
|
|
18
|
+
code: "INVALID_LINK" /* InvalidLink */
|
|
19
|
+
});
|
|
18
20
|
}
|
|
19
21
|
const user = await context.collection.model.findOne({
|
|
20
22
|
_id: new ObjectId(userId)
|
|
@@ -24,14 +26,20 @@ export const activate = async (payload, context) => {
|
|
|
24
26
|
}
|
|
25
27
|
});
|
|
26
28
|
if (!user) {
|
|
27
|
-
return
|
|
29
|
+
return context.error(HTTPStatus.NotFound, {
|
|
30
|
+
code: "USER_NOT_FOUND" /* UserNotFound */
|
|
31
|
+
});
|
|
28
32
|
}
|
|
29
33
|
if (user.active) {
|
|
30
|
-
return
|
|
34
|
+
return context.error(HTTPStatus.Forbidden, {
|
|
35
|
+
code: "ALREADY_ACTIVE_USER" /* AlreadyActiveUser */
|
|
36
|
+
});
|
|
31
37
|
}
|
|
32
38
|
const equal = await bcrypt.compare(user._id.toString(), token);
|
|
33
39
|
if (!equal) {
|
|
34
|
-
return
|
|
40
|
+
return context.error(HTTPStatus.NotFound, {
|
|
41
|
+
code: "INVALID_LINK" /* InvalidLink */
|
|
42
|
+
});
|
|
35
43
|
}
|
|
36
44
|
if (!user.password) {
|
|
37
45
|
if (!payload.password) {
|
|
@@ -50,7 +58,7 @@ export const activate = async (payload, context) => {
|
|
|
50
58
|
}
|
|
51
59
|
}
|
|
52
60
|
);
|
|
53
|
-
return
|
|
61
|
+
return;
|
|
54
62
|
}
|
|
55
63
|
await context.collection.model.updateOne(
|
|
56
64
|
{
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Context, SchemaWithId, TokenRecipient } from '@aeriajs/types';
|
|
2
2
|
import type { description } from './description.js';
|
|
3
|
-
import {
|
|
3
|
+
import type { ObjectId } from '@aeriajs/core';
|
|
4
|
+
import { HTTPStatus, ACError } from '@aeriajs/types';
|
|
4
5
|
type Props = {
|
|
5
6
|
email: string;
|
|
6
7
|
password: string;
|
|
@@ -14,8 +15,7 @@ type Return = {
|
|
|
14
15
|
};
|
|
15
16
|
token: TokenRecipient;
|
|
16
17
|
};
|
|
17
|
-
export declare enum
|
|
18
|
-
Unauthenticated = "UNAUTHENTICATED",
|
|
18
|
+
export declare enum AuthenticationError {
|
|
19
19
|
InvalidCredentials = "INVALID_CREDENTIALS",
|
|
20
20
|
InactiveUser = "INACTIVE_USER"
|
|
21
21
|
}
|
|
@@ -32,7 +32,11 @@ export declare const getDefaultUser: () => Promise<{
|
|
|
32
32
|
content: string;
|
|
33
33
|
};
|
|
34
34
|
}>;
|
|
35
|
-
export declare const authenticate: (props: Props, context: Context<typeof description>) => Promise<
|
|
35
|
+
export declare const authenticate: (props: Props, context: Context<typeof description>) => Promise<Return | import("@aeriajs/types").EndpointError<{
|
|
36
|
+
readonly code: ACError.AuthorizationError;
|
|
37
|
+
} & {
|
|
38
|
+
httpStatus: HTTPStatus.Unauthorized;
|
|
39
|
+
}> | {
|
|
36
40
|
user: {
|
|
37
41
|
_id: null;
|
|
38
42
|
name: string;
|
|
@@ -44,5 +48,13 @@ export declare const authenticate: (props: Props, context: Context<typeof descri
|
|
|
44
48
|
type: string;
|
|
45
49
|
content: string;
|
|
46
50
|
};
|
|
47
|
-
}
|
|
51
|
+
} | import("@aeriajs/types").EndpointError<{
|
|
52
|
+
readonly code: AuthenticationError.InvalidCredentials;
|
|
53
|
+
} & {
|
|
54
|
+
httpStatus: HTTPStatus.Unauthorized;
|
|
55
|
+
}> | import("@aeriajs/types").EndpointError<{
|
|
56
|
+
readonly code: AuthenticationError.InactiveUser;
|
|
57
|
+
} & {
|
|
58
|
+
httpStatus: HTTPStatus.Unauthorized;
|
|
59
|
+
}>>;
|
|
48
60
|
export {};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.authenticate = exports.getDefaultUser = exports.
|
|
3
|
+
exports.authenticate = exports.getDefaultUser = exports.AuthenticationError = void 0;
|
|
4
|
+
const types_1 = require("@aeriajs/types");
|
|
5
|
+
const common_1 = require("@aeriajs/common");
|
|
4
6
|
const bcrypt_1 = require("bcrypt");
|
|
5
7
|
const core_1 = require("@aeriajs/core");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
AuthenticationErrors["InactiveUser"] = "INACTIVE_USER";
|
|
12
|
-
})(AuthenticationErrors || (exports.AuthenticationErrors = AuthenticationErrors = {}));
|
|
8
|
+
var AuthenticationError;
|
|
9
|
+
(function (AuthenticationError) {
|
|
10
|
+
AuthenticationError["InvalidCredentials"] = "INVALID_CREDENTIALS";
|
|
11
|
+
AuthenticationError["InactiveUser"] = "INACTIVE_USER";
|
|
12
|
+
})(AuthenticationError || (exports.AuthenticationError = AuthenticationError = {}));
|
|
13
13
|
const getUser = async (userId, context) => {
|
|
14
14
|
const leanUser = await context.collection.functions.get({
|
|
15
15
|
filters: {
|
|
@@ -17,7 +17,7 @@ const getUser = async (userId, context) => {
|
|
|
17
17
|
},
|
|
18
18
|
populate: ['picture_file'],
|
|
19
19
|
});
|
|
20
|
-
if (
|
|
20
|
+
if ((0, common_1.isError)(leanUser)) {
|
|
21
21
|
throw new Error();
|
|
22
22
|
}
|
|
23
23
|
const tokenContent = {
|
|
@@ -81,21 +81,25 @@ const authenticate = async (props, context) => {
|
|
|
81
81
|
if ('revalidate' in props) {
|
|
82
82
|
const { token } = props;
|
|
83
83
|
if (!token && !context.token.authenticated) {
|
|
84
|
-
return (
|
|
84
|
+
return context.error(types_1.HTTPStatus.Unauthorized, {
|
|
85
|
+
code: types_1.ACError.AuthorizationError,
|
|
86
|
+
});
|
|
85
87
|
}
|
|
86
88
|
const decodedToken = token
|
|
87
89
|
? await (0, core_1.decodeToken)(token.content)
|
|
88
90
|
: context.token;
|
|
89
|
-
return
|
|
90
|
-
?
|
|
91
|
-
:
|
|
91
|
+
return decodedToken.sub
|
|
92
|
+
? getUser(decodedToken.sub, context)
|
|
93
|
+
: (0, exports.getDefaultUser)();
|
|
92
94
|
}
|
|
93
95
|
if (typeof props.email !== 'string') {
|
|
94
|
-
return (
|
|
96
|
+
return context.error(types_1.HTTPStatus.Unauthorized, {
|
|
97
|
+
code: AuthenticationError.InvalidCredentials,
|
|
98
|
+
});
|
|
95
99
|
}
|
|
96
100
|
if (context.config.defaultUser) {
|
|
97
101
|
if (props.email === context.config.defaultUser.username && props.password === context.config.defaultUser.password) {
|
|
98
|
-
return (0,
|
|
102
|
+
return (0, exports.getDefaultUser)();
|
|
99
103
|
}
|
|
100
104
|
}
|
|
101
105
|
const user = await context.collection.model.findOne({
|
|
@@ -108,11 +112,15 @@ const authenticate = async (props, context) => {
|
|
|
108
112
|
},
|
|
109
113
|
});
|
|
110
114
|
if (!user || !user.password || !await (0, bcrypt_1.compare)(props.password, user.password)) {
|
|
111
|
-
return (
|
|
115
|
+
return context.error(types_1.HTTPStatus.Unauthorized, {
|
|
116
|
+
code: AuthenticationError.InvalidCredentials,
|
|
117
|
+
});
|
|
112
118
|
}
|
|
113
119
|
if (!user.active) {
|
|
114
|
-
return (
|
|
120
|
+
return context.error(types_1.HTTPStatus.Unauthorized, {
|
|
121
|
+
code: AuthenticationError.InactiveUser,
|
|
122
|
+
});
|
|
115
123
|
}
|
|
116
|
-
return
|
|
124
|
+
return getUser(user._id, context);
|
|
117
125
|
};
|
|
118
126
|
exports.authenticate = authenticate;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
import { HTTPStatus, ACError } from "@aeriajs/types";
|
|
3
|
+
import { isError } from "@aeriajs/common";
|
|
2
4
|
import { compare as bcryptCompare } from "bcrypt";
|
|
3
5
|
import { signToken, decodeToken } from "@aeriajs/core";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return AuthenticationErrors2;
|
|
10
|
-
})(AuthenticationErrors || {});
|
|
6
|
+
export var AuthenticationError = /* @__PURE__ */ ((AuthenticationError2) => {
|
|
7
|
+
AuthenticationError2["InvalidCredentials"] = "INVALID_CREDENTIALS";
|
|
8
|
+
AuthenticationError2["InactiveUser"] = "INACTIVE_USER";
|
|
9
|
+
return AuthenticationError2;
|
|
10
|
+
})(AuthenticationError || {});
|
|
11
11
|
const getUser = async (userId, context) => {
|
|
12
12
|
const leanUser = await context.collection.functions.get({
|
|
13
13
|
filters: {
|
|
@@ -15,7 +15,7 @@ const getUser = async (userId, context) => {
|
|
|
15
15
|
},
|
|
16
16
|
populate: ["picture_file"]
|
|
17
17
|
});
|
|
18
|
-
if (
|
|
18
|
+
if (isError(leanUser)) {
|
|
19
19
|
throw new Error();
|
|
20
20
|
}
|
|
21
21
|
const tokenContent = {
|
|
@@ -77,17 +77,21 @@ export const authenticate = async (props, context) => {
|
|
|
77
77
|
if ("revalidate" in props) {
|
|
78
78
|
const { token } = props;
|
|
79
79
|
if (!token && !context.token.authenticated) {
|
|
80
|
-
return
|
|
80
|
+
return context.error(HTTPStatus.Unauthorized, {
|
|
81
|
+
code: ACError.AuthorizationError
|
|
82
|
+
});
|
|
81
83
|
}
|
|
82
84
|
const decodedToken = token ? await decodeToken(token.content) : context.token;
|
|
83
|
-
return
|
|
85
|
+
return decodedToken.sub ? getUser(decodedToken.sub, context) : getDefaultUser();
|
|
84
86
|
}
|
|
85
87
|
if (typeof props.email !== "string") {
|
|
86
|
-
return
|
|
88
|
+
return context.error(HTTPStatus.Unauthorized, {
|
|
89
|
+
code: "INVALID_CREDENTIALS" /* InvalidCredentials */
|
|
90
|
+
});
|
|
87
91
|
}
|
|
88
92
|
if (context.config.defaultUser) {
|
|
89
93
|
if (props.email === context.config.defaultUser.username && props.password === context.config.defaultUser.password) {
|
|
90
|
-
return
|
|
94
|
+
return getDefaultUser();
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
97
|
const user = await context.collection.model.findOne(
|
|
@@ -103,10 +107,14 @@ export const authenticate = async (props, context) => {
|
|
|
103
107
|
}
|
|
104
108
|
);
|
|
105
109
|
if (!user || !user.password || !await bcryptCompare(props.password, user.password)) {
|
|
106
|
-
return
|
|
110
|
+
return context.error(HTTPStatus.Unauthorized, {
|
|
111
|
+
code: "INVALID_CREDENTIALS" /* InvalidCredentials */
|
|
112
|
+
});
|
|
107
113
|
}
|
|
108
114
|
if (!user.active) {
|
|
109
|
-
return
|
|
115
|
+
return context.error(HTTPStatus.Unauthorized, {
|
|
116
|
+
code: "INACTIVE_USER" /* InactiveUser */
|
|
117
|
+
});
|
|
110
118
|
}
|
|
111
|
-
return
|
|
119
|
+
return getUser(user._id, context);
|
|
112
120
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Context, Schema } from '@aeriajs/types';
|
|
2
2
|
import type { description } from './description.js';
|
|
3
|
-
export declare const createAccount: (payload: Omit<Schema<typeof description>, 'roles'>, context: Context<typeof description>) => Promise<
|
|
3
|
+
export declare const createAccount: (payload: Omit<Schema<typeof description>, 'roles'>, context: Context<typeof description>) => Promise<any>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createAccount = void 0;
|
|
4
|
+
const types_1 = require("@aeriajs/types");
|
|
4
5
|
const common_1 = require("@aeriajs/common");
|
|
5
6
|
const validation_1 = require("@aeriajs/validation");
|
|
6
7
|
const bcrypt = require("bcrypt");
|
|
@@ -38,7 +39,10 @@ const createAccount = async (payload, context) => {
|
|
|
38
39
|
],
|
|
39
40
|
});
|
|
40
41
|
if ((0, common_1.isLeft)(validationEither)) {
|
|
41
|
-
return (
|
|
42
|
+
return context.error(types_1.HTTPStatus.BadRequest, {
|
|
43
|
+
code: types_1.ACError.MalformedInput,
|
|
44
|
+
details: (0, common_1.unwrapEither)(validationEither),
|
|
45
|
+
});
|
|
42
46
|
}
|
|
43
47
|
if (context.config.security.signupDefaults) {
|
|
44
48
|
Object.assign(user, context.config.security.signupDefaults);
|
|
@@ -58,6 +62,6 @@ const createAccount = async (payload, context) => {
|
|
|
58
62
|
if (!newUser) {
|
|
59
63
|
throw new Error();
|
|
60
64
|
}
|
|
61
|
-
return
|
|
65
|
+
return newUser;
|
|
62
66
|
};
|
|
63
67
|
exports.createAccount = createAccount;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
2
|
+
import { HTTPStatus, ACError } from "@aeriajs/types";
|
|
3
|
+
import { isLeft, unwrapEither } from "@aeriajs/common";
|
|
3
4
|
import { validate } from "@aeriajs/validation";
|
|
4
5
|
import * as bcrypt from "bcrypt";
|
|
5
6
|
export const createAccount = async (payload, context) => {
|
|
@@ -36,7 +37,10 @@ export const createAccount = async (payload, context) => {
|
|
|
36
37
|
]
|
|
37
38
|
});
|
|
38
39
|
if (isLeft(validationEither)) {
|
|
39
|
-
return
|
|
40
|
+
return context.error(HTTPStatus.BadRequest, {
|
|
41
|
+
code: ACError.MalformedInput,
|
|
42
|
+
details: unwrapEither(validationEither)
|
|
43
|
+
});
|
|
40
44
|
}
|
|
41
45
|
if (context.config.security.signupDefaults) {
|
|
42
46
|
Object.assign(user, context.config.security.signupDefaults);
|
|
@@ -56,5 +60,5 @@ export const createAccount = async (payload, context) => {
|
|
|
56
60
|
if (!newUser) {
|
|
57
61
|
throw new Error();
|
|
58
62
|
}
|
|
59
|
-
return
|
|
63
|
+
return newUser;
|
|
60
64
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Context, SchemaWithId } from '@aeriajs/types';
|
|
2
|
-
import type { description } from './description';
|
|
3
|
-
export declare enum
|
|
2
|
+
import type { description } from './description.js';
|
|
3
|
+
export declare enum ActivationError {
|
|
4
4
|
UserNotFound = "USER_NOT_FOUND",
|
|
5
5
|
AlreadyActiveUser = "ALREADY_ACTIVE_USER",
|
|
6
6
|
InvalidLink = "INVALID_LINK"
|
|
7
7
|
}
|
|
8
|
-
export declare const getCurrentUser: (_payload: undefined, context: Context<typeof description>) => Promise<
|
|
8
|
+
export declare const getCurrentUser: (_payload: undefined, context: Context<typeof description>) => Promise<SchemaWithId<{
|
|
9
9
|
readonly $id: "user";
|
|
10
10
|
readonly required: readonly ["name", "roles", "email"];
|
|
11
11
|
readonly form: readonly ["name", "active", "roles", "email", "phone_number", "picture_file"];
|
|
@@ -104,4 +104,4 @@ export declare const getCurrentUser: (_payload: undefined, context: Context<type
|
|
|
104
104
|
};
|
|
105
105
|
};
|
|
106
106
|
};
|
|
107
|
-
}
|
|
107
|
+
}>>;
|