@esri/hub-common 9.38.0 → 9.41.0

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 (116) hide show
  1. package/dist/es2017/content/_internal.js +83 -0
  2. package/dist/es2017/content/_internal.js.map +1 -1
  3. package/dist/es2017/content/compose.js +7 -11
  4. package/dist/es2017/content/compose.js.map +1 -1
  5. package/dist/es2017/core/types/IHubContent.js +7 -0
  6. package/dist/es2017/core/types/IHubContent.js.map +1 -1
  7. package/dist/es2017/index.js +2 -0
  8. package/dist/es2017/index.js.map +1 -1
  9. package/dist/es2017/items/_enrichments.js +21 -0
  10. package/dist/es2017/items/_enrichments.js.map +1 -1
  11. package/dist/es2017/org/fetch-org.js +21 -0
  12. package/dist/es2017/org/fetch-org.js.map +1 -0
  13. package/dist/es2017/org/index.js +2 -0
  14. package/dist/es2017/org/index.js.map +1 -0
  15. package/dist/es2017/search/_internal/portalSearchGroups.js.map +1 -1
  16. package/dist/es2017/search/_internal/portalSearchUsers.js +89 -0
  17. package/dist/es2017/search/_internal/portalSearchUsers.js.map +1 -0
  18. package/dist/es2017/search/collectionState.js +1 -1
  19. package/dist/es2017/search/collectionState.js.map +1 -1
  20. package/dist/es2017/search/convertCatalog.js +14 -5
  21. package/dist/es2017/search/convertCatalog.js.map +1 -1
  22. package/dist/es2017/search/hubSearch.js +4 -1
  23. package/dist/es2017/search/hubSearch.js.map +1 -1
  24. package/dist/es2017/urls/getUserHomeUrl.js +12 -0
  25. package/dist/es2017/urls/getUserHomeUrl.js.map +1 -0
  26. package/dist/es2017/urls/index.js +1 -0
  27. package/dist/es2017/urls/index.js.map +1 -1
  28. package/dist/es2017/users/HubUsers.js +64 -0
  29. package/dist/es2017/users/HubUsers.js.map +1 -0
  30. package/dist/es2017/users/_internal/enrichments.js +85 -0
  31. package/dist/es2017/users/_internal/enrichments.js.map +1 -0
  32. package/dist/es2017/users/index.js +2 -0
  33. package/dist/es2017/users/index.js.map +1 -0
  34. package/dist/esm/content/_internal.js +85 -0
  35. package/dist/esm/content/_internal.js.map +1 -1
  36. package/dist/esm/content/compose.js +5 -11
  37. package/dist/esm/content/compose.js.map +1 -1
  38. package/dist/esm/core/types/IHubContent.js +7 -0
  39. package/dist/esm/core/types/IHubContent.js.map +1 -1
  40. package/dist/esm/index.js +2 -0
  41. package/dist/esm/index.js.map +1 -1
  42. package/dist/esm/items/_enrichments.js +21 -0
  43. package/dist/esm/items/_enrichments.js.map +1 -1
  44. package/dist/esm/org/fetch-org.js +22 -0
  45. package/dist/esm/org/fetch-org.js.map +1 -0
  46. package/dist/esm/org/index.js +2 -0
  47. package/dist/esm/org/index.js.map +1 -0
  48. package/dist/esm/search/_internal/portalSearchGroups.js.map +1 -1
  49. package/dist/esm/search/_internal/portalSearchUsers.js +104 -0
  50. package/dist/esm/search/_internal/portalSearchUsers.js.map +1 -0
  51. package/dist/esm/search/collectionState.js +1 -1
  52. package/dist/esm/search/collectionState.js.map +1 -1
  53. package/dist/esm/search/convertCatalog.js +14 -5
  54. package/dist/esm/search/convertCatalog.js.map +1 -1
  55. package/dist/esm/search/hubSearch.js +4 -1
  56. package/dist/esm/search/hubSearch.js.map +1 -1
  57. package/dist/esm/urls/getUserHomeUrl.js +12 -0
  58. package/dist/esm/urls/getUserHomeUrl.js.map +1 -0
  59. package/dist/esm/urls/index.js +1 -0
  60. package/dist/esm/urls/index.js.map +1 -1
  61. package/dist/esm/users/HubUsers.js +66 -0
  62. package/dist/esm/users/HubUsers.js.map +1 -0
  63. package/dist/esm/users/_internal/enrichments.js +86 -0
  64. package/dist/esm/users/_internal/enrichments.js.map +1 -0
  65. package/dist/esm/users/index.js +2 -0
  66. package/dist/esm/users/index.js.map +1 -0
  67. package/dist/node/content/_internal.js +84 -1
  68. package/dist/node/content/_internal.js.map +1 -1
  69. package/dist/node/content/compose.js +6 -10
  70. package/dist/node/content/compose.js.map +1 -1
  71. package/dist/node/core/types/IHubContent.js +8 -0
  72. package/dist/node/core/types/IHubContent.js.map +1 -1
  73. package/dist/node/index.js +2 -0
  74. package/dist/node/index.js.map +1 -1
  75. package/dist/node/items/_enrichments.js +21 -0
  76. package/dist/node/items/_enrichments.js.map +1 -1
  77. package/dist/node/org/fetch-org.js +24 -0
  78. package/dist/node/org/fetch-org.js.map +1 -0
  79. package/dist/node/org/index.js +5 -0
  80. package/dist/node/org/index.js.map +1 -0
  81. package/dist/node/search/_internal/portalSearchGroups.js.map +1 -1
  82. package/dist/node/search/_internal/portalSearchUsers.js +93 -0
  83. package/dist/node/search/_internal/portalSearchUsers.js.map +1 -0
  84. package/dist/node/search/collectionState.js +1 -1
  85. package/dist/node/search/collectionState.js.map +1 -1
  86. package/dist/node/search/convertCatalog.js +14 -5
  87. package/dist/node/search/convertCatalog.js.map +1 -1
  88. package/dist/node/search/hubSearch.js +4 -1
  89. package/dist/node/search/hubSearch.js.map +1 -1
  90. package/dist/node/urls/getUserHomeUrl.js +16 -0
  91. package/dist/node/urls/getUserHomeUrl.js.map +1 -0
  92. package/dist/node/urls/index.js +1 -0
  93. package/dist/node/urls/index.js.map +1 -1
  94. package/dist/node/users/HubUsers.js +68 -0
  95. package/dist/node/users/HubUsers.js.map +1 -0
  96. package/dist/node/users/_internal/enrichments.js +89 -0
  97. package/dist/node/users/_internal/enrichments.js.map +1 -0
  98. package/dist/node/users/index.js +5 -0
  99. package/dist/node/users/index.js.map +1 -0
  100. package/dist/types/content/_internal.d.ts +54 -5
  101. package/dist/types/core/types/IHubContent.d.ts +21 -0
  102. package/dist/types/index.d.ts +2 -0
  103. package/dist/types/org/fetch-org.d.ts +9 -0
  104. package/dist/types/org/index.d.ts +1 -0
  105. package/dist/types/search/_internal/portalSearchUsers.d.ts +8 -0
  106. package/dist/types/search/types/ICatalog.d.ts +14 -3
  107. package/dist/types/search/types/ICollection.d.ts +9 -3
  108. package/dist/types/search/types/types.d.ts +17 -1
  109. package/dist/types/urls/getUserHomeUrl.d.ts +10 -0
  110. package/dist/types/urls/index.d.ts +1 -0
  111. package/dist/types/users/HubUsers.d.ts +11 -0
  112. package/dist/types/users/_internal/enrichments.d.ts +28 -0
  113. package/dist/types/users/index.d.ts +1 -0
  114. package/dist/umd/common.umd.js +422 -38
  115. package/dist/umd/common.umd.js.map +1 -1
  116. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * @esri/hub-common - v9.37.0 - Thu Jun 02 2022 20:53:16 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/hub-common - v9.40.0 - Fri Jun 10 2022 19:52:59 GMT+0000 (Coordinated Universal Time)
3
3
  * Copyright (c) 2022 Environmental Systems Research Institute, Inc.
4
4
  * Apache-2.0
5
5
  */
@@ -5444,6 +5444,17 @@
5444
5444
  return portalUrl + "/home/group.html?id=" + groupId;
5445
5445
  }
5446
5446
 
5447
+ /**
5448
+ * Return the URL of the user's page in the Portal Home application
5449
+ * @param username The username
5450
+ * @param portalUrlOrObject a portal base or API URL, a portal object, or request options containing either of those
5451
+ * @returns URL to the user's profile, defaults to `https://www.arcgis.com/home/user.html?user={username}`
5452
+ */
5453
+ function getUserHomeUrl(username, portalUrlOrObject) {
5454
+ var portalUrl = getPortalUrl(portalUrlOrObject);
5455
+ return portalUrl + "/home/user.html?user=" + username;
5456
+ }
5457
+
5447
5458
  var MAP_OR_FEATURE_SERVER_URL_REGEX = /\/(map|feature)server/i;
5448
5459
  /**
5449
5460
  *
@@ -6434,6 +6445,14 @@
6434
6445
  return request(cleanUrl(options.url), options);
6435
6446
  }
6436
6447
 
6448
+ exports.PublisherSource = void 0;
6449
+ (function (PublisherSource) {
6450
+ PublisherSource["CitationContact"] = "metadata.resource.citation.contact";
6451
+ PublisherSource["ResourceContact"] = "metadata.resource.contact";
6452
+ PublisherSource["ItemOwner"] = "item.owner";
6453
+ PublisherSource["None"] = "none";
6454
+ })(exports.PublisherSource || (exports.PublisherSource = {}));
6455
+
6437
6456
  /**
6438
6457
  * Turns an bounding box coordinate array into an extent object
6439
6458
  * @param bBox bounding box coordinate array
@@ -7012,6 +7031,90 @@
7012
7031
  : undefined;
7013
7032
  return itemExtent || extentEnrichmentCoordinates || layerExtent;
7014
7033
  };
7034
+ /**
7035
+ * @private
7036
+ *
7037
+ * Extracts the first contact from a given formal item metadata path.
7038
+ * This is particularly helpful if the contact path is either an object or an array.
7039
+ *
7040
+ * Note: the raw contact object must have the following properties:
7041
+ * - `rpIndName`: name of the individual
7042
+ * - `rpOrgName`: name of the individual's organization
7043
+ *
7044
+ * @param metadata formal item metadata
7045
+ * @param path path to the contact object/array
7046
+ * @returns
7047
+ */
7048
+ var extractFirstContact = function (metadata, path) {
7049
+ var rawContacts = getProp(metadata, path) || {};
7050
+ var _a = Array.isArray(rawContacts)
7051
+ ? rawContacts[0]
7052
+ : rawContacts, rpIndName = _a.rpIndName, rpOrgName = _a.rpOrgName;
7053
+ return { individualName: rpIndName, organizationName: rpOrgName };
7054
+ };
7055
+ /**
7056
+ * Determines the correct orgId for an item.
7057
+ * Note: it's undocumented, but the portal API will return orgId for items... sometimes.
7058
+ *
7059
+ * @param item
7060
+ * @param ownerUser item owner's hydrated user object
7061
+ */
7062
+ var getItemOrgId = function (item, ownerUser) {
7063
+ return item.orgId || (ownerUser === null || ownerUser === void 0 ? void 0 : ownerUser.orgId);
7064
+ };
7065
+ /**
7066
+ * Calculates the Publisher display info for the given item.
7067
+ * Utilizes this fallback pattern:
7068
+ * 1) Formal Item Metadata > Resource > Citation > Contact
7069
+ * 2) Formal Item Metadata > Resource > Contact
7070
+ * 3) Item’s Owner and Org Name
7071
+ * 4) Undefined (Item Owner / Org are private and we can't access additional info)
7072
+ *
7073
+ * @param item
7074
+ * @param metadata
7075
+ * @param org portal info of the item's organization
7076
+ * @param ownerUser the item owner's hydrated user
7077
+ * @returns
7078
+ */
7079
+ var getPublisherInfo = function (item, metadata, org, ownerUser) {
7080
+ var result = {
7081
+ nameSource: exports.PublisherSource.None,
7082
+ organizationSource: exports.PublisherSource.None,
7083
+ };
7084
+ var citationContact = extractFirstContact(metadata, "metadata.dataIdInfo.idCitation.citRespParty");
7085
+ var resourceContact = extractFirstContact(metadata, "metadata.mdContact");
7086
+ // Determine publisher name properties
7087
+ var ownerFullName = getProp(ownerUser, "fullName");
7088
+ if (citationContact.individualName) {
7089
+ result.name = citationContact.individualName;
7090
+ result.nameSource = exports.PublisherSource.CitationContact;
7091
+ }
7092
+ else if (resourceContact.individualName) {
7093
+ result.name = resourceContact.individualName;
7094
+ result.nameSource = exports.PublisherSource.ResourceContact;
7095
+ }
7096
+ else if (ownerFullName) {
7097
+ result.name = ownerFullName;
7098
+ result.username = ownerUser.username;
7099
+ result.nameSource = exports.PublisherSource.ItemOwner;
7100
+ }
7101
+ // Determine publisher org properties
7102
+ var orgName = getProp(org, "name");
7103
+ if (citationContact.organizationName) {
7104
+ result.organization = citationContact.organizationName;
7105
+ result.organizationSource = exports.PublisherSource.CitationContact;
7106
+ }
7107
+ else if (resourceContact.organizationName) {
7108
+ result.organization = resourceContact.organizationName;
7109
+ result.organizationSource = exports.PublisherSource.ResourceContact;
7110
+ }
7111
+ else if (orgName) {
7112
+ result.organization = orgName;
7113
+ result.orgId = getItemOrgId(item, ownerUser);
7114
+ result.organizationSource = exports.PublisherSource.ItemOwner;
7115
+ }
7116
+ return result;
7117
+ };
7015
7118
 
7016
7119
  var STANDARD_LICENSES = [
7017
7120
  {
@@ -7919,13 +8022,8 @@
7919
8022
  get metadataUpdateFrequency() {
7920
8023
  return getUpdateFrequencyFromMetadata(metadata, "metadataUpdateFrequency");
7921
8024
  },
7922
- // TODO: add the publisher logic outlined here:
7923
- // https://devtopia.esri.com/dc/hub/issues/2932#issuecomment-3276309
7924
8025
  get publisher() {
7925
- return {
7926
- name: item.owner,
7927
- username: item.owner,
7928
- };
8026
+ return getPublisherInfo(item, metadata, org, ownerUser);
7929
8027
  },
7930
8028
  // TODO: is metrics in use?
7931
8029
  get metrics() {
@@ -7945,11 +8043,10 @@
7945
8043
  Array.isArray(data.layers) &&
7946
8044
  data.layers.find(function (_layer) { return _layer.id === layer.id; });
7947
8045
  return dataLayer ? dataLayer.layerDefinition : undefined;
8046
+ }, get orgId() {
8047
+ return org ? org.id : getItemOrgId(item, ownerUser);
7948
8048
  },
7949
- get orgId() {
7950
- // NOTE: it's undocumented, but the portal API will return orgId for items... sometimes
7951
- return org ? org.id : item.orgId || (ownerUser === null || ownerUser === void 0 ? void 0 : ownerUser.orgId);
7952
- }, get contentTypeIcon() {
8049
+ get contentTypeIcon() {
7953
8050
  /* Note: only returns calcite-icons */
7954
8051
  return getContentTypeIcon(type);
7955
8052
  },
@@ -9882,6 +9979,24 @@
9882
9979
  };
9883
9980
  });
9884
9981
 
9982
+ /**
9983
+ * Fetches the portal for a given org.
9984
+ *
9985
+ * @param orgId
9986
+ * @param options request options
9987
+ * @returns
9988
+ */
9989
+ var fetchOrg = function (orgId, options) {
9990
+ var orgPortalUrl = getProp(options, "portal") ||
9991
+ getProp(options, "authentication.portal") ||
9992
+ "www.arcgis.com";
9993
+ // In order to get the correct response, we must pass options.portal
9994
+ // as a base portal url (e.g., www.arcgis.com, qaext.arcgis.com, etc)
9995
+ // **not** an org portal (i.e. org.maps.arcgis.com).
9996
+ var basePortalUrl = getPortalBaseFromOrgUrl(orgPortalUrl) + "/sharing/rest";
9997
+ return getPortal(orgId, __assign(__assign({}, options), { portal: basePortalUrl }));
9998
+ };
9999
+
9885
10000
  /**
9886
10001
  * Parse metadataxml into json object
9887
10002
  * @param metadataXml
@@ -9928,7 +10043,7 @@
9928
10043
  requestOptions: requestOptions,
9929
10044
  };
9930
10045
  })
9931
- .catch(function (error) { return handleEnrichmentError$1(error, input, opId); });
10046
+ .catch(function (error) { return handleEnrichmentError$2(error, input, opId); });
9932
10047
  };
9933
10048
  var enrichMetadata = function (input) {
9934
10049
  var data = input.data, stack = input.stack, requestOptions = input.requestOptions;
@@ -9960,7 +10075,25 @@
9960
10075
  requestOptions: requestOptions,
9961
10076
  };
9962
10077
  })
9963
- .catch(function (error) { return handleEnrichmentError$1(error, input, opId); });
10078
+ .catch(function (error) { return handleEnrichmentError$2(error, input, opId); });
10079
+ };
10080
+ // Note, this MUST be run after `enrichOwnerUser` to access the correct orgId during
10081
+ // processing. `item.orgId` is only SOMETIMES returned by Portal, so we need to have
10082
+ // the ownerUser's orgId as a backup.
10083
+ var enrichOrg = function (input) {
10084
+ var data = input.data, stack = input.stack, requestOptions = input.requestOptions;
10085
+ var opId = stack.start("enrichOrg");
10086
+ var orgId = getItemOrgId(data.item, data.ownerUser);
10087
+ return fetchOrg(orgId, requestOptions)
10088
+ .then(function (org) {
10089
+ stack.finish(opId);
10090
+ return {
10091
+ data: __assign(__assign({}, data), { org: org }),
10092
+ stack: stack,
10093
+ requestOptions: requestOptions,
10094
+ };
10095
+ })
10096
+ .catch(function (error) { return handleEnrichmentError$2(error, input, opId); });
9964
10097
  };
9965
10098
  var enrichData = function (input) {
9966
10099
  var data = input.data, stack = input.stack, requestOptions = input.requestOptions;
@@ -9970,7 +10103,7 @@
9970
10103
  stack.finish(opId);
9971
10104
  return { data: __assign(__assign({}, data), { data: itemData }), stack: stack, requestOptions: requestOptions };
9972
10105
  })
9973
- .catch(function (error) { return handleEnrichmentError$1(error, input, opId); });
10106
+ .catch(function (error) { return handleEnrichmentError$2(error, input, opId); });
9974
10107
  };
9975
10108
  var enrichServer = function (input) {
9976
10109
  var data = input.data, stack = input.stack, requestOptions = input.requestOptions;
@@ -9982,7 +10115,7 @@
9982
10115
  stack.finish(opId);
9983
10116
  return { data: __assign(__assign({}, data), { server: server }), stack: stack, requestOptions: requestOptions };
9984
10117
  })
9985
- .catch(function (error) { return handleEnrichmentError$1(error, input, opId); });
10118
+ .catch(function (error) { return handleEnrichmentError$2(error, input, opId); });
9986
10119
  };
9987
10120
  var enrichLayers = function (input) {
9988
10121
  var data = input.data, stack = input.stack, requestOptions = input.requestOptions;
@@ -10000,12 +10133,12 @@
10000
10133
  stack.finish(opId);
10001
10134
  return { data: __assign(__assign({}, data), { layers: layers }), stack: stack, requestOptions: requestOptions };
10002
10135
  })
10003
- .catch(function (error) { return handleEnrichmentError$1(error, input, opId); }));
10136
+ .catch(function (error) { return handleEnrichmentError$2(error, input, opId); }));
10004
10137
  };
10005
10138
  // add the error to the content.errors,
10006
10139
  // log current stack operation as finished with an error
10007
10140
  // and return output that can be piped into the next operation
10008
- var handleEnrichmentError$1 = function (error, input, opId) {
10141
+ var handleEnrichmentError$2 = function (error, input, opId) {
10009
10142
  var data = input.data, stack = input.stack, requestOptions = input.requestOptions;
10010
10143
  stack.finish(opId, { error: error });
10011
10144
  return {
@@ -10018,6 +10151,7 @@
10018
10151
  groupIds: enrichGroupIds,
10019
10152
  metadata: enrichMetadata,
10020
10153
  ownerUser: enrichOwnerUser,
10154
+ org: enrichOrg,
10021
10155
  data: enrichData,
10022
10156
  server: enrichServer,
10023
10157
  layers: enrichLayers,
@@ -13099,7 +13233,7 @@
13099
13233
  requestOptions: requestOptions,
13100
13234
  };
13101
13235
  })
13102
- .catch(function (error) { return handleEnrichmentError(error, input, opId); });
13236
+ .catch(function (error) { return handleEnrichmentError$1(error, input, opId); });
13103
13237
  };
13104
13238
  /**
13105
13239
  * Create a summary of the Group membership by searching for members,
@@ -13124,12 +13258,12 @@
13124
13258
  requestOptions: requestOptions,
13125
13259
  };
13126
13260
  })
13127
- .catch(function (error) { return handleEnrichmentError(error, input, opId); });
13261
+ .catch(function (error) { return handleEnrichmentError$1(error, input, opId); });
13128
13262
  };
13129
13263
  // add the error to the content.errors,
13130
13264
  // log current stack operation as finished with an error
13131
13265
  // and return output that can be piped into the next operation
13132
- var handleEnrichmentError = function (error, input, opId) {
13266
+ var handleEnrichmentError$1 = function (error, input, opId) {
13133
13267
  var data = input.data, stack = input.stack, requestOptions = input.requestOptions;
13134
13268
  stack.finish(opId, { error: error });
13135
13269
  return {
@@ -13141,7 +13275,7 @@
13141
13275
  /**
13142
13276
  * Available enrichments for Groups
13143
13277
  */
13144
- var groupEnrichementOperations = {
13278
+ var groupEnrichementOperations$1 = {
13145
13279
  membershipSummary: enrichGroupMembershipSummary,
13146
13280
  contentCount: enrichGroupContentCount,
13147
13281
  };
@@ -13155,7 +13289,7 @@
13155
13289
  function fetchGroupEnrichments(group, enrichments, requestOptions) {
13156
13290
  // create a pipeline of enrichment operations
13157
13291
  var operations = enrichments.reduce(function (ops, enrichment) {
13158
- var operation = groupEnrichementOperations[enrichment];
13292
+ var operation = groupEnrichementOperations$1[enrichment];
13159
13293
  // only include the enrichments that we know how to fetch
13160
13294
  operation && ops.push(operation);
13161
13295
  return ops;
@@ -14371,7 +14505,7 @@
14371
14505
  so_1.countFields = options.aggFields.join(",");
14372
14506
  so_1.countSize = options.aggLimit || 10;
14373
14507
  }
14374
- searchPromise = searchPortal$2(so_1);
14508
+ searchPromise = searchPortal$3(so_1);
14375
14509
  }
14376
14510
  else {
14377
14511
  // Hub API Search
@@ -14399,7 +14533,7 @@
14399
14533
  * @param site
14400
14534
  * @returns
14401
14535
  */
14402
- function searchPortal$2(searchOptions) {
14536
+ function searchPortal$3(searchOptions) {
14403
14537
  var _a;
14404
14538
  var portalUrl = ((_a = searchOptions.authentication) === null || _a === void 0 ? void 0 : _a.portal) || searchOptions.portal;
14405
14539
  var token;
@@ -14430,7 +14564,7 @@
14430
14564
  results: content,
14431
14565
  facets: facets,
14432
14566
  hasNext: hasNext,
14433
- next: getNextFunction(searchOptions, resp.nextStart, resp.total, searchPortal$2),
14567
+ next: getNextFunction(searchOptions, resp.nextStart, resp.total, searchPortal$3),
14434
14568
  };
14435
14569
  });
14436
14570
  }
@@ -14788,7 +14922,7 @@
14788
14922
  if (collection.sortOption) {
14789
14923
  state.sort = serializeSortState(collection.sortOption);
14790
14924
  }
14791
- var facetState = collection.facets.reduce(function (s, facet) {
14925
+ var facetState = (collection.facets || []).reduce(function (s, facet) {
14792
14926
  return __assign(__assign({}, s), serializeFacetState(facet));
14793
14927
  }, {});
14794
14928
  return __assign(__assign({}, state), facetState);
@@ -14799,19 +14933,28 @@
14799
14933
  * @param original
14800
14934
  */
14801
14935
  function convertCatalog(original) {
14802
- var filter = {
14803
- filterType: "content",
14936
+ var filterGroup = {
14937
+ filterType: "item",
14938
+ operation: "OR",
14939
+ filters: [],
14804
14940
  };
14805
14941
  var groups = getProp(original, "groups");
14806
14942
  if (Array.isArray(groups) && groups.length) {
14807
- filter.group = groups;
14943
+ filterGroup.filters.push({
14944
+ filterType: "item",
14945
+ group: groups,
14946
+ });
14808
14947
  }
14809
14948
  else if (typeof groups === "string") {
14810
- filter.group = [groups];
14949
+ filterGroup.filters.push({
14950
+ filterType: "item",
14951
+ group: [groups],
14952
+ });
14811
14953
  }
14812
14954
  var catalog = {
14813
14955
  title: "Default Catalog",
14814
- filter: filter,
14956
+ scope: [filterGroup],
14957
+ collections: [],
14815
14958
  };
14816
14959
  return catalog;
14817
14960
  }
@@ -17671,7 +17814,7 @@
17671
17814
  so.countFields = options.aggFields.join(",");
17672
17815
  so.countSize = options.aggLimit || 10;
17673
17816
  }
17674
- return [2 /*return*/, searchPortal$1(so)];
17817
+ return [2 /*return*/, searchPortal$2(so)];
17675
17818
  });
17676
17819
  });
17677
17820
  }
@@ -17682,7 +17825,7 @@
17682
17825
  * @param searchOptions
17683
17826
  * @returns
17684
17827
  */
17685
- function searchPortal$1(searchOptions) {
17828
+ function searchPortal$2(searchOptions) {
17686
17829
  return __awaiter(this, void 0, void 0, function () {
17687
17830
  var resp, fn, results, facets;
17688
17831
  return __generator(this, function (_a) {
@@ -17703,7 +17846,7 @@
17703
17846
  results: results,
17704
17847
  facets: facets,
17705
17848
  hasNext: resp.nextStart > -1,
17706
- next: getNextFunction(searchOptions, resp.nextStart, resp.total, searchPortal$1),
17849
+ next: getNextFunction(searchOptions, resp.nextStart, resp.total, searchPortal$2),
17707
17850
  }];
17708
17851
  }
17709
17852
  });
@@ -17991,7 +18134,7 @@
17991
18134
  if (!so.authentication) {
17992
18135
  so.portal = so.requestOptions.portal || api.url + "/sharing/rest";
17993
18136
  }
17994
- return [2 /*return*/, searchPortal(so)];
18137
+ return [2 /*return*/, searchPortal$1(so)];
17995
18138
  });
17996
18139
  });
17997
18140
  }
@@ -18002,7 +18145,7 @@
18002
18145
  * @param searchOptions
18003
18146
  * @returns
18004
18147
  */
18005
- function searchPortal(searchOptions) {
18148
+ function searchPortal$1(searchOptions) {
18006
18149
  return __awaiter(this, void 0, void 0, function () {
18007
18150
  var resp, fn, results;
18008
18151
  return __generator(this, function (_a) {
@@ -18023,7 +18166,7 @@
18023
18166
  results: results,
18024
18167
  facets: [],
18025
18168
  hasNext: resp.nextStart > -1,
18026
- next: getNextFunction(searchOptions, resp.nextStart, resp.total, searchPortal),
18169
+ next: getNextFunction(searchOptions, resp.nextStart, resp.total, searchPortal$1),
18027
18170
  }];
18028
18171
  }
18029
18172
  });
@@ -18050,6 +18193,104 @@
18050
18193
  });
18051
18194
  }
18052
18195
 
18196
+ /**
18197
+ * @private
18198
+ * Portal Search implementation for Users
18199
+ * @param filterGroups
18200
+ * @param options
18201
+ */
18202
+ function portalSearchUsers(filterGroups, options) {
18203
+ return __awaiter(this, void 0, void 0, function () {
18204
+ var expandedGroups, so, props;
18205
+ return __generator(this, function (_a) {
18206
+ // requestOptions is always required and user must be authd
18207
+ if (!options.requestOptions) {
18208
+ throw new HubError$1("portalSearchUsers", "requestOptions: IHubRequestOptions is required.");
18209
+ }
18210
+ if (!options.requestOptions.authentication) {
18211
+ throw new HubError$1("portalSearchUsers", "requestOptions must pass authentication.");
18212
+ }
18213
+ expandedGroups = filterGroups.map(function (fg) {
18214
+ fg.filters = fg.filters.map(expandFilter);
18215
+ return fg;
18216
+ });
18217
+ so = serializeFilterGroupsForPortal(expandedGroups);
18218
+ props = [
18219
+ "num",
18220
+ "sortField",
18221
+ "sortOrder",
18222
+ "include",
18223
+ "start",
18224
+ "requestOptions",
18225
+ ];
18226
+ // copy the props over
18227
+ props.forEach(function (prop) {
18228
+ if (options.hasOwnProperty(prop)) {
18229
+ so[prop] = options[prop];
18230
+ }
18231
+ });
18232
+ // Ensure authentication gets sent
18233
+ so.authentication = options.requestOptions.authentication;
18234
+ // Execute search
18235
+ return [2 /*return*/, searchPortal(so)];
18236
+ });
18237
+ });
18238
+ }
18239
+ /**
18240
+ * Internal portal search, which then converts `IGroup`s to `IHubSearchResult`s
18241
+ * handling enrichments & includes along the way
18242
+ *
18243
+ * @param searchOptions
18244
+ * @returns
18245
+ */
18246
+ function searchPortal(searchOptions) {
18247
+ return __awaiter(this, void 0, void 0, function () {
18248
+ var resp, fn, results;
18249
+ return __generator(this, function (_a) {
18250
+ switch (_a.label) {
18251
+ case 0: return [4 /*yield*/, searchUsers(searchOptions)];
18252
+ case 1:
18253
+ resp = _a.sent();
18254
+ fn = function (user) {
18255
+ return userToSearchResult(user, searchOptions.include, searchOptions.requestOptions);
18256
+ };
18257
+ return [4 /*yield*/, Promise.all(resp.results.map(fn))];
18258
+ case 2:
18259
+ results = _a.sent();
18260
+ // Group Search does not support aggregations
18261
+ // Construct the return
18262
+ return [2 /*return*/, {
18263
+ total: resp.total,
18264
+ results: results,
18265
+ facets: [],
18266
+ hasNext: resp.nextStart > -1,
18267
+ next: getNextFunction(searchOptions, resp.nextStart, resp.total, searchPortal),
18268
+ }];
18269
+ }
18270
+ });
18271
+ });
18272
+ }
18273
+ /**
18274
+ * Convert an Item to a IHubSearchResult
18275
+ * Fetches the includes and attaches them to the item
18276
+ * @param item
18277
+ * @param includes
18278
+ * @param requestOptions
18279
+ * @returns
18280
+ */
18281
+ function userToSearchResult(user, includes, requestOptions) {
18282
+ if (includes === void 0) { includes = []; }
18283
+ return __awaiter(this, void 0, void 0, function () {
18284
+ return __generator(this, function (_a) {
18285
+ // Delegate to HubGroups module
18286
+ // This layer of indirection is not necessary but
18287
+ // aligns with how the items search works and
18288
+ // allows for future specialization
18289
+ return [2 /*return*/, enrichUserSearchResult(user, includes, requestOptions)];
18290
+ });
18291
+ });
18292
+ }
18293
+
18053
18294
  /**
18054
18295
  * Main Search function for ArcGIS Hub
18055
18296
  *
@@ -18083,6 +18324,7 @@
18083
18324
  arcgis: {
18084
18325
  item: portalSearchItems,
18085
18326
  group: portalSearchGroups,
18327
+ user: portalSearchUsers,
18086
18328
  },
18087
18329
  "arcgis-hub": {
18088
18330
  item: hubSearchItems,
@@ -18092,7 +18334,7 @@
18092
18334
  if (!fn) {
18093
18335
  throw new HubError$1("hubSearch", "Search via \"" + filterType + "\" filter against \"" + apiType + "\" api is not implemented");
18094
18336
  }
18095
- return [2 /*return*/, fn(filterGroups, options)];
18337
+ return [2 /*return*/, fn(cloneObject$1(filterGroups), options)];
18096
18338
  });
18097
18339
  });
18098
18340
  }
@@ -19566,6 +19808,145 @@
19566
19808
  return Hub;
19567
19809
  }());
19568
19810
 
19811
+ var enrichUserOrg = function (input) {
19812
+ var data = input.data, stack = input.stack, requestOptions = input.requestOptions;
19813
+ var opId = stack.start("enrichUserOrg");
19814
+ var options = __assign(__assign({}, requestOptions), {
19815
+ // In order to get the correct response, we must pass options.portal
19816
+ // as a base portal url (e.g., www.arcgis.com, qaext.arcgis.com, etc)
19817
+ // **not** an org portal (i.e. org.maps.arcgis.com).
19818
+ portal: getPortalBaseFromOrgUrl(requestOptions.portal) + "/sharing/rest" });
19819
+ // TODO: Add Caching
19820
+ // Had implemented a simple caching system, but it leads to unstable
19821
+ // tests because we can't deterministically clear it
19822
+ // if (!orgCache[data.user.orgId]) {
19823
+ // orgCache[data.user.orgId] = fetchOrg(data.user.orgId, options);
19824
+ // }
19825
+ // return (orgCache[data.user.orgId] as Promise<IPortal>)
19826
+ return fetchOrg(data.user.orgId, options)
19827
+ .then(function (results) {
19828
+ stack.finish(opId);
19829
+ return {
19830
+ data: __assign(__assign({}, data), {
19831
+ org: results,
19832
+ }),
19833
+ stack: stack,
19834
+ requestOptions: requestOptions,
19835
+ };
19836
+ })
19837
+ .catch(function (error) { return handleEnrichmentError(error, input, opId); });
19838
+ };
19839
+ /**
19840
+ * Simple cache for user org's. This does not expire
19841
+ * but that seems reasonable as Org props rarely change
19842
+ */
19843
+ // This works find at run-time, but it's a problem in tests
19844
+ // where we are validating calls. Will work with Randy to
19845
+ // create something that's more robust
19846
+ // const orgCache: Record<string, any> = {};
19847
+ // add the error to the content.errors,
19848
+ // log current stack operation as finished with an error
19849
+ // and return output that can be piped into the next operation
19850
+ var handleEnrichmentError = function (error, input, opId) {
19851
+ var data = input.data, stack = input.stack, requestOptions = input.requestOptions;
19852
+ stack.finish(opId, { error: error });
19853
+ return {
19854
+ data: __assign(__assign({}, data), { errors: getEnrichmentErrors(error, data.errors) }),
19855
+ stack: stack,
19856
+ requestOptions: requestOptions,
19857
+ };
19858
+ };
19859
+ /**
19860
+ * Available enrichments for Groups
19861
+ */
19862
+ var groupEnrichementOperations = {
19863
+ org: enrichUserOrg,
19864
+ };
19865
+ /**
19866
+ * Fetch enrichments for Users
19867
+ * @param group
19868
+ * @param enrichments
19869
+ * @param requestOptions
19870
+ * @returns
19871
+ */
19872
+ function fetchUserEnrichments(user, enrichments, requestOptions) {
19873
+ // create a pipeline of enrichment operations
19874
+ var operations = enrichments.reduce(function (ops, enrichment) {
19875
+ var operation = groupEnrichementOperations[enrichment];
19876
+ // only include the enrichments that we know how to fetch
19877
+ operation && ops.push(operation);
19878
+ return ops;
19879
+ }, []);
19880
+ var pipeline = createOperationPipeline(operations);
19881
+ // execute pipeline and return the item and enrichments
19882
+ return pipeline({
19883
+ data: { user: user },
19884
+ stack: new OperationStack$1(),
19885
+ requestOptions: requestOptions,
19886
+ }).then(function (output) {
19887
+ // TODO: send telemetry so we have info on what enrichments are requested and possible errors
19888
+ return output.data;
19889
+ });
19890
+ }
19891
+
19892
+ /**
19893
+ * Enrich a User object
19894
+ * @param user
19895
+ * @param includes
19896
+ * @param requestOptions
19897
+ * @returns
19898
+ */
19899
+ function enrichUserSearchResult(user, include, requestOptions) {
19900
+ return __awaiter(this, void 0, void 0, function () {
19901
+ var result, DEFAULTS, specs, enrichments, enriched, token;
19902
+ return __generator(this, function (_a) {
19903
+ switch (_a.label) {
19904
+ case 0:
19905
+ result = {
19906
+ access: user.access,
19907
+ id: user.username,
19908
+ type: "User",
19909
+ name: user.fullName,
19910
+ owner: user.username,
19911
+ summary: user.description,
19912
+ createdDate: new Date(user.created),
19913
+ createdDateSource: "user.created",
19914
+ updatedDate: new Date(user.modified),
19915
+ updatedDateSource: "user.modified",
19916
+ family: "people",
19917
+ links: {
19918
+ self: "not-implemented",
19919
+ siteRelative: "not-implemented",
19920
+ thumbnail: "not-implemented",
19921
+ },
19922
+ };
19923
+ DEFAULTS = ["org.name AS orgName"];
19924
+ // merge includes
19925
+ include = __spreadArrays(DEFAULTS, include).filter(unique);
19926
+ specs = include.map(parseInclude);
19927
+ enrichments = mapBy("enrichment", specs).filter(unique);
19928
+ enriched = {};
19929
+ if (!enrichments.length) return [3 /*break*/, 2];
19930
+ return [4 /*yield*/, fetchUserEnrichments(user, enrichments, requestOptions)];
19931
+ case 1:
19932
+ enriched = _a.sent();
19933
+ _a.label = 2;
19934
+ case 2:
19935
+ // map the enriched props onto the result
19936
+ specs.forEach(function (spec) {
19937
+ result[spec.prop] = getProp(enriched, spec.path);
19938
+ });
19939
+ token = requestOptions.authentication.token;
19940
+ // Handle links
19941
+ result.links.thumbnail = getUserThumbnailUrl(requestOptions.portal, user, token);
19942
+ result.links.self = getUserHomeUrl(result.id, requestOptions);
19943
+ result.links.siteRelative = "/people/" + result.id;
19944
+ return [2 /*return*/, result];
19945
+ }
19946
+ });
19947
+ });
19948
+ }
19949
+
19569
19950
  exports.ArcGISContext = ArcGISContext;
19570
19951
  exports.ArcGISContextManager = ArcGISContextManager;
19571
19952
  exports.DEFAULT_THEME = DEFAULT_THEME;
@@ -19693,6 +20074,7 @@
19693
20074
  exports.enrichPageSearchResult = enrichPageSearchResult;
19694
20075
  exports.enrichProjectSearchResult = enrichProjectSearchResult;
19695
20076
  exports.enrichSiteSearchResult = enrichSiteSearchResult;
20077
+ exports.enrichUserSearchResult = enrichUserSearchResult;
19696
20078
  exports.ensureProp = ensureProp;
19697
20079
  exports.ensureUniqueDomainName = ensureUniqueDomainName;
19698
20080
  exports.ensureUniqueString = ensureUniqueString;
@@ -19715,6 +20097,7 @@
19715
20097
  exports.fetchHubTranslation = fetchHubTranslation;
19716
20098
  exports.fetchImageAsBlob = fetchImageAsBlob;
19717
20099
  exports.fetchModelFromItem = fetchModelFromItem;
20100
+ exports.fetchOrg = fetchOrg;
19718
20101
  exports.fetchProject = fetchProject;
19719
20102
  exports.fetchSite = fetchSite;
19720
20103
  exports.fetchSiteModel = fetchSiteModel;
@@ -19783,6 +20166,7 @@
19783
20166
  exports.getUniqueDomainNamePortal = getUniqueDomainNamePortal;
19784
20167
  exports.getUniqueItemTitle = getUniqueItemTitle;
19785
20168
  exports.getUniqueSlug = getUniqueSlug;
20169
+ exports.getUserHomeUrl = getUserHomeUrl;
19786
20170
  exports.getUserThumbnailUrl = getUserThumbnailUrl;
19787
20171
  exports.getWithDefault = getWithDefault$1;
19788
20172
  exports.hasBasePriv = hasBasePriv;