shennian 0.4.37 → 0.4.38
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.
|
@@ -9,3 +9,4 @@ export declare function synchronizeMachinePersonalAuthority(input: {
|
|
|
9
9
|
machineId?: string | null;
|
|
10
10
|
fetchImpl?: typeof fetch;
|
|
11
11
|
}): Promise<MachinePersonalAuthority>;
|
|
12
|
+
export declare function fetchMachineAuthorityResponse(url: string, machineToken: string, request?: typeof fetch): Promise<Response>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SESSION_SYNC_DATA_EPOCH as
|
|
1
|
+
import{setTimeout as h}from"node:timers/promises";import{SESSION_SYNC_DATA_EPOCH as s}from"@shennian/wire";import{loadConfig as m,saveConfig as d}from"../config/index.js";import{getDaemonInstallationId as l}from"./identity.js";async function y(a){const t=await f(`${a.serverUrl.replace(/\/+$/,"")}/api/machines/identity`,a.machineToken,a.fetchImpl);if(!t.ok)throw new Error(`machine_personal_authority_unavailable:${t.status}`);const e=await t.json();if(typeof e.machineId!="string"||!e.machineId||typeof e.daemonInstallationId!="string"||!e.daemonInstallationId||typeof e.dataEpoch!="number"||!Number.isSafeInteger(e.dataEpoch))throw new Error("machine_personal_authority_invalid_response");if(a.machineId&&e.machineId!==a.machineId)throw new Error("machine_personal_authority_machine_mismatch");if(e.daemonInstallationId!==l())throw new Error("machine_personal_authority_daemon_mismatch");if(e.dataEpoch!==s)throw new Error("machine_personal_authority_epoch_mismatch");const o=m();return o.machineId!==e.machineId&&d({...o,machineId:e.machineId}),e}async function f(a,t,e=fetch){const o=AbortSignal.timeout(1e4);for(let n=0;;n+=1)try{return await e(a,{headers:{Authorization:`Bearer ${t}`},signal:o})}catch(r){const i=r,c=i?.cause?.code??i?.code;if(o.aborted||n>=2||!["ECONNRESET","EPIPE","UND_ERR_SOCKET"].includes(c??""))throw r;await h(250*(n+1),void 0,{signal:o})}}export{f as fetchMachineAuthorityResponse,y as synchronizeMachinePersonalAuthority};
|