@tdxvolt/volt-client-grpc 0.1.0 → 0.1.2

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.
@@ -22,8 +22,10 @@ service VoltAPI {
22
22
  // Third party services can use this to interrogate the Volt policy and determine if a client has permission to perform a certain action on a resource.
23
23
  rpc CanAccessResource(CanAccessResourceRequest) returns (CanAccessResourceResponse);
24
24
 
25
+ rpc CheckCompatibility(CheckCompatibilityRequest) returns (CheckCompatibilityResponse);
26
+
25
27
  // Creates a long-lived, bi-directional connection (session) to the Volt.
26
- // The connection stream serves several purposes, including remote invocations via a tunnel, Volt event notifications, pings and service registration management.
28
+ // The connection stream serves several purposes, including remote invocations via a Relay, Volt event notifications, pings and service registration management.
27
29
  // A connection session is required in order for a client to be able to register services with the Volt.
28
30
  // When the stream is closed, any services registered on it will be set to offline.
29
31
  rpc Connect(stream ConnectRequest) returns (stream ConnectResponse);
@@ -83,9 +85,11 @@ service VoltAPI {
83
85
  rpc GetResourceDescendants(GetResourceDescendantsRequest) returns (GetResourceDescendantsResponse);
84
86
 
85
87
  // Invoke a method.
86
- // This is primarily for use by tunnel connections when proxying invocations.
88
+ // This is primarily for use by Relay connections when proxying invocations.
87
89
  rpc Invoke(stream InvokeRequest) returns (stream InvokeResponse);
88
90
 
91
+ rpc MoveResource(MoveResourceRequest) returns (MoveResourceResponse);
92
+
89
93
  // Request access to a resource.
90
94
  // The subject of the access is assumed to be the identity of the currently authenticated peer.
91
95
  rpc RequestAccess(RequestAccessRequest) returns (RequestAccessResponse);
@@ -216,6 +220,19 @@ message CanAccessResourceResponse {
216
220
  PolicyDecision decision = 6;
217
221
  }
218
222
 
223
+ message CheckCompatibilityRequest {
224
+ // The client platform API version.
225
+ Version version = 1;
226
+ }
227
+
228
+ message CheckCompatibilityResponse {
229
+ // Details of any error that occurred on the call.
230
+ tdx.volt_api.volt.v1.Status status = 1;
231
+
232
+ // The target Volt API version.
233
+ Version version = 2;
234
+ }
235
+
219
236
  // All fields in this message are optional, send an empty message if necessary.
220
237
  message ConnectHello {
221
238
  // Optionally specify the calling address of the peer.
@@ -228,19 +245,19 @@ message ConnectHello {
228
245
  // Set to receive notification of resource events.
229
246
  bool subscribe_resource_events = 3;
230
247
 
231
- // Set this to support tunnelled service invocation.
232
- // This indicates that the callee is happy to receive method invocations from other clients of the tunnel.
248
+ // Set this to support Relayled service invocation.
249
+ // This indicates that the callee is happy to receive method invocations from other clients of the Relay.
233
250
  // Currently this will usually be set to the `id` of the calling Volt, but in theory any client could receive remote invocation requests in this way.
234
- string tunnel_id = 4;
251
+ string relay_id = 4;
235
252
 
236
- // A friendly name to present to other tunnel clients.
237
- string tunnel_name = 5;
253
+ // A friendly name to present to other Relay clients.
254
+ string relay_name = 5;
238
255
 
239
- // The certificate authority to present to other tunnel clients.
240
- string tunnel_ca_pem = 6;
256
+ // The certificate authority to present to other Relay clients.
257
+ string relay_ca_pem = 6;
241
258
 
242
- // Set to indicate the connection is discoverable to other tunnel clients.
243
- bool tunnel_discoverable = 7;
259
+ // Set to indicate the connection is discoverable to other Relay clients.
260
+ bool relay_discoverable = 7;
244
261
  }
245
262
 
246
263
  // A session ping message.
@@ -277,7 +294,7 @@ message ConnectMessage {
277
294
  string from_identity_id = 10;
278
295
  string from_name = 11;
279
296
 
280
- repeated string receipts = 12;
297
+ repeated string receipt = 12;
281
298
  ConnectMessageType message_type = 15;
282
299
  ConnectMessageRelay message_relay = 16;
283
300
  }
@@ -290,8 +307,8 @@ message ConnectGoodbye {
290
307
  bool ended = 2;
291
308
  }
292
309
 
293
- message ConnectTunnel {
294
- // Indicates the tunnel connection status.
310
+ message ConnectRelay {
311
+ // Indicates the Relay connection status.
295
312
  bool connected = 1;
296
313
  }
297
314
 
@@ -317,8 +334,8 @@ message ConnectEvent {
317
334
  // A resource event notification, such as updated or deleted.
318
335
  ConnectResource connect_resource = 3;
319
336
 
320
- // Events relating to tunnel connections.
321
- ConnectTunnel tunnel = 6;
337
+ // Events relating to Relay connections.
338
+ ConnectRelay relay = 6;
322
339
  }
323
340
  }
324
341
 
@@ -338,7 +355,7 @@ message ConnectRequest {
338
355
  ConnectPing ping = 4;
339
356
 
340
357
  // Send invocation responses back to the caller.
341
- // n.b. The 'request' and 'response' semantics are inverted with remote invocations because the tunnelled connection is established by a request **from** the 'target' Volt to the tunnel. Hence any invocation on behalf of a client of the tunnel involves sending a **response** back down the tunnel connection to the 'target' Volt.
358
+ // n.b. The 'request' and 'response' semantics are inverted with remote invocations because the Relayed connection is established by a request **from** the 'target' Volt to the Relay. Hence any invocation on behalf of a client of the Relay involves sending a **response** back down the Relay connection to the 'target' Volt.
342
359
  InvokeResponse invoke_response = 5;
343
360
 
344
361
  // Send HTTP response back to the originating request.
@@ -366,7 +383,7 @@ message ConnectResponse {
366
383
  ConnectPing ping = 5;
367
384
 
368
385
  // Send an invocation request to a remote target.
369
- // n.b. The 'request' and 'response' semantics are inverted for remote invocations because the tunnelled connection is established by a request **from** the 'target' Volt to the tunnel. Hence any invocation on behalf of a client of the tunnel involves sending a **response** back down the tunnel connection to the 'target' Volt.
386
+ // n.b. The 'request' and 'response' semantics are inverted for remote invocations because the Relayed connection is established by a request **from** the 'target' Volt to the Relay. Hence any invocation on behalf of a client of the Relay involves sending a **response** back down the Relay connection to the 'target' Volt.
370
387
  InvokeRequest invoke_request = 6;
371
388
 
372
389
  // Send an HTTP request to a remote target.
@@ -401,6 +418,11 @@ message DeleteResourceRequest {
401
418
  // Set to indicate all descendant resources should also be deleted.
402
419
  // If this is not set and the resource has descendants, the call will fail.
403
420
  bool recursive = 2;
421
+
422
+ // Set to attempt to unlink the resource from this parent resource, rather than completely delete it.
423
+ // The resource will be removed as a descendant from the `parent_id` resource. If the resource is has more than one parent, it will not be removed from those other parents.
424
+ // Note that if the resource's only parent is `parent_id` it will be removed from that parent and deleted as normal.
425
+ string parent_id = 3;
404
426
  }
405
427
 
406
428
  message DeleteResourceResponse {
@@ -426,7 +448,7 @@ message DiscoverServicesResponse {
426
448
  tdx.volt_api.volt.v1.Status status = 1;
427
449
 
428
450
  // The services that were discovered.
429
- repeated Resource resources = 2;
451
+ repeated Resource resource = 2;
430
452
  }
431
453
 
432
454
  message GetAccessRequest {
@@ -467,7 +489,7 @@ message GetBindingsResponse {
467
489
  tdx.volt_api.volt.v1.Status status = 1;
468
490
 
469
491
  // The bindings that match the criteria.
470
- repeated Binding bindings = 2;
492
+ repeated Binding binding = 2;
471
493
  }
472
494
 
473
495
  message GetIdentitiesRequest {
@@ -485,7 +507,7 @@ message GetIdentitiesResponse {
485
507
  tdx.volt_api.volt.v1.Status status = 1;
486
508
 
487
509
  // The identity list that matched the criteria.
488
- repeated Identity identities = 2;
510
+ repeated Identity identity = 2;
489
511
  }
490
512
 
491
513
  // One of `identity_id` or `fingerprint` must be populated.
@@ -548,14 +570,8 @@ message GetResourceRequest {
548
570
  // The id of the resource to retrieve.
549
571
  string resource_id = 1;
550
572
 
551
- // Set to include resource attributes in the response.
552
- bool include_attributes = 2;
553
-
554
573
  // Set to include service description protobuf in the response, if applicable.
555
574
  bool include_protobuf = 3;
556
-
557
- // Set to include any aliases associated with the resource.
558
- bool include_aliases = 4;
559
575
  }
560
576
 
561
577
  message GetResourceResponse {
@@ -566,8 +582,9 @@ message GetResourceResponse {
566
582
  Resource resource = 2;
567
583
  }
568
584
 
569
- // Lookup is performed by combining the criteria below in the form:
585
+ // By default, the lookup is performed by combining the criteria below in the form:
570
586
  // (id = id[0] or id = id[1]) and (name = name[0] or name = name[1]) etc...
587
+ // To combine using 'or' rather than 'and', set the `combine_terms_exclusive` flag.
571
588
  // Also see note below regarding attributes.
572
589
  message GetResourcesRequest {
573
590
  repeated string id = 1;
@@ -590,9 +607,12 @@ message GetResourcesRequest {
590
607
 
591
608
  repeated string store = 9;
592
609
 
610
+ // Indicates that the above terms should be combined using 'or' rather than 'and' (the default).
611
+ bool combine_terms_exclusive = 10;
612
+
593
613
  // Attributes to search by.
594
614
  // n.b. currently this API is mutually exclusive in that if any attribute queries are specified the rpc will only search on those attributes, ignoring any parameters defined above.
595
- repeated ResourceAttributeQuery attributes = 100;
615
+ repeated ResourceAttributeQuery attribute = 100;
596
616
 
597
617
  // If set, will return resources where *any of* the attribute queries apply, otherwise will only return resources where *all of* the attribute queries apply.
598
618
  bool any_of = 101;
@@ -606,7 +626,7 @@ message GetResourcesResponse {
606
626
  tdx.volt_api.volt.v1.Status status = 1;
607
627
 
608
628
  // The list of resources that match the lookup.
609
- repeated Resource resources = 2;
629
+ repeated Resource resource = 2;
610
630
  }
611
631
 
612
632
  message GetResourceAncestorsRequest {
@@ -624,12 +644,6 @@ message GetResourceAncestorsRequest {
624
644
 
625
645
  // Optional - can be used to determine if a resource is an ancestor.
626
646
  string ancestor_id = 5;
627
-
628
- // Pre-load all resource attributes.
629
- bool include_attributes = 6;
630
-
631
- // Set to include any aliases associated with the resource.
632
- bool include_aliases = 7;
633
647
  }
634
648
 
635
649
  message GetResourceAncestorsResponse {
@@ -637,7 +651,7 @@ message GetResourceAncestorsResponse {
637
651
  tdx.volt_api.volt.v1.Status status = 1;
638
652
 
639
653
  // The retrieved ancestors.
640
- repeated Resource ancestors = 2;
654
+ repeated Resource ancestor = 2;
641
655
  }
642
656
 
643
657
  message GetResourceDescendantsRequest {
@@ -662,12 +676,6 @@ message GetResourceDescendantsRequest {
662
676
 
663
677
  // Restrict to a specific named resource.
664
678
  string name = 7;
665
-
666
- // Pre-load all resource attributes.
667
- bool include_attributes = 8;
668
-
669
- // Set to include any aliases associated with the resource.
670
- bool include_aliases = 9;
671
679
  }
672
680
 
673
681
  message GetResourceDescendantsResponse {
@@ -675,7 +683,7 @@ message GetResourceDescendantsResponse {
675
683
  tdx.volt_api.volt.v1.Status status = 1;
676
684
 
677
685
  // The retrieved descendants.
678
- repeated Resource descendants = 2;
686
+ repeated Resource descendant = 2;
679
687
  }
680
688
 
681
689
  message InvokeRequest {
@@ -686,7 +694,7 @@ message InvokeRequest {
686
694
  string token = 2;
687
695
 
688
696
  // Key fingerprint of the target Volt.
689
- // This is used by the tunnel to route the request.
697
+ // This is used by Relays to route the request.
690
698
  string identity_fingerprint = 3;
691
699
 
692
700
  oneof request_payload {
@@ -720,6 +728,25 @@ message InvokeResponse {
720
728
  bool server_end = 5;
721
729
  }
722
730
 
731
+ enum MoveResourceMode {
732
+ MOVE_RESOURCE_MODE_UNKNOWN = 0;
733
+ MOVE_RESOURCE_MODE_MOVE = 1;
734
+ MOVE_RESOURCE_MODE_LINK = 2;
735
+ MOVE_RESOURCE_MODE_COPY = 3;
736
+ }
737
+
738
+ message MoveResourceRequest {
739
+ string resource_id = 1;
740
+ string from_resource_id = 2;
741
+ string to_resource_id = 3;
742
+ MoveResourceMode move_mode = 4;
743
+ }
744
+
745
+ message MoveResourceResponse {
746
+ // Details of any error that occurred on the call.
747
+ tdx.volt_api.volt.v1.Status status = 1;
748
+ }
749
+
723
750
  message RequestAccessRequest {
724
751
  // The target resource id.
725
752
  string resource_id = 1;
@@ -847,6 +874,12 @@ message SaveResourceRequest {
847
874
  // The id of the folder resource in which a new resource should be created.
848
875
  // If omitted, the home folder of the currently authenticated identity will be used.
849
876
  string create_in_parent_id = 3;
877
+
878
+ // Set to indicate the resource attributes should be purged before saving the resource.
879
+ // If the `resource` field contains attributes they will be saved after the purge.
880
+ // If the `resource` field does not contain attributes this effectively deletes all attributes for this resource.
881
+ // This allows you to selectively update attributes if required, i.e. don't set this flag and include a single attribute in the update.
882
+ bool purge_attributes = 4;
850
883
  }
851
884
 
852
885
  message SaveResourceResponse {
@@ -7,14 +7,16 @@ import "tdx/volt_api/volt/v1/status.proto";
7
7
  // The Wire API allows clients to subscribe and publish to Volt wire resources.
8
8
  service WireAPI {
9
9
  // Establishes a client-streaming call to the wire resource.
10
- rpc PublishWire(stream PublishRequest) returns (PublishResponse);
10
+ rpc PublishWire(stream PublishWireRequest) returns (stream PublishWireResponse);
11
11
 
12
12
  // Establishes a bi-directional streaming call to the wire resource.
13
13
  // Although we're only really interested in receiving data from the wire, a bi-directional stream is required so that we can gracefully stop the subscription.
14
- rpc SubscribeWire(stream SubscribeRequest) returns (stream SubscribeResponse);
14
+ rpc SubscribeWire(stream SubscribeWireRequest) returns (stream SubscribeWireResponse);
15
15
  }
16
16
 
17
- message PublishRequest {
17
+ // Because the publish RPC is client-streaming, the policy will not be checked until the first message arrives. This can mean that the `PublishWire` call appears to succeed but then fails after the first attempt to publish a message.
18
+ // To avoid this, clients can immediately send a message with the `wire_id` set and no `chunk` set. This will establish that the correct permissions are in place and fail fast if not.
19
+ message PublishWireRequest {
18
20
  // Only necessary in the first payload.
19
21
  string wire_id = 1;
20
22
 
@@ -22,13 +24,13 @@ message PublishRequest {
22
24
  bytes chunk = 2;
23
25
  }
24
26
 
25
- message PublishResponse {
27
+ message PublishWireResponse {
26
28
  // Details of any error that occurred on the call.
27
29
  tdx.volt_api.volt.v1.Status status = 1;
28
30
  }
29
31
 
30
32
  // The request must include one of the following fields.
31
- message SubscribeRequest {
33
+ message SubscribeWireRequest {
32
34
  oneof payload {
33
35
  // The wire id, only required for the first message.
34
36
  string wire_id = 1;
@@ -38,7 +40,7 @@ message SubscribeRequest {
38
40
  }
39
41
 
40
42
  // One of the following fields will be present in the response.
41
- message SubscribeResponse {
43
+ message SubscribeWireResponse {
42
44
  oneof payload {
43
45
  // Details of any error that occured on the call.
44
46
  tdx.volt_api.volt.v1.Status status = 1;
package/src/constants.js CHANGED
@@ -1,75 +1,75 @@
1
1
  // eslint-disable-next-line import/prefer-default-export
2
2
  export const constants = {
3
- authTokenName: "tdx-token",
4
- collectionOperation: {
5
- add: "ADD",
6
- remove: "REMOVE",
7
- update: "UPDATE",
8
- },
9
- crypto: {
10
- subjectDefaults: [
11
- {
12
- name: "countryName",
13
- value: "GB",
14
- },
15
- {
16
- name: "localityName",
17
- value: "Southampton",
18
- },
19
- {
20
- name: "organizationName",
21
- value: "nquiringminds Ltd",
22
- },
23
- ],
24
- userIdOID: "0.9.2342.19200300.100.1.1",
25
- },
26
- defaultDIDHostName: "volt.tdxcloud.com",
27
- didServiceType: {
28
- voltConfig: "tdx-volt-config",
29
- },
30
- identityType: {
31
- did: "did",
32
- volt: "volt",
33
- },
34
- onlineStatus: {
35
- offline: "offline",
36
- online: "online",
37
- unknown: "unknown",
38
- },
39
- publicKeyPrefix: "-----BEGIN PUBLIC KEY-----",
40
- privateKeyPrefix: "-----BEGIN RSA PRIVATE KEY-----",
41
- privateEncryptedKeyPrefix: "-----BEGIN ENCRYPTED PRIVATE KEY-----",
42
- resource: {
43
- identity: "ident",
44
- identityView: "ident-view",
45
- proxy: "proxy",
46
- proxyView: "proxy-view",
47
- vc: "vc",
48
- vcView: "vc-view",
49
- },
50
- voltStatus: {
51
- pending: "",
52
- online: "online",
53
- offline: "offline",
54
- deleted: "deleted",
55
- revoked: "revoked",
56
- },
57
- /**
58
- * These top-level service types should map to a protobuf definition
59
- * in @tdxvolt/volt-proto.
60
- */
61
- serviceType: {
62
- fileAPI: "tdx.volt_api.volt.v1.FileAPI",
63
- protocolBridgeDataStream: "tdx.volt_api.protocol_bridge.v1.ProtocolBridgeStreamAPI",
64
- sqliteServerAPI: "tdx.volt_api.data.v1.SqliteServerAPI",
65
- ssiAPI: "tdx.volt_api.ssi.v1.SsiAPI",
66
- tunnelAPI: "tdx.volt_api.tunnel.v1.TunnelAPI",
67
- voltAPI: "tdx.volt_api.volt.v1.VoltAPI",
68
- wireAPI: "tdx.volt_api.volt.v1.WireAPI",
69
- },
70
- tunnelInvokeMethod: "/tdx.volt_api.volt.v1.VoltAPI/Invoke",
71
- tunnelPingInterval: 10000,
72
- tunnelPingTimeout: 2500,
73
- tunnelReconnectAfter: 30000,
74
- tunnelTimeoutInterval: 10000 * 2, // This must always be greater than `tunnelPingInterval`.
3
+ authTokenName: "tdx-token",
4
+ collectionOperation: {
5
+ add: "ADD",
6
+ remove: "REMOVE",
7
+ update: "UPDATE",
8
+ },
9
+ crypto: {
10
+ subjectDefaults: [
11
+ {
12
+ name: "countryName",
13
+ value: "GB",
14
+ },
15
+ {
16
+ name: "localityName",
17
+ value: "Southampton",
18
+ },
19
+ {
20
+ name: "organizationName",
21
+ value: "nquiringminds Ltd",
22
+ },
23
+ ],
24
+ userIdOID: "0.9.2342.19200300.100.1.1",
25
+ },
26
+ defaultDIDHostName: "cloud.tdxvolt.com",
27
+ didServiceType: {
28
+ voltConfig: "tdx-volt-config",
29
+ },
30
+ identityType: {
31
+ did: "did",
32
+ volt: "volt",
33
+ },
34
+ onlineStatus: {
35
+ offline: "offline",
36
+ online: "online",
37
+ unknown: "unknown",
38
+ },
39
+ publicKeyPrefix: "-----BEGIN PUBLIC KEY-----",
40
+ privateKeyPrefix: "-----BEGIN RSA PRIVATE KEY-----",
41
+ privateEncryptedKeyPrefix: "-----BEGIN ENCRYPTED PRIVATE KEY-----",
42
+ resource: {
43
+ identity: "ident",
44
+ identityView: "ident-view",
45
+ proxy: "proxy",
46
+ proxyView: "proxy-view",
47
+ vc: "vc",
48
+ vcView: "vc-view",
49
+ },
50
+ voltStatus: {
51
+ pending: "",
52
+ online: "online",
53
+ offline: "offline",
54
+ deleted: "deleted",
55
+ revoked: "revoked",
56
+ },
57
+ /**
58
+ * These top-level service types should map to a protobuf definition
59
+ * in @tdxvolt/volt-proto.
60
+ */
61
+ serviceType: {
62
+ fileAPI: "tdx.volt_api.volt.v1.FileAPI",
63
+ sqliteServerAPI: "tdx.volt_api.data.v1.SqliteServerAPI",
64
+ sqliteDatabaseAPI: "tdx.volt_api.data.v1.SqliteDatabaseAPI",
65
+ ssiAPI: "tdx.volt_api.ssi.v1.SsiAPI",
66
+ relayAPI: "tdx.volt_api.relay.v1.RelayAPI",
67
+ voltAPI: "tdx.volt_api.volt.v1.VoltAPI",
68
+ wireAPI: "tdx.volt_api.volt.v1.WireAPI",
69
+ },
70
+ tunnelInvokeMethod: "/tdx.volt_api.volt.v1.VoltAPI/Invoke",
71
+ tunnelPingInterval: 10000,
72
+ tunnelPingTimeout: 2500,
73
+ tunnelReconnectAfter: 30000,
74
+ tunnelTimeoutInterval: 10000 * 2, // This must always be greater than `tunnelPingInterval`.
75
75
  };
package/src/grpc-call.js CHANGED
@@ -1,20 +1,20 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
2
  import debug from "debug";
3
3
  import EventEmitter from "events";
4
- import {VoltCrypto} from "./volt-crypto.js";
4
+ import {VoltCredential} from "./volt-credential.js";
5
5
 
6
6
  const log = debug("volt-client-grpc:grpc-call");
7
7
 
8
8
  function _prepareInvokeRequest(request, method, methodType = "METHOD_TYPE_UNARY") {
9
- const meta = this._voltClient.crypto.getIdentityMetadata(
9
+ const meta = this._voltClient.credential.getIdentityMetadata(
10
10
  this._voltClient.grpc,
11
- this._voltClient.options.id,
11
+ this._voltClient.voltConfig.id,
12
12
  this._voltClient.isRemote
13
13
  );
14
14
  let invokeRequest;
15
15
  let callMethod = method;
16
16
 
17
- if (this._voltClient.isVoltTunnel) {
17
+ if (this._voltClient.isVoltRelay) {
18
18
  let requestPayload;
19
19
  if (request) {
20
20
  requestPayload = this._grpcClient[method].requestSerialize(request);
@@ -35,23 +35,23 @@ function _prepareInvokeRequest(request, method, methodType = "METHOD_TYPE_UNARY"
35
35
  },
36
36
  };
37
37
 
38
- const invokePayload = VoltCrypto.aesEncrypt(
38
+ const invokePayload = VoltCredential.aesEncrypt(
39
39
  tunnelMethod.responseSerialize(tunnelResp),
40
40
  meta.sharedKey.key,
41
41
  meta.sharedKey.iv
42
42
  );
43
43
 
44
- log("target volt is %s", this._voltClient.crypto.voltFingerprint);
44
+ log("target volt is %s", this._voltClient.credential.voltFingerprint);
45
45
 
46
46
  invokeRequest = {
47
- identity_fingerprint: this._voltClient.crypto.voltFingerprint,
47
+ identity_fingerprint: this._voltClient.credential.voltFingerprint,
48
48
  payload: invokePayload,
49
49
  };
50
50
 
51
51
  callMethod = "Invoke";
52
52
  } else if (this._voltClient.isRemote && meta.sharedKey.key) {
53
53
  const requestPayload = this._grpcClient[method].requestSerializeOriginal(request);
54
- invokeRequest = VoltCrypto.aesEncrypt(requestPayload, meta.sharedKey.key, meta.sharedKey.iv);
54
+ invokeRequest = VoltCredential.aesEncrypt(requestPayload, meta.sharedKey.key, meta.sharedKey.iv);
55
55
  } else {
56
56
  invokeRequest = request;
57
57
  }
@@ -67,7 +67,7 @@ function _prepareInvokeRequest(request, method, methodType = "METHOD_TYPE_UNARY"
67
67
  function _preparePayloadRequest(request, invokeInfo) {
68
68
  let payloadRequest;
69
69
 
70
- if (this._voltClient.isVoltTunnel) {
70
+ if (this._voltClient.isVoltRelay) {
71
71
  const requestPayload = this._grpcClient[invokeInfo.methodName].requestSerialize(request);
72
72
  const tunnelMethod = this._grpcClient.Tunnel;
73
73
 
@@ -77,7 +77,7 @@ function _preparePayloadRequest(request, invokeInfo) {
77
77
  },
78
78
  };
79
79
 
80
- const invokePayload = VoltCrypto.aesEncrypt(
80
+ const invokePayload = VoltCredential.aesEncrypt(
81
81
  tunnelMethod.responseSerialize(tunnelResp),
82
82
  invokeInfo.meta.sharedKey.key,
83
83
  invokeInfo.meta.sharedKey.iv
@@ -88,7 +88,11 @@ function _preparePayloadRequest(request, invokeInfo) {
88
88
  };
89
89
  } else if (this._voltClient.isRemote && invokeInfo.meta.sharedKey.key) {
90
90
  const requestPayload = this._grpcClient[invokeInfo.methodName].requestSerializeOriginal(request);
91
- payloadRequest = VoltCrypto.aesEncrypt(requestPayload, invokeInfo.meta.sharedKey.key, invokeInfo.meta.sharedKey.iv);
91
+ payloadRequest = VoltCredential.aesEncrypt(
92
+ requestPayload,
93
+ invokeInfo.meta.sharedKey.key,
94
+ invokeInfo.meta.sharedKey.iv
95
+ );
92
96
  } else {
93
97
  payloadRequest = request;
94
98
  }
@@ -99,9 +103,9 @@ function _preparePayloadRequest(request, invokeInfo) {
99
103
  function _parseResponse(method, meta, response) {
100
104
  let invokeResponse = {};
101
105
 
102
- if (this._voltClient.isVoltTunnel) {
106
+ if (this._voltClient.isVoltRelay) {
103
107
  if (response.payload) {
104
- const decryptedPayload = VoltCrypto.aesDecrypt(response.payload, meta.sharedKey.key, meta.sharedKey.iv);
108
+ const decryptedPayload = VoltCredential.aesDecrypt(response.payload, meta.sharedKey.key, meta.sharedKey.iv);
105
109
  const tunnelMethod = this._grpcClient.Tunnel;
106
110
  const responsePayload = tunnelMethod.requestDeserialize(decryptedPayload);
107
111
  if (responsePayload.payload === "method_payload") {
@@ -111,7 +115,7 @@ function _parseResponse(method, meta, response) {
111
115
  } else {
112
116
  log("unexpected tunnel payload type: %s", responsePayload.payload);
113
117
  }
114
- } else if (response.status && response.status.message) {
118
+ } else if (response.status?.message) {
115
119
  // There's been an error in the tunnel.
116
120
  log(
117
121
  "Tunnel status received: %s, code %d, description: %s",
@@ -125,7 +129,7 @@ function _parseResponse(method, meta, response) {
125
129
  log("started method %d for %s", invokeResponse.methodId, method);
126
130
  }
127
131
  } else if (this._voltClient.isRemote && meta.sharedKey.key) {
128
- const decryptedPayload = VoltCrypto.aesDecrypt(response, meta.sharedKey.key, meta.sharedKey.iv);
132
+ const decryptedPayload = VoltCredential.aesDecrypt(response, meta.sharedKey.key, meta.sharedKey.iv);
129
133
  invokeResponse = {payload: this._grpcClient[method].responseDeserializeOriginal(decryptedPayload)};
130
134
  } else {
131
135
  invokeResponse = {payload: response};
@@ -178,6 +182,10 @@ export default class GRPCCall extends EventEmitter {
178
182
 
179
183
  this._initialRequest = _prepareInvokeRequest.call(this, request, this._methodName, this._methodType);
180
184
 
185
+ if (!this._grpcClient[this._initialRequest.method]) {
186
+ return reject(new Error(`method not found: '${this._initialRequest.method}'`));
187
+ }
188
+
181
189
  this._call = this._grpcClient[this._initialRequest.method](this._initialRequest.meta.metadata, callbackIntercept);
182
190
 
183
191
  this._call.on("data", (streamResponse) => {
@@ -227,28 +235,28 @@ export default class GRPCCall extends EventEmitter {
227
235
  }
228
236
 
229
237
  end() {
230
- if (!this._call) {
231
- throw new Error("call not initialised");
232
- } else {
238
+ if (this._call) {
233
239
  return this._call.end();
240
+ } else {
241
+ throw new Error("call not initialised");
234
242
  }
235
243
  }
236
244
 
237
245
  get writable() {
238
- return this._call && this._call.writable;
246
+ return this._call?.writable;
239
247
  }
240
248
 
241
249
  write(request) {
242
250
  if (!this._call) {
243
251
  log("ERROR - call not initialised");
244
252
  throw new Error("call not initialised");
245
- } else if (!this._initialRequest) {
253
+ } else if (this._initialRequest) {
254
+ const payloadRequest = _preparePayloadRequest.call(this, request, this._initialRequest);
255
+ return this._call.write(payloadRequest);
256
+ } else {
246
257
  this._initialRequest = _prepareInvokeRequest.call(this, request, this._methodName, this._methodType);
247
258
 
248
259
  return this._call.write(this._initialRequest.request);
249
- } else {
250
- const payloadRequest = _preparePayloadRequest.call(this, request, this._initialRequest);
251
- return this._call.write(payloadRequest);
252
260
  }
253
261
  }
254
262
  }