@fuul/sdk 0.17.0 → 1.0.0
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 +21 -26
- package/dist/constants.d.ts.map +1 -0
- package/dist/fuul-sdk.mjs +1569 -0
- package/dist/fuul-sdk.umd.js +3 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/{lib/cjs/types → dist}/infrastructure/conversions/conversionService.d.ts +2 -2
- package/dist/infrastructure/conversions/conversionService.d.ts.map +1 -0
- package/{lib/cjs/types → dist}/infrastructure/conversions/dtos.d.ts +4 -0
- package/dist/infrastructure/conversions/dtos.d.ts.map +1 -0
- package/{lib/cjs/types → dist}/infrastructure/http/HttpClient.d.ts +1 -1
- package/dist/infrastructure/http/HttpClient.d.ts.map +1 -0
- package/dist/types/index.d.ts +37 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/events.d.ts +4 -0
- package/dist/utils/events.d.ts.map +1 -0
- package/{lib/cjs/types → dist}/utils/localStorage.d.ts +5 -0
- package/dist/utils/localStorage.d.ts.map +1 -0
- package/dist/utils/queryParams.d.ts.map +1 -0
- package/package.json +55 -17
- package/lib/cjs/constants.js +0 -15
- package/lib/cjs/index.js +0 -247
- package/lib/cjs/infrastructure/conversions/conversionService.js +0 -24
- package/lib/cjs/infrastructure/conversions/dtos.js +0 -2
- package/lib/cjs/infrastructure/http/HttpClient.js +0 -51
- package/lib/cjs/types/constants.d.ts.map +0 -1
- package/lib/cjs/types/index.d.ts +0 -46
- package/lib/cjs/types/index.d.ts.map +0 -1
- package/lib/cjs/types/index.js +0 -2
- package/lib/cjs/types/infrastructure/conversions/conversionService.d.ts.map +0 -1
- package/lib/cjs/types/infrastructure/conversions/dtos.d.ts.map +0 -1
- package/lib/cjs/types/infrastructure/http/HttpClient.d.ts.map +0 -1
- package/lib/cjs/types/types/index.d.ts +0 -27
- package/lib/cjs/types/types/index.d.ts.map +0 -1
- package/lib/cjs/types/utils/localStorage.d.ts.map +0 -1
- package/lib/cjs/types/utils/queryParams.d.ts.map +0 -1
- package/lib/cjs/utils/localStorage.js +0 -20
- package/lib/cjs/utils/queryParams.js +0 -14
- package/lib/esm/constants.js +0 -12
- package/lib/esm/index.mjs +0 -243
- package/lib/esm/infrastructure/conversions/conversionService.js +0 -20
- package/lib/esm/infrastructure/conversions/dtos.js +0 -1
- package/lib/esm/infrastructure/http/HttpClient.js +0 -44
- package/lib/esm/types/constants.d.ts +0 -13
- package/lib/esm/types/constants.d.ts.map +0 -1
- package/lib/esm/types/index.d.ts +0 -46
- package/lib/esm/types/index.d.ts.map +0 -1
- package/lib/esm/types/index.js +0 -1
- package/lib/esm/types/infrastructure/conversions/conversionService.d.ts +0 -8
- package/lib/esm/types/infrastructure/conversions/conversionService.d.ts.map +0 -1
- package/lib/esm/types/infrastructure/conversions/dtos.d.ts +0 -33
- package/lib/esm/types/infrastructure/conversions/dtos.d.ts.map +0 -1
- package/lib/esm/types/infrastructure/http/HttpClient.d.ts +0 -27
- package/lib/esm/types/infrastructure/http/HttpClient.d.ts.map +0 -1
- package/lib/esm/types/types/index.d.ts +0 -27
- package/lib/esm/types/types/index.d.ts.map +0 -1
- package/lib/esm/types/utils/localStorage.d.ts +0 -9
- package/lib/esm/types/utils/localStorage.d.ts.map +0 -1
- package/lib/esm/types/utils/queryParams.d.ts +0 -2
- package/lib/esm/types/utils/queryParams.d.ts.map +0 -1
- package/lib/esm/utils/localStorage.js +0 -9
- package/lib/esm/utils/queryParams.js +0 -10
- /package/{lib/cjs/types → dist}/constants.d.ts +0 -0
- /package/{lib/cjs/types → dist}/utils/queryParams.d.ts +0 -0
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
(function(g,w){typeof exports=="object"&&typeof module<"u"?module.exports=w():typeof define=="function"&&define.amd?define(w):(g=typeof globalThis<"u"?globalThis:g||self,g.FuulSdk=w())})(this,function(){"use strict";var Tn=Object.defineProperty;var _n=(g,w,P)=>w in g?Tn(g,w,{enumerable:!0,configurable:!0,writable:!0,value:P}):g[w]=P;var _=(g,w,P)=>(_n(g,typeof w!="symbol"?w+"":w,P),P);let g=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");const w="fuul.session_id",P="fuul.tracking_id",de="fuul.referrer_id",D="fuul.traffic_source",q="fuul.traffic_category",H="fuul.traffic_title",he="fuul.traffic_tag",Ve="fuul.traffic_origin_url",pe="fuul.sent",We=["google.com","bing.com","yahoo.com"],Ye=()=>localStorage.getItem(w),me=()=>localStorage.getItem(P),Ge=()=>localStorage.getItem(de),Xe=()=>localStorage.getItem(D),Qe=()=>localStorage.getItem(q),Ze=()=>localStorage.getItem(H),et=()=>localStorage.getItem(he),L=typeof window>"u"||typeof document>"u",ye=()=>g(),tt=()=>{L||localStorage.setItem(w,ye())},nt=()=>{L||me()||localStorage.setItem(P,ye())},rt=()=>{if(L)return;const e=new URLSearchParams(window.location.search);localStorage.setItem(de,e.get("referrer")??""),localStorage.setItem(D,e.get("source")??""),localStorage.setItem(q,e.get("category")??""),localStorage.setItem(H,e.get("title")??""),localStorage.setItem(he,e.get("tag")??""),localStorage.setItem(Ve,document.referrer??""),st()},st=()=>{const e=new URLSearchParams(window.location.search),t=e.get("source"),n=e.get("referrer");if(!t)if(n)localStorage.setItem(D,"affiliate"),localStorage.setItem(q,"affiliate"),localStorage.setItem(H,n);else{const r=document.referrer;localStorage.setItem(q,r),localStorage.setItem(H,r),We.includes(r)?localStorage.setItem(D,"organic"):localStorage.setItem(D,"direct")}};function Ee(e,t){return function(){return e.apply(t,arguments)}}const{toString:Se}=Object.prototype,{getPrototypeOf:X}=Object,Q=(e=>t=>{const n=Se.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),A=e=>(e=e.toLowerCase(),t=>Q(t)===e),M=e=>t=>typeof t===e,{isArray:x}=Array,U=M("undefined");function ot(e){return e!==null&&!U(e)&&e.constructor!==null&&!U(e.constructor)&&N(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const we=A("ArrayBuffer");function it(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&we(e.buffer),t}const at=M("string"),N=M("function"),ge=M("number"),Z=e=>e!==null&&typeof e=="object",ct=e=>e===!0||e===!1,K=e=>{if(Q(e)!=="object")return!1;const t=X(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)},ut=A("Date"),lt=A("File"),ft=A("Blob"),dt=A("FileList"),ht=e=>Z(e)&&N(e.pipe),pt=e=>{const t="[object FormData]";return e&&(typeof FormData=="function"&&e instanceof FormData||Se.call(e)===t||N(e.toString)&&e.toString()===t)},mt=A("URLSearchParams"),yt=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function B(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,s;if(typeof e!="object"&&(e=[e]),x(e))for(r=0,s=e.length;r<s;r++)t.call(null,e[r],r,e);else{const o=n?Object.getOwnPropertyNames(e):Object.keys(e),i=o.length;let u;for(r=0;r<i;r++)u=o[r],t.call(null,e[u],u,e)}}function Re(e,t){t=t.toLowerCase();const n=Object.keys(e);let r=n.length,s;for(;r-- >0;)if(s=n[r],t===s.toLowerCase())return s;return null}const be=(()=>typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global)(),Ae=e=>!U(e)&&e!==be;function ee(){const{caseless:e}=Ae(this)&&this||{},t={},n=(r,s)=>{const o=e&&Re(t,s)||s;K(t[o])&&K(r)?t[o]=ee(t[o],r):K(r)?t[o]=ee({},r):x(r)?t[o]=r.slice():t[o]=r};for(let r=0,s=arguments.length;r<s;r++)arguments[r]&&B(arguments[r],n);return t}const Et=(e,t,n,{allOwnKeys:r}={})=>(B(t,(s,o)=>{n&&N(s)?e[o]=Ee(s,n):e[o]=s},{allOwnKeys:r}),e),St=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),wt=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},gt=(e,t,n,r)=>{let s,o,i;const u={};if(t=t||{},e==null)return t;do{for(s=Object.getOwnPropertyNames(e),o=s.length;o-- >0;)i=s[o],(!r||r(i,e,t))&&!u[i]&&(t[i]=e[i],u[i]=!0);e=n!==!1&&X(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Rt=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},bt=e=>{if(!e)return null;if(x(e))return e;let t=e.length;if(!ge(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},At=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&X(Uint8Array)),Ot=(e,t)=>{const r=(e&&e[Symbol.iterator]).call(e);let s;for(;(s=r.next())&&!s.done;){const o=s.value;t.call(e,o[0],o[1])}},Tt=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},_t=A("HTMLFormElement"),Pt=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,s){return r.toUpperCase()+s}),Oe=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Nt=A("RegExp"),Te=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};B(n,(s,o)=>{t(s,o,e)!==!1&&(r[o]=s)}),Object.defineProperties(e,r)},Ct=e=>{Te(e,(t,n)=>{if(N(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(N(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},xt=(e,t)=>{const n={},r=s=>{s.forEach(o=>{n[o]=!0})};return x(e)?r(e):r(String(e).split(t)),n},It=()=>{},Ft=(e,t)=>(e=+e,Number.isFinite(e)?e:t),te="abcdefghijklmnopqrstuvwxyz",_e="0123456789",Pe={DIGIT:_e,ALPHA:te,ALPHA_DIGIT:te+te.toUpperCase()+_e},Dt=(e=16,t=Pe.ALPHA_DIGIT)=>{let n="";const{length:r}=t;for(;e--;)n+=t[Math.random()*r|0];return n};function Lt(e){return!!(e&&N(e.append)&&e[Symbol.toStringTag]==="FormData"&&e[Symbol.iterator])}const a={isArray:x,isArrayBuffer:we,isBuffer:ot,isFormData:pt,isArrayBufferView:it,isString:at,isNumber:ge,isBoolean:ct,isObject:Z,isPlainObject:K,isUndefined:U,isDate:ut,isFile:lt,isBlob:ft,isRegExp:Nt,isFunction:N,isStream:ht,isURLSearchParams:mt,isTypedArray:At,isFileList:dt,forEach:B,merge:ee,extend:Et,trim:yt,stripBOM:St,inherits:wt,toFlatObject:gt,kindOf:Q,kindOfTest:A,endsWith:Rt,toArray:bt,forEachEntry:Ot,matchAll:Tt,isHTMLForm:_t,hasOwnProperty:Oe,hasOwnProp:Oe,reduceDescriptors:Te,freezeMethods:Ct,toObjectSet:xt,toCamelCase:Pt,noop:It,toFiniteNumber:Ft,findKey:Re,global:be,isContextDefined:Ae,ALPHABET:Pe,generateString:Dt,isSpecCompliantForm:Lt,toJSONObject:e=>{const t=new Array(10),n=(r,s)=>{if(Z(r)){if(t.indexOf(r)>=0)return;if(!("toJSON"in r)){t[s]=r;const o=x(r)?[]:{};return B(r,(i,u)=>{const d=n(i,s+1);!U(d)&&(o[u]=d)}),t[s]=void 0,o}}return r};return n(e,0)}};function m(e,t,n,r,s){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),s&&(this.response=s)}a.inherits(m,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:a.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const Ne=m.prototype,Ce={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{Ce[e]={value:e}}),Object.defineProperties(m,Ce),Object.defineProperty(Ne,"isAxiosError",{value:!0}),m.from=(e,t,n,r,s,o)=>{const i=Object.create(Ne);return a.toFlatObject(e,i,function(d){return d!==Error.prototype},u=>u!=="isAxiosError"),m.call(i,e.message,t,n,r,s),i.cause=e,i.name=e.name,o&&Object.assign(i,o),i};const Ut=null;function ne(e){return a.isPlainObject(e)||a.isArray(e)}function xe(e){return a.endsWith(e,"[]")?e.slice(0,-2):e}function Ie(e,t,n){return e?e.concat(t).map(function(s,o){return s=xe(s),!n&&o?"["+s+"]":s}).join(n?".":""):t}function Bt(e){return a.isArray(e)&&!e.some(ne)}const kt=a.toFlatObject(a,{},null,function(t){return/^is[A-Z]/.test(t)});function v(e,t,n){if(!a.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=a.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(p,T){return!a.isUndefined(T[p])});const r=n.metaTokens,s=n.visitor||l,o=n.dots,i=n.indexes,d=(n.Blob||typeof Blob<"u"&&Blob)&&a.isSpecCompliantForm(t);if(!a.isFunction(s))throw new TypeError("visitor must be a function");function c(f){if(f===null)return"";if(a.isDate(f))return f.toISOString();if(!d&&a.isBlob(f))throw new m("Blob is not supported. Use a Buffer instead.");return a.isArrayBuffer(f)||a.isTypedArray(f)?d&&typeof Blob=="function"?new Blob([f]):Buffer.from(f):f}function l(f,p,T){let R=f;if(f&&!T&&typeof f=="object"){if(a.endsWith(p,"{}"))p=r?p:p.slice(0,-2),f=JSON.stringify(f);else if(a.isArray(f)&&Bt(f)||(a.isFileList(f)||a.endsWith(p,"[]"))&&(R=a.toArray(f)))return p=xe(p),R.forEach(function(G,On){!(a.isUndefined(G)||G===null)&&t.append(i===!0?Ie([p],On,o):i===null?p:p+"[]",c(G))}),!1}return ne(f)?!0:(t.append(Ie(T,p,o),c(f)),!1)}const h=[],E=Object.assign(kt,{defaultVisitor:l,convertValue:c,isVisitable:ne});function y(f,p){if(!a.isUndefined(f)){if(h.indexOf(f)!==-1)throw Error("Circular reference detected in "+p.join("."));h.push(f),a.forEach(f,function(R,F){(!(a.isUndefined(R)||R===null)&&s.call(t,R,a.isString(F)?F.trim():F,p,E))===!0&&y(R,p?p.concat(F):[F])}),h.pop()}}if(!a.isObject(e))throw new TypeError("data must be an object");return y(e),t}function Fe(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function re(e,t){this._pairs=[],e&&v(e,this,t)}const De=re.prototype;De.append=function(t,n){this._pairs.push([t,n])},De.toString=function(t){const n=t?function(r){return t.call(this,r,Fe)}:Fe;return this._pairs.map(function(s){return n(s[0])+"="+n(s[1])},"").join("&")};function jt(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function Le(e,t,n){if(!t)return e;const r=n&&n.encode||jt,s=n&&n.serialize;let o;if(s?o=s(t,n):o=a.isURLSearchParams(t)?t.toString():new re(t,n).toString(r),o){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+o}return e}class qt{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){a.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Ue=qt,Be={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Ht=typeof URLSearchParams<"u"?URLSearchParams:re,Mt=typeof FormData<"u"?FormData:null,Kt=typeof Blob<"u"?Blob:null,vt=(()=>{let e;return typeof navigator<"u"&&((e=navigator.product)==="ReactNative"||e==="NativeScript"||e==="NS")?!1:typeof window<"u"&&typeof document<"u"})(),$t=(()=>typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function")(),b={isBrowser:!0,classes:{URLSearchParams:Ht,FormData:Mt,Blob:Kt},isStandardBrowserEnv:vt,isStandardBrowserWebWorkerEnv:$t,protocols:["http","https","file","blob","url","data"]};function zt(e,t){return v(e,new b.classes.URLSearchParams,Object.assign({visitor:function(n,r,s,o){return b.isNode&&a.isBuffer(n)?(this.append(r,n.toString("base64")),!1):o.defaultVisitor.apply(this,arguments)}},t))}function Jt(e){return a.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Vt(e){const t={},n=Object.keys(e);let r;const s=n.length;let o;for(r=0;r<s;r++)o=n[r],t[o]=e[o];return t}function ke(e){function t(n,r,s,o){let i=n[o++];const u=Number.isFinite(+i),d=o>=n.length;return i=!i&&a.isArray(s)?s.length:i,d?(a.hasOwnProp(s,i)?s[i]=[s[i],r]:s[i]=r,!u):((!s[i]||!a.isObject(s[i]))&&(s[i]=[]),t(n,r,s[i],o)&&a.isArray(s[i])&&(s[i]=Vt(s[i])),!u)}if(a.isFormData(e)&&a.isFunction(e.entries)){const n={};return a.forEachEntry(e,(r,s)=>{t(Jt(r),s,n,0)}),n}return null}const Wt={"Content-Type":void 0};function Yt(e,t,n){if(a.isString(e))try{return(t||JSON.parse)(e),a.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const $={transitional:Be,adapter:["xhr","http"],transformRequest:[function(t,n){const r=n.getContentType()||"",s=r.indexOf("application/json")>-1,o=a.isObject(t);if(o&&a.isHTMLForm(t)&&(t=new FormData(t)),a.isFormData(t))return s&&s?JSON.stringify(ke(t)):t;if(a.isArrayBuffer(t)||a.isBuffer(t)||a.isStream(t)||a.isFile(t)||a.isBlob(t))return t;if(a.isArrayBufferView(t))return t.buffer;if(a.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let u;if(o){if(r.indexOf("application/x-www-form-urlencoded")>-1)return zt(t,this.formSerializer).toString();if((u=a.isFileList(t))||r.indexOf("multipart/form-data")>-1){const d=this.env&&this.env.FormData;return v(u?{"files[]":t}:t,d&&new d,this.formSerializer)}}return o||s?(n.setContentType("application/json",!1),Yt(t)):t}],transformResponse:[function(t){const n=this.transitional||$.transitional,r=n&&n.forcedJSONParsing,s=this.responseType==="json";if(t&&a.isString(t)&&(r&&!this.responseType||s)){const i=!(n&&n.silentJSONParsing)&&s;try{return JSON.parse(t)}catch(u){if(i)throw u.name==="SyntaxError"?m.from(u,m.ERR_BAD_RESPONSE,this,null,this.response):u}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:b.classes.FormData,Blob:b.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};a.forEach(["delete","get","head"],function(t){$.headers[t]={}}),a.forEach(["post","put","patch"],function(t){$.headers[t]=a.merge(Wt)});const se=$,Gt=a.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Xt=e=>{const t={};let n,r,s;return e&&e.split(`
|
|
2
|
+
`).forEach(function(i){s=i.indexOf(":"),n=i.substring(0,s).trim().toLowerCase(),r=i.substring(s+1).trim(),!(!n||t[n]&&Gt[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},je=Symbol("internals");function k(e){return e&&String(e).trim().toLowerCase()}function z(e){return e===!1||e==null?e:a.isArray(e)?e.map(z):String(e)}function Qt(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}function Zt(e){return/^[-_a-zA-Z]+$/.test(e.trim())}function oe(e,t,n,r,s){if(a.isFunction(r))return r.call(this,t,n);if(s&&(t=n),!!a.isString(t)){if(a.isString(r))return t.indexOf(r)!==-1;if(a.isRegExp(r))return r.test(t)}}function en(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function tn(e,t){const n=a.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(s,o,i){return this[r].call(this,t,s,o,i)},configurable:!0})})}class J{constructor(t){t&&this.set(t)}set(t,n,r){const s=this;function o(u,d,c){const l=k(d);if(!l)throw new Error("header name must be a non-empty string");const h=a.findKey(s,l);(!h||s[h]===void 0||c===!0||c===void 0&&s[h]!==!1)&&(s[h||d]=z(u))}const i=(u,d)=>a.forEach(u,(c,l)=>o(c,l,d));return a.isPlainObject(t)||t instanceof this.constructor?i(t,n):a.isString(t)&&(t=t.trim())&&!Zt(t)?i(Xt(t),n):t!=null&&o(n,t,r),this}get(t,n){if(t=k(t),t){const r=a.findKey(this,t);if(r){const s=this[r];if(!n)return s;if(n===!0)return Qt(s);if(a.isFunction(n))return n.call(this,s,r);if(a.isRegExp(n))return n.exec(s);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=k(t),t){const r=a.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||oe(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let s=!1;function o(i){if(i=k(i),i){const u=a.findKey(r,i);u&&(!n||oe(r,r[u],u,n))&&(delete r[u],s=!0)}}return a.isArray(t)?t.forEach(o):o(t),s}clear(t){const n=Object.keys(this);let r=n.length,s=!1;for(;r--;){const o=n[r];(!t||oe(this,this[o],o,t,!0))&&(delete this[o],s=!0)}return s}normalize(t){const n=this,r={};return a.forEach(this,(s,o)=>{const i=a.findKey(r,o);if(i){n[i]=z(s),delete n[o];return}const u=t?en(o):String(o).trim();u!==o&&delete n[o],n[u]=z(s),r[u]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return a.forEach(this,(r,s)=>{r!=null&&r!==!1&&(n[s]=t&&a.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
|
|
3
|
+
`)}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(s=>r.set(s)),r}static accessor(t){const r=(this[je]=this[je]={accessors:{}}).accessors,s=this.prototype;function o(i){const u=k(i);r[u]||(tn(s,i),r[u]=!0)}return a.isArray(t)?t.forEach(o):o(t),this}}J.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),a.freezeMethods(J.prototype),a.freezeMethods(J);const O=J;function ie(e,t){const n=this||se,r=t||n,s=O.from(r.headers);let o=r.data;return a.forEach(e,function(u){o=u.call(n,o,s.normalize(),t?t.status:void 0)}),s.normalize(),o}function qe(e){return!!(e&&e.__CANCEL__)}function j(e,t,n){m.call(this,e??"canceled",m.ERR_CANCELED,t,n),this.name="CanceledError"}a.inherits(j,m,{__CANCEL__:!0});function nn(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new m("Request failed with status code "+n.status,[m.ERR_BAD_REQUEST,m.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}const rn=b.isStandardBrowserEnv?function(){return{write:function(n,r,s,o,i,u){const d=[];d.push(n+"="+encodeURIComponent(r)),a.isNumber(s)&&d.push("expires="+new Date(s).toGMTString()),a.isString(o)&&d.push("path="+o),a.isString(i)&&d.push("domain="+i),u===!0&&d.push("secure"),document.cookie=d.join("; ")},read:function(n){const r=document.cookie.match(new RegExp("(^|;\\s*)("+n+")=([^;]*)"));return r?decodeURIComponent(r[3]):null},remove:function(n){this.write(n,"",Date.now()-864e5)}}}():function(){return{write:function(){},read:function(){return null},remove:function(){}}}();function sn(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function on(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}function He(e,t){return e&&!sn(t)?on(e,t):t}const an=b.isStandardBrowserEnv?function(){const t=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");let r;function s(o){let i=o;return t&&(n.setAttribute("href",i),i=n.href),n.setAttribute("href",i),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:n.pathname.charAt(0)==="/"?n.pathname:"/"+n.pathname}}return r=s(window.location.href),function(i){const u=a.isString(i)?s(i):i;return u.protocol===r.protocol&&u.host===r.host}}():function(){return function(){return!0}}();function cn(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function un(e,t){e=e||10;const n=new Array(e),r=new Array(e);let s=0,o=0,i;return t=t!==void 0?t:1e3,function(d){const c=Date.now(),l=r[o];i||(i=c),n[s]=d,r[s]=c;let h=o,E=0;for(;h!==s;)E+=n[h++],h=h%e;if(s=(s+1)%e,s===o&&(o=(o+1)%e),c-i<t)return;const y=l&&c-l;return y?Math.round(E*1e3/y):void 0}}function Me(e,t){let n=0;const r=un(50,250);return s=>{const o=s.loaded,i=s.lengthComputable?s.total:void 0,u=o-n,d=r(u),c=o<=i;n=o;const l={loaded:o,total:i,progress:i?o/i:void 0,bytes:u,rate:d||void 0,estimated:d&&i&&c?(i-o)/d:void 0,event:s};l[t?"download":"upload"]=!0,e(l)}}const V={http:Ut,xhr:typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){let s=e.data;const o=O.from(e.headers).normalize(),i=e.responseType;let u;function d(){e.cancelToken&&e.cancelToken.unsubscribe(u),e.signal&&e.signal.removeEventListener("abort",u)}a.isFormData(s)&&(b.isStandardBrowserEnv||b.isStandardBrowserWebWorkerEnv)&&o.setContentType(!1);let c=new XMLHttpRequest;if(e.auth){const y=e.auth.username||"",f=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";o.set("Authorization","Basic "+btoa(y+":"+f))}const l=He(e.baseURL,e.url);c.open(e.method.toUpperCase(),Le(l,e.params,e.paramsSerializer),!0),c.timeout=e.timeout;function h(){if(!c)return;const y=O.from("getAllResponseHeaders"in c&&c.getAllResponseHeaders()),p={data:!i||i==="text"||i==="json"?c.responseText:c.response,status:c.status,statusText:c.statusText,headers:y,config:e,request:c};nn(function(R){n(R),d()},function(R){r(R),d()},p),c=null}if("onloadend"in c?c.onloadend=h:c.onreadystatechange=function(){!c||c.readyState!==4||c.status===0&&!(c.responseURL&&c.responseURL.indexOf("file:")===0)||setTimeout(h)},c.onabort=function(){c&&(r(new m("Request aborted",m.ECONNABORTED,e,c)),c=null)},c.onerror=function(){r(new m("Network Error",m.ERR_NETWORK,e,c)),c=null},c.ontimeout=function(){let f=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded";const p=e.transitional||Be;e.timeoutErrorMessage&&(f=e.timeoutErrorMessage),r(new m(f,p.clarifyTimeoutError?m.ETIMEDOUT:m.ECONNABORTED,e,c)),c=null},b.isStandardBrowserEnv){const y=(e.withCredentials||an(l))&&e.xsrfCookieName&&rn.read(e.xsrfCookieName);y&&o.set(e.xsrfHeaderName,y)}s===void 0&&o.setContentType(null),"setRequestHeader"in c&&a.forEach(o.toJSON(),function(f,p){c.setRequestHeader(p,f)}),a.isUndefined(e.withCredentials)||(c.withCredentials=!!e.withCredentials),i&&i!=="json"&&(c.responseType=e.responseType),typeof e.onDownloadProgress=="function"&&c.addEventListener("progress",Me(e.onDownloadProgress,!0)),typeof e.onUploadProgress=="function"&&c.upload&&c.upload.addEventListener("progress",Me(e.onUploadProgress)),(e.cancelToken||e.signal)&&(u=y=>{c&&(r(!y||y.type?new j(null,e,c):y),c.abort(),c=null)},e.cancelToken&&e.cancelToken.subscribe(u),e.signal&&(e.signal.aborted?u():e.signal.addEventListener("abort",u)));const E=cn(l);if(E&&b.protocols.indexOf(E)===-1){r(new m("Unsupported protocol "+E+":",m.ERR_BAD_REQUEST,e));return}c.send(s||null)})}};a.forEach(V,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const ln={getAdapter:e=>{e=a.isArray(e)?e:[e];const{length:t}=e;let n,r;for(let s=0;s<t&&(n=e[s],!(r=a.isString(n)?V[n.toLowerCase()]:n));s++);if(!r)throw r===!1?new m(`Adapter ${n} is not supported by the environment`,"ERR_NOT_SUPPORT"):new Error(a.hasOwnProp(V,n)?`Adapter '${n}' is not available in the build`:`Unknown adapter '${n}'`);if(!a.isFunction(r))throw new TypeError("adapter is not a function");return r},adapters:V};function ae(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new j(null,e)}function Ke(e){return ae(e),e.headers=O.from(e.headers),e.data=ie.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),ln.getAdapter(e.adapter||se.adapter)(e).then(function(r){return ae(e),r.data=ie.call(e,e.transformResponse,r),r.headers=O.from(r.headers),r},function(r){return qe(r)||(ae(e),r&&r.response&&(r.response.data=ie.call(e,e.transformResponse,r.response),r.response.headers=O.from(r.response.headers))),Promise.reject(r)})}const ve=e=>e instanceof O?e.toJSON():e;function I(e,t){t=t||{};const n={};function r(c,l,h){return a.isPlainObject(c)&&a.isPlainObject(l)?a.merge.call({caseless:h},c,l):a.isPlainObject(l)?a.merge({},l):a.isArray(l)?l.slice():l}function s(c,l,h){if(a.isUndefined(l)){if(!a.isUndefined(c))return r(void 0,c,h)}else return r(c,l,h)}function o(c,l){if(!a.isUndefined(l))return r(void 0,l)}function i(c,l){if(a.isUndefined(l)){if(!a.isUndefined(c))return r(void 0,c)}else return r(void 0,l)}function u(c,l,h){if(h in t)return r(c,l);if(h in e)return r(void 0,c)}const d={url:o,method:o,data:o,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:u,headers:(c,l)=>s(ve(c),ve(l),!0)};return a.forEach(Object.keys(e).concat(Object.keys(t)),function(l){const h=d[l]||s,E=h(e[l],t[l],l);a.isUndefined(E)&&h!==u||(n[l]=E)}),n}const $e="1.3.4",ce={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{ce[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const ze={};ce.transitional=function(t,n,r){function s(o,i){return"[Axios v"+$e+"] Transitional option '"+o+"'"+i+(r?". "+r:"")}return(o,i,u)=>{if(t===!1)throw new m(s(i," has been removed"+(n?" in "+n:"")),m.ERR_DEPRECATED);return n&&!ze[i]&&(ze[i]=!0,console.warn(s(i," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(o,i,u):!0}};function fn(e,t,n){if(typeof e!="object")throw new m("options must be an object",m.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let s=r.length;for(;s-- >0;){const o=r[s],i=t[o];if(i){const u=e[o],d=u===void 0||i(u,o,e);if(d!==!0)throw new m("option "+o+" must be "+d,m.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new m("Unknown option "+o,m.ERR_BAD_OPTION)}}const ue={assertOptions:fn,validators:ce},C=ue.validators;class W{constructor(t){this.defaults=t,this.interceptors={request:new Ue,response:new Ue}}request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=I(this.defaults,n);const{transitional:r,paramsSerializer:s,headers:o}=n;r!==void 0&&ue.assertOptions(r,{silentJSONParsing:C.transitional(C.boolean),forcedJSONParsing:C.transitional(C.boolean),clarifyTimeoutError:C.transitional(C.boolean)},!1),s!==void 0&&ue.assertOptions(s,{encode:C.function,serialize:C.function},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i;i=o&&a.merge(o.common,o[n.method]),i&&a.forEach(["delete","get","head","post","put","patch","common"],f=>{delete o[f]}),n.headers=O.concat(i,o);const u=[];let d=!0;this.interceptors.request.forEach(function(p){typeof p.runWhen=="function"&&p.runWhen(n)===!1||(d=d&&p.synchronous,u.unshift(p.fulfilled,p.rejected))});const c=[];this.interceptors.response.forEach(function(p){c.push(p.fulfilled,p.rejected)});let l,h=0,E;if(!d){const f=[Ke.bind(this),void 0];for(f.unshift.apply(f,u),f.push.apply(f,c),E=f.length,l=Promise.resolve(n);h<E;)l=l.then(f[h++],f[h++]);return l}E=u.length;let y=n;for(h=0;h<E;){const f=u[h++],p=u[h++];try{y=f(y)}catch(T){p.call(this,T);break}}try{l=Ke.call(this,y)}catch(f){return Promise.reject(f)}for(h=0,E=c.length;h<E;)l=l.then(c[h++],c[h++]);return l}getUri(t){t=I(this.defaults,t);const n=He(t.baseURL,t.url);return Le(n,t.params,t.paramsSerializer)}}a.forEach(["delete","get","head","options"],function(t){W.prototype[t]=function(n,r){return this.request(I(r||{},{method:t,url:n,data:(r||{}).data}))}}),a.forEach(["post","put","patch"],function(t){function n(r){return function(o,i,u){return this.request(I(u||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:o,data:i}))}}W.prototype[t]=n(),W.prototype[t+"Form"]=n(!0)});const Y=W;class le{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(o){n=o});const r=this;this.promise.then(s=>{if(!r._listeners)return;let o=r._listeners.length;for(;o-- >0;)r._listeners[o](s);r._listeners=null}),this.promise.then=s=>{let o;const i=new Promise(u=>{r.subscribe(u),o=u}).then(s);return i.cancel=function(){r.unsubscribe(o)},i},t(function(o,i,u){r.reason||(r.reason=new j(o,i,u),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}static source(){let t;return{token:new le(function(s){t=s}),cancel:t}}}const dn=le;function hn(e){return function(n){return e.apply(null,n)}}function pn(e){return a.isObject(e)&&e.isAxiosError===!0}const fe={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(fe).forEach(([e,t])=>{fe[t]=e});const mn=fe;function Je(e){const t=new Y(e),n=Ee(Y.prototype.request,t);return a.extend(n,Y.prototype,t,{allOwnKeys:!0}),a.extend(n,t,null,{allOwnKeys:!0}),n.create=function(s){return Je(I(e,s))},n}const S=Je(se);S.Axios=Y,S.CanceledError=j,S.CancelToken=dn,S.isCancel=qe,S.VERSION=$e,S.toFormData=v,S.AxiosError=m,S.Cancel=S.CanceledError,S.all=function(t){return Promise.all(t)},S.spread=hn,S.isAxiosError=pn,S.mergeConfig=I,S.AxiosHeaders=O,S.formToJSON=e=>ke(a.isHTMLForm(e)?new FormData(e):e),S.HttpStatusCode=mn,S.default=S;const yn=S,En=e=>{let t="";return Object.keys(e).forEach(n=>{t=t===""?t+`?${n}=${e[n]}`:t+`&${n}=${e[n]}`}),t};class Sn{constructor(t){_(this,"client");_(this,"queryParams");this.client=yn.create({...t,headers:t.apiKey?this._getHeaders(t.apiKey):{}}),this.queryParams=t.queryParams?En(t.queryParams):""}async get(t,n){return this.client.get(t+this.queryParams,{params:n})}async post(t,n){return this.client.post(t+this.queryParams,n)}async put(t,n){return this.client.put(t+this.queryParams,n)}async delete(t){return this.client.delete(t+this.queryParams)}_getHeaders(t){const n={};return n.Authorization=`Bearer ${t}`,n}}class wn{constructor(t){_(this,"httpClient");this.httpClient=t}async getAll(){const{data:t}=await this.httpClient.get("conversions");return t}}const gn=(e,t)=>{const n=Date.now(),r=`${pe}_${e}`,s={...t,timestamp:n};localStorage.setItem(r,JSON.stringify(s))},Rn=(e,t)=>{const n=`${pe}_${e}`,r=localStorage.getItem(n);if(!r)return!0;const s=JSON.parse(r);if(Date.now()-s.timestamp>6e4)return!0;if(t.metadata){const{tracking_id:d,project_id:c,referrer:l,source:h,category:E,title:y,tag:f}=t.metadata,p=s.metadata.tracking_id===d&&s.metadata.project_id===c&&s.metadata.referrer===l&&s.metadata.source===h&&s.metadata.category===E&&s.metadata.title===y&&s.metadata.tag===f;return s.user_address,t.user_address,!p}return!0},bn=(e,t)=>`p=${t}&source=fuul&referrer=${e}`;class An{constructor(t,n={}){_(this,"apiKey");_(this,"BASE_API_URL","https://api.fuul.xyz/api/v1/");_(this,"httpClient");_(this,"settings");_(this,"conversionService");this.apiKey=t,this.settings=n,this.checkApiKey(),tt(),nt(),rt(),this.httpClient=new Sn({baseURL:n.baseApiUrl||this.BASE_API_URL,timeout:1e4,apiKey:this.apiKey,...this.settings.defaultQueryParams&&{queryParams:this.settings.defaultQueryParams}}),this.conversionService=new wn(this.httpClient),this.init()}async init(){L||await this.sendEvent("pageview")}checkApiKey(){if(!this.apiKey)throw new Error("Fuul API key is required")}async sendEvent(t,n={},r={}){const s=Ye(),o=me(),i=Ge(),u=Xe(),d=Qe(),c=Ze(),l=et(),{userAddress:h,signature:E,signatureMessage:y}=r;if(!o)return;const f={name:t,event_args:n,metadata:{...i&&{referrer:i},session_id:s,tracking_id:o,source:u,category:d,title:c,tag:l},...h&&{user_address:h},...E&&{signature:E},...y&&{signature_message:y}};if(Rn(t,f))try{await this.httpClient.post("events",f),gn(t,f)}catch(p){return p}}verifyConnection(){if(L)throw new Error('Fuul SDK is not supported in this environment. Please use "typeof window !== undefined" to check if you are in the browser environment.');window.alert("You are successfully connected to Fuul SDK! ✅")}generateTrackingLink({address:t,projectId:n,baseUrl:r}){return`${r??window.location.href}?${bn(t,n)}`}async getAllConversions(){return this.conversionService.getAll()}}return An});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EventArgs, FuulSettings, IGenerateTrackingLink, EventMetadata } from './types';
|
|
2
|
+
import { ConversionDTO } from './infrastructure/conversions/dtos';
|
|
3
|
+
declare class Fuul {
|
|
4
|
+
private readonly apiKey;
|
|
5
|
+
private readonly BASE_API_URL;
|
|
6
|
+
private readonly httpClient;
|
|
7
|
+
private readonly settings;
|
|
8
|
+
private conversionService;
|
|
9
|
+
constructor(apiKey: string, settings?: FuulSettings);
|
|
10
|
+
init(): Promise<void>;
|
|
11
|
+
checkApiKey(): void;
|
|
12
|
+
/**
|
|
13
|
+
* @param {EventType} name Event name.
|
|
14
|
+
* @param {EventArgs} args Event arguments
|
|
15
|
+
* @param {EventMetadata} metadata Event metadata like userAddress, signature, signatureMessage
|
|
16
|
+
* @returns {Promise<any>} Promise object represents the result of the event.
|
|
17
|
+
* @example
|
|
18
|
+
* ```js
|
|
19
|
+
* fuul.sendEvent('my_event', { value: 10 }, { userAddress: '0x01' })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
sendEvent(name: string, args?: EventArgs, metadata?: EventMetadata): Promise<any>;
|
|
23
|
+
verifyConnection(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Generates a tracking link for a referrer
|
|
26
|
+
* @param {Object} trackingLinkParams - Tracking link parameters
|
|
27
|
+
* @param {string} trackingLinkParams.address - Referrer wallet address.
|
|
28
|
+
* @param {string} trackingLinkParams.projectId - Project ID.
|
|
29
|
+
* @param {string} trackingLinkParams.baseUrl - Base URL of your app. Defaults to window.location.href.
|
|
30
|
+
* @returns {string} tracking link
|
|
31
|
+
**/
|
|
32
|
+
generateTrackingLink({ address, projectId, baseUrl }: IGenerateTrackingLink): string;
|
|
33
|
+
getAllConversions(): Promise<ConversionDTO[]>;
|
|
34
|
+
}
|
|
35
|
+
export default Fuul;
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,EACL,SAAS,EACT,YAAY,EACZ,qBAAqB,EACrB,aAAa,EAEd,MAAM,SAAS,CAAA;AAIhB,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAA;AAOjE,cAAM,IAAI;IACR,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAyC;IACtE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAc;IAEvC,OAAO,CAAC,iBAAiB,CAAmB;gBAEhC,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAE,YAAiB;IAqBjD,IAAI;IAQV,WAAW,IAAI,IAAI;IAMnB;;;;;;;;;OASG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,SAAc,EAAE,QAAQ,GAAE,aAAkB,GAAG,OAAO,CAAC,GAAG,CAAC;IA2C/F,gBAAgB,IAAI,IAAI;IAUxB;;;;;;;QAOI;IACJ,oBAAoB,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,qBAAqB,GAAG,MAAM;IAI9E,iBAAiB,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;CAGpD;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HttpClient } from
|
|
2
|
-
import { ConversionDTO } from
|
|
1
|
+
import { HttpClient } from '../http/HttpClient';
|
|
2
|
+
import { ConversionDTO } from './dtos';
|
|
3
3
|
export declare class ConversionService {
|
|
4
4
|
private httpClient;
|
|
5
5
|
constructor(httpClient: HttpClient);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversionService.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/conversions/conversionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAEtC,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,UAAU,CAAY;gBAElB,UAAU,EAAE,UAAU;IAI5B,MAAM,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;CAKzC"}
|
|
@@ -2,6 +2,10 @@ export interface Project {
|
|
|
2
2
|
id: string;
|
|
3
3
|
name: string;
|
|
4
4
|
thumbnail_url: string;
|
|
5
|
+
integration_type: string;
|
|
6
|
+
user_landing_page_url?: string;
|
|
7
|
+
partner_landing_page_url?: string;
|
|
8
|
+
user_onboarding_page_url?: string;
|
|
5
9
|
}
|
|
6
10
|
interface ConversionPaymentActionArgs {
|
|
7
11
|
payment_type: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dtos.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/conversions/dtos.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,wBAAwB,CAAC,EAAE,MAAM,CAAC;CACnC;AAED,UAAU,2BAA2B;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,WAAW,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,EAAE,2BAA2B,CAAC;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,UAAU,EAAE,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/http/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,aAAa,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAA;AAGnF,UAAU,iBAAiB;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACrC;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;gBAExB,OAAO,EAAE,iBAAiB;IAQhC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAI7D,IAAI,CAAC,CAAC,EACV,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;QACJ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KACnB,GACA,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAItB,GAAG,CAAC,CAAC,EACT,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;QACJ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KACnB,GACA,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAItB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAIxD,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,sBAAsB;CAOpD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface SendEventMetadataRequest {
|
|
2
|
+
referrer?: string;
|
|
3
|
+
project_id?: string;
|
|
4
|
+
tracking_id: string;
|
|
5
|
+
session_id: string;
|
|
6
|
+
user_address?: string;
|
|
7
|
+
source?: string;
|
|
8
|
+
category?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
tag?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SendEventRequest {
|
|
13
|
+
name: string;
|
|
14
|
+
event_args?: EventArgs;
|
|
15
|
+
metadata?: SendEventMetadataRequest;
|
|
16
|
+
user_address?: string;
|
|
17
|
+
signature?: string;
|
|
18
|
+
signatureMessage?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface EventMetadata {
|
|
21
|
+
userAddress?: string;
|
|
22
|
+
signature?: string;
|
|
23
|
+
signatureMessage?: string;
|
|
24
|
+
}
|
|
25
|
+
export type EventArgs = {
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
};
|
|
28
|
+
export type FuulSettings = {
|
|
29
|
+
baseApiUrl?: string;
|
|
30
|
+
defaultQueryParams?: Record<string, string>;
|
|
31
|
+
};
|
|
32
|
+
export interface IGenerateTrackingLink {
|
|
33
|
+
address: string;
|
|
34
|
+
projectId: string;
|
|
35
|
+
baseUrl?: string;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,wBAAwB,CAAC;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SendEventRequest } from '../types';
|
|
2
|
+
export declare const saveSentEvent: (eventName: string, params: SendEventRequest) => void;
|
|
3
|
+
export declare const shouldSendEvent: (eventName: string, reqBody: SendEventRequest) => boolean;
|
|
4
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/utils/events.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAE3C,eAAO,MAAM,aAAa,cAAe,MAAM,UAAU,gBAAgB,KAAG,IAO3E,CAAA;AAED,eAAO,MAAM,eAAe,cAAe,MAAM,WAAW,gBAAgB,KAAG,OAoC9E,CAAA"}
|
|
@@ -6,4 +6,9 @@ export declare const getTrafficSource: () => string | null;
|
|
|
6
6
|
export declare const getTrafficCategory: () => string | null;
|
|
7
7
|
export declare const getTrafficTitle: () => string | null;
|
|
8
8
|
export declare const getTrafficTag: () => string | null;
|
|
9
|
+
export declare const isBrowserUndefined: boolean;
|
|
10
|
+
export declare const saveSessionId: () => void;
|
|
11
|
+
export declare const saveTrackingId: () => void;
|
|
12
|
+
export declare const saveUrlParams: () => void;
|
|
13
|
+
export declare const saveTrafficSource: () => void;
|
|
9
14
|
//# sourceMappingURL=localStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localStorage.d.ts","sourceRoot":"","sources":["../../../src/utils/localStorage.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,YAAY,qBAA6C,CAAA;AACtE,eAAO,MAAM,aAAa,qBAA8C,CAAA;AACxE,eAAO,MAAM,YAAY,qBAA6C,CAAA;AACtE,eAAO,MAAM,aAAa,qBAA8C,CAAA;AACxE,eAAO,MAAM,gBAAgB,qBAAiD,CAAA;AAC9E,eAAO,MAAM,kBAAkB,qBAAmD,CAAA;AAClF,eAAO,MAAM,eAAe,qBAAgD,CAAA;AAC5E,eAAO,MAAM,aAAa,qBAA8C,CAAA;AAExE,eAAO,MAAM,kBAAkB,SAAmE,CAAA;AAGlG,eAAO,MAAM,aAAa,QAAO,IAMhC,CAAA;AAED,eAAO,MAAM,cAAc,QAAO,IAQjC,CAAA;AAED,eAAO,MAAM,aAAa,QAAO,IAehC,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAO,IA4BpC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryParams.d.ts","sourceRoot":"","sources":["../../../src/utils/queryParams.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,SAAU,OAAO,MAAM,EAAE,MAAM,CAAC,WAW5D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,24 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fuul/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "1.0.0",
|
|
5
4
|
"description": "Fuul SDK",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Fuul",
|
|
7
|
+
"Fuul Protocol",
|
|
8
|
+
"Fuul SDK"
|
|
10
9
|
],
|
|
10
|
+
"author": "Fuul Team",
|
|
11
11
|
"scripts": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
12
|
+
"build": "tsc && vite build",
|
|
13
|
+
"lint": "eslint 'src/**/*.{js,json,ts}'",
|
|
14
|
+
"lint:fix": "eslint --fix 'src/**/*.{js,json,ts}'",
|
|
15
|
+
"format": "prettier --write 'src/**/*.{js,json,ts}' --config ./.prettierrc",
|
|
16
|
+
"semantic-release": "semantic-release",
|
|
17
|
+
"test": "jest --coverage --watchAll",
|
|
18
|
+
"test:ci": "jest --ci --passWithNoTests"
|
|
19
|
+
},
|
|
20
|
+
"husky": {
|
|
21
|
+
"hooks": {
|
|
22
|
+
"pre-commit": "lint-staged"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"lint-staged": {
|
|
26
|
+
"src/**/*.{js,jsx,ts,tsx}": [
|
|
27
|
+
"npm run lint",
|
|
28
|
+
"npm run format"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"import": "./dist/fuul-sdk.mjs",
|
|
37
|
+
"require": "./dist/fuul-sdk.umd.js"
|
|
38
|
+
}
|
|
18
39
|
},
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
40
|
+
"main": "./dist/fuul-protocol-abis.umd.js",
|
|
41
|
+
"module": "./dist/fuul-protocol-abis.mjs",
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"license": "MIT",
|
|
22
44
|
"dependencies": {
|
|
23
45
|
"axios": "^1.2.2",
|
|
24
46
|
"nanoid": "^4.0.0"
|
|
@@ -26,10 +48,26 @@
|
|
|
26
48
|
"devDependencies": {
|
|
27
49
|
"@semantic-release/git": "^10.0.1",
|
|
28
50
|
"@semantic-release/npm": "^9.0.2",
|
|
51
|
+
"@types/jest": "^29.5.3",
|
|
29
52
|
"@types/node": "^18.11.18",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^5.58.0",
|
|
54
|
+
"@typescript-eslint/parser": "^5.58.0",
|
|
55
|
+
"eslint": "^8.38.0",
|
|
56
|
+
"eslint-config-prettier": "^8.8.0",
|
|
57
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
58
|
+
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
59
|
+
"husky": "^8.0.3",
|
|
60
|
+
"jest": "^29.6.1",
|
|
61
|
+
"jest-localstorage-mock": "^2.4.26",
|
|
62
|
+
"prettier": "^2.8.7",
|
|
30
63
|
"semantic-release": "^20.1.1",
|
|
64
|
+
"ts-jest": "^29.1.1",
|
|
31
65
|
"ts-node": "^10.9.1",
|
|
32
|
-
"typescript": "^4.7.4"
|
|
66
|
+
"typescript": "^4.7.4",
|
|
67
|
+
"vite": "^4.2.1",
|
|
68
|
+
"vite-plugin-dts": "^2.2.0",
|
|
69
|
+
"vite-plugin-linter": "^2.0.2",
|
|
70
|
+
"vite-tsconfig-paths": "^4.2.0"
|
|
33
71
|
},
|
|
34
72
|
"repository": {
|
|
35
73
|
"type": "git",
|
|
@@ -37,6 +75,6 @@
|
|
|
37
75
|
},
|
|
38
76
|
"publishConfig": {
|
|
39
77
|
"tag": "latest",
|
|
40
|
-
"access": "
|
|
78
|
+
"access": "public"
|
|
41
79
|
}
|
|
42
80
|
}
|
package/lib/cjs/constants.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SEARCH_ENGINE_URLS = exports.SENT_EVENT_VALIDITY_PERIOD_MS = exports.SENT_EVENT_ID_KEY = exports.TRAFFIC_ORIGIN_URL = exports.TRAFFIC_TAG_KEY = exports.TRAFFIC_TITLE_KEY = exports.TRAFFIC_CATEGORY_KEY = exports.TRAFFIC_SOURCE_KEY = exports.REFERRER_ID_KEY = exports.PROJECT_ID_KEY = exports.TRACKING_ID_KEY = exports.SESSION_ID_KEY = void 0;
|
|
4
|
-
exports.SESSION_ID_KEY = "fuul.session_id";
|
|
5
|
-
exports.TRACKING_ID_KEY = "fuul.tracking_id";
|
|
6
|
-
exports.PROJECT_ID_KEY = "fuul.project_id";
|
|
7
|
-
exports.REFERRER_ID_KEY = "fuul.referrer_id";
|
|
8
|
-
exports.TRAFFIC_SOURCE_KEY = "fuul.traffic_source";
|
|
9
|
-
exports.TRAFFIC_CATEGORY_KEY = "fuul.traffic_category";
|
|
10
|
-
exports.TRAFFIC_TITLE_KEY = "fuul.traffic_title";
|
|
11
|
-
exports.TRAFFIC_TAG_KEY = "fuul.traffic_tag";
|
|
12
|
-
exports.TRAFFIC_ORIGIN_URL = "fuul.traffic_origin_url";
|
|
13
|
-
exports.SENT_EVENT_ID_KEY = "fuul.sent";
|
|
14
|
-
exports.SENT_EVENT_VALIDITY_PERIOD_MS = 60000;
|
|
15
|
-
exports.SEARCH_ENGINE_URLS = ["google.com", "bing.com", "yahoo.com"];
|
package/lib/cjs/index.js
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Fuul = void 0;
|
|
13
|
-
const nanoid_1 = require("nanoid");
|
|
14
|
-
const localStorage_js_1 = require("./utils/localStorage.js");
|
|
15
|
-
const constants_js_1 = require("./constants.js");
|
|
16
|
-
const HttpClient_js_1 = require("./infrastructure/http/HttpClient.js");
|
|
17
|
-
const conversionService_js_1 = require("./infrastructure/conversions/conversionService.js");
|
|
18
|
-
const saveSentEvent = (eventName, params) => {
|
|
19
|
-
const timestamp = Date.now();
|
|
20
|
-
const SENT_EVENT_KEY = `${constants_js_1.SENT_EVENT_ID_KEY}_${eventName}`;
|
|
21
|
-
const eventParams = Object.assign(Object.assign({}, params), { timestamp });
|
|
22
|
-
localStorage.setItem(SENT_EVENT_KEY, JSON.stringify(eventParams));
|
|
23
|
-
};
|
|
24
|
-
const shouldEventBeSent = (eventName, params) => {
|
|
25
|
-
const SENT_EVENT_KEY = `${constants_js_1.SENT_EVENT_ID_KEY}_${eventName}`;
|
|
26
|
-
const sentEvent = localStorage.getItem(SENT_EVENT_KEY);
|
|
27
|
-
if (!sentEvent) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
const parsedEvent = JSON.parse(sentEvent);
|
|
31
|
-
const nowTimestamp = Date.now();
|
|
32
|
-
const timespanMillis = nowTimestamp - parsedEvent.timestamp;
|
|
33
|
-
const sentEventExpired = timespanMillis > constants_js_1.SENT_EVENT_VALIDITY_PERIOD_MS;
|
|
34
|
-
if (sentEventExpired) {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
let eventArgsMatch = false;
|
|
38
|
-
if (eventName === "connect_wallet") {
|
|
39
|
-
eventArgsMatch =
|
|
40
|
-
parsedEvent["tracking_id"] === params.tracking_id &&
|
|
41
|
-
parsedEvent["address"] === params.address;
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
eventArgsMatch =
|
|
45
|
-
parsedEvent["tracking_id"] === params.tracking_id &&
|
|
46
|
-
parsedEvent["project_id"] === params.project_id &&
|
|
47
|
-
parsedEvent["referrer_id"] === params.referrer_id &&
|
|
48
|
-
parsedEvent["source"] === params.source &&
|
|
49
|
-
parsedEvent["category"] === params.category &&
|
|
50
|
-
parsedEvent["title"] === params.title &&
|
|
51
|
-
parsedEvent["tag"] === params.tag;
|
|
52
|
-
}
|
|
53
|
-
return !eventArgsMatch;
|
|
54
|
-
};
|
|
55
|
-
const generateRandomId = () => (0, nanoid_1.nanoid)();
|
|
56
|
-
const isBrowserUndefined = typeof window === "undefined" || typeof document === "undefined";
|
|
57
|
-
const saveSessionId = () => {
|
|
58
|
-
if (isBrowserUndefined) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
localStorage.setItem(constants_js_1.SESSION_ID_KEY, generateRandomId());
|
|
62
|
-
};
|
|
63
|
-
const saveTrackingId = () => {
|
|
64
|
-
if (isBrowserUndefined) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (!(0, localStorage_js_1.getTrackingId)()) {
|
|
68
|
-
localStorage.setItem(constants_js_1.TRACKING_ID_KEY, generateRandomId());
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
const saveUrlParams = () => {
|
|
72
|
-
var _a, _b, _c, _d, _e, _f;
|
|
73
|
-
if (isBrowserUndefined) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const queryParams = new URLSearchParams(window.location.search);
|
|
77
|
-
localStorage.setItem(constants_js_1.REFERRER_ID_KEY, (_a = queryParams.get("referrer")) !== null && _a !== void 0 ? _a : "");
|
|
78
|
-
localStorage.setItem(constants_js_1.TRAFFIC_SOURCE_KEY, (_b = queryParams.get("source")) !== null && _b !== void 0 ? _b : "");
|
|
79
|
-
localStorage.setItem(constants_js_1.TRAFFIC_CATEGORY_KEY, (_c = queryParams.get("category")) !== null && _c !== void 0 ? _c : "");
|
|
80
|
-
localStorage.setItem(constants_js_1.TRAFFIC_TITLE_KEY, (_d = queryParams.get("title")) !== null && _d !== void 0 ? _d : "");
|
|
81
|
-
localStorage.setItem(constants_js_1.TRAFFIC_TAG_KEY, (_e = queryParams.get("tag")) !== null && _e !== void 0 ? _e : "");
|
|
82
|
-
localStorage.setItem(constants_js_1.TRAFFIC_ORIGIN_URL, (_f = document.referrer) !== null && _f !== void 0 ? _f : "");
|
|
83
|
-
saveTrafficSource();
|
|
84
|
-
};
|
|
85
|
-
const saveTrafficSource = () => {
|
|
86
|
-
const queryParams = new URLSearchParams(window.location.search);
|
|
87
|
-
const source = queryParams.get("source");
|
|
88
|
-
const referrer = queryParams.get("referrer");
|
|
89
|
-
if (source) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
if (referrer) {
|
|
93
|
-
localStorage.setItem(constants_js_1.TRAFFIC_SOURCE_KEY, "affiliate");
|
|
94
|
-
localStorage.setItem(constants_js_1.TRAFFIC_CATEGORY_KEY, "affiliate");
|
|
95
|
-
localStorage.setItem(constants_js_1.TRAFFIC_TITLE_KEY, referrer);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
// if traffic source is not defined
|
|
99
|
-
const originURL = document.referrer;
|
|
100
|
-
localStorage.setItem(constants_js_1.TRAFFIC_CATEGORY_KEY, originURL);
|
|
101
|
-
localStorage.setItem(constants_js_1.TRAFFIC_TITLE_KEY, originURL);
|
|
102
|
-
// if traffic source is a search engine
|
|
103
|
-
if (constants_js_1.SEARCH_ENGINE_URLS.includes(originURL)) {
|
|
104
|
-
localStorage.setItem(constants_js_1.TRAFFIC_SOURCE_KEY, "organic");
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
// if traffic source is direct
|
|
108
|
-
localStorage.setItem(constants_js_1.TRAFFIC_SOURCE_KEY, "direct");
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
const buildTrackingLinkQueryParams = (referrer, projectId) => {
|
|
113
|
-
return `p=${projectId}&source=fuul&referrer=${referrer}`;
|
|
114
|
-
};
|
|
115
|
-
class Fuul {
|
|
116
|
-
constructor(apiKey, settings = {}) {
|
|
117
|
-
this.BASE_API_URL = "https://api.fuul.xyz/api/v1/";
|
|
118
|
-
this.apiKey = apiKey;
|
|
119
|
-
this.settings = settings;
|
|
120
|
-
this.checkApiKey();
|
|
121
|
-
saveSessionId();
|
|
122
|
-
saveTrackingId();
|
|
123
|
-
saveUrlParams();
|
|
124
|
-
this.httpClient = new HttpClient_js_1.HttpClient(Object.assign({ baseURL: this.BASE_API_URL, timeout: 10000, apiKey: this.apiKey }, (this.settings.defaultQueryParams &&
|
|
125
|
-
typeof this.settings.defaultQueryParams !== "string" && {
|
|
126
|
-
queryParams: this.settings.defaultQueryParams,
|
|
127
|
-
})));
|
|
128
|
-
this.conversionService = new conversionService_js_1.ConversionService(this.httpClient);
|
|
129
|
-
this.init();
|
|
130
|
-
}
|
|
131
|
-
init() {
|
|
132
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
-
if (isBrowserUndefined) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
yield this.sendEvent("pageview");
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
checkApiKey() {
|
|
140
|
-
if (!this.apiKey) {
|
|
141
|
-
throw new Error("Fuul API key is required");
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* @param {EventType} name Event name.
|
|
146
|
-
* @param {EventArgsType} args Event additional arguments.
|
|
147
|
-
* @param {String} signature Event signature.
|
|
148
|
-
* @param {String} signature_message Event signature message.
|
|
149
|
-
* ```js
|
|
150
|
-
* import { Fuul } from 'fuul-sdk'
|
|
151
|
-
*
|
|
152
|
-
* // Initialize Fuul in your app root file
|
|
153
|
-
* new Fuul('your-api-key')
|
|
154
|
-
*
|
|
155
|
-
* // Then you can send an event as follows:
|
|
156
|
-
* fuul.sendEvent('connect_wallet', {
|
|
157
|
-
* address,
|
|
158
|
-
* })
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
sendEvent(name, args, signature, signature_message) {
|
|
162
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
-
const session_id = (0, localStorage_js_1.getSessionId)();
|
|
164
|
-
const tracking_id = (0, localStorage_js_1.getTrackingId)();
|
|
165
|
-
const referrer_id = (0, localStorage_js_1.getReferrerId)();
|
|
166
|
-
const source = (0, localStorage_js_1.getTrafficSource)();
|
|
167
|
-
const category = (0, localStorage_js_1.getTrafficCategory)();
|
|
168
|
-
const title = (0, localStorage_js_1.getTrafficTitle)();
|
|
169
|
-
const tag = (0, localStorage_js_1.getTrafficTag)();
|
|
170
|
-
if (!tracking_id)
|
|
171
|
-
return;
|
|
172
|
-
let params = {
|
|
173
|
-
tracking_id,
|
|
174
|
-
source,
|
|
175
|
-
category,
|
|
176
|
-
title,
|
|
177
|
-
tag,
|
|
178
|
-
};
|
|
179
|
-
let reqBody = {};
|
|
180
|
-
if (name === "connect_wallet") {
|
|
181
|
-
params = Object.assign(Object.assign({}, params), { address: args === null || args === void 0 ? void 0 : args.address });
|
|
182
|
-
reqBody = {
|
|
183
|
-
name,
|
|
184
|
-
session_id,
|
|
185
|
-
event_args: Object.assign(Object.assign({}, args), { tracking_id,
|
|
186
|
-
source,
|
|
187
|
-
category,
|
|
188
|
-
title,
|
|
189
|
-
tag }),
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
params = Object.assign(Object.assign({}, params), { project_id: args === null || args === void 0 ? void 0 : args.project_id, referrer_id });
|
|
194
|
-
reqBody = {
|
|
195
|
-
name,
|
|
196
|
-
session_id,
|
|
197
|
-
event_args: Object.assign(Object.assign({}, args), { referrer: referrer_id, tracking_id,
|
|
198
|
-
source,
|
|
199
|
-
category,
|
|
200
|
-
title,
|
|
201
|
-
tag }),
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
reqBody = Object.assign(Object.assign(Object.assign({}, reqBody), (signature && {
|
|
205
|
-
signature,
|
|
206
|
-
})), (signature_message && {
|
|
207
|
-
signature_message,
|
|
208
|
-
}));
|
|
209
|
-
if (!shouldEventBeSent(name, params)) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
try {
|
|
213
|
-
yield this.httpClient.post("events", reqBody);
|
|
214
|
-
saveSentEvent(name, params);
|
|
215
|
-
}
|
|
216
|
-
catch (error) {
|
|
217
|
-
return error;
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
verifyConnection() {
|
|
222
|
-
if (isBrowserUndefined) {
|
|
223
|
-
throw new Error('Fuul SDK is not supported in this environment. Please use "typeof window !== undefined" to check if you are in the browser environment.');
|
|
224
|
-
}
|
|
225
|
-
window.alert("You are successfully connected to Fuul SDK! ✅");
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Generates a tracking link for a referrer
|
|
229
|
-
* @param {Object} trackingLinkParams - Tracking link parameters
|
|
230
|
-
* @param {string} trackingLinkParams.address - Referrer wallet address.
|
|
231
|
-
* @param {string} trackingLinkParams.projectId - Project ID.
|
|
232
|
-
* @param {string} trackingLinkParams.baseUrl - Base URL of your app. Defaults to window.location.href.
|
|
233
|
-
* @returns {string} tracking link
|
|
234
|
-
**/
|
|
235
|
-
generateTrackingLink({ address, projectId, baseUrl, }) {
|
|
236
|
-
return `${baseUrl !== null && baseUrl !== void 0 ? baseUrl : window.location.href}?${buildTrackingLinkQueryParams(address, projectId)}`;
|
|
237
|
-
}
|
|
238
|
-
getAllConversions() {
|
|
239
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
-
return this.conversionService.getAll();
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
exports.Fuul = Fuul;
|
|
245
|
-
exports.default = {
|
|
246
|
-
Fuul,
|
|
247
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ConversionService = void 0;
|
|
13
|
-
class ConversionService {
|
|
14
|
-
constructor(httpClient) {
|
|
15
|
-
this.httpClient = httpClient;
|
|
16
|
-
}
|
|
17
|
-
getAll() {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
const { data } = yield this.httpClient.get("conversions");
|
|
20
|
-
return data;
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.ConversionService = ConversionService;
|