-
Notifications
You must be signed in to change notification settings - Fork 3
/
types.ts
129 lines (111 loc) · 3.81 KB
/
types.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
import { components, paths } from './generatedApiTypes'
export enum Region {
EU = 'EU',
AP = 'AP',
Global = 'Global',
}
export enum AuthenticationMode {
AuthHeader = 'AuthHeader',
QueryParameter = 'QueryParameter',
}
/**
* Options for FingerprintJS server API client
*/
export interface Options {
/**
* Secret API key
*/
apiKey: string
/**
* Region of the FingerprintJS service server
*/
region?: Region
/**
* Authentication mode
* Optional, default value is AuthHeader
*/
authenticationMode?: AuthenticationMode
/**
* Optional fetch implementation
* */
fetch?: typeof fetch
}
/**
* More info: https://dev.fingerprintjs.com/docs/server-api#query-parameters
*/
export type VisitorHistoryFilter = paths['/visitors/{visitor_id}']['get']['parameters']['query']
/**
* More info: https://dev.fingerprintjs.com/docs/server-api#response
*/
export type VisitorsResponse = paths['/visitors/{visitor_id}']['get']['responses']['200']['content']['application/json']
export type VisitorsError403 =
paths['/visitors/{visitor_id}']['get']['responses']['403']['content']['application/json'] & {
status: 403
}
export type VisitorsError429 =
paths['/visitors/{visitor_id}']['get']['responses']['429']['content']['application/json'] & {
status: 429
/**
* How many seconds to wait before retrying
*/
retryAfter: number
}
export type DeleteVisitError404 =
paths['/visitors/{visitor_id}']['delete']['responses']['404']['content']['application/json'] & {
status: 404
}
export type DeleteVisitError403 =
paths['/visitors/{visitor_id}']['delete']['responses']['403']['content']['application/json'] & {
status: 403
}
export type VisitorsError = WithResponse<VisitorsError403 | VisitorsError429>
export type DeleteVisitorError = WithResponse<DeleteVisitError404 | DeleteVisitError403>
export function isVisitorsError(response: any): response is VisitorsError {
return (
(response?.hasOwnProperty('status') &&
(response.status === 403 || response.status === 429) &&
response?.hasOwnProperty('error') &&
typeof response.error === 'string') ||
false
)
}
export function isDeleteVisitorError(response: any): response is DeleteVisitorError {
return (
(response?.hasOwnProperty('status') &&
(response.status === 403 || response.status === 404) &&
response.error?.hasOwnProperty('message') &&
typeof response.error.message === 'string' &&
response.error?.hasOwnProperty('code') &&
typeof response.error.code === 'string') ||
false
)
}
export type EventResponse = paths['/events/{request_id}']['get']['responses']['200']['content']['application/json']
export type EventError403 = paths['/events/{request_id}']['get']['responses']['403']['content']['application/json']
export type EventError404 = paths['/events/{request_id}']['get']['responses']['404']['content']['application/json']
type WithResponse<T> = T & {
response: Response
}
type GenericEventError = WithResponse<EventError403 | EventError404>
type EventErrorCode<T extends GenericEventError> = T extends EventError403 ? 403 : 404
export type EventError<T extends GenericEventError = GenericEventError> = WithResponse<
T & {
status: EventErrorCode<T>
}
>
export function isEventError(response: any): response is EventError {
return (
(response?.hasOwnProperty('status') &&
(response.status === 403 || response.status === 404) &&
response?.hasOwnProperty('error') &&
response.error?.hasOwnProperty('message') &&
typeof response.error.message === 'string' &&
response.error?.hasOwnProperty('code') &&
typeof response.error.code === 'string') ||
false
)
}
/**
* More info: https://dev.fingerprintjs.com/docs/webhooks#identification-webhook-object-format
*/
export type VisitWebhook = components['schemas']['WebhookVisit']