@esri/hub-common 9.43.1 → 9.44.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 (98) hide show
  1. package/dist/es2017/ArcGISContext.js +1 -1
  2. package/dist/es2017/ArcGISContext.js.map +1 -1
  3. package/dist/es2017/content/_fetch.js +4 -2
  4. package/dist/es2017/content/_fetch.js.map +1 -1
  5. package/dist/es2017/content/fetch.js +10 -4
  6. package/dist/es2017/content/fetch.js.map +1 -1
  7. package/dist/es2017/items/_enrichments.js +9 -4
  8. package/dist/es2017/items/_enrichments.js.map +1 -1
  9. package/dist/es2017/resources/_internal/_validate-url-helpers.js +3 -12
  10. package/dist/es2017/resources/_internal/_validate-url-helpers.js.map +1 -1
  11. package/dist/es2017/search/Collection.js +71 -0
  12. package/dist/es2017/search/Collection.js.map +1 -0
  13. package/dist/es2017/search/_internal/ifilter-utils.js +221 -0
  14. package/dist/es2017/search/_internal/ifilter-utils.js.map +1 -0
  15. package/dist/es2017/search/_internal/portalSearchGroups.js +47 -2
  16. package/dist/es2017/search/_internal/portalSearchGroups.js.map +1 -1
  17. package/dist/es2017/search/_internal/portalSearchItems.js +95 -6
  18. package/dist/es2017/search/_internal/portalSearchItems.js.map +1 -1
  19. package/dist/es2017/search/_internal/portalSearchUsers.js +46 -1
  20. package/dist/es2017/search/_internal/portalSearchUsers.js.map +1 -1
  21. package/dist/es2017/search/filter-utils.js +1 -0
  22. package/dist/es2017/search/filter-utils.js.map +1 -1
  23. package/dist/es2017/search/hubSearch.js +38 -3
  24. package/dist/es2017/search/hubSearch.js.map +1 -1
  25. package/dist/es2017/search/types/IHubCatalog.js +1 -0
  26. package/dist/es2017/search/types/IHubCatalog.js.map +1 -0
  27. package/dist/es2017/search/types/index.js +1 -0
  28. package/dist/es2017/search/types/index.js.map +1 -1
  29. package/dist/esm/ArcGISContext.js +1 -1
  30. package/dist/esm/ArcGISContext.js.map +1 -1
  31. package/dist/esm/content/_fetch.js +4 -2
  32. package/dist/esm/content/_fetch.js.map +1 -1
  33. package/dist/esm/content/fetch.js +4 -3
  34. package/dist/esm/content/fetch.js.map +1 -1
  35. package/dist/esm/items/_enrichments.js +9 -4
  36. package/dist/esm/items/_enrichments.js.map +1 -1
  37. package/dist/esm/resources/_internal/_validate-url-helpers.js +3 -12
  38. package/dist/esm/resources/_internal/_validate-url-helpers.js.map +1 -1
  39. package/dist/esm/search/Collection.js +106 -0
  40. package/dist/esm/search/Collection.js.map +1 -0
  41. package/dist/esm/search/_internal/ifilter-utils.js +222 -0
  42. package/dist/esm/search/_internal/ifilter-utils.js.map +1 -0
  43. package/dist/esm/search/_internal/portalSearchGroups.js +50 -2
  44. package/dist/esm/search/_internal/portalSearchGroups.js.map +1 -1
  45. package/dist/esm/search/_internal/portalSearchItems.js +97 -6
  46. package/dist/esm/search/_internal/portalSearchItems.js.map +1 -1
  47. package/dist/esm/search/_internal/portalSearchUsers.js +49 -1
  48. package/dist/esm/search/_internal/portalSearchUsers.js.map +1 -1
  49. package/dist/esm/search/filter-utils.js +1 -0
  50. package/dist/esm/search/filter-utils.js.map +1 -1
  51. package/dist/esm/search/hubSearch.js +41 -3
  52. package/dist/esm/search/hubSearch.js.map +1 -1
  53. package/dist/esm/search/types/IHubCatalog.js +1 -0
  54. package/dist/esm/search/types/IHubCatalog.js.map +1 -0
  55. package/dist/esm/search/types/index.js +1 -0
  56. package/dist/esm/search/types/index.js.map +1 -1
  57. package/dist/node/ArcGISContext.js +1 -1
  58. package/dist/node/ArcGISContext.js.map +1 -1
  59. package/dist/node/content/_fetch.js +4 -2
  60. package/dist/node/content/_fetch.js.map +1 -1
  61. package/dist/node/content/fetch.js +10 -4
  62. package/dist/node/content/fetch.js.map +1 -1
  63. package/dist/node/items/_enrichments.js +9 -4
  64. package/dist/node/items/_enrichments.js.map +1 -1
  65. package/dist/node/resources/_internal/_validate-url-helpers.js +3 -12
  66. package/dist/node/resources/_internal/_validate-url-helpers.js.map +1 -1
  67. package/dist/node/search/Collection.js +75 -0
  68. package/dist/node/search/Collection.js.map +1 -0
  69. package/dist/node/search/_internal/ifilter-utils.js +226 -0
  70. package/dist/node/search/_internal/ifilter-utils.js.map +1 -0
  71. package/dist/node/search/_internal/portalSearchGroups.js +49 -3
  72. package/dist/node/search/_internal/portalSearchGroups.js.map +1 -1
  73. package/dist/node/search/_internal/portalSearchItems.js +98 -6
  74. package/dist/node/search/_internal/portalSearchItems.js.map +1 -1
  75. package/dist/node/search/_internal/portalSearchUsers.js +48 -2
  76. package/dist/node/search/_internal/portalSearchUsers.js.map +1 -1
  77. package/dist/node/search/filter-utils.js +1 -0
  78. package/dist/node/search/filter-utils.js.map +1 -1
  79. package/dist/node/search/hubSearch.js +39 -3
  80. package/dist/node/search/hubSearch.js.map +1 -1
  81. package/dist/node/search/types/IHubCatalog.js +3 -0
  82. package/dist/node/search/types/IHubCatalog.js.map +1 -0
  83. package/dist/node/search/types/index.js +1 -0
  84. package/dist/node/search/types/index.js.map +1 -1
  85. package/dist/types/content/_fetch.d.ts +2 -0
  86. package/dist/types/core/types/IServerEnrichments.d.ts +1 -1
  87. package/dist/types/resources/_internal/_validate-url-helpers.d.ts +3 -12
  88. package/dist/types/search/Collection.d.ts +18 -0
  89. package/dist/types/search/_internal/ifilter-utils.d.ts +4 -0
  90. package/dist/types/search/_internal/portalSearchGroups.d.ts +12 -3
  91. package/dist/types/search/_internal/portalSearchItems.d.ts +28 -4
  92. package/dist/types/search/_internal/portalSearchUsers.d.ts +11 -2
  93. package/dist/types/search/hubSearch.d.ts +2 -1
  94. package/dist/types/search/types/IHubCatalog.d.ts +71 -0
  95. package/dist/types/search/types/index.d.ts +1 -0
  96. package/dist/umd/common.umd.js +505 -65
  97. package/dist/umd/common.umd.js.map +1 -1
  98. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * @esri/hub-common - v9.43.0 - Wed Jun 15 2022 19:01:13 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/hub-common - v9.43.3 - Fri Jun 24 2022 18:21:01 GMT+0000 (Coordinated Universal Time)
3
3
  * Copyright (c) 2022 Environmental Systems Research Institute, Inc.
4
4
  * Apache-2.0
5
5
  */
@@ -5631,7 +5631,7 @@
5631
5631
  */
5632
5632
  get: function () {
5633
5633
  if (this.isAuthenticated) {
5634
- if (this.isPortal) {
5634
+ if (this.isPortal || !this._portalSelf.urlKey) {
5635
5635
  return "https://" + this._portalSelf.portalHostname;
5636
5636
  }
5637
5637
  else {
@@ -10091,14 +10091,19 @@
10091
10091
  })
10092
10092
  .catch(function (error) { return handleEnrichmentError$2(error, input, opId); });
10093
10093
  };
10094
- // Note, this MUST be run after `enrichOwnerUser` to access the correct orgId during
10095
- // processing. `item.orgId` is only SOMETIMES returned by Portal, so we need to have
10096
- // the ownerUser's orgId as a backup.
10094
+ // Note, this MUST be run after `enrichOwnerUser` to access the correct orgId during processing.
10095
+ // `item.orgId` is only SOMETIMES returned by Portal, so we need the ownerUser's orgId as a backup.
10096
+ //
10097
+ // If an orgId isn't present on either the item or the ownerUser, this operation will be skipped.
10097
10098
  var enrichOrg = function (input) {
10098
10099
  var data = input.data, stack = input.stack, requestOptions = input.requestOptions;
10099
10100
  var opId = stack.start("enrichOrg");
10100
10101
  var orgId = getItemOrgId(data.item, data.ownerUser);
10101
- return fetchOrg(orgId, requestOptions)
10102
+ // Only fetch the org if an explicit orgId is present
10103
+ var orgPromise = orgId
10104
+ ? fetchOrg(orgId, requestOptions)
10105
+ : Promise.resolve(undefined);
10106
+ return orgPromise
10102
10107
  .then(function (org) {
10103
10108
  stack.finish(opId);
10104
10109
  return {
@@ -10340,7 +10345,8 @@
10340
10345
  var opts = cloneObject$1(requestOptions);
10341
10346
  opts.params = __assign(__assign({}, opts.params), {
10342
10347
  // TODO: we should fetch errors too
10343
- "fields[datasets]": "slug,boundary,extent,searchDescription,statistics" });
10348
+ // TODO: stop fetching recordCount at next breaking change
10349
+ "fields[datasets]": "slug,boundary,extent,recordCount,searchDescription,statistics" });
10344
10350
  if (slug) {
10345
10351
  opts.params["filter[slug]"] = slug;
10346
10352
  }
@@ -10350,13 +10356,14 @@
10350
10356
  var getDatasetEnrichments = function (dataset) {
10351
10357
  var _a = parseDatasetId(dataset.id), itemId = _a.itemId, layerIdString = _a.layerId;
10352
10358
  var layerId = layerIdString && parseInt(layerIdString, 10);
10353
- var _b = dataset.attributes, slug = _b.slug, boundary = _b.boundary, extent = _b.extent, searchDescription = _b.searchDescription, statistics = _b.statistics;
10359
+ var _b = dataset.attributes, slug = _b.slug, boundary = _b.boundary, extent = _b.extent, recordCount = _b.recordCount, searchDescription = _b.searchDescription, statistics = _b.statistics;
10354
10360
  return {
10355
10361
  itemId: itemId,
10356
10362
  layerId: layerId,
10357
10363
  slug: slug,
10358
10364
  boundary: boundary,
10359
10365
  extent: extent,
10366
+ recordCount: recordCount,
10360
10367
  searchDescription: searchDescription,
10361
10368
  statistics: statistics,
10362
10369
  };
@@ -10577,7 +10584,7 @@
10577
10584
  * ```
10578
10585
  */
10579
10586
  var fetchContent = function (identifier, options) { return __awaiter(void 0, void 0, void 0, function () {
10580
- var content, _a, layer, type, _b, _c;
10587
+ var content, _a, layer, type, canQuery, _b, _c;
10581
10588
  return __generator(this, function (_d) {
10582
10589
  switch (_d.label) {
10583
10590
  case 0:
@@ -10593,14 +10600,15 @@
10593
10600
  case 4:
10594
10601
  content = _a;
10595
10602
  layer = content.layer, type = content.type;
10603
+ canQuery = !!layer && hasFeatures(type);
10596
10604
  _b = content;
10597
- if (!(!!layer && hasFeatures(type))) return [3 /*break*/, 6];
10605
+ if (!(canQuery && (isNil(content.recordCount) || content.viewDefinition))) return [3 /*break*/, 6];
10598
10606
  return [4 /*yield*/, fetchContentRecordCount(content, options)];
10599
10607
  case 5:
10600
10608
  _c = _d.sent();
10601
10609
  return [3 /*break*/, 7];
10602
10610
  case 6:
10603
- _c = undefined;
10611
+ _c = content.recordCount;
10604
10612
  _d.label = 7;
10605
10613
  case 7:
10606
10614
  _b.recordCount = _c;
@@ -11821,18 +11829,9 @@
11821
11829
  * Gets item info out of a feature layer item.
11822
11830
  *
11823
11831
  * @export
11824
- * @param {string} url Item URL
11825
- * @param {{
11826
- * name: string,
11827
- * description: string,
11828
- * extent: any
11829
- * }} body Item body.
11830
- * @return {*} {{
11831
- * title: string,
11832
- * description: string,
11833
- * extent: any,
11834
- * url: string
11835
- * }}
11832
+ * @param url Item URL
11833
+ * @param body Item body.
11834
+ * @return Item info (title, description, extent, url)
11836
11835
  */
11837
11836
  function getFeatureLayerItem(url, body) {
11838
11837
  return {
@@ -13549,7 +13548,7 @@
13549
13548
  * @param join
13550
13549
  * @returns
13551
13550
  */
13552
- function mergeSearchOptions$1(so1, so2, join) {
13551
+ function mergeSearchOptions$2(so1, so2, join) {
13553
13552
  // TODO: Remove with _searchContent
13554
13553
  Logger.warn("DEPRECATION: mergeSearchOptions will be removed. Work with IFilterGroups<\"group\"> and hubSearch() instead");
13555
13554
  var result = cloneObject$1(so1);
@@ -13570,7 +13569,7 @@
13570
13569
  * @param opts
13571
13570
  * @returns
13572
13571
  */
13573
- function serializeMatchOptions$1(key, opts) {
13572
+ function serializeMatchOptions$2(key, opts) {
13574
13573
  var result = {
13575
13574
  q: "",
13576
13575
  filter: "",
@@ -13595,7 +13594,7 @@
13595
13594
  var groupFilterableFields = ["title", "typekeywords", "owner"];
13596
13595
  var filterableFields = __spreadArrays(userFilterableFields, itemFilterableFields, groupFilterableFields);
13597
13596
  if (filterableFields.includes(key)) {
13598
- result.filter = serializeStringOrArray$1("AND", key, opts.exact);
13597
+ result.filter = serializeStringOrArray$2("AND", key, opts.exact);
13599
13598
  }
13600
13599
  else {
13601
13600
  // Treat it the same as .all
@@ -13621,18 +13620,18 @@
13621
13620
  }
13622
13621
  // Handle the other props
13623
13622
  if (opts.any) {
13624
- result.q = serializeStringOrArray$1("OR", key, opts.any);
13623
+ result.q = serializeStringOrArray$2("OR", key, opts.any);
13625
13624
  }
13626
13625
  if (opts.all) {
13627
13626
  result.q =
13628
13627
  (result.q ? result.q + " AND " : "") +
13629
- serializeStringOrArray$1("AND", key, opts.all);
13628
+ serializeStringOrArray$2("AND", key, opts.all);
13630
13629
  }
13631
13630
  if (opts.not) {
13632
13631
  // negate the entries if they are not
13633
13632
  result.q =
13634
13633
  (result.q ? result.q + " AND " : "") +
13635
- serializeStringOrArray$1("OR", "-" + key, opts.not);
13634
+ serializeStringOrArray$2("OR", "-" + key, opts.not);
13636
13635
  }
13637
13636
  return result;
13638
13637
  }
@@ -13643,7 +13642,7 @@
13643
13642
  * @param range
13644
13643
  * @returns
13645
13644
  */
13646
- function serializeDateRange$1(key, range) {
13645
+ function serializeDateRange$2(key, range) {
13647
13646
  return {
13648
13647
  q: key + ":[" + range.from + " TO " + range.to + "]",
13649
13648
  filter: "",
@@ -13657,7 +13656,7 @@
13657
13656
  * @param value
13658
13657
  * @returns
13659
13658
  */
13660
- function serializeStringOrArray$1(join, key, value) {
13659
+ function serializeStringOrArray$2(join, key, value) {
13661
13660
  var q = "";
13662
13661
  if (Array.isArray(value)) {
13663
13662
  q = key + ":\"" + value.join("\" " + join + " " + key + ":\"") + "\"";
@@ -14145,12 +14144,12 @@
14145
14144
  // from hitting the else
14146
14145
  /* istanbul ignore else */
14147
14146
  if (typeof entry === "object") {
14148
- acc = mergeSearchOptions$1(acc, convertContentFilterToSearchOptions(entry), "OR");
14147
+ acc = mergeSearchOptions$2(acc, convertContentFilterToSearchOptions(entry), "OR");
14149
14148
  }
14150
14149
  return acc;
14151
14150
  }, { q: "", filter: "" });
14152
14151
  // merge with searchOptions using AND
14153
- searchOptions = mergeSearchOptions$1(searchOptions, subFilterOptions, "AND");
14152
+ searchOptions = mergeSearchOptions$2(searchOptions, subFilterOptions, "AND");
14154
14153
  }
14155
14154
  // term is always last, and pre-pended on searchOptions.q
14156
14155
  if (filter.term) {
@@ -14178,11 +14177,11 @@
14178
14177
  var key = _a[0], value = _a[1];
14179
14178
  // MatchOptions may go into either q or filter
14180
14179
  if (!specialProps.includes(key)) {
14181
- result = mergeSearchOptions$1(result, serializeMatchOptions$1(key, value), "AND");
14180
+ result = mergeSearchOptions$2(result, serializeMatchOptions$2(key, value), "AND");
14182
14181
  }
14183
14182
  // Dates only go into q
14184
14183
  if (dateProps.includes(key)) {
14185
- result = mergeSearchOptions$1(result, serializeDateRange$1(key, value), "AND");
14184
+ result = mergeSearchOptions$2(result, serializeDateRange$2(key, value), "AND");
14186
14185
  }
14187
14186
  });
14188
14187
  return result;
@@ -14313,11 +14312,11 @@
14313
14312
  var key = _a[0], value = _a[1];
14314
14313
  // MatchOptions fields
14315
14314
  if (!specialProps.includes(key)) {
14316
- result = mergeSearchOptions$1(result, serializeMatchOptions$1(key, value), "AND");
14315
+ result = mergeSearchOptions$2(result, serializeMatchOptions$2(key, value), "AND");
14317
14316
  }
14318
14317
  // Dates only go into q
14319
14318
  if (dateProps.includes(key)) {
14320
- result = mergeSearchOptions$1(result, serializeDateRange$1(key, value), "AND");
14319
+ result = mergeSearchOptions$2(result, serializeDateRange$2(key, value), "AND");
14321
14320
  }
14322
14321
  });
14323
14322
  // searchUserAccess is also a top-level property
@@ -14453,11 +14452,11 @@
14453
14452
  var key = _a[0], value = _a[1];
14454
14453
  // MatchOptions fields
14455
14454
  if (!specialProps.includes(key)) {
14456
- result = mergeSearchOptions$1(result, serializeMatchOptions$1(key, value), "AND");
14455
+ result = mergeSearchOptions$2(result, serializeMatchOptions$2(key, value), "AND");
14457
14456
  }
14458
14457
  // Dates only go into q
14459
14458
  if (dateProps.includes(key)) {
14460
- result = mergeSearchOptions$1(result, serializeDateRange$1(key, value), "AND");
14459
+ result = mergeSearchOptions$2(result, serializeDateRange$2(key, value), "AND");
14461
14460
  }
14462
14461
  });
14463
14462
  // disabled is also a top-level property
@@ -14975,6 +14974,7 @@
14975
14974
  return catalog;
14976
14975
  }
14977
14976
 
14977
+ // DEPRECATED - REMOVE THIS FILE
14978
14978
  /**
14979
14979
  * Expand a Filter into it's more expressive structure so it can be
14980
14980
  * serialized deterministically.
@@ -15027,7 +15027,7 @@
15027
15027
  */
15028
15028
  function serializeFilterGroupsForPortal(filterGroups) {
15029
15029
  var groupSearchOptions = filterGroups.map(serializeGroup);
15030
- var result = mergeSearchOptions(groupSearchOptions, "AND");
15030
+ var result = mergeSearchOptions$1(groupSearchOptions, "AND");
15031
15031
  return result;
15032
15032
  }
15033
15033
  /**
@@ -15038,9 +15038,9 @@
15038
15038
  function serializeGroup(filterGroup) {
15039
15039
  var operation = filterGroup.operation || "AND";
15040
15040
  var filters = filterGroup.filters.map(expandFilter);
15041
- var filterSearchOptions = filters.map(serializeFilter);
15041
+ var filterSearchOptions = filters.map(serializeFilter$1);
15042
15042
  // combine these searchOptions
15043
- var groupSearchOptions = mergeSearchOptions(filterSearchOptions, operation);
15043
+ var groupSearchOptions = mergeSearchOptions$1(filterSearchOptions, operation);
15044
15044
  //
15045
15045
  if (filters.length > 1) {
15046
15046
  groupSearchOptions.q = "(" + groupSearchOptions.q + ")";
@@ -15052,7 +15052,7 @@
15052
15052
  * @param filter
15053
15053
  * @returns
15054
15054
  */
15055
- function serializeFilter(filter) {
15055
+ function serializeFilter$1(filter) {
15056
15056
  var dateProps = ["created", "modified"];
15057
15057
  var boolProps = ["isopendata"];
15058
15058
  var passThroughProps = ["searchUserAccess", "searchUserName"];
@@ -15068,11 +15068,11 @@
15068
15068
  var so = { q: "" };
15069
15069
  if (!specialProps.includes(key)) {
15070
15070
  qCount++;
15071
- so.q = serializeMatchOptions(key, value);
15071
+ so.q = serializeMatchOptions$1(key, value);
15072
15072
  }
15073
15073
  if (dateProps.includes(key)) {
15074
15074
  qCount++;
15075
- so.q = serializeDateRange(key, value);
15075
+ so.q = serializeDateRange$1(key, value);
15076
15076
  }
15077
15077
  if (boolProps.includes(key)) {
15078
15078
  qCount++;
@@ -15089,13 +15089,13 @@
15089
15089
  })
15090
15090
  .filter(function (e) { return e !== undefined; });
15091
15091
  // merge up all the searchOptions
15092
- var searchOptions = mergeSearchOptions(opts, "AND");
15092
+ var searchOptions = mergeSearchOptions$1(opts, "AND");
15093
15093
  if (qCount > 1) {
15094
15094
  searchOptions.q = "(" + searchOptions.q + ")";
15095
15095
  }
15096
15096
  return searchOptions;
15097
15097
  }
15098
- function mergeSearchOptions(options, operation) {
15098
+ function mergeSearchOptions$1(options, operation) {
15099
15099
  var result = options.reduce(function (acc, entry) {
15100
15100
  // walk the props
15101
15101
  Object.entries(entry).forEach(function (_a) {
@@ -15120,21 +15120,21 @@
15120
15120
  * @param value
15121
15121
  * @returns
15122
15122
  */
15123
- function serializeMatchOptions(key, value) {
15123
+ function serializeMatchOptions$1(key, value) {
15124
15124
  var result = "";
15125
15125
  if (value.any) {
15126
- result = "" + serializeStringOrArray("OR", key, value.any);
15126
+ result = "" + serializeStringOrArray$1("OR", key, value.any);
15127
15127
  }
15128
15128
  if (value.all) {
15129
15129
  result =
15130
15130
  (result ? result + " AND " : "") +
15131
- ("" + serializeStringOrArray("AND", key, value.all));
15131
+ ("" + serializeStringOrArray$1("AND", key, value.all));
15132
15132
  }
15133
15133
  if (value.not) {
15134
15134
  // negate the entries if they are not
15135
15135
  result =
15136
15136
  (result ? result + " AND " : "") +
15137
- ("" + serializeStringOrArray("OR", "-" + key, value.not));
15137
+ ("" + serializeStringOrArray$1("OR", "-" + key, value.not));
15138
15138
  }
15139
15139
  // TODO HANDLE EXACT
15140
15140
  return result;
@@ -15145,7 +15145,7 @@
15145
15145
  * @param range
15146
15146
  * @returns
15147
15147
  */
15148
- function serializeDateRange(key, range) {
15148
+ function serializeDateRange$1(key, range) {
15149
15149
  return key + ":[" + range.from + " TO " + range.to + "]";
15150
15150
  }
15151
15151
  /**
@@ -15155,7 +15155,7 @@
15155
15155
  * @param value
15156
15156
  * @returns
15157
15157
  */
15158
- function serializeStringOrArray(join, key, value) {
15158
+ function serializeStringOrArray$1(join, key, value) {
15159
15159
  var q = "";
15160
15160
  if (Array.isArray(value)) {
15161
15161
  q = key + ":\"" + value.join("\" " + join + " " + key + ":\"") + "\"";
@@ -15333,6 +15333,224 @@
15333
15333
  };
15334
15334
  }
15335
15335
 
15336
+ function expandPredicate(predicate) {
15337
+ var result = {};
15338
+ var dateProps = ["created", "modified", "lastlogin"];
15339
+ var copyProps = [
15340
+ "filterType",
15341
+ "term",
15342
+ "searchUserAccess",
15343
+ "isopendata",
15344
+ "searchUserName",
15345
+ ];
15346
+ var nonMatchOptionsFields = __spreadArrays(dateProps, copyProps);
15347
+ // Do the conversion
15348
+ Object.entries(predicate).forEach(function (_a) {
15349
+ var key = _a[0], value = _a[1];
15350
+ // Handle MatchOptions fields
15351
+ if (!nonMatchOptionsFields.includes(key)) {
15352
+ setProp(key, valueToMatchOptions(value), result);
15353
+ }
15354
+ // Handle Date fields
15355
+ if (dateProps.includes(key)) {
15356
+ var dateFieldValue = cloneObject$1(getProp(predicate, key));
15357
+ if (getProp(predicate, key + ".type") === "relative-date") {
15358
+ setProp(key, relativeDateToDateRange(dateFieldValue), result);
15359
+ }
15360
+ else {
15361
+ setProp(key, dateFieldValue, result);
15362
+ }
15363
+ }
15364
+ // Handle fields that are just copied forward
15365
+ if (copyProps.includes(key) && predicate.hasOwnProperty(key)) {
15366
+ setProp(key, value, result);
15367
+ }
15368
+ });
15369
+ return result;
15370
+ }
15371
+ function serializeQueryForPortal(query) {
15372
+ var filterSearchOptions = query.filters.map(serializeFilter);
15373
+ var result = mergeSearchOptions(filterSearchOptions, "AND");
15374
+ return result;
15375
+ }
15376
+ function mergeSearchOptions(options, operation) {
15377
+ var result = options.reduce(function (acc, entry) {
15378
+ // walk the props
15379
+ Object.entries(entry).forEach(function (_a) {
15380
+ var key = _a[0], value = _a[1];
15381
+ // if prop exists
15382
+ if (acc[key]) {
15383
+ // combine via operation
15384
+ acc[key] = acc[key] + " " + operation + " " + value;
15385
+ }
15386
+ else {
15387
+ // just copy the value
15388
+ acc[key] = value;
15389
+ }
15390
+ });
15391
+ return acc;
15392
+ }, { q: "" });
15393
+ return result;
15394
+ }
15395
+ /**
15396
+ * Serialize the filters in a FitlerGroup into a Portal Query
15397
+ * @param filter
15398
+ * @returns
15399
+ */
15400
+ function serializeFilter(filter) {
15401
+ var operation = filter.operation || "AND";
15402
+ var predicates = filter.predicates.map(expandPredicate);
15403
+ var predicateSearchOptions = predicates.map(serializePredicate);
15404
+ // combine these searchOptions
15405
+ var searchOptions = mergeSearchOptions(predicateSearchOptions, operation);
15406
+ // wrap in parens if we have more than one predicate
15407
+ if (predicates.length > 1) {
15408
+ searchOptions.q = "(" + searchOptions.q + ")";
15409
+ }
15410
+ return searchOptions;
15411
+ }
15412
+ /**
15413
+ * Serialize a Filter into a Portal Query
15414
+ * @param predicate
15415
+ * @returns
15416
+ */
15417
+ function serializePredicate(predicate) {
15418
+ var dateProps = ["created", "modified"];
15419
+ var boolProps = ["isopendata"];
15420
+ var passThroughProps = ["searchUserAccess", "searchUserName"];
15421
+ var specialProps = __spreadArrays([
15422
+ "filterType",
15423
+ "term"
15424
+ ], dateProps, boolProps, passThroughProps);
15425
+ var portalAllowList = [
15426
+ "access",
15427
+ "categories",
15428
+ "created",
15429
+ "description",
15430
+ "disabled",
15431
+ "email",
15432
+ "emailstatus",
15433
+ "firstname",
15434
+ "fullname",
15435
+ "group",
15436
+ "id",
15437
+ "isInvitationOnly",
15438
+ "isopendata",
15439
+ "joined",
15440
+ "lastlogin",
15441
+ "lastname",
15442
+ "memberType",
15443
+ "modified",
15444
+ "name",
15445
+ "orgid",
15446
+ "orgIds",
15447
+ "owner",
15448
+ "provider",
15449
+ "role",
15450
+ "searchUserAccess",
15451
+ "searchUserName",
15452
+ "snippet",
15453
+ "tags",
15454
+ "term",
15455
+ "type",
15456
+ "typekeywords",
15457
+ "userlicensetype",
15458
+ "username",
15459
+ ];
15460
+ var qCount = 0;
15461
+ // TODO: Look at using reduce vs .map and remove the `.filter`
15462
+ var opts = Object.entries(predicate)
15463
+ .map(function (_a) {
15464
+ var key = _a[0], value = _a[1];
15465
+ // When serializing for portal we limit predicate properties to
15466
+ // a list of known properties that the portal api accepts. This will
15467
+ // not attempt to ensure the properties are used in the correct combinations
15468
+ if (portalAllowList.includes(key)) {
15469
+ var so = { q: "" };
15470
+ if (!specialProps.includes(key)) {
15471
+ qCount++;
15472
+ so.q = serializeMatchOptions(key, value);
15473
+ }
15474
+ if (dateProps.includes(key)) {
15475
+ qCount++;
15476
+ so.q = serializeDateRange(key, value);
15477
+ }
15478
+ if (boolProps.includes(key)) {
15479
+ qCount++;
15480
+ so.q = key + ":" + value;
15481
+ }
15482
+ if (passThroughProps.includes(key)) {
15483
+ so[key] = value;
15484
+ }
15485
+ if (key === "term") {
15486
+ qCount++;
15487
+ so.q = value;
15488
+ }
15489
+ return so;
15490
+ }
15491
+ })
15492
+ .filter(function (e) { return e !== undefined; });
15493
+ // merge up all the searchOptions
15494
+ var searchOptions = mergeSearchOptions(opts, "AND");
15495
+ if (qCount > 1) {
15496
+ searchOptions.q = "(" + searchOptions.q + ")";
15497
+ }
15498
+ return searchOptions;
15499
+ }
15500
+ /**
15501
+ * Serialize MatchOptions into portal syntax
15502
+ * @param key
15503
+ * @param value
15504
+ * @returns
15505
+ */
15506
+ function serializeMatchOptions(key, value) {
15507
+ var result = "";
15508
+ if (value.any) {
15509
+ result = "" + serializeStringOrArray("OR", key, value.any);
15510
+ }
15511
+ if (value.all) {
15512
+ result =
15513
+ (result ? result + " AND " : "") +
15514
+ ("" + serializeStringOrArray("AND", key, value.all));
15515
+ }
15516
+ if (value.not) {
15517
+ // negate the entries if they are not
15518
+ result =
15519
+ (result ? result + " AND " : "") +
15520
+ ("" + serializeStringOrArray("OR", "-" + key, value.not));
15521
+ }
15522
+ return result;
15523
+ }
15524
+ /**
15525
+ * Serialize a date-range into Portal syntax
15526
+ * @param key
15527
+ * @param range
15528
+ * @returns
15529
+ */
15530
+ function serializeDateRange(key, range) {
15531
+ return key + ":[" + range.from + " TO " + range.to + "]";
15532
+ }
15533
+ /**
15534
+ * Serialize a `string` or `string[]` into a string
15535
+ * @param join
15536
+ * @param key
15537
+ * @param value
15538
+ * @returns
15539
+ */
15540
+ function serializeStringOrArray(join, key, value) {
15541
+ var q = "";
15542
+ if (Array.isArray(value)) {
15543
+ q = key + ":\"" + value.join("\" " + join + " " + key + ":\"") + "\"";
15544
+ if (value.length > 1) {
15545
+ q = "(" + q + ")";
15546
+ }
15547
+ }
15548
+ else {
15549
+ q = key + ":\"" + value + "\"";
15550
+ }
15551
+ return q;
15552
+ }
15553
+
15336
15554
  /**
15337
15555
  * Fetch Page specific Enrichments
15338
15556
  * @param item
@@ -17850,12 +18068,12 @@
17850
18068
 
17851
18069
  /**
17852
18070
  * @private
17853
- * Portal Search Implementation for Items
18071
+ * DEPRECATED
17854
18072
  * @param filterGroups
17855
18073
  * @param options
17856
18074
  * @returns
17857
18075
  */
17858
- function portalSearchItems(filterGroups, options) {
18076
+ function portalSearchItemsFilterGroups(filterGroups, options) {
17859
18077
  var _a;
17860
18078
  return __awaiter(this, void 0, void 0, function () {
17861
18079
  var replaced, expandedGroups, so, props;
@@ -17863,7 +18081,7 @@
17863
18081
  if (!options.requestOptions) {
17864
18082
  throw new HubError$1("hubSearch", "requestOptions: IHubRequestOptions is required.");
17865
18083
  }
17866
- replaced = applyWellKnownItemFilters(filterGroups);
18084
+ replaced = applyWellKnownItemFilterGroups(filterGroups);
17867
18085
  expandedGroups = replaced.map(function (fg) {
17868
18086
  fg.filters = fg.filters.map(expandFilter);
17869
18087
  return fg;
@@ -17898,6 +18116,57 @@
17898
18116
  });
17899
18117
  });
17900
18118
  }
18119
+ /**
18120
+ * @private
18121
+ * Portal Search Implementation for Items
18122
+ * @param query
18123
+ * @param options
18124
+ * @returns
18125
+ */
18126
+ function portalSearchItems(query, options) {
18127
+ var _a;
18128
+ return __awaiter(this, void 0, void 0, function () {
18129
+ var updatedQuery, so, props;
18130
+ return __generator(this, function (_b) {
18131
+ if (!options.requestOptions) {
18132
+ throw new HubError$1("portalSearchItems", "options.requestOptions is required.");
18133
+ }
18134
+ updatedQuery = applyWellKnownItemPredicates(query);
18135
+ // Expand the individual predicates in each filter
18136
+ updatedQuery.filters = updatedQuery.filters.map(function (filter) {
18137
+ filter.predicates = filter.predicates.map(expandPredicate);
18138
+ return filter;
18139
+ });
18140
+ so = serializeQueryForPortal(updatedQuery);
18141
+ props = [
18142
+ "num",
18143
+ "sortField",
18144
+ "sortOrder",
18145
+ "include",
18146
+ "start",
18147
+ "requestOptions",
18148
+ ];
18149
+ // copy the props over
18150
+ props.forEach(function (prop) {
18151
+ if (options.hasOwnProperty(prop)) {
18152
+ so[prop] = options[prop];
18153
+ }
18154
+ });
18155
+ if (options.requestOptions.authentication) {
18156
+ so.authentication = options.requestOptions.authentication;
18157
+ }
18158
+ else {
18159
+ so.portal = options.requestOptions.portal;
18160
+ }
18161
+ // Aggregations
18162
+ if ((_a = options.aggFields) === null || _a === void 0 ? void 0 : _a.length) {
18163
+ so.countFields = options.aggFields.join(",");
18164
+ so.countSize = options.aggLimit || 10;
18165
+ }
18166
+ return [2 /*return*/, searchPortal$2(so)];
18167
+ });
18168
+ });
18169
+ }
17901
18170
  /**
17902
18171
  * Internal portal search, which then converts `IItem`s to `IHubSearchResult`s
17903
18172
  * handling enrichments & includes along the way
@@ -18138,7 +18407,36 @@
18138
18407
  * Only exported to enable extensive testing
18139
18408
  * @param filterGroups
18140
18409
  */
18141
- function applyWellKnownItemFilters(filterGroups) {
18410
+ function applyWellKnownItemPredicates(query) {
18411
+ var queryClone = cloneObject$1(query);
18412
+ // iterate the filters
18413
+ queryClone.filters = queryClone.filters.map(function (filter) {
18414
+ // replace predicates with well-known types
18415
+ filter.predicates = filter.predicates.reduce(function (acc, predicate) {
18416
+ // if the predicate has a well-known type
18417
+ // we replace it with the set of predicates defined
18418
+ // for the well-known type
18419
+ if (isWellKnownTypeFilter(predicate.type)) {
18420
+ var replacements = lookupTypePredicates(predicate.type);
18421
+ acc = __spreadArrays(acc, replacements);
18422
+ }
18423
+ else {
18424
+ // this predicate does not have a well-known type
18425
+ // so we just keep it
18426
+ acc.push(predicate);
18427
+ }
18428
+ return acc;
18429
+ }, []);
18430
+ return filter;
18431
+ });
18432
+ return queryClone;
18433
+ }
18434
+ /**
18435
+ * DEPRECATED
18436
+ * @param filterGroups
18437
+ * @returns
18438
+ */
18439
+ function applyWellKnownItemFilterGroups(filterGroups) {
18142
18440
  var clone = cloneObject$1(filterGroups);
18143
18441
  // iterate the filterGroups
18144
18442
  var result = clone.map(function (filterGroup) {
@@ -18190,6 +18488,16 @@
18190
18488
  function lookupTypeFilters(key) {
18191
18489
  return WellKnownItemFilters[key];
18192
18490
  }
18491
+ function lookupTypePredicates(key) {
18492
+ var rawPredicates = WellKnownItemFilters[key];
18493
+ // Remove the filterType property as it's not needed in an IPredicate
18494
+ var predicates = rawPredicates.map(function (entry) {
18495
+ var c = cloneObject$1(entry);
18496
+ delete c.filterType;
18497
+ return c;
18498
+ });
18499
+ return predicates;
18500
+ }
18193
18501
 
18194
18502
  // ## ## ####### ######## ########
18195
18503
  // ### ## ## ## ## ##
@@ -18393,12 +18701,13 @@
18393
18701
 
18394
18702
  /**
18395
18703
  * @private
18396
- * Portal Search Implementation for Items
18704
+ * DEPRECATED: Use `portalSerchGroups`
18705
+ * Portal Search Implementation for Groups
18397
18706
  * @param filterGroups
18398
18707
  * @param options
18399
18708
  * @returns
18400
18709
  */
18401
- function portalSearchGroups(filterGroups, options) {
18710
+ function portalSearchGroupsFilterGroups(filterGroups, options) {
18402
18711
  return __awaiter(this, void 0, void 0, function () {
18403
18712
  var api, expandedGroups, so, props;
18404
18713
  return __generator(this, function (_a) {
@@ -18445,6 +18754,51 @@
18445
18754
  });
18446
18755
  });
18447
18756
  }
18757
+ /**
18758
+ * @private
18759
+ * Portal Search Implementation for Groups
18760
+ * @param query
18761
+ * @param options
18762
+ * @returns
18763
+ */
18764
+ function portalSearchGroups(query, options) {
18765
+ return __awaiter(this, void 0, void 0, function () {
18766
+ var so, props;
18767
+ return __generator(this, function (_a) {
18768
+ if (!options.requestOptions) {
18769
+ throw new HubError$1("portalSearchGroups", "options.requestOptions is required.");
18770
+ }
18771
+ // Expand the individual predicates in each filter
18772
+ query.filters = query.filters.map(function (filter) {
18773
+ filter.predicates = filter.predicates.map(expandPredicate);
18774
+ return filter;
18775
+ });
18776
+ so = serializeQueryForPortal(query);
18777
+ props = [
18778
+ "num",
18779
+ "sortField",
18780
+ "sortOrder",
18781
+ "include",
18782
+ "start",
18783
+ "requestOptions",
18784
+ ];
18785
+ // copy the props over
18786
+ props.forEach(function (prop) {
18787
+ if (options.hasOwnProperty(prop)) {
18788
+ so[prop] = options[prop];
18789
+ }
18790
+ });
18791
+ // If we don't have auth, ensure we have .portal
18792
+ if (options.requestOptions.authentication) {
18793
+ so.authentication = options.requestOptions.authentication;
18794
+ }
18795
+ else {
18796
+ so.portal = options.requestOptions.portal;
18797
+ }
18798
+ return [2 /*return*/, searchPortal$1(so)];
18799
+ });
18800
+ });
18801
+ }
18448
18802
  /**
18449
18803
  * Internal portal search, which then converts `IGroup`s to `IHubSearchResult`s
18450
18804
  * handling enrichments & includes along the way
@@ -18502,11 +18856,12 @@
18502
18856
 
18503
18857
  /**
18504
18858
  * @private
18859
+ * DEPRECATED: Use `portalSearchUsers`
18505
18860
  * Portal Search implementation for Users
18506
18861
  * @param filterGroups
18507
18862
  * @param options
18508
18863
  */
18509
- function portalSearchUsers(filterGroups, options) {
18864
+ function portalSearchUsersFilterGroups(filterGroups, options) {
18510
18865
  return __awaiter(this, void 0, void 0, function () {
18511
18866
  var expandedGroups, so, props;
18512
18867
  return __generator(this, function (_a) {
@@ -18543,6 +18898,52 @@
18543
18898
  });
18544
18899
  });
18545
18900
  }
18901
+ /**
18902
+ * @private
18903
+ * Portal Search Implementation for Users
18904
+ * @param filterGroups
18905
+ * @param options
18906
+ * @returns
18907
+ */
18908
+ function portalSearchUsers(query, options) {
18909
+ return __awaiter(this, void 0, void 0, function () {
18910
+ var so, props;
18911
+ return __generator(this, function (_a) {
18912
+ // requestOptions is always required and user must be authd
18913
+ if (!options.requestOptions) {
18914
+ throw new HubError$1("portalSearchUsers", "requestOptions: IHubRequestOptions is required.");
18915
+ }
18916
+ if (!options.requestOptions.authentication) {
18917
+ throw new HubError$1("portalSearchUsers", "requestOptions must pass authentication.");
18918
+ }
18919
+ // Expand the individual predicates in each filter
18920
+ query.filters = query.filters.map(function (filter) {
18921
+ filter.predicates = filter.predicates.map(expandPredicate);
18922
+ return filter;
18923
+ });
18924
+ so = serializeQueryForPortal(query);
18925
+ props = [
18926
+ "num",
18927
+ "sortField",
18928
+ "sortOrder",
18929
+ "include",
18930
+ "start",
18931
+ "requestOptions",
18932
+ ];
18933
+ // copy the props over
18934
+ props.forEach(function (prop) {
18935
+ if (options.hasOwnProperty(prop)) {
18936
+ so[prop] = options[prop];
18937
+ }
18938
+ });
18939
+ // Unlike Groups and Item, the Users api *requires* authentication
18940
+ // so we set it directly
18941
+ so.authentication = options.requestOptions.authentication;
18942
+ // Execute search
18943
+ return [2 /*return*/, searchPortal(so)];
18944
+ });
18945
+ });
18946
+ }
18546
18947
  /**
18547
18948
  * Internal portal search, which then converts `IGroup`s to `IHubSearchResult`s
18548
18949
  * handling enrichments & includes along the way
@@ -18627,6 +19028,44 @@
18627
19028
  }
18628
19029
  filterType = filterGroups[0].filterType;
18629
19030
  apiType = expandApi(options.api || "arcgis").type;
19031
+ fnHash = {
19032
+ arcgis: {
19033
+ item: portalSearchItemsFilterGroups,
19034
+ group: portalSearchGroupsFilterGroups,
19035
+ user: portalSearchUsersFilterGroups,
19036
+ },
19037
+ "arcgis-hub": {
19038
+ item: hubSearchItems,
19039
+ },
19040
+ };
19041
+ fn = getProp(fnHash, apiType + "." + filterType);
19042
+ if (!fn) {
19043
+ throw new HubError$1("hubSearch", "Search via \"" + filterType + "\" filter against \"" + apiType + "\" api is not implemented");
19044
+ }
19045
+ return [2 /*return*/, fn(cloneObject$1(filterGroups), options)];
19046
+ });
19047
+ });
19048
+ }
19049
+ function hubSearchQuery(query, options) {
19050
+ return __awaiter(this, void 0, void 0, function () {
19051
+ var filterType, apiType, fnHash, fn;
19052
+ return __generator(this, function (_a) {
19053
+ // Validate inputs
19054
+ if (!query) {
19055
+ throw new HubError$1("hubSearch", "Query is required.");
19056
+ }
19057
+ if (!query.filters || !query.filters.length) {
19058
+ throw new HubError$1("hubSearch", "Query must contain at least one Filter.");
19059
+ }
19060
+ if (!options.requestOptions) {
19061
+ throw new HubError$1("hubSearch", "requestOptions: IHubRequestOptions is required.");
19062
+ }
19063
+ // Ensure includes is an array
19064
+ if (!options.include) {
19065
+ options.include = [];
19066
+ }
19067
+ filterType = query.targetEntity;
19068
+ apiType = expandApi(options.api || "arcgis").type;
18630
19069
  fnHash = {
18631
19070
  arcgis: {
18632
19071
  item: portalSearchItems,
@@ -18641,7 +19080,7 @@
18641
19080
  if (!fn) {
18642
19081
  throw new HubError$1("hubSearch", "Search via \"" + filterType + "\" filter against \"" + apiType + "\" api is not implemented");
18643
19082
  }
18644
- return [2 /*return*/, fn(cloneObject$1(filterGroups), options)];
19083
+ return [2 /*return*/, fn(cloneObject$1(query), options)];
18645
19084
  });
18646
19085
  });
18647
19086
  }
@@ -20480,6 +20919,7 @@
20480
20919
  exports.hubApiRequest = hubApiRequest;
20481
20920
  exports.hubApiSearch = hubApiSearch;
20482
20921
  exports.hubSearch = hubSearch;
20922
+ exports.hubSearchQuery = hubSearchQuery;
20483
20923
  exports.includes = includes;
20484
20924
  exports.incrementString = incrementString;
20485
20925
  exports.interpolate = interpolate;
@@ -20514,7 +20954,7 @@
20514
20954
  exports.mergeGroupFilters = mergeGroupFilters;
20515
20955
  exports.mergeMatchOptions = mergeMatchOptions;
20516
20956
  exports.mergeObjects = mergeObjects;
20517
- exports.mergeSearchOptions = mergeSearchOptions$1;
20957
+ exports.mergeSearchOptions = mergeSearchOptions$2;
20518
20958
  exports.mergeUserFilters = mergeUserFilters;
20519
20959
  exports.normalizeItemType = normalizeItemType;
20520
20960
  exports.normalizeSolutionTemplateItem = normalizeSolutionTemplateItem;
@@ -20539,13 +20979,13 @@
20539
20979
  exports.searchSites = searchSites;
20540
20980
  exports.serializeCollectionState = serializeCollectionState;
20541
20981
  exports.serializeContentFilterForPortal = serializeContentFilterForPortal;
20542
- exports.serializeDateRange = serializeDateRange$1;
20982
+ exports.serializeDateRange = serializeDateRange$2;
20543
20983
  exports.serializeFilterGroupsForPortal = serializeFilterGroupsForPortal;
20544
20984
  exports.serializeGroupFilterForPortal = serializeGroupFilterForPortal;
20545
- exports.serializeMatchOptions = serializeMatchOptions$1;
20985
+ exports.serializeMatchOptions = serializeMatchOptions$2;
20546
20986
  exports.serializeModel = serializeModel;
20547
20987
  exports.serializeSpatialReference = serializeSpatialReference;
20548
- exports.serializeStringOrArray = serializeStringOrArray$1;
20988
+ exports.serializeStringOrArray = serializeStringOrArray$2;
20549
20989
  exports.serializeUserFilterForPortal = serializeUserFilterForPortal;
20550
20990
  exports.setContentHubId = setContentHubId;
20551
20991
  exports.setContentSiteUrls = setContentSiteUrls;