@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.
Files changed (70) hide show
  1. package/dist/es2017/ArcGISContext.js +158 -147
  2. package/dist/es2017/ArcGISContext.js.map +1 -1
  3. package/dist/es2017/ArcGISContextManager.js +160 -0
  4. package/dist/es2017/ArcGISContextManager.js.map +1 -0
  5. package/dist/es2017/index.js +1 -0
  6. package/dist/es2017/index.js.map +1 -1
  7. package/dist/es2017/search/_searchContent.js +18 -7
  8. package/dist/es2017/search/_searchContent.js.map +1 -1
  9. package/dist/es2017/search/_searchGroups.js +1 -11
  10. package/dist/es2017/search/_searchGroups.js.map +1 -1
  11. package/dist/es2017/search/utils.js +1 -1
  12. package/dist/es2017/urls/getHubApiFromPortalUrl.js +21 -0
  13. package/dist/es2017/urls/getHubApiFromPortalUrl.js.map +1 -0
  14. package/dist/es2017/urls/getPortalBaseFromOrgUrl.js +25 -0
  15. package/dist/es2017/urls/getPortalBaseFromOrgUrl.js.map +1 -0
  16. package/dist/es2017/urls/index.js +2 -0
  17. package/dist/es2017/urls/index.js.map +1 -1
  18. package/dist/esm/ArcGISContext.js +251 -202
  19. package/dist/esm/ArcGISContext.js.map +1 -1
  20. package/dist/esm/ArcGISContextManager.js +204 -0
  21. package/dist/esm/ArcGISContextManager.js.map +1 -0
  22. package/dist/esm/index.js +1 -0
  23. package/dist/esm/index.js.map +1 -1
  24. package/dist/esm/search/_searchContent.js +18 -7
  25. package/dist/esm/search/_searchContent.js.map +1 -1
  26. package/dist/esm/search/_searchGroups.js +3 -13
  27. package/dist/esm/search/_searchGroups.js.map +1 -1
  28. package/dist/esm/search/utils.js +1 -1
  29. package/dist/esm/urls/getHubApiFromPortalUrl.js +21 -0
  30. package/dist/esm/urls/getHubApiFromPortalUrl.js.map +1 -0
  31. package/dist/esm/urls/getPortalBaseFromOrgUrl.js +25 -0
  32. package/dist/esm/urls/getPortalBaseFromOrgUrl.js.map +1 -0
  33. package/dist/esm/urls/index.js +2 -0
  34. package/dist/esm/urls/index.js.map +1 -1
  35. package/dist/node/ArcGISContext.js +158 -147
  36. package/dist/node/ArcGISContext.js.map +1 -1
  37. package/dist/node/ArcGISContextManager.js +164 -0
  38. package/dist/node/ArcGISContextManager.js.map +1 -0
  39. package/dist/node/index.js +1 -0
  40. package/dist/node/index.js.map +1 -1
  41. package/dist/node/search/_searchContent.js +17 -6
  42. package/dist/node/search/_searchContent.js.map +1 -1
  43. package/dist/node/search/_searchGroups.js +1 -11
  44. package/dist/node/search/_searchGroups.js.map +1 -1
  45. package/dist/node/search/utils.js +1 -1
  46. package/dist/node/urls/getHubApiFromPortalUrl.js +25 -0
  47. package/dist/node/urls/getHubApiFromPortalUrl.js.map +1 -0
  48. package/dist/node/urls/getPortalBaseFromOrgUrl.js +29 -0
  49. package/dist/node/urls/getPortalBaseFromOrgUrl.js.map +1 -0
  50. package/dist/node/urls/index.js +2 -0
  51. package/dist/node/urls/index.js.map +1 -1
  52. package/dist/types/ArcGISContext.d.ts +103 -77
  53. package/dist/types/ArcGISContextManager.d.ts +113 -0
  54. package/dist/types/index.d.ts +1 -0
  55. package/dist/types/search/utils.d.ts +1 -1
  56. package/dist/types/urls/getHubApiFromPortalUrl.d.ts +8 -0
  57. package/dist/types/urls/getPortalBaseFromOrgUrl.d.ts +9 -0
  58. package/dist/types/urls/index.d.ts +2 -0
  59. package/dist/umd/common.umd.js +144 -125
  60. package/dist/umd/common.umd.js.map +1 -1
  61. package/dist/umd/common.umd.min.js +1 -1
  62. package/dist/umd/common.umd.min.js.map +1 -1
  63. package/package.json +1 -1
  64. package/dist/es2017/ArcGISContextState.js +0 -203
  65. package/dist/es2017/ArcGISContextState.js.map +0 -1
  66. package/dist/esm/ArcGISContextState.js +0 -285
  67. package/dist/esm/ArcGISContextState.js.map +0 -1
  68. package/dist/node/ArcGISContextState.js +0 -207
  69. package/dist/node/ArcGISContextState.js.map +0 -1
  70. package/dist/types/ArcGISContextState.d.ts +0 -129
@@ -11,25 +11,20 @@ import { cloneObject, getGroupThumbnailUrl } from "..";
11
11
  * @returns
12
12
  */
13
13
  export async function _searchGroups(filter, options) {
14
- var _a;
15
14
  // expand filter so we can serialize to either api
16
15
  const expanded = expandGroupFilter(filter);
17
16
  // API
18
17
  const api = expandApi(options.api || "arcgis");
19
18
  if (api.type === "arcgis") {
20
19
  const so = serializeGroupFilterForPortal(expanded);
21
- let token = "";
22
20
  // if we have auth, pass it forward
23
21
  // otherwise set the portal property
24
22
  if (options.authentication) {
25
23
  so.authentication = options.authentication;
26
- const us = options.authentication;
27
- token = us.token;
28
24
  }
29
25
  else {
30
26
  so.portal = `${api.url}/sharing/rest`;
31
27
  }
32
- // TODO: Dry this up - typscript makes this... inconvenient
33
28
  if (options.num) {
34
29
  so.num = options.num;
35
30
  }
@@ -39,10 +34,6 @@ export async function _searchGroups(filter, options) {
39
34
  if (options.sortOrder) {
40
35
  so.sortOrder = options.sortOrder;
41
36
  }
42
- let portalUrl = `${api.url}/sharing/rest`;
43
- if ((_a = so.authentication) === null || _a === void 0 ? void 0 : _a.portal) {
44
- portalUrl = so.authentication.portal;
45
- }
46
37
  if (options.site) {
47
38
  so.site = cloneObject(options.site);
48
39
  }
@@ -63,8 +54,7 @@ function searchPortalGroups(searchOptions) {
63
54
  group.siteTeamUrl = `${searchOptions.site.item.url}/teams/${group.id}/about`;
64
55
  return group;
65
56
  };
66
- const portalUrl = ((_a = searchOptions.authentication) === null || _a === void 0 ? void 0 : _a.portal) ||
67
- "https://www.arcgis.com/sharing/rest";
57
+ const portalUrl = ((_a = searchOptions.authentication) === null || _a === void 0 ? void 0 : _a.portal) || searchOptions.portal;
68
58
  let token;
69
59
  if (searchOptions.authentication) {
70
60
  const us = searchOptions.authentication;
@@ -1 +1 @@
1
- {"version":3,"file":"_searchGroups.js","sourceRoot":"","sources":["../../../src/search/_searchGroups.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,IAAI,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AG,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,CAAC,QAAQ,EAAE,EAAE;;QACxD,MAAM,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;YACP,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,OAAO;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"}
@@ -352,7 +352,7 @@ export function getNextFunction(request, nextStart, total, fn) {
352
352
  * Construct a the full url to a group thumbnail
353
353
  *
354
354
  * - If the group has a thumbnail, construct the full url
355
- * - If the group is not public, append on the token
355
+ * - If the group is not public, append on the token (if passed in)
356
356
  * @param portalUrl
357
357
  * @param group
358
358
  * @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
+ let 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
+ let 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"}
@@ -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
  const 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,CA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IG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,GAAW,EAAE,EAAE;IACrD,OAAO,+BAA+B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnD,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,GAAW,EAAE,EAAE;IACnD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACzD,MAAM,YAAY,GAAG,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;IACvC,OAAO,YAAY,IAAI,GAAG,UAAU,CAAC,YAAY,CAAC,UAAU,CAAC;AAC/D,CAAC,CAAC"}
@@ -1,197 +1,282 @@
1
- import { __awaiter, __generator } from "tslib";
2
- import { getSelf, getUser } from "@esri/arcgis-rest-portal";
3
- import { ArcGISContextState, } from "./ArcGISContextState";
4
- import { cloneObject } from ".";
1
+ import { getProp, getWithDefault } from ".";
5
2
  /**
6
- * Application Context Object
3
+ * Hash of Hub API end points so updates
4
+ * are centralized
5
+ */
6
+ var hubApiEndpoints = {
7
+ domains: "/api/v3/domains",
8
+ search: "/api/v3/datasets",
9
+ discussions: "/api/discussions/v1",
10
+ };
11
+ /**
12
+ * ArcGISContext
7
13
  *
8
- * Abstraction that combines a `UserSession` with
9
- * the `portal/self` and `user/self` responses to
10
- * provide a central lookup of platform information.
14
+ * Abstraction that holds a UserSession, along with
15
+ * getters to streamline access to various platform
16
+ * urls, and common constructs like IRequestOptions
11
17
  *
12
- * This is a work-in-progress, and will likely expand over time.
18
+ * Thin class just used to enable getters
13
19
  *
14
- * `ArcGISContext` is used in conjuction with the `arcgis-app-identity`
15
- * component to orchestrate oAuth.
20
+ * This class should not be used by anything other than
21
+ * the ArcGISContextManager class
16
22
  */
17
23
  var ArcGISContext = /** @class */ (function () {
18
- /**
19
- * Private constructor. Use `ArcGISContext.create(...)` to
20
- * instantiate an instance
21
- * @param opts
22
- */
23
24
  function ArcGISContext(opts) {
24
25
  this._portalUrl = "https://www.arcgis.com";
25
- this._debug = false;
26
- // Having a unique id makes debugging easier
27
- this.id = new Date().getTime();
28
- if (opts.debug) {
29
- this._debug = opts.debug;
30
- }
31
- this.log("ArcGISContext:ctor: Creating " + this.id);
26
+ this.id = opts.id;
27
+ this._portalUrl = opts.portalUrl;
28
+ this._hubUrl = opts.hubUrl;
32
29
  if (opts.authentication) {
33
30
  this._authentication = opts.authentication;
34
- this._portalUrl = this._authentication.portal.replace("/sharing/rest", "");
35
- this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
36
- }
37
- else if (opts.portalUrl) {
38
- this._portalUrl = opts.portalUrl;
39
- this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
40
- }
41
- else {
42
- this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
43
31
  }
44
- if (opts.portal) {
45
- this._portalSelf = cloneObject(opts.portal);
32
+ if (opts.portalSelf) {
33
+ this._portalSelf = opts.portalSelf;
46
34
  }
47
35
  if (opts.currentUser) {
48
- this._currentUser = cloneObject(opts.currentUser);
36
+ this._currentUser = opts.currentUser;
49
37
  }
50
38
  }
51
- /**
52
- * Static async Factory
53
- * @param opts
54
- * @returns
55
- */
56
- ArcGISContext.create = function (opts) {
57
- if (opts === void 0) { opts = {}; }
58
- return __awaiter(this, void 0, void 0, function () {
59
- var ctx;
60
- return __generator(this, function (_a) {
61
- switch (_a.label) {
62
- case 0:
63
- ctx = new ArcGISContext(opts);
64
- return [4 /*yield*/, ctx.initialize()];
65
- case 1:
66
- _a.sent();
67
- return [2 /*return*/, ctx];
39
+ Object.defineProperty(ArcGISContext.prototype, "session", {
40
+ /**
41
+ * Return the UserSession if authenticated
42
+ */
43
+ get: function () {
44
+ return this._authentication;
45
+ },
46
+ enumerable: false,
47
+ configurable: true
48
+ });
49
+ Object.defineProperty(ArcGISContext.prototype, "isAuthenticated", {
50
+ /**
51
+ * Return boolean indicating if authenticatio is present
52
+ */
53
+ get: function () {
54
+ return !!this._authentication;
55
+ },
56
+ enumerable: false,
57
+ configurable: true
58
+ });
59
+ Object.defineProperty(ArcGISContext.prototype, "userRequestOptions", {
60
+ /**
61
+ * Return `IUserRequestOptions`, which is used for REST-JS
62
+ * functions which require authentication information.
63
+ *
64
+ * If context is not authenticated, this function will throw
65
+ */
66
+ get: function () {
67
+ if (this.isAuthenticated) {
68
+ return {
69
+ authentication: this._authentication,
70
+ portal: this.sharingApiUrl,
71
+ };
72
+ }
73
+ },
74
+ enumerable: false,
75
+ configurable: true
76
+ });
77
+ Object.defineProperty(ArcGISContext.prototype, "requestOptions", {
78
+ /**
79
+ * Return `IRequestOptions`, which is used by REST-JS functions
80
+ * which *may* use authentication information if provided.
81
+ *
82
+ * If context is not authenticated, this function just returns
83
+ * the `portal` property, which informs REST-JS what Sharing API
84
+ * instance to use (i.e. AGO, Enterprise etc)
85
+ */
86
+ get: function () {
87
+ var ro = {
88
+ portal: this.sharingApiUrl,
89
+ };
90
+ if (this.isAuthenticated) {
91
+ ro = {
92
+ authentication: this._authentication,
93
+ portal: this.sharingApiUrl,
94
+ };
95
+ }
96
+ return ro;
97
+ },
98
+ enumerable: false,
99
+ configurable: true
100
+ });
101
+ Object.defineProperty(ArcGISContext.prototype, "hubRequestOptions", {
102
+ /**
103
+ * Return a `IHubRequestOptions` object
104
+ */
105
+ get: function () {
106
+ // We may add more logic around what is returned in some corner cases
107
+ return {
108
+ authentication: this.session,
109
+ isPortal: this.isPortal,
110
+ portalSelf: this.portal,
111
+ hubApiUrl: this.hubUrl,
112
+ };
113
+ },
114
+ enumerable: false,
115
+ configurable: true
116
+ });
117
+ Object.defineProperty(ArcGISContext.prototype, "portalUrl", {
118
+ /**
119
+ * Return the portal url.
120
+ *
121
+ * If authenticated @ ArcGIS Online, it will return
122
+ * the https://org.env.arcgis.com
123
+ *
124
+ * If authenticated @ ArcGIS Enterprise, it will return
125
+ * https://portalHostname, which includes the web adaptor
126
+ */
127
+ get: function () {
128
+ if (this.isAuthenticated) {
129
+ if (this.isPortal) {
130
+ return "https://" + this._portalSelf.portalHostname;
68
131
  }
69
- });
70
- });
71
- };
72
- /**
73
- * Set the Authentication (UserSession) for the context.
74
- * This should be called when a user signs into a running
75
- * application.
76
- * @param auth
77
- */
78
- ArcGISContext.prototype.setAuthentication = function (auth) {
79
- return __awaiter(this, void 0, void 0, function () {
80
- return __generator(this, function (_a) {
81
- switch (_a.label) {
82
- case 0:
83
- this._authentication = auth;
84
- this._portalUrl = auth.portal.replace("/sharing/rest", "");
85
- return [4 /*yield*/, this.initialize()];
86
- case 1:
87
- _a.sent();
88
- return [2 /*return*/];
132
+ else {
133
+ return "https://" + this._portalSelf.urlKey + "." + this._portalSelf.customBaseUrl;
89
134
  }
90
- });
91
- });
92
- };
93
- /**
94
- * Clear the Authentication (UserSession). This should be
95
- * called when a user signs out of an application, but
96
- * the application continues running
97
- */
98
- ArcGISContext.prototype.clearAuthentication = function () {
99
- // Reset the portalUrl from the org url to the base url
100
- // for ArcGIS Enterprise, we just leave the _portalUrl as-is
101
- if (!this._state.isPortal) {
102
- this._portalUrl = getPortalBaseFromOrgUrl(this._portalUrl);
103
- }
104
- // Clear the auth, portalSelf and currentUser props
105
- this._authentication = null;
106
- this._portalSelf = null;
107
- this._currentUser = null;
108
- this._state = new ArcGISContextState({
109
- id: this.id,
110
- portalUrl: this._portalUrl,
111
- hubUrl: this._hubUrl,
112
- });
113
- };
114
- Object.defineProperty(ArcGISContext.prototype, "state", {
135
+ }
136
+ else {
137
+ return this._portalUrl;
138
+ }
139
+ },
140
+ enumerable: false,
141
+ configurable: true
142
+ });
143
+ Object.defineProperty(ArcGISContext.prototype, "sharingApiUrl", {
115
144
  /**
116
- * Return a reference to the current state.
117
- * When `.setAuthentication()` or `.clearAuthenentication()` are
118
- * called, the state will be re-created. This is done so frameworks
119
- * like React or Ember can detect changes.
145
+ * Returns the url to the sharing api
146
+ * i.e. https://myorg.maps.arcgis.com/sharing/rest
120
147
  */
121
148
  get: function () {
122
- return this._state;
149
+ return this.portalUrl + "/sharing/rest";
123
150
  },
124
151
  enumerable: false,
125
152
  configurable: true
126
153
  });
127
- /**
128
- * @internal
129
- * Log debugging messages to the console
130
- * @param message
131
- */
132
- ArcGISContext.prototype.log = function (message) {
133
- if (this._debug) {
134
- // tslint:disable-next-line:no-console
135
- console.info(message);
136
- }
137
- };
138
- /**
139
- * If we have a UserSession, fetch portal/self and
140
- * store that along with current user
141
- */
142
- ArcGISContext.prototype.initialize = function () {
143
- return __awaiter(this, void 0, void 0, function () {
144
- var username, requests, _a, portal, user, ex_1, msg;
145
- return __generator(this, function (_b) {
146
- switch (_b.label) {
147
- case 0:
148
- if (!(this._authentication && (!this._portalSelf || !this._currentUser))) return [3 /*break*/, 4];
149
- this.log("ArcGISContext-" + this.id + ": Initializing");
150
- username = this._authentication.username;
151
- requests = [
152
- getSelf({ authentication: this._authentication }),
153
- getUser({ username: username, authentication: this._authentication }),
154
- ];
155
- _b.label = 1;
156
- case 1:
157
- _b.trys.push([1, 3, , 4]);
158
- return [4 /*yield*/, Promise.all(requests)];
159
- case 2:
160
- _a = _b.sent(), portal = _a[0], user = _a[1];
161
- this._portalSelf = portal;
162
- this._currentUser = user;
163
- return [3 /*break*/, 4];
164
- case 3:
165
- ex_1 = _b.sent();
166
- msg = "ArcGISContext could not fetch portal & user for \"" + this._authentication.username + "\" using " + this._authentication.portal + ".";
167
- // tslint:disable-next-line:no-console
168
- console.error(msg);
169
- throw ex_1;
170
- case 4:
171
- // update the state
172
- this._state = new ArcGISContextState(this.stateOpts);
173
- return [2 /*return*/];
174
- }
175
- });
176
- });
177
- };
178
- Object.defineProperty(ArcGISContext.prototype, "stateOpts", {
179
- get: function () {
180
- var stateOpts = {
181
- id: this.id,
182
- portalUrl: this._portalUrl,
183
- hubUrl: this._hubUrl,
184
- };
185
- if (this._authentication) {
186
- stateOpts.authentication = this._authentication;
154
+ Object.defineProperty(ArcGISContext.prototype, "hubUrl", {
155
+ get: function () {
156
+ return this._hubUrl;
157
+ },
158
+ enumerable: false,
159
+ configurable: true
160
+ });
161
+ Object.defineProperty(ArcGISContext.prototype, "isPortal", {
162
+ /**
163
+ * Returns boolean indicating if the backing system
164
+ * is ArcGIS Enterprise (formerly ArcGIS Portal) or not
165
+ */
166
+ get: function () {
167
+ return this._portalSelf
168
+ ? this._portalSelf.isPortal
169
+ : this._portalUrl.indexOf("arcgis.com") === -1;
170
+ },
171
+ enumerable: false,
172
+ configurable: true
173
+ });
174
+ Object.defineProperty(ArcGISContext.prototype, "discussionsServiceUrl", {
175
+ // Hub APIs
176
+ // ----------
177
+ // Discussions
178
+ get: function () {
179
+ if (this._hubUrl) {
180
+ return "" + this._hubUrl + hubApiEndpoints.discussions;
181
+ }
182
+ },
183
+ enumerable: false,
184
+ configurable: true
185
+ });
186
+ Object.defineProperty(ArcGISContext.prototype, "hubSearchServiceUrl", {
187
+ // Hub Search
188
+ get: function () {
189
+ if (this._hubUrl) {
190
+ return "" + this._hubUrl + hubApiEndpoints.search;
191
+ }
192
+ },
193
+ enumerable: false,
194
+ configurable: true
195
+ });
196
+ Object.defineProperty(ArcGISContext.prototype, "domainServiceUrl", {
197
+ // Domain
198
+ get: function () {
199
+ if (this._hubUrl) {
200
+ return "" + this._hubUrl + hubApiEndpoints.domains;
187
201
  }
202
+ },
203
+ enumerable: false,
204
+ configurable: true
205
+ });
206
+ Object.defineProperty(ArcGISContext.prototype, "eventsConfig", {
207
+ // Events
208
+ // returns `{serviceId: '3ef..', publicViewId: 'bc3...'}
209
+ get: function () {
188
210
  if (this._portalSelf) {
189
- stateOpts.portalSelf = this._portalSelf;
211
+ return getProp(this._portalSelf, "portalProperties.hub.settings.events");
190
212
  }
191
- if (this._currentUser) {
192
- stateOpts.currentUser = this._currentUser;
213
+ },
214
+ enumerable: false,
215
+ configurable: true
216
+ });
217
+ Object.defineProperty(ArcGISContext.prototype, "hubEnabled", {
218
+ /**
219
+ * Returns boolean indicating if the current user
220
+ * belongs to an organization that has licensed
221
+ * ArcGIS Hub
222
+ */
223
+ get: function () {
224
+ return getWithDefault(this._portalSelf, "portalProperties.hub.enabled", false);
225
+ },
226
+ enumerable: false,
227
+ configurable: true
228
+ });
229
+ Object.defineProperty(ArcGISContext.prototype, "communityOrgId", {
230
+ /**
231
+ * Return Hub Community Org Id, if defined
232
+ */
233
+ get: function () {
234
+ if (this._portalSelf) {
235
+ return getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.orgId");
193
236
  }
194
- return stateOpts;
237
+ },
238
+ enumerable: false,
239
+ configurable: true
240
+ });
241
+ Object.defineProperty(ArcGISContext.prototype, "communityOrgHostname", {
242
+ get: function () {
243
+ if (this._portalSelf) {
244
+ return getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.portalHostname");
245
+ }
246
+ },
247
+ enumerable: false,
248
+ configurable: true
249
+ });
250
+ Object.defineProperty(ArcGISContext.prototype, "communityOrgUrl", {
251
+ get: function () {
252
+ if (this.communityOrgHostname) {
253
+ return "https://" + this.communityOrgHostname;
254
+ }
255
+ },
256
+ enumerable: false,
257
+ configurable: true
258
+ });
259
+ Object.defineProperty(ArcGISContext.prototype, "helperServices", {
260
+ // Platform API service urls are all in helperServices
261
+ // and not consistent to expose as urls
262
+ get: function () {
263
+ if (this._portalSelf) {
264
+ return this._portalSelf.helperServices;
265
+ }
266
+ },
267
+ enumerable: false,
268
+ configurable: true
269
+ });
270
+ Object.defineProperty(ArcGISContext.prototype, "currentUser", {
271
+ get: function () {
272
+ return this._currentUser;
273
+ },
274
+ enumerable: false,
275
+ configurable: true
276
+ });
277
+ Object.defineProperty(ArcGISContext.prototype, "portal", {
278
+ get: function () {
279
+ return this._portalSelf;
195
280
  },
196
281
  enumerable: false,
197
282
  configurable: true
@@ -199,40 +284,4 @@ var ArcGISContext = /** @class */ (function () {
199
284
  return ArcGISContext;
200
285
  }());
201
286
  export { ArcGISContext };
202
- /**
203
- * Cross-walk from a portalUrl to the corresponding Hub.
204
- *
205
- * If the passed url is not recognized, then this will return `undefined`
206
- * @param portalUrl
207
- * @returns
208
- */
209
- function getHubApiFromPortalUrl(portalUrl) {
210
- var result;
211
- if (portalUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
212
- result = "https://hubqa.arcgis.com";
213
- }
214
- else if (portalUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
215
- result = "https://hubdev.arcgis.com";
216
- }
217
- else if (portalUrl.match(/(www|\.maps)\.arcgis.com/)) {
218
- result = "https://hub.arcgis.com";
219
- }
220
- return result;
221
- }
222
- function getPortalBaseFromOrgUrl(orgUrl) {
223
- var result;
224
- if (orgUrl.match(/(qaext|\.mapsqa)\.arcgis.com/)) {
225
- result = "https://qaext.arcgis.com";
226
- }
227
- else if (orgUrl.match(/(devext|\.mapsdevext)\.arcgis.com/)) {
228
- result = "https://devext.arcgis.com";
229
- }
230
- else {
231
- /* istanbul ignore else */
232
- if (orgUrl.match(/(www|\.maps)\.arcgis.com/)) {
233
- result = "https://www.arcgis.com";
234
- }
235
- }
236
- return result;
237
- }
238
287
  //# sourceMappingURL=ArcGISContext.js.map