/
kyc.ts
152 lines (137 loc) · 4.24 KB
/
kyc.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import { z } from 'zod'
import { EMAIL_REGEX } from './common'
export enum KycStatus {
KycNotCreated = 'KycNotCreated',
KycPending = 'KycPending',
KycApproved = 'KycApproved',
KycDenied = 'KycDenied',
KycExpired = 'KycExpired',
}
export const kycStatusSchema = z.nativeEnum(KycStatus, {
description: 'kycStatusSchema',
})
/*
* FiatConnect dynamic type definitions.
*
* The following types contain information about differet KYC Schemas
* that are currently supported by payment providers. The types can be added to via a pull request to the FiatConnect
* specification repo -- for example, when support for a new schema is added.
*
*/
// 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(),
middleName: z.string().optional(),
lastName: z.string(),
dateOfBirth: z.object({
day: z.string(),
month: z.string(),
year: z.string(),
}),
address: z.object({
address1: z.string(),
address2: z.string().optional(),
isoCountryCode: z.string(),
isoRegionCode: z.string(),
city: z.string(),
postalCode: z.string().optional(),
}),
phoneNumber: z.string(),
selfieDocument: z.string(),
identificationDocument: z.string(),
},
{ description: 'personalDataAndDocumentsKycSchema' },
)
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
.object({
identificationDocumentType: identificationDocumentTypeWithBackSchema,
identificationDocumentBack: z.string(),
})
.or(
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' },
)
export type KycSchemas = z.infer<typeof kycSchemasSchema>
/*
/ KYC Endpoint Types
*/
// Path parameters for all KYC endpoints
export const kycRequestParamsSchema = z.object(
{
kycSchema: kycSchemaSchema,
},
{ description: 'kycRequestParamsSchema' },
)
export type KycRequestParams = z.infer<typeof kycRequestParamsSchema>
// Response body for POST /kyc/:kycSchema and GET /kyc/:kycSchema/status
export const kycStatusResponseSchema = z.object(
{
kycStatus: kycStatusSchema,
},
{ description: 'kycStatusResponseSchema' },
)
export type KycStatusResponse = z.infer<typeof kycStatusResponseSchema>