New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add PersonalDataAndDocumentsDetailed kyc schema #122
Changes from all commits
407824a
aeeac17
fbb47dd
352af69
fcfff4d
73bd9f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { z } from 'zod' | ||
import { EMAIL_REGEX } from './common' | ||
|
||
export enum KycStatus { | ||
KycNotCreated = 'KycNotCreated', | ||
|
@@ -7,6 +8,7 @@ export enum KycStatus { | |
KycDenied = 'KycDenied', | ||
KycExpired = 'KycExpired', | ||
} | ||
|
||
export const kycStatusSchema = z.nativeEnum(KycStatus, { | ||
description: 'kycStatusSchema', | ||
}) | ||
|
@@ -23,11 +25,44 @@ export const kycStatusSchema = z.nativeEnum(KycStatus, { | |
// When adding new schemas be sure to also update kycSchemasSchema | ||
export enum KycSchema { | ||
PersonalDataAndDocuments = 'PersonalDataAndDocuments', | ||
PersonalDataAndDocumentsDetailed = 'PersonalDataAndDocumentsDetailed', | ||
} | ||
|
||
export const kycSchemaSchema = z.nativeEnum(KycSchema, { | ||
description: 'kycSchemaSchema', | ||
}) | ||
|
||
export enum IdentificationDocumentType { | ||
IDC = 'IDC', | ||
PAS = 'PAS', | ||
DL = 'DL', | ||
} | ||
|
||
// need nonempty array types to get zod enums to compile | ||
const documentsWithBack: [ | ||
IdentificationDocumentType, | ||
...IdentificationDocumentType[], | ||
] = [IdentificationDocumentType.IDC, IdentificationDocumentType.DL] | ||
const documentsWithoutBack: [ | ||
IdentificationDocumentType, | ||
...IdentificationDocumentType[], | ||
] = ( | ||
Object.keys(IdentificationDocumentType) as [ | ||
IdentificationDocumentType, | ||
...IdentificationDocumentType[], | ||
] | ||
).filter((idType) => !documentsWithBack.includes(idType)) as [ | ||
IdentificationDocumentType, | ||
...IdentificationDocumentType[], | ||
] | ||
|
||
const identificationDocumentTypeWithBackSchema = z.enum(documentsWithBack) | ||
const identificationDocumentTypeWithoutBackSchema = z.enum(documentsWithoutBack) | ||
export const identificationDocumentTypeSchema = | ||
identificationDocumentTypeWithBackSchema.or( | ||
identificationDocumentTypeWithoutBackSchema, | ||
) | ||
|
||
export const personalDataAndDocumentsKycSchema = z.object( | ||
{ | ||
firstName: z.string(), | ||
|
@@ -56,10 +91,39 @@ export type PersonalDataAndDocumentsKyc = z.infer< | |
typeof personalDataAndDocumentsKycSchema | ||
> | ||
|
||
export const personalDataAndDocumentsDetailedKycSchema = | ||
personalDataAndDocumentsKycSchema | ||
.omit({ identificationDocument: true }) | ||
.and( | ||
z.object({ | ||
email: z.string().regex(EMAIL_REGEX), | ||
identificationDocumentFront: z.string(), | ||
}), | ||
) | ||
.and( | ||
z | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i assume the linter did this due to the next line's length, but weird to have a line containing only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. z There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tbh i hate this but yes it's the linter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. futzed around for a while trying to get the z some company on that line, to no avail |
||
.object({ | ||
identificationDocumentType: identificationDocumentTypeWithBackSchema, | ||
identificationDocumentBack: z.string(), | ||
}) | ||
.or( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is, if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so, but to avoid having to reason about this I just dropped it. seems simpler. |
||
z.object({ | ||
identificationDocumentType: | ||
identificationDocumentTypeWithoutBackSchema, | ||
}), | ||
), | ||
) | ||
|
||
export type PersonalDataAndDocumentsDetailedKyc = z.infer< | ||
typeof personalDataAndDocumentsDetailedKycSchema | ||
> | ||
|
||
export const kycSchemasSchema = z.object( | ||
{ | ||
[kycSchemaSchema.enum.PersonalDataAndDocuments]: | ||
personalDataAndDocumentsKycSchema, | ||
[kycSchemaSchema.enum.PersonalDataAndDocumentsDetailed]: | ||
personalDataAndDocumentsDetailedKycSchema, | ||
}, | ||
{ description: 'kycSchemasSchema' }, | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and the award for most uses of the word "document" in a single expression goes to... 🤣