@sudobility/wildduck_client 1.4.0 → 1.4.1
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.
- package/dist/hooks/addresses/useWildduckGetAddresses.js +2 -2
- package/dist/hooks/addresses/useWildduckGetAddresses.js.map +1 -1
- package/dist/hooks/messages/useWildduckDeleteMessage.js +2 -2
- package/dist/hooks/messages/useWildduckDeleteMessage.js.map +1 -1
- package/dist/hooks/messages/useWildduckForwardMessage.js +2 -2
- package/dist/hooks/messages/useWildduckForwardMessage.js.map +1 -1
- package/dist/hooks/messages/useWildduckGetMessage.js +2 -2
- package/dist/hooks/messages/useWildduckGetMessage.js.map +1 -1
- package/dist/hooks/messages/useWildduckGetMessageAttachment.js +2 -2
- package/dist/hooks/messages/useWildduckGetMessageAttachment.js.map +1 -1
- package/dist/hooks/messages/useWildduckGetMessageSource.js +2 -2
- package/dist/hooks/messages/useWildduckGetMessageSource.js.map +1 -1
- package/dist/hooks/messages/useWildduckGetMessages.js +2 -2
- package/dist/hooks/messages/useWildduckGetMessages.js.map +1 -1
- package/dist/hooks/messages/useWildduckSearchMessages.d.ts +0 -1
- package/dist/hooks/messages/useWildduckSearchMessages.d.ts.map +1 -1
- package/dist/hooks/messages/useWildduckSearchMessages.js +9 -25
- package/dist/hooks/messages/useWildduckSearchMessages.js.map +1 -1
- package/dist/hooks/messages/useWildduckSendMessage.js +2 -2
- package/dist/hooks/messages/useWildduckSendMessage.js.map +1 -1
- package/dist/hooks/messages/useWildduckSubmitDraft.js +2 -2
- package/dist/hooks/messages/useWildduckSubmitDraft.js.map +1 -1
- package/dist/hooks/messages/useWildduckUpdateMessage.js +2 -2
- package/dist/hooks/messages/useWildduckUpdateMessage.js.map +1 -1
- package/dist/hooks/messages/useWildduckUploadMessage.js +2 -2
- package/dist/hooks/messages/useWildduckUploadMessage.js.map +1 -1
- package/dist/hooks/useWildduckAddresses.d.ts.map +1 -1
- package/dist/hooks/useWildduckAddresses.js +46 -66
- package/dist/hooks/useWildduckAddresses.js.map +1 -1
- package/dist/hooks/useWildduckAuth.d.ts.map +1 -1
- package/dist/hooks/useWildduckAuth.js +22 -67
- package/dist/hooks/useWildduckAuth.js.map +1 -1
- package/dist/hooks/useWildduckAutoReply.d.ts.map +1 -1
- package/dist/hooks/useWildduckAutoReply.js +23 -30
- package/dist/hooks/useWildduckAutoReply.js.map +1 -1
- package/dist/hooks/useWildduckFilters.d.ts.map +1 -1
- package/dist/hooks/useWildduckFilters.js +27 -66
- package/dist/hooks/useWildduckFilters.js.map +1 -1
- package/dist/hooks/useWildduckMailboxes.d.ts.map +1 -1
- package/dist/hooks/useWildduckMailboxes.js +54 -73
- package/dist/hooks/useWildduckMailboxes.js.map +1 -1
- package/dist/hooks/useWildduckMessages.d.ts +8 -8
- package/dist/hooks/useWildduckMessages.d.ts.map +1 -1
- package/dist/hooks/useWildduckMessages.js +83 -83
- package/dist/hooks/useWildduckMessages.js.map +1 -1
- package/dist/hooks/useWildduckQueries.d.ts +2 -2
- package/dist/hooks/useWildduckQueries.d.ts.map +1 -1
- package/dist/hooks/useWildduckQueries.js +32 -130
- package/dist/hooks/useWildduckQueries.js.map +1 -1
- package/dist/hooks/useWildduckSettings.d.ts.map +1 -1
- package/dist/hooks/useWildduckSettings.js +12 -32
- package/dist/hooks/useWildduckSettings.js.map +1 -1
- package/dist/hooks/useWildduckUsers.d.ts.map +1 -1
- package/dist/hooks/useWildduckUsers.js +15 -37
- package/dist/hooks/useWildduckUsers.js.map +1 -1
- package/dist/hooks/users/useWildduckCreateUser.js +2 -2
- package/dist/hooks/users/useWildduckCreateUser.js.map +1 -1
- package/dist/hooks/users/useWildduckDeleteUser.js +2 -2
- package/dist/hooks/users/useWildduckDeleteUser.js.map +1 -1
- package/dist/hooks/users/useWildduckGetUser.js +2 -2
- package/dist/hooks/users/useWildduckGetUser.js.map +1 -1
- package/dist/hooks/users/useWildduckUpdateUser.js +2 -2
- package/dist/hooks/users/useWildduckUpdateUser.js.map +1 -1
- package/dist/hooks/users/useWildduckUser2FA.d.ts +2 -2
- package/dist/hooks/users/useWildduckUser2FA.d.ts.map +1 -1
- package/dist/hooks/users/useWildduckUser2FA.js.map +1 -1
- package/dist/hooks/users/useWildduckUserEncryption.d.ts +2 -2
- package/dist/hooks/users/useWildduckUserEncryption.d.ts.map +1 -1
- package/dist/hooks/users/useWildduckUserEncryption.js.map +1 -1
- package/dist/hooks/users/useWildduckUserForwarding.d.ts +2 -2
- package/dist/hooks/users/useWildduckUserForwarding.d.ts.map +1 -1
- package/dist/hooks/users/useWildduckUserForwarding.js.map +1 -1
- package/dist/hooks/users/useWildduckUserLimits.d.ts +2 -2
- package/dist/hooks/users/useWildduckUserLimits.d.ts.map +1 -1
- package/dist/hooks/users/useWildduckUserLimits.js.map +1 -1
- package/dist/hooks/users/useWildduckUserProfile.d.ts +2 -2
- package/dist/hooks/users/useWildduckUserProfile.d.ts.map +1 -1
- package/dist/hooks/users/useWildduckUserProfile.js.map +1 -1
- package/dist/hooks/users/useWildduckUserQuota.d.ts +2 -2
- package/dist/hooks/users/useWildduckUserQuota.d.ts.map +1 -1
- package/dist/hooks/users/useWildduckUserQuota.js.map +1 -1
- package/dist/hooks/users/useWildduckUserSpam.d.ts +2 -2
- package/dist/hooks/users/useWildduckUserSpam.d.ts.map +1 -1
- package/dist/hooks/users/useWildduckUserSpam.js.map +1 -1
- package/dist/network/wildduck-client.d.ts +60 -11
- package/dist/network/wildduck-client.d.ts.map +1 -1
- package/dist/network/wildduck-client.js +155 -65
- package/dist/network/wildduck-client.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,35 +1,26 @@
|
|
|
1
1
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
3
|
+
import { WildduckClient } from "../network/wildduck-client";
|
|
3
4
|
const useWildduckMailboxes = (networkClient, config, wildduckUserAuth, _devMode = false) => {
|
|
4
5
|
const queryClient = useQueryClient();
|
|
5
6
|
const hasFetchedRef = useRef(false);
|
|
7
|
+
const api = useMemo(() => new WildduckClient(networkClient, config), [networkClient, config]);
|
|
6
8
|
const userId = wildduckUserAuth?.userId || null;
|
|
7
|
-
const buildHeaders = useCallback(() => {
|
|
8
|
-
return {
|
|
9
|
-
"Content-Type": "application/json",
|
|
10
|
-
Accept: "application/json",
|
|
11
|
-
};
|
|
12
|
-
}, []);
|
|
13
9
|
const getMailboxes = useCallback(async (userId, options = {}) => {
|
|
14
10
|
try {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const response = await networkClient.request(`${apiUrl}${endpoint}`, {
|
|
29
|
-
method: "GET",
|
|
30
|
-
headers,
|
|
31
|
-
});
|
|
32
|
-
const mailboxData = response.data;
|
|
11
|
+
if (!wildduckUserAuth) {
|
|
12
|
+
throw new Error("User not authenticated");
|
|
13
|
+
}
|
|
14
|
+
const getMailboxesOptions = {};
|
|
15
|
+
if (options.specialUse !== undefined)
|
|
16
|
+
getMailboxesOptions.specialUse = options.specialUse;
|
|
17
|
+
if (options.showHidden !== undefined)
|
|
18
|
+
getMailboxesOptions.showHidden = options.showHidden;
|
|
19
|
+
if (options.counters !== undefined)
|
|
20
|
+
getMailboxesOptions.counters = options.counters;
|
|
21
|
+
if (options.sizes !== undefined)
|
|
22
|
+
getMailboxesOptions.sizes = options.sizes;
|
|
23
|
+
const mailboxData = await api.getMailboxes(wildduckUserAuth, getMailboxesOptions);
|
|
33
24
|
const mailboxList = mailboxData.results || [];
|
|
34
25
|
queryClient.setQueryData(["wildduck-mailboxes", userId], mailboxList);
|
|
35
26
|
return mailboxList;
|
|
@@ -39,17 +30,13 @@ const useWildduckMailboxes = (networkClient, config, wildduckUserAuth, _devMode
|
|
|
39
30
|
console.error("[useWildduckMailboxes] Failed to get mailboxes:", errorMessage);
|
|
40
31
|
throw new Error(errorMessage);
|
|
41
32
|
}
|
|
42
|
-
}, [
|
|
33
|
+
}, [api, wildduckUserAuth, queryClient]);
|
|
43
34
|
const getMailbox = useCallback(async (userId, mailboxId) => {
|
|
44
35
|
try {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
method: "GET",
|
|
50
|
-
headers,
|
|
51
|
-
});
|
|
52
|
-
const mailboxData = response.data;
|
|
36
|
+
if (!wildduckUserAuth) {
|
|
37
|
+
throw new Error("User not authenticated");
|
|
38
|
+
}
|
|
39
|
+
const mailboxData = await api.getMailbox(wildduckUserAuth, mailboxId);
|
|
53
40
|
if (!mailboxData.results || mailboxData.results.length === 0) {
|
|
54
41
|
throw new Error("Mailbox not found");
|
|
55
42
|
}
|
|
@@ -65,7 +52,7 @@ const useWildduckMailboxes = (networkClient, config, wildduckUserAuth, _devMode
|
|
|
65
52
|
console.error("[useWildduckMailboxes] Failed to get mailbox:", errorMessage);
|
|
66
53
|
throw new Error(errorMessage);
|
|
67
54
|
}
|
|
68
|
-
}, [
|
|
55
|
+
}, [api, wildduckUserAuth, queryClient]);
|
|
69
56
|
const cachedMailboxes = userId
|
|
70
57
|
? queryClient.getQueryData([
|
|
71
58
|
"wildduck-mailboxes",
|
|
@@ -97,20 +84,13 @@ const useWildduckMailboxes = (networkClient, config, wildduckUserAuth, _devMode
|
|
|
97
84
|
"wildduck-create-mailbox",
|
|
98
85
|
config.cloudflareWorkerUrl || config.backendUrl,
|
|
99
86
|
],
|
|
100
|
-
mutationFn: async ({
|
|
87
|
+
mutationFn: async ({ params, }) => {
|
|
101
88
|
try {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
body: JSON.stringify({
|
|
108
|
-
path: params.path,
|
|
109
|
-
hidden: params.hidden,
|
|
110
|
-
retention: params.retention,
|
|
111
|
-
}),
|
|
112
|
-
});
|
|
113
|
-
return response.data;
|
|
89
|
+
if (!wildduckUserAuth) {
|
|
90
|
+
throw new Error("User not authenticated");
|
|
91
|
+
}
|
|
92
|
+
await api.createMailbox(wildduckUserAuth, params);
|
|
93
|
+
return { success: true, id: "" };
|
|
114
94
|
}
|
|
115
95
|
catch (err) {
|
|
116
96
|
const errorMessage = err instanceof Error ? err.message : "Failed to create mailbox";
|
|
@@ -118,8 +98,10 @@ const useWildduckMailboxes = (networkClient, config, wildduckUserAuth, _devMode
|
|
|
118
98
|
throw new Error(errorMessage);
|
|
119
99
|
}
|
|
120
100
|
},
|
|
121
|
-
onSuccess: async (
|
|
122
|
-
|
|
101
|
+
onSuccess: async () => {
|
|
102
|
+
if (userId) {
|
|
103
|
+
await getMailboxes(userId, { counters: true });
|
|
104
|
+
}
|
|
123
105
|
},
|
|
124
106
|
});
|
|
125
107
|
const updateMutation = useMutation({
|
|
@@ -127,16 +109,13 @@ const useWildduckMailboxes = (networkClient, config, wildduckUserAuth, _devMode
|
|
|
127
109
|
"wildduck-update-mailbox",
|
|
128
110
|
config.cloudflareWorkerUrl || config.backendUrl,
|
|
129
111
|
],
|
|
130
|
-
mutationFn: async ({
|
|
112
|
+
mutationFn: async ({ mailboxId, params, }) => {
|
|
131
113
|
try {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
body: JSON.stringify(params),
|
|
138
|
-
});
|
|
139
|
-
return response.data;
|
|
114
|
+
if (!wildduckUserAuth) {
|
|
115
|
+
throw new Error("User not authenticated");
|
|
116
|
+
}
|
|
117
|
+
const response = await api.updateMailbox(wildduckUserAuth, mailboxId, params);
|
|
118
|
+
return { success: response.success };
|
|
140
119
|
}
|
|
141
120
|
catch (err) {
|
|
142
121
|
const errorMessage = err instanceof Error ? err.message : "Failed to update mailbox";
|
|
@@ -144,8 +123,10 @@ const useWildduckMailboxes = (networkClient, config, wildduckUserAuth, _devMode
|
|
|
144
123
|
throw new Error(errorMessage);
|
|
145
124
|
}
|
|
146
125
|
},
|
|
147
|
-
onSuccess: async (
|
|
148
|
-
|
|
126
|
+
onSuccess: async () => {
|
|
127
|
+
if (userId) {
|
|
128
|
+
await getMailboxes(userId, { counters: true });
|
|
129
|
+
}
|
|
149
130
|
},
|
|
150
131
|
});
|
|
151
132
|
const deleteMutation = useMutation({
|
|
@@ -153,15 +134,13 @@ const useWildduckMailboxes = (networkClient, config, wildduckUserAuth, _devMode
|
|
|
153
134
|
"wildduck-delete-mailbox",
|
|
154
135
|
config.cloudflareWorkerUrl || config.backendUrl,
|
|
155
136
|
],
|
|
156
|
-
mutationFn: async ({
|
|
137
|
+
mutationFn: async ({ mailboxId, }) => {
|
|
157
138
|
try {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
});
|
|
164
|
-
return response.data;
|
|
139
|
+
if (!wildduckUserAuth) {
|
|
140
|
+
throw new Error("User not authenticated");
|
|
141
|
+
}
|
|
142
|
+
const response = await api.deleteMailbox(wildduckUserAuth, mailboxId);
|
|
143
|
+
return { success: response.success };
|
|
165
144
|
}
|
|
166
145
|
catch (err) {
|
|
167
146
|
const errorMessage = err instanceof Error ? err.message : "Failed to delete mailbox";
|
|
@@ -169,8 +148,10 @@ const useWildduckMailboxes = (networkClient, config, wildduckUserAuth, _devMode
|
|
|
169
148
|
throw new Error(errorMessage);
|
|
170
149
|
}
|
|
171
150
|
},
|
|
172
|
-
onSuccess: async (
|
|
173
|
-
|
|
151
|
+
onSuccess: async () => {
|
|
152
|
+
if (userId) {
|
|
153
|
+
await getMailboxes(userId, { counters: true });
|
|
154
|
+
}
|
|
174
155
|
},
|
|
175
156
|
});
|
|
176
157
|
const refresh = useCallback(async () => {
|
|
@@ -186,9 +167,9 @@ const useWildduckMailboxes = (networkClient, config, wildduckUserAuth, _devMode
|
|
|
186
167
|
updateMutation.error?.message ||
|
|
187
168
|
deleteMutation.error?.message ||
|
|
188
169
|
null;
|
|
189
|
-
const createMailbox = useCallback(async (
|
|
190
|
-
const updateMailbox = useCallback(async (
|
|
191
|
-
const deleteMailbox = useCallback(async (
|
|
170
|
+
const createMailbox = useCallback(async (_userId, params) => createMutation.mutateAsync({ params }), [createMutation]);
|
|
171
|
+
const updateMailbox = useCallback(async (_userId, mailboxId, params) => updateMutation.mutateAsync({ mailboxId, params }), [updateMutation]);
|
|
172
|
+
const deleteMailbox = useCallback(async (_userId, mailboxId) => deleteMutation.mutateAsync({ mailboxId }), [deleteMutation]);
|
|
192
173
|
const clearError = useCallback(() => {
|
|
193
174
|
createMutation.reset();
|
|
194
175
|
updateMutation.reset();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWildduckMailboxes.js","sourceRoot":"","sources":["../../src/hooks/useWildduckMailboxes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useWildduckMailboxes.js","sourceRoot":"","sources":["../../src/hooks/useWildduckMailboxes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAUhE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAqD5D,MAAM,oBAAoB,GAAG,CAC3B,aAA4B,EAC5B,MAAsB,EACtB,gBAA4C,EAC5C,WAAoB,KAAK,EACG,EAAE;IAC9B,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAGpC,MAAM,GAAG,GAAG,OAAO,CACjB,GAAG,EAAE,CAAC,IAAI,cAAc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AAC,cAAc,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC;IAErD,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QAEL,SAAS,EAAE,eAAe;QAC1B,SAAS;QACT,KAAK;QAGL,YAAY;QACZ,UAAU;QACV,OAAO;QAGP,aAAa;QACb,UAAU,EAAE,cAAc,CAAC,SAAS;QACpC,WAAW,EAAE,cAAc,CAAC,KAAK;QAGjC,aAAa;QACb,UAAU,EAAE,cAAc,CAAC,SAAS;QACpC,WAAW,EAAE,cAAc,CAAC,KAAK;QAGjC,aAAa;QACb,UAAU,EAAE,cAAc,CAAC,SAAS;QACpC,WAAW,EAAE,cAAc,CAAC,KAAK;QAGjC,UAAU;KACX,CAAC,EACF;QACE,eAAe;QACf,SAAS;QACT,KAAK;QACL,YAAY;QACZ,UAAU;QACV,OAAO;QACP,aAAa;QACb,cAAc,CAAC,SAAS;QACxB,cAAc,CAAC,KAAK;QACpB,aAAa;QACb,cAAc,CAAC,SAAS;QACxB,cAAc,CAAC,KAAK;QACpB,aAAa;QACb,cAAc,CAAC,SAAS;QACxB,cAAc,CAAC,KAAK;QACpB,UAAU;KACX,CACF,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAmC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NetworkClient, Optional, WildduckConfig, WildduckMessage, WildduckMessageResponse, WildduckUpdateMessageRequest } from "@sudobility/types";
|
|
1
|
+
import type { NetworkClient, Optional, WildduckConfig, WildduckMessage, WildduckMessageResponse, WildduckUpdateMessageRequest, WildduckUserAuth } from "@sudobility/types";
|
|
2
2
|
interface GetMessagesOptions {
|
|
3
3
|
limit?: number;
|
|
4
4
|
page?: number;
|
|
@@ -37,27 +37,27 @@ interface UseWildduckMessagesReturn {
|
|
|
37
37
|
currentPage: number;
|
|
38
38
|
isLoading: boolean;
|
|
39
39
|
error: Optional<string>;
|
|
40
|
-
getMessages: (
|
|
41
|
-
getMessage: (
|
|
42
|
-
searchMessages: (
|
|
40
|
+
getMessages: (wildduckUserAuth: WildduckUserAuth, mailboxId: string, options?: GetMessagesOptions) => Promise<WildduckMessage[]>;
|
|
41
|
+
getMessage: (wildduckUserAuth: WildduckUserAuth, mailboxId: string, messageId: string) => Promise<WildduckMessageResponse>;
|
|
42
|
+
searchMessages: (wildduckUserAuth: WildduckUserAuth, query: string, options?: GetMessagesOptions) => Promise<WildduckMessage[]>;
|
|
43
43
|
refresh: () => Promise<void>;
|
|
44
|
-
sendMessage: (
|
|
44
|
+
sendMessage: (wildduckUserAuth: WildduckUserAuth, params: SendMessageParams) => Promise<{
|
|
45
45
|
success: boolean;
|
|
46
46
|
id: string;
|
|
47
47
|
}>;
|
|
48
48
|
isSending: boolean;
|
|
49
49
|
sendError: Optional<Error>;
|
|
50
|
-
updateMessage: (
|
|
50
|
+
updateMessage: (wildduckUserAuth: WildduckUserAuth, mailboxId: string, messageId: string, params: WildduckUpdateMessageRequest) => Promise<{
|
|
51
51
|
success: boolean;
|
|
52
52
|
}>;
|
|
53
53
|
isUpdating: boolean;
|
|
54
54
|
updateError: Optional<Error>;
|
|
55
|
-
deleteMessage: (
|
|
55
|
+
deleteMessage: (wildduckUserAuth: WildduckUserAuth, mailboxId: string, messageId: string) => Promise<{
|
|
56
56
|
success: boolean;
|
|
57
57
|
}>;
|
|
58
58
|
isDeleting: boolean;
|
|
59
59
|
deleteError: Optional<Error>;
|
|
60
|
-
moveMessage: (
|
|
60
|
+
moveMessage: (wildduckUserAuth: WildduckUserAuth, mailboxId: string, messageId: string, targetMailbox: string) => Promise<{
|
|
61
61
|
success: boolean;
|
|
62
62
|
}>;
|
|
63
63
|
isMoving: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWildduckMessages.d.ts","sourceRoot":"","sources":["../../src/hooks/useWildduckMessages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,QAAQ,EACR,cAAc,EACd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ClC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,KACd,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACnC,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IAG7B,WAAW,EAAE,CACX,gBAAgB,EAAE,gBAAgB,EAClC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,KAClB,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IAG3B,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAUD,QAAA,MAAM,mBAAmB,GACvB,eAAe,aAAa,EAC5B,QAAQ,cAAc,EACtB,WAAU,OAAe,KACxB,yBAgdF,CAAC;AAEF,OAAO,EACL,mBAAmB,EACnB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,GAC/B,CAAC"}
|
|
@@ -1,38 +1,29 @@
|
|
|
1
1
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
2
2
|
import { useCallback, useMemo, useState } from "react";
|
|
3
|
+
import { WildduckClient } from "../network/wildduck-client";
|
|
3
4
|
const useWildduckMessages = (networkClient, config, _devMode = false) => {
|
|
4
5
|
const queryClient = useQueryClient();
|
|
6
|
+
const api = useMemo(() => new WildduckClient(networkClient, config), [networkClient, config]);
|
|
5
7
|
const [messages, setMessages] = useState([]);
|
|
6
8
|
const [totalMessages, setTotalMessages] = useState(0);
|
|
7
9
|
const [currentPage, setCurrentPage] = useState(1);
|
|
8
10
|
const [lastFetchParams, setLastFetchParams] = useState(null);
|
|
9
|
-
const
|
|
10
|
-
return {
|
|
11
|
-
"Content-Type": "application/json",
|
|
12
|
-
Accept: "application/json",
|
|
13
|
-
};
|
|
14
|
-
}, []);
|
|
15
|
-
const getMessages = useCallback(async (userId, mailboxId, options = {}) => {
|
|
11
|
+
const getMessages = useCallback(async (wildduckUserAuth, mailboxId, options = {}) => {
|
|
16
12
|
try {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (options.
|
|
21
|
-
|
|
22
|
-
if (options.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const query = queryParams.toString();
|
|
27
|
-
const endpoint = `/users/${userId}/mailboxes/${mailboxId}/messages${query ? `?${query}` : ""}`;
|
|
28
|
-
const response = await networkClient.request(`${apiUrl}${endpoint}`, { method: "GET", headers });
|
|
29
|
-
const messageData = response.data;
|
|
30
|
-
const messageList = messageData.results || [];
|
|
13
|
+
const getMessagesOptions = {};
|
|
14
|
+
if (options.limit !== undefined)
|
|
15
|
+
getMessagesOptions.limit = options.limit;
|
|
16
|
+
if (options.page !== undefined)
|
|
17
|
+
getMessagesOptions.page = options.page;
|
|
18
|
+
if (options.order !== undefined)
|
|
19
|
+
getMessagesOptions.order = options.order;
|
|
20
|
+
const response = await api.getMessages(wildduckUserAuth, mailboxId, getMessagesOptions);
|
|
21
|
+
const messageList = response.results || [];
|
|
31
22
|
setMessages(messageList);
|
|
32
|
-
setTotalMessages(
|
|
33
|
-
setCurrentPage(
|
|
34
|
-
setLastFetchParams({
|
|
35
|
-
queryClient.setQueryData(["wildduck-messages", userId, mailboxId], messageList);
|
|
23
|
+
setTotalMessages(response.total || 0);
|
|
24
|
+
setCurrentPage(response.page || 1);
|
|
25
|
+
setLastFetchParams({ wildduckUserAuth, mailboxId, options });
|
|
26
|
+
queryClient.setQueryData(["wildduck-messages", wildduckUserAuth.userId, mailboxId], messageList);
|
|
36
27
|
return messageList;
|
|
37
28
|
}
|
|
38
29
|
catch (err) {
|
|
@@ -41,31 +32,28 @@ const useWildduckMessages = (networkClient, config, _devMode = false) => {
|
|
|
41
32
|
setTotalMessages(0);
|
|
42
33
|
throw new Error(errorMessage);
|
|
43
34
|
}
|
|
44
|
-
}, [
|
|
45
|
-
const getMessage = useCallback(async (
|
|
35
|
+
}, [api, queryClient]);
|
|
36
|
+
const getMessage = useCallback(async (wildduckUserAuth, mailboxId, messageId) => {
|
|
46
37
|
try {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
const response = await networkClient.request(`${apiUrl}/users/${userId}/mailboxes/${mailboxId}/messages/${messageId}`, { method: "GET", headers });
|
|
50
|
-
const messageData = response.data;
|
|
51
|
-
queryClient.setQueryData(["wildduck-message", userId, mailboxId, messageId], messageData);
|
|
38
|
+
const messageData = await api.getMessage(wildduckUserAuth, mailboxId, messageId);
|
|
39
|
+
queryClient.setQueryData(["wildduck-message", wildduckUserAuth.userId, mailboxId, messageId], messageData);
|
|
52
40
|
return messageData;
|
|
53
41
|
}
|
|
54
42
|
catch (err) {
|
|
55
43
|
const errorMessage = err instanceof Error ? err.message : "Failed to get message";
|
|
56
44
|
throw new Error(errorMessage);
|
|
57
45
|
}
|
|
58
|
-
}, [
|
|
59
|
-
const searchMessages = useCallback(async (
|
|
46
|
+
}, [api, queryClient]);
|
|
47
|
+
const searchMessages = useCallback(async (wildduckUserAuth, query, options = {}) => {
|
|
60
48
|
try {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const messageList =
|
|
49
|
+
const response = await api.searchMessages(wildduckUserAuth, query, {
|
|
50
|
+
limit: options.limit || 50,
|
|
51
|
+
page: options.page || 1,
|
|
52
|
+
});
|
|
53
|
+
const messageList = response.results || [];
|
|
66
54
|
setMessages(messageList);
|
|
67
|
-
setTotalMessages(
|
|
68
|
-
setCurrentPage(
|
|
55
|
+
setTotalMessages(response.total || 0);
|
|
56
|
+
setCurrentPage(response.page || 1);
|
|
69
57
|
return messageList;
|
|
70
58
|
}
|
|
71
59
|
catch (err) {
|
|
@@ -74,22 +62,26 @@ const useWildduckMessages = (networkClient, config, _devMode = false) => {
|
|
|
74
62
|
setTotalMessages(0);
|
|
75
63
|
throw new Error(errorMessage);
|
|
76
64
|
}
|
|
77
|
-
}, [
|
|
65
|
+
}, [api]);
|
|
78
66
|
const sendMutation = useMutation({
|
|
79
67
|
mutationKey: [
|
|
80
68
|
"wildduck-send-message",
|
|
81
69
|
config.cloudflareWorkerUrl || config.backendUrl,
|
|
82
70
|
],
|
|
83
|
-
mutationFn: async ({
|
|
71
|
+
mutationFn: async ({ wildduckUserAuth, params, }) => {
|
|
84
72
|
try {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
73
|
+
const submitRequest = {
|
|
74
|
+
from: params.from ? { address: params.from } : undefined,
|
|
75
|
+
to: params.to,
|
|
76
|
+
cc: params.cc,
|
|
77
|
+
bcc: params.bcc,
|
|
78
|
+
subject: params.subject,
|
|
79
|
+
text: params.text,
|
|
80
|
+
html: params.html,
|
|
81
|
+
attachments: params.attachments,
|
|
82
|
+
};
|
|
83
|
+
const response = await api.submitMessage(wildduckUserAuth, submitRequest);
|
|
84
|
+
return { success: response.success, id: response.message.id };
|
|
93
85
|
}
|
|
94
86
|
catch (err) {
|
|
95
87
|
const errorMessage = err instanceof Error ? err.message : "Failed to send message";
|
|
@@ -98,7 +90,7 @@ const useWildduckMessages = (networkClient, config, _devMode = false) => {
|
|
|
98
90
|
},
|
|
99
91
|
onSuccess: (_, variables) => {
|
|
100
92
|
queryClient.invalidateQueries({
|
|
101
|
-
queryKey: ["wildduck-messages", variables.userId],
|
|
93
|
+
queryKey: ["wildduck-messages", variables.wildduckUserAuth.userId],
|
|
102
94
|
});
|
|
103
95
|
},
|
|
104
96
|
});
|
|
@@ -107,12 +99,10 @@ const useWildduckMessages = (networkClient, config, _devMode = false) => {
|
|
|
107
99
|
"wildduck-update-message",
|
|
108
100
|
config.cloudflareWorkerUrl || config.backendUrl,
|
|
109
101
|
],
|
|
110
|
-
mutationFn: async ({
|
|
102
|
+
mutationFn: async ({ wildduckUserAuth, mailboxId, messageId, params, }) => {
|
|
111
103
|
try {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
const response = await networkClient.request(`${apiUrl}/users/${userId}/mailboxes/${mailboxId}/messages/${messageId}`, { method: "PUT", headers, body: JSON.stringify(params) });
|
|
115
|
-
return response.data;
|
|
104
|
+
const response = await api.updateMessage(wildduckUserAuth, mailboxId, Number(messageId), params);
|
|
105
|
+
return { success: response.success };
|
|
116
106
|
}
|
|
117
107
|
catch (err) {
|
|
118
108
|
const errorMessage = err instanceof Error ? err.message : "Failed to update message";
|
|
@@ -123,13 +113,17 @@ const useWildduckMessages = (networkClient, config, _devMode = false) => {
|
|
|
123
113
|
queryClient.invalidateQueries({
|
|
124
114
|
queryKey: [
|
|
125
115
|
"wildduck-message",
|
|
126
|
-
variables.userId,
|
|
116
|
+
variables.wildduckUserAuth.userId,
|
|
127
117
|
variables.mailboxId,
|
|
128
118
|
variables.messageId,
|
|
129
119
|
],
|
|
130
120
|
});
|
|
131
121
|
queryClient.invalidateQueries({
|
|
132
|
-
queryKey: [
|
|
122
|
+
queryKey: [
|
|
123
|
+
"wildduck-messages",
|
|
124
|
+
variables.wildduckUserAuth.userId,
|
|
125
|
+
variables.mailboxId,
|
|
126
|
+
],
|
|
133
127
|
});
|
|
134
128
|
},
|
|
135
129
|
});
|
|
@@ -138,12 +132,10 @@ const useWildduckMessages = (networkClient, config, _devMode = false) => {
|
|
|
138
132
|
"wildduck-delete-message",
|
|
139
133
|
config.cloudflareWorkerUrl || config.backendUrl,
|
|
140
134
|
],
|
|
141
|
-
mutationFn: async ({
|
|
135
|
+
mutationFn: async ({ wildduckUserAuth, mailboxId, messageId, }) => {
|
|
142
136
|
try {
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
const response = await networkClient.request(`${apiUrl}/users/${userId}/mailboxes/${mailboxId}/messages/${messageId}`, { method: "DELETE", headers });
|
|
146
|
-
return response.data;
|
|
137
|
+
const response = await api.deleteMessage(wildduckUserAuth, mailboxId, Number(messageId));
|
|
138
|
+
return { success: response.success };
|
|
147
139
|
}
|
|
148
140
|
catch (err) {
|
|
149
141
|
const errorMessage = err instanceof Error ? err.message : "Failed to delete message";
|
|
@@ -154,13 +146,17 @@ const useWildduckMessages = (networkClient, config, _devMode = false) => {
|
|
|
154
146
|
queryClient.invalidateQueries({
|
|
155
147
|
queryKey: [
|
|
156
148
|
"wildduck-message",
|
|
157
|
-
variables.userId,
|
|
149
|
+
variables.wildduckUserAuth.userId,
|
|
158
150
|
variables.mailboxId,
|
|
159
151
|
variables.messageId,
|
|
160
152
|
],
|
|
161
153
|
});
|
|
162
154
|
queryClient.invalidateQueries({
|
|
163
|
-
queryKey: [
|
|
155
|
+
queryKey: [
|
|
156
|
+
"wildduck-messages",
|
|
157
|
+
variables.wildduckUserAuth.userId,
|
|
158
|
+
variables.mailboxId,
|
|
159
|
+
],
|
|
164
160
|
});
|
|
165
161
|
},
|
|
166
162
|
});
|
|
@@ -169,16 +165,10 @@ const useWildduckMessages = (networkClient, config, _devMode = false) => {
|
|
|
169
165
|
"wildduck-move-message",
|
|
170
166
|
config.cloudflareWorkerUrl || config.backendUrl,
|
|
171
167
|
],
|
|
172
|
-
mutationFn: async ({
|
|
168
|
+
mutationFn: async ({ wildduckUserAuth, mailboxId, messageId, targetMailbox, }) => {
|
|
173
169
|
try {
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
const response = await networkClient.request(`${apiUrl}/users/${userId}/mailboxes/${mailboxId}/messages/${messageId}`, {
|
|
177
|
-
method: "PUT",
|
|
178
|
-
headers,
|
|
179
|
-
body: JSON.stringify({ mailbox: targetMailbox }),
|
|
180
|
-
});
|
|
181
|
-
return response.data;
|
|
170
|
+
const response = await api.updateMessage(wildduckUserAuth, mailboxId, Number(messageId), { mailbox: targetMailbox });
|
|
171
|
+
return { success: response.success };
|
|
182
172
|
}
|
|
183
173
|
catch (err) {
|
|
184
174
|
const errorMessage = err instanceof Error ? err.message : "Failed to move message";
|
|
@@ -189,22 +179,22 @@ const useWildduckMessages = (networkClient, config, _devMode = false) => {
|
|
|
189
179
|
queryClient.invalidateQueries({
|
|
190
180
|
queryKey: [
|
|
191
181
|
"wildduck-message",
|
|
192
|
-
variables.userId,
|
|
182
|
+
variables.wildduckUserAuth.userId,
|
|
193
183
|
variables.mailboxId,
|
|
194
184
|
variables.messageId,
|
|
195
185
|
],
|
|
196
186
|
});
|
|
197
187
|
queryClient.invalidateQueries({
|
|
198
|
-
queryKey: ["wildduck-messages", variables.userId],
|
|
188
|
+
queryKey: ["wildduck-messages", variables.wildduckUserAuth.userId],
|
|
199
189
|
});
|
|
200
190
|
queryClient.invalidateQueries({
|
|
201
|
-
queryKey: ["wildduck-mailboxes", variables.userId],
|
|
191
|
+
queryKey: ["wildduck-mailboxes", variables.wildduckUserAuth.userId],
|
|
202
192
|
});
|
|
203
193
|
},
|
|
204
194
|
});
|
|
205
195
|
const refresh = useCallback(async () => {
|
|
206
196
|
if (lastFetchParams) {
|
|
207
|
-
await getMessages(lastFetchParams.
|
|
197
|
+
await getMessages(lastFetchParams.wildduckUserAuth, lastFetchParams.mailboxId, lastFetchParams.options);
|
|
208
198
|
}
|
|
209
199
|
}, [lastFetchParams, getMessages]);
|
|
210
200
|
const isLoading = sendMutation.isPending ||
|
|
@@ -216,10 +206,20 @@ const useWildduckMessages = (networkClient, config, _devMode = false) => {
|
|
|
216
206
|
deleteMutation.error?.message ||
|
|
217
207
|
moveMutation.error?.message ||
|
|
218
208
|
null;
|
|
219
|
-
const sendMessage = useCallback(async (
|
|
220
|
-
const updateMessage = useCallback(async (
|
|
221
|
-
|
|
222
|
-
|
|
209
|
+
const sendMessage = useCallback(async (wildduckUserAuth, params) => sendMutation.mutateAsync({ wildduckUserAuth, params }), [sendMutation]);
|
|
210
|
+
const updateMessage = useCallback(async (wildduckUserAuth, mailboxId, messageId, params) => updateMutation.mutateAsync({
|
|
211
|
+
wildduckUserAuth,
|
|
212
|
+
mailboxId,
|
|
213
|
+
messageId,
|
|
214
|
+
params,
|
|
215
|
+
}), [updateMutation]);
|
|
216
|
+
const deleteMessage = useCallback(async (wildduckUserAuth, mailboxId, messageId) => deleteMutation.mutateAsync({ wildduckUserAuth, mailboxId, messageId }), [deleteMutation]);
|
|
217
|
+
const moveMessage = useCallback(async (wildduckUserAuth, mailboxId, messageId, targetMailbox) => moveMutation.mutateAsync({
|
|
218
|
+
wildduckUserAuth,
|
|
219
|
+
mailboxId,
|
|
220
|
+
messageId,
|
|
221
|
+
targetMailbox,
|
|
222
|
+
}), [moveMutation]);
|
|
223
223
|
const clearError = useCallback(() => {
|
|
224
224
|
sendMutation.reset();
|
|
225
225
|
updateMutation.reset();
|