@esri/hub-common 9.13.0 → 9.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * @esri/hub-common - v9.12.0 - Thu Jan 20 2022 20:07:02 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/hub-common - v9.13.0 - Fri Jan 21 2022 23:22:52 GMT+0000 (Coordinated Universal Time)
3
3
  * Copyright (c) 2022 Environmental Systems Research Institute, Inc.
4
4
  * Apache-2.0
5
5
  */
@@ -10733,117 +10733,29 @@
10733
10733
  discussions: "/api/discussions/v1",
10734
10734
  };
10735
10735
  /**
10736
- * Application Context Object
10737
- *
10738
- * Abstraction that combines a `UserSession` with
10739
- * the `portal/self` and `user/self` responses to
10740
- * provide a central lookup of platform information.
10741
- *
10742
- * This is a work-in-progress, and will likely expand over time.
10736
+ * @internal
10737
+ * Thin class just used to enable getters
10743
10738
  *
10744
- * `ArcGISContext` is used in conjuction with the `arcgis-app-identity`
10745
- * component to orchestrate oAuth.
10739
+ * This class should not be used by anything other than
10740
+ * the ArcGISContext class
10746
10741
  */
10747
- var ArcGISContext = /** @class */ (function () {
10748
- /**
10749
- * Private constructor. Use `ArcGISContext.create(...)` to
10750
- * instantiate an instance
10751
- * @param opts
10752
- */
10753
- function ArcGISContext(opts) {
10742
+ var ArcGISContextState = /** @class */ (function () {
10743
+ function ArcGISContextState(opts) {
10754
10744
  this._portalUrl = "https://www.arcgis.com";
10755
- this._debug = false;
10756
- // Having a unique id makes debugging easier
10757
- this.id = new Date().getTime();
10758
- if (opts.debug) {
10759
- this._debug = opts.debug;
10760
- }
10761
- this.log("ArcGISContext:ctor: Creating " + this.id);
10745
+ this.id = opts.id;
10746
+ this._portalUrl = opts.portalUrl;
10747
+ this._hubUrl = opts.hubUrl;
10762
10748
  if (opts.authentication) {
10763
10749
  this._authentication = opts.authentication;
10764
- this._portalUrl = this._authentication.portal.replace("/sharing/rest", "");
10765
- this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
10766
10750
  }
10767
- else if (opts.portalUrl) {
10768
- this._portalUrl = opts.portalUrl;
10769
- this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
10751
+ if (opts.portalSelf) {
10752
+ this._portalSelf = opts.portalSelf;
10770
10753
  }
10771
- else {
10772
- this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
10754
+ if (opts.currentUser) {
10755
+ this._currentUser = opts.currentUser;
10773
10756
  }
10774
10757
  }
10775
- /**
10776
- * Static async Factory
10777
- * @param opts
10778
- * @returns
10779
- */
10780
- ArcGISContext.create = function (opts) {
10781
- if (opts === void 0) { opts = {}; }
10782
- return __awaiter(this, void 0, void 0, function () {
10783
- var ctx;
10784
- return __generator(this, function (_a) {
10785
- switch (_a.label) {
10786
- case 0:
10787
- ctx = new ArcGISContext(opts);
10788
- return [4 /*yield*/, ctx.initialize()];
10789
- case 1:
10790
- _a.sent();
10791
- return [2 /*return*/, ctx];
10792
- }
10793
- });
10794
- });
10795
- };
10796
- /**
10797
- * If we have a UserSession, fetch portal/self and
10798
- * store that along with current user
10799
- */
10800
- ArcGISContext.prototype.initialize = function () {
10801
- return __awaiter(this, void 0, void 0, function () {
10802
- var ps;
10803
- return __generator(this, function (_a) {
10804
- switch (_a.label) {
10805
- case 0:
10806
- if (!this._authentication) return [3 /*break*/, 2];
10807
- this.log("ArcGISContext-" + this.id + ": Initializing");
10808
- return [4 /*yield*/, getSelf({ authentication: this._authentication })];
10809
- case 1:
10810
- ps = _a.sent();
10811
- this._portalSelf = ps;
10812
- this._currentUser = ps.user;
10813
- _a.label = 2;
10814
- case 2: return [2 /*return*/];
10815
- }
10816
- });
10817
- });
10818
- };
10819
- // Set authentication after the instance is up and running
10820
- ArcGISContext.prototype.setAuthentication = function (auth) {
10821
- return __awaiter(this, void 0, void 0, function () {
10822
- return __generator(this, function (_a) {
10823
- switch (_a.label) {
10824
- case 0:
10825
- this._authentication = auth;
10826
- this._portalUrl = auth.portal.replace("/sharing/rest", "");
10827
- return [4 /*yield*/, this.initialize()];
10828
- case 1:
10829
- _a.sent();
10830
- return [2 /*return*/];
10831
- }
10832
- });
10833
- });
10834
- };
10835
- /**
10836
- * @internal
10837
- * Log debugging messages to the console
10838
- * @param message
10839
- */
10840
- ArcGISContext.prototype.log = function (message) {
10841
- if (this._debug) {
10842
- // tslint:disable-next-line:no-console
10843
- console.info(message);
10844
- }
10845
- };
10846
- Object.defineProperty(ArcGISContext.prototype, "session", {
10758
+ Object.defineProperty(ArcGISContextState.prototype, "session", {
10847
10759
  /**
10848
10760
  * Return the UserSession if authenticated
10849
10761
  */
@@ -10853,7 +10765,7 @@
10853
10765
  enumerable: false,
10854
10766
  configurable: true
10855
10767
  });
10856
- Object.defineProperty(ArcGISContext.prototype, "isAuthenticated", {
10768
+ Object.defineProperty(ArcGISContextState.prototype, "isAuthenticated", {
10857
10769
  /**
10858
10770
  * Return boolean indicating if authenticatio is present
10859
10771
  */
@@ -10863,7 +10775,7 @@
10863
10775
  enumerable: false,
10864
10776
  configurable: true
10865
10777
  });
10866
- Object.defineProperty(ArcGISContext.prototype, "userRequestOptions", {
10778
+ Object.defineProperty(ArcGISContextState.prototype, "userRequestOptions", {
10867
10779
  /**
10868
10780
  * Return `IUserRequestOptions`, which is used for REST-JS
10869
10781
  * functions which require authentication information.
@@ -10881,7 +10793,7 @@
10881
10793
  enumerable: false,
10882
10794
  configurable: true
10883
10795
  });
10884
- Object.defineProperty(ArcGISContext.prototype, "requestOptions", {
10796
+ Object.defineProperty(ArcGISContextState.prototype, "requestOptions", {
10885
10797
  /**
10886
10798
  * Return `IRequestOptions`, which is used by REST-JS functions
10887
10799
  * which *may* use authentication information if provided.
@@ -10905,7 +10817,7 @@
10905
10817
  enumerable: false,
10906
10818
  configurable: true
10907
10819
  });
10908
- Object.defineProperty(ArcGISContext.prototype, "hubRequestOptions", {
10820
+ Object.defineProperty(ArcGISContextState.prototype, "hubRequestOptions", {
10909
10821
  /**
10910
10822
  * Return a `IHubRequestOptions` object
10911
10823
  */
@@ -10921,7 +10833,7 @@
10921
10833
  enumerable: false,
10922
10834
  configurable: true
10923
10835
  });
10924
- Object.defineProperty(ArcGISContext.prototype, "portalUrl", {
10836
+ Object.defineProperty(ArcGISContextState.prototype, "portalUrl", {
10925
10837
  // ==============================
10926
10838
  // Getters / Computed Properties
10927
10839
  // ==============================
@@ -10950,7 +10862,7 @@
10950
10862
  enumerable: false,
10951
10863
  configurable: true
10952
10864
  });
10953
- Object.defineProperty(ArcGISContext.prototype, "sharingApiUrl", {
10865
+ Object.defineProperty(ArcGISContextState.prototype, "sharingApiUrl", {
10954
10866
  /**
10955
10867
  * Returns the url to the sharing api
10956
10868
  * i.e. https://myorg.maps.arcgis.com/sharing/rest
@@ -10961,14 +10873,14 @@
10961
10873
  enumerable: false,
10962
10874
  configurable: true
10963
10875
  });
10964
- Object.defineProperty(ArcGISContext.prototype, "hubUrl", {
10876
+ Object.defineProperty(ArcGISContextState.prototype, "hubUrl", {
10965
10877
  get: function () {
10966
10878
  return this._hubUrl;
10967
10879
  },
10968
10880
  enumerable: false,
10969
10881
  configurable: true
10970
10882
  });
10971
- Object.defineProperty(ArcGISContext.prototype, "isPortal", {
10883
+ Object.defineProperty(ArcGISContextState.prototype, "isPortal", {
10972
10884
  /**
10973
10885
  * Returns boolean indicating if the backing system
10974
10886
  * is ArcGIS Enterprise (formerly ArcGIS Portal) or not
@@ -10981,7 +10893,7 @@
10981
10893
  enumerable: false,
10982
10894
  configurable: true
10983
10895
  });
10984
- Object.defineProperty(ArcGISContext.prototype, "discussionsServiceUrl", {
10896
+ Object.defineProperty(ArcGISContextState.prototype, "discussionsServiceUrl", {
10985
10897
  // Hub APIs
10986
10898
  // ----------
10987
10899
  // Discussions
@@ -10993,7 +10905,7 @@
10993
10905
  enumerable: false,
10994
10906
  configurable: true
10995
10907
  });
10996
- Object.defineProperty(ArcGISContext.prototype, "hubSearchServiceUrl", {
10908
+ Object.defineProperty(ArcGISContextState.prototype, "hubSearchServiceUrl", {
10997
10909
  // Hub Search
10998
10910
  get: function () {
10999
10911
  if (this._hubUrl) {
@@ -11003,7 +10915,7 @@
11003
10915
  enumerable: false,
11004
10916
  configurable: true
11005
10917
  });
11006
- Object.defineProperty(ArcGISContext.prototype, "domainServiceUrl", {
10918
+ Object.defineProperty(ArcGISContextState.prototype, "domainServiceUrl", {
11007
10919
  // Domain
11008
10920
  get: function () {
11009
10921
  if (this._hubUrl) {
@@ -11013,7 +10925,7 @@
11013
10925
  enumerable: false,
11014
10926
  configurable: true
11015
10927
  });
11016
- Object.defineProperty(ArcGISContext.prototype, "eventsConfig", {
10928
+ Object.defineProperty(ArcGISContextState.prototype, "eventsConfig", {
11017
10929
  // Events
11018
10930
  // returns `{serviceId: '3ef..', publicViewId: 'bc3...'}
11019
10931
  get: function () {
@@ -11024,7 +10936,7 @@
11024
10936
  enumerable: false,
11025
10937
  configurable: true
11026
10938
  });
11027
- Object.defineProperty(ArcGISContext.prototype, "hubEnabled", {
10939
+ Object.defineProperty(ArcGISContextState.prototype, "hubEnabled", {
11028
10940
  /**
11029
10941
  * Returns boolean indicating if the current user
11030
10942
  * belongs to an organization that has licensed
@@ -11036,7 +10948,7 @@
11036
10948
  enumerable: false,
11037
10949
  configurable: true
11038
10950
  });
11039
- Object.defineProperty(ArcGISContext.prototype, "communityOrgId", {
10951
+ Object.defineProperty(ArcGISContextState.prototype, "communityOrgId", {
11040
10952
  /**
11041
10953
  * Return Hub Community Org Id, if defined
11042
10954
  */
@@ -11048,7 +10960,7 @@
11048
10960
  enumerable: false,
11049
10961
  configurable: true
11050
10962
  });
11051
- Object.defineProperty(ArcGISContext.prototype, "communityOrgHostname", {
10963
+ Object.defineProperty(ArcGISContextState.prototype, "communityOrgHostname", {
11052
10964
  get: function () {
11053
10965
  if (this._portalSelf) {
11054
10966
  return getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.portalHostname");
@@ -11057,7 +10969,7 @@
11057
10969
  enumerable: false,
11058
10970
  configurable: true
11059
10971
  });
11060
- Object.defineProperty(ArcGISContext.prototype, "communityOrgUrl", {
10972
+ Object.defineProperty(ArcGISContextState.prototype, "communityOrgUrl", {
11061
10973
  get: function () {
11062
10974
  if (this.communityOrgHostname) {
11063
10975
  return "https://" + this.communityOrgHostname;
@@ -11066,7 +10978,7 @@
11066
10978
  enumerable: false,
11067
10979
  configurable: true
11068
10980
  });
11069
- Object.defineProperty(ArcGISContext.prototype, "helperServices", {
10981
+ Object.defineProperty(ArcGISContextState.prototype, "helperServices", {
11070
10982
  // Platform API service urls are all in helperServices
11071
10983
  // and not consistent to expose as urls
11072
10984
  get: function () {
@@ -11077,20 +10989,189 @@
11077
10989
  enumerable: false,
11078
10990
  configurable: true
11079
10991
  });
11080
- Object.defineProperty(ArcGISContext.prototype, "currentUser", {
10992
+ Object.defineProperty(ArcGISContextState.prototype, "currentUser", {
11081
10993
  get: function () {
11082
10994
  return this._currentUser;
11083
10995
  },
11084
10996
  enumerable: false,
11085
10997
  configurable: true
11086
10998
  });
11087
- Object.defineProperty(ArcGISContext.prototype, "portal", {
10999
+ Object.defineProperty(ArcGISContextState.prototype, "portal", {
11088
11000
  get: function () {
11089
11001
  return this._portalSelf;
11090
11002
  },
11091
11003
  enumerable: false,
11092
11004
  configurable: true
11093
11005
  });
11006
+ return ArcGISContextState;
11007
+ }());
11008
+
11009
+ /**
11010
+ * Application Context Object
11011
+ *
11012
+ * Abstraction that combines a `UserSession` with
11013
+ * the `portal/self` and `user/self` responses to
11014
+ * provide a central lookup of platform information.
11015
+ *
11016
+ * This is a work-in-progress, and will likely expand over time.
11017
+ *
11018
+ * `ArcGISContext` is used in conjuction with the `arcgis-app-identity`
11019
+ * component to orchestrate oAuth.
11020
+ */
11021
+ var ArcGISContext = /** @class */ (function () {
11022
+ /**
11023
+ * Private constructor. Use `ArcGISContext.create(...)` to
11024
+ * instantiate an instance
11025
+ * @param opts
11026
+ */
11027
+ function ArcGISContext(opts) {
11028
+ this._portalUrl = "https://www.arcgis.com";
11029
+ this._debug = false;
11030
+ // Having a unique id makes debugging easier
11031
+ this.id = new Date().getTime();
11032
+ if (opts.debug) {
11033
+ this._debug = opts.debug;
11034
+ }
11035
+ this.log("ArcGISContext:ctor: Creating " + this.id);
11036
+ if (opts.authentication) {
11037
+ this._authentication = opts.authentication;
11038
+ this._portalUrl = this._authentication.portal.replace("/sharing/rest", "");
11039
+ this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
11040
+ }
11041
+ else if (opts.portalUrl) {
11042
+ this._portalUrl = opts.portalUrl;
11043
+ this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
11044
+ }
11045
+ else {
11046
+ this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
11047
+ }
11048
+ }
11049
+ /**
11050
+ * Static async Factory
11051
+ * @param opts
11052
+ * @returns
11053
+ */
11054
+ ArcGISContext.create = function (opts) {
11055
+ if (opts === void 0) { opts = {}; }
11056
+ return __awaiter(this, void 0, void 0, function () {
11057
+ var ctx;
11058
+ return __generator(this, function (_a) {
11059
+ switch (_a.label) {
11060
+ case 0:
11061
+ ctx = new ArcGISContext(opts);
11062
+ return [4 /*yield*/, ctx.initialize()];
11063
+ case 1:
11064
+ _a.sent();
11065
+ return [2 /*return*/, ctx];
11066
+ }
11067
+ });
11068
+ });
11069
+ };
11070
+ /**
11071
+ * If we have a UserSession, fetch portal/self and
11072
+ * store that along with current user
11073
+ */
11074
+ ArcGISContext.prototype.initialize = function () {
11075
+ return __awaiter(this, void 0, void 0, function () {
11076
+ var stateOpts, ps;
11077
+ return __generator(this, function (_a) {
11078
+ switch (_a.label) {
11079
+ case 0:
11080
+ stateOpts = {
11081
+ id: this.id,
11082
+ portalUrl: this._portalUrl,
11083
+ hubUrl: this._hubUrl,
11084
+ };
11085
+ if (!this._authentication) return [3 /*break*/, 2];
11086
+ this.log("ArcGISContext-" + this.id + ": Initializing");
11087
+ return [4 /*yield*/, getSelf({ authentication: this._authentication })];
11088
+ case 1:
11089
+ ps = _a.sent();
11090
+ this._portalSelf = ps;
11091
+ this._currentUser = ps.user;
11092
+ stateOpts = {
11093
+ id: this.id,
11094
+ portalUrl: this._portalUrl,
11095
+ hubUrl: this._hubUrl,
11096
+ portalSelf: this._portalSelf,
11097
+ currentUser: this._currentUser,
11098
+ authentication: this._authentication,
11099
+ };
11100
+ _a.label = 2;
11101
+ case 2:
11102
+ // update the state
11103
+ this._state = new ArcGISContextState(stateOpts);
11104
+ return [2 /*return*/];
11105
+ }
11106
+ });
11107
+ });
11108
+ };
11109
+ /**
11110
+ * Set the Authentication (UserSession) for the context.
11111
+ * This should be called when a user signs into a running
11112
+ * application.
11113
+ * @param auth
11114
+ */
11115
+ ArcGISContext.prototype.setAuthentication = function (auth) {
11116
+ return __awaiter(this, void 0, void 0, function () {
11117
+ return __generator(this, function (_a) {
11118
+ switch (_a.label) {
11119
+ case 0:
11120
+ this._authentication = auth;
11121
+ this._portalUrl = auth.portal.replace("/sharing/rest", "");
11122
+ return [4 /*yield*/, this.initialize()];
11123
+ case 1:
11124
+ _a.sent();
11125
+ return [2 /*return*/];
11126
+ }
11127
+ });
11128
+ });
11129
+ };
11130
+ /**
11131
+ * Clear the Authentication (UserSession). This should be
11132
+ * called when a user signs out of an application, but
11133
+ * the application continues running
11134
+ */
11135
+ ArcGISContext.prototype.clearAuthentication = function () {
11136
+ // Reset the portalUrl from the org url to the base url
11137
+ // for ArcGIS Enterprise, we just leave the _portalUrl as-is
11138
+ if (!this._state.isPortal) {
11139
+ this._portalUrl = getPortalBaseFromOrgUrl(this._portalUrl);
11140
+ }
11141
+ // Clear the auth, portalSelf and currentUser props
11142
+ this._authentication = null;
11143
+ this._portalSelf = null;
11144
+ this._currentUser = null;
11145
+ this._state = new ArcGISContextState({
11146
+ id: this.id,
11147
+ portalUrl: this._portalUrl,
11148
+ hubUrl: this._hubUrl,
11149
+ });
11150
+ };
11151
+ Object.defineProperty(ArcGISContext.prototype, "state", {
11152
+ /**
11153
+ * Return a reference to the current state.
11154
+ * When `.setAuthentication()` or `.clearAuthenentication()` are
11155
+ * called, the state will be re-created. This is done so frameworks
11156
+ * like React or Ember can detect changes.
11157
+ */
11158
+ get: function () {
11159
+ return this._state;
11160
+ },
11161
+ enumerable: false,
11162
+ configurable: true
11163
+ });
11164
+ /**
11165
+ * @internal
11166
+ * Log debugging messages to the console
11167
+ * @param message
11168
+ */
11169
+ ArcGISContext.prototype.log = function (message) {
11170
+ if (this._debug) {
11171
+ // tslint:disable-next-line:no-console
11172
+ console.info(message);
11173
+ }
11174
+ };
11094
11175
  return ArcGISContext;
11095
11176
  }());
11096
11177
  /**
@@ -11113,6 +11194,22 @@
11113
11194
  }
11114
11195
  return result;
11115
11196
  }
11197
+ function getPortalBaseFromOrgUrl(orgUrl) {
11198
+ var result;
11199
+ if (orgUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
11200
+ result = "https://qaext.arcgis.com";
11201
+ }
11202
+ else if (orgUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
11203
+ result = "https://devext.arcgis.com";
11204
+ }
11205
+ else {
11206
+ /* istanbul ignore else */
11207
+ if (orgUrl.match(/(www|\.maps)\.arcgis.com/)) {
11208
+ result = "https://www.arcgis.com";
11209
+ }
11210
+ }
11211
+ return result;
11212
+ }
11116
11213
 
11117
11214
  /* Copyright (c) 2018-2020 Environmental Systems Research Institute, Inc.
11118
11215
  * Apache-2.0 */