@eluvio/elv-client-js 4.0.9 → 4.0.11

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.
@@ -152,13 +152,13 @@ var AuthorizationClient = /*#__PURE__*/function () {
152
152
  key: "AuthorizationToken",
153
153
  value: function () {
154
154
  var _AuthorizationToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
155
- var libraryId, objectId, versionHash, partHash, encryption, audienceData, context, _ref3$update, update, _ref3$channelAuth, channelAuth, oauthToken, _ref3$noCache, noCache, _ref3$noAuth, noAuth, isWalletRequest, initialNoCache, authorizationToken;
155
+ var libraryId, objectId, versionHash, partHash, encryption, audienceData, context, _ref3$update, update, _ref3$makeAccessReque, makeAccessRequest, _ref3$channelAuth, channelAuth, oauthToken, _ref3$noCache, noCache, _ref3$noAuth, noAuth, isWalletRequest, initialNoCache, authorizationToken;
156
156
 
157
157
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
158
158
  while (1) {
159
159
  switch (_context2.prev = _context2.next) {
160
160
  case 0:
161
- libraryId = _ref3.libraryId, objectId = _ref3.objectId, versionHash = _ref3.versionHash, partHash = _ref3.partHash, encryption = _ref3.encryption, audienceData = _ref3.audienceData, context = _ref3.context, _ref3$update = _ref3.update, update = _ref3$update === void 0 ? false : _ref3$update, _ref3$channelAuth = _ref3.channelAuth, channelAuth = _ref3$channelAuth === void 0 ? false : _ref3$channelAuth, oauthToken = _ref3.oauthToken, _ref3$noCache = _ref3.noCache, noCache = _ref3$noCache === void 0 ? false : _ref3$noCache, _ref3$noAuth = _ref3.noAuth, noAuth = _ref3$noAuth === void 0 ? false : _ref3$noAuth;
161
+ libraryId = _ref3.libraryId, objectId = _ref3.objectId, versionHash = _ref3.versionHash, partHash = _ref3.partHash, encryption = _ref3.encryption, audienceData = _ref3.audienceData, context = _ref3.context, _ref3$update = _ref3.update, update = _ref3$update === void 0 ? false : _ref3$update, _ref3$makeAccessReque = _ref3.makeAccessRequest, makeAccessRequest = _ref3$makeAccessReque === void 0 ? false : _ref3$makeAccessReque, _ref3$channelAuth = _ref3.channelAuth, channelAuth = _ref3$channelAuth === void 0 ? false : _ref3$channelAuth, oauthToken = _ref3.oauthToken, _ref3$noCache = _ref3.noCache, noCache = _ref3$noCache === void 0 ? false : _ref3$noCache, _ref3$noAuth = _ref3.noAuth, noAuth = _ref3$noAuth === void 0 ? false : _ref3$noAuth;
162
162
 
163
163
  if (versionHash) {
164
164
  objectId = this.client.utils.DecodeVersionHash(versionHash).objectId;
@@ -243,7 +243,7 @@ var AuthorizationClient = /*#__PURE__*/function () {
243
243
  partHash: partHash,
244
244
  encryption: encryption,
245
245
  update: update,
246
- noAuth: noAuth
246
+ makeAccessRequest: makeAccessRequest
247
247
  });
248
248
 
249
249
  case 27:
@@ -280,13 +280,13 @@ var AuthorizationClient = /*#__PURE__*/function () {
280
280
  key: "GenerateAuthorizationToken",
281
281
  value: function () {
282
282
  var _GenerateAuthorizationToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref4) {
283
- var libraryId, objectId, versionHash, partHash, encryption, _ref4$update, update, _ref4$noAuth, noAuth, publicKey, owner, ownerCapKey, ownerCap, cap, token, _yield$this$MakeAcces, transactionHash, signature, multiSig;
283
+ var libraryId, objectId, versionHash, partHash, encryption, _ref4$update, update, _ref4$makeAccessReque, makeAccessRequest, publicKey, owner, ownerCapKey, ownerCap, cap, token, _yield$this$MakeAcces, transactionHash, signature, multiSig;
284
284
 
285
285
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
286
286
  while (1) {
287
287
  switch (_context3.prev = _context3.next) {
288
288
  case 0:
289
- libraryId = _ref4.libraryId, objectId = _ref4.objectId, versionHash = _ref4.versionHash, partHash = _ref4.partHash, encryption = _ref4.encryption, _ref4$update = _ref4.update, update = _ref4$update === void 0 ? false : _ref4$update, _ref4$noAuth = _ref4.noAuth, noAuth = _ref4$noAuth === void 0 ? false : _ref4$noAuth;
289
+ libraryId = _ref4.libraryId, objectId = _ref4.objectId, versionHash = _ref4.versionHash, partHash = _ref4.partHash, encryption = _ref4.encryption, _ref4$update = _ref4.update, update = _ref4$update === void 0 ? false : _ref4$update, _ref4$makeAccessReque = _ref4.makeAccessRequest, makeAccessRequest = _ref4$makeAccessReque === void 0 ? false : _ref4$makeAccessReque;
290
290
 
291
291
  if (versionHash) {
292
292
  objectId = Utils.DecodeVersionHash(versionHash).objectId;
@@ -353,7 +353,7 @@ var AuthorizationClient = /*#__PURE__*/function () {
353
353
  addr: Utils.FormatAddress(this.client.signer && this.client.signer.address || "")
354
354
  };
355
355
 
356
- if (!update) {
356
+ if (!(update || makeAccessRequest)) {
357
357
  _context3.next = 29;
358
358
  break;
359
359
  }
@@ -365,8 +365,7 @@ var AuthorizationClient = /*#__PURE__*/function () {
365
365
  versionHash: versionHash,
366
366
  update: update,
367
367
  publicKey: publicKey,
368
- noCache: this.noCache,
369
- noAuth: this.noAuth || noAuth
368
+ noCache: this.noCache
370
369
  });
371
370
 
372
371
  case 26:
@@ -343,7 +343,7 @@ exports.SetPermission = /*#__PURE__*/function () {
343
343
 
344
344
  exports.CreateContentType = /*#__PURE__*/function () {
345
345
  var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref6) {
346
- var name, _ref6$metadata, metadata, bitcode, _yield$this$authClien, contractAddress, objectId, path, createResponse, uploadResponse;
346
+ var name, _ref6$metadata, metadata, bitcode, _yield$this$authClien, contractAddress, objectId, path, rawCreateResponse, nodeUrl, createResponse, uploadResponse;
347
347
 
348
348
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
349
349
  while (1) {
@@ -373,32 +373,36 @@ exports.CreateContentType = /*#__PURE__*/function () {
373
373
  this.Log("Created type: ".concat(contractAddress, " ").concat(objectId));
374
374
  /* Create object, upload bitcode and finalize */
375
375
 
376
- _context4.t0 = this.utils;
377
- _context4.t1 = this.HttpClient;
378
- _context4.next = 17;
376
+ _context4.t0 = this.HttpClient;
377
+ _context4.next = 16;
379
378
  return this.authClient.AuthorizationHeader({
380
379
  libraryId: this.contentSpaceLibraryId,
381
380
  objectId: objectId,
382
381
  update: true
383
382
  });
384
383
 
385
- case 17:
386
- _context4.t2 = _context4.sent;
387
- _context4.t3 = path;
388
- _context4.t4 = {
389
- headers: _context4.t2,
384
+ case 16:
385
+ _context4.t1 = _context4.sent;
386
+ _context4.t2 = path;
387
+ _context4.t3 = {
388
+ headers: _context4.t1,
390
389
  method: "POST",
391
- path: _context4.t3
390
+ path: _context4.t2
392
391
  };
393
- _context4.t5 = _context4.t1.Request.call(_context4.t1, _context4.t4);
394
- _context4.next = 23;
395
- return _context4.t0.ResponseToJson.call(_context4.t0, _context4.t5);
392
+ _context4.next = 21;
393
+ return _context4.t0.Request.call(_context4.t0, _context4.t3);
396
394
 
397
- case 23:
395
+ case 21:
396
+ rawCreateResponse = _context4.sent;
397
+ nodeUrl = new URL(rawCreateResponse.url).origin;
398
+ _context4.next = 25;
399
+ return this.utils.ResponseToJson(rawCreateResponse);
400
+
401
+ case 25:
398
402
  createResponse = _context4.sent;
399
403
  // Record the node used in creating this write token
400
- this.HttpClient.RecordWriteToken(createResponse.write_token);
401
- _context4.next = 27;
404
+ this.HttpClient.RecordWriteToken(createResponse.write_token, nodeUrl);
405
+ _context4.next = 29;
402
406
  return this.ReplaceMetadata({
403
407
  libraryId: this.contentSpaceLibraryId,
404
408
  objectId: objectId,
@@ -406,13 +410,13 @@ exports.CreateContentType = /*#__PURE__*/function () {
406
410
  metadata: metadata
407
411
  });
408
412
 
409
- case 27:
413
+ case 29:
410
414
  if (!bitcode) {
411
- _context4.next = 33;
415
+ _context4.next = 35;
412
416
  break;
413
417
  }
414
418
 
415
- _context4.next = 30;
419
+ _context4.next = 32;
416
420
  return this.UploadPart({
417
421
  libraryId: this.contentSpaceLibraryId,
418
422
  objectId: objectId,
@@ -421,9 +425,9 @@ exports.CreateContentType = /*#__PURE__*/function () {
421
425
  encrypted: false
422
426
  });
423
427
 
424
- case 30:
428
+ case 32:
425
429
  uploadResponse = _context4.sent;
426
- _context4.next = 33;
430
+ _context4.next = 35;
427
431
  return this.ReplaceMetadata({
428
432
  libraryId: this.contentSpaceLibraryId,
429
433
  objectId: objectId,
@@ -432,8 +436,8 @@ exports.CreateContentType = /*#__PURE__*/function () {
432
436
  metadata: uploadResponse.part.hash
433
437
  });
434
438
 
435
- case 33:
436
- _context4.next = 35;
439
+ case 35:
440
+ _context4.next = 37;
437
441
  return this.FinalizeContentObject({
438
442
  libraryId: this.contentSpaceLibraryId,
439
443
  objectId: objectId,
@@ -441,10 +445,10 @@ exports.CreateContentType = /*#__PURE__*/function () {
441
445
  commitMessage: "Create content type"
442
446
  });
443
447
 
444
- case 35:
448
+ case 37:
445
449
  return _context4.abrupt("return", objectId);
446
450
 
447
- case 36:
451
+ case 38:
448
452
  case "end":
449
453
  return _context4.stop();
450
454
  }
@@ -960,7 +964,7 @@ exports.RemoveLibraryContentType = /*#__PURE__*/function () {
960
964
 
961
965
  exports.CreateContentObject = /*#__PURE__*/function () {
962
966
  var _ref21 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(_ref20) {
963
- var libraryId, objectId, _ref20$options, options, typeId, type, currentAccountAddress, canContribute, _yield$this$authClien3, contractAddress, path, createResponse;
967
+ var libraryId, objectId, _ref20$options, options, typeId, type, currentAccountAddress, canContribute, _yield$this$authClien3, contractAddress, path, rawCreateResponse, nodeUrl, createResponse;
964
968
 
965
969
  return _regeneratorRuntime.wrap(function _callee11$(_context11) {
966
970
  while (1) {
@@ -1108,38 +1112,43 @@ exports.CreateContentObject = /*#__PURE__*/function () {
1108
1112
 
1109
1113
  case 55:
1110
1114
  path = UrlJoin("qid", objectId);
1111
- _context11.t4 = this.utils;
1112
- _context11.t5 = this.HttpClient;
1113
- _context11.next = 60;
1115
+ _context11.t4 = this.HttpClient;
1116
+ _context11.next = 59;
1114
1117
  return this.authClient.AuthorizationHeader({
1115
1118
  libraryId: libraryId,
1116
1119
  objectId: objectId,
1117
1120
  update: true
1118
1121
  });
1119
1122
 
1120
- case 60:
1121
- _context11.t6 = _context11.sent;
1122
- _context11.t7 = path;
1123
- _context11.t8 = options;
1124
- _context11.t9 = {
1125
- headers: _context11.t6,
1123
+ case 59:
1124
+ _context11.t5 = _context11.sent;
1125
+ _context11.t6 = path;
1126
+ _context11.t7 = options;
1127
+ _context11.t8 = {
1128
+ headers: _context11.t5,
1126
1129
  method: "POST",
1127
- path: _context11.t7,
1128
- body: _context11.t8
1130
+ path: _context11.t6,
1131
+ body: _context11.t7
1129
1132
  };
1130
- _context11.t10 = _context11.t5.Request.call(_context11.t5, _context11.t9);
1131
- _context11.next = 67;
1132
- return _context11.t4.ResponseToJson.call(_context11.t4, _context11.t10);
1133
+ _context11.next = 65;
1134
+ return _context11.t4.Request.call(_context11.t4, _context11.t8);
1135
+
1136
+ case 65:
1137
+ rawCreateResponse = _context11.sent;
1138
+ nodeUrl = new URL(rawCreateResponse.url).origin;
1139
+ _context11.next = 69;
1140
+ return this.utils.ResponseToJson(rawCreateResponse);
1133
1141
 
1134
- case 67:
1142
+ case 69:
1135
1143
  createResponse = _context11.sent;
1136
1144
  // Record the node used in creating this write token
1137
- this.HttpClient.RecordWriteToken(createResponse.write_token);
1145
+ this.HttpClient.RecordWriteToken(createResponse.write_token, nodeUrl);
1138
1146
  createResponse.writeToken = createResponse.write_token;
1139
1147
  createResponse.objectId = createResponse.id;
1148
+ createResponse.nodeUrl = nodeUrl;
1140
1149
  return _context11.abrupt("return", createResponse);
1141
1150
 
1142
- case 72:
1151
+ case 75:
1143
1152
  case "end":
1144
1153
  return _context11.stop();
1145
1154
  }
@@ -1435,7 +1444,7 @@ exports.CreateNonOwnerCap = /*#__PURE__*/function () {
1435
1444
 
1436
1445
  exports.EditContentObject = /*#__PURE__*/function () {
1437
1446
  var _ref28 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(_ref27) {
1438
- var libraryId, objectId, _ref27$options, options, path, rawEditResponse, actualUrl, nodeUrl, editResponse;
1447
+ var libraryId, objectId, _ref27$options, options, path, rawEditResponse, nodeUrl, editResponse;
1439
1448
 
1440
1449
  return _regeneratorRuntime.wrap(function _callee15$(_context15) {
1441
1450
  while (1) {
@@ -1528,15 +1537,11 @@ exports.EditContentObject = /*#__PURE__*/function () {
1528
1537
 
1529
1538
  case 33:
1530
1539
  rawEditResponse = _context15.sent;
1531
- actualUrl = new URL(rawEditResponse.url);
1532
- actualUrl.pathname = "";
1533
- actualUrl.search = "";
1534
- actualUrl.hash = "";
1535
- nodeUrl = actualUrl.href;
1536
- _context15.next = 41;
1540
+ nodeUrl = new URL(rawEditResponse.url).origin;
1541
+ _context15.next = 37;
1537
1542
  return this.utils.ResponseToJson(rawEditResponse);
1538
1543
 
1539
- case 41:
1544
+ case 37:
1540
1545
  editResponse = _context15.sent;
1541
1546
  // Record the node used in creating this write token
1542
1547
  this.HttpClient.RecordWriteToken(editResponse.write_token, nodeUrl);
@@ -1545,7 +1550,7 @@ exports.EditContentObject = /*#__PURE__*/function () {
1545
1550
  editResponse.nodeUrl = nodeUrl;
1546
1551
  return _context15.abrupt("return", editResponse);
1547
1552
 
1548
- case 47:
1553
+ case 43:
1549
1554
  case "end":
1550
1555
  return _context15.stop();
1551
1556
  }
@@ -1560,7 +1560,8 @@ exports.DownloadPart = /*#__PURE__*/function () {
1560
1560
  libraryId: libraryId,
1561
1561
  objectId: objectId,
1562
1562
  versionHash: versionHash,
1563
- encryption: encryption
1563
+ encryption: encryption,
1564
+ makeAccessRequest: true
1564
1565
  });
1565
1566
 
1566
1567
  case 9:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "4.0.9",
3
+ "version": "4.0.11",
4
4
  "description": "Javascript client for the Eluvio Content Fabric",
5
5
  "main": "src/index.js",
6
6
  "author": "Kevin Talmadge",
@@ -116,6 +116,7 @@ class AuthorizationClient {
116
116
  audienceData,
117
117
  context,
118
118
  update=false,
119
+ makeAccessRequest=false,
119
120
  channelAuth=false,
120
121
  oauthToken,
121
122
  noCache=false,
@@ -171,7 +172,7 @@ class AuthorizationClient {
171
172
  partHash,
172
173
  encryption,
173
174
  update,
174
- noAuth
175
+ makeAccessRequest
175
176
  });
176
177
  }
177
178
 
@@ -183,7 +184,7 @@ class AuthorizationClient {
183
184
  }
184
185
  }
185
186
 
186
- async GenerateAuthorizationToken({libraryId, objectId, versionHash, partHash, encryption, update=false, noAuth=false}) {
187
+ async GenerateAuthorizationToken({libraryId, objectId, versionHash, partHash, encryption, update=false, makeAccessRequest=false}) {
187
188
  if(versionHash) { objectId = Utils.DecodeVersionHash(versionHash).objectId; }
188
189
 
189
190
  // Generate AFGH public key if encryption is specified
@@ -204,15 +205,14 @@ class AuthorizationClient {
204
205
  addr: Utils.FormatAddress(((this.client.signer && this.client.signer.address) || ""))
205
206
  };
206
207
 
207
- if(update) {
208
+ if(update || makeAccessRequest) {
208
209
  const { transactionHash } = await this.MakeAccessRequest({
209
210
  libraryId,
210
211
  objectId,
211
212
  versionHash,
212
213
  update,
213
214
  publicKey,
214
- noCache: this.noCache,
215
- noAuth: this.noAuth || noAuth
215
+ noCache: this.noCache
216
216
  });
217
217
 
218
218
  if(transactionHash) {
@@ -174,20 +174,20 @@ exports.CreateContentType = async function({name, metadata={}, bitcode}) {
174
174
  this.Log(`Created type: ${contractAddress} ${objectId}`);
175
175
 
176
176
  /* Create object, upload bitcode and finalize */
177
- const createResponse = await this.utils.ResponseToJson(
178
- this.HttpClient.Request({
179
- headers: await this.authClient.AuthorizationHeader({
180
- libraryId: this.contentSpaceLibraryId,
181
- objectId,
182
- update: true
183
- }),
184
- method: "POST",
185
- path: path
186
- })
187
- );
177
+ const rawCreateResponse = await this.HttpClient.Request({
178
+ headers: await this.authClient.AuthorizationHeader({
179
+ libraryId: this.contentSpaceLibraryId,
180
+ objectId,
181
+ update: true
182
+ }),
183
+ method: "POST",
184
+ path: path
185
+ });
186
+ const nodeUrl = (new URL(rawCreateResponse.url)).origin;
187
+ const createResponse = await this.utils.ResponseToJson(rawCreateResponse);
188
188
 
189
189
  // Record the node used in creating this write token
190
- this.HttpClient.RecordWriteToken(createResponse.write_token);
190
+ this.HttpClient.RecordWriteToken(createResponse.write_token, nodeUrl);
191
191
 
192
192
  await this.ReplaceMetadata({
193
193
  libraryId: this.contentSpaceLibraryId,
@@ -605,20 +605,21 @@ exports.CreateContentObject = async function({libraryId, objectId, options={}})
605
605
 
606
606
  const path = UrlJoin("qid", objectId);
607
607
 
608
- let createResponse = await this.utils.ResponseToJson(
609
- this.HttpClient.Request({
610
- headers: await this.authClient.AuthorizationHeader({libraryId, objectId, update: true}),
611
- method: "POST",
612
- path: path,
613
- body: options
614
- })
615
- );
608
+ const rawCreateResponse = await this.HttpClient.Request({
609
+ headers: await this.authClient.AuthorizationHeader({libraryId, objectId, update: true}),
610
+ method: "POST",
611
+ path: path,
612
+ body: options
613
+ });
614
+ const nodeUrl = (new URL(rawCreateResponse.url)).origin;
615
+ const createResponse = await this.utils.ResponseToJson(rawCreateResponse);
616
616
 
617
617
  // Record the node used in creating this write token
618
- this.HttpClient.RecordWriteToken(createResponse.write_token);
618
+ this.HttpClient.RecordWriteToken(createResponse.write_token, nodeUrl);
619
619
 
620
620
  createResponse.writeToken = createResponse.write_token;
621
621
  createResponse.objectId = createResponse.id;
622
+ createResponse.nodeUrl = nodeUrl;
622
623
 
623
624
  return createResponse;
624
625
  };
@@ -780,14 +781,8 @@ exports.EditContentObject = async function({libraryId, objectId, options={}}) {
780
781
  path: path,
781
782
  body: options
782
783
  });
783
-
784
- const actualUrl = new URL(rawEditResponse.url);
785
- actualUrl.pathname = "";
786
- actualUrl.search = "";
787
- actualUrl.hash = "";
788
- const nodeUrl = actualUrl.href;
789
-
790
- let editResponse = await this.utils.ResponseToJson(rawEditResponse);
784
+ const nodeUrl = (new URL(rawEditResponse.url)).origin;
785
+ const editResponse = await this.utils.ResponseToJson(rawEditResponse);
791
786
 
792
787
  // Record the node used in creating this write token
793
788
  this.HttpClient.RecordWriteToken(editResponse.write_token, nodeUrl);
@@ -809,7 +809,7 @@ exports.DownloadPart = async function({
809
809
  const encryption = encrypted ? "cgck" : undefined;
810
810
  const path = UrlJoin("q", writeToken || versionHash || objectId, "data", partHash);
811
811
 
812
- let headers = await this.authClient.AuthorizationHeader({libraryId, objectId, versionHash, encryption});
812
+ let headers = await this.authClient.AuthorizationHeader({libraryId, objectId, versionHash, encryption, makeAccessRequest: true});
813
813
 
814
814
  const bytesTotal = (await this.ContentPart({libraryId, objectId, versionHash, partHash})).part.size;
815
815
 
@@ -0,0 +1,34 @@
1
+ // List all access gropus visible to the current private key
2
+
3
+ const Utility = require("./lib/Utility");
4
+
5
+ const Client = require("./lib/concerns/Client");
6
+ const Logger = require("./lib/concerns/Logger");
7
+
8
+ class ListAccessGroups extends Utility {
9
+ blueprint() {
10
+ return {
11
+ concerns: [Logger, Client]
12
+ };
13
+ }
14
+
15
+ async body() {
16
+ const logger = this.logger;
17
+ const libList = await this.concerns.Library.list();
18
+ logger.data("libraries", libList);
19
+
20
+ logger.logList(libList);
21
+ if(libList.length === 0) logger.warn("No visible libraries found using supplied private key.");
22
+ }
23
+
24
+ header() {
25
+ return "Get list of access groups";
26
+ }
27
+
28
+ }
29
+
30
+ if(require.main === module) {
31
+ Utility.cmdLineInvoke(ListAccessGroups);
32
+ } else {
33
+ module.exports = ListAccessGroups;
34
+ }