@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,14 +1,5 @@
1
1
  import { getSelf } from "@esri/arcgis-rest-portal";
2
- import { getProp, getWithDefault } from ".";
3
- /**
4
- * Hash of Hub API end points so updates
5
- * are centralized
6
- */
7
- const hubApiEndpoints = {
8
- domains: "/api/v3/domains",
9
- search: "/api/v3/datasets",
10
- discussions: "/api/discussions/v1",
11
- };
2
+ import { ArcGISContextState, } from "./ArcGISContextState";
12
3
  /**
13
4
  * Application Context Object
14
5
  *
@@ -64,19 +55,69 @@ export class ArcGISContext {
64
55
  * store that along with current user
65
56
  */
66
57
  async initialize() {
58
+ let stateOpts = {
59
+ id: this.id,
60
+ portalUrl: this._portalUrl,
61
+ hubUrl: this._hubUrl,
62
+ };
67
63
  if (this._authentication) {
68
64
  this.log(`ArcGISContext-${this.id}: Initializing`);
69
65
  const ps = await getSelf({ authentication: this._authentication });
70
66
  this._portalSelf = ps;
71
67
  this._currentUser = ps.user;
68
+ stateOpts = {
69
+ id: this.id,
70
+ portalUrl: this._portalUrl,
71
+ hubUrl: this._hubUrl,
72
+ portalSelf: this._portalSelf,
73
+ currentUser: this._currentUser,
74
+ authentication: this._authentication,
75
+ };
72
76
  }
77
+ // update the state
78
+ this._state = new ArcGISContextState(stateOpts);
73
79
  }
74
- // Set authentication after the instance is up and running
80
+ /**
81
+ * Set the Authentication (UserSession) for the context.
82
+ * This should be called when a user signs into a running
83
+ * application.
84
+ * @param auth
85
+ */
75
86
  async setAuthentication(auth) {
76
87
  this._authentication = auth;
77
88
  this._portalUrl = auth.portal.replace("/sharing/rest", "");
78
89
  await this.initialize();
79
90
  }
91
+ /**
92
+ * Clear the Authentication (UserSession). This should be
93
+ * called when a user signs out of an application, but
94
+ * the application continues running
95
+ */
96
+ clearAuthentication() {
97
+ // Reset the portalUrl from the org url to the base url
98
+ // for ArcGIS Enterprise, we just leave the _portalUrl as-is
99
+ if (!this._state.isPortal) {
100
+ this._portalUrl = getPortalBaseFromOrgUrl(this._portalUrl);
101
+ }
102
+ // Clear the auth, portalSelf and currentUser props
103
+ this._authentication = null;
104
+ this._portalSelf = null;
105
+ this._currentUser = null;
106
+ this._state = new ArcGISContextState({
107
+ id: this.id,
108
+ portalUrl: this._portalUrl,
109
+ hubUrl: this._hubUrl,
110
+ });
111
+ }
112
+ /**
113
+ * Return a reference to the current state.
114
+ * When `.setAuthentication()` or `.clearAuthenentication()` are
115
+ * called, the state will be re-created. This is done so frameworks
116
+ * like React or Ember can detect changes.
117
+ */
118
+ get state() {
119
+ return this._state;
120
+ }
80
121
  /**
81
122
  * @internal
82
123
  * Log debugging messages to the console
@@ -88,174 +129,6 @@ export class ArcGISContext {
88
129
  console.info(message);
89
130
  }
90
131
  }
91
- /**
92
- * Return the UserSession if authenticated
93
- */
94
- get session() {
95
- return this._authentication;
96
- }
97
- /**
98
- * Return boolean indicating if authenticatio is present
99
- */
100
- get isAuthenticated() {
101
- return !!this._authentication;
102
- }
103
- /**
104
- * Return `IUserRequestOptions`, which is used for REST-JS
105
- * functions which require authentication information.
106
- *
107
- * If context is not authenticated, this function will throw
108
- */
109
- get userRequestOptions() {
110
- if (this.isAuthenticated) {
111
- return {
112
- authentication: this._authentication,
113
- portal: this.sharingApiUrl,
114
- };
115
- }
116
- }
117
- /**
118
- * Return `IRequestOptions`, which is used by REST-JS functions
119
- * which *may* use authentication information if provided.
120
- *
121
- * If context is not authenticated, this function just returns
122
- * the `portal` property, which informs REST-JS what Sharing API
123
- * instance to use (i.e. AGO, Enterprise etc)
124
- */
125
- get requestOptions() {
126
- let ro = {
127
- portal: this.sharingApiUrl,
128
- };
129
- if (this.isAuthenticated) {
130
- ro = {
131
- authentication: this._authentication,
132
- portal: this.sharingApiUrl,
133
- };
134
- }
135
- return ro;
136
- }
137
- /**
138
- * Return a `IHubRequestOptions` object
139
- */
140
- get hubRequestOptions() {
141
- // We may add more logic around what is returned in some corner cases
142
- return {
143
- authentication: this.session,
144
- isPortal: this.isPortal,
145
- portalSelf: this.portal,
146
- hubApiUrl: this.hubUrl,
147
- };
148
- }
149
- // ==============================
150
- // Getters / Computed Properties
151
- // ==============================
152
- /**
153
- * Return the portal url.
154
- *
155
- * If authenticated @ ArcGIS Online, it will return
156
- * the https://org.env.arcgis.com
157
- *
158
- * If authenticated @ ArcGIS Enterprise, it will return
159
- * https://portalHostname, which includes the web adaptor
160
- */
161
- get portalUrl() {
162
- if (this.isAuthenticated) {
163
- if (this.isPortal) {
164
- return `https://${this._portalSelf.portalHostname}`;
165
- }
166
- else {
167
- return `https://${this._portalSelf.urlKey}.${this._portalSelf.customBaseUrl}`;
168
- }
169
- }
170
- else {
171
- return this._portalUrl;
172
- }
173
- }
174
- /**
175
- * Returns the url to the sharing api
176
- * i.e. https://myorg.maps.arcgis.com/sharing/rest
177
- */
178
- get sharingApiUrl() {
179
- return `${this.portalUrl}/sharing/rest`;
180
- }
181
- get hubUrl() {
182
- return this._hubUrl;
183
- }
184
- /**
185
- * Returns boolean indicating if the backing system
186
- * is ArcGIS Enterprise (formerly ArcGIS Portal) or not
187
- */
188
- get isPortal() {
189
- return this._portalSelf
190
- ? this._portalSelf.isPortal
191
- : this._portalUrl.indexOf("arcgis.com") === -1;
192
- }
193
- // Hub APIs
194
- // ----------
195
- // Discussions
196
- get discussionsServiceUrl() {
197
- if (this._hubUrl) {
198
- return `${this._hubUrl}${hubApiEndpoints.discussions}`;
199
- }
200
- }
201
- // Hub Search
202
- get hubSearchServiceUrl() {
203
- if (this._hubUrl) {
204
- return `${this._hubUrl}${hubApiEndpoints.search}`;
205
- }
206
- }
207
- // Domain
208
- get domainServiceUrl() {
209
- if (this._hubUrl) {
210
- return `${this._hubUrl}${hubApiEndpoints.domains}`;
211
- }
212
- }
213
- // Events
214
- // returns `{serviceId: '3ef..', publicViewId: 'bc3...'}
215
- get eventsConfig() {
216
- if (this._portalSelf) {
217
- return getProp(this._portalSelf, "portalProperties.hub.settings.events");
218
- }
219
- }
220
- /**
221
- * Returns boolean indicating if the current user
222
- * belongs to an organization that has licensed
223
- * ArcGIS Hub
224
- */
225
- get hubEnabled() {
226
- return getWithDefault(this._portalSelf, "portalProperties.hub.enabled", false);
227
- }
228
- /**
229
- * Return Hub Community Org Id, if defined
230
- */
231
- get communityOrgId() {
232
- if (this._portalSelf) {
233
- return getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.orgId");
234
- }
235
- }
236
- get communityOrgHostname() {
237
- if (this._portalSelf) {
238
- return getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.portalHostname");
239
- }
240
- }
241
- get communityOrgUrl() {
242
- if (this.communityOrgHostname) {
243
- return `https://${this.communityOrgHostname}`;
244
- }
245
- }
246
- // Platform API service urls are all in helperServices
247
- // and not consistent to expose as urls
248
- get helperServices() {
249
- if (this._portalSelf) {
250
- return this._portalSelf.helperServices;
251
- }
252
- }
253
- get currentUser() {
254
- return this._currentUser;
255
- }
256
- get portal() {
257
- return this._portalSelf;
258
- }
259
132
  }
260
133
  /**
261
134
  * Cross-walk from a portalUrl to the corresponding Hub.
@@ -277,4 +150,20 @@ function getHubApiFromPortalUrl(portalUrl) {
277
150
  }
278
151
  return result;
279
152
  }
153
+ function getPortalBaseFromOrgUrl(orgUrl) {
154
+ let result;
155
+ if (orgUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
156
+ result = "https://qaext.arcgis.com";
157
+ }
158
+ else if (orgUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
159
+ result = "https://devext.arcgis.com";
160
+ }
161
+ else {
162
+ /* istanbul ignore else */
163
+ if (orgUrl.match(/(www|\.maps)\.arcgis.com/)) {
164
+ result = "https://www.arcgis.com";
165
+ }
166
+ }
167
+ return result;
168
+ }
280
169
  //# sourceMappingURL=ArcGISContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ArcGISContext.js","sourceRoot":"","sources":["../../src/ArcGISContext.ts"],"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;SACrB,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACK,GAAG,CAAC,OAAe;QACzB,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,sCAAsC;YACtC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACvB;IACH,CAAC;CACF;AAED;;;;;;GAMG;AACH,SAAS,sBAAsB,CAAC,SAAiB;IAC/C,IAAI,MAAM,CAAC;IAEX,IAAI,SAAS,CAAC,KAAK,CAAC,8BAA8B,CAAC,EAAE;QACnD,MAAM,GAAG,0BAA0B,CAAC;KACrC;SAAM,IAAI,SAAS,CAAC,KAAK,CAAC,mCAAmC,CAAC,EAAE;QAC/D,MAAM,GAAG,2BAA2B,CAAC;KACtC;SAAM,IAAI,SAAS,CAAC,KAAK,CAAC,0BAA0B,CAAC,EAAE;QACtD,MAAM,GAAG,wBAAwB,CAAC;KACnC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,uBAAuB,CAAC,MAAc;IAC7C,IAAI,MAAM,CAAC;IAEX,IAAI,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,EAAE;QAChD,MAAM,GAAG,0BAA0B,CAAC;KACrC;SAAM,IAAI,MAAM,CAAC,KAAK,CAAC,mCAAmC,CAAC,EAAE;QAC5D,MAAM,GAAG,2BAA2B,CAAC;KACtC;SAAM;QACL,0BAA0B;QAC1B,IAAI,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,EAAE;YAC5C,MAAM,GAAG,wBAAwB,CAAC;SACnC;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,203 @@
1
+ import { getProp, getWithDefault } from ".";
2
+ /**
3
+ * Hash of Hub API end points so updates
4
+ * are centralized
5
+ */
6
+ const hubApiEndpoints = {
7
+ domains: "/api/v3/domains",
8
+ search: "/api/v3/datasets",
9
+ discussions: "/api/discussions/v1",
10
+ };
11
+ /**
12
+ * @internal
13
+ * Thin class just used to enable getters
14
+ *
15
+ * This class should not be used by anything other than
16
+ * the ArcGISContext class
17
+ */
18
+ export class ArcGISContextState {
19
+ constructor(opts) {
20
+ this._portalUrl = "https://www.arcgis.com";
21
+ this.id = opts.id;
22
+ this._portalUrl = opts.portalUrl;
23
+ this._hubUrl = opts.hubUrl;
24
+ if (opts.authentication) {
25
+ this._authentication = opts.authentication;
26
+ }
27
+ if (opts.portalSelf) {
28
+ this._portalSelf = opts.portalSelf;
29
+ }
30
+ if (opts.currentUser) {
31
+ this._currentUser = opts.currentUser;
32
+ }
33
+ }
34
+ /**
35
+ * Return the UserSession if authenticated
36
+ */
37
+ get session() {
38
+ return this._authentication;
39
+ }
40
+ /**
41
+ * Return boolean indicating if authenticatio is present
42
+ */
43
+ get isAuthenticated() {
44
+ return !!this._authentication;
45
+ }
46
+ /**
47
+ * Return `IUserRequestOptions`, which is used for REST-JS
48
+ * functions which require authentication information.
49
+ *
50
+ * If context is not authenticated, this function will throw
51
+ */
52
+ get userRequestOptions() {
53
+ if (this.isAuthenticated) {
54
+ return {
55
+ authentication: this._authentication,
56
+ portal: this.sharingApiUrl,
57
+ };
58
+ }
59
+ }
60
+ /**
61
+ * Return `IRequestOptions`, which is used by REST-JS functions
62
+ * which *may* use authentication information if provided.
63
+ *
64
+ * If context is not authenticated, this function just returns
65
+ * the `portal` property, which informs REST-JS what Sharing API
66
+ * instance to use (i.e. AGO, Enterprise etc)
67
+ */
68
+ get requestOptions() {
69
+ let ro = {
70
+ portal: this.sharingApiUrl,
71
+ };
72
+ if (this.isAuthenticated) {
73
+ ro = {
74
+ authentication: this._authentication,
75
+ portal: this.sharingApiUrl,
76
+ };
77
+ }
78
+ return ro;
79
+ }
80
+ /**
81
+ * Return a `IHubRequestOptions` object
82
+ */
83
+ get hubRequestOptions() {
84
+ // We may add more logic around what is returned in some corner cases
85
+ return {
86
+ authentication: this.session,
87
+ isPortal: this.isPortal,
88
+ portalSelf: this.portal,
89
+ hubApiUrl: this.hubUrl,
90
+ };
91
+ }
92
+ // ==============================
93
+ // Getters / Computed Properties
94
+ // ==============================
95
+ /**
96
+ * Return the portal url.
97
+ *
98
+ * If authenticated @ ArcGIS Online, it will return
99
+ * the https://org.env.arcgis.com
100
+ *
101
+ * If authenticated @ ArcGIS Enterprise, it will return
102
+ * https://portalHostname, which includes the web adaptor
103
+ */
104
+ get portalUrl() {
105
+ if (this.isAuthenticated) {
106
+ if (this.isPortal) {
107
+ return `https://${this._portalSelf.portalHostname}`;
108
+ }
109
+ else {
110
+ return `https://${this._portalSelf.urlKey}.${this._portalSelf.customBaseUrl}`;
111
+ }
112
+ }
113
+ else {
114
+ return this._portalUrl;
115
+ }
116
+ }
117
+ /**
118
+ * Returns the url to the sharing api
119
+ * i.e. https://myorg.maps.arcgis.com/sharing/rest
120
+ */
121
+ get sharingApiUrl() {
122
+ return `${this.portalUrl}/sharing/rest`;
123
+ }
124
+ get hubUrl() {
125
+ return this._hubUrl;
126
+ }
127
+ /**
128
+ * Returns boolean indicating if the backing system
129
+ * is ArcGIS Enterprise (formerly ArcGIS Portal) or not
130
+ */
131
+ get isPortal() {
132
+ return this._portalSelf
133
+ ? this._portalSelf.isPortal
134
+ : this._portalUrl.indexOf("arcgis.com") === -1;
135
+ }
136
+ // Hub APIs
137
+ // ----------
138
+ // Discussions
139
+ get discussionsServiceUrl() {
140
+ if (this._hubUrl) {
141
+ return `${this._hubUrl}${hubApiEndpoints.discussions}`;
142
+ }
143
+ }
144
+ // Hub Search
145
+ get hubSearchServiceUrl() {
146
+ if (this._hubUrl) {
147
+ return `${this._hubUrl}${hubApiEndpoints.search}`;
148
+ }
149
+ }
150
+ // Domain
151
+ get domainServiceUrl() {
152
+ if (this._hubUrl) {
153
+ return `${this._hubUrl}${hubApiEndpoints.domains}`;
154
+ }
155
+ }
156
+ // Events
157
+ // returns `{serviceId: '3ef..', publicViewId: 'bc3...'}
158
+ get eventsConfig() {
159
+ if (this._portalSelf) {
160
+ return getProp(this._portalSelf, "portalProperties.hub.settings.events");
161
+ }
162
+ }
163
+ /**
164
+ * Returns boolean indicating if the current user
165
+ * belongs to an organization that has licensed
166
+ * ArcGIS Hub
167
+ */
168
+ get hubEnabled() {
169
+ return getWithDefault(this._portalSelf, "portalProperties.hub.enabled", false);
170
+ }
171
+ /**
172
+ * Return Hub Community Org Id, if defined
173
+ */
174
+ get communityOrgId() {
175
+ if (this._portalSelf) {
176
+ return getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.orgId");
177
+ }
178
+ }
179
+ get communityOrgHostname() {
180
+ if (this._portalSelf) {
181
+ return getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.portalHostname");
182
+ }
183
+ }
184
+ get communityOrgUrl() {
185
+ if (this.communityOrgHostname) {
186
+ return `https://${this.communityOrgHostname}`;
187
+ }
188
+ }
189
+ // Platform API service urls are all in helperServices
190
+ // and not consistent to expose as urls
191
+ get helperServices() {
192
+ if (this._portalSelf) {
193
+ return this._portalSelf.helperServices;
194
+ }
195
+ }
196
+ get currentUser() {
197
+ return this._currentUser;
198
+ }
199
+ get portal() {
200
+ return this._portalSelf;
201
+ }
202
+ }
203
+ //# sourceMappingURL=ArcGISContextState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArcGISContextState.js","sourceRoot":"","sources":["../../src/ArcGISContextState.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAsB,MAAM,GAAG,CAAC;AAEhE;;;GAGG;AACH,MAAM,eAAe,GAAG;IACtB,OAAO,EAAE,iBAAiB;IAC1B,MAAM,EAAE,kBAAkB;IAC1B,WAAW,EAAE,qBAAqB;CACnC,CAAC;AA6CF;;;;;;GAMG;AACH,MAAM,OAAO,kBAAkB;IAY7B,YAAY,IAAgC;QARpC,eAAU,GAAW,wBAAwB,CAAC;QASpD,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QA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