joytalk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +640 -0
- package/dist/apis/index.d.ts +24 -0
- package/dist/apis/request.d.ts +2 -0
- package/dist/index.cjs.js +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.es.js +2297 -0
- package/dist/index.umd.js +6 -0
- package/dist/lib/index.d.ts +121 -0
- package/dist/lib/modules/api-client.d.ts +12 -0
- package/dist/lib/modules/connection-manager.d.ts +74 -0
- package/dist/lib/modules/faq-manager.d.ts +23 -0
- package/dist/lib/modules/file-uploader.d.ts +29 -0
- package/dist/lib/modules/message-handler.d.ts +62 -0
- package/dist/lib/modules/user-manager.d.ts +25 -0
- package/dist/main.d.ts +1 -0
- package/dist/types/index.d.ts +77 -0
- package/dist/types/message.d.ts +316 -0
- package/dist/types/request.d.ts +91 -0
- package/dist/utils/event-emitter.d.ts +30 -0
- package/dist/utils/http-handler.d.ts +2 -0
- package/package.json +28 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
(function(A,J){typeof exports=="object"&&typeof module<"u"?J(exports):typeof define=="function"&&define.amd?define(["exports"],J):(A=typeof globalThis<"u"?globalThis:A||self,J(A.JoyTalk={}))})(this,(function(A){"use strict";function J(e,t){return function(){return e.apply(t,arguments)}}const{toString:Rt}=Object.prototype,{getPrototypeOf:Se}=Object,{iterator:re,toStringTag:Fe}=Symbol,se=(e=>t=>{const n=Rt.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),F=e=>(e=e.toLowerCase(),t=>se(t)===e),oe=e=>t=>typeof t===e,{isArray:z}=Array,W=oe("undefined");function Q(e){return e!==null&&!W(e)&&e.constructor!==null&&!W(e.constructor)&&g(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Le=F("ArrayBuffer");function Ot(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Le(e.buffer),t}const At=oe("string"),g=oe("function"),xe=oe("number"),Y=e=>e!==null&&typeof e=="object",gt=e=>e===!0||e===!1,ie=e=>{if(se(e)!=="object")return!1;const t=Se(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Fe in e)&&!(re in e)},Nt=e=>{if(!Y(e)||Q(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Ct=F("Date"),Ut=F("File"),_t=F("Blob"),Dt=F("FileList"),Ft=e=>Y(e)&&g(e.pipe),Lt=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||g(e.append)&&((t=se(e))==="formdata"||t==="object"&&g(e.toString)&&e.toString()==="[object FormData]"))},xt=F("URLSearchParams"),[Pt,It,kt,Bt]=["ReadableStream","Request","Response","Headers"].map(F),jt=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Z(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,s;if(typeof e!="object"&&(e=[e]),z(e))for(r=0,s=e.length;r<s;r++)t.call(null,e[r],r,e);else{if(Q(e))return;const o=n?Object.getOwnPropertyNames(e):Object.keys(e),i=o.length;let c;for(r=0;r<i;r++)c=o[r],t.call(null,e[c],c,e)}}function Pe(e,t){if(Q(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,s;for(;r-- >0;)if(s=n[r],t===s.toLowerCase())return s;return null}const H=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Ie=e=>!W(e)&&e!==H;function Te(){const{caseless:e,skipUndefined:t}=Ie(this)&&this||{},n={},r=(s,o)=>{const i=e&&Pe(n,o)||o;ie(n[i])&&ie(s)?n[i]=Te(n[i],s):ie(s)?n[i]=Te({},s):z(s)?n[i]=s.slice():(!t||!W(s))&&(n[i]=s)};for(let s=0,o=arguments.length;s<o;s++)arguments[s]&&Z(arguments[s],r);return n}const Ht=(e,t,n,{allOwnKeys:r}={})=>(Z(t,(s,o)=>{n&&g(s)?e[o]=J(s,n):e[o]=s},{allOwnKeys:r}),e),vt=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),qt=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},$t=(e,t,n,r)=>{let s,o,i;const c={};if(t=t||{},e==null)return t;do{for(s=Object.getOwnPropertyNames(e),o=s.length;o-- >0;)i=s[o],(!r||r(i,e,t))&&!c[i]&&(t[i]=e[i],c[i]=!0);e=n!==!1&&Se(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Mt=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},Jt=e=>{if(!e)return null;if(z(e))return e;let t=e.length;if(!xe(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},zt=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Se(Uint8Array)),Wt=(e,t)=>{const r=(e&&e[re]).call(e);let s;for(;(s=r.next())&&!s.done;){const o=s.value;t.call(e,o[0],o[1])}},Gt=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},Kt=F("HTMLFormElement"),Vt=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,s){return r.toUpperCase()+s}),ke=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Xt=F("RegExp"),Be=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Z(n,(s,o)=>{let i;(i=t(s,o,e))!==!1&&(r[o]=i||s)}),Object.defineProperties(e,r)},Qt=e=>{Be(e,(t,n)=>{if(g(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(g(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},Yt=(e,t)=>{const n={},r=s=>{s.forEach(o=>{n[o]=!0})};return z(e)?r(e):r(String(e).split(t)),n},Zt=()=>{},en=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function tn(e){return!!(e&&g(e.append)&&e[Fe]==="FormData"&&e[re])}const nn=e=>{const t=new Array(10),n=(r,s)=>{if(Y(r)){if(t.indexOf(r)>=0)return;if(Q(r))return r;if(!("toJSON"in r)){t[s]=r;const o=z(r)?[]:{};return Z(r,(i,c)=>{const d=n(i,s+1);!W(d)&&(o[c]=d)}),t[s]=void 0,o}}return r};return n(e,0)},rn=F("AsyncFunction"),sn=e=>e&&(Y(e)||g(e))&&g(e.then)&&g(e.catch),je=((e,t)=>e?setImmediate:t?((n,r)=>(H.addEventListener("message",({source:s,data:o})=>{s===H&&o===n&&r.length&&r.shift()()},!1),s=>{r.push(s),H.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",g(H.postMessage)),on=typeof queueMicrotask<"u"?queueMicrotask.bind(H):typeof process<"u"&&process.nextTick||je,a={isArray:z,isArrayBuffer:Le,isBuffer:Q,isFormData:Lt,isArrayBufferView:Ot,isString:At,isNumber:xe,isBoolean:gt,isObject:Y,isPlainObject:ie,isEmptyObject:Nt,isReadableStream:Pt,isRequest:It,isResponse:kt,isHeaders:Bt,isUndefined:W,isDate:Ct,isFile:Ut,isBlob:_t,isRegExp:Xt,isFunction:g,isStream:Ft,isURLSearchParams:xt,isTypedArray:zt,isFileList:Dt,forEach:Z,merge:Te,extend:Ht,trim:jt,stripBOM:vt,inherits:qt,toFlatObject:$t,kindOf:se,kindOfTest:F,endsWith:Mt,toArray:Jt,forEachEntry:Wt,matchAll:Gt,isHTMLForm:Kt,hasOwnProperty:ke,hasOwnProp:ke,reduceDescriptors:Be,freezeMethods:Qt,toObjectSet:Yt,toCamelCase:Vt,noop:Zt,toFiniteNumber:en,findKey:Pe,global:H,isContextDefined:Ie,isSpecCompliantForm:tn,toJSONObject:nn,isAsyncFn:rn,isThenable:sn,setImmediate:je,asap:on,isIterable:e=>e!=null&&g(e[re])};function E(e,t,n,r,s){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),s&&(this.response=s,this.status=s.status?s.status:null)}a.inherits(E,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:a.toJSONObject(this.config),code:this.code,status:this.status}}});const He=E.prototype,ve={};["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=>{ve[e]={value:e}}),Object.defineProperties(E,ve),Object.defineProperty(He,"isAxiosError",{value:!0}),E.from=(e,t,n,r,s,o)=>{const i=Object.create(He);a.toFlatObject(e,i,function(u){return u!==Error.prototype},l=>l!=="isAxiosError");const c=e&&e.message?e.message:"Error",d=t==null&&e?e.code:t;return E.call(i,c,d,n,r,s),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",o&&Object.assign(i,o),i};const an=null;function ye(e){return a.isPlainObject(e)||a.isArray(e)}function qe(e){return a.endsWith(e,"[]")?e.slice(0,-2):e}function $e(e,t,n){return e?e.concat(t).map(function(s,o){return s=qe(s),!n&&o?"["+s+"]":s}).join(n?".":""):t}function cn(e){return a.isArray(e)&&!e.some(ye)}const un=a.toFlatObject(a,{},null,function(t){return/^is[A-Z]/.test(t)});function ae(e,t,n){if(!a.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=a.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,h){return!a.isUndefined(h[m])});const r=n.metaTokens,s=n.visitor||u,o=n.dots,i=n.indexes,d=(n.Blob||typeof Blob<"u"&&Blob)&&a.isSpecCompliantForm(t);if(!a.isFunction(s))throw new TypeError("visitor must be a function");function l(f){if(f===null)return"";if(a.isDate(f))return f.toISOString();if(a.isBoolean(f))return f.toString();if(!d&&a.isBlob(f))throw new E("Blob is not supported. Use a Buffer instead.");return a.isArrayBuffer(f)||a.isTypedArray(f)?d&&typeof Blob=="function"?new Blob([f]):Buffer.from(f):f}function u(f,m,h){let y=f;if(f&&!h&&typeof f=="object"){if(a.endsWith(m,"{}"))m=r?m:m.slice(0,-2),f=JSON.stringify(f);else if(a.isArray(f)&&cn(f)||(a.isFileList(f)||a.endsWith(m,"[]"))&&(y=a.toArray(f)))return m=qe(m),y.forEach(function(b,C){!(a.isUndefined(b)||b===null)&&t.append(i===!0?$e([m],C,o):i===null?m:m+"[]",l(b))}),!1}return ye(f)?!0:(t.append($e(h,m,o),l(f)),!1)}const p=[],S=Object.assign(un,{defaultVisitor:u,convertValue:l,isVisitable:ye});function R(f,m){if(!a.isUndefined(f)){if(p.indexOf(f)!==-1)throw Error("Circular reference detected in "+m.join("."));p.push(f),a.forEach(f,function(y,_){(!(a.isUndefined(y)||y===null)&&s.call(t,y,a.isString(_)?_.trim():_,m,S))===!0&&R(y,m?m.concat(_):[_])}),p.pop()}}if(!a.isObject(e))throw new TypeError("data must be an object");return R(e),t}function Me(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function be(e,t){this._pairs=[],e&&ae(e,this,t)}const Je=be.prototype;Je.append=function(t,n){this._pairs.push([t,n])},Je.toString=function(t){const n=t?function(r){return t.call(this,r,Me)}:Me;return this._pairs.map(function(s){return n(s[0])+"="+n(s[1])},"").join("&")};function ln(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function ze(e,t,n){if(!t)return e;const r=n&&n.encode||ln;a.isFunction(n)&&(n={serialize:n});const s=n&&n.serialize;let o;if(s?o=s(t,n):o=a.isURLSearchParams(t)?t.toString():new be(t,n).toString(r),o){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+o}return e}class We{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){a.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Ge={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},fn={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:be,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},we=typeof window<"u"&&typeof document<"u",Re=typeof navigator=="object"&&navigator||void 0,dn=we&&(!Re||["ReactNative","NativeScript","NS"].indexOf(Re.product)<0),hn=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",pn=we&&window.location.href||"http://localhost",w={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:we,hasStandardBrowserEnv:dn,hasStandardBrowserWebWorkerEnv:hn,navigator:Re,origin:pn},Symbol.toStringTag,{value:"Module"})),...fn};function mn(e,t){return ae(e,new w.classes.URLSearchParams,{visitor:function(n,r,s,o){return w.isNode&&a.isBuffer(n)?(this.append(r,n.toString("base64")),!1):o.defaultVisitor.apply(this,arguments)},...t})}function En(e){return a.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Sn(e){const t={},n=Object.keys(e);let r;const s=n.length;let o;for(r=0;r<s;r++)o=n[r],t[o]=e[o];return t}function Ke(e){function t(n,r,s,o){let i=n[o++];if(i==="__proto__")return!0;const c=Number.isFinite(+i),d=o>=n.length;return i=!i&&a.isArray(s)?s.length:i,d?(a.hasOwnProp(s,i)?s[i]=[s[i],r]:s[i]=r,!c):((!s[i]||!a.isObject(s[i]))&&(s[i]=[]),t(n,r,s[i],o)&&a.isArray(s[i])&&(s[i]=Sn(s[i])),!c)}if(a.isFormData(e)&&a.isFunction(e.entries)){const n={};return a.forEachEntry(e,(r,s)=>{t(En(r),s,n,0)}),n}return null}function Tn(e,t,n){if(a.isString(e))try{return(t||JSON.parse)(e),a.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const ee={transitional:Ge,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",s=r.indexOf("application/json")>-1,o=a.isObject(t);if(o&&a.isHTMLForm(t)&&(t=new FormData(t)),a.isFormData(t))return s?JSON.stringify(Ke(t)):t;if(a.isArrayBuffer(t)||a.isBuffer(t)||a.isStream(t)||a.isFile(t)||a.isBlob(t)||a.isReadableStream(t))return t;if(a.isArrayBufferView(t))return t.buffer;if(a.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let c;if(o){if(r.indexOf("application/x-www-form-urlencoded")>-1)return mn(t,this.formSerializer).toString();if((c=a.isFileList(t))||r.indexOf("multipart/form-data")>-1){const d=this.env&&this.env.FormData;return ae(c?{"files[]":t}:t,d&&new d,this.formSerializer)}}return o||s?(n.setContentType("application/json",!1),Tn(t)):t}],transformResponse:[function(t){const n=this.transitional||ee.transitional,r=n&&n.forcedJSONParsing,s=this.responseType==="json";if(a.isResponse(t)||a.isReadableStream(t))return t;if(t&&a.isString(t)&&(r&&!this.responseType||s)){const i=!(n&&n.silentJSONParsing)&&s;try{return JSON.parse(t,this.parseReviver)}catch(c){if(i)throw c.name==="SyntaxError"?E.from(c,E.ERR_BAD_RESPONSE,this,null,this.response):c}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:w.classes.FormData,Blob:w.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};a.forEach(["delete","get","head","post","put","patch"],e=>{ee.headers[e]={}});const yn=a.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),bn=e=>{const t={};let n,r,s;return e&&e.split(`
|
|
2
|
+
`).forEach(function(i){s=i.indexOf(":"),n=i.substring(0,s).trim().toLowerCase(),r=i.substring(s+1).trim(),!(!n||t[n]&&yn[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},Ve=Symbol("internals");function te(e){return e&&String(e).trim().toLowerCase()}function ce(e){return e===!1||e==null?e:a.isArray(e)?e.map(ce):String(e)}function wn(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}const Rn=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function Oe(e,t,n,r,s){if(a.isFunction(r))return r.call(this,t,n);if(s&&(t=n),!!a.isString(t)){if(a.isString(r))return t.indexOf(r)!==-1;if(a.isRegExp(r))return r.test(t)}}function On(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function An(e,t){const n=a.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(s,o,i){return this[r].call(this,t,s,o,i)},configurable:!0})})}let N=class{constructor(t){t&&this.set(t)}set(t,n,r){const s=this;function o(c,d,l){const u=te(d);if(!u)throw new Error("header name must be a non-empty string");const p=a.findKey(s,u);(!p||s[p]===void 0||l===!0||l===void 0&&s[p]!==!1)&&(s[p||d]=ce(c))}const i=(c,d)=>a.forEach(c,(l,u)=>o(l,u,d));if(a.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(a.isString(t)&&(t=t.trim())&&!Rn(t))i(bn(t),n);else if(a.isObject(t)&&a.isIterable(t)){let c={},d,l;for(const u of t){if(!a.isArray(u))throw TypeError("Object iterator must return a key-value pair");c[l=u[0]]=(d=c[l])?a.isArray(d)?[...d,u[1]]:[d,u[1]]:u[1]}i(c,n)}else t!=null&&o(n,t,r);return this}get(t,n){if(t=te(t),t){const r=a.findKey(this,t);if(r){const s=this[r];if(!n)return s;if(n===!0)return wn(s);if(a.isFunction(n))return n.call(this,s,r);if(a.isRegExp(n))return n.exec(s);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=te(t),t){const r=a.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||Oe(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let s=!1;function o(i){if(i=te(i),i){const c=a.findKey(r,i);c&&(!n||Oe(r,r[c],c,n))&&(delete r[c],s=!0)}}return a.isArray(t)?t.forEach(o):o(t),s}clear(t){const n=Object.keys(this);let r=n.length,s=!1;for(;r--;){const o=n[r];(!t||Oe(this,this[o],o,t,!0))&&(delete this[o],s=!0)}return s}normalize(t){const n=this,r={};return a.forEach(this,(s,o)=>{const i=a.findKey(r,o);if(i){n[i]=ce(s),delete n[o];return}const c=t?On(o):String(o).trim();c!==o&&delete n[o],n[c]=ce(s),r[c]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return a.forEach(this,(r,s)=>{r!=null&&r!==!1&&(n[s]=t&&a.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
|
|
3
|
+
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(s=>r.set(s)),r}static accessor(t){const r=(this[Ve]=this[Ve]={accessors:{}}).accessors,s=this.prototype;function o(i){const c=te(i);r[c]||(An(s,i),r[c]=!0)}return a.isArray(t)?t.forEach(o):o(t),this}};N.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),a.reduceDescriptors(N.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),a.freezeMethods(N);function Ae(e,t){const n=this||ee,r=t||n,s=N.from(r.headers);let o=r.data;return a.forEach(e,function(c){o=c.call(n,o,s.normalize(),t?t.status:void 0)}),s.normalize(),o}function Xe(e){return!!(e&&e.__CANCEL__)}function G(e,t,n){E.call(this,e??"canceled",E.ERR_CANCELED,t,n),this.name="CanceledError"}a.inherits(G,E,{__CANCEL__:!0});function Qe(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new E("Request failed with status code "+n.status,[E.ERR_BAD_REQUEST,E.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function gn(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Nn(e,t){e=e||10;const n=new Array(e),r=new Array(e);let s=0,o=0,i;return t=t!==void 0?t:1e3,function(d){const l=Date.now(),u=r[o];i||(i=l),n[s]=d,r[s]=l;let p=o,S=0;for(;p!==s;)S+=n[p++],p=p%e;if(s=(s+1)%e,s===o&&(o=(o+1)%e),l-i<t)return;const R=u&&l-u;return R?Math.round(S*1e3/R):void 0}}function Cn(e,t){let n=0,r=1e3/t,s,o;const i=(l,u=Date.now())=>{n=u,s=null,o&&(clearTimeout(o),o=null),e(...l)};return[(...l)=>{const u=Date.now(),p=u-n;p>=r?i(l,u):(s=l,o||(o=setTimeout(()=>{o=null,i(s)},r-p)))},()=>s&&i(s)]}const ue=(e,t,n=3)=>{let r=0;const s=Nn(50,250);return Cn(o=>{const i=o.loaded,c=o.lengthComputable?o.total:void 0,d=i-r,l=s(d),u=i<=c;r=i;const p={loaded:i,total:c,progress:c?i/c:void 0,bytes:d,rate:l||void 0,estimated:l&&c&&u?(c-i)/l:void 0,event:o,lengthComputable:c!=null,[t?"download":"upload"]:!0};e(p)},n)},Ye=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Ze=e=>(...t)=>a.asap(()=>e(...t)),Un=w.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,w.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(w.origin),w.navigator&&/(msie|trident)/i.test(w.navigator.userAgent)):()=>!0,_n=w.hasStandardBrowserEnv?{write(e,t,n,r,s,o,i){if(typeof document>"u")return;const c=[`${e}=${encodeURIComponent(t)}`];a.isNumber(n)&&c.push(`expires=${new Date(n).toUTCString()}`),a.isString(r)&&c.push(`path=${r}`),a.isString(s)&&c.push(`domain=${s}`),o===!0&&c.push("secure"),a.isString(i)&&c.push(`SameSite=${i}`),document.cookie=c.join("; ")},read(e){if(typeof document>"u")return null;const t=document.cookie.match(new RegExp("(?:^|; )"+e+"=([^;]*)"));return t?decodeURIComponent(t[1]):null},remove(e){this.write(e,"",Date.now()-864e5,"/")}}:{write(){},read(){return null},remove(){}};function Dn(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Fn(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function et(e,t,n){let r=!Dn(t);return e&&(r||n==!1)?Fn(e,t):t}const tt=e=>e instanceof N?{...e}:e;function v(e,t){t=t||{};const n={};function r(l,u,p,S){return a.isPlainObject(l)&&a.isPlainObject(u)?a.merge.call({caseless:S},l,u):a.isPlainObject(u)?a.merge({},u):a.isArray(u)?u.slice():u}function s(l,u,p,S){if(a.isUndefined(u)){if(!a.isUndefined(l))return r(void 0,l,p,S)}else return r(l,u,p,S)}function o(l,u){if(!a.isUndefined(u))return r(void 0,u)}function i(l,u){if(a.isUndefined(u)){if(!a.isUndefined(l))return r(void 0,l)}else return r(void 0,u)}function c(l,u,p){if(p in t)return r(l,u);if(p in e)return r(void 0,l)}const d={url:o,method:o,data:o,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken: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:c,headers:(l,u,p)=>s(tt(l),tt(u),p,!0)};return a.forEach(Object.keys({...e,...t}),function(u){const p=d[u]||s,S=p(e[u],t[u],u);a.isUndefined(S)&&p!==c||(n[u]=S)}),n}const nt=e=>{const t=v({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:s,xsrfCookieName:o,headers:i,auth:c}=t;if(t.headers=i=N.from(i),t.url=ze(et(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),c&&i.set("Authorization","Basic "+btoa((c.username||"")+":"+(c.password?unescape(encodeURIComponent(c.password)):""))),a.isFormData(n)){if(w.hasStandardBrowserEnv||w.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(a.isFunction(n.getHeaders)){const d=n.getHeaders(),l=["content-type","content-length"];Object.entries(d).forEach(([u,p])=>{l.includes(u.toLowerCase())&&i.set(u,p)})}}if(w.hasStandardBrowserEnv&&(r&&a.isFunction(r)&&(r=r(t)),r||r!==!1&&Un(t.url))){const d=s&&o&&_n.read(o);d&&i.set(s,d)}return t},Ln=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const s=nt(e);let o=s.data;const i=N.from(s.headers).normalize();let{responseType:c,onUploadProgress:d,onDownloadProgress:l}=s,u,p,S,R,f;function m(){R&&R(),f&&f(),s.cancelToken&&s.cancelToken.unsubscribe(u),s.signal&&s.signal.removeEventListener("abort",u)}let h=new XMLHttpRequest;h.open(s.method.toUpperCase(),s.url,!0),h.timeout=s.timeout;function y(){if(!h)return;const b=N.from("getAllResponseHeaders"in h&&h.getAllResponseHeaders()),L={data:!c||c==="text"||c==="json"?h.responseText:h.response,status:h.status,statusText:h.statusText,headers:b,config:e,request:h};Qe(function(D){n(D),m()},function(D){r(D),m()},L),h=null}"onloadend"in h?h.onloadend=y:h.onreadystatechange=function(){!h||h.readyState!==4||h.status===0&&!(h.responseURL&&h.responseURL.indexOf("file:")===0)||setTimeout(y)},h.onabort=function(){h&&(r(new E("Request aborted",E.ECONNABORTED,e,h)),h=null)},h.onerror=function(C){const L=C&&C.message?C.message:"Network Error",$=new E(L,E.ERR_NETWORK,e,h);$.event=C||null,r($),h=null},h.ontimeout=function(){let C=s.timeout?"timeout of "+s.timeout+"ms exceeded":"timeout exceeded";const L=s.transitional||Ge;s.timeoutErrorMessage&&(C=s.timeoutErrorMessage),r(new E(C,L.clarifyTimeoutError?E.ETIMEDOUT:E.ECONNABORTED,e,h)),h=null},o===void 0&&i.setContentType(null),"setRequestHeader"in h&&a.forEach(i.toJSON(),function(C,L){h.setRequestHeader(L,C)}),a.isUndefined(s.withCredentials)||(h.withCredentials=!!s.withCredentials),c&&c!=="json"&&(h.responseType=s.responseType),l&&([S,f]=ue(l,!0),h.addEventListener("progress",S)),d&&h.upload&&([p,R]=ue(d),h.upload.addEventListener("progress",p),h.upload.addEventListener("loadend",R)),(s.cancelToken||s.signal)&&(u=b=>{h&&(r(!b||b.type?new G(null,e,h):b),h.abort(),h=null)},s.cancelToken&&s.cancelToken.subscribe(u),s.signal&&(s.signal.aborted?u():s.signal.addEventListener("abort",u)));const _=gn(s.url);if(_&&w.protocols.indexOf(_)===-1){r(new E("Unsupported protocol "+_+":",E.ERR_BAD_REQUEST,e));return}h.send(o||null)})},xn=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,s;const o=function(l){if(!s){s=!0,c();const u=l instanceof Error?l:this.reason;r.abort(u instanceof E?u:new G(u instanceof Error?u.message:u))}};let i=t&&setTimeout(()=>{i=null,o(new E(`timeout ${t} of ms exceeded`,E.ETIMEDOUT))},t);const c=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(l=>{l.unsubscribe?l.unsubscribe(o):l.removeEventListener("abort",o)}),e=null)};e.forEach(l=>l.addEventListener("abort",o));const{signal:d}=r;return d.unsubscribe=()=>a.asap(c),d}},Pn=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,s;for(;r<n;)s=r+t,yield e.slice(r,s),r=s},In=async function*(e,t){for await(const n of kn(e))yield*Pn(n,t)},kn=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},rt=(e,t,n,r)=>{const s=In(e,t);let o=0,i,c=d=>{i||(i=!0,r&&r(d))};return new ReadableStream({async pull(d){try{const{done:l,value:u}=await s.next();if(l){c(),d.close();return}let p=u.byteLength;if(n){let S=o+=p;n(S)}d.enqueue(new Uint8Array(u))}catch(l){throw c(l),l}},cancel(d){return c(d),s.return()}},{highWaterMark:2})},st=64*1024,{isFunction:le}=a,Bn=(({Request:e,Response:t})=>({Request:e,Response:t}))(a.global),{ReadableStream:ot,TextEncoder:it}=a.global,at=(e,...t)=>{try{return!!e(...t)}catch{return!1}},jn=e=>{e=a.merge.call({skipUndefined:!0},Bn,e);const{fetch:t,Request:n,Response:r}=e,s=t?le(t):typeof fetch=="function",o=le(n),i=le(r);if(!s)return!1;const c=s&&le(ot),d=s&&(typeof it=="function"?(f=>m=>f.encode(m))(new it):async f=>new Uint8Array(await new n(f).arrayBuffer())),l=o&&c&&at(()=>{let f=!1;const m=new n(w.origin,{body:new ot,method:"POST",get duplex(){return f=!0,"half"}}).headers.has("Content-Type");return f&&!m}),u=i&&c&&at(()=>a.isReadableStream(new r("").body)),p={stream:u&&(f=>f.body)};s&&["text","arrayBuffer","blob","formData","stream"].forEach(f=>{!p[f]&&(p[f]=(m,h)=>{let y=m&&m[f];if(y)return y.call(m);throw new E(`Response type '${f}' is not supported`,E.ERR_NOT_SUPPORT,h)})});const S=async f=>{if(f==null)return 0;if(a.isBlob(f))return f.size;if(a.isSpecCompliantForm(f))return(await new n(w.origin,{method:"POST",body:f}).arrayBuffer()).byteLength;if(a.isArrayBufferView(f)||a.isArrayBuffer(f))return f.byteLength;if(a.isURLSearchParams(f)&&(f=f+""),a.isString(f))return(await d(f)).byteLength},R=async(f,m)=>{const h=a.toFiniteNumber(f.getContentLength());return h??S(m)};return async f=>{let{url:m,method:h,data:y,signal:_,cancelToken:b,timeout:C,onDownloadProgress:L,onUploadProgress:$,responseType:D,headers:_e,withCredentials:pe="same-origin",fetchOptions:mt}=nt(f),Et=t||fetch;D=D?(D+"").toLowerCase():"text";let me=xn([_,b&&b.toAbortSignal()],C),ne=null;const M=me&&me.unsubscribe&&(()=>{me.unsubscribe()});let St;try{if($&&l&&h!=="get"&&h!=="head"&&(St=await R(_e,y))!==0){let j=new n(m,{method:"POST",body:y,duplex:"half"}),X;if(a.isFormData(y)&&(X=j.headers.get("content-type"))&&_e.setContentType(X),j.body){const[De,Ee]=Ye(St,ue(Ze($)));y=rt(j.body,st,De,Ee)}}a.isString(pe)||(pe=pe?"include":"omit");const I=o&&"credentials"in n.prototype,Tt={...mt,signal:me,method:h.toUpperCase(),headers:_e.normalize().toJSON(),body:y,duplex:"half",credentials:I?pe:void 0};ne=o&&new n(m,Tt);let B=await(o?Et(ne,mt):Et(m,Tt));const yt=u&&(D==="stream"||D==="response");if(u&&(L||yt&&M)){const j={};["status","statusText","headers"].forEach(bt=>{j[bt]=B[bt]});const X=a.toFiniteNumber(B.headers.get("content-length")),[De,Ee]=L&&Ye(X,ue(Ze(L),!0))||[];B=new r(rt(B.body,st,De,()=>{Ee&&Ee(),M&&M()}),j)}D=D||"text";let tr=await p[a.findKey(p,D)||"text"](B,f);return!yt&&M&&M(),await new Promise((j,X)=>{Qe(j,X,{data:tr,headers:N.from(B.headers),status:B.status,statusText:B.statusText,config:f,request:ne})})}catch(I){throw M&&M(),I&&I.name==="TypeError"&&/Load failed|fetch/i.test(I.message)?Object.assign(new E("Network Error",E.ERR_NETWORK,f,ne),{cause:I.cause||I}):E.from(I,I&&I.code,f,ne)}}},Hn=new Map,ct=e=>{let t=e&&e.env||{};const{fetch:n,Request:r,Response:s}=t,o=[r,s,n];let i=o.length,c=i,d,l,u=Hn;for(;c--;)d=o[c],l=u.get(d),l===void 0&&u.set(d,l=c?new Map:jn(t)),u=l;return l};ct();const ge={http:an,xhr:Ln,fetch:{get:ct}};a.forEach(ge,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const ut=e=>`- ${e}`,vn=e=>a.isFunction(e)||e===null||e===!1;function qn(e,t){e=a.isArray(e)?e:[e];const{length:n}=e;let r,s;const o={};for(let i=0;i<n;i++){r=e[i];let c;if(s=r,!vn(r)&&(s=ge[(c=String(r)).toLowerCase()],s===void 0))throw new E(`Unknown adapter '${c}'`);if(s&&(a.isFunction(s)||(s=s.get(t))))break;o[c||"#"+i]=s}if(!s){const i=Object.entries(o).map(([d,l])=>`adapter ${d} `+(l===!1?"is not supported by the environment":"is not available in the build"));let c=n?i.length>1?`since :
|
|
4
|
+
`+i.map(ut).join(`
|
|
5
|
+
`):" "+ut(i[0]):"as no adapter specified";throw new E("There is no suitable adapter to dispatch the request "+c,"ERR_NOT_SUPPORT")}return s}const lt={getAdapter:qn,adapters:ge};function Ne(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new G(null,e)}function ft(e){return Ne(e),e.headers=N.from(e.headers),e.data=Ae.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),lt.getAdapter(e.adapter||ee.adapter,e)(e).then(function(r){return Ne(e),r.data=Ae.call(e,e.transformResponse,r),r.headers=N.from(r.headers),r},function(r){return Xe(r)||(Ne(e),r&&r.response&&(r.response.data=Ae.call(e,e.transformResponse,r.response),r.response.headers=N.from(r.response.headers))),Promise.reject(r)})}const dt="1.13.2",fe={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{fe[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const ht={};fe.transitional=function(t,n,r){function s(o,i){return"[Axios v"+dt+"] Transitional option '"+o+"'"+i+(r?". "+r:"")}return(o,i,c)=>{if(t===!1)throw new E(s(i," has been removed"+(n?" in "+n:"")),E.ERR_DEPRECATED);return n&&!ht[i]&&(ht[i]=!0,console.warn(s(i," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(o,i,c):!0}},fe.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function $n(e,t,n){if(typeof e!="object")throw new E("options must be an object",E.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let s=r.length;for(;s-- >0;){const o=r[s],i=t[o];if(i){const c=e[o],d=c===void 0||i(c,o,e);if(d!==!0)throw new E("option "+o+" must be "+d,E.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new E("Unknown option "+o,E.ERR_BAD_OPTION)}}const de={assertOptions:$n,validators:fe},x=de.validators;let q=class{constructor(t){this.defaults=t||{},this.interceptors={request:new We,response:new We}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let s={};Error.captureStackTrace?Error.captureStackTrace(s):s=new Error;const o=s.stack?s.stack.replace(/^.+\n/,""):"";try{r.stack?o&&!String(r.stack).endsWith(o.replace(/^.+\n.+\n/,""))&&(r.stack+=`
|
|
6
|
+
`+o):r.stack=o}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=v(this.defaults,n);const{transitional:r,paramsSerializer:s,headers:o}=n;r!==void 0&&de.assertOptions(r,{silentJSONParsing:x.transitional(x.boolean),forcedJSONParsing:x.transitional(x.boolean),clarifyTimeoutError:x.transitional(x.boolean)},!1),s!=null&&(a.isFunction(s)?n.paramsSerializer={serialize:s}:de.assertOptions(s,{encode:x.function,serialize:x.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),de.assertOptions(n,{baseUrl:x.spelling("baseURL"),withXsrfToken:x.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=o&&a.merge(o.common,o[n.method]);o&&a.forEach(["delete","get","head","post","put","patch","common"],f=>{delete o[f]}),n.headers=N.concat(i,o);const c=[];let d=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(d=d&&m.synchronous,c.unshift(m.fulfilled,m.rejected))});const l=[];this.interceptors.response.forEach(function(m){l.push(m.fulfilled,m.rejected)});let u,p=0,S;if(!d){const f=[ft.bind(this),void 0];for(f.unshift(...c),f.push(...l),S=f.length,u=Promise.resolve(n);p<S;)u=u.then(f[p++],f[p++]);return u}S=c.length;let R=n;for(;p<S;){const f=c[p++],m=c[p++];try{R=f(R)}catch(h){m.call(this,h);break}}try{u=ft.call(this,R)}catch(f){return Promise.reject(f)}for(p=0,S=l.length;p<S;)u=u.then(l[p++],l[p++]);return u}getUri(t){t=v(this.defaults,t);const n=et(t.baseURL,t.url,t.allowAbsoluteUrls);return ze(n,t.params,t.paramsSerializer)}};a.forEach(["delete","get","head","options"],function(t){q.prototype[t]=function(n,r){return this.request(v(r||{},{method:t,url:n,data:(r||{}).data}))}}),a.forEach(["post","put","patch"],function(t){function n(r){return function(o,i,c){return this.request(v(c||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:o,data:i}))}}q.prototype[t]=n(),q.prototype[t+"Form"]=n(!0)});let Mn=class wt{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(o){n=o});const r=this;this.promise.then(s=>{if(!r._listeners)return;let o=r._listeners.length;for(;o-- >0;)r._listeners[o](s);r._listeners=null}),this.promise.then=s=>{let o;const i=new Promise(c=>{r.subscribe(c),o=c}).then(s);return i.cancel=function(){r.unsubscribe(o)},i},t(function(o,i,c){r.reason||(r.reason=new G(o,i,c),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new wt(function(s){t=s}),cancel:t}}};function Jn(e){return function(n){return e.apply(null,n)}}function zn(e){return a.isObject(e)&&e.isAxiosError===!0}const Ce={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,WebServerIsDown:521,ConnectionTimedOut:522,OriginIsUnreachable:523,TimeoutOccurred:524,SslHandshakeFailed:525,InvalidSslCertificate:526};Object.entries(Ce).forEach(([e,t])=>{Ce[t]=e});function pt(e){const t=new q(e),n=J(q.prototype.request,t);return a.extend(n,q.prototype,t,{allOwnKeys:!0}),a.extend(n,t,null,{allOwnKeys:!0}),n.create=function(s){return pt(v(e,s))},n}const T=pt(ee);T.Axios=q,T.CanceledError=G,T.CancelToken=Mn,T.isCancel=Xe,T.VERSION=dt,T.toFormData=ae,T.AxiosError=E,T.Cancel=T.CanceledError,T.all=function(t){return Promise.all(t)},T.spread=Jn,T.isAxiosError=zn,T.mergeConfig=v,T.AxiosHeaders=N,T.formToJSON=e=>Ke(a.isHTMLForm(e)?new FormData(e):e),T.getAdapter=lt.getAdapter,T.HttpStatusCode=Ce,T.default=T;const{Axios:cr,AxiosError:ur,CanceledError:lr,isCancel:fr,CancelToken:dr,VERSION:hr,all:pr,Cancel:mr,isAxiosError:Er,spread:Sr,toFormData:Tr,AxiosHeaders:yr,HttpStatusCode:br,formToJSON:wr,getAdapter:Rr,mergeConfig:Or}=T,Ue="JOYTALK_TOKEN";var K=(e=>(e.SEND="1",e.WITHDRAW="2",e.EDIT="3",e.SYSTEM_NOTICE="4",e.TRANSFER="5",e.INBOUND="6",e.REPLY="7",e.UNBIND="8",e))(K||{}),P=(e=>(e.TEXT="1",e.IMAGE="2",e.VIDEO="3",e.FILE="4",e.FAQ="5",e))(P||{}),k=(e=>(e[e.CONNECT_SUCCESS=200]="CONNECT_SUCCESS",e[e.CONNECT_FAILED=40001]="CONNECT_FAILED",e[e.TRANSFER_CUSTOMER_SUCCESS=201]="TRANSFER_CUSTOMER_SUCCESS",e[e.TRANSFER_TO_CUSTOMER_SUCCESS=202]="TRANSFER_TO_CUSTOMER_SUCCESS",e[e.TRANSFER_USER_SUCCESS=203]="TRANSFER_USER_SUCCESS",e[e.TRANSFER_FAIL=50001]="TRANSFER_FAIL",e[e.MATCH_FAIL=50002]="MATCH_FAIL",e[e.MATCH_INFO=50005]="MATCH_INFO",e[e.MATCH_SUCCESS=50006]="MATCH_SUCCESS",e[e.RETRACT=204]="RETRACT",e[e.RETRACT_FAIL=50003]="RETRACT_FAIL",e[e.EDIT=205]="EDIT",e[e.EDIT_FAIL=50004]="EDIT_FAIL",e[e.COMMON_FAIL=5e4]="COMMON_FAIL",e[e.SEND_SUCCESS=206]="SEND_SUCCESS",e[e.SEND_CALLBACK=207]="SEND_CALLBACK",e[e.CHANGE_CHAT_STATUS=208]="CHANGE_CHAT_STATUS",e))(k||{}),he=(e=>(e.CUSTOMER="1",e.USER="2",e.ANONYMOUS="3",e))(he||{});function Wn(e){return e.contentType==="1"}var U=(e=>(e.CONNECTED="connected",e.DISCONNECTED="disconnected",e.ERROR="error",e.MESSAGE="message",e.STATUS_CHANGE="status_change",e.HEARTBEAT_TIMEOUT="heartbeat_timeout",e))(U||{}),O=(e=>(e.DISCONNECTED="disconnected",e.CONNECTING="connecting",e.CONNECTED="connected",e.RECONNECTING="reconnecting",e.ERROR="error",e))(O||{});const V=T.create({baseURL:"http://dev-joytalk-api.halaladmin.vip",timeout:6e5});V.interceptors.request.use(e=>(e.noAuth||(e.headers.Authorization=`Bearer ${localStorage.getItem(Ue)}`),delete e.noAuth,e),e=>Promise.reject(e)),V.interceptors.response.use(e=>e.data.code!==200?(console.error(e.data.message),Promise.reject(e)):Promise.resolve(e.data),e=>Promise.reject(e));const Gn=e=>V.post("/api/open-auth/obs/v1/ObsService/GetObsAuthInfo",e),Kn=e=>T.post("https://joytalk-fat.obs.ap-southeast-1.myhuaweicloud.com:443",e,{headers:{"Content-Type":"multipart/form-data"}}),Vn=e=>V.post("/api/open-auth/open_consultation/v1/OpenConsultationService/GetConsultationList",e),Xn=e=>V.get("/api/open-auth/faq/v1/FaqService/GetFaqList",{params:e}),Qn=()=>V.get("/api/open-auth/user/v1/UserService/GetUserInfo");class Yn{events=new Map;on(t,n){this.events.has(t)||this.events.set(t,[]),this.events.get(t).push(n)}off(t,n){const r=this.events.get(t);if(r){const s=r.indexOf(n);s>-1&&r.splice(s,1)}}emit(t,n){const r=this.events.get(t);r&&r.forEach(s=>{try{s(n)}catch(o){console.error(`事件回调执行错误 [${t}]:`,o)}})}removeAllListeners(t){t?this.events.delete(t):this.events.clear()}}const Zn="https://joytalk-fat.obs.ap-southeast-1.myhuaweicloud.com:443/";class er extends Yn{config;ws=null;status=O.DISCONNECTED;reconnectTimer=null;reconnectAttempts=0;heartbeatTimeoutTimer=null;lastHeartbeatTime=0;customerGroupId="";OBS_URL=Zn;sessionData=null;userInfo=null;constructor(t){super(),this.config={token:t.token||"",autoReconnect:t.autoReconnect??!0,reconnectInterval:t.reconnectInterval??3e3,maxReconnectAttempts:t.maxReconnectAttempts??5,heartbeatTimeout:t.heartbeatTimeout??1e4},localStorage.setItem(Ue,this.config.token||"")}connect(t){return this.customerGroupId=t,new Promise((n,r)=>{if(this.status===O.CONNECTED){n();return}if(this.status!==O.CONNECTING){this.setStatus(O.CONNECTING);try{const s=this.buildWebSocketUrl();this.ws=new WebSocket(s),this.ws.onopen=()=>{this.reconnectAttempts=0,this.setStatus(O.CONNECTED),this.emit(U.CONNECTED),n()},this.ws.onmessage=o=>{try{this.handleMessage(o.data)}catch(i){console.error("解析消息失败:",i)}},this.ws.onerror=o=>{console.error("连接错误:",o),this.setStatus(O.ERROR),this.emit(U.ERROR,o),r(o)},this.ws.onclose=()=>{this.setStatus(O.DISCONNECTED),this.emit(U.DISCONNECTED),this.config.autoReconnect&&this.reconnectAttempts<this.config.maxReconnectAttempts&&this.scheduleReconnect()}}catch(s){this.setStatus(O.ERROR),this.emit(U.ERROR,s),r(s)}}})}disconnect(){this.config.autoReconnect=!1,this.clearReconnectTimer(),this.heartbeatTimeoutTimer&&(clearTimeout(this.heartbeatTimeoutTimer),this.heartbeatTimeoutTimer=null),this.ws&&(this.ws.close(),this.ws=null),this.setStatus(O.DISCONNECTED)}sendMessage(t,n,r=K.SEND){if(this.status!==O.CONNECTED||!this.ws)throw new Error("未连接到服务器");const s={msgType:r,data:t,toUid:this.sessionData?.cid,chatType:n,editId:void 0};this.ws.send(JSON.stringify(s))}sendText(t){return this.sendMessage(t,P.TEXT),Promise.resolve(!0)}sendFile({file:t,thumbnailFile:n,chatType:r}){return new Promise(async(s,o)=>{try{const[i,c]=await Promise.all([this.handleUploadFile(t),n?this.handleUploadFile(n):Promise.resolve(void 0)]),d={fileName:t.name,fileUrl:i,thumbnailUrl:c,fileSize:t.size};this.sendMessage(JSON.stringify(d),r),s(JSON.stringify(d))}catch(i){console.error("上传文件失败:",i),o(i)}})}getStatus(){return this.status}isConnected(){return this.status===O.CONNECTED}buildWebSocketUrl(){const t=new URL("ws://dev-joytalk-api.halaladmin.vip/api/ws");return this.config.token&&t.searchParams.set("Authorization",this.config.token),t.toString()}handleMessage(t){if(t==="ping"){this.lastHeartbeatTime=Date.now(),this.heartbeatTimeoutTimer&&(clearTimeout(this.heartbeatTimeoutTimer),this.heartbeatTimeoutTimer=null),this.sendHeartbeat();return}if(t=JSON.parse(t),this.isMessage(t))try{switch(t.code){case k.CONNECT_SUCCESS:this.sendMessage(this.customerGroupId,void 0,K.INBOUND);break;case k.MATCH_INFO:case k.MATCH_SUCCESS:const n=JSON.parse(typeof t.data=="string"?t.data:JSON.stringify(t.data));this.sessionData=n,t.data=n,this.getFaqList();break;case k.SEND_SUCCESS:const r=JSON.parse(typeof t.data=="string"?t.data:JSON.stringify(t.data));t.chatType!==P.TEXT&&typeof r.content=="string"&&(r.content=JSON.parse(r.content),r.content?.fileUrl?.startsWith("http")||(r.content.fileUrl=this.OBS_URL+r.content.fileUrl),r.content?.thumbnailUrl?.startsWith("http")||(r.content.thumbnailUrl=this.OBS_URL+r.content.thumbnailUrl)),t.data=r;break}this.emit(U.MESSAGE,t)}catch(n){console.error("解析消息失败:",n)}}isMessage(t){return typeof t=="object"&&t!==null&&"data"in t&&"msgType"in t&&"toUid"in t&&"chatType"in t&&"code"in t}setStatus(t){this.status!==t&&(this.status=t,this.emit(U.STATUS_CHANGE,t))}scheduleReconnect(){this.clearReconnectTimer(),this.reconnectAttempts++,this.setStatus(O.RECONNECTING),this.reconnectTimer=setTimeout(()=>{this.connect(this.customerGroupId).catch(t=>{console.error("重连失败:",t)})},this.config.reconnectInterval)}clearReconnectTimer(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}sendHeartbeat(){if(!(this.status!==O.CONNECTED||!this.ws))try{this.ws.send("pong"),this.lastHeartbeatTime=Date.now(),this.heartbeatTimeoutTimer=setTimeout(()=>{Date.now()-this.lastHeartbeatTime>=this.config.heartbeatTimeout&&(this.emit(U.HEARTBEAT_TIMEOUT),console.warn("心跳超时,尝试重连"),this.ws&&this.ws.close())},this.config.heartbeatTimeout)}catch(t){console.error("发送心跳失败:",t)}}getConsultationList(t){return Vn({entranceId:t})}handleUploadFile(t){return new Promise(async(n,r)=>{const s=t.name.split(".").pop(),o=await Gn({ext:s||""}),{accessKeyId:i,signature:c,policy:d,key:l}=o.data,u=new FormData;u.append("key",l),u.append("AccessKeyId",i),u.append("signature",c),u.append("policy",d),u.append("file",t),(await Kn(u)).status===204?n(this.OBS_URL+l):r(new Error("上传文件失败"))})}getVideoThumbnail=t=>new Promise((n,r)=>{const s=document.createElement("video"),o=document.createElement("canvas"),i=o.getContext("2d");if(!i){r(new Error("无法创建 canvas 上下文"));return}const c=URL.createObjectURL(t);s.preload="metadata",s.src=c,s.muted=!0,s.playsInline=!0,s.addEventListener("loadedmetadata",()=>{o.width=s.videoWidth,o.height=s.videoHeight,s.currentTime=0}),s.addEventListener("seeked",()=>{try{i.drawImage(s,0,0,o.width,o.height),o.toBlob(d=>{if(URL.revokeObjectURL(c),s.remove(),!d){r(new Error("无法生成缩略图"));return}const l=t.name.replace(/\.[^/.]+$/,"")+"_thumb.jpg",u=new File([d],l,{type:"image/jpeg",lastModified:Date.now()});n(u)},"image/jpeg",.6)}catch(d){URL.revokeObjectURL(c),s.remove(),r(d)}}),s.addEventListener("error",()=>{URL.revokeObjectURL(c),s.remove(),r(new Error("视频加载失败"))}),s.load()});async getFaqList(){const t=await Xn({id:this.sessionData?.cid});if(!t.data?.topic?.length)return;const n={guideText:t.data.guideText,list:t.data.topic.map(r=>({...r,question:r.question}))};setTimeout(()=>{const r={code:k.SEND_SUCCESS,data:{content:n,contentType:P.FAQ,sendUserType:he.CUSTOMER,customerServiceAvatar:this.sessionData?.customerAvatar,customerServiceName:this.sessionData?.customerName,createTime:Date.now()},msgType:K.SEND,chatType:P.FAQ,toUid:this.sessionData?.uid};this.emit(U.MESSAGE,r)},t.data.showDelaySeconds*1e3)}sendFaq(t){const n={sendUserType:he.CUSTOMER,customerServiceAvatar:this.sessionData?.customerAvatar,customerServiceName:this.sessionData?.customerName,createTime:Date.now()},r={code:k.SEND_SUCCESS,data:n,msgType:K.SEND,chatType:P.FAQ,toUid:this.sessionData?.uid};if(t.isMulti){const s={...r,data:{...n,content:{list:t.item},contentType:P.FAQ}};this.emit(U.MESSAGE,s)}else{const s=t.item?.[0]||t;if(s.answer){const o={...r,data:{...n,content:s.answer,contentType:P.TEXT}};this.emit(U.MESSAGE,o)}s.imageUrl?.forEach(o=>{const i={...r,data:{...n,content:{fileUrl:o?.startsWith("http")?o:this.OBS_URL+o,fileName:o.split("/").pop()},contentType:P.IMAGE}};this.emit(U.MESSAGE,i)})}}async getUserInfo(){if(this.userInfo)return this.userInfo;const t=await Qn();return this.userInfo=t.data,this.userInfo}}A.ChatType=P,A.ConnectionStatus=O,A.EventType=U,A.MessageCode=k,A.MessageType=K,A.SendUserType=he,A.TOKEN_KEY=Ue,A.default=er,A.isTextMessage=Wn,Object.defineProperties(A,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { MessageType, ConnectionStatus, FaqItem, UserInfo, SDKConfig, ChatType } from '../types';
|
|
2
|
+
import { EventEmitter } from '../utils/event-emitter';
|
|
3
|
+
/**
|
|
4
|
+
* 客服 SDK 主类
|
|
5
|
+
*/
|
|
6
|
+
export default class JoyTalk extends EventEmitter {
|
|
7
|
+
private config;
|
|
8
|
+
private ws;
|
|
9
|
+
private status;
|
|
10
|
+
private reconnectTimer;
|
|
11
|
+
private reconnectAttempts;
|
|
12
|
+
/** 心跳超时定时器 */
|
|
13
|
+
private heartbeatTimeoutTimer;
|
|
14
|
+
/** 最后一次心跳时间 */
|
|
15
|
+
private lastHeartbeatTime;
|
|
16
|
+
/** 客户组ID */
|
|
17
|
+
private customerGroupId;
|
|
18
|
+
/** obs 地址 */
|
|
19
|
+
OBS_URL: string;
|
|
20
|
+
private sessionData;
|
|
21
|
+
userInfo: UserInfo | null;
|
|
22
|
+
constructor(config: SDKConfig);
|
|
23
|
+
/**
|
|
24
|
+
* 连接到服务器
|
|
25
|
+
* @returns Promise<void>
|
|
26
|
+
*/
|
|
27
|
+
connect(customerGroupId: string): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* 断开连接
|
|
30
|
+
* @returns void
|
|
31
|
+
*/
|
|
32
|
+
disconnect(): void;
|
|
33
|
+
/**
|
|
34
|
+
* 发送消息
|
|
35
|
+
* @param data - 消息内容
|
|
36
|
+
* @param chatType - 聊天类型
|
|
37
|
+
* @param msgType - 消息类型
|
|
38
|
+
* @returns void
|
|
39
|
+
*/
|
|
40
|
+
sendMessage(data: string, chatType: ChatType | undefined, msgType?: MessageType): void;
|
|
41
|
+
/**
|
|
42
|
+
* 发送文本消息
|
|
43
|
+
* @param content - 消息内容
|
|
44
|
+
* @returns void
|
|
45
|
+
*/
|
|
46
|
+
sendText(content: string): Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* 发送文件消息
|
|
49
|
+
* @param file - 文件对象
|
|
50
|
+
* @param thumbnailFile - 缩略图文件对象
|
|
51
|
+
* @returns void
|
|
52
|
+
*/
|
|
53
|
+
sendFile({ file, thumbnailFile, chatType, }: {
|
|
54
|
+
file: File;
|
|
55
|
+
thumbnailFile?: File;
|
|
56
|
+
chatType: ChatType.IMAGE | ChatType.VIDEO | ChatType.FILE;
|
|
57
|
+
}): Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* 获取当前连接状态
|
|
60
|
+
* @returns ConnectionStatus
|
|
61
|
+
*/
|
|
62
|
+
getStatus(): ConnectionStatus;
|
|
63
|
+
/**
|
|
64
|
+
* 是否已连接
|
|
65
|
+
* @returns boolean
|
|
66
|
+
*/
|
|
67
|
+
isConnected(): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* 构建 WebSocket URL
|
|
70
|
+
* @returns string
|
|
71
|
+
*/
|
|
72
|
+
private buildWebSocketUrl;
|
|
73
|
+
/**
|
|
74
|
+
* 处理收到的消息
|
|
75
|
+
* @param data - 消息数据
|
|
76
|
+
* @returns void
|
|
77
|
+
*/
|
|
78
|
+
private handleMessage;
|
|
79
|
+
/**
|
|
80
|
+
* 判断是否为消息对象
|
|
81
|
+
* @param data - 消息数据
|
|
82
|
+
* @returns boolean
|
|
83
|
+
*/
|
|
84
|
+
private isMessage;
|
|
85
|
+
/**
|
|
86
|
+
* 设置连接状态
|
|
87
|
+
* @param status - 连接状态
|
|
88
|
+
* @returns void
|
|
89
|
+
*/
|
|
90
|
+
private setStatus;
|
|
91
|
+
/**
|
|
92
|
+
* 安排重连
|
|
93
|
+
* @returns void
|
|
94
|
+
*/
|
|
95
|
+
private scheduleReconnect;
|
|
96
|
+
/**
|
|
97
|
+
* 清除重连定时器
|
|
98
|
+
* @returns void
|
|
99
|
+
*/
|
|
100
|
+
private clearReconnectTimer;
|
|
101
|
+
/**
|
|
102
|
+
* 发送心跳
|
|
103
|
+
* @returns void
|
|
104
|
+
*/
|
|
105
|
+
private sendHeartbeat;
|
|
106
|
+
/**
|
|
107
|
+
* 获取咨询列表
|
|
108
|
+
* @returns Promise<ConsultationListResponse>
|
|
109
|
+
*/
|
|
110
|
+
getConsultationList(entranceId: number): Promise<import('../types').RequestResponse<import('../types').ConsultationListResponse>>;
|
|
111
|
+
private handleUploadFile;
|
|
112
|
+
/**
|
|
113
|
+
* 获取视频文件的首帧作为缩略图
|
|
114
|
+
* @param videoFile - 视频文件对象
|
|
115
|
+
* @returns Promise<File> 返回首帧图片的 File 对象
|
|
116
|
+
*/
|
|
117
|
+
getVideoThumbnail: (videoFile: File) => Promise<File>;
|
|
118
|
+
private getFaqList;
|
|
119
|
+
sendFaq(faqItem: FaqItem): void;
|
|
120
|
+
getUserInfo(): Promise<UserInfo>;
|
|
121
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SessionData } from '../../types';
|
|
2
|
+
import { EventEmitter } from '../../utils/event-emitter';
|
|
3
|
+
export declare class ApiClient extends EventEmitter {
|
|
4
|
+
/** obs 地址 */
|
|
5
|
+
readonly OBS_URL: string;
|
|
6
|
+
/**
|
|
7
|
+
* 获取咨询列表
|
|
8
|
+
*/
|
|
9
|
+
getConsultationList(entranceId: number): Promise<import('../../types').RequestResponse<import('../../types').ConsultationListResponse>>;
|
|
10
|
+
handleUploadFile(file: File): Promise<string>;
|
|
11
|
+
getFaqList(sessionData: SessionData): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ConnectionStatus, SDKConfig } from '../../types';
|
|
2
|
+
import { EventEmitter } from '../../utils/event-emitter';
|
|
3
|
+
/**
|
|
4
|
+
* 连接管理器接口
|
|
5
|
+
*/
|
|
6
|
+
export interface IConnectionManager {
|
|
7
|
+
connect(customerGroupId: string): Promise<void>;
|
|
8
|
+
disconnect(): void;
|
|
9
|
+
getStatus(): ConnectionStatus;
|
|
10
|
+
isConnected(): boolean;
|
|
11
|
+
getWebSocket(): WebSocket | null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* WebSocket 连接管理器
|
|
15
|
+
*/
|
|
16
|
+
export declare class ConnectionManager extends EventEmitter implements IConnectionManager {
|
|
17
|
+
private config;
|
|
18
|
+
private ws;
|
|
19
|
+
private status;
|
|
20
|
+
private reconnectTimer;
|
|
21
|
+
private reconnectAttempts;
|
|
22
|
+
private heartbeatTimeoutTimer;
|
|
23
|
+
private lastHeartbeatTime;
|
|
24
|
+
private customerGroupId;
|
|
25
|
+
constructor(config: Required<SDKConfig>);
|
|
26
|
+
/**
|
|
27
|
+
* 连接到服务器
|
|
28
|
+
*/
|
|
29
|
+
connect(customerGroupId: string): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* 断开连接
|
|
32
|
+
*/
|
|
33
|
+
disconnect(): void;
|
|
34
|
+
/**
|
|
35
|
+
* 获取当前连接状态
|
|
36
|
+
*/
|
|
37
|
+
getStatus(): ConnectionStatus;
|
|
38
|
+
/**
|
|
39
|
+
* 是否已连接
|
|
40
|
+
*/
|
|
41
|
+
isConnected(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* 获取 WebSocket 实例
|
|
44
|
+
*/
|
|
45
|
+
getWebSocket(): WebSocket | null;
|
|
46
|
+
/**
|
|
47
|
+
* 设置消息处理器
|
|
48
|
+
*/
|
|
49
|
+
setMessageHandler(handler: (data: string | MessageEvent) => void): void;
|
|
50
|
+
/**
|
|
51
|
+
* 发送心跳
|
|
52
|
+
*/
|
|
53
|
+
sendHeartbeat(): void;
|
|
54
|
+
/**
|
|
55
|
+
* 处理心跳响应
|
|
56
|
+
*/
|
|
57
|
+
handleHeartbeatResponse(): void;
|
|
58
|
+
/**
|
|
59
|
+
* 构建 WebSocket URL
|
|
60
|
+
*/
|
|
61
|
+
private buildWebSocketUrl;
|
|
62
|
+
/**
|
|
63
|
+
* 设置连接状态
|
|
64
|
+
*/
|
|
65
|
+
private setStatus;
|
|
66
|
+
/**
|
|
67
|
+
* 安排重连
|
|
68
|
+
*/
|
|
69
|
+
private scheduleReconnect;
|
|
70
|
+
/**
|
|
71
|
+
* 清除重连定时器
|
|
72
|
+
*/
|
|
73
|
+
private clearReconnectTimer;
|
|
74
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SessionData, FaqItem } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* FAQ 管理器接口
|
|
4
|
+
*/
|
|
5
|
+
export interface IFaqManager {
|
|
6
|
+
getFaqList(sessionData: SessionData): Promise<void>;
|
|
7
|
+
sendFaq(faqItem: FaqItem, sessionData: SessionData, obsUrl: string): void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* FAQ 管理器
|
|
11
|
+
*/
|
|
12
|
+
export declare class FaqManager implements IFaqManager {
|
|
13
|
+
private emit;
|
|
14
|
+
constructor(emit: (event: string, data?: any) => void);
|
|
15
|
+
/**
|
|
16
|
+
* 获取 FAQ 列表
|
|
17
|
+
*/
|
|
18
|
+
getFaqList(sessionData: SessionData): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* 发送 FAQ
|
|
21
|
+
*/
|
|
22
|
+
sendFaq(faqItem: FaqItem, sessionData: SessionData, obsUrl: string): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文件上传模块
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 文件上传器接口
|
|
6
|
+
*/
|
|
7
|
+
export interface IFileUploader {
|
|
8
|
+
uploadFile(file: File): Promise<string>;
|
|
9
|
+
getVideoThumbnail(videoFile: File): Promise<File>;
|
|
10
|
+
getObsUrl(): string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 文件上传器
|
|
14
|
+
*/
|
|
15
|
+
export declare class FileUploader implements IFileUploader {
|
|
16
|
+
private obsUrl;
|
|
17
|
+
/**
|
|
18
|
+
* 获取 OBS URL
|
|
19
|
+
*/
|
|
20
|
+
getObsUrl(): string;
|
|
21
|
+
/**
|
|
22
|
+
* 上传文件
|
|
23
|
+
*/
|
|
24
|
+
uploadFile(file: File): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* 获取视频文件的首帧作为缩略图
|
|
27
|
+
*/
|
|
28
|
+
getVideoThumbnail(videoFile: File): Promise<File>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { MessageType, ChatType, Message, SessionData } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* 消息处理器接口
|
|
4
|
+
*/
|
|
5
|
+
export interface IMessageHandler {
|
|
6
|
+
handleMessage(data: string | Message): void;
|
|
7
|
+
sendMessage(data: string, chatType: ChatType | undefined, msgType?: MessageType): void;
|
|
8
|
+
sendText(content: string): Promise<boolean>;
|
|
9
|
+
sendFile(params: {
|
|
10
|
+
file: File;
|
|
11
|
+
thumbnailFile?: File;
|
|
12
|
+
chatType: ChatType.IMAGE | ChatType.VIDEO | ChatType.FILE;
|
|
13
|
+
}): Promise<string>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 消息处理器
|
|
17
|
+
*/
|
|
18
|
+
export declare class MessageHandler implements IMessageHandler {
|
|
19
|
+
private ws;
|
|
20
|
+
private sessionData;
|
|
21
|
+
private customerGroupId;
|
|
22
|
+
private obsUrl;
|
|
23
|
+
private emit;
|
|
24
|
+
private handleUploadFile;
|
|
25
|
+
constructor(ws: WebSocket | null, sessionData: SessionData | null, customerGroupId: string, obsUrl: string, emit: (event: string, data?: any) => void, handleUploadFile: (file: File) => Promise<string>);
|
|
26
|
+
/**
|
|
27
|
+
* 更新 WebSocket 实例
|
|
28
|
+
*/
|
|
29
|
+
updateWebSocket(ws: WebSocket | null): void;
|
|
30
|
+
/**
|
|
31
|
+
* 更新会话数据
|
|
32
|
+
*/
|
|
33
|
+
updateSessionData(sessionData: SessionData | null): void;
|
|
34
|
+
/**
|
|
35
|
+
* 更新客户组ID
|
|
36
|
+
*/
|
|
37
|
+
updateCustomerGroupId(customerGroupId: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* 处理收到的消息
|
|
40
|
+
*/
|
|
41
|
+
handleMessage(data: string | Message): void;
|
|
42
|
+
/**
|
|
43
|
+
* 发送消息
|
|
44
|
+
*/
|
|
45
|
+
sendMessage(data: string, chatType: ChatType | undefined, msgType?: MessageType): void;
|
|
46
|
+
/**
|
|
47
|
+
* 发送文本消息
|
|
48
|
+
*/
|
|
49
|
+
sendText(content: string): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* 发送文件消息
|
|
52
|
+
*/
|
|
53
|
+
sendFile({ file, thumbnailFile, chatType, }: {
|
|
54
|
+
file: File;
|
|
55
|
+
thumbnailFile?: File;
|
|
56
|
+
chatType: ChatType.IMAGE | ChatType.VIDEO | ChatType.FILE;
|
|
57
|
+
}): Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* 判断是否为消息对象
|
|
60
|
+
*/
|
|
61
|
+
private isMessage;
|
|
62
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { UserInfo } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* 用户管理器接口
|
|
4
|
+
*/
|
|
5
|
+
export interface IUserManager {
|
|
6
|
+
getUserInfo(): Promise<UserInfo>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 用户管理器
|
|
10
|
+
*/
|
|
11
|
+
export declare class UserManager implements IUserManager {
|
|
12
|
+
private userInfo;
|
|
13
|
+
/**
|
|
14
|
+
* 获取用户信息
|
|
15
|
+
*/
|
|
16
|
+
getUserInfo(): Promise<UserInfo>;
|
|
17
|
+
/**
|
|
18
|
+
* 获取缓存的用户信息
|
|
19
|
+
*/
|
|
20
|
+
getCachedUserInfo(): UserInfo | null;
|
|
21
|
+
/**
|
|
22
|
+
* 清除用户信息缓存
|
|
23
|
+
*/
|
|
24
|
+
clearCache(): void;
|
|
25
|
+
}
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK 类型定义
|
|
3
|
+
*/
|
|
4
|
+
export * from './request';
|
|
5
|
+
export * from './message';
|
|
6
|
+
/**
|
|
7
|
+
* SDK 配置选项
|
|
8
|
+
*/
|
|
9
|
+
export interface SDKConfig {
|
|
10
|
+
/** 服务器地址 */
|
|
11
|
+
/** API 基础地址(用于获取聊天记录等 HTTP 请求) */
|
|
12
|
+
/** 用户ID */
|
|
13
|
+
/** 用户名称 */
|
|
14
|
+
/** 认证令牌 */
|
|
15
|
+
token: string;
|
|
16
|
+
/** 自动重连 */
|
|
17
|
+
autoReconnect?: boolean;
|
|
18
|
+
/** 重连间隔(毫秒) */
|
|
19
|
+
reconnectInterval?: number;
|
|
20
|
+
/** 最大重连次数 */
|
|
21
|
+
maxReconnectAttempts?: number;
|
|
22
|
+
/** 心跳超时时间(毫秒),默认 10000 */
|
|
23
|
+
heartbeatTimeout?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 事件类型
|
|
27
|
+
*/
|
|
28
|
+
export declare enum EventType {
|
|
29
|
+
/** 连接成功 */
|
|
30
|
+
CONNECTED = "connected",
|
|
31
|
+
/** 连接断开 */
|
|
32
|
+
DISCONNECTED = "disconnected",
|
|
33
|
+
/** 连接错误 */
|
|
34
|
+
ERROR = "error",
|
|
35
|
+
/** 收到消息 */
|
|
36
|
+
MESSAGE = "message",
|
|
37
|
+
/** 状态变化 */
|
|
38
|
+
STATUS_CHANGE = "status_change",
|
|
39
|
+
/** 心跳超时 */
|
|
40
|
+
HEARTBEAT_TIMEOUT = "heartbeat_timeout"
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 连接状态
|
|
44
|
+
*/
|
|
45
|
+
export declare enum ConnectionStatus {
|
|
46
|
+
/** 未连接 */
|
|
47
|
+
DISCONNECTED = "disconnected",
|
|
48
|
+
/** 连接中 */
|
|
49
|
+
CONNECTING = "connecting",
|
|
50
|
+
/** 已连接 */
|
|
51
|
+
CONNECTED = "connected",
|
|
52
|
+
/** 重连中 */
|
|
53
|
+
RECONNECTING = "reconnecting",
|
|
54
|
+
/** 错误 */
|
|
55
|
+
ERROR = "error"
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 事件回调函数类型
|
|
59
|
+
*/
|
|
60
|
+
export type EventCallback<T = any> = (data?: T) => void;
|
|
61
|
+
/**
|
|
62
|
+
* 聊天记录查询参数
|
|
63
|
+
*/
|
|
64
|
+
export interface ChatHistoryParams {
|
|
65
|
+
/** 会话ID(可选,不传则获取当前用户的聊天记录) */
|
|
66
|
+
sessionId?: string;
|
|
67
|
+
/** 接收者ID(可选,用于查询与特定用户的聊天记录) */
|
|
68
|
+
receiverId?: string;
|
|
69
|
+
/** 页码,从 1 开始 */
|
|
70
|
+
page?: number;
|
|
71
|
+
/** 每页数量 */
|
|
72
|
+
pageSize?: number;
|
|
73
|
+
/** 开始时间戳(可选) */
|
|
74
|
+
startTime?: number;
|
|
75
|
+
/** 结束时间戳(可选) */
|
|
76
|
+
endTime?: number;
|
|
77
|
+
}
|