@sermas/api-client 1.0.0-alpha.20 → 1.0.0-alpha.22
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/index.cjs +1 -1
- package/index.cjs.map +1 -1
- package/index.d.cts +7 -4
- package/index.d.ts +7 -4
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/package.json +1 -2
package/index.d.cts
CHANGED
|
@@ -954,17 +954,17 @@ declare class PlatformService {
|
|
|
954
954
|
/**
|
|
955
955
|
* @param appId
|
|
956
956
|
* @param requestBody
|
|
957
|
-
* @returns
|
|
957
|
+
* @returns AppClientDto
|
|
958
958
|
* @throws ApiError
|
|
959
959
|
*/
|
|
960
|
-
createClient(appId: string, requestBody: AppClientDto): CancelablePromise<
|
|
960
|
+
createClient(appId: string, requestBody: AppClientDto): CancelablePromise<AppClientDto>;
|
|
961
961
|
/**
|
|
962
962
|
* @param appId
|
|
963
963
|
* @param clientId
|
|
964
|
-
* @returns
|
|
964
|
+
* @returns AppClientDto
|
|
965
965
|
* @throws ApiError
|
|
966
966
|
*/
|
|
967
|
-
readClient(appId: string, clientId: string): CancelablePromise<
|
|
967
|
+
readClient(appId: string, clientId: string): CancelablePromise<AppClientDto>;
|
|
968
968
|
/**
|
|
969
969
|
* @param clientId
|
|
970
970
|
* @param appId
|
|
@@ -2499,6 +2499,8 @@ interface SermasApiClientConfig {
|
|
|
2499
2499
|
domain?: string;
|
|
2500
2500
|
access_token?: string;
|
|
2501
2501
|
refresh_token?: string;
|
|
2502
|
+
clientId?: string;
|
|
2503
|
+
clientSecret?: string;
|
|
2502
2504
|
env?: SermasEnvType;
|
|
2503
2505
|
appId?: string;
|
|
2504
2506
|
logger?: LoggerService;
|
|
@@ -2520,6 +2522,7 @@ declare class SermasApiClient {
|
|
|
2520
2522
|
init(force?: boolean): Promise<void>;
|
|
2521
2523
|
refreshToken(): Promise<any>;
|
|
2522
2524
|
loadToken(clientId: any, clientSecret: any, appId?: string): Promise<JwtTokenDto>;
|
|
2525
|
+
setToken(accessToken: string | LoginResponseDto, refreshToken?: string): Promise<void>;
|
|
2523
2526
|
login(username: any, password: any, appId?: string): Promise<LoginResponseDto>;
|
|
2524
2527
|
}
|
|
2525
2528
|
|
package/index.d.ts
CHANGED
|
@@ -954,17 +954,17 @@ declare class PlatformService {
|
|
|
954
954
|
/**
|
|
955
955
|
* @param appId
|
|
956
956
|
* @param requestBody
|
|
957
|
-
* @returns
|
|
957
|
+
* @returns AppClientDto
|
|
958
958
|
* @throws ApiError
|
|
959
959
|
*/
|
|
960
|
-
createClient(appId: string, requestBody: AppClientDto): CancelablePromise<
|
|
960
|
+
createClient(appId: string, requestBody: AppClientDto): CancelablePromise<AppClientDto>;
|
|
961
961
|
/**
|
|
962
962
|
* @param appId
|
|
963
963
|
* @param clientId
|
|
964
|
-
* @returns
|
|
964
|
+
* @returns AppClientDto
|
|
965
965
|
* @throws ApiError
|
|
966
966
|
*/
|
|
967
|
-
readClient(appId: string, clientId: string): CancelablePromise<
|
|
967
|
+
readClient(appId: string, clientId: string): CancelablePromise<AppClientDto>;
|
|
968
968
|
/**
|
|
969
969
|
* @param clientId
|
|
970
970
|
* @param appId
|
|
@@ -2499,6 +2499,8 @@ interface SermasApiClientConfig {
|
|
|
2499
2499
|
domain?: string;
|
|
2500
2500
|
access_token?: string;
|
|
2501
2501
|
refresh_token?: string;
|
|
2502
|
+
clientId?: string;
|
|
2503
|
+
clientSecret?: string;
|
|
2502
2504
|
env?: SermasEnvType;
|
|
2503
2505
|
appId?: string;
|
|
2504
2506
|
logger?: LoggerService;
|
|
@@ -2520,6 +2522,7 @@ declare class SermasApiClient {
|
|
|
2520
2522
|
init(force?: boolean): Promise<void>;
|
|
2521
2523
|
refreshToken(): Promise<any>;
|
|
2522
2524
|
loadToken(clientId: any, clientSecret: any, appId?: string): Promise<JwtTokenDto>;
|
|
2525
|
+
setToken(accessToken: string | LoginResponseDto, refreshToken?: string): Promise<void>;
|
|
2523
2526
|
login(username: any, password: any, appId?: string): Promise<LoginResponseDto>;
|
|
2524
2527
|
}
|
|
2525
2528
|
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var de=Object.defineProperty;var me=(o,e,t)=>e in o?de(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var n=(o,e,t)=>(me(o,typeof e!="symbol"?e+"":e,t),t),re=(o,e,t)=>{if(!e.has(o))throw TypeError("Cannot "+t)};var l=(o,e,t)=>(re(o,e,"read from private field"),t?t.call(o):e.get(o)),D=(o,e,t)=>{if(e.has(o))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(o):e.set(o,t)},m=(o,e,t,s)=>(re(o,e,"write to private field"),s?s.call(o,t):e.set(o,t),t);import{jwtDecode as Te}from"jwt-decode";var j=class{constructor(e){this.broker=e}async tokenRequested(e,t){return this.broker.publish("app/:appId/platform/token",e,t)}async onTokenRequested(e,t){return this.broker.subscribe("app/:appId/platform/token",e,t)}async appChanged(e,t){return this.broker.publish("app/:appId/platform/app/changed/:appId",e,t)}async onAppChanged(e,t){return this.broker.subscribe("app/:appId/platform/app/changed/:appId",e,t)}async clientChanged(e,t){return this.broker.publish("app/:appId/platform/client/changed/:clientId",e,t)}async onClientChanged(e,t){return this.broker.subscribe("app/:appId/platform/client/changed/:clientId",e,t)}async appModuleChanged(e,t){return this.broker.publish("app/:appId/platform/module",e,t)}async onAppModuleChanged(e,t){return this.broker.subscribe("app/:appId/platform/module",e,t)}};var H=class{constructor(e){this.broker=e}async moduleChanged(e,t){return this.broker.publish("system/platform/module/changed/:moduleId",e,t)}async onModuleChanged(e,t){return this.broker.subscribe("system/platform/module/changed/:moduleId",e,t)}};var N=class{constructor(e){this.broker=e}async userUpdate(e,t){return this.broker.publish("app/:appId/auth/update",e,t)}async onUserUpdate(e,t){return this.broker.subscribe("app/:appId/auth/update",e,t)}async userRegistration(e,t){return this.broker.publish("app/:appId/auth/create",e,t)}async onUserRegistration(e,t){return this.broker.subscribe("app/:appId/auth/create",e,t)}async userLogin(e,t){return this.broker.publish("app/:appId/auth/login",e,t)}async onUserLogin(e,t){return this.broker.subscribe("app/:appId/auth/login",e,t)}};var _=class{constructor(e){this.broker=e}async userDetected(e,t){return this.broker.publish("app/:appId/detection/user",e,t)}async onUserDetected(e,t){return this.broker.subscribe("app/:appId/detection/user",e,t)}async interactionIntention(e,t){return this.broker.publish("app/:appId/detection/interaction",e,t)}async onInteractionIntention(e,t){return this.broker.subscribe("app/:appId/detection/interaction",e,t)}async userCharacterization(e,t){return this.broker.publish("app/:appId/detection/characterization",e,t)}async onUserCharacterization(e,t){return this.broker.subscribe("app/:appId/detection/characterization",e,t)}async audioClassification(e,t){return this.broker.publish("app/:appId/detection/audio",e,t)}async onAudioClassification(e,t){return this.broker.subscribe("app/:appId/detection/audio",e,t)}async objectDetected(e,t){return this.broker.publish("app/:appId/detection/object",e,t)}async onObjectDetected(e,t){return this.broker.subscribe("app/:appId/detection/object",e,t)}async qrCodeDetected(e,t){return this.broker.publish("app/:appId/detection/qr_code",e,t)}async onQrCodeDetected(e,t){return this.broker.subscribe("app/:appId/detection/qr_code",e,t)}async noise(e,t){return this.broker.publish("app/:appId/detection/noise",e,t)}async onNoise(e,t){return this.broker.subscribe("app/:appId/detection/noise",e,t)}};var X=class{constructor(e){this.broker=e}async toolTriggered(e,t){return this.broker.publish("app/:appId/dialogue/tool/:name",e,t)}async onToolTriggered(e,t){return this.broker.subscribe("app/:appId/dialogue/tool/:name",e,t)}async dialogueMessages(e,t){return this.broker.publish("app/:appId/dialogue/messages",e,t)}async onDialogueMessages(e,t){return this.broker.subscribe("app/:appId/dialogue/messages",e,t)}async agentSpeech(e,t){return this.broker.publish("app/:appId/dialogue/speech/:sessionId/:chunkId",e,t)}async onAgentSpeech(e,t){return this.broker.subscribe("app/:appId/dialogue/speech/:sessionId/:chunkId",e,t)}};var z=class{constructor(e){this.broker=e}async userInteraction(e,t){return this.broker.publish("app/:appId/session/interaction/user",e,t)}async onUserInteraction(e,t){return this.broker.subscribe("app/:appId/session/interaction/user",e,t)}async sessionChanged(e,t){return this.broker.publish("app/:appId/session/session/changed/:sessionId",e,t)}async onSessionChanged(e,t){return this.broker.subscribe("app/:appId/session/session/changed/:sessionId",e,t)}async agentInteraction(e,t){return this.broker.publish("app/:appId/session/interaction/agent",e,t)}async onAgentInteraction(e,t){return this.broker.subscribe("app/:appId/session/interaction/agent",e,t)}async agentChanged(e,t){return this.broker.publish("app/:appId/session/agent/changed/:agentId",e,t)}async onAgentChanged(e,t){return this.broker.subscribe("app/:appId/session/agent/changed/:agentId",e,t)}async storageUpdated(e,t){return this.broker.publish("app/:appId/session/storage/:storageId",e,t)}async onStorageUpdated(e,t){return this.broker.subscribe("app/:appId/session/storage/:storageId",e,t)}async support(e,t){return this.broker.publish("app/:appId/session/support",e,t)}async onSupport(e,t){return this.broker.subscribe("app/:appId/session/support",e,t)}};var $=class{constructor(e){this.broker=e}async assetChange(e,t){return this.broker.publish("app/:appId/ui/status",e,t)}async onAssetChange(e,t){return this.broker.subscribe("app/:appId/ui/status",e,t)}async content(e,t){return this.broker.publish("app/:appId/ui/content",e,t)}async onContent(e,t){return this.broker.subscribe("app/:appId/ui/content",e,t)}async interaction(e,t){return this.broker.publish("app/:appId/ui/interaction/:moduleId",e,t)}async onInteraction(e,t){return this.broker.subscribe("app/:appId/ui/interaction/:moduleId",e,t)}};var G=class{constructor(e){this.broker=e}async detected(e,t){return this.broker.publish("app/:appId/xr/marker/detected",e,t)}async onDetected(e,t){return this.broker.subscribe("app/:appId/xr/marker/detected",e,t)}async changed(e,t){return this.broker.publish("app/:appId/xr/marker/changed/:markerId",e,t)}async onChanged(e,t){return this.broker.subscribe("app/:appId/xr/marker/changed/:markerId",e,t)}async occluded(e,t){return this.broker.publish("app/:appId/xr/occlusion",e,t)}async onOccluded(e,t){return this.broker.subscribe("app/:appId/xr/occlusion",e,t)}};var J=class{constructor(e){this.broker=e}async actuate(e,t){return this.broker.publish("app/:appId/robotics/actuate",e,t)}async onActuate(e,t){return this.broker.subscribe("app/:appId/robotics/actuate",e,t)}async move(e,t){return this.broker.publish("app/:appId/robotics/move",e,t)}async onMove(e,t){return this.broker.subscribe("app/:appId/robotics/move",e,t)}async robotStatus(e,t){return this.broker.publish("app/:appId/robotics/status",e,t)}async onRobotStatus(e,t){return this.broker.subscribe("app/:appId/robotics/status",e,t)}async initialPose(e,t){return this.broker.publish("app/:appId/robotics/initialpose",e,t)}async onInitialPose(e,t){return this.broker.subscribe("app/:appId/robotics/initialpose",e,t)}};var S=class{constructor(e){this.broker=e;n(this,"platform");n(this,"module");n(this,"auth");n(this,"detection");n(this,"dialogue");n(this,"session");n(this,"ui");n(this,"xr");n(this,"robotics");this.platform=new j(e),this.module=new H(e),this.auth=new N(e),this.detection=new _(e),this.dialogue=new X(e),this.session=new z(e),this.ui=new $(e),this.xr=new G(e),this.robotics=new J(e)}};import he from"mqtt";var Y,se=o=>{Y=o},ce=(o="logger")=>new class{format(e){return`[${o}] ${e}`}debug(e,...t){console.debug(this.format(e))}error(e,...t){console.error(this.format(e))}fatal(e,...t){console.error(this.format(e))}log(e,...t){console.info(this.format(e))}setLogLevels(e){}verbose(e,...t){console.debug(this.format(e))}warn(e,...t){console.warn(this.format(e))}},C=class{constructor(e){n(this,"logger");this.logger=Y||ce(e)}debug(e,...t){this.logger.debug(e)}error(e,...t){this.logger.error(e)}fatal(e,...t){this.logger.error(e)}log(e,...t){(this.logger.info||this.logger.log).apply(this.logger,[e])}setLogLevels(e){}verbose(e,...t){this.logger.verbose(e)}warn(e,...t){this.logger.warn(e)}};var V=class o{constructor(e){this.config=e;n(this,"logger",new C(o.name));n(this,"client");n(this,"subscriptions",[])}async setToken(e){this.logger.debug("Token updated, reconnecting"),this.client.options.username=e,this.client.reconnect()}async connect(){if(this.client)try{this.client.end(!0)}catch{}finally{this.client=void 0}this.client=await he.connectAsync(this.config.url,{username:this.config.username,password:this.config.password}),this.client.on("connect",()=>{}),this.client.on("error",e=>{this.logger.error(`mqtt client error ${e.stack}`)}),this.client.on("message",(e,t)=>{let s=t;try{s=JSON.parse(t.toString())}catch{}this.logger.debug(`MSG ${e}`);let i=e.indexOf("#");i>-1&&(e=e.substring(0,i));let r=this.parseTopic(e),p=a=>a==="+";this.subscriptions.forEach(a=>{if(a.type===r.type&&!(!p(a.appId)&&a.appId!==r.appId)&&!(!p(a.resource)&&a.resource!==r.resource)&&!(!p(a.scope)&&a.scope!==r.scope)){for(let u in r.context||[])if(!p(a.context[u])&&a.context[u]!==r.context[u])return;a.callback(s)}})})}parseTopic(e){let t=e.split("/"),[s,i,r,p]=t,a=t.slice(3);return{type:s,appId:i,resource:r,scope:p,context:a}}async subscribe(e,t,s){return e=this.replaceTopicParams(e,{...s||{}}),this.subscriptions.push({...this.parseTopic(e),topic:e,callback:t}),this.logger.debug(`SUB ${e}`),await this.client.subscribeAsync(e),()=>{let i=this.subscriptions.findIndex(r=>r.topic===e&&r.callback===t);i>-1&&(this.subscriptions.splice(i,1),this.subscriptions.filter(r=>r.topic===e).length===1&&this.client.unsubscribe(e))}}async publish(e,t,s){let i=t.byteLength!==void 0,r;i?r=t:r=JSON.stringify(t);try{e=this.replaceTopicParams(e,{...i?{}:t,...s||{}}),await this.client.publishAsync(e,r)}catch{return!1}return!0}replaceTopicParams(e,t){t={...this.config?.params||{},...t||{}};for(let s of Object.keys(t)){let i=`:${s}`,r=t[s];if(r!=null){if(typeof r=="object"&&!Array.isArray(r)){e=this.replaceTopicParams(e,r);continue}if(!(typeof r!="string"&&typeof r!="number"))for(;e.indexOf(i)>-1;)e=e.replace(i,r.toString())}}return e=e.split("/").map(s=>s[0]===":"?"+":s).join("/"),e}};var T=class{constructor(e){this.config=e}};import ie from"axios";import ne from"form-data";var P=class extends Error{constructor(t,s,i){super(i);n(this,"url");n(this,"status");n(this,"statusText");n(this,"body");n(this,"request");this.name="ApiError",this.url=s.url,this.status=s.status,this.statusText=s.statusText,this.body=s.body,this.request=t}};var F=class extends Error{constructor(e){super(e),this.name="CancelError"}get isCancelled(){return!0}},h,g,c,f,I,q,b,A=class{constructor(e){D(this,h,void 0);D(this,g,void 0);D(this,c,void 0);D(this,f,void 0);D(this,I,void 0);D(this,q,void 0);D(this,b,void 0);m(this,h,!1),m(this,g,!1),m(this,c,!1),m(this,f,[]),m(this,I,new Promise((t,s)=>{m(this,q,t),m(this,b,s);let i=a=>{l(this,h)||l(this,g)||l(this,c)||(m(this,h,!0),l(this,q)&&l(this,q).call(this,a))},r=a=>{l(this,h)||l(this,g)||l(this,c)||(m(this,g,!0),l(this,b)&&l(this,b).call(this,a))},p=a=>{l(this,h)||l(this,g)||l(this,c)||l(this,f).push(a)};return Object.defineProperty(p,"isResolved",{get:()=>l(this,h)}),Object.defineProperty(p,"isRejected",{get:()=>l(this,g)}),Object.defineProperty(p,"isCancelled",{get:()=>l(this,c)}),e(i,r,p)}))}get[Symbol.toStringTag](){return"Cancellable Promise"}then(e,t){return l(this,I).then(e,t)}catch(e){return l(this,I).catch(e)}finally(e){return l(this,I).finally(e)}cancel(){if(!(l(this,h)||l(this,g)||l(this,c))){if(m(this,c,!0),l(this,f).length)try{for(let e of l(this,f))e()}catch(e){console.warn("Cancellation threw an error",e);return}l(this,f).length=0,l(this,b)&&l(this,b).call(this,new F("Request aborted"))}}get isCancelled(){return l(this,c)}};h=new WeakMap,g=new WeakMap,c=new WeakMap,f=new WeakMap,I=new WeakMap,q=new WeakMap,b=new WeakMap;var ee=o=>o!=null,Q=o=>typeof o=="string",Z=o=>Q(o)&&o!=="",ae=o=>typeof o=="object"&&typeof o.type=="string"&&typeof o.stream=="function"&&typeof o.arrayBuffer=="function"&&typeof o.constructor=="function"&&typeof o.constructor.name=="string"&&/^(Blob|File)$/.test(o.constructor.name)&&/^(Blob|File)$/.test(o[Symbol.toStringTag]),ge=o=>o instanceof ne,ye=o=>o>=200&&o<300,De=o=>{try{return btoa(o)}catch{return Buffer.from(o).toString("base64")}},fe=o=>{let e=[],t=(i,r)=>{e.push(`${encodeURIComponent(i)}=${encodeURIComponent(String(r))}`)},s=(i,r)=>{ee(r)&&(Array.isArray(r)?r.forEach(p=>{s(i,p)}):typeof r=="object"?Object.entries(r).forEach(([p,a])=>{s(`${i}[${p}]`,a)}):t(i,r))};return Object.entries(o).forEach(([i,r])=>{s(i,r)}),e.length>0?`?${e.join("&")}`:""},be=(o,e)=>{let t=o.ENCODE_PATH||encodeURI,s=e.url.replace("{api-version}",o.VERSION).replace(/{(.*?)}/g,(r,p)=>e.path?.hasOwnProperty(p)?t(String(e.path[p])):r),i=`${o.BASE}${s}`;return e.query?`${i}${fe(e.query)}`:i},Ie=o=>{if(o.formData){let e=new ne,t=(s,i)=>{Q(i)||ae(i)?e.append(s,i):e.append(s,JSON.stringify(i))};return Object.entries(o.formData).filter(([s,i])=>ee(i)).forEach(([s,i])=>{Array.isArray(i)?i.forEach(r=>t(s,r)):t(s,i)}),e}},W=async(o,e)=>typeof e=="function"?e(o):e,Re=async(o,e,t)=>{let[s,i,r,p]=await Promise.all([W(e,o.TOKEN),W(e,o.USERNAME),W(e,o.PASSWORD),W(e,o.HEADERS)]),a=typeof t?.getHeaders=="function"&&t?.getHeaders()||{},u=Object.entries({Accept:"application/json",...p,...e.headers,...a}).filter(([y,d])=>ee(d)).reduce((y,[d,v])=>({...y,[d]:String(v)}),{});if(Z(s)&&(u.Authorization=`Bearer ${s}`),Z(i)&&Z(r)){let y=De(`${i}:${r}`);u.Authorization=`Basic ${y}`}return e.body&&(e.mediaType?u["Content-Type"]=e.mediaType:ae(e.body)?u["Content-Type"]=e.body.type||"application/octet-stream":Q(e.body)?u["Content-Type"]="text/plain":ge(e.body)||(u["Content-Type"]="application/json")),u},ve=o=>{if(o.body)return o.body},Ce=async(o,e,t,s,i,r,p,a)=>{let u=ie.CancelToken.source(),y={url:t,headers:r,data:s??i,method:e.method,withCredentials:o.WITH_CREDENTIALS,cancelToken:u.token};p(()=>u.cancel("The user aborted a request."));try{return await a.request(y)}catch(d){let v=d;if(v.response)return v.response;throw d}},Pe=(o,e)=>{if(e){let t=o.headers[e];if(Q(t))return t}},qe=o=>{if(o.status!==204)return o.data},Se=(o,e)=>{let s={400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error",502:"Bad Gateway",503:"Service Unavailable",...o.errors}[e.status];if(s)throw new P(o,e,s);if(!e.ok){let i=e.status??"unknown",r=e.statusText??"unknown",p=(()=>{try{return JSON.stringify(e.body,null,2)}catch{return}})();throw new P(o,e,`Generic Error: status: ${i}; status text: ${r}; body: ${p}`)}},pe=(o,e,t=ie)=>new A(async(s,i,r)=>{try{let p=be(o,e),a=Ie(e),u=ve(e),y=await Re(o,e,a);if(!r.isCancelled){let d=await Ce(o,e,p,u,a,y,r,t),v=qe(d),ue=Pe(d,e.responseHeader),oe={url:p,ok:ye(d.status),status:d.status,statusText:d.statusText,body:ue??v};Se(e,oe),s(oe.body)}}catch(p){i(p)}});var K=class extends T{constructor(e){super(e)}request(e){return pe(this.config,e)}};var E=class{constructor(e){this.httpRequest=e}roboticsAgentControllerMoveToArea(e,t){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/move/{appId}/{room}",path:{appId:e,room:t}})}roboticsAgentControllerStatusDescription(e,t){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/status/{appId}/{robotId}",path:{appId:e,robotId:t}})}roboticsAgentControllerMove(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/relocate",body:e,mediaType:"application/json"})}roboticsAgentControllerInitialPose(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/initialpose",body:e,mediaType:"application/json"})}roboticsAgentControllerActuate(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/actuate",body:e,mediaType:"application/json"})}roboticsAgentControllerStatus(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/status",body:e,mediaType:"application/json"})}};var k=class{constructor(e){this.httpRequest=e}whoami(){return this.httpRequest.request({method:"GET",url:"/api/auth/whoami",errors:{401:"Not authorized"}})}login(e){return this.httpRequest.request({method:"POST",url:"/api/auth/login",body:e,mediaType:"application/json",errors:{401:"Not authorized"}})}register(e){return this.httpRequest.request({method:"POST",url:"/api/auth/register",body:e,mediaType:"application/json"})}refreshToken(e){return this.httpRequest.request({method:"POST",url:"/api/auth/refresh",body:e,mediaType:"application/json",errors:{401:"Not authorized"}})}edit(e,t){return this.httpRequest.request({method:"PUT",url:"/api/auth/{userId}",path:{userId:e},body:t,mediaType:"application/json",errors:{401:"Not authorized"}})}delete(e){return this.httpRequest.request({method:"DELETE",url:"/api/auth/{userId}",path:{userId:e},errors:{401:"Not authorized"}})}authAdminControllerSaveUser(e){return this.httpRequest.request({method:"POST",url:"/api/auth/admin/user",body:e,mediaType:"application/json"})}};var x=class{constructor(e){this.httpRequest=e}detectionControllerSentimentAnalysis(e){return this.httpRequest.request({method:"POST",url:"/api/detection/sentiment-analysis",body:e,mediaType:"application/json"})}detectionControllerInteractionIntention(e){return this.httpRequest.request({method:"POST",url:"/api/detection/interaction",body:e,mediaType:"application/json"})}detectionControllerSendFrame(e,t,s){return this.httpRequest.request({method:"POST",url:"/api/detection/{appId}/{cameraId}/frame",path:{appId:e,cameraId:t},formData:s,mediaType:"multipart/form-data"})}detectionControllerServe(e,t,s){return this.httpRequest.request({method:"GET",url:"/api/detection/{appId}/{cameraId}/camera",path:{appId:e,cameraId:t},query:{overlay:s}})}};var U=class{constructor(e){this.httpRequest=e}save(e){return this.httpRequest.request({method:"PUT",url:"/api/dialogue/document",body:e,mediaType:"application/json"})}import(e){return this.httpRequest.request({method:"POST",url:"/api/dialogue/document",body:e,mediaType:"application/json"})}remove(e,t){return this.httpRequest.request({method:"DELETE",url:"/api/dialogue/document/{appId}",path:{appId:e},query:{documentId:t}})}speak(e){return this.httpRequest.request({method:"POST",url:"/api/dialogue/speech/tts",body:e,mediaType:"application/json"})}text(e,t,s,i,r,p,a){return this.httpRequest.request({method:"POST",url:"/api/dialogue/speech/stt/{appId}/{sessionId}",path:{appId:e,sessionId:t},query:{language:s,gender:i,llm:r,sampleRate:p},formData:a,mediaType:"multipart/form-data"})}chatMessage(e,t,s,i,r,p,a){return this.httpRequest.request({method:"POST",url:"/api/dialogue/speech/chat/{appId}/{sessionId}",path:{appId:e,sessionId:t},query:{language:s,gender:i,llm:r,actor:p},body:a,mediaType:"application/json"})}stopAgentSpeech(e,t){return this.httpRequest.request({method:"POST",url:"/api/dialogue/speech/stop/{appId}/{sessionId}",path:{appId:e,sessionId:t}})}import1(){return this.httpRequest.request({method:"POST",url:"/api/dialogue/admin/document"})}};var O=class{constructor(e){this.httpRequest=e}getUserSettings(){return this.httpRequest.request({method:"GET",url:"/api/platorm/topics/user"})}getSettings(){return this.httpRequest.request({method:"GET",url:"/api/platorm/topics"})}getClientAccessToken(e){return this.httpRequest.request({method:"POST",url:"/api/platform/token",body:e,mediaType:"application/json"})}getClientAccessToken1(e){return this.httpRequest.request({method:"POST",url:"/api/platform/token/access_token",body:e,mediaType:"application/json"})}getClientRefreshToken(e){return this.httpRequest.request({method:"POST",url:"/api/platform/token/refresh",body:e,mediaType:"application/json"})}getClientRefreshToken1(e){return this.httpRequest.request({method:"POST",url:"/api/platform/token/refresh_token",body:e,mediaType:"application/json"})}platformAppControllerListApps(){return this.httpRequest.request({method:"GET",url:"/api/app"})}createApp(e){return this.httpRequest.request({method:"POST",url:"/api/app",body:e,mediaType:"application/json"})}updateApp(e){return this.httpRequest.request({method:"PUT",url:"/api/app",body:e,mediaType:"application/json"})}listUserApps(){return this.httpRequest.request({method:"GET",url:"/api/app/list"})}updateAppTools(e,t){return this.httpRequest.request({method:"PUT",url:"/api/app/{appId}/tools",path:{appId:e},body:t,mediaType:"application/json"})}updateAppSettings(e,t){return this.httpRequest.request({method:"PUT",url:"/api/app/{appId}/settings",path:{appId:e},body:t,mediaType:"application/json"})}getAppRepository(e){return this.httpRequest.request({method:"GET",url:"/api/app/{appId}/repository",path:{appId:e}})}getAppRepositoryRobots(e,t){return this.httpRequest.request({method:"GET",url:"/api/app/{appId}/repository/robots",path:{appId:e},query:{name:t}})}getAppRepositoryAvatars(e,t){return this.httpRequest.request({method:"GET",url:"/api/app/{appId}/repository/avatars",path:{appId:e},query:{name:t}})}getAppRepositoryBackgrounds(e,t){return this.httpRequest.request({method:"GET",url:"/api/app/{appId}/repository/backgrounds",path:{appId:e},query:{name:t}})}readApp(e){return this.httpRequest.request({method:"GET",url:"/api/app/{appId}",path:{appId:e}})}removeApp(e){return this.httpRequest.request({method:"DELETE",url:"/api/app/{appId}",path:{appId:e}})}importApps(e,t){return this.httpRequest.request({method:"POST",url:"/api/app/admin/import",query:{skipClients:e},body:t,mediaType:"application/json"})}exportApps(e){return this.httpRequest.request({method:"POST",url:"/api/app/admin/export",body:e,mediaType:"application/json"})}removeApps(e){return this.httpRequest.request({method:"POST",url:"/api/app/admin/remove",body:e,mediaType:"application/json"})}createClient(e,t){return this.httpRequest.request({method:"POST",url:"/api/platform/app/{appId}/client",path:{appId:e},body:t,mediaType:"application/json"})}readClient(e,t){return this.httpRequest.request({method:"GET",url:"/api/platform/app/{appId}/client/{clientId}",path:{appId:e,clientId:t}})}removeClient(e,t){return this.httpRequest.request({method:"DELETE",url:"/api/platform/app/{appId}/client/{clientId}",path:{clientId:e,appId:t}})}listTopics(e,t){return this.httpRequest.request({method:"GET",url:"/api/platform/app/{appId}/client/{clientId}/topics",path:{appId:e,clientId:t}})}saveAppModule(e,t){return this.httpRequest.request({method:"POST",url:"/api/platform/app/{appId}/module",path:{appId:e},body:t,mediaType:"application/json"})}getAppModule(e,t){return this.httpRequest.request({method:"GET",url:"/api/platform/app/{appId}/module/{moduleId}",path:{appId:e,moduleId:t}})}removeAppModule(e,t){return this.httpRequest.request({method:"DELETE",url:"/api/platform/app/{appId}/module/{moduleId}",path:{appId:e,moduleId:t}})}savePlatformModule(e){return this.httpRequest.request({method:"POST",url:"/api/platform/module",body:e,mediaType:"application/json"})}refreshPlatformModule(e){return this.httpRequest.request({method:"HEAD",url:"/api/platform/module/{moduleId}",path:{moduleId:e}})}getPlatformModule(e){return this.httpRequest.request({method:"GET",url:"/api/platform/module/{moduleId}",path:{moduleId:e}})}removePlatformModule(e){return this.httpRequest.request({method:"DELETE",url:"/api/platform/module/{moduleId}",path:{moduleId:e}})}dataLoggerControllerGetLogs(e,t){return this.httpRequest.request({method:"POST",url:"/api/datalogger/get/{appId}",path:{appId:e},body:t,mediaType:"application/json"})}};var M=class{constructor(e){this.httpRequest=e}roboticsAgentControllerMoveToArea(e,t){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/move/{appId}/{room}",path:{appId:e,room:t}})}roboticsAgentControllerStatusDescription(e,t){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/status/{appId}/{robotId}",path:{appId:e,robotId:t}})}roboticsAgentControllerMove(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/relocate",body:e,mediaType:"application/json"})}roboticsAgentControllerInitialPose(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/initialpose",body:e,mediaType:"application/json"})}roboticsAgentControllerActuate(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/actuate",body:e,mediaType:"application/json"})}roboticsAgentControllerStatus(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/status",body:e,mediaType:"application/json"})}navigationControllerSave(){return this.httpRequest.request({method:"POST",url:"/api/robotics/navigation/{appId}"})}navigationControllerRemove(e){return this.httpRequest.request({method:"DELETE",url:"/api/robotics/navigation/{appId}/spaceId",path:{spaceId:e}})}navigationControllerGetById(e){return this.httpRequest.request({method:"GET",url:"/api/robotics/navigation/{appId}/{spaceId}",path:{spaceId:e}})}navigationControllerGetStatus(e,t){return this.httpRequest.request({method:"GET",url:"/api/robotics/navigation/{appId}/status/{robotId}",path:{appId:e,robotId:t}})}};var B=class{constructor(e){this.httpRequest=e}sessionControllerRead(e){return this.httpRequest.request({method:"GET",url:"/api/session/{sessionId}",path:{sessionId:e}})}sessionControllerDelete(e){return this.httpRequest.request({method:"DELETE",url:"/api/session/{sessionId}",path:{sessionId:e}})}sessionControllerCreate(e){return this.httpRequest.request({method:"POST",url:"/api/session",body:e,mediaType:"application/json"})}sessionControllerUpdate(e){return this.httpRequest.request({method:"PUT",url:"/api/session",body:e,mediaType:"application/json"})}agentUpdate(e){return this.httpRequest.request({method:"POST",url:"/api/session/agent",body:e,mediaType:"application/json"})}saveStore(e){return this.httpRequest.request({method:"POST",url:"/api/session/storage",body:e,mediaType:"application/json",errors:{401:"Unauthorized"}})}getStore(e){return this.httpRequest.request({method:"GET",url:"/api/session/storage/{storageId}",path:{storageId:e},errors:{401:"Unauthorized"}})}searchStore(e){return this.httpRequest.request({method:"POST",url:"/api/session/storage/search",body:e,mediaType:"application/json",errors:{401:"Unauthorized"}})}support(e){return this.httpRequest.request({method:"POST",url:"/api/session/support",body:e,mediaType:"application/json",errors:{401:"unauthorized"}})}};var w=class{constructor(e){this.httpRequest=e}notifyInteraction(e,t,s){return this.httpRequest.request({method:"PUT",url:"/api/ui/interaction/{appId}/{moduleId}",path:{appId:e,moduleId:t},body:s,mediaType:"application/json",errors:{401:"unauthorized"}})}showContent(e){return this.httpRequest.request({method:"GET",url:"/api/ui/asset/{appId}",body:e,mediaType:"application/json",errors:{401:"unauthorized"}})}uiModelControllerMapBlendShapes(e){return this.httpRequest.request({method:"POST",url:"/api/ui/model/map-blend-shapes",body:e,mediaType:"application/json",errors:{401:"unauthorized"}})}};var L=class{constructor(e){this.httpRequest=e}xrMarkerControllerSearchMarker(e){return this.httpRequest.request({method:"POST",url:"/api/xr/marker/search",body:e,mediaType:"application/json",errors:{401:"unauthorized"}})}xrMarkerControllerSaveMarker(e){return this.httpRequest.request({method:"PUT",url:"/api/xr/marker",body:e,mediaType:"application/json",errors:{401:"Unauthorized"}})}xrMarkerControllerDeleteMarker(e){return this.httpRequest.request({method:"DELETE",url:"/api/xr/marker/{markerId}",path:{":markerId":e},errors:{401:"Unauthorized"}})}xrMarkerControllerGetMarkerQrCode(e){return this.httpRequest.request({method:"GET",url:"/api/xr/marker/{markerId}",path:{":markerId":e},errors:{401:"Unauthorized"}})}xrOcclusionControllerOcclusion(){return this.httpRequest.request({method:"GET",url:"/api/xr/occlusion",errors:{401:"Unauthorized"}})}};var R=class{constructor(e,t=K){n(this,"agent");n(this,"authentication");n(this,"detection");n(this,"dialogue");n(this,"platform");n(this,"robotics");n(this,"session");n(this,"ui");n(this,"xr");n(this,"request");this.request=new t({BASE:e?.BASE??"",VERSION:e?.VERSION??"1.0",WITH_CREDENTIALS:e?.WITH_CREDENTIALS??!1,CREDENTIALS:e?.CREDENTIALS??"include",TOKEN:e?.TOKEN,USERNAME:e?.USERNAME,PASSWORD:e?.PASSWORD,HEADERS:e?.HEADERS,ENCODE_PATH:e?.ENCODE_PATH}),this.agent=new E(this.request),this.authentication=new k(this.request),this.detection=new x(this.request),this.dialogue=new U(this.request),this.platform=new O(this.request),this.robotics=new M(this.request),this.session=new B(this.request),this.ui=new w(this.request),this.xr=new L(this.request)}};var so=(o=1e3)=>new Promise(e=>setTimeout(()=>e(),o)),le="prod.sermas.spindoxlabs.it",io=async o=>{o.logger&&se(o.logger);let e=new te(o);return o.access_token&&await e.init(),e},te=class o{constructor(e){this.config=e;n(this,"logger",new C(o.name));n(this,"api");n(this,"events");n(this,"broker");n(this,"apiUrl");n(this,"mqttUrl");n(this,"refreshTimeout");n(this,"ready",!1);n(this,"jwt");n(this,"params",{});let t=e.domain||le;!e.domain&&e.env&&(t=le.replace("prod.",`${e.env}.`)),this.config.domain=t,this.apiUrl=`https://${t}`,this.mqttUrl=`wss://${t}:443/mqtt`}async init(e=!1){if(e&&(this.ready=!1),this.ready)return;this.api?this.api.request.config.TOKEN=this.config.access_token:this.api=new R({BASE:this.apiUrl,TOKEN:this.config.access_token}),this.broker?this.broker.setToken(this.config.access_token):(this.params={appId:this.config.appId},this.broker=new V({url:this.mqttUrl,username:this.config.access_token,password:"api-client",params:this.params}),await this.broker.connect()),this.events=new S(this.broker);let t=Te(this.config.access_token);this.jwt=t;let s=(t.exp-10)*1e3-Date.now();this.refreshTimeout&&clearTimeout(this.refreshTimeout),this.refreshTimeout=setTimeout(()=>this.refreshToken(),s),this.ready=!0}async refreshToken(){this.logger.log("Refreshing token");let e;try{e=await this.api.platform.getClientRefreshToken({refreshToken:this.config.refresh_token,appId:this.config.appId})}catch(t){this.logger.error(`Refresh token failed: ${t.stack}`);return}return this.logger.debug(`Expires in ${e.expires_in*1e3-Date.now()/1e3/60/60}min`),this.config.access_token=e.access_token,this.config.refresh_token=e.refresh_token,await this.init(!0),e}async loadToken(e,t,s){let i=new R({BASE:this.apiUrl});this.config.appId=s||this.config.appId;let r=await i.platform.getClientAccessToken({clientId:e,clientSecret:t,appId:this.config.appId});return this.logger.debug(`Expires in ${r.expires_in*1e3-Date.now()/1e3/60/60}min`),this.config.access_token=r.access_token,this.config.refresh_token=r.refresh_token,await this.init(!0),r}async login(e,t,s){let i=new R({BASE:this.apiUrl});this.config.appId=s||this.config.appId;let r=await i.authentication.login({username:e,password:t,appId:this.config.appId});return this.config.access_token=r.access_token,this.config.refresh_token=r.refresh_token,await this.init(!0),r}};export{te as SermasApiClient,io as createSermasClient,so as sleep};
|
|
1
|
+
var de=Object.defineProperty;var ce=(o,e,t)=>e in o?de(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var n=(o,e,t)=>(ce(o,typeof e!="symbol"?e+"":e,t),t),re=(o,e,t)=>{if(!e.has(o))throw TypeError("Cannot "+t)};var l=(o,e,t)=>(re(o,e,"read from private field"),t?t.call(o):e.get(o)),f=(o,e,t)=>{if(e.has(o))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(o):e.set(o,t)},c=(o,e,t,r)=>(re(o,e,"write to private field"),r?r.call(o,t):e.set(o,t),t);import{jwtDecode as Te}from"jwt-decode";var j=class{constructor(e){this.broker=e}async tokenRequested(e,t){return this.broker.publish("app/:appId/platform/token",e,t)}async onTokenRequested(e,t){return this.broker.subscribe("app/:appId/platform/token",e,t)}async appChanged(e,t){return this.broker.publish("app/:appId/platform/app/changed/:appId",e,t)}async onAppChanged(e,t){return this.broker.subscribe("app/:appId/platform/app/changed/:appId",e,t)}async clientChanged(e,t){return this.broker.publish("app/:appId/platform/client/changed/:clientId",e,t)}async onClientChanged(e,t){return this.broker.subscribe("app/:appId/platform/client/changed/:clientId",e,t)}async appModuleChanged(e,t){return this.broker.publish("app/:appId/platform/module",e,t)}async onAppModuleChanged(e,t){return this.broker.subscribe("app/:appId/platform/module",e,t)}};var H=class{constructor(e){this.broker=e}async moduleChanged(e,t){return this.broker.publish("system/platform/module/changed/:moduleId",e,t)}async onModuleChanged(e,t){return this.broker.subscribe("system/platform/module/changed/:moduleId",e,t)}};var N=class{constructor(e){this.broker=e}async userUpdate(e,t){return this.broker.publish("app/:appId/auth/update",e,t)}async onUserUpdate(e,t){return this.broker.subscribe("app/:appId/auth/update",e,t)}async userRegistration(e,t){return this.broker.publish("app/:appId/auth/create",e,t)}async onUserRegistration(e,t){return this.broker.subscribe("app/:appId/auth/create",e,t)}async userLogin(e,t){return this.broker.publish("app/:appId/auth/login",e,t)}async onUserLogin(e,t){return this.broker.subscribe("app/:appId/auth/login",e,t)}};var _=class{constructor(e){this.broker=e}async userDetected(e,t){return this.broker.publish("app/:appId/detection/user",e,t)}async onUserDetected(e,t){return this.broker.subscribe("app/:appId/detection/user",e,t)}async interactionIntention(e,t){return this.broker.publish("app/:appId/detection/interaction",e,t)}async onInteractionIntention(e,t){return this.broker.subscribe("app/:appId/detection/interaction",e,t)}async userCharacterization(e,t){return this.broker.publish("app/:appId/detection/characterization",e,t)}async onUserCharacterization(e,t){return this.broker.subscribe("app/:appId/detection/characterization",e,t)}async audioClassification(e,t){return this.broker.publish("app/:appId/detection/audio",e,t)}async onAudioClassification(e,t){return this.broker.subscribe("app/:appId/detection/audio",e,t)}async objectDetected(e,t){return this.broker.publish("app/:appId/detection/object",e,t)}async onObjectDetected(e,t){return this.broker.subscribe("app/:appId/detection/object",e,t)}async qrCodeDetected(e,t){return this.broker.publish("app/:appId/detection/qr_code",e,t)}async onQrCodeDetected(e,t){return this.broker.subscribe("app/:appId/detection/qr_code",e,t)}async noise(e,t){return this.broker.publish("app/:appId/detection/noise",e,t)}async onNoise(e,t){return this.broker.subscribe("app/:appId/detection/noise",e,t)}};var X=class{constructor(e){this.broker=e}async toolTriggered(e,t){return this.broker.publish("app/:appId/dialogue/tool/:name",e,t)}async onToolTriggered(e,t){return this.broker.subscribe("app/:appId/dialogue/tool/:name",e,t)}async dialogueMessages(e,t){return this.broker.publish("app/:appId/dialogue/messages",e,t)}async onDialogueMessages(e,t){return this.broker.subscribe("app/:appId/dialogue/messages",e,t)}async agentSpeech(e,t){return this.broker.publish("app/:appId/dialogue/speech/:sessionId/:chunkId",e,t)}async onAgentSpeech(e,t){return this.broker.subscribe("app/:appId/dialogue/speech/:sessionId/:chunkId",e,t)}};var z=class{constructor(e){this.broker=e}async userInteraction(e,t){return this.broker.publish("app/:appId/session/interaction/user",e,t)}async onUserInteraction(e,t){return this.broker.subscribe("app/:appId/session/interaction/user",e,t)}async sessionChanged(e,t){return this.broker.publish("app/:appId/session/session/changed/:sessionId",e,t)}async onSessionChanged(e,t){return this.broker.subscribe("app/:appId/session/session/changed/:sessionId",e,t)}async agentInteraction(e,t){return this.broker.publish("app/:appId/session/interaction/agent",e,t)}async onAgentInteraction(e,t){return this.broker.subscribe("app/:appId/session/interaction/agent",e,t)}async agentChanged(e,t){return this.broker.publish("app/:appId/session/agent/changed/:agentId",e,t)}async onAgentChanged(e,t){return this.broker.subscribe("app/:appId/session/agent/changed/:agentId",e,t)}async storageUpdated(e,t){return this.broker.publish("app/:appId/session/storage/:storageId",e,t)}async onStorageUpdated(e,t){return this.broker.subscribe("app/:appId/session/storage/:storageId",e,t)}async support(e,t){return this.broker.publish("app/:appId/session/support",e,t)}async onSupport(e,t){return this.broker.subscribe("app/:appId/session/support",e,t)}};var G=class{constructor(e){this.broker=e}async assetChange(e,t){return this.broker.publish("app/:appId/ui/status",e,t)}async onAssetChange(e,t){return this.broker.subscribe("app/:appId/ui/status",e,t)}async content(e,t){return this.broker.publish("app/:appId/ui/content",e,t)}async onContent(e,t){return this.broker.subscribe("app/:appId/ui/content",e,t)}async interaction(e,t){return this.broker.publish("app/:appId/ui/interaction/:moduleId",e,t)}async onInteraction(e,t){return this.broker.subscribe("app/:appId/ui/interaction/:moduleId",e,t)}};var $=class{constructor(e){this.broker=e}async detected(e,t){return this.broker.publish("app/:appId/xr/marker/detected",e,t)}async onDetected(e,t){return this.broker.subscribe("app/:appId/xr/marker/detected",e,t)}async changed(e,t){return this.broker.publish("app/:appId/xr/marker/changed/:markerId",e,t)}async onChanged(e,t){return this.broker.subscribe("app/:appId/xr/marker/changed/:markerId",e,t)}async occluded(e,t){return this.broker.publish("app/:appId/xr/occlusion",e,t)}async onOccluded(e,t){return this.broker.subscribe("app/:appId/xr/occlusion",e,t)}};var J=class{constructor(e){this.broker=e}async actuate(e,t){return this.broker.publish("app/:appId/robotics/actuate",e,t)}async onActuate(e,t){return this.broker.subscribe("app/:appId/robotics/actuate",e,t)}async move(e,t){return this.broker.publish("app/:appId/robotics/move",e,t)}async onMove(e,t){return this.broker.subscribe("app/:appId/robotics/move",e,t)}async robotStatus(e,t){return this.broker.publish("app/:appId/robotics/status",e,t)}async onRobotStatus(e,t){return this.broker.subscribe("app/:appId/robotics/status",e,t)}async initialPose(e,t){return this.broker.publish("app/:appId/robotics/initialpose",e,t)}async onInitialPose(e,t){return this.broker.subscribe("app/:appId/robotics/initialpose",e,t)}};var S=class{constructor(e){this.broker=e;n(this,"platform");n(this,"module");n(this,"auth");n(this,"detection");n(this,"dialogue");n(this,"session");n(this,"ui");n(this,"xr");n(this,"robotics");this.platform=new j(e),this.module=new H(e),this.auth=new N(e),this.detection=new _(e),this.dialogue=new X(e),this.session=new z(e),this.ui=new G(e),this.xr=new $(e),this.robotics=new J(e)}};import he from"mqtt";var Y,se=o=>{Y=o},me=(o="logger")=>new class{format(e){return`[${o}] ${e}`}debug(e,...t){console.debug(this.format(e))}error(e,...t){console.error(this.format(e))}fatal(e,...t){console.error(this.format(e))}log(e,...t){console.info(this.format(e))}setLogLevels(e){}verbose(e,...t){console.debug(this.format(e))}warn(e,...t){console.warn(this.format(e))}},C=class{constructor(e){n(this,"logger");this.logger=Y||me(e)}debug(e,...t){this.logger.debug(e)}error(e,...t){this.logger.error(e)}fatal(e,...t){this.logger.error(e)}log(e,...t){(this.logger.info||this.logger.log).apply(this.logger,[e])}setLogLevels(e){}verbose(e,...t){this.logger.verbose(e)}warn(e,...t){this.logger.warn(e)}};var F=class o{constructor(e){this.config=e;n(this,"logger",new C(o.name));n(this,"client");n(this,"subscriptions",[])}async setToken(e){this.logger.debug("Token updated, reconnecting"),this.client.options.username=e,this.client.reconnect()}async connect(){if(this.client)try{this.client.end(!0)}catch{}finally{this.client=void 0}this.client=await he.connectAsync(this.config.url,{username:this.config.username,password:this.config.password}),this.client.on("connect",()=>{}),this.client.on("error",e=>{this.logger.error(`mqtt client error ${e.stack}`)}),this.client.on("message",(e,t)=>{let r=t;try{r=JSON.parse(t.toString())}catch{}this.logger.debug(`MSG ${e}`);let i=e.indexOf("#");i>-1&&(e=e.substring(0,i));let s=this.parseTopic(e),p=a=>a==="+";this.subscriptions.forEach(a=>{if(a.type===s.type&&!(!p(a.appId)&&a.appId!==s.appId)&&!(!p(a.resource)&&a.resource!==s.resource)&&!(!p(a.scope)&&a.scope!==s.scope)){for(let u in s.context||[])if(!p(a.context[u])&&a.context[u]!==s.context[u])return;a.callback(r)}})})}parseTopic(e){let t=e.split("/"),[r,i,s,p]=t,a=t.slice(3);return{type:r,appId:i,resource:s,scope:p,context:a}}async subscribe(e,t,r){return e=this.replaceTopicParams(e,{...r||{}}),this.subscriptions.push({...this.parseTopic(e),topic:e,callback:t}),this.logger.debug(`SUB ${e}`),await this.client.subscribeAsync(e),()=>{let i=this.subscriptions.findIndex(s=>s.topic===e&&s.callback===t);i>-1&&(this.subscriptions.splice(i,1),this.subscriptions.filter(s=>s.topic===e).length===1&&this.client.unsubscribe(e))}}async publish(e,t,r){let i=t.byteLength!==void 0,s;i?s=t:s=JSON.stringify(t);try{e=this.replaceTopicParams(e,{...i?{}:t,...r||{}}),await this.client.publishAsync(e,s)}catch{return!1}return!0}replaceTopicParams(e,t){t={...this.config?.params||{},...t||{}};for(let r of Object.keys(t)){let i=`:${r}`,s=t[r];if(s!=null){if(typeof s=="object"&&!Array.isArray(s)){e=this.replaceTopicParams(e,s);continue}if(!(typeof s!="string"&&typeof s!="number"))for(;e.indexOf(i)>-1;)e=e.replace(i,s.toString())}}return e=e.split("/").map(r=>r[0]===":"?"+":r).join("/"),e}};var T=class{constructor(e){this.config=e}};import ie from"axios";import ne from"form-data";var P=class extends Error{constructor(t,r,i){super(i);n(this,"url");n(this,"status");n(this,"statusText");n(this,"body");n(this,"request");this.name="ApiError",this.url=r.url,this.status=r.status,this.statusText=r.statusText,this.body=r.body,this.request=t}};var V=class extends Error{constructor(e){super(e),this.name="CancelError"}get isCancelled(){return!0}},h,g,m,D,I,q,b,A=class{constructor(e){f(this,h,void 0);f(this,g,void 0);f(this,m,void 0);f(this,D,void 0);f(this,I,void 0);f(this,q,void 0);f(this,b,void 0);c(this,h,!1),c(this,g,!1),c(this,m,!1),c(this,D,[]),c(this,I,new Promise((t,r)=>{c(this,q,t),c(this,b,r);let i=a=>{l(this,h)||l(this,g)||l(this,m)||(c(this,h,!0),l(this,q)&&l(this,q).call(this,a))},s=a=>{l(this,h)||l(this,g)||l(this,m)||(c(this,g,!0),l(this,b)&&l(this,b).call(this,a))},p=a=>{l(this,h)||l(this,g)||l(this,m)||l(this,D).push(a)};return Object.defineProperty(p,"isResolved",{get:()=>l(this,h)}),Object.defineProperty(p,"isRejected",{get:()=>l(this,g)}),Object.defineProperty(p,"isCancelled",{get:()=>l(this,m)}),e(i,s,p)}))}get[Symbol.toStringTag](){return"Cancellable Promise"}then(e,t){return l(this,I).then(e,t)}catch(e){return l(this,I).catch(e)}finally(e){return l(this,I).finally(e)}cancel(){if(!(l(this,h)||l(this,g)||l(this,m))){if(c(this,m,!0),l(this,D).length)try{for(let e of l(this,D))e()}catch(e){console.warn("Cancellation threw an error",e);return}l(this,D).length=0,l(this,b)&&l(this,b).call(this,new V("Request aborted"))}}get isCancelled(){return l(this,m)}};h=new WeakMap,g=new WeakMap,m=new WeakMap,D=new WeakMap,I=new WeakMap,q=new WeakMap,b=new WeakMap;var ee=o=>o!=null,Q=o=>typeof o=="string",Z=o=>Q(o)&&o!=="",ae=o=>typeof o=="object"&&typeof o.type=="string"&&typeof o.stream=="function"&&typeof o.arrayBuffer=="function"&&typeof o.constructor=="function"&&typeof o.constructor.name=="string"&&/^(Blob|File)$/.test(o.constructor.name)&&/^(Blob|File)$/.test(o[Symbol.toStringTag]),ge=o=>o instanceof ne,ye=o=>o>=200&&o<300,fe=o=>{try{return btoa(o)}catch{return Buffer.from(o).toString("base64")}},De=o=>{let e=[],t=(i,s)=>{e.push(`${encodeURIComponent(i)}=${encodeURIComponent(String(s))}`)},r=(i,s)=>{ee(s)&&(Array.isArray(s)?s.forEach(p=>{r(i,p)}):typeof s=="object"?Object.entries(s).forEach(([p,a])=>{r(`${i}[${p}]`,a)}):t(i,s))};return Object.entries(o).forEach(([i,s])=>{r(i,s)}),e.length>0?`?${e.join("&")}`:""},be=(o,e)=>{let t=o.ENCODE_PATH||encodeURI,r=e.url.replace("{api-version}",o.VERSION).replace(/{(.*?)}/g,(s,p)=>e.path?.hasOwnProperty(p)?t(String(e.path[p])):s),i=`${o.BASE}${r}`;return e.query?`${i}${De(e.query)}`:i},Ie=o=>{if(o.formData){let e=new ne,t=(r,i)=>{Q(i)||ae(i)?e.append(r,i):e.append(r,JSON.stringify(i))};return Object.entries(o.formData).filter(([r,i])=>ee(i)).forEach(([r,i])=>{Array.isArray(i)?i.forEach(s=>t(r,s)):t(r,i)}),e}},W=async(o,e)=>typeof e=="function"?e(o):e,Re=async(o,e,t)=>{let[r,i,s,p]=await Promise.all([W(e,o.TOKEN),W(e,o.USERNAME),W(e,o.PASSWORD),W(e,o.HEADERS)]),a=typeof t?.getHeaders=="function"&&t?.getHeaders()||{},u=Object.entries({Accept:"application/json",...p,...e.headers,...a}).filter(([y,d])=>ee(d)).reduce((y,[d,v])=>({...y,[d]:String(v)}),{});if(Z(r)&&(u.Authorization=`Bearer ${r}`),Z(i)&&Z(s)){let y=fe(`${i}:${s}`);u.Authorization=`Basic ${y}`}return e.body&&(e.mediaType?u["Content-Type"]=e.mediaType:ae(e.body)?u["Content-Type"]=e.body.type||"application/octet-stream":Q(e.body)?u["Content-Type"]="text/plain":ge(e.body)||(u["Content-Type"]="application/json")),u},ve=o=>{if(o.body)return o.body},Ce=async(o,e,t,r,i,s,p,a)=>{let u=ie.CancelToken.source(),y={url:t,headers:s,data:r??i,method:e.method,withCredentials:o.WITH_CREDENTIALS,cancelToken:u.token};p(()=>u.cancel("The user aborted a request."));try{return await a.request(y)}catch(d){let v=d;if(v.response)return v.response;throw d}},Pe=(o,e)=>{if(e){let t=o.headers[e];if(Q(t))return t}},qe=o=>{if(o.status!==204)return o.data},Se=(o,e)=>{let r={400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error",502:"Bad Gateway",503:"Service Unavailable",...o.errors}[e.status];if(r)throw new P(o,e,r);if(!e.ok){let i=e.status??"unknown",s=e.statusText??"unknown",p=(()=>{try{return JSON.stringify(e.body,null,2)}catch{return}})();throw new P(o,e,`Generic Error: status: ${i}; status text: ${s}; body: ${p}`)}},pe=(o,e,t=ie)=>new A(async(r,i,s)=>{try{let p=be(o,e),a=Ie(e),u=ve(e),y=await Re(o,e,a);if(!s.isCancelled){let d=await Ce(o,e,p,u,a,y,s,t),v=qe(d),ue=Pe(d,e.responseHeader),oe={url:p,ok:ye(d.status),status:d.status,statusText:d.statusText,body:ue??v};Se(e,oe),r(oe.body)}}catch(p){i(p)}});var K=class extends T{constructor(e){super(e)}request(e){return pe(this.config,e)}};var E=class{constructor(e){this.httpRequest=e}roboticsAgentControllerMoveToArea(e,t){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/move/{appId}/{room}",path:{appId:e,room:t}})}roboticsAgentControllerStatusDescription(e,t){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/status/{appId}/{robotId}",path:{appId:e,robotId:t}})}roboticsAgentControllerMove(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/relocate",body:e,mediaType:"application/json"})}roboticsAgentControllerInitialPose(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/initialpose",body:e,mediaType:"application/json"})}roboticsAgentControllerActuate(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/actuate",body:e,mediaType:"application/json"})}roboticsAgentControllerStatus(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/status",body:e,mediaType:"application/json"})}};var k=class{constructor(e){this.httpRequest=e}whoami(){return this.httpRequest.request({method:"GET",url:"/api/auth/whoami",errors:{401:"Not authorized"}})}login(e){return this.httpRequest.request({method:"POST",url:"/api/auth/login",body:e,mediaType:"application/json",errors:{401:"Not authorized"}})}register(e){return this.httpRequest.request({method:"POST",url:"/api/auth/register",body:e,mediaType:"application/json"})}refreshToken(e){return this.httpRequest.request({method:"POST",url:"/api/auth/refresh",body:e,mediaType:"application/json",errors:{401:"Not authorized"}})}edit(e,t){return this.httpRequest.request({method:"PUT",url:"/api/auth/{userId}",path:{userId:e},body:t,mediaType:"application/json",errors:{401:"Not authorized"}})}delete(e){return this.httpRequest.request({method:"DELETE",url:"/api/auth/{userId}",path:{userId:e},errors:{401:"Not authorized"}})}authAdminControllerSaveUser(e){return this.httpRequest.request({method:"POST",url:"/api/auth/admin/user",body:e,mediaType:"application/json"})}};var x=class{constructor(e){this.httpRequest=e}detectionControllerSentimentAnalysis(e){return this.httpRequest.request({method:"POST",url:"/api/detection/sentiment-analysis",body:e,mediaType:"application/json"})}detectionControllerInteractionIntention(e){return this.httpRequest.request({method:"POST",url:"/api/detection/interaction",body:e,mediaType:"application/json"})}detectionControllerSendFrame(e,t,r){return this.httpRequest.request({method:"POST",url:"/api/detection/{appId}/{cameraId}/frame",path:{appId:e,cameraId:t},formData:r,mediaType:"multipart/form-data"})}detectionControllerServe(e,t,r){return this.httpRequest.request({method:"GET",url:"/api/detection/{appId}/{cameraId}/camera",path:{appId:e,cameraId:t},query:{overlay:r}})}};var U=class{constructor(e){this.httpRequest=e}save(e){return this.httpRequest.request({method:"PUT",url:"/api/dialogue/document",body:e,mediaType:"application/json"})}import(e){return this.httpRequest.request({method:"POST",url:"/api/dialogue/document",body:e,mediaType:"application/json"})}remove(e,t){return this.httpRequest.request({method:"DELETE",url:"/api/dialogue/document/{appId}",path:{appId:e},query:{documentId:t}})}speak(e){return this.httpRequest.request({method:"POST",url:"/api/dialogue/speech/tts",body:e,mediaType:"application/json"})}text(e,t,r,i,s,p,a){return this.httpRequest.request({method:"POST",url:"/api/dialogue/speech/stt/{appId}/{sessionId}",path:{appId:e,sessionId:t},query:{language:r,gender:i,llm:s,sampleRate:p},formData:a,mediaType:"multipart/form-data"})}chatMessage(e,t,r,i,s,p,a){return this.httpRequest.request({method:"POST",url:"/api/dialogue/speech/chat/{appId}/{sessionId}",path:{appId:e,sessionId:t},query:{language:r,gender:i,llm:s,actor:p},body:a,mediaType:"application/json"})}stopAgentSpeech(e,t){return this.httpRequest.request({method:"POST",url:"/api/dialogue/speech/stop/{appId}/{sessionId}",path:{appId:e,sessionId:t}})}import1(){return this.httpRequest.request({method:"POST",url:"/api/dialogue/admin/document"})}};var O=class{constructor(e){this.httpRequest=e}getUserSettings(){return this.httpRequest.request({method:"GET",url:"/api/platorm/topics/user"})}getSettings(){return this.httpRequest.request({method:"GET",url:"/api/platorm/topics"})}getClientAccessToken(e){return this.httpRequest.request({method:"POST",url:"/api/platform/token",body:e,mediaType:"application/json"})}getClientAccessToken1(e){return this.httpRequest.request({method:"POST",url:"/api/platform/token/access_token",body:e,mediaType:"application/json"})}getClientRefreshToken(e){return this.httpRequest.request({method:"POST",url:"/api/platform/token/refresh",body:e,mediaType:"application/json"})}getClientRefreshToken1(e){return this.httpRequest.request({method:"POST",url:"/api/platform/token/refresh_token",body:e,mediaType:"application/json"})}platformAppControllerListApps(){return this.httpRequest.request({method:"GET",url:"/api/app"})}createApp(e){return this.httpRequest.request({method:"POST",url:"/api/app",body:e,mediaType:"application/json"})}updateApp(e){return this.httpRequest.request({method:"PUT",url:"/api/app",body:e,mediaType:"application/json"})}listUserApps(){return this.httpRequest.request({method:"GET",url:"/api/app/list"})}updateAppTools(e,t){return this.httpRequest.request({method:"PUT",url:"/api/app/{appId}/tools",path:{appId:e},body:t,mediaType:"application/json"})}updateAppSettings(e,t){return this.httpRequest.request({method:"PUT",url:"/api/app/{appId}/settings",path:{appId:e},body:t,mediaType:"application/json"})}getAppRepository(e){return this.httpRequest.request({method:"GET",url:"/api/app/{appId}/repository",path:{appId:e}})}getAppRepositoryRobots(e,t){return this.httpRequest.request({method:"GET",url:"/api/app/{appId}/repository/robots",path:{appId:e},query:{name:t}})}getAppRepositoryAvatars(e,t){return this.httpRequest.request({method:"GET",url:"/api/app/{appId}/repository/avatars",path:{appId:e},query:{name:t}})}getAppRepositoryBackgrounds(e,t){return this.httpRequest.request({method:"GET",url:"/api/app/{appId}/repository/backgrounds",path:{appId:e},query:{name:t}})}readApp(e){return this.httpRequest.request({method:"GET",url:"/api/app/{appId}",path:{appId:e}})}removeApp(e){return this.httpRequest.request({method:"DELETE",url:"/api/app/{appId}",path:{appId:e}})}importApps(e,t){return this.httpRequest.request({method:"POST",url:"/api/app/admin/import",query:{skipClients:e},body:t,mediaType:"application/json"})}exportApps(e){return this.httpRequest.request({method:"POST",url:"/api/app/admin/export",body:e,mediaType:"application/json"})}removeApps(e){return this.httpRequest.request({method:"POST",url:"/api/app/admin/remove",body:e,mediaType:"application/json"})}createClient(e,t){return this.httpRequest.request({method:"POST",url:"/api/platform/app/{appId}/client",path:{appId:e},body:t,mediaType:"application/json"})}readClient(e,t){return this.httpRequest.request({method:"GET",url:"/api/platform/app/{appId}/client/{clientId}",path:{appId:e,clientId:t}})}removeClient(e,t){return this.httpRequest.request({method:"DELETE",url:"/api/platform/app/{appId}/client/{clientId}",path:{clientId:e,appId:t}})}listTopics(e,t){return this.httpRequest.request({method:"GET",url:"/api/platform/app/{appId}/client/{clientId}/topics",path:{appId:e,clientId:t}})}saveAppModule(e,t){return this.httpRequest.request({method:"POST",url:"/api/platform/app/{appId}/module",path:{appId:e},body:t,mediaType:"application/json"})}getAppModule(e,t){return this.httpRequest.request({method:"GET",url:"/api/platform/app/{appId}/module/{moduleId}",path:{appId:e,moduleId:t}})}removeAppModule(e,t){return this.httpRequest.request({method:"DELETE",url:"/api/platform/app/{appId}/module/{moduleId}",path:{appId:e,moduleId:t}})}savePlatformModule(e){return this.httpRequest.request({method:"POST",url:"/api/platform/module",body:e,mediaType:"application/json"})}refreshPlatformModule(e){return this.httpRequest.request({method:"HEAD",url:"/api/platform/module/{moduleId}",path:{moduleId:e}})}getPlatformModule(e){return this.httpRequest.request({method:"GET",url:"/api/platform/module/{moduleId}",path:{moduleId:e}})}removePlatformModule(e){return this.httpRequest.request({method:"DELETE",url:"/api/platform/module/{moduleId}",path:{moduleId:e}})}dataLoggerControllerGetLogs(e,t){return this.httpRequest.request({method:"POST",url:"/api/datalogger/get/{appId}",path:{appId:e},body:t,mediaType:"application/json"})}};var M=class{constructor(e){this.httpRequest=e}roboticsAgentControllerMoveToArea(e,t){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/move/{appId}/{room}",path:{appId:e,room:t}})}roboticsAgentControllerStatusDescription(e,t){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/status/{appId}/{robotId}",path:{appId:e,robotId:t}})}roboticsAgentControllerMove(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/relocate",body:e,mediaType:"application/json"})}roboticsAgentControllerInitialPose(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/initialpose",body:e,mediaType:"application/json"})}roboticsAgentControllerActuate(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/actuate",body:e,mediaType:"application/json"})}roboticsAgentControllerStatus(e){return this.httpRequest.request({method:"POST",url:"/api/robotics/agent/status",body:e,mediaType:"application/json"})}navigationControllerSave(){return this.httpRequest.request({method:"POST",url:"/api/robotics/navigation/{appId}"})}navigationControllerRemove(e){return this.httpRequest.request({method:"DELETE",url:"/api/robotics/navigation/{appId}/spaceId",path:{spaceId:e}})}navigationControllerGetById(e){return this.httpRequest.request({method:"GET",url:"/api/robotics/navigation/{appId}/{spaceId}",path:{spaceId:e}})}navigationControllerGetStatus(e,t){return this.httpRequest.request({method:"GET",url:"/api/robotics/navigation/{appId}/status/{robotId}",path:{appId:e,robotId:t}})}};var B=class{constructor(e){this.httpRequest=e}sessionControllerRead(e){return this.httpRequest.request({method:"GET",url:"/api/session/{sessionId}",path:{sessionId:e}})}sessionControllerDelete(e){return this.httpRequest.request({method:"DELETE",url:"/api/session/{sessionId}",path:{sessionId:e}})}sessionControllerCreate(e){return this.httpRequest.request({method:"POST",url:"/api/session",body:e,mediaType:"application/json"})}sessionControllerUpdate(e){return this.httpRequest.request({method:"PUT",url:"/api/session",body:e,mediaType:"application/json"})}agentUpdate(e){return this.httpRequest.request({method:"POST",url:"/api/session/agent",body:e,mediaType:"application/json"})}saveStore(e){return this.httpRequest.request({method:"POST",url:"/api/session/storage",body:e,mediaType:"application/json",errors:{401:"Unauthorized"}})}getStore(e){return this.httpRequest.request({method:"GET",url:"/api/session/storage/{storageId}",path:{storageId:e},errors:{401:"Unauthorized"}})}searchStore(e){return this.httpRequest.request({method:"POST",url:"/api/session/storage/search",body:e,mediaType:"application/json",errors:{401:"Unauthorized"}})}support(e){return this.httpRequest.request({method:"POST",url:"/api/session/support",body:e,mediaType:"application/json",errors:{401:"unauthorized"}})}};var w=class{constructor(e){this.httpRequest=e}notifyInteraction(e,t,r){return this.httpRequest.request({method:"PUT",url:"/api/ui/interaction/{appId}/{moduleId}",path:{appId:e,moduleId:t},body:r,mediaType:"application/json",errors:{401:"unauthorized"}})}showContent(e){return this.httpRequest.request({method:"GET",url:"/api/ui/asset/{appId}",body:e,mediaType:"application/json",errors:{401:"unauthorized"}})}uiModelControllerMapBlendShapes(e){return this.httpRequest.request({method:"POST",url:"/api/ui/model/map-blend-shapes",body:e,mediaType:"application/json",errors:{401:"unauthorized"}})}};var L=class{constructor(e){this.httpRequest=e}xrMarkerControllerSearchMarker(e){return this.httpRequest.request({method:"POST",url:"/api/xr/marker/search",body:e,mediaType:"application/json",errors:{401:"unauthorized"}})}xrMarkerControllerSaveMarker(e){return this.httpRequest.request({method:"PUT",url:"/api/xr/marker",body:e,mediaType:"application/json",errors:{401:"Unauthorized"}})}xrMarkerControllerDeleteMarker(e){return this.httpRequest.request({method:"DELETE",url:"/api/xr/marker/{markerId}",path:{":markerId":e},errors:{401:"Unauthorized"}})}xrMarkerControllerGetMarkerQrCode(e){return this.httpRequest.request({method:"GET",url:"/api/xr/marker/{markerId}",path:{":markerId":e},errors:{401:"Unauthorized"}})}xrOcclusionControllerOcclusion(){return this.httpRequest.request({method:"GET",url:"/api/xr/occlusion",errors:{401:"Unauthorized"}})}};var R=class{constructor(e,t=K){n(this,"agent");n(this,"authentication");n(this,"detection");n(this,"dialogue");n(this,"platform");n(this,"robotics");n(this,"session");n(this,"ui");n(this,"xr");n(this,"request");this.request=new t({BASE:e?.BASE??"",VERSION:e?.VERSION??"1.0",WITH_CREDENTIALS:e?.WITH_CREDENTIALS??!1,CREDENTIALS:e?.CREDENTIALS??"include",TOKEN:e?.TOKEN,USERNAME:e?.USERNAME,PASSWORD:e?.PASSWORD,HEADERS:e?.HEADERS,ENCODE_PATH:e?.ENCODE_PATH}),this.agent=new E(this.request),this.authentication=new k(this.request),this.detection=new x(this.request),this.dialogue=new U(this.request),this.platform=new O(this.request),this.robotics=new M(this.request),this.session=new B(this.request),this.ui=new w(this.request),this.xr=new L(this.request)}};var io=(o=1e3)=>new Promise(e=>setTimeout(()=>e(),o)),le="prod.sermas.spindoxlabs.it",no=async o=>{o.logger&&se(o.logger);let e=new te(o);return o.access_token&&await e.init(),e},te=class o{constructor(e){this.config=e;n(this,"logger",new C(o.name));n(this,"api");n(this,"events");n(this,"broker");n(this,"apiUrl");n(this,"mqttUrl");n(this,"refreshTimeout");n(this,"ready",!1);n(this,"jwt");n(this,"params",{});let t=e.domain||le;!e.domain&&e.env&&(t=le.replace("prod.",`${e.env}.`)),this.config.domain=t,this.apiUrl=`https://${t}`,this.mqttUrl=`wss://${t}:443/mqtt`}async init(e=!1){if(e&&(this.ready=!1),this.ready)return;this.api?this.api.request.config.TOKEN=this.config.access_token:this.api=new R({BASE:this.apiUrl,TOKEN:this.config.access_token}),this.broker?this.broker.setToken(this.config.access_token):(this.params={appId:this.config.appId},this.broker=new F({url:this.mqttUrl,username:this.config.access_token,password:"api-client",params:this.params}),await this.broker.connect()),this.events=new S(this.broker);let t=Te(this.config.access_token);this.jwt=t,this.config.clientId=this.config.clientId||t.aud;let i=new Date(t.exp*1e3).getTime()-Date.now()-30*1e3;this.logger.verbose(`Token expires in ${Math.round(i/1e3/60/60)}min`),this.refreshTimeout&&clearTimeout(this.refreshTimeout),this.refreshTimeout=setTimeout(()=>this.refreshToken(),i),this.ready=!0}async refreshToken(){this.logger.verbose("Refreshing token");let e;try{e=await this.api.platform.getClientRefreshToken({refreshToken:this.config.refresh_token,appId:this.config.appId,clientId:this.config.clientId,clientSecret:this.config.clientSecret})}catch(t){this.logger.error(`Refresh token failed: ${t.stack}`);return}if(!e){this.logger.warn("Failed to refresh token, no response");return}return this.config.access_token=e.access_token,this.config.refresh_token=e.refresh_token,await this.init(!0),e}async loadToken(e,t,r){let i=new R({BASE:this.apiUrl});this.config.appId=r||this.config.appId;let s=await i.platform.getClientAccessToken({clientId:e,clientSecret:t,appId:this.config.appId});return this.config.clientId=e,this.config.clientSecret=t,this.config.appId=r||this.config.appId,this.config.access_token=s.access_token,this.config.refresh_token=s.refresh_token,await this.init(!0),s}async setToken(e,t){if(typeof e!="string"){let r=e;e=r.access_token,t=r.refresh_token}this.config.access_token=e,this.config.refresh_token=t,await this.init(!0)}async login(e,t,r){let i=new R({BASE:this.apiUrl});this.config.appId=r||this.config.appId;let s=await i.authentication.login({username:e,password:t,appId:this.config.appId});return this.config.access_token=s.access_token,this.config.refresh_token=s.refresh_token,await this.init(!0),s}};export{te as SermasApiClient,no as createSermasClient,io as sleep};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|