@driveflux/auth 4.0.90 → 4.0.92

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 (104) hide show
  1. package/dist/AuthProvider.d.ts +1 -0
  2. package/dist/AuthProvider.js +76 -59
  3. package/dist/ability.d.ts +1 -0
  4. package/dist/authorization/casl-prisma.d.ts +3 -0
  5. package/dist/authorization/casl-prisma.d.ts.map +1 -0
  6. package/dist/authorization/casl-prisma.js +2 -0
  7. package/dist/authorization/constants.d.ts +2 -1
  8. package/dist/authorization/define.d.ts +1 -0
  9. package/dist/authorization/define.js +57 -28
  10. package/dist/authorization/fields/index.d.ts +1 -0
  11. package/dist/authorization/fields/index.js +4 -7
  12. package/dist/authorization/helpers.d.ts +1 -0
  13. package/dist/authorization/helpers.js +10 -8
  14. package/dist/authorization/index.d.ts +1 -0
  15. package/dist/authorization/index.d.ts.map +1 -1
  16. package/dist/authorization/index.js +6 -6
  17. package/dist/authorization/permissions-list.d.ts +1 -0
  18. package/dist/authorization/permissions-list.js +5 -7
  19. package/dist/authorization/quick.d.ts +3 -1
  20. package/dist/authorization/quick.d.ts.map +1 -1
  21. package/dist/authorization/quick.js +1 -1
  22. package/dist/authorization/roles/admin/business-development-executive.d.ts +1 -0
  23. package/dist/authorization/roles/admin/business-development-executive.js +20 -7
  24. package/dist/authorization/roles/admin/ceo.d.ts +1 -0
  25. package/dist/authorization/roles/admin/ceo.js +4 -2
  26. package/dist/authorization/roles/admin/common.d.ts +1 -0
  27. package/dist/authorization/roles/admin/common.js +5 -3
  28. package/dist/authorization/roles/admin/concierge.d.ts +1 -0
  29. package/dist/authorization/roles/admin/concierge.js +35 -10
  30. package/dist/authorization/roles/admin/customer-success-executive.d.ts +1 -0
  31. package/dist/authorization/roles/admin/customer-success-executive.js +40 -10
  32. package/dist/authorization/roles/admin/data-analyst.d.ts +1 -0
  33. package/dist/authorization/roles/admin/data-analyst.js +7 -4
  34. package/dist/authorization/roles/admin/designer.d.ts +1 -0
  35. package/dist/authorization/roles/admin/designer.js +7 -4
  36. package/dist/authorization/roles/admin/engineer.d.ts +1 -0
  37. package/dist/authorization/roles/admin/engineer.js +7 -4
  38. package/dist/authorization/roles/admin/finance-executive.d.ts +1 -0
  39. package/dist/authorization/roles/admin/finance-executive.js +11 -4
  40. package/dist/authorization/roles/admin/head-of-business-development.d.ts +1 -0
  41. package/dist/authorization/roles/admin/head-of-business-development.js +14 -4
  42. package/dist/authorization/roles/admin/head-of-data-analytics.d.ts +1 -0
  43. package/dist/authorization/roles/admin/head-of-data-analytics.js +14 -4
  44. package/dist/authorization/roles/admin/head-of-engineering.d.ts +1 -0
  45. package/dist/authorization/roles/admin/head-of-engineering.js +17 -6
  46. package/dist/authorization/roles/admin/head-of-finance.d.ts +1 -0
  47. package/dist/authorization/roles/admin/head-of-finance.js +8 -3
  48. package/dist/authorization/roles/admin/head-of-human-resources.d.ts +1 -0
  49. package/dist/authorization/roles/admin/head-of-human-resources.js +13 -5
  50. package/dist/authorization/roles/admin/head-of-marketing.d.ts +1 -0
  51. package/dist/authorization/roles/admin/head-of-marketing.js +17 -5
  52. package/dist/authorization/roles/admin/head-of-operations.d.ts +1 -0
  53. package/dist/authorization/roles/admin/head-of-operations.js +8 -3
  54. package/dist/authorization/roles/admin/head-of-product.d.ts +1 -0
  55. package/dist/authorization/roles/admin/head-of-product.js +17 -6
  56. package/dist/authorization/roles/admin/head-of-sales.d.ts +1 -0
  57. package/dist/authorization/roles/admin/head-of-sales.js +17 -5
  58. package/dist/authorization/roles/admin/human-resources-executive.d.ts +1 -0
  59. package/dist/authorization/roles/admin/human-resources-executive.js +12 -5
  60. package/dist/authorization/roles/admin/marketing-executive.d.ts +1 -0
  61. package/dist/authorization/roles/admin/marketing-executive.js +7 -4
  62. package/dist/authorization/roles/admin/product-manager.d.ts +1 -0
  63. package/dist/authorization/roles/admin/product-manager.js +7 -4
  64. package/dist/authorization/roles/admin/sales-executive.d.ts +1 -0
  65. package/dist/authorization/roles/admin/sales-executive.js +24 -8
  66. package/dist/authorization/roles/consumer/business-admin.d.ts +1 -0
  67. package/dist/authorization/roles/consumer/business-admin.js +19 -6
  68. package/dist/authorization/roles/consumer/business-user.d.ts +1 -0
  69. package/dist/authorization/roles/consumer/business-user.js +18 -6
  70. package/dist/authorization/roles/consumer/member.d.ts +1 -0
  71. package/dist/authorization/roles/consumer/member.js +16 -6
  72. package/dist/authorization/types.d.ts +7 -17
  73. package/dist/authorization/types.d.ts.map +1 -1
  74. package/dist/authorization/types.js +1 -1
  75. package/dist/authorization/update-user-permissions.d.ts +1 -0
  76. package/dist/authorization/update-user-permissions.js +22 -15
  77. package/dist/authorization/utils.d.ts +1 -0
  78. package/dist/authorization/utils.d.ts.map +1 -1
  79. package/dist/authorization/utils.js +26 -11
  80. package/dist/constants.d.ts +1 -0
  81. package/dist/context.d.ts +1 -0
  82. package/dist/default.d.ts +1 -0
  83. package/dist/index.d.ts +1 -0
  84. package/dist/providers.d.ts +1 -0
  85. package/dist/react.d.ts +1 -0
  86. package/dist/server/authenticate-user.d.ts +1 -0
  87. package/dist/server/authenticate-user.js +11 -7
  88. package/dist/server/cors.d.ts +1 -0
  89. package/dist/server/cors.js +23 -12
  90. package/dist/server/credentials-provider.d.ts +1 -0
  91. package/dist/server/credentials-provider.js +2 -2
  92. package/dist/server/index.d.ts +1 -0
  93. package/dist/server/next-auth.d.ts +12 -11
  94. package/dist/server/next-auth.js +104 -109
  95. package/dist/server/prisma-adapter.d.ts +1 -0
  96. package/dist/server/prisma-adapter.js +88 -52
  97. package/dist/server/types.d.ts +1 -0
  98. package/dist/server/verfiy-token.d.ts +1 -0
  99. package/dist/server/verfiy-token.js +39 -24
  100. package/dist/translations.d.ts +1 -0
  101. package/dist/types.d.ts +1 -0
  102. package/dist/use-auth.d.ts +1 -0
  103. package/dist/use-session.d.ts +1 -0
  104. package/package.json +17 -13
@@ -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,3 +1,4 @@
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,3 +1,4 @@
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,3 +2,4 @@ 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,3 +2,4 @@ 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,3 +2,4 @@ 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
  };
@@ -1,30 +1,20 @@
1
- import type { ForcedSubject, hkt, PureAbility } from '@casl/ability';
1
+ import type { Ability } from '@casl/ability';
2
2
  import type { Subjects } from '@casl/prisma';
3
- import type { ExtractModelName } from '@casl/prisma/runtime';
4
- import type { Prisma, PrismaClient } from '@driveflux/db';
3
+ import type { Model, PrismaQueryOf, WhereInputOf } from '@casl/prisma/runtime';
4
+ import type { Prisma } from '@driveflux/db';
5
5
  import type { RawModels, RealModelNames } from '@driveflux/db/types';
6
6
  import type { DEPARTMENTS_MAP, GENERAL_ROLES, ROLES } from './constants.js';
7
7
  export type Action = 'create' | 'update' | 'delete' | 'read' | 'manage' | 'release' | 'reverse' | 'reserveVehicle' | 'reserveDelistedVehicle' | 'reserveVehicleForFree' | 'charge' | 'execute' | 'connectHostToStripe' | 'manageAdmin' | 'executeTask' | 'deletePayoutChargeLine' | 'manageCustomerInquiries' | 'cancelInvoice' | 'markInvoice' | 'testPricingInput' | 'readPricingInput' | 'createAdmin' | 'refund' | 'viewSubscriptionApproval' | 'confirmVehicleAvailability' | 'updateSubscriptionUser' | 'startSubscription';
8
8
  export type SubjectsModels = {
9
9
  [M in RealModelNames]: RawModels<M>;
10
10
  };
11
- type ModelWhereInput = {
12
- [K in Prisma.ModelName]: Uncapitalize<K> extends keyof PrismaClient ? Extract<Parameters<PrismaClient[Uncapitalize<K>]['findFirst']>[0], {
13
- where?: any;
14
- }>['where'] : never;
15
- };
16
- interface PrismaQueryTypeFactory extends hkt.GenericFactory {
17
- produce: WhereInput<ExtractModelName<this[0], RealModelNames>>;
18
- }
19
- type WhereInput<TModelName extends RealModelNames> = Extract<ModelWhereInput[TModelName], Record<any, any>>;
20
- type Model<T, TName extends string> = T & ForcedSubject<TName>;
21
- type PrismaModel = Model<Record<string, any>, string>;
22
- export type PrismaQuery<T extends PrismaModel = PrismaModel> = WhereInput<ExtractModelName<T, RealModelNames>> & hkt.Container<PrismaQueryTypeFactory>;
23
11
  export type AppSubjects = Subjects<SubjectsModels> | 'all' | 'Reports';
24
12
  export type AppSubjectNames = RealModelNames | 'all' | 'Reports';
25
- export type AppAbility = PureAbility<[Action, AppSubjects], PrismaQuery>;
13
+ export type AppAbility = Ability<[Action, AppSubjects], PrismaQuery>;
26
14
  export type Role = (typeof ROLES)[keyof typeof ROLES];
27
15
  export type Department = keyof typeof DEPARTMENTS_MAP;
28
16
  export type AdminRole = (typeof DEPARTMENTS_MAP)[keyof typeof DEPARTMENTS_MAP][number];
29
17
  export type UserGroup = (typeof GENERAL_ROLES)[number];
30
- export {};
18
+ export type PrismaQuery<T extends Model<Record<string, any>, string> = Model<Record<string, any>, string>> = PrismaQueryOf<Prisma.TypeMap, T>;
19
+ export type WhereInput<TModelName extends Prisma.ModelName> = WhereInputOf<Prisma.TypeMap, TModelName>;
20
+ //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/authorization/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EAAE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,eAAe,CAAC,CAAC,MAAM,CAAC,CAAA;AAE/D,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAA;AAEtD,MAAM,MAAM,WAAW,CACtB,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,KAAK,CACnD,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnB,MAAM,CACN,IACE,aAAa,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;AAEpC,MAAM,MAAM,UAAU,CAAC,UAAU,SAAS,MAAM,CAAC,SAAS,IAAI,YAAY,CACzE,MAAM,CAAC,OAAO,EACd,UAAU,CACV,CAAA"}
@@ -1 +1 @@
1
- export {};
1
+ export { };
@@ -6,3 +6,4 @@ 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,3 +11,4 @@ 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 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/authorization/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAW,MAAM,eAAe,CAAA;AAE9D,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE7D,eAAO,MAAM,iBAAiB,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC,mBAAmB,CAQ9E,CAAA;AAEF,QAAA,MAAM,SAAS;;;;;CAWL,CAAA;AAEV,eAAO,MAAM,kBAAkB,GAAI,gBAAgB,MAAM,OAAO,SAAS,aAClB,CAAA;AAEvD,eAAO,MAAM,gBAAgB,gBAU5B,CAAA;AAGD,eAAO,MAAM,CAAC,GAAI,WAAW,eAAe,EAAE,YAAU,KAEkB,GACzE,CAAA"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/authorization/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAW,MAAM,eAAe,CAAA;AAE9D,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE7D,eAAO,MAAM,iBAAiB,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC,mBAAmB,CAU9E,CAAA;AAEF,QAAA,MAAM,SAAS;;;;;CAWL,CAAA;AAEV,eAAO,MAAM,kBAAkB,GAAI,gBAAgB,MAAM,OAAO,SAAS,aAClB,CAAA;AAEvD,eAAO,MAAM,gBAAgB,gBAU5B,CAAA;AAGD,eAAO,MAAM,CAAC,GAAI,WAAW,eAAe,EAAE,YAAU,KAEkB,GACzE,CAAA"}
@@ -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,3 +7,4 @@ 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/context.d.ts CHANGED
@@ -17,3 +17,4 @@ 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/default.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare const extractDefault: <T>(mod: T) => T;
2
+ //# sourceMappingURL=default.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import NextAuthOriginal from 'next-auth';
2
2
  export declare const NextAuth: typeof NextAuthOriginal;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,4 @@
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,3 +2,4 @@ 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,3 +6,4 @@ 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,2 +1,3 @@
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
@@ -1,28 +1,39 @@
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 = [config.appUrl];
6
- if (config.appEnv === 'development' ||
7
- (origin && allowedOrigins.includes(origin))) {
4
+ origin: (origin, callback)=>{
5
+ const allowedOrigins = [
6
+ config.appUrl
7
+ ];
8
+ if (config.appEnv === 'development' || origin && allowedOrigins.includes(origin)) {
8
9
  callback(null, true);
9
- }
10
- else {
10
+ } else {
11
11
  callback(new Error('CORS not allowed'));
12
12
  }
13
13
  },
14
- allowedHeaders: ['content-type', 'x-correlation-id', 'authorization'],
14
+ allowedHeaders: [
15
+ 'content-type',
16
+ 'x-correlation-id',
17
+ 'authorization'
18
+ ],
15
19
  exposedHeaders: '*',
16
- methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'],
17
- credentials: true,
20
+ methods: [
21
+ 'GET',
22
+ 'HEAD',
23
+ 'PUT',
24
+ 'PATCH',
25
+ 'POST',
26
+ 'DELETE'
27
+ ],
28
+ credentials: true
18
29
  };
19
30
  // Initializing the cors middleware
20
31
  // I don't have time to debug cors now, I've got a million things to do.
21
32
  // TODO Implement this properly please
22
33
  const corsHandler = config.appEnv === 'development' ? Cors(corsOptions) : Cors();
23
- export const cors = (req, res) => {
24
- return new Promise((resolve, reject) => {
25
- corsHandler(req, res, (result) => {
34
+ export const cors = (req, res)=>{
35
+ return new Promise((resolve, reject)=>{
36
+ corsHandler(req, res, (result)=>{
26
37
  if (result instanceof Error) {
27
38
  return reject(result);
28
39
  }
@@ -23,3 +23,4 @@ export type CredentialsProviderType = 'Credentials';
23
23
  type UserCredentialsConfig<C extends Record<string, CredentialInput>> = Partial<Omit<CredentialsConfig<C>, 'options'>> & Pick<CredentialsConfig<C>, 'authorize' | 'credentials'>;
24
24
  export declare function Credentials<C extends Record<string, CredentialInput> = Record<string, CredentialInput>>(options: UserCredentialsConfig<C>): CredentialsConfig<C>;
25
25
  export {};
26
+ //# sourceMappingURL=credentials-provider.d.ts.map
@@ -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
  }
@@ -1,3 +1,4 @@
1
1
  export { getServerSession } from 'next-auth';
2
2
  export * from './authenticate-user.js';
3
3
  export * from './next-auth.js';
4
+ //# sourceMappingURL=index.d.ts.map