1 | |
2 | type Persona = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Create a Report |
7 | * Creates a new Report of any type. |
8 | */ |
9 | export async function main( |
10 | auth: Persona, |
11 | body: { |
12 | data?: |
13 | | { |
14 | type?: "report/address-lookup"; |
15 | attributes: { |
16 | "account-id"?: string; |
17 | "reference-id"?: string; |
18 | "report-template-id"?: string; |
19 | } & { |
20 | query: { |
21 | addressee?: string; |
22 | "address-street-1": string; |
23 | "address-street-2"?: string; |
24 | "address-city": string; |
25 | "address-subdivision": string; |
26 | "address-postal-code": string; |
27 | "address-country-code": string; |
28 | }; |
29 | }; |
30 | } |
31 | | { |
32 | type?: "report/adverse-media"; |
33 | attributes: { |
34 | "account-id"?: string; |
35 | "reference-id"?: string; |
36 | "report-template-id"?: string; |
37 | } & { |
38 | query: { |
39 | "name-first"?: string; |
40 | "name-middle"?: string; |
41 | "name-last"?: string; |
42 | term?: string; |
43 | birthdate?: string; |
44 | "country-code"?: string; |
45 | }; |
46 | }; |
47 | } |
48 | | { |
49 | type?: "report/business-adverse-media"; |
50 | attributes: { |
51 | "account-id"?: string; |
52 | "reference-id"?: string; |
53 | "report-template-id"?: string; |
54 | } & { query: { term: string } }; |
55 | } |
56 | | { |
57 | type?: "report/business-lookup"; |
58 | attributes: { |
59 | "account-id"?: string; |
60 | "reference-id"?: string; |
61 | "report-template-id"?: string; |
62 | } & { |
63 | query: { |
64 | "business-name": string; |
65 | "phone-number"?: string; |
66 | website?: string; |
67 | ein?: string; |
68 | "address-street-1"?: string; |
69 | "address-street-2"?: string; |
70 | "address-city"?: string; |
71 | "address-subdivision"?: string; |
72 | "address-postal-code"?: string; |
73 | "address-country-code"?: string; |
74 | "associated-people"?: { |
75 | "name-full"?: string; |
76 | "name-first"?: string; |
77 | "name-last"?: string; |
78 | titles?: string[]; |
79 | }[]; |
80 | }; |
81 | }; |
82 | } |
83 | | { |
84 | type?: "report/business-watchlist"; |
85 | attributes: { |
86 | "account-id"?: string; |
87 | "reference-id"?: string; |
88 | "report-template-id"?: string; |
89 | } & { query: { term: string; "address-country-code"?: string } }; |
90 | } |
91 | | { |
92 | type?: "report/crypto-address-watchlist"; |
93 | attributes: { |
94 | "account-id"?: string; |
95 | "reference-id"?: string; |
96 | "report-template-id"?: string; |
97 | } & { query: { "crypto-address": string } }; |
98 | } |
99 | | { |
100 | type?: "report/email-address"; |
101 | attributes: { |
102 | "account-id"?: string; |
103 | "reference-id"?: string; |
104 | "report-template-id"?: string; |
105 | } & { query: { "email-address": string } }; |
106 | } |
107 | | { |
108 | type?: "report/phone-number"; |
109 | attributes: { |
110 | "account-id"?: string; |
111 | "reference-id"?: string; |
112 | "report-template-id"?: string; |
113 | } & { query: { "phone-number": string } }; |
114 | } |
115 | | { |
116 | type?: "report/politically-exposed-person"; |
117 | attributes: { |
118 | "account-id"?: string; |
119 | "reference-id"?: string; |
120 | "report-template-id"?: string; |
121 | } & { |
122 | query: { |
123 | "name-first"?: string; |
124 | "name-middle"?: string; |
125 | "name-last"?: string; |
126 | term?: string; |
127 | birthdate?: string; |
128 | "country-code"?: string; |
129 | }; |
130 | }; |
131 | } |
132 | | { |
133 | type?: "report/profile"; |
134 | attributes?: { |
135 | "account-id"?: string; |
136 | "reference-id"?: string; |
137 | "report-template-id"?: string; |
138 | } & { |
139 | query?: { |
140 | "name-first"?: string; |
141 | "name-last"?: string; |
142 | birthdate?: string; |
143 | "social-security-number"?: string; |
144 | "address-street-1"?: string; |
145 | "address-street-2"?: string; |
146 | "address-city"?: string; |
147 | "address-subdivision"?: string; |
148 | "address-postal-code"?: string; |
149 | "country-code"?: string; |
150 | "phone-number"?: string; |
151 | }; |
152 | }; |
153 | } |
154 | | { |
155 | type?: "report/profile-non-authoritative"; |
156 | attributes: { |
157 | "account-id"?: string; |
158 | "reference-id"?: string; |
159 | "report-template-id"?: string; |
160 | } & { |
161 | query: { |
162 | "name-first"?: string; |
163 | "name-last"?: string; |
164 | "phone-number"?: string; |
165 | "email-address"?: string; |
166 | "address-city"?: string; |
167 | "address-subdivision"?: string; |
168 | }; |
169 | }; |
170 | } |
171 | | { |
172 | type?: "report/social-media"; |
173 | attributes: { |
174 | "account-id"?: string; |
175 | "reference-id"?: string; |
176 | "report-template-id"?: string; |
177 | } & { |
178 | query: { |
179 | "name-first"?: string; |
180 | "name-last"?: string; |
181 | birthdate?: string; |
182 | "phone-number"?: string; |
183 | "email-address"?: string; |
184 | "address-city"?: string; |
185 | "address-subdivision"?: string; |
186 | "address-postal-code"?: string; |
187 | "address-country-code"?: string; |
188 | }; |
189 | }; |
190 | } |
191 | | { |
192 | type?: "report/synthetic"; |
193 | attributes: { |
194 | "account-id"?: string; |
195 | "reference-id"?: string; |
196 | "report-template-id"?: string; |
197 | } & { |
198 | query: { |
199 | "name-first": string; |
200 | "name-last": string; |
201 | birthdate: string; |
202 | "social-security-number"?: string; |
203 | "identification-number"?: string; |
204 | "address-street-1": string; |
205 | "address-street-2"?: string; |
206 | "address-city": string; |
207 | "address-subdivision": string; |
208 | "address-postal-code": string; |
209 | "address-country-code": string; |
210 | "phone-number"?: string; |
211 | "email-address"?: string; |
212 | }; |
213 | }; |
214 | } |
215 | | { |
216 | type?: "report/watchlist"; |
217 | attributes: { |
218 | "account-id"?: string; |
219 | "reference-id"?: string; |
220 | "report-template-id"?: string; |
221 | } & { |
222 | query: { |
223 | "name-first"?: string; |
224 | "name-middle"?: string; |
225 | "name-last"?: string; |
226 | term?: string; |
227 | birthdate?: string; |
228 | "address-country-code"?: string; |
229 | }; |
230 | }; |
231 | }; |
232 | meta?: { |
233 | "auto-create-account"?: false | true; |
234 | "auto-create-account-type-id"?: string; |
235 | "auto-create-account-reference-id"?: string; |
236 | "processing-mode"?: string; |
237 | "request-flags"?: string[]; |
238 | }; |
239 | }, |
240 | include?: string, |
241 | fields?: string, |
242 | Key_Inflection?: string, |
243 | Idempotency_Key?: string, |
244 | Persona_Version?: string, |
245 | ) { |
246 | const url = new URL(`https://api.withpersona.com/api/v1/reports`); |
247 | for (const [k, v] of [ |
248 | ["include", include], |
249 | ["fields", fields], |
250 | ]) { |
251 | if (v !== undefined && v !== "" && k !== undefined) { |
252 | url.searchParams.append(k, v); |
253 | } |
254 | } |
255 | const headers: Record<string, string> = { |
256 | Authorization: `Bearer ${auth.apiKey}`, |
257 | "Content-Type": "application/json", |
258 | }; |
259 | if (Key_Inflection) { |
260 | headers["Key-Inflection"] = Key_Inflection; |
261 | } |
262 | if (Idempotency_Key) { |
263 | headers["Idempotency-Key"] = Idempotency_Key; |
264 | } |
265 | if (Persona_Version) { |
266 | headers["Persona-Version"] = Persona_Version; |
267 | } |
268 | const response = await fetch(url, { |
269 | method: "POST", |
270 | headers, |
271 | body: JSON.stringify(body), |
272 | }); |
273 | if (!response.ok) { |
274 | const text = await response.text(); |
275 | throw new Error(`${response.status} ${text}`); |
276 | } |
277 | return await response.json(); |
278 | } |
279 |
|