@driveflux/auth 4.0.87 → 4.0.89

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 +0 -1
  2. package/dist/AuthProvider.js +59 -76
  3. package/dist/ability.d.ts +0 -1
  4. package/dist/authorization/constants.d.ts +1 -2
  5. package/dist/authorization/constants.js +24 -45
  6. package/dist/authorization/define.d.ts +0 -1
  7. package/dist/authorization/define.js +28 -57
  8. package/dist/authorization/fields/index.d.ts +0 -1
  9. package/dist/authorization/fields/index.js +7 -4
  10. package/dist/authorization/helpers.d.ts +0 -1
  11. package/dist/authorization/helpers.js +8 -10
  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 +7 -5
  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 +7 -20
  20. package/dist/authorization/roles/admin/ceo.d.ts +0 -1
  21. package/dist/authorization/roles/admin/ceo.js +2 -4
  22. package/dist/authorization/roles/admin/common.d.ts +0 -1
  23. package/dist/authorization/roles/admin/common.js +3 -5
  24. package/dist/authorization/roles/admin/concierge.d.ts +0 -1
  25. package/dist/authorization/roles/admin/concierge.js +10 -35
  26. package/dist/authorization/roles/admin/customer-success-executive.d.ts +0 -1
  27. package/dist/authorization/roles/admin/customer-success-executive.js +10 -40
  28. package/dist/authorization/roles/admin/data-analyst.d.ts +0 -1
  29. package/dist/authorization/roles/admin/data-analyst.js +4 -7
  30. package/dist/authorization/roles/admin/designer.d.ts +0 -1
  31. package/dist/authorization/roles/admin/designer.js +4 -7
  32. package/dist/authorization/roles/admin/engineer.d.ts +0 -1
  33. package/dist/authorization/roles/admin/engineer.js +4 -7
  34. package/dist/authorization/roles/admin/finance-executive.d.ts +0 -1
  35. package/dist/authorization/roles/admin/finance-executive.js +4 -11
  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 +4 -14
  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 +4 -14
  40. package/dist/authorization/roles/admin/head-of-engineering.d.ts +0 -1
  41. package/dist/authorization/roles/admin/head-of-engineering.js +6 -17
  42. package/dist/authorization/roles/admin/head-of-finance.d.ts +0 -1
  43. package/dist/authorization/roles/admin/head-of-finance.js +3 -8
  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 +5 -13
  46. package/dist/authorization/roles/admin/head-of-marketing.d.ts +0 -1
  47. package/dist/authorization/roles/admin/head-of-marketing.js +5 -17
  48. package/dist/authorization/roles/admin/head-of-operations.d.ts +0 -1
  49. package/dist/authorization/roles/admin/head-of-operations.js +3 -8
  50. package/dist/authorization/roles/admin/head-of-product.d.ts +0 -1
  51. package/dist/authorization/roles/admin/head-of-product.js +6 -17
  52. package/dist/authorization/roles/admin/head-of-sales.d.ts +0 -1
  53. package/dist/authorization/roles/admin/head-of-sales.js +5 -17
  54. package/dist/authorization/roles/admin/human-resources-executive.d.ts +0 -1
  55. package/dist/authorization/roles/admin/human-resources-executive.js +5 -12
  56. package/dist/authorization/roles/admin/marketing-executive.d.ts +0 -1
  57. package/dist/authorization/roles/admin/marketing-executive.js +4 -7
  58. package/dist/authorization/roles/admin/product-manager.d.ts +0 -1
  59. package/dist/authorization/roles/admin/product-manager.js +4 -7
  60. package/dist/authorization/roles/admin/sales-executive.d.ts +0 -1
  61. package/dist/authorization/roles/admin/sales-executive.js +8 -24
  62. package/dist/authorization/roles/consumer/business-admin.d.ts +0 -1
  63. package/dist/authorization/roles/consumer/business-admin.js +6 -19
  64. package/dist/authorization/roles/consumer/business-user.d.ts +0 -1
  65. package/dist/authorization/roles/consumer/business-user.js +6 -18
  66. package/dist/authorization/roles/consumer/member.d.ts +0 -1
  67. package/dist/authorization/roles/consumer/member.js +6 -16
  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 +15 -22
  72. package/dist/authorization/utils.d.ts +0 -1
  73. package/dist/authorization/utils.js +11 -26
  74. package/dist/constants.d.ts +0 -1
  75. package/dist/constants.js +4 -2
  76. package/dist/context.d.ts +0 -1
  77. package/dist/context.js +9 -8
  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 +7 -11
  85. package/dist/server/cors.d.ts +0 -1
  86. package/dist/server/cors.js +12 -23
  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.d.ts +11 -0
  91. package/dist/server/next-auth.js +109 -104
  92. package/dist/server/prisma-adapter.d.ts +0 -1
  93. package/dist/server/prisma-adapter.js +52 -88
  94. package/dist/server/types.d.ts +0 -1
  95. package/dist/server/verfiy-token.d.ts +0 -1
  96. package/dist/server/verfiy-token.js +24 -39
  97. package/dist/translations.d.ts +0 -1
  98. package/dist/translations.js +4 -4
  99. package/dist/types.d.ts +0 -1
  100. package/dist/use-auth.d.ts +0 -1
  101. package/dist/use-auth.js +1 -1
  102. package/dist/use-session.d.ts +0 -1
  103. package/dist/use-session.js +1 -1
  104. package/package.json +29 -29
@@ -4,172 +4,136 @@ export function PrismaAdapter() {
4
4
  return {
5
5
  // TODO
6
6
  // @ts-expect-error TypeScript is not working here
7
- createUser: async ({ id, groups, permissions, emailVerified, ...data })=>{
7
+ createUser: async ({ id, groups, permissions, emailVerified, ...data }) => {
8
8
  // @ts-expect-error
9
9
  const userData = {
10
10
  id: id || generateId('User'),
11
- groups: groups || [
12
- 'member'
13
- ],
11
+ groups: groups || ['member'],
14
12
  permissions: permissions || {},
15
13
  emailVerified: Boolean(emailVerified),
16
14
  email: data.email.toLowerCase().trim(),
17
- ...data
15
+ ...data,
18
16
  };
19
17
  const user = await prisma.user.create({
20
18
  data: {
21
- ...userData
22
- }
19
+ ...userData,
20
+ },
23
21
  });
24
22
  return user;
25
23
  },
26
24
  // TODO
27
25
  // @ts-expect-error
28
- getUser: (id)=>prisma.user.findUnique({
29
- where: {
30
- id
31
- }
32
- }),
26
+ getUser: (id) => prisma.user.findUnique({ where: { id } }),
33
27
  // TODO
34
28
  // @ts-expect-error
35
- getUserByEmail: (email)=>prisma.user.findUnique({
36
- where: {
37
- email: email.toLowerCase().trim()
38
- }
39
- }),
29
+ getUserByEmail: (email) => prisma.user.findUnique({ where: { email: email.toLowerCase().trim() } }),
40
30
  // TODO
41
31
  // @ts-expect-error
42
- async getUserByAccount (provider_providerAccountId) {
32
+ async getUserByAccount(provider_providerAccountId) {
43
33
  const account = await prisma.account.findUnique({
44
- where: {
45
- provider_providerAccountId
46
- },
47
- select: {
48
- user: true
49
- }
34
+ where: { provider_providerAccountId },
35
+ select: { user: true },
50
36
  });
51
37
  return account?.user ?? null;
52
38
  },
53
39
  // TODO
54
40
  // @ts-expect-error
55
- updateUser: ({ id, ...data })=>{
41
+ updateUser: ({ id, ...data }) => {
56
42
  // @ts-expect-error
57
43
  const userData = {
58
44
  email: data.email?.toLowerCase().trim(),
59
- ...data
45
+ ...data,
60
46
  };
61
- return prisma.user.update({
62
- where: {
63
- id
64
- },
65
- data: {
66
- ...userData
67
- }
68
- });
47
+ return prisma.user.update({ where: { id }, data: { ...userData } });
69
48
  },
70
49
  // TODO
71
50
  // @ts-expect-error
72
- deleteUser: (id)=>prisma.user.delete({
73
- where: {
74
- id
75
- }
76
- }),
51
+ deleteUser: (id) => prisma.user.delete({ where: { id } }),
77
52
  // @ts-expect-error
78
- linkAccount: ({ id, ...data })=>{
53
+ linkAccount: ({ id, ...data }) => {
79
54
  return prisma.account.create({
80
55
  // @ts-expect-error
81
56
  data: {
82
57
  id: id || generateId('Account'),
83
- ...data
84
- }
58
+ ...data,
59
+ },
85
60
  });
86
61
  },
87
62
  // @ts-expect-error
88
- unlinkAccount: (provider_providerAccountId)=>prisma.account.delete({
89
- where: {
90
- provider_providerAccountId
91
- }
92
- }),
63
+ unlinkAccount: (provider_providerAccountId) => prisma.account.delete({
64
+ where: { provider_providerAccountId },
65
+ }),
93
66
  // TODO
94
67
  // @ts-expect-error
95
- async getSessionAndUser (sessionToken) {
68
+ async getSessionAndUser(sessionToken) {
96
69
  const userAndSession = await prisma.session.findUnique({
97
- where: {
98
- sessionToken
99
- },
100
- include: {
101
- user: true
102
- }
70
+ where: { sessionToken },
71
+ include: { user: true },
103
72
  });
104
- if (!userAndSession) return null;
73
+ if (!userAndSession)
74
+ return null;
105
75
  const { user, ...session } = userAndSession;
106
- return {
107
- user,
108
- session
109
- };
76
+ return { user, session };
110
77
  },
111
78
  // TODO
112
79
  // @ts-expect-error
113
- async createSession ({ id, ...data }) {
80
+ async createSession({ id, ...data }) {
114
81
  const session = await prisma.session.create({
115
82
  data: {
116
83
  id: id || generateId('Session'),
117
- ...data
118
- }
84
+ ...data,
85
+ },
119
86
  });
120
87
  return session;
121
88
  },
122
- updateSession: (data)=>{
89
+ updateSession: (data) => {
123
90
  return prisma.session.update({
124
- where: {
125
- sessionToken: data.sessionToken
126
- },
127
- data
91
+ where: { sessionToken: data.sessionToken },
92
+ data,
128
93
  });
129
94
  },
130
- deleteSession: async (sessionToken)=>{
95
+ deleteSession: async (sessionToken) => {
131
96
  try {
132
- await prisma.session.delete({
133
- where: {
134
- sessionToken
135
- }
136
- });
137
- } catch (_e) {
138
- // TODO
139
- // DO nothing for now
97
+ await prisma.session.delete({ where: { sessionToken } });
98
+ }
99
+ catch (_e) {
100
+ // TODO
101
+ // DO nothing for now
140
102
  }
141
103
  },
142
104
  // TODO
143
105
  // @ts-expect-error
144
- async createVerificationToken ({ id, ...data }) {
106
+ async createVerificationToken({ id, ...data }) {
145
107
  const verificationToken = await prisma.verificationToken.create({
146
108
  data: {
147
109
  id: id || generateId('VerificationToken'),
148
- ...data
149
- }
110
+ ...data,
111
+ },
150
112
  });
151
113
  // TODO
152
114
  // @ts-expect-errors // MongoDB needs an ID, but we don't
153
- if (verificationToken.id) verificationToken.id = undefined;
115
+ if (verificationToken.id)
116
+ verificationToken.id = undefined;
154
117
  return verificationToken;
155
118
  },
156
- async useVerificationToken (identifier_token) {
119
+ async useVerificationToken(identifier_token) {
157
120
  try {
158
121
  const verificationToken = await prisma.verificationToken.delete({
159
- where: {
160
- identifier_token
161
- }
122
+ where: { identifier_token },
162
123
  });
163
124
  // TODO
164
125
  // @ts-expect-errors // MongoDB needs an ID, but we don't
165
- if (verificationToken.id) verificationToken.id = undefined;
126
+ if (verificationToken.id)
127
+ verificationToken.id = undefined;
166
128
  return verificationToken;
167
- } catch (error) {
129
+ }
130
+ catch (error) {
168
131
  // If token already used/deleted, just return null
169
132
  // https://www.prisma.io/docs/reference/api-reference/error-reference#p2025
170
- if (error.code === 'P2025') return null;
133
+ if (error.code === 'P2025')
134
+ return null;
171
135
  throw error;
172
136
  }
173
- }
137
+ },
174
138
  };
175
139
  }
@@ -18,4 +18,3 @@ declare module 'next-auth' {
18
18
  }
19
19
  }
20
20
  export {};
21
- //# sourceMappingURL=types.d.ts.map
@@ -11,4 +11,3 @@ export declare const verifyToken: (tokenIdOrValue: string | TokenWithMaybeUser,
11
11
  export declare const clearToken: (tokenId: string) => Promise<void>;
12
12
  export declare const clearExpiredTokens: () => Promise<void>;
13
13
  export {};
14
- //# sourceMappingURL=verfiy-token.d.ts.map
@@ -1,36 +1,29 @@
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' ? 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
- });
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
+ }));
22
13
  if (!token) {
23
14
  return new Err(makeProblem(PROBLEM_INVALID_DATA, 'Invalid token'));
24
15
  }
25
16
  if (token.expiresAt && token.expiresAt.getTime() < Date.now()) {
26
17
  return new Err(makeProblem(PROBLEM_EXPIRED, 'This token has expired'));
27
18
  }
28
- if (typeof verifications?.scope !== 'undefined' && token.scope !== verifications.scope) {
19
+ if (typeof verifications?.scope !== 'undefined' &&
20
+ token.scope !== verifications.scope) {
29
21
  return new Err(makeProblem(PROBLEM_INVALID_DATA, 'Invalid token scope'));
30
22
  }
31
23
  if (typeof verifications?.metadata !== 'undefined') {
32
- for (const key of Object.keys(verifications.metadata)){
33
- if (typeof verifications.metadata[key] !== 'undefined' && verifications.metadata[key] !== token.metadata?.[key]) {
24
+ for (const key of Object.keys(verifications.metadata)) {
25
+ if (typeof verifications.metadata[key] !== 'undefined' &&
26
+ verifications.metadata[key] !== token.metadata?.[key]) {
34
27
  return new Err(makeProblem(PROBLEM_INVALID_DATA, 'Invalid token data'));
35
28
  }
36
29
  }
@@ -40,30 +33,22 @@ export const verifyToken = async (tokenIdOrValue, verifications, option)=>{
40
33
  }
41
34
  return new Ok(token);
42
35
  };
43
- export const clearToken = async (tokenId)=>{
36
+ export const clearToken = async (tokenId) => {
44
37
  try {
45
38
  await prisma.token.delete({
46
39
  where: {
47
- id: tokenId
48
- }
40
+ id: tokenId,
41
+ },
49
42
  });
50
- } catch (_e) {
51
- // Nothing to for now
43
+ }
44
+ catch (_e) {
45
+ // Nothing to for now
52
46
  }
53
47
  };
54
- export const clearExpiredTokens = async ()=>{
48
+ export const clearExpiredTokens = async () => {
55
49
  await prisma.token.deleteMany({
56
50
  where: {
57
- OR: [
58
- {
59
- expiresAt: {
60
- lte: new Date()
61
- }
62
- },
63
- {
64
- invalid: true
65
- }
66
- ]
67
- }
51
+ OR: [{ expiresAt: { lte: new Date() } }, { invalid: true }],
52
+ },
68
53
  });
69
54
  };
@@ -9,4 +9,3 @@ export declare const translations: {
9
9
  export declare const setTranslations: (ts: Partial<Translations>) => void;
10
10
  export declare const setTranslation: <K extends keyof Translations>(key: K, value: Translations[K]) => void;
11
11
  export {};
12
- //# sourceMappingURL=translations.d.ts.map
@@ -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/types.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export type * from 'next-auth';
2
2
  import './server/types.js';
3
- //# sourceMappingURL=types.d.ts.map
@@ -1,2 +1 @@
1
1
  export declare const useAuth: () => import("./context.js").AuthContextObject;
2
- //# sourceMappingURL=use-auth.d.ts.map
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
  };
@@ -21,4 +21,3 @@ type SessionContextValue<R extends boolean = false> = R extends true ? {
21
21
  };
22
22
  export declare const useSession: <R extends boolean>(options?: UseSessionOptions<R>) => SessionContextValue<R>;
23
23
  export {};
24
- //# sourceMappingURL=use-session.d.ts.map
@@ -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.87",
3
+ "version": "4.0.89",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -72,41 +72,41 @@
72
72
  "dist"
73
73
  ],
74
74
  "dependencies": {
75
- "@casl/ability": "^6.7.3",
76
- "@casl/prisma": "^1.5.2",
77
- "@driveflux/config": "3.0.10",
78
- "@driveflux/db": "4.1.19",
79
- "@driveflux/fetch": "8.0.1",
80
- "@driveflux/problem": "6.0.1",
81
- "@driveflux/reporter": "7.0.2",
82
- "@driveflux/result": "6.0.1",
83
- "@driveflux/singleton": "3.0.0",
84
- "@driveflux/ui": "3.0.3",
85
- "@driveflux/utils": "6.0.0",
86
- "@driveflux/web-analytics": "3.0.3",
75
+ "@casl/ability": "^6.8.1",
76
+ "@casl/prisma": "^1.6.2",
77
+ "@driveflux/config": "3.0.11",
78
+ "@driveflux/db": "4.1.20",
79
+ "@driveflux/fetch": "8.0.2",
80
+ "@driveflux/problem": "6.0.2",
81
+ "@driveflux/reporter": "7.0.3",
82
+ "@driveflux/result": "6.0.2",
83
+ "@driveflux/singleton": "3.0.1",
84
+ "@driveflux/ui": "3.0.4",
85
+ "@driveflux/utils": "6.0.1",
86
+ "@driveflux/web-analytics": "3.0.4",
87
87
  "@types/cors": "^2.8.19",
88
- "bcryptjs": "^3.0.2",
88
+ "bcryptjs": "^3.0.3",
89
89
  "change-case": "^5.4.4",
90
- "cors": "^2.8.5",
91
- "jose": "^6.1.0",
90
+ "cors": "^2.8.6",
91
+ "jose": "^6.2.3",
92
92
  "js-cookie": "^3.0.5",
93
- "nanoid": "^5.1.6",
94
- "next-auth": "^4.24.11",
95
- "universal-cookie": "^8.0.1"
93
+ "nanoid": "^5.1.11",
94
+ "next-auth": "4.24.14",
95
+ "universal-cookie": "^8.1.2"
96
96
  },
97
97
  "devDependencies": {
98
- "@driveflux/fab": "4.0.0",
99
- "@driveflux/tsconfig": "3.0.0",
100
- "@swc/cli": "^0.7.8",
101
- "@swc/core": "^1.13.5",
98
+ "@driveflux/fab": "4.0.1",
99
+ "@driveflux/tsconfig": "3.0.1",
100
+ "@swc/cli": "^0.8.1",
101
+ "@swc/core": "^1.15.33",
102
102
  "@types/js-cookie": "^3.0.6",
103
- "@types/node": "^24.9.1",
104
- "@types/react": "19.2.2",
103
+ "@types/node": "^25.7.0",
104
+ "@types/react": "19.2.14",
105
105
  "del-cli": "^7.0.0",
106
- "next": "16.0.7",
107
- "react": "19.2.1",
108
- "swr": "^2.3.6",
109
- "typescript": "^5.9.3"
106
+ "next": "16.2.6",
107
+ "react": "19.2.6",
108
+ "swr": "^2.4.1",
109
+ "typescript": "^6.0.3"
110
110
  },
111
111
  "scripts": {
112
112
  "build": "fab",