@esri/hub-common 9.43.2 → 9.44.1

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 (92) hide show
  1. package/dist/es2017/ArcGISContext.js +1 -1
  2. package/dist/es2017/ArcGISContext.js.map +1 -1
  3. package/dist/es2017/items/_enrichments.js +9 -4
  4. package/dist/es2017/items/_enrichments.js.map +1 -1
  5. package/dist/es2017/search/Collection.js +71 -0
  6. package/dist/es2017/search/Collection.js.map +1 -0
  7. package/dist/es2017/search/_internal/ifilter-utils.js +221 -0
  8. package/dist/es2017/search/_internal/ifilter-utils.js.map +1 -0
  9. package/dist/es2017/search/_internal/portalSearchGroups.js +47 -2
  10. package/dist/es2017/search/_internal/portalSearchGroups.js.map +1 -1
  11. package/dist/es2017/search/_internal/portalSearchItems.js +100 -7
  12. package/dist/es2017/search/_internal/portalSearchItems.js.map +1 -1
  13. package/dist/es2017/search/_internal/portalSearchUsers.js +46 -1
  14. package/dist/es2017/search/_internal/portalSearchUsers.js.map +1 -1
  15. package/dist/es2017/search/_internal/portalSearchUtils.js +22 -0
  16. package/dist/es2017/search/_internal/portalSearchUtils.js.map +1 -0
  17. package/dist/es2017/search/filter-utils.js +1 -0
  18. package/dist/es2017/search/filter-utils.js.map +1 -1
  19. package/dist/es2017/search/hubSearch.js +47 -3
  20. package/dist/es2017/search/hubSearch.js.map +1 -1
  21. package/dist/es2017/search/types/IHubAggregation.js +1 -0
  22. package/dist/es2017/search/types/IHubAggregation.js.map +1 -0
  23. package/dist/es2017/search/types/IHubCatalog.js +1 -0
  24. package/dist/es2017/search/types/IHubCatalog.js.map +1 -0
  25. package/dist/es2017/search/types/index.js +2 -0
  26. package/dist/es2017/search/types/index.js.map +1 -1
  27. package/dist/esm/ArcGISContext.js +1 -1
  28. package/dist/esm/ArcGISContext.js.map +1 -1
  29. package/dist/esm/items/_enrichments.js +9 -4
  30. package/dist/esm/items/_enrichments.js.map +1 -1
  31. package/dist/esm/search/Collection.js +106 -0
  32. package/dist/esm/search/Collection.js.map +1 -0
  33. package/dist/esm/search/_internal/ifilter-utils.js +222 -0
  34. package/dist/esm/search/_internal/ifilter-utils.js.map +1 -0
  35. package/dist/esm/search/_internal/portalSearchGroups.js +50 -2
  36. package/dist/esm/search/_internal/portalSearchGroups.js.map +1 -1
  37. package/dist/esm/search/_internal/portalSearchItems.js +101 -7
  38. package/dist/esm/search/_internal/portalSearchItems.js.map +1 -1
  39. package/dist/esm/search/_internal/portalSearchUsers.js +49 -1
  40. package/dist/esm/search/_internal/portalSearchUsers.js.map +1 -1
  41. package/dist/esm/search/_internal/portalSearchUtils.js +22 -0
  42. package/dist/esm/search/_internal/portalSearchUtils.js.map +1 -0
  43. package/dist/esm/search/filter-utils.js +1 -0
  44. package/dist/esm/search/filter-utils.js.map +1 -1
  45. package/dist/esm/search/hubSearch.js +50 -3
  46. package/dist/esm/search/hubSearch.js.map +1 -1
  47. package/dist/esm/search/types/IHubAggregation.js +1 -0
  48. package/dist/esm/search/types/IHubAggregation.js.map +1 -0
  49. package/dist/esm/search/types/IHubCatalog.js +1 -0
  50. package/dist/esm/search/types/IHubCatalog.js.map +1 -0
  51. package/dist/esm/search/types/index.js +2 -0
  52. package/dist/esm/search/types/index.js.map +1 -1
  53. package/dist/node/ArcGISContext.js +1 -1
  54. package/dist/node/ArcGISContext.js.map +1 -1
  55. package/dist/node/items/_enrichments.js +9 -4
  56. package/dist/node/items/_enrichments.js.map +1 -1
  57. package/dist/node/search/Collection.js +75 -0
  58. package/dist/node/search/Collection.js.map +1 -0
  59. package/dist/node/search/_internal/ifilter-utils.js +226 -0
  60. package/dist/node/search/_internal/ifilter-utils.js.map +1 -0
  61. package/dist/node/search/_internal/portalSearchGroups.js +49 -3
  62. package/dist/node/search/_internal/portalSearchGroups.js.map +1 -1
  63. package/dist/node/search/_internal/portalSearchItems.js +103 -7
  64. package/dist/node/search/_internal/portalSearchItems.js.map +1 -1
  65. package/dist/node/search/_internal/portalSearchUsers.js +48 -2
  66. package/dist/node/search/_internal/portalSearchUsers.js.map +1 -1
  67. package/dist/node/search/_internal/portalSearchUtils.js +26 -0
  68. package/dist/node/search/_internal/portalSearchUtils.js.map +1 -0
  69. package/dist/node/search/filter-utils.js +1 -0
  70. package/dist/node/search/filter-utils.js.map +1 -1
  71. package/dist/node/search/hubSearch.js +48 -3
  72. package/dist/node/search/hubSearch.js.map +1 -1
  73. package/dist/node/search/types/IHubAggregation.js +3 -0
  74. package/dist/node/search/types/IHubAggregation.js.map +1 -0
  75. package/dist/node/search/types/IHubCatalog.js +3 -0
  76. package/dist/node/search/types/IHubCatalog.js.map +1 -0
  77. package/dist/node/search/types/index.js +2 -0
  78. package/dist/node/search/types/index.js.map +1 -1
  79. package/dist/types/search/Collection.d.ts +18 -0
  80. package/dist/types/search/_internal/ifilter-utils.d.ts +4 -0
  81. package/dist/types/search/_internal/portalSearchGroups.d.ts +12 -3
  82. package/dist/types/search/_internal/portalSearchItems.d.ts +28 -4
  83. package/dist/types/search/_internal/portalSearchUsers.d.ts +11 -2
  84. package/dist/types/search/_internal/portalSearchUtils.d.ts +9 -0
  85. package/dist/types/search/hubSearch.d.ts +11 -1
  86. package/dist/types/search/types/IHubAggregation.d.ts +11 -0
  87. package/dist/types/search/types/IHubCatalog.d.ts +71 -0
  88. package/dist/types/search/types/IHubSearchResponse.d.ts +2 -0
  89. package/dist/types/search/types/index.d.ts +2 -0
  90. package/dist/umd/common.umd.js +528 -49
  91. package/dist/umd/common.umd.js.map +1 -1
  92. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * @esri/hub-common - v9.43.1 - Wed Jun 22 2022 18:24:40 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/hub-common - v9.44.0 - Mon Jun 27 2022 19:59:43 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 {
@@ -13543,7 +13548,7 @@
13543
13548
  * @param join
13544
13549
  * @returns
13545
13550
  */
13546
- function mergeSearchOptions$1(so1, so2, join) {
13551
+ function mergeSearchOptions$2(so1, so2, join) {
13547
13552
  // TODO: Remove with _searchContent
13548
13553
  Logger.warn("DEPRECATION: mergeSearchOptions will be removed. Work with IFilterGroups<\"group\"> and hubSearch() instead");
13549
13554
  var result = cloneObject$1(so1);
@@ -13564,7 +13569,7 @@
13564
13569
  * @param opts
13565
13570
  * @returns
13566
13571
  */
13567
- function serializeMatchOptions$1(key, opts) {
13572
+ function serializeMatchOptions$2(key, opts) {
13568
13573
  var result = {
13569
13574
  q: "",
13570
13575
  filter: "",
@@ -13589,7 +13594,7 @@
13589
13594
  var groupFilterableFields = ["title", "typekeywords", "owner"];
13590
13595
  var filterableFields = __spreadArrays(userFilterableFields, itemFilterableFields, groupFilterableFields);
13591
13596
  if (filterableFields.includes(key)) {
13592
- result.filter = serializeStringOrArray$1("AND", key, opts.exact);
13597
+ result.filter = serializeStringOrArray$2("AND", key, opts.exact);
13593
13598
  }
13594
13599
  else {
13595
13600
  // Treat it the same as .all
@@ -13615,18 +13620,18 @@
13615
13620
  }
13616
13621
  // Handle the other props
13617
13622
  if (opts.any) {
13618
- result.q = serializeStringOrArray$1("OR", key, opts.any);
13623
+ result.q = serializeStringOrArray$2("OR", key, opts.any);
13619
13624
  }
13620
13625
  if (opts.all) {
13621
13626
  result.q =
13622
13627
  (result.q ? result.q + " AND " : "") +
13623
- serializeStringOrArray$1("AND", key, opts.all);
13628
+ serializeStringOrArray$2("AND", key, opts.all);
13624
13629
  }
13625
13630
  if (opts.not) {
13626
13631
  // negate the entries if they are not
13627
13632
  result.q =
13628
13633
  (result.q ? result.q + " AND " : "") +
13629
- serializeStringOrArray$1("OR", "-" + key, opts.not);
13634
+ serializeStringOrArray$2("OR", "-" + key, opts.not);
13630
13635
  }
13631
13636
  return result;
13632
13637
  }
@@ -13637,7 +13642,7 @@
13637
13642
  * @param range
13638
13643
  * @returns
13639
13644
  */
13640
- function serializeDateRange$1(key, range) {
13645
+ function serializeDateRange$2(key, range) {
13641
13646
  return {
13642
13647
  q: key + ":[" + range.from + " TO " + range.to + "]",
13643
13648
  filter: "",
@@ -13651,7 +13656,7 @@
13651
13656
  * @param value
13652
13657
  * @returns
13653
13658
  */
13654
- function serializeStringOrArray$1(join, key, value) {
13659
+ function serializeStringOrArray$2(join, key, value) {
13655
13660
  var q = "";
13656
13661
  if (Array.isArray(value)) {
13657
13662
  q = key + ":\"" + value.join("\" " + join + " " + key + ":\"") + "\"";
@@ -14139,12 +14144,12 @@
14139
14144
  // from hitting the else
14140
14145
  /* istanbul ignore else */
14141
14146
  if (typeof entry === "object") {
14142
- acc = mergeSearchOptions$1(acc, convertContentFilterToSearchOptions(entry), "OR");
14147
+ acc = mergeSearchOptions$2(acc, convertContentFilterToSearchOptions(entry), "OR");
14143
14148
  }
14144
14149
  return acc;
14145
14150
  }, { q: "", filter: "" });
14146
14151
  // merge with searchOptions using AND
14147
- searchOptions = mergeSearchOptions$1(searchOptions, subFilterOptions, "AND");
14152
+ searchOptions = mergeSearchOptions$2(searchOptions, subFilterOptions, "AND");
14148
14153
  }
14149
14154
  // term is always last, and pre-pended on searchOptions.q
14150
14155
  if (filter.term) {
@@ -14172,11 +14177,11 @@
14172
14177
  var key = _a[0], value = _a[1];
14173
14178
  // MatchOptions may go into either q or filter
14174
14179
  if (!specialProps.includes(key)) {
14175
- result = mergeSearchOptions$1(result, serializeMatchOptions$1(key, value), "AND");
14180
+ result = mergeSearchOptions$2(result, serializeMatchOptions$2(key, value), "AND");
14176
14181
  }
14177
14182
  // Dates only go into q
14178
14183
  if (dateProps.includes(key)) {
14179
- result = mergeSearchOptions$1(result, serializeDateRange$1(key, value), "AND");
14184
+ result = mergeSearchOptions$2(result, serializeDateRange$2(key, value), "AND");
14180
14185
  }
14181
14186
  });
14182
14187
  return result;
@@ -14307,11 +14312,11 @@
14307
14312
  var key = _a[0], value = _a[1];
14308
14313
  // MatchOptions fields
14309
14314
  if (!specialProps.includes(key)) {
14310
- result = mergeSearchOptions$1(result, serializeMatchOptions$1(key, value), "AND");
14315
+ result = mergeSearchOptions$2(result, serializeMatchOptions$2(key, value), "AND");
14311
14316
  }
14312
14317
  // Dates only go into q
14313
14318
  if (dateProps.includes(key)) {
14314
- result = mergeSearchOptions$1(result, serializeDateRange$1(key, value), "AND");
14319
+ result = mergeSearchOptions$2(result, serializeDateRange$2(key, value), "AND");
14315
14320
  }
14316
14321
  });
14317
14322
  // searchUserAccess is also a top-level property
@@ -14447,11 +14452,11 @@
14447
14452
  var key = _a[0], value = _a[1];
14448
14453
  // MatchOptions fields
14449
14454
  if (!specialProps.includes(key)) {
14450
- result = mergeSearchOptions$1(result, serializeMatchOptions$1(key, value), "AND");
14455
+ result = mergeSearchOptions$2(result, serializeMatchOptions$2(key, value), "AND");
14451
14456
  }
14452
14457
  // Dates only go into q
14453
14458
  if (dateProps.includes(key)) {
14454
- result = mergeSearchOptions$1(result, serializeDateRange$1(key, value), "AND");
14459
+ result = mergeSearchOptions$2(result, serializeDateRange$2(key, value), "AND");
14455
14460
  }
14456
14461
  });
14457
14462
  // disabled is also a top-level property
@@ -14969,6 +14974,7 @@
14969
14974
  return catalog;
14970
14975
  }
14971
14976
 
14977
+ // DEPRECATED - REMOVE THIS FILE
14972
14978
  /**
14973
14979
  * Expand a Filter into it's more expressive structure so it can be
14974
14980
  * serialized deterministically.
@@ -15021,7 +15027,7 @@
15021
15027
  */
15022
15028
  function serializeFilterGroupsForPortal(filterGroups) {
15023
15029
  var groupSearchOptions = filterGroups.map(serializeGroup);
15024
- var result = mergeSearchOptions(groupSearchOptions, "AND");
15030
+ var result = mergeSearchOptions$1(groupSearchOptions, "AND");
15025
15031
  return result;
15026
15032
  }
15027
15033
  /**
@@ -15032,9 +15038,9 @@
15032
15038
  function serializeGroup(filterGroup) {
15033
15039
  var operation = filterGroup.operation || "AND";
15034
15040
  var filters = filterGroup.filters.map(expandFilter);
15035
- var filterSearchOptions = filters.map(serializeFilter);
15041
+ var filterSearchOptions = filters.map(serializeFilter$1);
15036
15042
  // combine these searchOptions
15037
- var groupSearchOptions = mergeSearchOptions(filterSearchOptions, operation);
15043
+ var groupSearchOptions = mergeSearchOptions$1(filterSearchOptions, operation);
15038
15044
  //
15039
15045
  if (filters.length > 1) {
15040
15046
  groupSearchOptions.q = "(" + groupSearchOptions.q + ")";
@@ -15046,7 +15052,7 @@
15046
15052
  * @param filter
15047
15053
  * @returns
15048
15054
  */
15049
- function serializeFilter(filter) {
15055
+ function serializeFilter$1(filter) {
15050
15056
  var dateProps = ["created", "modified"];
15051
15057
  var boolProps = ["isopendata"];
15052
15058
  var passThroughProps = ["searchUserAccess", "searchUserName"];
@@ -15062,11 +15068,11 @@
15062
15068
  var so = { q: "" };
15063
15069
  if (!specialProps.includes(key)) {
15064
15070
  qCount++;
15065
- so.q = serializeMatchOptions(key, value);
15071
+ so.q = serializeMatchOptions$1(key, value);
15066
15072
  }
15067
15073
  if (dateProps.includes(key)) {
15068
15074
  qCount++;
15069
- so.q = serializeDateRange(key, value);
15075
+ so.q = serializeDateRange$1(key, value);
15070
15076
  }
15071
15077
  if (boolProps.includes(key)) {
15072
15078
  qCount++;
@@ -15083,13 +15089,13 @@
15083
15089
  })
15084
15090
  .filter(function (e) { return e !== undefined; });
15085
15091
  // merge up all the searchOptions
15086
- var searchOptions = mergeSearchOptions(opts, "AND");
15092
+ var searchOptions = mergeSearchOptions$1(opts, "AND");
15087
15093
  if (qCount > 1) {
15088
15094
  searchOptions.q = "(" + searchOptions.q + ")";
15089
15095
  }
15090
15096
  return searchOptions;
15091
15097
  }
15092
- function mergeSearchOptions(options, operation) {
15098
+ function mergeSearchOptions$1(options, operation) {
15093
15099
  var result = options.reduce(function (acc, entry) {
15094
15100
  // walk the props
15095
15101
  Object.entries(entry).forEach(function (_a) {
@@ -15114,21 +15120,21 @@
15114
15120
  * @param value
15115
15121
  * @returns
15116
15122
  */
15117
- function serializeMatchOptions(key, value) {
15123
+ function serializeMatchOptions$1(key, value) {
15118
15124
  var result = "";
15119
15125
  if (value.any) {
15120
- result = "" + serializeStringOrArray("OR", key, value.any);
15126
+ result = "" + serializeStringOrArray$1("OR", key, value.any);
15121
15127
  }
15122
15128
  if (value.all) {
15123
15129
  result =
15124
15130
  (result ? result + " AND " : "") +
15125
- ("" + serializeStringOrArray("AND", key, value.all));
15131
+ ("" + serializeStringOrArray$1("AND", key, value.all));
15126
15132
  }
15127
15133
  if (value.not) {
15128
15134
  // negate the entries if they are not
15129
15135
  result =
15130
15136
  (result ? result + " AND " : "") +
15131
- ("" + serializeStringOrArray("OR", "-" + key, value.not));
15137
+ ("" + serializeStringOrArray$1("OR", "-" + key, value.not));
15132
15138
  }
15133
15139
  // TODO HANDLE EXACT
15134
15140
  return result;
@@ -15139,7 +15145,7 @@
15139
15145
  * @param range
15140
15146
  * @returns
15141
15147
  */
15142
- function serializeDateRange(key, range) {
15148
+ function serializeDateRange$1(key, range) {
15143
15149
  return key + ":[" + range.from + " TO " + range.to + "]";
15144
15150
  }
15145
15151
  /**
@@ -15149,7 +15155,7 @@
15149
15155
  * @param value
15150
15156
  * @returns
15151
15157
  */
15152
- function serializeStringOrArray(join, key, value) {
15158
+ function serializeStringOrArray$1(join, key, value) {
15153
15159
  var q = "";
15154
15160
  if (Array.isArray(value)) {
15155
15161
  q = key + ":\"" + value.join("\" " + join + " " + key + ":\"") + "\"";
@@ -15327,6 +15333,224 @@
15327
15333
  };
15328
15334
  }
15329
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
+
15330
15554
  /**
15331
15555
  * Fetch Page specific Enrichments
15332
15556
  * @param item
@@ -17844,12 +18068,34 @@
17844
18068
 
17845
18069
  /**
17846
18070
  * @private
17847
- * Portal Search Implementation for Items
18071
+ * Convert a portal aggregation structure into the HubAggregations structure
18072
+ * @param searchResults
18073
+ * @returns
18074
+ */
18075
+ function convertPortalAggregations(searchResults) {
18076
+ var _a;
18077
+ if ((_a = searchResults.aggregations) === null || _a === void 0 ? void 0 : _a.counts) {
18078
+ return searchResults.aggregations.counts.map(function (entry) {
18079
+ return {
18080
+ mode: "terms",
18081
+ field: entry.fieldName,
18082
+ values: entry.fieldValues,
18083
+ };
18084
+ });
18085
+ }
18086
+ else {
18087
+ return [];
18088
+ }
18089
+ }
18090
+
18091
+ /**
18092
+ * @private
18093
+ * DEPRECATED
17848
18094
  * @param filterGroups
17849
18095
  * @param options
17850
18096
  * @returns
17851
18097
  */
17852
- function portalSearchItems(filterGroups, options) {
18098
+ function portalSearchItemsFilterGroups(filterGroups, options) {
17853
18099
  var _a;
17854
18100
  return __awaiter(this, void 0, void 0, function () {
17855
18101
  var replaced, expandedGroups, so, props;
@@ -17857,7 +18103,7 @@
17857
18103
  if (!options.requestOptions) {
17858
18104
  throw new HubError$1("hubSearch", "requestOptions: IHubRequestOptions is required.");
17859
18105
  }
17860
- replaced = applyWellKnownItemFilters(filterGroups);
18106
+ replaced = applyWellKnownItemFilterGroups(filterGroups);
17861
18107
  expandedGroups = replaced.map(function (fg) {
17862
18108
  fg.filters = fg.filters.map(expandFilter);
17863
18109
  return fg;
@@ -17892,6 +18138,57 @@
17892
18138
  });
17893
18139
  });
17894
18140
  }
18141
+ /**
18142
+ * @private
18143
+ * Portal Search Implementation for Items
18144
+ * @param query
18145
+ * @param options
18146
+ * @returns
18147
+ */
18148
+ function portalSearchItems(query, options) {
18149
+ var _a;
18150
+ return __awaiter(this, void 0, void 0, function () {
18151
+ var updatedQuery, so, props;
18152
+ return __generator(this, function (_b) {
18153
+ if (!options.requestOptions) {
18154
+ throw new HubError$1("portalSearchItems", "options.requestOptions is required.");
18155
+ }
18156
+ updatedQuery = applyWellKnownItemPredicates(query);
18157
+ // Expand the individual predicates in each filter
18158
+ updatedQuery.filters = updatedQuery.filters.map(function (filter) {
18159
+ filter.predicates = filter.predicates.map(expandPredicate);
18160
+ return filter;
18161
+ });
18162
+ so = serializeQueryForPortal(updatedQuery);
18163
+ props = [
18164
+ "num",
18165
+ "sortField",
18166
+ "sortOrder",
18167
+ "include",
18168
+ "start",
18169
+ "requestOptions",
18170
+ ];
18171
+ // copy the props over
18172
+ props.forEach(function (prop) {
18173
+ if (options.hasOwnProperty(prop)) {
18174
+ so[prop] = options[prop];
18175
+ }
18176
+ });
18177
+ if (options.requestOptions.authentication) {
18178
+ so.authentication = options.requestOptions.authentication;
18179
+ }
18180
+ else {
18181
+ so.portal = options.requestOptions.portal;
18182
+ }
18183
+ // Aggregations
18184
+ if ((_a = options.aggFields) === null || _a === void 0 ? void 0 : _a.length) {
18185
+ so.countFields = options.aggFields.join(",");
18186
+ so.countSize = options.aggLimit || 10;
18187
+ }
18188
+ return [2 /*return*/, searchPortal$2(so)];
18189
+ });
18190
+ });
18191
+ }
17895
18192
  /**
17896
18193
  * Internal portal search, which then converts `IItem`s to `IHubSearchResult`s
17897
18194
  * handling enrichments & includes along the way
@@ -17901,7 +18198,7 @@
17901
18198
  */
17902
18199
  function searchPortal$2(searchOptions) {
17903
18200
  return __awaiter(this, void 0, void 0, function () {
17904
- var resp, fn, results, facets;
18201
+ var resp, fn, results, facets, aggregations;
17905
18202
  return __generator(this, function (_a) {
17906
18203
  switch (_a.label) {
17907
18204
  case 0: return [4 /*yield*/, searchItems(searchOptions)];
@@ -17914,11 +18211,13 @@
17914
18211
  case 2:
17915
18212
  results = _a.sent();
17916
18213
  facets = convertPortalItemResponseToFacets(resp);
18214
+ aggregations = convertPortalAggregations(resp);
17917
18215
  // Construct the return
17918
18216
  return [2 /*return*/, {
17919
18217
  total: resp.total,
17920
18218
  results: results,
17921
18219
  facets: facets,
18220
+ aggregations: aggregations,
17922
18221
  hasNext: resp.nextStart > -1,
17923
18222
  next: getNextFunction(searchOptions, resp.nextStart, resp.total, searchPortal$2),
17924
18223
  }];
@@ -18132,7 +18431,36 @@
18132
18431
  * Only exported to enable extensive testing
18133
18432
  * @param filterGroups
18134
18433
  */
18135
- function applyWellKnownItemFilters(filterGroups) {
18434
+ function applyWellKnownItemPredicates(query) {
18435
+ var queryClone = cloneObject$1(query);
18436
+ // iterate the filters
18437
+ queryClone.filters = queryClone.filters.map(function (filter) {
18438
+ // replace predicates with well-known types
18439
+ filter.predicates = filter.predicates.reduce(function (acc, predicate) {
18440
+ // if the predicate has a well-known type
18441
+ // we replace it with the set of predicates defined
18442
+ // for the well-known type
18443
+ if (isWellKnownTypeFilter(predicate.type)) {
18444
+ var replacements = lookupTypePredicates(predicate.type);
18445
+ acc = __spreadArrays(acc, replacements);
18446
+ }
18447
+ else {
18448
+ // this predicate does not have a well-known type
18449
+ // so we just keep it
18450
+ acc.push(predicate);
18451
+ }
18452
+ return acc;
18453
+ }, []);
18454
+ return filter;
18455
+ });
18456
+ return queryClone;
18457
+ }
18458
+ /**
18459
+ * DEPRECATED
18460
+ * @param filterGroups
18461
+ * @returns
18462
+ */
18463
+ function applyWellKnownItemFilterGroups(filterGroups) {
18136
18464
  var clone = cloneObject$1(filterGroups);
18137
18465
  // iterate the filterGroups
18138
18466
  var result = clone.map(function (filterGroup) {
@@ -18184,6 +18512,16 @@
18184
18512
  function lookupTypeFilters(key) {
18185
18513
  return WellKnownItemFilters[key];
18186
18514
  }
18515
+ function lookupTypePredicates(key) {
18516
+ var rawPredicates = WellKnownItemFilters[key];
18517
+ // Remove the filterType property as it's not needed in an IPredicate
18518
+ var predicates = rawPredicates.map(function (entry) {
18519
+ var c = cloneObject$1(entry);
18520
+ delete c.filterType;
18521
+ return c;
18522
+ });
18523
+ return predicates;
18524
+ }
18187
18525
 
18188
18526
  // ## ## ####### ######## ########
18189
18527
  // ### ## ## ## ## ##
@@ -18387,12 +18725,13 @@
18387
18725
 
18388
18726
  /**
18389
18727
  * @private
18390
- * Portal Search Implementation for Items
18728
+ * DEPRECATED: Use `portalSerchGroups`
18729
+ * Portal Search Implementation for Groups
18391
18730
  * @param filterGroups
18392
18731
  * @param options
18393
18732
  * @returns
18394
18733
  */
18395
- function portalSearchGroups(filterGroups, options) {
18734
+ function portalSearchGroupsFilterGroups(filterGroups, options) {
18396
18735
  return __awaiter(this, void 0, void 0, function () {
18397
18736
  var api, expandedGroups, so, props;
18398
18737
  return __generator(this, function (_a) {
@@ -18439,6 +18778,51 @@
18439
18778
  });
18440
18779
  });
18441
18780
  }
18781
+ /**
18782
+ * @private
18783
+ * Portal Search Implementation for Groups
18784
+ * @param query
18785
+ * @param options
18786
+ * @returns
18787
+ */
18788
+ function portalSearchGroups(query, options) {
18789
+ return __awaiter(this, void 0, void 0, function () {
18790
+ var so, props;
18791
+ return __generator(this, function (_a) {
18792
+ if (!options.requestOptions) {
18793
+ throw new HubError$1("portalSearchGroups", "options.requestOptions is required.");
18794
+ }
18795
+ // Expand the individual predicates in each filter
18796
+ query.filters = query.filters.map(function (filter) {
18797
+ filter.predicates = filter.predicates.map(expandPredicate);
18798
+ return filter;
18799
+ });
18800
+ so = serializeQueryForPortal(query);
18801
+ props = [
18802
+ "num",
18803
+ "sortField",
18804
+ "sortOrder",
18805
+ "include",
18806
+ "start",
18807
+ "requestOptions",
18808
+ ];
18809
+ // copy the props over
18810
+ props.forEach(function (prop) {
18811
+ if (options.hasOwnProperty(prop)) {
18812
+ so[prop] = options[prop];
18813
+ }
18814
+ });
18815
+ // If we don't have auth, ensure we have .portal
18816
+ if (options.requestOptions.authentication) {
18817
+ so.authentication = options.requestOptions.authentication;
18818
+ }
18819
+ else {
18820
+ so.portal = options.requestOptions.portal;
18821
+ }
18822
+ return [2 /*return*/, searchPortal$1(so)];
18823
+ });
18824
+ });
18825
+ }
18442
18826
  /**
18443
18827
  * Internal portal search, which then converts `IGroup`s to `IHubSearchResult`s
18444
18828
  * handling enrichments & includes along the way
@@ -18496,11 +18880,12 @@
18496
18880
 
18497
18881
  /**
18498
18882
  * @private
18883
+ * DEPRECATED: Use `portalSearchUsers`
18499
18884
  * Portal Search implementation for Users
18500
18885
  * @param filterGroups
18501
18886
  * @param options
18502
18887
  */
18503
- function portalSearchUsers(filterGroups, options) {
18888
+ function portalSearchUsersFilterGroups(filterGroups, options) {
18504
18889
  return __awaiter(this, void 0, void 0, function () {
18505
18890
  var expandedGroups, so, props;
18506
18891
  return __generator(this, function (_a) {
@@ -18537,6 +18922,52 @@
18537
18922
  });
18538
18923
  });
18539
18924
  }
18925
+ /**
18926
+ * @private
18927
+ * Portal Search Implementation for Users
18928
+ * @param filterGroups
18929
+ * @param options
18930
+ * @returns
18931
+ */
18932
+ function portalSearchUsers(query, options) {
18933
+ return __awaiter(this, void 0, void 0, function () {
18934
+ var so, props;
18935
+ return __generator(this, function (_a) {
18936
+ // requestOptions is always required and user must be authd
18937
+ if (!options.requestOptions) {
18938
+ throw new HubError$1("portalSearchUsers", "requestOptions: IHubRequestOptions is required.");
18939
+ }
18940
+ if (!options.requestOptions.authentication) {
18941
+ throw new HubError$1("portalSearchUsers", "requestOptions must pass authentication.");
18942
+ }
18943
+ // Expand the individual predicates in each filter
18944
+ query.filters = query.filters.map(function (filter) {
18945
+ filter.predicates = filter.predicates.map(expandPredicate);
18946
+ return filter;
18947
+ });
18948
+ so = serializeQueryForPortal(query);
18949
+ props = [
18950
+ "num",
18951
+ "sortField",
18952
+ "sortOrder",
18953
+ "include",
18954
+ "start",
18955
+ "requestOptions",
18956
+ ];
18957
+ // copy the props over
18958
+ props.forEach(function (prop) {
18959
+ if (options.hasOwnProperty(prop)) {
18960
+ so[prop] = options[prop];
18961
+ }
18962
+ });
18963
+ // Unlike Groups and Item, the Users api *requires* authentication
18964
+ // so we set it directly
18965
+ so.authentication = options.requestOptions.authentication;
18966
+ // Execute search
18967
+ return [2 /*return*/, searchPortal(so)];
18968
+ });
18969
+ });
18970
+ }
18540
18971
  /**
18541
18972
  * Internal portal search, which then converts `IGroup`s to `IHubSearchResult`s
18542
18973
  * handling enrichments & includes along the way
@@ -18621,6 +19052,53 @@
18621
19052
  }
18622
19053
  filterType = filterGroups[0].filterType;
18623
19054
  apiType = expandApi(options.api || "arcgis").type;
19055
+ fnHash = {
19056
+ arcgis: {
19057
+ item: portalSearchItemsFilterGroups,
19058
+ group: portalSearchGroupsFilterGroups,
19059
+ user: portalSearchUsersFilterGroups,
19060
+ },
19061
+ "arcgis-hub": {
19062
+ item: hubSearchItems,
19063
+ },
19064
+ };
19065
+ fn = getProp(fnHash, apiType + "." + filterType);
19066
+ if (!fn) {
19067
+ throw new HubError$1("hubSearch", "Search via \"" + filterType + "\" filter against \"" + apiType + "\" api is not implemented");
19068
+ }
19069
+ return [2 /*return*/, fn(cloneObject$1(filterGroups), options)];
19070
+ });
19071
+ });
19072
+ }
19073
+ /**
19074
+ * Main entrypoint for searching via Hub
19075
+ *
19076
+ * Default's to search ArcGIS Portal but can delegate
19077
+ * to Hub API when it's available.
19078
+ * @param query
19079
+ * @param options
19080
+ * @returns
19081
+ */
19082
+ function hubSearchQuery(query, options) {
19083
+ return __awaiter(this, void 0, void 0, function () {
19084
+ var filterType, apiType, fnHash, fn;
19085
+ return __generator(this, function (_a) {
19086
+ // Validate inputs
19087
+ if (!query) {
19088
+ throw new HubError$1("hubSearch", "Query is required.");
19089
+ }
19090
+ if (!query.filters || !query.filters.length) {
19091
+ throw new HubError$1("hubSearch", "Query must contain at least one Filter.");
19092
+ }
19093
+ if (!options.requestOptions) {
19094
+ throw new HubError$1("hubSearch", "requestOptions: IHubRequestOptions is required.");
19095
+ }
19096
+ // Ensure includes is an array
19097
+ if (!options.include) {
19098
+ options.include = [];
19099
+ }
19100
+ filterType = query.targetEntity;
19101
+ apiType = expandApi(options.api || "arcgis").type;
18624
19102
  fnHash = {
18625
19103
  arcgis: {
18626
19104
  item: portalSearchItems,
@@ -18635,7 +19113,7 @@
18635
19113
  if (!fn) {
18636
19114
  throw new HubError$1("hubSearch", "Search via \"" + filterType + "\" filter against \"" + apiType + "\" api is not implemented");
18637
19115
  }
18638
- return [2 /*return*/, fn(cloneObject$1(filterGroups), options)];
19116
+ return [2 /*return*/, fn(cloneObject$1(query), options)];
18639
19117
  });
18640
19118
  });
18641
19119
  }
@@ -20474,6 +20952,7 @@
20474
20952
  exports.hubApiRequest = hubApiRequest;
20475
20953
  exports.hubApiSearch = hubApiSearch;
20476
20954
  exports.hubSearch = hubSearch;
20955
+ exports.hubSearchQuery = hubSearchQuery;
20477
20956
  exports.includes = includes;
20478
20957
  exports.incrementString = incrementString;
20479
20958
  exports.interpolate = interpolate;
@@ -20508,7 +20987,7 @@
20508
20987
  exports.mergeGroupFilters = mergeGroupFilters;
20509
20988
  exports.mergeMatchOptions = mergeMatchOptions;
20510
20989
  exports.mergeObjects = mergeObjects;
20511
- exports.mergeSearchOptions = mergeSearchOptions$1;
20990
+ exports.mergeSearchOptions = mergeSearchOptions$2;
20512
20991
  exports.mergeUserFilters = mergeUserFilters;
20513
20992
  exports.normalizeItemType = normalizeItemType;
20514
20993
  exports.normalizeSolutionTemplateItem = normalizeSolutionTemplateItem;
@@ -20533,13 +21012,13 @@
20533
21012
  exports.searchSites = searchSites;
20534
21013
  exports.serializeCollectionState = serializeCollectionState;
20535
21014
  exports.serializeContentFilterForPortal = serializeContentFilterForPortal;
20536
- exports.serializeDateRange = serializeDateRange$1;
21015
+ exports.serializeDateRange = serializeDateRange$2;
20537
21016
  exports.serializeFilterGroupsForPortal = serializeFilterGroupsForPortal;
20538
21017
  exports.serializeGroupFilterForPortal = serializeGroupFilterForPortal;
20539
- exports.serializeMatchOptions = serializeMatchOptions$1;
21018
+ exports.serializeMatchOptions = serializeMatchOptions$2;
20540
21019
  exports.serializeModel = serializeModel;
20541
21020
  exports.serializeSpatialReference = serializeSpatialReference;
20542
- exports.serializeStringOrArray = serializeStringOrArray$1;
21021
+ exports.serializeStringOrArray = serializeStringOrArray$2;
20543
21022
  exports.serializeUserFilterForPortal = serializeUserFilterForPortal;
20544
21023
  exports.setContentHubId = setContentHubId;
20545
21024
  exports.setContentSiteUrls = setContentSiteUrls;