@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 ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright 2025 Hong Minhee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,135 @@
1
+ <!-- deno-fmt-ignore-file -->
2
+
3
+ @upyo/jmap
4
+ ==========
5
+
6
+ [![JSR][JSR badge]][JSR]
7
+ [![npm][npm badge]][npm]
8
+
9
+ [JMAP] transport for the [Upyo] email library. Implements [RFC 8620] (core)
10
+ and [RFC 8621] (mail) for sending emails via JMAP protocol.
11
+
12
+ [JSR]: https://jsr.io/@upyo/jmap
13
+ [JSR badge]: https://jsr.io/badges/@upyo/jmap
14
+ [npm]: https://www.npmjs.com/package/@upyo/jmap
15
+ [npm badge]: https://img.shields.io/npm/v/@upyo/jmap?logo=npm
16
+ [JMAP]: https://jmap.io/
17
+ [RFC 8620]: https://www.rfc-editor.org/rfc/rfc8620
18
+ [RFC 8621]: https://www.rfc-editor.org/rfc/rfc8621
19
+ [Upyo]: https://upyo.org/
20
+
21
+
22
+ Features
23
+ --------
24
+
25
+ - RFC 8620 (JMAP Core) and RFC 8621 (JMAP Mail) compliant
26
+ - Bearer token authentication
27
+ - Automatic session discovery and caching
28
+ - Automatic identity resolution from sender email
29
+ - File attachment support (blob upload)
30
+ - Inline attachment support (multipart/related)
31
+ - Exponential backoff retry with configurable attempts
32
+ - Request timeout support
33
+ - AbortSignal support for cancellation
34
+
35
+
36
+ Installation
37
+ ------------
38
+
39
+ ~~~~ sh
40
+ npm add @upyo/core @upyo/jmap
41
+ pnpm add @upyo/core @upyo/jmap
42
+ yarn add @upyo/core @upyo/jmap
43
+ deno add --jsr @upyo/core @upyo/jmap
44
+ bun add @upyo/core @upyo/jmap
45
+ ~~~~
46
+
47
+
48
+ Usage
49
+ -----
50
+
51
+ ~~~~ typescript
52
+ import { createMessage } from "@upyo/core";
53
+ import { JmapTransport } from "@upyo/jmap";
54
+ import process from "node:process";
55
+
56
+ const message = createMessage({
57
+ from: "sender@example.com",
58
+ to: "recipient@example.net",
59
+ subject: "Hello from Upyo!",
60
+ content: { text: "This is a test email." },
61
+ });
62
+
63
+ const transport = new JmapTransport({
64
+ sessionUrl: process.env.JMAP_SESSION_URL!,
65
+ bearerToken: process.env.JMAP_BEARER_TOKEN!,
66
+ });
67
+
68
+ const receipt = await transport.send(message);
69
+ if (receipt.successful) {
70
+ console.log("Message sent with ID:", receipt.messageId);
71
+ } else {
72
+ console.error("Send failed:", receipt.errorMessages.join(", "));
73
+ }
74
+ ~~~~
75
+
76
+
77
+ Configuration
78
+ -------------
79
+
80
+ ### Authentication Options
81
+
82
+ Either `bearerToken` or `basicAuth` must be provided:
83
+
84
+ | Option | Type | Description |
85
+ |--------|------|-------------|
86
+ | `sessionUrl` | `string` | JMAP session URL (e.g., `https://server/.well-known/jmap`) |
87
+ | `bearerToken` | `string` | Bearer token for authentication |
88
+ | `basicAuth` | `{ username: string, password: string }` | Basic authentication credentials |
89
+
90
+ ### Optional Options
91
+
92
+ | Option | Type | Default | Description |
93
+ |--------|------|---------|-------------|
94
+ | `accountId` | `string` | Auto-detected | JMAP account ID (defaults to first account with mail capability) |
95
+ | `identityId` | `string` | Auto-resolved | Identity ID for sending (defaults to identity matching sender email) |
96
+ | `timeout` | `number` | `30000` | Request timeout in milliseconds |
97
+ | `retries` | `number` | `3` | Number of retry attempts for failed requests |
98
+ | `sessionCacheTtl` | `number` | `300000` | Session cache TTL in milliseconds (5 minutes) |
99
+ | `headers` | `Record<string, string>` | `{}` | Additional HTTP headers to include in requests |
100
+ | `baseUrl` | `string` | - | Base URL for rewriting session URLs (useful when server returns internal hostnames) |
101
+
102
+
103
+ Error Handling
104
+ --------------
105
+
106
+ The transport returns a `Receipt` discriminated union:
107
+
108
+ ~~~~ typescript
109
+ const receipt = await transport.send(message);
110
+
111
+ if (receipt.successful) {
112
+ // Success: receipt.messageId contains the submission ID
113
+ console.log("Sent:", receipt.messageId);
114
+ } else {
115
+ // Failure: receipt.errorMessages contains error details
116
+ console.error("Failed:", receipt.errorMessages);
117
+ }
118
+ ~~~~
119
+
120
+ You can also catch specific JMAP errors:
121
+
122
+ ~~~~ typescript
123
+ import { JmapApiError, isCapabilityError } from "@upyo/jmap";
124
+
125
+ try {
126
+ const receipt = await transport.send(message);
127
+ } catch (error) {
128
+ if (error instanceof JmapApiError) {
129
+ console.error("JMAP error:", error.statusCode, error.responseBody);
130
+ }
131
+ if (isCapabilityError(error)) {
132
+ console.error("Server missing required capabilities");
133
+ }
134
+ }
135
+ ~~~~