@interncom/diplomatic 0.0.27 → 0.0.29
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/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useClientState, useSyncOnResume } from "./useClient";
|
|
2
|
-
import { StateManager,
|
|
1
|
+
import { useClientState, useSyncOnResume } from "./react/useClient";
|
|
2
|
+
import { StateManager, opMapApplier } from './state';
|
|
3
3
|
import { localStorageStore } from "./localStorageStore";
|
|
4
4
|
import { idbStore } from "./idbStore";
|
|
5
5
|
import type { IDiplomaticClientState } from "./types";
|
|
@@ -7,5 +7,8 @@ import DiplomaticClient from "./client";
|
|
|
7
7
|
import libsodiumCrypto from "./crypto";
|
|
8
8
|
import { btoh, htob } from "./shared/lib";
|
|
9
9
|
import { type IOp, Verb } from "./shared/types";
|
|
10
|
-
|
|
10
|
+
import useStateWatcher from "./react/useStateWatcher";
|
|
11
|
+
import InitSeedView from "./react/initSeedView";
|
|
12
|
+
import ClientStatusBar from "./react/statusBar";
|
|
13
|
+
export { useClientState, useSyncOnResume, StateManager, useStateWatcher, opMapApplier, localStorageStore, idbStore, DiplomaticClient, libsodiumCrypto, btoh, htob, Verb, InitSeedView, ClientStatusBar, };
|
|
11
14
|
export type { IOp, IDiplomaticClientState, };
|
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ var __export = (target, all) => {
|
|
|
10
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
// src/useClient.ts
|
|
13
|
+
// src/react/useClient.ts
|
|
14
14
|
import { useState, useEffect } from "react";
|
|
15
15
|
function useClientState(client) {
|
|
16
16
|
const [state, setState] = useState();
|
|
@@ -42,9 +42,6 @@ function useSyncOnResume(client) {
|
|
|
42
42
|
}, [client]);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
// src/state.ts
|
|
46
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
47
|
-
|
|
48
45
|
// src/eventEmitter.ts
|
|
49
46
|
var EventEmitter = class {
|
|
50
47
|
events = {};
|
|
@@ -87,20 +84,6 @@ var StateManager = class {
|
|
|
87
84
|
this.emitter.off(opType, listener);
|
|
88
85
|
};
|
|
89
86
|
};
|
|
90
|
-
function useStateWatcher(mgr, opType, callback) {
|
|
91
|
-
const [val, setVal] = useState2(callback());
|
|
92
|
-
useEffect2(() => {
|
|
93
|
-
function update() {
|
|
94
|
-
const newVal = callback();
|
|
95
|
-
setVal(newVal);
|
|
96
|
-
}
|
|
97
|
-
mgr.on(opType, update);
|
|
98
|
-
return () => {
|
|
99
|
-
mgr.off(opType, update);
|
|
100
|
-
};
|
|
101
|
-
}, [mgr, opType, callback]);
|
|
102
|
-
return val;
|
|
103
|
-
}
|
|
104
87
|
function opMapApplier(appliers) {
|
|
105
88
|
return async (op) => {
|
|
106
89
|
const applier = appliers[op.type];
|
|
@@ -8953,7 +8936,7 @@ var DiplomaticClient = class {
|
|
|
8953
8936
|
}
|
|
8954
8937
|
const { hostURL, hostKeyPair, encKey } = this;
|
|
8955
8938
|
const paths = await this.store.listDownloads();
|
|
8956
|
-
paths.sort((p1, p2) =>
|
|
8939
|
+
paths.sort((p1, p2) => p1.localeCompare(p2));
|
|
8957
8940
|
for (const path of paths) {
|
|
8958
8941
|
const cipher = await api_default.getDelta(hostURL, path, hostKeyPair);
|
|
8959
8942
|
const packed = await crypto_default.decryptXSalsa20Poly1305Combined(cipher, encKey);
|
|
@@ -9018,8 +9001,98 @@ var DiplomaticClient = class {
|
|
|
9018
9001
|
return this.apply(op);
|
|
9019
9002
|
}
|
|
9020
9003
|
};
|
|
9004
|
+
|
|
9005
|
+
// src/react/useStateWatcher.ts
|
|
9006
|
+
import { useState as useState2, useEffect as useEffect2 } from "react";
|
|
9007
|
+
function useStateWatcher(mgr, opType, callback) {
|
|
9008
|
+
const [val, setVal] = useState2(callback());
|
|
9009
|
+
useEffect2(() => {
|
|
9010
|
+
function update() {
|
|
9011
|
+
const newVal = callback();
|
|
9012
|
+
setVal(newVal);
|
|
9013
|
+
}
|
|
9014
|
+
mgr.on(opType, update);
|
|
9015
|
+
return () => {
|
|
9016
|
+
mgr.off(opType, update);
|
|
9017
|
+
};
|
|
9018
|
+
}, [mgr, opType, callback]);
|
|
9019
|
+
return val;
|
|
9020
|
+
}
|
|
9021
|
+
|
|
9022
|
+
// src/react/initSeedView.tsx
|
|
9023
|
+
import { useState as useState3, useCallback } from "react";
|
|
9024
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9025
|
+
function InitSeedView({ client, path }) {
|
|
9026
|
+
const [seedString, setSeedString] = useState3("");
|
|
9027
|
+
const [username, setUsername] = useState3("");
|
|
9028
|
+
const genSeed = useCallback(async () => {
|
|
9029
|
+
const seed = await crypto_default.gen256BitSecureRandomSeed();
|
|
9030
|
+
const seedStr = btoh(seed);
|
|
9031
|
+
setSeedString(seedStr);
|
|
9032
|
+
}, []);
|
|
9033
|
+
const handleInitFormSubmit = useCallback(async (e) => {
|
|
9034
|
+
e.preventDefault();
|
|
9035
|
+
const seed = htob(seedString);
|
|
9036
|
+
await client.setSeed(seed);
|
|
9037
|
+
window.location.replace(path);
|
|
9038
|
+
}, [seedString, client, path]);
|
|
9039
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
9040
|
+
/* @__PURE__ */ jsx("h1", { children: "Initialize" }),
|
|
9041
|
+
/* @__PURE__ */ jsxs("form", { id: "seed", action: "/", method: "get", onSubmit: handleInitFormSubmit, style: { display: "flex", flexDirection: "column" }, children: [
|
|
9042
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: genSeed, children: "Generate" }),
|
|
9043
|
+
/* @__PURE__ */ jsx("input", { name: "password", type: "password", autoComplete: "new-password", placeholder: "Push generate to pick a seed", value: seedString, onChange: (e) => setSeedString(e.target.value) }),
|
|
9044
|
+
/* @__PURE__ */ jsx("input", { name: "username", type: "text", autoComplete: "username", placeholder: "Choose an account name (not shared)", onChange: (e) => setUsername(e.target.value), required: true }),
|
|
9045
|
+
/* @__PURE__ */ jsx("button", { type: "submit", disabled: !seedString || !username, children: "INIT" })
|
|
9046
|
+
] })
|
|
9047
|
+
] });
|
|
9048
|
+
}
|
|
9049
|
+
|
|
9050
|
+
// src/react/statusBar.tsx
|
|
9051
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
9052
|
+
function GlowingDot({ on }) {
|
|
9053
|
+
const color = on ? "#01FF70" : "#AAAAAA";
|
|
9054
|
+
const size = 6;
|
|
9055
|
+
return /* @__PURE__ */ jsx2("div", { style: { width: size, height: size, borderRadius: "50%", boxShadow: `0 0 4px ${color}`, backgroundColor: color } });
|
|
9056
|
+
}
|
|
9057
|
+
function DotLabel({ on, label }) {
|
|
9058
|
+
return /* @__PURE__ */ jsxs2("div", { style: { display: "flex", flexDirection: "row", marginRight: 16, alignItems: "center", gap: 6 }, children: [
|
|
9059
|
+
/* @__PURE__ */ jsx2(GlowingDot, { on }),
|
|
9060
|
+
label
|
|
9061
|
+
] });
|
|
9062
|
+
}
|
|
9063
|
+
function ClientStatusBar({ state }) {
|
|
9064
|
+
return /* @__PURE__ */ jsxs2(
|
|
9065
|
+
"div",
|
|
9066
|
+
{
|
|
9067
|
+
style: {
|
|
9068
|
+
marginTop: 16,
|
|
9069
|
+
borderRadius: 8,
|
|
9070
|
+
padding: "8px 16px",
|
|
9071
|
+
border: "1px solid grey",
|
|
9072
|
+
display: "flex",
|
|
9073
|
+
flexDirection: "row",
|
|
9074
|
+
justifyContent: "space-around"
|
|
9075
|
+
},
|
|
9076
|
+
children: [
|
|
9077
|
+
/* @__PURE__ */ jsx2(DotLabel, { on: state.hasSeed, label: "SEED" }),
|
|
9078
|
+
/* @__PURE__ */ jsx2(DotLabel, { on: state.hasHost, label: "HOST" }),
|
|
9079
|
+
/* @__PURE__ */ jsx2(DotLabel, { on: state.connected, label: "LINK" }),
|
|
9080
|
+
/* @__PURE__ */ jsxs2("div", { style: { marginRight: 16 }, children: [
|
|
9081
|
+
"\u21D1 ",
|
|
9082
|
+
state.numUploads
|
|
9083
|
+
] }),
|
|
9084
|
+
/* @__PURE__ */ jsxs2("div", { children: [
|
|
9085
|
+
"\u21D3 ",
|
|
9086
|
+
state.numDownloads
|
|
9087
|
+
] })
|
|
9088
|
+
]
|
|
9089
|
+
}
|
|
9090
|
+
);
|
|
9091
|
+
}
|
|
9021
9092
|
export {
|
|
9093
|
+
ClientStatusBar,
|
|
9022
9094
|
DiplomaticClient,
|
|
9095
|
+
InitSeedView,
|
|
9023
9096
|
StateManager,
|
|
9024
9097
|
Verb,
|
|
9025
9098
|
btoh,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IDiplomaticClientState } from "../types";
|
|
2
|
+
import type DiplomaticClient from "../client";
|
|
3
|
+
export declare function useClientState(client: DiplomaticClient): IDiplomaticClientState | undefined;
|
|
4
|
+
export declare function useSyncOnResume(client: DiplomaticClient): void;
|
package/dist/state.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ export declare class StateManager {
|
|
|
10
10
|
on: (opType: string, listener: () => void) => void;
|
|
11
11
|
off: (opType: string, listener: () => void) => void;
|
|
12
12
|
}
|
|
13
|
-
export declare function useStateWatcher<T>(mgr: StateManager, opType: string, callback: () => T): T;
|
|
14
13
|
interface IApplier<T extends IOp> {
|
|
15
14
|
check: (op: IOp) => op is T;
|
|
16
15
|
apply: (op: T) => Promise<void>;
|