@driveflux/api-functions 0.0.7-next.2 → 0.0.7-next.20
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 +66 -325
- package/dist/auth/emails.js +42 -210
- package/dist/auth/formatter.js +9 -9
- package/dist/auth/otp.js +120 -374
- package/dist/auth/register.js +95 -383
- package/dist/auth/register.js.map +1 -1
- package/dist/auth/tokens.d.ts +3 -3
- package/dist/auth/tokens.js +114 -426
- package/dist/auth/verifications.js +176 -581
- package/dist/constants.js +4 -4
- package/dist/mailjet/calls/manage-contacts-in-list.d.ts +2 -2
- package/dist/mailjet/calls/manage-contacts-in-list.d.ts.map +1 -1
- package/dist/mailjet/calls/manage-contacts-in-list.js +22 -167
- package/dist/mailjet/calls/manage-contacts-in-list.js.map +1 -1
- package/dist/mailjet/calls/manage-subscription-status.d.ts +2 -2
- package/dist/mailjet/calls/manage-subscription-status.d.ts.map +1 -1
- package/dist/mailjet/calls/manage-subscription-status.js +13 -154
- package/dist/mailjet/calls/manage-subscription-status.js.map +1 -1
- package/dist/mailjet/calls/request-service.js +18 -182
- package/dist/mailjet/refresh-email-preferences.js +21 -221
- package/dist/mailjet/set-contact.d.ts +2 -2
- package/dist/mailjet/set-contact.d.ts.map +1 -1
- package/dist/mailjet/set-contact.js +21 -213
- package/dist/mailjet/set-contact.js.map +1 -1
- package/dist/mailjet/types.d.ts +2 -2
- package/dist/mailjet/types.d.ts.map +1 -1
- package/dist/mailjet/utils/convert-to-array.d.ts +1 -1
- package/dist/mailjet/utils/convert-to-array.d.ts.map +1 -1
- package/dist/mailjet/utils/convert-to-array.js +9 -56
- package/dist/mailjet/utils/extract-email-preferences.d.ts +1 -1
- package/dist/mailjet/utils/extract-email-preferences.d.ts.map +1 -1
- package/dist/mailjet/utils/extract-email-preferences.js +37 -214
- package/dist/mailjet/utils/lists.js +28 -248
- package/dist/mailjet/utils/update-email-references.d.ts +2 -2
- package/dist/mailjet/utils/update-email-references.d.ts.map +1 -1
- package/dist/mailjet/utils/update-email-references.js +27 -207
- package/dist/mailjet/utils/update-email-references.js.map +1 -1
- package/dist/notion/client.js +50 -196
- package/dist/notion/helpful.js +25 -169
- package/dist/notion/schemas/block.js +1 -1
- package/dist/notion/schemas/common.js +7 -9
- package/dist/notion/schemas/database.d.ts +1 -1
- package/dist/notion/schemas/database.js +68 -100
- package/dist/notion/schemas/emoji.js +1 -1
- package/dist/notion/schemas/file.js +1 -1
- package/dist/notion/schemas/kb.js +3 -3
- package/dist/notion/schemas/page.d.ts +1 -1
- package/dist/notion/schemas/page.js +69 -103
- package/dist/notion/schemas/parent.js +4 -4
- package/dist/notion/schemas/user.js +2 -2
- package/dist/reservation/agree.d.ts +1 -1
- package/dist/reservation/agree.d.ts.map +1 -1
- package/dist/reservation/agree.js +17 -157
- package/dist/reservation/checks.d.ts +1 -1
- package/dist/reservation/checks.d.ts.map +1 -1
- package/dist/reservation/checks.js +21 -177
- package/dist/reservation/display-vehicle.d.ts +1 -1
- package/dist/reservation/display-vehicle.js +122 -500
- package/dist/reservation/display-vehicle.js.map +1 -1
- package/dist/reservation/fetch-or-create.d.ts +2 -2
- package/dist/reservation/fetch-or-create.d.ts.map +1 -1
- package/dist/reservation/fetch-or-create.js +188 -478
- package/dist/reservation/fetch-or-create.js.map +1 -1
- package/dist/reservation/invoice.d.ts +3 -3
- package/dist/reservation/invoice.d.ts.map +1 -1
- package/dist/reservation/invoice.js +182 -492
- package/dist/reservation/invoice.js.map +1 -1
- package/dist/reservation/payer.d.ts +1 -1
- package/dist/reservation/payer.d.ts.map +1 -1
- package/dist/reservation/payer.js +25 -175
- package/dist/reservation/reserve.d.ts +1 -1
- package/dist/reservation/reserve.d.ts.map +1 -1
- package/dist/reservation/reserve.js +35 -196
- package/dist/reservation/reserve.js.map +1 -1
- package/dist/reservation/types.d.ts +1 -0
- package/dist/reservation/types.d.ts.map +1 -1
- package/dist/reservation/vehicle.d.ts +1 -1
- package/dist/reservation/vehicle.d.ts.map +1 -1
- package/dist/reservation/vehicle.js +23 -188
- package/dist/reservation/vehicle.js.map +1 -1
- package/dist/slack.js +57 -268
- package/dist/validation.js +38 -98
- package/dist/vehicle/vehicle-pricing/constants.d.ts +1 -1
- package/dist/vehicle/vehicle-pricing/constants.d.ts.map +1 -1
- package/dist/vehicle/vehicle-pricing/constants.js +16 -16
- package/dist/vehicle/vehicle-pricing/index.d.ts +1 -1
- package/dist/vehicle/vehicle-pricing/index.d.ts.map +1 -1
- package/dist/vehicle/vehicle-pricing/index.js +87 -259
- package/dist/vehicle/vehicle-pricing/index.js.map +1 -1
- package/package.json +21 -21
package/dist/auth/formatter.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const knownCountryCodes = [
|
|
2
2
|
'1',
|
|
3
3
|
'376',
|
|
4
4
|
'93',
|
|
@@ -223,17 +223,17 @@ var knownCountryCodes = [
|
|
|
223
223
|
'692',
|
|
224
224
|
'383'
|
|
225
225
|
];
|
|
226
|
-
export
|
|
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
|
|
230
|
-
|
|
230
|
+
const withPlus = cleaned.startsWith('+') ? cleaned : `+${cleaned}`;
|
|
231
231
|
// Find the country code by checking against known codes
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
let countryCode = '';
|
|
233
|
+
let remainingNumber = '';
|
|
234
234
|
// Try to find the country code by checking the longest matches first
|
|
235
|
-
for(
|
|
236
|
-
|
|
235
|
+
for(let i = 4; i >= 1; i--){
|
|
236
|
+
const potentialCode = withPlus.substring(1, 1 + i) // Skip the + and take i digits
|
|
237
237
|
;
|
|
238
238
|
if (knownCountryCodes.includes(potentialCode)) {
|
|
239
239
|
countryCode = potentialCode;
|
|
@@ -243,7 +243,7 @@ export var cleanupPhoneNumber = function(phoneNumber) {
|
|
|
243
243
|
}
|
|
244
244
|
// If we found a country code and the remaining number starts with 0, remove it
|
|
245
245
|
if (countryCode && remainingNumber.startsWith('0')) {
|
|
246
|
-
return
|
|
246
|
+
return `+${countryCode}${remainingNumber.substring(1)}`;
|
|
247
247
|
}
|
|
248
248
|
return withPlus;
|
|
249
249
|
};
|
package/dist/auth/otp.js
CHANGED
|
@@ -1,148 +1,3 @@
|
|
|
1
|
-
function _array_like_to_array(arr, len) {
|
|
2
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
-
return arr2;
|
|
5
|
-
}
|
|
6
|
-
function _array_without_holes(arr) {
|
|
7
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
8
|
-
}
|
|
9
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
-
try {
|
|
11
|
-
var info = gen[key](arg);
|
|
12
|
-
var value = info.value;
|
|
13
|
-
} catch (error) {
|
|
14
|
-
reject(error);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
if (info.done) {
|
|
18
|
-
resolve(value);
|
|
19
|
-
} else {
|
|
20
|
-
Promise.resolve(value).then(_next, _throw);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function _async_to_generator(fn) {
|
|
24
|
-
return function() {
|
|
25
|
-
var self = this, args = arguments;
|
|
26
|
-
return new Promise(function(resolve, reject) {
|
|
27
|
-
var gen = fn.apply(self, args);
|
|
28
|
-
function _next(value) {
|
|
29
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
-
}
|
|
31
|
-
function _throw(err) {
|
|
32
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
-
}
|
|
34
|
-
_next(undefined);
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function _iterable_to_array(iter) {
|
|
39
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
40
|
-
}
|
|
41
|
-
function _non_iterable_spread() {
|
|
42
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
43
|
-
}
|
|
44
|
-
function _to_consumable_array(arr) {
|
|
45
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
46
|
-
}
|
|
47
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
48
|
-
if (!o) return;
|
|
49
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
50
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
51
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
52
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
53
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
54
|
-
}
|
|
55
|
-
function _ts_generator(thisArg, body) {
|
|
56
|
-
var f, y, t, _ = {
|
|
57
|
-
label: 0,
|
|
58
|
-
sent: function() {
|
|
59
|
-
if (t[0] & 1) throw t[1];
|
|
60
|
-
return t[1];
|
|
61
|
-
},
|
|
62
|
-
trys: [],
|
|
63
|
-
ops: []
|
|
64
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
65
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
66
|
-
return this;
|
|
67
|
-
}), g;
|
|
68
|
-
function verb(n) {
|
|
69
|
-
return function(v) {
|
|
70
|
-
return step([
|
|
71
|
-
n,
|
|
72
|
-
v
|
|
73
|
-
]);
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
function step(op) {
|
|
77
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
78
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
79
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
80
|
-
if (y = 0, t) op = [
|
|
81
|
-
op[0] & 2,
|
|
82
|
-
t.value
|
|
83
|
-
];
|
|
84
|
-
switch(op[0]){
|
|
85
|
-
case 0:
|
|
86
|
-
case 1:
|
|
87
|
-
t = op;
|
|
88
|
-
break;
|
|
89
|
-
case 4:
|
|
90
|
-
_.label++;
|
|
91
|
-
return {
|
|
92
|
-
value: op[1],
|
|
93
|
-
done: false
|
|
94
|
-
};
|
|
95
|
-
case 5:
|
|
96
|
-
_.label++;
|
|
97
|
-
y = op[1];
|
|
98
|
-
op = [
|
|
99
|
-
0
|
|
100
|
-
];
|
|
101
|
-
continue;
|
|
102
|
-
case 7:
|
|
103
|
-
op = _.ops.pop();
|
|
104
|
-
_.trys.pop();
|
|
105
|
-
continue;
|
|
106
|
-
default:
|
|
107
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
108
|
-
_ = 0;
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
112
|
-
_.label = op[1];
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
116
|
-
_.label = t[1];
|
|
117
|
-
t = op;
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
if (t && _.label < t[2]) {
|
|
121
|
-
_.label = t[2];
|
|
122
|
-
_.ops.push(op);
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
if (t[2]) _.ops.pop();
|
|
126
|
-
_.trys.pop();
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
op = body.call(thisArg, _);
|
|
130
|
-
} catch (e) {
|
|
131
|
-
op = [
|
|
132
|
-
6,
|
|
133
|
-
e
|
|
134
|
-
];
|
|
135
|
-
y = 0;
|
|
136
|
-
} finally{
|
|
137
|
-
f = t = 0;
|
|
138
|
-
}
|
|
139
|
-
if (op[0] & 5) throw op[1];
|
|
140
|
-
return {
|
|
141
|
-
value: op[0] ? op[1] : void 0,
|
|
142
|
-
done: true
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
1
|
import { ROLES } from '@driveflux/auth/authorization/constants';
|
|
147
2
|
import { config } from '@driveflux/config/backend';
|
|
148
3
|
import { prisma } from '@driveflux/db';
|
|
@@ -154,23 +9,21 @@ import { z } from 'zod';
|
|
|
154
9
|
import { sendEmailChangedEmail } from './emails.js';
|
|
155
10
|
import { clearToken, createSMSToken, verifyToken } from './tokens.js';
|
|
156
11
|
import { sendVerificationSMS } from './verifications.js';
|
|
157
|
-
|
|
12
|
+
const SendVerificationSMSBody = z.object({
|
|
158
13
|
phoneNumber: z.string(),
|
|
159
14
|
checkDuplication: z.boolean().optional().nullable(),
|
|
160
15
|
includeUser: z.boolean().optional().nullable(),
|
|
161
16
|
userId: z.string().optional().nullable()
|
|
162
17
|
});
|
|
163
|
-
|
|
18
|
+
const VerifyOtpBody = z.object({
|
|
164
19
|
scope: z.enum([
|
|
165
20
|
'verify-email',
|
|
166
21
|
'verify-phone'
|
|
167
22
|
]),
|
|
168
|
-
email: z.email().optional().transform(
|
|
169
|
-
return email === null || email === void 0 ? void 0 : email.toLowerCase().trim();
|
|
170
|
-
}),
|
|
23
|
+
email: z.email().optional().transform((email)=>email?.toLowerCase().trim()),
|
|
171
24
|
phoneNumber: z.string().optional(),
|
|
172
25
|
code: z.string()
|
|
173
|
-
}).refine(
|
|
26
|
+
}).refine((d)=>{
|
|
174
27
|
if (d.scope === 'verify-email' && !d.email) {
|
|
175
28
|
return false;
|
|
176
29
|
}
|
|
@@ -180,7 +33,7 @@ var VerifyOtpBody = z.object({
|
|
|
180
33
|
'email'
|
|
181
34
|
],
|
|
182
35
|
message: 'Email is required'
|
|
183
|
-
}).refine(
|
|
36
|
+
}).refine((d)=>{
|
|
184
37
|
if (d.scope === 'verify-phone' && !d.phoneNumber) {
|
|
185
38
|
return false;
|
|
186
39
|
}
|
|
@@ -191,234 +44,127 @@ var VerifyOtpBody = z.object({
|
|
|
191
44
|
],
|
|
192
45
|
message: 'Phone number is required'
|
|
193
46
|
});
|
|
194
|
-
|
|
195
|
-
|
|
47
|
+
const INVALID_TOKEN_PROBLEM = makeProblem(PROBLEM_INVALID_DATA, 'Unable to verify token. It could have been expired.');
|
|
48
|
+
const VerifyOtpOnlyBody = z.object({
|
|
196
49
|
phoneNumber: z.string().optional(),
|
|
197
50
|
code: z.string()
|
|
198
51
|
});
|
|
199
|
-
export
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (tokenResult.err) {
|
|
215
|
-
console.log('Error verifying token', tokenResult.val);
|
|
216
|
-
return [
|
|
217
|
-
2,
|
|
218
|
-
new Err(INVALID_TOKEN_PROBLEM)
|
|
219
|
-
];
|
|
220
|
-
}
|
|
221
|
-
// delete the previous token
|
|
222
|
-
// TODO maybe: verify this token when registering one more time then clear it
|
|
223
|
-
// await clearToken(tokenResult.val.id)
|
|
224
|
-
return [
|
|
225
|
-
2,
|
|
226
|
-
new Ok({
|
|
227
|
-
phoneNumber: phoneNumber,
|
|
228
|
-
phoneNumberVerified: true
|
|
229
|
-
})
|
|
230
|
-
];
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
})();
|
|
52
|
+
export const handleVerifyOTPOnly = async ({ phoneNumber, code })=>{
|
|
53
|
+
const tokenResult = await verifyToken(code, {
|
|
54
|
+
scope: 'verify-phone'
|
|
55
|
+
});
|
|
56
|
+
if (tokenResult.err) {
|
|
57
|
+
console.log('Error verifying token', tokenResult.val);
|
|
58
|
+
return new Err(INVALID_TOKEN_PROBLEM);
|
|
59
|
+
}
|
|
60
|
+
// delete the previous token
|
|
61
|
+
// TODO maybe: verify this token when registering one more time then clear it
|
|
62
|
+
// await clearToken(tokenResult.val.id)
|
|
63
|
+
return new Ok({
|
|
64
|
+
phoneNumber,
|
|
65
|
+
phoneNumberVerified: true
|
|
66
|
+
});
|
|
234
67
|
};
|
|
235
|
-
export
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
];
|
|
298
|
-
case 3:
|
|
299
|
-
_state.sent();
|
|
300
|
-
return [
|
|
301
|
-
4,
|
|
302
|
-
prisma.token.create({
|
|
303
|
-
data: {
|
|
304
|
-
id: generateId('Token'),
|
|
305
|
-
user: {
|
|
306
|
-
connect: {
|
|
307
|
-
id: user === null || user === void 0 ? void 0 : user.id
|
|
308
|
-
}
|
|
309
|
-
},
|
|
310
|
-
expiresAt: addDays(new Date(), 365),
|
|
311
|
-
scope: 'all'
|
|
312
|
-
}
|
|
313
|
-
})
|
|
314
|
-
];
|
|
315
|
-
case 4:
|
|
316
|
-
token = _state.sent();
|
|
317
|
-
if (!(previousUser.email !== user.email)) return [
|
|
318
|
-
3,
|
|
319
|
-
6
|
|
320
|
-
];
|
|
321
|
-
return [
|
|
322
|
-
4,
|
|
323
|
-
sendEmailChangedEmail(user.id)
|
|
324
|
-
];
|
|
325
|
-
case 5:
|
|
326
|
-
_state.sent();
|
|
327
|
-
_state.label = 6;
|
|
328
|
-
case 6:
|
|
329
|
-
return [
|
|
330
|
-
2,
|
|
331
|
-
new Ok({
|
|
332
|
-
accessToken: token.id,
|
|
333
|
-
expiresAt: token.expiresAt,
|
|
334
|
-
user: user
|
|
335
|
-
})
|
|
336
|
-
];
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
})();
|
|
68
|
+
export const handleVerifyOTP = async (b)=>{
|
|
69
|
+
const { scope, email, phoneNumber: preFormattedPhoneNumber, code } = VerifyOtpBody.parse(b);
|
|
70
|
+
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
|
+
});
|
|
80
|
+
if (tokenResult.err) {
|
|
81
|
+
return new Err(INVALID_TOKEN_PROBLEM);
|
|
82
|
+
}
|
|
83
|
+
if (!tokenResult.val.user) {
|
|
84
|
+
return new Err(INVALID_TOKEN_PROBLEM);
|
|
85
|
+
}
|
|
86
|
+
const previousUser = tokenResult.val.user;
|
|
87
|
+
const userUpdate = scope === 'verify-email' ? {
|
|
88
|
+
emailVerified: true,
|
|
89
|
+
email
|
|
90
|
+
} : {
|
|
91
|
+
phoneNumberVerified: true,
|
|
92
|
+
phoneNumber
|
|
93
|
+
};
|
|
94
|
+
userUpdate.temporary = false;
|
|
95
|
+
userUpdate.temporaryEmail = null;
|
|
96
|
+
const userGroups = new Set(tokenResult.val.user?.groups);
|
|
97
|
+
userGroups.add(ROLES.MEMBER);
|
|
98
|
+
userUpdate.groups = [
|
|
99
|
+
...userGroups
|
|
100
|
+
];
|
|
101
|
+
const user = await prisma.user.update({
|
|
102
|
+
where: {
|
|
103
|
+
id: tokenResult.val.user.id
|
|
104
|
+
},
|
|
105
|
+
data: userUpdate
|
|
106
|
+
});
|
|
107
|
+
// delete the previous token
|
|
108
|
+
await clearToken(tokenResult.val.id);
|
|
109
|
+
// Login the user
|
|
110
|
+
const token = await prisma.token.create({
|
|
111
|
+
data: {
|
|
112
|
+
id: generateId('Token'),
|
|
113
|
+
user: {
|
|
114
|
+
connect: {
|
|
115
|
+
id: user?.id
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
expiresAt: addDays(new Date(), 365),
|
|
119
|
+
scope: 'all'
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
if (previousUser.email !== user.email) {
|
|
123
|
+
await sendEmailChangedEmail(user.id);
|
|
124
|
+
}
|
|
125
|
+
return new Ok({
|
|
126
|
+
accessToken: token.id,
|
|
127
|
+
expiresAt: token.expiresAt,
|
|
128
|
+
user: user
|
|
129
|
+
});
|
|
340
130
|
};
|
|
341
|
-
export
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
return [
|
|
354
|
-
4,
|
|
355
|
-
prisma.user.findFirst({
|
|
356
|
-
where: {
|
|
357
|
-
OR: [
|
|
358
|
-
{
|
|
359
|
-
phoneNumber: formattedPhoneNumber
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
phoneNumber: phoneNumber
|
|
363
|
-
}
|
|
364
|
-
],
|
|
365
|
-
phoneNumberVerified: true
|
|
366
|
-
}
|
|
367
|
-
})
|
|
368
|
-
];
|
|
369
|
-
case 1:
|
|
370
|
-
user = _state.sent();
|
|
371
|
-
if (user) {
|
|
372
|
-
return [
|
|
373
|
-
2,
|
|
374
|
-
new Err(makeProblem(PROBLEM_CONFLICT, 'This phone number is already registered'))
|
|
375
|
-
];
|
|
376
|
-
}
|
|
377
|
-
_state.label = 2;
|
|
378
|
-
case 2:
|
|
379
|
-
if (!(!config.isProd && !config.sendSMSOutsideOfProd)) return [
|
|
380
|
-
3,
|
|
381
|
-
4
|
|
382
|
-
];
|
|
383
|
-
return [
|
|
384
|
-
4,
|
|
385
|
-
createSMSToken(userId || null, formattedPhoneNumber)
|
|
386
|
-
];
|
|
387
|
-
case 3:
|
|
388
|
-
code = _state.sent();
|
|
389
|
-
if (!(code === null || code === void 0 ? void 0 : code.value)) {
|
|
390
|
-
return [
|
|
391
|
-
2,
|
|
392
|
-
new Err(makeProblem(PROBLEM_INVALID_DATA, 'Invalid Data'))
|
|
393
|
-
];
|
|
394
|
-
}
|
|
395
|
-
return [
|
|
396
|
-
2,
|
|
397
|
-
new Ok({
|
|
398
|
-
success: true,
|
|
399
|
-
code: code.value
|
|
400
|
-
})
|
|
401
|
-
];
|
|
402
|
-
case 4:
|
|
403
|
-
return [
|
|
404
|
-
4,
|
|
405
|
-
sendVerificationSMS(userId || null, phoneNumber)
|
|
406
|
-
];
|
|
407
|
-
case 5:
|
|
408
|
-
verificationResult = _state.sent();
|
|
409
|
-
if (verificationResult.err) {
|
|
410
|
-
return [
|
|
411
|
-
2,
|
|
412
|
-
verificationResult
|
|
413
|
-
];
|
|
131
|
+
export const handleSendVerificationSMS = async (b)=>{
|
|
132
|
+
const { phoneNumber, checkDuplication, userId } = SendVerificationSMSBody.parse(b);
|
|
133
|
+
const formattedPhoneNumber = `+${phoneNumber.replace(/[^0-9]/g, '')}`;
|
|
134
|
+
if (checkDuplication) {
|
|
135
|
+
const user = await prisma.user.findFirst({
|
|
136
|
+
where: {
|
|
137
|
+
OR: [
|
|
138
|
+
{
|
|
139
|
+
phoneNumber: formattedPhoneNumber
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
phoneNumber: phoneNumber
|
|
414
143
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
new Ok({
|
|
418
|
-
success: true
|
|
419
|
-
})
|
|
420
|
-
];
|
|
144
|
+
],
|
|
145
|
+
phoneNumberVerified: true
|
|
421
146
|
}
|
|
422
147
|
});
|
|
423
|
-
|
|
148
|
+
if (user) {
|
|
149
|
+
return new Err(makeProblem(PROBLEM_CONFLICT, 'This phone number is already registered'));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (!config.isProd && !config.sendSMSOutsideOfProd) {
|
|
153
|
+
const code = await createSMSToken(userId || null, formattedPhoneNumber);
|
|
154
|
+
if (!code?.value) {
|
|
155
|
+
return new Err(makeProblem(PROBLEM_INVALID_DATA, 'Invalid Data'));
|
|
156
|
+
}
|
|
157
|
+
return new Ok({
|
|
158
|
+
success: true,
|
|
159
|
+
code: code.value
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
// Send the sms verification
|
|
163
|
+
const verificationResult = await sendVerificationSMS(userId || null, phoneNumber);
|
|
164
|
+
if (verificationResult.err) {
|
|
165
|
+
return verificationResult;
|
|
166
|
+
}
|
|
167
|
+
return new Ok({
|
|
168
|
+
success: true
|
|
169
|
+
});
|
|
424
170
|
};
|