@eluvio/elv-client-js 4.0.91 → 4.0.93

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.
@@ -12,11 +12,11 @@ var _require = require("./Validation"),
12
12
  var ContentObjectAudit = {
13
13
  AuditContentObject: function AuditContentObject(_ref) {
14
14
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
15
- var client, libraryId, objectId, versionHash, salt, samples, _ref$live, live, queryParams, uris, httpClient, path, responses, auditHash, verified, audits, _iterator, _step, response, url, audit, res;
15
+ var client, libraryId, objectId, versionHash, salt, samples, _ref$live, live, authorizationToken, queryParams, uris, httpClient, path, responses, auditHash, verified, audits, _iterator, _step, response, url, audit, res;
16
16
  return _regeneratorRuntime.wrap(function _callee$(_context) {
17
17
  while (1) switch (_context.prev = _context.next) {
18
18
  case 0:
19
- client = _ref.client, libraryId = _ref.libraryId, objectId = _ref.objectId, versionHash = _ref.versionHash, salt = _ref.salt, samples = _ref.samples, _ref$live = _ref.live, live = _ref$live === void 0 ? false : _ref$live;
19
+ client = _ref.client, libraryId = _ref.libraryId, objectId = _ref.objectId, versionHash = _ref.versionHash, salt = _ref.salt, samples = _ref.samples, _ref$live = _ref.live, live = _ref$live === void 0 ? false : _ref$live, authorizationToken = _ref.authorizationToken;
20
20
  if (!salt) {
21
21
  salt = client.utils.B64(UUID());
22
22
  }
@@ -73,33 +73,45 @@ var ContentObjectAudit = {
73
73
  });
74
74
  path = UrlJoin("qlibs", libraryId, "q", versionHash || objectId, live ? "call/live/audit" : "audit");
75
75
  _context.t4 = httpClient;
76
- _context.next = 24;
76
+ if (!authorizationToken) {
77
+ _context.next = 26;
78
+ break;
79
+ }
80
+ _context.t5 = {
81
+ Authorization: "Bearer ".concat(authorizationToken)
82
+ };
83
+ _context.next = 29;
84
+ break;
85
+ case 26:
86
+ _context.next = 28;
77
87
  return client.authClient.AuthorizationHeader({
78
88
  libraryId: libraryId,
79
89
  objectId: objectId,
80
90
  versionHash: versionHash
81
91
  });
82
- case 24:
92
+ case 28:
83
93
  _context.t5 = _context.sent;
84
- _context.t6 = queryParams;
85
- _context.t7 = path;
86
- _context.t8 = {
87
- headers: _context.t5,
88
- queryParams: _context.t6,
94
+ case 29:
95
+ _context.t6 = _context.t5;
96
+ _context.t7 = queryParams;
97
+ _context.t8 = path;
98
+ _context.t9 = {
99
+ headers: _context.t6,
100
+ queryParams: _context.t7,
89
101
  method: "GET",
90
- path: _context.t7
102
+ path: _context.t8
91
103
  };
92
- _context.next = 30;
93
- return _context.t4.RequestAll.call(_context.t4, _context.t8);
94
- case 30:
104
+ _context.next = 35;
105
+ return _context.t4.RequestAll.call(_context.t4, _context.t9);
106
+ case 35:
95
107
  responses = _context.sent;
96
108
  audits = [];
97
109
  _iterator = _createForOfIteratorHelper(responses);
98
- _context.prev = 33;
110
+ _context.prev = 38;
99
111
  _iterator.s();
100
- case 35:
112
+ case 40:
101
113
  if ((_step = _iterator.n()).done) {
102
- _context.next = 52;
114
+ _context.next = 57;
103
115
  break;
104
116
  }
105
117
  response = _step.value;
@@ -108,17 +120,17 @@ var ContentObjectAudit = {
108
120
  host: url.hostname
109
121
  };
110
122
  if (response.ok) {
111
- _context.next = 44;
123
+ _context.next = 49;
112
124
  break;
113
125
  }
114
126
  audit.error = response;
115
127
  audit.errorMessage = response.message || JSON.stringify(response);
116
- _context.next = 49;
128
+ _context.next = 54;
117
129
  break;
118
- case 44:
119
- _context.next = 46;
130
+ case 49:
131
+ _context.next = 51;
120
132
  return client.utils.ResponseToJson(response);
121
- case 46:
133
+ case 51:
122
134
  res = _context.sent;
123
135
  if (auditHash === undefined) {
124
136
  auditHash = res.audit_hash;
@@ -128,23 +140,23 @@ var ContentObjectAudit = {
128
140
  verified = true;
129
141
  }
130
142
  audit.audit_hash = res.audit_hash;
131
- case 49:
143
+ case 54:
132
144
  audits.push(audit);
133
- case 50:
134
- _context.next = 35;
135
- break;
136
- case 52:
137
- _context.next = 57;
145
+ case 55:
146
+ _context.next = 40;
138
147
  break;
139
- case 54:
140
- _context.prev = 54;
141
- _context.t9 = _context["catch"](33);
142
- _iterator.e(_context.t9);
143
148
  case 57:
144
- _context.prev = 57;
149
+ _context.next = 62;
150
+ break;
151
+ case 59:
152
+ _context.prev = 59;
153
+ _context.t10 = _context["catch"](38);
154
+ _iterator.e(_context.t10);
155
+ case 62:
156
+ _context.prev = 62;
145
157
  _iterator.f();
146
- return _context.finish(57);
147
- case 60:
158
+ return _context.finish(62);
159
+ case 65:
148
160
  verified = verified || false;
149
161
  return _context.abrupt("return", {
150
162
  verified: verified,
@@ -152,11 +164,11 @@ var ContentObjectAudit = {
152
164
  samples: samples,
153
165
  audits: audits
154
166
  });
155
- case 62:
167
+ case 67:
156
168
  case "end":
157
169
  return _context.stop();
158
170
  }
159
- }, _callee, null, [[33, 54, 57, 60]]);
171
+ }, _callee, null, [[38, 59, 62, 65]]);
160
172
  }))();
161
173
  }
162
174
  };
@@ -4811,16 +4811,17 @@ exports.Collection = /*#__PURE__*/function () {
4811
4811
  * @param {string=} versionHash - Version hash of the object -- if not specified, latest version is returned
4812
4812
  * @param {string=} salt - base64-encoded byte sequence for salting the audit hash
4813
4813
  * @param {Array<number>=} samples - list of percentages (0.0 - <1.0) used for sampling the content part list, up to 3
4814
+ * @param {string=} authorizationToken - Additional authorization token for this request
4814
4815
  *
4815
4816
  * @returns {Promise<Object>} - Response describing audit results
4816
4817
  */
4817
4818
  exports.AuditContentObject = /*#__PURE__*/function () {
4818
4819
  var _ref109 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee59(_ref108) {
4819
- var libraryId, objectId, versionHash, salt, samples;
4820
+ var libraryId, objectId, versionHash, salt, samples, authorizationToken;
4820
4821
  return _regeneratorRuntime.wrap(function _callee59$(_context59) {
4821
4822
  while (1) switch (_context59.prev = _context59.next) {
4822
4823
  case 0:
4823
- libraryId = _ref108.libraryId, objectId = _ref108.objectId, versionHash = _ref108.versionHash, salt = _ref108.salt, samples = _ref108.samples;
4824
+ libraryId = _ref108.libraryId, objectId = _ref108.objectId, versionHash = _ref108.versionHash, salt = _ref108.salt, samples = _ref108.samples, authorizationToken = _ref108.authorizationToken;
4824
4825
  _context59.next = 3;
4825
4826
  return ContentObjectAudit.AuditContentObject({
4826
4827
  client: this,
@@ -4828,7 +4829,8 @@ exports.AuditContentObject = /*#__PURE__*/function () {
4828
4829
  objectId: objectId,
4829
4830
  versionHash: versionHash,
4830
4831
  salt: salt,
4831
- samples: samples
4832
+ samples: samples,
4833
+ authorizationToken: authorizationToken
4832
4834
  });
4833
4835
  case 3:
4834
4836
  return _context59.abrupt("return", _context59.sent);
@@ -1761,14 +1761,14 @@ exports.PublishContentVersion = /*#__PURE__*/function () {
1761
1761
  throw Error("Pending version hash mismatch on ".concat(objectId, ": expected ").concat(objectHash, ", currently ").concat(pendingHash));
1762
1762
  case 19:
1763
1763
  if (!awaitCommitConfirmation) {
1764
- _context21.next = 34;
1764
+ _context21.next = 48;
1765
1765
  break;
1766
1766
  }
1767
1767
  this.Log("Awaiting commit confirmation for ".concat(objectHash));
1768
1768
  pollingInterval = this.ethClient.Provider().pollingInterval || 500; // eslint-disable-next-line no-constant-condition
1769
1769
  case 22:
1770
1770
  if (!true) {
1771
- _context21.next = 34;
1771
+ _context21.next = 48;
1772
1772
  break;
1773
1773
  }
1774
1774
  _context21.next = 25;
@@ -1776,15 +1776,37 @@ exports.PublishContentVersion = /*#__PURE__*/function () {
1776
1776
  return setTimeout(resolve, pollingInterval);
1777
1777
  });
1778
1778
  case 25:
1779
- _context21.next = 27;
1780
- return this.ContractEvents({
1781
- contractAddress: this.utils.HashToAddress(objectId),
1782
- abi: abi,
1783
- fromBlock: fromBlock,
1784
- topics: [Ethers.utils.id("VersionConfirm(address,address,string)")],
1785
- count: 1000
1779
+ _context21.t0 = this;
1780
+ _context21.t1 = this.utils.HashToAddress(objectId);
1781
+ _context21.t2 = abi;
1782
+ _context21.t3 = fromBlock;
1783
+ _context21.next = 31;
1784
+ return this.authClient.IsV3({
1785
+ id: objectId
1786
1786
  });
1787
- case 27:
1787
+ case 31:
1788
+ if (!_context21.sent) {
1789
+ _context21.next = 35;
1790
+ break;
1791
+ }
1792
+ _context21.t4 = Ethers.utils.id("VersionConfirm(address,address,string)");
1793
+ _context21.next = 36;
1794
+ break;
1795
+ case 35:
1796
+ _context21.t4 = Ethers.utils.id("VersionConfirm(address,string)");
1797
+ case 36:
1798
+ _context21.t5 = _context21.t4;
1799
+ _context21.t6 = [_context21.t5];
1800
+ _context21.t7 = {
1801
+ contractAddress: _context21.t1,
1802
+ abi: _context21.t2,
1803
+ fromBlock: _context21.t3,
1804
+ topics: _context21.t6,
1805
+ count: 1000
1806
+ };
1807
+ _context21.next = 41;
1808
+ return _context21.t0.ContractEvents.call(_context21.t0, _context21.t7);
1809
+ case 41:
1788
1810
  events = _context21.sent;
1789
1811
  confirmEvent = events.find(function (blockEvents) {
1790
1812
  return blockEvents.find(function (event) {
@@ -1792,72 +1814,72 @@ exports.PublishContentVersion = /*#__PURE__*/function () {
1792
1814
  });
1793
1815
  });
1794
1816
  if (!confirmEvent) {
1795
- _context21.next = 32;
1817
+ _context21.next = 46;
1796
1818
  break;
1797
1819
  }
1798
1820
  // Found confirmation
1799
1821
  this.Log("Commit confirmed on chain: ".concat(objectHash));
1800
- return _context21.abrupt("break", 34);
1801
- case 32:
1822
+ return _context21.abrupt("break", 48);
1823
+ case 46:
1802
1824
  _context21.next = 22;
1803
1825
  break;
1804
- case 34:
1826
+ case 48:
1805
1827
  if (!awaitCommitConfirmation) {
1806
- _context21.next = 62;
1828
+ _context21.next = 76;
1807
1829
  break;
1808
1830
  }
1809
1831
  _pollingInterval = 500; // ms
1810
1832
  tries = 20;
1811
- case 37:
1833
+ case 51:
1812
1834
  if (!(tries > 0)) {
1813
- _context21.next = 62;
1835
+ _context21.next = 76;
1814
1836
  break;
1815
1837
  }
1816
1838
  h = void 0;
1817
- _context21.prev = 39;
1818
- _context21.next = 42;
1839
+ _context21.prev = 53;
1840
+ _context21.next = 56;
1819
1841
  return this.LatestVersionHashV2({
1820
1842
  objectId: objectId
1821
1843
  });
1822
- case 42:
1844
+ case 56:
1823
1845
  h = _context21.sent;
1824
1846
  if (!(h === versionHash)) {
1825
- _context21.next = 48;
1847
+ _context21.next = 62;
1826
1848
  break;
1827
1849
  }
1828
1850
  this.Log("Commit confirmed on fabric node: ".concat(versionHash));
1829
- return _context21.abrupt("break", 62);
1830
- case 48:
1851
+ return _context21.abrupt("break", 76);
1852
+ case 62:
1831
1853
  tries--;
1832
- _context21.next = 51;
1854
+ _context21.next = 65;
1833
1855
  return new Promise(function (resolve) {
1834
1856
  return setTimeout(resolve, _pollingInterval);
1835
1857
  });
1836
- case 51:
1837
- _context21.next = 60;
1858
+ case 65:
1859
+ _context21.next = 74;
1838
1860
  break;
1839
- case 53:
1840
- _context21.prev = 53;
1841
- _context21.t0 = _context21["catch"](39);
1842
- if (!(_context21.t0.status !== 404)) {
1843
- _context21.next = 57;
1861
+ case 67:
1862
+ _context21.prev = 67;
1863
+ _context21.t8 = _context21["catch"](53);
1864
+ if (!(_context21.t8.status !== 404)) {
1865
+ _context21.next = 71;
1844
1866
  break;
1845
1867
  }
1846
- throw _context21.t0;
1847
- case 57:
1868
+ throw _context21.t8;
1869
+ case 71:
1848
1870
  tries--;
1849
- _context21.next = 60;
1871
+ _context21.next = 74;
1850
1872
  return new Promise(function (resolve) {
1851
1873
  return setTimeout(resolve, _pollingInterval);
1852
1874
  });
1853
- case 60:
1854
- _context21.next = 37;
1875
+ case 74:
1876
+ _context21.next = 51;
1855
1877
  break;
1856
- case 62:
1878
+ case 76:
1857
1879
  case "end":
1858
1880
  return _context21.stop();
1859
1881
  }
1860
- }, _callee21, this, [[39, 53]]);
1882
+ }, _callee21, this, [[53, 67]]);
1861
1883
  }));
1862
1884
  return function (_x20) {
1863
1885
  return _ref38.apply(this, arguments);
@@ -2497,16 +2497,17 @@ exports.StreamAddWatermark = /*#__PURE__*/function () {
2497
2497
  * @param {string=} versionHash - Version hash of the live stream -- if not specified, latest version is returned
2498
2498
  * @param {string=} salt - base64-encoded byte sequence for salting the audit hash
2499
2499
  * @param {Array<number>=} samples - list of percentages (0.0 - <1.0) used for sampling the content part list, up to 3
2500
+ * @param {string=} authorizationToken - Additional authorization token for this request
2500
2501
  *
2501
2502
  * @returns {Promise<Object>} - Response describing audit results
2502
2503
  */
2503
2504
  exports.AuditStream = /*#__PURE__*/function () {
2504
2505
  var _ref33 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref32) {
2505
- var objectId, versionHash, salt, samples;
2506
+ var objectId, versionHash, salt, samples, authorizationToken;
2506
2507
  return _regeneratorRuntime.wrap(function _callee17$(_context17) {
2507
2508
  while (1) switch (_context17.prev = _context17.next) {
2508
2509
  case 0:
2509
- objectId = _ref32.objectId, versionHash = _ref32.versionHash, salt = _ref32.salt, samples = _ref32.samples;
2510
+ objectId = _ref32.objectId, versionHash = _ref32.versionHash, salt = _ref32.salt, samples = _ref32.samples, authorizationToken = _ref32.authorizationToken;
2510
2511
  _context17.next = 3;
2511
2512
  return ContentObjectAudit.AuditContentObject({
2512
2513
  client: this,
@@ -2514,7 +2515,8 @@ exports.AuditStream = /*#__PURE__*/function () {
2514
2515
  versionHash: versionHash,
2515
2516
  salt: salt,
2516
2517
  samples: samples,
2517
- live: true
2518
+ live: true,
2519
+ authorizationToken: authorizationToken
2518
2520
  });
2519
2521
  case 3:
2520
2522
  return _context17.abrupt("return", _context17.sent);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "4.0.91",
3
+ "version": "4.0.93",
4
4
  "description": "Javascript client for the Eluvio Content Fabric",
5
5
  "main": "src/index.js",
6
6
  "author": "Kevin Talmadge",
@@ -5,7 +5,7 @@ const UUID = require("uuid").v4;
5
5
  const {ValidateParameters} = require("./Validation");
6
6
 
7
7
  const ContentObjectAudit = {
8
- async AuditContentObject({client, libraryId, objectId, versionHash, salt, samples, live=false}) {
8
+ async AuditContentObject({client, libraryId, objectId, versionHash, salt, samples, live=false, authorizationToken}) {
9
9
  if(!salt){
10
10
  salt = client.utils.B64(UUID());
11
11
  }
@@ -53,7 +53,9 @@ const ContentObjectAudit = {
53
53
 
54
54
  let path = UrlJoin("qlibs", libraryId, "q", versionHash || objectId, live ? "call/live/audit" : "audit");
55
55
  let responses = await httpClient.RequestAll({
56
- headers: await client.authClient.AuthorizationHeader({libraryId, objectId, versionHash}),
56
+ headers: authorizationToken ?
57
+ { Authorization: `Bearer ${authorizationToken}`} :
58
+ await client.authClient.AuthorizationHeader({libraryId, objectId, versionHash}),
57
59
  queryParams: queryParams,
58
60
  method: "GET",
59
61
  path
@@ -3056,17 +3056,19 @@ exports.Collection = async function({collectionType}) {
3056
3056
  * @param {string=} versionHash - Version hash of the object -- if not specified, latest version is returned
3057
3057
  * @param {string=} salt - base64-encoded byte sequence for salting the audit hash
3058
3058
  * @param {Array<number>=} samples - list of percentages (0.0 - <1.0) used for sampling the content part list, up to 3
3059
+ * @param {string=} authorizationToken - Additional authorization token for this request
3059
3060
  *
3060
3061
  * @returns {Promise<Object>} - Response describing audit results
3061
3062
  */
3062
- exports.AuditContentObject = async function({libraryId, objectId, versionHash, salt, samples}) {
3063
+ exports.AuditContentObject = async function({libraryId, objectId, versionHash, salt, samples, authorizationToken}) {
3063
3064
  return await ContentObjectAudit.AuditContentObject({
3064
3065
  client: this,
3065
3066
  libraryId,
3066
3067
  objectId,
3067
3068
  versionHash,
3068
3069
  salt,
3069
- samples
3070
+ samples,
3071
+ authorizationToken
3070
3072
  });
3071
3073
  };
3072
3074
 
@@ -1050,7 +1050,11 @@ exports.PublishContentVersion = async function({objectId, versionHash, awaitComm
1050
1050
  contractAddress: this.utils.HashToAddress(objectId),
1051
1051
  abi,
1052
1052
  fromBlock,
1053
- topics: [ Ethers.utils.id("VersionConfirm(address,address,string)") ],
1053
+ topics: [
1054
+ await this.authClient.IsV3({id: objectId}) ?
1055
+ Ethers.utils.id("VersionConfirm(address,address,string)") :
1056
+ Ethers.utils.id("VersionConfirm(address,string)")
1057
+ ],
1054
1058
  count: 1000
1055
1059
  });
1056
1060
 
@@ -1955,16 +1955,18 @@ exports.StreamAddWatermark = async function({
1955
1955
  * @param {string=} versionHash - Version hash of the live stream -- if not specified, latest version is returned
1956
1956
  * @param {string=} salt - base64-encoded byte sequence for salting the audit hash
1957
1957
  * @param {Array<number>=} samples - list of percentages (0.0 - <1.0) used for sampling the content part list, up to 3
1958
+ * @param {string=} authorizationToken - Additional authorization token for this request
1958
1959
  *
1959
1960
  * @returns {Promise<Object>} - Response describing audit results
1960
1961
  */
1961
- exports.AuditStream = async function({objectId, versionHash, salt, samples}) {
1962
+ exports.AuditStream = async function({objectId, versionHash, salt, samples, authorizationToken}) {
1962
1963
  return await ContentObjectAudit.AuditContentObject({
1963
1964
  client: this,
1964
1965
  objectId,
1965
1966
  versionHash,
1966
1967
  salt,
1967
1968
  samples,
1968
- live: true
1969
+ live: true,
1970
+ authorizationToken
1969
1971
  });
1970
1972
  };