@esri/hub-common 9.13.2 → 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.
- package/dist/es2017/ArcGISContext.js +158 -147
- package/dist/es2017/ArcGISContext.js.map +1 -1
- package/dist/es2017/ArcGISContextManager.js +160 -0
- package/dist/es2017/ArcGISContextManager.js.map +1 -0
- package/dist/es2017/index.js +1 -0
- package/dist/es2017/index.js.map +1 -1
- package/dist/es2017/search/_searchContent.js +18 -7
- package/dist/es2017/search/_searchContent.js.map +1 -1
- package/dist/es2017/search/_searchGroups.js +1 -11
- package/dist/es2017/search/_searchGroups.js.map +1 -1
- package/dist/es2017/search/utils.js +1 -1
- package/dist/es2017/urls/getHubApiFromPortalUrl.js +21 -0
- package/dist/es2017/urls/getHubApiFromPortalUrl.js.map +1 -0
- package/dist/es2017/urls/getPortalBaseFromOrgUrl.js +25 -0
- package/dist/es2017/urls/getPortalBaseFromOrgUrl.js.map +1 -0
- package/dist/es2017/urls/index.js +2 -0
- package/dist/es2017/urls/index.js.map +1 -1
- package/dist/esm/ArcGISContext.js +251 -202
- package/dist/esm/ArcGISContext.js.map +1 -1
- package/dist/esm/ArcGISContextManager.js +204 -0
- package/dist/esm/ArcGISContextManager.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/search/_searchContent.js +18 -7
- package/dist/esm/search/_searchContent.js.map +1 -1
- package/dist/esm/search/_searchGroups.js +3 -13
- package/dist/esm/search/_searchGroups.js.map +1 -1
- package/dist/esm/search/utils.js +1 -1
- package/dist/esm/urls/getHubApiFromPortalUrl.js +21 -0
- package/dist/esm/urls/getHubApiFromPortalUrl.js.map +1 -0
- package/dist/esm/urls/getPortalBaseFromOrgUrl.js +25 -0
- package/dist/esm/urls/getPortalBaseFromOrgUrl.js.map +1 -0
- package/dist/esm/urls/index.js +2 -0
- package/dist/esm/urls/index.js.map +1 -1
- package/dist/node/ArcGISContext.js +158 -147
- package/dist/node/ArcGISContext.js.map +1 -1
- package/dist/node/ArcGISContextManager.js +164 -0
- package/dist/node/ArcGISContextManager.js.map +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/search/_searchContent.js +17 -6
- package/dist/node/search/_searchContent.js.map +1 -1
- package/dist/node/search/_searchGroups.js +1 -11
- package/dist/node/search/_searchGroups.js.map +1 -1
- package/dist/node/search/utils.js +1 -1
- package/dist/node/urls/getHubApiFromPortalUrl.js +25 -0
- package/dist/node/urls/getHubApiFromPortalUrl.js.map +1 -0
- package/dist/node/urls/getPortalBaseFromOrgUrl.js +29 -0
- package/dist/node/urls/getPortalBaseFromOrgUrl.js.map +1 -0
- package/dist/node/urls/index.js +2 -0
- package/dist/node/urls/index.js.map +1 -1
- package/dist/types/ArcGISContext.d.ts +103 -77
- package/dist/types/ArcGISContextManager.d.ts +113 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/search/utils.d.ts +1 -1
- package/dist/types/urls/getHubApiFromPortalUrl.d.ts +8 -0
- package/dist/types/urls/getPortalBaseFromOrgUrl.d.ts +9 -0
- package/dist/types/urls/index.d.ts +2 -0
- package/dist/umd/common.umd.js +144 -125
- package/dist/umd/common.umd.js.map +1 -1
- package/dist/umd/common.umd.min.js +1 -1
- package/dist/umd/common.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/es2017/ArcGISContextState.js +0 -203
- package/dist/es2017/ArcGISContextState.js.map +0 -1
- package/dist/esm/ArcGISContextState.js +0 -285
- package/dist/esm/ArcGISContextState.js.map +0 -1
- package/dist/node/ArcGISContextState.js +0 -207
- package/dist/node/ArcGISContextState.js.map +0 -1
- package/dist/types/ArcGISContextState.d.ts +0 -129
|
@@ -1,194 +1,205 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ArcGISContextState, } from "./ArcGISContextState";
|
|
3
|
-
import { cloneObject } from ".";
|
|
1
|
+
import { getProp, getWithDefault } from ".";
|
|
4
2
|
/**
|
|
5
|
-
*
|
|
3
|
+
* Hash of Hub API end points so updates
|
|
4
|
+
* are centralized
|
|
5
|
+
*/
|
|
6
|
+
const hubApiEndpoints = {
|
|
7
|
+
domains: "/api/v3/domains",
|
|
8
|
+
search: "/api/v3/datasets",
|
|
9
|
+
discussions: "/api/discussions/v1",
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* ArcGISContext
|
|
6
13
|
*
|
|
7
|
-
* Abstraction that
|
|
8
|
-
*
|
|
9
|
-
*
|
|
14
|
+
* Abstraction that holds a UserSession, along with
|
|
15
|
+
* getters to streamline access to various platform
|
|
16
|
+
* urls, and common constructs like IRequestOptions
|
|
10
17
|
*
|
|
11
|
-
*
|
|
18
|
+
* Thin class just used to enable getters
|
|
12
19
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
20
|
+
* This class should not be used by anything other than
|
|
21
|
+
* the ArcGISContextManager class
|
|
15
22
|
*/
|
|
16
23
|
export class ArcGISContext {
|
|
17
|
-
/**
|
|
18
|
-
* Private constructor. Use `ArcGISContext.create(...)` to
|
|
19
|
-
* instantiate an instance
|
|
20
|
-
* @param opts
|
|
21
|
-
*/
|
|
22
24
|
constructor(opts) {
|
|
23
25
|
this._portalUrl = "https://www.arcgis.com";
|
|
24
|
-
this.
|
|
25
|
-
|
|
26
|
-
this.
|
|
27
|
-
if (opts.debug) {
|
|
28
|
-
this._debug = opts.debug;
|
|
29
|
-
}
|
|
30
|
-
this.log(`ArcGISContext:ctor: Creating ${this.id}`);
|
|
26
|
+
this.id = opts.id;
|
|
27
|
+
this._portalUrl = opts.portalUrl;
|
|
28
|
+
this._hubUrl = opts.hubUrl;
|
|
31
29
|
if (opts.authentication) {
|
|
32
30
|
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
31
|
}
|
|
40
|
-
|
|
41
|
-
this.
|
|
42
|
-
}
|
|
43
|
-
if (opts.portal) {
|
|
44
|
-
this._portalSelf = cloneObject(opts.portal);
|
|
32
|
+
if (opts.portalSelf) {
|
|
33
|
+
this._portalSelf = opts.portalSelf;
|
|
45
34
|
}
|
|
46
35
|
if (opts.currentUser) {
|
|
47
|
-
this._currentUser =
|
|
36
|
+
this._currentUser = opts.currentUser;
|
|
48
37
|
}
|
|
49
38
|
}
|
|
50
39
|
/**
|
|
51
|
-
*
|
|
52
|
-
* @param opts
|
|
53
|
-
* @returns
|
|
40
|
+
* Return the UserSession if authenticated
|
|
54
41
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
await ctx.initialize();
|
|
58
|
-
return ctx;
|
|
42
|
+
get session() {
|
|
43
|
+
return this._authentication;
|
|
59
44
|
}
|
|
60
45
|
/**
|
|
61
|
-
*
|
|
62
|
-
* This should be called when a user signs into a running
|
|
63
|
-
* application.
|
|
64
|
-
* @param auth
|
|
46
|
+
* Return boolean indicating if authenticatio is present
|
|
65
47
|
*/
|
|
66
|
-
|
|
67
|
-
this._authentication
|
|
68
|
-
this._portalUrl = auth.portal.replace("/sharing/rest", "");
|
|
69
|
-
await this.initialize();
|
|
48
|
+
get isAuthenticated() {
|
|
49
|
+
return !!this._authentication;
|
|
70
50
|
}
|
|
71
51
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
52
|
+
* Return `IUserRequestOptions`, which is used for REST-JS
|
|
53
|
+
* functions which require authentication information.
|
|
54
|
+
*
|
|
55
|
+
* If context is not authenticated, this function will throw
|
|
75
56
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
57
|
+
get userRequestOptions() {
|
|
58
|
+
if (this.isAuthenticated) {
|
|
59
|
+
return {
|
|
60
|
+
authentication: this._authentication,
|
|
61
|
+
portal: this.sharingApiUrl,
|
|
62
|
+
};
|
|
81
63
|
}
|
|
82
|
-
// Clear the auth, portalSelf and currentUser props
|
|
83
|
-
this._authentication = null;
|
|
84
|
-
this._portalSelf = null;
|
|
85
|
-
this._currentUser = null;
|
|
86
|
-
this._state = new ArcGISContextState({
|
|
87
|
-
id: this.id,
|
|
88
|
-
portalUrl: this._portalUrl,
|
|
89
|
-
hubUrl: this._hubUrl,
|
|
90
|
-
});
|
|
91
64
|
}
|
|
92
65
|
/**
|
|
93
|
-
* Return
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
66
|
+
* Return `IRequestOptions`, which is used by REST-JS functions
|
|
67
|
+
* which *may* use authentication information if provided.
|
|
68
|
+
*
|
|
69
|
+
* If context is not authenticated, this function just returns
|
|
70
|
+
* the `portal` property, which informs REST-JS what Sharing API
|
|
71
|
+
* instance to use (i.e. AGO, Enterprise etc)
|
|
97
72
|
*/
|
|
98
|
-
get
|
|
99
|
-
|
|
73
|
+
get requestOptions() {
|
|
74
|
+
let ro = {
|
|
75
|
+
portal: this.sharingApiUrl,
|
|
76
|
+
};
|
|
77
|
+
if (this.isAuthenticated) {
|
|
78
|
+
ro = {
|
|
79
|
+
authentication: this._authentication,
|
|
80
|
+
portal: this.sharingApiUrl,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return ro;
|
|
100
84
|
}
|
|
101
85
|
/**
|
|
102
|
-
*
|
|
103
|
-
* Log debugging messages to the console
|
|
104
|
-
* @param message
|
|
86
|
+
* Return a `IHubRequestOptions` object
|
|
105
87
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
88
|
+
get hubRequestOptions() {
|
|
89
|
+
// We may add more logic around what is returned in some corner cases
|
|
90
|
+
return {
|
|
91
|
+
authentication: this.session,
|
|
92
|
+
isPortal: this.isPortal,
|
|
93
|
+
portalSelf: this.portal,
|
|
94
|
+
hubApiUrl: this.hubUrl,
|
|
95
|
+
};
|
|
111
96
|
}
|
|
112
97
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
98
|
+
* Return the portal url.
|
|
99
|
+
*
|
|
100
|
+
* If authenticated @ ArcGIS Online, it will return
|
|
101
|
+
* the https://org.env.arcgis.com
|
|
102
|
+
*
|
|
103
|
+
* If authenticated @ ArcGIS Enterprise, it will return
|
|
104
|
+
* https://portalHostname, which includes the web adaptor
|
|
115
105
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const username = this._authentication.username;
|
|
121
|
-
const requests = [
|
|
122
|
-
getSelf({ authentication: this._authentication }),
|
|
123
|
-
getUser({ username, authentication: this._authentication }),
|
|
124
|
-
];
|
|
125
|
-
try {
|
|
126
|
-
const [portal, user] = await Promise.all(requests);
|
|
127
|
-
this._portalSelf = portal;
|
|
128
|
-
this._currentUser = user;
|
|
106
|
+
get portalUrl() {
|
|
107
|
+
if (this.isAuthenticated) {
|
|
108
|
+
if (this.isPortal) {
|
|
109
|
+
return `https://${this._portalSelf.portalHostname}`;
|
|
129
110
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// tslint:disable-next-line:no-console
|
|
133
|
-
console.error(msg);
|
|
134
|
-
throw ex;
|
|
111
|
+
else {
|
|
112
|
+
return `https://${this._portalSelf.urlKey}.${this._portalSelf.customBaseUrl}`;
|
|
135
113
|
}
|
|
136
114
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
get stateOpts() {
|
|
141
|
-
const stateOpts = {
|
|
142
|
-
id: this.id,
|
|
143
|
-
portalUrl: this._portalUrl,
|
|
144
|
-
hubUrl: this._hubUrl,
|
|
145
|
-
};
|
|
146
|
-
if (this._authentication) {
|
|
147
|
-
stateOpts.authentication = this._authentication;
|
|
115
|
+
else {
|
|
116
|
+
return this._portalUrl;
|
|
148
117
|
}
|
|
149
|
-
|
|
150
|
-
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns the url to the sharing api
|
|
121
|
+
* i.e. https://myorg.maps.arcgis.com/sharing/rest
|
|
122
|
+
*/
|
|
123
|
+
get sharingApiUrl() {
|
|
124
|
+
return `${this.portalUrl}/sharing/rest`;
|
|
125
|
+
}
|
|
126
|
+
get hubUrl() {
|
|
127
|
+
return this._hubUrl;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Returns boolean indicating if the backing system
|
|
131
|
+
* is ArcGIS Enterprise (formerly ArcGIS Portal) or not
|
|
132
|
+
*/
|
|
133
|
+
get isPortal() {
|
|
134
|
+
return this._portalSelf
|
|
135
|
+
? this._portalSelf.isPortal
|
|
136
|
+
: this._portalUrl.indexOf("arcgis.com") === -1;
|
|
137
|
+
}
|
|
138
|
+
// Hub APIs
|
|
139
|
+
// ----------
|
|
140
|
+
// Discussions
|
|
141
|
+
get discussionsServiceUrl() {
|
|
142
|
+
if (this._hubUrl) {
|
|
143
|
+
return `${this._hubUrl}${hubApiEndpoints.discussions}`;
|
|
151
144
|
}
|
|
152
|
-
|
|
153
|
-
|
|
145
|
+
}
|
|
146
|
+
// Hub Search
|
|
147
|
+
get hubSearchServiceUrl() {
|
|
148
|
+
if (this._hubUrl) {
|
|
149
|
+
return `${this._hubUrl}${hubApiEndpoints.search}`;
|
|
154
150
|
}
|
|
155
|
-
return stateOpts;
|
|
156
151
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
* @param portalUrl
|
|
163
|
-
* @returns
|
|
164
|
-
*/
|
|
165
|
-
function getHubApiFromPortalUrl(portalUrl) {
|
|
166
|
-
let result;
|
|
167
|
-
if (portalUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
|
|
168
|
-
result = "https://hubqa.arcgis.com";
|
|
152
|
+
// Domain
|
|
153
|
+
get domainServiceUrl() {
|
|
154
|
+
if (this._hubUrl) {
|
|
155
|
+
return `${this._hubUrl}${hubApiEndpoints.domains}`;
|
|
156
|
+
}
|
|
169
157
|
}
|
|
170
|
-
|
|
171
|
-
|
|
158
|
+
// Events
|
|
159
|
+
// returns `{serviceId: '3ef..', publicViewId: 'bc3...'}
|
|
160
|
+
get eventsConfig() {
|
|
161
|
+
if (this._portalSelf) {
|
|
162
|
+
return getProp(this._portalSelf, "portalProperties.hub.settings.events");
|
|
163
|
+
}
|
|
172
164
|
}
|
|
173
|
-
|
|
174
|
-
|
|
165
|
+
/**
|
|
166
|
+
* Returns boolean indicating if the current user
|
|
167
|
+
* belongs to an organization that has licensed
|
|
168
|
+
* ArcGIS Hub
|
|
169
|
+
*/
|
|
170
|
+
get hubEnabled() {
|
|
171
|
+
return getWithDefault(this._portalSelf, "portalProperties.hub.enabled", false);
|
|
175
172
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
173
|
+
/**
|
|
174
|
+
* Return Hub Community Org Id, if defined
|
|
175
|
+
*/
|
|
176
|
+
get communityOrgId() {
|
|
177
|
+
if (this._portalSelf) {
|
|
178
|
+
return getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.orgId");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
get communityOrgHostname() {
|
|
182
|
+
if (this._portalSelf) {
|
|
183
|
+
return getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.portalHostname");
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
get communityOrgUrl() {
|
|
187
|
+
if (this.communityOrgHostname) {
|
|
188
|
+
return `https://${this.communityOrgHostname}`;
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
|
-
|
|
191
|
+
// Platform API service urls are all in helperServices
|
|
192
|
+
// and not consistent to expose as urls
|
|
193
|
+
get helperServices() {
|
|
194
|
+
if (this._portalSelf) {
|
|
195
|
+
return this._portalSelf.helperServices;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
get currentUser() {
|
|
199
|
+
return this._currentUser;
|
|
200
|
+
}
|
|
201
|
+
get portal() {
|
|
202
|
+
return this._portalSelf;
|
|
203
|
+
}
|
|
193
204
|
}
|
|
194
205
|
//# sourceMappingURL=ArcGISContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArcGISContext.js","sourceRoot":"","sources":["../../src/ArcGISContext.ts"],"names":[],"mappings":"
|
|
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,MAAM,eAAe,GAAG;IACtB,OAAO,EAAE,iBAAiB;IAC1B,MAAM,EAAE,kBAAkB;IAC1B,WAAW,EAAE,qBAAqB;CACnC,CAAC;AA+CF;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,aAAa;IAYxB,YAAY,IAA2B;QAR/B,eAAU,GAAW,wBAAwB,CAAC;QASpD,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,IAAI,CAAC,cAAc,EAAE;YACvB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,cAAc,CAAC;SAC5C;QAED,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC;SACpC;QAED,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC;SACtC;IACH,CAAC;IAED;;OAEG;I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EAChB,kDAAkD,CACnD,CAAC;SACH;IACH,CAAC;IAED,IAAW,oBAAoB;QAC7B,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO,OAAO,CACZ,IAAI,CAAC,WAAW,EAChB,2DAA2D,CAC5D,CAAC;SACH;IACH,CAAC;IAED,IAAW,eAAe;QACxB,IAAI,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"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { getSelf, getUser } from "@esri/arcgis-rest-portal";
|
|
2
|
+
import { ArcGISContext, } from "./ArcGISContext";
|
|
3
|
+
import { cloneObject, Logger, Level } from ".";
|
|
4
|
+
import { getHubApiFromPortalUrl } from "./urls/getHubApiFromPortalUrl";
|
|
5
|
+
import { getPortalBaseFromOrgUrl } from "./urls/getPortalBaseFromOrgUrl";
|
|
6
|
+
/**
|
|
7
|
+
* ArcGIS Context Manager
|
|
8
|
+
*
|
|
9
|
+
* The manager exposes context (`IArcGISContext`), which combines a `UserSession` with
|
|
10
|
+
* the `portal/self` and `user/self` responses to provide a central lookup for platform
|
|
11
|
+
* information, api urls, and other useful properties for developers such as IRequestOptions
|
|
12
|
+
* IUserRequestOptions, IHubRequestOptions etc.
|
|
13
|
+
*
|
|
14
|
+
* The context is exposed on gthe `.context` property, and as the authentication changes
|
|
15
|
+
* the `.context` is re-created. This is done to allow web frameworks to watch for
|
|
16
|
+
* changes on that single property, instead of having to leverage observers or events
|
|
17
|
+
* for change detection.
|
|
18
|
+
*
|
|
19
|
+
* This is a work-in-progress, and will likely expand over time.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export class ArcGISContextManager {
|
|
23
|
+
/**
|
|
24
|
+
* Private constructor. Use `ArcGISContextManager.create(...)` to
|
|
25
|
+
* instantiate an instance
|
|
26
|
+
* @param opts
|
|
27
|
+
*/
|
|
28
|
+
constructor(opts) {
|
|
29
|
+
this._portalUrl = "https://www.arcgis.com";
|
|
30
|
+
this._logLevel = Level.error;
|
|
31
|
+
// Having a unique id makes debugging easier
|
|
32
|
+
this.id = new Date().getTime();
|
|
33
|
+
if (opts.logLevel) {
|
|
34
|
+
this._logLevel = opts.logLevel;
|
|
35
|
+
}
|
|
36
|
+
Logger.setLogLevel(this._logLevel);
|
|
37
|
+
Logger.debug(`ArcGISContextManager:ctor: Creating ${this.id}`);
|
|
38
|
+
if (opts.authentication) {
|
|
39
|
+
this._authentication = opts.authentication;
|
|
40
|
+
this._portalUrl = this._authentication.portal.replace("/sharing/rest", "");
|
|
41
|
+
this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
|
|
42
|
+
}
|
|
43
|
+
else if (opts.portalUrl) {
|
|
44
|
+
this._portalUrl = opts.portalUrl;
|
|
45
|
+
this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
|
|
49
|
+
}
|
|
50
|
+
if (opts.portal) {
|
|
51
|
+
this._portalSelf = cloneObject(opts.portal);
|
|
52
|
+
}
|
|
53
|
+
if (opts.currentUser) {
|
|
54
|
+
this._currentUser = cloneObject(opts.currentUser);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Static async Factory
|
|
59
|
+
* @param opts
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
static async create(opts = {}) {
|
|
63
|
+
const ctx = new ArcGISContextManager(opts);
|
|
64
|
+
await ctx.initialize();
|
|
65
|
+
return ctx;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Set the Authentication (UserSession) for the context.
|
|
69
|
+
* This should be called when a user signs into a running
|
|
70
|
+
* application.
|
|
71
|
+
* @param auth
|
|
72
|
+
*/
|
|
73
|
+
async setAuthentication(auth) {
|
|
74
|
+
this._authentication = auth;
|
|
75
|
+
this._portalUrl = auth.portal.replace("/sharing/rest", "");
|
|
76
|
+
await this.initialize();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Clear the Authentication (UserSession). This should be
|
|
80
|
+
* called when a user signs out of an application, but
|
|
81
|
+
* the application continues running
|
|
82
|
+
*/
|
|
83
|
+
clearAuthentication() {
|
|
84
|
+
// Reset the portalUrl from the org url to the base url
|
|
85
|
+
// for ArcGIS Enterprise, we just leave the _portalUrl as-is
|
|
86
|
+
if (!this._context.isPortal) {
|
|
87
|
+
this._portalUrl = getPortalBaseFromOrgUrl(this._portalUrl);
|
|
88
|
+
}
|
|
89
|
+
// Clear the auth, portalSelf and currentUser props
|
|
90
|
+
this._authentication = null;
|
|
91
|
+
this._portalSelf = null;
|
|
92
|
+
this._currentUser = null;
|
|
93
|
+
this._context = new ArcGISContext({
|
|
94
|
+
id: this.id,
|
|
95
|
+
portalUrl: this._portalUrl,
|
|
96
|
+
hubUrl: this._hubUrl,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Return a reference to the current state.
|
|
101
|
+
* When `.setAuthentication()` or `.clearAuthenentication()` are
|
|
102
|
+
* called, the state will be re-created. This is done so frameworks
|
|
103
|
+
* like React or Ember can detect changes.
|
|
104
|
+
*/
|
|
105
|
+
get context() {
|
|
106
|
+
return this._context;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* If we have a UserSession, fetch portal/self and
|
|
110
|
+
* store that along with current user
|
|
111
|
+
*/
|
|
112
|
+
async initialize() {
|
|
113
|
+
// if we have auth, and don't have portalSelf or currentUser, fetch them
|
|
114
|
+
if (this._authentication && (!this._portalSelf || !this._currentUser)) {
|
|
115
|
+
Logger.debug(`ArcGISContextManager-${this.id}: Initializing`);
|
|
116
|
+
const username = this._authentication.username;
|
|
117
|
+
const requests = [
|
|
118
|
+
getSelf({ authentication: this._authentication }),
|
|
119
|
+
getUser({ username, authentication: this._authentication }),
|
|
120
|
+
];
|
|
121
|
+
try {
|
|
122
|
+
const [portal, user] = await Promise.all(requests);
|
|
123
|
+
this._portalSelf = portal;
|
|
124
|
+
this._currentUser = user;
|
|
125
|
+
Logger.debug(`ArcGISContextManager-${this.id}: received portalSelf and currentUser`);
|
|
126
|
+
}
|
|
127
|
+
catch (ex) {
|
|
128
|
+
const msg = `ArcGISContextManager could not fetch portal & user for "${this._authentication.username}" using ${this._authentication.portal}.`;
|
|
129
|
+
Logger.error(msg);
|
|
130
|
+
// tslint:disable-next-line:no-console
|
|
131
|
+
console.error(msg);
|
|
132
|
+
throw ex;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
Logger.debug(`ArcGISContextManager-${this.id}: updating context`);
|
|
136
|
+
// update the context
|
|
137
|
+
this._context = new ArcGISContext(this.contextOpts);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Getter to streamline the creation of updated Context instances
|
|
141
|
+
*/
|
|
142
|
+
get contextOpts() {
|
|
143
|
+
const contextOpts = {
|
|
144
|
+
id: this.id,
|
|
145
|
+
portalUrl: this._portalUrl,
|
|
146
|
+
hubUrl: this._hubUrl,
|
|
147
|
+
};
|
|
148
|
+
if (this._authentication) {
|
|
149
|
+
contextOpts.authentication = this._authentication;
|
|
150
|
+
}
|
|
151
|
+
if (this._portalSelf) {
|
|
152
|
+
contextOpts.portalSelf = this._portalSelf;
|
|
153
|
+
}
|
|
154
|
+
if (this._currentUser) {
|
|
155
|
+
contextOpts.currentUser = this._currentUser;
|
|
156
|
+
}
|
|
157
|
+
return contextOpts;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
//# 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,MAAM,OAAO,oBAAoB;IAsB/B;;;;OAIG;IACH,YAAoB,IAAkC;QAf9C,eAAU,GAAW,wBAAwB,CAAC;QAQ9C,cAAS,GAAU,KAAK,CAAC,KAAK,CAAC;QAQrC,4CAA4C;QAC5C,IAAI,CAAC,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;SAChC;QACD,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACnC,MAAM,CAAC,KAAK,CAAC,uCAAuC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QAE/D,IAAI,IAAI,CAAC,cAAc,EAAE;YACvB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,cAAc,CAAC;YAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,OAAO,CACnD,eAAe,EACf,EAAE,CACH,CAAC;YACF,IAAI,CAAC,OAAO,GAAG,sBAAsB,CAAC,IAAI,CAAC,UA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,MAAM,GAAG,CAAC;gBAC9I,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAClB,sCAAsC;gBACtC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACnB,MAAM,EAAE,CAAC;aACV;SACF;QACD,MAAM,CAAC,KAAK,CAAC,wBAAwB,IAAI,CAAC,EAAE,oBAAoB,CAAC,CAAC;QAClE,qBAAqB;QACrB,IAAI,CAAC,QAAQ,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,IAAY,WAAW;QACrB,MAAM,WAAW,GAA0B;YACzC,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,SAAS,EAAE,IAAI,CAAC,UAAU;YAC1B,MAAM,EAAE,IAAI,CAAC,OAAO;SACrB,CAAC;QACF,IAAI,IAAI,CAAC,eAAe,EAAE;YACxB,WAAW,CAAC,cAAc,GAAG,IAAI,CAAC,eAAe,CAAC;SACnD;QACD,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC;SAC3C;QACD,IAAI,IAAI,CAAC,YAAY,EAAE;YACrB,WAAW,CAAC,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;SAC7C;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;CACF"}
|
package/dist/es2017/index.js
CHANGED
|
@@ -20,6 +20,7 @@ export * from "./utils";
|
|
|
20
20
|
export * from "./i18n";
|
|
21
21
|
export * from "./request";
|
|
22
22
|
export * from "./surveys";
|
|
23
|
+
export * from "./ArcGISContextManager";
|
|
23
24
|
export * from "./ArcGISContext";
|
|
24
25
|
import OperationStack from "./OperationStack";
|
|
25
26
|
import OperationError from "./OperationError";
|
package/dist/es2017/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;gBAC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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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { expandContentFilter, serializeContentFilterForPortal, convertPortalResponseToFacets, } from "./content-utils";
|
|
2
2
|
import { searchItems } from "@esri/arcgis-rest-portal";
|
|
3
3
|
import { expandApi, getNextFunction } from ".";
|
|
4
|
-
import { cloneObject, itemToContent, setContentSiteUrls, } from "..";
|
|
4
|
+
import { cloneObject, getItemThumbnailUrl, itemToContent, setContentSiteUrls, } from "..";
|
|
5
5
|
/**
|
|
6
6
|
* Search for content via the Portal or Hub API
|
|
7
7
|
* @param filter
|
|
@@ -14,13 +14,12 @@ export async function _searchContent(filter, options) {
|
|
|
14
14
|
// API
|
|
15
15
|
const api = expandApi(options.api || "arcgis");
|
|
16
16
|
let searchPromise;
|
|
17
|
-
// map over the apis, depending on the type we issue the queries
|
|
18
|
-
// const searchPromises = apis.map((api) => {
|
|
19
17
|
// Portal Search
|
|
20
18
|
if (api.type === "arcgis") {
|
|
21
19
|
// serialize for portal
|
|
22
20
|
const so = serializeContentFilterForPortal(expanded);
|
|
23
|
-
//
|
|
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 async 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 async function _searchContent(filter, options) {
|
|
|
61
59
|
},
|
|
62
60
|
});
|
|
63
61
|
}
|
|
64
|
-
// });
|
|
65
|
-
// return for results
|
|
66
62
|
return searchPromise;
|
|
67
63
|
}
|
|
68
64
|
/**
|
|
@@ -74,12 +70,27 @@ export async function _searchContent(filter, options) {
|
|
|
74
70
|
* @returns
|
|
75
71
|
*/
|
|
76
72
|
function searchPortal(searchOptions) {
|
|
73
|
+
var _a;
|
|
74
|
+
const portalUrl = ((_a = searchOptions.authentication) === null || _a === void 0 ? void 0 : _a.portal) || searchOptions.portal;
|
|
75
|
+
let token;
|
|
76
|
+
if (searchOptions.authentication) {
|
|
77
|
+
const us = searchOptions.authentication;
|
|
78
|
+
token = us.token;
|
|
79
|
+
}
|
|
80
|
+
const thumbnailify = (content) => {
|
|
81
|
+
content.thumbnailUrl = getItemThumbnailUrl(content, portalUrl, token);
|
|
82
|
+
return content;
|
|
83
|
+
};
|
|
77
84
|
return searchItems(searchOptions).then((resp) => {
|
|
78
85
|
const hasNext = resp.nextStart > -1;
|
|
86
|
+
// convert items to IHubContent's
|
|
79
87
|
let content = resp.results.map(itemToContent);
|
|
88
|
+
// if we have a site, add those urls
|
|
80
89
|
if (searchOptions.site) {
|
|
81
90
|
content = content.map((entry) => setContentSiteUrls(entry, searchOptions.site));
|
|
82
91
|
}
|
|
92
|
+
// add thumbnailUrl
|
|
93
|
+
content = content.map(thumbnailify);
|
|
83
94
|
// convert aggregations into facets
|
|
84
95
|
const facets = convertPortalResponseToFacets(resp);
|
|
85
96
|
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,M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