@holochain/client 0.17.0-dev.5 → 0.17.0-dev.6
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 +4 -7
- package/lib/api/admin/websocket.d.ts +3 -4
- package/lib/api/admin/websocket.js +8 -6
- package/lib/api/app/websocket.d.ts +3 -4
- package/lib/api/app/websocket.js +8 -6
- package/lib/api/app-agent/websocket.d.ts +3 -3
- package/lib/api/app-agent/websocket.js +4 -5
- package/lib/api/client.d.ts +1 -1
- package/lib/api/common.d.ts +15 -0
- package/lib/api/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ npm install --save-exact @holochain/client
|
|
|
34
34
|
```typescript
|
|
35
35
|
import { ActionHash, AdminWebsocket, AppAgentWebsocket, CellType } from "@holochain/client";
|
|
36
36
|
|
|
37
|
-
const adminWs = await AdminWebsocket.connect("ws://127.0.0.1:65000");
|
|
37
|
+
const adminWs = await AdminWebsocket.connect({url: "ws://127.0.0.1:65000"});
|
|
38
38
|
const agent_key = await adminWs.generateAgentPubKey();
|
|
39
39
|
const role_name = "role";
|
|
40
40
|
const installed_app_id = "test-app";
|
|
@@ -51,10 +51,7 @@ if (!(CellType.Provisioned in appInfo.cell_info[role_name][0])) {
|
|
|
51
51
|
const { cell_id } = appInfo.cell_info[role_name][0][CellType.Provisioned];
|
|
52
52
|
await adminWs.authorizeSigningCredentials(cell_id);
|
|
53
53
|
await adminWs.attachAppInterface({ port: 65001 });
|
|
54
|
-
const appAgentWs = await AppAgentWebsocket.connect(
|
|
55
|
-
"ws://127.0.0.1:65001",
|
|
56
|
-
installed_app_id
|
|
57
|
-
);
|
|
54
|
+
const appAgentWs = await AppAgentWebsocket.connect(installed_app_id, {url: "ws://127.0.0.1:65001"});
|
|
58
55
|
|
|
59
56
|
const zomeCallPayload: CallZomeRequest = {
|
|
60
57
|
cell_id,
|
|
@@ -74,7 +71,7 @@ await adminWs.client.close();
|
|
|
74
71
|
```typescript
|
|
75
72
|
import { AdminWebsocket, AppWebsocket, CellType } from "@holochain/client";
|
|
76
73
|
|
|
77
|
-
const adminWs = await AdminWebsocket.connect("ws://127.0.0.1:65000");
|
|
74
|
+
const adminWs = await AdminWebsocket.connect({url: "ws://127.0.0.1:65000"});
|
|
78
75
|
const agent_key = await adminWs.generateAgentPubKey();
|
|
79
76
|
const installed_app_id = "test-app";
|
|
80
77
|
const appInfo = await adminWs.installApp({
|
|
@@ -90,7 +87,7 @@ if (!(CellType.Provisioned in appInfo.cell_info["role"][0])) {
|
|
|
90
87
|
const { cell_id } = appInfo.cell_info["role"][0][CellType.Provisioned];
|
|
91
88
|
await adminWs.authorizeSigningCredentials(cell_id);
|
|
92
89
|
await adminWs.attachAppInterface({ port: 65001 });
|
|
93
|
-
const appWs = await AppWebsocket.connect("ws://127.0.0.1:65001");
|
|
90
|
+
const appWs = await AppWebsocket.connect({url: "ws://127.0.0.1:65001"});
|
|
94
91
|
|
|
95
92
|
let signalCb;
|
|
96
93
|
const signalReceived = new Promise<void>((resolve) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CapSecret, GrantedFunctions } from "../../hdk/capabilities.js";
|
|
2
2
|
import type { AgentPubKey, CellId } from "../../types.js";
|
|
3
3
|
import { WsClient } from "../client.js";
|
|
4
|
-
import { Requester, Transformer } from "../common.js";
|
|
4
|
+
import { WebsocketConnectionOptions, Requester, Transformer } from "../common.js";
|
|
5
5
|
import { AddAgentInfoRequest, AddAgentInfoResponse, AdminApi, AgentInfoRequest, AgentInfoResponse, AttachAppInterfaceRequest, AttachAppInterfaceResponse, DeleteCloneCellRequest, DeleteCloneCellResponse, DisableAppRequest, DisableAppResponse, DumpFullStateRequest, DumpFullStateResponse, DumpNetworkStatsRequest, DumpNetworkStatsResponse, DumpStateRequest, DumpStateResponse, EnableAppRequest, EnableAppResponse, GenerateAgentPubKeyRequest, GenerateAgentPubKeyResponse, GetDnaDefinitionRequest, GetDnaDefinitionResponse, GrantZomeCallCapabilityRequest, GrantZomeCallCapabilityResponse, InstallAppRequest, InstallAppResponse, ListAppInterfacesRequest, ListAppInterfacesResponse, ListAppsRequest, ListAppsResponse, ListCellIdsRequest, ListCellIdsResponse, ListDnasRequest, ListDnasResponse, RegisterDnaRequest, RegisterDnaResponse, StorageInfoRequest, StorageInfoResponse, UninstallAppRequest, UninstallAppResponse, UpdateCoordinatorsRequest, UpdateCoordinatorsResponse } from "./types.js";
|
|
6
6
|
/**
|
|
7
7
|
* A class for interacting with a conductor's Admin API.
|
|
@@ -21,11 +21,10 @@ export declare class AdminWebsocket implements AdminApi {
|
|
|
21
21
|
/**
|
|
22
22
|
* Factory mehtod to create a new instance connected to the given URL.
|
|
23
23
|
*
|
|
24
|
-
* @param
|
|
25
|
-
* @param defaultTimeout - The default timeout for any request.
|
|
24
|
+
* @param options - {@link (WebsocketConnectionOptions:interface)}
|
|
26
25
|
* @returns A promise for a new connected instance.
|
|
27
26
|
*/
|
|
28
|
-
static connect(
|
|
27
|
+
static connect(options?: WebsocketConnectionOptions): Promise<AdminWebsocket>;
|
|
29
28
|
_requester<ReqI, ReqO, ResI, ResO>(tag: string, transformer?: Transformer<ReqI, ReqO, ResI, ResO>): (req: ReqI, timeout?: number | undefined) => Promise<ResO>;
|
|
30
29
|
/**
|
|
31
30
|
* Send a request to open the given port for {@link AppWebsocket} connections.
|
|
@@ -26,18 +26,20 @@ export class AdminWebsocket {
|
|
|
26
26
|
/**
|
|
27
27
|
* Factory mehtod to create a new instance connected to the given URL.
|
|
28
28
|
*
|
|
29
|
-
* @param
|
|
30
|
-
* @param defaultTimeout - The default timeout for any request.
|
|
29
|
+
* @param options - {@link (WebsocketConnectionOptions:interface)}
|
|
31
30
|
* @returns A promise for a new connected instance.
|
|
32
31
|
*/
|
|
33
|
-
static async connect(
|
|
32
|
+
static async connect(options = {}) {
|
|
34
33
|
// Check if we are in the launcher's environment, and if so, redirect the url to connect to
|
|
35
34
|
const env = getLauncherEnvironment();
|
|
36
35
|
if (env?.ADMIN_INTERFACE_PORT) {
|
|
37
|
-
url = new URL(`ws://127.0.0.1:${env.ADMIN_INTERFACE_PORT}`);
|
|
36
|
+
options.url = new URL(`ws://127.0.0.1:${env.ADMIN_INTERFACE_PORT}`);
|
|
38
37
|
}
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
if (!options.url) {
|
|
39
|
+
throw new Error("Unable to connect to Admin Websocket: No url provided and not in a Launcher environment.");
|
|
40
|
+
}
|
|
41
|
+
const wsClient = await WsClient.connect(options.url);
|
|
42
|
+
return new AdminWebsocket(wsClient, options.defaultTimeout);
|
|
41
43
|
}
|
|
42
44
|
_requester(tag, transformer) {
|
|
43
45
|
return requesterTransformer((req, timeout) => promiseTimeout(this.client.request(req), tag, timeout || this.defaultTimeout).then(catchError), tag, transformer);
|
|
@@ -2,7 +2,7 @@ import Emittery from "emittery";
|
|
|
2
2
|
import { CapSecret } from "../../hdk/capabilities.js";
|
|
3
3
|
import { InstalledAppId } from "../../types.js";
|
|
4
4
|
import { WsClient } from "../client.js";
|
|
5
|
-
import { Requester, Transformer } from "../common.js";
|
|
5
|
+
import { WebsocketConnectionOptions, Requester, Transformer } from "../common.js";
|
|
6
6
|
import { Nonce256Bit } from "../zome-call-signing.js";
|
|
7
7
|
import { AppApi, AppInfoRequest, AppInfoResponse, CallZomeRequest, CallZomeResponse, CreateCloneCellRequest, CreateCloneCellResponse, DisableCloneCellRequest, DisableCloneCellResponse, EnableCloneCellRequest, EnableCloneCellResponse, NetworkInfoRequest, NetworkInfoResponse } from "./types.js";
|
|
8
8
|
/**
|
|
@@ -19,11 +19,10 @@ export declare class AppWebsocket extends Emittery implements AppApi {
|
|
|
19
19
|
/**
|
|
20
20
|
* Instance factory for creating AppWebsockets.
|
|
21
21
|
*
|
|
22
|
-
* @param
|
|
23
|
-
* @param defaultTimeout - Timeout to default to for all operations.
|
|
22
|
+
* @param options - {@link (WebsocketConnectionOptions:interface)}
|
|
24
23
|
* @returns A new instance of an AppWebsocket.
|
|
25
24
|
*/
|
|
26
|
-
static connect(
|
|
25
|
+
static connect(options?: WebsocketConnectionOptions): Promise<AppWebsocket>;
|
|
27
26
|
_requester<ReqI, ReqO, ResI, ResO>(tag: string, transformer?: Transformer<ReqI, ReqO, ResI, ResO>): (req: ReqI, timeout?: number | undefined) => Promise<ResO>;
|
|
28
27
|
/**
|
|
29
28
|
* Request the app's info, including all cell infos.
|
package/lib/api/app/websocket.js
CHANGED
|
@@ -36,18 +36,20 @@ export class AppWebsocket extends Emittery {
|
|
|
36
36
|
/**
|
|
37
37
|
* Instance factory for creating AppWebsockets.
|
|
38
38
|
*
|
|
39
|
-
* @param
|
|
40
|
-
* @param defaultTimeout - Timeout to default to for all operations.
|
|
39
|
+
* @param options - {@link (WebsocketConnectionOptions:interface)}
|
|
41
40
|
* @returns A new instance of an AppWebsocket.
|
|
42
41
|
*/
|
|
43
|
-
static async connect(
|
|
42
|
+
static async connect(options = {}) {
|
|
44
43
|
// Check if we are in the launcher's environment, and if so, redirect the url to connect to
|
|
45
44
|
const env = getLauncherEnvironment();
|
|
46
45
|
if (env?.APP_INTERFACE_PORT) {
|
|
47
|
-
url = new URL(`ws://127.0.0.1:${env.APP_INTERFACE_PORT}`);
|
|
46
|
+
options.url = new URL(`ws://127.0.0.1:${env.APP_INTERFACE_PORT}`);
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
if (!options.url) {
|
|
49
|
+
throw new Error("Unable to connect to App Websocket: No url provided and not in a Launcher environment.");
|
|
50
|
+
}
|
|
51
|
+
const wsClient = await WsClient.connect(options.url);
|
|
52
|
+
const appWebsocket = new AppWebsocket(wsClient, options.defaultTimeout, env?.INSTALLED_APP_ID);
|
|
51
53
|
wsClient.on("signal", (signal) => appWebsocket.emit("signal", signal));
|
|
52
54
|
return appWebsocket;
|
|
53
55
|
}
|
|
@@ -3,6 +3,7 @@ import { AgentPubKey, CellId, InstalledAppId, RoleName } from "../../types.js";
|
|
|
3
3
|
import { AppInfo } from "../admin/types.js";
|
|
4
4
|
import { AppSignalCb, CallZomeResponse, CreateCloneCellResponse, DisableCloneCellResponse, EnableCloneCellResponse, NetworkInfoResponse } from "../app/types.js";
|
|
5
5
|
import { AppWebsocket } from "../app/websocket.js";
|
|
6
|
+
import { WebsocketConnectionOptions } from "../common.js";
|
|
6
7
|
import { AppAgentCallZomeRequest, AppAgentClient, AppAgentEvents, AppAgentNetworkInfoRequest, AppCreateCloneCellRequest, AppDisableCloneCellRequest, AppEnableCloneCellRequest } from "./types.js";
|
|
7
8
|
/**
|
|
8
9
|
* A class to establish a websocket connection to an App interface, for a
|
|
@@ -26,12 +27,11 @@ export declare class AppAgentWebsocket implements AppAgentClient {
|
|
|
26
27
|
/**
|
|
27
28
|
* Instance factory for creating AppAgentWebsockets.
|
|
28
29
|
*
|
|
29
|
-
* @param url - The `ws://` URL of the App API to connect to.
|
|
30
30
|
* @param installed_app_id - ID of the App to link to.
|
|
31
|
-
* @param
|
|
31
|
+
* @param options - {@link (WebsocketConnectionOptions:interface)}
|
|
32
32
|
* @returns A new instance of an AppAgentWebsocket.
|
|
33
33
|
*/
|
|
34
|
-
static connect(
|
|
34
|
+
static connect(installed_app_id: InstalledAppId, options?: WebsocketConnectionOptions): Promise<AppAgentWebsocket>;
|
|
35
35
|
/**
|
|
36
36
|
* Get a cell id by its role name or clone id.
|
|
37
37
|
*
|
|
@@ -3,7 +3,7 @@ import { omit } from "lodash-es";
|
|
|
3
3
|
import { getLauncherEnvironment } from "../../environments/launcher.js";
|
|
4
4
|
import { CellType } from "../admin/types.js";
|
|
5
5
|
import { AppWebsocket } from "../app/websocket.js";
|
|
6
|
-
import { getBaseRoleNameFromCloneId, isCloneId } from "../common.js";
|
|
6
|
+
import { getBaseRoleNameFromCloneId, isCloneId, } from "../common.js";
|
|
7
7
|
/**
|
|
8
8
|
* A class to establish a websocket connection to an App interface, for a
|
|
9
9
|
* specific agent and app.
|
|
@@ -52,13 +52,12 @@ export class AppAgentWebsocket {
|
|
|
52
52
|
/**
|
|
53
53
|
* Instance factory for creating AppAgentWebsockets.
|
|
54
54
|
*
|
|
55
|
-
* @param url - The `ws://` URL of the App API to connect to.
|
|
56
55
|
* @param installed_app_id - ID of the App to link to.
|
|
57
|
-
* @param
|
|
56
|
+
* @param options - {@link (WebsocketConnectionOptions:interface)}
|
|
58
57
|
* @returns A new instance of an AppAgentWebsocket.
|
|
59
58
|
*/
|
|
60
|
-
static async connect(
|
|
61
|
-
const appWebsocket = await AppWebsocket.connect(
|
|
59
|
+
static async connect(installed_app_id, options = {}) {
|
|
60
|
+
const appWebsocket = await AppWebsocket.connect(options);
|
|
62
61
|
const appInfo = await appWebsocket.appInfo({
|
|
63
62
|
installed_app_id: installed_app_id,
|
|
64
63
|
});
|
package/lib/api/client.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare class WsClient extends Emittery {
|
|
|
14
14
|
url: URL | undefined;
|
|
15
15
|
private pendingRequests;
|
|
16
16
|
private index;
|
|
17
|
-
constructor(socket: IsoWebSocket, url
|
|
17
|
+
constructor(socket: IsoWebSocket, url?: URL);
|
|
18
18
|
private setupSocket;
|
|
19
19
|
/**
|
|
20
20
|
* Instance factory for creating WsClients.
|
package/lib/api/common.d.ts
CHANGED
|
@@ -78,3 +78,18 @@ export declare class CloneId {
|
|
|
78
78
|
toString(): string;
|
|
79
79
|
getBaseRoleName(): string;
|
|
80
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Options for a Websocket connection.
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
export interface WebsocketConnectionOptions {
|
|
87
|
+
/**
|
|
88
|
+
* The `ws://` URL of the Websocket server to connect to. Not required when connecting to App API from a Launcher or Kangaroo environment.
|
|
89
|
+
*/
|
|
90
|
+
url?: URL;
|
|
91
|
+
/**
|
|
92
|
+
* Timeout to default to for all operations.
|
|
93
|
+
*/
|
|
94
|
+
defaultTimeout?: number;
|
|
95
|
+
}
|
package/lib/api/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export * from "./admin/index.js";
|
|
|
3
3
|
export * from "./app-agent/index.js";
|
|
4
4
|
export * from "./app/index.js";
|
|
5
5
|
export { IsoWebSocket, WsClient } from "./client.js";
|
|
6
|
-
export { CloneId, HolochainError, Requester, Transformer, getBaseRoleNameFromCloneId, isCloneId, } from "./common.js";
|
|
6
|
+
export { CloneId, HolochainError, Requester, Transformer, WebsocketConnectionOptions, getBaseRoleNameFromCloneId, isCloneId, } from "./common.js";
|
|
7
7
|
export * from "./zome-call-signing.js";
|
package/package.json
CHANGED