@esri/hub-common 9.10.2 → 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.
Files changed (62) hide show
  1. package/dist/es2017/ArcGISContext.js +169 -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/urls/convert-urls-to-anchor-tags.js +14 -0
  10. package/dist/es2017/urls/convert-urls-to-anchor-tags.js.map +1 -0
  11. package/dist/es2017/urls/index.js +1 -0
  12. package/dist/es2017/urls/index.js.map +1 -1
  13. package/dist/es2017/utils/index.js +1 -0
  14. package/dist/es2017/utils/index.js.map +1 -1
  15. package/dist/es2017/utils/sessionLocalStorage.js +47 -0
  16. package/dist/es2017/utils/sessionLocalStorage.js.map +1 -0
  17. package/dist/esm/ArcGISContext.js +209 -0
  18. package/dist/esm/ArcGISContext.js.map +1 -0
  19. package/dist/esm/ArcGISContextState.js +285 -0
  20. package/dist/esm/ArcGISContextState.js.map +1 -0
  21. package/dist/esm/content/index.js +124 -1
  22. package/dist/esm/content/index.js.map +1 -1
  23. package/dist/esm/index.js +1 -0
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/urls/convert-urls-to-anchor-tags.js +14 -0
  26. package/dist/esm/urls/convert-urls-to-anchor-tags.js.map +1 -0
  27. package/dist/esm/urls/index.js +1 -0
  28. package/dist/esm/urls/index.js.map +1 -1
  29. package/dist/esm/utils/index.js +1 -0
  30. package/dist/esm/utils/index.js.map +1 -1
  31. package/dist/esm/utils/sessionLocalStorage.js +50 -0
  32. package/dist/esm/utils/sessionLocalStorage.js.map +1 -0
  33. package/dist/node/ArcGISContext.js +173 -0
  34. package/dist/node/ArcGISContext.js.map +1 -0
  35. package/dist/node/ArcGISContextState.js +207 -0
  36. package/dist/node/ArcGISContextState.js.map +1 -0
  37. package/dist/node/content/index.js +125 -2
  38. package/dist/node/content/index.js.map +1 -1
  39. package/dist/node/index.js +1 -0
  40. package/dist/node/index.js.map +1 -1
  41. package/dist/node/urls/convert-urls-to-anchor-tags.js +18 -0
  42. package/dist/node/urls/convert-urls-to-anchor-tags.js.map +1 -0
  43. package/dist/node/urls/index.js +1 -0
  44. package/dist/node/urls/index.js.map +1 -1
  45. package/dist/node/utils/index.js +1 -0
  46. package/dist/node/utils/index.js.map +1 -1
  47. package/dist/node/utils/sessionLocalStorage.js +53 -0
  48. package/dist/node/utils/sessionLocalStorage.js.map +1 -0
  49. package/dist/types/ArcGISContext.d.ts +98 -0
  50. package/dist/types/ArcGISContextState.d.ts +129 -0
  51. package/dist/types/content/index.d.ts +13 -0
  52. package/dist/types/index.d.ts +1 -0
  53. package/dist/types/types.d.ts +5 -2
  54. package/dist/types/urls/convert-urls-to-anchor-tags.d.ts +5 -0
  55. package/dist/types/urls/index.d.ts +1 -0
  56. package/dist/types/utils/index.d.ts +1 -0
  57. package/dist/types/utils/sessionLocalStorage.d.ts +23 -0
  58. package/dist/umd/common.umd.js +3397 -2684
  59. package/dist/umd/common.umd.js.map +1 -1
  60. package/dist/umd/common.umd.min.js +1 -1
  61. package/dist/umd/common.umd.min.js.map +1 -1
  62. package/package.json +1 -1
@@ -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"}
@@ -0,0 +1,209 @@
1
+ import { __awaiter, __generator } from "tslib";
2
+ import { getSelf } from "@esri/arcgis-rest-portal";
3
+ import { ArcGISContextState, } from "./ArcGISContextState";
4
+ /**
5
+ * Application Context Object
6
+ *
7
+ * Abstraction that combines a `UserSession` with
8
+ * the `portal/self` and `user/self` responses to
9
+ * provide a central lookup of platform information.
10
+ *
11
+ * This is a work-in-progress, and will likely expand over time.
12
+ *
13
+ * `ArcGISContext` is used in conjuction with the `arcgis-app-identity`
14
+ * component to orchestrate oAuth.
15
+ */
16
+ var ArcGISContext = /** @class */ (function () {
17
+ /**
18
+ * Private constructor. Use `ArcGISContext.create(...)` to
19
+ * instantiate an instance
20
+ * @param opts
21
+ */
22
+ function ArcGISContext(opts) {
23
+ this._portalUrl = "https://www.arcgis.com";
24
+ this._debug = false;
25
+ // Having a unique id makes debugging easier
26
+ this.id = new Date().getTime();
27
+ if (opts.debug) {
28
+ this._debug = opts.debug;
29
+ }
30
+ this.log("ArcGISContext:ctor: Creating " + this.id);
31
+ if (opts.authentication) {
32
+ this._authentication = opts.authentication;
33
+ this._portalUrl = this._authentication.portal.replace("/sharing/rest", "");
34
+ this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
35
+ }
36
+ else if (opts.portalUrl) {
37
+ this._portalUrl = opts.portalUrl;
38
+ this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
39
+ }
40
+ else {
41
+ this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
42
+ }
43
+ }
44
+ /**
45
+ * Static async Factory
46
+ * @param opts
47
+ * @returns
48
+ */
49
+ ArcGISContext.create = function (opts) {
50
+ if (opts === void 0) { opts = {}; }
51
+ return __awaiter(this, void 0, void 0, function () {
52
+ var ctx;
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0:
56
+ ctx = new ArcGISContext(opts);
57
+ return [4 /*yield*/, ctx.initialize()];
58
+ case 1:
59
+ _a.sent();
60
+ return [2 /*return*/, ctx];
61
+ }
62
+ });
63
+ });
64
+ };
65
+ /**
66
+ * If we have a UserSession, fetch portal/self and
67
+ * store that along with current user
68
+ */
69
+ ArcGISContext.prototype.initialize = function () {
70
+ return __awaiter(this, void 0, void 0, function () {
71
+ var stateOpts, ps;
72
+ return __generator(this, function (_a) {
73
+ switch (_a.label) {
74
+ case 0:
75
+ stateOpts = {
76
+ id: this.id,
77
+ portalUrl: this._portalUrl,
78
+ hubUrl: this._hubUrl,
79
+ };
80
+ if (!this._authentication) return [3 /*break*/, 2];
81
+ this.log("ArcGISContext-" + this.id + ": Initializing");
82
+ return [4 /*yield*/, getSelf({ authentication: this._authentication })];
83
+ case 1:
84
+ ps = _a.sent();
85
+ this._portalSelf = ps;
86
+ this._currentUser = ps.user;
87
+ stateOpts = {
88
+ id: this.id,
89
+ portalUrl: this._portalUrl,
90
+ hubUrl: this._hubUrl,
91
+ portalSelf: this._portalSelf,
92
+ currentUser: this._currentUser,
93
+ authentication: this._authentication,
94
+ };
95
+ _a.label = 2;
96
+ case 2:
97
+ // update the state
98
+ this._state = new ArcGISContextState(stateOpts);
99
+ return [2 /*return*/];
100
+ }
101
+ });
102
+ });
103
+ };
104
+ /**
105
+ * Set the Authentication (UserSession) for the context.
106
+ * This should be called when a user signs into a running
107
+ * application.
108
+ * @param auth
109
+ */
110
+ ArcGISContext.prototype.setAuthentication = function (auth) {
111
+ return __awaiter(this, void 0, void 0, function () {
112
+ return __generator(this, function (_a) {
113
+ switch (_a.label) {
114
+ case 0:
115
+ this._authentication = auth;
116
+ this._portalUrl = auth.portal.replace("/sharing/rest", "");
117
+ return [4 /*yield*/, this.initialize()];
118
+ case 1:
119
+ _a.sent();
120
+ return [2 /*return*/];
121
+ }
122
+ });
123
+ });
124
+ };
125
+ /**
126
+ * Clear the Authentication (UserSession). This should be
127
+ * called when a user signs out of an application, but
128
+ * the application continues running
129
+ */
130
+ ArcGISContext.prototype.clearAuthentication = function () {
131
+ // Reset the portalUrl from the org url to the base url
132
+ // for ArcGIS Enterprise, we just leave the _portalUrl as-is
133
+ if (!this._state.isPortal) {
134
+ this._portalUrl = getPortalBaseFromOrgUrl(this._portalUrl);
135
+ }
136
+ // Clear the auth, portalSelf and currentUser props
137
+ this._authentication = null;
138
+ this._portalSelf = null;
139
+ this._currentUser = null;
140
+ this._state = new ArcGISContextState({
141
+ id: this.id,
142
+ portalUrl: this._portalUrl,
143
+ hubUrl: this._hubUrl,
144
+ });
145
+ };
146
+ Object.defineProperty(ArcGISContext.prototype, "state", {
147
+ /**
148
+ * Return a reference to the current state.
149
+ * When `.setAuthentication()` or `.clearAuthenentication()` are
150
+ * called, the state will be re-created. This is done so frameworks
151
+ * like React or Ember can detect changes.
152
+ */
153
+ get: function () {
154
+ return this._state;
155
+ },
156
+ enumerable: false,
157
+ configurable: true
158
+ });
159
+ /**
160
+ * @internal
161
+ * Log debugging messages to the console
162
+ * @param message
163
+ */
164
+ ArcGISContext.prototype.log = function (message) {
165
+ if (this._debug) {
166
+ // tslint:disable-next-line:no-console
167
+ console.info(message);
168
+ }
169
+ };
170
+ return ArcGISContext;
171
+ }());
172
+ export { ArcGISContext };
173
+ /**
174
+ * Cross-walk from a portalUrl to the corresponding Hub.
175
+ *
176
+ * If the passed url is not recognized, then this will return `undefined`
177
+ * @param portalUrl
178
+ * @returns
179
+ */
180
+ function getHubApiFromPortalUrl(portalUrl) {
181
+ var result;
182
+ if (portalUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
183
+ result = "https://hubqa.arcgis.com";
184
+ }
185
+ else if (portalUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
186
+ result = "https://hubdev.arcgis.com";
187
+ }
188
+ else if (portalUrl.match(/(www|\.maps)\.arcgis.com/)) {
189
+ result = "https://hub.arcgis.com";
190
+ }
191
+ return result;
192
+ }
193
+ function getPortalBaseFromOrgUrl(orgUrl) {
194
+ var result;
195
+ if (orgUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
196
+ result = "https://qaext.arcgis.com";
197
+ }
198
+ else if (orgUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
199
+ result = "https://devext.arcgis.com";
200
+ }
201
+ else {
202
+ /* istanbul ignore else */
203
+ if (orgUrl.match(/(www|\.maps)\.arcgis.com/)) {
204
+ result = "https://www.arcgis.com";
205
+ }
206
+ }
207
+ return result;
208
+ }
209
+ //# sourceMappingURL=ArcGISContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArcGISContext.js","sourceRoot":"","sources":["../../src/ArcGISContext.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAW,MAAM,0BAA0B,CAAC;AAE5D,OAAO,EACL,kBAAkB,GAGnB,MAAM,sBAAsB,CAAC;AA+B9B;;;;;;;;;;;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;SAC1B;QACD,IAAI,CAAC,GAAG,CAAC,kCAAgC,IAAI,CAAC,EAAI,CAAC,CAAC;QAEpD,IAAI,IAAI,CAAC,cAAc,EAAE;YACvB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,cAAc,CAAC;YAC3C,IAAI,CAAC,UAAU,GAAG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X,UAAY,OAAe;QACzB,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,sCAAsC;YACtC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACvB;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AAlJD,IAkJC;;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,C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