@driveflux/api-functions 0.0.4 → 0.0.5

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 (56) hide show
  1. package/dist/auth/confirm.js +327 -73
  2. package/dist/auth/emails.js +210 -43
  3. package/dist/auth/formatter.js +11 -11
  4. package/dist/auth/otp.js +392 -122
  5. package/dist/auth/register.js +396 -100
  6. package/dist/auth/tokens.js +430 -115
  7. package/dist/auth/verifications.js +512 -154
  8. package/dist/constants.js +4 -5
  9. package/dist/mailjet/calls/manage-contacts-in-list.js +166 -22
  10. package/dist/mailjet/calls/manage-subscription-status.js +153 -13
  11. package/dist/mailjet/calls/request-service.js +183 -18
  12. package/dist/mailjet/refresh-email-preferences.d.ts +10 -10
  13. package/dist/mailjet/refresh-email-preferences.d.ts.map +1 -1
  14. package/dist/mailjet/refresh-email-preferences.js +226 -27
  15. package/dist/mailjet/refresh-email-preferences.js.map +1 -1
  16. package/dist/mailjet/set-contact.d.ts +10 -10
  17. package/dist/mailjet/set-contact.d.ts.map +1 -1
  18. package/dist/mailjet/set-contact.js +215 -24
  19. package/dist/mailjet/set-contact.js.map +1 -1
  20. package/dist/mailjet/types.js +1 -2
  21. package/dist/mailjet/utils/convert-to-array.js +58 -9
  22. package/dist/mailjet/utils/extract-email-preferences.d.ts +8 -8
  23. package/dist/mailjet/utils/extract-email-preferences.d.ts.map +1 -1
  24. package/dist/mailjet/utils/extract-email-preferences.js +218 -42
  25. package/dist/mailjet/utils/extract-email-preferences.js.map +1 -1
  26. package/dist/mailjet/utils/lists.js +249 -30
  27. package/dist/mailjet/utils/update-email-references.js +208 -27
  28. package/dist/notion/client.js +197 -48
  29. package/dist/notion/helpful.js +170 -29
  30. package/dist/notion/schemas/block.js +43 -49
  31. package/dist/notion/schemas/common.js +14 -17
  32. package/dist/notion/schemas/database.js +159 -125
  33. package/dist/notion/schemas/emoji.js +2 -3
  34. package/dist/notion/schemas/file.js +10 -10
  35. package/dist/notion/schemas/kb.js +8 -9
  36. package/dist/notion/schemas/page.js +171 -126
  37. package/dist/notion/schemas/parent.js +8 -9
  38. package/dist/notion/schemas/user.js +20 -21
  39. package/dist/reservation/agree.js +158 -19
  40. package/dist/reservation/checks.js +178 -23
  41. package/dist/reservation/display-vehicle.js +514 -142
  42. package/dist/reservation/fetch-or-create.js +482 -197
  43. package/dist/reservation/invoice.js +496 -198
  44. package/dist/reservation/payer.js +177 -28
  45. package/dist/reservation/reserve.js +191 -31
  46. package/dist/reservation/types.js +1 -2
  47. package/dist/reservation/vehicle.js +186 -24
  48. package/dist/slack.js +273 -67
  49. package/dist/validation.d.ts +19 -13
  50. package/dist/validation.d.ts.map +1 -1
  51. package/dist/validation.js +144 -63
  52. package/dist/validation.js.map +1 -1
  53. package/dist/vehicle/vehicle-pricing/constants.js +36 -33
  54. package/dist/vehicle/vehicle-pricing/index.js +257 -99
  55. package/dist/vehicle/vehicle-pricing/types.js +1 -2
  56. package/package.json +9 -9
@@ -1,4 +1,4 @@
1
- const knownCountryCodes = [
1
+ var knownCountryCodes = [
2
2
  '1',
3
3
  '376',
4
4
  '93',
@@ -221,19 +221,20 @@ const knownCountryCodes = [
221
221
  '246',
222
222
  '269',
223
223
  '692',
224
- '383',
224
+ '383'
225
225
  ];
226
- export const cleanupPhoneNumber = (phoneNumber) => {
226
+ export var cleanupPhoneNumber = function(phoneNumber) {
227
227
  // Remove all characters except numbers and +
228
- const cleaned = phoneNumber.replace(/[^\d+]/g, '');
228
+ var cleaned = phoneNumber.replace(/[^\d+]/g, '');
229
229
  // If it doesn't start with +, add it
230
- const withPlus = cleaned.startsWith('+') ? cleaned : `+${cleaned}`;
230
+ var withPlus = cleaned.startsWith('+') ? cleaned : "+".concat(cleaned);
231
231
  // Find the country code by checking against known codes
232
- let countryCode = '';
233
- let remainingNumber = '';
232
+ var countryCode = '';
233
+ var 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
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
  if (knownCountryCodes.includes(potentialCode)) {
238
239
  countryCode = potentialCode;
239
240
  remainingNumber = withPlus.substring(1 + i); // Everything after the country code
@@ -242,8 +243,7 @@ export const cleanupPhoneNumber = (phoneNumber) => {
242
243
  }
243
244
  // If we found a country code and the remaining number starts with 0, remove it
244
245
  if (countryCode && remainingNumber.startsWith('0')) {
245
- return `+${countryCode}${remainingNumber.substring(1)}`;
246
+ return "+".concat(countryCode).concat(remainingNumber.substring(1));
246
247
  }
247
248
  return withPlus;
248
249
  };
249
- //# sourceMappingURL=formatter.js.map
package/dist/auth/otp.js CHANGED
@@ -1,154 +1,424 @@
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';
4
149
  import { generateId } from '@driveflux/db/id';
5
- import { makeProblem, PROBLEM_CONFLICT, PROBLEM_INVALID_DATA, } from '@driveflux/problem';
150
+ import { makeProblem, PROBLEM_CONFLICT, PROBLEM_INVALID_DATA } from '@driveflux/problem';
6
151
  import { Err, Ok } from '@driveflux/result';
7
152
  import { addDays } from 'date-fns/addDays';
8
153
  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
- const SendVerificationSMSBody = z.object({
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
- userId: z.string().optional().nullable(),
161
+ userId: z.string().optional().nullable()
17
162
  });
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()),
163
+ var VerifyOtpBody = z.object({
164
+ scope: z.enum([
165
+ 'verify-email',
166
+ 'verify-phone'
167
+ ]),
168
+ email: z.email().optional().transform(function(email) {
169
+ return email === null || email === void 0 ? void 0 : email.toLowerCase().trim();
170
+ }),
25
171
  phoneNumber: z.string().optional(),
26
- code: z.string(),
27
- })
28
- .refine((d) => {
172
+ code: z.string()
173
+ }).refine(function(d) {
29
174
  if (d.scope === 'verify-email' && !d.email) {
30
175
  return false;
31
176
  }
32
177
  return true;
33
178
  }, {
34
- path: ['email'],
35
- message: 'Email is required',
36
- })
37
- .refine((d) => {
179
+ path: [
180
+ 'email'
181
+ ],
182
+ message: 'Email is required'
183
+ }).refine(function(d) {
38
184
  if (d.scope === 'verify-phone' && !d.phoneNumber) {
39
185
  return false;
40
186
  }
41
187
  return true;
42
188
  }, {
43
- path: ['phoneNumber'],
44
- message: 'Phone number is required',
189
+ path: [
190
+ 'phoneNumber'
191
+ ],
192
+ message: 'Phone number is required'
45
193
  });
46
- const INVALID_TOKEN_PROBLEM = makeProblem(PROBLEM_INVALID_DATA, 'Unable to verify token. It could have been expired.');
47
- const VerifyOtpOnlyBody = z.object({
194
+ var INVALID_TOKEN_PROBLEM = makeProblem(PROBLEM_INVALID_DATA, 'Unable to verify token. It could have been expired.');
195
+ var VerifyOtpOnlyBody = z.object({
48
196
  phoneNumber: z.string().optional(),
49
- code: z.string(),
197
+ code: z.string()
50
198
  });
51
- export const handleVerifyOTPOnly = async ({ phoneNumber, code, }) => {
52
- const tokenResult = await verifyToken(code, { scope: 'verify-phone' });
53
- if (tokenResult.err) {
54
- console.log('Error verifying token', tokenResult.val);
55
- return new Err(INVALID_TOKEN_PROBLEM);
56
- }
57
- // delete the previous token
58
- // TODO maybe: verify this token when registering one more time then clear it
59
- // await clearToken(tokenResult.val.id)
60
- return new Ok({
61
- phoneNumber,
62
- phoneNumberVerified: true,
63
- });
64
- };
65
- export const handleVerifyOTP = async (b) => {
66
- const { scope, email, phoneNumber: preFormattedPhoneNumber, code, } = VerifyOtpBody.parse(b);
67
- const phoneNumber = `+${preFormattedPhoneNumber?.replace(/[^0-9]/g, '')}`;
68
- const tokenResult = await verifyToken(code, { scope, metadata: { email, phoneNumber } }, { includeUser: true });
69
- if (tokenResult.err) {
70
- return new Err(INVALID_TOKEN_PROBLEM);
71
- }
72
- if (!tokenResult.val.user) {
73
- return new Err(INVALID_TOKEN_PROBLEM);
74
- }
75
- const previousUser = tokenResult.val.user;
76
- const userUpdate = scope === 'verify-email'
77
- ? {
78
- emailVerified: true,
79
- email,
80
- }
81
- : {
82
- phoneNumberVerified: true,
83
- phoneNumber,
84
- };
85
- userUpdate.temporary = false;
86
- userUpdate.temporaryEmail = null;
87
- const userGroups = new Set(tokenResult.val.user?.groups);
88
- userGroups.add(ROLES.MEMBER);
89
- userUpdate.groups = [...userGroups];
90
- const user = await prisma.user.update({
91
- where: {
92
- id: tokenResult.val.user.id,
93
- },
94
- data: userUpdate,
95
- });
96
- // delete the previous token
97
- await clearToken(tokenResult.val.id);
98
- // Login the user
99
- const token = await prisma.token.create({
100
- data: {
101
- id: generateId('Token'),
102
- user: {
103
- connect: {
104
- id: user?.id,
105
- },
106
- },
107
- expiresAt: addDays(new Date(), 365),
108
- scope: 'all',
109
- },
110
- });
111
- if (previousUser.email !== user.email) {
112
- await sendEmailChangedEmail(user.id);
113
- }
114
- return new Ok({
115
- accessToken: token.id,
116
- expiresAt: token.expiresAt,
117
- user: user,
118
- });
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
+ })();
119
234
  };
120
- export const handleSendVerificationSMS = async (b) => {
121
- const { phoneNumber, checkDuplication, userId } = SendVerificationSMSBody.parse(b);
122
- const formattedPhoneNumber = `+${phoneNumber.replace(/[^0-9]/g, '')}`;
123
- if (checkDuplication) {
124
- const user = await prisma.user.findFirst({
125
- where: {
126
- OR: [
127
- { phoneNumber: formattedPhoneNumber },
128
- { phoneNumber: phoneNumber },
129
- ],
130
- phoneNumberVerified: true,
131
- },
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
+ ];
262
+ }
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
+ ];
337
+ }
132
338
  });
133
- if (user) {
134
- return new Err(makeProblem(PROBLEM_CONFLICT, 'This phone number is already registered'));
135
- }
136
- }
137
- if (!config.isProd && !config.sendSMSOutsideOfProd) {
138
- const code = await createSMSToken(userId || null, formattedPhoneNumber);
139
- if (!code?.value) {
140
- return new Err(makeProblem(PROBLEM_INVALID_DATA, 'Invalid Data'));
141
- }
142
- return new Ok({
143
- success: true,
144
- code: code.value,
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
+ }
145
422
  });
146
- }
147
- // Send the sms verification
148
- const verificationResult = await sendVerificationSMS(userId || null, phoneNumber);
149
- if (verificationResult.err) {
150
- return verificationResult;
151
- }
152
- return new Ok({ success: true });
423
+ })();
153
424
  };
154
- //# sourceMappingURL=otp.js.map