@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.
49 lines (48 loc) • 2.04 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] = "24352a4c-5035-435a-a2fd-a591890694f8", e._sentryDebugIdIdentifier = "sentry-dbid-24352a4c-5035-435a-a2fd-a591890694f8");
} catch (e) {}
import { n as httpGet, s as useApiContext } from "./http-D1NDkBxF.js";
import { skipToken, useQueries, useQuery } from "@tanstack/preact-query";
//#region src/api/legalEntity/useLegalEntity.ts
var ROOT_LE = Symbol("ROOT_LE");
var getLegalEntity = async (rootLegalEntityId, baseUrl, legalEntityId) => {
return httpGet({
baseUrl,
path: `legalEntities/${legalEntityId === rootLegalEntityId ? rootLegalEntityId : `${rootLegalEntityId}/child/${legalEntityId}`}`
});
};
/**
* Retrieves a given legal entity.
*
* @param id can be:
* * a specific LE id
* * or `ROOT_LE` if you want the root LE without knowing its ID
* * or `skipToken` as a way to type-safely disable the query
*/
var useLegalEntity = (id, options) => {
const { rootLegalEntityId, baseUrl } = useApiContext();
const idToFetch = id === ROOT_LE ? rootLegalEntityId.value : id;
const enabled = id !== skipToken;
const result = useQuery({
queryKey: idToFetch === skipToken ? [] : ["legalEntity", idToFetch],
queryFn: idToFetch === skipToken ? skipToken : () => getLegalEntity(rootLegalEntityId.value, baseUrl.value, idToFetch),
...options
});
return {
refetch: result.refetch,
isLoading: result.isLoading,
isError: result.isError,
data: enabled ? result.data : void 0
};
};
var useLegalEntities = (ids, options) => {
const { rootLegalEntityId, baseUrl } = useApiContext();
return useQueries({ queries: ids.map((id) => ({
queryKey: ["legalEntity", id],
queryFn: () => getLegalEntity(rootLegalEntityId.value, baseUrl.value, id),
...options
})) });
};
//#endregion
export { useLegalEntities as n, useLegalEntity as r, ROOT_LE as t };