From 710638d58cac1a95def7c0096f80f9787ecab9f8 Mon Sep 17 00:00:00 2001 From: sruthakeerthikotla Date: Mon, 8 Jun 2020 20:58:42 +0530 Subject: [PATCH 1/2] Create app.js --- odo/app.js | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 odo/app.js diff --git a/odo/app.js b/odo/app.js new file mode 100644 index 0000000..e56bf5a --- /dev/null +++ b/odo/app.js @@ -0,0 +1,116 @@ +module.exports = (options) => { + const app = require('express')() + const mf = options.mf; + /******************************************************************************** + Below is a sample. + + sendNotification : Sends a notification to all devices that have registered for push service. + Consumes a single string as a mandatory paramter that contains the message of the push notification. + + + setProperty : Sets a live update property on the MF server's live update settings + Consumes below parameters in order : + 1. Property ID (mandatory) + 2. Property name (mandatory) + 3. Property default value (mandatory) + 4. Property descriptioon (optional) + + sendCustomLogs : Sends the custom data that is mentioned as "customDataMap" in the input json. + This custom data is available on the analytics console to build custom charts. + + ********************************************************************************/ + app.post('/order',mf.securityUtils.mfpAuth('accessRestricted'), (req, res) => { + var messageText = "Hello world from MFP"; + mf.push.sendNotification(messageText); + + mf.liveupdate.setProperty('bcg1', 'background', 'blue', "Property that is used to set background color"); + + /* Below push related user context data is obtained using the "securityUtils.mfpAuth" filter in the app.get request and + sent to the analytics server. Hence the push parameters are passed to the "mf-security" module and push scope is sent to the + filter as a parameter. */ + + var userContext = JSON.stringify(req.securityContext); + userContext = userContext.replace('mfp-application', 'mfpapplication'); //This is done to avoid json accessing errors + userContext = userContext.replace('mfp-device', 'mfpdevice'); + userContext = userContext.replace('mfp-user', 'mfpuser'); + userContext = JSON.parse(userContext); + + var datetime = new Date(); + var customLogInputs = { + "serverIpAddress": mf.analytics.mf_url, + "customDataMap": { + "client id": userContext.client_id + }, + "timestamp": datetime, + "timezone": "60", + "appVersion": userContext.mfpapplication.version, + "appName": "IBM Acme App", + "appID": userContext.mfpapplication.id, + "appVersionCode": userContext.mfpapplication.version, + "deviceID": userContext.mfpdevice.id, + "deviceModel": "iPhone6,2", + "deviceBrand": "Apple", + "deviceOS": "iOS", + "deviceOSversion": "9.2.1" + }; + + mf.analytics.sendCustomLogs(customLogInputs); + + mf.push.sendNotificationByUsers(messageText, [userContext.mfpuser.id] ); + + mf.push.sendNotificationByDeviceIds(messageText, [userContext.mfpdevice.id]); + + res.send("Order placed!"); + }); + + var port = process.env.PORT || 8080; + app.listen(port); + console.log('Node.js web server at port 7000 is running..'); + + /* + app.get('/analytics/networktransactions', (req, res) => { + + + var networkLogInputs = { + "resourceURL": "http://9.8.7.6:9080/some/path", + "responseCode": "200", + "requestMethod": "GET", + "loginModuleName": "My Login Module", + "realmName": "userCredChallengerRealm", + "sessionID": "jfkld789087f908s", + "trackingID": "f81d4fae-7dec-11d0-a765-00a0c91e6bf6", + "serverIpAddress": "172.16.254.1", + "bytesReceived": "2300", + "bytesSent": "120", + "serverProcessingTime": "289", + "backendProcessingTime": "95", + "adapterName": "MyAdapter", + "procedureName": "MyProcedure", + "authenticator": "com.ibm.acme.MyAuthenticator", + "loginModule": "com.ibm.acme.MyLoginModule", + "authSuccess": false, + "validationCode": "TOKEN_FAILED_MISSING_PARAMETER", + "roundTripTime": "598", + "inboundTimestamp": "2020-05-03T05:12:53.459Z", + "outboundTimestamp": "2020-05-03T05:12:53.459Z", + "userAgent": "Mozilla/5.0 (Linux; U; Android 4.0.3; ...", + "appVersion": "2.0 Beta", + "appName": "IBM Acme App", + "appID": "com.ibm.acme", + "appVersionCode": "2", + "deviceID": "518c66913ec337f0", + "deviceModel": "iPhone6,2", + "deviceBrand": "Apple", + "deviceOS": "iOS", + "deviceOSversion": "9.2.1", + "timestamp": "2020-05-03T05:12:53.459Z", + "timezone": "60" + }; + + analytics.sendNetworkTransactions(networkLogInputs); + res.send("Network logs have been sent!"); + + });*/ + + return app; +}; From 974e7c0465df8448536224d9d2f356044b6e51c3 Mon Sep 17 00:00:00 2001 From: sruthakeerthikotla Date: Mon, 8 Jun 2020 21:01:16 +0530 Subject: [PATCH 2/2] Create package.json --- odo/package.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 odo/package.json diff --git a/odo/package.json b/odo/package.json new file mode 100644 index 0000000..a419805 --- /dev/null +++ b/odo/package.json @@ -0,0 +1,15 @@ +{ + "name": "nodejs-mobile-foundation", + "version": "1.0.0", + "description": "The Node.js Mobile Foundation stack for microservice developers to rapidly build backend-for-frontend patterns for mobile applications interfacing with IBM Mobile Foundation", + "license": "See https://mobilefirstplatform.ibmcloud.com/licenses/ipla", + "main": "app.js", + "repository": { + "type": "git", + "url": "https://github.com/MobileFirst-Platform-Developer-Center/stacks/stacks.git" + }, + "scripts": {}, + "dependencies": { + "express": "^4.17.1" + } +}