@amplitude/ampli
Version:
Amplitude CLI
182 lines (181 loc) • 8.71 kB
JavaScript
"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.SDK.Android,
[]: types_1.SDK.AndroidLegacy,
[]: types_1.SDK.AndroidItlyV4,
[]: types_1.SDK.AndroidItlyV3,
[]: types_1.SDK.AndroidItlyV2,
[]: types_1.SDK.AndroidItlyV1,
[]: types_1.SDK.Android,
[]: types_1.SDK.AndroidLegacy,
[]: types_1.SDK.AndroidItlyV4,
[]: types_1.SDK.AndroidItlyV3,
[]: types_1.SDK.AndroidItlyV1,
[]: types_1.SDK.Jre,
[]: types_1.SDK.JreItlyV4,
[]: types_1.SDK.JreItlyV3,
[]: types_1.SDK.Jre,
[]: types_1.SDK.JreItlyV4,
[]: types_1.SDK.JreItlyV3,
[]: types_1.SDK.JreItlyV1,
[]: types_1.SDK.Browser,
[]: types_1.SDK.BrowserLegacy,
[]: types_1.SDK.BrowserItlyV3,
[]: types_1.SDK.BrowserItlyV2,
[]: types_1.SDK.BrowserItlyV1,
[]: types_1.SDK.Browser,
[]: types_1.SDK.BrowserLegacy,
[]: types_1.SDK.BrowserItlyV3,
[]: types_1.SDK.BrowserItlyV2,
[]: types_1.SDK.BrowserItlyV1,
[]: types_1.SDK.NodeJS,
[]: types_1.SDK.NodeJSLegacy,
[]: types_1.SDK.NodeJSItlyV3,
[]: types_1.SDK.NodeJSItlyV2,
[]: types_1.SDK.NodeJSItlyV1,
[]: types_1.SDK.NodeJS,
[]: types_1.SDK.NodeJSLegacy,
[]: types_1.SDK.NodeJSItlyV3,
[]: types_1.SDK.NodeJSItlyV2,
[]: types_1.SDK.NodeJSItlyV1,
[]: types_1.SDK.ReactNative,
[]: types_1.SDK.ReactNativeLegacy,
[]: types_1.SDK.ReactNativeItlyV3,
[]: types_1.SDK.ReactNative,
[]: types_1.SDK.ReactNativeLegacy,
[]: types_1.SDK.ReactNativeItlyV3,
[]: types_1.SDK.DotNetItly,
[]: types_1.SDK.Go,
[]: types_1.SDK.Swift,
[]: types_1.SDK.IOS,
[]: types_1.SDK.IOSItlyV2,
[]: types_1.SDK.IOSItlyV1,
[]: types_1.SDK.Swift,
[]: types_1.SDK.IOS,
[]: types_1.SDK.IOSItlyV2,
[]: types_1.SDK.IOSItlyV1,
[]: types_1.SDK.Python,
[]: types_1.SDK.PythonItlyV2,
[]: types_1.SDK.PythonItlyV1,
[]: types_1.SDK.RubyItlyV2,
[]: types_1.SDK.RubyItlyV1,
};
exports.UnsupportedRuntimeDocUrls = {
[]: 'https://www.docs.developers.amplitude.com/analytics/apis/http-v2-api/',
[]: 'https://www.docs.developers.amplitude.com/data/sdks/flutter/',
[]: 'https://www.docs.developers.amplitude.com/data/sdks/unity/',
[]: '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;