mailery 0.19.1 → 0.20.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/dist/index.cjs +54 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +54 -26
- package/dist/index.js.map +1 -1
- package/dist/{null-DxTHQSrJ.d.cts → null-B3N6bTpc.d.cts} +33 -5
- package/dist/{null-DxTHQSrJ.d.ts → null-B3N6bTpc.d.ts} +33 -5
- package/dist/testing.cjs +52 -24
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +3 -3
- package/dist/testing.d.ts +3 -3
- package/dist/testing.js +52 -24
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2500,7 +2500,7 @@ function derivePlaintext(html) {
|
|
|
2500
2500
|
var PLAIN_TEXT = { noEscape: true };
|
|
2501
2501
|
async function renderTemplate(template, ctx, opts = {}) {
|
|
2502
2502
|
const hb = makeHandlebars(opts.helpers);
|
|
2503
|
-
const subject = hb.compile(template.subject)(ctx);
|
|
2503
|
+
const subject = hb.compile(template.subject, PLAIN_TEXT)(ctx).replace(/[\r\n]+/g, " ");
|
|
2504
2504
|
const preheader = hb.compile(template.preheader)(ctx);
|
|
2505
2505
|
let html;
|
|
2506
2506
|
if (template.body.html) {
|
|
@@ -5148,6 +5148,7 @@ async function processScheduledBroadcasts2(ctx) {
|
|
|
5148
5148
|
}
|
|
5149
5149
|
|
|
5150
5150
|
// src/server/mailer.ts
|
|
5151
|
+
var STORAGE_REQUIRED = "Mailer.init: give exactly one of `db` (an open Db) or `mongo` (a connection mailery opens)";
|
|
5151
5152
|
var Mailer = class _Mailer {
|
|
5152
5153
|
db;
|
|
5153
5154
|
collections;
|
|
@@ -5157,6 +5158,8 @@ var Mailer = class _Mailer {
|
|
|
5157
5158
|
config;
|
|
5158
5159
|
events;
|
|
5159
5160
|
queueDriver;
|
|
5161
|
+
/** The client `Mailer.init` opened from `config.mongo`; closed by `stop()`. Null when the host gave `db`. */
|
|
5162
|
+
ownedClient;
|
|
5160
5163
|
workersStarted = false;
|
|
5161
5164
|
runnerContext;
|
|
5162
5165
|
constructor(args) {
|
|
@@ -5166,6 +5169,7 @@ var Mailer = class _Mailer {
|
|
|
5166
5169
|
this.adapter = args.adapter;
|
|
5167
5170
|
this.providers = args.providers;
|
|
5168
5171
|
this.queueDriver = args.queueDriver;
|
|
5172
|
+
this.ownedClient = args.ownedClient;
|
|
5169
5173
|
this.queues = args.queueDriver.queues;
|
|
5170
5174
|
this.events = args.events;
|
|
5171
5175
|
this.runnerContext = {
|
|
@@ -5262,36 +5266,58 @@ var Mailer = class _Mailer {
|
|
|
5262
5266
|
});
|
|
5263
5267
|
}
|
|
5264
5268
|
static async init(input) {
|
|
5265
|
-
|
|
5266
|
-
if (!resolveProvider(
|
|
5269
|
+
if (input.db == null === (input.mongo == null)) throw new Error(STORAGE_REQUIRED);
|
|
5270
|
+
if (!resolveProvider(input.providers, input.defaultProvider)) {
|
|
5267
5271
|
throw new Error(
|
|
5268
|
-
`defaultProvider "${
|
|
5272
|
+
`defaultProvider "${input.defaultProvider}" is not a registered provider. Registered: ${registeredProviderNames(input.providers).join(", ") || "(none)"}`
|
|
5269
5273
|
);
|
|
5270
5274
|
}
|
|
5271
|
-
if (
|
|
5275
|
+
if (input.defaultTransactionalProvider != null && !resolveProvider(input.providers, input.defaultTransactionalProvider)) {
|
|
5272
5276
|
throw new Error(
|
|
5273
|
-
`defaultTransactionalProvider "${
|
|
5277
|
+
`defaultTransactionalProvider "${input.defaultTransactionalProvider}" is not a registered provider. Registered: ${registeredProviderNames(input.providers).join(", ") || "(none)"}`
|
|
5274
5278
|
);
|
|
5275
5279
|
}
|
|
5276
|
-
if (
|
|
5280
|
+
if (input.varsAdapter) {
|
|
5277
5281
|
const { assertNoReservedVarKeys: assertNoReservedVarKeys2 } = await Promise.resolve().then(() => (init_vars(), vars_exports));
|
|
5278
|
-
assertNoReservedVarKeys2(
|
|
5279
|
-
}
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
await
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5282
|
+
assertNoReservedVarKeys2(input.varsAdapter);
|
|
5283
|
+
}
|
|
5284
|
+
let ownedClient = null;
|
|
5285
|
+
let db;
|
|
5286
|
+
if (input.mongo) {
|
|
5287
|
+
const { MongoClient } = await import('mongodb');
|
|
5288
|
+
ownedClient = await MongoClient.connect(input.mongo.uri, input.mongo.clientOptions);
|
|
5289
|
+
db = ownedClient.db(input.mongo.dbName);
|
|
5290
|
+
} else if (input.db) {
|
|
5291
|
+
db = input.db;
|
|
5292
|
+
} else {
|
|
5293
|
+
throw new Error(STORAGE_REQUIRED);
|
|
5294
|
+
}
|
|
5295
|
+
try {
|
|
5296
|
+
const config = resolveConfig({
|
|
5297
|
+
...input,
|
|
5298
|
+
db,
|
|
5299
|
+
adapter: typeof input.adapter === "function" ? input.adapter(db) : input.adapter
|
|
5300
|
+
});
|
|
5301
|
+
const collections = getCollections(config.db, config.collectionPrefix);
|
|
5302
|
+
await ensureIndexes(config.db, config.collectionPrefix);
|
|
5303
|
+
const queueDriver = await createQueueDriver(config.queue, config.db);
|
|
5304
|
+
if (!config.workerless && config.queue.driver !== "noop") {
|
|
5305
|
+
await queueDriver.scheduleRepeatingTick(config.tickIntervalSeconds);
|
|
5306
|
+
}
|
|
5307
|
+
return new _Mailer({
|
|
5308
|
+
config,
|
|
5309
|
+
db: config.db,
|
|
5310
|
+
collections,
|
|
5311
|
+
adapter: config.adapter,
|
|
5312
|
+
providers: config.providers,
|
|
5313
|
+
queueDriver,
|
|
5314
|
+
events: new EventRegistry(),
|
|
5315
|
+
ownedClient
|
|
5316
|
+
});
|
|
5317
|
+
} catch (err) {
|
|
5318
|
+
await ownedClient?.close();
|
|
5319
|
+
throw err;
|
|
5320
|
+
}
|
|
5295
5321
|
}
|
|
5296
5322
|
// -------------------------------------------------------------------------
|
|
5297
5323
|
// Event registration + firing
|
|
@@ -5764,6 +5790,8 @@ var Mailer = class _Mailer {
|
|
|
5764
5790
|
async stop() {
|
|
5765
5791
|
await this.queueDriver.close();
|
|
5766
5792
|
this.workersStarted = false;
|
|
5793
|
+
await this.ownedClient?.close();
|
|
5794
|
+
this.ownedClient = null;
|
|
5767
5795
|
}
|
|
5768
5796
|
/** Used internally by the admin router and tests; not part of the public API. */
|
|
5769
5797
|
getRunnerContext() {
|
|
@@ -9579,7 +9607,7 @@ function unitToMs2(value, unit) {
|
|
|
9579
9607
|
}
|
|
9580
9608
|
|
|
9581
9609
|
// src/server/api/agent.ts
|
|
9582
|
-
var VERSION = "0.
|
|
9610
|
+
var VERSION = "0.20.0" ;
|
|
9583
9611
|
var broadcastCountSchema = zod.z.object({
|
|
9584
9612
|
recipientCap: zod.z.number().int().positive().max(1e7).nullable().optional()
|
|
9585
9613
|
});
|
|
@@ -11646,7 +11674,7 @@ var DEDUPE_POLICIES = [
|
|
|
11646
11674
|
];
|
|
11647
11675
|
|
|
11648
11676
|
// src/server/index.ts
|
|
11649
|
-
var VERSION2 = "0.
|
|
11677
|
+
var VERSION2 = "0.20.0" ;
|
|
11650
11678
|
|
|
11651
11679
|
exports.DEDUPE_POLICIES = DEDUPE_POLICIES;
|
|
11652
11680
|
exports.DEFAULT_BOT_UA_RE = DEFAULT_BOT_UA_RE;
|