Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"_minorVersionBump": "gulp minorVersionBump",
"_majorVersionBump": "gulp majorVersionBump",
"serve": "node serve-proxy.js . -p 8000 -c-1",
"serveLocalAccount": "node serve-proxy.js . -p 8000 -c-1 --localAccount",
"_serveWithWebCacheHelp": "echo !!!Make sure to npm run release:dev/stageing/prod before testing the cache!!!",
"serveWithWebCache": "npm run _releaseWebCache && npm run _serveWithWebCacheHelp && http-server ./dist -p 8000 -c-1",
"serveExternal": "node serve-proxy.js . -p 8000 -a 0.0.0.0 --log-ip -c-1",
Expand Down Expand Up @@ -118,4 +119,4 @@
"tinycolor2": "^1.4.2",
"underscore": "^1.13.4"
}
}
}
14 changes: 8 additions & 6 deletions serve-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const fs = require('fs');
const httpProxy = require('http-proxy');

// Account server configuration - switch between local and production
const ACCOUNT_SERVER = 'https://account.phcode.dev'; // Production
// const ACCOUNT_SERVER = 'http://localhost:5000'; // Local development
let accountServer = 'https://account.phcode.dev'; // Production
// Set to local development server if --localAccount flag is provided

// Default configuration
let config = {
Expand Down Expand Up @@ -45,6 +45,8 @@ function parseArgs() {
config.silent = true;
} else if (arg === '--log-ip') {
config.logIp = true;
} else if (arg === '--localAccount') {
accountServer = 'http://localhost:5000';
} else if (!arg.startsWith('-')) {
config.root = path.resolve(arg);
}
Expand Down Expand Up @@ -74,7 +76,7 @@ proxy.on('proxyReq', (proxyReq, req) => {
const originalOrigin = req.headers.origin;

// Set target host
const accountHost = new URL(ACCOUNT_SERVER).hostname;
const accountHost = new URL(accountServer).hostname;
proxyReq.setHeader('Host', accountHost);

// Transform referer from localhost:8000 to phcode.dev
Expand Down Expand Up @@ -262,12 +264,12 @@ const server = http.createServer((req, res) => {
req.url = targetPath + (parsedUrl.search || '');

if (!config.silent) {
console.log(`[PROXY] ${req.method} ${originalUrl} -> ${ACCOUNT_SERVER}${req.url}`);
console.log(`[PROXY] ${req.method} ${originalUrl} -> ${accountServer}${req.url}`);
}

// Proxy the request
proxy.web(req, res, {
target: ACCOUNT_SERVER,
target: accountServer,
changeOrigin: true,
secure: true
});
Expand Down Expand Up @@ -313,7 +315,7 @@ server.listen(config.port, config.host, () => {
console.log(`Available on:`);
console.log(` http://${config.host === '0.0.0.0' ? 'localhost' : config.host}:${config.port}`);
console.log(`Proxy routes:`);
console.log(` /proxy/accounts/* -> ${ACCOUNT_SERVER}/*`);
console.log(` /proxy/accounts/* -> ${accountServer}/*`);
console.log('Hit CTRL-C to stop the server');
}
});
Expand Down
43 changes: 37 additions & 6 deletions src/services/promotions.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,24 @@ define(function (require, exports, module) {
}
}

/**
* Check if user has active pro subscription
* Returns true if user is logged in and has a paid subscription
*/
async function _hasProSubscription() {
try {
// First verify login status to ensure login state is properly resolved
await LoginService.verifyLoginStatus();

// getEntitlements() returns null if not logged in
const entitlements = await LoginService.getEntitlements();
return entitlements && entitlements.plan && entitlements.plan.paidSubscriber === true;
} catch (error) {
console.error("Error checking pro subscription:", error);
return false;
}
}

/**
* Check if pro trial is currently activated
*/
Expand Down Expand Up @@ -205,10 +223,14 @@ define(function (require, exports, module) {
if (remainingDays <= 0 && !isNewerVersion) {
// Check if promo ended dialog was already shown for this version
if (existingTrialData.upgradeDialogShownVersion !== currentVersion) {
// todo we should not show this to logged in pro subscribers, but at startup time,
// we do not know if login is done yet.
console.log("Existing trial expired, showing promo ended dialog");
ProDialogs.showProEndedDialog();
// Check if user has pro subscription before showing promo dialog
const hasProSubscription = await _hasProSubscription();
if (!hasProSubscription) {
console.log("Existing trial expired, showing promo ended dialog");
ProDialogs.showProEndedDialog();
} else {
console.log("Existing trial expired, but user has pro subscription - skipping promo dialog");
}
// Store that dialog was shown for this version
await _setTrialData({
...existingTrialData,
Expand Down Expand Up @@ -256,7 +278,13 @@ define(function (require, exports, module) {
Metrics.countEvent(Metrics.EVENT_TYPE.PRO, "trial", "activated");
console.log(`Pro trial activated for ${trialDays} days`);

ProDialogs.showProUpgradeDialog(trialDays);
// Check if user has pro subscription before showing upgrade dialog
const hasProSubscription = await _hasProSubscription();
if (!hasProSubscription) {
ProDialogs.showProUpgradeDialog(trialDays);
} else {
console.log("Pro trial activated, but user has pro subscription - skipping upgrade dialog");
}
// Trigger the event for UI to handle
LoginService.trigger(EVENT_PRO_UPGRADE_ON_INSTALL, {
trialDays: trialDays,
Expand All @@ -273,11 +301,14 @@ define(function (require, exports, module) {

/**
* Start the pro trial activation process
* Waits 2 minutes, then triggers the upgrade event
*/
console.log(`Checking pro trial activation in ${TRIAL_POLL_MS / 1000} seconds...`);

const trialActivatePoller = setInterval(()=> {
if(Phoenix.isTestWindow) {
clearInterval(trialActivatePoller);
return;
}
if(_isAnyDialogsVisible()){
// maybe the user hasn't dismissed the new project dialog
return;
Expand Down
Loading