UNPKG

@amplitude/ampli

Version:

Amplitude CLI

182 lines (181 loc) 8.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getRuntimeDisplayString = exports.isUnknownRuntime = exports.isSupportedRuntime = exports.isPlatformOnlyRuntime = exports.isAmpliRuntime = exports.getAmpliRuntimeProperties = exports.getRuntimeLanguageAndVersion = exports.UnsupportedRuntimeBaseDocUrl = exports.UnsupportedRuntimeDocUrls = exports.RuntimeSDKs = void 0; const types_1 = require("../types"); exports.RuntimeSDKs = { [types_1.RuntimeId.AndroidKotlinAmpliV2]: types_1.SDK.Android, [types_1.RuntimeId.AndroidKotlinAmpli]: types_1.SDK.AndroidLegacy, [types_1.RuntimeId.AndroidKotlinV4]: types_1.SDK.AndroidItlyV4, [types_1.RuntimeId.AndroidKotlinV3]: types_1.SDK.AndroidItlyV3, [types_1.RuntimeId.AndroidKotlinV2]: types_1.SDK.AndroidItlyV2, [types_1.RuntimeId.AndroidKotlin]: types_1.SDK.AndroidItlyV1, [types_1.RuntimeId.AndroidJavaAmpliV2]: types_1.SDK.Android, [types_1.RuntimeId.AndroidJavaAmpli]: types_1.SDK.AndroidLegacy, [types_1.RuntimeId.AndroidJavaV4]: types_1.SDK.AndroidItlyV4, [types_1.RuntimeId.AndroidJavaV3]: types_1.SDK.AndroidItlyV3, [types_1.RuntimeId.AndroidJava]: types_1.SDK.AndroidItlyV1, [types_1.RuntimeId.JreKotlinAmpli]: types_1.SDK.Jre, [types_1.RuntimeId.JreKotlinV4]: types_1.SDK.JreItlyV4, [types_1.RuntimeId.JreKotlinV3]: types_1.SDK.JreItlyV3, [types_1.RuntimeId.JreJavaAmpli]: types_1.SDK.Jre, [types_1.RuntimeId.JreJavaV4]: types_1.SDK.JreItlyV4, [types_1.RuntimeId.JreJavaV3]: types_1.SDK.JreItlyV3, [types_1.RuntimeId.JreJava]: types_1.SDK.JreItlyV1, [types_1.RuntimeId.BrowserTypeScriptAmpliV2]: types_1.SDK.Browser, [types_1.RuntimeId.BrowserTypeScriptAmpli]: types_1.SDK.BrowserLegacy, [types_1.RuntimeId.BrowserTypeScriptV3]: types_1.SDK.BrowserItlyV3, [types_1.RuntimeId.BrowserTypeScriptV2]: types_1.SDK.BrowserItlyV2, [types_1.RuntimeId.BrowserTypeScript]: types_1.SDK.BrowserItlyV1, [types_1.RuntimeId.BrowserJavaScriptAmpliV2]: types_1.SDK.Browser, [types_1.RuntimeId.BrowserJavaScriptAmpli]: types_1.SDK.BrowserLegacy, [types_1.RuntimeId.BrowserJavaScriptV3]: types_1.SDK.BrowserItlyV3, [types_1.RuntimeId.BrowserJavaScriptV2]: types_1.SDK.BrowserItlyV2, [types_1.RuntimeId.BrowserJavaScript]: types_1.SDK.BrowserItlyV1, [types_1.RuntimeId.NodeJsTypeScriptAmpliV2]: types_1.SDK.NodeJS, [types_1.RuntimeId.NodeJsTypeScriptAmpli]: types_1.SDK.NodeJSLegacy, [types_1.RuntimeId.NodeJsTypeScriptV3]: types_1.SDK.NodeJSItlyV3, [types_1.RuntimeId.NodeJsTypeScriptV2]: types_1.SDK.NodeJSItlyV2, [types_1.RuntimeId.NodeJsTypeScript]: types_1.SDK.NodeJSItlyV1, [types_1.RuntimeId.NodeJsJavaScriptAmpliV2]: types_1.SDK.NodeJS, [types_1.RuntimeId.NodeJsJavaScriptAmpli]: types_1.SDK.NodeJSLegacy, [types_1.RuntimeId.NodeJsJavaScriptV3]: types_1.SDK.NodeJSItlyV3, [types_1.RuntimeId.NodeJsJavaScriptV2]: types_1.SDK.NodeJSItlyV2, [types_1.RuntimeId.NodeJsJavaScript]: types_1.SDK.NodeJSItlyV1, [types_1.RuntimeId.ReactNativeTypeScriptAmpliV2]: types_1.SDK.ReactNative, [types_1.RuntimeId.ReactNativeTypeScriptAmpli]: types_1.SDK.ReactNativeLegacy, [types_1.RuntimeId.ReactNativeTypeScriptV3]: types_1.SDK.ReactNativeItlyV3, [types_1.RuntimeId.ReactNativeJavaScriptAmpliV2]: types_1.SDK.ReactNative, [types_1.RuntimeId.ReactNativeJavaScriptAmpli]: types_1.SDK.ReactNativeLegacy, [types_1.RuntimeId.ReactNativeJavaScriptV3]: types_1.SDK.ReactNativeItlyV3, [types_1.RuntimeId.DotNetCSharp]: types_1.SDK.DotNetItly, [types_1.RuntimeId.StarGoAmpli]: types_1.SDK.Go, [types_1.RuntimeId.IOSSwiftAmpliV2]: types_1.SDK.Swift, [types_1.RuntimeId.IOSSwiftAmpli]: types_1.SDK.IOS, [types_1.RuntimeId.IOSSwiftV2]: types_1.SDK.IOSItlyV2, [types_1.RuntimeId.IOSSwift]: types_1.SDK.IOSItlyV1, [types_1.RuntimeId.IOSObjCAmpliV2]: types_1.SDK.Swift, [types_1.RuntimeId.IOSObjCAmpli]: types_1.SDK.IOS, [types_1.RuntimeId.IOSObjCV2]: types_1.SDK.IOSItlyV2, [types_1.RuntimeId.IOSObjC]: types_1.SDK.IOSItlyV1, [types_1.RuntimeId.StarPythonAmpli]: types_1.SDK.Python, [types_1.RuntimeId.StarPythonV2]: types_1.SDK.PythonItlyV2, [types_1.RuntimeId.StarPython]: types_1.SDK.PythonItlyV1, [types_1.RuntimeId.StarRubyV2]: types_1.SDK.RubyItlyV2, [types_1.RuntimeId.StarRuby]: types_1.SDK.RubyItlyV1, }; exports.UnsupportedRuntimeDocUrls = { [types_1.UnsupportedRuntimeId.HTTP]: 'https://www.docs.developers.amplitude.com/analytics/apis/http-v2-api/', [types_1.UnsupportedRuntimeId.Flutter]: 'https://www.docs.developers.amplitude.com/data/sdks/flutter/', [types_1.UnsupportedRuntimeId.Unity]: 'https://www.docs.developers.amplitude.com/data/sdks/unity/', [types_1.UnsupportedRuntimeId.Unreal]: 'https://www.docs.developers.amplitude.com/data/sdks/unreal/', }; exports.UnsupportedRuntimeBaseDocUrl = 'https://www.docs.developers.amplitude.com/data/sdks/'; function getRuntimePlatform(platform) { switch (platform) { case 'android': case 'ios': case 'browser': case 'jre': case 'react-native': case 'node.js': case '.net': case '*': case 'unknown': return platform; default: return 'unknown'; } } function getRuntimeLanguage(language) { switch (language) { case 'c#': case 'go': case 'java': case 'javascript': case 'kotlin': case 'obj-c': case 'php': case 'python': case 'ruby': case 'rust': case 'scala': case 'swift': case 'typescript': case 'unknown': return language; default: return 'unknown'; } } function getRuntimeVersion(version) { switch (version) { case 'ampli-v2': case 'ampli': case 'v4': case 'v3': case 'v2': case 'v1': case 'unknown': return version; default: return 'unknown'; } } function getRuntimeLanguageAndVersion(languageId) { let language; let version; const parts = languageId.split('-'); const ampliIndex = parts.indexOf('ampli'); if (ampliIndex >= 0) { language = parts.slice(0, ampliIndex).join('-'); version = parts.slice(ampliIndex).join('-'); } else if (/^v\d+$/.test(parts[parts.length - 1])) { language = parts.slice(0, parts.length - 1).join('-'); version = parts[parts.length - 1]; } else { language = languageId; version = 'v1'; } return [language, version]; } exports.getRuntimeLanguageAndVersion = getRuntimeLanguageAndVersion; function getAmpliRuntimeProperties(runtime) { var _a, _b, _c, _d; const [platformId, languageId = ''] = ((_a = runtime.code) !== null && _a !== void 0 ? _a : '').split(':', 2); const [runtimeLanguage, runtimeVersion] = getRuntimeLanguageAndVersion(languageId); let sdkVersion; if (runtime.sdk) { const runtimeId = (_b = Object.entries(exports.RuntimeSDKs).find(e => e[1] === runtime.sdk)) === null || _b === void 0 ? void 0 : _b[0]; if (runtimeId) { [, sdkVersion] = getRuntimeLanguageAndVersion(runtimeId); } } const ampliPlatform = getRuntimePlatform(((_c = runtime.platform) === null || _c === void 0 ? void 0 : _c.toLowerCase().replace(/\s/g, '-')) || platformId); const ampliLanguage = getRuntimeLanguage(((_d = runtime.language) === null || _d === void 0 ? void 0 : _d.toLowerCase()) || runtimeLanguage); const ampliVersion = ampliLanguage !== 'unknown' ? getRuntimeVersion(sdkVersion || runtimeVersion) : 'unknown'; return { runtimeLanguage: ampliLanguage, runtimePlatform: ampliPlatform, runtimeVersion: ampliVersion, }; } exports.getAmpliRuntimeProperties = getAmpliRuntimeProperties; exports.isAmpliRuntime = (runtimeId) => /\bampli\b/.test(runtimeId); function isPlatformOnlyRuntime(runtimeId) { return runtimeId.search(/-\*-\*$/) >= 0; } exports.isPlatformOnlyRuntime = isPlatformOnlyRuntime; function isSupportedRuntime(runtimeId) { return types_1.RuntimeIds.includes(runtimeId); } exports.isSupportedRuntime = isSupportedRuntime; function isUnknownRuntime(runtimeId) { return !isSupportedRuntime(runtimeId) && !isPlatformOnlyRuntime(runtimeId) && !types_1.UnsupportedRuntimeIds.includes(runtimeId); } exports.isUnknownRuntime = isUnknownRuntime; function getRuntimeDisplayString(runtime) { return `${runtime.platformName}${runtime.languageName !== 'NULL' ? `/${runtime.languageName}` : ''}`; } exports.getRuntimeDisplayString = getRuntimeDisplayString;