UNPKG

recombee-js-api-client

Version:

Client-side js library for easy use of the Recombee recommendation API

672 lines (617 loc) 210 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["recombee"] = factory(); else root["recombee"] = factory(); })(self, () => { return /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ "./src/api-client.js": /*!***************************!*\ !*** ./src/api-client.js ***! \***************************/ /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; 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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; } function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); } function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var jsSHA = __webpack_require__(/*! jssha */ "./node_modules/.pnpm/jssha@3.3.1/node_modules/jssha/dist/sha.js"); var api_errors = __webpack_require__(/*! ./errors */ "./src/errors/index.js"); /** * Client for sending requests to Recombee and getting replies */ var ApiClient = /*#__PURE__*/function () { /** * Construct the client * @param {string} databaseId - ID of your database * @param {string} publicToken - Corresponding public token * @param {Object} options - Other custom options */ function ApiClient(databaseId, publicToken, options) { _classCallCheck(this, ApiClient); this.databaseId = databaseId; this.publicToken = publicToken; this.options = options || {}; this.baseUri = this._getBaseUri(); this.useHttps = 'useHttps' in this.options ? this.options.useHttps : true; this.async = 'async' in this.options ? this.options.async : true; this.future_v6_fetch = 'future_v6_fetch' in this.options ? this.options.future_v6_fetch : false; } return _createClass(ApiClient, [{ key: "_getRegionalBaseUri", value: function _getRegionalBaseUri(region) { var uri = { 'ap-se': 'client-rapi-ap-se.recombee.com', 'ca-east': 'client-rapi-ca-east.recombee.com', 'eu-west': 'client-rapi-eu-west.recombee.com', 'us-west': 'client-rapi-us-west.recombee.com' }[region.toLowerCase()]; if (uri === undefined) { throw new Error("Region \"".concat(region, "\" is unknown. You may need to update the version of the SDK.")); } return uri; } }, { key: "_getBaseUri", value: function _getBaseUri() { var baseUri = this.options.baseUri; if (this.options.region) { if (baseUri) { throw new Error('baseUri and region cannot be specified at the same time'); } baseUri = this._getRegionalBaseUri(this.options.region); } return baseUri || 'client-rapi.recombee.com'; } /** * Send the request to Recombee * @param {Request} request - Request to be sent * @param {Object} callback - Optional callback (send returns Promise if omitted) */ }, { key: "send", value: function send(request, callback) { if (this.future_v6_fetch) { if (!(typeof globalThis === 'undefined' ? window.Promise : globalThis.Promise)) { throw new Error('future_v6_fetch requires Promises to be available.'); } if (!this.async) { throw new Error('future_v6_fetch cannot be used with synchronous requests.'); } if (callback === undefined) { return this._sendFetch(request); } else { return this._sendFetch(request).then(function (result) { return callback(null, result); })["catch"](callback); } } return this._sendXhr(request, callback); } }, { key: "_sendFetch", value: function () { var _sendFetch2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(request) { var url, response; return _regeneratorRuntime().wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: url = this._getUrl(request); _context.prev = 1; _context.next = 4; return fetch(url, { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify(request.bodyParameters()), signal: AbortSignal.timeout(request.timeout) }); case 4: response = _context.sent; if (!response.ok) { _context.next = 11; break; } _context.next = 8; return response.json(); case 8: return _context.abrupt("return", _context.sent); case 11: _context.t0 = api_errors.ResponseError; _context.t1 = request; _context.t2 = response.status; _context.next = 16; return response.text(); case 16: _context.t3 = _context.sent; throw new _context.t0(_context.t1, _context.t2, _context.t3); case 18: _context.next = 27; break; case 20: _context.prev = 20; _context.t4 = _context["catch"](1); if (!(_context.t4.name === 'TimeoutError')) { _context.next = 26; break; } throw new api_errors.TimeoutError(request); case 26: throw _context.t4; case 27: case "end": return _context.stop(); } }, _callee, this, [[1, 20]]); })); function _sendFetch(_x) { return _sendFetch2.apply(this, arguments); } return _sendFetch; }() }, { key: "_sendXhr", value: function _sendXhr(request, callback) { var Promise = typeof globalThis === 'undefined' ? window.Promise : globalThis.Promise; if (callback === undefined && Promise) { var sendXhr = this._sendXhr.bind(this); return new Promise(function (resolve, reject) { sendXhr(request, function (err, result) { return err ? reject(err) : resolve(result); }); }); } var url = this._getUrl(request); var xmlhttp = new XMLHttpRequest(); xmlhttp.open('POST', url, this.async); xmlhttp.setRequestHeader('Accept', 'application/json'); xmlhttp.setRequestHeader('Content-Type', 'application/json'); if (this.async) xmlhttp.timeout = request.timeout; xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.responseText) { if (this.status == 200) { if (callback) return callback(null, JSON.parse(this.responseText)); } else { if (callback) return callback(new api_errors.ResponseError(request, this.status, this.responseText)); } } }; xmlhttp.ontimeout = function () { if (callback) return callback(new api_errors.TimeoutError(request)); }; xmlhttp.send(JSON.stringify(request.bodyParameters())); } }, { key: "_getUrl", value: function _getUrl(request) { var signedUrl = this._signUrl(request.path); var url = (this.useHttps || request.ensureHttps ? 'https://' : 'http://') + this.baseUri + signedUrl; return url; } }, { key: "_signUrl", value: function _signUrl(req_part) { var url = '/' + this.databaseId + req_part; url += (req_part.indexOf('?') == -1 ? '?' : '&') + 'frontend_timestamp=' + parseInt(new Date().getTime() / 1000); var shaObj = new jsSHA('SHA-1', 'TEXT'); shaObj.setHMACKey(this.publicToken, 'TEXT'); shaObj.update(url); url += '&frontend_sign=' + shaObj.getHMAC('HEX'); return url; } }]); }(); exports.ApiClient = ApiClient; /***/ }), /***/ "./src/errors/api-error.js": /*!*********************************!*\ !*** ./src/errors/api-error.js ***! \*********************************/ /***/ ((__unused_webpack_module, exports) => { "use strict"; //http://stackoverflow.com/questions/31089801/extending-error-in-javascript-with-es6-syntax /** * Base class for errors that occur because of errors in requests reported by API or because of a timeout */ 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(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); } function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } var ApiError = /*#__PURE__*/function (_Error) { function ApiError(message) { var _this; _classCallCheck(this, ApiError); _this = _callSuper(this, ApiError, [message]); _this.name = _this.constructor.name; if (typeof Error.captureStackTrace === 'function') { Error.captureStackTrace(_this, _this.constructor); } else { _this.stack = new Error(message).stack; } return _this; } _inherits(ApiError, _Error); return _createClass(ApiError); }(/*#__PURE__*/_wrapNativeSuper(Error)); exports.ApiError = ApiError; /***/ }), /***/ "./src/errors/index.js": /*!*****************************!*\ !*** ./src/errors/index.js ***! \*****************************/ /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; exports.ApiError = __webpack_require__(/*! ./api-error */ "./src/errors/api-error.js").ApiError; exports.ResponseError = __webpack_require__(/*! ./response-error */ "./src/errors/response-error.js").ResponseError; exports.TimeoutError = __webpack_require__(/*! ./timeout-error */ "./src/errors/timeout-error.js").TimeoutError; /***/ }), /***/ "./src/errors/response-error.js": /*!**************************************!*\ !*** ./src/errors/response-error.js ***! \**************************************/ /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; 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(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } var ae = __webpack_require__(/*! ./api-error */ "./src/errors/api-error.js"); /** * Error thrown when a request did not succeed (did not return 200 or 201) */ var ResponseError = /*#__PURE__*/function (_ae$ApiError) { /** * Create the exception * @param {Request} request - Request which caused the exception * @param {number} statusCode - The returned status code * @param {string} message - Error message from the API */ function ResponseError(request, statusCode, message) { var _this; _classCallCheck(this, ResponseError); _this = _callSuper(this, ResponseError, [message]); _this.request = request; _this.statusCode = statusCode; return _this; } _inherits(ResponseError, _ae$ApiError); return _createClass(ResponseError); }(ae.ApiError); exports.ResponseError = ResponseError; /***/ }), /***/ "./src/errors/timeout-error.js": /*!*************************************!*\ !*** ./src/errors/timeout-error.js ***! \*************************************/ /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; 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(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } var ae = __webpack_require__(/*! ./api-error */ "./src/errors/api-error.js"); /** * Error thrown when a request is not processed within the timeout */ var TimeoutError = /*#__PURE__*/function (_ae$ApiError) { /** * Create the exception * @param {Request} request - Request which caused the exception */ function TimeoutError(request) { var _this; _classCallCheck(this, TimeoutError); _this = _callSuper(this, TimeoutError, ["Client did not get response within ".concat(request.timeout, " ms")]); _this.request = request; return _this; } _inherits(TimeoutError, _ae$ApiError); return _createClass(TimeoutError); }(ae.ApiError); exports.TimeoutError = TimeoutError; /***/ }), /***/ "./src/requests/add-bookmark.js": /*!**************************************!*\ !*** ./src/requests/add-bookmark.js ***! \**************************************/ /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; /* This file is auto-generated, do not edit */ 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(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } var rqs = __webpack_require__(/*! ./request */ "./src/requests/request.js"); /** * Adds a bookmark of the given item made by the given user. */ var AddBookmark = /*#__PURE__*/function (_rqs$Request) { /** * Construct the request * @param {string} userId - User who bookmarked the item * @param {string} itemId - Bookmarked item * @param {Object} optional - Optional parameters given as an object with structure name of the parameter: value * - Allowed parameters: * - *timestamp* * - Type: string | number * - Description: UTC timestamp of the bookmark as ISO8601-1 pattern or UTC epoch time. The default value is the current time. * - *cascadeCreate* * - Type: boolean * - Description: Sets whether the given user/item should be created if not present in the database. * - *recommId* * - Type: string * - Description: If this bookmark is based on a recommendation request, `recommId` is the id of the clicked recommendation. * - *additionalData* * - Type: object * - Description: A dictionary of additional data for the interaction. */ function AddBookmark(userId, itemId, optional) { var _this; _classCallCheck(this, AddBookmark); _this = _callSuper(this, AddBookmark, ['POST', '/bookmarks/', 9000, false]); _this.userId = userId; _this.itemId = itemId; optional = optional || {}; _this.timestamp = optional.timestamp; _this.cascadeCreate = optional.cascadeCreate; _this.recommId = optional.recommId; _this.additionalData = optional.additionalData; return _this; } /** * Get body parameters * @return {Object} The values of body parameters (name of parameter: value of the parameter) */ _inherits(AddBookmark, _rqs$Request); return _createClass(AddBookmark, [{ key: "bodyParameters", value: function bodyParameters() { var params = {}; params.userId = this.userId; params.itemId = this.itemId; if (this.timestamp !== undefined) params.timestamp = this.timestamp; if (this.cascadeCreate !== undefined) params.cascadeCreate = this.cascadeCreate; if (this.recommId !== undefined) params.recommId = this.recommId; if (this.additionalData !== undefined) params.additionalData = this.additionalData; params.cascadeCreate = this.cascadeCreate !== undefined ? this.cascadeCreate : true; return params; } }]); }(rqs.Request); exports.AddBookmark = AddBookmark; /***/ }), /***/ "./src/requests/add-cart-addition.js": /*!*******************************************!*\ !*** ./src/requests/add-cart-addition.js ***! \*******************************************/ /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; /* This file is auto-generated, do not edit */ 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(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } var rqs = __webpack_require__(/*! ./request */ "./src/requests/request.js"); /** * Adds a cart addition of the given item made by the given user. */ var AddCartAddition = /*#__PURE__*/function (_rqs$Request) { /** * Construct the request * @param {string} userId - User who added the item to the cart * @param {string} itemId - Item added to the cart * @param {Object} optional - Optional parameters given as an object with structure name of the parameter: value * - Allowed parameters: * - *timestamp* * - Type: string | number * - Description: UTC timestamp of the cart addition as ISO8601-1 pattern or UTC epoch time. The default value is the current time. * - *cascadeCreate* * - Type: boolean * - Description: Sets whether the given user/item should be created if not present in the database. * - *amount* * - Type: number * - Description: Amount (number) added to cart. The default is 1. For example, if `user-x` adds two `item-y` during a single order (session...), the `amount` should equal 2. * - *price* * - Type: number * - Description: Price of the added item. If `amount` is greater than 1, the sum of prices of all the items should be given. * - *recommId* * - Type: string * - Description: If this cart addition is based on a recommendation request, `recommId` is the id of the clicked recommendation. * - *additionalData* * - Type: object * - Description: A dictionary of additional data for the interaction. */ function AddCartAddition(userId, itemId, optional) { var _this; _classCallCheck(this, AddCartAddition); _this = _callSuper(this, AddCartAddition, ['POST', '/cartadditions/', 9000, false]); _this.userId = userId; _this.itemId = itemId; optional = optional || {}; _this.timestamp = optional.timestamp; _this.cascadeCreate = optional.cascadeCreate; _this.amount = optional.amount; _this.price = optional.price; _this.recommId = optional.recommId; _this.additionalData = optional.additionalData; return _this; } /** * Get body parameters * @return {Object} The values of body parameters (name of parameter: value of the parameter) */ _inherits(AddCartAddition, _rqs$Request); return _createClass(AddCartAddition, [{ key: "bodyParameters", value: function bodyParameters() { var params = {}; params.userId = this.userId; params.itemId = this.itemId; if (this.timestamp !== undefined) params.timestamp = this.timestamp; if (this.cascadeCreate !== undefined) params.cascadeCreate = this.cascadeCreate; if (this.amount !== undefined) params.amount = this.amount; if (this.price !== undefined) params.price = this.price; if (this.recommId !== undefined) params.recommId = this.recommId; if (this.additionalData !== undefined) params.additionalData = this.additionalData; params.cascadeCreate = this.cascadeCreate !== undefined ? this.cascadeCreate : true; return params; } }]); }(rqs.Request); exports.AddCartAddition = AddCartAddition; /***/ }), /***/ "./src/requests/add-detail-view.js": /*!*****************************************!*\ !*** ./src/requests/add-detail-view.js ***! \*****************************************/ /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; /* This file is auto-generated, do not edit */ 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(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } var rqs = __webpack_require__(/*! ./request */ "./src/requests/request.js"); /** * Adds a detail view of the given item made by the given user. */ var AddDetailView = /*#__PURE__*/function (_rqs$Request) { /** * Construct the request * @param {string} userId - User who viewed the item * @param {string} itemId - Viewed item * @param {Object} optional - Optional parameters given as an object with structure name of the parameter: value * - Allowed parameters: * - *timestamp* * - Type: string | number * - Description: UTC timestamp of the view as ISO8601-1 pattern or UTC epoch time. The default value is the current time. * - *duration* * - Type: number * - Description: Duration of the view * - *cascadeCreate* * - Type: boolean * - Description: Sets whether the given user/item should be created if not present in the database. * - *recommId* * - Type: string * - Description: If this detail view is based on a recommendation request, `recommId` is the id of the clicked recommendation. * - *additionalData* * - Type: object * - Description: A dictionary of additional data for the interaction. */ function AddDetailView(userId, itemId, optional) { var _this; _classCallCheck(this, AddDetailView); _this = _callSuper(this, AddDetailView, ['POST', '/detailviews/', 9000, false]); _this.userId = userId; _this.itemId = itemId; optional = optional || {}; _this.timestamp = optional.timestamp; _this.duration = optional.duration; _this.cascadeCreate = optional.cascadeCreate; _this.recommId = optional.recommId; _this.additionalData = optional.additionalData; return _this; } /** * Get body parameters * @return {Object} The values of body parameters (name of parameter: value of the parameter) */ _inherits(AddDetailView, _rqs$Request); return _createClass(AddDetailView, [{ key: "bodyParameters", value: function bodyParameters() { var params = {}; params.userId = this.userId; params.itemId = this.itemId; if (this.timestamp !== undefined) params.timestamp = this.timestamp; if (this.duration !== undefined) params.duration = this.duration; if (this.cascadeCreate !== undefined) params.cascadeCreate = this.cascadeCreate; if (this.recommId !== undefined) params.recommId = this.recommId; if (this.additionalData !== undefined) params.additionalData = this.additionalData; params.cascadeCreate = this.cascadeCreate !== undefined ? this.cascadeCreate : true; return params; } }]); }(rqs.Request); exports.AddDetailView = AddDetailView; /***/ }), /***/ "./src/requests/add-purchase.js": /*!**************************************!*\ !*** ./src/requests/add-purchase.js ***! \**************************************/ /