@esri/hub-common 9.13.1 → 9.13.2
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 +53 -28
- package/dist/es2017/ArcGISContext.js.map +1 -1
- package/dist/esm/ArcGISContext.js +69 -40
- package/dist/esm/ArcGISContext.js.map +1 -1
- package/dist/node/ArcGISContext.js +52 -27
- package/dist/node/ArcGISContext.js.map +1 -1
- package/dist/types/ArcGISContext.d.ts +18 -6
- package/dist/umd/common.umd.js +68 -40
- 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
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { getSelf } from "@esri/arcgis-rest-portal";
|
|
1
|
+
import { getSelf, getUser } from "@esri/arcgis-rest-portal";
|
|
2
2
|
import { ArcGISContextState, } from "./ArcGISContextState";
|
|
3
|
+
import { cloneObject } from ".";
|
|
3
4
|
/**
|
|
4
5
|
* Application Context Object
|
|
5
6
|
*
|
|
@@ -39,6 +40,12 @@ export class ArcGISContext {
|
|
|
39
40
|
else {
|
|
40
41
|
this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
|
|
41
42
|
}
|
|
43
|
+
if (opts.portal) {
|
|
44
|
+
this._portalSelf = cloneObject(opts.portal);
|
|
45
|
+
}
|
|
46
|
+
if (opts.currentUser) {
|
|
47
|
+
this._currentUser = cloneObject(opts.currentUser);
|
|
48
|
+
}
|
|
42
49
|
}
|
|
43
50
|
/**
|
|
44
51
|
* Static async Factory
|
|
@@ -50,33 +57,6 @@ export class ArcGISContext {
|
|
|
50
57
|
await ctx.initialize();
|
|
51
58
|
return ctx;
|
|
52
59
|
}
|
|
53
|
-
/**
|
|
54
|
-
* If we have a UserSession, fetch portal/self and
|
|
55
|
-
* store that along with current user
|
|
56
|
-
*/
|
|
57
|
-
async initialize() {
|
|
58
|
-
let stateOpts = {
|
|
59
|
-
id: this.id,
|
|
60
|
-
portalUrl: this._portalUrl,
|
|
61
|
-
hubUrl: this._hubUrl,
|
|
62
|
-
};
|
|
63
|
-
if (this._authentication) {
|
|
64
|
-
this.log(`ArcGISContext-${this.id}: Initializing`);
|
|
65
|
-
const ps = await getSelf({ authentication: this._authentication });
|
|
66
|
-
this._portalSelf = ps;
|
|
67
|
-
this._currentUser = ps.user;
|
|
68
|
-
stateOpts = {
|
|
69
|
-
id: this.id,
|
|
70
|
-
portalUrl: this._portalUrl,
|
|
71
|
-
hubUrl: this._hubUrl,
|
|
72
|
-
portalSelf: this._portalSelf,
|
|
73
|
-
currentUser: this._currentUser,
|
|
74
|
-
authentication: this._authentication,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
// update the state
|
|
78
|
-
this._state = new ArcGISContextState(stateOpts);
|
|
79
|
-
}
|
|
80
60
|
/**
|
|
81
61
|
* Set the Authentication (UserSession) for the context.
|
|
82
62
|
* This should be called when a user signs into a running
|
|
@@ -129,6 +109,51 @@ export class ArcGISContext {
|
|
|
129
109
|
console.info(message);
|
|
130
110
|
}
|
|
131
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* If we have a UserSession, fetch portal/self and
|
|
114
|
+
* store that along with current user
|
|
115
|
+
*/
|
|
116
|
+
async initialize() {
|
|
117
|
+
// if we have auth, and don't have portalSelf or currentUser, fetch them
|
|
118
|
+
if (this._authentication && (!this._portalSelf || !this._currentUser)) {
|
|
119
|
+
this.log(`ArcGISContext-${this.id}: Initializing`);
|
|
120
|
+
const username = this._authentication.username;
|
|
121
|
+
const requests = [
|
|
122
|
+
getSelf({ authentication: this._authentication }),
|
|
123
|
+
getUser({ username, authentication: this._authentication }),
|
|
124
|
+
];
|
|
125
|
+
try {
|
|
126
|
+
const [portal, user] = await Promise.all(requests);
|
|
127
|
+
this._portalSelf = portal;
|
|
128
|
+
this._currentUser = user;
|
|
129
|
+
}
|
|
130
|
+
catch (ex) {
|
|
131
|
+
const msg = `ArcGISContext could not fetch portal & user for "${this._authentication.username}" using ${this._authentication.portal}.`;
|
|
132
|
+
// tslint:disable-next-line:no-console
|
|
133
|
+
console.error(msg);
|
|
134
|
+
throw ex;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// update the state
|
|
138
|
+
this._state = new ArcGISContextState(this.stateOpts);
|
|
139
|
+
}
|
|
140
|
+
get stateOpts() {
|
|
141
|
+
const stateOpts = {
|
|
142
|
+
id: this.id,
|
|
143
|
+
portalUrl: this._portalUrl,
|
|
144
|
+
hubUrl: this._hubUrl,
|
|
145
|
+
};
|
|
146
|
+
if (this._authentication) {
|
|
147
|
+
stateOpts.authentication = this._authentication;
|
|
148
|
+
}
|
|
149
|
+
if (this._portalSelf) {
|
|
150
|
+
stateOpts.portalSelf = this._portalSelf;
|
|
151
|
+
}
|
|
152
|
+
if (this._currentUser) {
|
|
153
|
+
stateOpts.currentUser = this._currentUser;
|
|
154
|
+
}
|
|
155
|
+
return stateOpts;
|
|
156
|
+
}
|
|
132
157
|
}
|
|
133
158
|
/**
|
|
134
159
|
* Cross-walk from a portalUrl to the corresponding Hub.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArcGISContext.js","sourceRoot":"","sources":["../../src/ArcGISContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAW,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"ArcGISContext.js","sourceRoot":"","sources":["../../src/ArcGISContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAW,MAAM,0BAA0B,CAAC;AAErE,OAAO,EACL,kBAAkB,GAGnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AA2ChC;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,aAAa;IAsBxB;;;;OAIG;IACH,YAAoB,IAA2B;QAfvC,eAAU,GAAW,wBAAwB,CAAC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;YACrB,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;SAC3C;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAED;;;;;;GAMG;AACH,SAAS,sBAAsB,CAAC,SAAiB;IAC/C,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;AAED,SAAS,uBAAuB,CAAC,MAAc;IAC7C,IAAI,MAAM,CAAC;IAEX,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"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __awaiter, __generator } from "tslib";
|
|
2
|
-
import { getSelf } from "@esri/arcgis-rest-portal";
|
|
2
|
+
import { getSelf, getUser } from "@esri/arcgis-rest-portal";
|
|
3
3
|
import { ArcGISContextState, } from "./ArcGISContextState";
|
|
4
|
+
import { cloneObject } from ".";
|
|
4
5
|
/**
|
|
5
6
|
* Application Context Object
|
|
6
7
|
*
|
|
@@ -40,6 +41,12 @@ var ArcGISContext = /** @class */ (function () {
|
|
|
40
41
|
else {
|
|
41
42
|
this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
|
|
42
43
|
}
|
|
44
|
+
if (opts.portal) {
|
|
45
|
+
this._portalSelf = cloneObject(opts.portal);
|
|
46
|
+
}
|
|
47
|
+
if (opts.currentUser) {
|
|
48
|
+
this._currentUser = cloneObject(opts.currentUser);
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
/**
|
|
45
52
|
* Static async Factory
|
|
@@ -62,45 +69,6 @@ var ArcGISContext = /** @class */ (function () {
|
|
|
62
69
|
});
|
|
63
70
|
});
|
|
64
71
|
};
|
|
65
|
-
/**
|
|
66
|
-
* If we have a UserSession, fetch portal/self and
|
|
67
|
-
* store that along with current user
|
|
68
|
-
*/
|
|
69
|
-
ArcGISContext.prototype.initialize = function () {
|
|
70
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
-
var stateOpts, ps;
|
|
72
|
-
return __generator(this, function (_a) {
|
|
73
|
-
switch (_a.label) {
|
|
74
|
-
case 0:
|
|
75
|
-
stateOpts = {
|
|
76
|
-
id: this.id,
|
|
77
|
-
portalUrl: this._portalUrl,
|
|
78
|
-
hubUrl: this._hubUrl,
|
|
79
|
-
};
|
|
80
|
-
if (!this._authentication) return [3 /*break*/, 2];
|
|
81
|
-
this.log("ArcGISContext-" + this.id + ": Initializing");
|
|
82
|
-
return [4 /*yield*/, getSelf({ authentication: this._authentication })];
|
|
83
|
-
case 1:
|
|
84
|
-
ps = _a.sent();
|
|
85
|
-
this._portalSelf = ps;
|
|
86
|
-
this._currentUser = ps.user;
|
|
87
|
-
stateOpts = {
|
|
88
|
-
id: this.id,
|
|
89
|
-
portalUrl: this._portalUrl,
|
|
90
|
-
hubUrl: this._hubUrl,
|
|
91
|
-
portalSelf: this._portalSelf,
|
|
92
|
-
currentUser: this._currentUser,
|
|
93
|
-
authentication: this._authentication,
|
|
94
|
-
};
|
|
95
|
-
_a.label = 2;
|
|
96
|
-
case 2:
|
|
97
|
-
// update the state
|
|
98
|
-
this._state = new ArcGISContextState(stateOpts);
|
|
99
|
-
return [2 /*return*/];
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
72
|
/**
|
|
105
73
|
* Set the Authentication (UserSession) for the context.
|
|
106
74
|
* This should be called when a user signs into a running
|
|
@@ -167,6 +135,67 @@ var ArcGISContext = /** @class */ (function () {
|
|
|
167
135
|
console.info(message);
|
|
168
136
|
}
|
|
169
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;
|
|
187
|
+
}
|
|
188
|
+
if (this._portalSelf) {
|
|
189
|
+
stateOpts.portalSelf = this._portalSelf;
|
|
190
|
+
}
|
|
191
|
+
if (this._currentUser) {
|
|
192
|
+
stateOpts.currentUser = this._currentUser;
|
|
193
|
+
}
|
|
194
|
+
return stateOpts;
|
|
195
|
+
},
|
|
196
|
+
enumerable: false,
|
|
197
|
+
configurable: true
|
|
198
|
+
});
|
|
170
199
|
return ArcGISContext;
|
|
171
200
|
}());
|
|
172
201
|
export { ArcGISContext };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArcGISContext.js","sourceRoot":"","sources":["../../src/ArcGISContext.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAW,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"ArcGISContext.js","sourceRoot":"","sources":["../../src/ArcGISContext.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAW,MAAM,0BAA0B,CAAC;AAErE,OAAO,EACL,kBAAkB,GAGnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AA2ChC;;;;;;;;;;;GAWG;AACH;IAsBE;;;;OAIG;IACH,uBAAoB,IAA2B;QAfv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,WAAW,EAAE;gBACpB,SAAS,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC;aACzC;YACD,IAAI,IAAI,CAAC,YAAY,EAAE;gBACrB,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;aAC3C;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;;;OAAA;IACH,oBAAC;AAAD,CAAC,AA3KD,IA2KC;;AAED;;;;;;GAMG;AACH,SAAS,sBAAsB,CAAC,SAAiB;IAC/C,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;AAED,SAAS,uBAAuB,CAAC,MAAc;IAC7C,IAAI,MAAM,CAAC;IAEX,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"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ArcGISContext = void 0;
|
|
4
4
|
const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
|
|
5
5
|
const ArcGISContextState_1 = require("./ArcGISContextState");
|
|
6
|
+
const _1 = require(".");
|
|
6
7
|
/**
|
|
7
8
|
* Application Context Object
|
|
8
9
|
*
|
|
@@ -42,6 +43,12 @@ class ArcGISContext {
|
|
|
42
43
|
else {
|
|
43
44
|
this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
|
|
44
45
|
}
|
|
46
|
+
if (opts.portal) {
|
|
47
|
+
this._portalSelf = _1.cloneObject(opts.portal);
|
|
48
|
+
}
|
|
49
|
+
if (opts.currentUser) {
|
|
50
|
+
this._currentUser = _1.cloneObject(opts.currentUser);
|
|
51
|
+
}
|
|
45
52
|
}
|
|
46
53
|
/**
|
|
47
54
|
* Static async Factory
|
|
@@ -53,33 +60,6 @@ class ArcGISContext {
|
|
|
53
60
|
await ctx.initialize();
|
|
54
61
|
return ctx;
|
|
55
62
|
}
|
|
56
|
-
/**
|
|
57
|
-
* If we have a UserSession, fetch portal/self and
|
|
58
|
-
* store that along with current user
|
|
59
|
-
*/
|
|
60
|
-
async initialize() {
|
|
61
|
-
let stateOpts = {
|
|
62
|
-
id: this.id,
|
|
63
|
-
portalUrl: this._portalUrl,
|
|
64
|
-
hubUrl: this._hubUrl,
|
|
65
|
-
};
|
|
66
|
-
if (this._authentication) {
|
|
67
|
-
this.log(`ArcGISContext-${this.id}: Initializing`);
|
|
68
|
-
const ps = await arcgis_rest_portal_1.getSelf({ authentication: this._authentication });
|
|
69
|
-
this._portalSelf = ps;
|
|
70
|
-
this._currentUser = ps.user;
|
|
71
|
-
stateOpts = {
|
|
72
|
-
id: this.id,
|
|
73
|
-
portalUrl: this._portalUrl,
|
|
74
|
-
hubUrl: this._hubUrl,
|
|
75
|
-
portalSelf: this._portalSelf,
|
|
76
|
-
currentUser: this._currentUser,
|
|
77
|
-
authentication: this._authentication,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
// update the state
|
|
81
|
-
this._state = new ArcGISContextState_1.ArcGISContextState(stateOpts);
|
|
82
|
-
}
|
|
83
63
|
/**
|
|
84
64
|
* Set the Authentication (UserSession) for the context.
|
|
85
65
|
* This should be called when a user signs into a running
|
|
@@ -132,6 +112,51 @@ class ArcGISContext {
|
|
|
132
112
|
console.info(message);
|
|
133
113
|
}
|
|
134
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* If we have a UserSession, fetch portal/self and
|
|
117
|
+
* store that along with current user
|
|
118
|
+
*/
|
|
119
|
+
async initialize() {
|
|
120
|
+
// if we have auth, and don't have portalSelf or currentUser, fetch them
|
|
121
|
+
if (this._authentication && (!this._portalSelf || !this._currentUser)) {
|
|
122
|
+
this.log(`ArcGISContext-${this.id}: Initializing`);
|
|
123
|
+
const username = this._authentication.username;
|
|
124
|
+
const requests = [
|
|
125
|
+
arcgis_rest_portal_1.getSelf({ authentication: this._authentication }),
|
|
126
|
+
arcgis_rest_portal_1.getUser({ username, authentication: this._authentication }),
|
|
127
|
+
];
|
|
128
|
+
try {
|
|
129
|
+
const [portal, user] = await Promise.all(requests);
|
|
130
|
+
this._portalSelf = portal;
|
|
131
|
+
this._currentUser = user;
|
|
132
|
+
}
|
|
133
|
+
catch (ex) {
|
|
134
|
+
const msg = `ArcGISContext could not fetch portal & user for "${this._authentication.username}" using ${this._authentication.portal}.`;
|
|
135
|
+
// tslint:disable-next-line:no-console
|
|
136
|
+
console.error(msg);
|
|
137
|
+
throw ex;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// update the state
|
|
141
|
+
this._state = new ArcGISContextState_1.ArcGISContextState(this.stateOpts);
|
|
142
|
+
}
|
|
143
|
+
get stateOpts() {
|
|
144
|
+
const stateOpts = {
|
|
145
|
+
id: this.id,
|
|
146
|
+
portalUrl: this._portalUrl,
|
|
147
|
+
hubUrl: this._hubUrl,
|
|
148
|
+
};
|
|
149
|
+
if (this._authentication) {
|
|
150
|
+
stateOpts.authentication = this._authentication;
|
|
151
|
+
}
|
|
152
|
+
if (this._portalSelf) {
|
|
153
|
+
stateOpts.portalSelf = this._portalSelf;
|
|
154
|
+
}
|
|
155
|
+
if (this._currentUser) {
|
|
156
|
+
stateOpts.currentUser = this._currentUser;
|
|
157
|
+
}
|
|
158
|
+
return stateOpts;
|
|
159
|
+
}
|
|
135
160
|
}
|
|
136
161
|
exports.ArcGISContext = ArcGISContext;
|
|
137
162
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArcGISContext.js","sourceRoot":"","sources":["../../src/ArcGISContext.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ArcGISContext.js","sourceRoot":"","sources":["../../src/ArcGISContext.ts"],"names":[],"mappings":";;;AAAA,iEAAqE;AAErE,6DAI8B;AAC9B,wBAAgC;AA2ChC;;;;;;;;;;;GAWG;AACH,MAAa,aAAa;IAsBxB;;;;OAIG;IACH,YAAoB,IAA2B;QAfvC,eAAU,GAAW,wBAAwB,CAAC;QAQ9C,WAAM,GAAG,KAAK,CAAC;QAQrB,4CAA4C;QAC5C,IAAI,CAAC,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;SAC1B;QACD,IAAI,CAAC,GAAG,CAAC,gCAAgC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QAEpD,IAAI,IAAI,CAAC,cAAc,EAAE;YACvB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,cAAc,CAAC;YAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,OAAO,CACnD,eAAe,EACf,EAAE,CACH,CAAC;YACF,IAAI,CAAC,OAAO,GAAG,sBAAsB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;SACxD;aAAM,IAAI,IAAI,CAAC,SAAS,EAAE;YACzB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC;YACjC,IAAI,CAAC,OAAO,GAAG,sB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AK,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"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IPortal } from "@esri/arcgis-rest-portal";
|
|
2
|
+
import { IUser, UserSession } from "@esri/arcgis-rest-auth";
|
|
2
3
|
import { IArcGISContextState } from "./ArcGISContextState";
|
|
3
4
|
/**
|
|
4
5
|
* Options that can be passed into `ArcGISContext.create`
|
|
@@ -20,6 +21,16 @@ export interface IArcGISContextOptions {
|
|
|
20
21
|
* used instead of this property.
|
|
21
22
|
*/
|
|
22
23
|
portalUrl?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Portal self for the authenticated user. If not passed into `.create`
|
|
26
|
+
* with the UserSession, it will be fetched
|
|
27
|
+
*/
|
|
28
|
+
portal?: IPortal;
|
|
29
|
+
/**
|
|
30
|
+
* Current user as `IUser`. If not passed into `.create` with the UserSession
|
|
31
|
+
* it will be fetched.
|
|
32
|
+
*/
|
|
33
|
+
currentUser?: IUser;
|
|
23
34
|
/**
|
|
24
35
|
* If set to `true` additional logging will be sent to the console
|
|
25
36
|
* Defaults to false.
|
|
@@ -64,11 +75,6 @@ export declare class ArcGISContext {
|
|
|
64
75
|
* @returns
|
|
65
76
|
*/
|
|
66
77
|
static create(opts?: IArcGISContextOptions): Promise<ArcGISContext>;
|
|
67
|
-
/**
|
|
68
|
-
* If we have a UserSession, fetch portal/self and
|
|
69
|
-
* store that along with current user
|
|
70
|
-
*/
|
|
71
|
-
initialize(): Promise<void>;
|
|
72
78
|
/**
|
|
73
79
|
* Set the Authentication (UserSession) for the context.
|
|
74
80
|
* This should be called when a user signs into a running
|
|
@@ -95,4 +101,10 @@ export declare class ArcGISContext {
|
|
|
95
101
|
* @param message
|
|
96
102
|
*/
|
|
97
103
|
private log;
|
|
104
|
+
/**
|
|
105
|
+
* If we have a UserSession, fetch portal/self and
|
|
106
|
+
* store that along with current user
|
|
107
|
+
*/
|
|
108
|
+
private initialize;
|
|
109
|
+
private get stateOpts();
|
|
98
110
|
}
|
package/dist/umd/common.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* @preserve
|
|
2
|
-
* @esri/hub-common - v9.13.
|
|
2
|
+
* @esri/hub-common - v9.13.1 - Sat Jan 22 2022 18:07:51 GMT+0000 (Coordinated Universal Time)
|
|
3
3
|
* Copyright (c) 2022 Environmental Systems Research Institute, Inc.
|
|
4
4
|
* Apache-2.0
|
|
5
5
|
*/
|
|
@@ -11045,6 +11045,12 @@
|
|
|
11045
11045
|
else {
|
|
11046
11046
|
this._hubUrl = getHubApiFromPortalUrl(this._portalUrl);
|
|
11047
11047
|
}
|
|
11048
|
+
if (opts.portal) {
|
|
11049
|
+
this._portalSelf = cloneObject$1(opts.portal);
|
|
11050
|
+
}
|
|
11051
|
+
if (opts.currentUser) {
|
|
11052
|
+
this._currentUser = cloneObject$1(opts.currentUser);
|
|
11053
|
+
}
|
|
11048
11054
|
}
|
|
11049
11055
|
/**
|
|
11050
11056
|
* Static async Factory
|
|
@@ -11067,45 +11073,6 @@
|
|
|
11067
11073
|
});
|
|
11068
11074
|
});
|
|
11069
11075
|
};
|
|
11070
|
-
/**
|
|
11071
|
-
* If we have a UserSession, fetch portal/self and
|
|
11072
|
-
* store that along with current user
|
|
11073
|
-
*/
|
|
11074
|
-
ArcGISContext.prototype.initialize = function () {
|
|
11075
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
11076
|
-
var stateOpts, ps;
|
|
11077
|
-
return __generator(this, function (_a) {
|
|
11078
|
-
switch (_a.label) {
|
|
11079
|
-
case 0:
|
|
11080
|
-
stateOpts = {
|
|
11081
|
-
id: this.id,
|
|
11082
|
-
portalUrl: this._portalUrl,
|
|
11083
|
-
hubUrl: this._hubUrl,
|
|
11084
|
-
};
|
|
11085
|
-
if (!this._authentication) return [3 /*break*/, 2];
|
|
11086
|
-
this.log("ArcGISContext-" + this.id + ": Initializing");
|
|
11087
|
-
return [4 /*yield*/, getSelf({ authentication: this._authentication })];
|
|
11088
|
-
case 1:
|
|
11089
|
-
ps = _a.sent();
|
|
11090
|
-
this._portalSelf = ps;
|
|
11091
|
-
this._currentUser = ps.user;
|
|
11092
|
-
stateOpts = {
|
|
11093
|
-
id: this.id,
|
|
11094
|
-
portalUrl: this._portalUrl,
|
|
11095
|
-
hubUrl: this._hubUrl,
|
|
11096
|
-
portalSelf: this._portalSelf,
|
|
11097
|
-
currentUser: this._currentUser,
|
|
11098
|
-
authentication: this._authentication,
|
|
11099
|
-
};
|
|
11100
|
-
_a.label = 2;
|
|
11101
|
-
case 2:
|
|
11102
|
-
// update the state
|
|
11103
|
-
this._state = new ArcGISContextState(stateOpts);
|
|
11104
|
-
return [2 /*return*/];
|
|
11105
|
-
}
|
|
11106
|
-
});
|
|
11107
|
-
});
|
|
11108
|
-
};
|
|
11109
11076
|
/**
|
|
11110
11077
|
* Set the Authentication (UserSession) for the context.
|
|
11111
11078
|
* This should be called when a user signs into a running
|
|
@@ -11172,6 +11139,67 @@
|
|
|
11172
11139
|
console.info(message);
|
|
11173
11140
|
}
|
|
11174
11141
|
};
|
|
11142
|
+
/**
|
|
11143
|
+
* If we have a UserSession, fetch portal/self and
|
|
11144
|
+
* store that along with current user
|
|
11145
|
+
*/
|
|
11146
|
+
ArcGISContext.prototype.initialize = function () {
|
|
11147
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
11148
|
+
var username, requests, _a, portal, user, ex_1, msg;
|
|
11149
|
+
return __generator(this, function (_b) {
|
|
11150
|
+
switch (_b.label) {
|
|
11151
|
+
case 0:
|
|
11152
|
+
if (!(this._authentication && (!this._portalSelf || !this._currentUser))) return [3 /*break*/, 4];
|
|
11153
|
+
this.log("ArcGISContext-" + this.id + ": Initializing");
|
|
11154
|
+
username = this._authentication.username;
|
|
11155
|
+
requests = [
|
|
11156
|
+
getSelf({ authentication: this._authentication }),
|
|
11157
|
+
getUser({ username: username, authentication: this._authentication }),
|
|
11158
|
+
];
|
|
11159
|
+
_b.label = 1;
|
|
11160
|
+
case 1:
|
|
11161
|
+
_b.trys.push([1, 3, , 4]);
|
|
11162
|
+
return [4 /*yield*/, Promise.all(requests)];
|
|
11163
|
+
case 2:
|
|
11164
|
+
_a = _b.sent(), portal = _a[0], user = _a[1];
|
|
11165
|
+
this._portalSelf = portal;
|
|
11166
|
+
this._currentUser = user;
|
|
11167
|
+
return [3 /*break*/, 4];
|
|
11168
|
+
case 3:
|
|
11169
|
+
ex_1 = _b.sent();
|
|
11170
|
+
msg = "ArcGISContext could not fetch portal & user for \"" + this._authentication.username + "\" using " + this._authentication.portal + ".";
|
|
11171
|
+
// tslint:disable-next-line:no-console
|
|
11172
|
+
console.error(msg);
|
|
11173
|
+
throw ex_1;
|
|
11174
|
+
case 4:
|
|
11175
|
+
// update the state
|
|
11176
|
+
this._state = new ArcGISContextState(this.stateOpts);
|
|
11177
|
+
return [2 /*return*/];
|
|
11178
|
+
}
|
|
11179
|
+
});
|
|
11180
|
+
});
|
|
11181
|
+
};
|
|
11182
|
+
Object.defineProperty(ArcGISContext.prototype, "stateOpts", {
|
|
11183
|
+
get: function () {
|
|
11184
|
+
var stateOpts = {
|
|
11185
|
+
id: this.id,
|
|
11186
|
+
portalUrl: this._portalUrl,
|
|
11187
|
+
hubUrl: this._hubUrl,
|
|
11188
|
+
};
|
|
11189
|
+
if (this._authentication) {
|
|
11190
|
+
stateOpts.authentication = this._authentication;
|
|
11191
|
+
}
|
|
11192
|
+
if (this._portalSelf) {
|
|
11193
|
+
stateOpts.portalSelf = this._portalSelf;
|
|
11194
|
+
}
|
|
11195
|
+
if (this._currentUser) {
|
|
11196
|
+
stateOpts.currentUser = this._currentUser;
|
|
11197
|
+
}
|
|
11198
|
+
return stateOpts;
|
|
11199
|
+
},
|
|
11200
|
+
enumerable: false,
|
|
11201
|
+
configurable: true
|
|
11202
|
+
});
|
|
11175
11203
|
return ArcGISContext;
|
|
11176
11204
|
}());
|
|
11177
11205
|
/**
|