@esri/hub-common 14.48.1 → 14.49.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/esm/ArcGISContext.js +8 -0
- package/dist/esm/ArcGISContext.js.map +1 -1
- package/dist/esm/ArcGISContextManager.js +148 -95
- package/dist/esm/ArcGISContextManager.js.map +1 -1
- package/dist/esm/permissions/checkPermission.js +8 -1
- package/dist/esm/permissions/checkPermission.js.map +1 -1
- package/dist/esm/sites/_internal/SiteBusinessRules.js +4 -1
- package/dist/esm/sites/_internal/SiteBusinessRules.js.map +1 -1
- package/dist/esm/sites/_internal/_migrate-telemetry-config.js +2 -1
- package/dist/esm/sites/_internal/_migrate-telemetry-config.js.map +1 -1
- package/dist/esm/sites/site-schema-version.js +1 -1
- package/dist/esm/utils/hubUserAppResources.js +62 -9
- package/dist/esm/utils/hubUserAppResources.js.map +1 -1
- package/dist/esm/utils/internal/fetchAndMigrateUserHubSettings.js +39 -0
- package/dist/esm/utils/internal/fetchAndMigrateUserHubSettings.js.map +1 -0
- package/dist/node/ArcGISContext.js +8 -0
- package/dist/node/ArcGISContext.js.map +1 -1
- package/dist/node/ArcGISContextManager.js +147 -94
- package/dist/node/ArcGISContextManager.js.map +1 -1
- package/dist/node/permissions/checkPermission.js +8 -1
- package/dist/node/permissions/checkPermission.js.map +1 -1
- package/dist/node/sites/_internal/SiteBusinessRules.js +4 -1
- package/dist/node/sites/_internal/SiteBusinessRules.js.map +1 -1
- package/dist/node/sites/_internal/_migrate-telemetry-config.js +2 -1
- package/dist/node/sites/_internal/_migrate-telemetry-config.js.map +1 -1
- package/dist/node/sites/site-schema-version.js +1 -1
- package/dist/node/utils/hubUserAppResources.js +70 -13
- package/dist/node/utils/hubUserAppResources.js.map +1 -1
- package/dist/node/utils/internal/fetchAndMigrateUserHubSettings.js +43 -0
- package/dist/node/utils/internal/fetchAndMigrateUserHubSettings.js.map +1 -0
- package/dist/types/ArcGISContext.d.ts +17 -0
- package/dist/types/ArcGISContextManager.d.ts +21 -9
- package/dist/types/sites/site-schema-version.d.ts +1 -1
- package/dist/types/utils/hubUserAppResources.d.ts +46 -0
- package/dist/types/utils/internal/fetchAndMigrateUserHubSettings.d.ts +12 -0
- package/package.json +1 -1
|
@@ -1,15 +1,68 @@
|
|
|
1
1
|
import { USER_SITE_SETTINGS_APP, USER_SITE_SETTINGS_KEY, } from "./internal/clearUserSiteSettings";
|
|
2
2
|
import { USER_HUB_SETTINGS_APP, USER_HUB_SETTINGS_KEY, } from "./internal/clearUserHubSettings";
|
|
3
|
-
import {
|
|
3
|
+
import { applySiteSettingsMigrations } from "./internal/siteSettingsMigrations";
|
|
4
4
|
import { getUserResource, setUserResource, } from "./internal/userAppResources";
|
|
5
|
+
import { fetchAndMigrateUserHubSettings } from "./internal/fetchAndMigrateUserHubSettings";
|
|
5
6
|
/**
|
|
7
|
+
* @private
|
|
8
|
+
* DEPRECATED: Use `updateUserSiteSettings` instead
|
|
6
9
|
* Store User settings in the Site App's cache
|
|
7
10
|
* @param settings
|
|
8
11
|
* @param context
|
|
9
12
|
* @param replace
|
|
10
13
|
* @returns
|
|
11
14
|
*/
|
|
15
|
+
/* istanbul ignore next */
|
|
12
16
|
export async function setUserSiteSettings(settings, context, replace = false) {
|
|
17
|
+
/* istanbul ignore next */
|
|
18
|
+
return updateUserSiteSettings(settings, context, replace);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @private
|
|
22
|
+
* DEPRECATED: Use `fetchUserSiteSettings`
|
|
23
|
+
* Get the current user's settings for the current Site
|
|
24
|
+
* @param context
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
/* istanbul ignore next */
|
|
28
|
+
export async function getUserSiteSettings(context) {
|
|
29
|
+
/* istanbul ignore next */
|
|
30
|
+
return fetchUserSiteSettings(context);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @private
|
|
34
|
+
* DEPRECATED: use `updateUserHubSettings` instead
|
|
35
|
+
* Store the current user's Hub settings
|
|
36
|
+
* @param settings
|
|
37
|
+
* @param context
|
|
38
|
+
* @param replace
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
/* istanbul ignore next */
|
|
42
|
+
export async function setUserHubSettings(settings, context, replace = false) {
|
|
43
|
+
/* istanbul ignore next */
|
|
44
|
+
return updateUserHubSettings(settings, context, replace);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @private
|
|
48
|
+
* DEPRECATED: Use `fetchUserHubSettings`
|
|
49
|
+
* Get the current user's settings for ArcGIS Hub
|
|
50
|
+
* @param context
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
/* istanbul ignore next */
|
|
54
|
+
export async function getUserHubSettings(context) {
|
|
55
|
+
/* istanbul ignore next */
|
|
56
|
+
return fetchUserHubSettings(context);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Store User settings in the Site App's cache
|
|
60
|
+
* @param settings
|
|
61
|
+
* @param context
|
|
62
|
+
* @param replace
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
export async function updateUserSiteSettings(settings, context, replace = false) {
|
|
13
66
|
const token = context.tokenFor(USER_SITE_SETTINGS_APP);
|
|
14
67
|
if (token) {
|
|
15
68
|
// always stamp in the updated and username properties
|
|
@@ -27,11 +80,11 @@ export async function setUserSiteSettings(settings, context, replace = false) {
|
|
|
27
80
|
}
|
|
28
81
|
}
|
|
29
82
|
/**
|
|
30
|
-
*
|
|
83
|
+
* Fetch the user's settings for the current Site
|
|
31
84
|
* @param context
|
|
32
85
|
* @returns
|
|
33
86
|
*/
|
|
34
|
-
export async function
|
|
87
|
+
export async function fetchUserSiteSettings(context) {
|
|
35
88
|
const token = context.tokenFor(USER_SITE_SETTINGS_APP);
|
|
36
89
|
if (token) {
|
|
37
90
|
const settings = (await getUserResource(context.currentUser.username, USER_SITE_SETTINGS_KEY, context.portalUrl, token));
|
|
@@ -43,13 +96,13 @@ export async function getUserSiteSettings(context) {
|
|
|
43
96
|
}
|
|
44
97
|
}
|
|
45
98
|
/**
|
|
46
|
-
* Store the current user's Hub settings
|
|
99
|
+
* Store the current user's Hub settings as a User App Resource
|
|
47
100
|
* @param settings
|
|
48
101
|
* @param context
|
|
49
102
|
* @param replace
|
|
50
103
|
* @returns
|
|
51
104
|
*/
|
|
52
|
-
export async function
|
|
105
|
+
export async function updateUserHubSettings(settings, context, replace = false) {
|
|
53
106
|
const token = context.tokenFor(USER_HUB_SETTINGS_APP);
|
|
54
107
|
if (token) {
|
|
55
108
|
// always stamp in the updated and username properties
|
|
@@ -67,15 +120,15 @@ export async function setUserHubSettings(settings, context, replace = false) {
|
|
|
67
120
|
}
|
|
68
121
|
}
|
|
69
122
|
/**
|
|
70
|
-
*
|
|
123
|
+
* Fetch the current user's settings for ArcGIS Hub
|
|
124
|
+
* Will return null if the hubforarcgis token is not available
|
|
71
125
|
* @param context
|
|
72
126
|
* @returns
|
|
73
127
|
*/
|
|
74
|
-
export async function
|
|
128
|
+
export async function fetchUserHubSettings(context) {
|
|
75
129
|
const token = context.tokenFor(USER_HUB_SETTINGS_APP);
|
|
76
130
|
if (token) {
|
|
77
|
-
|
|
78
|
-
return applyHubSettingsMigrations(settings);
|
|
131
|
+
return await fetchAndMigrateUserHubSettings(context.currentUser.username, context.portalUrl, token);
|
|
79
132
|
}
|
|
80
133
|
else {
|
|
81
134
|
return Promise.resolve(null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hubUserAppResources.js","sourceRoot":"","sources":["../../../src/utils/hubUserAppResources.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"hubUserAppResources.js","sourceRoot":"","sources":["../../../src/utils/hubUserAppResources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OAAO,EAAE,CAAC;QACxC,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC;QACjD,MAAM,QAAQ,GAAqB;YACjC,GAAG,EAAE,qBAAqB;YAC1B,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,gBAAgB;SACzB,CAAC;QACF,OAAO,eAAe,CACpB,QAAQ,EACR,OAAO,CAAC,WAAW,CAAC,QAAQ,EAC5B,OAAO,CAAC,SAAS,EACjB,KAAK,EACL,OAAO,CACR,CAAC;KACH;SAAM;QACL,MAAM,IAAI,KAAK,CACb,6DAA6D,CAC9D,CAAC;KACH;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAAuB;IAEvB,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IACtD,IAAI,KAAK,EAAE;QACT,OAAO,MAAM,8BAA8B,CACzC,OAAO,CAAC,WAAW,CAAC,QAAQ,EAC5B,OAAO,CAAC,SAAS,EACjB,KAAK,CACN,CAAC;KACH;SAAM;QACL,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KAC9B;AACH,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { failSafe } from "../fail-safe";
|
|
2
|
+
import { USER_HUB_SETTINGS_KEY } from "./clearUserHubSettings";
|
|
3
|
+
import { applyHubSettingsMigrations } from "./siteSettingsMigrations";
|
|
4
|
+
import { getUserResource } from "./userAppResources";
|
|
5
|
+
/**
|
|
6
|
+
* @private
|
|
7
|
+
* Fetch the User Hub Settings and apply migrations
|
|
8
|
+
* Caller is responsible for ensuring the passed token
|
|
9
|
+
* is assoicated with the `hubforarcgis` client id
|
|
10
|
+
* @param username
|
|
11
|
+
* @param portalUrl
|
|
12
|
+
* @param token
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export async function fetchAndMigrateUserHubSettings(username, portalUrl, token) {
|
|
16
|
+
// create failsafe function that returns a default Hub Settings object
|
|
17
|
+
const fsGetResource = failSafe(getUserResource, getDefaultUserHubSettings(username));
|
|
18
|
+
// fetch the user's Hub Settings
|
|
19
|
+
const settings = await fsGetResource(username, USER_HUB_SETTINGS_KEY, portalUrl, token);
|
|
20
|
+
// apply any migrations and return the result
|
|
21
|
+
return applyHubSettingsMigrations(settings);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get a default Hub Settings object for a user
|
|
25
|
+
* This will be run through migrations, so it's ok if it's not the latest version
|
|
26
|
+
* @param username
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
function getDefaultUserHubSettings(username) {
|
|
30
|
+
return {
|
|
31
|
+
schemaVersion: 1,
|
|
32
|
+
username,
|
|
33
|
+
updated: new Date().getTime(),
|
|
34
|
+
preview: {
|
|
35
|
+
workspace: false,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=fetchAndMigrateUserHubSettings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchAndMigrateUserHubSettings.js","sourceRoot":"","sources":["../../../../src/utils/internal/fetchAndMigrateUserHubSettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,QAAgB,EAChB,SAAiB,EACjB,KAAa;IAEb,sEAAsE;IACtE,MAAM,aAAa,GAAG,QAAQ,CAC5B,eAAe,EACf,yBAAyB,CAAC,QAAQ,CAAC,CACpC,CAAC;IACF,gCAAgC;IAChC,MAAM,QAAQ,GAAG,MAAM,aAAa,CAClC,QAAQ,EACR,qBAAqB,EACrB,SAAS,EACT,KAAK,CACN,CAAC;IACF,6CAA6C;IAC7C,OAAO,0BAA0B,CAAC,QAAQ,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;GAKG;AACH,SAAS,yBAAyB,CAAC,QAAgB;IACjD,OAAO;QACL,aAAa,EAAE,CAAC;QAChB,QAAQ;QACR,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;QAC7B,OAAO,EAAE;YACP,SAAS,EAAE,KAAK;SACjB;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -57,6 +57,7 @@ class ArcGISContext {
|
|
|
57
57
|
}
|
|
58
58
|
this._featureFlags = opts.featureFlags || {};
|
|
59
59
|
this._userResourceTokens = opts.userResourceTokens || [];
|
|
60
|
+
this._userHubSettings = opts.userHubSettings || null;
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
63
|
* Return the UserSession if authenticated
|
|
@@ -360,6 +361,13 @@ class ArcGISContext {
|
|
|
360
361
|
get userResourceTokens() {
|
|
361
362
|
return this._userResourceTokens;
|
|
362
363
|
}
|
|
364
|
+
/**
|
|
365
|
+
* Return the user hub settings.
|
|
366
|
+
* Updates must be done via `contextManager.updateUserHubSettings`
|
|
367
|
+
*/
|
|
368
|
+
get userHubSettings() {
|
|
369
|
+
return this._userHubSettings;
|
|
370
|
+
}
|
|
363
371
|
/**
|
|
364
372
|
* Return a token for a specific app
|
|
365
373
|
* @param app
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArcGISContext.js","sourceRoot":"","sources":["../../src/ArcGISContext.ts"],"names":[],"mappings":";;;AAQA,uCAAoD;AAGpD,qFAAkF;
|
|
1
|
+
{"version":3,"file":"ArcGISContext.js","sourceRoot":"","sources":["../../src/ArcGISContext.ts"],"names":[],"mappings":";;;AAQA,uCAAoD;AAGpD,qFAAkF;AAIlF;;;GAGG;AACH,MAAM,eAAe,GAAG;IACtB,OAAO,E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CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,IAAW,kBAAkB;QAC3B,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED;;;OAGG;IACH,IAAW,eAAe;QACxB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACI,QAAQ,CAAC,GAAoB;QAClC,MAAM,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;QAClE,IAAI,KAAK,EAAE;YACT,OAAO,KAAK,CAAC,KAAK,CAAC;SACpB;IACH,CAAC;CACF;AA3aD,sCA2aC"}
|
|
@@ -11,6 +11,25 @@ const util_1 = require("./util");
|
|
|
11
11
|
const encoding_1 = require("./utils/encoding");
|
|
12
12
|
const arcgis_rest_request_1 = require("@esri/arcgis-rest-request");
|
|
13
13
|
const fail_safe_1 = require("./utils/fail-safe");
|
|
14
|
+
const hubUserAppResources_1 = require("./utils/hubUserAppResources");
|
|
15
|
+
const fetchAndMigrateUserHubSettings_1 = require("./utils/internal/fetchAndMigrateUserHubSettings");
|
|
16
|
+
const objects_1 = require("./objects");
|
|
17
|
+
/**
|
|
18
|
+
* Properties that we can always serialize/deserialize regardless of authentication status
|
|
19
|
+
*/
|
|
20
|
+
const CONTEXT_SERIALIZABLE_PROPS = [
|
|
21
|
+
"portalUrl",
|
|
22
|
+
"serviceStatus",
|
|
23
|
+
"featureFlags",
|
|
24
|
+
"properties",
|
|
25
|
+
"resourceConfigs",
|
|
26
|
+
"trustedOrgIds",
|
|
27
|
+
"trustedOrgs",
|
|
28
|
+
];
|
|
29
|
+
/**
|
|
30
|
+
* Properties that we only serialize/deserialize if the user is authenticated
|
|
31
|
+
*/
|
|
32
|
+
const CONTEXT_AUTHD_SERIALIZABLE_PROPS = ["resourceTokens", "portal", "currentUser"];
|
|
14
33
|
/**
|
|
15
34
|
* The manager exposes context (`IArcGISContext`), which combines a `UserSession` with
|
|
16
35
|
* the `portal/self` and `user/self` responses to provide a central lookup for platform
|
|
@@ -36,8 +55,10 @@ class ArcGISContextManager {
|
|
|
36
55
|
this._properties = {};
|
|
37
56
|
this._logLevel = logger_1.Level.error;
|
|
38
57
|
this._featureFlags = {};
|
|
58
|
+
this._trustedOrgIds = [];
|
|
59
|
+
this._trustedOrgs = [];
|
|
39
60
|
this._resourceConfigs = [];
|
|
40
|
-
this.
|
|
61
|
+
this._userResourceTokens = [];
|
|
41
62
|
// Having a unique id makes debugging easier
|
|
42
63
|
this.id = new Date().getTime();
|
|
43
64
|
if (opts.logLevel) {
|
|
@@ -66,7 +87,7 @@ class ArcGISContextManager {
|
|
|
66
87
|
this._hubUrl = getHubApiFromPortalUrl_1.getHubApiFromPortalUrl(this._portalUrl);
|
|
67
88
|
}
|
|
68
89
|
if (opts.portal) {
|
|
69
|
-
this.
|
|
90
|
+
this._portal = util_1.cloneObject(opts.portal);
|
|
70
91
|
}
|
|
71
92
|
if (opts.currentUser) {
|
|
72
93
|
this._currentUser = util_1.cloneObject(opts.currentUser);
|
|
@@ -84,10 +105,10 @@ class ArcGISContextManager {
|
|
|
84
105
|
this._trustedOrgs = util_1.cloneObject(opts.trustedOrgs);
|
|
85
106
|
}
|
|
86
107
|
if (opts.resourceConfigs) {
|
|
87
|
-
this._resourceConfigs = opts.resourceConfigs;
|
|
108
|
+
this._resourceConfigs = util_1.cloneObject(opts.resourceConfigs);
|
|
88
109
|
}
|
|
89
110
|
if (opts.resourceTokens) {
|
|
90
|
-
this.
|
|
111
|
+
this._userResourceTokens = util_1.cloneObject(opts.resourceTokens);
|
|
91
112
|
}
|
|
92
113
|
}
|
|
93
114
|
/**
|
|
@@ -113,48 +134,51 @@ class ArcGISContextManager {
|
|
|
113
134
|
* @returns
|
|
114
135
|
*/
|
|
115
136
|
static async deserialize(serializedContext) {
|
|
137
|
+
// decode the string
|
|
116
138
|
const decoded = encoding_1.base64ToUnicode(serializedContext);
|
|
117
139
|
const state = JSON.parse(decoded);
|
|
118
140
|
// create opts and populate from state
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
141
|
+
let opts = {};
|
|
142
|
+
//
|
|
143
|
+
// iterate the serialized props
|
|
144
|
+
CONTEXT_SERIALIZABLE_PROPS.forEach((prop) => {
|
|
145
|
+
opts = util_1.maybeAdd(prop, objects_1.getProp(state, prop), opts);
|
|
146
|
+
});
|
|
147
|
+
// check if there is a session and if it's still valid
|
|
122
148
|
if (state.session) {
|
|
123
|
-
// re-create the session
|
|
124
149
|
const userSession = arcgis_rest_auth_1.UserSession.deserialize(state.session);
|
|
125
|
-
// if the session is still valid, use it and the other properties
|
|
126
150
|
if (userSession.tokenExpires.getTime() > Date.now()) {
|
|
151
|
+
CONTEXT_AUTHD_SERIALIZABLE_PROPS.forEach((prop) => {
|
|
152
|
+
opts = util_1.maybeAdd(prop, objects_1.getProp(state, prop), opts);
|
|
153
|
+
});
|
|
154
|
+
// CRTITICAL: This must be done after the maybeAdd calls above
|
|
155
|
+
// as those return clones of the opts object, and cloneObject
|
|
156
|
+
// does not support cloning a UserSession
|
|
127
157
|
opts.authentication = userSession;
|
|
128
|
-
if (state.portal) {
|
|
129
|
-
opts.portal = state.portal;
|
|
130
|
-
}
|
|
131
|
-
if (state.currentUser) {
|
|
132
|
-
opts.currentUser = state.currentUser;
|
|
133
|
-
}
|
|
134
|
-
if (state.properties) {
|
|
135
|
-
opts.properties = state.properties;
|
|
136
|
-
}
|
|
137
|
-
if (state.trustedOrgIds) {
|
|
138
|
-
opts.trustedOrgIds = state.trustedOrgIds;
|
|
139
|
-
}
|
|
140
|
-
if (state.trustedOrgs) {
|
|
141
|
-
opts.trustedOrgs = state.trustedOrgs;
|
|
142
|
-
}
|
|
143
158
|
}
|
|
144
159
|
}
|
|
145
|
-
else {
|
|
146
|
-
// if the session is expired, we can still carry forward the portalUrl
|
|
147
|
-
// we don't need this when auth is passed b/c it will use that instead
|
|
148
|
-
// of portalUrl
|
|
149
|
-
opts.portalUrl = state.portalUrl;
|
|
150
|
-
}
|
|
151
|
-
// service status and feature flags are safe to carry forward even if session is expired
|
|
152
|
-
opts.serviceStatus = state.serviceStatus;
|
|
153
|
-
opts.featureFlags = state.featureFlags;
|
|
154
|
-
opts.resourceConfigs = state.resourceConfigs;
|
|
155
|
-
opts.resourceTokens = state.resourceTokens;
|
|
156
160
|
return ArcGISContextManager.create(opts);
|
|
157
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Serialize the context into a string that can be stored
|
|
164
|
+
* and re-hydrated
|
|
165
|
+
* @returns
|
|
166
|
+
*/
|
|
167
|
+
serialize() {
|
|
168
|
+
let state = {};
|
|
169
|
+
// iterate the serializable props...
|
|
170
|
+
CONTEXT_SERIALIZABLE_PROPS.forEach((prop) => {
|
|
171
|
+
state = util_1.maybeAdd(prop, objects_1.getProp(this, `_${prop}`), state);
|
|
172
|
+
});
|
|
173
|
+
// If user is authenticated, serialize the session and other auth related props
|
|
174
|
+
if (this._authentication) {
|
|
175
|
+
state.session = this._authentication.serialize();
|
|
176
|
+
CONTEXT_AUTHD_SERIALIZABLE_PROPS.forEach((prop) => {
|
|
177
|
+
state = util_1.maybeAdd(prop, objects_1.getProp(this, `_${prop}`), state);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return encoding_1.unicodeToBase64(JSON.stringify(state));
|
|
181
|
+
}
|
|
158
182
|
/**
|
|
159
183
|
* Set the Authentication (UserSession) for the context.
|
|
160
184
|
* This should be called when a user signs into a running
|
|
@@ -187,9 +211,9 @@ class ArcGISContextManager {
|
|
|
187
211
|
}
|
|
188
212
|
// Clear the auth related props
|
|
189
213
|
this._authentication = null;
|
|
190
|
-
this.
|
|
214
|
+
this._portal = null;
|
|
191
215
|
this._currentUser = null;
|
|
192
|
-
this.
|
|
216
|
+
this._userResourceTokens = [];
|
|
193
217
|
// re-create the context
|
|
194
218
|
this._context = new ArcGISContext_1.ArcGISContext(this.contextOpts);
|
|
195
219
|
}
|
|
@@ -203,40 +227,33 @@ class ArcGISContextManager {
|
|
|
203
227
|
return this._context;
|
|
204
228
|
}
|
|
205
229
|
/**
|
|
206
|
-
*
|
|
207
|
-
* in
|
|
208
|
-
*
|
|
209
|
-
* @
|
|
230
|
+
* Update the User's Hub Settings
|
|
231
|
+
* Stores in the user-app-resource associated with the `hubforarcgis` clientId
|
|
232
|
+
* and updates the context
|
|
233
|
+
* @param settings
|
|
210
234
|
*/
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
serviceStatus: this._serviceStatus,
|
|
215
|
-
featureFlags: this._featureFlags,
|
|
216
|
-
properties: this._properties,
|
|
217
|
-
resourceConfigs: this._resourceConfigs,
|
|
218
|
-
resourceTokens: this._resourceTokens,
|
|
219
|
-
};
|
|
220
|
-
if (this._authentication) {
|
|
221
|
-
state.session = this._authentication.serialize();
|
|
222
|
-
}
|
|
223
|
-
if (this._portalSelf) {
|
|
224
|
-
state.portal = this._portalSelf;
|
|
225
|
-
}
|
|
226
|
-
if (this._currentUser) {
|
|
227
|
-
state.currentUser = this._currentUser;
|
|
235
|
+
async updateUserHubSettings(settings) {
|
|
236
|
+
if (!this._authentication) {
|
|
237
|
+
throw new Error("Cannot update user hub settings without an authenticated user");
|
|
228
238
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
239
|
+
// update the user-app-resource
|
|
240
|
+
await hubUserAppResources_1.updateUserHubSettings(settings, this.context);
|
|
241
|
+
// update the context
|
|
242
|
+
this._userHubSettings = settings;
|
|
243
|
+
// update the feature flags
|
|
244
|
+
Object.keys(objects_1.getWithDefault(settings, "preview", {})).forEach((key) => {
|
|
245
|
+
// only set the flag if it's true, otherwise delete the flag so we revert to default behavior
|
|
246
|
+
if (objects_1.getProp(settings, `preview.${key}`)) {
|
|
247
|
+
this._featureFlags[`hub:feature:${key}`] = true;
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
delete this._featureFlags[`hub:feature:${key}`];
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
this._context = new ArcGISContext_1.ArcGISContext(this.contextOpts);
|
|
236
254
|
}
|
|
237
255
|
/**
|
|
238
|
-
* If we have a UserSession, fetch
|
|
239
|
-
* store that along with current user
|
|
256
|
+
* If we have a UserSession, fetch other resources to populate the context
|
|
240
257
|
*/
|
|
241
258
|
async initialize() {
|
|
242
259
|
// setup array to hold promises and one to track promise index
|
|
@@ -251,7 +268,7 @@ class ArcGISContextManager {
|
|
|
251
268
|
// and we only want to fetch the info, if it was not passed in
|
|
252
269
|
if (this._authentication) {
|
|
253
270
|
const token = await this._authentication.getToken(this._authentication.portal);
|
|
254
|
-
if (!this.
|
|
271
|
+
if (!this._portal) {
|
|
255
272
|
promises.push(arcgis_rest_portal_1.getSelf({ authentication: this._authentication }));
|
|
256
273
|
promiseKeys.push("portal");
|
|
257
274
|
}
|
|
@@ -260,16 +277,17 @@ class ArcGISContextManager {
|
|
|
260
277
|
promises.push(arcgis_rest_portal_1.getUser({ username, authentication: this._authentication }));
|
|
261
278
|
promiseKeys.push("user");
|
|
262
279
|
}
|
|
263
|
-
if (!this._trustedOrgs) {
|
|
280
|
+
if (!this._trustedOrgs.length) {
|
|
264
281
|
promises.push(getTrustedOrgs(this._portalUrl, this._authentication));
|
|
265
282
|
promiseKeys.push("trustedOrgs");
|
|
266
283
|
}
|
|
267
|
-
if
|
|
284
|
+
// if we don't have the tokens but we have resource configs, fetch them
|
|
285
|
+
if (!this._userResourceTokens.length && this._resourceConfigs.length) {
|
|
268
286
|
promises.push(getUserResourceTokens(this._resourceConfigs, token, this._portalUrl + "/sharing/rest"));
|
|
269
287
|
promiseKeys.push("tokens");
|
|
270
288
|
}
|
|
271
|
-
// always add "self" to resourceTokens
|
|
272
|
-
this.
|
|
289
|
+
// always add "self" to resourceTokens, associated with the app's clientId
|
|
290
|
+
this._userResourceTokens.push({
|
|
273
291
|
app: "self",
|
|
274
292
|
token,
|
|
275
293
|
clientId: this._authentication.clientId || "self",
|
|
@@ -292,7 +310,7 @@ class ArcGISContextManager {
|
|
|
292
310
|
const result = results[idx];
|
|
293
311
|
switch (key) {
|
|
294
312
|
case "portal":
|
|
295
|
-
this.
|
|
313
|
+
this._portal = result;
|
|
296
314
|
break;
|
|
297
315
|
case "user":
|
|
298
316
|
this._currentUser = result;
|
|
@@ -302,8 +320,8 @@ class ArcGISContextManager {
|
|
|
302
320
|
this._trustedOrgIds = getTrustedOrgIds(this._trustedOrgs);
|
|
303
321
|
break;
|
|
304
322
|
case "tokens":
|
|
305
|
-
this.
|
|
306
|
-
...this.
|
|
323
|
+
this._userResourceTokens = [
|
|
324
|
+
...this._userResourceTokens,
|
|
307
325
|
...result,
|
|
308
326
|
];
|
|
309
327
|
break;
|
|
@@ -312,6 +330,21 @@ class ArcGISContextManager {
|
|
|
312
330
|
break;
|
|
313
331
|
}
|
|
314
332
|
});
|
|
333
|
+
// if we are auth'd and have a hubforarcgis token,
|
|
334
|
+
// fetch the users IUserHubSettings extract out the
|
|
335
|
+
// preview properties and cross-walk to permissions
|
|
336
|
+
const hubAppToken = this._userResourceTokens.find((e) => e.app === "hubforarcgis");
|
|
337
|
+
if (this._authentication && hubAppToken) {
|
|
338
|
+
this._userHubSettings = await fetchAndMigrateUserHubSettings_1.fetchAndMigrateUserHubSettings(this._authentication.username, this._portalUrl, hubAppToken.token);
|
|
339
|
+
// Check for preview settings and walk the into feature flags
|
|
340
|
+
Object.keys(objects_1.getWithDefault(this._userHubSettings, "preview", {})).forEach((key) => {
|
|
341
|
+
// only set the flag if it's true, otherwise we can override
|
|
342
|
+
// feature flag query params
|
|
343
|
+
if (objects_1.getProp(this._userHubSettings, `preview.${key}`)) {
|
|
344
|
+
this._featureFlags[`hub:feature:${key}`] = true;
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
}
|
|
315
348
|
logger_1.Logger.debug(`ArcGISContextManager-${this.id}: updating context`);
|
|
316
349
|
// update the context
|
|
317
350
|
this._context = new ArcGISContext_1.ArcGISContext(this.contextOpts);
|
|
@@ -320,34 +353,42 @@ class ArcGISContextManager {
|
|
|
320
353
|
* Getter to streamline the creation of updated Context instances
|
|
321
354
|
*/
|
|
322
355
|
get contextOpts() {
|
|
323
|
-
|
|
356
|
+
// Prop names for the IArcGISContextOptions interface do not match
|
|
357
|
+
// up exactly with the prop names on the serialized context so we have to define
|
|
358
|
+
// separate arrays here
|
|
359
|
+
const anonProps = ["hubUrl", ...CONTEXT_SERIALIZABLE_PROPS];
|
|
360
|
+
const authdProps = ["currentUser", "userResourceTokens", "userHubSettings"];
|
|
361
|
+
let contextOpts = {
|
|
324
362
|
id: this.id,
|
|
325
363
|
portalUrl: this._portalUrl,
|
|
326
|
-
hubUrl: this._hubUrl,
|
|
327
|
-
properties: this._properties,
|
|
328
|
-
serviceStatus: this._serviceStatus,
|
|
329
|
-
featureFlags: this._featureFlags,
|
|
330
364
|
};
|
|
365
|
+
// iterate the anon props...
|
|
366
|
+
anonProps.forEach((prop) => {
|
|
367
|
+
contextOpts = util_1.maybeAdd(prop, objects_1.getProp(this, `_${prop}`), contextOpts);
|
|
368
|
+
});
|
|
369
|
+
// If user is authenticated, we can add other props
|
|
331
370
|
if (this._authentication) {
|
|
371
|
+
authdProps.forEach((prop) => {
|
|
372
|
+
contextOpts = util_1.maybeAdd(prop, objects_1.getProp(this, `_${prop}`), contextOpts);
|
|
373
|
+
});
|
|
374
|
+
// CRTITICAL: .authentication must be attached after the maybeAdd calls above
|
|
375
|
+
// as those return clones of the opts object, and cloneObject
|
|
376
|
+
// does not support cloning a UserSession
|
|
332
377
|
contextOpts.authentication = this._authentication;
|
|
333
378
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
if (this._currentUser) {
|
|
338
|
-
contextOpts.currentUser = this._currentUser;
|
|
339
|
-
}
|
|
340
|
-
if (this._trustedOrgIds) {
|
|
341
|
-
contextOpts.trustedOrgIds = this._trustedOrgIds;
|
|
342
|
-
}
|
|
343
|
-
if (this._trustedOrgs) {
|
|
344
|
-
contextOpts.trustedOrgs = this._trustedOrgs;
|
|
345
|
-
}
|
|
346
|
-
contextOpts.userResourceTokens = this._resourceTokens;
|
|
379
|
+
// Handle some special cases where the prop names don't map cleanly
|
|
380
|
+
// and would require a breaking change to fix
|
|
381
|
+
contextOpts.portalSelf = this._portal;
|
|
347
382
|
return contextOpts;
|
|
348
383
|
}
|
|
349
384
|
}
|
|
350
385
|
exports.ArcGISContextManager = ArcGISContextManager;
|
|
386
|
+
/**
|
|
387
|
+
* @internal
|
|
388
|
+
* Fetch the service status for the given portalUrl
|
|
389
|
+
* @param portalUrl
|
|
390
|
+
* @returns
|
|
391
|
+
*/
|
|
351
392
|
function getServiceStatus(portalUrl) {
|
|
352
393
|
let status = HUB_SERVICE_STATUS;
|
|
353
394
|
const isPortal = portalUrl.indexOf("arcgis.com") === -1;
|
|
@@ -360,6 +401,7 @@ function getServiceStatus(portalUrl) {
|
|
|
360
401
|
return Promise.resolve(status);
|
|
361
402
|
}
|
|
362
403
|
/**
|
|
404
|
+
* @internal
|
|
363
405
|
* Get trusted orgs w/ a failSafe to return an empty array
|
|
364
406
|
*/
|
|
365
407
|
async function getTrustedOrgs(_portalUrl, _authentication) {
|
|
@@ -372,11 +414,20 @@ async function getTrustedOrgs(_portalUrl, _authentication) {
|
|
|
372
414
|
return trustedOrgs.trustedOrgs;
|
|
373
415
|
}
|
|
374
416
|
/**
|
|
417
|
+
* @internal
|
|
375
418
|
* Extract trustedOrg ids from trustedOrgs response
|
|
376
419
|
*/
|
|
377
420
|
function getTrustedOrgIds(trustedOrgs) {
|
|
378
421
|
return trustedOrgs.map((org) => org.to.orgId);
|
|
379
422
|
}
|
|
423
|
+
/**
|
|
424
|
+
* @internal
|
|
425
|
+
* Get a set of tokens for the given configs
|
|
426
|
+
* @param configs
|
|
427
|
+
* @param currentToken
|
|
428
|
+
* @param portalUrl
|
|
429
|
+
* @returns
|
|
430
|
+
*/
|
|
380
431
|
async function getUserResourceTokens(configs, currentToken, portalUrl) {
|
|
381
432
|
// failSafe exchangeToken so we don't have to catch
|
|
382
433
|
const failSafeExchange = fail_safe_1.failSafe(arcgis_rest_auth_1.exchangeToken, null);
|
|
@@ -387,7 +438,9 @@ async function getUserResourceTokens(configs, currentToken, portalUrl) {
|
|
|
387
438
|
}
|
|
388
439
|
});
|
|
389
440
|
});
|
|
390
|
-
|
|
441
|
+
const results = await Promise.all(promises);
|
|
442
|
+
// remove any null entries so downstream code doesn't have to check
|
|
443
|
+
return results.filter((e) => !!e);
|
|
391
444
|
}
|
|
392
445
|
const HUB_SERVICE_STATUS = {
|
|
393
446
|
portal: "online",
|