Skip to content

Commit 1acfb83

Browse files
chore: wip
1 parent d384ba1 commit 1acfb83

File tree

9 files changed

+35
-61
lines changed

9 files changed

+35
-61
lines changed

storage/framework/core/cache/src/drivers/dynamodb.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ export class DynamoDBCacheDriver extends BaseCacheDriver {
3838
),
3939
},
4040
})
41-
41+
4242
super(client)
4343
}
4444
}
4545

46-
export const dynamodb: DynamoDBCacheDriver = new DynamoDBCacheDriver()
46+
export const dynamodb: DynamoDBCacheDriver = new DynamoDBCacheDriver()

storage/framework/core/cache/src/drivers/filesystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ export class FileSystemCacheDriver extends BaseCacheDriver {
2727
}
2828

2929
// Export a singleton instance with default config
30-
export const fileSystem = new FileSystemCacheDriver()
30+
export const fileSystem = new FileSystemCacheDriver()

storage/framework/core/cache/src/drivers/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// index.ts
22
import type { CacheDriver } from '@stacksjs/types'
3+
import type { DynamoDBOptions } from './dynamodb'
4+
import type { FileSystemOptions } from './filesystem'
5+
import type { RedisOptions } from './redis'
36
import { config } from '@stacksjs/config'
4-
import { dynamodb, DynamoDBCacheDriver, type DynamoDBOptions } from './dynamodb'
5-
import { fileSystem, FileSystemCacheDriver, type FileSystemOptions } from './filesystem'
7+
import { dynamodb, DynamoDBCacheDriver } from './dynamodb'
8+
import { fileSystem, FileSystemCacheDriver } from './filesystem'
69
import { memory, MemoryCacheDriver } from './memory'
7-
import { redis, RedisCacheDriver, type RedisOptions } from './redis'
10+
import { redis, RedisCacheDriver } from './redis'
811

912
// Map of available drivers
1013
const drivers: Record<string, CacheDriver> = {
@@ -35,11 +38,11 @@ export { redis, RedisCacheDriver, type RedisOptions } from './redis'
3538
*/
3639
export function createCache(driver: 'redis', options?: RedisOptions): CacheDriver
3740
export function createCache(driver: 'fileSystem', options?: FileSystemOptions): CacheDriver
38-
export function createCache(driver: 'memory', options?: { maxSize?: number; maxItems?: number }): CacheDriver
41+
export function createCache(driver: 'memory', options?: { maxSize?: number, maxItems?: number }): CacheDriver
3942
export function createCache(driver: 'dynamodb', options?: DynamoDBOptions): CacheDriver
4043
export function createCache(
4144
driver: 'redis' | 'fileSystem' | 'memory' | 'dynamodb',
42-
options?: any
45+
options?: any,
4346
): CacheDriver {
4447
switch (driver) {
4548
case 'redis':
@@ -53,4 +56,4 @@ export function createCache(
5356
default:
5457
return memory
5558
}
56-
}
59+
}

storage/framework/core/cache/src/drivers/redis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ export class RedisCacheDriver extends BaseCacheDriver {
3737
}
3838

3939
// Export a singleton instance with default config
40-
export const redis: RedisCacheDriver = new RedisCacheDriver()
40+
export const redis: RedisCacheDriver = new RedisCacheDriver()

storage/framework/core/email/src/drivers/mailtrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { EmailAddress, EmailMessage, EmailResult, MailtrapConfig, RenderOptions } from '@stacksjs/types'
22
import { Buffer } from 'node:buffer'
33
import { log } from '@stacksjs/logging'
4-
import { BaseEmailDriver } from '../base'
54
import { template } from '../template'
5+
import { BaseEmailDriver } from './base'
66

77
export class MailtrapDriver extends BaseEmailDriver {
88
public name = 'mailtrap'

storage/framework/core/email/src/drivers/sendgrid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { EmailAddress, EmailMessage, EmailResult, RenderOptions, SendGridConfig } from '@stacksjs/types'
22
import { Buffer } from 'node:buffer'
33
import { log } from '@stacksjs/logging'
4-
import { BaseEmailDriver } from '../base'
54
import { template } from '../template'
5+
import { BaseEmailDriver } from './base'
66

77
export class SendGridDriver extends BaseEmailDriver {
88
public name = 'sendgrid'
Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
1-
import type { EmailMessage, EmailResult, RenderOptions, SESConfig } from '@stacksjs/types'
1+
import type { EmailMessage, EmailResult, RenderOptions } from '@stacksjs/types'
22
import { SendEmailCommand, SES } from '@aws-sdk/client-ses'
3-
import { log } from '@stacksjs/logging'
4-
import { BaseEmailDriver } from '../base'
3+
import { config } from '@stacksjs/config'
54
import { template } from '../template'
5+
import { BaseEmailDriver } from './base'
66

77
export class SESDriver extends BaseEmailDriver {
88
public name = 'ses'
99
private client: SES
1010

11-
constructor(config: SESConfig) {
12-
super(config)
11+
constructor() {
12+
super()
13+
14+
const credentials = {
15+
accessKeyId: config.email.drivers?.ses?.credentials?.accessKeyId ?? '',
16+
secretAccessKey: config.email.drivers?.ses?.credentials?.secretAccessKey ?? '',
17+
}
18+
1319
this.client = new SES({
14-
region: config.region,
15-
credentials: config.credentials,
20+
region: config.email.drivers?.ses?.region || 'us-east-1',
21+
credentials,
1622
})
1723
}
1824

1925
public async send(message: EmailMessage, options?: RenderOptions): Promise<EmailResult> {
20-
const logContext = {
21-
provider: this.name,
22-
to: message.to,
23-
subject: message.subject,
24-
template: message.template,
25-
}
26-
27-
log.info('Sending email...', logContext)
28-
2926
try {
3027
this.validateMessage(message)
3128
const templ = await template(message.template, options)
3229

3330
const params = {
34-
Source: message.from.name
35-
? `${message.from.name} <${message.from.address}>`
36-
: message.from.address,
31+
Source: message.from?.address || config.email.from?.address,
3732

3833
Destination: {
3934
ToAddresses: this.formatAddresses(message.to),
@@ -44,48 +39,24 @@ export class SESDriver extends BaseEmailDriver {
4439
Message: {
4540
Body: {
4641
Html: {
47-
Charset: 'UTF-8',
42+
Charset: config.email.charset || 'UTF-8',
4843
Data: templ.html,
4944
},
50-
...(message.text && {
51-
Text: {
52-
Charset: 'UTF-8',
53-
Data: message.text,
54-
},
55-
}),
5645
},
5746
Subject: {
58-
Charset: 'UTF-8',
47+
Charset: config.email.charset || 'UTF-8',
5948
Data: message.subject,
6049
},
6150
},
6251
}
6352

64-
const response = await this.sendWithRetry(params)
53+
const response = await this.client.send(new SendEmailCommand(params))
6554
return this.handleSuccess(message, response.MessageId)
6655
}
6756
catch (error) {
6857
return this.handleError(error, message)
6958
}
7059
}
71-
72-
/**
73-
* SES-specific retry logic
74-
*/
75-
private async sendWithRetry(params: any, attempt = 1): Promise<any> {
76-
try {
77-
const command = new SendEmailCommand(params)
78-
const response = await this.client.send(command)
79-
log.info(`[${this.name}] Email sent successfully`, { attempt })
80-
return response
81-
}
82-
catch (error) {
83-
if (attempt < this.config.maxRetries) {
84-
log.warn(`[${this.name}] Email send failed, retrying (${attempt}/${this.config.maxRetries})`)
85-
await new Promise(resolve => setTimeout(resolve, this.config.retryTimeout))
86-
return this.sendWithRetry(params, attempt + 1)
87-
}
88-
throw error
89-
}
90-
}
9160
}
61+
62+
export default SESDriver

storage/framework/core/types/src/email.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface EmailOptions {
1616
}
1717

1818
default: 'ses' | 'sendgrid' | 'mailtrap'
19-
19+
2020
drivers: {
2121
ses?: {
2222
region: string

0 commit comments

Comments
 (0)