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

Lint fixes for power pages web extension #245

Merged
merged 2 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 5 additions & 6 deletions src/web/client/common/authenticationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { pathParamToSchema, PROVIDER_ID, SCOPE_OPTION } from './constants';
import { ERRORS } from './errorHandler';
import { dataSourcePropertiesMap } from './localStore';

/* eslint-disable @typescript-eslint/no-explicit-any */
export function getHeader(accessToken: string) {
return {
authorization: "Bearer " + accessToken,
Expand All @@ -30,22 +29,22 @@ export async function dataverseAuthentication(dataverseOrgURL: string): Promise<
return accessToken;
}

export function getRequestURLForSingleEntity(dataverseOrgUrl: string, entity: string, entityId: string, urlquery: string, entitiesSchemaMap: any, method: string): string {
export function getRequestURLForSingleEntity(dataverseOrgUrl: string, entity: string, entityId: string, urlquery: string, entitiesSchemaMap: Map<string, Map<string, string>>, method: string): string {
const parameterizedUrl = dataSourcePropertiesMap.get(urlquery) as string;
let requestUrl = parameterizedUrl.replace('{dataverseOrgUrl}', dataverseOrgUrl).replace('{entity}', entity).replace('{entityId}', entityId).replace('{api}', dataSourcePropertiesMap.get('api')).replace('{data}', dataSourcePropertiesMap.get('data')).replace('{version}', dataSourcePropertiesMap.get('version'));
let requestUrl = parameterizedUrl.replace('{dataverseOrgUrl}', dataverseOrgUrl).replace('{entity}', entity).replace('{entityId}', entityId).replace('{api}', dataSourcePropertiesMap.get('api') as string).replace('{data}', dataSourcePropertiesMap.get('data') as string).replace('{version}', dataSourcePropertiesMap.get('version') as string);
switch (method) {
case 'GET':
requestUrl = requestUrl + entitiesSchemaMap.get(pathParamToSchema.get(entity)).get('_fetchQueryParameters');
requestUrl = requestUrl + entitiesSchemaMap.get(pathParamToSchema.get(entity) as string)?.get('_fetchQueryParameters');
break;
default:
break;
}
return requestUrl;
}

export function getCustomRequestURL(dataverseOrgUrl: string, entity: string, urlQuery: string, entitiesSchemaMap: any): string {
export function getCustomRequestURL(dataverseOrgUrl: string, entity: string, urlQuery: string, entitiesSchemaMap: Map<string, Map<string, string>>): string {
const parameterizedUrl = dataSourcePropertiesMap.get(urlQuery) as string;
const fetchQueryParameters = entitiesSchemaMap.get(pathParamToSchema.get(entity) as string)?.get("_fetchQueryParameters");
const requestUrl = parameterizedUrl.replace('{dataverseOrgUrl}', dataverseOrgUrl).replace('{entity}', entity).replace('{api}', dataSourcePropertiesMap.get('api')).replace('{data}', dataSourcePropertiesMap.get('data')).replace('{version}', dataSourcePropertiesMap.get('version'));
const requestUrl = parameterizedUrl.replace('{dataverseOrgUrl}', dataverseOrgUrl).replace('{entity}', entity).replace('{api}', dataSourcePropertiesMap.get('api') as string)?.replace('{data}', dataSourcePropertiesMap.get('data') as string).replace('{version}', dataSourcePropertiesMap.get('version') as string);
vedg marked this conversation as resolved.
Show resolved Hide resolved
return requestUrl + fetchQueryParameters;
}
52 changes: 24 additions & 28 deletions src/web/client/common/localStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */

import { getCustomRequestURL, getHeader } from "./authenticationProvider";
import { MULTI_ENTITY_URL_KEY, ORG_URL, pathParamToSchema, PORTAL_LANGUAGES, PORTAL_LANGUAGE_DEFAULT, WEBSITES, WEBSITE_LANGUAGES, WEBSITE_NAME } from "./constants";
import { MULTI_ENTITY_URL_KEY, ORG_URL, pathParamToSchema, PORTAL_LANGUAGES, PORTAL_LANGUAGE_DEFAULT, WEBSITES, WEBSITE_NAME } from "./constants";
import { getDataSourcePropertiesMap, getEntitiesSchemaMap } from "./portalSchemaReader";
import { ERRORS, showErrorDialog } from "./errorHandler";
import { getDataFromDataVerse } from "./remoteFetchProvider";
import { PortalsFS } from "./fileSystemProvider";
import { createFileSystem } from "./createFileSystem";

let dataSourcePropertiesMap = new Map();
let entitiesSchemaMap = new Map();
let languageIdCodeMap = new Map();
let websiteLanguageIdToPortalLanguageMap = new Map();
let websiteIdToLanguage = new Map();
const portalDetailsMap = new Map();
let dataSourcePropertiesMap = new Map<string, string>();
let entitiesSchemaMap = new Map<string, Map<string, string>>();
let languageIdCodeMap = new Map<string, string>();
let websiteLanguageIdToPortalLanguageMap = new Map<string, string>();
let websiteIdToLanguage = new Map<string, string>();

export async function languageIdToCode(accessToken: string, dataverseOrgURL: string, entitiesSchemaMap: any): Promise<Map<string, any>> {
export async function languageIdToCode(accessToken: string, dataverseOrgURL: string, entitiesSchemaMap: Map<string, Map<string, string>>): Promise<Map<string, string>> {

try {
const requestUrl = getCustomRequestURL(dataverseOrgURL, PORTAL_LANGUAGES, MULTI_ENTITY_URL_KEY, entitiesSchemaMap);
Expand All @@ -33,16 +29,16 @@ export async function languageIdToCode(accessToken: string, dataverseOrgURL: str
}
const result = await response.json();
if (result) {
if (result.value.length > 0) {
if (result.value?.length > 0) {
for (let counter = 0; counter < result.value.length; counter++) {
const adx_portallanguageid = result.value[counter].adx_portallanguageid ? result.value[counter].adx_portallanguageid : PORTAL_LANGUAGE_DEFAULT;
const adx_languagecode = result.value[counter].adx_languagecode;
languageIdCodeMap.set(adx_portallanguageid, adx_languagecode);
}
}
}
} catch (e: any) {
if (e.message.includes('Unauthorized')) {
} catch (error) {
if (typeof error === "string" && error.includes("Unauthorized")){
showErrorDialog(ERRORS.AUTHORIZATION_FAILED, ERRORS.SERVER_ERROR_PERMISSION_DENIED);
}
else {
Expand All @@ -52,7 +48,7 @@ export async function languageIdToCode(accessToken: string, dataverseOrgURL: str
return languageIdCodeMap;
}

export async function websiteLanguageIdToPortalLanguage(accessToken: string, dataverseOrgURL: string, entitiesSchemaMap: any): Promise<Map<string, any>> {
export async function websiteLanguageIdToPortalLanguage(accessToken: string, dataverseOrgURL: string, entitiesSchemaMap: Map<string, Map<string, string>>): Promise<Map<string, string>> {
try {
const requestUrl = getCustomRequestURL(dataverseOrgURL, PORTAL_LANGUAGES, MULTI_ENTITY_URL_KEY, entitiesSchemaMap);
const response = await fetch(requestUrl, {
Expand All @@ -63,16 +59,16 @@ export async function websiteLanguageIdToPortalLanguage(accessToken: string, dat
}
const result = await response.json();
if (result) {
if (result.value.length > 0) {
if (result.value?.length > 0) {
for (let counter = 0; counter < result.value.length; counter++) {
const adx_portalLanguageId_value = result.value[counter].adx_portallanguageid_value ? result.value[counter].adx_portallanguageid_value : PORTAL_LANGUAGE_DEFAULT;
const adx_websiteLanguageId = result.value[counter].adx_websitelanguageid;
websiteLanguageIdToPortalLanguageMap.set(adx_websiteLanguageId, adx_portalLanguageId_value);
}
}
}
} catch (e: any) {
if (e.message.includes('Unauthorized')) {
} catch (error) {
if (typeof error === "string" && error.includes("Unauthorized")){
showErrorDialog(ERRORS.AUTHORIZATION_FAILED, ERRORS.SERVER_ERROR_PERMISSION_DENIED);
}
else {
Expand All @@ -82,7 +78,7 @@ export async function websiteLanguageIdToPortalLanguage(accessToken: string, dat
return websiteLanguageIdToPortalLanguageMap;
}

export async function websiteIdToLanguageMap(accessToken: string, dataverseOrgUrl: string, entitiesSchemaMap: any): Promise<Map<string, string>> {
export async function websiteIdToLanguageMap(accessToken: string, dataverseOrgUrl: string, entitiesSchemaMap: Map<string, Map<string, string>>): Promise<Map<string, string>> {
try {
const requestUrl = getCustomRequestURL(dataverseOrgUrl, WEBSITES, MULTI_ENTITY_URL_KEY, entitiesSchemaMap);
const response = await fetch(requestUrl, {
Expand All @@ -93,7 +89,7 @@ export async function websiteIdToLanguageMap(accessToken: string, dataverseOrgUr
}
const result = await response.json();
if (result) {
if (result.value.length > 0) {
if (result.value?.length > 0) {
for (let counter = 0; counter < result.value.length; counter++) {
const adx_websiteId = result.value[counter].adx_websiteid ? result.value[counter].adx_websiteid : null;
const adx_website_language = result.value[counter].adx_website_language;
Expand All @@ -102,8 +98,8 @@ export async function websiteIdToLanguageMap(accessToken: string, dataverseOrgUr
}
}

} catch (e: any) {
if (e.message.includes('Unauthorized')) {
} catch (error) {
if (typeof error === "string" && error.includes("Unauthorized")){
showErrorDialog(ERRORS.AUTHORIZATION_FAILED, ERRORS.SERVER_ERROR_PERMISSION_DENIED);
}
else {
Expand All @@ -114,21 +110,21 @@ export async function websiteIdToLanguageMap(accessToken: string, dataverseOrgUr
}


export async function setContext(accessToken: string, pseudoEntityName: string, entityId: string, queryParamsMap: any, portalsFS: PortalsFS) {
export async function setContext(accessToken: string, pseudoEntityName: string, entityId: string, queryParamsMap: Map<string, string>, portalsFS: PortalsFS) {
const entity = pathParamToSchema.get(pseudoEntityName) as string;
const dataverseOrgUrl = queryParamsMap.get(ORG_URL);
const dataverseOrgUrl = queryParamsMap.get(ORG_URL) as string;
dataSourcePropertiesMap = getDataSourcePropertiesMap();
entitiesSchemaMap = getEntitiesSchemaMap();
websiteIdToLanguage = await websiteIdToLanguageMap(accessToken, dataverseOrgUrl, entitiesSchemaMap);
websiteLanguageIdToPortalLanguageMap = await websiteLanguageIdToPortalLanguage(accessToken, dataverseOrgUrl, entitiesSchemaMap);
languageIdCodeMap = await languageIdToCode(accessToken, queryParamsMap.get(ORG_URL), entitiesSchemaMap);
languageIdCodeMap = await languageIdToCode(accessToken, dataverseOrgUrl, entitiesSchemaMap);
createEntityFiles(portalsFS, accessToken, entity, entityId, queryParamsMap, entitiesSchemaMap, languageIdCodeMap);
}

function createEntityFiles(portalsFS: PortalsFS, accessToken: string, entity: string, entityId: string, queryParamsMap: any, entitiesSchemaMap: any, languageIdCodeMap: any) {
const portalFolderName = queryParamsMap.get(WEBSITE_NAME);
function createEntityFiles(portalsFS: PortalsFS, accessToken: string, entity: string, entityId: string, queryParamsMap: Map<string, string>, entitiesSchemaMap: Map<string, Map<string, string>>, languageIdCodeMap: Map<string, string>) {
const portalFolderName = queryParamsMap.get(WEBSITE_NAME) as string;
createFileSystem(portalsFS, portalFolderName);
getDataFromDataVerse(accessToken, entity, entityId, queryParamsMap, entitiesSchemaMap, languageIdCodeMap, portalsFS);
}

export { dataSourcePropertiesMap, entitiesSchemaMap, websiteIdToLanguage, websiteLanguageIdToPortalLanguageMap, languageIdCodeMap, portalDetailsMap };
export { dataSourcePropertiesMap, entitiesSchemaMap, websiteIdToLanguage, websiteLanguageIdToPortalLanguageMap, languageIdCodeMap };
4 changes: 0 additions & 4 deletions src/web/client/common/portalSchemaInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

/* eslint-disable @typescript-eslint/no-explicit-any */

export interface Entities {
entity?: (Entity)[] | null;
}
export interface Entity {
fields: any;
relationships?: string | any;
_name: string;
_displayname: string;
_etc?: string | null;
Expand Down
6 changes: 2 additions & 4 deletions src/web/client/common/portalSchemaReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

/* eslint-disable @typescript-eslint/no-explicit-any */

import { portal_schema_data } from "./portalSchema";

export function getEntitiesSchemaMap(): Map<string, any> {
const entitiesMap = new Map<string, any>();
export function getEntitiesSchemaMap(): Map<string, Map<string, string>> {
const entitiesMap = new Map<string, Map<string, string>>();
for (let i = 0; i < portal_schema_data.entities.entity.length; i++) {
const entity = portal_schema_data.entities.entity[i];
const entitiesDetailsMap = new Map<string, string>();
Expand Down
33 changes: 18 additions & 15 deletions src/web/client/common/remoteFetchProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ import { PortalsFS } from './fileSystemProvider';
import { SaveEntityDetails } from './portalSchemaInterface';
import { registerSaveProvider } from './remoteSaveProvider';
import { INFO } from './resources/Info';

/* eslint-disable @typescript-eslint/no-explicit-any */
let saveDataMap = new Map<string, SaveEntityDetails>();

export async function fetchData(accessToken: string, entity: string, entityId: string, queryParamsMap: any, entitiesSchemaMap: any, languageIdCodeMap: any, portalFs: PortalsFS) {
export async function fetchData(accessToken: string, entity: string, entityId: string, queryParamsMap: Map<string, string>, entitiesSchemaMap: Map<string, Map<string, string>>, languageIdCodeMap: Map<string, string>, portalFs: PortalsFS) {
try {
const dataverseOrgUrl = queryParamsMap.get(ORG_URL);
const dataverseOrgUrl = queryParamsMap.get(ORG_URL) as string;
let url;
if (entityId) {
url = SINGLE_ENTITY_URL_KEY;
Expand All @@ -44,32 +42,37 @@ export async function fetchData(accessToken: string, entity: string, entityId: s
if (typeof error === "string" && error.includes('Unauthorized')) {
vscode.window.showErrorMessage(ERRORS.AUTHORIZATION_FAILED);
} else {
showErrorDialog(ERRORS.INVALID_ARGUMENT, ERRORS.INVALID_ARGUMENT_DESC);
showErrorDialog(ERRORS.INVALID_ARGUMENT, ERRORS.INVALID_ARGUMENT);
}
}
}

function createContentFiles(result: string, entity: string, queryParamsMap: any, entitiesSchemaMap: any, languageIdCodeMap: any, portalsFS: PortalsFS, dataverseOrgUrl: string, accessToken: string, entityId: string) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this commented line?

function createContentFiles(result: any, entity: string, queryParamsMap: Map<string, string>, entitiesSchemaMap: Map<string, Map<string, string>>, languageIdCodeMap: Map<string, string>, portalsFS: PortalsFS, dataverseOrgUrl: string, accessToken: string, entityId: string) {
let languageCode = DEFAULT_LANGUAGE_CODE;
if (languageIdCodeMap?.size) {
languageCode = languageIdCodeMap.get(queryParamsMap.get(WEBSITE_ID)) ? languageIdCodeMap.get(queryParamsMap.get(WEBSITE_ID)) : DEFAULT_LANGUAGE_CODE;
if (languageIdCodeMap?.size && languageIdCodeMap.get(queryParamsMap.get(WEBSITE_ID) as string)) {
languageCode = languageIdCodeMap.get(queryParamsMap.get(WEBSITE_ID) as string) as string;
}
const attributes = entitiesSchemaMap.get(pathParamToSchema.get(entity)).get('_attributes');
const exportType = entitiesSchemaMap.get(pathParamToSchema.get(entity)).get('_exporttype');
const portalFolderName = queryParamsMap.get(WEBSITE_NAME);
const entityEntry = entitiesSchemaMap.get(pathParamToSchema.get(entity) as string);
const attributes = entityEntry?.get('_attributes');
const exportType = entityEntry?.get('_exporttype');
const portalFolderName = queryParamsMap.get(WEBSITE_NAME) as string;
const subUri = entityFolder.get(entity) as string;
if (exportType && exportType === 'SubFolders') {
portalsFS.createDirectory(vscode.Uri.parse(`${PORTALS_URI_SCHEME}:/${portalFolderName}/${subUri}/`, true));
}
if (attributes) {
const fileName = result[entitiesSchemaMap.get(pathParamToSchema.get(entity)).get(FILE_NAME_FIELD)] ? result[entitiesSchemaMap.get(pathParamToSchema.get(entity)).get(FILE_NAME_FIELD)].toLowerCase() : EMPTY_FILE_NAME;
let fileName = EMPTY_FILE_NAME;
const fetchedFileName = entitiesSchemaMap.get(pathParamToSchema.get(entity) as string)?.get(FILE_NAME_FIELD);
if (fetchedFileName)
fileName = result[fetchedFileName].toLowerCase();
if (fileName === EMPTY_FILE_NAME) {
showErrorDialog(ERRORS.FILE_NAME_NOT_SET, ERRORS.SERVICE_ERROR);
}
portalsFS.createDirectory(vscode.Uri.parse(`${PORTALS_URI_SCHEME}:/${portalFolderName}/${subUri}/${fileName}/`, true));
portalsFS.createDirectory(vscode.Uri.parse(`${PORTALS_URI_SCHEME}:/${portalFolderName}/${subUri}/${fileName}/${entityFolder.get(CONTENT_PAGES)}/`, true));
const attributeArray = attributes.split(',');
let counter = 0
let counter = 0;
for (counter; counter < attributeArray.length; counter++) {
const value = result[attributeArray[counter]] ? result[attributeArray[counter]] : NO_CONTENT;
saveDataMap = createVirtualFile(portalsFS, fileName, languageCode, value, columnExtension.get(attributeArray[counter]) as string, subUri, entityId, attributeArray[counter] as string, entity, portalFolderName);
Expand All @@ -79,15 +82,15 @@ function createContentFiles(result: string, entity: string, queryParamsMap: any,
registerSaveProvider(accessToken, portalsFS, dataverseOrgUrl, saveDataMap);
}

function createVirtualFile(portalsFS: PortalsFS, fileName: string, languageCode: string, data: any, portalFileExtension: string, subUri: string, entityId: string, saveDataAtribute: string, entity: string, portalFolderName: string) {
function createVirtualFile(portalsFS: PortalsFS, fileName: string, languageCode: string, data: string | undefined, portalFileExtension: string, subUri: string, entityId: string, saveDataAtribute: string, entity: string, portalFolderName: string) {
const saveEntityDetails = new SaveEntityDetails(entityId, entity, saveDataAtribute);
const fileUri = `${PORTALS_URI_SCHEME}:/${portalFolderName}/${subUri}/${fileName}/${entityFolder.get(CONTENT_PAGES)}/${fileName}.${languageCode}.${portalFileExtension}`;
portalsFS.writeFile(vscode.Uri.parse(fileUri), new TextEncoder().encode(data), { create: true, overwrite: true });
saveDataMap.set(vscode.Uri.parse(fileUri).fsPath, saveEntityDetails);
return saveDataMap;
}

export async function getDataFromDataVerse(accessToken: string, entity: string, entityId: string, queryParamMap: any, entitiesSchemaMap: any, languageIdCodeMap: any, portalFs: PortalsFS) {
export async function getDataFromDataVerse(accessToken: string, entity: string, entityId: string, queryParamMap: Map<string, string>, entitiesSchemaMap: Map<string, Map<string, string>>, languageIdCodeMap: Map<string, string>, portalFs: PortalsFS) {
vscode.window.showInformationMessage(INFO.FETCH_FILE);
await fetchData(accessToken, entity, entityId, queryParamMap, entitiesSchemaMap, languageIdCodeMap, portalFs);
}
3 changes: 1 addition & 2 deletions src/web/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { checkMandatoryParameters, removeEncodingFromParameters, ERRORS, showErr
import { INFO } from "./common/resources/Info";
let _telemetry: TelemetryReporter;

/* eslint-disable @typescript-eslint/no-explicit-any */
export function activate(context: vscode.ExtensionContext): void {
// setup telemetry
_telemetry = new TelemetryReporter(context.extension.id, context.extension.packageJSON.version, AI_KEY);
Expand All @@ -27,7 +26,7 @@ export function activate(context: vscode.ExtensionContext): void {
context.subscriptions.push(
vscode.commands.registerCommand(
"microsoft-powerapps-portals.webExtension.init",
async (args: any) => {
async (args) => {
_telemetry.sendTelemetryEvent("StartCommand", { 'commandId': 'microsoft-powerapps-portals.webExtension.init' });
vscode.window.showInformationMessage(INFO.WORKSPACE_INITIAL_LOAD);
const { appName, entity, entityId, searchParams } = args;
Expand Down