arcanajs 4.0.0 → 5.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/dist/529.js +2 -0
- package/dist/529.js.map +1 -0
- package/dist/630.js +3 -0
- package/dist/630.js.LICENSE.txt +14 -0
- package/dist/630.js.map +1 -0
- package/dist/arcanajs.auth.js +3 -0
- package/dist/arcanajs.auth.js.LICENSE.txt +14 -0
- package/dist/arcanajs.auth.js.map +1 -0
- package/dist/arcanajs.js +1 -1
- package/dist/arcanajs.js.map +1 -1
- package/dist/arcanajs.mail.js +2 -0
- package/dist/arcanajs.mail.js.map +1 -0
- package/dist/arcanajs.validator.js +2 -0
- package/dist/arcanajs.validator.js.map +1 -0
- package/dist/arcanox.js +1 -1
- package/dist/arcanox.js.map +1 -1
- package/dist/cli/commands/dependency.d.ts +1 -0
- package/dist/cli/commands/make/Controller.d.ts +3 -0
- package/dist/cli/commands/make/Factory.d.ts +2 -0
- package/dist/cli/commands/make/Middleware.d.ts +1 -0
- package/dist/cli/commands/make/Migration.d.ts +2 -0
- package/dist/cli/commands/make/Model.d.ts +2 -0
- package/dist/cli/commands/make/Provider.d.ts +1 -0
- package/dist/cli/commands/make/Request.d.ts +1 -0
- package/dist/cli/commands/make/Seeder.d.ts +2 -0
- package/dist/cli/index.js +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/utils/toPascalCase.d.ts +1 -0
- package/dist/cli/utils/writeFile.d.ts +1 -0
- package/dist/lib/arcanox/providers/DatabaseProvider.d.ts +9 -4
- package/dist/lib/auth/AuthProvider.d.ts +10 -0
- package/dist/lib/auth/JWTService.d.ts +11 -0
- package/dist/lib/auth/SessionManager.d.ts +4 -0
- package/dist/lib/auth/middleware/AuthMiddleware.d.ts +5 -0
- package/dist/lib/auth/middleware/AuthenticatedMiddleware.d.ts +5 -0
- package/dist/lib/auth/middleware/GuestMiddleware.d.ts +5 -0
- package/dist/lib/auth/middleware/RoleMiddleware.d.ts +7 -0
- package/dist/lib/auth/types/AuthConfig.d.ts +24 -0
- package/dist/lib/auth/types/JWTPayload.d.ts +10 -0
- package/dist/lib/auth/types/index.d.ts +2 -0
- package/dist/lib/auth/utils/PasswordHasher.d.ts +16 -0
- package/dist/lib/auth/utils/TokenBlacklist.d.ts +9 -0
- package/dist/lib/index.arcanox.d.ts +16 -2
- package/dist/lib/index.auth.d.ts +11 -0
- package/dist/lib/index.client.d.ts +2 -0
- package/dist/lib/index.mail.d.ts +8 -0
- package/dist/lib/index.server.d.ts +4 -6
- package/dist/lib/index.validator.d.ts +6 -0
- package/dist/lib/mail/MailProvider.d.ts +10 -0
- package/dist/lib/mail/MailService.d.ts +57 -0
- package/dist/lib/mail/Mailable.d.ts +106 -0
- package/dist/lib/mail/index.d.ts +6 -0
- package/dist/lib/mail/queue/MailQueue.d.ts +51 -0
- package/dist/lib/mail/queue/index.d.ts +1 -0
- package/dist/lib/mail/types/MailConfig.d.ts +146 -0
- package/dist/lib/mail/types/index.d.ts +1 -0
- package/dist/lib/mail/utils/TemplateRenderer.d.ts +34 -0
- package/dist/lib/mail/utils/index.d.ts +1 -0
- package/dist/lib/server/ArcanaJSServer.d.ts +15 -8
- package/dist/lib/server/Container.d.ts +8 -0
- package/dist/lib/server/Router.d.ts +23 -33
- package/dist/lib/server/support/ServiceProvider.d.ts +4 -0
- package/dist/lib/validation/Validator.d.ts +55 -0
- package/dist/types/global.d.ts +102 -0
- package/package.json +68 -15
- package/dist/lib/arcanox/index.d.ts +0 -13
- package/dist/lib/server/validation/Validator.d.ts +0 -12
- /package/dist/lib/{server/validation → validation}/ValidationException.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const toPascalCase: (str: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const writeFile: (dir: string, fileName: string, content: string) => Promise<void>;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { ServiceProvider } from "../../server/support/ServiceProvider";
|
|
2
|
+
/**
|
|
3
|
+
* Database Service Provider
|
|
4
|
+
*
|
|
5
|
+
* Registers and bootstraps the database system
|
|
6
|
+
*/
|
|
7
|
+
export declare class DatabaseProvider extends ServiceProvider {
|
|
8
|
+
register(): Promise<void>;
|
|
9
|
+
shutdown(): Promise<void>;
|
|
5
10
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ServiceProvider } from "../server/support/ServiceProvider";
|
|
2
|
+
/**
|
|
3
|
+
* Authentication Service Provider
|
|
4
|
+
*
|
|
5
|
+
* Registers and bootstraps the authentication system
|
|
6
|
+
*/
|
|
7
|
+
export declare class AuthProvider extends ServiceProvider {
|
|
8
|
+
register(): Promise<void>;
|
|
9
|
+
boot(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import jwt from "jsonwebtoken";
|
|
2
|
+
import { AuthConfig, JWTPayload } from "./types";
|
|
3
|
+
export declare class JWTService {
|
|
4
|
+
private static config;
|
|
5
|
+
static init(config: AuthConfig["jwt"]): void;
|
|
6
|
+
static generateToken(payload: JWTPayload, options?: jwt.SignOptions): string;
|
|
7
|
+
static generateRefreshToken(payload: JWTPayload): string;
|
|
8
|
+
static verifyToken(token: string): Promise<JWTPayload>;
|
|
9
|
+
static revokeToken(token: string): Promise<void>;
|
|
10
|
+
static refreshAccessToken(refreshToken: string): Promise<string>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AuthConfig } from "./types";
|
|
2
|
+
export declare class SessionManager {
|
|
3
|
+
static createMiddleware(config: AuthConfig["session"]): import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
4
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NextFunction, Request, Response } from "express";
|
|
2
|
+
import { Middleware } from "../../server/http/Middleware";
|
|
3
|
+
export declare class RoleMiddleware implements Middleware {
|
|
4
|
+
private roles;
|
|
5
|
+
constructor(...roles: string[]);
|
|
6
|
+
handle(req: Request, res: Response, next: NextFunction): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface AuthConfig {
|
|
2
|
+
jwt: {
|
|
3
|
+
secret: string;
|
|
4
|
+
accessTokenExpiry?: string | number;
|
|
5
|
+
refreshTokenExpiry?: string | number;
|
|
6
|
+
algorithm?: "HS256" | "RS256";
|
|
7
|
+
};
|
|
8
|
+
session: {
|
|
9
|
+
secret: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
maxAge?: number;
|
|
12
|
+
secure?: boolean;
|
|
13
|
+
redis?: {
|
|
14
|
+
host: string;
|
|
15
|
+
port: number;
|
|
16
|
+
password?: string;
|
|
17
|
+
db?: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
tokenBlacklist?: {
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
storage: "memory" | "redis";
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class PasswordHasher {
|
|
2
|
+
private static readonly SALT_ROUNDS;
|
|
3
|
+
/**
|
|
4
|
+
* Hash a password.
|
|
5
|
+
* @param password The password to hash.
|
|
6
|
+
* @returns The hashed password.
|
|
7
|
+
*/
|
|
8
|
+
static hash(password: string): Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Verify a password against a hash.
|
|
11
|
+
* @param password The plain text password.
|
|
12
|
+
* @param hash The hashed password.
|
|
13
|
+
* @returns True if the password matches the hash.
|
|
14
|
+
*/
|
|
15
|
+
static verify(password: string, hash: string): Promise<boolean>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AuthConfig } from "../types";
|
|
2
|
+
export declare class TokenBlacklist {
|
|
3
|
+
private static redisClient;
|
|
4
|
+
private static memoryStore;
|
|
5
|
+
private static config;
|
|
6
|
+
static init(config: AuthConfig["tokenBlacklist"], redisConfig?: AuthConfig["session"]["redis"]): Promise<void>;
|
|
7
|
+
static add(token: string, expiresInSeconds: number): Promise<void>;
|
|
8
|
+
static isRevoked(token: string): Promise<boolean>;
|
|
9
|
+
}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/// <reference path="../types/global.d.ts" />
|
|
2
|
+
|
|
3
|
+
export { MongoAdapter } from "./arcanox/adapters/MongoAdapter";
|
|
4
|
+
export { MySQLAdapter } from "./arcanox/adapters/MySQLAdapter";
|
|
5
|
+
export { PostgresAdapter } from "./arcanox/adapters/PostgresAdapter";
|
|
6
|
+
export { Model } from "./arcanox/Model";
|
|
7
|
+
export { QueryBuilder } from "./arcanox/QueryBuilder";
|
|
8
|
+
export { BelongsTo } from "./arcanox/relations/BelongsTo";
|
|
9
|
+
export { BelongsToMany } from "./arcanox/relations/BelongsToMany";
|
|
10
|
+
export { HasMany } from "./arcanox/relations/HasMany";
|
|
11
|
+
export { HasOne } from "./arcanox/relations/HasOne";
|
|
12
|
+
export { Relation } from "./arcanox/relations/Relation";
|
|
13
|
+
export { Macroable } from "./arcanox/support/Macroable";
|
|
14
|
+
export type { ColumnDefinition, Connection, DatabaseAdapter, DatabaseConfig, JoinClause, OrderByClause, SelectOptions, WhereClause, } from "./arcanox/types";
|
|
3
15
|
export { Blueprint, Migration, MigrationRunner, Schema, } from "./arcanox/schema";
|
|
4
16
|
export type { MigrationStatus } from "./arcanox/schema";
|
|
5
17
|
export { Factory } from "./arcanox/factory";
|
|
6
18
|
export { Seeder } from "./arcanox/seeder";
|
|
19
|
+
export * from "./arcanox/extensions/MongoExtensions";
|
|
20
|
+
export { DatabaseProvider } from "./arcanox/providers/DatabaseProvider";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference path="../types/global.d.ts" />
|
|
2
|
+
|
|
3
|
+
export { AuthProvider } from "./auth/AuthProvider";
|
|
4
|
+
export { JWTService } from "./auth/JWTService";
|
|
5
|
+
export { AuthenticatedMiddleware } from "./auth/middleware/AuthenticatedMiddleware";
|
|
6
|
+
export { AuthMiddleware } from "./auth/middleware/AuthMiddleware";
|
|
7
|
+
export { GuestMiddleware } from "./auth/middleware/GuestMiddleware";
|
|
8
|
+
export { RoleMiddleware } from "./auth/middleware/RoleMiddleware";
|
|
9
|
+
export { SessionManager } from "./auth/SessionManager";
|
|
10
|
+
export type { AuthConfig, JWTPayload } from "./auth/types";
|
|
11
|
+
export { PasswordHasher } from "./auth/utils/PasswordHasher";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference path="../types/global.d.ts" />
|
|
2
|
+
|
|
3
|
+
export { Mailable } from "./mail/Mailable";
|
|
4
|
+
export { MailProvider } from "./mail/MailProvider";
|
|
5
|
+
export { MailService } from "./mail/MailService";
|
|
6
|
+
export { MailQueue } from "./mail/queue/MailQueue";
|
|
7
|
+
export type { MailAttachment, MailConfig, MailDriver, MailFromConfig, MailgunConfig, MailMessage, MailQueueConfig, MailTemplateConfig, SendGridConfig, SESConfig, SMTPConfig, } from "./mail/types";
|
|
8
|
+
export { TemplateRenderer } from "./mail/utils/TemplateRenderer";
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
+
/// <reference path="../types/global.d.ts" />
|
|
2
|
+
|
|
1
3
|
import { Express } from "express";
|
|
2
4
|
import ArcanaJSServer, { ArcanaJSConfig } from "./server/ArcanaJSServer";
|
|
3
5
|
export { default as ArcanaJSServer } from "./server/ArcanaJSServer";
|
|
4
6
|
export { Container } from "./server/Container";
|
|
5
7
|
export { Express, NextFunction, Request, Response } from "express";
|
|
6
|
-
export { FormRequest } from "./server/http/FormRequest";
|
|
7
|
-
export { JsonResource } from "./server/http/JsonResource";
|
|
8
|
-
export type { Middleware } from "./server/http/Middleware";
|
|
9
8
|
export { default as Route } from "./server/Router";
|
|
9
|
+
export type { Middleware } from "./server/http/Middleware";
|
|
10
10
|
export { ServiceProvider } from "./server/support/ServiceProvider";
|
|
11
|
-
export { ValidationException } from "./server/validation/ValidationException";
|
|
12
|
-
export { Validator } from "./server/validation/Validator";
|
|
13
11
|
/**
|
|
14
12
|
* Create an ArcanaJS server with the given Express app
|
|
15
13
|
*
|
|
@@ -25,7 +23,7 @@ export { Validator } from "./server/validation/Validator";
|
|
|
25
23
|
* const app = express();
|
|
26
24
|
* const server = createArcanaServer(app, {
|
|
27
25
|
* port: 3000,
|
|
28
|
-
* viewsDir: 'src/views',
|
|
26
|
+
* viewsDir: 'src/resources/views',
|
|
29
27
|
* });
|
|
30
28
|
*
|
|
31
29
|
* server.start();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference path="../types/global.d.ts" />
|
|
2
|
+
|
|
3
|
+
export { FormRequest } from "./server/http/FormRequest";
|
|
4
|
+
export { JsonResource } from "./server/http/JsonResource";
|
|
5
|
+
export { ValidationException } from "./validation/ValidationException";
|
|
6
|
+
export { Validator } from "./validation/Validator";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ServiceProvider } from "../server/support/ServiceProvider";
|
|
2
|
+
/**
|
|
3
|
+
* Mail Service Provider
|
|
4
|
+
*
|
|
5
|
+
* Registers and bootstraps the mail system
|
|
6
|
+
*/
|
|
7
|
+
export declare class MailProvider extends ServiceProvider {
|
|
8
|
+
register(): Promise<void>;
|
|
9
|
+
boot(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Mailable } from "./Mailable";
|
|
2
|
+
import { MailConfig, MailMessage } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Core mail service for sending emails
|
|
5
|
+
*/
|
|
6
|
+
export declare class MailService {
|
|
7
|
+
private static config?;
|
|
8
|
+
private static transporter?;
|
|
9
|
+
/**
|
|
10
|
+
* Initialize the mail service
|
|
11
|
+
*/
|
|
12
|
+
static init(config: MailConfig): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Create nodemailer transporter based on configuration
|
|
15
|
+
*/
|
|
16
|
+
private static createTransporter;
|
|
17
|
+
/**
|
|
18
|
+
* Create SMTP transporter
|
|
19
|
+
*/
|
|
20
|
+
private static createSMTPTransporter;
|
|
21
|
+
/**
|
|
22
|
+
* Create SendGrid transporter
|
|
23
|
+
*/
|
|
24
|
+
private static createSendGridTransporter;
|
|
25
|
+
/**
|
|
26
|
+
* Create Mailgun transporter
|
|
27
|
+
*/
|
|
28
|
+
private static createMailgunTransporter;
|
|
29
|
+
/**
|
|
30
|
+
* Create AWS SES transporter
|
|
31
|
+
*/
|
|
32
|
+
private static createSESTransporter;
|
|
33
|
+
/**
|
|
34
|
+
* Create log-only transporter (for testing)
|
|
35
|
+
*/
|
|
36
|
+
private static createLogTransporter;
|
|
37
|
+
/**
|
|
38
|
+
* Send an email immediately
|
|
39
|
+
*/
|
|
40
|
+
static send(mailable: Mailable | MailMessage): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Queue an email for async sending
|
|
43
|
+
*/
|
|
44
|
+
static queue(mailable: Mailable): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Send a raw email message
|
|
47
|
+
*/
|
|
48
|
+
static sendRaw(message: MailMessage): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Get the mail configuration
|
|
51
|
+
*/
|
|
52
|
+
static getConfig(): MailConfig | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Verify transporter connection
|
|
55
|
+
*/
|
|
56
|
+
static verify(): Promise<boolean>;
|
|
57
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { MailAttachment, MailMessage } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for creating email messages
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* class WelcomeEmail extends Mailable {
|
|
8
|
+
* constructor(private user: User) {
|
|
9
|
+
* super();
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* build() {
|
|
13
|
+
* return this
|
|
14
|
+
* .to(this.user.email)
|
|
15
|
+
* .subject('Welcome to ArcanaJS!')
|
|
16
|
+
* .view('emails/welcome', { name: this.user.name });
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // Send the email
|
|
21
|
+
* await new WelcomeEmail(user).send();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare abstract class Mailable {
|
|
25
|
+
protected message: Partial<MailMessage>;
|
|
26
|
+
protected viewName?: string;
|
|
27
|
+
protected viewData?: Record<string, any>;
|
|
28
|
+
/**
|
|
29
|
+
* Build the email message
|
|
30
|
+
* Must be implemented by subclasses
|
|
31
|
+
*/
|
|
32
|
+
abstract build(): this;
|
|
33
|
+
/**
|
|
34
|
+
* Set the recipient(s)
|
|
35
|
+
*/
|
|
36
|
+
to(address: string | string[], name?: string): this;
|
|
37
|
+
/**
|
|
38
|
+
* Set the sender
|
|
39
|
+
*/
|
|
40
|
+
from(address: string, name?: string): this;
|
|
41
|
+
/**
|
|
42
|
+
* Set the email subject
|
|
43
|
+
*/
|
|
44
|
+
subject(subject: string): this;
|
|
45
|
+
/**
|
|
46
|
+
* Set the email view template
|
|
47
|
+
*/
|
|
48
|
+
view(template: string, data?: Record<string, any>): this;
|
|
49
|
+
/**
|
|
50
|
+
* Set HTML content directly
|
|
51
|
+
*/
|
|
52
|
+
html(content: string): this;
|
|
53
|
+
/**
|
|
54
|
+
* Set plain text content
|
|
55
|
+
*/
|
|
56
|
+
text(content: string): this;
|
|
57
|
+
/**
|
|
58
|
+
* Add CC recipient(s)
|
|
59
|
+
*/
|
|
60
|
+
cc(address: string | string[]): this;
|
|
61
|
+
/**
|
|
62
|
+
* Add BCC recipient(s)
|
|
63
|
+
*/
|
|
64
|
+
bcc(address: string | string[]): this;
|
|
65
|
+
/**
|
|
66
|
+
* Set reply-to address
|
|
67
|
+
*/
|
|
68
|
+
replyTo(address: string): this;
|
|
69
|
+
/**
|
|
70
|
+
* Add an attachment
|
|
71
|
+
*/
|
|
72
|
+
attach(attachment: MailAttachment): this;
|
|
73
|
+
/**
|
|
74
|
+
* Attach a file from path
|
|
75
|
+
*/
|
|
76
|
+
attachFromPath(path: string, filename?: string): this;
|
|
77
|
+
/**
|
|
78
|
+
* Attach data as a file
|
|
79
|
+
*/
|
|
80
|
+
attachData(content: string | Buffer, filename: string, contentType?: string): this;
|
|
81
|
+
/**
|
|
82
|
+
* Set email priority
|
|
83
|
+
*/
|
|
84
|
+
priority(level: "high" | "normal" | "low"): this;
|
|
85
|
+
/**
|
|
86
|
+
* Add custom headers
|
|
87
|
+
*/
|
|
88
|
+
withHeaders(headers: Record<string, string>): this;
|
|
89
|
+
/**
|
|
90
|
+
* Get the built message
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
getMessage(): {
|
|
94
|
+
message: Partial<MailMessage>;
|
|
95
|
+
viewName?: string;
|
|
96
|
+
viewData?: Record<string, any>;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Send the email immediately
|
|
100
|
+
*/
|
|
101
|
+
send(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Queue the email for async sending
|
|
104
|
+
*/
|
|
105
|
+
queue(): Promise<void>;
|
|
106
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Mailable } from "../Mailable";
|
|
2
|
+
import { MailQueueConfig } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Mail queue for async email processing
|
|
5
|
+
*/
|
|
6
|
+
export declare class MailQueue {
|
|
7
|
+
private static config?;
|
|
8
|
+
private static queue;
|
|
9
|
+
private static processing;
|
|
10
|
+
private static redisClient?;
|
|
11
|
+
/**
|
|
12
|
+
* Initialize the mail queue
|
|
13
|
+
*/
|
|
14
|
+
static init(config: MailQueueConfig): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Initialize Redis connection
|
|
17
|
+
*/
|
|
18
|
+
private static initRedis;
|
|
19
|
+
/**
|
|
20
|
+
* Add a job to the queue
|
|
21
|
+
*/
|
|
22
|
+
static add(mailable: Mailable): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Start processing the queue
|
|
25
|
+
*/
|
|
26
|
+
private static startProcessing;
|
|
27
|
+
/**
|
|
28
|
+
* Process next job in queue
|
|
29
|
+
*/
|
|
30
|
+
private static processNext;
|
|
31
|
+
/**
|
|
32
|
+
* Handle failed job
|
|
33
|
+
*/
|
|
34
|
+
private static handleFailedJob;
|
|
35
|
+
/**
|
|
36
|
+
* Store failed job for manual review
|
|
37
|
+
*/
|
|
38
|
+
private static storeFailedJob;
|
|
39
|
+
/**
|
|
40
|
+
* Generate unique job ID
|
|
41
|
+
*/
|
|
42
|
+
private static generateId;
|
|
43
|
+
/**
|
|
44
|
+
* Get queue size
|
|
45
|
+
*/
|
|
46
|
+
static size(): Promise<number>;
|
|
47
|
+
/**
|
|
48
|
+
* Clear the queue
|
|
49
|
+
*/
|
|
50
|
+
static clear(): Promise<void>;
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./MailQueue";
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Transporter } from "nodemailer";
|
|
2
|
+
/**
|
|
3
|
+
* Supported mail transport drivers
|
|
4
|
+
*/
|
|
5
|
+
export type MailDriver = "smtp" | "sendgrid" | "mailgun" | "ses" | "log";
|
|
6
|
+
/**
|
|
7
|
+
* SMTP Configuration
|
|
8
|
+
*/
|
|
9
|
+
export interface SMTPConfig {
|
|
10
|
+
host: string;
|
|
11
|
+
port: number;
|
|
12
|
+
secure?: boolean;
|
|
13
|
+
auth?: {
|
|
14
|
+
user: string;
|
|
15
|
+
pass: string;
|
|
16
|
+
};
|
|
17
|
+
tls?: {
|
|
18
|
+
rejectUnauthorized?: boolean;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* SendGrid Configuration
|
|
23
|
+
*/
|
|
24
|
+
export interface SendGridConfig {
|
|
25
|
+
apiKey: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Mailgun Configuration
|
|
29
|
+
*/
|
|
30
|
+
export interface MailgunConfig {
|
|
31
|
+
apiKey: string;
|
|
32
|
+
domain: string;
|
|
33
|
+
host?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* AWS SES Configuration
|
|
37
|
+
*/
|
|
38
|
+
export interface SESConfig {
|
|
39
|
+
region: string;
|
|
40
|
+
accessKeyId: string;
|
|
41
|
+
secretAccessKey: string;
|
|
42
|
+
sessionToken?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Mail Queue Configuration
|
|
46
|
+
*/
|
|
47
|
+
export interface MailQueueConfig {
|
|
48
|
+
enabled: boolean;
|
|
49
|
+
driver: "memory" | "redis";
|
|
50
|
+
redis?: {
|
|
51
|
+
host: string;
|
|
52
|
+
port: number;
|
|
53
|
+
password?: string;
|
|
54
|
+
db?: number;
|
|
55
|
+
};
|
|
56
|
+
retries?: number;
|
|
57
|
+
retryDelay?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Mail Template Configuration
|
|
61
|
+
*/
|
|
62
|
+
export interface MailTemplateConfig {
|
|
63
|
+
engine: "ejs" | "handlebars";
|
|
64
|
+
viewsPath: string;
|
|
65
|
+
layoutsPath?: string;
|
|
66
|
+
defaultLayout?: string;
|
|
67
|
+
inlineCss?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Default Sender Configuration
|
|
71
|
+
*/
|
|
72
|
+
export interface MailFromConfig {
|
|
73
|
+
address: string;
|
|
74
|
+
name?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Main Mail Configuration
|
|
78
|
+
*/
|
|
79
|
+
export interface MailConfig {
|
|
80
|
+
/**
|
|
81
|
+
* Default mail driver to use
|
|
82
|
+
*/
|
|
83
|
+
default: MailDriver;
|
|
84
|
+
/**
|
|
85
|
+
* Default "from" address and name
|
|
86
|
+
*/
|
|
87
|
+
from: MailFromConfig;
|
|
88
|
+
/**
|
|
89
|
+
* SMTP Configuration
|
|
90
|
+
*/
|
|
91
|
+
smtp?: SMTPConfig;
|
|
92
|
+
/**
|
|
93
|
+
* SendGrid Configuration
|
|
94
|
+
*/
|
|
95
|
+
sendgrid?: SendGridConfig;
|
|
96
|
+
/**
|
|
97
|
+
* Mailgun Configuration
|
|
98
|
+
*/
|
|
99
|
+
mailgun?: MailgunConfig;
|
|
100
|
+
/**
|
|
101
|
+
* AWS SES Configuration
|
|
102
|
+
*/
|
|
103
|
+
ses?: SESConfig;
|
|
104
|
+
/**
|
|
105
|
+
* Queue Configuration
|
|
106
|
+
*/
|
|
107
|
+
queue?: MailQueueConfig;
|
|
108
|
+
/**
|
|
109
|
+
* Template Configuration
|
|
110
|
+
*/
|
|
111
|
+
templates?: MailTemplateConfig;
|
|
112
|
+
/**
|
|
113
|
+
* Reply-to address
|
|
114
|
+
*/
|
|
115
|
+
replyTo?: MailFromConfig;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Mail Message Options
|
|
119
|
+
*/
|
|
120
|
+
export interface MailMessage {
|
|
121
|
+
to: string | string[];
|
|
122
|
+
from?: MailFromConfig;
|
|
123
|
+
subject: string;
|
|
124
|
+
html?: string;
|
|
125
|
+
text?: string;
|
|
126
|
+
cc?: string | string[];
|
|
127
|
+
bcc?: string | string[];
|
|
128
|
+
replyTo?: string;
|
|
129
|
+
attachments?: MailAttachment[];
|
|
130
|
+
headers?: Record<string, string>;
|
|
131
|
+
priority?: "high" | "normal" | "low";
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Mail Attachment
|
|
135
|
+
*/
|
|
136
|
+
export interface MailAttachment {
|
|
137
|
+
filename: string;
|
|
138
|
+
content?: string | Buffer;
|
|
139
|
+
path?: string;
|
|
140
|
+
contentType?: string;
|
|
141
|
+
cid?: string;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Nodemailer Transporter Type
|
|
145
|
+
*/
|
|
146
|
+
export type MailTransporter = Transporter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./MailConfig";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MailTemplateConfig } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Template renderer for email views
|
|
4
|
+
*/
|
|
5
|
+
export declare class TemplateRenderer {
|
|
6
|
+
private static config?;
|
|
7
|
+
/**
|
|
8
|
+
* Initialize the template renderer
|
|
9
|
+
*/
|
|
10
|
+
static init(config: MailTemplateConfig): void;
|
|
11
|
+
/**
|
|
12
|
+
* Render a template to HTML
|
|
13
|
+
*/
|
|
14
|
+
static render(templateName: string, data?: Record<string, any>): Promise<{
|
|
15
|
+
html: string;
|
|
16
|
+
text: string;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Render EJS template
|
|
20
|
+
*/
|
|
21
|
+
private static renderEJS;
|
|
22
|
+
/**
|
|
23
|
+
* Render Handlebars template
|
|
24
|
+
*/
|
|
25
|
+
private static renderHandlebars;
|
|
26
|
+
/**
|
|
27
|
+
* Apply layout to rendered content
|
|
28
|
+
*/
|
|
29
|
+
private static applyLayout;
|
|
30
|
+
/**
|
|
31
|
+
* Convert HTML to plain text
|
|
32
|
+
*/
|
|
33
|
+
private static htmlToText;
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./TemplateRenderer";
|