Skip to content

Commit 39bce37

Browse files
committed
chore: linting fixes
1 parent 17ea040 commit 39bce37

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

src/.DS_Store

0 Bytes
Binary file not shown.

src/common/pay_theory_types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// noinspection JSUnusedGlobalSymbols
2+
// eslint-disable no-unused-vars
23

34
import { defaultElementIds, ElementTypes, MERCHANT_FEE, SERVICE_FEE } from './data';
45

@@ -108,7 +109,7 @@ export interface TokenizedPaymentMethodObject {
108109
brand: string;
109110
expiration: string;
110111
payment_type: 'card' | 'ach';
111-
metadata: { [keys: string | number]: string | number | boolean };
112+
metadata: Record<string | number, string | number | boolean>;
112113
}
113114

114115
export interface TokenizedPaymentMethodResponse {

src/components/pay-theory-hosted-field-transactional/index.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* eslint-disable no-unused-vars */
2+
/* eslint-disable no-empty-function */
3+
14
import PayTheoryHostedField from '../pay-theory-hosted-field';
25
import common from '../../common';
36
import {
@@ -87,7 +90,7 @@ class PayTheoryHostedFieldTransactional extends PayTheoryHostedField {
8790
protected _completed = false;
8891

8992
// Used to track if the element was the one that was used when transact was called
90-
protected _isTransactingElement: boolean = false;
93+
protected _isTransactingElement = false;
9194

9295
// Used to track if the element is ready to communicate with the transacting iframe
9396
protected _isReady = false;
@@ -249,30 +252,33 @@ class PayTheoryHostedFieldTransactional extends PayTheoryHostedField {
249252
}
250253
}
251254

252-
async connectedCallback() {
255+
connectedCallback() {
253256
// Set up a listener for the hosted field to message saying it is ready for the pt-token to be sent
254257
this._removeHostTokenListener = common.handleHostedFieldMessage(
255-
// @ts-ignore
256258
(event: { type: unknown; element: ElementTypes }) => {
257259
return (
258260
event.type === 'pt-static:pt_token_ready' &&
259261
this._transactingIFrameId.includes(event.element)
260262
);
261263
},
262-
this.sendPtToken,
264+
() => this.sendPtToken(),
263265
);
264266

265267
this._removeFeeListener = common.handleHostedFieldMessage(
266268
(event: { type: unknown }) => event.type === 'pt-static:calculated_fee',
267-
this.handleFeeMessage,
269+
(message: {
270+
type: string;
271+
body: { fee: number; payment_type: string };
272+
field: ElementTypes;
273+
}) => this.handleFeeMessage(message),
268274
);
269275

270276
this._removeFeeCalcReconnect = common.handleHostedFieldMessage(
271277
(event: { type: unknown }) => event.type === 'pt-static:fee_calc_reconnect',
272-
this.handleFeeCalcReconnect,
278+
(message: { type: string; field: ElementTypes }) => this.handleFeeCalcReconnect(message),
273279
);
274280

275-
await super.connectedCallback();
281+
super.connectedCallback();
276282
}
277283

278284
disconnectedCallback() {
@@ -286,7 +292,6 @@ class PayTheoryHostedFieldTransactional extends PayTheoryHostedField {
286292
data.fee_mode = data.fee_mode ?? this._feeMode ?? defaultFeeMode;
287293
data.metadata = data.metadata ?? this._metadata;
288294
this._isTransactingElement = true;
289-
// @ts-ignore
290295
const response = await common.sendTransactingMessage(element, data.payTheoryData.billing_info);
291296
if (response.type === ERROR_STEP) {
292297
this._isTransactingElement = false;
@@ -334,7 +339,7 @@ class PayTheoryHostedFieldTransactional extends PayTheoryHostedField {
334339
common.hostedFieldsEndpoint,
335340
);
336341
const result = await this.resetToken();
337-
if (result) {
342+
if (result.type === ResponseMessageTypes.READY) {
338343
this._isTransactingElement = false;
339344
this.initialized = false;
340345
// Successfully sent the cancel message and reset the token
@@ -355,7 +360,6 @@ class PayTheoryHostedFieldTransactional extends PayTheoryHostedField {
355360
): Promise<TokenizedPaymentMethodMessage | ErrorMessage> {
356361
this._isTransactingElement = true;
357362
this._initialized = true;
358-
// @ts-ignore
359363
const response = await common.sendTransactingMessage(element, data.billingInfo);
360364
if (response.type === ERROR_STEP) {
361365
this._isTransactingElement = false;

src/components/pay-theory-hosted-field/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* global HTMLElement */
2+
/* eslint-disable no-unused-vars */
3+
24
import common from '../../common';
3-
//@ts-expect-error
5+
//@ts-expect-error - TS doesn't know about DOMPurify
46
import DOMPurify from 'dompurify';
57
import { ElementTypes } from '../../common/data';
68
import { StyleObject } from '../../common/pay_theory_types';

src/field-set/validation.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ const findAchError = (processedElements: PayTheoryHostedField[]): string | false
154154
return false;
155155
}
156156

157-
// @ts-ignore
158157
achCheck.forEach(obj => {
159158
if (processedElements.reduce(obj.check, false) === false) {
160159
return obj.error;
@@ -213,7 +212,7 @@ const validatePhone = (phone: string) => {
213212
return stripped.length >= 5 && stripped.length <= 15;
214213
};
215214

216-
type payorInfo = {
215+
interface payorInfo {
217216
same_as_billing?: boolean;
218217
email?: string;
219218
phone?: string;
@@ -227,7 +226,7 @@ type payorInfo = {
227226
postal_code?: string;
228227
country?: string;
229228
};
230-
};
229+
}
231230

232231
const isValidPayorInfo = (payorInfo: payorInfo): ErrorResponse | null => {
233232
if (!validate(payorInfo, 'object')) {
@@ -268,7 +267,7 @@ const isValidPayorInfo = (payorInfo: payorInfo): ErrorResponse | null => {
268267
};
269268

270269
const nullifyEmptyStrings = (params: object) => {
271-
const newParams = JSON.parse(JSON.stringify(params));
270+
const newParams: object = JSON.parse(JSON.stringify(params));
272271
Object.keys(newParams).forEach(key => {
273272
const value = newParams[key as keyof typeof newParams] as unknown;
274273
if (value === '') {
@@ -281,9 +280,9 @@ const nullifyEmptyStrings = (params: object) => {
281280
return newParams;
282281
};
283282

284-
const formatPayorObject = (payorInfo: payorInfo): PayorInfo => {
283+
const formatPayorObject = (payorInfo: PayorInfo): PayorInfo => {
285284
// Make a deep copy of the payorInfo object
286-
let payorCopy = JSON.parse(JSON.stringify(payorInfo));
285+
let payorCopy: PayorInfo = JSON.parse(JSON.stringify(payorInfo));
287286
// Nullify unknown empty strings
288287
payorCopy = nullifyEmptyStrings(payorCopy);
289288
// Strip out unknown non-numeric characters from the phone number
@@ -480,7 +479,7 @@ const isValidHealthExpenseType = (healthExpenseType: unknown): ErrorResponse | n
480479
if (healthExpenseType === null || healthExpenseType === undefined) return null;
481480
if (!validate<string>(healthExpenseType, 'string')) {
482481
return handleTypedError(ErrorType.INVALID_PARAM, 'healthExpenseType must be a string');
483-
} //@ts-expect-error
482+
} //@ts-expect-error - healthExpenseType is a string and want to compare to all values of the enum which are also strings
484483
if (!Object.values(HealthExpenseType).includes(healthExpenseType)) {
485484
return handleTypedError(
486485
ErrorType.INVALID_PARAM,
@@ -529,7 +528,7 @@ const validTransactionParams = (
529528
error = isValidPayorInfo(payorInfo);
530529
if (error) return error;
531530
// validate the payorId
532-
error = isValidPayorDetails(payorInfo, payTheoryData?.payor_id);
531+
error = isValidPayorDetails(payorInfo, payTheoryData.payor_id);
533532
if (error) return error;
534533
// validate the fee mode
535534
error = isValidFeeMode(feeMode);
@@ -547,7 +546,7 @@ const validTransactionParams = (
547546
error = isValidHealthExpenseType(props.healthExpenseType);
548547
if (error) return error;
549548
// validate the fee
550-
return isValidFeeAmount(payTheoryData?.fee);
549+
return isValidFeeAmount(payTheoryData.fee);
551550
};
552551

553552
const validQRSize = (size: unknown): ErrorResponse | null => {

0 commit comments

Comments
 (0)