idea-toolbox
Advanced tools
Comparing version 0.9.0 to 0.9.1
32
index.js
@@ -36,3 +36,3 @@ 'use strict'; | ||
// SNS | ||
createSNSPushPlatormEndpoint, | ||
createSNSPushPlatormEndpoint, publishSNSPush, | ||
// OTHER | ||
@@ -398,3 +398,3 @@ ISODateToItalianFormat, cleanStr, joinArraysOnKeys | ||
case 'FCM': platformARN = SNS_PUSH_PLATFORM_ARN_ANDROID; break; | ||
default: return done(new Error(`E.USERS.FAILED_CREATING_ENDPOINT`)); | ||
default: return done(new Error()); | ||
} | ||
@@ -405,3 +405,3 @@ // create a new endpoint in the platform | ||
console.log('Creating SNS platform endpoint', platformARN, err, data); | ||
if(err || !data.EndpointArn) return done(new Error(`E.USERS.FAILED_CREATING_ENDPOINT`)); | ||
if(err || !data.EndpointArn) done(err || new Error()); | ||
else done(null, data.EndpointArn); | ||
@@ -411,2 +411,28 @@ }); | ||
/** | ||
* Send a push notification through a SNS endpoint. | ||
* @param {string} message the message to send | ||
* @param {string} platform enum: APNS, FCM | ||
* @param {string} endpoint endpoint to a specific device | ||
* @param {*} done cb(err, data) => {} | ||
*/ | ||
function publishSNSPush(message, platform, endpoint, done) { | ||
let structuredMessage; | ||
switch(platform) { | ||
case 'APNS': | ||
structuredMessage = { APNS: JSON.stringify({ aps: { alert: message } }) }; | ||
break; | ||
case 'FCM': | ||
structuredMessage = { GCM: JSON.stringify({ data: { message: message } }) }; | ||
break; | ||
default: return done(new Error()); | ||
} | ||
SNS.publish({ | ||
MessageStructure: 'json', Message: JSON.stringify(structuredMessage), TargetArn: endpoint | ||
}, (err, data) => { | ||
console.log('Sending push notification', endpoint, err, data); | ||
done(err, data); | ||
}); | ||
} | ||
/// | ||
@@ -413,0 +439,0 @@ /// OTHER |
{ | ||
"name": "idea-toolbox", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"description": "IDEA's utility functions", | ||
@@ -5,0 +5,0 @@ "engines": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22699
483