@esri/hub-common 9.12.0 → 9.13.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 (34) hide show
  1. package/dist/es2017/ArcGISContext.js +280 -0
  2. package/dist/es2017/ArcGISContext.js.map +1 -0
  3. package/dist/es2017/index.js +1 -0
  4. package/dist/es2017/index.js.map +1 -1
  5. package/dist/es2017/utils/index.js +1 -0
  6. package/dist/es2017/utils/index.js.map +1 -1
  7. package/dist/es2017/utils/sessionLocalStorage.js +47 -0
  8. package/dist/es2017/utils/sessionLocalStorage.js.map +1 -0
  9. package/dist/esm/ArcGISContext.js +395 -0
  10. package/dist/esm/ArcGISContext.js.map +1 -0
  11. package/dist/esm/index.js +1 -0
  12. package/dist/esm/index.js.map +1 -1
  13. package/dist/esm/utils/index.js +1 -0
  14. package/dist/esm/utils/index.js.map +1 -1
  15. package/dist/esm/utils/sessionLocalStorage.js +50 -0
  16. package/dist/esm/utils/sessionLocalStorage.js.map +1 -0
  17. package/dist/node/ArcGISContext.js +284 -0
  18. package/dist/node/ArcGISContext.js.map +1 -0
  19. package/dist/node/index.js +1 -0
  20. package/dist/node/index.js.map +1 -1
  21. package/dist/node/utils/index.js +1 -0
  22. package/dist/node/utils/index.js.map +1 -1
  23. package/dist/node/utils/sessionLocalStorage.js +53 -0
  24. package/dist/node/utils/sessionLocalStorage.js.map +1 -0
  25. package/dist/types/ArcGISContext.d.ts +148 -0
  26. package/dist/types/index.d.ts +1 -0
  27. package/dist/types/types.d.ts +5 -2
  28. package/dist/types/utils/index.d.ts +1 -0
  29. package/dist/types/utils/sessionLocalStorage.d.ts +23 -0
  30. package/dist/umd/common.umd.js +3171 -2694
  31. package/dist/umd/common.umd.js.map +1 -1
  32. package/dist/umd/common.umd.min.js +1 -1
  33. package/dist/umd/common.umd.min.js.map +1 -1
  34. package/package.json +1 -1
@@ -0,0 +1,280 @@
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
+ };
12
+ /**
13
+ * Application Context Object
14
+ *
15
+ * Abstraction that combines a `UserSession` with
16
+ * the `portal/self` and `user/self` responses to
17
+ * provide a central lookup of platform information.
18
+ *
19
+ * This is a work-in-progress, and will likely expand over time.
20
+ *
21
+ * `ArcGISContext` is used in conjuction with the `arcgis-app-identity`
22
+ * component to orchestrate oAuth.
23
+ */
24
+ export class ArcGISContext {
25
+ /**
26
+ * Private constructor. Use `ArcGISContext.create(...)` to
27
+ * instantiate an instance
28
+ * @param opts
29
+ */
30
+ constructor(opts) {
31
+ this._portalUrl = "https://www.arcgis.com";
32
+ this._debug = false;
33
+ // Having a unique id makes debugging easier
34
+ this.id = new Date().getTime();
35
+ if (opts.debug) {
36
+ this._debug = opts.debug;
37
+ }
38
+ this.log(`ArcGISContext:ctor: Creating ${this.id}`);
39
+ if (opts.authentication) {
40
+ this._authentication = opts.authentication;
41
+ this._portalUrl = this._authentication.portal.replace("/sharing/rest", "");
42
+ this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
43
+ }
44
+ else if (opts.portalUrl) {
45
+ this._portalUrl = opts.portalUrl;
46
+ this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
47
+ }
48
+ else {
49
+ this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
50
+ }
51
+ }
52
+ /**
53
+ * Static async Factory
54
+ * @param opts
55
+ * @returns
56
+ */
57
+ static async create(opts = {}) {
58
+ const ctx = new ArcGISContext(opts);
59
+ await ctx.initialize();
60
+ return ctx;
61
+ }
62
+ /**
63
+ * If we have a UserSession, fetch portal/self and
64
+ * store that along with current user
65
+ */
66
+ async initialize() {
67
+ if (this._authentication) {
68
+ this.log(`ArcGISContext-${this.id}: Initializing`);
69
+ const ps = await getSelf({ authentication: this._authentication });
70
+ this._portalSelf = ps;
71
+ this._currentUser = ps.user;
72
+ }
73
+ }
74
+ // Set authentication after the instance is up and running
75
+ async setAuthentication(auth) {
76
+ this._authentication = auth;
77
+ this._portalUrl = auth.portal.replace("/sharing/rest", "");
78
+ await this.initialize();
79
+ }
80
+ /**
81
+ * @internal
82
+ * Log debugging messages to the console
83
+ * @param message
84
+ */
85
+ log(message) {
86
+ if (this._debug) {
87
+ // tslint:disable-next-line:no-console
88
+ console.info(message);
89
+ }
90
+ }
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
+ }
260
+ /**
261
+ * Cross-walk from a portalUrl to the corresponding Hub.
262
+ *
263
+ * If the passed url is not recognized, then this will return `undefined`
264
+ * @param portalUrl
265
+ * @returns
266
+ */
267
+ function getHubApiFromPortalUrl(portalUrl) {
268
+ let result;
269
+ if (portalUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
270
+ result = "https://hubqa.arcgis.com";
271
+ }
272
+ else if (portalUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
273
+ result = "https://hubdev.arcgis.com";
274
+ }
275
+ else if (portalUrl.match(/(www|\.maps)\.arcgis.com/)) {
276
+ result = "https://hub.arcgis.com";
277
+ }
278
+ return result;
279
+ }
280
+ //# sourceMappingURL=ArcGISContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArcGISContext.js","sourceRoot":"","sources":["../../src/ArcGISContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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AW,IAAI,CAAC,oBAAoB,EAAE,CAAC;SAC/C;IACH,CAAC;IAED,sDAAsD;IACtD,uCAAuC;IACvC,IAAW,cAAc;QACvB,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;SACxC;IACH,CAAC;IAED,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,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"}
@@ -20,6 +20,7 @@ export * from "./utils";
20
20
  export * from "./i18n";
21
21
  export * from "./request";
22
22
  export * from "./surveys";
23
+ export * from "./ArcGISContext";
23
24
  import OperationStack from "./OperationStack";
24
25
  import OperationError from "./OperationError";
25
26
  // Re-exports
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;gBACgB;AAEhB,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,C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AAE,MAAM,MAAM,CAAC"}
@@ -15,4 +15,5 @@ export * from "./increment-string";
15
15
  export * from "./logger";
16
16
  export * from "./is-update-group";
17
17
  export * from "./revertable-tasks";
18
+ export * from "./sessionLocalStorage";
18
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { UserSession } from "@esri/arcgis-rest-auth";
2
+ /**
3
+ * Remove any serialized sessions associated with the passed clientId
4
+ * from a browser's local storage
5
+ * @param clientId oAuth Client Id
6
+ * @param win optional window (used for testing)
7
+ */
8
+ export function clearSession(clientId,
9
+ /* istanbul ignore next */
10
+ win = window) {
11
+ if (win.localStorage) {
12
+ win.localStorage.removeItem(`__CONTEXT_${clientId}`);
13
+ }
14
+ }
15
+ /**
16
+ * Re-hydrate a UserSession from a browser's local storage.
17
+ * If not found,
18
+ * @param clientId oAuth Client Id
19
+ * @param win optional window (used for testing)
20
+ * @returns
21
+ */
22
+ export function getSession(clientId,
23
+ /* istanbul ignore next */
24
+ win = window) {
25
+ let result = null;
26
+ if (win.localStorage) {
27
+ const serializedSession = win.localStorage.getItem(`__CONTEXT_${clientId}`);
28
+ if (serializedSession) {
29
+ result = UserSession.deserialize(serializedSession);
30
+ }
31
+ }
32
+ return result;
33
+ }
34
+ /**
35
+ * Serialize a UserSession into a browser's local storage
36
+ * @param clientId oAuth Client Id
37
+ * @param session UserSession
38
+ * @param win optional window (used for testing)
39
+ */
40
+ export function saveSession(clientId, session,
41
+ /* istanbul ignore next */
42
+ win = window) {
43
+ if (win.localStorage) {
44
+ win.localStorage.setItem(`__CONTEXT_${clientId}`, session.serialize());
45
+ }
46
+ }
47
+ //# sourceMappingURL=sessionLocalStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessionLocalStorage.js","sourceRoot":"","sources":["../../../src/utils/sessionLocalStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,QAAgB;AAChB,0BAA0B;AAC1B,MAAW,MAAM;IAEjB,IAAI,GAAG,CAAC,YAAY,EAAE;QACpB,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,aAAa,QAAQ,EAAE,CAAC,CAAC;KACtD;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACxB,QAAgB;AAChB,0BAA0B;AAC1B,MAAW,MAAM;IAEjB,IAAI,MAAM,GAAuB,IAAI,CAAC;IACtC,IAAI,GAAG,CAAC,YAAY,EAAE;QACpB,MAAM,iBAAiB,GAAG,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,aAAa,QAAQ,EAAE,CAAC,CAAC;QAC5E,IAAI,iBAAiB,EAAE;YACrB,MAAM,GAAG,WAAW,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;SACrD;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CACzB,QAAgB,EAChB,OAAoB;AACpB,0BAA0B;AAC1B,MAAW,MAAM;IAEjB,IAAI,GAAG,CAAC,YAAY,EAAE;QACpB,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,aAAa,QAAQ,EAAE,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;KACxE;AACH,CAAC"}