@magicfeedback/native 1.2.4-beta.8 → 1.2.5-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.magicfeedback=t():e.magicfeedback=t()}(self,(()=>{return e={98:function(e,t){var i="undefined"!=typeof self?self:this,s=function(){function e(){this.fetch=!1,this.DOMException=i.DOMException}return e.prototype=i,new e}();!function(e){!function(t){var i="URLSearchParams"in e,s="Symbol"in e&&"iterator"in Symbol,n="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),r="FormData"in e,a="ArrayBuffer"in e;if(a)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(e){return e&&o.indexOf(Object.prototype.toString.call(e))>-1};function d(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function l(e){return"string"!=typeof e&&(e=String(e)),e}function u(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return s&&(t[Symbol.iterator]=function(){return t}),t}function h(e){this.map={},e instanceof h?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function p(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function f(e){return new Promise((function(t,i){e.onload=function(){t(e.result)},e.onerror=function(){i(e.error)}}))}function m(e){var t=new FileReader,i=f(t);return t.readAsArrayBuffer(e),i}function b(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function g(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:n&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:r&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():a&&n&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=b(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(e)||c(e))?this._bodyArrayBuffer=b(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):i&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},n&&(this.blob=function(){var e=p(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(m)}),this.text=function(){var e,t,i,s=p(this);if(s)return s;if(this._bodyBlob)return e=this._bodyBlob,i=f(t=new FileReader),t.readAsText(e),i;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),i=new Array(t.length),s=0;s<t.length;s++)i[s]=String.fromCharCode(t[s]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},r&&(this.formData=function(){return this.text().then(k)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(e,t){e=d(e),t=l(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},h.prototype.delete=function(e){delete this.map[d(e)]},h.prototype.get=function(e){return e=d(e),this.has(e)?this.map[e]:null},h.prototype.has=function(e){return this.map.hasOwnProperty(d(e))},h.prototype.set=function(e,t){this.map[d(e)]=l(t)},h.prototype.forEach=function(e,t){for(var i in this.map)this.map.hasOwnProperty(i)&&e.call(t,this.map[i],i,this)},h.prototype.keys=function(){var e=[];return this.forEach((function(t,i){e.push(i)})),u(e)},h.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),u(e)},h.prototype.entries=function(){var e=[];return this.forEach((function(t,i){e.push([i,t])})),u(e)},s&&(h.prototype[Symbol.iterator]=h.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var i,s,n=(t=t||{}).body;if(e instanceof v){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new h(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,n||null==e._bodyInit||(n=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new h(t.headers)),this.method=(s=(i=t.method||this.method||"GET").toUpperCase(),y.indexOf(s)>-1?s:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function k(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var i=e.split("="),s=i.shift().replace(/\+/g," "),n=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(s),decodeURIComponent(n))}})),t}function w(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new h(t.headers),this.url=t.url||"",this._initBody(e)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},g.call(v.prototype),g.call(w.prototype),w.prototype.clone=function(){return new w(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},w.error=function(){var e=new w(null,{status:0,statusText:""});return e.type="error",e};var E=[301,302,303,307,308];w.redirect=function(e,t){if(-1===E.indexOf(t))throw new RangeError("Invalid status code");return new w(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var i=Error(e);this.stack=i.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function C(e,i){return new Promise((function(s,r){var a=new v(e,i);if(a.signal&&a.signal.aborted)return r(new t.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function c(){o.abort()}o.onload=function(){var e,t,i={status:o.status,statusText:o.statusText,headers:(e=o.getAllResponseHeaders()||"",t=new h,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var i=e.split(":"),s=i.shift().trim();if(s){var n=i.join(":").trim();t.append(s,n)}})),t)};i.url="responseURL"in o?o.responseURL:i.headers.get("X-Request-URL");var n="response"in o?o.response:o.responseText;s(new w(n,i))},o.onerror=function(){r(new TypeError("Network request failed"))},o.ontimeout=function(){r(new TypeError("Network request failed"))},o.onabort=function(){r(new t.DOMException("Aborted","AbortError"))},o.open(a.method,a.url,!0),"include"===a.credentials?o.withCredentials=!0:"omit"===a.credentials&&(o.withCredentials=!1),"responseType"in o&&n&&(o.responseType="blob"),a.headers.forEach((function(e,t){o.setRequestHeader(t,e)})),a.signal&&(a.signal.addEventListener("abort",c),o.onreadystatechange=function(){4===o.readyState&&a.signal.removeEventListener("abort",c)}),o.send(void 0===a._bodyInit?null:a._bodyInit)}))}C.polyfill=!0,e.fetch||(e.fetch=C,e.Headers=h,e.Request=v,e.Response=w),t.Headers=h,t.Request=v,t.Response=w,t.fetch=C,Object.defineProperty(t,"__esModule",{value:!0})}({})}(s),s.fetch.ponyfill=!0,delete s.fetch.polyfill;var n=s;(t=n.fetch).default=n.fetch,t.fetch=n.fetch,t.Headers=n.Headers,t.Request=n.Request,t.Response=n.Response,e.exports=t},290:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=s(i(519));let r=null;r||(r=(0,n.default)()),t.default=r},519:function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(954),r=i(712),a=i(5),o=i(341),c=i(290);t.default=function(){const e=new r.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?c.HOST_API_URL_DEV:c.HOST_API_URL),t=new a.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,n,r,a=!0,c,d){return s(this,void 0,void 0,(function*(){i||t.err("No appID provided"),n||t.err("No publicKey provided"),r||t.err("No feedback provided"),r.answers||r.profile||r.metrics||r.metadata||t.err("No feedback data provided");const s=e.get("url"),l={integration:i,publicKey:n,privateKey:d,completed:a,id:c,feedback:r};try{const e=yield(0,o.sendFeedback)(s,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,s){return i||t.err("No appID provided"),s||t.err("No publicKey provided"),new n.Form(e,i,s)}}}},712:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const n=i(5),r=i(341),a=i(183);t.Form=class{constructor(e,t,i){this.config=e,this.log=new n.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i,this.url=e.get("url"),this.id="",this.formData=null,this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.questions=[],this.censorQuestions=[],this.elementQuestions=[],this.questionInProcess=null,this.history={},this.progress=0,this.total=0}generate(e,t){return s(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;const i=localStorage.getItem(`magicfeedback-${this.appId}`);if(i&&new Date(JSON.parse(i).savedAt)<new Date((new Date).getTime()+864e5)?(this.formData=JSON.parse(i),(0,r.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,this.formData.questions&&(this.questions=this.formData.questions,this.total=this.questions.length),localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData)),this.generateForm())}))):this.formData=yield(0,r.getForm)(this.url,this.appId,this.publicKey,this.log),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}generateForm(){var e,t,i;try{this.questions.sort(((e,t)=>e.position-t.position));const s=document.getElementById(this.selector);if(!s)throw new Error(`Element with ID '${this.selector}' not found.`);s.classList.add("magicfeedback-container"),s.id="magicfeedback-container-"+this.appId,s.innerHTML="";const n=document.createElement("form");n.classList.add("magicfeedback-form"),n.id="magicfeedback-"+this.appId;const r=document.createElement("div");if(r.classList.add("magicfeedback-questions"),r.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,a.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0]),"MAGICSURVEY"===(null===(t=this.formData)||void 0===t?void 0:t.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,r.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>r.appendChild(e))),n.appendChild(r),s.appendChild(n),this.formOptionsConfig.addButton){const e=(0,a.renderActions)(null===(i=this.formData)||void 0===i?void 0:i.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);n.appendChild(e)}n.addEventListener("submit",(e=>{e.preventDefault(),this.send()}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}getMetaData(){this.feedback.metadata.push({key:"navigator-url",value:[window.location.href]}),this.feedback.metadata.push({key:"navigator-origin",value:[window.location.origin]}),this.feedback.metadata.push({key:"navigator-pathname",value:[window.location.pathname]}),this.feedback.metadata.push({key:"navigator-search",value:[window.location.search]}),this.feedback.metadata.push({key:"navigator-user",value:[navigator.userAgent]}),this.feedback.metadata.push({key:"navigator-language",value:[navigator.language]}),this.feedback.metadata.push({key:"navigator-platform",value:[navigator.platform]}),this.feedback.metadata.push({key:"navigator-appVersion",value:[navigator.appVersion]}),this.feedback.metadata.push({key:"navigator-appName",value:[navigator.appName]}),this.feedback.metadata.push({key:"navigator-product",value:[navigator.product]}),this.feedback.metadata.push({key:"screen-width",value:[window.screen.width.toString()]}),this.feedback.metadata.push({key:"screen-height",value:[window.screen.height.toString()]})}send(e,t,i){var n;return s(this,void 0,void 0,(function*(){const s=document.getElementById("magicfeedback-container-"+this.appId),r=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.answer(),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,answer:this.feedback.answers,progress:this.progress,total:this.total}));const a=yield this.pushAnswers("MAGICSURVEY"!==(null===(n=this.formData)||void 0===n?void 0:n.identity));a&&(this.id=a,yield this.processNextQuestion(s,r)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:a,loading:!1,progress:this.progress,total:this.total,answer:this.feedback.answers,error:a?null:new Error("No response")}))}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress+this.censorQuestions.length,total:this.total-this.censorQuestions.length,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);const t=[];let i=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const s=e.type,n=e.classList[0],a={key:e.name,value:[]},o="magicfeedback-consent"===n?e.checked.toString():e.value;if(a.key&&""!==a.key)switch(s){case"radio":case"checkbox":if("magicfeedback-consent"===n||e.checked){a.value.push(o);const e=t.findIndex((e=>e.key===a.key));-1!==e?t[e].value=[...t[e].value,...a.value]:t.push(a)}break;default:if(""!==o){if("email"===s){if(!(0,r.validateEmail)(o)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[o]})}a.value.push(o);const e=t.findIndex((e=>e.key===a.key));console.log(e,t),-1!==e?t[e].value=[...t[e].value,...a.value]:t.push(a)}}})),this.feedback.answers=i?[]:t}finish(){if(this.formOptionsConfig.addSuccessScreen){const e=document.getElementById("magicfeedback-container-"+this.appId);e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,a.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}this.answer(),this.pushAnswers(!0)}censureQuestions(e){this.censorQuestions=this.questions.filter((t=>e.includes(t.id))).map((e=>e.id))}pushAnswers(e=!1){var t,i;return s(this,void 0,void 0,(function*(){try{if("MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(i=this.questionInProcess)||void 0===i?void 0:i.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const s=this.config.get("url"),n={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,r.sendFeedback)(s,this.id?Object.assign(Object.assign({},n),{sessionId:this.id}):n,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){return s(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const t=this.config.get("url"),i={answer:this.feedback.answers[0].value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,r.getFollowUpQuestion)(t,i,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e,t){var i,n,r,o;return s(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(n=this.questionInProcess)||void 0===n?void 0:n.followup){const e=yield this.callFollowUpQuestion(this.questionInProcess);if(e){this.questionInProcess=e;const i=(0,a.renderQuestions)([e],null===(r=this.formOptionsConfig)||void 0===r?void 0:r.questionFormat,null===(o=this.formData)||void 0===o?void 0:o.lang[0])[0];this.history[this.progress].push({object:e,element:i}),t.removeChild(t.childNodes[0]),t.appendChild(i)}else this.renderNextQuestion(t)}else this.renderNextQuestion(t);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,a.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}}))}renderNextQuestion(e){this.progress++,this.progress<this.total?(this.questionInProcess=this.history[this.progress][0].object,this.censorQuestions.includes(this.questionInProcess.id)?this.renderNextQuestion(e):(e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element))):this.finish()}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e&&e.childNodes.length>0&&e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;let t=this.history[this.progress][this.history[this.progress].length-1];this.censorQuestions.includes(t.object.id)?this.back():(this.questionInProcess=t.object,e.appendChild(t.element))}}},374:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her...";case"ar":return"اكتب إجابتك هنا..."}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her...";case"ar":return"اكتب رقمك هنا..."}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her...";case"ar":return"اكتب بريدك الإلكتروني هنا..."}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her...";case"ar":return"اكتب تاريخك هنا..."}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her...";case"ar":return"اكتب كلمة المرور الخاصة بك هنا..."}}}},183:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const s=i(528);function n(e,t){return"object"==typeof e?e[t]||e.en:e}t.renderQuestions=function e(t,i="standard",r="en"){if(!t)throw new Error("[MagicFeedback] No questions provided");const a=[];return t.forEach((t=>{var o,c;if((null===(c=null===(o=null==t?void 0:t.questionType)||void 0===o?void 0:o.conf)||void 0===c?void 0:c.length)>0){let s=document.createElement("div");s.classList.add("magicfeedback-div"),t.questionType.conf.forEach((e=>e.ref=t.ref)),e(t.questionType.conf,i,r).forEach((e=>{s.appendChild(e)})),a.push(s)}else{const e=function(e,t,i){const{id:r,title:a,type:o,ref:c,require:d,value:l,defaultValue:u,assets:h}=e;let p,f,m=document.createElement("div");m.classList.add("magicfeedback-div");const b="slim"===t?n(a,i):null==h?void 0:h.placeholder;switch(o){case"TEXT":p=document.createElement("input"),p.type="text",p.placeholder=b||s.placeholder.answer(i||"en"),f="magicfeedback-text";break;case"LONGTEXT":p=document.createElement("textarea"),p.rows=3,p.placeholder=b||s.placeholder.answer(i||"en"),f="magicfeedback-longtext";break;case"NUMBER":p=document.createElement("input"),p.type="number",p.placeholder=b||s.placeholder.number(i||"en"),f="magicfeedback-number",l.length&&(l.sort(((e,t)=>Number(e)-Number(t))),p.max=l[l.length-1],p.min=l[0],p.value=l[0]);break;case"RADIO":case"MULTIPLECHOICE":p=document.createElement("div"),f="magicfeedback-"+("MULTIPLECHOICE"===o?"checkbox":"radio"),l.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"MULTIPLECHOICE"===o?"checkbox":"radio"}-container`);const s=document.createElement("label"),n=document.createElement("input");n.id=`rating-${c}-${t}`,n.type="MULTIPLECHOICE"===o?"checkbox":"radio",n.name=c,n.value=e,n.classList.add(f),n.classList.add("magicfeedback-input"),e===u&&(n.checked=!0),s.textContent=e,s.htmlFor=`rating-${c}-${t}`,i.appendChild(n),i.appendChild(s),p.appendChild(i)}));break;case"BOOLEAN":p=document.createElement("div"),f="magicfeedback-radio";const e=document.createElement("div");e.classList.add("magicfeedback-boolean-container"),e.style.display="flex",e.style.flexDirection="row",e.style.justifyContent="space-between",e.style.width="70%",e.style.margin="auto",(h.addIcon?["✓","✗"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];case"ar":return["نعم","لا"];default:return["Yes","No"]}}(i)).forEach(((t,i)=>{const s=document.createElement("label");s.classList.add("magicfeedback-boolean-option"),s.htmlFor=`rating-${c}-${i}`,s.style.cursor="pointer",s.style.border="1px solid #000",s.style.display="flex",s.style.justifyContent="center",s.style.alignItems="center",s.style.margin="auto",s.style.padding="0",s.style.width="45%",s.style.height="38px";const n=document.createElement("label");n.htmlFor=`rating-${c}-${i}`,n.textContent=t,n.style.margin="0",n.style.padding="0";const r=document.createElement("input");r.id=`rating-${c}-${i}`,r.type="radio",r.name=c,r.value=t,r.classList.add(f),r.classList.add("magicfeedback-input"),r.style.position="absolute",r.style.opacity="0",r.style.width="0",r.style.height="0",r.style.margin="0",s.appendChild(r),s.appendChild(n),e.appendChild(s)})),p.appendChild(e);break;case"RATING_EMOJI":p=document.createElement("div"),f="magicfeedback-rating";const g=document.createElement("div");g.classList.add("magicfeedback-rating-container");const y=l.length?Number(l[l.length-1]):5;for(let e=l.length?Number(l[0]):1;e<=y;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-option");const i=document.createElement("label");i.htmlFor=`rating-${c}-${e}`,i.classList.add("magicfeedback-rating-option-label-container");const s=document.createElement("label");s.htmlFor=`rating-${c}-${e}`,s.textContent=e.toString();const n=document.createElement("img");if(5===y)switch(e){case 1:n.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:n.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:n.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:n.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:n.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else n.src=`https://magicfeedback-c6458-dev.web.app/assets/${e}.svg`;n.alt=`face-${c}-${e}`,n.className=`rating-image${e}`;const r=document.createElement("input");r.id=`rating-${c}-${e}`,r.type="radio",r.name=c,r.value=e.toString(),r.classList.add(f),r.classList.add("magicfeedback-input"),i.appendChild(r),i.appendChild(n),i.appendChild(s),t.appendChild(i),g.appendChild(t)}p.appendChild(g);break;case"RATING_NUMBER":p=document.createElement("div"),f="magicfeedback-rating-number";const v=document.createElement("div");v.classList.add("magicfeedback-rating-number-container");const k=l.length?Number(l[l.length-1]):5;for(let e=l.length?Number(l[0]):1;e<=k;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-number-option");const i=document.createElement("label");i.htmlFor=`rating-${c}-${e}`,i.classList.add("magicfeedback-rating-number-option-label-container");const s=document.createElement("label");s.htmlFor=`rating-${c}-${e}`,s.textContent=e.toString();const n=document.createElement("input");n.id=`rating-${c}-${e}`,n.type="radio",n.name=c,n.value=e.toString(),n.classList.add(f),n.classList.add("magicfeedback-input"),i.appendChild(n),i.appendChild(s),t.appendChild(i),v.appendChild(t)}p.appendChild(v);break;case"RATING_STAR":p=document.createElement("div"),f="magicfeedback-rating-star";const w=function(e){const t="magicfeedback-rating-star-selected",i=document.createElement("div");i.classList.add("magicfeedback-rating-star-container");for(let s=1;s<=5;s++){const n=document.createElement("label");n.classList.add("magicfeedback-rating-star-option");const r=document.createElement("input");r.id=`rating-${e}-${s}`,r.type="radio",r.name=e,r.value=s.toString(),r.style.position="absolute",r.style.opacity="0",r.style.width="0",r.style.height="0",r.classList.add("magicfeedback-input"),r.addEventListener("change",(()=>{const e=i.querySelectorAll(".rating__star");for(let i=0;i<e.length;i++)i+1<=Number(r.value)?e[i].classList.contains(t)||e[i].classList.add(t):e[i].classList.contains(t)&&e[i].classList.remove(t)})),n.appendChild(r);const a=document.createElement("label");a.htmlFor=`rating-${e}-${s}`,a.classList.add("rating__star"),a.textContent="★",a.style.fontSize="40px",a.style.color="#CCCCCC",a.style.cursor="pointer",n.appendChild(a),i.appendChild(n)}return i}(c);p.appendChild(w);break;case"MULTIPLECHOISE_IMAGE":p=document.createElement("div"),f="magicfeedback-multiple-choice-image";const E=document.createElement("div");E.classList.add("magicfeedback-multiple-choice-image-container"),E.style.display="flex",E.style.flexDirection="row",E.style.flexWrap="wrap",E.style.justifyContent="center";const C=l.length;let x=1,O=1;switch(C){case 1:case 2:case 3:x=C,O=1;break;case 4:case 5:case 6:O=2,x=Math.ceil(C/2);break;default:O=3,x=Math.ceil(C/3)}console.log(h);const S=void 0!==(null==h?void 0:h.addTitle)&&h.addTitle,L=void 0!==(null==h?void 0:h.multiOption)&&h.multiOption;l.forEach((e=>{try{const{position:t,url:i,value:s}=JSON.parse(e),n=document.createElement("label");n.classList.add("magicfeedback-multiple-choice-image-option"),n.style.width=`calc( ${100/x}% - 10px)`,n.style.height=`calc( ${100/O}% - 10px)`,n.style.margin="5px";const r=document.createElement("label");r.htmlFor=`rating-${c}-${t}`,r.classList.add("magicfeedback-image-option-label-container"),r.style.display="flex",r.style.flexDirection="column",r.addEventListener("mouseover",(()=>{r.style.border="2px solid #000"})),r.addEventListener("mouseout",(()=>{r.style.border="none"})),r.addEventListener("click",(()=>{r.style.border="2px solid #000"}));const a=document.createElement("label");a.textContent=s,a.classList.add("magicfeedback-multiple-choice-image-label");const o=document.createElement("input");o.id=`rating-${c}-${t}`,o.type=L?"checkbox":"radio",o.name=c,o.value=s,o.style.position="absolute",o.style.opacity="0",o.style.width="0",o.style.height="0",o.classList.add("magicfeedback-input");const d=document.createElement("img");d.classList.add("magicfeedback-multiple-choice-image-image"),d.src=i,d.style.cursor="pointer",d.style.backgroundSize="cover",d.style.width="100%",d.style.height="100%",d.style.margin="auto",r.appendChild(o),r.appendChild(d),S&&r.appendChild(a),n.appendChild(r),E.appendChild(n)}catch(e){console.error(e)}})),p.appendChild(E);break;case"SELECT":p=document.createElement("select"),f="magicfeedback-select";const I=document.createElement("option");I.value="",I.text="slim"===t?n(a,i):u||"Select an option",I.disabled=!0,I.selected=!0,p.appendChild(I),l.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,p.appendChild(t)}));break;case"DATE":p=document.createElement("input"),p.type="date",p.required=d,p.placeholder=b||s.placeholder.date(i||"en"),f="magicfeedback-date";break;case"CONSENT":p=document.createElement("input"),f="magicfeedback-consent",p.type="checkbox",p.id=`magicfeedback-${r}`,p.name=c,p.value="true",p.required=d,p.classList.add("magicfeedback-consent"),p.classList.add("magicfeedback-input");break;case"EMAIL":p=document.createElement("input"),p.type="email",p.required=d,p.placeholder=b||"you@example.com",f="magicfeedback-email";break;case"PASSWORD":p=document.createElement("input"),p.type="password",p.required=d,p.placeholder=b||s.placeholder.password(i||"en"),f="magicfeedback-password";break;default:return m}p.id=`magicfeedback-${r}`,p.setAttribute("name",c),p.classList.add(f),void 0!==u&&(p.value=u),["RADIO","MULTIPLECHOICE"].includes(o)||(p.classList.add("magicfeedback-input"),p.required=d);const g=document.createElement("label");if(g.setAttribute("for",`magicfeedback-${r}`),g.textContent=n(a,i),g.classList.add("magicfeedback-label"),["CONSENT"].includes(o))m.classList.add("magicfeedback-consent-container"),m.appendChild(p),m.appendChild(g);else{if("slim"!==t&&(m.appendChild(g),void 0!==(null==h?void 0:h.general)&&""!==(null==h?void 0:h.general))){const e=document.createElement("img");e.src=h.general,e.classList.add("magicfeedback-image"),e.style.maxWidth="auto",e.style.height="400px",e.style.margin="10px 0",m.appendChild(e)}m.appendChild(p)}return m}(t,i,r);a.push(e)}})),a},t.renderActions=function(e="",t,i="Submit",s="Back",n="Next"){const r=document.createElement("div");r.classList.add("magicfeedback-action-container");const a=document.createElement("button");a.id="magicfeedback-submit",a.type="submit",a.classList.add("magicfeedback-submit"),a.textContent="MAGICSURVEY"===e?n||"Next":i||"Submit";const o=document.createElement("button");return o.id="magicfeedback-back",o.type="button",o.classList.add("magicfeedback-back"),o.textContent=s||"Back",o.addEventListener("click",t),"MAGICSURVEY"===e&&r.appendChild(o),r.appendChild(a),r},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t}},341:function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const r=n(i(98)),a=n(i(147)),o=i(374),c={Accept:"application/json","Magicfeedback-Sdk-Version":a.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,n){return s(this,void 0,void 0,(function*(){try{const s=yield(0,r.default)(e+o.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(s.ok){const e=yield s.json();return n.log(`Received form for app ${t}`,e),e}throw n.err(`Failed to get questions for app ${t}:`,s.status,s.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return n.err(e),null}}))},t.getQuestions=function(e,t,i,n){return s(this,void 0,void 0,(function*(){try{const s=yield(0,r.default)(e+o.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(s.ok){const e=yield s.json();return n.log(`Received questions for app ${t}`,e),e}throw n.err(`Failed to get questions for app ${t}:`,s.status,s.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return n.err(e),[]}}))},t.sendFeedback=function(e,t,i){return s(this,void 0,void 0,(function*(){try{const s=yield(0,r.default)(e+o.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(s.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield s.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,s.status,s.statusText),new Error(s.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return s(this,void 0,void 0,(function*(){try{const s=yield(0,r.default)(e+o.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(s.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield s.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,s.status,s.statusText),new Error(s.statusText)}catch(e){return i.err(e),""}}))}},5:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},147:e=>{"use strict";e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.2.4-beta.8","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","publish":"npm publish --access public","publish:beta":"npm publish --access public --tag beta","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"}}')}},t={},function i(s){var n=t[s];if(void 0!==n)return n.exports;var r=t[s]={exports:{}};return e[s].call(r.exports,r,r.exports,i),r.exports}(607).default;var e,t}));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.magicfeedback=t():e.magicfeedback=t()}(self,(()=>{return e={98:function(e,t){var i="undefined"!=typeof self?self:this,s=function(){function e(){this.fetch=!1,this.DOMException=i.DOMException}return e.prototype=i,new e}();!function(e){!function(t){var i="URLSearchParams"in e,s="Symbol"in e&&"iterator"in Symbol,r="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),n="FormData"in e,a="ArrayBuffer"in e;if(a)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(e){return e&&o.indexOf(Object.prototype.toString.call(e))>-1};function d(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function l(e){return"string"!=typeof e&&(e=String(e)),e}function u(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return s&&(t[Symbol.iterator]=function(){return t}),t}function h(e){this.map={},e instanceof h?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function p(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function f(e){return new Promise((function(t,i){e.onload=function(){t(e.result)},e.onerror=function(){i(e.error)}}))}function m(e){var t=new FileReader,i=f(t);return t.readAsArrayBuffer(e),i}function b(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function g(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:r&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:n&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():a&&r&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=b(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(e)||c(e))?this._bodyArrayBuffer=b(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):i&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r&&(this.blob=function(){var e=p(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(m)}),this.text=function(){var e,t,i,s=p(this);if(s)return s;if(this._bodyBlob)return e=this._bodyBlob,i=f(t=new FileReader),t.readAsText(e),i;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),i=new Array(t.length),s=0;s<t.length;s++)i[s]=String.fromCharCode(t[s]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},n&&(this.formData=function(){return this.text().then(k)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(e,t){e=d(e),t=l(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},h.prototype.delete=function(e){delete this.map[d(e)]},h.prototype.get=function(e){return e=d(e),this.has(e)?this.map[e]:null},h.prototype.has=function(e){return this.map.hasOwnProperty(d(e))},h.prototype.set=function(e,t){this.map[d(e)]=l(t)},h.prototype.forEach=function(e,t){for(var i in this.map)this.map.hasOwnProperty(i)&&e.call(t,this.map[i],i,this)},h.prototype.keys=function(){var e=[];return this.forEach((function(t,i){e.push(i)})),u(e)},h.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),u(e)},h.prototype.entries=function(){var e=[];return this.forEach((function(t,i){e.push([i,t])})),u(e)},s&&(h.prototype[Symbol.iterator]=h.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var i,s,r=(t=t||{}).body;if(e instanceof v){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new h(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,r||null==e._bodyInit||(r=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new h(t.headers)),this.method=(s=(i=t.method||this.method||"GET").toUpperCase(),y.indexOf(s)>-1?s:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(r)}function k(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var i=e.split("="),s=i.shift().replace(/\+/g," "),r=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(s),decodeURIComponent(r))}})),t}function w(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new h(t.headers),this.url=t.url||"",this._initBody(e)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},g.call(v.prototype),g.call(w.prototype),w.prototype.clone=function(){return new w(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},w.error=function(){var e=new w(null,{status:0,statusText:""});return e.type="error",e};var E=[301,302,303,307,308];w.redirect=function(e,t){if(-1===E.indexOf(t))throw new RangeError("Invalid status code");return new w(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var i=Error(e);this.stack=i.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function C(e,i){return new Promise((function(s,n){var a=new v(e,i);if(a.signal&&a.signal.aborted)return n(new t.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function c(){o.abort()}o.onload=function(){var e,t,i={status:o.status,statusText:o.statusText,headers:(e=o.getAllResponseHeaders()||"",t=new h,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var i=e.split(":"),s=i.shift().trim();if(s){var r=i.join(":").trim();t.append(s,r)}})),t)};i.url="responseURL"in o?o.responseURL:i.headers.get("X-Request-URL");var r="response"in o?o.response:o.responseText;s(new w(r,i))},o.onerror=function(){n(new TypeError("Network request failed"))},o.ontimeout=function(){n(new TypeError("Network request failed"))},o.onabort=function(){n(new t.DOMException("Aborted","AbortError"))},o.open(a.method,a.url,!0),"include"===a.credentials?o.withCredentials=!0:"omit"===a.credentials&&(o.withCredentials=!1),"responseType"in o&&r&&(o.responseType="blob"),a.headers.forEach((function(e,t){o.setRequestHeader(t,e)})),a.signal&&(a.signal.addEventListener("abort",c),o.onreadystatechange=function(){4===o.readyState&&a.signal.removeEventListener("abort",c)}),o.send(void 0===a._bodyInit?null:a._bodyInit)}))}C.polyfill=!0,e.fetch||(e.fetch=C,e.Headers=h,e.Request=v,e.Response=w),t.Headers=h,t.Request=v,t.Response=w,t.fetch=C,Object.defineProperty(t,"__esModule",{value:!0})}({})}(s),s.fetch.ponyfill=!0,delete s.fetch.polyfill;var r=s;(t=r.fetch).default=r.fetch,t.fetch=r.fetch,t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response,e.exports=t},290:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=s(i(519));let n=null;n||(n=(0,r.default)()),t.default=n},519:function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(r,n){function a(e){try{c(s.next(e))}catch(e){n(e)}}function o(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const r=i(954),n=i(712),a=i(5),o=i(341),c=i(290);t.default=function(){const e=new n.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?c.HOST_API_URL_DEV:c.HOST_API_URL),t=new a.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,r,n,a=!0,c,d){return s(this,void 0,void 0,(function*(){i||t.err("No appID provided"),r||t.err("No publicKey provided"),n||t.err("No feedback provided"),n.answers||n.profile||n.metrics||n.metadata||t.err("No feedback data provided");const s=e.get("url"),l={integration:i,publicKey:r,privateKey:d,completed:a,id:c,feedback:n};try{const e=yield(0,o.sendFeedback)(s,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,s){return i||t.err("No appID provided"),s||t.err("No publicKey provided"),new r.Form(e,i,s)}}}},712:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(r,n){function a(e){try{c(s.next(e))}catch(e){n(e)}}function o(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const r=i(5),n=i(341),a=i(183);t.Form=class{constructor(e,t,i){this.config=e,this.log=new r.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i,this.url=e.get("url"),this.id="",this.formData=null,this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.questions=[],this.elementQuestions=[],this.questionInProcess=null,this.history={},this.progress=0,this.total=0}generate(e,t){return s(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;const i=localStorage.getItem(`magicfeedback-${this.appId}`);if(i&&new Date(JSON.parse(i).savedAt)<new Date((new Date).getTime()+864e5)?(this.formData=JSON.parse(i),(0,n.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,this.formData.questions&&(this.questions=this.formData.questions,this.total=this.questions.length),localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData)),this.generateForm())}))):this.formData=yield(0,n.getForm)(this.url,this.appId,this.publicKey,this.log),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}generateForm(){var e,t,i;try{this.questions.sort(((e,t)=>e.position-t.position));let s=document.getElementById(this.selector);if(!s&&(s=document.getElementById("magicfeedback-container-"+this.appId),!s))throw new Error(`Element with ID '${this.selector}' not found.`);s.classList.add("magicfeedback-container"),s.id="magicfeedback-container-"+this.appId,s.innerHTML="";const r=document.createElement("form");r.classList.add("magicfeedback-form"),r.id="magicfeedback-"+this.appId;const n=document.createElement("div");if(n.classList.add("magicfeedback-questions"),n.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,a.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0]),"MAGICSURVEY"===(null===(t=this.formData)||void 0===t?void 0:t.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,n.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>n.appendChild(e))),r.appendChild(n),s.appendChild(r),this.formOptionsConfig.addButton){const e=(0,a.renderActions)(null===(i=this.formData)||void 0===i?void 0:i.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);r.appendChild(e)}r.addEventListener("submit",(e=>{e.preventDefault(),this.send()}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}getMetaData(){this.feedback.metadata.push({key:"navigator-url",value:[window.location.href]}),this.feedback.metadata.push({key:"navigator-origin",value:[window.location.origin]}),this.feedback.metadata.push({key:"navigator-pathname",value:[window.location.pathname]}),this.feedback.metadata.push({key:"navigator-search",value:[window.location.search]}),this.feedback.metadata.push({key:"navigator-user",value:[navigator.userAgent]}),this.feedback.metadata.push({key:"navigator-language",value:[navigator.language]}),this.feedback.metadata.push({key:"navigator-platform",value:[navigator.platform]}),this.feedback.metadata.push({key:"navigator-appVersion",value:[navigator.appVersion]}),this.feedback.metadata.push({key:"navigator-appName",value:[navigator.appName]}),this.feedback.metadata.push({key:"navigator-product",value:[navigator.product]}),this.feedback.metadata.push({key:"screen-width",value:[window.screen.width.toString()]}),this.feedback.metadata.push({key:"screen-height",value:[window.screen.height.toString()]})}send(e,t,i){var r;return s(this,void 0,void 0,(function*(){const s=document.getElementById("magicfeedback-container-"+this.appId),n=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,progress:this.progress,total:this.total}));const a=yield this.pushAnswers("MAGICSURVEY"!==(null===(r=this.formData)||void 0===r?void 0:r.identity));a&&(this.id=a,yield this.processNextQuestion(s,n)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:a,loading:!1,progress:this.progress,total:this.total,error:a?null:new Error("No response")}))}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);const t=[];let i=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const s=e.type,r=e.classList[0],a={key:e.name,value:[]},o="magicfeedback-consent"===r?e.checked.toString():e.value;if(a.key&&""!==a.key)switch(s){case"radio":case"checkbox":if("magicfeedback-consent"===r||e.checked){a.value.push(o);const e=t.findIndex((e=>e.key===a.key));-1!==e?t[e].value=[...t[e].value,...a.value]:t.push(a)}break;default:if(""!==o){if("email"===s){if(!(0,n.validateEmail)(o)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[o]})}a.value.push(o);const e=t.findIndex((e=>e.key===a.key));console.log(e,t),-1!==e?t[e].value=[...t[e].value,...a.value]:t.push(a)}}})),this.feedback.answers=i?[]:t}pushAnswers(e=!1){var t,i;return s(this,void 0,void 0,(function*(){try{if(this.answer(),"MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(i=this.questionInProcess)||void 0===i?void 0:i.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const s=this.config.get("url"),r={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,n.sendFeedback)(s,this.id?Object.assign(Object.assign({},r),{sessionId:this.id}):r,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){return s(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const t=this.config.get("url"),i={answer:this.feedback.answers[0].value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,n.getFollowUpQuestion)(t,i,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e,t){var i,r,n,o;return s(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(r=this.questionInProcess)||void 0===r?void 0:r.followup){const i=yield this.callFollowUpQuestion(this.questionInProcess);if(i){this.questionInProcess=i;const e=(0,a.renderQuestions)([i],null===(n=this.formOptionsConfig)||void 0===n?void 0:n.questionFormat,null===(o=this.formData)||void 0===o?void 0:o.lang[0])[0];this.history[this.progress].push({object:i,element:e}),t.removeChild(t.childNodes[0]),t.appendChild(e)}else this.renderNextQuestion(t,e)}else this.renderNextQuestion(t,e);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,a.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}}))}renderNextQuestion(e,t){if(this.progress++,this.progress<this.total)this.questionInProcess=this.history[this.progress][0].object,e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element);else{if(this.formOptionsConfig.addSuccessScreen){t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,a.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");t.appendChild(e)}this.pushAnswers(!0)}}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;const t=this.history[this.progress][this.history[this.progress].length-1];this.questionInProcess=t.object,e.appendChild(t.element)}}},374:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her..."}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her..."}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her..."}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her..."}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her..."}}}},183:(e,t,i)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const s=i(528);function r(e,t){return"object"==typeof e?e[t]||e.en:e}t.renderQuestions=function e(t,i="standard",n="en"){if(!t)throw new Error("[MagicFeedback] No questions provided");const a=[];return t.forEach((t=>{var o,c;if((null===(c=null===(o=null==t?void 0:t.questionType)||void 0===o?void 0:o.conf)||void 0===c?void 0:c.length)>0){let s=document.createElement("div");s.classList.add("magicfeedback-div"),t.questionType.conf.forEach((e=>e.ref=t.ref)),e(t.questionType.conf,i,n).forEach((e=>{s.appendChild(e)})),a.push(s)}else{const e=function(e,t,i){const{id:n,title:a,type:o,ref:c,require:d,value:l,defaultValue:u,assets:h}=e;let p,f,m=document.createElement("div");switch(m.classList.add("magicfeedback-div"),o){case"TEXT":p=document.createElement("input"),p.type="text",p.placeholder="slim"===t?r(a,i):s.placeholder.answer(i||"en"),f="magicfeedback-text";break;case"LONGTEXT":p=document.createElement("textarea"),p.rows=3,p.placeholder="slim"===t?r(a,i):s.placeholder.answer(i||"en"),f="magicfeedback-longtext";break;case"NUMBER":p=document.createElement("input"),p.type="number",p.placeholder="slim"===t?r(a,i):s.placeholder.number(i||"en"),f="magicfeedback-number",l.length&&(l.sort(((e,t)=>Number(e)-Number(t))),p.max=l[l.length-1],p.min=l[0],p.value=l[0]);break;case"RADIO":case"MULTIPLECHOICE":p=document.createElement("div"),f="magicfeedback-"+("MULTIPLECHOICE"===o?"checkbox":"radio"),l.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"MULTIPLECHOICE"===o?"checkbox":"radio"}-container`);const s=document.createElement("label"),r=document.createElement("input");r.id=`rating-${c}-${t}`,r.type="MULTIPLECHOICE"===o?"checkbox":"radio",r.name=c,r.value=e,r.classList.add(f),r.classList.add("magicfeedback-input"),e===u&&(r.checked=!0),s.textContent=e,s.htmlFor=`rating-${c}-${t}`,i.appendChild(r),i.appendChild(s),p.appendChild(i)}));break;case"BOOLEAN":p=document.createElement("div"),f="magicfeedback-radio";const e=document.createElement("div");e.classList.add("magicfeedback-boolean-container"),e.style.display="flex",e.style.flexDirection="row",e.style.justifyContent="space-between",e.style.width="70%",e.style.margin="auto",(h.addIcon?["✓","✗"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];default:return["Yes","No"]}}(i)).forEach(((t,i)=>{const s=document.createElement("label");s.classList.add("magicfeedback-boolean-option"),s.htmlFor=`rating-${c}-${i}`,s.style.cursor="pointer",s.style.border="1px solid #000",s.style.display="flex",s.style.justifyContent="center",s.style.alignItems="center",s.style.margin="auto",s.style.padding="0",s.style.width="45%",s.style.height="38px";const r=document.createElement("label");r.htmlFor=`rating-${c}-${i}`,r.textContent=t,r.style.margin="0",r.style.padding="0";const n=document.createElement("input");n.id=`rating-${c}-${i}`,n.type="radio",n.name=c,n.value=t,n.classList.add(f),n.classList.add("magicfeedback-input"),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.style.margin="0",s.appendChild(n),s.appendChild(r),e.appendChild(s)})),p.appendChild(e);break;case"RATING_EMOJI":p=document.createElement("div"),f="magicfeedback-rating";const b=document.createElement("div");b.classList.add("magicfeedback-rating-container");const g=l.length?Number(l[l.length-1]):5;for(let e=l.length?Number(l[0]):1;e<=g;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-option");const i=document.createElement("label");i.htmlFor=`rating-${c}-${e}`,i.classList.add("magicfeedback-rating-option-label-container");const s=document.createElement("label");s.htmlFor=`rating-${c}-${e}`,s.textContent=e.toString();const r=document.createElement("img");if(5===g)switch(e){case 1:r.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:r.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:r.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:r.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:r.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else r.src=`https://magicfeedback-c6458-dev.web.app/assets/${e}.svg`;r.alt=`face-${c}-${e}`,r.className=`rating-image${e}`;const n=document.createElement("input");n.id=`rating-${c}-${e}`,n.type="radio",n.name=c,n.value=e.toString(),n.classList.add(f),n.classList.add("magicfeedback-input"),i.appendChild(n),i.appendChild(r),i.appendChild(s),t.appendChild(i),b.appendChild(t)}p.appendChild(b);break;case"RATING_NUMBER":p=document.createElement("div"),f="magicfeedback-rating-number";const y=document.createElement("div");y.classList.add("magicfeedback-rating-number-container");const v=l.length?Number(l[l.length-1]):5;for(let e=l.length?Number(l[0]):1;e<=v;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-number-option");const i=document.createElement("label");i.htmlFor=`rating-${c}-${e}`,i.classList.add("magicfeedback-rating-number-option-label-container");const s=document.createElement("label");s.htmlFor=`rating-${c}-${e}`,s.textContent=e.toString();const r=document.createElement("input");r.id=`rating-${c}-${e}`,r.type="radio",r.name=c,r.value=e.toString(),r.classList.add(f),r.classList.add("magicfeedback-input"),i.appendChild(r),i.appendChild(s),t.appendChild(i),y.appendChild(t)}p.appendChild(y);break;case"RATING_STAR":p=document.createElement("div"),f="magicfeedback-rating-star";const k=function(e){const t="magicfeedback-rating-star-selected",i=document.createElement("div");i.classList.add("magicfeedback-rating-star-container");for(let s=1;s<=5;s++){const r=document.createElement("label");r.classList.add("magicfeedback-rating-star-option");const n=document.createElement("input");n.id=`rating-${e}-${s}`,n.type="radio",n.name=e,n.value=s.toString(),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.classList.add("magicfeedback-input"),n.addEventListener("change",(()=>{const e=i.querySelectorAll(".rating__star");for(let i=0;i<e.length;i++)i+1<=Number(n.value)?e[i].classList.contains(t)||e[i].classList.add(t):e[i].classList.contains(t)&&e[i].classList.remove(t)})),r.appendChild(n);const a=document.createElement("label");a.htmlFor=`rating-${e}-${s}`,a.classList.add("rating__star"),a.textContent="★",a.style.fontSize="40px",a.style.color="#CCCCCC",a.style.cursor="pointer",r.appendChild(a),i.appendChild(r)}return i}(c);p.appendChild(k);break;case"MULTIPLECHOISE_IMAGE":p=document.createElement("div"),f="magicfeedback-multiple-choice-image";const w=document.createElement("div");w.classList.add("magicfeedback-multiple-choice-image-container"),w.style.display="flex",w.style.flexDirection="row",w.style.flexWrap="wrap",w.style.justifyContent="center";const E=l.length;let C=1,x=1;switch(E){case 1:case 2:case 3:C=E,x=1;break;case 4:case 5:case 6:x=2,C=Math.ceil(E/2);break;default:x=3,C=Math.ceil(E/3)}const O=void 0!==h.addTitle&&h.addTitle;l.forEach((e=>{try{const{position:t,url:i,value:s}=JSON.parse(e),r=document.createElement("label");r.classList.add("magicfeedback-multiple-choice-image-option"),r.style.width=`calc( ${100/C}% - 10px)`,r.style.height=`calc( ${100/x}% - 10px)`,r.style.margin="5px";const n=document.createElement("label");n.htmlFor=`rating-${c}-${t}`,n.classList.add("magicfeedback-image-option-label-container"),n.style.display="flex",n.style.flexDirection="column",n.addEventListener("mouseover",(()=>{n.style.border="2px solid #000"})),n.addEventListener("mouseout",(()=>{n.style.border="none"})),n.addEventListener("click",(()=>{n.style.border="2px solid #000"}));const a=document.createElement("label");a.textContent=s,a.classList.add("magicfeedback-multiple-choice-image-label");const o=document.createElement("input");o.id=`rating-${c}-${t}`,o.type="radio",o.name=c,o.value=s,o.style.position="absolute",o.style.opacity="0",o.style.width="0",o.style.height="0",o.classList.add("magicfeedback-input");const d=document.createElement("img");d.classList.add("magicfeedback-multiple-choice-image-image"),d.src=i,d.style.cursor="pointer",d.style.backgroundSize="cover",d.style.width="100%",d.style.height="100%",d.style.margin="auto",n.appendChild(o),n.appendChild(d),O&&n.appendChild(a),r.appendChild(n),w.appendChild(r)}catch(e){console.error(e)}})),p.appendChild(w);break;case"SELECT":p=document.createElement("select"),f="magicfeedback-select";const S=document.createElement("option");S.value="",S.text="slim"===t?r(a,i):u||"Select an option",S.disabled=!0,S.selected=!0,p.appendChild(S),l.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,p.appendChild(t)}));break;case"DATE":p=document.createElement("input"),p.type="date",p.required=d,p.placeholder="slim"===t?r(a,i):s.placeholder.date(i||"en"),f="magicfeedback-date";break;case"CONSENT":p=document.createElement("input"),f="magicfeedback-consent",p.type="checkbox",p.id=`magicfeedback-${n}`,p.name=c,p.value="true",p.required=d,p.classList.add("magicfeedback-consent"),p.classList.add("magicfeedback-input");break;case"EMAIL":p=document.createElement("input"),p.type="email",p.required=d,p.placeholder="slim"===t?r(a,i):"you@example.com",f="magicfeedback-email";break;case"PASSWORD":p=document.createElement("input"),p.type="password",p.required=d,p.placeholder="slim"===t?r(a,i):s.placeholder.password(i||"en"),f="magicfeedback-password";break;default:return m}p.id=`magicfeedback-${n}`,p.setAttribute("name",c),p.classList.add(f),void 0!==u&&(p.value=u),["RADIO","MULTIPLECHOICE"].includes(o)||(p.classList.add("magicfeedback-input"),p.required=d);const b=document.createElement("label");if(b.setAttribute("for",`magicfeedback-${n}`),b.textContent=r(a,i),b.classList.add("magicfeedback-label"),["CONSENT"].includes(o))m.classList.add("magicfeedback-consent-container"),m.appendChild(p),m.appendChild(b);else{if("slim"!==t&&(m.appendChild(b),void 0!==(null==h?void 0:h.general)&&""!==(null==h?void 0:h.general))){const e=document.createElement("img");e.src=h.general,e.classList.add("magicfeedback-image"),e.style.maxWidth="auto",e.style.height="400px",e.style.margin="10px 0",m.appendChild(e)}m.appendChild(p)}return m}(t,i,n);a.push(e)}})),a},t.renderActions=function(e="",t,i="Submit",s="Back",r="Next"){const n=document.createElement("div");n.classList.add("magicfeedback-action-container");const a=document.createElement("button");a.id="magicfeedback-submit",a.type="submit",a.classList.add("magicfeedback-submit"),a.textContent="MAGICSURVEY"===e?r||"Next":i||"Submit";const o=document.createElement("button");return o.id="magicfeedback-back",o.type="button",o.classList.add("magicfeedback-back"),o.textContent=s||"Back",o.addEventListener("click",t),"MAGICSURVEY"===e&&n.appendChild(o),n.appendChild(a),n},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t}},341:function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(r,n){function a(e){try{c(s.next(e))}catch(e){n(e)}}function o(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const n=r(i(98)),a=r(i(147)),o=i(374),c={Accept:"application/json","Magicfeedback-Sdk-Version":a.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,r){return s(this,void 0,void 0,(function*(){try{const s=yield(0,n.default)(e+o.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(s.ok){const e=yield s.json();return r.log(`Received form for app ${t}`,e),e}throw r.err(`Failed to get questions for app ${t}:`,s.status,s.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return r.err(e),null}}))},t.getQuestions=function(e,t,i,r){return s(this,void 0,void 0,(function*(){try{const s=yield(0,n.default)(e+o.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(s.ok){const e=yield s.json();return r.log(`Received questions for app ${t}`,e),e}throw r.err(`Failed to get questions for app ${t}:`,s.status,s.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return r.err(e),[]}}))},t.sendFeedback=function(e,t,i){return s(this,void 0,void 0,(function*(){try{const s=yield(0,n.default)(e+o.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(s.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield s.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,s.status,s.statusText),new Error(s.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return s(this,void 0,void 0,(function*(){try{const s=yield(0,n.default)(e+o.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(s.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield s.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,s.status,s.statusText),new Error(s.statusText)}catch(e){return i.err(e),""}}))}},5:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},147:e=>{"use strict";e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.2.5-beta.1","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","publish":"npm publish --access public","publish:beta":"npm publish --access public --tag beta","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"}}')}},t={},function i(s){var r=t[s];if(void 0!==r)return r.exports;var n=t[s]={exports:{}};return e[s].call(n.exports,n,n.exports,i),n.exports}(607).default;var e,t}));
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.magicfeedback=t():e.magicfeedback=t()}(global,(()=>(()=>{"use strict";var e={290:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,i){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=s(i(519));let n=null;n||(n=(0,a.default)()),t.default=n},519:function(e,t,i){var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(a,n){function o(e){try{c(s.next(e))}catch(e){n(e)}}function r(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const a=i(954),n=i(712),o=i(5),r=i(341),c=i(290);t.default=function(){const e=new n.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?c.HOST_API_URL_DEV:c.HOST_API_URL),t=new o.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,a,n,o=!0,c,d){return s(this,void 0,void 0,(function*(){i||t.err("No appID provided"),a||t.err("No publicKey provided"),n||t.err("No feedback provided"),n.answers||n.profile||n.metrics||n.metadata||t.err("No feedback data provided");const s=e.get("url"),l={integration:i,publicKey:a,privateKey:d,completed:o,id:c,feedback:n};try{const e=yield(0,r.sendFeedback)(s,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,s){return i||t.err("No appID provided"),s||t.err("No publicKey provided"),new a.Form(e,i,s)}}}},712:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(a,n){function o(e){try{c(s.next(e))}catch(e){n(e)}}function r(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const a=i(5),n=i(341),o=i(183);t.Form=class{constructor(e,t,i){this.config=e,this.log=new a.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i,this.url=e.get("url"),this.id="",this.formData=null,this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.questions=[],this.censorQuestions=[],this.elementQuestions=[],this.questionInProcess=null,this.history={},this.progress=0,this.total=0}generate(e,t){return s(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;const i=localStorage.getItem(`magicfeedback-${this.appId}`);if(i&&new Date(JSON.parse(i).savedAt)<new Date((new Date).getTime()+864e5)?(this.formData=JSON.parse(i),(0,n.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,this.formData.questions&&(this.questions=this.formData.questions,this.total=this.questions.length),localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData)),this.generateForm())}))):this.formData=yield(0,n.getForm)(this.url,this.appId,this.publicKey,this.log),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}generateForm(){var e,t,i;try{this.questions.sort(((e,t)=>e.position-t.position));const s=document.getElementById(this.selector);if(!s)throw new Error(`Element with ID '${this.selector}' not found.`);s.classList.add("magicfeedback-container"),s.id="magicfeedback-container-"+this.appId,s.innerHTML="";const a=document.createElement("form");a.classList.add("magicfeedback-form"),a.id="magicfeedback-"+this.appId;const n=document.createElement("div");if(n.classList.add("magicfeedback-questions"),n.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,o.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0]),"MAGICSURVEY"===(null===(t=this.formData)||void 0===t?void 0:t.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,n.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>n.appendChild(e))),a.appendChild(n),s.appendChild(a),this.formOptionsConfig.addButton){const e=(0,o.renderActions)(null===(i=this.formData)||void 0===i?void 0:i.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);a.appendChild(e)}a.addEventListener("submit",(e=>{e.preventDefault(),this.send()}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}getMetaData(){this.feedback.metadata.push({key:"navigator-url",value:[window.location.href]}),this.feedback.metadata.push({key:"navigator-origin",value:[window.location.origin]}),this.feedback.metadata.push({key:"navigator-pathname",value:[window.location.pathname]}),this.feedback.metadata.push({key:"navigator-search",value:[window.location.search]}),this.feedback.metadata.push({key:"navigator-user",value:[navigator.userAgent]}),this.feedback.metadata.push({key:"navigator-language",value:[navigator.language]}),this.feedback.metadata.push({key:"navigator-platform",value:[navigator.platform]}),this.feedback.metadata.push({key:"navigator-appVersion",value:[navigator.appVersion]}),this.feedback.metadata.push({key:"navigator-appName",value:[navigator.appName]}),this.feedback.metadata.push({key:"navigator-product",value:[navigator.product]}),this.feedback.metadata.push({key:"screen-width",value:[window.screen.width.toString()]}),this.feedback.metadata.push({key:"screen-height",value:[window.screen.height.toString()]})}send(e,t,i){var a;return s(this,void 0,void 0,(function*(){const s=document.getElementById("magicfeedback-container-"+this.appId),n=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.answer(),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,answer:this.feedback.answers,progress:this.progress,total:this.total}));const o=yield this.pushAnswers("MAGICSURVEY"!==(null===(a=this.formData)||void 0===a?void 0:a.identity));o&&(this.id=o,yield this.processNextQuestion(s,n)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:o,loading:!1,progress:this.progress,total:this.total,answer:this.feedback.answers,error:o?null:new Error("No response")}))}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress+this.censorQuestions.length,total:this.total-this.censorQuestions.length,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);const t=[];let i=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const s=e.type,a=e.classList[0],o={key:e.name,value:[]},r="magicfeedback-consent"===a?e.checked.toString():e.value;if(o.key&&""!==o.key)switch(s){case"radio":case"checkbox":if("magicfeedback-consent"===a||e.checked){o.value.push(r);const e=t.findIndex((e=>e.key===o.key));-1!==e?t[e].value=[...t[e].value,...o.value]:t.push(o)}break;default:if(""!==r){if("email"===s){if(!(0,n.validateEmail)(r)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[r]})}o.value.push(r);const e=t.findIndex((e=>e.key===o.key));console.log(e,t),-1!==e?t[e].value=[...t[e].value,...o.value]:t.push(o)}}})),this.feedback.answers=i?[]:t}finish(){if(this.formOptionsConfig.addSuccessScreen){const e=document.getElementById("magicfeedback-container-"+this.appId);e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}this.answer(),this.pushAnswers(!0)}censureQuestions(e){this.censorQuestions=this.questions.filter((t=>e.includes(t.id))).map((e=>e.id))}pushAnswers(e=!1){var t,i;return s(this,void 0,void 0,(function*(){try{if("MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(i=this.questionInProcess)||void 0===i?void 0:i.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const s=this.config.get("url"),a={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,n.sendFeedback)(s,this.id?Object.assign(Object.assign({},a),{sessionId:this.id}):a,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){return s(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const t=this.config.get("url"),i={answer:this.feedback.answers[0].value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,n.getFollowUpQuestion)(t,i,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e,t){var i,a,n,r;return s(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(a=this.questionInProcess)||void 0===a?void 0:a.followup){const e=yield this.callFollowUpQuestion(this.questionInProcess);if(e){this.questionInProcess=e;const i=(0,o.renderQuestions)([e],null===(n=this.formOptionsConfig)||void 0===n?void 0:n.questionFormat,null===(r=this.formData)||void 0===r?void 0:r.lang[0])[0];this.history[this.progress].push({object:e,element:i}),t.removeChild(t.childNodes[0]),t.appendChild(i)}else this.renderNextQuestion(t)}else this.renderNextQuestion(t);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}}))}renderNextQuestion(e){this.progress++,this.progress<this.total?(this.questionInProcess=this.history[this.progress][0].object,this.censorQuestions.includes(this.questionInProcess.id)?this.renderNextQuestion(e):(e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element))):this.finish()}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e&&e.childNodes.length>0&&e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;let t=this.history[this.progress][this.history[this.progress].length-1];this.censorQuestions.includes(t.object.id)?this.back():(this.questionInProcess=t.object,e.appendChild(t.element))}}},374:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her...";case"ar":return"اكتب إجابتك هنا..."}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her...";case"ar":return"اكتب رقمك هنا..."}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her...";case"ar":return"اكتب بريدك الإلكتروني هنا..."}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her...";case"ar":return"اكتب تاريخك هنا..."}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her...";case"ar":return"اكتب كلمة المرور الخاصة بك هنا..."}}}},183:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const s=i(528);function a(e,t){return"object"==typeof e?e[t]||e.en:e}t.renderQuestions=function e(t,i="standard",n="en"){if(!t)throw new Error("[MagicFeedback] No questions provided");const o=[];return t.forEach((t=>{var r,c;if((null===(c=null===(r=null==t?void 0:t.questionType)||void 0===r?void 0:r.conf)||void 0===c?void 0:c.length)>0){let s=document.createElement("div");s.classList.add("magicfeedback-div"),t.questionType.conf.forEach((e=>e.ref=t.ref)),e(t.questionType.conf,i,n).forEach((e=>{s.appendChild(e)})),o.push(s)}else{const e=function(e,t,i){const{id:n,title:o,type:r,ref:c,require:d,value:l,defaultValue:u,assets:h}=e;let p,m,f=document.createElement("div");f.classList.add("magicfeedback-div");const g="slim"===t?a(o,i):null==h?void 0:h.placeholder;switch(r){case"TEXT":p=document.createElement("input"),p.type="text",p.placeholder=g||s.placeholder.answer(i||"en"),m="magicfeedback-text";break;case"LONGTEXT":p=document.createElement("textarea"),p.rows=3,p.placeholder=g||s.placeholder.answer(i||"en"),m="magicfeedback-longtext";break;case"NUMBER":p=document.createElement("input"),p.type="number",p.placeholder=g||s.placeholder.number(i||"en"),m="magicfeedback-number",l.length&&(l.sort(((e,t)=>Number(e)-Number(t))),p.max=l[l.length-1],p.min=l[0],p.value=l[0]);break;case"RADIO":case"MULTIPLECHOICE":p=document.createElement("div"),m="magicfeedback-"+("MULTIPLECHOICE"===r?"checkbox":"radio"),l.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"MULTIPLECHOICE"===r?"checkbox":"radio"}-container`);const s=document.createElement("label"),a=document.createElement("input");a.id=`rating-${c}-${t}`,a.type="MULTIPLECHOICE"===r?"checkbox":"radio",a.name=c,a.value=e,a.classList.add(m),a.classList.add("magicfeedback-input"),e===u&&(a.checked=!0),s.textContent=e,s.htmlFor=`rating-${c}-${t}`,i.appendChild(a),i.appendChild(s),p.appendChild(i)}));break;case"BOOLEAN":p=document.createElement("div"),m="magicfeedback-radio";const e=document.createElement("div");e.classList.add("magicfeedback-boolean-container"),e.style.display="flex",e.style.flexDirection="row",e.style.justifyContent="space-between",e.style.width="70%",e.style.margin="auto",(h.addIcon?["✓","✗"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];case"ar":return["نعم","لا"];default:return["Yes","No"]}}(i)).forEach(((t,i)=>{const s=document.createElement("label");s.classList.add("magicfeedback-boolean-option"),s.htmlFor=`rating-${c}-${i}`,s.style.cursor="pointer",s.style.border="1px solid #000",s.style.display="flex",s.style.justifyContent="center",s.style.alignItems="center",s.style.margin="auto",s.style.padding="0",s.style.width="45%",s.style.height="38px";const a=document.createElement("label");a.htmlFor=`rating-${c}-${i}`,a.textContent=t,a.style.margin="0",a.style.padding="0";const n=document.createElement("input");n.id=`rating-${c}-${i}`,n.type="radio",n.name=c,n.value=t,n.classList.add(m),n.classList.add("magicfeedback-input"),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.style.margin="0",s.appendChild(n),s.appendChild(a),e.appendChild(s)})),p.appendChild(e);break;case"RATING_EMOJI":p=document.createElement("div"),m="magicfeedback-rating";const b=document.createElement("div");b.classList.add("magicfeedback-rating-container");const v=l.length?Number(l[l.length-1]):5;for(let e=l.length?Number(l[0]):1;e<=v;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-option");const i=document.createElement("label");i.htmlFor=`rating-${c}-${e}`,i.classList.add("magicfeedback-rating-option-label-container");const s=document.createElement("label");s.htmlFor=`rating-${c}-${e}`,s.textContent=e.toString();const a=document.createElement("img");if(5===v)switch(e){case 1:a.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:a.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:a.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:a.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:a.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else a.src=`https://magicfeedback-c6458-dev.web.app/assets/${e}.svg`;a.alt=`face-${c}-${e}`,a.className=`rating-image${e}`;const n=document.createElement("input");n.id=`rating-${c}-${e}`,n.type="radio",n.name=c,n.value=e.toString(),n.classList.add(m),n.classList.add("magicfeedback-input"),i.appendChild(n),i.appendChild(a),i.appendChild(s),t.appendChild(i),b.appendChild(t)}p.appendChild(b);break;case"RATING_NUMBER":p=document.createElement("div"),m="magicfeedback-rating-number";const k=document.createElement("div");k.classList.add("magicfeedback-rating-number-container");const y=l.length?Number(l[l.length-1]):5;for(let e=l.length?Number(l[0]):1;e<=y;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-number-option");const i=document.createElement("label");i.htmlFor=`rating-${c}-${e}`,i.classList.add("magicfeedback-rating-number-option-label-container");const s=document.createElement("label");s.htmlFor=`rating-${c}-${e}`,s.textContent=e.toString();const a=document.createElement("input");a.id=`rating-${c}-${e}`,a.type="radio",a.name=c,a.value=e.toString(),a.classList.add(m),a.classList.add("magicfeedback-input"),i.appendChild(a),i.appendChild(s),t.appendChild(i),k.appendChild(t)}p.appendChild(k);break;case"RATING_STAR":p=document.createElement("div"),m="magicfeedback-rating-star";const w=function(e){const t="magicfeedback-rating-star-selected",i=document.createElement("div");i.classList.add("magicfeedback-rating-star-container");for(let s=1;s<=5;s++){const a=document.createElement("label");a.classList.add("magicfeedback-rating-star-option");const n=document.createElement("input");n.id=`rating-${e}-${s}`,n.type="radio",n.name=e,n.value=s.toString(),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.classList.add("magicfeedback-input"),n.addEventListener("change",(()=>{const e=i.querySelectorAll(".rating__star");for(let i=0;i<e.length;i++)i+1<=Number(n.value)?e[i].classList.contains(t)||e[i].classList.add(t):e[i].classList.contains(t)&&e[i].classList.remove(t)})),a.appendChild(n);const o=document.createElement("label");o.htmlFor=`rating-${e}-${s}`,o.classList.add("rating__star"),o.textContent="★",o.style.fontSize="40px",o.style.color="#CCCCCC",o.style.cursor="pointer",a.appendChild(o),i.appendChild(a)}return i}(c);p.appendChild(w);break;case"MULTIPLECHOISE_IMAGE":p=document.createElement("div"),m="magicfeedback-multiple-choice-image";const E=document.createElement("div");E.classList.add("magicfeedback-multiple-choice-image-container"),E.style.display="flex",E.style.flexDirection="row",E.style.flexWrap="wrap",E.style.justifyContent="center";const C=l.length;let x=1,L=1;switch(C){case 1:case 2:case 3:x=C,L=1;break;case 4:case 5:case 6:L=2,x=Math.ceil(C/2);break;default:L=3,x=Math.ceil(C/3)}console.log(h);const S=void 0!==(null==h?void 0:h.addTitle)&&h.addTitle,I=void 0!==(null==h?void 0:h.multiOption)&&h.multiOption;l.forEach((e=>{try{const{position:t,url:i,value:s}=JSON.parse(e),a=document.createElement("label");a.classList.add("magicfeedback-multiple-choice-image-option"),a.style.width=`calc( ${100/x}% - 10px)`,a.style.height=`calc( ${100/L}% - 10px)`,a.style.margin="5px";const n=document.createElement("label");n.htmlFor=`rating-${c}-${t}`,n.classList.add("magicfeedback-image-option-label-container"),n.style.display="flex",n.style.flexDirection="column",n.addEventListener("mouseover",(()=>{n.style.border="2px solid #000"})),n.addEventListener("mouseout",(()=>{n.style.border="none"})),n.addEventListener("click",(()=>{n.style.border="2px solid #000"}));const o=document.createElement("label");o.textContent=s,o.classList.add("magicfeedback-multiple-choice-image-label");const r=document.createElement("input");r.id=`rating-${c}-${t}`,r.type=I?"checkbox":"radio",r.name=c,r.value=s,r.style.position="absolute",r.style.opacity="0",r.style.width="0",r.style.height="0",r.classList.add("magicfeedback-input");const d=document.createElement("img");d.classList.add("magicfeedback-multiple-choice-image-image"),d.src=i,d.style.cursor="pointer",d.style.backgroundSize="cover",d.style.width="100%",d.style.height="100%",d.style.margin="auto",n.appendChild(r),n.appendChild(d),S&&n.appendChild(o),a.appendChild(n),E.appendChild(a)}catch(e){console.error(e)}})),p.appendChild(E);break;case"SELECT":p=document.createElement("select"),m="magicfeedback-select";const O=document.createElement("option");O.value="",O.text="slim"===t?a(o,i):u||"Select an option",O.disabled=!0,O.selected=!0,p.appendChild(O),l.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,p.appendChild(t)}));break;case"DATE":p=document.createElement("input"),p.type="date",p.required=d,p.placeholder=g||s.placeholder.date(i||"en"),m="magicfeedback-date";break;case"CONSENT":p=document.createElement("input"),m="magicfeedback-consent",p.type="checkbox",p.id=`magicfeedback-${n}`,p.name=c,p.value="true",p.required=d,p.classList.add("magicfeedback-consent"),p.classList.add("magicfeedback-input");break;case"EMAIL":p=document.createElement("input"),p.type="email",p.required=d,p.placeholder=g||"you@example.com",m="magicfeedback-email";break;case"PASSWORD":p=document.createElement("input"),p.type="password",p.required=d,p.placeholder=g||s.placeholder.password(i||"en"),m="magicfeedback-password";break;default:return f}p.id=`magicfeedback-${n}`,p.setAttribute("name",c),p.classList.add(m),void 0!==u&&(p.value=u),["RADIO","MULTIPLECHOICE"].includes(r)||(p.classList.add("magicfeedback-input"),p.required=d);const b=document.createElement("label");if(b.setAttribute("for",`magicfeedback-${n}`),b.textContent=a(o,i),b.classList.add("magicfeedback-label"),["CONSENT"].includes(r))f.classList.add("magicfeedback-consent-container"),f.appendChild(p),f.appendChild(b);else{if("slim"!==t&&(f.appendChild(b),void 0!==(null==h?void 0:h.general)&&""!==(null==h?void 0:h.general))){const e=document.createElement("img");e.src=h.general,e.classList.add("magicfeedback-image"),e.style.maxWidth="auto",e.style.height="400px",e.style.margin="10px 0",f.appendChild(e)}f.appendChild(p)}return f}(t,i,n);o.push(e)}})),o},t.renderActions=function(e="",t,i="Submit",s="Back",a="Next"){const n=document.createElement("div");n.classList.add("magicfeedback-action-container");const o=document.createElement("button");o.id="magicfeedback-submit",o.type="submit",o.classList.add("magicfeedback-submit"),o.textContent="MAGICSURVEY"===e?a||"Next":i||"Submit";const r=document.createElement("button");return r.id="magicfeedback-back",r.type="button",r.classList.add("magicfeedback-back"),r.textContent=s||"Back",r.addEventListener("click",t),"MAGICSURVEY"===e&&n.appendChild(r),n.appendChild(o),n},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t}},341:function(e,t,i){var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(a,n){function o(e){try{c(s.next(e))}catch(e){n(e)}}function r(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}c((s=s.apply(e,t||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const n=a(i(31)),o=a(i(147)),r=i(374),c={Accept:"application/json","Magicfeedback-Sdk-Version":o.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,a){return s(this,void 0,void 0,(function*(){try{const s=yield(0,n.default)(e+r.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(s.ok){const e=yield s.json();return a.log(`Received form for app ${t}`,e),e}throw a.err(`Failed to get questions for app ${t}:`,s.status,s.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return a.err(e),null}}))},t.getQuestions=function(e,t,i,a){return s(this,void 0,void 0,(function*(){try{const s=yield(0,n.default)(e+r.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(s.ok){const e=yield s.json();return a.log(`Received questions for app ${t}`,e),e}throw a.err(`Failed to get questions for app ${t}:`,s.status,s.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return a.err(e),[]}}))},t.sendFeedback=function(e,t,i){return s(this,void 0,void 0,(function*(){try{const s=yield(0,n.default)(e+r.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(s.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield s.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,s.status,s.statusText),new Error(s.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return s(this,void 0,void 0,(function*(){try{const s=yield(0,n.default)(e+r.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(s.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield s.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,s.status,s.statusText),new Error(s.statusText)}catch(e){return i.err(e),""}}))}},5:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},31:e=>{e.exports=require("cross-fetch")},147:e=>{e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.2.4-beta.8","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","publish":"npm publish --access public","publish:beta":"npm publish --access public --tag beta","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"}}')}},t={},i=function i(s){var a=t[s];if(void 0!==a)return a.exports;var n=t[s]={exports:{}};return e[s].call(n.exports,n,n.exports,i),n.exports}(607);return i.default})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.magicfeedback=t():e.magicfeedback=t()}(global,(()=>(()=>{"use strict";var e={290:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,i){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=a(i(519));let n=null;n||(n=(0,s.default)()),t.default=n},519:function(e,t,i){var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function o(e){try{c(a.next(e))}catch(e){n(e)}}function r(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}c((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=i(954),n=i(712),o=i(5),r=i(341),c=i(290);t.default=function(){const e=new n.Config;let t;return{init:function(i){(null==i?void 0:i.debug)&&e.set("debug",null==i?void 0:i.debug),e.set("url",(null==i?void 0:i.env)&&"dev"===(null==i?void 0:i.env)?c.HOST_API_URL_DEV:c.HOST_API_URL),t=new o.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,s,n,o=!0,c,d){return a(this,void 0,void 0,(function*(){i||t.err("No appID provided"),s||t.err("No publicKey provided"),n||t.err("No feedback provided"),n.answers||n.profile||n.metrics||n.metadata||t.err("No feedback data provided");const a=e.get("url"),l={integration:i,publicKey:s,privateKey:d,completed:o,id:c,feedback:n};try{const e=yield(0,r.sendFeedback)(a,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,a){return i||t.err("No appID provided"),a||t.err("No publicKey provided"),new s.Form(e,i,a)}}}},712:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function o(e){try{c(a.next(e))}catch(e){n(e)}}function r(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}c((a=a.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const s=i(5),n=i(341),o=i(183);t.Form=class{constructor(e,t,i){this.config=e,this.log=new s.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i,this.url=e.get("url"),this.id="",this.formData=null,this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.questions=[],this.elementQuestions=[],this.questionInProcess=null,this.history={},this.progress=0,this.total=0}generate(e,t){return a(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;const i=localStorage.getItem(`magicfeedback-${this.appId}`);if(i&&new Date(JSON.parse(i).savedAt)<new Date((new Date).getTime()+864e5)?(this.formData=JSON.parse(i),(0,n.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,this.formData.questions&&(this.questions=this.formData.questions,this.total=this.questions.length),localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData)),this.generateForm())}))):this.formData=yield(0,n.getForm)(this.url,this.appId,this.publicKey,this.log),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}generateForm(){var e,t,i;try{this.questions.sort(((e,t)=>e.position-t.position));let a=document.getElementById(this.selector);if(!a&&(a=document.getElementById("magicfeedback-container-"+this.appId),!a))throw new Error(`Element with ID '${this.selector}' not found.`);a.classList.add("magicfeedback-container"),a.id="magicfeedback-container-"+this.appId,a.innerHTML="";const s=document.createElement("form");s.classList.add("magicfeedback-form"),s.id="magicfeedback-"+this.appId;const n=document.createElement("div");if(n.classList.add("magicfeedback-questions"),n.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,o.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat,null===(e=this.formData)||void 0===e?void 0:e.lang[0]),"MAGICSURVEY"===(null===(t=this.formData)||void 0===t?void 0:t.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,n.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>n.appendChild(e))),s.appendChild(n),a.appendChild(s),this.formOptionsConfig.addButton){const e=(0,o.renderActions)(null===(i=this.formData)||void 0===i?void 0:i.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);s.appendChild(e)}s.addEventListener("submit",(e=>{e.preventDefault(),this.send()}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}getMetaData(){this.feedback.metadata.push({key:"navigator-url",value:[window.location.href]}),this.feedback.metadata.push({key:"navigator-origin",value:[window.location.origin]}),this.feedback.metadata.push({key:"navigator-pathname",value:[window.location.pathname]}),this.feedback.metadata.push({key:"navigator-search",value:[window.location.search]}),this.feedback.metadata.push({key:"navigator-user",value:[navigator.userAgent]}),this.feedback.metadata.push({key:"navigator-language",value:[navigator.language]}),this.feedback.metadata.push({key:"navigator-platform",value:[navigator.platform]}),this.feedback.metadata.push({key:"navigator-appVersion",value:[navigator.appVersion]}),this.feedback.metadata.push({key:"navigator-appName",value:[navigator.appName]}),this.feedback.metadata.push({key:"navigator-product",value:[navigator.product]}),this.feedback.metadata.push({key:"screen-width",value:[window.screen.width.toString()]}),this.feedback.metadata.push({key:"screen-height",value:[window.screen.height.toString()]})}send(e,t,i){var s;return a(this,void 0,void 0,(function*(){const a=document.getElementById("magicfeedback-container-"+this.appId),n=document.getElementById("magicfeedback-questions-"+this.appId);try{i&&(this.feedback.profile=[...this.feedback.profile,...i]),t&&(this.feedback.metrics=[...this.feedback.metrics,...t]),e&&(this.feedback.metadata=[...this.feedback.metadata,...e]),this.formOptionsConfig.beforeSubmitEvent&&(yield this.formOptionsConfig.beforeSubmitEvent({loading:!0,progress:this.progress,total:this.total}));const o=yield this.pushAnswers("MAGICSURVEY"!==(null===(s=this.formData)||void 0===s?void 0:s.identity));o&&(this.id=o,yield this.processNextQuestion(a,n)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:o,loading:!1,progress:this.progress,total:this.total,error:o?null:new Error("No response")}))}catch(e){this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({loading:!1,progress:this.progress,total:this.total,error:e}))}}))}answer(){const e=document.getElementById("magicfeedback-"+this.appId);if(!e)return this.log.err(`Form "${e}" not found.`),void(this.feedback.answers=[]);const t=[];let i=!1;e.querySelectorAll(".magicfeedback-input").forEach((e=>{const a=e.type,s=e.classList[0],o={key:e.name,value:[]},r="magicfeedback-consent"===s?e.checked.toString():e.value;if(o.key&&""!==o.key)switch(a){case"radio":case"checkbox":if("magicfeedback-consent"===s||e.checked){o.value.push(r);const e=t.findIndex((e=>e.key===o.key));-1!==e?t[e].value=[...t[e].value,...o.value]:t.push(o)}break;default:if(""!==r){if("email"===a){if(!(0,n.validateEmail)(r)){this.log.err("Invalid email"),i=!0;break}this.feedback.profile.push({key:"email",value:[r]})}o.value.push(r);const e=t.findIndex((e=>e.key===o.key));console.log(e,t),-1!==e?t[e].value=[...t[e].value,...o.value]:t.push(o)}}})),this.feedback.answers=i?[]:t}pushAnswers(e=!1){var t,i;return a(this,void 0,void 0,(function*(){try{if(this.answer(),"MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(i=this.questionInProcess)||void 0===i?void 0:i.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const a=this.config.get("url"),s={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,n.sendFeedback)(a,this.id?Object.assign(Object.assign({},s),{sessionId:this.id}):s,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){return a(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const t=this.config.get("url"),i={answer:this.feedback.answers[0].value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,n.getFollowUpQuestion)(t,i,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e,t){var i,s,n,r;return a(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(s=this.questionInProcess)||void 0===s?void 0:s.followup){const i=yield this.callFollowUpQuestion(this.questionInProcess);if(i){this.questionInProcess=i;const e=(0,o.renderQuestions)([i],null===(n=this.formOptionsConfig)||void 0===n?void 0:n.questionFormat,null===(r=this.formData)||void 0===r?void 0:r.lang[0])[0];this.history[this.progress].push({object:i,element:e}),t.removeChild(t.childNodes[0]),t.appendChild(e)}else this.renderNextQuestion(t,e)}else this.renderNextQuestion(t,e);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}}))}renderNextQuestion(e,t){if(this.progress++,this.progress<this.total)this.questionInProcess=this.history[this.progress][0].object,e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element);else{if(this.formOptionsConfig.addSuccessScreen){t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,o.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");t.appendChild(e)}this.pushAnswers(!0)}}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;const t=this.history[this.progress][this.history[this.progress].length-1];this.questionInProcess=t.object,e.appendChild(t.element)}}},374:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},528:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.placeholder=void 0,t.placeholder={answer:e=>{switch(e){case"en":default:return"Write your answer here...";case"es":return"Escribe tu respuesta aquí...";case"da":return"Skriv dit svar her...";case"fi":return"Kirjoita vastauksesi tähän...";case"sv":return"Skriv ditt svar här...";case"no":return"Skriv svaret ditt her..."}},number:e=>{switch(e){case"en":default:return"Write your number here...";case"es":return"Escribe tu número aquí...";case"da":return"Skriv dit nummer her...";case"fi":return"Kirjoita numerosi tähän...";case"sv":return"Skriv ditt nummer här...";case"no":return"Skriv nummeret ditt her..."}},email:e=>{switch(e){case"en":default:return"Write your email here...";case"es":return"Escribe tu correo electrónico aquí...";case"da":return"Skriv din e-mail her...";case"fi":return"Kirjoita sähköpostiosoitteesi tähän...";case"sv":return"Skriv din e-post här...";case"no":return"Skriv e-posten din her..."}},date:e=>{switch(e){case"en":default:return"Write your date here...";case"es":return"Escribe tu fecha aquí...";case"da":return"Skriv din dato her...";case"fi":return"Kirjoita päivämääräsi tähän...";case"sv":return"Skriv ditt datum här...";case"no":return"Skriv datoen din her..."}},password:e=>{switch(e){case"en":default:return"Write your password here...";case"es":return"Escribe tu contraseña aquí...";case"da":return"Skriv dit kodeord her...";case"fi":return"Kirjoita salasanasi tähän...";case"sv":return"Skriv ditt lösenord här...";case"no":return"Skriv passordet ditt her..."}}}},183:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0;const a=i(528);function s(e,t){return"object"==typeof e?e[t]||e.en:e}t.renderQuestions=function e(t,i="standard",n="en"){if(!t)throw new Error("[MagicFeedback] No questions provided");const o=[];return t.forEach((t=>{var r,c;if((null===(c=null===(r=null==t?void 0:t.questionType)||void 0===r?void 0:r.conf)||void 0===c?void 0:c.length)>0){let a=document.createElement("div");a.classList.add("magicfeedback-div"),t.questionType.conf.forEach((e=>e.ref=t.ref)),e(t.questionType.conf,i,n).forEach((e=>{a.appendChild(e)})),o.push(a)}else{const e=function(e,t,i){const{id:n,title:o,type:r,ref:c,require:d,value:l,defaultValue:u,assets:h}=e;let p,m,f=document.createElement("div");switch(f.classList.add("magicfeedback-div"),r){case"TEXT":p=document.createElement("input"),p.type="text",p.placeholder="slim"===t?s(o,i):a.placeholder.answer(i||"en"),m="magicfeedback-text";break;case"LONGTEXT":p=document.createElement("textarea"),p.rows=3,p.placeholder="slim"===t?s(o,i):a.placeholder.answer(i||"en"),m="magicfeedback-longtext";break;case"NUMBER":p=document.createElement("input"),p.type="number",p.placeholder="slim"===t?s(o,i):a.placeholder.number(i||"en"),m="magicfeedback-number",l.length&&(l.sort(((e,t)=>Number(e)-Number(t))),p.max=l[l.length-1],p.min=l[0],p.value=l[0]);break;case"RADIO":case"MULTIPLECHOICE":p=document.createElement("div"),m="magicfeedback-"+("MULTIPLECHOICE"===r?"checkbox":"radio"),l.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"MULTIPLECHOICE"===r?"checkbox":"radio"}-container`);const a=document.createElement("label"),s=document.createElement("input");s.id=`rating-${c}-${t}`,s.type="MULTIPLECHOICE"===r?"checkbox":"radio",s.name=c,s.value=e,s.classList.add(m),s.classList.add("magicfeedback-input"),e===u&&(s.checked=!0),a.textContent=e,a.htmlFor=`rating-${c}-${t}`,i.appendChild(s),i.appendChild(a),p.appendChild(i)}));break;case"BOOLEAN":p=document.createElement("div"),m="magicfeedback-radio";const e=document.createElement("div");e.classList.add("magicfeedback-boolean-container"),e.style.display="flex",e.style.flexDirection="row",e.style.justifyContent="space-between",e.style.width="70%",e.style.margin="auto",(h.addIcon?["✓","✗"]:function(e){switch(e){case"es":return["Sí","No"];case"fr":return["Oui","Non"];case"de":return["Ja","Nein"];case"it":return["Sì","No"];case"pt":return["Sim","Não"];case"nl":return["Ja","Nee"];case"pl":return["Tak","Nie"];case"ru":return["Да","Нет"];case"ja":return["はい","いいえ"];case"zh":return["是","不"];case"ko":return["예","아니"];case"da":case"sv":return["Ja","Nej"];case"fi":return["Kyllä","Ei"];case"no":return["Ja","Nei"];default:return["Yes","No"]}}(i)).forEach(((t,i)=>{const a=document.createElement("label");a.classList.add("magicfeedback-boolean-option"),a.htmlFor=`rating-${c}-${i}`,a.style.cursor="pointer",a.style.border="1px solid #000",a.style.display="flex",a.style.justifyContent="center",a.style.alignItems="center",a.style.margin="auto",a.style.padding="0",a.style.width="45%",a.style.height="38px";const s=document.createElement("label");s.htmlFor=`rating-${c}-${i}`,s.textContent=t,s.style.margin="0",s.style.padding="0";const n=document.createElement("input");n.id=`rating-${c}-${i}`,n.type="radio",n.name=c,n.value=t,n.classList.add(m),n.classList.add("magicfeedback-input"),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.style.margin="0",a.appendChild(n),a.appendChild(s),e.appendChild(a)})),p.appendChild(e);break;case"RATING_EMOJI":p=document.createElement("div"),m="magicfeedback-rating";const g=document.createElement("div");g.classList.add("magicfeedback-rating-container");const b=l.length?Number(l[l.length-1]):5;for(let e=l.length?Number(l[0]):1;e<=b;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-option");const i=document.createElement("label");i.htmlFor=`rating-${c}-${e}`,i.classList.add("magicfeedback-rating-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${c}-${e}`,a.textContent=e.toString();const s=document.createElement("img");if(5===b)switch(e){case 1:s.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:s.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:s.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:s.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:s.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else s.src=`https://magicfeedback-c6458-dev.web.app/assets/${e}.svg`;s.alt=`face-${c}-${e}`,s.className=`rating-image${e}`;const n=document.createElement("input");n.id=`rating-${c}-${e}`,n.type="radio",n.name=c,n.value=e.toString(),n.classList.add(m),n.classList.add("magicfeedback-input"),i.appendChild(n),i.appendChild(s),i.appendChild(a),t.appendChild(i),g.appendChild(t)}p.appendChild(g);break;case"RATING_NUMBER":p=document.createElement("div"),m="magicfeedback-rating-number";const v=document.createElement("div");v.classList.add("magicfeedback-rating-number-container");const k=l.length?Number(l[l.length-1]):5;for(let e=l.length?Number(l[0]):1;e<=k;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-number-option");const i=document.createElement("label");i.htmlFor=`rating-${c}-${e}`,i.classList.add("magicfeedback-rating-number-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${c}-${e}`,a.textContent=e.toString();const s=document.createElement("input");s.id=`rating-${c}-${e}`,s.type="radio",s.name=c,s.value=e.toString(),s.classList.add(m),s.classList.add("magicfeedback-input"),i.appendChild(s),i.appendChild(a),t.appendChild(i),v.appendChild(t)}p.appendChild(v);break;case"RATING_STAR":p=document.createElement("div"),m="magicfeedback-rating-star";const y=function(e){const t="magicfeedback-rating-star-selected",i=document.createElement("div");i.classList.add("magicfeedback-rating-star-container");for(let a=1;a<=5;a++){const s=document.createElement("label");s.classList.add("magicfeedback-rating-star-option");const n=document.createElement("input");n.id=`rating-${e}-${a}`,n.type="radio",n.name=e,n.value=a.toString(),n.style.position="absolute",n.style.opacity="0",n.style.width="0",n.style.height="0",n.classList.add("magicfeedback-input"),n.addEventListener("change",(()=>{const e=i.querySelectorAll(".rating__star");for(let i=0;i<e.length;i++)i+1<=Number(n.value)?e[i].classList.contains(t)||e[i].classList.add(t):e[i].classList.contains(t)&&e[i].classList.remove(t)})),s.appendChild(n);const o=document.createElement("label");o.htmlFor=`rating-${e}-${a}`,o.classList.add("rating__star"),o.textContent="★",o.style.fontSize="40px",o.style.color="#CCCCCC",o.style.cursor="pointer",s.appendChild(o),i.appendChild(s)}return i}(c);p.appendChild(y);break;case"MULTIPLECHOISE_IMAGE":p=document.createElement("div"),m="magicfeedback-multiple-choice-image";const E=document.createElement("div");E.classList.add("magicfeedback-multiple-choice-image-container"),E.style.display="flex",E.style.flexDirection="row",E.style.flexWrap="wrap",E.style.justifyContent="center";const w=l.length;let C=1,x=1;switch(w){case 1:case 2:case 3:C=w,x=1;break;case 4:case 5:case 6:x=2,C=Math.ceil(w/2);break;default:x=3,C=Math.ceil(w/3)}const L=void 0!==h.addTitle&&h.addTitle;l.forEach((e=>{try{const{position:t,url:i,value:a}=JSON.parse(e),s=document.createElement("label");s.classList.add("magicfeedback-multiple-choice-image-option"),s.style.width=`calc( ${100/C}% - 10px)`,s.style.height=`calc( ${100/x}% - 10px)`,s.style.margin="5px";const n=document.createElement("label");n.htmlFor=`rating-${c}-${t}`,n.classList.add("magicfeedback-image-option-label-container"),n.style.display="flex",n.style.flexDirection="column",n.addEventListener("mouseover",(()=>{n.style.border="2px solid #000"})),n.addEventListener("mouseout",(()=>{n.style.border="none"})),n.addEventListener("click",(()=>{n.style.border="2px solid #000"}));const o=document.createElement("label");o.textContent=a,o.classList.add("magicfeedback-multiple-choice-image-label");const r=document.createElement("input");r.id=`rating-${c}-${t}`,r.type="radio",r.name=c,r.value=a,r.style.position="absolute",r.style.opacity="0",r.style.width="0",r.style.height="0",r.classList.add("magicfeedback-input");const d=document.createElement("img");d.classList.add("magicfeedback-multiple-choice-image-image"),d.src=i,d.style.cursor="pointer",d.style.backgroundSize="cover",d.style.width="100%",d.style.height="100%",d.style.margin="auto",n.appendChild(r),n.appendChild(d),L&&n.appendChild(o),s.appendChild(n),E.appendChild(s)}catch(e){console.error(e)}})),p.appendChild(E);break;case"SELECT":p=document.createElement("select"),m="magicfeedback-select";const S=document.createElement("option");S.value="",S.text="slim"===t?s(o,i):u||"Select an option",S.disabled=!0,S.selected=!0,p.appendChild(S),l.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,p.appendChild(t)}));break;case"DATE":p=document.createElement("input"),p.type="date",p.required=d,p.placeholder="slim"===t?s(o,i):a.placeholder.date(i||"en"),m="magicfeedback-date";break;case"CONSENT":p=document.createElement("input"),m="magicfeedback-consent",p.type="checkbox",p.id=`magicfeedback-${n}`,p.name=c,p.value="true",p.required=d,p.classList.add("magicfeedback-consent"),p.classList.add("magicfeedback-input");break;case"EMAIL":p=document.createElement("input"),p.type="email",p.required=d,p.placeholder="slim"===t?s(o,i):"you@example.com",m="magicfeedback-email";break;case"PASSWORD":p=document.createElement("input"),p.type="password",p.required=d,p.placeholder="slim"===t?s(o,i):a.placeholder.password(i||"en"),m="magicfeedback-password";break;default:return f}p.id=`magicfeedback-${n}`,p.setAttribute("name",c),p.classList.add(m),void 0!==u&&(p.value=u),["RADIO","MULTIPLECHOICE"].includes(r)||(p.classList.add("magicfeedback-input"),p.required=d);const g=document.createElement("label");if(g.setAttribute("for",`magicfeedback-${n}`),g.textContent=s(o,i),g.classList.add("magicfeedback-label"),["CONSENT"].includes(r))f.classList.add("magicfeedback-consent-container"),f.appendChild(p),f.appendChild(g);else{if("slim"!==t&&(f.appendChild(g),void 0!==(null==h?void 0:h.general)&&""!==(null==h?void 0:h.general))){const e=document.createElement("img");e.src=h.general,e.classList.add("magicfeedback-image"),e.style.maxWidth="auto",e.style.height="400px",e.style.margin="10px 0",f.appendChild(e)}f.appendChild(p)}return f}(t,i,n);o.push(e)}})),o},t.renderActions=function(e="",t,i="Submit",a="Back",s="Next"){const n=document.createElement("div");n.classList.add("magicfeedback-action-container");const o=document.createElement("button");o.id="magicfeedback-submit",o.type="submit",o.classList.add("magicfeedback-submit"),o.textContent="MAGICSURVEY"===e?s||"Next":i||"Submit";const r=document.createElement("button");return r.id="magicfeedback-back",r.type="button",r.classList.add("magicfeedback-back"),r.textContent=a||"Back",r.addEventListener("click",t),"MAGICSURVEY"===e&&n.appendChild(r),n.appendChild(o),n},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t}},341:function(e,t,i){var a=this&&this.__awaiter||function(e,t,i,a){return new(i||(i=Promise))((function(s,n){function o(e){try{c(a.next(e))}catch(e){n(e)}}function r(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,r)}c((a=a.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const n=s(i(31)),o=s(i(147)),r=i(374),c={Accept:"application/json","Magicfeedback-Sdk-Version":o.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,s){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+r.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(a.ok){const e=yield a.json();return s.log(`Received form for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),null}}))},t.getQuestions=function(e,t,i,s){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+r.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(a.ok){const e=yield a.json();return s.log(`Received questions for app ${t}`,e),e}throw s.err(`Failed to get questions for app ${t}:`,a.status,a.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return s.err(e),[]}}))},t.sendFeedback=function(e,t,i){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+r.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(a.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield a.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,a.status,a.statusText),new Error(a.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return a(this,void 0,void 0,(function*(){try{const a=yield(0,n.default)(e+r.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(a.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield a.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,a.status,a.statusText),new Error(a.statusText)}catch(e){return i.err(e),""}}))}},5:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},31:e=>{e.exports=require("cross-fetch")},147:e=>{e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.2.5-beta.1","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","publish":"npm publish --access public","publish:beta":"npm publish --access public --tag beta","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"}}')}},t={},i=function i(a){var s=t[a];if(void 0!==s)return s.exports;var n=t[a]={exports:{}};return e[a].call(n.exports,n,n.exports,i),n.exports}(607);return i.default})()));
@@ -16,7 +16,6 @@ export declare class Form {
16
16
  private readonly feedback;
17
17
  questions: NativeQuestion[];
18
18
  private questionInProcess;
19
- private censorQuestions;
20
19
  private readonly history;
21
20
  private elementQuestions;
22
21
  progress: number;
@@ -60,17 +59,6 @@ export declare class Form {
60
59
  * TODO: Required
61
60
  */
62
61
  answer(): void;
63
- /**
64
- * Finish the form
65
- * @public
66
- */
67
- finish(): void;
68
- /**
69
- * Censure questions form the form
70
- * @param questions
71
- * @public
72
- */
73
- censureQuestions(questions: string[]): void;
74
62
  /**
75
63
  * Send
76
64
  * @param completed
@@ -93,6 +81,7 @@ export declare class Form {
93
81
  /**
94
82
  * Render next question
95
83
  * @param form
84
+ * @param container
96
85
  * @private
97
86
  */
98
87
  private renderNextQuestion;
@@ -1,7 +1,7 @@
1
1
  export declare const placeholder: {
2
- answer: (language: string) => "Write your answer here..." | "Escribe tu respuesta aquí..." | "Skriv dit svar her..." | "Kirjoita vastauksesi tähän..." | "Skriv ditt svar här..." | "Skriv svaret ditt her..." | "اكتب إجابتك هنا...";
3
- number: (language: string) => "Write your number here..." | "Escribe tu número aquí..." | "Skriv dit nummer her..." | "Kirjoita numerosi tähän..." | "Skriv ditt nummer här..." | "Skriv nummeret ditt her..." | "اكتب رقمك هنا...";
4
- email: (language: string) => "Write your email here..." | "Escribe tu correo electrónico aquí..." | "Skriv din e-mail her..." | "Kirjoita sähköpostiosoitteesi tähän..." | "Skriv din e-post här..." | "Skriv e-posten din her..." | "اكتب بريدك الإلكتروني هنا...";
5
- date: (language: string) => "Write your date here..." | "Escribe tu fecha aquí..." | "Skriv din dato her..." | "Kirjoita päivämääräsi tähän..." | "Skriv ditt datum här..." | "Skriv datoen din her..." | "اكتب تاريخك هنا...";
6
- password: (language: string) => "Write your password here..." | "Escribe tu contraseña aquí..." | "Skriv dit kodeord her..." | "Kirjoita salasanasi tähän..." | "Skriv ditt lösenord här..." | "Skriv passordet ditt her..." | "اكتب كلمة المرور الخاصة بك هنا...";
2
+ answer: (language: string) => "Write your answer here..." | "Escribe tu respuesta aquí..." | "Skriv dit svar her..." | "Kirjoita vastauksesi tähän..." | "Skriv ditt svar här..." | "Skriv svaret ditt her...";
3
+ number: (language: string) => "Write your number here..." | "Escribe tu número aquí..." | "Skriv dit nummer her..." | "Kirjoita numerosi tähän..." | "Skriv ditt nummer här..." | "Skriv nummeret ditt her...";
4
+ email: (language: string) => "Write your email here..." | "Escribe tu correo electrónico aquí..." | "Skriv din e-mail her..." | "Kirjoita sähköpostiosoitteesi tähän..." | "Skriv din e-post här..." | "Skriv e-posten din her...";
5
+ date: (language: string) => "Write your date here..." | "Escribe tu fecha aquí..." | "Skriv din dato her..." | "Kirjoita päivämääräsi tähän..." | "Skriv ditt datum här..." | "Skriv datoen din her...";
6
+ password: (language: string) => "Write your password here..." | "Escribe tu contraseña aquí..." | "Skriv dit kodeord her..." | "Kirjoita salasanasi tähän..." | "Skriv ditt lösenord här..." | "Skriv passordet ditt her...";
7
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicfeedback/native",
3
- "version": "1.2.4-beta.8",
3
+ "version": "1.2.5-beta.1",
4
4
  "main": "./dist/magicfeedback-sdk.node.js",
5
5
  "browser": "./dist/magicfeedback-sdk.browser.js",
6
6
  "types": "./dist/types/src/index.d.ts",
@@ -1,6 +0,0 @@
1
- export declare class Config {
2
- private variables;
3
- constructor();
4
- get<T>(key: string): T | undefined;
5
- set<T>(key: string, value: T): void;
6
- }
@@ -1,47 +0,0 @@
1
- import { generateFormOptions, NativeAnswer } from "./types";
2
- import { Config } from "./config";
3
- export declare class Form {
4
- /**
5
- * Attributes
6
- */
7
- private config;
8
- private request;
9
- private log;
10
- private appId;
11
- private publicKey;
12
- /**
13
- *
14
- * @param config
15
- * @param appId
16
- * @param publicKey
17
- */
18
- constructor(config: Config, appId: string, publicKey: string);
19
- /**
20
- * Generate
21
- * TODO: Check if is inside of a <form>
22
- * @param appId
23
- */
24
- generate(selector: string, options?: generateFormOptions): void;
25
- /**
26
- * Create
27
- * @param appId
28
- * @param appQuestions
29
- * @param selector
30
- * @param options
31
- *
32
- * TODO: Add option to generate in <form> or in other <tag>
33
- */
34
- private generateForm;
35
- /**
36
- * Answer
37
- * @param appId
38
- * @returns
39
- * TODO: Required
40
- */
41
- answer(): NativeAnswer[];
42
- /**
43
- * Send
44
- * @returns
45
- */
46
- send(): Promise<Response>;
47
- }
@@ -1,22 +0,0 @@
1
- import { Config } from "./config";
2
- export declare class Log {
3
- /**
4
- * Attributes
5
- */
6
- private config;
7
- /**
8
- *
9
- * @param config
10
- */
11
- constructor(config: Config);
12
- /**
13
- *
14
- * @param args
15
- */
16
- log(...args: any[]): void;
17
- /**
18
- *
19
- * @param args
20
- */
21
- err(...args: any[]): void;
22
- }
@@ -1,24 +0,0 @@
1
- export declare class Request {
2
- /**
3
- * Attributes
4
- */
5
- private headers;
6
- /**
7
- *
8
- */
9
- constructor();
10
- /**
11
- *
12
- * @param url
13
- * @param body
14
- * @returns
15
- */
16
- post(url: string, body: any): Promise<Response>;
17
- /**
18
- *
19
- * @param url
20
- * @param body
21
- * @returns
22
- */
23
- get(url: string, params: any): Promise<any>;
24
- }
@@ -1,54 +0,0 @@
1
- export type Key = string;
2
- export type InitOptions = {
3
- url?: string;
4
- debug?: boolean;
5
- };
6
- export type NativeFeedback = {
7
- appId: string;
8
- answers: NativeFeedbackAnswer[];
9
- profile?: NativeFeedbackProfile;
10
- };
11
- export type NativeFeedbackAnswer = {
12
- id: string;
13
- type?: FEEDBACKAPPANSWERTYPE;
14
- value: string[];
15
- };
16
- export type NativeFeedbackProfile = {
17
- [key: string]: string;
18
- };
19
- export declare enum FEEDBACKAPPANSWERTYPE {
20
- TEXT = "TEXT",
21
- LONGTEXT = "LONGTEXT",
22
- NUMBER = "NUMBER",
23
- RADIO = "RADIO",
24
- MULTIPLECHOICE = "MULTIPLECHOICE",
25
- DATE = "DATE",
26
- BOOLEAN = "BOOLEAN",
27
- SELECT = "SELECT"
28
- }
29
- export type NativeQuestion = {
30
- id: string;
31
- title: string;
32
- type: FEEDBACKAPPANSWERTYPE;
33
- ref: string;
34
- require: boolean;
35
- external_id: string;
36
- value: string[];
37
- defaultValue: string;
38
- appId: string;
39
- };
40
- export type NativeAnswer = {
41
- key: string;
42
- value: string[];
43
- };
44
- export type generateFormOptions = {
45
- addButton?: boolean;
46
- tag?: generateFormOptionsTag;
47
- afterSubmitEvent?: Function;
48
- beforeSubmitEvent?: Function;
49
- };
50
- declare enum generateFormOptionsTag {
51
- FORM = "form",
52
- DIV = "div"
53
- }
54
- export {};