alepha 0.10.6 → 0.10.7

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/core.d.ts CHANGED
@@ -28,13 +28,13 @@ declare const MODULE: unique symbol;
28
28
  /**
29
29
  * In Alepha, a service is a class that can be instantiated or an abstract class. Nothing more, nothing less...
30
30
  */
31
- type Service<T extends object = any> = InstantiableClass<T> | AbstractClass<T>;
32
- type InstantiableClass<T extends object = any> = new (...args: any[]) => T;
31
+ type Service<T$1 extends object = any> = InstantiableClass<T$1> | AbstractClass<T$1>;
32
+ type InstantiableClass<T$1 extends object = any> = new (...args: any[]) => T$1;
33
33
  /**
34
34
  * Abstract class is a class that cannot be instantiated directly!
35
35
  * It widely used for defining interfaces.
36
36
  */
37
- type AbstractClass<T extends object = any> = abstract new (...args: any[]) => T;
37
+ type AbstractClass<T$1 extends object = any> = abstract new (...args: any[]) => T$1;
38
38
  /**
39
39
  * Service substitution allows you to register a class as a different class.
40
40
  * Providing class A, but using class B instead.
@@ -42,17 +42,17 @@ type AbstractClass<T extends object = any> = abstract new (...args: any[]) => T;
42
42
  *
43
43
  * class A is mostly an AbstractClass, while class B is an InstantiableClass.
44
44
  */
45
- interface ServiceSubstitution<T extends object = any> {
45
+ interface ServiceSubstitution<T$1 extends object = any> {
46
46
  /**
47
47
  * Every time someone asks for this class, it will be provided with the 'use' class.
48
48
  */
49
- provide: Service<T>;
49
+ provide: Service<T$1>;
50
50
  /**
51
51
  * Service to use instead of the 'provide' service.
52
52
  *
53
53
  * Syntax is inspired by Angular's DI system.
54
54
  */
55
- use: Service<T>;
55
+ use: Service<T$1>;
56
56
  /**
57
57
  * If true, if the service already exists -> just ignore the substitution and do not throw an error.
58
58
  * Mostly used for plugins to enforce a substitution without throwing an error.
@@ -68,11 +68,11 @@ interface ServiceSubstitution<T extends object = any> {
68
68
  *
69
69
  * And yes, you declare the *type* of the service, not the *instance*.
70
70
  */
71
- type ServiceEntry<T extends object = any> = Service<T> | ServiceSubstitution<T>;
71
+ type ServiceEntry<T$1 extends object = any> = Service<T$1> | ServiceSubstitution<T$1>;
72
72
  //#endregion
73
73
  //#region src/helpers/descriptor.d.ts
74
- interface DescriptorArgs<T extends object = {}> {
75
- options: T;
74
+ interface DescriptorArgs<T$1 extends object = {}> {
75
+ options: T$1;
76
76
  alepha: Alepha;
77
77
  service: InstantiableClass<Service>;
78
78
  module?: Service;
@@ -82,22 +82,22 @@ interface DescriptorConfig {
82
82
  service: InstantiableClass<Service>;
83
83
  module?: Service;
84
84
  }
85
- declare abstract class Descriptor<T extends object = {}> {
85
+ declare abstract class Descriptor<T$1 extends object = {}> {
86
86
  protected readonly alepha: Alepha;
87
- readonly options: T;
87
+ readonly options: T$1;
88
88
  readonly config: DescriptorConfig;
89
- constructor(args: DescriptorArgs<T>);
89
+ constructor(args: DescriptorArgs<T$1>);
90
90
  /**
91
91
  * Called automatically by Alepha after the descriptor is created.
92
92
  */
93
93
  protected onInit(): void;
94
94
  }
95
- type DescriptorFactory<TDescriptor extends Descriptor = Descriptor> = {
96
- (options: TDescriptor["options"]): TDescriptor;
97
- [KIND]: InstantiableClass<TDescriptor>;
95
+ type DescriptorFactory<TDescriptor$1 extends Descriptor = Descriptor> = {
96
+ (options: TDescriptor$1["options"]): TDescriptor$1;
97
+ [KIND]: InstantiableClass<TDescriptor$1>;
98
98
  };
99
- type DescriptorFactoryLike<T extends object = any> = {
100
- (options: T): any;
99
+ type DescriptorFactoryLike<T$1 extends object = any> = {
100
+ (options: T$1): any;
101
101
  [KIND]: any;
102
102
  };
103
103
  declare const createDescriptor: <TDescriptor extends Descriptor>(descriptor: InstantiableClass<TDescriptor> & {
@@ -117,7 +117,7 @@ declare const createDescriptor: <TDescriptor extends Descriptor>(descriptor: Ins
117
117
  */
118
118
  declare const $inject: <T extends object>(type: Service<T>, opts?: InjectOptions<T>) => T;
119
119
  declare class InjectDescriptor extends Descriptor {}
120
- interface InjectOptions<T extends object = any> {
120
+ interface InjectOptions<T$1 extends object = any> {
121
121
  /**
122
122
  * - 'transient' → Always a new instance on every inject. Zero caching.
123
123
  * - 'singleton' → One instance per Alepha runtime (per-thread). Never disposed until Alepha shuts down. (default)
@@ -132,7 +132,7 @@ interface InjectOptions<T extends object = any> {
132
132
  /**
133
133
  * Constructor arguments to pass when creating a new instance.
134
134
  */
135
- args?: ConstructorParameters<InstantiableClass<T>>;
135
+ args?: ConstructorParameters<InstantiableClass<T$1>>;
136
136
  /**
137
137
  * Parent that requested the instance.
138
138
  *
@@ -190,7 +190,7 @@ interface InjectOptions<T extends object = any> {
190
190
  * If we speak with `$actions`, a module should be used when you have more than 30 actions in a single module.
191
191
  */
192
192
  declare const $module: <T extends object = {}>(options: ModuleDescriptorOptions<T>) => Service<Module<T>>;
193
- interface ModuleDescriptorOptions<T extends object> {
193
+ interface ModuleDescriptorOptions<T$1 extends object> {
194
194
  /**
195
195
  * Name of the module.
196
196
  *
@@ -210,16 +210,16 @@ interface ModuleDescriptorOptions<T extends object> {
210
210
  * You can override this behavior by providing a register function.
211
211
  * It's useful when you want to register services conditionally or in a specific order.
212
212
  */
213
- register?: (alepha: Alepha, options: T) => void;
213
+ register?: (alepha: Alepha, options: T$1) => void;
214
214
  }
215
215
  /**
216
216
  * Base class for all modules.
217
217
  */
218
- declare abstract class Module<T extends object = {}> {
219
- abstract readonly config: ModuleDescriptorOptions<T>;
218
+ declare abstract class Module<T$1 extends object = {}> {
219
+ abstract readonly config: ModuleDescriptorOptions<T$1>;
220
220
  abstract register(alepha: Alepha): void;
221
221
  static NAME_REGEX: RegExp;
222
- options: T;
222
+ options: T$1;
223
223
  /**
224
224
  * Check if a Service is a Module.
225
225
  */
@@ -229,7 +229,7 @@ declare abstract class Module<T extends object = {}> {
229
229
  */
230
230
  static of(ctor: Service): Service<Module> | undefined;
231
231
  }
232
- type WithModule<T extends object = any> = T & {
232
+ type WithModule<T$1 extends object = any> = T$1 & {
233
233
  [MODULE]?: Service;
234
234
  };
235
235
  //#endregion
@@ -237,7 +237,7 @@ type WithModule<T extends object = any> = T & {
237
237
  /**
238
238
  * Represents a value that can be either a value or a promise of value.
239
239
  */
240
- type Async<T> = T | Promise<T>;
240
+ type Async<T$1> = T$1 | Promise<T$1>;
241
241
  /**
242
242
  * Represents a function that returns an async value.
243
243
  */
@@ -245,7 +245,7 @@ type AsyncFn = (...args: any[]) => Async<any>;
245
245
  /**
246
246
  * Transforms a type T into a promise if it is not already a promise.
247
247
  */
248
- type MaybePromise<T> = T extends Promise<any> ? T : Promise<T>;
248
+ type MaybePromise<T$1> = T$1 extends Promise<any> ? T$1 : Promise<T$1>;
249
249
  //#endregion
250
250
  //#region src/interfaces/LoggerInterface.d.ts
251
251
  type LogLevel = "ERROR" | "WARN" | "INFO" | "DEBUG" | "TRACE" | "SILENT";
@@ -273,7 +273,7 @@ declare class EventManager {
273
273
  /**
274
274
  * Emits the specified event with the given payload.
275
275
  */
276
- emit<T extends keyof Hooks>(func: keyof Hooks, payload: Hooks[T], options?: {
276
+ emit<T extends keyof Hooks>(func: T, payload: Hooks[T], options?: {
277
277
  /**
278
278
  * If true, the hooks will be executed in reverse order.
279
279
  * This is useful for "stop" hooks that should be executed in reverse order.
@@ -630,10 +630,26 @@ declare class TypeProvider {
630
630
  * @experimental
631
631
  */
632
632
  stream(): TStream;
633
+ email(options?: TStringOptions$1): TString$1;
634
+ e164(options?: TStringOptions$1): TString$1;
635
+ bcp47(options?: TStringOptions$1): TString$1;
636
+ /**
637
+ * Create a schema for short text, such as names or titles.
638
+ * Default max length is 64 characters.
639
+ */
640
+ shortText(options?: TStringOptions$1): TString$1;
641
+ /**
642
+ * Create a schema for long text, such as descriptions or comments.
643
+ * Default max length is 1024 characters.
644
+ */
645
+ longText(options?: TStringOptions$1): TString$1;
646
+ /**
647
+ * Create a schema for rich text, such as HTML or Markdown.
648
+ * Default max length is 65535 characters.
649
+ */
650
+ richText(options?: TStringOptions$1): TString$1;
633
651
  /**
634
652
  * Create a schema for a string enum e.g. LIKE_THIS.
635
- *
636
- * @param options
637
653
  */
638
654
  snakeCase: (options?: TStringOptions$1) => TString$1;
639
655
  /**
@@ -935,12 +951,14 @@ declare class Alepha {
935
951
  * True if the App is running in a browser environment.
936
952
  */
937
953
  isBrowser(): boolean;
954
+ /**
955
+ * Returns whether the App is running in Vite dev mode.
956
+ */
957
+ isViteDev(): boolean;
938
958
  /**
939
959
  * Returns whether the App is running in a serverless environment.
940
- *
941
- * > Vite developer mode is also considered serverless.
942
960
  */
943
- isServerless(): boolean | "vite" | "vercel";
961
+ isServerless(): boolean | "vercel";
944
962
  /**
945
963
  * Returns whether the App is in test mode. (Running in a test environment)
946
964
  *
@@ -1126,20 +1144,20 @@ declare class Alepha {
1126
1144
  protected new<T extends object>(service: Service<T>, args?: any[]): T;
1127
1145
  protected processDescriptor(value: Descriptor, propertyKey?: string): void;
1128
1146
  }
1129
- interface Hook<T extends keyof Hooks = any> {
1147
+ interface Hook<T$1 extends keyof Hooks = any> {
1130
1148
  caller?: Service;
1131
1149
  priority?: "first" | "last";
1132
- callback: (payload: Hooks[T]) => Async<void>;
1150
+ callback: (payload: Hooks[T$1]) => Async<void>;
1133
1151
  }
1134
1152
  /**
1135
1153
  * This is how we store services in the Alepha container.
1136
1154
  */
1137
- interface ServiceDefinition<T extends object = any> {
1155
+ interface ServiceDefinition<T$1 extends object = any> {
1138
1156
  /**
1139
1157
  * The instance of the class or type definition.
1140
1158
  * Mostly used for caching / singleton but can be used for other purposes like forcing the instance.
1141
1159
  */
1142
- instance: T;
1160
+ instance: T$1;
1143
1161
  /**
1144
1162
  * List of classes which use this class.
1145
1163
  */
@@ -1211,6 +1229,9 @@ interface Hooks {
1211
1229
  prevValue: any;
1212
1230
  };
1213
1231
  }
1232
+ interface Configurable<T$1 extends object = any> {
1233
+ options: T$1;
1234
+ }
1214
1235
  //#endregion
1215
1236
  //#region src/interfaces/Run.d.ts
1216
1237
  interface RunOptions {
@@ -1366,15 +1387,15 @@ declare const $hook: {
1366
1387
  <T extends keyof Hooks>(options: HookOptions<T>): HookDescriptor<T>;
1367
1388
  [KIND]: typeof HookDescriptor;
1368
1389
  };
1369
- interface HookOptions<T extends keyof Hooks> {
1390
+ interface HookOptions<T$1 extends keyof Hooks> {
1370
1391
  /**
1371
1392
  * The name of the hook. "configure", "start", "ready", "stop", ...
1372
1393
  */
1373
- on: T;
1394
+ on: T$1;
1374
1395
  /**
1375
1396
  * The handler to run when the hook is triggered.
1376
1397
  */
1377
- handler: (args: Hooks[T]) => Async<any>;
1398
+ handler: (args: Hooks[T$1]) => Async<any>;
1378
1399
  /**
1379
1400
  * Force the hook to run first or last on the list of hooks.
1380
1401
  */
@@ -1388,7 +1409,7 @@ interface HookOptions<T extends keyof Hooks> {
1388
1409
  */
1389
1410
  after?: object | Array<object>;
1390
1411
  }
1391
- declare class HookDescriptor<T extends keyof Hooks> extends Descriptor<HookOptions<T>> {
1412
+ declare class HookDescriptor<T$1 extends keyof Hooks> extends Descriptor<HookOptions<T$1>> {
1392
1413
  called: number;
1393
1414
  protected onInit(): void;
1394
1415
  }
@@ -1447,5 +1468,5 @@ declare global {
1447
1468
  */
1448
1469
  declare const run: (entry: Alepha | Service | Array<Service>, opts?: RunOptions) => void;
1449
1470
  //#endregion
1450
- export { $cursor, $env, $hook, $inject, $module, AbstractClass, Alepha, AlephaError, AlsProvider, AppNotStartedError, Async, AsyncFn, AsyncLocalStorageData, CircularDependencyError, ContainerLockedError, CursorDescriptor, Descriptor, DescriptorArgs, DescriptorConfig, DescriptorFactory, DescriptorFactoryLike, Env, FileLike, Hook, HookDescriptor, HookOptions, Hooks, InjectDescriptor, InjectOptions, InstantiableClass, KIND, LogLevel, LoggerInterface, MaybePromise, Module, ModuleDescriptorOptions, OPTIONS, Service, ServiceEntry, ServiceSubstitution, State, StateManager, type Static, type StaticDecode, type StaticEncode, StreamLike, type TAny, type TArray, type TBigInt, type TBoolean, TFile, type TInteger, type TKeysToIndexer, type TNull, type TNumber, type TNumberOptions, type TObject, type TObjectOptions, type TOptional, type TOptionalAdd, type TPick, type TProperties, type TRecord, type TSchema, TStream, type TString, type TStringOptions, TTextOptions, type TTuple, type TUnion, type TVoid, TextLength, TooLateSubstitutionError, TypeBox, TypeBoxError, TypeBoxFormat, TypeBoxValue, TypeGuard, TypeProvider, WithModule, __alephaRef, createDescriptor, isDate, isDateTime, isEmail, isFileLike, isTypeFile, isURL, isUUID, run, t };
1471
+ export { $cursor, $env, $hook, $inject, $module, AbstractClass, Alepha, AlephaError, AlsProvider, AppNotStartedError, Async, AsyncFn, AsyncLocalStorageData, CircularDependencyError, Configurable, ContainerLockedError, CursorDescriptor, Descriptor, DescriptorArgs, DescriptorConfig, DescriptorFactory, DescriptorFactoryLike, Env, FileLike, Hook, HookDescriptor, HookOptions, Hooks, InjectDescriptor, InjectOptions, InstantiableClass, KIND, LogLevel, LoggerInterface, MaybePromise, Module, ModuleDescriptorOptions, OPTIONS, Service, ServiceEntry, ServiceSubstitution, State, StateManager, type Static, type StaticDecode, type StaticEncode, StreamLike, type TAny, type TArray, type TBigInt, type TBoolean, TFile, type TInteger, type TKeysToIndexer, type TNull, type TNumber, type TNumberOptions, type TObject, type TObjectOptions, type TOptional, type TOptionalAdd, type TPick, type TProperties, type TRecord, type TSchema, TStream, type TString, type TStringOptions, TTextOptions, type TTuple, type TUnion, type TVoid, TextLength, TooLateSubstitutionError, TypeBox, TypeBoxError, TypeBoxFormat, TypeBoxValue, TypeGuard, TypeProvider, WithModule, __alephaRef, createDescriptor, isDate, isDateTime, isEmail, isFileLike, isTypeFile, isURL, isUUID, run, t };
1451
1472
  //# sourceMappingURL=index.d.ts.map
package/email.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import * as _alepha_core1 from "alepha";
2
- import { Descriptor, KIND, Service, Static, TSchema } from "alepha";
3
2
  import * as _alepha_logger0 from "alepha/logger";
4
3
  import { Transporter } from "nodemailer";
5
4
 
@@ -13,230 +12,15 @@ declare abstract class EmailProvider {
13
12
  /**
14
13
  * Send an email.
15
14
  *
16
- * @param to The recipient email address.
17
- * @param subject The email subject.
18
- * @param body The email body (HTML content).
19
- *
20
15
  * @return Promise that resolves when the email is sent.
21
16
  */
22
- abstract send(to: string, subject: string, body: string): Promise<void>;
17
+ abstract send(options: EmailSendOptions): Promise<void>;
23
18
  }
24
- //#endregion
25
- //#region src/providers/MemoryEmailProvider.d.ts
26
- interface EmailRecord {
27
- to: string;
19
+ type EmailSendOptions = {
20
+ to: string | string[];
28
21
  subject: string;
29
22
  body: string;
30
- sentAt: Date;
31
- }
32
- declare class MemoryEmailProvider implements EmailProvider {
33
- protected readonly log: _alepha_logger0.Logger;
34
- protected emails: EmailRecord[];
35
- send(to: string, subject: string, body: string): Promise<void>;
36
- /**
37
- * Get all emails sent through this provider (for testing purposes).
38
- */
39
- getEmails(): EmailRecord[];
40
- /**
41
- * Clear all stored emails (for testing purposes).
42
- */
43
- clearEmails(): void;
44
- /**
45
- * Get the last email sent (for testing purposes).
46
- */
47
- getLastEmail(): EmailRecord | undefined;
48
- }
49
- //#endregion
50
- //#region src/services/TemplateService.d.ts
51
- /**
52
- * Minimal template service with Handlebars-like syntax for email templating.
53
- * Supports simple variable substitution with {{variableName}} syntax.
54
- */
55
- declare class TemplateService {
56
- /**
57
- * Compile a template string with the provided values.
58
- *
59
- * @param template Template string with {{variableName}} placeholders
60
- * @param values Object containing values to substitute
61
- * @returns Compiled template string with values substituted
62
- *
63
- * @example
64
- * ```ts
65
- * const service = new TemplateService();
66
- * const result = service.compile("Hello {{name}}!", { name: "John" });
67
- * // Result: "Hello John!"
68
- * ```
69
- */
70
- compile(template: string, values: Record<string, unknown>): string;
71
- /**
72
- * Validate that all required template variables are provided.
73
- *
74
- * @param template Template string
75
- * @param values Values object
76
- * @returns Array of missing variable names
77
- */
78
- validateTemplate(template: string, values: Record<string, unknown>): string[];
79
- /**
80
- * Extract all variable names from a template.
81
- *
82
- * @param template Template string
83
- * @returns Array of variable names found in the template
84
- */
85
- extractVariables(template: string): string[];
86
- }
87
- //#endregion
88
- //#region src/descriptors/$email.d.ts
89
- /**
90
- * Creates an email descriptor for sending type-safe templated emails.
91
- *
92
- * The $email descriptor provides a powerful templating system for creating and sending emails
93
- * with full type safety and validation. It supports multiple email providers, template variable
94
- * validation, and automatic HTML rendering.
95
- *
96
- * **Template Engine**
97
- * - Simple {{variable}} syntax for dynamic content
98
- * - Automatic template variable validation at runtime
99
- * - Support for nested object properties in templates
100
- * - HTML email support with rich formatting
101
- *
102
- * **Type Safety**
103
- * - Full TypeScript support with schema validation using TypeBox
104
- * - Compile-time type checking for template variables
105
- * - Runtime validation of email data before sending
106
- * - Automatic type inference from schema definitions
107
- *
108
- * **Provider Flexibility**
109
- * - Memory provider for development and testing
110
- * - Support for SMTP, SendGrid, AWS SES, and other providers
111
- * - Custom provider implementation for specialized services
112
- * - Automatic fallback and error handling
113
- *
114
- * **Template Management**
115
- * - Reusable email templates across your application
116
- * - Centralized template configuration and maintenance
117
- * - Template variable documentation through schemas
118
- * - Easy testing and preview capabilities
119
- *
120
- * **Development Experience**
121
- * - Clear error messages for missing template variables
122
- * - Comprehensive logging for debugging email delivery
123
- * - Memory provider captures emails for testing
124
- * - Template validation before sending
125
- *
126
- * @example Welcome email template
127
- * ```typescript
128
- * const welcomeEmail = $email({
129
- * subject: "Welcome to {{companyName}}, {{firstName}}!",
130
- * body: `
131
- * <h1>Welcome {{firstName}} {{lastName}}!</h1>
132
- * <p>Thank you for joining {{companyName}}.</p>
133
- * <p>Your account role is: <strong>{{role}}</strong></p>
134
- * <p>Get started by visiting your <a href="{{dashboardUrl}}">dashboard</a>.</p>
135
- * `,
136
- * schema: t.object({
137
- * firstName: t.text(),
138
- * lastName: t.text(),
139
- * companyName: t.text(),
140
- * role: t.enum(["admin", "user", "manager"]),
141
- * dashboardUrl: t.text()
142
- * })
143
- * });
144
- *
145
- * // Send with full type safety
146
- * await welcomeEmail.send("user@example.com", {
147
- * firstName: "John",
148
- * lastName: "Doe",
149
- * companyName: "Acme Corp",
150
- * role: "user",
151
- * dashboardUrl: "https://app.acme.com/dashboard"
152
- * });
153
- * ```
154
- *
155
- * @example Order confirmation email
156
- * ```typescript
157
- * const orderConfirmation = $email({
158
- * subject: "Order #{{orderNumber}} confirmed - {{totalAmount}}",
159
- * body: `
160
- * <h1>Order Confirmed!</h1>
161
- * <p>Hi {{customerName}},</p>
162
- * <p>Your order #{{orderNumber}} has been confirmed.</p>
163
- * <h2>Order Details:</h2>
164
- * <p><strong>Total: {{totalAmount}}</strong></p>
165
- * <p>Estimated delivery: {{deliveryDate}}</p>
166
- * `,
167
- * schema: t.object({
168
- * customerName: t.text(),
169
- * orderNumber: t.text(),
170
- * totalAmount: t.text(),
171
- * deliveryDate: t.text()
172
- * })
173
- * });
174
- * ```
175
- *
176
- * @example Development with memory provider
177
- * ```typescript
178
- * const testEmail = $email({
179
- * subject: "Test: {{subject}}",
180
- * body: "<p>{{message}}</p>",
181
- * provider: "memory", // Captures emails for testing
182
- * schema: t.object({
183
- * subject: t.text(),
184
- * message: t.text()
185
- * })
186
- * });
187
- *
188
- * // In tests - emails are captured, not actually sent
189
- * await testEmail.send("test@example.com", {
190
- * subject: "Unit Test",
191
- * message: "This email was captured for testing"
192
- * });
193
- * ```
194
- */
195
- declare const $email: {
196
- <T extends TSchema>(options: EmailDescriptorOptions<T>): EmailDescriptor<T>;
197
- [KIND]: typeof EmailDescriptor;
198
23
  };
199
- interface EmailDescriptorOptions<T extends TSchema> {
200
- /**
201
- * Email subject template. Supports {{variableName}} syntax.
202
- */
203
- subject: string;
204
- /**
205
- * Email body template (HTML content). Supports {{variableName}} syntax.
206
- */
207
- body: string;
208
- /**
209
- * Schema defining the structure of template variables.
210
- */
211
- schema: T;
212
- /**
213
- * Optional name of the email template.
214
- * @default Descriptor key
215
- */
216
- name?: string;
217
- /**
218
- * Optional description of the email template.
219
- */
220
- description?: string;
221
- /**
222
- * Email provider to use. If not provided, the default provider will be used.
223
- */
224
- provider?: Service<EmailProvider> | "memory";
225
- }
226
- declare class EmailDescriptor<T extends TSchema> extends Descriptor<EmailDescriptorOptions<T>> {
227
- protected readonly log: _alepha_logger0.Logger;
228
- protected readonly templateService: TemplateService;
229
- readonly provider: EmailProvider | MemoryEmailProvider;
230
- get name(): string;
231
- /**
232
- * Send an email using the template with the provided values.
233
- *
234
- * @param to Recipient email address
235
- * @param values Template variable values
236
- */
237
- send(to: string, values: Static<T>): Promise<void>;
238
- protected $provider(): EmailProvider | MemoryEmailProvider;
239
- }
240
24
  //#endregion
241
25
  //#region src/errors/EmailError.d.ts
242
26
  declare class EmailError extends Error {
@@ -247,7 +31,7 @@ declare class EmailError extends Error {
247
31
  interface LocalEmailProviderOptions {
248
32
  /**
249
33
  * Directory to save email files.
250
- * @default "email" (relative to project root)
34
+ * @default "node_modules/.email" (relative to project root)
251
35
  */
252
36
  directory?: string;
253
37
  }
@@ -255,9 +39,30 @@ declare class LocalEmailProvider implements EmailProvider {
255
39
  protected readonly log: _alepha_logger0.Logger;
256
40
  protected readonly directory: string;
257
41
  constructor(options?: LocalEmailProviderOptions);
258
- send(to: string, subject: string, body: string): Promise<void>;
259
- protected createEmailHtml(to: string, subject: string, body: string): string;
260
- protected escapeHtml(text: string): string;
42
+ send(options: EmailSendOptions): Promise<void>;
43
+ createEmailHtml(options: {
44
+ to: string;
45
+ subject: string;
46
+ body: string;
47
+ }): string;
48
+ escapeHtml(text: string): string;
49
+ }
50
+ //#endregion
51
+ //#region src/providers/MemoryEmailProvider.d.ts
52
+ interface EmailRecord {
53
+ to: string;
54
+ subject: string;
55
+ body: string;
56
+ sentAt: Date;
57
+ }
58
+ declare class MemoryEmailProvider implements EmailProvider {
59
+ protected readonly log: _alepha_logger0.Logger;
60
+ records: EmailRecord[];
61
+ send(options: EmailSendOptions): Promise<void>;
62
+ /**
63
+ * Get the last email sent (for testing purposes).
64
+ */
65
+ get last(): EmailRecord | undefined;
261
66
  }
262
67
  //#endregion
263
68
  //#region src/providers/NodemailerEmailProvider.d.ts
@@ -297,7 +102,7 @@ declare class NodemailerEmailProvider implements EmailProvider {
297
102
  protected fromAddress: string;
298
103
  readonly options: NodemailerEmailProviderOptions;
299
104
  constructor();
300
- send(to: string, subject: string, body: string): Promise<void>;
105
+ send(options: EmailSendOptions): Promise<void>;
301
106
  protected createTransporter(): Transporter;
302
107
  /**
303
108
  * Verify the connection to the email server.
@@ -312,6 +117,17 @@ declare class NodemailerEmailProvider implements EmailProvider {
312
117
  }
313
118
  //#endregion
314
119
  //#region src/index.d.ts
120
+ declare module "alepha" {
121
+ interface Hooks {
122
+ "email:sending": {
123
+ to: string | string[];
124
+ template: string;
125
+ variables: Record<string, unknown>;
126
+ provider: EmailProvider;
127
+ abort(): void;
128
+ };
129
+ }
130
+ }
315
131
  /**
316
132
  * Provides email sending capabilities for Alepha applications with multiple provider backends.
317
133
  *
@@ -324,5 +140,5 @@ declare class NodemailerEmailProvider implements EmailProvider {
324
140
  */
325
141
  declare const AlephaEmail: _alepha_core1.Service<_alepha_core1.Module<{}>>;
326
142
  //#endregion
327
- export { $email, AlephaEmail, EmailDescriptor, EmailDescriptorOptions, EmailError, EmailProvider, EmailRecord, LocalEmailProvider, LocalEmailProviderOptions, MemoryEmailProvider, NodemailerEmailProvider, NodemailerEmailProviderOptions, TemplateService };
143
+ export { AlephaEmail, EmailError, EmailProvider, EmailRecord, EmailSendOptions, LocalEmailProvider, LocalEmailProviderOptions, MemoryEmailProvider, NodemailerEmailProvider, NodemailerEmailProviderOptions };
328
144
  //# sourceMappingURL=index.d.ts.map
package/lock.d.ts CHANGED
@@ -273,7 +273,7 @@ declare const $lock: {
273
273
  <TFunc extends AsyncFn>(options: LockDescriptorOptions<TFunc>): LockDescriptor<TFunc>;
274
274
  [KIND]: typeof LockDescriptor;
275
275
  };
276
- interface LockDescriptorOptions<TFunc extends AsyncFn> {
276
+ interface LockDescriptorOptions<TFunc$1 extends AsyncFn> {
277
277
  /**
278
278
  * The function to execute when the lock is successfully acquired.
279
279
  *
@@ -308,7 +308,7 @@ interface LockDescriptorOptions<TFunc extends AsyncFn> {
308
308
  * }
309
309
  * ```
310
310
  */
311
- handler: TFunc;
311
+ handler: TFunc$1;
312
312
  /**
313
313
  * Whether the lock should wait for other instances to complete before giving up.
314
314
  *
@@ -388,7 +388,7 @@ interface LockDescriptorOptions<TFunc extends AsyncFn> {
388
388
  * });
389
389
  * ```
390
390
  */
391
- name?: string | ((...args: Parameters<TFunc>) => string);
391
+ name?: string | ((...args: Parameters<TFunc$1>) => string);
392
392
  /**
393
393
  * Maximum duration the lock can be held before it expires automatically.
394
394
  *
@@ -474,7 +474,7 @@ interface LockDescriptorOptions<TFunc extends AsyncFn> {
474
474
  * });
475
475
  * ```
476
476
  */
477
- gracePeriod?: ((...args: Parameters<TFunc>) => DurationLike | undefined) | DurationLike;
477
+ gracePeriod?: ((...args: Parameters<TFunc$1>) => DurationLike | undefined) | DurationLike;
478
478
  }
479
479
  declare const envSchema: _alepha_core1.TObject<{
480
480
  LOCK_PREFIX_KEY: _alepha_core1.TString;
@@ -482,7 +482,7 @@ declare const envSchema: _alepha_core1.TObject<{
482
482
  declare module "alepha" {
483
483
  interface Env extends Partial<Static<typeof envSchema>> {}
484
484
  }
485
- declare class LockDescriptor<TFunc extends AsyncFn> extends Descriptor<LockDescriptorOptions<TFunc>> {
485
+ declare class LockDescriptor<TFunc$1 extends AsyncFn> extends Descriptor<LockDescriptorOptions<TFunc$1>> {
486
486
  protected readonly log: _alepha_logger0.Logger;
487
487
  protected readonly provider: LockProvider;
488
488
  protected readonly env: {
@@ -496,14 +496,14 @@ declare class LockDescriptor<TFunc extends AsyncFn> extends Descriptor<LockDescr
496
496
  name: _alepha_core1.TString;
497
497
  }>;
498
498
  }>;
499
- run(...args: Parameters<TFunc>): Promise<void>;
499
+ run(...args: Parameters<TFunc$1>): Promise<void>;
500
500
  /**
501
501
  * Set the lock for the given key.
502
502
  */
503
503
  protected lock(key: string): Promise<LockResult>;
504
- protected setGracePeriod(key: string, lock: LockResult, ...args: Parameters<TFunc>): Promise<void>;
504
+ protected setGracePeriod(key: string, lock: LockResult, ...args: Parameters<TFunc$1>): Promise<void>;
505
505
  protected wait(key: string, maxDuration: DurationLike): Promise<void>;
506
- protected key(...args: Parameters<TFunc>): string;
506
+ protected key(...args: Parameters<TFunc$1>): string;
507
507
  protected parse(value: string): LockResult;
508
508
  }
509
509
  interface LockResult {
package/logger.d.ts CHANGED
@@ -269,7 +269,6 @@ declare module "alepha" {
269
269
  }
270
270
  }
271
271
  //# sourceMappingURL=index.d.ts.map
272
-
273
272
  //#endregion
274
273
  export { $logger, AlephaLogger, ConsoleColorProvider, ConsoleDestinationProvider, JsonFormatterProvider, LogDestinationProvider, LogEntry, LogFormatterProvider, Logger, LoggerDescriptorOptions, MemoryDestinationProvider, SimpleFormatterProvider, logEntrySchema };
275
274
  //# sourceMappingURL=index.d.ts.map