@adyen/kyc-components 2.13.1 → 2.13.3

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.
@@ -11104,7 +11104,7 @@ const createDocumentRequest = async ({
11104
11104
  attachments: [...page1 && page2 && encodedFront && encodedBack ? [createAttachment(encodedFront, page1.name, "front"), createAttachment(encodedBack, page2.name, "back")] : [createAttachment(encodedFront, page1.name)]]
11105
11105
  };
11106
11106
  };
11107
- const createAttachment = (content, pageName, pageType = "") => ({
11107
+ const createAttachment = (content, pageName, pageType) => ({
11108
11108
  content,
11109
11109
  pageName,
11110
11110
  ...pageType && {
@@ -12091,14 +12091,36 @@ const identityTypeToApiIdentityTypeMap = {
12091
12091
  };
12092
12092
  const apiIdentityTypeToIdentityTypeMap = reverseObject(identityTypeToApiIdentityTypeMap);
12093
12093
  const adjustIdentificationData = (data, apiData) => {
12094
- if (data.idNumber === void 0 && data.idNumberExempt === void 0)
12095
- return void 0;
12096
- return {
12094
+ const {
12095
+ typeOfIdentity: typeOfIdentity2,
12096
+ idNumber: idNumber2,
12097
+ idNumberExempt,
12098
+ residencyCountry: residencyCountry2
12099
+ } = data;
12100
+ const identificationData = {
12097
12101
  ...apiData,
12098
- number: stripCountryIdFormat(data.idNumber, data.residencyCountry),
12099
- nationalIdExempt: apiData.nationalIdExempt ?? !data.idNumber,
12100
- type: identityTypeToApiIdentityTypeMap[data.typeOfIdentity] ?? "nationalIdNumber"
12102
+ number: stripCountryIdFormat(idNumber2, residencyCountry2),
12103
+ type: identityTypeToApiIdentityTypeMap[typeOfIdentity2] ?? "nationalIdNumber"
12101
12104
  };
12105
+ switch (typeOfIdentity2) {
12106
+ case "passport":
12107
+ return {
12108
+ ...identificationData,
12109
+ cardNumber: ""
12110
+ };
12111
+ case "driversLicense":
12112
+ return {
12113
+ ...identificationData,
12114
+ expiryDate: ""
12115
+ };
12116
+ default:
12117
+ return idNumber2 === void 0 && idNumberExempt === void 0 ? void 0 : {
12118
+ ...identificationData,
12119
+ expiryDate: "",
12120
+ cardNumber: "",
12121
+ nationalIdExempt: apiData.nationalIdExempt ?? !idNumber2
12122
+ };
12123
+ }
12102
12124
  };
12103
12125
  const mapTransferInstrumentToPayoutAccount = (transferInstrument) => formatObject(transferInstrument, payoutComponentKeyMapping);
12104
12126
  const mapPayoutAccountToTransferInstrument = ({
@@ -12328,10 +12350,17 @@ const mapSolePropToLegalEntity = (data) => {
12328
12350
  requestObj.type = LegalEntityType.SOLE_PROPRIETORSHIP;
12329
12351
  return requestObj;
12330
12352
  };
12331
- const getPageName = (document2, pageIndex = 0) => {
12332
- var _a;
12333
- return ((_a = document2 == null ? void 0 : document2.attachments) == null ? void 0 : _a[pageIndex].pageName) || null;
12334
- };
12353
+ const getPage = ({
12354
+ attachments
12355
+ }, pageType) => {
12356
+ if (!attachments)
12357
+ throw Error("Document has no attachments");
12358
+ const attachment = pageType ? attachments.find((attach) => attach.pageType === pageType) : attachments[0];
12359
+ if (!attachment)
12360
+ throw Error(`Attachment not found${pageType ? ` with type '${pageType}'` : ""}`);
12361
+ return attachment;
12362
+ };
12363
+ const getPageName = (document2, pageType) => getPage(document2, pageType).pageName;
12335
12364
  const mapIndividualDocumentToApiDocument = async (data, entityId) => {
12336
12365
  var _a, _b, _c, _d;
12337
12366
  if (data) {
@@ -12361,24 +12390,34 @@ const mapIndividualDocumentToApiDocument = async (data, entityId) => {
12361
12390
  return documents2.filter(Boolean);
12362
12391
  }
12363
12392
  };
12393
+ const mapApiIdDocumentToSchema = (idDocument2) => {
12394
+ const {
12395
+ hasBackPage
12396
+ } = idDocumentTypeOptions.find(({
12397
+ id: id2
12398
+ }) => id2 === idDocument2.type);
12399
+ const frontPage2 = hasBackPage ? getPage(idDocument2, "front") : getPage(idDocument2);
12400
+ const backPage2 = hasBackPage ? getPage(idDocument2, "back") : void 0;
12401
+ return {
12402
+ ...frontPage2 ? {
12403
+ idFrontPage: [{
12404
+ name: frontPage2.pageName
12405
+ }]
12406
+ } : {},
12407
+ ...backPage2 ? {
12408
+ idBackPage: [{
12409
+ name: backPage2.pageName
12410
+ }]
12411
+ } : {},
12412
+ idDocumentType: idDocument2.type
12413
+ };
12414
+ };
12364
12415
  const mapApiDocumentToIndividualDocuments = (entityId) => {
12365
12416
  const idDocument2 = getIdDocument(entityId) || null;
12366
12417
  const proofOfResidence2 = getDocument$1(entityId, DocumentType.PROOF_OF_RESIDENCY) || null;
12367
12418
  const proofOfNationalId2 = getDocument$1(entityId, DocumentType.PROOF_OF_NATIONAL_ID_NUMBER) || null;
12368
12419
  return {
12369
- idDocument: {
12370
- ...(idDocument2 == null ? void 0 : idDocument2.attachments[0]) ? {
12371
- idFrontPage: [{
12372
- name: getPageName(idDocument2, 0)
12373
- }]
12374
- } : {},
12375
- ...(idDocument2 == null ? void 0 : idDocument2.attachments[1]) ? {
12376
- idBackPage: [{
12377
- name: getPageName(idDocument2, 1)
12378
- }]
12379
- } : {},
12380
- idDocumentType: idDocument2 == null ? void 0 : idDocument2.type
12381
- },
12420
+ idDocument: idDocument2 ? mapApiIdDocumentToSchema(idDocument2) : null,
12382
12421
  proofOfResidence: proofOfResidence2 ? [{
12383
12422
  name: getPageName(proofOfResidence2)
12384
12423
  }] : null,
@@ -12588,40 +12627,34 @@ function IdDocumentManualUploadComponent(props) {
12588
12627
  prevState,
12589
12628
  changeInitiatedBy
12590
12629
  }) => {
12591
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
12592
- if (changeInitiatedBy === "idDocument") {
12593
- if (((_b = (_a2 = currentState == null ? void 0 : currentState.data) == null ? void 0 : _a2.idDocument) == null ? void 0 : _b.idDocumentType) !== ((_d = (_c = prevState == null ? void 0 : prevState.data) == null ? void 0 : _c.idDocument) == null ? void 0 : _d.idDocumentType)) {
12594
- const data2 = (_e = currentState.data) == null ? void 0 : _e.idDocument;
12595
- const document2 = (data2 == null ? void 0 : data2.idDocumentType) ? getDocument$1(props.legalEntityId, data2.idDocumentType) : void 0;
12596
- const isFrontPageSelected = ((_f = data2 == null ? void 0 : data2.idFrontPage) == null ? void 0 : _f[0]) instanceof File;
12597
- const isBackPageSelected = ((_g = data2 == null ? void 0 : data2.idBackPage) == null ? void 0 : _g[0]) instanceof File;
12598
- if (document2) {
12599
- if (!isFrontPageSelected && ((_h = document2.attachments) == null ? void 0 : _h[0])) {
12600
- setIdFrontPage({
12601
- idFrontPage: [{
12602
- name: getPageName(document2, 0)
12603
- }]
12604
- });
12605
- }
12606
- if (!isBackPageSelected && ((_i = document2.attachments) == null ? void 0 : _i[1])) {
12607
- setIdBackPage({
12608
- idBackPage: [{
12609
- name: getPageName(document2, 1)
12610
- }]
12611
- });
12612
- }
12613
- } else {
12614
- if (!isFrontPageSelected) {
12615
- setIdFrontPage({
12616
- idFrontPage: null
12617
- });
12618
- }
12619
- if (!isBackPageSelected) {
12620
- setIdBackPage({
12621
- idBackPage: null
12622
- });
12623
- }
12624
- }
12630
+ var _a2, _b, _c, _d, _e, _f;
12631
+ if (changeInitiatedBy === "idDocument" && ((_b = (_a2 = currentState == null ? void 0 : currentState.data) == null ? void 0 : _a2.idDocument) == null ? void 0 : _b.idDocumentType) !== ((_d = (_c = prevState == null ? void 0 : prevState.data) == null ? void 0 : _c.idDocument) == null ? void 0 : _d.idDocumentType)) {
12632
+ const idDocumentType = (_f = (_e = currentState.data) == null ? void 0 : _e.idDocument) == null ? void 0 : _f.idDocumentType;
12633
+ const document2 = idDocumentType ? getDocument$1(props.legalEntityId, idDocumentType) : void 0;
12634
+ if (!document2) {
12635
+ setIdFrontPage({
12636
+ idFrontPage: null
12637
+ });
12638
+ setIdBackPage({
12639
+ idBackPage: null
12640
+ });
12641
+ } else if (hasBackPage(idDocumentType)) {
12642
+ setIdFrontPage({
12643
+ idFrontPage: [{
12644
+ name: getPageName(document2, "front")
12645
+ }]
12646
+ });
12647
+ setIdBackPage({
12648
+ idBackPage: [{
12649
+ name: getPageName(document2, "back")
12650
+ }]
12651
+ });
12652
+ } else {
12653
+ setIdFrontPage({
12654
+ idFrontPage: [{
12655
+ name: getPageName(document2)
12656
+ }]
12657
+ });
12625
12658
  }
12626
12659
  }
12627
12660
  };
@@ -1,5 +1,6 @@
1
+ export type PageType = 'front' | 'back';
1
2
  export interface Attachment {
2
3
  content: string;
3
- pageType?: string;
4
- pageName?: string;
4
+ pageName: string;
5
+ pageType?: PageType;
5
6
  }
@@ -11,6 +11,7 @@ export interface Individual {
11
11
  number?: string;
12
12
  type?: string;
13
13
  cardNumber?: string;
14
+ expiryDate?: string;
14
15
  };
15
16
  name: {
16
17
  firstName: string;
@@ -38,7 +38,7 @@ export declare const individualComponentsKeyMapping: {
38
38
  'address.otherAddressInformation': string;
39
39
  };
40
40
  export declare const individualApiKeyMapping: {
41
- [x: string]: "personalDetails.firstName" | "personalDetails.lastName" | "personalDetails.issuerState" | "personalDetails.phoneNumber" | "personalDetails.email" | "personalDetails.birthDate" | "personalDetails.idNumber" | "personalDetails.licenseCardNumber" | "personalDetails.nationality" | "personalDetails.jobTitle" | "personalDetails.typeOfIdentity" | "personalDetails.idNumberExempt" | "personalDetails.expiryDate" | "address.country" | "address.postalCode" | "address.city" | "address.stateOrProvince" | "address.otherAddressInformation" | "address.address";
41
+ [x: string]: "personalDetails.firstName" | "personalDetails.lastName" | "personalDetails.issuerState" | "personalDetails.expiryDate" | "personalDetails.phoneNumber" | "personalDetails.email" | "personalDetails.birthDate" | "personalDetails.idNumber" | "personalDetails.licenseCardNumber" | "personalDetails.nationality" | "personalDetails.jobTitle" | "personalDetails.typeOfIdentity" | "personalDetails.idNumberExempt" | "address.country" | "address.postalCode" | "address.city" | "address.stateOrProvince" | "address.otherAddressInformation" | "address.address";
42
42
  };
43
43
  export declare const companyComponentsKeyMapping: {
44
44
  'companyNameAndCountry.country': string;
@@ -5,6 +5,7 @@ import { PayoutDetailsSchema } from '../../components/PayoutDetails/types';
5
5
  import { PersonalDetailsSchema } from '../../components/PersonalDetails/types';
6
6
  import { SolePropSchema } from '../../components/SoleProp/types';
7
7
  import { TrustSchema } from '../../components/Trust/types';
8
+ import { Attachment, PageType } from '../../core/models/api/attachment';
8
9
  import { Document } from '../../core/models/api/document';
9
10
  import { Individual } from '../../core/models/api/individual';
10
11
  import { LegalEntity } from '../../core/models/api/legal-entity';
@@ -34,7 +35,8 @@ export declare const mapTrustToLegalEntity: (data: TrustSchema) => LegalEntity;
34
35
  export declare const mapLegalEntityToSoleProp: (legalEntity: LegalEntity) => SolePropSchema;
35
36
  export declare const mapSolePropToLegalEntity: (data: SolePropSchema) => LegalEntity;
36
37
  export type IndividualDocumentFields = Pick<IndividualSchema, 'idDocument' | 'proofOfResidence' | 'proofOfNationalId'>;
37
- export declare const getPageName: (document: Document, pageIndex?: number) => string;
38
+ export declare const getPage: ({ attachments }: Document, pageType?: PageType) => Attachment;
39
+ export declare const getPageName: (document: Document, pageType?: PageType) => string;
38
40
  export declare const mapIndividualDocumentToApiDocument: (data: IndividualSchema, entityId: string) => Promise<Document[]>;
39
41
  export declare const mapApiDocumentToIndividualDocuments: (entityId: string) => IndividualDocumentFields;
40
42
  export declare const mapCompanyDocumentToApiDocument: (data: CompanySchema, entityId: string) => Promise<Document[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adyen/kyc-components",
3
- "version": "2.13.1",
3
+ "version": "2.13.3",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "files": [