@swype-org/deposit 0.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 +175 -0
- package/dist/chunk-RG2MWY2W.js +583 -0
- package/dist/chunk-RG2MWY2W.js.map +1 -0
- package/dist/index.cjs +594 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +78 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +633 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +54 -0
- package/dist/react.d.ts +54 -0
- package/dist/react.js +48 -0
- package/dist/react.js.map +1 -0
- package/dist/types-pHp6PcIz.d.cts +171 -0
- package/dist/types-pHp6PcIz.d.ts +171 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# @swype-org/deposit
|
|
2
|
+
|
|
3
|
+
Lightweight merchant deposit SDK — open a hosted Blink payment flow, handle completion, zero runtime dependencies.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @swype-org/deposit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { Deposit } from '@swype-org/deposit';
|
|
13
|
+
|
|
14
|
+
const deposit = new Deposit({ signer: '/api/sign-payment' });
|
|
15
|
+
|
|
16
|
+
document.getElementById('deposit-btn')!.addEventListener('click', async () => {
|
|
17
|
+
try {
|
|
18
|
+
const { transfer: result } = await deposit.requestDeposit({
|
|
19
|
+
amount: 50,
|
|
20
|
+
chainId: 8453,
|
|
21
|
+
address: '0x...', // destination wallet
|
|
22
|
+
token: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
23
|
+
});
|
|
24
|
+
console.log('Transfer complete:', result.id, result.status);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error('Transfer failed:', error);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
> **Important:** `requestDeposit()` must be called from a user-gesture handler (click, keypress, etc.) so the browser allows the iframe to open.
|
|
32
|
+
|
|
33
|
+
## React Hook
|
|
34
|
+
|
|
35
|
+
A dedicated React entry point eliminates all boilerplate:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install @swype-org/deposit react
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
import { useBlinkDeposit } from '@swype-org/deposit/react';
|
|
43
|
+
|
|
44
|
+
function DepositButton() {
|
|
45
|
+
const { status, result, error, displayMessage, requestDeposit } = useBlinkDeposit({
|
|
46
|
+
signer: '/api/sign-payment',
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<>
|
|
51
|
+
<button
|
|
52
|
+
onClick={() =>
|
|
53
|
+
requestDeposit({ amount: 50, chainId: 8453, address: '0x...', token: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' })
|
|
54
|
+
}
|
|
55
|
+
disabled={status === 'signer-loading'}
|
|
56
|
+
>
|
|
57
|
+
{status === 'signer-loading' ? 'Preparing…' : 'Deposit'}
|
|
58
|
+
</button>
|
|
59
|
+
{error && <p>{displayMessage}</p>}
|
|
60
|
+
{result && <p>Transfer {result.transfer.id} complete!</p>}
|
|
61
|
+
</>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The hook returns reactive `status`, `result`, `error`, `displayMessage`, and `isActive` values, plus `requestDeposit`, `focus`, and `close` actions. It manages the `Deposit` lifecycle and cleans up on unmount.
|
|
67
|
+
|
|
68
|
+
## How It Works
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
Merchant App / SDK Merchant Signer Hosted Flow (iframe)
|
|
72
|
+
│ │ │
|
|
73
|
+
│ 1. requestDeposit(request) │ │
|
|
74
|
+
│──────────────────────────────► │ │
|
|
75
|
+
│ │ 2. signer(data) or POST URL │
|
|
76
|
+
│ │ (includes webviewBaseUrl) │
|
|
77
|
+
│ 3. { signature, payload, ...} │ │
|
|
78
|
+
│◄───────────────────────────────│ │
|
|
79
|
+
│ │
|
|
80
|
+
│ 4. SDK builds URL, opens iframe │
|
|
81
|
+
│───────────────────────────────────────────────────────────────► │
|
|
82
|
+
│ │
|
|
83
|
+
│ 5. User completes payment in hosted flow │
|
|
84
|
+
│ │
|
|
85
|
+
│ 6. postMessage: blink:transfer-complete │
|
|
86
|
+
│◄────────────────────────────────────────────────────────────── │
|
|
87
|
+
│ │
|
|
88
|
+
│ 7. Promise resolves with DepositResult │
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Configuration
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const deposit = new Deposit({
|
|
95
|
+
signer: '/api/sign-payment',
|
|
96
|
+
webviewBaseUrl: 'https://pay.tryblink.xyz',
|
|
97
|
+
hostedFlowOrigin: 'https://pay.tryblink.xyz',
|
|
98
|
+
containerElement: document.getElementById('deposit-root')!,
|
|
99
|
+
signerTimeoutMs: 15_000,
|
|
100
|
+
flowTimeoutMs: 300_000,
|
|
101
|
+
debug: false,
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Error Handling
|
|
106
|
+
|
|
107
|
+
Every error is a `DepositError` with a machine-readable `code`:
|
|
108
|
+
|
|
109
|
+
| Code | Meaning |
|
|
110
|
+
| ------------------------ | ----------------------------------------------- |
|
|
111
|
+
| `DEPOSIT_DISMISSED` | User closed the transfer before completing |
|
|
112
|
+
| `SIGNER_REQUEST_FAILED` | Signer returned a non-2xx response |
|
|
113
|
+
| `SIGNER_NETWORK_ERROR` | Network failure reaching the signer |
|
|
114
|
+
| `SIGNER_RESPONSE_INVALID`| Signer response missing required fields |
|
|
115
|
+
| `SIGNER_TIMEOUT` | Signer did not respond within `signerTimeoutMs` |
|
|
116
|
+
| `FLOW_TIMEOUT` | Entire flow exceeded `flowTimeoutMs` |
|
|
117
|
+
| `INVALID_REQUEST` | Bad input (amount, address, etc.) |
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { DepositError, getDisplayMessage } from '@swype-org/deposit';
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
await deposit.requestDeposit({ /* ... */ });
|
|
124
|
+
} catch (err) {
|
|
125
|
+
if (err instanceof DepositError) {
|
|
126
|
+
showToast(getDisplayMessage(err));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Events
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
transfer.on('complete', (result) => { /* DepositResult */ });
|
|
135
|
+
transfer.on('error', (error) => { /* DepositError */ });
|
|
136
|
+
transfer.on('close', () => { /* iframe closed */ });
|
|
137
|
+
transfer.on('status-change', (status) => { /* DepositStatus */ });
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Lifecycle
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
transfer.focus(); // No-op — retained for API compatibility
|
|
144
|
+
transfer.close(); // Close the iframe without waiting for completion
|
|
145
|
+
transfer.destroy(); // Tear down and release all resources (call on unmount)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## TypeScript
|
|
149
|
+
|
|
150
|
+
All types are exported:
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import type {
|
|
154
|
+
DepositConfig,
|
|
155
|
+
DepositStatus,
|
|
156
|
+
DepositRequest,
|
|
157
|
+
DepositResult,
|
|
158
|
+
SignerFunction,
|
|
159
|
+
SignerRequest,
|
|
160
|
+
SignerResponse,
|
|
161
|
+
TransferSummary,
|
|
162
|
+
} from '@swype-org/deposit';
|
|
163
|
+
|
|
164
|
+
import type { DepositErrorCode } from '@swype-org/deposit';
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Backward Compatibility
|
|
168
|
+
|
|
169
|
+
The previous `Checkout`-named symbols are re-exported as deprecated aliases:
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import { Checkout } from '@swype-org/deposit'; // deprecated alias for Transfer
|
|
173
|
+
import { CheckoutError } from '@swype-org/deposit'; // deprecated alias for DepositError
|
|
174
|
+
import { useBlinkCheckout } from '@swype-org/deposit/react'; // deprecated alias for useBlinkDeposit
|
|
175
|
+
```
|