@driveflux/auth 4.0.57 → 4.0.59

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 (48) hide show
  1. package/dist/AuthProvider.js +76 -59
  2. package/dist/authorization/constants.js +45 -24
  3. package/dist/authorization/define.js +57 -28
  4. package/dist/authorization/fields/index.js +4 -7
  5. package/dist/authorization/helpers.js +10 -8
  6. package/dist/authorization/index.js +6 -6
  7. package/dist/authorization/permissions-list.js +5 -7
  8. package/dist/authorization/quick.js +1 -1
  9. package/dist/authorization/roles/admin/business-development-executive.js +20 -7
  10. package/dist/authorization/roles/admin/ceo.js +4 -2
  11. package/dist/authorization/roles/admin/common.js +4 -2
  12. package/dist/authorization/roles/admin/concierge.js +35 -10
  13. package/dist/authorization/roles/admin/customer-success-executive.js +40 -10
  14. package/dist/authorization/roles/admin/data-analyst.js +7 -4
  15. package/dist/authorization/roles/admin/designer.js +7 -4
  16. package/dist/authorization/roles/admin/engineer.js +7 -4
  17. package/dist/authorization/roles/admin/finance-executive.js +11 -4
  18. package/dist/authorization/roles/admin/head-of-business-development.js +14 -4
  19. package/dist/authorization/roles/admin/head-of-data-analytics.js +14 -4
  20. package/dist/authorization/roles/admin/head-of-engineering.js +17 -6
  21. package/dist/authorization/roles/admin/head-of-finance.js +8 -3
  22. package/dist/authorization/roles/admin/head-of-human-resources.js +13 -5
  23. package/dist/authorization/roles/admin/head-of-marketing.js +17 -5
  24. package/dist/authorization/roles/admin/head-of-operations.js +8 -3
  25. package/dist/authorization/roles/admin/head-of-product.js +17 -6
  26. package/dist/authorization/roles/admin/head-of-sales.js +17 -5
  27. package/dist/authorization/roles/admin/human-resources-executive.js +12 -5
  28. package/dist/authorization/roles/admin/marketing-executive.js +7 -4
  29. package/dist/authorization/roles/admin/product-manager.js +7 -4
  30. package/dist/authorization/roles/admin/sales-executive.js +24 -8
  31. package/dist/authorization/roles/consumer/business-admin.js +19 -6
  32. package/dist/authorization/roles/consumer/business-user.js +18 -6
  33. package/dist/authorization/roles/consumer/member.js +16 -6
  34. package/dist/authorization/types.js +1 -1
  35. package/dist/authorization/update-user-permissions.js +22 -15
  36. package/dist/authorization/utils.js +26 -11
  37. package/dist/context.js +8 -9
  38. package/dist/default.js +1 -1
  39. package/dist/server/authenticate-user.js +11 -7
  40. package/dist/server/cors.js +23 -12
  41. package/dist/server/credentials-provider.js +2 -2
  42. package/dist/server/next-auth.js +104 -109
  43. package/dist/server/prisma-adapter.js +88 -52
  44. package/dist/server/verfiy-token.js +39 -24
  45. package/dist/translations.js +4 -4
  46. package/dist/use-auth.js +1 -1
  47. package/dist/use-session.js +1 -1
  48. package/package.json +2 -2
@@ -1,29 +1,36 @@
1
1
  import { prisma } from '@driveflux/db';
2
- import { makeProblem, PROBLEM_CORRUPT, PROBLEM_EXPIRED, PROBLEM_INVALID_DATA, } from '@driveflux/problem';
2
+ import { makeProblem, PROBLEM_CORRUPT, PROBLEM_EXPIRED, PROBLEM_INVALID_DATA } from '@driveflux/problem';
3
3
  import { Err, Ok } from '@driveflux/result';
4
- export const verifyToken = async (tokenIdOrValue, verifications, option) => {
5
- const token = typeof tokenIdOrValue === 'object'
6
- ? tokenIdOrValue
7
- : (await prisma.token.findFirst({
8
- where: {
9
- OR: [{ id: tokenIdOrValue }, { value: tokenIdOrValue }],
10
- },
11
- ...(option?.includeUser ? { include: { user: true } } : {}),
12
- }));
4
+ export const verifyToken = async (tokenIdOrValue, verifications, option)=>{
5
+ const token = typeof tokenIdOrValue === 'object' ? tokenIdOrValue : await prisma.token.findFirst({
6
+ where: {
7
+ OR: [
8
+ {
9
+ id: tokenIdOrValue
10
+ },
11
+ {
12
+ value: tokenIdOrValue
13
+ }
14
+ ]
15
+ },
16
+ ...option?.includeUser ? {
17
+ include: {
18
+ user: true
19
+ }
20
+ } : {}
21
+ });
13
22
  if (!token) {
14
23
  return new Err(makeProblem(PROBLEM_INVALID_DATA, 'Invalid token'));
15
24
  }
16
25
  if (token.expiresAt && token.expiresAt.getTime() < Date.now()) {
17
26
  return new Err(makeProblem(PROBLEM_EXPIRED, 'This token has expired'));
18
27
  }
19
- if (typeof verifications?.scope !== 'undefined' &&
20
- token.scope !== verifications.scope) {
28
+ if (typeof verifications?.scope !== 'undefined' && token.scope !== verifications.scope) {
21
29
  return new Err(makeProblem(PROBLEM_INVALID_DATA, 'Invalid token scope'));
22
30
  }
23
31
  if (typeof verifications?.metadata !== 'undefined') {
24
- for (const key of Object.keys(verifications.metadata)) {
25
- if (typeof verifications.metadata[key] !== 'undefined' &&
26
- verifications.metadata[key] !== token.metadata?.[key]) {
32
+ for (const key of Object.keys(verifications.metadata)){
33
+ if (typeof verifications.metadata[key] !== 'undefined' && verifications.metadata[key] !== token.metadata?.[key]) {
27
34
  return new Err(makeProblem(PROBLEM_INVALID_DATA, 'Invalid token data'));
28
35
  }
29
36
  }
@@ -33,22 +40,30 @@ export const verifyToken = async (tokenIdOrValue, verifications, option) => {
33
40
  }
34
41
  return new Ok(token);
35
42
  };
36
- export const clearToken = async (tokenId) => {
43
+ export const clearToken = async (tokenId)=>{
37
44
  try {
38
45
  await prisma.token.delete({
39
46
  where: {
40
- id: tokenId,
41
- },
47
+ id: tokenId
48
+ }
42
49
  });
43
- }
44
- catch (_e) {
45
- // Nothing to for now
50
+ } catch (_e) {
51
+ // Nothing to for now
46
52
  }
47
53
  };
48
- export const clearExpiredTokens = async () => {
54
+ export const clearExpiredTokens = async ()=>{
49
55
  await prisma.token.deleteMany({
50
56
  where: {
51
- OR: [{ expiresAt: { lte: new Date() } }, { invalid: true }],
52
- },
57
+ OR: [
58
+ {
59
+ expiresAt: {
60
+ lte: new Date()
61
+ }
62
+ },
63
+ {
64
+ invalid: true
65
+ }
66
+ ]
67
+ }
53
68
  });
54
69
  };
@@ -4,15 +4,15 @@ export const translations = singleton('authTranslations', {
4
4
  password: 'Password',
5
5
  unauthenticated: 'Unauthenticated',
6
6
  unauthenticatedDescription: 'You are not authenticated. Please log in to continue.',
7
- wrongUsernameOrPassword: 'The username / password combination is invalid.',
7
+ wrongUsernameOrPassword: 'The username / password combination is invalid.'
8
8
  });
9
- export const setTranslations = (ts) => {
10
- for (const key in ts) {
9
+ export const setTranslations = (ts)=>{
10
+ for(const key in ts){
11
11
  // TODO
12
12
  // @ts-expect-error
13
13
  translations[key] = ts[key];
14
14
  }
15
15
  };
16
- export const setTranslation = (key, value) => {
16
+ export const setTranslation = (key, value)=>{
17
17
  translations[key] = value;
18
18
  };
package/dist/use-auth.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useContext } from 'react';
2
2
  import { AuthContext } from './context.js';
3
- export const useAuth = () => {
3
+ export const useAuth = ()=>{
4
4
  return useContext(AuthContext);
5
5
  };
@@ -1,4 +1,4 @@
1
1
  import { useSession as originalUseSession } from 'next-auth/react';
2
- export const useSession = (options) => {
2
+ export const useSession = (options)=>{
3
3
  return originalUseSession(options);
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driveflux/auth",
3
- "version": "4.0.57",
3
+ "version": "4.0.59",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -75,7 +75,7 @@
75
75
  "@casl/ability": "^6.7.3",
76
76
  "@casl/prisma": "^1.5.2",
77
77
  "@driveflux/config": "3.0.8",
78
- "@driveflux/db": "4.0.32",
78
+ "@driveflux/db": "4.0.33",
79
79
  "@driveflux/fetch": "8.0.0",
80
80
  "@driveflux/problem": "6.0.0",
81
81
  "@driveflux/reporter": "7.0.1",