@agntcy/slim-bindings 1.0.0 → 1.4.0-rc.2
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 +37 -74
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -1,107 +1,70 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@agntcy/slim-bindings`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Node.js (≥18) bindings for **SLIM**: connect apps to a SLIM server, open sessions, and exchange messages using the same Rust core as other language bindings.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- **Primary JS/TS entry point** — Install `@agntcy/slim-bindings` for Node; optional `@agntcy/slim-bindings-*` packages supply the correct native binary per OS/arch.
|
|
10
|
-
- **Rust-backed core** — Same SLIM logic as other language bindings; native code ships per platform.
|
|
11
|
-
- **TypeScript** — Typed surface and editor support (with known FFI quirks documented below).
|
|
12
|
-
- **Authentication** — Shared secret, JWT, and SPIRE-oriented flows exposed through the generated API.
|
|
13
|
-
- **Async-first** — Promise-based calls aligned with Node conventions.
|
|
14
|
-
- **UniFFI** — Generated from Mozilla’s [UniFFI](https://mozilla.github.io/uniffi-rs/) bindings.
|
|
15
|
-
|
|
16
|
-
## Installation
|
|
17
|
-
|
|
18
|
-
Published builds install from npm only (no local Rust required):
|
|
5
|
+
## Install
|
|
19
6
|
|
|
20
7
|
```bash
|
|
21
8
|
npm install @agntcy/slim-bindings
|
|
22
9
|
```
|
|
23
10
|
|
|
24
|
-
|
|
11
|
+
npm installs this package and, when published for your OS/arch, the matching optional native addon (`@agntcy/slim-bindings-*`). If install fails with a native-load error, your platform/version combo may not have a published binary yet.
|
|
25
12
|
|
|
26
|
-
|
|
13
|
+
## Module shape
|
|
27
14
|
|
|
28
|
-
|
|
15
|
+
The published entry loads the generated UniFFI/Node bindings (see `package.json` `main` / `types`). From TypeScript or ESM-aware tooling you typically import the default export from the package path your bundler resolves (examples in this repo import from `generated/slim-bindings-node.js` when running inside the bindings workspace).
|
|
29
16
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
- [Task](https://taskfile.dev/)
|
|
17
|
+
```typescript
|
|
18
|
+
import slimBindings from '@agntcy/slim-bindings';
|
|
33
19
|
|
|
34
|
-
|
|
20
|
+
slimBindings.initializeWithDefaults();
|
|
21
|
+
const service = slimBindings.getGlobalService();
|
|
22
|
+
```
|
|
35
23
|
|
|
36
|
-
|
|
24
|
+
Full TypeScript types ship under `types/` in the published package (`index.d.ts` re-exports them).
|
|
37
25
|
|
|
38
|
-
|
|
39
|
-
task generate
|
|
40
|
-
```
|
|
26
|
+
## Typical flow
|
|
41
27
|
|
|
42
|
-
|
|
28
|
+
1. **Initialize** crypto/runtime once per process:
|
|
43
29
|
|
|
44
|
-
|
|
45
|
-
# Terminal 1: Start the server
|
|
46
|
-
task example:server
|
|
30
|
+
`slimBindings.initializeWithDefaults()`
|
|
47
31
|
|
|
48
|
-
|
|
49
|
-
task example:alice
|
|
32
|
+
2. **Obtain the global service** — entry point for apps, connections, and server mode:
|
|
50
33
|
|
|
51
|
-
|
|
52
|
-
task example:bob
|
|
53
|
-
```
|
|
34
|
+
`slimBindings.getGlobalService()`
|
|
54
35
|
|
|
55
|
-
|
|
36
|
+
3. **Identity** — SLIM names are three segments: `organization/namespace/application` (constructor `new slimBindings.Name(org, ns, app)`).
|
|
56
37
|
|
|
57
|
-
|
|
58
|
-
task generate # Generate bindings
|
|
59
|
-
task clean # Clean build artifacts
|
|
60
|
-
task example:server # Run server
|
|
61
|
-
task example:alice # Run Alice receiver
|
|
62
|
-
task example:bob # Run Bob sender
|
|
63
|
-
```
|
|
38
|
+
4. **Client: create an app** — e.g. shared-secret auth:
|
|
64
39
|
|
|
65
|
-
|
|
40
|
+
`service.createAppWithSecret(name, secret)`
|
|
41
|
+
Use a secret that meets the minimum length required by your deployment (examples use a 32+ character demo string).
|
|
66
42
|
|
|
67
|
-
|
|
43
|
+
5. **Client: connect to the SLIM server** — build a client config (see `newInsecureClientConfig(url)` for development-style HTTP to the server), then:
|
|
68
44
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
- **Pointers**: BigInt ↔ Number at FFI boundaries where needed
|
|
72
|
-
- **Errors**: Clearer extraction from Rust error types
|
|
45
|
+
`await service.connectAsync(config)`
|
|
46
|
+
Returns a connection id used for routing/subscriptions.
|
|
73
47
|
|
|
74
|
-
|
|
48
|
+
6. **Subscribe** the app to receive traffic for its name (often passing `BigInt(connId)` if the generated API expects `bigint` — see note below).
|
|
75
49
|
|
|
76
|
-
|
|
50
|
+
7. **Server** — for a network node that accepts clients, initialize the same way, then build a server config (e.g. `newInsecureServerConfig('0.0.0.0:46357')`) and run:
|
|
77
51
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
await app.subscribeAsync(name, BigInt(connId));
|
|
81
|
-
app.setRoute(name, Number(connId));
|
|
82
|
-
```
|
|
52
|
+
`slimBindings.getGlobalService().runServer(config)`
|
|
53
|
+
The process must stay alive while the server runs (see examples).
|
|
83
54
|
|
|
84
|
-
|
|
85
|
-
- When calling through to FFI with u64 parameters → use `Number()` from `bigint` when required.
|
|
55
|
+
## Examples
|
|
86
56
|
|
|
87
|
-
|
|
57
|
+
Runnable scripts live under `examples/` (from repo root, use the `Taskfile` targets `example:server`, `example:alice`, `example:bob`, or run them via npm from `examples/` as documented in [README_dev.md](./README_dev.md)).
|
|
88
58
|
|
|
89
|
-
|
|
90
|
-
2. Run `task generate` (builds the Rust library and emits Node bindings).
|
|
91
|
-
3. Consume files under `generated/` or run examples (`task example:server`, etc.).
|
|
59
|
+
## `bigint` vs `number` (FFI)
|
|
92
60
|
|
|
93
|
-
|
|
61
|
+
Some APIs are typed with `bigint` for 64-bit values, but `connectAsync` may return a JavaScript `number` at runtime. When you pass that value into a method that expects `bigint` (for example `subscribeAsync`), wrap it: `BigInt(connId)`. See [README_dev.md](./README_dev.md#ffi-type-conversions) for details.
|
|
94
62
|
|
|
95
|
-
##
|
|
63
|
+
## Building from source / contributing
|
|
96
64
|
|
|
97
|
-
|
|
98
|
-
- **Version**: In `package.json`; release tags use `slim-bindings-v*` (see `.github/scripts/get-binding-version.sh`).
|
|
99
|
-
- **Secrets**: `NPM_TOKEN` for `npm publish`.
|
|
65
|
+
Generator setup, Task commands, publishing, and FFI patches are documented for maintainers in **[README_dev.md](./README_dev.md)**.
|
|
100
66
|
|
|
101
|
-
##
|
|
67
|
+
## Links
|
|
102
68
|
|
|
103
|
-
- [
|
|
104
|
-
- [
|
|
105
|
-
- [ffi-rs](https://www.npmjs.com/package/ffi-rs)
|
|
106
|
-
- [SLIM](https://github.com/agntcy/slim)
|
|
107
|
-
- [React Native bindings](../react-native/README.md)
|
|
69
|
+
- [SLIM repository](https://github.com/agntcy/slim)
|
|
70
|
+
- [React Native bindings](../react-native/README.md) (mobile / JSI)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agntcy/slim-bindings",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.4.0-rc.2",
|
|
4
4
|
"description": "SLIM Node.js bindings using UniFFI",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
},
|
|
36
36
|
"license": "Apache-2.0",
|
|
37
37
|
"optionalDependencies": {
|
|
38
|
-
"@agntcy/slim-bindings-darwin-arm64": "1.0.
|
|
39
|
-
"@agntcy/slim-bindings-darwin-x64": "1.0.
|
|
40
|
-
"@agntcy/slim-bindings-linux-arm64-gnu": "1.0.
|
|
41
|
-
"@agntcy/slim-bindings-linux-arm64-musl": "1.0.
|
|
42
|
-
"@agntcy/slim-bindings-linux-x64-gnu": "1.0.
|
|
43
|
-
"@agntcy/slim-bindings-linux-x64-musl": "1.0.
|
|
44
|
-
"@agntcy/slim-bindings-win32-arm64-msvc": "1.0.
|
|
45
|
-
"@agntcy/slim-bindings-win32-x64-gnu": "1.0.
|
|
46
|
-
"@agntcy/slim-bindings-win32-x64-msvc": "1.0.
|
|
38
|
+
"@agntcy/slim-bindings-darwin-arm64": "1.4.0-rc.2",
|
|
39
|
+
"@agntcy/slim-bindings-darwin-x64": "1.4.0-rc.2",
|
|
40
|
+
"@agntcy/slim-bindings-linux-arm64-gnu": "1.4.0-rc.2",
|
|
41
|
+
"@agntcy/slim-bindings-linux-arm64-musl": "1.4.0-rc.2",
|
|
42
|
+
"@agntcy/slim-bindings-linux-x64-gnu": "1.4.0-rc.2",
|
|
43
|
+
"@agntcy/slim-bindings-linux-x64-musl": "1.4.0-rc.2",
|
|
44
|
+
"@agntcy/slim-bindings-win32-arm64-msvc": "1.4.0-rc.2",
|
|
45
|
+
"@agntcy/slim-bindings-win32-x64-gnu": "1.4.0-rc.2",
|
|
46
|
+
"@agntcy/slim-bindings-win32-x64-msvc": "1.4.0-rc.2"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/node": "^20.0.0",
|