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.

139 lines (138 loc) 5.72 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] = "5838a551-4905-48c7-8605-530d25594a10", e._sentryDebugIdIdentifier = "sentry-dbid-5838a551-4905-48c7-8605-530d25594a10"); } catch (e) {} import { o as createLogger } from "./translation-BFxyJ1c5.js"; import { t as CountryCodes } from "./country-code-CX5KqMBr.js"; import { t as useScenarios } from "./useScenarios-BxrbVsQp.js"; import { useEffect, useMemo, useState } from "preact/hooks"; import { signal } from "@preact/signals"; //#region src/core/error.ts var AdyenKycSdkError = class extends Error { sourceError; constructor(message, sourceError) { super(message); this.name = this.constructor.name; this.sourceError = sourceError; const stack = []; if (sourceError) { if (sourceError instanceof this.constructor) stack.push(`${this.name}: ${sourceError.message}`); if (sourceError.stack) stack.push(sourceError.stack); } this.stack = stack.join("\n"); } }; //#endregion //#region src/components/BankAccount/forms/PayoutAccount/payoutAccountFormat.ts var payoutAccountFormat = signal("local"); //#endregion //#region src/components/BankAccount/utils/defaultPayoutAccountFormat.ts var defaultPayoutAccountFormat = { [CountryCodes.CzechRepublic]: "iban", [CountryCodes.Denmark]: "local", [CountryCodes.Hungary]: "iban", [CountryCodes.Norway]: "local", [CountryCodes.Poland]: "local", [CountryCodes.Sweden]: "local", [CountryCodes.UnitedKingdom]: "local" }; //#endregion //#region src/hooks/useUnifyLoadingStatus.ts var useUnifyLoadingStatus = (setParentLoadingStatus, ...childLoadingStatuses) => { useEffect(() => { setParentLoadingStatus(childLoadingStatuses.some((status) => status === "loading" || status === "pending") ? "loading" : "success"); }, [...childLoadingStatuses]); }; //#endregion //#region src/hooks/useScenarioConfiguration.ts var logger = createLogger(); var useScenarioConfiguration = ({ getPayoutAccountFormatData, parseConfiguration, country, legalEntityType, instantVerificationAvailable, setLoadingStatus, existingBankAccountFormat }) => { const accountFormat = payoutAccountFormat.value; const { data: scenarios, isLoading: scenariosIsLoading, isError: scenariosIsError } = useScenarios(country, legalEntityType); const [accountFormatResponse, setAccountFormatResponse] = useState(); const configurationLoadingStatus = useMemo(() => { if (scenariosIsLoading) return "loading"; if (scenariosIsError) return "error"; if (scenarios) return "success"; return "pending"; }, [ scenarios, scenariosIsError, scenariosIsLoading ]); const [payoutFormatLoadingStatus, setpayoutFormatLoadingStatus] = useState("success"); useUnifyLoadingStatus(setLoadingStatus, configurationLoadingStatus, payoutFormatLoadingStatus); useEffect(() => { if (!getPayoutAccountFormatData) return; setpayoutFormatLoadingStatus("loading"); const makePayoutFormatCallAndSave = async () => { try { const response = await getPayoutAccountFormatData(); setAccountFormatResponse(response); const allowedBankAccountFormats = Object.keys(response); if (existingBankAccountFormat && !allowedBankAccountFormats.includes(existingBankAccountFormat)) throw new AdyenKycSdkError(`Account format, ${existingBankAccountFormat}, of transferInstrument is not in allowed formats for ${country}`); const defaultAccountFormat = defaultPayoutAccountFormat[country] ?? allowedBankAccountFormats[0]; payoutAccountFormat.value = existingBankAccountFormat ?? defaultAccountFormat; } catch (err) { logger.warn("WARNING: Payout format request failed - error:", err); } finally { setpayoutFormatLoadingStatus("success"); } }; makePayoutFormatCallAndSave().catch(logger.error); }, [ country, getPayoutAccountFormatData, setpayoutFormatLoadingStatus, existingBankAccountFormat ]); const { fieldConfigurations, requiredFields } = useMemo(() => { if (!scenarios) return {}; const payoutRequiredFields = accountFormatResponse ? accountFormatResponse[accountFormat] : void 0; return { fieldConfigurations: parseConfiguration(payoutRequiredFields ? { scenarios, country, requiredFields: payoutRequiredFields, bankVerificationAvailable: instantVerificationAvailable } : { scenarios, country, requiredFields: void 0, bankVerificationAvailable: void 0 }), requiredFields: payoutRequiredFields }; }, [ accountFormatResponse, accountFormat, scenarios, country, parseConfiguration, instantVerificationAvailable ]); return { requiredFields, fieldConfigurations }; }; //#endregion //#region src/utils/masking/transformers/uppercase.ts var uppercase = (str) => str?.toUpperCase() ?? str; //#endregion //#region src/utils/mapping/getPage.ts var getPage = ({ attachments }, pageType) => { if (!attachments) throw Error("Document has no attachments"); const attachment = pageType ? attachments.find((attach) => attach.pageType === pageType) : attachments[0]; if (!attachment) throw Error(`Attachment not found${pageType ? ` with type '${pageType}'` : ""}`); return attachment; }; var getPageName = (document, pageType) => getPage(document, pageType).pageName ?? ""; //#endregion //#region src/utils/mapping/mapExistingFile.ts var mapExistingFile = (name) => ({ name, existing: true }); //#endregion export { useScenarioConfiguration as a, AdyenKycSdkError as c, uppercase as i, getPage as n, useUnifyLoadingStatus as o, getPageName as r, payoutAccountFormat as s, mapExistingFile as t };