-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·122 lines (100 loc) · 4.24 KB
/
Copy pathapp.js
File metadata and controls
executable file
·122 lines (100 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
module.exports = (options) => {
const app = require('express')()
const mf = options.mf;
app.get('/hello', (req, res) => {
res.send("Hello from CP4A");
});
/********************************************************************************
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('RegisteredClient'), (req, res) => {
var messageText = "Hello world from MFP";
mf.push.sendNotification(messageText);
//TEST
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;
};