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