@nauth-toolkit/sms-aws-sns 0.1.28 → 0.1.29
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.
|
@@ -20,10 +20,10 @@ import { AWSSMSConfig } from './aws-sms-config.interface';
|
|
|
20
20
|
*/
|
|
21
21
|
export declare class AWSSMSProvider implements SMSProvider {
|
|
22
22
|
private readonly logger;
|
|
23
|
-
private
|
|
23
|
+
private snsClient;
|
|
24
24
|
private readonly config;
|
|
25
|
-
private
|
|
26
|
-
private
|
|
25
|
+
private snsClientClass;
|
|
26
|
+
private publishCommandClass;
|
|
27
27
|
/**
|
|
28
28
|
* Optional SMS template engine for customizing message content
|
|
29
29
|
*/
|
|
@@ -33,6 +33,12 @@ export declare class AWSSMSProvider implements SMSProvider {
|
|
|
33
33
|
*/
|
|
34
34
|
private globalVariables;
|
|
35
35
|
constructor(config: AWSSMSConfig);
|
|
36
|
+
/**
|
|
37
|
+
* Lazy-initialize AWS SNS SDK and client.
|
|
38
|
+
*
|
|
39
|
+
* @throws {NAuthException} When AWS SDK cannot be loaded
|
|
40
|
+
*/
|
|
41
|
+
private ensureAwsInitialized;
|
|
36
42
|
/**
|
|
37
43
|
* Set template engine for SMS message customization
|
|
38
44
|
*
|
|
@@ -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;AAW1D;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,cAAe,YAAW,WAAW;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IACrC,OAAO,CAAC,SAAS,CAA8B;IAC/C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,cAAc,CAA8B;IACpD,OAAO,CAAC,mBAAmB,CAAmC;IAE9D;;OAEG;IACH,OAAO,CAAC,cAAc,CAAC,CAAoB;IAE3C;;OAEG;IACH,OAAO,CAAC,eAAe,CAA4B;gBAEvC,MAAM,EAAE,YAAY;IAwBhC;;;;OAIG;YACW,oBAAoB;IAgClC;;;;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;CA6DtB"}
|
package/dist/aws-sms.provider.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.AWSSMSProvider = void 0;
|
|
4
37
|
const core_1 = require("@nauth-toolkit/core");
|
|
@@ -22,12 +55,10 @@ const core_1 = require("@nauth-toolkit/core");
|
|
|
22
55
|
*/
|
|
23
56
|
class AWSSMSProvider {
|
|
24
57
|
logger;
|
|
25
|
-
snsClient;
|
|
58
|
+
snsClient = null;
|
|
26
59
|
config;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
-
PublishCommandClass = null;
|
|
60
|
+
snsClientClass = null;
|
|
61
|
+
publishCommandClass = null;
|
|
31
62
|
/**
|
|
32
63
|
* Optional SMS template engine for customizing message content
|
|
33
64
|
*/
|
|
@@ -47,26 +78,38 @@ class AWSSMSProvider {
|
|
|
47
78
|
if (config.accessKeyId && !config.secretAccessKey) {
|
|
48
79
|
throw new core_1.NAuthException(core_1.AuthErrorCode.VALIDATION_FAILED, 'AWS SMS Provider: secretAccessKey is required when accessKeyId is provided');
|
|
49
80
|
}
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
81
|
+
// AWS SDK + client are initialized lazily in sendSMS() (async) to avoid require().
|
|
82
|
+
this.logger.log(`AWS SMS Provider initialized (region: ${config.region})`);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Lazy-initialize AWS SNS SDK and client.
|
|
86
|
+
*
|
|
87
|
+
* @throws {NAuthException} When AWS SDK cannot be loaded
|
|
88
|
+
*/
|
|
89
|
+
async ensureAwsInitialized() {
|
|
90
|
+
if (this.snsClient) {
|
|
91
|
+
return;
|
|
55
92
|
}
|
|
56
|
-
|
|
57
|
-
|
|
93
|
+
if (!this.snsClientClass || !this.publishCommandClass) {
|
|
94
|
+
try {
|
|
95
|
+
const awsSdk = await Promise.resolve().then(() => __importStar(require('@aws-sdk/client-sns')));
|
|
96
|
+
this.snsClientClass = awsSdk.SNSClient;
|
|
97
|
+
this.publishCommandClass = awsSdk.PublishCommand;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
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.');
|
|
101
|
+
}
|
|
58
102
|
}
|
|
59
103
|
// Initialize SNS client - credentials are optional (SDK auto-discovers)
|
|
60
|
-
const clientConfig = { region: config.region };
|
|
104
|
+
const clientConfig = { region: this.config.region };
|
|
61
105
|
// Only add credentials if explicitly provided
|
|
62
|
-
if (config.accessKeyId && config.secretAccessKey) {
|
|
106
|
+
if (this.config.accessKeyId && this.config.secretAccessKey) {
|
|
63
107
|
clientConfig.credentials = {
|
|
64
|
-
accessKeyId: config.accessKeyId,
|
|
65
|
-
secretAccessKey: config.secretAccessKey,
|
|
108
|
+
accessKeyId: this.config.accessKeyId,
|
|
109
|
+
secretAccessKey: this.config.secretAccessKey,
|
|
66
110
|
};
|
|
67
111
|
}
|
|
68
|
-
this.snsClient = new this.
|
|
69
|
-
this.logger.log(`AWS SMS Provider initialized (region: ${config.region})`);
|
|
112
|
+
this.snsClient = new this.snsClientClass(clientConfig);
|
|
70
113
|
}
|
|
71
114
|
/**
|
|
72
115
|
* Set template engine for SMS message customization
|
|
@@ -184,6 +227,7 @@ class AWSSMSProvider {
|
|
|
184
227
|
*/
|
|
185
228
|
async sendSMS(phone, message) {
|
|
186
229
|
try {
|
|
230
|
+
await this.ensureAwsInitialized();
|
|
187
231
|
const messageAttributes = {
|
|
188
232
|
'AWS.SNS.SMS.SMSType': {
|
|
189
233
|
DataType: 'String',
|
|
@@ -219,10 +263,7 @@ class AWSSMSProvider {
|
|
|
219
263
|
StringValue: this.config.configurationSetName,
|
|
220
264
|
};
|
|
221
265
|
}
|
|
222
|
-
|
|
223
|
-
throw new core_1.NAuthException(core_1.AuthErrorCode.INTERNAL_ERROR, 'AWS SDK not initialized');
|
|
224
|
-
}
|
|
225
|
-
const command = new this.PublishCommandClass(input);
|
|
266
|
+
const command = new this.publishCommandClass(input);
|
|
226
267
|
const response = await this.snsClient.send(command);
|
|
227
268
|
this.logger.log(`SMS sent to ${phone} (MessageId: ${response.MessageId})`);
|
|
228
269
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws-sms.provider.js","sourceRoot":"","sources":["../src/aws-sms.provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aws-sms.provider.js","sourceRoot":"","sources":["../src/aws-sms.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AC,cAAc,EAAE,4BAA4B,YAAY,EAAE,CAAC,CAAC;QACrG,CAAC;IACH,CAAC;CACF;AAvQD,wCAuQC"}
|
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.29",
|
|
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.29"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/jest": "^29.5.0",
|