@postalsys/ee-client 1.2.0 → 1.3.0
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 +17 -0
- package/index.js +320 -6
- 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:
|
|
@@ -105,6 +111,7 @@ When used in a browser with a container element, the client automatically create
|
|
|
105
111
|
- Message list with pagination
|
|
106
112
|
- Message viewer with actions (mark as read/unread, delete, move)
|
|
107
113
|
- Responsive design
|
|
114
|
+
- Dark mode support with persistent preference
|
|
108
115
|
|
|
109
116
|
```html
|
|
110
117
|
<div id="email-client" style="height: 600px;"></div>
|
|
@@ -178,6 +185,16 @@ The library uses contextually appropriate titles and button texts:
|
|
|
178
185
|
|
|
179
186
|
Both methods can be synchronous or asynchronous and should return a boolean for confirm dialogs.
|
|
180
187
|
|
|
188
|
+
### Dark Mode
|
|
189
|
+
|
|
190
|
+
The email client includes built-in dark mode support with automatic persistence of user preference:
|
|
191
|
+
|
|
192
|
+
- **Toggle Button**: A moon/sun icon in the top-right corner toggles between light and dark modes
|
|
193
|
+
- **Persistent Preference**: Dark mode preference is saved to localStorage and restored on page reload
|
|
194
|
+
- **Complete Theme**: All UI components are styled for optimal readability in both light and dark modes
|
|
195
|
+
|
|
196
|
+
Dark mode is automatically initialized based on the saved preference when the client is created.
|
|
197
|
+
|
|
181
198
|
## License
|
|
182
199
|
|
|
183
200
|
MIT © Postal Systems OÜ
|
package/index.js
CHANGED
|
@@ -17,6 +17,16 @@ 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
|
+
|
|
24
|
+
// Dark mode state
|
|
25
|
+
this.darkMode = false;
|
|
26
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
27
|
+
this.darkMode = localStorage.getItem('ee-client-dark-mode') === 'true';
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
// Get page size from localStorage or options or default
|
|
21
31
|
const savedPageSize =
|
|
22
32
|
typeof window !== 'undefined' && window.localStorage ? localStorage.getItem('ee-client-page-size') : null;
|
|
@@ -25,9 +35,15 @@ export class EmailEngineClient {
|
|
|
25
35
|
if (this.container) {
|
|
26
36
|
this.init();
|
|
27
37
|
}
|
|
38
|
+
|
|
39
|
+
// Start keep-alive timer for sess_ tokens
|
|
40
|
+
this._startKeepAliveTimer();
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
async apiRequest(method, endpoint, data = null) {
|
|
44
|
+
// Update activity timestamp for keep-alive
|
|
45
|
+
this._updateActivity();
|
|
46
|
+
|
|
31
47
|
const url = `${this.apiUrl}${endpoint}`;
|
|
32
48
|
const options = {
|
|
33
49
|
method: method,
|
|
@@ -167,6 +183,15 @@ export class EmailEngineClient {
|
|
|
167
183
|
|
|
168
184
|
if (this.container) {
|
|
169
185
|
this.renderMessage();
|
|
186
|
+
|
|
187
|
+
// Scroll to top of the email client container
|
|
188
|
+
this.container.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
189
|
+
|
|
190
|
+
// Also scroll the window to ensure visibility
|
|
191
|
+
if (typeof window !== 'undefined') {
|
|
192
|
+
const containerTop = this.container.getBoundingClientRect().top + window.pageYOffset;
|
|
193
|
+
window.scrollTo({ top: containerTop, behavior: 'smooth' });
|
|
194
|
+
}
|
|
170
195
|
}
|
|
171
196
|
|
|
172
197
|
return this.currentMessage;
|
|
@@ -1025,6 +1050,219 @@ export class EmailEngineClient {
|
|
|
1025
1050
|
.ee-compose-cancel:hover {
|
|
1026
1051
|
background: #545b62;
|
|
1027
1052
|
}
|
|
1053
|
+
|
|
1054
|
+
/* Dark mode toggle button */
|
|
1055
|
+
.ee-dark-mode-toggle {
|
|
1056
|
+
position: absolute;
|
|
1057
|
+
top: 8px;
|
|
1058
|
+
right: 16px;
|
|
1059
|
+
background: #f8f9fa;
|
|
1060
|
+
border: 1px solid #dee2e6;
|
|
1061
|
+
border-radius: 3px;
|
|
1062
|
+
padding: 6px 10px;
|
|
1063
|
+
font-size: 12px;
|
|
1064
|
+
cursor: pointer;
|
|
1065
|
+
z-index: 100;
|
|
1066
|
+
transition: all 0.2s ease;
|
|
1067
|
+
display: flex;
|
|
1068
|
+
align-items: center;
|
|
1069
|
+
justify-content: center;
|
|
1070
|
+
color: #495057;
|
|
1071
|
+
font-weight: 500;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
.ee-dark-mode-toggle:hover {
|
|
1075
|
+
background: #e9ecef;
|
|
1076
|
+
border-color: #adb5bd;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
.ee-dark-mode-icon {
|
|
1080
|
+
font-size: 14px;
|
|
1081
|
+
line-height: 1;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
/* Dark mode styles */
|
|
1085
|
+
.ee-dark-mode {
|
|
1086
|
+
background: #1a1a1a;
|
|
1087
|
+
color: #e0e0e0;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
.ee-dark-mode .ee-dark-mode-toggle {
|
|
1091
|
+
background: #333;
|
|
1092
|
+
border-color: #444;
|
|
1093
|
+
color: #e0e0e0;
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
.ee-dark-mode .ee-dark-mode-toggle:hover {
|
|
1097
|
+
background: #444;
|
|
1098
|
+
border-color: #555;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
.ee-dark-mode .ee-sidebar {
|
|
1102
|
+
background: #202020;
|
|
1103
|
+
border-color: #333;
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
.ee-dark-mode .ee-folder-item {
|
|
1107
|
+
border-color: #333;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
.ee-dark-mode .ee-folder-item:hover {
|
|
1111
|
+
background: #2a2a2a;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
.ee-dark-mode .ee-folder-item.active {
|
|
1115
|
+
background: #0056b3;
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
.ee-dark-mode .ee-message-list {
|
|
1119
|
+
background: #202020;
|
|
1120
|
+
border-color: #333;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
.ee-dark-mode .ee-message-item {
|
|
1124
|
+
border-color: #333;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
.ee-dark-mode .ee-message-item:hover {
|
|
1128
|
+
background: #2a2a2a;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
.ee-dark-mode .ee-message-item.active {
|
|
1132
|
+
background: #1a3d5c;
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
.ee-dark-mode .ee-message-date,
|
|
1136
|
+
.ee-dark-mode .ee-message-preview,
|
|
1137
|
+
.ee-dark-mode .ee-attachment-indicator {
|
|
1138
|
+
color: #999;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
.ee-dark-mode .ee-pane-header {
|
|
1142
|
+
background: linear-gradient(to bottom, #2a2a2a, #252525);
|
|
1143
|
+
border-color: #333;
|
|
1144
|
+
color: #e0e0e0;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
.ee-dark-mode .ee-pane-title {
|
|
1148
|
+
color: #e0e0e0;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
.ee-dark-mode .ee-page-size-label {
|
|
1152
|
+
color: #e0e0e0;
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
.ee-dark-mode .ee-message-viewer {
|
|
1156
|
+
background: #1a1a1a;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
.ee-dark-mode .ee-message-actions {
|
|
1160
|
+
background: linear-gradient(to bottom, #2a2a2a, #252525);
|
|
1161
|
+
border-color: #333;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
.ee-dark-mode .ee-button {
|
|
1165
|
+
background: #333;
|
|
1166
|
+
border-color: #444;
|
|
1167
|
+
color: #e0e0e0;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
.ee-dark-mode .ee-button:hover {
|
|
1171
|
+
background: #444;
|
|
1172
|
+
border-color: #555;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
.ee-dark-mode .ee-button:disabled {
|
|
1176
|
+
background: #222;
|
|
1177
|
+
color: #666;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
.ee-dark-mode select {
|
|
1181
|
+
background: #2a2a2a;
|
|
1182
|
+
border-color: #444;
|
|
1183
|
+
color: #e0e0e0;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
.ee-dark-mode .ee-message-content {
|
|
1187
|
+
background: #1a1a1a;
|
|
1188
|
+
color: #e0e0e0;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
.ee-dark-mode .ee-attachments {
|
|
1192
|
+
background: #252525;
|
|
1193
|
+
border-color: #333;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
.ee-dark-mode .ee-attachment-item {
|
|
1197
|
+
background: #2a2a2a;
|
|
1198
|
+
border-color: #333;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
.ee-dark-mode .ee-attachment-item:hover {
|
|
1202
|
+
background: #333;
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
.ee-dark-mode .ee-loading,
|
|
1206
|
+
.ee-dark-mode .ee-empty-state,
|
|
1207
|
+
.ee-dark-mode .ee-error {
|
|
1208
|
+
color: #999;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
.ee-dark-mode .ee-pagination {
|
|
1212
|
+
background: #252525;
|
|
1213
|
+
border-color: #333;
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
.ee-dark-mode .ee-compose-button {
|
|
1217
|
+
background: #0056b3;
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
.ee-dark-mode .ee-compose-modal {
|
|
1221
|
+
background: rgba(0, 0, 0, 0.7);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
.ee-dark-mode .ee-compose-content {
|
|
1225
|
+
background: #202020;
|
|
1226
|
+
color: #e0e0e0;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
.ee-dark-mode .ee-compose-header {
|
|
1230
|
+
background: linear-gradient(to bottom, #2a2a2a, #252525);
|
|
1231
|
+
border-color: #333;
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
.ee-dark-mode .ee-compose-close {
|
|
1235
|
+
color: #999;
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
.ee-dark-mode .ee-compose-close:hover {
|
|
1239
|
+
color: #fff;
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
.ee-dark-mode .ee-compose-input,
|
|
1243
|
+
.ee-dark-mode .ee-compose-textarea {
|
|
1244
|
+
background: #1a1a1a;
|
|
1245
|
+
border-color: #444;
|
|
1246
|
+
color: #e0e0e0;
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
.ee-dark-mode .ee-compose-input:focus,
|
|
1250
|
+
.ee-dark-mode .ee-compose-textarea:focus {
|
|
1251
|
+
border-color: #0056b3;
|
|
1252
|
+
box-shadow: 0 0 0 2px rgba(0,86,179,0.2);
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
.ee-dark-mode .ee-compose-actions {
|
|
1256
|
+
border-color: #333;
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
.ee-dark-mode .ee-compose-cancel {
|
|
1260
|
+
background: #444;
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
.ee-dark-mode .ee-compose-cancel:hover {
|
|
1264
|
+
background: #555;
|
|
1265
|
+
}
|
|
1028
1266
|
`;
|
|
1029
1267
|
document.head.appendChild(style);
|
|
1030
1268
|
}
|
|
@@ -1371,11 +1609,7 @@ export class EmailEngineClient {
|
|
|
1371
1609
|
});
|
|
1372
1610
|
});
|
|
1373
1611
|
|
|
1374
|
-
//
|
|
1375
|
-
const messageContent = viewer.querySelector('.ee-message-content');
|
|
1376
|
-
if (messageContent) {
|
|
1377
|
-
messageContent.scrollTop = 0;
|
|
1378
|
-
}
|
|
1612
|
+
// Message content scrolling is now handled in loadMessage method
|
|
1379
1613
|
}
|
|
1380
1614
|
|
|
1381
1615
|
createLayout() {
|
|
@@ -1384,7 +1618,10 @@ export class EmailEngineClient {
|
|
|
1384
1618
|
}
|
|
1385
1619
|
|
|
1386
1620
|
this.container.innerHTML = `
|
|
1387
|
-
<div class="ee-client">
|
|
1621
|
+
<div class="ee-client${this.darkMode ? ' ee-dark-mode' : ''}">
|
|
1622
|
+
<button class="ee-dark-mode-toggle" title="Toggle dark mode">
|
|
1623
|
+
<span class="ee-dark-mode-icon">${this.darkMode ? '☀️' : '🌙'}</span>
|
|
1624
|
+
</button>
|
|
1388
1625
|
<div class="ee-sidebar">
|
|
1389
1626
|
<div class="ee-pane-header">
|
|
1390
1627
|
<span class="ee-pane-title">Folders</span>
|
|
@@ -1616,6 +1853,13 @@ export class EmailEngineClient {
|
|
|
1616
1853
|
|
|
1617
1854
|
this.createStyles();
|
|
1618
1855
|
this.createLayout();
|
|
1856
|
+
|
|
1857
|
+
// Set up dark mode toggle
|
|
1858
|
+
const toggleBtn = this.container.querySelector('.ee-dark-mode-toggle');
|
|
1859
|
+
if (toggleBtn) {
|
|
1860
|
+
toggleBtn.addEventListener('click', () => this.toggleDarkMode());
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1619
1863
|
this.loadFolders()
|
|
1620
1864
|
.then(() => {
|
|
1621
1865
|
const inbox =
|
|
@@ -1630,6 +1874,76 @@ export class EmailEngineClient {
|
|
|
1630
1874
|
console.error('Failed to auto-select inbox:', error);
|
|
1631
1875
|
});
|
|
1632
1876
|
}
|
|
1877
|
+
|
|
1878
|
+
_updateActivity() {
|
|
1879
|
+
this.lastActivity = Date.now();
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
_startKeepAliveTimer() {
|
|
1883
|
+
// Only start keep-alive for sess_ tokens
|
|
1884
|
+
if (!this.accessToken || !this.accessToken.startsWith('sess_')) {
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
// Clear existing timer if any
|
|
1889
|
+
if (this.keepAliveTimer) {
|
|
1890
|
+
clearInterval(this.keepAliveTimer);
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
// Check every minute if we need to ping
|
|
1894
|
+
this.keepAliveTimer = setInterval(() => {
|
|
1895
|
+
const now = Date.now();
|
|
1896
|
+
const idleTime = now - this.lastActivity;
|
|
1897
|
+
|
|
1898
|
+
// If idle for 5+ minutes, ping to keep token alive
|
|
1899
|
+
if (idleTime >= 5 * 60 * 1000) {
|
|
1900
|
+
this._keepTokenAlive();
|
|
1901
|
+
}
|
|
1902
|
+
}, 60 * 1000); // Check every minute
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
async _keepTokenAlive() {
|
|
1906
|
+
try {
|
|
1907
|
+
// Ping account endpoint to keep token alive
|
|
1908
|
+
await this.apiRequest('GET', `/v1/account/${this.account}`);
|
|
1909
|
+
console.debug('Keep-alive ping sent for sess_ token');
|
|
1910
|
+
} catch (error) {
|
|
1911
|
+
console.warn('Keep-alive ping failed:', error.message);
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
toggleDarkMode() {
|
|
1916
|
+
this.darkMode = !this.darkMode;
|
|
1917
|
+
|
|
1918
|
+
// Save preference
|
|
1919
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
1920
|
+
localStorage.setItem('ee-client-dark-mode', this.darkMode.toString());
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1923
|
+
// Update UI
|
|
1924
|
+
const client = this.container.querySelector('.ee-client');
|
|
1925
|
+
if (client) {
|
|
1926
|
+
if (this.darkMode) {
|
|
1927
|
+
client.classList.add('ee-dark-mode');
|
|
1928
|
+
} else {
|
|
1929
|
+
client.classList.remove('ee-dark-mode');
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
// Update toggle button icon
|
|
1934
|
+
const icon = this.container.querySelector('.ee-dark-mode-icon');
|
|
1935
|
+
if (icon) {
|
|
1936
|
+
icon.textContent = this.darkMode ? '☀️' : '🌙';
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
destroy() {
|
|
1941
|
+
// Clean up keep-alive timer
|
|
1942
|
+
if (this.keepAliveTimer) {
|
|
1943
|
+
clearInterval(this.keepAliveTimer);
|
|
1944
|
+
this.keepAliveTimer = null;
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1633
1947
|
}
|
|
1634
1948
|
|
|
1635
1949
|
export function createEmailEngineClient(options) {
|