2025-05-28 15:36:51 -07:00

75 lines
2.7 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
// Manually implement reselect/createSelector without memoization so we don't force the dependency,
// because this object is simple enough to not need memoization and the interface makes it easier to share null handling logic
var createSelector = function createSelector(deps, selector) {
return function (state) {
return selector.apply(void 0, _toConsumableArray(deps.map(function (dep) {
return dep(state);
})));
};
};
var getUser = function getUser(user) {
return user || {};
};
var getId = createSelector([getUser], function (_ref) {
var id = _ref.id;
return id;
});
var getName = createSelector([getUser], function (_ref2) {
var name = _ref2.name;
return name;
});
var getRoles = createSelector([getUser], function (_ref3) {
var roles = _ref3.roles;
return roles || [];
});
var getSubscriptions = createSelector([getUser], function (_ref4) {
var subscriptions = _ref4.subscriptions;
return subscriptions || [];
});
var getSubscriptionTier = createSelector([getUser], function (_ref5) {
var subscriptionTier = _ref5.subscriptionTier;
return subscriptionTier;
});
/**
* Converts a decoded JWT object to a simple user object
* @param {object} jwt, A decoded JWT from the Auth API
* @returns {object} A user object with simple property names instead of JWT schema links
*/
var jwtToUser = function jwtToUser(jwt) {
return jwt ? {
id: jwt['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier'],
name: jwt['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'],
roles: jwt['http://schemas.microsoft.com/ws/2008/06/identity/claims/role'],
subscription: jwt['http://schemas.dndbeyond.com/ws/2019/08/identity/claims/subscriber'],
subscriptionTier: jwt['http://schemas.dndbeyond.com/ws/2019/08/identity/claims/subscriptiontier'],
avatarUrl: jwt.avatarUrl
} : null;
};
var _default = {
getId: getId,
getName: getName,
getRoles: getRoles,
getSubscriptions: getSubscriptions,
getSubscriptionTier: getSubscriptionTier,
jwtToUser: jwtToUser
};
exports["default"] = _default;