@magicfeedback/native 1.1.9-beta.1 → 1.1.9

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.
package/README.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # MagicFeedbackAI SDK
2
2
 
3
- MagicFeedback AI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)
3
+ This JavaScript library empowers you to effortlessly integrate the power of [MagicFeedback.io](https://magicfeedback.io/) into your web applications. With minimal code, you can capture valuable user feedback and insights, driving continuous improvement and enhancing user experience.
4
+
5
+ ## Table of Contents
6
+
7
+ * [Install](#install)
8
+ * [Init](#init)
9
+ * [How to use](#how-to-use)
10
+ * [Style](#style)
4
11
 
5
12
  ## Install
6
13
 
@@ -162,6 +169,7 @@ with the public key of your feedback application. This ID and key is provided by
162
169
 
163
170
  Then, you can include the feedback data in an object with the following structure:
164
171
 
172
+ ```js
165
173
  {
166
174
  text: "string", // Optional
167
175
  answers: [
@@ -189,6 +197,7 @@ Then, you can include the feedback data in an object with the following structur
189
197
  },
190
198
  ],
191
199
  }
200
+ ```
192
201
 
193
202
  * **key**: This setting determines the key of the feedback data.
194
203
  * **value**: This setting determines the value of the feedback data.
@@ -196,3 +205,92 @@ Then, you can include the feedback data in an object with the following structur
196
205
  Not all the fields are required. You can send only the fields that you need. But you need to send one of that minimal.
197
206
 
198
207
  Finally, to send the feedback, you can use the magicfeedback.send() function.
208
+
209
+
210
+ ## Style
211
+
212
+ This section provides the CSS code you can use to customize the appearance of your Magicfeedback form. By applying these styles to the corresponding classes in your HTML, you can control the layout, colors, fonts, and other visual aspects of your feedback form.
213
+
214
+ Feel free to adapt and expand upon the provided styles to match your desired design and branding.
215
+
216
+ ```css
217
+ /* Overall container for the feedback form */
218
+ .magicfeedback-container {
219
+ /* ... add your container styles here ... */
220
+ }
221
+
222
+ /* Main form element */
223
+ .magicfeedback-form {
224
+ /* ... add your form styles here ... */
225
+ }
226
+
227
+ /* Section for questions */
228
+ .magicfeedback-questions {
229
+ /* ... add your questions section styles here ... */
230
+ }
231
+
232
+ /* Section for div */
233
+ .magicfeedback-div {
234
+ /* ... add your generic div styles here ... */
235
+ }
236
+
237
+ /* Generic styles for various input elements */
238
+ .magicfeedback-label,
239
+ .magicfeedback-input,
240
+ .magicfeedback-contact,
241
+ .magicfeedback-password,
242
+ .magicfeedback-email,
243
+ .magicfeedback-boolean,
244
+ .magicfeedback-date,
245
+ .magicfeedback-select,
246
+ .magicfeedback-radio,
247
+ .magicfeedback-checkbox,
248
+ .magicfeedback-rating,
249
+ .magicfeedback-rating-container,
250
+ .magicfeedback-rating-option,
251
+ .magicfeedback-rating-option-label-container,
252
+ .magicfeedback-number,
253
+ .magicfeedback-longtext,
254
+ .magicfeedback-text {
255
+ /* ... add your generic input styles here ... */
256
+ }
257
+
258
+ /* Specific styles for individual input types */
259
+ .magicfeedback-radio-container,
260
+ .magicfeedback-checkbox-container {
261
+ /* ... add styles for radio/checkbox containers ... */
262
+ }
263
+
264
+ .magicfeedback-rating-image1,
265
+ .magicfeedback-rating-image2,
266
+ .magicfeedback-rating-image3,
267
+ .magicfeedback-rating-image4,
268
+ .magicfeedback-rating-image5,
269
+ .magicfeedback-rating-image6,
270
+ .magicfeedback-rating-image7,
271
+ .magicfeedback-rating-image8,
272
+ .magicfeedback-rating-image9,
273
+ .magicfeedback-rating-image10 {
274
+ /* ... add styles for rating images ... */
275
+ }
276
+
277
+ /* Action buttons container */
278
+ .magicfeedback-action-container {
279
+ /* ... add your action button container styles here ... */
280
+ }
281
+
282
+ /* Submit button */
283
+ .magicfeedback-submit {
284
+ /* ... add your submit button styles here ... */
285
+ }
286
+
287
+ /* Back button */
288
+ .magicfeedback-back {
289
+ /* ... add your back button styles here ... */
290
+ }
291
+
292
+ /* Success message (if applicable) */
293
+ .magicfeedback-success {
294
+ /* ... add your success message styles here ... */
295
+ }
296
+ ```
@@ -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,r=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,r="Symbol"in e&&"iterator"in Symbol,o="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),s="FormData"in e,n="ArrayBuffer"in e;if(n)var a=["[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&&a.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 u(e){return"string"!=typeof e&&(e=String(e)),e}function l(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return r&&(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 y(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:o&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:s&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():n&&o&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=b(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):n&&(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"))},o&&(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,r=p(this);if(r)return r;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),r=0;r<t.length;r++)i[r]=String.fromCharCode(t[r]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(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=u(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)]=u(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)})),l(e)},h.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),l(e)},h.prototype.entries=function(){var e=[];return this.forEach((function(t,i){e.push([i,t])})),l(e)},r&&(h.prototype[Symbol.iterator]=h.prototype.entries);var g=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var i,r,o=(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,o||null==e._bodyInit||(o=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=(r=(i=t.method||this.method||"GET").toUpperCase(),g.indexOf(r)>-1?r:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function k(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var i=e.split("="),r=i.shift().replace(/\+/g," "),o=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(r),decodeURIComponent(o))}})),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})},y.call(v.prototype),y.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 x(e,i){return new Promise((function(r,s){var n=new v(e,i);if(n.signal&&n.signal.aborted)return s(new t.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function c(){a.abort()}a.onload=function(){var e,t,i={status:a.status,statusText:a.statusText,headers:(e=a.getAllResponseHeaders()||"",t=new h,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var i=e.split(":"),r=i.shift().trim();if(r){var o=i.join(":").trim();t.append(r,o)}})),t)};i.url="responseURL"in a?a.responseURL:i.headers.get("X-Request-URL");var o="response"in a?a.response:a.responseText;r(new w(o,i))},a.onerror=function(){s(new TypeError("Network request failed"))},a.ontimeout=function(){s(new TypeError("Network request failed"))},a.onabort=function(){s(new t.DOMException("Aborted","AbortError"))},a.open(n.method,n.url,!0),"include"===n.credentials?a.withCredentials=!0:"omit"===n.credentials&&(a.withCredentials=!1),"responseType"in a&&o&&(a.responseType="blob"),n.headers.forEach((function(e,t){a.setRequestHeader(t,e)})),n.signal&&(n.signal.addEventListener("abort",c),a.onreadystatechange=function(){4===a.readyState&&n.signal.removeEventListener("abort",c)}),a.send(void 0===n._bodyInit?null:n._bodyInit)}))}x.polyfill=!0,e.fetch||(e.fetch=x,e.Headers=h,e.Request=v,e.Response=w),t.Headers=h,t.Request=v,t.Response=w,t.fetch=x,Object.defineProperty(t,"__esModule",{value:!0})}({})}(r),r.fetch.ponyfill=!0,delete r.fetch.polyfill;var o=r;(t=o.fetch).default=o.fetch,t.fetch=o.fetch,t.Headers=o.Headers,t.Request=o.Request,t.Response=o.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 r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=r(i(519));let s=null;s||(s=(0,o.default)()),t.default=s},519:function(e,t,i){"use strict";var r=this&&this.__awaiter||function(e,t,i,r){return new(i||(i=Promise))((function(o,s){function n(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,a)}c((r=r.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const o=i(954),s=i(712),n=i(5),a=i(341),c=i(290);t.default=function(){const e=new s.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 n.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,o,s,n=!0,c,d){return r(this,void 0,void 0,(function*(){i||t.err("No appID provided"),o||t.err("No publicKey provided"),s||t.err("No feedback provided"),s.answers||s.profile||s.metrics||s.metadata||t.err("No feedback data provided");const r=e.get("url"),u={integration:i,publicKey:o,privateKey:d,completed:n,id:c,feedback:s};try{const e=yield(0,a.sendFeedback)(r,u,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,r){return i||t.err("No appID provided"),r||t.err("No publicKey provided"),new o.Form(e,i,r)}}}},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 r=this&&this.__awaiter||function(e,t,i,r){return new(i||(i=Promise))((function(o,s){function n(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,a)}c((r=r.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const o=i(5),s=i(341),n=i(183);t.Form=class{constructor(e,t,i){this.config=e,this.log=new o.Log(e),this.formOptionsConfig={},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 r(this,void 0,void 0,(function*(){try{if(this.formOptionsConfig=t,this.selector=e,this.formData=yield(0,s.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.log.log("Generating form for app",this.appId),this.questions=yield(0,s.getQuestions)(this.url,this.appId,this.publicKey,this.log),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}));const i=new URLSearchParams(window.location.search),r=Object.fromEntries(i.entries());Object.entries(r).map((([e,t])=>this.feedback.metadata.push({value:[t],key:e}))),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;try{const i=document.getElementById(this.selector);if(!i)throw new Error(`Element with ID '${this.selector}' not found.`);i.id="magicfeedback-container-"+this.appId,i.classList.add("magicfeedback-container"),i.innerHTML="";const r=document.createElement("form");r.classList.add("magicfeedback-form"),r.id="magicfeedback-"+this.appId;const o=document.createElement("div");if(o.classList.add("magicfeedback-questions"),o.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,n.renderQuestions)(this.questions),"MAGICSURVEY"===(null===(e=this.formData)||void 0===e?void 0:e.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,o.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>o.appendChild(e))),r.appendChild(o),i.appendChild(r),this.formOptionsConfig.addButton){const e=(0,n.renderActions)(null===(t=this.formData)||void 0===t?void 0:t.identity,(()=>this.back()));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}))}}send(e,t,i){var o;return r(this,void 0,void 0,(function*(){const r=document.getElementById("magicfeedback-container-"+this.appId),s=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 n=yield this.pushAnswers("MAGICSURVEY"!==(null===(o=this.formData)||void 0===o?void 0:o.identity));n&&(this.id=n,yield this.processNextQuestion(r,s)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:n,loading:!1,progress:this.progress,total:this.total,error:n?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 r=e.type,o={key:e.name,value:[]},n=e.value;if(o.key&&""!==o.key)switch(r){case"radio":case"checkbox":e.checked&&(o.value.push(n),t.push(o));break;case"email":(0,s.validateEmail)(n)?(this.feedback.profile.push({key:"email",value:[n]}),o.value.push(n),t.push(o)):(this.log.err("Invalid email"),i=!0);break;default:""!==n?(o.value.push(n),t.push(o)):(this.log.err("Invalid value"),i=!0)}})),this.feedback.answers=i?[]:t}pushAnswers(e=!1){return r(this,void 0,void 0,(function*(){try{if(this.answer(),!e&&this.questionInProcess&&this.questionInProcess.require&&0===this.feedback.answers.length)throw new Error("No answers provided");const t=this.config.get("url"),i={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,s.sendFeedback)(t,this.id?Object.assign(Object.assign({},i),{sessionId:this.id}):i,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){return r(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,s.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,o;return r(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(o=this.questionInProcess)||void 0===o?void 0:o.followup){const i=yield this.callFollowUpQuestion(this.questionInProcess);if(i){this.questionInProcess=i;const e=(0,n.renderQuestions)([i])[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{this.total=this.questions.length,this.progress=this.questions.length,e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,n.renderSuccess)("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{t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,n.renderSuccess)("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"}}},183:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0,t.renderQuestions=function(e){if(!e)throw new Error("[MagicFeedback] No questions provided");const t=[];return e.forEach((e=>{const{id:i,title:r,type:o,ref:s,require:n,value:a,defaultValue:c}=e;let d,u,l=document.createElement("div");switch(l.classList.add("magicfeedback-div"),o){case"TEXT":d=document.createElement("input"),d.type="text",d.placeholder="Write your answer here...",u="magicfeedback-text";break;case"LONGTEXT":d=document.createElement("textarea"),d.rows=3,d.placeholder="Write your answer here...",u="magicfeedback-longtext";break;case"NUMBER":d=document.createElement("input"),d.type="number",d.placeholder="Insert a number here",u="magicfeedback-number",a.length&&(a.sort(((e,t)=>Number(e)-Number(t))),d.max=a[a.length-1],d.min=a[0],d.value=a[0]);break;case"RADIO":case"MULTIPLECHOICE":case"RATING":if(d=document.createElement("div"),"RATING"===o){u="magicfeedback-rating";const e=document.createElement("div");e.classList.add("magicfeedback-rating-container");for(let t=0;t<=10;t++){const i=document.createElement("div");i.classList.add("magicfeedback-rating-option");const r=document.createElement("label");r.htmlFor=`rating-${s}-${t}`,r.classList.add("magicfeedback-rating-option-label-container");const o=document.createElement("label");o.htmlFor=`rating-${s}-${t}`,o.textContent=t.toString();const a=document.createElement("img");a.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`,a.alt=`face-${s}-${t}`,a.className=`rating-image${t}`;const c=document.createElement("input");c.id=`rating-${s}-${t}`,c.type="radio",c.name=s,c.value=t.toString(),c.required=n,c.classList.add(u),c.classList.add("magicfeedback-input"),r.appendChild(c),r.appendChild(a),r.appendChild(o),i.appendChild(r),e.appendChild(i)}d.appendChild(e)}else u="magicfeedback-"+("RADIO"===o?"radio":"checkbox"),a.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"RADIO"===o?"radio":"checkbox"}-container`);const r=document.createElement("label"),a=document.createElement("input");a.id=`rating-${s}-${t}`,a.type="RADIO"===o?"radio":"checkbox",a.name=s,a.value=e,a.required=n,a.classList.add(u),a.classList.add("magicfeedback-input"),e===c&&(a.checked=!0),r.textContent=e,r.htmlFor=`rating-${s}-${t}`,i.appendChild(a),i.appendChild(r),d.appendChild(i)}));break;case"SELECT":d=document.createElement("select"),u="magicfeedback-select",d.placeholder="Select an option",a.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,d.appendChild(t)}));break;case"DATE":d=document.createElement("input"),d.type="date",u="magicfeedback-date";break;case"BOOLEAN":d=document.createElement("input"),d.type="checkbox",u="magicfeedback-boolean";break;case"EMAIL":d=document.createElement("input"),d.type="email",d.placeholder="you@example.com",u="magicfeedback-email";break;case"PASSWORD":d=document.createElement("input"),d.type="password",d.placeholder="Write your password here",u="magicfeedback-password";break;case"CONTACT":d=document.createElement("input"),d.type="tel",u="magicfeedback-contact";break;default:return}d.id=`magicfeedback-${i}`,d.setAttribute("name",s),void 0!==c&&(d.value=c);const h=document.createElement("label");h.setAttribute("for",`magicfeedback-${i}`),h.textContent=r,h.classList.add("magicfeedback-label"),l.appendChild(h),d.classList.add(u),"RADIO"!=o&&"MULTIPLECHOICE"!=o&&(d.classList.add("magicfeedback-input"),d.required=n),l.appendChild(d),t.push(l)})),t},t.renderActions=function(e="",t){const i=document.createElement("div");i.classList.add("magicfeedback-action-container");const r=document.createElement("button");r.id="magicfeedback-submit",r.type="submit",r.classList.add("magicfeedback-submit"),r.textContent="MAGICSURVEY"===e?"Next":"Submit";const o=document.createElement("button");return o.id="magicfeedback-back",o.type="button",o.classList.add("magicfeedback-back"),o.textContent="Back",o.addEventListener("click",t),"MAGICSURVEY"===e&&i.appendChild(o),i.appendChild(r),i},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 r=this&&this.__awaiter||function(e,t,i,r){return new(i||(i=Promise))((function(o,s){function n(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,a)}c((r=r.apply(e,t||[])).next())}))},o=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 s=o(i(98)),n=o(i(147)),a=i(374),c={Accept:"application/json","Magicfeedback-Sdk-Version":n.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,o){return r(this,void 0,void 0,(function*(){try{const r=yield(0,s.default)(e+a.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(r.ok){const e=yield r.json();return o.log(`Received form for app ${t}`,e),e}throw o.err(`Failed to get questions for app ${t}:`,r.status,r.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return o.err(e),null}}))},t.getQuestions=function(e,t,i,o){return r(this,void 0,void 0,(function*(){try{const r=yield(0,s.default)(e+a.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(r.ok){const e=yield r.json();return o.log(`Received questions for app ${t}`,e),e}throw o.err(`Failed to get questions for app ${t}:`,r.status,r.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return o.err(e),[]}}))},t.sendFeedback=function(e,t,i){return r(this,void 0,void 0,(function*(){try{const r=yield(0,s.default)(e+a.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(r.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield r.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,r.status,r.statusText),new Error(r.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return r(this,void 0,void 0,(function*(){try{const r=yield(0,s.default)(e+a.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(r.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield r.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,r.status,r.statusText),new Error(r.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.1.9-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(r){var o=t[r];if(void 0!==o)return o.exports;var s=t[r]={exports:{}};return e[r].call(s.exports,s,s.exports,i),s.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,r=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,r="Symbol"in e&&"iterator"in Symbol,o="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),s="FormData"in e,n="ArrayBuffer"in e;if(n)var a=["[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&&a.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 u(e){return"string"!=typeof e&&(e=String(e)),e}function l(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return r&&(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 y(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:o&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:s&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():n&&o&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=b(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):n&&(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"))},o&&(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,r=p(this);if(r)return r;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),r=0;r<t.length;r++)i[r]=String.fromCharCode(t[r]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(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=u(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)]=u(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)})),l(e)},h.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),l(e)},h.prototype.entries=function(){var e=[];return this.forEach((function(t,i){e.push([i,t])})),l(e)},r&&(h.prototype[Symbol.iterator]=h.prototype.entries);var g=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var i,r,o=(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,o||null==e._bodyInit||(o=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=(r=(i=t.method||this.method||"GET").toUpperCase(),g.indexOf(r)>-1?r:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function k(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var i=e.split("="),r=i.shift().replace(/\+/g," "),o=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(r),decodeURIComponent(o))}})),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})},y.call(v.prototype),y.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 x(e,i){return new Promise((function(r,s){var n=new v(e,i);if(n.signal&&n.signal.aborted)return s(new t.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function c(){a.abort()}a.onload=function(){var e,t,i={status:a.status,statusText:a.statusText,headers:(e=a.getAllResponseHeaders()||"",t=new h,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var i=e.split(":"),r=i.shift().trim();if(r){var o=i.join(":").trim();t.append(r,o)}})),t)};i.url="responseURL"in a?a.responseURL:i.headers.get("X-Request-URL");var o="response"in a?a.response:a.responseText;r(new w(o,i))},a.onerror=function(){s(new TypeError("Network request failed"))},a.ontimeout=function(){s(new TypeError("Network request failed"))},a.onabort=function(){s(new t.DOMException("Aborted","AbortError"))},a.open(n.method,n.url,!0),"include"===n.credentials?a.withCredentials=!0:"omit"===n.credentials&&(a.withCredentials=!1),"responseType"in a&&o&&(a.responseType="blob"),n.headers.forEach((function(e,t){a.setRequestHeader(t,e)})),n.signal&&(n.signal.addEventListener("abort",c),a.onreadystatechange=function(){4===a.readyState&&n.signal.removeEventListener("abort",c)}),a.send(void 0===n._bodyInit?null:n._bodyInit)}))}x.polyfill=!0,e.fetch||(e.fetch=x,e.Headers=h,e.Request=v,e.Response=w),t.Headers=h,t.Request=v,t.Response=w,t.fetch=x,Object.defineProperty(t,"__esModule",{value:!0})}({})}(r),r.fetch.ponyfill=!0,delete r.fetch.polyfill;var o=r;(t=o.fetch).default=o.fetch,t.fetch=o.fetch,t.Headers=o.Headers,t.Request=o.Request,t.Response=o.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 r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=r(i(519));let s=null;s||(s=(0,o.default)()),t.default=s},519:function(e,t,i){"use strict";var r=this&&this.__awaiter||function(e,t,i,r){return new(i||(i=Promise))((function(o,s){function n(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,a)}c((r=r.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const o=i(954),s=i(712),n=i(5),a=i(341),c=i(290);t.default=function(){const e=new s.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 n.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,o,s,n=!0,c,d){return r(this,void 0,void 0,(function*(){i||t.err("No appID provided"),o||t.err("No publicKey provided"),s||t.err("No feedback provided"),s.answers||s.profile||s.metrics||s.metadata||t.err("No feedback data provided");const r=e.get("url"),u={integration:i,publicKey:o,privateKey:d,completed:n,id:c,feedback:s};try{const e=yield(0,a.sendFeedback)(r,u,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,r){return i||t.err("No appID provided"),r||t.err("No publicKey provided"),new o.Form(e,i,r)}}}},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 r=this&&this.__awaiter||function(e,t,i,r){return new(i||(i=Promise))((function(o,s){function n(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,a)}c((r=r.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const o=i(5),s=i(341),n=i(183);t.Form=class{constructor(e,t,i){this.config=e,this.log=new o.Log(e),this.formOptionsConfig={},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 r(this,void 0,void 0,(function*(){try{if(this.formOptionsConfig=t,this.selector=e,this.formData=yield(0,s.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.log.log("Generating form for app",this.appId),this.questions=yield(0,s.getQuestions)(this.url,this.appId,this.publicKey,this.log),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}));const i=new URLSearchParams(window.location.search),r=Object.fromEntries(i.entries());Object.entries(r).map((([e,t])=>this.feedback.metadata.push({value:[t],key:e}))),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;try{const i=document.getElementById(this.selector);if(!i)throw new Error(`Element with ID '${this.selector}' not found.`);i.id="magicfeedback-container-"+this.appId,i.classList.add("magicfeedback-container"),i.innerHTML="";const r=document.createElement("form");r.classList.add("magicfeedback-form"),r.id="magicfeedback-"+this.appId;const o=document.createElement("div");if(o.classList.add("magicfeedback-questions"),o.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,n.renderQuestions)(this.questions),"MAGICSURVEY"===(null===(e=this.formData)||void 0===e?void 0:e.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,o.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>o.appendChild(e))),r.appendChild(o),i.appendChild(r),this.formOptionsConfig.addButton){const e=(0,n.renderActions)(null===(t=this.formData)||void 0===t?void 0:t.identity,(()=>this.back()));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}))}}send(e,t,i){var o;return r(this,void 0,void 0,(function*(){const r=document.getElementById("magicfeedback-container-"+this.appId),s=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 n=yield this.pushAnswers("MAGICSURVEY"!==(null===(o=this.formData)||void 0===o?void 0:o.identity));n&&(this.id=n,yield this.processNextQuestion(r,s)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:n,loading:!1,progress:this.progress,total:this.total,error:n?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 r=e.type,o={key:e.name,value:[]},n=e.value;if(o.key&&""!==o.key)switch(r){case"radio":case"checkbox":e.checked&&(o.value.push(n),t.push(o));break;case"email":(0,s.validateEmail)(n)?(this.feedback.profile.push({key:"email",value:[n]}),o.value.push(n),t.push(o)):(this.log.err("Invalid email"),i=!0);break;default:""!==n?(o.value.push(n),t.push(o)):(this.log.err("Invalid value"),i=!0)}})),this.feedback.answers=i?[]:t}pushAnswers(e=!1){return r(this,void 0,void 0,(function*(){try{if(this.answer(),!e&&this.questionInProcess&&this.questionInProcess.require&&0===this.feedback.answers.length)throw new Error("No answers provided");const t=this.config.get("url"),i={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,s.sendFeedback)(t,this.id?Object.assign(Object.assign({},i),{sessionId:this.id}):i,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){return r(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,s.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,o;return r(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(o=this.questionInProcess)||void 0===o?void 0:o.followup){const i=yield this.callFollowUpQuestion(this.questionInProcess);if(i){this.questionInProcess=i;const e=(0,n.renderQuestions)([i])[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{this.total=this.questions.length,this.progress=this.questions.length,e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,n.renderSuccess)("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{t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,n.renderSuccess)("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"}}},183:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0,t.renderQuestions=function(e){if(!e)throw new Error("[MagicFeedback] No questions provided");const t=[];return e.forEach((e=>{const{id:i,title:r,type:o,ref:s,require:n,value:a,defaultValue:c}=e;let d,u,l=document.createElement("div");switch(l.classList.add("magicfeedback-div"),o){case"TEXT":d=document.createElement("input"),d.type="text",d.placeholder="Write your answer here...",u="magicfeedback-text";break;case"LONGTEXT":d=document.createElement("textarea"),d.rows=3,d.placeholder="Write your answer here...",u="magicfeedback-longtext";break;case"NUMBER":d=document.createElement("input"),d.type="number",d.placeholder="Insert a number here",u="magicfeedback-number",a.length&&(a.sort(((e,t)=>Number(e)-Number(t))),d.max=a[a.length-1],d.min=a[0],d.value=a[0]);break;case"RADIO":case"MULTIPLECHOICE":case"RATING":if(d=document.createElement("div"),"RATING"===o){u="magicfeedback-rating";const e=document.createElement("div");e.classList.add("magicfeedback-rating-container");for(let t=1;t<=10;t++){const i=document.createElement("div");i.classList.add("magicfeedback-rating-option");const r=document.createElement("label");r.htmlFor=`rating-${s}-${t}`,r.classList.add("magicfeedback-rating-option-label-container");const o=document.createElement("label");o.htmlFor=`rating-${s}-${t}`,o.textContent=t.toString();const a=document.createElement("img");a.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`,a.alt=`face-${s}-${t}`,a.className=`rating-image${t}`;const c=document.createElement("input");c.id=`rating-${s}-${t}`,c.type="radio",c.name=s,c.value=t.toString(),c.required=n,c.classList.add(u),c.classList.add("magicfeedback-input"),r.appendChild(c),r.appendChild(a),r.appendChild(o),i.appendChild(r),e.appendChild(i)}d.appendChild(e)}else u="magicfeedback-"+("RADIO"===o?"radio":"checkbox"),a.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"RADIO"===o?"radio":"checkbox"}-container`);const r=document.createElement("label"),a=document.createElement("input");a.id=`rating-${s}-${t}`,a.type="RADIO"===o?"radio":"checkbox",a.name=s,a.value=e,a.required=n,a.classList.add(u),a.classList.add("magicfeedback-input"),e===c&&(a.checked=!0),r.textContent=e,r.htmlFor=`rating-${s}-${t}`,i.appendChild(a),i.appendChild(r),d.appendChild(i)}));break;case"SELECT":d=document.createElement("select"),u="magicfeedback-select",d.placeholder="Select an option",a.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,d.appendChild(t)}));break;case"DATE":d=document.createElement("input"),d.type="date",u="magicfeedback-date";break;case"BOOLEAN":d=document.createElement("input"),d.type="checkbox",u="magicfeedback-boolean";break;case"EMAIL":d=document.createElement("input"),d.type="email",d.placeholder="you@example.com",u="magicfeedback-email";break;case"PASSWORD":d=document.createElement("input"),d.type="password",d.placeholder="Write your password here",u="magicfeedback-password";break;case"CONTACT":d=document.createElement("input"),d.type="tel",u="magicfeedback-contact";break;default:return}d.id=`magicfeedback-${i}`,d.setAttribute("name",s),void 0!==c&&(d.value=c);const h=document.createElement("label");h.setAttribute("for",`magicfeedback-${i}`),h.textContent=r,h.classList.add("magicfeedback-label"),l.appendChild(h),d.classList.add(u),"RADIO"!=o&&"MULTIPLECHOICE"!=o&&(d.classList.add("magicfeedback-input"),d.required=n),l.appendChild(d),t.push(l)})),t},t.renderActions=function(e="",t){const i=document.createElement("div");i.classList.add("magicfeedback-action-container");const r=document.createElement("button");r.id="magicfeedback-submit",r.type="submit",r.classList.add("magicfeedback-submit"),r.textContent="MAGICSURVEY"===e?"Next":"Submit";const o=document.createElement("button");return o.id="magicfeedback-back",o.type="button",o.classList.add("magicfeedback-back"),o.textContent="Back",o.addEventListener("click",t),"MAGICSURVEY"===e&&i.appendChild(o),i.appendChild(r),i},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 r=this&&this.__awaiter||function(e,t,i,r){return new(i||(i=Promise))((function(o,s){function n(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,a)}c((r=r.apply(e,t||[])).next())}))},o=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 s=o(i(98)),n=o(i(147)),a=i(374),c={Accept:"application/json","Magicfeedback-Sdk-Version":n.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,o){return r(this,void 0,void 0,(function*(){try{const r=yield(0,s.default)(e+a.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(r.ok){const e=yield r.json();return o.log(`Received form for app ${t}`,e),e}throw o.err(`Failed to get questions for app ${t}:`,r.status,r.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return o.err(e),null}}))},t.getQuestions=function(e,t,i,o){return r(this,void 0,void 0,(function*(){try{const r=yield(0,s.default)(e+a.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(r.ok){const e=yield r.json();return o.log(`Received questions for app ${t}`,e),e}throw o.err(`Failed to get questions for app ${t}:`,r.status,r.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return o.err(e),[]}}))},t.sendFeedback=function(e,t,i){return r(this,void 0,void 0,(function*(){try{const r=yield(0,s.default)(e+a.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(r.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield r.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,r.status,r.statusText),new Error(r.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return r(this,void 0,void 0,(function*(){try{const r=yield(0,s.default)(e+a.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(r.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield r.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,r.status,r.statusText),new Error(r.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.1.9","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(r){var o=t[r];if(void 0!==o)return o.exports;var s=t[r]={exports:{}};return e[r].call(s.exports,s,s.exports,i),s.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 o=s(i(519));let n=null;n||(n=(0,o.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(o,n){function r(e){try{c(s.next(e))}catch(e){n(e)}}function a(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const o=i(954),n=i(712),r=i(5),a=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 r.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,o,n,r=!0,c,d){return s(this,void 0,void 0,(function*(){i||t.err("No appID provided"),o||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:o,privateKey:d,completed:r,id:c,feedback:n};try{const e=yield(0,a.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 o.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(o,n){function r(e){try{c(s.next(e))}catch(e){n(e)}}function a(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const o=i(5),n=i(341),r=i(183);t.Form=class{constructor(e,t,i){this.config=e,this.log=new o.Log(e),this.formOptionsConfig={},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{if(this.formOptionsConfig=t,this.selector=e,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.log.log("Generating form for app",this.appId),this.questions=yield(0,n.getQuestions)(this.url,this.appId,this.publicKey,this.log),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}));const i=new URLSearchParams(window.location.search),s=Object.fromEntries(i.entries());Object.entries(s).map((([e,t])=>this.feedback.metadata.push({value:[t],key:e}))),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;try{const i=document.getElementById(this.selector);if(!i)throw new Error(`Element with ID '${this.selector}' not found.`);i.id="magicfeedback-container-"+this.appId,i.classList.add("magicfeedback-container"),i.innerHTML="";const s=document.createElement("form");s.classList.add("magicfeedback-form"),s.id="magicfeedback-"+this.appId;const o=document.createElement("div");if(o.classList.add("magicfeedback-questions"),o.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,r.renderQuestions)(this.questions),"MAGICSURVEY"===(null===(e=this.formData)||void 0===e?void 0:e.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,o.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>o.appendChild(e))),s.appendChild(o),i.appendChild(s),this.formOptionsConfig.addButton){const e=(0,r.renderActions)(null===(t=this.formData)||void 0===t?void 0:t.identity,(()=>this.back()));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}))}}send(e,t,i){var o;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 r=yield this.pushAnswers("MAGICSURVEY"!==(null===(o=this.formData)||void 0===o?void 0:o.identity));r&&(this.id=r,yield this.processNextQuestion(s,n)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:r,loading:!1,progress:this.progress,total:this.total,error:r?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,o={key:e.name,value:[]},r=e.value;if(o.key&&""!==o.key)switch(s){case"radio":case"checkbox":e.checked&&(o.value.push(r),t.push(o));break;case"email":(0,n.validateEmail)(r)?(this.feedback.profile.push({key:"email",value:[r]}),o.value.push(r),t.push(o)):(this.log.err("Invalid email"),i=!0);break;default:""!==r?(o.value.push(r),t.push(o)):(this.log.err("Invalid value"),i=!0)}})),this.feedback.answers=i?[]:t}pushAnswers(e=!1){return s(this,void 0,void 0,(function*(){try{if(this.answer(),!e&&this.questionInProcess&&this.questionInProcess.require&&0===this.feedback.answers.length)throw new Error("No answers provided");const t=this.config.get("url"),i={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,n.sendFeedback)(t,this.id?Object.assign(Object.assign({},i),{sessionId:this.id}):i,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,o;return s(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(o=this.questionInProcess)||void 0===o?void 0:o.followup){const i=yield this.callFollowUpQuestion(this.questionInProcess);if(i){this.questionInProcess=i;const e=(0,r.renderQuestions)([i])[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{this.total=this.questions.length,this.progress=this.questions.length,e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,r.renderSuccess)("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{t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,r.renderSuccess)("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"}}},183:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0,t.renderQuestions=function(e){if(!e)throw new Error("[MagicFeedback] No questions provided");const t=[];return e.forEach((e=>{const{id:i,title:s,type:o,ref:n,require:r,value:a,defaultValue:c}=e;let d,l,u=document.createElement("div");switch(u.classList.add("magicfeedback-div"),o){case"TEXT":d=document.createElement("input"),d.type="text",d.placeholder="Write your answer here...",l="magicfeedback-text";break;case"LONGTEXT":d=document.createElement("textarea"),d.rows=3,d.placeholder="Write your answer here...",l="magicfeedback-longtext";break;case"NUMBER":d=document.createElement("input"),d.type="number",d.placeholder="Insert a number here",l="magicfeedback-number",a.length&&(a.sort(((e,t)=>Number(e)-Number(t))),d.max=a[a.length-1],d.min=a[0],d.value=a[0]);break;case"RADIO":case"MULTIPLECHOICE":case"RATING":if(d=document.createElement("div"),"RATING"===o){l="magicfeedback-rating";const e=document.createElement("div");e.classList.add("magicfeedback-rating-container");for(let t=0;t<=10;t++){const i=document.createElement("div");i.classList.add("magicfeedback-rating-option");const s=document.createElement("label");s.htmlFor=`rating-${n}-${t}`,s.classList.add("magicfeedback-rating-option-label-container");const o=document.createElement("label");o.htmlFor=`rating-${n}-${t}`,o.textContent=t.toString();const a=document.createElement("img");a.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`,a.alt=`face-${n}-${t}`,a.className=`rating-image${t}`;const c=document.createElement("input");c.id=`rating-${n}-${t}`,c.type="radio",c.name=n,c.value=t.toString(),c.required=r,c.classList.add(l),c.classList.add("magicfeedback-input"),s.appendChild(c),s.appendChild(a),s.appendChild(o),i.appendChild(s),e.appendChild(i)}d.appendChild(e)}else l="magicfeedback-"+("RADIO"===o?"radio":"checkbox"),a.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"RADIO"===o?"radio":"checkbox"}-container`);const s=document.createElement("label"),a=document.createElement("input");a.id=`rating-${n}-${t}`,a.type="RADIO"===o?"radio":"checkbox",a.name=n,a.value=e,a.required=r,a.classList.add(l),a.classList.add("magicfeedback-input"),e===c&&(a.checked=!0),s.textContent=e,s.htmlFor=`rating-${n}-${t}`,i.appendChild(a),i.appendChild(s),d.appendChild(i)}));break;case"SELECT":d=document.createElement("select"),l="magicfeedback-select",d.placeholder="Select an option",a.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,d.appendChild(t)}));break;case"DATE":d=document.createElement("input"),d.type="date",l="magicfeedback-date";break;case"BOOLEAN":d=document.createElement("input"),d.type="checkbox",l="magicfeedback-boolean";break;case"EMAIL":d=document.createElement("input"),d.type="email",d.placeholder="you@example.com",l="magicfeedback-email";break;case"PASSWORD":d=document.createElement("input"),d.type="password",d.placeholder="Write your password here",l="magicfeedback-password";break;case"CONTACT":d=document.createElement("input"),d.type="tel",l="magicfeedback-contact";break;default:return}d.id=`magicfeedback-${i}`,d.setAttribute("name",n),void 0!==c&&(d.value=c);const h=document.createElement("label");h.setAttribute("for",`magicfeedback-${i}`),h.textContent=s,h.classList.add("magicfeedback-label"),u.appendChild(h),d.classList.add(l),"RADIO"!=o&&"MULTIPLECHOICE"!=o&&(d.classList.add("magicfeedback-input"),d.required=r),u.appendChild(d),t.push(u)})),t},t.renderActions=function(e="",t){const i=document.createElement("div");i.classList.add("magicfeedback-action-container");const s=document.createElement("button");s.id="magicfeedback-submit",s.type="submit",s.classList.add("magicfeedback-submit"),s.textContent="MAGICSURVEY"===e?"Next":"Submit";const o=document.createElement("button");return o.id="magicfeedback-back",o.type="button",o.classList.add("magicfeedback-back"),o.textContent="Back",o.addEventListener("click",t),"MAGICSURVEY"===e&&i.appendChild(o),i.appendChild(s),i},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(o,n){function r(e){try{c(s.next(e))}catch(e){n(e)}}function a(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}c((s=s.apply(e,t||[])).next())}))},o=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=o(i(31)),r=o(i(147)),a=i(374),c={Accept:"application/json","Magicfeedback-Sdk-Version":r.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,o){return s(this,void 0,void 0,(function*(){try{const s=yield(0,n.default)(e+a.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(s.ok){const e=yield s.json();return o.log(`Received form for app ${t}`,e),e}throw o.err(`Failed to get questions for app ${t}:`,s.status,s.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return o.err(e),null}}))},t.getQuestions=function(e,t,i,o){return s(this,void 0,void 0,(function*(){try{const s=yield(0,n.default)(e+a.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(s.ok){const e=yield s.json();return o.log(`Received questions for app ${t}`,e),e}throw o.err(`Failed to get questions for app ${t}:`,s.status,s.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return o.err(e),[]}}))},t.sendFeedback=function(e,t,i){return s(this,void 0,void 0,(function*(){try{const s=yield(0,n.default)(e+a.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+a.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.1.9-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(s){var o=t[s];if(void 0!==o)return o.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 s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=s(i(519));let n=null;n||(n=(0,o.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(o,n){function r(e){try{c(s.next(e))}catch(e){n(e)}}function a(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const o=i(954),n=i(712),r=i(5),a=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 r.Log(e),t.log("Initialized Magicfeedback",e)},send:function(i,o,n,r=!0,c,d){return s(this,void 0,void 0,(function*(){i||t.err("No appID provided"),o||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:o,privateKey:d,completed:r,id:c,feedback:n};try{const e=yield(0,a.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 o.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(o,n){function r(e){try{c(s.next(e))}catch(e){n(e)}}function a(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const o=i(5),n=i(341),r=i(183);t.Form=class{constructor(e,t,i){this.config=e,this.log=new o.Log(e),this.formOptionsConfig={},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{if(this.formOptionsConfig=t,this.selector=e,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.log.log("Generating form for app",this.appId),this.questions=yield(0,n.getQuestions)(this.url,this.appId,this.publicKey,this.log),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}));const i=new URLSearchParams(window.location.search),s=Object.fromEntries(i.entries());Object.entries(s).map((([e,t])=>this.feedback.metadata.push({value:[t],key:e}))),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;try{const i=document.getElementById(this.selector);if(!i)throw new Error(`Element with ID '${this.selector}' not found.`);i.id="magicfeedback-container-"+this.appId,i.classList.add("magicfeedback-container"),i.innerHTML="";const s=document.createElement("form");s.classList.add("magicfeedback-form"),s.id="magicfeedback-"+this.appId;const o=document.createElement("div");if(o.classList.add("magicfeedback-questions"),o.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,r.renderQuestions)(this.questions),"MAGICSURVEY"===(null===(e=this.formData)||void 0===e?void 0:e.identity)?(this.elementQuestions.forEach(((e,t)=>this.history[t]=[{object:this.questions[t],element:e}])),this.questionInProcess=this.history[0][0].object,o.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>o.appendChild(e))),s.appendChild(o),i.appendChild(s),this.formOptionsConfig.addButton){const e=(0,r.renderActions)(null===(t=this.formData)||void 0===t?void 0:t.identity,(()=>this.back()));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}))}}send(e,t,i){var o;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 r=yield this.pushAnswers("MAGICSURVEY"!==(null===(o=this.formData)||void 0===o?void 0:o.identity));r&&(this.id=r,yield this.processNextQuestion(s,n)),this.formOptionsConfig.afterSubmitEvent&&(yield this.formOptionsConfig.afterSubmitEvent({response:r,loading:!1,progress:this.progress,total:this.total,error:r?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,o={key:e.name,value:[]},r=e.value;if(o.key&&""!==o.key)switch(s){case"radio":case"checkbox":e.checked&&(o.value.push(r),t.push(o));break;case"email":(0,n.validateEmail)(r)?(this.feedback.profile.push({key:"email",value:[r]}),o.value.push(r),t.push(o)):(this.log.err("Invalid email"),i=!0);break;default:""!==r?(o.value.push(r),t.push(o)):(this.log.err("Invalid value"),i=!0)}})),this.feedback.answers=i?[]:t}pushAnswers(e=!1){return s(this,void 0,void 0,(function*(){try{if(this.answer(),!e&&this.questionInProcess&&this.questionInProcess.require&&0===this.feedback.answers.length)throw new Error("No answers provided");const t=this.config.get("url"),i={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,n.sendFeedback)(t,this.id?Object.assign(Object.assign({},i),{sessionId:this.id}):i,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,o;return s(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(o=this.questionInProcess)||void 0===o?void 0:o.followup){const i=yield this.callFollowUpQuestion(this.questionInProcess);if(i){this.questionInProcess=i;const e=(0,r.renderQuestions)([i])[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{this.total=this.questions.length,this.progress=this.questions.length,e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,r.renderSuccess)("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{t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,r.renderSuccess)("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"}}},183:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0,t.renderQuestions=function(e){if(!e)throw new Error("[MagicFeedback] No questions provided");const t=[];return e.forEach((e=>{const{id:i,title:s,type:o,ref:n,require:r,value:a,defaultValue:c}=e;let d,l,u=document.createElement("div");switch(u.classList.add("magicfeedback-div"),o){case"TEXT":d=document.createElement("input"),d.type="text",d.placeholder="Write your answer here...",l="magicfeedback-text";break;case"LONGTEXT":d=document.createElement("textarea"),d.rows=3,d.placeholder="Write your answer here...",l="magicfeedback-longtext";break;case"NUMBER":d=document.createElement("input"),d.type="number",d.placeholder="Insert a number here",l="magicfeedback-number",a.length&&(a.sort(((e,t)=>Number(e)-Number(t))),d.max=a[a.length-1],d.min=a[0],d.value=a[0]);break;case"RADIO":case"MULTIPLECHOICE":case"RATING":if(d=document.createElement("div"),"RATING"===o){l="magicfeedback-rating";const e=document.createElement("div");e.classList.add("magicfeedback-rating-container");for(let t=1;t<=10;t++){const i=document.createElement("div");i.classList.add("magicfeedback-rating-option");const s=document.createElement("label");s.htmlFor=`rating-${n}-${t}`,s.classList.add("magicfeedback-rating-option-label-container");const o=document.createElement("label");o.htmlFor=`rating-${n}-${t}`,o.textContent=t.toString();const a=document.createElement("img");a.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`,a.alt=`face-${n}-${t}`,a.className=`rating-image${t}`;const c=document.createElement("input");c.id=`rating-${n}-${t}`,c.type="radio",c.name=n,c.value=t.toString(),c.required=r,c.classList.add(l),c.classList.add("magicfeedback-input"),s.appendChild(c),s.appendChild(a),s.appendChild(o),i.appendChild(s),e.appendChild(i)}d.appendChild(e)}else l="magicfeedback-"+("RADIO"===o?"radio":"checkbox"),a.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"RADIO"===o?"radio":"checkbox"}-container`);const s=document.createElement("label"),a=document.createElement("input");a.id=`rating-${n}-${t}`,a.type="RADIO"===o?"radio":"checkbox",a.name=n,a.value=e,a.required=r,a.classList.add(l),a.classList.add("magicfeedback-input"),e===c&&(a.checked=!0),s.textContent=e,s.htmlFor=`rating-${n}-${t}`,i.appendChild(a),i.appendChild(s),d.appendChild(i)}));break;case"SELECT":d=document.createElement("select"),l="magicfeedback-select",d.placeholder="Select an option",a.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,d.appendChild(t)}));break;case"DATE":d=document.createElement("input"),d.type="date",l="magicfeedback-date";break;case"BOOLEAN":d=document.createElement("input"),d.type="checkbox",l="magicfeedback-boolean";break;case"EMAIL":d=document.createElement("input"),d.type="email",d.placeholder="you@example.com",l="magicfeedback-email";break;case"PASSWORD":d=document.createElement("input"),d.type="password",d.placeholder="Write your password here",l="magicfeedback-password";break;case"CONTACT":d=document.createElement("input"),d.type="tel",l="magicfeedback-contact";break;default:return}d.id=`magicfeedback-${i}`,d.setAttribute("name",n),void 0!==c&&(d.value=c);const h=document.createElement("label");h.setAttribute("for",`magicfeedback-${i}`),h.textContent=s,h.classList.add("magicfeedback-label"),u.appendChild(h),d.classList.add(l),"RADIO"!=o&&"MULTIPLECHOICE"!=o&&(d.classList.add("magicfeedback-input"),d.required=r),u.appendChild(d),t.push(u)})),t},t.renderActions=function(e="",t){const i=document.createElement("div");i.classList.add("magicfeedback-action-container");const s=document.createElement("button");s.id="magicfeedback-submit",s.type="submit",s.classList.add("magicfeedback-submit"),s.textContent="MAGICSURVEY"===e?"Next":"Submit";const o=document.createElement("button");return o.id="magicfeedback-back",o.type="button",o.classList.add("magicfeedback-back"),o.textContent="Back",o.addEventListener("click",t),"MAGICSURVEY"===e&&i.appendChild(o),i.appendChild(s),i},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(o,n){function r(e){try{c(s.next(e))}catch(e){n(e)}}function a(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}c((s=s.apply(e,t||[])).next())}))},o=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=o(i(31)),r=o(i(147)),a=i(374),c={Accept:"application/json","Magicfeedback-Sdk-Version":r.default.version};t.validateEmail=function(e){return/\S+@\S+\.\S+/.test(e)},t.getForm=function(e,t,i,o){return s(this,void 0,void 0,(function*(){try{const s=yield(0,n.default)(e+a.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(s.ok){const e=yield s.json();return o.log(`Received form for app ${t}`,e),e}throw o.err(`Failed to get questions for app ${t}:`,s.status,s.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return o.err(e),null}}))},t.getQuestions=function(e,t,i,o){return s(this,void 0,void 0,(function*(){try{const s=yield(0,n.default)(e+a.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(s.ok){const e=yield s.json();return o.log(`Received questions for app ${t}`,e),e}throw o.err(`Failed to get questions for app ${t}:`,s.status,s.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return o.err(e),[]}}))},t.sendFeedback=function(e,t,i){return s(this,void 0,void 0,(function*(){try{const s=yield(0,n.default)(e+a.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+a.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.1.9","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 o=t[s];if(void 0!==o)return o.exports;var n=t[s]={exports:{}};return e[s].call(n.exports,n,n.exports,i),n.exports}(607);return i.default})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicfeedback/native",
3
- "version": "1.1.9-beta.1",
3
+ "version": "1.1.9",
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",