@skroz/profile-api 1.0.14 → 1.0.16
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/resolvers/AuthResolver.d.ts +1 -1
- package/dist/resolvers/AuthResolver.js +7 -7
- package/dist/resolvers/ProfileResolver.d.ts +3 -3
- package/dist/resolvers/ProfileResolver.js +4 -4
- package/package.json +2 -2
- package/src/resolvers/AuthResolver.ts +8 -8
- package/src/resolvers/ProfileResolver.ts +9 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ProfileAuthService } from '../services/ProfileAuthService';
|
|
2
2
|
import { ProfileContext } from '../types';
|
|
3
3
|
export interface AuthResolverDependencies<TContext extends ProfileContext = ProfileContext> {
|
|
4
|
-
authService: ProfileAuthService | (() => ProfileAuthService);
|
|
4
|
+
authService: ProfileAuthService | ((ctx: TContext) => ProfileAuthService);
|
|
5
5
|
userType: any;
|
|
6
6
|
onUserCreated?: (user: any, ctx: TContext) => Promise<void>;
|
|
7
7
|
onLogin?: (user: any, ctx: TContext) => Promise<void>;
|
|
@@ -30,16 +30,16 @@ const ProfileAuthService_1 = require("../services/ProfileAuthService");
|
|
|
30
30
|
const dto_1 = require("../dto");
|
|
31
31
|
function createAuthResolver(deps) {
|
|
32
32
|
const { authService, onUserCreated, onLogin, onLogout, onEmailConfirmed, onPasswordRecovered, logTelegramBot, userType, } = deps;
|
|
33
|
-
const getAuthService = () => {
|
|
33
|
+
const getAuthService = (ctx) => {
|
|
34
34
|
if (typeof authService === 'function')
|
|
35
|
-
return authService();
|
|
35
|
+
return authService(ctx);
|
|
36
36
|
return authService;
|
|
37
37
|
};
|
|
38
38
|
let AuthResolver = class AuthResolver {
|
|
39
39
|
register(input, ctx) {
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
41
|
const { t } = ctx;
|
|
42
|
-
const service = getAuthService();
|
|
42
|
+
const service = getAuthService(ctx);
|
|
43
43
|
if (yield service.db.isEmailTaken(input.email)) {
|
|
44
44
|
throw new Error(t('validation:auth.emailExists'));
|
|
45
45
|
}
|
|
@@ -65,7 +65,7 @@ function createAuthResolver(deps) {
|
|
|
65
65
|
login(input, ctx) {
|
|
66
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
67
|
const { t } = ctx;
|
|
68
|
-
const service = getAuthService();
|
|
68
|
+
const service = getAuthService(ctx);
|
|
69
69
|
const user = yield service.db.findUserByEmail(input.email);
|
|
70
70
|
if (!user)
|
|
71
71
|
throw new Error(t('validation:user.notFound'));
|
|
@@ -102,7 +102,7 @@ function createAuthResolver(deps) {
|
|
|
102
102
|
}
|
|
103
103
|
confirmEmail(input, ctx) {
|
|
104
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
const service = getAuthService();
|
|
105
|
+
const service = getAuthService(ctx);
|
|
106
106
|
const user = yield service.getUserByToken(ProfileAuthService_1.AUTH_TOKEN_REDIS_PREFIX, input.token);
|
|
107
107
|
if (!user)
|
|
108
108
|
throw new Error(ctx.t('validation:error.wrongCode'));
|
|
@@ -126,7 +126,7 @@ function createAuthResolver(deps) {
|
|
|
126
126
|
sendToken(input, ctx) {
|
|
127
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
128
|
const { t } = ctx;
|
|
129
|
-
const service = getAuthService();
|
|
129
|
+
const service = getAuthService(ctx);
|
|
130
130
|
const user = yield service.db.findUserByEmail(input.email);
|
|
131
131
|
if (!user)
|
|
132
132
|
throw new Error(t('validation:user.notFound'));
|
|
@@ -142,7 +142,7 @@ function createAuthResolver(deps) {
|
|
|
142
142
|
}
|
|
143
143
|
recoverPassword(input, ctx) {
|
|
144
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
const service = getAuthService();
|
|
145
|
+
const service = getAuthService(ctx);
|
|
146
146
|
const user = yield service.getUserByToken(ProfileAuthService_1.AUTH_TOKEN_REDIS_PREFIX, input.token);
|
|
147
147
|
if (!user)
|
|
148
148
|
throw new Error(ctx.t('validation:error.wrongCode'));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ProfileAuthService } from '../services/ProfileAuthService';
|
|
2
2
|
import { ProfileContext } from '../types';
|
|
3
|
-
export interface ProfileResolverDependencies {
|
|
4
|
-
authService: ProfileAuthService | (() => ProfileAuthService);
|
|
3
|
+
export interface ProfileResolverDependencies<TContext extends ProfileContext = ProfileContext> {
|
|
4
|
+
authService: ProfileAuthService | ((ctx: TContext) => ProfileAuthService);
|
|
5
5
|
userType: any;
|
|
6
6
|
}
|
|
7
|
-
export declare function createProfileResolver<TContext extends ProfileContext = ProfileContext>(deps: ProfileResolverDependencies): any;
|
|
7
|
+
export declare function createProfileResolver<TContext extends ProfileContext = ProfileContext>(deps: ProfileResolverDependencies<TContext>): any;
|
|
@@ -29,9 +29,9 @@ const graphql_validators_1 = require("@os-team/graphql-validators");
|
|
|
29
29
|
const dto_1 = require("../dto");
|
|
30
30
|
function createProfileResolver(deps) {
|
|
31
31
|
const { authService, userType } = deps;
|
|
32
|
-
const getAuthService = () => {
|
|
32
|
+
const getAuthService = (ctx) => {
|
|
33
33
|
if (typeof authService === 'function')
|
|
34
|
-
return authService();
|
|
34
|
+
return authService(ctx);
|
|
35
35
|
return authService;
|
|
36
36
|
};
|
|
37
37
|
let ProfileResolver = class ProfileResolver {
|
|
@@ -40,7 +40,7 @@ function createProfileResolver(deps) {
|
|
|
40
40
|
const { user, t } = ctx;
|
|
41
41
|
if (!user)
|
|
42
42
|
throw new type_graphql_1.UnauthorizedError();
|
|
43
|
-
const service = getAuthService();
|
|
43
|
+
const service = getAuthService(ctx);
|
|
44
44
|
if (yield service.db.isEmailTaken(input.email, user.id)) {
|
|
45
45
|
throw new Error(t('validation:updateEmail.emailExists'));
|
|
46
46
|
}
|
|
@@ -55,7 +55,7 @@ function createProfileResolver(deps) {
|
|
|
55
55
|
const { user, t } = ctx;
|
|
56
56
|
if (!user)
|
|
57
57
|
throw new type_graphql_1.UnauthorizedError();
|
|
58
|
-
const service = getAuthService();
|
|
58
|
+
const service = getAuthService(ctx);
|
|
59
59
|
const isOldPasswordOk = yield service.verifyPassword(user.password, input.oldPassword);
|
|
60
60
|
if (!isOldPasswordOk)
|
|
61
61
|
throw new Error(t('validation:updatePassword.wrongPassword'));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skroz/profile-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "git@gitlab.com:skroz/libs/utils.git",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"type-graphql": "^1.1.1",
|
|
44
44
|
"typeorm": "^0.2.45"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "20236f7b5f15fc83912ce95bea870d52b7ac0667"
|
|
47
47
|
}
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
export interface AuthResolverDependencies<
|
|
27
27
|
TContext extends ProfileContext = ProfileContext
|
|
28
28
|
> {
|
|
29
|
-
authService: ProfileAuthService | (() => ProfileAuthService);
|
|
29
|
+
authService: ProfileAuthService | ((ctx: TContext) => ProfileAuthService);
|
|
30
30
|
userType: any;
|
|
31
31
|
onUserCreated?: (user: any, ctx: TContext) => Promise<void>;
|
|
32
32
|
onLogin?: (user: any, ctx: TContext) => Promise<void>;
|
|
@@ -50,8 +50,8 @@ export function createAuthResolver<
|
|
|
50
50
|
userType,
|
|
51
51
|
} = deps;
|
|
52
52
|
|
|
53
|
-
const getAuthService = (): ProfileAuthService => {
|
|
54
|
-
if (typeof authService === 'function') return authService();
|
|
53
|
+
const getAuthService = (ctx: TContext): ProfileAuthService => {
|
|
54
|
+
if (typeof authService === 'function') return authService(ctx);
|
|
55
55
|
return authService;
|
|
56
56
|
};
|
|
57
57
|
|
|
@@ -62,7 +62,7 @@ export function createAuthResolver<
|
|
|
62
62
|
@Mutation(() => userType)
|
|
63
63
|
async register(@Arg('input') input: AuthInput, @Ctx() ctx: TContext) {
|
|
64
64
|
const { t } = ctx;
|
|
65
|
-
const service = getAuthService();
|
|
65
|
+
const service = getAuthService(ctx);
|
|
66
66
|
if (await service.db.isEmailTaken(input.email)) {
|
|
67
67
|
throw new Error(t('validation:auth.emailExists'));
|
|
68
68
|
}
|
|
@@ -93,7 +93,7 @@ export function createAuthResolver<
|
|
|
93
93
|
@Mutation(() => StatusPayload)
|
|
94
94
|
async login(@Arg('input') input: AuthInput, @Ctx() ctx: TContext) {
|
|
95
95
|
const { t } = ctx;
|
|
96
|
-
const service = getAuthService();
|
|
96
|
+
const service = getAuthService(ctx);
|
|
97
97
|
const user = await service.db.findUserByEmail(input.email);
|
|
98
98
|
if (!user) throw new Error(t('validation:user.notFound'));
|
|
99
99
|
|
|
@@ -145,7 +145,7 @@ export function createAuthResolver<
|
|
|
145
145
|
@Arg('input') input: ConfirmEmailInput,
|
|
146
146
|
@Ctx() ctx: TContext
|
|
147
147
|
) {
|
|
148
|
-
const service = getAuthService();
|
|
148
|
+
const service = getAuthService(ctx);
|
|
149
149
|
const user = await service.getUserByToken(
|
|
150
150
|
AUTH_TOKEN_REDIS_PREFIX,
|
|
151
151
|
input.token
|
|
@@ -182,7 +182,7 @@ export function createAuthResolver<
|
|
|
182
182
|
@Mutation(() => SendTokenPayload)
|
|
183
183
|
async sendToken(@Arg('input') input: SendTokenInput, @Ctx() ctx: TContext) {
|
|
184
184
|
const { t } = ctx;
|
|
185
|
-
const service = getAuthService();
|
|
185
|
+
const service = getAuthService(ctx);
|
|
186
186
|
const user = await service.db.findUserByEmail(input.email);
|
|
187
187
|
if (!user) throw new Error(t('validation:user.notFound'));
|
|
188
188
|
|
|
@@ -207,7 +207,7 @@ export function createAuthResolver<
|
|
|
207
207
|
@Arg('input') input: RecoverPasswordInput,
|
|
208
208
|
@Ctx() ctx: TContext
|
|
209
209
|
) {
|
|
210
|
-
const service = getAuthService();
|
|
210
|
+
const service = getAuthService(ctx);
|
|
211
211
|
const user = await service.getUserByToken(
|
|
212
212
|
AUTH_TOKEN_REDIS_PREFIX,
|
|
213
213
|
input.token
|
|
@@ -23,18 +23,20 @@ import {
|
|
|
23
23
|
updateProfileValidators,
|
|
24
24
|
} from '../dto';
|
|
25
25
|
|
|
26
|
-
export interface ProfileResolverDependencies
|
|
27
|
-
|
|
26
|
+
export interface ProfileResolverDependencies<
|
|
27
|
+
TContext extends ProfileContext = ProfileContext
|
|
28
|
+
> {
|
|
29
|
+
authService: ProfileAuthService | ((ctx: TContext) => ProfileAuthService);
|
|
28
30
|
userType: any;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
export function createProfileResolver<
|
|
32
34
|
TContext extends ProfileContext = ProfileContext
|
|
33
|
-
>(deps: ProfileResolverDependencies): any {
|
|
35
|
+
>(deps: ProfileResolverDependencies<TContext>): any {
|
|
34
36
|
const { authService, userType } = deps;
|
|
35
37
|
|
|
36
|
-
const getAuthService = (): ProfileAuthService => {
|
|
37
|
-
if (typeof authService === 'function') return authService();
|
|
38
|
+
const getAuthService = (ctx: TContext): ProfileAuthService => {
|
|
39
|
+
if (typeof authService === 'function') return authService(ctx);
|
|
38
40
|
return authService;
|
|
39
41
|
};
|
|
40
42
|
|
|
@@ -51,7 +53,7 @@ export function createProfileResolver<
|
|
|
51
53
|
const { user, t } = ctx;
|
|
52
54
|
if (!user) throw new UnauthorizedError();
|
|
53
55
|
|
|
54
|
-
const service = getAuthService();
|
|
56
|
+
const service = getAuthService(ctx);
|
|
55
57
|
if (await service.db.isEmailTaken(input.email, user.id)) {
|
|
56
58
|
throw new Error(t('validation:updateEmail.emailExists'));
|
|
57
59
|
}
|
|
@@ -77,7 +79,7 @@ export function createProfileResolver<
|
|
|
77
79
|
const { user, t } = ctx;
|
|
78
80
|
if (!user) throw new UnauthorizedError();
|
|
79
81
|
|
|
80
|
-
const service = getAuthService();
|
|
82
|
+
const service = getAuthService(ctx);
|
|
81
83
|
const isOldPasswordOk = await service.verifyPassword(
|
|
82
84
|
user.password!,
|
|
83
85
|
input.oldPassword
|