pxt-core 8.6.17 → 8.6.18
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/built/pxt.js +160 -108
- package/built/pxtlib.d.ts +13 -28
- package/built/pxtlib.js +160 -108
- package/built/target.js +1 -1
- package/built/web/authcode/js/{main.03da4c20.js → main.241f0fcc.js} +2 -2
- package/built/web/main.js +1 -1
- package/built/web/multiplayer/js/{main.b1d33fe1.js → main.c90f1c21.js} +2 -2
- package/built/web/pxtapp.js +1 -1
- package/built/web/pxtembed.js +2 -2
- package/built/web/pxtlib.js +1 -1
- package/built/web/pxtworker.js +2 -2
- package/built/web/rtlsemantic.css +1 -1
- package/built/web/semantic.css +1 -1
- package/built/web/skillmap/js/{main.8ab8a923.js → main.7f57af89.js} +2 -2
- package/package.json +1 -1
- package/react-common/components/profile/Profile.tsx +1 -1
- package/theme/tutorial-sidebar.less +15 -9
- package/webapp/public/authcode.html +1 -1
- package/webapp/public/multiplayer.html +1 -1
- package/webapp/public/skillmap.html +1 -1
package/built/pxt.js
CHANGED
|
@@ -97891,6 +97891,56 @@ var pxt;
|
|
|
97891
97891
|
const PREFERENCES_DEBOUNCE_MAX_MS = 10 * 1000;
|
|
97892
97892
|
let debouncePreferencesChangedTimeout = 0;
|
|
97893
97893
|
let debouncePreferencesChangedStarted = 0;
|
|
97894
|
+
//
|
|
97895
|
+
// Local storage of auth token.
|
|
97896
|
+
//
|
|
97897
|
+
// Last known auth token state. This is provided as a convenience for legacy methods that cannot be made async.
|
|
97898
|
+
// Preference hasAuthTokenAsync() over taking a dependency on this cached value.
|
|
97899
|
+
auth.cachedHasAuthToken = false;
|
|
97900
|
+
async function getAuthTokenAsync() {
|
|
97901
|
+
let token;
|
|
97902
|
+
try {
|
|
97903
|
+
token = await pxt.storage.shared.getAsync(AUTH_CONTAINER, CSRF_TOKEN_KEY);
|
|
97904
|
+
}
|
|
97905
|
+
catch (_a) { }
|
|
97906
|
+
auth.cachedHasAuthToken = !!token;
|
|
97907
|
+
return token;
|
|
97908
|
+
}
|
|
97909
|
+
auth.getAuthTokenAsync = getAuthTokenAsync;
|
|
97910
|
+
async function setAuthTokenAsync(token) {
|
|
97911
|
+
auth.cachedHasAuthToken = !!token;
|
|
97912
|
+
return await pxt.storage.shared.setAsync(AUTH_CONTAINER, CSRF_TOKEN_KEY, token);
|
|
97913
|
+
}
|
|
97914
|
+
async function hasAuthTokenAsync() {
|
|
97915
|
+
return !!(await getAuthTokenAsync());
|
|
97916
|
+
}
|
|
97917
|
+
auth.hasAuthTokenAsync = hasAuthTokenAsync;
|
|
97918
|
+
async function delAuthTokenAsync() {
|
|
97919
|
+
auth.cachedHasAuthToken = false;
|
|
97920
|
+
return await pxt.storage.shared.delAsync(AUTH_CONTAINER, CSRF_TOKEN_KEY);
|
|
97921
|
+
}
|
|
97922
|
+
async function getUserStateAsync() {
|
|
97923
|
+
let userState;
|
|
97924
|
+
if (await hasAuthTokenAsync()) {
|
|
97925
|
+
try {
|
|
97926
|
+
userState = await pxt.storage.shared.getAsync(AUTH_CONTAINER, AUTH_USER_STATE_KEY);
|
|
97927
|
+
}
|
|
97928
|
+
catch (_a) { }
|
|
97929
|
+
}
|
|
97930
|
+
auth.cachedUserState = userState;
|
|
97931
|
+
return userState;
|
|
97932
|
+
}
|
|
97933
|
+
auth.getUserStateAsync = getUserStateAsync;
|
|
97934
|
+
async function setUserStateAsync(state) {
|
|
97935
|
+
if (await hasAuthTokenAsync()) {
|
|
97936
|
+
auth.cachedUserState = Object.assign({}, state);
|
|
97937
|
+
return await pxt.storage.shared.setAsync(AUTH_CONTAINER, AUTH_USER_STATE_KEY, state);
|
|
97938
|
+
}
|
|
97939
|
+
}
|
|
97940
|
+
async function delUserStateAsync() {
|
|
97941
|
+
auth.cachedUserState = undefined;
|
|
97942
|
+
return await pxt.storage.shared.delAsync(AUTH_CONTAINER, AUTH_USER_STATE_KEY);
|
|
97943
|
+
}
|
|
97894
97944
|
class AuthClient {
|
|
97895
97945
|
constructor() {
|
|
97896
97946
|
this.initialUserPreferences_ = undefined;
|
|
@@ -97900,19 +97950,10 @@ var pxt;
|
|
|
97900
97950
|
_client = this;
|
|
97901
97951
|
}
|
|
97902
97952
|
async initAsync() {
|
|
97903
|
-
//
|
|
97904
|
-
|
|
97905
|
-
|
|
97906
|
-
|
|
97907
|
-
catch (_a) { }
|
|
97908
|
-
if (!this.state$) {
|
|
97909
|
-
this.state$ = {};
|
|
97910
|
-
}
|
|
97911
|
-
this.setUserProfileAsync(this.state$.profile);
|
|
97912
|
-
this.setUserPreferencesAsync(this.state$.preferences);
|
|
97913
|
-
}
|
|
97914
|
-
async authTokenAsync() {
|
|
97915
|
-
return await pxt.storage.shared.getAsync(AUTH_CONTAINER, CSRF_TOKEN_KEY);
|
|
97953
|
+
// Initialize user state from local storage.
|
|
97954
|
+
const state = await getUserStateAsync();
|
|
97955
|
+
this.setUserProfileAsync(state === null || state === void 0 ? void 0 : state.profile);
|
|
97956
|
+
this.setUserPreferencesAsync(state === null || state === void 0 ? void 0 : state.preferences);
|
|
97916
97957
|
}
|
|
97917
97958
|
/**
|
|
97918
97959
|
* Starts the process of authenticating the user against the given identity
|
|
@@ -97925,23 +97966,12 @@ var pxt;
|
|
|
97925
97966
|
* flow completes.
|
|
97926
97967
|
*/
|
|
97927
97968
|
async loginAsync(idp, persistent, callbackState = undefined) {
|
|
97928
|
-
var _a;
|
|
97929
97969
|
if (!hasIdentity() || !idpEnabled(idp)) {
|
|
97930
97970
|
return;
|
|
97931
97971
|
}
|
|
97932
97972
|
callbackState = callbackState !== null && callbackState !== void 0 ? callbackState : NilCallbackState;
|
|
97933
|
-
|
|
97934
|
-
|
|
97935
|
-
if (!state.profile) {
|
|
97936
|
-
await this.authCheckAsync();
|
|
97937
|
-
}
|
|
97938
|
-
const currIdp = (_a = state.profile) === null || _a === void 0 ? void 0 : _a.idp;
|
|
97939
|
-
// Check if we're already signed into this identity provider.
|
|
97940
|
-
if ((currIdp === null || currIdp === void 0 ? void 0 : currIdp.provider) === idp) {
|
|
97941
|
-
pxt.debug(`loginAsync: Already signed into ${idp}.`);
|
|
97942
|
-
return;
|
|
97943
|
-
}
|
|
97944
|
-
this.clearState();
|
|
97973
|
+
// Clear local auth state so we can no longer make authenticated requests.
|
|
97974
|
+
this.clearAuthStateAsync();
|
|
97945
97975
|
// Store some continuation state in local storage so we can return to what
|
|
97946
97976
|
// the user was doing before signing in.
|
|
97947
97977
|
const genId = () => (Math.PI * Math.random()).toString(36).slice(2);
|
|
@@ -97967,7 +97997,10 @@ var pxt;
|
|
|
97967
97997
|
window.location.href = apiResult.resp.loginUrl;
|
|
97968
97998
|
}
|
|
97969
97999
|
else {
|
|
97970
|
-
|
|
98000
|
+
try {
|
|
98001
|
+
await this.onSignInFailed();
|
|
98002
|
+
}
|
|
98003
|
+
catch (_a) { }
|
|
97971
98004
|
}
|
|
97972
98005
|
}
|
|
97973
98006
|
/**
|
|
@@ -97977,8 +98010,13 @@ var pxt;
|
|
|
97977
98010
|
if (!hasIdentity()) {
|
|
97978
98011
|
return;
|
|
97979
98012
|
}
|
|
97980
|
-
|
|
97981
|
-
|
|
98013
|
+
// Clear local auth state so we can no longer make authenticated requests.
|
|
98014
|
+
await this.clearAuthStateAsync();
|
|
98015
|
+
await AuthClient.staticLogoutAsync(continuationHash);
|
|
98016
|
+
try {
|
|
98017
|
+
await this.onSignedOut();
|
|
98018
|
+
}
|
|
98019
|
+
catch (_a) { }
|
|
97982
98020
|
}
|
|
97983
98021
|
/**
|
|
97984
98022
|
* Sign out the user and clear the auth token cookie.
|
|
@@ -97988,15 +98026,18 @@ var pxt;
|
|
|
97988
98026
|
return;
|
|
97989
98027
|
}
|
|
97990
98028
|
pxt.tickEvent('auth.logout');
|
|
97991
|
-
// backend
|
|
97992
|
-
|
|
97993
|
-
|
|
97994
|
-
|
|
97995
|
-
|
|
97996
|
-
|
|
97997
|
-
|
|
98029
|
+
// Tell backend to clear the http-only auth cookie. Ignore errors here, we want to clear local state even if the backend rejects this request.
|
|
98030
|
+
try {
|
|
98031
|
+
await AuthClient.staticApiAsync('/api/auth/logout');
|
|
98032
|
+
}
|
|
98033
|
+
catch (_a) { }
|
|
98034
|
+
// Clear local auth state so we can no longer make authenticated requests.
|
|
98035
|
+
await delAuthTokenAsync();
|
|
98036
|
+
await delUserStateAsync();
|
|
98037
|
+
// Redirect to home screen
|
|
97998
98038
|
if (pxt.BrowserUtils.hasWindow()) {
|
|
97999
|
-
|
|
98039
|
+
const hash = continuationHash ? continuationHash.startsWith('#') ? continuationHash : `#${continuationHash}` : "";
|
|
98040
|
+
window.location.href = `${window.location.origin}${window.location.pathname}${window.location.search}${hash}`;
|
|
98000
98041
|
location.reload();
|
|
98001
98042
|
}
|
|
98002
98043
|
}
|
|
@@ -98006,23 +98047,23 @@ var pxt;
|
|
|
98006
98047
|
if (!await this.loggedInAsync()) {
|
|
98007
98048
|
return;
|
|
98008
98049
|
}
|
|
98009
|
-
const
|
|
98050
|
+
const state = await getUserStateAsync();
|
|
98051
|
+
const userId = (_a = state === null || state === void 0 ? void 0 : state.profile) === null || _a === void 0 ? void 0 : _a.id;
|
|
98010
98052
|
const res = await this.apiAsync('/api/user', null, 'DELETE');
|
|
98011
98053
|
if (res.err) {
|
|
98012
|
-
|
|
98054
|
+
try {
|
|
98055
|
+
await this.onApiError((res.err));
|
|
98056
|
+
}
|
|
98057
|
+
catch (_b) { }
|
|
98013
98058
|
}
|
|
98014
98059
|
else {
|
|
98015
98060
|
try {
|
|
98016
|
-
// Clear
|
|
98017
|
-
await
|
|
98061
|
+
// Clear local auth state so we can no longer make authenticated requests.
|
|
98062
|
+
await this.clearAuthStateAsync();
|
|
98018
98063
|
try {
|
|
98019
98064
|
await this.onProfileDeleted(userId);
|
|
98020
98065
|
}
|
|
98021
|
-
catch (
|
|
98022
|
-
pxt.tickEvent('auth.profile.cloudToLocalFailed');
|
|
98023
|
-
}
|
|
98024
|
-
// Update state and UI to reflect logged out state.
|
|
98025
|
-
this.clearState();
|
|
98066
|
+
catch (_c) { }
|
|
98026
98067
|
}
|
|
98027
98068
|
finally {
|
|
98028
98069
|
pxt.tickEvent('auth.profile.deleted');
|
|
@@ -98043,12 +98084,12 @@ var pxt;
|
|
|
98043
98084
|
if (!await this.loggedInAsync()) {
|
|
98044
98085
|
return undefined;
|
|
98045
98086
|
}
|
|
98046
|
-
const state =
|
|
98087
|
+
const state = await getUserStateAsync();
|
|
98047
98088
|
return Object.assign({}, state.profile);
|
|
98048
98089
|
}
|
|
98049
98090
|
async userPreferencesAsync() {
|
|
98050
98091
|
//if (!await this.loggedInAsync()) { return undefined; } // allow even when not signed in.
|
|
98051
|
-
const state =
|
|
98092
|
+
const state = await getUserStateAsync();
|
|
98052
98093
|
return Object.assign({}, state.preferences);
|
|
98053
98094
|
}
|
|
98054
98095
|
/**
|
|
@@ -98060,12 +98101,12 @@ var pxt;
|
|
|
98060
98101
|
if (!hasIdentity()) {
|
|
98061
98102
|
return undefined;
|
|
98062
98103
|
}
|
|
98063
|
-
|
|
98064
|
-
if (!(await pxt.storage.shared.getAsync(AUTH_CONTAINER, CSRF_TOKEN_KEY))) {
|
|
98104
|
+
if (!(await hasAuthTokenAsync())) {
|
|
98065
98105
|
return undefined;
|
|
98066
98106
|
}
|
|
98067
|
-
const state =
|
|
98068
|
-
if ((_a = state.profile) === null || _a === void 0 ? void 0 : _a.id) {
|
|
98107
|
+
const state = await getUserStateAsync();
|
|
98108
|
+
if ((_a = state === null || state === void 0 ? void 0 : state.profile) === null || _a === void 0 ? void 0 : _a.id) {
|
|
98109
|
+
// If we already have a user profile, return it.
|
|
98069
98110
|
if (!this.initialAuthCheck_) {
|
|
98070
98111
|
this.initialAuthCheck_ = Promise.resolve(state.profile);
|
|
98071
98112
|
}
|
|
@@ -98079,14 +98120,16 @@ var pxt;
|
|
|
98079
98120
|
return this.initialAuthCheck_;
|
|
98080
98121
|
}
|
|
98081
98122
|
async loggedInAsync() {
|
|
98082
|
-
await this.authCheckAsync();
|
|
98083
|
-
|
|
98123
|
+
const profile = await this.authCheckAsync();
|
|
98124
|
+
if (!profile)
|
|
98125
|
+
return false;
|
|
98126
|
+
return await this.hasUserIdAsync();
|
|
98084
98127
|
}
|
|
98085
98128
|
async updateUserProfileAsync(opts) {
|
|
98086
98129
|
if (!await this.loggedInAsync()) {
|
|
98087
98130
|
return false;
|
|
98088
98131
|
}
|
|
98089
|
-
const state =
|
|
98132
|
+
const state = await getUserStateAsync();
|
|
98090
98133
|
const result = await this.apiAsync('/api/user/profile', {
|
|
98091
98134
|
id: state.profile.id,
|
|
98092
98135
|
username: opts.username,
|
|
@@ -98181,22 +98224,28 @@ var pxt;
|
|
|
98181
98224
|
}
|
|
98182
98225
|
}
|
|
98183
98226
|
}
|
|
98184
|
-
|
|
98227
|
+
async hasUserIdAsync() {
|
|
98185
98228
|
var _a;
|
|
98186
98229
|
if (!hasIdentity()) {
|
|
98187
98230
|
return false;
|
|
98188
98231
|
}
|
|
98189
|
-
|
|
98190
|
-
|
|
98232
|
+
if (!(await hasAuthTokenAsync())) {
|
|
98233
|
+
return undefined;
|
|
98234
|
+
}
|
|
98235
|
+
const state = await getUserStateAsync();
|
|
98236
|
+
return !!((_a = state === null || state === void 0 ? void 0 : state.profile) === null || _a === void 0 ? void 0 : _a.id);
|
|
98191
98237
|
}
|
|
98192
98238
|
async fetchUserAsync() {
|
|
98193
98239
|
var _a;
|
|
98194
98240
|
if (!hasIdentity()) {
|
|
98195
98241
|
return undefined;
|
|
98196
98242
|
}
|
|
98197
|
-
|
|
98243
|
+
if (!(await hasAuthTokenAsync())) {
|
|
98244
|
+
return undefined;
|
|
98245
|
+
}
|
|
98246
|
+
const state = await getUserStateAsync();
|
|
98198
98247
|
// We already have a user, no need to get it again.
|
|
98199
|
-
if ((_a = state.profile) === null || _a === void 0 ? void 0 : _a.id) {
|
|
98248
|
+
if ((_a = state === null || state === void 0 ? void 0 : state.profile) === null || _a === void 0 ? void 0 : _a.id) {
|
|
98200
98249
|
return state.profile;
|
|
98201
98250
|
}
|
|
98202
98251
|
const result = await this.apiAsync('/api/user/profile');
|
|
@@ -98208,34 +98257,48 @@ var pxt;
|
|
|
98208
98257
|
return undefined;
|
|
98209
98258
|
}
|
|
98210
98259
|
async setUserProfileAsync(profile) {
|
|
98211
|
-
const wasLoggedIn = this.
|
|
98212
|
-
this.
|
|
98213
|
-
const isLoggedIn = this.
|
|
98214
|
-
|
|
98260
|
+
const wasLoggedIn = await this.hasUserIdAsync();
|
|
98261
|
+
await this.transformUserProfileAsync(profile);
|
|
98262
|
+
const isLoggedIn = await this.hasUserIdAsync();
|
|
98263
|
+
try {
|
|
98264
|
+
await this.onUserProfileChanged();
|
|
98265
|
+
}
|
|
98266
|
+
catch (_a) { }
|
|
98215
98267
|
//pxt.data.invalidate(USER_PROFILE);
|
|
98216
98268
|
if (isLoggedIn && !wasLoggedIn) {
|
|
98217
|
-
|
|
98269
|
+
try {
|
|
98270
|
+
await this.onSignedIn();
|
|
98271
|
+
}
|
|
98272
|
+
catch (_b) { }
|
|
98218
98273
|
//pxt.data.invalidate(LOGGED_IN);
|
|
98219
98274
|
}
|
|
98220
98275
|
else if (!isLoggedIn && wasLoggedIn) {
|
|
98221
|
-
|
|
98276
|
+
try {
|
|
98277
|
+
await this.onSignedOut();
|
|
98278
|
+
}
|
|
98279
|
+
catch (_c) { }
|
|
98222
98280
|
//pxt.data.invalidate(LOGGED_IN);
|
|
98223
98281
|
}
|
|
98224
98282
|
}
|
|
98225
98283
|
async setUserPreferencesAsync(newPref) {
|
|
98226
98284
|
var _a;
|
|
98227
|
-
const
|
|
98285
|
+
const state = await getUserStateAsync();
|
|
98286
|
+
const oldPref = (_a = state === null || state === void 0 ? void 0 : state.preferences) !== null && _a !== void 0 ? _a : auth.DEFAULT_USER_PREFERENCES();
|
|
98228
98287
|
const diff = ts.pxtc.jsonPatch.diff(oldPref, newPref);
|
|
98229
98288
|
// update
|
|
98230
|
-
this.
|
|
98231
|
-
|
|
98289
|
+
const finalPref = await this.transformUserPreferencesAsync(Object.assign(Object.assign({}, oldPref), newPref));
|
|
98290
|
+
try {
|
|
98291
|
+
await this.onUserPreferencesChanged(diff);
|
|
98292
|
+
}
|
|
98293
|
+
catch (_b) { }
|
|
98294
|
+
return finalPref;
|
|
98232
98295
|
}
|
|
98233
98296
|
async fetchUserPreferencesAsync() {
|
|
98234
98297
|
// Wait for the initial auth
|
|
98235
98298
|
if (!await this.loggedInAsync()) {
|
|
98236
98299
|
return undefined;
|
|
98237
98300
|
}
|
|
98238
|
-
const state =
|
|
98301
|
+
const state = await getUserStateAsync();
|
|
98239
98302
|
const result = await this.apiAsync('/api/user/preferences');
|
|
98240
98303
|
if (result.success) {
|
|
98241
98304
|
// Set user profile from returned value
|
|
@@ -98243,52 +98306,41 @@ var pxt;
|
|
|
98243
98306
|
// Note the cloud should send partial information back if it is missing
|
|
98244
98307
|
// a field. So e.g. if the language has never been set in the cloud, it won't
|
|
98245
98308
|
// overwrite the local state.
|
|
98246
|
-
this.setUserPreferencesAsync(result.resp);
|
|
98309
|
+
const prefs = this.setUserPreferencesAsync(result.resp);
|
|
98247
98310
|
// update our one-time promise for the initial load
|
|
98248
|
-
return
|
|
98311
|
+
return prefs;
|
|
98249
98312
|
}
|
|
98250
98313
|
}
|
|
98251
98314
|
return undefined;
|
|
98252
98315
|
}
|
|
98253
98316
|
/**
|
|
98254
98317
|
* Updates user profile state and writes it to local storage.
|
|
98255
|
-
* Direct access to state$ allowed.
|
|
98256
98318
|
*/
|
|
98257
|
-
|
|
98258
|
-
|
|
98259
|
-
|
|
98319
|
+
async transformUserProfileAsync(profile) {
|
|
98320
|
+
let state = await getUserStateAsync();
|
|
98321
|
+
state = Object.assign(Object.assign({}, state), { profile: Object.assign({}, profile) });
|
|
98322
|
+
await setUserStateAsync(state);
|
|
98323
|
+
return state.profile;
|
|
98260
98324
|
}
|
|
98261
98325
|
/**
|
|
98262
98326
|
* Updates user preference state and writes it to local storage.
|
|
98263
|
-
* Direct access to state$ allowed.
|
|
98264
|
-
*/
|
|
98265
|
-
transformUserPreferences(preferences) {
|
|
98266
|
-
this.state$ = Object.assign(Object.assign({}, this.state$), { preferences: Object.assign({}, preferences) });
|
|
98267
|
-
this.saveState();
|
|
98268
|
-
}
|
|
98269
|
-
/**
|
|
98270
|
-
* Read-only access to current state.
|
|
98271
|
-
* Direct access to state$ allowed.
|
|
98272
|
-
*/
|
|
98273
|
-
/*private*/ getState() {
|
|
98274
|
-
return this.state$;
|
|
98275
|
-
}
|
|
98276
|
-
;
|
|
98277
|
-
/**
|
|
98278
|
-
* Write auth state to local storage.
|
|
98279
|
-
* Direct access to state$ allowed.
|
|
98280
98327
|
*/
|
|
98281
|
-
|
|
98282
|
-
|
|
98328
|
+
async transformUserPreferencesAsync(preferences) {
|
|
98329
|
+
let state = await getUserStateAsync();
|
|
98330
|
+
state = Object.assign(Object.assign({}, state), { preferences: Object.assign({}, preferences) });
|
|
98331
|
+
await setUserStateAsync(state);
|
|
98332
|
+
return state.preferences;
|
|
98283
98333
|
}
|
|
98284
98334
|
/**
|
|
98285
|
-
* Clear
|
|
98286
|
-
* Direct access to state$ allowed.
|
|
98335
|
+
* Clear local auth state then call the onStateCleared callback.
|
|
98287
98336
|
*/
|
|
98288
|
-
|
|
98289
|
-
|
|
98290
|
-
|
|
98291
|
-
|
|
98337
|
+
async clearAuthStateAsync() {
|
|
98338
|
+
await delAuthTokenAsync();
|
|
98339
|
+
await delUserStateAsync();
|
|
98340
|
+
try {
|
|
98341
|
+
await this.onStateCleared();
|
|
98342
|
+
}
|
|
98343
|
+
catch (_a) { }
|
|
98292
98344
|
}
|
|
98293
98345
|
/*protected*/ async apiAsync(url, data, method, authToken) {
|
|
98294
98346
|
return await AuthClient.staticApiAsync(url, data, method, authToken);
|
|
@@ -98296,7 +98348,7 @@ var pxt;
|
|
|
98296
98348
|
static async staticApiAsync(url, data, method, authToken) {
|
|
98297
98349
|
var _a;
|
|
98298
98350
|
const headers = {};
|
|
98299
|
-
authToken = authToken || (await
|
|
98351
|
+
authToken = authToken || (await getAuthTokenAsync());
|
|
98300
98352
|
if (authToken) {
|
|
98301
98353
|
headers["authorization"] = `mkcd ${authToken}`;
|
|
98302
98354
|
}
|
|
@@ -98381,14 +98433,14 @@ var pxt;
|
|
|
98381
98433
|
// "Remember me" wasn't selected because this token is not usable
|
|
98382
98434
|
// without its cookie-based counterpart. When "Remember me" is false,
|
|
98383
98435
|
// the cookie is not persisted.
|
|
98384
|
-
await
|
|
98436
|
+
await setAuthTokenAsync(authToken);
|
|
98385
98437
|
pxt.tickEvent('auth.login.success', { 'provider': loginState.idp });
|
|
98386
98438
|
} while (false);
|
|
98387
98439
|
// Clear url parameters and redirect to the callback location.
|
|
98388
98440
|
const hash = callbackState.hash.startsWith('#') ? callbackState.hash : `#${callbackState.hash}`;
|
|
98389
98441
|
const params = pxt.Util.stringifyQueryString('', callbackState.params);
|
|
98390
98442
|
const pathname = loginState.callbackPathname.startsWith('/') ? loginState.callbackPathname : `/${loginState.callbackPathname}`;
|
|
98391
|
-
const redirect = `${pathname}${
|
|
98443
|
+
const redirect = `${pathname}${params}${hash}`;
|
|
98392
98444
|
window.location.href = redirect;
|
|
98393
98445
|
}
|
|
98394
98446
|
auth.loginCallbackAsync = loginCallbackAsync;
|
|
@@ -98420,9 +98472,9 @@ var pxt;
|
|
|
98420
98472
|
return (_d = (_b = (_a = user === null || user === void 0 ? void 0 : user.idp) === null || _a === void 0 ? void 0 : _a.displayName) !== null && _b !== void 0 ? _b : (_c = user === null || user === void 0 ? void 0 : user.idp) === null || _c === void 0 ? void 0 : _c.username) !== null && _d !== void 0 ? _d : EMPTY_USERNAME;
|
|
98421
98473
|
}
|
|
98422
98474
|
auth.userName = userName;
|
|
98423
|
-
function identityProviderId() {
|
|
98424
|
-
var _a
|
|
98425
|
-
return (
|
|
98475
|
+
function identityProviderId(user) {
|
|
98476
|
+
var _a;
|
|
98477
|
+
return (_a = user === null || user === void 0 ? void 0 : user.idp) === null || _a === void 0 ? void 0 : _a.provider;
|
|
98426
98478
|
}
|
|
98427
98479
|
auth.identityProviderId = identityProviderId;
|
|
98428
98480
|
function firstName(user) {
|
|
@@ -103525,7 +103577,7 @@ var pxt;
|
|
|
103525
103577
|
(function (pxt) {
|
|
103526
103578
|
var cloud;
|
|
103527
103579
|
(function (cloud) {
|
|
103528
|
-
const DEV_BACKEND_PROD = "https://
|
|
103580
|
+
const DEV_BACKEND_PROD = "https://makecode.com";
|
|
103529
103581
|
const DEV_BACKEND_STAGING = "https://staging.pxt.io";
|
|
103530
103582
|
const DEV_BACKEND_LOCALHOST = "http://localhost:8080";
|
|
103531
103583
|
cloud.DEV_BACKEND = DEV_BACKEND_STAGING;
|
package/built/pxtlib.d.ts
CHANGED
|
@@ -84,18 +84,17 @@ declare namespace pxt.auth {
|
|
|
84
84
|
/**
|
|
85
85
|
* Cloud-synced user state.
|
|
86
86
|
*/
|
|
87
|
-
type
|
|
87
|
+
type UserState = {
|
|
88
88
|
profile?: UserProfile;
|
|
89
89
|
preferences?: UserPreferences;
|
|
90
90
|
};
|
|
91
91
|
function client(): AuthClient;
|
|
92
|
+
let cachedHasAuthToken: boolean;
|
|
93
|
+
function getAuthTokenAsync(): Promise<string>;
|
|
94
|
+
function hasAuthTokenAsync(): Promise<boolean>;
|
|
95
|
+
let cachedUserState: Readonly<UserState>;
|
|
96
|
+
function getUserStateAsync(): Promise<Readonly<UserState>>;
|
|
92
97
|
abstract class AuthClient {
|
|
93
|
-
/**
|
|
94
|
-
* In-memory cache of user profile state. This is persisted in local storage.
|
|
95
|
-
* DO NOT ACCESS DIRECTLY UNLESS YOU KNOW IT IS OK. Functions allowed direct
|
|
96
|
-
* access are marked as such below.
|
|
97
|
-
*/
|
|
98
|
-
private state$;
|
|
99
98
|
constructor();
|
|
100
99
|
initAsync(): Promise<void>;
|
|
101
100
|
protected abstract onSignedIn(): Promise<void>;
|
|
@@ -106,7 +105,6 @@ declare namespace pxt.auth {
|
|
|
106
105
|
protected abstract onProfileDeleted(userId: string): Promise<void>;
|
|
107
106
|
protected abstract onApiError(err: any): Promise<void>;
|
|
108
107
|
protected abstract onStateCleared(): Promise<void>;
|
|
109
|
-
authTokenAsync(): Promise<string>;
|
|
110
108
|
/**
|
|
111
109
|
* Starts the process of authenticating the user against the given identity
|
|
112
110
|
* provider. Upon success the backend will write an http-only session cookie
|
|
@@ -147,36 +145,23 @@ declare namespace pxt.auth {
|
|
|
147
145
|
immediate?: boolean;
|
|
148
146
|
filter?: (op: ts.pxtc.jsonPatch.PatchOperation) => boolean;
|
|
149
147
|
}): Promise<SetPrefResult>;
|
|
150
|
-
|
|
148
|
+
private hasUserIdAsync;
|
|
151
149
|
private fetchUserAsync;
|
|
152
150
|
private setUserProfileAsync;
|
|
153
151
|
private setUserPreferencesAsync;
|
|
154
152
|
private fetchUserPreferencesAsync;
|
|
155
153
|
/**
|
|
156
154
|
* Updates user profile state and writes it to local storage.
|
|
157
|
-
* Direct access to state$ allowed.
|
|
158
155
|
*/
|
|
159
|
-
private
|
|
156
|
+
private transformUserProfileAsync;
|
|
160
157
|
/**
|
|
161
158
|
* Updates user preference state and writes it to local storage.
|
|
162
|
-
* Direct access to state$ allowed.
|
|
163
|
-
*/
|
|
164
|
-
protected transformUserPreferences(preferences: UserPreferences): void;
|
|
165
|
-
/**
|
|
166
|
-
* Read-only access to current state.
|
|
167
|
-
* Direct access to state$ allowed.
|
|
168
|
-
*/
|
|
169
|
-
getState(): Readonly<State>;
|
|
170
|
-
/**
|
|
171
|
-
* Write auth state to local storage.
|
|
172
|
-
* Direct access to state$ allowed.
|
|
173
159
|
*/
|
|
174
|
-
|
|
160
|
+
protected transformUserPreferencesAsync(preferences: UserPreferences): Promise<UserPreferences>;
|
|
175
161
|
/**
|
|
176
|
-
* Clear
|
|
177
|
-
* Direct access to state$ allowed.
|
|
162
|
+
* Clear local auth state then call the onStateCleared callback.
|
|
178
163
|
*/
|
|
179
|
-
private
|
|
164
|
+
private clearAuthStateAsync;
|
|
180
165
|
apiAsync<T = any>(url: string, data?: any, method?: string, authToken?: string): Promise<ApiResult<T>>;
|
|
181
166
|
static staticApiAsync<T = any>(url: string, data?: any, method?: string, authToken?: string): Promise<ApiResult<T>>;
|
|
182
167
|
}
|
|
@@ -190,7 +175,7 @@ declare namespace pxt.auth {
|
|
|
190
175
|
function hasIdentity(): boolean;
|
|
191
176
|
function enableAuth(enabled?: boolean): void;
|
|
192
177
|
function userName(user: pxt.auth.UserProfile): string;
|
|
193
|
-
function identityProviderId(): pxt.IdentityProviderId | undefined;
|
|
178
|
+
function identityProviderId(user: pxt.auth.UserProfile): pxt.IdentityProviderId | undefined;
|
|
194
179
|
function firstName(user: pxt.auth.UserProfile): string;
|
|
195
180
|
function userInitials(user: pxt.auth.UserProfile): string;
|
|
196
181
|
function generateUserProfilePicDataUrl(profile: pxt.auth.UserProfile): void;
|
|
@@ -883,7 +868,7 @@ declare namespace pxt.BrowserUtils {
|
|
|
883
868
|
}
|
|
884
869
|
declare namespace pxt.cloud {
|
|
885
870
|
export type DevBackendType = "default" | "prod" | "staging" | "localhost";
|
|
886
|
-
const DEV_BACKEND_PROD = "https://
|
|
871
|
+
const DEV_BACKEND_PROD = "https://makecode.com";
|
|
887
872
|
const DEV_BACKEND_STAGING = "https://staging.pxt.io";
|
|
888
873
|
const DEV_BACKEND_LOCALHOST = "http://localhost:8080";
|
|
889
874
|
type BackendUrls = typeof DEV_BACKEND_PROD | typeof DEV_BACKEND_STAGING | typeof DEV_BACKEND_LOCALHOST;
|