(input)
| 1298 | } |
| 1299 | |
| 1300 | async function upsertHotmailAccount(input) { |
| 1301 | const state = await getState(); |
| 1302 | const accounts = normalizeHotmailAccounts(state.hotmailAccounts); |
| 1303 | const normalizedEmail = String(input?.email || '').trim().toLowerCase(); |
| 1304 | const existing = input?.id |
| 1305 | ? findHotmailAccount(accounts, input.id) |
| 1306 | : accounts.find((account) => account.email.toLowerCase() === normalizedEmail) || null; |
| 1307 | const credentialsChanged = !existing |
| 1308 | || (input?.clientId !== undefined && String(input.clientId).trim() !== existing.clientId) |
| 1309 | || (input?.refreshToken !== undefined && String(input.refreshToken).trim() !== existing.refreshToken) |
| 1310 | || (input?.email !== undefined && String(input.email).trim().toLowerCase() !== existing.email.toLowerCase()); |
| 1311 | const normalized = normalizeHotmailAccount({ |
| 1312 | ...(existing || {}), |
| 1313 | ...(credentialsChanged ? { |
| 1314 | status: 'pending', |
| 1315 | lastAuthAt: 0, |
| 1316 | lastError: '', |
| 1317 | } : {}), |
| 1318 | ...input, |
| 1319 | id: input?.id || existing?.id || crypto.randomUUID(), |
| 1320 | }); |
| 1321 | |
| 1322 | const nextAccounts = existing |
| 1323 | ? accounts.map((account) => (account.id === normalized.id ? normalized : account)) |
| 1324 | : [...accounts, normalized]; |
| 1325 | |
| 1326 | await syncHotmailAccounts(nextAccounts); |
| 1327 | return normalized; |
| 1328 | } |
| 1329 | |
| 1330 | async function deleteHotmailAccount(accountId) { |
| 1331 | const state = await getState(); |
no test coverage detected