@upyo/jmap 0.4.0-dev.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/LICENSE +20 -0
- package/README.md +135 -0
- package/dist/index.cjs +685 -0
- package/dist/index.d.cts +286 -0
- package/dist/index.d.ts +286 -0
- package/dist/index.js +679 -0
- package/package.json +71 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { Message, Receipt, Transport, TransportOptions } from "@upyo/core";
|
|
2
|
+
|
|
3
|
+
//#region src/config.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration interface for JMAP transport connection settings.
|
|
7
|
+
* @since 0.4.0
|
|
8
|
+
*/
|
|
9
|
+
interface JmapConfig {
|
|
10
|
+
/**
|
|
11
|
+
* The JMAP session URL (e.g., `https://server/.well-known/jmap`).
|
|
12
|
+
* This is used for session discovery per RFC 8620 Section 2.
|
|
13
|
+
*/
|
|
14
|
+
readonly sessionUrl: string;
|
|
15
|
+
/**
|
|
16
|
+
* Bearer token for authentication.
|
|
17
|
+
* Used in Authorization header as `Bearer {token}`.
|
|
18
|
+
* Either `bearerToken` or `basicAuth` must be provided.
|
|
19
|
+
*/
|
|
20
|
+
readonly bearerToken?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Basic authentication credentials.
|
|
23
|
+
* Used in Authorization header as `Basic {base64(username:password)}`.
|
|
24
|
+
* Either `bearerToken` or `basicAuth` must be provided.
|
|
25
|
+
* @since 0.4.0
|
|
26
|
+
*/
|
|
27
|
+
readonly basicAuth?: {
|
|
28
|
+
readonly username: string;
|
|
29
|
+
readonly password: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The JMAP account ID to use.
|
|
33
|
+
* If not provided, will be auto-detected from the session response
|
|
34
|
+
* (first account with mail capability).
|
|
35
|
+
*/
|
|
36
|
+
readonly accountId?: string;
|
|
37
|
+
/**
|
|
38
|
+
* The identity ID to use for email submission.
|
|
39
|
+
* If not provided, will be auto-resolved based on sender email address.
|
|
40
|
+
*/
|
|
41
|
+
readonly identityId?: string;
|
|
42
|
+
/**
|
|
43
|
+
* HTTP request timeout in milliseconds.
|
|
44
|
+
* @default 30000
|
|
45
|
+
*/
|
|
46
|
+
readonly timeout?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Number of retry attempts for failed requests.
|
|
49
|
+
* @default 3
|
|
50
|
+
*/
|
|
51
|
+
readonly retries?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Custom HTTP headers to include with requests.
|
|
54
|
+
*/
|
|
55
|
+
readonly headers?: Record<string, string>;
|
|
56
|
+
/**
|
|
57
|
+
* Session cache TTL in milliseconds.
|
|
58
|
+
* Sessions are refreshed when capabilities errors occur or after this duration.
|
|
59
|
+
* @default 300000 (5 minutes)
|
|
60
|
+
*/
|
|
61
|
+
readonly sessionCacheTtl?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Base URL to use for rewriting session URLs.
|
|
64
|
+
* Some JMAP servers return internal hostnames in session responses.
|
|
65
|
+
* When set, URLs from the session (apiUrl, uploadUrl, etc.) will be rewritten
|
|
66
|
+
* to use this base URL instead.
|
|
67
|
+
* Example: If the session returns `http://internal-host:8080/jmap/` and
|
|
68
|
+
* baseUrl is `http://localhost:8080`, URLs will be rewritten to use localhost.
|
|
69
|
+
* @since 0.4.0
|
|
70
|
+
*/
|
|
71
|
+
readonly baseUrl?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Resolved JMAP configuration with all fields populated.
|
|
75
|
+
* @since 0.4.0
|
|
76
|
+
*/
|
|
77
|
+
type ResolvedJmapConfig = {
|
|
78
|
+
readonly sessionUrl: string;
|
|
79
|
+
readonly bearerToken: string | null;
|
|
80
|
+
readonly basicAuth: {
|
|
81
|
+
readonly username: string;
|
|
82
|
+
readonly password: string;
|
|
83
|
+
} | null;
|
|
84
|
+
readonly accountId: string | null;
|
|
85
|
+
readonly identityId: string | null;
|
|
86
|
+
readonly timeout: number;
|
|
87
|
+
readonly retries: number;
|
|
88
|
+
readonly headers: Record<string, string>;
|
|
89
|
+
readonly sessionCacheTtl: number;
|
|
90
|
+
readonly baseUrl: string | null;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Creates a resolved JMAP configuration with default values applied.
|
|
94
|
+
* @param config The user-provided configuration.
|
|
95
|
+
* @returns The resolved configuration with all fields populated.
|
|
96
|
+
* @throws Error if neither bearerToken nor basicAuth is provided.
|
|
97
|
+
* @since 0.4.0
|
|
98
|
+
*/
|
|
99
|
+
declare function createJmapConfig(config: JmapConfig): ResolvedJmapConfig;
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/jmap-transport.d.ts
|
|
102
|
+
/**
|
|
103
|
+
* JMAP transport for sending emails via JMAP protocol (RFC 8620/8621).
|
|
104
|
+
* @since 0.4.0
|
|
105
|
+
*/
|
|
106
|
+
declare class JmapTransport implements Transport {
|
|
107
|
+
readonly config: ResolvedJmapConfig;
|
|
108
|
+
private readonly httpClient;
|
|
109
|
+
private cachedSession;
|
|
110
|
+
/**
|
|
111
|
+
* Creates a new JMAP transport instance.
|
|
112
|
+
* @param config The JMAP transport configuration.
|
|
113
|
+
* @since 0.4.0
|
|
114
|
+
*/
|
|
115
|
+
constructor(config: JmapConfig);
|
|
116
|
+
/**
|
|
117
|
+
* Sends a single email message.
|
|
118
|
+
* @param message The message to send.
|
|
119
|
+
* @param options Optional transport options.
|
|
120
|
+
* @returns A receipt indicating success or failure.
|
|
121
|
+
* @since 0.4.0
|
|
122
|
+
*/
|
|
123
|
+
send(message: Message, options?: TransportOptions): Promise<Receipt>;
|
|
124
|
+
/**
|
|
125
|
+
* Sends multiple messages sequentially.
|
|
126
|
+
* @param messages The messages to send.
|
|
127
|
+
* @param options Optional transport options.
|
|
128
|
+
* @yields Receipts for each message.
|
|
129
|
+
* @since 0.4.0
|
|
130
|
+
*/
|
|
131
|
+
sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt>;
|
|
132
|
+
/**
|
|
133
|
+
* Gets or refreshes the JMAP session.
|
|
134
|
+
* @param signal Optional abort signal.
|
|
135
|
+
* @returns The JMAP session.
|
|
136
|
+
* @since 0.4.0
|
|
137
|
+
*/
|
|
138
|
+
private getSession;
|
|
139
|
+
/**
|
|
140
|
+
* Rewrites session URLs to use the configured baseUrl.
|
|
141
|
+
* @param session The original session from the server.
|
|
142
|
+
* @returns A new session with rewritten URLs.
|
|
143
|
+
* @since 0.4.0
|
|
144
|
+
*/
|
|
145
|
+
private rewriteSessionUrls;
|
|
146
|
+
/**
|
|
147
|
+
* Gets the drafts mailbox ID from the session.
|
|
148
|
+
* @param session The JMAP session.
|
|
149
|
+
* @param accountId The account ID.
|
|
150
|
+
* @param signal Optional abort signal.
|
|
151
|
+
* @returns The drafts mailbox ID.
|
|
152
|
+
* @since 0.4.0
|
|
153
|
+
*/
|
|
154
|
+
private getDraftsMailboxId;
|
|
155
|
+
/**
|
|
156
|
+
* Gets the identity ID for the sender.
|
|
157
|
+
* @param session The JMAP session.
|
|
158
|
+
* @param accountId The account ID.
|
|
159
|
+
* @param senderEmail The sender's email address.
|
|
160
|
+
* @param signal Optional abort signal.
|
|
161
|
+
* @returns The identity ID.
|
|
162
|
+
* @since 0.4.0
|
|
163
|
+
*/
|
|
164
|
+
private getIdentityId;
|
|
165
|
+
/**
|
|
166
|
+
* Uploads all attachments and returns a map of contentId to blobId.
|
|
167
|
+
* @param session The JMAP session.
|
|
168
|
+
* @param accountId The account ID.
|
|
169
|
+
* @param attachments Array of attachments to upload.
|
|
170
|
+
* @param signal Optional abort signal.
|
|
171
|
+
* @returns Map of contentId to blobId.
|
|
172
|
+
* @since 0.4.0
|
|
173
|
+
*/
|
|
174
|
+
private uploadAttachments;
|
|
175
|
+
/**
|
|
176
|
+
* Parses the JMAP response to extract receipt information.
|
|
177
|
+
* @param response The JMAP response.
|
|
178
|
+
* @returns A receipt indicating success or failure.
|
|
179
|
+
* @since 0.4.0
|
|
180
|
+
*/
|
|
181
|
+
private parseResponse;
|
|
182
|
+
}
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/errors.d.ts
|
|
185
|
+
/**
|
|
186
|
+
* Error class for JMAP API errors.
|
|
187
|
+
* @since 0.4.0
|
|
188
|
+
*/
|
|
189
|
+
declare class JmapApiError extends Error {
|
|
190
|
+
readonly statusCode?: number;
|
|
191
|
+
readonly responseBody?: string;
|
|
192
|
+
readonly jmapErrorType?: string;
|
|
193
|
+
constructor(message: string, statusCode?: number, responseBody?: string, jmapErrorType?: string);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* JMAP-specific error types from RFC 8620.
|
|
197
|
+
* @since 0.4.0
|
|
198
|
+
*/
|
|
199
|
+
declare const JMAP_ERROR_TYPES: {
|
|
200
|
+
readonly unknownCapability: "urn:ietf:params:jmap:error:unknownCapability";
|
|
201
|
+
readonly notJSON: "urn:ietf:params:jmap:error:notJSON";
|
|
202
|
+
readonly notRequest: "urn:ietf:params:jmap:error:notRequest";
|
|
203
|
+
readonly limit: "urn:ietf:params:jmap:error:limit";
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Checks if the given error is a JMAP capability error.
|
|
207
|
+
* @param error The error to check.
|
|
208
|
+
* @returns `true` if the error is a JMAP capability error, `false` otherwise.
|
|
209
|
+
* @since 0.4.0
|
|
210
|
+
*/
|
|
211
|
+
declare function isCapabilityError(error: unknown): boolean;
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/session.d.ts
|
|
214
|
+
/**
|
|
215
|
+
* JMAP Session response structure (RFC 8620 Section 2).
|
|
216
|
+
* @since 0.4.0
|
|
217
|
+
*/
|
|
218
|
+
interface JmapSession {
|
|
219
|
+
readonly capabilities: Record<string, unknown>;
|
|
220
|
+
readonly accounts: Record<string, JmapAccount>;
|
|
221
|
+
readonly primaryAccounts: Record<string, string>;
|
|
222
|
+
readonly username: string;
|
|
223
|
+
readonly apiUrl: string;
|
|
224
|
+
readonly downloadUrl: string;
|
|
225
|
+
readonly uploadUrl: string;
|
|
226
|
+
readonly eventSourceUrl?: string;
|
|
227
|
+
readonly state: string;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* JMAP Account structure from session response.
|
|
231
|
+
* @since 0.4.0
|
|
232
|
+
*/
|
|
233
|
+
interface JmapAccount {
|
|
234
|
+
readonly name: string;
|
|
235
|
+
readonly isPersonal: boolean;
|
|
236
|
+
readonly isReadOnly: boolean;
|
|
237
|
+
readonly accountCapabilities: Record<string, unknown>;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* JMAP Identity object for sender authorization (RFC 8621 Section 6).
|
|
241
|
+
* @since 0.4.0
|
|
242
|
+
*/
|
|
243
|
+
interface JmapIdentity {
|
|
244
|
+
readonly id: string;
|
|
245
|
+
readonly name: string;
|
|
246
|
+
readonly email: string;
|
|
247
|
+
readonly replyTo?: readonly {
|
|
248
|
+
readonly email: string;
|
|
249
|
+
readonly name?: string;
|
|
250
|
+
}[];
|
|
251
|
+
readonly bcc?: readonly {
|
|
252
|
+
readonly email: string;
|
|
253
|
+
readonly name?: string;
|
|
254
|
+
}[];
|
|
255
|
+
readonly textSignature?: string;
|
|
256
|
+
readonly htmlSignature?: string;
|
|
257
|
+
readonly mayDelete: boolean;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Cached session data with metadata.
|
|
261
|
+
* @since 0.4.0
|
|
262
|
+
*/
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/blob-uploader.d.ts
|
|
265
|
+
/**
|
|
266
|
+
* Response from a successful blob upload.
|
|
267
|
+
*/
|
|
268
|
+
interface BlobUploadResponse {
|
|
269
|
+
readonly accountId: string;
|
|
270
|
+
readonly blobId: string;
|
|
271
|
+
readonly type: string;
|
|
272
|
+
readonly size: number;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Upload a blob to the JMAP server.
|
|
276
|
+
*
|
|
277
|
+
* @param config - The resolved JMAP configuration
|
|
278
|
+
* @param uploadUrl - The upload URL template from the session (e.g., "https://server/upload/{accountId}")
|
|
279
|
+
* @param accountId - The account ID to upload to
|
|
280
|
+
* @param blob - The blob or file to upload
|
|
281
|
+
* @param signal - Optional abort signal
|
|
282
|
+
* @returns The upload response containing the blobId
|
|
283
|
+
*/
|
|
284
|
+
declare function uploadBlob(config: ResolvedJmapConfig, uploadUrl: string, accountId: string, blob: Blob | File, signal?: AbortSignal): Promise<BlobUploadResponse>;
|
|
285
|
+
//#endregion
|
|
286
|
+
export { BlobUploadResponse, JMAP_ERROR_TYPES, JmapAccount, JmapApiError, JmapConfig, JmapIdentity, JmapSession, JmapTransport, ResolvedJmapConfig, createJmapConfig, isCapabilityError, uploadBlob };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { Message, Receipt, Transport, TransportOptions } from "@upyo/core";
|
|
2
|
+
|
|
3
|
+
//#region src/config.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration interface for JMAP transport connection settings.
|
|
7
|
+
* @since 0.4.0
|
|
8
|
+
*/
|
|
9
|
+
interface JmapConfig {
|
|
10
|
+
/**
|
|
11
|
+
* The JMAP session URL (e.g., `https://server/.well-known/jmap`).
|
|
12
|
+
* This is used for session discovery per RFC 8620 Section 2.
|
|
13
|
+
*/
|
|
14
|
+
readonly sessionUrl: string;
|
|
15
|
+
/**
|
|
16
|
+
* Bearer token for authentication.
|
|
17
|
+
* Used in Authorization header as `Bearer {token}`.
|
|
18
|
+
* Either `bearerToken` or `basicAuth` must be provided.
|
|
19
|
+
*/
|
|
20
|
+
readonly bearerToken?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Basic authentication credentials.
|
|
23
|
+
* Used in Authorization header as `Basic {base64(username:password)}`.
|
|
24
|
+
* Either `bearerToken` or `basicAuth` must be provided.
|
|
25
|
+
* @since 0.4.0
|
|
26
|
+
*/
|
|
27
|
+
readonly basicAuth?: {
|
|
28
|
+
readonly username: string;
|
|
29
|
+
readonly password: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The JMAP account ID to use.
|
|
33
|
+
* If not provided, will be auto-detected from the session response
|
|
34
|
+
* (first account with mail capability).
|
|
35
|
+
*/
|
|
36
|
+
readonly accountId?: string;
|
|
37
|
+
/**
|
|
38
|
+
* The identity ID to use for email submission.
|
|
39
|
+
* If not provided, will be auto-resolved based on sender email address.
|
|
40
|
+
*/
|
|
41
|
+
readonly identityId?: string;
|
|
42
|
+
/**
|
|
43
|
+
* HTTP request timeout in milliseconds.
|
|
44
|
+
* @default 30000
|
|
45
|
+
*/
|
|
46
|
+
readonly timeout?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Number of retry attempts for failed requests.
|
|
49
|
+
* @default 3
|
|
50
|
+
*/
|
|
51
|
+
readonly retries?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Custom HTTP headers to include with requests.
|
|
54
|
+
*/
|
|
55
|
+
readonly headers?: Record<string, string>;
|
|
56
|
+
/**
|
|
57
|
+
* Session cache TTL in milliseconds.
|
|
58
|
+
* Sessions are refreshed when capabilities errors occur or after this duration.
|
|
59
|
+
* @default 300000 (5 minutes)
|
|
60
|
+
*/
|
|
61
|
+
readonly sessionCacheTtl?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Base URL to use for rewriting session URLs.
|
|
64
|
+
* Some JMAP servers return internal hostnames in session responses.
|
|
65
|
+
* When set, URLs from the session (apiUrl, uploadUrl, etc.) will be rewritten
|
|
66
|
+
* to use this base URL instead.
|
|
67
|
+
* Example: If the session returns `http://internal-host:8080/jmap/` and
|
|
68
|
+
* baseUrl is `http://localhost:8080`, URLs will be rewritten to use localhost.
|
|
69
|
+
* @since 0.4.0
|
|
70
|
+
*/
|
|
71
|
+
readonly baseUrl?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Resolved JMAP configuration with all fields populated.
|
|
75
|
+
* @since 0.4.0
|
|
76
|
+
*/
|
|
77
|
+
type ResolvedJmapConfig = {
|
|
78
|
+
readonly sessionUrl: string;
|
|
79
|
+
readonly bearerToken: string | null;
|
|
80
|
+
readonly basicAuth: {
|
|
81
|
+
readonly username: string;
|
|
82
|
+
readonly password: string;
|
|
83
|
+
} | null;
|
|
84
|
+
readonly accountId: string | null;
|
|
85
|
+
readonly identityId: string | null;
|
|
86
|
+
readonly timeout: number;
|
|
87
|
+
readonly retries: number;
|
|
88
|
+
readonly headers: Record<string, string>;
|
|
89
|
+
readonly sessionCacheTtl: number;
|
|
90
|
+
readonly baseUrl: string | null;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Creates a resolved JMAP configuration with default values applied.
|
|
94
|
+
* @param config The user-provided configuration.
|
|
95
|
+
* @returns The resolved configuration with all fields populated.
|
|
96
|
+
* @throws Error if neither bearerToken nor basicAuth is provided.
|
|
97
|
+
* @since 0.4.0
|
|
98
|
+
*/
|
|
99
|
+
declare function createJmapConfig(config: JmapConfig): ResolvedJmapConfig;
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/jmap-transport.d.ts
|
|
102
|
+
/**
|
|
103
|
+
* JMAP transport for sending emails via JMAP protocol (RFC 8620/8621).
|
|
104
|
+
* @since 0.4.0
|
|
105
|
+
*/
|
|
106
|
+
declare class JmapTransport implements Transport {
|
|
107
|
+
readonly config: ResolvedJmapConfig;
|
|
108
|
+
private readonly httpClient;
|
|
109
|
+
private cachedSession;
|
|
110
|
+
/**
|
|
111
|
+
* Creates a new JMAP transport instance.
|
|
112
|
+
* @param config The JMAP transport configuration.
|
|
113
|
+
* @since 0.4.0
|
|
114
|
+
*/
|
|
115
|
+
constructor(config: JmapConfig);
|
|
116
|
+
/**
|
|
117
|
+
* Sends a single email message.
|
|
118
|
+
* @param message The message to send.
|
|
119
|
+
* @param options Optional transport options.
|
|
120
|
+
* @returns A receipt indicating success or failure.
|
|
121
|
+
* @since 0.4.0
|
|
122
|
+
*/
|
|
123
|
+
send(message: Message, options?: TransportOptions): Promise<Receipt>;
|
|
124
|
+
/**
|
|
125
|
+
* Sends multiple messages sequentially.
|
|
126
|
+
* @param messages The messages to send.
|
|
127
|
+
* @param options Optional transport options.
|
|
128
|
+
* @yields Receipts for each message.
|
|
129
|
+
* @since 0.4.0
|
|
130
|
+
*/
|
|
131
|
+
sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt>;
|
|
132
|
+
/**
|
|
133
|
+
* Gets or refreshes the JMAP session.
|
|
134
|
+
* @param signal Optional abort signal.
|
|
135
|
+
* @returns The JMAP session.
|
|
136
|
+
* @since 0.4.0
|
|
137
|
+
*/
|
|
138
|
+
private getSession;
|
|
139
|
+
/**
|
|
140
|
+
* Rewrites session URLs to use the configured baseUrl.
|
|
141
|
+
* @param session The original session from the server.
|
|
142
|
+
* @returns A new session with rewritten URLs.
|
|
143
|
+
* @since 0.4.0
|
|
144
|
+
*/
|
|
145
|
+
private rewriteSessionUrls;
|
|
146
|
+
/**
|
|
147
|
+
* Gets the drafts mailbox ID from the session.
|
|
148
|
+
* @param session The JMAP session.
|
|
149
|
+
* @param accountId The account ID.
|
|
150
|
+
* @param signal Optional abort signal.
|
|
151
|
+
* @returns The drafts mailbox ID.
|
|
152
|
+
* @since 0.4.0
|
|
153
|
+
*/
|
|
154
|
+
private getDraftsMailboxId;
|
|
155
|
+
/**
|
|
156
|
+
* Gets the identity ID for the sender.
|
|
157
|
+
* @param session The JMAP session.
|
|
158
|
+
* @param accountId The account ID.
|
|
159
|
+
* @param senderEmail The sender's email address.
|
|
160
|
+
* @param signal Optional abort signal.
|
|
161
|
+
* @returns The identity ID.
|
|
162
|
+
* @since 0.4.0
|
|
163
|
+
*/
|
|
164
|
+
private getIdentityId;
|
|
165
|
+
/**
|
|
166
|
+
* Uploads all attachments and returns a map of contentId to blobId.
|
|
167
|
+
* @param session The JMAP session.
|
|
168
|
+
* @param accountId The account ID.
|
|
169
|
+
* @param attachments Array of attachments to upload.
|
|
170
|
+
* @param signal Optional abort signal.
|
|
171
|
+
* @returns Map of contentId to blobId.
|
|
172
|
+
* @since 0.4.0
|
|
173
|
+
*/
|
|
174
|
+
private uploadAttachments;
|
|
175
|
+
/**
|
|
176
|
+
* Parses the JMAP response to extract receipt information.
|
|
177
|
+
* @param response The JMAP response.
|
|
178
|
+
* @returns A receipt indicating success or failure.
|
|
179
|
+
* @since 0.4.0
|
|
180
|
+
*/
|
|
181
|
+
private parseResponse;
|
|
182
|
+
}
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/errors.d.ts
|
|
185
|
+
/**
|
|
186
|
+
* Error class for JMAP API errors.
|
|
187
|
+
* @since 0.4.0
|
|
188
|
+
*/
|
|
189
|
+
declare class JmapApiError extends Error {
|
|
190
|
+
readonly statusCode?: number;
|
|
191
|
+
readonly responseBody?: string;
|
|
192
|
+
readonly jmapErrorType?: string;
|
|
193
|
+
constructor(message: string, statusCode?: number, responseBody?: string, jmapErrorType?: string);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* JMAP-specific error types from RFC 8620.
|
|
197
|
+
* @since 0.4.0
|
|
198
|
+
*/
|
|
199
|
+
declare const JMAP_ERROR_TYPES: {
|
|
200
|
+
readonly unknownCapability: "urn:ietf:params:jmap:error:unknownCapability";
|
|
201
|
+
readonly notJSON: "urn:ietf:params:jmap:error:notJSON";
|
|
202
|
+
readonly notRequest: "urn:ietf:params:jmap:error:notRequest";
|
|
203
|
+
readonly limit: "urn:ietf:params:jmap:error:limit";
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Checks if the given error is a JMAP capability error.
|
|
207
|
+
* @param error The error to check.
|
|
208
|
+
* @returns `true` if the error is a JMAP capability error, `false` otherwise.
|
|
209
|
+
* @since 0.4.0
|
|
210
|
+
*/
|
|
211
|
+
declare function isCapabilityError(error: unknown): boolean;
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/session.d.ts
|
|
214
|
+
/**
|
|
215
|
+
* JMAP Session response structure (RFC 8620 Section 2).
|
|
216
|
+
* @since 0.4.0
|
|
217
|
+
*/
|
|
218
|
+
interface JmapSession {
|
|
219
|
+
readonly capabilities: Record<string, unknown>;
|
|
220
|
+
readonly accounts: Record<string, JmapAccount>;
|
|
221
|
+
readonly primaryAccounts: Record<string, string>;
|
|
222
|
+
readonly username: string;
|
|
223
|
+
readonly apiUrl: string;
|
|
224
|
+
readonly downloadUrl: string;
|
|
225
|
+
readonly uploadUrl: string;
|
|
226
|
+
readonly eventSourceUrl?: string;
|
|
227
|
+
readonly state: string;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* JMAP Account structure from session response.
|
|
231
|
+
* @since 0.4.0
|
|
232
|
+
*/
|
|
233
|
+
interface JmapAccount {
|
|
234
|
+
readonly name: string;
|
|
235
|
+
readonly isPersonal: boolean;
|
|
236
|
+
readonly isReadOnly: boolean;
|
|
237
|
+
readonly accountCapabilities: Record<string, unknown>;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* JMAP Identity object for sender authorization (RFC 8621 Section 6).
|
|
241
|
+
* @since 0.4.0
|
|
242
|
+
*/
|
|
243
|
+
interface JmapIdentity {
|
|
244
|
+
readonly id: string;
|
|
245
|
+
readonly name: string;
|
|
246
|
+
readonly email: string;
|
|
247
|
+
readonly replyTo?: readonly {
|
|
248
|
+
readonly email: string;
|
|
249
|
+
readonly name?: string;
|
|
250
|
+
}[];
|
|
251
|
+
readonly bcc?: readonly {
|
|
252
|
+
readonly email: string;
|
|
253
|
+
readonly name?: string;
|
|
254
|
+
}[];
|
|
255
|
+
readonly textSignature?: string;
|
|
256
|
+
readonly htmlSignature?: string;
|
|
257
|
+
readonly mayDelete: boolean;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Cached session data with metadata.
|
|
261
|
+
* @since 0.4.0
|
|
262
|
+
*/
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/blob-uploader.d.ts
|
|
265
|
+
/**
|
|
266
|
+
* Response from a successful blob upload.
|
|
267
|
+
*/
|
|
268
|
+
interface BlobUploadResponse {
|
|
269
|
+
readonly accountId: string;
|
|
270
|
+
readonly blobId: string;
|
|
271
|
+
readonly type: string;
|
|
272
|
+
readonly size: number;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Upload a blob to the JMAP server.
|
|
276
|
+
*
|
|
277
|
+
* @param config - The resolved JMAP configuration
|
|
278
|
+
* @param uploadUrl - The upload URL template from the session (e.g., "https://server/upload/{accountId}")
|
|
279
|
+
* @param accountId - The account ID to upload to
|
|
280
|
+
* @param blob - The blob or file to upload
|
|
281
|
+
* @param signal - Optional abort signal
|
|
282
|
+
* @returns The upload response containing the blobId
|
|
283
|
+
*/
|
|
284
|
+
declare function uploadBlob(config: ResolvedJmapConfig, uploadUrl: string, accountId: string, blob: Blob | File, signal?: AbortSignal): Promise<BlobUploadResponse>;
|
|
285
|
+
//#endregion
|
|
286
|
+
export { BlobUploadResponse, JMAP_ERROR_TYPES, JmapAccount, JmapApiError, JmapConfig, JmapIdentity, JmapSession, JmapTransport, ResolvedJmapConfig, createJmapConfig, isCapabilityError, uploadBlob };
|