@esri/hub-common 9.17.1 → 9.20.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 (132) hide show
  1. package/dist/es2017/Hub.js +6 -10
  2. package/dist/es2017/Hub.js.map +1 -1
  3. package/dist/es2017/content/_internal.js +151 -30
  4. package/dist/es2017/content/_internal.js.map +1 -1
  5. package/dist/es2017/content/compose.js +607 -0
  6. package/dist/es2017/content/compose.js.map +1 -0
  7. package/dist/es2017/content/get-family.js +42 -0
  8. package/dist/es2017/content/get-family.js.map +1 -0
  9. package/dist/es2017/content/index.js +42 -468
  10. package/dist/es2017/content/index.js.map +1 -1
  11. package/dist/es2017/core/types/IHubContentEnrichments.js +1 -0
  12. package/dist/es2017/core/types/IHubContentEnrichments.js.map +1 -0
  13. package/dist/es2017/core/types/IHubItemEntityManager.js +1 -0
  14. package/dist/es2017/core/types/IHubItemEntityManager.js.map +1 -0
  15. package/dist/es2017/core/types/IServerEnrichments.js +1 -0
  16. package/dist/es2017/core/types/IServerEnrichments.js.map +1 -0
  17. package/dist/es2017/core/types/index.js +2 -1
  18. package/dist/es2017/core/types/index.js.map +1 -1
  19. package/dist/es2017/items/index.js +1 -0
  20. package/dist/es2017/items/index.js.map +1 -1
  21. package/dist/es2017/items/setItemThumbnail.js +31 -0
  22. package/dist/es2017/items/setItemThumbnail.js.map +1 -0
  23. package/dist/es2017/items/slugs.js +39 -15
  24. package/dist/es2017/items/slugs.js.map +1 -1
  25. package/dist/es2017/models/index.js +13 -0
  26. package/dist/es2017/models/index.js.map +1 -1
  27. package/dist/es2017/projects/HubProjectManager.js +40 -4
  28. package/dist/es2017/projects/HubProjectManager.js.map +1 -1
  29. package/dist/es2017/projects/HubProjects.js +91 -18
  30. package/dist/es2017/projects/HubProjects.js.map +1 -1
  31. package/dist/es2017/sites/domains/index.js +1 -0
  32. package/dist/es2017/sites/domains/index.js.map +1 -1
  33. package/dist/es2017/sites/domains/remove-domains-by-site-id.js +20 -0
  34. package/dist/es2017/sites/domains/remove-domains-by-site-id.js.map +1 -0
  35. package/dist/esm/Hub.js +6 -10
  36. package/dist/esm/Hub.js.map +1 -1
  37. package/dist/esm/content/_internal.js +153 -30
  38. package/dist/esm/content/_internal.js.map +1 -1
  39. package/dist/esm/content/compose.js +600 -0
  40. package/dist/esm/content/compose.js.map +1 -0
  41. package/dist/esm/content/get-family.js +42 -0
  42. package/dist/esm/content/get-family.js.map +1 -0
  43. package/dist/esm/content/index.js +44 -476
  44. package/dist/esm/content/index.js.map +1 -1
  45. package/dist/esm/core/types/IHubContentEnrichments.js +1 -0
  46. package/dist/esm/core/types/IHubContentEnrichments.js.map +1 -0
  47. package/dist/esm/core/types/IHubItemEntityManager.js +1 -0
  48. package/dist/esm/core/types/IHubItemEntityManager.js.map +1 -0
  49. package/dist/esm/core/types/IServerEnrichments.js +1 -0
  50. package/dist/esm/core/types/IServerEnrichments.js.map +1 -0
  51. package/dist/esm/core/types/index.js +2 -1
  52. package/dist/esm/core/types/index.js.map +1 -1
  53. package/dist/esm/items/index.js +1 -0
  54. package/dist/esm/items/index.js.map +1 -1
  55. package/dist/esm/items/setItemThumbnail.js +46 -0
  56. package/dist/esm/items/setItemThumbnail.js.map +1 -0
  57. package/dist/esm/items/slugs.js +39 -15
  58. package/dist/esm/items/slugs.js.map +1 -1
  59. package/dist/esm/models/index.js +23 -1
  60. package/dist/esm/models/index.js.map +1 -1
  61. package/dist/esm/projects/HubProjectManager.js +58 -4
  62. package/dist/esm/projects/HubProjectManager.js.map +1 -1
  63. package/dist/esm/projects/HubProjects.js +100 -21
  64. package/dist/esm/projects/HubProjects.js.map +1 -1
  65. package/dist/esm/sites/domains/index.js +1 -0
  66. package/dist/esm/sites/domains/index.js.map +1 -1
  67. package/dist/esm/sites/domains/remove-domains-by-site-id.js +20 -0
  68. package/dist/esm/sites/domains/remove-domains-by-site-id.js.map +1 -0
  69. package/dist/node/Hub.js +6 -10
  70. package/dist/node/Hub.js.map +1 -1
  71. package/dist/node/content/_internal.js +155 -31
  72. package/dist/node/content/_internal.js.map +1 -1
  73. package/dist/node/content/compose.js +612 -0
  74. package/dist/node/content/compose.js.map +1 -0
  75. package/dist/node/content/get-family.js +46 -0
  76. package/dist/node/content/get-family.js.map +1 -0
  77. package/dist/node/content/index.js +48 -477
  78. package/dist/node/content/index.js.map +1 -1
  79. package/dist/node/core/types/IHubContentEnrichments.js +3 -0
  80. package/dist/node/core/types/IHubContentEnrichments.js.map +1 -0
  81. package/dist/node/core/types/IHubItemEntityManager.js +3 -0
  82. package/dist/node/core/types/IHubItemEntityManager.js.map +1 -0
  83. package/dist/node/core/types/{IContentEnrichments.js → IServerEnrichments.js} +1 -1
  84. package/dist/node/core/types/IServerEnrichments.js.map +1 -0
  85. package/dist/node/core/types/index.js +2 -1
  86. package/dist/node/core/types/index.js.map +1 -1
  87. package/dist/node/items/index.js +1 -0
  88. package/dist/node/items/index.js.map +1 -1
  89. package/dist/node/items/setItemThumbnail.js +35 -0
  90. package/dist/node/items/setItemThumbnail.js.map +1 -0
  91. package/dist/node/items/slugs.js +42 -17
  92. package/dist/node/items/slugs.js.map +1 -1
  93. package/dist/node/models/index.js +15 -1
  94. package/dist/node/models/index.js.map +1 -1
  95. package/dist/node/projects/HubProjectManager.js +38 -2
  96. package/dist/node/projects/HubProjectManager.js.map +1 -1
  97. package/dist/node/projects/HubProjects.js +91 -17
  98. package/dist/node/projects/HubProjects.js.map +1 -1
  99. package/dist/node/sites/domains/index.js +1 -0
  100. package/dist/node/sites/domains/index.js.map +1 -1
  101. package/dist/node/sites/domains/remove-domains-by-site-id.js +24 -0
  102. package/dist/node/sites/domains/remove-domains-by-site-id.js.map +1 -0
  103. package/dist/types/Hub.d.ts +7 -11
  104. package/dist/types/content/_internal.d.ts +57 -22
  105. package/dist/types/content/compose.d.ts +115 -0
  106. package/dist/types/content/get-family.d.ts +7 -0
  107. package/dist/types/content/index.d.ts +4 -86
  108. package/dist/types/core/types/IHubContent.d.ts +4 -2
  109. package/dist/types/core/types/IHubContentEnrichments.d.ts +15 -0
  110. package/dist/types/core/types/IHubEntityManager.d.ts +16 -0
  111. package/dist/types/core/types/IHubItemEntity.d.ts +1 -1
  112. package/dist/types/core/types/IHubItemEntityManager.d.ts +15 -0
  113. package/dist/types/core/types/{IContentEnrichments.d.ts → IServerEnrichments.d.ts} +3 -2
  114. package/dist/types/core/types/index.d.ts +2 -1
  115. package/dist/types/items/index.d.ts +1 -0
  116. package/dist/types/items/setItemThumbnail.d.ts +9 -0
  117. package/dist/types/items/slugs.d.ts +20 -1
  118. package/dist/types/models/index.d.ts +8 -0
  119. package/dist/types/projects/HubProjectManager.d.ts +21 -3
  120. package/dist/types/projects/HubProjects.d.ts +3 -1
  121. package/dist/types/sites/domains/index.d.ts +1 -0
  122. package/dist/types/sites/domains/remove-domains-by-site-id.d.ts +8 -0
  123. package/dist/umd/common.umd.js +1247 -654
  124. package/dist/umd/common.umd.js.map +1 -1
  125. package/dist/umd/common.umd.min.js +1 -1
  126. package/dist/umd/common.umd.min.js.map +1 -1
  127. package/package.json +1 -1
  128. package/dist/es2017/core/types/IContentEnrichments.js +0 -1
  129. package/dist/es2017/core/types/IContentEnrichments.js.map +0 -1
  130. package/dist/esm/core/types/IContentEnrichments.js +0 -1
  131. package/dist/esm/core/types/IContentEnrichments.js.map +0 -1
  132. package/dist/node/core/types/IContentEnrichments.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * @esri/hub-common - v9.17.0 - Thu Feb 17 2022 19:38:03 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/hub-common - v9.19.0 - Fri Feb 25 2022 14:52:42 GMT+0000 (Coordinated Universal Time)
3
3
  * Copyright (c) 2022 Environmental Systems Research Institute, Inc.
4
4
  * Apache-2.0
5
5
  */
@@ -5850,6 +5850,27 @@
5850
5850
  "Workflow Manager Package",
5851
5851
  ];
5852
5852
  var site$1 = ["Hub Site Application", "Site Application"];
5853
+ /**
5854
+ * ```js
5855
+ * import { getCollection } from "@esri/hub-common";
5856
+ * //
5857
+ * getCollection('Feature Layer')
5858
+ * > 'dataset'
5859
+ * ```
5860
+ * Get the Hub collection for a given item type
5861
+ * @param itemType The ArcGIS [item type](https://developers.arcgis.com/rest/users-groups-and-items/items-and-item-types.htm).
5862
+ * @returns the Hub collection of a given item type.
5863
+ */
5864
+ var getCollection = function (type) {
5865
+ if (!type) {
5866
+ return;
5867
+ }
5868
+ var lowerCaseType = type.toLocaleLowerCase();
5869
+ return Object.keys(collections).find(function (key) {
5870
+ var collectionTypes = collections[key];
5871
+ return collectionTypes.some(function (t) { return t.toLocaleLowerCase() === lowerCaseType; });
5872
+ });
5873
+ };
5853
5874
  // TODO: remove this at the next breaking change
5854
5875
  // it's only here to support deprecated categories
5855
5876
  var collections = {
@@ -6084,6 +6105,252 @@
6084
6105
  };
6085
6106
  };
6086
6107
 
6108
+ // private helper functions
6109
+ function collectionToFamily(collection) {
6110
+ var overrides = {
6111
+ other: "content",
6112
+ solution: "template",
6113
+ };
6114
+ return overrides[collection] || collection;
6115
+ }
6116
+ /**
6117
+ * return the Hub family given an item's type
6118
+ * @param type item type
6119
+ * @returns Hub family
6120
+ */
6121
+ function getFamily(type) {
6122
+ var family;
6123
+ // override default behavior for the rows that are highlighted in yellow here:
6124
+ // https://esriis.sharepoint.com/:x:/r/sites/ArcGISHub/_layouts/15/Doc.aspx?sourcedoc=%7BADA1C9DC-4F6C-4DE4-92C6-693EF9571CFA%7D&file=Hub%20Routes.xlsx&nav=MTBfe0VENEREQzI4LUZFMDctNEI0Ri04NjcyLThCQUE2MTA0MEZGRn1fezIwMTIwMEJFLTA4MEQtNEExRC05QzA4LTE5MTAzOUQwMEE1RH0&action=default&mobileredirect=true&cid=df1c874b-c367-4cea-bc13-7bebfad3f2ac
6125
+ switch ((type || "").toLowerCase()) {
6126
+ case "image service":
6127
+ family = "dataset";
6128
+ break;
6129
+ case "feature service":
6130
+ case "raster layer":
6131
+ // TODO: check if feature service has > 1 layer first?
6132
+ family = "map";
6133
+ break;
6134
+ case "microsoft excel":
6135
+ family = "document";
6136
+ break;
6137
+ case "cad drawing":
6138
+ case "feature collection template":
6139
+ case "report template":
6140
+ family = "content";
6141
+ break;
6142
+ default:
6143
+ // by default derive from collection
6144
+ family = collectionToFamily(getCollection(type));
6145
+ }
6146
+ return family;
6147
+ }
6148
+
6149
+ // TODO: this needs to be able to handle "automatic"
6150
+ var getContentBoundary = function (item) {
6151
+ var _a;
6152
+ var extent = item.extent;
6153
+ var isValidItemExtent = isBBox(extent);
6154
+ // user specified provenance is stored in item.properties
6155
+ var provenance = ((_a = item.properties) === null || _a === void 0 ? void 0 : _a.boundary) ||
6156
+ // but we default to item if the item has an extent
6157
+ (isValidItemExtent ? "item" : undefined);
6158
+ var geometry;
6159
+ switch (provenance) {
6160
+ case "item":
6161
+ geometry = isValidItemExtent ? bBoxToPolygon(extent) : null;
6162
+ break;
6163
+ case "none":
6164
+ geometry = null;
6165
+ break;
6166
+ // TODO: handle other provenances
6167
+ }
6168
+ // TODO: derive and return center
6169
+ return {
6170
+ provenance: provenance,
6171
+ geometry: geometry,
6172
+ };
6173
+ };
6174
+ // when no request options are provided, the underlying
6175
+ // request functions assume that we are online in production
6176
+ // so we only want use enterprise logic if isPortal is explicitly defined
6177
+ var isPortal = function (requestOptions) {
6178
+ return requestOptions && requestOptions.isPortal;
6179
+ };
6180
+ /**
6181
+ * Returns whether or not an item is a proxied csv
6182
+ *
6183
+ * @param item
6184
+ * @param requestOptions Hub Request Options (including whether we're in portal)
6185
+ * @returns
6186
+ */
6187
+ var isProxiedCSV = function (item, requestOptions) {
6188
+ return !isPortal(requestOptions) &&
6189
+ item.access === "public" &&
6190
+ item.type === "CSV" &&
6191
+ item.size <= 5000000;
6192
+ };
6193
+ var getHubRelativeUrl = function (type, identifier, typeKeywords) {
6194
+ // solution types have their own logic
6195
+ var contentUrl = getSolutionUrl(type, identifier, typeKeywords);
6196
+ if (!contentUrl) {
6197
+ var family = getFamily(type);
6198
+ var familiesWithPluralizedRoute = [
6199
+ "app",
6200
+ "dataset",
6201
+ "document",
6202
+ "map",
6203
+ "template",
6204
+ ];
6205
+ // default to the catchall content route
6206
+ var path = "/content";
6207
+ if (family === "feedback") {
6208
+ // the exception
6209
+ path = "/feedback/surveys";
6210
+ }
6211
+ else if (isPageType(type)) {
6212
+ // pages are in the document family,
6213
+ // but instead of showing the page's metadata on /documents/about
6214
+ // but we render the page on the pages route
6215
+ path = "/pages";
6216
+ }
6217
+ else if (familiesWithPluralizedRoute.indexOf(family) > -1) {
6218
+ // the rule: route name is plural of family name
6219
+ path = "/" + family + "s";
6220
+ }
6221
+ contentUrl = path + "/" + identifier;
6222
+ }
6223
+ return contentUrl;
6224
+ };
6225
+ var isPageType = function (type) {
6226
+ return ["Hub Page", "Site Page"].includes(type);
6227
+ };
6228
+ var getSolutionUrl = function (type, identifier, typeKeywords) {
6229
+ var hubUrl;
6230
+ if (type === "Solution") {
6231
+ // NOTE: as per the above spreadsheet,
6232
+ // solution types are now in the Template family
6233
+ // but we don't send them to the route for initiative templates
6234
+ if ((typeKeywords === null || typeKeywords === void 0 ? void 0 : typeKeywords.indexOf("Deployed")) > 0) {
6235
+ // deployed solutions go to the generic content route
6236
+ hubUrl = "/content/" + identifier;
6237
+ }
6238
+ // others go to the solution about route
6239
+ hubUrl = "/templates/" + identifier + "/about";
6240
+ }
6241
+ return hubUrl;
6242
+ };
6243
+ function getMetadataPath(identifier) {
6244
+ // NOTE: i have verified that this will work regardless of the "Metadata Style" set on the org
6245
+ var metadataPaths = {
6246
+ updateFrequency: "metadata.dataIdInfo.resMaint.maintFreq.MaintFreqCd.@_value",
6247
+ reviseDate: "metadata.dataIdInfo.idCitation.date.reviseDate",
6248
+ pubDate: "metadata.dataIdInfo.idCitation.date.pubDate",
6249
+ createDate: "metadata.dataIdInfo.idCitation.date.createDate",
6250
+ metadataUpdateFrequency: "metadata.mdMaint.maintFreq.MaintFreqCd.@_value",
6251
+ metadataUpdatedDate: "metadata.mdDateSt",
6252
+ };
6253
+ return metadataPaths[identifier];
6254
+ }
6255
+ function getValueFromMetadata(metadata, identifier) {
6256
+ var path = getMetadataPath(identifier);
6257
+ return path && getProp(metadata, path);
6258
+ }
6259
+ var DatePrecision;
6260
+ (function (DatePrecision) {
6261
+ DatePrecision["Year"] = "year";
6262
+ DatePrecision["Month"] = "month";
6263
+ DatePrecision["Day"] = "day";
6264
+ DatePrecision["Time"] = "time";
6265
+ })(DatePrecision || (DatePrecision = {}));
6266
+ /**
6267
+ * Parses an ISO8601 date string into a date and a precision.
6268
+ * This is because a) if somone entered 2018, we want to respect that and not treat it as the same as 2018-01-01
6269
+ * and b) you cannot naively call new Date with an ISO 8601 string that does not include time information
6270
+ * For example, when I, here in mountain time, do new Date('2018').getFullYear() I get "2017".
6271
+ * This is because when you do not provide time or timezone info, UTC is assumed, so new Date('2018') is 2018-01-01T00:00:00 in UTC
6272
+ * which is actually 7 hours earlier here in mountain time.
6273
+ *
6274
+ * @param {string} isoString
6275
+ * @return { date: Date, precision: DatePrecision }
6276
+ */
6277
+ function parseISODateString(isoString) {
6278
+ isoString = "" + isoString;
6279
+ var date;
6280
+ var precision;
6281
+ if (/^\d{4}$/.test(isoString)) {
6282
+ // yyyy
6283
+ date = new Date(+isoString, 0, 1);
6284
+ precision = DatePrecision.Year;
6285
+ }
6286
+ else if (/^\d{4}-\d{1,2}$/.test(isoString)) {
6287
+ // yyyy-mm
6288
+ var parts = isoString.split("-");
6289
+ date = new Date(+parts[0], +parts[1] - 1, 1);
6290
+ precision = DatePrecision.Month;
6291
+ }
6292
+ else if (/^\d{4}-\d{1,2}-\d{1,2}$/.test(isoString)) {
6293
+ // yyyy-mm-dd
6294
+ var parts = isoString.split("-");
6295
+ date = new Date(+parts[0], +parts[1] - 1, +parts[2]);
6296
+ precision = DatePrecision.Day;
6297
+ }
6298
+ else if (!Number.isNaN(Date.parse(isoString))) {
6299
+ // any other string parsable to a valid date
6300
+ date = new Date(isoString);
6301
+ precision = isoString.includes("T")
6302
+ ? DatePrecision.Time
6303
+ : DatePrecision.Day;
6304
+ }
6305
+ return date && precision && { date: date, precision: precision };
6306
+ }
6307
+ var getServerSpatialReference = function (server, layer) {
6308
+ var _a;
6309
+ var layerSpatialReference = (_a = layer === null || layer === void 0 ? void 0 : layer.extent) === null || _a === void 0 ? void 0 : _a.spatialReference;
6310
+ return layerSpatialReference || (server === null || server === void 0 ? void 0 : server.spatialReference);
6311
+ };
6312
+ // NOTE: IItem has spatialRefernce: ISpatialReference, but
6313
+ // the portal REST API returns spatialReference as as string
6314
+ // that is always either WKID like "102100" or
6315
+ // WKT like "NAD_1983_HARN_StatePlane_Hawaii_3_FIPS_5103_Feet"
6316
+ // so we coerce those string into a ISpatialReference object
6317
+ var getItemSpatialReference = function (item) {
6318
+ var spatialReference = item.spatialReference;
6319
+ if (!spatialReference || typeof spatialReference === "object") {
6320
+ // no need to try and transform this into an ISpatialReference
6321
+ return spatialReference;
6322
+ }
6323
+ // otherwise it _should_ be a string (if coming form the REST API)
6324
+ // but we force it in case it was set to a number somewhere outside of TS
6325
+ var spatialReferenceString = spatialReference + "";
6326
+ var wkid = parseInt(spatialReferenceString, 10);
6327
+ return isNaN(wkid)
6328
+ ? // string is not a number, assume it is WKT
6329
+ { wkt: spatialReferenceString }
6330
+ : //
6331
+ { wkid: wkid };
6332
+ };
6333
+
6334
+ /* Copyright (c) 2017-2019 Environmental Systems Research Institute, Inc.
6335
+ * Apache-2.0 */
6336
+ var serviceRegex = new RegExp(/.+(?:map|feature|image)server/i);
6337
+ /**
6338
+ * Return the service url. If not matched, returns what was passed in
6339
+ */
6340
+ function parseServiceUrl(url) {
6341
+ var match = url.match(serviceRegex);
6342
+ if (match) {
6343
+ return match[0];
6344
+ }
6345
+ else {
6346
+ return stripQueryString(url);
6347
+ }
6348
+ }
6349
+ function stripQueryString(url) {
6350
+ var stripped = url.split('?')[0];
6351
+ return cleanUrl(stripped);
6352
+ }
6353
+
6087
6354
  var STANDARD_LICENSES = [
6088
6355
  {
6089
6356
  type: "CC0-1.0",
@@ -6380,116 +6647,313 @@
6380
6647
  }
6381
6648
 
6382
6649
  /**
6383
- * Use this module for functions that do not need to be used by consumers (yet),
6384
- * but may be shared between hub.js modules, and/or need to be tested
6385
- * to get 100% coverage w/o writing cumbersome tests of higher level functions.
6386
- *
6387
- * Consuming will not be able to import these functions.
6388
- *
6389
- * It's probably a good pattern to add functions here first and then
6390
- * move them to index.ts only when they are needed by a consumer.
6650
+ * Get the fully qualified URL for an item's thumbnail
6651
+ * @param item w/ id, thumbnail, and access
6652
+ * @param portalUrlOrObject a portal base or API URL, a portal object, or request options containing either of those
6653
+ * @param optionsOrToken options including width and/or token for the current user's session; will only be appended as a query parameter if the item's access is **not** `public`
6654
+ * @returns URL to the item's thumbnail, defaults to `https://www.arcgis.com/sharing/rest/content/items/{item.id}/info/{item.thumbnail}`. Returns `null` if the item does not have a thumbnail assigned.
6391
6655
  */
6656
+ function getItemThumbnailUrl(item, portalUrlOrObject, optionsOrToken) {
6657
+ if (!item || !item.thumbnail) {
6658
+ // TODO: handle image types by returning the image (item data) itself?
6659
+ return null;
6660
+ }
6661
+ // tslint:disable-next-line prefer-const
6662
+ var _a = optionsOrToken || {}, token = _a.token, width = _a.width;
6663
+ // TODO: at the next breaking change drop support for passing token as string
6664
+ if (!token && typeof optionsOrToken === "string") {
6665
+ token = optionsOrToken;
6666
+ }
6667
+ var itemApiUrl = getItemApiUrl(item, portalUrlOrObject, token);
6668
+ var _b = itemApiUrl.split("?"), baseUrl = _b[0], search = _b[1];
6669
+ var searchParams = new URLSearchParams(search);
6670
+ searchParams.delete("f");
6671
+ if (width) {
6672
+ searchParams.append("w", width + "");
6673
+ }
6674
+ var newSearch = searchParams.toString();
6675
+ var url = baseUrl + "/info/" + item.thumbnail;
6676
+ return newSearch ? url + "?" + newSearch : url;
6677
+ }
6678
+
6679
+ // helper fns - move this to _internal if needed elsewhere
6680
+ var getOnlyQueryLayer = function (layers) {
6681
+ var layer = layers && layers.length === 1 && layers[0];
6682
+ return layer && layer.capabilities.includes("Query") && layer;
6683
+ };
6684
+ var shouldUseLayerInfo = function (layer, layers, url) {
6685
+ return (layer &&
6686
+ layers &&
6687
+ layers.length > 1 &&
6688
+ // we use item info instead of layer info for single layer items
6689
+ !getLayerIdFromUrl(url));
6690
+ };
6392
6691
  /**
6393
- * Create a new content with updated extent and derived properties like boundary
6394
- * @param content original content
6395
- * @param extent new extent
6396
- * @returns a new content with the updated extent and boundary
6397
- */
6398
- var setContentExtent = function (content, extent) {
6399
- // update content's item and extent
6400
- var item = __assign(__assign({}, content.item), { extent: extent });
6401
- var updated = __assign(__assign({}, content), { item: item, extent: extent });
6402
- // derive boundary from content properties
6403
- var boundary = getContentBoundary(updated);
6404
- return __assign(__assign({}, updated), { boundary: boundary });
6692
+ * The possible values for updateFrequency
6693
+ *
6694
+ * @enum {string}
6695
+ */
6696
+ exports.UpdateFrequency = void 0;
6697
+ (function (UpdateFrequency) {
6698
+ UpdateFrequency["Continual"] = "continual";
6699
+ UpdateFrequency["Daily"] = "daily";
6700
+ UpdateFrequency["Weekly"] = "weekly";
6701
+ UpdateFrequency["Fortnightly"] = "fortnightly";
6702
+ UpdateFrequency["Monthly"] = "monthly";
6703
+ UpdateFrequency["Quarterly"] = "quarterly";
6704
+ UpdateFrequency["Biannually"] = "biannually";
6705
+ UpdateFrequency["Annually"] = "annually";
6706
+ UpdateFrequency["AsNeeded"] = "as-needed";
6707
+ UpdateFrequency["Irregular"] = "irregular";
6708
+ UpdateFrequency["NotPlanned"] = "not-planned";
6709
+ UpdateFrequency["Unknown"] = "unknown";
6710
+ UpdateFrequency["Semimonthly"] = "semimonthly";
6711
+ })(exports.UpdateFrequency || (exports.UpdateFrequency = {}));
6712
+ var getUpdateFrequencyFromMetadata = function (metadata, identifier) {
6713
+ var updateFrequencyMap = {
6714
+ "001": exports.UpdateFrequency.Continual,
6715
+ "002": exports.UpdateFrequency.Daily,
6716
+ "003": exports.UpdateFrequency.Weekly,
6717
+ "004": exports.UpdateFrequency.Fortnightly,
6718
+ "005": exports.UpdateFrequency.Monthly,
6719
+ "006": exports.UpdateFrequency.Quarterly,
6720
+ "007": exports.UpdateFrequency.Biannually,
6721
+ "008": exports.UpdateFrequency.Annually,
6722
+ "009": exports.UpdateFrequency.AsNeeded,
6723
+ "010": exports.UpdateFrequency.Irregular,
6724
+ "011": exports.UpdateFrequency.NotPlanned,
6725
+ "012": exports.UpdateFrequency.Unknown,
6726
+ "013": exports.UpdateFrequency.Semimonthly,
6727
+ };
6728
+ return updateFrequencyMap[getValueFromMetadata(metadata, identifier || "updateFrequency")];
6405
6729
  };
6406
- var getContentBoundary = function (content) {
6407
- var _a;
6408
- var item = content.item;
6409
- var extent = item.extent;
6410
- var isValidItemExtent = isBBox(extent);
6411
- // user specified provenance is stored in item.properties
6412
- var provenance = ((_a = item.properties) === null || _a === void 0 ? void 0 : _a.boundary) ||
6413
- // but we default to item if the item has an extent
6414
- (isValidItemExtent ? "item" : undefined);
6415
- var geometry;
6416
- switch (provenance) {
6417
- case "item":
6418
- geometry = isValidItemExtent ? bBoxToPolygon(extent) : null;
6419
- break;
6420
- case "none":
6421
- geometry = null;
6422
- break;
6423
- // TODO: handle other provenances
6424
- }
6425
- // TODO: derive and return center
6730
+ var getDateInfoFromMetadata = function (metadata, identifier) {
6731
+ var metadataDateInfo = parseISODateString(getValueFromMetadata(metadata, identifier));
6732
+ return (metadataDateInfo && __assign(__assign({}, metadataDateInfo), { source: "metadata." + getMetadataPath(identifier) }));
6733
+ };
6734
+ var getLastEditDateInfo = function (content, layerOrServer) {
6735
+ var source = layerOrServer + ".editingInfo.lastEditDate";
6736
+ var lastEditDate = getProp(content, source);
6737
+ return (lastEditDate && {
6738
+ date: new Date(lastEditDate),
6739
+ source: source,
6740
+ // NOTE: this default was taken from _enrichDates
6741
+ precision: DatePrecision.Day,
6742
+ });
6743
+ };
6744
+ var getItemDateInfo = function (item, createdOrModified) {
6426
6745
  return {
6427
- provenance: provenance,
6428
- geometry: geometry,
6746
+ date: new Date(item[createdOrModified]),
6747
+ // NOTE: this was set to Day in _enrichDates()
6748
+ // but I wonder if it should be Time instead?
6749
+ precision: DatePrecision.Day,
6750
+ source: "item." + createdOrModified,
6429
6751
  };
6430
6752
  };
6431
- var MAX_SIZE = 5000000;
6432
- /**
6433
- * Returns whether or not an item is a proxied csv
6434
- *
6435
- * @param item
6436
- * @param requestOptions Hub Request Options (including whether we're in portal)
6437
- * @returns
6438
- */
6439
- var isProxiedCSV = function (item, requestOptions) {
6440
- return !requestOptions.isPortal &&
6441
- item.access === "public" &&
6442
- item.type === "CSV" &&
6443
- item.size <= MAX_SIZE;
6753
+ var getUpdatedDateInfo = function (item, options) {
6754
+ return (
6755
+ // prefer metadata revise date
6756
+ getDateInfoFromMetadata(options.metadata, "reviseDate") ||
6757
+ // then layer last edit date
6758
+ getLastEditDateInfo(options, "layer") ||
6759
+ // then server last edit date
6760
+ getLastEditDateInfo(options, "server") ||
6761
+ // fall back to item modified date
6762
+ getItemDateInfo(item, "modified"));
6444
6763
  };
6445
-
6446
- // private helper functions
6447
- function collectionToFamily(collection) {
6448
- var overrides = {
6449
- other: "content",
6450
- solution: "template",
6451
- };
6452
- return overrides[collection] || collection;
6453
- }
6454
- var cache = {};
6455
- // TODO: remove this at next breaking version
6764
+ var getPublishedDateInfo = function (item, metadata) {
6765
+ return (
6766
+ // prefer metadata publish date
6767
+ getDateInfoFromMetadata(metadata, "pubDate") ||
6768
+ // then metadata create date
6769
+ getDateInfoFromMetadata(metadata, "createDate") ||
6770
+ // fall back to item created date
6771
+ getItemDateInfo(item, "created"));
6772
+ };
6773
+ var getMetadataUpdatedDateInfo = function (item, metadata) {
6774
+ // prefer date from metadata
6775
+ return (getDateInfoFromMetadata(metadata, "metadataUpdatedDate") ||
6776
+ // default to when the item was last modified
6777
+ getItemDateInfo(item, "modified"));
6778
+ };
6779
+ // public API
6456
6780
  /**
6457
- * ```js
6458
- * import { getCategory } from "@esri/hub-common";
6459
- * //
6460
- * getCategory('Feature Layer')
6461
- * > 'dataset'
6462
- * ```
6463
- * **DEPRECATED: Use getCollection() instead**
6464
- * returns the Hub category for a given item type
6465
- * @param itemType The ArcGIS [item type](https://developers.arcgis.com/rest/users-groups-and-items/items-and-item-types.htm).
6466
- * @returns the category of a given item type.
6781
+ * DEPRECATED: Compute the content type icon based on the content type
6782
+ * @param content type
6783
+ * @returns content type icon
6467
6784
  */
6468
- function getCategory(itemType) {
6469
- if (itemType === void 0) { itemType = ""; }
6470
- /* tslint:disable no-console */
6471
- console.warn("DEPRECATED: Use getCollection() instead. getCategory will be removed at v10.0.0");
6472
- /* tslint:enable no-console */
6473
- var collection = getCollection(itemType);
6474
- // for backwards compatibility
6475
- return collection === "feedback" ? "app" : collection;
6476
- }
6477
- /**
6478
- * ```js
6479
- * import { getTypes } from "@esri/hub-common";
6480
- * //
6481
- * getTypes('site')
6482
- * > [ 'hub site application' ]
6483
- * ```
6484
- * To do.
6485
- * @param category The ArcGIS Hub category.
6486
- * @returns all the item types for the given category.
6487
- *
6785
+ var getContentTypeIcon = function (contentType) {
6786
+ var _a;
6787
+ var type = camelize(contentType || "");
6788
+ var iconMap = {
6789
+ appbuilderExtension: "file",
6790
+ appbuilderWidgetPackage: "widgets-source",
6791
+ application: "web",
6792
+ applicationConfiguration: "app-gear",
6793
+ arcgisProMap: "desktop",
6794
+ cadDrawing: "file-cad",
6795
+ cityEngineWebScene: "urban-model",
6796
+ codeAttachment: "file-code",
6797
+ codeSample: "file-code",
6798
+ colorSet: "palette",
6799
+ contentCategorySet: "label",
6800
+ csv: "file-csv",
6801
+ cSV: "file-csv",
6802
+ cSVCollection: "file-csv",
6803
+ dashboard: "dashboard",
6804
+ desktopApplication: "desktop",
6805
+ documentLink: "link",
6806
+ excaliburImageryProject: "file",
6807
+ explorerMap: "file",
6808
+ exportPackage: "file",
6809
+ featureCollection: "data",
6810
+ featureCollectionTemplate: "file",
6811
+ featureLayer: "data",
6812
+ featureService: "collection",
6813
+ fileGeodatabase: "data",
6814
+ form: "survey",
6815
+ geocodingService: "file",
6816
+ geodataService: "file",
6817
+ geometryService: "file",
6818
+ geopackage: "file",
6819
+ geoprocessingService: "file",
6820
+ globeLayer: "layers",
6821
+ globeService: "file",
6822
+ hubInitiative: "initiative",
6823
+ hubInitiativeTemplate: "initiative-template",
6824
+ hubPage: "browser",
6825
+ hubSiteApplication: "web",
6826
+ image: "file-image",
6827
+ imageService: "data",
6828
+ insightsModel: "file",
6829
+ insightsPage: "graph-moving-average",
6830
+ insightsTheme: "palette",
6831
+ insightsWorkbook: "graph-moving-average",
6832
+ iWorkPages: "file-text",
6833
+ iWorkKeynote: "presentation",
6834
+ iWorkNumbers: "file-report",
6835
+ kML: "data",
6836
+ kMLCollection: "data",
6837
+ layer: "layers",
6838
+ layerPackage: "layers",
6839
+ layerTemplate: "file",
6840
+ locatorPackage: "file",
6841
+ mapArea: "file",
6842
+ mapDocument: "map-contents",
6843
+ mapImageLayer: "collection",
6844
+ mapPackage: "file",
6845
+ mapService: "collection",
6846
+ microsoftExcel: "file-report",
6847
+ microsoftPowerpoint: "presentation",
6848
+ microsoftWord: "file-text",
6849
+ mission: "file",
6850
+ mobileMapPackage: "map-contents",
6851
+ nativeApplication: "mobile",
6852
+ nativeApplicationInstaller: "file",
6853
+ nativeApplicationTemplate: "file",
6854
+ mobileApplication: "mobile",
6855
+ networkAnalysisService: "file",
6856
+ notebook: "code",
6857
+ orientedImageryCatalog: "file",
6858
+ orthoMappingProject: "file",
6859
+ orthoMappingTemplate: "file",
6860
+ pDF: "file-pdf",
6861
+ quickCaptureProject: "mobile",
6862
+ rasterFunctionTemplate: "file",
6863
+ rasterLayer: "map",
6864
+ realTimeAnalytic: "file",
6865
+ relationalDatabaseConnection: "file",
6866
+ reportTemplate: "file",
6867
+ sceneLayer: "data",
6868
+ sceneService: "urban-model",
6869
+ serviceDefinition: "file",
6870
+ shapefile: "data",
6871
+ solution: "puzzle-piece",
6872
+ sqliteGeodatabase: "file",
6873
+ statisticalDataCollection: "file",
6874
+ storymap: "tour",
6875
+ storyMap: "tour",
6876
+ storymapTheme: "palette",
6877
+ symbolSet: "file",
6878
+ table: "table",
6879
+ urbanModel: "urban-model",
6880
+ vectorTilePackage: "file-shape",
6881
+ vectorTileService: "map",
6882
+ visioDocument: "conditional-rules",
6883
+ webExperience: "apps",
6884
+ webMap: "map",
6885
+ webMappingApplication: "apps",
6886
+ webScene: "urban-model",
6887
+ wfs: "map",
6888
+ wFS: "map",
6889
+ wMS: "map",
6890
+ wMTS: "map",
6891
+ workflowManagerService: "file",
6892
+ workforceProject: "list-check",
6893
+ };
6894
+ return (_a = iconMap[type]) !== null && _a !== void 0 ? _a : "file";
6895
+ };
6896
+ /**
6897
+ * get portal URLs (home, API, data, and thumbnail) for an item
6898
+ *
6899
+ * @param item Item
6900
+ * @param requestOptions Request options
6901
+ * @returns a hash with the portal URLs
6902
+ * @export
6488
6903
  */
6489
- function getTypes(category) {
6490
- if (category === void 0) { category = ""; }
6491
- return categories[category.toLowerCase()];
6492
- }
6904
+ var getPortalUrls = function (item, requestOptions) {
6905
+ var authentication = requestOptions.authentication;
6906
+ var token = authentication && authentication.token;
6907
+ // add properties that depend on portal
6908
+ var portalHome = getItemHomeUrl(item.id, requestOptions);
6909
+ // the URL of the item's Portal API end point
6910
+ var portalApi = getItemApiUrl(item, requestOptions, token);
6911
+ // the URL of the item's data API end point
6912
+ var portalData = getItemDataUrl(item, requestOptions, token);
6913
+ // the full URL of the thumbnail
6914
+ var thumbnail = getItemThumbnailUrl(item, requestOptions, {
6915
+ token: token,
6916
+ });
6917
+ return {
6918
+ portalHome: portalHome,
6919
+ portalApi: portalApi,
6920
+ portalData: portalData,
6921
+ thumbnail: thumbnail,
6922
+ };
6923
+ };
6924
+ /**
6925
+ * If an item is a proxied csv, returns the url for the proxying feature layer.
6926
+ * If the item is not a proxied csv, returns undefined.
6927
+ *
6928
+ * @param item
6929
+ * @param requestOptions Hub Request Options (including whether we're in portal)
6930
+ * @returns
6931
+ */
6932
+ var getProxyUrl = function (item, requestOptions) {
6933
+ var result;
6934
+ if (isProxiedCSV(item, requestOptions)) {
6935
+ result = getHubApiUrl(requestOptions) + "/datasets/" + item.id + "_0/FeatureServer/0";
6936
+ }
6937
+ return result;
6938
+ };
6939
+ /**
6940
+ * parse layer id from a service URL
6941
+ * @param {string} url
6942
+ * @returns {string} layer id
6943
+ */
6944
+ var getLayerIdFromUrl = function (url) {
6945
+ var endsWithNumberSegmentRegEx = /\/\d+$/;
6946
+ var matched = url && url.match(endsWithNumberSegmentRegEx);
6947
+ return matched && matched[0].slice(1);
6948
+ };
6949
+ /**
6950
+ * Case-insensitive check if the type is "Feature Service"
6951
+ * @param {string} type - item's type
6952
+ * @returns {boolean}
6953
+ */
6954
+ var isFeatureService = function (type) {
6955
+ return type && type.toLowerCase() === "feature service";
6956
+ };
6493
6957
  /**
6494
6958
  * ```js
6495
6959
  * import { normalizeItemType } from "@esri/hub-common";
@@ -6526,103 +6990,341 @@
6526
6990
  return ret;
6527
6991
  }
6528
6992
  /**
6529
- * ```js
6530
- * import { getTypeCategories } from "@esri/hub-common";
6531
- * //
6532
- * getTypeCategories(item)
6533
- * > [ 'Hub Site Application' ]
6993
+ * return the layerId if we can tell that item is a single layer service
6994
+ * @param {*} item from AGO
6995
+ * @returns {string} layer id
6996
+ */
6997
+ var getItemLayerId = function (item) {
6998
+ // try to parse it from the URL, but failing that we check for
6999
+ // the Singlelayer typeKeyword, which I think is set when you create the item in AGO
7000
+ // but have not verified that, nor that we should alway return '0' in that case
7001
+ return (getLayerIdFromUrl(item.url) ||
7002
+ (isFeatureService(item.type) &&
7003
+ item.typeKeywords &&
7004
+ includes(item.typeKeywords, "Singlelayer") &&
7005
+ "0"));
7006
+ };
7007
+ /**
7008
+ * given an item, get the id to use w/ the Hub API
7009
+ * @param item
7010
+ * @returns Hub API id (hubId)
7011
+ */
7012
+ var getItemHubId = function (item) {
7013
+ if (item.access !== "public") {
7014
+ // the hub only indexes public items
7015
+ return;
7016
+ }
7017
+ var id = item.id;
7018
+ var layerId = getItemLayerId(item);
7019
+ return layerId ? id + "_" + layerId : id;
7020
+ };
7021
+ /**
7022
+ * Splits item category strings at slashes and discards the "Categories" keyword
7023
+ *
7024
+ * ```
7025
+ * ["/Categories/Boundaries", "/Categories/Planning and cadastre/Property records", "/Categories/Structure"]
7026
+ * ```
7027
+ * Should end up being
7028
+ * ```
7029
+ * ["Boundaries", "Planning and cadastre", "Property records", "Structure"]
6534
7030
  * ```
6535
- * @param item Item object.
6536
- * @returns typeCategory of the input item.
6537
7031
  *
7032
+ * @param categories - an array of strings
7033
+ * @private
6538
7034
  */
6539
- function getTypeCategories(item) {
6540
- if (item === void 0) { item = {}; }
6541
- var type = normalizeItemType(item);
6542
- var category = getCategory(type);
6543
- if (category) {
6544
- // upper case first letter and return as element in array for backwards compatibility
6545
- var chars = Array.from(category);
6546
- chars[0] = chars[0].toUpperCase();
6547
- return [chars.join("")];
6548
- }
6549
- else {
6550
- return ["Other"];
6551
- }
7035
+ function parseItemCategories(categories) {
7036
+ if (!categories)
7037
+ return categories;
7038
+ var exclude = ["categories", ""];
7039
+ var parsed = categories.map(function (cat) { return cat.split("/"); });
7040
+ var flattened = parsed.reduce(function (acc, arr, _) { return __spreadArrays(acc, arr); }, []);
7041
+ return flattened.filter(function (cat) { return !includes(exclude, cat.toLowerCase()); });
6552
7042
  }
7043
+ /**
7044
+ * Compose a new content object out of an item, enrichments, and context
7045
+ * @param item
7046
+ * @param options any enrichments, current state (selected layerId), or context (requestOptions)
7047
+ * @returns new content object
7048
+ */
7049
+ var composeContent = function (item, options) {
7050
+ // extract enrichments and context out of the options
7051
+ var _a = options || {}, slug = _a.slug, requestOptions = _a.requestOptions, data = _a.data, metadata = _a.metadata, groupIds = _a.groupIds, ownerUser = _a.ownerUser, org = _a.org, errors = _a.errors, server = _a.server, layers = _a.layers, recordCount = _a.recordCount, boundary = _a.boundary, statistics = _a.statistics;
7052
+ // set common variables that we will use in the derived properties below
7053
+ // if item refers to a layer we always want to use that layer id
7054
+ // otherwise use the layer id that was passed in (if any)
7055
+ var _layerIdFromUrl = getLayerIdFromUrl(item.url);
7056
+ var layerId = _layerIdFromUrl
7057
+ ? parseInt(_layerIdFromUrl, 10)
7058
+ : options === null || options === void 0 ? void 0 : options.layerId;
7059
+ var layer = layers &&
7060
+ (!isNil(layerId)
7061
+ ? // find the explicitly set layer id
7062
+ layers.find(function (_layer) { return _layer.id === layerId; })
7063
+ : // for feature servers with a single layer always show the layer
7064
+ isFeatureService(item.type) && getOnlyQueryLayer(layers));
7065
+ // NOTE: we only set hubId for public items in online
7066
+ var _canUseHubApi = !isPortal(requestOptions) && item.access === "public";
7067
+ var hubId = _canUseHubApi
7068
+ ? layer
7069
+ ? item.id + "_" + layer.id
7070
+ : getItemHubId(item)
7071
+ : undefined;
7072
+ var identifier = slug || hubId || item.id;
7073
+ // whether or not we should show layer info for name, description, etc
7074
+ var _shouldUseLayerInfo = shouldUseLayerInfo(layer, layers, item.url);
7075
+ var name = _shouldUseLayerInfo ? layer.name : item.title;
7076
+ var _layerDescription = _shouldUseLayerInfo && layer.description;
7077
+ // so much depends on type
7078
+ var type = layer
7079
+ ? // use layer type (Feature Layer, Table, etc) for layer content
7080
+ layer.type
7081
+ : // otherwise use the normalized item type
7082
+ normalizeItemType(item);
7083
+ // all the urls
7084
+ var urls = __assign({ relative: getHubRelativeUrl(type, identifier, item.typeKeywords) }, (requestOptions && getPortalUrls(item, requestOptions)));
7085
+ var _proxyUrl = getProxyUrl(item, requestOptions);
7086
+ // NOTE: I'd rather not compute these date values up front,
7087
+ // but they are used by several getters below, so we do it here only once
7088
+ var _updatedDateInfo = getUpdatedDateInfo(item, {
7089
+ metadata: metadata,
7090
+ layer: layer,
7091
+ server: server,
7092
+ });
7093
+ var _publishedDateInfo = getPublishedDateInfo(item, metadata);
7094
+ var _metadataUpdatedDateInfo = getMetadataUpdatedDateInfo(item, metadata);
7095
+ // return all of the above composed into a content object
7096
+ return __assign(__assign({
7097
+ // a reference to underlying item
7098
+ item: item }, item), {
7099
+ // item enrichments
7100
+ slug: slug,
7101
+ data: data,
7102
+ metadata: metadata,
7103
+ groupIds: groupIds,
7104
+ ownerUser: ownerUser,
7105
+ org: org, errors: errors || [],
7106
+ // server enrichments
7107
+ server: server,
7108
+ layers: layers,
7109
+ recordCount: recordCount,
7110
+ // enrichments from the Hub API (boundary is below)
7111
+ statistics: statistics,
7112
+ // derived properties
7113
+ // NOTE: in the getters below you can **not** use `this`
7114
+ // these are not meant to provide live updating computed props
7115
+ // their purpose is to avoid computing all these values above
7116
+ // especially where we want to defer computation of less used props
7117
+ hubId: hubId,
7118
+ identifier: identifier, get isProxied() {
7119
+ return !!_proxyUrl;
7120
+ }, layer: layer,
7121
+ name: name, get title() {
7122
+ return name;
7123
+ },
7124
+ get description() {
7125
+ return _layerDescription || item.description;
7126
+ }, type: type, get family() {
7127
+ return getFamily(type);
7128
+ }, get url() {
7129
+ return _proxyUrl
7130
+ ? _proxyUrl
7131
+ : _shouldUseLayerInfo
7132
+ ? parseServiceUrl(item.url) + "/" + layer.id
7133
+ : item.url;
7134
+ }, get categories() {
7135
+ return parseItemCategories(item.categories);
7136
+ },
7137
+ get actionLinks() {
7138
+ return item.properties && item.properties.links;
7139
+ },
7140
+ get hubActions() {
7141
+ return item.properties && item.properties.actions;
7142
+ },
7143
+ get isDownloadable() {
7144
+ return isDownloadable(item);
7145
+ },
7146
+ get structuredLicense() {
7147
+ return getStructuredLicense(item.licenseInfo);
7148
+ },
7149
+ get permissions() {
7150
+ return {
7151
+ visibility: item.access,
7152
+ control: item.itemControl || "view",
7153
+ };
7154
+ },
7155
+ get boundary() {
7156
+ // TODO: need to be able to handle automatic w/ additional enrichment
7157
+ // that could for example fetch the concave hull from the Hub API or resources
7158
+ return boundary || getContentBoundary(item);
7159
+ },
7160
+ get summary() {
7161
+ return _layerDescription
7162
+ ? _layerDescription
7163
+ : // TODO: this should use the logic for the Hub API's searchDescription
7164
+ // see: https://github.com/ArcGIS/hub-indexer/blob/b352cfded8221a967ac80447879d493db6476d7a/packages/duke/compose/dataset.js#L238-L250
7165
+ // TODO: can we strip HTML from description, and do we need to trim it to a X chars?
7166
+ item.snippet || item.description;
7167
+ }, urls: urls, get portalHomeUrl() {
7168
+ return urls.portalHome;
7169
+ },
7170
+ get portalDataUrl() {
7171
+ return urls.portalData;
7172
+ },
7173
+ get portalApiUrl() {
7174
+ return urls.portalApi;
7175
+ },
7176
+ get thumbnailUrl() {
7177
+ return urls.thumbnail;
7178
+ },
7179
+ /** The date the item was created */
7180
+ get createdDate() {
7181
+ return new Date(item.created);
7182
+ }, createdDateSource: "item.created", get updatedDate() {
7183
+ return _updatedDateInfo.date;
7184
+ },
7185
+ get updatedDateSource() {
7186
+ return _updatedDateInfo.source;
7187
+ },
7188
+ get updatedDatePrecision() {
7189
+ return _updatedDateInfo.precision;
7190
+ },
7191
+ get modified() {
7192
+ return _updatedDateInfo.date.getTime();
7193
+ },
7194
+ get publishedDate() {
7195
+ return _publishedDateInfo.date;
7196
+ },
7197
+ get publishedDateSource() {
7198
+ return _publishedDateInfo.source;
7199
+ },
7200
+ get publishedDatePrecision() {
7201
+ return _publishedDateInfo.precision;
7202
+ },
7203
+ get metadataUpdatedDate() {
7204
+ return _metadataUpdatedDateInfo.date;
7205
+ },
7206
+ get metadataUpdatedDateSource() {
7207
+ return _metadataUpdatedDateInfo.source;
7208
+ },
7209
+ get metadataUpdatedDatePrecision() {
7210
+ return _metadataUpdatedDateInfo.precision;
7211
+ },
7212
+ get updateFrequency() {
7213
+ return getUpdateFrequencyFromMetadata(metadata);
7214
+ },
7215
+ get metadataUpdateFrequency() {
7216
+ return getUpdateFrequencyFromMetadata(metadata, "metadataUpdateFrequency");
7217
+ },
7218
+ // TODO: add the publisher logic outlined here:
7219
+ // https://devtopia.esri.com/dc/hub/issues/2932#issuecomment-3276309
7220
+ get publisher() {
7221
+ return {
7222
+ name: item.owner,
7223
+ username: item.owner,
7224
+ };
7225
+ },
7226
+ // TODO: is metrics in use?
7227
+ get metrics() {
7228
+ return item.properties && item.properties.metrics;
7229
+ },
7230
+ get spatialReference() {
7231
+ // NOTE: I had to add || null just so packages/content/test/portal.test.ts would pass
7232
+ // we can remove that when that package is deprecated
7233
+ return (getItemSpatialReference(item) ||
7234
+ getServerSpatialReference(server, layer) ||
7235
+ null);
7236
+ },
7237
+ get orgId() {
7238
+ // NOTE: it's undocumented, but the portal API will return orgId for items... sometimes
7239
+ return org ? org.id : item.orgId;
7240
+ },
7241
+ // deprecated properties
7242
+ // TODO: should we add these in legacy wrappers
7243
+ // like itemToContent or datasetToContent instead?
7244
+ get contentTypeIcon() {
7245
+ /* tslint:disable no-console */
7246
+ console.warn(
7247
+ /* tslint:enable no-console */
7248
+ "DEPRECATED: it is now the responsibility of the consuming package to determine the icon");
7249
+ return getContentTypeIcon(type);
7250
+ },
7251
+ get license() {
7252
+ /* tslint:disable no-console */
7253
+ console.warn("DEPRECATED: use structuredLicense instead");
7254
+ /* tslint:enable no-console */
7255
+ return { name: "Custom License", description: item.accessInformation };
7256
+ },
7257
+ get hubType() {
7258
+ /* tslint:disable no-console */
7259
+ console.warn("DEPRECATED: use family instead");
7260
+ /* tslint:enable no-console */
7261
+ return getFamily(type);
7262
+ } });
7263
+ };
7264
+
7265
+ // TODO: remove this at next breaking version
6553
7266
  /**
6554
7267
  * ```js
6555
- * import { getCollection } from "@esri/hub-common";
7268
+ * import { getCategory } from "@esri/hub-common";
6556
7269
  * //
6557
- * getCollection('Feature Layer')
7270
+ * getCategory('Feature Layer')
6558
7271
  * > 'dataset'
6559
7272
  * ```
6560
- * Get the Hub collection for a given item type
7273
+ * **DEPRECATED: Use getCollection() instead**
7274
+ * returns the Hub category for a given item type
6561
7275
  * @param itemType The ArcGIS [item type](https://developers.arcgis.com/rest/users-groups-and-items/items-and-item-types.htm).
6562
- * @returns the Hub collection of a given item type.
7276
+ * @returns the category of a given item type.
6563
7277
  */
6564
- function getCollection(itemType) {
7278
+ function getCategory(itemType) {
6565
7279
  if (itemType === void 0) { itemType = ""; }
6566
- if (cache[itemType]) {
6567
- return cache[itemType];
6568
- }
6569
- for (var _i = 0, _a = Object.keys(collections); _i < _a.length; _i++) {
6570
- var collection = _a[_i];
6571
- for (var _b = 0, _c = collections[collection]; _b < _c.length; _b++) {
6572
- var type = _c[_b];
6573
- if (itemType.toLowerCase() === type.toLowerCase()) {
6574
- cache[itemType] = collection;
6575
- return collection;
6576
- }
6577
- }
6578
- }
7280
+ /* tslint:disable no-console */
7281
+ console.warn("DEPRECATED: Use getCollection() instead. getCategory will be removed at v10.0.0");
7282
+ /* tslint:enable no-console */
7283
+ var collection = getCollection(itemType);
7284
+ // for backwards compatibility
7285
+ return collection === "feedback" ? "app" : collection;
6579
7286
  }
6580
7287
  /**
6581
- * Case-insensitive check if the type is "Feature Service"
6582
- * @param {string} type - item's type
6583
- * @returns {boolean}
6584
- */
6585
- var isFeatureService = function (type) {
6586
- return type && type.toLowerCase() === "feature service";
6587
- };
6588
- /**
6589
- * parse layer id from a service URL
6590
- * @param {string} url
6591
- * @returns {string} layer id
6592
- */
6593
- var getLayerIdFromUrl = function (url) {
6594
- var endsWithNumberSegmentRegEx = /\/\d+$/;
6595
- var matched = url && url.match(endsWithNumberSegmentRegEx);
6596
- return matched && matched[0].slice(1);
6597
- };
6598
- /**
6599
- * return the layerId if we can tell that item is a single layer service
6600
- * @param {*} item from AGO
6601
- * @returns {string} layer id
6602
- */
6603
- var getItemLayerId = function (item) {
6604
- // try to parse it from the URL, but failing that we check for
6605
- // the Singlelayer typeKeyword, which I think is set when you create the item in AGO
6606
- // but have not verified that, nor that we should alway return '0' in that case
6607
- return (getLayerIdFromUrl(item.url) ||
6608
- (isFeatureService(item.type) &&
6609
- includes(item.typeKeywords, "Singlelayer") &&
6610
- "0"));
6611
- };
7288
+ * ```js
7289
+ * import { getTypes } from "@esri/hub-common";
7290
+ * //
7291
+ * getTypes('site')
7292
+ * > [ 'hub site application' ]
7293
+ * ```
7294
+ * To do.
7295
+ * @param category The ArcGIS Hub category.
7296
+ * @returns all the item types for the given category.
7297
+ *
7298
+ */
7299
+ function getTypes(category) {
7300
+ if (category === void 0) { category = ""; }
7301
+ return categories[category.toLowerCase()];
7302
+ }
6612
7303
  /**
6613
- * given an item, get the id to use w/ the Hub API
6614
- * @param item
6615
- * @returns Hub API id (hubId)
7304
+ * ```js
7305
+ * import { getTypeCategories } from "@esri/hub-common";
7306
+ * //
7307
+ * getTypeCategories(item)
7308
+ * > [ 'Hub Site Application' ]
7309
+ * ```
7310
+ * @param item Item object.
7311
+ * @returns typeCategory of the input item.
7312
+ *
6616
7313
  */
6617
- var getItemHubId = function (item) {
6618
- if (item.access !== "public") {
6619
- // the hub only indexes public items
6620
- return;
7314
+ function getTypeCategories(item) {
7315
+ if (item === void 0) { item = {}; }
7316
+ var type = normalizeItemType(item);
7317
+ var category = getCategory(type);
7318
+ if (category) {
7319
+ // upper case first letter and return as element in array for backwards compatibility
7320
+ var chars = Array.from(category);
7321
+ chars[0] = chars[0].toUpperCase();
7322
+ return [chars.join("")];
6621
7323
  }
6622
- var id = item.id;
6623
- var layerId = getItemLayerId(item);
6624
- return layerId ? id + "_" + layerId : id;
6625
- };
7324
+ else {
7325
+ return ["Other"];
7326
+ }
7327
+ }
6626
7328
  /**
6627
7329
  * ```js
6628
7330
  * import { getContentIdentifier } from "@esri/hub-common";
@@ -6652,7 +7354,7 @@
6652
7354
  // site data instead. Because this one is the original one that was used
6653
7355
  // to create the page url (not mutable once created) and the slug (below)
6654
7356
  // generated by the hub-indexer could simply change with page name.
6655
- if (isPageContent(content)) {
7357
+ if (isPageType(content.type)) {
6656
7358
  // check if the page is linked to the current site
6657
7359
  var pages = getProp(site, "data.values.pages") || [];
6658
7360
  // if so, return the page slug otherwise the page id
@@ -6736,60 +7438,6 @@
6736
7438
  return slug;
6737
7439
  }
6738
7440
  }
6739
- /**
6740
- * Splits item category strings at slashes and discards the "Categories" keyword
6741
- *
6742
- * ```
6743
- * ["/Categories/Boundaries", "/Categories/Planning and cadastre/Property records", "/Categories/Structure"]
6744
- * ```
6745
- * Should end up being
6746
- * ```
6747
- * ["Boundaries", "Planning and cadastre", "Property records", "Structure"]
6748
- * ```
6749
- *
6750
- * @param categories - an array of strings
6751
- * @private
6752
- */
6753
- function parseItemCategories(categories) {
6754
- if (!categories)
6755
- return categories;
6756
- var exclude = ["categories", ""];
6757
- var parsed = categories.map(function (cat) { return cat.split("/"); });
6758
- var flattened = parsed.reduce(function (acc, arr, _) { return __spreadArrays(acc, arr); }, []);
6759
- return flattened.filter(function (cat) { return !includes(exclude, cat.toLowerCase()); });
6760
- }
6761
- /**
6762
- * return the Hub family given an item's type
6763
- * @param type item type
6764
- * @returns Hub family
6765
- */
6766
- function getFamily(type) {
6767
- var family;
6768
- // override default behavior for the rows that are highlighted in yellow here:
6769
- // https://esriis.sharepoint.com/:x:/r/sites/ArcGISHub/_layouts/15/Doc.aspx?sourcedoc=%7BADA1C9DC-4F6C-4DE4-92C6-693EF9571CFA%7D&file=Hub%20Routes.xlsx&nav=MTBfe0VENEREQzI4LUZFMDctNEI0Ri04NjcyLThCQUE2MTA0MEZGRn1fezIwMTIwMEJFLTA4MEQtNEExRC05QzA4LTE5MTAzOUQwMEE1RH0&action=default&mobileredirect=true&cid=df1c874b-c367-4cea-bc13-7bebfad3f2ac
6770
- switch ((type || "").toLowerCase()) {
6771
- case "image service":
6772
- family = "dataset";
6773
- break;
6774
- case "feature service":
6775
- case "raster layer":
6776
- // TODO: check if feature service has > 1 layer first?
6777
- family = "map";
6778
- break;
6779
- case "microsoft excel":
6780
- family = "document";
6781
- break;
6782
- case "cad drawing":
6783
- case "feature collection template":
6784
- case "report template":
6785
- family = "content";
6786
- break;
6787
- default:
6788
- // by default derive from collection
6789
- family = collectionToFamily(getCollection(type));
6790
- }
6791
- return family;
6792
- }
6793
7441
  /**
6794
7442
  * DEPRECATED: Use getFamily() instead.
6795
7443
  *
@@ -6816,51 +7464,7 @@
6816
7464
  * @export
6817
7465
  */
6818
7466
  function itemToContent(item) {
6819
- var createdDate = new Date(item.created);
6820
- var createdDateSource = "item.created";
6821
- var properties = item.properties;
6822
- var content = Object.assign({}, item, {
6823
- identifier: item.id,
6824
- // no server errors when fetching the item directly
6825
- errors: [],
6826
- // store a reference to the item
6827
- item: item,
6828
- // NOTE: this will overwrite any existing item.name, which is
6829
- // The file name of the item for file types. Read-only.
6830
- // presumably there to use as the default file name when downloading
6831
- // we don't store item.name in the Hub API and we use name for title
6832
- name: item.title,
6833
- // TODO: hubType is no longer used, remove it at next breaking change
6834
- hubType: getItemHubType(item),
6835
- categories: parseItemCategories(item.categories),
6836
- itemCategories: item.categories,
6837
- // can we strip HTML from description, and do we need to trim it to a X chars?
6838
- summary: item.snippet || item.description,
6839
- publisher: {
6840
- name: item.owner,
6841
- username: item.owner,
6842
- },
6843
- permissions: {
6844
- visibility: item.access,
6845
- control: item.itemControl || "view",
6846
- },
6847
- // Hub app configuration metadata from item properties
6848
- actionLinks: properties && properties.links,
6849
- hubActions: properties && properties.actions,
6850
- metrics: properties && properties.metrics,
6851
- isDownloadable: isDownloadable(item),
6852
- // default boundary from item.extent
6853
- license: { name: "Custom License", description: item.accessInformation },
6854
- // dates and sources we will enrich these later...
6855
- createdDate: createdDate,
6856
- createdDateSource: createdDateSource,
6857
- publishedDate: createdDate,
6858
- publishedDateSource: createdDateSource,
6859
- updatedDate: new Date(item.modified),
6860
- updatedDateSource: "item.modified",
6861
- structuredLicense: getStructuredLicense(item.licenseInfo),
6862
- });
6863
- return setContentExtent(setContentType(content, item.type), item.extent);
7467
+ return composeContent(item);
6864
7468
  }
6865
7469
  /**
6866
7470
  * Convert a Hub API dataset resource to Hub Content
@@ -6872,76 +7476,43 @@
6872
7476
  function datasetToContent(dataset) {
6873
7477
  // extract item from dataset, create content from the item
6874
7478
  var item = datasetToItem(dataset);
6875
- var content = itemToContent(item);
6876
- // We remove these because the indexer doesn't actually
6877
- // preserve the original item categories so this attribute is invalid
6878
- delete content.itemCategories;
6879
- // overwrite or add enrichments from Hub API
6880
- var hubId = dataset.id, attributes = dataset.attributes;
6881
- var
6882
- // common enrichments
6883
- errors = attributes.errors, boundary = attributes.boundary, extent = attributes.extent, metadata = attributes.metadata, modified = attributes.modified, modifiedProvenance = attributes.modifiedProvenance, slug = attributes.slug, searchDescription = attributes.searchDescription, groupIds = attributes.groupIds,
7479
+ // extract enrichments from attributes
7480
+ var _a = dataset.attributes,
7481
+ // item enrichments
7482
+ errors = _a.errors, boundary = _a.boundary, metadata = _a.metadata, slug = _a.slug, groupIds = _a.groupIds, orgId = _a.orgId, orgName = _a.orgName, organization = _a.organization, orgExtent = _a.orgExtent,
6884
7483
  // map and feature server enrichments
6885
- server = attributes.server, layers = attributes.layers,
6886
- // NOTE: the Hub API also returns the following server properties
6887
- // but we should be able to get them from the above server object
6888
- // currentVersion, capabilities, tileInfo, serviceSpatialReference
6889
- // maxRecordCount, supportedQueryFormats, etc
6890
- // feature and raster layer enrichments
6891
- layer = attributes.layer, recordCount = attributes.recordCount, statistics = attributes.statistics,
6892
- // NOTE: the Hub API also returns the following layer properties
6893
- // but we should be able to get them from the above layer object
6894
- // supportedQueryFormats, supportsAdvancedQueries, advancedQueryCapabilities, useStandardizedQueries
6895
- // geometryType, objectIdField, displayField, fields,
6896
- // org properties?
6897
- orgId = attributes.orgId, orgName = attributes.orgName, organization = attributes.organization, orgExtent = attributes.orgExtent,
6898
- // NOTE: for layers and tables the Hub API returns the layer type
6899
- // ("Feature Layer", "Table", "Raster Layer") instead of the item type
6900
- type = attributes.type;
6901
- // NOTE: we could throw or return if there are errors
6902
- // to prevent type errors trying to read properties below
6903
- content.errors = errors;
6904
- // common enrichments
6905
- content.boundary = boundary;
6906
- if (!isBBox(item.extent) && extent && isBBox(extent.coordinates)) {
6907
- // we fall back to the extent derived by the API
6908
- // which prefers layer or service extents and ultimately
6909
- // falls back to the org's extent
6910
- content.extent = extent.coordinates;
6911
- }
6912
- // setting this to null signals to enrichMetadata to skip this
6913
- content.metadata = metadata || null;
6914
- if (content.modified !== modified) {
6915
- // capture the enriched modified date
6916
- // NOTE: the item modified date is still available on content.item.modified
6917
- content.modified = modified;
6918
- content.updatedDate = new Date(modified);
6919
- content.updatedDateSource = modifiedProvenance;
6920
- }
6921
- content.slug = slug;
7484
+ server = _a.server, layers = _a.layers, layer = _a.layer, recordCount = _a.recordCount, statistics = _a.statistics,
7485
+ // additional attributes needed
7486
+ searchDescription = _a.searchDescription;
7487
+ // get the layerId from the layer
7488
+ var layerId = layer && layer.id;
7489
+ // re-assemble the org as an enrichment
7490
+ var org = orgId && {
7491
+ id: orgId,
7492
+ name: orgName || organization,
7493
+ extent: orgExtent,
7494
+ };
7495
+ // compose a content out of the above
7496
+ var content = composeContent(item, {
7497
+ layerId: layerId,
7498
+ slug: slug,
7499
+ errors: errors,
7500
+ // setting this to null signals to enrichMetadata to skip this
7501
+ metadata: metadata || null,
7502
+ groupIds: groupIds,
7503
+ org: org,
7504
+ server: server,
7505
+ layers: layers,
7506
+ recordCount: recordCount,
7507
+ boundary: boundary,
7508
+ statistics: statistics,
7509
+ });
7510
+ // TODO: need to add searchDescription logic to composeContent()
6922
7511
  if (searchDescription) {
6923
7512
  // overwrite default summary (from snippet) w/ search description
6924
7513
  content.summary = searchDescription;
6925
7514
  }
6926
- content.groupIds = groupIds;
6927
- // server enrichments
6928
- content.server = server;
6929
- content.layers = layers;
6930
- // layer enrichments
6931
- content.layer = layer;
6932
- content.recordCount = recordCount;
6933
- content.statistics = statistics;
6934
- // org enrichments
6935
- if (orgId) {
6936
- content.org = {
6937
- id: orgId,
6938
- name: orgName || organization,
6939
- extent: orgExtent,
6940
- };
6941
- }
6942
- // return a content with updated hubId and type
6943
- // along w/ related properties like identifier, family, etc
6944
- return setContentType(setContentHubId(content, hubId), type);
7515
+ return content;
6945
7516
  }
6946
7517
  /**
6947
7518
  * Convert a Hub API dataset resource to a portal item
@@ -7027,166 +7598,50 @@
7027
7598
  culture: culture,
7028
7599
  url: url,
7029
7600
  access: access,
7030
- size: size,
7031
- protected: isProtected,
7032
- proxyFilter: proxyFilter,
7033
- properties: properties,
7034
- appCategories: appCategories,
7035
- industries: industries,
7036
- languages: languages,
7037
- largeThumbnail: largeThumbnail,
7038
- banner: banner,
7039
- screenshots: screenshots,
7040
- listed: listed,
7041
- ownerFolder: ownerFolder,
7042
- commentsEnabled: commentsEnabled,
7043
- numComments: numComments,
7044
- numRatings: numRatings,
7045
- avgRating: avgRating,
7046
- numViews: numViews,
7047
- itemControl: itemControl,
7048
- scoreCompleteness: scoreCompleteness,
7049
- };
7050
- }
7051
- /**
7052
- * returns a new content that has the specified type and
7053
- * and updated related properties like, family, etc
7054
- * @param content orignal content
7055
- * @param type new type
7056
- * @returns new content
7057
- */
7058
- var setContentType = function (content, type) {
7059
- // get family and normalized type based on new type
7060
- var normalizedType = normalizeItemType(__assign(__assign({}, content.item), { type: type }));
7061
- var family = getFamily(normalizedType);
7062
- var contentTypeIcon = getContentTypeIcon(normalizedType);
7063
- var contentTypeLabel = getContentTypeLabel(normalizedType, content.isProxied);
7064
- var updated = __assign(__assign({}, content), { type: normalizedType, family: family,
7065
- // TODO: remove this at next breaking change now that it has been deprecated
7066
- normalizedType: normalizedType,
7067
- contentTypeIcon: contentTypeIcon,
7068
- contentTypeLabel: contentTypeLabel });
7069
- // update the relative URL to the content
7070
- // which is based on type and family
7071
- return appendContentUrls(updated, {
7072
- relative: getContentRelativeUrl(updated),
7073
- });
7074
- };
7075
- /**
7076
- * Compute the content type icon based on the content type
7077
- * @param content type
7078
- * @returns content type icon
7079
- */
7080
- var getContentTypeIcon = function (contentType) {
7081
- var _a;
7082
- var type = camelize(contentType || "");
7083
- var iconMap = {
7084
- appbuilderExtension: "file",
7085
- appbuilderWidgetPackage: "widgets-source",
7086
- application: "web",
7087
- applicationConfiguration: "app-gear",
7088
- arcgisProMap: "desktop",
7089
- cadDrawing: "file-cad",
7090
- cityEngineWebScene: "urban-model",
7091
- codeAttachment: "file-code",
7092
- codeSample: "file-code",
7093
- colorSet: "palette",
7094
- contentCategorySet: "label",
7095
- csv: "file-csv",
7096
- cSV: "file-csv",
7097
- cSVCollection: "file-csv",
7098
- dashboard: "dashboard",
7099
- desktopApplication: "desktop",
7100
- documentLink: "link",
7101
- excaliburImageryProject: "file",
7102
- explorerMap: "file",
7103
- exportPackage: "file",
7104
- featureCollection: "data",
7105
- featureCollectionTemplate: "file",
7106
- featureLayer: "data",
7107
- featureService: "collection",
7108
- fileGeodatabase: "data",
7109
- form: "survey",
7110
- geocodingService: "file",
7111
- geodataService: "file",
7112
- geometryService: "file",
7113
- geopackage: "file",
7114
- geoprocessingService: "file",
7115
- globeLayer: "layers",
7116
- globeService: "file",
7117
- hubInitiative: "initiative",
7118
- hubInitiativeTemplate: "initiative-template",
7119
- hubPage: "browser",
7120
- hubSiteApplication: "web",
7121
- image: "file-image",
7122
- imageService: "data",
7123
- insightsModel: "file",
7124
- insightsPage: "graph-moving-average",
7125
- insightsTheme: "palette",
7126
- insightsWorkbook: "graph-moving-average",
7127
- iWorkPages: "file-text",
7128
- iWorkKeynote: "presentation",
7129
- iWorkNumbers: "file-report",
7130
- kML: "data",
7131
- kMLCollection: "data",
7132
- layer: "layers",
7133
- layerPackage: "layers",
7134
- layerTemplate: "file",
7135
- locatorPackage: "file",
7136
- mapArea: "file",
7137
- mapDocument: "map-contents",
7138
- mapImageLayer: "collection",
7139
- mapPackage: "file",
7140
- mapService: "collection",
7141
- microsoftExcel: "file-report",
7142
- microsoftPowerpoint: "presentation",
7143
- microsoftWord: "file-text",
7144
- mission: "file",
7145
- mobileMapPackage: "map-contents",
7146
- nativeApplication: "mobile",
7147
- nativeApplicationInstaller: "file",
7148
- nativeApplicationTemplate: "file",
7149
- mobileApplication: "mobile",
7150
- networkAnalysisService: "file",
7151
- notebook: "code",
7152
- orientedImageryCatalog: "file",
7153
- orthoMappingProject: "file",
7154
- orthoMappingTemplate: "file",
7155
- pDF: "file-pdf",
7156
- quickCaptureProject: "mobile",
7157
- rasterFunctionTemplate: "file",
7158
- rasterLayer: "map",
7159
- realTimeAnalytic: "file",
7160
- relationalDatabaseConnection: "file",
7161
- reportTemplate: "file",
7162
- sceneLayer: "data",
7163
- sceneService: "urban-model",
7164
- serviceDefinition: "file",
7165
- shapefile: "data",
7166
- solution: "puzzle-piece",
7167
- sqliteGeodatabase: "file",
7168
- statisticalDataCollection: "file",
7169
- storymap: "tour",
7170
- storyMap: "tour",
7171
- storymapTheme: "palette",
7172
- symbolSet: "file",
7173
- table: "table",
7174
- urbanModel: "urban-model",
7175
- vectorTilePackage: "file-shape",
7176
- vectorTileService: "map",
7177
- visioDocument: "conditional-rules",
7178
- webExperience: "apps",
7179
- webMap: "map",
7180
- webMappingApplication: "apps",
7181
- webScene: "urban-model",
7182
- wfs: "map",
7183
- wFS: "map",
7184
- wMS: "map",
7185
- wMTS: "map",
7186
- workflowManagerService: "file",
7187
- workforceProject: "list-check",
7601
+ size: size,
7602
+ protected: isProtected,
7603
+ proxyFilter: proxyFilter,
7604
+ properties: properties,
7605
+ appCategories: appCategories,
7606
+ industries: industries,
7607
+ languages: languages,
7608
+ largeThumbnail: largeThumbnail,
7609
+ banner: banner,
7610
+ screenshots: screenshots,
7611
+ listed: listed,
7612
+ ownerFolder: ownerFolder,
7613
+ commentsEnabled: commentsEnabled,
7614
+ numComments: numComments,
7615
+ numRatings: numRatings,
7616
+ avgRating: avgRating,
7617
+ numViews: numViews,
7618
+ itemControl: itemControl,
7619
+ scoreCompleteness: scoreCompleteness,
7188
7620
  };
7189
- return (_a = iconMap[type]) !== null && _a !== void 0 ? _a : "file";
7621
+ }
7622
+ /**
7623
+ * returns a new content that has the specified type and
7624
+ * and updated related properties like, family, etc
7625
+ * @param content orignal content
7626
+ * @param type new type
7627
+ * @returns new content
7628
+ */
7629
+ var setContentType = function (content, type) {
7630
+ // get family and normalized type based on new type
7631
+ var normalizedType = normalizeItemType(__assign(__assign({}, content.item), { type: type }));
7632
+ var family = getFamily(normalizedType);
7633
+ var contentTypeIcon = getContentTypeIcon(normalizedType);
7634
+ var contentTypeLabel = getContentTypeLabel(normalizedType, content.isProxied);
7635
+ var updated = __assign(__assign({}, content), { type: normalizedType, family: family,
7636
+ // TODO: remove this at next breaking change now that it has been deprecated
7637
+ normalizedType: normalizedType,
7638
+ contentTypeIcon: contentTypeIcon,
7639
+ contentTypeLabel: contentTypeLabel });
7640
+ // update the relative URL to the content
7641
+ // which is based on type and family
7642
+ return appendContentUrls(updated, {
7643
+ relative: getContentRelativeUrl(updated),
7644
+ });
7190
7645
  };
7191
7646
  /**
7192
7647
  * Compute the content type label
@@ -7252,78 +7707,7 @@
7252
7707
  return __assign(__assign({}, content), { urls: urls });
7253
7708
  };
7254
7709
  var getContentRelativeUrl = function (content, siteIdentifier) {
7255
- var family = content.family;
7256
- // prefer site specific identifier if passed in
7257
- var identifier = siteIdentifier || content.identifier;
7258
- // solution types have their own logic
7259
- var contentUrl = getSolutionUrl(content);
7260
- if (!contentUrl) {
7261
- var pluralizedFamilies = [
7262
- "app",
7263
- "dataset",
7264
- "document",
7265
- "map",
7266
- "template",
7267
- ];
7268
- // default to the catchall content route
7269
- var path = "/content";
7270
- if (content.family === "feedback") {
7271
- // exception
7272
- path = "/feedback/surveys";
7273
- }
7274
- else if (isPageContent(content)) {
7275
- // pages are in the document family,
7276
- // but instead of showing the page's metadata on /documents/about
7277
- // but we render the page on the pages route
7278
- path = "/pages";
7279
- }
7280
- else if (pluralizedFamilies.indexOf(family) > -1) {
7281
- // the rule
7282
- path = "/" + family + "s";
7283
- }
7284
- contentUrl = path + "/" + identifier;
7285
- }
7286
- return contentUrl;
7287
- };
7288
- var getSolutionUrl = function (content) {
7289
- var _a;
7290
- var hubUrl;
7291
- var type = content.type, identifier = content.identifier;
7292
- if (type === "Solution") {
7293
- // NOTE: as per the above spreadsheet,
7294
- // solution types are now in the Template family
7295
- // but we don't send them to the route for initiative templates
7296
- if (((_a = content.typeKeywords) === null || _a === void 0 ? void 0 : _a.indexOf("Deployed")) > 0) {
7297
- // deployed solutions go to the generic content route
7298
- hubUrl = "/content/" + identifier;
7299
- }
7300
- // others go to the solution about route
7301
- hubUrl = "/templates/" + identifier + "/about";
7302
- }
7303
- return hubUrl;
7304
- };
7305
- // page helpers
7306
- // TODO: we check both "Hub Page" and "Site Page" because we don't know whether the site is a portal or not
7307
- // In the future, the site object will have a site.isPortal() function that we can leverage
7308
- // instead of hardcoding the types here.
7309
- var isPageContent = function (content) {
7310
- return includes(["Hub Page", "Site Page"], content.type);
7311
- };
7312
- // proxied csv helpers
7313
- /**
7314
- * If an item is a proxied csv, returns the url for the proxying feature layer.
7315
- * If the item is not a proxied csv, returns undefined.
7316
- *
7317
- * @param item
7318
- * @param requestOptions Hub Request Options (including whether we're in portal)
7319
- * @returns
7320
- */
7321
- var getProxyUrl = function (item, requestOptions) {
7322
- var result;
7323
- if (isProxiedCSV(item, requestOptions)) {
7324
- result = requestOptions.hubApiUrl + "/datasets/" + item.id + "_0/FeatureServer/0";
7325
- }
7326
- return result;
7710
+ return getHubRelativeUrl(content.type, siteIdentifier || content.identifier, content.typeKeywords);
7327
7711
  };
7328
7712
 
7329
7713
  /**
@@ -8275,6 +8659,28 @@
8275
8659
  return clone;
8276
8660
  });
8277
8661
  }
8662
+ /**
8663
+ * Given an Item, fetch the data json and return an IModel
8664
+ * @param item
8665
+ * @param requestOptions
8666
+ * @returns
8667
+ */
8668
+ function fetchModelFromItem(item, requestOptions) {
8669
+ return __awaiter(this, void 0, void 0, function () {
8670
+ var data;
8671
+ return __generator(this, function (_a) {
8672
+ switch (_a.label) {
8673
+ case 0: return [4 /*yield*/, getItemData(item.id, requestOptions)];
8674
+ case 1:
8675
+ data = _a.sent();
8676
+ return [2 /*return*/, {
8677
+ item: item,
8678
+ data: data,
8679
+ }];
8680
+ }
8681
+ });
8682
+ });
8683
+ }
8278
8684
 
8279
8685
  /**
8280
8686
  * To streamline passing of either a model id or the model itself, we use this function
@@ -9049,19 +9455,43 @@
9049
9455
  * @returns
9050
9456
  */
9051
9457
  function getItemBySlug(slug, requestOptions) {
9458
+ return findItemsBySlug({ slug: slug }, requestOptions).then(function (results) {
9459
+ if (results.length) {
9460
+ return results[0];
9461
+ }
9462
+ else {
9463
+ return null;
9464
+ }
9465
+ });
9466
+ }
9467
+ /**
9468
+ * Find items by slug typeKeywords.
9469
+ *
9470
+ * Optional exclude parameter accepts the id of an item we expect to
9471
+ * have this particular slug. This is used during update calls
9472
+ * where we don't know if the slug specifically has been updated, but we
9473
+ * don't want a false-postive from the item we are updating
9474
+ *
9475
+ * @param slug
9476
+ * @param requestOptions
9477
+ * @returns
9478
+ */
9479
+ function findItemsBySlug(slugInfo, requestOptions) {
9052
9480
  var opts = {
9053
9481
  q: "",
9054
- filter: "typekeywords:\"slug|" + slug + "\"",
9482
+ filter: "typekeywords:\"slug|" + slugInfo.slug + "\"",
9055
9483
  authentication: requestOptions.authentication,
9056
9484
  };
9485
+ // We need to check for other items w/ a slug during
9486
+ // the update calls. For those scenarios we are interested
9487
+ // in any _other_ items which may have a specific slug
9488
+ // but not one specific item
9489
+ if (slugInfo.exclude) {
9490
+ opts.q = "NOT id:" + slugInfo.exclude;
9491
+ }
9057
9492
  return searchItems(opts)
9058
9493
  .then(function (response) {
9059
- if (response.results.length) {
9060
- return response.results[0];
9061
- }
9062
- else {
9063
- return null;
9064
- }
9494
+ return response.results;
9065
9495
  })
9066
9496
  .catch(function (e) {
9067
9497
  throw Error("Error in getItemBySlug " + e);
@@ -9079,20 +9509,20 @@
9079
9509
  * @param step
9080
9510
  * @returns
9081
9511
  */
9082
- function getUniqueSlug(slug, requestOptions, step) {
9512
+ function getUniqueSlug(slugInfo, requestOptions, step) {
9083
9513
  if (step === void 0) { step = 0; }
9084
- var combined = slug;
9514
+ var combinedSlug = slugInfo.slug;
9085
9515
  if (step) {
9086
- combined = slug + "-" + step;
9516
+ combinedSlug = slugInfo.slug + "-" + step;
9087
9517
  }
9088
- return getItemBySlug(combined, requestOptions)
9089
- .then(function (result) {
9090
- if (result) {
9518
+ return findItemsBySlug({ slug: combinedSlug, exclude: slugInfo.existingId }, requestOptions)
9519
+ .then(function (results) {
9520
+ if (results.length) {
9091
9521
  step++;
9092
- return getUniqueSlug(slug, requestOptions, step);
9522
+ return getUniqueSlug(slugInfo, requestOptions, step);
9093
9523
  }
9094
9524
  else {
9095
- return combined;
9525
+ return combinedSlug;
9096
9526
  }
9097
9527
  })
9098
9528
  .catch(function (e) {
@@ -9143,6 +9573,48 @@
9143
9573
  return template;
9144
9574
  }
9145
9575
 
9576
+ /**
9577
+ * Upload a file to be used as the thumbnail for an item
9578
+ * @param id
9579
+ * @param file
9580
+ * @param filename
9581
+ * @param requestOptions
9582
+ */
9583
+ function setItemThumbnail(id, file, filename, requestOptions) {
9584
+ return __awaiter(this, void 0, void 0, function () {
9585
+ var opts, response, err_1;
9586
+ return __generator(this, function (_a) {
9587
+ switch (_a.label) {
9588
+ case 0:
9589
+ opts = __assign({ item: {
9590
+ id: id,
9591
+ }, params: {
9592
+ thumbnail: file,
9593
+ }, filename: filename }, requestOptions);
9594
+ _a.label = 1;
9595
+ case 1:
9596
+ _a.trys.push([1, 3, , 4]);
9597
+ return [4 /*yield*/, updateItem(opts)];
9598
+ case 2:
9599
+ response = _a.sent();
9600
+ if (!response.success) {
9601
+ throw new HubError("Set Project Thumbnail", "Unknown error setting thumbnail.");
9602
+ }
9603
+ return [3 /*break*/, 4];
9604
+ case 3:
9605
+ err_1 = _a.sent();
9606
+ if (err_1 instanceof Error) {
9607
+ throw new HubError("Set Project Thumbnail", err_1.message, err_1);
9608
+ }
9609
+ else {
9610
+ throw new HubError("Set Project Thumbnail", "Unknown error setting thumbnail.");
9611
+ }
9612
+ case 4: return [2 /*return*/];
9613
+ }
9614
+ });
9615
+ });
9616
+ }
9617
+
9146
9618
  /**
9147
9619
  * Manage forward and backward property mappings to
9148
9620
  * streamline conversion between the Hub entities, and
@@ -9246,6 +9718,7 @@
9246
9718
  name: "No title provided",
9247
9719
  tags: [],
9248
9720
  typeKeywords: ["IHubProject", "HubProject"],
9721
+ status: "inactive",
9249
9722
  };
9250
9723
  /**
9251
9724
  * Default values for a new HubProject Model
@@ -9257,7 +9730,7 @@
9257
9730
  description: "No Description Provided",
9258
9731
  snippet: "",
9259
9732
  tags: [],
9260
- typeKeywords: [],
9733
+ typeKeywords: ["Hub Project"],
9261
9734
  properties: {
9262
9735
  slug: "",
9263
9736
  },
@@ -9265,7 +9738,6 @@
9265
9738
  data: {
9266
9739
  display: "about",
9267
9740
  timeline: {},
9268
- org: {},
9269
9741
  status: "inactive",
9270
9742
  contacts: [],
9271
9743
  schemaVersion: 1,
@@ -9346,7 +9818,7 @@
9346
9818
  }
9347
9819
  // Ensure slug is unique
9348
9820
  _a = project;
9349
- return [4 /*yield*/, getUniqueSlug(project.slug, requestOptions)];
9821
+ return [4 /*yield*/, getUniqueSlug({ slug: project.slug }, requestOptions)];
9350
9822
  case 1:
9351
9823
  // Ensure slug is unique
9352
9824
  _a.slug = _b.sent();
@@ -9376,15 +9848,11 @@
9376
9848
  return __generator(this, function (_b) {
9377
9849
  switch (_b.label) {
9378
9850
  case 0:
9379
- // verify that the slug is unique
9380
- // TODO: if the slug has not changed, we don't want to do this because
9381
- // the existing item will cause this to increment
9851
+ // verify that the slug is unique, excluding the current project
9382
9852
  _a = project;
9383
- return [4 /*yield*/, getUniqueSlug(project.slug, requestOptions)];
9853
+ return [4 /*yield*/, getUniqueSlug({ slug: project.slug, existingId: project.id }, requestOptions)];
9384
9854
  case 1:
9385
- // verify that the slug is unique
9386
- // TODO: if the slug has not changed, we don't want to do this because
9387
- // the existing item will cause this to increment
9855
+ // verify that the slug is unique, excluding the current project
9388
9856
  _a.slug = _b.sent();
9389
9857
  return [4 /*yield*/, getModel(project.id, requestOptions)];
9390
9858
  case 2:
@@ -9407,7 +9875,7 @@
9407
9875
  * @param identifier item id or slug
9408
9876
  * @param requestOptions
9409
9877
  */
9410
- function getProject(identifier, requestOptions) {
9878
+ function fetchProject(identifier, requestOptions) {
9411
9879
  var getPrms;
9412
9880
  if (isGuid(identifier)) {
9413
9881
  // get item by id
@@ -9415,12 +9883,20 @@
9415
9883
  }
9416
9884
  else {
9417
9885
  // search for item using filter=typekeywords:slug|identifier
9886
+ // although we could leverage searchProjects with an appropriate filter
9887
+ // getModelBySlug is a generalized function that works for any type
9418
9888
  getPrms = getModelBySlug(identifier, requestOptions);
9419
9889
  }
9420
9890
  return getPrms.then(function (model) {
9421
9891
  // transform the model into a HubProject
9422
9892
  var mapper = new PropertyMapper(getProjectPropertyMap());
9423
9893
  var project = mapper.modelToObject(model, {});
9894
+ var token;
9895
+ if (requestOptions.authentication) {
9896
+ var us = requestOptions.authentication;
9897
+ token = us.token;
9898
+ }
9899
+ project.thumbnailUrl = getItemThumbnailUrl(model.item, requestOptions, token);
9424
9900
  return project;
9425
9901
  });
9426
9902
  }
@@ -9448,13 +9924,88 @@
9448
9924
  // i.e. delegate to searchContent or just do an item search
9449
9925
  // and convert to IHubProject objects.
9450
9926
  //
9451
- // export async function searchProjects(
9452
- // filter: Filter<"content">,
9453
- // opts: IHubSearchOptions
9454
- // ): Promise<ISearchResponse<IHubProject>> {
9455
- // return _searchContent(filter, opts).then((results) => {
9456
- // })
9457
- // }
9927
+ function searchProjects(filter, options) {
9928
+ var _a;
9929
+ return __awaiter(this, void 0, void 0, function () {
9930
+ var scopingFilter, projectFilter, expanded, so;
9931
+ return __generator(this, function (_b) {
9932
+ scopingFilter = {
9933
+ filterType: "content",
9934
+ typekeywords: {
9935
+ exact: ["HubProject"],
9936
+ },
9937
+ };
9938
+ projectFilter = mergeContentFilter([scopingFilter, filter]);
9939
+ expanded = expandContentFilter(projectFilter);
9940
+ so = serializeContentFilterForPortal(expanded);
9941
+ // Aggregations
9942
+ if ((_a = options.aggregations) === null || _a === void 0 ? void 0 : _a.length) {
9943
+ so.countFields = options.aggregations.join(",");
9944
+ so.countSize = 200;
9945
+ }
9946
+ // copy over various options
9947
+ if (options.num) {
9948
+ so.num = options.num;
9949
+ }
9950
+ if (options.sortField) {
9951
+ so.sortField = options.sortField;
9952
+ }
9953
+ if (options.sortOrder) {
9954
+ so.sortOrder = options.sortOrder;
9955
+ }
9956
+ if (options.site) {
9957
+ so.site = cloneObject$1(options.site);
9958
+ }
9959
+ if (options.authentication) {
9960
+ so.authentication = options.authentication;
9961
+ }
9962
+ return [2 /*return*/, searchPortalProjects(so)];
9963
+ });
9964
+ });
9965
+ }
9966
+ /**
9967
+ * Internal fn that takes
9968
+ * @param searchOptions
9969
+ * @returns
9970
+ */
9971
+ function searchPortalProjects(searchOptions) {
9972
+ return __awaiter(this, void 0, void 0, function () {
9973
+ var response, hasNext, modelPromises, models, mapper, token, us, projects;
9974
+ return __generator(this, function (_a) {
9975
+ switch (_a.label) {
9976
+ case 0: return [4 /*yield*/, searchItems(searchOptions)];
9977
+ case 1:
9978
+ response = _a.sent();
9979
+ hasNext = response.nextStart > -1;
9980
+ modelPromises = response.results.map(function (itm) {
9981
+ return fetchModelFromItem(itm, {
9982
+ authentication: searchOptions.authentication,
9983
+ });
9984
+ });
9985
+ return [4 /*yield*/, Promise.all(modelPromises)];
9986
+ case 2:
9987
+ models = _a.sent();
9988
+ mapper = new PropertyMapper(getProjectPropertyMap());
9989
+ if (searchOptions.authentication) {
9990
+ us = searchOptions.authentication;
9991
+ token = us.token;
9992
+ }
9993
+ projects = models.map(function (m) {
9994
+ var prj = mapper.modelToObject(m, {});
9995
+ prj.thumbnailUrl = getItemThumbnailUrl(m.item, { authentication: searchOptions.authentication }, token);
9996
+ return prj;
9997
+ });
9998
+ return [2 /*return*/, {
9999
+ total: response.total,
10000
+ results: projects,
10001
+ facets: [],
10002
+ hasNext: hasNext,
10003
+ next: getNextFunction(searchOptions, response.nextStart, response.total, searchPortalProjects),
10004
+ }];
10005
+ }
10006
+ });
10007
+ });
10008
+ }
9458
10009
 
9459
10010
  /**
9460
10011
  * Centralized functions used to manage IHubProject instances
@@ -9563,6 +10114,18 @@
9563
10114
  });
9564
10115
  });
9565
10116
  };
10117
+ // DEPRECATED IN FAVOR OF .fetch()
10118
+ // TODO: REMOVE AT NEXT MAJOR
10119
+ /* istanbul ignore next */
10120
+ HubProjectManager.prototype.get = function (identifier, requestOptions) {
10121
+ return __awaiter(this, void 0, void 0, function () {
10122
+ return __generator(this, function (_a) {
10123
+ // tslint:disable-next-line
10124
+ console.warn("HubProjectManager.get is deprecated and will be removed. Use .fetch() instead.");
10125
+ return [2 /*return*/, this.fetch(identifier, requestOptions)];
10126
+ });
10127
+ });
10128
+ };
9566
10129
  /**
9567
10130
  * Fetch a Project via id or it's slug
9568
10131
  *
@@ -9577,10 +10140,51 @@
9577
10140
  return __awaiter(this, void 0, void 0, function () {
9578
10141
  return __generator(this, function (_a) {
9579
10142
  if (requestOptions || this.context.requestOptions) {
9580
- return [2 /*return*/, getProject(identifier, requestOptions || this.context.requestOptions)];
10143
+ return [2 /*return*/, fetchProject(identifier, requestOptions || this.context.requestOptions)];
9581
10144
  }
9582
10145
  else {
9583
- throw new HubError("Get Project", "Can not retrieve context.requestOptions from Context Manager. HubProjectManager is configured incorrectly.");
10146
+ throw new HubError("Fetch Project", "Can not retrieve context.requestOptions from Context Manager. HubProjectManager is configured incorrectly.");
10147
+ }
10148
+ });
10149
+ });
10150
+ };
10151
+ /**
10152
+ * Search for Projects
10153
+ *
10154
+ * @param filter
10155
+ * @param options
10156
+ */
10157
+ HubProjectManager.prototype.search = function (filter, options) {
10158
+ return __awaiter(this, void 0, void 0, function () {
10159
+ return __generator(this, function (_a) {
10160
+ // if we were not passed auth, and we have a session, use it
10161
+ if (!options.authentication && this.context.session) {
10162
+ options.authentication = this.context.session;
10163
+ }
10164
+ return [2 /*return*/, searchProjects(filter, options)];
10165
+ });
10166
+ });
10167
+ };
10168
+ /**
10169
+ * Set the thumbnail for the Project
10170
+ * @param id
10171
+ * @param file
10172
+ * @param filename
10173
+ * @param requestOptions
10174
+ * @returns
10175
+ */
10176
+ HubProjectManager.prototype.updateThumbnail = function (project, file, filename, requestOptions) {
10177
+ return __awaiter(this, void 0, void 0, function () {
10178
+ var ro;
10179
+ return __generator(this, function (_a) {
10180
+ switch (_a.label) {
10181
+ case 0:
10182
+ ro = requestOptions || this.context.userRequestOptions;
10183
+ return [4 /*yield*/, setItemThumbnail(project.id, file, filename, ro)];
10184
+ case 1:
10185
+ _a.sent();
10186
+ // get the item so we have updated props and timestamps
10187
+ return [2 /*return*/, this.fetch(project.id, requestOptions)];
9584
10188
  }
9585
10189
  });
9586
10190
  });
@@ -9771,36 +10375,6 @@
9771
10375
  });
9772
10376
  }
9773
10377
 
9774
- /**
9775
- * Get the fully qualified URL for an item's thumbnail
9776
- * @param item w/ id, thumbnail, and access
9777
- * @param portalUrlOrObject a portal base or API URL, a portal object, or request options containing either of those
9778
- * @param optionsOrToken options including width and/or token for the current user's session; will only be appended as a query parameter if the item's access is **not** `public`
9779
- * @returns URL to the item's thumbnail, defaults to `https://www.arcgis.com/sharing/rest/content/items/{item.id}/info/{item.thumbnail}`. Returns `null` if the item does not have a thumbnail assigned.
9780
- */
9781
- function getItemThumbnailUrl(item, portalUrlOrObject, optionsOrToken) {
9782
- if (!item || !item.thumbnail) {
9783
- // TODO: handle image types by returning the image (item data) itself?
9784
- return null;
9785
- }
9786
- // tslint:disable-next-line prefer-const
9787
- var _a = optionsOrToken || {}, token = _a.token, width = _a.width;
9788
- // TODO: at the next breaking change drop support for passing token as string
9789
- if (!token && typeof optionsOrToken === "string") {
9790
- token = optionsOrToken;
9791
- }
9792
- var itemApiUrl = getItemApiUrl(item, portalUrlOrObject, token);
9793
- var _b = itemApiUrl.split("?"), baseUrl = _b[0], search = _b[1];
9794
- var searchParams = new URLSearchParams(search);
9795
- searchParams.delete("f");
9796
- if (width) {
9797
- searchParams.append("w", width + "");
9798
- }
9799
- var newSearch = searchParams.toString();
9800
- var url = baseUrl + "/info/" + item.thumbnail;
9801
- return newSearch ? url + "?" + newSearch : url;
9802
- }
9803
-
9804
10378
  /**
9805
10379
  * Given an item, return an array of assets that includes
9806
10380
  * all the resources, as well as the thumbnail
@@ -11602,6 +12176,23 @@
11602
12176
  return fetch(url, { method: "DELETE", headers: headers, mode: "cors" }).then(_checkStatusAndParseJson);
11603
12177
  }
11604
12178
 
12179
+ /**
12180
+ * Remove all domain entries by site id.
12181
+ * User must be a member of the org that owns the domain entry.
12182
+ * @param {int} domainSiteId of the domain entries to remove
12183
+ * @param {IHubRequestOptions} hubRequestOptions`dom
12184
+ */
12185
+ function removeDomainsBySiteId(domainSiteId, hubRequestOptions) {
12186
+ // TODO: Can remove this if no longer required
12187
+ if (hubRequestOptions.isPortal) {
12188
+ throw new Error("removeDomainsBySiteId is not available in ArcGIS Enterprise. Instead, edit the hubdomain typekeyword on the item");
12189
+ }
12190
+ var headers = _getAuthHeader(hubRequestOptions);
12191
+ headers["Content-Type"] = "application/json";
12192
+ var url = _getDomainServiceUrl(hubRequestOptions.hubApiUrl) + "/?siteId=" + domainSiteId;
12193
+ return fetch(url, { method: "DELETE", headers: headers, mode: "cors" }).then(_checkStatusAndParseJson);
12194
+ }
12195
+
11605
12196
  /**
11606
12197
  * Update an entry in the domain system
11607
12198
  * @param {IHubDomain} domainEntry Doman object to be updated
@@ -12076,21 +12667,19 @@
12076
12667
  *
12077
12668
  * myHub.context.currentUser //=> {username: "casey", ...} as IUser
12078
12669
  *
12079
- * const projectStore = await myHub.getProjectStore();
12080
- *
12081
- * const pavingProject = await projectStore.create({name: "12th Street Paving"});
12670
+ * const pavingProject = await myHub.projects.create({name: "12th Street Paving"});
12082
12671
  * pavingProject.summary = "This is the 2024 planned paving of 12th Street, between 8th and 11th Ave";
12083
- * await projectStore.update(pavingProject);
12672
+ * await myHub.projects.update(pavingProject);
12084
12673
  * ```
12085
12674
  *
12086
- * This is a convenience class. Hub Stores can be created
12675
+ * This is a convenience class. Hub Managers can be created
12087
12676
  * directly, or the underlying functions can be imported an used
12088
12677
  * as need for scenarios where these class structures introduce
12089
12678
  * unwanted complexity
12090
12679
  */
12091
12680
  var Hub = /** @class */ (function () {
12092
12681
  /**
12093
- * Private so we can employ a factory function should we need
12682
+ * Private so we can employ a factory function to do
12094
12683
  * async work during creation
12095
12684
  * @param contextManager
12096
12685
  */
@@ -12098,9 +12687,7 @@
12098
12687
  this._contextManager = contextManager;
12099
12688
  }
12100
12689
  /**
12101
- * Factory function to construct a new HubProjectStore instance.
12102
- *
12103
- * Note: Used so that we could do async actions in the ctor.
12690
+ * Factory function to construct a new Hub instance.
12104
12691
  * @param contextManager
12105
12692
  * @returns
12106
12693
  */
@@ -12134,7 +12721,7 @@
12134
12721
  });
12135
12722
  Object.defineProperty(Hub.prototype, "projects", {
12136
12723
  /**
12137
- * Create a Project Store connected to the current Hub
12724
+ * HubProjectManager for the current Hub
12138
12725
  * @returns
12139
12726
  */
12140
12727
  get: function () {
@@ -12523,6 +13110,7 @@
12523
13110
  exports.cloneObject = cloneObject$1;
12524
13111
  exports.completeOAuth2 = completeOAuth2;
12525
13112
  exports.compose = compose;
13113
+ exports.composeContent = composeContent;
12526
13114
  exports.constructSlug = constructSlug;
12527
13115
  exports.convertContentDefinitionToFilter = convertContentDefinitionToFilter;
12528
13116
  exports.convertContentFilterToSearchOptions = convertContentFilterToSearchOptions;
@@ -12566,13 +13154,15 @@
12566
13154
  exports.fetchAndUploadThumbnail = fetchAndUploadThumbnail;
12567
13155
  exports.fetchHubTranslation = fetchHubTranslation;
12568
13156
  exports.fetchImageAsBlob = fetchImageAsBlob;
13157
+ exports.fetchModelFromItem = fetchModelFromItem;
13158
+ exports.fetchProject = fetchProject;
12569
13159
  exports.fetchSite = fetchSite;
12570
13160
  exports.filterBy = filterBy;
12571
13161
  exports.findBy = findBy;
13162
+ exports.findItemsBySlug = findItemsBySlug;
12572
13163
  exports.flattenArray = flattenArray;
12573
13164
  exports.generateRandomString = generateRandomString;
12574
13165
  exports.getCategory = getCategory;
12575
- exports.getCollection = getCollection;
12576
13166
  exports.getContentIdentifier = getContentIdentifier;
12577
13167
  exports.getContentSiteUrls = getContentSiteUrls;
12578
13168
  exports.getContentTypeIcon = getContentTypeIcon;
@@ -12609,7 +13199,7 @@
12609
13199
  exports.getPortalApiUrl = getPortalApiUrl;
12610
13200
  exports.getPortalBaseFromOrgUrl = getPortalBaseFromOrgUrl;
12611
13201
  exports.getPortalUrl = getPortalUrl;
12612
- exports.getProject = getProject;
13202
+ exports.getPortalUrls = getPortalUrls;
12613
13203
  exports.getProp = getProp;
12614
13204
  exports.getProps = getProps;
12615
13205
  exports.getProxyUrl = getProxyUrl;
@@ -12677,10 +13267,12 @@
12677
13267
  exports.relativeDateToDateRange = relativeDateToDateRange;
12678
13268
  exports.removeContextFromSlug = removeContextFromSlug;
12679
13269
  exports.removeDomain = removeDomain;
13270
+ exports.removeDomainsBySiteId = removeDomainsBySiteId;
12680
13271
  exports.removeEmptyProps = removeEmptyProps;
12681
13272
  exports.replaceItemId = replaceItemId;
12682
13273
  exports.runRevertableTask = runRevertableTask;
12683
13274
  exports.saveSession = saveSession;
13275
+ exports.searchProjects = searchProjects;
12684
13276
  exports.serializeContentFilterForPortal = serializeContentFilterForPortal;
12685
13277
  exports.serializeDateRange = serializeDateRange;
12686
13278
  exports.serializeGroupFilterForPortal = serializeGroupFilterForPortal;
@@ -12692,6 +13284,7 @@
12692
13284
  exports.setContentHubId = setContentHubId;
12693
13285
  exports.setContentSiteUrls = setContentSiteUrls;
12694
13286
  exports.setContentType = setContentType;
13287
+ exports.setItemThumbnail = setItemThumbnail;
12695
13288
  exports.setProp = setProp;
12696
13289
  exports.setSlugKeyword = setSlugKeyword;
12697
13290
  exports.shareItemToGroups = shareItemToGroups;