@eluvio/elv-client-js 4.2.33 → 4.2.36

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.
@@ -1,7 +1,7 @@
1
- var _typeof = require("@babel/runtime/helpers/typeof");
2
1
  var _defineProperty = require("@babel/runtime/helpers/defineProperty");
3
2
  var _regeneratorRuntime = require("@babel/runtime/regenerator");
4
3
  var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
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
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
  /**
@@ -28,6 +28,32 @@ var _require = require("../Validation"),
28
28
  ValidateWriteToken = _require.ValidateWriteToken,
29
29
  ValidateParameters = _require.ValidateParameters,
30
30
  ValidatePresence = _require.ValidatePresence;
31
+
32
+ /* Validation for Fabric tags, groups and query fields */
33
+
34
+ var ValidateTags = function ValidateTags(tags) {
35
+ if (!Array.isArray(tags)) {
36
+ throw Error("Tags must be an array");
37
+ }
38
+ };
39
+
40
+ // Group references are content object IDs. A library ID is also accepted, since a library
41
+ // may act as a group (see the Fabric's "lib" unique group type).
42
+ var ValidateGroups = function ValidateGroups(groups) {
43
+ if (!Array.isArray(groups)) {
44
+ throw Error("Groups must be an array");
45
+ }
46
+ groups.forEach(function (groupId) {
47
+ if (typeof groupId !== "string" || !(groupId.startsWith("iq__") || groupId.startsWith("ilib"))) {
48
+ throw Error("Invalid group ID: ".concat(groupId));
49
+ }
50
+ });
51
+ };
52
+ var ValidateQueryFields = function ValidateQueryFields(queryFields) {
53
+ if (_typeof(queryFields) !== "object" || queryFields === null || Array.isArray(queryFields)) {
54
+ throw Error("Query fields must be an object");
55
+ }
56
+ };
31
57
  exports.SetVisibility = /*#__PURE__*/function () {
32
58
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
33
59
  var id, visibility, hasSetVisibility, event;
@@ -808,14 +834,18 @@ exports.RemoveLibraryContentType = /*#__PURE__*/function () {
808
834
  * @namedParams
809
835
  * @param {string} libraryId - ID of the library
810
836
  * @param {string=} objectId - ID of the object (if contract already exists)
811
- * @param {Object=} options -
812
- * type: Version hash of the content type to associate with the object
813
- *
814
- * meta: Metadata to use for the new object
815
- *
816
- * noEncryptionConk: Set to true to prevent creation of an encryption conk for the object
817
- *
818
- * createKMSConk: Set to true to create a KMS conk for object (usually for sharing a playable object) (incompatible with noEncryptionConk: true)
837
+ * @param {Object=} options - Additional object creation options
838
+ * @param {string=} options.type - Version hash of the content type to associate with the object
839
+ * @param {Object=} options.meta - Metadata to use for the new object
840
+ * @param {string=} options.copy_from - Version hash of an existing object version to copy
841
+ * @param {string=} options.objectType - System-level object type, e.g. "cgroup" for a content group. May only be
842
+ * specified when creating a new object - the Fabric rejects an object type change on a new version of an existing object
843
+ * @param {Array<string>=} options.tags - Fabric tags to associate with the object
844
+ * @param {Array<string>=} options.groups - IDs of the content groups to add the object to. These categorize content and
845
+ * are distinct from the access groups that grant permissions
846
+ * @param {Object<string, string>=} options.queryFields - Unencrypted, indexed query fields to associate with the object
847
+ * @param {boolean=} options.noEncryptionConk - Set to true to prevent creation of an encryption conk for the object
848
+ * @param {boolean=} options.createKMSConk - Set to true to create a KMS conk for object (usually for sharing a playable object) (incompatible with noEncryptionConk: true)
819
849
  *
820
850
  * @returns {Promise<Object>} - Response containing the object ID and write token of the draft, as well as the url of the node that created the write token.
821
851
  */
@@ -837,128 +867,143 @@ exports.CreateContentObject = /*#__PURE__*/function () {
837
867
  }
838
868
  throw new Error("Incompatible options: noEncryptionConk and createKMSConk both set to true");
839
869
  case 6:
870
+ if (options.tags !== undefined) {
871
+ ValidateTags(options.tags);
872
+ }
873
+ if (options.groups !== undefined) {
874
+ ValidateGroups(options.groups);
875
+ }
876
+ if (options.queryFields !== undefined) {
877
+ ValidateQueryFields(options.queryFields);
878
+ }
879
+
880
+ // Look up content type, if specified
840
881
  if (!options.type) {
841
- _context11.next = 28;
882
+ _context11.next = 31;
842
883
  break;
843
884
  }
844
885
  this.Log("Type specified: ".concat(options.type));
845
886
  type = options.type;
846
887
  if (!type.startsWith("hq__")) {
847
- _context11.next = 15;
888
+ _context11.next = 18;
848
889
  break;
849
890
  }
850
- _context11.next = 12;
891
+ _context11.next = 15;
851
892
  return this.ContentType({
852
893
  versionHash: type
853
894
  });
854
- case 12:
895
+ case 15:
855
896
  type = _context11.sent;
856
- _context11.next = 24;
897
+ _context11.next = 27;
857
898
  break;
858
- case 15:
899
+ case 18:
859
900
  if (!type.startsWith("iq__")) {
860
- _context11.next = 21;
901
+ _context11.next = 24;
861
902
  break;
862
903
  }
863
- _context11.next = 18;
904
+ _context11.next = 21;
864
905
  return this.ContentType({
865
906
  typeId: type
866
907
  });
867
- case 18:
908
+ case 21:
868
909
  type = _context11.sent;
869
- _context11.next = 24;
910
+ _context11.next = 27;
870
911
  break;
871
- case 21:
872
- _context11.next = 23;
912
+ case 24:
913
+ _context11.next = 26;
873
914
  return this.ContentType({
874
915
  name: type
875
916
  });
876
- case 23:
917
+ case 26:
877
918
  type = _context11.sent;
878
- case 24:
919
+ case 27:
879
920
  if (type) {
880
- _context11.next = 26;
921
+ _context11.next = 29;
881
922
  break;
882
923
  }
883
924
  throw Error("Unable to find content type '".concat(options.type, "'"));
884
- case 26:
925
+ case 29:
885
926
  typeId = type.id;
886
927
  options.type = type.hash;
887
- case 28:
928
+ case 31:
888
929
  if (objectId) {
889
- _context11.next = 46;
930
+ _context11.next = 49;
890
931
  break;
891
932
  }
892
- _context11.next = 31;
933
+ _context11.next = 34;
893
934
  return this.CurrentAccountAddress();
894
- case 31:
935
+ case 34:
895
936
  currentAccountAddress = _context11.sent;
896
- _context11.next = 34;
937
+ _context11.next = 37;
897
938
  return this.CallContractMethod({
898
939
  contractAddress: this.utils.HashToAddress(libraryId),
899
940
  methodName: "canContribute",
900
941
  methodArgs: [currentAccountAddress]
901
942
  });
902
- case 34:
943
+ case 37:
903
944
  canContribute = _context11.sent;
904
945
  if (canContribute) {
905
- _context11.next = 37;
946
+ _context11.next = 40;
906
947
  break;
907
948
  }
908
949
  throw Error("Current user does not have permission to create content in library ".concat(libraryId));
909
- case 37:
950
+ case 40:
910
951
  this.Log("Deploying contract...");
911
- _context11.next = 40;
952
+ _context11.next = 43;
912
953
  return this.authClient.CreateContentObject({
913
954
  libraryId: libraryId,
914
955
  typeId: typeId
915
956
  });
916
- case 40:
957
+ case 43:
917
958
  _yield$this$authClien3 = _context11.sent;
918
959
  contractAddress = _yield$this$authClien3.contractAddress;
919
960
  objectId = this.utils.AddressToObjectId(contractAddress);
920
961
  this.Log("Contract deployed: ".concat(contractAddress, " ").concat(objectId));
921
- _context11.next = 53;
962
+ _context11.next = 56;
922
963
  break;
923
- case 46:
964
+ case 49:
924
965
  _context11.t0 = this;
925
966
  _context11.t1 = "Contract already deployed for contract type: ";
926
- _context11.next = 50;
967
+ _context11.next = 53;
927
968
  return this.AccessType({
928
969
  id: objectId
929
970
  });
930
- case 50:
971
+ case 53:
931
972
  _context11.t2 = _context11.sent;
932
973
  _context11.t3 = _context11.t1.concat.call(_context11.t1, _context11.t2);
933
974
  _context11.t0.Log.call(_context11.t0, _context11.t3);
934
- case 53:
975
+ case 56:
935
976
  if (!options.visibility) {
936
- _context11.next = 57;
977
+ _context11.next = 60;
937
978
  break;
938
979
  }
939
980
  this.Log("Setting visibility to ".concat(options.visibility));
940
- _context11.next = 57;
981
+ _context11.next = 60;
941
982
  return this.SetVisibility({
942
983
  id: objectId,
943
984
  visibility: options.visibility
944
985
  });
945
- case 57:
986
+ case 60:
946
987
  path = UrlJoin("qid", objectId);
947
988
  _context11.t4 = this.HttpClient;
948
- _context11.next = 61;
989
+ _context11.next = 64;
949
990
  return this.authClient.AuthorizationHeader({
950
991
  libraryId: libraryId,
951
992
  objectId: objectId,
952
993
  update: true
953
994
  });
954
- case 61:
995
+ case 64:
955
996
  _context11.t5 = _context11.sent;
956
997
  _context11.t6 = path;
957
998
  _context11.t7 = {
958
999
  // filter out options not recognized by server (noEncryptionConk, createKMSConk)
959
1000
  type: options.type,
960
1001
  meta: options.meta,
961
- copy_from: options.copy_from
1002
+ copy_from: options.copy_from,
1003
+ object_type: options.objectType,
1004
+ tags: options.tags,
1005
+ groups: options.groups,
1006
+ query_fields: options.queryFields
962
1007
  };
963
1008
  _context11.t8 = {
964
1009
  headers: _context11.t5,
@@ -966,30 +1011,30 @@ exports.CreateContentObject = /*#__PURE__*/function () {
966
1011
  path: _context11.t6,
967
1012
  body: _context11.t7
968
1013
  };
969
- _context11.next = 67;
1014
+ _context11.next = 70;
970
1015
  return _context11.t4.Request.call(_context11.t4, _context11.t8);
971
- case 67:
1016
+ case 70:
972
1017
  rawCreateResponse = _context11.sent;
973
1018
  // extract the url for the node that handled the request
974
1019
  // (not strictly needed now that we can quickly look up node URL for a write token,
975
1020
  // but still convenient)
976
1021
  nodeUrl = new URL(rawCreateResponse.url).origin;
977
- _context11.next = 71;
1022
+ _context11.next = 74;
978
1023
  return this.utils.ResponseToJson(rawCreateResponse, this.HttpClient.debug, this.HttpClient.Log.bind(this.HttpClient));
979
- case 71:
1024
+ case 74:
980
1025
  createResponse = _context11.sent;
981
1026
  if (options.noEncryptionConk) {
982
- _context11.next = 75;
1027
+ _context11.next = 78;
983
1028
  break;
984
1029
  }
985
- _context11.next = 75;
1030
+ _context11.next = 78;
986
1031
  return this.CreateEncryptionConk({
987
1032
  libraryId: libraryId,
988
1033
  objectId: objectId,
989
1034
  writeToken: createResponse.write_token,
990
1035
  createKMSConk: !!options.createKMSConk // make sure `undefined` gets converted to `false`
991
1036
  });
992
- case 75:
1037
+ case 78:
993
1038
  // Record the node used in creating this write token
994
1039
  this.RecordWriteToken({
995
1040
  writeToken: createResponse.write_token,
@@ -999,7 +1044,7 @@ exports.CreateContentObject = /*#__PURE__*/function () {
999
1044
  createResponse.objectId = createResponse.id;
1000
1045
  createResponse.nodeUrl = nodeUrl;
1001
1046
  return _context11.abrupt("return", createResponse);
1002
- case 80:
1047
+ case 83:
1003
1048
  case "end":
1004
1049
  return _context11.stop();
1005
1050
  }
@@ -1246,16 +1291,17 @@ exports.CreateNonOwnerCap = /*#__PURE__*/function () {
1246
1291
  * @param {object=} options -
1247
1292
  * @param {object=} options.meta - New metadata for the object - will be merged into existing metadata if specified
1248
1293
  * @param {string=} options.type - New type for the object - Object ID, version hash or name of type
1294
+ * @param {string=} nodeUrl - Fabric node URL to create the draft on
1249
1295
  *
1250
1296
  * @returns {Promise<object>} - Response containing the object ID and write token of the draft, as well as URL of node handling the draft
1251
1297
  */
1252
1298
  exports.EditContentObject = /*#__PURE__*/function () {
1253
1299
  var _ref28 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(_ref27) {
1254
- var libraryId, objectId, _ref27$options, options, path, rawEditResponse, nodeUrl, editResponse;
1300
+ var libraryId, objectId, _ref27$options, options, nodeUrl, path, rawEditResponse, responseNodeUrl, editResponse;
1255
1301
  return _regeneratorRuntime.wrap(function _callee15$(_context15) {
1256
1302
  while (1) switch (_context15.prev = _context15.next) {
1257
1303
  case 0:
1258
- libraryId = _ref27.libraryId, objectId = _ref27.objectId, _ref27$options = _ref27.options, options = _ref27$options === void 0 ? {} : _ref27$options;
1304
+ libraryId = _ref27.libraryId, objectId = _ref27.objectId, _ref27$options = _ref27.options, options = _ref27$options === void 0 ? {} : _ref27$options, nodeUrl = _ref27.nodeUrl;
1259
1305
  ValidateParameters({
1260
1306
  libraryId: libraryId,
1261
1307
  objectId: objectId
@@ -1318,33 +1364,35 @@ exports.EditContentObject = /*#__PURE__*/function () {
1318
1364
  _context15.t1 = _context15.sent;
1319
1365
  _context15.t2 = path;
1320
1366
  _context15.t3 = options;
1321
- _context15.t4 = {
1367
+ _context15.t4 = nodeUrl;
1368
+ _context15.t5 = {
1322
1369
  headers: _context15.t1,
1323
1370
  method: "POST",
1324
1371
  path: _context15.t2,
1325
- body: _context15.t3
1372
+ body: _context15.t3,
1373
+ nodeUrl: _context15.t4
1326
1374
  };
1327
- _context15.next = 33;
1328
- return _context15.t0.Request.call(_context15.t0, _context15.t4);
1329
- case 33:
1375
+ _context15.next = 34;
1376
+ return _context15.t0.Request.call(_context15.t0, _context15.t5);
1377
+ case 34:
1330
1378
  rawEditResponse = _context15.sent;
1331
1379
  // extract the url for the node that handled the request
1332
1380
  // TODO: remove/simplify after we start using /nodes API call to get node URLs for write tokens
1333
- nodeUrl = new URL(rawEditResponse.url).origin;
1334
- _context15.next = 37;
1381
+ responseNodeUrl = new URL(rawEditResponse.url).origin;
1382
+ _context15.next = 38;
1335
1383
  return this.utils.ResponseToJson(rawEditResponse, this.HttpClient.debug, this.HttpClient.Log.bind(this.HttpClient));
1336
- case 37:
1384
+ case 38:
1337
1385
  editResponse = _context15.sent;
1338
1386
  // Record the node used in creating this write token
1339
1387
  this.RecordWriteToken({
1340
1388
  writeToken: editResponse.write_token,
1341
- fabricNodeUrl: nodeUrl
1389
+ fabricNodeUrl: responseNodeUrl
1342
1390
  });
1343
1391
  editResponse.writeToken = editResponse.write_token;
1344
1392
  editResponse.objectId = editResponse.id;
1345
- editResponse.nodeUrl = nodeUrl;
1393
+ editResponse.nodeUrl = responseNodeUrl;
1346
1394
  return _context15.abrupt("return", editResponse);
1347
- case 43:
1395
+ case 44:
1348
1396
  case "end":
1349
1397
  return _context15.stop();
1350
1398
  }
@@ -2693,4 +2741,556 @@ exports.DeleteWriteToken = /*#__PURE__*/function () {
2693
2741
  return function (_x34) {
2694
2742
  return _ref65.apply(this, arguments);
2695
2743
  };
2744
+ }();
2745
+
2746
+ /* Content group creation, modification, deletion */
2747
+
2748
+ /**
2749
+ * Create content tags
2750
+ *
2751
+ * @methodGroup Content Groups
2752
+ * @namedParams
2753
+ * @param {string} libraryId - ID of the library
2754
+ * @param {string} writeToken - Write token of the draft
2755
+ * @param {Array<string>} tags - List of tags
2756
+ *
2757
+ * @returns {Promise<Array<string>>} - The tags on the object after the update
2758
+ */
2759
+ exports.AddContentObjectTags = /*#__PURE__*/function () {
2760
+ var _ref67 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee36(_ref66) {
2761
+ var libraryId, writeToken, tags, path, objectId;
2762
+ return _regeneratorRuntime.wrap(function _callee36$(_context37) {
2763
+ while (1) switch (_context37.prev = _context37.next) {
2764
+ case 0:
2765
+ libraryId = _ref66.libraryId, writeToken = _ref66.writeToken, tags = _ref66.tags;
2766
+ ValidateLibrary(libraryId);
2767
+ ValidateWriteToken(writeToken);
2768
+ ValidatePresence("tags", tags);
2769
+ path = UrlJoin("qlibs", libraryId, "q", writeToken, "tags");
2770
+ objectId = this.utils.DecodeWriteToken(writeToken).objectId;
2771
+ this.Log("Adding tags: ".concat(tags.join(", ")));
2772
+ _context37.t0 = this.HttpClient;
2773
+ _context37.next = 10;
2774
+ return this.authClient.AuthorizationHeader({
2775
+ libraryId: libraryId,
2776
+ objectId: objectId,
2777
+ update: true
2778
+ });
2779
+ case 10:
2780
+ _context37.t1 = _context37.sent;
2781
+ _context37.t2 = path;
2782
+ _context37.t3 = tags;
2783
+ _context37.t4 = {
2784
+ headers: _context37.t1,
2785
+ method: "POST",
2786
+ path: _context37.t2,
2787
+ body: _context37.t3,
2788
+ allowFailover: false
2789
+ };
2790
+ return _context37.abrupt("return", _context37.t0.RequestJsonBody.call(_context37.t0, _context37.t4));
2791
+ case 15:
2792
+ case "end":
2793
+ return _context37.stop();
2794
+ }
2795
+ }, _callee36, this);
2796
+ }));
2797
+ return function (_x35) {
2798
+ return _ref67.apply(this, arguments);
2799
+ };
2800
+ }();
2801
+
2802
+ /**
2803
+ * Update content tags, replacing any existing tags
2804
+ *
2805
+ * @methodGroup Content Groups
2806
+ * @namedParams
2807
+ * @param {string} libraryId - ID of the library
2808
+ * @param {string} writeToken - Write token of the draft
2809
+ * @param {Array<string>} tags - Tags the object should have. Must be given explicitly - pass an empty
2810
+ * array to remove all tags
2811
+ *
2812
+ * @returns {Promise<Array<string>>} - The tags on the object after the update
2813
+ */
2814
+ exports.SetContentObjectTags = /*#__PURE__*/function () {
2815
+ var _ref69 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee37(_ref68) {
2816
+ var libraryId, writeToken, tags, path, objectId;
2817
+ return _regeneratorRuntime.wrap(function _callee37$(_context38) {
2818
+ while (1) switch (_context38.prev = _context38.next) {
2819
+ case 0:
2820
+ libraryId = _ref68.libraryId, writeToken = _ref68.writeToken, tags = _ref68.tags;
2821
+ ValidateLibrary(libraryId);
2822
+ ValidateWriteToken(writeToken);
2823
+ ValidateTags(tags);
2824
+ path = UrlJoin("qlibs", libraryId, "q", writeToken, "tags");
2825
+ objectId = this.utils.DecodeWriteToken(writeToken).objectId;
2826
+ this.Log("Updating tags: ".concat(Array.isArray(tags) ? tags.join(", ") : tags));
2827
+ _context38.t0 = this.HttpClient;
2828
+ _context38.next = 10;
2829
+ return this.authClient.AuthorizationHeader({
2830
+ libraryId: libraryId,
2831
+ objectId: objectId,
2832
+ update: true
2833
+ });
2834
+ case 10:
2835
+ _context38.t1 = _context38.sent;
2836
+ _context38.t2 = path;
2837
+ _context38.t3 = tags;
2838
+ _context38.t4 = {
2839
+ headers: _context38.t1,
2840
+ method: "PUT",
2841
+ path: _context38.t2,
2842
+ body: _context38.t3,
2843
+ allowFailover: false
2844
+ };
2845
+ return _context38.abrupt("return", _context38.t0.RequestJsonBody.call(_context38.t0, _context38.t4));
2846
+ case 15:
2847
+ case "end":
2848
+ return _context38.stop();
2849
+ }
2850
+ }, _callee37, this);
2851
+ }));
2852
+ return function (_x36) {
2853
+ return _ref69.apply(this, arguments);
2854
+ };
2855
+ }();
2856
+
2857
+ /**
2858
+ * Remove the given tags from a content object
2859
+ *
2860
+ * @methodGroup Content Groups
2861
+ * @namedParams
2862
+ * @param {string} libraryId - ID of the library
2863
+ * @param {string} writeToken - Write token of the draft
2864
+ * @param {Array<string>} tags - List of tags
2865
+ *
2866
+ * @returns {Promise<Array<string>>} - The tags on the object after the update
2867
+ */
2868
+ exports.RemoveContentObjectTags = /*#__PURE__*/function () {
2869
+ var _ref71 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee38(_ref70) {
2870
+ var libraryId, writeToken, _ref70$tags, tags, path, objectId;
2871
+ return _regeneratorRuntime.wrap(function _callee38$(_context39) {
2872
+ while (1) switch (_context39.prev = _context39.next) {
2873
+ case 0:
2874
+ libraryId = _ref70.libraryId, writeToken = _ref70.writeToken, _ref70$tags = _ref70.tags, tags = _ref70$tags === void 0 ? [] : _ref70$tags;
2875
+ ValidateLibrary(libraryId);
2876
+ ValidateWriteToken(writeToken);
2877
+ ValidatePresence("tags", tags);
2878
+ path = UrlJoin("qlibs", libraryId, "q", writeToken, "tags");
2879
+ objectId = this.utils.DecodeWriteToken(writeToken).objectId;
2880
+ this.Log("Removing tags: ".concat(tags.join(", ")));
2881
+ _context39.t0 = this.HttpClient;
2882
+ _context39.next = 10;
2883
+ return this.authClient.AuthorizationHeader({
2884
+ libraryId: libraryId,
2885
+ objectId: objectId,
2886
+ update: true
2887
+ });
2888
+ case 10:
2889
+ _context39.t1 = _context39.sent;
2890
+ _context39.t2 = path;
2891
+ _context39.t3 = tags;
2892
+ _context39.t4 = {
2893
+ headers: _context39.t1,
2894
+ method: "DELETE",
2895
+ path: _context39.t2,
2896
+ body: _context39.t3,
2897
+ allowFailover: false
2898
+ };
2899
+ return _context39.abrupt("return", _context39.t0.RequestJsonBody.call(_context39.t0, _context39.t4));
2900
+ case 15:
2901
+ case "end":
2902
+ return _context39.stop();
2903
+ }
2904
+ }, _callee38, this);
2905
+ }));
2906
+ return function (_x37) {
2907
+ return _ref71.apply(this, arguments);
2908
+ };
2909
+ }();
2910
+
2911
+ /**
2912
+ * Create content query fields
2913
+ *
2914
+ * @methodGroup Content Groups
2915
+ * @namedParams
2916
+ * @param {string} libraryId - ID of the library
2917
+ * @param {string} writeToken - Write token of the draft
2918
+ * @param {Object} queryFields - Query fields defined by key/value pairs for each field
2919
+ *
2920
+ * @returns {Promise<Object<string, string>>} - The query fields on the object after the update
2921
+ */
2922
+ exports.AddContentObjectQueryFields = /*#__PURE__*/function () {
2923
+ var _ref73 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee39(_ref72) {
2924
+ var libraryId, writeToken, queryFields, path, objectId;
2925
+ return _regeneratorRuntime.wrap(function _callee39$(_context40) {
2926
+ while (1) switch (_context40.prev = _context40.next) {
2927
+ case 0:
2928
+ libraryId = _ref72.libraryId, writeToken = _ref72.writeToken, queryFields = _ref72.queryFields;
2929
+ ValidateLibrary(libraryId);
2930
+ ValidateWriteToken(writeToken);
2931
+ ValidatePresence("queryFields", queryFields);
2932
+ path = UrlJoin("qlibs", libraryId, "q", writeToken, "query_fields");
2933
+ objectId = this.utils.DecodeWriteToken(writeToken).objectId;
2934
+ _context40.t0 = this.HttpClient;
2935
+ _context40.next = 9;
2936
+ return this.authClient.AuthorizationHeader({
2937
+ libraryId: libraryId,
2938
+ objectId: objectId,
2939
+ update: true
2940
+ });
2941
+ case 9:
2942
+ _context40.t1 = _context40.sent;
2943
+ _context40.t2 = path;
2944
+ _context40.t3 = queryFields;
2945
+ _context40.t4 = {
2946
+ headers: _context40.t1,
2947
+ method: "POST",
2948
+ path: _context40.t2,
2949
+ body: _context40.t3,
2950
+ allowFailover: false
2951
+ };
2952
+ return _context40.abrupt("return", _context40.t0.RequestJsonBody.call(_context40.t0, _context40.t4));
2953
+ case 14:
2954
+ case "end":
2955
+ return _context40.stop();
2956
+ }
2957
+ }, _callee39, this);
2958
+ }));
2959
+ return function (_x38) {
2960
+ return _ref73.apply(this, arguments);
2961
+ };
2962
+ }();
2963
+
2964
+ /**
2965
+ * Replace existing content query fields
2966
+ *
2967
+ * @methodGroup Content Groups
2968
+ * @namedParams
2969
+ * @param {string} libraryId - ID of the library
2970
+ * @param {string} writeToken - Write token of the draft
2971
+ * @param {Object<string, string>} queryFields - Query fields as key/value pairs. Must be given explicitly -
2972
+ * pass an empty object to remove all fields
2973
+ *
2974
+ * @returns {Promise<Object<string, string>>} - The query fields on the object after the update
2975
+ */
2976
+ exports.SetContentObjectQueryFields = /*#__PURE__*/function () {
2977
+ var _ref75 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee40(_ref74) {
2978
+ var libraryId, writeToken, queryFields, path, objectId;
2979
+ return _regeneratorRuntime.wrap(function _callee40$(_context41) {
2980
+ while (1) switch (_context41.prev = _context41.next) {
2981
+ case 0:
2982
+ libraryId = _ref74.libraryId, writeToken = _ref74.writeToken, queryFields = _ref74.queryFields;
2983
+ ValidateLibrary(libraryId);
2984
+ ValidateWriteToken(writeToken);
2985
+ ValidateQueryFields(queryFields);
2986
+ path = UrlJoin("qlibs", libraryId, "q", writeToken, "query_fields");
2987
+ objectId = this.utils.DecodeWriteToken(writeToken).objectId;
2988
+ _context41.t0 = this.HttpClient;
2989
+ _context41.next = 9;
2990
+ return this.authClient.AuthorizationHeader({
2991
+ libraryId: libraryId,
2992
+ objectId: objectId,
2993
+ update: true
2994
+ });
2995
+ case 9:
2996
+ _context41.t1 = _context41.sent;
2997
+ _context41.t2 = path;
2998
+ _context41.t3 = queryFields;
2999
+ _context41.t4 = {
3000
+ headers: _context41.t1,
3001
+ method: "PUT",
3002
+ path: _context41.t2,
3003
+ body: _context41.t3,
3004
+ allowFailover: false
3005
+ };
3006
+ return _context41.abrupt("return", _context41.t0.RequestJsonBody.call(_context41.t0, _context41.t4));
3007
+ case 14:
3008
+ case "end":
3009
+ return _context41.stop();
3010
+ }
3011
+ }, _callee40, this);
3012
+ }));
3013
+ return function (_x39) {
3014
+ return _ref75.apply(this, arguments);
3015
+ };
3016
+ }();
3017
+
3018
+ /**
3019
+ * Remove the given query fields from a content object
3020
+ *
3021
+ * @methodGroup Content Groups
3022
+ * @namedParams
3023
+ * @param {string} libraryId - ID of the library
3024
+ * @param {string} writeToken - Write token of the draft
3025
+ * @param {Array<string>} fieldNames - Names of the query fields to remove
3026
+ *
3027
+ * @returns {Promise<Object<string, string>>} - The query fields on the object after the update
3028
+ */
3029
+ exports.RemoveContentObjectQueryFields = /*#__PURE__*/function () {
3030
+ var _ref77 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee41(_ref76) {
3031
+ var libraryId, writeToken, _ref76$fieldNames, fieldNames, path, objectId;
3032
+ return _regeneratorRuntime.wrap(function _callee41$(_context42) {
3033
+ while (1) switch (_context42.prev = _context42.next) {
3034
+ case 0:
3035
+ libraryId = _ref76.libraryId, writeToken = _ref76.writeToken, _ref76$fieldNames = _ref76.fieldNames, fieldNames = _ref76$fieldNames === void 0 ? [] : _ref76$fieldNames;
3036
+ ValidateLibrary(libraryId);
3037
+ ValidateWriteToken(writeToken);
3038
+ ValidatePresence("fieldNames", fieldNames);
3039
+ path = UrlJoin("qlibs", libraryId, "q", writeToken, "query_fields");
3040
+ objectId = this.utils.DecodeWriteToken(writeToken).objectId;
3041
+ this.Log("Removing query fields: ".concat(fieldNames.join(", ")));
3042
+ _context42.t0 = this.HttpClient;
3043
+ _context42.next = 10;
3044
+ return this.authClient.AuthorizationHeader({
3045
+ libraryId: libraryId,
3046
+ objectId: objectId,
3047
+ update: true
3048
+ });
3049
+ case 10:
3050
+ _context42.t1 = _context42.sent;
3051
+ _context42.t2 = path;
3052
+ _context42.t3 = fieldNames;
3053
+ _context42.t4 = {
3054
+ headers: _context42.t1,
3055
+ method: "DELETE",
3056
+ path: _context42.t2,
3057
+ body: _context42.t3,
3058
+ allowFailover: false
3059
+ };
3060
+ return _context42.abrupt("return", _context42.t0.RequestJsonBody.call(_context42.t0, _context42.t4));
3061
+ case 15:
3062
+ case "end":
3063
+ return _context42.stop();
3064
+ }
3065
+ }, _callee41, this);
3066
+ }));
3067
+ return function (_x40) {
3068
+ return _ref77.apply(this, arguments);
3069
+ };
3070
+ }();
3071
+
3072
+ /**
3073
+ * Create a content group - a content object that other content objects can be associated with in order to
3074
+ * categorize them. Content groups are distinct from the access groups that grant permissions.
3075
+ *
3076
+ * The group is left as a draft; finalize it before adding content objects to it.
3077
+ *
3078
+ * @methodGroup Content Groups
3079
+ * @namedParams
3080
+ * @param {string} libraryId - ID of the library
3081
+ * @param {string=} name - Internal content management name of the group
3082
+ * @param {string=} displayTitle - Public-facing title of the group
3083
+ * @param {Array<string>=} tags - Fabric tags to associate with the group
3084
+ * @param {Object<string, string>=} queryFields - Unencrypted, indexed query fields to associate with the group,
3085
+ * as key/value pairs
3086
+ *
3087
+ * @returns {Promise<Object>} - Response containing the object ID and write token of the draft
3088
+ */
3089
+ exports.CreateContentGroup = /*#__PURE__*/function () {
3090
+ var _ref79 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee42(_ref78) {
3091
+ var libraryId, name, displayTitle, tags, queryFields, _yield$this$CreateCon2, objectId, writeToken;
3092
+ return _regeneratorRuntime.wrap(function _callee42$(_context43) {
3093
+ while (1) switch (_context43.prev = _context43.next) {
3094
+ case 0:
3095
+ libraryId = _ref78.libraryId, name = _ref78.name, displayTitle = _ref78.displayTitle, tags = _ref78.tags, queryFields = _ref78.queryFields;
3096
+ ValidateLibrary(libraryId);
3097
+ _context43.next = 4;
3098
+ return this.CreateContentObject({
3099
+ libraryId: libraryId,
3100
+ options: {
3101
+ objectType: "cgroup",
3102
+ meta: {
3103
+ "public": {
3104
+ name: name,
3105
+ asset_metadata: {
3106
+ display_title: displayTitle
3107
+ }
3108
+ }
3109
+ },
3110
+ tags: tags,
3111
+ queryFields: queryFields
3112
+ }
3113
+ });
3114
+ case 4:
3115
+ _yield$this$CreateCon2 = _context43.sent;
3116
+ objectId = _yield$this$CreateCon2.objectId;
3117
+ writeToken = _yield$this$CreateCon2.writeToken;
3118
+ this.Log("Created content group: ".concat(objectId));
3119
+ return _context43.abrupt("return", {
3120
+ objectId: objectId,
3121
+ writeToken: writeToken
3122
+ });
3123
+ case 9:
3124
+ case "end":
3125
+ return _context43.stop();
3126
+ }
3127
+ }, _callee42, this);
3128
+ }));
3129
+ return function (_x41) {
3130
+ return _ref79.apply(this, arguments);
3131
+ };
3132
+ }();
3133
+
3134
+ /**
3135
+ * Add a content object to the given content groups. Groups the object already belongs to are retained.
3136
+ *
3137
+ * @methodGroup Content Groups
3138
+ * @namedParams
3139
+ * @param {string} libraryId - ID of the library
3140
+ * @param {string} writeToken - Write token of the draft
3141
+ * @param {Array<string>} groups - IDs of the content groups to add the object to. An empty array is a no-op
3142
+ *
3143
+ * @returns {Promise<Array<string>>} - The groups the object belongs to after the update. Order is not preserved
3144
+ */
3145
+ exports.AddContentObjectGroups = /*#__PURE__*/function () {
3146
+ var _ref81 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee43(_ref80) {
3147
+ var libraryId, writeToken, _ref80$groups, groups, path, objectId;
3148
+ return _regeneratorRuntime.wrap(function _callee43$(_context44) {
3149
+ while (1) switch (_context44.prev = _context44.next) {
3150
+ case 0:
3151
+ libraryId = _ref80.libraryId, writeToken = _ref80.writeToken, _ref80$groups = _ref80.groups, groups = _ref80$groups === void 0 ? [] : _ref80$groups;
3152
+ ValidateLibrary(libraryId);
3153
+ ValidateWriteToken(writeToken);
3154
+ ValidateGroups(groups);
3155
+ path = UrlJoin("qlibs", libraryId, "q", writeToken, "groups");
3156
+ objectId = this.utils.DecodeWriteToken(writeToken).objectId;
3157
+ this.Log("Adding groups: ".concat(groups.join(", ")));
3158
+ _context44.t0 = this.HttpClient;
3159
+ _context44.next = 10;
3160
+ return this.authClient.AuthorizationHeader({
3161
+ libraryId: libraryId,
3162
+ objectId: objectId,
3163
+ update: true
3164
+ });
3165
+ case 10:
3166
+ _context44.t1 = _context44.sent;
3167
+ _context44.t2 = path;
3168
+ _context44.t3 = groups;
3169
+ _context44.t4 = {
3170
+ headers: _context44.t1,
3171
+ method: "POST",
3172
+ path: _context44.t2,
3173
+ body: _context44.t3,
3174
+ allowFailover: false
3175
+ };
3176
+ return _context44.abrupt("return", _context44.t0.RequestJsonBody.call(_context44.t0, _context44.t4));
3177
+ case 15:
3178
+ case "end":
3179
+ return _context44.stop();
3180
+ }
3181
+ }, _callee43, this);
3182
+ }));
3183
+ return function (_x42) {
3184
+ return _ref81.apply(this, arguments);
3185
+ };
3186
+ }();
3187
+
3188
+ /**
3189
+ * Set the content groups a content object belongs to, replacing any existing groups.
3190
+ *
3191
+ * @methodGroup Content Groups
3192
+ * @namedParams
3193
+ * @param {string} libraryId - ID of the library
3194
+ * @param {string} writeToken - Write token of the draft
3195
+ * @param {Array<string>} groups - IDs of the content groups the object should belong to. Must be given
3196
+ * explicitly - pass an empty array to remove the object from all groups
3197
+ *
3198
+ * @returns {Promise<Array<string>>} - The groups the object belongs to after the update. Order is not preserved
3199
+ */
3200
+ exports.SetContentObjectGroups = /*#__PURE__*/function () {
3201
+ var _ref83 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee44(_ref82) {
3202
+ var libraryId, writeToken, groups, path, objectId;
3203
+ return _regeneratorRuntime.wrap(function _callee44$(_context45) {
3204
+ while (1) switch (_context45.prev = _context45.next) {
3205
+ case 0:
3206
+ libraryId = _ref82.libraryId, writeToken = _ref82.writeToken, groups = _ref82.groups;
3207
+ ValidateLibrary(libraryId);
3208
+ ValidateWriteToken(writeToken);
3209
+ ValidateGroups(groups);
3210
+ path = UrlJoin("qlibs", libraryId, "q", writeToken, "groups");
3211
+ objectId = this.utils.DecodeWriteToken(writeToken).objectId;
3212
+ this.Log("Setting groups: ".concat(groups.join(", ")));
3213
+ _context45.t0 = this.HttpClient;
3214
+ _context45.next = 10;
3215
+ return this.authClient.AuthorizationHeader({
3216
+ libraryId: libraryId,
3217
+ objectId: objectId,
3218
+ update: true
3219
+ });
3220
+ case 10:
3221
+ _context45.t1 = _context45.sent;
3222
+ _context45.t2 = path;
3223
+ _context45.t3 = groups;
3224
+ _context45.t4 = {
3225
+ headers: _context45.t1,
3226
+ method: "PUT",
3227
+ path: _context45.t2,
3228
+ body: _context45.t3,
3229
+ allowFailover: false
3230
+ };
3231
+ return _context45.abrupt("return", _context45.t0.RequestJsonBody.call(_context45.t0, _context45.t4));
3232
+ case 15:
3233
+ case "end":
3234
+ return _context45.stop();
3235
+ }
3236
+ }, _callee44, this);
3237
+ }));
3238
+ return function (_x43) {
3239
+ return _ref83.apply(this, arguments);
3240
+ };
3241
+ }();
3242
+
3243
+ /**
3244
+ * Remove a content object from the given content groups. Groups not listed are retained, and
3245
+ * removing a group the object does not belong to is a no-op.
3246
+ *
3247
+ * @methodGroup Content Groups
3248
+ * @namedParams
3249
+ * @param {string} libraryId - ID of the library
3250
+ * @param {string} writeToken - Write token of the draft
3251
+ * @param {Array<string>} groups - IDs of the content groups to remove the object from. An empty array is a no-op
3252
+ *
3253
+ * @returns {Promise<Array<string>>} - The groups the object belongs to after the update. Order is not preserved
3254
+ */
3255
+ exports.RemoveContentObjectGroups = /*#__PURE__*/function () {
3256
+ var _ref85 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee45(_ref84) {
3257
+ var libraryId, writeToken, _ref84$groups, groups, path, objectId;
3258
+ return _regeneratorRuntime.wrap(function _callee45$(_context46) {
3259
+ while (1) switch (_context46.prev = _context46.next) {
3260
+ case 0:
3261
+ libraryId = _ref84.libraryId, writeToken = _ref84.writeToken, _ref84$groups = _ref84.groups, groups = _ref84$groups === void 0 ? [] : _ref84$groups;
3262
+ ValidateLibrary(libraryId);
3263
+ ValidateWriteToken(writeToken);
3264
+ ValidateGroups(groups);
3265
+ path = UrlJoin("qlibs", libraryId, "q", writeToken, "groups");
3266
+ objectId = this.utils.DecodeWriteToken(writeToken).objectId;
3267
+ this.Log("Removing groups: ".concat(groups.join(", ")));
3268
+ _context46.t0 = this.HttpClient;
3269
+ _context46.next = 10;
3270
+ return this.authClient.AuthorizationHeader({
3271
+ libraryId: libraryId,
3272
+ objectId: objectId,
3273
+ update: true
3274
+ });
3275
+ case 10:
3276
+ _context46.t1 = _context46.sent;
3277
+ _context46.t2 = path;
3278
+ _context46.t3 = groups;
3279
+ _context46.t4 = {
3280
+ headers: _context46.t1,
3281
+ method: "DELETE",
3282
+ path: _context46.t2,
3283
+ body: _context46.t3,
3284
+ allowFailover: false
3285
+ };
3286
+ return _context46.abrupt("return", _context46.t0.RequestJsonBody.call(_context46.t0, _context46.t4));
3287
+ case 15:
3288
+ case "end":
3289
+ return _context46.stop();
3290
+ }
3291
+ }, _callee45, this);
3292
+ }));
3293
+ return function (_x44) {
3294
+ return _ref85.apply(this, arguments);
3295
+ };
2696
3296
  }();