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

Feature complete-cdn compatibility #325

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions sample-upload
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// ! DO NOT REMOVE
// This file is used to get CDN base path
1 change: 0 additions & 1 deletion src/__tests__/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
1 change: 0 additions & 1 deletion src/__tests__/theme.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/themeContext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/helper/serve.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
5 changes: 0 additions & 5 deletions src/lib/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: ',
Expand Down
5 changes: 0 additions & 5 deletions src/lib/CommandError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
67 changes: 36 additions & 31 deletions src/lib/Theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(
Expand All @@ -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`,
Expand Down Expand Up @@ -1884,7 +1889,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(
Expand Down Expand Up @@ -1921,9 +1926,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(
Expand Down Expand Up @@ -2528,7 +2533,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`,
Expand Down
9 changes: 0 additions & 9 deletions src/lib/api/helper/interceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 0 additions & 12 deletions src/lib/api/services/theme.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
5 changes: 3 additions & 2 deletions src/lib/api/services/upload.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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';
}
Expand Down
4 changes: 0 additions & 4 deletions src/lib/api/services/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
},
};
Loading