{"version":3,"sources":["Versions.js"],"names":["async","await","Api","versionsAsync","value","user","UserManager","getCurrentUserAsync","api","ApiV2Client","clientForUser","postAsync","secret","process","env","EXPO_VERSIONS_SECRET","setVersionsAsync","let","sdkVersions","sdkVersionsAsync","result","highestMajorVersion","_","forEach","key","semver","major","version","newestSdkVersionAsync","facebookReactNativeVersions","Set","facebookReactNativeVersion","add","Array","from","facebookReactNativeVersionsAsync","valid","ErrorCode","INVALID_VERSION","currentSdkVersion","minor","gt","facebookReactNativeVersionToExpoVersionAsync","gteSdkVersion","parseSdkVersionFromTag","expJson","sdkVersion","gte","e","tag","startsWith","substring"],"mappings":";;;;;;;;+BAaOA,aAA+B;AACpC,WAAOC,MAAMC,8BAAIC,aAAJD,EAAb;AACF,G;;kBAFsBC,a;;;;;;gCAIfH,WAAgCI,KAAhCJ,EAA4C;AACjD,UAAMK,OAAOJ,MAAMK,gCAAYC,mBAAZD,EAAnB;AACA,UAAME,MAAMC,gCAAYC,aAAZD,CAA0BJ,IAA1BI,CAAZ;AACA,WAAOR,MAAMO,IAAIG,SAAJH,CAAc,iBAAdA,EAAiC;AAC5CJ,WAD4C;AAE5CQ,cAAQC,QAAQC,GAARD,CAAYE;AAFwB,KAAjCP,CAAb;AAIF,G;;kBAPsBQ,gB;;;;;;gCAoCfhB,aAAuC;AAC5CiB,QAAIC,cAAcjB,MAAMC,8BAAIiB,gBAAJjB,EAAxBe;AACAA,QAAIG,SAAS,EAAbH;AACAA,QAAII,sBAAsB,OAA1BJ;AACAK,wCAAEC,OAAFD,CAAUJ,WAAVI,EAAuB,UAAClB,KAAD,EAAQoB,GAAR,EAAgB;AACrC,UAAIC,oCAAOC,KAAPD,CAAaD,GAAbC,IAAoBA,oCAAOC,KAAPD,CAAaJ,mBAAbI,CAAxB,EAA2D;AACzDJ,8BAAsBG,GAAtBH;AACAD,iBAAShB,KAATgB;AACF;AACD,KALDE;AAMAF,WAAOO,OAAPP,GAAiBC,mBAAjBD;AACA,WAAOA,MAAP;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AAA;AAAA;;;;AACA;AAAA;AAAA;;;;AACA;AAAA;AAAA;;;;AACA;AAAA;AAAA;;;;;;AAeO,SAASD,aAAT,CAAuBE,OAAvB,EAAqCC,UAArC,EAAkE;AACvE,MAAI,CAACD,QAAQC,UAAb,EAAyB;AACvB,WAAO,KAAP;AACF;;AAEA,MAAID,QAAQC,UAARD,KAAuB,aAA3B,EAA0C;AACxC,WAAO,IAAP;AACF;;AAEA,MAAI;AACF,WAAOpB,oCAAOsB,GAAPtB,CAAWoB,QAAQC,UAAnBrB,EAA+BqB,UAA/BrB,CAAP;AACF,GAFA,CAEE,OAAOuB,CAAP,EAAU;AACV,UAAM,4CACJX,0CAAUC,eADN,EAEH,GAAEO,QAAQC,UAAW,uDAFlB,CAAN;AAIF;AACF;;AAEO,SAASF,sBAAT,CAAgCK,GAAhC,EAA6C;AAClD,MAAIA,IAAIC,UAAJD,CAAe,MAAfA,CAAJ,EAA4B;AAC1B,WAAOA,IAAIE,SAAJF,CAAc,CAAdA,CAAP;AACF;;AAEA,SAAOA,GAAP;AACF","file":"../Versions.js","sourcesContent":["/**\n * @flow\n */\n\nimport _ from 'lodash';\nimport semver from 'semver';\n\nimport Api from './Api';\nimport ApiV2Client from './ApiV2';\nimport ErrorCode from './ErrorCode';\nimport XDLError from './XDLError';\nimport UserManager from './User';\n\nexport async function versionsAsync() {\n return await Api.versionsAsync();\n}\n\nexport async function setVersionsAsync(value: any) {\n const user = await UserManager.getCurrentUserAsync();\n const api = ApiV2Client.clientForUser(user);\n return await api.postAsync('versions/update', {\n value,\n secret: process.env.EXPO_VERSIONS_SECRET,\n });\n}\n\nexport function gteSdkVersion(expJson: any, sdkVersion: string): boolean {\n if (!expJson.sdkVersion) {\n return false;\n }\n\n if (expJson.sdkVersion === 'UNVERSIONED') {\n return true;\n }\n\n try {\n return semver.gte(expJson.sdkVersion, sdkVersion);\n } catch (e) {\n throw new XDLError(\n ErrorCode.INVALID_VERSION,\n `${expJson.sdkVersion} is not a valid version. Must be in the form of x.y.z`\n );\n }\n}\n\nexport function parseSdkVersionFromTag(tag: string) {\n if (tag.startsWith('sdk-')) {\n return tag.substring(4);\n }\n\n return tag;\n}\n\nexport async function newestSdkVersionAsync() {\n let sdkVersions = await Api.sdkVersionsAsync();\n let result = {};\n let highestMajorVersion = '0.0.0';\n _.forEach(sdkVersions, (value, key) => {\n if (semver.major(key) > semver.major(highestMajorVersion)) {\n highestMajorVersion = key;\n result = value;\n }\n });\n result.version = highestMajorVersion;\n return result;\n}\n\nexport async function facebookReactNativeVersionsAsync(): Promise> {\n let sdkVersions = await Api.sdkVersionsAsync();\n let facebookReactNativeVersions = new Set();\n\n _.forEach(sdkVersions, value => {\n if (value.facebookReactNativeVersion) {\n facebookReactNativeVersions.add(value.facebookReactNativeVersion);\n }\n });\n\n return Array.from(facebookReactNativeVersions);\n}\n\nexport async function facebookReactNativeVersionToExpoVersionAsync(\n facebookReactNativeVersion: string\n): Promise {\n if (!semver.valid(facebookReactNativeVersion)) {\n throw new XDLError(\n ErrorCode.INVALID_VERSION,\n `${facebookReactNativeVersion} is not a valid version. Must be in the form of x.y.z`\n );\n }\n\n let sdkVersions = await Api.sdkVersionsAsync();\n let currentSdkVersion = null;\n\n _.forEach(sdkVersions, (value, key) => {\n if (\n semver.major(value.facebookReactNativeVersion) === semver.major(facebookReactNativeVersion) &&\n semver.minor(value.facebookReactNativeVersion) === semver.minor(facebookReactNativeVersion) &&\n (!currentSdkVersion || semver.gt(key, currentSdkVersion))\n ) {\n currentSdkVersion = key;\n }\n });\n\n return currentSdkVersion;\n}\n"],"sourceRoot":"/xdl/src"}