@automata-network/pom-js-sdk
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -12,3 +12,2 @@ import { POMSocket, getSocket, SocketConnectionResult } from '@automata-network/pom-socket'; | ||
data: T; | ||
success?: boolean; | ||
error?: string; | ||
@@ -15,0 +14,0 @@ id?: string; |
@@ -19,3 +19,2 @@ import { POMSocket } from '@automata-network/pom-socket'; | ||
data: T; | ||
success?: boolean; | ||
error?: string; | ||
@@ -22,0 +21,0 @@ id?: string; |
@@ -1,2 +0,2 @@ | ||
"use strict";var t,e=require("@automata-network/pom-socket");exports.POMOperation=void 0,(t=exports.POMOperation||(exports.POMOperation={})).GetIdentityStatus="getIdentityStatus",t.AttestDevice="attestDevice",t.SignMessage="signMessage";const r=new Error("operation is cancelled"),o=new Error("need retry");function n(t){const{id:r=e.createRandomString(6),success:o=!0}=t;return{id:r,data:JSON.stringify({id:r,success:o,...t})}}function s(t){return JSON.parse(t)}exports.ERR_NEED_RETRY=o,exports.ERR_OPERATION_CANCELLED=r,exports.decodeMessageData=s,exports.encodeMessageData=n,exports.runWithErrorRetry=async function(t,e){const{signal:r,maxRetry:n=5,throttleInterval:s=3e3,backoffStrategyFactor:a,timeoutError:i}=e||{};let c=0,u=!0,d=!1;for(r?.addEventListener("abort",(function t(){d=!0,r?.removeEventListener("abort",t)}));u&&!d;){u=!1;try{return await t({retryCount:c})}catch(t){if(t===o&&c<n&&!d){c+=1,u=!0,await new Promise((t=>{setTimeout((()=>{t()}),s*(a?c*a:1))}));continue}throw t}}throw i||new Error("runWithErrorRetry no result")},exports.sendMessageAndWaitForResponse=function(t){const{socket:e,op:o,data:a,resolver:i,rejecter:c}=t,u=n({op:o,data:a});function d(t){e.off(p),c(t)}const p={success(t){try{const r=s(t);r.id===u.id&&r.op===o&&(r.success?(e.off(p),i(r.data)):d(new Error(r.error||"Unknown error")))}catch(t){d(t)}},error:d};return e.on(p),e.send(u.data),()=>{d(r)}}; | ||
"use strict";var e,t=require("@automata-network/pom-socket");exports.POMOperation=void 0,(e=exports.POMOperation||(exports.POMOperation={})).GetIdentityStatus="getIdentityStatus",e.AttestDevice="attestDevice",e.SignMessage="signMessage";const r=new Error("operation is cancelled"),o=new Error("need retry");function n(e){const{id:r=t.createRandomString(6),error:o}=e;return{id:r,data:JSON.stringify({id:r,success:null==o,error:o,...e})}}function s(e){return JSON.parse(e)}exports.ERR_NEED_RETRY=o,exports.ERR_OPERATION_CANCELLED=r,exports.decodeMessageData=s,exports.encodeMessageData=n,exports.runWithErrorRetry=async function(e,t){const{signal:r,maxRetry:n=5,throttleInterval:s=3e3,backoffStrategyFactor:a,timeoutError:i}=t||{};let c=0,u=!0,d=!1;for(r?.addEventListener("abort",(function e(){d=!0,r?.removeEventListener("abort",e)}));u&&!d;){u=!1;try{return await e({retryCount:c})}catch(e){if(e===o&&c<n&&!d){c+=1,u=!0,await new Promise((e=>{setTimeout((()=>{e()}),s*(a?c*a:1))}));continue}throw e}}throw i||new Error("runWithErrorRetry no result")},exports.sendMessageAndWaitForResponse=function(e){const{socket:t,op:o,data:a,resolver:i,rejecter:c}=e,u=n({op:o,data:a});function d(e){t.off(p),c(e)}const p={success(e){try{const r=s(e);r.id===u.id&&r.op===o&&(r.success?(t.off(p),i(r.data)):d(new Error(r.error||"Unknown error")))}catch(e){d(e)}},error:d};return t.on(p),t.send(u.data),()=>{d(r)}}; | ||
//# sourceMappingURL=util.js.map |
{ | ||
"name": "@automata-network/pom-js-sdk", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "A socket clinet for automata's Proof Of Machinehood", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -65,9 +65,11 @@ import {POMSocket, createRandomString} from '@automata-network/pom-socket'; | ||
data: T; | ||
success?: boolean; | ||
error?: string; | ||
id?: string; | ||
}) { | ||
const {id = createRandomString(6), success = true} = options; | ||
const {id = createRandomString(6), error} = options; | ||
return {id, data: JSON.stringify({id, success, ...options})}; | ||
return { | ||
id, | ||
data: JSON.stringify({id, success: error == null, error, ...options}), | ||
}; | ||
} | ||
@@ -74,0 +76,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
41387