emdash-smtp 0.3.1 → 0.3.2
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/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +18 -24
- package/dist/plugin.mjs.map +1 -1
- package/package.json +3 -3
package/dist/plugin.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;iBAkFgB,YAAA,CAAA,GAAgB,cAAA"}
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SMTP_ADMIN_PAGES, SMTP_ADMIN_WIDGETS, SMTP_PLUGIN_ID, SMTP_PLUGIN_VERSION, collectAllowedHosts, createDeliveryLogRecord, deliverWithConfiguredProvider, handleAdminInteraction,
|
|
1
|
+
import { SMTP_ADMIN_PAGES, SMTP_ADMIN_WIDGETS, SMTP_PLUGIN_ID, SMTP_PLUGIN_VERSION, collectAllowedHosts, createDeliveryLogRecord, deliverWithConfiguredProvider, handleAdminInteraction, writeDeliveryLog } from "emdash-smtp-core";
|
|
2
2
|
import { definePlugin } from "emdash";
|
|
3
3
|
import { sendmailSend, smtpSend } from "emdash-smtp-node-transports";
|
|
4
4
|
|
|
@@ -53,30 +53,24 @@ function createPlugin() {
|
|
|
53
53
|
pages: [...SMTP_ADMIN_PAGES],
|
|
54
54
|
widgets: [...SMTP_ADMIN_WIDGETS]
|
|
55
55
|
},
|
|
56
|
-
hooks: {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
throw err;
|
|
72
|
-
}
|
|
56
|
+
hooks: { "email:deliver": {
|
|
57
|
+
exclusive: true,
|
|
58
|
+
handler: async (event, ctx) => {
|
|
59
|
+
const source = event.source || ctx.plugin.id;
|
|
60
|
+
try {
|
|
61
|
+
await logSuccessfulDelivery(ctx, event, source, await deliverWithConfiguredProvider({
|
|
62
|
+
ctx,
|
|
63
|
+
runtime: createTrustedRuntime(ctx),
|
|
64
|
+
message: event.message,
|
|
65
|
+
source
|
|
66
|
+
}));
|
|
67
|
+
} catch (error) {
|
|
68
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
69
|
+
await logFailedDelivery(ctx, event, source, err);
|
|
70
|
+
throw err;
|
|
73
71
|
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
ctx,
|
|
77
|
-
runtime: createTrustedRuntime(ctx)
|
|
78
|
-
}) }
|
|
79
|
-
},
|
|
72
|
+
}
|
|
73
|
+
} },
|
|
80
74
|
routes: { admin: { handler: (async (routeCtx) => {
|
|
81
75
|
return handleAdminInteraction({
|
|
82
76
|
ctx: routeCtx,
|
package/dist/plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import { definePlugin } from \"emdash\";\nimport type { PluginContext, ResolvedPlugin } from \"emdash\";\n\nimport {\n\tcollectAllowedHosts,\n\tcreateDeliveryLogRecord,\n\tdeliverWithConfiguredProvider,\n\thandleAdminInteraction,\n\
|
|
1
|
+
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import { definePlugin } from \"emdash\";\nimport type { PluginContext, ResolvedPlugin } from \"emdash\";\n\nimport {\n\tcollectAllowedHosts,\n\tcreateDeliveryLogRecord,\n\tdeliverWithConfiguredProvider,\n\thandleAdminInteraction,\n\tSMTP_ADMIN_PAGES,\n\tSMTP_ADMIN_WIDGETS,\n\tSMTP_PLUGIN_ID,\n\tSMTP_PLUGIN_VERSION,\n\ttype AdminInteraction,\n\ttype DeliveryRuntime,\n\ttype SmtpPluginContextLike,\n\twriteDeliveryLog,\n} from \"emdash-smtp-core\";\nimport { sendmailSend, smtpSend } from \"emdash-smtp-node-transports\";\n\nfunction createTrustedRuntime(ctx: PluginContext): DeliveryRuntime {\n\treturn {\n\t\tvariant: \"trusted\",\n\t\tfetch: ctx.http ? (url, init) => ctx.http!.fetch(url, init) : undefined,\n\t\tsmtpSend,\n\t\tsendmailSend,\n\t};\n}\n\ninterface TrustedEmailDeliverEvent {\n\tmessage: {\n\t\tto: string;\n\t\tsubject: string;\n\t\ttext: string;\n\t\thtml?: string;\n\t};\n\tsource: string;\n}\n\nasync function logSuccessfulDelivery(\n\tctx: SmtpPluginContextLike,\n\tevent: TrustedEmailDeliverEvent,\n\tsource: string,\n\tresult: Awaited<ReturnType<typeof deliverWithConfiguredProvider>>,\n): Promise<void> {\n\tawait writeDeliveryLog(\n\t\tctx,\n\t\tcreateDeliveryLogRecord({\n\t\t\tproviderId: result.providerId,\n\t\t\tstatus: \"sent\",\n\t\t\tmessage: {\n\t\t\t\tto: event.message.to,\n\t\t\t\tsubject: event.message.subject,\n\t\t\t},\n\t\t\tsource,\n\t\t\tdurationMs: result.durationMs,\n\t\t\tremoteMessageId: result.remoteMessageId,\n\t\t}),\n\t);\n}\n\nasync function logFailedDelivery(\n\tctx: SmtpPluginContextLike,\n\tevent: TrustedEmailDeliverEvent,\n\tsource: string,\n\terror: Error,\n): Promise<void> {\n\tawait writeDeliveryLog(\n\t\tctx,\n\t\tcreateDeliveryLogRecord({\n\t\t\tproviderId: \"unknown\",\n\t\t\tstatus: \"failed\",\n\t\t\tmessage: {\n\t\t\t\tto: event.message.to,\n\t\t\t\tsubject: event.message.subject,\n\t\t\t},\n\t\t\tsource,\n\t\t\tdurationMs: 0,\n\t\t\terrorMessage: error.message,\n\t\t}),\n\t);\n}\n\nexport function createPlugin(): ResolvedPlugin {\n\treturn definePlugin({\n\t\tid: SMTP_PLUGIN_ID,\n\t\tversion: SMTP_PLUGIN_VERSION,\n\t\tcapabilities: [\"email:provide\", \"network:fetch\"],\n\t\tallowedHosts: collectAllowedHosts(\"trusted\"),\n\t\tstorage: {\n\t\t\tdeliveryLogs: {\n\t\t\t\tindexes: [\"providerId\", \"status\", \"createdAt\", \"source\"],\n\t\t\t},\n\t\t},\n\t\tadmin: {\n\t\t\tpages: [...SMTP_ADMIN_PAGES],\n\t\t\twidgets: [...SMTP_ADMIN_WIDGETS],\n\t\t},\n\t\thooks: {\n\t\t\t\"email:deliver\": {\n\t\t\t\texclusive: true,\n\t\t\t\thandler: async (event: TrustedEmailDeliverEvent, ctx: PluginContext) => {\n\t\t\t\t\tconst source = event.source || ctx.plugin.id;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = await deliverWithConfiguredProvider({\n\t\t\t\t\t\t\tctx: ctx as unknown as SmtpPluginContextLike,\n\t\t\t\t\t\t\truntime: createTrustedRuntime(ctx),\n\t\t\t\t\t\t\tmessage: event.message,\n\t\t\t\t\t\t\tsource,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tawait logSuccessfulDelivery(\n\t\t\t\t\t\t\tctx as unknown as SmtpPluginContextLike,\n\t\t\t\t\t\t\tevent,\n\t\t\t\t\t\t\tsource,\n\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconst err = error instanceof Error ? error : new Error(String(error));\n\t\t\t\t\t\tawait logFailedDelivery(ctx as unknown as SmtpPluginContextLike, event, source, err);\n\t\t\t\t\t\tthrow err;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\troutes: {\n\t\t\tadmin: {\n\t\t\t\thandler: (async (\n\t\t\t\t\trouteCtx: PluginContext & { input: unknown; request: unknown },\n\t\t\t\t) => {\n\t\t\t\t\treturn handleAdminInteraction({\n\t\t\t\t\t\tctx: routeCtx as unknown as SmtpPluginContextLike,\n\t\t\t\t\t\tvariant: \"trusted\",\n\t\t\t\t\t\truntime: createTrustedRuntime(routeCtx),\n\t\t\t\t\t\tinteraction: (routeCtx.input ?? { type: \"page_load\", page: \"/providers\" }) as AdminInteraction,\n\t\t\t\t\t});\n\t\t\t\t}) as never,\n\t\t\t},\n\t\t},\n\t});\n}\n\nexport default createPlugin;\n"],"mappings":";;;;;AAmBA,SAAS,qBAAqB,KAAqC;AAClE,QAAO;EACN,SAAS;EACT,OAAO,IAAI,QAAQ,KAAK,SAAS,IAAI,KAAM,MAAM,KAAK,KAAK,GAAG;EAC9D;EACA;EACA;;AAaF,eAAe,sBACd,KACA,OACA,QACA,QACgB;AAChB,OAAM,iBACL,KACA,wBAAwB;EACvB,YAAY,OAAO;EACnB,QAAQ;EACR,SAAS;GACR,IAAI,MAAM,QAAQ;GAClB,SAAS,MAAM,QAAQ;GACvB;EACD;EACA,YAAY,OAAO;EACnB,iBAAiB,OAAO;EACxB,CAAC,CACF;;AAGF,eAAe,kBACd,KACA,OACA,QACA,OACgB;AAChB,OAAM,iBACL,KACA,wBAAwB;EACvB,YAAY;EACZ,QAAQ;EACR,SAAS;GACR,IAAI,MAAM,QAAQ;GAClB,SAAS,MAAM,QAAQ;GACvB;EACD;EACA,YAAY;EACZ,cAAc,MAAM;EACpB,CAAC,CACF;;AAGF,SAAgB,eAA+B;AAC9C,QAAO,aAAa;EACnB,IAAI;EACJ,SAAS;EACT,cAAc,CAAC,iBAAiB,gBAAgB;EAChD,cAAc,oBAAoB,UAAU;EAC5C,SAAS,EACR,cAAc,EACb,SAAS;GAAC;GAAc;GAAU;GAAa;GAAS,EACxD,EACD;EACD,OAAO;GACN,OAAO,CAAC,GAAG,iBAAiB;GAC5B,SAAS,CAAC,GAAG,mBAAmB;GAChC;EACD,OAAO,EACN,iBAAiB;GAChB,WAAW;GACX,SAAS,OAAO,OAAiC,QAAuB;IACvE,MAAM,SAAS,MAAM,UAAU,IAAI,OAAO;AAC1C,QAAI;AAOH,WAAM,sBACL,KACA,OACA,QATc,MAAM,8BAA8B;MAC7C;MACL,SAAS,qBAAqB,IAAI;MAClC,SAAS,MAAM;MACf;MACA,CAAC,CAMD;aACO,OAAO;KACf,MAAM,MAAM,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;AACrE,WAAM,kBAAkB,KAAyC,OAAO,QAAQ,IAAI;AACpF,WAAM;;;GAGR,EACD;EACD,QAAQ,EACP,OAAO,EACN,UAAU,OACT,aACI;AACJ,UAAO,uBAAuB;IAC7B,KAAK;IACL,SAAS;IACT,SAAS,qBAAqB,SAAS;IACvC,aAAc,SAAS,SAAS;KAAE,MAAM;KAAa,MAAM;KAAc;IACzE,CAAC;MAEH,EACD;EACD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "emdash-smtp",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Trusted full-parity SMTP and transactional email plugin for EmDash",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
],
|
|
30
30
|
"author": "Mason James",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"emdash-smtp-core": "0.3.
|
|
33
|
-
"emdash-smtp-node-transports": "0.3.
|
|
32
|
+
"emdash-smtp-core": "0.3.2",
|
|
33
|
+
"emdash-smtp-node-transports": "0.3.2"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"emdash": ">=0.1.0"
|