@eluvio/elv-client-js 4.0.88 → 4.0.90

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.
Files changed (58) hide show
  1. package/dist/ElvClient-min.js +15 -14
  2. package/dist/ElvClient-node-min.js +14 -13
  3. package/dist/ElvFrameClient-min.js +10 -10
  4. package/dist/ElvPermissionsClient-min.js +9 -9
  5. package/dist/ElvWalletClient-min.js +15 -14
  6. package/dist/ElvWalletClient-node-min.js +14 -13
  7. package/dist/src/AuthorizationClient.js +9 -12
  8. package/dist/src/ContentObjectAudit.js +3 -3
  9. package/dist/src/ContentObjectVerification.js +3 -3
  10. package/dist/src/Crypto.js +2 -2
  11. package/dist/src/ElvClient.js +47 -28
  12. package/dist/src/ElvWallet.js +7 -5
  13. package/dist/src/EthClient.js +8 -9
  14. package/dist/src/FrameClient.js +8 -9
  15. package/dist/src/HttpClient.js +27 -4
  16. package/dist/src/Id.js +1 -2
  17. package/dist/src/PermissionsClient.js +31 -19
  18. package/dist/src/RemoteSigner.js +6 -8
  19. package/dist/src/UserProfileClient.js +35 -19
  20. package/dist/src/Utils.js +62 -28
  21. package/dist/src/client/ABRPublishing.js +2 -2
  22. package/dist/src/client/AccessGroups.js +2 -2
  23. package/dist/src/client/ContentAccess.js +104 -104
  24. package/dist/src/client/ContentManagement.js +25 -23
  25. package/dist/src/client/Contracts.js +2 -2
  26. package/dist/src/client/Files.js +77 -88
  27. package/dist/src/client/LiveConf.js +3 -7
  28. package/dist/src/client/LiveStream.js +35 -36
  29. package/dist/src/client/NFT.js +2 -2
  30. package/dist/src/walletClient/ClientMethods.js +2 -2
  31. package/dist/src/walletClient/Profile.js +2 -2
  32. package/dist/src/walletClient/Utils.js +2 -2
  33. package/dist/src/walletClient/index.js +17 -14
  34. package/package.json +1 -1
  35. package/src/HttpClient.js +16 -2
  36. package/src/Utils.js +27 -5
  37. package/src/client/ContentAccess.js +85 -93
  38. package/src/client/ContentManagement.js +25 -11
  39. package/src/client/Files.js +43 -51
  40. package/src/client/LiveConf.js +0 -2
  41. package/src/client/LiveStream.js +7 -3
  42. package/testScripts/OfferingEnsureStrongDrm.js +2 -2
  43. package/testScripts/Test.js +3 -0
  44. package/testScripts/abr_profile_4k_both.json +18 -0
  45. package/testScripts/abr_profile_4k_drm.json +9 -0
  46. package/testScripts/abr_profile_4k_drm_public_access.json +18 -0
  47. package/testScripts/abr_profile_both.json +18 -0
  48. package/testScripts/abr_profile_drm.json +9 -0
  49. package/testScripts/abr_profile_drm_public_access.json +18 -0
  50. package/utilities/example_files/abr_profile_4k_both.json +18 -0
  51. package/utilities/example_files/abr_profile_4k_drm.json +9 -0
  52. package/utilities/example_files/abr_profile_4k_drm_public_access.json +18 -0
  53. package/utilities/example_files/abr_profile_4k_drm_strict.json +9 -0
  54. package/utilities/example_files/abr_profile_both.json +18 -0
  55. package/utilities/example_files/abr_profile_drm.json +9 -0
  56. package/utilities/example_files/abr_profile_drm_hls_only.json +9 -0
  57. package/utilities/example_files/abr_profile_drm_public_access.json +18 -0
  58. package/utilities/example_files/simple_ingest_library_metadata.json +9 -0
@@ -1,8 +1,8 @@
1
1
  var _regeneratorRuntime = require("@babel/runtime/regenerator");
2
2
  var _defineProperty = require("@babel/runtime/helpers/defineProperty");
3
3
  var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
4
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
6
  /**
7
7
  * Methods for creating and managing NFTs
8
8
  *
@@ -1,8 +1,8 @@
1
1
  var _defineProperty = require("@babel/runtime/helpers/defineProperty");
2
2
  var _regeneratorRuntime = require("@babel/runtime/regenerator");
3
3
  var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
4
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
6
  var Utils = require("../Utils");
7
7
  var UrlJoin = require("url-join");
8
8
  var _require = require("./Utils"),
@@ -2,8 +2,8 @@ var _defineProperty = require("@babel/runtime/helpers/defineProperty");
2
2
  var _typeof = require("@babel/runtime/helpers/typeof");
3
3
  var _regeneratorRuntime = require("@babel/runtime/regenerator");
4
4
  var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
5
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
7
  var Utils = require("../Utils");
8
8
  var UrlJoin = require("url-join");
9
9
  var StateStorePath = function StateStorePath(_ref) {
@@ -2,8 +2,8 @@ var _regeneratorRuntime = require("@babel/runtime/regenerator");
2
2
  var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
3
3
  var _defineProperty = require("@babel/runtime/helpers/defineProperty");
4
4
  var _slicedToArray = require("@babel/runtime/helpers/slicedToArray");
5
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
7
  var Utils = require("../Utils");
8
8
  var RarityToPercentage = function RarityToPercentage(rarity) {
9
9
  if (!rarity) {
@@ -5,8 +5,8 @@ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
6
6
  var _classCallCheck = require("@babel/runtime/helpers/classCallCheck");
7
7
  var _createClass = require("@babel/runtime/helpers/createClass");
8
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
9
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
10
  var _require = require("../ElvClient"),
11
11
  ElvClient = _require.ElvClient;
12
12
  var Configuration = require("./Configuration");
@@ -77,7 +77,7 @@ var ElvWalletClient = /*#__PURE__*/function () {
77
77
  this.utils = client.utils;
78
78
  this.ForbiddenMethods = ElvWalletClient.ForbiddenMethods;
79
79
  }
80
- _createClass(ElvWalletClient, [{
80
+ return _createClass(ElvWalletClient, [{
81
81
  key: "Log",
82
82
  value: function Log(message) {
83
83
  var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -134,7 +134,7 @@ var ElvWalletClient = /*#__PURE__*/function () {
134
134
  */
135
135
  }, {
136
136
  key: "PersonalSign",
137
- value: function () {
137
+ value: (function () {
138
138
  var _PersonalSign = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref2) {
139
139
  var message, parameters, url;
140
140
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
@@ -263,7 +263,7 @@ var ElvWalletClient = /*#__PURE__*/function () {
263
263
  return _PersonalSign.apply(this, arguments);
264
264
  }
265
265
  return PersonalSign;
266
- }()
266
+ }())
267
267
  }, {
268
268
  key: "LogInURL",
269
269
  value: function () {
@@ -342,7 +342,7 @@ var ElvWalletClient = /*#__PURE__*/function () {
342
342
  */
343
343
  }, {
344
344
  key: "LogIn",
345
- value: function () {
345
+ value: (function () {
346
346
  var _LogIn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref5) {
347
347
  var _this = this;
348
348
  var _ref5$method, method, provider, _ref5$mode, mode, callbackUrl, marketplaceParams, _ref5$clearLogin, clearLogin, callback, loginUrl;
@@ -461,9 +461,10 @@ var ElvWalletClient = /*#__PURE__*/function () {
461
461
  *
462
462
  * @methodGroup Login
463
463
  */
464
+ )
464
465
  }, {
465
466
  key: "LogOut",
466
- value: function () {
467
+ value: (function () {
467
468
  var _LogOut = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
468
469
  return _regeneratorRuntime.wrap(function _callee8$(_context8) {
469
470
  while (1) switch (_context8.prev = _context8.next) {
@@ -506,7 +507,7 @@ var ElvWalletClient = /*#__PURE__*/function () {
506
507
  return _LogOut.apply(this, arguments);
507
508
  }
508
509
  return LogOut;
509
- }()
510
+ }())
510
511
  }, {
511
512
  key: "TokenStatus",
512
513
  value: function () {
@@ -546,7 +547,7 @@ var ElvWalletClient = /*#__PURE__*/function () {
546
547
  */
547
548
  }, {
548
549
  key: "Authenticate",
549
- value: function () {
550
+ value: (function () {
550
551
  var _Authenticate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref7) {
551
552
  var token, decodedToken;
552
553
  return _regeneratorRuntime.wrap(function _callee10$(_context10) {
@@ -612,9 +613,10 @@ var ElvWalletClient = /*#__PURE__*/function () {
612
613
  * - signingToken - Identical to `authToken`, but also includes the ability to perform arbitrary signatures with the custodial wallet. This token should be protected and should not be
613
614
  * shared with third parties.
614
615
  */
616
+ )
615
617
  }, {
616
618
  key: "AuthenticateOAuth",
617
- value: function () {
619
+ value: (function () {
618
620
  var _AuthenticateOAuth = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(_ref8) {
619
621
  var idToken, tenantId, email, signerURIs, _ref8$shareEmail, shareEmail, _ref8$extraData, extraData, nonce, _ref8$createRemoteTok, createRemoteToken, _ref8$force, force, tokenDuration, fabricToken, expiresAt, tokenResponse, address, decodedToken;
620
622
  return _regeneratorRuntime.wrap(function _callee11$(_context11) {
@@ -741,9 +743,10 @@ var ElvWalletClient = /*#__PURE__*/function () {
741
743
  * @returns {Promise<string>} - Returns an authorization token that can be used to initialize the client using <a href="#Authenticate">Authenticate</a>.
742
744
  * Save this token to avoid having to reauthenticate. This token expires after 24 hours.
743
745
  */
746
+ )
744
747
  }, {
745
748
  key: "AuthenticateExternalWallet",
746
- value: function () {
749
+ value: (function () {
747
750
  var _AuthenticateExternalWallet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(_ref9) {
748
751
  var _this2 = this;
749
752
  var address, _ref9$tokenDuration, tokenDuration, _ref9$walletName, walletName, Sign, expiresAt, fabricToken;
@@ -812,6 +815,7 @@ var ElvWalletClient = /*#__PURE__*/function () {
812
815
  *
813
816
  * @returns {string} - The client auth token
814
817
  */
818
+ )
815
819
  }, {
816
820
  key: "ClientAuthToken",
817
821
  value: function ClientAuthToken() {
@@ -1974,7 +1978,7 @@ var ElvWalletClient = /*#__PURE__*/function () {
1974
1978
  */
1975
1979
  }, {
1976
1980
  key: "Initialize",
1977
- value: function () {
1981
+ value: (function () {
1978
1982
  var _Initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee25(_ref24) {
1979
1983
  var client, _ref24$appId, appId, _ref24$network, network, _ref24$mode, mode, localization, marketplaceParams, previewMarketplaceId, _ref24$storeAuthToken, storeAuthToken, _ref24$skipMarketplac, skipMarketplaceLoad, _ref25, tenantSlug, marketplaceSlug, marketplaceId, marketplaceHash, previewMarketplaceHash, walletClient, url, savedToken;
1980
1984
  return _regeneratorRuntime.wrap(function _callee25$(_context25) {
@@ -2092,9 +2096,8 @@ var ElvWalletClient = /*#__PURE__*/function () {
2092
2096
  return _Initialize.apply(this, arguments);
2093
2097
  }
2094
2098
  return Initialize;
2095
- }()
2099
+ }())
2096
2100
  }]);
2097
- return ElvWalletClient;
2098
2101
  }();
2099
2102
  Object.assign(ElvWalletClient.prototype, require("./ClientMethods"));
2100
2103
  Object.assign(ElvWalletClient.prototype, require("./Profile"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "4.0.88",
3
+ "version": "4.0.90",
4
4
  "description": "Javascript client for the Eluvio Content Fabric",
5
5
  "main": "src/index.js",
6
6
  "author": "Kevin Talmadge",
package/src/HttpClient.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const URI = require("urijs");
2
2
  const Fetch = typeof fetch !== "undefined" ? fetch : require("node-fetch").default;
3
3
  const {LogMessage} = require("./LogMessage");
4
+ const Utils = require("./Utils");
4
5
 
5
6
  class HttpClient {
6
7
  Log(message, error=false) {
@@ -100,7 +101,10 @@ class HttpClient {
100
101
  }
101
102
 
102
103
  let response;
103
- this.Log(`${method} - ${uri.toString()}`);
104
+ if(this.debug) {
105
+ this.Log(`${method} - ${uri.toString()}`);
106
+ this.Log(`fetchParameters: ${JSON.stringify(fetchParameters, null, 2)}`);
107
+ }
104
108
  try {
105
109
  response =
106
110
  await HttpClient.Fetch(
@@ -166,7 +170,7 @@ class HttpClient {
166
170
  requestParams: fetchParameters
167
171
  };
168
172
 
169
- this.Log(
173
+ if(this.debug) this.Log(
170
174
  JSON.stringify(error, null, 2),
171
175
  true
172
176
  );
@@ -208,6 +212,16 @@ class HttpClient {
208
212
  );
209
213
  }
210
214
 
215
+ // Perform http request and then return response body parsed as JSON
216
+ // ResponseToJson() will log response if this.debug === true
217
+ async RequestJsonBody(params) {
218
+ return Utils.ResponseToJson(
219
+ this.Request(params),
220
+ this.debug,
221
+ this.Log.bind(this)
222
+ );
223
+ }
224
+
211
225
  URL({path, queryParams={}}) {
212
226
  let baseURI = this.BaseURI();
213
227
 
package/src/Utils.js CHANGED
@@ -545,18 +545,40 @@ const Utils = {
545
545
  });
546
546
  },
547
547
 
548
- ResponseToJson: async (response) => {
549
- return Utils.ResponseToFormat("json", response);
548
+ /**
549
+ * Interprets an http response body obtained from an http call as JSON and returns result of parsing it.
550
+ *
551
+ * @param {Promise} response - An http response from node-fetch
552
+ * @param {boolean=} debug - Whether or not to log the body
553
+ * @param {Function} logFn - Log function to use if debug is truthy
554
+ * @return {*} - Result of parsing response body as JSON
555
+ */
556
+ ResponseToJson: async (response, debug = false, logFn) => {
557
+ return await Utils.ResponseToFormat("json", response, debug, logFn);
550
558
  },
551
559
 
552
- ResponseToFormat: async (format, response) => {
560
+ /**
561
+ * Interprets an http response body obtained from an http call as a requested format and returns result of converting/formatting.
562
+ *
563
+ * @param {string} format - The format to use when interpreting response body (e.g. "json", "text" et. al.)
564
+ * @param {Promise} response - An http response from node-fetch
565
+ * @param {boolean=} debug - Whether or not to log a debug statement containing the body (ignored for formats other than "json" and "text")
566
+ * @param {Function} logFn - Log function to use if debug is truthy
567
+ * @return {*} - Result of converting response body into the requested format
568
+ */
569
+ ResponseToFormat: async (format, response, debug = false, logFn) => {
553
570
  response = await response;
571
+ let formattedBody;
554
572
 
555
573
  switch(format.toLowerCase()) {
556
574
  case "json":
557
- return await response.json();
575
+ formattedBody = await response.json();
576
+ if(debug) logFn(`response body: ${JSON.stringify(formattedBody, null, 2)}`);
577
+ return formattedBody;
558
578
  case "text":
559
- return await response.text();
579
+ formattedBody = await response.text();
580
+ if(debug) logFn(`response body: ${formattedBody}`);
581
+ return formattedBody;
560
582
  case "blob":
561
583
  return await response.blob();
562
584
  case "arraybuffer":
@@ -390,13 +390,11 @@ exports.ContentLibrary = async function({libraryId}) {
390
390
 
391
391
  const path = UrlJoin("qlibs", libraryId);
392
392
 
393
- const library = await this.utils.ResponseToJson(
394
- this.HttpClient.Request({
395
- headers: await this.authClient.AuthorizationHeader({libraryId}),
396
- method: "GET",
397
- path: path
398
- })
399
- );
393
+ const library = await this.HttpClient.RequestJsonBody({
394
+ headers: await this.authClient.AuthorizationHeader({libraryId}),
395
+ method: "GET",
396
+ path: path
397
+ });
400
398
 
401
399
  return {
402
400
  ...library,
@@ -566,14 +564,12 @@ exports.ContentObjects = async function({libraryId, filterOptions={}}) {
566
564
  this.Log("Filter options:");
567
565
  this.Log(filterOptions);
568
566
 
569
- return await this.utils.ResponseToJson(
570
- this.HttpClient.Request({
571
- headers: await this.authClient.AuthorizationHeader({libraryId}),
572
- method: "GET",
573
- path: path,
574
- queryParams
575
- })
576
- );
567
+ return await this.HttpClient.RequestJsonBody({
568
+ headers: await this.authClient.AuthorizationHeader({libraryId}),
569
+ method: "GET",
570
+ path: path,
571
+ queryParams
572
+ });
577
573
  };
578
574
 
579
575
  /**
@@ -597,13 +593,11 @@ exports.ContentObject = async function({libraryId, objectId, versionHash, writeT
597
593
 
598
594
  let path = UrlJoin("q", writeToken || versionHash || objectId);
599
595
 
600
- return await this.utils.ResponseToJson(
601
- this.HttpClient.Request({
602
- headers: await this.authClient.AuthorizationHeader({libraryId, objectId, versionHash}),
603
- method: "GET",
604
- path: path
605
- })
606
- );
596
+ return await this.HttpClient.RequestJsonBody({
597
+ headers: await this.authClient.AuthorizationHeader({libraryId, objectId, versionHash}),
598
+ method: "GET",
599
+ path: path
600
+ });
607
601
  };
608
602
 
609
603
  /**
@@ -919,22 +913,20 @@ exports.ContentObjectMetadata = async function({
919
913
 
920
914
  let metadata;
921
915
  try {
922
- metadata = await this.utils.ResponseToJson(
923
- this.HttpClient.Request({
924
- headers: { "Authorization": authTokens.map(token => `Bearer ${token}`) },
925
- queryParams: {
926
- ...queryParams,
927
- select,
928
- remove,
929
- link_depth: linkDepthLimit,
930
- resolve: resolveLinks,
931
- resolve_include_source: resolveIncludeSource,
932
- resolve_ignore_errors: resolveIgnoreErrors,
933
- },
934
- method: "GET",
935
- path: path
936
- })
937
- );
916
+ metadata = await this.HttpClient.RequestJsonBody({
917
+ headers: { "Authorization": authTokens.map(token => `Bearer ${token}`) },
918
+ queryParams: {
919
+ ...queryParams,
920
+ select,
921
+ remove,
922
+ link_depth: linkDepthLimit,
923
+ resolve: resolveLinks,
924
+ resolve_include_source: resolveIncludeSource,
925
+ resolve_ignore_errors: resolveIgnoreErrors,
926
+ },
927
+ method: "GET",
928
+ path: path
929
+ });
938
930
  } catch(error) {
939
931
  if(error.status !== 404) {
940
932
  throw error;
@@ -1066,13 +1058,11 @@ exports.ContentObjectVersions = async function({libraryId, objectId}) {
1066
1058
 
1067
1059
  let path = UrlJoin("qid", objectId);
1068
1060
 
1069
- return this.utils.ResponseToJson(
1070
- this.HttpClient.Request({
1071
- headers: await this.authClient.AuthorizationHeader({libraryId, objectId}),
1072
- method: "GET",
1073
- path: path
1074
- })
1075
- );
1061
+ return this.HttpClient.RequestJsonBody({
1062
+ headers: await this.authClient.AuthorizationHeader({libraryId, objectId}),
1063
+ method: "GET",
1064
+ path: path
1065
+ });
1076
1066
  };
1077
1067
 
1078
1068
  /**
@@ -1143,13 +1133,11 @@ exports.LatestVersionHashV2 = async function({objectId, versionHash}) {
1143
1133
  try {
1144
1134
  let path = UrlJoin("q", objectId);
1145
1135
 
1146
- let q = await this.utils.ResponseToJson(
1147
- this.HttpClient.Request({
1148
- headers: await this.authClient.AuthorizationHeader({objectId}),
1149
- method: "GET",
1150
- path: path
1151
- })
1152
- );
1136
+ let q = await this.HttpClient.RequestJsonBody({
1137
+ headers: await this.authClient.AuthorizationHeader({objectId}),
1138
+ method: "GET",
1139
+ path: path
1140
+ });
1153
1141
  latestHash = q.hash;
1154
1142
 
1155
1143
  } catch(error) {
@@ -1210,20 +1198,29 @@ exports.AvailableDRMs = async function() {
1210
1198
  return availableDRMs;
1211
1199
  }
1212
1200
 
1213
- try {
1214
- const config = [{
1215
- initDataTypes: ["cenc"],
1216
- audioCapabilities: [{
1217
- contentType: "audio/mp4;codecs=\"mp4a.40.2\""
1218
- }],
1219
- videoCapabilities: [{
1220
- contentType: "video/mp4;codecs=\"avc1.42E01E\""
1221
- }]
1222
- }];
1201
+ const config = [{
1202
+ initDataTypes: ["cenc"],
1203
+ audioCapabilities: [{
1204
+ contentType: "audio/mp4;codecs=\"mp4a.40.2\""
1205
+ }],
1206
+ videoCapabilities: [{
1207
+ contentType: "video/mp4;codecs=\"avc1.42E01E\""
1208
+ }]
1209
+ }];
1223
1210
 
1211
+ try {
1224
1212
  await navigator.requestMediaKeySystemAccess("com.widevine.alpha", config);
1225
-
1226
1213
  availableDRMs.push("widevine");
1214
+ // console.log("widevine detected");
1215
+ // eslint-disable-next-line no-empty
1216
+ } catch(e) {}
1217
+
1218
+ try {
1219
+ // unused parameters:
1220
+ // robustness: "2000" // 150, 2000, or 3000 if we know the secruity level
1221
+ await navigator.requestMediaKeySystemAccess("com.microsoft.playready", config);
1222
+ availableDRMs.push("playready");
1223
+ // console.log("playready detected");
1227
1224
  // eslint-disable-next-line no-empty
1228
1225
  } catch(e) {}
1229
1226
 
@@ -1370,15 +1367,13 @@ exports.AvailableOfferings = async function({
1370
1367
  .flat()
1371
1368
  .filter(token => token);
1372
1369
 
1373
- return await this.utils.ResponseToJson(
1374
- this.HttpClient.Request({
1375
- path: path,
1376
- method: "GET",
1377
- headers: {
1378
- Authorization: `Bearer ${authorization.join(",")}`
1379
- }
1380
- })
1381
- );
1370
+ return await this.HttpClient.RequestJsonBody({
1371
+ path: path,
1372
+ method: "GET",
1373
+ headers: {
1374
+ Authorization: `Bearer ${authorization.join(",")}`
1375
+ }
1376
+ });
1382
1377
  } catch(error) {
1383
1378
  if(error.status && parseInt(error.status) === 500) {
1384
1379
  return {};
@@ -1407,7 +1402,7 @@ exports.AvailableOfferings = async function({
1407
1402
  * @param {string=} linkPath - If playing from a link, the path to the link
1408
1403
  * @param {boolean=} signedLink - Specify if linkPath is referring to a signed link
1409
1404
  * @param {Array<string>} protocols=["dash","hls"]] - Acceptable playout protocols ("dash", "hls")
1410
- * @param {Array<string>} drms - Acceptable DRM formats ("clear", "aes-128", "widevine")
1405
+ * @param {Array<string>} drms - Acceptable DRM formats ("aes-128", "clear", "fairplay", "playready", "sample-aes", "widevine")
1411
1406
  * @param {string=} handler=playout - The handler to use for playout (not used with links)
1412
1407
  * @param {string=} offering=default - The offering to play
1413
1408
  * @param {string=} playoutType - The type of playout
@@ -1517,13 +1512,11 @@ exports.PlayoutOptions = async function({
1517
1512
  };
1518
1513
 
1519
1514
  const playoutOptions = Object.values(
1520
- await this.utils.ResponseToJson(
1521
- this.HttpClient.Request({
1522
- path,
1523
- method: "GET",
1524
- queryParams
1525
- })
1526
- )
1515
+ await this.HttpClient.RequestJsonBody({
1516
+ path,
1517
+ method: "GET",
1518
+ queryParams
1519
+ })
1527
1520
  );
1528
1521
 
1529
1522
  if(!signedLink && linkTarget.versionHash) {
@@ -1629,17 +1622,14 @@ exports.PlayoutOptions = async function({
1629
1622
  playoutMap.multiview = true;
1630
1623
 
1631
1624
  playoutMap.AvailableViews = async () => {
1632
- return await this.utils.ResponseToFormat(
1633
- "json",
1634
- await this.HttpClient.Request({
1635
- path: UrlJoin("q", linkTarget.versionHash || versionHash, "rep", handler, offering, "views.json"),
1636
- method: "GET",
1637
- queryParams: {
1638
- sid: sessionId,
1639
- authorization
1640
- }
1641
- })
1642
- );
1625
+ return await this.HttpClient.RequestJsonBody({
1626
+ path: UrlJoin("q", linkTarget.versionHash || versionHash, "rep", handler, offering, "views.json"),
1627
+ method: "GET",
1628
+ queryParams: {
1629
+ sid: sessionId,
1630
+ authorization
1631
+ }
1632
+ });
1643
1633
  };
1644
1634
 
1645
1635
  playoutMap.SwitchView = async (view) => {
@@ -1675,7 +1665,7 @@ exports.PlayoutOptions = async function({
1675
1665
  * @param {string=} linkPath - If playing from a link, the path to the link
1676
1666
  * @param {boolean=} signedLink - Specify if linkPath is referring to a signed link
1677
1667
  * @param {Array<string>} protocols=["dash","hls"]] - Acceptable playout protocols ("dash", "hls")
1678
- * @param {Array<string>} drms - Acceptable DRM formats ("clear", "aes-128", "sample-aes", "widevine")
1668
+ * @param {Array<string>} drms - Acceptable DRM formats ("aes-128", "clear", "fairplay", "playready", "sample-aes", "widevine")
1679
1669
  * @param {string=} handler=playout - The handler to use for playout
1680
1670
  * @param {string=} offering=default - The offering to play
1681
1671
  * @param {string=} playoutType - The type of playout
@@ -1873,7 +1863,9 @@ exports.CallBitcodeMethod = async function({
1873
1863
  path,
1874
1864
  queryParams,
1875
1865
  allowFailover: false
1876
- })
1866
+ }),
1867
+ this.HttpClient.debug,
1868
+ this.HttpClient.Log.bind(this.HttpClient)
1877
1869
  );
1878
1870
  };
1879
1871
 
@@ -183,8 +183,13 @@ exports.CreateContentType = async function({name, metadata={}, bitcode}) {
183
183
  path: path
184
184
  });
185
185
  // extract the url for the node that handled the request
186
+ // TODO: remove/simplify after we start using /nodes API call to get node URLs for write tokens
186
187
  const nodeUrl = (new URL(rawCreateResponse.url)).origin;
187
- const createResponse = await this.utils.ResponseToJson(rawCreateResponse);
188
+ const createResponse = await this.utils.ResponseToJson(
189
+ rawCreateResponse,
190
+ this.HttpClient.debug,
191
+ this.HttpClient.Log.bind(this.HttpClient)
192
+ );
188
193
 
189
194
  // Record the node used in creating this write token
190
195
  this.RecordWriteToken({writeToken: createResponse.write_token, fabricNodeUrl: nodeUrl});
@@ -602,8 +607,14 @@ exports.CreateContentObject = async function({libraryId, objectId, options={}})
602
607
  path: path,
603
608
  body: options
604
609
  });
610
+ // extract the url for the node that handled the request
611
+ // TODO: remove/simplify after we start using /nodes API call to get node URLs for write tokens
605
612
  const nodeUrl = (new URL(rawCreateResponse.url)).origin;
606
- const createResponse = await this.utils.ResponseToJson(rawCreateResponse);
613
+ const createResponse = await this.utils.ResponseToJson(
614
+ rawCreateResponse,
615
+ this.HttpClient.debug,
616
+ this.HttpClient.Log.bind(this.HttpClient)
617
+ );
607
618
 
608
619
  // Record the node used in creating this write token
609
620
  this.RecordWriteToken({writeToken: createResponse.write_token, fabricNodeUrl: nodeUrl});
@@ -773,8 +784,13 @@ exports.EditContentObject = async function({libraryId, objectId, options={}}) {
773
784
  body: options
774
785
  });
775
786
  // extract the url for the node that handled the request
787
+ // TODO: remove/simplify after we start using /nodes API call to get node URLs for write tokens
776
788
  const nodeUrl = (new URL(rawEditResponse.url)).origin;
777
- const editResponse = await this.utils.ResponseToJson(rawEditResponse);
789
+ const editResponse = await this.utils.ResponseToJson(
790
+ rawEditResponse,
791
+ this.HttpClient.debug,
792
+ this.HttpClient.Log.bind(this.HttpClient)
793
+ );
778
794
 
779
795
  // Record the node used in creating this write token
780
796
  this.RecordWriteToken({writeToken: editResponse.write_token, fabricNodeUrl: nodeUrl});
@@ -957,14 +973,12 @@ exports.FinalizeContentObject = async function({
957
973
 
958
974
  let path = UrlJoin("q", writeToken);
959
975
 
960
- const finalizeResponse = await this.utils.ResponseToJson(
961
- this.HttpClient.Request({
962
- headers: await this.authClient.AuthorizationHeader({libraryId, objectId, update: true}),
963
- method: "POST",
964
- path: path,
965
- allowFailover: false
966
- })
967
- );
976
+ const finalizeResponse = await this.HttpClient.RequestJsonBody({
977
+ headers: await this.authClient.AuthorizationHeader({libraryId, objectId, update: true}),
978
+ method: "POST",
979
+ path: path,
980
+ allowFailover: false
981
+ });
968
982
 
969
983
  this.Log(`Finalized: ${finalizeResponse.hash}`);
970
984