@interncom/diplomatic 0.0.0

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/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # diplomatic
2
+
3
+ Secure sync layer for web apps.
4
+
5
+ ## Usage
6
+
7
+ ```tsx
8
+ import { useClient, StateManager, useStateWatcher } from '@interncom/diplomatic'
9
+
10
+ const appState = { count: 0 };
11
+ const stateMgr = new StateManager(async (op) => {
12
+ if (op.type === "count" && typeof op.body === "number") {
13
+ appState.count = op.body;
14
+ }
15
+ })
16
+
17
+ export default function App() {
18
+ const [client] = useClient({
19
+ seed: "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF",
20
+ hostURL: "https://diplomatic-cloudflare-host.root-a00.workers.dev",
21
+ stateManager: stateMgr,
22
+ })
23
+ const count = useStateWatcher(stateMgr, "count", () => appState.count)
24
+ const inc = () => client.upsert("count", count + 1)
25
+
26
+ return (
27
+ <>
28
+ <h1>COUNT</h1>
29
+ <h2>{count}</h2>
30
+ <button type="button" onClick={inc}>+1</button>
31
+ </>
32
+ )
33
+ }
34
+ ```
package/dist/api.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import DiplomaticClientAPI from "./shared/client";
2
+ declare const webClientAPI: DiplomaticClientAPI;
3
+ export default webClientAPI;
@@ -0,0 +1,34 @@
1
+ import type { IOp, KeyPair } from "./shared/types";
2
+ import type { IClientStateStore, DiplomaticClientState, Applier } from "./types";
3
+ import type { StateManager } from "./state";
4
+ export interface IDiplomaticClientParams {
5
+ store: IClientStateStore;
6
+ stateManager: StateManager;
7
+ seed?: string | Uint8Array;
8
+ hostURL?: string;
9
+ hostID?: string;
10
+ }
11
+ export default class DiplomaticClient {
12
+ store: IClientStateStore;
13
+ applier: Applier;
14
+ listener?: (state: DiplomaticClientState) => void;
15
+ seed?: Uint8Array;
16
+ encKey?: Uint8Array;
17
+ hostURL?: URL;
18
+ hostKeyPair?: KeyPair;
19
+ lastFetchedAt?: string;
20
+ constructor(params: IDiplomaticClientParams);
21
+ init(params: IDiplomaticClientParams): Promise<void>;
22
+ loadSeed(): Promise<void>;
23
+ setSeed(seed: Uint8Array): Promise<void>;
24
+ loadHost(): Promise<void>;
25
+ register(hostURL: string): Promise<void>;
26
+ get state(): DiplomaticClientState;
27
+ private putDelta;
28
+ getDeltas(): Promise<IOp[]>;
29
+ processDeltas(): Promise<void>;
30
+ private pushQueuedOp;
31
+ pushQueuedOps(): Promise<void>;
32
+ apply(op: IOp): Promise<void>;
33
+ upsert<T>(type: string, body: T, version?: number): Promise<void>;
34
+ }
@@ -0,0 +1,3 @@
1
+ import { LibsodiumCrypto } from "./shared/crypto/libsodium";
2
+ declare const libsodiumCrypto: LibsodiumCrypto;
3
+ export default libsodiumCrypto;
@@ -0,0 +1,8 @@
1
+ type Listener = () => void;
2
+ export declare class EventEmitter {
3
+ private events;
4
+ on(event: string, listener: Listener): void;
5
+ off(event: string, listener: Listener): void;
6
+ emit(event: string): void;
7
+ }
8
+ export {};
@@ -0,0 +1,3 @@
1
+ import useClient from "./useClient";
2
+ import { StateManager, useStateWatcher } from './state';
3
+ export { useClient, StateManager, useStateWatcher, };