Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mailtrap extension #17157

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extensions/mailtrap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Mailtrap Changelog

## [Fix .map on undefined] - {PR_MERGE_DATE}

- Handle empty `result` coming from mailtrap on load/pagination of emails

## [View Details of Inbox & Email] - 2024-10-28

- Retitled command from "Copy Subject" to "List Inboxes"
Expand Down
3 changes: 2 additions & 1 deletion extensions/mailtrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"Developer Tools"
],
"contributors": [
"xmok"
"xmok",
"chrisclose-nib"
],
"license": "MIT",
"preferences": [
Expand Down
14 changes: 8 additions & 6 deletions extensions/mailtrap/src/services/mailtrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type Email = {
human_size: string;
};

const MAILTRAP_PAGE_SIZE = 30;
const { apiKey, accountId } = getPreferenceValues<Preferences>();
const headers = {
"Api-Token": apiKey,
Expand All @@ -71,14 +72,15 @@ export function getInboxes() {
export function getEmails(inboxId: number) {
return useFetch(
(options) =>
`https://mailtrap.io/api/accounts/${accountId}}/inboxes/${inboxId}/messages?` +
new URLSearchParams({ page: String(options.page + 1) }).toString(),
`https://mailtrap.io/api/accounts/${accountId}/inboxes/${inboxId}/messages?` +
new URLSearchParams({ last_id: options.lastItem?.id.toString() }).toString(),
{
headers,
mapResult(result: Email[]) {
mapResult(result?: Email[]) {
const data = result ?? [];
return {
data: result,
hasMore: result.length === 30,
data,
hasMore: data.length === MAILTRAP_PAGE_SIZE,
};
},
initialData: [],
Expand All @@ -87,7 +89,7 @@ export function getEmails(inboxId: number) {
}

export function markAsRead(inboxId: number, emailId: number) {
fetch(`https://mailtrap.io/api/accounts/${accountId}}/inboxes/${inboxId}}/messages/${emailId}`, {
fetch(`https://mailtrap.io/api/accounts/${accountId}/inboxes/${inboxId}/messages/${emailId}`, {
method: "PATCH",
headers,
body: JSON.stringify({
Expand Down
Loading