@eluvio/elv-client-js 4.0.135 → 4.0.137

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "4.0.135",
3
+ "version": "4.0.137",
4
4
  "description": "Javascript client for the Eluvio Content Fabric",
5
5
  "main": "src/index.js",
6
6
  "author": "Kevin Talmadge",
@@ -54,7 +54,7 @@
54
54
  "dependencies": {
55
55
  "@babel/runtime": "^7.8.4",
56
56
  "@eluvio/crypto": "^1.1.1",
57
- "@eluvio/elv-abr-profile": "^1.0.0",
57
+ "@eluvio/elv-abr-profile": "^1.0.2",
58
58
  "@sindresorhus/slugify": "^1.1.0",
59
59
  "babel-loader": "^8.0.6",
60
60
  "bignumber.js": "^8.0.2",
package/src/ElvClient.js CHANGED
@@ -16,7 +16,8 @@ const {LogMessage} = require("./LogMessage");
16
16
  const Pako = require("pako");
17
17
 
18
18
  const {
19
- ValidatePresence
19
+ ValidatePresence,
20
+ ValidateWriteToken
20
21
  } = require("./Validation");
21
22
  const UrlJoin = require("url-join");
22
23
 
@@ -618,10 +619,11 @@ class ElvClient {
618
619
  * @namedParams
619
620
  * @param {string=} matchEndpoint - Return node(s) matching the specified endpoint
620
621
  * @param {string=} matchNodeId - Return node(s) matching the specified node ID
622
+ * @param {string=} matchWriteToken - Return node(s) matching the specified write token
621
623
  *
622
624
  * @return {Promise<Array<Object>>} - A list of nodes in the space matching the parameters
623
625
  */
624
- async SpaceNodes({matchEndpoint, matchNodeId}={}) {
626
+ async SpaceNodes({matchEndpoint, matchNodeId, matchWriteToken}={}) {
625
627
  let nodes;
626
628
  this.SetStaticToken();
627
629
 
@@ -665,6 +667,7 @@ class ElvClient {
665
667
  });
666
668
  } else if(matchNodeId) {
667
669
  this.SetStaticToken();
670
+
668
671
  let node = await this.utils.ResponseToJson(
669
672
  this.HttpClient.Request({
670
673
  path: UrlJoin("nodes", matchNodeId),
@@ -677,6 +680,24 @@ class ElvClient {
677
680
 
678
681
  this.ClearStaticToken();
679
682
  return [node];
683
+ } else if(matchWriteToken) {
684
+ this.SetStaticToken();
685
+
686
+ const {nodes} = await this.utils.ResponseToJson(
687
+ this.HttpClient.Request({
688
+ path: UrlJoin("nodes"),
689
+ method: "GET",
690
+ headers: {
691
+ Authorization: `Bearer ${this.staticToken}`
692
+ },
693
+ queryParams: {
694
+ token: matchWriteToken
695
+ }
696
+ })
697
+ );
698
+
699
+ this.ClearStaticToken();
700
+ return nodes;
680
701
  }
681
702
  }
682
703
 
@@ -694,7 +715,50 @@ class ElvClient {
694
715
  };
695
716
  }
696
717
 
697
- WriteTokenNodeUrl({writeToken}) {
718
+ /**
719
+ * Return node url for a given write token via a network call
720
+ *
721
+ * @methodGroup Nodes
722
+ * @namedParams
723
+ * @param {string} writeToken - The write token to match to a node
724
+ *
725
+ * @returns {Promise<string>} - The node url for a write token
726
+ */
727
+ async WriteTokenNodeUrlNetwork({writeToken}) {
728
+ ValidateWriteToken(writeToken);
729
+
730
+ const nodes = await this.SpaceNodes({matchWriteToken: writeToken});
731
+
732
+ const nodeUrl = (
733
+ nodes &&
734
+ nodes[0] &&
735
+ nodes[0].services &&
736
+ nodes[0].services.fabric_api &&
737
+ nodes[0].services.fabric_api.urls &&
738
+ nodes[0].services.fabric_api.urls[0]
739
+ );
740
+
741
+ if(!nodeUrl) {
742
+ console.error(`No node url found for write token: ${writeToken}`);
743
+
744
+ return "";
745
+ }
746
+
747
+ return nodeUrl ? nodeUrl.toString() : undefined;
748
+ }
749
+
750
+ /**
751
+ * Return node url for a given write token via local lookup
752
+ *
753
+ * @methodGroup Nodes
754
+ * @namedParams
755
+ * @param {string} writeToken - The write token to match to a node
756
+ *
757
+ * @returns {string} - The node url for a write token
758
+ */
759
+ WriteTokenNodeUrlLocal({writeToken}) {
760
+ ValidateWriteToken(writeToken);
761
+
698
762
  const nodeUrl = this.HttpClient.draftURIs[writeToken];
699
763
 
700
764
  return nodeUrl ? nodeUrl.toString() : undefined;
@@ -509,7 +509,8 @@ class FrameClient {
509
509
  "UploadStatus",
510
510
  "UseRegion",
511
511
  "Visibility",
512
- "WriteTokenNodeUrl"
512
+ "WriteTokenNodeUrlLocal",
513
+ "WriteTokenNodeUrlNetwork"
513
514
  ];
514
515
  }
515
516