@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,284 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArcGISContext = void 0;
4
+ const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
5
+ const _1 = require(".");
6
+ /**
7
+ * Hash of Hub API end points so updates
8
+ * are centralized
9
+ */
10
+ const hubApiEndpoints = {
11
+ domains: "/api/v3/domains",
12
+ search: "/api/v3/datasets",
13
+ discussions: "/api/discussions/v1",
14
+ };
15
+ /**
16
+ * Application Context Object
17
+ *
18
+ * Abstraction that combines a `UserSession` with
19
+ * the `portal/self` and `user/self` responses to
20
+ * provide a central lookup of platform information.
21
+ *
22
+ * This is a work-in-progress, and will likely expand over time.
23
+ *
24
+ * `ArcGISContext` is used in conjuction with the `arcgis-app-identity`
25
+ * component to orchestrate oAuth.
26
+ */
27
+ class ArcGISContext {
28
+ /**
29
+ * Private constructor. Use `ArcGISContext.create(...)` to
30
+ * instantiate an instance
31
+ * @param opts
32
+ */
33
+ constructor(opts) {
34
+ this._portalUrl = "https://www.arcgis.com";
35
+ this._debug = false;
36
+ // Having a unique id makes debugging easier
37
+ this.id = new Date().getTime();
38
+ if (opts.debug) {
39
+ this._debug = opts.debug;
40
+ }
41
+ this.log(`ArcGISContext:ctor: Creating ${this.id}`);
42
+ if (opts.authentication) {
43
+ this._authentication = opts.authentication;
44
+ this._portalUrl = this._authentication.portal.replace("/sharing/rest", "");
45
+ this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
46
+ }
47
+ else if (opts.portalUrl) {
48
+ this._portalUrl = opts.portalUrl;
49
+ this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
50
+ }
51
+ else {
52
+ this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
53
+ }
54
+ }
55
+ /**
56
+ * Static async Factory
57
+ * @param opts
58
+ * @returns
59
+ */
60
+ static async create(opts = {}) {
61
+ const ctx = new ArcGISContext(opts);
62
+ await ctx.initialize();
63
+ return ctx;
64
+ }
65
+ /**
66
+ * If we have a UserSession, fetch portal/self and
67
+ * store that along with current user
68
+ */
69
+ async initialize() {
70
+ if (this._authentication) {
71
+ this.log(`ArcGISContext-${this.id}: Initializing`);
72
+ const ps = await arcgis_rest_portal_1.getSelf({ authentication: this._authentication });
73
+ this._portalSelf = ps;
74
+ this._currentUser = ps.user;
75
+ }
76
+ }
77
+ // Set authentication after the instance is up and running
78
+ async setAuthentication(auth) {
79
+ this._authentication = auth;
80
+ this._portalUrl = auth.portal.replace("/sharing/rest", "");
81
+ await this.initialize();
82
+ }
83
+ /**
84
+ * @internal
85
+ * Log debugging messages to the console
86
+ * @param message
87
+ */
88
+ log(message) {
89
+ if (this._debug) {
90
+ // tslint:disable-next-line:no-console
91
+ console.info(message);
92
+ }
93
+ }
94
+ /**
95
+ * Return the UserSession if authenticated
96
+ */
97
+ get session() {
98
+ return this._authentication;
99
+ }
100
+ /**
101
+ * Return boolean indicating if authenticatio is present
102
+ */
103
+ get isAuthenticated() {
104
+ return !!this._authentication;
105
+ }
106
+ /**
107
+ * Return `IUserRequestOptions`, which is used for REST-JS
108
+ * functions which require authentication information.
109
+ *
110
+ * If context is not authenticated, this function will throw
111
+ */
112
+ get userRequestOptions() {
113
+ if (this.isAuthenticated) {
114
+ return {
115
+ authentication: this._authentication,
116
+ portal: this.sharingApiUrl,
117
+ };
118
+ }
119
+ }
120
+ /**
121
+ * Return `IRequestOptions`, which is used by REST-JS functions
122
+ * which *may* use authentication information if provided.
123
+ *
124
+ * If context is not authenticated, this function just returns
125
+ * the `portal` property, which informs REST-JS what Sharing API
126
+ * instance to use (i.e. AGO, Enterprise etc)
127
+ */
128
+ get requestOptions() {
129
+ let ro = {
130
+ portal: this.sharingApiUrl,
131
+ };
132
+ if (this.isAuthenticated) {
133
+ ro = {
134
+ authentication: this._authentication,
135
+ portal: this.sharingApiUrl,
136
+ };
137
+ }
138
+ return ro;
139
+ }
140
+ /**
141
+ * Return a `IHubRequestOptions` object
142
+ */
143
+ get hubRequestOptions() {
144
+ // We may add more logic around what is returned in some corner cases
145
+ return {
146
+ authentication: this.session,
147
+ isPortal: this.isPortal,
148
+ portalSelf: this.portal,
149
+ hubApiUrl: this.hubUrl,
150
+ };
151
+ }
152
+ // ==============================
153
+ // Getters / Computed Properties
154
+ // ==============================
155
+ /**
156
+ * Return the portal url.
157
+ *
158
+ * If authenticated @ ArcGIS Online, it will return
159
+ * the https://org.env.arcgis.com
160
+ *
161
+ * If authenticated @ ArcGIS Enterprise, it will return
162
+ * https://portalHostname, which includes the web adaptor
163
+ */
164
+ get portalUrl() {
165
+ if (this.isAuthenticated) {
166
+ if (this.isPortal) {
167
+ return `https://${this._portalSelf.portalHostname}`;
168
+ }
169
+ else {
170
+ return `https://${this._portalSelf.urlKey}.${this._portalSelf.customBaseUrl}`;
171
+ }
172
+ }
173
+ else {
174
+ return this._portalUrl;
175
+ }
176
+ }
177
+ /**
178
+ * Returns the url to the sharing api
179
+ * i.e. https://myorg.maps.arcgis.com/sharing/rest
180
+ */
181
+ get sharingApiUrl() {
182
+ return `${this.portalUrl}/sharing/rest`;
183
+ }
184
+ get hubUrl() {
185
+ return this._hubUrl;
186
+ }
187
+ /**
188
+ * Returns boolean indicating if the backing system
189
+ * is ArcGIS Enterprise (formerly ArcGIS Portal) or not
190
+ */
191
+ get isPortal() {
192
+ return this._portalSelf
193
+ ? this._portalSelf.isPortal
194
+ : this._portalUrl.indexOf("arcgis.com") === -1;
195
+ }
196
+ // Hub APIs
197
+ // ----------
198
+ // Discussions
199
+ get discussionsServiceUrl() {
200
+ if (this._hubUrl) {
201
+ return `${this._hubUrl}${hubApiEndpoints.discussions}`;
202
+ }
203
+ }
204
+ // Hub Search
205
+ get hubSearchServiceUrl() {
206
+ if (this._hubUrl) {
207
+ return `${this._hubUrl}${hubApiEndpoints.search}`;
208
+ }
209
+ }
210
+ // Domain
211
+ get domainServiceUrl() {
212
+ if (this._hubUrl) {
213
+ return `${this._hubUrl}${hubApiEndpoints.domains}`;
214
+ }
215
+ }
216
+ // Events
217
+ // returns `{serviceId: '3ef..', publicViewId: 'bc3...'}
218
+ get eventsConfig() {
219
+ if (this._portalSelf) {
220
+ return _1.getProp(this._portalSelf, "portalProperties.hub.settings.events");
221
+ }
222
+ }
223
+ /**
224
+ * Returns boolean indicating if the current user
225
+ * belongs to an organization that has licensed
226
+ * ArcGIS Hub
227
+ */
228
+ get hubEnabled() {
229
+ return _1.getWithDefault(this._portalSelf, "portalProperties.hub.enabled", false);
230
+ }
231
+ /**
232
+ * Return Hub Community Org Id, if defined
233
+ */
234
+ get communityOrgId() {
235
+ if (this._portalSelf) {
236
+ return _1.getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.orgId");
237
+ }
238
+ }
239
+ get communityOrgHostname() {
240
+ if (this._portalSelf) {
241
+ return _1.getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.portalHostname");
242
+ }
243
+ }
244
+ get communityOrgUrl() {
245
+ if (this.communityOrgHostname) {
246
+ return `https://${this.communityOrgHostname}`;
247
+ }
248
+ }
249
+ // Platform API service urls are all in helperServices
250
+ // and not consistent to expose as urls
251
+ get helperServices() {
252
+ if (this._portalSelf) {
253
+ return this._portalSelf.helperServices;
254
+ }
255
+ }
256
+ get currentUser() {
257
+ return this._currentUser;
258
+ }
259
+ get portal() {
260
+ return this._portalSelf;
261
+ }
262
+ }
263
+ exports.ArcGISContext = ArcGISContext;
264
+ /**
265
+ * Cross-walk from a portalUrl to the corresponding Hub.
266
+ *
267
+ * If the passed url is not recognized, then this will return `undefined`
268
+ * @param portalUrl
269
+ * @returns
270
+ */
271
+ function getHubApiFromPortalUrl(portalUrl) {
272
+ let result;
273
+ if (portalUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
274
+ result = "https://hubqa.arcgis.com";
275
+ }
276
+ else if (portalUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
277
+ result = "https://hubdev.arcgis.com";
278
+ }
279
+ else if (portalUrl.match(/(www|\.maps)\.arcgis.com/)) {
280
+ result = "https://hub.arcgis.com";
281
+ }
282
+ return result;
283
+ }
284
+ //# sourceMappingURL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,IAAI,CAAC,oBAAoB,EAAE;YAC7B,OAAO,WAAW,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;AAjSD,sCAiSC;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"}
@@ -24,6 +24,7 @@ tslib_1.__exportStar(require("./utils"), exports);
24
24
  tslib_1.__exportStar(require("./i18n"), exports);
25
25
  tslib_1.__exportStar(require("./request"), exports);
26
26
  tslib_1.__exportStar(require("./surveys"), exports);
27
+ tslib_1.__exportStar(require("./ArcGISContext"), exports);
27
28
  const OperationStack_1 = require("./OperationStack");
28
29
  exports.OperationStack = OperationStack_1.default;
29
30
  const OperationError_1 = require("./OperationError");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;gBACgB;;;;AAEhB,mDAAyB;AACzB,gDAAsB;AACtB,iDAAuB;AACvB,uDAA6B;AAC7B,oDAA0B;AAC1B,sDAA4B;AAC5B,mDAAyB;AACzB,mDAAyB;AACzB,kDAAwB;AACxB,oDAA0B;AAC1B,sDAA4B;AAC5B,mDAAyB;AACzB,kDAAwB;AACxB,kDAAwB;AACxB,iDAAuB;AACvB,iDAAuB;AACvB,kDAAwB;AACxB,iDAAuB;AACvB,oDAA0B;AAC1B,oDAA0B;AAE1B,qDAA8C;AAGrC,yBAHF,wBAAc,CAGE;AAFvB,qDAA8C;AAErB,yBAFlB,wBAAc,CAEkB;AACvC,6BAAkC;AAAzB,4FAAA,IAAI,OAAA;AAAE,4FAAA,IAAI,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;gBACgB;;;;AAEhB,mDAAyB;AACzB,gDAAsB;AACtB,iDAAuB;AACvB,uDAA6B;AAC7B,oDAA0B;AAC1B,sDAA4B;AAC5B,mDAAyB;AACzB,mDAAyB;AACzB,kDAAwB;AACxB,oDAA0B;AAC1B,sDAA4B;AAC5B,mDAAyB;AACzB,kDAAwB;AACxB,kDAAwB;AACxB,iDAAuB;AACvB,iDAAuB;AACvB,kDAAwB;AACxB,iDAAuB;AACvB,oDAA0B;AAC1B,oDAA0B;AAC1B,0DAAgC;AAEhC,qDAA8C;AAIrC,yBAJF,wBAAc,CAIE;AAHvB,qDAA8C;AAGrB,yBAHlB,wBAAc,CAGkB;AACvC,6BAAkC;AAAzB,4FAAA,IAAI,OAAA;AAAE,4FAAA,IAAI,OAAA"}
@@ -18,4 +18,5 @@ tslib_1.__exportStar(require("./increment-string"), exports);
18
18
  tslib_1.__exportStar(require("./logger"), exports);
19
19
  tslib_1.__exportStar(require("./is-update-group"), exports);
20
20
  tslib_1.__exportStar(require("./revertable-tasks"), exports);
21
+ tslib_1.__exportStar(require("./sessionLocalStorage"), exports);
21
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,iEAAuC;AACvC,sEAA4C;AAC5C,sDAA4B;AAC5B,mEAAyC;AACzC,4DAAkC;AAClC,kEAAwC;AACxC,qDAA2B;AAC3B,oDAA0B;AAC1B,mDAAyB;AACzB,oDAA0B;AAC1B,4DAAkC;AAClC,2DAAiC;AACjC,6DAAmC;AACnC,mDAAyB;AACzB,4DAAkC;AAClC,6DAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,iEAAuC;AACvC,sEAA4C;AAC5C,sDAA4B;AAC5B,mEAAyC;AACzC,4DAAkC;AAClC,kEAAwC;AACxC,qDAA2B;AAC3B,oDAA0B;AAC1B,mDAAyB;AACzB,oDAA0B;AAC1B,4DAAkC;AAClC,2DAAiC;AACjC,6DAAmC;AACnC,mDAAyB;AACzB,4DAAkC;AAClC,6DAAmC;AACnC,gEAAsC"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.saveSession = exports.getSession = exports.clearSession = void 0;
4
+ const arcgis_rest_auth_1 = require("@esri/arcgis-rest-auth");
5
+ /**
6
+ * Remove any serialized sessions associated with the passed clientId
7
+ * from a browser's local storage
8
+ * @param clientId oAuth Client Id
9
+ * @param win optional window (used for testing)
10
+ */
11
+ function clearSession(clientId,
12
+ /* istanbul ignore next */
13
+ win = window) {
14
+ if (win.localStorage) {
15
+ win.localStorage.removeItem(`__CONTEXT_${clientId}`);
16
+ }
17
+ }
18
+ exports.clearSession = clearSession;
19
+ /**
20
+ * Re-hydrate a UserSession from a browser's local storage.
21
+ * If not found,
22
+ * @param clientId oAuth Client Id
23
+ * @param win optional window (used for testing)
24
+ * @returns
25
+ */
26
+ function getSession(clientId,
27
+ /* istanbul ignore next */
28
+ win = window) {
29
+ let result = null;
30
+ if (win.localStorage) {
31
+ const serializedSession = win.localStorage.getItem(`__CONTEXT_${clientId}`);
32
+ if (serializedSession) {
33
+ result = arcgis_rest_auth_1.UserSession.deserialize(serializedSession);
34
+ }
35
+ }
36
+ return result;
37
+ }
38
+ exports.getSession = getSession;
39
+ /**
40
+ * Serialize a UserSession into a browser's local storage
41
+ * @param clientId oAuth Client Id
42
+ * @param session UserSession
43
+ * @param win optional window (used for testing)
44
+ */
45
+ function saveSession(clientId, session,
46
+ /* istanbul ignore next */
47
+ win = window) {
48
+ if (win.localStorage) {
49
+ win.localStorage.setItem(`__CONTEXT_${clientId}`, session.serialize());
50
+ }
51
+ }
52
+ exports.saveSession = saveSession;
53
+ //# sourceMappingURL=sessionLocalStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessionLocalStorage.js","sourceRoot":"","sources":["../../../src/utils/sessionLocalStorage.ts"],"names":[],"mappings":";;;AAAA,6DAAqD;AAErD;;;;;GAKG;AACH,SAAgB,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;AARD,oCAQC;AAED;;;;;;GAMG;AACH,SAAgB,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,8BAAW,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;SACrD;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAbD,gCAaC;AAED;;;;;GAKG;AACH,SAAgB,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;AATD,kCASC"}
@@ -0,0 +1,148 @@
1
+ import { IPortal } from "@esri/arcgis-rest-portal";
2
+ import { IUser, IUserRequestOptions, UserSession } from "@esri/arcgis-rest-auth";
3
+ import { IHubRequestOptions } from ".";
4
+ import { IRequestOptions } from "@esri/arcgis-rest-request";
5
+ /**
6
+ * Options that can be passed into `ArcGISContext.create`
7
+ */
8
+ export interface IArcGISContextOptions {
9
+ /**
10
+ * Existing user session, which may be created from Identity Manager
11
+ * `const session = UserSession.fromCredential(idMgr.getCredential());`
12
+ */
13
+ authentication?: UserSession;
14
+ /**
15
+ * ArcGIS Online or ArcGIS Enterprise portal url.
16
+ * Do not include `/sharing/rest`
17
+ * Defaults to `https://www.arcgis.com`
18
+ * For ArcGIS Enterprise, you must include the webadaptor name.
19
+ * i.e. https://gis.mytown.gov/portal
20
+ *
21
+ * When Authentication is present, the UserSession.portal value is
22
+ * used instead of this property.
23
+ */
24
+ portalUrl?: string;
25
+ /**
26
+ * If set to `true` additional logging will be sent to the console
27
+ * Defaults to false.
28
+ */
29
+ debug?: boolean;
30
+ }
31
+ /**
32
+ * Application Context Object
33
+ *
34
+ * Abstraction that combines a `UserSession` with
35
+ * the `portal/self` and `user/self` responses to
36
+ * provide a central lookup of platform information.
37
+ *
38
+ * This is a work-in-progress, and will likely expand over time.
39
+ *
40
+ * `ArcGISContext` is used in conjuction with the `arcgis-app-identity`
41
+ * component to orchestrate oAuth.
42
+ */
43
+ export declare class ArcGISContext {
44
+ /**
45
+ * Random identifier useful for debugging issues
46
+ * where race-conditions can result in multiple
47
+ * contexts getting created
48
+ */
49
+ id: number;
50
+ private _authentication;
51
+ private _portalUrl;
52
+ private _hubUrl;
53
+ private _portalSelf;
54
+ private _currentUser;
55
+ private _debug;
56
+ /**
57
+ * Private constructor. Use `ArcGISContext.create(...)` to
58
+ * instantiate an instance
59
+ * @param opts
60
+ */
61
+ private constructor();
62
+ /**
63
+ * Static async Factory
64
+ * @param opts
65
+ * @returns
66
+ */
67
+ static create(opts?: IArcGISContextOptions): Promise<ArcGISContext>;
68
+ /**
69
+ * If we have a UserSession, fetch portal/self and
70
+ * store that along with current user
71
+ */
72
+ initialize(): Promise<void>;
73
+ setAuthentication(auth: UserSession): Promise<void>;
74
+ /**
75
+ * @internal
76
+ * Log debugging messages to the console
77
+ * @param message
78
+ */
79
+ private log;
80
+ /**
81
+ * Return the UserSession if authenticated
82
+ */
83
+ get session(): UserSession;
84
+ /**
85
+ * Return boolean indicating if authenticatio is present
86
+ */
87
+ get isAuthenticated(): boolean;
88
+ /**
89
+ * Return `IUserRequestOptions`, which is used for REST-JS
90
+ * functions which require authentication information.
91
+ *
92
+ * If context is not authenticated, this function will throw
93
+ */
94
+ get userRequestOptions(): IUserRequestOptions;
95
+ /**
96
+ * Return `IRequestOptions`, which is used by REST-JS functions
97
+ * which *may* use authentication information if provided.
98
+ *
99
+ * If context is not authenticated, this function just returns
100
+ * the `portal` property, which informs REST-JS what Sharing API
101
+ * instance to use (i.e. AGO, Enterprise etc)
102
+ */
103
+ get requestOptions(): IRequestOptions;
104
+ /**
105
+ * Return a `IHubRequestOptions` object
106
+ */
107
+ get hubRequestOptions(): IHubRequestOptions;
108
+ /**
109
+ * Return the portal url.
110
+ *
111
+ * If authenticated @ ArcGIS Online, it will return
112
+ * the https://org.env.arcgis.com
113
+ *
114
+ * If authenticated @ ArcGIS Enterprise, it will return
115
+ * https://portalHostname, which includes the web adaptor
116
+ */
117
+ get portalUrl(): string;
118
+ /**
119
+ * Returns the url to the sharing api
120
+ * i.e. https://myorg.maps.arcgis.com/sharing/rest
121
+ */
122
+ get sharingApiUrl(): string;
123
+ get hubUrl(): string;
124
+ /**
125
+ * Returns boolean indicating if the backing system
126
+ * is ArcGIS Enterprise (formerly ArcGIS Portal) or not
127
+ */
128
+ get isPortal(): boolean;
129
+ get discussionsServiceUrl(): string;
130
+ get hubSearchServiceUrl(): string;
131
+ get domainServiceUrl(): string;
132
+ get eventsConfig(): any;
133
+ /**
134
+ * Returns boolean indicating if the current user
135
+ * belongs to an organization that has licensed
136
+ * ArcGIS Hub
137
+ */
138
+ get hubEnabled(): boolean;
139
+ /**
140
+ * Return Hub Community Org Id, if defined
141
+ */
142
+ get communityOrgId(): string;
143
+ get communityOrgHostname(): string;
144
+ get communityOrgUrl(): string;
145
+ get helperServices(): any;
146
+ get currentUser(): IUser;
147
+ get portal(): IPortal;
148
+ }
@@ -18,6 +18,7 @@ export * from "./utils";
18
18
  export * from "./i18n";
19
19
  export * from "./request";
20
20
  export * from "./surveys";
21
+ export * from "./ArcGISContext";
21
22
  import OperationStack from "./OperationStack";
22
23
  import OperationError from "./OperationError";
23
24
  export { OperationStack, OperationError };
@@ -82,7 +82,11 @@ export interface ISolutionTemplate extends IModel {
82
82
  };
83
83
  }
84
84
  export declare type GenericAsyncFunc = (...args: any) => Promise<any>;
85
- interface IHubRequestOptionsPortalSelf extends IPortal {
85
+ /**
86
+ * @internal
87
+ * This just adds user to the IPortal interface
88
+ */
89
+ export interface IHubRequestOptionsPortalSelf extends IPortal {
86
90
  user?: IUser;
87
91
  }
88
92
  export interface IHubRequestOptions extends IRequestOptions {
@@ -415,4 +419,3 @@ export interface ISearchResponse<T> {
415
419
  next: (params?: any) => Promise<ISearchResponse<T>>;
416
420
  facets?: IFacet[];
417
421
  }
418
- export {};
@@ -15,3 +15,4 @@ 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";
@@ -0,0 +1,23 @@
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 declare function clearSession(clientId: string, win?: any): void;
9
+ /**
10
+ * Re-hydrate a UserSession from a browser's local storage.
11
+ * If not found,
12
+ * @param clientId oAuth Client Id
13
+ * @param win optional window (used for testing)
14
+ * @returns
15
+ */
16
+ export declare function getSession(clientId: string, win?: any): UserSession | null;
17
+ /**
18
+ * Serialize a UserSession into a browser's local storage
19
+ * @param clientId oAuth Client Id
20
+ * @param session UserSession
21
+ * @param win optional window (used for testing)
22
+ */
23
+ export declare function saveSession(clientId: string, session: UserSession, win?: any): void;