diff --git a/package.json b/package.json index 2b7f8472..a5b44e28 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "scripts": { "start": "concurrently --kill-others-on-fail \"yarn workspace @adyen/adyen-web start\" \"yarn workspace @adyen/adyen-web-playground start\" --names \"lib,playground\"", "build": "yarn workspace @adyen/adyen-web build", + "format": "yarn workspace @adyen/adyen-web format", "lint": "yarn workspace @adyen/adyen-web lint", "test": "yarn workspace @adyen/adyen-web test", "test:watch": "yarn workspace @adyen/adyen-web test:watch", diff --git a/packages/lib/package.json b/packages/lib/package.json index 58b897e8..4ea71b59 100644 --- a/packages/lib/package.json +++ b/packages/lib/package.json @@ -44,9 +44,12 @@ "size-only": "node ./scripts/size", "type-check": "tsc --noEmit", "type-check-generate": "tsc --emitDeclarationOnly", + "format": "npm run lint:fix && npm run prettier:fix && npm run styles:fix", "lint": "eslint 'src/**/*.{js,ts,tsx}' --quiet", "lint-styles": "stylelint '**/*.scss'", + "styles:fix": "npm run lint-styles -- --fix", "lint:fix": "npm run lint -- --fix", + "prettier:fix": "prettier \"src/**/*.{js,ts,tsx}\" \"package.json\" --write --loglevel silent", "prepublishOnly": "npm run build", "prepare": "cd ../.. && husky install packages/lib/.husky" }, diff --git a/packages/lib/src/components/AfterPay/AfterPayB2B.tsx b/packages/lib/src/components/AfterPay/AfterPayB2B.tsx index ba04a2fc..bf236838 100644 --- a/packages/lib/src/components/AfterPay/AfterPayB2B.tsx +++ b/packages/lib/src/components/AfterPay/AfterPayB2B.tsx @@ -2,7 +2,7 @@ import { h } from 'preact'; import OpenInvoiceContainer from '../helpers/OpenInvoiceContainer'; import ConsentCheckboxLabel from './components/ConsentCheckboxLabel'; import { AFTERPAY_B2B_CONSENT_URL, ALLOWED_COUNTRIES } from './config'; -import {OpenInvoiceContainerProps} from "../helpers/OpenInvoiceContainer/OpenInvoiceContainer"; +import { OpenInvoiceContainerProps } from '../helpers/OpenInvoiceContainer/OpenInvoiceContainer'; export default class AfterPayB2B extends OpenInvoiceContainer { public static type = 'afterpay_b2b'; diff --git a/packages/lib/src/components/AmazonPay/utils.ts b/packages/lib/src/components/AmazonPay/utils.ts index a3c101f6..2d61f5d6 100644 --- a/packages/lib/src/components/AmazonPay/utils.ts +++ b/packages/lib/src/components/AmazonPay/utils.ts @@ -7,15 +7,7 @@ import { SUPPORTED_LOCALES_EU, SUPPORTED_LOCALES_US } from './config'; -import { - AmazonPayButtonProps, - AmazonPayButtonSettings, - ChargeAmount, - Currency, - PayloadJSON, - Region, - SupportedLocale -} from './types'; +import { AmazonPayButtonProps, AmazonPayButtonSettings, ChargeAmount, Currency, PayloadJSON, Region, SupportedLocale } from './types'; import { PaymentAmount } from '../../types'; import { getDecimalAmount } from '../../utils/amount-util'; @@ -62,7 +54,7 @@ export function getFallbackLocale(region: Region): SupportedLocale { */ export function getSupportedLocales(region: Region): SupportedLocale[] { const supportedLocales = region === 'US' ? SUPPORTED_LOCALES_US : SUPPORTED_LOCALES_EU; - return (supportedLocales as unknown) as SupportedLocale[]; + return supportedLocales as unknown as SupportedLocale[]; } /** @@ -108,16 +100,8 @@ export function getChargeAmount(amount: PaymentAmount): ChargeAmount { * @returns PayloadJSON */ export function getPayloadJSON(props): PayloadJSON { - const { - addressDetails, - cancelUrl, - checkoutMode, - deliverySpecifications, - returnUrl, - merchantMetadata, - chargePermissionType, - recurringMetadata, - } = props; + const { addressDetails, cancelUrl, checkoutMode, deliverySpecifications, returnUrl, merchantMetadata, chargePermissionType, recurringMetadata } = + props; const { storeId } = props.configuration; const isPayNow = checkoutMode === 'ProcessOrder'; diff --git a/packages/lib/src/components/Card/Card.test.ts b/packages/lib/src/components/Card/Card.test.ts index 5f1017f2..38dafec4 100644 --- a/packages/lib/src/components/Card/Card.test.ts +++ b/packages/lib/src/components/Card/Card.test.ts @@ -1,7 +1,7 @@ import { CardElement } from './Card'; describe('Card', () => { - describe('formatProps', function() { + describe('formatProps', function () { test('should not require a billingAddress if it is a stored card', () => { const card = new CardElement({ billingAddressRequired: true, storedPaymentMethodId: 'test' }); expect(card.props.billingAddressRequired).toBe(false); diff --git a/packages/lib/src/components/Giftcard/components/GiftcardFields.tsx b/packages/lib/src/components/Giftcard/components/GiftcardFields.tsx index 8f64e48c..8622d5ad 100644 --- a/packages/lib/src/components/Giftcard/components/GiftcardFields.tsx +++ b/packages/lib/src/components/Giftcard/components/GiftcardFields.tsx @@ -1,7 +1,7 @@ import { h } from 'preact'; import { GiftcardNumberField } from './GiftcardNumberField'; import { GiftcardPinField } from './GiftcardPinField'; -import {GiftcardFieldsProps} from "./types"; +import { GiftcardFieldsProps } from './types'; export const GiftCardFields = (props: GiftcardFieldsProps) => { const { setRootNode, pinRequired } = props; diff --git a/packages/lib/src/components/Giftcard/components/types.ts b/packages/lib/src/components/Giftcard/components/types.ts index 1126c615..65f40727 100644 --- a/packages/lib/src/components/Giftcard/components/types.ts +++ b/packages/lib/src/components/Giftcard/components/types.ts @@ -1,5 +1,5 @@ import Language from '../../../language/Language'; -import {SFPState} from '../../internal/SecuredFields/SFP/types'; +import { SFPState } from '../../internal/SecuredFields/SFP/types'; export type GiftcardFieldsProps = { setRootNode: (input: HTMLElement) => void; diff --git a/packages/lib/src/components/Klarna/components/KlarnaWidget/KlarnaWidget.tsx b/packages/lib/src/components/Klarna/components/KlarnaWidget/KlarnaWidget.tsx index 0cb57511..74fd370a 100644 --- a/packages/lib/src/components/Klarna/components/KlarnaWidget/KlarnaWidget.tsx +++ b/packages/lib/src/components/Klarna/components/KlarnaWidget/KlarnaWidget.tsx @@ -29,7 +29,7 @@ export function KlarnaWidget({ sdkData, paymentMethodType, payButton, ...props } container: klarnaWidgetRef.current, payment_method_category: sdkData.payment_method_category }, - function(res) { + function (res) { // If show_form: true is received together with an error, something fixable is wrong and the consumer // needs to take action before moving forward // If show_form: false, the payment method in the loaded widget will not be offered for this order @@ -48,7 +48,7 @@ export function KlarnaWidget({ sdkData, paymentMethodType, payButton, ...props } { payment_method_category: sdkData.payment_method_category }, - function(res: KlarnaWidgetAuthorizeResponse) { + function (res: KlarnaWidgetAuthorizeResponse) { if (res.approved === true && res.show_form === true) { // Klarna has approved the authorization of credit for this order. setStatus('success'); @@ -78,7 +78,7 @@ export function KlarnaWidget({ sdkData, paymentMethodType, payButton, ...props } // Add Klarna Payments Widget SDK useEffect(() => { - window.klarnaAsyncCallback = function() { + window.klarnaAsyncCallback = function () { initializeKlarnaWidget(); }; diff --git a/packages/lib/src/components/MealVoucherFR/MealVoucherFR.tsx b/packages/lib/src/components/MealVoucherFR/MealVoucherFR.tsx index 6c21d21f..3b37f309 100644 --- a/packages/lib/src/components/MealVoucherFR/MealVoucherFR.tsx +++ b/packages/lib/src/components/MealVoucherFR/MealVoucherFR.tsx @@ -31,7 +31,7 @@ export class MealVoucherFRElement extends GiftcardElement { encryptedCardNumber: this.state.data?.encryptedCardNumber, encryptedSecurityCode: this.state.data?.encryptedSecurityCode, encryptedExpiryMonth: this.state.data?.encryptedExpiryMonth, - encryptedExpiryYear: this.state.data?.encryptedExpiryYear, + encryptedExpiryYear: this.state.data?.encryptedExpiryYear } }; } diff --git a/packages/lib/src/components/MealVoucherFR/components/MealVoucherFields.tsx b/packages/lib/src/components/MealVoucherFR/components/MealVoucherFields.tsx index 7101b321..1a03a7e5 100644 --- a/packages/lib/src/components/MealVoucherFR/components/MealVoucherFields.tsx +++ b/packages/lib/src/components/MealVoucherFR/components/MealVoucherFields.tsx @@ -1,8 +1,8 @@ import { h } from 'preact'; -import {MealVoucherExpiryField} from "./MealVoucherExpiryField"; -import {GiftcardFieldsProps} from "../../Giftcard/components/types"; -import {GiftcardPinField} from "../../Giftcard/components/GiftcardPinField"; -import {GiftcardNumberField} from "../../Giftcard/components/GiftcardNumberField"; +import { MealVoucherExpiryField } from './MealVoucherExpiryField'; +import { GiftcardFieldsProps } from '../../Giftcard/components/types'; +import { GiftcardPinField } from '../../Giftcard/components/GiftcardPinField'; +import { GiftcardNumberField } from '../../Giftcard/components/GiftcardNumberField'; export const MealVoucherFields = (props: GiftcardFieldsProps) => { const { setRootNode } = props; diff --git a/packages/lib/src/components/OnlineBankingIN/index.ts b/packages/lib/src/components/OnlineBankingIN/index.ts index 8c10c1a6..9dd84758 100644 --- a/packages/lib/src/components/OnlineBankingIN/index.ts +++ b/packages/lib/src/components/OnlineBankingIN/index.ts @@ -12,8 +12,8 @@ class OnlineBankingINElement extends IssuerListContainer { } /** - * Formats the component data output - */ + * Formats the component data output + */ formatData() { return { ...super.formatData(), diff --git a/packages/lib/src/components/PayNow/PayNow.test.ts b/packages/lib/src/components/PayNow/PayNow.test.ts index 30d25f7d..433b2e0a 100644 --- a/packages/lib/src/components/PayNow/PayNow.test.ts +++ b/packages/lib/src/components/PayNow/PayNow.test.ts @@ -22,4 +22,3 @@ describe('PayNow', () => { }); }); }); - diff --git a/packages/lib/src/components/Sepa/Sepa.test.ts b/packages/lib/src/components/Sepa/Sepa.test.ts index 7b1ea009..2d5b3ea1 100644 --- a/packages/lib/src/components/Sepa/Sepa.test.ts +++ b/packages/lib/src/components/Sepa/Sepa.test.ts @@ -4,8 +4,8 @@ describe('Sepa', () => { const mockStateChange = sepa => { sepa.setState({ data: { - 'ownerName': 'A. Klaassen', - 'ibanNumber': 'NL13TEST0123456789' + ownerName: 'A. Klaassen', + ibanNumber: 'NL13TEST0123456789' }, isValid: true }); @@ -15,8 +15,8 @@ describe('Sepa', () => { const mockInvalidStateChange = sepa => { sepa.setState({ data: { - 'ownerName': 'A. Klaassen', - 'ibanNumber': 'NOTANIBAN' + ownerName: 'A. Klaassen', + ibanNumber: 'NOTANIBAN' }, isValid: false }); diff --git a/packages/lib/src/components/Twint/Twint.tsx b/packages/lib/src/components/Twint/Twint.tsx index b68b0f2c..a063c952 100644 --- a/packages/lib/src/components/Twint/Twint.tsx +++ b/packages/lib/src/components/Twint/Twint.tsx @@ -1,6 +1,6 @@ -import RedirectElement from "../Redirect"; -import PayButton, {payAmountLabel} from "../internal/PayButton"; -import {h} from "preact"; +import RedirectElement from '../Redirect'; +import PayButton, { payAmountLabel } from '../internal/PayButton'; +import { h } from 'preact'; /** * TwintElement @@ -18,15 +18,12 @@ class TwintElement extends RedirectElement { */ get displayName(): string { const { i18n, name, storedPaymentMethodId } = this.props; - return storedPaymentMethodId ? `${name} ${i18n.get('twint.saved')}` - : name || this.constructor['type']; + return storedPaymentMethodId ? `${name} ${i18n.get('twint.saved')}` : name || this.constructor['type']; } - public payButtonLabel() { - const {i18n, amount, storedPaymentMethodId, name} = this.props; - if (storedPaymentMethodId) - return payAmountLabel(i18n, amount); + const { i18n, amount, storedPaymentMethodId, name } = this.props; + if (storedPaymentMethodId) return payAmountLabel(i18n, amount); return `${i18n.get('continueTo')} ${name}`; } @@ -35,12 +32,7 @@ class TwintElement extends RedirectElement { * @param props - props */ public payButton = props => { - return ( - - ); + return ; }; } diff --git a/packages/lib/src/components/WalletIN/index.ts b/packages/lib/src/components/WalletIN/index.ts index 4fb6924f..cb7ad97b 100644 --- a/packages/lib/src/components/WalletIN/index.ts +++ b/packages/lib/src/components/WalletIN/index.ts @@ -12,8 +12,8 @@ class WalletINElement extends IssuerListContainer { } /** - * Formats the component data output - */ + * Formats the component data output + */ formatData() { return { ...super.formatData(), diff --git a/packages/lib/src/components/index.ts b/packages/lib/src/components/index.ts index ac6738ba..796558a3 100644 --- a/packages/lib/src/components/index.ts +++ b/packages/lib/src/components/index.ts @@ -56,8 +56,8 @@ import WalletINElement from './WalletIN'; import OnlineBankingCZElement from './OnlineBankingCZ'; import OnlineBankingSKElement from './OnlineBankingSK'; import PayByBank from './PayByBank'; -import PromptPay from "./PromptPay"; -import Duitnow from "./DuitNow"; +import PromptPay from './PromptPay'; +import Duitnow from './DuitNow'; /** * Maps each component with a Component element. diff --git a/packages/lib/src/components/internal/Alert/Alert.tsx b/packages/lib/src/components/internal/Alert/Alert.tsx index 09b60b59..76dcc071 100644 --- a/packages/lib/src/components/internal/Alert/Alert.tsx +++ b/packages/lib/src/components/internal/Alert/Alert.tsx @@ -9,7 +9,7 @@ interface AlertProps { children: ComponentChildren; classNames?: string[]; icon?: string; - type?: typeof ALERT_TYPES[number]; + type?: (typeof ALERT_TYPES)[number]; } export default function Alert({ children, classNames = [], type = 'error', icon }: AlertProps) { diff --git a/packages/lib/src/components/internal/FormFields/ConsentCheckbox/ConsentCheckbox.tsx b/packages/lib/src/components/internal/FormFields/ConsentCheckbox/ConsentCheckbox.tsx index 6fceb7d2..b54a898c 100644 --- a/packages/lib/src/components/internal/FormFields/ConsentCheckbox/ConsentCheckbox.tsx +++ b/packages/lib/src/components/internal/FormFields/ConsentCheckbox/ConsentCheckbox.tsx @@ -7,7 +7,7 @@ export default function ConsentCheckbox({ errorMessage, label, onChange, i18n, . ; + return ; } - \ No newline at end of file diff --git a/packages/lib/src/components/internal/IssuerList/IssuerList.test.tsx b/packages/lib/src/components/internal/IssuerList/IssuerList.test.tsx index 1b22bd9a..18362dd8 100644 --- a/packages/lib/src/components/internal/IssuerList/IssuerList.test.tsx +++ b/packages/lib/src/components/internal/IssuerList/IssuerList.test.tsx @@ -70,10 +70,7 @@ describe('IssuerList', () => { expect(onChangeCb.mock.calls[0][0]).toStrictEqual(callbackData); expect(onChangeCb.mock.calls[1][0]).toStrictEqual(callbackData); - wrapper - .find('.adyen-checkout__issuer-button-group button') - .at(1) - .simulate('click'); + wrapper.find('.adyen-checkout__issuer-button-group button').at(1).simulate('click'); callbackData = { data: { issuer: '3' }, valid: { issuer: true }, errors: { issuer: null }, isValid: true }; diff --git a/packages/lib/src/components/internal/SecuredFields/lib/CSF/AbstractCSF.ts b/packages/lib/src/components/internal/SecuredFields/lib/CSF/AbstractCSF.ts index 0f1cb51d..02463297 100644 --- a/packages/lib/src/components/internal/SecuredFields/lib/CSF/AbstractCSF.ts +++ b/packages/lib/src/components/internal/SecuredFields/lib/CSF/AbstractCSF.ts @@ -46,11 +46,11 @@ abstract class AbstractCSF { // -- protected constructor(setupObj: CSFSetupObject) { this.props = setupObj; - this.state = ({} as any) as CSFStateObject; + this.state = {} as any as CSFStateObject; // Initialise storage objects - this.config = ({} as any) as CSFConfigObject; // {} as ConfigObject fails in linting - this.callbacks = ({} as any) as CSFCallbacksConfig; + this.config = {} as any as CSFConfigObject; // {} as ConfigObject fails in linting + this.callbacks = {} as any as CSFCallbacksConfig; } } export default AbstractCSF; diff --git a/packages/lib/src/components/internal/SecuredFields/lib/CSF/extensions/configureCallbacks.ts b/packages/lib/src/components/internal/SecuredFields/lib/CSF/extensions/configureCallbacks.ts index c3c1c266..4e4455ff 100644 --- a/packages/lib/src/components/internal/SecuredFields/lib/CSF/extensions/configureCallbacks.ts +++ b/packages/lib/src/components/internal/SecuredFields/lib/CSF/extensions/configureCallbacks.ts @@ -2,7 +2,7 @@ import { CSFCallbacksConfig } from '../types'; const noop = () => {}; -export function configureCallbacks(callbacksObj: CSFCallbacksConfig = ({} as any) as CSFCallbacksConfig): void { +export function configureCallbacks(callbacksObj: CSFCallbacksConfig = {} as any as CSFCallbacksConfig): void { // -- this.callbacks.onLoad = callbacksObj.onLoad ? callbacksObj.onLoad : noop; diff --git a/packages/lib/src/components/internal/SecuredFields/lib/CSF/extensions/handleEncryption.ts b/packages/lib/src/components/internal/SecuredFields/lib/CSF/extensions/handleEncryption.ts index ed1ee407..3b9ff5f6 100644 --- a/packages/lib/src/components/internal/SecuredFields/lib/CSF/extensions/handleEncryption.ts +++ b/packages/lib/src/components/internal/SecuredFields/lib/CSF/extensions/handleEncryption.ts @@ -38,7 +38,7 @@ export function handleEncryption(pFeedbackObj: SFFeedbackObj): void { // REMOVE ANY ERRORS ON FIELD e.g. was a full number that failed the luhnCheck, then we corrected the number and now it passes processErrors( - ({ error: '', fieldType } as any) as SFFeedbackObj, + { error: '', fieldType } as any as SFFeedbackObj, this.state.securedFields[fieldType], this.state.type, this.props.rootNode, diff --git a/packages/lib/src/components/internal/SecuredFields/lib/CSF/utils/cardType.ts b/packages/lib/src/components/internal/SecuredFields/lib/CSF/utils/cardType.ts index f6f273f3..d333dba6 100644 --- a/packages/lib/src/components/internal/SecuredFields/lib/CSF/utils/cardType.ts +++ b/packages/lib/src/components/internal/SecuredFields/lib/CSF/utils/cardType.ts @@ -93,7 +93,8 @@ CardType.cards.push({ startingRules: [506699, 50670, 50671, 50672, 50673, 50674, 50675, 50676, 506770, 506771, 506772, 506773, 506774, 506775, 506776, 506777, 506778, 401178, 438935, 451416, 457631, 457632, 504175, 627780, 636297, 636368], // eslint-disable-line max-len permittedLengths: [16], // prettier-ignore - pattern: /^((((506699)|(506770)|(506771)|(506772)|(506773)|(506774)|(506775)|(506776)|(506777)|(506778)|(401178)|(438935)|(451416)|(457631)|(457632)|(504175)|(627780)|(636368)|(636297))[0-9]{0,10})|((50676)|(50675)|(50674)|(50673)|(50672)|(50671)|(50670))[0-9]{0,11})$/ // eslint-disable-line max-len + pattern: + /^((((506699)|(506770)|(506771)|(506772)|(506773)|(506774)|(506775)|(506776)|(506777)|(506778)|(401178)|(438935)|(451416)|(457631)|(457632)|(504175)|(627780)|(636368)|(636297))[0-9]{0,10})|((50676)|(50675)|(50674)|(50673)|(50672)|(50671)|(50670))[0-9]{0,11})$/ // eslint-disable-line max-len }); CardType.cards.push({ cardType: 'uatp', startingRules: [1], permittedLengths: [15], pattern: /^1[0-9]{0,14}$/, cvcPolicy: 'optional' }); @@ -179,7 +180,8 @@ CardType.cards.push({ startingRules: [508528], permittedLengths: [16], // prettier-ignore - pattern: /^(100003|508(2|[5-9])|60(69|[7-8])|652(1[5-9]|[2-5][0-9]|8[5-9])|65300[3-4]|8172([0-1]|[3-5]|7|9)|817(3[3-8]|40[6-9]|410)|35380([0-2]|[5-6]|9))[0-9]{0,12}$/ // eslint-disable-line max-len + pattern: + /^(100003|508(2|[5-9])|60(69|[7-8])|652(1[5-9]|[2-5][0-9]|8[5-9])|65300[3-4]|8172([0-1]|[3-5]|7|9)|817(3[3-8]|40[6-9]|410)|35380([0-2]|[5-6]|9))[0-9]{0,12}$/ // eslint-disable-line max-len }); CardType.cards.push({ diff --git a/packages/lib/src/components/internal/SecuredFields/lib/CSF/utils/destroySecuredFields.ts b/packages/lib/src/components/internal/SecuredFields/lib/CSF/utils/destroySecuredFields.ts index 66c6f19b..9fe80b86 100644 --- a/packages/lib/src/components/internal/SecuredFields/lib/CSF/utils/destroySecuredFields.ts +++ b/packages/lib/src/components/internal/SecuredFields/lib/CSF/utils/destroySecuredFields.ts @@ -12,7 +12,7 @@ export function destroySecuredFields(): void { // Then remove ref to SecuredField instance securedFieldKeys.forEach(pFieldType => { const sf: SecuredField = this.state.securedFields[pFieldType]; - if (sf) sf.destroy();// Comment out if you want to test the 'destroy' effects in the actual SF + if (sf) sf.destroy(); // Comment out if you want to test the 'destroy' effects in the actual SF this.state.securedFields[pFieldType] = null; }); // -- diff --git a/packages/lib/src/components/internal/SocialSecurityNumberBrazil/validate.ts b/packages/lib/src/components/internal/SocialSecurityNumberBrazil/validate.ts index 693c81f4..58def64d 100644 --- a/packages/lib/src/components/internal/SocialSecurityNumberBrazil/validate.ts +++ b/packages/lib/src/components/internal/SocialSecurityNumberBrazil/validate.ts @@ -1,3 +1,3 @@ -export default function(ssn) { +export default function (ssn) { return /(^\d{3}\.\d{3}\.\d{3}-\d{2}$)|(^\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2}$)/.test(ssn); } diff --git a/packages/lib/src/components/utils.ts b/packages/lib/src/components/utils.ts index 889ed671..ae837eb1 100644 --- a/packages/lib/src/components/utils.ts +++ b/packages/lib/src/components/utils.ts @@ -1,4 +1,4 @@ -import {PaymentResponse, RawPaymentResponse, UIElementStatus} from './types'; +import { PaymentResponse, RawPaymentResponse, UIElementStatus } from './types'; const ALLOWED_PROPERTIES = ['action', 'resultCode', 'sessionData', 'order', 'sessionResult']; diff --git a/packages/lib/src/core/ProcessResponse/PaymentAction/PaymentAction.test.ts b/packages/lib/src/core/ProcessResponse/PaymentAction/PaymentAction.test.ts index 8311becc..130ffa1c 100644 --- a/packages/lib/src/core/ProcessResponse/PaymentAction/PaymentAction.test.ts +++ b/packages/lib/src/core/ProcessResponse/PaymentAction/PaymentAction.test.ts @@ -6,8 +6,7 @@ describe('getComponentForAction', () => { method: 'GET', paymentMethodType: 'ideal', type: 'redirect', - url: - 'http://localhost:8080/hpp/redirectIdeal.shtml?brandCode=ideal&countryCode=NL¤cyCode=EUR&issuerId=1121&merchantAccount=TestMerchant&merchantIntegration.type=CHECKOUT_GENERIC&merchantIntegration.version=49&merchantReference=8&merchantReturnData=991558707124405K&merchantSig=g1KlViuS0JSr%2Fl9ah1uC4dpYjpn9T%2FvB7dAwHn81sdA%3D&paymentAmount=250&recurringContract=RECURRING&resURL=http%3A%2F%2Flocalhost%3A8080%2Fcheckoutshopper%2Fservices%2FPaymentIncomingRedirect%2Fv1%2FlocalPaymentMethod%3FmerchantAccount%3DTestMerchant%26returnURL%3Dapp%253A%252F%252Fyou&sessionValidity=2019-05-24T15%3A12%3A04Z&shopperReference=emred&skinCode=pub.v2.9915585372919700.W8YBZHHDHqOtHZK8ZC-X7_n9x1N3opO8Wbc_MQlh2IU' + url: 'http://localhost:8080/hpp/redirectIdeal.shtml?brandCode=ideal&countryCode=NL¤cyCode=EUR&issuerId=1121&merchantAccount=TestMerchant&merchantIntegration.type=CHECKOUT_GENERIC&merchantIntegration.version=49&merchantReference=8&merchantReturnData=991558707124405K&merchantSig=g1KlViuS0JSr%2Fl9ah1uC4dpYjpn9T%2FvB7dAwHn81sdA%3D&paymentAmount=250&recurringContract=RECURRING&resURL=http%3A%2F%2Flocalhost%3A8080%2Fcheckoutshopper%2Fservices%2FPaymentIncomingRedirect%2Fv1%2FlocalPaymentMethod%3FmerchantAccount%3DTestMerchant%26returnURL%3Dapp%253A%252F%252Fyou&sessionValidity=2019-05-24T15%3A12%3A04Z&shopperReference=emred&skinCode=pub.v2.9915585372919700.W8YBZHHDHqOtHZK8ZC-X7_n9x1N3opO8Wbc_MQlh2IU' }; const redirectPostActionMock = { @@ -17,8 +16,7 @@ describe('getComponentForAction', () => { data: { test: '123' }, - url: - 'http://localhost:8080/hpp/redirectIdeal.shtml?brandCode=ideal&countryCode=NL¤cyCode=EUR&issuerId=1121&merchantAccount=TestMerchant&merchantIntegration.type=CHECKOUT_GENERIC&merchantIntegration.version=49&merchantReference=8&merchantReturnData=991558707124405K&merchantSig=g1KlViuS0JSr%2Fl9ah1uC4dpYjpn9T%2FvB7dAwHn81sdA%3D&paymentAmount=250&recurringContract=RECURRING&resURL=http%3A%2F%2Flocalhost%3A8080%2Fcheckoutshopper%2Fservices%2FPaymentIncomingRedirect%2Fv1%2FlocalPaymentMethod%3FmerchantAccount%3DTestMerchant%26returnURL%3Dapp%253A%252F%252Fyou&sessionValidity=2019-05-24T15%3A12%3A04Z&shopperReference=emred&skinCode=pub.v2.9915585372919700.W8YBZHHDHqOtHZK8ZC-X7_n9x1N3opO8Wbc_MQlh2IU' + url: 'http://localhost:8080/hpp/redirectIdeal.shtml?brandCode=ideal&countryCode=NL¤cyCode=EUR&issuerId=1121&merchantAccount=TestMerchant&merchantIntegration.type=CHECKOUT_GENERIC&merchantIntegration.version=49&merchantReference=8&merchantReturnData=991558707124405K&merchantSig=g1KlViuS0JSr%2Fl9ah1uC4dpYjpn9T%2FvB7dAwHn81sdA%3D&paymentAmount=250&recurringContract=RECURRING&resURL=http%3A%2F%2Flocalhost%3A8080%2Fcheckoutshopper%2Fservices%2FPaymentIncomingRedirect%2Fv1%2FlocalPaymentMethod%3FmerchantAccount%3DTestMerchant%26returnURL%3Dapp%253A%252F%252Fyou&sessionValidity=2019-05-24T15%3A12%3A04Z&shopperReference=emred&skinCode=pub.v2.9915585372919700.W8YBZHHDHqOtHZK8ZC-X7_n9x1N3opO8Wbc_MQlh2IU' }; test('processes a redirect response', () => { diff --git a/packages/lib/src/core/Services/sessions/cancel-order.ts b/packages/lib/src/core/Services/sessions/cancel-order.ts index dbad9981..06721040 100644 --- a/packages/lib/src/core/Services/sessions/cancel-order.ts +++ b/packages/lib/src/core/Services/sessions/cancel-order.ts @@ -1,6 +1,6 @@ import { httpPost } from '../http'; import Session from '../../CheckoutSession'; -import {CheckoutSessionOrdersResponse, Order} from '../../../types'; +import { CheckoutSessionOrdersResponse, Order } from '../../../types'; import { API_VERSION } from './constants'; /** diff --git a/packages/lib/src/core/core.test.ts b/packages/lib/src/core/core.test.ts index 3350afd0..f6ee0b92 100644 --- a/packages/lib/src/core/core.test.ts +++ b/packages/lib/src/core/core.test.ts @@ -89,8 +89,7 @@ describe('Core', () => { paymentData: 'Ab02b4c0!BQABAgCUeRP+3La4...', paymentMethodType: 'scheme', subtype: 'fingerprint', - token: - 'eyJ0aHJlZURTTWV0aG9kTm90aWZpY2F0aW9uVVJMIjoiaHR0cHM6XC9cL2NoZWNrb3V0c2hvcHBlci10ZXN0LmFkeWVuLmNvbVwvY2hlY2tvdXRzaG9wcGVyXC90aHJlZURTTWV0aG9kTm90aWZpY2F0aW9uLnNodG1sP29yaWdpbktleT1wdWIudjIuODExNTY1ODcwNTcxMzk0MC5hSFIwY0hNNkx5OXdhSEF0TnpFdGMybHRiMjR1YzJWaGJXeGxjM010WTJobFkydHZkWFF1WTI5dC50VnJIV3B4UktWVTVPMENiNUg5TVFlUnJKdmZRQ1lnbXR6VTY1WFhzZ2NvIiwidGhyZWVEU01ldGhvZFVybCI6Imh0dHBzOlwvXC9wYWwtdGVzdC5hZHllbi5jb21cL3RocmVlZHMyc2ltdWxhdG9yXC9hY3NcL3N0YXJ0TWV0aG9kLnNodG1sIiwidGhyZWVEU1NlcnZlclRyYW5zSUQiOiI5MzI2ZjNiOS00MTc3LTQ4ZTktYmM2Mi1kOTliYzVkZDA2Y2IifQ==', + token: 'eyJ0aHJlZURTTWV0aG9kTm90aWZpY2F0aW9uVVJMIjoiaHR0cHM6XC9cL2NoZWNrb3V0c2hvcHBlci10ZXN0LmFkeWVuLmNvbVwvY2hlY2tvdXRzaG9wcGVyXC90aHJlZURTTWV0aG9kTm90aWZpY2F0aW9uLnNodG1sP29yaWdpbktleT1wdWIudjIuODExNTY1ODcwNTcxMzk0MC5hSFIwY0hNNkx5OXdhSEF0TnpFdGMybHRiMjR1YzJWaGJXeGxjM010WTJobFkydHZkWFF1WTI5dC50VnJIV3B4UktWVTVPMENiNUg5TVFlUnJKdmZRQ1lnbXR6VTY1WFhzZ2NvIiwidGhyZWVEU01ldGhvZFVybCI6Imh0dHBzOlwvXC9wYWwtdGVzdC5hZHllbi5jb21cL3RocmVlZHMyc2ltdWxhdG9yXC9hY3NcL3N0YXJ0TWV0aG9kLnNodG1sIiwidGhyZWVEU1NlcnZlclRyYW5zSUQiOiI5MzI2ZjNiOS00MTc3LTQ4ZTktYmM2Mi1kOTliYzVkZDA2Y2IifQ==', type: 'threeDS2' }; @@ -117,8 +116,7 @@ describe('Core', () => { const challengeAction = { paymentData: 'Ab02b4c0!BQABAgCUeRP+3La4...', subtype: 'challenge', - token: - 'eyJhY3NSZWZlcmVuY2VOdW1iZXIiOiJBRFlFTi1BQ1MtU0lNVUxBVE9SIiwiYWNzVHJhbnNJRCI6Ijg0MzZjYThkLThkN2EtNGFjYy05NmYyLTE0ZjU0MjgyNzczZiIsImFjc1VSTCI6Imh0dHBzOlwvXC9wYWwtdGVzdC5hZHllbi5jb21cL3RocmVlZHMyc2ltdWxhdG9yXC9hY3NcL2NoYWxsZW5nZS5zaHRtbCIsIm1lc3NhZ2VWZXJzaW9uIjoiMi4xLjAiLCJ0aHJlZURTTm90aWZpY2F0aW9uVVJMIjoiaHR0cHM6XC9cL2NoZWNrb3V0c2hvcHBlci10ZXN0LmFkeWVuLmNvbVwvY2hlY2tvdXRzaG9wcGVyXC8zZG5vdGlmLnNodG1sP29yaWdpbktleT1wdWIudjIuODExNTY1ODcwNTcxMzk0MC5hSFIwY0hNNkx5OWphR1ZqYTI5MWRITm9iM0J3WlhJdGRHVnpkQzVoWkhsbGJpNWpiMjAuVGFKalVLN3VrUFdTUzJEX3l2ZDY4TFRLN2dRN2ozRXFOM05nS1JWQW84OCIsInRocmVlRFNTZXJ2ZXJUcmFuc0lEIjoiZTU0NDNjZTYtNTE3Mi00MmM1LThjY2MtYmRjMGE1MmNkZjViIn0=', + token: 'eyJhY3NSZWZlcmVuY2VOdW1iZXIiOiJBRFlFTi1BQ1MtU0lNVUxBVE9SIiwiYWNzVHJhbnNJRCI6Ijg0MzZjYThkLThkN2EtNGFjYy05NmYyLTE0ZjU0MjgyNzczZiIsImFjc1VSTCI6Imh0dHBzOlwvXC9wYWwtdGVzdC5hZHllbi5jb21cL3RocmVlZHMyc2ltdWxhdG9yXC9hY3NcL2NoYWxsZW5nZS5zaHRtbCIsIm1lc3NhZ2VWZXJzaW9uIjoiMi4xLjAiLCJ0aHJlZURTTm90aWZpY2F0aW9uVVJMIjoiaHR0cHM6XC9cL2NoZWNrb3V0c2hvcHBlci10ZXN0LmFkeWVuLmNvbVwvY2hlY2tvdXRzaG9wcGVyXC8zZG5vdGlmLnNodG1sP29yaWdpbktleT1wdWIudjIuODExNTY1ODcwNTcxMzk0MC5hSFIwY0hNNkx5OWphR1ZqYTI5MWRITm9iM0J3WlhJdGRHVnpkQzVoWkhsbGJpNWpiMjAuVGFKalVLN3VrUFdTUzJEX3l2ZDY4TFRLN2dRN2ozRXFOM05nS1JWQW84OCIsInRocmVlRFNTZXJ2ZXJUcmFuc0lEIjoiZTU0NDNjZTYtNTE3Mi00MmM1LThjY2MtYmRjMGE1MmNkZjViIn0=', type: 'threeDS2', paymentMethodType: 'scheme' }; diff --git a/packages/lib/src/language/utils.test.ts b/packages/lib/src/language/utils.test.ts index 76628cb7..1059e1d7 100644 --- a/packages/lib/src/language/utils.test.ts +++ b/packages/lib/src/language/utils.test.ts @@ -1,14 +1,6 @@ -import { - formatCustomTranslations, - formatLocale, - getTranslation, - interpolateElement, - loadTranslations, - matchLocale, - parseLocale -} from './utils'; +import { formatCustomTranslations, formatLocale, getTranslation, interpolateElement, loadTranslations, matchLocale, parseLocale } from './utils'; import locales from './locales'; -import {createElement} from "preact"; +import { createElement } from 'preact'; const defaultSupportedLocales = Object.keys(locales); @@ -257,7 +249,7 @@ describe('interpolateElement()', () => { test('it should throw an error when wrong amount elements', () => { const renderLink = translation => createElement('a', { href: 'example.com' }, [translation]); - const resultFn = () => interpolateElement('By clicking continue %#you%# agree with the %#term and conditions%#', [renderLink]); + const resultFn = () => interpolateElement('By clicking continue %#you%# agree with the %#term and conditions%#', [renderLink]); expect(resultFn).toThrow(Error); }); -}); \ No newline at end of file +}); diff --git a/packages/lib/src/utils/Formatters/formatter.test.ts b/packages/lib/src/utils/Formatters/formatter.test.ts index c447b4ab..5cc975ee 100644 --- a/packages/lib/src/utils/Formatters/formatter.test.ts +++ b/packages/lib/src/utils/Formatters/formatter.test.ts @@ -1,12 +1,13 @@ -import { digitsOnlyFormatter } from "./formatters"; +import { digitsOnlyFormatter } from './formatters'; -function getAllCharactersArray() { - const allCharacters:Array = []; - for (let i=32; i<127; i++) { allCharacters.push(String.fromCharCode(i)); } +function getAllCharactersArray() { + const allCharacters: Array = []; + for (let i = 32; i < 127; i++) { + allCharacters.push(String.fromCharCode(i)); + } return allCharacters.join(','); } - describe('Formatters', () => { describe('digitsOnlyFormatter', () => { test('All non-digit characters get removed from value', () => { diff --git a/packages/lib/src/utils/Formatters/formatters.ts b/packages/lib/src/utils/Formatters/formatters.ts index c5bcbabc..269114c0 100644 --- a/packages/lib/src/utils/Formatters/formatters.ts +++ b/packages/lib/src/utils/Formatters/formatters.ts @@ -1,6 +1,6 @@ -import { FormatterFn } from "./types"; +import { FormatterFn } from './types'; // Removes all non-digits -export const digitsOnlyFormatter: FormatterFn = (value:string) => { +export const digitsOnlyFormatter: FormatterFn = (value: string) => { return value.replace(/[^0-9]/g, ''); -} \ No newline at end of file +}; diff --git a/packages/lib/src/utils/Formatters/types.ts b/packages/lib/src/utils/Formatters/types.ts index 6e73b8f7..7c2692f0 100644 --- a/packages/lib/src/utils/Formatters/types.ts +++ b/packages/lib/src/utils/Formatters/types.ts @@ -1,8 +1,11 @@ // Context holds state data for the input field implementing this. -export type FormatterFn = (value: string, context?: { - state: { - data: { - country?: string, - }, - }, -}) => string; +export type FormatterFn = ( + value: string, + context?: { + state: { + data: { + country?: string; + }; + }; + } +) => string; diff --git a/packages/lib/src/utils/Validator/types.ts b/packages/lib/src/utils/Validator/types.ts index 0c3bc473..cf9807a6 100644 --- a/packages/lib/src/utils/Validator/types.ts +++ b/packages/lib/src/utils/Validator/types.ts @@ -1,5 +1,5 @@ import { ValidationRuleResult } from './ValidationRuleResult'; -import { Formatter } from '../useForm/types' +import { Formatter } from '../useForm/types'; type ValidatorMode = 'blur' | 'input'; diff --git a/packages/lib/src/utils/get-image.ts b/packages/lib/src/utils/get-image.ts index fba5994f..b8b09caf 100644 --- a/packages/lib/src/utils/get-image.ts +++ b/packages/lib/src/utils/get-image.ts @@ -15,19 +15,19 @@ export interface ImageOptions { const returnImage = ({ name, loadingContext, imageFolder = '', parentFolder = '', extension, size = '', subFolder = '' }: ImageOptions): string => `${loadingContext}images/${imageFolder}${subFolder}${parentFolder}${name}${size}.${extension}`; -export const getImageUrl = ({ loadingContext = FALLBACK_CONTEXT, extension = 'svg', ...options }: ImageOptions): Function => ( - name: string -): string => { - const imageOptions: ImageOptions = { - extension, - loadingContext, - imageFolder: 'logos/', - parentFolder: '', - name, - ...options +export const getImageUrl = + ({ loadingContext = FALLBACK_CONTEXT, extension = 'svg', ...options }: ImageOptions): Function => + (name: string): string => { + const imageOptions: ImageOptions = { + extension, + loadingContext, + imageFolder: 'logos/', + parentFolder: '', + name, + ...options + }; + + return returnImage(imageOptions); }; - return returnImage(imageOptions); -}; - export default getImageUrl; diff --git a/packages/lib/src/utils/get-issuer-image.ts b/packages/lib/src/utils/get-issuer-image.ts index 81e9e1b6..b84b8801 100644 --- a/packages/lib/src/utils/get-issuer-image.ts +++ b/packages/lib/src/utils/get-issuer-image.ts @@ -1,15 +1,17 @@ import { getImageUrl, ImageOptions } from './get-image'; -const getIssuerImageUrl = (options: object, type: string) => (issuer: string): string => { - if (!issuer) return null; +const getIssuerImageUrl = + (options: object, type: string) => + (issuer: string): string => { + if (!issuer) return null; - const imageOptions: ImageOptions = { - parentFolder: issuer ? `${type}/` : '', - type: issuer || type, - ...options + const imageOptions: ImageOptions = { + parentFolder: issuer ? `${type}/` : '', + type: issuer || type, + ...options + }; + + return getImageUrl(imageOptions)(issuer); }; - return getImageUrl(imageOptions)(issuer); -}; - export default getIssuerImageUrl; diff --git a/packages/lib/src/utils/get-process-message-handler.ts b/packages/lib/src/utils/get-process-message-handler.ts index 8988741c..7d346f46 100644 --- a/packages/lib/src/utils/get-process-message-handler.ts +++ b/packages/lib/src/utils/get-process-message-handler.ts @@ -12,44 +12,46 @@ import { hasOwnProperty } from './hasOwnProperty'; import { PostMsgParseErrorObject } from '../components/ThreeDS2/types'; -const getProcessMessageHandler = (domain: string, resolve: Function, reject: Function, expectedType: string): Function => event => { - const parseErrorObj: PostMsgParseErrorObject = {}; - const origin = event.origin || event.originalEvent.origin; +const getProcessMessageHandler = + (domain: string, resolve: Function, reject: Function, expectedType: string): Function => + event => { + const parseErrorObj: PostMsgParseErrorObject = {}; + const origin = event.origin || event.originalEvent.origin; - if (origin !== domain) { - return 'Message was not sent from the expected domain'; - } - - if (typeof event.data !== 'string') { - return 'Event data was not of type string'; - } - - if (!event.data.length) { - return 'Invalid event data string'; - } - - // Try to parse the data - try { - const feedbackObj = JSON.parse(event.data); - if (hasOwnProperty(feedbackObj, 'type') && feedbackObj.type === expectedType) { - resolve(feedbackObj); - } else { - // Silent fail - applies when RiskModule device fingerprinting is ongoing and this handler is picking up securedFields traffic - return 'Event data was not of expected type'; + if (origin !== domain) { + return 'Message was not sent from the expected domain'; } - } catch (e) { - parseErrorObj.type = `${expectedType}-JSON-parse-error`; - parseErrorObj.comment = 'failed to JSON parse event.data'; - parseErrorObj.extraInfo = `event.data = ${event.data}`; - parseErrorObj.eventDataRaw = event.data; - // TODO - decide whether to console.log/debug/error &/or call the merchant defined onError callback - console.debug('get-process-message-handler::CATCH::Un-parseable JSON:: parseErrorObj=', parseErrorObj); + if (typeof event.data !== 'string') { + return 'Event data was not of type string'; + } - return false; - } + if (!event.data.length) { + return 'Invalid event data string'; + } - return true; -}; + // Try to parse the data + try { + const feedbackObj = JSON.parse(event.data); + if (hasOwnProperty(feedbackObj, 'type') && feedbackObj.type === expectedType) { + resolve(feedbackObj); + } else { + // Silent fail - applies when RiskModule device fingerprinting is ongoing and this handler is picking up securedFields traffic + return 'Event data was not of expected type'; + } + } catch (e) { + parseErrorObj.type = `${expectedType}-JSON-parse-error`; + parseErrorObj.comment = 'failed to JSON parse event.data'; + parseErrorObj.extraInfo = `event.data = ${event.data}`; + parseErrorObj.eventDataRaw = event.data; + + // TODO - decide whether to console.log/debug/error &/or call the merchant defined onError callback + console.debug('get-process-message-handler::CATCH::Un-parseable JSON:: parseErrorObj=', parseErrorObj); + + return false; + } + + return true; + }; export default getProcessMessageHandler; diff --git a/packages/lib/src/utils/getProp.test.ts b/packages/lib/src/utils/getProp.test.ts index f6211328..33491572 100644 --- a/packages/lib/src/utils/getProp.test.ts +++ b/packages/lib/src/utils/getProp.test.ts @@ -2,7 +2,11 @@ import getProp from './getProp'; const props = { user: { - posts: [{ title: 'Foo', comments: ['Good one!', 'Interesting...'] }, { title: 'Bar', comments: ['Ok'] }, { title: 'Baz', comments: [] }] + posts: [ + { title: 'Foo', comments: ['Good one!', 'Interesting...'] }, + { title: 'Bar', comments: ['Ok'] }, + { title: 'Baz', comments: [] } + ] } }; diff --git a/packages/lib/src/utils/promiseTimeout.test.ts b/packages/lib/src/utils/promiseTimeout.test.ts index e98cda4b..8127f29e 100644 --- a/packages/lib/src/utils/promiseTimeout.test.ts +++ b/packages/lib/src/utils/promiseTimeout.test.ts @@ -24,7 +24,11 @@ describe('creating a promiseTimeout', () => { test('and letting it time out', async () => { jest.useFakeTimers(); - const newPromiseTimeout = promiseTimeout(1000, promiseOne(() => {}), { timed_out: true }); + const newPromiseTimeout = promiseTimeout( + 1000, + promiseOne(() => {}), + { timed_out: true } + ); // Fast-forward until all timers have been executed jest.advanceTimersByTime(1000); diff --git a/packages/lib/src/utils/useForm/types.ts b/packages/lib/src/utils/useForm/types.ts index cb13dedf..9f8fae2f 100644 --- a/packages/lib/src/utils/useForm/types.ts +++ b/packages/lib/src/utils/useForm/types.ts @@ -23,11 +23,11 @@ export interface Formatter { } export type FormProps = { - rules?: ValidatorRules, + rules?: ValidatorRules; formatters?: { [key: string]: Formatter | Function; - }, - [key: string]: any, + }; + [key: string]: any; }; export interface Form extends FormState { diff --git a/packages/lib/src/utils/useForm/useForm.ts b/packages/lib/src/utils/useForm/useForm.ts index 8b846e35..02fa074c 100644 --- a/packages/lib/src/utils/useForm/useForm.ts +++ b/packages/lib/src/utils/useForm/useForm.ts @@ -4,7 +4,7 @@ import { getReducer, init } from './reducer'; import { Form, FormState, FormProps, Formatter } from './types'; function isFormatterObject(formatter: Formatter | Function): formatter is Formatter { - return formatter && ('formatterFn' in formatter); + return formatter && 'formatterFn' in formatter; } function useForm(props: FormProps): Form {