denotify-client 1.1.8 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@supabase/supabase-js"),require("form-data"),require("url"),require("proxy-from-env"),require("http"),require("https"),require("util"),require("follow-redirects"),require("zlib"),require("stream"),require("events"),require("yup"),require("ethers")):"function"==typeof define&&define.amd?define(["exports","@supabase/supabase-js","form-data","url","proxy-from-env","http","https","util","follow-redirects","zlib","stream","events","yup","ethers"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["denotify-client"]={},e.supabaseJs,e.FormData$1,e.url,e.proxyFromEnv,e.http,e.https,e.util,e.followRedirects,e.zlib,e.stream,e.EventEmitter,e.yup,e.ethers)}(this,(function(e,t,r,n,o,s,i,a,c,u,l,d,f,h){"use strict";function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function m(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var g=p(r),y=p(n),w=p(s),b=p(i),E=p(a),R=p(c),O=p(u),S=p(l),T=p(d),v=m(f);function A(e,t){return function(){return e.apply(t,arguments)}}const{toString:C}=Object.prototype,{getPrototypeOf:x}=Object,N=(_=Object.create(null),e=>{const t=C.call(e);return _[t]||(_[t]=t.slice(8,-1).toLowerCase())});var _;const L=e=>(e=e.toLowerCase(),t=>N(t)===e),k=e=>t=>typeof t===e,{isArray:B}=Array,P=k("undefined");const j=L("ArrayBuffer");const D=k("string"),F=k("function"),U=k("number"),I=e=>null!==e&&"object"==typeof e,q=e=>{if("object"!==N(e))return!1;const t=x(e);return!(null!==t&&t!==Object.prototype&&null!==Object.getPrototypeOf(t)||Symbol.toStringTag in e||Symbol.iterator in e)},z=L("Date"),H=L("File"),M=L("Blob"),$=L("FileList"),W=L("URLSearchParams");function J(e,t,{allOwnKeys:r=!1}={}){if(null==e)return;let n,o;if("object"!=typeof e&&(e=[e]),B(e))for(n=0,o=e.length;n<o;n++)t.call(null,e[n],n,e);else{const o=r?Object.getOwnPropertyNames(e):Object.keys(e),s=o.length;let i;for(n=0;n<s;n++)i=o[n],t.call(null,e[i],i,e)}}function V(e,t){t=t.toLowerCase();const r=Object.keys(e);let n,o=r.length;for(;o-- >0;)if(n=r[o],t===n.toLowerCase())return n;return null}const K="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,G=e=>!P(e)&&e!==K;const X=(Z="undefined"!=typeof Uint8Array&&x(Uint8Array),e=>Z&&e instanceof Z);var Z;const Q=L("HTMLFormElement"),Y=(({hasOwnProperty:e})=>(t,r)=>e.call(t,r))(Object.prototype),ee=L("RegExp"),te=(e,t)=>{const r=Object.getOwnPropertyDescriptors(e),n={};J(r,((r,o)=>{!1!==t(r,o,e)&&(n[o]=r)})),Object.defineProperties(e,n)},re="abcdefghijklmnopqrstuvwxyz",ne="0123456789",oe={DIGIT:ne,ALPHA:re,ALPHA_DIGIT:re+re.toUpperCase()+ne};var se={isArray:B,isArrayBuffer:j,isBuffer:function(e){return null!==e&&!P(e)&&null!==e.constructor&&!P(e.constructor)&&F(e.constructor.isBuffer)&&e.constructor.isBuffer(e)},isFormData:e=>{const t="[object FormData]";return e&&("function"==typeof FormData&&e instanceof FormData||C.call(e)===t||F(e.toString)&&e.toString()===t)},isArrayBufferView:function(e){let t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&j(e.buffer),t},isString:D,isNumber:U,isBoolean:e=>!0===e||!1===e,isObject:I,isPlainObject:q,isUndefined:P,isDate:z,isFile:H,isBlob:M,isRegExp:ee,isFunction:F,isStream:e=>I(e)&&F(e.pipe),isURLSearchParams:W,isTypedArray:X,isFileList:$,forEach:J,merge:function e(){const{caseless:t}=G(this)&&this||{},r={},n=(n,o)=>{const s=t&&V(r,o)||o;q(r[s])&&q(n)?r[s]=e(r[s],n):q(n)?r[s]=e({},n):B(n)?r[s]=n.slice():r[s]=n};for(let e=0,t=arguments.length;e<t;e++)arguments[e]&&J(arguments[e],n);return r},extend:(e,t,r,{allOwnKeys:n}={})=>(J(t,((t,n)=>{r&&F(t)?e[n]=A(t,r):e[n]=t}),{allOwnKeys:n}),e),trim:e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),stripBOM:e=>(65279===e.charCodeAt(0)&&(e=e.slice(1)),e),inherits:(e,t,r,n)=>{e.prototype=Object.create(t.prototype,n),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),r&&Object.assign(e.prototype,r)},toFlatObject:(e,t,r,n)=>{let o,s,i;const a={};if(t=t||{},null==e)return t;do{for(o=Object.getOwnPropertyNames(e),s=o.length;s-- >0;)i=o[s],n&&!n(i,e,t)||a[i]||(t[i]=e[i],a[i]=!0);e=!1!==r&&x(e)}while(e&&(!r||r(e,t))&&e!==Object.prototype);return t},kindOf:N,kindOfTest:L,endsWith:(e,t,r)=>{e=String(e),(void 0===r||r>e.length)&&(r=e.length),r-=t.length;const n=e.indexOf(t,r);return-1!==n&&n===r},toArray:e=>{if(!e)return null;if(B(e))return e;let t=e.length;if(!U(t))return null;const r=new Array(t);for(;t-- >0;)r[t]=e[t];return r},forEachEntry:(e,t)=>{const r=(e&&e[Symbol.iterator]).call(e);let n;for(;(n=r.next())&&!n.done;){const r=n.value;t.call(e,r[0],r[1])}},matchAll:(e,t)=>{let r;const n=[];for(;null!==(r=e.exec(t));)n.push(r);return n},isHTMLForm:Q,hasOwnProperty:Y,hasOwnProp:Y,reduceDescriptors:te,freezeMethods:e=>{te(e,((t,r)=>{if(F(e)&&-1!==["arguments","caller","callee"].indexOf(r))return!1;const n=e[r];F(n)&&(t.enumerable=!1,"writable"in t?t.writable=!1:t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+r+"'")}))}))},toObjectSet:(e,t)=>{const r={},n=e=>{e.forEach((e=>{r[e]=!0}))};return B(e)?n(e):n(String(e).split(t)),r},toCamelCase:e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,(function(e,t,r){return t.toUpperCase()+r})),noop:()=>{},toFiniteNumber:(e,t)=>(e=+e,Number.isFinite(e)?e:t),findKey:V,global:K,isContextDefined:G,ALPHABET:oe,generateString:(e=16,t=oe.ALPHA_DIGIT)=>{let r="";const{length:n}=t;for(;e--;)r+=t[Math.random()*n|0];return r},isSpecCompliantForm:function(e){return!!(e&&F(e.append)&&"FormData"===e[Symbol.toStringTag]&&e[Symbol.iterator])},toJSONObject:e=>{const t=new Array(10),r=(e,n)=>{if(I(e)){if(t.indexOf(e)>=0)return;if(!("toJSON"in e)){t[n]=e;const o=B(e)?[]:{};return J(e,((e,t)=>{const s=r(e,n+1);!P(s)&&(o[t]=s)})),t[n]=void 0,o}}return e};return r(e,0)}};function ie(e,t,r,n,o){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),r&&(this.config=r),n&&(this.request=n),o&&(this.response=o)}se.inherits(ie,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:se.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const ae=ie.prototype,ce={};function ue(e){return se.isPlainObject(e)||se.isArray(e)}function le(e){return se.endsWith(e,"[]")?e.slice(0,-2):e}function de(e,t,r){return e?e.concat(t).map((function(e,t){return e=le(e),!r&&t?"["+e+"]":e})).join(r?".":""):t}["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(ie,ce),Object.defineProperty(ae,"isAxiosError",{value:!0}),ie.from=(e,t,r,n,o,s)=>{const i=Object.create(ae);return se.toFlatObject(e,i,(function(e){return e!==Error.prototype}),(e=>"isAxiosError"!==e)),ie.call(i,e.message,t,r,n,o),i.cause=e,i.name=e.name,s&&Object.assign(i,s),i};const fe=se.toFlatObject(se,{},null,(function(e){return/^is[A-Z]/.test(e)}));function he(e,t,r){if(!se.isObject(e))throw new TypeError("target must be an object");t=t||new(g.default||FormData);const n=(r=se.toFlatObject(r,{metaTokens:!0,dots:!1,indexes:!1},!1,(function(e,t){return!se.isUndefined(t[e])}))).metaTokens,o=r.visitor||u,s=r.dots,i=r.indexes,a=(r.Blob||"undefined"!=typeof Blob&&Blob)&&se.isSpecCompliantForm(t);if(!se.isFunction(o))throw new TypeError("visitor must be a function");function c(e){if(null===e)return"";if(se.isDate(e))return e.toISOString();if(!a&&se.isBlob(e))throw new ie("Blob is not supported. Use a Buffer instead.");return se.isArrayBuffer(e)||se.isTypedArray(e)?a&&"function"==typeof Blob?new Blob([e]):Buffer.from(e):e}function u(e,r,o){let a=e;if(e&&!o&&"object"==typeof e)if(se.endsWith(r,"{}"))r=n?r:r.slice(0,-2),e=JSON.stringify(e);else if(se.isArray(e)&&function(e){return se.isArray(e)&&!e.some(ue)}(e)||(se.isFileList(e)||se.endsWith(r,"[]"))&&(a=se.toArray(e)))return r=le(r),a.forEach((function(e,n){!se.isUndefined(e)&&null!==e&&t.append(!0===i?de([r],n,s):null===i?r:r+"[]",c(e))})),!1;return!!ue(e)||(t.append(de(o,r,s),c(e)),!1)}const l=[],d=Object.assign(fe,{defaultVisitor:u,convertValue:c,isVisitable:ue});if(!se.isObject(e))throw new TypeError("data must be an object");return function e(r,n){if(!se.isUndefined(r)){if(-1!==l.indexOf(r))throw Error("Circular reference detected in "+n.join("."));l.push(r),se.forEach(r,(function(r,s){!0===(!(se.isUndefined(r)||null===r)&&o.call(t,r,se.isString(s)?s.trim():s,n,d))&&e(r,n?n.concat(s):[s])})),l.pop()}}(e),t}function pe(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,(function(e){return t[e]}))}function me(e,t){this._pairs=[],e&&he(e,this,t)}const ge=me.prototype;function ye(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function we(e,t,r){if(!t)return e;const n=r&&r.encode||ye,o=r&&r.serialize;let s;if(s=o?o(t,r):se.isURLSearchParams(t)?t.toString():new me(t,r).toString(n),s){const t=e.indexOf("#");-1!==t&&(e=e.slice(0,t)),e+=(-1===e.indexOf("?")?"?":"&")+s}return e}ge.append=function(e,t){this._pairs.push([e,t])},ge.toString=function(e){const t=e?function(t){return e.call(this,t,pe)}:pe;return this._pairs.map((function(e){return t(e[0])+"="+t(e[1])}),"").join("&")};var be=class{constructor(){this.handlers=[]}use(e,t,r){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!r&&r.synchronous,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){se.forEach(this.handlers,(function(t){null!==t&&e(t)}))}},Ee={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Re={isNode:!0,classes:{URLSearchParams:y.default.URLSearchParams,FormData:g.default,Blob:"undefined"!=typeof Blob&&Blob||null},protocols:["http","https","file","data"]};function Oe(e){function t(e,r,n,o){let s=e[o++];const i=Number.isFinite(+s),a=o>=e.length;if(s=!s&&se.isArray(n)?n.length:s,a)return se.hasOwnProp(n,s)?n[s]=[n[s],r]:n[s]=r,!i;n[s]&&se.isObject(n[s])||(n[s]=[]);return t(e,r,n[s],o)&&se.isArray(n[s])&&(n[s]=function(e){const t={},r=Object.keys(e);let n;const o=r.length;let s;for(n=0;n<o;n++)s=r[n],t[s]=e[s];return t}(n[s])),!i}if(se.isFormData(e)&&se.isFunction(e.entries)){const r={};return se.forEachEntry(e,((e,n)=>{t(function(e){return se.matchAll(/\w+|\[(\w*)]/g,e).map((e=>"[]"===e[0]?"":e[1]||e[0]))}(e),n,r,0)})),r}return null}const Se={"Content-Type":void 0};const Te={transitional:Ee,adapter:["xhr","http"],transformRequest:[function(e,t){const r=t.getContentType()||"",n=r.indexOf("application/json")>-1,o=se.isObject(e);o&&se.isHTMLForm(e)&&(e=new FormData(e));if(se.isFormData(e))return n&&n?JSON.stringify(Oe(e)):e;if(se.isArrayBuffer(e)||se.isBuffer(e)||se.isStream(e)||se.isFile(e)||se.isBlob(e))return e;if(se.isArrayBufferView(e))return e.buffer;if(se.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let s;if(o){if(r.indexOf("application/x-www-form-urlencoded")>-1)return function(e,t){return he(e,new Re.classes.URLSearchParams,Object.assign({visitor:function(e,t,r,n){return se.isBuffer(e)?(this.append(t,e.toString("base64")),!1):n.defaultVisitor.apply(this,arguments)}},t))}(e,this.formSerializer).toString();if((s=se.isFileList(e))||r.indexOf("multipart/form-data")>-1){const t=this.env&&this.env.FormData;return he(s?{"files[]":e}:e,t&&new t,this.formSerializer)}}return o||n?(t.setContentType("application/json",!1),function(e,t,r){if(se.isString(e))try{return(t||JSON.parse)(e),se.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(r||JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){const t=this.transitional||Te.transitional,r=t&&t.forcedJSONParsing,n="json"===this.responseType;if(e&&se.isString(e)&&(r&&!this.responseType||n)){const r=!(t&&t.silentJSONParsing)&&n;try{return JSON.parse(e)}catch(e){if(r){if("SyntaxError"===e.name)throw ie.from(e,ie.ERR_BAD_RESPONSE,this,null,this.response);throw e}}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Re.classes.FormData,Blob:Re.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};se.forEach(["delete","get","head"],(function(e){Te.headers[e]={}})),se.forEach(["post","put","patch"],(function(e){Te.headers[e]=se.merge(Se)}));var ve=Te;const Ae=se.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"]);const Ce=Symbol("internals");function xe(e){return e&&String(e).trim().toLowerCase()}function Ne(e){return!1===e||null==e?e:se.isArray(e)?e.map(Ne):String(e)}function _e(e,t,r,n,o){return se.isFunction(n)?n.call(this,t,r):(o&&(t=r),se.isString(t)?se.isString(n)?-1!==t.indexOf(n):se.isRegExp(n)?n.test(t):void 0:void 0)}class Le{constructor(e){e&&this.set(e)}set(e,t,r){const n=this;function o(e,t,r){const o=xe(t);if(!o)throw new Error("header name must be a non-empty string");const s=se.findKey(n,o);(!s||void 0===n[s]||!0===r||void 0===r&&!1!==n[s])&&(n[s||t]=Ne(e))}const s=(e,t)=>se.forEach(e,((e,r)=>o(e,r,t)));return se.isPlainObject(e)||e instanceof this.constructor?s(e,t):se.isString(e)&&(e=e.trim())&&!/^[-_a-zA-Z]+$/.test(e.trim())?s((e=>{const t={};let r,n,o;return e&&e.split("\n").forEach((function(e){o=e.indexOf(":"),r=e.substring(0,o).trim().toLowerCase(),n=e.substring(o+1).trim(),!r||t[r]&&Ae[r]||("set-cookie"===r?t[r]?t[r].push(n):t[r]=[n]:t[r]=t[r]?t[r]+", "+n:n)})),t})(e),t):null!=e&&o(t,e,r),this}get(e,t){if(e=xe(e)){const r=se.findKey(this,e);if(r){const e=this[r];if(!t)return e;if(!0===t)return function(e){const t=Object.create(null),r=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let n;for(;n=r.exec(e);)t[n[1]]=n[2];return t}(e);if(se.isFunction(t))return t.call(this,e,r);if(se.isRegExp(t))return t.exec(e);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,t){if(e=xe(e)){const r=se.findKey(this,e);return!(!r||void 0===this[r]||t&&!_e(0,this[r],r,t))}return!1}delete(e,t){const r=this;let n=!1;function o(e){if(e=xe(e)){const o=se.findKey(r,e);!o||t&&!_e(0,r[o],o,t)||(delete r[o],n=!0)}}return se.isArray(e)?e.forEach(o):o(e),n}clear(e){const t=Object.keys(this);let r=t.length,n=!1;for(;r--;){const o=t[r];e&&!_e(0,this[o],o,e,!0)||(delete this[o],n=!0)}return n}normalize(e){const t=this,r={};return se.forEach(this,((n,o)=>{const s=se.findKey(r,o);if(s)return t[s]=Ne(n),void delete t[o];const i=e?function(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,((e,t,r)=>t.toUpperCase()+r))}(o):String(o).trim();i!==o&&delete t[o],t[i]=Ne(n),r[i]=!0})),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const t=Object.create(null);return se.forEach(this,((r,n)=>{null!=r&&!1!==r&&(t[n]=e&&se.isArray(r)?r.join(", "):r)})),t}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map((([e,t])=>e+": "+t)).join("\n")}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...t){const r=new this(e);return t.forEach((e=>r.set(e))),r}static accessor(e){const t=(this[Ce]=this[Ce]={accessors:{}}).accessors,r=this.prototype;function n(e){const n=xe(e);t[n]||(!function(e,t){const r=se.toCamelCase(" "+t);["get","set","has"].forEach((n=>{Object.defineProperty(e,n+r,{value:function(e,r,o){return this[n].call(this,t,e,r,o)},configurable:!0})}))}(r,e),t[n]=!0)}return se.isArray(e)?e.forEach(n):n(e),this}}Le.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),se.freezeMethods(Le.prototype),se.freezeMethods(Le);var ke=Le;function Be(e,t){const r=this||ve,n=t||r,o=ke.from(n.headers);let s=n.data;return se.forEach(e,(function(e){s=e.call(r,s,o.normalize(),t?t.status:void 0)})),o.normalize(),s}function Pe(e){return!(!e||!e.__CANCEL__)}function je(e,t,r){ie.call(this,null==e?"canceled":e,ie.ERR_CANCELED,t,r),this.name="CanceledError"}function De(e,t,r){const n=r.config.validateStatus;r.status&&n&&!n(r.status)?t(new ie("Request failed with status code "+r.status,[ie.ERR_BAD_REQUEST,ie.ERR_BAD_RESPONSE][Math.floor(r.status/100)-4],r.config,r.request,r)):e(r)}function Fe(e,t){return e&&!function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}(t)?function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}(e,t):t}se.inherits(je,ie,{__CANCEL__:!0});const Ue="1.3.4";function Ie(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}const qe=/^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/;function ze(e,t){e=e||10;const r=new Array(e),n=new Array(e);let o,s=0,i=0;return t=void 0!==t?t:1e3,function(a){const c=Date.now(),u=n[i];o||(o=c),r[s]=a,n[s]=c;let l=i,d=0;for(;l!==s;)d+=r[l++],l%=e;if(s=(s+1)%e,s===i&&(i=(i+1)%e),c-o<t)return;const f=u&&c-u;return f?Math.round(1e3*d/f):void 0}}const He=Symbol("internals");class Me extends S.default.Transform{constructor(e){super({readableHighWaterMark:(e=se.toFlatObject(e,{maxRate:0,chunkSize:65536,minChunkSize:100,timeWindow:500,ticksRate:2,samplesCount:15},null,((e,t)=>!se.isUndefined(t[e])))).chunkSize});const t=this,r=this[He]={length:e.length,timeWindow:e.timeWindow,ticksRate:e.ticksRate,chunkSize:e.chunkSize,maxRate:e.maxRate,minChunkSize:e.minChunkSize,bytesSeen:0,isCaptured:!1,notifiedBytesLoaded:0,ts:Date.now(),bytes:0,onReadCallback:null},n=ze(r.ticksRate*e.samplesCount,r.timeWindow);this.on("newListener",(e=>{"progress"===e&&(r.isCaptured||(r.isCaptured=!0))}));let o=0;r.updateProgress=function(e,t){let r=0;const n=1e3/t;let o=null;return function(t,s){const i=Date.now();if(t||i-r>n)return o&&(clearTimeout(o),o=null),r=i,e.apply(null,s);o||(o=setTimeout((()=>(o=null,r=Date.now(),e.apply(null,s))),n-(i-r)))}}((function(){const e=r.length,s=r.bytesSeen,i=s-o;if(!i||t.destroyed)return;const a=n(i);o=s,process.nextTick((()=>{t.emit("progress",{loaded:s,total:e,progress:e?s/e:void 0,bytes:i,rate:a||void 0,estimated:a&&e&&s<=e?(e-s)/a:void 0})}))}),r.ticksRate);const s=()=>{r.updateProgress(!0)};this.once("end",s),this.once("error",s)}_read(e){const t=this[He];return t.onReadCallback&&t.onReadCallback(),super._read(e)}_transform(e,t,r){const n=this,o=this[He],s=o.maxRate,i=this.readableHighWaterMark,a=o.timeWindow,c=s/(1e3/a),u=!1!==o.minChunkSize?Math.max(o.minChunkSize,.01*c):0;const l=(e,t)=>{const r=Buffer.byteLength(e);let l,d=null,f=i,h=0;if(s){const e=Date.now();(!o.ts||(h=e-o.ts)>=a)&&(o.ts=e,l=c-o.bytes,o.bytes=l<0?-l:0,h=0),l=c-o.bytes}if(s){if(l<=0)return setTimeout((()=>{t(null,e)}),a-h);l<f&&(f=l)}f&&r>f&&r-f>u&&(d=e.subarray(f),e=e.subarray(0,f)),function(e,t){const r=Buffer.byteLength(e);o.bytesSeen+=r,o.bytes+=r,o.isCaptured&&o.updateProgress(),n.push(e)?process.nextTick(t):o.onReadCallback=()=>{o.onReadCallback=null,process.nextTick(t)}}(e,d?()=>{process.nextTick(t,null,d)}:t)};l(e,(function e(t,n){if(t)return r(t);n?l(n,e):r(null)}))}setLength(e){return this[He].length=+e,this}}var $e=Me;const{asyncIterator:We}=Symbol;var Je=async function*(e){e.stream?yield*e.stream():e.arrayBuffer?yield await e.arrayBuffer():e[We]?yield*e[We]():yield e};const Ve=se.ALPHABET.ALPHA_DIGIT+"-_",Ke=new a.TextEncoder,Ge="\r\n",Xe=Ke.encode(Ge);class Ze{constructor(e,t){const{escapeName:r}=this.constructor,n=se.isString(t);let o=`Content-Disposition: form-data; name="${r(e)}"${!n&&t.name?`; filename="${r(t.name)}"`:""}${Ge}`;n?t=Ke.encode(String(t).replace(/\r?\n|\r\n?/g,Ge)):o+=`Content-Type: ${t.type||"application/octet-stream"}${Ge}`,this.headers=Ke.encode(o+Ge),this.contentLength=n?t.byteLength:t.size,this.size=this.headers.byteLength+this.contentLength+2,this.name=e,this.value=t}async*encode(){yield this.headers;const{value:e}=this;se.isTypedArray(e)?yield e:yield*Je(e),yield Xe}static escapeName(e){return String(e).replace(/[\r\n"]/g,(e=>({"\r":"%0D","\n":"%0A",'"':"%22"}[e])))}}var Qe=(e,t,r)=>{const{tag:n="form-data-boundary",size:o=25,boundary:s=n+"-"+se.generateString(o,Ve)}=r||{};if(!se.isFormData(e))throw TypeError("FormData instance required");if(s.length<1||s.length>70)throw Error("boundary must be 10-70 characters long");const i=Ke.encode("--"+s+Ge),a=Ke.encode("--"+s+"--"+Ge+Ge);let c=a.byteLength;const u=Array.from(e.entries()).map((([e,t])=>{const r=new Ze(e,t);return c+=r.size,r}));c+=i.byteLength*u.length,c=se.toFiniteNumber(c);const d={"Content-Type":`multipart/form-data; boundary=${s}`};return Number.isFinite(c)&&(d["Content-Length"]=c),t&&t(d),l.Readable.from(async function*(){for(const e of u)yield i,yield*e.encode();yield a}())};class Ye extends S.default.Transform{__transform(e,t,r){this.push(e),r()}_transform(e,t,r){if(0!==e.length&&(this._transform=this.__transform,120!==e[0])){const e=Buffer.alloc(2);e[0]=120,e[1]=156,this.push(e,t)}this.__transform(e,t,r)}}var et=Ye;const tt={flush:O.default.constants.Z_SYNC_FLUSH,finishFlush:O.default.constants.Z_SYNC_FLUSH},rt={flush:O.default.constants.BROTLI_OPERATION_FLUSH,finishFlush:O.default.constants.BROTLI_OPERATION_FLUSH},nt=se.isFunction(O.default.createBrotliDecompress),{http:ot,https:st}=R.default,it=/https:?/,at=Re.protocols.map((e=>e+":"));function ct(e){e.beforeRedirects.proxy&&e.beforeRedirects.proxy(e),e.beforeRedirects.config&&e.beforeRedirects.config(e)}function ut(e,t,r){let n=t;if(!n&&!1!==n){const e=o.getProxyForUrl(r);e&&(n=new URL(e))}if(n){if(n.username&&(n.auth=(n.username||"")+":"+(n.password||"")),n.auth){(n.auth.username||n.auth.password)&&(n.auth=(n.auth.username||"")+":"+(n.auth.password||""));const t=Buffer.from(n.auth,"utf8").toString("base64");e.headers["Proxy-Authorization"]="Basic "+t}e.headers.host=e.hostname+(e.port?":"+e.port:"");const t=n.hostname||n.host;e.hostname=t,e.host=t,e.port=n.port,e.path=r,n.protocol&&(e.protocol=n.protocol.includes(":")?n.protocol:`${n.protocol}:`)}e.beforeRedirects.proxy=function(e){ut(e,t,e.href)}}const lt="undefined"!=typeof process&&"process"===se.kindOf(process);var dt=lt&&function(e){return t=async function(t,r,n){let{data:o}=e;const{responseType:s,responseEncoding:i}=e,a=e.method.toUpperCase();let c,u,l=!1;const d=new T.default,f=()=>{e.cancelToken&&e.cancelToken.unsubscribe(h),e.signal&&e.signal.removeEventListener("abort",h),d.removeAllListeners()};function h(t){d.emit("abort",!t||t.type?new je(null,e,u):t)}n(((e,t)=>{c=!0,t&&(l=!0,f())})),d.once("abort",r),(e.cancelToken||e.signal)&&(e.cancelToken&&e.cancelToken.subscribe(h),e.signal&&(e.signal.aborted?h():e.signal.addEventListener("abort",h)));const p=Fe(e.baseURL,e.url),m=new URL(p,"http://localhost"),g=m.protocol||at[0];if("data:"===g){let n;if("GET"!==a)return De(t,r,{status:405,statusText:"method not allowed",headers:{},config:e});try{n=function(e,t,r){const n=r&&r.Blob||Re.classes.Blob,o=Ie(e);if(void 0===t&&n&&(t=!0),"data"===o){e=o.length?e.slice(o.length+1):e;const r=qe.exec(e);if(!r)throw new ie("Invalid URL",ie.ERR_INVALID_URL);const s=r[1],i=r[2],a=r[3],c=Buffer.from(decodeURIComponent(a),i?"base64":"utf8");if(t){if(!n)throw new ie("Blob is not supported",ie.ERR_NOT_SUPPORT);return new n([c],{type:s})}return c}throw new ie("Unsupported protocol "+o,ie.ERR_NOT_SUPPORT)}(e.url,"blob"===s,{Blob:e.env&&e.env.Blob})}catch(t){throw ie.from(t,ie.ERR_BAD_REQUEST,e)}return"text"===s?(n=n.toString(i),i&&"utf8"!==i||(n=se.stripBOM(n))):"stream"===s&&(n=S.default.Readable.from(n)),De(t,r,{data:n,status:200,statusText:"OK",headers:new ke,config:e})}if(-1===at.indexOf(g))return r(new ie("Unsupported protocol "+g,ie.ERR_BAD_REQUEST,e));const y=ke.from(e.headers).normalize();y.set("User-Agent","axios/"+Ue,!1);const R=e.onDownloadProgress,v=e.onUploadProgress,A=e.maxRate;let C,x;if(se.isSpecCompliantForm(o)){const e=y.getContentType(/boundary=([-_\w\d]{10,70})/i);o=Qe(o,(e=>{y.set(e)}),{tag:`axios-${Ue}-boundary`,boundary:e&&e[1]||void 0})}else if(se.isFormData(o)&&se.isFunction(o.getHeaders)){if(y.set(o.getHeaders()),!y.hasContentLength())try{const e=await E.default.promisify(o.getLength).call(o);Number.isFinite(e)&&e>=0&&y.setContentLength(e)}catch(e){}}else if(se.isBlob(o))o.size&&y.setContentType(o.type||"application/octet-stream"),y.setContentLength(o.size||0),o=S.default.Readable.from(Je(o));else if(o&&!se.isStream(o)){if(Buffer.isBuffer(o));else if(se.isArrayBuffer(o))o=Buffer.from(new Uint8Array(o));else{if(!se.isString(o))return r(new ie("Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream",ie.ERR_BAD_REQUEST,e));o=Buffer.from(o,"utf-8")}if(y.setContentLength(o.length,!1),e.maxBodyLength>-1&&o.length>e.maxBodyLength)return r(new ie("Request body larger than maxBodyLength limit",ie.ERR_BAD_REQUEST,e))}const N=se.toFiniteNumber(y.getContentLength());let _,L;se.isArray(A)?(C=A[0],x=A[1]):C=x=A,o&&(v||C)&&(se.isStream(o)||(o=S.default.Readable.from(o,{objectMode:!1})),o=S.default.pipeline([o,new $e({length:N,maxRate:se.toFiniteNumber(C)})],se.noop),v&&o.on("progress",(e=>{v(Object.assign(e,{upload:!0}))}))),e.auth&&(_=(e.auth.username||"")+":"+(e.auth.password||"")),!_&&m.username&&(_=m.username+":"+m.password),_&&y.delete("authorization");try{L=we(m.pathname+m.search,e.params,e.paramsSerializer).replace(/^\?/,"")}catch(t){const n=new Error(t.message);return n.config=e,n.url=e.url,n.exists=!0,r(n)}y.set("Accept-Encoding","gzip, compress, deflate"+(nt?", br":""),!1);const k={path:L,method:a,headers:y.toJSON(),agents:{http:e.httpAgent,https:e.httpsAgent},auth:_,protocol:g,beforeRedirect:ct,beforeRedirects:{}};let B;e.socketPath?k.socketPath=e.socketPath:(k.hostname=m.hostname,k.port=m.port,ut(k,e.proxy,g+"//"+m.hostname+(m.port?":"+m.port:"")+k.path));const P=it.test(k.protocol);if(k.agent=P?e.httpsAgent:e.httpAgent,e.transport?B=e.transport:0===e.maxRedirects?B=P?b.default:w.default:(e.maxRedirects&&(k.maxRedirects=e.maxRedirects),e.beforeRedirect&&(k.beforeRedirects.config=e.beforeRedirect),B=P?st:ot),e.maxBodyLength>-1?k.maxBodyLength=e.maxBodyLength:k.maxBodyLength=1/0,e.insecureHTTPParser&&(k.insecureHTTPParser=e.insecureHTTPParser),u=B.request(k,(function(n){if(u.destroyed)return;const o=[n],c=+n.headers["content-length"];if(R){const e=new $e({length:se.toFiniteNumber(c),maxRate:se.toFiniteNumber(x)});R&&e.on("progress",(e=>{R(Object.assign(e,{download:!0}))})),o.push(e)}let h=n;const p=n.req||u;if(!1!==e.decompress&&n.headers["content-encoding"])switch("HEAD"!==a&&204!==n.statusCode||delete n.headers["content-encoding"],n.headers["content-encoding"]){case"gzip":case"x-gzip":case"compress":case"x-compress":o.push(O.default.createUnzip(tt)),delete n.headers["content-encoding"];break;case"deflate":o.push(new et),o.push(O.default.createUnzip(tt)),delete n.headers["content-encoding"];break;case"br":nt&&(o.push(O.default.createBrotliDecompress(rt)),delete n.headers["content-encoding"])}h=o.length>1?S.default.pipeline(o,se.noop):o[0];const m=S.default.finished(h,(()=>{m(),f()})),g={status:n.statusCode,statusText:n.statusMessage,headers:new ke(n.headers),config:e,request:p};if("stream"===s)g.data=h,De(t,r,g);else{const n=[];let o=0;h.on("data",(function(t){n.push(t),o+=t.length,e.maxContentLength>-1&&o>e.maxContentLength&&(l=!0,h.destroy(),r(new ie("maxContentLength size of "+e.maxContentLength+" exceeded",ie.ERR_BAD_RESPONSE,e,p)))})),h.on("aborted",(function(){if(l)return;const t=new ie("maxContentLength size of "+e.maxContentLength+" exceeded",ie.ERR_BAD_RESPONSE,e,p);h.destroy(t),r(t)})),h.on("error",(function(t){u.destroyed||r(ie.from(t,null,e,p))})),h.on("end",(function(){try{let e=1===n.length?n[0]:Buffer.concat(n);"arraybuffer"!==s&&(e=e.toString(i),i&&"utf8"!==i||(e=se.stripBOM(e))),g.data=e}catch(t){r(ie.from(t,null,e,g.request,g))}De(t,r,g)}))}d.once("abort",(e=>{h.destroyed||(h.emit("error",e),h.destroy())}))})),d.once("abort",(e=>{r(e),u.destroy(e)})),u.on("error",(function(t){r(ie.from(t,null,e,u))})),u.on("socket",(function(e){e.setKeepAlive(!0,6e4)})),e.timeout){const t=parseInt(e.timeout,10);if(isNaN(t))return void r(new ie("error trying to parse `config.timeout` to int",ie.ERR_BAD_OPTION_VALUE,e,u));u.setTimeout(t,(function(){if(c)return;let t=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded";const n=e.transitional||Ee;e.timeoutErrorMessage&&(t=e.timeoutErrorMessage),r(new ie(t,n.clarifyTimeoutError?ie.ETIMEDOUT:ie.ECONNABORTED,e,u)),h()}))}if(se.isStream(o)){let t=!1,r=!1;o.on("end",(()=>{t=!0})),o.once("error",(e=>{r=!0,u.destroy(e)})),o.on("close",(()=>{t||r||h(new je("Request stream has been aborted",e,u))})),o.pipe(u)}else u.end(o)},new Promise(((e,r)=>{let n,o;const s=(e,t)=>{o||(o=!0,n&&n(e,t))},i=e=>{s(e,!0),r(e)};t((t=>{s(t),e(t)}),i,(e=>n=e)).catch(i)}));var t},ft=Re.isStandardBrowserEnv?{write:function(e,t,r,n,o,s){const i=[];i.push(e+"="+encodeURIComponent(t)),se.isNumber(r)&&i.push("expires="+new Date(r).toGMTString()),se.isString(n)&&i.push("path="+n),se.isString(o)&&i.push("domain="+o),!0===s&&i.push("secure"),document.cookie=i.join("; ")},read:function(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}},ht=Re.isStandardBrowserEnv?function(){const e=/(msie|trident)/i.test(navigator.userAgent),t=document.createElement("a");let r;function n(r){let n=r;return e&&(t.setAttribute("href",n),n=t.href),t.setAttribute("href",n),{href:t.href,protocol:t.protocol?t.protocol.replace(/:$/,""):"",host:t.host,search:t.search?t.search.replace(/^\?/,""):"",hash:t.hash?t.hash.replace(/^#/,""):"",hostname:t.hostname,port:t.port,pathname:"/"===t.pathname.charAt(0)?t.pathname:"/"+t.pathname}}return r=n(window.location.href),function(e){const t=se.isString(e)?n(e):e;return t.protocol===r.protocol&&t.host===r.host}}():function(){return!0};function pt(e,t){let r=0;const n=ze(50,250);return o=>{const s=o.loaded,i=o.lengthComputable?o.total:void 0,a=s-r,c=n(a);r=s;const u={loaded:s,total:i,progress:i?s/i:void 0,bytes:a,rate:c||void 0,estimated:c&&i&&s<=i?(i-s)/c:void 0,event:o};u[t?"download":"upload"]=!0,e(u)}}const mt={http:dt,xhr:"undefined"!=typeof XMLHttpRequest&&function(e){return new Promise((function(t,r){let n=e.data;const o=ke.from(e.headers).normalize(),s=e.responseType;let i;function a(){e.cancelToken&&e.cancelToken.unsubscribe(i),e.signal&&e.signal.removeEventListener("abort",i)}se.isFormData(n)&&(Re.isStandardBrowserEnv||Re.isStandardBrowserWebWorkerEnv)&&o.setContentType(!1);let c=new XMLHttpRequest;if(e.auth){const t=e.auth.username||"",r=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";o.set("Authorization","Basic "+btoa(t+":"+r))}const u=Fe(e.baseURL,e.url);function l(){if(!c)return;const n=ke.from("getAllResponseHeaders"in c&&c.getAllResponseHeaders());De((function(e){t(e),a()}),(function(e){r(e),a()}),{data:s&&"text"!==s&&"json"!==s?c.response:c.responseText,status:c.status,statusText:c.statusText,headers:n,config:e,request:c}),c=null}if(c.open(e.method.toUpperCase(),we(u,e.params,e.paramsSerializer),!0),c.timeout=e.timeout,"onloadend"in c?c.onloadend=l:c.onreadystatechange=function(){c&&4===c.readyState&&(0!==c.status||c.responseURL&&0===c.responseURL.indexOf("file:"))&&setTimeout(l)},c.onabort=function(){c&&(r(new ie("Request aborted",ie.ECONNABORTED,e,c)),c=null)},c.onerror=function(){r(new ie("Network Error",ie.ERR_NETWORK,e,c)),c=null},c.ontimeout=function(){let t=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded";const n=e.transitional||Ee;e.timeoutErrorMessage&&(t=e.timeoutErrorMessage),r(new ie(t,n.clarifyTimeoutError?ie.ETIMEDOUT:ie.ECONNABORTED,e,c)),c=null},Re.isStandardBrowserEnv){const t=(e.withCredentials||ht(u))&&e.xsrfCookieName&&ft.read(e.xsrfCookieName);t&&o.set(e.xsrfHeaderName,t)}void 0===n&&o.setContentType(null),"setRequestHeader"in c&&se.forEach(o.toJSON(),(function(e,t){c.setRequestHeader(t,e)})),se.isUndefined(e.withCredentials)||(c.withCredentials=!!e.withCredentials),s&&"json"!==s&&(c.responseType=e.responseType),"function"==typeof e.onDownloadProgress&&c.addEventListener("progress",pt(e.onDownloadProgress,!0)),"function"==typeof e.onUploadProgress&&c.upload&&c.upload.addEventListener("progress",pt(e.onUploadProgress)),(e.cancelToken||e.signal)&&(i=t=>{c&&(r(!t||t.type?new je(null,e,c):t),c.abort(),c=null)},e.cancelToken&&e.cancelToken.subscribe(i),e.signal&&(e.signal.aborted?i():e.signal.addEventListener("abort",i)));const d=Ie(u);d&&-1===Re.protocols.indexOf(d)?r(new ie("Unsupported protocol "+d+":",ie.ERR_BAD_REQUEST,e)):c.send(n||null)}))}};se.forEach(mt,((e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch(e){}Object.defineProperty(e,"adapterName",{value:t})}}));var gt={getAdapter:e=>{e=se.isArray(e)?e:[e];const{length:t}=e;let r,n;for(let o=0;o<t&&(r=e[o],!(n=se.isString(r)?mt[r.toLowerCase()]:r));o++);if(!n){if(!1===n)throw new ie(`Adapter ${r} is not supported by the environment`,"ERR_NOT_SUPPORT");throw new Error(se.hasOwnProp(mt,r)?`Adapter '${r}' is not available in the build`:`Unknown adapter '${r}'`)}if(!se.isFunction(n))throw new TypeError("adapter is not a function");return n},adapters:mt};function yt(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new je(null,e)}function wt(e){yt(e),e.headers=ke.from(e.headers),e.data=Be.call(e,e.transformRequest),-1!==["post","put","patch"].indexOf(e.method)&&e.headers.setContentType("application/x-www-form-urlencoded",!1);return gt.getAdapter(e.adapter||ve.adapter)(e).then((function(t){return yt(e),t.data=Be.call(e,e.transformResponse,t),t.headers=ke.from(t.headers),t}),(function(t){return Pe(t)||(yt(e),t&&t.response&&(t.response.data=Be.call(e,e.transformResponse,t.response),t.response.headers=ke.from(t.response.headers))),Promise.reject(t)}))}const bt=e=>e instanceof ke?e.toJSON():e;function Et(e,t){t=t||{};const r={};function n(e,t,r){return se.isPlainObject(e)&&se.isPlainObject(t)?se.merge.call({caseless:r},e,t):se.isPlainObject(t)?se.merge({},t):se.isArray(t)?t.slice():t}function o(e,t,r){return se.isUndefined(t)?se.isUndefined(e)?void 0:n(void 0,e,r):n(e,t,r)}function s(e,t){if(!se.isUndefined(t))return n(void 0,t)}function i(e,t){return se.isUndefined(t)?se.isUndefined(e)?void 0:n(void 0,e):n(void 0,t)}function a(r,o,s){return s in t?n(r,o):s in e?n(void 0,r):void 0}const c={url:s,method:s,data:s,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:a,headers:(e,t)=>o(bt(e),bt(t),!0)};return se.forEach(Object.keys(e).concat(Object.keys(t)),(function(n){const s=c[n]||o,i=s(e[n],t[n],n);se.isUndefined(i)&&s!==a||(r[n]=i)})),r}const Rt={};["object","boolean","number","function","string","symbol"].forEach(((e,t)=>{Rt[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}}));const Ot={};Rt.transitional=function(e,t,r){function n(e,t){return"[Axios v"+Ue+"] Transitional option '"+e+"'"+t+(r?". "+r:"")}return(r,o,s)=>{if(!1===e)throw new ie(n(o," has been removed"+(t?" in "+t:"")),ie.ERR_DEPRECATED);return t&&!Ot[o]&&(Ot[o]=!0,console.warn(n(o," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(r,o,s)}};var St={assertOptions:function(e,t,r){if("object"!=typeof e)throw new ie("options must be an object",ie.ERR_BAD_OPTION_VALUE);const n=Object.keys(e);let o=n.length;for(;o-- >0;){const s=n[o],i=t[s];if(i){const t=e[s],r=void 0===t||i(t,s,e);if(!0!==r)throw new ie("option "+s+" must be "+r,ie.ERR_BAD_OPTION_VALUE)}else if(!0!==r)throw new ie("Unknown option "+s,ie.ERR_BAD_OPTION)}},validators:Rt};const Tt=St.validators;class vt{constructor(e){this.defaults=e,this.interceptors={request:new be,response:new be}}request(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{},t=Et(this.defaults,t);const{transitional:r,paramsSerializer:n,headers:o}=t;let s;void 0!==r&&St.assertOptions(r,{silentJSONParsing:Tt.transitional(Tt.boolean),forcedJSONParsing:Tt.transitional(Tt.boolean),clarifyTimeoutError:Tt.transitional(Tt.boolean)},!1),void 0!==n&&St.assertOptions(n,{encode:Tt.function,serialize:Tt.function},!0),t.method=(t.method||this.defaults.method||"get").toLowerCase(),s=o&&se.merge(o.common,o[t.method]),s&&se.forEach(["delete","get","head","post","put","patch","common"],(e=>{delete o[e]})),t.headers=ke.concat(s,o);const i=[];let a=!0;this.interceptors.request.forEach((function(e){"function"==typeof e.runWhen&&!1===e.runWhen(t)||(a=a&&e.synchronous,i.unshift(e.fulfilled,e.rejected))}));const c=[];let u;this.interceptors.response.forEach((function(e){c.push(e.fulfilled,e.rejected)}));let l,d=0;if(!a){const e=[wt.bind(this),void 0];for(e.unshift.apply(e,i),e.push.apply(e,c),l=e.length,u=Promise.resolve(t);d<l;)u=u.then(e[d++],e[d++]);return u}l=i.length;let f=t;for(d=0;d<l;){const e=i[d++],t=i[d++];try{f=e(f)}catch(e){t.call(this,e);break}}try{u=wt.call(this,f)}catch(e){return Promise.reject(e)}for(d=0,l=c.length;d<l;)u=u.then(c[d++],c[d++]);return u}getUri(e){return we(Fe((e=Et(this.defaults,e)).baseURL,e.url),e.params,e.paramsSerializer)}}se.forEach(["delete","get","head","options"],(function(e){vt.prototype[e]=function(t,r){return this.request(Et(r||{},{method:e,url:t,data:(r||{}).data}))}})),se.forEach(["post","put","patch"],(function(e){function t(t){return function(r,n,o){return this.request(Et(o||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:r,data:n}))}}vt.prototype[e]=t(),vt.prototype[e+"Form"]=t(!0)}));var At=vt;class Ct{constructor(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");let t;this.promise=new Promise((function(e){t=e}));const r=this;this.promise.then((e=>{if(!r._listeners)return;let t=r._listeners.length;for(;t-- >0;)r._listeners[t](e);r._listeners=null})),this.promise.then=e=>{let t;const n=new Promise((e=>{r.subscribe(e),t=e})).then(e);return n.cancel=function(){r.unsubscribe(t)},n},e((function(e,n,o){r.reason||(r.reason=new je(e,n,o),t(r.reason))}))}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){this.reason?e(this.reason):this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1)}static source(){let e;return{token:new Ct((function(t){e=t})),cancel:e}}}var xt=Ct;const Nt={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(Nt).forEach((([e,t])=>{Nt[t]=e}));var _t=Nt;const Lt=function e(t){const r=new At(t),n=A(At.prototype.request,r);return se.extend(n,At.prototype,r,{allOwnKeys:!0}),se.extend(n,r,null,{allOwnKeys:!0}),n.create=function(r){return e(Et(t,r))},n}(ve);Lt.Axios=At,Lt.CanceledError=je,Lt.CancelToken=xt,Lt.isCancel=Pe,Lt.VERSION=Ue,Lt.toFormData=he,Lt.AxiosError=ie,Lt.Cancel=Lt.CanceledError,Lt.all=function(e){return Promise.all(e)},Lt.spread=function(e){return function(t){return e.apply(null,t)}},Lt.isAxiosError=function(e){return se.isObject(e)&&!0===e.isAxiosError},Lt.mergeConfig=Et,Lt.AxiosHeaders=ke,Lt.formToJSON=e=>Oe(se.isHTMLForm(e)?new FormData(e):e),Lt.HttpStatusCode=_t,Lt.default=Lt;var kt=Lt;const Bt="notify_discord_webhook";class Pt{static SimpleToRaw(e){return{name:"",notify_type:Bt,notify:e}}static validateCreate(e){const t=/^(https?|ftp):\/\/(-\.)?([^\s/?\.#]+\.?)+([^\s\.?#]+)?(\?\S*)?$/;return v.object({url:v.string().matches(t,"url is not a valid url").required(),username:v.string(),avatar_url:v.string().matches(t,"url is not a valid url"),message:v.string().required()}).validate(e)}}class jt{static SimpleToRaw(e,t){if("Discord"===e)return Pt.SimpleToRaw(t)}}class Dt{static SimpleToRaw(e,t,r){return{alertType:"event",network:t,nickname:e,type:"handler_function_call",handler:r}}static validateCreate(e){const t=([e],t)=>"true"===e?t.notRequired():t.required();return v.object({address:v.string().required(),abi:v.array().required(),nBlocks:v.number().min(10),condition:v.string().oneOf([">",">=","<","<=","=","true"]),constant:v.number().min(0).when("condition",t),responseArgIndex:v.number().min(0).when("condition",t),responseArgDecimals:v.number().min(0).when("condition",t)}).validate(e)}}class Ft{static SimpleToRaw(e,t,r){return{alertType:"event",network:t,nickname:e,type:"handler_onchain_event",handler:r}}static validateCreate(e){const t=([e],t)=>"true"===e?t.notRequired():t.required();return v.object({address:v.string().required(),event:v.string().required(),abi:v.array().required(),condition:v.string().oneOf([">",">=","<","<=","=","true"]),constant:v.number().min(0).when("condition",t),paramsIndex:v.number().min(0).when("condition",t),paramsDecimals:v.number().min(0).when("condition",t)}).validate(e)}static validateUpdate(e){}}class Ut{api;data=[];constructor(e){this.api=e}static create(e){return new Ut(e)}getAbiHash(e){if(void 0===this.api)throw new Error("FunctionBuilder must be initialised with api");return this.api.getAbiHash(e)}async addFunction(e,t,r,n){const o=new h.ethers.Contract(e,n);return o.interface.encodeFunctionData(t,r),this.data.push({address:e,bytecode:o.interface.encodeFunctionData(t,r),abiHash:await this.getAbiHash(n),function:t}),this}get(){return this.data}static schema(){return v.array().of(v.object({address:v.string().required(),bytecode:v.string().matches(/^(0x)?([0-9a-fA-F]{2})*$/).required(),abiHash:v.string().matches(/^[A-Fa-f0-9]{64}/).required(),function:v.string().required()}))}}class It{static version(){return"v1"}static execute(e,t,r="v1"){const n=JSON.parse(JSON.stringify(t));let o=!0;for(const t of n){const r=It.process(e,t.conditions);o=It.execLogic(o,t.logic,r)}return o}static process(e,t,r){const n=t.shift();if(!n)return void 0===r||r;const o=It.execCondition(e,n);if(void 0===r||"WHERE"===n.logic)return It.process(e,t,o);if(void 0===n.logic)throw new Error("Invalid filter. Condition must have logic value");const s=It.execLogic(r,n.logic,o);return It.process(e,t,s)}static execLogic(e,t,r){switch(t){case"AND":return e&&r;case"OR":return e||r;case"XOR":return(e||r)&&!(e&&r);case"NAND":case"NOR":return!(e&&r);case"WHERE":return r;default:throw new Error(`Invalid Filter. Bad logic value: ${t}`)}}static execCondition(e,t){const r=e[t.key];if("Number"===t.type){if("number"!=typeof t.constant||"number"!=typeof r)throw new Error(`Invalid filter. Type miss-match. Type: ${t.type}, Variable: ${t.constant}, Data: ${r}`);const e=r,n=t.constant;switch(t.operation){case"eq":return e===n;case"!eq":return e!==n;case"gt":return e>n;case"gte":return e>=n;case"lt":return e<n;case"lte":return e<=n;default:throw new Error("Invalid Filter. Operation does not match type")}}if("String"===t.type){if("string"!=typeof t.constant||"string"!=typeof r)throw new Error(`Invalid filter. Type miss-match. Type: ${t.type}, Variable: ${t.constant}, Data: ${r}`);const e=r,n=t.constant;switch(t.operation){case"contains":return e.includes(n);case"!contains":return!e.includes(n);case"is":return e===n;case"!is":return e!==n;case"isEmpty":return""===e;case"!isEmpty":return""!==e;default:throw new Error("Invalid Filter. Operation does not match type")}}if("Address"===t.type){if("string"!=typeof t.constant||"string"!=typeof r)throw new Error(`Invalid filter. Type miss-match. Type: ${t.type}, Variable: ${t.constant}, Data: ${r}`);const e=r,n=t.constant;switch(t.operation){case"contains":return e.toLowerCase().includes(n.toLowerCase());case"!contains":return!e.toLowerCase().includes(n.toLowerCase());case"is":return e.toLowerCase()===n.toLowerCase();case"!is":return e.toLowerCase()!==n.toLowerCase();case"isEmpty":return""===e;case"!isEmpty":return""!==e;default:throw new Error("Invalid Filter. Operation does not match type")}}throw new Error("Invalid Filter. Unknown Type")}}class qt{groups=[];constructor(){this.newGroup("WHERE")}static version(){return It.version()}static new(){return new qt}newGroup(e){if(0!==this.groups.length&&"WHERE"===e)throw new Error('Only the first groups can start with "WHERE"');return this.groups.push({logic:"WHERE",conditions:[]}),this}addCondition(e,t,r,n,o){const s=this.groups[this.groups.length-1];if(0===s.conditions.length&&"WHERE"!==e)throw new Error('Logic for the first condition of a group must be "WHERE"');if(s.conditions.length>0&&"WHERE"===e)throw new Error('Only the first condition of a group can be "WHERE"');return s.conditions.push({logic:e,key:t,type:r,operation:n,constant:o}),this}finalise(){for(const e of this.groups)if(0===e.conditions.length)throw new Error("Bad Filter. All Groups must have atleast one condition");return this.groups}static schema(){const e=v.string().oneOf(["AND","OR","XOR","NAND","NOR","WHERE"]).required(),t=v.object({logic:e,key:v.string().required(),type:v.string().oneOf(["String","Address","Number"]).required(),operation:v.string().when("type",(([e],t)=>{switch(e){case"String":return t.oneOf(["contains","!contains","is","!is","isEmpty","!isEmpty"]);case"Address":return t.oneOf(["is","!is","isEmpty","!isEmpty"]);case"Number":return t.oneOf(["String","Address","Number"]);default:throw new Error("Invalid Filter Data Type")}})),constant:v.mixed().when("type",(([e])=>{switch(e){case"String":case"Address":return v.string();case"Number":return v.number();default:throw new Error("Invalid Filter Data Type")}}))});return v.array().of(v.object({logic:e,conditions:v.array().of(t)}))}}class zt{static SimpleToRaw(e,t,r){return{alertType:"event",network:t,nickname:e,type:"handler_function_call_v2",handler:r}}static validateCreate(e){return v.object({timeBase:v.string().oneOf(["blocks","time"]).required(),nBlocks:v.number().min(10).when("timeBase",(([e],t)=>"blocks"===e?t.required():t)),timePeriod:v.string().matches(/^(\d+)([SMHD])$/i,"timePeriod must be of the format n[s|m|h|d], eg 10s for 10 seconds").when("timeBase",(([e],t)=>"time"===e?t.required():t)),startTime:v.number().default(0),debounceCount:v.number(),functions:Ut.schema(),triggerOn:v.string().oneOf(["always","filter"]).default("always"),latch:v.boolean().default(!1),filterVersion:v.string().when("triggerOn",(([e],t)=>"filter"===e?t.required():t)),filter:qt.schema().when("triggerOn",(([e],t)=>"filter"===e?t.required():t))}).validate(e)}}class Ht{static SimpleToRaw(e,t,r,n){switch(t){case"PollFunctionV2":return zt.SimpleToRaw(e,r,n);case"PollFunctionV1":return Dt.SimpleToRaw(e,r,n);case"OnchainEventV1":return Ft.SimpleToRaw(e,r,n);default:throw new Error("Invalid Trigger ID")}}}const Mt=e=>`https://${e}.functions.supabase.co/`,$t=e=>`https://${e}.supabase.co/`,Wt="fdgtrxmmrtlokhgkvcjz";class Jt{url;token;headers={};constructor(e,t){this.url=e,this.token=t,this.headers={Authorization:`Bearer ${t}`,"Content-Type":"application/json"}}static async create(e){if(e.key)throw new Error("Auth by key not yet supported");if(e.email&&e.password){const r=e.projectId?$t(e.projectId):$t(Wt),n=e.projectId?Mt(e.projectId):Mt(Wt),o=e.anonKey?e.anonKey:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZkZ3RyeG1tcnRsb2toZ2t2Y2p6Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NzMwODcwNzYsImV4cCI6MTk4ODY2MzA3Nn0.sAMxjlcJSSozBGr-LNcsudyxzUEM9e-UspMHHQLqLr4",s=t.createClient(r,o),{data:i,error:a}=await s.auth.signInWithPassword({email:e.email,password:e.password});if(a)throw a;if(void 0===i.session?.access_token)throw new Error("Access token not found");return new Jt(n,i.session?.access_token)}throw new Error("Authentication Required. DeNotify supports either username/password or API key authentication")}async alertHistory(e,t){const r="alert-history",n=t||{};return e&&(n.id=e),Object.keys(n).length>0?await this.request("get",r,{params:t}):await this.request("get",r)}async getAlert(e){return(await this.request("get",`alerts/${e}`))[0]}async getAlerts(){return await this.request("get","alerts")}async createAlert(e){const t=Ht.SimpleToRaw(e.name,e.triggerId,e.network,e.trigger),r=jt.SimpleToRaw(e.notificationId,e.notification);return await this.request("post","alerts",{body:{trigger:t,notification:r}})}async deleteAlert(e){return await this.request("delete",`alerts/${e}`)}async request(e,t,r={}){const n=new URL(`${this.url}${t}`);if(r.params)for(const e of Object.keys(r.params))n.searchParams.append(e,r.params[e]);console.log(n.toString());const o={method:e,url:n.toString(),headers:this.headers};r.body&&(o.data=r.body);return(await kt(o)).data}async getAbi(e,t){return await this.request("get",`abi/${e}/${t}`)}async getAbiHash(e){return(await this.request("post","abi",{body:e})).hash}async setAlertName(e,t){throw new Error("Not yet supported - Sorry!")}async enableAlert(e){throw new Error("Not yet supported - Sorry!")}async disableAlert(e){throw new Error("Not yet supported - Sorry!")}async updateNotification(e){throw new Error("Not yet supported - Sorry!")}async updateTrigger(e,t){return await this.request("patch",`alerts/trigger-handler/${e}`,{body:t})}}class Vt{name;network;triggerId;trigger;notificationId;notification;constructor(e){this.name=e}static create(e){return new Vt(e)}onNetwork(e){return this.network=e,this}withTrigger(e,t){return this.triggerId=e,this.trigger=t,this}withNotification(e,t){return this.notificationId=e,this.notification=t,this}async validate(){switch(this.triggerId){case"OnchainEventV1":return Ft.validateCreate(this.trigger);case"PollFunctionV1":return Dt.validateCreate(this.trigger);case"PollFunctionV2":return zt.validateCreate(this.trigger)}if("Discord"===this.notificationId)return Pt.validateCreate(this.notification)}async config(){if(void 0===this.trigger||void 0===this.triggerId)throw new Error("Trigger not configured");if(void 0===this.notification||void 0===this.notificationId)throw new Error("Notification not configured");if(void 0===this.network)throw new Error("Network not configured");return await this.validate(),{name:this.name,network:this.network,triggerId:this.triggerId,trigger:this.trigger,notificationId:this.notificationId,notification:this.notification}}}var Kt=Object.freeze({__proto__:null,Trigger:Ht,HandlerFunctionCallV2:zt,HandlerFunctionCall:Dt,HandlerOnchainEvent:Ft}),Gt=Object.freeze({__proto__:null,NOTIFY_DISCORD_WEBHOOK_RAW_ID:Bt,NotifyDiscordWebhook:Pt,Notification:jt});e.AlertBuilder=Vt,e.DeNotifyClient=Jt,e.FilterBuilder=qt,e.FunctionBuilder=Ut,e.Notification=Gt,e.Trigger=Kt}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@supabase/supabase-js"),require("yup"),require("ethers"),require("node-fetch")):"function"==typeof define&&define.amd?define(["exports","@supabase/supabase-js","yup","ethers","node-fetch"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["denotify-client"]={},t.supabaseJs,t.yup,t.ethers,t.fetch)}(this,(function(t,e,r,i,n){"use strict";function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function o(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(r){if("default"!==r){var i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,i.get?i:{enumerable:!0,get:function(){return t[r]}})}})),e.default=t,Object.freeze(e)}var a=o(r),c=s(n);const u="notify_discord_webhook";class d{static SimpleToRaw(t){return{name:"",notify_type:u,notify:t}}static validateCreate(t){const e=/^(https?|ftp):\/\/(-\.)?([^\s/?\.#]+\.?)+([^\s\.?#]+)?(\?\S*)?$/;return a.object({url:a.string().matches(e,"url is not a valid url").required(),username:a.string(),avatar_url:a.string().matches(e,"url is not a valid url"),message:a.string().required()}).validate(t)}}class l{static SimpleToRaw(t,e){if("Discord"===t)return d.SimpleToRaw(e)}}class h{static SimpleToRaw(t,e,r){return{alertType:"event",network:e,nickname:t,type:"handler_function_call",handler:r}}static validateCreate(t){const e=([t],e)=>"true"===t?e.notRequired():e.required();return a.object({address:a.string().required(),abi:a.array().required(),nBlocks:a.number().min(10),condition:a.string().oneOf([">",">=","<","<=","=","true"]),constant:a.number().min(0).when("condition",e),responseArgIndex:a.number().min(0).when("condition",e),responseArgDecimals:a.number().min(0).when("condition",e)}).validate(t)}}class p{static SimpleToRaw(t,e,r){return{alertType:"event",network:e,nickname:t,type:"handler_onchain_event",handler:r}}static validateCreate(t){const e=([t],e)=>"true"===t?e.notRequired():e.required();return a.object({address:a.string().required(),event:a.string().required(),abi:a.array().required(),condition:a.string().oneOf([">",">=","<","<=","=","true"]),constant:a.number().min(0).when("condition",e),paramsIndex:a.number().min(0).when("condition",e),paramsDecimals:a.number().min(0).when("condition",e)}).validate(t)}static validateUpdate(t){}}class f{api;data=[];constructor(t){this.api=t}static create(t){return new f(t)}getAbiHash(t){if(void 0===this.api)throw new Error("FunctionBuilder must be initialised with api");return this.api.getAbiHash(t)}async addFunction(t,e,r,n){const s=new i.ethers.Contract(t,n);return s.interface.encodeFunctionData(e,r),this.data.push({address:t,bytecode:s.interface.encodeFunctionData(e,r),abiHash:await this.getAbiHash(n),function:e}),this}get(){return this.data}static schema(){return a.array().of(a.object({address:a.string().required(),bytecode:a.string().matches(/^(0x)?([0-9a-fA-F]{2})*$/).required(),abiHash:a.string().matches(/^[A-Fa-f0-9]{64}/).required(),function:a.string().required()}))}}class g{static version(){return"v1"}static execute(t,e,r="v1"){const i=JSON.parse(JSON.stringify(e));let n=!0;for(const e of i){const r=g.process(t,e.conditions);n=g.execLogic(n,e.logic,r)}return n}static process(t,e,r){const i=e.shift();if(!i)return void 0===r||r;const n=g.execCondition(t,i);if(void 0===r||"WHERE"===i.logic)return g.process(t,e,n);if(void 0===i.logic)throw new Error("Invalid filter. Condition must have logic value");const s=g.execLogic(r,i.logic,n);return g.process(t,e,s)}static execLogic(t,e,r){switch(e){case"AND":return t&&r;case"OR":return t||r;case"XOR":return(t||r)&&!(t&&r);case"NAND":case"NOR":return!(t&&r);case"WHERE":return r;default:throw new Error(`Invalid Filter. Bad logic value: ${e}`)}}static execCondition(t,e){const r=t[e.key];if("Number"===e.type){if("number"!=typeof e.constant||"number"!=typeof r)throw new Error(`Invalid filter. Type miss-match. Type: ${e.type}, Variable: ${e.constant}, Data: ${r}`);const t=r,i=e.constant;switch(e.operation){case"eq":return t===i;case"!eq":return t!==i;case"gt":return t>i;case"gte":return t>=i;case"lt":return t<i;case"lte":return t<=i;default:throw new Error("Invalid Filter. Operation does not match type")}}if("String"===e.type){if("string"!=typeof e.constant||"string"!=typeof r)throw new Error(`Invalid filter. Type miss-match. Type: ${e.type}, Variable: ${e.constant}, Data: ${r}`);const t=r,i=e.constant;switch(e.operation){case"contains":return t.includes(i);case"!contains":return!t.includes(i);case"is":return t===i;case"!is":return t!==i;case"isEmpty":return""===t;case"!isEmpty":return""!==t;default:throw new Error("Invalid Filter. Operation does not match type")}}if("Address"===e.type){if("string"!=typeof e.constant||"string"!=typeof r)throw new Error(`Invalid filter. Type miss-match. Type: ${e.type}, Variable: ${e.constant}, Data: ${r}`);const t=r,i=e.constant;switch(e.operation){case"contains":return t.toLowerCase().includes(i.toLowerCase());case"!contains":return!t.toLowerCase().includes(i.toLowerCase());case"is":return t.toLowerCase()===i.toLowerCase();case"!is":return t.toLowerCase()!==i.toLowerCase();case"isEmpty":return""===t;case"!isEmpty":return""!==t;default:throw new Error("Invalid Filter. Operation does not match type")}}throw new Error("Invalid Filter. Unknown Type")}}class w{groups=[];constructor(){this.newGroup("WHERE")}static version(){return g.version()}static new(){return new w}newGroup(t){if(0!==this.groups.length&&"WHERE"===t)throw new Error('Only the first groups can start with "WHERE"');return this.groups.push({logic:"WHERE",conditions:[]}),this}addCondition(t,e,r,i,n){const s=this.groups[this.groups.length-1];if(0===s.conditions.length&&"WHERE"!==t)throw new Error('Logic for the first condition of a group must be "WHERE"');if(s.conditions.length>0&&"WHERE"===t)throw new Error('Only the first condition of a group can be "WHERE"');return s.conditions.push({logic:t,key:e,type:r,operation:i,constant:n}),this}finalise(){for(const t of this.groups)if(0===t.conditions.length)throw new Error("Bad Filter. All Groups must have atleast one condition");return this.groups}static schema(){const t=a.string().oneOf(["AND","OR","XOR","NAND","NOR","WHERE"]).required(),e=a.object({logic:t,key:a.string().required(),type:a.string().oneOf(["String","Address","Number"]).required(),operation:a.string().when("type",(([t],e)=>{switch(t){case"String":return e.oneOf(["contains","!contains","is","!is","isEmpty","!isEmpty"]);case"Address":return e.oneOf(["is","!is","isEmpty","!isEmpty"]);case"Number":return e.oneOf(["String","Address","Number"]);default:throw new Error("Invalid Filter Data Type")}})),constant:a.mixed().when("type",(([t])=>{switch(t){case"String":case"Address":return a.string();case"Number":return a.number();default:throw new Error("Invalid Filter Data Type")}}))});return a.array().of(a.object({logic:t,conditions:a.array().of(e)}))}}class y{static SimpleToRaw(t,e,r){return{alertType:"event",network:e,nickname:t,type:"handler_function_call_v2",handler:r}}static validateCreate(t){return a.object({timeBase:a.string().oneOf(["blocks","time"]).required(),nBlocks:a.number().min(10).when("timeBase",(([t],e)=>"blocks"===t?e.required():e)),timePeriod:a.string().matches(/^(\d+)([SMHD])$/i,"timePeriod must be of the format n[s|m|h|d], eg 10s for 10 seconds").when("timeBase",(([t],e)=>"time"===t?e.required():e)),startTime:a.number().default(0),debounceCount:a.number(),functions:f.schema(),triggerOn:a.string().oneOf(["always","filter"]).default("always"),latch:a.boolean().default(!1),filterVersion:a.string().when("triggerOn",(([t],e)=>"filter"===t?e.required():e)),filter:w.schema().when("triggerOn",(([t],e)=>"filter"===t?e.required():e))}).validate(t)}}class m{static SimpleToRaw(t,e,r,i){switch(e){case"PollFunctionV2":return y.SimpleToRaw(t,r,i);case"PollFunctionV1":return h.SimpleToRaw(t,r,i);case"OnchainEventV1":return p.SimpleToRaw(t,r,i);default:throw new Error("Invalid Trigger ID")}}}const b=t=>`https://${t}.functions.supabase.co/`,E=t=>`https://${t}.supabase.co/`,v="fdgtrxmmrtlokhgkvcjz";class I{url;token;headers={};constructor(t,e){this.url=t,this.token=e,this.headers={Authorization:`Bearer ${e}`,"Content-Type":"application/json"}}static async create(t){if(t.key)throw new Error("Auth by key not yet supported");if(t.email&&t.password){const r=t.projectId?E(t.projectId):E(v),i=t.projectId?b(t.projectId):b(v),n=t.anonKey?t.anonKey:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZkZ3RyeG1tcnRsb2toZ2t2Y2p6Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NzMwODcwNzYsImV4cCI6MTk4ODY2MzA3Nn0.sAMxjlcJSSozBGr-LNcsudyxzUEM9e-UspMHHQLqLr4",s=e.createClient(r,n),{data:o,error:a}=await s.auth.signInWithPassword({email:t.email,password:t.password});if(a)throw a;if(void 0===o.session?.access_token)throw new Error("Access token not found");return new I(i,o.session?.access_token)}throw new Error("Authentication Required. DeNotify supports either username/password or API key authentication")}async alertHistory(t,e){const r="alert-history",i=e||{};return t&&(i.id=t),Object.keys(i).length>0?await this.request("get",r,{params:e}):await this.request("get",r)}async getAlert(t){return(await this.request("get",`alerts/${t}`))[0]}async getAlerts(){return await this.request("get","alerts")}async createAlert(t){const e=m.SimpleToRaw(t.name,t.triggerId,t.network,t.trigger),r=l.SimpleToRaw(t.notificationId,t.notification);return await this.request("post","alerts",{body:{trigger:e,notification:r}})}async deleteAlert(t){return await this.request("delete",`alerts/${t}`)}async request(t,e,r={}){const i=new URL(`${this.url}${e}`);if(r.params)for(const t of Object.keys(r.params))i.searchParams.append(t,r.params[t]);const n={method:t,headers:this.headers};r.body&&(n.body=JSON.stringify(r.body));const s=await c.default(i.toString(),n);if(!s.ok)throw new Error(`unexpected response ${s.statusText}`);return await s.json()}async getAbi(t,e){return await this.request("get",`abi/${t}/${e}`)}async getAbiHash(t){return(await this.request("post","abi",{body:t})).hash}async setAlertName(t,e){throw new Error("Not yet supported - Sorry!")}async enableAlert(t){throw new Error("Not yet supported - Sorry!")}async disableAlert(t){throw new Error("Not yet supported - Sorry!")}async updateNotification(t){throw new Error("Not yet supported - Sorry!")}async updateTrigger(t,e){return await this.request("patch",`alerts/trigger-handler/${t}`,{body:e})}}class O{name;network;triggerId;trigger;notificationId;notification;constructor(t){this.name=t}static create(t){return new O(t)}onNetwork(t){return this.network=t,this}withTrigger(t,e){return this.triggerId=t,this.trigger=e,this}withNotification(t,e){return this.notificationId=t,this.notification=e,this}async validate(){switch(this.triggerId){case"OnchainEventV1":return p.validateCreate(this.trigger);case"PollFunctionV1":return h.validateCreate(this.trigger);case"PollFunctionV2":return y.validateCreate(this.trigger)}if("Discord"===this.notificationId)return d.validateCreate(this.notification)}async config(){if(void 0===this.trigger||void 0===this.triggerId)throw new Error("Trigger not configured");if(void 0===this.notification||void 0===this.notificationId)throw new Error("Notification not configured");if(void 0===this.network)throw new Error("Network not configured");return await this.validate(),{name:this.name,network:this.network,triggerId:this.triggerId,trigger:this.trigger,notificationId:this.notificationId,notification:this.notification}}}var k=Object.freeze({__proto__:null,Trigger:m,HandlerFunctionCallV2:y,HandlerFunctionCall:h,HandlerOnchainEvent:p}),q=Object.freeze({__proto__:null,NOTIFY_DISCORD_WEBHOOK_RAW_ID:u,NotifyDiscordWebhook:d,Notification:l});t.AlertBuilder=O,t.DeNotifyClient=I,t.FilterBuilder=w,t.FunctionBuilder=f,t.Notification=q,t.Trigger=k}));