@adyen/kyc-components 2.13.1 → 2.13.2

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,29 @@ const mapIndividualDocumentToApiDocument = async (data, entityId) => {
12361
12390
  return documents2.filter(Boolean);
12362
12391
  }
12363
12392
  };
12393
+ const mapApiIdDocumentToSchema = (idDocument2) => {
12394
+ const frontPage2 = getPage(idDocument2, "front");
12395
+ const backPage2 = getPage(idDocument2, "back");
12396
+ return {
12397
+ ...frontPage2 ? {
12398
+ idFrontPage: [{
12399
+ name: frontPage2.pageName
12400
+ }]
12401
+ } : {},
12402
+ ...backPage2 ? {
12403
+ idBackPage: [{
12404
+ name: backPage2.pageName
12405
+ }]
12406
+ } : {},
12407
+ idDocumentType: idDocument2.type
12408
+ };
12409
+ };
12364
12410
  const mapApiDocumentToIndividualDocuments = (entityId) => {
12365
12411
  const idDocument2 = getIdDocument(entityId) || null;
12366
12412
  const proofOfResidence2 = getDocument$1(entityId, DocumentType.PROOF_OF_RESIDENCY) || null;
12367
12413
  const proofOfNationalId2 = getDocument$1(entityId, DocumentType.PROOF_OF_NATIONAL_ID_NUMBER) || null;
12368
12414
  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
- },
12415
+ idDocument: idDocument2 ? mapApiIdDocumentToSchema(idDocument2) : null,
12382
12416
  proofOfResidence: proofOfResidence2 ? [{
12383
12417
  name: getPageName(proofOfResidence2)
12384
12418
  }] : null,
@@ -12599,14 +12633,14 @@ function IdDocumentManualUploadComponent(props) {
12599
12633
  if (!isFrontPageSelected && ((_h = document2.attachments) == null ? void 0 : _h[0])) {
12600
12634
  setIdFrontPage({
12601
12635
  idFrontPage: [{
12602
- name: getPageName(document2, 0)
12636
+ name: getPageName(document2, "front")
12603
12637
  }]
12604
12638
  });
12605
12639
  }
12606
12640
  if (!isBackPageSelected && ((_i = document2.attachments) == null ? void 0 : _i[1])) {
12607
12641
  setIdBackPage({
12608
12642
  idBackPage: [{
12609
- name: getPageName(document2, 1)
12643
+ name: getPageName(document2, "back")
12610
12644
  }]
12611
12645
  });
12612
12646
  }
@@ -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.2",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "files": [