@nauth-toolkit/sms-aws-sns 0.1.13 → 0.1.17
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/dist/aws-sms-config.interface.d.ts +69 -0
- package/dist/aws-sms-config.interface.d.ts.map +1 -1
- package/dist/aws-sms.provider.d.ts +97 -0
- package/dist/aws-sms.provider.d.ts.map +1 -1
- package/dist/aws-sms.provider.js +118 -0
- package/dist/aws-sms.provider.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,8 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS SNS SMS Configuration
|
|
3
|
+
*
|
|
4
|
+
* Minimal configuration for sending authentication SMS via AWS SNS.
|
|
5
|
+
* All messages are sent as transactional (highest priority).
|
|
6
|
+
*
|
|
7
|
+
* AWS credentials are optional - SDK will auto-discover from:
|
|
8
|
+
* - EC2 instance IAM role
|
|
9
|
+
* - ECS task role
|
|
10
|
+
* - Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
|
|
11
|
+
* - AWS credentials file (~/.aws/credentials)
|
|
12
|
+
* - AWS profile (AWS_PROFILE environment variable)
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // With IAM role (EC2, ECS, Lambda)
|
|
17
|
+
* const config: AWSSMSConfig = {
|
|
18
|
+
* region: 'us-east-1',
|
|
19
|
+
* originationNumber: '+12345678901',
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* // With explicit credentials (if needed)
|
|
23
|
+
* const config: AWSSMSConfig = {
|
|
24
|
+
* region: 'us-east-1',
|
|
25
|
+
* accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
|
|
26
|
+
* secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
|
|
27
|
+
* originationNumber: '+12345678901',
|
|
28
|
+
* };
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
1
31
|
export interface AWSSMSConfig {
|
|
32
|
+
/**
|
|
33
|
+
* AWS Region
|
|
34
|
+
* @example 'us-east-1'
|
|
35
|
+
*/
|
|
2
36
|
region: string;
|
|
37
|
+
/**
|
|
38
|
+
* AWS Access Key ID (Optional)
|
|
39
|
+
*
|
|
40
|
+
* If not provided, AWS SDK will auto-discover credentials from:
|
|
41
|
+
* - IAM instance role
|
|
42
|
+
* - Environment variables
|
|
43
|
+
* - AWS credentials file
|
|
44
|
+
*/
|
|
3
45
|
accessKeyId?: string;
|
|
46
|
+
/**
|
|
47
|
+
* AWS Secret Access Key (Optional)
|
|
48
|
+
*
|
|
49
|
+
* Required only if accessKeyId is provided.
|
|
50
|
+
*/
|
|
4
51
|
secretAccessKey?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Origination Number (E.164 format) or Sender ID
|
|
54
|
+
*
|
|
55
|
+
* - **US/Canada:** Phone number required (e.g., '+12345678901')
|
|
56
|
+
* - **Other regions:** Alphanumeric sender ID supported (e.g., 'MyApp')
|
|
57
|
+
*
|
|
58
|
+
* @example '+12345678901'
|
|
59
|
+
* @example 'MyApp'
|
|
60
|
+
*/
|
|
5
61
|
originationNumber: string;
|
|
62
|
+
/**
|
|
63
|
+
* AWS SNS Configuration Set Name (Optional)
|
|
64
|
+
*
|
|
65
|
+
* Use configuration sets to control:
|
|
66
|
+
* - CloudWatch metrics and logging
|
|
67
|
+
* - Event destinations (Kinesis, SQS, SNS)
|
|
68
|
+
* - Delivery status tracking
|
|
69
|
+
* - Spend limits and price controls
|
|
70
|
+
*
|
|
71
|
+
* Configure these settings in AWS Console, not here.
|
|
72
|
+
*
|
|
73
|
+
* @example 'my-sms-config-set'
|
|
74
|
+
*/
|
|
6
75
|
configurationSetName?: string;
|
|
7
76
|
}
|
|
8
77
|
//# sourceMappingURL=aws-sms-config.interface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws-sms-config.interface.d.ts","sourceRoot":"","sources":["../src/aws-sms-config.interface.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aws-sms-config.interface.d.ts","sourceRoot":"","sources":["../src/aws-sms-config.interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;;;;;OAQG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAE1B;;;;;;;;;;;;OAYG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B"}
|
|
@@ -1,18 +1,115 @@
|
|
|
1
1
|
import { SMSProvider, SMSTemplateEngine, SMSTemplateVariables } from '@nauth-toolkit/core';
|
|
2
2
|
import { AWSSMSConfig } from './aws-sms-config.interface';
|
|
3
|
+
/**
|
|
4
|
+
* AWS SNS SMS Provider (Platform-Agnostic)
|
|
5
|
+
*
|
|
6
|
+
* Sends authentication SMS via AWS Simple Notification Service.
|
|
7
|
+
* All messages sent as transactional (highest priority).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const provider = new AWSSMSProvider({
|
|
12
|
+
* region: 'us-east-1',
|
|
13
|
+
* accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
|
|
14
|
+
* secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
|
|
15
|
+
* originationNumber: '+12345678901',
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* await provider.sendOTP('+1234567890', '123456');
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
3
21
|
export declare class AWSSMSProvider implements SMSProvider {
|
|
4
22
|
private readonly logger;
|
|
5
23
|
private readonly snsClient;
|
|
6
24
|
private readonly config;
|
|
7
25
|
private SNSClientClass;
|
|
8
26
|
private PublishCommandClass;
|
|
27
|
+
/**
|
|
28
|
+
* Optional SMS template engine for customizing message content
|
|
29
|
+
*/
|
|
9
30
|
private templateEngine?;
|
|
31
|
+
/**
|
|
32
|
+
* Global variables available to all SMS templates
|
|
33
|
+
*/
|
|
10
34
|
private globalVariables;
|
|
11
35
|
constructor(config: AWSSMSConfig);
|
|
36
|
+
/**
|
|
37
|
+
* Set template engine for SMS message customization
|
|
38
|
+
*
|
|
39
|
+
* @param engine - SMS template engine instance
|
|
40
|
+
*/
|
|
12
41
|
setTemplateEngine(engine: SMSTemplateEngine): void;
|
|
42
|
+
/**
|
|
43
|
+
* Set global variables for SMS templates
|
|
44
|
+
*
|
|
45
|
+
* @param variables - Global template variables (appName, companyName, etc.)
|
|
46
|
+
*/
|
|
13
47
|
setGlobalVariables(variables: SMSTemplateVariables): void;
|
|
48
|
+
/**
|
|
49
|
+
* Send OTP code via AWS SNS
|
|
50
|
+
*
|
|
51
|
+
* Sends a transactional SMS message with the OTP code using AWS SNS.
|
|
52
|
+
* If template engine is configured, uses template to format message.
|
|
53
|
+
* Otherwise, falls back to hard-coded default message for backward compatibility.
|
|
54
|
+
*
|
|
55
|
+
* **Message Format (without templates):**
|
|
56
|
+
* ```
|
|
57
|
+
* Your verification code is: 123456
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* **Message Format (with templates):**
|
|
61
|
+
* Uses configured template with variables (code, expiryMinutes, appName, etc.)
|
|
62
|
+
*
|
|
63
|
+
* **Delivery Time:**
|
|
64
|
+
* - US: ~2-5 seconds
|
|
65
|
+
* - International: ~5-30 seconds
|
|
66
|
+
*
|
|
67
|
+
* @param phone - Recipient phone number in E.164 format (e.g., '+12345678901')
|
|
68
|
+
* @param code - OTP code to send (typically 6 digits)
|
|
69
|
+
* @param templateType - Optional template type (verification, mfa, passwordReset)
|
|
70
|
+
* @param variables - Optional template variables (expiryMinutes, appName, etc.)
|
|
71
|
+
*
|
|
72
|
+
* @throws {Error} If SMS delivery fails
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* // Without templates (backward compatible)
|
|
77
|
+
* await provider.sendOTP('+12345678901', '123456');
|
|
78
|
+
*
|
|
79
|
+
* // With templates
|
|
80
|
+
* await provider.sendOTP('+12345678901', '123456', 'verification', { expiryMinutes: 5 });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
14
83
|
sendOTP(phone: string, code: string, templateType?: string, variables?: Record<string, unknown>): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Send verification code via AWS SNS
|
|
86
|
+
*
|
|
87
|
+
* Alias for sendOTP(). Sends the same transactional SMS message.
|
|
88
|
+
*
|
|
89
|
+
* @param phone - Recipient phone number in E.164 format
|
|
90
|
+
* @param code - Verification code to send
|
|
91
|
+
*
|
|
92
|
+
* @throws {Error} If SMS delivery fails
|
|
93
|
+
*/
|
|
15
94
|
sendVerificationCode(phone: string, code: string): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Send SMS message via AWS SNS (Internal)
|
|
97
|
+
*
|
|
98
|
+
* Low-level method for sending SMS with full AWS SNS configuration.
|
|
99
|
+
*
|
|
100
|
+
* **AWS SNS Attributes:**
|
|
101
|
+
* - `AWS.SNS.SMS.SenderID`: Sender name or origination number
|
|
102
|
+
* - `AWS.SNS.SMS.SMSType`: Transactional or Promotional
|
|
103
|
+
* - `AWS.MM.SMS.OriginationNumber`: Phone number for US/Canada
|
|
104
|
+
* - `AWS.SNS.SMS.MaxPrice`: Maximum price per SMS
|
|
105
|
+
*
|
|
106
|
+
* @param phone - Recipient phone number in E.164 format
|
|
107
|
+
* @param message - SMS message content
|
|
108
|
+
*
|
|
109
|
+
* @throws {Error} If AWS SNS API call fails
|
|
110
|
+
*
|
|
111
|
+
* @private
|
|
112
|
+
*/
|
|
16
113
|
private sendSMS;
|
|
17
114
|
}
|
|
18
115
|
//# sourceMappingURL=aws-sms.provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws-sms.provider.d.ts","sourceRoot":"","sources":["../src/aws-sms.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAIX,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"aws-sms.provider.d.ts","sourceRoot":"","sources":["../src/aws-sms.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAIX,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAK1D;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,cAAe,YAAW,WAAW;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IAEtC,OAAO,CAAC,cAAc,CAAa;IAEnC,OAAO,CAAC,mBAAmB,CAAa;IAExC;;OAEG;IACH,OAAO,CAAC,cAAc,CAAC,CAAoB;IAE3C;;OAEG;IACH,OAAO,CAAC,eAAe,CAA4B;gBAEvC,MAAM,EAAE,YAAY;IA+ChC;;;;OAIG;IACH,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAIlD;;;;OAIG;IACH,kBAAkB,CAAC,SAAS,EAAE,oBAAoB,GAAG,IAAI;IAIzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACG,OAAO,CACX,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,MAAM,EACrB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,OAAO,CAAC,IAAI,CAAC;IAkChB;;;;;;;;;OASG;IACG,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItE;;;;;;;;;;;;;;;;;OAiBG;YACW,OAAO;CAiEtB"}
|
package/dist/aws-sms.provider.js
CHANGED
|
@@ -2,23 +2,52 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AWSSMSProvider = void 0;
|
|
4
4
|
const core_1 = require("@nauth-toolkit/core");
|
|
5
|
+
/**
|
|
6
|
+
* AWS SNS SMS Provider (Platform-Agnostic)
|
|
7
|
+
*
|
|
8
|
+
* Sends authentication SMS via AWS Simple Notification Service.
|
|
9
|
+
* All messages sent as transactional (highest priority).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const provider = new AWSSMSProvider({
|
|
14
|
+
* region: 'us-east-1',
|
|
15
|
+
* accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
|
|
16
|
+
* secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
|
|
17
|
+
* originationNumber: '+12345678901',
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* await provider.sendOTP('+1234567890', '123456');
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
5
23
|
class AWSSMSProvider {
|
|
6
24
|
logger;
|
|
7
25
|
snsClient;
|
|
8
26
|
config;
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
28
|
SNSClientClass = null;
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
30
|
PublishCommandClass = null;
|
|
31
|
+
/**
|
|
32
|
+
* Optional SMS template engine for customizing message content
|
|
33
|
+
*/
|
|
11
34
|
templateEngine;
|
|
35
|
+
/**
|
|
36
|
+
* Global variables available to all SMS templates
|
|
37
|
+
*/
|
|
12
38
|
globalVariables = {};
|
|
13
39
|
constructor(config) {
|
|
14
40
|
this.logger = new core_1.NAuthLogger();
|
|
15
41
|
this.config = config;
|
|
42
|
+
// Validate required configuration
|
|
16
43
|
if (!config.region || !config.originationNumber) {
|
|
17
44
|
throw new core_1.NAuthException(core_1.AuthErrorCode.VALIDATION_FAILED, 'AWS SMS Provider: region and originationNumber are required');
|
|
18
45
|
}
|
|
46
|
+
// If accessKeyId provided, secretAccessKey must also be provided
|
|
19
47
|
if (config.accessKeyId && !config.secretAccessKey) {
|
|
20
48
|
throw new core_1.NAuthException(core_1.AuthErrorCode.VALIDATION_FAILED, 'AWS SMS Provider: secretAccessKey is required when accessKeyId is provided');
|
|
21
49
|
}
|
|
50
|
+
// Lazy-load AWS SDK (optional dependency)
|
|
22
51
|
try {
|
|
23
52
|
const awsSdk = require('@aws-sdk/client-sns');
|
|
24
53
|
this.SNSClientClass = awsSdk.SNSClient;
|
|
@@ -27,7 +56,9 @@ class AWSSMSProvider {
|
|
|
27
56
|
catch (error) {
|
|
28
57
|
throw new core_1.NAuthException(core_1.AuthErrorCode.INTERNAL_ERROR, 'AWS SMS Provider: Failed to load @aws-sdk/client-sns. Ensure @nauth-toolkit/sms-aws-sns is properly installed.');
|
|
29
58
|
}
|
|
59
|
+
// Initialize SNS client - credentials are optional (SDK auto-discovers)
|
|
30
60
|
const clientConfig = { region: config.region };
|
|
61
|
+
// Only add credentials if explicitly provided
|
|
31
62
|
if (config.accessKeyId && config.secretAccessKey) {
|
|
32
63
|
clientConfig.credentials = {
|
|
33
64
|
accessKeyId: config.accessKeyId,
|
|
@@ -37,38 +68,120 @@ class AWSSMSProvider {
|
|
|
37
68
|
this.snsClient = new this.SNSClientClass(clientConfig);
|
|
38
69
|
this.logger.log(`AWS SMS Provider initialized (region: ${config.region})`);
|
|
39
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Set template engine for SMS message customization
|
|
73
|
+
*
|
|
74
|
+
* @param engine - SMS template engine instance
|
|
75
|
+
*/
|
|
40
76
|
setTemplateEngine(engine) {
|
|
41
77
|
this.templateEngine = engine;
|
|
42
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Set global variables for SMS templates
|
|
81
|
+
*
|
|
82
|
+
* @param variables - Global template variables (appName, companyName, etc.)
|
|
83
|
+
*/
|
|
43
84
|
setGlobalVariables(variables) {
|
|
44
85
|
this.globalVariables = variables || {};
|
|
45
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Send OTP code via AWS SNS
|
|
89
|
+
*
|
|
90
|
+
* Sends a transactional SMS message with the OTP code using AWS SNS.
|
|
91
|
+
* If template engine is configured, uses template to format message.
|
|
92
|
+
* Otherwise, falls back to hard-coded default message for backward compatibility.
|
|
93
|
+
*
|
|
94
|
+
* **Message Format (without templates):**
|
|
95
|
+
* ```
|
|
96
|
+
* Your verification code is: 123456
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* **Message Format (with templates):**
|
|
100
|
+
* Uses configured template with variables (code, expiryMinutes, appName, etc.)
|
|
101
|
+
*
|
|
102
|
+
* **Delivery Time:**
|
|
103
|
+
* - US: ~2-5 seconds
|
|
104
|
+
* - International: ~5-30 seconds
|
|
105
|
+
*
|
|
106
|
+
* @param phone - Recipient phone number in E.164 format (e.g., '+12345678901')
|
|
107
|
+
* @param code - OTP code to send (typically 6 digits)
|
|
108
|
+
* @param templateType - Optional template type (verification, mfa, passwordReset)
|
|
109
|
+
* @param variables - Optional template variables (expiryMinutes, appName, etc.)
|
|
110
|
+
*
|
|
111
|
+
* @throws {Error} If SMS delivery fails
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* // Without templates (backward compatible)
|
|
116
|
+
* await provider.sendOTP('+12345678901', '123456');
|
|
117
|
+
*
|
|
118
|
+
* // With templates
|
|
119
|
+
* await provider.sendOTP('+12345678901', '123456', 'verification', { expiryMinutes: 5 });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
46
122
|
async sendOTP(phone, code, templateType, variables) {
|
|
47
123
|
let message;
|
|
124
|
+
// ============================================================================
|
|
125
|
+
// Template-based message rendering
|
|
126
|
+
// ============================================================================
|
|
48
127
|
if (this.templateEngine && templateType) {
|
|
49
128
|
try {
|
|
129
|
+
// Merge global variables with template-specific variables
|
|
50
130
|
const allVariables = {
|
|
51
131
|
...this.globalVariables,
|
|
52
132
|
code,
|
|
53
133
|
...variables,
|
|
54
134
|
};
|
|
135
|
+
// Render template
|
|
55
136
|
const template = await this.templateEngine.render(templateType, allVariables);
|
|
56
137
|
message = template.content;
|
|
57
138
|
}
|
|
58
139
|
catch (error) {
|
|
59
140
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
60
141
|
this.logger.error(`Failed to render SMS template: ${errorMessage}`);
|
|
142
|
+
// Fall back to hard-coded message on template rendering error
|
|
61
143
|
message = `Your verification code is: ${code}`;
|
|
62
144
|
}
|
|
63
145
|
}
|
|
64
146
|
else {
|
|
147
|
+
// ============================================================================
|
|
148
|
+
// Backward compatibility: hard-coded default message
|
|
149
|
+
// ============================================================================
|
|
65
150
|
message = `Your verification code is: ${code}`;
|
|
66
151
|
}
|
|
67
152
|
await this.sendSMS(phone, message);
|
|
68
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Send verification code via AWS SNS
|
|
156
|
+
*
|
|
157
|
+
* Alias for sendOTP(). Sends the same transactional SMS message.
|
|
158
|
+
*
|
|
159
|
+
* @param phone - Recipient phone number in E.164 format
|
|
160
|
+
* @param code - Verification code to send
|
|
161
|
+
*
|
|
162
|
+
* @throws {Error} If SMS delivery fails
|
|
163
|
+
*/
|
|
69
164
|
async sendVerificationCode(phone, code) {
|
|
70
165
|
await this.sendOTP(phone, code);
|
|
71
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Send SMS message via AWS SNS (Internal)
|
|
169
|
+
*
|
|
170
|
+
* Low-level method for sending SMS with full AWS SNS configuration.
|
|
171
|
+
*
|
|
172
|
+
* **AWS SNS Attributes:**
|
|
173
|
+
* - `AWS.SNS.SMS.SenderID`: Sender name or origination number
|
|
174
|
+
* - `AWS.SNS.SMS.SMSType`: Transactional or Promotional
|
|
175
|
+
* - `AWS.MM.SMS.OriginationNumber`: Phone number for US/Canada
|
|
176
|
+
* - `AWS.SNS.SMS.MaxPrice`: Maximum price per SMS
|
|
177
|
+
*
|
|
178
|
+
* @param phone - Recipient phone number in E.164 format
|
|
179
|
+
* @param message - SMS message content
|
|
180
|
+
*
|
|
181
|
+
* @throws {Error} If AWS SNS API call fails
|
|
182
|
+
*
|
|
183
|
+
* @private
|
|
184
|
+
*/
|
|
72
185
|
async sendSMS(phone, message) {
|
|
73
186
|
try {
|
|
74
187
|
const messageAttributes = {
|
|
@@ -77,6 +190,7 @@ class AWSSMSProvider {
|
|
|
77
190
|
StringValue: 'Transactional',
|
|
78
191
|
},
|
|
79
192
|
};
|
|
193
|
+
// Determine if using phone number or sender ID
|
|
80
194
|
const isPhoneNumber = this.config.originationNumber.startsWith('+');
|
|
81
195
|
if (isPhoneNumber) {
|
|
82
196
|
messageAttributes['AWS.MM.SMS.OriginationNumber'] = {
|
|
@@ -90,12 +204,16 @@ class AWSSMSProvider {
|
|
|
90
204
|
StringValue: this.config.originationNumber,
|
|
91
205
|
};
|
|
92
206
|
}
|
|
207
|
+
// Build publish command
|
|
93
208
|
const input = {
|
|
94
209
|
PhoneNumber: phone,
|
|
95
210
|
Message: message,
|
|
96
211
|
MessageAttributes: messageAttributes,
|
|
97
212
|
};
|
|
213
|
+
// Add configuration set if provided
|
|
98
214
|
if (this.config.configurationSetName) {
|
|
215
|
+
// Note: Configuration sets control delivery tracking, logging, etc.
|
|
216
|
+
// Configure these in AWS Console, not here
|
|
99
217
|
input.MessageAttributes['AWS.SNS.SMS.ConfigurationSetName'] = {
|
|
100
218
|
DataType: 'String',
|
|
101
219
|
StringValue: this.config.configurationSetName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws-sms.provider.js","sourceRoot":"","sources":["../src/aws-sms.provider.ts"],"names":[],"mappings":";;;AAAA,8CAO6B;
|
|
1
|
+
{"version":3,"file":"aws-sms.provider.js","sourceRoot":"","sources":["../src/aws-sms.provider.ts"],"names":[],"mappings":";;;AAAA,8CAO6B;AAM7B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,cAAc;IACR,MAAM,CAAc;IACpB,SAAS,CAAY;IACrB,MAAM,CAAe;IACtC,8DAA8D;IACtD,cAAc,GAAQ,IAAI,CAAC;IACnC,8DAA8D;IACtD,mBAAmB,GAAQ,IAAI,CAAC;IAExC;;OAEG;IACK,cAAc,CAAqB;IAE3C;;OAEG;IACK,eAAe,GAAyB,EAAE,CAAC;IAEnD,YAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAW,EAAE,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,kCAAkC;QAClC,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;YAChD,MAAM,IAAI,qBAAc,CACtB,oBAAa,CAAC,iBAAiB,EAC/B,6DAA6D,CAC9D,CAAC;QACJ,CAAC;QAED,iEAAiE;QACjE,IAAI,MAAM,CAAC,WAAW,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;YAClD,MAAM,IAAI,qBAAc,CACtB,oBAAa,CAAC,iBAAiB,EAC/B,4EAA4E,CAC7E,CAAC;QACJ,CAAC;QAED,0CAA0C;QAC1C,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;YAC9C,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC;YACvC,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC,cAAc,CAAC;QACnD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,qBAAc,CACtB,oBAAa,CAAC,cAAc,EAC5B,gHAAgH,CACjH,CAAC;Q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PD,wCA+PC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,uDAAoD;AAA3C,kHAAA,cAAc,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nauth-toolkit/sms-aws-sns",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "AWS SNS SMS provider for nauth-toolkit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@aws-sdk/client-sns": "^3.0.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@nauth-toolkit/core": "^0.1.
|
|
20
|
+
"@nauth-toolkit/core": "^0.1.17"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/jest": "^29.5.0",
|