UNPKG

rauth-client

Version:

A lightweight, framework-agnostic JavaScript/TypeScript library for adding reverse authentication via WhatsApp on the client side.

3 lines (2 loc) 2.48 kB
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).rauth={})}(this,function(e){"use strict";const n={async init({appId:e,phone:n}){if(!e||!n)throw new Error("appId and phone are required");const o=await async function(){const e="undefined"!=typeof navigator?navigator:void 0;if(e&&e.userAgentData&&Array.isArray(e.userAgentData.brands)){const n=function(e){const n=["brave","edge","chrome","firefox","safari","opera"];for(const o of e){const e=o.brand.toLowerCase();for(const o of n)if(e.includes(o))return o}return""}(e.userAgentData.brands);if(n){let o=e.userAgentData.platform?e.userAgentData.platform.toLowerCase():"";return"windows"!==o&&"Windows"!==e.userAgentData.platform||(o="windows 10"),{browser:n,platform:o,session_source:"website"}}}const n="undefined"!=typeof navigator?navigator.userAgent:"",o=function(e){return(e=e.toLowerCase()).includes("edg/")?"edge":e.includes("chrome")&&!e.includes("edg/")?"chrome":e.includes("firefox")?"firefox":e.includes("safari")&&!e.includes("chrome")?"safari":e.includes("opera")||e.includes("opr/")?"opera":"unknown"}(n),t=function(e){return(e=e.toLowerCase()).includes("windows nt 10.0")?"windows 10":e.includes("windows nt 11.0")?"windows 11":e.includes("android")?"android":e.includes("iphone")||e.includes("ipad")?"ios":e.includes("mac os x")?"macos":e.includes("linux")?"linux":"unknown"}(n);return{browser:o,platform:t,session_source:"website"}}(),{ip:t,location:r}=await async function(){try{const e=await fetch("https://free.freeipapi.com/api/json"),n=await e.json();return{ip:n.ipAddress||"",city:n.cityName||"",country:n.countryName||"",location:n.cityName&&n.countryName?`${n.cityName}, ${n.countryName}`:""}}catch{return{ip:"",city:"",country:"",location:""}}}(),i={phone:n,ip:t,location:r,browser:o.browser,platform:o.platform,session_source:o.session_source};"undefined"!=typeof navigator&&navigator.platform&&""!==navigator.platform&&(i.device_name=navigator.platform);const a=await fetch("https://api.rauth.io/session/init",{method:"POST",headers:{"Content-Type":"application/json","x-app-id":e},body:JSON.stringify(i)});if(!a.ok){const e=await a.text();throw new Error("Rauth API error: "+e)}return a.json()}};"undefined"!=typeof window&&(window.rauth=n),e.default=n,e.rauth=n,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=rauth-client.min.js.map