@driveflux/api-functions 0.0.7-next.18 → 0.0.7-next.2
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 +325 -66
- package/dist/auth/emails.js +210 -42
- package/dist/auth/formatter.js +9 -9
- package/dist/auth/otp.js +374 -120
- package/dist/auth/register.js +383 -95
- package/dist/auth/register.js.map +1 -1
- package/dist/auth/tokens.d.ts +3 -3
- package/dist/auth/tokens.js +426 -114
- package/dist/auth/verifications.js +581 -176
- 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 +167 -22
- 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 +154 -13
- package/dist/mailjet/calls/manage-subscription-status.js.map +1 -1
- package/dist/mailjet/calls/request-service.js +182 -18
- package/dist/mailjet/refresh-email-preferences.js +221 -21
- 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 +213 -21
- 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 +56 -9
- 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 +214 -37
- package/dist/mailjet/utils/lists.js +248 -28
- 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 +207 -27
- package/dist/mailjet/utils/update-email-references.js.map +1 -1
- package/dist/notion/client.js +196 -50
- package/dist/notion/helpful.js +169 -25
- package/dist/notion/schemas/block.js +1 -1
- package/dist/notion/schemas/common.js +9 -7
- package/dist/notion/schemas/database.d.ts +1 -1
- package/dist/notion/schemas/database.js +100 -68
- 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 +103 -69
- 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 +157 -17
- package/dist/reservation/checks.d.ts +1 -1
- package/dist/reservation/checks.d.ts.map +1 -1
- package/dist/reservation/checks.js +177 -21
- package/dist/reservation/display-vehicle.d.ts +1 -1
- package/dist/reservation/display-vehicle.js +500 -122
- 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 +478 -188
- 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 +492 -182
- 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 +175 -25
- package/dist/reservation/reserve.d.ts +1 -1
- package/dist/reservation/reserve.d.ts.map +1 -1
- package/dist/reservation/reserve.js +196 -35
- package/dist/reservation/reserve.js.map +1 -1
- package/dist/reservation/types.d.ts +0 -1
- 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 +188 -23
- package/dist/reservation/vehicle.js.map +1 -1
- package/dist/slack.js +268 -57
- package/dist/validation.js +98 -38
- 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 +259 -87
- 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
|
+
var knownCountryCodes = [
|
|
2
2
|
'1',
|
|
3
3
|
'376',
|
|
4
4
|
'93',
|
|
@@ -223,17 +223,17 @@ const knownCountryCodes = [
|
|
|
223
223
|
'692',
|
|
224
224
|
'383'
|
|
225
225
|
];
|
|
226
|
-
export
|
|
226
|
+
export var cleanupPhoneNumber = function(phoneNumber) {
|
|
227
227
|
// Remove all characters except numbers and +
|
|
228
|
-
|
|
228
|
+
var cleaned = phoneNumber.replace(/[^\d+]/g, '');
|
|
229
229
|
// If it doesn't start with +, add it
|
|
230
|
-
|
|
230
|
+
var withPlus = cleaned.startsWith('+') ? cleaned : "+".concat(cleaned);
|
|
231
231
|
// Find the country code by checking against known codes
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
var countryCode = '';
|
|
233
|
+
var remainingNumber = '';
|
|
234
234
|
// Try to find the country code by checking the longest matches first
|
|
235
|
-
for(
|
|
236
|
-
|
|
235
|
+
for(var i = 4; i >= 1; i--){
|
|
236
|
+
var 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 const cleanupPhoneNumber = (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 "+".concat(countryCode).concat(remainingNumber.substring(1));
|
|
247
247
|
}
|
|
248
248
|
return withPlus;
|
|
249
249
|
};
|
package/dist/auth/otp.js
CHANGED
|
@@ -1,3 +1,148 @@
|
|
|
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
|
+
}
|
|
1
146
|
import { ROLES } from '@driveflux/auth/authorization/constants';
|
|
2
147
|
import { config } from '@driveflux/config/backend';
|
|
3
148
|
import { prisma } from '@driveflux/db';
|
|
@@ -9,21 +154,23 @@ import { z } from 'zod';
|
|
|
9
154
|
import { sendEmailChangedEmail } from './emails.js';
|
|
10
155
|
import { clearToken, createSMSToken, verifyToken } from './tokens.js';
|
|
11
156
|
import { sendVerificationSMS } from './verifications.js';
|
|
12
|
-
|
|
157
|
+
var SendVerificationSMSBody = z.object({
|
|
13
158
|
phoneNumber: z.string(),
|
|
14
159
|
checkDuplication: z.boolean().optional().nullable(),
|
|
15
160
|
includeUser: z.boolean().optional().nullable(),
|
|
16
161
|
userId: z.string().optional().nullable()
|
|
17
162
|
});
|
|
18
|
-
|
|
163
|
+
var VerifyOtpBody = z.object({
|
|
19
164
|
scope: z.enum([
|
|
20
165
|
'verify-email',
|
|
21
166
|
'verify-phone'
|
|
22
167
|
]),
|
|
23
|
-
email: z.email().optional().transform((email)
|
|
168
|
+
email: z.email().optional().transform(function(email) {
|
|
169
|
+
return email === null || email === void 0 ? void 0 : email.toLowerCase().trim();
|
|
170
|
+
}),
|
|
24
171
|
phoneNumber: z.string().optional(),
|
|
25
172
|
code: z.string()
|
|
26
|
-
}).refine((d)
|
|
173
|
+
}).refine(function(d) {
|
|
27
174
|
if (d.scope === 'verify-email' && !d.email) {
|
|
28
175
|
return false;
|
|
29
176
|
}
|
|
@@ -33,7 +180,7 @@ const VerifyOtpBody = z.object({
|
|
|
33
180
|
'email'
|
|
34
181
|
],
|
|
35
182
|
message: 'Email is required'
|
|
36
|
-
}).refine((d)
|
|
183
|
+
}).refine(function(d) {
|
|
37
184
|
if (d.scope === 'verify-phone' && !d.phoneNumber) {
|
|
38
185
|
return false;
|
|
39
186
|
}
|
|
@@ -44,127 +191,234 @@ const VerifyOtpBody = z.object({
|
|
|
44
191
|
],
|
|
45
192
|
message: 'Phone number is required'
|
|
46
193
|
});
|
|
47
|
-
|
|
48
|
-
|
|
194
|
+
var INVALID_TOKEN_PROBLEM = makeProblem(PROBLEM_INVALID_DATA, 'Unable to verify token. It could have been expired.');
|
|
195
|
+
var VerifyOtpOnlyBody = z.object({
|
|
49
196
|
phoneNumber: z.string().optional(),
|
|
50
197
|
code: z.string()
|
|
51
198
|
});
|
|
52
|
-
export
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
});
|
|
199
|
+
export var handleVerifyOTPOnly = function(param) {
|
|
200
|
+
var phoneNumber = param.phoneNumber, code = param.code;
|
|
201
|
+
return _async_to_generator(function() {
|
|
202
|
+
var tokenResult;
|
|
203
|
+
return _ts_generator(this, function(_state) {
|
|
204
|
+
switch(_state.label){
|
|
205
|
+
case 0:
|
|
206
|
+
return [
|
|
207
|
+
4,
|
|
208
|
+
verifyToken(code, {
|
|
209
|
+
scope: 'verify-phone'
|
|
210
|
+
})
|
|
211
|
+
];
|
|
212
|
+
case 1:
|
|
213
|
+
tokenResult = _state.sent();
|
|
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
|
+
})();
|
|
130
234
|
};
|
|
131
|
-
export
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
235
|
+
export var handleVerifyOTP = function(b) {
|
|
236
|
+
return _async_to_generator(function() {
|
|
237
|
+
var _tokenResult_val_user, _VerifyOtpBody_parse, scope, email, preFormattedPhoneNumber, code, phoneNumber, tokenResult, previousUser, userUpdate, userGroups, user, token;
|
|
238
|
+
return _ts_generator(this, function(_state) {
|
|
239
|
+
switch(_state.label){
|
|
240
|
+
case 0:
|
|
241
|
+
_VerifyOtpBody_parse = VerifyOtpBody.parse(b), scope = _VerifyOtpBody_parse.scope, email = _VerifyOtpBody_parse.email, preFormattedPhoneNumber = _VerifyOtpBody_parse.phoneNumber, code = _VerifyOtpBody_parse.code;
|
|
242
|
+
phoneNumber = "+".concat(preFormattedPhoneNumber === null || preFormattedPhoneNumber === void 0 ? void 0 : preFormattedPhoneNumber.replace(/[^0-9]/g, ''));
|
|
243
|
+
return [
|
|
244
|
+
4,
|
|
245
|
+
verifyToken(code, {
|
|
246
|
+
scope: scope,
|
|
247
|
+
metadata: {
|
|
248
|
+
email: email,
|
|
249
|
+
phoneNumber: phoneNumber
|
|
250
|
+
}
|
|
251
|
+
}, {
|
|
252
|
+
includeUser: true
|
|
253
|
+
})
|
|
254
|
+
];
|
|
255
|
+
case 1:
|
|
256
|
+
tokenResult = _state.sent();
|
|
257
|
+
if (tokenResult.err) {
|
|
258
|
+
return [
|
|
259
|
+
2,
|
|
260
|
+
new Err(INVALID_TOKEN_PROBLEM)
|
|
261
|
+
];
|
|
143
262
|
}
|
|
144
|
-
|
|
145
|
-
|
|
263
|
+
if (!tokenResult.val.user) {
|
|
264
|
+
return [
|
|
265
|
+
2,
|
|
266
|
+
new Err(INVALID_TOKEN_PROBLEM)
|
|
267
|
+
];
|
|
268
|
+
}
|
|
269
|
+
previousUser = tokenResult.val.user;
|
|
270
|
+
userUpdate = scope === 'verify-email' ? {
|
|
271
|
+
emailVerified: true,
|
|
272
|
+
email: email
|
|
273
|
+
} : {
|
|
274
|
+
phoneNumberVerified: true,
|
|
275
|
+
phoneNumber: phoneNumber
|
|
276
|
+
};
|
|
277
|
+
userUpdate.temporary = false;
|
|
278
|
+
userUpdate.temporaryEmail = null;
|
|
279
|
+
userGroups = new Set((_tokenResult_val_user = tokenResult.val.user) === null || _tokenResult_val_user === void 0 ? void 0 : _tokenResult_val_user.groups);
|
|
280
|
+
userGroups.add(ROLES.MEMBER);
|
|
281
|
+
userUpdate.groups = _to_consumable_array(userGroups);
|
|
282
|
+
return [
|
|
283
|
+
4,
|
|
284
|
+
prisma.user.update({
|
|
285
|
+
where: {
|
|
286
|
+
id: tokenResult.val.user.id
|
|
287
|
+
},
|
|
288
|
+
data: userUpdate
|
|
289
|
+
})
|
|
290
|
+
];
|
|
291
|
+
case 2:
|
|
292
|
+
user = _state.sent();
|
|
293
|
+
// delete the previous token
|
|
294
|
+
return [
|
|
295
|
+
4,
|
|
296
|
+
clearToken(tokenResult.val.id)
|
|
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
|
+
];
|
|
146
337
|
}
|
|
147
338
|
});
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
339
|
+
})();
|
|
340
|
+
};
|
|
341
|
+
export var handleSendVerificationSMS = function(b) {
|
|
342
|
+
return _async_to_generator(function() {
|
|
343
|
+
var _SendVerificationSMSBody_parse, phoneNumber, checkDuplication, userId, formattedPhoneNumber, user, code, verificationResult;
|
|
344
|
+
return _ts_generator(this, function(_state) {
|
|
345
|
+
switch(_state.label){
|
|
346
|
+
case 0:
|
|
347
|
+
_SendVerificationSMSBody_parse = SendVerificationSMSBody.parse(b), phoneNumber = _SendVerificationSMSBody_parse.phoneNumber, checkDuplication = _SendVerificationSMSBody_parse.checkDuplication, userId = _SendVerificationSMSBody_parse.userId;
|
|
348
|
+
formattedPhoneNumber = "+".concat(phoneNumber.replace(/[^0-9]/g, ''));
|
|
349
|
+
if (!checkDuplication) return [
|
|
350
|
+
3,
|
|
351
|
+
2
|
|
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
|
+
];
|
|
414
|
+
}
|
|
415
|
+
return [
|
|
416
|
+
2,
|
|
417
|
+
new Ok({
|
|
418
|
+
success: true
|
|
419
|
+
})
|
|
420
|
+
];
|
|
421
|
+
}
|
|
160
422
|
});
|
|
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
|
-
});
|
|
423
|
+
})();
|
|
170
424
|
};
|