(options = {})
| 350 | } |
| 351 | |
| 352 | async function fetchMicrosoftVerificationCode(options = {}) { |
| 353 | const { |
| 354 | token, |
| 355 | refreshToken, |
| 356 | clientId, |
| 357 | maxRetries = 3, |
| 358 | retryDelayMs = 10000, |
| 359 | top = 5, |
| 360 | log = null, |
| 361 | filterAfterTimestamp = 0, |
| 362 | senderFilters = [], |
| 363 | subjectFilters = [], |
| 364 | excludeCodes = [], |
| 365 | mailboxes = ['INBOX'], |
| 366 | fetchImpl, |
| 367 | signal, |
| 368 | } = options; |
| 369 | |
| 370 | let workingRefreshToken = String(refreshToken || token || '').trim(); |
| 371 | if (!workingRefreshToken) { |
| 372 | throw new Error('Microsoft refresh token is empty.'); |
| 373 | } |
| 374 | if (!clientId) { |
| 375 | throw new Error('Microsoft client_id is empty.'); |
| 376 | } |
| 377 | |
| 378 | const normalizedMailboxes = normalizeMailboxList(mailboxes); |
| 379 | let lastError = null; |
| 380 | |
| 381 | for (let attempt = 1; attempt <= maxRetries; attempt += 1) { |
| 382 | try { |
| 383 | const collectedMessages = []; |
| 384 | for (const mailbox of normalizedMailboxes) { |
| 385 | const result = await fetchMicrosoftMailboxMessages({ |
| 386 | clientId, |
| 387 | refreshToken: workingRefreshToken, |
| 388 | mailbox, |
| 389 | top, |
| 390 | fetchImpl, |
| 391 | signal, |
| 392 | log, |
| 393 | }); |
| 394 | if (result.nextRefreshToken) { |
| 395 | workingRefreshToken = result.nextRefreshToken; |
| 396 | } |
| 397 | collectedMessages.push(...result.messages); |
| 398 | } |
| 399 | |
| 400 | const match = extractVerificationCodeFromMessages(collectedMessages, { |
| 401 | filterAfterTimestamp, |
| 402 | senderFilters, |
| 403 | subjectFilters, |
| 404 | excludeCodes, |
| 405 | }); |
| 406 | if (match) { |
| 407 | return { |
| 408 | ...match, |
| 409 | nextRefreshToken: workingRefreshToken, |
no test coverage detected