@esri/hub-common 9.13.2 → 9.14.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 (70) hide show
  1. package/dist/es2017/ArcGISContext.js +158 -147
  2. package/dist/es2017/ArcGISContext.js.map +1 -1
  3. package/dist/es2017/ArcGISContextManager.js +160 -0
  4. package/dist/es2017/ArcGISContextManager.js.map +1 -0
  5. package/dist/es2017/index.js +1 -0
  6. package/dist/es2017/index.js.map +1 -1
  7. package/dist/es2017/search/_searchContent.js +18 -7
  8. package/dist/es2017/search/_searchContent.js.map +1 -1
  9. package/dist/es2017/search/_searchGroups.js +1 -11
  10. package/dist/es2017/search/_searchGroups.js.map +1 -1
  11. package/dist/es2017/search/utils.js +1 -1
  12. package/dist/es2017/urls/getHubApiFromPortalUrl.js +21 -0
  13. package/dist/es2017/urls/getHubApiFromPortalUrl.js.map +1 -0
  14. package/dist/es2017/urls/getPortalBaseFromOrgUrl.js +25 -0
  15. package/dist/es2017/urls/getPortalBaseFromOrgUrl.js.map +1 -0
  16. package/dist/es2017/urls/index.js +2 -0
  17. package/dist/es2017/urls/index.js.map +1 -1
  18. package/dist/esm/ArcGISContext.js +251 -202
  19. package/dist/esm/ArcGISContext.js.map +1 -1
  20. package/dist/esm/ArcGISContextManager.js +204 -0
  21. package/dist/esm/ArcGISContextManager.js.map +1 -0
  22. package/dist/esm/index.js +1 -0
  23. package/dist/esm/index.js.map +1 -1
  24. package/dist/esm/search/_searchContent.js +18 -7
  25. package/dist/esm/search/_searchContent.js.map +1 -1
  26. package/dist/esm/search/_searchGroups.js +3 -13
  27. package/dist/esm/search/_searchGroups.js.map +1 -1
  28. package/dist/esm/search/utils.js +1 -1
  29. package/dist/esm/urls/getHubApiFromPortalUrl.js +21 -0
  30. package/dist/esm/urls/getHubApiFromPortalUrl.js.map +1 -0
  31. package/dist/esm/urls/getPortalBaseFromOrgUrl.js +25 -0
  32. package/dist/esm/urls/getPortalBaseFromOrgUrl.js.map +1 -0
  33. package/dist/esm/urls/index.js +2 -0
  34. package/dist/esm/urls/index.js.map +1 -1
  35. package/dist/node/ArcGISContext.js +158 -147
  36. package/dist/node/ArcGISContext.js.map +1 -1
  37. package/dist/node/ArcGISContextManager.js +164 -0
  38. package/dist/node/ArcGISContextManager.js.map +1 -0
  39. package/dist/node/index.js +1 -0
  40. package/dist/node/index.js.map +1 -1
  41. package/dist/node/search/_searchContent.js +17 -6
  42. package/dist/node/search/_searchContent.js.map +1 -1
  43. package/dist/node/search/_searchGroups.js +1 -11
  44. package/dist/node/search/_searchGroups.js.map +1 -1
  45. package/dist/node/search/utils.js +1 -1
  46. package/dist/node/urls/getHubApiFromPortalUrl.js +25 -0
  47. package/dist/node/urls/getHubApiFromPortalUrl.js.map +1 -0
  48. package/dist/node/urls/getPortalBaseFromOrgUrl.js +29 -0
  49. package/dist/node/urls/getPortalBaseFromOrgUrl.js.map +1 -0
  50. package/dist/node/urls/index.js +2 -0
  51. package/dist/node/urls/index.js.map +1 -1
  52. package/dist/types/ArcGISContext.d.ts +103 -77
  53. package/dist/types/ArcGISContextManager.d.ts +113 -0
  54. package/dist/types/index.d.ts +1 -0
  55. package/dist/types/search/utils.d.ts +1 -1
  56. package/dist/types/urls/getHubApiFromPortalUrl.d.ts +8 -0
  57. package/dist/types/urls/getPortalBaseFromOrgUrl.d.ts +9 -0
  58. package/dist/types/urls/index.d.ts +2 -0
  59. package/dist/umd/common.umd.js +144 -125
  60. package/dist/umd/common.umd.js.map +1 -1
  61. package/dist/umd/common.umd.min.js +1 -1
  62. package/dist/umd/common.umd.min.js.map +1 -1
  63. package/package.json +1 -1
  64. package/dist/es2017/ArcGISContextState.js +0 -203
  65. package/dist/es2017/ArcGISContextState.js.map +0 -1
  66. package/dist/esm/ArcGISContextState.js +0 -285
  67. package/dist/esm/ArcGISContextState.js.map +0 -1
  68. package/dist/node/ArcGISContextState.js +0 -207
  69. package/dist/node/ArcGISContextState.js.map +0 -1
  70. package/dist/types/ArcGISContextState.d.ts +0 -129
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * @esri/hub-common - v9.13.1 - Sat Jan 22 2022 18:07:51 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/hub-common - v9.13.2 - Tue Jan 25 2022 00:14:10 GMT+0000 (Coordinated Universal Time)
3
3
  * Copyright (c) 2022 Environmental Systems Research Institute, Inc.
4
4
  * Apache-2.0
5
5
  */
@@ -4976,6 +4976,52 @@
4976
4976
  return content.replace("(", "<br/>(");
4977
4977
  }
4978
4978
 
4979
+ /**
4980
+ * Cross-walk from a portalUrl to the corresponding Hub API Url
4981
+ *
4982
+ * If the passed url is not recognized, then this will return `undefined`
4983
+ * @param portalUrl
4984
+ * @returns
4985
+ */
4986
+ function getHubApiFromPortalUrl(portalUrl) {
4987
+ var result;
4988
+ if (portalUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
4989
+ result = "https://hubqa.arcgis.com";
4990
+ }
4991
+ else if (portalUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
4992
+ result = "https://hubdev.arcgis.com";
4993
+ }
4994
+ else if (portalUrl.match(/(www|\.maps)\.arcgis.com/)) {
4995
+ result = "https://hub.arcgis.com";
4996
+ }
4997
+ return result;
4998
+ }
4999
+
5000
+ /**
5001
+ * Given an org url, get the portal base url
5002
+ *
5003
+ * i.e. https://myorg.maps.arcgis.com will return https://www.arcgis.com
5004
+ *
5005
+ * @param orgUrl
5006
+ * @returns
5007
+ */
5008
+ function getPortalBaseFromOrgUrl(orgUrl) {
5009
+ var result = orgUrl;
5010
+ if (orgUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
5011
+ result = "https://qaext.arcgis.com";
5012
+ }
5013
+ else if (orgUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
5014
+ result = "https://devext.arcgis.com";
5015
+ }
5016
+ else {
5017
+ /* istanbul ignore else */
5018
+ if (orgUrl.match(/(www|\.maps)\.arcgis.com/)) {
5019
+ result = "https://www.arcgis.com";
5020
+ }
5021
+ }
5022
+ return result;
5023
+ }
5024
+
4979
5025
  var MAP_OR_FEATURE_SERVER_URL_REGEX = /\/(map|feature)server/i;
4980
5026
  /**
4981
5027
  *
@@ -8793,7 +8839,7 @@
8793
8839
  * Construct a the full url to a group thumbnail
8794
8840
  *
8795
8841
  * - If the group has a thumbnail, construct the full url
8796
- * - If the group is not public, append on the token
8842
+ * - If the group is not public, append on the token (if passed in)
8797
8843
  * @param portalUrl
8798
8844
  * @param group
8799
8845
  * @param token
@@ -9524,12 +9570,11 @@
9524
9570
  return __generator(this, function (_b) {
9525
9571
  expanded = expandContentFilter(filter);
9526
9572
  api = expandApi(options.api || "arcgis");
9527
- // map over the apis, depending on the type we issue the queries
9528
- // const searchPromises = apis.map((api) => {
9529
9573
  // Portal Search
9530
9574
  if (api.type === "arcgis") {
9531
9575
  so = serializeContentFilterForPortal(expanded);
9532
- // pass auth forward
9576
+ // if we have auth, pass it forward
9577
+ // otherwise set the portal property
9533
9578
  if (options.authentication) {
9534
9579
  so.authentication = options.authentication;
9535
9580
  }
@@ -9542,7 +9587,6 @@
9542
9587
  so.countSize = 200;
9543
9588
  }
9544
9589
  // copy over various options
9545
- // TODO: Dry this up - typscript makes this... inconvenient
9546
9590
  if (options.num) {
9547
9591
  so.num = options.num;
9548
9592
  }
@@ -9569,8 +9613,6 @@
9569
9613
  },
9570
9614
  });
9571
9615
  }
9572
- // });
9573
- // return for results
9574
9616
  return [2 /*return*/, searchPromise];
9575
9617
  });
9576
9618
  });
@@ -9584,14 +9626,29 @@
9584
9626
  * @returns
9585
9627
  */
9586
9628
  function searchPortal(searchOptions) {
9629
+ var _a;
9630
+ var portalUrl = ((_a = searchOptions.authentication) === null || _a === void 0 ? void 0 : _a.portal) || searchOptions.portal;
9631
+ var token;
9632
+ if (searchOptions.authentication) {
9633
+ var us = searchOptions.authentication;
9634
+ token = us.token;
9635
+ }
9636
+ var thumbnailify = function (content) {
9637
+ content.thumbnailUrl = getItemThumbnailUrl(content, portalUrl, token);
9638
+ return content;
9639
+ };
9587
9640
  return searchItems(searchOptions).then(function (resp) {
9588
9641
  var hasNext = resp.nextStart > -1;
9642
+ // convert items to IHubContent's
9589
9643
  var content = resp.results.map(itemToContent);
9644
+ // if we have a site, add those urls
9590
9645
  if (searchOptions.site) {
9591
9646
  content = content.map(function (entry) {
9592
9647
  return setContentSiteUrls(entry, searchOptions.site);
9593
9648
  });
9594
9649
  }
9650
+ // add thumbnailUrl
9651
+ content = content.map(thumbnailify);
9595
9652
  // convert aggregations into facets
9596
9653
  var facets = convertPortalResponseToFacets(resp);
9597
9654
  return {
@@ -9613,10 +9670,9 @@
9613
9670
  * @returns
9614
9671
  */
9615
9672
  function _searchGroups(filter, options) {
9616
- var _a;
9617
9673
  return __awaiter(this, void 0, void 0, function () {
9618
9674
  var expanded, api, so;
9619
- return __generator(this, function (_b) {
9675
+ return __generator(this, function (_a) {
9620
9676
  expanded = expandGroupFilter(filter);
9621
9677
  api = expandApi(options.api || "arcgis");
9622
9678
  if (api.type === "arcgis") {
@@ -9629,7 +9685,6 @@
9629
9685
  else {
9630
9686
  so.portal = api.url + "/sharing/rest";
9631
9687
  }
9632
- // TODO: Dry this up - typscript makes this... inconvenient
9633
9688
  if (options.num) {
9634
9689
  so.num = options.num;
9635
9690
  }
@@ -9639,10 +9694,6 @@
9639
9694
  if (options.sortOrder) {
9640
9695
  so.sortOrder = options.sortOrder;
9641
9696
  }
9642
- api.url + "/sharing/rest";
9643
- if ((_a = so.authentication) === null || _a === void 0 ? void 0 : _a.portal) {
9644
- so.authentication.portal;
9645
- }
9646
9697
  if (options.site) {
9647
9698
  so.site = cloneObject$1(options.site);
9648
9699
  }
@@ -9665,8 +9716,7 @@
9665
9716
  group.siteTeamUrl = searchOptions.site.item.url + "/teams/" + group.id + "/about";
9666
9717
  return group;
9667
9718
  };
9668
- var portalUrl = ((_a = searchOptions.authentication) === null || _a === void 0 ? void 0 : _a.portal) ||
9669
- "https://www.arcgis.com/sharing/rest";
9719
+ var portalUrl = ((_a = searchOptions.authentication) === null || _a === void 0 ? void 0 : _a.portal) || searchOptions.portal;
9670
9720
  var token;
9671
9721
  if (searchOptions.authentication) {
9672
9722
  var us = searchOptions.authentication;
@@ -10733,14 +10783,19 @@
10733
10783
  discussions: "/api/discussions/v1",
10734
10784
  };
10735
10785
  /**
10736
- * @internal
10786
+ * ArcGISContext
10787
+ *
10788
+ * Abstraction that holds a UserSession, along with
10789
+ * getters to streamline access to various platform
10790
+ * urls, and common constructs like IRequestOptions
10791
+ *
10737
10792
  * Thin class just used to enable getters
10738
10793
  *
10739
10794
  * This class should not be used by anything other than
10740
- * the ArcGISContext class
10795
+ * the ArcGISContextManager class
10741
10796
  */
10742
- var ArcGISContextState = /** @class */ (function () {
10743
- function ArcGISContextState(opts) {
10797
+ var ArcGISContext = /** @class */ (function () {
10798
+ function ArcGISContext(opts) {
10744
10799
  this._portalUrl = "https://www.arcgis.com";
10745
10800
  this.id = opts.id;
10746
10801
  this._portalUrl = opts.portalUrl;
@@ -10755,7 +10810,7 @@
10755
10810
  this._currentUser = opts.currentUser;
10756
10811
  }
10757
10812
  }
10758
- Object.defineProperty(ArcGISContextState.prototype, "session", {
10813
+ Object.defineProperty(ArcGISContext.prototype, "session", {
10759
10814
  /**
10760
10815
  * Return the UserSession if authenticated
10761
10816
  */
@@ -10765,7 +10820,7 @@
10765
10820
  enumerable: false,
10766
10821
  configurable: true
10767
10822
  });
10768
- Object.defineProperty(ArcGISContextState.prototype, "isAuthenticated", {
10823
+ Object.defineProperty(ArcGISContext.prototype, "isAuthenticated", {
10769
10824
  /**
10770
10825
  * Return boolean indicating if authenticatio is present
10771
10826
  */
@@ -10775,7 +10830,7 @@
10775
10830
  enumerable: false,
10776
10831
  configurable: true
10777
10832
  });
10778
- Object.defineProperty(ArcGISContextState.prototype, "userRequestOptions", {
10833
+ Object.defineProperty(ArcGISContext.prototype, "userRequestOptions", {
10779
10834
  /**
10780
10835
  * Return `IUserRequestOptions`, which is used for REST-JS
10781
10836
  * functions which require authentication information.
@@ -10793,7 +10848,7 @@
10793
10848
  enumerable: false,
10794
10849
  configurable: true
10795
10850
  });
10796
- Object.defineProperty(ArcGISContextState.prototype, "requestOptions", {
10851
+ Object.defineProperty(ArcGISContext.prototype, "requestOptions", {
10797
10852
  /**
10798
10853
  * Return `IRequestOptions`, which is used by REST-JS functions
10799
10854
  * which *may* use authentication information if provided.
@@ -10817,7 +10872,7 @@
10817
10872
  enumerable: false,
10818
10873
  configurable: true
10819
10874
  });
10820
- Object.defineProperty(ArcGISContextState.prototype, "hubRequestOptions", {
10875
+ Object.defineProperty(ArcGISContext.prototype, "hubRequestOptions", {
10821
10876
  /**
10822
10877
  * Return a `IHubRequestOptions` object
10823
10878
  */
@@ -10833,10 +10888,7 @@
10833
10888
  enumerable: false,
10834
10889
  configurable: true
10835
10890
  });
10836
- Object.defineProperty(ArcGISContextState.prototype, "portalUrl", {
10837
- // ==============================
10838
- // Getters / Computed Properties
10839
- // ==============================
10891
+ Object.defineProperty(ArcGISContext.prototype, "portalUrl", {
10840
10892
  /**
10841
10893
  * Return the portal url.
10842
10894
  *
@@ -10862,7 +10914,7 @@
10862
10914
  enumerable: false,
10863
10915
  configurable: true
10864
10916
  });
10865
- Object.defineProperty(ArcGISContextState.prototype, "sharingApiUrl", {
10917
+ Object.defineProperty(ArcGISContext.prototype, "sharingApiUrl", {
10866
10918
  /**
10867
10919
  * Returns the url to the sharing api
10868
10920
  * i.e. https://myorg.maps.arcgis.com/sharing/rest
@@ -10873,14 +10925,14 @@
10873
10925
  enumerable: false,
10874
10926
  configurable: true
10875
10927
  });
10876
- Object.defineProperty(ArcGISContextState.prototype, "hubUrl", {
10928
+ Object.defineProperty(ArcGISContext.prototype, "hubUrl", {
10877
10929
  get: function () {
10878
10930
  return this._hubUrl;
10879
10931
  },
10880
10932
  enumerable: false,
10881
10933
  configurable: true
10882
10934
  });
10883
- Object.defineProperty(ArcGISContextState.prototype, "isPortal", {
10935
+ Object.defineProperty(ArcGISContext.prototype, "isPortal", {
10884
10936
  /**
10885
10937
  * Returns boolean indicating if the backing system
10886
10938
  * is ArcGIS Enterprise (formerly ArcGIS Portal) or not
@@ -10893,7 +10945,7 @@
10893
10945
  enumerable: false,
10894
10946
  configurable: true
10895
10947
  });
10896
- Object.defineProperty(ArcGISContextState.prototype, "discussionsServiceUrl", {
10948
+ Object.defineProperty(ArcGISContext.prototype, "discussionsServiceUrl", {
10897
10949
  // Hub APIs
10898
10950
  // ----------
10899
10951
  // Discussions
@@ -10905,7 +10957,7 @@
10905
10957
  enumerable: false,
10906
10958
  configurable: true
10907
10959
  });
10908
- Object.defineProperty(ArcGISContextState.prototype, "hubSearchServiceUrl", {
10960
+ Object.defineProperty(ArcGISContext.prototype, "hubSearchServiceUrl", {
10909
10961
  // Hub Search
10910
10962
  get: function () {
10911
10963
  if (this._hubUrl) {
@@ -10915,7 +10967,7 @@
10915
10967
  enumerable: false,
10916
10968
  configurable: true
10917
10969
  });
10918
- Object.defineProperty(ArcGISContextState.prototype, "domainServiceUrl", {
10970
+ Object.defineProperty(ArcGISContext.prototype, "domainServiceUrl", {
10919
10971
  // Domain
10920
10972
  get: function () {
10921
10973
  if (this._hubUrl) {
@@ -10925,7 +10977,7 @@
10925
10977
  enumerable: false,
10926
10978
  configurable: true
10927
10979
  });
10928
- Object.defineProperty(ArcGISContextState.prototype, "eventsConfig", {
10980
+ Object.defineProperty(ArcGISContext.prototype, "eventsConfig", {
10929
10981
  // Events
10930
10982
  // returns `{serviceId: '3ef..', publicViewId: 'bc3...'}
10931
10983
  get: function () {
@@ -10936,7 +10988,7 @@
10936
10988
  enumerable: false,
10937
10989
  configurable: true
10938
10990
  });
10939
- Object.defineProperty(ArcGISContextState.prototype, "hubEnabled", {
10991
+ Object.defineProperty(ArcGISContext.prototype, "hubEnabled", {
10940
10992
  /**
10941
10993
  * Returns boolean indicating if the current user
10942
10994
  * belongs to an organization that has licensed
@@ -10948,7 +11000,7 @@
10948
11000
  enumerable: false,
10949
11001
  configurable: true
10950
11002
  });
10951
- Object.defineProperty(ArcGISContextState.prototype, "communityOrgId", {
11003
+ Object.defineProperty(ArcGISContext.prototype, "communityOrgId", {
10952
11004
  /**
10953
11005
  * Return Hub Community Org Id, if defined
10954
11006
  */
@@ -10960,7 +11012,7 @@
10960
11012
  enumerable: false,
10961
11013
  configurable: true
10962
11014
  });
10963
- Object.defineProperty(ArcGISContextState.prototype, "communityOrgHostname", {
11015
+ Object.defineProperty(ArcGISContext.prototype, "communityOrgHostname", {
10964
11016
  get: function () {
10965
11017
  if (this._portalSelf) {
10966
11018
  return getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.portalHostname");
@@ -10969,7 +11021,7 @@
10969
11021
  enumerable: false,
10970
11022
  configurable: true
10971
11023
  });
10972
- Object.defineProperty(ArcGISContextState.prototype, "communityOrgUrl", {
11024
+ Object.defineProperty(ArcGISContext.prototype, "communityOrgUrl", {
10973
11025
  get: function () {
10974
11026
  if (this.communityOrgHostname) {
10975
11027
  return "https://" + this.communityOrgHostname;
@@ -10978,7 +11030,7 @@
10978
11030
  enumerable: false,
10979
11031
  configurable: true
10980
11032
  });
10981
- Object.defineProperty(ArcGISContextState.prototype, "helperServices", {
11033
+ Object.defineProperty(ArcGISContext.prototype, "helperServices", {
10982
11034
  // Platform API service urls are all in helperServices
10983
11035
  // and not consistent to expose as urls
10984
11036
  get: function () {
@@ -10989,50 +11041,55 @@
10989
11041
  enumerable: false,
10990
11042
  configurable: true
10991
11043
  });
10992
- Object.defineProperty(ArcGISContextState.prototype, "currentUser", {
11044
+ Object.defineProperty(ArcGISContext.prototype, "currentUser", {
10993
11045
  get: function () {
10994
11046
  return this._currentUser;
10995
11047
  },
10996
11048
  enumerable: false,
10997
11049
  configurable: true
10998
11050
  });
10999
- Object.defineProperty(ArcGISContextState.prototype, "portal", {
11051
+ Object.defineProperty(ArcGISContext.prototype, "portal", {
11000
11052
  get: function () {
11001
11053
  return this._portalSelf;
11002
11054
  },
11003
11055
  enumerable: false,
11004
11056
  configurable: true
11005
11057
  });
11006
- return ArcGISContextState;
11058
+ return ArcGISContext;
11007
11059
  }());
11008
11060
 
11009
11061
  /**
11010
- * Application Context Object
11062
+ * ArcGIS Context Manager
11063
+ *
11064
+ * The manager exposes context (`IArcGISContext`), which combines a `UserSession` with
11065
+ * the `portal/self` and `user/self` responses to provide a central lookup for platform
11066
+ * information, api urls, and other useful properties for developers such as IRequestOptions
11067
+ * IUserRequestOptions, IHubRequestOptions etc.
11011
11068
  *
11012
- * Abstraction that combines a `UserSession` with
11013
- * the `portal/self` and `user/self` responses to
11014
- * provide a central lookup of platform information.
11069
+ * The context is exposed on gthe `.context` property, and as the authentication changes
11070
+ * the `.context` is re-created. This is done to allow web frameworks to watch for
11071
+ * changes on that single property, instead of having to leverage observers or events
11072
+ * for change detection.
11015
11073
  *
11016
11074
  * This is a work-in-progress, and will likely expand over time.
11017
11075
  *
11018
- * `ArcGISContext` is used in conjuction with the `arcgis-app-identity`
11019
- * component to orchestrate oAuth.
11020
11076
  */
11021
- var ArcGISContext = /** @class */ (function () {
11077
+ var ArcGISContextManager = /** @class */ (function () {
11022
11078
  /**
11023
- * Private constructor. Use `ArcGISContext.create(...)` to
11079
+ * Private constructor. Use `ArcGISContextManager.create(...)` to
11024
11080
  * instantiate an instance
11025
11081
  * @param opts
11026
11082
  */
11027
- function ArcGISContext(opts) {
11083
+ function ArcGISContextManager(opts) {
11028
11084
  this._portalUrl = "https://www.arcgis.com";
11029
- this._debug = false;
11085
+ this._logLevel = exports.Level.error;
11030
11086
  // Having a unique id makes debugging easier
11031
11087
  this.id = new Date().getTime();
11032
- if (opts.debug) {
11033
- this._debug = opts.debug;
11088
+ if (opts.logLevel) {
11089
+ this._logLevel = opts.logLevel;
11034
11090
  }
11035
- this.log("ArcGISContext:ctor: Creating " + this.id);
11091
+ Logger.setLogLevel(this._logLevel);
11092
+ Logger.debug("ArcGISContextManager:ctor: Creating " + this.id);
11036
11093
  if (opts.authentication) {
11037
11094
  this._authentication = opts.authentication;
11038
11095
  this._portalUrl = this._authentication.portal.replace("/sharing/rest", "");
@@ -11057,14 +11114,14 @@
11057
11114
  * @param opts
11058
11115
  * @returns
11059
11116
  */
11060
- ArcGISContext.create = function (opts) {
11117
+ ArcGISContextManager.create = function (opts) {
11061
11118
  if (opts === void 0) { opts = {}; }
11062
11119
  return __awaiter(this, void 0, void 0, function () {
11063
11120
  var ctx;
11064
11121
  return __generator(this, function (_a) {
11065
11122
  switch (_a.label) {
11066
11123
  case 0:
11067
- ctx = new ArcGISContext(opts);
11124
+ ctx = new ArcGISContextManager(opts);
11068
11125
  return [4 /*yield*/, ctx.initialize()];
11069
11126
  case 1:
11070
11127
  _a.sent();
@@ -11079,7 +11136,7 @@
11079
11136
  * application.
11080
11137
  * @param auth
11081
11138
  */
11082
- ArcGISContext.prototype.setAuthentication = function (auth) {
11139
+ ArcGISContextManager.prototype.setAuthentication = function (auth) {
11083
11140
  return __awaiter(this, void 0, void 0, function () {
11084
11141
  return __generator(this, function (_a) {
11085
11142
  switch (_a.label) {
@@ -11099,23 +11156,23 @@
11099
11156
  * called when a user signs out of an application, but
11100
11157
  * the application continues running
11101
11158
  */
11102
- ArcGISContext.prototype.clearAuthentication = function () {
11159
+ ArcGISContextManager.prototype.clearAuthentication = function () {
11103
11160
  // Reset the portalUrl from the org url to the base url
11104
11161
  // for ArcGIS Enterprise, we just leave the _portalUrl as-is
11105
- if (!this._state.isPortal) {
11162
+ if (!this._context.isPortal) {
11106
11163
  this._portalUrl = getPortalBaseFromOrgUrl(this._portalUrl);
11107
11164
  }
11108
11165
  // Clear the auth, portalSelf and currentUser props
11109
11166
  this._authentication = null;
11110
11167
  this._portalSelf = null;
11111
11168
  this._currentUser = null;
11112
- this._state = new ArcGISContextState({
11169
+ this._context = new ArcGISContext({
11113
11170
  id: this.id,
11114
11171
  portalUrl: this._portalUrl,
11115
11172
  hubUrl: this._hubUrl,
11116
11173
  });
11117
11174
  };
11118
- Object.defineProperty(ArcGISContext.prototype, "state", {
11175
+ Object.defineProperty(ArcGISContextManager.prototype, "context", {
11119
11176
  /**
11120
11177
  * Return a reference to the current state.
11121
11178
  * When `.setAuthentication()` or `.clearAuthenentication()` are
@@ -11123,34 +11180,23 @@
11123
11180
  * like React or Ember can detect changes.
11124
11181
  */
11125
11182
  get: function () {
11126
- return this._state;
11183
+ return this._context;
11127
11184
  },
11128
11185
  enumerable: false,
11129
11186
  configurable: true
11130
11187
  });
11131
- /**
11132
- * @internal
11133
- * Log debugging messages to the console
11134
- * @param message
11135
- */
11136
- ArcGISContext.prototype.log = function (message) {
11137
- if (this._debug) {
11138
- // tslint:disable-next-line:no-console
11139
- console.info(message);
11140
- }
11141
- };
11142
11188
  /**
11143
11189
  * If we have a UserSession, fetch portal/self and
11144
11190
  * store that along with current user
11145
11191
  */
11146
- ArcGISContext.prototype.initialize = function () {
11192
+ ArcGISContextManager.prototype.initialize = function () {
11147
11193
  return __awaiter(this, void 0, void 0, function () {
11148
11194
  var username, requests, _a, portal, user, ex_1, msg;
11149
11195
  return __generator(this, function (_b) {
11150
11196
  switch (_b.label) {
11151
11197
  case 0:
11152
11198
  if (!(this._authentication && (!this._portalSelf || !this._currentUser))) return [3 /*break*/, 4];
11153
- this.log("ArcGISContext-" + this.id + ": Initializing");
11199
+ Logger.debug("ArcGISContextManager-" + this.id + ": Initializing");
11154
11200
  username = this._authentication.username;
11155
11201
  requests = [
11156
11202
  getSelf({ authentication: this._authentication }),
@@ -11164,80 +11210,50 @@
11164
11210
  _a = _b.sent(), portal = _a[0], user = _a[1];
11165
11211
  this._portalSelf = portal;
11166
11212
  this._currentUser = user;
11213
+ Logger.debug("ArcGISContextManager-" + this.id + ": received portalSelf and currentUser");
11167
11214
  return [3 /*break*/, 4];
11168
11215
  case 3:
11169
11216
  ex_1 = _b.sent();
11170
- msg = "ArcGISContext could not fetch portal & user for \"" + this._authentication.username + "\" using " + this._authentication.portal + ".";
11217
+ msg = "ArcGISContextManager could not fetch portal & user for \"" + this._authentication.username + "\" using " + this._authentication.portal + ".";
11218
+ Logger.error(msg);
11171
11219
  // tslint:disable-next-line:no-console
11172
11220
  console.error(msg);
11173
11221
  throw ex_1;
11174
11222
  case 4:
11175
- // update the state
11176
- this._state = new ArcGISContextState(this.stateOpts);
11223
+ Logger.debug("ArcGISContextManager-" + this.id + ": updating context");
11224
+ // update the context
11225
+ this._context = new ArcGISContext(this.contextOpts);
11177
11226
  return [2 /*return*/];
11178
11227
  }
11179
11228
  });
11180
11229
  });
11181
11230
  };
11182
- Object.defineProperty(ArcGISContext.prototype, "stateOpts", {
11231
+ Object.defineProperty(ArcGISContextManager.prototype, "contextOpts", {
11232
+ /**
11233
+ * Getter to streamline the creation of updated Context instances
11234
+ */
11183
11235
  get: function () {
11184
- var stateOpts = {
11236
+ var contextOpts = {
11185
11237
  id: this.id,
11186
11238
  portalUrl: this._portalUrl,
11187
11239
  hubUrl: this._hubUrl,
11188
11240
  };
11189
11241
  if (this._authentication) {
11190
- stateOpts.authentication = this._authentication;
11242
+ contextOpts.authentication = this._authentication;
11191
11243
  }
11192
11244
  if (this._portalSelf) {
11193
- stateOpts.portalSelf = this._portalSelf;
11245
+ contextOpts.portalSelf = this._portalSelf;
11194
11246
  }
11195
11247
  if (this._currentUser) {
11196
- stateOpts.currentUser = this._currentUser;
11248
+ contextOpts.currentUser = this._currentUser;
11197
11249
  }
11198
- return stateOpts;
11250
+ return contextOpts;
11199
11251
  },
11200
11252
  enumerable: false,
11201
11253
  configurable: true
11202
11254
  });
11203
- return ArcGISContext;
11255
+ return ArcGISContextManager;
11204
11256
  }());
11205
- /**
11206
- * Cross-walk from a portalUrl to the corresponding Hub.
11207
- *
11208
- * If the passed url is not recognized, then this will return `undefined`
11209
- * @param portalUrl
11210
- * @returns
11211
- */
11212
- function getHubApiFromPortalUrl(portalUrl) {
11213
- var result;
11214
- if (portalUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
11215
- result = "https://hubqa.arcgis.com";
11216
- }
11217
- else if (portalUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
11218
- result = "https://hubdev.arcgis.com";
11219
- }
11220
- else if (portalUrl.match(/(www|\.maps)\.arcgis.com/)) {
11221
- result = "https://hub.arcgis.com";
11222
- }
11223
- return result;
11224
- }
11225
- function getPortalBaseFromOrgUrl(orgUrl) {
11226
- var result;
11227
- if (orgUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
11228
- result = "https://qaext.arcgis.com";
11229
- }
11230
- else if (orgUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
11231
- result = "https://devext.arcgis.com";
11232
- }
11233
- else {
11234
- /* istanbul ignore else */
11235
- if (orgUrl.match(/(www|\.maps)\.arcgis.com/)) {
11236
- result = "https://www.arcgis.com";
11237
- }
11238
- }
11239
- return result;
11240
- }
11241
11257
 
11242
11258
  /* Copyright (c) 2018-2020 Environmental Systems Research Institute, Inc.
11243
11259
  * Apache-2.0 */
@@ -11499,6 +11515,7 @@
11499
11515
  }
11500
11516
 
11501
11517
  exports.ArcGISContext = ArcGISContext;
11518
+ exports.ArcGISContextManager = ArcGISContextManager;
11502
11519
  exports.GLOBAL_EXTENT = GLOBAL_EXTENT;
11503
11520
  exports.HUB_CDN_URLMAP = HUB_CDN_URLMAP;
11504
11521
  exports.HUB_LOCALES = HUB_LOCALES;
@@ -11627,6 +11644,7 @@
11627
11644
  exports.getFamily = getFamily;
11628
11645
  exports.getGeographicOrgExtent = getGeographicOrgExtent;
11629
11646
  exports.getGroupThumbnailUrl = getGroupThumbnailUrl;
11647
+ exports.getHubApiFromPortalUrl = getHubApiFromPortalUrl;
11630
11648
  exports.getHubApiUrl = getHubApiUrl;
11631
11649
  exports.getHubApiUrlFromPortal = getHubApiUrlFromPortal;
11632
11650
  exports.getHubLocaleAssetUrl = getHubLocaleAssetUrl;
@@ -11647,6 +11665,7 @@
11647
11665
  exports.getNextFunction = getNextFunction;
11648
11666
  exports.getOrgExtentAsBBox = getOrgExtentAsBBox;
11649
11667
  exports.getPortalApiUrl = getPortalApiUrl;
11668
+ exports.getPortalBaseFromOrgUrl = getPortalBaseFromOrgUrl;
11650
11669
  exports.getPortalUrl = getPortalUrl;
11651
11670
  exports.getProp = getProp;
11652
11671
  exports.getProps = getProps;