UNPKG

@adyen/kyc-components

Version:

This guide assumes that you have already an account with Adyen. A legalEntity needs to be created, and you need to have a `legalEntityId` to instatiate a Component.

78 lines (77 loc) 2.92 kB
try { let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack; n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "e663c721-d338-4ddf-9171-ade083a0030f", e._sentryDebugIdIdentifier = "sentry-dbid-e663c721-d338-4ddf-9171-ade083a0030f"); } catch (e) {} import { c as entriesOf } from "./AnalyticsContext-BFrJmsp0.js"; //#region src/hooks/formUtils.ts /** * Creates a new object with specified keys omitted. * * @param obj - The source object * @param omit - Array of keys to omit from the result * @returns A new object without the omitted keys */ var omitKeys = (obj, omit) => { const filtered = { ...obj }; for (const key of omit) delete filtered[key]; return filtered; }; /** * Adds keys to an object with values resolved from multiple sources. * Priority: existing value > pendingData > defaultData > initialValue * * @param obj - The base object to extend * @param add - Array of keys to add * @param initialValue - Fallback value if no other source has the key * @param defaultData - Default values for keys * @param pendingData - Pending values (highest priority after existing) * @returns A new object with the added keys */ var addKeys = (obj, add, initialValue, defaultData, pendingData) => { const extended = { ...obj }; for (const key of add) if (!(key in extended) || extended[key] === void 0) extended[key] = pendingData?.[key] ?? defaultData?.[key] ?? initialValue; return extended; }; /** * @description Extracts the field schema data from the form schema using the field component * * @param formData The data of the form using the field component * @param fieldKeys The keys in the field schema * @returns An object containing only the field schemas form data */ function getDataByFields(formData, fieldKeys) { return entriesOf(formData).reduce((acc, [key, val]) => { if (fieldKeys.includes(key)) return { ...acc, [key]: val }; return acc; }, {}); } //#endregion //#region src/utils/validation/validationResult.ts var ValidationResult = class { validationResults; constructor(results) { this.validationResults = results; } /** Checks if all validation rules have passed */ get isValid() { return this.validationResults.reduce((acc, result) => acc && result.isValid, true); } /** Checks if any validation rule returned an error */ hasError() { return Boolean(this.getError()); } /** Returns the first validation result that returned an error */ getError() { return this.validationResults.find((result) => result.hasError); } /** Used to add async validation results to the static validation result*/ addError(result) { this.validationResults.push(result); return this.validationResults; } }; //#endregion export { omitKeys as i, addKeys as n, getDataByFields as r, ValidationResult as t };