UNPKG

@stacks/profile

Version:

Library for Stacks profiles

57 lines 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveZoneFileToPerson = void 0; const common_1 = require("@stacks/common"); const zone_file_1 = require("zone-file"); const profile_1 = require("../profile"); const profileTokens_1 = require("../profileTokens"); function resolveZoneFileToPerson(zoneFile, publicKeyOrAddress, callback, fetchFn = (0, common_1.createFetchFn)()) { let zoneFileJson = null; try { zoneFileJson = (0, zone_file_1.parseZoneFile)(zoneFile); if (!zoneFileJson.hasOwnProperty('$origin')) { zoneFileJson = null; throw new Error('zone file is missing an origin'); } } catch (e) { console.error(e); } let tokenFileUrl = null; if (zoneFileJson && Object.keys(zoneFileJson).length > 0) { tokenFileUrl = (0, profile_1.getTokenFileUrl)(zoneFileJson); } else { let profile = null; try { profile = JSON.parse(zoneFile); const person = profile_1.Person.fromLegacyFormat(profile); profile = person.profile(); } catch (error) { console.warn(error); } callback(profile); return; } if (tokenFileUrl) { fetchFn(tokenFileUrl) .then((response) => response.text()) .then((responseText) => JSON.parse(responseText)) .then((responseJson) => { const tokenRecords = responseJson; const token = tokenRecords[0].token; const profile = (0, profileTokens_1.extractProfile)(token, publicKeyOrAddress); callback(profile); }) .catch((error) => { console.warn(error); }); } else { console.warn('Token file url not found'); callback({}); } } exports.resolveZoneFileToPerson = resolveZoneFileToPerson; //# sourceMappingURL=personZoneFiles.js.map