get-profile-data.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. const fetch = require("npm-registry-fetch");
  3. const { pulseTillDone } = require("@lerna/pulse-till-done");
  4. module.exports.getProfileData = getProfileData;
  5. /**
  6. * Retrieve profile data of logged-in user.
  7. * @param {import("./fetch-config").FetchConfig} opts
  8. * @returns {Promise<ProfileData>}
  9. */
  10. function getProfileData(opts) {
  11. opts.log.verbose("", "Retrieving npm user profile");
  12. return pulseTillDone(fetch.json("/-/npm/v1/user", opts)).then((data) => {
  13. opts.log.silly("npm profile get", "received %j", data);
  14. return Object.assign(
  15. // remap to match legacy whoami format
  16. { username: data.name },
  17. data
  18. );
  19. });
  20. }
  21. /**
  22. * @typedef {object} ProfileData
  23. * @property {{ pending: boolean; mode: 'auth-and-writes' | 'auth-only' }} tfa
  24. * @property {string} name
  25. * @property {string} username legacy field alias of `name`
  26. * @property {string} email
  27. * @property {boolean} email_verified
  28. * @property {string} created
  29. * @property {string} updated
  30. * @property {string} [fullname]
  31. * @property {string} [twitter]
  32. * @property {string} [github]
  33. */