@enbox/api 0.1.1 → 0.2.1
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 +505 -138
- package/dist/browser.mjs +23 -13
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/advanced.js +11 -0
- package/dist/esm/advanced.js.map +1 -0
- package/dist/esm/define-protocol.js +3 -3
- package/dist/esm/dwn-api.js +56 -114
- package/dist/esm/dwn-api.js.map +1 -1
- package/dist/esm/dwn-reader-api.js +128 -0
- package/dist/esm/dwn-reader-api.js.map +1 -0
- package/dist/esm/index.js +3 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/live-query.js +5 -4
- package/dist/esm/live-query.js.map +1 -1
- package/dist/esm/read-only-record.js +255 -0
- package/dist/esm/read-only-record.js.map +1 -0
- package/dist/esm/record.js +46 -57
- package/dist/esm/record.js.map +1 -1
- package/dist/esm/typed-web5.js +242 -0
- package/dist/esm/typed-web5.js.map +1 -0
- package/dist/esm/web5.js +71 -3
- package/dist/esm/web5.js.map +1 -1
- package/dist/types/advanced.d.ts +12 -0
- package/dist/types/advanced.d.ts.map +1 -0
- package/dist/types/define-protocol.d.ts +3 -3
- package/dist/types/dwn-api.d.ts +13 -92
- package/dist/types/dwn-api.d.ts.map +1 -1
- package/dist/types/dwn-reader-api.d.ts +138 -0
- package/dist/types/dwn-reader-api.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/live-query.d.ts +13 -1
- package/dist/types/live-query.d.ts.map +1 -1
- package/dist/types/protocol-types.d.ts +2 -2
- package/dist/types/read-only-record.d.ts +133 -0
- package/dist/types/read-only-record.d.ts.map +1 -0
- package/dist/types/record.d.ts +37 -17
- package/dist/types/record.d.ts.map +1 -1
- package/dist/types/{typed-dwn-api.d.ts → typed-web5.d.ts} +70 -73
- package/dist/types/typed-web5.d.ts.map +1 -0
- package/dist/types/web5.d.ts +79 -3
- package/dist/types/web5.d.ts.map +1 -1
- package/package.json +10 -6
- package/src/advanced.ts +29 -0
- package/src/define-protocol.ts +3 -3
- package/src/dwn-api.ts +91 -232
- package/src/dwn-reader-api.ts +255 -0
- package/src/index.ts +3 -2
- package/src/live-query.ts +20 -4
- package/src/protocol-types.ts +2 -2
- package/src/read-only-record.ts +328 -0
- package/src/record.ts +116 -86
- package/src/typed-web5.ts +445 -0
- package/src/web5.ts +104 -5
- package/dist/esm/typed-dwn-api.js +0 -182
- package/dist/esm/typed-dwn-api.js.map +0 -1
- package/dist/types/typed-dwn-api.d.ts.map +0 -1
- package/src/typed-dwn-api.ts +0 -370
package/dist/types/web5.d.ts
CHANGED
|
@@ -2,9 +2,13 @@
|
|
|
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 { DidMethodResolver } from '@enbox/dids';
|
|
6
|
+
import type { ProtocolDefinition } from '@enbox/dwn-sdk-js';
|
|
5
7
|
import type { DwnDataEncodedRecordsWriteMessage, DwnProtocolDefinition, HdIdentityVault, Permission, WalletConnectOptions, Web5Agent } from '@enbox/agent';
|
|
8
|
+
import type { SchemaMap, TypedProtocol } from './protocol-types.js';
|
|
6
9
|
import { DidApi } from './did-api.js';
|
|
7
|
-
import {
|
|
10
|
+
import { DwnReaderApi } from './dwn-reader-api.js';
|
|
11
|
+
import { TypedWeb5 } from './typed-web5.js';
|
|
8
12
|
import { VcApi } from './vc-api.js';
|
|
9
13
|
/** Override defaults configured during the technical preview phase. */
|
|
10
14
|
export type TechPreviewOptions = {
|
|
@@ -43,6 +47,26 @@ export type ConnectOptions = Omit<WalletConnectOptions, 'permissionRequests'> &
|
|
|
43
47
|
*/
|
|
44
48
|
permissionRequests: ConnectPermissionRequest[];
|
|
45
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Options for creating an anonymous (read-only) Web5 instance via {@link Web5.anonymous}.
|
|
52
|
+
*
|
|
53
|
+
* @beta
|
|
54
|
+
*/
|
|
55
|
+
export type Web5AnonymousOptions = {
|
|
56
|
+
/** Override the default DID method resolvers. Defaults to `[DidDht, DidJwk, DidKey, DidWeb]`. */
|
|
57
|
+
didResolvers?: DidMethodResolver[];
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* The result of calling {@link Web5.anonymous}.
|
|
61
|
+
*
|
|
62
|
+
* Contains only a read-only `dwn` property — no `did`, `vc`, or `agent`.
|
|
63
|
+
*
|
|
64
|
+
* @beta
|
|
65
|
+
*/
|
|
66
|
+
export type Web5AnonymousApi = {
|
|
67
|
+
/** A read-only DWN API for querying public data on remote DWNs. */
|
|
68
|
+
dwn: DwnReaderApi;
|
|
69
|
+
};
|
|
46
70
|
/** Optional overrides that can be provided when calling {@link Web5.connect}. */
|
|
47
71
|
export type Web5ConnectOptions = {
|
|
48
72
|
/**
|
|
@@ -184,11 +208,63 @@ export declare class Web5 {
|
|
|
184
208
|
agent: Web5Agent;
|
|
185
209
|
/** Exposed instance to the DID APIs, allow users to create and resolve DIDs */
|
|
186
210
|
did: DidApi;
|
|
187
|
-
/**
|
|
188
|
-
|
|
211
|
+
/** Internal DWN API instance. Use {@link Web5.using} for protocol-scoped access. */
|
|
212
|
+
private _dwn;
|
|
189
213
|
/** Exposed instance to the VC APIs, allow users to issue, present and verify VCs */
|
|
190
214
|
vc: VcApi;
|
|
191
215
|
constructor({ agent, connectedDid, delegateDid }: Web5Params);
|
|
216
|
+
/**
|
|
217
|
+
* Returns a {@link TypedWeb5} instance scoped to the given protocol.
|
|
218
|
+
*
|
|
219
|
+
* This is the **primary developer interface** for interacting with
|
|
220
|
+
* protocol-backed records. It auto-injects the protocol URI, protocolPath,
|
|
221
|
+
* and schema into every operation, and provides compile-time path
|
|
222
|
+
* autocompletion plus typed data payloads via the schema map.
|
|
223
|
+
*
|
|
224
|
+
* @param protocol - A typed protocol created via `defineProtocol()`.
|
|
225
|
+
* @returns A `TypedWeb5` instance bound to the given protocol.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```ts
|
|
229
|
+
* const social = web5.using(SocialProtocol);
|
|
230
|
+
*
|
|
231
|
+
* await social.configure();
|
|
232
|
+
*
|
|
233
|
+
* const { record } = await social.records.write('friend', {
|
|
234
|
+
* data: { did: 'did:example:alice', alias: 'Alice' },
|
|
235
|
+
* });
|
|
236
|
+
*
|
|
237
|
+
* const { records } = await social.records.query('friend');
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
using<D extends ProtocolDefinition, M extends SchemaMap>(protocol: TypedProtocol<D, M>): TypedWeb5<D, M>;
|
|
241
|
+
/**
|
|
242
|
+
* Creates a lightweight, read-only Web5 instance for querying public DWN data.
|
|
243
|
+
*
|
|
244
|
+
* No identity, vault, password, or signing keys are required. The returned
|
|
245
|
+
* API supports querying and reading published records and protocols from any
|
|
246
|
+
* remote DWN, using **unsigned** (anonymous) DWN messages.
|
|
247
|
+
*
|
|
248
|
+
* @param options - Optional configuration overrides.
|
|
249
|
+
* @returns A {@link Web5AnonymousApi} with a read-only `dwn` property.
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```ts
|
|
253
|
+
* const { dwn } = Web5.anonymous();
|
|
254
|
+
*
|
|
255
|
+
* const { records } = await dwn.records.query({
|
|
256
|
+
* from: 'did:dht:alice...',
|
|
257
|
+
* filter: { protocol: 'https://social.example/posts', protocolPath: 'post' },
|
|
258
|
+
* });
|
|
259
|
+
*
|
|
260
|
+
* for (const record of records) {
|
|
261
|
+
* console.log(record.id, await record.data.text());
|
|
262
|
+
* }
|
|
263
|
+
* ```
|
|
264
|
+
*
|
|
265
|
+
* @beta
|
|
266
|
+
*/
|
|
267
|
+
static anonymous(options?: Web5AnonymousOptions): Web5AnonymousApi;
|
|
192
268
|
/**
|
|
193
269
|
* Connects to a {@link Web5Agent}. Defaults to creating a local {@link Web5UserAgent} if one
|
|
194
270
|
* isn't provided.
|
package/dist/types/web5.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web5.d.ts","sourceRoot":"","sources":["../../src/web5.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAEV,iCAAiC,EAEjC,qBAAqB,EAErB,eAAe,EACf,UAAU,EACV,oBAAoB,EACpB,SAAS,EACV,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"web5.d.ts","sourceRoot":"","sources":["../../src/web5.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAEV,iCAAiC,EAEjC,qBAAqB,EAErB,eAAe,EACf,UAAU,EACV,oBAAoB,EACpB,SAAS,EACV,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAMpE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,uEAAuE;AACvE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF,0CAA0C;AAC1C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC;;OAEG;IACH,kBAAkB,EAAE,qBAAqB,CAAC;IAE1C;;OAEG;IACH,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;CAC5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BpC;;;;OAIG;WACU,sBAAsB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE;QAClE,MAAM,EAAE,iCAAiC,EAAE,CAAC;QAC5C,KAAK,EAAE,SAAS,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAqBtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enbox/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "SDK for accessing the features and capabilities of Web5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/esm/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"test:node": "bun test --timeout 10000 .spec.ts",
|
|
17
17
|
"test:node:coverage": "bun test --timeout 10000 --coverage --coverage-reporter=text --coverage-reporter=lcov --coverage-dir=coverage .spec.ts",
|
|
18
18
|
"test:browser": "bunx --bun vitest --config vitest.browser.config.ts --run",
|
|
19
|
-
"test:browser:coverage": "bunx --bun vitest --config vitest.browser.config.ts --run --coverage --coverage.provider=istanbul
|
|
19
|
+
"test:browser:coverage": "bunx --bun vitest --config vitest.browser.config.ts --run --coverage --coverage.provider=istanbul"
|
|
20
20
|
},
|
|
21
21
|
"homepage": "https://github.com/enboxorg/enbox/tree/main/packages/api#readme",
|
|
22
22
|
"bugs": "https://github.com/enboxorg/enbox/issues",
|
|
@@ -53,6 +53,10 @@
|
|
|
53
53
|
"types": "./dist/types/index.d.ts",
|
|
54
54
|
"import": "./dist/esm/index.js"
|
|
55
55
|
},
|
|
56
|
+
"./advanced": {
|
|
57
|
+
"types": "./dist/types/advanced.d.ts",
|
|
58
|
+
"import": "./dist/esm/advanced.js"
|
|
59
|
+
},
|
|
56
60
|
"./browser": {
|
|
57
61
|
"types": "./dist/types/index.d.ts",
|
|
58
62
|
"import": "./dist/browser.mjs"
|
|
@@ -77,14 +81,14 @@
|
|
|
77
81
|
"bun": ">=1.0.0"
|
|
78
82
|
},
|
|
79
83
|
"dependencies": {
|
|
80
|
-
"@enbox/agent": "0.1.
|
|
84
|
+
"@enbox/agent": "0.1.7",
|
|
81
85
|
"@enbox/common": "0.0.3",
|
|
82
|
-
"@enbox/dwn-clients": "0.0.
|
|
86
|
+
"@enbox/dwn-clients": "0.0.4"
|
|
83
87
|
},
|
|
84
88
|
"devDependencies": {
|
|
85
89
|
"@enbox/crypto": "0.0.4",
|
|
86
|
-
"@enbox/dids": "0.0.
|
|
87
|
-
"@enbox/dwn-sdk-js": "0.0.
|
|
90
|
+
"@enbox/dids": "0.0.5",
|
|
91
|
+
"@enbox/dwn-sdk-js": "0.0.7",
|
|
88
92
|
"@types/node": "20.14.8",
|
|
89
93
|
"@types/sinon": "17.0.3",
|
|
90
94
|
"@typescript-eslint/eslint-plugin": "8.32.1",
|
package/src/advanced.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Advanced API surface for power users who need direct access to
|
|
3
|
+
* the underlying {@link DwnApi}.
|
|
4
|
+
*
|
|
5
|
+
* Most applications should use `web5.using(protocol)` instead.
|
|
6
|
+
* Import from `@enbox/api/advanced` to access these exports.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export { DwnApi } from './dwn-api.js';
|
|
12
|
+
|
|
13
|
+
export type {
|
|
14
|
+
FetchGrantsRequest,
|
|
15
|
+
FetchRequestsRequest,
|
|
16
|
+
ProtocolsConfigureRequest,
|
|
17
|
+
ProtocolsConfigureResponse,
|
|
18
|
+
ProtocolsQueryRequest,
|
|
19
|
+
ProtocolsQueryResponse,
|
|
20
|
+
RecordsDeleteRequest,
|
|
21
|
+
RecordsQueryRequest,
|
|
22
|
+
RecordsQueryResponse,
|
|
23
|
+
RecordsReadRequest,
|
|
24
|
+
RecordsReadResponse,
|
|
25
|
+
RecordsSubscribeRequest,
|
|
26
|
+
RecordsSubscribeResponse,
|
|
27
|
+
RecordsWriteRequest,
|
|
28
|
+
RecordsWriteResponse,
|
|
29
|
+
} from './dwn-api.js';
|
package/src/define-protocol.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Factory function for creating typed protocol definitions.
|
|
3
3
|
*
|
|
4
4
|
* `defineProtocol()` wraps a standard {@link ProtocolDefinition} with
|
|
5
|
-
* compile-time type metadata so that {@link
|
|
5
|
+
* compile-time type metadata so that {@link TypedWeb5} can provide
|
|
6
6
|
* path autocompletion, data-shape inference, and tag type safety.
|
|
7
7
|
*/
|
|
8
8
|
|
|
@@ -17,7 +17,7 @@ import type { SchemaMap, TypedProtocol } from './protocol-types.js';
|
|
|
17
17
|
*
|
|
18
18
|
* The `definition` argument is returned as-is (no cloning). The schema map
|
|
19
19
|
* is a phantom type parameter — it exists only at compile time to thread
|
|
20
|
-
* type information through to `
|
|
20
|
+
* type information through to `TypedWeb5`.
|
|
21
21
|
*
|
|
22
22
|
* @param definition - A standard `ProtocolDefinition` object.
|
|
23
23
|
* @param _schemaMap - A phantom value (e.g. `{} as MySchemaMap`) that carries
|
|
@@ -32,7 +32,7 @@ import type { SchemaMap, TypedProtocol } from './protocol-types.js';
|
|
|
32
32
|
* });
|
|
33
33
|
*
|
|
34
34
|
* // socialGraph.definition is the raw ProtocolDefinition
|
|
35
|
-
* //
|
|
35
|
+
* // TypedWeb5 infers paths like 'friend' | 'friend/message' and
|
|
36
36
|
* // data types from the schema map.
|
|
37
37
|
* ```
|
|
38
38
|
*/
|