@swype-org/react-sdk 0.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/dist/index.cjs +1845 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +277 -0
- package/dist/index.d.ts +277 -0
- package/dist/index.js +1835 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
/** Wallet provider (e.g. MetaMask) */
|
|
4
|
+
interface Provider {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
logoURI?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Blockchain chain */
|
|
10
|
+
interface Chain {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
}
|
|
14
|
+
/** Token balance within a wallet source */
|
|
15
|
+
interface TokenBalance {
|
|
16
|
+
available: Amount;
|
|
17
|
+
total: Amount;
|
|
18
|
+
}
|
|
19
|
+
/** Token within a wallet source */
|
|
20
|
+
interface WalletToken {
|
|
21
|
+
symbol: string;
|
|
22
|
+
status: string;
|
|
23
|
+
}
|
|
24
|
+
/** A token source within a wallet (e.g. USDC on a specific chain) */
|
|
25
|
+
interface WalletSource {
|
|
26
|
+
id: string;
|
|
27
|
+
token: WalletToken;
|
|
28
|
+
balance: TokenBalance;
|
|
29
|
+
}
|
|
30
|
+
/** Full wallet with chain, balance, and token sources */
|
|
31
|
+
interface Wallet {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
status: string;
|
|
35
|
+
sources: WalletSource[];
|
|
36
|
+
balance: TokenBalance;
|
|
37
|
+
chain: {
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
};
|
|
41
|
+
createDate: string;
|
|
42
|
+
updateDate: string;
|
|
43
|
+
authorizationSessions?: AuthorizationSession[];
|
|
44
|
+
}
|
|
45
|
+
/** Connected account containing wallets */
|
|
46
|
+
interface Account {
|
|
47
|
+
id: string;
|
|
48
|
+
name: string;
|
|
49
|
+
wallets: Wallet[];
|
|
50
|
+
createDate: string;
|
|
51
|
+
updateDate: string;
|
|
52
|
+
authorizationSessions?: AuthorizationSession[];
|
|
53
|
+
}
|
|
54
|
+
/** Authorization session (summary) */
|
|
55
|
+
interface AuthorizationSession {
|
|
56
|
+
id: string;
|
|
57
|
+
status: string;
|
|
58
|
+
uri: string;
|
|
59
|
+
}
|
|
60
|
+
/** A single authorization action within a session */
|
|
61
|
+
interface AuthorizationAction {
|
|
62
|
+
id: string;
|
|
63
|
+
type: string;
|
|
64
|
+
status: string;
|
|
65
|
+
orderIndex: number;
|
|
66
|
+
metadata?: Record<string, unknown>;
|
|
67
|
+
}
|
|
68
|
+
/** Full authorization session with ordered actions */
|
|
69
|
+
interface AuthorizationSessionDetail {
|
|
70
|
+
id: string;
|
|
71
|
+
status: string;
|
|
72
|
+
uri: string;
|
|
73
|
+
actions: AuthorizationAction[];
|
|
74
|
+
}
|
|
75
|
+
/** Monetary amount */
|
|
76
|
+
interface Amount {
|
|
77
|
+
amount: number;
|
|
78
|
+
currency: string;
|
|
79
|
+
}
|
|
80
|
+
/** Transfer destination in a response */
|
|
81
|
+
interface TransferDestination {
|
|
82
|
+
id: string;
|
|
83
|
+
chainId: string;
|
|
84
|
+
address: string;
|
|
85
|
+
token: {
|
|
86
|
+
symbol: string;
|
|
87
|
+
};
|
|
88
|
+
amount: Amount;
|
|
89
|
+
}
|
|
90
|
+
/** Transfer object returned by the API */
|
|
91
|
+
interface Transfer {
|
|
92
|
+
id: string;
|
|
93
|
+
status: string;
|
|
94
|
+
sources: Array<{
|
|
95
|
+
id: string;
|
|
96
|
+
status: string;
|
|
97
|
+
provider: Provider;
|
|
98
|
+
wallets: unknown[];
|
|
99
|
+
}>;
|
|
100
|
+
destinations: TransferDestination[];
|
|
101
|
+
amount: Amount;
|
|
102
|
+
createDate: string;
|
|
103
|
+
updateDate: string;
|
|
104
|
+
authorizationSessions: AuthorizationSession[];
|
|
105
|
+
}
|
|
106
|
+
/** Standard API error shape */
|
|
107
|
+
interface ErrorResponse {
|
|
108
|
+
code: string;
|
|
109
|
+
message: string;
|
|
110
|
+
details: Array<{
|
|
111
|
+
code?: string;
|
|
112
|
+
message?: string;
|
|
113
|
+
}>;
|
|
114
|
+
traceId?: string;
|
|
115
|
+
}
|
|
116
|
+
/** Result of executing a single authorization action */
|
|
117
|
+
interface ActionExecutionResult {
|
|
118
|
+
actionId: string;
|
|
119
|
+
type: string;
|
|
120
|
+
status: 'success' | 'error';
|
|
121
|
+
message: string;
|
|
122
|
+
data?: unknown;
|
|
123
|
+
}
|
|
124
|
+
/** Source type discriminator for transfer creation */
|
|
125
|
+
type SourceType = 'providerId' | 'accountId' | 'walletId' | 'tokenId';
|
|
126
|
+
/** Destination input provided by the host app */
|
|
127
|
+
interface Destination {
|
|
128
|
+
chainId: string;
|
|
129
|
+
address: string;
|
|
130
|
+
token: {
|
|
131
|
+
symbol: string;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/** List response wrapper */
|
|
135
|
+
interface ListResponse<T> {
|
|
136
|
+
items: T[];
|
|
137
|
+
}
|
|
138
|
+
/** User configuration preferences */
|
|
139
|
+
interface UserConfig {
|
|
140
|
+
defaultAllowance?: number;
|
|
141
|
+
}
|
|
142
|
+
/** Theme mode */
|
|
143
|
+
type ThemeMode = 'light' | 'dark';
|
|
144
|
+
/** Steps in the payment flow */
|
|
145
|
+
type PaymentStep = 'login' | 'select-source' | 'enter-amount' | 'processing' | 'complete';
|
|
146
|
+
|
|
147
|
+
interface ThemeTokens {
|
|
148
|
+
bg: string;
|
|
149
|
+
bgCard: string;
|
|
150
|
+
bgInput: string;
|
|
151
|
+
bgHover: string;
|
|
152
|
+
bgOverlay: string;
|
|
153
|
+
text: string;
|
|
154
|
+
textSecondary: string;
|
|
155
|
+
textMuted: string;
|
|
156
|
+
textInverse: string;
|
|
157
|
+
border: string;
|
|
158
|
+
borderFocus: string;
|
|
159
|
+
accent: string;
|
|
160
|
+
accentHover: string;
|
|
161
|
+
accentText: string;
|
|
162
|
+
success: string;
|
|
163
|
+
successBg: string;
|
|
164
|
+
error: string;
|
|
165
|
+
errorBg: string;
|
|
166
|
+
shadow: string;
|
|
167
|
+
shadowLg: string;
|
|
168
|
+
radius: string;
|
|
169
|
+
radiusLg: string;
|
|
170
|
+
}
|
|
171
|
+
declare const darkTheme: ThemeTokens;
|
|
172
|
+
declare const lightTheme: ThemeTokens;
|
|
173
|
+
declare function getTheme(mode: ThemeMode): ThemeTokens;
|
|
174
|
+
|
|
175
|
+
interface SwypeConfig {
|
|
176
|
+
apiBaseUrl: string;
|
|
177
|
+
theme: ThemeMode;
|
|
178
|
+
tokens: ThemeTokens;
|
|
179
|
+
}
|
|
180
|
+
interface SwypeProviderProps {
|
|
181
|
+
/** Base URL for the Swype API (e.g. "http://localhost:3000") */
|
|
182
|
+
apiBaseUrl: string;
|
|
183
|
+
/** Light or dark mode */
|
|
184
|
+
theme?: ThemeMode;
|
|
185
|
+
children: React.ReactNode;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Provides Swype SDK configuration and all required infrastructure
|
|
189
|
+
* (Privy auth, wagmi, React Query) to child components.
|
|
190
|
+
*
|
|
191
|
+
* Must wrap any `<SwypePayment>` usage. The integrator does **not** need
|
|
192
|
+
* to set up Privy, wagmi, or React Query — this provider handles it all.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```tsx
|
|
196
|
+
* <SwypeProvider apiBaseUrl="https://api.swype.com">
|
|
197
|
+
* <SwypePayment destination={dest} onComplete={handler} />
|
|
198
|
+
* </SwypeProvider>
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
declare function SwypeProvider({ apiBaseUrl, theme, children, }: SwypeProviderProps): react_jsx_runtime.JSX.Element;
|
|
202
|
+
/** Access the Swype SDK configuration. Throws if used outside SwypeProvider. */
|
|
203
|
+
declare function useSwypeConfig(): SwypeConfig;
|
|
204
|
+
|
|
205
|
+
interface SwypePaymentProps {
|
|
206
|
+
/**
|
|
207
|
+
* Where the funds go -- controlled by the host app (merchant).
|
|
208
|
+
*
|
|
209
|
+
* The merchant sets this prop and can update it at any time; the SDK
|
|
210
|
+
* reads it reactively whenever a transfer is created.
|
|
211
|
+
*/
|
|
212
|
+
destination: Destination;
|
|
213
|
+
/** Called when the transfer reaches COMPLETED status */
|
|
214
|
+
onComplete?: (transfer: Transfer) => void;
|
|
215
|
+
/** Called on unrecoverable error */
|
|
216
|
+
onError?: (error: string) => void;
|
|
217
|
+
}
|
|
218
|
+
declare function SwypePayment({ destination, onComplete, onError, }: SwypePaymentProps): react_jsx_runtime.JSX.Element | null;
|
|
219
|
+
|
|
220
|
+
interface UseTransferPollingResult {
|
|
221
|
+
transfer: Transfer | null;
|
|
222
|
+
error: string | null;
|
|
223
|
+
isPolling: boolean;
|
|
224
|
+
startPolling: (transferId: string) => void;
|
|
225
|
+
stopPolling: () => void;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Polls GET /v1/transfers/{id} every `intervalMs` until status is
|
|
229
|
+
* COMPLETED or FAILED.
|
|
230
|
+
*/
|
|
231
|
+
declare function useTransferPolling(intervalMs?: number): UseTransferPollingResult;
|
|
232
|
+
interface UseAuthorizationExecutorResult {
|
|
233
|
+
executing: boolean;
|
|
234
|
+
results: ActionExecutionResult[];
|
|
235
|
+
error: string | null;
|
|
236
|
+
executeSession: (transfer: Transfer) => Promise<void>;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Executes the full authorization flow for a transfer's first session:
|
|
240
|
+
* fetches the session, walks through PENDING actions (OPEN_PROVIDER,
|
|
241
|
+
* SWITCH_CHAIN, APPROVE_PERMIT_2, SIGN_PERMIT2), reports each completion
|
|
242
|
+
* to the server, and chains new actions that appear.
|
|
243
|
+
*/
|
|
244
|
+
declare function useAuthorizationExecutor(): UseAuthorizationExecutorResult;
|
|
245
|
+
|
|
246
|
+
declare function fetchProviders(apiBaseUrl: string, token: string): Promise<Provider[]>;
|
|
247
|
+
declare function fetchChains(apiBaseUrl: string, token: string): Promise<Chain[]>;
|
|
248
|
+
declare function fetchAccounts(apiBaseUrl: string, token: string): Promise<Account[]>;
|
|
249
|
+
interface CreateTransferParams {
|
|
250
|
+
sourceType: SourceType;
|
|
251
|
+
sourceId: string;
|
|
252
|
+
destination: Destination;
|
|
253
|
+
amount: number;
|
|
254
|
+
currency?: string;
|
|
255
|
+
}
|
|
256
|
+
declare function createTransfer(apiBaseUrl: string, token: string, params: CreateTransferParams): Promise<Transfer>;
|
|
257
|
+
declare function fetchTransfer(apiBaseUrl: string, token: string, transferId: string): Promise<Transfer>;
|
|
258
|
+
declare function fetchAuthorizationSession(apiBaseUrl: string, sessionId: string): Promise<AuthorizationSessionDetail>;
|
|
259
|
+
declare function updateUserConfig(apiBaseUrl: string, token: string, config: {
|
|
260
|
+
defaultAllowance: number;
|
|
261
|
+
}): Promise<void>;
|
|
262
|
+
declare function reportActionCompletion(apiBaseUrl: string, actionId: string, result: Record<string, unknown>): Promise<AuthorizationSessionDetail>;
|
|
263
|
+
|
|
264
|
+
type api_CreateTransferParams = CreateTransferParams;
|
|
265
|
+
declare const api_createTransfer: typeof createTransfer;
|
|
266
|
+
declare const api_fetchAccounts: typeof fetchAccounts;
|
|
267
|
+
declare const api_fetchAuthorizationSession: typeof fetchAuthorizationSession;
|
|
268
|
+
declare const api_fetchChains: typeof fetchChains;
|
|
269
|
+
declare const api_fetchProviders: typeof fetchProviders;
|
|
270
|
+
declare const api_fetchTransfer: typeof fetchTransfer;
|
|
271
|
+
declare const api_reportActionCompletion: typeof reportActionCompletion;
|
|
272
|
+
declare const api_updateUserConfig: typeof updateUserConfig;
|
|
273
|
+
declare namespace api {
|
|
274
|
+
export { type api_CreateTransferParams as CreateTransferParams, api_createTransfer as createTransfer, api_fetchAccounts as fetchAccounts, api_fetchAuthorizationSession as fetchAuthorizationSession, api_fetchChains as fetchChains, api_fetchProviders as fetchProviders, api_fetchTransfer as fetchTransfer, api_reportActionCompletion as reportActionCompletion, api_updateUserConfig as updateUserConfig };
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export { type Account, type ActionExecutionResult, type Amount, type AuthorizationAction, type AuthorizationSession, type AuthorizationSessionDetail, type Chain, type Destination, type ErrorResponse, type ListResponse, type PaymentStep, type Provider, type SourceType, SwypePayment, type SwypePaymentProps, SwypeProvider, type SwypeProviderProps, type ThemeMode, type ThemeTokens, type TokenBalance, type Transfer, type TransferDestination, type UserConfig, type Wallet, type WalletSource, type WalletToken, darkTheme, getTheme, lightTheme, api as swypeApi, useAuthorizationExecutor, useSwypeConfig, useTransferPolling };
|