@postalsys/ee-client 1.8.2 → 1.9.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 +2 -0
- package/index.d.ts +15 -6
- package/index.js +222 -66
- package/package.json +16 -9
package/README.md
CHANGED
|
@@ -160,6 +160,8 @@ Load a page of messages from a folder. Pass `nextPageCursor` / `prevPageCursor`
|
|
|
160
160
|
|
|
161
161
|
Load a single message. HTML is requested with `webSafeHtml=true`, so EmailEngine returns it pre-processed with inline images embedded for safe display, and the message is marked as seen. Web-safe HTML also folds quoted thread history (reply history, forwarded content, disclaimers) into a `<details class="ee-collapsed-thread">` element - see [Quoted thread history](#quoted-thread-history).
|
|
162
162
|
|
|
163
|
+
When the message carries a one-time passcode (the `otp` field EmailEngine 2.87+ reads from an `OTP-Token` header), the viewer shows a "Code requested" box above the body with the code and a Copy code button. The site the code is for is named only when EmailEngine reports the origin as `authenticated`, since the header itself proves nothing about the sender.
|
|
164
|
+
|
|
163
165
|
### `markAsRead(messageId: string, seen?: boolean): Promise<boolean>`
|
|
164
166
|
|
|
165
167
|
Add or remove the `\Seen` flag. Pass `false` to mark as unread.
|
package/index.d.ts
CHANGED
|
@@ -38,6 +38,15 @@ export interface Attachment {
|
|
|
38
38
|
size?: number;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/** One-time passcode of a message, from its OTP-Token header (EmailEngine 2.87+, experimental) */
|
|
42
|
+
export interface MessageOtp {
|
|
43
|
+
code: string;
|
|
44
|
+
/** The origin the passcode is bound to, e.g. "https://example.com" */
|
|
45
|
+
origin: string;
|
|
46
|
+
/** Whether the receiving server vouches for the origin. The site is named in the UI only when true */
|
|
47
|
+
authenticated: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
41
50
|
export interface Message {
|
|
42
51
|
id: string;
|
|
43
52
|
subject?: string;
|
|
@@ -52,6 +61,7 @@ export interface Message {
|
|
|
52
61
|
intro?: string;
|
|
53
62
|
text?: MessageText;
|
|
54
63
|
attachments?: Attachment[];
|
|
64
|
+
otp?: MessageOtp;
|
|
55
65
|
}
|
|
56
66
|
|
|
57
67
|
export interface MessageListResponse {
|
|
@@ -85,12 +95,7 @@ export interface SubmitDraftOptions {
|
|
|
85
95
|
* `(message, title, cancelText, okText)`; `cancelText` is `null` for alerts.
|
|
86
96
|
* May be synchronous or asynchronous. Confirm handlers should resolve to a boolean.
|
|
87
97
|
*/
|
|
88
|
-
export type DialogMethod = (
|
|
89
|
-
message: string,
|
|
90
|
-
title?: string,
|
|
91
|
-
cancelText?: string | null,
|
|
92
|
-
okText?: string
|
|
93
|
-
) => boolean | void | Promise<boolean | void>;
|
|
98
|
+
export type DialogMethod = (message: string, title?: string, cancelText?: string | null, okText?: string) => boolean | void | Promise<boolean | void>;
|
|
94
99
|
|
|
95
100
|
export interface EmailEngineClientOptions {
|
|
96
101
|
apiUrl?: string;
|
|
@@ -143,6 +148,10 @@ export declare class EmailEngineClient {
|
|
|
143
148
|
formatDate(dateStr: string): string;
|
|
144
149
|
formatFileSize(bytes: number): string;
|
|
145
150
|
escapeHtml(value: unknown): string;
|
|
151
|
+
/** HTML of the "Code requested" box for a message's one-time passcode, empty without one */
|
|
152
|
+
renderOtpBox(otp?: MessageOtp): string;
|
|
153
|
+
/** Copies text to the clipboard, falling back to execCommand outside a secure context */
|
|
154
|
+
copyText(text: string): Promise<boolean>;
|
|
146
155
|
createStyles(): void;
|
|
147
156
|
buildFolderTree(): FolderTreeEntry[];
|
|
148
157
|
renderFolderList(): void;
|
package/index.js
CHANGED
|
@@ -79,16 +79,11 @@ export class EmailEngineClient {
|
|
|
79
79
|
// A containerId that matches nothing is almost always a typo; warn
|
|
80
80
|
// rather than silently degrading to a UI-less, API-only client.
|
|
81
81
|
if (!this.container) {
|
|
82
|
-
console.warn(
|
|
83
|
-
`EmailEngineClient: no element found for containerId "${options.containerId}"; UI rendering disabled`
|
|
84
|
-
);
|
|
82
|
+
console.warn(`EmailEngineClient: no element found for containerId "${options.containerId}"; UI rendering disabled`);
|
|
85
83
|
}
|
|
86
84
|
}
|
|
87
|
-
this.confirmMethod =
|
|
88
|
-
|
|
89
|
-
((message, _title = 'Confirm', _cancelText = 'Cancel', _okText = 'OK') => confirm(message));
|
|
90
|
-
this.alertMethod =
|
|
91
|
-
options.alertMethod || ((message, _title = 'Notice', _cancelText = null, _okText = 'OK') => alert(message));
|
|
85
|
+
this.confirmMethod = options.confirmMethod || ((message, _title = 'Confirm', _cancelText = 'Cancel', _okText = 'OK') => confirm(message));
|
|
86
|
+
this.alertMethod = options.alertMethod || ((message, _title = 'Notice', _cancelText = null, _okText = 'OK') => alert(message));
|
|
92
87
|
|
|
93
88
|
this.currentFolder = null;
|
|
94
89
|
this.currentMessage = null;
|
|
@@ -124,8 +119,7 @@ export class EmailEngineClient {
|
|
|
124
119
|
this.styleNonce = typeof options.styleNonce === 'string' && options.styleNonce ? options.styleNonce : null;
|
|
125
120
|
|
|
126
121
|
// Get page size from localStorage or options or default
|
|
127
|
-
const savedPageSize =
|
|
128
|
-
typeof window !== 'undefined' && window.localStorage ? localStorage.getItem('ee-client-page-size') : null;
|
|
122
|
+
const savedPageSize = typeof window !== 'undefined' && window.localStorage ? localStorage.getItem('ee-client-page-size') : null;
|
|
129
123
|
const requestedPageSize = savedPageSize ? parseInt(savedPageSize, 10) : parseInt(options.pageSize, 10);
|
|
130
124
|
this.pageSize = requestedPageSize > 0 ? requestedPageSize : 20;
|
|
131
125
|
|
|
@@ -151,16 +145,14 @@ export class EmailEngineClient {
|
|
|
151
145
|
try {
|
|
152
146
|
const nodeFetch = await import('node-fetch');
|
|
153
147
|
fetchFn = nodeFetch.default;
|
|
154
|
-
} catch
|
|
148
|
+
} catch {
|
|
155
149
|
// node-fetch is not installed; the guard below reports it
|
|
156
150
|
}
|
|
157
151
|
}
|
|
158
152
|
|
|
159
153
|
if (!fetchFn) {
|
|
160
154
|
// Either node-fetch is missing or it exposed no callable default export
|
|
161
|
-
throw new Error(
|
|
162
|
-
'fetch is not available. In Node.js environments, please install node-fetch: npm install node-fetch'
|
|
163
|
-
);
|
|
155
|
+
throw new Error('fetch is not available. In Node.js environments, please install node-fetch: npm install node-fetch');
|
|
164
156
|
}
|
|
165
157
|
|
|
166
158
|
try {
|
|
@@ -183,7 +175,7 @@ export class EmailEngineClient {
|
|
|
183
175
|
let details;
|
|
184
176
|
try {
|
|
185
177
|
details = await response.json();
|
|
186
|
-
} catch
|
|
178
|
+
} catch {
|
|
187
179
|
// Not a JSON body - the status line is all there is to go on
|
|
188
180
|
details = { message: response.statusText };
|
|
189
181
|
}
|
|
@@ -196,7 +188,7 @@ export class EmailEngineClient {
|
|
|
196
188
|
|
|
197
189
|
async apiRequest(method, endpoint, data = null) {
|
|
198
190
|
const options = {
|
|
199
|
-
method
|
|
191
|
+
method,
|
|
200
192
|
headers: {
|
|
201
193
|
'Content-Type': 'application/json',
|
|
202
194
|
...this._authHeaders()
|
|
@@ -253,7 +245,7 @@ export class EmailEngineClient {
|
|
|
253
245
|
this._setPaneHtml('.ee-message-list', '<div class="ee-loading">Loading messages...</div>');
|
|
254
246
|
|
|
255
247
|
try {
|
|
256
|
-
const params = new URLSearchParams({ path
|
|
248
|
+
const params = new URLSearchParams({ path, pageSize: this.pageSize });
|
|
257
249
|
if (cursor) {
|
|
258
250
|
params.set('cursor', cursor);
|
|
259
251
|
}
|
|
@@ -280,9 +272,7 @@ export class EmailEngineClient {
|
|
|
280
272
|
};
|
|
281
273
|
} catch (error) {
|
|
282
274
|
console.error('Failed to load messages:', error);
|
|
283
|
-
this._renderPaneError('.ee-message-list', 'Messages unavailable', error, () =>
|
|
284
|
-
this._fireAndForget(this.loadMessages(path, cursor))
|
|
285
|
-
);
|
|
275
|
+
this._renderPaneError('.ee-message-list', 'Messages unavailable', error, () => this._fireAndForget(this.loadMessages(path, cursor)));
|
|
286
276
|
throw error;
|
|
287
277
|
}
|
|
288
278
|
}
|
|
@@ -324,9 +314,7 @@ export class EmailEngineClient {
|
|
|
324
314
|
return this.currentMessage;
|
|
325
315
|
} catch (error) {
|
|
326
316
|
console.error('Failed to load message:', error);
|
|
327
|
-
this._renderPaneError('.ee-message-viewer', 'Message unavailable', error, () =>
|
|
328
|
-
this._fireAndForget(this.loadMessage(messageId))
|
|
329
|
-
);
|
|
317
|
+
this._renderPaneError('.ee-message-viewer', 'Message unavailable', error, () => this._fireAndForget(this.loadMessage(messageId)));
|
|
330
318
|
throw error;
|
|
331
319
|
}
|
|
332
320
|
}
|
|
@@ -408,9 +396,7 @@ export class EmailEngineClient {
|
|
|
408
396
|
}
|
|
409
397
|
|
|
410
398
|
_normalizeRecipients(to) {
|
|
411
|
-
return Array.isArray(to)
|
|
412
|
-
? to.map(addr => (typeof addr === 'string' ? { address: addr } : addr))
|
|
413
|
-
: [typeof to === 'string' ? { address: to } : to];
|
|
399
|
+
return Array.isArray(to) ? to.map(addr => (typeof addr === 'string' ? { address: addr } : addr)) : [typeof to === 'string' ? { address: to } : to];
|
|
414
400
|
}
|
|
415
401
|
|
|
416
402
|
// Account details (name, email address) fetched once and cached for the lifetime
|
|
@@ -426,8 +412,8 @@ export class EmailEngineClient {
|
|
|
426
412
|
try {
|
|
427
413
|
const messageData = {
|
|
428
414
|
to: this._normalizeRecipients(to),
|
|
429
|
-
subject
|
|
430
|
-
text
|
|
415
|
+
subject,
|
|
416
|
+
text
|
|
431
417
|
};
|
|
432
418
|
|
|
433
419
|
const response = await this.apiRequest('POST', `${this._accountPath()}/submit`, messageData);
|
|
@@ -451,8 +437,8 @@ export class EmailEngineClient {
|
|
|
451
437
|
const messageData = {
|
|
452
438
|
path: draftsFolder.path,
|
|
453
439
|
flags: ['\\Draft'],
|
|
454
|
-
subject
|
|
455
|
-
text
|
|
440
|
+
subject,
|
|
441
|
+
text
|
|
456
442
|
};
|
|
457
443
|
|
|
458
444
|
const recipients = to ? this._normalizeRecipients(to) : [];
|
|
@@ -467,7 +453,7 @@ export class EmailEngineClient {
|
|
|
467
453
|
if (accountInfo && accountInfo.email) {
|
|
468
454
|
messageData.from = { name: accountInfo.name || '', address: accountInfo.email };
|
|
469
455
|
}
|
|
470
|
-
} catch
|
|
456
|
+
} catch {
|
|
471
457
|
// Non-fatal: the draft is saved without a From header
|
|
472
458
|
}
|
|
473
459
|
|
|
@@ -649,6 +635,84 @@ export class EmailEngineClient {
|
|
|
649
635
|
return Math.round((bytes / Math.pow(1024, i)) * 100) / 100 + ' ' + sizes[i];
|
|
650
636
|
}
|
|
651
637
|
|
|
638
|
+
/**
|
|
639
|
+
* Markup for the "Code requested" box of a message that carries a one-time passcode
|
|
640
|
+
* (EmailEngine's `otp` field, from the OTP-Token header). The site the code is for is named
|
|
641
|
+
* only when EmailEngine reports the origin as authenticated: the header itself is not, and
|
|
642
|
+
* anyone can send a message claiming a code for any site.
|
|
643
|
+
*
|
|
644
|
+
* @param {{code: string, origin: string, authenticated?: boolean}} [otp]
|
|
645
|
+
* @returns {string} HTML, or an empty string when there is no passcode
|
|
646
|
+
*/
|
|
647
|
+
renderOtpBox(otp) {
|
|
648
|
+
if (!otp || typeof otp.code !== 'string' || !otp.code) {
|
|
649
|
+
return '';
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// one tile per character for a code a person reads off and types, as Gmail does
|
|
653
|
+
const code = /^[A-Za-z0-9]{1,10}$/.test(otp.code)
|
|
654
|
+
? Array.from(otp.code, ch => `<span class="ee-otp-char">${this.escapeHtml(ch)}</span>`).join('')
|
|
655
|
+
: `<span class="ee-otp-text">${this.escapeHtml(otp.code)}</span>`;
|
|
656
|
+
|
|
657
|
+
let site = '';
|
|
658
|
+
if (otp.authenticated) {
|
|
659
|
+
try {
|
|
660
|
+
site = new URL(otp.origin).host;
|
|
661
|
+
} catch {
|
|
662
|
+
// leave the site out rather than show a value that does not parse
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
return `
|
|
667
|
+
<div class="ee-otp" role="region" aria-label="Code requested">
|
|
668
|
+
<div class="ee-otp-title">Code requested${site ? ` for <span class="ee-otp-site">${this.escapeHtml(site)}</span>` : ''}</div>
|
|
669
|
+
<div class="ee-otp-code" aria-label="${this.escapeHtml(otp.code)}">${code}</div>
|
|
670
|
+
<div class="ee-otp-actions">
|
|
671
|
+
<button type="button" class="ee-button ee-otp-copy" data-action="copy-otp">Copy code</button>
|
|
672
|
+
<span class="ee-otp-status" aria-live="polite"></span>
|
|
673
|
+
</div>
|
|
674
|
+
${site ? '' : '<div class="ee-otp-note">The sender of this code could not be verified</div>'}
|
|
675
|
+
</div>
|
|
676
|
+
`;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Copies text to the clipboard. The Clipboard API needs a secure context, so a page served
|
|
681
|
+
* over plain http falls back to a selected textarea and execCommand
|
|
682
|
+
*
|
|
683
|
+
* @param {string} text
|
|
684
|
+
* @returns {Promise<boolean>} Whether the text was copied
|
|
685
|
+
*/
|
|
686
|
+
async copyText(text) {
|
|
687
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard && typeof window !== 'undefined' && window.isSecureContext) {
|
|
688
|
+
try {
|
|
689
|
+
await navigator.clipboard.writeText(text);
|
|
690
|
+
return true;
|
|
691
|
+
} catch {
|
|
692
|
+
// fall through to the legacy path
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
if (typeof document === 'undefined') {
|
|
697
|
+
return false;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
const textarea = document.createElement('textarea');
|
|
701
|
+
textarea.value = text;
|
|
702
|
+
textarea.setAttribute('readonly', '');
|
|
703
|
+
textarea.style.position = 'fixed';
|
|
704
|
+
textarea.style.top = '-1000px';
|
|
705
|
+
document.body.appendChild(textarea);
|
|
706
|
+
textarea.select();
|
|
707
|
+
try {
|
|
708
|
+
return document.execCommand('copy');
|
|
709
|
+
} catch {
|
|
710
|
+
return false;
|
|
711
|
+
} finally {
|
|
712
|
+
textarea.remove();
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
652
716
|
escapeHtml(value) {
|
|
653
717
|
if (value === null || value === undefined) {
|
|
654
718
|
return '';
|
|
@@ -660,7 +724,7 @@ export class EmailEngineClient {
|
|
|
660
724
|
_authHeaders() {
|
|
661
725
|
const headers = {};
|
|
662
726
|
if (this.accessToken) {
|
|
663
|
-
headers
|
|
727
|
+
headers.Authorization = `Bearer ${this.accessToken}`;
|
|
664
728
|
}
|
|
665
729
|
return headers;
|
|
666
730
|
}
|
|
@@ -712,12 +776,7 @@ export class EmailEngineClient {
|
|
|
712
776
|
this._saveBlob(blob, filename);
|
|
713
777
|
} catch (error) {
|
|
714
778
|
console.error('Failed to download attachment:', error);
|
|
715
|
-
this.alertMethod(
|
|
716
|
-
this._errorMessage(error, 'Failed to download attachment. Please try again.'),
|
|
717
|
-
'Download Error',
|
|
718
|
-
null,
|
|
719
|
-
'OK'
|
|
720
|
-
);
|
|
779
|
+
this.alertMethod(this._errorMessage(error, 'Failed to download attachment. Please try again.'), 'Download Error', null, 'OK');
|
|
721
780
|
}
|
|
722
781
|
}
|
|
723
782
|
|
|
@@ -737,12 +796,7 @@ export class EmailEngineClient {
|
|
|
737
796
|
this._saveBlob(blob, filename);
|
|
738
797
|
} catch (error) {
|
|
739
798
|
console.error('Failed to download original message:', error);
|
|
740
|
-
this.alertMethod(
|
|
741
|
-
this._errorMessage(error, 'Failed to download original message. Please try again.'),
|
|
742
|
-
'Download Error',
|
|
743
|
-
null,
|
|
744
|
-
'OK'
|
|
745
|
-
);
|
|
799
|
+
this.alertMethod(this._errorMessage(error, 'Failed to download original message. Please try again.'), 'Download Error', null, 'OK');
|
|
746
800
|
}
|
|
747
801
|
}
|
|
748
802
|
|
|
@@ -1006,6 +1060,82 @@ export class EmailEngineClient {
|
|
|
1006
1060
|
.ee-message-meta-row {
|
|
1007
1061
|
margin-bottom: 4px;
|
|
1008
1062
|
}
|
|
1063
|
+
|
|
1064
|
+
.ee-otp {
|
|
1065
|
+
margin-bottom: 16px;
|
|
1066
|
+
padding: 14px 16px;
|
|
1067
|
+
background: #eef3fb;
|
|
1068
|
+
border-radius: 8px;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
.ee-otp-title {
|
|
1072
|
+
font-size: 13px;
|
|
1073
|
+
color: #444;
|
|
1074
|
+
margin-bottom: 10px;
|
|
1075
|
+
overflow-wrap: anywhere;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
.ee-otp-site {
|
|
1079
|
+
font-weight: 600;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
.ee-otp-code {
|
|
1083
|
+
display: flex;
|
|
1084
|
+
flex-wrap: wrap;
|
|
1085
|
+
gap: 6px;
|
|
1086
|
+
margin-bottom: 12px;
|
|
1087
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
1088
|
+
font-size: 22px;
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
.ee-otp-char {
|
|
1092
|
+
display: inline-flex;
|
|
1093
|
+
align-items: center;
|
|
1094
|
+
justify-content: center;
|
|
1095
|
+
min-width: 32px;
|
|
1096
|
+
height: 40px;
|
|
1097
|
+
background: white;
|
|
1098
|
+
border-radius: 6px;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
.ee-otp-text {
|
|
1102
|
+
padding: 6px 10px;
|
|
1103
|
+
background: white;
|
|
1104
|
+
border-radius: 6px;
|
|
1105
|
+
font-size: 16px;
|
|
1106
|
+
overflow-wrap: anywhere;
|
|
1107
|
+
user-select: all;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
.ee-otp-actions {
|
|
1111
|
+
display: flex;
|
|
1112
|
+
align-items: center;
|
|
1113
|
+
gap: 10px;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
.ee-otp .ee-otp-copy {
|
|
1117
|
+
height: 32px;
|
|
1118
|
+
padding: 0 16px;
|
|
1119
|
+
font-size: 13px;
|
|
1120
|
+
background: #007bff;
|
|
1121
|
+
border-color: #007bff;
|
|
1122
|
+
color: white;
|
|
1123
|
+
border-radius: 16px;
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
.ee-otp .ee-otp-copy:hover:not(:disabled) {
|
|
1127
|
+
background: #0069d9;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
.ee-otp-status,
|
|
1131
|
+
.ee-otp-note {
|
|
1132
|
+
font-size: 12px;
|
|
1133
|
+
color: #666;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
.ee-otp-note {
|
|
1137
|
+
margin-top: 10px;
|
|
1138
|
+
}
|
|
1009
1139
|
|
|
1010
1140
|
.ee-message-meta-label {
|
|
1011
1141
|
display: inline-block;
|
|
@@ -1556,6 +1686,31 @@ export class EmailEngineClient {
|
|
|
1556
1686
|
color: #f0a5a5;
|
|
1557
1687
|
}
|
|
1558
1688
|
|
|
1689
|
+
.ee-dark-mode .ee-otp {
|
|
1690
|
+
background: #23303f;
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
.ee-dark-mode .ee-otp-title {
|
|
1694
|
+
color: #ccc;
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
.ee-dark-mode .ee-otp-char,
|
|
1698
|
+
.ee-dark-mode .ee-otp-text {
|
|
1699
|
+
background: #1a1a1a;
|
|
1700
|
+
color: #e0e0e0;
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
.ee-dark-mode .ee-otp .ee-otp-copy {
|
|
1704
|
+
background: #0056b3;
|
|
1705
|
+
border-color: #0056b3;
|
|
1706
|
+
color: white;
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
.ee-dark-mode .ee-otp-status,
|
|
1710
|
+
.ee-dark-mode .ee-otp-note {
|
|
1711
|
+
color: #999;
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1559
1714
|
.ee-dark-mode .ee-pagination {
|
|
1560
1715
|
background: #252525;
|
|
1561
1716
|
border-color: #333;
|
|
@@ -1844,7 +1999,7 @@ export class EmailEngineClient {
|
|
|
1844
1999
|
const pageSizeSelect = messageList.querySelector('[data-action="page-size"]');
|
|
1845
2000
|
if (pageSizeSelect) {
|
|
1846
2001
|
pageSizeSelect.addEventListener('change', e => {
|
|
1847
|
-
this.pageSize = parseInt(e.target.value);
|
|
2002
|
+
this.pageSize = parseInt(e.target.value, 10);
|
|
1848
2003
|
// Save to localStorage
|
|
1849
2004
|
if (typeof window !== 'undefined' && window.localStorage) {
|
|
1850
2005
|
localStorage.setItem('ee-client-page-size', this.pageSize.toString());
|
|
@@ -1918,6 +2073,7 @@ export class EmailEngineClient {
|
|
|
1918
2073
|
${this.escapeHtml(msg.subject || '(no subject)')}
|
|
1919
2074
|
</div>
|
|
1920
2075
|
</div>
|
|
2076
|
+
${this.renderOtpBox(msg.otp)}
|
|
1921
2077
|
<div class="ee-message-body"></div>
|
|
1922
2078
|
${
|
|
1923
2079
|
msg.attachments && msg.attachments.length > 0
|
|
@@ -1985,9 +2141,7 @@ export class EmailEngineClient {
|
|
|
1985
2141
|
|
|
1986
2142
|
viewer.querySelector('[data-action="toggle-read"]').addEventListener('click', () => {
|
|
1987
2143
|
const currentlyUnseen = msg.unseen;
|
|
1988
|
-
this.markAsRead(msg.id, currentlyUnseen).catch(error =>
|
|
1989
|
-
this._alertActionFailed(error, 'Failed to update the message flags')
|
|
1990
|
-
);
|
|
2144
|
+
this.markAsRead(msg.id, currentlyUnseen).catch(error => this._alertActionFailed(error, 'Failed to update the message flags'));
|
|
1991
2145
|
});
|
|
1992
2146
|
|
|
1993
2147
|
viewer.querySelector('[data-action="delete"]').addEventListener('click', async () => {
|
|
@@ -1998,9 +2152,7 @@ export class EmailEngineClient {
|
|
|
1998
2152
|
'Delete'
|
|
1999
2153
|
);
|
|
2000
2154
|
if (result) {
|
|
2001
|
-
this.deleteMessage(msg.id).catch(error =>
|
|
2002
|
-
this._alertActionFailed(error, 'Failed to delete the message')
|
|
2003
|
-
);
|
|
2155
|
+
this.deleteMessage(msg.id).catch(error => this._alertActionFailed(error, 'Failed to delete the message'));
|
|
2004
2156
|
}
|
|
2005
2157
|
});
|
|
2006
2158
|
|
|
@@ -2029,6 +2181,21 @@ export class EmailEngineClient {
|
|
|
2029
2181
|
});
|
|
2030
2182
|
});
|
|
2031
2183
|
|
|
2184
|
+
const copyOtpButton = viewer.querySelector('[data-action="copy-otp"]');
|
|
2185
|
+
if (copyOtpButton) {
|
|
2186
|
+
const status = viewer.querySelector('.ee-otp-status');
|
|
2187
|
+
copyOtpButton.addEventListener('click', async () => {
|
|
2188
|
+
const copied = await this.copyText(msg.otp.code);
|
|
2189
|
+
copyOtpButton.textContent = copied ? 'Copied' : 'Copy code';
|
|
2190
|
+
status.textContent = copied ? 'Code copied to the clipboard' : 'Could not copy, select the code and copy it by hand';
|
|
2191
|
+
clearTimeout(this._otpCopyTimer);
|
|
2192
|
+
this._otpCopyTimer = setTimeout(() => {
|
|
2193
|
+
copyOtpButton.textContent = 'Copy code';
|
|
2194
|
+
status.textContent = '';
|
|
2195
|
+
}, 2500);
|
|
2196
|
+
});
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2032
2199
|
// Message content scrolling is now handled in loadMessage method
|
|
2033
2200
|
}
|
|
2034
2201
|
|
|
@@ -2191,12 +2358,7 @@ export class EmailEngineClient {
|
|
|
2191
2358
|
|
|
2192
2359
|
if (!to && !subject && !message) {
|
|
2193
2360
|
modal.classList.remove('show');
|
|
2194
|
-
await this.alertMethod(
|
|
2195
|
-
'Nothing to save - fill in at least one field first.',
|
|
2196
|
-
'Validation Error',
|
|
2197
|
-
null,
|
|
2198
|
-
'OK'
|
|
2199
|
-
);
|
|
2361
|
+
await this.alertMethod('Nothing to save - fill in at least one field first.', 'Validation Error', null, 'OK');
|
|
2200
2362
|
modal.classList.add('show');
|
|
2201
2363
|
setTimeout(() => form.querySelector('input[name="to"]').focus(), 100);
|
|
2202
2364
|
return;
|
|
@@ -2238,17 +2400,10 @@ export class EmailEngineClient {
|
|
|
2238
2400
|
if (!to || !message) {
|
|
2239
2401
|
// Close modal temporarily to show alert, then reopen
|
|
2240
2402
|
modal.classList.remove('show');
|
|
2241
|
-
await this.alertMethod(
|
|
2242
|
-
'Please fill in the recipient and message fields.',
|
|
2243
|
-
'Validation Error',
|
|
2244
|
-
null,
|
|
2245
|
-
'OK'
|
|
2246
|
-
);
|
|
2403
|
+
await this.alertMethod('Please fill in the recipient and message fields.', 'Validation Error', null, 'OK');
|
|
2247
2404
|
modal.classList.add('show');
|
|
2248
2405
|
// Re-focus the appropriate field
|
|
2249
|
-
const fieldToFocus = !to
|
|
2250
|
-
? form.querySelector('input[name="to"]')
|
|
2251
|
-
: form.querySelector('textarea[name="message"]');
|
|
2406
|
+
const fieldToFocus = !to ? form.querySelector('input[name="to"]') : form.querySelector('textarea[name="message"]');
|
|
2252
2407
|
setTimeout(() => fieldToFocus.focus(), 100);
|
|
2253
2408
|
return;
|
|
2254
2409
|
}
|
|
@@ -2372,6 +2527,7 @@ export class EmailEngineClient {
|
|
|
2372
2527
|
let inThrottle;
|
|
2373
2528
|
return function () {
|
|
2374
2529
|
const args = arguments;
|
|
2530
|
+
// eslint-disable-next-line no-invalid-this -- the wrapper forwards whatever this its caller bound
|
|
2375
2531
|
const context = this;
|
|
2376
2532
|
if (!inThrottle) {
|
|
2377
2533
|
func.apply(context, args);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postalsys/ee-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "EmailEngine client library for browser and Node.js applications",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -13,12 +13,15 @@
|
|
|
13
13
|
"LICENSE"
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
16
|
+
"test": "node --test test/*.test.js",
|
|
17
|
+
"test:cjs": "node --test test/static-copy.test.js",
|
|
18
|
+
"test:coverage": "c8 --reporter=text --reporter=lcov npm test",
|
|
19
|
+
"lint": "eslint .",
|
|
20
|
+
"lint:fix": "eslint . --fix",
|
|
21
|
+
"format": "prettier --write .",
|
|
22
|
+
"format:check": "prettier --check .",
|
|
20
23
|
"update": "rm -rf node_modules package-lock.json && ncu -u && npm install",
|
|
21
|
-
"prepublishOnly": "npm run lint && npm run format:check"
|
|
24
|
+
"prepublishOnly": "npm run lint && npm run format:check && npm test"
|
|
22
25
|
},
|
|
23
26
|
"keywords": [
|
|
24
27
|
"email",
|
|
@@ -39,11 +42,15 @@
|
|
|
39
42
|
"url": "https://github.com/postalsys/ee-client/issues"
|
|
40
43
|
},
|
|
41
44
|
"engines": {
|
|
42
|
-
"node": ">=
|
|
45
|
+
"node": ">=20.0.0"
|
|
43
46
|
},
|
|
44
47
|
"devDependencies": {
|
|
45
|
-
"eslint": "
|
|
46
|
-
"
|
|
48
|
+
"@eslint/js": "10.0.1",
|
|
49
|
+
"c8": "12.0.0",
|
|
50
|
+
"eslint": "10.13.0",
|
|
51
|
+
"eslint-config-prettier": "10.1.8",
|
|
52
|
+
"globals": "17.13.0",
|
|
53
|
+
"prettier": "3.9.10"
|
|
47
54
|
},
|
|
48
55
|
"peerDependencies": {
|
|
49
56
|
"node-fetch": "^3.0.0"
|