@postalsys/ee-client 1.0.1 → 1.1.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 CHANGED
@@ -72,6 +72,7 @@ const client = new EmailEngineClient({
72
72
  - `account` (string, required): Account identifier
73
73
  - `accessToken` (string, optional): Access token for authentication
74
74
  - `container` (HTMLElement, optional): DOM container for UI components (browser only)
75
+ - `confirmMethod` (function, optional): Custom confirm dialog method. Can be sync or async. Defaults to browser's `confirm()`
75
76
 
76
77
  ### Methods
77
78
 
@@ -117,11 +118,49 @@ When used in a browser with a container element, the client automatically create
117
118
  apiUrl: 'https://your-emailengine-server.com',
118
119
  account: 'your-account-id',
119
120
  accessToken: 'your-access-token',
120
- container: document.getElementById('email-client')
121
+ container: document.getElementById('email-client'),
122
+ // Optional: Custom confirm dialog
123
+ confirmMethod: async message => {
124
+ return await myCustomDialog.confirm(message);
125
+ }
121
126
  });
122
127
  </script>
123
128
  ```
124
129
 
130
+ ### Custom Confirm Dialog
131
+
132
+ You can provide a custom confirm dialog method that will be used instead of the browser's default `confirm()`. This is useful for integrating with UI frameworks or custom dialog systems:
133
+
134
+ ```javascript
135
+ const client = new EmailEngineClient({
136
+ apiUrl: 'https://your-emailengine-server.com',
137
+ account: 'your-account-id',
138
+ accessToken: 'your-access-token',
139
+ container: document.getElementById('email-client'),
140
+ confirmMethod: async message => {
141
+ // Example with a custom async dialog
142
+ return await MyModal.confirm({
143
+ title: 'Confirm Action',
144
+ message: message,
145
+ buttons: ['Cancel', 'OK']
146
+ });
147
+ }
148
+ });
149
+ ```
150
+
151
+ The `confirmMethod` can be either synchronous or asynchronous:
152
+
153
+ ```javascript
154
+ // Synchronous example
155
+ confirmMethod: message => window.confirm(message);
156
+
157
+ // Asynchronous example
158
+ confirmMethod: async message => {
159
+ const result = await customDialog.show(message);
160
+ return result === 'ok';
161
+ };
162
+ ```
163
+
125
164
  ## License
126
165
 
127
166
  MIT © Postal Systems OÜ
package/index.cjs CHANGED
@@ -4,6 +4,7 @@ class EmailEngineClient {
4
4
  this.account = options.account;
5
5
  this.accessToken = options.accessToken;
6
6
  this.container = options.container;
7
+ this.confirmMethod = options.confirmMethod || (message => confirm(message));
7
8
 
8
9
  this.currentFolder = null;
9
10
  this.currentMessage = null;
@@ -1072,8 +1073,9 @@ class EmailEngineClient {
1072
1073
  this.markAsRead(msg.id, currentlyUnseen);
1073
1074
  });
1074
1075
 
1075
- viewer.querySelector('[data-action="delete"]').addEventListener('click', () => {
1076
- if (confirm('Delete this message?')) {
1076
+ viewer.querySelector('[data-action="delete"]').addEventListener('click', async () => {
1077
+ const result = await this.confirmMethod('Delete this message?');
1078
+ if (result) {
1077
1079
  this.deleteMessage(msg.id);
1078
1080
  }
1079
1081
  });
package/index.d.ts CHANGED
@@ -50,6 +50,7 @@ export interface EmailEngineClientOptions {
50
50
  accessToken?: string;
51
51
  container?: HTMLElement;
52
52
  containerId?: string;
53
+ confirmMethod?: (message: string) => boolean | Promise<boolean>;
53
54
  }
54
55
 
55
56
  export declare class EmailEngineClient {
package/index.js CHANGED
@@ -4,6 +4,7 @@ export class EmailEngineClient {
4
4
  this.account = options.account;
5
5
  this.accessToken = options.accessToken;
6
6
  this.container = options.container;
7
+ this.confirmMethod = options.confirmMethod || (message => confirm(message));
7
8
 
8
9
  this.currentFolder = null;
9
10
  this.currentMessage = null;
@@ -1072,8 +1073,9 @@ export class EmailEngineClient {
1072
1073
  this.markAsRead(msg.id, currentlyUnseen);
1073
1074
  });
1074
1075
 
1075
- viewer.querySelector('[data-action="delete"]').addEventListener('click', () => {
1076
- if (confirm('Delete this message?')) {
1076
+ viewer.querySelector('[data-action="delete"]').addEventListener('click', async () => {
1077
+ const result = await this.confirmMethod('Delete this message?');
1078
+ if (result) {
1077
1079
  this.deleteMessage(msg.id);
1078
1080
  }
1079
1081
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postalsys/ee-client",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "EmailEngine client library for browser and Node.js applications",
5
5
  "main": "index.js",
6
6
  "module": "index.js",