-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathhelpers.ts
More file actions
171 lines (153 loc) · 4.62 KB
/
helpers.ts
File metadata and controls
171 lines (153 loc) · 4.62 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import { AddAuthorizedUsersRequest, BeneficialOwner, CloseAccountRequest, CloseAccountType, CloseReason, MobileWalletPayloadRequest, RemoveAuthorizedUsersRequest } from "./types"
import { State, Address, FullName, Phone, Status, Title, Officer, BusinessContact, AuthorizedUser, Counterparty, Coordinates, UsAddress, InternationalAddress, Relationship, RelationshipsArrayData } from "./types/common"
export function createUsAddress(street: string, street2: string | null, city: string, state: State, postalCode: string, country: "US"): UsAddress {
return {
street,
...(street2 && { street2 }),
city,
state,
postalCode,
country
}
}
export function createAddress(street: string, street2: string | null, city: string, state: string | null, postalCode: string, country: string): InternationalAddress {
return {
street,
...(street2 && { street2 }),
city,
...(state && { state }),
postalCode,
country
}
}
export function createFullName(first: string, last: string): FullName {
return {
first,
last
}
}
export function createPhone(countryCode: string, number: string): Phone {
return {
countryCode,
number
}
}
export function createOfficer(status: Status | null, fullName: FullName, title: Title | null, ssn: string | null, passport: string | null,
nationality: string | null, dateOfBirth: string, address: Address, phone: Phone, email: string): Officer {
return {
...(status && { status }),
fullName,
...(title && { title }),
...(ssn && { ssn }),
...(passport && { passport }),
...(nationality && { nationality }),
dateOfBirth,
address,
phone,
email,
}
}
export function createBeneficialOwner(status: Status | null, fullName: FullName, ssn: string | null, passport: string | null,
nationality: string | null, dateOfBirth: string, address: Address, phone: Phone, email: string, percentage: number | null): BeneficialOwner {
return {
...(status && { status }),
fullName,
...(ssn && { ssn }),
...(passport && { passport }),
...(nationality && { nationality }),
dateOfBirth,
address,
phone,
email,
...(percentage && { percentage }),
}
}
export function createBusinessContact(fullName: FullName, email: string, phone: Phone): BusinessContact {
return {
fullName,
email,
phone
}
}
export function createAuthorizedUser(fullName: FullName, email: string, phone: Phone): AuthorizedUser {
return {
fullName,
email,
phone
}
}
export function createCounterparty(routingNumber: string, accountNumber: string, accountType: string, name: string): Counterparty {
return {
routingNumber,
accountNumber,
accountType,
name
}
}
export function createCoordinates(longitude: number, latitude: number): Coordinates {
return {
longitude,
latitude
}
}
export function createRelationship(type: string, id: string): Relationship {
return {
data: {
type,
id
}
}
}
export function createRelationshipArray(type: string, ids: string[]): RelationshipsArrayData {
const ra: any = []
ids.forEach(id => {
ra.push({
type,
id
})
})
return ra
}
export function createAddAuthorizedUsersRequest(customerId: string, authorizedUsers: AuthorizedUser[]): AddAuthorizedUsersRequest {
return {
customerId,
data: {
type: "addAuthorizedUsers",
attributes: {
authorizedUsers
}
}
}
}
export function createRemoveAuthorizedUsersRequest(customerId: string, authorizedUsersEmails: string[]): RemoveAuthorizedUsersRequest {
return {
customerId,
data: {
type: "removeAuthorizedUsers",
attributes: {
authorizedUsersEmails
}
}
}
}
export function createMobileWalletRequest(cardId: string, signedNonce: string): MobileWalletPayloadRequest {
return {
cardId,
data: {
attributes: {
signedNonce
}
}
}
}
export function createCloseAccountRequest(accountId: string, closeReason: CloseReason = "ByCustomer", accountType: CloseAccountType = "depositAccountClose"): CloseAccountRequest {
return {
accountId: accountId,
data: {
type: accountType,
attributes: {
reason: closeReason
}
}
}
}