@driveflux/auth 4.0.86 → 4.0.88

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 (103) hide show
  1. package/dist/AuthProvider.d.ts +0 -1
  2. package/dist/AuthProvider.js +76 -59
  3. package/dist/ability.d.ts +0 -1
  4. package/dist/authorization/constants.d.ts +1 -2
  5. package/dist/authorization/constants.js +45 -24
  6. package/dist/authorization/define.d.ts +0 -1
  7. package/dist/authorization/define.js +57 -28
  8. package/dist/authorization/fields/index.d.ts +0 -1
  9. package/dist/authorization/fields/index.js +4 -7
  10. package/dist/authorization/helpers.d.ts +0 -1
  11. package/dist/authorization/helpers.js +10 -8
  12. package/dist/authorization/index.d.ts +0 -1
  13. package/dist/authorization/index.js +6 -6
  14. package/dist/authorization/permissions-list.d.ts +0 -1
  15. package/dist/authorization/permissions-list.js +5 -7
  16. package/dist/authorization/quick.d.ts +0 -1
  17. package/dist/authorization/quick.js +1 -1
  18. package/dist/authorization/roles/admin/business-development-executive.d.ts +0 -1
  19. package/dist/authorization/roles/admin/business-development-executive.js +20 -7
  20. package/dist/authorization/roles/admin/ceo.d.ts +0 -1
  21. package/dist/authorization/roles/admin/ceo.js +4 -2
  22. package/dist/authorization/roles/admin/common.d.ts +0 -1
  23. package/dist/authorization/roles/admin/common.js +5 -3
  24. package/dist/authorization/roles/admin/concierge.d.ts +0 -1
  25. package/dist/authorization/roles/admin/concierge.js +35 -10
  26. package/dist/authorization/roles/admin/customer-success-executive.d.ts +0 -1
  27. package/dist/authorization/roles/admin/customer-success-executive.js +40 -10
  28. package/dist/authorization/roles/admin/data-analyst.d.ts +0 -1
  29. package/dist/authorization/roles/admin/data-analyst.js +7 -4
  30. package/dist/authorization/roles/admin/designer.d.ts +0 -1
  31. package/dist/authorization/roles/admin/designer.js +7 -4
  32. package/dist/authorization/roles/admin/engineer.d.ts +0 -1
  33. package/dist/authorization/roles/admin/engineer.js +7 -4
  34. package/dist/authorization/roles/admin/finance-executive.d.ts +0 -1
  35. package/dist/authorization/roles/admin/finance-executive.js +11 -4
  36. package/dist/authorization/roles/admin/head-of-business-development.d.ts +0 -1
  37. package/dist/authorization/roles/admin/head-of-business-development.js +14 -4
  38. package/dist/authorization/roles/admin/head-of-data-analytics.d.ts +0 -1
  39. package/dist/authorization/roles/admin/head-of-data-analytics.js +14 -4
  40. package/dist/authorization/roles/admin/head-of-engineering.d.ts +0 -1
  41. package/dist/authorization/roles/admin/head-of-engineering.js +17 -6
  42. package/dist/authorization/roles/admin/head-of-finance.d.ts +0 -1
  43. package/dist/authorization/roles/admin/head-of-finance.js +8 -3
  44. package/dist/authorization/roles/admin/head-of-human-resources.d.ts +0 -1
  45. package/dist/authorization/roles/admin/head-of-human-resources.js +13 -5
  46. package/dist/authorization/roles/admin/head-of-marketing.d.ts +0 -1
  47. package/dist/authorization/roles/admin/head-of-marketing.js +17 -5
  48. package/dist/authorization/roles/admin/head-of-operations.d.ts +0 -1
  49. package/dist/authorization/roles/admin/head-of-operations.js +8 -3
  50. package/dist/authorization/roles/admin/head-of-product.d.ts +0 -1
  51. package/dist/authorization/roles/admin/head-of-product.js +17 -6
  52. package/dist/authorization/roles/admin/head-of-sales.d.ts +0 -1
  53. package/dist/authorization/roles/admin/head-of-sales.js +17 -5
  54. package/dist/authorization/roles/admin/human-resources-executive.d.ts +0 -1
  55. package/dist/authorization/roles/admin/human-resources-executive.js +12 -5
  56. package/dist/authorization/roles/admin/marketing-executive.d.ts +0 -1
  57. package/dist/authorization/roles/admin/marketing-executive.js +7 -4
  58. package/dist/authorization/roles/admin/product-manager.d.ts +0 -1
  59. package/dist/authorization/roles/admin/product-manager.js +7 -4
  60. package/dist/authorization/roles/admin/sales-executive.d.ts +0 -1
  61. package/dist/authorization/roles/admin/sales-executive.js +24 -8
  62. package/dist/authorization/roles/consumer/business-admin.d.ts +0 -1
  63. package/dist/authorization/roles/consumer/business-admin.js +19 -6
  64. package/dist/authorization/roles/consumer/business-user.d.ts +0 -1
  65. package/dist/authorization/roles/consumer/business-user.js +18 -6
  66. package/dist/authorization/roles/consumer/member.d.ts +0 -1
  67. package/dist/authorization/roles/consumer/member.js +16 -6
  68. package/dist/authorization/types.d.ts +0 -1
  69. package/dist/authorization/types.js +1 -1
  70. package/dist/authorization/update-user-permissions.d.ts +0 -1
  71. package/dist/authorization/update-user-permissions.js +22 -15
  72. package/dist/authorization/utils.d.ts +0 -1
  73. package/dist/authorization/utils.js +26 -11
  74. package/dist/constants.d.ts +0 -1
  75. package/dist/constants.js +2 -4
  76. package/dist/context.d.ts +0 -1
  77. package/dist/context.js +8 -9
  78. package/dist/default.d.ts +0 -1
  79. package/dist/default.js +1 -1
  80. package/dist/index.d.ts +0 -1
  81. package/dist/providers.d.ts +0 -1
  82. package/dist/react.d.ts +0 -1
  83. package/dist/server/authenticate-user.d.ts +0 -1
  84. package/dist/server/authenticate-user.js +11 -7
  85. package/dist/server/cors.d.ts +0 -1
  86. package/dist/server/cors.js +23 -12
  87. package/dist/server/credentials-provider.d.ts +0 -1
  88. package/dist/server/credentials-provider.js +2 -2
  89. package/dist/server/index.d.ts +0 -1
  90. package/dist/server/next-auth.js +104 -109
  91. package/dist/server/prisma-adapter.d.ts +0 -1
  92. package/dist/server/prisma-adapter.js +88 -52
  93. package/dist/server/types.d.ts +0 -1
  94. package/dist/server/verfiy-token.d.ts +0 -1
  95. package/dist/server/verfiy-token.js +39 -24
  96. package/dist/translations.d.ts +0 -1
  97. package/dist/translations.js +4 -4
  98. package/dist/types.d.ts +0 -1
  99. package/dist/use-auth.d.ts +0 -1
  100. package/dist/use-auth.js +1 -1
  101. package/dist/use-session.d.ts +0 -1
  102. package/dist/use-session.js +1 -1
  103. package/package.json +29 -29
@@ -1,12 +1,23 @@
1
1
  import { OWNER_ROLES } from '../../constants.js';
2
- export const defineRoleAbilitiesHeadOfProduct = async (can, cannot) => {
2
+ export const defineRoleAbilitiesHeadOfProduct = async (can, cannot)=>{
3
3
  can('manage', 'all');
4
- cannot(['create', 'update', 'delete'], 'User', undefined, {
4
+ cannot([
5
+ 'create',
6
+ 'update',
7
+ 'delete'
8
+ ], 'User', undefined, {
5
9
  groups: {
6
- hasSome: [...OWNER_ROLES],
7
- },
10
+ hasSome: [
11
+ ...OWNER_ROLES
12
+ ]
13
+ }
8
14
  });
9
- cannot('update', 'Host', ['accountManagerId']);
10
- cannot('manage', ['Vacancy', 'Applicant']);
15
+ cannot('update', 'Host', [
16
+ 'accountManagerId'
17
+ ]);
18
+ cannot('manage', [
19
+ 'Vacancy',
20
+ 'Applicant'
21
+ ]);
11
22
  can('manageAdmin', 'Reports');
12
23
  };
@@ -1,4 +1,3 @@
1
1
  import type { AbilityBuilder } from '@casl/ability';
2
2
  import type { AppAbility } from '../../types.js';
3
3
  export declare const defineRoleAbilitiesHeadOfSales: (can: AbilityBuilder<AppAbility>["can"], cannot: AbilityBuilder<AppAbility>["cannot"]) => Promise<void>;
4
- //# sourceMappingURL=head-of-sales.d.ts.map
@@ -1,10 +1,22 @@
1
- export const defineRoleAbilitiesHeadOfSales = async (can, cannot) => {
1
+ export const defineRoleAbilitiesHeadOfSales = async (can, cannot)=>{
2
2
  can('manage', 'all');
3
- cannot(['create', 'update'], 'Payout');
4
- cannot(['release', 'reverse', 'deletePayoutChargeLine'], 'Payout');
3
+ cannot([
4
+ 'create',
5
+ 'update'
6
+ ], 'Payout');
7
+ cannot([
8
+ 'release',
9
+ 'reverse',
10
+ 'deletePayoutChargeLine'
11
+ ], 'Payout');
5
12
  cannot('cancelInvoice', 'Invoice');
6
13
  cannot('markInvoice', 'Invoice');
7
- cannot('update', 'Host', ['accountManagerId']);
8
- cannot('manage', ['Vacancy', 'Applicant']);
14
+ cannot('update', 'Host', [
15
+ 'accountManagerId'
16
+ ]);
17
+ cannot('manage', [
18
+ 'Vacancy',
19
+ 'Applicant'
20
+ ]);
9
21
  can('manageAdmin', 'Reports');
10
22
  };
@@ -1,4 +1,3 @@
1
1
  import type { AbilityBuilder } from '@casl/ability';
2
2
  import type { AppAbility } from '../../types.js';
3
3
  export declare const defineRoleAbilitiesHumanResourceExecutive: (can: AbilityBuilder<AppAbility>["can"], cannot: AbilityBuilder<AppAbility>["cannot"]) => Promise<void>;
4
- //# sourceMappingURL=human-resources-executive.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { getDocumentsFields } from '../../utils.js';
2
- export const defineRoleAbilitiesHumanResourceExecutive = async (can, cannot) => {
2
+ export const defineRoleAbilitiesHumanResourceExecutive = async (can, cannot)=>{
3
3
  can('read', [
4
4
  'Subscription',
5
5
  'Invoice',
@@ -17,15 +17,22 @@ export const defineRoleAbilitiesHumanResourceExecutive = async (can, cannot) =>
17
17
  'Discount',
18
18
  'PlatformConfig',
19
19
  'Vacancy',
20
- 'Applicant',
20
+ 'Applicant'
21
+ ]);
22
+ cannot('read', [
23
+ 'User'
24
+ ], [
25
+ 'documents'
21
26
  ]);
22
- cannot('read', ['User'], ['documents']);
23
27
  cannot('create', 'Business');
24
28
  cannot('read', 'User', [
25
29
  ...getDocumentsFields('identification'),
26
30
  ...getDocumentsFields('drivingHistory'),
27
31
  ...getDocumentsFields('financial'),
28
- ...getDocumentsFields('offerLetter'),
32
+ ...getDocumentsFields('offerLetter')
33
+ ]);
34
+ can('manage', [
35
+ 'Vacancy',
36
+ 'Applicant'
29
37
  ]);
30
- can('manage', ['Vacancy', 'Applicant']);
31
38
  };
@@ -1,4 +1,3 @@
1
1
  import type { AbilityBuilder } from '@casl/ability';
2
2
  import type { AppAbility } from '../../types.js';
3
3
  export declare const defineRoleAbilitiesMarketingExecutive: (can: AbilityBuilder<AppAbility>["can"], cannot: AbilityBuilder<AppAbility>["cannot"]) => Promise<void>;
4
- //# sourceMappingURL=marketing-executive.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { getDocumentsFields } from '../../utils.js';
2
- export const defineRoleAbilitiesMarketingExecutive = async (can, cannot) => {
2
+ export const defineRoleAbilitiesMarketingExecutive = async (can, cannot)=>{
3
3
  can('read', [
4
4
  'Subscription',
5
5
  'Cycle',
@@ -16,7 +16,7 @@ export const defineRoleAbilitiesMarketingExecutive = async (can, cannot) => {
16
16
  'PaymentLink',
17
17
  'Invoice',
18
18
  'Transaction',
19
- 'Refund',
19
+ 'Refund'
20
20
  ]);
21
21
  can('manage', 'Coupon');
22
22
  can('readPricingInput', 'Vehicle');
@@ -25,7 +25,10 @@ export const defineRoleAbilitiesMarketingExecutive = async (can, cannot) => {
25
25
  ...getDocumentsFields('identification'),
26
26
  ...getDocumentsFields('drivingHistory'),
27
27
  ...getDocumentsFields('financial'),
28
- ...getDocumentsFields('offerLetter'),
28
+ ...getDocumentsFields('offerLetter')
29
+ ]);
30
+ cannot('read', [
31
+ 'Vacancy',
32
+ 'Applicant'
29
33
  ]);
30
- cannot('read', ['Vacancy', 'Applicant']);
31
34
  };
@@ -1,4 +1,3 @@
1
1
  import type { AbilityBuilder } from '@casl/ability';
2
2
  import type { AppAbility } from '../../types.js';
3
3
  export declare const defineRoleAbilitiesProductManager: (can: AbilityBuilder<AppAbility>["can"], cannot: AbilityBuilder<AppAbility>["cannot"]) => Promise<void>;
4
- //# sourceMappingURL=product-manager.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { getDocumentsFields } from '../../utils.js';
2
- export const defineRoleAbilitiesProductManager = async (can, cannot) => {
2
+ export const defineRoleAbilitiesProductManager = async (can, cannot)=>{
3
3
  can('read', [
4
4
  'Subscription',
5
5
  'Cycle',
@@ -11,17 +11,20 @@ export const defineRoleAbilitiesProductManager = async (can, cannot) => {
11
11
  'ServiceCenter',
12
12
  'Coupon',
13
13
  'Discount',
14
- 'PlatformConfig',
14
+ 'PlatformConfig'
15
15
  ]);
16
16
  cannot('read', 'User', [
17
17
  ...getDocumentsFields('identification'),
18
18
  ...getDocumentsFields('drivingHistory'),
19
19
  ...getDocumentsFields('financial'),
20
- ...getDocumentsFields('offerLetter'),
20
+ ...getDocumentsFields('offerLetter')
21
21
  ]);
22
22
  cannot('create', 'Business');
23
23
  cannot('read', 'Business', 'paymentMethods');
24
24
  cannot('read', 'User', 'paymentMethods');
25
25
  cannot('read', 'Invoice');
26
- cannot('read', ['Vacancy', 'Applicant']);
26
+ cannot('read', [
27
+ 'Vacancy',
28
+ 'Applicant'
29
+ ]);
27
30
  };
@@ -1,4 +1,3 @@
1
1
  import type { AbilityBuilder } from '@casl/ability';
2
2
  import type { AppAbility } from '../../types.js';
3
3
  export declare const defineRoleAbilitiesSalesExecutive: (can: AbilityBuilder<AppAbility>["can"], cannot: AbilityBuilder<AppAbility>["cannot"]) => Promise<void>;
4
- //# sourceMappingURL=sales-executive.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { getDocumentsFields, getPricingFields } from '../../utils.js';
2
- export const defineRoleAbilitiesSalesExecutive = async (can, cannot) => {
2
+ export const defineRoleAbilitiesSalesExecutive = async (can, cannot)=>{
3
3
  can('read', [
4
4
  'Subscription',
5
5
  'Cycle',
@@ -9,16 +9,26 @@ export const defineRoleAbilitiesSalesExecutive = async (can, cannot) => {
9
9
  'Host',
10
10
  'Discount',
11
11
  'PlatformConfig',
12
- 'PaymentLink',
12
+ 'PaymentLink'
13
13
  ]);
14
- can(['read', 'update'], ['Invoice', 'Transaction', 'Refund']);
15
- can(['read', 'update'], 'User');
14
+ can([
15
+ 'read',
16
+ 'update'
17
+ ], [
18
+ 'Invoice',
19
+ 'Transaction',
20
+ 'Refund'
21
+ ]);
22
+ can([
23
+ 'read',
24
+ 'update'
25
+ ], 'User');
16
26
  cannot('update', 'User', 'status');
17
27
  cannot('update', 'User', [
18
28
  ...getDocumentsFields('identification'),
19
29
  ...getDocumentsFields('drivingHistory'),
20
30
  ...getDocumentsFields('financial'),
21
- ...getDocumentsFields('offerLetter'),
31
+ ...getDocumentsFields('offerLetter')
22
32
  ]);
23
33
  can('manage', 'Business');
24
34
  can('manage', 'Inquiry');
@@ -29,17 +39,23 @@ export const defineRoleAbilitiesSalesExecutive = async (can, cannot) => {
29
39
  'endedAt',
30
40
  'plan',
31
41
  'mileagePackage',
32
- 'payerType',
42
+ 'payerType'
33
43
  ]);
34
44
  can('read', 'SubscriptionReservation');
35
- cannot('update', 'Subscription', ['status', 'started']);
45
+ cannot('update', 'Subscription', [
46
+ 'status',
47
+ 'started'
48
+ ]);
36
49
  cannot('update', 'Vehicle', getPricingFields());
37
50
  can('testPricingInput', 'Vehicle');
38
51
  can('readPricingInput', 'Vehicle');
39
52
  cannot('cancelInvoice', 'Invoice');
40
53
  cannot('markInvoice', 'Invoice');
41
54
  cannot('delete', 'Quotation');
42
- cannot('read', ['Vacancy', 'Applicant']);
55
+ cannot('read', [
56
+ 'Vacancy',
57
+ 'Applicant'
58
+ ]);
43
59
  can('read', 'Activity');
44
60
  can('read', 'ActivityTask');
45
61
  };
@@ -2,4 +2,3 @@ import type { AbilityBuilder } from '@casl/ability';
2
2
  import type { User } from '@driveflux/db';
3
3
  import type { AppAbility } from '../../types.js';
4
4
  export declare const defineRoleAbilitiesBusinessAdmin: (can: AbilityBuilder<AppAbility>["can"], user: User) => Promise<void>;
5
- //# sourceMappingURL=business-admin.d.ts.map
@@ -1,12 +1,25 @@
1
- export const defineRoleAbilitiesBusinessAdmin = async (can, user) => {
1
+ export const defineRoleAbilitiesBusinessAdmin = async (can, user)=>{
2
2
  if (!user.businessId) {
3
3
  return;
4
4
  }
5
- can(['read', 'update'], 'User', { businessId: user.businessId });
6
- can('read', 'Subscription', { businessId: user.businessId });
7
- can('update', 'Business', ['phoneNumber', 'mobileNumber', 'addresses'], {
8
- id: user.businessId,
5
+ can([
6
+ 'read',
7
+ 'update'
8
+ ], 'User', {
9
+ businessId: user.businessId
10
+ });
11
+ can('read', 'Subscription', {
12
+ businessId: user.businessId
13
+ });
14
+ can('update', 'Business', [
15
+ 'phoneNumber',
16
+ 'mobileNumber',
17
+ 'addresses'
18
+ ], {
19
+ id: user.businessId
20
+ });
21
+ can('read', 'Business', {
22
+ id: user.businessId
9
23
  });
10
- can('read', 'Business', { id: user.businessId });
11
24
  can('create', 'Mandate');
12
25
  };
@@ -2,4 +2,3 @@ import type { AbilityBuilder } from '@casl/ability';
2
2
  import type { User } from '@driveflux/db';
3
3
  import type { AppAbility } from '../../types.js';
4
4
  export declare const defineRoleAbilitiesBusinessUser: (can: AbilityBuilder<AppAbility>["can"], user: User) => Promise<void>;
5
- //# sourceMappingURL=business-user.d.ts.map
@@ -1,12 +1,24 @@
1
- export const defineRoleAbilitiesBusinessUser = async (can, user) => {
1
+ export const defineRoleAbilitiesBusinessUser = async (can, user)=>{
2
2
  if (!user.businessId) {
3
3
  return;
4
4
  }
5
- can(['read'], 'User', { businessId: user.businessId });
6
- can('read', 'Subscription', { businessId: user.businessId });
7
- can('update', 'Business', ['phoneNumber', 'mobileNumber', 'addresses'], {
8
- id: user.businessId,
5
+ can([
6
+ 'read'
7
+ ], 'User', {
8
+ businessId: user.businessId
9
+ });
10
+ can('read', 'Subscription', {
11
+ businessId: user.businessId
12
+ });
13
+ can('update', 'Business', [
14
+ 'phoneNumber',
15
+ 'mobileNumber',
16
+ 'addresses'
17
+ ], {
18
+ id: user.businessId
19
+ });
20
+ can('read', 'Business', {
21
+ id: user.businessId
9
22
  });
10
- can('read', 'Business', { id: user.businessId });
11
23
  can('create', 'Mandate');
12
24
  };
@@ -2,4 +2,3 @@ import type { AbilityBuilder } from '@casl/ability';
2
2
  import type { User } from '@driveflux/db';
3
3
  import type { AppAbility } from '../../types.js';
4
4
  export declare const defineRoleAbilitiesMember: (can: AbilityBuilder<AppAbility>["can"], user: User) => Promise<void>;
5
- //# sourceMappingURL=member.d.ts.map
@@ -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,13 +6,23 @@ export const defineRoleAbilitiesMember = async (can, user) => {
6
6
  'utilization.pricePerKm',
7
7
  'utilization.paid',
8
8
  'utilization.allowedMileage',
9
- 'utilization.mileage',
10
- ], { subscription: { userId: user.id } });
11
- can('read', 'Vehicle', { status: 'listed' });
9
+ 'utilization.mileage'
10
+ ], {
11
+ subscription: {
12
+ userId: user.id
13
+ }
14
+ });
15
+ can('read', 'Vehicle', {
16
+ status: 'listed'
17
+ });
12
18
  can('create', 'Business');
13
19
  if (user.businessId) {
14
- can('update', 'Business', { id: user.businessId });
20
+ can('update', 'Business', {
21
+ id: user.businessId
22
+ });
15
23
  }
16
- can('read', 'Subscription', { userId: user.id });
24
+ can('read', 'Subscription', {
25
+ userId: user.id
26
+ });
17
27
  can('read', 'Coupon');
18
28
  };
@@ -28,4 +28,3 @@ export type Department = keyof typeof DEPARTMENTS_MAP;
28
28
  export type AdminRole = (typeof DEPARTMENTS_MAP)[keyof typeof DEPARTMENTS_MAP][number];
29
29
  export type UserGroup = (typeof GENERAL_ROLES)[number];
30
30
  export {};
31
- //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- export {};
1
+ export { };
@@ -6,4 +6,3 @@ export declare const updateUserPermissions: (userId: string | RawModels<"User">
6
6
  user: User;
7
7
  ability: AppAbility;
8
8
  }>;
9
- //# sourceMappingURL=update-user-permissions.d.ts.map
@@ -2,32 +2,39 @@ 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'
7
- ? await prisma.user.findUnique({
8
- where: {
9
- id: userId,
10
- },
11
- })
12
- : userId;
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;
13
11
  if (!user) {
14
12
  return new Err(makeProblem(PROBLEM_NOT_FOUND, 'User not found when trying to update the permissions'));
15
13
  }
16
- const groups = newGroups ? [...newGroups] : [...user.groups];
14
+ const groups = newGroups ? [
15
+ ...newGroups
16
+ ] : [
17
+ ...user.groups
18
+ ];
17
19
  const ability = await defineAbilityFor({
18
20
  ...user,
19
- groups,
21
+ groups
20
22
  });
21
23
  await prisma.user.update({
22
24
  where: {
23
- id: user.id,
25
+ id: user.id
24
26
  },
25
27
  data: {
26
- groups: [...groups],
27
- permissions: ability.rules,
28
- },
28
+ groups: [
29
+ ...groups
30
+ ],
31
+ permissions: ability.rules
32
+ }
29
33
  });
30
34
  user.groups = groups;
31
35
  user.permissions = ability.rules;
32
- return new Ok({ user, ability });
36
+ return new Ok({
37
+ user,
38
+ ability
39
+ });
33
40
  };
@@ -11,4 +11,3 @@ export declare const getDocumentsFields: (documentsGroup: keyof typeof documents
11
11
  export declare const getPricingFields: () => string[];
12
12
  export declare const s: (modelName: AppSubjectNames, key?: string) => any;
13
13
  export {};
14
- //# sourceMappingURL=utils.d.ts.map
@@ -1,25 +1,37 @@
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: ['visa', 'passport', 'idFront', 'idBack', 'drivingLicense'],
11
- drivingHistory: ['pdrm', 'jpj', 'bgs'],
10
+ identification: [
11
+ 'visa',
12
+ 'passport',
13
+ 'idFront',
14
+ 'idBack',
15
+ 'drivingLicense'
16
+ ],
17
+ drivingHistory: [
18
+ 'pdrm',
19
+ 'jpj',
20
+ 'bgs'
21
+ ],
12
22
  financial: [
13
23
  'experianReport',
14
24
  'bankStatement',
15
25
  'bankStatement2',
16
26
  'bankStatement3',
17
- 'epfStatement',
27
+ 'epfStatement'
18
28
  ],
19
- offerLetter: ['offerLetter'],
29
+ offerLetter: [
30
+ 'offerLetter'
31
+ ]
20
32
  };
21
- export const getDocumentsFields = (documentsGroup) => documents[documentsGroup].map((d) => `documents.${d}`);
22
- export const getPricingFields = () => {
33
+ export const getDocumentsFields = (documentsGroup)=>documents[documentsGroup].map((d)=>`documents.${d}`);
34
+ export const getPricingFields = ()=>{
23
35
  return [
24
36
  'pricing',
25
37
  'basePrice',
@@ -27,14 +39,17 @@ export const getPricingFields = () => {
27
39
  'basePricePlan12',
28
40
  'basePricePlan24',
29
41
  'basePricePlan36',
30
- 'basePricePlan60',
42
+ 'basePricePlan60'
31
43
  ];
32
44
  };
33
45
  // we are creating a helper function to fake an object
34
- export const s = (modelName, key = 'id') => {
46
+ export const s = (modelName, key = 'id')=>{
35
47
  const objectName = getObjectName(modelName);
36
- return subject(modelName, { object: objectName, [key]: 'XXXXXXXXX' });
48
+ return subject(modelName, {
49
+ object: objectName,
50
+ [key]: 'XXXXXXXXX'
51
+ });
37
52
  };
38
- const getObjectName = (modelName) => {
53
+ const getObjectName = (modelName)=>{
39
54
  return modelName[0].toLowerCase() + modelName.slice(1);
40
55
  };
@@ -7,4 +7,3 @@ export declare const AUTH_COOKIE_PKCE_CODE_VERIFIER: string;
7
7
  export declare const AUTH_COOKIE_STATE: string;
8
8
  export declare const AUTH_COOKIE_NONCE: string;
9
9
  export declare const PROBLEM_INVALID_LOGIN = "invalid_credentials";
10
- //# sourceMappingURL=constants.d.ts.map
package/dist/constants.js CHANGED
@@ -1,7 +1,5 @@
1
- const envSuffux = process.env.APP_ENV === 'production' ? '' : (process.env.APP_ENV ?? '');
2
- export const AUTH_COOKIE_PREFIX = envSuffux
3
- ? `flux-auth.${envSuffux}`
4
- : 'flux-auth';
1
+ const envSuffux = process.env.APP_ENV === 'production' ? '' : process.env.APP_ENV ?? '';
2
+ export const AUTH_COOKIE_PREFIX = envSuffux ? `flux-auth.${envSuffux}` : 'flux-auth';
5
3
  export const AUTH_COOKIE_ACCESSED_ADMIN = `${AUTH_COOKIE_PREFIX}.has-accessed-admin`;
6
4
  export const AUTH_COOKIE_SESSION_TOKEN = `${AUTH_COOKIE_PREFIX}.session-token`;
7
5
  export const AUTH_COOKIE_CALLBACK_URL = `${AUTH_COOKIE_PREFIX}.callback-url`;
package/dist/context.d.ts CHANGED
@@ -17,4 +17,3 @@ export interface AuthContextObject {
17
17
  accessToken?: string;
18
18
  }
19
19
  export declare const AuthContext: import("react").Context<AuthContextObject>;
20
- //# sourceMappingURL=context.d.ts.map
package/dist/context.js CHANGED
@@ -2,16 +2,15 @@ import { createContext } from 'react';
2
2
  const defaultContext = {
3
3
  user: undefined,
4
4
  isLoadingUser: false,
5
- signIn: async () => Promise.resolve(undefined),
6
- refresh: async () => Promise.resolve(undefined),
5
+ signIn: async ()=>Promise.resolve(undefined),
6
+ refresh: async ()=>Promise.resolve(undefined),
7
7
  /**
8
- *
9
- * @deprecated There's no need for access token anymore, we use cookies
10
- */
11
- getAccessToken: async () => Promise.resolve(undefined),
8
+ *
9
+ * @deprecated There's no need for access token anymore, we use cookies
10
+ */ getAccessToken: async ()=>Promise.resolve(undefined),
12
11
  // TODO
13
12
  // eslint-disable-next-line @typescript-eslint/no-empty-function -- initial state
14
- logout: () => { },
15
- status: 'loading',
13
+ logout: ()=>{},
14
+ status: 'loading'
16
15
  };
17
- export const AuthContext = createContext(defaultContext);
16
+ export const AuthContext = /*#__PURE__*/ createContext(defaultContext);
package/dist/default.d.ts CHANGED
@@ -1,2 +1 @@
1
1
  export declare const extractDefault: <T>(mod: T) => T;
2
- //# sourceMappingURL=default.d.ts.map
package/dist/default.js CHANGED
@@ -1,4 +1,4 @@
1
- export const extractDefault = (mod) => {
1
+ export const extractDefault = (mod)=>{
2
2
  if (typeof mod === 'object' && mod !== null && 'default' in mod) {
3
3
  return mod.default;
4
4
  }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  import NextAuthOriginal from 'next-auth';
2
2
  export declare const NextAuth: typeof NextAuthOriginal;
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,3 @@
1
1
  export { default as AuthProvider } from './AuthProvider.js';
2
2
  export * from './context.js';
3
3
  export * from './use-auth.js';
4
- //# sourceMappingURL=providers.d.ts.map
package/dist/react.d.ts CHANGED
@@ -2,4 +2,3 @@ import type { signIn } from 'next-auth/react';
2
2
  export * from 'next-auth/react';
3
3
  export { useSession as useAuthSession } from './use-session.js';
4
4
  export type SignInFunction = typeof signIn;
5
- //# sourceMappingURL=react.d.ts.map
@@ -6,4 +6,3 @@ interface AuthDetails {
6
6
  }
7
7
  export declare const authenticateUser: ({ login, password, }: AuthDetails) => PromisedResult<User>;
8
8
  export {};
9
- //# sourceMappingURL=authenticate-user.d.ts.map
@@ -5,25 +5,29 @@ 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
- : { phoneNumber: login.replace(/[\s-]/g, '') }),
16
- },
13
+ ...isEmail ? {
14
+ email: login.toLowerCase().trim()
15
+ } : {
16
+ phoneNumber: login.replace(/[\s-]/g, '')
17
+ }
18
+ }
17
19
  });
18
20
  if (!user) {
19
21
  return new Err(makeProblem(PROBLEM_INVALID_LOGIN, translations.wrongUsernameOrPassword));
20
22
  }
21
23
  // Check the user's password
22
- if (isEmail && !(await bcrypt.compare(password, user.password))) {
24
+ if (isEmail && !await bcrypt.compare(password, user.password)) {
23
25
  return new Err(makeProblem(PROBLEM_INVALID_LOGIN, 'The email / password combination is invalid.'));
24
26
  }
25
27
  if (!isEmail) {
26
- const tokenResult = await verifyToken(password, { scope: 'verify-phone' });
28
+ const tokenResult = await verifyToken(password, {
29
+ scope: 'verify-phone'
30
+ });
27
31
  if (!tokenResult.ok) {
28
32
  return new Err(makeProblem(PROBLEM_INVALID_LOGIN, 'The OTP is invalid.'));
29
33
  }
@@ -1,3 +1,2 @@
1
1
  import type { NextApiRequest, NextApiResponse } from 'next';
2
2
  export declare const cors: (req: NextApiRequest, res: NextApiResponse) => Promise<unknown>;
3
- //# sourceMappingURL=cors.d.ts.map