@aeriajs/builtins 0.0.231 → 0.0.232
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 +4 -4
- package/dist/authentication.js +4 -5
- package/dist/authentication.mjs +4 -5
- package/dist/collections/file/download.d.ts +7 -8
- package/dist/collections/file/download.js +4 -5
- package/dist/collections/file/download.mjs +4 -5
- package/dist/collections/file/index.d.ts +18 -18
- package/dist/collections/file/remove.d.ts +12 -12
- package/dist/collections/file/removeAll.d.ts +2 -2
- package/dist/collections/user/activate.d.ts +17 -17
- package/dist/collections/user/activate.js +10 -11
- package/dist/collections/user/activate.mjs +10 -11
- package/dist/collections/user/authenticate.d.ts +7 -8
- package/dist/collections/user/createAccount.d.ts +9 -10
- package/dist/collections/user/createAccount.js +4 -5
- package/dist/collections/user/createAccount.mjs +4 -5
- package/dist/collections/user/editProfile.d.ts +3 -3
- package/dist/collections/user/getActivationLink.d.ts +13 -14
- package/dist/collections/user/getCurrentUser.d.ts +5 -5
- package/dist/collections/user/getCurrentUser.js +5 -6
- package/dist/collections/user/getCurrentUser.mjs +5 -6
- package/dist/collections/user/getInfo.d.ts +13 -13
- package/dist/collections/user/getInfo.js +9 -10
- package/dist/collections/user/getInfo.mjs +9 -10
- package/dist/collections/user/getRedefinePasswordLink.d.ts +11 -12
- package/dist/collections/user/index.d.ts +78 -78
- package/dist/collections/user/insert.d.ts +8 -9
- package/dist/collections/user/redefinePassword.d.ts +17 -17
- package/dist/collections/user/redefinePassword.js +10 -11
- package/dist/collections/user/redefinePassword.mjs +10 -11
- package/dist/functions/describe.d.ts +9 -9
- package/dist/index.d.ts +96 -96
- package/package.json +15 -15
package/dist/authentication.d.ts
CHANGED
|
@@ -6,10 +6,10 @@ export type SuccessfulAuthentication = {
|
|
|
6
6
|
user: TokenableUser;
|
|
7
7
|
token: TokenRecipient;
|
|
8
8
|
};
|
|
9
|
-
export declare
|
|
10
|
-
InvalidCredentials
|
|
11
|
-
InactiveUser
|
|
12
|
-
}
|
|
9
|
+
export declare const AuthenticationError: {
|
|
10
|
+
readonly InvalidCredentials: "INVALID_CREDENTIALS";
|
|
11
|
+
readonly InactiveUser: "INACTIVE_USER";
|
|
12
|
+
};
|
|
13
13
|
export declare const successfulAuthentication: <TUser extends TokenableUser>(user: TUser, context: RouteContext) => Promise<SuccessfulAuthentication>;
|
|
14
14
|
export declare const defaultSuccessfulAuthentication: () => Promise<{
|
|
15
15
|
user: {
|
package/dist/authentication.js
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultSuccessfulAuthentication = exports.successfulAuthentication = exports.AuthenticationError = void 0;
|
|
4
4
|
const core_1 = require("@aeriajs/core");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
})(AuthenticationError || (exports.AuthenticationError = AuthenticationError = {}));
|
|
5
|
+
exports.AuthenticationError = {
|
|
6
|
+
InvalidCredentials: 'INVALID_CREDENTIALS',
|
|
7
|
+
InactiveUser: 'INACTIVE_USER',
|
|
8
|
+
};
|
|
10
9
|
const successfulAuthentication = async (user, context) => {
|
|
11
10
|
const tokenContent = {
|
|
12
11
|
sub: user._id,
|
package/dist/authentication.mjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { signToken } from "@aeriajs/core";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
})(AuthenticationError || {});
|
|
3
|
+
export const AuthenticationError = {
|
|
4
|
+
InvalidCredentials: "INVALID_CREDENTIALS",
|
|
5
|
+
InactiveUser: "INACTIVE_USER"
|
|
6
|
+
};
|
|
8
7
|
export const successfulAuthentication = async (user, context) => {
|
|
9
8
|
const tokenContent = {
|
|
10
9
|
sub: user._id,
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import type { Context } from '@aeriajs/types';
|
|
2
2
|
import type { description } from './description.js';
|
|
3
|
-
import { HTTPStatus, ACError } from '@aeriajs/types';
|
|
4
3
|
import * as fs from 'node:fs';
|
|
5
|
-
export declare
|
|
6
|
-
RangeNotSatisfiable
|
|
7
|
-
}
|
|
4
|
+
export declare const DownloadError: {
|
|
5
|
+
readonly RangeNotSatisfiable: "RANGE_NOT_SATISFIABLE";
|
|
6
|
+
};
|
|
8
7
|
export declare const download: (payload: {
|
|
9
8
|
fileId: string;
|
|
10
9
|
options: readonly ("picture" | "download")[];
|
|
11
10
|
noHeaders?: boolean;
|
|
12
11
|
}, context: Context<typeof description>) => Promise<import("@aeriajs/types").Result.Error<{
|
|
13
|
-
readonly code:
|
|
12
|
+
readonly code: "RESOURCE_NOT_FOUND";
|
|
14
13
|
} & {
|
|
15
|
-
httpStatus:
|
|
14
|
+
httpStatus: 404;
|
|
16
15
|
}> | import("@aeriajs/types").Result.Error<{
|
|
17
|
-
readonly code:
|
|
16
|
+
readonly code: "RANGE_NOT_SATISFIABLE";
|
|
18
17
|
} & {
|
|
19
|
-
httpStatus:
|
|
18
|
+
httpStatus: 416;
|
|
20
19
|
}> | fs.ReadStream>;
|
|
@@ -4,10 +4,9 @@ exports.download = exports.DownloadError = void 0;
|
|
|
4
4
|
const types_1 = require("@aeriajs/types");
|
|
5
5
|
const core_1 = require("@aeriajs/core");
|
|
6
6
|
const fs = require("node:fs");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
})(DownloadError || (exports.DownloadError = DownloadError = {}));
|
|
7
|
+
exports.DownloadError = {
|
|
8
|
+
RangeNotSatisfiable: 'RANGE_NOT_SATISFIABLE',
|
|
9
|
+
};
|
|
11
10
|
const download = async (payload, context) => {
|
|
12
11
|
const { fileId, options = [] } = payload;
|
|
13
12
|
const file = await context.collection.model.findOne({
|
|
@@ -54,7 +53,7 @@ const download = async (payload, context) => {
|
|
|
54
53
|
'content-range': `bytes */${stat.size}`,
|
|
55
54
|
});
|
|
56
55
|
return context.error(types_1.HTTPStatus.RangeNotSatisfiable, {
|
|
57
|
-
code: DownloadError.RangeNotSatisfiable,
|
|
56
|
+
code: exports.DownloadError.RangeNotSatisfiable,
|
|
58
57
|
});
|
|
59
58
|
}
|
|
60
59
|
const chunkSize = (end - start) + 1;
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
import { HTTPStatus, ACError } from "@aeriajs/types";
|
|
3
3
|
import { ObjectId } from "@aeriajs/core";
|
|
4
4
|
import * as fs from "node:fs";
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})(DownloadError || {});
|
|
5
|
+
export const DownloadError = {
|
|
6
|
+
RangeNotSatisfiable: "RANGE_NOT_SATISFIABLE"
|
|
7
|
+
};
|
|
9
8
|
export const download = async (payload, context) => {
|
|
10
9
|
const { fileId, options = [] } = payload;
|
|
11
10
|
const file = await context.collection.model.findOne({
|
|
@@ -49,7 +48,7 @@ export const download = async (payload, context) => {
|
|
|
49
48
|
"content-range": `bytes */${stat.size}`
|
|
50
49
|
});
|
|
51
50
|
return context.error(HTTPStatus.RangeNotSatisfiable, {
|
|
52
|
-
code:
|
|
51
|
+
code: DownloadError.RangeNotSatisfiable
|
|
53
52
|
});
|
|
54
53
|
}
|
|
55
54
|
const chunkSize = end - start + 1;
|
|
@@ -230,34 +230,34 @@ export declare const file: Omit<import("@aeriajs/types").Collection<never>, "fun
|
|
|
230
230
|
options: readonly ("picture" | "download")[];
|
|
231
231
|
noHeaders?: boolean;
|
|
232
232
|
}, context: import("@aeriajs/types").Context<typeof description>) => Promise<import("@aeriajs/types").Result.Error<{
|
|
233
|
-
readonly code:
|
|
233
|
+
readonly code: "RESOURCE_NOT_FOUND";
|
|
234
234
|
} & {
|
|
235
|
-
httpStatus:
|
|
235
|
+
httpStatus: 404;
|
|
236
236
|
}> | import("@aeriajs/types").Result.Error<{
|
|
237
|
-
readonly code:
|
|
237
|
+
readonly code: "RANGE_NOT_SATISFIABLE";
|
|
238
238
|
} & {
|
|
239
|
-
httpStatus:
|
|
239
|
+
httpStatus: 416;
|
|
240
240
|
}> | import("fs").ReadStream>;
|
|
241
241
|
remove: (payload: import("@aeriajs/types").RemovePayload<import("@aeriajs/types").SchemaWithId<typeof description>>, context: import("@aeriajs/types").Context<typeof description>) => Promise<{
|
|
242
242
|
readonly _tag: "Result";
|
|
243
243
|
readonly error: undefined;
|
|
244
244
|
readonly result: import("mongodb").WithId<Omit<import("@aeriajs/types").PackReferences<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>>, "_id">> | null;
|
|
245
245
|
} | import("@aeriajs/types").Result.Error<{
|
|
246
|
-
readonly code:
|
|
246
|
+
readonly code: "RESOURCE_NOT_FOUND";
|
|
247
247
|
} & {
|
|
248
|
-
httpStatus:
|
|
248
|
+
httpStatus: 404;
|
|
249
249
|
}> | import("@aeriajs/types").Result.Error<{
|
|
250
|
-
readonly code:
|
|
250
|
+
readonly code: "OWNERSHIP_ERROR";
|
|
251
251
|
} & {
|
|
252
|
-
httpStatus:
|
|
252
|
+
httpStatus: 403;
|
|
253
253
|
}> | {
|
|
254
254
|
readonly _tag: "Error";
|
|
255
255
|
readonly error: Pick<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
|
|
256
256
|
readonly httpStatus: {
|
|
257
|
-
readonly enum: [
|
|
257
|
+
readonly enum: [403, 404, 400];
|
|
258
258
|
};
|
|
259
259
|
readonly code: {
|
|
260
|
-
readonly enum: [
|
|
260
|
+
readonly enum: ["RESOURCE_NOT_FOUND", "OWNERSHIP_ERROR", "INSECURE_OPERATOR", "MALFORMED_INPUT"];
|
|
261
261
|
};
|
|
262
262
|
readonly message: {
|
|
263
263
|
readonly type: "string";
|
|
@@ -267,16 +267,16 @@ export declare const file: Omit<import("@aeriajs/types").Collection<never>, "fun
|
|
|
267
267
|
readonly additionalProperties: true;
|
|
268
268
|
};
|
|
269
269
|
}>> & {
|
|
270
|
-
code:
|
|
271
|
-
httpStatus:
|
|
270
|
+
code: "RESOURCE_NOT_FOUND" | "INSECURE_OPERATOR" | "OWNERSHIP_ERROR" | "MALFORMED_INPUT";
|
|
271
|
+
httpStatus: 403 | 400 | 404;
|
|
272
272
|
message: string;
|
|
273
273
|
details: any;
|
|
274
274
|
}, never>, "code" | "httpStatus"> & Partial<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
|
|
275
275
|
readonly httpStatus: {
|
|
276
|
-
readonly enum: [
|
|
276
|
+
readonly enum: [403, 404, 400];
|
|
277
277
|
};
|
|
278
278
|
readonly code: {
|
|
279
|
-
readonly enum: [
|
|
279
|
+
readonly enum: ["RESOURCE_NOT_FOUND", "OWNERSHIP_ERROR", "INSECURE_OPERATOR", "MALFORMED_INPUT"];
|
|
280
280
|
};
|
|
281
281
|
readonly message: {
|
|
282
282
|
readonly type: "string";
|
|
@@ -286,8 +286,8 @@ export declare const file: Omit<import("@aeriajs/types").Collection<never>, "fun
|
|
|
286
286
|
readonly additionalProperties: true;
|
|
287
287
|
};
|
|
288
288
|
}>> & {
|
|
289
|
-
code:
|
|
290
|
-
httpStatus:
|
|
289
|
+
code: "RESOURCE_NOT_FOUND" | "INSECURE_OPERATOR" | "OWNERSHIP_ERROR" | "MALFORMED_INPUT";
|
|
290
|
+
httpStatus: 403 | 400 | 404;
|
|
291
291
|
message: string;
|
|
292
292
|
details: any;
|
|
293
293
|
}, never>>;
|
|
@@ -298,9 +298,9 @@ export declare const file: Omit<import("@aeriajs/types").Collection<never>, "fun
|
|
|
298
298
|
readonly error: undefined;
|
|
299
299
|
readonly result: import("mongodb").DeleteResult;
|
|
300
300
|
} | import("@aeriajs/types").Result.Error<{
|
|
301
|
-
readonly code:
|
|
301
|
+
readonly code: "OWNERSHIP_ERROR";
|
|
302
302
|
} & {
|
|
303
|
-
httpStatus:
|
|
303
|
+
httpStatus: 403;
|
|
304
304
|
}>>;
|
|
305
305
|
};
|
|
306
306
|
contracts: {
|
|
@@ -6,21 +6,21 @@ export declare const remove: (payload: RemovePayload<SchemaWithId<typeof descrip
|
|
|
6
6
|
readonly error: undefined;
|
|
7
7
|
readonly result: import("mongodb").WithId<Omit<import("@aeriajs/types").PackReferences<SchemaWithId<import("@aeriajs/types").Description>>, "_id">> | null;
|
|
8
8
|
} | Result.Error<{
|
|
9
|
-
readonly code:
|
|
9
|
+
readonly code: "RESOURCE_NOT_FOUND";
|
|
10
10
|
} & {
|
|
11
|
-
httpStatus:
|
|
11
|
+
httpStatus: 404;
|
|
12
12
|
}> | Result.Error<{
|
|
13
|
-
readonly code:
|
|
13
|
+
readonly code: "OWNERSHIP_ERROR";
|
|
14
14
|
} & {
|
|
15
|
-
httpStatus:
|
|
15
|
+
httpStatus: 403;
|
|
16
16
|
}> | {
|
|
17
17
|
readonly _tag: "Error";
|
|
18
18
|
readonly error: Pick<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
|
|
19
19
|
readonly httpStatus: {
|
|
20
|
-
readonly enum: [
|
|
20
|
+
readonly enum: [403, 404, 400];
|
|
21
21
|
};
|
|
22
22
|
readonly code: {
|
|
23
|
-
readonly enum: [
|
|
23
|
+
readonly enum: ["RESOURCE_NOT_FOUND", "OWNERSHIP_ERROR", "INSECURE_OPERATOR", "MALFORMED_INPUT"];
|
|
24
24
|
};
|
|
25
25
|
readonly message: {
|
|
26
26
|
readonly type: "string";
|
|
@@ -30,16 +30,16 @@ export declare const remove: (payload: RemovePayload<SchemaWithId<typeof descrip
|
|
|
30
30
|
readonly additionalProperties: true;
|
|
31
31
|
};
|
|
32
32
|
}>> & {
|
|
33
|
-
code:
|
|
34
|
-
httpStatus:
|
|
33
|
+
code: "RESOURCE_NOT_FOUND" | "INSECURE_OPERATOR" | "OWNERSHIP_ERROR" | "MALFORMED_INPUT";
|
|
34
|
+
httpStatus: 403 | 400 | 404;
|
|
35
35
|
message: string;
|
|
36
36
|
details: any;
|
|
37
37
|
}, never>, "code" | "httpStatus"> & Partial<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
|
|
38
38
|
readonly httpStatus: {
|
|
39
|
-
readonly enum: [
|
|
39
|
+
readonly enum: [403, 404, 400];
|
|
40
40
|
};
|
|
41
41
|
readonly code: {
|
|
42
|
-
readonly enum: [
|
|
42
|
+
readonly enum: ["RESOURCE_NOT_FOUND", "OWNERSHIP_ERROR", "INSECURE_OPERATOR", "MALFORMED_INPUT"];
|
|
43
43
|
};
|
|
44
44
|
readonly message: {
|
|
45
45
|
readonly type: "string";
|
|
@@ -49,8 +49,8 @@ export declare const remove: (payload: RemovePayload<SchemaWithId<typeof descrip
|
|
|
49
49
|
readonly additionalProperties: true;
|
|
50
50
|
};
|
|
51
51
|
}>> & {
|
|
52
|
-
code:
|
|
53
|
-
httpStatus:
|
|
52
|
+
code: "RESOURCE_NOT_FOUND" | "INSECURE_OPERATOR" | "OWNERSHIP_ERROR" | "MALFORMED_INPUT";
|
|
53
|
+
httpStatus: 403 | 400 | 404;
|
|
54
54
|
message: string;
|
|
55
55
|
details: any;
|
|
56
56
|
}, never>>;
|
|
@@ -5,7 +5,7 @@ export declare const removeAll: (payload: RemoveAllPayload<SchemaWithId<typeof d
|
|
|
5
5
|
readonly error: undefined;
|
|
6
6
|
readonly result: import("mongodb").DeleteResult;
|
|
7
7
|
} | import("@aeriajs/types").Result.Error<{
|
|
8
|
-
readonly code:
|
|
8
|
+
readonly code: "OWNERSHIP_ERROR";
|
|
9
9
|
} & {
|
|
10
|
-
httpStatus:
|
|
10
|
+
httpStatus: 403;
|
|
11
11
|
}>>;
|
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
import type { Context } from '@aeriajs/types';
|
|
2
2
|
import type { description } from './description.js';
|
|
3
3
|
import { ObjectId } from '@aeriajs/core';
|
|
4
|
-
import { Result
|
|
5
|
-
export declare
|
|
6
|
-
UserNotFound
|
|
7
|
-
AlreadyActiveUser
|
|
8
|
-
InvalidLink
|
|
9
|
-
InvalidToken
|
|
10
|
-
}
|
|
4
|
+
import { Result } from '@aeriajs/types';
|
|
5
|
+
export declare const ActivationError: {
|
|
6
|
+
readonly UserNotFound: "USER_NOT_FOUND";
|
|
7
|
+
readonly AlreadyActiveUser: "ALREADY_ACTIVE_USER";
|
|
8
|
+
readonly InvalidLink: "INVALID_LINK";
|
|
9
|
+
readonly InvalidToken: "INVALID_TOKEN";
|
|
10
|
+
};
|
|
11
11
|
export declare const activate: (payload: {
|
|
12
12
|
password?: string;
|
|
13
13
|
userId?: string;
|
|
14
14
|
token?: string;
|
|
15
15
|
}, context: Context<typeof description>) => Promise<Result.Error<{
|
|
16
|
-
readonly code:
|
|
16
|
+
readonly code: "INVALID_LINK";
|
|
17
17
|
} & {
|
|
18
|
-
httpStatus:
|
|
18
|
+
httpStatus: 404;
|
|
19
19
|
}> | Result.Error<{
|
|
20
|
-
readonly code:
|
|
20
|
+
readonly code: "USER_NOT_FOUND";
|
|
21
21
|
} & {
|
|
22
|
-
httpStatus:
|
|
22
|
+
httpStatus: 404;
|
|
23
23
|
}> | Result.Error<{
|
|
24
|
-
readonly code:
|
|
24
|
+
readonly code: "ALREADY_ACTIVE_USER";
|
|
25
25
|
} & {
|
|
26
|
-
httpStatus:
|
|
26
|
+
httpStatus: 403;
|
|
27
27
|
}> | Result.Error<{
|
|
28
|
-
readonly code:
|
|
28
|
+
readonly code: "INVALID_TOKEN";
|
|
29
29
|
} & {
|
|
30
|
-
httpStatus:
|
|
30
|
+
httpStatus: 401;
|
|
31
31
|
}> | Result.Error<{
|
|
32
|
-
readonly code:
|
|
32
|
+
readonly code: "MALFORMED_INPUT";
|
|
33
33
|
} & {
|
|
34
|
-
httpStatus:
|
|
34
|
+
httpStatus: 422;
|
|
35
35
|
}> | {
|
|
36
36
|
readonly _tag: "Result";
|
|
37
37
|
readonly error: undefined;
|
|
@@ -4,13 +4,12 @@ exports.activate = exports.ActivationError = void 0;
|
|
|
4
4
|
const core_1 = require("@aeriajs/core");
|
|
5
5
|
const types_1 = require("@aeriajs/types");
|
|
6
6
|
const bcrypt = require("bcrypt");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})(ActivationError || (exports.ActivationError = ActivationError = {}));
|
|
7
|
+
exports.ActivationError = {
|
|
8
|
+
UserNotFound: 'USER_NOT_FOUND',
|
|
9
|
+
AlreadyActiveUser: 'ALREADY_ACTIVE_USER',
|
|
10
|
+
InvalidLink: 'INVALID_LINK',
|
|
11
|
+
InvalidToken: 'INVALID_TOKEN',
|
|
12
|
+
};
|
|
14
13
|
const activate = async (payload, context) => {
|
|
15
14
|
const { userId, token, password, } = payload;
|
|
16
15
|
if (!context.config.secret) {
|
|
@@ -18,7 +17,7 @@ const activate = async (payload, context) => {
|
|
|
18
17
|
}
|
|
19
18
|
if (!userId || !token) {
|
|
20
19
|
return context.error(types_1.HTTPStatus.NotFound, {
|
|
21
|
-
code: ActivationError.InvalidLink,
|
|
20
|
+
code: exports.ActivationError.InvalidLink,
|
|
22
21
|
});
|
|
23
22
|
}
|
|
24
23
|
const user = await context.collection.model.findOne({
|
|
@@ -31,18 +30,18 @@ const activate = async (payload, context) => {
|
|
|
31
30
|
});
|
|
32
31
|
if (!user) {
|
|
33
32
|
return context.error(types_1.HTTPStatus.NotFound, {
|
|
34
|
-
code: ActivationError.UserNotFound,
|
|
33
|
+
code: exports.ActivationError.UserNotFound,
|
|
35
34
|
});
|
|
36
35
|
}
|
|
37
36
|
if (user.active) {
|
|
38
37
|
return context.error(types_1.HTTPStatus.Forbidden, {
|
|
39
|
-
code: ActivationError.AlreadyActiveUser,
|
|
38
|
+
code: exports.ActivationError.AlreadyActiveUser,
|
|
40
39
|
});
|
|
41
40
|
}
|
|
42
41
|
const decoded = await (0, core_1.decodeToken)(token, context.config.secret);
|
|
43
42
|
if (!decoded) {
|
|
44
43
|
return context.error(types_1.HTTPStatus.Unauthorized, {
|
|
45
|
-
code: ActivationError.InvalidToken,
|
|
44
|
+
code: exports.ActivationError.InvalidToken,
|
|
46
45
|
});
|
|
47
46
|
}
|
|
48
47
|
if (!user.password) {
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
import { decodeToken, ObjectId } from "@aeriajs/core";
|
|
3
3
|
import { Result, ACError, HTTPStatus } from "@aeriajs/types";
|
|
4
4
|
import * as bcrypt from "bcrypt";
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
})(ActivationError || {});
|
|
5
|
+
export const ActivationError = {
|
|
6
|
+
UserNotFound: "USER_NOT_FOUND",
|
|
7
|
+
AlreadyActiveUser: "ALREADY_ACTIVE_USER",
|
|
8
|
+
InvalidLink: "INVALID_LINK",
|
|
9
|
+
InvalidToken: "INVALID_TOKEN"
|
|
10
|
+
};
|
|
12
11
|
export const activate = async (payload, context) => {
|
|
13
12
|
const {
|
|
14
13
|
userId,
|
|
@@ -20,7 +19,7 @@ export const activate = async (payload, context) => {
|
|
|
20
19
|
}
|
|
21
20
|
if (!userId || !token) {
|
|
22
21
|
return context.error(HTTPStatus.NotFound, {
|
|
23
|
-
code:
|
|
22
|
+
code: ActivationError.InvalidLink
|
|
24
23
|
});
|
|
25
24
|
}
|
|
26
25
|
const user = await context.collection.model.findOne({
|
|
@@ -33,18 +32,18 @@ export const activate = async (payload, context) => {
|
|
|
33
32
|
});
|
|
34
33
|
if (!user) {
|
|
35
34
|
return context.error(HTTPStatus.NotFound, {
|
|
36
|
-
code:
|
|
35
|
+
code: ActivationError.UserNotFound
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
38
|
if (user.active) {
|
|
40
39
|
return context.error(HTTPStatus.Forbidden, {
|
|
41
|
-
code:
|
|
40
|
+
code: ActivationError.AlreadyActiveUser
|
|
42
41
|
});
|
|
43
42
|
}
|
|
44
43
|
const decoded = await decodeToken(token, context.config.secret);
|
|
45
44
|
if (!decoded) {
|
|
46
45
|
return context.error(HTTPStatus.Unauthorized, {
|
|
47
|
-
code:
|
|
46
|
+
code: ActivationError.InvalidToken
|
|
48
47
|
});
|
|
49
48
|
}
|
|
50
49
|
if (!user.password) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Context, TokenRecipient } from '@aeriajs/types';
|
|
2
2
|
import type { description } from './description.js';
|
|
3
|
-
import { Result
|
|
4
|
-
import { AuthenticationError } from '../../authentication.js';
|
|
3
|
+
import { Result } from '@aeriajs/types';
|
|
5
4
|
type Props = {
|
|
6
5
|
email: string;
|
|
7
6
|
password: string;
|
|
@@ -10,9 +9,9 @@ type Props = {
|
|
|
10
9
|
revalidate: true;
|
|
11
10
|
};
|
|
12
11
|
export declare const authenticate: (props: Props, context: Context<typeof description>) => Promise<Result.Error<{
|
|
13
|
-
readonly code:
|
|
12
|
+
readonly code: "AUTHORIZATION_ERROR";
|
|
14
13
|
} & {
|
|
15
|
-
httpStatus:
|
|
14
|
+
httpStatus: 401;
|
|
16
15
|
}> | {
|
|
17
16
|
readonly _tag: "Result";
|
|
18
17
|
readonly error: undefined;
|
|
@@ -34,12 +33,12 @@ export declare const authenticate: (props: Props, context: Context<typeof descri
|
|
|
34
33
|
readonly error: undefined;
|
|
35
34
|
readonly result: import("../../authentication.js").SuccessfulAuthentication;
|
|
36
35
|
} | Result.Error<{
|
|
37
|
-
readonly code:
|
|
36
|
+
readonly code: "INVALID_CREDENTIALS";
|
|
38
37
|
} & {
|
|
39
|
-
httpStatus:
|
|
38
|
+
httpStatus: 401;
|
|
40
39
|
}> | Result.Error<{
|
|
41
|
-
readonly code:
|
|
40
|
+
readonly code: "INACTIVE_USER";
|
|
42
41
|
} & {
|
|
43
|
-
httpStatus:
|
|
42
|
+
httpStatus: 401;
|
|
44
43
|
}>>;
|
|
45
44
|
export {};
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import type { Context, SchemaWithId, PackReferences } from '@aeriajs/types';
|
|
2
2
|
import type { description } from './description.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
3
|
+
export declare const CreateAccountError: {
|
|
4
|
+
readonly SignupDisallowed: "SIGNUP_DISALLOWED";
|
|
5
|
+
};
|
|
7
6
|
export declare const createAccount: (payload: Partial<PackReferences<SchemaWithId<typeof description>>> & Record<string, unknown>, context: Context<typeof description>) => Promise<import("@aeriajs/types").Result.Error<{
|
|
8
|
-
readonly code:
|
|
7
|
+
readonly code: "SIGNUP_DISALLOWED";
|
|
9
8
|
} & {
|
|
10
|
-
httpStatus:
|
|
9
|
+
httpStatus: 403;
|
|
11
10
|
}> | import("@aeriajs/types").Result.Error<{
|
|
12
|
-
readonly code:
|
|
11
|
+
readonly code: "MALFORMED_INPUT";
|
|
13
12
|
readonly details: import("@aeriajs/types").PropertyValidationError | import("@aeriajs/types").ValidationError;
|
|
14
13
|
} & {
|
|
15
|
-
httpStatus:
|
|
14
|
+
httpStatus: 400;
|
|
16
15
|
}> | import("@aeriajs/types").Result.Error<{
|
|
17
|
-
readonly code:
|
|
16
|
+
readonly code: "OWNERSHIP_ERROR";
|
|
18
17
|
} & {
|
|
19
|
-
httpStatus:
|
|
18
|
+
httpStatus: 403;
|
|
20
19
|
}> | import("@aeriajs/types").InsertReturnType<SchemaWithId<{
|
|
21
20
|
readonly $id: "user";
|
|
22
21
|
readonly icon: "users";
|
|
@@ -5,15 +5,14 @@ const types_1 = require("@aeriajs/types");
|
|
|
5
5
|
const validation_1 = require("@aeriajs/validation");
|
|
6
6
|
const bcrypt = require("bcrypt");
|
|
7
7
|
const core_1 = require("@aeriajs/core");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
})(CreateAccountError || (exports.CreateAccountError = CreateAccountError = {}));
|
|
8
|
+
exports.CreateAccountError = {
|
|
9
|
+
SignupDisallowed: 'SIGNUP_DISALLOWED',
|
|
10
|
+
};
|
|
12
11
|
const createAccount = async (payload, context) => {
|
|
13
12
|
const userCandidate = Object.assign({}, payload);
|
|
14
13
|
if (!context.config.security.allowSignup) {
|
|
15
14
|
return context.error(types_1.HTTPStatus.Forbidden, {
|
|
16
|
-
code: CreateAccountError.SignupDisallowed,
|
|
15
|
+
code: exports.CreateAccountError.SignupDisallowed,
|
|
17
16
|
});
|
|
18
17
|
}
|
|
19
18
|
const { error, result: user } = (0, validation_1.validate)(userCandidate, {
|
|
@@ -3,15 +3,14 @@ import { HTTPStatus, ACError } from "@aeriajs/types";
|
|
|
3
3
|
import { validate } from "@aeriajs/validation";
|
|
4
4
|
import * as bcrypt from "bcrypt";
|
|
5
5
|
import { insert as originalInsert } from "@aeriajs/core";
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
})(CreateAccountError || {});
|
|
6
|
+
export const CreateAccountError = {
|
|
7
|
+
SignupDisallowed: "SIGNUP_DISALLOWED"
|
|
8
|
+
};
|
|
10
9
|
export const createAccount = async (payload, context) => {
|
|
11
10
|
const userCandidate = Object.assign({}, payload);
|
|
12
11
|
if (!context.config.security.allowSignup) {
|
|
13
12
|
return context.error(HTTPStatus.Forbidden, {
|
|
14
|
-
code:
|
|
13
|
+
code: CreateAccountError.SignupDisallowed
|
|
15
14
|
});
|
|
16
15
|
}
|
|
17
16
|
const { error, result: user } = validate(userCandidate, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { description } from './description.js';
|
|
2
|
-
import {
|
|
2
|
+
import { type Context, type SchemaWithId, type PackReferences } from '@aeriajs/types';
|
|
3
3
|
export declare const editProfile: (payload: Partial<PackReferences<SchemaWithId<typeof description>>> & Record<string, unknown>, context: Context<typeof description>) => Promise<import("@aeriajs/types").InsertReturnType<SchemaWithId<{
|
|
4
4
|
readonly $id: "user";
|
|
5
5
|
readonly icon: "users";
|
|
@@ -105,7 +105,7 @@ export declare const editProfile: (payload: Partial<PackReferences<SchemaWithId<
|
|
|
105
105
|
};
|
|
106
106
|
};
|
|
107
107
|
}>> | import("@aeriajs/types").Result.Error<{
|
|
108
|
-
readonly code:
|
|
108
|
+
readonly code: "TARGET_IMMUTABLE";
|
|
109
109
|
} & {
|
|
110
|
-
httpStatus:
|
|
110
|
+
httpStatus: 403;
|
|
111
111
|
}>>;
|