@postalsys/ee-client 1.8.1 → 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 +227 -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
|
@@ -6,6 +6,11 @@ const MESSAGE_BODY_STYLES = `
|
|
|
6
6
|
:host {
|
|
7
7
|
all: initial;
|
|
8
8
|
display: block;
|
|
9
|
+
/* Nothing the message does paints outside this box, whatever its outermost wrapper says.
|
|
10
|
+
EmailEngine clips the message inside a wrapper of its own; this is the viewer's copy of
|
|
11
|
+
that rule, for a body rendered by a version whose wrapper the sender could still style.
|
|
12
|
+
clip, not hidden: the host must not become a scroll container of its own. */
|
|
13
|
+
overflow: clip;
|
|
9
14
|
color: inherit;
|
|
10
15
|
font-family: var(--ee-font, sans-serif);
|
|
11
16
|
font-size: 14px;
|
|
@@ -74,16 +79,11 @@ export class EmailEngineClient {
|
|
|
74
79
|
// A containerId that matches nothing is almost always a typo; warn
|
|
75
80
|
// rather than silently degrading to a UI-less, API-only client.
|
|
76
81
|
if (!this.container) {
|
|
77
|
-
console.warn(
|
|
78
|
-
`EmailEngineClient: no element found for containerId "${options.containerId}"; UI rendering disabled`
|
|
79
|
-
);
|
|
82
|
+
console.warn(`EmailEngineClient: no element found for containerId "${options.containerId}"; UI rendering disabled`);
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
|
-
this.confirmMethod =
|
|
83
|
-
|
|
84
|
-
((message, _title = 'Confirm', _cancelText = 'Cancel', _okText = 'OK') => confirm(message));
|
|
85
|
-
this.alertMethod =
|
|
86
|
-
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));
|
|
87
87
|
|
|
88
88
|
this.currentFolder = null;
|
|
89
89
|
this.currentMessage = null;
|
|
@@ -119,8 +119,7 @@ export class EmailEngineClient {
|
|
|
119
119
|
this.styleNonce = typeof options.styleNonce === 'string' && options.styleNonce ? options.styleNonce : null;
|
|
120
120
|
|
|
121
121
|
// Get page size from localStorage or options or default
|
|
122
|
-
const savedPageSize =
|
|
123
|
-
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;
|
|
124
123
|
const requestedPageSize = savedPageSize ? parseInt(savedPageSize, 10) : parseInt(options.pageSize, 10);
|
|
125
124
|
this.pageSize = requestedPageSize > 0 ? requestedPageSize : 20;
|
|
126
125
|
|
|
@@ -146,16 +145,14 @@ export class EmailEngineClient {
|
|
|
146
145
|
try {
|
|
147
146
|
const nodeFetch = await import('node-fetch');
|
|
148
147
|
fetchFn = nodeFetch.default;
|
|
149
|
-
} catch
|
|
148
|
+
} catch {
|
|
150
149
|
// node-fetch is not installed; the guard below reports it
|
|
151
150
|
}
|
|
152
151
|
}
|
|
153
152
|
|
|
154
153
|
if (!fetchFn) {
|
|
155
154
|
// Either node-fetch is missing or it exposed no callable default export
|
|
156
|
-
throw new Error(
|
|
157
|
-
'fetch is not available. In Node.js environments, please install node-fetch: npm install node-fetch'
|
|
158
|
-
);
|
|
155
|
+
throw new Error('fetch is not available. In Node.js environments, please install node-fetch: npm install node-fetch');
|
|
159
156
|
}
|
|
160
157
|
|
|
161
158
|
try {
|
|
@@ -178,7 +175,7 @@ export class EmailEngineClient {
|
|
|
178
175
|
let details;
|
|
179
176
|
try {
|
|
180
177
|
details = await response.json();
|
|
181
|
-
} catch
|
|
178
|
+
} catch {
|
|
182
179
|
// Not a JSON body - the status line is all there is to go on
|
|
183
180
|
details = { message: response.statusText };
|
|
184
181
|
}
|
|
@@ -191,7 +188,7 @@ export class EmailEngineClient {
|
|
|
191
188
|
|
|
192
189
|
async apiRequest(method, endpoint, data = null) {
|
|
193
190
|
const options = {
|
|
194
|
-
method
|
|
191
|
+
method,
|
|
195
192
|
headers: {
|
|
196
193
|
'Content-Type': 'application/json',
|
|
197
194
|
...this._authHeaders()
|
|
@@ -248,7 +245,7 @@ export class EmailEngineClient {
|
|
|
248
245
|
this._setPaneHtml('.ee-message-list', '<div class="ee-loading">Loading messages...</div>');
|
|
249
246
|
|
|
250
247
|
try {
|
|
251
|
-
const params = new URLSearchParams({ path
|
|
248
|
+
const params = new URLSearchParams({ path, pageSize: this.pageSize });
|
|
252
249
|
if (cursor) {
|
|
253
250
|
params.set('cursor', cursor);
|
|
254
251
|
}
|
|
@@ -275,9 +272,7 @@ export class EmailEngineClient {
|
|
|
275
272
|
};
|
|
276
273
|
} catch (error) {
|
|
277
274
|
console.error('Failed to load messages:', error);
|
|
278
|
-
this._renderPaneError('.ee-message-list', 'Messages unavailable', error, () =>
|
|
279
|
-
this._fireAndForget(this.loadMessages(path, cursor))
|
|
280
|
-
);
|
|
275
|
+
this._renderPaneError('.ee-message-list', 'Messages unavailable', error, () => this._fireAndForget(this.loadMessages(path, cursor)));
|
|
281
276
|
throw error;
|
|
282
277
|
}
|
|
283
278
|
}
|
|
@@ -319,9 +314,7 @@ export class EmailEngineClient {
|
|
|
319
314
|
return this.currentMessage;
|
|
320
315
|
} catch (error) {
|
|
321
316
|
console.error('Failed to load message:', error);
|
|
322
|
-
this._renderPaneError('.ee-message-viewer', 'Message unavailable', error, () =>
|
|
323
|
-
this._fireAndForget(this.loadMessage(messageId))
|
|
324
|
-
);
|
|
317
|
+
this._renderPaneError('.ee-message-viewer', 'Message unavailable', error, () => this._fireAndForget(this.loadMessage(messageId)));
|
|
325
318
|
throw error;
|
|
326
319
|
}
|
|
327
320
|
}
|
|
@@ -403,9 +396,7 @@ export class EmailEngineClient {
|
|
|
403
396
|
}
|
|
404
397
|
|
|
405
398
|
_normalizeRecipients(to) {
|
|
406
|
-
return Array.isArray(to)
|
|
407
|
-
? to.map(addr => (typeof addr === 'string' ? { address: addr } : addr))
|
|
408
|
-
: [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];
|
|
409
400
|
}
|
|
410
401
|
|
|
411
402
|
// Account details (name, email address) fetched once and cached for the lifetime
|
|
@@ -421,8 +412,8 @@ export class EmailEngineClient {
|
|
|
421
412
|
try {
|
|
422
413
|
const messageData = {
|
|
423
414
|
to: this._normalizeRecipients(to),
|
|
424
|
-
subject
|
|
425
|
-
text
|
|
415
|
+
subject,
|
|
416
|
+
text
|
|
426
417
|
};
|
|
427
418
|
|
|
428
419
|
const response = await this.apiRequest('POST', `${this._accountPath()}/submit`, messageData);
|
|
@@ -446,8 +437,8 @@ export class EmailEngineClient {
|
|
|
446
437
|
const messageData = {
|
|
447
438
|
path: draftsFolder.path,
|
|
448
439
|
flags: ['\\Draft'],
|
|
449
|
-
subject
|
|
450
|
-
text
|
|
440
|
+
subject,
|
|
441
|
+
text
|
|
451
442
|
};
|
|
452
443
|
|
|
453
444
|
const recipients = to ? this._normalizeRecipients(to) : [];
|
|
@@ -462,7 +453,7 @@ export class EmailEngineClient {
|
|
|
462
453
|
if (accountInfo && accountInfo.email) {
|
|
463
454
|
messageData.from = { name: accountInfo.name || '', address: accountInfo.email };
|
|
464
455
|
}
|
|
465
|
-
} catch
|
|
456
|
+
} catch {
|
|
466
457
|
// Non-fatal: the draft is saved without a From header
|
|
467
458
|
}
|
|
468
459
|
|
|
@@ -644,6 +635,84 @@ export class EmailEngineClient {
|
|
|
644
635
|
return Math.round((bytes / Math.pow(1024, i)) * 100) / 100 + ' ' + sizes[i];
|
|
645
636
|
}
|
|
646
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
|
+
|
|
647
716
|
escapeHtml(value) {
|
|
648
717
|
if (value === null || value === undefined) {
|
|
649
718
|
return '';
|
|
@@ -655,7 +724,7 @@ export class EmailEngineClient {
|
|
|
655
724
|
_authHeaders() {
|
|
656
725
|
const headers = {};
|
|
657
726
|
if (this.accessToken) {
|
|
658
|
-
headers
|
|
727
|
+
headers.Authorization = `Bearer ${this.accessToken}`;
|
|
659
728
|
}
|
|
660
729
|
return headers;
|
|
661
730
|
}
|
|
@@ -707,12 +776,7 @@ export class EmailEngineClient {
|
|
|
707
776
|
this._saveBlob(blob, filename);
|
|
708
777
|
} catch (error) {
|
|
709
778
|
console.error('Failed to download attachment:', error);
|
|
710
|
-
this.alertMethod(
|
|
711
|
-
this._errorMessage(error, 'Failed to download attachment. Please try again.'),
|
|
712
|
-
'Download Error',
|
|
713
|
-
null,
|
|
714
|
-
'OK'
|
|
715
|
-
);
|
|
779
|
+
this.alertMethod(this._errorMessage(error, 'Failed to download attachment. Please try again.'), 'Download Error', null, 'OK');
|
|
716
780
|
}
|
|
717
781
|
}
|
|
718
782
|
|
|
@@ -732,12 +796,7 @@ export class EmailEngineClient {
|
|
|
732
796
|
this._saveBlob(blob, filename);
|
|
733
797
|
} catch (error) {
|
|
734
798
|
console.error('Failed to download original message:', error);
|
|
735
|
-
this.alertMethod(
|
|
736
|
-
this._errorMessage(error, 'Failed to download original message. Please try again.'),
|
|
737
|
-
'Download Error',
|
|
738
|
-
null,
|
|
739
|
-
'OK'
|
|
740
|
-
);
|
|
799
|
+
this.alertMethod(this._errorMessage(error, 'Failed to download original message. Please try again.'), 'Download Error', null, 'OK');
|
|
741
800
|
}
|
|
742
801
|
}
|
|
743
802
|
|
|
@@ -1001,6 +1060,82 @@ export class EmailEngineClient {
|
|
|
1001
1060
|
.ee-message-meta-row {
|
|
1002
1061
|
margin-bottom: 4px;
|
|
1003
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
|
+
}
|
|
1004
1139
|
|
|
1005
1140
|
.ee-message-meta-label {
|
|
1006
1141
|
display: inline-block;
|
|
@@ -1551,6 +1686,31 @@ export class EmailEngineClient {
|
|
|
1551
1686
|
color: #f0a5a5;
|
|
1552
1687
|
}
|
|
1553
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
|
+
|
|
1554
1714
|
.ee-dark-mode .ee-pagination {
|
|
1555
1715
|
background: #252525;
|
|
1556
1716
|
border-color: #333;
|
|
@@ -1839,7 +1999,7 @@ export class EmailEngineClient {
|
|
|
1839
1999
|
const pageSizeSelect = messageList.querySelector('[data-action="page-size"]');
|
|
1840
2000
|
if (pageSizeSelect) {
|
|
1841
2001
|
pageSizeSelect.addEventListener('change', e => {
|
|
1842
|
-
this.pageSize = parseInt(e.target.value);
|
|
2002
|
+
this.pageSize = parseInt(e.target.value, 10);
|
|
1843
2003
|
// Save to localStorage
|
|
1844
2004
|
if (typeof window !== 'undefined' && window.localStorage) {
|
|
1845
2005
|
localStorage.setItem('ee-client-page-size', this.pageSize.toString());
|
|
@@ -1913,6 +2073,7 @@ export class EmailEngineClient {
|
|
|
1913
2073
|
${this.escapeHtml(msg.subject || '(no subject)')}
|
|
1914
2074
|
</div>
|
|
1915
2075
|
</div>
|
|
2076
|
+
${this.renderOtpBox(msg.otp)}
|
|
1916
2077
|
<div class="ee-message-body"></div>
|
|
1917
2078
|
${
|
|
1918
2079
|
msg.attachments && msg.attachments.length > 0
|
|
@@ -1980,9 +2141,7 @@ export class EmailEngineClient {
|
|
|
1980
2141
|
|
|
1981
2142
|
viewer.querySelector('[data-action="toggle-read"]').addEventListener('click', () => {
|
|
1982
2143
|
const currentlyUnseen = msg.unseen;
|
|
1983
|
-
this.markAsRead(msg.id, currentlyUnseen).catch(error =>
|
|
1984
|
-
this._alertActionFailed(error, 'Failed to update the message flags')
|
|
1985
|
-
);
|
|
2144
|
+
this.markAsRead(msg.id, currentlyUnseen).catch(error => this._alertActionFailed(error, 'Failed to update the message flags'));
|
|
1986
2145
|
});
|
|
1987
2146
|
|
|
1988
2147
|
viewer.querySelector('[data-action="delete"]').addEventListener('click', async () => {
|
|
@@ -1993,9 +2152,7 @@ export class EmailEngineClient {
|
|
|
1993
2152
|
'Delete'
|
|
1994
2153
|
);
|
|
1995
2154
|
if (result) {
|
|
1996
|
-
this.deleteMessage(msg.id).catch(error =>
|
|
1997
|
-
this._alertActionFailed(error, 'Failed to delete the message')
|
|
1998
|
-
);
|
|
2155
|
+
this.deleteMessage(msg.id).catch(error => this._alertActionFailed(error, 'Failed to delete the message'));
|
|
1999
2156
|
}
|
|
2000
2157
|
});
|
|
2001
2158
|
|
|
@@ -2024,6 +2181,21 @@ export class EmailEngineClient {
|
|
|
2024
2181
|
});
|
|
2025
2182
|
});
|
|
2026
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
|
+
|
|
2027
2199
|
// Message content scrolling is now handled in loadMessage method
|
|
2028
2200
|
}
|
|
2029
2201
|
|
|
@@ -2186,12 +2358,7 @@ export class EmailEngineClient {
|
|
|
2186
2358
|
|
|
2187
2359
|
if (!to && !subject && !message) {
|
|
2188
2360
|
modal.classList.remove('show');
|
|
2189
|
-
await this.alertMethod(
|
|
2190
|
-
'Nothing to save - fill in at least one field first.',
|
|
2191
|
-
'Validation Error',
|
|
2192
|
-
null,
|
|
2193
|
-
'OK'
|
|
2194
|
-
);
|
|
2361
|
+
await this.alertMethod('Nothing to save - fill in at least one field first.', 'Validation Error', null, 'OK');
|
|
2195
2362
|
modal.classList.add('show');
|
|
2196
2363
|
setTimeout(() => form.querySelector('input[name="to"]').focus(), 100);
|
|
2197
2364
|
return;
|
|
@@ -2233,17 +2400,10 @@ export class EmailEngineClient {
|
|
|
2233
2400
|
if (!to || !message) {
|
|
2234
2401
|
// Close modal temporarily to show alert, then reopen
|
|
2235
2402
|
modal.classList.remove('show');
|
|
2236
|
-
await this.alertMethod(
|
|
2237
|
-
'Please fill in the recipient and message fields.',
|
|
2238
|
-
'Validation Error',
|
|
2239
|
-
null,
|
|
2240
|
-
'OK'
|
|
2241
|
-
);
|
|
2403
|
+
await this.alertMethod('Please fill in the recipient and message fields.', 'Validation Error', null, 'OK');
|
|
2242
2404
|
modal.classList.add('show');
|
|
2243
2405
|
// Re-focus the appropriate field
|
|
2244
|
-
const fieldToFocus = !to
|
|
2245
|
-
? form.querySelector('input[name="to"]')
|
|
2246
|
-
: form.querySelector('textarea[name="message"]');
|
|
2406
|
+
const fieldToFocus = !to ? form.querySelector('input[name="to"]') : form.querySelector('textarea[name="message"]');
|
|
2247
2407
|
setTimeout(() => fieldToFocus.focus(), 100);
|
|
2248
2408
|
return;
|
|
2249
2409
|
}
|
|
@@ -2367,6 +2527,7 @@ export class EmailEngineClient {
|
|
|
2367
2527
|
let inThrottle;
|
|
2368
2528
|
return function () {
|
|
2369
2529
|
const args = arguments;
|
|
2530
|
+
// eslint-disable-next-line no-invalid-this -- the wrapper forwards whatever this its caller bound
|
|
2370
2531
|
const context = this;
|
|
2371
2532
|
if (!inThrottle) {
|
|
2372
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"
|