@enbox/api 0.6.24 → 0.6.26
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/browser.mjs +19 -11
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/enbox-types.js +11 -0
- package/dist/esm/enbox-types.js.map +1 -0
- package/dist/esm/enbox.js +300 -40
- package/dist/esm/enbox.js.map +1 -1
- package/dist/esm/index.js +7 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/read-only-record.js.map +1 -1
- package/dist/esm/repository.js +29 -3
- package/dist/esm/repository.js.map +1 -1
- package/dist/types/enbox-types.d.ts +94 -0
- package/dist/types/enbox-types.d.ts.map +1 -0
- package/dist/types/enbox.d.ts +141 -74
- package/dist/types/enbox.d.ts.map +1 -1
- package/dist/types/index.d.ts +8 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/repository.d.ts +19 -0
- package/dist/types/repository.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/enbox-types.ts +111 -0
- package/src/enbox.ts +340 -83
- package/src/index.ts +8 -5
- package/src/read-only-record.ts +1 -1
- package/src/repository.ts +30 -4
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public type surface for the {@link Enbox} class.
|
|
3
|
+
*
|
|
4
|
+
* Session and connect types are derived from
|
|
5
|
+
* {@link AgentSessionPrimitives} in `@enbox/agent`, so the minimal session
|
|
6
|
+
* shape lives in one place and downstream packages stay in sync.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { AgentSessionPrimitives } from '@enbox/agent';
|
|
11
|
+
import type { AuthManager } from '@enbox/auth/auth-manager';
|
|
12
|
+
import type { DidMethodResolver } from '@enbox/dids';
|
|
13
|
+
import type { AuthManagerOptions, AuthSession, HandlerConnectOptions, VaultConnectOptions } from '@enbox/auth';
|
|
14
|
+
import type { DwnReaderApi } from './dwn-reader-api.js';
|
|
15
|
+
import type { Enbox } from './enbox.js';
|
|
16
|
+
/**
|
|
17
|
+
* Options for creating an anonymous (read-only) Enbox instance via {@link Enbox.anonymous}.
|
|
18
|
+
*
|
|
19
|
+
* @beta
|
|
20
|
+
*/
|
|
21
|
+
export type EnboxAnonymousOptions = {
|
|
22
|
+
/** Override the default DID method resolvers. Defaults to `[DidDht, DidJwk, DidKey, DidWeb]`. */
|
|
23
|
+
didResolvers?: DidMethodResolver[];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The result of calling {@link Enbox.anonymous}.
|
|
27
|
+
*
|
|
28
|
+
* Contains only a read-only `dwn` property — no `did`, `vc`, or `agent`.
|
|
29
|
+
*
|
|
30
|
+
* @beta
|
|
31
|
+
*/
|
|
32
|
+
export type EnboxAnonymousApi = {
|
|
33
|
+
/** A read-only DWN API for querying public data on remote DWNs. */
|
|
34
|
+
dwn: DwnReaderApi;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Parameters for constructing an {@link Enbox} instance.
|
|
38
|
+
*
|
|
39
|
+
* These are the minimal primitives needed to interact with the DWN network.
|
|
40
|
+
* Typically obtained from an agent session via `@enbox/auth`.
|
|
41
|
+
*
|
|
42
|
+
* Built on {@link AgentSessionPrimitives}: same `agent`/`delegateDid` shape,
|
|
43
|
+
* with `did` renamed to `connectedDid` to mirror the constructor parameter
|
|
44
|
+
* name used throughout `@enbox/api` for the tenant DID.
|
|
45
|
+
*/
|
|
46
|
+
export type EnboxParams = Omit<AgentSessionPrimitives, 'did'> & {
|
|
47
|
+
/** The DID of the tenant under which all DID, DWN, and VC requests are being performed. */
|
|
48
|
+
connectedDid: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Session-shaped parameters accepted by {@link Enbox.fromSession}.
|
|
52
|
+
*
|
|
53
|
+
* Alias for {@link AgentSessionPrimitives} so callers can pass an
|
|
54
|
+
* `AuthSession` from `@enbox/auth`, an `AgentSession` from `@enbox/agent`, or
|
|
55
|
+
* any compatible custom session without duplicating field declarations.
|
|
56
|
+
*/
|
|
57
|
+
export type EnboxSessionParams = AgentSessionPrimitives;
|
|
58
|
+
/**
|
|
59
|
+
* High-level connection options for {@link Enbox.connect}.
|
|
60
|
+
*
|
|
61
|
+
* Composed of two parts:
|
|
62
|
+
*
|
|
63
|
+
* 1. **Manager-wide defaults** ({@link AuthManagerOptions}) — `password`,
|
|
64
|
+
* `sync`, `dwnEndpoints`, `connectHandler`, etc. Forwarded to
|
|
65
|
+
* `AuthManager.create()` and reused across reconnects.
|
|
66
|
+
* 2. **Per-call signals** ({@link HandlerConnectOptions} ∪
|
|
67
|
+
* {@link VaultConnectOptions}) — `protocols`, `createIdentity`,
|
|
68
|
+
* `recoveryPhrase`, `metadata`, etc. Forwarded to
|
|
69
|
+
* `AuthManager.connect()` and used to route handler vs local flow.
|
|
70
|
+
*
|
|
71
|
+
* Several fields (`password`, `sync`, `dwnEndpoints`, `connectHandler`)
|
|
72
|
+
* appear on multiple parents. The intersection keeps a single `?:`-typed
|
|
73
|
+
* field; the value flows to both the manager (as a default) and the
|
|
74
|
+
* per-call payload — matching the behavior of restored sessions.
|
|
75
|
+
*
|
|
76
|
+
* Routing between local and handler flow happens at runtime inside
|
|
77
|
+
* `AuthManager._isLocalConnect` based on whether `protocols` or
|
|
78
|
+
* `connectHandler` is provided. See `Enbox.connect()` for examples.
|
|
79
|
+
*
|
|
80
|
+
* If you need full control of the exact options forwarded to
|
|
81
|
+
* `AuthManager.connect()`, drop down one layer: create the
|
|
82
|
+
* `AuthManager` yourself and pass its session to `Enbox.fromSession`.
|
|
83
|
+
*/
|
|
84
|
+
export type EnboxConnectOptions = AuthManagerOptions & HandlerConnectOptions & VaultConnectOptions;
|
|
85
|
+
/** The result of a high-level asynchronous {@link Enbox.connect} call. */
|
|
86
|
+
export type EnboxConnectResult = {
|
|
87
|
+
/** The AuthManager that owns the session lifecycle. */
|
|
88
|
+
auth: AuthManager;
|
|
89
|
+
/** The high-level Enbox API instance. */
|
|
90
|
+
enbox: Enbox;
|
|
91
|
+
/** The active session returned by `AuthManager.connect()`. */
|
|
92
|
+
session: AuthSession;
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=enbox-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enbox-types.d.ts","sourceRoot":"","sources":["../../src/enbox-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EACV,kBAAkB,EAClB,WAAW,EACX,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,iGAAiG;IACjG,YAAY,CAAC,EAAE,iBAAiB,EAAE,CAAC;CACpC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,mEAAmE;IACnE,GAAG,EAAE,YAAY,CAAC;CACnB,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,sBAAsB,EAAE,KAAK,CAAC,GAAG;IAC9D,2FAA2F;IAC3F,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,mBAAmB,GAC3B,kBAAkB,GAClB,qBAAqB,GACrB,mBAAmB,CAAC;AAExB,0EAA0E;AAC1E,MAAM,MAAM,kBAAkB,GAAG;IAC/B,uDAAuD;IACvD,IAAI,EAAE,WAAW,CAAC;IAElB,yCAAyC;IACzC,KAAK,EAAE,KAAK,CAAC;IAEb,8DAA8D;IAC9D,OAAO,EAAE,WAAW,CAAC;CACtB,CAAC"}
|
package/dist/types/enbox.d.ts
CHANGED
|
@@ -2,79 +2,43 @@
|
|
|
2
2
|
* NOTE: Added reference types here to avoid a `pnpm` bug during build.
|
|
3
3
|
* https://github.com/enboxorg/enbox/pull/507
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
6
|
-
import type { DidMethodResolver } from '@enbox/dids';
|
|
7
|
-
import type { EnboxAgent } from '@enbox/agent';
|
|
5
|
+
import type { EnboxPlatformAgent } from '@enbox/agent';
|
|
8
6
|
import type { ProtocolDefinition } from '@enbox/dwn-sdk-js';
|
|
7
|
+
import type { EnboxAnonymousApi, EnboxAnonymousOptions, EnboxConnectOptions, EnboxConnectResult, EnboxParams, EnboxSessionParams } from './enbox-types.js';
|
|
9
8
|
import type { SchemaMap, TypedProtocol } from './protocol-types.js';
|
|
10
9
|
import { DidApi } from './did-api.js';
|
|
11
|
-
import { DwnReaderApi } from './dwn-reader-api.js';
|
|
12
10
|
import { TypedEnbox } from './typed-enbox.js';
|
|
13
11
|
import { VcApi } from './vc-api.js';
|
|
14
|
-
/**
|
|
15
|
-
* Options for creating an anonymous (read-only) Enbox instance via {@link Enbox.anonymous}.
|
|
16
|
-
*
|
|
17
|
-
* @beta
|
|
18
|
-
*/
|
|
19
|
-
export type EnboxAnonymousOptions = {
|
|
20
|
-
/** Override the default DID method resolvers. Defaults to `[DidDht, DidJwk, DidKey, DidWeb]`. */
|
|
21
|
-
didResolvers?: DidMethodResolver[];
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* The result of calling {@link Enbox.anonymous}.
|
|
25
|
-
*
|
|
26
|
-
* Contains only a read-only `dwn` property — no `did`, `vc`, or `agent`.
|
|
27
|
-
*
|
|
28
|
-
* @beta
|
|
29
|
-
*/
|
|
30
|
-
export type EnboxAnonymousApi = {
|
|
31
|
-
/** A read-only DWN API for querying public data on remote DWNs. */
|
|
32
|
-
dwn: DwnReaderApi;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Parameters for constructing an {@link Enbox} instance.
|
|
36
|
-
*
|
|
37
|
-
* These are the minimal primitives needed to interact with the DWN network.
|
|
38
|
-
* Typically obtained from an {@link AuthSession} via `@enbox/auth`.
|
|
39
|
-
*/
|
|
40
|
-
export type EnboxParams = {
|
|
41
|
-
/**
|
|
42
|
-
* A {@link EnboxAgent} instance that handles DIDs, DWNs and VCs requests. The agent manages the
|
|
43
|
-
* user keys and identities, and is responsible to sign and verify messages.
|
|
44
|
-
*/
|
|
45
|
-
agent: EnboxAgent;
|
|
46
|
-
/** The DID of the tenant under which all DID, DWN, and VC requests are being performed. */
|
|
47
|
-
connectedDid: string;
|
|
48
|
-
/** The DID that will be signing messages using grants from the connectedDid. */
|
|
49
|
-
delegateDid?: string;
|
|
50
|
-
};
|
|
51
12
|
/**
|
|
52
13
|
* The main Enbox API interface. It provides protocol-scoped access to
|
|
53
14
|
* Decentralized Web Nodes (DWNs), Decentralized Identifiers (DIDs),
|
|
54
15
|
* and Verifiable Credentials (VCs).
|
|
55
16
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
17
|
+
* For common app flows, use the asynchronous {@link Enbox.connect} helper.
|
|
18
|
+
* For custom auth/session flows, use {@link Enbox.fromSession} with an
|
|
19
|
+
* existing session, or the public constructor with raw `{ agent, connectedDid }`.
|
|
59
20
|
*
|
|
60
21
|
* @example
|
|
61
22
|
* ```ts
|
|
62
|
-
* import { AuthManager } from '@enbox/auth';
|
|
63
23
|
* import { Enbox } from '@enbox/api';
|
|
64
24
|
*
|
|
65
|
-
* const
|
|
66
|
-
*
|
|
25
|
+
* const { enbox } = await Enbox.connect({
|
|
26
|
+
* createIdentity: true,
|
|
27
|
+
* sync: '15s',
|
|
28
|
+
* });
|
|
67
29
|
*
|
|
68
|
-
* const enbox = Enbox.connect({ session });
|
|
69
30
|
* const social = enbox.using(SocialProtocol);
|
|
70
31
|
* ```
|
|
71
32
|
*/
|
|
72
33
|
export declare class Enbox {
|
|
73
34
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
35
|
+
* The {@link EnboxPlatformAgent} this instance is bound to. The platform
|
|
36
|
+
* agent handles DIDs, DWN access, signing keys, and DWN sync — every
|
|
37
|
+
* Enbox session needs all of those, so the type is narrower than the
|
|
38
|
+
* minimal {@link EnboxAgent} interface and the constructor refuses
|
|
39
|
+
* non-platform agents at compile time.
|
|
76
40
|
*/
|
|
77
|
-
agent:
|
|
41
|
+
agent: EnboxPlatformAgent;
|
|
78
42
|
/** Exposed instance to the DID APIs, allow users to create and resolve DIDs. */
|
|
79
43
|
did: DidApi;
|
|
80
44
|
/** Internal DWN API instance. Use {@link Enbox.using} for protocol-scoped access. */
|
|
@@ -89,6 +53,20 @@ export declare class Enbox {
|
|
|
89
53
|
private readonly _typedInstances;
|
|
90
54
|
/** Exposed instance to the VC APIs, allow users to issue, present and verify VCs. */
|
|
91
55
|
vc: VcApi;
|
|
56
|
+
/**
|
|
57
|
+
* The `AuthManager` this instance owns and is responsible for tearing down
|
|
58
|
+
* during {@link Enbox.disconnect}. Set only by the async
|
|
59
|
+
* {@link Enbox.connect} factory; never populated by the public constructor
|
|
60
|
+
* or {@link Enbox.fromSession}.
|
|
61
|
+
*/
|
|
62
|
+
private _ownedAuth?;
|
|
63
|
+
/**
|
|
64
|
+
* Memoized teardown promise. Two parallel `enbox.disconnect()` calls
|
|
65
|
+
* share the same promise so `agent.sync.stopSync()` (and the optional
|
|
66
|
+
* `auth.shutdown()`) run exactly once even when callers fire the
|
|
67
|
+
* teardown from independent code paths.
|
|
68
|
+
*/
|
|
69
|
+
private _disconnecting?;
|
|
92
70
|
constructor({ agent, connectedDid, delegateDid }: EnboxParams);
|
|
93
71
|
/**
|
|
94
72
|
* Returns a {@link TypedEnbox} instance scoped to the given protocol.
|
|
@@ -120,23 +98,57 @@ export declare class Enbox {
|
|
|
120
98
|
*/
|
|
121
99
|
using<D extends ProtocolDefinition, M extends SchemaMap>(protocol: TypedProtocol<D, M>): TypedEnbox<D, M>;
|
|
122
100
|
/**
|
|
123
|
-
*
|
|
101
|
+
* Signs the user out and releases resources held by this Enbox instance.
|
|
102
|
+
*
|
|
103
|
+
* When this instance owns the underlying `AuthManager` (i.e. it was
|
|
104
|
+
* created via `Enbox.connect()` with no caller-supplied `agent`), the
|
|
105
|
+
* disconnect proceeds in three phases:
|
|
106
|
+
*
|
|
107
|
+
* 1. **Stop sync** — `agent.sync.stopSync(timeout)` halts the DWN
|
|
108
|
+
* sync engine. Always runs, regardless of ownership.
|
|
109
|
+
* 2. **Sign out** — `AuthManager.disconnect()` sends delegate-grant
|
|
110
|
+
* revocations to the connected DWN endpoints, clears session
|
|
111
|
+
* restore markers (PREVIOUSLY_CONNECTED, ACTIVE_IDENTITY,
|
|
112
|
+
* delegate keys, etc.) from the StorageAdapter, and clears the
|
|
113
|
+
* in-memory delegate decryption key cache. **Without this step
|
|
114
|
+
* a later `Enbox.connect()` would silently restore the
|
|
115
|
+
* supposedly signed-out session from the persisted markers.**
|
|
116
|
+
* 3. **Release resources** — `AuthManager.shutdown()` locks the
|
|
117
|
+
* vault, closes the sync engine, and closes the StorageAdapter.
|
|
118
|
+
*
|
|
119
|
+
* When the instance was created from a caller-owned session
|
|
120
|
+
* ({@link Enbox.fromSession}), a raw agent (the public constructor),
|
|
121
|
+
* or `Enbox.connect({ agent })`, only step 1 (stop sync) runs — the
|
|
122
|
+
* caller's AuthManager / agent keep their lifecycle. The caller is
|
|
123
|
+
* responsible for calling `auth.disconnect()` and `auth.shutdown()`
|
|
124
|
+
* on their own handle when they're done.
|
|
124
125
|
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* `disconnect()`, the `Enbox` instance should not be reused.
|
|
126
|
+
* Idempotent: parallel calls share the same teardown promise. After
|
|
127
|
+
* calling `disconnect()`, the `Enbox` instance should not be reused.
|
|
128
128
|
*
|
|
129
129
|
* @param timeout - Maximum milliseconds to wait for an in-progress sync
|
|
130
130
|
* cycle to finish before force-stopping. Defaults to `2000`.
|
|
131
131
|
*
|
|
132
132
|
* @example
|
|
133
133
|
* ```ts
|
|
134
|
-
*
|
|
134
|
+
* // High-level flow: a single disconnect() does sign-out + teardown.
|
|
135
|
+
* const { enbox } = await Enbox.connect({ createIdentity: true });
|
|
136
|
+
* // ... user uses the app ...
|
|
137
|
+
* await enbox.disconnect(); // revoke grants, clear markers, close vault
|
|
138
|
+
*
|
|
139
|
+
* // Caller-owned auth: enbox.disconnect() only stops Enbox-side state.
|
|
140
|
+
* const auth = await AuthManager.create({...});
|
|
141
|
+
* const session = await auth.connect();
|
|
142
|
+
* const enbox = Enbox.fromSession(session);
|
|
143
|
+
* await enbox.disconnect(); // stops sync + clears typed-enbox cache
|
|
144
|
+
* await auth.disconnect(); // sign-out: caller's responsibility
|
|
145
|
+
* await auth.shutdown(); // close resources: caller's responsibility
|
|
135
146
|
* ```
|
|
136
147
|
*
|
|
137
148
|
* @beta
|
|
138
149
|
*/
|
|
139
150
|
disconnect(timeout?: number): Promise<void>;
|
|
151
|
+
private _doDisconnect;
|
|
140
152
|
/**
|
|
141
153
|
* Creates a lightweight, read-only Enbox instance for querying public DWN data.
|
|
142
154
|
*
|
|
@@ -165,30 +177,85 @@ export declare class Enbox {
|
|
|
165
177
|
*/
|
|
166
178
|
static anonymous(options?: EnboxAnonymousOptions): EnboxAnonymousApi;
|
|
167
179
|
/**
|
|
168
|
-
* Creates an {@link Enbox} instance from
|
|
180
|
+
* Creates an {@link Enbox} instance from a session-shaped object.
|
|
181
|
+
*
|
|
182
|
+
* Accepts `AuthSession`, `AgentSession`, or any compatible custom session
|
|
183
|
+
* with `{ agent, did, delegateDid? }`. This is the right entry point
|
|
184
|
+
* whenever you already hold an active session — including ones produced by
|
|
185
|
+
* a caller-managed `AuthManager`.
|
|
186
|
+
*
|
|
187
|
+
* For raw `{ agent, connectedDid }` access (no session shape), use the
|
|
188
|
+
* public constructor directly: `new Enbox({ agent, connectedDid })`.
|
|
189
|
+
*/
|
|
190
|
+
static fromSession(session: EnboxSessionParams): Enbox;
|
|
191
|
+
/**
|
|
192
|
+
* High-level entry point that creates an {@link AuthManager}, runs
|
|
193
|
+
* `auth.connect()`, and returns the resulting `{ auth, session, enbox }`.
|
|
194
|
+
*
|
|
195
|
+
* For callers that already own an agent and DID, use the dedicated
|
|
196
|
+
* synchronous entry points instead:
|
|
197
|
+
* - `new Enbox({ agent, connectedDid })` for raw parameters
|
|
198
|
+
* - {@link Enbox.fromSession} for session-shaped objects
|
|
169
199
|
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
200
|
+
* Routing happens at runtime inside `AuthManager._isVaultConnect`:
|
|
201
|
+
* presence of a non-empty `protocols` array or a `connectHandler` selects
|
|
202
|
+
* the handler flow; everything else routes to local. Local-style fields
|
|
203
|
+
* (`password`, `dwnEndpoints`, etc.) are forwarded to both the manager
|
|
204
|
+
* (as defaults) and the per-call payload, so behavior is consistent with
|
|
205
|
+
* restored sessions.
|
|
173
206
|
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
207
|
+
* If you need exact control of the `AuthManager.connect()` payload,
|
|
208
|
+
* drop down one layer: create the `AuthManager` yourself with
|
|
209
|
+
* `AuthManager.create()`, call `auth.connect(...)` with your exact
|
|
210
|
+
* options, and pass the resulting session to `Enbox.fromSession`.
|
|
177
211
|
*
|
|
178
212
|
* @example
|
|
179
213
|
* ```ts
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
* const enbox = Enbox.connect({ session });
|
|
185
|
-
*
|
|
186
|
-
* // Using raw parameters
|
|
187
|
-
* const enbox = Enbox.connect({ agent, connectedDid: did });
|
|
214
|
+
* const { enbox, session, auth } = await Enbox.connect({ createIdentity: true });
|
|
215
|
+
* // ...
|
|
216
|
+
* await enbox.disconnect();
|
|
217
|
+
* await auth.shutdown(); // release vault + storage handles
|
|
188
218
|
* ```
|
|
189
219
|
*/
|
|
190
|
-
static connect(
|
|
191
|
-
|
|
192
|
-
|
|
220
|
+
static connect(options?: EnboxConnectOptions): Promise<EnboxConnectResult>;
|
|
221
|
+
/**
|
|
222
|
+
* Split `EnboxConnectOptions` into the manager-wide defaults that
|
|
223
|
+
* `AuthManager.create()` consumes.
|
|
224
|
+
*
|
|
225
|
+
* Implemented as an **explicit allowlist** for the same reason as
|
|
226
|
+
* `toAuthConnectOptions`: a denylist would silently leak future
|
|
227
|
+
* `HandlerConnectOptions` / `VaultConnectOptions` fields into the
|
|
228
|
+
* manager-default record. The `satisfies Partial<AuthManagerOptions>`
|
|
229
|
+
* annotation makes the compiler verify every key in the allowlist
|
|
230
|
+
* exists on `AuthManagerOptions`, so a misspelled or stale field name
|
|
231
|
+
* is a type error.
|
|
232
|
+
*/
|
|
233
|
+
private static toAuthManagerOptions;
|
|
234
|
+
/**
|
|
235
|
+
* Split `EnboxConnectOptions` into the per-call payload that
|
|
236
|
+
* `AuthManager.connect()` consumes.
|
|
237
|
+
*
|
|
238
|
+
* Implemented as an **explicit allowlist** of the fields declared on
|
|
239
|
+
* {@link HandlerConnectOptions} ∪ {@link VaultConnectOptions}. A
|
|
240
|
+
* denylist (strip manager-only fields, forward the rest) would
|
|
241
|
+
* silently leak any future `AuthManagerOptions` field into
|
|
242
|
+
* `AuthManager.connect()`; the allowlist makes the type boundary
|
|
243
|
+
* explicit and the leak impossible. The trade-off is symmetric:
|
|
244
|
+
* any new connect-options field requires an edit here. That's
|
|
245
|
+
* acceptable — it's the same edit the public `ConnectOptions` type
|
|
246
|
+
* already needs, just on one extra line.
|
|
247
|
+
*
|
|
248
|
+
* The `satisfies Partial<ConnectOptions>` annotation makes the
|
|
249
|
+
* compiler verify every key in the allowlist exists on `ConnectOptions`,
|
|
250
|
+
* so misspelling a field name is a type error rather than a silent
|
|
251
|
+
* drop. Routing between local and handler flow happens inside
|
|
252
|
+
* `AuthManager._isVaultConnect` based on the presence of `protocols`
|
|
253
|
+
* / `connectHandler`.
|
|
254
|
+
*
|
|
255
|
+
* `protocols: []` is normalized away — an empty array carries no
|
|
256
|
+
* permission intent and would otherwise produce a zero-grant
|
|
257
|
+
* "connected" handler session indistinguishable from a denied connect.
|
|
258
|
+
*/
|
|
259
|
+
private static toAuthConnectOptions;
|
|
193
260
|
}
|
|
194
261
|
//# sourceMappingURL=enbox.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enbox.d.ts","sourceRoot":"","sources":["../../src/enbox.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"enbox.d.ts","sourceRoot":"","sources":["../../src/enbox.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAG5D,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAQpE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAkBpC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,KAAK;IAChB;;;;;;OAMG;IACI,KAAK,EAAE,kBAAkB,CAAC;IAEjC,gFAAgF;IACzE,GAAG,EAAE,MAAM,CAAC;IAEnB,qFAAqF;IACrF,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAE9B;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAgE;IAEhG,qFAAqF;IAC9E,EAAE,EAAE,KAAK,CAAC;IAEjB;;;;;OAKG;IACH,OAAO,CAAC,UAAU,CAAC,CAAc;IAEjC;;;;;OAKG;IACH,OAAO,CAAC,cAAc,CAAC,CAAgB;gBAE3B,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,EAAE,WAAW;IAO7D;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACI,KAAK,CAAC,CAAC,SAAS,kBAAkB,EAAE,CAAC,SAAS,SAAS,EAC5D,QAAQ,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,GAC5B,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;IAenB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiDG;IACU,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAY1C,aAAa;IAwC3B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;WACW,SAAS,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,iBAAiB;IAc3E;;;;;;;;;;OAUG;WACW,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,KAAK;IAQ7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;WACiB,OAAO,CAAC,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAqF3F;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAmBnC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;CAyBpC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,16 +4,18 @@
|
|
|
4
4
|
* The SDK provides protocol-scoped access to DWN records with compile-time
|
|
5
5
|
* type safety, DID management, and Verifiable Credential operations.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* Common authentication and identity setup is available through
|
|
8
|
+
* `Enbox.connect()`. Advanced session management can use `@enbox/auth` or
|
|
9
|
+
* `@enbox/agent` directly.
|
|
8
10
|
*
|
|
9
11
|
* @example
|
|
10
12
|
* ```ts
|
|
11
|
-
* import { AuthManager } from '@enbox/auth';
|
|
12
13
|
* import { Enbox } from '@enbox/api';
|
|
13
14
|
*
|
|
14
|
-
* const
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* const { enbox } = await Enbox.connect({
|
|
16
|
+
* createIdentity: true,
|
|
17
|
+
* sync: '15s',
|
|
18
|
+
* });
|
|
17
19
|
* ```
|
|
18
20
|
*
|
|
19
21
|
* [Link to GitHub Repo](https://github.com/enboxorg/enbox)
|
|
@@ -24,6 +26,7 @@ export * from './define-protocol.js';
|
|
|
24
26
|
export * from './did-api.js';
|
|
25
27
|
export * from './dwn-reader-api.js';
|
|
26
28
|
export * from './enbox.js';
|
|
29
|
+
export type * from './enbox-types.js';
|
|
27
30
|
export * from './grant-revocation.js';
|
|
28
31
|
export * from './live-query.js';
|
|
29
32
|
export * from './permission-grant.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,mBAAmB,kBAAkB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAE5B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,CAAC;AACjB,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -24,6 +24,25 @@
|
|
|
24
24
|
* const members = await social.group.member.query(groupContextId);
|
|
25
25
|
* ```
|
|
26
26
|
*
|
|
27
|
+
* ## Deliberate `as never` pattern
|
|
28
|
+
*
|
|
29
|
+
* The CRUD methods below pass their `options: Record<string, unknown>`
|
|
30
|
+
* parameter to `typed.records.{create, query, subscribe, update}` with
|
|
31
|
+
* `as never`. This is the type-system bridge between the type-erased
|
|
32
|
+
* Proxy (which doesn't carry the per-protocol generic) and the strictly-
|
|
33
|
+
* typed record methods (which take `TypedRecordCreateParams<...>` etc.).
|
|
34
|
+
*
|
|
35
|
+
* `never` is the universal bottom subtype, so any strict generic is
|
|
36
|
+
* satisfied. The structural runtime shape of `options` is validated by
|
|
37
|
+
* the DWN SDK's grant-processing layer downstream — the cast is a
|
|
38
|
+
* narrow, intentional escape hatch at the proxy boundary.
|
|
39
|
+
*
|
|
40
|
+
* SonarCloud's `typescript:S4325` flags these casts as redundant
|
|
41
|
+
* because its rule doesn't model generic-parameter constraints. We
|
|
42
|
+
* suppress S4325 at the file level (see `sonar-project.properties`)
|
|
43
|
+
* because every CRUD method uses the same pattern and per-line
|
|
44
|
+
* `// NOSONAR` would dwarf the actual code.
|
|
45
|
+
*
|
|
27
46
|
* @module
|
|
28
47
|
*/
|
|
29
48
|
import type { Repository } from './repository-types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/repository.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/repository.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAmB,MAAM,mBAAmB,CAAC;AA2S7E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,UAAU,CACxB,CAAC,SAAS,kBAAkB,EAC5B,CAAC,SAAS,SAAS,EACnB,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAqC3C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enbox/api",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.26",
|
|
4
4
|
"description": "Enbox SDK — high-level API for Decentralized Web Nodes, DIDs, and Verifiable Credentials",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/esm/index.js",
|
|
@@ -81,15 +81,15 @@
|
|
|
81
81
|
"bun": ">=1.0.0"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@enbox/agent": "0.7.
|
|
85
|
-
"@enbox/auth": "0.6.
|
|
86
|
-
"@enbox/common": "0.1.
|
|
87
|
-
"@enbox/dwn-clients": "0.4.
|
|
84
|
+
"@enbox/agent": "0.7.2",
|
|
85
|
+
"@enbox/auth": "0.6.34",
|
|
86
|
+
"@enbox/common": "0.1.1",
|
|
87
|
+
"@enbox/dwn-clients": "0.4.1"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
|
-
"@enbox/crypto": "0.1.
|
|
91
|
-
"@enbox/dids": "0.1.
|
|
92
|
-
"@enbox/dwn-sdk-js": "0.3.
|
|
90
|
+
"@enbox/crypto": "0.1.1",
|
|
91
|
+
"@enbox/dids": "0.1.1",
|
|
92
|
+
"@enbox/dwn-sdk-js": "0.3.6",
|
|
93
93
|
"@types/node": "22.19.15",
|
|
94
94
|
"@types/sinon": "17.0.3",
|
|
95
95
|
"@typescript-eslint/eslint-plugin": "8.32.1",
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public type surface for the {@link Enbox} class.
|
|
3
|
+
*
|
|
4
|
+
* Session and connect types are derived from
|
|
5
|
+
* {@link AgentSessionPrimitives} in `@enbox/agent`, so the minimal session
|
|
6
|
+
* shape lives in one place and downstream packages stay in sync.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { AgentSessionPrimitives } from '@enbox/agent';
|
|
12
|
+
import type { AuthManager } from '@enbox/auth/auth-manager';
|
|
13
|
+
import type { DidMethodResolver } from '@enbox/dids';
|
|
14
|
+
import type {
|
|
15
|
+
AuthManagerOptions,
|
|
16
|
+
AuthSession,
|
|
17
|
+
HandlerConnectOptions,
|
|
18
|
+
VaultConnectOptions,
|
|
19
|
+
} from '@enbox/auth';
|
|
20
|
+
|
|
21
|
+
import type { DwnReaderApi } from './dwn-reader-api.js';
|
|
22
|
+
import type { Enbox } from './enbox.js';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Options for creating an anonymous (read-only) Enbox instance via {@link Enbox.anonymous}.
|
|
26
|
+
*
|
|
27
|
+
* @beta
|
|
28
|
+
*/
|
|
29
|
+
export type EnboxAnonymousOptions = {
|
|
30
|
+
/** Override the default DID method resolvers. Defaults to `[DidDht, DidJwk, DidKey, DidWeb]`. */
|
|
31
|
+
didResolvers?: DidMethodResolver[];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The result of calling {@link Enbox.anonymous}.
|
|
36
|
+
*
|
|
37
|
+
* Contains only a read-only `dwn` property — no `did`, `vc`, or `agent`.
|
|
38
|
+
*
|
|
39
|
+
* @beta
|
|
40
|
+
*/
|
|
41
|
+
export type EnboxAnonymousApi = {
|
|
42
|
+
/** A read-only DWN API for querying public data on remote DWNs. */
|
|
43
|
+
dwn: DwnReaderApi;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Parameters for constructing an {@link Enbox} instance.
|
|
48
|
+
*
|
|
49
|
+
* These are the minimal primitives needed to interact with the DWN network.
|
|
50
|
+
* Typically obtained from an agent session via `@enbox/auth`.
|
|
51
|
+
*
|
|
52
|
+
* Built on {@link AgentSessionPrimitives}: same `agent`/`delegateDid` shape,
|
|
53
|
+
* with `did` renamed to `connectedDid` to mirror the constructor parameter
|
|
54
|
+
* name used throughout `@enbox/api` for the tenant DID.
|
|
55
|
+
*/
|
|
56
|
+
export type EnboxParams = Omit<AgentSessionPrimitives, 'did'> & {
|
|
57
|
+
/** The DID of the tenant under which all DID, DWN, and VC requests are being performed. */
|
|
58
|
+
connectedDid: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Session-shaped parameters accepted by {@link Enbox.fromSession}.
|
|
63
|
+
*
|
|
64
|
+
* Alias for {@link AgentSessionPrimitives} so callers can pass an
|
|
65
|
+
* `AuthSession` from `@enbox/auth`, an `AgentSession` from `@enbox/agent`, or
|
|
66
|
+
* any compatible custom session without duplicating field declarations.
|
|
67
|
+
*/
|
|
68
|
+
export type EnboxSessionParams = AgentSessionPrimitives;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* High-level connection options for {@link Enbox.connect}.
|
|
72
|
+
*
|
|
73
|
+
* Composed of two parts:
|
|
74
|
+
*
|
|
75
|
+
* 1. **Manager-wide defaults** ({@link AuthManagerOptions}) — `password`,
|
|
76
|
+
* `sync`, `dwnEndpoints`, `connectHandler`, etc. Forwarded to
|
|
77
|
+
* `AuthManager.create()` and reused across reconnects.
|
|
78
|
+
* 2. **Per-call signals** ({@link HandlerConnectOptions} ∪
|
|
79
|
+
* {@link VaultConnectOptions}) — `protocols`, `createIdentity`,
|
|
80
|
+
* `recoveryPhrase`, `metadata`, etc. Forwarded to
|
|
81
|
+
* `AuthManager.connect()` and used to route handler vs local flow.
|
|
82
|
+
*
|
|
83
|
+
* Several fields (`password`, `sync`, `dwnEndpoints`, `connectHandler`)
|
|
84
|
+
* appear on multiple parents. The intersection keeps a single `?:`-typed
|
|
85
|
+
* field; the value flows to both the manager (as a default) and the
|
|
86
|
+
* per-call payload — matching the behavior of restored sessions.
|
|
87
|
+
*
|
|
88
|
+
* Routing between local and handler flow happens at runtime inside
|
|
89
|
+
* `AuthManager._isLocalConnect` based on whether `protocols` or
|
|
90
|
+
* `connectHandler` is provided. See `Enbox.connect()` for examples.
|
|
91
|
+
*
|
|
92
|
+
* If you need full control of the exact options forwarded to
|
|
93
|
+
* `AuthManager.connect()`, drop down one layer: create the
|
|
94
|
+
* `AuthManager` yourself and pass its session to `Enbox.fromSession`.
|
|
95
|
+
*/
|
|
96
|
+
export type EnboxConnectOptions =
|
|
97
|
+
& AuthManagerOptions
|
|
98
|
+
& HandlerConnectOptions
|
|
99
|
+
& VaultConnectOptions;
|
|
100
|
+
|
|
101
|
+
/** The result of a high-level asynchronous {@link Enbox.connect} call. */
|
|
102
|
+
export type EnboxConnectResult = {
|
|
103
|
+
/** The AuthManager that owns the session lifecycle. */
|
|
104
|
+
auth: AuthManager;
|
|
105
|
+
|
|
106
|
+
/** The high-level Enbox API instance. */
|
|
107
|
+
enbox: Enbox;
|
|
108
|
+
|
|
109
|
+
/** The active session returned by `AuthManager.connect()`. */
|
|
110
|
+
session: AuthSession;
|
|
111
|
+
};
|