@adyen/kyc-components 2.6.2 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { useContext, useState, useCallback, useEffect, useMemo, useReducer, useLayoutEffect, useRef as useRef$1, useId as useId$1 } from "preact/hooks";
2
- import { createContext, createElement, Component, toChildArray, render } from "preact";
2
+ import { createContext, createElement, toChildArray, render } from "preact";
3
3
  import cx from "classnames";
4
4
  import { jsx, jsxs, Fragment } from "preact/jsx-runtime";
5
5
  import { useId, useRef, useMemo as useMemo$1, forwardRef, memo } from "preact/compat";
@@ -499,7 +499,7 @@ const createLogger = (namespace) => {
499
499
  });
500
500
  return methods;
501
501
  };
502
- const logger$i = createLogger("Link");
502
+ const logger$j = createLogger("Link");
503
503
  const getIconClass = (icon, external) => {
504
504
  if (external) {
505
505
  return "adl-link__icon adyen-kyc-icon-external-link";
@@ -511,7 +511,7 @@ const getIconClass = (icon, external) => {
511
511
  };
512
512
  const isValidLink = (href) => {
513
513
  if (href === "#") {
514
- logger$i.error('Links must include a valid href. If your href is "#", consider using a Button instead');
514
+ logger$j.error('Links must include a valid href. If your href is "#", consider using a Button instead');
515
515
  return false;
516
516
  }
517
517
  return true;
@@ -1104,7 +1104,7 @@ class ValidationResult {
1104
1104
  return this.validationResults.filter((result) => result.hasError);
1105
1105
  }
1106
1106
  }
1107
- const logger$h = createLogger("useAsyncValidator");
1107
+ const logger$i = createLogger("useAsyncValidator");
1108
1108
  const useAsyncValidator = (asyncRules) => {
1109
1109
  const [asyncValidationResults, setAsyncValidationResults] = useState({});
1110
1110
  const clearAsyncValidationResults = useCallback(() => setAsyncValidationResults({}), []);
@@ -1127,7 +1127,7 @@ const useAsyncValidator = (asyncRules) => {
1127
1127
  hasError: !isValid
1128
1128
  }])
1129
1129
  });
1130
- }).catch(logger$h.error);
1130
+ }).catch(logger$i.error);
1131
1131
  }, [asyncRules, clearAsyncValidationResults]);
1132
1132
  return {
1133
1133
  asyncValidationResults,
@@ -5146,7 +5146,7 @@ function datasetUtilities(locale) {
5146
5146
  getDatasetKey: (identifier) => createDatasetKey(identifier, locale)
5147
5147
  };
5148
5148
  }
5149
- const logger$g = createLogger("CountryField");
5149
+ const logger$h = createLogger("CountryField");
5150
5150
  function CountryField({
5151
5151
  allowedCountries = [],
5152
5152
  classNameModifiers = [],
@@ -5167,7 +5167,7 @@ function CountryField({
5167
5167
  dataset: countriesFromApi
5168
5168
  } = useDataset(datasetIdentifier.country);
5169
5169
  useEffect(() => {
5170
- loadFlags2().catch(logger$g.error);
5170
+ loadFlags2().catch(logger$h.error);
5171
5171
  }, [loadFlags2]);
5172
5172
  const countries = countriesFromApi.filter((country2) => allowedCountries.length ? allowedCountries.includes(country2.id) : true).map((item) => ({
5173
5173
  ...item,
@@ -6293,7 +6293,7 @@ const accountHolderValidationRules = {
6293
6293
  }
6294
6294
  };
6295
6295
  const accountHolderFields = ["accountHolder"];
6296
- const logger$f = createLogger("AccountHolder");
6296
+ const logger$g = createLogger("AccountHolder");
6297
6297
  function getAvailableAccountHolderOptions(legalEntityType, isChangeOfLegalEntityTypeAllowed, isTrustFlowEnabled, isSoleProprietorshipAllowed, isChangeToMyNameAllowed) {
6298
6298
  switch (legalEntityType) {
6299
6299
  case LegalEntityType.ORGANIZATION: {
@@ -6303,7 +6303,7 @@ function getAvailableAccountHolderOptions(legalEntityType, isChangeOfLegalEntity
6303
6303
  return [...isChangeToMyNameAllowed ? ["myName"] : [], ...isChangeOfLegalEntityTypeAllowed ? ["theCompanyIWorkFor"] : [], ...isTrustFlowEnabled ? ["aTrust"] : [], ...isSoleProprietorshipAllowed ? ["mySoleTraderName"] : []];
6304
6304
  }
6305
6305
  default:
6306
- logger$f.error(`No available account holder options for legal entity type '${legalEntityType}'`);
6306
+ logger$g.error(`No available account holder options for legal entity type '${legalEntityType}'`);
6307
6307
  return [];
6308
6308
  }
6309
6309
  }
@@ -6633,184 +6633,19 @@ const getDocumentGuidancePrefix = (documentType2, isIcon = false, isFront = true
6633
6633
  }
6634
6634
  };
6635
6635
  const _documentGuidance_component = "";
6636
- const getFontFaceRule = (fontFamily, fontStyle, fontWeight, fontSrc, additionalFormats) => {
6637
- const ruleLines = [`font-family: '${fontFamily}'`, `font-style: ${fontStyle}`, `font-weight: ${fontWeight}`, `src: url(${fontSrc})`];
6638
- const additionalSources = [];
6639
- if (additionalFormats.eot) {
6640
- additionalSources.push(`url(${additionalFormats.eot}) format('embedded-opentype')`);
6641
- }
6642
- if (additionalFormats.woff) {
6643
- additionalSources.push(`url(${additionalFormats.woff}) format('woff')`);
6644
- }
6645
- if (additionalFormats.woff2) {
6646
- additionalSources.push(`url(${additionalFormats.woff2}) format('woff2')`);
6647
- }
6648
- if (additionalFormats.ttf) {
6649
- additionalSources.push(`url(${additionalFormats.ttf}) format('truetype')`);
6650
- }
6651
- if (additionalFormats.otf) {
6652
- additionalSources.push(`url(${additionalFormats.otf}) format('opentype')`);
6653
- }
6654
- if (additionalSources.length > 0) {
6655
- ruleLines.push(`src: ${additionalSources.join(",")};`);
6656
- }
6657
- return `@font-face {${ruleLines.join(";")}}`;
6658
- };
6659
- const loadFont = (fontFamily, fontStyle, fontWeight, fontSrc, additionalFormats) => {
6660
- const style = document.createElement("style");
6661
- style.setAttribute("type", "text/css");
6662
- style.innerText = getFontFaceRule(fontFamily, fontStyle, fontWeight, fontSrc, additionalFormats);
6663
- document.body.insertBefore(style, document.body.firstChild);
6664
- };
6665
- const loadADLIconFont = (loadingContext) => {
6666
- const fontPath = `${loadingContext}static/fonts`;
6667
- const iconFontPath = `${fontPath}/adyen-kyc-icons`;
6668
- loadFont("adyen-kyc-icons", "normal", "normal", `${iconFontPath}.eot`, {
6669
- eot: `${iconFontPath}.eot`,
6670
- woff: `${iconFontPath}.woff`,
6671
- woff2: `${iconFontPath}.woff2`,
6672
- ttf: `${iconFontPath}.ttf`,
6673
- otf: `${iconFontPath}.otf`
6674
- });
6675
- };
6676
- const logger$e = createLogger("Fetch");
6677
- const getRequestObject = (options, data) => {
6678
- const {
6679
- headers = [],
6680
- method = "GET",
6681
- sdkToken
6682
- } = options;
6683
- let authHeaders;
6684
- if (options.sdkToken) {
6685
- authHeaders = {
6686
- Authorization: `Bearer ${sdkToken}`,
6687
- Origin: window.location.origin
6688
- };
6689
- }
6690
- return {
6691
- method,
6692
- mode: "cors",
6693
- cache: "default",
6694
- credentials: "same-origin",
6695
- headers: {
6696
- Accept: "application/json, text/plain, */*",
6697
- "Content-Type": method === "POST" ? "application/json" : "text/plain",
6698
- ...authHeaders,
6699
- ...headers
6700
- },
6701
- redirect: "follow",
6702
- referrerPolicy: "no-referrer-when-downgrade",
6703
- ...data && {
6704
- body: JSON.stringify(data)
6705
- }
6706
- };
6707
- };
6708
- const getRequestUrl = (loadingContext, path, clientKey) => {
6709
- let url = `${loadingContext}${path}`;
6710
- if (clientKey) {
6711
- url += `?clientKey=${clientKey}`;
6712
- }
6713
- return url;
6714
- };
6715
- const handleFetchError = (message, level) => {
6716
- switch (level) {
6717
- case "silent":
6718
- break;
6719
- case "info":
6720
- case "warn":
6721
- case "error":
6722
- return logger$e[level](message);
6723
- default:
6724
- throw new Error(message);
6725
- }
6726
- };
6727
- const handleFetchResponse = async (response, responseType) => {
6728
- switch (responseType) {
6729
- case "arraybuffer":
6730
- return response.arrayBuffer();
6731
- case "blob":
6732
- return response.blob();
6733
- case "json":
6734
- return response.json();
6735
- case "text":
6736
- return response.text();
6737
- }
6738
- };
6739
- const http = async (options, data, responseType = "json") => {
6740
- const {
6741
- errorLevel = "warn",
6742
- loadingContext = "",
6743
- path,
6744
- clientKey = ""
6745
- } = options;
6746
- const request = getRequestObject(options, data);
6747
- const url = getRequestUrl(loadingContext, path, clientKey);
6748
- return fetch(url, request).then((response) => {
6749
- if (response.ok)
6750
- return handleFetchResponse(response, responseType);
6751
- const errorMessage = options.errorMessage || `Service at ${url} is not available`;
6752
- if (options.errorHandler) {
6753
- return options.errorHandler(handleFetchResponse(response, responseType));
6754
- }
6755
- return handleFetchError(errorMessage, errorLevel);
6756
- }).catch((e) => {
6757
- const errorMessage = options.errorMessage || `Call to ${url} failed. Error= ${e}`;
6758
- return handleFetchError(errorMessage, errorLevel);
6759
- });
6760
- };
6761
- const httpGet = async (options, data) => http({
6762
- ...options,
6763
- method: "GET"
6764
- }, data);
6765
- const httpPost = async (options, data) => http({
6766
- ...options,
6767
- method: "POST"
6768
- }, data);
6769
- let isFlagsLoaded = false;
6770
- let isDocumentGuidanceLoaded = false;
6771
- const getIconContainer = () => {
6772
- const container = document.createElement("div");
6773
- container.setAttribute("aria-hidden", "true");
6774
- container.setAttribute("id", "adl-icon-container");
6775
- container.style.height = "0";
6776
- return container;
6777
- };
6778
- const buildSpriteDOMFromResponse = (responseData) => {
6779
- const iconContainer = getIconContainer();
6780
- iconContainer.innerHTML = responseData;
6781
- return iconContainer;
6782
- };
6783
- const loadFlags = async (loadingContext) => {
6784
- if (isFlagsLoaded)
6785
- return;
6786
- isFlagsLoaded = true;
6787
- const responseData = await http({
6788
- loadingContext,
6789
- path: "static/images/country-flags.svg"
6790
- }, null, "text");
6791
- document.body.insertBefore(buildSpriteDOMFromResponse(responseData), document.body.firstChild);
6792
- };
6793
- const loadDocumentGuidance = async (loadingContext) => {
6794
- if (isDocumentGuidanceLoaded)
6795
- return;
6796
- isDocumentGuidanceLoaded = true;
6797
- const responseData = await http({
6798
- loadingContext,
6799
- path: "static/images/document-guidance.svg"
6800
- }, null, "text");
6801
- document.body.insertBefore(buildSpriteDOMFromResponse(responseData), document.body.firstChild);
6802
- };
6803
6636
  function DocumentGuidance({
6804
6637
  type,
6805
6638
  className
6806
6639
  }) {
6807
6640
  const {
6808
- loadingContext,
6809
6641
  i18n
6810
6642
  } = useCoreContext();
6643
+ const {
6644
+ loadDocumentGuidance: loadDocumentGuidance2
6645
+ } = useConfigurationApi();
6811
6646
  const [guidancePrefix, setGuidancePrefix] = useState(null);
6812
6647
  useEffect(() => {
6813
- loadDocumentGuidance(loadingContext);
6648
+ loadDocumentGuidance2();
6814
6649
  }, []);
6815
6650
  useEffect(() => {
6816
6651
  setGuidancePrefix(getDocumentGuidancePrefix(type));
@@ -7198,7 +7033,7 @@ function Dropzone(props) {
7198
7033
  })]
7199
7034
  });
7200
7035
  }
7201
- const logger$d = createLogger("TextArea");
7036
+ const logger$f = createLogger("TextArea");
7202
7037
  function TextArea(props) {
7203
7038
  const {
7204
7039
  classNameModifiers,
@@ -7219,7 +7054,7 @@ function TextArea(props) {
7219
7054
  } = useCoreContext();
7220
7055
  const [value, setValue] = useState("");
7221
7056
  if (Object.prototype.hasOwnProperty.call(props, "onChange")) {
7222
- logger$d.error("Error: Form fields that rely on InputBase may not have an onChange property");
7057
+ logger$f.error("Error: Form fields that rely on InputBase may not have an onChange property");
7223
7058
  }
7224
7059
  const handleInput = (e) => {
7225
7060
  var _a;
@@ -7614,7 +7449,7 @@ function FieldContainer(props) {
7614
7449
  }
7615
7450
  return renderField(fieldName);
7616
7451
  }
7617
- const logger$c = createLogger("SearchAddress");
7452
+ const logger$e = createLogger("SearchAddress");
7618
7453
  const SearchAddress = ({
7619
7454
  data,
7620
7455
  legalEntityId,
@@ -7640,7 +7475,7 @@ const SearchAddress = ({
7640
7475
  const response = await handleFindAddress(selectedAddressId);
7641
7476
  autocompleteAddressForm(response);
7642
7477
  } catch (e) {
7643
- logger$c.error(e);
7478
+ logger$e.error(e);
7644
7479
  }
7645
7480
  };
7646
7481
  const onDrilldown = async (selectedAddress) => {
@@ -7652,7 +7487,7 @@ const SearchAddress = ({
7652
7487
  }, legalEntityId);
7653
7488
  setItems((response == null ? void 0 : response.results) || []);
7654
7489
  } catch (e) {
7655
- logger$c.error(e);
7490
+ logger$e.error(e);
7656
7491
  }
7657
7492
  };
7658
7493
  const onChange = (e) => {
@@ -7707,7 +7542,7 @@ const SearchAddress = ({
7707
7542
  setItems([]);
7708
7543
  }
7709
7544
  } catch (e) {
7710
- logger$c.error(e);
7545
+ logger$e.error(e);
7711
7546
  }
7712
7547
  setLoading(false);
7713
7548
  }
@@ -10859,7 +10694,7 @@ const initOnfido = async ({
10859
10694
  language: getOnfidoLocaleConfig(i18n)
10860
10695
  });
10861
10696
  };
10862
- const logger$b = createLogger("IdVerificationComponent");
10697
+ const logger$d = createLogger("IdVerificationComponent");
10863
10698
  function IdVerificationComponent({
10864
10699
  userDetails,
10865
10700
  handleGetIdVerificationToken,
@@ -10890,7 +10725,7 @@ function IdVerificationComponent({
10890
10725
  onIdVerificationError,
10891
10726
  onIdVerificationComplete
10892
10727
  });
10893
- })().catch(logger$b.error);
10728
+ })().catch(logger$d.error);
10894
10729
  return () => {
10895
10730
  if (onfidoSdk.current)
10896
10731
  onfidoSdk.current.tearDown();
@@ -10942,7 +10777,7 @@ function IdDocumentAlreadyUpload(props) {
10942
10777
  })]
10943
10778
  });
10944
10779
  }
10945
- const logger$a = createLogger("IdDocumentInstantVerificationComponent");
10780
+ const logger$c = createLogger("IdDocumentInstantVerificationComponent");
10946
10781
  const idVerificationSchema = ["instantIdVerificationData", "idDocumentType"];
10947
10782
  const documentTypeValidationRules = {
10948
10783
  instantIdVerificationData: {
@@ -11023,7 +10858,7 @@ function IdDocumentInstantVerificationComponent(props) {
11023
10858
  handleGetIdVerificationToken: props.handleGetIdVerificationToken,
11024
10859
  userDetails: props.userDetails,
11025
10860
  onIdVerificationComplete: handleIdVerificationComplete,
11026
- onIdVerificationError: logger$a.error
10861
+ onIdVerificationError: logger$c.error
11027
10862
  }), jsxs("div", {
11028
10863
  className: "adyen-kyc-document-upload__manual-upload",
11029
10864
  children: [i18n.get("canNotCompleteInstantVerification"), " ", jsx("button", {
@@ -11170,15 +11005,17 @@ const IdVerificationMethodOptionFooter = ({
11170
11005
  const idVerificationMethodFields = ["idVerificationMethod"];
11171
11006
  function IdVerificationMethodComponent(props) {
11172
11007
  const {
11173
- i18n,
11174
- loadingContext
11008
+ i18n
11175
11009
  } = useCoreContext();
11010
+ const {
11011
+ getImageUrl
11012
+ } = useConfigurationApi();
11176
11013
  const verificationMethodFormId = props.id;
11177
11014
  const schema = idVerificationMethodFields;
11178
11015
  const stateRef = useRef$1({
11179
11016
  setState: null
11180
11017
  });
11181
- const svgPath = `${loadingContext}static/images/id-verification-method`;
11018
+ const svgPath = `${getImageUrl()}id-verification-method`;
11182
11019
  const methodsMetadata = makeIdVerificationMethodsMetadata(svgPath);
11183
11020
  const {
11184
11021
  handleChangeFor,
@@ -13523,6 +13360,14 @@ const bankVerificationValidationRules = {
13523
13360
  }
13524
13361
  };
13525
13362
  const BankVerificationWidget$1 = "";
13363
+ const AuthContext = createContext(void 0);
13364
+ const useAuthContext = () => {
13365
+ const authContext = useContext(AuthContext);
13366
+ if (!authContext) {
13367
+ throw new Error("Cannot use authContext without <AuthProvider>");
13368
+ }
13369
+ return authContext;
13370
+ };
13526
13371
  class AdyenKycSdkError extends Error {
13527
13372
  constructor(message, sourceError) {
13528
13373
  super(message);
@@ -13550,6 +13395,99 @@ const removeAnimationStartListener = (element, listener) => {
13550
13395
  element.removeEventListener("MSAnimationStart", listener, false);
13551
13396
  element.removeEventListener("webkitAnimationStart", listener, false);
13552
13397
  };
13398
+ const logger$b = createLogger("Fetch");
13399
+ const getRequestObject = (options, data) => {
13400
+ const {
13401
+ headers = [],
13402
+ method = "GET",
13403
+ sdkToken
13404
+ } = options;
13405
+ let authHeaders;
13406
+ if (options.sdkToken) {
13407
+ authHeaders = {
13408
+ Authorization: `Bearer ${sdkToken}`,
13409
+ Origin: window.location.origin
13410
+ };
13411
+ }
13412
+ return {
13413
+ method,
13414
+ mode: "cors",
13415
+ cache: "default",
13416
+ credentials: "same-origin",
13417
+ headers: {
13418
+ Accept: "application/json, text/plain, */*",
13419
+ "Content-Type": method === "POST" ? "application/json" : "text/plain",
13420
+ ...authHeaders,
13421
+ ...headers
13422
+ },
13423
+ redirect: "follow",
13424
+ referrerPolicy: "no-referrer-when-downgrade",
13425
+ ...data && {
13426
+ body: JSON.stringify(data)
13427
+ }
13428
+ };
13429
+ };
13430
+ const getRequestUrl = (loadingContext, path, clientKey) => {
13431
+ let url = `${loadingContext}${path}`;
13432
+ if (clientKey) {
13433
+ url += `?clientKey=${clientKey}`;
13434
+ }
13435
+ return url;
13436
+ };
13437
+ const handleFetchError = (message, level) => {
13438
+ switch (level) {
13439
+ case "silent":
13440
+ break;
13441
+ case "info":
13442
+ case "warn":
13443
+ case "error":
13444
+ return logger$b[level](message);
13445
+ default:
13446
+ throw new Error(message);
13447
+ }
13448
+ };
13449
+ const handleFetchResponse = async (response, responseType) => {
13450
+ switch (responseType) {
13451
+ case "arraybuffer":
13452
+ return response.arrayBuffer();
13453
+ case "blob":
13454
+ return response.blob();
13455
+ case "json":
13456
+ return response.json();
13457
+ case "text":
13458
+ return response.text();
13459
+ }
13460
+ };
13461
+ const http = async (options, data, responseType = "json") => {
13462
+ const {
13463
+ errorLevel = "warn",
13464
+ loadingContext = "",
13465
+ path,
13466
+ clientKey = ""
13467
+ } = options;
13468
+ const request = getRequestObject(options, data);
13469
+ const url = getRequestUrl(loadingContext, path, clientKey);
13470
+ return fetch(url, request).then((response) => {
13471
+ if (response.ok)
13472
+ return handleFetchResponse(response, responseType);
13473
+ const errorMessage = options.errorMessage || `Service at ${url} is not available`;
13474
+ if (options.errorHandler) {
13475
+ return options.errorHandler(handleFetchResponse(response, responseType));
13476
+ }
13477
+ return handleFetchError(errorMessage, errorLevel);
13478
+ }).catch((e) => {
13479
+ const errorMessage = options.errorMessage || `Call to ${url} failed. Error= ${e}`;
13480
+ return handleFetchError(errorMessage, errorLevel);
13481
+ });
13482
+ };
13483
+ const httpGet = async (options, data) => http({
13484
+ ...options,
13485
+ method: "GET"
13486
+ }, data);
13487
+ const httpPost = async (options, data) => http({
13488
+ ...options,
13489
+ method: "POST"
13490
+ }, data);
13553
13491
  const removeElementSiblings = (element) => {
13554
13492
  const parent = element.parentNode;
13555
13493
  let child = parent.firstChild;
@@ -13563,7 +13501,7 @@ const RELEVANT_MESSAGE_TYPES = ["account_verification_report_id", "error"];
13563
13501
  const TERMINAL_DATA_PROPS = ["accounts", "error", "reference"];
13564
13502
  const MOUNT_TIMEOUT = 10 * 1e3;
13565
13503
  const TINK_VENDOR = "Tink";
13566
- const logger$9 = createLogger("iframeWidget");
13504
+ const logger$a = createLogger("iframeWidget");
13567
13505
  const isObjectData = (data) => typeof data === "object" && !Array.isArray(data) && data !== null;
13568
13506
  const isTerminalMessageData = (data) => Object.entries(data).some(([prop]) => TERMINAL_DATA_PROPS.includes(prop));
13569
13507
  const parseMessageJson = (message) => {
@@ -13582,7 +13520,7 @@ const callbackErrorHandler = async (response) => {
13582
13520
  try {
13583
13521
  await response;
13584
13522
  } catch (ex) {
13585
- logger$9.error(ex);
13523
+ logger$a.error(ex);
13586
13524
  }
13587
13525
  return {
13588
13526
  error: "UNKNOWN_ERROR",
@@ -13591,7 +13529,7 @@ const callbackErrorHandler = async (response) => {
13591
13529
  };
13592
13530
  let activeWidget;
13593
13531
  class IFrameWidget {
13594
- constructor(iframeElement, url, vendor) {
13532
+ constructor(iframeElement, url, vendor, sdkToken) {
13595
13533
  this.mountInProgress = false;
13596
13534
  this.waitForResponse = async () => new Promise((resolve, reject) => {
13597
13535
  this.listener = async (message) => {
@@ -13614,6 +13552,7 @@ class IFrameWidget {
13614
13552
  this.iframeElement = iframeElement;
13615
13553
  this.iframeWindow = iframeElement.contentWindow;
13616
13554
  this.vendor = vendor;
13555
+ this.sdkToken = sdkToken;
13617
13556
  }
13618
13557
  removeMessageEventListener() {
13619
13558
  if (!this.listener)
@@ -13642,7 +13581,8 @@ class IFrameWidget {
13642
13581
  const httpOptions = {
13643
13582
  errorHandler: callbackErrorHandler,
13644
13583
  errorLevel: null,
13645
- loadingContext: ""
13584
+ loadingContext: "",
13585
+ sdkToken: this.sdkToken
13646
13586
  };
13647
13587
  const redirectUrl = new URL(this.iframeUrl.searchParams.get("redirect_uri"));
13648
13588
  const redirectQueryParams = redirectUrl.searchParams;
@@ -13686,7 +13626,7 @@ class IFrameWidget {
13686
13626
  message = responseData.errorMessage;
13687
13627
  }
13688
13628
  } catch (ex) {
13689
- logger$9.error(ex);
13629
+ logger$a.error(ex);
13690
13630
  }
13691
13631
  throw new AdyenKycSdkError(message);
13692
13632
  }
@@ -13762,6 +13702,8 @@ function BankVerificationWidget({
13762
13702
  widgetCallback
13763
13703
  }) {
13764
13704
  const widgetContainerRef = useRef$1(null);
13705
+ const context = useAuthContext();
13706
+ const sdkToken = context.isEmbeddedDropin ? context.sdkToken : void 0;
13765
13707
  useEffect(
13766
13708
  () => {
13767
13709
  const container = widgetContainerRef.current;
@@ -13776,7 +13718,7 @@ function BankVerificationWidget({
13776
13718
  evt.target.appendChild(iFrame);
13777
13719
  requestAnimationFrame(async () => {
13778
13720
  try {
13779
- iFrameWidget = new IFrameWidget(iFrame, url, vendor);
13721
+ iFrameWidget = new IFrameWidget(iFrame, url, vendor, sdkToken);
13780
13722
  const result = await iFrameWidget.mountAndWaitForResponse();
13781
13723
  widgetCallback({
13782
13724
  action: "verification_success",
@@ -13824,7 +13766,7 @@ function BankVerificationWidget({
13824
13766
  ref: widgetContainerRef
13825
13767
  });
13826
13768
  }
13827
- const logger$8 = createLogger("BankVerification");
13769
+ const logger$9 = createLogger("BankVerification");
13828
13770
  const accountVerificationFields = ["verifiedAccountHolder", "verifiedBankCountry", "verifiedBankName", "verifiedCurrencyCode", "verifiedBankAccountNumber"];
13829
13771
  const InstantVerificationErrorContext = createContext(null);
13830
13772
  const useInstantVerificationErrorNotification = (notificationVisibilityDuration) => {
@@ -13858,7 +13800,7 @@ const usePreferredVendorForCountry = (country2, getBankVerificationVendors) => {
13858
13800
  const preferredVendor2 = vendors[0];
13859
13801
  setPreferredVendor(preferredVendor2.name ? preferredVendor2 : null);
13860
13802
  };
13861
- getPreferredVendor().catch(logger$8.error);
13803
+ getPreferredVendor().catch(logger$9.error);
13862
13804
  }, [country2, getBankVerificationVendors]);
13863
13805
  return preferredVendor;
13864
13806
  };
@@ -15323,9 +15265,11 @@ const getInstantVerificationProvider = (bankVerificationProviders, bankCountry2)
15323
15265
  function PayoutVerificationMethod(props) {
15324
15266
  var _a;
15325
15267
  const {
15326
- i18n,
15327
- loadingContext
15268
+ i18n
15328
15269
  } = useCoreContext();
15270
+ const {
15271
+ getImageUrl
15272
+ } = useConfigurationApi();
15329
15273
  const instantVerificationError = useContext(InstantVerificationErrorContext);
15330
15274
  const {
15331
15275
  isSettingEnabled
@@ -15364,7 +15308,7 @@ function PayoutVerificationMethod(props) {
15364
15308
  }), [data, errors, fieldProblems, valid]);
15365
15309
  const providerName = getInstantVerificationProvider(props.bankVerificationVendors, data.bankCountry);
15366
15310
  const instantVerificationAvailable = Boolean(props.instantVerificationAllowed && providerName && providerName !== "loading");
15367
- const svgPath = `${loadingContext}static/images/payout-verification-method`;
15311
+ const svgPath = `${getImageUrl()}payout-verification-method`;
15368
15312
  const methodsMetadata = makePayoutVerificationMethodsMetadata(svgPath, providerName === "loading" ? void 0 : providerName);
15369
15313
  useEffect(() => {
15370
15314
  if (!hasSelectedMethod && instantVerificationAvailable && data.payoutVerificationMethod !== "instantVerification") {
@@ -17025,7 +16969,7 @@ const defaultPayoutAccountFormat = {
17025
16969
  [CountryCodes.Sweden]: "local",
17026
16970
  [CountryCodes.UnitedKingdom]: "local"
17027
16971
  };
17028
- const logger$7 = createLogger("useScenarioConfiguration");
16972
+ const logger$8 = createLogger("useScenarioConfiguration");
17029
16973
  const useScenarioConfiguration = ({
17030
16974
  getConfigurationData,
17031
16975
  getPayoutAccountFormatData,
@@ -17047,12 +16991,12 @@ const useScenarioConfiguration = ({
17047
16991
  const configurationResponse2 = await getConfigurationData();
17048
16992
  setConfigurationResponse(configurationResponse2);
17049
16993
  } catch (err) {
17050
- logger$7.warn("WARNING: Configuration request failed - error:", err);
16994
+ logger$8.warn("WARNING: Configuration request failed - error:", err);
17051
16995
  } finally {
17052
16996
  setLoadingStatus("success");
17053
16997
  }
17054
16998
  };
17055
- makeConfigCallAndSave().catch(logger$7.error);
16999
+ makeConfigCallAndSave().catch(logger$8.error);
17056
17000
  }, [getConfigurationData, setLoadingStatus]);
17057
17001
  useEffect(() => {
17058
17002
  setLoadingStatus("loading");
@@ -17068,12 +17012,12 @@ const useScenarioConfiguration = ({
17068
17012
  const defaultAccountFormat = defaultPayoutAccountFormat[country2] ?? allowedBankAccountFormats[0];
17069
17013
  setAccountFormat(defaultAccountFormat);
17070
17014
  } catch (err) {
17071
- logger$7.warn("WARNING: Payout format request failed - error:", err);
17015
+ logger$8.warn("WARNING: Payout format request failed - error:", err);
17072
17016
  } finally {
17073
17017
  setLoadingStatus("success");
17074
17018
  }
17075
17019
  };
17076
- makePayoutFormatCallAndSave().catch(logger$7.error);
17020
+ makePayoutFormatCallAndSave().catch(logger$8.error);
17077
17021
  }, [country2, setAccountFormat, getPayoutAccountFormatData, setLoadingStatus]);
17078
17022
  const {
17079
17023
  fieldConfigurations,
@@ -17702,7 +17646,7 @@ var ToastType = /* @__PURE__ */ ((ToastType2) => {
17702
17646
  return ToastType2;
17703
17647
  })(ToastType || {});
17704
17648
  const FormComposer = "";
17705
- const logger$6 = createLogger("FormRouterContextProvider");
17649
+ const logger$7 = createLogger("FormRouterContextProvider");
17706
17650
  function FormRouterContextProvider({
17707
17651
  children,
17708
17652
  forms,
@@ -17722,7 +17666,7 @@ function FormRouterContextProvider({
17722
17666
  if (formIndex > -1) {
17723
17667
  setFormIndex(formIndex);
17724
17668
  } else {
17725
- logger$6.error("No form was found to have that field so form navigation failed.");
17669
+ logger$7.error("No form was found to have that field so form navigation failed.");
17726
17670
  }
17727
17671
  }
17728
17672
  }), [forms, handleGetIdVerificationToken, setFormIndex]);
@@ -18317,7 +18261,7 @@ function CompanyDropinComponent({
18317
18261
  })
18318
18262
  });
18319
18263
  }
18320
- const logger$5 = createLogger("useExemptSettlor");
18264
+ const logger$6 = createLogger("useExemptSettlor");
18321
18265
  const useExemptSettlor = ({
18322
18266
  trust,
18323
18267
  handleGetLegalEntity
@@ -18329,7 +18273,7 @@ const useExemptSettlor = ({
18329
18273
  setExemptSettlor(exemptSettlorLE);
18330
18274
  }, [handleGetLegalEntity]);
18331
18275
  useEffect(() => {
18332
- updateExemptSettlor(trust).catch(logger$5.error);
18276
+ updateExemptSettlor(trust).catch(logger$6.error);
18333
18277
  }, [trust, updateExemptSettlor]);
18334
18278
  return exemptSettlor;
18335
18279
  };
@@ -20762,11 +20706,16 @@ function PayoutDetailsDropinComponent({
20762
20706
  } = useStateContext();
20763
20707
  const formValidity = currentState.validityByForm;
20764
20708
  useEffect(() => {
20765
- var _a2, _b2;
20709
+ var _a2, _b2, _c2, _d;
20710
+ const currentCountry = ((_b2 = (_a2 = currentState == null ? void 0 : currentState.data) == null ? void 0 : _a2.payoutVerificationMethod) == null ? void 0 : _b2.bankCountry) ?? defaultPayoutCountry;
20766
20711
  setData({
20767
- ...currentState.data
20712
+ ...currentState.data,
20713
+ payoutAccountDetails: {
20714
+ ...(_c2 = currentState.data) == null ? void 0 : _c2.payoutAccountDetails,
20715
+ currency: (_d = currencyByCountry[currentCountry]) == null ? void 0 : _d[0]
20716
+ }
20768
20717
  });
20769
- setBankAccountCountry(((_b2 = (_a2 = currentState == null ? void 0 : currentState.data) == null ? void 0 : _a2.payoutVerificationMethod) == null ? void 0 : _b2.bankCountry) ?? defaultPayoutCountry);
20718
+ setBankAccountCountry(currentCountry);
20770
20719
  onChange == null ? void 0 : onChange(currentState);
20771
20720
  }, [currentState, onChange]);
20772
20721
  const forms = useMemo(() => {
@@ -21265,8 +21214,8 @@ function ContentElements({
21265
21214
  }
21266
21215
  };
21267
21216
  const elements = contentElements.map((contentElement) => {
21268
- const Component2 = components[contentElement.type];
21269
- return jsx(Component2, {
21217
+ const Component = components[contentElement.type];
21218
+ return jsx(Component, {
21270
21219
  ...getProps(contentElement)
21271
21220
  }, getKey(contentElement.type));
21272
21221
  });
@@ -21980,7 +21929,7 @@ const serviceAgreementValidationRules = {
21980
21929
  errorMessage: "fieldIsRequired"
21981
21930
  }
21982
21931
  };
21983
- const logger$4 = createLogger("useServiceAgreement");
21932
+ const logger$5 = createLogger("useServiceAgreement");
21984
21933
  const FALLBACK_LANGUAGE_CODE = "en";
21985
21934
  const useServiceAgreement = ({
21986
21935
  handleGetServiceAgreement,
@@ -22009,7 +21958,7 @@ const useServiceAgreement = ({
22009
21958
  language: agreementLanguage
22010
21959
  });
22011
21960
  if (!document2) {
22012
- logger$4.log('"document" field was missing in response');
21961
+ logger$5.log('"document" field was missing in response');
22013
21962
  return;
22014
21963
  }
22015
21964
  const contract = JSON.parse(decodeURIComponent(escape(window.atob(document2))));
@@ -22027,7 +21976,7 @@ const useServiceAgreement = ({
22027
21976
  throw err;
22028
21977
  }
22029
21978
  };
22030
- requestServiceAgreement().catch(logger$4.error);
21979
+ requestServiceAgreement().catch(logger$5.error);
22031
21980
  }, [handleGetServiceAgreement, handleServiceAgreementIsNotAvailableInThatLanguage, agreementLanguage, legalEntityId, serviceAgreementType]);
22032
21981
  return {
22033
21982
  loading: loading2,
@@ -22461,6 +22410,80 @@ const labels = (data, country2) => ({
22461
22410
  }
22462
22411
  }
22463
22412
  });
22413
+ const getFontFaceRule = (fontFamily, fontStyle, fontWeight, fontSrc, additionalFormats) => {
22414
+ const ruleLines = [`font-family: '${fontFamily}'`, `font-style: ${fontStyle}`, `font-weight: ${fontWeight}`, `src: url(${fontSrc})`];
22415
+ const additionalSources = [];
22416
+ if (additionalFormats.eot) {
22417
+ additionalSources.push(`url(${additionalFormats.eot}) format('embedded-opentype')`);
22418
+ }
22419
+ if (additionalFormats.woff) {
22420
+ additionalSources.push(`url(${additionalFormats.woff}) format('woff')`);
22421
+ }
22422
+ if (additionalFormats.woff2) {
22423
+ additionalSources.push(`url(${additionalFormats.woff2}) format('woff2')`);
22424
+ }
22425
+ if (additionalFormats.ttf) {
22426
+ additionalSources.push(`url(${additionalFormats.ttf}) format('truetype')`);
22427
+ }
22428
+ if (additionalFormats.otf) {
22429
+ additionalSources.push(`url(${additionalFormats.otf}) format('opentype')`);
22430
+ }
22431
+ if (additionalSources.length > 0) {
22432
+ ruleLines.push(`src: ${additionalSources.join(",")};`);
22433
+ }
22434
+ return `@font-face {${ruleLines.join(";")}}`;
22435
+ };
22436
+ const loadFont = (fontFamily, fontStyle, fontWeight, fontSrc, additionalFormats) => {
22437
+ const style = document.createElement("style");
22438
+ style.setAttribute("type", "text/css");
22439
+ style.innerText = getFontFaceRule(fontFamily, fontStyle, fontWeight, fontSrc, additionalFormats);
22440
+ document.body.insertBefore(style, document.body.firstChild);
22441
+ };
22442
+ const loadADLIconFont = (loadingContext) => {
22443
+ const fontPath = `${loadingContext}static/fonts`;
22444
+ const iconFontPath = `${fontPath}/adyen-kyc-icons`;
22445
+ loadFont("adyen-kyc-icons", "normal", "normal", `${iconFontPath}.eot`, {
22446
+ eot: `${iconFontPath}.eot`,
22447
+ woff: `${iconFontPath}.woff`,
22448
+ woff2: `${iconFontPath}.woff2`,
22449
+ ttf: `${iconFontPath}.ttf`,
22450
+ otf: `${iconFontPath}.otf`
22451
+ });
22452
+ };
22453
+ let isFlagsLoaded = false;
22454
+ let isDocumentGuidanceLoaded = false;
22455
+ const getIconContainer = () => {
22456
+ const container = document.createElement("div");
22457
+ container.setAttribute("aria-hidden", "true");
22458
+ container.setAttribute("id", "adl-icon-container");
22459
+ container.style.height = "0";
22460
+ return container;
22461
+ };
22462
+ const buildSpriteDOMFromResponse = (responseData) => {
22463
+ const iconContainer = getIconContainer();
22464
+ iconContainer.innerHTML = responseData;
22465
+ return iconContainer;
22466
+ };
22467
+ const loadFlags = async (loadingContext) => {
22468
+ if (isFlagsLoaded)
22469
+ return;
22470
+ isFlagsLoaded = true;
22471
+ const responseData = await http({
22472
+ loadingContext,
22473
+ path: "static/images/country-flags.svg"
22474
+ }, null, "text");
22475
+ document.body.insertBefore(buildSpriteDOMFromResponse(responseData), document.body.firstChild);
22476
+ };
22477
+ const loadDocumentGuidance = async (loadingContext) => {
22478
+ if (isDocumentGuidanceLoaded)
22479
+ return;
22480
+ isDocumentGuidanceLoaded = true;
22481
+ const responseData = await http({
22482
+ loadingContext,
22483
+ path: "static/images/document-guidance.svg"
22484
+ }, null, "text");
22485
+ document.body.insertBefore(buildSpriteDOMFromResponse(responseData), document.body.firstChild);
22486
+ };
22464
22487
  const getOpeningStep = (forms, remediationActions) => {
22465
22488
  var _a;
22466
22489
  if (remediationActions && Object.keys(remediationActions).length > 0) {
@@ -22492,11 +22515,13 @@ function withFormComposer(WrappedComponent, {
22492
22515
  var _a, _b, _c;
22493
22516
  const {
22494
22517
  i18n,
22495
- loadingContext,
22496
22518
  contextCountry: initialContextCountry,
22497
22519
  setContextCountry: setInitialContextCountry,
22498
22520
  isReview
22499
22521
  } = useCoreContext();
22522
+ const {
22523
+ loadingContext
22524
+ } = useAuthContext();
22500
22525
  const {
22501
22526
  getConfiguration: getConfiguration2,
22502
22527
  getPayoutAccountFormat: getPayoutAccountFormat2
@@ -23270,7 +23295,7 @@ function TrustDropinComponent(props) {
23270
23295
  }
23271
23296
  const PAGES_WITH_STATUS = [TaskTypes.DECISION_MAKER_OVERVIEW, TaskTypes.TASKS_OVERVIEW];
23272
23297
  const POLLING_INTERVAL = 3e3;
23273
- const logger$3 = createLogger("DropinComposerComponent");
23298
+ const logger$4 = createLogger("DropinComposerComponent");
23274
23299
  function DropinComposerComponent({
23275
23300
  capabilities,
23276
23301
  legalEntityResponse,
@@ -23338,7 +23363,7 @@ function DropinComposerComponent({
23338
23363
  setPciStatus(response);
23339
23364
  return response;
23340
23365
  } catch (e) {
23341
- logger$3.warn(i18n.get("failedToGetPciStatus"));
23366
+ logger$4.warn(i18n.get("failedToGetPciStatus"));
23342
23367
  }
23343
23368
  }
23344
23369
  return void 0;
@@ -23369,7 +23394,7 @@ function DropinComposerComponent({
23369
23394
  const response = await args.handleGetServiceAgreementAcceptanceInfos(legalEntity.id);
23370
23395
  setServiceAgreementAcceptanceInfos(response.data);
23371
23396
  } catch (e) {
23372
- logger$3.warn(i18n.get("failedToGetServiceAgreementStatus"));
23397
+ logger$4.warn(i18n.get("failedToGetServiceAgreementStatus"));
23373
23398
  }
23374
23399
  }
23375
23400
  };
@@ -23379,7 +23404,7 @@ function DropinComposerComponent({
23379
23404
  const response = await args.handleGetServiceAgreementStatus(legalEntity.id);
23380
23405
  setServiceAgreementTypes(response.termsOfServiceTypes);
23381
23406
  } catch (e) {
23382
- logger$3.warn(i18n.get("failedToGetServiceAgreementStatus"));
23407
+ logger$4.warn(i18n.get("failedToGetServiceAgreementStatus"));
23383
23408
  }
23384
23409
  }
23385
23410
  };
@@ -23418,7 +23443,7 @@ function DropinComposerComponent({
23418
23443
  setCapabilityProblems(getCapabilityProblems(response));
23419
23444
  return response;
23420
23445
  } catch (e) {
23421
- logger$3.warn(i18n.get("failedToFetchLegalEntityDetails"));
23446
+ logger$4.warn(i18n.get("failedToFetchLegalEntityDetails"));
23422
23447
  }
23423
23448
  }
23424
23449
  return void 0;
@@ -23430,7 +23455,7 @@ function DropinComposerComponent({
23430
23455
  setTrust(response);
23431
23456
  return response;
23432
23457
  } catch (e) {
23433
- logger$3.warn(i18n.get("failedToFetchTrustDetails"));
23458
+ logger$4.warn(i18n.get("failedToFetchTrustDetails"));
23434
23459
  }
23435
23460
  }
23436
23461
  return void 0;
@@ -23480,7 +23505,7 @@ function DropinComposerComponent({
23480
23505
  label: i18n.get("successFullyRemovedTrustMember")
23481
23506
  });
23482
23507
  } catch (err) {
23483
- logger$3.error(`Failed to delete trust member`, err);
23508
+ logger$4.error(`Failed to delete trust member`, err);
23484
23509
  showToast({
23485
23510
  type: ToastType.ERROR,
23486
23511
  label: i18n.get("failedToRemoveTrustMember")
@@ -23532,7 +23557,7 @@ function DropinComposerComponent({
23532
23557
  break;
23533
23558
  case "rootTrustee":
23534
23559
  default:
23535
- logger$3.warn(`Updating trust member type "${trustMember.trustMemberType}" is not implemented.`);
23560
+ logger$4.warn(`Updating trust member type "${trustMember.trustMemberType}" is not implemented.`);
23536
23561
  }
23537
23562
  showToast({
23538
23563
  label: i18n.get("successfullyUpdatedDetails"),
@@ -23540,7 +23565,7 @@ function DropinComposerComponent({
23540
23565
  });
23541
23566
  await refreshTrustAndRunOnSubmit(trust, 1);
23542
23567
  } catch (err) {
23543
- logger$3.error(err);
23568
+ logger$4.error(err);
23544
23569
  showToast({
23545
23570
  label: i18n.get("failedToUpdateDetails"),
23546
23571
  type: ToastType.ERROR
@@ -23763,7 +23788,7 @@ function DropinComposerComponent({
23763
23788
  }
23764
23789
  };
23765
23790
  setIsLoadingConfiguration(true);
23766
- fetchConfiguration().catch(logger$3.error).finally(() => {
23791
+ fetchConfiguration().catch(logger$4.error).finally(() => {
23767
23792
  setIsLoadingConfiguration(false);
23768
23793
  onLoad();
23769
23794
  });
@@ -24330,6 +24355,38 @@ const updateTransferInstrument = async (context, transferInstrument, transferIns
24330
24355
  }, transferInstrument);
24331
24356
  };
24332
24357
  const COMPONENTS_API_VERSION = "v1";
24358
+ const useComponentApi = (rootLegalEntityId) => {
24359
+ const authContext = useAuthContext();
24360
+ if (!authContext.isEmbeddedDropin) {
24361
+ throw new Error("Cannot use component API outside an embedded dropin");
24362
+ }
24363
+ const {
24364
+ sdkToken,
24365
+ loadingContext: base
24366
+ } = authContext;
24367
+ return useMemo(() => {
24368
+ const loadingContext = `${base}api/${COMPONENTS_API_VERSION}/`;
24369
+ const loadingContextWithRootLEAuth = `${loadingContext}legalEntities/`;
24370
+ const baseRequestContext = {
24371
+ loadingContext: loadingContextWithRootLEAuth,
24372
+ legalEntityId: rootLegalEntityId,
24373
+ sdkToken
24374
+ };
24375
+ return {
24376
+ getLegalEntity: async (legalEntityId) => getLegalEntity({
24377
+ ...baseRequestContext,
24378
+ legalEntityId
24379
+ }),
24380
+ getTransferInstrument: async (transferInstrumentId) => getTransferInstrument(baseRequestContext, transferInstrumentId),
24381
+ getBankVerificationVendor: async (country2) => getBankVerificationVendor(baseRequestContext, country2),
24382
+ getDocument: async (documentId) => getDocument(baseRequestContext, documentId),
24383
+ createDocument: async (document2, ownerId) => createDocument(baseRequestContext, document2, ownerId),
24384
+ updateDocument: async (document2, documentId, ownerId) => updateDocument(baseRequestContext, document2, documentId, ownerId),
24385
+ createTransferInstrument: async (transferInstrument) => createTransferInstrument(baseRequestContext, transferInstrument),
24386
+ updateTransferInstrument: async (transferInstrument, transferInstrumentId) => updateTransferInstrument(baseRequestContext, transferInstrument, transferInstrumentId)
24387
+ };
24388
+ }, [base, rootLegalEntityId, sdkToken]);
24389
+ };
24333
24390
  const getEmbeddedApi = ({
24334
24391
  base,
24335
24392
  sdkToken,
@@ -24362,6 +24419,7 @@ const getEmbeddedApi = ({
24362
24419
  }, datasetIdentifier2, locale),
24363
24420
  loadFlags: async () => loadFlags(base),
24364
24421
  loadDocumentGuidance: async () => loadDocumentGuidance(base),
24422
+ getImageUrl: () => `${base}static/images/`,
24365
24423
  getAllowedCountries: () => {
24366
24424
  throw new Error("getAllowedCountries: Not implemented in onboarding component api");
24367
24425
  },
@@ -24467,7 +24525,7 @@ const validatePhoneNumber = async (context, phoneNumber2) => {
24467
24525
  number: phoneNumber2
24468
24526
  });
24469
24527
  };
24470
- const logger$2 = createLogger("verify-id-number");
24528
+ const logger$3 = createLogger("verify-id-number");
24471
24529
  const verifyIdNumber = async (context, request) => {
24472
24530
  const {
24473
24531
  loadingContext,
@@ -24494,13 +24552,13 @@ const verifyIdNumber = async (context, request) => {
24494
24552
  message: "Service did not respond, do not block verification"
24495
24553
  };
24496
24554
  }
24497
- return logger$2.warn(`Unexpected response status ${responseData.status}`);
24555
+ return logger$3.warn(`Unexpected response status ${responseData.status}`);
24498
24556
  },
24499
24557
  path: "v1/verification/idNumber",
24500
24558
  clientKey
24501
24559
  }, request);
24502
24560
  } catch (e) {
24503
- logger$2.warn("WARNING: idNumber verification failed - error:", e);
24561
+ logger$3.warn("WARNING: idNumber verification failed - error:", e);
24504
24562
  }
24505
24563
  };
24506
24564
  const getKycExternalApi = ({
@@ -24536,57 +24594,27 @@ const getKycExternalApi = ({
24536
24594
  validatePhoneNumber: async (phoneNumber2) => validatePhoneNumber({
24537
24595
  loadingContext,
24538
24596
  clientKey
24539
- }, phoneNumber2)
24597
+ }, phoneNumber2),
24598
+ getImageUrl: () => `${loadingContext}static/images/`
24540
24599
  });
24541
24600
  const ConfigurationApiProvider = ({
24542
24601
  children,
24543
24602
  rootLegalEntityId
24544
24603
  }) => {
24545
- const coreContext = useCoreContext();
24546
- const contextValue = useMemo(() => coreContext.isEmbeddedDropin && rootLegalEntityId ? getEmbeddedApi({
24547
- base: coreContext.loadingContext,
24548
- sdkToken: coreContext.sdkToken,
24604
+ const authContext = useAuthContext();
24605
+ const contextValue = useMemo(() => authContext.isEmbeddedDropin && rootLegalEntityId ? getEmbeddedApi({
24606
+ base: authContext.loadingContext,
24607
+ sdkToken: authContext.sdkToken,
24549
24608
  rootLegalEntityId
24550
24609
  }) : getKycExternalApi({
24551
- loadingContext: coreContext.loadingContext,
24552
- clientKey: coreContext.clientKey
24553
- }), [coreContext, rootLegalEntityId]);
24610
+ loadingContext: authContext.loadingContext,
24611
+ clientKey: authContext.clientKey
24612
+ }), [authContext, rootLegalEntityId]);
24554
24613
  return jsx(ConfigurationApiContext.Provider, {
24555
24614
  value: contextValue,
24556
24615
  children
24557
24616
  });
24558
24617
  };
24559
- const useComponentApi = (rootLegalEntityId) => {
24560
- const coreContext = useCoreContext();
24561
- if (!coreContext.isEmbeddedDropin) {
24562
- throw new Error("Cannot use component API outside an embedded dropin");
24563
- }
24564
- const {
24565
- loadingContext: base,
24566
- sdkToken = ""
24567
- } = coreContext;
24568
- const apiVersion = "v1";
24569
- const loadingContext = `${base}api/${apiVersion}/`;
24570
- const loadingContextWithRootLEAuth = `${loadingContext}legalEntities/`;
24571
- const baseRequestContext = {
24572
- loadingContext: loadingContextWithRootLEAuth,
24573
- legalEntityId: rootLegalEntityId,
24574
- sdkToken
24575
- };
24576
- return {
24577
- getLegalEntity: async (legalEntityId) => getLegalEntity({
24578
- ...baseRequestContext,
24579
- legalEntityId
24580
- }),
24581
- getTransferInstrument: async (transferInstrumentId) => getTransferInstrument(baseRequestContext, transferInstrumentId),
24582
- getBankVerificationVendor: async (country2) => getBankVerificationVendor(baseRequestContext, country2),
24583
- getDocument: async (documentId) => getDocument(baseRequestContext, documentId),
24584
- createDocument: async (document2, ownerId) => createDocument(baseRequestContext, document2, ownerId),
24585
- updateDocument: async (document2, documentId, ownerId) => updateDocument(baseRequestContext, document2, documentId, ownerId),
24586
- createTransferInstrument: async (transferInstrument) => createTransferInstrument(baseRequestContext, transferInstrument),
24587
- updateTransferInstrument: async (transferInstrument, transferInstrumentId) => updateTransferInstrument(baseRequestContext, transferInstrument, transferInstrumentId)
24588
- };
24589
- };
24590
24618
  class EventEmitter {
24591
24619
  constructor() {
24592
24620
  this.listeners = {
@@ -24668,6 +24696,102 @@ const componentsMap = {
24668
24696
  pci: PciDropinComponent,
24669
24697
  payoutEmbeddedDropin: PayoutEmbeddedDropin
24670
24698
  };
24699
+ const refreshSdkToken = async (context, refreshToken) => {
24700
+ const {
24701
+ loadingContext,
24702
+ sdkToken
24703
+ } = context;
24704
+ return httpPost({
24705
+ loadingContext,
24706
+ errorLevel: "warn",
24707
+ errorMessage: `Failed to refresh token`,
24708
+ path: `sessions/refresh`,
24709
+ sdkToken,
24710
+ headers: {
24711
+ "Content-Type": "application/json"
24712
+ }
24713
+ }, {
24714
+ refreshToken
24715
+ });
24716
+ };
24717
+ const SDK_TOKEN_TTL = 6e4;
24718
+ const REFRESH_INTERVAL = SDK_TOKEN_TTL - 5e3;
24719
+ const RETRY_LIMIT = 2;
24720
+ const logger$2 = createLogger("useSdkToken");
24721
+ const useSdkToken = ({
24722
+ initialSdkToken,
24723
+ refreshToken,
24724
+ autheBase
24725
+ }) => {
24726
+ const [sdkToken, setSdkToken] = useState(initialSdkToken);
24727
+ const doRefresh = async (sdkToken2, refreshToken2, retries) => {
24728
+ try {
24729
+ const {
24730
+ token: newSdkToken
24731
+ } = await refreshSdkToken({
24732
+ loadingContext: autheBase,
24733
+ sdkToken: sdkToken2
24734
+ }, refreshToken2);
24735
+ setSdkToken(newSdkToken);
24736
+ } catch (e) {
24737
+ if (!retries) {
24738
+ throw new Error("Unable to refresh token after retries", e);
24739
+ }
24740
+ logger$2.warn("Failed to refresh token. Retrying..", e);
24741
+ await doRefresh(sdkToken2, refreshToken2, retries - 1);
24742
+ }
24743
+ };
24744
+ useEffect(() => {
24745
+ if (!sdkToken || !refreshToken) {
24746
+ return;
24747
+ }
24748
+ const refreshHandler = setInterval(() => {
24749
+ doRefresh(sdkToken, refreshToken, RETRY_LIMIT).catch(() => {
24750
+ clearInterval(refreshHandler);
24751
+ });
24752
+ }, REFRESH_INTERVAL);
24753
+ return () => {
24754
+ clearInterval(refreshHandler);
24755
+ };
24756
+ }, [sdkToken]);
24757
+ return sdkToken;
24758
+ };
24759
+ const AUTHE_API_VERSION = "v1";
24760
+ const AuthProvider = ({
24761
+ children,
24762
+ sdkToken: initialSdkToken,
24763
+ refreshToken,
24764
+ clientKey,
24765
+ loadingContext
24766
+ }) => {
24767
+ const autheBase = `${loadingContext}authe/api/${AUTHE_API_VERSION}/`;
24768
+ const sdkToken = useSdkToken({
24769
+ initialSdkToken,
24770
+ refreshToken,
24771
+ autheBase
24772
+ });
24773
+ const contextValue = useMemo(() => {
24774
+ if (sdkToken && refreshToken) {
24775
+ return {
24776
+ isEmbeddedDropin: true,
24777
+ sdkToken,
24778
+ loadingContext: `${loadingContext}onboardingcomponents/`
24779
+ };
24780
+ }
24781
+ if (clientKey) {
24782
+ return {
24783
+ isEmbeddedDropin: false,
24784
+ clientKey,
24785
+ loadingContext
24786
+ };
24787
+ }
24788
+ throw new Error("Must provide either `sdkToken` and `refreshToken` or `clientKey`");
24789
+ }, [sdkToken, clientKey]);
24790
+ return jsx(AuthContext.Provider, {
24791
+ value: contextValue,
24792
+ children
24793
+ });
24794
+ };
24671
24795
  const close = "Close";
24672
24796
  const individual = "Individual";
24673
24797
  const payoutAccount = "Payout account";
@@ -26886,91 +27010,23 @@ class Language {
26886
27010
  }
26887
27011
  }
26888
27012
  const logger = createLogger("CoreProvider");
26889
- class CoreProvider extends Component {
26890
- constructor(props) {
26891
- super(props);
26892
- this.setContextCountry = (country2) => {
26893
- this.setState({
26894
- contextCountry: country2
26895
- });
26896
- };
26897
- this.setLocale = (locale) => {
26898
- var _a;
26899
- this.setState({
26900
- loaded: false
26901
- });
26902
- const originalLanguage = (_a = this.state.i18n) == null ? void 0 : _a.locale;
26903
- this.state.i18n.loadTranslations({
26904
- locale,
26905
- loadingContext: this.props.loadingContext,
26906
- clientKey: this.props.clientKey
26907
- }).then(() => {
26908
- userEvents.addEvent("Changed page language", {
26909
- segmentation: {
26910
- originalLanguage,
26911
- newLanguage: locale
26912
- }
26913
- });
26914
- this.setState({
26915
- loaded: true
26916
- });
26917
- });
26918
- };
26919
- this.setAccountHolder = (accountHolder2) => {
26920
- this.setState({
26921
- accountHolder: accountHolder2
26922
- });
26923
- };
26924
- this.setAccountFormat = (accountFormat) => {
26925
- this.setState({
26926
- accountFormat
26927
- });
26928
- };
26929
- this.getContextValue = () => {
26930
- const baseContext = {
26931
- i18n: this.state.i18n,
26932
- setLocale: this.setLocale,
26933
- loadingContext: this.props.loadingContext,
26934
- translations: this.props.translations,
26935
- setContextCountry: this.setContextCountry,
26936
- contextCountry: this.state.contextCountry,
26937
- isReview: this.props.isReview ?? false,
26938
- setAccountHolder: this.setAccountHolder,
26939
- accountHolder: this.state.accountHolder,
26940
- setAccountFormat: this.setAccountFormat,
26941
- accountFormat: this.state.accountFormat
26942
- };
26943
- if (this.props.sdkToken) {
26944
- return {
26945
- ...baseContext,
26946
- isEmbeddedDropin: true,
26947
- sdkToken: this.props.sdkToken
26948
- };
26949
- }
26950
- if (this.props.clientKey) {
26951
- return {
26952
- ...baseContext,
26953
- isEmbeddedDropin: false,
26954
- clientKey: this.props.clientKey
26955
- };
26956
- }
26957
- throw new Error("Must provide either `sdkToken` or `clientKey`");
26958
- };
26959
- this.state = {
26960
- loaded: false,
26961
- contextCountry: this.props.contextCountry,
26962
- i18n: new Language(),
26963
- accountHolder: null,
26964
- accountFormat: "local"
26965
- };
26966
- }
26967
- async componentDidMount() {
26968
- const {
26969
- contextCountry,
26970
- locale,
26971
- loadingContext,
26972
- clientKey
26973
- } = this.props;
27013
+ const CoreProvider = ({
27014
+ contextCountry: initialContextCountry,
27015
+ locale,
27016
+ clientKey,
27017
+ children,
27018
+ translations,
27019
+ isReview
27020
+ }) => {
27021
+ const {
27022
+ loadingContext
27023
+ } = useAuthContext();
27024
+ const [loaded, setLoaded] = useState(false);
27025
+ const [contextCountry, setContextCountry] = useState(initialContextCountry);
27026
+ const [i18n] = useState(new Language());
27027
+ const [accountHolder2, setAccountHolder] = useState(null);
27028
+ const [accountFormat, setAccountFormat] = useState("local");
27029
+ const init2 = async () => {
26974
27030
  loadADLIconFont(loadingContext);
26975
27031
  try {
26976
27032
  let initializationLocale = locale;
@@ -27000,32 +27056,59 @@ class CoreProvider extends Component {
27000
27056
  - ${listify(locales)}. falling back to "${FALLBACK_LOCALE}"`);
27001
27057
  initializationLocale = FALLBACK_LOCALE;
27002
27058
  }
27003
- await this.state.i18n.initialize({
27059
+ await i18n.initialize({
27004
27060
  locale: initializationLocale,
27005
- loadingContext: this.props.loadingContext,
27006
- clientKey: this.props.clientKey,
27007
- customTranslations: this.props.translations,
27061
+ loadingContext,
27062
+ clientKey,
27063
+ customTranslations: translations,
27008
27064
  allowedLocales: locales
27009
27065
  });
27010
- this.setState({
27011
- loaded: true
27012
- });
27066
+ setLoaded(true);
27013
27067
  } catch (e) {
27014
27068
  logger.log(e);
27015
27069
  }
27016
- }
27017
- shouldComponentUpdate(nextProps, nextState) {
27018
- return this.state.contextCountry !== nextState.contextCountry || this.state.loaded === false || this.state.accountHolder !== nextState.accountHolder || this.state.accountFormat !== nextState.accountFormat;
27019
- }
27020
- render(props) {
27021
- if (!this.state.loaded)
27022
- return null;
27023
- return jsx(CoreContext.Provider, {
27024
- value: this.getContextValue(),
27025
- children: props.children && toChildArray(props.children)
27070
+ };
27071
+ const setLocale = (locale2) => {
27072
+ setLoaded(false);
27073
+ const originalLanguage = i18n == null ? void 0 : i18n.locale;
27074
+ i18n.loadTranslations({
27075
+ locale: locale2,
27076
+ loadingContext,
27077
+ clientKey
27078
+ }).then(() => {
27079
+ userEvents.addEvent("Changed page language", {
27080
+ segmentation: {
27081
+ originalLanguage,
27082
+ newLanguage: locale2
27083
+ }
27084
+ });
27085
+ setLoaded(true);
27026
27086
  });
27087
+ };
27088
+ useEffect(() => {
27089
+ init2();
27090
+ });
27091
+ const contextValue = useMemo(() => ({
27092
+ i18n,
27093
+ setLocale,
27094
+ loadingContext,
27095
+ isReview,
27096
+ translations,
27097
+ setContextCountry,
27098
+ contextCountry,
27099
+ setAccountHolder,
27100
+ accountHolder: accountHolder2,
27101
+ setAccountFormat,
27102
+ accountFormat
27103
+ }), [contextCountry, loaded, accountHolder2, accountFormat]);
27104
+ if (!loaded) {
27105
+ return null;
27027
27106
  }
27028
- }
27107
+ return jsx(CoreContext.Provider, {
27108
+ value: contextValue,
27109
+ children: children && toChildArray(children)
27110
+ });
27111
+ };
27029
27112
  function ExperimentsContextProvider({
27030
27113
  children,
27031
27114
  experiments
@@ -27165,28 +27248,32 @@ class UIElement extends BaseElement {
27165
27248
  constructor(props) {
27166
27249
  super(props);
27167
27250
  this.render = () => {
27168
- const Component2 = this.props.component;
27169
- return jsx(CoreProvider, {
27170
- locale: this.props.locale,
27171
- loadingContext: this.props.loadingContext,
27172
- translations: this.props.translations,
27173
- clientKey: this.props.clientKey,
27174
- contextCountry: this.props.contextCountry,
27175
- isReview: this.props.isReview,
27251
+ const Component = this.props.component;
27252
+ return jsx(AuthProvider, {
27176
27253
  sdkToken: this.props.sdkToken,
27254
+ refreshToken: this.props.refreshToken,
27255
+ clientKey: this.props.clientKey,
27256
+ loadingContext: this.props.loadingContext,
27177
27257
  children: jsx(ConfigurationApiProvider, {
27178
- children: jsx(SettingsContextProvider, {
27179
- settings: this.props.settings,
27180
- children: jsx(ExperimentsContextProvider, {
27181
- experiments: this.props.experiments,
27182
- children: jsx("div", {
27183
- className: "adyen-kyc-dropin-container adl-u-position-relative",
27184
- children: jsx(AutoResizer, {
27185
- children: jsx(ToastContextProvider, {
27186
- children: jsx(StateProvider, {
27187
- children: jsx(Component2, {
27188
- ...this.props.componentProps,
27189
- eventEmitter: this.eventEmitter
27258
+ children: jsx(CoreProvider, {
27259
+ locale: this.props.locale,
27260
+ translations: this.props.translations,
27261
+ clientKey: this.props.clientKey,
27262
+ contextCountry: this.props.contextCountry,
27263
+ isReview: this.props.isReview,
27264
+ children: jsx(SettingsContextProvider, {
27265
+ settings: this.props.settings,
27266
+ children: jsx(ExperimentsContextProvider, {
27267
+ experiments: this.props.experiments,
27268
+ children: jsx("div", {
27269
+ className: "adyen-kyc-dropin-container adl-u-position-relative",
27270
+ children: jsx(AutoResizer, {
27271
+ children: jsx(ToastContextProvider, {
27272
+ children: jsx(StateProvider, {
27273
+ children: jsx(Component, {
27274
+ ...this.props.componentProps,
27275
+ eventEmitter: this.eventEmitter
27276
+ })
27190
27277
  })
27191
27278
  })
27192
27279
  })
@@ -27733,10 +27820,10 @@ const validateComponentName = (componentName) => {
27733
27820
  const validateCoreOptions = (coreOptions) => {
27734
27821
  const requiredOptions = ["locale", "environment", "country"];
27735
27822
  const missing = requiredOptions.filter((option) => !coreOptions[option]);
27736
- if (!coreOptions.sdkToken && !coreOptions.clientKey) {
27823
+ if (!(coreOptions.sdkToken && coreOptions.refreshToken) && !coreOptions.clientKey) {
27737
27824
  throw new Error(`
27738
27825
 
27739
- Please specify atleast one of sdkToken or clientKey for the SDK to initialize!
27826
+ Please specify either sdkToken and a refreshToken or a clientKey for the SDK to initialize!
27740
27827
 
27741
27828
 
27742
27829
  - For more information please check: https://github.com/Adyen/adyen-kyc-components#configuration.`);