ts-mailkit 2.0.1 → 3.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.
Files changed (34) hide show
  1. package/README.md +114 -63
  2. package/dist/core/client.d.ts +35 -40
  3. package/dist/core/client.d.ts.map +1 -1
  4. package/dist/core/errors.d.ts +3 -0
  5. package/dist/core/errors.d.ts.map +1 -1
  6. package/dist/core/types.d.ts +126 -7
  7. package/dist/core/types.d.ts.map +1 -1
  8. package/dist/index.cjs +329 -68
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.ts +14 -13
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +327 -68
  13. package/dist/index.js.map +1 -1
  14. package/dist/renderers/default/default-renderer.d.ts +2 -2
  15. package/dist/renderers/renderer.interface.d.ts +1 -1
  16. package/dist/templates/factory.d.ts +1 -1
  17. package/dist/templates/factory.d.ts.map +1 -1
  18. package/dist/templates/template-builder.d.ts +36 -0
  19. package/dist/templates/template-builder.d.ts.map +1 -0
  20. package/dist/transports/console/console-sender.d.ts +7 -2
  21. package/dist/transports/console/console-sender.d.ts.map +1 -1
  22. package/dist/transports/cpaas/cpaas-sender.d.ts +51 -0
  23. package/dist/transports/cpaas/cpaas-sender.d.ts.map +1 -0
  24. package/dist/transports/cpaas/types.d.ts +133 -0
  25. package/dist/transports/cpaas/types.d.ts.map +1 -0
  26. package/dist/transports/memory/memory-sender.d.ts +26 -6
  27. package/dist/transports/memory/memory-sender.d.ts.map +1 -1
  28. package/dist/transports/sender.interface.d.ts +34 -3
  29. package/dist/transports/sender.interface.d.ts.map +1 -1
  30. package/package.json +39 -37
  31. package/dist/transports/zeptomail/types.d.ts +0 -47
  32. package/dist/transports/zeptomail/types.d.ts.map +0 -1
  33. package/dist/transports/zeptomail/zeptomail-sender.d.ts +0 -22
  34. package/dist/transports/zeptomail/zeptomail-sender.d.ts.map +0 -1
@@ -1,5 +1,6 @@
1
- import type { SendMailOptions, SendResult } from '../../core/types.js';
2
- import type { IEmailSender } from '../sender.interface.js';
1
+ import type { SendMailOptions, SendResult } from "../../core/types.js";
2
+ import type { BulkKnownTemplateSendOptions, BulkSendOptions, KnownTemplateSendOptions } from "../../core/types.js";
3
+ import type { IEmailSender } from "../sender.interface.js";
3
4
  /**
4
5
  * In-memory email sender for automated testing, local development, and CI environments.
5
6
  * Captures all dispatched emails and provides inspection methods.
@@ -7,22 +8,41 @@ import type { IEmailSender } from '../sender.interface.js';
7
8
  export declare class MemoryEmailSender implements IEmailSender {
8
9
  readonly name = "memory";
9
10
  private sentMails;
11
+ private sentBulkMails;
12
+ private sentTemplateMails;
13
+ private sentBulkTemplateMails;
10
14
  private nextId;
15
+ private result;
11
16
  send(options: SendMailOptions): Promise<SendResult>;
17
+ sendBulk(options: BulkSendOptions): Promise<SendResult>;
18
+ sendKnownTemplate(options: KnownTemplateSendOptions): Promise<SendResult>;
19
+ sendBulkKnownTemplate(options: BulkKnownTemplateSendOptions): Promise<SendResult>;
12
20
  /**
13
- * Returns a copy of all emails sent through this transport instance.
21
+ * Returns a copy of all single emails sent through this transport instance.
14
22
  */
15
23
  getSentMails(): SendMailOptions[];
16
24
  /**
17
- * Returns the most recent email sent, or undefined if no emails have been sent.
25
+ * Returns the most recent single email sent, or undefined if none have been sent.
18
26
  */
19
27
  getLastMail(): SendMailOptions | undefined;
20
28
  /**
21
- * Clears all recorded sent emails.
29
+ * Returns a copy of all bulk emails sent through this transport instance.
30
+ */
31
+ getSentBulkMails(): BulkSendOptions[];
32
+ /**
33
+ * Returns a copy of all single template emails sent through this transport instance.
34
+ */
35
+ getSentTemplateMails(): KnownTemplateSendOptions[];
36
+ /**
37
+ * Returns a copy of all bulk template emails sent through this transport instance.
38
+ */
39
+ getSentBulkTemplateMails(): BulkKnownTemplateSendOptions[];
40
+ /**
41
+ * Clears all recorded emails.
22
42
  */
23
43
  clear(): void;
24
44
  /**
25
- * Returns the total count of sent emails.
45
+ * Returns the total count of single emails sent.
26
46
  */
27
47
  count(): number;
28
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"memory-sender.d.ts","sourceRoot":"","sources":["../../../src/transports/memory/memory-sender.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;GAGG;AACH,qBAAa,iBAAkB,YAAW,YAAY;IACpD,QAAQ,CAAC,IAAI,YAAY;IAEzB,OAAO,CAAC,SAAS,CAAyB;IAC1C,OAAO,CAAC,MAAM,CAAK;IAEb,IAAI,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,CAQxD;IAED;;OAEG;IACH,YAAY,IAAI,eAAe,EAAE,CAEhC;IAED;;OAEG;IACH,WAAW,IAAI,eAAe,GAAG,SAAS,CAIzC;IAED;;OAEG;IACH,KAAK,IAAI,IAAI,CAEZ;IAED;;OAEG;IACH,KAAK,IAAI,MAAM,CAEd;CACF"}
1
+ {"version":3,"file":"memory-sender.d.ts","sourceRoot":"","sources":["../../../src/transports/memory/memory-sender.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EACV,4BAA4B,EAC5B,eAAe,EACf,wBAAwB,EACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;GAGG;AACH,qBAAa,iBAAkB,YAAW,YAAY;IACpD,QAAQ,CAAC,IAAI,YAAY;IAEzB,OAAO,CAAC,SAAS,CAAyB;IAC1C,OAAO,CAAC,aAAa,CAAyB;IAC9C,OAAO,CAAC,iBAAiB,CAAkC;IAC3D,OAAO,CAAC,qBAAqB,CAAsC;IACnE,OAAO,CAAC,MAAM,CAAK;IAEnB,OAAO,CAAC,MAAM;IAWR,IAAI,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,CAGxD;IAEK,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,CAG5D;IAEK,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,UAAU,CAAC,CAG9E;IAEK,qBAAqB,CAAC,OAAO,EAAE,4BAA4B,GAAG,OAAO,CAAC,UAAU,CAAC,CAGtF;IAED;;OAEG;IACH,YAAY,IAAI,eAAe,EAAE,CAEhC;IAED;;OAEG;IACH,WAAW,IAAI,eAAe,GAAG,SAAS,CAEzC;IAED;;OAEG;IACH,gBAAgB,IAAI,eAAe,EAAE,CAEpC;IAED;;OAEG;IACH,oBAAoB,IAAI,wBAAwB,EAAE,CAEjD;IAED;;OAEG;IACH,wBAAwB,IAAI,4BAA4B,EAAE,CAEzD;IAED;;OAEG;IACH,KAAK,IAAI,IAAI,CAKZ;IAED;;OAEG;IACH,KAAK,IAAI,MAAM,CAEd;CACF"}
@@ -1,20 +1,51 @@
1
- import type { SendMailOptions, SendResult } from '../core/types.js';
1
+ import type { SendMailOptions, SendResult } from "../core/types.js";
2
+ import type { BulkKnownTemplateSendOptions, BulkSendOptions, KnownTemplateSendOptions } from "../core/types.js";
2
3
  /**
3
4
  * Contract that every concrete email sender/transport must satisfy.
4
5
  * Implement this interface to create custom transports (e.g. SMTP, Resend, SendGrid, Postmark).
6
+ *
7
+ * Bulk/template capabilities are optional. Transports that do not implement
8
+ * them will cause `MailKit` to throw a `ConfigurationError` when those
9
+ * methods are used.
5
10
  */
6
11
  export interface IEmailSender {
7
12
  /**
8
- * Unique identifier for the transport (e.g., 'zeptomail', 'memory', 'console', 'smtp').
13
+ * Unique identifier for the transport (e.g., 'cpaas', 'memory', 'console', 'smtp').
9
14
  */
10
15
  readonly name: string;
11
16
  /**
12
17
  * Dispatches an email using the transport adapter.
13
18
  *
14
19
  * @param options Structured email options including recipients, subject, HTML, text, attachments, etc.
15
- * @returns A SendResult indicating success and optional provider messageId or response data.
20
+ * @returns A SendResult indicating success and optional provider messageId or raw response data.
16
21
  * @throws TransportError if the transport fails to send the email.
17
22
  */
18
23
  send(options: SendMailOptions): Promise<SendResult>;
24
+ /**
25
+ * Dispatches a batch of a single raw email content to many recipients.
26
+ * The provider delivers an individual copy to each recipient.
27
+ *
28
+ * @param options Structured bulk email options.
29
+ * @returns A SendResult indicating success and optional raw response data.
30
+ * @throws TransportError if the transport fails to send the batch.
31
+ */
32
+ sendBulk?(options: BulkSendOptions): Promise<SendResult>;
33
+ /**
34
+ * Dispatches a single email using a provider-side template.
35
+ *
36
+ * @param options Template identifier, recipient, and optional merge data.
37
+ * @returns A SendResult indicating success and optional raw response data.
38
+ * @throws TransportError if the transport fails to send the email.
39
+ */
40
+ sendKnownTemplate?(options: KnownTemplateSendOptions): Promise<SendResult>;
41
+ /**
42
+ * Dispatches a batch of emails using a provider-side template, with
43
+ * optional per-recipient merge data.
44
+ *
45
+ * @param options Template identifier, recipients, and optional merge data.
46
+ * @returns A SendResult indicating success and optional raw response data.
47
+ * @throws TransportError if the transport fails to send the batch.
48
+ */
49
+ sendBulkKnownTemplate?(options: BulkKnownTemplateSendOptions): Promise<SendResult>;
19
50
  }
20
51
  //# sourceMappingURL=sender.interface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sender.interface.d.ts","sourceRoot":"","sources":["../../src/transports/sender.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEpE;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;;;OAMG;IACH,IAAI,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACrD"}
1
+ {"version":3,"file":"sender.interface.d.ts","sourceRoot":"","sources":["../../src/transports/sender.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,KAAK,EACV,4BAA4B,EAC5B,eAAe,EACf,wBAAwB,EACzB,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;;;OAMG;IACH,IAAI,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAEpD;;;;;;;OAOG;IACH,QAAQ,CAAC,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAEzD;;;;;;OAMG;IACH,iBAAiB,CAAC,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAE3E;;;;;;;OAOG;IACH,qBAAqB,CAAC,CAAC,OAAO,EAAE,4BAA4B,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACpF"}
package/package.json CHANGED
@@ -1,12 +1,37 @@
1
1
  {
2
2
  "name": "ts-mailkit",
3
- "version": "2.0.1",
3
+ "version": "3.0.0",
4
4
  "description": "Strictly typed, modular, and composable email composition and dispatch library for TypeScript and modern edge runtimes.",
5
+ "keywords": [
6
+ "cpaas",
7
+ "dto",
8
+ "edge",
9
+ "email",
10
+ "mailer",
11
+ "transactional-email",
12
+ "typescript",
13
+ "workerd",
14
+ "zoho-mail"
15
+ ],
16
+ "homepage": "https://github.com/AD-RIAN-Studio/ts-mailkit#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/AD-RIAN-Studio/ts-mailkit/issues"
19
+ },
20
+ "license": "MIT",
21
+ "author": "AD-RIAN Studio",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/AD-RIAN-Studio/ts-mailkit.git"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "README.md"
29
+ ],
30
+ "type": "module",
31
+ "sideEffects": false,
5
32
  "main": "./dist/index.cjs",
6
33
  "module": "./dist/index.js",
7
34
  "types": "./dist/index.d.ts",
8
- "type": "module",
9
- "sideEffects": false,
10
35
  "exports": {
11
36
  ".": {
12
37
  "types": "./dist/index.d.ts",
@@ -17,46 +42,23 @@
17
42
  "publishConfig": {
18
43
  "access": "public"
19
44
  },
20
- "packageManager": "pnpm@11.22.0",
21
- "repository": {
22
- "type": "git",
23
- "url": "git+https://github.com/AD-RIAN-Studio/ts-mailkit.git"
24
- },
25
- "bugs": {
26
- "url": "https://github.com/AD-RIAN-Studio/ts-mailkit/issues"
27
- },
28
- "homepage": "https://github.com/AD-RIAN-Studio/ts-mailkit#readme",
29
- "files": [
30
- "dist",
31
- "README.md"
32
- ],
33
45
  "scripts": {
34
- "build": "tsdown && tsc --emitDeclarationOnly",
35
- "dev": "tsdown --watch",
46
+ "build": "vp pack && tsc --emitDeclarationOnly",
47
+ "dev": "vp pack --watch",
48
+ "check": "vp check",
49
+ "check:fix": "vp check --fix",
50
+ "lint": "vp lint",
51
+ "format": "vp fmt",
36
52
  "typecheck": "tsc --noEmit",
37
- "test": "vitest run test/unit",
38
- "test:unit": "vitest run test/unit",
39
- "test:watch": "vitest test/unit",
40
- "prepublishOnly": "pnpm run build && pnpm run test:unit"
53
+ "test": "vp test run test/unit",
54
+ "test:unit": "vp test run test/unit",
55
+ "test:watch": "vp test test/unit",
56
+ "prepublishOnly": "pnpm run check && pnpm run typecheck && pnpm run test:unit && pnpm run build"
41
57
  },
42
- "keywords": [
43
- "email",
44
- "mailer",
45
- "zeptomail",
46
- "zoho-mail",
47
- "typescript",
48
- "dto",
49
- "transactional-email",
50
- "edge",
51
- "workerd"
52
- ],
53
- "author": "AD-RIAN Studio",
54
- "license": "MIT",
55
58
  "devDependencies": {
56
59
  "@types/node": "^26.1.1",
57
- "tsdown": "^0.23.0",
58
60
  "tsx": "^4.19.3",
59
61
  "typescript": "^7.0.2",
60
- "vitest": "^3.0.7"
62
+ "vite-plus": "catalog:"
61
63
  }
62
64
  }
@@ -1,47 +0,0 @@
1
- import type { Recipient } from '../../core/types.js';
2
- export interface ZeptoMailHttpConfig {
3
- /**
4
- * Zoho ZeptoMail API host domain.
5
- * Examples: 'api.zeptomail.com', 'api.zeptomail.eu', 'api.zeptomail.in'
6
- * @default 'api.zeptomail.com'
7
- */
8
- apiHost?: string;
9
- /**
10
- * ZeptoMail Send Mail API Token.
11
- */
12
- apiToken: string;
13
- /**
14
- * Default verified sender email address or Recipient object.
15
- */
16
- from: Recipient;
17
- /**
18
- * Optional custom fetch implementation (useful for mocking, testing, or proxies).
19
- * Defaults to global `fetch`.
20
- */
21
- fetch?: typeof fetch;
22
- }
23
- export interface ZeptoMailAddressObject {
24
- address: string;
25
- name?: string;
26
- }
27
- export interface ZeptoMailRecipientWrapper {
28
- email_address: ZeptoMailAddressObject;
29
- }
30
- export interface ZeptoMailAttachmentPayload {
31
- name: string;
32
- content: string;
33
- mime_type?: string;
34
- cid?: string;
35
- }
36
- export interface ZeptoMailSendPayload {
37
- from: ZeptoMailAddressObject;
38
- to: ZeptoMailRecipientWrapper[];
39
- subject: string;
40
- htmlbody: string;
41
- textbody?: string;
42
- cc?: ZeptoMailRecipientWrapper[];
43
- bcc?: ZeptoMailRecipientWrapper[];
44
- reply_to?: ZeptoMailAddressObject[];
45
- attachments?: ZeptoMailAttachmentPayload[];
46
- }
47
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/transports/zeptomail/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,EAAE,SAAS,CAAC;IAEhB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,yBAAyB;IACxC,aAAa,EAAE,sBAAsB,CAAC;CACvC;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,EAAE,EAAE,yBAAyB,EAAE,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,EAAE,CAAC,EAAE,yBAAyB,EAAE,CAAC;IACjC,GAAG,CAAC,EAAE,yBAAyB,EAAE,CAAC;IAClC,QAAQ,CAAC,EAAE,sBAAsB,EAAE,CAAC;IACpC,WAAW,CAAC,EAAE,0BAA0B,EAAE,CAAC;CAC5C"}
@@ -1,22 +0,0 @@
1
- import { type SendMailOptions, type SendResult } from '../../core/types.js';
2
- import type { IEmailSender } from '../sender.interface.js';
3
- import type { ZeptoMailHttpConfig } from './types.js';
4
- /**
5
- * ZeptoMail (Zoho Mail transactional email HTTP API) transport adapter.
6
- *
7
- * Designed for zero dependencies and universal edge compatibility (Node.js, Bun, Deno, Cloudflare Workers)
8
- * by utilizing the standard global `fetch` API.
9
- */
10
- export declare class ZeptoMailHttpSender implements IEmailSender {
11
- readonly name = "zeptomail";
12
- private readonly apiUrl;
13
- private readonly authHeader;
14
- private readonly defaultFrom;
15
- private readonly fetchImpl;
16
- constructor(config: ZeptoMailHttpConfig);
17
- /**
18
- * Dispatches an email using Zoho ZeptoMail API v1.1.
19
- */
20
- send(options: SendMailOptions): Promise<SendResult>;
21
- }
22
- //# sourceMappingURL=zeptomail-sender.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zeptomail-sender.d.ts","sourceRoot":"","sources":["../../../src/transports/zeptomail/zeptomail-sender.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,UAAU,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EACV,mBAAmB,EAGpB,MAAM,YAAY,CAAC;AAEpB;;;;;GAKG;AACH,qBAAa,mBAAoB,YAAW,YAAY;IACtD,QAAQ,CAAC,IAAI,eAAe;IAE5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqC;IACjE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;IAEzC,YAAY,MAAM,EAAE,mBAAmB,EA4BtC;IAED;;OAEG;IACG,IAAI,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,CAmIxD;CACF"}