From 7de26857ce86c5c36d406286e624646a54998af3 Mon Sep 17 00:00:00 2001 From: Ashok Redkar Date: Fri, 5 Jul 2024 15:24:48 +0530 Subject: [PATCH 1/4] use CDN key from grindor completed API --- src/helper/serve.utils.ts | 2 +- src/lib/Theme.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/helper/serve.utils.ts b/src/helper/serve.utils.ts index 94c80541..728e79c0 100644 --- a/src/helper/serve.utils.ts +++ b/src/helper/serve.utils.ts @@ -218,7 +218,7 @@ export async function startServer({ domain, host, isSSR, port }) { 'fdk-cli-dev-files', User.current_user._id, ) - ).start.cdn.url; + ).complete.cdn.url; } else { jetfireUrl.searchParams.set('__csr', 'true'); } diff --git a/src/lib/Theme.ts b/src/lib/Theme.ts index 9434f171..37d69042 100644 --- a/src/lib/Theme.ts +++ b/src/lib/Theme.ts @@ -1884,7 +1884,7 @@ export default class Theme { path.join(process.cwd(), Theme.BUILD_FOLDER, commonJS), 'application-theme-assets', ); - const commonJsUrl = commonJsUrlRes.start.cdn.url; + const commonJsUrl = commonJsUrlRes.complete.cdn.url; Logger.info('Uploading umdJS'); const umdMinAssets = glob.sync( @@ -1921,9 +1921,9 @@ export default class Theme { }); const cssUrls = await Promise.all(cssPromisesArr); return [ - cssUrls.map((res) => res.start.cdn.url), + cssUrls.map((res) => res.complete.cdn.url), commonJsUrl, - umdJsUrls.map((res) => res.start.cdn.url), + umdJsUrls.map((res) => res.complete.cdn.url), ]; } catch (err) { throw new CommandError( @@ -2528,7 +2528,7 @@ export default class Theme { zipFilePath, 'application-theme-src', ); - return res.start.cdn.url; + return res.complete.cdn.url; } catch (err) { throw new CommandError( err.message || `Failed to upload src folder`, From 45f08dc17d54990b8efab6f35481d87fe3fdfc89 Mon Sep 17 00:00:00 2001 From: Ashok Redkar Date: Fri, 5 Jul 2024 17:51:04 +0530 Subject: [PATCH 2/4] remove version compatibility api usage --- src/__tests__/auth.spec.ts | 1 - src/__tests__/theme.spec.ts | 1 - src/__tests__/themeContext.spec.ts | 1 - src/lib/Auth.ts | 5 ----- src/lib/api/services/theme.service.ts | 12 ------------ src/lib/api/services/url.ts | 4 ---- 6 files changed, 24 deletions(-) diff --git a/src/__tests__/auth.spec.ts b/src/__tests__/auth.spec.ts index 735113b2..91a8b664 100644 --- a/src/__tests__/auth.spec.ts +++ b/src/__tests__/auth.spec.ts @@ -52,7 +52,6 @@ describe('Auth Commands', () => { setEnv(); program = await init('fdk'); const mock = new MockAdapter(axios); - mock.onGet(`${URLS.IS_VERSION_COMPATIBLE()}`).reply(200); await login(); }); diff --git a/src/__tests__/theme.spec.ts b/src/__tests__/theme.spec.ts index ecc0483a..c09c0732 100644 --- a/src/__tests__/theme.spec.ts +++ b/src/__tests__/theme.spec.ts @@ -137,7 +137,6 @@ describe('Theme Commands', () => { const mockInstance = new MockAdapter( uninterceptedApiClient.axiosInstance, ); - mock.onGet(`${URLS.IS_VERSION_COMPATIBLE()}`).reply(200); mock.onGet( `${URLS.GET_APPLICATION_DETAILS( appConfig.company_id, diff --git a/src/__tests__/themeContext.spec.ts b/src/__tests__/themeContext.spec.ts index 0202d59c..76f6e939 100644 --- a/src/__tests__/themeContext.spec.ts +++ b/src/__tests__/themeContext.spec.ts @@ -61,7 +61,6 @@ describe('Theme Context Commands', () => { setEnv(); program = await init('fdk'); const mock = new MockAdapter(axios); - mock.onGet(`${URLS.IS_VERSION_COMPATIBLE()}`).reply(200); mock.onGet( `${URLS.GET_APPLICATION_DETAILS( appConfig.company_id, diff --git a/src/lib/Auth.ts b/src/lib/Auth.ts index 1ebd23b0..e1a17e1c 100644 --- a/src/lib/Auth.ts +++ b/src/lib/Auth.ts @@ -61,16 +61,11 @@ export const startServer = async () => { return Auth.server; }; -async function checkVersionCompatibility() { - const response = await ThemeService.checkCompatibleVersion(); -} - export default class Auth { static server = null; static isOrganizationChange = false; constructor() {} public static async login() { - await checkVersionCompatibility(); Logger.info( chalk.green( 'Current env: ', diff --git a/src/lib/api/services/theme.service.ts b/src/lib/api/services/theme.service.ts index 74fd27ed..560a2551 100644 --- a/src/lib/api/services/theme.service.ts +++ b/src/lib/api/services/theme.service.ts @@ -227,18 +227,6 @@ export default { throw error; } }, - checkCompatibleVersion: async () => { - try { - let axiosOptions = Object.assign({}, getCommonHeaderOptions()); - let response = await ApiClient.get( - URLS.IS_VERSION_COMPATIBLE(), - axiosOptions, - ); - return response.data; - } catch (error) { - throw error; - } - }, getDefaultTheme: async (data) => { try { const axiosOption = Object.assign({}, getCommonHeaderOptions()); diff --git a/src/lib/api/services/url.ts b/src/lib/api/services/url.ts index be4de5cf..ebbe7ebd 100644 --- a/src/lib/api/services/url.ts +++ b/src/lib/api/services/url.ts @@ -178,8 +178,4 @@ export const URLS = { `/organization/${organization_id}/accounts/access-request?page_size=${page_size}&page_no=${page_no}&request_status=accepted`, ); }, - - IS_VERSION_COMPATIBLE: () => { - return urlJoin(BLITZKRIEG_PANEL_URL(), '/_compatibility'); - }, }; From 832237adf160e564c98fa173763c8ddcb37ee731 Mon Sep 17 00:00:00 2001 From: Ashok Redkar Date: Mon, 8 Jul 2024 10:21:38 +0530 Subject: [PATCH 3/4] remove version compatibility messages --- src/lib/CommandError.ts | 5 ----- src/lib/api/helper/interceptors.ts | 9 --------- 2 files changed, 14 deletions(-) diff --git a/src/lib/CommandError.ts b/src/lib/CommandError.ts index 53288228..dcd59a59 100644 --- a/src/lib/CommandError.ts +++ b/src/lib/CommandError.ts @@ -53,11 +53,6 @@ export const ErrorCodes = { `No themes are created, Please create/add a theme under the sales channel. For more details, refer to the documentation link: ${domain}/help/docs/partners/themes/vuejs/overview`, code: 'FDK-00011', }, - DOWNGRADE_CLI_VERSION: { - message: - 'Seems like current Fynd Platform version is not compatible with installed CLI version.\n\nIn order to continue with current FP version, Please use previous version of CLI `npm install -g @gofynd/fdk-cli@3.0.4` command.', - code: 'FDK-00012', - }, // generic ECONN_RESET: { diff --git a/src/lib/api/helper/interceptors.ts b/src/lib/api/helper/interceptors.ts index 95d86cd9..e536977b 100644 --- a/src/lib/api/helper/interceptors.ts +++ b/src/lib/api/helper/interceptors.ts @@ -129,15 +129,6 @@ export function responseErrorInterceptor() { ) { ConfigStore.delete(CONFIG_KEYS.AUTH_TOKEN); throw new CommandError(COMMON_LOG_MESSAGES.RequireAuth); - } else if ( - error.response && - error.response.status === 404 && - error.response.config.url.includes('/_compatibility') - ) { - throw new CommandError( - ErrorCodes.DOWNGRADE_CLI_VERSION.message, - ErrorCodes.DOWNGRADE_CLI_VERSION.code, - ); } else if (error.response) { Debug(`Error Response : ${JSON.stringify(error.response.data)}`); throw new CommandError( From fe7ab5ac1f1ff1baf87a13326ec76c2478ce34d0 Mon Sep 17 00:00:00 2001 From: Karan Raina Date: Wed, 10 Jul 2024 14:50:51 +0530 Subject: [PATCH 4/4] Fix grindor cdn URL --- sample-upload | 2 + src/lib/Theme.ts | 59 ++++++++++++++------------ src/lib/api/services/upload.service.ts | 5 ++- 3 files changed, 37 insertions(+), 29 deletions(-) create mode 100644 sample-upload diff --git a/sample-upload b/sample-upload new file mode 100644 index 00000000..e2997fa2 --- /dev/null +++ b/sample-upload @@ -0,0 +1,2 @@ +// ! DO NOT REMOVE +// This file is used to get CDN base path \ No newline at end of file diff --git a/src/lib/Theme.ts b/src/lib/Theme.ts index 37d69042..3a98581e 100644 --- a/src/lib/Theme.ts +++ b/src/lib/Theme.ts @@ -114,7 +114,6 @@ export default class Theme { public static async getThemeBundle(stats: MultiStats) { const fileList = stats.stats[0].toJson().assets.map(({ name }) => name); const outputFileName= fileList.find(file => file.startsWith('themeBundle') && file.endsWith('.js')); - const buildPath = path.join(process.cwd(), Theme.BUILD_FOLDER); const outputFilePath = path.resolve(buildPath, outputFileName); @@ -1680,20 +1679,22 @@ export default class Theme { }; private static getImageCdnBaseUrl = async () => { - let imageCdnUrl = ''; try { - let startData = { - file_name: 'test.jpg', - content_type: 'image/jpeg', - size: '1', - }; - let startAssetData = ( - await UploadService.startUpload( - startData, - 'application-theme-images', - ) - ).data; - return (imageCdnUrl = path.dirname(startAssetData.cdn.url)); + const dummyFile = path.join( + __dirname, + '..', + '..', + 'sample-upload' + ); + + const response = await UploadService.uploadFile( + dummyFile, + 'application-theme-images', + null, + 'image/jpg' + ); + + return path.dirname(response.complete.cdn.url); } catch (err) { Logger.error(err); throw new CommandError( @@ -1704,20 +1705,24 @@ export default class Theme { }; private static getAssetCdnBaseUrl = async () => { - let assetCdnUrl = ''; try { - const startData = { - file_name: 'test.ttf', - content_type: 'font/ttf', - size: '10', - }; - const startAssetData = ( - await UploadService.startUpload( - startData, - 'application-theme-assets', - ) - ).data; - return (assetCdnUrl = path.dirname(startAssetData.cdn.url)); + console.log({__dirname}); + const dummyFile = path.join( + __dirname, + '..', + '..', + 'sample-upload' + ); + + const response = await UploadService.uploadFile( + dummyFile, + 'application-theme-assets', + null, + 'application/javascript' + ); + + return path.dirname(response.complete.cdn.url); + } catch (err) { throw new CommandError( `Failed in getting assets CDN base url`, diff --git a/src/lib/api/services/upload.service.ts b/src/lib/api/services/upload.service.ts index 9f0ba2d3..8aca0314 100644 --- a/src/lib/api/services/upload.service.ts +++ b/src/lib/api/services/upload.service.ts @@ -26,7 +26,7 @@ export default { throw error; } }, - uploadFile: async (filepath, namespace, file_name = null) => { + uploadFile: async (filepath, namespace, file_name = null, mimeType = null) => { let spinner = new Spinner(); let textMessage; try { @@ -35,7 +35,8 @@ export default { filepath, )} [${Math.round(stats.size / 1024)} KB]`; spinner.start(textMessage); - let contentType = mime.getType(path.extname(filepath)); + let contentType = mimeType || mime.getType(path.extname(filepath)); + if (contentType === 'image/jpg') { contentType = 'image/jpeg'; }