@wild-framework/mail-auto 0.2.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 +21 -0
- package/README.md +28 -0
- package/dist/classify.d.ts +10 -0
- package/dist/classify.d.ts.map +1 -0
- package/dist/classify.js +10 -0
- package/dist/classify.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +30 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +55 -0
- package/dist/provider.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wild Framework contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @wild-framework/mail-auto
|
|
2
|
+
|
|
3
|
+
Env-driven mail provider for [Wild Framework](https://github.com/KhandaSoftware/wild-framework).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @wild-framework/mail-auto
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Register `MailProvider` and set `MAIL_DRIVER` to swap backends without touching app code:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { MailProvider } from "@wild-framework/mail-auto";
|
|
17
|
+
|
|
18
|
+
app.register(MailProvider);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| `MAIL_DRIVER` | Backend | Env vars |
|
|
22
|
+
| ------------- | ------- | -------- |
|
|
23
|
+
| `smtp` | SMTP | `SMTP_HOST`, `SMTP_PORT`, `SMTP_SECURE`, `SMTP_USER`, `SMTP_PASS`, `MAIL_FROM` |
|
|
24
|
+
| unset / other | In-memory | — (dev/tests) |
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
MIT
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Which concrete mail backend a driver name maps to. */
|
|
2
|
+
export type MailBackend = "smtp" | "memory";
|
|
3
|
+
/**
|
|
4
|
+
* Classify a `MAIL_DRIVER` value.
|
|
5
|
+
*
|
|
6
|
+
* "smtp" → "smtp"
|
|
7
|
+
* anything else / undefined → "memory"
|
|
8
|
+
*/
|
|
9
|
+
export declare function classifyMailDriver(driver: string | undefined): MailBackend;
|
|
10
|
+
//# sourceMappingURL=classify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classify.d.ts","sourceRoot":"","sources":["../src/classify.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE5C;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,CAE1E"}
|
package/dist/classify.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classify a `MAIL_DRIVER` value.
|
|
3
|
+
*
|
|
4
|
+
* "smtp" → "smtp"
|
|
5
|
+
* anything else / undefined → "memory"
|
|
6
|
+
*/
|
|
7
|
+
export function classifyMailDriver(driver) {
|
|
8
|
+
return driver?.trim().toLowerCase() === "smtp" ? "smtp" : "memory";
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=classify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classify.js","sourceRoot":"","sources":["../src/classify.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAA0B;IACzD,OAAO,MAAM,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;AACvE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Provider, Application } from "@wild-framework/core";
|
|
2
|
+
/**
|
|
3
|
+
* Unified, env-driven mail provider.
|
|
4
|
+
*
|
|
5
|
+
* Selects a concrete driver from `MAIL_DRIVER` and binds a `Mail` into the
|
|
6
|
+
* container. This is the "one provider to rule them all" — register it and
|
|
7
|
+
* set `MAIL_DRIVER` to swap backends without touching app code:
|
|
8
|
+
*
|
|
9
|
+
* MAIL_DRIVER=smtp → SMTP (SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS, MAIL_FROM)
|
|
10
|
+
* (unset) → in-memory (dev/tests)
|
|
11
|
+
*
|
|
12
|
+
* Static configuration (no-arg constructor requirement):
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* MailProvider.driver = "smtp"; // optional — force a backend
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* The explicit providers (`MailProvider` from `@wild-framework/mail` and
|
|
19
|
+
* `SmtpMailProvider` from `@wild-framework/mail-smtp`) remain available when
|
|
20
|
+
* you want to be explicit.
|
|
21
|
+
*/
|
|
22
|
+
export declare class MailProvider implements Provider {
|
|
23
|
+
/** Force a backend; defaults to `MAIL_DRIVER` (smtp | memory). */
|
|
24
|
+
static driver: "smtp" | "memory" | undefined;
|
|
25
|
+
private instance;
|
|
26
|
+
register(app: Application): void;
|
|
27
|
+
boot(): Promise<void>;
|
|
28
|
+
shutdown(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAMlE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,YAAa,YAAW,QAAQ;IACzC,kEAAkE;IAClE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;IAE7C,OAAO,CAAC,QAAQ,CAA6B;IAE7C,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;IAoB1B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAGlC"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Container } from "@wild-framework/container";
|
|
2
|
+
import { Mail, InMemoryMailDriver } from "@wild-framework/mail";
|
|
3
|
+
import { SmtpMailDriver } from "@wild-framework/mail-smtp";
|
|
4
|
+
import { classifyMailDriver } from "./classify.js";
|
|
5
|
+
/**
|
|
6
|
+
* Unified, env-driven mail provider.
|
|
7
|
+
*
|
|
8
|
+
* Selects a concrete driver from `MAIL_DRIVER` and binds a `Mail` into the
|
|
9
|
+
* container. This is the "one provider to rule them all" — register it and
|
|
10
|
+
* set `MAIL_DRIVER` to swap backends without touching app code:
|
|
11
|
+
*
|
|
12
|
+
* MAIL_DRIVER=smtp → SMTP (SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS, MAIL_FROM)
|
|
13
|
+
* (unset) → in-memory (dev/tests)
|
|
14
|
+
*
|
|
15
|
+
* Static configuration (no-arg constructor requirement):
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* MailProvider.driver = "smtp"; // optional — force a backend
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* The explicit providers (`MailProvider` from `@wild-framework/mail` and
|
|
22
|
+
* `SmtpMailProvider` from `@wild-framework/mail-smtp`) remain available when
|
|
23
|
+
* you want to be explicit.
|
|
24
|
+
*/
|
|
25
|
+
export class MailProvider {
|
|
26
|
+
/** Force a backend; defaults to `MAIL_DRIVER` (smtp | memory). */
|
|
27
|
+
static driver;
|
|
28
|
+
instance;
|
|
29
|
+
register(app) {
|
|
30
|
+
const container = app.resolve(Container);
|
|
31
|
+
const backend = classifyMailDriver(MailProvider.driver ?? process.env.MAIL_DRIVER);
|
|
32
|
+
if (backend === "smtp") {
|
|
33
|
+
const driver = new SmtpMailDriver({
|
|
34
|
+
host: process.env.SMTP_HOST ?? "localhost",
|
|
35
|
+
port: process.env.SMTP_PORT ? Number(process.env.SMTP_PORT) : undefined,
|
|
36
|
+
secure: process.env.SMTP_SECURE === "true",
|
|
37
|
+
user: process.env.SMTP_USER,
|
|
38
|
+
pass: process.env.SMTP_PASS,
|
|
39
|
+
from: process.env.MAIL_FROM,
|
|
40
|
+
});
|
|
41
|
+
this.instance = driver;
|
|
42
|
+
container.singleton(Mail, () => new Mail(driver));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
container.singleton(Mail, () => new Mail(new InMemoryMailDriver()));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async boot() {
|
|
49
|
+
await this.instance?.connect();
|
|
50
|
+
}
|
|
51
|
+
async shutdown() {
|
|
52
|
+
await this.instance?.close();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,YAAY;IACrB,kEAAkE;IAClE,MAAM,CAAC,MAAM,CAAgC;IAErC,QAAQ,CAA6B;IAE7C,QAAQ,CAAC,GAAgB;QACrB,MAAM,SAAS,GAAG,GAAG,CAA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/mail-auto",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "Sphah",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/KhandaSoftware/wild-framework.git"
|
|
24
|
+
},
|
|
25
|
+
"description": "Env-driven mail provider — auto-selects SMTP or in-memory from MAIL_DRIVER.",
|
|
26
|
+
"keywords": [
|
|
27
|
+
"wild",
|
|
28
|
+
"framework",
|
|
29
|
+
"mail",
|
|
30
|
+
"email",
|
|
31
|
+
"smtp",
|
|
32
|
+
"auto"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@wild-framework/core": "0.2.0",
|
|
36
|
+
"@wild-framework/container": "0.2.0",
|
|
37
|
+
"@wild-framework/mail": "0.2.0",
|
|
38
|
+
"@wild-framework/mail-smtp": "0.2.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc",
|
|
42
|
+
"clean": "rm -rf dist",
|
|
43
|
+
"test": "vitest run"
|
|
44
|
+
}
|
|
45
|
+
}
|