@aeriajs/builtins 0.0.64 → 0.0.65
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/user/authenticate.d.ts +3 -5
- package/dist/collections/user/authenticate.js +7 -3
- package/dist/collections/user/authenticate.mjs +5 -3
- package/dist/collections/user/index.d.ts +4 -8
- package/dist/functions/describe.d.ts +1 -4
- package/dist/index.d.ts +4 -8
- package/package.json +13 -13
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import type { Context, SchemaWithId } from '@aeriajs/types';
|
|
1
|
+
import type { Context, SchemaWithId, TokenRecipient } from '@aeriajs/types';
|
|
2
2
|
import type { description } from './description.js';
|
|
3
3
|
import type { ObjectId } from '@aeriajs/core';
|
|
4
4
|
type Props = {
|
|
5
5
|
email: string;
|
|
6
6
|
password: string;
|
|
7
7
|
} | {
|
|
8
|
+
token?: TokenRecipient;
|
|
8
9
|
revalidate: true;
|
|
9
10
|
};
|
|
10
11
|
type Return = {
|
|
11
12
|
user: Pick<SchemaWithId<typeof description>, 'name' | 'email' | 'roles' | 'active'> & {
|
|
12
13
|
_id: ObjectId | null;
|
|
13
14
|
};
|
|
14
|
-
token:
|
|
15
|
-
type: 'bearer';
|
|
16
|
-
content: string;
|
|
17
|
-
};
|
|
15
|
+
token: TokenRecipient;
|
|
18
16
|
};
|
|
19
17
|
export declare enum AuthenticationErrors {
|
|
20
18
|
Unauthenticated = "UNAUTHENTICATED",
|
|
@@ -81,11 +81,15 @@ const getDefaultUser = async () => {
|
|
|
81
81
|
exports.getDefaultUser = getDefaultUser;
|
|
82
82
|
const authenticate = async (props, context) => {
|
|
83
83
|
if ('revalidate' in props) {
|
|
84
|
-
|
|
84
|
+
const { token } = props;
|
|
85
|
+
if (!token && !context.token.authenticated) {
|
|
85
86
|
return (0, common_1.left)(AuthenticationErrors.Unauthenticated);
|
|
86
87
|
}
|
|
87
|
-
|
|
88
|
-
? await
|
|
88
|
+
const decodedToken = token
|
|
89
|
+
? await (0, core_1.decodeToken)(token.content)
|
|
90
|
+
: context.token;
|
|
91
|
+
return (0, common_1.right)(decodedToken.sub
|
|
92
|
+
? await getUser(decodedToken.sub, context)
|
|
89
93
|
: await (0, exports.getDefaultUser)());
|
|
90
94
|
}
|
|
91
95
|
if (typeof props.email !== 'string') {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { compare as bcryptCompare } from "bcrypt";
|
|
3
|
-
import { signToken } from "@aeriajs/core";
|
|
3
|
+
import { signToken, decodeToken } from "@aeriajs/core";
|
|
4
4
|
import { left, right } from "@aeriajs/common";
|
|
5
5
|
export var AuthenticationErrors = /* @__PURE__ */ ((AuthenticationErrors2) => {
|
|
6
6
|
AuthenticationErrors2["Unauthenticated"] = "UNAUTHENTICATED";
|
|
@@ -77,10 +77,12 @@ export const getDefaultUser = async () => {
|
|
|
77
77
|
};
|
|
78
78
|
export const authenticate = async (props, context) => {
|
|
79
79
|
if ("revalidate" in props) {
|
|
80
|
-
|
|
80
|
+
const { token } = props;
|
|
81
|
+
if (!token && !context.token.authenticated) {
|
|
81
82
|
return left("UNAUTHENTICATED" /* Unauthenticated */);
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
+
const decodedToken = token ? await decodeToken(token.content) : context.token;
|
|
85
|
+
return right(decodedToken.sub ? await getUser(decodedToken.sub, context) : await getDefaultUser());
|
|
84
86
|
}
|
|
85
87
|
if (typeof props.email !== "string") {
|
|
86
88
|
return left("INVALID_CREDENTIALS" /* InvalidCredentials */);
|
|
@@ -415,6 +415,7 @@ export declare const user: Omit<import("@aeriajs/types").Collection<{
|
|
|
415
415
|
email: string;
|
|
416
416
|
password: string;
|
|
417
417
|
} | {
|
|
418
|
+
token?: import("@aeriajs/types").TokenRecipient | undefined;
|
|
418
419
|
revalidate: true;
|
|
419
420
|
}, context: import("@aeriajs/types").Context<{
|
|
420
421
|
readonly $id: "user";
|
|
@@ -620,10 +621,7 @@ export declare const user: Omit<import("@aeriajs/types").Collection<{
|
|
|
620
621
|
}>, "name" | "roles" | "email" | "active"> & {
|
|
621
622
|
_id: any;
|
|
622
623
|
};
|
|
623
|
-
token:
|
|
624
|
-
type: "bearer";
|
|
625
|
-
content: string;
|
|
626
|
-
};
|
|
624
|
+
token: import("@aeriajs/types").TokenRecipient;
|
|
627
625
|
} | {
|
|
628
626
|
user: {
|
|
629
627
|
_id: null;
|
|
@@ -1713,6 +1711,7 @@ export declare const user: Omit<import("@aeriajs/types").Collection<{
|
|
|
1713
1711
|
email: string;
|
|
1714
1712
|
password: string;
|
|
1715
1713
|
} | {
|
|
1714
|
+
token?: import("@aeriajs/types").TokenRecipient | undefined;
|
|
1716
1715
|
revalidate: true;
|
|
1717
1716
|
}, context: import("@aeriajs/types").Context<{
|
|
1718
1717
|
readonly $id: "user";
|
|
@@ -1918,10 +1917,7 @@ export declare const user: Omit<import("@aeriajs/types").Collection<{
|
|
|
1918
1917
|
}>, "name" | "roles" | "email" | "active"> & {
|
|
1919
1918
|
_id: any;
|
|
1920
1919
|
};
|
|
1921
|
-
token:
|
|
1922
|
-
type: "bearer";
|
|
1923
|
-
content: string;
|
|
1924
|
-
};
|
|
1920
|
+
token: import("@aeriajs/types").TokenRecipient;
|
|
1925
1921
|
} | {
|
|
1926
1922
|
user: {
|
|
1927
1923
|
_id: null;
|
|
@@ -114,10 +114,7 @@ export declare const describe: (contextOrPayload: RouteContext | Payload) => Pro
|
|
|
114
114
|
}>, "name" | "roles" | "email" | "active"> & {
|
|
115
115
|
_id: any;
|
|
116
116
|
};
|
|
117
|
-
token:
|
|
118
|
-
type: "bearer";
|
|
119
|
-
content: string;
|
|
120
|
-
};
|
|
117
|
+
token: import("@aeriajs/types").TokenRecipient;
|
|
121
118
|
} | {
|
|
122
119
|
user: {
|
|
123
120
|
_id: null;
|
package/dist/index.d.ts
CHANGED
|
@@ -1600,6 +1600,7 @@ export declare const collections: {
|
|
|
1600
1600
|
email: string;
|
|
1601
1601
|
password: string;
|
|
1602
1602
|
} | {
|
|
1603
|
+
token?: import("@aeriajs/types").TokenRecipient | undefined;
|
|
1603
1604
|
revalidate: true;
|
|
1604
1605
|
}, context: import("@aeriajs/types").Context<{
|
|
1605
1606
|
readonly $id: "user";
|
|
@@ -1805,10 +1806,7 @@ export declare const collections: {
|
|
|
1805
1806
|
}>, "name" | "roles" | "email" | "active"> & {
|
|
1806
1807
|
_id: any;
|
|
1807
1808
|
};
|
|
1808
|
-
token:
|
|
1809
|
-
type: "bearer";
|
|
1810
|
-
content: string;
|
|
1811
|
-
};
|
|
1809
|
+
token: import("@aeriajs/types").TokenRecipient;
|
|
1812
1810
|
} | {
|
|
1813
1811
|
user: {
|
|
1814
1812
|
_id: null;
|
|
@@ -2898,6 +2896,7 @@ export declare const collections: {
|
|
|
2898
2896
|
email: string;
|
|
2899
2897
|
password: string;
|
|
2900
2898
|
} | {
|
|
2899
|
+
token?: import("@aeriajs/types").TokenRecipient | undefined;
|
|
2901
2900
|
revalidate: true;
|
|
2902
2901
|
}, context: import("@aeriajs/types").Context<{
|
|
2903
2902
|
readonly $id: "user";
|
|
@@ -3103,10 +3102,7 @@ export declare const collections: {
|
|
|
3103
3102
|
}>, "name" | "roles" | "email" | "active"> & {
|
|
3104
3103
|
_id: any;
|
|
3105
3104
|
};
|
|
3106
|
-
token:
|
|
3107
|
-
type: "bearer";
|
|
3108
|
-
content: string;
|
|
3109
|
-
};
|
|
3105
|
+
token: import("@aeriajs/types").TokenRecipient;
|
|
3110
3106
|
} | {
|
|
3111
3107
|
user: {
|
|
3112
3108
|
_id: null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/builtins",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.65",
|
|
4
4
|
"description": "## Installation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -36,22 +36,22 @@
|
|
|
36
36
|
"bcrypt": "^5.1.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@aeriajs/access-control": "^0.0.
|
|
40
|
-
"@aeriajs/core": "^0.0.
|
|
41
|
-
"@aeriajs/common": "^0.0.
|
|
42
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
43
|
-
"@aeriajs/types": "^0.0.
|
|
44
|
-
"@aeriajs/validation": "^0.0.
|
|
39
|
+
"@aeriajs/access-control": "^0.0.36",
|
|
40
|
+
"@aeriajs/core": "^0.0.65",
|
|
41
|
+
"@aeriajs/common": "^0.0.36",
|
|
42
|
+
"@aeriajs/entrypoint": "^0.0.36",
|
|
43
|
+
"@aeriajs/types": "^0.0.33",
|
|
44
|
+
"@aeriajs/validation": "^0.0.39",
|
|
45
45
|
"@types/bcrypt": "^5.0.2",
|
|
46
46
|
"mongodb": "^6.5.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@aeriajs/access-control": "^0.0.
|
|
50
|
-
"@aeriajs/core": "^0.0.
|
|
51
|
-
"@aeriajs/common": "^0.0.
|
|
52
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
53
|
-
"@aeriajs/types": "^0.0.
|
|
54
|
-
"@aeriajs/validation": "^0.0.
|
|
49
|
+
"@aeriajs/access-control": "^0.0.36",
|
|
50
|
+
"@aeriajs/core": "^0.0.65",
|
|
51
|
+
"@aeriajs/common": "^0.0.36",
|
|
52
|
+
"@aeriajs/entrypoint": "^0.0.36",
|
|
53
|
+
"@aeriajs/types": "^0.0.33",
|
|
54
|
+
"@aeriajs/validation": "^0.0.39"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"test": "echo skipping",
|