@eliware/mail-client 15.0.2 → 15.0.3

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/README.md CHANGED
@@ -31,19 +31,19 @@ Use Node.js 26 or later. Browser applications require Fetch, Headers, AbortSigna
31
31
 
32
32
  ## Setup
33
33
 
34
- Install the package with `npm install @eliware/mail-client`. Read the [usage guide](docs/usage.md) to configure the API URL and bearer-token provider.
34
+ Install the package with `npm install @eliware/mail-client`. Follow the [usage guide](docs/usage.md) to configure the API address and bearer-token provider.
35
35
 
36
36
  ## Usage
37
37
 
38
- Read the [usage guide](docs/usage.md), [API reference](docs/api.md), and [release notes](RELEASE_NOTES.md). Find runnable examples in [examples/README.md](examples/README.md).
38
+ Follow the [usage guide](docs/usage.md). Find client methods in the [API reference](docs/api.md) and version changes in the [release notes](RELEASE_NOTES.md).
39
39
 
40
40
  ## Development
41
41
 
42
- Read [AGENTS.md](AGENTS.md), [documentation](docs/README.md), and [specifications](specs/README.md) before changing files. Run `npm ci` to install locked dependencies.
42
+ Read [AGENTS.md](AGENTS.md) and [specifications](specs/README.md) before changing files. Find maintained guides in [documentation](docs/README.md).
43
43
 
44
44
  ## Testing
45
45
 
46
- Run `npm test` for aggregate checks. Run `npm run smoke` for an HTTP and WebSocket check.
46
+ Run `npm test` for aggregate validation. Run `npm run smoke` to check an HTTP and WebSocket connection.
47
47
 
48
48
  ## Troubleshooting
49
49
 
@@ -56,11 +56,10 @@ Keep long-lived API tokens in server-side secret stores. Do not expose them to b
56
56
  ## API
57
57
 
58
58
  Read the [API reference](docs/api.md) for client options, methods, events, logging, and errors.
59
- The Node.js entry uses `@eliware/log`. Browser logging stays silent by default.
60
59
 
61
60
  ## Packaging
62
61
 
63
- Follow approved release steps before you publish a version. Read [release notes](RELEASE_NOTES.md) for package changes.
62
+ Read [package details](docs/package.md) for runtime support, package contents, and version rules. Read [release notes](RELEASE_NOTES.md) for package changes.
64
63
 
65
64
  ## Examples
66
65
 
package/RELEASE_NOTES.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Release Notes
2
2
 
3
+ ## 15.0.3 — 2026-10-30
4
+
5
+ ### Added
6
+
7
+ - Add a package guide for runtime support, entrypoints, environment values, package contents, and publication.
8
+
9
+ ### Changed
10
+
11
+ - Set the package version to 15.0.3.
12
+ - Send `consumer_id` in durable WebSocket requests and use the server-stored consumer cursor.
13
+ - Reject `after` when a WebSocket connection uses `consumerId`.
14
+ - Keep `ready` pending while automatic reconnect retries token-provider or socket failures.
15
+ - Update locked transitive dependencies and simplify README navigation.
16
+
17
+ ### Fixed
18
+
19
+ - Stop queued event handlers after an earlier event handler fails.
20
+ - Reject browser WebSocket frames that contain binary `Blob` data.
21
+
3
22
  ## 15.0.2 — 2026-10-30
4
23
 
5
24
  ### Added
package/docs/README.md CHANGED
@@ -6,4 +6,5 @@ This directory contains user and API documentation for `@eliware/mail-client`.
6
6
 
7
7
  - [Usage](usage.md)
8
8
  - [API reference](api.md)
9
+ - [Package details](package.md)
9
10
  - [Troubleshooting](troubleshooting.md)
package/docs/api.md CHANGED
@@ -141,7 +141,7 @@ The error message uses the API error message when available. Network errors and
141
141
 
142
142
  ### `connectEvents(options)`
143
143
 
144
- Open the `/ws` route and receive event notifications. The WebSocket URL uses `ws` for an HTTP base address and `wss` for an HTTPS base address. The client puts the optional `after` cursor in the URL and excludes tokens.
144
+ Open the `/ws` route and receive event notifications. The WebSocket URL uses `ws` for an HTTP base address and `wss` for an HTTPS base address. The client puts the optional `after` cursor or `consumer_id` in the URL and excludes tokens.
145
145
 
146
146
  After the socket opens, the client sends this JSON frame as its first message:
147
147
 
@@ -155,23 +155,25 @@ The client waits for this server frame before it delivers events:
155
155
  { "type": "authenticated" }
156
156
  ```
157
157
 
158
- | Option | Default | Description |
159
- | --------------------- | ------------- | --------------------------------------------------------------------------- |
160
- | `onEvent(event)` | Required | Processes one JSON event. A returned promise delays cursor acknowledgement. |
161
- | `onError(error)` | No operation | Receives socket, handler, and acknowledgement errors. |
162
- | `logger` | Client logger | Overrides the logger for this event connection. |
163
- | `after` | Live edge | Starts event replay after a decimal cursor. |
164
- | `consumerId` | None | Enables server-side cursor acknowledgements. |
165
- | `autoReconnect` | `true` | Reconnects after unexpected closure. |
166
- | `retryDelayMs` | `500` | Sets the first reconnect wait interval. |
167
- | `maxReconnectDelayMs` | `30000` | Sets the longest reconnect wait interval. |
168
- | `WebSocketImpl` | Client option | Overrides the WebSocket constructor for this connection. |
158
+ | Option | Default | Description |
159
+ | --------------------- | ------------- | ------------------------------------------------------------------------------ |
160
+ | `onEvent(event)` | Required | Processes one JSON event. A returned promise delays cursor acknowledgement. |
161
+ | `onError(error)` | No operation | Receives socket, handler, and acknowledgement errors. |
162
+ | `logger` | Client logger | Overrides the logger for this event connection. |
163
+ | `after` | Live edge | Starts event replay after a decimal cursor. |
164
+ | `consumerId` | None | Sends `consumer_id` to the server and enables durable cursor acknowledgements. |
165
+ | `autoReconnect` | `true` | Reconnects after unexpected closure. |
166
+ | `retryDelayMs` | `500` | Sets the first reconnect wait interval. |
167
+ | `maxReconnectDelayMs` | `30000` | Sets the longest reconnect wait interval. |
168
+ | `WebSocketImpl` | Client option | Overrides the WebSocket constructor for this connection. |
169
169
 
170
- The connection object exposes `ready`, `cursor`, and `close()`. The `ready` promise resolves after the first authentication acknowledgement. It rejects if the first token request fails or the socket closes before authentication. A rejected token request retries automatically when `autoReconnect` is enabled. An invalid token value or WebSocket construction error stops automatic reconnects.
170
+ The connection object exposes `ready`, `cursor`, and `close()`. The `ready` promise resolves after the first authentication acknowledgement. When `autoReconnect` is enabled, retryable token-provider failures and socket closures keep `ready` pending while the client retries. The promise rejects when retries stop before authentication, the token value is invalid, socket construction fails, or the caller closes the connection.
171
171
 
172
172
  The server accepts cursors from `0` through the maximum Snowflake ID. It requires decimal strings without leading zeroes, except for `0` itself.
173
173
 
174
- The client calls one event handler at a time. With `consumerId`, it acknowledges an event after its handler succeeds. It advances `cursor` only after the server accepts that acknowledgement. If event handling or acknowledgement fails, the client reports the error, closes the socket, and stops automatic reconnects.
174
+ The client calls one event handler at a time. With `consumerId`, it sends that ID in the WebSocket URL and acknowledges each event after its handler succeeds. The server stores progress for that consumer. The client advances `cursor` only after the server accepts the acknowledgement. If event handling or acknowledgement fails, the client reports the error, closes the socket, and stops automatic reconnects.
175
+
176
+ Do not pass both `after` and `consumerId`. The server uses `after` for cursor-based replay and `consumer_id` for durable replay. The server rejects a request that includes both values.
175
177
 
176
178
  Without `consumerId`, `cursor` remains in memory and is used when the connection reconnects. Store the cursor outside the client if it must survive a new process start. Make event handlers safe to run more than once.
177
179
 
@@ -0,0 +1,47 @@
1
+ # Package details
2
+
3
+ ## Installation and support
4
+
5
+ Install the package with npm:
6
+
7
+ ```sh
8
+ npm install @eliware/mail-client
9
+ ```
10
+
11
+ The package supports Node.js 26 or later. Browser applications use Fetch, Headers, AbortSignal, URL, and WebSocket APIs. Use a bundler that honors the package `browser` export condition to select the browser entry.
12
+
13
+ The package root exports `createMailClient` and `MailApiError`. It includes TypeScript declarations at `src/index.d.ts`. Node.js uses `src/index.mjs`. Browser builds use `src/index.browser.mjs` and a silent logger by default.
14
+
15
+ The Node.js entry uses `@eliware/log` as a runtime dependency. The browser entry does not import the Node.js logger. Both entries expose the same client API.
16
+
17
+ ## Environment values
18
+
19
+ The library accepts `baseUrl` and `getAccessToken` as required client options. It does not read API URLs or API tokens from the environment. The examples use these application-owned values:
20
+
21
+ | Value | Example default | Required status | Purpose |
22
+ | ----------------------- | ---------------------------- | -------------------------------- | -------------------------------------------------------- |
23
+ | `MAIL_API_URL` | `https://mail.example.test` | Required by usage examples | Sets the mail-server base address. |
24
+ | `MAIL_API_TOKEN` | `replace-with-a-local-token` | Required by the Node.js examples | Supplies a bearer token to the example host. |
25
+ | `MAIL_WEB_API_TOKEN` | None | Required by the mail-web example | Supplies the server token for browser-token requests. |
26
+ | `MAIL_CLIENT_LOG_LEVEL` | `LOG_LEVEL` or `info` | Optional for the Node.js entry | Sets the package logger level. |
27
+ | `LOG_LEVEL` | `info` | Optional for the Node.js entry | Sets the logger level when the package value is missing. |
28
+
29
+ The host application reads the first three values and passes them to the library. Keep long-lived tokens on trusted servers. The library reads the two log-level values in the Node.js entry. The browser entry does not read them.
30
+
31
+ The package requires `baseUrl` and `getAccessToken` when you create a client. The environment values above belong to the example host applications. Only the two log-level values come from the library process environment.
32
+
33
+ ## Package contents
34
+
35
+ The npm package includes `src/`, `docs/`, `examples/`, `specs/`, `README.md`, `AGENTS.md`, `LICENSE`, `RELEASE_NOTES.md`, and `package.json`. These paths contain runtime entries, declarations, user guides, examples, and package metadata.
36
+
37
+ The package does not include tests, fixtures, coverage output, or the lockfile. npm installs the runtime dependency declared in `package.json`.
38
+
39
+ ## Versions and publication
40
+
41
+ The package uses numeric `MAJOR.MINOR.PATCH` versions. Each release tag follows `vMAJOR.MINOR.PATCH` and matches `package.json`.
42
+
43
+ The GitHub publication workflow tests each tagged commit with Node.js 26 before it publishes the package. It runs `npm test`.
44
+
45
+ npm adds provenance data that identifies the GitHub Actions build that published the package. The package is public on npm under `@eliware/mail-client`.
46
+
47
+ Read [release notes](../RELEASE_NOTES.md) for changes in each published version.
package/docs/usage.md CHANGED
@@ -18,6 +18,8 @@ Use a long-lived API token in trusted Node.js applications. Keep a different tok
18
18
 
19
19
  Use a short-lived browser token in browser code. The mail-web server keeps its long-lived token and requests a browser token from `POST /api/auth/token`. The mail-web server sends the short-lived token to the signed-in browser through its authenticated session.
20
20
 
21
+ The library does not read `MAIL_API_URL`, `MAIL_API_TOKEN`, or `MAIL_WEB_API_TOKEN`. The host application reads those values and passes them through `baseUrl` and `getAccessToken`. Read [package details](package.md) for each value's purpose and default.
22
+
21
23
  EliD sign-in belongs to mail-web. This package does not run OAuth flows and does not depend on `@eliware/elid-client`.
22
24
 
23
25
  ## Create a Node.js client
@@ -113,24 +115,25 @@ const events = browserMail.connectEvents({
113
115
  await events.ready;
114
116
  ```
115
117
 
116
- The server sends `{"type":"authenticated"}` before it sends events. The client resolves `ready` after it receives that frame. The client rejects `ready` if the first connection closes before authentication succeeds.
118
+ The server sends `{"type":"authenticated"}` before it sends events. The client resolves `ready` after it receives that frame. If a retryable failure occurs first, `ready` stays pending until authentication succeeds or retries stop.
117
119
 
118
120
  Events are notification signals. They can repeat and do not include complete message bodies or attachment bytes. Read current message data through the HTTP API. Make event handlers safe to run more than once.
119
121
 
120
122
  ## Process durable events
121
123
 
122
- Use a stable `consumerId` when the application must store progress on mail-server. Set `after` to a saved decimal cursor when processing must start from an earlier event.
124
+ Use a stable `consumerId` when the application must store progress on mail-server. The client sends it as `consumer_id` when it opens the WebSocket. The server resumes from the saved cursor for that consumer.
123
125
 
124
126
  ```js
125
127
  const events = browserMail.connectEvents({
126
128
  consumerId: "mail-discord-production",
127
- after: savedCursor,
128
129
  onEvent: handleEvent,
129
130
  onError: reportEventError,
130
131
  });
131
132
  ```
132
133
 
133
- The client runs one event handler at a time. After a handler succeeds, the client posts its cursor to the acknowledgement route. The client advances its cursor only after that request succeeds. If a handler or acknowledgement fails, the client reports the error, closes the socket, and stops automatic reconnects.
134
+ The client runs one event handler at a time. After a handler succeeds, the client posts its cursor to the acknowledgement route with the same consumer ID. The client advances its cursor only after that request succeeds. If a handler or acknowledgement fails, the client reports the error, closes the socket, and stops automatic reconnects.
135
+
136
+ Do not set `after` when you set `consumerId`. The server uses the durable consumer cursor for replay and rejects requests that include both values.
134
137
 
135
138
  Without `consumerId`, the client tracks the cursor in memory only. The client includes its current cursor when it reconnects. Store progress with `consumerId` when an application must continue after a new process starts.
136
139
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eliware/mail-client",
3
- "version": "15.0.2",
3
+ "version": "15.0.3",
4
4
  "type": "module",
5
5
  "description": "Mail client library for the Eliware mail platform.",
6
6
  "keywords": [
@@ -57,6 +57,8 @@ directives:
57
57
  - Reconnect safely and continue events from the last acknowledged cursor.
58
58
  - Retry WebSocket setup after token provider failures when automatic reconnect is enabled.
59
59
  - Let stable consumer IDs acknowledge processed event cursors through the HTTP API.
60
+ - Send a stable consumer ID as `consumer_id` when opening a durable WebSocket connection.
61
+ - Use the server-stored consumer cursor for durable WebSocket event replay.
60
62
  - Move durable cursors only after handlers and server acknowledgements succeed.
61
63
  - Tolerate repeated events and refresh current data through the HTTP API after notifications.
62
64
  - Let callers process events without RabbitMQ payloads as a client contract.
@@ -48,12 +48,13 @@ export function createEventConnection({
48
48
  }
49
49
 
50
50
  function scheduleReconnect(code) {
51
- if (stopped || !autoReconnect || code === 1000 || code === 1008) return;
51
+ if (stopped || !autoReconnect || code === 1000 || code === 1008) return false;
52
52
  const delay = Math.min(retryDelayMs * 2 ** attempt, maxReconnectDelayMs);
53
53
  attempt += 1;
54
54
  logs.reconnectScheduled(code, delay, attempt, cursor);
55
55
  timer = setTimeout(connect, delay);
56
56
  timer.unref?.();
57
+ return true;
57
58
  }
58
59
 
59
60
  const processEvent = createEventProcessor({
@@ -78,8 +79,7 @@ export function createEventConnection({
78
79
  if (stopped) return;
79
80
  logs.tokenProviderFailed(error);
80
81
  report(error);
81
- settleReady(error);
82
- scheduleReconnect(1006);
82
+ if (!scheduleReconnect(1006)) settleReady(error);
83
83
  return;
84
84
  }
85
85
  if (stopped) return;
@@ -93,7 +93,7 @@ export function createEventConnection({
93
93
  }
94
94
  try {
95
95
  socket = createWebSocketSession({
96
- url: socketUrl(baseUrl, cursor),
96
+ url: socketUrl(baseUrl, consumerId === undefined ? cursor : null, consumerId),
97
97
  token,
98
98
  WebSocketImpl,
99
99
  onAuthenticated: () => {
@@ -104,7 +104,7 @@ export function createEventConnection({
104
104
  },
105
105
  onEvent: (event) => {
106
106
  processing = processing
107
- .then(() => processEvent(event))
107
+ .then(() => (stopped ? undefined : processEvent(event)))
108
108
  .catch((error) => {
109
109
  logs.eventFailed(event, error);
110
110
  report(error);
@@ -115,9 +115,10 @@ export function createEventConnection({
115
115
  },
116
116
  onClose: (code) => {
117
117
  logs.closed(code, authenticated, cursor);
118
- if (!authenticated)
118
+ const reconnecting = scheduleReconnect(code);
119
+ if (!authenticated && !reconnecting) {
119
120
  settleReady(new Error(`WebSocket authentication closed with code ${code}`));
120
- scheduleReconnect(code);
121
+ }
121
122
  },
122
123
  onError: (error) => {
123
124
  logs.socketFailed(error);
@@ -1,6 +1,7 @@
1
- export function socketUrl(baseUrl, cursor) {
1
+ export function socketUrl(baseUrl, cursor, consumerId) {
2
2
  const url = new URL("/ws", baseUrl);
3
3
  url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
4
4
  if (cursor !== null) url.searchParams.set("after", cursor);
5
+ if (consumerId !== undefined) url.searchParams.set("consumer_id", consumerId);
5
6
  return url.toString();
6
7
  }
@@ -41,4 +41,7 @@ export function validateEventOptions({
41
41
  if (after !== undefined && !isValidCursor(after)) {
42
42
  throw new TypeError("after must be a decimal Snowflake cursor");
43
43
  }
44
+ if (after !== undefined && consumerId !== undefined) {
45
+ throw new TypeError("after and consumerId cannot be used together");
46
+ }
44
47
  }
@@ -16,7 +16,8 @@ export function createWebSocketSession({
16
16
  socket.send(JSON.stringify({ type: "authenticate", token }));
17
17
  });
18
18
  subscribe(socket, "message", (value, isBinary = false) => {
19
- if (isBinary) {
19
+ const data = value?.data;
20
+ if (isBinary || (typeof Blob !== "undefined" && data instanceof Blob)) {
20
21
  onError(new TypeError("WebSocket frames must use JSON text"));
21
22
  socket.close(1002, "JSON text required");
22
23
  return;