You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.2 KiB

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getManifest = getManifest;
function _axios() {
const data = _interopRequireDefault(require("axios"));
_axios = function () {
return data;
};
return data;
}
function _internal() {
const data = require("./internal");
_internal = function () {
return data;
};
return data;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
async function getManifest(publicUrl, {
platform = 'all'
} = {}) {
const req = {
url: publicUrl,
method: 'get',
headers: {
Accept: 'application/expo+json,application/json'
}
};
let exp;
try {
const resp = await _axios().default.request(req);
exp = resp.data;
} catch (e) {
throw new (_internal().XDLError)('INVALID_MANIFEST', `Unable to fetch manifest from ${publicUrl}. ` + e.toString());
}
exp = await _extractManifest(exp, publicUrl);
if (exp.platform !== platform && platform !== 'all') {
throw new (_internal().XDLError)('INVALID_MANIFEST', `Manifest from ${publicUrl} is not compatible with the ${platform} platform`);
}
return exp;
}
// Third party publicUrls can return an array of manifests
// We need to choose the first compatible one
async function _extractManifest(expOrArray, publicUrl) {
// if its not an array, assume it was a single manifest obj
if (!Array.isArray(expOrArray)) {
return expOrArray;
}
const {
sdkVersions
} = await _internal().Versions.versionsAsync();
for (let i = 0; i < expOrArray.length; i++) {
const manifestCandidate = expOrArray[i];
const sdkVersion = manifestCandidate.sdkVersion;
if (!sdkVersion) {
continue;
}
const versionObj = sdkVersions[sdkVersion];
if (!versionObj) {
continue;
}
const isDeprecated = versionObj.isDeprecated || false;
if (!isDeprecated) {
return manifestCandidate;
}
}
const supportedVersions = Object.keys(sdkVersions);
throw new (_internal().XDLError)('INVALID_MANIFEST', `No compatible manifest found at ${publicUrl}. Please use one of the SDK versions supported: ${JSON.stringify(supportedVersions)}`);
}
//# sourceMappingURL=ThirdParty.js.map