@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.
- package/dist/AuthProvider.d.ts +1 -0
- package/dist/AuthProvider.js +76 -59
- package/dist/ability.d.ts +1 -0
- package/dist/authorization/casl-prisma.d.ts +3 -0
- package/dist/authorization/casl-prisma.d.ts.map +1 -0
- package/dist/authorization/casl-prisma.js +2 -0
- package/dist/authorization/constants.d.ts +2 -1
- package/dist/authorization/define.d.ts +1 -0
- package/dist/authorization/define.js +57 -28
- package/dist/authorization/fields/index.d.ts +1 -0
- package/dist/authorization/fields/index.js +4 -7
- package/dist/authorization/helpers.d.ts +1 -0
- package/dist/authorization/helpers.js +10 -8
- package/dist/authorization/index.d.ts +1 -0
- package/dist/authorization/index.d.ts.map +1 -1
- package/dist/authorization/index.js +6 -6
- package/dist/authorization/permissions-list.d.ts +1 -0
- package/dist/authorization/permissions-list.js +5 -7
- package/dist/authorization/quick.d.ts +3 -1
- package/dist/authorization/quick.d.ts.map +1 -1
- package/dist/authorization/quick.js +1 -1
- package/dist/authorization/roles/admin/business-development-executive.d.ts +1 -0
- package/dist/authorization/roles/admin/business-development-executive.js +20 -7
- package/dist/authorization/roles/admin/ceo.d.ts +1 -0
- package/dist/authorization/roles/admin/ceo.js +4 -2
- package/dist/authorization/roles/admin/common.d.ts +1 -0
- package/dist/authorization/roles/admin/common.js +5 -3
- package/dist/authorization/roles/admin/concierge.d.ts +1 -0
- package/dist/authorization/roles/admin/concierge.js +35 -10
- package/dist/authorization/roles/admin/customer-success-executive.d.ts +1 -0
- package/dist/authorization/roles/admin/customer-success-executive.js +40 -10
- package/dist/authorization/roles/admin/data-analyst.d.ts +1 -0
- package/dist/authorization/roles/admin/data-analyst.js +7 -4
- package/dist/authorization/roles/admin/designer.d.ts +1 -0
- package/dist/authorization/roles/admin/designer.js +7 -4
- package/dist/authorization/roles/admin/engineer.d.ts +1 -0
- package/dist/authorization/roles/admin/engineer.js +7 -4
- package/dist/authorization/roles/admin/finance-executive.d.ts +1 -0
- package/dist/authorization/roles/admin/finance-executive.js +11 -4
- package/dist/authorization/roles/admin/head-of-business-development.d.ts +1 -0
- package/dist/authorization/roles/admin/head-of-business-development.js +14 -4
- package/dist/authorization/roles/admin/head-of-data-analytics.d.ts +1 -0
- package/dist/authorization/roles/admin/head-of-data-analytics.js +14 -4
- package/dist/authorization/roles/admin/head-of-engineering.d.ts +1 -0
- package/dist/authorization/roles/admin/head-of-engineering.js +17 -6
- package/dist/authorization/roles/admin/head-of-finance.d.ts +1 -0
- package/dist/authorization/roles/admin/head-of-finance.js +8 -3
- package/dist/authorization/roles/admin/head-of-human-resources.d.ts +1 -0
- package/dist/authorization/roles/admin/head-of-human-resources.js +13 -5
- package/dist/authorization/roles/admin/head-of-marketing.d.ts +1 -0
- package/dist/authorization/roles/admin/head-of-marketing.js +17 -5
- package/dist/authorization/roles/admin/head-of-operations.d.ts +1 -0
- package/dist/authorization/roles/admin/head-of-operations.js +8 -3
- package/dist/authorization/roles/admin/head-of-product.d.ts +1 -0
- package/dist/authorization/roles/admin/head-of-product.js +17 -6
- package/dist/authorization/roles/admin/head-of-sales.d.ts +1 -0
- package/dist/authorization/roles/admin/head-of-sales.js +17 -5
- package/dist/authorization/roles/admin/human-resources-executive.d.ts +1 -0
- package/dist/authorization/roles/admin/human-resources-executive.js +12 -5
- package/dist/authorization/roles/admin/marketing-executive.d.ts +1 -0
- package/dist/authorization/roles/admin/marketing-executive.js +7 -4
- package/dist/authorization/roles/admin/product-manager.d.ts +1 -0
- package/dist/authorization/roles/admin/product-manager.js +7 -4
- package/dist/authorization/roles/admin/sales-executive.d.ts +1 -0
- package/dist/authorization/roles/admin/sales-executive.js +24 -8
- package/dist/authorization/roles/consumer/business-admin.d.ts +1 -0
- package/dist/authorization/roles/consumer/business-admin.js +19 -6
- package/dist/authorization/roles/consumer/business-user.d.ts +1 -0
- package/dist/authorization/roles/consumer/business-user.js +18 -6
- package/dist/authorization/roles/consumer/member.d.ts +1 -0
- package/dist/authorization/roles/consumer/member.js +16 -6
- package/dist/authorization/types.d.ts +7 -17
- package/dist/authorization/types.d.ts.map +1 -1
- package/dist/authorization/types.js +1 -1
- package/dist/authorization/update-user-permissions.d.ts +1 -0
- package/dist/authorization/update-user-permissions.js +22 -15
- package/dist/authorization/utils.d.ts +1 -0
- package/dist/authorization/utils.d.ts.map +1 -1
- package/dist/authorization/utils.js +26 -11
- package/dist/constants.d.ts +1 -0
- package/dist/context.d.ts +1 -0
- package/dist/default.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/providers.d.ts +1 -0
- package/dist/react.d.ts +1 -0
- package/dist/server/authenticate-user.d.ts +1 -0
- package/dist/server/authenticate-user.js +11 -7
- package/dist/server/cors.d.ts +1 -0
- package/dist/server/cors.js +23 -12
- package/dist/server/credentials-provider.d.ts +1 -0
- package/dist/server/credentials-provider.js +2 -2
- package/dist/server/index.d.ts +1 -0
- package/dist/server/next-auth.d.ts +12 -11
- package/dist/server/next-auth.js +104 -109
- package/dist/server/prisma-adapter.d.ts +1 -0
- package/dist/server/prisma-adapter.js +88 -52
- package/dist/server/types.d.ts +1 -0
- package/dist/server/verfiy-token.d.ts +1 -0
- package/dist/server/verfiy-token.js +39 -24
- package/dist/translations.d.ts +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/use-auth.d.ts +1 -0
- package/dist/use-session.d.ts +1 -0
- 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', [
|
|
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([
|
|
15
|
-
|
|
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', [
|
|
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', [
|
|
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([
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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([
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
], {
|
|
11
|
-
|
|
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', {
|
|
20
|
+
can('update', 'Business', {
|
|
21
|
+
id: user.businessId
|
|
22
|
+
});
|
|
15
23
|
}
|
|
16
|
-
can('read', 'Subscription', {
|
|
24
|
+
can('read', 'Subscription', {
|
|
25
|
+
userId: user.id
|
|
26
|
+
});
|
|
17
27
|
can('read', 'Coupon');
|
|
18
28
|
};
|
|
@@ -1,30 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Ability } from '@casl/ability';
|
|
2
2
|
import type { Subjects } from '@casl/prisma';
|
|
3
|
-
import type {
|
|
4
|
-
import type { Prisma
|
|
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 =
|
|
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,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/authorization/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAE3E,MAAM,MAAM,MAAM,GACf,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,SAAS,GACT,SAAS,GACT,gBAAgB,GAChB,wBAAwB,GACxB,uBAAuB,GACvB,QAAQ,GACR,SAAS,GACT,qBAAqB,GACrB,aAAa,GACb,aAAa,GACb,wBAAwB,GACxB,yBAAyB,GACzB,eAAe,GACf,aAAa,GACb,kBAAkB,GAClB,kBAAkB,GAClB,aAAa,GACb,QAAQ,GACR,0BAA0B,GAC1B,4BAA4B,GAC5B,wBAAwB,GACxB,mBAAmB,CAAA;AAEtB,MAAM,MAAM,cAAc,GAAG;KAC3B,CAAC,IAAI,cAAc,GAAG,SAAS,CAAC,CAAC,CAAC;CACnC,CAAA;AAwBD,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,cAAc,CAAC,GAAG,KAAK,GAAG,SAAS,CAAA;AACtE,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,KAAK,GAAG,SAAS,CAAA;AAEhE,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,WAAW,CAAC,CAAA;AAEpE,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,OAAO,KAAK,CAAC,CAAA;AAErD,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,eAAe,CAAA;AAErD,MAAM,MAAM,SAAS,GACpB,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,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 { };
|
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 ? [
|
|
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: [
|
|
27
|
-
|
|
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({
|
|
36
|
+
return new Ok({
|
|
37
|
+
user,
|
|
38
|
+
ability
|
|
39
|
+
});
|
|
33
40
|
};
|
|
@@ -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,
|
|
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: [
|
|
11
|
-
|
|
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: [
|
|
29
|
+
offerLetter: [
|
|
30
|
+
'offerLetter'
|
|
31
|
+
]
|
|
20
32
|
};
|
|
21
|
-
export const getDocumentsFields = (documentsGroup)
|
|
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, {
|
|
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
|
};
|
package/dist/constants.d.ts
CHANGED
package/dist/context.d.ts
CHANGED
package/dist/default.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/providers.d.ts
CHANGED
package/dist/react.d.ts
CHANGED
|
@@ -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
|
-
...
|
|
14
|
-
|
|
15
|
-
|
|
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 && !
|
|
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, {
|
|
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
|
}
|
package/dist/server/cors.d.ts
CHANGED
package/dist/server/cors.js
CHANGED
|
@@ -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 = [
|
|
6
|
-
|
|
7
|
-
|
|
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: [
|
|
14
|
+
allowedHeaders: [
|
|
15
|
+
'content-type',
|
|
16
|
+
'x-correlation-id',
|
|
17
|
+
'authorization'
|
|
18
|
+
],
|
|
15
19
|
exposedHeaders: '*',
|
|
16
|
-
methods: [
|
|
17
|
-
|
|
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
|
package/dist/server/index.d.ts
CHANGED