@stacksjs/ts-cloud-core 0.1.1
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.md +21 -0
- package/README.md +321 -0
- package/package.json +31 -0
- package/src/advanced-features.test.ts +465 -0
- package/src/aws/cloudformation.ts +421 -0
- package/src/aws/cloudfront.ts +158 -0
- package/src/aws/credentials.test.ts +132 -0
- package/src/aws/credentials.ts +545 -0
- package/src/aws/index.ts +87 -0
- package/src/aws/s3.test.ts +188 -0
- package/src/aws/s3.ts +1088 -0
- package/src/aws/signature.test.ts +670 -0
- package/src/aws/signature.ts +1155 -0
- package/src/backup/disaster-recovery.test.ts +726 -0
- package/src/backup/disaster-recovery.ts +500 -0
- package/src/backup/index.ts +34 -0
- package/src/backup/manager.test.ts +498 -0
- package/src/backup/manager.ts +432 -0
- package/src/cicd/circleci.ts +430 -0
- package/src/cicd/github-actions.ts +424 -0
- package/src/cicd/gitlab-ci.ts +255 -0
- package/src/cicd/index.ts +8 -0
- package/src/cli/history.ts +396 -0
- package/src/cli/index.ts +10 -0
- package/src/cli/progress.ts +458 -0
- package/src/cli/repl.ts +454 -0
- package/src/cli/suggestions.ts +327 -0
- package/src/cli/table.test.ts +319 -0
- package/src/cli/table.ts +332 -0
- package/src/cloudformation/builder.test.ts +327 -0
- package/src/cloudformation/builder.ts +378 -0
- package/src/cloudformation/builders/api-gateway.ts +449 -0
- package/src/cloudformation/builders/cache.ts +334 -0
- package/src/cloudformation/builders/cdn.ts +278 -0
- package/src/cloudformation/builders/compute.ts +485 -0
- package/src/cloudformation/builders/database.ts +392 -0
- package/src/cloudformation/builders/functions.ts +343 -0
- package/src/cloudformation/builders/messaging.ts +140 -0
- package/src/cloudformation/builders/monitoring.ts +300 -0
- package/src/cloudformation/builders/network.ts +264 -0
- package/src/cloudformation/builders/queue.ts +147 -0
- package/src/cloudformation/builders/security.ts +399 -0
- package/src/cloudformation/builders/storage.ts +285 -0
- package/src/cloudformation/index.ts +30 -0
- package/src/cloudformation/types.ts +173 -0
- package/src/compliance/aws-config.ts +543 -0
- package/src/compliance/cloudtrail.ts +376 -0
- package/src/compliance/compliance.test.ts +423 -0
- package/src/compliance/guardduty.ts +446 -0
- package/src/compliance/index.ts +66 -0
- package/src/compliance/security-hub.ts +456 -0
- package/src/containers/build-optimization.ts +416 -0
- package/src/containers/containers.test.ts +508 -0
- package/src/containers/image-scanning.ts +360 -0
- package/src/containers/index.ts +9 -0
- package/src/containers/registry.ts +293 -0
- package/src/containers/service-mesh.ts +520 -0
- package/src/database/database.test.ts +762 -0
- package/src/database/index.ts +9 -0
- package/src/database/migrations.ts +444 -0
- package/src/database/performance.ts +528 -0
- package/src/database/replicas.ts +534 -0
- package/src/database/users.ts +494 -0
- package/src/dependency-graph.ts +143 -0
- package/src/deployment/ab-testing.ts +582 -0
- package/src/deployment/blue-green.ts +452 -0
- package/src/deployment/canary.ts +500 -0
- package/src/deployment/deployment.test.ts +526 -0
- package/src/deployment/index.ts +61 -0
- package/src/deployment/progressive.ts +62 -0
- package/src/dns/dns.test.ts +641 -0
- package/src/dns/dnssec.ts +315 -0
- package/src/dns/index.ts +8 -0
- package/src/dns/resolver.ts +496 -0
- package/src/dns/routing.ts +593 -0
- package/src/email/advanced/analytics.ts +445 -0
- package/src/email/advanced/index.ts +11 -0
- package/src/email/advanced/rules.ts +465 -0
- package/src/email/advanced/scheduling.ts +352 -0
- package/src/email/advanced/search.ts +412 -0
- package/src/email/advanced/shared-mailboxes.ts +404 -0
- package/src/email/advanced/templates.ts +455 -0
- package/src/email/advanced/threading.ts +281 -0
- package/src/email/analytics.ts +467 -0
- package/src/email/bounce-handling.ts +425 -0
- package/src/email/email.test.ts +431 -0
- package/src/email/handlers/__tests__/inbound.test.ts +38 -0
- package/src/email/handlers/__tests__/outbound.test.ts +37 -0
- package/src/email/handlers/converter.ts +227 -0
- package/src/email/handlers/feedback.ts +228 -0
- package/src/email/handlers/inbound.ts +169 -0
- package/src/email/handlers/outbound.ts +178 -0
- package/src/email/index.ts +15 -0
- package/src/email/reputation.ts +303 -0
- package/src/email/templates.ts +352 -0
- package/src/errors/index.test.ts +434 -0
- package/src/errors/index.ts +416 -0
- package/src/health-checks/index.ts +40 -0
- package/src/index.ts +360 -0
- package/src/intrinsic-functions.ts +118 -0
- package/src/lambda/concurrency.ts +330 -0
- package/src/lambda/destinations.ts +345 -0
- package/src/lambda/dlq.ts +425 -0
- package/src/lambda/index.ts +11 -0
- package/src/lambda/lambda.test.ts +840 -0
- package/src/lambda/layers.ts +263 -0
- package/src/lambda/versions.ts +376 -0
- package/src/lambda/vpc.ts +399 -0
- package/src/local/config.ts +114 -0
- package/src/local/index.ts +6 -0
- package/src/local/mock-aws.ts +351 -0
- package/src/modules/ai.ts +340 -0
- package/src/modules/api.ts +478 -0
- package/src/modules/auth.ts +805 -0
- package/src/modules/cache.ts +417 -0
- package/src/modules/cdn.ts +1062 -0
- package/src/modules/communication.ts +1094 -0
- package/src/modules/compute.ts +3348 -0
- package/src/modules/database.ts +554 -0
- package/src/modules/deployment.ts +1079 -0
- package/src/modules/dns.ts +337 -0
- package/src/modules/email.ts +1538 -0
- package/src/modules/filesystem.ts +515 -0
- package/src/modules/index.ts +32 -0
- package/src/modules/messaging.ts +486 -0
- package/src/modules/monitoring.ts +2086 -0
- package/src/modules/network.ts +664 -0
- package/src/modules/parameter-store.ts +325 -0
- package/src/modules/permissions.ts +1081 -0
- package/src/modules/phone.ts +494 -0
- package/src/modules/queue.ts +1260 -0
- package/src/modules/redirects.ts +464 -0
- package/src/modules/registry.ts +699 -0
- package/src/modules/search.ts +401 -0
- package/src/modules/secrets.ts +416 -0
- package/src/modules/security.ts +731 -0
- package/src/modules/sms.ts +389 -0
- package/src/modules/storage.ts +1120 -0
- package/src/modules/workflow.ts +680 -0
- package/src/multi-account/config.ts +521 -0
- package/src/multi-account/index.ts +7 -0
- package/src/multi-account/manager.ts +427 -0
- package/src/multi-region/cross-region.ts +410 -0
- package/src/multi-region/index.ts +8 -0
- package/src/multi-region/manager.ts +483 -0
- package/src/multi-region/regions.ts +435 -0
- package/src/network-security/index.ts +48 -0
- package/src/observability/index.ts +9 -0
- package/src/observability/logs.ts +522 -0
- package/src/observability/metrics.ts +460 -0
- package/src/observability/observability.test.ts +782 -0
- package/src/observability/synthetics.ts +568 -0
- package/src/observability/xray.ts +358 -0
- package/src/phone/advanced/analytics.ts +349 -0
- package/src/phone/advanced/callbacks.ts +428 -0
- package/src/phone/advanced/index.ts +8 -0
- package/src/phone/advanced/ivr-builder.ts +504 -0
- package/src/phone/advanced/recording.ts +310 -0
- package/src/phone/handlers/__tests__/incoming-call.test.ts +40 -0
- package/src/phone/handlers/incoming-call.ts +117 -0
- package/src/phone/handlers/missed-call.ts +116 -0
- package/src/phone/handlers/voicemail.ts +179 -0
- package/src/phone/index.ts +9 -0
- package/src/presets/api-backend.ts +134 -0
- package/src/presets/data-pipeline.ts +204 -0
- package/src/presets/extend.test.ts +295 -0
- package/src/presets/extend.ts +297 -0
- package/src/presets/fullstack-app.ts +144 -0
- package/src/presets/index.ts +27 -0
- package/src/presets/jamstack.ts +135 -0
- package/src/presets/microservices.ts +167 -0
- package/src/presets/ml-api.ts +208 -0
- package/src/presets/nodejs-server.ts +104 -0
- package/src/presets/nodejs-serverless.ts +114 -0
- package/src/presets/realtime-app.ts +184 -0
- package/src/presets/static-site.ts +64 -0
- package/src/presets/traditional-web-app.ts +339 -0
- package/src/presets/wordpress.ts +138 -0
- package/src/preview/github.test.ts +249 -0
- package/src/preview/github.ts +297 -0
- package/src/preview/index.ts +37 -0
- package/src/preview/manager.test.ts +440 -0
- package/src/preview/manager.ts +326 -0
- package/src/preview/notifications.test.ts +582 -0
- package/src/preview/notifications.ts +341 -0
- package/src/queue/batch-processing.ts +402 -0
- package/src/queue/dlq-monitoring.ts +402 -0
- package/src/queue/fifo.ts +342 -0
- package/src/queue/index.ts +9 -0
- package/src/queue/management.ts +428 -0
- package/src/queue/queue.test.ts +429 -0
- package/src/resource-mgmt/index.ts +39 -0
- package/src/resource-naming.ts +62 -0
- package/src/s3/index.ts +523 -0
- package/src/schema/cloud-config.schema.json +554 -0
- package/src/schema/index.ts +68 -0
- package/src/security/certificate-manager.ts +492 -0
- package/src/security/index.ts +9 -0
- package/src/security/scanning.ts +545 -0
- package/src/security/secrets-manager.ts +476 -0
- package/src/security/secrets-rotation.ts +456 -0
- package/src/security/security.test.ts +738 -0
- package/src/sms/advanced/ab-testing.ts +389 -0
- package/src/sms/advanced/analytics.ts +336 -0
- package/src/sms/advanced/campaigns.ts +523 -0
- package/src/sms/advanced/chatbot.ts +224 -0
- package/src/sms/advanced/index.ts +10 -0
- package/src/sms/advanced/link-tracking.ts +248 -0
- package/src/sms/advanced/mms.ts +308 -0
- package/src/sms/handlers/__tests__/send.test.ts +40 -0
- package/src/sms/handlers/delivery-status.ts +133 -0
- package/src/sms/handlers/receive.ts +162 -0
- package/src/sms/handlers/send.ts +174 -0
- package/src/sms/index.ts +9 -0
- package/src/stack-diff.ts +389 -0
- package/src/static-site/index.ts +85 -0
- package/src/template-builder.ts +110 -0
- package/src/template-validator.ts +574 -0
- package/src/utils/cache.ts +291 -0
- package/src/utils/diff.ts +269 -0
- package/src/utils/hash.ts +227 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/parallel.ts +294 -0
- package/src/validators/credentials.test.ts +274 -0
- package/src/validators/credentials.ts +233 -0
- package/src/validators/quotas.test.ts +434 -0
- package/src/validators/quotas.ts +217 -0
- package/test/ai.test.ts +327 -0
- package/test/api.test.ts +511 -0
- package/test/auth.test.ts +632 -0
- package/test/cache.test.ts +406 -0
- package/test/cdn.test.ts +247 -0
- package/test/compute.test.ts +861 -0
- package/test/database.test.ts +523 -0
- package/test/deployment.test.ts +499 -0
- package/test/dns.test.ts +270 -0
- package/test/email.test.ts +439 -0
- package/test/filesystem.test.ts +382 -0
- package/test/integration.test.ts +350 -0
- package/test/messaging.test.ts +514 -0
- package/test/monitoring.test.ts +634 -0
- package/test/network.test.ts +425 -0
- package/test/permissions.test.ts +488 -0
- package/test/queue.test.ts +484 -0
- package/test/registry.test.ts +306 -0
- package/test/security.test.ts +462 -0
- package/test/storage.test.ts +463 -0
- package/test/template-validator.test.ts +559 -0
- package/test/workflow.test.ts +592 -0
- package/tsconfig.json +16 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outbound Email Lambda Handler
|
|
3
|
+
*
|
|
4
|
+
* Processes outgoing emails:
|
|
5
|
+
* - Accepts JSON email payloads from S3
|
|
6
|
+
* - Generates proper MIME messages
|
|
7
|
+
* - Supports HTML and plain text
|
|
8
|
+
* - Handles attachments (base64 encoded)
|
|
9
|
+
* - Tracks via configuration set
|
|
10
|
+
* - Stores sent emails in S3
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const handler = `
|
|
14
|
+
const { S3Client, GetObjectCommand, PutObjectCommand, DeleteObjectCommand } = require('@aws-sdk/client-s3');
|
|
15
|
+
const { SESClient, SendRawEmailCommand } = require('@aws-sdk/client-ses');
|
|
16
|
+
|
|
17
|
+
const s3 = new S3Client({});
|
|
18
|
+
const ses = new SESClient({});
|
|
19
|
+
|
|
20
|
+
exports.handler = async (event) => {
|
|
21
|
+
console.log('Outbound email event:', JSON.stringify(event, null, 2));
|
|
22
|
+
|
|
23
|
+
const bucket = process.env.EMAIL_BUCKET;
|
|
24
|
+
const configSet = process.env.CONFIG_SET || 'default';
|
|
25
|
+
|
|
26
|
+
for (const record of event.Records) {
|
|
27
|
+
try {
|
|
28
|
+
// Get the email payload from S3
|
|
29
|
+
const s3Event = record.s3 || {};
|
|
30
|
+
const key = decodeURIComponent(s3Event.object?.key?.replace(/\\+/g, ' ') || '');
|
|
31
|
+
|
|
32
|
+
if (!key || !key.startsWith('outbox/')) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const getResult = await s3.send(new GetObjectCommand({
|
|
37
|
+
Bucket: bucket,
|
|
38
|
+
Key: key,
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
const emailData = JSON.parse(await getResult.Body.transformToString());
|
|
42
|
+
|
|
43
|
+
// Build MIME message
|
|
44
|
+
const boundary = \`----=_Part_\${Date.now()}_\${Math.random().toString(36).substr(2)}\`;
|
|
45
|
+
const mixedBoundary = \`----=_Mixed_\${Date.now()}_\${Math.random().toString(36).substr(2)}\`;
|
|
46
|
+
|
|
47
|
+
let rawMessage = '';
|
|
48
|
+
|
|
49
|
+
// Headers
|
|
50
|
+
rawMessage += \`From: \${emailData.from}\\r\\n\`;
|
|
51
|
+
rawMessage += \`To: \${Array.isArray(emailData.to) ? emailData.to.join(', ') : emailData.to}\\r\\n\`;
|
|
52
|
+
|
|
53
|
+
if (emailData.cc) {
|
|
54
|
+
rawMessage += \`Cc: \${Array.isArray(emailData.cc) ? emailData.cc.join(', ') : emailData.cc}\\r\\n\`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (emailData.replyTo) {
|
|
58
|
+
rawMessage += \`Reply-To: \${emailData.replyTo}\\r\\n\`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
rawMessage += \`Subject: =?UTF-8?B?\${Buffer.from(emailData.subject || '').toString('base64')}?=\\r\\n\`;
|
|
62
|
+
rawMessage += \`Date: \${new Date().toUTCString()}\\r\\n\`;
|
|
63
|
+
rawMessage += \`Message-ID: <\${Date.now()}.\${Math.random().toString(36)}@\${emailData.from.split('@')[1] || 'local'}>\\r\\n\`;
|
|
64
|
+
rawMessage += 'MIME-Version: 1.0\\r\\n';
|
|
65
|
+
|
|
66
|
+
const hasAttachments = emailData.attachments && emailData.attachments.length > 0;
|
|
67
|
+
|
|
68
|
+
if (hasAttachments) {
|
|
69
|
+
rawMessage += \`Content-Type: multipart/mixed; boundary="\${mixedBoundary}"\\r\\n\\r\\n\`;
|
|
70
|
+
rawMessage += \`--\${mixedBoundary}\\r\\n\`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Body (multipart alternative for HTML + text)
|
|
74
|
+
if (emailData.html && emailData.text) {
|
|
75
|
+
rawMessage += \`Content-Type: multipart/alternative; boundary="\${boundary}"\\r\\n\\r\\n\`;
|
|
76
|
+
|
|
77
|
+
// Plain text part
|
|
78
|
+
rawMessage += \`--\${boundary}\\r\\n\`;
|
|
79
|
+
rawMessage += 'Content-Type: text/plain; charset=UTF-8\\r\\n';
|
|
80
|
+
rawMessage += 'Content-Transfer-Encoding: quoted-printable\\r\\n\\r\\n';
|
|
81
|
+
rawMessage += emailData.text + '\\r\\n\\r\\n';
|
|
82
|
+
|
|
83
|
+
// HTML part
|
|
84
|
+
rawMessage += \`--\${boundary}\\r\\n\`;
|
|
85
|
+
rawMessage += 'Content-Type: text/html; charset=UTF-8\\r\\n';
|
|
86
|
+
rawMessage += 'Content-Transfer-Encoding: quoted-printable\\r\\n\\r\\n';
|
|
87
|
+
rawMessage += emailData.html + '\\r\\n\\r\\n';
|
|
88
|
+
|
|
89
|
+
rawMessage += \`--\${boundary}--\\r\\n\`;
|
|
90
|
+
} else if (emailData.html) {
|
|
91
|
+
if (!hasAttachments) {
|
|
92
|
+
rawMessage += 'Content-Type: text/html; charset=UTF-8\\r\\n';
|
|
93
|
+
rawMessage += 'Content-Transfer-Encoding: quoted-printable\\r\\n\\r\\n';
|
|
94
|
+
} else {
|
|
95
|
+
rawMessage += 'Content-Type: text/html; charset=UTF-8\\r\\n\\r\\n';
|
|
96
|
+
}
|
|
97
|
+
rawMessage += emailData.html + '\\r\\n';
|
|
98
|
+
} else {
|
|
99
|
+
if (!hasAttachments) {
|
|
100
|
+
rawMessage += 'Content-Type: text/plain; charset=UTF-8\\r\\n';
|
|
101
|
+
rawMessage += 'Content-Transfer-Encoding: quoted-printable\\r\\n\\r\\n';
|
|
102
|
+
} else {
|
|
103
|
+
rawMessage += 'Content-Type: text/plain; charset=UTF-8\\r\\n\\r\\n';
|
|
104
|
+
}
|
|
105
|
+
rawMessage += (emailData.text || emailData.body || '') + '\\r\\n';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Attachments
|
|
109
|
+
if (hasAttachments) {
|
|
110
|
+
for (const attachment of emailData.attachments) {
|
|
111
|
+
rawMessage += \`--\${mixedBoundary}\\r\\n\`;
|
|
112
|
+
rawMessage += \`Content-Type: \${attachment.contentType || 'application/octet-stream'}; name="\${attachment.filename}"\\r\\n\`;
|
|
113
|
+
rawMessage += 'Content-Transfer-Encoding: base64\\r\\n';
|
|
114
|
+
rawMessage += \`Content-Disposition: attachment; filename="\${attachment.filename}"\\r\\n\\r\\n\`;
|
|
115
|
+
rawMessage += attachment.content + '\\r\\n';
|
|
116
|
+
}
|
|
117
|
+
rawMessage += \`--\${mixedBoundary}--\\r\\n\`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Send via SES
|
|
121
|
+
const sendResult = await ses.send(new SendRawEmailCommand({
|
|
122
|
+
RawMessage: { Data: Buffer.from(rawMessage) },
|
|
123
|
+
ConfigurationSetName: configSet,
|
|
124
|
+
}));
|
|
125
|
+
|
|
126
|
+
console.log(\`Email sent: \${sendResult.MessageId}\`);
|
|
127
|
+
|
|
128
|
+
// Store in sent folder
|
|
129
|
+
const timestamp = new Date();
|
|
130
|
+
const year = timestamp.getFullYear();
|
|
131
|
+
const month = String(timestamp.getMonth() + 1).padStart(2, '0');
|
|
132
|
+
const day = String(timestamp.getDate()).padStart(2, '0');
|
|
133
|
+
|
|
134
|
+
const fromEmail = emailData.from.match(/<([^>]+)>/) ? emailData.from.match(/<([^>]+)>/)[1] : emailData.from;
|
|
135
|
+
const [localPart, domain] = fromEmail.split('@');
|
|
136
|
+
|
|
137
|
+
const sentPath = \`mailboxes/\${domain}/\${localPart}/sent/\${year}/\${month}/\${day}/\${sendResult.MessageId}\`;
|
|
138
|
+
|
|
139
|
+
// Save sent email metadata
|
|
140
|
+
await s3.send(new PutObjectCommand({
|
|
141
|
+
Bucket: bucket,
|
|
142
|
+
Key: \`\${sentPath}/metadata.json\`,
|
|
143
|
+
Body: JSON.stringify({
|
|
144
|
+
messageId: sendResult.MessageId,
|
|
145
|
+
from: emailData.from,
|
|
146
|
+
to: emailData.to,
|
|
147
|
+
cc: emailData.cc,
|
|
148
|
+
subject: emailData.subject,
|
|
149
|
+
sentAt: timestamp.toISOString(),
|
|
150
|
+
hasAttachments,
|
|
151
|
+
}, null, 2),
|
|
152
|
+
ContentType: 'application/json',
|
|
153
|
+
}));
|
|
154
|
+
|
|
155
|
+
// Save raw message
|
|
156
|
+
await s3.send(new PutObjectCommand({
|
|
157
|
+
Bucket: bucket,
|
|
158
|
+
Key: \`\${sentPath}/raw.eml\`,
|
|
159
|
+
Body: rawMessage,
|
|
160
|
+
ContentType: 'message/rfc822',
|
|
161
|
+
}));
|
|
162
|
+
|
|
163
|
+
// Delete from outbox
|
|
164
|
+
await s3.send(new DeleteObjectCommand({
|
|
165
|
+
Bucket: bucket,
|
|
166
|
+
Key: key,
|
|
167
|
+
}));
|
|
168
|
+
|
|
169
|
+
} catch (error) {
|
|
170
|
+
console.error('Error sending email:', error);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return { statusCode: 200, body: 'OK' };
|
|
175
|
+
};
|
|
176
|
+
`
|
|
177
|
+
|
|
178
|
+
export default handler
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email Advanced Features
|
|
3
|
+
* Bounce handling, analytics, reputation monitoring, and template management
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export * from './bounce-handling'
|
|
7
|
+
export * from './analytics'
|
|
8
|
+
export * from './reputation'
|
|
9
|
+
export * from './templates'
|
|
10
|
+
|
|
11
|
+
// Advanced features (namespaced to avoid conflicts)
|
|
12
|
+
export * as EmailAdvanced from './advanced'
|
|
13
|
+
|
|
14
|
+
// Handlers (namespaced)
|
|
15
|
+
export * as EmailHandlers from './handlers/inbound'
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SES Sender Reputation Monitoring
|
|
3
|
+
* Reputation tracking, sending limits, and deliverability monitoring
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface ReputationDashboard {
|
|
7
|
+
id: string
|
|
8
|
+
timestamp: Date
|
|
9
|
+
overallScore: number
|
|
10
|
+
bounceRate: number
|
|
11
|
+
complaintRate: number
|
|
12
|
+
spamReports: number
|
|
13
|
+
blacklistStatus: BlacklistStatus[]
|
|
14
|
+
dkimStatus: 'VERIFIED' | 'PENDING' | 'FAILED'
|
|
15
|
+
spfStatus: 'PASS' | 'FAIL' | 'SOFTFAIL'
|
|
16
|
+
dmarcStatus: 'PASS' | 'FAIL' | 'NONE'
|
|
17
|
+
sendingLimits: SendingLimits
|
|
18
|
+
recommendations: string[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface BlacklistStatus {
|
|
22
|
+
listName: string
|
|
23
|
+
listed: boolean
|
|
24
|
+
listedAt?: Date
|
|
25
|
+
delistUrl?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SendingLimits {
|
|
29
|
+
maxSendRate: number // emails per second
|
|
30
|
+
max24HourSend: number
|
|
31
|
+
sentLast24Hours: number
|
|
32
|
+
remainingQuota: number
|
|
33
|
+
quotaResetTime: Date
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface WarmupPlan {
|
|
37
|
+
id: string
|
|
38
|
+
name: string
|
|
39
|
+
startDate: Date
|
|
40
|
+
currentDay: number
|
|
41
|
+
totalDays: number
|
|
42
|
+
dailyLimits: number[]
|
|
43
|
+
currentLimit: number
|
|
44
|
+
status: 'active' | 'paused' | 'completed'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface DomainReputation {
|
|
48
|
+
id: string
|
|
49
|
+
domain: string
|
|
50
|
+
reputationScore: number
|
|
51
|
+
totalSent: number
|
|
52
|
+
deliveryRate: number
|
|
53
|
+
openRate: number
|
|
54
|
+
clickRate: number
|
|
55
|
+
bounceRate: number
|
|
56
|
+
complaintRate: number
|
|
57
|
+
engagementScore: number
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Sender reputation manager
|
|
62
|
+
*/
|
|
63
|
+
export class SenderReputationManager {
|
|
64
|
+
private dashboards: Map<string, ReputationDashboard> = new Map()
|
|
65
|
+
private warmupPlans: Map<string, WarmupPlan> = new Map()
|
|
66
|
+
private domainReputations: Map<string, DomainReputation> = new Map()
|
|
67
|
+
private dashboardCounter = 0
|
|
68
|
+
private warmupCounter = 0
|
|
69
|
+
private domainCounter = 0
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Get reputation dashboard
|
|
73
|
+
*/
|
|
74
|
+
getReputationDashboard(): ReputationDashboard {
|
|
75
|
+
const id = `dashboard-${Date.now()}-${this.dashboardCounter++}`
|
|
76
|
+
|
|
77
|
+
const bounceRate = Math.random() * 5 // 0-5%
|
|
78
|
+
const complaintRate = Math.random() * 0.5 // 0-0.5%
|
|
79
|
+
const spamReports = Math.floor(Math.random() * 10)
|
|
80
|
+
|
|
81
|
+
// Calculate overall score (0-100)
|
|
82
|
+
const overallScore = Math.max(0, 100 - (bounceRate * 10) - (complaintRate * 100) - (spamReports * 2))
|
|
83
|
+
|
|
84
|
+
const recommendations: string[] = []
|
|
85
|
+
if (bounceRate > 2) recommendations.push('Reduce bounce rate by cleaning email list')
|
|
86
|
+
if (complaintRate > 0.1) recommendations.push('Review email content and unsubscribe process')
|
|
87
|
+
if (spamReports > 5) recommendations.push('Improve email relevance and targeting')
|
|
88
|
+
|
|
89
|
+
const dashboard: ReputationDashboard = {
|
|
90
|
+
id,
|
|
91
|
+
timestamp: new Date(),
|
|
92
|
+
overallScore,
|
|
93
|
+
bounceRate,
|
|
94
|
+
complaintRate,
|
|
95
|
+
spamReports,
|
|
96
|
+
blacklistStatus: this.checkBlacklists(),
|
|
97
|
+
dkimStatus: 'VERIFIED',
|
|
98
|
+
spfStatus: 'PASS',
|
|
99
|
+
dmarcStatus: 'PASS',
|
|
100
|
+
sendingLimits: {
|
|
101
|
+
maxSendRate: 14,
|
|
102
|
+
max24HourSend: 50000,
|
|
103
|
+
sentLast24Hours: 12000,
|
|
104
|
+
remainingQuota: 38000,
|
|
105
|
+
quotaResetTime: new Date(Date.now() + 24 * 60 * 60 * 1000),
|
|
106
|
+
},
|
|
107
|
+
recommendations,
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
this.dashboards.set(id, dashboard)
|
|
111
|
+
|
|
112
|
+
return dashboard
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Check blacklists
|
|
117
|
+
*/
|
|
118
|
+
private checkBlacklists(): BlacklistStatus[] {
|
|
119
|
+
const blacklists = [
|
|
120
|
+
'Spamhaus ZEN',
|
|
121
|
+
'Spamcop',
|
|
122
|
+
'SORBS',
|
|
123
|
+
'Barracuda',
|
|
124
|
+
'URIBL',
|
|
125
|
+
]
|
|
126
|
+
|
|
127
|
+
return blacklists.map(listName => ({
|
|
128
|
+
listName,
|
|
129
|
+
listed: Math.random() > 0.95, // 5% chance of being listed
|
|
130
|
+
delistUrl: `https://www.${listName.toLowerCase().replace(/\s/g, '')}.org/delist`,
|
|
131
|
+
}))
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Create warmup plan
|
|
136
|
+
*/
|
|
137
|
+
createWarmupPlan(options: {
|
|
138
|
+
name: string
|
|
139
|
+
initialDailyLimit: number
|
|
140
|
+
targetDailyLimit: number
|
|
141
|
+
durationDays: number
|
|
142
|
+
}): WarmupPlan {
|
|
143
|
+
const id = `warmup-${Date.now()}-${this.warmupCounter++}`
|
|
144
|
+
|
|
145
|
+
const dailyLimits: number[] = []
|
|
146
|
+
const increment = (options.targetDailyLimit - options.initialDailyLimit) / options.durationDays
|
|
147
|
+
|
|
148
|
+
for (let day = 0; day < options.durationDays; day++) {
|
|
149
|
+
dailyLimits.push(Math.floor(options.initialDailyLimit + (increment * day)))
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const warmupPlan: WarmupPlan = {
|
|
153
|
+
id,
|
|
154
|
+
name: options.name,
|
|
155
|
+
startDate: new Date(),
|
|
156
|
+
currentDay: 1,
|
|
157
|
+
totalDays: options.durationDays,
|
|
158
|
+
dailyLimits,
|
|
159
|
+
currentLimit: dailyLimits[0],
|
|
160
|
+
status: 'active',
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this.warmupPlans.set(id, warmupPlan)
|
|
164
|
+
|
|
165
|
+
return warmupPlan
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Create aggressive warmup plan
|
|
170
|
+
*/
|
|
171
|
+
createAggressiveWarmupPlan(options: {
|
|
172
|
+
name: string
|
|
173
|
+
}): WarmupPlan {
|
|
174
|
+
return this.createWarmupPlan({
|
|
175
|
+
name: options.name,
|
|
176
|
+
initialDailyLimit: 500,
|
|
177
|
+
targetDailyLimit: 50000,
|
|
178
|
+
durationDays: 14,
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Create conservative warmup plan
|
|
184
|
+
*/
|
|
185
|
+
createConservativeWarmupPlan(options: {
|
|
186
|
+
name: string
|
|
187
|
+
}): WarmupPlan {
|
|
188
|
+
return this.createWarmupPlan({
|
|
189
|
+
name: options.name,
|
|
190
|
+
initialDailyLimit: 200,
|
|
191
|
+
targetDailyLimit: 50000,
|
|
192
|
+
durationDays: 30,
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Advance warmup plan
|
|
198
|
+
*/
|
|
199
|
+
advanceWarmupPlan(warmupId: string): WarmupPlan {
|
|
200
|
+
const warmup = this.warmupPlans.get(warmupId)
|
|
201
|
+
|
|
202
|
+
if (!warmup) {
|
|
203
|
+
throw new Error(`Warmup plan not found: ${warmupId}`)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (warmup.currentDay < warmup.totalDays) {
|
|
207
|
+
warmup.currentDay++
|
|
208
|
+
warmup.currentLimit = warmup.dailyLimits[warmup.currentDay - 1]
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (warmup.currentDay >= warmup.totalDays) {
|
|
212
|
+
warmup.status = 'completed'
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return warmup
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Track domain reputation
|
|
220
|
+
*/
|
|
221
|
+
trackDomainReputation(options: {
|
|
222
|
+
domain: string
|
|
223
|
+
totalSent: number
|
|
224
|
+
delivered: number
|
|
225
|
+
opened: number
|
|
226
|
+
clicked: number
|
|
227
|
+
bounced: number
|
|
228
|
+
complained: number
|
|
229
|
+
}): DomainReputation {
|
|
230
|
+
const id = `domain-${Date.now()}-${this.domainCounter++}`
|
|
231
|
+
|
|
232
|
+
const deliveryRate = (options.delivered / options.totalSent) * 100
|
|
233
|
+
const openRate = options.delivered > 0 ? (options.opened / options.delivered) * 100 : 0
|
|
234
|
+
const clickRate = options.delivered > 0 ? (options.clicked / options.delivered) * 100 : 0
|
|
235
|
+
const bounceRate = (options.bounced / options.totalSent) * 100
|
|
236
|
+
const complaintRate = options.delivered > 0 ? (options.complained / options.delivered) * 100 : 0
|
|
237
|
+
|
|
238
|
+
const engagementScore = (openRate * 0.4) + (clickRate * 0.6)
|
|
239
|
+
const reputationScore = Math.max(0, 100 - (bounceRate * 10) - (complaintRate * 100) + (engagementScore * 0.2))
|
|
240
|
+
|
|
241
|
+
const domainReputation: DomainReputation = {
|
|
242
|
+
id,
|
|
243
|
+
domain: options.domain,
|
|
244
|
+
reputationScore,
|
|
245
|
+
totalSent: options.totalSent,
|
|
246
|
+
deliveryRate,
|
|
247
|
+
openRate,
|
|
248
|
+
clickRate,
|
|
249
|
+
bounceRate,
|
|
250
|
+
complaintRate,
|
|
251
|
+
engagementScore,
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
this.domainReputations.set(options.domain, domainReputation)
|
|
255
|
+
|
|
256
|
+
return domainReputation
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Get domain reputation
|
|
261
|
+
*/
|
|
262
|
+
getDomainReputation(domain: string): DomainReputation | undefined {
|
|
263
|
+
return this.domainReputations.get(domain)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* List all domain reputations
|
|
268
|
+
*/
|
|
269
|
+
listDomainReputations(): DomainReputation[] {
|
|
270
|
+
return Array.from(this.domainReputations.values())
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Get warmup plan
|
|
275
|
+
*/
|
|
276
|
+
getWarmupPlan(id: string): WarmupPlan | undefined {
|
|
277
|
+
return this.warmupPlans.get(id)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* List warmup plans
|
|
282
|
+
*/
|
|
283
|
+
listWarmupPlans(): WarmupPlan[] {
|
|
284
|
+
return Array.from(this.warmupPlans.values())
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Clear all data
|
|
289
|
+
*/
|
|
290
|
+
clear(): void {
|
|
291
|
+
this.dashboards.clear()
|
|
292
|
+
this.warmupPlans.clear()
|
|
293
|
+
this.domainReputations.clear()
|
|
294
|
+
this.dashboardCounter = 0
|
|
295
|
+
this.warmupCounter = 0
|
|
296
|
+
this.domainCounter = 0
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Global sender reputation manager instance
|
|
302
|
+
*/
|
|
303
|
+
export const senderReputationManager: SenderReputationManager = new SenderReputationManager()
|