mail-time 3.0.0 → 4.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/index.d.cts ADDED
@@ -0,0 +1,322 @@
1
+ export type MailTimePresetName = import("./presets.js").MailTimePresetName;
2
+ export type MailTimePresetConfig = import("./presets.js").MailTimePresetConfig;
3
+ export type MailTimePingResult = {
4
+ status: string;
5
+ code: number;
6
+ statusCode: number;
7
+ paused?: boolean;
8
+ error?: unknown;
9
+ };
10
+ export type MailTimeStorageClient = {
11
+ [key: string]: any;
12
+ query?: (queryText: string, values?: unknown[]) => Promise<{
13
+ rows?: unknown[];
14
+ rowCount?: number | null;
15
+ }>;
16
+ };
17
+ export type MailTimeMongoDb = {
18
+ [key: string]: any;
19
+ };
20
+ export type MailTimeTransport = {
21
+ [key: string]: any;
22
+ };
23
+ export type MailTimeJoSkAdapterOptions = {
24
+ [key: string]: any;
25
+ type?: "mongo" | "redis" | "postgres";
26
+ client?: MailTimeStorageClient;
27
+ db?: MailTimeMongoDb;
28
+ prefix?: string;
29
+ resetOnInit?: boolean;
30
+ useHashTags?: boolean;
31
+ };
32
+ export type MailTimeJoSkOptions = {
33
+ [key: string]: any;
34
+ adapter: MailTimeJoSkAdapterOptions | object;
35
+ debug?: boolean;
36
+ autoClear?: boolean;
37
+ zombieTime?: number;
38
+ minRevolvingDelay?: number;
39
+ maxRevolvingDelay?: number;
40
+ execute?: "batch" | "one";
41
+ concurrency?: number;
42
+ lockOwnerId?: string;
43
+ resetOnInit?: boolean;
44
+ onError?: (title: string, details: object) => void;
45
+ onExecuted?: (uid: string, details: object) => void;
46
+ };
47
+ export type MailTimeTask = {
48
+ uuid: string;
49
+ to?: string | string[];
50
+ tries: number;
51
+ sendAt: number;
52
+ isSent: boolean;
53
+ isCancelled: boolean;
54
+ isFailed: boolean;
55
+ isSending?: boolean;
56
+ sendingAt?: number;
57
+ template?: string | false;
58
+ transport: number;
59
+ concatSubject?: string | false;
60
+ mailOptions: MailTimeMailOptions[];
61
+ };
62
+ export type MailTimeIterateOptions = {
63
+ limit?: number;
64
+ sendingTimeout?: number;
65
+ };
66
+ export type CustomQueue = {
67
+ ping: () => Promise<MailTimePingResult>;
68
+ iterate: (opts?: MailTimeIterateOptions) => Promise<void> | void;
69
+ getPendingTo: (to: string, sendAt: number) => Promise<MailTimeTask | object | null>;
70
+ push: (email: MailTimeTask) => Promise<void> | void;
71
+ cancel: (uuid: string) => Promise<boolean>;
72
+ remove: (email: MailTimeTask | object, opts?: {
73
+ leaseTries: number;
74
+ leaseSendingAt: number;
75
+ }) => Promise<boolean>;
76
+ update: (email: MailTimeTask | object, updateObj: object) => Promise<boolean>;
77
+ ready?: () => Promise<void>;
78
+ };
79
+ export type MailTimeRejectedRecipient = {
80
+ address: string;
81
+ error: string;
82
+ };
83
+ export type MailTimeMailOptions = {
84
+ [key: string]: any;
85
+ to: string | string[];
86
+ sendAt?: Date | number;
87
+ template?: string;
88
+ concatSubject?: string;
89
+ text?: string | false;
90
+ html?: string | false;
91
+ subject?: string;
92
+ accepted?: string[];
93
+ rejected?: MailTimeRejectedRecipient[];
94
+ };
95
+ export type MailTimeConcatEmailsOptions = {
96
+ subject?: string;
97
+ };
98
+ export type MailTimeOptions = {
99
+ queue: RedisQueue | MongoQueue | PostgresQueue | CustomQueue;
100
+ type?: "server" | "client";
101
+ from?: string | ((transport: MailTimeTransport) => string);
102
+ transports?: MailTimeTransport[];
103
+ strategy?: "backup" | "balancer";
104
+ failsToNext?: number;
105
+ retries?: number;
106
+ maxTries?: number;
107
+ retryDelay?: number;
108
+ interval?: number;
109
+ keepHistory?: boolean;
110
+ concatEmails?: boolean | MailTimeConcatEmailsOptions;
111
+ concatSubject?: string;
112
+ concatDelimiter?: string;
113
+ concatDelay?: number;
114
+ concatThrottling?: number;
115
+ revolvingInterval?: number;
116
+ mode?: "one" | "batch";
117
+ concurrency?: number;
118
+ sendingTimeout?: number;
119
+ verifyTransports?: boolean;
120
+ template?: string;
121
+ prefix?: string;
122
+ debug?: boolean;
123
+ josk?: MailTimeJoSkOptions;
124
+ onError?: (error: unknown, email: MailTimeTask | null, details?: object) => void;
125
+ onSent?: (email: MailTimeTask, details?: object) => void;
126
+ };
127
+ /**
128
+ * @typedef {import('./presets.js').MailTimePresetName} MailTimePresetName
129
+ */
130
+ /**
131
+ * @typedef {import('./presets.js').MailTimePresetConfig} MailTimePresetConfig
132
+ */
133
+ /**
134
+ * @typedef {{ status: string, code: number, statusCode: number, paused?: boolean, error?: unknown }} MailTimePingResult
135
+ */
136
+ /**
137
+ * @typedef {{ [key: string]: any, query?: (queryText: string, values?: unknown[]) => Promise<{ rows?: unknown[], rowCount?: number | null }> }} MailTimeStorageClient
138
+ */
139
+ /**
140
+ * @typedef {{ [key: string]: any }} MailTimeMongoDb
141
+ */
142
+ /**
143
+ * @typedef {{ [key: string]: any }} MailTimeTransport
144
+ */
145
+ /**
146
+ * @typedef {{ [key: string]: any, type?: 'mongo' | 'redis' | 'postgres', client?: MailTimeStorageClient, db?: MailTimeMongoDb, prefix?: string, resetOnInit?: boolean, useHashTags?: boolean }} MailTimeJoSkAdapterOptions
147
+ */
148
+ /**
149
+ * @typedef {{ [key: string]: any, adapter: MailTimeJoSkAdapterOptions | object, debug?: boolean, autoClear?: boolean, zombieTime?: number, minRevolvingDelay?: number, maxRevolvingDelay?: number, execute?: 'batch' | 'one', concurrency?: number, lockOwnerId?: string, resetOnInit?: boolean, onError?: (title: string, details: object) => void, onExecuted?: (uid: string, details: object) => void }} MailTimeJoSkOptions
150
+ */
151
+ /**
152
+ * @typedef {{ uuid: string, to?: string | string[], tries: number, sendAt: number, isSent: boolean, isCancelled: boolean, isFailed: boolean, isSending?: boolean, sendingAt?: number, template?: string | false, transport: number, concatSubject?: string | false, mailOptions: MailTimeMailOptions[] }} MailTimeTask
153
+ */
154
+ /**
155
+ * @typedef {{ limit?: number, sendingTimeout?: number }} MailTimeIterateOptions
156
+ */
157
+ /**
158
+ * @typedef {{ ping: () => Promise<MailTimePingResult>, iterate: (opts?: MailTimeIterateOptions) => Promise<void> | void, getPendingTo: (to: string, sendAt: number) => Promise<MailTimeTask | object | null>, push: (email: MailTimeTask) => Promise<void> | void, cancel: (uuid: string) => Promise<boolean>, remove: (email: MailTimeTask | object, opts?: { leaseTries: number, leaseSendingAt: number }) => Promise<boolean>, update: (email: MailTimeTask | object, updateObj: object) => Promise<boolean>, ready?: () => Promise<void> }} CustomQueue
159
+ */
160
+ /**
161
+ * @typedef {{ address: string, error: string }} MailTimeRejectedRecipient
162
+ */
163
+ /**
164
+ * @typedef {{ [key: string]: any, to: string | string[], sendAt?: Date | number, template?: string, concatSubject?: string, text?: string | false, html?: string | false, subject?: string, accepted?: string[], rejected?: MailTimeRejectedRecipient[] }} MailTimeMailOptions
165
+ */
166
+ /**
167
+ * @typedef {{ subject?: string }} MailTimeConcatEmailsOptions
168
+ */
169
+ /**
170
+ * @typedef {{ queue: RedisQueue | MongoQueue | PostgresQueue | CustomQueue, type?: 'server' | 'client', from?: string | ((transport: MailTimeTransport) => string), transports?: MailTimeTransport[], strategy?: 'backup' | 'balancer', failsToNext?: number, retries?: number, maxTries?: number, retryDelay?: number, interval?: number, keepHistory?: boolean, concatEmails?: boolean | MailTimeConcatEmailsOptions, concatSubject?: string, concatDelimiter?: string, concatDelay?: number, concatThrottling?: number, revolvingInterval?: number, mode?: 'one' | 'batch', concurrency?: number, sendingTimeout?: number, verifyTransports?: boolean, template?: string, prefix?: string, debug?: boolean, josk?: MailTimeJoSkOptions, onError?: (error: unknown, email: MailTimeTask | null, details?: object) => void, onSent?: (email: MailTimeTask, details?: object) => void }} MailTimeOptions
171
+ */
172
+ /** Class of MailTime */
173
+ export class MailTime {
174
+ static set Template(newVal: string);
175
+ static get Template(): string;
176
+ /**
177
+ * Create a MailTime instance
178
+ * @param {MailTimeOptions} opts - configuration object
179
+ */
180
+ constructor(opts: MailTimeOptions);
181
+ queue: MongoQueue | RedisQueue | PostgresQueue | CustomQueue;
182
+ debug: boolean;
183
+ type: "server" | "client";
184
+ prefix: string;
185
+ maxTries: number;
186
+ retryDelay: number;
187
+ template: string;
188
+ keepHistory: boolean;
189
+ onSent: (email: MailTimeTask, details?: object) => void;
190
+ onError: (error: unknown, email: MailTimeTask | null, details?: object) => void;
191
+ revolvingInterval: number;
192
+ mode: "one" | "batch";
193
+ concurrency: number;
194
+ sendingTimeout: number;
195
+ failsToNext: number;
196
+ strategy: "backup" | "balancer";
197
+ transports: MailTimeTransport[];
198
+ transport: number;
199
+ verifyTransports: boolean;
200
+ from: boolean | ((transport: MailTimeTransport) => string);
201
+ /** @type {string} */
202
+ concatSubject: string;
203
+ concatEmails: boolean;
204
+ concatDelimiter: string;
205
+ concatDelay: number;
206
+ josk: {
207
+ [key: string]: any;
208
+ adapter: MailTimeJoSkAdapterOptions | object;
209
+ debug?: boolean;
210
+ autoClear?: boolean;
211
+ zombieTime?: number;
212
+ minRevolvingDelay?: number;
213
+ maxRevolvingDelay?: number;
214
+ execute?: "batch" | "one";
215
+ concurrency?: number;
216
+ lockOwnerId?: string;
217
+ resetOnInit?: boolean;
218
+ onError?: (title: string, details: object) => void;
219
+ onExecuted?: (uid: string, details: object) => void;
220
+ } | undefined;
221
+ scheduler: JoSk | undefined;
222
+ /**
223
+ * @async
224
+ * @memberOf MailTime
225
+ * @name ping
226
+ * @description Check package readiness and connection to Storage
227
+ * @returns {Promise<MailTimePingResult>}
228
+ * @throws {Error}
229
+ */
230
+ ping(): Promise<MailTimePingResult>;
231
+ /**
232
+ * @async
233
+ * @memberOf MailTime
234
+ * @name ready
235
+ * @description Wait until queue and scheduler storage are ready
236
+ * @returns {Promise<MailTime>}
237
+ */
238
+ ready(): Promise<MailTime>;
239
+ /**
240
+ * @memberOf MailTime
241
+ * @name destroy
242
+ * @description Stop the scheduler and block future dispatches. Without `{ drain: true }`, any in-flight SMTP attempts are neutralized on completion — they perform no storage writes, no `onSent`/`onError` callbacks, and no logging once `destroy()` returns; their claimed rows are recovered by stale-lock timeout (`sendingTimeout`). Pass `{ drain: true }` to instead let in-flight attempts run to completion (returns a Promise that resolves once they settle).
243
+ * @param {{ drain?: boolean }} [opts]
244
+ * @returns {boolean | Promise<boolean>}
245
+ */
246
+ destroy(opts?: {
247
+ drain?: boolean;
248
+ }): boolean | Promise<boolean>;
249
+ /**
250
+ * @async
251
+ * @memberOf MailTime
252
+ * @name drain
253
+ * @description Wait for all in-flight email send attempts to settle
254
+ * @returns {Promise<void>}
255
+ */
256
+ drain(): Promise<void>;
257
+ /**
258
+ * @memberOf MailTime
259
+ * @name pause
260
+ * @description Pause this server instance from competing for the queue-drain lease. In-flight SMTP sends finish; peer server instances keep draining. Reversible (unlike `destroy()`). No-op on `client` instances or after `destroy()`. To stop scanning *and* wait for in-flight sends: `mailTime.pause(); await mailTime.drain();`.
261
+ * @returns {boolean} `true` if newly paused; `false` if already paused, a client instance, or destroyed
262
+ */
263
+ pause(): boolean;
264
+ /**
265
+ * @memberOf MailTime
266
+ * @name resume
267
+ * @description Resume competing for the queue-drain lease after `pause()`; triggers an immediate scan. No-op on `client` instances, after `destroy()`, or when not paused.
268
+ * @returns {boolean} `true` if newly resumed; `false` if not paused, a client instance, or destroyed
269
+ */
270
+ resume(): boolean;
271
+ /**
272
+ * @memberOf MailTime
273
+ * @name isPaused
274
+ * @description Whether this instance is currently paused from draining the queue. Always `false` on `client` instances.
275
+ * @returns {boolean}
276
+ */
277
+ get isPaused(): boolean;
278
+ /**
279
+ * @memberOf MailTime
280
+ * @name send
281
+ * @description alias of `sendMail`
282
+ * @param {MailTimeMailOptions} opts - email options
283
+ * @returns {Promise<string>} uuid of the email
284
+ */
285
+ send(opts: MailTimeMailOptions): Promise<string>;
286
+ /**
287
+ * @async
288
+ * @memberOf MailTime
289
+ * @name sendMail
290
+ * @description add email to the queue or append to existing letter if {concatEmails: true}
291
+ * @param {MailTimeMailOptions} opts - email options
292
+ * @returns {Promise<string>} uuid of the email
293
+ * @throws {Error}
294
+ */
295
+ sendMail(opts?: MailTimeMailOptions): Promise<string>;
296
+ /**
297
+ * @async
298
+ * @memberOf MailTime
299
+ * @name cancel
300
+ * @description alias of `cancelMail`
301
+ * @param {string|Promise<string>} uuid - uuid returned from `send` or `sendMail`
302
+ * @returns {Promise<boolean>} returns `true` if cancelled or `false` if not found was sent or was cancelled previously
303
+ */
304
+ cancel(uuid: string | Promise<string>): Promise<boolean>;
305
+ /**
306
+ * @async
307
+ * @memberOf MailTime
308
+ * @name cancelMail
309
+ * @description remove email from the queue or mark as `isCancelled`
310
+ * @param {string|Promise<string>} uuid - uuid returned from `send` or `sendMail`
311
+ * @returns {Promise<boolean>} returns `true` if cancelled or `false` if not found was sent or was cancelled previously
312
+ */
313
+ cancelMail(uuid: string | Promise<string>): Promise<boolean>;
314
+ }
315
+ import { MongoQueue } from './adapters/mongo.js';
316
+ import { RedisQueue } from './adapters/redis.js';
317
+ import { PostgresQueue } from './adapters/postgres.js';
318
+ import { mailTimePreset } from './presets.js';
319
+ import { presets } from './presets.js';
320
+ import { presetNames } from './presets.js';
321
+ import { JoSk } from 'josk';
322
+ export { MongoQueue, RedisQueue, PostgresQueue, mailTimePreset, presets, presetNames };
package/index.d.ts ADDED
@@ -0,0 +1,322 @@
1
+ export type MailTimePresetName = import("./presets.js").MailTimePresetName;
2
+ export type MailTimePresetConfig = import("./presets.js").MailTimePresetConfig;
3
+ export type MailTimePingResult = {
4
+ status: string;
5
+ code: number;
6
+ statusCode: number;
7
+ paused?: boolean;
8
+ error?: unknown;
9
+ };
10
+ export type MailTimeStorageClient = {
11
+ [key: string]: any;
12
+ query?: (queryText: string, values?: unknown[]) => Promise<{
13
+ rows?: unknown[];
14
+ rowCount?: number | null;
15
+ }>;
16
+ };
17
+ export type MailTimeMongoDb = {
18
+ [key: string]: any;
19
+ };
20
+ export type MailTimeTransport = {
21
+ [key: string]: any;
22
+ };
23
+ export type MailTimeJoSkAdapterOptions = {
24
+ [key: string]: any;
25
+ type?: "mongo" | "redis" | "postgres";
26
+ client?: MailTimeStorageClient;
27
+ db?: MailTimeMongoDb;
28
+ prefix?: string;
29
+ resetOnInit?: boolean;
30
+ useHashTags?: boolean;
31
+ };
32
+ export type MailTimeJoSkOptions = {
33
+ [key: string]: any;
34
+ adapter: MailTimeJoSkAdapterOptions | object;
35
+ debug?: boolean;
36
+ autoClear?: boolean;
37
+ zombieTime?: number;
38
+ minRevolvingDelay?: number;
39
+ maxRevolvingDelay?: number;
40
+ execute?: "batch" | "one";
41
+ concurrency?: number;
42
+ lockOwnerId?: string;
43
+ resetOnInit?: boolean;
44
+ onError?: (title: string, details: object) => void;
45
+ onExecuted?: (uid: string, details: object) => void;
46
+ };
47
+ export type MailTimeTask = {
48
+ uuid: string;
49
+ to?: string | string[];
50
+ tries: number;
51
+ sendAt: number;
52
+ isSent: boolean;
53
+ isCancelled: boolean;
54
+ isFailed: boolean;
55
+ isSending?: boolean;
56
+ sendingAt?: number;
57
+ template?: string | false;
58
+ transport: number;
59
+ concatSubject?: string | false;
60
+ mailOptions: MailTimeMailOptions[];
61
+ };
62
+ export type MailTimeIterateOptions = {
63
+ limit?: number;
64
+ sendingTimeout?: number;
65
+ };
66
+ export type CustomQueue = {
67
+ ping: () => Promise<MailTimePingResult>;
68
+ iterate: (opts?: MailTimeIterateOptions) => Promise<void> | void;
69
+ getPendingTo: (to: string, sendAt: number) => Promise<MailTimeTask | object | null>;
70
+ push: (email: MailTimeTask) => Promise<void> | void;
71
+ cancel: (uuid: string) => Promise<boolean>;
72
+ remove: (email: MailTimeTask | object, opts?: {
73
+ leaseTries: number;
74
+ leaseSendingAt: number;
75
+ }) => Promise<boolean>;
76
+ update: (email: MailTimeTask | object, updateObj: object) => Promise<boolean>;
77
+ ready?: () => Promise<void>;
78
+ };
79
+ export type MailTimeRejectedRecipient = {
80
+ address: string;
81
+ error: string;
82
+ };
83
+ export type MailTimeMailOptions = {
84
+ [key: string]: any;
85
+ to: string | string[];
86
+ sendAt?: Date | number;
87
+ template?: string;
88
+ concatSubject?: string;
89
+ text?: string | false;
90
+ html?: string | false;
91
+ subject?: string;
92
+ accepted?: string[];
93
+ rejected?: MailTimeRejectedRecipient[];
94
+ };
95
+ export type MailTimeConcatEmailsOptions = {
96
+ subject?: string;
97
+ };
98
+ export type MailTimeOptions = {
99
+ queue: RedisQueue | MongoQueue | PostgresQueue | CustomQueue;
100
+ type?: "server" | "client";
101
+ from?: string | ((transport: MailTimeTransport) => string);
102
+ transports?: MailTimeTransport[];
103
+ strategy?: "backup" | "balancer";
104
+ failsToNext?: number;
105
+ retries?: number;
106
+ maxTries?: number;
107
+ retryDelay?: number;
108
+ interval?: number;
109
+ keepHistory?: boolean;
110
+ concatEmails?: boolean | MailTimeConcatEmailsOptions;
111
+ concatSubject?: string;
112
+ concatDelimiter?: string;
113
+ concatDelay?: number;
114
+ concatThrottling?: number;
115
+ revolvingInterval?: number;
116
+ mode?: "one" | "batch";
117
+ concurrency?: number;
118
+ sendingTimeout?: number;
119
+ verifyTransports?: boolean;
120
+ template?: string;
121
+ prefix?: string;
122
+ debug?: boolean;
123
+ josk?: MailTimeJoSkOptions;
124
+ onError?: (error: unknown, email: MailTimeTask | null, details?: object) => void;
125
+ onSent?: (email: MailTimeTask, details?: object) => void;
126
+ };
127
+ /**
128
+ * @typedef {import('./presets.js').MailTimePresetName} MailTimePresetName
129
+ */
130
+ /**
131
+ * @typedef {import('./presets.js').MailTimePresetConfig} MailTimePresetConfig
132
+ */
133
+ /**
134
+ * @typedef {{ status: string, code: number, statusCode: number, paused?: boolean, error?: unknown }} MailTimePingResult
135
+ */
136
+ /**
137
+ * @typedef {{ [key: string]: any, query?: (queryText: string, values?: unknown[]) => Promise<{ rows?: unknown[], rowCount?: number | null }> }} MailTimeStorageClient
138
+ */
139
+ /**
140
+ * @typedef {{ [key: string]: any }} MailTimeMongoDb
141
+ */
142
+ /**
143
+ * @typedef {{ [key: string]: any }} MailTimeTransport
144
+ */
145
+ /**
146
+ * @typedef {{ [key: string]: any, type?: 'mongo' | 'redis' | 'postgres', client?: MailTimeStorageClient, db?: MailTimeMongoDb, prefix?: string, resetOnInit?: boolean, useHashTags?: boolean }} MailTimeJoSkAdapterOptions
147
+ */
148
+ /**
149
+ * @typedef {{ [key: string]: any, adapter: MailTimeJoSkAdapterOptions | object, debug?: boolean, autoClear?: boolean, zombieTime?: number, minRevolvingDelay?: number, maxRevolvingDelay?: number, execute?: 'batch' | 'one', concurrency?: number, lockOwnerId?: string, resetOnInit?: boolean, onError?: (title: string, details: object) => void, onExecuted?: (uid: string, details: object) => void }} MailTimeJoSkOptions
150
+ */
151
+ /**
152
+ * @typedef {{ uuid: string, to?: string | string[], tries: number, sendAt: number, isSent: boolean, isCancelled: boolean, isFailed: boolean, isSending?: boolean, sendingAt?: number, template?: string | false, transport: number, concatSubject?: string | false, mailOptions: MailTimeMailOptions[] }} MailTimeTask
153
+ */
154
+ /**
155
+ * @typedef {{ limit?: number, sendingTimeout?: number }} MailTimeIterateOptions
156
+ */
157
+ /**
158
+ * @typedef {{ ping: () => Promise<MailTimePingResult>, iterate: (opts?: MailTimeIterateOptions) => Promise<void> | void, getPendingTo: (to: string, sendAt: number) => Promise<MailTimeTask | object | null>, push: (email: MailTimeTask) => Promise<void> | void, cancel: (uuid: string) => Promise<boolean>, remove: (email: MailTimeTask | object, opts?: { leaseTries: number, leaseSendingAt: number }) => Promise<boolean>, update: (email: MailTimeTask | object, updateObj: object) => Promise<boolean>, ready?: () => Promise<void> }} CustomQueue
159
+ */
160
+ /**
161
+ * @typedef {{ address: string, error: string }} MailTimeRejectedRecipient
162
+ */
163
+ /**
164
+ * @typedef {{ [key: string]: any, to: string | string[], sendAt?: Date | number, template?: string, concatSubject?: string, text?: string | false, html?: string | false, subject?: string, accepted?: string[], rejected?: MailTimeRejectedRecipient[] }} MailTimeMailOptions
165
+ */
166
+ /**
167
+ * @typedef {{ subject?: string }} MailTimeConcatEmailsOptions
168
+ */
169
+ /**
170
+ * @typedef {{ queue: RedisQueue | MongoQueue | PostgresQueue | CustomQueue, type?: 'server' | 'client', from?: string | ((transport: MailTimeTransport) => string), transports?: MailTimeTransport[], strategy?: 'backup' | 'balancer', failsToNext?: number, retries?: number, maxTries?: number, retryDelay?: number, interval?: number, keepHistory?: boolean, concatEmails?: boolean | MailTimeConcatEmailsOptions, concatSubject?: string, concatDelimiter?: string, concatDelay?: number, concatThrottling?: number, revolvingInterval?: number, mode?: 'one' | 'batch', concurrency?: number, sendingTimeout?: number, verifyTransports?: boolean, template?: string, prefix?: string, debug?: boolean, josk?: MailTimeJoSkOptions, onError?: (error: unknown, email: MailTimeTask | null, details?: object) => void, onSent?: (email: MailTimeTask, details?: object) => void }} MailTimeOptions
171
+ */
172
+ /** Class of MailTime */
173
+ export class MailTime {
174
+ static set Template(newVal: string);
175
+ static get Template(): string;
176
+ /**
177
+ * Create a MailTime instance
178
+ * @param {MailTimeOptions} opts - configuration object
179
+ */
180
+ constructor(opts: MailTimeOptions);
181
+ queue: MongoQueue | RedisQueue | PostgresQueue | CustomQueue;
182
+ debug: boolean;
183
+ type: "server" | "client";
184
+ prefix: string;
185
+ maxTries: number;
186
+ retryDelay: number;
187
+ template: string;
188
+ keepHistory: boolean;
189
+ onSent: (email: MailTimeTask, details?: object) => void;
190
+ onError: (error: unknown, email: MailTimeTask | null, details?: object) => void;
191
+ revolvingInterval: number;
192
+ mode: "one" | "batch";
193
+ concurrency: number;
194
+ sendingTimeout: number;
195
+ failsToNext: number;
196
+ strategy: "backup" | "balancer";
197
+ transports: MailTimeTransport[];
198
+ transport: number;
199
+ verifyTransports: boolean;
200
+ from: boolean | ((transport: MailTimeTransport) => string);
201
+ /** @type {string} */
202
+ concatSubject: string;
203
+ concatEmails: boolean;
204
+ concatDelimiter: string;
205
+ concatDelay: number;
206
+ josk: {
207
+ [key: string]: any;
208
+ adapter: MailTimeJoSkAdapterOptions | object;
209
+ debug?: boolean;
210
+ autoClear?: boolean;
211
+ zombieTime?: number;
212
+ minRevolvingDelay?: number;
213
+ maxRevolvingDelay?: number;
214
+ execute?: "batch" | "one";
215
+ concurrency?: number;
216
+ lockOwnerId?: string;
217
+ resetOnInit?: boolean;
218
+ onError?: (title: string, details: object) => void;
219
+ onExecuted?: (uid: string, details: object) => void;
220
+ } | undefined;
221
+ scheduler: JoSk | undefined;
222
+ /**
223
+ * @async
224
+ * @memberOf MailTime
225
+ * @name ping
226
+ * @description Check package readiness and connection to Storage
227
+ * @returns {Promise<MailTimePingResult>}
228
+ * @throws {Error}
229
+ */
230
+ ping(): Promise<MailTimePingResult>;
231
+ /**
232
+ * @async
233
+ * @memberOf MailTime
234
+ * @name ready
235
+ * @description Wait until queue and scheduler storage are ready
236
+ * @returns {Promise<MailTime>}
237
+ */
238
+ ready(): Promise<MailTime>;
239
+ /**
240
+ * @memberOf MailTime
241
+ * @name destroy
242
+ * @description Stop the scheduler and block future dispatches. Without `{ drain: true }`, any in-flight SMTP attempts are neutralized on completion — they perform no storage writes, no `onSent`/`onError` callbacks, and no logging once `destroy()` returns; their claimed rows are recovered by stale-lock timeout (`sendingTimeout`). Pass `{ drain: true }` to instead let in-flight attempts run to completion (returns a Promise that resolves once they settle).
243
+ * @param {{ drain?: boolean }} [opts]
244
+ * @returns {boolean | Promise<boolean>}
245
+ */
246
+ destroy(opts?: {
247
+ drain?: boolean;
248
+ }): boolean | Promise<boolean>;
249
+ /**
250
+ * @async
251
+ * @memberOf MailTime
252
+ * @name drain
253
+ * @description Wait for all in-flight email send attempts to settle
254
+ * @returns {Promise<void>}
255
+ */
256
+ drain(): Promise<void>;
257
+ /**
258
+ * @memberOf MailTime
259
+ * @name pause
260
+ * @description Pause this server instance from competing for the queue-drain lease. In-flight SMTP sends finish; peer server instances keep draining. Reversible (unlike `destroy()`). No-op on `client` instances or after `destroy()`. To stop scanning *and* wait for in-flight sends: `mailTime.pause(); await mailTime.drain();`.
261
+ * @returns {boolean} `true` if newly paused; `false` if already paused, a client instance, or destroyed
262
+ */
263
+ pause(): boolean;
264
+ /**
265
+ * @memberOf MailTime
266
+ * @name resume
267
+ * @description Resume competing for the queue-drain lease after `pause()`; triggers an immediate scan. No-op on `client` instances, after `destroy()`, or when not paused.
268
+ * @returns {boolean} `true` if newly resumed; `false` if not paused, a client instance, or destroyed
269
+ */
270
+ resume(): boolean;
271
+ /**
272
+ * @memberOf MailTime
273
+ * @name isPaused
274
+ * @description Whether this instance is currently paused from draining the queue. Always `false` on `client` instances.
275
+ * @returns {boolean}
276
+ */
277
+ get isPaused(): boolean;
278
+ /**
279
+ * @memberOf MailTime
280
+ * @name send
281
+ * @description alias of `sendMail`
282
+ * @param {MailTimeMailOptions} opts - email options
283
+ * @returns {Promise<string>} uuid of the email
284
+ */
285
+ send(opts: MailTimeMailOptions): Promise<string>;
286
+ /**
287
+ * @async
288
+ * @memberOf MailTime
289
+ * @name sendMail
290
+ * @description add email to the queue or append to existing letter if {concatEmails: true}
291
+ * @param {MailTimeMailOptions} opts - email options
292
+ * @returns {Promise<string>} uuid of the email
293
+ * @throws {Error}
294
+ */
295
+ sendMail(opts?: MailTimeMailOptions): Promise<string>;
296
+ /**
297
+ * @async
298
+ * @memberOf MailTime
299
+ * @name cancel
300
+ * @description alias of `cancelMail`
301
+ * @param {string|Promise<string>} uuid - uuid returned from `send` or `sendMail`
302
+ * @returns {Promise<boolean>} returns `true` if cancelled or `false` if not found was sent or was cancelled previously
303
+ */
304
+ cancel(uuid: string | Promise<string>): Promise<boolean>;
305
+ /**
306
+ * @async
307
+ * @memberOf MailTime
308
+ * @name cancelMail
309
+ * @description remove email from the queue or mark as `isCancelled`
310
+ * @param {string|Promise<string>} uuid - uuid returned from `send` or `sendMail`
311
+ * @returns {Promise<boolean>} returns `true` if cancelled or `false` if not found was sent or was cancelled previously
312
+ */
313
+ cancelMail(uuid: string | Promise<string>): Promise<boolean>;
314
+ }
315
+ import { MongoQueue } from './adapters/mongo.js';
316
+ import { RedisQueue } from './adapters/redis.js';
317
+ import { PostgresQueue } from './adapters/postgres.js';
318
+ import { mailTimePreset } from './presets.js';
319
+ import { presets } from './presets.js';
320
+ import { presetNames } from './presets.js';
321
+ import { JoSk } from 'josk';
322
+ export { MongoQueue, RedisQueue, PostgresQueue, mailTimePreset, presets, presetNames };