@methodfi/opal-react 0.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -33,35 +33,36 @@ export default function App() {
33
33
  Use the `useOpal` hook in your components:
34
34
 
35
35
  ```tsx
36
- import { useOpal } from '@methodfi/opal-react';
36
+ import { useOpal, OpalEventType } from '@methodfi/opal-react';
37
37
 
38
38
  function Screen() {
39
- const { open } = useOpal({
39
+ const { open, close, isOpen, error } = useOpal({
40
40
  env: 'dev',
41
41
  onOpen: () => {},
42
42
  onExit: () => {},
43
- onError: (error) => console.error('Error:', error),
44
- onEvent: (event) => {
43
+ onEvent: event => {
45
44
  switch (event.type) {
46
- case 'opal.session.started': { /* ... */ }
47
- case 'opal.session.errored': { /* ... */ }
48
- case 'opal.session.exited': { /* ... */ }
49
- case 'card_connect.card.verified': { /* ... */ }
50
- // See events section
45
+ case OpalEventType.SESSION_STARTED:
46
+ // ...
47
+ break;
48
+ case OpalEventType.SESSION_COMPLETED:
49
+ // ...
50
+ break;
51
+ case OpalEventType.SESSION_ERRORED:
52
+ // ...
53
+ break;
54
+ case OpalEventType.SESSION_EXITED:
55
+ // ...
56
+ break;
51
57
  }
52
58
  },
53
59
  });
54
60
 
55
61
  const onLaunchOpal = async () => {
56
- // Resulting token from POST /opal/token (otkn_*)
57
- const token = await getOpalToken();
62
+ const token = await getOpalToken(); // POST /opal/token
58
63
  open({ token });
59
64
  };
60
65
 
61
- return (
62
- <button onClick={onLaunchOpal}>
63
- Launch Opal
64
- </button>
65
- );
66
+ return <button onClick={onLaunchOpal}>Launch Opal</button>;
66
67
  }
67
- ```
68
+ ```
package/dist/index.d.ts CHANGED
@@ -1,76 +1,56 @@
1
1
  import { ReactNode } from 'react';
2
- import * as react_jsx_runtime from 'react/jsx-runtime';
3
2
 
4
3
  type OpalEnvironment = 'local' | 'dev' | 'sandbox' | 'production';
5
4
  type OpalMode = 'opal' | 'card_connect' | 'account_verification' | string;
6
5
  type OpalEventObject = 'session' | 'card' | 'account' | 'bank' | string;
7
6
  type OpalEventAction = 'started' | 'errored' | 'exited' | 'verified' | 'completed' | string;
8
- type OpalEventType = 'opal.session.started' | 'opal.session.errored' | 'opal.session.exited' | 'card_connect.session.started' | 'card_connect.session.errored' | 'card_connect.card.verified' | 'account_verification.session.started' | 'account_verification.session.errored' | 'account_verification.account.verified' | string;
7
+ declare const OpalEventType: {
8
+ readonly SESSION_STARTED: "opal.session.started";
9
+ readonly SESSION_ERRORED: "opal.session.errored";
10
+ readonly SESSION_EXITED: "opal.session.exited";
11
+ readonly SESSION_COMPLETED: "opal.session.completed";
12
+ };
13
+ type OpalEventType = 'opal.session.started' | 'opal.session.errored' | 'opal.session.exited' | 'opal.session.completed';
9
14
  /**
10
15
  * Structured event object matching Method's Opal event format
11
- * Events follow the pattern: <mode>.<object>.<action>
16
+ * Types follow the pattern: <mode>.<object>.<action>, which is
17
+ * also split up into those properties for convenience.
12
18
  */
13
19
  interface OpalEvent {
14
- /** The type of event, formatted as <mode>.<object>.<action> */
15
20
  type: OpalEventType;
16
- /** The operational mode associated with the event (e.g., 'card_connect') */
17
21
  mode: OpalMode;
18
- /** The object the event is related to (e.g., 'card', 'session') */
19
22
  object: OpalEventObject;
20
- /** The action that occurred (e.g., 'started', 'verified', 'errored') */
21
23
  action: OpalEventAction;
22
- /** The ISO 8601 timestamp of when the event occurred */
23
24
  timestamp: string;
24
- /** Additional context or details related to the event (varies by event type) */
25
25
  data?: OpalEventData | null;
26
26
  }
27
27
  /**
28
28
  * Error data structure for Opal session errors
29
29
  */
30
30
  interface OpalErrorData {
31
- /** Error type identifier */
32
31
  type: string;
33
- /** Error sub-type for more specific categorization */
34
32
  sub_type?: string;
35
- /** Human-readable error message */
36
33
  message: string;
37
34
  }
38
- /**
39
- * Card verification event data
40
- */
41
- interface CardVerifiedEventData {
42
- /** The account ID of the verified card */
43
- account: string;
44
- /** Additional metadata about the card verification */
45
- metadata?: Record<string, any>;
46
- }
47
- /**
48
- * Account verification event data
49
- */
50
- interface AccountVerifiedEventData {
51
- /** The account ID of the verified account */
52
- account: string;
53
- /** Account verification details */
54
- account_verification?: {
55
- account_id: string;
56
- type: string;
57
- [key: string]: any;
58
- };
59
- /** Additional metadata */
60
- metadata?: Record<string, any>;
61
- }
62
35
  /**
63
36
  * Union type for all possible event data structures
64
37
  */
65
- type OpalEventData = OpalErrorData | CardVerifiedEventData | AccountVerifiedEventData | Record<string, any>;
66
- /**
67
- * Legacy error interface for backward compatibility
68
- */
69
- interface OpalError {
70
- code: string;
71
- message: string;
72
- type: 'api_error' | 'connection_error' | 'validation_error';
73
- }
38
+ type OpalEventData = OpalErrorData | OpalIdentityEventData | OpalConnectEventData | OpalCardConnectEventData | OpalAccountVerificationEventData;
39
+ type OpalIdentityEventData = {
40
+ entity_id: string;
41
+ };
42
+ type OpalConnectEventData = {
43
+ entity_id: string;
44
+ accounts: string[];
45
+ };
46
+ type OpalCardConnectEventData = {
47
+ entity_id: string;
48
+ accounts: string[];
49
+ };
50
+ type OpalAccountVerificationEventData = {
51
+ entity_id: string;
52
+ accounts: string[];
53
+ };
74
54
  /**
75
55
  * Configuration object for the useOpal hook
76
56
  */
@@ -83,19 +63,6 @@ interface OpalConfig {
83
63
  onExit?: (data?: any) => void;
84
64
  /** Called for all Opal events with properly typed event object */
85
65
  onEvent?: (event: OpalEvent) => void;
86
- /** Called when an error occurs */
87
- onError?: (error: OpalErrorData) => void;
88
- /** Called on successful completion */
89
- onSuccess?: (data: OpalSuccessData) => void;
90
- }
91
- /**
92
- * Success data structure for completed Opal sessions
93
- */
94
- interface OpalSuccessData {
95
- /** The session ID of the completed session */
96
- sessionId: string;
97
- /** Additional metadata from the session */
98
- metadata?: Record<string, any>;
99
66
  }
100
67
  /**
101
68
  * Options for opening an Opal session
@@ -104,46 +71,14 @@ interface OpalOpenOptions {
104
71
  /** The Opal token (otkn_*) obtained from POST /opal/token */
105
72
  token: string;
106
73
  }
107
- /**
108
- * Legacy message interface - use OpalEvent instead
109
- * @deprecated Use OpalEvent for better type safety
110
- */
111
- interface OpalMessage {
112
- type: string;
113
- mode: string;
114
- object: string;
115
- action: string;
116
- timestamp: string;
117
- }
118
74
  /**
119
75
  * Return type for the useOpal hook
120
76
  */
121
77
  interface UseOpalReturn {
122
- /** Opens Opal with the provided token and options */
123
78
  open: (options: OpalOpenOptions) => void;
124
- /** Closes the current Opal session */
125
79
  close: () => void;
126
- /** Whether Opal is loaded and ready for interaction */
127
- isReady: boolean;
128
- /** Whether Opal is currently open */
129
80
  isOpen: boolean;
130
- /** Current error state, if any */
131
- error: OpalError | OpalErrorData | null;
132
- }
133
- /**
134
- * Props for the OpalIframe component
135
- */
136
- interface OpalIframeProps {
137
- /** The Opal token */
138
- token: string;
139
- /** The full Opal URL with token */
140
- opalUrl: string;
141
- /** Callback for handling iframe messages */
142
- onMessage: (message: OpalEvent) => void;
143
- /** Callback for when the iframe should be closed */
144
- onClose: () => void;
145
- /** Optional styles for the iframe container */
146
- style?: React.CSSProperties;
81
+ error: OpalErrorData | null;
147
82
  }
148
83
 
149
84
  interface OpalProviderProps {
@@ -167,7 +102,6 @@ interface OpalProviderProps {
167
102
  * ```
168
103
  */
169
104
  declare function OpalProvider({ children }: OpalProviderProps): JSX.Element;
170
-
171
105
  /**
172
106
  * Hook for interacting with Opal within an OpalProvider context.
173
107
  * This hook allows you to configure event handlers and open/close Opal sessions.
@@ -175,21 +109,26 @@ declare function OpalProvider({ children }: OpalProviderProps): JSX.Element;
175
109
  *
176
110
  * @example
177
111
  * ```tsx
178
- * const { open, close, isReady, isOpen, error } = useOpal({
112
+ * const { open, close, isOpen, error } = useOpal({
179
113
  * env: 'dev',
180
114
  * onOpen: () => console.log('Opal opened'),
181
115
  * onExit: () => console.log('Opal closed'),
182
116
  * onEvent: (event) => {
183
117
  * switch (event.type) {
184
- * case 'opal.session.started':
118
+ * case OpalEventType.SESSION_STARTED:
185
119
  * console.log('Session started');
186
120
  * break;
187
- * case 'card_connect.card.verified':
188
- * console.log('Card verified:', event.data);
121
+ * case OpalEventType.SESSION_COMPLETED:
122
+ * console.log('Session completed:', event.data);
123
+ * break;
124
+ * case OpalEventType.SESSION_EXITED:
125
+ * console.log('Session exited:', event.data);
126
+ * break;
127
+ * case OpalEventType.SESSION_ERRORED:
128
+ * console.log('Session errored:', event.data);
189
129
  * break;
190
130
  * }
191
131
  * },
192
- * onError: (error) => console.error('Opal error:', error),
193
132
  * });
194
133
  *
195
134
  * // Open Opal with a token
@@ -204,7 +143,4 @@ declare function OpalProvider({ children }: OpalProviderProps): JSX.Element;
204
143
  */
205
144
  declare function useOpal(config?: OpalConfig): UseOpalReturn;
206
145
 
207
- declare function OpalIframe({ token, opalUrl, onMessage, style, }: OpalIframeProps): react_jsx_runtime.JSX.Element | null;
208
-
209
- export { OpalIframe, OpalProvider, useOpal };
210
- export type { AccountVerifiedEventData, CardVerifiedEventData, OpalConfig, OpalEnvironment, OpalError, OpalErrorData, OpalEvent, OpalEventAction, OpalEventData, OpalEventObject, OpalEventType, OpalIframeProps, OpalMessage, OpalMode, OpalOpenOptions, OpalSuccessData, UseOpalReturn };
146
+ export { OpalEventType, OpalProvider, useOpal };