Skip to content

Commit

Permalink
chore: generate test link
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienne-deriv committed Sep 24, 2024
1 parent de69d69 commit be1724f
Show file tree
Hide file tree
Showing 10 changed files with 316 additions and 227 deletions.
17 changes: 8 additions & 9 deletions src/javascript/_common/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const Analytics = (() => {
const init = () => {
if (process.env.RUDDERSTACK_KEY && process.env.GROWTHBOOK_CLIENT_KEY && process.env.GROWTHBOOK_DECRYPTION_KEY) {
DerivAnalytics.Analytics.initialise({
growthbookKey : process.env.GROWTHBOOK_CLIENT_KEY, // optional key to enable A/B tests
growthbookKey: process.env.GROWTHBOOK_CLIENT_KEY, // optional key to enable A/B tests

Check failure on line 7 in src/javascript/_common/analytics.js

View workflow job for this annotation

GitHub Actions / Build and Test

Missing space after key 'growthbookKey'

Check failure on line 7 in src/javascript/_common/analytics.js

View workflow job for this annotation

GitHub Actions / build_and_deploy_preview_link

Missing space after key 'growthbookKey'
growthbookDecryptionKey: process.env.GROWTHBOOK_DECRYPTION_KEY, // optional key to enable A/B tests
rudderstackKey : process.env.RUDDERSTACK_KEY,
rudderstackKey: process.env.RUDDERSTACK_KEY,

Check failure on line 9 in src/javascript/_common/analytics.js

View workflow job for this annotation

GitHub Actions / Build and Test

Missing space after key 'rudderstackKey'

Check failure on line 9 in src/javascript/_common/analytics.js

View workflow job for this annotation

GitHub Actions / build_and_deploy_preview_link

Missing space after key 'rudderstackKey'
});
}
};
Expand All @@ -17,20 +17,19 @@ const Analytics = (() => {
const resolvedDefaultValue = defaultValue !== undefined ? defaultValue : false;
const isGBLoaded = isGrowthbookLoaded();

if (!isGBLoaded) return null;
if (!isGBLoaded) return [null, false];
if (DerivAnalytics.Analytics?.getInstances()?.ab) {
return DerivAnalytics.Analytics?.getFeatureValue(featureFlag, resolvedDefaultValue);
return [DerivAnalytics.Analytics?.getFeatureValue(featureFlag, resolvedDefaultValue), true];
}
};

const setGrowthbookOnChange = onChange => {

Check failure on line 26 in src/javascript/_common/analytics.js

View workflow job for this annotation

GitHub Actions / Build and Test

Expected to return a value at the end of arrow function

Check failure on line 26 in src/javascript/_common/analytics.js

View workflow job for this annotation

GitHub Actions / build_and_deploy_preview_link

Expected to return a value at the end of arrow function
const isGBLoaded = isGrowthbookLoaded();
if (!isGBLoaded) return null;
if (DerivAnalytics.Analytics?.getInstances()?.ab) {
DerivAnalytics.Analytics?.getInstances()?.ab?.GrowthBook?.setRenderer(() => {
onChange?.();
});
}

DerivAnalytics.Analytics?.getInstances().ab.GrowthBook?.setRenderer(() => {
onChange?.();
});
};

return {
Expand Down
141 changes: 87 additions & 54 deletions src/javascript/_common/auth.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,118 @@
const Utils = require('@deriv-com/utils');
const {
AppIDConstants,
LocalStorageConstants,
LocalStorageUtils,
URLConstants,
WebSocketUtils,
} = require('@deriv-com/utils');
const Analytics = require('./analytics');

export const DEFAULT_OAUTH_LOGOUT_URL = 'https://oauth.deriv.com/oauth2/sessions/logout';

export const DEFAULT_OAUTH_ORIGIN_URL = 'https://oauth.deriv.com';

const SocketURL = {
[URLConstants.derivP2pProduction]: 'blue.derivws.com',
[URLConstants.derivP2pStaging] : 'red.derivws.com',
};

export const getServerInfo = () => {
const origin = window.location.origin;
const hostname = window.location.hostname;

const existingAppId = LocalStorageUtils.getValue(LocalStorageConstants.configAppId);
const existingServerUrl = LocalStorageUtils.getValue(LocalStorageConstants.configServerURL);
// since we don't have official app_id for staging,
// we will use the red server with app_id=62019 for the staging-p2p.deriv.com for now
// to fix the login issue
if (origin === URLConstants.derivP2pStaging && (!existingAppId || !existingServerUrl)) {
LocalStorageUtils.setValue(LocalStorageConstants.configServerURL, SocketURL[origin]);
LocalStorageUtils.setValue(LocalStorageConstants.configAppId, `${AppIDConstants.domainAppId[hostname]}`);
}

// const storedServerUrl = LocalStorageUtils.getValue(LocalStorageConstants.configServerURL);
const serverUrl = 'qa101.deriv.dev';

const appId = LocalStorageUtils.getValue(LocalStorageConstants.configAppId);
const lang = LocalStorageUtils.getValue(LocalStorageConstants.i18nLanguage);

return {
appId,
lang,
serverUrl,
};
};

export const getOAuthLogoutUrl = () => {
const { appId, serverUrl } = Utils.WebSocketUtils.getServerInfo();
const { appId, serverUrl } = getServerInfo();

const oauthUrl = appId && serverUrl ? `https://${serverUrl}/oauth2/sessions/logout` : DEFAULT_OAUTH_LOGOUT_URL;

return oauthUrl;
};

export const getOAuthOrigin = () => {
const { appId, serverUrl } = Utils.WebSocketUtils.getServerInfo();
const { appId, serverUrl } = getServerInfo();

const oauthUrl = appId && serverUrl ? `https://${serverUrl}` : DEFAULT_OAUTH_ORIGIN_URL;

return oauthUrl;
};

export const AuthClient = (() => {
const isOAuth2Enabled = oAuth2GrowthbookConfig => {
const { OAuth2EnabledApps, OAuth2EnabledAppsInitialised } = oAuth2GrowthbookConfig;
const appId = Utils.WebSocketUtils.getAppId();
export const isOAuth2Enabled = () => {
const [OAuth2EnabledApps, OAuth2EnabledAppsInitialised] = Analytics.getGrowthbookFeatureValue({
featureFlag: 'hydra_be',
});
const appId = WebSocketUtils.getAppId();

if (OAuth2EnabledAppsInitialised) {
const FEHydraAppIds = OAuth2EnabledApps?.length
? OAuth2EnabledApps[OAuth2EnabledApps.length - 1]?.enabled_for ?? []
: [];
return FEHydraAppIds.includes(+appId);
}
if (OAuth2EnabledAppsInitialised) {
const FEHydraAppIds = OAuth2EnabledApps?.length
? OAuth2EnabledApps[OAuth2EnabledApps.length - 1]?.enabled_for ?? []
: [];
return FEHydraAppIds.includes(+appId);
}

return false;
};
const getLogoutHandler = (oAuth2GrowthbookConfig, onWSLogoutAndRedirect) => {
const isAuthEnabled = isOAuth2Enabled(oAuth2GrowthbookConfig);
return false;
};

if (!isAuthEnabled) {
console.log('lol auth2 is not enabled');
return onWSLogoutAndRedirect;
}
export const getLogoutHandler = onWSLogoutAndRedirect => {
const isAuthEnabled = isOAuth2Enabled();

if (!isAuthEnabled) {
return onWSLogoutAndRedirect;
}

const onMessage = async event => {
const allowedOrigin = getOAuthOrigin();
if (allowedOrigin === event.origin) {
if (event.data === 'logout_complete') {
console.log('logout_complete calledd!');
onWSLogoutAndRedirect();
}
const onMessage = async event => {
const allowedOrigin = getOAuthOrigin();
if (allowedOrigin === event.origin) {
if (event.data === 'logout_complete') {
await onWSLogoutAndRedirect();
}
};
}
};

window.addEventListener('message', onMessage);
window.addEventListener('message', onMessage);

const oAuth2Logout = async () => {
if (!isAuthEnabled) {
console.log('lol auth2 is not enabled');
onWSLogoutAndRedirect();
return;
}
const oAuth2Logout = () => {
if (!isAuthEnabled) {
onWSLogoutAndRedirect();
return;
}

let iframe = document.getElementById('logout-iframe');
if (!iframe) {
iframe = document.createElement('iframe');
iframe.id = 'logout-iframe';
iframe.style.display = 'none';
document.body.appendChild(iframe);
let iframe = document.getElementById('logout-iframe');
if (!iframe) {
iframe = document.createElement('iframe');
iframe.id = 'logout-iframe';
iframe.style.display = 'none';
document.body.appendChild(iframe);

setTimeout(() => {
onWSLogoutAndRedirect();
}, 10000);
}
console.log('auth2 doneee');
};
setTimeout(() => {
onWSLogoutAndRedirect();
}, 10000);
}

return oAuth2Logout;
iframe.src = getOAuthLogoutUrl();
};

return {
getLogoutHandler,
isOAuth2Enabled,
};
})();
return oAuth2Logout;
};
Loading

0 comments on commit be1724f

Please sign in to comment.