@calimero-network/mero-js 2.0.0-beta.1 → 2.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.
Files changed (204) hide show
  1. package/README.md +358 -341
  2. package/dist/admin-api/admin-client.d.ts +90 -0
  3. package/dist/admin-api/admin-client.d.ts.map +1 -0
  4. package/dist/admin-api/admin-client.js +302 -0
  5. package/dist/admin-api/admin-client.js.map +1 -0
  6. package/dist/admin-api/admin-factory.d.ts +8 -0
  7. package/dist/admin-api/admin-factory.d.ts.map +1 -0
  8. package/dist/admin-api/admin-factory.js +42 -0
  9. package/dist/admin-api/admin-factory.js.map +1 -0
  10. package/dist/admin-api/admin-types.d.ts +497 -0
  11. package/dist/admin-api/admin-types.d.ts.map +1 -0
  12. package/dist/admin-api/admin-types.js +4 -0
  13. package/dist/admin-api/admin-types.js.map +1 -0
  14. package/dist/admin-api/index.d.ts +4 -0
  15. package/dist/admin-api/index.d.ts.map +1 -0
  16. package/dist/admin-api/index.js +5 -0
  17. package/dist/admin-api/index.js.map +1 -0
  18. package/dist/auth/index.d.ts +26 -0
  19. package/dist/auth/index.d.ts.map +1 -0
  20. package/dist/auth/index.js +51 -0
  21. package/dist/auth/index.js.map +1 -0
  22. package/dist/auth-api/auth-client.d.ts +34 -0
  23. package/dist/auth-api/auth-client.d.ts.map +1 -0
  24. package/dist/auth-api/auth-client.js +112 -0
  25. package/dist/auth-api/auth-client.js.map +1 -0
  26. package/dist/auth-api/auth-factory.d.ts +8 -0
  27. package/dist/auth-api/auth-factory.d.ts.map +1 -0
  28. package/dist/auth-api/auth-factory.js +42 -0
  29. package/dist/auth-api/auth-factory.js.map +1 -0
  30. package/dist/auth-api/auth-types.d.ts +127 -0
  31. package/dist/auth-api/auth-types.d.ts.map +1 -0
  32. package/dist/auth-api/auth-types.js +3 -0
  33. package/dist/auth-api/auth-types.js.map +1 -0
  34. package/dist/auth-api/index.d.ts +4 -0
  35. package/dist/auth-api/index.d.ts.map +1 -0
  36. package/dist/auth-api/index.js +5 -0
  37. package/dist/auth-api/index.js.map +1 -0
  38. package/dist/cloud/cloud-client.d.ts +20 -0
  39. package/dist/cloud/cloud-client.d.ts.map +1 -0
  40. package/dist/cloud/cloud-client.js +26 -0
  41. package/dist/cloud/cloud-client.js.map +1 -0
  42. package/dist/cloud/index.d.ts +3 -0
  43. package/dist/cloud/index.d.ts.map +1 -0
  44. package/dist/cloud/index.js +2 -0
  45. package/dist/cloud/index.js.map +1 -0
  46. package/dist/events/index.d.ts +5 -0
  47. package/dist/events/index.d.ts.map +1 -0
  48. package/dist/events/index.js +3 -0
  49. package/dist/events/index.js.map +1 -0
  50. package/dist/events/sse.d.ts +41 -0
  51. package/dist/events/sse.d.ts.map +1 -0
  52. package/dist/events/sse.js +237 -0
  53. package/dist/events/sse.js.map +1 -0
  54. package/dist/events/ws.d.ts +42 -0
  55. package/dist/events/ws.d.ts.map +1 -0
  56. package/dist/events/ws.js +178 -0
  57. package/dist/events/ws.js.map +1 -0
  58. package/dist/http-client/api-response.d.ts +16 -0
  59. package/dist/http-client/api-response.d.ts.map +1 -0
  60. package/dist/http-client/api-response.js +2 -0
  61. package/dist/http-client/api-response.js.map +1 -0
  62. package/dist/http-client/index.d.ts +1 -1
  63. package/dist/http-client/index.d.ts.map +1 -1
  64. package/dist/http-client/index.js +1 -2
  65. package/dist/http-client/index.js.map +1 -1
  66. package/dist/http-client/web-client.d.ts +3 -3
  67. package/dist/http-client/web-client.d.ts.map +1 -1
  68. package/dist/http-client/web-client.js +6 -18
  69. package/dist/http-client/web-client.js.map +1 -1
  70. package/dist/index.browser.mjs +2 -1
  71. package/dist/index.browser.mjs.map +4 -4
  72. package/dist/index.cjs +1033 -1415
  73. package/dist/index.cjs.map +4 -4
  74. package/dist/index.d.ts +12 -8
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +15 -7
  77. package/dist/index.js.map +1 -1
  78. package/dist/index.mjs +1032 -1420
  79. package/dist/index.mjs.map +4 -4
  80. package/dist/mero-js.d.ts +44 -189
  81. package/dist/mero-js.d.ts.map +1 -1
  82. package/dist/mero-js.js +139 -314
  83. package/dist/mero-js.js.map +1 -1
  84. package/dist/rpc/index.d.ts +22 -0
  85. package/dist/rpc/index.d.ts.map +1 -0
  86. package/dist/rpc/index.js +38 -0
  87. package/dist/rpc/index.js.map +1 -0
  88. package/dist/token-store/index.d.ts +20 -0
  89. package/dist/token-store/index.d.ts.map +1 -0
  90. package/dist/token-store/index.js +62 -0
  91. package/dist/token-store/index.js.map +1 -0
  92. package/package.json +7 -42
  93. package/dist/api/admin/aliases.d.ts +0 -54
  94. package/dist/api/admin/aliases.d.ts.map +0 -1
  95. package/dist/api/admin/aliases.js +0 -43
  96. package/dist/api/admin/aliases.js.map +0 -1
  97. package/dist/api/admin/applications.d.ts +0 -52
  98. package/dist/api/admin/applications.d.ts.map +0 -1
  99. package/dist/api/admin/applications.js +0 -31
  100. package/dist/api/admin/applications.js.map +0 -1
  101. package/dist/api/admin/blobs.d.ts +0 -24
  102. package/dist/api/admin/blobs.d.ts.map +0 -1
  103. package/dist/api/admin/blobs.js +0 -58
  104. package/dist/api/admin/blobs.js.map +0 -1
  105. package/dist/api/admin/capabilities.d.ts +0 -26
  106. package/dist/api/admin/capabilities.d.ts.map +0 -1
  107. package/dist/api/admin/capabilities.js +0 -13
  108. package/dist/api/admin/capabilities.js.map +0 -1
  109. package/dist/api/admin/client.d.ts +0 -63
  110. package/dist/api/admin/client.d.ts.map +0 -1
  111. package/dist/api/admin/client.js +0 -103
  112. package/dist/api/admin/client.js.map +0 -1
  113. package/dist/api/admin/contexts.d.ts +0 -110
  114. package/dist/api/admin/contexts.d.ts.map +0 -1
  115. package/dist/api/admin/contexts.js +0 -61
  116. package/dist/api/admin/contexts.js.map +0 -1
  117. package/dist/api/admin/factory.d.ts +0 -4
  118. package/dist/api/admin/factory.d.ts.map +0 -1
  119. package/dist/api/admin/factory.js +0 -5
  120. package/dist/api/admin/factory.js.map +0 -1
  121. package/dist/api/admin/identity.d.ts +0 -10
  122. package/dist/api/admin/identity.d.ts.map +0 -1
  123. package/dist/api/admin/identity.js +0 -10
  124. package/dist/api/admin/identity.js.map +0 -1
  125. package/dist/api/admin/index.d.ts +0 -23
  126. package/dist/api/admin/index.d.ts.map +0 -1
  127. package/dist/api/admin/index.js +0 -26
  128. package/dist/api/admin/index.js.map +0 -1
  129. package/dist/api/admin/network.d.ts +0 -10
  130. package/dist/api/admin/network.d.ts.map +0 -1
  131. package/dist/api/admin/network.js +0 -9
  132. package/dist/api/admin/network.js.map +0 -1
  133. package/dist/api/admin/proposals.d.ts +0 -49
  134. package/dist/api/admin/proposals.d.ts.map +0 -1
  135. package/dist/api/admin/proposals.js +0 -34
  136. package/dist/api/admin/proposals.js.map +0 -1
  137. package/dist/api/admin/public.d.ts +0 -15
  138. package/dist/api/admin/public.d.ts.map +0 -1
  139. package/dist/api/admin/public.js +0 -18
  140. package/dist/api/admin/public.js.map +0 -1
  141. package/dist/api/admin/tee.d.ts +0 -74
  142. package/dist/api/admin/tee.d.ts.map +0 -1
  143. package/dist/api/admin/tee.js +0 -16
  144. package/dist/api/admin/tee.js.map +0 -1
  145. package/dist/api/auth/client.d.ts +0 -55
  146. package/dist/api/auth/client.d.ts.map +0 -1
  147. package/dist/api/auth/client.js +0 -127
  148. package/dist/api/auth/client.js.map +0 -1
  149. package/dist/api/auth/factory.d.ts +0 -4
  150. package/dist/api/auth/factory.d.ts.map +0 -1
  151. package/dist/api/auth/factory.js +0 -5
  152. package/dist/api/auth/factory.js.map +0 -1
  153. package/dist/api/auth/index.d.ts +0 -4
  154. package/dist/api/auth/index.d.ts.map +0 -1
  155. package/dist/api/auth/index.js +0 -4
  156. package/dist/api/auth/index.js.map +0 -1
  157. package/dist/api/auth/types.d.ts +0 -94
  158. package/dist/api/auth/types.d.ts.map +0 -1
  159. package/dist/api/auth/types.js +0 -4
  160. package/dist/api/auth/types.js.map +0 -1
  161. package/dist/api/index.d.ts +0 -15
  162. package/dist/api/index.d.ts.map +0 -1
  163. package/dist/api/index.js +0 -18
  164. package/dist/api/index.js.map +0 -1
  165. package/dist/api/rpc/client.d.ts +0 -76
  166. package/dist/api/rpc/client.d.ts.map +0 -1
  167. package/dist/api/rpc/client.js +0 -126
  168. package/dist/api/rpc/client.js.map +0 -1
  169. package/dist/api/rpc/index.d.ts +0 -3
  170. package/dist/api/rpc/index.d.ts.map +0 -1
  171. package/dist/api/rpc/index.js +0 -2
  172. package/dist/api/rpc/index.js.map +0 -1
  173. package/dist/api/rpc/types.d.ts +0 -74
  174. package/dist/api/rpc/types.d.ts.map +0 -1
  175. package/dist/api/rpc/types.js +0 -6
  176. package/dist/api/rpc/types.js.map +0 -1
  177. package/dist/api/sse/client.d.ts +0 -76
  178. package/dist/api/sse/client.d.ts.map +0 -1
  179. package/dist/api/sse/client.js +0 -203
  180. package/dist/api/sse/client.js.map +0 -1
  181. package/dist/api/sse/index.d.ts +0 -4
  182. package/dist/api/sse/index.d.ts.map +0 -1
  183. package/dist/api/sse/index.js +0 -2
  184. package/dist/api/sse/index.js.map +0 -1
  185. package/dist/api/sse/types.d.ts +0 -35
  186. package/dist/api/sse/types.d.ts.map +0 -1
  187. package/dist/api/sse/types.js +0 -6
  188. package/dist/api/sse/types.js.map +0 -1
  189. package/dist/api/utils.d.ts +0 -68
  190. package/dist/api/utils.d.ts.map +0 -1
  191. package/dist/api/utils.js +0 -83
  192. package/dist/api/utils.js.map +0 -1
  193. package/dist/api/ws/client.d.ts +0 -72
  194. package/dist/api/ws/client.d.ts.map +0 -1
  195. package/dist/api/ws/client.js +0 -202
  196. package/dist/api/ws/client.js.map +0 -1
  197. package/dist/api/ws/index.d.ts +0 -4
  198. package/dist/api/ws/index.d.ts.map +0 -1
  199. package/dist/api/ws/index.js +0 -2
  200. package/dist/api/ws/index.js.map +0 -1
  201. package/dist/api/ws/types.d.ts +0 -32
  202. package/dist/api/ws/types.d.ts.map +0 -1
  203. package/dist/api/ws/types.js +0 -6
  204. package/dist/api/ws/types.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"web-client.js","sourceRoot":"","sources":["../../src/http-client/web-client.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErE,qCAAqC;AACrC,MAAM,OAAO,SAAU,SAAQ,KAAK;IAGlC,YACS,MAAc,EACd,UAAkB,EAClB,GAAW,EACX,OAAgB,EAChB,QAAiB;QAExB,KAAK,CAAC,QAAQ,MAAM,IAAI,UAAU,EAAE,CAAC,CAAC;QAN/B,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAQ;QAClB,QAAG,GAAH,GAAG,CAAQ;QACX,YAAO,GAAP,OAAO,CAAS;QAChB,aAAQ,GAAR,QAAQ,CAAS;QAPR,SAAI,GAAG,WAAoB,CAAC;IAU9C,CAAC;IAED,MAAM;QAOJ,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,OAAO,EAAE,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC;YACtC,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;IACJ,CAAC;CACF;AAED,+CAA+C;AAC/C,SAAS,eAAe,CAAC,OAAgB;IACvC,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAC7B,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,2CAA2C;AAC3C,MAAM,OAAO,aAAa;IAMxB,YAAoB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;QALxC,sEAAsE;QAC9D,wBAAmB,GAA2B,IAAI,CAAC;QAC3D,2EAA2E;QAC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IAAI;YACF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,OAAO,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;SAClE;QAAC,MAAM;YACN,OAAO,EAAE,CAAC;SACX;IACH,CAAC;CACF"}
@@ -1,2 +1,3 @@
1
- var ae=Object.defineProperty;var O=(r,e)=>{for(var t in e)ae(r,t,{get:e[t],enumerable:!0})};function J(r){let e=r.filter(Boolean);if(e.length===0)return;let t=AbortSignal;if(typeof t.any=="function")try{return t.any(e)}catch{}let s=new AbortController,o=i=>{s.abort(i.target.reason);for(let a of e)a.removeEventListener("abort",o)};for(let i of e){if(i.aborted)return AbortSignal.abort(i.reason);i.addEventListener("abort",o,{once:!0})}return s.signal}function V(r){if(typeof AbortSignal.timeout=="function")return AbortSignal.timeout(r);let e=new AbortController;return setTimeout(()=>{e.abort(new DOMException("Timeout","TimeoutError"))},r),e.signal}var b=class extends Error{constructor(t,s,o,i,a){super(`HTTP ${t} ${s}`);this.status=t;this.statusText=s;this.url=o;this.headers=i;this.bodyText=a;this.name="HTTPError"}toJSON(){return{status:this.status,statusText:this.statusText,url:this.url,headers:Q(this.headers),bodyText:this.bodyText}}};function Q(r){let e={};return r.forEach((t,s)=>{e[s]=t}),e}var $=class{constructor(e){this.transport=e;this.refreshTokenPromise=null;this.onTokenRefreshPromise=null}async get(e,t){return this.request(e,{...t,method:"GET"})}async post(e,t,s){let o=t?JSON.stringify(t):void 0;return e.includes("/refresh")&&(console.log("[HTTP POST /refresh] Body being sent:",o),console.log("[HTTP POST /refresh] Body type:",typeof t,t?Object.keys(t):"undefined")),this.request(e,{...s,method:"POST",body:o,headers:{"Content-Type":"application/json",...s?.headers}})}async put(e,t,s){return this.request(e,{...s,method:"PUT",body:t?JSON.stringify(t):void 0,headers:{"Content-Type":"application/json",...s?.headers}})}async delete(e,t){return this.request(e,{...t,method:"DELETE"})}async patch(e,t,s){return this.request(e,{...s,method:"PATCH",body:t?JSON.stringify(t):void 0,headers:{"Content-Type":"application/json",...s?.headers}})}async head(e,t){let s=await this.makeRequest(e,{...t,method:"HEAD",parse:"response"});return{headers:Q(s.headers),status:s.status}}async request(e,t){return this.makeRequest(e,t)}async makeRequest(e,t,s=0,o){let a=this.buildUrl(e),p=o??Date.now(),C=this.createAbortSignal(t),d=await this.buildHeaders(t?.headers),u;d instanceof Headers?(u={},d.forEach((l,_)=>{u[_]=l})):u=d;let c={method:t?.method||"GET",headers:u},H=t?.body instanceof ReadableStream||typeof t?.body=="object"&&t?.body!==null&&"getReader"in t.body&&!(t.body instanceof Blob);(t?.body!==void 0&&!H||t?.body!==void 0&&H&&s===0)&&(c.body=t.body);let q;if(s>0&&o!==void 0){let l=t?.timeoutMs||this.transport.timeoutMs;if(l){let _=Date.now()-p,D=Math.max(0,l-_);q=this.createAbortSignal({...t,timeoutMs:D})}else q=this.createAbortSignal(t)}else q=C;q&&(c.signal=q),this.transport.credentials!==void 0&&(c.credentials=this.transport.credentials),t?.mode!==void 0&&(c.mode=t.mode),t?.cache!==void 0&&(c.cache=t.cache),t?.redirect!==void 0&&(c.redirect=t.redirect),t?.referrer!==void 0&&(c.referrer=t.referrer),t?.referrerPolicy!==void 0&&(c.referrerPolicy=t.referrerPolicy),t?.integrity!==void 0&&(c.integrity=t.integrity),t?.keepalive!==void 0&&(c.keepalive=t.keepalive);try{let l=await this.transport.fetch(a,c);if(!l.ok){let _=await this.getBodyText(l),D=new b(l.status,l.statusText,a,l.headers,_),re=t?.signal?.aborted===!0,oe=l.headers.get("x-auth-error");if(l.status===401&&this.transport.refreshToken&&s<1&&!H&&!re&&this.transport.refreshToken){console.log("[mero-js] 401 received, attempting token refresh...",{hasAuthError:oe});try{let h=this.refreshTokenPromise;h||(h=this.transport.refreshToken(),this.refreshTokenPromise=h);let B=await h;if(!B||B.trim()==="")throw this.refreshTokenPromise=null,this.onTokenRefreshPromise=null,new Error("Refresh token returned empty token");if(!this.transport.onTokenRefresh)throw this.refreshTokenPromise=null,this.onTokenRefreshPromise=null,new Error("onTokenRefresh callback is required when refreshToken is provided. The callback must update the token storage so getAuthToken() returns the new token.");let U=this.onTokenRefreshPromise;U||(U=this.transport.onTokenRefresh(B),this.onTokenRefreshPromise=U),await U,this.refreshTokenPromise=null,this.onTokenRefreshPromise=null;let z=t?.timeoutMs||this.transport.timeoutMs;if(z&&o!==void 0){let ie=Date.now()-p;if(z-ie<=0)throw D}return this.makeRequest(e,t,s+1,p)}catch(h){throw this.refreshTokenPromise=null,this.onTokenRefreshPromise=null,console.log("[mero-js] Token refresh failed:",h),h instanceof Error&&h.message.includes("onTokenRefresh")?h:D}}throw D}return this.parseResponse(l,t?.parse)}catch(l){throw l instanceof b||l instanceof Error&&l.message.includes("onTokenRefresh")?l:new b(0,"Network Error",a,new Headers,l instanceof Error?l.message:"Unknown error")}}buildUrl(e){if(e.startsWith("http://")||e.startsWith("https://"))return e;let t=this.transport.baseUrl;return e.startsWith("/")?`${t.endsWith("/")?t.slice(0,-1):t}${e}`:`${t.endsWith("/")?t:`${t}/`}${e}`}createAbortSignal(e){let t=[];this.transport.defaultAbortSignal&&t.push(this.transport.defaultAbortSignal),e?.signal&&t.push(e.signal);let s=e?.timeoutMs||this.transport.timeoutMs;return s&&t.push(V(s)),t.length>0?J(t):void 0}async buildHeaders(e){let t={...this.transport.defaultHeaders};if(this.transport.getAuthToken)try{let s=await this.transport.getAuthToken();s&&s.trim()!==""&&(t.Authorization=`Bearer ${s}`)}catch{}return e&&(e instanceof Headers?e.forEach((s,o)=>{t[o]=s}):Array.isArray(e)?e.forEach(([s,o])=>{t[s]=o}):Object.assign(t,e)),t}async parseResponse(e,t){switch(t){case"text":return await e.text();case"blob":return await e.blob();case"arrayBuffer":return await e.arrayBuffer();case"response":return e;case"json":default:return await e.json()}}async getBodyText(e){try{let t=await e.text();return t.length>65536?t.slice(0,65536)+"...":t}catch{return""}}};function K(r){return new $(r)}function G(r){let e={fetch:(t,s)=>globalThis.fetch(t,s),baseUrl:r.baseUrl,getAuthToken:r.getAuthToken,onTokenRefresh:r.onTokenRefresh,refreshToken:r.refreshToken,defaultHeaders:r.defaultHeaders,timeoutMs:r.timeoutMs,credentials:r.credentials,defaultAbortSignal:r.defaultAbortSignal};return K(e)}function F(r){let e=r.fetch??globalThis.fetch;if(!e)throw new Error("No fetch implementation available. Please provide a fetch implementation (e.g., undici.fetch) or use Node.js 18+ which has native fetch support.");let s={fetch:e===globalThis.fetch?(o,i)=>globalThis.fetch(o,i):(o,i)=>e(o,i),baseUrl:r.baseUrl,getAuthToken:r.getAuthToken,onTokenRefresh:r.onTokenRefresh,refreshToken:r.refreshToken,defaultHeaders:r.defaultHeaders,timeoutMs:r.timeoutMs,credentials:r.credentials,defaultAbortSignal:r.defaultAbortSignal};return K(s)}function pe(r){return typeof window<"u"?G(r):F(r)}function le(r,e){if(e<=0)return!1;let s=r?.name;if(s==="TimeoutError")return!0;if(s==="AbortError")return!1;let o=r;if("status"in o&&typeof o.status=="number"){let i=o.status;return i>=500||i===429}return s==="TypeError"}function ce(r){let t=250*Math.pow(2,r-1),s=(Math.random()-.5)*.4*t;return Math.max(0,t+s)}async function X(r,e={}){let{attempts:t=3}=e,s;for(let o=1;o<=t;o++)try{return await r(o)}catch(i){if(s=i,!le(s,t-o))throw s;let a=ce(o),d=s.headers?.get?.("Retry-After");if(d){let u=parseInt(d,10);if(!isNaN(u))a=Math.max(a,u*1e3);else{let c=new Date(d);if(!isNaN(c.getTime())){let H=Math.max(0,c.getTime()-Date.now());a=Math.max(a,Math.min(H,6e4))}}}await new Promise(u=>setTimeout(u,a))}throw s||new Error("Retry failed without error")}function ue(r,e={}){return async(...t)=>X(()=>r(...t),e)}var Z={};O(Z,{AuthApiClient:()=>x,createAuthApiClient:()=>N});var j=class extends Error{constructor(e){super(e.message),this.name="ApiResponseError",this.type=e.type,this.code=e.code,this.data=e.data}};function Y(r){return typeof r=="object"&&r!==null&&"error"in r&&r.error!==null&&r.error!==void 0&&typeof r.error=="object"}async function n(r){let e=await r;if(Y(e))throw new j(e.error);if(e.data===null||e.data===void 0)throw new Error("Response data is null or undefined");return e.data}async function Ee(r){let e=await r;if(Y(e))throw new j(e.error);return e.data===null||e.data===void 0?null:e.data}var x=class{constructor(e,t){this.httpClient=e;this.embedded=t.embedded??!0}getAuthPath(e){return this.embedded?`/auth${e}`:e}async getLogin(){return this.httpClient.get(this.getAuthPath("/login"),{parse:"text"})}async getChallenge(){return n(this.httpClient.get(this.getAuthPath("/challenge")))}async getToken(e){return n(this.httpClient.post(this.getAuthPath("/token"),e))}async refreshToken(e){return n(this.httpClient.post(this.getAuthPath("/refresh"),e))}async getProviders(){return n(this.httpClient.get(this.getAuthPath("/providers")))}async getIdentity(){return n(this.httpClient.get(this.getAuthPath("/identity")))}async validateToken(e){let t=await this.httpClient.post(this.getAuthPath("/validate"),e);return t.data===""||t.data===void 0||t.data===null?{valid:!0}:typeof t.data=="object"&&"valid"in t.data?t.data:{valid:!0}}async validateTokenGet(e){let t=await this.httpClient.get(this.getAuthPath("/validate"),{headers:{Authorization:`Bearer ${e}`}});return t.data===""||t.data===void 0||t.data===null?{valid:!0}:typeof t.data=="object"&&"valid"in t.data?t.data:{valid:!0}}async getHealth(){return n(this.httpClient.get(this.getAuthPath("/health")))}async getCallback(e){let t=e?`?callback-url=${encodeURIComponent(e)}`:"";return this.httpClient.get(this.getAuthPath(`/callback${t}`),{parse:"text"})}async revokeToken(){return n(this.httpClient.post(this.getAuthPath("/admin/revoke"),{}))}async listRootKeys(){return n(this.httpClient.get(this.getAuthPath("/admin/keys")))}async createRootKey(e){return n(this.httpClient.post(this.getAuthPath("/admin/keys"),e))}async deleteRootKey(e){return n(this.httpClient.delete(this.getAuthPath(`/admin/keys/${e}`)))}async listClientKeys(){return n(this.httpClient.get(this.getAuthPath("/admin/keys/clients")))}async generateClientKey(e){return n(this.httpClient.post(this.getAuthPath("/admin/client-key"),e))}async deleteClientKey(e,t){return n(this.httpClient.delete(this.getAuthPath(`/admin/keys/${e}/clients/${t}`)))}async getKeyPermissions(e){return n(this.httpClient.get(this.getAuthPath(`/admin/keys/${e}/permissions`)))}async updateKeyPermissions(e,t){return n(this.httpClient.put(this.getAuthPath(`/admin/keys/${e}/permissions`),t))}async getProtectedIdentity(){return n(this.httpClient.get(this.getAuthPath("/admin/identity")))}async getMetrics(){return n(this.httpClient.get(this.getAuthPath("/admin/metrics")))}};function N(r,e){return new x(r,e)}var ee={};O(ee,{AdminApiClient:()=>m,AliasesApiClient:()=>I,ApplicationsApiClient:()=>k,BlobsApiClient:()=>E,CapabilitiesApiClient:()=>v,ContextsApiClient:()=>T,IdentityApiClient:()=>w,NetworkApiClient:()=>S,ProposalsApiClient:()=>P,PublicApiClient:()=>A,TeeApiClient:()=>W,createAdminApiClient:()=>M});var A=class{constructor(e){this.httpClient=e}async health(){return n(this.httpClient.get("/admin-api/health"))}async isAuthed(){return n(this.httpClient.get("/admin-api/is-authed"))}async getCertificate(){return this.httpClient.get("/admin-api/certificate",{parse:"text"})}};var k=class{constructor(e){this.httpClient=e}async installApplication(e){return n(this.httpClient.post("/admin-api/install-application",e))}async installDevApplication(e){return n(this.httpClient.post("/admin-api/install-dev-application",e))}async listApplications(){return n(this.httpClient.get("/admin-api/applications"))}async getApplication(e){return n(this.httpClient.get(`/admin-api/applications/${e}`))}async uninstallApplication(e){return n(this.httpClient.delete(`/admin-api/applications/${e}`))}async listPackages(){return n(this.httpClient.get("/admin-api/packages"))}async listVersions(e){return n(this.httpClient.get(`/admin-api/packages/${e}/versions`))}async getLatestVersion(e){return n(this.httpClient.get(`/admin-api/packages/${e}/latest`))}};var T=class{constructor(e){this.httpClient=e}async listContexts(){return n(this.httpClient.get("/admin-api/contexts"))}async createContext(e){return n(this.httpClient.post("/admin-api/contexts",e))}async getContext(e){return n(this.httpClient.get(`/admin-api/contexts/${e}`))}async deleteContext(e){return n(this.httpClient.delete(`/admin-api/contexts/${e}`))}async getContextStorage(e){return n(this.httpClient.get(`/admin-api/contexts/${e}/storage`))}async getContextIdentities(e){return n(this.httpClient.get(`/admin-api/contexts/${e}/identities`))}async getContextIdentitiesOwned(e){return n(this.httpClient.get(`/admin-api/contexts/${e}/identities-owned`))}async inviteToContext(e){return n(this.httpClient.post("/admin-api/contexts/invite",e))}async inviteToContextOpenInvitation(e){return n(this.httpClient.post("/admin-api/contexts/invite_by_open_invitation",e))}async inviteSpecializedNode(e){return n(this.httpClient.post("/admin-api/contexts/invite-specialized-node",e))}async joinContext(e){return n(this.httpClient.post("/admin-api/contexts/join",e))}async joinContextByOpenInvitation(e){return n(this.httpClient.post("/admin-api/contexts/join_by_open_invitation",e))}async updateContextApplication(e,t){return n(this.httpClient.put(`/admin-api/contexts/${e}/application`,t))}async getContextsForApplication(e){return n(this.httpClient.get(`/admin-api/contexts/for-application/${e}`))}async getContextsWithExecutorsForApplication(e){return n(this.httpClient.get(`/admin-api/contexts/with-executors/for-application/${e}`))}async getProxyContract(e){return n(this.httpClient.get(`/admin-api/contexts/${e}/proxy-contract`))}async syncContext(){return n(this.httpClient.post("/admin-api/contexts/sync",{}))}async syncContextById(e){return n(this.httpClient.post(`/admin-api/contexts/sync/${e}`,{}))}};var P=class{constructor(e){this.httpClient=e}async getProposals(e,t){return n(this.httpClient.post(`/admin-api/contexts/${e}/proposals`,t))}async getProposal(e,t){return n(this.httpClient.get(`/admin-api/contexts/${e}/proposals/${t}`))}async createAndApproveProposal(e,t){return n(this.httpClient.post(`/admin-api/contexts/${e}/proposals/create-and-approve`,t))}async approveProposal(e,t){return n(this.httpClient.post(`/admin-api/contexts/${e}/proposals/approve`,t))}async getNumberOfActiveProposals(e){return n(this.httpClient.get(`/admin-api/contexts/${e}/proposals/count`))}async getNumberOfProposalApprovals(e,t){return n(this.httpClient.get(`/admin-api/contexts/${e}/proposals/${t}/approvals/count`))}async getProposalApprovers(e,t){return n(this.httpClient.get(`/admin-api/contexts/${e}/proposals/${t}/approvals/users`))}async getContextValue(e,t){return n(this.httpClient.post(`/admin-api/contexts/${e}/proposals/get-context-value`,t))}async getContextStorageEntries(e,t){return n(this.httpClient.post(`/admin-api/contexts/${e}/proposals/context-storage-entries`,t))}};var v=class{constructor(e){this.httpClient=e}async grantPermission(e,t){return n(this.httpClient.post(`/admin-api/contexts/${e}/capabilities/grant`,t))}async revokePermission(e,t){return n(this.httpClient.post(`/admin-api/contexts/${e}/capabilities/revoke`,t))}};var w=class{constructor(e){this.httpClient=e}async generateContextIdentity(){return n(this.httpClient.post("/admin-api/identity/context",{}))}};var S=class{constructor(e){this.httpClient=e}async getPeersCount(){return this.httpClient.get("/admin-api/peers")}};var E=class{constructor(e){this.httpClient=e}async uploadBlob(e){let t=await n(this.httpClient.request("/admin-api/blobs",{method:"PUT",body:e,headers:{"Content-Type":"application/octet-stream"}}));return{blobId:t.blob_id,size:t.size,hash:t.hash??null}}async listBlobs(){return{blobs:(await n(this.httpClient.get("/admin-api/blobs"))).blobs.map(t=>({blobId:t.blob_id,size:t.size,hash:t.hash??null}))}}async getBlob(e){return this.httpClient.get(`/admin-api/blobs/${e}`,{parse:"blob"})}async getBlobInfo(e){let t=await this.httpClient.head(`/admin-api/blobs/${e}`);return{blobId:e,size:parseInt(t.headers["content-length"]||"0",10),hash:t.headers["x-blob-hash"]||null}}async deleteBlob(e){let t=await n(this.httpClient.delete(`/admin-api/blobs/${e}`));return{blobId:t.blob_id||t.blobId||e,deleted:t.deleted}}};var I=class{constructor(e){this.httpClient=e}async createContextAlias(e){return n(this.httpClient.post("/admin-api/alias/create/context",e))}async createApplicationAlias(e){return n(this.httpClient.post("/admin-api/alias/create/application",e))}async createIdentityAlias(e,t){return n(this.httpClient.post(`/admin-api/alias/create/identity/${e}`,t))}async lookupContextAlias(e){return n(this.httpClient.post(`/admin-api/alias/lookup/context/${e}`,{}))}async lookupApplicationAlias(e){return n(this.httpClient.post(`/admin-api/alias/lookup/application/${e}`,{}))}async lookupIdentityAlias(e,t){return n(this.httpClient.post(`/admin-api/alias/lookup/identity/${e}/${t}`,{}))}async listContextAliases(){return n(this.httpClient.get("/admin-api/alias/list/context"))}async listApplicationAliases(){return n(this.httpClient.get("/admin-api/alias/list/application"))}async listIdentityAliases(e){return n(this.httpClient.get(`/admin-api/alias/list/identity/${e}`))}async deleteContextAlias(e){return n(this.httpClient.post(`/admin-api/alias/delete/context/${e}`,{}))}async deleteApplicationAlias(e){return n(this.httpClient.post(`/admin-api/alias/delete/application/${e}`,{}))}async deleteIdentityAlias(e,t){return n(this.httpClient.post(`/admin-api/alias/delete/identity/${e}/${t}`,{}))}};var W=class{constructor(e){this.httpClient=e}async getTeeInfo(){return n(this.httpClient.get("/admin-api/tee/info"))}async attestTee(e){return n(this.httpClient.post("/admin-api/tee/attest",e))}async verifyTeeQuote(e){return n(this.httpClient.post("/admin-api/tee/verify-quote",e))}};var m=class{constructor(e){this.httpClient=e}get public(){return this._public||(this._public=new A(this.httpClient)),this._public}get applications(){return this._applications||(this._applications=new k(this.httpClient)),this._applications}get contexts(){return this._contexts||(this._contexts=new T(this.httpClient)),this._contexts}get proposals(){return this._proposals||(this._proposals=new P(this.httpClient)),this._proposals}get capabilities(){return this._capabilities||(this._capabilities=new v(this.httpClient)),this._capabilities}get identity(){return this._identity||(this._identity=new w(this.httpClient)),this._identity}get network(){return this._network||(this._network=new S(this.httpClient)),this._network}get blobs(){return this._blobs||(this._blobs=new E(this.httpClient)),this._blobs}get aliases(){return this._aliases||(this._aliases=new I(this.httpClient)),this._aliases}get tee(){return this._tee||(this._tee=new W(this.httpClient)),this._tee}};function M(r){return new m(r)}var te={};O(te,{JsonRpcError:()=>g,RpcClient:()=>f});var g=class extends Error{constructor(t,s,o){let i=typeof s=="string"?s:s?.message?String(s.message):t;super(i);this.type=t;this.data=s;this.requestId=o;this.name="JsonRpcError"}},f=class{constructor(e){this.httpClient=e;this.path="/jsonrpc"}generateRequestId(){return Math.floor(Math.random()*Math.pow(2,32))}async execute(e){let t=this.generateRequestId(),s={jsonrpc:"2.0",id:t,method:"execute",params:{contextId:e.contextId,method:e.method,argsJson:e.args,executorPublicKey:e.executorPublicKey,substitute:e.substitute??[]}},o=await this.httpClient.post(this.path,s);if(o.id!==t)throw new g("MismatchedRequestIdError",`Expected request ID ${t}, got ${o.id}`,o.id);if(o.error)throw new g(o.error.type,o.error.data,o.id);return o.result??{output:null}}async query(e,t,s,o){return(await this.execute({contextId:e,method:t,args:s,executorPublicKey:o})).output}async mutate(e,t,s,o){return(await this.execute({contextId:e,method:t,args:s,executorPublicKey:o})).output}};var se={};O(se,{WebSocketClient:()=>R});var R=class{constructor(e){this.ws=null;this.requestId=0;this.pendingRequests=new Map;this.eventHandlers=[];this.errorHandlers=[];this.closeHandlers=[];this.reconnectAttempts=0;this.subscribedContexts=new Set;this.options={autoReconnect:!0,reconnectDelay:1e3,maxReconnectAttempts:5,getAuthToken:async()=>null,...e}}async connect(){if(this.ws?.readyState===WebSocket.OPEN)return;let e=this.options.baseUrl.replace(/^http:/,"ws:").replace(/^https:/,"wss:").replace(/\/$/,"")+"/ws",t=await this.options.getAuthToken();return new Promise((s,o)=>{let i=t?`${e}?token=${encodeURIComponent(t)}`:e;this.ws=new WebSocket(i),this.ws.onopen=()=>{this.reconnectAttempts=0,s()},this.ws.onerror=a=>{let p=new Error("WebSocket error");this.errorHandlers.forEach(C=>C(p)),o(p)},this.ws.onclose=a=>{this.closeHandlers.forEach(p=>p(a.code,a.reason)),this.handleDisconnect()},this.ws.onmessage=a=>{this.handleMessage(a.data)}})}disconnect(){this.options.autoReconnect=!1,this.ws?.close(),this.ws=null,this.subscribedContexts.clear()}async subscribe(e){let t=await this.send({id:++this.requestId,method:"subscribe",params:{contextIds:e}});return t.error||e.forEach(s=>this.subscribedContexts.add(s)),t}async unsubscribe(e){let t=await this.send({id:++this.requestId,method:"unsubscribe",params:{contextIds:e}});return t.error||e.forEach(s=>this.subscribedContexts.delete(s)),t}onEvent(e){return this.eventHandlers.push(e),()=>{this.eventHandlers=this.eventHandlers.filter(t=>t!==e)}}onError(e){return this.errorHandlers.push(e),()=>{this.errorHandlers=this.errorHandlers.filter(t=>t!==e)}}onClose(e){return this.closeHandlers.push(e),()=>{this.closeHandlers=this.closeHandlers.filter(t=>t!==e)}}isConnected(){return this.ws?.readyState===WebSocket.OPEN}getSubscribedContexts(){return Array.from(this.subscribedContexts)}async send(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("WebSocket not connected");return new Promise((t,s)=>{let o=e.id;o!==null&&this.pendingRequests.set(o,{resolve:t,reject:s}),this.ws.send(JSON.stringify(e)),setTimeout(()=>{o!==null&&this.pendingRequests.has(o)&&(this.pendingRequests.delete(o),s(new Error("WebSocket request timeout")))},3e4)})}handleMessage(e){try{let t=JSON.parse(e);if(t.id!==void 0&&this.pendingRequests.has(t.id)){let{resolve:o}=this.pendingRequests.get(t.id);this.pendingRequests.delete(t.id),o(t);return}let s={contextId:t.contextId||t.context_id,type:t.type||t.event,data:t.data||t.payload};this.eventHandlers.forEach(o=>o(s))}catch(t){this.errorHandlers.forEach(s=>s(t instanceof Error?t:new Error(String(t))))}}handleDisconnect(){if(!this.options.autoReconnect)return;if(this.reconnectAttempts>=this.options.maxReconnectAttempts){this.errorHandlers.forEach(t=>t(new Error("Max reconnect attempts reached")));return}this.reconnectAttempts++;let e=this.options.reconnectDelay*Math.pow(2,this.reconnectAttempts-1);setTimeout(async()=>{try{await this.connect(),this.subscribedContexts.size>0&&await this.subscribe(Array.from(this.subscribedContexts))}catch{}},e)}};var ne={};O(ne,{SseClient:()=>y});var y=class{constructor(e){this.eventSource=null;this.sessionId=null;this.eventHandlers=[];this.errorHandlers=[];this.subscribedContexts=new Set;this._lastEventId=null;this.options={autoReconnect:!0,reconnectDelay:1e3,getAuthToken:async()=>null,...e}}async connect(){if(this.eventSource)throw new Error("Already connected");let e=await this.options.getAuthToken(),t=`${this.options.baseUrl}/sse`;return e&&(t+=`?token=${encodeURIComponent(e)}`),new Promise((s,o)=>{this.eventSource=new EventSource(t,{withCredentials:!0}),this.eventSource.addEventListener("connect",i=>{let a=i;try{let p=a.data;this.sessionId=typeof p=="string"&&p.startsWith("{")?JSON.parse(p).session_id||JSON.parse(p).sessionId:p,s(this.sessionId)}catch{this.sessionId=a.data,s(this.sessionId)}}),this.eventSource.onmessage=i=>{this._lastEventId=i.lastEventId;try{let a=JSON.parse(i.data),p={id:i.lastEventId,event:"message",data:a};this.eventHandlers.forEach(C=>C(p))}catch{let a={id:i.lastEventId,event:"message",data:i.data};this.eventHandlers.forEach(p=>p(a))}},this.eventSource.onerror=i=>{let a=new Error("SSE connection error");this.errorHandlers.forEach(p=>p(a)),this.eventSource?.readyState===EventSource.CLOSED&&(this.handleDisconnect(),this.sessionId||o(a))}})}disconnect(){this.options.autoReconnect=!1,this.eventSource?.close(),this.eventSource=null,this.sessionId=null,this.subscribedContexts.clear()}async subscribe(e){if(!this.sessionId)throw new Error("Not connected");let t={id:this.sessionId,method:"subscribe",params:{contextIds:e}},s=await this.options.httpClient.post("/sse/subscription",t);return s.error||e.forEach(o=>this.subscribedContexts.add(o)),s}async unsubscribe(e){if(!this.sessionId)throw new Error("Not connected");let t={id:this.sessionId,method:"unsubscribe",params:{contextIds:e}},s=await this.options.httpClient.post("/sse/subscription",t);return s.error||e.forEach(o=>this.subscribedContexts.delete(o)),s}async getSession(){if(!this.sessionId)throw new Error("Not connected");return this.options.httpClient.get(`/sse/session/${this.sessionId}`)}onEvent(e){return this.eventHandlers.push(e),()=>{this.eventHandlers=this.eventHandlers.filter(t=>t!==e)}}onError(e){return this.errorHandlers.push(e),()=>{this.errorHandlers=this.errorHandlers.filter(t=>t!==e)}}isConnected(){return this.eventSource?.readyState===EventSource.OPEN}getSessionId(){return this.sessionId}getSubscribedContexts(){return Array.from(this.subscribedContexts)}getLastEventId(){return this._lastEventId}handleDisconnect(){this.options.autoReconnect&&setTimeout(async()=>{try{await this.connect(),this.subscribedContexts.size>0&&await this.subscribe(Array.from(this.subscribedContexts))}catch{}},this.options.reconnectDelay)}};var L=class{constructor(e){this.tokenData=null;this.refreshPromise=null;this.tokenStorage=null;this.config={timeoutMs:1e4,...e},this.tokenStorage=e.tokenStorage||null;let t=typeof window<"u"&&"__TAURI_INTERNALS__"in window,s=this.config.authBaseUrl??this.config.baseUrl,o=s===this.config.baseUrl;this.httpClient=G({baseUrl:this.config.baseUrl,getAuthToken:async()=>(await this.getValidToken())?.access_token||"",refreshToken:async()=>(await this.performTokenRefresh()).access_token,onTokenRefresh:async a=>{this.tokenData&&this.tokenStorage&&await this.tokenStorage.set(this.tokenData)},timeoutMs:this.config.timeoutMs,credentials:this.config.requestCredentials??(t?"omit":void 0)});let i=G({baseUrl:s,getAuthToken:async()=>(await this.getValidToken())?.access_token||"",timeoutMs:this.config.timeoutMs,credentials:this.config.requestCredentials??(t?"omit":void 0)});this.authClient=N(i,{baseUrl:s,embedded:o}),this.adminClient=M(this.httpClient),this.rpcClient=new f(this.httpClient)}async init(){if(console.log("[mero-js] init() called, tokenStorage:",this.tokenStorage?"EXISTS":"NULL"),this.tokenStorage){let e=await this.tokenStorage.get();console.log("[mero-js] init() storedToken:",e?"LOADED":"NULL"),e&&(this.tokenData=e,console.log("[mero-js] init() tokenData set, expires_at:",e.expires_at))}else console.log("[mero-js] init() no tokenStorage configured")}get auth(){return this.authClient}get admin(){return this.adminClient}get rpc(){return this.rpcClient}async authenticate(e){let t=e||this.config.credentials;if(!t)throw new Error("No credentials provided for authentication");try{let s={auth_method:"user_password",public_key:t.username,client_name:"mero-js-sdk",permissions:["admin"],timestamp:Math.floor(Date.now()/1e3),provider_data:{username:t.username,password:t.password}},o=await this.authClient.getToken(s),i;try{let a=JSON.parse(atob(o.access_token.split(".")[1]));i=a.exp*1e3,console.log("[mero-js] Extracted exp from JWT:",a.exp,"-> expires_at:",i)}catch{i=Date.now()+(o.expires_in||3600)*1e3,console.warn("[mero-js] Failed to parse JWT, using expires_in fallback:",i)}return this.tokenData={access_token:o.access_token,refresh_token:o.refresh_token,expires_at:i},this.tokenStorage&&await this.tokenStorage.set(this.tokenData),this.tokenData}catch(s){let o=s instanceof Error?s.message:"Unknown error",i=s&&typeof s=="object"&&"status"in s?`HTTP ${String(s.status)}`:"",a=s&&typeof s=="object"&&"statusText"in s?` ${String(s.statusText)}`:"",p=s&&typeof s=="object"&&"bodyText"in s?`: ${String(s.bodyText)}`:"";throw new Error(`Authentication failed: ${i}${a}${p||o}`)}}async getValidToken(){if(console.log("[mero-js] getValidToken called, tokenData:",this.tokenData?"EXISTS":"NULL"),!this.tokenData)return console.log("[mero-js] No tokenData, returning null"),null;let e=Date.now(),t=this.tokenData.expires_at,s=e>=t;return console.log("[mero-js] Token check: now=",e,"expires_at=",t,"isExpired=",s),s?(console.log("[mero-js] Token expired, attempting preemptive refresh"),await this.refreshToken()):(console.log("[mero-js] Token valid, returning tokenData"),this.tokenData)}async refreshToken(){return this.performTokenRefresh()}async performTokenRefresh(){if(this.refreshPromise)return console.log("[mero-js] Refresh already in progress, waiting for existing promise"),this.refreshPromise;console.log("[mero-js] Starting new refresh attempt"),this.refreshPromise=this.doTokenRefresh();try{return await this.refreshPromise}finally{this.refreshPromise=null}}async doTokenRefresh(){if(console.log("[mero-js doTokenRefresh] STARTING refresh..."),console.log("[mero-js doTokenRefresh] tokenData exists:",!!this.tokenData),console.log("[mero-js doTokenRefresh] access_token exists:",!!this.tokenData?.access_token),console.log("[mero-js doTokenRefresh] refresh_token exists:",!!this.tokenData?.refresh_token),!this.tokenData?.refresh_token)throw new Error("No refresh token available");if(!this.tokenData?.access_token)throw new Error("No access token available for refresh (server requires both tokens)");try{let e={access_token:this.tokenData.access_token,refresh_token:this.tokenData.refresh_token};console.log("[mero-js doTokenRefresh] Payload keys:",Object.keys(e)),console.log("[mero-js doTokenRefresh] access_token length:",e.access_token?.length),console.log("[mero-js doTokenRefresh] refresh_token length:",e.refresh_token?.length);let t=await this.authClient.refreshToken(e),s;try{let o=JSON.parse(atob(t.access_token.split(".")[1]));s=o.exp*1e3,console.log("[mero-js] Extracted exp from JWT:",o.exp,"-> expires_at:",s)}catch{s=Date.now()+(t.expires_in||3600)*1e3,console.warn("[mero-js] Failed to parse JWT, using expires_in fallback:",s)}return this.tokenData={access_token:t.access_token,refresh_token:t.refresh_token,expires_at:s},this.tokenStorage&&await this.tokenStorage.set(this.tokenData),this.tokenData}catch(e){console.error("[mero-js] Token refresh failed:",e);let t=e,s=t?.status,o=t?.body||t?.message||"";if(s&&(console.error("[mero-js] Refresh error status:",s),console.error("[mero-js] Refresh error body:",o)),o.includes("still valid")||o.includes("token valid")){console.warn("[mero-js] Server says token is still valid - NOT clearing tokens"),console.warn("[mero-js] This usually means the 401 came from a different issue (wrong endpoint, missing header, etc.)");let i=new Error("Token is valid but request failed. Check Authorization header.");throw i.tokenStillValid=!0,i}throw s&&s>=400&&s<500?(console.warn("[mero-js] Refresh failed with 4XX - clearing tokens, user must re-authenticate"),await this.clearToken(),new Error(`Session expired. Please log in again. (${s})`)):s&&s>=500?(console.warn("[mero-js] Refresh failed with 5XX - server error, keeping tokens"),new Error(`Server error during refresh. Please try again later. (${s})`)):(console.warn("[mero-js] Refresh failed with unknown error - clearing tokens"),await this.clearToken(),new Error(`Token refresh failed: ${e instanceof Error?e.message:"Unknown error"}`))}}async clearToken(){this.tokenData=null,this.tokenStorage&&await this.tokenStorage.clear()}isAuthenticated(){return this.tokenData!==null}getTokenData(){return this.tokenData}async setToken(e){this.tokenData=e,this.tokenStorage&&(e?await this.tokenStorage.set(e):await this.tokenStorage.clear())}createWebSocket(e){return new R({baseUrl:this.config.baseUrl,getAuthToken:async()=>this.tokenData?.access_token||null,...e})}createSse(e){return new y({baseUrl:this.config.baseUrl,httpClient:this.httpClient,getAuthToken:async()=>this.tokenData?.access_token||null,...e})}};function he(r){return new L(r)}export{ee as AdminApi,m as AdminApiClient,j as ApiResponseError,Z as AuthApi,x as AuthApiClient,b as HTTPError,g as JsonRpcError,L as MeroJs,te as RpcApi,f as RpcClient,ne as SseApi,y as SseClient,$ as WebHttpClient,R as WebSocketClient,se as WsApi,J as combineSignals,M as createAdminApiClient,N as createAuthApiClient,G as createBrowserHttpClient,K as createHttpClient,he as createMeroJs,F as createNodeHttpClient,ue as createRetryableMethod,V as createTimeoutSignal,pe as createUniversalHttpClient,n as unwrap,Ee as unwrapOrNull,X as withRetry};
1
+ function q(r){let e=r.filter(Boolean);if(e.length===0)return;let t=AbortSignal;if(typeof t.any=="function")try{return t.any(e)}catch{}let s=new AbortController,n=a=>{s.abort(a.target.reason);for(let p of e)p.removeEventListener("abort",n)};for(let a of e){if(a.aborted)return AbortSignal.abort(a.reason);a.addEventListener("abort",n,{once:!0})}return s.signal}function U(r){if(typeof AbortSignal.timeout=="function")return AbortSignal.timeout(r);let e=new AbortController;return setTimeout(()=>{e.abort(new DOMException("Timeout","TimeoutError"))},r),e.signal}var f=class extends Error{constructor(t,s,n,a,p){super(`HTTP ${t} ${s}`);this.status=t;this.statusText=s;this.url=n;this.headers=a;this.bodyText=p;this.name="HTTPError"}toJSON(){return{status:this.status,statusText:this.statusText,url:this.url,headers:B(this.headers),bodyText:this.bodyText}}};function B(r){let e={};return r.forEach((t,s)=>{e[s]=t}),e}var A=class{constructor(e){this.transport=e;this.refreshTokenPromise=null;this.onTokenRefreshPromise=null}async get(e,t){return this.request(e,{...t,method:"GET"})}async post(e,t,s){return this.request(e,{...s,method:"POST",body:t?JSON.stringify(t):void 0,headers:{"Content-Type":"application/json",...s?.headers}})}async put(e,t,s){return this.request(e,{...s,method:"PUT",body:t?JSON.stringify(t):void 0,headers:{"Content-Type":"application/json",...s?.headers}})}async delete(e,t){return this.request(e,{...t,method:"DELETE"})}async patch(e,t,s){return this.request(e,{...s,method:"PATCH",body:t?JSON.stringify(t):void 0,headers:{"Content-Type":"application/json",...s?.headers}})}async head(e,t){let s=await this.makeRequest(e,{...t,method:"HEAD",parse:"response"});return{headers:B(s.headers),status:s.status}}async request(e,t){return this.makeRequest(e,t)}async makeRequest(e,t,s=0,n){let p=this.buildUrl(e),h=n??Date.now(),y=this.createAbortSignal(t),c=await this.buildHeaders(t?.headers),u;c instanceof Headers?(u={},c.forEach((o,k)=>{u[k]=o})):u=c;let l={method:t?.method||"GET",headers:u},T=t?.body instanceof ReadableStream||typeof t?.body=="object"&&t?.body!==null&&"getReader"in t.body&&!(t.body instanceof Blob);(t?.body!==void 0&&!T||t?.body!==void 0&&T&&s===0)&&(l.body=t.body);let b;if(s>0&&n!==void 0){let o=t?.timeoutMs||this.transport.timeoutMs;if(o){let k=Date.now()-h,w=Math.max(0,o-k);b=this.createAbortSignal({...t,timeoutMs:w})}else b=this.createAbortSignal(t)}else b=y;b&&(l.signal=b),this.transport.credentials!==void 0&&(l.credentials=this.transport.credentials),t?.mode!==void 0&&(l.mode=t.mode),t?.cache!==void 0&&(l.cache=t.cache),t?.redirect!==void 0&&(l.redirect=t.redirect),t?.referrer!==void 0&&(l.referrer=t.referrer),t?.referrerPolicy!==void 0&&(l.referrerPolicy=t.referrerPolicy),t?.integrity!==void 0&&(l.integrity=t.integrity),t?.keepalive!==void 0&&(l.keepalive=t.keepalive);try{let o=await this.transport.fetch(p,l);if(!o.ok){let k=await this.getBodyText(o),w=new f(o.status,o.statusText,p,o.headers,k),z=t?.signal?.aborted===!0;if(o.status===401&&this.transport.refreshToken&&o.headers.get("x-auth-error")==="token_expired"&&s<1&&!T&&!z)try{let d=this.refreshTokenPromise;d||(d=this.transport.refreshToken(),this.refreshTokenPromise=d);let G=await d;if(!G||G.trim()==="")throw this.refreshTokenPromise=null,this.onTokenRefreshPromise=null,new Error("Refresh token returned empty token");if(!this.transport.onTokenRefresh)throw this.refreshTokenPromise=null,this.onTokenRefreshPromise=null,new Error("onTokenRefresh callback is required when refreshToken is provided. The callback must update the token storage so getAuthToken() returns the new token.");let P=this.onTokenRefreshPromise;P||(P=this.transport.onTokenRefresh(G),this.onTokenRefreshPromise=P),await P,this.refreshTokenPromise=null,this.onTokenRefreshPromise=null;let J=t?.timeoutMs||this.transport.timeoutMs;if(J&&n!==void 0){let Q=Date.now()-h;if(J-Q<=0)throw w}return this.makeRequest(e,t,s+1,h)}catch(d){throw this.refreshTokenPromise=null,this.onTokenRefreshPromise=null,d instanceof Error&&d.message.includes("onTokenRefresh")?d:w}throw w}return this.parseResponse(o,t?.parse)}catch(o){throw o instanceof f||o instanceof Error&&o.message.includes("onTokenRefresh")?o:new f(0,"Network Error",p,new Headers,o instanceof Error?o.message:"Unknown error")}}buildUrl(e){if(e.startsWith("http://")||e.startsWith("https://"))return e;let t=this.transport.baseUrl;return e.startsWith("/")?`${t.endsWith("/")?t.slice(0,-1):t}${e}`:`${t.endsWith("/")?t:`${t}/`}${e}`}createAbortSignal(e){let t=[];this.transport.defaultAbortSignal&&t.push(this.transport.defaultAbortSignal),e?.signal&&t.push(e.signal);let s=e?.timeoutMs||this.transport.timeoutMs;return s&&t.push(U(s)),t.length>0?q(t):void 0}async buildHeaders(e){let t={...this.transport.defaultHeaders};if(this.transport.getAuthToken)try{let s=await this.transport.getAuthToken();s&&s.trim()!==""&&(t.Authorization=`Bearer ${s}`)}catch{}return e&&(e instanceof Headers?e.forEach((s,n)=>{t[n]=s}):Array.isArray(e)?e.forEach(([s,n])=>{t[s]=n}):Object.assign(t,e)),t}async parseResponse(e,t){switch(t){case"text":return await e.text();case"blob":return await e.blob();case"arrayBuffer":return await e.arrayBuffer();case"response":return e;case"json":default:return await e.json()}}async getBodyText(e){try{let t=await e.text();return t.length>65536?t.slice(0,65536)+"...":t}catch{return""}}};function $(r){return new A(r)}function S(r){let e={fetch:(t,s)=>globalThis.fetch(t,s),baseUrl:r.baseUrl,getAuthToken:r.getAuthToken,onTokenRefresh:r.onTokenRefresh,refreshToken:r.refreshToken,defaultHeaders:r.defaultHeaders,timeoutMs:r.timeoutMs,credentials:r.credentials,defaultAbortSignal:r.defaultAbortSignal};return $(e)}function K(r){let e=r.fetch??globalThis.fetch;if(!e)throw new Error("No fetch implementation available. Please provide a fetch implementation (e.g., undici.fetch) or use Node.js 18+ which has native fetch support.");let s={fetch:e===globalThis.fetch?(n,a)=>globalThis.fetch(n,a):(n,a)=>e(n,a),baseUrl:r.baseUrl,getAuthToken:r.getAuthToken,onTokenRefresh:r.onTokenRefresh,refreshToken:r.refreshToken,defaultHeaders:r.defaultHeaders,timeoutMs:r.timeoutMs,credentials:r.credentials,defaultAbortSignal:r.defaultAbortSignal};return $(s)}function X(r){return typeof window<"u"?S(r):K(r)}function Y(r,e){if(e<=0)return!1;let s=r?.name;if(s==="TimeoutError")return!0;if(s==="AbortError")return!1;let n=r;if("status"in n&&typeof n.status=="number"){let a=n.status;return a>=500||a===429}return s==="TypeError"}function Z(r){let t=250*Math.pow(2,r-1),s=(Math.random()-.5)*.4*t;return Math.max(0,t+s)}async function F(r,e={}){let{attempts:t=3}=e,s;for(let n=1;n<=t;n++)try{return await r(n)}catch(a){if(s=a,!Y(s,t-n))throw s;let p=Z(n),c=s.headers?.get?.("Retry-After");if(c){let u=parseInt(c,10);if(!isNaN(u))p=Math.max(p,u*1e3);else{let l=new Date(c);if(!isNaN(l.getTime())){let T=Math.max(0,l.getTime()-Date.now());p=Math.max(p,Math.min(T,6e4))}}}await new Promise(u=>setTimeout(u,p))}throw s||new Error("Retry failed without error")}function ee(r,e={}){return async(...t)=>F(()=>r(...t),e)}var m=class{constructor(e){this.httpClient=e}async getHealth(){let e=await this.httpClient.get("/auth/health");if(!e.data)throw new Error("Health response data is null");return e.data}async getIdentity(){let e=await this.httpClient.get("/admin/identity");if(!e.data)throw new Error("Identity response data is null");return e.data}async getProviders(){let e=await this.httpClient.get("/auth/providers");if(!e.data)throw new Error("Providers response data is null");return e.data}async getLoginPage(){return this.httpClient.get("/auth/login",{parse:"text"})}async generateTokens(e){return this.httpClient.post("/auth/token",e)}async refreshToken(e){return this.httpClient.post("/auth/refresh",e)}async generateMockTokens(e){return this.httpClient.post("/auth/mock-token",e)}async getChallenge(){return this.httpClient.get("/auth/challenge")}async validateToken(e){try{let t=await this.validateTokenGet(e);return{valid:t.status===200,headers:t.headers,status:t.status}}catch{return{valid:!1,headers:{},status:401}}}async validateTokenGet(e){let t=await this.httpClient.head("/auth/validate",{headers:{Authorization:`Bearer ${e}`}});return{status:t.status,headers:t.headers}}async isAuthed(){return this.httpClient.get("/auth/is-authed")}async revokeTokens(e){return this.httpClient.post("/admin/revoke",e)}async listRootKeys(){let e=await this.httpClient.get("/admin/keys");if(!e.data)throw new Error("Root keys response data is null");return e.data}async createRootKey(e){return this.httpClient.post("/admin/keys",e)}async deleteRootKey(e){return this.httpClient.delete(`/admin/keys/${e}`)}async listClientKeys(){let e=await this.httpClient.get("/admin/keys/clients");if(!e.data)throw new Error("Client keys response data is null");return e.data}async generateClientKey(e){return this.httpClient.post("/admin/client-key",e)}async deleteClientKey(e,t){return this.httpClient.delete(`/admin/keys/${e}/clients/${t}`)}async getKeyPermissions(e){return this.httpClient.get(`/admin/keys/${e}/permissions`)}async updateKeyPermissions(e,t){return this.httpClient.put(`/admin/keys/${e}/permissions`,{permissions:t})}};var D=class{async get(){throw new Error("HTTP client not implemented - use createAuthApiClientFromHttpClient with a real HTTP client")}async post(){throw new Error("HTTP client not implemented - use createAuthApiClientFromHttpClient with a real HTTP client")}async put(){throw new Error("HTTP client not implemented - use createAuthApiClientFromHttpClient with a real HTTP client")}async delete(){throw new Error("HTTP client not implemented - use createAuthApiClientFromHttpClient with a real HTTP client")}async patch(){throw new Error("HTTP client not implemented - use createAuthApiClientFromHttpClient with a real HTTP client")}async head(){throw new Error("HTTP client not implemented - use createAuthApiClientFromHttpClient with a real HTTP client")}async request(){throw new Error("HTTP client not implemented - use createAuthApiClientFromHttpClient with a real HTTP client")}};function ye(r){let e=new D;return new m(e)}function Te(r){let e=new D;return new m(e)}function be(r){let e=new D;return new m(e)}function j(r,e){return new m(r)}function i(r){return r.data}var g=class{constructor(e){this.httpClient=e}async healthCheck(){return i(await this.httpClient.get("/admin-api/health"))}async isAuthed(){return this.httpClient.get("/admin-api/is-authed")}async installApplication(e){return i(await this.httpClient.post("/admin-api/install-application",e))}async installDevApplication(e){return i(await this.httpClient.post("/admin-api/install-dev-application",e))}async uninstallApplication(e){return i(await this.httpClient.delete(`/admin-api/applications/${e}`))}async listApplications(){return i(await this.httpClient.get("/admin-api/applications"))}async getApplication(e){return i(await this.httpClient.get(`/admin-api/applications/${e}`))}async listPackages(){return i(await this.httpClient.get("/admin-api/packages"))}async listPackageVersions(e){return i(await this.httpClient.get(`/admin-api/packages/${encodeURIComponent(e)}/versions`))}async getLatestPackageVersion(e){return this.httpClient.get(`/admin-api/packages/${encodeURIComponent(e)}/latest`)}async createContext(e){return i(await this.httpClient.post("/admin-api/contexts",e))}async deleteContext(e,t){return i(t?await this.httpClient.request(`/admin-api/contexts/${e}`,{method:"DELETE",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}}):await this.httpClient.delete(`/admin-api/contexts/${e}`))}async getContexts(){return i(await this.httpClient.get("/admin-api/contexts"))}async getContext(e){return i(await this.httpClient.get(`/admin-api/contexts/${e}`))}async getContextsForApplication(e){return i(await this.httpClient.get(`/admin-api/contexts/for-application/${e}`))}async generateContextIdentity(){return i(await this.httpClient.post("/admin-api/identity/context",{}))}async getContextIdentities(e){return i(await this.httpClient.get(`/admin-api/contexts/${e}/identities`))}async getContextIdentitiesOwned(e){return i(await this.httpClient.get(`/admin-api/contexts/${e}/identities-owned`))}async joinContext(e){return i(await this.httpClient.post(`/admin-api/contexts/${e}/join`,{}))}async getContextGroup(e){return i(await this.httpClient.get(`/admin-api/contexts/${e}/group`))}async getContextStorage(e){return i(await this.httpClient.get(`/admin-api/contexts/${e}/storage`))}async syncContext(e){await this.httpClient.post(`/admin-api/contexts/sync/${e??""}`,{})}async inviteSpecializedNode(e){return i(await this.httpClient.post("/admin-api/contexts/invite-specialized-node",e))}async updateContextApplication(e,t){await this.httpClient.post(`/admin-api/contexts/${e}/application`,t)}async getContextsWithExecutorsForApplication(e){return i(await this.httpClient.get(`/admin-api/contexts/with-executors/for-application/${e}`))}async uploadBlob(e){return i(await this.httpClient.put("/admin-api/blobs",e))}async deleteBlob(e){return i(await this.httpClient.delete(`/admin-api/blobs/${e}`))}async listBlobs(){return i(await this.httpClient.get("/admin-api/blobs"))}async getBlob(e){return i(await this.httpClient.get(`/admin-api/blobs/${e}`))}async createContextAlias(e){return i(await this.httpClient.post("/admin-api/alias/create/context",e))}async createApplicationAlias(e){return i(await this.httpClient.post("/admin-api/alias/create/application",e))}async lookupContextAlias(e){return i(await this.httpClient.post(`/admin-api/alias/lookup/context/${encodeURIComponent(e)}`,{}))}async lookupApplicationAlias(e){return i(await this.httpClient.post(`/admin-api/alias/lookup/application/${encodeURIComponent(e)}`,{}))}async deleteContextAlias(e){return i(await this.httpClient.post(`/admin-api/alias/delete/context/${encodeURIComponent(e)}`,{}))}async deleteApplicationAlias(e){return i(await this.httpClient.post(`/admin-api/alias/delete/application/${encodeURIComponent(e)}`,{}))}async listContextAliases(){return i(await this.httpClient.get("/admin-api/alias/list/context"))}async listApplicationAliases(){return i(await this.httpClient.get("/admin-api/alias/list/application"))}async listContextIdentityAliases(e){return i(await this.httpClient.get(`/admin-api/alias/list/identity/${e}`))}async createContextIdentityAlias(e,t){return i(await this.httpClient.post(`/admin-api/alias/create/identity/${e}`,t))}async lookupContextIdentityAlias(e,t){return i(await this.httpClient.post(`/admin-api/alias/lookup/identity/${e}/${encodeURIComponent(t)}`,{}))}async deleteContextIdentityAlias(e,t){return i(await this.httpClient.post(`/admin-api/alias/delete/identity/${e}/${encodeURIComponent(t)}`,{}))}async listNamespaces(){return i(await this.httpClient.get("/admin-api/namespaces"))}async getNamespace(e){return i(await this.httpClient.get(`/admin-api/namespaces/${e}`))}async getNamespaceIdentity(e){return i(await this.httpClient.get(`/admin-api/namespaces/${e}/identity`))}async listNamespacesForApplication(e){return i(await this.httpClient.get(`/admin-api/namespaces/for-application/${e}`))}async createNamespace(e){return i(await this.httpClient.post("/admin-api/namespaces",e))}async deleteNamespace(e,t){return i(await this.httpClient.request(`/admin-api/namespaces/${e}`,{method:"DELETE",body:t?JSON.stringify(t):void 0,headers:t?{"Content-Type":"application/json"}:void 0}))}async createNamespaceInvitation(e,t){return i(await this.httpClient.post(`/admin-api/namespaces/${e}/invite`,t??{}))}async joinNamespace(e,t){return i(await this.httpClient.post(`/admin-api/namespaces/${e}/join`,t,{timeoutMs:65e3}))}async createGroupInNamespace(e,t){return i(await this.httpClient.post(`/admin-api/namespaces/${e}/groups`,t??{}))}async listNamespaceGroups(e){return i(await this.httpClient.get(`/admin-api/namespaces/${e}/groups`))}async getGroupInfo(e){return i(await this.httpClient.get(`/admin-api/groups/${e}`))}async deleteGroup(e,t){return i(t?await this.httpClient.request(`/admin-api/groups/${e}`,{method:"DELETE",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}}):await this.httpClient.delete(`/admin-api/groups/${e}`))}async listGroupMembers(e){let t=await this.httpClient.get(`/admin-api/groups/${e}/members`);if(!Array.isArray(t?.members)){let s=String(e).replace(/[\r\n\t\s]/g,"").slice(0,64);throw new Error(`Invalid listGroupMembers response for group ${s}: missing or non-array \`members\` field`)}return t}async listGroupContexts(e){return i(await this.httpClient.get(`/admin-api/groups/${e}/contexts`))}async addGroupMembers(e,t){await this.httpClient.post(`/admin-api/groups/${e}/members`,t)}async removeGroupMembers(e,t){await this.httpClient.post(`/admin-api/groups/${e}/members/remove`,t)}async updateMemberRole(e,t,s){await this.httpClient.put(`/admin-api/groups/${e}/members/${t}/role`,s)}async getMemberCapabilities(e,t){return i(await this.httpClient.get(`/admin-api/groups/${e}/members/${t}/capabilities`))}async setMemberCapabilities(e,t,s){await this.httpClient.put(`/admin-api/groups/${e}/members/${t}/capabilities`,s)}async setDefaultCapabilities(e,t){await this.httpClient.put(`/admin-api/groups/${e}/settings/default-capabilities`,t)}async setSubgroupVisibility(e,t){await this.httpClient.put(`/admin-api/groups/${e}/settings/subgroup-visibility`,t)}async setTeeAdmissionPolicy(e,t){await this.httpClient.put(`/admin-api/groups/${e}/settings/tee-admission-policy`,t)}async updateGroupSettings(e,t){await this.httpClient.patch(`/admin-api/groups/${e}`,t)}async setGroupAlias(e,t){await this.httpClient.put(`/admin-api/groups/${e}/alias`,t)}async setMemberAlias(e,t,s){await this.httpClient.put(`/admin-api/groups/${e}/members/${t}/alias`,s)}async syncGroup(e,t){return i(await this.httpClient.post(`/admin-api/groups/${e}/sync`,t??{}))}async registerGroupSigningKey(e,t){return i(await this.httpClient.post(`/admin-api/groups/${e}/signing-key`,t))}async upgradeGroup(e,t){return i(await this.httpClient.post(`/admin-api/groups/${e}/upgrade`,t))}async getGroupUpgradeStatus(e){return i(await this.httpClient.get(`/admin-api/groups/${e}/upgrade/status`))}async retryGroupUpgrade(e,t){return i(await this.httpClient.post(`/admin-api/groups/${e}/upgrade/retry`,t??{}))}async nestGroup(e,t){await this.httpClient.post(`/admin-api/groups/${e}/nest`,t)}async unnestGroup(e,t){await this.httpClient.post(`/admin-api/groups/${e}/unnest`,t)}async listSubgroups(e){return i(await this.httpClient.get(`/admin-api/groups/${e}/subgroups`))}async detachContextFromGroup(e,t,s){await this.httpClient.post(`/admin-api/groups/${e}/contexts/${t}/remove`,s??{})}async createGroupInvitation(e,t){return i(await this.httpClient.post(`/admin-api/groups/${e}/invite`,t??{}))}async joinGroup(e){return i(await this.httpClient.post("/admin-api/groups/join",e))}async getTeeInfo(){return i(await this.httpClient.get("/admin-api/tee/info"))}async teeAttest(e){return i(await this.httpClient.post("/admin-api/tee/attest",e))}async teeVerifyQuote(e){return i(await this.httpClient.post("/admin-api/tee/verify-quote",e))}async getPeersCount(){return this.httpClient.get("/admin-api/peers")}};var v=class{async get(){throw new Error("HTTP client not implemented - use createAdminApiClientFromHttpClient with a real HTTP client")}async post(){throw new Error("HTTP client not implemented - use createAdminApiClientFromHttpClient with a real HTTP client")}async put(){throw new Error("HTTP client not implemented - use createAdminApiClientFromHttpClient with a real HTTP client")}async delete(){throw new Error("HTTP client not implemented - use createAdminApiClientFromHttpClient with a real HTTP client")}async patch(){throw new Error("HTTP client not implemented - use createAdminApiClientFromHttpClient with a real HTTP client")}async head(){throw new Error("HTTP client not implemented - use createAdminApiClientFromHttpClient with a real HTTP client")}async request(){throw new Error("HTTP client not implemented - use createAdminApiClientFromHttpClient with a real HTTP client")}};function De(r){let e=new v;return new g(e)}function ve(r){let e=new v;return new g(e)}function xe(r){let e=new v;return new g(e)}function V(r,e){return new g(r)}function N(r){try{let e=r.indexOf("#");if(e===-1)return null;let t=r.substring(e+1),s=new URLSearchParams(t),n=s.get("access_token");return n?{accessToken:n,refreshToken:s.get("refresh_token")??"",applicationId:s.get("application_id")??"",contextId:s.get("context_id")??"",contextIdentity:s.get("context_identity")??"",nodeUrl:s.get("node_url")??""}:null}catch{return null}}function M(r,e){let t=new URLSearchParams;return t.set("callback-url",e.callbackUrl),e.permissions&&e.permissions.length>0&&t.set("permissions",e.permissions.join(",")),t.set("mode",e.mode),e.packageName&&(t.set("package-name",e.packageName),e.packageVersion&&t.set("package-version",e.packageVersion),e.registryUrl&&t.set("registry-url",e.registryUrl)),`${r.replace(/\/+$/,"")}/auth/login?${t.toString()}`}var E=class extends Error{constructor(e,t,s,n){super(t),this.name="RpcError",this.code=e,this.data=s,this.type=n}},x=class{constructor(e){this.httpClient=e.httpClient}async execute(e){let t={jsonrpc:"2.0",id:1,method:"execute",params:{contextId:e.contextId,method:e.method,argsJson:e.argsJson??{}}},s=await this.httpClient.post("/jsonrpc",t);if(s.error){let n=s.error,a=n.code??-1,p=n.message??n.type??"RPC error";throw new E(a,p,n.data,n.type)}return s.result&&"output"in s.result?s.result.output:s.result}};var C=class{constructor(e){this.sessionId=null;this.abortController=null;this.reconnectTimer=null;this.subscribedContextIds=new Set;this.closed=!1;this.listeners={connect:[],event:[],error:[]};this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.getAuthToken=e.getAuthToken,this.reconnectDelayMs=e.reconnectDelayMs??3e3}on(e,t){let s=e;if(s in this.listeners){let n=this.listeners[s];n.includes(t)||n.push(t)}}off(e,t){let s=e;if(s in this.listeners){let n=this.listeners[s],a=n.indexOf(t);a!==-1&&n.splice(a,1)}}emit(e,t){let s=e;if(s in this.listeners)for(let n of this.listeners[s])try{n(t)}catch{}}async connect(){if(!(this.abortController&&!this.closed)){this.closed=!1,this.abortController=new AbortController;try{let e=await this.getAuthToken(),t=await fetch(`${this.baseUrl}/sse`,{headers:{Authorization:`Bearer ${e}`,Accept:"text/event-stream"},signal:this.abortController.signal});if(!t.ok)throw new Error(`SSE connection failed: ${t.status}`);if(!t.body)throw new Error("SSE response has no body");this.readStream(t.body).catch(s=>{if(this.closed)return;let n=s instanceof Error?s:new Error(String(s));this.emit("error",n),this.scheduleReconnect()})}catch(e){if(this.closed)return;let t=e instanceof Error?e:new Error(String(e));this.emit("error",t),this.scheduleReconnect()}}}async readStream(e){let t=e.getReader(),s=new TextDecoder,n="";try{for(;;){let{done:a,value:p}=await t.read();if(a)break;n+=s.decode(p,{stream:!0});let h=n.split(`
2
+ `);n=h.pop()??"";for(let y of h)if(y.startsWith("data:")){let c=y.slice(5).trim();c&&this.handleMessage(c)}}if(n+=s.decode(),n.startsWith("data:")){let a=n.slice(5).trim();a&&this.handleMessage(a)}}catch(a){if(this.closed)return;let p=a instanceof Error?a:new Error(String(a));this.emit("error",p)}this.closed||this.scheduleReconnect()}handleMessage(e){try{let t=JSON.parse(e);if(t.type==="connect"&&t.session_id){this.sessionId=t.session_id,this.emit("connect",t.session_id),this.subscribedContextIds.size>0&&this.sendSubscription("subscribe",[...this.subscribedContextIds]);return}if(t.result&&t.result.contextId){let s=t.result.data;if(Array.isArray(s))try{let n=new Uint8Array(s),a=new TextDecoder().decode(n);s=JSON.parse(a)}catch{}this.emit("event",{contextId:t.result.contextId,data:s})}}catch{}}async subscribe(e){let t=e.filter(s=>!this.subscribedContextIds.has(s));for(let s of e)this.subscribedContextIds.add(s);t.length>0&&this.sessionId&&await this.sendSubscription("subscribe",t)}async unsubscribe(e){let t=e.filter(s=>this.subscribedContextIds.has(s));for(let s of e)this.subscribedContextIds.delete(s);t.length>0&&this.sessionId&&await this.sendSubscription("unsubscribe",t)}async sendSubscription(e,t){try{let s=await this.getAuthToken(),n=await fetch(`${this.baseUrl}/sse/subscription`,{method:"POST",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify({id:this.sessionId,method:e,params:{contextIds:t}})});n.ok||this.emit("error",new Error(`SSE ${e} failed: ${n.status}`))}catch(s){this.emit("error",s instanceof Error?s:new Error(`SSE ${e} failed`))}}forceReconnect(){this.abortController&&(this.abortController.abort(),this.abortController=null),this.sessionId=null,this.connect()}scheduleReconnect(){this.closed||(this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.forceReconnect()},this.reconnectDelayMs))}close(){this.closed=!0,this.abortController&&(this.abortController.abort(),this.abortController=null),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.sessionId=null,this.subscribedContextIds.clear()}};var I=class I{constructor(e){this.ws=null;this.closed=!1;this.reconnectAttempt=0;this.reconnectTimer=null;this.subscribedContextIds=new Set;this.listeners={connect:[],event:[],error:[]};this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.getAuthToken=e.getAuthToken}on(e,t){let s=e;if(s in this.listeners){let n=this.listeners[s];n.includes(t)||n.push(t)}}off(e,t){let s=e;if(s in this.listeners){let n=this.listeners[s],a=n.indexOf(t);a!==-1&&n.splice(a,1)}}emit(e,t){let s=e;if(s in this.listeners)for(let n of this.listeners[s])try{n(t)}catch{}}async connect(){if(!(this.ws&&(this.ws.readyState===WebSocket.CONNECTING||this.ws.readyState===WebSocket.OPEN))){this.closed=!1;try{let e=await this.getAuthToken();if(!e)throw new Error("No authentication token available for WebSocket connection");let t=this.baseUrl.replace(/^http/,"ws");this.ws=new WebSocket(`${t}/ws?token=${encodeURIComponent(e)}`),this.ws.onopen=()=>{this.reconnectAttempt=0,this.emit("connect"),this.subscribedContextIds.size>0&&this.sendMessage({id:null,method:"subscribe",params:{contextIds:[...this.subscribedContextIds]}})},this.ws.onmessage=s=>{this.handleMessage(s.data)},this.ws.onerror=()=>{this.emit("error",new Error("WebSocket error"))},this.ws.onclose=()=>{this.closed||this.scheduleReconnect()}}catch(e){if(this.closed)return;let t=e instanceof Error?e:new Error(String(e));this.emit("error",t),this.scheduleReconnect()}}}handleMessage(e){if(typeof e=="string")try{let t=JSON.parse(e);if(t.result&&t.result.contextId){let s=t.result.data;if(Array.isArray(s))try{let n=new Uint8Array(s),a=new TextDecoder().decode(n);s=JSON.parse(a)}catch{}this.emit("event",{contextId:t.result.contextId,data:s})}}catch{}}subscribe(e){for(let t of e)this.subscribedContextIds.add(t);this.ws&&this.ws.readyState===WebSocket.OPEN&&this.sendMessage({id:null,method:"subscribe",params:{contextIds:e}})}unsubscribe(e){for(let t of e)this.subscribedContextIds.delete(t);this.ws&&this.ws.readyState===WebSocket.OPEN&&this.sendMessage({id:null,method:"unsubscribe",params:{contextIds:e}})}sendMessage(e){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify(e))}scheduleReconnect(){if(this.closed)return;this.reconnectTimer&&clearTimeout(this.reconnectTimer);let e=Math.min(1e3*Math.pow(2,this.reconnectAttempt),I.MAX_BACKOFF_MS);this.reconnectAttempt++,this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},e)}close(){this.closed=!0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.ws&&(this.ws.onclose=null,this.ws.close(),this.ws=null),this.subscribedContextIds.clear()}};I.MAX_BACKOFF_MS=3e4;var R=I;function _(r,e){try{let t=r.split(".");if(t.length===3){let s=t[1].replace(/-/g,"+").replace(/_/g,"/");for(;s.length%4;)s+="=";let n=JSON.parse(atob(s));if(typeof n.exp=="number")return n.exp*1e3}}catch{}return e}var H=class{constructor(e){this.tokenData=null;this.refreshPromise=null;this.rpcClient=null;this.sseClient=null;this.wsClient=null;this.wsWarned=!1;this.config={timeoutMs:1e4,...e},this.tokenStore=e.tokenStore??null,this.tokenStore&&(this.tokenData=this.tokenStore.getTokens());let t=typeof window<"u"&&"__TAURI_INTERNALS__"in window;this.httpClient=S({baseUrl:this.config.baseUrl,getAuthToken:async()=>(await this.getValidToken())?.access_token||"",refreshToken:async()=>(await this.performTokenRefresh()).access_token,onTokenRefresh:async s=>{this.tokenData&&(this.tokenData.access_token=s,this.tokenStore?.setTokens(this.tokenData))},timeoutMs:this.config.timeoutMs,credentials:this.config.requestCredentials??(t?"omit":void 0)}),this.authClient=j(this.httpClient,{baseUrl:this.config.baseUrl,getAuthToken:async()=>(await this.getValidToken())?.access_token||"",timeoutMs:this.config.timeoutMs}),this.adminClient=V(this.httpClient,{baseUrl:this.config.baseUrl,getAuthToken:async()=>(await this.getValidToken())?.access_token||"",timeoutMs:this.config.timeoutMs})}get auth(){return this.authClient}get admin(){return this.adminClient}get rpc(){return this.rpcClient||(this.rpcClient=new x({httpClient:this.httpClient})),this.rpcClient}get events(){return this.sseClient||(this.sseClient=new C({baseUrl:this.config.baseUrl,getAuthToken:async()=>(await this.getValidToken())?.access_token||""})),this.sseClient}get ws(){return this.wsWarned||(this.wsWarned=!0,console.warn("[mero-js] WsClient is experimental. Use mero.events (SSE) for production.")),this.wsClient||(this.wsClient=new R({baseUrl:this.config.baseUrl,getAuthToken:async()=>(await this.getValidToken())?.access_token||""})),this.wsClient}async authenticate(e){let t=e||this.config.credentials;if(!t)throw new Error("No credentials provided for authentication");try{let s={auth_method:"user_password",public_key:t.username,client_name:"mero-js-sdk",permissions:["admin"],timestamp:Math.floor(Date.now()/1e3),provider_data:{username:t.username,password:t.password}},n=await this.authClient.generateTokens(s),a=n.data.access_token;return this.tokenData={access_token:a,refresh_token:n.data.refresh_token,expires_at:_(a,Date.now()+36e5)},this.tokenStore?.setTokens(this.tokenData),this.tokenData}catch(s){throw new Error(`Authentication failed: ${s instanceof Error?s.message:"Unknown error"}`)}}async getValidToken(){return this.tokenData}async refreshToken(){if(!this.tokenData?.refresh_token)throw new Error("No refresh token available");if(this.refreshPromise)return this.refreshPromise;this.refreshPromise=this.performTokenRefresh();try{return await this.refreshPromise}finally{this.refreshPromise=null}}async performTokenRefresh(){if(!this.tokenData?.refresh_token)throw new Error("No refresh token available");try{let e=await this.authClient.refreshToken({access_token:this.tokenData.access_token,refresh_token:this.tokenData.refresh_token}),t=e.data.access_token;return this.tokenData={access_token:t,refresh_token:e.data.refresh_token,expires_at:_(t,Date.now()+36e5)},this.tokenStore?.setTokens(this.tokenData),this.tokenData}catch(e){throw new Error(`Token refresh failed: ${e instanceof Error?e.message:"Unknown error"}`)}}clearToken(){this.tokenData=null,this.tokenStore?.clear()}isAuthenticated(){return this.tokenData!==null}setTokenData(e){let t=e.expires_at||_(e.access_token,Date.now()+36e5);this.tokenData={...e,expires_at:t},this.tokenStore?.setTokens(this.tokenData)}getTokenData(){return this.tokenData}close(){this.sseClient?.close(),this.wsClient?.close()}static parseAuthCallback(e){return N(e)}static buildAuthLoginUrl(e,t){return M(e,t)}};function te(r){return new H(r)}var L=class{constructor(){this.tokens=null}getTokens(){return this.tokens}setTokens(e){this.tokens=e}clear(){this.tokens=null}},se="mero-tokens",W=class{constructor(e=se){this.key=e}getTokens(){try{if(typeof localStorage>"u")return null;let e=localStorage.getItem(this.key);if(!e)return null;let t=JSON.parse(e);return t&&t.access_token&&t.refresh_token?{access_token:t.access_token,refresh_token:t.refresh_token,expires_at:typeof t.expires_at=="number"?t.expires_at:Date.now()+36e5}:null}catch{return null}}setTokens(e){try{if(typeof localStorage>"u")return;localStorage.setItem(this.key,JSON.stringify(e))}catch{}}clear(){try{if(typeof localStorage>"u")return;localStorage.removeItem(this.key)}catch{}}};var O=class{constructor(e={}){this.baseUrl=(e.cloudBaseUrl||"https://cloud.calimero.network").replace(/\/+$/,"")}enableHA(e){let t=new URLSearchParams({group_id:e.groupId,context_id:e.contextId});e.redirectUrl&&t.set("redirect_url",e.redirectUrl),window.open(`${this.baseUrl}/enable-ha?${t.toString()}`)}disableHA(e){let t=new URLSearchParams({group_id:e.groupId,context_id:e.contextId});e.redirectUrl&&t.set("redirect_url",e.redirectUrl),window.open(`${this.baseUrl}/disable-ha?${t.toString()}`)}};export{g as AdminApiClient,m as AuthApiClient,O as CloudClient,f as HTTPError,W as LocalStorageTokenStore,L as MemoryTokenStore,H as MeroJs,x as RpcClient,E as RpcError,C as SseClient,A as WebHttpClient,R as WsClient,M as buildAuthLoginUrl,q as combineSignals,xe as createAdminApiClient,V as createAdminApiClientFromHttpClient,be as createAuthApiClient,j as createAuthApiClientFromHttpClient,De as createBrowserAdminApiClient,ye as createBrowserAuthApiClient,S as createBrowserHttpClient,$ as createHttpClient,te as createMeroJs,ve as createNodeAdminApiClient,Te as createNodeAuthApiClient,K as createNodeHttpClient,ee as createRetryableMethod,U as createTimeoutSignal,X as createUniversalHttpClient,N as parseAuthCallback,F as withRetry};
2
3
  //# sourceMappingURL=index.browser.mjs.map