@holochain/client 0.12.6 → 0.12.7

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.
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Action, DhtOp, Entry, ZomeCallCapGrant } from "../../hdk/index.js";
3
2
  import { ActionHash, AgentPubKey, CellId, DnaHash, DnaProperties, Duration, HoloHash, HoloHashB64, InstalledAppId, KitsuneAgent, KitsuneSpace, RoleName, Signature, Timestamp, WasmHash } from "../../types.js";
4
3
  import { Requester } from "../common.js";
@@ -7,7 +6,7 @@ import { DisableCloneCellRequest } from "../index.js";
7
6
  * @public
8
7
  */
9
8
  export type AttachAppInterfaceRequest = {
10
- port: number;
9
+ port?: number;
11
10
  };
12
11
  /**
13
12
  * @public
@@ -127,7 +126,7 @@ export type AppInfo = {
127
126
  /**
128
127
  * @public
129
128
  */
130
- export type MembraneProof = Buffer;
129
+ export type MembraneProof = Uint8Array;
131
130
  /**
132
131
  * @public
133
132
  */
@@ -163,7 +162,7 @@ export type DumpStateResponse = any;
163
162
  */
164
163
  export type DumpFullStateRequest = {
165
164
  cell_id: CellId;
166
- dht_ops_cursor: number | undefined;
165
+ dht_ops_cursor?: number;
167
166
  };
168
167
  /**
169
168
  * @public
@@ -195,7 +194,7 @@ export type RegisterDnaResponse = HoloHash;
195
194
  */
196
195
  export type DnaModifiers = {
197
196
  network_seed: NetworkSeed;
198
- properties: DnaProperties;
197
+ properties: Uint8Array;
199
198
  origin_time: Timestamp;
200
199
  quantum_time: Duration;
201
200
  };
@@ -252,6 +251,16 @@ export type UninstallAppRequest = {
252
251
  * @public
253
252
  */
254
253
  export type UninstallAppResponse = null;
254
+ /**
255
+ * @public
256
+ */
257
+ export type UpdateCoordinatorsRequest = {
258
+ dna_hash: DnaHash;
259
+ } & CoordinatorSource;
260
+ /**
261
+ * @public
262
+ */
263
+ export type UpdateCoordinatorsResponse = void;
255
264
  /**
256
265
  * @public
257
266
  */
@@ -373,12 +382,33 @@ export type NetworkSeed = string;
373
382
  * @public
374
383
  */
375
384
  export type InstallAppRequest = {
385
+ /**
386
+ * The agent to use when creating Cells for this App.
387
+ */
376
388
  agent_key: AgentPubKey;
389
+ /**
390
+ * The unique identifier for an installed app in this conductor.
391
+ * If not specified, it will be derived from the app name in the bundle manifest.
392
+ */
377
393
  installed_app_id?: InstalledAppId;
394
+ /**
395
+ * Include proof-of-membrane-membership data for cells that require it,
396
+ * keyed by the CellNick specified in the app bundle manifest.
397
+ */
378
398
  membrane_proofs: {
379
399
  [key: string]: MembraneProof;
380
400
  };
401
+ /**
402
+ * Optional global network seed override. If set will override the network seed value for all
403
+ * DNAs in the bundle.
404
+ */
381
405
  network_seed?: NetworkSeed;
406
+ /**
407
+ * Optional: If app installation fails due to genesis failure, normally the app will be immediately uninstalled.
408
+ * When this flag is set, the app is left installed with empty cells intact. This can be useful for
409
+ * using graft_records_onto_source_chain, or for diagnostics.
410
+ */
411
+ ignore_genesis_failure?: boolean;
382
412
  } & AppBundleSource;
383
413
  /**
384
414
  * @public
@@ -500,13 +530,41 @@ export type InstallAppDnaPayload = {
500
530
  * @public
501
531
  */
502
532
  export type ZomeLocation = Location;
533
+ /**
534
+ * @public
535
+ */
536
+ export interface ZomeDependency {
537
+ name: ZomeName;
538
+ }
503
539
  /**
504
540
  * @public
505
541
  */
506
542
  export type ZomeManifest = {
507
543
  name: string;
508
544
  hash?: string;
545
+ dependencies?: ZomeDependency[];
509
546
  } & ZomeLocation;
547
+ /**
548
+ * @public
549
+ */
550
+ export interface CoordinatorManifest {
551
+ zomes: Array<ZomeManifest>;
552
+ }
553
+ /**
554
+ * @public
555
+ */
556
+ export interface CoordinatorBundle {
557
+ manifest: CoordinatorManifest;
558
+ resources: ResourceMap;
559
+ }
560
+ /**
561
+ * @public
562
+ */
563
+ export type CoordinatorSource = {
564
+ path: string;
565
+ } | {
566
+ bundle: CoordinatorBundle;
567
+ };
510
568
  /**
511
569
  * @public
512
570
  */
@@ -624,6 +682,46 @@ export interface FullStateDump {
624
682
  source_chain_dump: SourceChainJsonDump;
625
683
  integration_dump: FullIntegrationStateDump;
626
684
  }
685
+ /**
686
+ * @public
687
+ */
688
+ export interface DnaStorageInfo {
689
+ authored_data_size: number;
690
+ authored_data_size_on_disk: number;
691
+ dht_data_size: number;
692
+ dht_data_size_on_disk: number;
693
+ cache_data_size: number;
694
+ cache_data_size_on_disk: number;
695
+ used_by: Array<InstalledAppId>;
696
+ }
697
+ /**
698
+ * @public
699
+ */
700
+ export interface DnaStorageBlob {
701
+ dna: DnaStorageInfo;
702
+ }
703
+ /**
704
+ * @public
705
+ */
706
+ export interface StorageInfo {
707
+ blobs: Array<DnaStorageBlob>;
708
+ }
709
+ /**
710
+ * @public
711
+ */
712
+ export type StorageInfoRequest = void;
713
+ /**
714
+ * @public
715
+ */
716
+ export type StorageInfoResponse = StorageInfo;
717
+ /**
718
+ * @public
719
+ */
720
+ export type DumpNetworkStatsRequest = void;
721
+ /**
722
+ * @public
723
+ */
724
+ export type DumpNetworkStatsResponse = string;
627
725
  /**
628
726
  * @public
629
727
  */
@@ -646,4 +744,6 @@ export interface AdminApi {
646
744
  addAgentInfo: Requester<AddAgentInfoRequest, AddAgentInfoResponse>;
647
745
  deleteCloneCell: Requester<DeleteCloneCellRequest, DeleteCloneCellResponse>;
648
746
  grantZomeCallCapability: Requester<GrantZomeCallCapabilityRequest, GrantZomeCallCapabilityResponse>;
747
+ storageInfo: Requester<StorageInfoRequest, StorageInfoResponse>;
748
+ dumpNetworkStats: Requester<DumpNetworkStatsRequest, DumpNetworkStatsResponse>;
649
749
  }
@@ -2,7 +2,7 @@ import { CapSecret, GrantedFunctions } from "../../hdk/capabilities.js";
2
2
  import type { AgentPubKey, CellId } from "../../types.js";
3
3
  import { WsClient } from "../client.js";
4
4
  import { Requester, Transformer } from "../common.js";
5
- import { AddAgentInfoRequest, AddAgentInfoResponse, AdminApi, AgentInfoRequest, AgentInfoResponse, AttachAppInterfaceRequest, AttachAppInterfaceResponse, DeleteCloneCellRequest, DeleteCloneCellResponse, DisableAppRequest, DisableAppResponse, DumpFullStateRequest, DumpFullStateResponse, DumpStateRequest, DumpStateResponse, EnableAppRequest, EnableAppResponse, GenerateAgentPubKeyRequest, GenerateAgentPubKeyResponse, GetDnaDefinitionRequest, GetDnaDefinitionResponse, GrantZomeCallCapabilityRequest, GrantZomeCallCapabilityResponse, InstallAppRequest, InstallAppResponse, ListAppInterfacesRequest, ListAppInterfacesResponse, ListAppsRequest, ListAppsResponse, ListCellIdsRequest, ListCellIdsResponse, ListDnasRequest, ListDnasResponse, RegisterDnaRequest, RegisterDnaResponse, UninstallAppRequest, UninstallAppResponse } from "./types.js";
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.
8
8
  *
@@ -25,7 +25,7 @@ export declare class AdminWebsocket implements AdminApi {
25
25
  * @param defaultTimeout - The default timeout for any request.
26
26
  * @returns A promise for a new connected instance.
27
27
  */
28
- static connect(url: string, defaultTimeout?: number): Promise<AdminWebsocket>;
28
+ static connect(url: URL, defaultTimeout?: number): Promise<AdminWebsocket>;
29
29
  _requester<ReqI, ReqO, ResI, ResO>(tag: string, transformer?: Transformer<ReqI, ReqO, ResI, ResO>): (req: ReqI, timeout?: number | undefined) => Promise<ResO>;
30
30
  /**
31
31
  * Send a request to open the given port for {@link AppWebsocket} connections.
@@ -70,6 +70,10 @@ export declare class AdminWebsocket implements AdminApi {
70
70
  * Install the specified app into Holochain.
71
71
  */
72
72
  installApp: Requester<InstallAppRequest, InstallAppResponse>;
73
+ /**
74
+ * Update coordinators for an installed app.
75
+ */
76
+ updateCoordinators: Requester<UpdateCoordinatorsRequest, UpdateCoordinatorsResponse>;
73
77
  /**
74
78
  * List all registered DNAs.
75
79
  */
@@ -103,6 +107,8 @@ export declare class AdminWebsocket implements AdminApi {
103
107
  * calls.
104
108
  */
105
109
  grantZomeCallCapability: Requester<GrantZomeCallCapabilityRequest, GrantZomeCallCapabilityResponse>;
110
+ storageInfo: Requester<StorageInfoRequest, StorageInfoResponse>;
111
+ dumpNetworkStats: Requester<DumpNetworkStatsRequest, DumpNetworkStatsResponse>;
106
112
  /**
107
113
  * Grant a capability for signing zome calls.
108
114
  *
@@ -34,7 +34,7 @@ export class AdminWebsocket {
34
34
  // Check if we are in the launcher's environment, and if so, redirect the url to connect to
35
35
  const env = getLauncherEnvironment();
36
36
  if (env?.ADMIN_INTERFACE_PORT) {
37
- url = `ws://127.0.0.1:${env.ADMIN_INTERFACE_PORT}`;
37
+ url = new URL(`ws://127.0.0.1:${env.ADMIN_INTERFACE_PORT}`);
38
38
  }
39
39
  const wsClient = await WsClient.connect(url);
40
40
  return new AdminWebsocket(wsClient, defaultTimeout);
@@ -85,6 +85,10 @@ export class AdminWebsocket {
85
85
  * Install the specified app into Holochain.
86
86
  */
87
87
  installApp = this._requester("install_app");
88
+ /**
89
+ * Update coordinators for an installed app.
90
+ */
91
+ updateCoordinators = this._requester("update_coordinators");
88
92
  /**
89
93
  * List all registered DNAs.
90
94
  */
@@ -118,6 +122,8 @@ export class AdminWebsocket {
118
122
  * calls.
119
123
  */
120
124
  grantZomeCallCapability = this._requester("grant_zome_call_capability");
125
+ storageInfo = this._requester("storage_info");
126
+ dumpNetworkStats = this._requester("dump_network_stats");
121
127
  // zome call signing related methods
122
128
  /**
123
129
  * Grant a capability for signing zome calls.
@@ -153,7 +159,7 @@ export class AdminWebsocket {
153
159
  * granted for all zomes and functions.
154
160
  */
155
161
  authorizeSigningCredentials = async (cellId, functions) => {
156
- const [keyPair, signingKey] = generateSigningKeyPair();
162
+ const [keyPair, signingKey] = await generateSigningKeyPair();
157
163
  const capSecret = await this.grantSigningKey(cellId, functions || { [GrantedFunctionsType.All]: null }, signingKey);
158
164
  setSigningCredentials(cellId, { capSecret, keyPair, signingKey });
159
165
  };
@@ -1,5 +1,5 @@
1
1
  import { AgentPubKey, CellId, DnaHash, DnaProperties, InstalledAppId, NetworkInfo, RoleName, Timestamp } from "../../types.js";
2
- import { AppInfo, ClonedCell, FunctionName, MembraneProof, NetworkSeed, ZomeName } from "../admin/index.js";
2
+ import { AppInfo, ClonedCell, FunctionName, MembraneProof, NetworkSeed, ZomeName } from "../admin/types.js";
3
3
  import { Requester } from "../common.js";
4
4
  /**
5
5
  * @public
@@ -114,9 +114,17 @@ export type EnableCloneCellResponse = CreateCloneCellResponse;
114
114
  */
115
115
  export interface NetworkInfoRequest {
116
116
  /**
117
- * The DNAs for which to get network info
117
+ * The calling agent
118
+ */
119
+ agent_pub_key: AgentPubKey;
120
+ /**
121
+ * Get network info for these DNAs
118
122
  */
119
123
  dnas: DnaHash[];
124
+ /**
125
+ * Timestamp in ms since which received amount of bytes from peers will be returned. Defaults to UNIX_EPOCH.
126
+ */
127
+ last_time_queried?: number;
120
128
  }
121
129
  /**
122
130
  * @public
@@ -23,8 +23,8 @@ export declare class AppWebsocket extends Emittery implements AppApi {
23
23
  * @param defaultTimeout - Timeout to default to for all operations.
24
24
  * @returns A new instance of an AppWebsocket.
25
25
  */
26
- static connect(url: string, defaultTimeout?: number): Promise<AppWebsocket>;
27
- _requester: <ReqI, ReqO, ResI, ResO>(tag: string, transformer?: Transformer<ReqI, ReqO, ResI, ResO> | undefined) => (req: ReqI, timeout?: number | undefined) => Promise<ResO>;
26
+ static connect(url: URL, defaultTimeout?: number): Promise<AppWebsocket>;
27
+ _requester<ReqI, ReqO, ResI, ResO>(tag: string, transformer?: Transformer<ReqI, ReqO, ResI, ResO>): (req: ReqI, timeout?: number | undefined) => Promise<ResO>;
28
28
  /**
29
29
  * Request the app's info, including all cell infos.
30
30
  *
@@ -1,11 +1,11 @@
1
1
  import { hashZomeCall } from "@holochain/serialization";
2
2
  import { decode, encode } from "@msgpack/msgpack";
3
+ import _sodium from "libsodium-wrappers";
3
4
  import Emittery from "emittery";
4
- import nacl from "tweetnacl";
5
- import { getHostZomeCallSigner, getLauncherEnvironment, isLauncher, signZomeCallTauri, } from "../../environments/launcher.js";
5
+ import { getLauncherEnvironment, signZomeCallTauri, signZomeCallElectron, getHostZomeCallSigner, } from "../../environments/launcher.js";
6
6
  import { encodeHashToBase64 } from "../../utils/base64.js";
7
7
  import { WsClient } from "../client.js";
8
- import { catchError, DEFAULT_TIMEOUT, promiseTimeout, requesterTransformer, } from "../common.js";
8
+ import { DEFAULT_TIMEOUT, catchError, promiseTimeout, requesterTransformer, } from "../common.js";
9
9
  import { getNonceExpiration, getSigningCredentials, randomNonce, } from "../zome-call-signing.js";
10
10
  /**
11
11
  * A class to establish a websocket connection to an App interface of a
@@ -19,6 +19,15 @@ export class AppWebsocket extends Emittery {
19
19
  overrideInstalledAppId;
20
20
  constructor(client, defaultTimeout, overrideInstalledAppId) {
21
21
  super();
22
+ // Ensure all super methods are bound to this instance because Emittery relies on `this` being the instance.
23
+ // Please retain until the upstream is fixed https://github.com/sindresorhus/emittery/issues/86.
24
+ Object.getOwnPropertyNames(Emittery.prototype).forEach((name) => {
25
+ const to_bind = this[name];
26
+ if (typeof to_bind === "function") {
27
+ this[name] =
28
+ to_bind.bind(this);
29
+ }
30
+ });
22
31
  this.client = client;
23
32
  this.defaultTimeout =
24
33
  defaultTimeout === undefined ? DEFAULT_TIMEOUT : defaultTimeout;
@@ -35,14 +44,16 @@ export class AppWebsocket extends Emittery {
35
44
  // Check if we are in the launcher's environment, and if so, redirect the url to connect to
36
45
  const env = getLauncherEnvironment();
37
46
  if (env?.APP_INTERFACE_PORT) {
38
- url = `ws://127.0.0.1:${env.APP_INTERFACE_PORT}`;
47
+ url = new URL(`ws://127.0.0.1:${env.APP_INTERFACE_PORT}`);
39
48
  }
40
49
  const wsClient = await WsClient.connect(url);
41
50
  const appWebsocket = new AppWebsocket(wsClient, defaultTimeout, env?.INSTALLED_APP_ID);
42
51
  wsClient.on("signal", (signal) => appWebsocket.emit("signal", signal));
43
52
  return appWebsocket;
44
53
  }
45
- _requester = (tag, transformer) => requesterTransformer((req, timeout) => promiseTimeout(this.client.request(req), tag, timeout || this.defaultTimeout).then(catchError), tag, transformer);
54
+ _requester(tag, transformer) {
55
+ return requesterTransformer((req, timeout) => promiseTimeout(this.client.request(req), tag, timeout || this.defaultTimeout).then(catchError), tag, transformer);
56
+ }
46
57
  /**
47
58
  * Request the app's info, including all cell infos.
48
59
  *
@@ -91,10 +102,16 @@ const callZomeTransform = {
91
102
  if (hostSigner) {
92
103
  return hostSigner.signZomeCall(request);
93
104
  }
94
- else if (isLauncher) {
105
+ else {
106
+ const env = getLauncherEnvironment();
107
+ if (!env) {
108
+ return signZomeCall(request);
109
+ }
110
+ if (env.FRAMEWORK === "electron") {
111
+ return signZomeCallElectron(request);
112
+ }
95
113
  return signZomeCallTauri(request);
96
114
  }
97
- return signZomeCall(request);
98
115
  },
99
116
  output: (response) => decode(response),
100
117
  };
@@ -128,9 +145,11 @@ export const signZomeCall = async (request) => {
128
145
  expires_at: getNonceExpiration(),
129
146
  };
130
147
  const hashedZomeCall = await hashZomeCall(unsignedZomeCallPayload);
131
- const signature = nacl
132
- .sign(hashedZomeCall, signingCredentialsForCell.keyPair.secretKey)
133
- .subarray(0, nacl.sign.signatureLength);
148
+ await _sodium.ready;
149
+ const sodium = _sodium;
150
+ const signature = sodium
151
+ .crypto_sign(hashedZomeCall, signingCredentialsForCell.keyPair.privateKey)
152
+ .subarray(0, sodium.crypto_sign_BYTES);
134
153
  const signedZomeCall = {
135
154
  ...unsignedZomeCallPayload,
136
155
  signature,
@@ -1,6 +1,6 @@
1
1
  import { UnsubscribeFunction } from "emittery";
2
2
  import { AgentPubKey, RoleName } from "../../index.js";
3
- import { AppInfoResponse, AppSignal, AppSignalCb, CallZomeRequest, CallZomeRequestSigned, DisableCloneCellRequest, EnableCloneCellRequest, EnableCloneCellResponse } from "../app/index.js";
3
+ import { AppInfoResponse, AppSignal, AppSignalCb, CallZomeRequest, CallZomeRequestSigned, DisableCloneCellRequest, EnableCloneCellRequest, EnableCloneCellResponse, NetworkInfoRequest, NetworkInfoResponse } from "../app/index.js";
4
4
  import { CreateCloneCellRequest, CreateCloneCellResponse, DisableCloneCellResponse } from "../index.js";
5
5
  /**
6
6
  * @public
@@ -34,6 +34,10 @@ export type AppEnableCloneCellRequest = Omit<EnableCloneCellRequest, "app_id">;
34
34
  * @public
35
35
  */
36
36
  export type AppDisableCloneCellRequest = Omit<DisableCloneCellRequest, "app_id">;
37
+ /**
38
+ * @public
39
+ */
40
+ export type AppAgentNetworkInfoRequest = Omit<NetworkInfoRequest, "agent_pub_key">;
37
41
  /**
38
42
  * @public
39
43
  */
@@ -51,4 +55,5 @@ export interface AppAgentClient {
51
55
  createCloneCell(args: AppCreateCloneCellRequest): Promise<CreateCloneCellResponse>;
52
56
  enableCloneCell(args: AppEnableCloneCellRequest): Promise<EnableCloneCellResponse>;
53
57
  disableCloneCell(args: AppDisableCloneCellRequest): Promise<DisableCloneCellResponse>;
58
+ networkInfo(args: AppAgentNetworkInfoRequest): Promise<NetworkInfoResponse>;
54
59
  }
@@ -1,7 +1,9 @@
1
1
  import Emittery, { UnsubscribeFunction } from "emittery";
2
2
  import { AgentPubKey, CellId, InstalledAppId, RoleName } from "../../types.js";
3
- import { AppInfo, AppSignalCb, AppWebsocket, CallZomeResponse, CreateCloneCellResponse, DisableCloneCellResponse, EnableCloneCellResponse } from "../index.js";
4
- import { AppAgentCallZomeRequest, AppAgentClient, AppAgentEvents, AppCreateCloneCellRequest, AppDisableCloneCellRequest, AppEnableCloneCellRequest } from "./types.js";
3
+ import { AppInfo } from "../admin/types.js";
4
+ import { AppSignalCb, CallZomeResponse, CreateCloneCellResponse, DisableCloneCellResponse, EnableCloneCellResponse, NetworkInfoResponse } from "../app/types.js";
5
+ import { AppWebsocket } from "../app/websocket.js";
6
+ import { AppAgentCallZomeRequest, AppAgentClient, AppAgentEvents, AppAgentNetworkInfoRequest, AppCreateCloneCellRequest, AppDisableCloneCellRequest, AppEnableCloneCellRequest } from "./types.js";
5
7
  /**
6
8
  * A class to establish a websocket connection to an App interface, for a
7
9
  * specific agent and app.
@@ -29,7 +31,7 @@ export declare class AppAgentWebsocket implements AppAgentClient {
29
31
  * @param defaultTimeout - Timeout to default to for all operations.
30
32
  * @returns A new instance of an AppAgentWebsocket.
31
33
  */
32
- static connect(url: string, installed_app_id: InstalledAppId, defaultTimeout?: number): Promise<AppAgentWebsocket>;
34
+ static connect(url: URL, installed_app_id: InstalledAppId, defaultTimeout?: number): Promise<AppAgentWebsocket>;
33
35
  /**
34
36
  * Get a cell id by its role name or clone id.
35
37
  *
@@ -66,6 +68,12 @@ export declare class AppAgentWebsocket implements AppAgentClient {
66
68
  * @param args - Specify the clone cell to disable.
67
69
  */
68
70
  disableCloneCell(args: AppDisableCloneCellRequest): Promise<DisableCloneCellResponse>;
71
+ /**
72
+ * Request network info about gossip status.
73
+ * @param args - Specify the DNAs for which you want network info
74
+ * @returns Network info for the specified DNAs
75
+ */
76
+ networkInfo(args: AppAgentNetworkInfoRequest): Promise<NetworkInfoResponse>;
69
77
  /**
70
78
  * Register an event listener for signals.
71
79
  *
@@ -1,8 +1,9 @@
1
1
  import Emittery from "emittery";
2
2
  import { omit } from "lodash-es";
3
3
  import { getLauncherEnvironment } from "../../environments/launcher.js";
4
+ import { CellType } from "../admin/types.js";
5
+ import { AppWebsocket } from "../app/websocket.js";
4
6
  import { getBaseRoleNameFromCloneId, isCloneId } from "../common.js";
5
- import { AppWebsocket, CellType, } from "../index.js";
6
7
  /**
7
8
  * A class to establish a websocket connection to an App interface, for a
8
9
  * specific agent and app.
@@ -18,6 +19,15 @@ export class AppAgentWebsocket {
18
19
  constructor(appWebsocket, installedAppId, myPubKey) {
19
20
  this.appWebsocket = appWebsocket;
20
21
  this.emitter = new Emittery();
22
+ // Ensure all super methods are bound to this instance because Emittery relies on `this` being the instance.
23
+ // Please retain until the upstream is fixed https://github.com/sindresorhus/emittery/issues/86.
24
+ Object.getOwnPropertyNames(Emittery.prototype).forEach((name) => {
25
+ const to_bind = this.emitter[name];
26
+ if (typeof to_bind === "function") {
27
+ this.emitter[name] =
28
+ to_bind.bind(this.emitter);
29
+ }
30
+ });
21
31
  const env = getLauncherEnvironment();
22
32
  this.installedAppId = env?.INSTALLED_APP_ID || installedAppId;
23
33
  this.myPubKey = myPubKey;
@@ -92,12 +102,7 @@ export class AppAgentWebsocket {
92
102
  * @returns The zome call's response.
93
103
  */
94
104
  async callZome(request, timeout) {
95
- if ("provenance" in request) {
96
- if ("role_name" in request && request.role_name) {
97
- throw new Error("Cannot find other agent's cells based on role name. Use cell id when providing a provenance.");
98
- }
99
- }
100
- else {
105
+ if (!("provenance" in request)) {
101
106
  request = {
102
107
  ...request,
103
108
  provenance: this.myPubKey,
@@ -155,6 +160,17 @@ export class AppAgentWebsocket {
155
160
  ...args,
156
161
  });
157
162
  }
163
+ /**
164
+ * Request network info about gossip status.
165
+ * @param args - Specify the DNAs for which you want network info
166
+ * @returns Network info for the specified DNAs
167
+ */
168
+ async networkInfo(args) {
169
+ return this.appWebsocket.networkInfo({
170
+ ...args,
171
+ agent_pub_key: this.myPubKey,
172
+ });
173
+ }
158
174
  /**
159
175
  * Register an event listener for signals.
160
176
  *
@@ -1,30 +1,28 @@
1
1
  /// <reference types="ws" />
2
- import { decode } from "@msgpack/msgpack";
3
2
  import Emittery from "emittery";
4
- import Websocket from "isomorphic-ws";
3
+ import IsoWebSocket from "isomorphic-ws";
5
4
  /**
6
- * A Websocket client which can make requests and receive responses,
5
+ * A WebSocket client which can make requests and receive responses,
7
6
  * as well as send and receive signals.
8
7
  *
9
- * Uses Holochain's websocket WireMessage for communication.
8
+ * Uses Holochain's WireMessage for communication.
10
9
  *
11
10
  * @public
12
11
  */
13
12
  export declare class WsClient extends Emittery {
14
- socket: Websocket;
15
- pendingRequests: Record<number, {
16
- resolve: (msg: unknown) => ReturnType<typeof decode>;
17
- reject: (error: Error) => void;
18
- }>;
19
- index: number;
20
- constructor(socket: Websocket);
13
+ socket: IsoWebSocket;
14
+ url: URL | undefined;
15
+ private pendingRequests;
16
+ private index;
17
+ constructor(socket: IsoWebSocket, url: URL);
18
+ private setupSocket;
21
19
  /**
22
20
  * Instance factory for creating WsClients.
23
21
  *
24
- * @param url - The `ws://` URL to connect to.
22
+ * @param url - The WebSocket URL to connect to.
25
23
  * @returns An new instance of the WsClient.
26
24
  */
27
- static connect(url: string): Promise<WsClient>;
25
+ static connect(url: URL): Promise<WsClient>;
28
26
  /**
29
27
  * Sends data as a signal.
30
28
  *
@@ -37,10 +35,12 @@ export declare class WsClient extends Emittery {
37
35
  * @param request - The request to send over the websocket.
38
36
  * @returns
39
37
  */
40
- request<Req, Res>(request: Req): Promise<Res>;
38
+ request<Response>(request: unknown): Promise<Response>;
39
+ private sendMessage;
41
40
  private handleResponse;
42
41
  /**
43
42
  * Close the websocket connection.
44
43
  */
45
- close(code?: number): Promise<void>;
44
+ close(code?: number): Promise<CloseEvent>;
46
45
  }
46
+ export { IsoWebSocket };