@neuctra/authix 1.2.0 → 1.2.2
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.
|
@@ -1851,7 +1851,7 @@ class li {
|
|
|
1851
1851
|
if (e && e.success) {
|
|
1852
1852
|
if (typeof document < "u") {
|
|
1853
1853
|
const n = (/* @__PURE__ */ new Date(0)).toUTCString();
|
|
1854
|
-
document.cookie = `a_s_b=; path=/;
|
|
1854
|
+
document.cookie = `a_s_b=; path=/; Max-Age=${n}; SameSite=Lax`;
|
|
1855
1855
|
}
|
|
1856
1856
|
return { success: !0 };
|
|
1857
1857
|
}
|
|
@@ -6515,7 +6515,7 @@ const Ns = [
|
|
|
6515
6515
|
y(!1);
|
|
6516
6516
|
}
|
|
6517
6517
|
})();
|
|
6518
|
-
}, [
|
|
6518
|
+
}, []), ee(() => {
|
|
6519
6519
|
d?.email && K((v) => ({ ...v, email: d.email }));
|
|
6520
6520
|
}, [d?.email]);
|
|
6521
6521
|
const ge = (v, U) => {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...n){const s=new this(e);return n.forEach(i=>s.set(i)),s}static accessor(e){const s=(this[Ct]=this[Ct]={accessors:{}}).accessors,i=this.prototype;function o(a){const c=Ce(a);s[c]||(on(i,a),s[c]=!0)}return f.isArray(e)?e.forEach(o):o(e),this}};re.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),f.reduceDescriptors(re.prototype,({value:t},e)=>{let n=e[0].toUpperCase()+e.slice(1);return{get:()=>t,set(s){this[n]=s}}}),f.freezeMethods(re);function Ge(t,e){const n=this||Te,s=e||n,i=re.from(s.headers);let o=s.data;return f.forEach(t,function(c){o=c.call(n,o,i.normalize(),e?e.status:void 0)}),i.normalize(),o}function Pt(t){return!!(t&&t.__CANCEL__)}function be(t,e,n){N.call(this,t??"canceled",N.ERR_CANCELED,e,n),this.name="CanceledError"}f.inherits(be,N,{__CANCEL__:!0});function Ot(t,e,n){const s=n.config.validateStatus;!n.status||!s||s(n.status)?t(n):e(new N("Request failed with status code "+n.status,[N.ERR_BAD_REQUEST,N.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function an(t){const e=/^([-+\w]{1,25})(:?\/\/|:)/.exec(t);return e&&e[1]||""}function ln(t,e){t=t||10;const n=new Array(t),s=new Array(t);let i=0,o=0,a;return e=e!==void 0?e:1e3,function(d){const u=Date.now(),x=s[o];a||(a=u),n[i]=d,s[i]=u;let y=o,k=0;for(;y!==i;)k+=n[y++],y=y%t;if(i=(i+1)%t,i===o&&(o=(o+1)%t),u-a<e)return;const T=x&&u-x;return T?Math.round(k*1e3/T):void 0}}function cn(t,e){let n=0,s=1e3/e,i,o;const a=(u,x=Date.now())=>{n=x,i=null,o&&(clearTimeout(o),o=null),t(...u)};return[(...u)=>{const x=Date.now(),y=x-n;y>=s?a(u,x):(i=u,o||(o=setTimeout(()=>{o=null,a(i)},s-y)))},()=>i&&a(i)]}const Ue=(t,e,n=3)=>{let s=0;const i=ln(50,250);return cn(o=>{const a=o.loaded,c=o.lengthComputable?o.total:void 0,d=a-s,u=i(d),x=a<=c;s=a;const y={loaded:a,total:c,progress:c?a/c:void 0,bytes:d,rate:u||void 0,estimated:u&&c&&x?(c-a)/u:void 0,event:o,lengthComputable:c!=null,[e?"download":"upload"]:!0};t(y)},n)},It=(t,e)=>{const n=t!=null;return[s=>e[0]({lengthComputable:n,total:t,loaded:s}),e[1]]},_t=t=>(...e)=>f.asap(()=>t(...e)),dn=Z.hasStandardBrowserEnv?((t,e)=>n=>(n=new URL(n,Z.origin),t.protocol===n.protocol&&t.host===n.host&&(e||t.port===n.port)))(new URL(Z.origin),Z.navigator&&/(msie|trident)/i.test(Z.navigator.userAgent)):()=>!0,un=Z.hasStandardBrowserEnv?{write(t,e,n,s,i,o){const a=[t+"="+encodeURIComponent(e)];f.isNumber(n)&&a.push("expires="+new Date(n).toGMTString()),f.isString(s)&&a.push("path="+s),f.isString(i)&&a.push("domain="+i),o===!0&&a.push("secure"),document.cookie=a.join("; ")},read(t){const e=document.cookie.match(new RegExp("(^|;\\s*)("+t+")=([^;]*)"));return e?decodeURIComponent(e[3]):null},remove(t){this.write(t,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function pn(t){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)}function fn(t,e){return e?t.replace(/\/?\/$/,"")+"/"+e.replace(/^\/+/,""):t}function Rt(t,e,n){let s=!pn(e);return t&&(s||n==!1)?fn(t,e):e}const zt=t=>t instanceof re?{...t}:t;function xe(t,e){e=e||{};const n={};function s(u,x,y,k){return f.isPlainObject(u)&&f.isPlainObject(x)?f.merge.call({caseless:k},u,x):f.isPlainObject(x)?f.merge({},x):f.isArray(x)?x.slice():x}function i(u,x,y,k){if(f.isUndefined(x)){if(!f.isUndefined(u))return s(void 0,u,y,k)}else return s(u,x,y,k)}function o(u,x){if(!f.isUndefined(x))return s(void 0,x)}function a(u,x){if(f.isUndefined(x)){if(!f.isUndefined(u))return s(void 0,u)}else return s(void 0,x)}function c(u,x,y){if(y in e)return s(u,x);if(y in t)return s(void 0,u)}const d={url:o,method:o,data:o,baseURL:a,transformRequest:a,transformResponse:a,paramsSerializer:a,timeout:a,timeoutMessage:a,withCredentials:a,withXSRFToken:a,adapter:a,responseType:a,xsrfCookieName:a,xsrfHeaderName:a,onUploadProgress:a,onDownloadProgress:a,decompress:a,maxContentLength:a,maxBodyLength:a,beforeRedirect:a,transport:a,httpAgent:a,httpsAgent:a,cancelToken:a,socketPath:a,responseEncoding:a,validateStatus:c,headers:(u,x,y)=>i(zt(u),zt(x),y,!0)};return f.forEach(Object.keys({...t,...e}),function(x){const y=d[x]||i,k=y(t[x],e[x],x);f.isUndefined(k)&&y!==c||(n[x]=k)}),n}const At=t=>{const e=xe({},t);let{data:n,withXSRFToken:s,xsrfHeaderName:i,xsrfCookieName:o,headers:a,auth:c}=e;if(e.headers=a=re.from(a),e.url=vt(Rt(e.baseURL,e.url,e.allowAbsoluteUrls),t.params,t.paramsSerializer),c&&a.set("Authorization","Basic "+btoa((c.username||"")+":"+(c.password?unescape(encodeURIComponent(c.password)):""))),f.isFormData(n)){if(Z.hasStandardBrowserEnv||Z.hasStandardBrowserWebWorkerEnv)a.setContentType(void 0);else if(f.isFunction(n.getHeaders)){const d=n.getHeaders(),u=["content-type","content-length"];Object.entries(d).forEach(([x,y])=>{u.includes(x.toLowerCase())&&a.set(x,y)})}}if(Z.hasStandardBrowserEnv&&(s&&f.isFunction(s)&&(s=s(e)),s||s!==!1&&dn(e.url))){const d=i&&o&&un.read(o);d&&a.set(i,d)}return e},xn=typeof XMLHttpRequest<"u"&&function(t){return new Promise(function(n,s){const i=At(t);let o=i.data;const a=re.from(i.headers).normalize();let{responseType:c,onUploadProgress:d,onDownloadProgress:u}=i,x,y,k,T,p;function w(){T&&T(),p&&p(),i.cancelToken&&i.cancelToken.unsubscribe(x),i.signal&&i.signal.removeEventListener("abort",x)}let h=new XMLHttpRequest;h.open(i.method.toUpperCase(),i.url,!0),h.timeout=i.timeout;function I(){if(!h)return;const g=re.from("getAllResponseHeaders"in h&&h.getAllResponseHeaders()),D={data:!c||c==="text"||c==="json"?h.responseText:h.response,status:h.status,statusText:h.statusText,headers:g,config:t,request:h};Ot(function(j){n(j),w()},function(j){s(j),w()},D),h=null}"onloadend"in h?h.onloadend=I:h.onreadystatechange=function(){!h||h.readyState!==4||h.status===0&&!(h.responseURL&&h.responseURL.indexOf("file:")===0)||setTimeout(I)},h.onabort=function(){h&&(s(new N("Request aborted",N.ECONNABORTED,t,h)),h=null)},h.onerror=function(z){const D=z&&z.message?z.message:"Network Error",b=new N(D,N.ERR_NETWORK,t,h);b.event=z||null,s(b),h=null},h.ontimeout=function(){let z=i.timeout?"timeout of "+i.timeout+"ms exceeded":"timeout exceeded";const D=i.transitional||kt;i.timeoutErrorMessage&&(z=i.timeoutErrorMessage),s(new N(z,D.clarifyTimeoutError?N.ETIMEDOUT:N.ECONNABORTED,t,h)),h=null},o===void 0&&a.setContentType(null),"setRequestHeader"in h&&f.forEach(a.toJSON(),function(z,D){h.setRequestHeader(D,z)}),f.isUndefined(i.withCredentials)||(h.withCredentials=!!i.withCredentials),c&&c!=="json"&&(h.responseType=i.responseType),u&&([k,p]=Ue(u,!0),h.addEventListener("progress",k)),d&&h.upload&&([y,T]=Ue(d),h.upload.addEventListener("progress",y),h.upload.addEventListener("loadend",T)),(i.cancelToken||i.signal)&&(x=g=>{h&&(s(!g||g.type?new be(null,t,h):g),h.abort(),h=null)},i.cancelToken&&i.cancelToken.subscribe(x),i.signal&&(i.signal.aborted?x():i.signal.addEventListener("abort",x)));const C=an(i.url);if(C&&Z.protocols.indexOf(C)===-1){s(new N("Unsupported protocol "+C+":",N.ERR_BAD_REQUEST,t));return}h.send(o||null)})},hn=(t,e)=>{const{length:n}=t=t?t.filter(Boolean):[];if(e||n){let s=new AbortController,i;const o=function(u){if(!i){i=!0,c();const x=u instanceof Error?u:this.reason;s.abort(x instanceof N?x:new be(x instanceof Error?x.message:x))}};let a=e&&setTimeout(()=>{a=null,o(new N(`timeout ${e} of ms exceeded`,N.ETIMEDOUT))},e);const c=()=>{t&&(a&&clearTimeout(a),a=null,t.forEach(u=>{u.unsubscribe?u.unsubscribe(o):u.removeEventListener("abort",o)}),t=null)};t.forEach(u=>u.addEventListener("abort",o));const{signal:d}=s;return d.unsubscribe=()=>f.asap(c),d}},mn=function*(t,e){let n=t.byteLength;if(n<e){yield t;return}let s=0,i;for(;s<n;)i=s+e,yield t.slice(s,i),s=i},gn=async function*(t,e){for await(const n of yn(t))yield*mn(n,e)},yn=async function*(t){if(t[Symbol.asyncIterator]){yield*t;return}const e=t.getReader();try{for(;;){const{done:n,value:s}=await e.read();if(n)break;yield s}}finally{await e.cancel()}},$t=(t,e,n,s)=>{const i=gn(t,e);let o=0,a,c=d=>{a||(a=!0,s&&s(d))};return new ReadableStream({async pull(d){try{const{done:u,value:x}=await i.next();if(u){c(),d.close();return}let y=x.byteLength;if(n){let k=o+=y;n(k)}d.enqueue(new Uint8Array(x))}catch(u){throw c(u),u}},cancel(d){return c(d),i.return()}},{highWaterMark:2})},Nt=64*1024,{isFunction:De}=f,bn=(({Request:t,Response:e})=>({Request:t,Response:e}))(f.global),{ReadableStream:Ut,TextEncoder:Dt}=f.global,Ft=(t,...e)=>{try{return!!t(...e)}catch{return!1}},wn=t=>{t=f.merge.call({skipUndefined:!0},bn,t);const{fetch:e,Request:n,Response:s}=t,i=e?De(e):typeof fetch=="function",o=De(n),a=De(s);if(!i)return!1;const c=i&&De(Ut),d=i&&(typeof Dt=="function"?(p=>w=>p.encode(w))(new Dt):async p=>new Uint8Array(await new n(p).arrayBuffer())),u=o&&c&&Ft(()=>{let p=!1;const w=new n(Z.origin,{body:new Ut,method:"POST",get duplex(){return p=!0,"half"}}).headers.has("Content-Type");return p&&!w}),x=a&&c&&Ft(()=>f.isReadableStream(new s("").body)),y={stream:x&&(p=>p.body)};i&&["text","arrayBuffer","blob","formData","stream"].forEach(p=>{!y[p]&&(y[p]=(w,h)=>{let I=w&&w[p];if(I)return I.call(w);throw new N(`Response type '${p}' is not supported`,N.ERR_NOT_SUPPORT,h)})});const k=async p=>{if(p==null)return 0;if(f.isBlob(p))return p.size;if(f.isSpecCompliantForm(p))return(await new n(Z.origin,{method:"POST",body:p}).arrayBuffer()).byteLength;if(f.isArrayBufferView(p)||f.isArrayBuffer(p))return p.byteLength;if(f.isURLSearchParams(p)&&(p=p+""),f.isString(p))return(await d(p)).byteLength},T=async(p,w)=>{const h=f.toFiniteNumber(p.getContentLength());return h??k(w)};return async p=>{let{url:w,method:h,data:I,signal:C,cancelToken:g,timeout:z,onDownloadProgress:D,onUploadProgress:b,responseType:j,headers:q,withCredentials:_="same-origin",fetchOptions:X}=At(p),W=e||fetch;j=j?(j+"").toLowerCase():"text";let P=hn([C,g&&g.toAbortSignal()],z),G=null;const O=P&&P.unsubscribe&&(()=>{P.unsubscribe()});let R;try{if(b&&u&&h!=="get"&&h!=="head"&&(R=await T(q,I))!==0){let l=new n(w,{method:"POST",body:I,duplex:"half"}),m;if(f.isFormData(I)&&(m=l.headers.get("content-type"))&&q.setContentType(m),l.body){const[E,U]=It(R,Ue(_t(b)));I=$t(l.body,Nt,E,U)}}f.isString(_)||(_=_?"include":"omit");const M=o&&"credentials"in n.prototype,K={...X,signal:P,method:h.toUpperCase(),headers:q.normalize().toJSON(),body:I,duplex:"half",credentials:M?_:void 0};G=o&&new n(w,K);let H=await(o?W(G,X):W(w,K));const F=x&&(j==="stream"||j==="response");if(x&&(D||F&&O)){const l={};["status","statusText","headers"].forEach(ne=>{l[ne]=H[ne]});const m=f.toFiniteNumber(H.headers.get("content-length")),[E,U]=D&&It(m,Ue(_t(D),!0))||[];H=new s($t(H.body,Nt,E,()=>{U&&U(),O&&O()}),l)}j=j||"text";let J=await y[f.findKey(y,j)||"text"](H,p);return!F&&O&&O(),await new Promise((l,m)=>{Ot(l,m,{data:J,headers:re.from(H.headers),status:H.status,statusText:H.statusText,config:p,request:G})})}catch(M){throw O&&O(),M&&M.name==="TypeError"&&/Load failed|fetch/i.test(M.message)?Object.assign(new N("Network Error",N.ERR_NETWORK,p,G),{cause:M.cause||M}):N.from(M,M&&M.code,p,G)}}},Sn=new Map,Lt=t=>{let e=t?t.env:{};const{fetch:n,Request:s,Response:i}=e,o=[s,i,n];let a=o.length,c=a,d,u,x=Sn;for(;c--;)d=o[c],u=x.get(d),u===void 0&&x.set(d,u=c?new Map:wn(e)),x=u;return u};Lt();const Xe={http:Mr,xhr:xn,fetch:{get:Lt}};f.forEach(Xe,(t,e)=>{if(t){try{Object.defineProperty(t,"name",{value:e})}catch{}Object.defineProperty(t,"adapterName",{value:e})}});const qt=t=>`- ${t}`,jn=t=>f.isFunction(t)||t===null||t===!1,Mt={getAdapter:(t,e)=>{t=f.isArray(t)?t:[t];const{length:n}=t;let s,i;const o={};for(let a=0;a<n;a++){s=t[a];let c;if(i=s,!jn(s)&&(i=Xe[(c=String(s)).toLowerCase()],i===void 0))throw new N(`Unknown adapter '${c}'`);if(i&&(f.isFunction(i)||(i=i.get(e))))break;o[c||"#"+a]=i}if(!i){const a=Object.entries(o).map(([d,u])=>`adapter ${d} `+(u===!1?"is not supported by the environment":"is not available in the build"));let c=n?a.length>1?`since :
|
|
4
4
|
`+a.map(qt).join(`
|
|
5
5
|
`):" "+qt(a[0]):"as no adapter specified";throw new N("There is no suitable adapter to dispatch the request "+c,"ERR_NOT_SUPPORT")}return i},adapters:Xe};function Ze(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new be(null,t)}function Wt(t){return Ze(t),t.headers=re.from(t.headers),t.data=Ge.call(t,t.transformRequest),["post","put","patch"].indexOf(t.method)!==-1&&t.headers.setContentType("application/x-www-form-urlencoded",!1),Mt.getAdapter(t.adapter||Te.adapter,t)(t).then(function(s){return Ze(t),s.data=Ge.call(t,t.transformResponse,s),s.headers=re.from(s.headers),s},function(s){return Pt(s)||(Ze(t),s&&s.response&&(s.response.data=Ge.call(t,t.transformResponse,s.response),s.response.headers=re.from(s.response.headers))),Promise.reject(s)})}const Bt="1.12.2",Fe={};["object","boolean","number","function","string","symbol"].forEach((t,e)=>{Fe[t]=function(s){return typeof s===t||"a"+(e<1?"n ":" ")+t}});const Ht={};Fe.transitional=function(e,n,s){function i(o,a){return"[Axios v"+Bt+"] Transitional option '"+o+"'"+a+(s?". "+s:"")}return(o,a,c)=>{if(e===!1)throw new N(i(a," has been removed"+(n?" in "+n:"")),N.ERR_DEPRECATED);return n&&!Ht[a]&&(Ht[a]=!0,console.warn(i(a," has been deprecated since v"+n+" and will be removed in the near future"))),e?e(o,a,c):!0}},Fe.spelling=function(e){return(n,s)=>(console.warn(`${s} is likely a misspelling of ${e}`),!0)};function vn(t,e,n){if(typeof t!="object")throw new N("options must be an object",N.ERR_BAD_OPTION_VALUE);const s=Object.keys(t);let i=s.length;for(;i-- >0;){const o=s[i],a=e[o];if(a){const c=t[o],d=c===void 0||a(c,o,t);if(d!==!0)throw new N("option "+o+" must be "+d,N.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new N("Unknown option "+o,N.ERR_BAD_OPTION)}}const Le={assertOptions:vn,validators:Fe},ae=Le.validators;let he=class{constructor(e){this.defaults=e||{},this.interceptors={request:new Et,response:new Et}}async request(e,n){try{return await this._request(e,n)}catch(s){if(s instanceof Error){let i={};Error.captureStackTrace?Error.captureStackTrace(i):i=new Error;const o=i.stack?i.stack.replace(/^.+\n/,""):"";try{s.stack?o&&!String(s.stack).endsWith(o.replace(/^.+\n.+\n/,""))&&(s.stack+=`
|
|
6
|
-
`+o):s.stack=o}catch{}}throw s}}_request(e,n){typeof e=="string"?(n=n||{},n.url=e):n=e||{},n=xe(this.defaults,n);const{transitional:s,paramsSerializer:i,headers:o}=n;s!==void 0&&Le.assertOptions(s,{silentJSONParsing:ae.transitional(ae.boolean),forcedJSONParsing:ae.transitional(ae.boolean),clarifyTimeoutError:ae.transitional(ae.boolean)},!1),i!=null&&(f.isFunction(i)?n.paramsSerializer={serialize:i}:Le.assertOptions(i,{encode:ae.function,serialize:ae.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Le.assertOptions(n,{baseUrl:ae.spelling("baseURL"),withXsrfToken:ae.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let a=o&&f.merge(o.common,o[n.method]);o&&f.forEach(["delete","get","head","post","put","patch","common"],p=>{delete o[p]}),n.headers=re.concat(a,o);const c=[];let d=!0;this.interceptors.request.forEach(function(w){typeof w.runWhen=="function"&&w.runWhen(n)===!1||(d=d&&w.synchronous,c.unshift(w.fulfilled,w.rejected))});const u=[];this.interceptors.response.forEach(function(w){u.push(w.fulfilled,w.rejected)});let x,y=0,k;if(!d){const p=[Wt.bind(this),void 0];for(p.unshift(...c),p.push(...u),k=p.length,x=Promise.resolve(n);y<k;)x=x.then(p[y++],p[y++]);return x}k=c.length;let T=n;for(;y<k;){const p=c[y++],w=c[y++];try{T=p(T)}catch(h){w.call(this,h);break}}try{x=Wt.call(this,T)}catch(p){return Promise.reject(p)}for(y=0,k=u.length;y<k;)x=x.then(u[y++],u[y++]);return x}getUri(e){e=xe(this.defaults,e);const n=Rt(e.baseURL,e.url,e.allowAbsoluteUrls);return vt(n,e.params,e.paramsSerializer)}};f.forEach(["delete","get","head","options"],function(e){he.prototype[e]=function(n,s){return this.request(xe(s||{},{method:e,url:n,data:(s||{}).data}))}}),f.forEach(["post","put","patch"],function(e){function n(s){return function(o,a,c){return this.request(xe(c||{},{method:e,headers:s?{"Content-Type":"multipart/form-data"}:{},url:o,data:a}))}}he.prototype[e]=n(),he.prototype[e+"Form"]=n(!0)});let En=class nr{constructor(e){if(typeof e!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(o){n=o});const s=this;this.promise.then(i=>{if(!s._listeners)return;let o=s._listeners.length;for(;o-- >0;)s._listeners[o](i);s._listeners=null}),this.promise.then=i=>{let o;const a=new Promise(c=>{s.subscribe(c),o=c}).then(i);return a.cancel=function(){s.unsubscribe(o)},a},e(function(o,a,c){s.reason||(s.reason=new be(o,a,c),n(s.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const n=this._listeners.indexOf(e);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const e=new AbortController,n=s=>{e.abort(s)};return this.subscribe(n),e.signal.unsubscribe=()=>this.unsubscribe(n),e.signal}static source(){let e;return{token:new nr(function(i){e=i}),cancel:e}}};function kn(t){return function(n){return t.apply(null,n)}}function Tn(t){return f.isObject(t)&&t.isAxiosError===!0}const Qe={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(Qe).forEach(([t,e])=>{Qe[e]=t});function Vt(t){const e=new he(t),n=lt(he.prototype.request,e);return f.extend(n,he.prototype,e,{allOwnKeys:!0}),f.extend(n,e,null,{allOwnKeys:!0}),n.create=function(i){return Vt(xe(t,i))},n}const Y=Vt(Te);Y.Axios=he,Y.CanceledError=be,Y.CancelToken=En,Y.isCancel=Pt,Y.VERSION=Bt,Y.toFormData=$e,Y.AxiosError=N,Y.Cancel=Y.CanceledError,Y.all=function(e){return Promise.all(e)},Y.spread=kn,Y.isAxiosError=Tn,Y.mergeConfig=xe,Y.AxiosHeaders=re,Y.formToJSON=t=>Tt(f.isHTMLForm(t)?new FormData(t):t),Y.getAdapter=Mt.getAdapter,Y.HttpStatusCode=Qe,Y.default=Y;const{Axios:xs,AxiosError:hs,CanceledError:ms,isCancel:gs,CancelToken:ys,VERSION:bs,all:ws,Cancel:Ss,isAxiosError:js,spread:vs,toFormData:Es,AxiosHeaders:ks,HttpStatusCode:Ts,formToJSON:Cs,getAdapter:Ps,mergeConfig:Os}=Y;class Cn{baseUrl;apiKey;appId;client;constructor(e){if(!e||!e.baseUrl)throw new Error("NeuctraAuthixClient: 'baseUrl' is required in config");this.baseUrl=e.baseUrl.replace(/\/$/,""),this.apiKey=e.apiKey||null,this.appId=e.appId||null,this.client=Y.create({baseURL:this.baseUrl,headers:{"Content-Type":"application/json",...this.apiKey?{"x-api-key":this.apiKey}:{}},timeout:3e4,withCredentials:!0})}async request(e,n,s,i={},o=!1){try{const a={...this.appId?{appId:this.appId}:{},...s||{}};return(await this.client.request({url:n,method:e,data:a,headers:i,withCredentials:o})).data}catch(a){throw Y.isAxiosError(a)?{message:a.response?.data?.message||a.message||"Request failed",status:a.response?.status??0}:{message:a.message||"Unexpected error occurred"}}}async signupUser(e){const{name:n,email:s,password:i}=e;if(!n||!s||!i)throw new Error("signup: 'name', 'email', and 'password' are required");return await this.request("POST","/users/signup",e,{},!0)}async loginUser(e){const{email:n,password:s}=e;if(!n||!s)throw new Error("login: 'email' and 'password' are required");try{return await this.request("POST","/users/login",{email:n,password:s},{},!0)}catch(i){throw new Error(i.message||"Login failed due to an unknown error")}}async logoutUser(){try{const e=await this.request("POST","/users/logout",{},{},!0);if(e&&e.success){if(typeof document<"u"){const n=new Date(0).toUTCString();document.cookie=`a_s_b=; path=/; expires=${n}; SameSite=Lax`}return{success:!0}}return{success:!1}}catch(e){throw new Error(e.message||"Logout failed due to an unknown error")}}async changePassword(e){const{userId:n,currentPassword:s,newPassword:i}=e;if(!n)throw new Error("changePassword: 'userId' is required");if(!s||!i)throw new Error("changePassword: both 'currentPassword' and 'newPassword' are required");return await this.request("PUT",`/users/change-password/${n}`,{currentPassword:s,newPassword:i},{},!0)}async requestEmailVerificationOTP(e){const{userId:n,email:s}=e;if(!n)throw{message:"requestEmailVerificationOTP: 'userId' is required",status:400};if(!s)throw{message:"requestEmailVerificationOTP: 'email' is required",status:400};try{return await this.request("POST",`/users/send-verify-otp/${encodeURIComponent(n)}`,{email:s},{},!0)}catch(i){throw console.error("requestEmailVerificationOTP Error:",i),{message:i?.message||"Failed to send verification OTP",status:i?.status||500}}}async verifyEmail(e){const{email:n,otp:s}=e;if(!n)throw new Error("verifyEmail: 'email' is required");if(!s)throw new Error("verifyEmail: 'otp' is required");try{return await this.request("POST","/users/verify-email",{email:n,otp:s},{},!0)}catch(i){throw{message:i.message||"Failed to verify email",status:i.status||500}}}async checkUserSession(){if(typeof window>"u")return{authenticated:!1};try{return await this.request("GET","/users/session",void 0,{},!0)}catch{return{authenticated:!1}}}async updateUser(e){const{userId:n}=e;if(!n)throw new Error("updateUser: 'userId' is required");return await this.request("PUT",`/users/update/${n}`,{...e},{},!0)}async deleteUser(e){const{userId:n}=e;if(!n)throw new Error("deleteUser: 'userId' is required");return await this.request("DELETE",`/users/delete/${n}`,{},{},!0)}async getUserProfile(e){const{userId:n}=e;if(!n)throw new Error("getProfile: 'userId' and 'appId' are required");try{return await this.request("POST","/users/profile",{userId:n},{},!0)}catch(s){throw{message:s.message||"Failed to fetch profile",status:s.status||500}}}async requestResetUserPasswordOTP(e){const{email:n}=e;if(!n)throw new Error("forgotPassword: 'email' is required");return await this.request("POST","/users/forgot-password",{email:n})}async resetUserPassword(e){const{email:n,otp:s,newPassword:i}=e;if(!n||!s||!i)throw new Error("resetPassword: 'email', 'otp' and 'newPassword' are required");return await this.request("POST","/users/reset-password",{email:n,otp:s,newPassword:i})}async checkIfUserExists(e){if(!e)throw new Error("checkUser: 'userId' is required");return await this.request("GET",`/users/check-user/${e}?appId=${this.appId}`)}async searchUserData(e){const{userId:n,...s}=e;if(!n)throw new Error("userId required");const i=new URLSearchParams(s).toString();return await this.request("GET",`/users/${n}/data/search?${i}`,void 0,{},!1)}async searchUserDataByKeys(e){const{userId:n,...s}=e;if(!n)throw new Error("searchUserDataByKeys: 'userId' is required");const i=new URLSearchParams(Object.entries(s).reduce((o,[a,c])=>(c!=null&&(o[a]=String(c)),o),{})).toString();return await this.request("GET",`/users/${n}/data/searchbyref?${i}`,void 0,{},!1)}async getUserData(e){const{userId:n}=e;if(!n)throw new Error("getUserData: 'userId' is required");return await this.request("GET",`/users/${n}/data`,void 0,{},!1)}async getSingleUserData(e){const{userId:n,dataId:s}=e;if(!n||!s)throw new Error("getSingleUserData: 'userId' and 'dataId' are required");return await this.request("GET",`/users/${n}/data/${s}`,void 0,{},!1)}async addUserData(e){const{userId:n,dataCategory:s,data:i}=e;if(!n)throw new Error("addUserData: 'userId' is required");if(!s)throw new Error("addUserData: 'dataCategory' is required");if(!i)throw new Error("addUserData: 'data' is required");return await this.request("POST",`/users/${n}/data`,{dataCategory:s,...i},{},!1)}async updateUserData(e){const{userId:n,dataId:s,data:i}=e;if(!n||!s)throw new Error("updateUserData: 'userId' and 'dataId' are required");if(!i)throw new Error("updateUserData: 'data' is required");return await this.request("PUT",`/users/${n}/data/${s}`,i,{},!1)}async deleteUserData(e){const{userId:n,dataId:s}=e;if(!n||!s)throw new Error("deleteUserData: 'userId' and 'dataId' are required");return await this.request("DELETE",`/users/${n}/data/${s}`,void 0,{},!1)}async getAppData(e){const n=this.appId;if(!n)throw new Error("getAppData: 'appId' is required");const s=e?`?category=${encodeURIComponent(e)}`:"";return await this.request("GET",`/app/${n}/data${s}`,void 0,{},!1)}async getSingleAppData(e){const n=this.appId;if(!n)throw new Error("getSingleAppData: 'appId' is required");if(!e.dataId)throw new Error("getSingleAppData: 'dataId' is required");return await this.request("GET",`/app/${n}/data/${e.dataId}`,void 0,{},!1)}async searchAppDataByKeys(e){const n=this.appId;if(!n)throw new Error("searchAppDataByKeys: 'appId' is required");if(!e||typeof e!="object")throw new Error("searchAppDataByKeys: params object is required");return await this.request("POST",`/app/${encodeURIComponent(n)}/data/search/bykeys`,e,{},!1)}async addAppData(e){const n=this.appId;if(!n)throw new Error("addAppData: 'appId' is required");const{dataCategory:s,data:i}=e;if(!s)throw new Error("addAppData: 'dataCategory' is required");if(!i||typeof i!="object")throw new Error("addAppData: 'data' is required");return await this.request("POST",`/app/${n}/data/${encodeURIComponent(s)}`,{item:i},{},!1)}async updateAppData(e){const n=this.appId;if(!n)throw new Error("updateAppData: 'appId' is required");if(!e.dataId)throw new Error("updateAppData: 'dataId' is required");if(!e.data)throw new Error("updateAppData: 'data' is required");return await this.request("PATCH",`/app/${n}/data/${e.dataId}`,e.data,{},!1)}async deleteAppData(e){const n=this.appId;if(!n)throw new Error("deleteAppData: 'appId' is required");if(!e.dataId)throw new Error("deleteAppData: 'dataId' is required");return await this.request("DELETE",`/app/${n}/data/${e.dataId}`,void 0,{},!1)}}var qe={exports:{}},Pe={};/**
|
|
6
|
+
`+o):s.stack=o}catch{}}throw s}}_request(e,n){typeof e=="string"?(n=n||{},n.url=e):n=e||{},n=xe(this.defaults,n);const{transitional:s,paramsSerializer:i,headers:o}=n;s!==void 0&&Le.assertOptions(s,{silentJSONParsing:ae.transitional(ae.boolean),forcedJSONParsing:ae.transitional(ae.boolean),clarifyTimeoutError:ae.transitional(ae.boolean)},!1),i!=null&&(f.isFunction(i)?n.paramsSerializer={serialize:i}:Le.assertOptions(i,{encode:ae.function,serialize:ae.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Le.assertOptions(n,{baseUrl:ae.spelling("baseURL"),withXsrfToken:ae.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let a=o&&f.merge(o.common,o[n.method]);o&&f.forEach(["delete","get","head","post","put","patch","common"],p=>{delete o[p]}),n.headers=re.concat(a,o);const c=[];let d=!0;this.interceptors.request.forEach(function(w){typeof w.runWhen=="function"&&w.runWhen(n)===!1||(d=d&&w.synchronous,c.unshift(w.fulfilled,w.rejected))});const u=[];this.interceptors.response.forEach(function(w){u.push(w.fulfilled,w.rejected)});let x,y=0,k;if(!d){const p=[Wt.bind(this),void 0];for(p.unshift(...c),p.push(...u),k=p.length,x=Promise.resolve(n);y<k;)x=x.then(p[y++],p[y++]);return x}k=c.length;let T=n;for(;y<k;){const p=c[y++],w=c[y++];try{T=p(T)}catch(h){w.call(this,h);break}}try{x=Wt.call(this,T)}catch(p){return Promise.reject(p)}for(y=0,k=u.length;y<k;)x=x.then(u[y++],u[y++]);return x}getUri(e){e=xe(this.defaults,e);const n=Rt(e.baseURL,e.url,e.allowAbsoluteUrls);return vt(n,e.params,e.paramsSerializer)}};f.forEach(["delete","get","head","options"],function(e){he.prototype[e]=function(n,s){return this.request(xe(s||{},{method:e,url:n,data:(s||{}).data}))}}),f.forEach(["post","put","patch"],function(e){function n(s){return function(o,a,c){return this.request(xe(c||{},{method:e,headers:s?{"Content-Type":"multipart/form-data"}:{},url:o,data:a}))}}he.prototype[e]=n(),he.prototype[e+"Form"]=n(!0)});let En=class nr{constructor(e){if(typeof e!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(o){n=o});const s=this;this.promise.then(i=>{if(!s._listeners)return;let o=s._listeners.length;for(;o-- >0;)s._listeners[o](i);s._listeners=null}),this.promise.then=i=>{let o;const a=new Promise(c=>{s.subscribe(c),o=c}).then(i);return a.cancel=function(){s.unsubscribe(o)},a},e(function(o,a,c){s.reason||(s.reason=new be(o,a,c),n(s.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const n=this._listeners.indexOf(e);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const e=new AbortController,n=s=>{e.abort(s)};return this.subscribe(n),e.signal.unsubscribe=()=>this.unsubscribe(n),e.signal}static source(){let e;return{token:new nr(function(i){e=i}),cancel:e}}};function kn(t){return function(n){return t.apply(null,n)}}function Tn(t){return f.isObject(t)&&t.isAxiosError===!0}const Qe={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(Qe).forEach(([t,e])=>{Qe[e]=t});function Vt(t){const e=new he(t),n=lt(he.prototype.request,e);return f.extend(n,he.prototype,e,{allOwnKeys:!0}),f.extend(n,e,null,{allOwnKeys:!0}),n.create=function(i){return Vt(xe(t,i))},n}const Y=Vt(Te);Y.Axios=he,Y.CanceledError=be,Y.CancelToken=En,Y.isCancel=Pt,Y.VERSION=Bt,Y.toFormData=$e,Y.AxiosError=N,Y.Cancel=Y.CanceledError,Y.all=function(e){return Promise.all(e)},Y.spread=kn,Y.isAxiosError=Tn,Y.mergeConfig=xe,Y.AxiosHeaders=re,Y.formToJSON=t=>Tt(f.isHTMLForm(t)?new FormData(t):t),Y.getAdapter=Mt.getAdapter,Y.HttpStatusCode=Qe,Y.default=Y;const{Axios:xs,AxiosError:hs,CanceledError:ms,isCancel:gs,CancelToken:ys,VERSION:bs,all:ws,Cancel:Ss,isAxiosError:js,spread:vs,toFormData:Es,AxiosHeaders:ks,HttpStatusCode:Ts,formToJSON:Cs,getAdapter:Ps,mergeConfig:Os}=Y;class Cn{baseUrl;apiKey;appId;client;constructor(e){if(!e||!e.baseUrl)throw new Error("NeuctraAuthixClient: 'baseUrl' is required in config");this.baseUrl=e.baseUrl.replace(/\/$/,""),this.apiKey=e.apiKey||null,this.appId=e.appId||null,this.client=Y.create({baseURL:this.baseUrl,headers:{"Content-Type":"application/json",...this.apiKey?{"x-api-key":this.apiKey}:{}},timeout:3e4,withCredentials:!0})}async request(e,n,s,i={},o=!1){try{const a={...this.appId?{appId:this.appId}:{},...s||{}};return(await this.client.request({url:n,method:e,data:a,headers:i,withCredentials:o})).data}catch(a){throw Y.isAxiosError(a)?{message:a.response?.data?.message||a.message||"Request failed",status:a.response?.status??0}:{message:a.message||"Unexpected error occurred"}}}async signupUser(e){const{name:n,email:s,password:i}=e;if(!n||!s||!i)throw new Error("signup: 'name', 'email', and 'password' are required");return await this.request("POST","/users/signup",e,{},!0)}async loginUser(e){const{email:n,password:s}=e;if(!n||!s)throw new Error("login: 'email' and 'password' are required");try{return await this.request("POST","/users/login",{email:n,password:s},{},!0)}catch(i){throw new Error(i.message||"Login failed due to an unknown error")}}async logoutUser(){try{const e=await this.request("POST","/users/logout",{},{},!0);if(e&&e.success){if(typeof document<"u"){const n=new Date(0).toUTCString();document.cookie=`a_s_b=; path=/; Max-Age=${n}; SameSite=Lax`}return{success:!0}}return{success:!1}}catch(e){throw new Error(e.message||"Logout failed due to an unknown error")}}async changePassword(e){const{userId:n,currentPassword:s,newPassword:i}=e;if(!n)throw new Error("changePassword: 'userId' is required");if(!s||!i)throw new Error("changePassword: both 'currentPassword' and 'newPassword' are required");return await this.request("PUT",`/users/change-password/${n}`,{currentPassword:s,newPassword:i},{},!0)}async requestEmailVerificationOTP(e){const{userId:n,email:s}=e;if(!n)throw{message:"requestEmailVerificationOTP: 'userId' is required",status:400};if(!s)throw{message:"requestEmailVerificationOTP: 'email' is required",status:400};try{return await this.request("POST",`/users/send-verify-otp/${encodeURIComponent(n)}`,{email:s},{},!0)}catch(i){throw console.error("requestEmailVerificationOTP Error:",i),{message:i?.message||"Failed to send verification OTP",status:i?.status||500}}}async verifyEmail(e){const{email:n,otp:s}=e;if(!n)throw new Error("verifyEmail: 'email' is required");if(!s)throw new Error("verifyEmail: 'otp' is required");try{return await this.request("POST","/users/verify-email",{email:n,otp:s},{},!0)}catch(i){throw{message:i.message||"Failed to verify email",status:i.status||500}}}async checkUserSession(){if(typeof window>"u")return{authenticated:!1};try{return await this.request("GET","/users/session",void 0,{},!0)}catch{return{authenticated:!1}}}async updateUser(e){const{userId:n}=e;if(!n)throw new Error("updateUser: 'userId' is required");return await this.request("PUT",`/users/update/${n}`,{...e},{},!0)}async deleteUser(e){const{userId:n}=e;if(!n)throw new Error("deleteUser: 'userId' is required");return await this.request("DELETE",`/users/delete/${n}`,{},{},!0)}async getUserProfile(e){const{userId:n}=e;if(!n)throw new Error("getProfile: 'userId' and 'appId' are required");try{return await this.request("POST","/users/profile",{userId:n},{},!0)}catch(s){throw{message:s.message||"Failed to fetch profile",status:s.status||500}}}async requestResetUserPasswordOTP(e){const{email:n}=e;if(!n)throw new Error("forgotPassword: 'email' is required");return await this.request("POST","/users/forgot-password",{email:n})}async resetUserPassword(e){const{email:n,otp:s,newPassword:i}=e;if(!n||!s||!i)throw new Error("resetPassword: 'email', 'otp' and 'newPassword' are required");return await this.request("POST","/users/reset-password",{email:n,otp:s,newPassword:i})}async checkIfUserExists(e){if(!e)throw new Error("checkUser: 'userId' is required");return await this.request("GET",`/users/check-user/${e}?appId=${this.appId}`)}async searchUserData(e){const{userId:n,...s}=e;if(!n)throw new Error("userId required");const i=new URLSearchParams(s).toString();return await this.request("GET",`/users/${n}/data/search?${i}`,void 0,{},!1)}async searchUserDataByKeys(e){const{userId:n,...s}=e;if(!n)throw new Error("searchUserDataByKeys: 'userId' is required");const i=new URLSearchParams(Object.entries(s).reduce((o,[a,c])=>(c!=null&&(o[a]=String(c)),o),{})).toString();return await this.request("GET",`/users/${n}/data/searchbyref?${i}`,void 0,{},!1)}async getUserData(e){const{userId:n}=e;if(!n)throw new Error("getUserData: 'userId' is required");return await this.request("GET",`/users/${n}/data`,void 0,{},!1)}async getSingleUserData(e){const{userId:n,dataId:s}=e;if(!n||!s)throw new Error("getSingleUserData: 'userId' and 'dataId' are required");return await this.request("GET",`/users/${n}/data/${s}`,void 0,{},!1)}async addUserData(e){const{userId:n,dataCategory:s,data:i}=e;if(!n)throw new Error("addUserData: 'userId' is required");if(!s)throw new Error("addUserData: 'dataCategory' is required");if(!i)throw new Error("addUserData: 'data' is required");return await this.request("POST",`/users/${n}/data`,{dataCategory:s,...i},{},!1)}async updateUserData(e){const{userId:n,dataId:s,data:i}=e;if(!n||!s)throw new Error("updateUserData: 'userId' and 'dataId' are required");if(!i)throw new Error("updateUserData: 'data' is required");return await this.request("PUT",`/users/${n}/data/${s}`,i,{},!1)}async deleteUserData(e){const{userId:n,dataId:s}=e;if(!n||!s)throw new Error("deleteUserData: 'userId' and 'dataId' are required");return await this.request("DELETE",`/users/${n}/data/${s}`,void 0,{},!1)}async getAppData(e){const n=this.appId;if(!n)throw new Error("getAppData: 'appId' is required");const s=e?`?category=${encodeURIComponent(e)}`:"";return await this.request("GET",`/app/${n}/data${s}`,void 0,{},!1)}async getSingleAppData(e){const n=this.appId;if(!n)throw new Error("getSingleAppData: 'appId' is required");if(!e.dataId)throw new Error("getSingleAppData: 'dataId' is required");return await this.request("GET",`/app/${n}/data/${e.dataId}`,void 0,{},!1)}async searchAppDataByKeys(e){const n=this.appId;if(!n)throw new Error("searchAppDataByKeys: 'appId' is required");if(!e||typeof e!="object")throw new Error("searchAppDataByKeys: params object is required");return await this.request("POST",`/app/${encodeURIComponent(n)}/data/search/bykeys`,e,{},!1)}async addAppData(e){const n=this.appId;if(!n)throw new Error("addAppData: 'appId' is required");const{dataCategory:s,data:i}=e;if(!s)throw new Error("addAppData: 'dataCategory' is required");if(!i||typeof i!="object")throw new Error("addAppData: 'data' is required");return await this.request("POST",`/app/${n}/data/${encodeURIComponent(s)}`,{item:i},{},!1)}async updateAppData(e){const n=this.appId;if(!n)throw new Error("updateAppData: 'appId' is required");if(!e.dataId)throw new Error("updateAppData: 'dataId' is required");if(!e.data)throw new Error("updateAppData: 'data' is required");return await this.request("PATCH",`/app/${n}/data/${e.dataId}`,e.data,{},!1)}async deleteAppData(e){const n=this.appId;if(!n)throw new Error("deleteAppData: 'appId' is required");if(!e.dataId)throw new Error("deleteAppData: 'dataId' is required");return await this.request("DELETE",`/app/${n}/data/${e.dataId}`,void 0,{},!1)}}var qe={exports:{}},Pe={};/**
|
|
7
7
|
* @license React
|
|
8
8
|
* react-jsx-runtime.production.js
|
|
9
9
|
*
|
|
@@ -496,7 +496,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
496
496
|
animation: none;
|
|
497
497
|
}
|
|
498
498
|
}
|
|
499
|
-
`})]})},ss=({darkMode:t=!0,homeUrl:e,onLogout:n,onVerify:s,primaryColor:i="#00C212"})=>{const o=me(),[a,c]=S.useState(null),[d,u]=S.useState(),[x,y]=S.useState(!0),[k,T]=S.useState(!1),[p,w]=S.useState(!1),[h,I]=S.useState(!1),[C,g]=S.useState(!1),[z,D]=S.useState(!1),[b,j]=S.useState(!1),[q,_]=S.useState(!1),[X,W]=S.useState(!1),[P,G]=S.useState(null),[O,R]=S.useState(!1),[M,K]=S.useState({email:"",otp:""}),[H,F]=S.useState(!1),[J,l]=S.useState(!1);S.useEffect(()=>{if(typeof window<"u"){const v=()=>c(window.innerWidth);return v(),window.addEventListener("resize",v),()=>window.removeEventListener("resize",v)}},[]);const m=(v,$)=>{G({type:v,message:$}),setTimeout(()=>G(null),3e3)},E=()=>{W(!0);const v=setTimeout(()=>{_(!1),W(!1)},150);return()=>clearTimeout(v)};S.useEffect(()=>{const v=$=>{const V=document.querySelector(".dropdown-container");V&&!V.contains($.target)&&E()};return q&&document.addEventListener("mousedown",v),()=>{document.removeEventListener("mousedown",v)}},[q]);const U=async()=>{if(!M.email||!/\S+@\S+\.\S+/.test(M.email)){m("error","Please enter a valid email");return}if(!d?.id){m("error","User not found. Cannot send OTP.");return}try{l(!0);const v=await o.requestEmailVerificationOTP({userId:d.id,email:M.email}),$=v?.data?.success??v?.success,V=v?.data?.message??v?.message;$?(m("success",V||"OTP sent to email!"),F(!0)):m("error",V||"Failed to send OTP")}catch(v){const $=v?.response?.data?.message||v?.message||"Server error";m("error",$)}finally{l(!1)}},ne=async v=>{if(v.preventDefault(),!M.email||!M.otp){m("error","Please fill in all fields");return}if(!d){m("error","User not found");return}try{l(!0);const $=await o.verifyEmail({email:M.email,otp:M.otp}),V=$?.data?.success??$?.success,Q=$?.data?.message??$?.message;if(V){m("success",Q||"Email verified!");const ue={...d,isVerified:!0};u(ue),typeof s=="function"&&s(ue),K({email:ue.email,otp:""}),F(!1),j?.(!1)}else m("error",Q||"Verification failed")}catch($){const V=$?.response?.data?.message||$?.message||"Something went wrong";m("error",V)}finally{l(!1)}},le=async v=>{if(!d)return!1;try{const $=await o.updateUser({userId:d.id,avatarUrl:v});if($?.success){const V={...d,...$.user,avatarUrl:v};return u(V),m("success","Avatar updated successfully!"),!0}return m("error",$?.message||"Failed to update avatar"),!1}catch($){return console.error("Avatar update error:",$),m("error","Failed to update avatar"),!1}},B=async()=>{if(d){w(!0);try{const v=d.email,$=await o.updateUser({userId:d.id,...d});if($.success&&$.user){const V=$.user.email!==v,Q={...d,...$.user,isVerified:V?!1:d.isVerified};u(Q),localStorage.setItem("userInfo",JSON.stringify(Q)),m("success",V?"Email updated. Please verify your new email.":"Profile updated successfully"),T(!1)}else m("error",$.message||"Update failed")}catch(v){console.error(v),m("error","Update failed")}finally{w(!1)}}},ce=async v=>{try{const $=await o.checkIfUserExists(v);$?.success===!0&&$?.exists===!1&&(console.warn("❌ User does not exist on server. Clearing session..."),localStorage.removeItem("userInfo"),u(null))}catch($){console.error("⚠️ User validation request failed:",$)}};S.useEffect(()=>{(async()=>{try{y(!0);const $=await o.checkUserSession();if($.user?.id){const V=$.user.id,Q=await o.getUserProfile({userId:V});if(Q.user){const ue=Q.user;u(ue),ce(V)}else u(null),localStorage.removeItem("userInfo")}else u(null),localStorage.removeItem("userInfo")}catch($){console.error("User init failed:",$),u(null),localStorage.removeItem("userInfo")}finally{y(!1)}})()},[d]),S.useEffect(()=>{d?.email&&K(v=>({...v,email:d.email}))},[d?.email]);const je=(v,$)=>{let V=parseInt(v.replace("#",""),16),Q=(V>>16)+$,ue=(V>>8&255)+$,at=(V&255)+$;return Q=Math.min(255,Math.max(0,Q)),ue=Math.min(255,Math.max(0,ue)),at=Math.min(255,Math.max(0,at)),`#${(at|ue<<8|Q<<16).toString(16).padStart(6,"0")}`},A=t?{background:"#000000",surface:"#09090b",surfaceLight:"#27272a",surfaceLighter:"#3f3f46",textPrimary:"#ffffff",textSecondary:"#d4d4d8",textTertiary:"#a1a1aa",accent:i,accentHover:je(i,-15),success:"#10b981",error:"#ef4444",border:"#27272a",warning:"#f59e0b"}:{background:"#ffffff",surface:"#fafafa",surfaceLight:"#f4f4f5",surfaceLighter:"#e4e4e7",textPrimary:"#18181b",textSecondary:"#52525b",textTertiary:"#71717a",accent:i,accentHover:je(i,-15),success:"#10b981",error:"#ef4444",border:"#e4e4e7",warning:"#d97706"};if(x)return r.jsx("div",{style:{width:"100%",minHeight:"400px",display:"flex",alignItems:"center",justifyContent:"center",color:A.textPrimary,fontFamily:"'Inter', -apple-system, BlinkMacSystemFont, sans-serif"},children:r.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"16px",textAlign:"center"},children:[r.jsx(oe,{size:40,color:A.accent,style:{animation:"spin 1s linear infinite"},"aria-hidden":"true"}),r.jsx("p",{style:{color:A.textTertiary,margin:0},children:"Loading your profile..."})]})});if(!d)return r.jsx("div",{style:{width:"100%",minHeight:"400px",display:"flex",alignItems:"center",justifyContent:"center",color:A.textPrimary,fontFamily:"'Inter', -apple-system, BlinkMacSystemFont, sans-serif"},children:r.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",textAlign:"center"},children:[r.jsx(ie,{size:40,color:A.error,"aria-hidden":"true"}),r.jsx("p",{style:{color:A.textTertiary,margin:0},children:"No profile found. Please log in again."})]})});const as=[{label:"Full Name",value:d.name,name:"name",type:"text",icon:Se},{label:"Email Address",value:d.email,name:"email",type:"email",icon:pe},{label:"Phone Number",value:d.phone||"Not set",name:"phone",type:"tel",icon:Hn},{label:"Address",value:d.address||"Not provided",name:"address",type:"text",icon:Wn}];return r.jsxs("div",{style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:A.textPrimary,fontFamily:"'Inter', -apple-system, BlinkMacSystemFont, sans-serif",lineHeight:1.5,minHeight:"80vh"},children:[P&&r.jsxs("div",{style:{position:"fixed",top:"20px",right:"20px",padding:"12px 24px",borderRadius:"12px",boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",backdropFilter:"blur(8px)",border:"1px solid",zIndex:1e3,display:"flex",alignItems:"center",gap:"8px",fontSize:"12px",fontWeight:500,maxWidth:"400px",animation:"slideIn 0.3s ease-out",...P.type==="success"?{backgroundColor:t?"rgba(16, 185, 129, 0.1)":"rgba(16, 185, 129, 0.05)",borderColor:t?"rgba(16, 185, 129, 0.3)":"rgba(16, 185, 129, 0.2)",color:t?"#34d399":"#059669"}:{backgroundColor:t?"rgba(239, 68, 68, 0.1)":"rgba(239, 68, 68, 0.05)",borderColor:t?"rgba(239, 68, 68, 0.3)":"rgba(239, 68, 68, 0.2)",color:t?"#f87171":"#dc2626"}},role:"alert","aria-live":"polite",children:[P.type==="success"?r.jsx(de,{size:20,"aria-hidden":"true"}):r.jsx(ie,{size:20,"aria-hidden":"true"}),P.message]}),r.jsx("div",{style:{maxWidth:"1200px",margin:"0 auto",width:"100%",boxSizing:"border-box"},children:r.jsxs("div",{style:{display:"grid",gap:"24px",gridTemplateColumns:"1fr",...a&&window.innerWidth>=1024&&{gridTemplateColumns:"1fr 2fr",gap:"10px"},...a&&window.innerWidth>=768&&a&&window.innerWidth<1024&&{gap:"10px"},...a&&window.innerWidth>=600&&a&&window.innerWidth<768&&{gap:"28px"}},children:[r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"6px",height:"100%"},children:[r.jsxs("section",{style:{backgroundColor:A.surface,borderRadius:"16px",position:"relative",padding:"24px",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)",textAlign:"center",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",flex:1,minHeight:"300px"},children:[e&&r.jsx("a",{href:e||"/",target:"_self",rel:"noopener noreferrer",style:{position:"absolute",top:"18px",left:"18px"},children:r.jsx(Ln,{size:20,style:{color:t?"#ffffff":"#000000"}})}),r.jsxs("div",{style:{position:"relative",display:"inline-block",marginBottom:"16px"},children:[r.jsx("img",{src:d.avatarUrl||`https://api.dicebear.com/9.x/initials/svg?seed=${encodeURIComponent(d.name)}`,alt:`Profile avatar of ${d.name}`,style:{width:"128px",height:"128px",borderRadius:"50%",objectFit:"cover",boxShadow:"0 10px 25px -5px rgba(0, 0, 0, 0.3)",border:`3px solid ${A.border}`},width:128,height:128,loading:"eager"}),r.jsx("button",{onClick:()=>I(!0),style:{position:"absolute",bottom:"8px",right:"8px",backgroundColor:A.accent,color:"white",padding:"8px",borderRadius:"50%",border:"none",cursor:"pointer",transition:"all 0.2s ease",display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px"},"aria-label":"Change profile picture",children:r.jsx(et,{size:16,"aria-hidden":"true"})})]}),r.jsx("h2",{style:{fontSize:"24px",fontWeight:600,margin:"0 0 4px 0",color:A.textPrimary},children:d.name}),r.jsx("p",{style:{color:A.textTertiary,margin:"0 0 8px 0"},children:d.email}),r.jsxs("div",{style:{backgroundColor:d.isVerified?t?"rgba(16, 185, 129, 0.1)":"rgba(16, 185, 129, 0.05)":t?"rgba(245, 158, 11, 0.1)":"rgba(245, 158, 11, 0.05)",color:d.isVerified?A.success:A.warning,border:`1px solid ${d.isVerified?t?"rgba(16, 185, 129, 0.3)":"rgba(16, 185, 129, 0.2)":t?"rgba(245, 158, 11, 0.3)":"rgba(245, 158, 11, 0.2)"}`,padding:"6px 12px",borderRadius:"20px",fontSize:"12px",fontWeight:500,display:"inline-flex",alignItems:"center",gap:"6px",marginTop:"8px"},children:[d.isVerified?r.jsx(de,{size:16,"aria-hidden":"true"}):r.jsx(ie,{size:16,"aria-hidden":"true"}),d.isVerified?"Email Verified":"Not Verified"]})]}),r.jsx("nav",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:k?r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>T(!1),style:{backgroundColor:A.surfaceLight,border:`1px solid ${A.border}`,color:A.textPrimary,padding:"10px 20px",borderRadius:"6px",borderStyle:"solid",cursor:"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",flex:a&&window.innerWidth<1024?"1":"auto"},children:[r.jsx(Ie,{size:16,"aria-hidden":"true"}),"Cancel"]}),r.jsxs("button",{onClick:B,disabled:p,style:{background:`linear-gradient(to right, ${A.accent}, ${A.accentHover})`,opacity:p?.7:1,color:"white",padding:"10px 20px",borderRadius:"6px",border:"none",cursor:p?"not-allowed":"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",flex:a&&window.innerWidth<1024?"1":"auto"},children:[p?r.jsx(oe,{size:16,style:{animation:"spin 1s linear infinite"},"aria-hidden":"true"}):r.jsx(Vn,{size:16,"aria-hidden":"true"}),p?"Saving...":"Save Changes"]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>T(!0),style:{background:`linear-gradient(to right, ${A.accent}, ${A.accentHover})`,color:"white",padding:"10px 20px",borderRadius:"6px",border:"none",cursor:"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",flex:a&&window.innerWidth<1024?"1":"auto"},children:[r.jsx(Bn,{size:16,"aria-hidden":"true"}),"Edit Profile"]}),!d.isVerified&&r.jsxs("button",{onClick:()=>j(!0),disabled:O,style:{background:"linear-gradient(to right, #fbbf24, #f59e0b)",color:"white",padding:"10px 20px",borderRadius:"6px",border:"none",cursor:O?"not-allowed":"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",minHeight:"36px",opacity:O?.7:1,flex:a&&window.innerWidth<1024?"1":"auto"},children:[O?r.jsx(oe,{size:14,style:{animation:"spin 1s linear infinite"},"aria-hidden":"true"}):r.jsx(ot,{size:14,"aria-hidden":"true"}),O?"Sending...":"Verify Email"]}),r.jsxs("div",{style:{position:"relative"},children:[r.jsxs("button",{style:{backgroundColor:A.surfaceLight,color:A.textPrimary,padding:"10px 20px",borderRadius:"6px",border:"none",cursor:"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",width:"100%",boxSizing:"border-box"},onClick:()=>_(!q),children:[r.jsx(Fn,{size:16,"aria-hidden":"true"}),"More Actions"]}),q&&r.jsxs("div",{className:`dropdown-container ${X?"closing":""}`,style:{position:"absolute",bottom:"100%",left:0,right:0,backgroundColor:A.surface,border:`1px solid ${A.border}`,borderRadius:"12px 12px 0 0",boxShadow:"0 -8px 24px rgba(0, 0, 0, 0.25)",zIndex:200,marginBottom:"6px",overflow:"hidden",animation:`${X?"drawerSlideDown":"drawerSlideUp"} 0.25s ease-out forwards`},children:[r.jsxs("button",{onClick:()=>{g(!0),E()},style:{width:"100%",padding:"14px 18px",backgroundColor:"transparent",border:"none",color:A.textPrimary,cursor:"pointer",transition:"all 0.2s ease",fontSize:"13px",fontWeight:500,display:"flex",alignItems:"center",gap:"8px",textAlign:"left"},onMouseEnter:v=>v.currentTarget.style.backgroundColor=A.surfaceLight,onMouseLeave:v=>v.currentTarget.style.backgroundColor="transparent",children:[r.jsx(st,{size:14,"aria-hidden":"true"}),"Change Password"]}),n&&r.jsxs("button",{onClick:()=>{n(),E()},style:{width:"100%",padding:"14px 18px",backgroundColor:"transparent",border:"none",color:t?"#fca5a5":"#dc2626",cursor:"pointer",transition:"all 0.2s ease",fontSize:"13px",fontWeight:500,display:"flex",alignItems:"center",gap:"8px",textAlign:"left"},onMouseEnter:v=>{v.currentTarget.style.backgroundColor=t?"rgba(239, 68, 68, 0.1)":"rgba(239, 68, 68, 0.05)"},onMouseLeave:v=>v.currentTarget.style.backgroundColor="transparent",children:[r.jsx(it,{size:14,"aria-hidden":"true"}),"Logout"]}),r.jsxs("button",{onClick:()=>{D(!0),E()},style:{width:"100%",padding:"14px 18px",backgroundColor:"transparent",border:"none",color:"#ef4444",cursor:"pointer",transition:"all 0.2s ease",fontSize:"13px",fontWeight:600,display:"flex",alignItems:"center",gap:"8px",textAlign:"left"},onMouseEnter:v=>{v.currentTarget.style.backgroundColor=t?"rgba(239, 68, 68, 0.1)":"rgba(239, 68, 68, 0.05)"},onMouseLeave:v=>v.currentTarget.style.backgroundColor="transparent",children:[r.jsx(Me,{size:14,"aria-hidden":"true"}),"Delete Account"]})]})]})]})})]}),r.jsxs("div",{style:{minWidth:0,display:"flex",flexDirection:"column",gap:"12px"},children:[r.jsxs("section",{style:{backgroundColor:A.surface,borderRadius:"16px",padding:"24px",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},children:[r.jsxs("h2",{style:{fontSize:"20px",fontWeight:600,margin:"0 0 24px 0",color:A.textSecondary,display:"flex",alignItems:"center",gap:"8px"},children:[r.jsx(Se,{size:20,"aria-hidden":"true"}),"Personal Information"]}),r.jsx("div",{style:{display:"grid",gap:"20px",gridTemplateColumns:"1fr",...a&&window.innerWidth>=600&&{gridTemplateColumns:"1fr 1fr",gap:"20px"}},children:as.map(v=>{const $=v.icon;return r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[r.jsxs("label",{style:{color:A.textTertiary,fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",gap:"8px"},children:[r.jsx($,{size:16,"aria-hidden":"true"}),v.label]}),k?r.jsx("input",{type:v.type,name:v.name,value:d[v.name],onChange:V=>u(Q=>Q&&{...Q,[V.target.name]:V.target.value}),style:{padding:"12px",borderRadius:"8px",border:`1px solid ${i}`,backgroundColor:"transparent",color:A.textPrimary,fontSize:"12px",outline:"none",transition:"border-color 0.2s ease",minHeight:"44px",width:"100%",boxSizing:"border-box"},placeholder:`Enter ${v.label.toLowerCase()}`,"aria-label":v.label}):r.jsx("div",{style:{padding:"12px",borderRadius:"8px",border:"1px solid transparent",fontSize:"12px",minHeight:"44px",display:"flex",alignItems:"center",boxSizing:"border-box",color:A.textPrimary,backgroundColor:t?"rgba(255,255,255,0.05)":"rgba(0,0,0,0.05)"},children:v.value})]},v.name)})})]}),r.jsxs("section",{style:{backgroundColor:A.surface,borderRadius:"16px",padding:"30px 24px",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},children:[r.jsxs("h2",{style:{fontSize:"20px",fontWeight:600,margin:"0 0 24px 0",color:A.textSecondary,display:"flex",alignItems:"center",gap:"8px"},children:[r.jsx(er,{size:20,"aria-hidden":"true"}),"Security Status"]}),r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 0"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",color:A.textSecondary},children:[r.jsx(pe,{size:16,"aria-hidden":"true"}),r.jsx("span",{children:"Email Verification"})]}),r.jsx("div",{style:{padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",gap:"6px",...d.isVerified?{backgroundColor:t?"rgba(16, 185, 129, 0.1)":"rgba(16, 185, 129, 0.05)",color:A.success,border:`1px solid ${t?"rgba(16, 185, 129, 0.3)":"rgba(16, 185, 129, 0.2)"}`}:{backgroundColor:t?"rgba(245, 158, 11, 0.1)":"rgba(245, 158, 11, 0.05)",color:A.warning,border:`1px solid ${t?"rgba(245, 158, 11, 0.3)":"rgba(245, 158, 11, 0.2)"}`}},children:d.isVerified?r.jsxs(r.Fragment,{children:[r.jsx(de,{size:16,"aria-hidden":"true"}),"Verified"]}):r.jsxs(r.Fragment,{children:[r.jsx(ie,{size:16,"aria-hidden":"true"}),"Not Verified"]})})]}),!d.isVerified&&r.jsx("div",{style:{padding:"12px",borderRadius:"8px",backgroundColor:t?"rgba(100, 100, 100, 0.1)":"rgba(0, 0, 0, 0.05)"},children:r.jsx("p",{style:{color:A.textTertiary,fontSize:"12px",margin:0},children:"Verify your email to unlock all features and enhance your account security."})})]})]})]})]})}),r.jsx(ts,{isOpen:h,onClose:()=>{I(!1)},onUpdate:le,colors:A}),r.jsx(rs,{userId:d.id,isOpen:C,onClose:()=>g(!1),onSuccess:v=>m("success",v),onError:v=>m("error",v),colors:A}),r.jsx(es,{userId:d.id,isOpen:z,onClose:()=>D(!1),onSuccess:v=>m("success",v),onError:v=>m("error",v),colors:A}),r.jsx(ns,{isOpen:b,onClose:()=>{j(!1),F(!1),K({email:d?.email||"",otp:""})},onVerify:ne,onSendOTP:U,verifyFormData:M,setVerifyFormData:K,otpSent:H,verifying:J,user:d,colors:A,darkMode:t}),r.jsx("style",{children:`
|
|
499
|
+
`})]})},ss=({darkMode:t=!0,homeUrl:e,onLogout:n,onVerify:s,primaryColor:i="#00C212"})=>{const o=me(),[a,c]=S.useState(null),[d,u]=S.useState(),[x,y]=S.useState(!0),[k,T]=S.useState(!1),[p,w]=S.useState(!1),[h,I]=S.useState(!1),[C,g]=S.useState(!1),[z,D]=S.useState(!1),[b,j]=S.useState(!1),[q,_]=S.useState(!1),[X,W]=S.useState(!1),[P,G]=S.useState(null),[O,R]=S.useState(!1),[M,K]=S.useState({email:"",otp:""}),[H,F]=S.useState(!1),[J,l]=S.useState(!1);S.useEffect(()=>{if(typeof window<"u"){const v=()=>c(window.innerWidth);return v(),window.addEventListener("resize",v),()=>window.removeEventListener("resize",v)}},[]);const m=(v,$)=>{G({type:v,message:$}),setTimeout(()=>G(null),3e3)},E=()=>{W(!0);const v=setTimeout(()=>{_(!1),W(!1)},150);return()=>clearTimeout(v)};S.useEffect(()=>{const v=$=>{const V=document.querySelector(".dropdown-container");V&&!V.contains($.target)&&E()};return q&&document.addEventListener("mousedown",v),()=>{document.removeEventListener("mousedown",v)}},[q]);const U=async()=>{if(!M.email||!/\S+@\S+\.\S+/.test(M.email)){m("error","Please enter a valid email");return}if(!d?.id){m("error","User not found. Cannot send OTP.");return}try{l(!0);const v=await o.requestEmailVerificationOTP({userId:d.id,email:M.email}),$=v?.data?.success??v?.success,V=v?.data?.message??v?.message;$?(m("success",V||"OTP sent to email!"),F(!0)):m("error",V||"Failed to send OTP")}catch(v){const $=v?.response?.data?.message||v?.message||"Server error";m("error",$)}finally{l(!1)}},ne=async v=>{if(v.preventDefault(),!M.email||!M.otp){m("error","Please fill in all fields");return}if(!d){m("error","User not found");return}try{l(!0);const $=await o.verifyEmail({email:M.email,otp:M.otp}),V=$?.data?.success??$?.success,Q=$?.data?.message??$?.message;if(V){m("success",Q||"Email verified!");const ue={...d,isVerified:!0};u(ue),typeof s=="function"&&s(ue),K({email:ue.email,otp:""}),F(!1),j?.(!1)}else m("error",Q||"Verification failed")}catch($){const V=$?.response?.data?.message||$?.message||"Something went wrong";m("error",V)}finally{l(!1)}},le=async v=>{if(!d)return!1;try{const $=await o.updateUser({userId:d.id,avatarUrl:v});if($?.success){const V={...d,...$.user,avatarUrl:v};return u(V),m("success","Avatar updated successfully!"),!0}return m("error",$?.message||"Failed to update avatar"),!1}catch($){return console.error("Avatar update error:",$),m("error","Failed to update avatar"),!1}},B=async()=>{if(d){w(!0);try{const v=d.email,$=await o.updateUser({userId:d.id,...d});if($.success&&$.user){const V=$.user.email!==v,Q={...d,...$.user,isVerified:V?!1:d.isVerified};u(Q),localStorage.setItem("userInfo",JSON.stringify(Q)),m("success",V?"Email updated. Please verify your new email.":"Profile updated successfully"),T(!1)}else m("error",$.message||"Update failed")}catch(v){console.error(v),m("error","Update failed")}finally{w(!1)}}},ce=async v=>{try{const $=await o.checkIfUserExists(v);$?.success===!0&&$?.exists===!1&&(console.warn("❌ User does not exist on server. Clearing session..."),localStorage.removeItem("userInfo"),u(null))}catch($){console.error("⚠️ User validation request failed:",$)}};S.useEffect(()=>{(async()=>{try{y(!0);const $=await o.checkUserSession();if($.user?.id){const V=$.user.id,Q=await o.getUserProfile({userId:V});if(Q.user){const ue=Q.user;u(ue),ce(V)}else u(null),localStorage.removeItem("userInfo")}else u(null),localStorage.removeItem("userInfo")}catch($){console.error("User init failed:",$),u(null),localStorage.removeItem("userInfo")}finally{y(!1)}})()},[]),S.useEffect(()=>{d?.email&&K(v=>({...v,email:d.email}))},[d?.email]);const je=(v,$)=>{let V=parseInt(v.replace("#",""),16),Q=(V>>16)+$,ue=(V>>8&255)+$,at=(V&255)+$;return Q=Math.min(255,Math.max(0,Q)),ue=Math.min(255,Math.max(0,ue)),at=Math.min(255,Math.max(0,at)),`#${(at|ue<<8|Q<<16).toString(16).padStart(6,"0")}`},A=t?{background:"#000000",surface:"#09090b",surfaceLight:"#27272a",surfaceLighter:"#3f3f46",textPrimary:"#ffffff",textSecondary:"#d4d4d8",textTertiary:"#a1a1aa",accent:i,accentHover:je(i,-15),success:"#10b981",error:"#ef4444",border:"#27272a",warning:"#f59e0b"}:{background:"#ffffff",surface:"#fafafa",surfaceLight:"#f4f4f5",surfaceLighter:"#e4e4e7",textPrimary:"#18181b",textSecondary:"#52525b",textTertiary:"#71717a",accent:i,accentHover:je(i,-15),success:"#10b981",error:"#ef4444",border:"#e4e4e7",warning:"#d97706"};if(x)return r.jsx("div",{style:{width:"100%",minHeight:"400px",display:"flex",alignItems:"center",justifyContent:"center",color:A.textPrimary,fontFamily:"'Inter', -apple-system, BlinkMacSystemFont, sans-serif"},children:r.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"16px",textAlign:"center"},children:[r.jsx(oe,{size:40,color:A.accent,style:{animation:"spin 1s linear infinite"},"aria-hidden":"true"}),r.jsx("p",{style:{color:A.textTertiary,margin:0},children:"Loading your profile..."})]})});if(!d)return r.jsx("div",{style:{width:"100%",minHeight:"400px",display:"flex",alignItems:"center",justifyContent:"center",color:A.textPrimary,fontFamily:"'Inter', -apple-system, BlinkMacSystemFont, sans-serif"},children:r.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",textAlign:"center"},children:[r.jsx(ie,{size:40,color:A.error,"aria-hidden":"true"}),r.jsx("p",{style:{color:A.textTertiary,margin:0},children:"No profile found. Please log in again."})]})});const as=[{label:"Full Name",value:d.name,name:"name",type:"text",icon:Se},{label:"Email Address",value:d.email,name:"email",type:"email",icon:pe},{label:"Phone Number",value:d.phone||"Not set",name:"phone",type:"tel",icon:Hn},{label:"Address",value:d.address||"Not provided",name:"address",type:"text",icon:Wn}];return r.jsxs("div",{style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:A.textPrimary,fontFamily:"'Inter', -apple-system, BlinkMacSystemFont, sans-serif",lineHeight:1.5,minHeight:"80vh"},children:[P&&r.jsxs("div",{style:{position:"fixed",top:"20px",right:"20px",padding:"12px 24px",borderRadius:"12px",boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",backdropFilter:"blur(8px)",border:"1px solid",zIndex:1e3,display:"flex",alignItems:"center",gap:"8px",fontSize:"12px",fontWeight:500,maxWidth:"400px",animation:"slideIn 0.3s ease-out",...P.type==="success"?{backgroundColor:t?"rgba(16, 185, 129, 0.1)":"rgba(16, 185, 129, 0.05)",borderColor:t?"rgba(16, 185, 129, 0.3)":"rgba(16, 185, 129, 0.2)",color:t?"#34d399":"#059669"}:{backgroundColor:t?"rgba(239, 68, 68, 0.1)":"rgba(239, 68, 68, 0.05)",borderColor:t?"rgba(239, 68, 68, 0.3)":"rgba(239, 68, 68, 0.2)",color:t?"#f87171":"#dc2626"}},role:"alert","aria-live":"polite",children:[P.type==="success"?r.jsx(de,{size:20,"aria-hidden":"true"}):r.jsx(ie,{size:20,"aria-hidden":"true"}),P.message]}),r.jsx("div",{style:{maxWidth:"1200px",margin:"0 auto",width:"100%",boxSizing:"border-box"},children:r.jsxs("div",{style:{display:"grid",gap:"24px",gridTemplateColumns:"1fr",...a&&window.innerWidth>=1024&&{gridTemplateColumns:"1fr 2fr",gap:"10px"},...a&&window.innerWidth>=768&&a&&window.innerWidth<1024&&{gap:"10px"},...a&&window.innerWidth>=600&&a&&window.innerWidth<768&&{gap:"28px"}},children:[r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"6px",height:"100%"},children:[r.jsxs("section",{style:{backgroundColor:A.surface,borderRadius:"16px",position:"relative",padding:"24px",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)",textAlign:"center",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",flex:1,minHeight:"300px"},children:[e&&r.jsx("a",{href:e||"/",target:"_self",rel:"noopener noreferrer",style:{position:"absolute",top:"18px",left:"18px"},children:r.jsx(Ln,{size:20,style:{color:t?"#ffffff":"#000000"}})}),r.jsxs("div",{style:{position:"relative",display:"inline-block",marginBottom:"16px"},children:[r.jsx("img",{src:d.avatarUrl||`https://api.dicebear.com/9.x/initials/svg?seed=${encodeURIComponent(d.name)}`,alt:`Profile avatar of ${d.name}`,style:{width:"128px",height:"128px",borderRadius:"50%",objectFit:"cover",boxShadow:"0 10px 25px -5px rgba(0, 0, 0, 0.3)",border:`3px solid ${A.border}`},width:128,height:128,loading:"eager"}),r.jsx("button",{onClick:()=>I(!0),style:{position:"absolute",bottom:"8px",right:"8px",backgroundColor:A.accent,color:"white",padding:"8px",borderRadius:"50%",border:"none",cursor:"pointer",transition:"all 0.2s ease",display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px"},"aria-label":"Change profile picture",children:r.jsx(et,{size:16,"aria-hidden":"true"})})]}),r.jsx("h2",{style:{fontSize:"24px",fontWeight:600,margin:"0 0 4px 0",color:A.textPrimary},children:d.name}),r.jsx("p",{style:{color:A.textTertiary,margin:"0 0 8px 0"},children:d.email}),r.jsxs("div",{style:{backgroundColor:d.isVerified?t?"rgba(16, 185, 129, 0.1)":"rgba(16, 185, 129, 0.05)":t?"rgba(245, 158, 11, 0.1)":"rgba(245, 158, 11, 0.05)",color:d.isVerified?A.success:A.warning,border:`1px solid ${d.isVerified?t?"rgba(16, 185, 129, 0.3)":"rgba(16, 185, 129, 0.2)":t?"rgba(245, 158, 11, 0.3)":"rgba(245, 158, 11, 0.2)"}`,padding:"6px 12px",borderRadius:"20px",fontSize:"12px",fontWeight:500,display:"inline-flex",alignItems:"center",gap:"6px",marginTop:"8px"},children:[d.isVerified?r.jsx(de,{size:16,"aria-hidden":"true"}):r.jsx(ie,{size:16,"aria-hidden":"true"}),d.isVerified?"Email Verified":"Not Verified"]})]}),r.jsx("nav",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:k?r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>T(!1),style:{backgroundColor:A.surfaceLight,border:`1px solid ${A.border}`,color:A.textPrimary,padding:"10px 20px",borderRadius:"6px",borderStyle:"solid",cursor:"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",flex:a&&window.innerWidth<1024?"1":"auto"},children:[r.jsx(Ie,{size:16,"aria-hidden":"true"}),"Cancel"]}),r.jsxs("button",{onClick:B,disabled:p,style:{background:`linear-gradient(to right, ${A.accent}, ${A.accentHover})`,opacity:p?.7:1,color:"white",padding:"10px 20px",borderRadius:"6px",border:"none",cursor:p?"not-allowed":"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",flex:a&&window.innerWidth<1024?"1":"auto"},children:[p?r.jsx(oe,{size:16,style:{animation:"spin 1s linear infinite"},"aria-hidden":"true"}):r.jsx(Vn,{size:16,"aria-hidden":"true"}),p?"Saving...":"Save Changes"]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>T(!0),style:{background:`linear-gradient(to right, ${A.accent}, ${A.accentHover})`,color:"white",padding:"10px 20px",borderRadius:"6px",border:"none",cursor:"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",flex:a&&window.innerWidth<1024?"1":"auto"},children:[r.jsx(Bn,{size:16,"aria-hidden":"true"}),"Edit Profile"]}),!d.isVerified&&r.jsxs("button",{onClick:()=>j(!0),disabled:O,style:{background:"linear-gradient(to right, #fbbf24, #f59e0b)",color:"white",padding:"10px 20px",borderRadius:"6px",border:"none",cursor:O?"not-allowed":"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",minHeight:"36px",opacity:O?.7:1,flex:a&&window.innerWidth<1024?"1":"auto"},children:[O?r.jsx(oe,{size:14,style:{animation:"spin 1s linear infinite"},"aria-hidden":"true"}):r.jsx(ot,{size:14,"aria-hidden":"true"}),O?"Sending...":"Verify Email"]}),r.jsxs("div",{style:{position:"relative"},children:[r.jsxs("button",{style:{backgroundColor:A.surfaceLight,color:A.textPrimary,padding:"10px 20px",borderRadius:"6px",border:"none",cursor:"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",width:"100%",boxSizing:"border-box"},onClick:()=>_(!q),children:[r.jsx(Fn,{size:16,"aria-hidden":"true"}),"More Actions"]}),q&&r.jsxs("div",{className:`dropdown-container ${X?"closing":""}`,style:{position:"absolute",bottom:"100%",left:0,right:0,backgroundColor:A.surface,border:`1px solid ${A.border}`,borderRadius:"12px 12px 0 0",boxShadow:"0 -8px 24px rgba(0, 0, 0, 0.25)",zIndex:200,marginBottom:"6px",overflow:"hidden",animation:`${X?"drawerSlideDown":"drawerSlideUp"} 0.25s ease-out forwards`},children:[r.jsxs("button",{onClick:()=>{g(!0),E()},style:{width:"100%",padding:"14px 18px",backgroundColor:"transparent",border:"none",color:A.textPrimary,cursor:"pointer",transition:"all 0.2s ease",fontSize:"13px",fontWeight:500,display:"flex",alignItems:"center",gap:"8px",textAlign:"left"},onMouseEnter:v=>v.currentTarget.style.backgroundColor=A.surfaceLight,onMouseLeave:v=>v.currentTarget.style.backgroundColor="transparent",children:[r.jsx(st,{size:14,"aria-hidden":"true"}),"Change Password"]}),n&&r.jsxs("button",{onClick:()=>{n(),E()},style:{width:"100%",padding:"14px 18px",backgroundColor:"transparent",border:"none",color:t?"#fca5a5":"#dc2626",cursor:"pointer",transition:"all 0.2s ease",fontSize:"13px",fontWeight:500,display:"flex",alignItems:"center",gap:"8px",textAlign:"left"},onMouseEnter:v=>{v.currentTarget.style.backgroundColor=t?"rgba(239, 68, 68, 0.1)":"rgba(239, 68, 68, 0.05)"},onMouseLeave:v=>v.currentTarget.style.backgroundColor="transparent",children:[r.jsx(it,{size:14,"aria-hidden":"true"}),"Logout"]}),r.jsxs("button",{onClick:()=>{D(!0),E()},style:{width:"100%",padding:"14px 18px",backgroundColor:"transparent",border:"none",color:"#ef4444",cursor:"pointer",transition:"all 0.2s ease",fontSize:"13px",fontWeight:600,display:"flex",alignItems:"center",gap:"8px",textAlign:"left"},onMouseEnter:v=>{v.currentTarget.style.backgroundColor=t?"rgba(239, 68, 68, 0.1)":"rgba(239, 68, 68, 0.05)"},onMouseLeave:v=>v.currentTarget.style.backgroundColor="transparent",children:[r.jsx(Me,{size:14,"aria-hidden":"true"}),"Delete Account"]})]})]})]})})]}),r.jsxs("div",{style:{minWidth:0,display:"flex",flexDirection:"column",gap:"12px"},children:[r.jsxs("section",{style:{backgroundColor:A.surface,borderRadius:"16px",padding:"24px",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},children:[r.jsxs("h2",{style:{fontSize:"20px",fontWeight:600,margin:"0 0 24px 0",color:A.textSecondary,display:"flex",alignItems:"center",gap:"8px"},children:[r.jsx(Se,{size:20,"aria-hidden":"true"}),"Personal Information"]}),r.jsx("div",{style:{display:"grid",gap:"20px",gridTemplateColumns:"1fr",...a&&window.innerWidth>=600&&{gridTemplateColumns:"1fr 1fr",gap:"20px"}},children:as.map(v=>{const $=v.icon;return r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[r.jsxs("label",{style:{color:A.textTertiary,fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",gap:"8px"},children:[r.jsx($,{size:16,"aria-hidden":"true"}),v.label]}),k?r.jsx("input",{type:v.type,name:v.name,value:d[v.name],onChange:V=>u(Q=>Q&&{...Q,[V.target.name]:V.target.value}),style:{padding:"12px",borderRadius:"8px",border:`1px solid ${i}`,backgroundColor:"transparent",color:A.textPrimary,fontSize:"12px",outline:"none",transition:"border-color 0.2s ease",minHeight:"44px",width:"100%",boxSizing:"border-box"},placeholder:`Enter ${v.label.toLowerCase()}`,"aria-label":v.label}):r.jsx("div",{style:{padding:"12px",borderRadius:"8px",border:"1px solid transparent",fontSize:"12px",minHeight:"44px",display:"flex",alignItems:"center",boxSizing:"border-box",color:A.textPrimary,backgroundColor:t?"rgba(255,255,255,0.05)":"rgba(0,0,0,0.05)"},children:v.value})]},v.name)})})]}),r.jsxs("section",{style:{backgroundColor:A.surface,borderRadius:"16px",padding:"30px 24px",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},children:[r.jsxs("h2",{style:{fontSize:"20px",fontWeight:600,margin:"0 0 24px 0",color:A.textSecondary,display:"flex",alignItems:"center",gap:"8px"},children:[r.jsx(er,{size:20,"aria-hidden":"true"}),"Security Status"]}),r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 0"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",color:A.textSecondary},children:[r.jsx(pe,{size:16,"aria-hidden":"true"}),r.jsx("span",{children:"Email Verification"})]}),r.jsx("div",{style:{padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",gap:"6px",...d.isVerified?{backgroundColor:t?"rgba(16, 185, 129, 0.1)":"rgba(16, 185, 129, 0.05)",color:A.success,border:`1px solid ${t?"rgba(16, 185, 129, 0.3)":"rgba(16, 185, 129, 0.2)"}`}:{backgroundColor:t?"rgba(245, 158, 11, 0.1)":"rgba(245, 158, 11, 0.05)",color:A.warning,border:`1px solid ${t?"rgba(245, 158, 11, 0.3)":"rgba(245, 158, 11, 0.2)"}`}},children:d.isVerified?r.jsxs(r.Fragment,{children:[r.jsx(de,{size:16,"aria-hidden":"true"}),"Verified"]}):r.jsxs(r.Fragment,{children:[r.jsx(ie,{size:16,"aria-hidden":"true"}),"Not Verified"]})})]}),!d.isVerified&&r.jsx("div",{style:{padding:"12px",borderRadius:"8px",backgroundColor:t?"rgba(100, 100, 100, 0.1)":"rgba(0, 0, 0, 0.05)"},children:r.jsx("p",{style:{color:A.textTertiary,fontSize:"12px",margin:0},children:"Verify your email to unlock all features and enhance your account security."})})]})]})]})]})}),r.jsx(ts,{isOpen:h,onClose:()=>{I(!1)},onUpdate:le,colors:A}),r.jsx(rs,{userId:d.id,isOpen:C,onClose:()=>g(!1),onSuccess:v=>m("success",v),onError:v=>m("error",v),colors:A}),r.jsx(es,{userId:d.id,isOpen:z,onClose:()=>D(!1),onSuccess:v=>m("success",v),onError:v=>m("error",v),colors:A}),r.jsx(ns,{isOpen:b,onClose:()=>{j(!1),F(!1),K({email:d?.email||"",otp:""})},onVerify:ne,onSendOTP:U,verifyFormData:M,setVerifyFormData:K,otpSent:H,verifying:J,user:d,colors:A,darkMode:t}),r.jsx("style",{children:`
|
|
500
500
|
@keyframes slideIn {
|
|
501
501
|
from {
|
|
502
502
|
transform: translateX(100%);
|