@airhornjs/aws 5.0.11 → 5.0.12
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.
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
102
102
|
Code coverage generated by
|
|
103
103
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
104
|
-
at 2025-
|
|
104
|
+
at 2025-10-06T06:27:33.003Z
|
|
105
105
|
</div>
|
|
106
106
|
<script src="prettify.js"></script>
|
|
107
107
|
<script>
|
|
@@ -802,7 +802,7 @@ export class AirhornAws implements AirhornProvider {
|
|
|
802
802
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
803
803
|
Code coverage generated by
|
|
804
804
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
805
|
-
at 2025-
|
|
805
|
+
at 2025-10-06T06:27:33.003Z
|
|
806
806
|
</div>
|
|
807
807
|
<script src="prettify.js"></script>
|
|
808
808
|
<script>
|
package/dist/index.js
CHANGED
|
@@ -1,184 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { SESClient, SendEmailCommand } from "@aws-sdk/client-ses";
|
|
3
|
-
import { PublishCommand, SNSClient } from "@aws-sdk/client-sns";
|
|
4
|
-
import {
|
|
5
|
-
AirhornSendType
|
|
6
|
-
} from "airhorn";
|
|
7
|
-
var AirhornAws = class {
|
|
8
|
-
name = "aws";
|
|
9
|
-
capabilities;
|
|
10
|
-
snsClient;
|
|
11
|
-
sesClient;
|
|
12
|
-
constructor(options) {
|
|
13
|
-
if (!options.region) {
|
|
14
|
-
throw new Error("AirhornAws requires region");
|
|
15
|
-
}
|
|
16
|
-
this.capabilities = options.capabilities || [
|
|
17
|
-
AirhornSendType.SMS,
|
|
18
|
-
AirhornSendType.MobilePush,
|
|
19
|
-
AirhornSendType.Email
|
|
20
|
-
];
|
|
21
|
-
const credentials = options.accessKeyId && options.secretAccessKey ? {
|
|
22
|
-
accessKeyId: options.accessKeyId,
|
|
23
|
-
secretAccessKey: options.secretAccessKey,
|
|
24
|
-
sessionToken: options.sessionToken
|
|
25
|
-
} : void 0;
|
|
26
|
-
if (this.capabilities.includes(AirhornSendType.SMS)) {
|
|
27
|
-
this.snsClient = new SNSClient({
|
|
28
|
-
region: options.region,
|
|
29
|
-
credentials
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
if (this.capabilities.includes(AirhornSendType.Email)) {
|
|
33
|
-
this.sesClient = new SESClient({
|
|
34
|
-
region: options.region,
|
|
35
|
-
credentials
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
async send(message, options) {
|
|
40
|
-
const result = {
|
|
41
|
-
success: false,
|
|
42
|
-
response: null,
|
|
43
|
-
errors: []
|
|
44
|
-
};
|
|
45
|
-
try {
|
|
46
|
-
if (message.type === AirhornSendType.SMS || message.type === AirhornSendType.MobilePush) {
|
|
47
|
-
return this.sendSMS(message, options);
|
|
48
|
-
}
|
|
49
|
-
if (message.type === AirhornSendType.Email) {
|
|
50
|
-
return this.sendEmail(message, options);
|
|
51
|
-
}
|
|
52
|
-
throw new Error(
|
|
53
|
-
`AirhornAws does not support message type: ${message.type}`
|
|
54
|
-
);
|
|
55
|
-
} catch (error) {
|
|
56
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
57
|
-
result.errors.push(err);
|
|
58
|
-
result.response = {
|
|
59
|
-
error: err.message,
|
|
60
|
-
details: error
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
async sendSMS(message, options) {
|
|
66
|
-
const result = {
|
|
67
|
-
success: false,
|
|
68
|
-
response: null,
|
|
69
|
-
errors: []
|
|
70
|
-
};
|
|
71
|
-
try {
|
|
72
|
-
if (!this.snsClient) {
|
|
73
|
-
throw new Error("SNS is not configured");
|
|
74
|
-
}
|
|
75
|
-
if (!message.from) {
|
|
76
|
-
throw new Error(
|
|
77
|
-
"From identifier is required for SMS/MobilePush messages"
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
let command;
|
|
81
|
-
if (message.type === AirhornSendType.MobilePush || message.to.startsWith("arn:")) {
|
|
82
|
-
command = new PublishCommand({
|
|
83
|
-
TargetArn: message.to,
|
|
84
|
-
Message: message.content,
|
|
85
|
-
MessageAttributes: options?.MessageAttributes,
|
|
86
|
-
MessageStructure: options?.MessageStructure,
|
|
87
|
-
...options
|
|
88
|
-
});
|
|
89
|
-
} else {
|
|
90
|
-
command = new PublishCommand({
|
|
91
|
-
PhoneNumber: message.to,
|
|
92
|
-
Message: message.content,
|
|
93
|
-
MessageAttributes: {
|
|
94
|
-
"AWS.SNS.SMS.SenderID": {
|
|
95
|
-
DataType: "String",
|
|
96
|
-
StringValue: message.from
|
|
97
|
-
},
|
|
98
|
-
"AWS.SNS.SMS.SMSType": {
|
|
99
|
-
DataType: "String",
|
|
100
|
-
StringValue: options?.smsType || "Transactional"
|
|
101
|
-
},
|
|
102
|
-
...options?.MessageAttributes
|
|
103
|
-
},
|
|
104
|
-
...options
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
const response = await this.snsClient.send(command);
|
|
108
|
-
result.success = true;
|
|
109
|
-
result.response = {
|
|
110
|
-
messageId: response.MessageId,
|
|
111
|
-
sequenceNumber: response.SequenceNumber,
|
|
112
|
-
metadata: response.$metadata
|
|
113
|
-
};
|
|
114
|
-
} catch (error) {
|
|
115
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
116
|
-
result.errors.push(err);
|
|
117
|
-
result.response = {
|
|
118
|
-
error: err.message,
|
|
119
|
-
details: error
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
async sendEmail(message, options) {
|
|
125
|
-
const result = {
|
|
126
|
-
success: false,
|
|
127
|
-
response: null,
|
|
128
|
-
errors: []
|
|
129
|
-
};
|
|
130
|
-
try {
|
|
131
|
-
if (!this.sesClient) {
|
|
132
|
-
throw new Error("SES is not configured");
|
|
133
|
-
}
|
|
134
|
-
if (!message.from) {
|
|
135
|
-
throw new Error("From email address is required for email messages");
|
|
136
|
-
}
|
|
137
|
-
const command = new SendEmailCommand({
|
|
138
|
-
Source: message.from,
|
|
139
|
-
Destination: {
|
|
140
|
-
ToAddresses: [message.to],
|
|
141
|
-
CcAddresses: options?.ccAddresses,
|
|
142
|
-
BccAddresses: options?.bccAddresses
|
|
143
|
-
},
|
|
144
|
-
Message: {
|
|
145
|
-
Subject: {
|
|
146
|
-
Data: message.subject || "Notification",
|
|
147
|
-
Charset: "UTF-8"
|
|
148
|
-
},
|
|
149
|
-
Body: {
|
|
150
|
-
Text: {
|
|
151
|
-
Data: message.content,
|
|
152
|
-
Charset: "UTF-8"
|
|
153
|
-
},
|
|
154
|
-
Html: {
|
|
155
|
-
Data: message.content,
|
|
156
|
-
Charset: "UTF-8"
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
ReplyToAddresses: options?.replyToAddresses,
|
|
161
|
-
ReturnPath: options?.returnPath,
|
|
162
|
-
ConfigurationSetName: options?.configurationSetName,
|
|
163
|
-
Tags: options?.tags
|
|
164
|
-
});
|
|
165
|
-
const response = await this.sesClient.send(command);
|
|
166
|
-
result.success = true;
|
|
167
|
-
result.response = {
|
|
168
|
-
messageId: response.MessageId,
|
|
169
|
-
metadata: response.$metadata
|
|
170
|
-
};
|
|
171
|
-
} catch (error) {
|
|
172
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
173
|
-
result.errors.push(err);
|
|
174
|
-
result.response = {
|
|
175
|
-
error: err.message,
|
|
176
|
-
details: error
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
return result;
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
export {
|
|
183
|
-
AirhornAws
|
|
184
|
-
};
|
|
1
|
+
import{SESClient as c,SendEmailCommand as d}from"@aws-sdk/client-ses";import{PublishCommand as o,SNSClient as l}from"@aws-sdk/client-sns";import{AirhornSendType as i}from"airhorn";var a=class{name="aws";capabilities;snsClient;sesClient;constructor(e){if(!e.region)throw new Error("AirhornAws requires region");this.capabilities=e.capabilities||[i.SMS,i.MobilePush,i.Email];let s=e.accessKeyId&&e.secretAccessKey?{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,sessionToken:e.sessionToken}:void 0;this.capabilities.includes(i.SMS)&&(this.snsClient=new l({region:e.region,credentials:s})),this.capabilities.includes(i.Email)&&(this.sesClient=new c({region:e.region,credentials:s}))}async send(e,s){let t={success:!1,response:null,errors:[]};try{if(e.type===i.SMS||e.type===i.MobilePush)return this.sendSMS(e,s);if(e.type===i.Email)return this.sendEmail(e,s);throw new Error(`AirhornAws does not support message type: ${e.type}`)}catch(r){let n=r instanceof Error?r:new Error(String(r));t.errors.push(n),t.response={error:n.message,details:r}}return t}async sendSMS(e,s){let t={success:!1,response:null,errors:[]};try{if(!this.snsClient)throw new Error("SNS is not configured");if(!e.from)throw new Error("From identifier is required for SMS/MobilePush messages");let r;e.type===i.MobilePush||e.to.startsWith("arn:")?r=new o({TargetArn:e.to,Message:e.content,MessageAttributes:s?.MessageAttributes,MessageStructure:s?.MessageStructure,...s}):r=new o({PhoneNumber:e.to,Message:e.content,MessageAttributes:{"AWS.SNS.SMS.SenderID":{DataType:"String",StringValue:e.from},"AWS.SNS.SMS.SMSType":{DataType:"String",StringValue:s?.smsType||"Transactional"},...s?.MessageAttributes},...s});let n=await this.snsClient.send(r);t.success=!0,t.response={messageId:n.MessageId,sequenceNumber:n.SequenceNumber,metadata:n.$metadata}}catch(r){let n=r instanceof Error?r:new Error(String(r));t.errors.push(n),t.response={error:n.message,details:r}}return t}async sendEmail(e,s){let t={success:!1,response:null,errors:[]};try{if(!this.sesClient)throw new Error("SES is not configured");if(!e.from)throw new Error("From email address is required for email messages");let r=new d({Source:e.from,Destination:{ToAddresses:[e.to],CcAddresses:s?.ccAddresses,BccAddresses:s?.bccAddresses},Message:{Subject:{Data:e.subject||"Notification",Charset:"UTF-8"},Body:{Text:{Data:e.content,Charset:"UTF-8"},Html:{Data:e.content,Charset:"UTF-8"}}},ReplyToAddresses:s?.replyToAddresses,ReturnPath:s?.returnPath,ConfigurationSetName:s?.configurationSetName,Tags:s?.tags}),n=await this.sesClient.send(r);t.success=!0,t.response={messageId:n.MessageId,metadata:n.$metadata}}catch(r){let n=r instanceof Error?r:new Error(String(r));t.errors.push(n),t.response={error:n.message,details:r}}return t}};export{a as AirhornAws};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@airhornjs/aws",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.12",
|
|
4
4
|
"description": "AWS SNS and SES provider for Airhorn",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,21 +33,21 @@
|
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"author": "Jared Wray <me@jaredwray.com>",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@aws-sdk/client-ses": "^3.
|
|
37
|
-
"@aws-sdk/client-sns": "^3.
|
|
36
|
+
"@aws-sdk/client-ses": "^3.901.0",
|
|
37
|
+
"@aws-sdk/client-sns": "^3.901.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@biomejs/biome": "^2.2.
|
|
41
|
-
"@types/node": "^24.
|
|
40
|
+
"@biomejs/biome": "^2.2.5",
|
|
41
|
+
"@types/node": "^24.6.2",
|
|
42
42
|
"@vitest/coverage-v8": "^3.2.4",
|
|
43
43
|
"rimraf": "^6.0.1",
|
|
44
44
|
"tsup": "^8.5.0",
|
|
45
|
-
"tsx": "^4.20.
|
|
46
|
-
"typescript": "^5.9.
|
|
45
|
+
"tsx": "^4.20.6",
|
|
46
|
+
"typescript": "^5.9.3",
|
|
47
47
|
"vitest": "^3.2.4"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"airhorn": "^5.0.
|
|
50
|
+
"airhorn": "^5.0.12"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"lint": "biome check --write --error-on-warnings",
|
|
@@ -55,6 +55,6 @@
|
|
|
55
55
|
"test:ci": "biome check --error-on-warnings && vitest run --coverage",
|
|
56
56
|
"clean": "rimraf ./dist ./coverage ./node_modules ./package-lock.json ./pnpm-lock.yaml",
|
|
57
57
|
"build:publish": "pnpm publish --access public --no-git-checks",
|
|
58
|
-
"build": "rimraf ./dist && tsup src/index.ts --format esm --dts --clean"
|
|
58
|
+
"build": "rimraf ./dist && tsup src/index.ts --format esm --dts --clean --minify"
|
|
59
59
|
}
|
|
60
60
|
}
|