iso-ucan 0.4.2 → 0.5.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/dist/src/capability.d.ts +0 -3
- package/dist/src/capability.d.ts.map +1 -1
- package/dist/src/delegation.d.ts +4 -1
- package/dist/src/delegation.d.ts.map +1 -1
- package/dist/src/envelope.d.ts +1 -1
- package/dist/src/envelope.d.ts.map +1 -1
- package/dist/src/invocation.d.ts.map +1 -1
- package/dist/src/rpc/client.d.ts +24 -0
- package/dist/src/rpc/client.d.ts.map +1 -0
- package/dist/src/rpc/command.d.ts +19 -0
- package/dist/src/rpc/command.d.ts.map +1 -0
- package/dist/src/rpc/index.d.ts +5 -0
- package/dist/src/rpc/index.d.ts.map +1 -0
- package/dist/src/rpc/receipt.d.ts +114 -0
- package/dist/src/rpc/receipt.d.ts.map +1 -0
- package/dist/src/rpc/server.d.ts +18 -0
- package/dist/src/rpc/server.d.ts.map +1 -0
- package/dist/src/rpc/types.d.ts +112 -0
- package/dist/src/rpc/types.d.ts.map +1 -0
- package/dist/src/store.d.ts +4 -2
- package/dist/src/store.d.ts.map +1 -1
- package/dist/src/types.d.ts +15 -3
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils.d.ts +19 -2
- package/dist/src/utils.d.ts.map +1 -1
- package/license +9 -0
- package/package.json +19 -26
- package/readme.md +185 -18
- package/src/capability.js +1 -6
- package/src/delegation.js +15 -13
- package/src/invocation.js +10 -6
- package/src/rpc/client.js +85 -0
- package/src/rpc/command.js +28 -0
- package/src/rpc/index.js +10 -0
- package/src/rpc/receipt.js +136 -0
- package/src/rpc/server.js +155 -0
- package/src/rpc/types.js +9 -0
- package/src/rpc/types.ts +153 -0
- package/src/store.js +41 -16
- package/src/types.ts +15 -6
- package/src/utils.js +39 -15
- package/dist/src/client.d.ts +0 -41
- package/dist/src/client.d.ts.map +0 -1
- package/dist/src/server.d.ts +0 -38
- package/dist/src/server.d.ts.map +0 -1
- package/src/client.js +0 -52
- package/src/server.js +0 -47
package/dist/src/client.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @import {InferProtocol, RouteOutput, StandardSchemaV1, ClientOptions, RouterClient} from './types'
|
|
3
|
-
* @import {Capability} from './capability'
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Workaround to make imports types work
|
|
7
|
-
* @template {{ cmd: string; in: unknown; out: unknown; }} T
|
|
8
|
-
* @typedef {Object} DELETE_ME
|
|
9
|
-
* @prop {string} url
|
|
10
|
-
* @prop {Capability<StandardSchemaV1, string>[]} capabilities
|
|
11
|
-
* @prop {InferProtocol<Record<string, RouteOutput<Capability<StandardSchemaV1>, unknown>>>} router
|
|
12
|
-
* @prop {ClientOptions} options
|
|
13
|
-
* @prop {RouterClient<T>} routerClient
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* @template {InferProtocol<Record<string, RouteOutput<Capability<StandardSchemaV1>, unknown>>>} T
|
|
17
|
-
* @param {ClientOptions} options
|
|
18
|
-
* @returns {RouterClient<T>}
|
|
19
|
-
*/
|
|
20
|
-
export function createClient<T extends InferProtocol<Record<string, RouteOutput<Capability<StandardSchemaV1>, unknown>>>>(options: ClientOptions): RouterClient<T>;
|
|
21
|
-
/**
|
|
22
|
-
* Workaround to make imports types work
|
|
23
|
-
*/
|
|
24
|
-
export type DELETE_ME<T extends {
|
|
25
|
-
cmd: string;
|
|
26
|
-
in: unknown;
|
|
27
|
-
out: unknown;
|
|
28
|
-
}> = {
|
|
29
|
-
url: string;
|
|
30
|
-
capabilities: Capability<StandardSchemaV1, string>[];
|
|
31
|
-
router: InferProtocol<Record<string, RouteOutput<Capability<StandardSchemaV1>, unknown>>>;
|
|
32
|
-
options: ClientOptions;
|
|
33
|
-
routerClient: RouterClient<T>;
|
|
34
|
-
};
|
|
35
|
-
import type { StandardSchemaV1 } from './types';
|
|
36
|
-
import type { Capability } from './capability';
|
|
37
|
-
import type { RouteOutput } from './types';
|
|
38
|
-
import type { InferProtocol } from './types';
|
|
39
|
-
import type { ClientOptions } from './types';
|
|
40
|
-
import type { RouterClient } from './types';
|
|
41
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/src/client.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AAEH;;;;GAIG;AACH,6BAJiG,CAAC,SAArF,cAAe,MAAM,CAAC,MAAM,EAAE,YAAY,WAAW,gBAAgB,CAAC,EAAE,OAAO,CAAC,CAAC,CAAE,WACrF,aAAa,GACX,aAAa,CAAC,CAAC,CAgC3B;;;;sBA5C0D,CAAC,SAA/C;IAAG,GAAG,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,OAAO,CAAC;CAAG;SAEhD,MAAM;kBACN,WAAW,gBAAgB,EAAE,MAAM,CAAC,EAAE;YACtC,cAAc,MAAM,CAAC,MAAM,EAAE,YAAY,WAAW,gBAAgB,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;aACjF,aAAa;kBACb,aAAa,CAAC,CAAC;;sCAZmE,SAAS;gCACxE,cAAc;iCADiD,SAAS;mCAAT,SAAS;mCAAT,SAAS;kCAAT,SAAS"}
|
package/dist/src/server.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @import { RouteOutput, StandardSchemaV1, RouteOptions, RouteHandlerOptions} from './types'
|
|
3
|
-
* @import {Capability} from './capability'
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Workaround to make imports types work
|
|
7
|
-
* @template {Capability<StandardSchemaV1, string>} T
|
|
8
|
-
* @template Output
|
|
9
|
-
* @typedef {Object} DELETE_ME
|
|
10
|
-
* @prop {string} url
|
|
11
|
-
* @prop {Capability<StandardSchemaV1, string>[]} capabilities
|
|
12
|
-
* @prop {RouteOutput<T, Output>} router
|
|
13
|
-
* @prop {RouteOptions<T, Output>} options
|
|
14
|
-
* @prop {RouteHandlerOptions} routerClient
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* @template Output
|
|
18
|
-
* @template {Capability<StandardSchemaV1>} Cap
|
|
19
|
-
* @param {RouteOptions<Cap, Output>} options
|
|
20
|
-
* @returns {RouteOutput<Cap, Output>}
|
|
21
|
-
*/
|
|
22
|
-
export function route<Output, Cap extends Capability<StandardSchemaV1>>(options: RouteOptions<Cap, Output>): RouteOutput<Cap, Output>;
|
|
23
|
-
/**
|
|
24
|
-
* Workaround to make imports types work
|
|
25
|
-
*/
|
|
26
|
-
export type DELETE_ME<T extends Capability<StandardSchemaV1, string>, Output> = {
|
|
27
|
-
url: string;
|
|
28
|
-
capabilities: Capability<StandardSchemaV1, string>[];
|
|
29
|
-
router: RouteOutput<T, Output>;
|
|
30
|
-
options: RouteOptions<T, Output>;
|
|
31
|
-
routerClient: RouteHandlerOptions;
|
|
32
|
-
};
|
|
33
|
-
import type { StandardSchemaV1 } from './types';
|
|
34
|
-
import type { Capability } from './capability';
|
|
35
|
-
import type { RouteOptions } from './types';
|
|
36
|
-
import type { RouteOutput } from './types';
|
|
37
|
-
import type { RouteHandlerOptions } from './types';
|
|
38
|
-
//# sourceMappingURL=server.d.ts.map
|
package/dist/src/server.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;;;;;;;;GAUG;AAEH;;;;;GAKG;AACH,sBALa,MAAM,EACyB,GAAG,SAAlC,WAAY,gBAAgB,CAAE,WAChC,aAAa,GAAG,EAAE,MAAM,CAAC,GACvB,YAAY,GAAG,EAAE,MAAM,CAAC,CAqBpC;;;;sBAnCmD,CAAC,SAAxC,WAAY,gBAAgB,EAAE,MAAM,CAAE,EACtC,MAAM;SAET,MAAM;kBACN,WAAW,gBAAgB,EAAE,MAAM,CAAC,EAAE;YACtC,YAAY,CAAC,EAAE,MAAM,CAAC;aACtB,aAAa,CAAC,EAAE,MAAM,CAAC;kBACvB,mBAAmB;;sCAbuD,SAAS;gCAChE,cAAc;kCADyC,SAAS;iCAAT,SAAS;yCAAT,SAAS"}
|
package/src/client.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @import {InferProtocol, RouteOutput, StandardSchemaV1, ClientOptions, RouterClient} from './types'
|
|
3
|
-
* @import {Capability} from './capability'
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Workaround to make imports types work
|
|
8
|
-
* @template {{ cmd: string; in: unknown; out: unknown; }} T
|
|
9
|
-
* @typedef {Object} DELETE_ME
|
|
10
|
-
* @prop {string} url
|
|
11
|
-
* @prop {Capability<StandardSchemaV1, string>[]} capabilities
|
|
12
|
-
* @prop {InferProtocol<Record<string, RouteOutput<Capability<StandardSchemaV1>, unknown>>>} router
|
|
13
|
-
* @prop {ClientOptions} options
|
|
14
|
-
* @prop {RouterClient<T>} routerClient
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @template {InferProtocol<Record<string, RouteOutput<Capability<StandardSchemaV1>, unknown>>>} T
|
|
19
|
-
* @param {ClientOptions} options
|
|
20
|
-
* @returns {RouterClient<T>}
|
|
21
|
-
*/
|
|
22
|
-
export function createClient(options) {
|
|
23
|
-
const { url, capabilities } = options
|
|
24
|
-
|
|
25
|
-
// Create a map of capabilities by their `cmd` property
|
|
26
|
-
const capabilityMap = Object.fromEntries(
|
|
27
|
-
capabilities.map((cap) => [cap.cmd, cap])
|
|
28
|
-
)
|
|
29
|
-
return {
|
|
30
|
-
request: async (/** @type {string} */ cmd, /** @type {any} */ args) => {
|
|
31
|
-
const capability = capabilityMap[cmd]
|
|
32
|
-
|
|
33
|
-
if (!capability) {
|
|
34
|
-
throw new Error(`Capability not found: ${cmd}`)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const inv = await capability.invoke({
|
|
38
|
-
args,
|
|
39
|
-
iss: options.issuer,
|
|
40
|
-
sub: options.audience.did,
|
|
41
|
-
store: options.store,
|
|
42
|
-
exp: null,
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const response = await fetch(url, {
|
|
46
|
-
method: 'POST',
|
|
47
|
-
body: /** @type {BufferSource} */ (inv.bytes),
|
|
48
|
-
})
|
|
49
|
-
return response.json()
|
|
50
|
-
},
|
|
51
|
-
}
|
|
52
|
-
}
|
package/src/server.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// import type { StandardSchemaV1 } from '@standard-schema/spec'
|
|
2
|
-
// import type { Capability } from './capability.js'
|
|
3
|
-
// import type { RouteHandlerOptions, RouteOptions, RouteOutput } from './types.js'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @import { RouteOutput, StandardSchemaV1, RouteOptions, RouteHandlerOptions} from './types'
|
|
7
|
-
* @import {Capability} from './capability'
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Workaround to make imports types work
|
|
12
|
-
* @template {Capability<StandardSchemaV1, string>} T
|
|
13
|
-
* @template Output
|
|
14
|
-
* @typedef {Object} DELETE_ME
|
|
15
|
-
* @prop {string} url
|
|
16
|
-
* @prop {Capability<StandardSchemaV1, string>[]} capabilities
|
|
17
|
-
* @prop {RouteOutput<T, Output>} router
|
|
18
|
-
* @prop {RouteOptions<T, Output>} options
|
|
19
|
-
* @prop {RouteHandlerOptions} routerClient
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @template Output
|
|
24
|
-
* @template {Capability<StandardSchemaV1>} Cap
|
|
25
|
-
* @param {RouteOptions<Cap, Output>} options
|
|
26
|
-
* @returns {RouteOutput<Cap, Output>}
|
|
27
|
-
*/
|
|
28
|
-
export function route(options) {
|
|
29
|
-
return {
|
|
30
|
-
cap: options.capability,
|
|
31
|
-
fn: async (
|
|
32
|
-
/** @type {RouteHandlerOptions} */ { request, issuer, invocation, store }
|
|
33
|
-
) => {
|
|
34
|
-
const { capability, handler } = options
|
|
35
|
-
|
|
36
|
-
const args = await capability.validate(invocation.payload.args)
|
|
37
|
-
if (args.issues) {
|
|
38
|
-
throw new Error(args.issues.map((issue) => issue.message).join(', '))
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// TODO: handle failure
|
|
42
|
-
const result = await handler({ args: args.value, store })
|
|
43
|
-
|
|
44
|
-
return result
|
|
45
|
-
},
|
|
46
|
-
}
|
|
47
|
-
}
|