@roadmanjs/chat 0.0.3
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/README.md +41 -0
- package/dist/chat/index.d.ts +3 -0
- package/dist/chat/index.js +16 -0
- package/dist/chat/index.js.map +1 -0
- package/dist/chat/methods/ChatConvo.methods.d.ts +4 -0
- package/dist/chat/methods/ChatConvo.methods.js +118 -0
- package/dist/chat/methods/ChatConvo.methods.js.map +1 -0
- package/dist/chat/methods/ChatConvo.test.d.ts +1 -0
- package/dist/chat/methods/ChatConvo.test.js +24 -0
- package/dist/chat/methods/ChatConvo.test.js.map +1 -0
- package/dist/chat/methods/index.d.ts +1 -0
- package/dist/chat/methods/index.js +14 -0
- package/dist/chat/methods/index.js.map +1 -0
- package/dist/chat/models/ChatAttachment.model.d.ts +18 -0
- package/dist/chat/models/ChatAttachment.model.js +51 -0
- package/dist/chat/models/ChatAttachment.model.js.map +1 -0
- package/dist/chat/models/ChatConvo.model.d.ts +36 -0
- package/dist/chat/models/ChatConvo.model.js +111 -0
- package/dist/chat/models/ChatConvo.model.js.map +1 -0
- package/dist/chat/models/ChatMessage.model.d.ts +30 -0
- package/dist/chat/models/ChatMessage.model.js +90 -0
- package/dist/chat/models/ChatMessage.model.js.map +1 -0
- package/dist/chat/models/index.d.ts +3 -0
- package/dist/chat/models/index.js +16 -0
- package/dist/chat/models/index.js.map +1 -0
- package/dist/chat/resolvers/ChatConvo.resolver.d.ts +17 -0
- package/dist/chat/resolvers/ChatConvo.resolver.js +233 -0
- package/dist/chat/resolvers/ChatConvo.resolver.js.map +1 -0
- package/dist/chat/resolvers/ChatMessage.resolver.d.ts +11 -0
- package/dist/chat/resolvers/ChatMessage.resolver.js +142 -0
- package/dist/chat/resolvers/ChatMessage.resolver.js.map +1 -0
- package/dist/chat/resolvers/index.d.ts +2 -0
- package/dist/chat/resolvers/index.js +15 -0
- package/dist/chat/resolvers/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/middlewares/firebaseToken.d.ts +2 -0
- package/dist/middlewares/firebaseToken.js +67 -0
- package/dist/middlewares/firebaseToken.js.map +1 -0
- package/dist/middlewares/index.d.ts +2 -0
- package/dist/middlewares/index.js +15 -0
- package/dist/middlewares/index.js.map +1 -0
- package/dist/middlewares/isAuth.d.ts +2 -0
- package/dist/middlewares/isAuth.js +32 -0
- package/dist/middlewares/isAuth.js.map +1 -0
- package/dist/roadman.d.ts +10 -0
- package/dist/roadman.js +19 -0
- package/dist/roadman.js.map +1 -0
- package/dist/shared/ContextType.d.ts +19 -0
- package/dist/shared/ContextType.js +7 -0
- package/dist/shared/ContextType.js.map +1 -0
- package/dist/shared/pubsub.utils.d.ts +9 -0
- package/dist/shared/pubsub.utils.js +19 -0
- package/dist/shared/pubsub.utils.js.map +1 -0
- package/dist/user/User.methods.d.ts +12 -0
- package/dist/user/User.methods.js +101 -0
- package/dist/user/User.methods.js.map +1 -0
- package/dist/user/User.model.d.ts +43 -0
- package/dist/user/User.model.js +143 -0
- package/dist/user/User.model.js.map +1 -0
- package/dist/user/User.resolver.auth.d.ts +6 -0
- package/dist/user/User.resolver.auth.js +82 -0
- package/dist/user/User.resolver.auth.js.map +1 -0
- package/dist/user/User.resolver.d.ts +9 -0
- package/dist/user/User.resolver.js +103 -0
- package/dist/user/User.resolver.js.map +1 -0
- package/dist/user/User.resolver.public.d.ts +5 -0
- package/dist/user/User.resolver.public.js +50 -0
- package/dist/user/User.resolver.public.js.map +1 -0
- package/dist/user/auth.d.ts +5 -0
- package/dist/user/auth.js +24 -0
- package/dist/user/auth.js.map +1 -0
- package/dist/user/index.d.ts +6 -0
- package/dist/user/index.js +19 -0
- package/dist/user/index.js.map +1 -0
- package/package.json +81 -0
- package/register/index.js +1 -0
- package/register/transpile-only.js +3 -0
- package/register/type-check.js +3 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
import { RedisPubSub } from 'graphql-redis-subscriptions';
|
|
3
|
+
export { ResType, GeoType } from 'couchset';
|
|
4
|
+
export interface ContextType {
|
|
5
|
+
req: Request;
|
|
6
|
+
res: Response;
|
|
7
|
+
payload?: any;
|
|
8
|
+
pubsub: RedisPubSub;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* GraphQL Types start
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* ResType
|
|
15
|
+
*/
|
|
16
|
+
export interface GeoLocationType {
|
|
17
|
+
lat: number;
|
|
18
|
+
lon: number;
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeoType = exports.ResType = void 0;
|
|
4
|
+
var couchset_1 = require("couchset");
|
|
5
|
+
Object.defineProperty(exports, "ResType", { enumerable: true, get: function () { return couchset_1.ResType; } });
|
|
6
|
+
Object.defineProperty(exports, "GeoType", { enumerable: true, get: function () { return couchset_1.GeoType; } });
|
|
7
|
+
//# sourceMappingURL=ContextType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextType.js","sourceRoot":"","sources":["../../src/shared/ContextType.ts"],"names":[],"mappings":";;;AAIA,qCAA0C;AAAlC,mGAAA,OAAO,OAAA;AAAE,mGAAA,OAAO,OAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.publishMessageToTopic = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Publish any message to a topic
|
|
6
|
+
* @param ctx
|
|
7
|
+
* @param topic
|
|
8
|
+
* @param data
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
const publishMessageToTopic = async (ctx, topic, data) => {
|
|
12
|
+
if (ctx && ctx.pubsub) {
|
|
13
|
+
await ctx.pubsub.publish(topic, data);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
};
|
|
18
|
+
exports.publishMessageToTopic = publishMessageToTopic;
|
|
19
|
+
//# sourceMappingURL=pubsub.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pubsub.utils.js","sourceRoot":"","sources":["../../src/shared/pubsub.utils.ts"],"names":[],"mappings":";;;AAEA;;;;;;GAMG;AACI,MAAM,qBAAqB,GAAG,KAAK,EACtC,GAAgB,EAChB,KAAa,EACb,IAAS,EACO,EAAE;IAClB,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE;QACnB,MAAM,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC;KACf;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAVW,QAAA,qBAAqB,yBAUhC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LoginResponseType, UserType } from './User.model';
|
|
2
|
+
/**
|
|
3
|
+
* Shared Create user method
|
|
4
|
+
* @param args
|
|
5
|
+
*/
|
|
6
|
+
export declare const createNewUser: (args: UserType) => Promise<LoginResponseType>;
|
|
7
|
+
/**
|
|
8
|
+
* Shared user login experience
|
|
9
|
+
* @param user
|
|
10
|
+
* @param password
|
|
11
|
+
*/
|
|
12
|
+
export declare const createLoginToken: (user: UserType) => Promise<LoginResponseType>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.createLoginToken = exports.createNewUser = void 0;
|
|
26
|
+
const User_model_1 = __importDefault(require("./User.model"));
|
|
27
|
+
const lodash_1 = __importStar(require("lodash"));
|
|
28
|
+
const auth_1 = require("./auth");
|
|
29
|
+
const logs_1 = require("@roadmanjs/logs");
|
|
30
|
+
/**
|
|
31
|
+
* Shared Create user method
|
|
32
|
+
* @param args
|
|
33
|
+
*/
|
|
34
|
+
const createNewUser = async (args) => {
|
|
35
|
+
const { email, fullname, phone, balance = 1 } = args;
|
|
36
|
+
try {
|
|
37
|
+
const findIfExits = await User_model_1.default.pagination({
|
|
38
|
+
where: {
|
|
39
|
+
$or: [{ email: { $eq: email } }, { phone: phone }],
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
if (!(0, lodash_1.isEmpty)(findIfExits)) {
|
|
43
|
+
throw new Error('user already exists');
|
|
44
|
+
}
|
|
45
|
+
const names = (fullname || '').split(' ');
|
|
46
|
+
const firstname = names.length ? names[0] : null;
|
|
47
|
+
const lastname = names.length ? names[1] : null;
|
|
48
|
+
const user = {
|
|
49
|
+
fullname,
|
|
50
|
+
firstname,
|
|
51
|
+
lastname,
|
|
52
|
+
phone,
|
|
53
|
+
email,
|
|
54
|
+
balance,
|
|
55
|
+
currency: 'USD',
|
|
56
|
+
};
|
|
57
|
+
(0, logs_1.log)('New user account', JSON.stringify(user));
|
|
58
|
+
const userItem = lodash_1.default.pickBy(user, lodash_1.default.identity);
|
|
59
|
+
// Create the user
|
|
60
|
+
const createdUser = (await User_model_1.default.create(userItem));
|
|
61
|
+
const refreshToken = (0, auth_1.createRefreshToken)(createdUser);
|
|
62
|
+
const accessToken = (0, auth_1.createAccessToken)(createdUser);
|
|
63
|
+
return {
|
|
64
|
+
success: true,
|
|
65
|
+
user: createdUser,
|
|
66
|
+
refreshToken,
|
|
67
|
+
accessToken,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
console.error(err);
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.createNewUser = createNewUser;
|
|
76
|
+
/**
|
|
77
|
+
* Shared user login experience
|
|
78
|
+
* @param user
|
|
79
|
+
* @param password
|
|
80
|
+
*/
|
|
81
|
+
const createLoginToken = async (user) => {
|
|
82
|
+
try {
|
|
83
|
+
if (!user) {
|
|
84
|
+
throw new Error('could not find user');
|
|
85
|
+
}
|
|
86
|
+
const refreshToken = (0, auth_1.createRefreshToken)(user);
|
|
87
|
+
const accessToken = (0, auth_1.createAccessToken)(user);
|
|
88
|
+
return {
|
|
89
|
+
success: true,
|
|
90
|
+
accessToken,
|
|
91
|
+
refreshToken,
|
|
92
|
+
user,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
console.error('error login in', error);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
exports.createLoginToken = createLoginToken;
|
|
101
|
+
//# sourceMappingURL=User.methods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"User.methods.js","sourceR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;
|
|
8
|
+
username?: string;
|
|
9
|
+
fullname?: string;
|
|
10
|
+
firstname?: string;
|
|
11
|
+
lastname?: string;
|
|
12
|
+
phone?: string;
|
|
13
|
+
website?: string;
|
|
14
|
+
address?: string;
|
|
15
|
+
country?: string;
|
|
16
|
+
bio?: string;
|
|
17
|
+
avatar?: string;
|
|
18
|
+
currency?: string;
|
|
19
|
+
balance?: number;
|
|
20
|
+
admin?: boolean;
|
|
21
|
+
plans?: string[];
|
|
22
|
+
tokenVersion?: number;
|
|
23
|
+
createdAt?: Date;
|
|
24
|
+
updatedAt?: Date;
|
|
25
|
+
}
|
|
26
|
+
export declare const userModelPublicSelectors: string[];
|
|
27
|
+
export declare class LoginResponseType {
|
|
28
|
+
success: boolean;
|
|
29
|
+
message?: string;
|
|
30
|
+
refreshToken: string;
|
|
31
|
+
accessToken: string;
|
|
32
|
+
user: UserType;
|
|
33
|
+
}
|
|
34
|
+
export declare class ResType {
|
|
35
|
+
success: boolean;
|
|
36
|
+
message?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare const UserModel: Model;
|
|
39
|
+
/**
|
|
40
|
+
* Methods
|
|
41
|
+
*/
|
|
42
|
+
export declare const incrementRefreshToken: (userId: string) => Promise<boolean>;
|
|
43
|
+
export default UserModel;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.incrementRefreshToken = exports.UserModel = exports.ResType = exports.LoginResponseType = exports.userModelPublicSelectors = exports.UserType = void 0;
|
|
10
|
+
const couchset_1 = require("couchset");
|
|
11
|
+
const lodash_1 = require("lodash");
|
|
12
|
+
const modelName = 'User';
|
|
13
|
+
/**
|
|
14
|
+
* GraphQL Types start
|
|
15
|
+
*/
|
|
16
|
+
let UserType = class UserType {
|
|
17
|
+
};
|
|
18
|
+
__decorate([
|
|
19
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
20
|
+
], UserType.prototype, "id", void 0);
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
23
|
+
], UserType.prototype, "email", void 0);
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
26
|
+
], UserType.prototype, "username", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
29
|
+
], UserType.prototype, "fullname", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
32
|
+
], UserType.prototype, "firstname", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
35
|
+
], UserType.prototype, "lastname", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
38
|
+
], UserType.prototype, "phone", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
41
|
+
], UserType.prototype, "website", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
44
|
+
], UserType.prototype, "address", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
47
|
+
], UserType.prototype, "country", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
50
|
+
], UserType.prototype, "bio", void 0);
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
53
|
+
], UserType.prototype, "avatar", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
56
|
+
], UserType.prototype, "currency", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, couchset_1.Field)(() => Number, { nullable: true })
|
|
59
|
+
], UserType.prototype, "balance", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
(0, couchset_1.Field)(() => Boolean, { nullable: true })
|
|
62
|
+
], UserType.prototype, "admin", void 0);
|
|
63
|
+
__decorate([
|
|
64
|
+
(0, couchset_1.Field)(() => [String], { nullable: true })
|
|
65
|
+
], UserType.prototype, "plans", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
(0, couchset_1.Field)(() => Number, { nullable: true })
|
|
68
|
+
], UserType.prototype, "tokenVersion", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, couchset_1.Field)(() => Date, { nullable: true })
|
|
71
|
+
], UserType.prototype, "createdAt", void 0);
|
|
72
|
+
__decorate([
|
|
73
|
+
(0, couchset_1.Field)(() => Date, { nullable: true })
|
|
74
|
+
], UserType.prototype, "updatedAt", void 0);
|
|
75
|
+
UserType = __decorate([
|
|
76
|
+
(0, couchset_1.InputType)('UserTypeInput'),
|
|
77
|
+
(0, couchset_1.ObjectType)()
|
|
78
|
+
], UserType);
|
|
79
|
+
exports.UserType = UserType;
|
|
80
|
+
exports.userModelPublicSelectors = [
|
|
81
|
+
'id',
|
|
82
|
+
'email',
|
|
83
|
+
'username',
|
|
84
|
+
'fullname',
|
|
85
|
+
'firstname',
|
|
86
|
+
'lastname',
|
|
87
|
+
'phone',
|
|
88
|
+
'website',
|
|
89
|
+
'address',
|
|
90
|
+
'country',
|
|
91
|
+
'bio',
|
|
92
|
+
'avatar',
|
|
93
|
+
];
|
|
94
|
+
let LoginResponseType = class LoginResponseType {
|
|
95
|
+
};
|
|
96
|
+
__decorate([
|
|
97
|
+
(0, couchset_1.Field)(() => Boolean, { nullable: false })
|
|
98
|
+
], LoginResponseType.prototype, "success", void 0);
|
|
99
|
+
__decorate([
|
|
100
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
101
|
+
], LoginResponseType.prototype, "message", void 0);
|
|
102
|
+
__decorate([
|
|
103
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
104
|
+
], LoginResponseType.prototype, "refreshToken", void 0);
|
|
105
|
+
__decorate([
|
|
106
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
107
|
+
], LoginResponseType.prototype, "accessToken", void 0);
|
|
108
|
+
__decorate([
|
|
109
|
+
(0, couchset_1.Field)(() => UserType, { nullable: true })
|
|
110
|
+
], LoginResponseType.prototype, "user", void 0);
|
|
111
|
+
LoginResponseType = __decorate([
|
|
112
|
+
(0, couchset_1.ObjectType)()
|
|
113
|
+
], LoginResponseType);
|
|
114
|
+
exports.LoginResponseType = LoginResponseType;
|
|
115
|
+
let ResType = class ResType {
|
|
116
|
+
};
|
|
117
|
+
__decorate([
|
|
118
|
+
(0, couchset_1.Field)(() => Boolean, { nullable: false })
|
|
119
|
+
], ResType.prototype, "success", void 0);
|
|
120
|
+
__decorate([
|
|
121
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
122
|
+
], ResType.prototype, "message", void 0);
|
|
123
|
+
ResType = __decorate([
|
|
124
|
+
(0, couchset_1.ObjectType)()
|
|
125
|
+
], ResType);
|
|
126
|
+
exports.ResType = ResType;
|
|
127
|
+
exports.UserModel = new couchset_1.Model(modelName);
|
|
128
|
+
/**
|
|
129
|
+
* Methods
|
|
130
|
+
*/
|
|
131
|
+
const incrementRefreshToken = async (userId) => {
|
|
132
|
+
const existing = await exports.UserModel.findById(userId);
|
|
133
|
+
if (!(0, lodash_1.isEmpty)(existing)) {
|
|
134
|
+
const currentVersion = existing.tokenVersion || 0;
|
|
135
|
+
existing.tokenVersion = currentVersion + 1;
|
|
136
|
+
await exports.UserModel.save(existing);
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
140
|
+
};
|
|
141
|
+
exports.incrementRefreshToken = incrementRefreshToken;
|
|
142
|
+
exports.default = exports.UserModel;
|
|
143
|
+
//# sourceMappingURL=User.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"User.model.js","sourceRoot":"","sources":["../../src/user/User.model.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAA6D;AAE7D,mCAA+B;AAE/B,MAAM,SAAS,GAAG,MAAM,CAAC;AACzB;;GAEG;AAGH,IAAa,QAAQ,GAArB,MAAa,QAAQ;CA2DpB,CAAA;AAzDG;IADC,IAAA,gBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;oCAC1B;AAGZ;IADC,IAAA,gBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;uCACvB;AAGf;IADC,IAAA,gBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;0CACpB;AAGlB;IADC,IAAA,gBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;0CACpB;AAGlB;IADC,IAAA,gBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;2CACnB;AAGnB;IADC,IAAA,gBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;0CACpB;AAGlB;IADC,IAAA,gBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,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C,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;wCACrB;AALR,OAAO;IADnB,IAAA,qBAAU,GAAE;GACA,OAAO,CAMnB;AANY,0BAAO;AAQP,QAAA,SAAS,GAAU,IAAI,gBAAK,CAAC,SAAS,CAAC,CAAC;AAErD;;GAEG;AACI,MAAM,qBAAqB,GAAG,KAAK,EAAE,MAAc,EAAoB,EAAE;IAC5E,MAAM,QAAQ,GAAG,MAAM,iBAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClD,IAAI,CAAC,IAAA,gBAAO,EAAC,QAAQ,CAAC,EAAE;QACpB,MAAM,cAAc,GAAG,QAAQ,CAAC,YAAY,IAAI,CAAC,CAAC;QAClD,QAAQ,CAAC,YAAY,GAAG,cAAc,GAAG,CAAC,CAAC;QAC3C,MAAM,iBAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;KACf;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AATW,QAAA,qBAAqB,yBAShC;AAEF,kBAAe,iBAAS,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ContextType } from 'couchset';
|
|
2
|
+
import { LoginResponseType } from './User.model';
|
|
3
|
+
export declare class UserAuthResolver {
|
|
4
|
+
phoneLogin(phone: string, _firebaseToken: string, createNew: boolean, { res }: ContextType): Promise<LoginResponseType>;
|
|
5
|
+
}
|
|
6
|
+
export default UserAuthResolver;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
9
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.UserAuthResolver = void 0;
|
|
16
|
+
const couchset_1 = require("couchset");
|
|
17
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
18
|
+
const User_model_1 = require("./User.model");
|
|
19
|
+
const logs_1 = require("@roadmanjs/logs");
|
|
20
|
+
const User_methods_1 = require("./User.methods");
|
|
21
|
+
const firebaseToken_1 = require("../middlewares/firebaseToken");
|
|
22
|
+
const auth_1 = require("./auth");
|
|
23
|
+
let UserAuthResolver = class UserAuthResolver {
|
|
24
|
+
async phoneLogin(phone, _firebaseToken, createNew, { res }) {
|
|
25
|
+
try {
|
|
26
|
+
const username = phone;
|
|
27
|
+
(0, logs_1.log)(`LOGIN: phone=${phone} _firebaseToken=${_firebaseToken}`);
|
|
28
|
+
const users = await User_model_1.UserModel.pagination({
|
|
29
|
+
select: '*',
|
|
30
|
+
where: {
|
|
31
|
+
$or: [{ email: { $eq: username } }, { phone: username }, { phone: `+1${username}` }],
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
(0, logs_1.log)(`users found are users=${users.length}`);
|
|
35
|
+
const firstUser = users || users[0];
|
|
36
|
+
if (!(0, isEmpty_1.default)(firstUser)) {
|
|
37
|
+
// user is found
|
|
38
|
+
const user = firstUser; // get first document
|
|
39
|
+
const response = await (0, User_methods_1.createLoginToken)(user); // login user without password
|
|
40
|
+
const { refreshToken } = response;
|
|
41
|
+
(0, auth_1.sendRefreshToken)(res, refreshToken);
|
|
42
|
+
return response;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// create new
|
|
46
|
+
const response = await (0, User_methods_1.createNewUser)({
|
|
47
|
+
email: '',
|
|
48
|
+
fullname: '',
|
|
49
|
+
phone,
|
|
50
|
+
});
|
|
51
|
+
(0, logs_1.log)(`creating new user =${JSON.stringify(response)}`);
|
|
52
|
+
const { refreshToken } = response;
|
|
53
|
+
(0, auth_1.sendRefreshToken)(res, refreshToken);
|
|
54
|
+
return response;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error(error);
|
|
59
|
+
return {
|
|
60
|
+
success: false,
|
|
61
|
+
message: error && error.message,
|
|
62
|
+
accessToken: null,
|
|
63
|
+
refreshToken: null,
|
|
64
|
+
user: null,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, couchset_1.Mutation)(() => User_model_1.LoginResponseType),
|
|
71
|
+
(0, couchset_1.UseMiddleware)(firebaseToken_1.FirebaseTokenVerify),
|
|
72
|
+
__param(0, (0, couchset_1.Arg)('phone', () => String, { nullable: false })),
|
|
73
|
+
__param(1, (0, couchset_1.Arg)('firebaseToken', () => String, { nullable: false })),
|
|
74
|
+
__param(2, (0, couchset_1.Arg)('createNew', () => Boolean, { nullable: true })),
|
|
75
|
+
__param(3, (0, couchset_1.Ctx)())
|
|
76
|
+
], UserAuthResolver.prototype, "phoneLogin", null);
|
|
77
|
+
UserAuthResolver = __decorate([
|
|
78
|
+
(0, couchset_1.Resolver)()
|
|
79
|
+
], UserAuthResolver);
|
|
80
|
+
exports.UserAuthResolver = UserAuthResolver;
|
|
81
|
+
exports.default = UserAuthResolver;
|
|
82
|
+
//# sourceMappingURL=User.resolver.auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"User.resol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AAgB;AAgE7B,kBAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ContextType } from 'couchset';
|
|
2
|
+
import { UserType, ResType } from './User.model';
|
|
3
|
+
export declare class UserResolver {
|
|
4
|
+
me(context: ContextType): Promise<UserType | null>;
|
|
5
|
+
revokeRefreshTokenForUser(userId: string): Promise<ResType>;
|
|
6
|
+
updateUserProfile(user: UserType, { payload }: ContextType): Promise<ResType>;
|
|
7
|
+
logout({ res }: ContextType): Promise<boolean>;
|
|
8
|
+
}
|
|
9
|
+
export default UserResolver;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
9
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.UserResolver = void 0;
|
|
16
|
+
const couchset_1 = require("couchset");
|
|
17
|
+
const User_model_1 = require("./User.model");
|
|
18
|
+
const auth_1 = require("./auth");
|
|
19
|
+
const isAuth_1 = require("../middlewares/isAuth");
|
|
20
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
21
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
22
|
+
const jsonwebtoken_1 = require("jsonwebtoken");
|
|
23
|
+
let UserResolver = class UserResolver {
|
|
24
|
+
async me(context) {
|
|
25
|
+
const authorization = (0, get_1.default)(context, 'req.headers.authorization', '');
|
|
26
|
+
if ((0, isEmpty_1.default)(authorization)) {
|
|
27
|
+
throw new Error('Not Authenticated');
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
const token = authorization.split(' ')[1];
|
|
31
|
+
const verified = (0, jsonwebtoken_1.verify)(token, process.env.ACCESS_TOKEN_SECRET);
|
|
32
|
+
const { userId } = verified;
|
|
33
|
+
if ((0, isEmpty_1.default)(userId)) {
|
|
34
|
+
throw new Error('userId is not valid');
|
|
35
|
+
}
|
|
36
|
+
const user = await User_model_1.UserModel.findById(userId);
|
|
37
|
+
return user;
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
console.log('error getting me', err);
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async revokeRefreshTokenForUser(userId) {
|
|
45
|
+
try {
|
|
46
|
+
const updated = await (0, User_model_1.incrementRefreshToken)(userId);
|
|
47
|
+
if (!updated) {
|
|
48
|
+
throw new Error('error revokeRefreshTokenForUser');
|
|
49
|
+
}
|
|
50
|
+
return { success: true };
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
return { success: false, message: err && err.message };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async updateUserProfile(user, { payload }) {
|
|
57
|
+
try {
|
|
58
|
+
const userId = payload && payload.userId;
|
|
59
|
+
console.log('update userId', userId);
|
|
60
|
+
const findUser = await User_model_1.UserModel.findById(userId);
|
|
61
|
+
if (findUser) {
|
|
62
|
+
const updatedUser = Object.assign(Object.assign({}, findUser), user);
|
|
63
|
+
await User_model_1.UserModel.updateById(userId, updatedUser);
|
|
64
|
+
return { success: true };
|
|
65
|
+
}
|
|
66
|
+
throw new Error('error updateing user');
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
return { success: false, message: err && err.message };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async logout({ res }) {
|
|
73
|
+
(0, auth_1.sendRefreshToken)(res, '');
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
__decorate([
|
|
78
|
+
(0, couchset_1.Query)(() => User_model_1.UserType),
|
|
79
|
+
(0, couchset_1.UseMiddleware)(isAuth_1.isAuth),
|
|
80
|
+
__param(0, (0, couchset_1.Ctx)())
|
|
81
|
+
], UserResolver.prototype, "me", null);
|
|
82
|
+
__decorate([
|
|
83
|
+
(0, couchset_1.Mutation)(() => User_model_1.ResType),
|
|
84
|
+
(0, couchset_1.UseMiddleware)(isAuth_1.isAuth),
|
|
85
|
+
__param(0, (0, couchset_1.Arg)('userId', () => String))
|
|
86
|
+
], UserResolver.prototype, "revokeRefreshTokenForUser", null);
|
|
87
|
+
__decorate([
|
|
88
|
+
(0, couchset_1.UseMiddleware)(isAuth_1.isAuth),
|
|
89
|
+
(0, couchset_1.Mutation)(() => User_model_1.ResType),
|
|
90
|
+
__param(0, (0, couchset_1.Arg)('user', () => User_model_1.UserType)),
|
|
91
|
+
__param(1, (0, couchset_1.Ctx)())
|
|
92
|
+
], UserResolver.prototype, "updateUserProfile", null);
|
|
93
|
+
__decorate([
|
|
94
|
+
(0, couchset_1.Mutation)(() => Boolean),
|
|
95
|
+
(0, couchset_1.UseMiddleware)(isAuth_1.isAuth),
|
|
96
|
+
__param(0, (0, couchset_1.Ctx)())
|
|
97
|
+
], UserResolver.prototype, "logout", null);
|
|
98
|
+
UserResolver = __decorate([
|
|
99
|
+
(0, couchset_1.Resolver)()
|
|
100
|
+
], UserResolver);
|
|
101
|
+
exports.UserResolver = UserResolver;
|
|
102
|
+
exports.default = UserResolver;
|
|
103
|
+
//# sourceMappingURL=User.resolver.js.map
|
|
@@ -0,0 +1 @@
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CAAC,oBAAO,CAAC;IACvB,IAAA,wBAAa,EAAC,eAAM,CAAC;IACW,WAAA,IAAA,cAAG,EAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,CAAA;6DAU3D;AAID;IAFC,IAAA,wBAAa,EAAC,eAAM,CAAC;IACrB,IAAA,mBAAQ,EAAC,GAAG,EAAE,CAAC,oBAAO,CAAC;IAEnB,WAAA,IAAA,cAAG,EAAC,MAAM,EAAE,GAAG,EAAE,CAAC,qBAAQ,CAAC,CAAA;IAC3B,WAAA,IAAA,cAAG,GAAE,CAAA;qDAsBT;AAID;IAFC,IAAA,mBAAQ,EAAC,GAAG,EAAE,CAAC,OAAO,CAAC;IACvB,IAAA,wBAAa,EAAC,eAAM,CAAC;IACR,WAAA,IAAA,cAAG,GAAE,CAAA;0CAGlB;AAvEQ,YAAY;IADxB,IAAA,mBAAQ,GAAE;GACE,YAAY,CAwExB;AAxEY,oCAAY;AA0EzB,kBAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
9
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UserResolverPublic = void 0;
|
|
13
|
+
const couchset_1 = require("couchset");
|
|
14
|
+
const logs_1 = require("@roadmanjs/logs");
|
|
15
|
+
const User_model_1 = require("./User.model");
|
|
16
|
+
let UserResolverPublic = class UserResolverPublic {
|
|
17
|
+
async getUser(id) {
|
|
18
|
+
try {
|
|
19
|
+
const username = id;
|
|
20
|
+
(0, logs_1.log)(`GET USER: id,username=${username}`);
|
|
21
|
+
const users = await User_model_1.UserModel.pagination({
|
|
22
|
+
select: User_model_1.userModelPublicSelectors,
|
|
23
|
+
where: {
|
|
24
|
+
$or: [
|
|
25
|
+
{ id: { $eq: username } },
|
|
26
|
+
{ email: { $eq: username } },
|
|
27
|
+
{ phone: { $eq: username } },
|
|
28
|
+
{ phone: { $eq: `+1${username}` } },
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
(0, logs_1.log)(`users found are users=${users && users.length}`);
|
|
33
|
+
return users && users[0]; // get first document
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error(error);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, couchset_1.Query)(() => User_model_1.UserType),
|
|
43
|
+
__param(0, (0, couchset_1.Arg)('id', () => String, { nullable: false }))
|
|
44
|
+
], UserResolverPublic.prototype, "getUser", null);
|
|
45
|
+
UserResolverPublic = __decorate([
|
|
46
|
+
(0, couchset_1.Resolver)()
|
|
47
|
+
], UserResolverPublic);
|
|
48
|
+
exports.UserResolverPublic = UserResolverPublic;
|
|
49
|
+
exports.default = UserResolverPublic;
|
|
50
|
+
//# sourceMappingURL=User.resolver.public.js.map
|