@esri/hub-common 9.43.3 → 9.45.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 (87) hide show
  1. package/dist/es2017/ArcGISContext.js +1 -1
  2. package/dist/es2017/ArcGISContext.js.map +1 -1
  3. package/dist/es2017/search/Collection.js +71 -0
  4. package/dist/es2017/search/Collection.js.map +1 -0
  5. package/dist/es2017/search/_internal/ifilter-utils.js +221 -0
  6. package/dist/es2017/search/_internal/ifilter-utils.js.map +1 -0
  7. package/dist/es2017/search/_internal/portalSearchGroups.js +47 -2
  8. package/dist/es2017/search/_internal/portalSearchGroups.js.map +1 -1
  9. package/dist/es2017/search/_internal/portalSearchItems.js +100 -7
  10. package/dist/es2017/search/_internal/portalSearchItems.js.map +1 -1
  11. package/dist/es2017/search/_internal/portalSearchUsers.js +46 -1
  12. package/dist/es2017/search/_internal/portalSearchUsers.js.map +1 -1
  13. package/dist/es2017/search/_internal/portalSearchUtils.js +22 -0
  14. package/dist/es2017/search/_internal/portalSearchUtils.js.map +1 -0
  15. package/dist/es2017/search/filter-utils.js +1 -0
  16. package/dist/es2017/search/filter-utils.js.map +1 -1
  17. package/dist/es2017/search/hubSearch.js +47 -3
  18. package/dist/es2017/search/hubSearch.js.map +1 -1
  19. package/dist/es2017/search/types/IHubAggregation.js +1 -0
  20. package/dist/es2017/search/types/IHubAggregation.js.map +1 -0
  21. package/dist/es2017/search/types/IHubCatalog.js +1 -0
  22. package/dist/es2017/search/types/IHubCatalog.js.map +1 -0
  23. package/dist/es2017/search/types/index.js +2 -0
  24. package/dist/es2017/search/types/index.js.map +1 -1
  25. package/dist/esm/ArcGISContext.js +1 -1
  26. package/dist/esm/ArcGISContext.js.map +1 -1
  27. package/dist/esm/search/Collection.js +106 -0
  28. package/dist/esm/search/Collection.js.map +1 -0
  29. package/dist/esm/search/_internal/ifilter-utils.js +222 -0
  30. package/dist/esm/search/_internal/ifilter-utils.js.map +1 -0
  31. package/dist/esm/search/_internal/portalSearchGroups.js +50 -2
  32. package/dist/esm/search/_internal/portalSearchGroups.js.map +1 -1
  33. package/dist/esm/search/_internal/portalSearchItems.js +101 -7
  34. package/dist/esm/search/_internal/portalSearchItems.js.map +1 -1
  35. package/dist/esm/search/_internal/portalSearchUsers.js +49 -1
  36. package/dist/esm/search/_internal/portalSearchUsers.js.map +1 -1
  37. package/dist/esm/search/_internal/portalSearchUtils.js +22 -0
  38. package/dist/esm/search/_internal/portalSearchUtils.js.map +1 -0
  39. package/dist/esm/search/filter-utils.js +1 -0
  40. package/dist/esm/search/filter-utils.js.map +1 -1
  41. package/dist/esm/search/hubSearch.js +50 -3
  42. package/dist/esm/search/hubSearch.js.map +1 -1
  43. package/dist/esm/search/types/IHubAggregation.js +1 -0
  44. package/dist/esm/search/types/IHubAggregation.js.map +1 -0
  45. package/dist/esm/search/types/IHubCatalog.js +1 -0
  46. package/dist/esm/search/types/IHubCatalog.js.map +1 -0
  47. package/dist/esm/search/types/index.js +2 -0
  48. package/dist/esm/search/types/index.js.map +1 -1
  49. package/dist/node/ArcGISContext.js +1 -1
  50. package/dist/node/ArcGISContext.js.map +1 -1
  51. package/dist/node/search/Collection.js +75 -0
  52. package/dist/node/search/Collection.js.map +1 -0
  53. package/dist/node/search/_internal/ifilter-utils.js +226 -0
  54. package/dist/node/search/_internal/ifilter-utils.js.map +1 -0
  55. package/dist/node/search/_internal/portalSearchGroups.js +49 -3
  56. package/dist/node/search/_internal/portalSearchGroups.js.map +1 -1
  57. package/dist/node/search/_internal/portalSearchItems.js +103 -7
  58. package/dist/node/search/_internal/portalSearchItems.js.map +1 -1
  59. package/dist/node/search/_internal/portalSearchUsers.js +48 -2
  60. package/dist/node/search/_internal/portalSearchUsers.js.map +1 -1
  61. package/dist/node/search/_internal/portalSearchUtils.js +26 -0
  62. package/dist/node/search/_internal/portalSearchUtils.js.map +1 -0
  63. package/dist/node/search/filter-utils.js +1 -0
  64. package/dist/node/search/filter-utils.js.map +1 -1
  65. package/dist/node/search/hubSearch.js +48 -3
  66. package/dist/node/search/hubSearch.js.map +1 -1
  67. package/dist/node/search/types/IHubAggregation.js +3 -0
  68. package/dist/node/search/types/IHubAggregation.js.map +1 -0
  69. package/dist/node/search/types/IHubCatalog.js +3 -0
  70. package/dist/node/search/types/IHubCatalog.js.map +1 -0
  71. package/dist/node/search/types/index.js +2 -0
  72. package/dist/node/search/types/index.js.map +1 -1
  73. package/dist/types/core/types/IHubTimeline.d.ts +0 -5
  74. package/dist/types/search/Collection.d.ts +18 -0
  75. package/dist/types/search/_internal/ifilter-utils.d.ts +4 -0
  76. package/dist/types/search/_internal/portalSearchGroups.d.ts +12 -3
  77. package/dist/types/search/_internal/portalSearchItems.d.ts +28 -4
  78. package/dist/types/search/_internal/portalSearchUsers.d.ts +11 -2
  79. package/dist/types/search/_internal/portalSearchUtils.d.ts +9 -0
  80. package/dist/types/search/hubSearch.d.ts +11 -1
  81. package/dist/types/search/types/IHubAggregation.d.ts +11 -0
  82. package/dist/types/search/types/IHubCatalog.d.ts +71 -0
  83. package/dist/types/search/types/IHubSearchResponse.d.ts +2 -0
  84. package/dist/types/search/types/index.d.ts +2 -0
  85. package/dist/umd/common.umd.js +519 -45
  86. package/dist/umd/common.umd.js.map +1 -1
  87. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * @esri/hub-common - v9.43.2 - Thu Jun 23 2022 17:43:06 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/hub-common - v9.44.1 - Tue Jun 28 2022 15:39:40 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 {
@@ -13548,7 +13548,7 @@
13548
13548
  * @param join
13549
13549
  * @returns
13550
13550
  */
13551
- function mergeSearchOptions$1(so1, so2, join) {
13551
+ function mergeSearchOptions$2(so1, so2, join) {
13552
13552
  // TODO: Remove with _searchContent
13553
13553
  Logger.warn("DEPRECATION: mergeSearchOptions will be removed. Work with IFilterGroups<\"group\"> and hubSearch() instead");
13554
13554
  var result = cloneObject$1(so1);
@@ -13569,7 +13569,7 @@
13569
13569
  * @param opts
13570
13570
  * @returns
13571
13571
  */
13572
- function serializeMatchOptions$1(key, opts) {
13572
+ function serializeMatchOptions$2(key, opts) {
13573
13573
  var result = {
13574
13574
  q: "",
13575
13575
  filter: "",
@@ -13594,7 +13594,7 @@
13594
13594
  var groupFilterableFields = ["title", "typekeywords", "owner"];
13595
13595
  var filterableFields = __spreadArrays(userFilterableFields, itemFilterableFields, groupFilterableFields);
13596
13596
  if (filterableFields.includes(key)) {
13597
- result.filter = serializeStringOrArray$1("AND", key, opts.exact);
13597
+ result.filter = serializeStringOrArray$2("AND", key, opts.exact);
13598
13598
  }
13599
13599
  else {
13600
13600
  // Treat it the same as .all
@@ -13620,18 +13620,18 @@
13620
13620
  }
13621
13621
  // Handle the other props
13622
13622
  if (opts.any) {
13623
- result.q = serializeStringOrArray$1("OR", key, opts.any);
13623
+ result.q = serializeStringOrArray$2("OR", key, opts.any);
13624
13624
  }
13625
13625
  if (opts.all) {
13626
13626
  result.q =
13627
13627
  (result.q ? result.q + " AND " : "") +
13628
- serializeStringOrArray$1("AND", key, opts.all);
13628
+ serializeStringOrArray$2("AND", key, opts.all);
13629
13629
  }
13630
13630
  if (opts.not) {
13631
13631
  // negate the entries if they are not
13632
13632
  result.q =
13633
13633
  (result.q ? result.q + " AND " : "") +
13634
- serializeStringOrArray$1("OR", "-" + key, opts.not);
13634
+ serializeStringOrArray$2("OR", "-" + key, opts.not);
13635
13635
  }
13636
13636
  return result;
13637
13637
  }
@@ -13642,7 +13642,7 @@
13642
13642
  * @param range
13643
13643
  * @returns
13644
13644
  */
13645
- function serializeDateRange$1(key, range) {
13645
+ function serializeDateRange$2(key, range) {
13646
13646
  return {
13647
13647
  q: key + ":[" + range.from + " TO " + range.to + "]",
13648
13648
  filter: "",
@@ -13656,7 +13656,7 @@
13656
13656
  * @param value
13657
13657
  * @returns
13658
13658
  */
13659
- function serializeStringOrArray$1(join, key, value) {
13659
+ function serializeStringOrArray$2(join, key, value) {
13660
13660
  var q = "";
13661
13661
  if (Array.isArray(value)) {
13662
13662
  q = key + ":\"" + value.join("\" " + join + " " + key + ":\"") + "\"";
@@ -14144,12 +14144,12 @@
14144
14144
  // from hitting the else
14145
14145
  /* istanbul ignore else */
14146
14146
  if (typeof entry === "object") {
14147
- acc = mergeSearchOptions$1(acc, convertContentFilterToSearchOptions(entry), "OR");
14147
+ acc = mergeSearchOptions$2(acc, convertContentFilterToSearchOptions(entry), "OR");
14148
14148
  }
14149
14149
  return acc;
14150
14150
  }, { q: "", filter: "" });
14151
14151
  // merge with searchOptions using AND
14152
- searchOptions = mergeSearchOptions$1(searchOptions, subFilterOptions, "AND");
14152
+ searchOptions = mergeSearchOptions$2(searchOptions, subFilterOptions, "AND");
14153
14153
  }
14154
14154
  // term is always last, and pre-pended on searchOptions.q
14155
14155
  if (filter.term) {
@@ -14177,11 +14177,11 @@
14177
14177
  var key = _a[0], value = _a[1];
14178
14178
  // MatchOptions may go into either q or filter
14179
14179
  if (!specialProps.includes(key)) {
14180
- result = mergeSearchOptions$1(result, serializeMatchOptions$1(key, value), "AND");
14180
+ result = mergeSearchOptions$2(result, serializeMatchOptions$2(key, value), "AND");
14181
14181
  }
14182
14182
  // Dates only go into q
14183
14183
  if (dateProps.includes(key)) {
14184
- result = mergeSearchOptions$1(result, serializeDateRange$1(key, value), "AND");
14184
+ result = mergeSearchOptions$2(result, serializeDateRange$2(key, value), "AND");
14185
14185
  }
14186
14186
  });
14187
14187
  return result;
@@ -14312,11 +14312,11 @@
14312
14312
  var key = _a[0], value = _a[1];
14313
14313
  // MatchOptions fields
14314
14314
  if (!specialProps.includes(key)) {
14315
- result = mergeSearchOptions$1(result, serializeMatchOptions$1(key, value), "AND");
14315
+ result = mergeSearchOptions$2(result, serializeMatchOptions$2(key, value), "AND");
14316
14316
  }
14317
14317
  // Dates only go into q
14318
14318
  if (dateProps.includes(key)) {
14319
- result = mergeSearchOptions$1(result, serializeDateRange$1(key, value), "AND");
14319
+ result = mergeSearchOptions$2(result, serializeDateRange$2(key, value), "AND");
14320
14320
  }
14321
14321
  });
14322
14322
  // searchUserAccess is also a top-level property
@@ -14452,11 +14452,11 @@
14452
14452
  var key = _a[0], value = _a[1];
14453
14453
  // MatchOptions fields
14454
14454
  if (!specialProps.includes(key)) {
14455
- result = mergeSearchOptions$1(result, serializeMatchOptions$1(key, value), "AND");
14455
+ result = mergeSearchOptions$2(result, serializeMatchOptions$2(key, value), "AND");
14456
14456
  }
14457
14457
  // Dates only go into q
14458
14458
  if (dateProps.includes(key)) {
14459
- result = mergeSearchOptions$1(result, serializeDateRange$1(key, value), "AND");
14459
+ result = mergeSearchOptions$2(result, serializeDateRange$2(key, value), "AND");
14460
14460
  }
14461
14461
  });
14462
14462
  // disabled is also a top-level property
@@ -14974,6 +14974,7 @@
14974
14974
  return catalog;
14975
14975
  }
14976
14976
 
14977
+ // DEPRECATED - REMOVE THIS FILE
14977
14978
  /**
14978
14979
  * Expand a Filter into it's more expressive structure so it can be
14979
14980
  * serialized deterministically.
@@ -15026,7 +15027,7 @@
15026
15027
  */
15027
15028
  function serializeFilterGroupsForPortal(filterGroups) {
15028
15029
  var groupSearchOptions = filterGroups.map(serializeGroup);
15029
- var result = mergeSearchOptions(groupSearchOptions, "AND");
15030
+ var result = mergeSearchOptions$1(groupSearchOptions, "AND");
15030
15031
  return result;
15031
15032
  }
15032
15033
  /**
@@ -15037,9 +15038,9 @@
15037
15038
  function serializeGroup(filterGroup) {
15038
15039
  var operation = filterGroup.operation || "AND";
15039
15040
  var filters = filterGroup.filters.map(expandFilter);
15040
- var filterSearchOptions = filters.map(serializeFilter);
15041
+ var filterSearchOptions = filters.map(serializeFilter$1);
15041
15042
  // combine these searchOptions
15042
- var groupSearchOptions = mergeSearchOptions(filterSearchOptions, operation);
15043
+ var groupSearchOptions = mergeSearchOptions$1(filterSearchOptions, operation);
15043
15044
  //
15044
15045
  if (filters.length > 1) {
15045
15046
  groupSearchOptions.q = "(" + groupSearchOptions.q + ")";
@@ -15051,7 +15052,7 @@
15051
15052
  * @param filter
15052
15053
  * @returns
15053
15054
  */
15054
- function serializeFilter(filter) {
15055
+ function serializeFilter$1(filter) {
15055
15056
  var dateProps = ["created", "modified"];
15056
15057
  var boolProps = ["isopendata"];
15057
15058
  var passThroughProps = ["searchUserAccess", "searchUserName"];
@@ -15067,11 +15068,11 @@
15067
15068
  var so = { q: "" };
15068
15069
  if (!specialProps.includes(key)) {
15069
15070
  qCount++;
15070
- so.q = serializeMatchOptions(key, value);
15071
+ so.q = serializeMatchOptions$1(key, value);
15071
15072
  }
15072
15073
  if (dateProps.includes(key)) {
15073
15074
  qCount++;
15074
- so.q = serializeDateRange(key, value);
15075
+ so.q = serializeDateRange$1(key, value);
15075
15076
  }
15076
15077
  if (boolProps.includes(key)) {
15077
15078
  qCount++;
@@ -15088,13 +15089,13 @@
15088
15089
  })
15089
15090
  .filter(function (e) { return e !== undefined; });
15090
15091
  // merge up all the searchOptions
15091
- var searchOptions = mergeSearchOptions(opts, "AND");
15092
+ var searchOptions = mergeSearchOptions$1(opts, "AND");
15092
15093
  if (qCount > 1) {
15093
15094
  searchOptions.q = "(" + searchOptions.q + ")";
15094
15095
  }
15095
15096
  return searchOptions;
15096
15097
  }
15097
- function mergeSearchOptions(options, operation) {
15098
+ function mergeSearchOptions$1(options, operation) {
15098
15099
  var result = options.reduce(function (acc, entry) {
15099
15100
  // walk the props
15100
15101
  Object.entries(entry).forEach(function (_a) {
@@ -15119,21 +15120,21 @@
15119
15120
  * @param value
15120
15121
  * @returns
15121
15122
  */
15122
- function serializeMatchOptions(key, value) {
15123
+ function serializeMatchOptions$1(key, value) {
15123
15124
  var result = "";
15124
15125
  if (value.any) {
15125
- result = "" + serializeStringOrArray("OR", key, value.any);
15126
+ result = "" + serializeStringOrArray$1("OR", key, value.any);
15126
15127
  }
15127
15128
  if (value.all) {
15128
15129
  result =
15129
15130
  (result ? result + " AND " : "") +
15130
- ("" + serializeStringOrArray("AND", key, value.all));
15131
+ ("" + serializeStringOrArray$1("AND", key, value.all));
15131
15132
  }
15132
15133
  if (value.not) {
15133
15134
  // negate the entries if they are not
15134
15135
  result =
15135
15136
  (result ? result + " AND " : "") +
15136
- ("" + serializeStringOrArray("OR", "-" + key, value.not));
15137
+ ("" + serializeStringOrArray$1("OR", "-" + key, value.not));
15137
15138
  }
15138
15139
  // TODO HANDLE EXACT
15139
15140
  return result;
@@ -15144,7 +15145,7 @@
15144
15145
  * @param range
15145
15146
  * @returns
15146
15147
  */
15147
- function serializeDateRange(key, range) {
15148
+ function serializeDateRange$1(key, range) {
15148
15149
  return key + ":[" + range.from + " TO " + range.to + "]";
15149
15150
  }
15150
15151
  /**
@@ -15154,7 +15155,7 @@
15154
15155
  * @param value
15155
15156
  * @returns
15156
15157
  */
15157
- function serializeStringOrArray(join, key, value) {
15158
+ function serializeStringOrArray$1(join, key, value) {
15158
15159
  var q = "";
15159
15160
  if (Array.isArray(value)) {
15160
15161
  q = key + ":\"" + value.join("\" " + join + " " + key + ":\"") + "\"";
@@ -15332,6 +15333,224 @@
15332
15333
  };
15333
15334
  }
15334
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
+
15335
15554
  /**
15336
15555
  * Fetch Page specific Enrichments
15337
15556
  * @param item
@@ -17849,12 +18068,34 @@
17849
18068
 
17850
18069
  /**
17851
18070
  * @private
17852
- * 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
17853
18094
  * @param filterGroups
17854
18095
  * @param options
17855
18096
  * @returns
17856
18097
  */
17857
- function portalSearchItems(filterGroups, options) {
18098
+ function portalSearchItemsFilterGroups(filterGroups, options) {
17858
18099
  var _a;
17859
18100
  return __awaiter(this, void 0, void 0, function () {
17860
18101
  var replaced, expandedGroups, so, props;
@@ -17862,7 +18103,7 @@
17862
18103
  if (!options.requestOptions) {
17863
18104
  throw new HubError$1("hubSearch", "requestOptions: IHubRequestOptions is required.");
17864
18105
  }
17865
- replaced = applyWellKnownItemFilters(filterGroups);
18106
+ replaced = applyWellKnownItemFilterGroups(filterGroups);
17866
18107
  expandedGroups = replaced.map(function (fg) {
17867
18108
  fg.filters = fg.filters.map(expandFilter);
17868
18109
  return fg;
@@ -17897,6 +18138,57 @@
17897
18138
  });
17898
18139
  });
17899
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
+ }
17900
18192
  /**
17901
18193
  * Internal portal search, which then converts `IItem`s to `IHubSearchResult`s
17902
18194
  * handling enrichments & includes along the way
@@ -17906,7 +18198,7 @@
17906
18198
  */
17907
18199
  function searchPortal$2(searchOptions) {
17908
18200
  return __awaiter(this, void 0, void 0, function () {
17909
- var resp, fn, results, facets;
18201
+ var resp, fn, results, facets, aggregations;
17910
18202
  return __generator(this, function (_a) {
17911
18203
  switch (_a.label) {
17912
18204
  case 0: return [4 /*yield*/, searchItems(searchOptions)];
@@ -17919,11 +18211,13 @@
17919
18211
  case 2:
17920
18212
  results = _a.sent();
17921
18213
  facets = convertPortalItemResponseToFacets(resp);
18214
+ aggregations = convertPortalAggregations(resp);
17922
18215
  // Construct the return
17923
18216
  return [2 /*return*/, {
17924
18217
  total: resp.total,
17925
18218
  results: results,
17926
18219
  facets: facets,
18220
+ aggregations: aggregations,
17927
18221
  hasNext: resp.nextStart > -1,
17928
18222
  next: getNextFunction(searchOptions, resp.nextStart, resp.total, searchPortal$2),
17929
18223
  }];
@@ -18137,7 +18431,36 @@
18137
18431
  * Only exported to enable extensive testing
18138
18432
  * @param filterGroups
18139
18433
  */
18140
- 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) {
18141
18464
  var clone = cloneObject$1(filterGroups);
18142
18465
  // iterate the filterGroups
18143
18466
  var result = clone.map(function (filterGroup) {
@@ -18189,6 +18512,16 @@
18189
18512
  function lookupTypeFilters(key) {
18190
18513
  return WellKnownItemFilters[key];
18191
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
+ }
18192
18525
 
18193
18526
  // ## ## ####### ######## ########
18194
18527
  // ### ## ## ## ## ##
@@ -18392,12 +18725,13 @@
18392
18725
 
18393
18726
  /**
18394
18727
  * @private
18395
- * Portal Search Implementation for Items
18728
+ * DEPRECATED: Use `portalSerchGroups`
18729
+ * Portal Search Implementation for Groups
18396
18730
  * @param filterGroups
18397
18731
  * @param options
18398
18732
  * @returns
18399
18733
  */
18400
- function portalSearchGroups(filterGroups, options) {
18734
+ function portalSearchGroupsFilterGroups(filterGroups, options) {
18401
18735
  return __awaiter(this, void 0, void 0, function () {
18402
18736
  var api, expandedGroups, so, props;
18403
18737
  return __generator(this, function (_a) {
@@ -18444,6 +18778,51 @@
18444
18778
  });
18445
18779
  });
18446
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
+ }
18447
18826
  /**
18448
18827
  * Internal portal search, which then converts `IGroup`s to `IHubSearchResult`s
18449
18828
  * handling enrichments & includes along the way
@@ -18501,11 +18880,12 @@
18501
18880
 
18502
18881
  /**
18503
18882
  * @private
18883
+ * DEPRECATED: Use `portalSearchUsers`
18504
18884
  * Portal Search implementation for Users
18505
18885
  * @param filterGroups
18506
18886
  * @param options
18507
18887
  */
18508
- function portalSearchUsers(filterGroups, options) {
18888
+ function portalSearchUsersFilterGroups(filterGroups, options) {
18509
18889
  return __awaiter(this, void 0, void 0, function () {
18510
18890
  var expandedGroups, so, props;
18511
18891
  return __generator(this, function (_a) {
@@ -18542,6 +18922,52 @@
18542
18922
  });
18543
18923
  });
18544
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
+ }
18545
18971
  /**
18546
18972
  * Internal portal search, which then converts `IGroup`s to `IHubSearchResult`s
18547
18973
  * handling enrichments & includes along the way
@@ -18626,6 +19052,53 @@
18626
19052
  }
18627
19053
  filterType = filterGroups[0].filterType;
18628
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;
18629
19102
  fnHash = {
18630
19103
  arcgis: {
18631
19104
  item: portalSearchItems,
@@ -18640,7 +19113,7 @@
18640
19113
  if (!fn) {
18641
19114
  throw new HubError$1("hubSearch", "Search via \"" + filterType + "\" filter against \"" + apiType + "\" api is not implemented");
18642
19115
  }
18643
- return [2 /*return*/, fn(cloneObject$1(filterGroups), options)];
19116
+ return [2 /*return*/, fn(cloneObject$1(query), options)];
18644
19117
  });
18645
19118
  });
18646
19119
  }
@@ -20479,6 +20952,7 @@
20479
20952
  exports.hubApiRequest = hubApiRequest;
20480
20953
  exports.hubApiSearch = hubApiSearch;
20481
20954
  exports.hubSearch = hubSearch;
20955
+ exports.hubSearchQuery = hubSearchQuery;
20482
20956
  exports.includes = includes;
20483
20957
  exports.incrementString = incrementString;
20484
20958
  exports.interpolate = interpolate;
@@ -20513,7 +20987,7 @@
20513
20987
  exports.mergeGroupFilters = mergeGroupFilters;
20514
20988
  exports.mergeMatchOptions = mergeMatchOptions;
20515
20989
  exports.mergeObjects = mergeObjects;
20516
- exports.mergeSearchOptions = mergeSearchOptions$1;
20990
+ exports.mergeSearchOptions = mergeSearchOptions$2;
20517
20991
  exports.mergeUserFilters = mergeUserFilters;
20518
20992
  exports.normalizeItemType = normalizeItemType;
20519
20993
  exports.normalizeSolutionTemplateItem = normalizeSolutionTemplateItem;
@@ -20538,13 +21012,13 @@
20538
21012
  exports.searchSites = searchSites;
20539
21013
  exports.serializeCollectionState = serializeCollectionState;
20540
21014
  exports.serializeContentFilterForPortal = serializeContentFilterForPortal;
20541
- exports.serializeDateRange = serializeDateRange$1;
21015
+ exports.serializeDateRange = serializeDateRange$2;
20542
21016
  exports.serializeFilterGroupsForPortal = serializeFilterGroupsForPortal;
20543
21017
  exports.serializeGroupFilterForPortal = serializeGroupFilterForPortal;
20544
- exports.serializeMatchOptions = serializeMatchOptions$1;
21018
+ exports.serializeMatchOptions = serializeMatchOptions$2;
20545
21019
  exports.serializeModel = serializeModel;
20546
21020
  exports.serializeSpatialReference = serializeSpatialReference;
20547
- exports.serializeStringOrArray = serializeStringOrArray$1;
21021
+ exports.serializeStringOrArray = serializeStringOrArray$2;
20548
21022
  exports.serializeUserFilterForPortal = serializeUserFilterForPortal;
20549
21023
  exports.setContentHubId = setContentHubId;
20550
21024
  exports.setContentSiteUrls = setContentSiteUrls;