alepha 0.9.3 → 0.9.5

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/datetime.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _alepha_core1 from "alepha";
2
- import * as _alepha_core0 from "alepha";
3
2
  import { Alepha, Descriptor, KIND } from "alepha";
3
+ import * as _alepha_logger0 from "alepha/logger";
4
4
  import dayjs, { Dayjs, ManipulateType } from "dayjs";
5
5
  import dayjsDuration from "dayjs/plugin/duration.js";
6
6
 
@@ -11,7 +11,7 @@ type Duration = dayjsDuration.Duration;
11
11
  type DurationLike = number | dayjsDuration.Duration | [number, ManipulateType];
12
12
  declare class DateTimeProvider {
13
13
  protected alepha: Alepha;
14
- protected log: _alepha_core1.Logger;
14
+ protected log: _alepha_logger0.Logger;
15
15
  protected ref: DateTime | null;
16
16
  protected readonly timeouts: Timeout[];
17
17
  protected readonly intervals: Interval[];
@@ -103,7 +103,6 @@ interface Timeout {
103
103
  callback: () => void;
104
104
  clear: () => void;
105
105
  }
106
- //# sourceMappingURL=DateTimeProvider.d.ts.map
107
106
  //#endregion
108
107
  //#region src/descriptors/$interval.d.ts
109
108
  /**
@@ -130,12 +129,9 @@ declare class IntervalDescriptor extends Descriptor<IntervalDescriptorOptions> {
130
129
  called: number;
131
130
  protected onInit(): void;
132
131
  }
133
- //# sourceMappingURL=$interval.d.ts.map
134
132
  //#endregion
135
133
  //#region src/index.d.ts
136
- declare const AlephaDateTime: _alepha_core0.Service<_alepha_core0.Module>;
137
- //# sourceMappingURL=index.d.ts.map
138
-
134
+ declare const AlephaDateTime: _alepha_core1.Service<_alepha_core1.Module>;
139
135
  //#endregion
140
136
  export { $interval, AlephaDateTime, DateTime, DateTimeApi, DateTimeProvider, Duration, DurationLike, Interval, IntervalDescriptor, IntervalDescriptorOptions, Timeout };
141
137
  //# sourceMappingURL=index.d.ts.map
package/email.cjs ADDED
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+ var m = require('@alepha/email');
3
+ Object.keys(m).forEach(function (k) {
4
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
5
+ enumerable: true,
6
+ get: function () { return m[k]; }
7
+ });
8
+ });
package/email.d.ts ADDED
@@ -0,0 +1,246 @@
1
+ import * as _alepha_core1 from "alepha";
2
+ import { Descriptor, KIND, Service, Static, TSchema } from "alepha";
3
+ import * as _alepha_logger0 from "alepha/logger";
4
+ import { Transporter } from "nodemailer";
5
+
6
+ //#region src/providers/EmailProvider.d.ts
7
+ /**
8
+ * Email provider interface.
9
+ *
10
+ * All methods are asynchronous and return promises.
11
+ */
12
+ declare abstract class EmailProvider {
13
+ /**
14
+ * Send an email.
15
+ *
16
+ * @param to The recipient email address.
17
+ * @param subject The email subject.
18
+ * @param body The email body (HTML content).
19
+ *
20
+ * @return Promise that resolves when the email is sent.
21
+ */
22
+ abstract send(to: string, subject: string, body: string): Promise<void>;
23
+ }
24
+ //#endregion
25
+ //#region src/providers/MemoryEmailProvider.d.ts
26
+ interface EmailRecord {
27
+ to: string;
28
+ subject: string;
29
+ 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
+ * Create an email descriptor for sending templated emails.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * import { $email } from "alepha/email";
95
+ * import { t } from "alepha";
96
+ *
97
+ * class App {
98
+ * welcome = $email({
99
+ * subject: "Welcome {{name}}!",
100
+ * body: "<h1>Welcome {{name}}!</h1><p>Your role is {{role}}.</p>",
101
+ * schema: t.object({
102
+ * name: t.string(),
103
+ * role: t.string()
104
+ * })
105
+ * });
106
+ *
107
+ * async sendWelcome(userEmail: string, name: string, role: string) {
108
+ * await this.welcome.send(userEmail, { name, role });
109
+ * }
110
+ * }
111
+ * ```
112
+ */
113
+ declare const $email: {
114
+ <T extends TSchema>(options: EmailDescriptorOptions<T>): EmailDescriptor<T>;
115
+ [KIND]: typeof EmailDescriptor;
116
+ };
117
+ interface EmailDescriptorOptions<T extends TSchema> {
118
+ /**
119
+ * Email subject template. Supports {{variableName}} syntax.
120
+ */
121
+ subject: string;
122
+ /**
123
+ * Email body template (HTML content). Supports {{variableName}} syntax.
124
+ */
125
+ body: string;
126
+ /**
127
+ * Schema defining the structure of template variables.
128
+ */
129
+ schema: T;
130
+ /**
131
+ * Optional name of the email template.
132
+ * @default Descriptor key
133
+ */
134
+ name?: string;
135
+ /**
136
+ * Optional description of the email template.
137
+ */
138
+ description?: string;
139
+ /**
140
+ * Email provider to use. If not provided, the default provider will be used.
141
+ */
142
+ provider?: Service<EmailProvider> | "memory";
143
+ }
144
+ declare class EmailDescriptor<T extends TSchema> extends Descriptor<EmailDescriptorOptions<T>> {
145
+ protected readonly log: _alepha_logger0.Logger;
146
+ protected readonly templateService: TemplateService;
147
+ readonly provider: EmailProvider | MemoryEmailProvider;
148
+ get name(): string;
149
+ /**
150
+ * Send an email using the template with the provided values.
151
+ *
152
+ * @param to Recipient email address
153
+ * @param values Template variable values
154
+ */
155
+ send(to: string, values: Static<T>): Promise<void>;
156
+ protected $provider(): EmailProvider | MemoryEmailProvider;
157
+ }
158
+ //#endregion
159
+ //#region src/errors/EmailError.d.ts
160
+ declare class EmailError extends Error {
161
+ constructor(message: string, cause?: Error);
162
+ }
163
+ //#endregion
164
+ //#region src/providers/LocalEmailProvider.d.ts
165
+ interface LocalEmailProviderOptions {
166
+ /**
167
+ * Directory to save email files.
168
+ * @default "email" (relative to project root)
169
+ */
170
+ directory?: string;
171
+ }
172
+ declare class LocalEmailProvider implements EmailProvider {
173
+ protected readonly log: _alepha_logger0.Logger;
174
+ protected readonly directory: string;
175
+ constructor(options?: LocalEmailProviderOptions);
176
+ send(to: string, subject: string, body: string): Promise<void>;
177
+ protected createEmailHtml(to: string, subject: string, body: string): string;
178
+ protected escapeHtml(text: string): string;
179
+ }
180
+ //#endregion
181
+ //#region src/providers/NodemailerEmailProvider.d.ts
182
+ interface NodemailerEmailProviderOptions {
183
+ /**
184
+ * Custom transporter configuration.
185
+ * If provided, will override environment variables.
186
+ */
187
+ transporter?: Transporter;
188
+ /**
189
+ * Custom from email address.
190
+ * If not provided, will use EMAIL_FROM from environment.
191
+ */
192
+ from?: string;
193
+ /**
194
+ * Additional nodemailer options.
195
+ */
196
+ options?: {
197
+ pool?: boolean;
198
+ maxConnections?: number;
199
+ maxMessages?: number;
200
+ rateDelta?: number;
201
+ rateLimit?: number;
202
+ };
203
+ }
204
+ declare class NodemailerEmailProvider implements EmailProvider {
205
+ protected readonly env: {
206
+ EMAIL_HOST: string;
207
+ EMAIL_PORT: number;
208
+ EMAIL_USER: string;
209
+ EMAIL_PASS: string;
210
+ EMAIL_FROM: string;
211
+ EMAIL_SECURE: boolean;
212
+ };
213
+ protected readonly log: _alepha_logger0.Logger;
214
+ protected transporter: Transporter;
215
+ protected fromAddress: string;
216
+ readonly options: NodemailerEmailProviderOptions;
217
+ constructor();
218
+ send(to: string, subject: string, body: string): Promise<void>;
219
+ protected createTransporter(): Transporter;
220
+ /**
221
+ * Verify the connection to the email server.
222
+ */
223
+ verify(): Promise<boolean>;
224
+ /**
225
+ * Close the transporter connection.
226
+ */
227
+ close(): void;
228
+ protected readonly onStart: _alepha_core1.HookDescriptor<"start">;
229
+ protected readonly onStop: _alepha_core1.HookDescriptor<"stop">;
230
+ }
231
+ //#endregion
232
+ //#region src/index.d.ts
233
+ /**
234
+ * Provides email sending capabilities for Alepha applications with multiple provider backends.
235
+ *
236
+ * The email module enables declarative email sending through the `$email` descriptor, allowing you to send
237
+ * emails through different providers: memory (for testing), local file system, or SMTP via Nodemailer.
238
+ * It supports HTML email content and automatic provider selection based on environment configuration.
239
+ *
240
+ * @see {@link EmailProvider}
241
+ * @module alepha.email
242
+ */
243
+ declare const AlephaEmail: _alepha_core1.Service<_alepha_core1.Module>;
244
+ //#endregion
245
+ export { $email, AlephaEmail, EmailDescriptor, EmailDescriptorOptions, EmailError, EmailProvider, EmailRecord, LocalEmailProvider, LocalEmailProviderOptions, MemoryEmailProvider, NodemailerEmailProvider, NodemailerEmailProviderOptions, TemplateService };
246
+ //# sourceMappingURL=index.d.ts.map
package/email.js ADDED
@@ -0,0 +1 @@
1
+ export * from '@alepha/email'
package/file.d.ts CHANGED
@@ -35,7 +35,6 @@ declare const streamToBuffer: (streamLike: StreamLike) => Promise<Buffer>;
35
35
  */
36
36
  declare const bufferToArrayBuffer: (buffer: Buffer) => ArrayBuffer;
37
37
  declare const isReadableStream: (obj: unknown) => obj is NodeJS.ReadableStream;
38
- //# sourceMappingURL=createFile.d.ts.map
39
38
  //#endregion
40
39
  //#region src/helpers/getContentType.d.ts
41
40
  /**
@@ -49,8 +48,6 @@ declare const mimeMap: Record<string, string>;
49
48
  * @see {mimeMap}
50
49
  */
51
50
  declare const getContentType: (filename: string) => string;
52
- //# sourceMappingURL=getContentType.d.ts.map
53
-
54
51
  //#endregion
55
52
  export { bufferToArrayBuffer, createFile, createFileFromBuffer, createFileFromStream, createFileFromUrl, createFileFromWebFile, getContentType, isReadableStream, mimeMap, streamToBuffer };
56
53
  //# sourceMappingURL=index.d.ts.map
package/lock/redis.d.ts CHANGED
@@ -1,16 +1,15 @@
1
1
  import * as _alepha_core0 from "alepha";
2
- import { Logger } from "alepha";
3
2
  import { LockProvider } from "alepha/lock";
3
+ import * as _alepha_logger0 from "alepha/logger";
4
4
  import { RedisProvider } from "alepha/redis";
5
5
 
6
6
  //#region src/providers/RedisLockProvider.d.ts
7
7
  declare class RedisLockProvider implements LockProvider {
8
- protected readonly log: Logger;
8
+ protected readonly log: _alepha_logger0.Logger;
9
9
  protected readonly redisProvider: RedisProvider;
10
10
  set(key: string, value: string, nx?: boolean, px?: number): Promise<string>;
11
11
  del(...keys: string[]): Promise<void>;
12
12
  }
13
- //# sourceMappingURL=RedisLockProvider.d.ts.map
14
13
  //#endregion
15
14
  //#region src/index.d.ts
16
15
  /**
@@ -20,8 +19,6 @@ declare class RedisLockProvider implements LockProvider {
20
19
  * @module alepha.lock.redis
21
20
  */
22
21
  declare const AlephaLockRedis: _alepha_core0.Service<_alepha_core0.Module>;
23
- //# sourceMappingURL=index.d.ts.map
24
-
25
22
  //#endregion
26
23
  export { AlephaLockRedis, RedisLockProvider };
27
24
  //# sourceMappingURL=index.d.ts.map