From 4761523e8513b4c67a0db3010a8d89bdb0a81ef9 Mon Sep 17 00:00:00 2001 From: saileshwar-skyflow Date: Wed, 11 Sep 2024 16:51:56 +0530 Subject: [PATCH] SK-1658: Fixed linting while throwing error codes --- src/client/index.ts | 3 +-- src/core/external/collect/collect-container.ts | 9 +++------ src/core/external/collect/collect-element.ts | 12 ++++-------- .../collect/compose-collect-container.ts | 12 ++++-------- src/core/external/common/iframe.ts | 6 ++---- src/core/internal/iframe-form/index.ts | 5 +---- src/libs/element-options.ts | 18 ++++++------------ src/skyflow.ts | 6 ++---- src/utils/helpers/index.ts | 9 +++------ 9 files changed, 26 insertions(+), 54 deletions(-) diff --git a/src/client/index.ts b/src/client/index.ts index b85f1a10..3f51f25c 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -119,8 +119,7 @@ class Client { }; httpRequest.onerror = () => { - reject(new SkyflowError(SKYFLOW_ERROR_CODE.NETWORK_ERROR, - [], true)); + reject(new SkyflowError(SKYFLOW_ERROR_CODE.NETWORK_ERROR, [], true)); }; }); } diff --git a/src/core/external/collect/collect-container.ts b/src/core/external/collect/collect-container.ts index 2d9ef812..85234fd6 100644 --- a/src/core/external/collect/collect-container.ts +++ b/src/core/external/collect/collect-container.ts @@ -286,14 +286,12 @@ class CollectContainer extends Container { const collectElements = Object.values(this.#elements); collectElements.forEach((element) => { if (!element.isMounted()) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.ELEMENTS_NOT_MOUNTED, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.ELEMENTS_NOT_MOUNTED, [], true); } element.isValidElement(); }); if (Object.prototype.hasOwnProperty.call(options, 'tokens') && !validateBooleanOptions(options.tokens)) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TOKENS_IN_COLLECT, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TOKENS_IN_COLLECT, [], true); } if (options?.additionalFields) { validateAdditionalFieldsInCollect(options.additionalFields); @@ -337,8 +335,7 @@ class CollectContainer extends Container { const fileElements = Object.values(this.#elements); fileElements.forEach((element) => { if (!element.isMounted()) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.ELEMENTS_NOT_MOUNTED, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.ELEMENTS_NOT_MOUNTED, [], true); } element.isValidElement(); }); diff --git a/src/core/external/collect/collect-element.ts b/src/core/external/collect/collect-element.ts index 9638dd1f..cd629c9b 100644 --- a/src/core/external/collect/collect-element.ts +++ b/src/core/external/collect/collect-element.ts @@ -436,16 +436,13 @@ class CollectElement extends SkyflowElement { // todo: off methods on(eventName: string, handler) { if (!Object.values(ELEMENT_EVENTS_TO_CLIENT).includes(eventName)) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_EVENT_LISTENER, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_EVENT_LISTENER, [], true); } if (!handler) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.MISSING_HANDLER_IN_EVENT_LISTENER, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.MISSING_HANDLER_IN_EVENT_LISTENER, [], true); } if (typeof handler !== 'function') { - throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_HANDLER_IN_EVENT_LISTENER, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_HANDLER_IN_EVENT_LISTENER, [], true); } this.#eventEmitter.on(eventName, (data) => { if (data.value === undefined) { @@ -516,8 +513,7 @@ class CollectElement extends SkyflowElement { // break; default: - throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_EVENT_TYPE, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_EVENT_TYPE, [], true); } this.#states[index].isEmpty = data.value.isEmpty; this.#states[index].isValid = data.value.isValid; diff --git a/src/core/external/collect/compose-collect-container.ts b/src/core/external/collect/compose-collect-container.ts index 3861e852..a107300d 100644 --- a/src/core/external/collect/compose-collect-container.ts +++ b/src/core/external/collect/compose-collect-container.ts @@ -307,8 +307,7 @@ class ComposableContainer extends Container { const { layout } = this.#options; if (sum(layout) !== this.#elementsList.length) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.MISMATCH_ELEMENT_COUNT_LAYOUT_SUM, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.MISMATCH_ELEMENT_COUNT_LAYOUT_SUM, [], true); } let count = 0; layout.forEach((rowCount, index) => { @@ -359,15 +358,13 @@ class ComposableContainer extends Container { try { validateInitConfig(this.#metaData.clientJSON.config); if (!this.#isMounted) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.COMPOSABLE_CONTAINER_NOT_MOUNTED, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.COMPOSABLE_CONTAINER_NOT_MOUNTED, [], true); } const containerElements = getElements(this.#tempElements); containerElements.forEach((element:any) => { if (!element?.isMounted) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.ELEMENTS_NOT_MOUNTED, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.ELEMENTS_NOT_MOUNTED, [], true); } }); @@ -377,8 +374,7 @@ class ComposableContainer extends Container { }); if (options && options.tokens && typeof options.tokens !== 'boolean') { - throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TOKENS_IN_COLLECT, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TOKENS_IN_COLLECT, [], true); } if (options?.additionalFields) { validateAdditionalFieldsInCollect(options.additionalFields); diff --git a/src/core/external/common/iframe.ts b/src/core/external/common/iframe.ts index 88665a05..5e2bd7ae 100644 --- a/src/core/external/common/iframe.ts +++ b/src/core/external/common/iframe.ts @@ -35,14 +35,12 @@ export default class IFrame { if (typeof domElement === 'string') { this.container = document.querySelector(domElement) || undefined; if (!this.container) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ELEMENT_SELECTOR, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ELEMENT_SELECTOR, [], true); } } else if (domElement instanceof HTMLElement) { this.container = domElement; } else { - throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ELEMENT_SELECTOR, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ELEMENT_SELECTOR, [], true); } } catch (e: any) { // eslint-disable-next-line no-console diff --git a/src/core/internal/iframe-form/index.ts b/src/core/internal/iframe-form/index.ts index 6ab81731..e3896273 100644 --- a/src/core/internal/iframe-form/index.ts +++ b/src/core/internal/iframe-form/index.ts @@ -991,10 +991,7 @@ export class IFrameForm { }; tokenize = (options) => { - if (!this.client) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.CLIENT_CONNECTION, - [], true); - } + if (!this.client) throw new SkyflowError(SKYFLOW_ERROR_CODE.CLIENT_CONNECTION, [], true); const insertResponseObject: any = {}; const updateResponseObject: any = {}; const formElements = Object.keys(this.iFrameFormElements); diff --git a/src/libs/element-options.ts b/src/libs/element-options.ts index 251fd3d6..d87d8dc8 100644 --- a/src/libs/element-options.ts +++ b/src/libs/element-options.ts @@ -35,14 +35,12 @@ export function validateElementOptions( newOptions: any = {}, ) { if (elementType !== 'group' && !Object.prototype.hasOwnProperty.call(ELEMENTS, elementType)) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ELEMENT_TYPE, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ELEMENT_TYPE, [], true); } if (Object.prototype.hasOwnProperty.call(oldOptions, 'validations')) { if (!Array.isArray(oldOptions.validations)) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_VALIDATIONS_TYPE, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_VALIDATIONS_TYPE, [], true); } else { oldOptions.validations.forEach((validationRule: IValidationRule, index) => { if (!Object.prototype.hasOwnProperty.call(validationRule, 'type')) { @@ -309,15 +307,13 @@ export const formatOptions = (elementType, options, logLevel) => { if (!(typeof formattedOptions.cardMetadata === 'object') || (Object.prototype.toString.call(formattedOptions.cardMetadata) !== '[object Object]') ) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_OPTION_CARD_METADATA, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_OPTION_CARD_METADATA, [], true); } if (Object.prototype.hasOwnProperty.call(formattedOptions.cardMetadata, 'scheme')) { if (!(typeof formattedOptions.cardMetadata.scheme === 'object') || (Object.prototype.toString.call(formattedOptions.cardMetadata.scheme) !== '[object Array]')) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_OPTION_CARD_SCHEME, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_OPTION_CARD_SCHEME, [], true); } } } @@ -388,12 +384,10 @@ export const formatOptions = (elementType, options, logLevel) => { [], true); } if (options.allowedFileType.length <= 0) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.EMPTY_ALLOWED_OPTIONS_ARRAY, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.EMPTY_ALLOWED_OPTIONS_ARRAY, [], true); } if (!options.allowedFileType.every((item) => typeof item === 'string')) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ALLOWED_FILETYPE_ARRAY, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ALLOWED_FILETYPE_ARRAY, [], true); } } if (Object.prototype.hasOwnProperty.call(options, 'allowedFileType')) { diff --git a/src/skyflow.ts b/src/skyflow.ts index 70063b17..2288cdd3 100644 --- a/src/skyflow.ts +++ b/src/skyflow.ts @@ -204,11 +204,9 @@ class Skyflow { default: if (!type) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.EMPTY_CONTAINER_TYPE, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.EMPTY_CONTAINER_TYPE, [], true); } - throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_CONTAINER_TYPE, - [type], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_CONTAINER_TYPE, [type], true); } } diff --git a/src/utils/helpers/index.ts b/src/utils/helpers/index.ts index 1c2fd1e0..19531fbe 100644 --- a/src/utils/helpers/index.ts +++ b/src/utils/helpers/index.ts @@ -173,13 +173,11 @@ const DANGEROUS_FILE_TYPE = ['application/zip', 'application/vnd.debian.binary-p // Check file type and file size in KB export const fileValidation = (value, required: Boolean = false, fileElement) => { if (required && (value === undefined || value === '')) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.NO_FILE_SELECTED, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.NO_FILE_SELECTED, [], true); } if (DANGEROUS_FILE_TYPE.includes(value.type)) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_FILE_TYPE, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_FILE_TYPE, [], true); } if (Object.prototype.hasOwnProperty.call(fileElement, 'allowedFileType') && (value !== undefined && value !== '')) { @@ -200,8 +198,7 @@ export const fileValidation = (value, required: Boolean = false, fileElement) => } if (value.size > 32000000) { - throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_FILE_SIZE, - [], true); + throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_FILE_SIZE, [], true); } return true;