Comparing version 0.0.14 to 0.0.15
163
index.js
var portalPostMessage; | ||
var platform = ''; | ||
var platform = ""; | ||
var PLATFORM_MOBILE_APP = 'MOBILE_APP'; | ||
var PLATFORM_TERMINAL = 'TERMINAL'; | ||
var PLATFORM_WEB_PORTAL = 'WEB_PORTAL'; | ||
var PLATFORM_MOBILE_APP = "MOBILE_APP"; | ||
var PLATFORM_TERMINAL = "TERMINAL"; | ||
var PLATFORM_WEB_PORTAL = "WEB_PORTAL"; | ||
@@ -27,3 +27,3 @@ // sdk code | ||
setStorage: onSetStorage, | ||
getStorage: onGetStorage | ||
getStorage: onGetStorage, | ||
}; | ||
@@ -33,40 +33,46 @@ | ||
function sleep(ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
async function onPrepareSignedRequest({ success, fail }) { | ||
var signedRequest = ""; | ||
var signedRequest = ''; | ||
if ('revenuemonster' in window) { | ||
if ("revenuemonster" in window) { | ||
await sleep(100); | ||
platform = window.revenuemonster.platform; | ||
signedRequest = window.revenuemonster.getSignedRequest(); | ||
success({ signedRequest, platform: platform }) | ||
} else if ('signedRequest' in window) { | ||
success({ signedRequest, platform: platform }); | ||
} else if ("signedRequest" in window) { | ||
await sleep(100); | ||
platform = PLATFORM_TERMINAL; | ||
signedRequest = window.signedRequest.getSignedRequest(); | ||
success({ signedRequest, platform: platform }) | ||
success({ signedRequest, platform: platform }); | ||
} else { | ||
platform = PLATFORM_WEB_PORTAL; | ||
window.addEventListener('message', function (event) { | ||
portalPostMessage = function (msg) { | ||
event.source.postMessage(JSON.stringify(msg), event.origin); | ||
}; | ||
if (typeof event.data !== 'string') return; | ||
if (!event.data.startsWith("{") && !event.data.startsWith("setImmediate")) { | ||
success({ signedRequest: event.data, platform: platform }); | ||
portalPostMessage({ | ||
action: 'FINISH_HANDSHAKE', | ||
}) | ||
window.onhashchange = function () { | ||
window.addEventListener( | ||
"message", | ||
function (event) { | ||
portalPostMessage = function (msg) { | ||
event.source.postMessage(JSON.stringify(msg), event.origin); | ||
}; | ||
if (typeof event.data !== "string") return; | ||
if ( | ||
!event.data.startsWith("{") && | ||
!event.data.startsWith("setImmediate") | ||
) { | ||
success({ signedRequest: event.data, platform: platform }); | ||
portalPostMessage({ | ||
action: 'URL_CHANGE', | ||
message: window.location.href, | ||
}) | ||
action: "FINISH_HANDSHAKE", | ||
}); | ||
window.onhashchange = function () { | ||
portalPostMessage({ | ||
action: "URL_CHANGE", | ||
message: window.location.href, | ||
}); | ||
}; | ||
return; | ||
} | ||
return; | ||
} | ||
}, false); | ||
}, | ||
false | ||
); | ||
} | ||
@@ -82,18 +88,18 @@ | ||
JSON.stringify({ | ||
action: 'SCANNER', | ||
type: 'scanner', | ||
action: "SCANNER", | ||
type: "scanner", | ||
}) | ||
); | ||
var elem = window.revenuemonster.os === 'android' ? document : window; | ||
elem.addEventListener( | ||
'message', | ||
function (event) { | ||
var msg = JSON.parse(event.data); | ||
if (msg.action === 'SCANNER') { | ||
success({ code: msg.result }); | ||
} | ||
}, | ||
false | ||
); | ||
var elem = window.revenuemonster.os === "android" ? document : window; | ||
function onMessage(event) { | ||
var msg = JSON.parse(event.data); | ||
if (msg.action === "SCANNER") { | ||
elem.removeEventListener("message", onMessage); | ||
success({ code: msg.result }); | ||
} | ||
} | ||
elem.addEventListener("message", onMessage, false); | ||
break; | ||
@@ -111,5 +117,5 @@ | ||
case PLATFORM_MOBILE_APP: | ||
var funcName = 'hide'; | ||
var funcName = "hide"; | ||
if (isLoading) { | ||
funcName = 'show'; | ||
funcName = "show"; | ||
} | ||
@@ -119,3 +125,3 @@ | ||
JSON.stringify({ | ||
action: 'TOGGLE_LOADER', | ||
action: "TOGGLE_LOADER", | ||
type: funcName, | ||
@@ -132,5 +138,5 @@ }) | ||
portalPostMessage({ | ||
action: 'TOGGLE_LOADER', | ||
type: isLoading ? 'show' : 'hide', | ||
}) | ||
action: "TOGGLE_LOADER", | ||
type: isLoading ? "show" : "hide", | ||
}); | ||
break; | ||
@@ -145,3 +151,3 @@ } | ||
JSON.stringify({ | ||
action: 'SHOW_TOAST', | ||
action: "SHOW_TOAST", | ||
message: title, | ||
@@ -158,10 +164,10 @@ }) | ||
portalPostMessage({ | ||
action: 'SHOW_NOTIFICATION', | ||
action: "SHOW_NOTIFICATION", | ||
type, | ||
message: title, | ||
}) | ||
}); | ||
} | ||
} | ||
function onShowAlert({ title = '', type = 'success' }) { | ||
function onShowAlert({ title = "", type = "success" }) { | ||
switch (platform) { | ||
@@ -171,3 +177,3 @@ case PLATFORM_MOBILE_APP: | ||
JSON.stringify({ | ||
action: 'MODAL_MESSAGE', | ||
action: "MODAL_MESSAGE", | ||
type, | ||
@@ -192,3 +198,2 @@ message: title, | ||
} | ||
} | ||
@@ -202,3 +207,3 @@ | ||
eventData = window.revenuemonster.getEventData(); | ||
success(eventData) | ||
success(eventData); | ||
break; | ||
@@ -213,3 +218,2 @@ | ||
function onSetBarTitle({ title }) { | ||
@@ -220,3 +224,3 @@ switch (platform) { | ||
JSON.stringify({ | ||
action: 'NAVBAR_TITLE', | ||
action: "NAVBAR_TITLE", | ||
message: title, | ||
@@ -237,6 +241,6 @@ }) | ||
portalPostMessage({ | ||
action: 'SET_COOKIE', | ||
action: "SET_COOKIE", | ||
type: key, | ||
message: value, | ||
}) | ||
}); | ||
break; | ||
@@ -250,20 +254,27 @@ } | ||
portalPostMessage({ | ||
action: 'GET_COOKIE', | ||
action: "GET_COOKIE", | ||
type: key, | ||
}) | ||
}); | ||
window.addEventListener('message', function (event) { | ||
if (typeof event.data !== 'string') return; | ||
if (event.data.startsWith("{") && !event.data.startsWith("setImmediate")) { | ||
const x = JSON.parse(event.data); | ||
switch (x.action) { | ||
case "GET_COOKIE": | ||
if (key === x.type) { | ||
success({ data: x.data }); | ||
} | ||
break; | ||
window.addEventListener( | ||
"message", | ||
function (event) { | ||
if (typeof event.data !== "string") return; | ||
if ( | ||
event.data.startsWith("{") && | ||
!event.data.startsWith("setImmediate") | ||
) { | ||
const x = JSON.parse(event.data); | ||
switch (x.action) { | ||
case "GET_COOKIE": | ||
if (key === x.type) { | ||
success({ data: x.data }); | ||
} | ||
break; | ||
} | ||
return; | ||
} | ||
return; | ||
} | ||
}, false); | ||
}, | ||
false | ||
); | ||
break; | ||
@@ -294,3 +305,3 @@ } | ||
PLATFORM_TERMINAL, | ||
PLATFORM_WEB_PORTAL | ||
}; | ||
PLATFORM_WEB_PORTAL, | ||
}; |
{ | ||
"name": "rm-plugin", | ||
"version": "0.0.14", | ||
"type": "module", | ||
"description": "", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/RevenueMonster/rm-plugin.git" | ||
}, | ||
"main": "index.min.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": ["react-native", "revenuemonster", "sdk"], | ||
"author": "Mohamed Yussuf", | ||
"license": "MIT" | ||
} | ||
"name": "rm-plugin", | ||
"version": "0.0.15", | ||
"type": "module", | ||
"description": "", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/RevenueMonster/rm-plugin.git" | ||
}, | ||
"main": "index.min.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"react-native", | ||
"revenuemonster", | ||
"sdk" | ||
], | ||
"author": "Mohamed Yussuf", | ||
"license": "MIT" | ||
} |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
23895
608
1