@edge-markets/connect-link 1.0.3 → 1.3.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 +58 -3
- package/dist/index.d.mts +527 -131
- package/dist/index.d.ts +527 -131
- package/dist/index.js +605 -9
- package/dist/index.mjs +599 -4
- package/package.json +22 -14
package/README.md
CHANGED
|
@@ -94,10 +94,12 @@ interface EdgeLinkConfig {
|
|
|
94
94
|
onEvent?: (event) => void // Called for analytics events
|
|
95
95
|
scopes?: EdgeScope[] // Scopes to request (default: all)
|
|
96
96
|
linkUrl?: string // Custom Link URL (dev only)
|
|
97
|
-
redirectUri?: string // Custom redirect URI
|
|
97
|
+
redirectUri?: string // Custom redirect URI (default: window.location.origin + '/oauth/edge/callback')
|
|
98
98
|
}
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
+
The `redirectUri` is automatically set to `${window.location.origin}/oauth/edge/callback` if not provided.
|
|
102
|
+
|
|
101
103
|
## Callbacks
|
|
102
104
|
|
|
103
105
|
### onSuccess
|
|
@@ -179,7 +181,55 @@ const link = new EdgeLink({
|
|
|
179
181
|
})
|
|
180
182
|
```
|
|
181
183
|
|
|
182
|
-
## React
|
|
184
|
+
## React Hook
|
|
185
|
+
|
|
186
|
+
The recommended way to use EdgeLink in React:
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
import { useEdgeLink } from '@edge-markets/connect-link'
|
|
190
|
+
|
|
191
|
+
function ConnectButton() {
|
|
192
|
+
const { open, ready, isOpen, error } = useEdgeLink({
|
|
193
|
+
clientId: process.env.NEXT_PUBLIC_EDGE_CLIENT_ID!,
|
|
194
|
+
environment: 'staging',
|
|
195
|
+
onSuccess: async (result) => {
|
|
196
|
+
await fetch('/api/edge/exchange', {
|
|
197
|
+
method: 'POST',
|
|
198
|
+
headers: { 'Content-Type': 'application/json' },
|
|
199
|
+
body: JSON.stringify(result),
|
|
200
|
+
})
|
|
201
|
+
},
|
|
202
|
+
onExit: (metadata) => {
|
|
203
|
+
if (metadata.reason === 'popup_blocked') {
|
|
204
|
+
alert('Please allow popups')
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
if (error) {
|
|
210
|
+
return <div>Error: {error.message}</div>
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<button onClick={() => open()} disabled={!ready || isOpen}>
|
|
215
|
+
{isOpen ? 'Connecting...' : 'Connect EdgeBoost'}
|
|
216
|
+
</button>
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Hook Return Values
|
|
222
|
+
|
|
223
|
+
| Property | Type | Description |
|
|
224
|
+
|----------|------|-------------|
|
|
225
|
+
| `open` | `(options?) => void` | Opens the Link popup |
|
|
226
|
+
| `ready` | `boolean` | True when EdgeLink is initialized |
|
|
227
|
+
| `isOpen` | `boolean` | True when popup is open |
|
|
228
|
+
| `error` | `Error \| null` | Initialization or runtime error |
|
|
229
|
+
|
|
230
|
+
## Manual React Example
|
|
231
|
+
|
|
232
|
+
For more control, you can use EdgeLink directly:
|
|
183
233
|
|
|
184
234
|
```tsx
|
|
185
235
|
import { useEffect, useRef, useCallback } from 'react'
|
|
@@ -197,7 +247,6 @@ function ConnectButton() {
|
|
|
197
247
|
method: 'POST',
|
|
198
248
|
body: JSON.stringify(result),
|
|
199
249
|
})
|
|
200
|
-
// Refresh user state
|
|
201
250
|
},
|
|
202
251
|
onExit: (metadata) => {
|
|
203
252
|
if (metadata.reason === 'popup_blocked') {
|
|
@@ -269,3 +318,9 @@ function ConnectButton() {
|
|
|
269
318
|
MIT
|
|
270
319
|
|
|
271
320
|
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|