@culturefy/shared 1.0.28 → 1.0.30

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.
Files changed (106) hide show
  1. package/build/cjs/dto/index.js +8 -0
  2. package/build/cjs/dto/index.js.map +1 -1
  3. package/build/cjs/index.js +6 -0
  4. package/build/cjs/index.js.map +1 -1
  5. package/build/cjs/interfaces/index.js +16 -0
  6. package/build/cjs/interfaces/index.js.map +1 -0
  7. package/build/cjs/interfaces/keycloak.js +2 -0
  8. package/build/cjs/interfaces/keycloak.js.map +1 -0
  9. package/build/cjs/interfaces/user.js +2 -0
  10. package/build/cjs/interfaces/user.js.map +1 -0
  11. package/build/cjs/middlewares/index.js +10 -0
  12. package/build/cjs/middlewares/index.js.map +1 -0
  13. package/build/cjs/middlewares/token-validation.js +485 -0
  14. package/build/cjs/middlewares/token-validation.js.map +1 -0
  15. package/build/cjs/models/user.model.js +510 -0
  16. package/build/cjs/models/user.model.js.map +1 -0
  17. package/build/cjs/service/keycloak.service.js +1003 -0
  18. package/build/cjs/service/keycloak.service.js.map +1 -0
  19. package/build/cjs/service/user.service.js +95 -0
  20. package/build/cjs/service/user.service.js.map +1 -0
  21. package/build/cjs/utils/index.js +6 -0
  22. package/build/cjs/utils/index.js.map +1 -1
  23. package/build/cjs/utils/jwt.js +14 -0
  24. package/build/cjs/utils/jwt.js.map +1 -0
  25. package/build/cjs/utils/response.js +19 -0
  26. package/build/cjs/utils/response.js.map +1 -1
  27. package/build/esm/dto/index.js +1 -1
  28. package/build/esm/dto/index.js.map +1 -1
  29. package/build/esm/index.js +1 -0
  30. package/build/esm/index.js.map +1 -1
  31. package/build/esm/interfaces/index.js +3 -0
  32. package/build/esm/interfaces/index.js.map +1 -0
  33. package/build/esm/interfaces/keycloak.js +2 -0
  34. package/build/esm/interfaces/keycloak.js.map +1 -0
  35. package/build/esm/interfaces/user.js +2 -0
  36. package/build/esm/interfaces/user.js.map +1 -0
  37. package/build/esm/middlewares/index.js +2 -0
  38. package/build/esm/middlewares/index.js.map +1 -0
  39. package/build/esm/middlewares/token-validation.js +481 -0
  40. package/build/esm/middlewares/token-validation.js.map +1 -0
  41. package/build/esm/models/user.model.js +500 -0
  42. package/build/esm/models/user.model.js.map +1 -0
  43. package/build/esm/service/keycloak.service.js +996 -0
  44. package/build/esm/service/keycloak.service.js.map +1 -0
  45. package/build/esm/service/user.service.js +91 -0
  46. package/build/esm/service/user.service.js.map +1 -0
  47. package/build/esm/utils/index.js +1 -0
  48. package/build/esm/utils/index.js.map +1 -1
  49. package/build/esm/utils/jwt.js +10 -0
  50. package/build/esm/utils/jwt.js.map +1 -0
  51. package/build/esm/utils/response.js +18 -0
  52. package/build/esm/utils/response.js.map +1 -1
  53. package/build/package.json +16 -4
  54. package/build/src/dto/index.d.ts +1 -0
  55. package/build/src/dto/index.js +3 -0
  56. package/build/src/dto/index.js.map +1 -1
  57. package/build/src/index.d.ts +1 -0
  58. package/build/src/index.js +1 -0
  59. package/build/src/index.js.map +1 -1
  60. package/build/src/interfaces/index.d.ts +2 -0
  61. package/build/src/interfaces/index.js +6 -0
  62. package/build/src/interfaces/index.js.map +1 -0
  63. package/build/src/interfaces/keycloak.d.ts +151 -0
  64. package/build/src/interfaces/keycloak.js +3 -0
  65. package/build/src/interfaces/keycloak.js.map +1 -0
  66. package/build/src/interfaces/user.d.ts +5 -0
  67. package/build/src/interfaces/user.js +3 -0
  68. package/build/src/interfaces/user.js.map +1 -0
  69. package/build/src/middlewares/index.d.ts +1 -0
  70. package/build/src/middlewares/index.js +5 -0
  71. package/build/src/middlewares/index.js.map +1 -0
  72. package/build/src/middlewares/token-validation.d.ts +17 -0
  73. package/build/src/middlewares/token-validation.js +329 -0
  74. package/build/src/middlewares/token-validation.js.map +1 -0
  75. package/build/src/models/user.model.d.ts +196 -0
  76. package/build/src/models/user.model.js +403 -0
  77. package/build/src/models/user.model.js.map +1 -0
  78. package/build/src/service/keycloak.service.d.ts +88 -0
  79. package/build/src/service/keycloak.service.js +1059 -0
  80. package/build/src/service/keycloak.service.js.map +1 -0
  81. package/build/src/service/user.service.d.ts +11 -0
  82. package/build/src/service/user.service.js +118 -0
  83. package/build/src/service/user.service.js.map +1 -0
  84. package/build/src/utils/index.d.ts +1 -0
  85. package/build/src/utils/index.js +1 -0
  86. package/build/src/utils/index.js.map +1 -1
  87. package/build/src/utils/jwt.d.ts +1 -0
  88. package/build/src/utils/jwt.js +14 -0
  89. package/build/src/utils/jwt.js.map +1 -0
  90. package/build/src/utils/response.d.ts +1 -0
  91. package/build/src/utils/response.js +19 -0
  92. package/build/src/utils/response.js.map +1 -1
  93. package/package.json +16 -4
  94. package/src/dto/index.ts +1 -0
  95. package/src/index.ts +2 -1
  96. package/src/interfaces/index.ts +2 -0
  97. package/src/interfaces/keycloak.ts +161 -0
  98. package/src/interfaces/user.ts +5 -0
  99. package/src/middlewares/index.ts +1 -0
  100. package/src/middlewares/token-validation.ts +456 -0
  101. package/src/models/user.model.ts +494 -0
  102. package/src/service/keycloak.service.ts +1104 -0
  103. package/src/service/user.service.ts +99 -0
  104. package/src/utils/index.ts +2 -1
  105. package/src/utils/jwt.ts +10 -0
  106. package/src/utils/response.ts +19 -0
@@ -0,0 +1,494 @@
1
+ // @ts-nocheck
2
+
3
+
4
+ import { LocationDTO } from '../dto';
5
+ import { model, Schema, type Schema as MSchema } from 'mongoose';
6
+
7
+ export const USER_DOCUMENT_NAME = 'User';
8
+ export const USER_COLLECTION_NAME = 'users';
9
+
10
+ export enum USER_TYPE {
11
+ USER = "USER",
12
+ ADMIN = "ADMIN",
13
+ SUPER_ADMIN = "SUPER_ADMIN",
14
+ }
15
+
16
+ export class SocialLinksDTO {
17
+ facebook: string | null = ''
18
+ linkedin: string | null = ''
19
+ instagram: string | null = ''
20
+ twitter: string | null = ''
21
+ }
22
+
23
+ export interface ISocialLinks {
24
+ facebook: string | null,
25
+ linkedin: string | null,
26
+ instagram: string | null,
27
+ twitter: string | null,
28
+ }
29
+
30
+
31
+ export class MentorshipDTO {
32
+ isOpenToMentorship: boolean = false
33
+ isLookingForMentorship: boolean = false
34
+ }
35
+
36
+ export enum ThirdPartyAccounts_Enums {
37
+ GOOGLE = "GOOGLE",
38
+ MICROSOFT = "MICROSOFT",
39
+ }
40
+
41
+ export class UserEmailAuthTokensDTO {
42
+ refresh_token: string = ''
43
+ access_token: string = ''
44
+ accountType: ThirdPartyAccounts_Enums.GOOGLE | ThirdPartyAccounts_Enums.MICROSOFT = ThirdPartyAccounts_Enums.GOOGLE
45
+ email: string = ''
46
+ token_expiry: number = 0
47
+ }
48
+
49
+ export class UserYoutubeAuthTokensDTO {
50
+ refresh_token: string = ''
51
+ access_token: string = ''
52
+ email: string = ''
53
+ token_expiry: number = 0
54
+ }
55
+
56
+ export class RewardDTO {
57
+ points: number | null = 0;
58
+ pointsToSend: number | null = 0;
59
+ pointsToReedem: number | null = 0;
60
+ amount: number | null = 0;
61
+ }
62
+
63
+ export class User implements IUser {
64
+ _id: Schema.Types.ObjectId = new Schema.Types.ObjectId('');
65
+ userId?: Schema.Types.ObjectId = new Schema.Types.ObjectId('');
66
+ id: Schema.Types.ObjectId = new Schema.Types.ObjectId('');
67
+ fcm_token: Array<any> = [];
68
+ google_id?: string | undefined = '';
69
+ cultureGroup?: Array<Schema.Types.ObjectId> = [];
70
+ facebook_id?: string | undefined = '';
71
+ stripe_customerId: string | null = '';
72
+ email?: string | undefined = '';
73
+ // employeeId?: number | null = null;
74
+ employeeId?: string = '';
75
+ password?: string | null | undefined = '';
76
+ profilePicUrl?: string | undefined = '';
77
+ role?: Schema.Types.ObjectId | undefined;
78
+ roleId?: Schema.Types.ObjectId | null = new Schema.Types.ObjectId('');
79
+ verified?: boolean | undefined = true;
80
+ status?: boolean | undefined = true;
81
+ createdAt: Date = new Date();
82
+ updatedAt?: Date | undefined = new Date();
83
+ type?: USER_TYPE | null = null;
84
+ firstName?: string = '';
85
+ lastName?: string = '';
86
+ dateOfBirth?: Date | null = null;
87
+ phonenumber?: string = '';
88
+ location?: LocationDTO = new LocationDTO()
89
+ socialLinks?: SocialLinksDTO = new SocialLinksDTO()
90
+ business?: Schema.Types.ObjectId = new Schema.Types.ObjectId('');
91
+ businessId?: Schema.Types.ObjectId = new Schema.Types.ObjectId('');
92
+ bio?: string = '';
93
+ gender?: string = '';
94
+ skills?: Array<Schema.Types.ObjectId> = [];
95
+ reward?: RewardDTO = new RewardDTO();
96
+ profileviews?: number = 0;
97
+ website?: string = '';
98
+ lifeExperience?: Array<Schema.Types.ObjectId> = [];
99
+ position?: string = '';
100
+ isMentor?: boolean = false;
101
+ permissions?: string[] | undefined = [];
102
+
103
+ businessQuestionsAnswered?: boolean = true;
104
+ following?: Schema.Types.ObjectId[] = [];
105
+
106
+ invitationHash?: string = ''
107
+ invitationHashExpiryDate?: Date = new Date()
108
+ isinvitationHashExpired?: boolean = false
109
+ coverPicUrl?: string = ''
110
+ isDeleted?: boolean = false
111
+ isActive?: boolean = false
112
+ departmentId?: Schema.Types.ObjectId | undefined = undefined;
113
+ mentorship?: MentorshipDTO = new MentorshipDTO()
114
+ ethnicity?: string = ''
115
+ // race?: string = ''
116
+ personOfColor?: string = ''
117
+ tenure?: number = 0
118
+ satisfactionLevel?: number = 1
119
+ satisfactionLevelDate?: Date = new Date()
120
+ performanceLevel?: number = 1
121
+ performanceLevelDate?: Date = new Date()
122
+ salary?: number = 0
123
+ hireDate?: Date = new Date();
124
+ jobLevel?: ''
125
+ supervisorId?: Schema.Types.ObjectId | undefined = new Schema.Types.ObjectId('')
126
+ enpsRating?: number = 0
127
+ disability?: 'yes' | 'no' = 'no'
128
+ diverse?: boolean = false
129
+ women?: boolean = false
130
+ poc?: boolean = false
131
+ isMfaVerified?: boolean = false
132
+ mfaVerificationType?: string = "none"
133
+ verificationOtp?: {
134
+ otp: string;
135
+ expiresAt: Date;
136
+ } = {
137
+ otp: '',
138
+ expiresAt: new Date(),
139
+ }
140
+
141
+ thirdPartyAuthTokens?: UserEmailAuthTokensDTO = new UserEmailAuthTokensDTO()
142
+ youtubeAuthTokens?: UserYoutubeAuthTokensDTO = new UserYoutubeAuthTokensDTO()
143
+
144
+
145
+ }
146
+
147
+ export default interface IUser {
148
+ _id: Schema.Types.ObjectId,
149
+ userId?: Schema.Types.ObjectId;
150
+ email?: string;
151
+ // employeeId?: number | null;
152
+ employeeId?: string;
153
+ profileviews?: number;
154
+ password?: string | null;
155
+ profilePicUrl?: string;
156
+ role?: Schema.Types.ObjectId;
157
+ fcm_token?: Array<any>;
158
+ roleId?: Schema.Types.ObjectId | null;
159
+ verified?: boolean;
160
+ blocked_transactions?: boolean;
161
+ status?: boolean;
162
+ createdAt: Date;
163
+ updatedAt?: Date;
164
+ cultureGroup?: Array<Schema.Types.ObjectId>;
165
+ type?: USER_TYPE | null;
166
+
167
+ firstName?: string,
168
+ lastName?: string,
169
+ dateOfBirth?: Date | null,
170
+
171
+ phonenumber?: string,
172
+ location?: LocationDTO,
173
+ reward?: RewardDTO,
174
+ business?: Schema.Types.ObjectId,
175
+ bio?: string,
176
+ gender?: string,
177
+ skills?: Array<Schema.Types.ObjectId>,
178
+ website?: string,
179
+ socialLinks?: ISocialLinks
180
+ lifeExperience?: Array<Schema.Types.ObjectId>,
181
+ businessId?: Schema.Types.ObjectId,
182
+ position?: string,
183
+ isMentor?: boolean,
184
+ permissions?: string[],
185
+
186
+ businessQuestionsAnswered?: boolean,
187
+ following?: Schema.Types.ObjectId[],
188
+
189
+ invitationHash?: string
190
+ invitationHashExpiryDate?: Date
191
+ isinvitationHashExpired?: boolean
192
+ coverPicUrl?: string
193
+ isDeleted?: boolean
194
+ isActive?: boolean
195
+
196
+ departmentId?: Schema.Types.ObjectId | undefined
197
+ mentorship?: MentorshipDTO
198
+ ethnicity?: string
199
+ // race?: string
200
+ personOfColor?: string
201
+
202
+ tenure?: number
203
+ satisfactionLevel?: number
204
+ satisfactionLevelDate?: Date
205
+ performanceLevel?: number
206
+ performanceLevelDate?: Date
207
+ salary?: number
208
+ hireDate?: Date
209
+ jobLevel?: ''
210
+ supervisorId?: Schema.Types.ObjectId | undefined
211
+ enpsRating?: number
212
+ disability?: 'yes' | 'no'
213
+ diverse?: boolean
214
+ women?: boolean
215
+ poc?: boolean
216
+ isMfaVerified?: boolean
217
+ mfaVerificationType?: string
218
+ verificationOtp?: { otp: string; expiresAt: Date } | null
219
+ thirdPartyAuthTokens?: UserEmailAuthTokensDTO
220
+ youtubeAuthTokens?: UserYoutubeAuthTokensDTO
221
+ }
222
+
223
+ const otpSchema = new Schema({
224
+ otp: { type: String, required: true },
225
+ expiresAt: { type: Date, required: true }
226
+ });
227
+
228
+ const userSchemaDef = {
229
+ email: {
230
+ type: Schema.Types.String,
231
+ required: false,
232
+ // unique: true,
233
+ trim: true,
234
+ // select: false,
235
+ },
236
+ userId: {
237
+ type: Schema.Types.ObjectId,
238
+ required: false,
239
+ },
240
+ employeeId: {
241
+ type: Schema.Types.String,
242
+ required: false,
243
+ },
244
+ password: {
245
+ type: Schema.Types.String,
246
+ required: false,
247
+ select: false,
248
+ },
249
+ profileviews: {
250
+ type: Schema.Types.Number,
251
+ required: false,
252
+ default: 0,
253
+ },
254
+ profilePicUrl: {
255
+ type: Schema.Types.String,
256
+ required: false,
257
+ trim: true,
258
+ },
259
+ cultureGroup: [{ type: Schema.Types.ObjectId, required: false, ref: 'Cultur' }],
260
+ firstName: {
261
+ type: Schema.Types.String,
262
+ required: false,
263
+ trim: true,
264
+ },
265
+ lastName: {
266
+ type: Schema.Types.String,
267
+ required: false,
268
+ trim: true,
269
+ },
270
+ dateOfBirth: {
271
+ type: Schema.Types.Date,
272
+ required: false,
273
+ },
274
+ phonenumber: {
275
+ type: Schema.Types.String,
276
+ required: false,
277
+ },
278
+ location: {
279
+ type: Schema.Types.Mixed,
280
+ required: false,
281
+ },
282
+ role: {
283
+ type: Schema.Types.ObjectId,
284
+ required: false,
285
+ },
286
+ roleId: {
287
+ type: Schema.Types.ObjectId,
288
+ required: false,
289
+ },
290
+ business: {
291
+ type: Schema.Types.ObjectId,
292
+ ref: 'Businesses',
293
+ required: false,
294
+ },
295
+ following: {
296
+ type: [Schema.Types.ObjectId],
297
+ ref: USER_DOCUMENT_NAME,
298
+ required: false,
299
+ default: []
300
+ },
301
+ businessId: {
302
+ type: Schema.Types.ObjectId,
303
+ ref: 'Businesses',
304
+ required: false,
305
+ // strictPopulate: false,
306
+ },
307
+ fcm_token: { type: Schema.Types.Array, required: false },
308
+ bio: { type: Schema.Types.String, required: false },
309
+ gender: { type: Schema.Types.String, required: false },
310
+ skills: [{ type: Schema.Types.ObjectId, required: false, ref: 'userSkills' }],
311
+ website: { type: Schema.Types.String, required: false },
312
+ socialLinks: {
313
+ facebook: { type: Schema.Types.String, required: false },
314
+ linkedin: { type: Schema.Types.String, required: false },
315
+ instagram: { type: Schema.Types.String, required: false },
316
+ twitter: { type: Schema.Types.String, required: false },
317
+ },
318
+ lifeExperience: [{ type: Schema.Types.ObjectId, required: false, ref: 'Life' }],
319
+
320
+ position: { type: Schema.Types.String, required: false },
321
+ isMentor: { type: Schema.Types.Boolean, required: false },
322
+
323
+ permissions: [{ type: Schema.Types.Mixed, required: false }],
324
+ businessQuestionsAnswered: {
325
+ type: Schema.Types.Boolean,
326
+ required: false,
327
+ default: true
328
+ },
329
+
330
+ type: {
331
+ type: Schema.Types.String,
332
+ required: false,
333
+ // enum: [USER_TYPE.ADMIN, USER_TYPE.SUPER_ADMIN, USER_TYPE.USER]
334
+ },
335
+ reward: {
336
+ points: { type: Schema.Types.Number, default: 0, min: 0 },
337
+ pointsToSend: { type: Schema.Types.Number, default: 0, min: 0 },
338
+ pointsToReedem: { type: Schema.Types.Number, default: 0, min: 0 },
339
+ amount: { type: Schema.Types.Number, default: 0, min: 0 },
340
+ },
341
+ verified: {
342
+ type: Schema.Types.Boolean,
343
+ default: false,
344
+ },
345
+ blocked_transactions: {
346
+ type: Schema.Types.Boolean,
347
+ default: false,
348
+ },
349
+ status: {
350
+ type: Schema.Types.Boolean,
351
+ default: true,
352
+ },
353
+ createdAt: {
354
+ type: Date,
355
+ required: false,
356
+ select: false,
357
+ },
358
+ updatedAt: {
359
+ type: Date,
360
+ required: false,
361
+ select: false,
362
+ },
363
+ invitationHash: { type: Schema.Types.String, required: false },
364
+ invitationHashExpiryDate: { type: Schema.Types.Date, required: false },
365
+ isinvitationHashExpired: { type: Schema.Types.Boolean, default: false },
366
+ coverPicUrl: { type: Schema.Types.String, required: false },
367
+ isDeleted: {
368
+ type: Schema.Types.Boolean,
369
+ default: false,
370
+ },
371
+ isActive: {
372
+ type: Schema.Types.Boolean,
373
+ default: false,
374
+ },
375
+ departmentId: {
376
+ type: Schema.Types.ObjectId,
377
+ required: false,
378
+ },
379
+ mentorship: {
380
+ isOpenToMentorship: { type: Schema.Types.Boolean, default: false },
381
+ isLookingForMentorship: { type: Schema.Types.Boolean, default: false }
382
+ },
383
+ ethnicity: {
384
+ type: Schema.Types.String,
385
+ required: false,
386
+ },
387
+ personOfColor: {
388
+ type: Schema.Types.String,
389
+ required: false,
390
+ },
391
+ tenure: {
392
+ type: Schema.Types.Number,
393
+ required: false,
394
+ },
395
+ satisfactionLevel: {
396
+ type: Schema.Types.Number,
397
+ required: false,
398
+ },
399
+ satisfactionLevelDate: {
400
+ type: Schema.Types.Date,
401
+ required: false,
402
+ },
403
+ performanceLevel: {
404
+ type: Schema.Types.Number,
405
+ required: false,
406
+ },
407
+ performanceLevelDate: {
408
+ type: Schema.Types.Date,
409
+ required: false,
410
+ },
411
+ salary: {
412
+ type: Schema.Types.Number,
413
+ required: false,
414
+ },
415
+ hireDate: {
416
+ type: Schema.Types.Date,
417
+ required: false,
418
+ },
419
+ jobLevel: {
420
+ type: Schema.Types.String,
421
+ required: false,
422
+ default: ''
423
+ },
424
+ supervisorId: {
425
+ type: Schema.Types.ObjectId,
426
+ required: false,
427
+ },
428
+ enpsRating: {
429
+ type: Schema.Types.Number,
430
+ required: false,
431
+ },
432
+ disability: {
433
+ type: Schema.Types.String,
434
+ required: false,
435
+ default: 'no'
436
+ },
437
+ diverse: {
438
+ type: Schema.Types.Boolean,
439
+ required: false,
440
+ // default: false
441
+ },
442
+ women: {
443
+ type: Schema.Types.Boolean,
444
+ required: false,
445
+ // default: false
446
+ },
447
+ poc: {
448
+ type: Schema.Types.Boolean,
449
+ required: false,
450
+ // default: false
451
+ },
452
+ isMfaVerified: {
453
+ type: Schema.Types.Boolean,
454
+ default: false,
455
+ required: false,
456
+ // default: false
457
+ },
458
+ mfaVerificationType: {
459
+ type: Schema.Types.String,
460
+ default: 'none',
461
+ required: false,
462
+ // default: false
463
+ },
464
+ verificationOtp: {
465
+ type: otpSchema,
466
+ default: null,
467
+ required: false,
468
+ // default: false
469
+ },
470
+ thirdPartyAuthTokens: {
471
+ access_token: { type: Schema.Types.String },
472
+ refresh_token: { type: Schema.Types.String },
473
+ accountType: { type: Schema.Types.String },
474
+ email: { type: Schema.Types.String },
475
+ token_expiry: { type: Schema.Types.Number }
476
+ },
477
+ youtubeAuthTokens: {
478
+ access_token: { type: Schema.Types.String },
479
+ refresh_token: { type: Schema.Types.String },
480
+ email: { type: Schema.Types.String },
481
+ token_expiry: { type: Schema.Types.Number }
482
+ }
483
+ }
484
+
485
+ const schema: MSchema<IUser> = new Schema<IUser>(
486
+ userSchemaDef,
487
+ {
488
+ versionKey: false,
489
+ timestamps: true,
490
+ collection: USER_COLLECTION_NAME
491
+ },
492
+ );
493
+
494
+ export const UserModel = model<IUser>(USER_DOCUMENT_NAME, schema, USER_COLLECTION_NAME);