@esri/hub-common 9.13.0 → 9.13.1

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.
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArcGISContextState = 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
+ * @internal
16
+ * Thin class just used to enable getters
17
+ *
18
+ * This class should not be used by anything other than
19
+ * the ArcGISContext class
20
+ */
21
+ class ArcGISContextState {
22
+ constructor(opts) {
23
+ this._portalUrl = "https://www.arcgis.com";
24
+ this.id = opts.id;
25
+ this._portalUrl = opts.portalUrl;
26
+ this._hubUrl = opts.hubUrl;
27
+ if (opts.authentication) {
28
+ this._authentication = opts.authentication;
29
+ }
30
+ if (opts.portalSelf) {
31
+ this._portalSelf = opts.portalSelf;
32
+ }
33
+ if (opts.currentUser) {
34
+ this._currentUser = opts.currentUser;
35
+ }
36
+ }
37
+ /**
38
+ * Return the UserSession if authenticated
39
+ */
40
+ get session() {
41
+ return this._authentication;
42
+ }
43
+ /**
44
+ * Return boolean indicating if authenticatio is present
45
+ */
46
+ get isAuthenticated() {
47
+ return !!this._authentication;
48
+ }
49
+ /**
50
+ * Return `IUserRequestOptions`, which is used for REST-JS
51
+ * functions which require authentication information.
52
+ *
53
+ * If context is not authenticated, this function will throw
54
+ */
55
+ get userRequestOptions() {
56
+ if (this.isAuthenticated) {
57
+ return {
58
+ authentication: this._authentication,
59
+ portal: this.sharingApiUrl,
60
+ };
61
+ }
62
+ }
63
+ /**
64
+ * Return `IRequestOptions`, which is used by REST-JS functions
65
+ * which *may* use authentication information if provided.
66
+ *
67
+ * If context is not authenticated, this function just returns
68
+ * the `portal` property, which informs REST-JS what Sharing API
69
+ * instance to use (i.e. AGO, Enterprise etc)
70
+ */
71
+ get requestOptions() {
72
+ let ro = {
73
+ portal: this.sharingApiUrl,
74
+ };
75
+ if (this.isAuthenticated) {
76
+ ro = {
77
+ authentication: this._authentication,
78
+ portal: this.sharingApiUrl,
79
+ };
80
+ }
81
+ return ro;
82
+ }
83
+ /**
84
+ * Return a `IHubRequestOptions` object
85
+ */
86
+ get hubRequestOptions() {
87
+ // We may add more logic around what is returned in some corner cases
88
+ return {
89
+ authentication: this.session,
90
+ isPortal: this.isPortal,
91
+ portalSelf: this.portal,
92
+ hubApiUrl: this.hubUrl,
93
+ };
94
+ }
95
+ // ==============================
96
+ // Getters / Computed Properties
97
+ // ==============================
98
+ /**
99
+ * Return the portal url.
100
+ *
101
+ * If authenticated @ ArcGIS Online, it will return
102
+ * the https://org.env.arcgis.com
103
+ *
104
+ * If authenticated @ ArcGIS Enterprise, it will return
105
+ * https://portalHostname, which includes the web adaptor
106
+ */
107
+ get portalUrl() {
108
+ if (this.isAuthenticated) {
109
+ if (this.isPortal) {
110
+ return `https://${this._portalSelf.portalHostname}`;
111
+ }
112
+ else {
113
+ return `https://${this._portalSelf.urlKey}.${this._portalSelf.customBaseUrl}`;
114
+ }
115
+ }
116
+ else {
117
+ return this._portalUrl;
118
+ }
119
+ }
120
+ /**
121
+ * Returns the url to the sharing api
122
+ * i.e. https://myorg.maps.arcgis.com/sharing/rest
123
+ */
124
+ get sharingApiUrl() {
125
+ return `${this.portalUrl}/sharing/rest`;
126
+ }
127
+ get hubUrl() {
128
+ return this._hubUrl;
129
+ }
130
+ /**
131
+ * Returns boolean indicating if the backing system
132
+ * is ArcGIS Enterprise (formerly ArcGIS Portal) or not
133
+ */
134
+ get isPortal() {
135
+ return this._portalSelf
136
+ ? this._portalSelf.isPortal
137
+ : this._portalUrl.indexOf("arcgis.com") === -1;
138
+ }
139
+ // Hub APIs
140
+ // ----------
141
+ // Discussions
142
+ get discussionsServiceUrl() {
143
+ if (this._hubUrl) {
144
+ return `${this._hubUrl}${hubApiEndpoints.discussions}`;
145
+ }
146
+ }
147
+ // Hub Search
148
+ get hubSearchServiceUrl() {
149
+ if (this._hubUrl) {
150
+ return `${this._hubUrl}${hubApiEndpoints.search}`;
151
+ }
152
+ }
153
+ // Domain
154
+ get domainServiceUrl() {
155
+ if (this._hubUrl) {
156
+ return `${this._hubUrl}${hubApiEndpoints.domains}`;
157
+ }
158
+ }
159
+ // Events
160
+ // returns `{serviceId: '3ef..', publicViewId: 'bc3...'}
161
+ get eventsConfig() {
162
+ if (this._portalSelf) {
163
+ return _1.getProp(this._portalSelf, "portalProperties.hub.settings.events");
164
+ }
165
+ }
166
+ /**
167
+ * Returns boolean indicating if the current user
168
+ * belongs to an organization that has licensed
169
+ * ArcGIS Hub
170
+ */
171
+ get hubEnabled() {
172
+ return _1.getWithDefault(this._portalSelf, "portalProperties.hub.enabled", false);
173
+ }
174
+ /**
175
+ * Return Hub Community Org Id, if defined
176
+ */
177
+ get communityOrgId() {
178
+ if (this._portalSelf) {
179
+ return _1.getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.orgId");
180
+ }
181
+ }
182
+ get communityOrgHostname() {
183
+ if (this._portalSelf) {
184
+ return _1.getProp(this._portalSelf, "portalProperties.hub.settings.communityOrg.portalHostname");
185
+ }
186
+ }
187
+ get communityOrgUrl() {
188
+ if (this.communityOrgHostname) {
189
+ return `https://${this.communityOrgHostname}`;
190
+ }
191
+ }
192
+ // Platform API service urls are all in helperServices
193
+ // and not consistent to expose as urls
194
+ get helperServices() {
195
+ if (this._portalSelf) {
196
+ return this._portalSelf.helperServices;
197
+ }
198
+ }
199
+ get currentUser() {
200
+ return this._currentUser;
201
+ }
202
+ get portal() {
203
+ return this._portalSelf;
204
+ }
205
+ }
206
+ exports.ArcGISContextState = ArcGISContextState;
207
+ //# sourceMappingURL=ArcGISContextState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArcGISContextState.js","sourceRoot":"","sources":["../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;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;AAjOD,gDAiOC"}
@@ -1,7 +1,5 @@
1
- import { IPortal } from "@esri/arcgis-rest-portal";
2
- import { IUser, IUserRequestOptions, UserSession } from "@esri/arcgis-rest-auth";
3
- import { IHubRequestOptions } from ".";
4
- import { IRequestOptions } from "@esri/arcgis-rest-request";
1
+ import { UserSession } from "@esri/arcgis-rest-auth";
2
+ import { IArcGISContextState } from "./ArcGISContextState";
5
3
  /**
6
4
  * Options that can be passed into `ArcGISContext.create`
7
5
  */
@@ -47,6 +45,7 @@ export declare class ArcGISContext {
47
45
  * contexts getting created
48
46
  */
49
47
  id: number;
48
+ private _state;
50
49
  private _authentication;
51
50
  private _portalUrl;
52
51
  private _hubUrl;
@@ -70,79 +69,30 @@ export declare class ArcGISContext {
70
69
  * store that along with current user
71
70
  */
72
71
  initialize(): Promise<void>;
73
- setAuthentication(auth: UserSession): Promise<void>;
74
- /**
75
- * @internal
76
- * Log debugging messages to the console
77
- * @param message
78
- */
79
- private log;
80
- /**
81
- * Return the UserSession if authenticated
82
- */
83
- get session(): UserSession;
84
- /**
85
- * Return boolean indicating if authenticatio is present
86
- */
87
- get isAuthenticated(): boolean;
88
- /**
89
- * Return `IUserRequestOptions`, which is used for REST-JS
90
- * functions which require authentication information.
91
- *
92
- * If context is not authenticated, this function will throw
93
- */
94
- get userRequestOptions(): IUserRequestOptions;
95
72
  /**
96
- * Return `IRequestOptions`, which is used by REST-JS functions
97
- * which *may* use authentication information if provided.
98
- *
99
- * If context is not authenticated, this function just returns
100
- * the `portal` property, which informs REST-JS what Sharing API
101
- * instance to use (i.e. AGO, Enterprise etc)
102
- */
103
- get requestOptions(): IRequestOptions;
104
- /**
105
- * Return a `IHubRequestOptions` object
106
- */
107
- get hubRequestOptions(): IHubRequestOptions;
108
- /**
109
- * Return the portal url.
110
- *
111
- * If authenticated @ ArcGIS Online, it will return
112
- * the https://org.env.arcgis.com
113
- *
114
- * If authenticated @ ArcGIS Enterprise, it will return
115
- * https://portalHostname, which includes the web adaptor
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
116
77
  */
117
- get portalUrl(): string;
118
- /**
119
- * Returns the url to the sharing api
120
- * i.e. https://myorg.maps.arcgis.com/sharing/rest
121
- */
122
- get sharingApiUrl(): string;
123
- get hubUrl(): string;
78
+ setAuthentication(auth: UserSession): Promise<void>;
124
79
  /**
125
- * Returns boolean indicating if the backing system
126
- * is ArcGIS Enterprise (formerly ArcGIS Portal) or not
80
+ * Clear the Authentication (UserSession). This should be
81
+ * called when a user signs out of an application, but
82
+ * the application continues running
127
83
  */
128
- get isPortal(): boolean;
129
- get discussionsServiceUrl(): string;
130
- get hubSearchServiceUrl(): string;
131
- get domainServiceUrl(): string;
132
- get eventsConfig(): any;
84
+ clearAuthentication(): void;
133
85
  /**
134
- * Returns boolean indicating if the current user
135
- * belongs to an organization that has licensed
136
- * ArcGIS Hub
86
+ * Return a reference to the current state.
87
+ * When `.setAuthentication()` or `.clearAuthenentication()` are
88
+ * called, the state will be re-created. This is done so frameworks
89
+ * like React or Ember can detect changes.
137
90
  */
138
- get hubEnabled(): boolean;
91
+ get state(): IArcGISContextState;
139
92
  /**
140
- * Return Hub Community Org Id, if defined
93
+ * @internal
94
+ * Log debugging messages to the console
95
+ * @param message
141
96
  */
142
- get communityOrgId(): string;
143
- get communityOrgHostname(): string;
144
- get communityOrgUrl(): string;
145
- get helperServices(): any;
146
- get currentUser(): IUser;
147
- get portal(): IPortal;
97
+ private log;
148
98
  }
@@ -0,0 +1,129 @@
1
+ import { IUser, IUserRequestOptions, UserSession } from "@esri/arcgis-rest-auth";
2
+ import { IPortal } from "@esri/arcgis-rest-portal";
3
+ import { IRequestOptions } from "@esri/arcgis-rest-request";
4
+ import { IHubRequestOptions } from ".";
5
+ /**
6
+ * Defined the properties of the ArcGISContext.state
7
+ * object. This wll be a class instance, and when authentication
8
+ * changes, the instance will be replaced. This is done to allow
9
+ * frameworks like React or Ember to bind into the .state property
10
+ * and react when it changes.
11
+ */
12
+ export interface IArcGISContextState {
13
+ id: number;
14
+ session: UserSession;
15
+ isAuthenticated: boolean;
16
+ userRequestOptions: IUserRequestOptions;
17
+ requestOptions: IRequestOptions;
18
+ hubRequestOptions: IHubRequestOptions;
19
+ portalUrl: string;
20
+ sharingApiUrl: string;
21
+ hubUrl: string;
22
+ isPortal: boolean;
23
+ discussionsServiceUrl: string;
24
+ hubSearchServiceUrl: string;
25
+ domainServiceUrl: string;
26
+ eventsConfig: any;
27
+ hubEnabled: boolean;
28
+ communityOrgId: string;
29
+ communityOrgHostname: string;
30
+ communityOrgUrl: string;
31
+ helperServices: any;
32
+ currentUser: IUser;
33
+ portal: IPortal;
34
+ }
35
+ /**
36
+ * @internal
37
+ */
38
+ export interface IArcGISContextStateOptions {
39
+ id: number;
40
+ portalUrl: string;
41
+ hubUrl: string;
42
+ authentication?: UserSession;
43
+ portalSelf?: IPortal;
44
+ currentUser?: IUser;
45
+ }
46
+ /**
47
+ * @internal
48
+ * Thin class just used to enable getters
49
+ *
50
+ * This class should not be used by anything other than
51
+ * the ArcGISContext class
52
+ */
53
+ export declare class ArcGISContextState implements IArcGISContextState {
54
+ id: number;
55
+ private _authentication;
56
+ private _portalUrl;
57
+ private _hubUrl;
58
+ private _portalSelf;
59
+ private _currentUser;
60
+ constructor(opts: IArcGISContextStateOptions);
61
+ /**
62
+ * Return the UserSession if authenticated
63
+ */
64
+ get session(): UserSession;
65
+ /**
66
+ * Return boolean indicating if authenticatio is present
67
+ */
68
+ get isAuthenticated(): boolean;
69
+ /**
70
+ * Return `IUserRequestOptions`, which is used for REST-JS
71
+ * functions which require authentication information.
72
+ *
73
+ * If context is not authenticated, this function will throw
74
+ */
75
+ get userRequestOptions(): IUserRequestOptions;
76
+ /**
77
+ * Return `IRequestOptions`, which is used by REST-JS functions
78
+ * which *may* use authentication information if provided.
79
+ *
80
+ * If context is not authenticated, this function just returns
81
+ * the `portal` property, which informs REST-JS what Sharing API
82
+ * instance to use (i.e. AGO, Enterprise etc)
83
+ */
84
+ get requestOptions(): IRequestOptions;
85
+ /**
86
+ * Return a `IHubRequestOptions` object
87
+ */
88
+ get hubRequestOptions(): IHubRequestOptions;
89
+ /**
90
+ * Return the portal url.
91
+ *
92
+ * If authenticated @ ArcGIS Online, it will return
93
+ * the https://org.env.arcgis.com
94
+ *
95
+ * If authenticated @ ArcGIS Enterprise, it will return
96
+ * https://portalHostname, which includes the web adaptor
97
+ */
98
+ get portalUrl(): string;
99
+ /**
100
+ * Returns the url to the sharing api
101
+ * i.e. https://myorg.maps.arcgis.com/sharing/rest
102
+ */
103
+ get sharingApiUrl(): string;
104
+ get hubUrl(): string;
105
+ /**
106
+ * Returns boolean indicating if the backing system
107
+ * is ArcGIS Enterprise (formerly ArcGIS Portal) or not
108
+ */
109
+ get isPortal(): boolean;
110
+ get discussionsServiceUrl(): string;
111
+ get hubSearchServiceUrl(): string;
112
+ get domainServiceUrl(): string;
113
+ get eventsConfig(): any;
114
+ /**
115
+ * Returns boolean indicating if the current user
116
+ * belongs to an organization that has licensed
117
+ * ArcGIS Hub
118
+ */
119
+ get hubEnabled(): boolean;
120
+ /**
121
+ * Return Hub Community Org Id, if defined
122
+ */
123
+ get communityOrgId(): string;
124
+ get communityOrgHostname(): string;
125
+ get communityOrgUrl(): string;
126
+ get helperServices(): any;
127
+ get currentUser(): IUser;
128
+ get portal(): IPortal;
129
+ }