UNPKG

@contentstack/management

Version:

The Content Management API is used to manage the content of your Contentstack account

98 lines (97 loc) 2.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isHost = isHost; exports.isNode = isNode; exports.getNodeVersion = getNodeVersion; exports["default"] = getUserAgent; var _os = require("os"); var HOST_REGEX = /^(?!\w+:\/\/)([\w-:]+\.)+([\w-:]+)(?::(\d+))?(?!:)$/; function isHost(host) { return HOST_REGEX.test(host); } function isNode() { return typeof process !== 'undefined' && !process.browser; } function getNodeVersion() { return process.versions.node ? "v".concat(process.versions.node) : process.version; } function isReactNative() { return typeof window !== 'undefined' && 'navigator' in window && 'product' in window.navigator && window.navigator.product === 'ReactNative'; } function getBrowserOS() { if (!window) { return null; } var userAgent = window.navigator.userAgent; var platform = window.navigator.platform; var macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K']; var windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE']; var iosPlatforms = ['iPhone', 'iPad', 'iPod']; var os = null; if (macosPlatforms.indexOf(platform) !== -1) { os = 'macOS'; } else if (iosPlatforms.indexOf(platform) !== -1) { os = 'iOS'; } else if (windowsPlatforms.indexOf(platform) !== -1) { os = 'Windows'; } else if (/Android/.test(userAgent)) { os = 'Android'; } else if (/Linux/.test(platform)) { os = 'Linux'; } return os; } function getNodeOS() { var os = (0, _os.platform)() || 'linux'; var version = (0, _os.release)() || '0.0.0'; var osMap = { android: 'Android', aix: 'Linux', darwin: 'macOS', freebsd: 'Linux', linux: 'Linux', openbsd: 'Linux', sunos: 'Linux', win32: 'Windows' }; if (os in osMap) { return "".concat(osMap[os] || 'Linux', "/").concat(version); } return null; } function getUserAgent(sdk, application, integration, feature) { var headerParts = []; if (application) { headerParts.push("app ".concat(application)); } if (integration) { headerParts.push("integration ".concat(integration)); } if (feature) { headerParts.push('feature ' + feature); } headerParts.push("sdk ".concat(sdk)); var os = null; try { if (isReactNative()) { os = getBrowserOS(); headerParts.push('platform ReactNative'); } else if (isNode()) { os = getNodeOS(); headerParts.push("platform node.js/".concat(getNodeVersion())); } else { os = getBrowserOS(); headerParts.push("platform browser"); } } catch (e) { os = null; } if (os) { headerParts.push("os ".concat(os)); } return "".concat(headerParts.filter(function (item) { return item !== ''; }).join('; '), ";"); }