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

core(deps): GITHUB-1972 bump yup to 1.1.1 #1972

Merged
merged 1 commit into from
Jul 5, 2023
Merged
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
chore(common): GITHUB-1972 bump yup to 1.1.1
  • Loading branch information
Scott Robinson committed Jun 22, 2023
commit 025ef017706f5d663dcbee092ca45e28db0c6804
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",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we be certain that we don't require this type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From https://www.npmjs.com/package/@types/yup:

This package has been deprecated

This is a stub types definition. yup provides its own type definitions, so you do not need this installed.

"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