@interncom/diplomatic 0.1.2 → 0.2.0-rc1

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 (117) hide show
  1. package/README.md +69 -42
  2. package/dist/cli/bin/host.js +6 -0
  3. package/dist/cli/bun/src/codec.d.ts +3 -0
  4. package/dist/cli/bun/src/crypto.d.ts +3 -0
  5. package/dist/cli/bun/src/host.d.ts +1 -0
  6. package/dist/cli/bun/src/storage/sqlite.d.ts +3 -0
  7. package/dist/cli/index.js +6020 -0
  8. package/dist/cli/index.mjs +6020 -0
  9. package/dist/{shared/crypto/libsodium.d.ts → cli/shared/crypto/noble.d.ts} +1 -6
  10. package/dist/{shared → cli/shared}/types.d.ts +1 -2
  11. package/dist/cli/src/index.d.ts +44 -0
  12. package/dist/{client.d.ts → web/client.d.ts} +1 -1
  13. package/dist/web/crypto.d.ts +3 -0
  14. package/dist/{index.d.ts → web/index.d.ts} +3 -3
  15. package/dist/web/index.js +6800 -0
  16. package/dist/web/index.mjs +7645 -0
  17. package/dist/web/shared/api/peek.d.ts +3 -0
  18. package/dist/web/shared/api/pull.d.ts +3 -0
  19. package/dist/web/shared/api/push.d.ts +4 -0
  20. package/dist/web/shared/api/user.d.ts +2 -0
  21. package/dist/web/shared/auth.d.ts +8 -0
  22. package/dist/web/shared/bag.d.ts +15 -0
  23. package/dist/web/shared/binary.d.ts +8 -0
  24. package/dist/web/shared/client.d.ts +22 -0
  25. package/dist/web/shared/clock.d.ts +13 -0
  26. package/dist/web/shared/codec.d.ts +43 -0
  27. package/dist/web/shared/codecs/authTimestamp.d.ts +8 -0
  28. package/dist/web/shared/codecs/bag.d.ts +3 -0
  29. package/dist/web/shared/codecs/eid.d.ts +10 -0
  30. package/dist/web/shared/codecs/messageHead.d.ts +16 -0
  31. package/dist/web/shared/codecs/notifItem.d.ts +7 -0
  32. package/dist/web/shared/codecs/peekItem.d.ts +6 -0
  33. package/dist/web/shared/codecs/peekItemHead.d.ts +7 -0
  34. package/dist/web/shared/codecs/pullItem.d.ts +6 -0
  35. package/dist/web/shared/codecs/pushItem.d.ts +11 -0
  36. package/dist/web/shared/codecs/respHead.d.ts +10 -0
  37. package/dist/web/shared/codecs/usageQuota.d.ts +6 -0
  38. package/dist/web/shared/consts.d.ts +50 -0
  39. package/dist/web/shared/crypto/noble.d.ts +11 -0
  40. package/dist/web/shared/enclave.d.ts +8 -0
  41. package/dist/web/shared/endpoint.d.ts +23 -0
  42. package/dist/web/shared/events.d.ts +8 -0
  43. package/dist/web/shared/http/listener.d.ts +11 -0
  44. package/dist/web/shared/http/server.d.ts +14 -0
  45. package/dist/web/shared/http.d.ts +82 -0
  46. package/dist/web/shared/message.d.ts +22 -0
  47. package/dist/web/shared/singleton.d.ts +15 -0
  48. package/dist/web/shared/sync.d.ts +9 -0
  49. package/dist/web/shared/types.d.ts +163 -0
  50. package/dist/web/shared/valstat.d.ts +6 -0
  51. package/package.json +27 -11
  52. package/dist/crypto.d.ts +0 -3
  53. package/dist/exim.d.ts +0 -0
  54. package/dist/index.mjs +0 -11295
  55. package/dist/lib.d.ts +0 -2
  56. /package/dist/{shared → cli/shared}/api/peek.d.ts +0 -0
  57. /package/dist/{shared → cli/shared}/api/pull.d.ts +0 -0
  58. /package/dist/{shared → cli/shared}/api/push.d.ts +0 -0
  59. /package/dist/{shared → cli/shared}/api/user.d.ts +0 -0
  60. /package/dist/{shared → cli/shared}/auth.d.ts +0 -0
  61. /package/dist/{shared → cli/shared}/bag.d.ts +0 -0
  62. /package/dist/{shared → cli/shared}/binary.d.ts +0 -0
  63. /package/dist/{shared → cli/shared}/client.d.ts +0 -0
  64. /package/dist/{shared → cli/shared}/clock.d.ts +0 -0
  65. /package/dist/{shared → cli/shared}/codec.d.ts +0 -0
  66. /package/dist/{shared → cli/shared}/codecs/authTimestamp.d.ts +0 -0
  67. /package/dist/{shared → cli/shared}/codecs/bag.d.ts +0 -0
  68. /package/dist/{shared → cli/shared}/codecs/eid.d.ts +0 -0
  69. /package/dist/{shared → cli/shared}/codecs/messageHead.d.ts +0 -0
  70. /package/dist/{shared → cli/shared}/codecs/notifItem.d.ts +0 -0
  71. /package/dist/{shared → cli/shared}/codecs/peekItem.d.ts +0 -0
  72. /package/dist/{shared → cli/shared}/codecs/peekItemHead.d.ts +0 -0
  73. /package/dist/{shared → cli/shared}/codecs/pullItem.d.ts +0 -0
  74. /package/dist/{shared → cli/shared}/codecs/pushItem.d.ts +0 -0
  75. /package/dist/{shared → cli/shared}/codecs/respHead.d.ts +0 -0
  76. /package/dist/{shared → cli/shared}/codecs/usageQuota.d.ts +0 -0
  77. /package/dist/{shared → cli/shared}/consts.d.ts +0 -0
  78. /package/dist/{shared → cli/shared}/enclave.d.ts +0 -0
  79. /package/dist/{shared → cli/shared}/endpoint.d.ts +0 -0
  80. /package/dist/{shared → cli/shared}/events.d.ts +0 -0
  81. /package/dist/{shared → cli/shared}/http/listener.d.ts +0 -0
  82. /package/dist/{shared → cli/shared}/http/server.d.ts +0 -0
  83. /package/dist/{shared → cli/shared}/http.d.ts +0 -0
  84. /package/dist/{shared → cli/shared}/message.d.ts +0 -0
  85. /package/dist/{shared → cli/shared}/singleton.d.ts +0 -0
  86. /package/dist/{shared → cli/shared}/sync.d.ts +0 -0
  87. /package/dist/{shared → cli/shared}/valstat.d.ts +0 -0
  88. /package/dist/{entdb → web/entdb}/entdb.d.ts +0 -0
  89. /package/dist/{entdb → web/entdb}/idb.d.ts +0 -0
  90. /package/dist/{entdb → web/entdb}/memory.d.ts +0 -0
  91. /package/dist/{events.d.ts → web/events.d.ts} +0 -0
  92. /package/dist/{react → web/react}/useClient.d.ts +0 -0
  93. /package/dist/{react → web/react}/useEntities.d.ts +0 -0
  94. /package/dist/{react → web/react}/useStateWatcher.d.ts +0 -0
  95. /package/dist/{shared → web/shared}/codecs/file.d.ts +0 -0
  96. /package/dist/{shared → web/shared}/codecs/fileHead.d.ts +0 -0
  97. /package/dist/{shared → web/shared}/codecs/fileIndexItem.d.ts +0 -0
  98. /package/dist/{shared → web/shared}/exim.d.ts +0 -0
  99. /package/dist/{shared → web/shared}/lpc/listener.d.ts +0 -0
  100. /package/dist/{shared → web/shared}/lpc/pusher.d.ts +0 -0
  101. /package/dist/{shared → web/shared}/lpc/server.d.ts +0 -0
  102. /package/dist/{shared → web/shared}/storage/memory.d.ts +0 -0
  103. /package/dist/{state.d.ts → web/state.d.ts} +0 -0
  104. /package/dist/{stores → web/stores}/idb/dnlds.d.ts +0 -0
  105. /package/dist/{stores → web/stores}/idb/hosts.d.ts +0 -0
  106. /package/dist/{stores → web/stores}/idb/msgs.d.ts +0 -0
  107. /package/dist/{stores → web/stores}/idb/seed.d.ts +0 -0
  108. /package/dist/{stores → web/stores}/idb/store.d.ts +0 -0
  109. /package/dist/{stores → web/stores}/idb/uplds.d.ts +0 -0
  110. /package/dist/{stores → web/stores}/memory/dnlds.d.ts +0 -0
  111. /package/dist/{stores → web/stores}/memory/hosts.d.ts +0 -0
  112. /package/dist/{stores → web/stores}/memory/msgs.d.ts +0 -0
  113. /package/dist/{stores → web/stores}/memory/seed.d.ts +0 -0
  114. /package/dist/{stores → web/stores}/memory/store.d.ts +0 -0
  115. /package/dist/{stores → web/stores}/memory/uplds.d.ts +0 -0
  116. /package/dist/{sync.d.ts → web/sync.d.ts} +0 -0
  117. /package/dist/{types.d.ts → web/types.d.ts} +0 -0
package/README.md CHANGED
@@ -1,46 +1,73 @@
1
- # diplomatic
2
-
3
- Secure sync layer for web apps.
4
-
5
- ## Usage
6
-
7
- ```tsx
8
- import {
9
- DiplomaticClient,
10
- localStorageStore,
11
- StateManager,
12
- useStateWatcher,
13
- } from "@interncom/diplomatic";
14
-
15
- const appState = { count: 0 };
16
- const stateMgr = new StateManager(async (op) => {
17
- if (op.type === "count" && typeof op.body === "number") {
18
- appState.count = op.body;
19
- }
20
- });
21
-
22
- const client = new DiplomaticClient({
23
- seed: "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF",
24
- hostURL: "https://diplomatic-cloudflare-host.root-a00.workers.dev",
25
- stateManager: stateMgr,
26
- store: localStorageStore,
27
- });
28
-
29
- export default function App() {
30
- const count = useStateWatcher(stateMgr, "count", () => appState.count);
31
- const inc = () => client.upsert("count", count + 1);
32
-
33
- return (
34
- <div style={{ width: "100vw", textAlign: "center" }}>
35
- <h1>COUNT</h1>
36
- <h2>{count}</h2>
37
- <button onClick={inc}>+1</button>
38
- </div>
39
- );
1
+ # @interncom/diplomatic Package
2
+
3
+ This directory manages the build and packaging of the `@interncom/diplomatic` NPM module, which provides secure sync layer and CLI utilities for the DIPLOMATIC protocol.
4
+
5
+ ## Overview
6
+
7
+ The `@interncom/diplomatic` package exposes both web (browser) and CLI (Node.js) components from the monorepo:
8
+
9
+ - **Web components**: React hooks, client APIs, and storage utilities for browser-based applications
10
+ - **CLI components**: Command-line tools and host server for Node.js environments
11
+
12
+ ## Building the NPM Module
13
+
14
+ First, install dependencies:
15
+
16
+ ```bash
17
+ bun install
18
+ ```
19
+
20
+ To clean previous builds:
21
+
22
+ ```bash
23
+ bun run clean
24
+ ```
25
+
26
+ Then run the build script to generate the distribution bundles:
27
+
28
+ ```bash
29
+ bun run build
30
+ ```
31
+
32
+ This command:
33
+ 1. Builds the web bundle (`dist/web/index.mjs`) from `../web/src/index.ts`
34
+ 2. Builds the CLI bundle (`dist/cli/index.mjs`) from `../web/src/cli/index.ts` (with external dependencies like `libsodium-wrappers`)
35
+ 3. Generates the CLI binary (`dist/cli/bin/host.js`) for the `diplomatic-host` command
36
+
37
+ Note: The CLI bundle uses external dependencies that must be installed and available at runtime.
38
+
39
+ ## Package Exports
40
+
41
+ The package uses conditional exports for environment-specific loading:
42
+
43
+ ```json
44
+ {
45
+ ".": {
46
+ "browser": "./dist/web/index.mjs",
47
+ "node": "./dist/cli/index.mjs"
48
+ },
49
+ "./web": "./dist/web/index.mjs",
50
+ "./cli": "./dist/cli/index.mjs"
40
51
  }
41
52
  ```
42
53
 
43
- ## Development
54
+ - **Browser environments**: Automatically loads web components
55
+ - **Node.js environments**: Automatically loads CLI components
56
+ - **Explicit imports**: Use `./web` or `./cli` subpaths for specific components
57
+
58
+ ## Dependencies
59
+
60
+ This package pulls source code from:
61
+ - `../shared/`: Common TypeScript utilities
62
+ - `../web/`: Web client source
63
+ - `../bun/`: Additional utilities (via symlinks in `../web/src/`)
64
+
65
+ ## Publishing
66
+
67
+ To publish the package:
68
+
69
+ ```bash
70
+ npm publish
71
+ ```
44
72
 
45
- To deploy npm package, from the `web` dir, run:
46
- `npm run build && npm run tsc && npm publish --public`.
73
+ The package is configured for public access with scoped name `@interncom/diplomatic`.
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { runBunHost } from '../index.mjs';
4
+
5
+ const port = process.argv[2] ? Number.parseInt(process.argv[2]) : undefined;
6
+ runBunHost(port);
@@ -0,0 +1,3 @@
1
+ import type { IMsgpackCodec } from "../../shared/types.ts";
2
+ declare const bunMsgpack: IMsgpackCodec;
3
+ export default bunMsgpack;
@@ -0,0 +1,3 @@
1
+ import { NobleCrypto } from "../../shared/crypto/noble.ts";
2
+ declare const crypto: NobleCrypto;
3
+ export default crypto;
@@ -0,0 +1 @@
1
+ export declare function runBunHost(port?: number): Promise<void>;
@@ -0,0 +1,3 @@
1
+ import type { IStorage } from "../../../shared/types.ts";
2
+ declare const sqliteStorage: IStorage;
3
+ export default sqliteStorage;