@esri/hub-common 9.47.0 → 10.0.0-next.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.
- package/dist/es2017/core/traits/WithCatalog.js +1 -0
- package/dist/es2017/core/traits/WithCatalog.js.map +1 -0
- package/dist/es2017/index.js +1 -0
- package/dist/es2017/index.js.map +1 -1
- package/dist/es2017/org/fetchOrgLimits.js +32 -0
- package/dist/es2017/org/fetchOrgLimits.js.map +1 -0
- package/dist/es2017/org/index.js +1 -0
- package/dist/es2017/org/index.js.map +1 -1
- package/dist/es2017/search/Catalog.js +346 -0
- package/dist/es2017/search/Catalog.js.map +1 -0
- package/dist/es2017/search/Collection.js +38 -19
- package/dist/es2017/search/Collection.js.map +1 -1
- package/dist/es2017/search/_internal/{ipredicate-utils.js → expandPredicate.js} +1 -1
- package/dist/es2017/search/_internal/expandPredicate.js.map +1 -0
- package/dist/es2017/search/_internal/hubSearchItems.js +0 -43
- package/dist/es2017/search/_internal/hubSearchItems.js.map +1 -1
- package/dist/es2017/search/_internal/index.js +0 -1
- package/dist/es2017/search/_internal/index.js.map +1 -1
- package/dist/es2017/search/_internal/portalSearchGroups.js +1 -2
- package/dist/es2017/search/_internal/portalSearchGroups.js.map +1 -1
- package/dist/es2017/search/_internal/portalSearchItems.js +2 -5
- package/dist/es2017/search/_internal/portalSearchItems.js.map +1 -1
- package/dist/es2017/search/_internal/portalSearchUsers.js +1 -2
- package/dist/es2017/search/_internal/portalSearchUsers.js.map +1 -1
- package/dist/es2017/search/_searchContent.js +1 -5
- package/dist/es2017/search/_searchContent.js.map +1 -1
- package/dist/es2017/search/_searchGroups.js.map +1 -1
- package/dist/es2017/search/content-utils.js +2 -67
- package/dist/es2017/search/content-utils.js.map +1 -1
- package/dist/es2017/search/fetchCatalog.js +46 -0
- package/dist/es2017/search/fetchCatalog.js.map +1 -0
- package/dist/es2017/search/hubSearch.js +1 -1
- package/dist/es2017/search/hubSearch.js.map +1 -1
- package/dist/es2017/search/index.js +3 -2
- package/dist/es2017/search/index.js.map +1 -1
- package/dist/es2017/search/serializeQueryForPortal.js +1 -1
- package/dist/es2017/search/serializeQueryForPortal.js.map +1 -1
- package/dist/es2017/search/types/index.js +0 -2
- package/dist/es2017/search/types/index.js.map +1 -1
- package/dist/es2017/search/upgradeCatalogSchema.js +66 -0
- package/dist/es2017/search/upgradeCatalogSchema.js.map +1 -0
- package/dist/es2017/types/IMessage.js +1 -0
- package/dist/es2017/types/IMessage.js.map +1 -0
- package/dist/es2017/types/index.js +2 -0
- package/dist/es2017/types/index.js.map +1 -0
- package/dist/es2017/types.js.map +1 -1
- package/dist/esm/core/traits/WithCatalog.js +1 -0
- package/dist/esm/core/traits/WithCatalog.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/org/fetchOrgLimits.js +32 -0
- package/dist/esm/org/fetchOrgLimits.js.map +1 -0
- package/dist/esm/org/index.js +1 -0
- package/dist/esm/org/index.js.map +1 -1
- package/dist/esm/search/Catalog.js +404 -0
- package/dist/esm/search/Catalog.js.map +1 -0
- package/dist/esm/search/Collection.js +40 -24
- package/dist/esm/search/Collection.js.map +1 -1
- package/dist/esm/search/_internal/{ipredicate-utils.js → expandPredicate.js} +1 -1
- package/dist/esm/search/_internal/expandPredicate.js.map +1 -0
- package/dist/esm/search/_internal/hubSearchItems.js +1 -45
- package/dist/esm/search/_internal/hubSearchItems.js.map +1 -1
- package/dist/esm/search/_internal/index.js +0 -1
- package/dist/esm/search/_internal/index.js.map +1 -1
- package/dist/esm/search/_internal/portalSearchGroups.js +1 -2
- package/dist/esm/search/_internal/portalSearchGroups.js.map +1 -1
- package/dist/esm/search/_internal/portalSearchItems.js +3 -5
- package/dist/esm/search/_internal/portalSearchItems.js.map +1 -1
- package/dist/esm/search/_internal/portalSearchUsers.js +1 -2
- package/dist/esm/search/_internal/portalSearchUsers.js.map +1 -1
- package/dist/esm/search/_searchContent.js +1 -5
- package/dist/esm/search/_searchContent.js.map +1 -1
- package/dist/esm/search/_searchGroups.js.map +1 -1
- package/dist/esm/search/content-utils.js +2 -70
- package/dist/esm/search/content-utils.js.map +1 -1
- package/dist/esm/search/fetchCatalog.js +59 -0
- package/dist/esm/search/fetchCatalog.js.map +1 -0
- package/dist/esm/search/hubSearch.js +1 -1
- package/dist/esm/search/hubSearch.js.map +1 -1
- package/dist/esm/search/index.js +3 -2
- package/dist/esm/search/index.js.map +1 -1
- package/dist/esm/search/serializeQueryForPortal.js +1 -1
- package/dist/esm/search/serializeQueryForPortal.js.map +1 -1
- package/dist/esm/search/types/index.js +0 -2
- package/dist/esm/search/types/index.js.map +1 -1
- package/dist/esm/search/upgradeCatalogSchema.js +66 -0
- package/dist/esm/search/upgradeCatalogSchema.js.map +1 -0
- package/dist/esm/types/IMessage.js +1 -0
- package/dist/esm/types/IMessage.js.map +1 -0
- package/dist/esm/types/index.js +2 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/node/{search/types/IFacetOption.js → core/traits/WithCatalog.js} +1 -1
- package/dist/node/core/traits/WithCatalog.js.map +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/org/fetchOrgLimits.js +37 -0
- package/dist/node/org/fetchOrgLimits.js.map +1 -0
- package/dist/node/org/index.js +1 -0
- package/dist/node/org/index.js.map +1 -1
- package/dist/node/search/Catalog.js +350 -0
- package/dist/node/search/Catalog.js.map +1 -0
- package/dist/node/search/Collection.js +37 -18
- package/dist/node/search/Collection.js.map +1 -1
- package/dist/node/search/_internal/{ipredicate-utils.js → expandPredicate.js} +1 -1
- package/dist/node/search/_internal/expandPredicate.js.map +1 -0
- package/dist/node/search/_internal/hubSearchItems.js +1 -45
- package/dist/node/search/_internal/hubSearchItems.js.map +1 -1
- package/dist/node/search/_internal/index.js +0 -1
- package/dist/node/search/_internal/index.js.map +1 -1
- package/dist/node/search/_internal/portalSearchGroups.js +2 -3
- package/dist/node/search/_internal/portalSearchGroups.js.map +1 -1
- package/dist/node/search/_internal/portalSearchItems.js +2 -5
- package/dist/node/search/_internal/portalSearchItems.js.map +1 -1
- package/dist/node/search/_internal/portalSearchUsers.js +2 -3
- package/dist/node/search/_internal/portalSearchUsers.js.map +1 -1
- package/dist/node/search/_searchContent.js +0 -4
- package/dist/node/search/_searchContent.js.map +1 -1
- package/dist/node/search/_searchGroups.js.map +1 -1
- package/dist/node/search/content-utils.js +3 -70
- package/dist/node/search/content-utils.js.map +1 -1
- package/dist/node/search/fetchCatalog.js +50 -0
- package/dist/node/search/fetchCatalog.js.map +1 -0
- package/dist/node/search/hubSearch.js +1 -1
- package/dist/node/search/hubSearch.js.map +1 -1
- package/dist/node/search/index.js +3 -2
- package/dist/node/search/index.js.map +1 -1
- package/dist/node/search/serializeQueryForPortal.js +2 -2
- package/dist/node/search/serializeQueryForPortal.js.map +1 -1
- package/dist/node/search/types/index.js +0 -2
- package/dist/node/search/types/index.js.map +1 -1
- package/dist/node/search/upgradeCatalogSchema.js +71 -0
- package/dist/node/search/upgradeCatalogSchema.js.map +1 -0
- package/dist/node/{search/types/IFacet.js → types/IMessage.js} +1 -1
- package/dist/node/types/IMessage.js.map +1 -0
- package/dist/node/types/index.js +5 -0
- package/dist/node/types/index.js.map +1 -0
- package/dist/node/types.js.map +1 -1
- package/dist/types/core/traits/WithCatalog.d.ts +7 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/org/fetchOrgLimits.d.ts +35 -0
- package/dist/types/org/index.d.ts +1 -0
- package/dist/types/search/Catalog.d.ts +143 -0
- package/dist/types/search/Collection.d.ts +23 -2
- package/dist/types/search/_internal/{ipredicate-utils.d.ts → expandPredicate.d.ts} +0 -0
- package/dist/types/search/_internal/hubSearchItems.d.ts +1 -2
- package/dist/types/search/_internal/index.d.ts +0 -1
- package/dist/types/search/_searchGroups.d.ts +1 -5
- package/dist/types/search/content-utils.d.ts +1 -18
- package/dist/types/search/fetchCatalog.d.ts +10 -0
- package/dist/types/search/index.d.ts +3 -2
- package/dist/types/search/types/ICatalog.d.ts +0 -5
- package/dist/types/search/types/ICollection.d.ts +0 -2
- package/dist/types/search/types/IHubSearchOptions.d.ts +5 -1
- package/dist/types/search/types/IHubSearchResponse.d.ts +3 -3
- package/dist/types/search/types/index.d.ts +0 -2
- package/dist/types/search/types/types.d.ts +0 -2
- package/dist/types/search/upgradeCatalogSchema.d.ts +12 -0
- package/dist/types/types/IMessage.d.ts +32 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types.d.ts +0 -2
- package/dist/umd/common.umd.js +652 -337
- package/dist/umd/common.umd.js.map +1 -1
- package/package.json +1 -1
- package/dist/es2017/search/_internal/ipredicate-utils.js.map +0 -1
- package/dist/es2017/search/_internal/state.js +0 -155
- package/dist/es2017/search/_internal/state.js.map +0 -1
- package/dist/es2017/search/collectionState.js +0 -60
- package/dist/es2017/search/collectionState.js.map +0 -1
- package/dist/es2017/search/convertCatalog.js +0 -33
- package/dist/es2017/search/convertCatalog.js.map +0 -1
- package/dist/es2017/search/types/IFacet.js +0 -1
- package/dist/es2017/search/types/IFacet.js.map +0 -1
- package/dist/es2017/search/types/IFacetOption.js +0 -1
- package/dist/es2017/search/types/IFacetOption.js.map +0 -1
- package/dist/esm/search/_internal/ipredicate-utils.js.map +0 -1
- package/dist/esm/search/_internal/state.js +0 -155
- package/dist/esm/search/_internal/state.js.map +0 -1
- package/dist/esm/search/collectionState.js +0 -61
- package/dist/esm/search/collectionState.js.map +0 -1
- package/dist/esm/search/convertCatalog.js +0 -33
- package/dist/esm/search/convertCatalog.js.map +0 -1
- package/dist/esm/search/types/IFacet.js +0 -1
- package/dist/esm/search/types/IFacet.js.map +0 -1
- package/dist/esm/search/types/IFacetOption.js +0 -1
- package/dist/esm/search/types/IFacetOption.js.map +0 -1
- package/dist/node/search/_internal/ipredicate-utils.js.map +0 -1
- package/dist/node/search/_internal/state.js +0 -166
- package/dist/node/search/_internal/state.js.map +0 -1
- package/dist/node/search/collectionState.js +0 -65
- package/dist/node/search/collectionState.js.map +0 -1
- package/dist/node/search/convertCatalog.js +0 -37
- package/dist/node/search/convertCatalog.js.map +0 -1
- package/dist/node/search/types/IFacet.js.map +0 -1
- package/dist/node/search/types/IFacetOption.js.map +0 -1
- package/dist/types/search/_internal/state.d.ts +0 -70
- package/dist/types/search/collectionState.d.ts +0 -19
- package/dist/types/search/convertCatalog.d.ts +0 -6
- package/dist/types/search/types/IFacet.d.ts +0 -62
- package/dist/types/search/types/IFacetOption.d.ts +0 -30
package/dist/umd/common.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* @preserve
|
|
2
|
-
* @esri/hub-common - v9.
|
|
2
|
+
* @esri/hub-common - v9.49.0 - Thu Jul 21 2022 17:19:07 GMT+0000 (Coordinated Universal Time)
|
|
3
3
|
* Copyright (c) 2022 Environmental Systems Research Institute, Inc.
|
|
4
4
|
* Apache-2.0
|
|
5
5
|
*/
|
|
@@ -10011,6 +10011,37 @@
|
|
|
10011
10011
|
return getPortal(orgId, __assign(__assign({}, options), { portal: basePortalUrl }));
|
|
10012
10012
|
};
|
|
10013
10013
|
|
|
10014
|
+
/**
|
|
10015
|
+
* Generic function to fetch org limits
|
|
10016
|
+
* @param orgId
|
|
10017
|
+
* @param limitsType
|
|
10018
|
+
* @param limitName
|
|
10019
|
+
* @param options
|
|
10020
|
+
* @returns
|
|
10021
|
+
*/
|
|
10022
|
+
function fetchOrgLimits(orgId, limitsType, limitName, options) {
|
|
10023
|
+
var portal = options.authentication.portal;
|
|
10024
|
+
var url = portal + "/portals/" + orgId + "/limits?limitsType=" + limitsType + "&limitName=" + limitName + "&f=json";
|
|
10025
|
+
return request(url, options);
|
|
10026
|
+
}
|
|
10027
|
+
/**
|
|
10028
|
+
* Fetch the maximum number of groups a user can create in an org
|
|
10029
|
+
* @param orgId
|
|
10030
|
+
* @param options
|
|
10031
|
+
* @returns
|
|
10032
|
+
*/
|
|
10033
|
+
function fetchMaxNumUserGroupsLimit(orgId, options) {
|
|
10034
|
+
return fetchOrgLimits(orgId, "Groups", "MaxNumUserGroups", options)
|
|
10035
|
+
.then(function (response) {
|
|
10036
|
+
return response.limitValue;
|
|
10037
|
+
})
|
|
10038
|
+
.catch(function (_) {
|
|
10039
|
+
// it's possible that the org doesn't have this property set, and
|
|
10040
|
+
// the api will return a 500 error. So we just return the default value
|
|
10041
|
+
return 512;
|
|
10042
|
+
});
|
|
10043
|
+
}
|
|
10044
|
+
|
|
10014
10045
|
/**
|
|
10015
10046
|
* Parse metadataxml into json object
|
|
10016
10047
|
* @param metadataXml
|
|
@@ -13862,76 +13893,6 @@
|
|
|
13862
13893
|
},
|
|
13863
13894
|
],
|
|
13864
13895
|
};
|
|
13865
|
-
/**
|
|
13866
|
-
* @private
|
|
13867
|
-
* Convert portal search response to facets
|
|
13868
|
-
* Note: Only applicable to an item search
|
|
13869
|
-
* @param response
|
|
13870
|
-
* @returns
|
|
13871
|
-
*/
|
|
13872
|
-
// TODO: Remove with _searchContent
|
|
13873
|
-
function convertPortalResponseToFacets(response, operation) {
|
|
13874
|
-
if (operation === void 0) { operation = "OR"; }
|
|
13875
|
-
// delegate to a more future-friendly version
|
|
13876
|
-
return convertPortalItemResponseToFacets(response, operation, "filter");
|
|
13877
|
-
}
|
|
13878
|
-
/**
|
|
13879
|
-
* @private
|
|
13880
|
-
* Convert portal search response to facets
|
|
13881
|
-
* Note: Only applicable to an item search
|
|
13882
|
-
* @param response
|
|
13883
|
-
* @returns
|
|
13884
|
-
*/
|
|
13885
|
-
function convertPortalItemResponseToFacets(response, operation, optionProp // TODO: Remove with _searchContent and use `filters`
|
|
13886
|
-
) {
|
|
13887
|
-
var _a;
|
|
13888
|
-
if (operation === void 0) { operation = "OR"; }
|
|
13889
|
-
if (optionProp === void 0) { optionProp = "filters"; }
|
|
13890
|
-
// TODO: move into portalSearchItems
|
|
13891
|
-
var result = [];
|
|
13892
|
-
if ((_a = response.aggregations) === null || _a === void 0 ? void 0 : _a.counts) {
|
|
13893
|
-
response.aggregations.counts.forEach(function (entry) {
|
|
13894
|
-
var facet = {
|
|
13895
|
-
label: entry.fieldName,
|
|
13896
|
-
key: entry.fieldName,
|
|
13897
|
-
aggField: entry.fieldName,
|
|
13898
|
-
display: "multi-select",
|
|
13899
|
-
};
|
|
13900
|
-
var options = [];
|
|
13901
|
-
entry.fieldValues.forEach(function (fv) {
|
|
13902
|
-
var filter = {
|
|
13903
|
-
filterType: "item",
|
|
13904
|
-
};
|
|
13905
|
-
// construct the filter based on the operation
|
|
13906
|
-
var matchKey = operation === "OR" ? "any" : "all";
|
|
13907
|
-
var filterMatchOption = {};
|
|
13908
|
-
filterMatchOption[matchKey] = [fv.value];
|
|
13909
|
-
filter[entry.fieldName] = filterMatchOption;
|
|
13910
|
-
// construct the FacetOption
|
|
13911
|
-
var fo = {
|
|
13912
|
-
label: fv.value + " (" + fv.count + ")",
|
|
13913
|
-
key: fv.value,
|
|
13914
|
-
count: fv.count,
|
|
13915
|
-
selected: false,
|
|
13916
|
-
};
|
|
13917
|
-
// Temporary to ensure the old fn can delegate to this
|
|
13918
|
-
// but we can still return the correct structure
|
|
13919
|
-
// TODO: Remove with _searchContent
|
|
13920
|
-
/* istanbul ignore next */
|
|
13921
|
-
if (optionProp === "filter") {
|
|
13922
|
-
fo.filter = filter;
|
|
13923
|
-
}
|
|
13924
|
-
else {
|
|
13925
|
-
fo.filters = [filter];
|
|
13926
|
-
}
|
|
13927
|
-
options.push(fo);
|
|
13928
|
-
});
|
|
13929
|
-
facet.options = options;
|
|
13930
|
-
result.push(facet);
|
|
13931
|
-
});
|
|
13932
|
-
}
|
|
13933
|
-
return result;
|
|
13934
|
-
}
|
|
13935
13896
|
/**
|
|
13936
13897
|
* Merge `Filter<"content">` objects
|
|
13937
13898
|
*
|
|
@@ -14527,7 +14488,6 @@
|
|
|
14527
14488
|
searchPromise = Promise.resolve({
|
|
14528
14489
|
total: 0,
|
|
14529
14490
|
results: [],
|
|
14530
|
-
facets: [],
|
|
14531
14491
|
hasNext: false,
|
|
14532
14492
|
next: function () {
|
|
14533
14493
|
// tslint:disable-next-line
|
|
@@ -14571,12 +14531,9 @@
|
|
|
14571
14531
|
}
|
|
14572
14532
|
// add thumbnailUrl
|
|
14573
14533
|
content = content.map(thumbnailify);
|
|
14574
|
-
// convert aggregations into facets
|
|
14575
|
-
var facets = convertPortalResponseToFacets(resp);
|
|
14576
14534
|
return {
|
|
14577
14535
|
total: resp.total,
|
|
14578
14536
|
results: content,
|
|
14579
|
-
facets: facets,
|
|
14580
14537
|
hasNext: hasNext,
|
|
14581
14538
|
next: getNextFunction(searchOptions, resp.nextStart, resp.total, searchPortal$3),
|
|
14582
14539
|
};
|
|
@@ -14756,234 +14713,68 @@
|
|
|
14756
14713
|
});
|
|
14757
14714
|
}
|
|
14758
14715
|
|
|
14716
|
+
var CATALOG_SCHEMA_VERSION = 1.0;
|
|
14759
14717
|
/**
|
|
14760
|
-
*
|
|
14761
|
-
*
|
|
14762
|
-
*
|
|
14763
|
-
* @param sortOptions
|
|
14764
|
-
* @param sortState
|
|
14765
|
-
* @returns
|
|
14766
|
-
*/
|
|
14767
|
-
function applySortState(sortOptions, sortState) {
|
|
14768
|
-
var updated = cloneObject$1(sortOptions);
|
|
14769
|
-
if (sortState) {
|
|
14770
|
-
var _a = sortState.split("|"), label = _a[0], attribute = _a[1], order = _a[2];
|
|
14771
|
-
updated.label = label;
|
|
14772
|
-
updated.attribute = attribute;
|
|
14773
|
-
updated.order = order;
|
|
14774
|
-
}
|
|
14775
|
-
return updated;
|
|
14776
|
-
}
|
|
14777
|
-
/**
|
|
14778
|
-
* @private
|
|
14779
|
-
* Apply FacetState to a Facet
|
|
14780
|
-
* @param facet
|
|
14781
|
-
* @param state
|
|
14782
|
-
* @returns
|
|
14783
|
-
*/
|
|
14784
|
-
function applyFacetState(facet, state) {
|
|
14785
|
-
var updated = cloneObject$1(facet);
|
|
14786
|
-
switch (facet.display) {
|
|
14787
|
-
case "single-select":
|
|
14788
|
-
updated = applySingleSelectFacetState(facet, state);
|
|
14789
|
-
break;
|
|
14790
|
-
case "multi-select":
|
|
14791
|
-
updated = applyMultiSelectFacetState(facet, state);
|
|
14792
|
-
break;
|
|
14793
|
-
}
|
|
14794
|
-
return updated;
|
|
14795
|
-
}
|
|
14796
|
-
/**
|
|
14797
|
-
* @private
|
|
14798
|
-
* Apply the Facet State onto a single-select facet
|
|
14799
|
-
*
|
|
14800
|
-
* Intentionally mutates the facet.
|
|
14801
|
-
* @param facet
|
|
14802
|
-
* @param state
|
|
14718
|
+
* Apply schema upgrades to Catalog objects
|
|
14719
|
+
* @param catalog
|
|
14803
14720
|
* @returns
|
|
14804
14721
|
*/
|
|
14805
|
-
function
|
|
14806
|
-
var
|
|
14807
|
-
|
|
14808
|
-
|
|
14809
|
-
return o;
|
|
14810
|
-
});
|
|
14811
|
-
return updated;
|
|
14812
|
-
}
|
|
14813
|
-
/**
|
|
14814
|
-
* @private
|
|
14815
|
-
* Serialize single-select facet into IFacetState
|
|
14816
|
-
* @param facet
|
|
14817
|
-
* @returns
|
|
14818
|
-
*/
|
|
14819
|
-
function serializeSingleSelectFacetState(facet) {
|
|
14820
|
-
var state = {};
|
|
14821
|
-
var selected = facet.options.find(function (o) { return o.selected; });
|
|
14822
|
-
if (selected) {
|
|
14823
|
-
state[facet.key] = selected.key;
|
|
14722
|
+
function upgradeCatalogSchema(catalog) {
|
|
14723
|
+
var clone = cloneObject$1(catalog);
|
|
14724
|
+
if (getProp(clone, "schemaVersion") === CATALOG_SCHEMA_VERSION) {
|
|
14725
|
+
return clone;
|
|
14824
14726
|
}
|
|
14825
14727
|
else {
|
|
14826
|
-
|
|
14728
|
+
// apply migrations in order
|
|
14729
|
+
clone = applyCatalogSchema(clone);
|
|
14730
|
+
return clone;
|
|
14827
14731
|
}
|
|
14828
|
-
return state;
|
|
14829
|
-
}
|
|
14830
|
-
/**
|
|
14831
|
-
* @private
|
|
14832
|
-
* Apply the Facet State onto a multi-select Facet
|
|
14833
|
-
*
|
|
14834
|
-
* Intentionally mutates the facet.
|
|
14835
|
-
* @param facet
|
|
14836
|
-
* @param state
|
|
14837
|
-
* @returns
|
|
14838
|
-
*/
|
|
14839
|
-
function applyMultiSelectFacetState(facet, state) {
|
|
14840
|
-
var _a;
|
|
14841
|
-
var updated = cloneObject$1(facet);
|
|
14842
|
-
var selectedKeys = ((_a = state[facet.key]) === null || _a === void 0 ? void 0 : _a.split(",")) || [];
|
|
14843
|
-
updated.options = updated.options.map(function (o) {
|
|
14844
|
-
o.selected = selectedKeys.includes(o.key);
|
|
14845
|
-
return o;
|
|
14846
|
-
});
|
|
14847
|
-
return updated;
|
|
14848
14732
|
}
|
|
14849
14733
|
/**
|
|
14850
|
-
*
|
|
14851
|
-
*
|
|
14852
|
-
* @param
|
|
14734
|
+
* Apply the Catalog schema to the original, unversioned
|
|
14735
|
+
* site catalog objects
|
|
14736
|
+
* @param original
|
|
14853
14737
|
* @returns
|
|
14854
14738
|
*/
|
|
14855
|
-
function
|
|
14856
|
-
|
|
14857
|
-
|
|
14858
|
-
var value = selected.map(function (o) { return o.key; }).join(",");
|
|
14859
|
-
if (value.length) {
|
|
14860
|
-
state[facet.key] = value;
|
|
14739
|
+
function applyCatalogSchema(original) {
|
|
14740
|
+
if (getProp(original, "schemaVersion") > 1.0) {
|
|
14741
|
+
return original;
|
|
14861
14742
|
}
|
|
14862
14743
|
else {
|
|
14863
|
-
|
|
14864
|
-
|
|
14865
|
-
|
|
14866
|
-
|
|
14867
|
-
|
|
14868
|
-
|
|
14869
|
-
|
|
14870
|
-
|
|
14871
|
-
|
|
14872
|
-
|
|
14873
|
-
|
|
14874
|
-
|
|
14875
|
-
|
|
14876
|
-
|
|
14877
|
-
|
|
14878
|
-
/**
|
|
14879
|
-
* @private
|
|
14880
|
-
* Serialize the state of a facet into a key/value pair
|
|
14881
|
-
*
|
|
14882
|
-
* Called from the various facet components
|
|
14883
|
-
* @param facet
|
|
14884
|
-
* @returns
|
|
14885
|
-
*/
|
|
14886
|
-
function serializeFacetState(facet) {
|
|
14887
|
-
var state = {};
|
|
14888
|
-
switch (facet.display) {
|
|
14889
|
-
case "single-select":
|
|
14890
|
-
state = serializeSingleSelectFacetState(facet);
|
|
14891
|
-
break;
|
|
14892
|
-
case "multi-select":
|
|
14893
|
-
state = serializeMultiSelectFacetState(facet);
|
|
14894
|
-
break;
|
|
14895
|
-
}
|
|
14896
|
-
return state;
|
|
14897
|
-
}
|
|
14898
|
-
|
|
14899
|
-
/**
|
|
14900
|
-
* Apply ICollectionState to an ICollection
|
|
14901
|
-
*
|
|
14902
|
-
* Typically used in a Gallery or Catalog component to
|
|
14903
|
-
* set the inital state, based on values deserialized
|
|
14904
|
-
* from a query string
|
|
14905
|
-
* @param collection
|
|
14906
|
-
* @param state
|
|
14907
|
-
* @returns
|
|
14908
|
-
*/
|
|
14909
|
-
function applyCollectionState(collection, state) {
|
|
14910
|
-
var updated = cloneObject$1(collection);
|
|
14911
|
-
// Apply default query
|
|
14912
|
-
if (state.query) {
|
|
14913
|
-
updated.defaultQuery = state.query;
|
|
14914
|
-
}
|
|
14915
|
-
// Apply Sort State
|
|
14916
|
-
updated.sortOption = applySortState(updated.sortOption, state.sort);
|
|
14917
|
-
// Look for state props for the facets and apply them
|
|
14918
|
-
updated.facets = updated.facets.map(function (facet) {
|
|
14919
|
-
// see if there is a key for this facet on the state
|
|
14920
|
-
if (Object.keys(state).includes(facet.key)) {
|
|
14921
|
-
var facetState = {};
|
|
14922
|
-
facetState[facet.key] = state[facet.key];
|
|
14923
|
-
return applyFacetState(facet, facetState);
|
|
14744
|
+
var catalog = {
|
|
14745
|
+
schemaVersion: 1,
|
|
14746
|
+
title: "Default Catalog",
|
|
14747
|
+
scopes: {
|
|
14748
|
+
item: {
|
|
14749
|
+
targetEntity: "item",
|
|
14750
|
+
filters: [],
|
|
14751
|
+
},
|
|
14752
|
+
},
|
|
14753
|
+
collections: [],
|
|
14754
|
+
};
|
|
14755
|
+
var rawGroups = getProp(original, "groups");
|
|
14756
|
+
var groups = [];
|
|
14757
|
+
if (Array.isArray(rawGroups) && rawGroups.length) {
|
|
14758
|
+
groups = rawGroups;
|
|
14924
14759
|
}
|
|
14925
|
-
else {
|
|
14926
|
-
|
|
14927
|
-
|
|
14928
|
-
|
|
14929
|
-
|
|
14760
|
+
else if (typeof rawGroups === "string") {
|
|
14761
|
+
groups = [rawGroups];
|
|
14762
|
+
}
|
|
14763
|
+
if (groups.length) {
|
|
14764
|
+
catalog.scopes.item.filters.push({
|
|
14765
|
+
predicates: [{ group: groups }],
|
|
14930
14766
|
});
|
|
14931
|
-
return facet;
|
|
14932
14767
|
}
|
|
14933
|
-
|
|
14934
|
-
//
|
|
14935
|
-
return updated;
|
|
14936
|
-
}
|
|
14937
|
-
/**
|
|
14938
|
-
* Serialize the current state of a collection into a hash that
|
|
14939
|
-
* can be converted into a query string
|
|
14940
|
-
* @param collection
|
|
14941
|
-
* @returns
|
|
14942
|
-
*/
|
|
14943
|
-
function serializeCollectionState(collection) {
|
|
14944
|
-
var state = {};
|
|
14945
|
-
if (collection.defaultQuery) {
|
|
14946
|
-
state.query = collection.defaultQuery;
|
|
14947
|
-
}
|
|
14948
|
-
if (collection.sortOption) {
|
|
14949
|
-
state.sort = serializeSortState(collection.sortOption);
|
|
14768
|
+
return catalog;
|
|
14950
14769
|
}
|
|
14951
|
-
var facetState = (collection.facets || []).reduce(function (s, facet) {
|
|
14952
|
-
return __assign(__assign({}, s), serializeFacetState(facet));
|
|
14953
|
-
}, {});
|
|
14954
|
-
return __assign(__assign({}, state), facetState);
|
|
14955
14770
|
}
|
|
14956
|
-
|
|
14957
14771
|
/**
|
|
14958
|
-
*
|
|
14772
|
+
* DEPRECATED: Use upgradeCatalogSchema(...)
|
|
14959
14773
|
* @param original
|
|
14960
14774
|
*/
|
|
14775
|
+
/* istanbul ignore next */
|
|
14961
14776
|
function convertCatalog(original) {
|
|
14962
|
-
|
|
14963
|
-
schemaVersion: 1,
|
|
14964
|
-
title: "Default Catalog",
|
|
14965
|
-
scopes: {
|
|
14966
|
-
item: {
|
|
14967
|
-
targetEntity: "item",
|
|
14968
|
-
filters: [],
|
|
14969
|
-
},
|
|
14970
|
-
},
|
|
14971
|
-
collections: [],
|
|
14972
|
-
};
|
|
14973
|
-
var rawGroups = getProp(original, "groups");
|
|
14974
|
-
var groups = [];
|
|
14975
|
-
if (Array.isArray(rawGroups) && rawGroups.length) {
|
|
14976
|
-
groups = rawGroups;
|
|
14977
|
-
}
|
|
14978
|
-
else if (typeof rawGroups === "string") {
|
|
14979
|
-
groups = [rawGroups];
|
|
14980
|
-
}
|
|
14981
|
-
if (groups.length) {
|
|
14982
|
-
catalog.scopes.item.filters.push({
|
|
14983
|
-
predicates: [{ group: groups }],
|
|
14984
|
-
});
|
|
14985
|
-
}
|
|
14986
|
-
return catalog;
|
|
14777
|
+
return upgradeCatalogSchema(original);
|
|
14987
14778
|
}
|
|
14988
14779
|
|
|
14989
14780
|
/**
|
|
@@ -18022,7 +17813,7 @@
|
|
|
18022
17813
|
*/
|
|
18023
17814
|
function searchPortal$2(searchOptions) {
|
|
18024
17815
|
return __awaiter(this, void 0, void 0, function () {
|
|
18025
|
-
var resp, fn, results,
|
|
17816
|
+
var resp, fn, results, aggregations;
|
|
18026
17817
|
return __generator(this, function (_a) {
|
|
18027
17818
|
switch (_a.label) {
|
|
18028
17819
|
case 0: return [4 /*yield*/, searchItems(searchOptions)];
|
|
@@ -18034,13 +17825,11 @@
|
|
|
18034
17825
|
return [4 /*yield*/, Promise.all(resp.results.map(fn))];
|
|
18035
17826
|
case 2:
|
|
18036
17827
|
results = _a.sent();
|
|
18037
|
-
facets = convertPortalItemResponseToFacets(resp);
|
|
18038
17828
|
aggregations = convertPortalAggregations(resp);
|
|
18039
17829
|
// Construct the return
|
|
18040
17830
|
return [2 /*return*/, {
|
|
18041
17831
|
total: resp.total,
|
|
18042
17832
|
results: results,
|
|
18043
|
-
facets: facets,
|
|
18044
17833
|
aggregations: aggregations,
|
|
18045
17834
|
hasNext: resp.nextStart > -1,
|
|
18046
17835
|
next: getNextFunction(searchOptions, resp.nextStart, resp.total, searchPortal$2),
|
|
@@ -18339,7 +18128,7 @@
|
|
|
18339
18128
|
function hubSearchItems(filters, options) {
|
|
18340
18129
|
var _a;
|
|
18341
18130
|
return __awaiter(this, void 0, void 0, function () {
|
|
18342
|
-
var api, apiUrl, cleanFilters, searchRequest, aggs, session, opts, raw, json, token_1, us, tokenizeThubmnailUrl, conversion, results,
|
|
18131
|
+
var api, apiUrl, cleanFilters, searchRequest, aggs, session, opts, raw, json, token_1, us, tokenizeThubmnailUrl, conversion, results, response, ex_1;
|
|
18343
18132
|
return __generator(this, function (_b) {
|
|
18344
18133
|
switch (_b.label) {
|
|
18345
18134
|
case 0:
|
|
@@ -18420,11 +18209,9 @@
|
|
|
18420
18209
|
return [4 /*yield*/, Promise.all(json.data.map(conversion))];
|
|
18421
18210
|
case 4:
|
|
18422
18211
|
results = _b.sent();
|
|
18423
|
-
facets = convertHubResponseToFacets(json);
|
|
18424
18212
|
response = {
|
|
18425
18213
|
total: json.meta.total,
|
|
18426
18214
|
results: results,
|
|
18427
|
-
facets: facets,
|
|
18428
18215
|
hasNext: json.meta.hasNext,
|
|
18429
18216
|
next: function () {
|
|
18430
18217
|
// tslint:disable-next-line
|
|
@@ -18477,48 +18264,6 @@
|
|
|
18477
18264
|
// TODO: Per-type plucking of props into the `meta` hash for use in the card components
|
|
18478
18265
|
return Promise.resolve(result);
|
|
18479
18266
|
}
|
|
18480
|
-
/* istanbul ignore next */
|
|
18481
|
-
function convertHubResponseToFacets(response, operation) {
|
|
18482
|
-
var _a;
|
|
18483
|
-
if (operation === void 0) { operation = "OR"; }
|
|
18484
|
-
var result = [];
|
|
18485
|
-
if ((_a = response.meta) === null || _a === void 0 ? void 0 : _a.aggregations) {
|
|
18486
|
-
var meta = response.meta;
|
|
18487
|
-
meta.aggregations.forEach(function (entry) {
|
|
18488
|
-
// Dyanmic facets typically "AND" so we are refining
|
|
18489
|
-
var facet = {
|
|
18490
|
-
label: entry.field,
|
|
18491
|
-
key: entry.field,
|
|
18492
|
-
aggField: entry.field,
|
|
18493
|
-
display: "multi-select",
|
|
18494
|
-
operation: operation,
|
|
18495
|
-
};
|
|
18496
|
-
var options = [];
|
|
18497
|
-
entry.values.forEach(function (fv) {
|
|
18498
|
-
var filter = {
|
|
18499
|
-
filterType: "item",
|
|
18500
|
-
};
|
|
18501
|
-
// construct the filter based on the operation
|
|
18502
|
-
var matchKey = operation === "OR" ? "any" : "all";
|
|
18503
|
-
var filterMatchOption = {};
|
|
18504
|
-
filterMatchOption[matchKey] = [fv.value];
|
|
18505
|
-
filter[entry.field] = filterMatchOption;
|
|
18506
|
-
// construct the FacetOption
|
|
18507
|
-
var fo = {
|
|
18508
|
-
label: fv.value + " (" + fv.count + ")",
|
|
18509
|
-
key: fv.value,
|
|
18510
|
-
count: fv.count,
|
|
18511
|
-
selected: false,
|
|
18512
|
-
filters: [filter],
|
|
18513
|
-
};
|
|
18514
|
-
options.push(fo);
|
|
18515
|
-
});
|
|
18516
|
-
facet.options = options;
|
|
18517
|
-
result.push(facet);
|
|
18518
|
-
});
|
|
18519
|
-
}
|
|
18520
|
-
return result;
|
|
18521
|
-
}
|
|
18522
18267
|
|
|
18523
18268
|
/**
|
|
18524
18269
|
* @private
|
|
@@ -18591,7 +18336,6 @@
|
|
|
18591
18336
|
return [2 /*return*/, {
|
|
18592
18337
|
total: resp.total,
|
|
18593
18338
|
results: results,
|
|
18594
|
-
facets: [],
|
|
18595
18339
|
hasNext: resp.nextStart > -1,
|
|
18596
18340
|
next: getNextFunction(searchOptions, resp.nextStart, resp.total, searchPortal$1),
|
|
18597
18341
|
}];
|
|
@@ -18692,7 +18436,6 @@
|
|
|
18692
18436
|
return [2 /*return*/, {
|
|
18693
18437
|
total: resp.total,
|
|
18694
18438
|
results: results,
|
|
18695
|
-
facets: [],
|
|
18696
18439
|
hasNext: resp.nextStart > -1,
|
|
18697
18440
|
next: getNextFunction(searchOptions, resp.nextStart, resp.total, searchPortal),
|
|
18698
18441
|
}];
|
|
@@ -18782,13 +18525,584 @@
|
|
|
18782
18525
|
};
|
|
18783
18526
|
fn = getProp(fnHash, apiType + "." + filterType);
|
|
18784
18527
|
if (!fn) {
|
|
18785
|
-
throw new HubError$1("hubSearch", "Search via \"" + filterType + "\" filter against \"" + apiType + "\" api is not implemented");
|
|
18528
|
+
throw new HubError$1("hubSearch", "Search via \"" + filterType + "\" filter against \"" + apiType + "\" api is not implemented. Please ensure \"targetEntity\" is defined on the query.");
|
|
18786
18529
|
}
|
|
18787
18530
|
return [2 /*return*/, fn(cloneObject$1(query), options)];
|
|
18788
18531
|
});
|
|
18789
18532
|
});
|
|
18790
18533
|
}
|
|
18791
18534
|
|
|
18535
|
+
/**
|
|
18536
|
+
* Collection Class
|
|
18537
|
+
*
|
|
18538
|
+
* Abstracts searching a Collection
|
|
18539
|
+
*
|
|
18540
|
+
* For more information, check out the [Catalog & Collection Guide](/hub.js/guides/concepts/catalog-collection/)
|
|
18541
|
+
*/
|
|
18542
|
+
var Collection = /** @class */ (function () {
|
|
18543
|
+
function Collection(collection, context) {
|
|
18544
|
+
this._collection = collection;
|
|
18545
|
+
this._context = context;
|
|
18546
|
+
}
|
|
18547
|
+
/**
|
|
18548
|
+
* Create an instance of a Collection from a JSON object
|
|
18549
|
+
* @param collection
|
|
18550
|
+
* @param context
|
|
18551
|
+
* @returns
|
|
18552
|
+
*/
|
|
18553
|
+
Collection.fromJson = function (collection, context) {
|
|
18554
|
+
return new Collection(collection, context);
|
|
18555
|
+
};
|
|
18556
|
+
/**
|
|
18557
|
+
* Return the JSON object backing the instance
|
|
18558
|
+
* @returns
|
|
18559
|
+
*/
|
|
18560
|
+
Collection.prototype.toJson = function () {
|
|
18561
|
+
return cloneObject$1(this._collection);
|
|
18562
|
+
};
|
|
18563
|
+
Object.defineProperty(Collection.prototype, "label", {
|
|
18564
|
+
// Getters
|
|
18565
|
+
get: function () {
|
|
18566
|
+
return this._collection.label;
|
|
18567
|
+
},
|
|
18568
|
+
enumerable: false,
|
|
18569
|
+
configurable: true
|
|
18570
|
+
});
|
|
18571
|
+
Object.defineProperty(Collection.prototype, "key", {
|
|
18572
|
+
get: function () {
|
|
18573
|
+
return this._collection.key;
|
|
18574
|
+
},
|
|
18575
|
+
enumerable: false,
|
|
18576
|
+
configurable: true
|
|
18577
|
+
});
|
|
18578
|
+
Object.defineProperty(Collection.prototype, "include", {
|
|
18579
|
+
get: function () {
|
|
18580
|
+
return this._collection.include || [];
|
|
18581
|
+
},
|
|
18582
|
+
enumerable: false,
|
|
18583
|
+
configurable: true
|
|
18584
|
+
});
|
|
18585
|
+
Object.defineProperty(Collection.prototype, "scope", {
|
|
18586
|
+
get: function () {
|
|
18587
|
+
return this._collection.scope;
|
|
18588
|
+
},
|
|
18589
|
+
enumerable: false,
|
|
18590
|
+
configurable: true
|
|
18591
|
+
});
|
|
18592
|
+
Object.defineProperty(Collection.prototype, "sortField", {
|
|
18593
|
+
get: function () {
|
|
18594
|
+
return this._collection.sortField || "title";
|
|
18595
|
+
},
|
|
18596
|
+
enumerable: false,
|
|
18597
|
+
configurable: true
|
|
18598
|
+
});
|
|
18599
|
+
Object.defineProperty(Collection.prototype, "sortDirection", {
|
|
18600
|
+
get: function () {
|
|
18601
|
+
return this._collection.sortDirection || "asc";
|
|
18602
|
+
},
|
|
18603
|
+
enumerable: false,
|
|
18604
|
+
configurable: true
|
|
18605
|
+
});
|
|
18606
|
+
Object.defineProperty(Collection.prototype, "targetEntity", {
|
|
18607
|
+
get: function () {
|
|
18608
|
+
return this._collection.targetEntity;
|
|
18609
|
+
},
|
|
18610
|
+
enumerable: false,
|
|
18611
|
+
configurable: true
|
|
18612
|
+
});
|
|
18613
|
+
/**
|
|
18614
|
+
* Search the collection using a string or IQuery
|
|
18615
|
+
* @param query
|
|
18616
|
+
* @param options
|
|
18617
|
+
* @returns
|
|
18618
|
+
*/
|
|
18619
|
+
Collection.prototype.search = function (query, options) {
|
|
18620
|
+
if (options === void 0) { options = {}; }
|
|
18621
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
18622
|
+
var qry, opts;
|
|
18623
|
+
return __generator(this, function (_a) {
|
|
18624
|
+
if (typeof query === "string") {
|
|
18625
|
+
// construct a query from that...
|
|
18626
|
+
qry = {
|
|
18627
|
+
targetEntity: this._collection.targetEntity,
|
|
18628
|
+
filters: [
|
|
18629
|
+
{
|
|
18630
|
+
predicates: [
|
|
18631
|
+
{
|
|
18632
|
+
term: query,
|
|
18633
|
+
},
|
|
18634
|
+
],
|
|
18635
|
+
},
|
|
18636
|
+
],
|
|
18637
|
+
};
|
|
18638
|
+
}
|
|
18639
|
+
else {
|
|
18640
|
+
qry = query;
|
|
18641
|
+
}
|
|
18642
|
+
// TODO: What should happen when a Query is passed in that has a targetEntity that doesn't match the collection's targetEntity?
|
|
18643
|
+
// merge the passed in query w/ the scope
|
|
18644
|
+
qry.filters = __spreadArrays(qry.filters, this.scope.filters);
|
|
18645
|
+
opts = cloneObject$1(options);
|
|
18646
|
+
opts.requestOptions = this._context.hubRequestOptions;
|
|
18647
|
+
// inject default sort info if not specified
|
|
18648
|
+
opts.sortField = options.sortField || this.sortField;
|
|
18649
|
+
opts.sortOrder = options.sortOrder || this.sortDirection;
|
|
18650
|
+
// inject default includes if not specified
|
|
18651
|
+
opts.include = options.include || this.include;
|
|
18652
|
+
// execute the search and return results
|
|
18653
|
+
return [2 /*return*/, hubSearch(qry, opts)];
|
|
18654
|
+
});
|
|
18655
|
+
});
|
|
18656
|
+
};
|
|
18657
|
+
return Collection;
|
|
18658
|
+
}());
|
|
18659
|
+
|
|
18660
|
+
/**
|
|
18661
|
+
* Fetch a IHubCatalog from a backing item.
|
|
18662
|
+
* This will apply schema upgrades to the structure
|
|
18663
|
+
* @param identifier
|
|
18664
|
+
* @param requestOptions
|
|
18665
|
+
* @returns
|
|
18666
|
+
*/
|
|
18667
|
+
function fetchCatalog(identifier, requestOptions) {
|
|
18668
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
18669
|
+
var getPrms, url, fetched;
|
|
18670
|
+
return __generator(this, function (_a) {
|
|
18671
|
+
switch (_a.label) {
|
|
18672
|
+
case 0:
|
|
18673
|
+
// identifier can be a guid or a url
|
|
18674
|
+
if (identifier.indexOf("http") === 0) {
|
|
18675
|
+
url = identifier;
|
|
18676
|
+
// get down the the hostname
|
|
18677
|
+
url = stripProtocol(url);
|
|
18678
|
+
// if url does not include a hash (i.e. it's not portal)
|
|
18679
|
+
// then we want to split on the first slash to get the hostname
|
|
18680
|
+
// lookupDomain will handle the enterprise base urls
|
|
18681
|
+
if (!url.includes("#")) {
|
|
18682
|
+
url = url.split("/")[0];
|
|
18683
|
+
}
|
|
18684
|
+
getPrms = lookupDomain(url, requestOptions)
|
|
18685
|
+
// get the item's data, and read the catalog out of it
|
|
18686
|
+
.then(function (_a) {
|
|
18687
|
+
var siteId = _a.siteId;
|
|
18688
|
+
return getItemData(siteId, requestOptions);
|
|
18689
|
+
})
|
|
18690
|
+
.then(function (data) {
|
|
18691
|
+
return upgradeCatalogSchema(data.catalog || {});
|
|
18692
|
+
});
|
|
18693
|
+
}
|
|
18694
|
+
else if (isGuid(identifier)) {
|
|
18695
|
+
// get the item's data, and read the catalog out of it
|
|
18696
|
+
getPrms = getItemData(identifier, requestOptions).then(function (data) {
|
|
18697
|
+
return upgradeCatalogSchema(data.catalog || {});
|
|
18698
|
+
});
|
|
18699
|
+
}
|
|
18700
|
+
else {
|
|
18701
|
+
throw new HubError$1("Catalog.create", "Identifier must be a url, guid");
|
|
18702
|
+
}
|
|
18703
|
+
return [4 /*yield*/, getPrms];
|
|
18704
|
+
case 1:
|
|
18705
|
+
fetched = _a.sent();
|
|
18706
|
+
return [2 /*return*/, fetched];
|
|
18707
|
+
}
|
|
18708
|
+
});
|
|
18709
|
+
});
|
|
18710
|
+
}
|
|
18711
|
+
|
|
18712
|
+
/**
|
|
18713
|
+
* Catalog Class
|
|
18714
|
+
*
|
|
18715
|
+
* Abstracts working with Catalogs and fetching collections with
|
|
18716
|
+
* the correct scope applied.
|
|
18717
|
+
*
|
|
18718
|
+
* For more information, check out the [Catalog & Collection Guide](/hub.js/guides/concepts/catalog-collection/)
|
|
18719
|
+
*/
|
|
18720
|
+
var Catalog = /** @class */ (function () {
|
|
18721
|
+
// internal - use static factory methods
|
|
18722
|
+
function Catalog(catalog, context) {
|
|
18723
|
+
this._catalog = catalog;
|
|
18724
|
+
this._context = context;
|
|
18725
|
+
}
|
|
18726
|
+
/**
|
|
18727
|
+
* Create a Collection instance from a Catalog json object, a site url or itemId
|
|
18728
|
+
* '''js
|
|
18729
|
+
* const catalog = await Catalog.create('https://site-org.hub.arcgis.com', context);
|
|
18730
|
+
* '''
|
|
18731
|
+
*
|
|
18732
|
+
* @param identifier
|
|
18733
|
+
* @param context
|
|
18734
|
+
* @returns
|
|
18735
|
+
*/
|
|
18736
|
+
Catalog.init = function (identifier, context) {
|
|
18737
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
18738
|
+
var mgr, fetched;
|
|
18739
|
+
return __generator(this, function (_a) {
|
|
18740
|
+
switch (_a.label) {
|
|
18741
|
+
case 0:
|
|
18742
|
+
if (!!context) return [3 /*break*/, 2];
|
|
18743
|
+
return [4 /*yield*/, ArcGISContextManager.create()];
|
|
18744
|
+
case 1:
|
|
18745
|
+
mgr = _a.sent();
|
|
18746
|
+
context = mgr.context;
|
|
18747
|
+
_a.label = 2;
|
|
18748
|
+
case 2: return [4 /*yield*/, fetchCatalog(identifier, context.hubRequestOptions)];
|
|
18749
|
+
case 3:
|
|
18750
|
+
fetched = _a.sent();
|
|
18751
|
+
// return an instance
|
|
18752
|
+
return [2 /*return*/, new Catalog(fetched, context)];
|
|
18753
|
+
}
|
|
18754
|
+
});
|
|
18755
|
+
});
|
|
18756
|
+
};
|
|
18757
|
+
/**
|
|
18758
|
+
* Create a Catalog instance from a Catalog Json object
|
|
18759
|
+
* @param json
|
|
18760
|
+
* @param context
|
|
18761
|
+
* @returns
|
|
18762
|
+
*/
|
|
18763
|
+
Catalog.fromJson = function (json, context) {
|
|
18764
|
+
// ensure it's in the latest structure
|
|
18765
|
+
var catalog = upgradeCatalogSchema(json);
|
|
18766
|
+
return new Catalog(catalog, context);
|
|
18767
|
+
};
|
|
18768
|
+
/**
|
|
18769
|
+
* Return the JSON object backing the instance
|
|
18770
|
+
* @returns
|
|
18771
|
+
*/
|
|
18772
|
+
Catalog.prototype.toJson = function () {
|
|
18773
|
+
return cloneObject$1(this._catalog);
|
|
18774
|
+
};
|
|
18775
|
+
Object.defineProperty(Catalog.prototype, "schemaVersion", {
|
|
18776
|
+
/**
|
|
18777
|
+
* Return the schema version
|
|
18778
|
+
*/
|
|
18779
|
+
get: function () {
|
|
18780
|
+
return this._catalog.schemaVersion;
|
|
18781
|
+
},
|
|
18782
|
+
enumerable: false,
|
|
18783
|
+
configurable: true
|
|
18784
|
+
});
|
|
18785
|
+
Object.defineProperty(Catalog.prototype, "title", {
|
|
18786
|
+
/**
|
|
18787
|
+
* Title getter
|
|
18788
|
+
*/
|
|
18789
|
+
get: function () {
|
|
18790
|
+
return this._catalog.title;
|
|
18791
|
+
},
|
|
18792
|
+
/**
|
|
18793
|
+
* Title setter
|
|
18794
|
+
*/
|
|
18795
|
+
set: function (v) {
|
|
18796
|
+
this._catalog.title = v;
|
|
18797
|
+
},
|
|
18798
|
+
enumerable: false,
|
|
18799
|
+
configurable: true
|
|
18800
|
+
});
|
|
18801
|
+
Object.defineProperty(Catalog.prototype, "scopes", {
|
|
18802
|
+
/**
|
|
18803
|
+
* Return the existing scopes hash
|
|
18804
|
+
*/
|
|
18805
|
+
get: function () {
|
|
18806
|
+
return this._catalog.scopes;
|
|
18807
|
+
},
|
|
18808
|
+
enumerable: false,
|
|
18809
|
+
configurable: true
|
|
18810
|
+
});
|
|
18811
|
+
Object.defineProperty(Catalog.prototype, "availableScopes", {
|
|
18812
|
+
/**
|
|
18813
|
+
* Return an array of the entity types available in this Catalog
|
|
18814
|
+
*/
|
|
18815
|
+
get: function () {
|
|
18816
|
+
return Object.keys(this.scopes);
|
|
18817
|
+
},
|
|
18818
|
+
enumerable: false,
|
|
18819
|
+
configurable: true
|
|
18820
|
+
});
|
|
18821
|
+
/**
|
|
18822
|
+
* Get the scope's query for a particular entity type
|
|
18823
|
+
* @param type
|
|
18824
|
+
* @returns
|
|
18825
|
+
*/
|
|
18826
|
+
Catalog.prototype.getScope = function (type) {
|
|
18827
|
+
return this._catalog.scopes[type];
|
|
18828
|
+
};
|
|
18829
|
+
/**
|
|
18830
|
+
* Set the scope for a specific entity type
|
|
18831
|
+
* @param type
|
|
18832
|
+
* @param query
|
|
18833
|
+
*/
|
|
18834
|
+
Catalog.prototype.setScope = function (type, query) {
|
|
18835
|
+
this._catalog.scopes[type] = query;
|
|
18836
|
+
};
|
|
18837
|
+
Object.defineProperty(Catalog.prototype, "collections", {
|
|
18838
|
+
/**
|
|
18839
|
+
* Get the collections array. Returns simple objects not Collection instances
|
|
18840
|
+
*/
|
|
18841
|
+
get: function () {
|
|
18842
|
+
return this._catalog.collections || [];
|
|
18843
|
+
},
|
|
18844
|
+
enumerable: false,
|
|
18845
|
+
configurable: true
|
|
18846
|
+
});
|
|
18847
|
+
Object.defineProperty(Catalog.prototype, "collectionNames", {
|
|
18848
|
+
/**
|
|
18849
|
+
* Get the names of the collections
|
|
18850
|
+
*/
|
|
18851
|
+
get: function () {
|
|
18852
|
+
return mapBy("key", this.collections);
|
|
18853
|
+
},
|
|
18854
|
+
enumerable: false,
|
|
18855
|
+
configurable: true
|
|
18856
|
+
});
|
|
18857
|
+
/**
|
|
18858
|
+
* Get a Collection instance by name
|
|
18859
|
+
* @param name
|
|
18860
|
+
* @returns
|
|
18861
|
+
*/
|
|
18862
|
+
Catalog.prototype.getCollection = function (name) {
|
|
18863
|
+
var json = this.collections.find(function (entry) { return entry.key === name; });
|
|
18864
|
+
if (json) {
|
|
18865
|
+
// clone it then merge in the associated scope filter
|
|
18866
|
+
var clone = cloneObject$1(json);
|
|
18867
|
+
var catalogScope = this.getScope(clone.scope.targetEntity);
|
|
18868
|
+
if (catalogScope === null || catalogScope === void 0 ? void 0 : catalogScope.filters) {
|
|
18869
|
+
clone.scope.filters = __spreadArrays(clone.scope.filters, catalogScope.filters);
|
|
18870
|
+
}
|
|
18871
|
+
return Collection.fromJson(clone, this._context);
|
|
18872
|
+
}
|
|
18873
|
+
else {
|
|
18874
|
+
throw new HubError$1("getCollection", "Collection \"" + name + "\" is not present in the Catalog");
|
|
18875
|
+
}
|
|
18876
|
+
};
|
|
18877
|
+
/**
|
|
18878
|
+
* Search for Items
|
|
18879
|
+
* Will throw if the Catalog does not have a scope defined for items
|
|
18880
|
+
* @param query
|
|
18881
|
+
* @param options
|
|
18882
|
+
* @returns
|
|
18883
|
+
*/
|
|
18884
|
+
Catalog.prototype.searchItems = function (query, options) {
|
|
18885
|
+
if (options === void 0) { options = {}; }
|
|
18886
|
+
if (!this.getScope("item")) {
|
|
18887
|
+
var result = this.getEmptyResult();
|
|
18888
|
+
result.messages = [
|
|
18889
|
+
{
|
|
18890
|
+
code: "missingScope",
|
|
18891
|
+
message: "Catalog does not have a scope for items",
|
|
18892
|
+
data: {
|
|
18893
|
+
scope: "item",
|
|
18894
|
+
},
|
|
18895
|
+
},
|
|
18896
|
+
];
|
|
18897
|
+
return Promise.resolve(result);
|
|
18898
|
+
}
|
|
18899
|
+
else {
|
|
18900
|
+
// ensure it's an item search
|
|
18901
|
+
options.targetEntity = "item";
|
|
18902
|
+
return this.search(query, options);
|
|
18903
|
+
}
|
|
18904
|
+
};
|
|
18905
|
+
/**
|
|
18906
|
+
* Search for Groups
|
|
18907
|
+
* Will throw if the Catalog does not have a scope defined for groups
|
|
18908
|
+
* @param query
|
|
18909
|
+
* @param options
|
|
18910
|
+
* @returns
|
|
18911
|
+
*/
|
|
18912
|
+
Catalog.prototype.searchGroups = function (query, options) {
|
|
18913
|
+
if (options === void 0) { options = {}; }
|
|
18914
|
+
if (!this.getScope("group")) {
|
|
18915
|
+
var result = this.getEmptyResult();
|
|
18916
|
+
result.messages = [
|
|
18917
|
+
{
|
|
18918
|
+
code: "missingScope",
|
|
18919
|
+
message: "Catalog does not have a scope for groups",
|
|
18920
|
+
data: {
|
|
18921
|
+
scope: "group",
|
|
18922
|
+
},
|
|
18923
|
+
},
|
|
18924
|
+
];
|
|
18925
|
+
return Promise.resolve(result);
|
|
18926
|
+
}
|
|
18927
|
+
else {
|
|
18928
|
+
// ensure it's an group search
|
|
18929
|
+
options.targetEntity = "group";
|
|
18930
|
+
return this.search(query, options);
|
|
18931
|
+
}
|
|
18932
|
+
};
|
|
18933
|
+
/**
|
|
18934
|
+
* Search for Users
|
|
18935
|
+
* Will throw if the Catalog does not have a scope defined for users
|
|
18936
|
+
* @param query
|
|
18937
|
+
* @param options
|
|
18938
|
+
* @returns
|
|
18939
|
+
*/
|
|
18940
|
+
Catalog.prototype.searchUsers = function (query, options) {
|
|
18941
|
+
if (options === void 0) { options = {}; }
|
|
18942
|
+
if (!this.getScope("user")) {
|
|
18943
|
+
var result = this.getEmptyResult();
|
|
18944
|
+
result.messages = [
|
|
18945
|
+
{
|
|
18946
|
+
code: "missingScope",
|
|
18947
|
+
message: "Catalog does not have a scope for user",
|
|
18948
|
+
data: {
|
|
18949
|
+
scope: "user",
|
|
18950
|
+
},
|
|
18951
|
+
},
|
|
18952
|
+
];
|
|
18953
|
+
return Promise.resolve(result);
|
|
18954
|
+
}
|
|
18955
|
+
else {
|
|
18956
|
+
// ensure it's an group search
|
|
18957
|
+
options.targetEntity = "user";
|
|
18958
|
+
return this.search(query, options);
|
|
18959
|
+
}
|
|
18960
|
+
};
|
|
18961
|
+
/**
|
|
18962
|
+
* Execute a search against all the collections in the Catalog
|
|
18963
|
+
* @param query
|
|
18964
|
+
* @param options
|
|
18965
|
+
* @returns
|
|
18966
|
+
*/
|
|
18967
|
+
Catalog.prototype.searchCollections = function (query, options) {
|
|
18968
|
+
if (options === void 0) { options = {}; }
|
|
18969
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
18970
|
+
var qry, promiseKeys, promises, responses, hash, i;
|
|
18971
|
+
var _this = this;
|
|
18972
|
+
return __generator(this, function (_a) {
|
|
18973
|
+
switch (_a.label) {
|
|
18974
|
+
case 0:
|
|
18975
|
+
qry = {
|
|
18976
|
+
targetEntity: "item",
|
|
18977
|
+
filters: [
|
|
18978
|
+
{
|
|
18979
|
+
predicates: [
|
|
18980
|
+
{
|
|
18981
|
+
term: query,
|
|
18982
|
+
},
|
|
18983
|
+
],
|
|
18984
|
+
},
|
|
18985
|
+
],
|
|
18986
|
+
};
|
|
18987
|
+
promiseKeys = [];
|
|
18988
|
+
promises = this.collectionNames.map(function (name) {
|
|
18989
|
+
var col = _this.getCollection(name);
|
|
18990
|
+
promiseKeys.push(name);
|
|
18991
|
+
qry.targetEntity = col.targetEntity;
|
|
18992
|
+
return col.search(qry, options);
|
|
18993
|
+
});
|
|
18994
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
18995
|
+
case 1:
|
|
18996
|
+
responses = _a.sent();
|
|
18997
|
+
hash = {};
|
|
18998
|
+
for (i = 0; i < promiseKeys.length; i++) {
|
|
18999
|
+
hash[promiseKeys[i]] = responses[i];
|
|
19000
|
+
}
|
|
19001
|
+
return [2 /*return*/, hash];
|
|
19002
|
+
}
|
|
19003
|
+
});
|
|
19004
|
+
});
|
|
19005
|
+
};
|
|
19006
|
+
/**
|
|
19007
|
+
* Execute a search against all the scopes in the Catalog
|
|
19008
|
+
* @param query
|
|
19009
|
+
* @param options
|
|
19010
|
+
* @returns
|
|
19011
|
+
*/
|
|
19012
|
+
Catalog.prototype.searchScopes = function (query, options) {
|
|
19013
|
+
if (options === void 0) { options = {}; }
|
|
19014
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
19015
|
+
var qry, promiseKeys, promises, responses, hash, i;
|
|
19016
|
+
var _this = this;
|
|
19017
|
+
return __generator(this, function (_a) {
|
|
19018
|
+
switch (_a.label) {
|
|
19019
|
+
case 0:
|
|
19020
|
+
qry = {
|
|
19021
|
+
targetEntity: "item",
|
|
19022
|
+
filters: [
|
|
19023
|
+
{
|
|
19024
|
+
predicates: [
|
|
19025
|
+
{
|
|
19026
|
+
term: query,
|
|
19027
|
+
},
|
|
19028
|
+
],
|
|
19029
|
+
},
|
|
19030
|
+
],
|
|
19031
|
+
};
|
|
19032
|
+
promiseKeys = [];
|
|
19033
|
+
promises = this.availableScopes.map(function (name) {
|
|
19034
|
+
promiseKeys.push(name);
|
|
19035
|
+
// make clones
|
|
19036
|
+
var qryClone = cloneObject$1(qry);
|
|
19037
|
+
var optsClone = cloneObject$1(options);
|
|
19038
|
+
// set the target entity
|
|
19039
|
+
qryClone.targetEntity = name;
|
|
19040
|
+
optsClone.targetEntity = name;
|
|
19041
|
+
// return the search promise
|
|
19042
|
+
return _this.search(qryClone, optsClone);
|
|
19043
|
+
});
|
|
19044
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
19045
|
+
case 1:
|
|
19046
|
+
responses = _a.sent();
|
|
19047
|
+
hash = {};
|
|
19048
|
+
for (i = 0; i < promiseKeys.length; i++) {
|
|
19049
|
+
hash[promiseKeys[i]] = responses[i];
|
|
19050
|
+
}
|
|
19051
|
+
return [2 /*return*/, hash];
|
|
19052
|
+
}
|
|
19053
|
+
});
|
|
19054
|
+
});
|
|
19055
|
+
};
|
|
19056
|
+
/**
|
|
19057
|
+
* Execute a search against the Catalog as a whole
|
|
19058
|
+
* @param query
|
|
19059
|
+
* @param targetEntity
|
|
19060
|
+
* @returns
|
|
19061
|
+
*/
|
|
19062
|
+
Catalog.prototype.search = function (query, options) {
|
|
19063
|
+
var targetEntity = options.targetEntity;
|
|
19064
|
+
var qry;
|
|
19065
|
+
if (typeof query === "string") {
|
|
19066
|
+
qry = {
|
|
19067
|
+
targetEntity: targetEntity,
|
|
19068
|
+
filters: [
|
|
19069
|
+
{
|
|
19070
|
+
predicates: [
|
|
19071
|
+
{
|
|
19072
|
+
term: query,
|
|
19073
|
+
},
|
|
19074
|
+
],
|
|
19075
|
+
},
|
|
19076
|
+
],
|
|
19077
|
+
};
|
|
19078
|
+
}
|
|
19079
|
+
else {
|
|
19080
|
+
qry = cloneObject$1(query);
|
|
19081
|
+
}
|
|
19082
|
+
// Now merge in catalog scope level filters
|
|
19083
|
+
qry.filters = __spreadArrays(qry.filters, this.getScope(targetEntity).filters);
|
|
19084
|
+
var opts = cloneObject$1(options);
|
|
19085
|
+
// An Catalog instance always uses the context so we remove/replace any passed in auth
|
|
19086
|
+
delete opts.authentication;
|
|
19087
|
+
opts.requestOptions = this._context.hubRequestOptions;
|
|
19088
|
+
return hubSearch(qry, opts);
|
|
19089
|
+
};
|
|
19090
|
+
/**
|
|
19091
|
+
* Construct an empty result. Returned when a search is performed against an entity type that
|
|
19092
|
+
* does not have a scope defined.
|
|
19093
|
+
* @returns
|
|
19094
|
+
*/
|
|
19095
|
+
Catalog.prototype.getEmptyResult = function () {
|
|
19096
|
+
return {
|
|
19097
|
+
results: [],
|
|
19098
|
+
total: 0,
|
|
19099
|
+
hasNext: false,
|
|
19100
|
+
next: null,
|
|
19101
|
+
};
|
|
19102
|
+
};
|
|
19103
|
+
return Catalog;
|
|
19104
|
+
}());
|
|
19105
|
+
|
|
18792
19106
|
/**
|
|
18793
19107
|
* Enrich a generic search result
|
|
18794
19108
|
* @param group
|
|
@@ -20399,6 +20713,8 @@
|
|
|
20399
20713
|
|
|
20400
20714
|
exports.ArcGISContext = ArcGISContext;
|
|
20401
20715
|
exports.ArcGISContextManager = ArcGISContextManager;
|
|
20716
|
+
exports.Catalog = Catalog;
|
|
20717
|
+
exports.Collection = Collection;
|
|
20402
20718
|
exports.DEFAULT_THEME = DEFAULT_THEME;
|
|
20403
20719
|
exports.ENTERPRISE_SITE_ITEM_TYPE = ENTERPRISE_SITE_ITEM_TYPE;
|
|
20404
20720
|
exports.GLOBAL_EXTENT = GLOBAL_EXTENT;
|
|
@@ -20460,7 +20776,6 @@
|
|
|
20460
20776
|
exports.addSiteDomains = addSiteDomains;
|
|
20461
20777
|
exports.addSolutionResourceUrlToAssets = addSolutionResourceUrlToAssets;
|
|
20462
20778
|
exports.addUsersToGroup = addUsersToGroup;
|
|
20463
|
-
exports.applyCollectionState = applyCollectionState;
|
|
20464
20779
|
exports.applyPropertiesToItems = applyPropertiesToItems;
|
|
20465
20780
|
exports.arrayToObject = arrayToObject;
|
|
20466
20781
|
exports.atob = abab.atob;
|
|
@@ -20491,8 +20806,6 @@
|
|
|
20491
20806
|
exports.convertContentFilterToSearchOptions = convertContentFilterToSearchOptions;
|
|
20492
20807
|
exports.convertItemToProject = convertItemToProject;
|
|
20493
20808
|
exports.convertItemToSite = convertItemToSite;
|
|
20494
|
-
exports.convertPortalItemResponseToFacets = convertPortalItemResponseToFacets;
|
|
20495
|
-
exports.convertPortalResponseToFacets = convertPortalResponseToFacets;
|
|
20496
20809
|
exports.convertSolutionTemplateResourcesToAssets = convertSolutionTemplateResourcesToAssets;
|
|
20497
20810
|
exports.convertToWellKnownLocale = convertToWellKnownLocale;
|
|
20498
20811
|
exports.convertUrlsToAnchorTags = convertUrlsToAnchorTags;
|
|
@@ -20545,8 +20858,10 @@
|
|
|
20545
20858
|
exports.fetchContent = fetchContent;
|
|
20546
20859
|
exports.fetchHubTranslation = fetchHubTranslation;
|
|
20547
20860
|
exports.fetchImageAsBlob = fetchImageAsBlob;
|
|
20861
|
+
exports.fetchMaxNumUserGroupsLimit = fetchMaxNumUserGroupsLimit;
|
|
20548
20862
|
exports.fetchModelFromItem = fetchModelFromItem;
|
|
20549
20863
|
exports.fetchOrg = fetchOrg;
|
|
20864
|
+
exports.fetchOrgLimits = fetchOrgLimits;
|
|
20550
20865
|
exports.fetchProject = fetchProject;
|
|
20551
20866
|
exports.fetchSite = fetchSite;
|
|
20552
20867
|
exports.fetchSiteModel = fetchSiteModel;
|
|
@@ -20680,7 +20995,6 @@
|
|
|
20680
20995
|
exports.saveSession = saveSession;
|
|
20681
20996
|
exports.searchProjects = searchProjects;
|
|
20682
20997
|
exports.searchSites = searchSites;
|
|
20683
|
-
exports.serializeCollectionState = serializeCollectionState;
|
|
20684
20998
|
exports.serializeContentFilterForPortal = serializeContentFilterForPortal;
|
|
20685
20999
|
exports.serializeDateRange = serializeDateRange$1;
|
|
20686
21000
|
exports.serializeGroupFilterForPortal = serializeGroupFilterForPortal;
|
|
@@ -20708,6 +21022,7 @@
|
|
|
20708
21022
|
exports.updateModel = updateModel;
|
|
20709
21023
|
exports.updateProject = updateProject;
|
|
20710
21024
|
exports.updateSite = updateSite;
|
|
21025
|
+
exports.upgradeCatalogSchema = upgradeCatalogSchema;
|
|
20711
21026
|
exports.upgradeProtocol = upgradeProtocol;
|
|
20712
21027
|
exports.upgradeSiteSchema = upgradeSiteSchema;
|
|
20713
21028
|
exports.uploadResourcesFromUrl = uploadResourcesFromUrl;
|