@esri/hub-common 9.39.0 → 9.40.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 (50) hide show
  1. package/dist/es2017/content/_internal.js +83 -0
  2. package/dist/es2017/content/_internal.js.map +1 -1
  3. package/dist/es2017/content/compose.js +7 -11
  4. package/dist/es2017/content/compose.js.map +1 -1
  5. package/dist/es2017/core/types/IHubContent.js +7 -0
  6. package/dist/es2017/core/types/IHubContent.js.map +1 -1
  7. package/dist/es2017/index.js +1 -0
  8. package/dist/es2017/index.js.map +1 -1
  9. package/dist/es2017/items/_enrichments.js +21 -0
  10. package/dist/es2017/items/_enrichments.js.map +1 -1
  11. package/dist/es2017/org/fetch-org.js +21 -0
  12. package/dist/es2017/org/fetch-org.js.map +1 -0
  13. package/dist/es2017/org/index.js +2 -0
  14. package/dist/es2017/org/index.js.map +1 -0
  15. package/dist/esm/content/_internal.js +85 -0
  16. package/dist/esm/content/_internal.js.map +1 -1
  17. package/dist/esm/content/compose.js +5 -11
  18. package/dist/esm/content/compose.js.map +1 -1
  19. package/dist/esm/core/types/IHubContent.js +7 -0
  20. package/dist/esm/core/types/IHubContent.js.map +1 -1
  21. package/dist/esm/index.js +1 -0
  22. package/dist/esm/index.js.map +1 -1
  23. package/dist/esm/items/_enrichments.js +21 -0
  24. package/dist/esm/items/_enrichments.js.map +1 -1
  25. package/dist/esm/org/fetch-org.js +22 -0
  26. package/dist/esm/org/fetch-org.js.map +1 -0
  27. package/dist/esm/org/index.js +2 -0
  28. package/dist/esm/org/index.js.map +1 -0
  29. package/dist/node/content/_internal.js +84 -1
  30. package/dist/node/content/_internal.js.map +1 -1
  31. package/dist/node/content/compose.js +6 -10
  32. package/dist/node/content/compose.js.map +1 -1
  33. package/dist/node/core/types/IHubContent.js +8 -0
  34. package/dist/node/core/types/IHubContent.js.map +1 -1
  35. package/dist/node/index.js +1 -0
  36. package/dist/node/index.js.map +1 -1
  37. package/dist/node/items/_enrichments.js +21 -0
  38. package/dist/node/items/_enrichments.js.map +1 -1
  39. package/dist/node/org/fetch-org.js +24 -0
  40. package/dist/node/org/fetch-org.js.map +1 -0
  41. package/dist/node/org/index.js +5 -0
  42. package/dist/node/org/index.js.map +1 -0
  43. package/dist/types/content/_internal.d.ts +54 -5
  44. package/dist/types/core/types/IHubContent.d.ts +21 -0
  45. package/dist/types/index.d.ts +1 -0
  46. package/dist/types/org/fetch-org.d.ts +9 -0
  47. package/dist/types/org/index.d.ts +1 -0
  48. package/dist/umd/common.umd.js +135 -11
  49. package/dist/umd/common.umd.js.map +1 -1
  50. package/package.json +1 -1
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./fetch-org"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/org/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B"}
@@ -1,6 +1,6 @@
1
- import { IItem } from "@esri/arcgis-rest-portal";
2
- import { ILayerDefinition, ISpatialReference } from "@esri/arcgis-rest-types";
3
- import { IHubContent } from "../core";
1
+ import { IItem, IPortal } from "@esri/arcgis-rest-portal";
2
+ import { ILayerDefinition, ISpatialReference, IUser } from "@esri/arcgis-rest-types";
3
+ import { IHubContent, PublisherSource } from "../core";
4
4
  import { IHubGeography, GeographyProvenance, IHubRequestOptions } from "../types";
5
5
  import { IHubAdditionalResource } from "../core/types/IHubAdditionalResource";
6
6
  /**
@@ -49,6 +49,14 @@ export declare const setContentBoundary: (content: IHubContent, boundary: Geogra
49
49
  publishedDate: Date;
50
50
  publishedDateSource?: string;
51
51
  updateFrequency?: string;
52
+ publisher?: {
53
+ name?: string;
54
+ username?: string;
55
+ nameSource: PublisherSource;
56
+ organization?: string;
57
+ orgId?: string;
58
+ organizationSource: PublisherSource;
59
+ };
52
60
  portalHomeUrl?: string;
53
61
  portalApiUrl?: string;
54
62
  portalDataUrl?: string;
@@ -85,8 +93,8 @@ export declare const setContentBoundary: (content: IHubContent, boundary: Geogra
85
93
  };
86
94
  metadata?: any;
87
95
  groupIds?: string[];
88
- ownerUser?: import("@esri/arcgis-rest-portal").IUser;
89
- org?: Partial<import("@esri/arcgis-rest-portal").IPortal>;
96
+ ownerUser?: IUser;
97
+ org?: Partial<IPortal>;
90
98
  errors?: import("../types").IEnrichmentErrorInfo[];
91
99
  server?: Partial<import("@esri/arcgis-rest-feature-layer").IFeatureServiceDefinition>;
92
100
  layers?: Partial<ILayerDefinition>[];
@@ -284,4 +292,45 @@ export declare const getAdditionalResourceUrl: (resource: IAGOAdditionalResource
284
292
  * @returns the correct extent in a bbox format, or undefined
285
293
  */
286
294
  export declare const determineExtent: (item: IItem, extentEnrichment?: any, layer?: ILayerDefinition) => any;
295
+ /**
296
+ * @private
297
+ *
298
+ * Extracts the first contact from a given formal item metadata path.
299
+ * This is particularly helpful if the contact path is either an object or an array.
300
+ *
301
+ * Note: the raw contact object must have the following properties:
302
+ * - `rpIndName`: name of the individual
303
+ * - `rpOrgName`: name of the individual's organization
304
+ *
305
+ * @param metadata formal item metadata
306
+ * @param path path to the contact object/array
307
+ * @returns
308
+ */
309
+ export declare const extractFirstContact: (metadata: any, path: string) => {
310
+ individualName: any;
311
+ organizationName: any;
312
+ };
313
+ /**
314
+ * Determines the correct orgId for an item.
315
+ * Note: it's undocumented, but the portal API will return orgId for items... sometimes.
316
+ *
317
+ * @param item
318
+ * @param ownerUser item owner's hydrated user object
319
+ */
320
+ export declare const getItemOrgId: (item: IItem, ownerUser?: IUser) => any;
321
+ /**
322
+ * Calculates the Publisher display info for the given item.
323
+ * Utilizes this fallback pattern:
324
+ * 1) Formal Item Metadata > Resource > Citation > Contact
325
+ * 2) Formal Item Metadata > Resource > Contact
326
+ * 3) Item’s Owner and Org Name
327
+ * 4) Undefined (Item Owner / Org are private and we can't access additional info)
328
+ *
329
+ * @param item
330
+ * @param metadata
331
+ * @param org portal info of the item's organization
332
+ * @param ownerUser the item owner's hydrated user
333
+ * @returns
334
+ */
335
+ export declare const getPublisherInfo: (item: IItem, metadata?: any, org?: Partial<IPortal>, ownerUser?: IUser) => any;
287
336
  export {};
@@ -5,6 +5,12 @@ import { IStructuredLicense } from "../../items/get-structured-license";
5
5
  import { IHubItemEntity } from ".";
6
6
  import { IHubContentEnrichments } from "./IHubContentEnrichments";
7
7
  import { IHubAdditionalResource } from "./IHubAdditionalResource";
8
+ export declare enum PublisherSource {
9
+ CitationContact = "metadata.resource.citation.contact",
10
+ ResourceContact = "metadata.resource.contact",
11
+ ItemOwner = "item.owner",
12
+ None = "none"
13
+ }
8
14
  /**
9
15
  * Data model for content
10
16
  */
@@ -61,6 +67,21 @@ export interface IHubContent extends IHubItemEntity, IHubContentEnrichments, IIt
61
67
  publishedDateSource?: string;
62
68
  /** Frequency at which the content is updated */
63
69
  updateFrequency?: string;
70
+ /**
71
+ * Info to display about the content's publisher. Follows this fallback pattern:
72
+ * 1) Formal Item Metadata > Resource > Citation > Contact
73
+ * 2) Formal Item Metadata > Resource > Contact
74
+ * 3) Item’s Owner and Org Name
75
+ * 4) Undefined (Item Owner / Org are private and we can't access additional info)
76
+ */
77
+ publisher?: {
78
+ name?: string;
79
+ username?: string;
80
+ nameSource: PublisherSource;
81
+ organization?: string;
82
+ orgId?: string;
83
+ organizationSource: PublisherSource;
84
+ };
64
85
  /** URL of the resource's page in the Portal Home application */
65
86
  portalHomeUrl?: string;
66
87
  /** URL of the Portal API endpoint for the resource */
@@ -25,6 +25,7 @@ export * from "./util";
25
25
  export * from "./utils";
26
26
  export * from "./Hub";
27
27
  export * from "./pages";
28
+ export * from "./org";
28
29
  import OperationStack from "./OperationStack";
29
30
  import OperationError from "./OperationError";
30
31
  import HubError from "./HubError";
@@ -0,0 +1,9 @@
1
+ import { IRequestOptions } from "@esri/arcgis-rest-request";
2
+ /**
3
+ * Fetches the portal for a given org.
4
+ *
5
+ * @param orgId
6
+ * @param options request options
7
+ * @returns
8
+ */
9
+ export declare const fetchOrg: (orgId: string, options?: IRequestOptions) => Promise<import("@esri/arcgis-rest-portal").IPortal>;
@@ -0,0 +1 @@
1
+ export * from "./fetch-org";
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * @esri/hub-common - v9.38.0 - Mon Jun 06 2022 22:49:18 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/hub-common - v9.39.0 - Fri Jun 10 2022 17:25:47 GMT+0000 (Coordinated Universal Time)
3
3
  * Copyright (c) 2022 Environmental Systems Research Institute, Inc.
4
4
  * Apache-2.0
5
5
  */
@@ -6434,6 +6434,14 @@
6434
6434
  return request(cleanUrl(options.url), options);
6435
6435
  }
6436
6436
 
6437
+ exports.PublisherSource = void 0;
6438
+ (function (PublisherSource) {
6439
+ PublisherSource["CitationContact"] = "metadata.resource.citation.contact";
6440
+ PublisherSource["ResourceContact"] = "metadata.resource.contact";
6441
+ PublisherSource["ItemOwner"] = "item.owner";
6442
+ PublisherSource["None"] = "none";
6443
+ })(exports.PublisherSource || (exports.PublisherSource = {}));
6444
+
6437
6445
  /**
6438
6446
  * Turns an bounding box coordinate array into an extent object
6439
6447
  * @param bBox bounding box coordinate array
@@ -7012,6 +7020,90 @@
7012
7020
  : undefined;
7013
7021
  return itemExtent || extentEnrichmentCoordinates || layerExtent;
7014
7022
  };
7023
+ /**
7024
+ * @private
7025
+ *
7026
+ * Extracts the first contact from a given formal item metadata path.
7027
+ * This is particularly helpful if the contact path is either an object or an array.
7028
+ *
7029
+ * Note: the raw contact object must have the following properties:
7030
+ * - `rpIndName`: name of the individual
7031
+ * - `rpOrgName`: name of the individual's organization
7032
+ *
7033
+ * @param metadata formal item metadata
7034
+ * @param path path to the contact object/array
7035
+ * @returns
7036
+ */
7037
+ var extractFirstContact = function (metadata, path) {
7038
+ var rawContacts = getProp(metadata, path) || {};
7039
+ var _a = Array.isArray(rawContacts)
7040
+ ? rawContacts[0]
7041
+ : rawContacts, rpIndName = _a.rpIndName, rpOrgName = _a.rpOrgName;
7042
+ return { individualName: rpIndName, organizationName: rpOrgName };
7043
+ };
7044
+ /**
7045
+ * Determines the correct orgId for an item.
7046
+ * Note: it's undocumented, but the portal API will return orgId for items... sometimes.
7047
+ *
7048
+ * @param item
7049
+ * @param ownerUser item owner's hydrated user object
7050
+ */
7051
+ var getItemOrgId = function (item, ownerUser) {
7052
+ return item.orgId || (ownerUser === null || ownerUser === void 0 ? void 0 : ownerUser.orgId);
7053
+ };
7054
+ /**
7055
+ * Calculates the Publisher display info for the given item.
7056
+ * Utilizes this fallback pattern:
7057
+ * 1) Formal Item Metadata > Resource > Citation > Contact
7058
+ * 2) Formal Item Metadata > Resource > Contact
7059
+ * 3) Item’s Owner and Org Name
7060
+ * 4) Undefined (Item Owner / Org are private and we can't access additional info)
7061
+ *
7062
+ * @param item
7063
+ * @param metadata
7064
+ * @param org portal info of the item's organization
7065
+ * @param ownerUser the item owner's hydrated user
7066
+ * @returns
7067
+ */
7068
+ var getPublisherInfo = function (item, metadata, org, ownerUser) {
7069
+ var result = {
7070
+ nameSource: exports.PublisherSource.None,
7071
+ organizationSource: exports.PublisherSource.None,
7072
+ };
7073
+ var citationContact = extractFirstContact(metadata, "metadata.dataIdInfo.idCitation.citRespParty");
7074
+ var resourceContact = extractFirstContact(metadata, "metadata.mdContact");
7075
+ // Determine publisher name properties
7076
+ var ownerFullName = getProp(ownerUser, "fullName");
7077
+ if (citationContact.individualName) {
7078
+ result.name = citationContact.individualName;
7079
+ result.nameSource = exports.PublisherSource.CitationContact;
7080
+ }
7081
+ else if (resourceContact.individualName) {
7082
+ result.name = resourceContact.individualName;
7083
+ result.nameSource = exports.PublisherSource.ResourceContact;
7084
+ }
7085
+ else if (ownerFullName) {
7086
+ result.name = ownerFullName;
7087
+ result.username = ownerUser.username;
7088
+ result.nameSource = exports.PublisherSource.ItemOwner;
7089
+ }
7090
+ // Determine publisher org properties
7091
+ var orgName = getProp(org, "name");
7092
+ if (citationContact.organizationName) {
7093
+ result.organization = citationContact.organizationName;
7094
+ result.organizationSource = exports.PublisherSource.CitationContact;
7095
+ }
7096
+ else if (resourceContact.organizationName) {
7097
+ result.organization = resourceContact.organizationName;
7098
+ result.organizationSource = exports.PublisherSource.ResourceContact;
7099
+ }
7100
+ else if (orgName) {
7101
+ result.organization = orgName;
7102
+ result.orgId = getItemOrgId(item, ownerUser);
7103
+ result.organizationSource = exports.PublisherSource.ItemOwner;
7104
+ }
7105
+ return result;
7106
+ };
7015
7107
 
7016
7108
  var STANDARD_LICENSES = [
7017
7109
  {
@@ -7919,13 +8011,8 @@
7919
8011
  get metadataUpdateFrequency() {
7920
8012
  return getUpdateFrequencyFromMetadata(metadata, "metadataUpdateFrequency");
7921
8013
  },
7922
- // TODO: add the publisher logic outlined here:
7923
- // https://devtopia.esri.com/dc/hub/issues/2932#issuecomment-3276309
7924
8014
  get publisher() {
7925
- return {
7926
- name: item.owner,
7927
- username: item.owner,
7928
- };
8015
+ return getPublisherInfo(item, metadata, org, ownerUser);
7929
8016
  },
7930
8017
  // TODO: is metrics in use?
7931
8018
  get metrics() {
@@ -7945,11 +8032,10 @@
7945
8032
  Array.isArray(data.layers) &&
7946
8033
  data.layers.find(function (_layer) { return _layer.id === layer.id; });
7947
8034
  return dataLayer ? dataLayer.layerDefinition : undefined;
8035
+ }, get orgId() {
8036
+ return org ? org.id : getItemOrgId(item, ownerUser);
7948
8037
  },
7949
- get orgId() {
7950
- // NOTE: it's undocumented, but the portal API will return orgId for items... sometimes
7951
- return org ? org.id : item.orgId || (ownerUser === null || ownerUser === void 0 ? void 0 : ownerUser.orgId);
7952
- }, get contentTypeIcon() {
8038
+ get contentTypeIcon() {
7953
8039
  /* Note: only returns calcite-icons */
7954
8040
  return getContentTypeIcon(type);
7955
8041
  },
@@ -9882,6 +9968,24 @@
9882
9968
  };
9883
9969
  });
9884
9970
 
9971
+ /**
9972
+ * Fetches the portal for a given org.
9973
+ *
9974
+ * @param orgId
9975
+ * @param options request options
9976
+ * @returns
9977
+ */
9978
+ var fetchOrg = function (orgId, options) {
9979
+ var orgPortalUrl = getProp(options, "portal") ||
9980
+ getProp(options, "authentication.portal") ||
9981
+ "www.arcgis.com";
9982
+ // In order to get the correct response, we must pass options.portal
9983
+ // as a base portal url (e.g., www.arcgis.com, qaext.arcgis.com, etc)
9984
+ // **not** an org portal (i.e. org.maps.arcgis.com).
9985
+ var basePortalUrl = getPortalBaseFromOrgUrl(orgPortalUrl) + "/sharing/rest";
9986
+ return getPortal(orgId, __assign(__assign({}, options), { portal: basePortalUrl }));
9987
+ };
9988
+
9885
9989
  /**
9886
9990
  * Parse metadataxml into json object
9887
9991
  * @param metadataXml
@@ -9962,6 +10066,24 @@
9962
10066
  })
9963
10067
  .catch(function (error) { return handleEnrichmentError$1(error, input, opId); });
9964
10068
  };
10069
+ // Note, this MUST be run after `enrichOwnerUser` to access the correct orgId during
10070
+ // processing. `item.orgId` is only SOMETIMES returned by Portal, so we need to have
10071
+ // the ownerUser's orgId as a backup.
10072
+ var enrichOrg = function (input) {
10073
+ var data = input.data, stack = input.stack, requestOptions = input.requestOptions;
10074
+ var opId = stack.start("enrichOrg");
10075
+ var orgId = getItemOrgId(data.item, data.ownerUser);
10076
+ return fetchOrg(orgId, requestOptions)
10077
+ .then(function (org) {
10078
+ stack.finish(opId);
10079
+ return {
10080
+ data: __assign(__assign({}, data), { org: org }),
10081
+ stack: stack,
10082
+ requestOptions: requestOptions,
10083
+ };
10084
+ })
10085
+ .catch(function (error) { return handleEnrichmentError$1(error, input, opId); });
10086
+ };
9965
10087
  var enrichData = function (input) {
9966
10088
  var data = input.data, stack = input.stack, requestOptions = input.requestOptions;
9967
10089
  var opId = stack.start("enrichData");
@@ -10018,6 +10140,7 @@
10018
10140
  groupIds: enrichGroupIds,
10019
10141
  metadata: enrichMetadata,
10020
10142
  ownerUser: enrichOwnerUser,
10143
+ org: enrichOrg,
10021
10144
  data: enrichData,
10022
10145
  server: enrichServer,
10023
10146
  layers: enrichLayers,
@@ -19724,6 +19847,7 @@
19724
19847
  exports.fetchHubTranslation = fetchHubTranslation;
19725
19848
  exports.fetchImageAsBlob = fetchImageAsBlob;
19726
19849
  exports.fetchModelFromItem = fetchModelFromItem;
19850
+ exports.fetchOrg = fetchOrg;
19727
19851
  exports.fetchProject = fetchProject;
19728
19852
  exports.fetchSite = fetchSite;
19729
19853
  exports.fetchSiteModel = fetchSiteModel;