Skip to content
Open
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": "8.0.2",
"version": "8.0.3",
"main": "index.js",
"license": "MIT",
"bin": {
Expand Down
6 changes: 6 additions & 0 deletions src/lib/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export const getApp = async () => {
if (Auth.wantToChangeOrganization){
ConfigStore.delete(CONFIG_KEYS.AUTH_TOKEN);
clearExtensionContext();
const currentEnv = ConfigStore.get(
CONFIG_KEYS.CURRENT_ENV_VALUE,
);
ConfigStore.clear();
ConfigStore.set(CONFIG_KEYS.CURRENT_ENV_VALUE, currentEnv);
}
const expiryTimestamp =
Math.floor(Date.now() / 1000) + req.body.auth_token.expires_in;
Expand Down Expand Up @@ -248,6 +253,7 @@ export default class Auth {
ConfigStore.clear();
ConfigStore.set(CONFIG_KEYS.CURRENT_ENV_VALUE, currentEnv);
ConfigStore.set(CONFIG_KEYS.EXTRAS, extras);
ConfigStore.set('extensionSections', {});
}

public static getUserInfo() {
Expand Down
68 changes: 45 additions & 23 deletions src/lib/ExtensionSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default class ExtensionSection {

if (!extensions?.length) {
throw new Error(
'No installed extensions found!',
'No extension found in the organization!',
);
}
const selectedExtensionName = await promptUser({
Expand All @@ -151,13 +151,15 @@ export default class ExtensionSection {
)?._id;
} catch (error) {
Logger.error(
'Could not fetch the list of extensions',
error.message
);
extensionId = await promptUser({
type: 'text',
name: 'extensionId',
message: 'Please Enter your extensionId: ',
});
if(error.code !== 403 && error.code !== 401){
extensionId = await promptUser({
type: 'text',
name: 'extensionId',
message: 'Please Enter your extensionId: ',
});
}
} finally {
Configstore.set(
'extensionSections.extensionId',
Expand Down Expand Up @@ -202,8 +204,10 @@ export default class ExtensionSection {
themeId: undefined,
companyType: 'live',
};
let isError = false;
let errorObj: any;
try {
const configObj =
const configObj: any =
await Theme.selectCompanyAndStore();
const { data: appConfig } =
await configurationService.getApplicationDetails(
Expand All @@ -223,15 +227,23 @@ export default class ExtensionSection {
companyType: configObj['accountType'],
};
} catch (error) {
Logger.error('Could not fetch the applied!');
for (let lkey in themeDetails) {
themeDetails[lkey] = await promptUser({
type: 'text',
name: lkey,
message: `Please enter ${lkey}: `,
});
Logger.error('Could not fetch the applied themes!');
if(error.code !== 403 && error.code !== 401){
for (let lkey in themeDetails) {
themeDetails[lkey] = await promptUser({
type: 'text',
name: lkey,
message: `Please enter ${lkey}: `,
});
}
} else {
isError = true;
errorObj = error;
}
} finally {
if(isError){
throw errorObj;
}
Configstore.set(
'extensionSections.appliedTheme',
themeDetails,
Expand All @@ -242,7 +254,9 @@ export default class ExtensionSection {
default:
return null;
}
} catch (error) { }
} catch (error) {
throw new CommandError(error.message);
}
}

if (!Configstore.all.extensionSections) {
Expand Down Expand Up @@ -280,14 +294,17 @@ export default class ExtensionSection {
const userInput = {};
for (let val in missingKeys) {
const result = await getOption(missingKeys[val]);
if(!result){
break;
}
userInput[missingKeys[val]] = result;
}

const finalContext = Object.assign(mergedConfig, userInput);

return finalContext;
} catch (error) {
console.log(error);
throw new CommandError(error.message);
}
}

Expand Down Expand Up @@ -373,6 +390,10 @@ export default class ExtensionSection {
} else {
throw new CommandError('Unsupported framework!');
}
} else if(bindingInterface) {
throw new CommandError(
'Unsupported Interface! Only Web Themes are supported',
);
}


Expand Down Expand Up @@ -457,18 +478,19 @@ export default class ExtensionSection {
context,
sectionData.status,
);
Logger.info('Code published ...');

} else {
throw new CommandError(
'Unsupported Framework! Only react and vue2 are supported',
);
}
} else {
} else if(bindingInterface) {
throw new CommandError(
'Unsupported Interface! Only Web Themes are supported',
);
}

Logger.info('Code published ...');
}

static async buildExtensionCodeVue({ bundleName }) {
Expand Down Expand Up @@ -678,18 +700,18 @@ export default class ExtensionSection {
context,
sectionData.status,
);
Logger.info('Draft successful!');
} else {
throw new CommandError(
'Unsupported Framework! Only react and vue2 are supported',
);
}
} else {
} else if(bindingInterface) {
throw new CommandError(
'Unsupported Interface! Only Web Themes are supported',
);
}

Logger.info('Draft successful!');
}

static async watchExtensionCodeBuild(
Expand Down Expand Up @@ -831,7 +853,7 @@ export default class ExtensionSection {
data,
);
} catch (error) {
console.log(error);
throw new CommandError(error.message);
}
}
public static async previewExtension(options: any) {
Expand Down Expand Up @@ -996,7 +1018,7 @@ export default class ExtensionSection {
'Unsupported Framework! Only react and vue2 are supported',
);
}
} else {
} else if(bindingInterface) {
throw new CommandError(
'Unsupported Interface! Only Web Themes are supported',
);
Expand Down
10 changes: 4 additions & 6 deletions src/lib/Theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export default class Theme {
throw new CommandError(`Folder ${options.name} already exists`);
}

const configObj = await Theme.selectCompanyAndStore();
const configObj: any = await Theme.selectCompanyAndStore();
const { data: appConfig } =
await ConfigurationService.getApplicationDetails(configObj);

Expand Down Expand Up @@ -520,7 +520,7 @@ export default class Theme {
options,
targetDirectory,
appConfig,
themeType,
themeType
);
shouldDelete = true;
process.chdir(path.join('.', options.name));
Expand Down Expand Up @@ -632,7 +632,6 @@ export default class Theme {
});
Logger.info(b5.toString());
} catch (error) {
Logger.error(error);
if (shouldDelete) await Theme.cleanUp(targetDirectory);
throw new CommandError(error.message, error.code);
}
Expand All @@ -643,7 +642,7 @@ export default class Theme {
let targetDirectory = '';
let dir_name = 'default';
try {
let configObj = await Theme.selectCompanyAndStore();
let configObj: any = await Theme.selectCompanyAndStore();
configObj = await Theme.selectTheme(configObj);
const { data: appConfig } =
await ConfigurationService.getApplicationDetails(configObj);
Expand Down Expand Up @@ -962,7 +961,6 @@ export default class Theme {
});
Logger.debug(b5.toString());
} catch (error) {
Logger.error(error);
throw new CommandError(error.message, error.code);
} finally {
rimraf.sync(path.join(process.cwd(), Theme.SRC_FOLDER));
Expand Down Expand Up @@ -3312,7 +3310,7 @@ private static async getAvailableReactSectionsForSync(sections, sectionChunkingE
options,
targetDirectory,
appConfig,
themeType,
themeType
) => {
const defaultTheme = await ThemeService.getDefaultTheme({
company_id: appConfig.company_id,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ThemeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class ThemeContext {
throw new CommandError(
'Context with the same name already exists',
);
let configObj = await Theme.selectCompanyAndStore();
let configObj: any = await Theme.selectCompanyAndStore();
configObj = await Theme.selectTheme(configObj);
const { data: appConfig } =
await ConfigurationService.getApplicationDetails(configObj);
Expand Down
15 changes: 14 additions & 1 deletion src/lib/api/helper/interceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,21 @@ function getErrorMessage(error) {
export function responseErrorInterceptor() {
return (error) => {
// Request made and server responded
Debug(error);
Debug(`Error recieved from backend: ${JSON.stringify(error)}`);

let errorCode = "";
let errorMessage = error?.response?.data?.message;
if(error?.response?.data?.code){
errorCode = error.response.data.code.replace(/_([a-z])/g, (match, letter)=> letter.toUpperCase());
}
if (
error.response &&
(error.response.status === 401 || error.response.status === 403) &&
errorMessage && !errorMessage.includes('login')
) {
throw new CommandError(errorMessage, error.response.status);
}
else if (
error.response &&
(error.response.status === 401 || error.response.status === 403)
) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/services/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const URLS = {
);
},

GET_APPLIED_THEME: (company_id: number, application_id: string) => {
GET_APPLIED_THEME: (company_id: number, application_id: string) => {
return urlJoin(
THEME_URL(),
`organization/${getOrganizationId()}/company/${company_id}/application/${application_id}/applied-theme`,
Expand Down
Loading