(accessToken, options = {})
| 111 | } |
| 112 | |
| 113 | async function fetchGraphMessages(accessToken, options = {}) { |
| 114 | const fetchImpl = getFetchImpl(options.fetchImpl); |
| 115 | const mailbox = normalizeMailboxLabel(options.mailbox); |
| 116 | const top = Math.max(1, Math.min(Number(options.top) || 5, 30)); |
| 117 | const url = `${GRAPH_API_BASE}/${normalizeMailboxId(mailbox)}/messages?$top=${encodeURIComponent(top)}&$select=id,internetMessageId,subject,from,bodyPreview,receivedDateTime&$orderby=receivedDateTime desc`; |
| 118 | const response = await fetchImpl(url, { |
| 119 | method: 'GET', |
| 120 | headers: { |
| 121 | Accept: 'application/json', |
| 122 | Authorization: `Bearer ${accessToken}`, |
| 123 | }, |
| 124 | signal: options.signal, |
| 125 | }); |
| 126 | |
| 127 | if (!response.ok) { |
| 128 | throw new Error(`graph: ${await getResponseErrorText(response)}`); |
| 129 | } |
| 130 | |
| 131 | const payload = await response.json(); |
| 132 | return Array.isArray(payload?.value) ? payload.value : []; |
| 133 | } |
| 134 | |
| 135 | async function fetchOutlookMessages(accessToken, options = {}) { |
| 136 | const fetchImpl = getFetchImpl(options.fetchImpl); |
no test coverage detected