@driveflux/api-functions 1.0.146 → 1.0.148
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/auth/confirm.js +24 -24
- package/dist/auth/consent.js +27 -22
- package/dist/auth/emails.js +13 -12
- package/dist/auth/formatter.js +5 -5
- package/dist/auth/otp.js +50 -66
- package/dist/auth/register.js +35 -48
- package/dist/auth/tokens.js +55 -58
- package/dist/auth/verifications.js +52 -53
- package/dist/constants.js +1 -0
- package/dist/create-logger.js +2 -1
- package/dist/mailjet/calls/manage-contacts-in-list.js +6 -5
- package/dist/mailjet/calls/manage-subscription-status.js +5 -4
- package/dist/mailjet/calls/request-service.js +6 -7
- package/dist/mailjet/refresh-email-preferences.js +12 -11
- package/dist/mailjet/set-contact.js +12 -11
- package/dist/mailjet/types.js +2 -1
- package/dist/mailjet/utils/convert-to-array.js +6 -8
- package/dist/mailjet/utils/extract-email-preferences.js +15 -14
- package/dist/mailjet/utils/lists.js +8 -7
- package/dist/mailjet/utils/update-email-references.js +15 -16
- package/dist/notion/client.js +19 -22
- package/dist/notion/helpful.js +9 -6
- package/dist/notion/schemas/block.js +48 -42
- package/dist/notion/schemas/common.js +14 -9
- package/dist/notion/schemas/database.js +60 -62
- package/dist/notion/schemas/emoji.js +2 -1
- package/dist/notion/schemas/file.js +9 -9
- package/dist/notion/schemas/kb.js +6 -5
- package/dist/notion/schemas/page.js +61 -72
- package/dist/notion/schemas/parent.js +5 -4
- package/dist/notion/schemas/user.js +19 -18
- package/dist/reservation/agree.js +3 -2
- package/dist/reservation/checks.js +4 -3
- package/dist/reservation/display-vehicle.js +83 -73
- package/dist/reservation/ensure-user-billing-address.js +11 -9
- package/dist/reservation/fetch-or-create.js +56 -49
- package/dist/reservation/invoice.js +88 -77
- package/dist/reservation/payer.js +6 -5
- package/dist/reservation/payment-intent-sync.js +6 -4
- package/dist/reservation/reserve.js +4 -3
- package/dist/reservation/types.js +2 -1
- package/dist/reservation/vehicle.js +16 -13
- package/dist/slack.js +29 -24
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +85 -81
- package/dist/validation.js.map +1 -1
- package/dist/vehicle/vehicle-pricing/constants.js +19 -22
- package/dist/vehicle/vehicle-pricing/index.js +42 -28
- package/dist/vehicle/vehicle-pricing/types.js +2 -1
- package/package.json +11 -11
package/dist/auth/confirm.js
CHANGED
|
@@ -13,34 +13,35 @@ const Body = z.object({
|
|
|
13
13
|
firstName: z.string(),
|
|
14
14
|
lastName: z.string(),
|
|
15
15
|
email: z.string(),
|
|
16
|
-
phoneNumber: z.string().transform((s)=>s.replace(/[\s-]/g, '')),
|
|
16
|
+
phoneNumber: z.string().transform((s) => s.replace(/[\s-]/g, '')),
|
|
17
17
|
code: z.string().optional().nullable(),
|
|
18
18
|
pageSource: z.string().optional().nullable(),
|
|
19
19
|
fingerprint: z.string().optional(),
|
|
20
20
|
ipAddress: z.string(),
|
|
21
|
-
userAgent: z.string().optional()
|
|
21
|
+
userAgent: z.string().optional(),
|
|
22
22
|
});
|
|
23
|
-
export const handleConfirmUser = async (b, user)=>{
|
|
23
|
+
export const handleConfirmUser = async (b, user) => {
|
|
24
24
|
const { phoneNumber, code, pageSource, fingerprint, ipAddress, userAgent, ...body } = Body.parse(b);
|
|
25
25
|
console.log('fingerprint in handle confirm user???', fingerprint);
|
|
26
26
|
let phoneNumberVerified = false;
|
|
27
27
|
if (code) {
|
|
28
|
-
const tokenResult = await verifyToken(code, {
|
|
29
|
-
scope: 'verify-phone'
|
|
30
|
-
});
|
|
28
|
+
const tokenResult = await verifyToken(code, { scope: 'verify-phone' });
|
|
31
29
|
if (tokenResult.err) {
|
|
32
30
|
return new Err(makeProblem(PROBLEM_CONFLICT, 'Invalid OTP token'));
|
|
33
31
|
}
|
|
34
32
|
await clearToken(tokenResult.val.id);
|
|
35
33
|
phoneNumberVerified = true;
|
|
36
|
-
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
37
36
|
phoneNumberVerified = user.phoneNumberVerified;
|
|
38
37
|
}
|
|
39
|
-
const method = isMetadata(user?.metadata)
|
|
38
|
+
const method = isMetadata(user?.metadata)
|
|
39
|
+
? user?.metadata?.signupProvider
|
|
40
|
+
: undefined;
|
|
40
41
|
const tokenId = generateId('Token');
|
|
41
42
|
const updatedUser = await prisma.user.update({
|
|
42
43
|
where: {
|
|
43
|
-
id: user.id
|
|
44
|
+
id: user.id,
|
|
44
45
|
},
|
|
45
46
|
data: {
|
|
46
47
|
...body,
|
|
@@ -48,20 +49,18 @@ export const handleConfirmUser = async (b, user)=>{
|
|
|
48
49
|
preferredCurrency: 'MYR',
|
|
49
50
|
preferredLocale: 'en',
|
|
50
51
|
phoneNumberVerified,
|
|
51
|
-
groups: [
|
|
52
|
-
'member'
|
|
53
|
-
],
|
|
52
|
+
groups: ['member'],
|
|
54
53
|
signupParams: {
|
|
55
54
|
method,
|
|
56
|
-
source: pageSource
|
|
55
|
+
source: pageSource,
|
|
57
56
|
},
|
|
58
57
|
registrationComplete: true,
|
|
59
58
|
tokens: {
|
|
60
59
|
create: {
|
|
61
60
|
id: tokenId,
|
|
62
61
|
expiresAt: addDays(new Date(), 365),
|
|
63
|
-
scope: 'all'
|
|
64
|
-
}
|
|
62
|
+
scope: 'all',
|
|
63
|
+
},
|
|
65
64
|
},
|
|
66
65
|
consented: true,
|
|
67
66
|
consents: {
|
|
@@ -70,30 +69,31 @@ export const handleConfirmUser = async (b, user)=>{
|
|
|
70
69
|
...user,
|
|
71
70
|
phoneNumber,
|
|
72
71
|
firstName: body.firstName,
|
|
73
|
-
lastName: body.lastName
|
|
72
|
+
lastName: body.lastName,
|
|
74
73
|
},
|
|
75
74
|
fingerprint,
|
|
76
75
|
termsVersion: 'universal',
|
|
77
76
|
ipAddress: ipAddress,
|
|
78
77
|
userAgent: userAgent,
|
|
79
78
|
sessionToken: tokenId,
|
|
80
|
-
consentType: 'terms'
|
|
81
|
-
})
|
|
82
|
-
}
|
|
79
|
+
consentType: 'terms',
|
|
80
|
+
}),
|
|
81
|
+
},
|
|
83
82
|
},
|
|
84
83
|
include: {
|
|
85
84
|
tokens: {
|
|
86
85
|
where: {
|
|
87
|
-
id: tokenId
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
86
|
+
id: tokenId,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
91
90
|
});
|
|
92
91
|
// We don't want this to be a task. It should be instant
|
|
93
92
|
await sendVerificationEmail(updatedUser.id);
|
|
94
93
|
await refreshEmailPreferences(updatedUser.id);
|
|
95
94
|
return new Ok({
|
|
96
95
|
token: updatedUser.tokens[0],
|
|
97
|
-
user: updatedUser
|
|
96
|
+
user: updatedUser,
|
|
98
97
|
});
|
|
99
98
|
};
|
|
99
|
+
//# sourceMappingURL=confirm.js.map
|
package/dist/auth/consent.js
CHANGED
|
@@ -1,53 +1,58 @@
|
|
|
1
1
|
import { prisma } from '@driveflux/db';
|
|
2
2
|
import { generateId } from '@driveflux/db/id';
|
|
3
|
-
export const getConsentCreateData = ({ fingerprint, termsVersion, ipAddress, userAgent, user, sessionToken, sessionId, consentType })=>{
|
|
3
|
+
export const getConsentCreateData = ({ fingerprint, termsVersion, ipAddress, userAgent, user, sessionToken, sessionId, consentType, }) => {
|
|
4
4
|
const consentCreate = {
|
|
5
5
|
id: generateId('UserConsent'),
|
|
6
6
|
ipAddress,
|
|
7
7
|
consentType: consentType || 'terms',
|
|
8
8
|
sessionToken,
|
|
9
|
-
userName: [
|
|
10
|
-
user.firstName,
|
|
11
|
-
user.lastName
|
|
12
|
-
].filter(Boolean).join(' '),
|
|
9
|
+
userName: [user.firstName, user.lastName].filter(Boolean).join(' '),
|
|
13
10
|
phoneNumber: user.phoneNumber,
|
|
14
11
|
email: user.email,
|
|
15
12
|
fingerprint,
|
|
16
13
|
user: {
|
|
17
14
|
connect: {
|
|
18
|
-
id: user.id
|
|
19
|
-
}
|
|
15
|
+
id: user.id,
|
|
16
|
+
},
|
|
20
17
|
},
|
|
21
|
-
...sessionId
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
...(sessionId
|
|
19
|
+
? {
|
|
20
|
+
session: {
|
|
21
|
+
connect: {
|
|
22
|
+
id: sessionId,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
26
25
|
}
|
|
27
|
-
|
|
26
|
+
: undefined),
|
|
28
27
|
userAgent,
|
|
29
|
-
termsVersion: termsVersion || 'universal'
|
|
28
|
+
termsVersion: termsVersion || 'universal',
|
|
30
29
|
};
|
|
31
30
|
return consentCreate;
|
|
32
31
|
};
|
|
33
|
-
export const createConsent = (data)=>{
|
|
32
|
+
export const createConsent = (data) => {
|
|
34
33
|
const consentData = getConsentCreateData(data);
|
|
35
34
|
return prisma.userConsent.create({
|
|
36
|
-
data: consentData
|
|
35
|
+
data: consentData,
|
|
37
36
|
});
|
|
38
37
|
};
|
|
39
|
-
export const shouldConsentAgain = (consent)=>{
|
|
40
|
-
return !consent.userAgent ||
|
|
38
|
+
export const shouldConsentAgain = (consent) => {
|
|
39
|
+
return (!consent.userAgent ||
|
|
40
|
+
!consent.ipAddress ||
|
|
41
|
+
consent.ipAddress === '0.0.0.0' ||
|
|
42
|
+
!consent.userName ||
|
|
43
|
+
!consent.phoneNumber ||
|
|
44
|
+
!consent.email);
|
|
41
45
|
};
|
|
42
|
-
export const checkUserConsent = async (userId)=>{
|
|
46
|
+
export const checkUserConsent = async (userId) => {
|
|
43
47
|
const consent = await prisma.userConsent.findFirst({
|
|
44
48
|
where: {
|
|
45
49
|
userId,
|
|
46
|
-
consentType: 'terms'
|
|
50
|
+
consentType: 'terms',
|
|
47
51
|
},
|
|
48
52
|
orderBy: {
|
|
49
|
-
createdAt: 'desc'
|
|
50
|
-
}
|
|
53
|
+
createdAt: 'desc',
|
|
54
|
+
},
|
|
51
55
|
});
|
|
52
56
|
return consent && !shouldConsentAgain(consent);
|
|
53
57
|
};
|
|
58
|
+
//# sourceMappingURL=consent.js.map
|
package/dist/auth/emails.js
CHANGED
|
@@ -4,11 +4,11 @@ import { emailChangedEmail } from '@driveflux/email-templates/flux/email-changed
|
|
|
4
4
|
import { passwordChangedEmail } from '@driveflux/email-templates/flux/password-changed';
|
|
5
5
|
import { makeProblem, PROBLEM_NOT_FOUND } from '@driveflux/problem';
|
|
6
6
|
import { Err } from '@driveflux/result';
|
|
7
|
-
export const sendEmailChangedEmail = async (userId)=>{
|
|
7
|
+
export const sendEmailChangedEmail = async (userId) => {
|
|
8
8
|
const user = await prisma.user.findUnique({
|
|
9
9
|
where: {
|
|
10
|
-
id: userId
|
|
11
|
-
}
|
|
10
|
+
id: userId,
|
|
11
|
+
},
|
|
12
12
|
});
|
|
13
13
|
if (!user) {
|
|
14
14
|
return new Err(makeProblem(PROBLEM_NOT_FOUND, `The user ${userId} was not found`));
|
|
@@ -17,20 +17,20 @@ export const sendEmailChangedEmail = async (userId)=>{
|
|
|
17
17
|
subject: 'Email change confirmation',
|
|
18
18
|
to: {
|
|
19
19
|
name: user.firstName || '',
|
|
20
|
-
address: user.email
|
|
20
|
+
address: user.email,
|
|
21
21
|
},
|
|
22
22
|
html: emailChangedEmail({
|
|
23
23
|
user: user.firstName || '',
|
|
24
24
|
title: 'Email change confirmation',
|
|
25
|
-
newEmail: user.email
|
|
26
|
-
})
|
|
25
|
+
newEmail: user.email,
|
|
26
|
+
}),
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
|
-
export const sendPasswordChangedEmail = async (userId)=>{
|
|
29
|
+
export const sendPasswordChangedEmail = async (userId) => {
|
|
30
30
|
const user = await prisma.user.findUnique({
|
|
31
31
|
where: {
|
|
32
|
-
id: userId
|
|
33
|
-
}
|
|
32
|
+
id: userId,
|
|
33
|
+
},
|
|
34
34
|
});
|
|
35
35
|
if (!user) {
|
|
36
36
|
return new Err(makeProblem(PROBLEM_NOT_FOUND, `The user ${userId} was not found`));
|
|
@@ -40,11 +40,12 @@ export const sendPasswordChangedEmail = async (userId)=>{
|
|
|
40
40
|
subject: title,
|
|
41
41
|
to: {
|
|
42
42
|
name: user.firstName || '',
|
|
43
|
-
address: user.email
|
|
43
|
+
address: user.email,
|
|
44
44
|
},
|
|
45
45
|
html: passwordChangedEmail({
|
|
46
46
|
user: user.firstName || '',
|
|
47
|
-
title: title
|
|
48
|
-
})
|
|
47
|
+
title: title,
|
|
48
|
+
}),
|
|
49
49
|
});
|
|
50
50
|
};
|
|
51
|
+
//# sourceMappingURL=emails.js.map
|
package/dist/auth/formatter.js
CHANGED
|
@@ -221,9 +221,9 @@ const knownCountryCodes = [
|
|
|
221
221
|
'246',
|
|
222
222
|
'269',
|
|
223
223
|
'692',
|
|
224
|
-
'383'
|
|
224
|
+
'383',
|
|
225
225
|
];
|
|
226
|
-
export const cleanupPhoneNumber = (phoneNumber)=>{
|
|
226
|
+
export const cleanupPhoneNumber = (phoneNumber) => {
|
|
227
227
|
// Remove all characters except numbers and +
|
|
228
228
|
const cleaned = phoneNumber.replace(/[^\d+]/g, '');
|
|
229
229
|
// If it doesn't start with +, add it
|
|
@@ -232,9 +232,8 @@ export const cleanupPhoneNumber = (phoneNumber)=>{
|
|
|
232
232
|
let countryCode = '';
|
|
233
233
|
let remainingNumber = '';
|
|
234
234
|
// Try to find the country code by checking the longest matches first
|
|
235
|
-
for(let i = 4; i >= 1; i--){
|
|
236
|
-
const potentialCode = withPlus.substring(1, 1 + i) // Skip the + and take i digits
|
|
237
|
-
;
|
|
235
|
+
for (let i = 4; i >= 1; i--) {
|
|
236
|
+
const potentialCode = withPlus.substring(1, 1 + i); // Skip the + and take i digits
|
|
238
237
|
if (knownCountryCodes.includes(potentialCode)) {
|
|
239
238
|
countryCode = potentialCode;
|
|
240
239
|
remainingNumber = withPlus.substring(1 + i); // Everything after the country code
|
|
@@ -247,3 +246,4 @@ export const cleanupPhoneNumber = (phoneNumber)=>{
|
|
|
247
246
|
}
|
|
248
247
|
return withPlus;
|
|
249
248
|
};
|
|
249
|
+
//# sourceMappingURL=formatter.js.map
|
package/dist/auth/otp.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ROLES } from '@driveflux/auth/authorization/constants';
|
|
|
2
2
|
import { config } from '@driveflux/config/backend';
|
|
3
3
|
import { prisma } from '@driveflux/db';
|
|
4
4
|
import { generateId } from '@driveflux/db/id';
|
|
5
|
-
import { makeProblem, PROBLEM_CONFLICT, PROBLEM_INVALID_DATA } from '@driveflux/problem';
|
|
5
|
+
import { makeProblem, PROBLEM_CONFLICT, PROBLEM_INVALID_DATA, } from '@driveflux/problem';
|
|
6
6
|
import { Err, Ok } from '@driveflux/result';
|
|
7
7
|
import { addDays } from 'date-fns/addDays';
|
|
8
8
|
import { z } from 'zod';
|
|
@@ -13,46 +13,43 @@ const SendVerificationSMSBody = z.object({
|
|
|
13
13
|
phoneNumber: z.string(),
|
|
14
14
|
checkDuplication: z.boolean().optional().nullable(),
|
|
15
15
|
includeUser: z.boolean().optional().nullable(),
|
|
16
|
-
userId: z.string().optional().nullable()
|
|
16
|
+
userId: z.string().optional().nullable(),
|
|
17
17
|
});
|
|
18
|
-
const VerifyOtpBody = z
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
const VerifyOtpBody = z
|
|
19
|
+
.object({
|
|
20
|
+
scope: z.enum(['verify-email', 'verify-phone']),
|
|
21
|
+
email: z
|
|
22
|
+
.email()
|
|
23
|
+
.optional()
|
|
24
|
+
.transform((email) => email?.toLowerCase().trim()),
|
|
24
25
|
phoneNumber: z.string().optional(),
|
|
25
|
-
code: z.string()
|
|
26
|
-
})
|
|
26
|
+
code: z.string(),
|
|
27
|
+
})
|
|
28
|
+
.refine((d) => {
|
|
27
29
|
if (d.scope === 'verify-email' && !d.email) {
|
|
28
30
|
return false;
|
|
29
31
|
}
|
|
30
32
|
return true;
|
|
31
33
|
}, {
|
|
32
|
-
path: [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}).refine((d)=>{
|
|
34
|
+
path: ['email'],
|
|
35
|
+
message: 'Email is required',
|
|
36
|
+
})
|
|
37
|
+
.refine((d) => {
|
|
37
38
|
if (d.scope === 'verify-phone' && !d.phoneNumber) {
|
|
38
39
|
return false;
|
|
39
40
|
}
|
|
40
41
|
return true;
|
|
41
42
|
}, {
|
|
42
|
-
path: [
|
|
43
|
-
|
|
44
|
-
],
|
|
45
|
-
message: 'Phone number is required'
|
|
43
|
+
path: ['phoneNumber'],
|
|
44
|
+
message: 'Phone number is required',
|
|
46
45
|
});
|
|
47
46
|
const INVALID_TOKEN_PROBLEM = makeProblem(PROBLEM_INVALID_DATA, 'Unable to verify token. It could have been expired.');
|
|
48
47
|
const VerifyOtpOnlyBody = z.object({
|
|
49
48
|
phoneNumber: z.string().optional(),
|
|
50
|
-
code: z.string()
|
|
49
|
+
code: z.string(),
|
|
51
50
|
});
|
|
52
|
-
export const handleVerifyOTPOnly = async ({ phoneNumber, code })=>{
|
|
53
|
-
const tokenResult = await verifyToken(code, {
|
|
54
|
-
scope: 'verify-phone'
|
|
55
|
-
});
|
|
51
|
+
export const handleVerifyOTPOnly = async ({ phoneNumber, code, }) => {
|
|
52
|
+
const tokenResult = await verifyToken(code, { scope: 'verify-phone' });
|
|
56
53
|
if (tokenResult.err) {
|
|
57
54
|
console.error('Error verifying token', tokenResult.val);
|
|
58
55
|
return new Err(INVALID_TOKEN_PROBLEM);
|
|
@@ -62,21 +59,13 @@ export const handleVerifyOTPOnly = async ({ phoneNumber, code })=>{
|
|
|
62
59
|
// await clearToken(tokenResult.val.id)
|
|
63
60
|
return new Ok({
|
|
64
61
|
phoneNumber,
|
|
65
|
-
phoneNumberVerified: true
|
|
62
|
+
phoneNumberVerified: true,
|
|
66
63
|
});
|
|
67
64
|
};
|
|
68
|
-
export const handleVerifyOTP = async (b)=>{
|
|
69
|
-
const { scope, email, phoneNumber: preFormattedPhoneNumber, code } = VerifyOtpBody.parse(b);
|
|
65
|
+
export const handleVerifyOTP = async (b) => {
|
|
66
|
+
const { scope, email, phoneNumber: preFormattedPhoneNumber, code, } = VerifyOtpBody.parse(b);
|
|
70
67
|
const phoneNumber = `+${preFormattedPhoneNumber?.replace(/[^0-9]/g, '')}`;
|
|
71
|
-
const tokenResult = await verifyToken(code, {
|
|
72
|
-
scope,
|
|
73
|
-
metadata: {
|
|
74
|
-
email,
|
|
75
|
-
phoneNumber
|
|
76
|
-
}
|
|
77
|
-
}, {
|
|
78
|
-
includeUser: true
|
|
79
|
-
});
|
|
68
|
+
const tokenResult = await verifyToken(code, { scope, metadata: { email, phoneNumber } }, { includeUser: true });
|
|
80
69
|
if (tokenResult.err) {
|
|
81
70
|
return new Err(INVALID_TOKEN_PROBLEM);
|
|
82
71
|
}
|
|
@@ -84,25 +73,25 @@ export const handleVerifyOTP = async (b)=>{
|
|
|
84
73
|
return new Err(INVALID_TOKEN_PROBLEM);
|
|
85
74
|
}
|
|
86
75
|
const previousUser = tokenResult.val.user;
|
|
87
|
-
const userUpdate = scope === 'verify-email'
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
76
|
+
const userUpdate = scope === 'verify-email'
|
|
77
|
+
? {
|
|
78
|
+
emailVerified: true,
|
|
79
|
+
email,
|
|
80
|
+
}
|
|
81
|
+
: {
|
|
82
|
+
phoneNumberVerified: true,
|
|
83
|
+
phoneNumber,
|
|
84
|
+
};
|
|
94
85
|
userUpdate.temporary = false;
|
|
95
86
|
userUpdate.temporaryEmail = null;
|
|
96
87
|
const userGroups = new Set(tokenResult.val.user?.groups);
|
|
97
88
|
userGroups.add(ROLES.MEMBER);
|
|
98
|
-
userUpdate.groups = [
|
|
99
|
-
...userGroups
|
|
100
|
-
];
|
|
89
|
+
userUpdate.groups = [...userGroups];
|
|
101
90
|
const user = await prisma.user.update({
|
|
102
91
|
where: {
|
|
103
|
-
id: tokenResult.val.user.id
|
|
92
|
+
id: tokenResult.val.user.id,
|
|
104
93
|
},
|
|
105
|
-
data: userUpdate
|
|
94
|
+
data: userUpdate,
|
|
106
95
|
});
|
|
107
96
|
// delete the previous token
|
|
108
97
|
await clearToken(tokenResult.val.id);
|
|
@@ -112,12 +101,12 @@ export const handleVerifyOTP = async (b)=>{
|
|
|
112
101
|
id: generateId('Token'),
|
|
113
102
|
user: {
|
|
114
103
|
connect: {
|
|
115
|
-
id: user?.id
|
|
116
|
-
}
|
|
104
|
+
id: user?.id,
|
|
105
|
+
},
|
|
117
106
|
},
|
|
118
107
|
expiresAt: addDays(new Date(), 365),
|
|
119
|
-
scope: 'all'
|
|
120
|
-
}
|
|
108
|
+
scope: 'all',
|
|
109
|
+
},
|
|
121
110
|
});
|
|
122
111
|
if (previousUser.email !== user.email) {
|
|
123
112
|
await sendEmailChangedEmail(user.id);
|
|
@@ -125,25 +114,21 @@ export const handleVerifyOTP = async (b)=>{
|
|
|
125
114
|
return new Ok({
|
|
126
115
|
accessToken: token.id,
|
|
127
116
|
expiresAt: token.expiresAt,
|
|
128
|
-
user: user
|
|
117
|
+
user: user,
|
|
129
118
|
});
|
|
130
119
|
};
|
|
131
|
-
export const handleSendVerificationSMS = async (b)=>{
|
|
120
|
+
export const handleSendVerificationSMS = async (b) => {
|
|
132
121
|
const { phoneNumber, checkDuplication, userId } = SendVerificationSMSBody.parse(b);
|
|
133
122
|
const formattedPhoneNumber = `+${phoneNumber.replace(/[^0-9]/g, '')}`;
|
|
134
123
|
if (checkDuplication) {
|
|
135
124
|
const user = await prisma.user.findFirst({
|
|
136
125
|
where: {
|
|
137
126
|
OR: [
|
|
138
|
-
{
|
|
139
|
-
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
phoneNumber: phoneNumber
|
|
143
|
-
}
|
|
127
|
+
{ phoneNumber: formattedPhoneNumber },
|
|
128
|
+
{ phoneNumber: phoneNumber },
|
|
144
129
|
],
|
|
145
|
-
phoneNumberVerified: true
|
|
146
|
-
}
|
|
130
|
+
phoneNumberVerified: true,
|
|
131
|
+
},
|
|
147
132
|
});
|
|
148
133
|
if (user) {
|
|
149
134
|
return new Err(makeProblem(PROBLEM_CONFLICT, 'This phone number is already registered'));
|
|
@@ -156,7 +141,7 @@ export const handleSendVerificationSMS = async (b)=>{
|
|
|
156
141
|
}
|
|
157
142
|
return new Ok({
|
|
158
143
|
success: true,
|
|
159
|
-
code: code.value
|
|
144
|
+
code: code.value,
|
|
160
145
|
});
|
|
161
146
|
}
|
|
162
147
|
// Send the sms verification
|
|
@@ -164,7 +149,6 @@ export const handleSendVerificationSMS = async (b)=>{
|
|
|
164
149
|
if (verificationResult.err) {
|
|
165
150
|
return verificationResult;
|
|
166
151
|
}
|
|
167
|
-
return new Ok({
|
|
168
|
-
success: true
|
|
169
|
-
});
|
|
152
|
+
return new Ok({ success: true });
|
|
170
153
|
};
|
|
154
|
+
//# sourceMappingURL=otp.js.map
|
package/dist/auth/register.js
CHANGED
|
@@ -19,25 +19,19 @@ import { sendVerificationEmail } from './verifications.js';
|
|
|
19
19
|
export const RegistrationValidation = z.object({
|
|
20
20
|
firstName: z.string(),
|
|
21
21
|
lastName: z.string(),
|
|
22
|
-
phoneNumber: z.string().transform((s)=>s.replace(/[\s-]/g, '')),
|
|
23
|
-
authMethod: z.enum([
|
|
24
|
-
'mobile',
|
|
25
|
-
'email',
|
|
26
|
-
'facebook',
|
|
27
|
-
'google',
|
|
28
|
-
'apple'
|
|
29
|
-
]),
|
|
22
|
+
phoneNumber: z.string().transform((s) => s.replace(/[\s-]/g, '')),
|
|
23
|
+
authMethod: z.enum(['mobile', 'email', 'facebook', 'google', 'apple']),
|
|
30
24
|
code: z.string().optional().nullable(),
|
|
31
25
|
keepCode: z.boolean().optional().default(false),
|
|
32
|
-
email: z.email().transform((s)=>s.toLowerCase().trim()),
|
|
33
|
-
dateOfBirth: dateValidation
|
|
26
|
+
email: z.email().transform((s) => s.toLowerCase().trim()),
|
|
27
|
+
dateOfBirth: dateValidation
|
|
28
|
+
.refine((d) => {
|
|
34
29
|
return isAfter(d, subYears(new Date(), 25));
|
|
35
30
|
}, {
|
|
36
|
-
path: [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}).optional(),
|
|
31
|
+
path: ['dateOfBirth'],
|
|
32
|
+
message: 'You must be at least 25 years old to signup for the service.',
|
|
33
|
+
})
|
|
34
|
+
.optional(),
|
|
41
35
|
password: z.string().min(6).optional(),
|
|
42
36
|
noMarketing: z.boolean().optional(),
|
|
43
37
|
pageSource: z.string().optional().nullable(),
|
|
@@ -47,14 +41,12 @@ export const RegistrationValidation = z.object({
|
|
|
47
41
|
userAgent: z.string().optional(),
|
|
48
42
|
ipAddress: z.ipv4().or(z.ipv6()),
|
|
49
43
|
sessionToken: z.string().optional(),
|
|
50
|
-
sessionId: z.string().optional()
|
|
44
|
+
sessionId: z.string().optional(),
|
|
51
45
|
});
|
|
52
|
-
export const handleRegister = async ({ noMarketing, password, authMethod, phoneNumber, code, keepCode, pageSource, skipPassword, fingerprint, termsVersion, userAgent, ipAddress, sessionToken, sessionId, ...body })=>{
|
|
46
|
+
export const handleRegister = async ({ noMarketing, password, authMethod, phoneNumber, code, keepCode, pageSource, skipPassword, fingerprint, termsVersion, userAgent, ipAddress, sessionToken, sessionId, ...body }) => {
|
|
53
47
|
let phoneNumberVerified = false;
|
|
54
48
|
if (code) {
|
|
55
|
-
const tokenResult = await verifyToken(code, {
|
|
56
|
-
scope: 'verify-phone'
|
|
57
|
-
});
|
|
49
|
+
const tokenResult = await verifyToken(code, { scope: 'verify-phone' });
|
|
58
50
|
if (tokenResult.err) {
|
|
59
51
|
return new Err(makeProblem(PROBLEM_CONFLICT, 'Invalid OTP token'));
|
|
60
52
|
}
|
|
@@ -68,9 +60,7 @@ export const handleRegister = async ({ noMarketing, password, authMethod, phoneN
|
|
|
68
60
|
}
|
|
69
61
|
// Check if the user exists
|
|
70
62
|
const foundUser = await prisma.user.findFirst({
|
|
71
|
-
where: {
|
|
72
|
-
email: body.email
|
|
73
|
-
}
|
|
63
|
+
where: { email: body.email },
|
|
74
64
|
});
|
|
75
65
|
if (foundUser) {
|
|
76
66
|
return new Err(makeProblem(PROBLEM_CONFLICT, 'A user with this email address already exists. Did you mean to login?'));
|
|
@@ -87,12 +77,10 @@ export const handleRegister = async ({ noMarketing, password, authMethod, phoneN
|
|
|
87
77
|
preferredCurrency: 'MYR',
|
|
88
78
|
preferredLocale: 'en',
|
|
89
79
|
phoneNumberVerified,
|
|
90
|
-
groups: [
|
|
91
|
-
'member'
|
|
92
|
-
],
|
|
80
|
+
groups: ['member'],
|
|
93
81
|
signupParams: {
|
|
94
82
|
method: authMethod,
|
|
95
|
-
source: pageSource
|
|
83
|
+
source: pageSource,
|
|
96
84
|
},
|
|
97
85
|
registrationComplete: true,
|
|
98
86
|
accounts: {
|
|
@@ -101,16 +89,16 @@ export const handleRegister = async ({ noMarketing, password, authMethod, phoneN
|
|
|
101
89
|
object: 'account',
|
|
102
90
|
type: 'default',
|
|
103
91
|
provider: 'credentials',
|
|
104
|
-
providerAccountId: id
|
|
105
|
-
}
|
|
92
|
+
providerAccountId: id,
|
|
93
|
+
},
|
|
106
94
|
},
|
|
107
95
|
tokens: {
|
|
108
96
|
create: {
|
|
109
97
|
id: tokenId,
|
|
110
98
|
expiresAt: addDays(new Date(), 365),
|
|
111
|
-
scope: 'all'
|
|
112
|
-
}
|
|
113
|
-
}
|
|
99
|
+
scope: 'all',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
114
102
|
};
|
|
115
103
|
const { user: _removeDueToNestedCreate, ...consentCreate } = getConsentCreateData({
|
|
116
104
|
user: userCreateData,
|
|
@@ -119,28 +107,28 @@ export const handleRegister = async ({ noMarketing, password, authMethod, phoneN
|
|
|
119
107
|
ipAddress: ipAddress,
|
|
120
108
|
userAgent: userAgent,
|
|
121
109
|
sessionToken: tokenId,
|
|
122
|
-
consentType: 'terms'
|
|
110
|
+
consentType: 'terms',
|
|
123
111
|
});
|
|
124
112
|
const finalCreateData = {
|
|
125
113
|
...userCreateData,
|
|
126
114
|
consents: {
|
|
127
|
-
create: consentCreate
|
|
128
|
-
}
|
|
115
|
+
create: consentCreate,
|
|
116
|
+
},
|
|
129
117
|
};
|
|
130
118
|
// Find a host with the same email
|
|
131
119
|
const host = await prisma.host.findFirst({
|
|
132
120
|
where: {
|
|
133
|
-
email: finalCreateData.email
|
|
121
|
+
email: finalCreateData.email,
|
|
134
122
|
},
|
|
135
123
|
select: {
|
|
136
|
-
id: true
|
|
137
|
-
}
|
|
124
|
+
id: true,
|
|
125
|
+
},
|
|
138
126
|
});
|
|
139
127
|
if (host?.id) {
|
|
140
128
|
finalCreateData.host = {
|
|
141
129
|
connect: {
|
|
142
|
-
id: host.id
|
|
143
|
-
}
|
|
130
|
+
id: host.id,
|
|
131
|
+
},
|
|
144
132
|
};
|
|
145
133
|
}
|
|
146
134
|
const user = await prisma.user.create({
|
|
@@ -148,21 +136,20 @@ export const handleRegister = async ({ noMarketing, password, authMethod, phoneN
|
|
|
148
136
|
include: {
|
|
149
137
|
tokens: {
|
|
150
138
|
where: {
|
|
151
|
-
id: tokenId
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
139
|
+
id: tokenId,
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
155
143
|
});
|
|
156
144
|
// We don't want this to be a task. It should be instant
|
|
157
145
|
await sendVerificationEmail(user.id);
|
|
158
146
|
if (!noMarketing) {
|
|
159
|
-
await setContactInList(user.id, {
|
|
160
|
-
generalMarketing: true
|
|
161
|
-
});
|
|
147
|
+
await setContactInList(user.id, { generalMarketing: true });
|
|
162
148
|
}
|
|
163
149
|
await refreshEmailPreferences(user.id);
|
|
164
150
|
return new Ok({
|
|
165
151
|
token: user.tokens[0],
|
|
166
|
-
user
|
|
152
|
+
user,
|
|
167
153
|
});
|
|
168
154
|
};
|
|
155
|
+
//# sourceMappingURL=register.js.map
|