@driveflux/auth 4.0.88 → 4.0.90

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 (46) hide show
  1. package/dist/AuthProvider.d.ts.map +1 -1
  2. package/dist/AuthProvider.js +60 -79
  3. package/dist/authorization/define.js +28 -57
  4. package/dist/authorization/fields/index.js +7 -4
  5. package/dist/authorization/helpers.js +8 -10
  6. package/dist/authorization/index.js +6 -6
  7. package/dist/authorization/permissions-list.js +7 -5
  8. package/dist/authorization/quick.js +1 -1
  9. package/dist/authorization/roles/admin/business-development-executive.js +7 -20
  10. package/dist/authorization/roles/admin/ceo.js +2 -4
  11. package/dist/authorization/roles/admin/common.d.ts.map +1 -1
  12. package/dist/authorization/roles/admin/common.js +3 -5
  13. package/dist/authorization/roles/admin/concierge.js +10 -35
  14. package/dist/authorization/roles/admin/customer-success-executive.js +10 -40
  15. package/dist/authorization/roles/admin/data-analyst.js +4 -7
  16. package/dist/authorization/roles/admin/designer.js +4 -7
  17. package/dist/authorization/roles/admin/engineer.js +4 -7
  18. package/dist/authorization/roles/admin/finance-executive.js +4 -11
  19. package/dist/authorization/roles/admin/head-of-business-development.js +4 -14
  20. package/dist/authorization/roles/admin/head-of-data-analytics.js +4 -14
  21. package/dist/authorization/roles/admin/head-of-engineering.js +6 -17
  22. package/dist/authorization/roles/admin/head-of-finance.js +3 -8
  23. package/dist/authorization/roles/admin/head-of-human-resources.js +5 -13
  24. package/dist/authorization/roles/admin/head-of-marketing.js +5 -17
  25. package/dist/authorization/roles/admin/head-of-operations.js +3 -8
  26. package/dist/authorization/roles/admin/head-of-product.js +6 -17
  27. package/dist/authorization/roles/admin/head-of-sales.js +5 -17
  28. package/dist/authorization/roles/admin/human-resources-executive.js +5 -12
  29. package/dist/authorization/roles/admin/marketing-executive.js +4 -7
  30. package/dist/authorization/roles/admin/product-manager.js +4 -7
  31. package/dist/authorization/roles/admin/sales-executive.js +8 -24
  32. package/dist/authorization/roles/consumer/business-admin.js +6 -19
  33. package/dist/authorization/roles/consumer/business-user.js +6 -18
  34. package/dist/authorization/roles/consumer/member.js +6 -16
  35. package/dist/authorization/types.js +1 -1
  36. package/dist/authorization/update-user-permissions.js +15 -22
  37. package/dist/authorization/utils.js +11 -26
  38. package/dist/server/authenticate-user.js +7 -11
  39. package/dist/server/cors.js +12 -23
  40. package/dist/server/credentials-provider.js +2 -2
  41. package/dist/server/next-auth.d.ts +12 -1
  42. package/dist/server/next-auth.d.ts.map +1 -1
  43. package/dist/server/next-auth.js +109 -104
  44. package/dist/server/prisma-adapter.js +52 -88
  45. package/dist/server/verfiy-token.js +24 -39
  46. package/package.json +16 -16
@@ -1,4 +1,4 @@
1
- export const defineRoleAbilitiesMember = async (can, user)=>{
1
+ export const defineRoleAbilitiesMember = async (can, user) => {
2
2
  can('read', 'Cycle', [
3
3
  'id',
4
4
  'startDate',
@@ -6,23 +6,13 @@ export const defineRoleAbilitiesMember = async (can, user)=>{
6
6
  'utilization.pricePerKm',
7
7
  'utilization.paid',
8
8
  'utilization.allowedMileage',
9
- 'utilization.mileage'
10
- ], {
11
- subscription: {
12
- userId: user.id
13
- }
14
- });
15
- can('read', 'Vehicle', {
16
- status: 'listed'
17
- });
9
+ 'utilization.mileage',
10
+ ], { subscription: { userId: user.id } });
11
+ can('read', 'Vehicle', { status: 'listed' });
18
12
  can('create', 'Business');
19
13
  if (user.businessId) {
20
- can('update', 'Business', {
21
- id: user.businessId
22
- });
14
+ can('update', 'Business', { id: user.businessId });
23
15
  }
24
- can('read', 'Subscription', {
25
- userId: user.id
26
- });
16
+ can('read', 'Subscription', { userId: user.id });
27
17
  can('read', 'Coupon');
28
18
  };
@@ -1 +1 @@
1
- export { };
1
+ export {};
@@ -2,39 +2,32 @@ import { prisma } from '@driveflux/db';
2
2
  import { makeProblem, PROBLEM_NOT_FOUND } from '@driveflux/problem';
3
3
  import { Err, Ok } from '@driveflux/result';
4
4
  import { defineAbilityFor } from './define.js';
5
- export const updateUserPermissions = async (userId, newGroups)=>{
6
- const user = typeof userId === 'string' ? await prisma.user.findUnique({
7
- where: {
8
- id: userId
9
- }
10
- }) : userId;
5
+ export const updateUserPermissions = async (userId, newGroups) => {
6
+ const user = typeof userId === 'string'
7
+ ? await prisma.user.findUnique({
8
+ where: {
9
+ id: userId,
10
+ },
11
+ })
12
+ : userId;
11
13
  if (!user) {
12
14
  return new Err(makeProblem(PROBLEM_NOT_FOUND, 'User not found when trying to update the permissions'));
13
15
  }
14
- const groups = newGroups ? [
15
- ...newGroups
16
- ] : [
17
- ...user.groups
18
- ];
16
+ const groups = newGroups ? [...newGroups] : [...user.groups];
19
17
  const ability = await defineAbilityFor({
20
18
  ...user,
21
- groups
19
+ groups,
22
20
  });
23
21
  await prisma.user.update({
24
22
  where: {
25
- id: user.id
23
+ id: user.id,
26
24
  },
27
25
  data: {
28
- groups: [
29
- ...groups
30
- ],
31
- permissions: ability.rules
32
- }
26
+ groups: [...groups],
27
+ permissions: ability.rules,
28
+ },
33
29
  });
34
30
  user.groups = groups;
35
31
  user.permissions = ability.rules;
36
- return new Ok({
37
- user,
38
- ability
39
- });
32
+ return new Ok({ user, ability });
40
33
  };
@@ -1,37 +1,25 @@
1
1
  import { subject } from '@casl/ability';
2
2
  import { pascalCase } from 'change-case';
3
- export const detectSubjectType = (subject)=>{
3
+ export const detectSubjectType = (subject) => {
4
4
  if (!('object' in subject)) {
5
5
  throw new Error(`Trying to get an object from model ${subject} that is not a real model`);
6
6
  }
7
7
  return pascalCase(subject.object);
8
8
  };
9
9
  const documents = {
10
- identification: [
11
- 'visa',
12
- 'passport',
13
- 'idFront',
14
- 'idBack',
15
- 'drivingLicense'
16
- ],
17
- drivingHistory: [
18
- 'pdrm',
19
- 'jpj',
20
- 'bgs'
21
- ],
10
+ identification: ['visa', 'passport', 'idFront', 'idBack', 'drivingLicense'],
11
+ drivingHistory: ['pdrm', 'jpj', 'bgs'],
22
12
  financial: [
23
13
  'experianReport',
24
14
  'bankStatement',
25
15
  'bankStatement2',
26
16
  'bankStatement3',
27
- 'epfStatement'
17
+ 'epfStatement',
28
18
  ],
29
- offerLetter: [
30
- 'offerLetter'
31
- ]
19
+ offerLetter: ['offerLetter'],
32
20
  };
33
- export const getDocumentsFields = (documentsGroup)=>documents[documentsGroup].map((d)=>`documents.${d}`);
34
- export const getPricingFields = ()=>{
21
+ export const getDocumentsFields = (documentsGroup) => documents[documentsGroup].map((d) => `documents.${d}`);
22
+ export const getPricingFields = () => {
35
23
  return [
36
24
  'pricing',
37
25
  'basePrice',
@@ -39,17 +27,14 @@ export const getPricingFields = ()=>{
39
27
  'basePricePlan12',
40
28
  'basePricePlan24',
41
29
  'basePricePlan36',
42
- 'basePricePlan60'
30
+ 'basePricePlan60',
43
31
  ];
44
32
  };
45
33
  // we are creating a helper function to fake an object
46
- export const s = (modelName, key = 'id')=>{
34
+ export const s = (modelName, key = 'id') => {
47
35
  const objectName = getObjectName(modelName);
48
- return subject(modelName, {
49
- object: objectName,
50
- [key]: 'XXXXXXXXX'
51
- });
36
+ return subject(modelName, { object: objectName, [key]: 'XXXXXXXXX' });
52
37
  };
53
- const getObjectName = (modelName)=>{
38
+ const getObjectName = (modelName) => {
54
39
  return modelName[0].toLowerCase() + modelName.slice(1);
55
40
  };
@@ -5,29 +5,25 @@ import bcrypt from 'bcryptjs';
5
5
  import { PROBLEM_INVALID_LOGIN } from '../constants.js';
6
6
  import { translations } from '../translations.js';
7
7
  import { verifyToken } from './verfiy-token.js';
8
- export const authenticateUser = async ({ login, password })=>{
8
+ export const authenticateUser = async ({ login, password, }) => {
9
9
  const isEmail = login.includes('@');
10
10
  // Check if the user exists
11
11
  const user = await prisma.user.findFirst({
12
12
  where: {
13
- ...isEmail ? {
14
- email: login.toLowerCase().trim()
15
- } : {
16
- phoneNumber: login.replace(/[\s-]/g, '')
17
- }
18
- }
13
+ ...(isEmail
14
+ ? { email: login.toLowerCase().trim() }
15
+ : { phoneNumber: login.replace(/[\s-]/g, '') }),
16
+ },
19
17
  });
20
18
  if (!user) {
21
19
  return new Err(makeProblem(PROBLEM_INVALID_LOGIN, translations.wrongUsernameOrPassword));
22
20
  }
23
21
  // Check the user's password
24
- if (isEmail && !await bcrypt.compare(password, user.password)) {
22
+ if (isEmail && !(await bcrypt.compare(password, user.password))) {
25
23
  return new Err(makeProblem(PROBLEM_INVALID_LOGIN, 'The email / password combination is invalid.'));
26
24
  }
27
25
  if (!isEmail) {
28
- const tokenResult = await verifyToken(password, {
29
- scope: 'verify-phone'
30
- });
26
+ const tokenResult = await verifyToken(password, { scope: 'verify-phone' });
31
27
  if (!tokenResult.ok) {
32
28
  return new Err(makeProblem(PROBLEM_INVALID_LOGIN, 'The OTP is invalid.'));
33
29
  }
@@ -1,39 +1,28 @@
1
1
  import { config } from '@driveflux/config/backend';
2
2
  import Cors from 'cors';
3
3
  const corsOptions = {
4
- origin: (origin, callback)=>{
5
- const allowedOrigins = [
6
- config.appUrl
7
- ];
8
- if (config.appEnv === 'development' || origin && allowedOrigins.includes(origin)) {
4
+ origin: (origin, callback) => {
5
+ const allowedOrigins = [config.appUrl];
6
+ if (config.appEnv === 'development' ||
7
+ (origin && allowedOrigins.includes(origin))) {
9
8
  callback(null, true);
10
- } else {
9
+ }
10
+ else {
11
11
  callback(new Error('CORS not allowed'));
12
12
  }
13
13
  },
14
- allowedHeaders: [
15
- 'content-type',
16
- 'x-correlation-id',
17
- 'authorization'
18
- ],
14
+ allowedHeaders: ['content-type', 'x-correlation-id', 'authorization'],
19
15
  exposedHeaders: '*',
20
- methods: [
21
- 'GET',
22
- 'HEAD',
23
- 'PUT',
24
- 'PATCH',
25
- 'POST',
26
- 'DELETE'
27
- ],
28
- credentials: true
16
+ methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'],
17
+ credentials: true,
29
18
  };
30
19
  // Initializing the cors middleware
31
20
  // I don't have time to debug cors now, I've got a million things to do.
32
21
  // TODO Implement this properly please
33
22
  const corsHandler = config.appEnv === 'development' ? Cors(corsOptions) : Cors();
34
- export const cors = (req, res)=>{
35
- return new Promise((resolve, reject)=>{
36
- corsHandler(req, res, (result)=>{
23
+ export const cors = (req, res) => {
24
+ return new Promise((resolve, reject) => {
25
+ corsHandler(req, res, (result) => {
37
26
  if (result instanceof Error) {
38
27
  return reject(result);
39
28
  }
@@ -4,7 +4,7 @@ export function Credentials(options) {
4
4
  name: 'Credentials',
5
5
  type: 'flux-credentials',
6
6
  credentials: {},
7
- authorize: ()=>null,
8
- options
7
+ authorize: () => null,
8
+ options,
9
9
  };
10
10
  }
@@ -47,6 +47,7 @@ export declare const authOptions: {
47
47
  }) => Promise<{
48
48
  user: {
49
49
  object?: "user" | undefined;
50
+ status?: import("@driveflux/db").UserStatus | undefined;
50
51
  id?: string | undefined;
51
52
  businessId?: string | null | undefined;
52
53
  hostId?: string | null | undefined;
@@ -60,7 +61,6 @@ export declare const authOptions: {
60
61
  dateOfBirth?: Date | null | undefined;
61
62
  nationality?: string | null | undefined;
62
63
  consented?: boolean | undefined;
63
- status?: import("@driveflux/db").UserStatus | undefined;
64
64
  race?: import("@driveflux/db").Race | null | undefined;
65
65
  maritalStatus?: import("@driveflux/db").MaritalStatus | null | undefined;
66
66
  emergencyContactName?: string | null | undefined;
@@ -260,6 +260,17 @@ export declare const authOptions: {
260
260
  updatedAt: Date | null;
261
261
  metadata: PrismaJson.AnyMetadata | null;
262
262
  } | null;
263
+ proofOfResidency: {
264
+ name: string | null;
265
+ description: string | null;
266
+ url: string;
267
+ fileType: string | null;
268
+ mimeType: string | null;
269
+ uploaded: boolean;
270
+ createdAt: Date | null;
271
+ updatedAt: Date | null;
272
+ metadata: PrismaJson.AnyMetadata | null;
273
+ } | null;
263
274
  } | null | undefined;
264
275
  paymentMethods?: ({
265
276
  id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"next-auth.d.ts","sourceRoot":"","sources":["../../src/server/next-auth.ts"],"names":[],"mappings":"AAEA,OAAO,qBAAqB,CAAA;AAK5B,OAAO,KAAK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