@magicfeedback/native 1.1.13 → 1.1.14-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ This method is optional. You can start actived the debug mode to see on console
|
|
|
38
38
|
|
|
39
39
|
```js
|
|
40
40
|
magicfeedback.init({
|
|
41
|
-
debug: true | false // Default false
|
|
41
|
+
debug: true | false, // Default false
|
|
42
42
|
env: "prod" // Default
|
|
43
43
|
})
|
|
44
44
|
|
|
@@ -150,7 +150,7 @@ form.back() // Go to the previous question.
|
|
|
150
150
|
If you would like to include additional information with your feedback, you can do so by adding it to the `metadata`
|
|
151
151
|
, `metrics` o `profile` variables. These variables are optional and should be formatted as follows:
|
|
152
152
|
|
|
153
|
-
```
|
|
153
|
+
```js
|
|
154
154
|
[
|
|
155
155
|
{
|
|
156
156
|
"key": "key_1",
|
|
@@ -160,7 +160,7 @@ If you would like to include additional information with your feedback, you can
|
|
|
160
160
|
"key": "key_2",
|
|
161
161
|
"value": "value_2"
|
|
162
162
|
},
|
|
163
|
-
...
|
|
163
|
+
/* ... */
|
|
164
164
|
]
|
|
165
165
|
```
|
|
166
166
|
|
|
@@ -208,39 +208,31 @@ Then, you can include the feedback data in an object with the following structur
|
|
|
208
208
|
|
|
209
209
|
```js
|
|
210
210
|
{
|
|
211
|
-
text: "string",
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
value: ["string"]
|
|
218
|
-
},
|
|
219
|
-
],
|
|
220
|
-
metadata
|
|
221
|
-
:
|
|
222
|
-
[
|
|
223
|
-
{
|
|
224
|
-
key: 'string',
|
|
225
|
-
value: "string"
|
|
226
|
-
},
|
|
211
|
+
text: "string", /* Optional */
|
|
212
|
+
answers: [
|
|
213
|
+
{
|
|
214
|
+
key: 'string',
|
|
215
|
+
value: ["string"]
|
|
216
|
+
},
|
|
227
217
|
],
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
value: "string"
|
|
234
|
-
},
|
|
218
|
+
metadata: [
|
|
219
|
+
{
|
|
220
|
+
key: 'string',
|
|
221
|
+
value: "string"
|
|
222
|
+
},
|
|
235
223
|
],
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
value: "string"
|
|
242
|
-
},
|
|
224
|
+
metrics: [
|
|
225
|
+
{
|
|
226
|
+
key: 'string',
|
|
227
|
+
value: "string"
|
|
228
|
+
},
|
|
243
229
|
],
|
|
230
|
+
profile: [
|
|
231
|
+
{
|
|
232
|
+
key: 'string',
|
|
233
|
+
value: "string"
|
|
234
|
+
},
|
|
235
|
+
]
|
|
244
236
|
}
|
|
245
237
|
```
|
|
246
238
|
|
|
@@ -321,6 +313,37 @@ Feel free to adapt and expand upon the provided styles to match your desired des
|
|
|
321
313
|
/* ... add styles for rating images ... */
|
|
322
314
|
}
|
|
323
315
|
|
|
316
|
+
/* Section for number rating */
|
|
317
|
+
.magicfeedback-rating-number-container {
|
|
318
|
+
/* ... add your number rating container styles here ... */
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
.magicfeedback-rating-number-option {
|
|
322
|
+
/* ... add your number rating option styles here ... */
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.magicfeedback-rating-number-option-label-container {
|
|
326
|
+
/* ... add your number rating option label container styles here ... */
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
/* Section for star rating */
|
|
331
|
+
.magicfeedback-rating-star {
|
|
332
|
+
/* ... add your star rating container styles here ... */
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
.magicfeedback-rating-star-container {
|
|
336
|
+
/* ... add your star rating styles here ... */
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
.magicfeedback-rating-star-option {
|
|
340
|
+
/* ... add your star rating option styles here ... */
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
.magicfeedback-rating-star-selected {
|
|
344
|
+
/* ... add your star rating selected styles here ... */
|
|
345
|
+
}
|
|
346
|
+
|
|
324
347
|
/* Action buttons container */
|
|
325
348
|
.magicfeedback-action-container {
|
|
326
349
|
/* ... add your action button container styles here ... */
|
|
@@ -341,3 +364,31 @@ Feel free to adapt and expand upon the provided styles to match your desired des
|
|
|
341
364
|
/* ... add your success message styles here ... */
|
|
342
365
|
}
|
|
343
366
|
```
|
|
367
|
+
|
|
368
|
+
## Collected Metadata
|
|
369
|
+
|
|
370
|
+
### Browser Metadata (navigator object):
|
|
371
|
+
|
|
372
|
+
* **navigator-url (Browser URL)**: This captures the full URL, including any query parameters, using window.location.href.
|
|
373
|
+
* **navigator-origin (Browser Origin)**: This retrieves the origin portion of the URL (protocol, host, and port) using
|
|
374
|
+
window.location.origin.
|
|
375
|
+
* **navigator-pathname (Browser Pathname)**: This extracts the path component of the URL using window.location.pathname.
|
|
376
|
+
* **navigator-search (Browser Search Parameters): This captures the query string (search parameters) from the URL using
|
|
377
|
+
window.location.search.
|
|
378
|
+
* **navigator-user (User Agent)**: This retrieves a string identifying the browser and its version using navigator.userAgent.
|
|
379
|
+
|
|
380
|
+
* **navigator-language (Browser Language)**: This captures the user's preferred language setting from the browser using
|
|
381
|
+
navigator.language.
|
|
382
|
+
* **navigator-platform (Browser Platform)**: This retrieves the operating system platform the browser is running on using
|
|
383
|
+
navigator.platform.
|
|
384
|
+
* **navigator-appVersion (Browser Application Version)**: This captures the browser application version using
|
|
385
|
+
navigator.appVersion.
|
|
386
|
+
* **navigator-appName (Browser Application Name)**: This retrieves the name of the browser application using
|
|
387
|
+
navigator.appName.
|
|
388
|
+
* **navigator-product (Browser Product)**: This captures the name of the browser's rendering engine using navigator.product.
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
### Screen Metadata (screen object):
|
|
392
|
+
|
|
393
|
+
* **screen-width (Screen Width)**: This retrieves the width of the user's screen in pixels using window.screen.width.
|
|
394
|
+
* **screen-height (Screen Height)**: This captures the height of the user's screen in pixels using window.screen.height.
|
|
@@ -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,o=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,o="Symbol"in e&&"iterator"in Symbol,r="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 l(e){return"string"!=typeof e&&(e=String(e)),e}function u(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return o&&(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:r&&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&&r&&(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"))},r&&(this.blob=function(){var e=p(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(m)}),this.text=function(){var e,t,i,o=p(this);if(o)return o;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),o=0;o<t.length;o++)i[o]=String.fromCharCode(t[o]);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=l(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},h.prototype.delete=function(e){delete this.map[d(e)]},h.prototype.get=function(e){return e=d(e),this.has(e)?this.map[e]:null},h.prototype.has=function(e){return this.map.hasOwnProperty(d(e))},h.prototype.set=function(e,t){this.map[d(e)]=l(t)},h.prototype.forEach=function(e,t){for(var i in this.map)this.map.hasOwnProperty(i)&&e.call(t,this.map[i],i,this)},h.prototype.keys=function(){var e=[];return this.forEach((function(t,i){e.push(i)})),u(e)},h.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),u(e)},h.prototype.entries=function(){var e=[];return this.forEach((function(t,i){e.push([i,t])})),u(e)},o&&(h.prototype[Symbol.iterator]=h.prototype.entries);var g=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var i,o,r=(t=t||{}).body;if(e instanceof v){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new h(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,r||null==e._bodyInit||(r=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new h(t.headers)),this.method=(o=(i=t.method||this.method||"GET").toUpperCase(),g.indexOf(o)>-1?o:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(r)}function k(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var i=e.split("="),o=i.shift().replace(/\+/g," "),r=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(o),decodeURIComponent(r))}})),t}function w(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new h(t.headers),this.url=t.url||"",this._initBody(e)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},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 O(e,i){return new Promise((function(o,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(":"),o=i.shift().trim();if(o){var r=i.join(":").trim();t.append(o,r)}})),t)};i.url="responseURL"in a?a.responseURL:i.headers.get("X-Request-URL");var r="response"in a?a.response:a.responseText;o(new w(r,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&&r&&(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)}))}O.polyfill=!0,e.fetch||(e.fetch=O,e.Headers=h,e.Request=v,e.Response=w),t.Headers=h,t.Request=v,t.Response=w,t.fetch=O,Object.defineProperty(t,"__esModule",{value:!0})}({})}(o),o.fetch.ponyfill=!0,delete o.fetch.polyfill;var r=o;(t=r.fetch).default=r.fetch,t.fetch=r.fetch,t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response,e.exports=t},290:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_API_URL_DEV=t.HOST_API_URL=void 0,t.HOST_API_URL="https://api.magicfeedback.io/",t.HOST_API_URL_DEV="https://api-dev.magicfeedback.io/"},607:function(e,t,i){"use strict";var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=o(i(519));let s=null;s||(s=(0,r.default)()),t.default=s},519:function(e,t,i){"use strict";var o=this&&this.__awaiter||function(e,t,i,o){return new(i||(i=Promise))((function(r,s){function n(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const r=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,r,s,n=!0,c,d){return o(this,void 0,void 0,(function*(){i||t.err("No appID provided"),r||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 o=e.get("url"),l={integration:i,publicKey:r,privateKey:d,completed:n,id:c,feedback:s};try{const e=yield(0,a.sendFeedback)(o,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,o){return i||t.err("No appID provided"),o||t.err("No publicKey provided"),new r.Form(e,i,o)}}}},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 o=this&&this.__awaiter||function(e,t,i,o){return new(i||(i=Promise))((function(r,s){function n(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const r=i(5),s=i(341),n=i(183);t.Form=class{constructor(e,t,i){this.config=e,this.log=new r.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 o(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,formData:this.formData}));const i=new URLSearchParams(window.location.search),o=Object.fromEntries(i.entries());Object.entries(o).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 o=document.createElement("form");o.classList.add("magicfeedback-form"),o.id="magicfeedback-"+this.appId;const r=document.createElement("div");if(r.classList.add("magicfeedback-questions"),r.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,n.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat),"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,r.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>r.appendChild(e))),o.appendChild(r),i.appendChild(o),this.formOptionsConfig.addButton){const e=(0,n.renderActions)(null===(t=this.formData)||void 0===t?void 0:t.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);o.appendChild(e)}o.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 r;return o(this,void 0,void 0,(function*(){const o=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===(r=this.formData)||void 0===r?void 0:r.identity));n&&(this.id=n,yield this.processNextQuestion(o,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 o=e.type,r=e.classList[0],n={key:e.name,value:[]},a="magicfeedback-boolean"===r?e.checked.toString():e.value;if(n.key&&""!==n.key)switch(o){case"radio":case"checkbox":if("magicfeedback-boolean"===r||e.checked){n.value.push(a);const e=t.findIndex((e=>e.key===n.key));-1!==e?t[e].value=[...t[e].value,...n.value]:t.push(n)}break;case"email":(0,s.validateEmail)(a)?(this.feedback.profile.push({key:"email",value:[a]}),n.value.push(a),t.push(n)):(this.log.err("Invalid email"),i=!0);break;default:""!==a&&(n.value.push(a),t.push(n))}})),this.feedback.answers=i?[]:t}pushAnswers(e=!1){var t,i;return o(this,void 0,void 0,(function*(){try{if(this.answer(),"MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(i=this.questionInProcess)||void 0===i?void 0:i.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const o=this.config.get("url"),r={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,s.sendFeedback)(o,this.id?Object.assign(Object.assign({},r),{sessionId:this.id}):r,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){return o(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,r,s;return o(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(r=this.questionInProcess)||void 0===r?void 0:r.followup){const i=yield this.callFollowUpQuestion(this.questionInProcess);if(i){this.questionInProcess=i;const e=(0,n.renderQuestions)([i],null===(s=this.formOptionsConfig)||void 0===s?void 0:s.questionFormat)[0];this.history[this.progress].push({object:i,element:e}),t.removeChild(t.childNodes[0]),t.appendChild(e)}else this.renderNextQuestion(t,e)}else this.renderNextQuestion(t,e);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,n.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}}))}renderNextQuestion(e,t){if(this.progress++,this.progress<this.total)this.questionInProcess=this.history[this.progress][0].object,e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element);else{if(this.formOptionsConfig.addSuccessScreen){t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,n.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");t.appendChild(e)}this.pushAnswers(!0)}}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;const t=this.history[this.progress][this.history[this.progress].length-1];this.questionInProcess=t.object,e.appendChild(t.element)}}},374:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},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,t="standard"){if(!e)throw new Error("[MagicFeedback] No questions provided");const i=[];return e.forEach((e=>{const{id:o,title:r,type:s,ref:n,require:a,value:c,defaultValue:d}=e;let l,u,h=document.createElement("div");switch(h.classList.add("magicfeedback-div"),s){case"TEXT":l=document.createElement("input"),l.type="text",l.placeholder="slim"===t?r:"Write your answer here...",u="magicfeedback-text";break;case"LONGTEXT":l=document.createElement("textarea"),l.rows=3,l.placeholder="slim"===t?r:"Write your answer here...",u="magicfeedback-longtext";break;case"NUMBER":l=document.createElement("input"),l.type="number",l.placeholder="slim"===t?r:"Insert a number here",u="magicfeedback-number",c.length&&(c.sort(((e,t)=>Number(e)-Number(t))),l.max=c[c.length-1],l.min=c[0],l.value=c[0]);break;case"RADIO":case"MULTIPLECHOICE":case"RATING":if(l=document.createElement("div"),"RATING"===s){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 o=document.createElement("label");o.htmlFor=`rating-${n}-${t}`,o.classList.add("magicfeedback-rating-option-label-container");const r=document.createElement("label");r.htmlFor=`rating-${n}-${t}`,r.textContent=t.toString();const s=document.createElement("img");s.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`,s.alt=`face-${n}-${t}`,s.className=`rating-image${t}`;const a=document.createElement("input");a.id=`rating-${n}-${t}`,a.type="radio",a.name=n,a.value=t.toString(),a.classList.add(u),a.classList.add("magicfeedback-input"),o.appendChild(a),o.appendChild(s),o.appendChild(r),i.appendChild(o),e.appendChild(i)}l.appendChild(e)}else u="magicfeedback-"+("RADIO"===s?"radio":"checkbox"),c.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"RADIO"===s?"radio":"checkbox"}-container`);const o=document.createElement("label"),r=document.createElement("input");r.id=`rating-${n}-${t}`,r.type="RADIO"===s?"radio":"checkbox",r.name=n,r.value=e,r.classList.add(u),r.classList.add("magicfeedback-input"),e===d&&(r.checked=!0),o.textContent=e,o.htmlFor=`rating-${n}-${t}`,i.appendChild(r),i.appendChild(o),l.appendChild(i)}));break;case"SELECT":l=document.createElement("select"),u="magicfeedback-select",l.placeholder="slim"===t?r:"Select an option",c.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,l.appendChild(t)}));break;case"DATE":l=document.createElement("input"),l.type="date",l.placeholder="slim"===t?r:"Select a date",u="magicfeedback-date";break;case"BOOLEAN":l=document.createElement("input"),l.type="checkbox",u="magicfeedback-boolean";break;case"EMAIL":l=document.createElement("input"),l.type="email",l.placeholder="slim"===t?r:"you@example.com",u="magicfeedback-email";break;case"PASSWORD":l=document.createElement("input"),l.type="password",l.placeholder="slim"===t?r:"Write your password here",u="magicfeedback-password";break;case"CONTACT":l=document.createElement("input"),l.type="tel",l.placeholder="slim"===t?r:"Enter your phone number",u="magicfeedback-contact";break;default:return}l.id=`magicfeedback-${o}`,l.setAttribute("name",n),l.classList.add(u),void 0!==d&&(l.value=d),["RADIO","MULTIPLECHOICE"].includes(s)||(l.classList.add("magicfeedback-input"),l.required=a);const p=document.createElement("label");p.setAttribute("for",`magicfeedback-${o}`),p.textContent=r,p.classList.add("magicfeedback-label"),["BOOLEAN"].includes(s)?(h.classList.add("magicfeedback-boolean-container"),h.appendChild(l),h.appendChild(p)):("slim"!==t&&h.appendChild(p),h.appendChild(l)),i.push(h)})),i},t.renderActions=function(e="",t,i="Submit",o="Back",r="Next"){const s=document.createElement("div");s.classList.add("magicfeedback-action-container");const n=document.createElement("button");n.id="magicfeedback-submit",n.type="submit",n.classList.add("magicfeedback-submit"),n.textContent="MAGICSURVEY"===e?r||"Next":i||"Submit";const a=document.createElement("button");return a.id="magicfeedback-back",a.type="button",a.classList.add("magicfeedback-back"),a.textContent=o||"Back",a.addEventListener("click",t),"MAGICSURVEY"===e&&s.appendChild(a),s.appendChild(n),s},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 o=this&&this.__awaiter||function(e,t,i,o){return new(i||(i=Promise))((function(r,s){function n(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,a)}c((o=o.apply(e,t||[])).next())}))},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const s=r(i(98)),n=r(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,r){return o(this,void 0,void 0,(function*(){try{const o=yield(0,s.default)(e+a.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(o.ok){const e=yield o.json();return r.log(`Received form for app ${t}`,e),e}throw r.err(`Failed to get questions for app ${t}:`,o.status,o.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return r.err(e),null}}))},t.getQuestions=function(e,t,i,r){return o(this,void 0,void 0,(function*(){try{const o=yield(0,s.default)(e+a.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(o.ok){const e=yield o.json();return r.log(`Received questions for app ${t}`,e),e}throw r.err(`Failed to get questions for app ${t}:`,o.status,o.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return r.err(e),[]}}))},t.sendFeedback=function(e,t,i){return o(this,void 0,void 0,(function*(){try{const o=yield(0,s.default)(e+a.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(o.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield o.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,o.status,o.statusText),new Error(o.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return o(this,void 0,void 0,(function*(){try{const o=yield(0,s.default)(e+a.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(o.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield o.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,o.status,o.statusText),new Error(o.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.13","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(o){var r=t[o];if(void 0!==r)return r.exports;var s=t[o]={exports:{}};return e[o].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,s=function(){function e(){this.fetch=!1,this.DOMException=i.DOMException}return e.prototype=i,new e}();!function(e){!function(t){var i="URLSearchParams"in e,s="Symbol"in e&&"iterator"in Symbol,o="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),n="FormData"in e,r="ArrayBuffer"in e;if(r)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 l(e){return"string"!=typeof e&&(e=String(e)),e}function u(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return s&&(t[Symbol.iterator]=function(){return t}),t}function h(e){this.map={},e instanceof h?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function p(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function f(e){return new Promise((function(t,i){e.onload=function(){t(e.result)},e.onerror=function(){i(e.error)}}))}function m(e){var t=new FileReader,i=f(t);return t.readAsArrayBuffer(e),i}function b(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function g(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:o&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:n&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():r&&o&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=b(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):r&&(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,s=p(this);if(s)return s;if(this._bodyBlob)return e=this._bodyBlob,i=f(t=new FileReader),t.readAsText(e),i;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),i=new Array(t.length),s=0;s<t.length;s++)i[s]=String.fromCharCode(t[s]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},n&&(this.formData=function(){return this.text().then(k)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(e,t){e=d(e),t=l(t);var i=this.map[e];this.map[e]=i?i+", "+t:t},h.prototype.delete=function(e){delete this.map[d(e)]},h.prototype.get=function(e){return e=d(e),this.has(e)?this.map[e]:null},h.prototype.has=function(e){return this.map.hasOwnProperty(d(e))},h.prototype.set=function(e,t){this.map[d(e)]=l(t)},h.prototype.forEach=function(e,t){for(var i in this.map)this.map.hasOwnProperty(i)&&e.call(t,this.map[i],i,this)},h.prototype.keys=function(){var e=[];return this.forEach((function(t,i){e.push(i)})),u(e)},h.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),u(e)},h.prototype.entries=function(){var e=[];return this.forEach((function(t,i){e.push([i,t])})),u(e)},s&&(h.prototype[Symbol.iterator]=h.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(e,t){var i,s,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=(s=(i=t.method||this.method||"GET").toUpperCase(),y.indexOf(s)>-1?s:i),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&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("="),s=i.shift().replace(/\+/g," "),o=i.join("=").replace(/\+/g," ");t.append(decodeURIComponent(s),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})},g.call(v.prototype),g.call(w.prototype),w.prototype.clone=function(){return new w(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},w.error=function(){var e=new w(null,{status:0,statusText:""});return e.type="error",e};var E=[301,302,303,307,308];w.redirect=function(e,t){if(-1===E.indexOf(t))throw new RangeError("Invalid status code");return new w(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var i=Error(e);this.stack=i.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function _(e,i){return new Promise((function(s,n){var r=new v(e,i);if(r.signal&&r.signal.aborted)return n(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(":"),s=i.shift().trim();if(s){var o=i.join(":").trim();t.append(s,o)}})),t)};i.url="responseURL"in a?a.responseURL:i.headers.get("X-Request-URL");var o="response"in a?a.response:a.responseText;s(new w(o,i))},a.onerror=function(){n(new TypeError("Network request failed"))},a.ontimeout=function(){n(new TypeError("Network request failed"))},a.onabort=function(){n(new t.DOMException("Aborted","AbortError"))},a.open(r.method,r.url,!0),"include"===r.credentials?a.withCredentials=!0:"omit"===r.credentials&&(a.withCredentials=!1),"responseType"in a&&o&&(a.responseType="blob"),r.headers.forEach((function(e,t){a.setRequestHeader(t,e)})),r.signal&&(r.signal.addEventListener("abort",c),a.onreadystatechange=function(){4===a.readyState&&r.signal.removeEventListener("abort",c)}),a.send(void 0===r._bodyInit?null:r._bodyInit)}))}_.polyfill=!0,e.fetch||(e.fetch=_,e.Headers=h,e.Request=v,e.Response=w),t.Headers=h,t.Request=v,t.Response=w,t.fetch=_,Object.defineProperty(t,"__esModule",{value:!0})}({})}(s),s.fetch.ponyfill=!0,delete s.fetch.polyfill;var o=s;(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 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){"use strict";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)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(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={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i,this.url=e.get("url"),this.id="",this.formData=null,this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.questions=[],this.elementQuestions=[],this.questionInProcess=null,this.history={},this.progress=0,this.total=0}generate(e,t){return s(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;const i=localStorage.getItem(`magicfeedback-${this.appId}`);if(i&&new Date(JSON.parse(i).savedAt)<new Date((new Date).getTime()+864e5)?(this.formData=JSON.parse(i),(0,n.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,this.formData.questions&&(this.questions=this.formData.questions,this.total=this.questions.length),localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData)),this.generateForm())}))):this.formData=yield(0,n.getForm)(this.url,this.appId,this.publicKey,this.log),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}generateForm(){var e,t;try{this.questions.sort(((e,t)=>e.position-t.position));const i=document.getElementById(this.selector);if(!i)throw new Error(`Element with ID '${this.selector}' not found.`);i.classList.add("magicfeedback-container"),i.id="magicfeedback-container-"+this.appId,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,this.formOptionsConfig.questionFormat),"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()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);s.appendChild(e)}s.addEventListener("submit",(e=>{e.preventDefault(),this.send()}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}getMetaData(){this.feedback.metadata.push({key:"navigator-url",value:[window.location.href]}),this.feedback.metadata.push({key:"navigator-origin",value:[window.location.origin]}),this.feedback.metadata.push({key:"navigator-pathname",value:[window.location.pathname]}),this.feedback.metadata.push({key:"navigator-search",value:[window.location.search]}),this.feedback.metadata.push({key:"navigator-user",value:[navigator.userAgent]}),this.feedback.metadata.push({key:"navigator-language",value:[navigator.language]}),this.feedback.metadata.push({key:"navigator-platform",value:[navigator.platform]}),this.feedback.metadata.push({key:"navigator-appVersion",value:[navigator.appVersion]}),this.feedback.metadata.push({key:"navigator-appName",value:[navigator.appName]}),this.feedback.metadata.push({key:"navigator-product",value:[navigator.product]}),this.feedback.metadata.push({key:"screen-width",value:[window.screen.width.toString()]}),this.feedback.metadata.push({key:"screen-height",value:[window.screen.height.toString()]})}send(e,t,i){var 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=e.classList[0],r={key:e.name,value:[]},a="magicfeedback-boolean"===o?e.checked.toString():e.value;if(r.key&&""!==r.key)switch(s){case"radio":case"checkbox":if("magicfeedback-boolean"===o||e.checked){r.value.push(a);const e=t.findIndex((e=>e.key===r.key));-1!==e?t[e].value=[...t[e].value,...r.value]:t.push(r)}break;case"email":(0,n.validateEmail)(a)?(this.feedback.profile.push({key:"email",value:[a]}),r.value.push(a),t.push(r)):(this.log.err("Invalid email"),i=!0);break;default:""!==a&&(r.value.push(a),t.push(r))}})),this.feedback.answers=i?[]:t}pushAnswers(e=!1){var t,i;return s(this,void 0,void 0,(function*(){try{if(this.answer(),"MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(i=this.questionInProcess)||void 0===i?void 0:i.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const s=this.config.get("url"),o={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,n.sendFeedback)(s,this.id?Object.assign(Object.assign({},o),{sessionId:this.id}):o,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,n;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],null===(n=this.formOptionsConfig)||void 0===n?void 0:n.questionFormat)[0];this.history[this.progress].push({object:i,element:e}),t.removeChild(t.childNodes[0]),t.appendChild(e)}else this.renderNextQuestion(t,e)}else this.renderNextQuestion(t,e);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,r.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}}))}renderNextQuestion(e,t){if(this.progress++,this.progress<this.total)this.questionInProcess=this.history[this.progress][0].object,e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element);else{if(this.formOptionsConfig.addSuccessScreen){t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,r.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");t.appendChild(e)}this.pushAnswers(!0)}}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;const t=this.history[this.progress][this.history[this.progress].length-1];this.questionInProcess=t.object,e.appendChild(t.element)}}},374:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},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,t="standard"){if(!e)throw new Error("[MagicFeedback] No questions provided");const i=[];return e.forEach((e=>{const{id:s,title:o,type:n,ref:r,require:a,value:c,defaultValue:d}=e;let l,u,h=document.createElement("div");switch(h.classList.add("magicfeedback-div"),n){case"TEXT":l=document.createElement("input"),l.type="text",l.placeholder="slim"===t?o:"Write your answer here...",u="magicfeedback-text";break;case"LONGTEXT":l=document.createElement("textarea"),l.rows=3,l.placeholder="slim"===t?o:"Write your answer here...",u="magicfeedback-longtext";break;case"NUMBER":l=document.createElement("input"),l.type="number",l.placeholder="slim"===t?o:"Insert a number here",u="magicfeedback-number",c.length&&(c.sort(((e,t)=>Number(e)-Number(t))),l.max=c[c.length-1],l.min=c[0],l.value=c[0]);break;case"RADIO":case"MULTIPLECHOICE":l=document.createElement("div"),u="magicfeedback-"+("RADIO"===n?"radio":"checkbox"),c.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"RADIO"===n?"radio":"checkbox"}-container`);const s=document.createElement("label"),o=document.createElement("input");o.id=`rating-${r}-${t}`,o.type="RADIO"===n?"radio":"checkbox",o.name=r,o.value=e,o.classList.add(u),o.classList.add("magicfeedback-input"),e===d&&(o.checked=!0),s.textContent=e,s.htmlFor=`rating-${r}-${t}`,i.appendChild(o),i.appendChild(s),l.appendChild(i)}));break;case"RATING":case"WIDGET_RATING_EMOJI_1_10":case"WIDGET_RATING_EMOJI_1_5":l=document.createElement("div"),u="magicfeedback-rating";const e=document.createElement("div");e.classList.add("magicfeedback-rating-container");const i=["WIDGET_RATING_EMOJI_1_5","WIDGET_RATING_NUMBER_1_5"].includes(n)?5:10;for(let t=1;t<=i;t++){const i=document.createElement("div");i.classList.add("magicfeedback-rating-option");const s=document.createElement("label");s.htmlFor=`rating-${r}-${t}`,s.classList.add("magicfeedback-rating-option-label-container");const o=document.createElement("label");o.htmlFor=`rating-${r}-${t}`,o.textContent=t.toString();const a=document.createElement("img");if(["WIDGET_RATING_EMOJI_1_5"].includes(n))switch(t){case 1:a.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:a.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:a.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:a.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:a.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else a.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`;a.alt=`face-${r}-${t}`,a.className=`rating-image${t}`;const c=document.createElement("input");c.id=`rating-${r}-${t}`,c.type="radio",c.name=r,c.value=t.toString(),c.classList.add(u),c.classList.add("magicfeedback-input"),s.appendChild(c),["WIDGET_RATING_EMOJI_1_5","WIDGET_RATING_EMOJI_1_10","RATING"].includes(n)?s.appendChild(a):s.classList.add("magicfeedback-rating-option-label-container-number"),s.appendChild(o),i.appendChild(s),e.appendChild(i)}l.appendChild(e);break;case"WIDGET_RATING_NUMBER_1_10":case"WIDGET_RATING_NUMBER_1_5":l=document.createElement("div"),u="magicfeedback-rating-number";const s=document.createElement("div");s.classList.add("magicfeedback-rating-number-container");const a=["WIDGET_RATING_NUMBER_1_5"].includes(n)?5:10;for(let e=1;e<=a;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-number-option");const i=document.createElement("label");i.htmlFor=`rating-${r}-${e}`,i.classList.add("magicfeedback-rating-number-option-label-container");const o=document.createElement("label");o.htmlFor=`rating-${r}-${e}`,o.textContent=e.toString();const n=document.createElement("input");n.id=`rating-${r}-${e}`,n.type="radio",n.name=r,n.value=e.toString(),n.classList.add(u),n.classList.add("magicfeedback-input"),i.appendChild(n),i.appendChild(o),t.appendChild(i),s.appendChild(t)}l.appendChild(s);break;case"WIDGET_RATING_STAR_1_5":l=document.createElement("div"),u="magicfeedback-rating-star";const h=function(){const e="magicfeedback-rating-star-selected",t=document.createElement("div");t.classList.add("magicfeedback-rating-star-container");for(let i=1;i<=5;i++){const s=document.createElement("label");s.classList.add("magicfeedback-rating-star-option");const o=document.createElement("input");o.type="radio",o.name="rating",o.value=i.toString(),o.style.position="absolute",o.style.opacity="0",o.style.width="0",o.style.height="0",o.addEventListener("change",(()=>{const i=t.querySelectorAll(".rating__star");for(let t=0;t<i.length;t++)t+1<=Number(o.value)?i[t].classList.contains(e)||i[t].classList.add(e):i[t].classList.contains(e)&&i[t].classList.remove(e)})),s.appendChild(o);const n=document.createElement("span");n.classList.add("rating__star"),n.textContent="★",n.style.fontSize="40px",n.style.cursor="pointer",s.appendChild(n),t.appendChild(s)}return t}();l.appendChild(h);break;case"SELECT":l=document.createElement("select"),u="magicfeedback-select",l.placeholder="slim"===t?o:"Select an option",c.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,l.appendChild(t)}));break;case"DATE":l=document.createElement("input"),l.type="date",l.placeholder="slim"===t?o:"Select a date",u="magicfeedback-date";break;case"BOOLEAN":l=document.createElement("input"),l.type="checkbox",u="magicfeedback-boolean";break;case"EMAIL":l=document.createElement("input"),l.type="email",l.placeholder="slim"===t?o:"you@example.com",u="magicfeedback-email";break;case"PASSWORD":l=document.createElement("input"),l.type="password",l.placeholder="slim"===t?o:"Write your password here",u="magicfeedback-password";break;case"CONTACT":l=document.createElement("input"),l.type="tel",l.placeholder="slim"===t?o:"Enter your phone number",u="magicfeedback-contact";break;default:return}l.id=`magicfeedback-${s}`,l.setAttribute("name",r),l.classList.add(u),void 0!==d&&(l.value=d),["RADIO","MULTIPLECHOICE"].includes(n)||(l.classList.add("magicfeedback-input"),l.required=a);const p=document.createElement("label");p.setAttribute("for",`magicfeedback-${s}`),p.textContent=o,p.classList.add("magicfeedback-label"),["BOOLEAN"].includes(n)?(h.classList.add("magicfeedback-boolean-container"),h.appendChild(l),h.appendChild(p)):("slim"!==t&&h.appendChild(p),h.appendChild(l)),i.push(h)})),i},t.renderActions=function(e="",t,i="Submit",s="Back",o="Next"){const n=document.createElement("div");n.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?o||"Next":i||"Submit";const a=document.createElement("button");return a.id="magicfeedback-back",a.type="button",a.classList.add("magicfeedback-back"),a.textContent=s||"Back",a.addEventListener("click",t),"MAGICSURVEY"===e&&n.appendChild(a),n.appendChild(r),n},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t}},341:function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(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(98)),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)=>{"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.14-beta.1","main":"./dist/magicfeedback-sdk.node.js","browser":"./dist/magicfeedback-sdk.browser.js","types":"./dist/types/src/index.d.ts","repository":{"type":"git","url":"git+ssh://git@github.com/MagicFeedback/magicfeedback-sdk.git"},"author":"farias@magicfeedback.io","license":"MIT","private":false,"scripts":{"dev":"vite","build":"webpack","build:watch":"webpack --watch --mode development","publish":"npm publish --access public","publish:beta":"npm publish --access public --tag beta","test":"jest","test:watch":"jest --watchAll","coverage":"vitest run --coverage"},"files":["dist"],"devDependencies":{"@babel/preset-typescript":"^7.22.5","@types/node":"^17.0.21","@types/webpack":"^5.28.0","@types/webpack-node-externals":"^2.5.3","c8":"^7.11.0","jest":"^29.5.0","jest-environment-jsdom":"^29.5.0","jest-fetch-mock":"^3.0.3","nock":"^13.2.4","ts-jest":"^29.1.0","ts-loader":"^9.2.7","ts-node":"^10.7.0","typescript":"^4.6.2","vite":"^2.8.0","vite-plugin-dts":"^0.9.9","vitest":"^0.5.9","webpack":"^5.70.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"},"dependencies":{"cross-fetch":"^3.1.5","is-bundling-for-browser-or-node":"^1.1.1"},"description":"MagicFeedbackAI JavaScript Library for [MagicFeedback.io](https://magicfeedback.io/)","bugs":{"url":"https://github.com/MagicFeedback/magicfeedback-sdk/issues"},"homepage":"https://github.com/MagicFeedback/magicfeedback-sdk#readme","directories":{"example":"examples","test":"test"}}')}},t={},function i(s){var 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).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,formData:this.formData}));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,this.formOptionsConfig.questionFormat),"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()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);s.appendChild(e)}s.addEventListener("submit",(e=>{e.preventDefault(),this.send()}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}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=e.classList[0],r={key:e.name,value:[]},a="magicfeedback-boolean"===o?e.checked.toString():e.value;if(r.key&&""!==r.key)switch(s){case"radio":case"checkbox":if("magicfeedback-boolean"===o||e.checked){r.value.push(a);const e=t.findIndex((e=>e.key===r.key));-1!==e?t[e].value=[...t[e].value,...r.value]:t.push(r)}break;case"email":(0,n.validateEmail)(a)?(this.feedback.profile.push({key:"email",value:[a]}),r.value.push(a),t.push(r)):(this.log.err("Invalid email"),i=!0);break;default:""!==a&&(r.value.push(a),t.push(r))}})),this.feedback.answers=i?[]:t}pushAnswers(e=!1){var t,i;return s(this,void 0,void 0,(function*(){try{if(this.answer(),"MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(i=this.questionInProcess)||void 0===i?void 0:i.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const s=this.config.get("url"),o={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,n.sendFeedback)(s,this.id?Object.assign(Object.assign({},o),{sessionId:this.id}):o,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,n;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],null===(n=this.formOptionsConfig)||void 0===n?void 0:n.questionFormat)[0];this.history[this.progress].push({object:i,element:e}),t.removeChild(t.childNodes[0]),t.appendChild(e)}else this.renderNextQuestion(t,e)}else this.renderNextQuestion(t,e);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,r.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}}))}renderNextQuestion(e,t){if(this.progress++,this.progress<this.total)this.questionInProcess=this.history[this.progress][0].object,e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element);else{if(this.formOptionsConfig.addSuccessScreen){t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,r.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");t.appendChild(e)}this.pushAnswers(!0)}}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;const t=this.history[this.progress][this.history[this.progress].length-1];this.questionInProcess=t.object,e.appendChild(t.element)}}},374:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},183:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0,t.renderQuestions=function(e,t="standard"){if(!e)throw new Error("[MagicFeedback] No questions provided");const i=[];return e.forEach((e=>{const{id:s,title:o,type:n,ref:r,require:a,value:c,defaultValue:d}=e;let l,u,h=document.createElement("div");switch(h.classList.add("magicfeedback-div"),n){case"TEXT":l=document.createElement("input"),l.type="text",l.placeholder="slim"===t?o:"Write your answer here...",u="magicfeedback-text";break;case"LONGTEXT":l=document.createElement("textarea"),l.rows=3,l.placeholder="slim"===t?o:"Write your answer here...",u="magicfeedback-longtext";break;case"NUMBER":l=document.createElement("input"),l.type="number",l.placeholder="slim"===t?o:"Insert a number here",u="magicfeedback-number",c.length&&(c.sort(((e,t)=>Number(e)-Number(t))),l.max=c[c.length-1],l.min=c[0],l.value=c[0]);break;case"RADIO":case"MULTIPLECHOICE":case"RATING":if(l=document.createElement("div"),"RATING"===n){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 s=document.createElement("label");s.htmlFor=`rating-${r}-${t}`,s.classList.add("magicfeedback-rating-option-label-container");const o=document.createElement("label");o.htmlFor=`rating-${r}-${t}`,o.textContent=t.toString();const n=document.createElement("img");n.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`,n.alt=`face-${r}-${t}`,n.className=`rating-image${t}`;const a=document.createElement("input");a.id=`rating-${r}-${t}`,a.type="radio",a.name=r,a.value=t.toString(),a.classList.add(u),a.classList.add("magicfeedback-input"),s.appendChild(a),s.appendChild(n),s.appendChild(o),i.appendChild(s),e.appendChild(i)}l.appendChild(e)}else u="magicfeedback-"+("RADIO"===n?"radio":"checkbox"),c.forEach(((e,t)=>{const i=document.createElement("div");i.classList.add(`magicfeedback-${"RADIO"===n?"radio":"checkbox"}-container`);const s=document.createElement("label"),o=document.createElement("input");o.id=`rating-${r}-${t}`,o.type="RADIO"===n?"radio":"checkbox",o.name=r,o.value=e,o.classList.add(u),o.classList.add("magicfeedback-input"),e===d&&(o.checked=!0),s.textContent=e,s.htmlFor=`rating-${r}-${t}`,i.appendChild(o),i.appendChild(s),l.appendChild(i)}));break;case"SELECT":l=document.createElement("select"),u="magicfeedback-select",l.placeholder="slim"===t?o:"Select an option",c.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,l.appendChild(t)}));break;case"DATE":l=document.createElement("input"),l.type="date",l.placeholder="slim"===t?o:"Select a date",u="magicfeedback-date";break;case"BOOLEAN":l=document.createElement("input"),l.type="checkbox",u="magicfeedback-boolean";break;case"EMAIL":l=document.createElement("input"),l.type="email",l.placeholder="slim"===t?o:"you@example.com",u="magicfeedback-email";break;case"PASSWORD":l=document.createElement("input"),l.type="password",l.placeholder="slim"===t?o:"Write your password here",u="magicfeedback-password";break;case"CONTACT":l=document.createElement("input"),l.type="tel",l.placeholder="slim"===t?o:"Enter your phone number",u="magicfeedback-contact";break;default:return}l.id=`magicfeedback-${s}`,l.setAttribute("name",r),l.classList.add(u),void 0!==d&&(l.value=d),["RADIO","MULTIPLECHOICE"].includes(n)||(l.classList.add("magicfeedback-input"),l.required=a);const p=document.createElement("label");p.setAttribute("for",`magicfeedback-${s}`),p.textContent=o,p.classList.add("magicfeedback-label"),["BOOLEAN"].includes(n)?(h.classList.add("magicfeedback-boolean-container"),h.appendChild(l),h.appendChild(p)):("slim"!==t&&h.appendChild(p),h.appendChild(l)),i.push(h)})),i},t.renderActions=function(e="",t,i="Submit",s="Back",o="Next"){const n=document.createElement("div");n.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?o||"Next":i||"Submit";const a=document.createElement("button");return a.id="magicfeedback-back",a.type="button",a.classList.add("magicfeedback-back"),a.textContent=s||"Back",a.addEventListener("click",t),"MAGICSURVEY"===e&&n.appendChild(a),n.appendChild(r),n},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t}},341:function(e,t,i){var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(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.13","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 a=s(i(519));let o=null;o||(o=(0,a.default)()),t.default=o},519:function(e,t,i){var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(a,o){function n(e){try{c(s.next(e))}catch(e){o(e)}}function r(e){try{c(s.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,r)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const a=i(954),o=i(712),n=i(5),r=i(341),c=i(290);t.default=function(){const e=new o.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,a,o,n=!0,c,d){return s(this,void 0,void 0,(function*(){i||t.err("No appID provided"),a||t.err("No publicKey provided"),o||t.err("No feedback provided"),o.answers||o.profile||o.metrics||o.metadata||t.err("No feedback data provided");const s=e.get("url"),l={integration:i,publicKey:a,privateKey:d,completed:n,id:c,feedback:o};try{const e=yield(0,r.sendFeedback)(s,l,t);return t.log("sent native feedback"),e}catch(e){return t.err("error native feedback",e),!1}}))},form:function(i,s){return i||t.err("No appID provided"),s||t.err("No publicKey provided"),new a.Form(e,i,s)}}}},712:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0,t.Config=class{constructor(){this.variables={},this.variables.env="prod",this.variables.debug=!1}get(e){return this.variables[e]}set(e,t){this.variables[e]=t}}},954:function(e,t,i){var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(a,o){function n(e){try{c(s.next(e))}catch(e){o(e)}}function r(e){try{c(s.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,r)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Form=void 0;const a=i(5),o=i(341),n=i(183);t.Form=class{constructor(e,t,i){this.config=e,this.log=new a.Log(e),this.formOptionsConfig={addButton:!0,sendButtonText:"Send",backButtonText:"Back",nextButtonText:"Next",addSuccessScreen:!0,getMetaData:!0,questionFormat:"standard"},this.selector="",this.appId=t,this.publicKey=i,this.url=e.get("url"),this.id="",this.formData=null,this.feedback={text:"",answers:[],profile:[],metrics:[],metadata:[]},this.questions=[],this.elementQuestions=[],this.questionInProcess=null,this.history={},this.progress=0,this.total=0}generate(e,t){return s(this,void 0,void 0,(function*(){try{this.formOptionsConfig=Object.assign(Object.assign({},this.formOptionsConfig),t),this.selector=e;const i=localStorage.getItem(`magicfeedback-${this.appId}`);if(i&&new Date(JSON.parse(i).savedAt)<new Date((new Date).getTime()+864e5)?(this.formData=JSON.parse(i),(0,o.getForm)(this.url,this.appId,this.publicKey,this.log).then((e=>{var t,i;(null==e?void 0:e.updatedAt)&&(null===(t=this.formData)||void 0===t?void 0:t.savedAt)&&(null==e?void 0:e.updatedAt)>(null===(i=this.formData)||void 0===i?void 0:i.savedAt)&&(console.log("Form updated"),this.formData=e,this.formData.savedAt=new Date,this.formData.questions&&(this.questions=this.formData.questions,this.total=this.questions.length),localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData)),this.generateForm())}))):this.formData=yield(0,o.getForm)(this.url,this.appId,this.publicKey,this.log),void 0===this.formData||!this.formData)throw new Error(`No form for app ${this.appId}`);if(this.formData.savedAt||(this.formData.savedAt=new Date,localStorage.setItem(`magicfeedback-${this.appId}`,JSON.stringify(this.formData))),this.questions=this.formData.questions,void 0===this.questions||!this.questions)throw new Error(`No questions for app ${this.appId}`);this.total=this.questions.length,this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,progress:this.progress,total:this.total,formData:this.formData})),this.formOptionsConfig.getMetaData&&this.getMetaData(),this.generateForm()}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&(yield this.formOptionsConfig.onLoadedEvent({loading:!1,error:e})))}}))}generateForm(){var e,t;try{this.questions.sort(((e,t)=>e.position-t.position));const i=document.getElementById(this.selector);if(!i)throw new Error(`Element with ID '${this.selector}' not found.`);i.classList.add("magicfeedback-container"),i.id="magicfeedback-container-"+this.appId,i.innerHTML="";const s=document.createElement("form");s.classList.add("magicfeedback-form"),s.id="magicfeedback-"+this.appId;const a=document.createElement("div");if(a.classList.add("magicfeedback-questions"),a.id="magicfeedback-questions-"+this.appId,this.elementQuestions=(0,n.renderQuestions)(this.questions,this.formOptionsConfig.questionFormat),"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,a.appendChild(this.history[0][0].element)):this.elementQuestions.forEach((e=>a.appendChild(e))),s.appendChild(a),i.appendChild(s),this.formOptionsConfig.addButton){const e=(0,n.renderActions)(null===(t=this.formData)||void 0===t?void 0:t.identity,(()=>this.back()),this.formOptionsConfig.sendButtonText,this.formOptionsConfig.backButtonText,this.formOptionsConfig.nextButtonText);s.appendChild(e)}s.addEventListener("submit",(e=>{e.preventDefault(),this.send()}))}catch(e){return this.log.err(e),void(this.formOptionsConfig.onLoadedEvent&&this.formOptionsConfig.onLoadedEvent({loading:!1,error:e}))}}getMetaData(){this.feedback.metadata.push({key:"navigator-url",value:[window.location.href]}),this.feedback.metadata.push({key:"navigator-origin",value:[window.location.origin]}),this.feedback.metadata.push({key:"navigator-pathname",value:[window.location.pathname]}),this.feedback.metadata.push({key:"navigator-search",value:[window.location.search]}),this.feedback.metadata.push({key:"navigator-user",value:[navigator.userAgent]}),this.feedback.metadata.push({key:"navigator-language",value:[navigator.language]}),this.feedback.metadata.push({key:"navigator-platform",value:[navigator.platform]}),this.feedback.metadata.push({key:"navigator-appVersion",value:[navigator.appVersion]}),this.feedback.metadata.push({key:"navigator-appName",value:[navigator.appName]}),this.feedback.metadata.push({key:"navigator-product",value:[navigator.product]}),this.feedback.metadata.push({key:"screen-width",value:[window.screen.width.toString()]}),this.feedback.metadata.push({key:"screen-height",value:[window.screen.height.toString()]})}send(e,t,i){var a;return s(this,void 0,void 0,(function*(){const s=document.getElementById("magicfeedback-container-"+this.appId),o=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===(a=this.formData)||void 0===a?void 0:a.identity));n&&(this.id=n,yield this.processNextQuestion(s,o)),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 s=e.type,a=e.classList[0],n={key:e.name,value:[]},r="magicfeedback-boolean"===a?e.checked.toString():e.value;if(n.key&&""!==n.key)switch(s){case"radio":case"checkbox":if("magicfeedback-boolean"===a||e.checked){n.value.push(r);const e=t.findIndex((e=>e.key===n.key));-1!==e?t[e].value=[...t[e].value,...n.value]:t.push(n)}break;case"email":(0,o.validateEmail)(r)?(this.feedback.profile.push({key:"email",value:[r]}),n.value.push(r),t.push(n)):(this.log.err("Invalid email"),i=!0);break;default:""!==r&&(n.value.push(r),t.push(n))}})),this.feedback.answers=i?[]:t}pushAnswers(e=!1){var t,i;return s(this,void 0,void 0,(function*(){try{if(this.answer(),"MAGICFORM"===(null===(t=this.formData)||void 0===t?void 0:t.identity)){if(0===this.feedback.answers.length)throw new Error("No answers provided");this.questions.forEach((e=>{if(e.require&&!this.feedback.answers.find((t=>t.key===e.ref)))throw new Error(`No answer provided for question ${e.title}`)}))}else if(!e&&(null===(i=this.questionInProcess)||void 0===i?void 0:i.require)&&0===this.feedback.answers.length)throw new Error("No answers provided");const s=this.config.get("url"),a={integration:this.appId,publicKey:this.publicKey,feedback:this.feedback,completed:e};return yield(0,o.sendFeedback)(s,this.id?Object.assign(Object.assign({},a),{sessionId:this.id}):a,this.log)}catch(e){return this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),""}}))}callFollowUpQuestion(e){return s(this,void 0,void 0,(function*(){if(!(null==e?void 0:e.followup))return null;try{if(0===this.feedback.answers.length)throw new Error("No answers provided");const t=this.config.get("url"),i={answer:this.feedback.answers[0].value[0],publicKey:this.publicKey,sessionId:this.id,question:e};return yield(0,o.getFollowUpQuestion)(t,i,this.log)}catch(e){throw this.log.err(`An error occurred while submitting the form ${this.appId}:`,e),e}}))}processNextQuestion(e,t){var i,a,o;return s(this,void 0,void 0,(function*(){if("MAGICSURVEY"===(null===(i=this.formData)||void 0===i?void 0:i.identity))if(null===(a=this.questionInProcess)||void 0===a?void 0:a.followup){const i=yield this.callFollowUpQuestion(this.questionInProcess);if(i){this.questionInProcess=i;const e=(0,n.renderQuestions)([i],null===(o=this.formOptionsConfig)||void 0===o?void 0:o.questionFormat)[0];this.history[this.progress].push({object:i,element:e}),t.removeChild(t.childNodes[0]),t.appendChild(e)}else this.renderNextQuestion(t,e)}else this.renderNextQuestion(t,e);else if(this.total=this.questions.length,this.progress=this.questions.length,this.formOptionsConfig.addSuccessScreen){e.childNodes.length>0&&e.removeChild(e.childNodes[0]);const t=(0,n.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");e.appendChild(t)}}))}renderNextQuestion(e,t){if(this.progress++,this.progress<this.total)this.questionInProcess=this.history[this.progress][0].object,e.removeChild(e.childNodes[0]),e.appendChild(this.history[this.progress][0].element);else{if(this.formOptionsConfig.addSuccessScreen){t.childNodes.length>0&&t.removeChild(t.childNodes[0]);const e=(0,n.renderSuccess)(this.formOptionsConfig.successMessage||"Thank you for your feedback!");t.appendChild(e)}this.pushAnswers(!0)}}back(){if(0===this.progress)return;const e=document.getElementById("magicfeedback-questions-"+this.appId);e.removeChild(e.childNodes[0]),this.history[this.progress].length>1?this.history[this.progress].pop():this.progress--;const t=this.history[this.progress][this.history[this.progress].length-1];this.questionInProcess=t.object,e.appendChild(t.element)}}},374:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={sdk:{app:(e,t)=>`sdk/app/${e}/${t}`,app_info:(e,t)=>`sdk/app/${e}/${t}/info`,feedback:"sdk/feedback",followUpQuestion:"sdk/followUpQuestion"}}},183:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.renderSuccess=t.renderError=t.renderActions=t.renderQuestions=void 0,t.renderQuestions=function(e,t="standard"){if(!e)throw new Error("[MagicFeedback] No questions provided");const i=[];return e.forEach((e=>{const{id:s,title:a,type:o,ref:n,require:r,value:c,defaultValue:d}=e;let l,u,h=document.createElement("div");switch(h.classList.add("magicfeedback-div"),o){case"TEXT":l=document.createElement("input"),l.type="text",l.placeholder="slim"===t?a:"Write your answer here...",u="magicfeedback-text";break;case"LONGTEXT":l=document.createElement("textarea"),l.rows=3,l.placeholder="slim"===t?a:"Write your answer here...",u="magicfeedback-longtext";break;case"NUMBER":l=document.createElement("input"),l.type="number",l.placeholder="slim"===t?a:"Insert a number here",u="magicfeedback-number",c.length&&(c.sort(((e,t)=>Number(e)-Number(t))),l.max=c[c.length-1],l.min=c[0],l.value=c[0]);break;case"RADIO":case"MULTIPLECHOICE":l=document.createElement("div"),u="magicfeedback-"+("RADIO"===o?"radio":"checkbox"),c.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.classList.add(u),a.classList.add("magicfeedback-input"),e===d&&(a.checked=!0),s.textContent=e,s.htmlFor=`rating-${n}-${t}`,i.appendChild(a),i.appendChild(s),l.appendChild(i)}));break;case"RATING":case"WIDGET_RATING_EMOJI_1_10":case"WIDGET_RATING_EMOJI_1_5":l=document.createElement("div"),u="magicfeedback-rating";const e=document.createElement("div");e.classList.add("magicfeedback-rating-container");const i=["WIDGET_RATING_EMOJI_1_5","WIDGET_RATING_NUMBER_1_5"].includes(o)?5:10;for(let t=1;t<=i;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 a=document.createElement("label");a.htmlFor=`rating-${n}-${t}`,a.textContent=t.toString();const r=document.createElement("img");if(["WIDGET_RATING_EMOJI_1_5"].includes(o))switch(t){case 1:r.src="https://magicfeedback-c6458-dev.web.app/assets/1.svg";break;case 2:r.src="https://magicfeedback-c6458-dev.web.app/assets/2.svg";break;case 3:r.src="https://magicfeedback-c6458-dev.web.app/assets/6.svg";break;case 4:r.src="https://magicfeedback-c6458-dev.web.app/assets/9.svg";break;case 5:r.src="https://magicfeedback-c6458-dev.web.app/assets/10.svg"}else r.src=`https://magicfeedback-c6458-dev.web.app/assets/${t}.svg`;r.alt=`face-${n}-${t}`,r.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.classList.add(u),c.classList.add("magicfeedback-input"),s.appendChild(c),["WIDGET_RATING_EMOJI_1_5","WIDGET_RATING_EMOJI_1_10","RATING"].includes(o)?s.appendChild(r):s.classList.add("magicfeedback-rating-option-label-container-number"),s.appendChild(a),i.appendChild(s),e.appendChild(i)}l.appendChild(e);break;case"WIDGET_RATING_NUMBER_1_10":case"WIDGET_RATING_NUMBER_1_5":l=document.createElement("div"),u="magicfeedback-rating-number";const s=document.createElement("div");s.classList.add("magicfeedback-rating-number-container");const r=["WIDGET_RATING_NUMBER_1_5"].includes(o)?5:10;for(let e=1;e<=r;e++){const t=document.createElement("div");t.classList.add("magicfeedback-rating-number-option");const i=document.createElement("label");i.htmlFor=`rating-${n}-${e}`,i.classList.add("magicfeedback-rating-number-option-label-container");const a=document.createElement("label");a.htmlFor=`rating-${n}-${e}`,a.textContent=e.toString();const o=document.createElement("input");o.id=`rating-${n}-${e}`,o.type="radio",o.name=n,o.value=e.toString(),o.classList.add(u),o.classList.add("magicfeedback-input"),i.appendChild(o),i.appendChild(a),t.appendChild(i),s.appendChild(t)}l.appendChild(s);break;case"WIDGET_RATING_STAR_1_5":l=document.createElement("div"),u="magicfeedback-rating-star";const h=function(){const e="magicfeedback-rating-star-selected",t=document.createElement("div");t.classList.add("magicfeedback-rating-star-container");for(let i=1;i<=5;i++){const s=document.createElement("label");s.classList.add("magicfeedback-rating-star-option");const a=document.createElement("input");a.type="radio",a.name="rating",a.value=i.toString(),a.style.position="absolute",a.style.opacity="0",a.style.width="0",a.style.height="0",a.addEventListener("change",(()=>{const i=t.querySelectorAll(".rating__star");for(let t=0;t<i.length;t++)t+1<=Number(a.value)?i[t].classList.contains(e)||i[t].classList.add(e):i[t].classList.contains(e)&&i[t].classList.remove(e)})),s.appendChild(a);const o=document.createElement("span");o.classList.add("rating__star"),o.textContent="★",o.style.fontSize="40px",o.style.cursor="pointer",s.appendChild(o),t.appendChild(s)}return t}();l.appendChild(h);break;case"SELECT":l=document.createElement("select"),u="magicfeedback-select",l.placeholder="slim"===t?a:"Select an option",c.forEach((e=>{const t=document.createElement("option");t.value=e,t.text=e,l.appendChild(t)}));break;case"DATE":l=document.createElement("input"),l.type="date",l.placeholder="slim"===t?a:"Select a date",u="magicfeedback-date";break;case"BOOLEAN":l=document.createElement("input"),l.type="checkbox",u="magicfeedback-boolean";break;case"EMAIL":l=document.createElement("input"),l.type="email",l.placeholder="slim"===t?a:"you@example.com",u="magicfeedback-email";break;case"PASSWORD":l=document.createElement("input"),l.type="password",l.placeholder="slim"===t?a:"Write your password here",u="magicfeedback-password";break;case"CONTACT":l=document.createElement("input"),l.type="tel",l.placeholder="slim"===t?a:"Enter your phone number",u="magicfeedback-contact";break;default:return}l.id=`magicfeedback-${s}`,l.setAttribute("name",n),l.classList.add(u),void 0!==d&&(l.value=d),["RADIO","MULTIPLECHOICE"].includes(o)||(l.classList.add("magicfeedback-input"),l.required=r);const p=document.createElement("label");p.setAttribute("for",`magicfeedback-${s}`),p.textContent=a,p.classList.add("magicfeedback-label"),["BOOLEAN"].includes(o)?(h.classList.add("magicfeedback-boolean-container"),h.appendChild(l),h.appendChild(p)):("slim"!==t&&h.appendChild(p),h.appendChild(l)),i.push(h)})),i},t.renderActions=function(e="",t,i="Submit",s="Back",a="Next"){const o=document.createElement("div");o.classList.add("magicfeedback-action-container");const n=document.createElement("button");n.id="magicfeedback-submit",n.type="submit",n.classList.add("magicfeedback-submit"),n.textContent="MAGICSURVEY"===e?a||"Next":i||"Submit";const r=document.createElement("button");return r.id="magicfeedback-back",r.type="button",r.classList.add("magicfeedback-back"),r.textContent=s||"Back",r.addEventListener("click",t),"MAGICSURVEY"===e&&o.appendChild(r),o.appendChild(n),o},t.renderError=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-error"),t.textContent=e,t},t.renderSuccess=function(e){const t=document.createElement("div");return t.classList.add("magicfeedback-success"),t.textContent=e,t}},341:function(e,t,i){var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(a,o){function n(e){try{c(s.next(e))}catch(e){o(e)}}function r(e){try{c(s.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,r)}c((s=s.apply(e,t||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getFollowUpQuestion=t.sendFeedback=t.getQuestions=t.getForm=t.validateEmail=void 0;const o=a(i(31)),n=a(i(147)),r=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,a){return s(this,void 0,void 0,(function*(){try{const s=yield(0,o.default)(e+r.endpoints.sdk.app_info(t,i),{method:"GET",headers:c});if(s.ok){const e=yield s.json();return a.log(`Received form for app ${t}`,e),e}throw a.err(`Failed to get questions for app ${t}:`,s.status,s.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return a.err(e),null}}))},t.getQuestions=function(e,t,i,a){return s(this,void 0,void 0,(function*(){try{const s=yield(0,o.default)(e+r.endpoints.sdk.app(t,i),{method:"GET",headers:c});if(s.ok){const e=yield s.json();return a.log(`Received questions for app ${t}`,e),e}throw a.err(`Failed to get questions for app ${t}:`,s.status,s.statusText),new Error("[MagicFeedback] Bad response from server")}catch(e){return a.err(e),[]}}))},t.sendFeedback=function(e,t,i){return s(this,void 0,void 0,(function*(){try{const s=yield(0,o.default)(e+r.endpoints.sdk.feedback,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(s.ok)return i.log(`Form ${t.integration} submitted successfully!`),(yield s.json()).sessionId;throw i.err(`Failed to submit form ${t.integration}:`,s.status,s.statusText),new Error(s.statusText)}catch(e){return i.err(e),""}}))},t.getFollowUpQuestion=function(e,t,i){return s(this,void 0,void 0,(function*(){try{const s=yield(0,o.default)(e+r.endpoints.sdk.followUpQuestion,{method:"POST",headers:Object.assign({"Content-Type":"application/json"},c),body:JSON.stringify(t)});if(s.ok)return i.log(`Received follow up question for form ${t.integration}`),(yield s.json())||"";throw i.err(`Failed to get follow up question for form ${t.integration}:`,s.status,s.statusText),new Error(s.statusText)}catch(e){return i.err(e),""}}))}},5:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Log=void 0,t.Log=class{constructor(e){this.config=e}log(...e){this.config.get("debug")&&console.log("[MagicFeedback]:",...e)}err(...e){console.error("[MagicFeedback]:",...e)}}},31:e=>{e.exports=require("cross-fetch")},147:e=>{e.exports=JSON.parse('{"name":"@magicfeedback/native","version":"1.1.14-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 a=t[s];if(void 0!==a)return a.exports;var o=t[s]={exports:{}};return e[s].call(o.exports,o,o.exports,i),o.exports}(607);return i.default})()));
|
|
@@ -33,13 +33,18 @@ export declare class Form {
|
|
|
33
33
|
* @param selector
|
|
34
34
|
* @param options
|
|
35
35
|
*/
|
|
36
|
-
generate(selector: string, options
|
|
36
|
+
generate(selector: string, options: generateFormOptions): Promise<void>;
|
|
37
37
|
/**
|
|
38
38
|
* Create
|
|
39
39
|
*
|
|
40
40
|
* TODO: Add option to generate in <form> or in other <tag>
|
|
41
41
|
*/
|
|
42
42
|
private generateForm;
|
|
43
|
+
/**
|
|
44
|
+
* Get the metadata from the URL, navigators and others
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
private getMetaData;
|
|
43
48
|
/**
|
|
44
49
|
* Send current answer and verify if its necessary continue with a new question
|
|
45
50
|
* @pubilc
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NativeQuestion } from "./types";
|
|
1
2
|
export declare class FormData {
|
|
2
3
|
id: string;
|
|
3
4
|
name: string;
|
|
@@ -7,11 +8,13 @@ export declare class FormData {
|
|
|
7
8
|
status: string;
|
|
8
9
|
createdAt: Date;
|
|
9
10
|
updatedAt: Date;
|
|
11
|
+
savedAt?: Date;
|
|
10
12
|
externalId?: string | null;
|
|
11
13
|
companyId: string;
|
|
12
14
|
productId: string;
|
|
13
15
|
userId: string;
|
|
14
16
|
setting: Record<string, any>;
|
|
15
17
|
conf: Record<string, any>;
|
|
16
|
-
|
|
18
|
+
questions: NativeQuestion[];
|
|
19
|
+
constructor(id: string, name: string, description: string, type: string, identity: string, status: string, createdAt: Date, updatedAt: Date, externalId: string | null, companyId: string, productId: string, userId: string, setting: Record<string, any>, conf: Record<string, any>, questions: NativeQuestion[]);
|
|
17
20
|
}
|
|
@@ -23,7 +23,12 @@ export declare enum FEEDBACKAPPANSWERTYPE {
|
|
|
23
23
|
EMAIL = "EMAIL",
|
|
24
24
|
PASSWORD = "PASSWORD",
|
|
25
25
|
RATING = "RATING",
|
|
26
|
-
CONTACT = "CONTACT"
|
|
26
|
+
CONTACT = "CONTACT",
|
|
27
|
+
WIDGET_RATING_EMOJI_1_10 = "WIDGET_RATING_EMOJI_1_10",
|
|
28
|
+
WIDGET_RATING_EMOJI_1_5 = "WIDGET_RATING_EMOJI_1_5",
|
|
29
|
+
WIDGET_RATING_NUMBER_1_10 = "WIDGET_RATING_NUMBER_1_10",
|
|
30
|
+
WIDGET_RATING_NUMBER_1_5 = "WIDGET_RATING_NUMBER_1_5",
|
|
31
|
+
WIDGET_RATING_STAR_1_5 = "WIDGET_RATING_STAR_1_5"
|
|
27
32
|
}
|
|
28
33
|
export type NativeQuestion = {
|
|
29
34
|
id: string;
|
|
@@ -36,6 +41,7 @@ export type NativeQuestion = {
|
|
|
36
41
|
defaultValue: string;
|
|
37
42
|
appId: string;
|
|
38
43
|
followup: boolean;
|
|
44
|
+
position: number;
|
|
39
45
|
};
|
|
40
46
|
export type NativeAnswer = {
|
|
41
47
|
key: string;
|
|
@@ -56,6 +62,7 @@ export type generateFormOptions = {
|
|
|
56
62
|
addSuccessScreen?: boolean;
|
|
57
63
|
successMessage?: string;
|
|
58
64
|
questionFormat?: "standard" | "slim";
|
|
65
|
+
getMetaData?: boolean;
|
|
59
66
|
tag?: generateFormOptionsTag;
|
|
60
67
|
afterSubmitEvent?: Function;
|
|
61
68
|
beforeSubmitEvent?: Function;
|