@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,198 +1,209 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ArcGISContext = void 0;
|
|
4
|
-
const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
|
|
5
|
-
const ArcGISContextState_1 = require("./ArcGISContextState");
|
|
6
4
|
const _1 = require(".");
|
|
7
5
|
/**
|
|
8
|
-
*
|
|
6
|
+
* Hash of Hub API end points so updates
|
|
7
|
+
* are centralized
|
|
8
|
+
*/
|
|
9
|
+
const hubApiEndpoints = {
|
|
10
|
+
domains: "/api/v3/domains",
|
|
11
|
+
search: "/api/v3/datasets",
|
|
12
|
+
discussions: "/api/discussions/v1",
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* ArcGISContext
|
|
9
16
|
*
|
|
10
|
-
* Abstraction that
|
|
11
|
-
*
|
|
12
|
-
*
|
|
17
|
+
* Abstraction that holds a UserSession, along with
|
|
18
|
+
* getters to streamline access to various platform
|
|
19
|
+
* urls, and common constructs like IRequestOptions
|
|
13
20
|
*
|
|
14
|
-
*
|
|
21
|
+
* Thin class just used to enable getters
|
|
15
22
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
23
|
+
* This class should not be used by anything other than
|
|
24
|
+
* the ArcGISContextManager class
|
|
18
25
|
*/
|
|
19
26
|
class ArcGISContext {
|
|
20
|
-
/**
|
|
21
|
-
* Private constructor. Use `ArcGISContext.create(...)` to
|
|
22
|
-
* instantiate an instance
|
|
23
|
-
* @param opts
|
|
24
|
-
*/
|
|
25
27
|
constructor(opts) {
|
|
26
28
|
this._portalUrl = "https://www.arcgis.com";
|
|
27
|
-
this.
|
|
28
|
-
|
|
29
|
-
this.
|
|
30
|
-
if (opts.debug) {
|
|
31
|
-
this._debug = opts.debug;
|
|
32
|
-
}
|
|
33
|
-
this.log(`ArcGISContext:ctor: Creating ${this.id}`);
|
|
29
|
+
this.id = opts.id;
|
|
30
|
+
this._portalUrl = opts.portalUrl;
|
|
31
|
+
this._hubUrl = opts.hubUrl;
|
|
34
32
|
if (opts.authentication) {
|
|
35
33
|
this._authentication = opts.authentication;
|
|
36
|
-
this._portalUrl = this._authentication.portal.replace("/sharing/rest", "");
|
|
37
|
-
this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
|
|
38
|
-
}
|
|
39
|
-
else if (opts.portalUrl) {
|
|
40
|
-
this._portalUrl = opts.portalUrl;
|
|
41
|
-
this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
|
|
42
34
|
}
|
|
43
|
-
|
|
44
|
-
this.
|
|
45
|
-
}
|
|
46
|
-
if (opts.portal) {
|
|
47
|
-
this._portalSelf = _1.cloneObject(opts.portal);
|
|
35
|
+
if (opts.portalSelf) {
|
|
36
|
+
this._portalSelf = opts.portalSelf;
|
|
48
37
|
}
|
|
49
38
|
if (opts.currentUser) {
|
|
50
|
-
this._currentUser =
|
|
39
|
+
this._currentUser = opts.currentUser;
|
|
51
40
|
}
|
|
52
41
|
}
|
|
53
42
|
/**
|
|
54
|
-
*
|
|
55
|
-
* @param opts
|
|
56
|
-
* @returns
|
|
43
|
+
* Return the UserSession if authenticated
|
|
57
44
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
await ctx.initialize();
|
|
61
|
-
return ctx;
|
|
45
|
+
get session() {
|
|
46
|
+
return this._authentication;
|
|
62
47
|
}
|
|
63
48
|
/**
|
|
64
|
-
*
|
|
65
|
-
* This should be called when a user signs into a running
|
|
66
|
-
* application.
|
|
67
|
-
* @param auth
|
|
49
|
+
* Return boolean indicating if authenticatio is present
|
|
68
50
|
*/
|
|
69
|
-
|
|
70
|
-
this._authentication
|
|
71
|
-
this._portalUrl = auth.portal.replace("/sharing/rest", "");
|
|
72
|
-
await this.initialize();
|
|
51
|
+
get isAuthenticated() {
|
|
52
|
+
return !!this._authentication;
|
|
73
53
|
}
|
|
74
54
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
55
|
+
* Return `IUserRequestOptions`, which is used for REST-JS
|
|
56
|
+
* functions which require authentication information.
|
|
57
|
+
*
|
|
58
|
+
* If context is not authenticated, this function will throw
|
|
78
59
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
60
|
+
get userRequestOptions() {
|
|
61
|
+
if (this.isAuthenticated) {
|
|
62
|
+
return {
|
|
63
|
+
authentication: this._authentication,
|
|
64
|
+
portal: this.sharingApiUrl,
|
|
65
|
+
};
|
|
84
66
|
}
|
|
85
|
-
// Clear the auth, portalSelf and currentUser props
|
|
86
|
-
this._authentication = null;
|
|
87
|
-
this._portalSelf = null;
|
|
88
|
-
this._currentUser = null;
|
|
89
|
-
this._state = new ArcGISContextState_1.ArcGISContextState({
|
|
90
|
-
id: this.id,
|
|
91
|
-
portalUrl: this._portalUrl,
|
|
92
|
-
hubUrl: this._hubUrl,
|
|
93
|
-
});
|
|
94
67
|
}
|
|
95
68
|
/**
|
|
96
|
-
* Return
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
69
|
+
* Return `IRequestOptions`, which is used by REST-JS functions
|
|
70
|
+
* which *may* use authentication information if provided.
|
|
71
|
+
*
|
|
72
|
+
* If context is not authenticated, this function just returns
|
|
73
|
+
* the `portal` property, which informs REST-JS what Sharing API
|
|
74
|
+
* instance to use (i.e. AGO, Enterprise etc)
|
|
100
75
|
*/
|
|
101
|
-
get
|
|
102
|
-
|
|
76
|
+
get requestOptions() {
|
|
77
|
+
let ro = {
|
|
78
|
+
portal: this.sharingApiUrl,
|
|
79
|
+
};
|
|
80
|
+
if (this.isAuthenticated) {
|
|
81
|
+
ro = {
|
|
82
|
+
authentication: this._authentication,
|
|
83
|
+
portal: this.sharingApiUrl,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return ro;
|
|
103
87
|
}
|
|
104
88
|
/**
|
|
105
|
-
*
|
|
106
|
-
* Log debugging messages to the console
|
|
107
|
-
* @param message
|
|
89
|
+
* Return a `IHubRequestOptions` object
|
|
108
90
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
91
|
+
get hubRequestOptions() {
|
|
92
|
+
// We may add more logic around what is returned in some corner cases
|
|
93
|
+
return {
|
|
94
|
+
authentication: this.session,
|
|
95
|
+
isPortal: this.isPortal,
|
|
96
|
+
portalSelf: this.portal,
|
|
97
|
+
hubApiUrl: this.hubUrl,
|
|
98
|
+
};
|
|
114
99
|
}
|
|
115
100
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
101
|
+
* Return the portal url.
|
|
102
|
+
*
|
|
103
|
+
* If authenticated @ ArcGIS Online, it will return
|
|
104
|
+
* the https://org.env.arcgis.com
|
|
105
|
+
*
|
|
106
|
+
* If authenticated @ ArcGIS Enterprise, it will return
|
|
107
|
+
* https://portalHostname, which includes the web adaptor
|
|
118
108
|
*/
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const username = this._authentication.username;
|
|
124
|
-
const requests = [
|
|
125
|
-
arcgis_rest_portal_1.getSelf({ authentication: this._authentication }),
|
|
126
|
-
arcgis_rest_portal_1.getUser({ username, authentication: this._authentication }),
|
|
127
|
-
];
|
|
128
|
-
try {
|
|
129
|
-
const [portal, user] = await Promise.all(requests);
|
|
130
|
-
this._portalSelf = portal;
|
|
131
|
-
this._currentUser = user;
|
|
109
|
+
get portalUrl() {
|
|
110
|
+
if (this.isAuthenticated) {
|
|
111
|
+
if (this.isPortal) {
|
|
112
|
+
return `https://${this._portalSelf.portalHostname}`;
|
|
132
113
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// tslint:disable-next-line:no-console
|
|
136
|
-
console.error(msg);
|
|
137
|
-
throw ex;
|
|
114
|
+
else {
|
|
115
|
+
return `https://${this._portalSelf.urlKey}.${this._portalSelf.customBaseUrl}`;
|
|
138
116
|
}
|
|
139
117
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
get stateOpts() {
|
|
144
|
-
const stateOpts = {
|
|
145
|
-
id: this.id,
|
|
146
|
-
portalUrl: this._portalUrl,
|
|
147
|
-
hubUrl: this._hubUrl,
|
|
148
|
-
};
|
|
149
|
-
if (this._authentication) {
|
|
150
|
-
stateOpts.authentication = this._authentication;
|
|
118
|
+
else {
|
|
119
|
+
return this._portalUrl;
|
|
151
120
|
}
|
|
152
|
-
|
|
153
|
-
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Returns the url to the sharing api
|
|
124
|
+
* i.e. https://myorg.maps.arcgis.com/sharing/rest
|
|
125
|
+
*/
|
|
126
|
+
get sharingApiUrl() {
|
|
127
|
+
return `${this.portalUrl}/sharing/rest`;
|
|
128
|
+
}
|
|
129
|
+
get hubUrl() {
|
|
130
|
+
return this._hubUrl;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Returns boolean indicating if the backing system
|
|
134
|
+
* is ArcGIS Enterprise (formerly ArcGIS Portal) or not
|
|
135
|
+
*/
|
|
136
|
+
get isPortal() {
|
|
137
|
+
return this._portalSelf
|
|
138
|
+
? this._portalSelf.isPortal
|
|
139
|
+
: this._portalUrl.indexOf("arcgis.com") === -1;
|
|
140
|
+
}
|
|
141
|
+
// Hub APIs
|
|
142
|
+
// ----------
|
|
143
|
+
// Discussions
|
|
144
|
+
get discussionsServiceUrl() {
|
|
145
|
+
if (this._hubUrl) {
|
|
146
|
+
return `${this._hubUrl}${hubApiEndpoints.discussions}`;
|
|
154
147
|
}
|
|
155
|
-
|
|
156
|
-
|
|
148
|
+
}
|
|
149
|
+
// Hub Search
|
|
150
|
+
get hubSearchServiceUrl() {
|
|
151
|
+
if (this._hubUrl) {
|
|
152
|
+
return `${this._hubUrl}${hubApiEndpoints.search}`;
|
|
157
153
|
}
|
|
158
|
-
return stateOpts;
|
|
159
154
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
* If the passed url is not recognized, then this will return `undefined`
|
|
166
|
-
* @param portalUrl
|
|
167
|
-
* @returns
|
|
168
|
-
*/
|
|
169
|
-
function getHubApiFromPortalUrl(portalUrl) {
|
|
170
|
-
let result;
|
|
171
|
-
if (portalUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
|
|
172
|
-
result = "https://hubqa.arcgis.com";
|
|
155
|
+
// Domain
|
|
156
|
+
get domainServiceUrl() {
|
|
157
|
+
if (this._hubUrl) {
|
|
158
|
+
return `${this._hubUrl}${hubApiEndpoints.domains}`;
|
|
159
|
+
}
|
|
173
160
|
}
|
|
174
|
-
|
|
175
|
-
|
|
161
|
+
// Events
|
|
162
|
+
// returns `{serviceId: '3ef..', publicViewId: 'bc3...'}
|
|
163
|
+
get eventsConfig() {
|
|
164
|
+
if (this._portalSelf) {
|
|
165
|
+
return _1.getProp(this._portalSelf, "portalProperties.hub.settings.events");
|
|
166
|
+
}
|
|
176
167
|
}
|
|
177
|
-
|
|
178
|
-
|
|
168
|
+
/**
|
|
169
|
+
* Returns boolean indicating if the current user
|
|
170
|
+
* belongs to an organization that has licensed
|
|
171
|
+
* ArcGIS Hub
|
|
172
|
+
*/
|
|
173
|
+
get hubEnabled() {
|
|
174
|
+
return _1.getWithDefault(this._portalSelf, "portalProperties.hub.enabled", false);
|
|
179
175
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
176
|
+
/**
|
|
177
|
+
* Return Hub Community Org Id, if defined
|
|
178
|
+
*/
|
|
179
|
+
get communityOrgId() {
|
|
180
|
+
if (this._portalSelf) {
|
|
181
|
+
return _1.getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.orgId");
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
get communityOrgHostname() {
|
|
185
|
+
if (this._portalSelf) {
|
|
186
|
+
return _1.getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.portalHostname");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
get communityOrgUrl() {
|
|
190
|
+
if (this.communityOrgHostname) {
|
|
191
|
+
return `https://${this.communityOrgHostname}`;
|
|
194
192
|
}
|
|
195
193
|
}
|
|
196
|
-
|
|
194
|
+
// Platform API service urls are all in helperServices
|
|
195
|
+
// and not consistent to expose as urls
|
|
196
|
+
get helperServices() {
|
|
197
|
+
if (this._portalSelf) {
|
|
198
|
+
return this._portalSelf.helperServices;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
get currentUser() {
|
|
202
|
+
return this._currentUser;
|
|
203
|
+
}
|
|
204
|
+
get portal() {
|
|
205
|
+
return this._portalSelf;
|
|
206
|
+
}
|
|
197
207
|
}
|
|
208
|
+
exports.ArcGISContext = ArcGISContext;
|
|
198
209
|
//# 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,wBAAgE;AAEhE;;;GAGG;AACH,MAAM,eAAe,GAAG;IACtB,OAAO,EAAE,iBAAiB;IAC1B,MAAM,EAAE,kBAAkB;IAC1B,WAAW,EAAE,qBAAqB;CACnC,CAAC;AA+CF;;;;;;;;;;;GAWG;AACH,MAAa,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;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ACnB,IAAI,CAAC,WAAW,EAChB,8BAA8B,EAC9B,KAAK,CACN,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,IAAW,cAAc;QACvB,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO,UAAO,CACZ,IAAI,CAAC,WAAW,EAChB,kDAAkD,CACnD,CAAC;SACH;IACH,CAAC;IAED,IAAW,oBAAoB;QAC7B,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO,UAAO,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;AA7ND,sCA6NC"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArcGISContextManager = void 0;
|
|
4
|
+
const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
|
|
5
|
+
const ArcGISContext_1 = require("./ArcGISContext");
|
|
6
|
+
const _1 = require(".");
|
|
7
|
+
const getHubApiFromPortalUrl_1 = require("./urls/getHubApiFromPortalUrl");
|
|
8
|
+
const getPortalBaseFromOrgUrl_1 = require("./urls/getPortalBaseFromOrgUrl");
|
|
9
|
+
/**
|
|
10
|
+
* ArcGIS Context Manager
|
|
11
|
+
*
|
|
12
|
+
* The manager exposes context (`IArcGISContext`), which combines a `UserSession` with
|
|
13
|
+
* the `portal/self` and `user/self` responses to provide a central lookup for platform
|
|
14
|
+
* information, api urls, and other useful properties for developers such as IRequestOptions
|
|
15
|
+
* IUserRequestOptions, IHubRequestOptions etc.
|
|
16
|
+
*
|
|
17
|
+
* The context is exposed on gthe `.context` property, and as the authentication changes
|
|
18
|
+
* the `.context` is re-created. This is done to allow web frameworks to watch for
|
|
19
|
+
* changes on that single property, instead of having to leverage observers or events
|
|
20
|
+
* for change detection.
|
|
21
|
+
*
|
|
22
|
+
* This is a work-in-progress, and will likely expand over time.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
class ArcGISContextManager {
|
|
26
|
+
/**
|
|
27
|
+
* Private constructor. Use `ArcGISContextManager.create(...)` to
|
|
28
|
+
* instantiate an instance
|
|
29
|
+
* @param opts
|
|
30
|
+
*/
|
|
31
|
+
constructor(opts) {
|
|
32
|
+
this._portalUrl = "https://www.arcgis.com";
|
|
33
|
+
this._logLevel = _1.Level.error;
|
|
34
|
+
// Having a unique id makes debugging easier
|
|
35
|
+
this.id = new Date().getTime();
|
|
36
|
+
if (opts.logLevel) {
|
|
37
|
+
this._logLevel = opts.logLevel;
|
|
38
|
+
}
|
|
39
|
+
_1.Logger.setLogLevel(this._logLevel);
|
|
40
|
+
_1.Logger.debug(`ArcGISContextManager:ctor: Creating ${this.id}`);
|
|
41
|
+
if (opts.authentication) {
|
|
42
|
+
this._authentication = opts.authentication;
|
|
43
|
+
this._portalUrl = this._authentication.portal.replace("/sharing/rest", "");
|
|
44
|
+
this._hubUrl = getHubApiFromPortalUrl_1.getHubApiFromPortalUrl(this._portalUrl);
|
|
45
|
+
}
|
|
46
|
+
else if (opts.portalUrl) {
|
|
47
|
+
this._portalUrl = opts.portalUrl;
|
|
48
|
+
this._hubUrl = getHubApiFromPortalUrl_1.getHubApiFromPortalUrl(this._portalUrl);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this._hubUrl = getHubApiFromPortalUrl_1.getHubApiFromPortalUrl(this._portalUrl);
|
|
52
|
+
}
|
|
53
|
+
if (opts.portal) {
|
|
54
|
+
this._portalSelf = _1.cloneObject(opts.portal);
|
|
55
|
+
}
|
|
56
|
+
if (opts.currentUser) {
|
|
57
|
+
this._currentUser = _1.cloneObject(opts.currentUser);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Static async Factory
|
|
62
|
+
* @param opts
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
static async create(opts = {}) {
|
|
66
|
+
const ctx = new ArcGISContextManager(opts);
|
|
67
|
+
await ctx.initialize();
|
|
68
|
+
return ctx;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Set the Authentication (UserSession) for the context.
|
|
72
|
+
* This should be called when a user signs into a running
|
|
73
|
+
* application.
|
|
74
|
+
* @param auth
|
|
75
|
+
*/
|
|
76
|
+
async setAuthentication(auth) {
|
|
77
|
+
this._authentication = auth;
|
|
78
|
+
this._portalUrl = auth.portal.replace("/sharing/rest", "");
|
|
79
|
+
await this.initialize();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Clear the Authentication (UserSession). This should be
|
|
83
|
+
* called when a user signs out of an application, but
|
|
84
|
+
* the application continues running
|
|
85
|
+
*/
|
|
86
|
+
clearAuthentication() {
|
|
87
|
+
// Reset the portalUrl from the org url to the base url
|
|
88
|
+
// for ArcGIS Enterprise, we just leave the _portalUrl as-is
|
|
89
|
+
if (!this._context.isPortal) {
|
|
90
|
+
this._portalUrl = getPortalBaseFromOrgUrl_1.getPortalBaseFromOrgUrl(this._portalUrl);
|
|
91
|
+
}
|
|
92
|
+
// Clear the auth, portalSelf and currentUser props
|
|
93
|
+
this._authentication = null;
|
|
94
|
+
this._portalSelf = null;
|
|
95
|
+
this._currentUser = null;
|
|
96
|
+
this._context = new ArcGISContext_1.ArcGISContext({
|
|
97
|
+
id: this.id,
|
|
98
|
+
portalUrl: this._portalUrl,
|
|
99
|
+
hubUrl: this._hubUrl,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Return a reference to the current state.
|
|
104
|
+
* When `.setAuthentication()` or `.clearAuthenentication()` are
|
|
105
|
+
* called, the state will be re-created. This is done so frameworks
|
|
106
|
+
* like React or Ember can detect changes.
|
|
107
|
+
*/
|
|
108
|
+
get context() {
|
|
109
|
+
return this._context;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* If we have a UserSession, fetch portal/self and
|
|
113
|
+
* store that along with current user
|
|
114
|
+
*/
|
|
115
|
+
async initialize() {
|
|
116
|
+
// if we have auth, and don't have portalSelf or currentUser, fetch them
|
|
117
|
+
if (this._authentication && (!this._portalSelf || !this._currentUser)) {
|
|
118
|
+
_1.Logger.debug(`ArcGISContextManager-${this.id}: Initializing`);
|
|
119
|
+
const username = this._authentication.username;
|
|
120
|
+
const requests = [
|
|
121
|
+
arcgis_rest_portal_1.getSelf({ authentication: this._authentication }),
|
|
122
|
+
arcgis_rest_portal_1.getUser({ username, authentication: this._authentication }),
|
|
123
|
+
];
|
|
124
|
+
try {
|
|
125
|
+
const [portal, user] = await Promise.all(requests);
|
|
126
|
+
this._portalSelf = portal;
|
|
127
|
+
this._currentUser = user;
|
|
128
|
+
_1.Logger.debug(`ArcGISContextManager-${this.id}: received portalSelf and currentUser`);
|
|
129
|
+
}
|
|
130
|
+
catch (ex) {
|
|
131
|
+
const msg = `ArcGISContextManager could not fetch portal & user for "${this._authentication.username}" using ${this._authentication.portal}.`;
|
|
132
|
+
_1.Logger.error(msg);
|
|
133
|
+
// tslint:disable-next-line:no-console
|
|
134
|
+
console.error(msg);
|
|
135
|
+
throw ex;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
_1.Logger.debug(`ArcGISContextManager-${this.id}: updating context`);
|
|
139
|
+
// update the context
|
|
140
|
+
this._context = new ArcGISContext_1.ArcGISContext(this.contextOpts);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Getter to streamline the creation of updated Context instances
|
|
144
|
+
*/
|
|
145
|
+
get contextOpts() {
|
|
146
|
+
const contextOpts = {
|
|
147
|
+
id: this.id,
|
|
148
|
+
portalUrl: this._portalUrl,
|
|
149
|
+
hubUrl: this._hubUrl,
|
|
150
|
+
};
|
|
151
|
+
if (this._authentication) {
|
|
152
|
+
contextOpts.authentication = this._authentication;
|
|
153
|
+
}
|
|
154
|
+
if (this._portalSelf) {
|
|
155
|
+
contextOpts.portalSelf = this._portalSelf;
|
|
156
|
+
}
|
|
157
|
+
if (this._currentUser) {
|
|
158
|
+
contextOpts.currentUser = this._currentUser;
|
|
159
|
+
}
|
|
160
|
+
return contextOpts;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.ArcGISContextManager = ArcGISContextManager;
|
|
164
|
+
//# sourceMappingURL=ArcGISContextManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArcGISContextManager.js","sourceRoot":"","sources":["../../src/ArcGISContextManager.ts"],"names":[],"mappings":";;;AAAA,iEAAqE;AAErE,mDAIyB;AACzB,wBAA+C;AAC/C,0EAAuE;AACvE,4EAAyE;AA4CzE;;;;;;;;;;;;;;;GAeG;AACH,MAAa,oBAAoB;IAsB/B;;;;OAIG;IACH,YAAoB,IAAkC;QAf9C,eAAU,GAAW,wBAAwB,CAAC;QAQ9C,cAAS,GAAU,QAAK,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,SAAM,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACnC,SAAM,CAAC,KAAK,CAAC,uCAAuC,IAAI,CAAC,EAAE,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24
|
tslib_1.__exportStar(require("./i18n"), exports);
|
|
25
25
|
tslib_1.__exportStar(require("./request"), exports);
|
|
26
26
|
tslib_1.__exportStar(require("./surveys"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./ArcGISContextManager"), exports);
|
|
27
28
|
tslib_1.__exportStar(require("./ArcGISContext"), exports);
|
|
28
29
|
const OperationStack_1 = require("./OperationStack");
|
|
29
30
|
exports.OperationStack = OperationStack_1.default;
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;gBACgB;;;;AAEhB,mDAAyB;AACzB,gDAAsB;AACtB,iDAAuB;AACvB,uDAA6B;AAC7B,oDAA0B;AAC1B,sDAA4B;AAC5B,mDAAyB;AACzB,mDAAyB;AACzB,kDAAwB;AACxB,oDAA0B;AAC1B,sDAA4B;AAC5B,mDAAyB;AACzB,kDAAwB;AACxB,kDAAwB;AACxB,iDAAuB;AACvB,iDAAuB;AACvB,kDAAwB;AACxB,iDAAuB;AACvB,oDAA0B;AAC1B,oDAA0B;AAC1B,0DAAgC;AAEhC,qDAA8C;AAIrC,yBAJF,wBAAc,CAIE;AAHvB,qDAA8C;AAGrB,yBAHlB,wBAAc,CAGkB;AACvC,6BAAkC;AAAzB,4FAAA,IAAI,OAAA;AAAE,4FAAA,IAAI,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;gBACgB;;;;AAEhB,mDAAyB;AACzB,gDAAsB;AACtB,iDAAuB;AACvB,uDAA6B;AAC7B,oDAA0B;AAC1B,sDAA4B;AAC5B,mDAAyB;AACzB,mDAAyB;AACzB,kDAAwB;AACxB,oDAA0B;AAC1B,sDAA4B;AAC5B,mDAAyB;AACzB,kDAAwB;AACxB,kDAAwB;AACxB,iDAAuB;AACvB,iDAAuB;AACvB,kDAAwB;AACxB,iDAAuB;AACvB,oDAA0B;AAC1B,oDAA0B;AAC1B,iEAAuC;AACvC,0DAAgC;AAEhC,qDAA8C;AAIrC,yBAJF,wBAAc,CAIE;AAHvB,qDAA8C;AAGrB,yBAHlB,wBAAc,CAGkB;AACvC,6BAAkC;AAAzB,4FAAA,IAAI,OAAA;AAAE,4FAAA,IAAI,OAAA"}
|
|
@@ -17,13 +17,12 @@ async function _searchContent(filter, options) {
|
|
|
17
17
|
// API
|
|
18
18
|
const api = _1.expandApi(options.api || "arcgis");
|
|
19
19
|
let searchPromise;
|
|
20
|
-
// map over the apis, depending on the type we issue the queries
|
|
21
|
-
// const searchPromises = apis.map((api) => {
|
|
22
20
|
// Portal Search
|
|
23
21
|
if (api.type === "arcgis") {
|
|
24
22
|
// serialize for portal
|
|
25
23
|
const so = content_utils_1.serializeContentFilterForPortal(expanded);
|
|
26
|
-
//
|
|
24
|
+
// if we have auth, pass it forward
|
|
25
|
+
// otherwise set the portal property
|
|
27
26
|
if (options.authentication) {
|
|
28
27
|
so.authentication = options.authentication;
|
|
29
28
|
}
|
|
@@ -36,7 +35,6 @@ async function _searchContent(filter, options) {
|
|
|
36
35
|
so.countSize = 200;
|
|
37
36
|
}
|
|
38
37
|
// copy over various options
|
|
39
|
-
// TODO: Dry this up - typscript makes this... inconvenient
|
|
40
38
|
if (options.num) {
|
|
41
39
|
so.num = options.num;
|
|
42
40
|
}
|
|
@@ -64,8 +62,6 @@ async function _searchContent(filter, options) {
|
|
|
64
62
|
},
|
|
65
63
|
});
|
|
66
64
|
}
|
|
67
|
-
// });
|
|
68
|
-
// return for results
|
|
69
65
|
return searchPromise;
|
|
70
66
|
}
|
|
71
67
|
exports._searchContent = _searchContent;
|
|
@@ -78,12 +74,27 @@ exports._searchContent = _searchContent;
|
|
|
78
74
|
* @returns
|
|
79
75
|
*/
|
|
80
76
|
function searchPortal(searchOptions) {
|
|
77
|
+
var _a;
|
|
78
|
+
const portalUrl = ((_a = searchOptions.authentication) === null || _a === void 0 ? void 0 : _a.portal) || searchOptions.portal;
|
|
79
|
+
let token;
|
|
80
|
+
if (searchOptions.authentication) {
|
|
81
|
+
const us = searchOptions.authentication;
|
|
82
|
+
token = us.token;
|
|
83
|
+
}
|
|
84
|
+
const thumbnailify = (content) => {
|
|
85
|
+
content.thumbnailUrl = __1.getItemThumbnailUrl(content, portalUrl, token);
|
|
86
|
+
return content;
|
|
87
|
+
};
|
|
81
88
|
return arcgis_rest_portal_1.searchItems(searchOptions).then((resp) => {
|
|
82
89
|
const hasNext = resp.nextStart > -1;
|
|
90
|
+
// convert items to IHubContent's
|
|
83
91
|
let content = resp.results.map(__1.itemToContent);
|
|
92
|
+
// if we have a site, add those urls
|
|
84
93
|
if (searchOptions.site) {
|
|
85
94
|
content = content.map((entry) => __1.setContentSiteUrls(entry, searchOptions.site));
|
|
86
95
|
}
|
|
96
|
+
// add thumbnailUrl
|
|
97
|
+
content = content.map(thumbnailify);
|
|
87
98
|
// convert aggregations into facets
|
|
88
99
|
const facets = content_utils_1.convertPortalResponseToFacets(resp);
|
|
89
100
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_searchContent.js","sourceRoot":"","sources":["../../../src/search/_searchContent.ts"],"names":[],"mappings":";;;AAAA,mDAIyB;AAOzB,iEAAuE;AACvE,wBAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"_searchContent.js","sourceRoot":"","sources":["../../../src/search/_searchContent.ts"],"names":[],"mappings":";;;AAAA,mDAIyB;AAOzB,iEAAuE;AACvE,wBAA+C;AAC/C,0BAOY;AAGZ;;;;GAIG;AACI,KAAK,UAAU,cAAc,CAClC,MAAyB,EACzB,OAA0B;;IAE1B,kDAAkD;IAClD,MAAM,QAAQ,GAAG,mCAAmB,CAAC,MAAM,CAAC,CAAC;IAE7C,MAAM;IACN,MAAM,GAAG,GAAG,YAAS,CAAC,OAAO,CAAC,GAAG,IAAI,QAAQ,CAAC,CAAC;IAE/C,IAAI,aAAa,CAAC;IAClB,gBA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