airbits-notif-utils
Advanced tools
Comparing version 1.0.5 to 1.0.6
82
index.js
var MongoRepository = require("airbits-data").MongoRepository; | ||
const http = require('http'); | ||
var rp = require('request-promise'); | ||
exports.NotificationManager = function(restheartUser, restheartPass, restheartUrl, dbName, fsmkey, fsmApiUrl){ | ||
exports.NotificationManager = function (restheartUser, restheartPass, restheartUrl, dbName, fsmkey, fsmApiUrl) { | ||
var userRepo = new MongoRepository(restheartUser, restheartPass, restheartUrl, dbName, "users"); | ||
@@ -10,13 +10,24 @@ const firebaseKey = fsmkey; | ||
this.registerUserNotificationId = (userId, subscriptionId) =>{ | ||
return new Promise((resolve, reject)=>{ | ||
this.registerUserNotificationId = (userId, subscriptionId) => { | ||
return new Promise((resolve, reject) => { | ||
console.log("registrando notif Id: " + subscriptionId); | ||
const subId = {"subscriptionId": subscriptionId}; | ||
userRepo.update(userId,subId) | ||
.then((result)=>{ | ||
sendNotification(subscriptionId); | ||
resolve({"message": "subscription registered"}); | ||
const subId = { | ||
"subscriptionId": subscriptionId | ||
}; | ||
userRepo.update(userId, subId) | ||
.then((result) => { | ||
console.log("todo tranka la actualizacion de la db. ahora sending notif"); | ||
sendNotification(subscriptionId) | ||
.then((notifRes) => { | ||
console.log("listo la notif!") | ||
resolve({ | ||
"message": "subscription registered" | ||
}); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}) | ||
.catch((err)=>{ | ||
.catch((err) => { | ||
reject(err); | ||
@@ -27,23 +38,36 @@ }); | ||
function sendNotification(subscriptionId){ | ||
const postOptions = { | ||
host: 'https://fcm.googleapis.com', | ||
port: '80', | ||
path: '/fcm/send', | ||
method: 'POST', | ||
headers: { | ||
'Authorization': "key=" + firebaseKey | ||
} | ||
}; | ||
let request = https.request(https_options, (response) =>{ | ||
console.log("respondio fsm:"+ JSON.stringify(response)); | ||
function sendNotification(subscriptionId) { | ||
console.log("dentro de sendNotif. sale promise"); | ||
return new Promise((resolve, reject) => { | ||
const body = { | ||
"to": subscriptionId, | ||
"title": "notif from lambda", | ||
"body": "nada" | ||
}; | ||
var options = { | ||
method: 'POST', | ||
uri: 'https://fcm.googleapis.com/fcm/send', | ||
headers: { | ||
'Authorization': "key=" + firebaseKey | ||
}, | ||
body: body, | ||
json: true // Automatically stringifies the body to JSON | ||
}; | ||
rp(options) | ||
.then(function (parsedBody) { | ||
resolve(parsedBody); | ||
}) | ||
.catch(function (err) { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
} |
{ | ||
"name": "airbits-notif-utils", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "notification utilities for xens app", | ||
@@ -9,4 +9,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"airbits-data": "^1.0.4" | ||
"airbits-data": "^1.0.4", | ||
"request": "^2.83.0", | ||
"request-promise": "^4.2.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
15586
57
0
3
+ Addedrequest@^2.83.0
+ Addedrequest-promise@^4.2.2
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbluebird@3.7.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedrequest-promise@4.2.6(transitive)
+ Addedrequest-promise-core@1.1.4(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstealthy-require@1.1.1(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)