@eluvio/elv-client-js 4.0.1 → 4.0.3

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.
@@ -83,7 +83,8 @@ var ElvClient = /*#__PURE__*/function () {
83
83
  *
84
84
  * @namedParams
85
85
  * @param {string} contentSpaceId - ID of the content space
86
- * @param {string} contentSpaceId - ID of the blockchain network
86
+ * @param {string} networkId - ID of the blockchain network
87
+ * @param {string} networkName - Name of the blockchain network
87
88
  * @param {number} fabricVersion - The version of the target content fabric
88
89
  * @param {Array<string>} fabricURIs - A list of full URIs to content fabric nodes
89
90
  * @param {Array<string>} ethereumURIs - A list of full URIs to ethereum nodes
@@ -94,6 +95,9 @@ var ElvClient = /*#__PURE__*/function () {
94
95
  * @param {string=} staticToken - Static token that will be used for all authorization in place of normal auth
95
96
  * @param {boolean=} noCache=false - If enabled, blockchain transactions will not be cached
96
97
  * @param {boolean=} noAuth=false - If enabled, blockchain authorization will not be performed
98
+ * @param {boolean=} assumeV3=false - If enabled, V3 fabric will be assumed
99
+ * @param {string=} service=default - The mode that determines how HttpClient will be initialized.
100
+ * If 'default' is set, HttpClient uris will use fabricUris. If 'search' is used, searchUris will be used
97
101
  *
98
102
  * @return {ElvClient} - New ElvClient connected to the specified content fabric and blockchain
99
103
  */
@@ -115,7 +119,9 @@ var ElvClient = /*#__PURE__*/function () {
115
119
  _ref$noAuth = _ref.noAuth,
116
120
  noAuth = _ref$noAuth === void 0 ? false : _ref$noAuth,
117
121
  _ref$assumeV = _ref.assumeV3,
118
- assumeV3 = _ref$assumeV === void 0 ? false : _ref$assumeV;
122
+ assumeV3 = _ref$assumeV === void 0 ? false : _ref$assumeV,
123
+ _ref$service = _ref.service,
124
+ service = _ref$service === void 0 ? "default" : _ref$service;
119
125
 
120
126
  _classCallCheck(this, ElvClient);
121
127
 
@@ -136,6 +142,12 @@ var ElvClient = /*#__PURE__*/function () {
136
142
  this.noCache = noCache;
137
143
  this.noAuth = noAuth;
138
144
  this.assumeV3 = assumeV3;
145
+
146
+ if (!["search", "default"].includes(this.service)) {
147
+ throw Error("Invalid service: ".concat(this.service));
148
+ }
149
+
150
+ this.service = service;
139
151
  this.debug = false;
140
152
  this.InitializeClients({
141
153
  staticToken: staticToken
@@ -261,6 +273,7 @@ var ElvClient = /*#__PURE__*/function () {
261
273
  var _InitializeClients = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
262
274
  var _ref3,
263
275
  staticToken,
276
+ uris,
264
277
  wallet,
265
278
  signer,
266
279
  _args2 = arguments;
@@ -279,8 +292,9 @@ var ElvClient = /*#__PURE__*/function () {
279
292
  this.objectImageUrls = {};
280
293
  this.visibilityInfo = {};
281
294
  this.inaccessibleLibraries = {};
295
+ uris = this.service === "search" ? this.searchURIs : this.fabricURIs;
282
296
  this.HttpClient = new HttpClient({
283
- uris: this.fabricURIs,
297
+ uris: uris,
284
298
  debug: this.debug
285
299
  });
286
300
  this.AuthHttpClient = new HttpClient({
@@ -325,7 +339,7 @@ var ElvClient = /*#__PURE__*/function () {
325
339
  this.Crypto = Crypto;
326
340
  this.Crypto.ElvCrypto();
327
341
 
328
- case 17:
342
+ case 18:
329
343
  case "end":
330
344
  return _context2.stop();
331
345
  }
@@ -360,7 +374,7 @@ var ElvClient = /*#__PURE__*/function () {
360
374
  * @param {string} region - Preferred region - the fabric will auto-detect the best region if not specified
361
375
  * - Available regions: as-east au-east eu-east-north eu-west-north na-east-north na-east-south na-west-north na-west-south eu-east-south eu-west-south
362
376
  *
363
- * @return {Promise<Object>} - An object containing the updated fabric and ethereum URLs in order of preference
377
+ * @return {Promise<Object>} - An object containing the updated fabric, ethereum, auth service, and search URLs in order of preference
364
378
  */
365
379
 
366
380
  }, {
@@ -521,11 +535,11 @@ var ElvClient = /*#__PURE__*/function () {
521
535
  return NodeId;
522
536
  }()
523
537
  /**
524
- * Retrieve the fabric and ethereum nodes currently used by the client, in preference order
538
+ * Retrieve the fabric, ethereum, auth service, and search nodes currently used by the client, in preference order
525
539
  *
526
540
  * @methodGroup Nodes
527
541
  *
528
- * @return {Promise<Object>} - An object containing the lists of fabric and ethereum urls in use by the client
542
+ * @return {Promise<Object>} - An object containing the lists of fabric, ethereum, auth service, and search urls in use by the client
529
543
  */
530
544
 
531
545
  }, {
@@ -534,16 +548,18 @@ var ElvClient = /*#__PURE__*/function () {
534
548
  return {
535
549
  fabricURIs: this.fabricURIs,
536
550
  ethereumURIs: this.ethereumURIs,
537
- authServiceURIs: this.authServiceURIs
551
+ authServiceURIs: this.authServiceURIs,
552
+ searchURIs: this.searchURIs
538
553
  };
539
554
  }
540
555
  /**
541
- * Set the client to use the specified fabric and ethereum nodes, in preference order
556
+ * Set the client to use the specified fabric, ethereum, auth service, and search nodes, in preference order
542
557
  *
543
558
  * @namedParams
544
559
  * @param {Array<string>=} fabricURIs - A list of URLs for the fabric, in preference order
545
560
  * @param {Array<string>=} ethereumURIs - A list of URLs for the blockchain, in preference order
546
561
  * @param {Array<string>=} authServiceURIs - A list of URLs for the auth service, in preference order
562
+ * @param {Array<string>=} searchURIs - A list of URLs for the search nodes, in preference order
547
563
  *
548
564
  * @methodGroup Nodes
549
565
  */
@@ -553,7 +569,8 @@ var ElvClient = /*#__PURE__*/function () {
553
569
  value: function SetNodes(_ref6) {
554
570
  var fabricURIs = _ref6.fabricURIs,
555
571
  ethereumURIs = _ref6.ethereumURIs,
556
- authServiceURIs = _ref6.authServiceURIs;
572
+ authServiceURIs = _ref6.authServiceURIs,
573
+ searchURIs = _ref6.searchURIs;
557
574
 
558
575
  if (fabricURIs) {
559
576
  this.fabricURIs = fabricURIs;
@@ -572,6 +589,10 @@ var ElvClient = /*#__PURE__*/function () {
572
589
  this.AuthHttpClient.uris = authServiceURIs;
573
590
  this.AuthHttpClient.uriIndex = 0;
574
591
  }
592
+
593
+ if (searchURIs) {
594
+ this.searchURIs = searchURIs;
595
+ }
575
596
  }
576
597
  /**
577
598
  * Return information about how the client was connected to the network
@@ -36,8 +36,8 @@ var HttpClient = /*#__PURE__*/function () {
36
36
  }
37
37
  }, {
38
38
  key: "BaseURI",
39
- value: function BaseURI(url) {
40
- return new URI(url || this.uris[this.uriIndex]);
39
+ value: function BaseURI() {
40
+ return new URI(this.uris[this.uriIndex]);
41
41
  }
42
42
  }, {
43
43
  key: "RecordWriteToken",
@@ -65,15 +65,14 @@ var HttpClient = /*#__PURE__*/function () {
65
65
  key: "Request",
66
66
  value: function () {
67
67
  var _Request = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2) {
68
- var method, path, _ref2$queryParams, queryParams, body, _ref2$bodyType, bodyType, _ref2$headers, headers, _ref2$attempts, attempts, _ref2$failover, failover, _ref2$forceFailover, forceFailover, nodeUrl, baseURI, writeTokenMatch, writeToken, uri, fetchParameters, response, responseType, errorBody, error;
68
+ var method, path, _ref2$queryParams, queryParams, body, _ref2$bodyType, bodyType, _ref2$headers, headers, _ref2$attempts, attempts, _ref2$failover, failover, _ref2$forceFailover, forceFailover, baseURI, writeTokenMatch, writeToken, uri, fetchParameters, response, responseType, errorBody, error;
69
69
 
70
70
  return _regeneratorRuntime.wrap(function _callee$(_context) {
71
71
  while (1) {
72
72
  switch (_context.prev = _context.next) {
73
73
  case 0:
74
- method = _ref2.method, path = _ref2.path, _ref2$queryParams = _ref2.queryParams, queryParams = _ref2$queryParams === void 0 ? {} : _ref2$queryParams, body = _ref2.body, _ref2$bodyType = _ref2.bodyType, bodyType = _ref2$bodyType === void 0 ? "JSON" : _ref2$bodyType, _ref2$headers = _ref2.headers, headers = _ref2$headers === void 0 ? {} : _ref2$headers, _ref2$attempts = _ref2.attempts, attempts = _ref2$attempts === void 0 ? 0 : _ref2$attempts, _ref2$failover = _ref2.failover, failover = _ref2$failover === void 0 ? true : _ref2$failover, _ref2$forceFailover = _ref2.forceFailover, forceFailover = _ref2$forceFailover === void 0 ? false : _ref2$forceFailover, nodeUrl = _ref2.nodeUrl;
75
- // if nodeUrl passed in, restrict communication to that node only (unless previously recorded write token is found in next step)
76
- baseURI = this.BaseURI(nodeUrl); // If URL contains a write token, it must go to the correct server and can not fail over
74
+ method = _ref2.method, path = _ref2.path, _ref2$queryParams = _ref2.queryParams, queryParams = _ref2$queryParams === void 0 ? {} : _ref2$queryParams, body = _ref2.body, _ref2$bodyType = _ref2.bodyType, bodyType = _ref2$bodyType === void 0 ? "JSON" : _ref2$bodyType, _ref2$headers = _ref2.headers, headers = _ref2$headers === void 0 ? {} : _ref2$headers, _ref2$attempts = _ref2.attempts, attempts = _ref2$attempts === void 0 ? 0 : _ref2$attempts, _ref2$failover = _ref2.failover, failover = _ref2$failover === void 0 ? true : _ref2$failover, _ref2$forceFailover = _ref2.forceFailover, forceFailover = _ref2$forceFailover === void 0 ? false : _ref2$forceFailover;
75
+ baseURI = this.BaseURI(); // If URL contains a write token, it must go to the correct server and can not fail over
77
76
 
78
77
  writeTokenMatch = path.replace(/^\//, "").match(/(qlibs\/ilib[a-zA-Z0-9]+|q|qid)\/(tqw__[a-zA-Z0-9]+)/);
79
78
  writeToken = writeTokenMatch ? writeTokenMatch[2] : undefined;
@@ -128,7 +127,7 @@ var HttpClient = /*#__PURE__*/function () {
128
127
  break;
129
128
  }
130
129
 
131
- if (!(!writeToken && !nodeUrl && (failover && parseInt(response.status) >= 500 || forceFailover) && attempts < this.uris.length)) {
130
+ if (!(!writeToken && (failover && parseInt(response.status) >= 500 || forceFailover) && attempts < this.uris.length)) {
132
131
  _context.next = 24;
133
132
  break;
134
133
  }
@@ -1428,7 +1428,6 @@ exports.CreateNonOwnerCap = /*#__PURE__*/function () {
1428
1428
  * @param {object=} options -
1429
1429
  * meta: New metadata for the object - will be merged into existing metadata if specified
1430
1430
  * type: New type for the object - Object ID, version hash or name of type
1431
- * nodeUrl: Node URL to use in HTTP call
1432
1431
  *
1433
1432
  * @returns {Promise<object>} - Response containing the object ID and write token of the draft, as well as URL of node handling the draft
1434
1433
  */
@@ -1518,28 +1517,26 @@ exports.EditContentObject = /*#__PURE__*/function () {
1518
1517
  _context15.t1 = _context15.sent;
1519
1518
  _context15.t2 = path;
1520
1519
  _context15.t3 = options;
1521
- _context15.t4 = options.nodeUrl;
1522
- _context15.t5 = {
1520
+ _context15.t4 = {
1523
1521
  headers: _context15.t1,
1524
1522
  method: "POST",
1525
1523
  path: _context15.t2,
1526
- body: _context15.t3,
1527
- nodeUrl: _context15.t4
1524
+ body: _context15.t3
1528
1525
  };
1529
- _context15.next = 34;
1530
- return _context15.t0.Request.call(_context15.t0, _context15.t5);
1526
+ _context15.next = 33;
1527
+ return _context15.t0.Request.call(_context15.t0, _context15.t4);
1531
1528
 
1532
- case 34:
1529
+ case 33:
1533
1530
  rawEditResponse = _context15.sent;
1534
1531
  actualUrl = new URL(rawEditResponse.url);
1535
1532
  actualUrl.pathname = "";
1536
1533
  actualUrl.search = "";
1537
1534
  actualUrl.hash = "";
1538
1535
  nodeUrl = actualUrl.href;
1539
- _context15.next = 42;
1536
+ _context15.next = 41;
1540
1537
  return this.utils.ResponseToJson(rawEditResponse);
1541
1538
 
1542
- case 42:
1539
+ case 41:
1543
1540
  editResponse = _context15.sent;
1544
1541
  // Record the node used in creating this write token
1545
1542
  this.HttpClient.RecordWriteToken(editResponse.write_token, nodeUrl);
@@ -1548,7 +1545,7 @@ exports.EditContentObject = /*#__PURE__*/function () {
1548
1545
  editResponse.nodeUrl = nodeUrl;
1549
1546
  return _context15.abrupt("return", editResponse);
1550
1547
 
1551
- case 48:
1548
+ case 47:
1552
1549
  case "end":
1553
1550
  return _context15.stop();
1554
1551
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "Javascript client for the Eluvio Content Fabric",
5
5
  "main": "src/index.js",
6
6
  "author": "Kevin Talmadge",
package/src/ElvClient.js CHANGED
@@ -126,7 +126,8 @@ class ElvClient {
126
126
  *
127
127
  * @namedParams
128
128
  * @param {string} contentSpaceId - ID of the content space
129
- * @param {string} contentSpaceId - ID of the blockchain network
129
+ * @param {string} networkId - ID of the blockchain network
130
+ * @param {string} networkName - Name of the blockchain network
130
131
  * @param {number} fabricVersion - The version of the target content fabric
131
132
  * @param {Array<string>} fabricURIs - A list of full URIs to content fabric nodes
132
133
  * @param {Array<string>} ethereumURIs - A list of full URIs to ethereum nodes
@@ -137,6 +138,9 @@ class ElvClient {
137
138
  * @param {string=} staticToken - Static token that will be used for all authorization in place of normal auth
138
139
  * @param {boolean=} noCache=false - If enabled, blockchain transactions will not be cached
139
140
  * @param {boolean=} noAuth=false - If enabled, blockchain authorization will not be performed
141
+ * @param {boolean=} assumeV3=false - If enabled, V3 fabric will be assumed
142
+ * @param {string=} service=default - The mode that determines how HttpClient will be initialized.
143
+ * If 'default' is set, HttpClient uris will use fabricUris. If 'search' is used, searchUris will be used
140
144
  *
141
145
  * @return {ElvClient} - New ElvClient connected to the specified content fabric and blockchain
142
146
  */
@@ -154,7 +158,8 @@ class ElvClient {
154
158
  staticToken,
155
159
  noCache=false,
156
160
  noAuth=false,
157
- assumeV3=false
161
+ assumeV3=false,
162
+ service="default"
158
163
  }) {
159
164
  this.utils = Utils;
160
165
 
@@ -180,6 +185,12 @@ class ElvClient {
180
185
  this.noAuth = noAuth;
181
186
  this.assumeV3 = assumeV3;
182
187
 
188
+ if(!["search", "default"].includes(this.service)) {
189
+ throw Error(`Invalid service: ${this.service}`);
190
+ }
191
+
192
+ this.service = service;
193
+
183
194
  this.debug = false;
184
195
 
185
196
  this.InitializeClients({staticToken});
@@ -372,7 +383,8 @@ class ElvClient {
372
383
  this.visibilityInfo = {};
373
384
  this.inaccessibleLibraries = {};
374
385
 
375
- this.HttpClient = new HttpClient({uris: this.fabricURIs, debug: this.debug});
386
+ const uris = this.service === "search" ? this.searchURIs : this.fabricURIs;
387
+ this.HttpClient = new HttpClient({uris, debug: this.debug});
376
388
  this.AuthHttpClient = new HttpClient({uris: this.authServiceURIs, debug: this.debug});
377
389
  this.ethClient = new EthClient({client: this, uris: this.ethereumURIs, networkId: this.networkId, debug: this.debug, timeout: this.ethereumContractTimeout});
378
390
 
@@ -422,7 +434,7 @@ class ElvClient {
422
434
  * @param {string} region - Preferred region - the fabric will auto-detect the best region if not specified
423
435
  * - Available regions: as-east au-east eu-east-north eu-west-north na-east-north na-east-south na-west-north na-west-south eu-east-south eu-west-south
424
436
  *
425
- * @return {Promise<Object>} - An object containing the updated fabric and ethereum URLs in order of preference
437
+ * @return {Promise<Object>} - An object containing the updated fabric, ethereum, auth service, and search URLs in order of preference
426
438
  */
427
439
  async UseRegion({region}) {
428
440
  if(!this.configUrl) {
@@ -491,31 +503,33 @@ class ElvClient {
491
503
  }
492
504
 
493
505
  /**
494
- * Retrieve the fabric and ethereum nodes currently used by the client, in preference order
506
+ * Retrieve the fabric, ethereum, auth service, and search nodes currently used by the client, in preference order
495
507
  *
496
508
  * @methodGroup Nodes
497
509
  *
498
- * @return {Promise<Object>} - An object containing the lists of fabric and ethereum urls in use by the client
510
+ * @return {Promise<Object>} - An object containing the lists of fabric, ethereum, auth service, and search urls in use by the client
499
511
  */
500
512
  Nodes() {
501
513
  return {
502
514
  fabricURIs: this.fabricURIs,
503
515
  ethereumURIs: this.ethereumURIs,
504
- authServiceURIs: this.authServiceURIs
516
+ authServiceURIs: this.authServiceURIs,
517
+ searchURIs: this.searchURIs
505
518
  };
506
519
  }
507
520
 
508
521
  /**
509
- * Set the client to use the specified fabric and ethereum nodes, in preference order
522
+ * Set the client to use the specified fabric, ethereum, auth service, and search nodes, in preference order
510
523
  *
511
524
  * @namedParams
512
525
  * @param {Array<string>=} fabricURIs - A list of URLs for the fabric, in preference order
513
526
  * @param {Array<string>=} ethereumURIs - A list of URLs for the blockchain, in preference order
514
527
  * @param {Array<string>=} authServiceURIs - A list of URLs for the auth service, in preference order
528
+ * @param {Array<string>=} searchURIs - A list of URLs for the search nodes, in preference order
515
529
  *
516
530
  * @methodGroup Nodes
517
531
  */
518
- SetNodes({fabricURIs, ethereumURIs, authServiceURIs}) {
532
+ SetNodes({fabricURIs, ethereumURIs, authServiceURIs, searchURIs}) {
519
533
  if(fabricURIs) {
520
534
  this.fabricURIs = fabricURIs;
521
535
 
@@ -535,6 +549,10 @@ class ElvClient {
535
549
  this.AuthHttpClient.uris = authServiceURIs;
536
550
  this.AuthHttpClient.uriIndex = 0;
537
551
  }
552
+
553
+ if(searchURIs) {
554
+ this.searchURIs = searchURIs;
555
+ }
538
556
  }
539
557
 
540
558
  /**
@@ -480,6 +480,6 @@ class FrameClient {
480
480
  }
481
481
 
482
482
  const { UploadFiles } = require("./client/Files");
483
- FrameClient.prototype.UploadFiles=UploadFiles;
483
+ FrameClient.prototype.UploadFiles = UploadFiles;
484
484
 
485
485
  exports.FrameClient = FrameClient;
package/src/HttpClient.js CHANGED
@@ -14,8 +14,8 @@ class HttpClient {
14
14
  this.draftURIs = {};
15
15
  }
16
16
 
17
- BaseURI(url) {
18
- return new URI(url || this.uris[this.uriIndex]);
17
+ BaseURI() {
18
+ return new URI(this.uris[this.uriIndex]);
19
19
  }
20
20
 
21
21
  static Fetch(url, params={}) {
@@ -49,11 +49,9 @@ class HttpClient {
49
49
  headers={},
50
50
  attempts=0,
51
51
  failover=true,
52
- forceFailover=false,
53
- nodeUrl
52
+ forceFailover=false
54
53
  }) {
55
- // if nodeUrl passed in, restrict communication to that node only (unless previously recorded write token is found in next step)
56
- let baseURI = this.BaseURI(nodeUrl);
54
+ let baseURI = this.BaseURI();
57
55
 
58
56
  // If URL contains a write token, it must go to the correct server and can not fail over
59
57
  const writeTokenMatch = path.replace(/^\//, "").match(/(qlibs\/ilib[a-zA-Z0-9]+|q|qid)\/(tqw__[a-zA-Z0-9]+)/);
@@ -107,7 +105,7 @@ class HttpClient {
107
105
 
108
106
  if(!response.ok) {
109
107
  // Fail over if not a write token request, the response was a server error, and we haven't tried all available nodes
110
- if(!writeToken && !nodeUrl && ((failover && parseInt(response.status) >= 500) || forceFailover) && attempts < this.uris.length) {
108
+ if(!writeToken && ((failover && parseInt(response.status) >= 500) || forceFailover) && attempts < this.uris.length) {
111
109
  // Server error - Try next node
112
110
  this.Log(`HttpClient failing over from ${this.BaseURI()}: ${attempts + 1} attempts`, true);
113
111
  this.uriIndex = (this.uriIndex + 1) % this.uris.length;
@@ -749,7 +749,6 @@ exports.CreateNonOwnerCap = async function({objectId, libraryId, publicKey, writ
749
749
  * @param {object=} options -
750
750
  * meta: New metadata for the object - will be merged into existing metadata if specified
751
751
  * type: New type for the object - Object ID, version hash or name of type
752
- * nodeUrl: Node URL to use in HTTP call
753
752
  *
754
753
  * @returns {Promise<object>} - Response containing the object ID and write token of the draft, as well as URL of node handling the draft
755
754
  */
@@ -779,8 +778,7 @@ exports.EditContentObject = async function({libraryId, objectId, options={}}) {
779
778
  headers: await this.authClient.AuthorizationHeader({libraryId, objectId, update: true}),
780
779
  method: "POST",
781
780
  path: path,
782
- body: options,
783
- nodeUrl: options.nodeUrl
781
+ body: options
784
782
  });
785
783
 
786
784
  const actualUrl = new URL(rawEditResponse.url);