@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.
58 lines (57 loc) • 2.18 kB
JavaScript
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] = "c8992036-812a-4f93-b52a-38c68f12bf51", e._sentryDebugIdIdentifier = "sentry-dbid-c8992036-812a-4f93-b52a-38c68f12bf51");
} catch (e) {}
import { u as entriesOf } from "./useAnalyticsContext-BVFDMrVE.js";
//#region src/hooks/useForm/utils.ts
var omitKeys = (obj, omit) => Object.keys(obj).filter((k) => !omit.includes(k)).reduce((a, c) => {
a[c] = obj[c];
return a;
}, {});
var addKeys = (obj, add, initialValue, defaultData, pendingData) => add.reduce((a, c) => ({
...a,
[c]: a[c] ?? pendingData?.[c] ?? defaultData?.[c] ?? initialValue
}), obj);
/**
* @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 };