130 lines
4.7 KiB
TypeScript
130 lines
4.7 KiB
TypeScript
// Metro module 11814 (f11815).
|
|
import AuthenticationStore from "../../../stores/AuthenticationStore";
|
|
import { AnalyticEvents, MarketingURLs, Routes } from "../../../Constants";
|
|
import ModalActionCreators from "../../../actions/ModalActionCreators";
|
|
import { showSimpleLoadingModal } from "./SimpleLoadingModal";
|
|
import MobileWebHandoffUtils from "../MobileWebHandoffUtils";
|
|
import AnalyticsUtils from "../../../utils/AnalyticsUtils";
|
|
import { maybeExtractId } from "../../../_bundle/Module513";
|
|
import { getLoginHandoffSourceFromRedirectTo, LoginHandoffSource } from "../../auth/LoginHandoffSource";
|
|
import URLUtils from "../../../utils/URLUtils";
|
|
import Linking from "../../../lib/native/Linking";
|
|
let c8101_8;
|
|
const createHandoffTokenWithLoadingModal = function createHandoffTokenWithLoadingModal({ nonce, fingerprint, handoffSource }) {
|
|
return new Promise((resolve) => {
|
|
ModalActionCreators.popWithKey(c8101_8);
|
|
if (AuthenticationStore.isAuthenticated()) {
|
|
showSimpleLoadingModal(c8101_8, {
|
|
operation: () => MobileWebHandoffUtils.createHandoffToken(nonce),
|
|
onResolved: resolve,
|
|
onRejected: () => {
|
|
AnalyticsUtils.track(AnalyticEvents.MOBILE_WEB_HANDOFF_FAILURE, {
|
|
reason: "handoff_token_fetch_failure",
|
|
fingerprint: maybeExtractId(fingerprint),
|
|
handoff_source: handoffSource
|
|
}, {
|
|
fingerprint
|
|
});
|
|
resolve("null");
|
|
}
|
|
});
|
|
} else {
|
|
AnalyticsUtils.track(AnalyticEvents.MOBILE_WEB_HANDOFF_FAILURE, {
|
|
reason: "user_not_authenticated_in_app",
|
|
fingerprint: maybeExtractId(fingerprint),
|
|
handoff_source: handoffSource
|
|
}, {
|
|
fingerprint
|
|
});
|
|
resolve("null");
|
|
}
|
|
});
|
|
};
|
|
c8101_8 = "mweb-handoff";
|
|
const r27 = {
|
|
redirectWithHandoffToken: async function redirectWithHandoffToken(c27185_0, c27185_1) {
|
|
let c27185_4;
|
|
let env30458;
|
|
c27185_4 = void 0;
|
|
const r10 = env30458 = {};
|
|
let c27185_3 = r10;
|
|
env30458[1] = void 0;
|
|
env30458[2] = void 0;
|
|
env30458[0] = c27185_0;
|
|
let r13 = c27185_1;
|
|
if (r13 === void 0) {
|
|
r13 = {};
|
|
}
|
|
const forceExternalBrowser = r13.forceExternalBrowser;
|
|
if (forceExternalBrowser !== void 0) {
|
|
env30458[1] = forceExternalBrowser;
|
|
const { forceExternalBrowser: _forceExternalBrowser, ...rest } = r13;
|
|
env30458[2] = rest;
|
|
env30458[3] = void 0;
|
|
env30458[4] = void 0;
|
|
env30458[5] = void 0;
|
|
} else {
|
|
env30458[1] = false;
|
|
const { forceExternalBrowser: _forceExternalBrowser, ...rest } = r13;
|
|
env30458[2] = rest;
|
|
env30458[3] = void 0;
|
|
env30458[4] = void 0;
|
|
env30458[5] = void 0;
|
|
}
|
|
await void 0;
|
|
let nonce2 = env30458[2].nonce;
|
|
if (nonce2 == null) {
|
|
nonce2 = MobileWebHandoffUtils.generateNonce();
|
|
}
|
|
env30458[3] = {
|
|
...env30458[2],
|
|
nonce: nonce2,
|
|
handoffSource: getLoginHandoffSourceFromRedirectTo(env30458[0])
|
|
};
|
|
env30458[4] = await (0, createHandoffTokenWithLoadingModal)(env30458[3]);
|
|
env30458[5] = env30458[2].skipLoginRedirect === true ? (function sanitizeRedirectURL(a0) {
|
|
const uRL = new URL(`${location.protocol}${window.GLOBAL_ENV.WEBAPP_ENDPOINT}`);
|
|
const uRL2 = new URL(a0, uRL);
|
|
uRL.pathname = uRL2.pathname;
|
|
uRL.search = uRL2.search;
|
|
uRL.hash = uRL2.hash;
|
|
return uRL;
|
|
})(env30458[0]) : new URL(URLUtils.makeUrl(Routes.LOGIN_HANDOFF, false));
|
|
env30458[5].searchParams.append("handoff_token", env30458[4]);
|
|
if (env30458[2].skipLoginRedirect !== true) {
|
|
env30458[5].searchParams.append("handoff_key", env30458[3].nonce);
|
|
env30458[5].searchParams.append("redirect_to", env30458[0]);
|
|
}
|
|
if (env30458[1]) {
|
|
Linking.openURLExternally(env30458[5].href);
|
|
} else {
|
|
Linking.performURLNavigation(env30458[5].href);
|
|
}
|
|
},
|
|
redirectDeveloperPortalWithHandoffToken: async function redirectDeveloperPortalWithHandoffToken(c27186_0, c27186_1) {
|
|
let c27186_4;
|
|
c27186_4 = void 0;
|
|
let c30459_0 = c27186_0;
|
|
let r36 = c27186_1;
|
|
if (r36 === void 0) {
|
|
r36 = {};
|
|
}
|
|
let c30459_1 = r36;
|
|
await void 0;
|
|
const nonce4 = c30459_1.nonce;
|
|
let nonce3 = nonce4;
|
|
if (nonce4 == null) {
|
|
nonce3 = MobileWebHandoffUtils.generateNonce();
|
|
}
|
|
let c30459_2 = {
|
|
...c30459_1,
|
|
nonce: nonce3,
|
|
handoffSource: LoginHandoffSource.ROLE_SUBSCRIPTION_SETTING
|
|
};
|
|
let c30459_3 = await (0, createHandoffTokenWithLoadingModal)(c30459_2);
|
|
let c30459_4 = new URL(`${location.protocol}${MarketingURLs.DEVELOPER_PORTAL_LOGIN_HANDOFF(c30459_2.nonce, c30459_3, c30459_0)}`);
|
|
Linking.performURLNavigation(c30459_4.href);
|
|
}
|
|
};
|
|
export default r27;
|