Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(eslint): update dependencies w/ fixes #3

Merged
merged 1 commit into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
www/push.js
16 changes: 0 additions & 16 deletions .eslintrc

This file was deleted.

17 changes: 17 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root: true
extends: '@cordova/eslint-config/browser'
parser: '@babel/eslint-parser'
globals:
cordova: true
rules:
indent: ["error", 2]

overrides:
- files: [spec/**/*.js, example/server/**/*.js]
extends: '@cordova/eslint-config/node-tests'
rules:
indent: ["error", 2]

- files: [src/windows/**/*.js]
globals:
Windows: true
201 changes: 89 additions & 112 deletions example/server/pushADM.js
Original file line number Diff line number Diff line change
@@ -1,158 +1,135 @@



// Client ID and Client Secret received from ADM
// For more info, see: https://developer.amazon.com/public/apis/engage/device-messaging/tech-docs/02-obtaining-adm-credentials
var CLIENT_ID = "amzn1.application-oa2-client.8e838f6629554e26ae3f43a6c663cd60";
var CLIENT_SECRET = "0af96083320f5d70dc4f358cc783ac65a22e78b297ba257df34d5f723f24543f";
var CLIENT_ID = 'amzn1.application-oa2-client.8e838f6629554e26ae3f43a6c663cd60';
var CLIENT_SECRET = '0af96083320f5d70dc4f358cc783ac65a22e78b297ba257df34d5f723f24543f';

// Registration ID, received on device after it registers with ADM server
var REGISTRATION_IDS = ["amzn1.adm-registration.v2.Y29tLmFtYXpvbi5EZXZpY2VNZXNzYWdpbmcuUmVnaXN0cmF0aW9uSWRFbmNyeXB0aW9uS2V5ITEhOE9rZ2h5TXlhVEFFczg2ejNWL3JMcmhTa255Uk5BclhBbE1XMFZzcnU1aFF6cTlvdU5FbVEwclZmdk5oTFBVRXVDN1luQlRSNnRVRUViREdQSlBvSzRNaXVRRUlyUy9NYWZCYS9VWTJUaGZwb3ZVTHhlRTM0MGhvampBK01hVktsMEhxakdmQStOSXRjUXBTQUhNU1NlVVVUVkFreVRhRTBCYktaQ2ZkUFdqSmIwcHgzRDhMQnllVXdxQ2EwdHNXRmFVNklYL0U4UXovcHg0K3Jjb25VbVFLRUVVOFVabnh4RDhjYmtIcHd1ZThiekorbGtzR2taMG95cC92Y3NtZytrcTRPNjhXUUpiZEk3QzFvQThBRTFWWXM2NHkyMjdYVGV5RlhhMWNHS0k9IW5GNEJMSXNleC9xbWpHSU52NnczY0E9PQ"];
var REGISTRATION_IDS = ['amzn1.adm-registration.v2.Y29tLmFtYXpvbi5EZXZpY2VNZXNzYWdpbmcuUmVnaXN0cmF0aW9uSWRFbmNyeXB0aW9uS2V5ITEhOE9rZ2h5TXlhVEFFczg2ejNWL3JMcmhTa255Uk5BclhBbE1XMFZzcnU1aFF6cTlvdU5FbVEwclZmdk5oTFBVRXVDN1luQlRSNnRVRUViREdQSlBvSzRNaXVRRUlyUy9NYWZCYS9VWTJUaGZwb3ZVTHhlRTM0MGhvampBK01hVktsMEhxakdmQStOSXRjUXBTQUhNU1NlVVVUVkFreVRhRTBCYktaQ2ZkUFdqSmIwcHgzRDhMQnllVXdxQ2EwdHNXRmFVNklYL0U4UXovcHg0K3Jjb25VbVFLRUVVOFVabnh4RDhjYmtIcHd1ZThiekorbGtzR2taMG95cC92Y3NtZytrcTRPNjhXUUpiZEk3QzFvQThBRTFWWXM2NHkyMjdYVGV5RlhhMWNHS0k9IW5GNEJMSXNleC9xbWpHSU52NnczY0E9PQ'];

// Message payload to be sent to client
var payload = {
data: {
message: "PushPlugin works!!",
sound: "beep.wav",
url: "http://www.amazon.com",
timeStamp: new Date().toISOString(),
foo: "baz"
},
consolidationKey: "my app",
expiresAfter: 3600
data: {
message: 'PushPlugin works!!',
sound: 'beep.wav',
url: 'http://www.amazon.com',
timeStamp: new Date().toISOString(),
foo: 'baz'
},
consolidationKey: 'my app',
expiresAfter: 3600
};

//* ********************************

//*********************************


var https = require("https");
var querystring = require("querystring");
var https = require('https');
var querystring = require('querystring');


if(CLIENT_ID == "" || CLIENT_SECRET == "" || REGISTRATION_IDS.length == 0){
console.log("******************\nSetup Error: \nYou need to edit the pushADM.js file and enter your ADM credentials and device registration ID(s).\n******************");
process.exit(1);
if (CLIENT_ID === '' || CLIENT_SECRET === '' || REGISTRATION_IDS.length === 0) {
console.log('******************\nSetup Error: \nYou need to edit the pushADM.js file and enter your ADM credentials and device registration ID(s).\n******************');
process.exit(1);
}


// Get access token from server, and use it to post message to device
getAccessToken(function(accessToken){

for(var i = 0; i < REGISTRATION_IDS.length; i++){

var registrationID = REGISTRATION_IDS[i];

postMessage(accessToken, registrationID, payload);
}
getAccessToken(function (accessToken) {
for (var i = 0; i < REGISTRATION_IDS.length; i++) {
var registrationID = REGISTRATION_IDS[i];

postMessage(accessToken, registrationID, payload);
}
});




// Query OAuth server for access token
// For more info, see: https://developer.amazon.com/public/apis/engage/device-messaging/tech-docs/05-requesting-an-access-token

function getAccessToken(callback){

console.log("Requesting access token from server...");

var credentials = {
scope: "messaging:push",
grant_type: "client_credentials",
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET
function getAccessToken (callback) {
console.log('Requesting access token from server...');

var credentials = {
scope: 'messaging:push',
grant_type: 'client_credentials',
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET
};

var post_data = querystring.stringify(credentials);

var post_options = {
host: 'api.amazon.com',
port: '443',
path: '/auth/O2/token',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
}
};

var post_data = querystring.stringify(credentials);

var post_options = {
host: "api.amazon.com",
port: "443",
path: "/auth/O2/token",
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
}
};

var req = https.request(post_options, function(res) {

var data = "";

res.on("data", function (chunk) {
data += chunk;
});

res.on("end", function() {
console.log("\nAccess token response:", data);
var accessToken = JSON.parse(data).access_token;
callback(accessToken);
});
var req = https.request(post_options, function (res) {
var data = '';

res.on('data', function (chunk) {
data += chunk;
});

req.on("error", function(e) {
console.log("\nProblem with access token request: ", e.message);
res.on('end', function () {
console.log('\nAccess token response:', data);
var accessToken = JSON.parse(data).access_token;
callback(accessToken);
});
});

req.write(post_data);
req.end();
req.on('error', function (e) {
console.log('\nProblem with access token request: ', e.message);
});

req.write(post_data);
req.end();
}


// Post message payload to ADM server
// For more info, see: https://developer.amazon.com/public/apis/engage/device-messaging/tech-docs/06-sending-a-message

function postMessage(accessToken, registrationID, payload){

if(accessToken == undefined || registrationID == undefined || payload == undefined){
return;
}

console.log("\nSending message...");

var post_data = JSON.stringify(payload);

var api_path = "/messaging/registrations/" + registrationID + "/messages";
function postMessage (accessToken, registrationID, payload) {
if (accessToken === undefined || registrationID === undefined || payload === undefined) {
return;
}

var post_options = {
host: "api.amazon.com",
port: "443",
path: api_path,
method: "POST",
headers: {
"Authorization": "Bearer " + accessToken,
"X-Amzn-Type-Version": "[email protected]",
"X-Amzn-Accept-Type" : "[email protected]",
"Content-Type": "application/json",
"Accept": "application/json",
}
};
console.log('\nSending message...');

var req = https.request(post_options, function(res) {
var post_data = JSON.stringify(payload);

var data = "";
var api_path = '/messaging/registrations/' + registrationID + '/messages';

res.on("data", function (chunk) {
data += chunk;
});
var post_options = {
host: 'api.amazon.com',
port: '443',
path: api_path,
method: 'POST',
headers: {
Authorization: 'Bearer ' + accessToken,
'X-Amzn-Type-Version': '[email protected]',
'X-Amzn-Accept-Type': '[email protected]',
'Content-Type': 'application/json',
Accept: 'application/json'
}
};

res.on("end", function() {
console.log("\nSend message response: ", data);
});
var req = https.request(post_options, function (res) {
var data = '';

res.on('data', function (chunk) {
data += chunk;
});

req.on("error", function(e) {
console.log("\nProblem with send message request: ", e.message);
res.on('end', function () {
console.log('\nSend message response: ', data);
});
});

req.write(post_data);
req.end();
req.on('error', function (e) {
console.log('\nProblem with send message request: ', e.message);
});

req.write(post_data);
req.end();
}


58 changes: 28 additions & 30 deletions example/server/pushAzure.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,44 @@
** TodoItem product
** https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-cordova-get-started/
*/
var azureMobileApps = require('azure-mobile-apps'),
promises = require('azure-mobile-apps/src/utilities/promises'),
logger = require('azure-mobile-apps/src/logger');
var azureMobileApps = require('azure-mobile-apps');
var logger = require('azure-mobile-apps/src/logger');

// Create a new table definition
var table = azureMobileApps.table();

// In the TodoItem product, sends a push notification
// when a new item inserted into the table.
table.insert(function (context) {
// For more information about the Notification Hubs JavaScript SDK,
// see http://aka.ms/nodejshubs
logger.info('Running TodoItem.insert');
// For more information about the Notification Hubs JavaScript SDK,
// see http://aka.ms/nodejshubs
logger.info('Running TodoItem.insert');

// Define the push notification template payload.
// Requires template specified in the client app. See
// https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-cordova-get-started-push/
var payload = '{"message": "' + context.item.text + '" }';
// Define the push notification template payload.
// Requires template specified in the client app. See
// https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-cordova-get-started-push/
var payload = '{"message": "' + context.item.text + '" }';

// Execute the insert. The insert returns the results as a Promise,
// Do the push as a post-execute action within the promise flow.
return context.execute()
.then(function (results) {
// Only do the push if configured
if (context.push) {

context.push.send(null, payload, function (error) {
if (error) {
logger.error('Error while sending push notification: ', error);
} else {
logger.info('Push notification sent successfully!');
}
});
}
// Don't forget to return the results from the context.execute()
return results;
})
.catch(function (error) {
logger.error('Error while running context.execute: ', error);
// Execute the insert. The insert returns the results as a Promise,
// Do the push as a post-execute action within the promise flow.
return context.execute()
.then(function (results) {
// Only do the push if configured
if (context.push) {
context.push.send(null, payload, function (error) {
if (error) {
logger.error('Error while sending push notification: ', error);
} else {
logger.info('Push notification sent successfully!');
}
});
}
// Don't forget to return the results from the context.execute()
return results;
})
.catch(function (error) {
logger.error('Error while running context.execute: ', error);
});
});

module.exports = table;
10 changes: 5 additions & 5 deletions hooks/browser/updateManifest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function(context) {
module.exports = function (context) {
console.log('Updating manifest.json with push properties…');
var path = require('path');
var fs = require('fs');
Expand All @@ -18,7 +18,7 @@ module.exports = function(context) {
return;
}

fs.readFile(platformManifestJson, 'utf8', function(err, platformJson) {
fs.readFile(platformManifestJson, 'utf8', function (err, platformJson) {
if (err) throw err; // we'll not consider error handling for now
var platformManifest = JSON.parse(platformJson);

Expand All @@ -27,16 +27,16 @@ module.exports = function(context) {
'plugins/phonegap-plugin-push/src/browser/manifest.json'
);

fs.readFile(pluginManifestPath, 'utf8', function(err, pluginJson) {
fs.readFile(pluginManifestPath, 'utf8', function (err, pluginJson) {
if (err) throw err; // we'll not consider error handling for now
var pluginManifest = JSON.parse(pluginJson);

platformManifest['gcm_sender_id'] = pluginManifest['gcm_sender_id'];
platformManifest.gcm_sender_id = pluginManifest.gcm_sender_id;

fs.writeFile(
platformManifestJson,
JSON.stringify(platformManifest),
function(err) {
function (err) {
if (err) {
return console.log(err);
}
Expand Down
Loading