@esri/hub-common 9.11.0 → 9.13.2

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 (48) hide show
  1. package/dist/es2017/ArcGISContext.js +194 -0
  2. package/dist/es2017/ArcGISContext.js.map +1 -0
  3. package/dist/es2017/ArcGISContextState.js +203 -0
  4. package/dist/es2017/ArcGISContextState.js.map +1 -0
  5. package/dist/es2017/content/index.js +124 -1
  6. package/dist/es2017/content/index.js.map +1 -1
  7. package/dist/es2017/index.js +1 -0
  8. package/dist/es2017/index.js.map +1 -1
  9. package/dist/es2017/utils/index.js +1 -0
  10. package/dist/es2017/utils/index.js.map +1 -1
  11. package/dist/es2017/utils/sessionLocalStorage.js +47 -0
  12. package/dist/es2017/utils/sessionLocalStorage.js.map +1 -0
  13. package/dist/esm/ArcGISContext.js +238 -0
  14. package/dist/esm/ArcGISContext.js.map +1 -0
  15. package/dist/esm/ArcGISContextState.js +285 -0
  16. package/dist/esm/ArcGISContextState.js.map +1 -0
  17. package/dist/esm/content/index.js +124 -1
  18. package/dist/esm/content/index.js.map +1 -1
  19. package/dist/esm/index.js +1 -0
  20. package/dist/esm/index.js.map +1 -1
  21. package/dist/esm/utils/index.js +1 -0
  22. package/dist/esm/utils/index.js.map +1 -1
  23. package/dist/esm/utils/sessionLocalStorage.js +50 -0
  24. package/dist/esm/utils/sessionLocalStorage.js.map +1 -0
  25. package/dist/node/ArcGISContext.js +198 -0
  26. package/dist/node/ArcGISContext.js.map +1 -0
  27. package/dist/node/ArcGISContextState.js +207 -0
  28. package/dist/node/ArcGISContextState.js.map +1 -0
  29. package/dist/node/content/index.js +125 -2
  30. package/dist/node/content/index.js.map +1 -1
  31. package/dist/node/index.js +1 -0
  32. package/dist/node/index.js.map +1 -1
  33. package/dist/node/utils/index.js +1 -0
  34. package/dist/node/utils/index.js.map +1 -1
  35. package/dist/node/utils/sessionLocalStorage.js +53 -0
  36. package/dist/node/utils/sessionLocalStorage.js.map +1 -0
  37. package/dist/types/ArcGISContext.d.ts +110 -0
  38. package/dist/types/ArcGISContextState.d.ts +129 -0
  39. package/dist/types/content/index.d.ts +13 -0
  40. package/dist/types/index.d.ts +1 -0
  41. package/dist/types/types.d.ts +5 -2
  42. package/dist/types/utils/index.d.ts +1 -0
  43. package/dist/types/utils/sessionLocalStorage.d.ts +23 -0
  44. package/dist/umd/common.umd.js +3421 -2695
  45. package/dist/umd/common.umd.js.map +1 -1
  46. package/dist/umd/common.umd.min.js +1 -1
  47. package/dist/umd/common.umd.min.js.map +1 -1
  48. package/package.json +1 -1
@@ -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"}
@@ -0,0 +1,238 @@
1
+ import { __awaiter, __generator } from "tslib";
2
+ import { getSelf, getUser } from "@esri/arcgis-rest-portal";
3
+ import { ArcGISContextState, } from "./ArcGISContextState";
4
+ import { cloneObject } from ".";
5
+ /**
6
+ * Application Context Object
7
+ *
8
+ * Abstraction that combines a `UserSession` with
9
+ * the `portal/self` and `user/self` responses to
10
+ * provide a central lookup of platform information.
11
+ *
12
+ * This is a work-in-progress, and will likely expand over time.
13
+ *
14
+ * `ArcGISContext` is used in conjuction with the `arcgis-app-identity`
15
+ * component to orchestrate oAuth.
16
+ */
17
+ var ArcGISContext = /** @class */ (function () {
18
+ /**
19
+ * Private constructor. Use `ArcGISContext.create(...)` to
20
+ * instantiate an instance
21
+ * @param opts
22
+ */
23
+ function ArcGISContext(opts) {
24
+ this._portalUrl = "https://www.arcgis.com";
25
+ this._debug = false;
26
+ // Having a unique id makes debugging easier
27
+ this.id = new Date().getTime();
28
+ if (opts.debug) {
29
+ this._debug = opts.debug;
30
+ }
31
+ this.log("ArcGISContext:ctor: Creating " + this.id);
32
+ if (opts.authentication) {
33
+ this._authentication = opts.authentication;
34
+ this._portalUrl = this._authentication.portal.replace("/sharing/rest", "");
35
+ this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
36
+ }
37
+ else if (opts.portalUrl) {
38
+ this._portalUrl = opts.portalUrl;
39
+ this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
40
+ }
41
+ else {
42
+ this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
43
+ }
44
+ if (opts.portal) {
45
+ this._portalSelf = cloneObject(opts.portal);
46
+ }
47
+ if (opts.currentUser) {
48
+ this._currentUser = cloneObject(opts.currentUser);
49
+ }
50
+ }
51
+ /**
52
+ * Static async Factory
53
+ * @param opts
54
+ * @returns
55
+ */
56
+ ArcGISContext.create = function (opts) {
57
+ if (opts === void 0) { opts = {}; }
58
+ return __awaiter(this, void 0, void 0, function () {
59
+ var ctx;
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0:
63
+ ctx = new ArcGISContext(opts);
64
+ return [4 /*yield*/, ctx.initialize()];
65
+ case 1:
66
+ _a.sent();
67
+ return [2 /*return*/, ctx];
68
+ }
69
+ });
70
+ });
71
+ };
72
+ /**
73
+ * Set the Authentication (UserSession) for the context.
74
+ * This should be called when a user signs into a running
75
+ * application.
76
+ * @param auth
77
+ */
78
+ ArcGISContext.prototype.setAuthentication = function (auth) {
79
+ return __awaiter(this, void 0, void 0, function () {
80
+ return __generator(this, function (_a) {
81
+ switch (_a.label) {
82
+ case 0:
83
+ this._authentication = auth;
84
+ this._portalUrl = auth.portal.replace("/sharing/rest", "");
85
+ return [4 /*yield*/, this.initialize()];
86
+ case 1:
87
+ _a.sent();
88
+ return [2 /*return*/];
89
+ }
90
+ });
91
+ });
92
+ };
93
+ /**
94
+ * Clear the Authentication (UserSession). This should be
95
+ * called when a user signs out of an application, but
96
+ * the application continues running
97
+ */
98
+ ArcGISContext.prototype.clearAuthentication = function () {
99
+ // Reset the portalUrl from the org url to the base url
100
+ // for ArcGIS Enterprise, we just leave the _portalUrl as-is
101
+ if (!this._state.isPortal) {
102
+ this._portalUrl = getPortalBaseFromOrgUrl(this._portalUrl);
103
+ }
104
+ // Clear the auth, portalSelf and currentUser props
105
+ this._authentication = null;
106
+ this._portalSelf = null;
107
+ this._currentUser = null;
108
+ this._state = new ArcGISContextState({
109
+ id: this.id,
110
+ portalUrl: this._portalUrl,
111
+ hubUrl: this._hubUrl,
112
+ });
113
+ };
114
+ Object.defineProperty(ArcGISContext.prototype, "state", {
115
+ /**
116
+ * Return a reference to the current state.
117
+ * When `.setAuthentication()` or `.clearAuthenentication()` are
118
+ * called, the state will be re-created. This is done so frameworks
119
+ * like React or Ember can detect changes.
120
+ */
121
+ get: function () {
122
+ return this._state;
123
+ },
124
+ enumerable: false,
125
+ configurable: true
126
+ });
127
+ /**
128
+ * @internal
129
+ * Log debugging messages to the console
130
+ * @param message
131
+ */
132
+ ArcGISContext.prototype.log = function (message) {
133
+ if (this._debug) {
134
+ // tslint:disable-next-line:no-console
135
+ console.info(message);
136
+ }
137
+ };
138
+ /**
139
+ * If we have a UserSession, fetch portal/self and
140
+ * store that along with current user
141
+ */
142
+ ArcGISContext.prototype.initialize = function () {
143
+ return __awaiter(this, void 0, void 0, function () {
144
+ var username, requests, _a, portal, user, ex_1, msg;
145
+ return __generator(this, function (_b) {
146
+ switch (_b.label) {
147
+ case 0:
148
+ if (!(this._authentication && (!this._portalSelf || !this._currentUser))) return [3 /*break*/, 4];
149
+ this.log("ArcGISContext-" + this.id + ": Initializing");
150
+ username = this._authentication.username;
151
+ requests = [
152
+ getSelf({ authentication: this._authentication }),
153
+ getUser({ username: username, authentication: this._authentication }),
154
+ ];
155
+ _b.label = 1;
156
+ case 1:
157
+ _b.trys.push([1, 3, , 4]);
158
+ return [4 /*yield*/, Promise.all(requests)];
159
+ case 2:
160
+ _a = _b.sent(), portal = _a[0], user = _a[1];
161
+ this._portalSelf = portal;
162
+ this._currentUser = user;
163
+ return [3 /*break*/, 4];
164
+ case 3:
165
+ ex_1 = _b.sent();
166
+ msg = "ArcGISContext could not fetch portal & user for \"" + this._authentication.username + "\" using " + this._authentication.portal + ".";
167
+ // tslint:disable-next-line:no-console
168
+ console.error(msg);
169
+ throw ex_1;
170
+ case 4:
171
+ // update the state
172
+ this._state = new ArcGISContextState(this.stateOpts);
173
+ return [2 /*return*/];
174
+ }
175
+ });
176
+ });
177
+ };
178
+ Object.defineProperty(ArcGISContext.prototype, "stateOpts", {
179
+ get: function () {
180
+ var stateOpts = {
181
+ id: this.id,
182
+ portalUrl: this._portalUrl,
183
+ hubUrl: this._hubUrl,
184
+ };
185
+ if (this._authentication) {
186
+ stateOpts.authentication = this._authentication;
187
+ }
188
+ if (this._portalSelf) {
189
+ stateOpts.portalSelf = this._portalSelf;
190
+ }
191
+ if (this._currentUser) {
192
+ stateOpts.currentUser = this._currentUser;
193
+ }
194
+ return stateOpts;
195
+ },
196
+ enumerable: false,
197
+ configurable: true
198
+ });
199
+ return ArcGISContext;
200
+ }());
201
+ export { ArcGISContext };
202
+ /**
203
+ * Cross-walk from a portalUrl to the corresponding Hub.
204
+ *
205
+ * If the passed url is not recognized, then this will return `undefined`
206
+ * @param portalUrl
207
+ * @returns
208
+ */
209
+ function getHubApiFromPortalUrl(portalUrl) {
210
+ var result;
211
+ if (portalUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
212
+ result = "https://hubqa.arcgis.com";
213
+ }
214
+ else if (portalUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
215
+ result = "https://hubdev.arcgis.com";
216
+ }
217
+ else if (portalUrl.match(/(www|\.maps)\.arcgis.com/)) {
218
+ result = "https://hub.arcgis.com";
219
+ }
220
+ return result;
221
+ }
222
+ function getPortalBaseFromOrgUrl(orgUrl) {
223
+ var result;
224
+ if (orgUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
225
+ result = "https://qaext.arcgis.com";
226
+ }
227
+ else if (orgUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
228
+ result = "https://devext.arcgis.com";
229
+ }
230
+ else {
231
+ /* istanbul ignore else */
232
+ if (orgUrl.match(/(www|\.maps)\.arcgis.com/)) {
233
+ result = "https://www.arcgis.com";
234
+ }
235
+ }
236
+ return result;
237
+ }
238
+ //# sourceMappingURL=ArcGISContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArcGISContext.js","sourceRoot":"","sources":["../../src/ArcGISContext.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAW,MAAM,0BAA0B,CAAC;AAErE,OAAO,EACL,kBAAkB,GAGnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AA2ChC;;;;;;;;;;;GAWG;AACH;IAsBE;;;;OAIG;IACH,uBAAoB,IAA2B;QAfvC,eAAU,GAAW,wBAAwB,CAAC;QAQ9C,WAAM,GAAG,KAAK,CAAC;QAQrB,4CAA4C;QAC5C,IAAI,CAAC,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;SAC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D,IA2KC;;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,285 @@
1
+ import { getProp, getWithDefault } from ".";
2
+ /**
3
+ * Hash of Hub API end points so updates
4
+ * are centralized
5
+ */
6
+ var 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
+ var ArcGISContextState = /** @class */ (function () {
19
+ function ArcGISContextState(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
+ Object.defineProperty(ArcGISContextState.prototype, "session", {
35
+ /**
36
+ * Return the UserSession if authenticated
37
+ */
38
+ get: function () {
39
+ return this._authentication;
40
+ },
41
+ enumerable: false,
42
+ configurable: true
43
+ });
44
+ Object.defineProperty(ArcGISContextState.prototype, "isAuthenticated", {
45
+ /**
46
+ * Return boolean indicating if authenticatio is present
47
+ */
48
+ get: function () {
49
+ return !!this._authentication;
50
+ },
51
+ enumerable: false,
52
+ configurable: true
53
+ });
54
+ Object.defineProperty(ArcGISContextState.prototype, "userRequestOptions", {
55
+ /**
56
+ * Return `IUserRequestOptions`, which is used for REST-JS
57
+ * functions which require authentication information.
58
+ *
59
+ * If context is not authenticated, this function will throw
60
+ */
61
+ get: function () {
62
+ if (this.isAuthenticated) {
63
+ return {
64
+ authentication: this._authentication,
65
+ portal: this.sharingApiUrl,
66
+ };
67
+ }
68
+ },
69
+ enumerable: false,
70
+ configurable: true
71
+ });
72
+ Object.defineProperty(ArcGISContextState.prototype, "requestOptions", {
73
+ /**
74
+ * Return `IRequestOptions`, which is used by REST-JS functions
75
+ * which *may* use authentication information if provided.
76
+ *
77
+ * If context is not authenticated, this function just returns
78
+ * the `portal` property, which informs REST-JS what Sharing API
79
+ * instance to use (i.e. AGO, Enterprise etc)
80
+ */
81
+ get: function () {
82
+ var ro = {
83
+ portal: this.sharingApiUrl,
84
+ };
85
+ if (this.isAuthenticated) {
86
+ ro = {
87
+ authentication: this._authentication,
88
+ portal: this.sharingApiUrl,
89
+ };
90
+ }
91
+ return ro;
92
+ },
93
+ enumerable: false,
94
+ configurable: true
95
+ });
96
+ Object.defineProperty(ArcGISContextState.prototype, "hubRequestOptions", {
97
+ /**
98
+ * Return a `IHubRequestOptions` object
99
+ */
100
+ get: function () {
101
+ // We may add more logic around what is returned in some corner cases
102
+ return {
103
+ authentication: this.session,
104
+ isPortal: this.isPortal,
105
+ portalSelf: this.portal,
106
+ hubApiUrl: this.hubUrl,
107
+ };
108
+ },
109
+ enumerable: false,
110
+ configurable: true
111
+ });
112
+ Object.defineProperty(ArcGISContextState.prototype, "portalUrl", {
113
+ // ==============================
114
+ // Getters / Computed Properties
115
+ // ==============================
116
+ /**
117
+ * Return the portal url.
118
+ *
119
+ * If authenticated @ ArcGIS Online, it will return
120
+ * the https://org.env.arcgis.com
121
+ *
122
+ * If authenticated @ ArcGIS Enterprise, it will return
123
+ * https://portalHostname, which includes the web adaptor
124
+ */
125
+ get: function () {
126
+ if (this.isAuthenticated) {
127
+ if (this.isPortal) {
128
+ return "https://" + this._portalSelf.portalHostname;
129
+ }
130
+ else {
131
+ return "https://" + this._portalSelf.urlKey + "." + this._portalSelf.customBaseUrl;
132
+ }
133
+ }
134
+ else {
135
+ return this._portalUrl;
136
+ }
137
+ },
138
+ enumerable: false,
139
+ configurable: true
140
+ });
141
+ Object.defineProperty(ArcGISContextState.prototype, "sharingApiUrl", {
142
+ /**
143
+ * Returns the url to the sharing api
144
+ * i.e. https://myorg.maps.arcgis.com/sharing/rest
145
+ */
146
+ get: function () {
147
+ return this.portalUrl + "/sharing/rest";
148
+ },
149
+ enumerable: false,
150
+ configurable: true
151
+ });
152
+ Object.defineProperty(ArcGISContextState.prototype, "hubUrl", {
153
+ get: function () {
154
+ return this._hubUrl;
155
+ },
156
+ enumerable: false,
157
+ configurable: true
158
+ });
159
+ Object.defineProperty(ArcGISContextState.prototype, "isPortal", {
160
+ /**
161
+ * Returns boolean indicating if the backing system
162
+ * is ArcGIS Enterprise (formerly ArcGIS Portal) or not
163
+ */
164
+ get: function () {
165
+ return this._portalSelf
166
+ ? this._portalSelf.isPortal
167
+ : this._portalUrl.indexOf("arcgis.com") === -1;
168
+ },
169
+ enumerable: false,
170
+ configurable: true
171
+ });
172
+ Object.defineProperty(ArcGISContextState.prototype, "discussionsServiceUrl", {
173
+ // Hub APIs
174
+ // ----------
175
+ // Discussions
176
+ get: function () {
177
+ if (this._hubUrl) {
178
+ return "" + this._hubUrl + hubApiEndpoints.discussions;
179
+ }
180
+ },
181
+ enumerable: false,
182
+ configurable: true
183
+ });
184
+ Object.defineProperty(ArcGISContextState.prototype, "hubSearchServiceUrl", {
185
+ // Hub Search
186
+ get: function () {
187
+ if (this._hubUrl) {
188
+ return "" + this._hubUrl + hubApiEndpoints.search;
189
+ }
190
+ },
191
+ enumerable: false,
192
+ configurable: true
193
+ });
194
+ Object.defineProperty(ArcGISContextState.prototype, "domainServiceUrl", {
195
+ // Domain
196
+ get: function () {
197
+ if (this._hubUrl) {
198
+ return "" + this._hubUrl + hubApiEndpoints.domains;
199
+ }
200
+ },
201
+ enumerable: false,
202
+ configurable: true
203
+ });
204
+ Object.defineProperty(ArcGISContextState.prototype, "eventsConfig", {
205
+ // Events
206
+ // returns `{serviceId: '3ef..', publicViewId: 'bc3...'}
207
+ get: function () {
208
+ if (this._portalSelf) {
209
+ return getProp(this._portalSelf, "portalProperties.hub.settings.events");
210
+ }
211
+ },
212
+ enumerable: false,
213
+ configurable: true
214
+ });
215
+ Object.defineProperty(ArcGISContextState.prototype, "hubEnabled", {
216
+ /**
217
+ * Returns boolean indicating if the current user
218
+ * belongs to an organization that has licensed
219
+ * ArcGIS Hub
220
+ */
221
+ get: function () {
222
+ return getWithDefault(this._portalSelf, "portalProperties.hub.enabled", false);
223
+ },
224
+ enumerable: false,
225
+ configurable: true
226
+ });
227
+ Object.defineProperty(ArcGISContextState.prototype, "communityOrgId", {
228
+ /**
229
+ * Return Hub Community Org Id, if defined
230
+ */
231
+ get: function () {
232
+ if (this._portalSelf) {
233
+ return getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.orgId");
234
+ }
235
+ },
236
+ enumerable: false,
237
+ configurable: true
238
+ });
239
+ Object.defineProperty(ArcGISContextState.prototype, "communityOrgHostname", {
240
+ get: function () {
241
+ if (this._portalSelf) {
242
+ return getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.portalHostname");
243
+ }
244
+ },
245
+ enumerable: false,
246
+ configurable: true
247
+ });
248
+ Object.defineProperty(ArcGISContextState.prototype, "communityOrgUrl", {
249
+ get: function () {
250
+ if (this.communityOrgHostname) {
251
+ return "https://" + this.communityOrgHostname;
252
+ }
253
+ },
254
+ enumerable: false,
255
+ configurable: true
256
+ });
257
+ Object.defineProperty(ArcGISContextState.prototype, "helperServices", {
258
+ // Platform API service urls are all in helperServices
259
+ // and not consistent to expose as urls
260
+ get: function () {
261
+ if (this._portalSelf) {
262
+ return this._portalSelf.helperServices;
263
+ }
264
+ },
265
+ enumerable: false,
266
+ configurable: true
267
+ });
268
+ Object.defineProperty(ArcGISContextState.prototype, "currentUser", {
269
+ get: function () {
270
+ return this._currentUser;
271
+ },
272
+ enumerable: false,
273
+ configurable: true
274
+ });
275
+ Object.defineProperty(ArcGISContextState.prototype, "portal", {
276
+ get: function () {
277
+ return this._portalSelf;
278
+ },
279
+ enumerable: false,
280
+ configurable: true
281
+ });
282
+ return ArcGISContextState;
283
+ }());
284
+ export { ArcGISContextState };
285
+ //# 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,IAAM,eAAe,GAAG;IACtB,OAAO,EAAE,iBAAiB;IAC1B,MAAM,EAAE,kBAAkB;IAC1B,WAAW,EAAE,qBAAqB;CACnC,CAAC;AA6CF;;;;;;GAMG;AACH;IAYE,4BAAY,IAAgC;QARpC,eAAU,GAAW,wBAAwB,CAAC;QASpD,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,UAA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