@esri/hub-common 9.12.0 → 9.14.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 (78) hide show
  1. package/dist/es2017/ArcGISContext.js +205 -0
  2. package/dist/es2017/ArcGISContext.js.map +1 -0
  3. package/dist/es2017/ArcGISContextManager.js +160 -0
  4. package/dist/es2017/ArcGISContextManager.js.map +1 -0
  5. package/dist/es2017/index.js +2 -0
  6. package/dist/es2017/index.js.map +1 -1
  7. package/dist/es2017/search/_searchContent.js +18 -7
  8. package/dist/es2017/search/_searchContent.js.map +1 -1
  9. package/dist/es2017/search/_searchGroups.js +1 -11
  10. package/dist/es2017/search/_searchGroups.js.map +1 -1
  11. package/dist/es2017/search/utils.js +1 -1
  12. package/dist/es2017/urls/getHubApiFromPortalUrl.js +21 -0
  13. package/dist/es2017/urls/getHubApiFromPortalUrl.js.map +1 -0
  14. package/dist/es2017/urls/getPortalBaseFromOrgUrl.js +25 -0
  15. package/dist/es2017/urls/getPortalBaseFromOrgUrl.js.map +1 -0
  16. package/dist/es2017/urls/index.js +2 -0
  17. package/dist/es2017/urls/index.js.map +1 -1
  18. package/dist/es2017/utils/index.js +1 -0
  19. package/dist/es2017/utils/index.js.map +1 -1
  20. package/dist/es2017/utils/sessionLocalStorage.js +47 -0
  21. package/dist/es2017/utils/sessionLocalStorage.js.map +1 -0
  22. package/dist/esm/ArcGISContext.js +287 -0
  23. package/dist/esm/ArcGISContext.js.map +1 -0
  24. package/dist/esm/ArcGISContextManager.js +204 -0
  25. package/dist/esm/ArcGISContextManager.js.map +1 -0
  26. package/dist/esm/index.js +2 -0
  27. package/dist/esm/index.js.map +1 -1
  28. package/dist/esm/search/_searchContent.js +18 -7
  29. package/dist/esm/search/_searchContent.js.map +1 -1
  30. package/dist/esm/search/_searchGroups.js +3 -13
  31. package/dist/esm/search/_searchGroups.js.map +1 -1
  32. package/dist/esm/search/utils.js +1 -1
  33. package/dist/esm/urls/getHubApiFromPortalUrl.js +21 -0
  34. package/dist/esm/urls/getHubApiFromPortalUrl.js.map +1 -0
  35. package/dist/esm/urls/getPortalBaseFromOrgUrl.js +25 -0
  36. package/dist/esm/urls/getPortalBaseFromOrgUrl.js.map +1 -0
  37. package/dist/esm/urls/index.js +2 -0
  38. package/dist/esm/urls/index.js.map +1 -1
  39. package/dist/esm/utils/index.js +1 -0
  40. package/dist/esm/utils/index.js.map +1 -1
  41. package/dist/esm/utils/sessionLocalStorage.js +50 -0
  42. package/dist/esm/utils/sessionLocalStorage.js.map +1 -0
  43. package/dist/node/ArcGISContext.js +209 -0
  44. package/dist/node/ArcGISContext.js.map +1 -0
  45. package/dist/node/ArcGISContextManager.js +164 -0
  46. package/dist/node/ArcGISContextManager.js.map +1 -0
  47. package/dist/node/index.js +2 -0
  48. package/dist/node/index.js.map +1 -1
  49. package/dist/node/search/_searchContent.js +17 -6
  50. package/dist/node/search/_searchContent.js.map +1 -1
  51. package/dist/node/search/_searchGroups.js +1 -11
  52. package/dist/node/search/_searchGroups.js.map +1 -1
  53. package/dist/node/search/utils.js +1 -1
  54. package/dist/node/urls/getHubApiFromPortalUrl.js +25 -0
  55. package/dist/node/urls/getHubApiFromPortalUrl.js.map +1 -0
  56. package/dist/node/urls/getPortalBaseFromOrgUrl.js +29 -0
  57. package/dist/node/urls/getPortalBaseFromOrgUrl.js.map +1 -0
  58. package/dist/node/urls/index.js +2 -0
  59. package/dist/node/urls/index.js.map +1 -1
  60. package/dist/node/utils/index.js +1 -0
  61. package/dist/node/utils/index.js.map +1 -1
  62. package/dist/node/utils/sessionLocalStorage.js +53 -0
  63. package/dist/node/utils/sessionLocalStorage.js.map +1 -0
  64. package/dist/types/ArcGISContext.d.ts +136 -0
  65. package/dist/types/ArcGISContextManager.d.ts +113 -0
  66. package/dist/types/index.d.ts +2 -0
  67. package/dist/types/search/utils.d.ts +1 -1
  68. package/dist/types/types.d.ts +5 -2
  69. package/dist/types/urls/getHubApiFromPortalUrl.d.ts +8 -0
  70. package/dist/types/urls/getPortalBaseFromOrgUrl.d.ts +9 -0
  71. package/dist/types/urls/index.d.ts +2 -0
  72. package/dist/types/utils/index.d.ts +1 -0
  73. package/dist/types/utils/sessionLocalStorage.d.ts +23 -0
  74. package/dist/umd/common.umd.js +3330 -2709
  75. package/dist/umd/common.umd.js.map +1 -1
  76. package/dist/umd/common.umd.min.js +1 -1
  77. package/dist/umd/common.umd.min.js.map +1 -1
  78. 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,287 @@
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
+ * ArcGISContext
13
+ *
14
+ * Abstraction that holds a UserSession, along with
15
+ * getters to streamline access to various platform
16
+ * urls, and common constructs like IRequestOptions
17
+ *
18
+ * Thin class just used to enable getters
19
+ *
20
+ * This class should not be used by anything other than
21
+ * the ArcGISContextManager class
22
+ */
23
+ var ArcGISContext = /** @class */ (function () {
24
+ function ArcGISContext(opts) {
25
+ this._portalUrl = "https://www.arcgis.com";
26
+ this.id = opts.id;
27
+ this._portalUrl = opts.portalUrl;
28
+ this._hubUrl = opts.hubUrl;
29
+ if (opts.authentication) {
30
+ this._authentication = opts.authentication;
31
+ }
32
+ if (opts.portalSelf) {
33
+ this._portalSelf = opts.portalSelf;
34
+ }
35
+ if (opts.currentUser) {
36
+ this._currentUser = opts.currentUser;
37
+ }
38
+ }
39
+ Object.defineProperty(ArcGISContext.prototype, "session", {
40
+ /**
41
+ * Return the UserSession if authenticated
42
+ */
43
+ get: function () {
44
+ return this._authentication;
45
+ },
46
+ enumerable: false,
47
+ configurable: true
48
+ });
49
+ Object.defineProperty(ArcGISContext.prototype, "isAuthenticated", {
50
+ /**
51
+ * Return boolean indicating if authenticatio is present
52
+ */
53
+ get: function () {
54
+ return !!this._authentication;
55
+ },
56
+ enumerable: false,
57
+ configurable: true
58
+ });
59
+ Object.defineProperty(ArcGISContext.prototype, "userRequestOptions", {
60
+ /**
61
+ * Return `IUserRequestOptions`, which is used for REST-JS
62
+ * functions which require authentication information.
63
+ *
64
+ * If context is not authenticated, this function will throw
65
+ */
66
+ get: function () {
67
+ if (this.isAuthenticated) {
68
+ return {
69
+ authentication: this._authentication,
70
+ portal: this.sharingApiUrl,
71
+ };
72
+ }
73
+ },
74
+ enumerable: false,
75
+ configurable: true
76
+ });
77
+ Object.defineProperty(ArcGISContext.prototype, "requestOptions", {
78
+ /**
79
+ * Return `IRequestOptions`, which is used by REST-JS functions
80
+ * which *may* use authentication information if provided.
81
+ *
82
+ * If context is not authenticated, this function just returns
83
+ * the `portal` property, which informs REST-JS what Sharing API
84
+ * instance to use (i.e. AGO, Enterprise etc)
85
+ */
86
+ get: function () {
87
+ var ro = {
88
+ portal: this.sharingApiUrl,
89
+ };
90
+ if (this.isAuthenticated) {
91
+ ro = {
92
+ authentication: this._authentication,
93
+ portal: this.sharingApiUrl,
94
+ };
95
+ }
96
+ return ro;
97
+ },
98
+ enumerable: false,
99
+ configurable: true
100
+ });
101
+ Object.defineProperty(ArcGISContext.prototype, "hubRequestOptions", {
102
+ /**
103
+ * Return a `IHubRequestOptions` object
104
+ */
105
+ get: function () {
106
+ // We may add more logic around what is returned in some corner cases
107
+ return {
108
+ authentication: this.session,
109
+ isPortal: this.isPortal,
110
+ portalSelf: this.portal,
111
+ hubApiUrl: this.hubUrl,
112
+ };
113
+ },
114
+ enumerable: false,
115
+ configurable: true
116
+ });
117
+ Object.defineProperty(ArcGISContext.prototype, "portalUrl", {
118
+ /**
119
+ * Return the portal url.
120
+ *
121
+ * If authenticated @ ArcGIS Online, it will return
122
+ * the https://org.env.arcgis.com
123
+ *
124
+ * If authenticated @ ArcGIS Enterprise, it will return
125
+ * https://portalHostname, which includes the web adaptor
126
+ */
127
+ get: function () {
128
+ if (this.isAuthenticated) {
129
+ if (this.isPortal) {
130
+ return "https://" + this._portalSelf.portalHostname;
131
+ }
132
+ else {
133
+ return "https://" + this._portalSelf.urlKey + "." + this._portalSelf.customBaseUrl;
134
+ }
135
+ }
136
+ else {
137
+ return this._portalUrl;
138
+ }
139
+ },
140
+ enumerable: false,
141
+ configurable: true
142
+ });
143
+ Object.defineProperty(ArcGISContext.prototype, "sharingApiUrl", {
144
+ /**
145
+ * Returns the url to the sharing api
146
+ * i.e. https://myorg.maps.arcgis.com/sharing/rest
147
+ */
148
+ get: function () {
149
+ return this.portalUrl + "/sharing/rest";
150
+ },
151
+ enumerable: false,
152
+ configurable: true
153
+ });
154
+ Object.defineProperty(ArcGISContext.prototype, "hubUrl", {
155
+ get: function () {
156
+ return this._hubUrl;
157
+ },
158
+ enumerable: false,
159
+ configurable: true
160
+ });
161
+ Object.defineProperty(ArcGISContext.prototype, "isPortal", {
162
+ /**
163
+ * Returns boolean indicating if the backing system
164
+ * is ArcGIS Enterprise (formerly ArcGIS Portal) or not
165
+ */
166
+ get: function () {
167
+ return this._portalSelf
168
+ ? this._portalSelf.isPortal
169
+ : this._portalUrl.indexOf("arcgis.com") === -1;
170
+ },
171
+ enumerable: false,
172
+ configurable: true
173
+ });
174
+ Object.defineProperty(ArcGISContext.prototype, "discussionsServiceUrl", {
175
+ // Hub APIs
176
+ // ----------
177
+ // Discussions
178
+ get: function () {
179
+ if (this._hubUrl) {
180
+ return "" + this._hubUrl + hubApiEndpoints.discussions;
181
+ }
182
+ },
183
+ enumerable: false,
184
+ configurable: true
185
+ });
186
+ Object.defineProperty(ArcGISContext.prototype, "hubSearchServiceUrl", {
187
+ // Hub Search
188
+ get: function () {
189
+ if (this._hubUrl) {
190
+ return "" + this._hubUrl + hubApiEndpoints.search;
191
+ }
192
+ },
193
+ enumerable: false,
194
+ configurable: true
195
+ });
196
+ Object.defineProperty(ArcGISContext.prototype, "domainServiceUrl", {
197
+ // Domain
198
+ get: function () {
199
+ if (this._hubUrl) {
200
+ return "" + this._hubUrl + hubApiEndpoints.domains;
201
+ }
202
+ },
203
+ enumerable: false,
204
+ configurable: true
205
+ });
206
+ Object.defineProperty(ArcGISContext.prototype, "eventsConfig", {
207
+ // Events
208
+ // returns `{serviceId: '3ef..', publicViewId: 'bc3...'}
209
+ get: function () {
210
+ if (this._portalSelf) {
211
+ return getProp(this._portalSelf, "portalProperties.hub.settings.events");
212
+ }
213
+ },
214
+ enumerable: false,
215
+ configurable: true
216
+ });
217
+ Object.defineProperty(ArcGISContext.prototype, "hubEnabled", {
218
+ /**
219
+ * Returns boolean indicating if the current user
220
+ * belongs to an organization that has licensed
221
+ * ArcGIS Hub
222
+ */
223
+ get: function () {
224
+ return getWithDefault(this._portalSelf, "portalProperties.hub.enabled", false);
225
+ },
226
+ enumerable: false,
227
+ configurable: true
228
+ });
229
+ Object.defineProperty(ArcGISContext.prototype, "communityOrgId", {
230
+ /**
231
+ * Return Hub Community Org Id, if defined
232
+ */
233
+ get: function () {
234
+ if (this._portalSelf) {
235
+ return getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.orgId");
236
+ }
237
+ },
238
+ enumerable: false,
239
+ configurable: true
240
+ });
241
+ Object.defineProperty(ArcGISContext.prototype, "communityOrgHostname", {
242
+ get: function () {
243
+ if (this._portalSelf) {
244
+ return getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.portalHostname");
245
+ }
246
+ },
247
+ enumerable: false,
248
+ configurable: true
249
+ });
250
+ Object.defineProperty(ArcGISContext.prototype, "communityOrgUrl", {
251
+ get: function () {
252
+ if (this.communityOrgHostname) {
253
+ return "https://" + this.communityOrgHostname;
254
+ }
255
+ },
256
+ enumerable: false,
257
+ configurable: true
258
+ });
259
+ Object.defineProperty(ArcGISContext.prototype, "helperServices", {
260
+ // Platform API service urls are all in helperServices
261
+ // and not consistent to expose as urls
262
+ get: function () {
263
+ if (this._portalSelf) {
264
+ return this._portalSelf.helperServices;
265
+ }
266
+ },
267
+ enumerable: false,
268
+ configurable: true
269
+ });
270
+ Object.defineProperty(ArcGISContext.prototype, "currentUser", {
271
+ get: function () {
272
+ return this._currentUser;
273
+ },
274
+ enumerable: false,
275
+ configurable: true
276
+ });
277
+ Object.defineProperty(ArcGISContext.prototype, "portal", {
278
+ get: function () {
279
+ return this._portalSelf;
280
+ },
281
+ enumerable: false,
282
+ configurable: true
283
+ });
284
+ return ArcGISContext;
285
+ }());
286
+ export { ArcGISContext };
287
+ //# sourceMappingURL=ArcGISContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArcGISContext.js","sourceRoot":"","sources":["../../src/ArcGISContext.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,CAA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AAE;gBACpB,OAAO,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;aACxC;QACH,CAAC;;;OAAA;IAED,sBAAW,sCAAW;aAAtB;YACE,OAAO,IAAI,CAAC,YAAY,CAAC;QAC3B,CAAC;;;OAAA;IAED,sBAAW,iCAAM;aAAjB;YACE,OAAO,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;;;OAAA;IACH,oBAAC;AAAD,CAAC,AA7ND,IA6NC"}
@@ -0,0 +1,204 @@
1
+ import { __awaiter, __generator } from "tslib";
2
+ import { getSelf, getUser } from "@esri/arcgis-rest-portal";
3
+ import { ArcGISContext, } from "./ArcGISContext";
4
+ import { cloneObject, Logger, Level } from ".";
5
+ import { getHubApiFromPortalUrl } from "./urls/getHubApiFromPortalUrl";
6
+ import { getPortalBaseFromOrgUrl } from "./urls/getPortalBaseFromOrgUrl";
7
+ /**
8
+ * ArcGIS Context Manager
9
+ *
10
+ * The manager exposes context (`IArcGISContext`), which combines a `UserSession` with
11
+ * the `portal/self` and `user/self` responses to provide a central lookup for platform
12
+ * information, api urls, and other useful properties for developers such as IRequestOptions
13
+ * IUserRequestOptions, IHubRequestOptions etc.
14
+ *
15
+ * The context is exposed on gthe `.context` property, and as the authentication changes
16
+ * the `.context` is re-created. This is done to allow web frameworks to watch for
17
+ * changes on that single property, instead of having to leverage observers or events
18
+ * for change detection.
19
+ *
20
+ * This is a work-in-progress, and will likely expand over time.
21
+ *
22
+ */
23
+ var ArcGISContextManager = /** @class */ (function () {
24
+ /**
25
+ * Private constructor. Use `ArcGISContextManager.create(...)` to
26
+ * instantiate an instance
27
+ * @param opts
28
+ */
29
+ function ArcGISContextManager(opts) {
30
+ this._portalUrl = "https://www.arcgis.com";
31
+ this._logLevel = Level.error;
32
+ // Having a unique id makes debugging easier
33
+ this.id = new Date().getTime();
34
+ if (opts.logLevel) {
35
+ this._logLevel = opts.logLevel;
36
+ }
37
+ Logger.setLogLevel(this._logLevel);
38
+ Logger.debug("ArcGISContextManager: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
+ if (opts.portal) {
52
+ this._portalSelf = cloneObject(opts.portal);
53
+ }
54
+ if (opts.currentUser) {
55
+ this._currentUser = cloneObject(opts.currentUser);
56
+ }
57
+ }
58
+ /**
59
+ * Static async Factory
60
+ * @param opts
61
+ * @returns
62
+ */
63
+ ArcGISContextManager.create = function (opts) {
64
+ if (opts === void 0) { opts = {}; }
65
+ return __awaiter(this, void 0, void 0, function () {
66
+ var ctx;
67
+ return __generator(this, function (_a) {
68
+ switch (_a.label) {
69
+ case 0:
70
+ ctx = new ArcGISContextManager(opts);
71
+ return [4 /*yield*/, ctx.initialize()];
72
+ case 1:
73
+ _a.sent();
74
+ return [2 /*return*/, ctx];
75
+ }
76
+ });
77
+ });
78
+ };
79
+ /**
80
+ * Set the Authentication (UserSession) for the context.
81
+ * This should be called when a user signs into a running
82
+ * application.
83
+ * @param auth
84
+ */
85
+ ArcGISContextManager.prototype.setAuthentication = function (auth) {
86
+ return __awaiter(this, void 0, void 0, function () {
87
+ return __generator(this, function (_a) {
88
+ switch (_a.label) {
89
+ case 0:
90
+ this._authentication = auth;
91
+ this._portalUrl = auth.portal.replace("/sharing/rest", "");
92
+ return [4 /*yield*/, this.initialize()];
93
+ case 1:
94
+ _a.sent();
95
+ return [2 /*return*/];
96
+ }
97
+ });
98
+ });
99
+ };
100
+ /**
101
+ * Clear the Authentication (UserSession). This should be
102
+ * called when a user signs out of an application, but
103
+ * the application continues running
104
+ */
105
+ ArcGISContextManager.prototype.clearAuthentication = function () {
106
+ // Reset the portalUrl from the org url to the base url
107
+ // for ArcGIS Enterprise, we just leave the _portalUrl as-is
108
+ if (!this._context.isPortal) {
109
+ this._portalUrl = getPortalBaseFromOrgUrl(this._portalUrl);
110
+ }
111
+ // Clear the auth, portalSelf and currentUser props
112
+ this._authentication = null;
113
+ this._portalSelf = null;
114
+ this._currentUser = null;
115
+ this._context = new ArcGISContext({
116
+ id: this.id,
117
+ portalUrl: this._portalUrl,
118
+ hubUrl: this._hubUrl,
119
+ });
120
+ };
121
+ Object.defineProperty(ArcGISContextManager.prototype, "context", {
122
+ /**
123
+ * Return a reference to the current state.
124
+ * When `.setAuthentication()` or `.clearAuthenentication()` are
125
+ * called, the state will be re-created. This is done so frameworks
126
+ * like React or Ember can detect changes.
127
+ */
128
+ get: function () {
129
+ return this._context;
130
+ },
131
+ enumerable: false,
132
+ configurable: true
133
+ });
134
+ /**
135
+ * If we have a UserSession, fetch portal/self and
136
+ * store that along with current user
137
+ */
138
+ ArcGISContextManager.prototype.initialize = function () {
139
+ return __awaiter(this, void 0, void 0, function () {
140
+ var username, requests, _a, portal, user, ex_1, msg;
141
+ return __generator(this, function (_b) {
142
+ switch (_b.label) {
143
+ case 0:
144
+ if (!(this._authentication && (!this._portalSelf || !this._currentUser))) return [3 /*break*/, 4];
145
+ Logger.debug("ArcGISContextManager-" + this.id + ": Initializing");
146
+ username = this._authentication.username;
147
+ requests = [
148
+ getSelf({ authentication: this._authentication }),
149
+ getUser({ username: username, authentication: this._authentication }),
150
+ ];
151
+ _b.label = 1;
152
+ case 1:
153
+ _b.trys.push([1, 3, , 4]);
154
+ return [4 /*yield*/, Promise.all(requests)];
155
+ case 2:
156
+ _a = _b.sent(), portal = _a[0], user = _a[1];
157
+ this._portalSelf = portal;
158
+ this._currentUser = user;
159
+ Logger.debug("ArcGISContextManager-" + this.id + ": received portalSelf and currentUser");
160
+ return [3 /*break*/, 4];
161
+ case 3:
162
+ ex_1 = _b.sent();
163
+ msg = "ArcGISContextManager could not fetch portal & user for \"" + this._authentication.username + "\" using " + this._authentication.portal + ".";
164
+ Logger.error(msg);
165
+ // tslint:disable-next-line:no-console
166
+ console.error(msg);
167
+ throw ex_1;
168
+ case 4:
169
+ Logger.debug("ArcGISContextManager-" + this.id + ": updating context");
170
+ // update the context
171
+ this._context = new ArcGISContext(this.contextOpts);
172
+ return [2 /*return*/];
173
+ }
174
+ });
175
+ });
176
+ };
177
+ Object.defineProperty(ArcGISContextManager.prototype, "contextOpts", {
178
+ /**
179
+ * Getter to streamline the creation of updated Context instances
180
+ */
181
+ get: function () {
182
+ var contextOpts = {
183
+ id: this.id,
184
+ portalUrl: this._portalUrl,
185
+ hubUrl: this._hubUrl,
186
+ };
187
+ if (this._authentication) {
188
+ contextOpts.authentication = this._authentication;
189
+ }
190
+ if (this._portalSelf) {
191
+ contextOpts.portalSelf = this._portalSelf;
192
+ }
193
+ if (this._currentUser) {
194
+ contextOpts.currentUser = this._currentUser;
195
+ }
196
+ return contextOpts;
197
+ },
198
+ enumerable: false,
199
+ configurable: true
200
+ });
201
+ return ArcGISContextManager;
202
+ }());
203
+ export { ArcGISContextManager };
204
+ //# sourceMappingURL=ArcGISContextManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArcGISContextManager.js","sourceRoot":"","sources":["../../src/ArcGISContextManager.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAW,MAAM,0BAA0B,CAAC;AAErE,OAAO,EACL,aAAa,GAGd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AA4CzE;;;;;;;;;;;;;;;GAeG;AACH;IAsBE;;;;OAIG;IACH,8BAAoB,IAAkC;QAf9C,eAAU,GAAW,wBAAwB,CAAC;QAQ9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,CAAC,eAAe,EAAE;gBACxB,WAAW,CAAC,cAAc,GAAG,IAAI,CAAC,eAAe,CAAC;aACnD;YACD,IAAI,IAAI,CAAC,WAAW,EAAE;gBACpB,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC;aAC3C;YACD,IAAI,IAAI,CAAC,YAAY,EAAE;gBACrB,WAAW,CAAC,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;aAC7C;YACD,OAAO,WAAW,CAAC;QACrB,CAAC;;;OAAA;IACH,2BAAC;AAAD,CAAC,AAxKD,IAwKC"}
package/dist/esm/index.js CHANGED
@@ -20,6 +20,8 @@ export * from "./utils";
20
20
  export * from "./i18n";
21
21
  export * from "./request";
22
22
  export * from "./surveys";
23
+ export * from "./ArcGISContextManager";
24
+ export * from "./ArcGISContext";
23
25
  import OperationStack from "./OperationStack";
24
26
  import OperationError from "./OperationError";
25
27
  // 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,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAE1B,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,aAAa;AACb,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC"}
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,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAEhC,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,aAAa;AACb,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC"}
@@ -2,7 +2,7 @@ import { __awaiter, __generator } from "tslib";
2
2
  import { expandContentFilter, serializeContentFilterForPortal, convertPortalResponseToFacets, } from "./content-utils";
3
3
  import { searchItems } from "@esri/arcgis-rest-portal";
4
4
  import { expandApi, getNextFunction } from ".";
5
- import { cloneObject, itemToContent, setContentSiteUrls, } from "..";
5
+ import { cloneObject, getItemThumbnailUrl, itemToContent, setContentSiteUrls, } from "..";
6
6
  /**
7
7
  * Search for content via the Portal or Hub API
8
8
  * @param filter
@@ -15,12 +15,11 @@ export function _searchContent(filter, options) {
15
15
  return __generator(this, function (_b) {
16
16
  expanded = expandContentFilter(filter);
17
17
  api = expandApi(options.api || "arcgis");
18
- // map over the apis, depending on the type we issue the queries
19
- // const searchPromises = apis.map((api) => {
20
18
  // Portal Search
21
19
  if (api.type === "arcgis") {
22
20
  so = serializeContentFilterForPortal(expanded);
23
- // pass auth forward
21
+ // if we have auth, pass it forward
22
+ // otherwise set the portal property
24
23
  if (options.authentication) {
25
24
  so.authentication = options.authentication;
26
25
  }
@@ -33,7 +32,6 @@ export function _searchContent(filter, options) {
33
32
  so.countSize = 200;
34
33
  }
35
34
  // copy over various options
36
- // TODO: Dry this up - typscript makes this... inconvenient
37
35
  if (options.num) {
38
36
  so.num = options.num;
39
37
  }
@@ -61,8 +59,6 @@ export function _searchContent(filter, options) {
61
59
  },
62
60
  });
63
61
  }
64
- // });
65
- // return for results
66
62
  return [2 /*return*/, searchPromise];
67
63
  });
68
64
  });
@@ -76,14 +72,29 @@ export function _searchContent(filter, options) {
76
72
  * @returns
77
73
  */
78
74
  function searchPortal(searchOptions) {
75
+ var _a;
76
+ var portalUrl = ((_a = searchOptions.authentication) === null || _a === void 0 ? void 0 : _a.portal) || searchOptions.portal;
77
+ var token;
78
+ if (searchOptions.authentication) {
79
+ var us = searchOptions.authentication;
80
+ token = us.token;
81
+ }
82
+ var thumbnailify = function (content) {
83
+ content.thumbnailUrl = getItemThumbnailUrl(content, portalUrl, token);
84
+ return content;
85
+ };
79
86
  return searchItems(searchOptions).then(function (resp) {
80
87
  var hasNext = resp.nextStart > -1;
88
+ // convert items to IHubContent's
81
89
  var content = resp.results.map(itemToContent);
90
+ // if we have a site, add those urls
82
91
  if (searchOptions.site) {
83
92
  content = content.map(function (entry) {
84
93
  return setContentSiteUrls(entry, searchOptions.site);
85
94
  });
86
95
  }
96
+ // add thumbnailUrl
97
+ content = content.map(thumbnailify);
87
98
  // convert aggregations into facets
88
99
  var facets = convertPortalResponseToFacets(resp);
89
100
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"_searchContent.js","sourceRoot":"","sources":["../../../src/search/_searchContent.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,mBAAmB,EACnB,+BAA+B,EAC/B,6BAA6B,GAC9B,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,GAAG,CAAC;AAC/C,OAAO,EACL,WAAW,EAGX,aAAa,EACb,kBAAkB,GACnB,MAAM,IAAI,CAAC;AAEZ;;;;GAIG;AACH,MAAM,UAAgB,cAAc,CAClC,MAAyB,EACzB,OAA0B;;;;;YAGpB,QAAQ,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;YAGvC,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,QAAQ,CAAC,CAAC;YAG/C,gEAAgE;YAChE,6CAA6C;YAC7C,gBAAgB;YAChB,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;gBAEnB,EAAE,GAAG,+BAA+B,CAAC,QAAQ,CAAC,CAAC;gBACrD,oBAAoB;gBACpB,IAAI,OAAO,CAAC,cAAc,EAAE;oBAC1B,EAAE,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;iBAC5C;qBAAM;oBACL,EAAE,CAAC,MAAM,GAAM,GAAG,CAAC,GAAG,kBAAe,CAAC;iBACvC;gBACD,eAAe;gBACf,UAAI,OAAO,CAAC,YAAY,0CAAE,MAAM,EAAE;oBAChC,EAAE,CAAC,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBAChD,EAAE,CAAC,SAAS,GAAG,GAAG,CAAC;iBACpB;gBACD,4BAA4B;gBAC5B,2DAA2D;gBAC3D,IAAI,OAAO,CAAC,GAAG,EAAE;oBACf,EAAE,CAAC,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