@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.
- package/dist/es2017/ArcGISContext.js +205 -0
- package/dist/es2017/ArcGISContext.js.map +1 -0
- package/dist/es2017/ArcGISContextManager.js +160 -0
- package/dist/es2017/ArcGISContextManager.js.map +1 -0
- package/dist/es2017/index.js +2 -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/es2017/utils/index.js +1 -0
- package/dist/es2017/utils/index.js.map +1 -1
- package/dist/es2017/utils/sessionLocalStorage.js +47 -0
- package/dist/es2017/utils/sessionLocalStorage.js.map +1 -0
- package/dist/esm/ArcGISContext.js +287 -0
- package/dist/esm/ArcGISContext.js.map +1 -0
- package/dist/esm/ArcGISContextManager.js +204 -0
- package/dist/esm/ArcGISContextManager.js.map +1 -0
- package/dist/esm/index.js +2 -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/esm/utils/index.js +1 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/sessionLocalStorage.js +50 -0
- package/dist/esm/utils/sessionLocalStorage.js.map +1 -0
- package/dist/node/ArcGISContext.js +209 -0
- package/dist/node/ArcGISContext.js.map +1 -0
- package/dist/node/ArcGISContextManager.js +164 -0
- package/dist/node/ArcGISContextManager.js.map +1 -0
- package/dist/node/index.js +2 -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/node/utils/index.js +1 -0
- package/dist/node/utils/index.js.map +1 -1
- package/dist/node/utils/sessionLocalStorage.js +53 -0
- package/dist/node/utils/sessionLocalStorage.js.map +1 -0
- package/dist/types/ArcGISContext.d.ts +136 -0
- package/dist/types/ArcGISContextManager.d.ts +113 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/search/utils.d.ts +1 -1
- package/dist/types/types.d.ts +5 -2
- 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/types/utils/index.d.ts +1 -0
- package/dist/types/utils/sessionLocalStorage.d.ts +23 -0
- package/dist/umd/common.umd.js +3330 -2709
- 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
|
@@ -12,26 +12,21 @@ import { cloneObject, getGroupThumbnailUrl } from "..";
|
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
14
|
export function _searchGroups(filter, options) {
|
|
15
|
-
var _a;
|
|
16
15
|
return __awaiter(this, void 0, void 0, function () {
|
|
17
|
-
var expanded, api, so
|
|
18
|
-
return __generator(this, function (
|
|
16
|
+
var expanded, api, so;
|
|
17
|
+
return __generator(this, function (_a) {
|
|
19
18
|
expanded = expandGroupFilter(filter);
|
|
20
19
|
api = expandApi(options.api || "arcgis");
|
|
21
20
|
if (api.type === "arcgis") {
|
|
22
21
|
so = serializeGroupFilterForPortal(expanded);
|
|
23
|
-
token = "";
|
|
24
22
|
// if we have auth, pass it forward
|
|
25
23
|
// otherwise set the portal property
|
|
26
24
|
if (options.authentication) {
|
|
27
25
|
so.authentication = options.authentication;
|
|
28
|
-
us = options.authentication;
|
|
29
|
-
token = us.token;
|
|
30
26
|
}
|
|
31
27
|
else {
|
|
32
28
|
so.portal = api.url + "/sharing/rest";
|
|
33
29
|
}
|
|
34
|
-
// TODO: Dry this up - typscript makes this... inconvenient
|
|
35
30
|
if (options.num) {
|
|
36
31
|
so.num = options.num;
|
|
37
32
|
}
|
|
@@ -41,10 +36,6 @@ export function _searchGroups(filter, options) {
|
|
|
41
36
|
if (options.sortOrder) {
|
|
42
37
|
so.sortOrder = options.sortOrder;
|
|
43
38
|
}
|
|
44
|
-
portalUrl = api.url + "/sharing/rest";
|
|
45
|
-
if ((_a = so.authentication) === null || _a === void 0 ? void 0 : _a.portal) {
|
|
46
|
-
portalUrl = so.authentication.portal;
|
|
47
|
-
}
|
|
48
39
|
if (options.site) {
|
|
49
40
|
so.site = cloneObject(options.site);
|
|
50
41
|
}
|
|
@@ -68,8 +59,7 @@ function searchPortalGroups(searchOptions) {
|
|
|
68
59
|
group.siteTeamUrl = searchOptions.site.item.url + "/teams/" + group.id + "/about";
|
|
69
60
|
return group;
|
|
70
61
|
};
|
|
71
|
-
var portalUrl = ((_a = searchOptions.authentication) === null || _a === void 0 ? void 0 : _a.portal) ||
|
|
72
|
-
"https://www.arcgis.com/sharing/rest";
|
|
62
|
+
var portalUrl = ((_a = searchOptions.authentication) === null || _a === void 0 ? void 0 : _a.portal) || searchOptions.portal;
|
|
73
63
|
var token;
|
|
74
64
|
if (searchOptions.authentication) {
|
|
75
65
|
var us = searchOptions.authentication;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_searchGroups.js","sourceRoot":"","sources":["../../../src/search/_searchGroups.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,GAAG,CAAC;AAC/C,OAAO,EACL,iBAAiB,EACjB,6BAA6B,GAC9B,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAmB,MAAM,IAAI,CAAC;AAMxE;;;;;;;GAOG;AACH,MAAM,UAAgB,aAAa,CACjC,MAAuB,EACvB,OAA0B
|
|
1
|
+
{"version":3,"file":"_searchGroups.js","sourceRoot":"","sources":["../../../src/search/_searchGroups.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,GAAG,CAAC;AAC/C,OAAO,EACL,iBAAiB,EACjB,6BAA6B,GAC9B,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAmB,MAAM,IAAI,CAAC;AAMxE;;;;;;;GAOG;AACH,MAAM,UAAgB,aAAa,CACjC,MAAuB,EACvB,OAA0B;;;;YAGpB,QAAQ,GAAG,iBAAiB,CAAC,MAAM,CAAC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I,aAAa,CAAC,MAAM,CAAC;IAC/D,IAAI,KAAa,CAAC;IAClB,IAAI,aAAa,CAAC,cAAc,EAAE;QAChC,IAAM,EAAE,GAAgB,aAAa,CAAC,cAA6B,CAAC;QACpE,KAAK,GAAG,EAAE,CAAC,KAAK,CAAC;KAClB;IAED,IAAM,YAAY,GAAG,UAAC,KAAa;QACjC,KAAK,CAAC,YAAY,GAAG,oBAAoB,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QACnE,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IAEF,qBAAqB;IACrB,OAAO,iBAAiB,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,UAAC,QAAQ;;QACpD,IAAM,OAAO,GAAY,QAAQ,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;QAEjD,wBAAwB;QACxB,IAAI,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACjD,qDAAqD;QACrD,gBAAI,aAAa,CAAC,IAAI,0CAAE,IAAI,0CAAE,GAAG,EAAE;YACjC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;SAC7C;QAED,OAAO;YACL,OAAO,SAAA;YACP,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,OAAO,SAAA;YACP,IAAI,EAAE,eAAe,CACnB,aAAa,EACb,QAAQ,CAAC,SAAS,EAClB,QAAQ,CAAC,KAAK,EACd,kBAAkB,CACnB;SACyB,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/esm/search/utils.js
CHANGED
|
@@ -349,7 +349,7 @@ export function getNextFunction(request, nextStart, total, fn) {
|
|
|
349
349
|
* Construct a the full url to a group thumbnail
|
|
350
350
|
*
|
|
351
351
|
* - If the group has a thumbnail, construct the full url
|
|
352
|
-
* - If the group is not public, append on the token
|
|
352
|
+
* - If the group is not public, append on the token (if passed in)
|
|
353
353
|
* @param portalUrl
|
|
354
354
|
* @param group
|
|
355
355
|
* @param token
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-walk from a portalUrl to the corresponding Hub API Url
|
|
3
|
+
*
|
|
4
|
+
* If the passed url is not recognized, then this will return `undefined`
|
|
5
|
+
* @param portalUrl
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export function getHubApiFromPortalUrl(portalUrl) {
|
|
9
|
+
var result;
|
|
10
|
+
if (portalUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
|
|
11
|
+
result = "https://hubqa.arcgis.com";
|
|
12
|
+
}
|
|
13
|
+
else if (portalUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
|
|
14
|
+
result = "https://hubdev.arcgis.com";
|
|
15
|
+
}
|
|
16
|
+
else if (portalUrl.match(/(www|\.maps)\.arcgis.com/)) {
|
|
17
|
+
result = "https://hub.arcgis.com";
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=getHubApiFromPortalUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHubApiFromPortalUrl.js","sourceRoot":"","sources":["../../../src/urls/getHubApiFromPortalUrl.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,UAAU,sBAAsB,CAAC,SAAiB;IACtD,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"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given an org url, get the portal base url
|
|
3
|
+
*
|
|
4
|
+
* i.e. https://myorg.maps.arcgis.com will return https://www.arcgis.com
|
|
5
|
+
*
|
|
6
|
+
* @param orgUrl
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export function getPortalBaseFromOrgUrl(orgUrl) {
|
|
10
|
+
var result = orgUrl;
|
|
11
|
+
if (orgUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
|
|
12
|
+
result = "https://qaext.arcgis.com";
|
|
13
|
+
}
|
|
14
|
+
else if (orgUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
|
|
15
|
+
result = "https://devext.arcgis.com";
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
/* istanbul ignore else */
|
|
19
|
+
if (orgUrl.match(/(www|\.maps)\.arcgis.com/)) {
|
|
20
|
+
result = "https://www.arcgis.com";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=getPortalBaseFromOrgUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPortalBaseFromOrgUrl.js","sourceRoot":"","sources":["../../../src/urls/getPortalBaseFromOrgUrl.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAc;IACpD,IAAI,MAAM,GAAG,MAAM,CAAC;IAEpB,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"}
|
package/dist/esm/urls/index.js
CHANGED
|
@@ -14,6 +14,8 @@ export * from "./get-item-home-url";
|
|
|
14
14
|
export * from "./get-item-api-url";
|
|
15
15
|
export * from "./get-item-data-url";
|
|
16
16
|
export * from "./convert-urls-to-anchor-tags";
|
|
17
|
+
export * from "./getHubApiFromPortalUrl";
|
|
18
|
+
export * from "./getPortalBaseFromOrgUrl";
|
|
17
19
|
var MAP_OR_FEATURE_SERVER_URL_REGEX = /\/(map|feature)server/i;
|
|
18
20
|
/**
|
|
19
21
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/urls/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iBAAiB,CAAC;AAChC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/urls/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACj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U,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,50 @@
|
|
|
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) {
|
|
11
|
+
if (win === void 0) { win = window; }
|
|
12
|
+
if (win.localStorage) {
|
|
13
|
+
win.localStorage.removeItem("__CONTEXT_" + clientId);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Re-hydrate a UserSession from a browser's local storage.
|
|
18
|
+
* If not found,
|
|
19
|
+
* @param clientId oAuth Client Id
|
|
20
|
+
* @param win optional window (used for testing)
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export function getSession(clientId,
|
|
24
|
+
/* istanbul ignore next */
|
|
25
|
+
win) {
|
|
26
|
+
if (win === void 0) { win = window; }
|
|
27
|
+
var result = null;
|
|
28
|
+
if (win.localStorage) {
|
|
29
|
+
var serializedSession = win.localStorage.getItem("__CONTEXT_" + clientId);
|
|
30
|
+
if (serializedSession) {
|
|
31
|
+
result = UserSession.deserialize(serializedSession);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Serialize a UserSession into a browser's local storage
|
|
38
|
+
* @param clientId oAuth Client Id
|
|
39
|
+
* @param session UserSession
|
|
40
|
+
* @param win optional window (used for testing)
|
|
41
|
+
*/
|
|
42
|
+
export function saveSession(clientId, session,
|
|
43
|
+
/* istanbul ignore next */
|
|
44
|
+
win) {
|
|
45
|
+
if (win === void 0) { win = window; }
|
|
46
|
+
if (win.localStorage) {
|
|
47
|
+
win.localStorage.setItem("__CONTEXT_" + clientId, session.serialize());
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# 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,GAAiB;IAAjB,oBAAA,EAAA,YAAiB;IAEjB,IAAI,GAAG,CAAC,YAAY,EAAE;QACpB,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,eAAa,QAAU,CAAC,CAAC;KACtD;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACxB,QAAgB;AAChB,0BAA0B;AAC1B,GAAiB;IAAjB,oBAAA,EAAA,YAAiB;IAEjB,IAAI,MAAM,GAAuB,IAAI,CAAC;IACtC,IAAI,GAAG,CAAC,YAAY,EAAE;QACpB,IAAM,iBAAiB,GAAG,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,eAAa,QAAU,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,GAAiB;IAAjB,oBAAA,EAAA,YAAiB;IAEjB,IAAI,GAAG,CAAC,YAAY,EAAE;QACpB,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,eAAa,QAAU,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;KACxE;AACH,CAAC"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArcGISContext = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
/**
|
|
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
|
|
16
|
+
*
|
|
17
|
+
* Abstraction that holds a UserSession, along with
|
|
18
|
+
* getters to streamline access to various platform
|
|
19
|
+
* urls, and common constructs like IRequestOptions
|
|
20
|
+
*
|
|
21
|
+
* Thin class just used to enable getters
|
|
22
|
+
*
|
|
23
|
+
* This class should not be used by anything other than
|
|
24
|
+
* the ArcGISContextManager class
|
|
25
|
+
*/
|
|
26
|
+
class ArcGISContext {
|
|
27
|
+
constructor(opts) {
|
|
28
|
+
this._portalUrl = "https://www.arcgis.com";
|
|
29
|
+
this.id = opts.id;
|
|
30
|
+
this._portalUrl = opts.portalUrl;
|
|
31
|
+
this._hubUrl = opts.hubUrl;
|
|
32
|
+
if (opts.authentication) {
|
|
33
|
+
this._authentication = opts.authentication;
|
|
34
|
+
}
|
|
35
|
+
if (opts.portalSelf) {
|
|
36
|
+
this._portalSelf = opts.portalSelf;
|
|
37
|
+
}
|
|
38
|
+
if (opts.currentUser) {
|
|
39
|
+
this._currentUser = opts.currentUser;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Return the UserSession if authenticated
|
|
44
|
+
*/
|
|
45
|
+
get session() {
|
|
46
|
+
return this._authentication;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Return boolean indicating if authenticatio is present
|
|
50
|
+
*/
|
|
51
|
+
get isAuthenticated() {
|
|
52
|
+
return !!this._authentication;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
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
|
|
59
|
+
*/
|
|
60
|
+
get userRequestOptions() {
|
|
61
|
+
if (this.isAuthenticated) {
|
|
62
|
+
return {
|
|
63
|
+
authentication: this._authentication,
|
|
64
|
+
portal: this.sharingApiUrl,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
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)
|
|
75
|
+
*/
|
|
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;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Return a `IHubRequestOptions` object
|
|
90
|
+
*/
|
|
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
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
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
|
|
108
|
+
*/
|
|
109
|
+
get portalUrl() {
|
|
110
|
+
if (this.isAuthenticated) {
|
|
111
|
+
if (this.isPortal) {
|
|
112
|
+
return `https://${this._portalSelf.portalHostname}`;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
return `https://${this._portalSelf.urlKey}.${this._portalSelf.customBaseUrl}`;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return this._portalUrl;
|
|
120
|
+
}
|
|
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}`;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Hub Search
|
|
150
|
+
get hubSearchServiceUrl() {
|
|
151
|
+
if (this._hubUrl) {
|
|
152
|
+
return `${this._hubUrl}${hubApiEndpoints.search}`;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// Domain
|
|
156
|
+
get domainServiceUrl() {
|
|
157
|
+
if (this._hubUrl) {
|
|
158
|
+
return `${this._hubUrl}${hubApiEndpoints.domains}`;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
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
|
+
}
|
|
167
|
+
}
|
|
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);
|
|
175
|
+
}
|
|
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}`;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
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
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.ArcGISContext = ArcGISContext;
|
|
209
|
+
//# sourceMappingURL=ArcGISContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,cA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AC,WAAW,EAAE,sCAAsC,CAAC,CAAC;SAC1E;IACH,CAAC;IAED;;;;OAIG;IACH,IAAW,UAAU;QACnB,OAAO,iBAAc,CACnB,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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;CACF;AAxKD,oDAwKC"}
|
package/dist/node/index.js
CHANGED
|
@@ -24,6 +24,8 @@ tslib_1.__exportStar(require("./utils"), exports);
|
|
|
24
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);
|
|
28
|
+
tslib_1.__exportStar(require("./ArcGISContext"), exports);
|
|
27
29
|
const OperationStack_1 = require("./OperationStack");
|
|
28
30
|
exports.OperationStack = OperationStack_1.default;
|
|
29
31
|
const OperationError_1 = require("./OperationError");
|
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;
|
|
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"}
|