@foxford/foxford-js-sdk
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var e=require('axios');var t=require('axios-retry');function r(e){return e&&'object'==typeof e&&'default'in e?e:{default:e}}var n=r(e);var o=r(t);function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function s(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),e}var c;var u=(function(){var e=function(e){var t=Object.prototype;var r=t.hasOwnProperty;var n;var o="function"==typeof Symbol?Symbol:{};var a=o.iterator||"@@iterator";var i=o.asyncIterator||"@@asyncIterator";var s=o.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=(e,t,r)=>e[t]=r}function u(e,t,r,n){var o=Object.create((t&&t.prototype instanceof y?t:y).prototype);var a=new O(n||[]);return o._invoke=((e,t,r)=>{var n=f;return(o,a)=>{if(n===l)throw new Error("Generator is already running");if(n===d){if("throw"===o)throw a;return U()}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var s=j(i,r);if(s){if(s===v)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===f)throw n=d,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=l;var c=h(e,t,r);if("normal"===c.type){if(n=r.done?d:p,c.arg===v)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=d,r.method="throw",r.arg=c.arg)}}})(e,r,a),o}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var f="suspendedStart";var p="suspendedYield";var l="executing";var d="completed";var v={};function y(){}function m(){}function g(){}var w={};w[a]=function(){return this};var b=Object.getPrototypeOf;var x=b&&b(b(P([])));x&&x!==t&&r.call(x,a)&&(w=x);var k=g.prototype=y.prototype=Object.create(w);function E(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function C(e,t){function n(o,a,i,s){var c=h(e[o],e,a);if("throw"!==c.type){var u=c.arg;var f=u.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((e=>{n("next",e,i,s)}),(e=>{n("throw",e,i,s)})):t.resolve(f).then((e=>{u.value=e,i(u)}),(e=>n("throw",e,i,s)))}s(c.arg)}var o;this._invoke=(e,r)=>{function a(){return new t(((t,o)=>{n(e,r,t,o)}))}return o=o?o.then(a,a):a()}}function j(e,t){var r=e.iterator[t.method];if(r===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=n,j(e,t),"throw"===t.method))return v;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var o=h(r,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,v;var a=o.arg;return a?a.done?(t[e.resultName]=a.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=n),t.delegate=null,v):a:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,v)}function _(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function L(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(_,this),this.reset(!0)}function P(e){if(e){var t=e[a];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function t(){for(;++o<e.length;)if(r.call(e,o))return t.value=e[o],t.done=!1,t;return t.value=n,t.done=!0,t};return i.next=i}}return{next:U}}function U(){return{value:n,done:!0}}return m.prototype=k.constructor=g,g.constructor=m,m.displayName=c(g,s,"GeneratorFunction"),e.isGeneratorFunction=e=>{var t="function"==typeof e&&e.constructor;return!!t&&(t===m||"GeneratorFunction"===(t.displayName||t.name))},e.mark=e=>(Object.setPrototypeOf?Object.setPrototypeOf(e,g):(e.__proto__=g,c(e,s,"GeneratorFunction")),e.prototype=Object.create(k),e),e.awrap=e=>({__await:e}),E(C.prototype),C.prototype[i]=function(){return this},e.AsyncIterator=C,e.async=(t,r,n,o,a)=>{void 0===a&&(a=Promise);var i=new C(u(t,r,n,o),a);return e.isGeneratorFunction(r)?i:i.next().then((e=>e.done?e.value:i.next()))},E(k),c(k,s,"Generator"),k[a]=function(){return this},k.toString=()=>"[object Generator]",e.keys=e=>{var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=P,O.prototype={constructor:O,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=n,this.done=!1,this.delegate=null,this.method="next",this.arg=n,this.tryEntries.forEach(L),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=n)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function o(r,o){return s.type="throw",s.arg=e,t.next=r,o&&(t.method="next",t.arg=n),!!o}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a];var s=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc");var u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?(this.method="next",this.next=a.finallyLoc,v):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),L(r),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:P(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=n),v}},e}((c={exports:{}}).exports);try{regeneratorRuntime=e}catch(t){Function("e","regeneratorRuntime=e")(e)}}(),c.exports);function h(e,t,r,n,o,a,i){try{var s=e[a](i);var c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function f(e){return function(){var t=this,r=arguments;return new Promise(((n,o)=>{var a=e.apply(t,r);function i(e){h(a,n,o,i,s,"next",e)}function s(e){h(a,n,o,i,s,"throw",e)}i(void 0)}))}}var p='https://foxford.ru';function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function d(e){var t=!1;for(var r=0;r<e.length;r++){var n=e.charAt(r);t&&/[a-zA-Z]/.test(n)&&n.toUpperCase()===n?(e=e.substr(0,r)+'-'+e.substr(r),t=!1,r++):t=n.toLowerCase()===n}return e}var v=function e(t){return t?t instanceof Date?t:Array.isArray(t)?t.map((t=>e(t))):"object"==typeof t?((e,t)=>{var r={};var n=Object.keys(e);for(var o=0;o<n.length;o++){var a=n[o];var i=t(a,e[a]);r[i[0]]=i[1]}return r})(t,((r,n)=>{var o=function(){var e=[].map.call(arguments,(e=>e.trim())).filter((e=>e.length)).join('-');return e.length?1===e.length?e:/[_.\- ]+/.test(e)?(e=d(e)).replace(/^[_.\- ]+/,'').toLowerCase().replace(/[_.\- ]+(\w|$)/g,((e,t)=>t.toUpperCase())):e===e.toUpperCase()?e.toLowerCase():e[0]!==e[0].toLowerCase()?e[0].toLowerCase()+e.slice(1):e:''}(r);if(r!==o&&o in t)throw new Error("Camelcased key `"+o+"` would overwrite existing key of the given JSON object");return[o,e(n)]})):t:t};function y(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function m(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((t=>Object.getOwnPropertyDescriptor(e,t).enumerable))),r.push.apply(r,n)}return r}var g=[422,401];var w=n.default.create({timeout:1e4,baseURL:p,withCredentials:!0,xsrfCookieName:'_csrf_token',xsrfHeaderName:'X-CSRF-Token',headers:{'X-Requested-With':'XMLHttpRequest'}});w.interceptors.request.use((e=>{var t,r,o,a;var i='boolean'!=typeof e.camelize||e.camelize;if(e.headers?e.headers['Content-Type']='application/json':e.headers={'Content-Type':'application/json'},e.headers.Referer=(null===(t=window)||void 0===t||null===(r=t.location)||void 0===r?void 0:r.href)||'',e.headers['X-Referer']=(null===(o=window)||void 0===o||null===(a=o.location)||void 0===a?void 0:a.href)||'',e.headers['Referrer-Policy']='no-referrer-when-downgrade',i){var s=n.default.defaults.transformResponse||[];var c=e=>v(e);var u=Array.isArray(s)?[].concat((e=>{if(Array.isArray(e))return l(e)})(h=s)||(e=>{if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)})(h)||((e,t)=>{if(e){if("string"==typeof e)return l(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(e,t):void 0}})(h)||(()=>{throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")})(),[c]):[s,c];e.transformResponse=u}var h;return e})),w.interceptors.response.use((e=>e),(e=>{var t=e.config,r=void 0===t?null:t,n=e.response,o=void 0===n?null:n;if(null===r||null===o)return Promise.reject(e);var a=r;g.includes(o.status)&&(a._retry=!0);var i=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?m(Object(r),!0).forEach((t=>{y(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):m(Object(r)).forEach((t=>{Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({status:o.status,statusText:o.statusText,errorText:e.toString(),headers:o.headers},'object'==typeof o.data?o.data:{data:o.data});return Promise.reject(i)})),o.default(w,{retries:3,retryDelay:o.default.exponentialDelay});var b=function(){function e(t){if(a(this,e),this.id=void 0,this.email=void 0,this.firstName=void 0,this.middleName=void 0,this.lastName=void 0,this.phone=void 0,this.parent=void 0,this.fakeUser=void 0,this.isCustomer=void 0,this.emailConfirmed=void 0,this.fakeEmail=void 0,this.phoneConfirmed=void 0,this.createdAt=void 0,this.recentRegistration=void 0,this.profileEnriched=void 0,this.skype=void 0,this.graduate=void 0,this.type=void 0,this.avatarUrl=void 0,this.bonusAmount=void 0,this.grade=void 0,this.gradeChecked=void 0,this.tags=void 0,this.hasChats=void 0,this.hasReferrals=void 0,this.onboardingFinished=void 0,this.externshipUser=void 0,'object'!=typeof t)throw new Error('data is wrong');this.id=t.id,this.gradeChecked=t.gradeChecked,this.email=t.email||'',this.firstName=t.firstName,this.middleName=t.middleName||'',this.lastName=t.lastName,this.phone=t.phone||'',this.parent=t.parent,this.fakeUser=t.fakeUser,this.isCustomer=t.isCustomer,this.emailConfirmed=t.emailConfirmed,this.fakeEmail=t.fakeEmail,this.phoneConfirmed=t.phoneConfirmed,this.createdAt=t.createdAt||'',this.recentRegistration=t.recentRegistration,this.profileEnriched=t.profileEnriched,this.skype=t.skype||'',this.graduate=t.graduate,this.type=t.type,this.avatarUrl=t.avatarUrl||'',this.bonusAmount=t.bonusAmount,this.grade=t.grade,this.tags=t.tags,this.hasChats=t.hasChats,this.hasReferrals=t.hasReferrals,this.onboardingFinished=t.onboardingFinished,this.externshipUser=t.externshipUser}return s(e,[{key:"isLoggedIn",value:function(){return this.id>0}}]),e}();var x={id:0,gradeChecked:!1,email:'',firstName:'',middleName:'',lastName:'',phone:'',parent:!1,fakeUser:!1,isCustomer:!1,emailConfirmed:!1,fakeEmail:!1,phoneConfirmed:!1,createdAt:'',recentRegistration:!1,profileEnriched:!1,skype:'',graduate:!1,type:'pupil',avatarUrl:'',bonusAmount:0,grade:{id:0,index:0},tags:[],hasChats:!1,hasReferrals:!1,onboardingFinished:!1,externshipUser:!1};var k=function(){function e(){a(this,e)}var t;var r;var n;var o;return s(e,[{key:"getUser",value:(o=f(u.mark((function e(){var t;return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,w.get('/api/user/me').then((e=>e.data));case 3:return t=new b(e.sent),e.abrupt("return",t);case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",new b(x));case 11:case"end":return e.stop()}}),e,null,[[0,8]])}))),function(){return o.apply(this,arguments)})},{key:"createUser",value:e=>new b(e)},{key:"purchases",value:(n=f(u.mark((function e(t){var r,n,o,a;return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:if(n=t.resourceType,!(r=t.resourceId)||'number'==typeof r){e.next=3;break}throw new Error('resourceId must be a number');case 3:if(!n||'string'==typeof n){e.next=5;break}throw new Error('resourceType must be a string');case 5:return o=[],r&&o.push("resource_id=".concat(encodeURIComponent(r))),n&&o.push("resource_type=".concat(encodeURIComponent(n))),a=o.length?"?".concat(o.join('&')):'',e.next=11,w.get("/api/user/purchases".concat(a));case 11:return e.abrupt("return",e.sent.data);case 14:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})},{key:"signIn",value:e=>{var t=e.redirectUrl,r=void 0===t?void 0:t;if(r&&'string'!=typeof r)throw new Error('redirectUrl must be a string');var n="".concat(p,"/user/registration?redirect_url=");r&&(n+=encodeURIComponent(document.location.href)),document.location.href=n}},{key:"signOut",value:(r=f(u.mark((function e(){var t,r,n=arguments;return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:return t=!(n.length>0&&void 0!==n[0])||n[0],e.next=3,w.delete("/user/log_out");case 3:return r=e.sent,t&&window.location.reload(),e.abrupt("return",r);case 6:case"end":return e.stop()}}),e)}))),function(){return r.apply(this,arguments)})},{key:"pushEvent",value:(t=f(u.mark((function e(t){return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:return e.next=2,w.post("/api/user/event",{event:t});case 2:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();var E=function(){function e(){a(this,e)}var t;return s(e,[{key:"checkPromocode",value:(t=f(u.mark((function e(t){return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:return e.next=2,w.get("/api/promo_codes/invite/".concat(t));case 2:return e.abrupt("return",e.sent.data);case 5:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();var C=function(){function e(){a(this,e)}var t;return s(e,[{key:"createLeadRequest",value:function(e,t,r){var n=arguments.length>2&&void 0!==r?r:{};return Object.assign({type:e,agreement:!0,context:t},n)}},{key:"send",value:(t=f(u.mark((function e(t){var r,n=arguments;return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:'',e.next=3,w.post("/api/lead_requests".concat(r),{lead_request:t});case 3:return e.abrupt("return",e.sent.data);case 6:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();var j=function(){function e(){a(this,e)}var t;return s(e,[{key:"addTag",value:(t=f(u.mark((function e(t){return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:return e.next=2,w.post("/api/user/tag?id=".concat(t));case 2:return e.abrupt("return",e.sent.data);case 5:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();var _=function(){function e(){a(this,e)}var t;return s(e,[{key:"createCartItem",value:(e,t)=>({resource_id:e,cart_item_type:t})},{key:"addCartItemToCart",value:(t=f(u.mark((function e(t){return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:return e.next=2,w.post("/api/cart_items",{cart_item:t});case 2:return e.abrupt("return",e.sent.data);case 5:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();var L=function(){function e(){a(this,e)}var t;var r;return s(e,[{key:"getCourse",value:(r=f(u.mark((function e(t){return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:if('number'==typeof t){e.next=2;break}throw new TypeError('id is wrong');case 2:return e.next=4,w.get("/api/courses/".concat(t));case 4:return e.abrupt("return",e.sent.data);case 7:case"end":return e.stop()}}),e)}))),function(e){return r.apply(this,arguments)})},{key:"enrollCourse",value:(t=f(u.mark((function e(t){return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:if('number'==typeof t){e.next=2;break}throw new TypeError('id is wrong');case 2:return e.next=4,w.post("/api/courses/".concat(t,"/users_courses"));case 4:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();var O=function(){function e(){a(this,e)}var t;return s(e,[{key:"getProductPack",value:(t=f(u.mark((function e(t){return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:if('number'==typeof t){e.next=2;break}throw new TypeError('id is wrong');case 2:return e.next=4,w.get("/api/product_packs/".concat(t));case 4:return e.abrupt("return",e.sent.data);case 7:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();var P=function(){function e(t){var r=arguments.length>0&&void 0!==t?t:'latest';a(this,e),this.version=void 0,this.version=r}var t;var r;return s(e,[{key:"create",value:(r=f(u.mark((function e(t){return u.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}throw new Error('You must specify config for creating widgets');case 2:return e.next=4,this.loadAssets();case 4:if(window.FoxfordWidgets){e.next=6;break}throw new Error('FoxfordWidgets not found in global scope');case 6:if('function'==typeof window.FoxfordWidgets.create){e.next=8;break}throw new Error('Not found function create in FoxfordWidgets library');case 8:window.FoxfordWidgets.create(t);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"loadAssets",value:(t=f(u.mark((function e(){var t=this;return u.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.version||(this.version='latest'),e.abrupt("return",new Promise(((e,r)=>{var n="https://dist.ngcdn.ru/libs/foxford-widgets/".concat(t.version,"/foxford-widgets.js");var o=document.createElement('script');o.type='text/javascript',o.async=!0,o.onload=()=>e(!0),o.onerror=e=>r(e),o.src=n,document.body.appendChild(o)})));case 2:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}();var U={host:p,widgetsVersion:'latest'};exports.Foxford=function(){function e(t){var r=arguments.length>0&&void 0!==t?t:U;a(this,e),this.api=void 0,this.user=void 0,this.tag=void 0,this.cart=void 0,this.promo=void 0,this.course=void 0,this.productPack=void 0,this.leadrequest=void 0,this.widgets=void 0,this._config=void 0,this._config=r,this._config.host&&(w.defaults.baseURL=this._config.host),this.user=new k,this.promo=new E,this.tag=new j,this.cart=new _,this.course=new L,this.widgets=new P(r.widgetsVersion),this.productPack=new O,this.leadrequest=new C,this.api=w}return s(e,[{key:"shortURL",value:e=>w.post("/api/short_urls",{link:e}).then((e=>e))}]),e}(); | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var e=require('axios');var t=require('axios-retry');function r(e){return e&&'object'==typeof e&&'default'in e?e:{default:e}}var n=r(e);var a=r(t);function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function s(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),e}var c;var u=(function(){var e=function(e){var t=Object.prototype;var r=t.hasOwnProperty;var n;var a="function"==typeof Symbol?Symbol:{};var o=a.iterator||"@@iterator";var i=a.asyncIterator||"@@asyncIterator";var s=a.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=(e,t,r)=>e[t]=r}function u(e,t,r,n){var a=Object.create((t&&t.prototype instanceof y?t:y).prototype);var o=new O(n||[]);return a._invoke=((e,t,r)=>{var n=f;return(a,o)=>{if(n===l)throw new Error("Generator is already running");if(n===d){if("throw"===a)throw o;return U()}for(r.method=a,r.arg=o;;){var i=r.delegate;if(i){var s=j(i,r);if(s){if(s===v)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===f)throw n=d,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=l;var c=h(e,t,r);if("normal"===c.type){if(n=r.done?d:p,c.arg===v)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=d,r.method="throw",r.arg=c.arg)}}})(e,r,o),a}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var f="suspendedStart";var p="suspendedYield";var l="executing";var d="completed";var v={};function y(){}function m(){}function g(){}var w={};w[o]=function(){return this};var b=Object.getPrototypeOf;var x=b&&b(b(P([])));x&&x!==t&&r.call(x,o)&&(w=x);var k=g.prototype=y.prototype=Object.create(w);function E(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function C(e,t){function n(a,o,i,s){var c=h(e[a],e,o);if("throw"!==c.type){var u=c.arg;var f=u.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((e=>{n("next",e,i,s)}),(e=>{n("throw",e,i,s)})):t.resolve(f).then((e=>{u.value=e,i(u)}),(e=>n("throw",e,i,s)))}s(c.arg)}var a;this._invoke=(e,r)=>{function o(){return new t(((t,a)=>{n(e,r,t,a)}))}return a=a?a.then(o,o):o()}}function j(e,t){var r=e.iterator[t.method];if(r===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=n,j(e,t),"throw"===t.method))return v;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var a=h(r,e.iterator,t.arg);if("throw"===a.type)return t.method="throw",t.arg=a.arg,t.delegate=null,v;var o=a.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=n),t.delegate=null,v):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,v)}function _(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function L(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(_,this),this.reset(!0)}function P(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var a=-1,i=function t(){for(;++a<e.length;)if(r.call(e,a))return t.value=e[a],t.done=!1,t;return t.value=n,t.done=!0,t};return i.next=i}}return{next:U}}function U(){return{value:n,done:!0}}return m.prototype=k.constructor=g,g.constructor=m,m.displayName=c(g,s,"GeneratorFunction"),e.isGeneratorFunction=e=>{var t="function"==typeof e&&e.constructor;return!!t&&(t===m||"GeneratorFunction"===(t.displayName||t.name))},e.mark=e=>(Object.setPrototypeOf?Object.setPrototypeOf(e,g):(e.__proto__=g,c(e,s,"GeneratorFunction")),e.prototype=Object.create(k),e),e.awrap=e=>({__await:e}),E(C.prototype),C.prototype[i]=function(){return this},e.AsyncIterator=C,e.async=(t,r,n,a,o)=>{void 0===o&&(o=Promise);var i=new C(u(t,r,n,a),o);return e.isGeneratorFunction(r)?i:i.next().then((e=>e.done?e.value:i.next()))},E(k),c(k,s,"Generator"),k[o]=function(){return this},k.toString=()=>"[object Generator]",e.keys=e=>{var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=P,O.prototype={constructor:O,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=n,this.done=!1,this.delegate=null,this.method="next",this.arg=n,this.tryEntries.forEach(L),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=n)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function a(r,a){return s.type="throw",s.arg=e,t.next=r,a&&(t.method="next",t.arg=n),!!a}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o];var s=i.completion;if("root"===i.tryLoc)return a("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc");var u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return a(i.catchLoc,!0);if(this.prev<i.finallyLoc)return a(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return a(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return a(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var a=this.tryEntries[n];if(a.tryLoc<=this.prev&&r.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var o=a;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=e,i.arg=t,o?(this.method="next",this.next=o.finallyLoc,v):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),L(r),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;L(r)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:P(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=n),v}},e}((c={exports:{}}).exports);try{regeneratorRuntime=e}catch(t){Function("e","regeneratorRuntime=e")(e)}}(),c.exports);function h(e,t,r,n,a,o,i){try{var s=e[o](i);var c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,a)}function f(e){return function(){var t=this,r=arguments;return new Promise(((n,a)=>{var o=e.apply(t,r);function i(e){h(o,n,a,i,s,"next",e)}function s(e){h(o,n,a,i,s,"throw",e)}i(void 0)}))}}var p='https://foxford.ru';function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function d(e){var t=!1;for(var r=0;r<e.length;r++){var n=e.charAt(r);t&&/[a-zA-Z]/.test(n)&&n.toUpperCase()===n?(e=e.substr(0,r)+'-'+e.substr(r),t=!1,r++):t=n.toLowerCase()===n}return e}var v=function e(t){return t?t instanceof Date?t:Array.isArray(t)?t.map((t=>e(t))):"object"==typeof t?((e,t)=>{var r={};var n=Object.keys(e);for(var a=0;a<n.length;a++){var o=n[a];var i=t(o,e[o]);r[i[0]]=i[1]}return r})(t,((r,n)=>{var a=function(){var e=[].map.call(arguments,(e=>e.trim())).filter((e=>e.length)).join('-');return e.length?1===e.length?e:/[_.\- ]+/.test(e)?(e=d(e)).replace(/^[_.\- ]+/,'').toLowerCase().replace(/[_.\- ]+(\w|$)/g,((e,t)=>t.toUpperCase())):e===e.toUpperCase()?e.toLowerCase():e[0]!==e[0].toLowerCase()?e[0].toLowerCase()+e.slice(1):e:''}(r);if(r!==a&&a in t)throw new Error("Camelcased key `"+a+"` would overwrite existing key of the given JSON object");return[a,e(n)]})):t:t};function y(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function m(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((t=>Object.getOwnPropertyDescriptor(e,t).enumerable))),r.push.apply(r,n)}return r}var g=[422,401];var w=n.default.create({timeout:1e4,baseURL:p,withCredentials:!0,xsrfCookieName:'_csrf_token',xsrfHeaderName:'X-CSRF-Token',headers:{'X-Requested-With':'XMLHttpRequest'}});w.interceptors.request.use((e=>{var t,r;var a='boolean'!=typeof e.camelize||e.camelize;if(e.headers?e.headers['Content-Type']='application/json':e.headers={'Content-Type':'application/json'},e.headers['X-Referer']=(null===(t=window)||void 0===t||null===(r=t.location)||void 0===r?void 0:r.href)||'',e.headers['Referrer-Policy']='no-referrer-when-downgrade',a){var o=n.default.defaults.transformResponse||[];var i=e=>v(e);var s=Array.isArray(o)?[].concat((e=>{if(Array.isArray(e))return l(e)})(c=o)||(e=>{if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)})(c)||((e,t)=>{if(e){if("string"==typeof e)return l(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(e,t):void 0}})(c)||(()=>{throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")})(),[i]):[o,i];e.transformResponse=s}var c;return e})),w.interceptors.response.use((e=>e),(e=>{var t=e.config,r=void 0===t?null:t,n=e.response,a=void 0===n?null:n;if(null===r||null===a)return Promise.reject(e);var o=r;g.includes(a.status)&&(o._retry=!0);var i=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?m(Object(r),!0).forEach((t=>{y(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):m(Object(r)).forEach((t=>{Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({status:a.status,statusText:a.statusText,errorText:e.toString(),headers:a.headers},'object'==typeof a.data?a.data:{data:a.data});return Promise.reject(i)})),a.default(w,{retries:3,retryDelay:a.default.exponentialDelay});var b=function(){function e(t){if(o(this,e),this.id=void 0,this.email=void 0,this.firstName=void 0,this.middleName=void 0,this.lastName=void 0,this.phone=void 0,this.parent=void 0,this.fakeUser=void 0,this.isCustomer=void 0,this.emailConfirmed=void 0,this.fakeEmail=void 0,this.phoneConfirmed=void 0,this.createdAt=void 0,this.recentRegistration=void 0,this.profileEnriched=void 0,this.skype=void 0,this.graduate=void 0,this.type=void 0,this.avatarUrl=void 0,this.bonusAmount=void 0,this.grade=void 0,this.gradeChecked=void 0,this.tags=void 0,this.hasChats=void 0,this.hasReferrals=void 0,this.onboardingFinished=void 0,this.externshipUser=void 0,'object'!=typeof t)throw new Error('data is wrong');this.id=t.id,this.gradeChecked=t.gradeChecked,this.email=t.email||'',this.firstName=t.firstName,this.middleName=t.middleName||'',this.lastName=t.lastName,this.phone=t.phone||'',this.parent=t.parent,this.fakeUser=t.fakeUser,this.isCustomer=t.isCustomer,this.emailConfirmed=t.emailConfirmed,this.fakeEmail=t.fakeEmail,this.phoneConfirmed=t.phoneConfirmed,this.createdAt=t.createdAt||'',this.recentRegistration=t.recentRegistration,this.profileEnriched=t.profileEnriched,this.skype=t.skype||'',this.graduate=t.graduate,this.type=t.type,this.avatarUrl=t.avatarUrl||'',this.bonusAmount=t.bonusAmount,this.grade=t.grade,this.tags=t.tags,this.hasChats=t.hasChats,this.hasReferrals=t.hasReferrals,this.onboardingFinished=t.onboardingFinished,this.externshipUser=t.externshipUser}return s(e,[{key:"isLoggedIn",value:function(){return this.id>0}}]),e}();var x={id:0,gradeChecked:!1,email:'',firstName:'',middleName:'',lastName:'',phone:'',parent:!1,fakeUser:!1,isCustomer:!1,emailConfirmed:!1,fakeEmail:!1,phoneConfirmed:!1,createdAt:'',recentRegistration:!1,profileEnriched:!1,skype:'',graduate:!1,type:'pupil',avatarUrl:'',bonusAmount:0,grade:{id:0,index:0},tags:[],hasChats:!1,hasReferrals:!1,onboardingFinished:!1,externshipUser:!1};var k=function(){function e(){o(this,e)}var t;var r;var n;var a;return s(e,[{key:"getUser",value:(a=f(u.mark((function e(){var t;return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,w.get('/api/user/me').then((e=>e.data));case 3:return t=new b(e.sent),e.abrupt("return",t);case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",new b(x));case 11:case"end":return e.stop()}}),e,null,[[0,8]])}))),function(){return a.apply(this,arguments)})},{key:"createUser",value:e=>new b(e)},{key:"purchases",value:(n=f(u.mark((function e(t){var r,n,a,o;return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:if(n=t.resourceType,!(r=t.resourceId)||'number'==typeof r){e.next=3;break}throw new Error('resourceId must be a number');case 3:if(!n||'string'==typeof n){e.next=5;break}throw new Error('resourceType must be a string');case 5:return a=[],r&&a.push("resource_id=".concat(encodeURIComponent(r))),n&&a.push("resource_type=".concat(encodeURIComponent(n))),o=a.length?"?".concat(a.join('&')):'',e.next=11,w.get("/api/user/purchases".concat(o));case 11:return e.abrupt("return",e.sent.data);case 14:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})},{key:"signIn",value:e=>{var t=e.redirectUrl,r=void 0===t?void 0:t;if(r&&'string'!=typeof r)throw new Error('redirectUrl must be a string');var n="".concat(p,"/user/registration?redirect_url=");r&&(n+=encodeURIComponent(document.location.href)),document.location.href=n}},{key:"signOut",value:(r=f(u.mark((function e(){var t,r,n=arguments;return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:return t=!(n.length>0&&void 0!==n[0])||n[0],e.next=3,w.delete("/user/log_out");case 3:return r=e.sent,t&&window.location.reload(),e.abrupt("return",r);case 6:case"end":return e.stop()}}),e)}))),function(){return r.apply(this,arguments)})},{key:"pushEvent",value:(t=f(u.mark((function e(t){return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:return e.next=2,w.post("/api/user/event",{event:t});case 2:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();var E=function(){function e(){o(this,e)}var t;return s(e,[{key:"checkPromocode",value:(t=f(u.mark((function e(t){return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:return e.next=2,w.get("/api/promo_codes/invite/".concat(t));case 2:return e.abrupt("return",e.sent.data);case 5:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();var C=function(){function e(){o(this,e)}var t;return s(e,[{key:"createLeadRequest",value:function(e,t,r){var n=arguments.length>2&&void 0!==r?r:{};return Object.assign({type:e,agreement:!0,context:t},n)}},{key:"send",value:(t=f(u.mark((function e(t){var r,n=arguments;return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:'',e.next=3,w.post("/api/lead_requests".concat(r),{lead_request:t});case 3:return e.abrupt("return",e.sent.data);case 6:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();var j=function(){function e(){o(this,e)}var t;return s(e,[{key:"addTag",value:(t=f(u.mark((function e(t){return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:return e.next=2,w.post("/api/user/tag?id=".concat(t));case 2:return e.abrupt("return",e.sent.data);case 5:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();var _=function(){function e(){o(this,e)}var t;return s(e,[{key:"createCartItem",value:(e,t)=>({resource_id:e,cart_item_type:t})},{key:"addCartItemToCart",value:(t=f(u.mark((function e(t){return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:return e.next=2,w.post("/api/cart_items",{cart_item:t});case 2:return e.abrupt("return",e.sent.data);case 5:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();var L=function(){function e(){o(this,e)}var t;var r;return s(e,[{key:"getCourse",value:(r=f(u.mark((function e(t){return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:if('number'==typeof t){e.next=2;break}throw new TypeError('id is wrong');case 2:return e.next=4,w.get("/api/courses/".concat(t));case 4:return e.abrupt("return",e.sent.data);case 7:case"end":return e.stop()}}),e)}))),function(e){return r.apply(this,arguments)})},{key:"enrollCourse",value:(t=f(u.mark((function e(t){return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:if('number'==typeof t){e.next=2;break}throw new TypeError('id is wrong');case 2:return e.next=4,w.post("/api/courses/".concat(t,"/users_courses"));case 4:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();var O=function(){function e(){o(this,e)}var t;return s(e,[{key:"getProductPack",value:(t=f(u.mark((function e(t){return u.wrap((e=>{for(;;)switch(e.prev=e.next){case 0:if('number'==typeof t){e.next=2;break}throw new TypeError('id is wrong');case 2:return e.next=4,w.get("/api/product_packs/".concat(t));case 4:return e.abrupt("return",e.sent.data);case 7:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();var P=function(){function e(t){var r=arguments.length>0&&void 0!==t?t:'latest';o(this,e),this.version=void 0,this.version=r}var t;var r;return s(e,[{key:"create",value:(r=f(u.mark((function e(t){return u.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}throw new Error('You must specify config for creating widgets');case 2:return e.next=4,this.loadAssets();case 4:if(window.FoxfordWidgets){e.next=6;break}throw new Error('FoxfordWidgets not found in global scope');case 6:if('function'==typeof window.FoxfordWidgets.create){e.next=8;break}throw new Error('Not found function create in FoxfordWidgets library');case 8:window.FoxfordWidgets.create(t);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"loadAssets",value:(t=f(u.mark((function e(){var t=this;return u.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.version||(this.version='latest'),e.abrupt("return",new Promise(((e,r)=>{var n="https://dist.ngcdn.ru/libs/foxford-widgets/".concat(t.version,"/foxford-widgets.js");var a=document.createElement('script');a.type='text/javascript',a.async=!0,a.onload=()=>e(!0),a.onerror=e=>r(e),a.src=n,document.body.appendChild(a)})));case 2:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}();var U={host:p,widgetsVersion:'latest'};exports.Foxford=function(){function e(t){var r=arguments.length>0&&void 0!==t?t:U;o(this,e),this.api=void 0,this.user=void 0,this.tag=void 0,this.cart=void 0,this.promo=void 0,this.course=void 0,this.productPack=void 0,this.leadrequest=void 0,this.widgets=void 0,this._config=void 0,this._config=r,this._config.host&&(w.defaults.baseURL=this._config.host),this.user=new k,this.promo=new E,this.tag=new j,this.cart=new _,this.course=new L,this.widgets=new P(r.widgetsVersion),this.productPack=new O,this.leadrequest=new C,this.api=w}return s(e,[{key:"shortURL",value:e=>w.post("/api/short_urls",{link:e}).then((e=>e))}]),e}(); | ||
//# sourceMappingURL=foxford.cjs.js.map |
{ | ||
"name": "@foxford/foxford-js-sdk", | ||
"version": "2.1.39", | ||
"version": "2.1.40", | ||
"description": "Foxford sdk for external projects", | ||
@@ -5,0 +5,0 @@ "main": "foxford.cjs.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
259323
-0.17%1077
-0.09%