@swype-org/react-sdk 0.1.0 → 0.1.2
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 +1357 -491
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +77 -5
- package/dist/index.d.ts +77 -5
- package/dist/index.js +1359 -494
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -27,6 +27,11 @@ interface WalletSource {
|
|
|
27
27
|
token: WalletToken;
|
|
28
28
|
balance: TokenBalance;
|
|
29
29
|
}
|
|
30
|
+
/** Token + chain most recently authorized via Permit2 for a wallet */
|
|
31
|
+
interface LastAuthorizedToken {
|
|
32
|
+
symbol: string;
|
|
33
|
+
chainName: string;
|
|
34
|
+
}
|
|
30
35
|
/** Full wallet with chain, balance, and token sources */
|
|
31
36
|
interface Wallet {
|
|
32
37
|
id: string;
|
|
@@ -38,6 +43,8 @@ interface Wallet {
|
|
|
38
43
|
id: string;
|
|
39
44
|
name: string;
|
|
40
45
|
};
|
|
46
|
+
/** The token+chain most recently authorized via Permit2, if any. */
|
|
47
|
+
lastAuthorizedToken?: LastAuthorizedToken | null;
|
|
41
48
|
createDate: string;
|
|
42
49
|
updateDate: string;
|
|
43
50
|
authorizationSessions?: AuthorizationSession[];
|
|
@@ -123,6 +130,11 @@ interface ActionExecutionResult {
|
|
|
123
130
|
}
|
|
124
131
|
/** Source type discriminator for transfer creation */
|
|
125
132
|
type SourceType = 'providerId' | 'accountId' | 'walletId' | 'tokenId';
|
|
133
|
+
/** User's chain+token selection for the SELECT_SOURCE action. */
|
|
134
|
+
interface SourceSelection {
|
|
135
|
+
chainName: string;
|
|
136
|
+
tokenSymbol: string;
|
|
137
|
+
}
|
|
126
138
|
/** Destination input provided by the host app */
|
|
127
139
|
interface Destination {
|
|
128
140
|
chainId: string;
|
|
@@ -142,7 +154,19 @@ interface UserConfig {
|
|
|
142
154
|
/** Theme mode */
|
|
143
155
|
type ThemeMode = 'light' | 'dark';
|
|
144
156
|
/** Steps in the payment flow */
|
|
145
|
-
type PaymentStep = 'login' | '
|
|
157
|
+
type PaymentStep = 'login' | 'enter-amount' | 'ready' | 'processing' | 'complete';
|
|
158
|
+
/** User-selected advanced settings for chain/asset override */
|
|
159
|
+
interface AdvancedSettings {
|
|
160
|
+
/** Override asset (e.g. 'USDC', 'USDT'). Null = let backend decide. */
|
|
161
|
+
asset: string | null;
|
|
162
|
+
/** Override chain name (e.g. 'Base', 'Ethereum'). Null = let backend decide. */
|
|
163
|
+
chain: string | null;
|
|
164
|
+
}
|
|
165
|
+
/** User's top-up allowance selection for the SIGN_PERMIT2 action. */
|
|
166
|
+
interface AllowanceSelection {
|
|
167
|
+
/** Extra amount (in human-readable units, e.g. 100 = $100) to add on top of the transfer amount. */
|
|
168
|
+
topUpAmount: number;
|
|
169
|
+
}
|
|
146
170
|
|
|
147
171
|
interface ThemeTokens {
|
|
148
172
|
bg: string;
|
|
@@ -176,6 +200,10 @@ interface SwypeConfig {
|
|
|
176
200
|
apiBaseUrl: string;
|
|
177
201
|
theme: ThemeMode;
|
|
178
202
|
tokens: ThemeTokens;
|
|
203
|
+
/** Pre-set deposit amount (controlled by host app via useSwypeDepositAmount) */
|
|
204
|
+
depositAmount: number | null;
|
|
205
|
+
/** Update the deposit amount from a host-app component */
|
|
206
|
+
setDepositAmount: (amount: number | null) => void;
|
|
179
207
|
}
|
|
180
208
|
interface SwypeProviderProps {
|
|
181
209
|
/** Base URL for the Swype API (e.g. "http://localhost:3000") */
|
|
@@ -201,6 +229,26 @@ interface SwypeProviderProps {
|
|
|
201
229
|
declare function SwypeProvider({ apiBaseUrl, theme, children, }: SwypeProviderProps): react_jsx_runtime.JSX.Element;
|
|
202
230
|
/** Access the Swype SDK configuration. Throws if used outside SwypeProvider. */
|
|
203
231
|
declare function useSwypeConfig(): SwypeConfig;
|
|
232
|
+
/**
|
|
233
|
+
* Hook for host apps to pre-set the deposit amount before showing the
|
|
234
|
+
* payment widget. When set, the amount field in SwypePayment is
|
|
235
|
+
* auto-populated.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```tsx
|
|
239
|
+
* function ProductPage() {
|
|
240
|
+
* const { setAmount } = useSwypeDepositAmount();
|
|
241
|
+
* useEffect(() => { setAmount(25.00); }, []);
|
|
242
|
+
* return <SwypePayment destination={dest} />;
|
|
243
|
+
* }
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
declare function useSwypeDepositAmount(): {
|
|
247
|
+
/** Current deposit amount, or null if not set */
|
|
248
|
+
amount: number | null;
|
|
249
|
+
/** Set the deposit amount (pass null to clear) */
|
|
250
|
+
setAmount: (amount: number | null) => void;
|
|
251
|
+
};
|
|
204
252
|
|
|
205
253
|
interface SwypePaymentProps {
|
|
206
254
|
/**
|
|
@@ -233,13 +281,26 @@ interface UseAuthorizationExecutorResult {
|
|
|
233
281
|
executing: boolean;
|
|
234
282
|
results: ActionExecutionResult[];
|
|
235
283
|
error: string | null;
|
|
284
|
+
/** The SELECT_SOURCE action when paused for user selection, null otherwise. */
|
|
285
|
+
pendingSelectSource: AuthorizationAction | null;
|
|
286
|
+
/** Call this from the UI to provide the user's chain+token choice. */
|
|
287
|
+
resolveSelectSource: (selection: SourceSelection) => void;
|
|
288
|
+
/** The SIGN_PERMIT2 action when paused for allowance selection, null otherwise. */
|
|
289
|
+
pendingAllowanceSelection: AuthorizationAction | null;
|
|
290
|
+
/** Call this from the UI to provide the user's top-up allowance choice. */
|
|
291
|
+
resolveAllowanceSelection: (selection: AllowanceSelection) => void;
|
|
236
292
|
executeSession: (transfer: Transfer) => Promise<void>;
|
|
237
293
|
}
|
|
238
294
|
/**
|
|
239
295
|
* Executes the full authorization flow for a transfer's first session:
|
|
240
296
|
* fetches the session, walks through PENDING actions (OPEN_PROVIDER,
|
|
241
|
-
* SWITCH_CHAIN, APPROVE_PERMIT_2, SIGN_PERMIT2), reports
|
|
242
|
-
* to the server, and chains new actions that appear.
|
|
297
|
+
* SELECT_SOURCE, SWITCH_CHAIN, APPROVE_PERMIT_2, SIGN_PERMIT2), reports
|
|
298
|
+
* each completion to the server, and chains new actions that appear.
|
|
299
|
+
*
|
|
300
|
+
* When a SELECT_SOURCE action is encountered, the executor pauses and
|
|
301
|
+
* exposes the action via `pendingSelectSource`. The UI should display
|
|
302
|
+
* a chain+token selector and call `resolveSelectSource()` with the
|
|
303
|
+
* user's choice. The executor then resumes automatically.
|
|
243
304
|
*/
|
|
244
305
|
declare function useAuthorizationExecutor(): UseAuthorizationExecutorResult;
|
|
245
306
|
|
|
@@ -259,6 +320,16 @@ declare function fetchAuthorizationSession(apiBaseUrl: string, sessionId: string
|
|
|
259
320
|
declare function updateUserConfig(apiBaseUrl: string, token: string, config: {
|
|
260
321
|
defaultAllowance: number;
|
|
261
322
|
}): Promise<void>;
|
|
323
|
+
/**
|
|
324
|
+
* Updates the user's default allowance, authenticated by session ID.
|
|
325
|
+
* PATCH /v1/authorization-sessions/{id}/user-config
|
|
326
|
+
*
|
|
327
|
+
* This does not require a bearer token — the session ID itself serves
|
|
328
|
+
* as proof of authorization.
|
|
329
|
+
*/
|
|
330
|
+
declare function updateUserConfigBySession(apiBaseUrl: string, sessionId: string, config: {
|
|
331
|
+
defaultAllowance: number;
|
|
332
|
+
}): Promise<void>;
|
|
262
333
|
declare function reportActionCompletion(apiBaseUrl: string, actionId: string, result: Record<string, unknown>): Promise<AuthorizationSessionDetail>;
|
|
263
334
|
|
|
264
335
|
type api_CreateTransferParams = CreateTransferParams;
|
|
@@ -270,8 +341,9 @@ declare const api_fetchProviders: typeof fetchProviders;
|
|
|
270
341
|
declare const api_fetchTransfer: typeof fetchTransfer;
|
|
271
342
|
declare const api_reportActionCompletion: typeof reportActionCompletion;
|
|
272
343
|
declare const api_updateUserConfig: typeof updateUserConfig;
|
|
344
|
+
declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
|
|
273
345
|
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 };
|
|
346
|
+
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, api_updateUserConfigBySession as updateUserConfigBySession };
|
|
275
347
|
}
|
|
276
348
|
|
|
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 };
|
|
349
|
+
export { type Account, type ActionExecutionResult, type AdvancedSettings, 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, useSwypeDepositAmount, useTransferPolling };
|
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,11 @@ interface WalletSource {
|
|
|
27
27
|
token: WalletToken;
|
|
28
28
|
balance: TokenBalance;
|
|
29
29
|
}
|
|
30
|
+
/** Token + chain most recently authorized via Permit2 for a wallet */
|
|
31
|
+
interface LastAuthorizedToken {
|
|
32
|
+
symbol: string;
|
|
33
|
+
chainName: string;
|
|
34
|
+
}
|
|
30
35
|
/** Full wallet with chain, balance, and token sources */
|
|
31
36
|
interface Wallet {
|
|
32
37
|
id: string;
|
|
@@ -38,6 +43,8 @@ interface Wallet {
|
|
|
38
43
|
id: string;
|
|
39
44
|
name: string;
|
|
40
45
|
};
|
|
46
|
+
/** The token+chain most recently authorized via Permit2, if any. */
|
|
47
|
+
lastAuthorizedToken?: LastAuthorizedToken | null;
|
|
41
48
|
createDate: string;
|
|
42
49
|
updateDate: string;
|
|
43
50
|
authorizationSessions?: AuthorizationSession[];
|
|
@@ -123,6 +130,11 @@ interface ActionExecutionResult {
|
|
|
123
130
|
}
|
|
124
131
|
/** Source type discriminator for transfer creation */
|
|
125
132
|
type SourceType = 'providerId' | 'accountId' | 'walletId' | 'tokenId';
|
|
133
|
+
/** User's chain+token selection for the SELECT_SOURCE action. */
|
|
134
|
+
interface SourceSelection {
|
|
135
|
+
chainName: string;
|
|
136
|
+
tokenSymbol: string;
|
|
137
|
+
}
|
|
126
138
|
/** Destination input provided by the host app */
|
|
127
139
|
interface Destination {
|
|
128
140
|
chainId: string;
|
|
@@ -142,7 +154,19 @@ interface UserConfig {
|
|
|
142
154
|
/** Theme mode */
|
|
143
155
|
type ThemeMode = 'light' | 'dark';
|
|
144
156
|
/** Steps in the payment flow */
|
|
145
|
-
type PaymentStep = 'login' | '
|
|
157
|
+
type PaymentStep = 'login' | 'enter-amount' | 'ready' | 'processing' | 'complete';
|
|
158
|
+
/** User-selected advanced settings for chain/asset override */
|
|
159
|
+
interface AdvancedSettings {
|
|
160
|
+
/** Override asset (e.g. 'USDC', 'USDT'). Null = let backend decide. */
|
|
161
|
+
asset: string | null;
|
|
162
|
+
/** Override chain name (e.g. 'Base', 'Ethereum'). Null = let backend decide. */
|
|
163
|
+
chain: string | null;
|
|
164
|
+
}
|
|
165
|
+
/** User's top-up allowance selection for the SIGN_PERMIT2 action. */
|
|
166
|
+
interface AllowanceSelection {
|
|
167
|
+
/** Extra amount (in human-readable units, e.g. 100 = $100) to add on top of the transfer amount. */
|
|
168
|
+
topUpAmount: number;
|
|
169
|
+
}
|
|
146
170
|
|
|
147
171
|
interface ThemeTokens {
|
|
148
172
|
bg: string;
|
|
@@ -176,6 +200,10 @@ interface SwypeConfig {
|
|
|
176
200
|
apiBaseUrl: string;
|
|
177
201
|
theme: ThemeMode;
|
|
178
202
|
tokens: ThemeTokens;
|
|
203
|
+
/** Pre-set deposit amount (controlled by host app via useSwypeDepositAmount) */
|
|
204
|
+
depositAmount: number | null;
|
|
205
|
+
/** Update the deposit amount from a host-app component */
|
|
206
|
+
setDepositAmount: (amount: number | null) => void;
|
|
179
207
|
}
|
|
180
208
|
interface SwypeProviderProps {
|
|
181
209
|
/** Base URL for the Swype API (e.g. "http://localhost:3000") */
|
|
@@ -201,6 +229,26 @@ interface SwypeProviderProps {
|
|
|
201
229
|
declare function SwypeProvider({ apiBaseUrl, theme, children, }: SwypeProviderProps): react_jsx_runtime.JSX.Element;
|
|
202
230
|
/** Access the Swype SDK configuration. Throws if used outside SwypeProvider. */
|
|
203
231
|
declare function useSwypeConfig(): SwypeConfig;
|
|
232
|
+
/**
|
|
233
|
+
* Hook for host apps to pre-set the deposit amount before showing the
|
|
234
|
+
* payment widget. When set, the amount field in SwypePayment is
|
|
235
|
+
* auto-populated.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```tsx
|
|
239
|
+
* function ProductPage() {
|
|
240
|
+
* const { setAmount } = useSwypeDepositAmount();
|
|
241
|
+
* useEffect(() => { setAmount(25.00); }, []);
|
|
242
|
+
* return <SwypePayment destination={dest} />;
|
|
243
|
+
* }
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
declare function useSwypeDepositAmount(): {
|
|
247
|
+
/** Current deposit amount, or null if not set */
|
|
248
|
+
amount: number | null;
|
|
249
|
+
/** Set the deposit amount (pass null to clear) */
|
|
250
|
+
setAmount: (amount: number | null) => void;
|
|
251
|
+
};
|
|
204
252
|
|
|
205
253
|
interface SwypePaymentProps {
|
|
206
254
|
/**
|
|
@@ -233,13 +281,26 @@ interface UseAuthorizationExecutorResult {
|
|
|
233
281
|
executing: boolean;
|
|
234
282
|
results: ActionExecutionResult[];
|
|
235
283
|
error: string | null;
|
|
284
|
+
/** The SELECT_SOURCE action when paused for user selection, null otherwise. */
|
|
285
|
+
pendingSelectSource: AuthorizationAction | null;
|
|
286
|
+
/** Call this from the UI to provide the user's chain+token choice. */
|
|
287
|
+
resolveSelectSource: (selection: SourceSelection) => void;
|
|
288
|
+
/** The SIGN_PERMIT2 action when paused for allowance selection, null otherwise. */
|
|
289
|
+
pendingAllowanceSelection: AuthorizationAction | null;
|
|
290
|
+
/** Call this from the UI to provide the user's top-up allowance choice. */
|
|
291
|
+
resolveAllowanceSelection: (selection: AllowanceSelection) => void;
|
|
236
292
|
executeSession: (transfer: Transfer) => Promise<void>;
|
|
237
293
|
}
|
|
238
294
|
/**
|
|
239
295
|
* Executes the full authorization flow for a transfer's first session:
|
|
240
296
|
* fetches the session, walks through PENDING actions (OPEN_PROVIDER,
|
|
241
|
-
* SWITCH_CHAIN, APPROVE_PERMIT_2, SIGN_PERMIT2), reports
|
|
242
|
-
* to the server, and chains new actions that appear.
|
|
297
|
+
* SELECT_SOURCE, SWITCH_CHAIN, APPROVE_PERMIT_2, SIGN_PERMIT2), reports
|
|
298
|
+
* each completion to the server, and chains new actions that appear.
|
|
299
|
+
*
|
|
300
|
+
* When a SELECT_SOURCE action is encountered, the executor pauses and
|
|
301
|
+
* exposes the action via `pendingSelectSource`. The UI should display
|
|
302
|
+
* a chain+token selector and call `resolveSelectSource()` with the
|
|
303
|
+
* user's choice. The executor then resumes automatically.
|
|
243
304
|
*/
|
|
244
305
|
declare function useAuthorizationExecutor(): UseAuthorizationExecutorResult;
|
|
245
306
|
|
|
@@ -259,6 +320,16 @@ declare function fetchAuthorizationSession(apiBaseUrl: string, sessionId: string
|
|
|
259
320
|
declare function updateUserConfig(apiBaseUrl: string, token: string, config: {
|
|
260
321
|
defaultAllowance: number;
|
|
261
322
|
}): Promise<void>;
|
|
323
|
+
/**
|
|
324
|
+
* Updates the user's default allowance, authenticated by session ID.
|
|
325
|
+
* PATCH /v1/authorization-sessions/{id}/user-config
|
|
326
|
+
*
|
|
327
|
+
* This does not require a bearer token — the session ID itself serves
|
|
328
|
+
* as proof of authorization.
|
|
329
|
+
*/
|
|
330
|
+
declare function updateUserConfigBySession(apiBaseUrl: string, sessionId: string, config: {
|
|
331
|
+
defaultAllowance: number;
|
|
332
|
+
}): Promise<void>;
|
|
262
333
|
declare function reportActionCompletion(apiBaseUrl: string, actionId: string, result: Record<string, unknown>): Promise<AuthorizationSessionDetail>;
|
|
263
334
|
|
|
264
335
|
type api_CreateTransferParams = CreateTransferParams;
|
|
@@ -270,8 +341,9 @@ declare const api_fetchProviders: typeof fetchProviders;
|
|
|
270
341
|
declare const api_fetchTransfer: typeof fetchTransfer;
|
|
271
342
|
declare const api_reportActionCompletion: typeof reportActionCompletion;
|
|
272
343
|
declare const api_updateUserConfig: typeof updateUserConfig;
|
|
344
|
+
declare const api_updateUserConfigBySession: typeof updateUserConfigBySession;
|
|
273
345
|
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 };
|
|
346
|
+
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, api_updateUserConfigBySession as updateUserConfigBySession };
|
|
275
347
|
}
|
|
276
348
|
|
|
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 };
|
|
349
|
+
export { type Account, type ActionExecutionResult, type AdvancedSettings, 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, useSwypeDepositAmount, useTransferPolling };
|