UNPKG

espn-fantasy-football-api

Version:

A Javascript API to connect to ESPN's fantasy football API

784 lines (725 loc) 560 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["espn-fantasy-football-api"] = factory(); else root["espn-fantasy-football-api"] = factory(); })(self, () => { return /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ "./src/base-classes/base-cacheable-object/base-cacheable-object.js": /*!*************************************************************************!*\ !*** ./src/base-classes/base-cacheable-object/base-cacheable-object.js ***! \*************************************************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) /* harmony export */ }); /* harmony import */ var lodash_isEmpty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash/isEmpty */ "./node_modules/lodash/isEmpty.js"); /* harmony import */ var lodash_isEmpty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_isEmpty__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var lodash_map__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash/map */ "./node_modules/lodash/map.js"); /* harmony import */ var lodash_map__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_map__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! lodash/get */ "./node_modules/lodash/get.js"); /* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash_get__WEBPACK_IMPORTED_MODULE_2__); /* harmony import */ var _base_object_base_object_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../base-object/base-object.js */ "./src/base-classes/base-object/base-object.js"); function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _get2() { if (typeof Reflect !== "undefined" && Reflect.get) { _get2 = Reflect.get.bind(); } else { _get2 = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get2.apply(this, arguments); } function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * The base class for all project objects that can be cached. This class is extremely useful for * classes which have unique identifiers but cannot make API calls. * * Note: The id used for caching may be different than any id used by the response from the wire. * This allows for caching of an instance with the same id but different season data. Example: * League with different `seasonId`s can all be cached using this functionality. See the * `getCacheId` method for implementation. * * When managing the cache, never set an object to an `undefined` id. Always check that the result * from `getCacheId` is valid (see `_populateObject` for an example). Otherwise the cache will not * be in the correct state. * * @extends {BaseObject} */ var BaseCacheableObject = /*#__PURE__*/function (_BaseObject) { _inherits(BaseCacheableObject, _BaseObject); var _super = _createSuper(BaseCacheableObject); function BaseCacheableObject() { _classCallCheck(this, BaseCacheableObject); return _super.apply(this, arguments); } _createClass(BaseCacheableObject, [{ key: "getIDParams", value: /** * Returns an object containing all IDs used for API requests and caching for the instance. * @return {Object} */ function getIDParams() { return this.constructor.getIDParams(this); } /** * Returns the id used for caching. Important for classes that have multiple identifiers. Example: * League is identified by its `leagueId` and its `seasonId`. This method prevents separate * seasons from overriding each other's data. * @return {String|undefined} */ }, { key: "getCacheId", value: function getCacheId() { return this.constructor.getCacheId(this); } }], [{ key: "_populateObject", value: /** * Defers to `BaseObject._populateObject` and then caches the instance using the caching id from * `getCacheId`. * @override */ function _populateObject(_ref) { var data = _ref.data, constructorParams = _ref.constructorParams, rawData = _ref.rawData, instance = _ref.instance, isDataFromServer = _ref.isDataFromServer; var populatedInstance = _get2(_getPrototypeOf(BaseCacheableObject), "_populateObject", this).call(this, { data: data, constructorParams: constructorParams, rawData: rawData, instance: instance, isDataFromServer: isDataFromServer }); if (isDataFromServer && populatedInstance.getCacheId()) { this.cache[populatedInstance.getCacheId()] = populatedInstance; } return populatedInstance; } /** * Returns all cached instances of an BaseCacheableObject. If no cache exists, a cache object is * created. This implementation ensures each class has a unique cache of only instances of the * BaseCacheableObject that does not overlap with other BaseCacheableObject classes. The keys of * the cache should use the caching id implemented in `getCacheId`. * @return {Object.<String, BaseCacheableObject>} The cache of BaseCacheableObjects. */ }, { key: "cache", get: function get() { if (!this._cache) { this._cache = {}; } return this._cache; } /** * Sets the cache object. * @param {Object.<String, BaseCacheableObject>} cache */, set: function set(cache) { this._cache = cache; } /** * Resets cache to an empty object. */ }, { key: "clearCache", value: function clearCache() { this._cache = {}; } /** * Returns a cached instance matching the passed caching id if it exists. Otherwise, returns * undefined. * @param {Number} id This id must match the form of the caching id provided by `getCacheId`. * @return {BaseCacheableObject|undefined} */ }, { key: "get", value: function get(id) { return lodash_get__WEBPACK_IMPORTED_MODULE_2___default()(this.cache, id); } /** * Should be overridden by each subclass. Returns an object containing all IDs used for API * requests and caching. * @return {Object} */ }, { key: "getIDParams", value: function getIDParams() { return {}; } /** * Constructs and returns an id for the cache if possible from the passed params. If construction * is not possible, returns undefined. * @param {Object} idParams * @return {string|undefined} */ }, { key: "getCacheId", value: function getCacheId(idParams) { var cacheId = lodash_map__WEBPACK_IMPORTED_MODULE_1___default()(this.getIDParams(idParams), function (value, key) { return "".concat(key, "=").concat(value, ";"); }).join(''); return lodash_isEmpty__WEBPACK_IMPORTED_MODULE_0___default()(cacheId) ? undefined : cacheId; } }]); return BaseCacheableObject; }(_base_object_base_object_js__WEBPACK_IMPORTED_MODULE_3__["default"]); BaseCacheableObject.displayName = 'BaseCacheableObject'; /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (BaseCacheableObject); /***/ }), /***/ "./src/base-classes/base-object/base-object.js": /*!*****************************************************!*\ !*** ./src/base-classes/base-object/base-object.js ***! \*****************************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) /* harmony export */ }); /* harmony import */ var lodash_forEach__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash/forEach */ "./node_modules/lodash/forEach.js"); /* harmony import */ var lodash_forEach__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_forEach__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var lodash_set__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash/set */ "./node_modules/lodash/set.js"); /* harmony import */ var lodash_set__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_set__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var lodash_isUndefined__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! lodash/isUndefined */ "./node_modules/lodash/isUndefined.js"); /* harmony import */ var lodash_isUndefined__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash_isUndefined__WEBPACK_IMPORTED_MODULE_2__); /* harmony import */ var lodash_isPlainObject__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! lodash/isPlainObject */ "./node_modules/lodash/isPlainObject.js"); /* harmony import */ var lodash_isPlainObject__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(lodash_isPlainObject__WEBPACK_IMPORTED_MODULE_3__); /* harmony import */ var lodash_isString__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! lodash/isString */ "./node_modules/lodash/isString.js"); /* harmony import */ var lodash_isString__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(lodash_isString__WEBPACK_IMPORTED_MODULE_4__); /* harmony import */ var lodash_map__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! lodash/map */ "./node_modules/lodash/map.js"); /* harmony import */ var lodash_map__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(lodash_map__WEBPACK_IMPORTED_MODULE_5__); /* harmony import */ var lodash_isFunction__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! lodash/isFunction */ "./node_modules/lodash/isFunction.js"); /* harmony import */ var lodash_isFunction__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(lodash_isFunction__WEBPACK_IMPORTED_MODULE_6__); /* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! lodash/get */ "./node_modules/lodash/get.js"); /* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(lodash_get__WEBPACK_IMPORTED_MODULE_7__); /* harmony import */ var lodash_isEmpty__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! lodash/isEmpty */ "./node_modules/lodash/isEmpty.js"); /* harmony import */ var lodash_isEmpty__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(lodash_isEmpty__WEBPACK_IMPORTED_MODULE_8__); /* harmony import */ var lodash_assignWith__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! lodash/assignWith */ "./node_modules/lodash/assignWith.js"); /* harmony import */ var lodash_assignWith__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(lodash_assignWith__WEBPACK_IMPORTED_MODULE_9__); /* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../utils.js */ "./src/utils.js"); function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /** * The base class for all project objects. Provides data mapping functionality. */ var BaseObject = /*#__PURE__*/function () { /** * @param {Object} options Properties to be assigned to the BaseObject. Must match the keys of the * BaseObject's `responseMap` or valid options defined by the class's * `constructor`. */ function BaseObject() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classCallCheck(this, BaseObject); if (!lodash_isEmpty__WEBPACK_IMPORTED_MODULE_8___default()(options)) { this.constructor._populateObject({ data: options, instance: this, isDataFromServer: false }); } } /** * The class name. Minification will break `this.constructor.name`; this allows for readable * logging even in minified code. * @type {String} */ _createClass(BaseObject, null, [{ key: "responseMap", get: function get() { return this._responseMap; }, set: function set(_responseMap) { this._responseMap = lodash_assignWith__WEBPACK_IMPORTED_MODULE_9___default()({}, this._responseMap, _responseMap); } }, { key: "_processObjectValue", value: /** * Helper for processing items on `responseMap`s that are objects. * @private * * @param {Object} options.data * @param {BaseObject} options.instance The instance to populate. This instance will be mutated. * @param {Object} options.constructorParams Params to be passed to the instance's constructor. * Useful for passing parent data, such as `leagueId`. * @param {String} options.value The value of the responseMap entry being parsed. * @return {*} */ function _processObjectValue(_ref) { var data = _ref.data, rawData = _ref.rawData, constructorParams = _ref.constructorParams, instance = _ref.instance, value = _ref.value; if (!value.key) { throw new Error("".concat(this.displayName, ": _populateObject: Invalid responseMap object. Object must define ") + 'key. See docs for typedef of ResponseMapValueObject.'); } var responseData = lodash_get__WEBPACK_IMPORTED_MODULE_7___default()(data, value.key); if (lodash_isFunction__WEBPACK_IMPORTED_MODULE_6___default()(value.manualParse)) { return value.manualParse(responseData, data, rawData, constructorParams, instance); } else if (value.BaseObject) { var buildInstance = function buildInstance(passedData) { return value.BaseObject.buildFromServer(passedData, constructorParams, rawData); }; return value.isArray ? lodash_map__WEBPACK_IMPORTED_MODULE_5___default()(responseData, buildInstance) : buildInstance(responseData); } throw new Error("".concat(this.displayName, ": _populateObject: Invalid responseMap object. Object must define ") + '`BaseObject` or `manualParse`. See docs for typedef of ResponseMapValueObject.'); } /** * Helper method for `_populateObject` that houses the attribute mapping logic. Should never be * used by other methods. See {@link ResponseMapValueObject} for `responseMap` documentation. * @private * * @param {Object} options.data * @param {BaseObject} options.instance The instance to populate. This instance will be mutated. * @param {Object} options.constructorParams Params to be passed to the instance's constructor. * Useful for passing parent data, such as `leagueId`. * @param {Boolean} options.isDataFromServer When true, the data came from the ESPN API over the * wire. When false, the data came locally. * @param {String} options.key The key of the responseMap entry being parsed. * @param {String} options.value The value of the responseMap entry being parsed. */ }, { key: "_processResponseMapItem", value: function _processResponseMapItem(_ref2) { var data = _ref2.data, rawData = _ref2.rawData, constructorParams = _ref2.constructorParams, instance = _ref2.instance, isDataFromServer = _ref2.isDataFromServer, key = _ref2.key, value = _ref2.value; /** * @typedef {Object} BaseObject~ResponseMapValueObject * * The `responseMap` can have two values: a string or a ResponseMapValueObject. When string, the * data found on that response is directly mapped to the BaseObject without mutation. When * ResponseMapValueObject, the data at the `key` will be used to create BaseObject(s) or * manually parsed with a provided `manualParse function`. Either result is attached to the * BaseObject being populated. * * @property {String} key The key on the response data where the data can be found. This must be * defined. * @property {BaseObject} BaseObject The BaseObject to create with the response data. * @property {Boolean} isArray Whether or not the response data is an array. Useful for * attributes such as "teams". * @property {Boolean} defer Whether or not to wait to parse the entry until a second pass of * the map. This is useful for populating items with cached instances * that are not guaranteed to be parsed/cached during initial parsing. * Example: Using Team instances on League. * @property {function} manualParse A function to manually apply logic to the response. This * function must return its result to be attached to the * populated BaseObject. The arguments to this function are: * (data at the key), (the whole response), (the instance being * populated). * @example * static responseMap = { * teamId: 'teamId', * team: { * key: 'team_on_response', * BaseObject: true * }, * teams: { * key: 'teams_on_response', * BaseObject: Team, * isArray: true * }, * manualTeams: { * key: 'manual_teams_on_response', * BaseObject: Team, * manualParse: (responseData, response, constructorParams, instance) => ( * Team.buildFromServer(responseData) * ) * } * }; */ var item; if (!isDataFromServer) { item = lodash_get__WEBPACK_IMPORTED_MODULE_7___default()(data, key); } else if (lodash_isString__WEBPACK_IMPORTED_MODULE_4___default()(value)) { item = lodash_get__WEBPACK_IMPORTED_MODULE_7___default()(data, value); } else if (lodash_isPlainObject__WEBPACK_IMPORTED_MODULE_3___default()(value)) { item = this._processObjectValue({ data: data, rawData: rawData, constructorParams: constructorParams, instance: instance, value: value }); } else { throw new Error("".concat(this.displayName, ": _populateObject: Did not recognize responseMap value type for key ") + "".concat(key)); } if (!lodash_isUndefined__WEBPACK_IMPORTED_MODULE_2___default()(item)) { lodash_set__WEBPACK_IMPORTED_MODULE_1___default()(instance, key, item); } } /** * Returns the passed instance of the BaseObject populated with the passed data, mapping the * attributes defined in the value of responseMap to the matching key. * @private * * @param {Object} options.data The data to map onto the passed instance. * @param {BaseObject} options.instance The instance to populate. This instance will be mutated. * @param {Boolean} options.isDataFromServer When true, the data came from ESPN. When false, the * data came locally. * @return {BaseObject} The mutated BaseObject instance. */ }, { key: "_populateObject", value: function _populateObject(_ref3) { var _this = this; var data = _ref3.data, rawData = _ref3.rawData, constructorParams = _ref3.constructorParams, instance = _ref3.instance, isDataFromServer = _ref3.isDataFromServer; if (!instance) { throw new Error("".concat(this.displayName, ": _populateObject: Did not receive instance to populate")); } else if (lodash_isEmpty__WEBPACK_IMPORTED_MODULE_8___default()(data)) { return instance; } var deferredMapItems = {}; lodash_forEach__WEBPACK_IMPORTED_MODULE_0___default()(this.responseMap, function (value, key) { if (lodash_isPlainObject__WEBPACK_IMPORTED_MODULE_3___default()(value) && value.defer) { lodash_set__WEBPACK_IMPORTED_MODULE_1___default()(deferredMapItems, key, value); } else { _this._processResponseMapItem({ data: data, rawData: rawData, constructorParams: constructorParams, instance: instance, isDataFromServer: isDataFromServer, key: key, value: value }); } }); lodash_forEach__WEBPACK_IMPORTED_MODULE_0___default()(deferredMapItems, function (value, key) { _this._processResponseMapItem({ data: data, rawData: rawData, constructorParams: constructorParams, instance: instance, isDataFromServer: isDataFromServer, key: key, value: value }); }); return instance; } /** * Returns a new instance of the BaseObject populated with the passed data that came from ESPN, * mapping the attributes defined in the value of responseMap to the matching key. Use this method * when constructing BaseObjects with server responses. * @param {Object} data Data originating from the server. * @param {Object} constructorParams Params to be passed to the instance's constructor. Useful * for passing parent data, such as `leagueId`. * @return {BaseObject} A new instance of the BaseObject populated with the passed data. */ }, { key: "buildFromServer", value: function buildFromServer(data, constructorParams) { var instance = new this(constructorParams); var flatData = this.flattenResponse ? (0,_utils_js__WEBPACK_IMPORTED_MODULE_10__.flattenObjectSansNumericKeys)(data) : data; this._populateObject({ data: flatData, rawData: data, constructorParams: constructorParams, instance: instance, isDataFromServer: true }); return instance; } }]); return BaseObject; }(); BaseObject.displayName = 'BaseObject'; /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (BaseObject); /***/ }), /***/ "./src/boxscore-player/boxscore-player.js": /*!************************************************!*\ !*** ./src/boxscore-player/boxscore-player.js ***! \************************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) /* harmony export */ }); /* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash/get */ "./node_modules/lodash/get.js"); /* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_get__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _player_player__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../player/player */ "./src/player/player.js"); /* harmony import */ var _player_stats_player_stats__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../player-stats/player-stats */ "./src/player-stats/player-stats.js"); /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../constants */ "./src/constants.js"); function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /* global PlayerStats */ /** * Represents a player and their stats on a boxscore. * * @augments {Player} */ var BoxscorePlayer = /*#__PURE__*/function (_Player) { _inherits(BoxscorePlayer, _Player); var _super = _createSuper(BoxscorePlayer); function BoxscorePlayer() { _classCallCheck(this, BoxscorePlayer); return _super.apply(this, arguments); } return _createClass(BoxscorePlayer); }(_player_player__WEBPACK_IMPORTED_MODULE_1__["default"]); BoxscorePlayer.displayName = 'BoxscorePlayer'; /* eslint-disable jsdoc/no-undefined-types */ /** * @typedef {PlayerMap} BoxscorePlayerMap * * @property {Player} player The player model representing the NFL player. * @property {string} rosteredPosition The position the player is slotted at in the fantasy lineup * @property {number} totalPoints The total points scored by the player. * @property {PlayerStats} pointBreakdown The PlayerStats model with the points scored by the * player. * @property {PlayerStats} rawStats The PlayerStats model with the raw statistics registered by * the player. */ /* eslint-enable jsdoc/no-undefined-types */ /** * @type {BoxscorePlayerMap} */ BoxscorePlayer.responseMap = { availabilityStatus: { key: 'status', manualParse: function manualParse(responseData, data, rawData) { return rawData.playerPoolEntry.status; } }, rosteredPosition: { key: 'lineupSlotId', manualParse: function manualParse(responseData) { return lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(_constants__WEBPACK_IMPORTED_MODULE_3__.slotCategoryIdToPositionMap, responseData); } }, totalPoints: 'appliedStatTotal', pointBreakdown: { key: 'stats', manualParse: function manualParse(responseData, data, rawData, constructorParams) { return (0,_player_stats_player_stats__WEBPACK_IMPORTED_MODULE_2__.parsePlayerStats)({ responseData: responseData, constructorParams: constructorParams, usesPoints: true, statKey: 'appliedStats', statSourceId: 0, statSplitTypeId: 1 }); } }, projectedPointBreakdown: { key: 'stats', manualParse: function manualParse(responseData, data, rawData, constructorParams) { return (0,_player_stats_player_stats__WEBPACK_IMPORTED_MODULE_2__.parsePlayerStats)({ responseData: responseData, constructorParams: constructorParams, usesPoints: true, statKey: 'appliedStats', statSourceId: 1, statSplitTypeId: 1 }); } }, rawStats: { key: 'stats', manualParse: function manualParse(responseData, data, rawData, constructorParams) { return (0,_player_stats_player_stats__WEBPACK_IMPORTED_MODULE_2__.parsePlayerStats)({ responseData: responseData, constructorParams: constructorParams, usesPoints: false, statKey: 'stats', statSourceId: 0, statSplitTypeId: 1 }); } }, projectedRawStats: { key: 'stats', manualParse: function manualParse(responseData, data, rawData, constructorParams) { return (0,_player_stats_player_stats__WEBPACK_IMPORTED_MODULE_2__.parsePlayerStats)({ responseData: responseData, constructorParams: constructorParams, usesPoints: false, statKey: 'stats', statSourceId: 1, statSplitTypeId: 1 }); } } }; /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (BoxscorePlayer); /***/ }), /***/ "./src/boxscore/boxscore.js": /*!**********************************!*\ !*** ./src/boxscore/boxscore.js ***! \**********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) /* harmony export */ }); /* harmony import */ var lodash_map__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash/map */ "./node_modules/lodash/map.js"); /* harmony import */ var lodash_map__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_map__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash/get */ "./node_modules/lodash/get.js"); /* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_get__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var _base_classes_base_object_base_object__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../base-classes/base-object/base-object */ "./src/base-classes/base-object/base-object.js"); /* harmony import */ var _boxscore_player_boxscore_player__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../boxscore-player/boxscore-player */ "./src/boxscore-player/boxscore-player.js"); function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Represents a boxscore for a week. * * @augments {BaseObject} */ var Boxscore = /*#__PURE__*/function (_BaseObject) { _inherits(Boxscore, _BaseObject); var _super = _createSuper(Boxscore); function Boxscore() { _classCallCheck(this, Boxscore); return _super.apply(this, arguments); } return _createClass(Boxscore); }(_base_classes_base_object_base_object__WEBPACK_IMPORTED_MODULE_2__["default"]); Boxscore.displayName = 'Boxscore'; /** * @typedef {object} BoxscoreMap * * @property {number} homeScore The total points scored by the home team. * @property {number} homeProjectedScore The projected total points scored by the home team. * NOTE: This field is only populated in the boxscore for the current matchup period! * @property {number} homeTeamId The home team's id. Can be used to load a cached Team. * @property {BoxscorePlayer[]} homeRoster The home team's roster, containing player info and * stats. * * @property {number} awayScore The total points scored by the away team. * @property {number} awayProjectedScore The projected total points scored by the away team. * NOTE: This field is only populated in the boxscore for the current matchup period! * @property {number} awayTeamId The away team's id. Can be used to load a cached Team. * @property {BoxscorePlayer[]} awayRoster The away team's roster, containing player info and * stats. */ /** * @type {BoxscoreMap} */ Boxscore.responseMap = { homeScore: { key: 'home', manualParse: function manualParse(responseData) { return lodash_get__WEBPACK_IMPORTED_MODULE_1___default()(responseData, 'totalPointsLive') || lodash_get__WEBPACK_IMPORTED_MODULE_1___default()(responseData, 'totalPoints'); } }, homeProjectedScore: 'home.totalProjectedPointsLive', homeTeamId: 'home.teamId', homeRoster: { key: 'home.rosterForCurrentScoringPeriod.entries', isArray: true, manualParse: function manualParse(responseData, data, rawData, constructorParams) { return lodash_map__WEBPACK_IMPORTED_MODULE_0___default()(responseData, function (playerData) { return _boxscore_player_boxscore_player__WEBPACK_IMPORTED_MODULE_3__["default"].buildFromServer(playerData, constructorParams); }); } }, awayScore: { key: 'away', manualParse: function manualParse(responseData) { return lodash_get__WEBPACK_IMPORTED_MODULE_1___default()(responseData, 'totalPointsLive') || lodash_get__WEBPACK_IMPORTED_MODULE_1___default()(responseData, 'totalPoints'); } }, awayProjectedScore: 'away.totalProjectedPointsLive', awayTeamId: 'away.teamId', awayRoster: { key: 'away.rosterForCurrentScoringPeriod.entries', isArray: true, manualParse: function manualParse(responseData, data, rawData, constructorParams) { return lodash_map__WEBPACK_IMPORTED_MODULE_0___default()(responseData, function (playerData) { return _boxscore_player_boxscore_player__WEBPACK_IMPORTED_MODULE_3__["default"].buildFromServer(playerData, constructorParams); }); } } }; /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Boxscore); /***/ }), /***/ "./src/client/client.js": /*!******************************!*\ !*** ./src/client/client.js ***! \******************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) /* harmony export */ }); /* harmony import */ var lodash_merge__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash/merge */ "./node_modules/lodash/merge.js"); /* harmony import */ var lodash_merge__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_merge__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var lodash_find__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash/find */ "./node_modules/lodash/find.js"); /* harmony import */ var lodash_find__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_find__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var lodash_map__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! lodash/map */ "./node_modules/lodash/map.js"); /* harmony import */ var lodash_map__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash_map__WEBPACK_IMPORTED_MODULE_2__); /* harmony import */ var lodash_filter__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! lodash/filter */ "./node_modules/lodash/filter.js"); /* harmony import */ var lodash_filter__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(lodash_filter__WEBPACK_IMPORTED_MODULE_3__); /* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! lodash/get */ "./node_modules/lodash/get.js"); /* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(lodash_get__WEBPACK_IMPORTED_MODULE_4__); /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! axios */ "./node_modules/axios/lib/axios.js"); /* harmony import */ var _boxscore_boxscore__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../boxscore/boxscore */ "./src/boxscore/boxscore.js"); /* harmony import */ var _draft_player_draft_player__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../draft-player/draft-player */ "./src/draft-player/draft-player.js"); /* harmony import */ var _free_agent_player_free_agent_player__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../free-agent-player/free-agent-player */ "./src/free-agent-player/free-agent-player.js"); /* harmony import */ var _league_league__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../league/league */ "./src/league/league.js"); /* harmony import */ var _nfl_game_nfl_game__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../nfl-game/nfl-game */ "./src/nfl-game/nfl-game.js"); /* harmony import */ var _team_team__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../team/team */ "./src/team/team.js"); /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../utils */ "./src/utils.js"); function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n