Skip to content

Commit

Permalink
chore(common): GITHUB-1972 bump yup to 1.1.1 (#1972)
Browse files Browse the repository at this point in the history
  • Loading branch information
quad authored Jul 5, 2023
1 parent 362aadc commit c6b8fee
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 113 deletions.
133 changes: 55 additions & 78 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"@types/iframe-resizer": "^3.5.9",
"@types/reselect": "^2.2.0",
"@types/shallowequal": "^1.1.1",
"@types/yup": "^0.26.24",
"card-validator": "^6.2.0",
"core-js": "^3.25.2",
"current-script-polyfill": "^1.0.0",
Expand All @@ -76,7 +75,7 @@
"rxjs": "^6.6.7",
"shallowequal": "^1.1.0",
"tslib": "^1.10.0",
"yup": "^0.27.0"
"yup": "^1.1.1"
},
"devDependencies": {
"@babel/core": "^7.6.2",
Expand Down Expand Up @@ -112,6 +111,7 @@
"jest-junit": "^15.0.0",
"nx": "^13.10.3",
"prettier": "^2.6.2",
"regenerator-runtime": "^0.13.3",
"request": "^2.83.0",
"semver": "^7.1.1",
"source-map-loader": "^0.2.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,39 @@
import { creditCardType, cvv, expirationDate, number } from 'card-validator';
import { includes } from 'lodash';
import { object, string, StringSchema, ValidationError } from 'yup';
import { object, ObjectShape, string, StringSchema, ValidationError } from 'yup';

import { CardInstrument } from '../../payment/instrument';
import HostedFieldType from '../hosted-field-type';

import { HostedInputValidateErrorDataMap } from './hosted-input-validate-error-data';
import HostedInputValidateResults from './hosted-input-validate-results';
import HostedInputValues from './hosted-input-values';

export default class HostedInputValidator {
private readonly _completeSchema: ObjectShape = {
cardCode: this._getCardCodeSchema(),
cardCodeVerification: this._getCardCodeVerificationSchema(),
cardExpiry: this._getCardExpirySchema(),
cardName: this._getCardNameSchema(),
cardNumber: this._getCardNumberSchema(),
cardNumberVerification: this._getCardNumberVerificationSchema(),
};

constructor(private _cardInstrument?: CardInstrument) {
this._configureCardValidator();
}

async validate(values: HostedInputValues): Promise<HostedInputValidateResults> {
const requiredFields = Object.keys(values);
const schemas: { [key in keyof HostedInputValues]: StringSchema } = {};
const schemas: ObjectShape = {};
const results: HostedInputValidateResults = {
errors: {},
isValid: true,
};

if (includes(requiredFields, HostedFieldType.CardCode)) {
schemas.cardCode = this._getCardCodeSchema();
results.errors.cardCode = [];
}

if (includes(requiredFields, HostedFieldType.CardCodeVerification)) {
schemas.cardCodeVerification = this._getCardCodeVerificationSchema();
results.errors.cardCodeVerification = [];
}

if (includes(requiredFields, HostedFieldType.CardExpiry)) {
schemas.cardExpiry = this._getCardExpirySchema();
results.errors.cardExpiry = [];
}

if (includes(requiredFields, HostedFieldType.CardName)) {
schemas.cardName = this._getCardNameSchema();
results.errors.cardName = [];
}

if (includes(requiredFields, HostedFieldType.CardNumber)) {
schemas.cardNumber = this._getCardNumberSchema();
results.errors.cardNumber = [];
}

if (includes(requiredFields, HostedFieldType.CardNumberVerification)) {
schemas.cardNumberVerification = this._getCardNumberVerificationSchema();
results.errors.cardNumberVerification = [];
let requiredField: keyof HostedInputValues;
for (requiredField in values) {
if (Object.prototype.hasOwnProperty.call(values, requiredField)) {
schemas[requiredField] = this._completeSchema[requiredField];
results.errors[requiredField] = [];
}
}

try {
Expand Down

0 comments on commit c6b8fee

Please sign in to comment.