-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
93 lines (81 loc) · 2.32 KB
/
index.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
import type { PlaidEventName, PlaidSelection, PlaidViewName } from './event-types';
import type { ExitStatus } from './exit-status-types';
// #region Misc
export interface PlaidAccount {
id: string;
name: string;
mask: string;
type: string;
subtype: string;
verification_status: string;
}
export interface PlaidInstitution {
name: string;
institution_id: string;
}
export interface PlaidLinkError {
error_type: string;
error_code: string;
error_message: string;
display_message: string;
}
export interface PlaidLinkOptions {
token: string | null;
receivedRedirectUri?: string;
onSuccess: PlaidLinkOnSuccess;
onExit?: PlaidLinkOnExit;
onLoad?: () => void;
onEvent?: PlaidLinkOnEvent;
}
// #endregion
// #region Callbacks
export interface PlaidLinkOnSuccessMetadata {
institution: null | PlaidInstitution;
accounts: PlaidAccount[];
link_session_id: string;
transfer_status?: string;
}
export interface PlaidLinkOnExitMetadata {
institution: PlaidInstitution | null;
status: ExitStatus | null;
link_session_id: string;
request_id: string;
}
export interface PlaidLinkOnEventMetadata {
error_type: string | null;
error_code: string | null;
error_message: string | null;
exit_status: string | null;
institution_id: string | null;
institution_name: string | null;
institution_search_query: string | null;
mfa_type: string | null;
view_name: PlaidViewName | null;
selection: PlaidSelection | null;
timestamp: string; // ISO 8601 format timestamp
link_session_id: string;
request_id: string;
}
export type PlaidLinkOnSuccess = (public_token: string, metadata: PlaidLinkOnSuccessMetadata) => void;
export type PlaidLinkOnExit = (err: PlaidLinkError | null, metadata: PlaidLinkOnExitMetadata) => void;
export type PlaidLinkOnEvent = (eventName: PlaidEventName, metadata: PlaidLinkOnEventMetadata) => void;
// #endregion
// #region Global Plaid
export interface PlaidHandler {
open: () => void;
exit: (force?: boolean) => void;
destroy: () => void;
}
export interface PlaidEmbeddedHandler {
destroy: () => void;
}
export interface Plaid extends PlaidHandler {
create: (config: PlaidLinkOptions) => PlaidHandler;
createEmbedded: (config: PlaidLinkOptions, domTarget: HTMLElement) => PlaidEmbeddedHandler;
}
declare global {
interface Window {
Plaid: Plaid;
}
}
// #endregion