Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ID:FPCO-25735;HOURS:2;DONE:90; Add timer in login command #277

Open
wants to merge 82 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
54a7027
ID:FPCO-25735;HOURS:2;DONE:90; Add timer in login command
ManishPrajapati-GoFynd Dec 15, 2023
bc7f1a3
ID:FPCO-25735;HOURS:2;DONE:90; Remove testing fields
ManishPrajapati-GoFynd Dec 15, 2023
bbbf32c
ID:FPCO-25735;HOURS:2;DONE:90; Set timer to 2 min | Add debug logs | …
ManishPrajapati-GoFynd Dec 18, 2023
cc85e3a
ID:FPCO-25735;HOURS:2;DONE:90; Set timer to 5 min
ManishPrajapati-GoFynd Dec 19, 2023
ec774e9
ID:FPCO-25735;HOURS:2;DONE:90; Add debug logs and set 2 minute timeout
ManishPrajapati-GoFynd Jan 10, 2024
e3324a0
ID:FPCO-25735;HOURS:2;DONE:90; Throw error on timeout
ManishPrajapati-GoFynd Mar 5, 2024
67f597b
ID:FPCO-25735;HOURS:2;DONE:90; Merge branch 'master'
ManishPrajapati-GoFynd Mar 5, 2024
f14c0f8
ID:FPCO-25735;HOURS:2;DONE:90; Merge branch 'master'
ManishPrajapati-GoFynd Mar 5, 2024
7d2d106
ID:FPCO-25735;HOURS:2;DONE:90; remove temp theme
ManishPrajapati-GoFynd Mar 5, 2024
340e23b
ID:FPCO-25735;HOURS:2;DONE:90; add temp theme folder in git ignore
ManishPrajapati-GoFynd Mar 5, 2024
df5cb01
ID:FPCO-25735;HOURS:2;DONE:90; Add partners domain support in env set…
ManishPrajapati-GoFynd Mar 6, 2024
d64348a
ID:FPCO-25735;HOURS:2;DONE:90; Fix support for sandbox
ManishPrajapati-GoFynd Mar 6, 2024
e04db35
5.0.5
ManishPrajapati-GoFynd Mar 6, 2024
f45c130
Updated message
Mar 6, 2024
cfb3dcd
Merge branch 'FPCO-25735-timeout-in-fdk-login' of github.com:gofynd/f…
Mar 6, 2024
aa751d4
ID:FPCO-25735;HOURS:2;DONE:90; Fix error handling of timeout | Fix er…
ManishPrajapati-GoFynd Mar 7, 2024
06a96ff
Merge branch 'FPCO-25735-timeout-in-fdk-login' of github.com:gofynd/f…
ManishPrajapati-GoFynd Mar 7, 2024
7db2418
ID:FPCO-25735;HOURS:2;DONE:90; Update error message and sandbox handling
ManishPrajapati-GoFynd Mar 7, 2024
511cdc8
Error message updated
Mar 11, 2024
05aac93
ID:FPCO-25735;DONE:100;HOURS:4; Remove auth command
ManishPrajapati-GoFynd Mar 19, 2024
4835377
Merge branch 'master' of github.com:gofynd/fdk-cli into FPCO-25735-ti…
ManishPrajapati-GoFynd Mar 19, 2024
ce10b91
ID:FPCO-25735;DONE:100;HOURS:4; Fix test cases
ManishPrajapati-GoFynd Mar 20, 2024
ab20077
ID:FPCO-25735;DONE:100;HOURS:4; Update readme
ManishPrajapati-GoFynd Mar 20, 2024
8524e9f
ID:FPCO-25735;DONE:100;HOURS:4; update warning message
ManishPrajapati-GoFynd Mar 21, 2024
005da69
ID:FPCO-25735;DONE:100;HOURS:4; Fix option description
ManishPrajapati-GoFynd Mar 22, 2024
3112e76
ID:FPCO-25735;DONE:100;HOURS:4; Fix warning message
ManishPrajapati-GoFynd Apr 1, 2024
6780775
Merge branch 'master' of github.com:gofynd/fdk-cli into FPCO-25735-ti…
ManishPrajapati-GoFynd Apr 8, 2024
d7e2749
Improved extension preview-url command user experience
bhargavprajapatiFynd Jul 30, 2024
a1cf765
Updated ngrok tunnel related logs
bhargavprajapatiFynd Jul 30, 2024
dd5e71d
improved extension preview-url command
bhargavprajapatiFynd Jul 31, 2024
2da2449
minor improvements
bhargavprajapatiFynd Jul 31, 2024
23707a3
Add ext list and update fdk.ext.config read logic
jinalviranii Aug 2, 2024
50a2a82
Merge branch 'master' of github.com:gofynd/fdk-cli into improve-exten…
Aug 2, 2024
0484d62
branches added
Aug 2, 2024
7a1ca0a
ngork tunnel support removed
Aug 4, 2024
ce18778
handle submodule in extension template
ManishPrajapati-GoFynd Aug 5, 2024
c07649b
handle git command error
ManishPrajapati-GoFynd Aug 5, 2024
1ccda4d
add debug logs
ManishPrajapati-GoFynd Aug 5, 2024
01d2c34
preview URL changes
Aug 6, 2024
6ccdb78
create action in temporary folder and then move it to extension folde…
ManishPrajapati-GoFynd Aug 6, 2024
d9a25af
move files using cross OS compatible commands
ManishPrajapati-GoFynd Aug 6, 2024
6df2879
move function to utils with doc string comments | create branch variable
ManishPrajapati-GoFynd Aug 6, 2024
06fc4f3
fix install java frontend dependencies
ManishPrajapati-GoFynd Aug 6, 2024
00e6bc0
added --auto-update and --tunnel-url flag support and improved error …
bhargavprajapatiFynd Aug 6, 2024
5eb00ff
removed dead code
bhargavprajapatiFynd Aug 6, 2024
a98d78d
Update frontend port and add .env in java extension too
ManishPrajapati-GoFynd Aug 6, 2024
512e187
Update test case
ManishPrajapati-GoFynd Aug 6, 2024
2414053
Update frontend port to 8081 as env path is updated in frontend
ManishPrajapati-GoFynd Aug 6, 2024
b5eeb1d
Update base url in both env and application.yml if exist
ManishPrajapati-GoFynd Aug 6, 2024
257e463
add temp folder constant and stringify error
ManishPrajapati-GoFynd Aug 6, 2024
0f94147
Merge branch 'handle-submodule-in-extension-template--master' into im…
bhargavprajapatiFynd Aug 7, 2024
5144dc2
Added extension config file support
bhargavprajapatiFynd Aug 7, 2024
28039c7
changed extension context file name
bhargavprajapatiFynd Aug 7, 2024
41d9367
Fixed extension preview url test cases
bhargavprajapatiFynd Aug 7, 2024
4eadd8f
Remove updating env in extension init and setup command
bhargavprajapatiFynd Aug 7, 2024
16157c8
Updated testcases for .env file change
bhargavprajapatiFynd Aug 7, 2024
44b3452
Adding extension.context file on ext init and setup
bhargavprajapatiFynd Aug 7, 2024
7803a35
fix: added proper api secret in context file
bhargavprajapatiFynd Aug 7, 2024
2f6441e
Added new ext tunnel command
bhargavprajapatiFynd Aug 7, 2024
07c94b7
Readme.md updated
Aug 7, 2024
323927f
6.0.0
Aug 7, 2024
00f4f08
6.0.0-beta.0
Aug 7, 2024
501be90
6.0.0-beta.1
Aug 7, 2024
248ad18
added missing dependency
Aug 7, 2024
f6d8c1d
6.0.0-beta.2
Aug 7, 2024
0bfb4d2
Made node+react as first option in ext init and setup command
bhargavprajapatiFynd Aug 8, 2024
b7930a2
add template support in init extension command
ManishPrajapati-GoFynd Aug 8, 2024
56f6d94
- Added --reset flag
bhargavprajapatiFynd Aug 8, 2024
08a1f1f
Ask developer to select or create extension on init command
ManishPrajapati-GoFynd Aug 8, 2024
8bfbe40
Enhancement on init command
ManishPrajapati-GoFynd Aug 8, 2024
f26898c
Added sticky preview url
bhargavprajapatiFynd Aug 8, 2024
d9741ef
Merge branch 'improve-extension-preview-url-command' of github.com:go…
ManishPrajapati-GoFynd Aug 8, 2024
7db84b3
Fix test cases
ManishPrajapati-GoFynd Aug 9, 2024
e951ac5
Fix mock argument
ManishPrajapati-GoFynd Aug 9, 2024
440f911
Merge branch 'master' of github.com:gofynd/fdk-cli into FPCO-25735-ti…
ManishPrajapati-GoFynd Aug 9, 2024
7a2f354
Merge branch 'improve-extension-preview-url-command' of github.com:go…
ManishPrajapati-GoFynd Aug 9, 2024
2defeb4
Updating messages and removing extra lines
ManishPrajapati-GoFynd Aug 9, 2024
74fa3ce
Update test case
ManishPrajapati-GoFynd Aug 9, 2024
966aaf1
revert timer changes
bhargavprajapatiFynd Aug 20, 2024
ac7eec1
Merge branch 'master' into FPCO-25735-timeout-in-fdk-login
bhargavprajapatiFynd Aug 20, 2024
5a97ca2
Merge branch 'master' into FPCO-25735-timeout-in-fdk-login
bhargavprajapatiFynd Aug 20, 2024
f8185fb
only run auth file
bhargavprajapatiFynd Aug 20, 2024
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,6 @@ csv/
*venv/*

# Sentry Auth Token
.sentryclirc
.sentryclirc

/temp-theme
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,14 @@ fdk env set [options]
```sh
fdk env set -u api.fynd.com
```
```sh
fdk env set -p partners.fynd.com
```
#### **Command Options**
| Option | Description | Required |
| ------------- |-------------|----------|
| --url, -u | Platform API domain | Yes |
| --partners, -p | Partners domain | Yes |
| --help | Show help | No |
| --verbose, -v | enable debug mode | No |

Expand Down Expand Up @@ -363,6 +367,9 @@ Set the active environment before running extension commands
```sh
fdk env set -u api.fynd.com
```
```sh
fdk env set -p partners.fynd.com
```


<div id="extension-init"></div>
Expand Down
7 changes: 5 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gofynd/fdk-cli",
"version": "5.0.4",
"version": "5.0.5",
"main": "index.js",
"license": "MIT",
"bin": {
Expand Down
14 changes: 14 additions & 0 deletions src/__tests__/env.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,18 @@ describe('Env Commands', () => {
await new Promise((r) => setTimeout(r, 2000));
expect(currentEnv).toMatch('api.fyndx1.de');
});

it('should console current set env by partners domain', async () => {
await program.parseAsync([
'ts-node',
'./src/fdk.ts',
'env',
'set',
'-p',
'partners.fyndx1.de',
]);
const currentEnv = configStore.get(CONFIG_KEYS.CURRENT_ENV_VALUE);
await new Promise((r) => setTimeout(r, 2000));
expect(currentEnv).toMatch('api.fyndx1.de');
});
});
2 changes: 2 additions & 0 deletions src/commands/environment/environment-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export default function environmentCommandBuilder() {
env.command('set')
// todo: remove -n option in future version
.option('-n, --name [env-name]', 'Environment name')
// todo: remove -u option in future version
.option('-u, --url [api-domain]', 'API domain')
.option('-p, --partners [partners-domain]', 'Partners domain')
.description('Set new environment')
.asyncAction(Env.setNewEnvs);

Expand Down
6 changes: 3 additions & 3 deletions src/fdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,14 @@ export async function init(programName: string) {
// set default environment
const current_env = configStore.get(CONFIG_KEYS.CURRENT_ENV_VALUE);

if (!current_env || !current_env.includes('api.'))
if (!current_env || (!current_env.includes('api.') && !current_env.includes('api-')))
configStore.set(CONFIG_KEYS.CURRENT_ENV_VALUE, 'api.fynd.com');

// todo: remove this warning in future version of fdk cli, when everybody get used to set env by url.
if (current_env && !current_env.includes('api.')) {
if (current_env && !current_env.includes('api.') && !current_env.includes('api-')) {
console.warn(
chalk.yellow(
`Warning: Reseting active environment to api.fynd.com. Please use \`fdk env set -u <env-api-url>\` to change active environment. Ref: ${
`Warning: Reseting active environment to api.fynd.com. Please use \`fdk env set -p <partners-domain>\` to change active environment. Ref: ${
ManishPrajapati-GoFynd marked this conversation as resolved.
Show resolved Hide resolved
getPlatformUrls().partners
}/help/docs/partners/themes/vuejs/command-reference#environment-commands-1`,
),
Expand Down
74 changes: 59 additions & 15 deletions src/lib/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import CommandError from './CommandError';
import Logger from './Logger';
import inquirer from 'inquirer';
import ConfigStore, { CONFIG_KEYS } from './Config';
import { ALLOWD_ENV } from '../helper/constants';
import open from 'open';
import express from 'express';
var cors = require('cors');
const port = 7071;
import chalk from 'chalk';
import ThemeService from './api/services/theme.service';
import { getLocalBaseUrl } from '../helper/serve.utils';
import Debug from './Debug';

const SERVER_TIMER = 1000 * 60 * 2; // 2 min

async function checkTokenExpired(auth_token) {
const { expiry_time } = auth_token;
Expand All @@ -29,15 +31,15 @@ export const getApp = async () => {

app.post('/token', async (req, res) => {
try {
if (Auth.isOrganizationChange)
if (Auth.wantToChangeOrganization)
ConfigStore.delete(CONFIG_KEYS.AUTH_TOKEN);
const expiryTimestamp =
Math.floor(Date.now() / 1000) + req.body.auth_token.expires_in;
req.body.auth_token.expiry_time = expiryTimestamp;
ConfigStore.set(CONFIG_KEYS.AUTH_TOKEN, req.body.auth_token);
ConfigStore.set(CONFIG_KEYS.ORGANIZATION, req.body.organization);
Auth.stopSever();
if (Auth.isOrganizationChange)
if (Auth.wantToChangeOrganization)
Logger.info('Organization changed successfully');
else Logger.info('User logged in successfully');
res.status(200).json({ message: 'success' });
Expand All @@ -49,16 +51,53 @@ export const getApp = async () => {
return { app };
};

function startTimer(){
Debug("Server timer starts")
Auth.timer_id = setTimeout(() => {
Auth.stopSever(() => {
console.log(chalk.red('Server timeout: Please run fdk login command again.'));
process.exit(1);
})
}, SERVER_TIMER)
}

function resetTimer(){
if (Auth.timer_id) {
Debug("Server timer stoped")
clearTimeout(Auth.timer_id)
Auth.timer_id = null;
}
}
export const startServer = async () => {
if (Auth.server) return Auth.server;

const { app } = await getApp();
const serverIn = require('http').createServer(app);
Auth.server = serverIn.listen(port, (err) => {
if (err) console.log(err);

// handle errors thrown while start listening
serverIn.on('error', (error) => {
if (error.code === 'EADDRINUSE') {
console.error(chalk.red(`Port ${port} is already in use.`));
} else {
console.error(chalk.red('An unexpected error occurred:'), error);
}
process.exit(1);
});

return Auth.server;
Auth.server = serverIn.listen(port);

// resolve promise only if server starts listening
// we will open partner panel only if server is listening
return new Promise(resolve => {
serverIn.on('listening', () => {
Debug(`Server started listening on ${port}`);
resolve(Auth.server);
});
}).then(server => {
// once server start listening, start server timer
startTimer();
return server
})
};

async function checkVersionCompatibility() {
Expand All @@ -67,7 +106,8 @@ async function checkVersionCompatibility() {

export default class Auth {
static server = null;
static isOrganizationChange = false;
static timer_id;
static wantToChangeOrganization = false;
constructor() {}
public static async login() {
await checkVersionCompatibility();
Expand All @@ -78,7 +118,6 @@ export default class Auth {
),
);
const isLoggedIn = await Auth.isAlreadyLoggedIn();
await startServer();
if (isLoggedIn) {
const questions = [
{
Expand All @@ -91,21 +130,22 @@ export default class Auth {
];
await inquirer.prompt(questions).then(async (answers) => {
if (answers.confirmChangeOrg === 'No') {
Auth.isOrganizationChange = false;
await Auth.stopSever();
Auth.wantToChangeOrganization = false;
return;
} else {
Auth.isOrganizationChange = true;
Auth.wantToChangeOrganization = true;
await startServer();
}
});
}
} else
await startServer();
const env = ConfigStore.get(CONFIG_KEYS.CURRENT_ENV_VALUE);
try {
let domain = null;
let partnerDomain = env.replace('api', 'partners');
domain = `https://${partnerDomain}`;
try {
if (Auth.isOrganizationChange || !isLoggedIn) {
if (Auth.wantToChangeOrganization || !isLoggedIn) {
await open(
`${domain}/organizations/?fdk-cli=true&callback=${encodeURIComponent(
`${getLocalBaseUrl()}:${port}`,
Expand Down Expand Up @@ -169,7 +209,11 @@ export default class Auth {
else return false;
} else return false;
};
static stopSever = async () => {
Auth.server.close(() => {});
static stopSever = async (cb = null) => {
resetTimer();
Auth.server?.close?.(() => {
Debug("Server closed");
cb?.();
});
};
}
55 changes: 41 additions & 14 deletions src/lib/Env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { isValidDomain } from '../helper/utils';
import Debug from './Debug';
import { getPlatformUrls } from './api/services/url';


export default class Env {
constructor() {}

Expand All @@ -31,39 +30,67 @@ export default class Env {
try {
// todo: remove name warning in future version
if (options.name) {
console.warn(chalk.yellow(`Warning: The -n/--name option is deprecated. Please use -u/--url option instead. Ref: ${getPlatformUrls().partners}/help/docs/partners/themes/vuejs/command-reference#environment-commands-1`));
throw new Error('Please use -u/--url option.');
console.warn(
chalk.yellow(
`Warning: The -n/--name option is deprecated. Please use -u/--url or -p/--partners option instead. Ref: ${
getPlatformUrls().partners
}/help/docs/partners/themes/vuejs/command-reference#environment-commands-1`,
),
);
throw new Error(
'Please use -u/--url or -p/--partners option.',
);
}
if (!options.url) {
throw new Error('Please provide -u/--url option.');

if (!options.url && !options.partners) {
throw new Error(
'Please provide -u/--url or -p/--partners option.',
);
}

if (!isValidDomain(options.url)) {
throw new Error('Please provide valid URL.');
let finalUrl = options.url || options.partners;

if (finalUrl.includes('https://')) {
finalUrl = finalUrl.replace('https://', '');
}

// todo: in future, when url support will be removed, update isValidDomain to get only partners domain, as of now -u and -p can accept both url(api & partners).
if (!isValidDomain(finalUrl)) {
throw new Error(
`Please provide valid domain, Example:${
options.partners ? ' partners.fynd.com' : ''
}${options.url ? ' api.fynd.com' : ''}`,
);
}

if (finalUrl.includes('partners')) {
finalUrl = finalUrl.replace('partners', 'api');
}

try {
const url = urljoin(
'https://',
options.url,
finalUrl,
'/service/application/content/_healthz',
);
const response = await axios.get(url);

if (response?.status === 200) {
Env.setEnv(options.url);
Env.setEnv(finalUrl);
Logger.info(
`CLI will start using: ${chalk.bold(options.url)}`,
`CLI will start using: ${chalk.bold(finalUrl)}`,
);
} else {
throw new Error(
'Provided url is not valid platform URL.',
'Provided domain is not valid partners panel domain.',
);
}
} catch (err) {
Debug(err)
throw new Error('Provided url is not valid platform URL.');
Debug(err);
throw new Error(
'Provided domain is not valid partners panel domain.',
);
}

} catch (e) {
throw new CommandError(e.message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const COMMON_LOG_MESSAGES = {
'Use fdk login --help to know more',
)}`,
contextMismatch: `Active Environment and Active Context Environment doesn't match.\n${chalk.yellow(
'Use `fdk theme context-list` to switch context OR `fdk env set -u <env-api-url>` to change active environment.',
'Use `fdk theme context-list` to switch context OR `fdk env set -p <partners-domain>` to change active environment.',
)}`,
invalidThemeType: `${chalk.yellow(`Theme Type can be react or vue2 only`)}`,
ThemeTypeNotAvailableInContext: `${chalk.yellow(
Expand Down
Loading