@postalsys/ee-client 1.2.0 → 1.2.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/README.md +6 -0
- package/index.js +55 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,6 +63,8 @@ const message = await client.loadMessage(messages[0].id);
|
|
|
63
63
|
- `confirmMethod` (function, optional): Custom confirm dialog method. Receives `(message, title, cancelText, okText)` parameters. Can be sync or async. Defaults to browser's `confirm()` with standard parameters.
|
|
64
64
|
- `alertMethod` (function, optional): Custom alert dialog method. Receives `(message, title, cancelText, okText)` parameters where `cancelText` is `null` for alerts. Can be sync or async. Defaults to browser's `alert()` with standard parameters.
|
|
65
65
|
|
|
66
|
+
**Note**: For session tokens (starting with `sess_`), the client automatically implements a keep-alive mechanism that pings the `/v1/account/{account}` endpoint every 5 minutes of inactivity to prevent token expiration.
|
|
67
|
+
|
|
66
68
|
### Methods
|
|
67
69
|
|
|
68
70
|
#### `loadFolders(): Promise<Folder[]>`
|
|
@@ -97,6 +99,10 @@ Send a new email message. The `to` parameter can be:
|
|
|
97
99
|
- An object with name and address: `{ name: 'John Doe', address: 'john@example.com' }`
|
|
98
100
|
- An array of strings or objects for multiple recipients
|
|
99
101
|
|
|
102
|
+
#### `destroy(): void`
|
|
103
|
+
|
|
104
|
+
Clean up the client instance, clearing any active timers (like the keep-alive timer for session tokens).
|
|
105
|
+
|
|
100
106
|
## Browser UI
|
|
101
107
|
|
|
102
108
|
When used in a browser with a container element, the client automatically creates a full email interface with:
|
package/index.js
CHANGED
|
@@ -17,6 +17,10 @@ export class EmailEngineClient {
|
|
|
17
17
|
this.nextPageCursor = null;
|
|
18
18
|
this.prevPageCursor = null;
|
|
19
19
|
|
|
20
|
+
// Keep-alive timer for sess_ tokens
|
|
21
|
+
this.keepAliveTimer = null;
|
|
22
|
+
this.lastActivity = Date.now();
|
|
23
|
+
|
|
20
24
|
// Get page size from localStorage or options or default
|
|
21
25
|
const savedPageSize =
|
|
22
26
|
typeof window !== 'undefined' && window.localStorage ? localStorage.getItem('ee-client-page-size') : null;
|
|
@@ -25,9 +29,15 @@ export class EmailEngineClient {
|
|
|
25
29
|
if (this.container) {
|
|
26
30
|
this.init();
|
|
27
31
|
}
|
|
32
|
+
|
|
33
|
+
// Start keep-alive timer for sess_ tokens
|
|
34
|
+
this._startKeepAliveTimer();
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
async apiRequest(method, endpoint, data = null) {
|
|
38
|
+
// Update activity timestamp for keep-alive
|
|
39
|
+
this._updateActivity();
|
|
40
|
+
|
|
31
41
|
const url = `${this.apiUrl}${endpoint}`;
|
|
32
42
|
const options = {
|
|
33
43
|
method: method,
|
|
@@ -1630,6 +1640,51 @@ export class EmailEngineClient {
|
|
|
1630
1640
|
console.error('Failed to auto-select inbox:', error);
|
|
1631
1641
|
});
|
|
1632
1642
|
}
|
|
1643
|
+
|
|
1644
|
+
_updateActivity() {
|
|
1645
|
+
this.lastActivity = Date.now();
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
_startKeepAliveTimer() {
|
|
1649
|
+
// Only start keep-alive for sess_ tokens
|
|
1650
|
+
if (!this.accessToken || !this.accessToken.startsWith('sess_')) {
|
|
1651
|
+
return;
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
// Clear existing timer if any
|
|
1655
|
+
if (this.keepAliveTimer) {
|
|
1656
|
+
clearInterval(this.keepAliveTimer);
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
// Check every minute if we need to ping
|
|
1660
|
+
this.keepAliveTimer = setInterval(() => {
|
|
1661
|
+
const now = Date.now();
|
|
1662
|
+
const idleTime = now - this.lastActivity;
|
|
1663
|
+
|
|
1664
|
+
// If idle for 5+ minutes, ping to keep token alive
|
|
1665
|
+
if (idleTime >= 5 * 60 * 1000) {
|
|
1666
|
+
this._keepTokenAlive();
|
|
1667
|
+
}
|
|
1668
|
+
}, 60 * 1000); // Check every minute
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
async _keepTokenAlive() {
|
|
1672
|
+
try {
|
|
1673
|
+
// Ping account endpoint to keep token alive
|
|
1674
|
+
await this.apiRequest('GET', `/v1/account/${this.account}`);
|
|
1675
|
+
console.debug('Keep-alive ping sent for sess_ token');
|
|
1676
|
+
} catch (error) {
|
|
1677
|
+
console.warn('Keep-alive ping failed:', error.message);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
destroy() {
|
|
1682
|
+
// Clean up keep-alive timer
|
|
1683
|
+
if (this.keepAliveTimer) {
|
|
1684
|
+
clearInterval(this.keepAliveTimer);
|
|
1685
|
+
this.keepAliveTimer = null;
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1633
1688
|
}
|
|
1634
1689
|
|
|
1635
1690
|
export function createEmailEngineClient(options) {
|