@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.
56 lines (55 loc) • 2.49 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] = "df90f599-251f-4c96-85fb-82add3617c94", e._sentryDebugIdIdentifier = "sentry-dbid-df90f599-251f-4c96-85fb-82add3617c94");
} catch (e) {}
import { n as httpGet, s as useApiContext } from "./http-D1NDkBxF.js";
import { u as entriesOf } from "./useAnalyticsContext-BVFDMrVE.js";
import { t as Scenarios } from "./get-scenarios-DnCVdYIC.js";
import { skipToken, useQuery } from "@tanstack/preact-query";
//#region src/api/configurations/useScenarios.ts
var getScenarios = async (legalEntityId, baseUrl, legalEntityType, countryCode) => {
return httpGet({
baseUrl,
path: `legalEntities/${legalEntityId}/configurations/scenarios?${new URLSearchParams({
countryCode,
legalEntityType
})}`
});
};
/**
* Based on country and capabilities the forms will be different. Since different combinations
* of country+capabilities often have the same result, we group them in scenarios.
*
* Note: this might not be the exact truth, and during the form completion
* some differences might arise, but it is true as a starting point.
*
* @param countryCode - need to be dynamic, might not match the legalEntityId's countryCode
* @param legalEntityType - needs to be dynamic, might not match the legalEntityId's legalEntityType
*/
var useScenarios = (countryCode, legalEntityType, options) => {
const { rootLegalEntityId, baseUrl } = useApiContext();
const result = useQuery({
queryKey: countryCode === skipToken ? [] : [
"scenarios",
legalEntityType,
countryCode
],
queryFn: countryCode === skipToken ? skipToken : () => getScenarios(rootLegalEntityId.value, baseUrl.value, legalEntityType, countryCode),
...options,
select: (response) => entriesOf(response).reduce((acc, [entityType, scenarios]) => {
acc[entityType] = scenarios ? sortScenarios(scenarios) : void 0;
return acc;
}, {})
});
return {
isLoading: result.isLoading,
isError: result.isError,
data: result.data?.[legalEntityType]
};
};
/**
* Sorts scenarios according to their order within the {@link Scenarios} const.
*/
var sortScenarios = (scenarios) => Object.values(Scenarios).reduce((acc, potential) => scenarios.includes(potential) ? [...acc, potential] : acc, []);
//#endregion
export { useScenarios as t };