@swype-org/deposit-mobile 0.2.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.
@@ -0,0 +1,139 @@
1
+ import { M as MobileDepositStatus, D as DepositResult, a as DepositError, b as MobileDepositConfig, c as DepositRequest, T as TransferSummary } from './types-Df_KwICF.cjs';
2
+ export { C as CheckoutError, d as CheckoutErrorCode, e as DepositMobileErrorCode, f as MobileCheckoutConfig, g as MobileCheckoutStatus, S as SignerFunction, h as SignerRequest, i as SignerResponse, j as getDisplayMessage } from './types-Df_KwICF.cjs';
3
+
4
+ declare const DEFAULT_WEBVIEW_BASE_URL = "https://pay-staging.tryblink.xyz";
5
+ type EventMap = {
6
+ complete: (result: DepositResult) => void;
7
+ error: (error: DepositError) => void;
8
+ dismiss: () => void;
9
+ 'status-change': (status: MobileDepositStatus) => void;
10
+ };
11
+ type EventName = keyof EventMap;
12
+ /**
13
+ * Mobile deposit SDK.
14
+ *
15
+ * Opens a hosted payment flow in an in-app browser, waits for the result
16
+ * via deep link callback, and resolves when the user completes payment.
17
+ *
18
+ * ```ts
19
+ * const deposit = new MobileDeposit({
20
+ * signer: 'https://api.merchant.com/sign-payment',
21
+ * callbackScheme: 'myapp',
22
+ * openUrl: (url) => WebBrowser.openBrowserAsync(url),
23
+ * });
24
+ *
25
+ * // When a deep link arrives, pass it to the SDK:
26
+ * Linking.addEventListener('url', ({ url }) => deposit.handleDeepLink(url));
27
+ *
28
+ * // Start a deposit:
29
+ * const result = await deposit.requestDeposit({
30
+ * amount: 50,
31
+ * chainId: 8453,
32
+ * address: '0x...',
33
+ * token: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
34
+ * });
35
+ * ```
36
+ */
37
+ declare class MobileDeposit {
38
+ private readonly config;
39
+ private requestId;
40
+ private destroyed;
41
+ private _status;
42
+ private _result;
43
+ private _error;
44
+ private flowTimer;
45
+ private lastSignerResponse;
46
+ private pendingResolve;
47
+ private pendingReject;
48
+ private pendingRequestId;
49
+ private listeners;
50
+ /** Current phase of the deposit flow. */
51
+ get status(): MobileDepositStatus;
52
+ /** Last successful {@link DepositResult}, available when `status === 'completed'`. */
53
+ get result(): DepositResult | null;
54
+ /** Last {@link DepositError}, available when `status === 'error'`. */
55
+ get error(): DepositError | null;
56
+ /** Whether a deposit flow is currently in progress. */
57
+ get isActive(): boolean;
58
+ constructor(config: MobileDepositConfig);
59
+ /**
60
+ * Open the hosted payment flow for the given deposit.
61
+ *
62
+ * The returned Promise resolves when the user completes the payment (via
63
+ * deep link callback) and rejects with a {@link DepositError} on failure.
64
+ *
65
+ * The merchant must listen for incoming deep links and pass them to
66
+ * {@link handleDeepLink} for the promise to resolve.
67
+ */
68
+ requestDeposit(request: DepositRequest): Promise<DepositResult>;
69
+ /**
70
+ * Feed an incoming deep link URL to the SDK.
71
+ *
72
+ * Returns `true` if the URL was a valid Swype callback and the SDK handled
73
+ * it. Returns `false` if the URL did not match the expected callback pattern
74
+ * (the merchant should handle it themselves).
75
+ *
76
+ * Typically called from `Linking.addEventListener('url', ...)` or the
77
+ * equivalent deep link handler on the platform.
78
+ */
79
+ handleDeepLink(url: string): boolean;
80
+ /** Register an event listener. */
81
+ on<K extends EventName>(event: K, handler: EventMap[K]): this;
82
+ /** Remove a previously registered event listener. */
83
+ off<K extends EventName>(event: K, handler: EventMap[K]): this;
84
+ /**
85
+ * Cancel the current flow. Rejects the pending promise with
86
+ * `BROWSER_DISMISSED` and resets to idle.
87
+ */
88
+ close(): void;
89
+ /** Tear down the instance and release all resources. */
90
+ destroy(): void;
91
+ private log;
92
+ private setStatus;
93
+ private runSignerFlow;
94
+ private cleanup;
95
+ private emit;
96
+ }
97
+ /** @deprecated Use {@link MobileDeposit} instead. */
98
+ declare const MobileCheckout: typeof MobileDeposit;
99
+
100
+ /**
101
+ * Parsed result from a Swype deep link callback.
102
+ *
103
+ * @internal
104
+ */
105
+ interface DeepLinkResult {
106
+ transferId: string;
107
+ transferStatus: string;
108
+ amount?: number;
109
+ currency?: string;
110
+ chainId?: string;
111
+ address?: string;
112
+ token?: string;
113
+ }
114
+ /**
115
+ * Check whether a URL matches the expected Swype callback deep link pattern.
116
+ */
117
+ declare function isSwypeCallback(url: string, callbackScheme: string, callbackPath?: string): boolean;
118
+ /**
119
+ * Parse a Swype callback deep link URL into a {@link DeepLinkResult}.
120
+ *
121
+ * Returns `null` if the URL does not match the expected scheme/path or is
122
+ * missing the required `transferId` parameter.
123
+ *
124
+ * Expected format:
125
+ * ```
126
+ * {scheme}://{path}?transferId=xxx&transferStatus=completed&amount=50&currency=USD&chainId=8453&address=0x...&token=USDC
127
+ * ```
128
+ */
129
+ declare function parseDeepLink(url: string, callbackScheme: string, callbackPath?: string): DeepLinkResult | null;
130
+ /**
131
+ * Convert a parsed deep link result into a {@link TransferSummary}.
132
+ *
133
+ * @internal
134
+ */
135
+ declare function toTransferSummary(result: DeepLinkResult): TransferSummary;
136
+
137
+ declare const VERSION = "0.2.0";
138
+
139
+ export { DEFAULT_WEBVIEW_BASE_URL, DepositError, DepositRequest, DepositResult, MobileCheckout, MobileDeposit, MobileDepositConfig, MobileDepositStatus, TransferSummary, VERSION, isSwypeCallback, parseDeepLink, toTransferSummary };
@@ -0,0 +1,139 @@
1
+ import { M as MobileDepositStatus, D as DepositResult, a as DepositError, b as MobileDepositConfig, c as DepositRequest, T as TransferSummary } from './types-Df_KwICF.js';
2
+ export { C as CheckoutError, d as CheckoutErrorCode, e as DepositMobileErrorCode, f as MobileCheckoutConfig, g as MobileCheckoutStatus, S as SignerFunction, h as SignerRequest, i as SignerResponse, j as getDisplayMessage } from './types-Df_KwICF.js';
3
+
4
+ declare const DEFAULT_WEBVIEW_BASE_URL = "https://pay-staging.tryblink.xyz";
5
+ type EventMap = {
6
+ complete: (result: DepositResult) => void;
7
+ error: (error: DepositError) => void;
8
+ dismiss: () => void;
9
+ 'status-change': (status: MobileDepositStatus) => void;
10
+ };
11
+ type EventName = keyof EventMap;
12
+ /**
13
+ * Mobile deposit SDK.
14
+ *
15
+ * Opens a hosted payment flow in an in-app browser, waits for the result
16
+ * via deep link callback, and resolves when the user completes payment.
17
+ *
18
+ * ```ts
19
+ * const deposit = new MobileDeposit({
20
+ * signer: 'https://api.merchant.com/sign-payment',
21
+ * callbackScheme: 'myapp',
22
+ * openUrl: (url) => WebBrowser.openBrowserAsync(url),
23
+ * });
24
+ *
25
+ * // When a deep link arrives, pass it to the SDK:
26
+ * Linking.addEventListener('url', ({ url }) => deposit.handleDeepLink(url));
27
+ *
28
+ * // Start a deposit:
29
+ * const result = await deposit.requestDeposit({
30
+ * amount: 50,
31
+ * chainId: 8453,
32
+ * address: '0x...',
33
+ * token: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
34
+ * });
35
+ * ```
36
+ */
37
+ declare class MobileDeposit {
38
+ private readonly config;
39
+ private requestId;
40
+ private destroyed;
41
+ private _status;
42
+ private _result;
43
+ private _error;
44
+ private flowTimer;
45
+ private lastSignerResponse;
46
+ private pendingResolve;
47
+ private pendingReject;
48
+ private pendingRequestId;
49
+ private listeners;
50
+ /** Current phase of the deposit flow. */
51
+ get status(): MobileDepositStatus;
52
+ /** Last successful {@link DepositResult}, available when `status === 'completed'`. */
53
+ get result(): DepositResult | null;
54
+ /** Last {@link DepositError}, available when `status === 'error'`. */
55
+ get error(): DepositError | null;
56
+ /** Whether a deposit flow is currently in progress. */
57
+ get isActive(): boolean;
58
+ constructor(config: MobileDepositConfig);
59
+ /**
60
+ * Open the hosted payment flow for the given deposit.
61
+ *
62
+ * The returned Promise resolves when the user completes the payment (via
63
+ * deep link callback) and rejects with a {@link DepositError} on failure.
64
+ *
65
+ * The merchant must listen for incoming deep links and pass them to
66
+ * {@link handleDeepLink} for the promise to resolve.
67
+ */
68
+ requestDeposit(request: DepositRequest): Promise<DepositResult>;
69
+ /**
70
+ * Feed an incoming deep link URL to the SDK.
71
+ *
72
+ * Returns `true` if the URL was a valid Swype callback and the SDK handled
73
+ * it. Returns `false` if the URL did not match the expected callback pattern
74
+ * (the merchant should handle it themselves).
75
+ *
76
+ * Typically called from `Linking.addEventListener('url', ...)` or the
77
+ * equivalent deep link handler on the platform.
78
+ */
79
+ handleDeepLink(url: string): boolean;
80
+ /** Register an event listener. */
81
+ on<K extends EventName>(event: K, handler: EventMap[K]): this;
82
+ /** Remove a previously registered event listener. */
83
+ off<K extends EventName>(event: K, handler: EventMap[K]): this;
84
+ /**
85
+ * Cancel the current flow. Rejects the pending promise with
86
+ * `BROWSER_DISMISSED` and resets to idle.
87
+ */
88
+ close(): void;
89
+ /** Tear down the instance and release all resources. */
90
+ destroy(): void;
91
+ private log;
92
+ private setStatus;
93
+ private runSignerFlow;
94
+ private cleanup;
95
+ private emit;
96
+ }
97
+ /** @deprecated Use {@link MobileDeposit} instead. */
98
+ declare const MobileCheckout: typeof MobileDeposit;
99
+
100
+ /**
101
+ * Parsed result from a Swype deep link callback.
102
+ *
103
+ * @internal
104
+ */
105
+ interface DeepLinkResult {
106
+ transferId: string;
107
+ transferStatus: string;
108
+ amount?: number;
109
+ currency?: string;
110
+ chainId?: string;
111
+ address?: string;
112
+ token?: string;
113
+ }
114
+ /**
115
+ * Check whether a URL matches the expected Swype callback deep link pattern.
116
+ */
117
+ declare function isSwypeCallback(url: string, callbackScheme: string, callbackPath?: string): boolean;
118
+ /**
119
+ * Parse a Swype callback deep link URL into a {@link DeepLinkResult}.
120
+ *
121
+ * Returns `null` if the URL does not match the expected scheme/path or is
122
+ * missing the required `transferId` parameter.
123
+ *
124
+ * Expected format:
125
+ * ```
126
+ * {scheme}://{path}?transferId=xxx&transferStatus=completed&amount=50&currency=USD&chainId=8453&address=0x...&token=USDC
127
+ * ```
128
+ */
129
+ declare function parseDeepLink(url: string, callbackScheme: string, callbackPath?: string): DeepLinkResult | null;
130
+ /**
131
+ * Convert a parsed deep link result into a {@link TransferSummary}.
132
+ *
133
+ * @internal
134
+ */
135
+ declare function toTransferSummary(result: DeepLinkResult): TransferSummary;
136
+
137
+ declare const VERSION = "0.2.0";
138
+
139
+ export { DEFAULT_WEBVIEW_BASE_URL, DepositError, DepositRequest, DepositResult, MobileCheckout, MobileDeposit, MobileDepositConfig, MobileDepositStatus, TransferSummary, VERSION, isSwypeCallback, parseDeepLink, toTransferSummary };
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { CheckoutError, DEFAULT_WEBVIEW_BASE_URL, DepositError, MobileCheckout, MobileDeposit, getDisplayMessage, isSwypeCallback, parseDeepLink, toTransferSummary } from './chunk-QIPX2XQS.js';
2
+
3
+ // src/index.ts
4
+ var VERSION = "0.2.0";
5
+
6
+ export { VERSION };
7
+ //# sourceMappingURL=index.js.map
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAiBO,IAAM,OAAA,GAAU","file":"index.js","sourcesContent":["export { MobileDeposit, MobileCheckout, DEFAULT_WEBVIEW_BASE_URL } from './mobile-deposit.ts';\nexport { DepositError, CheckoutError, getDisplayMessage } from './errors.ts';\nexport { isSwypeCallback, parseDeepLink, toTransferSummary } from './deep-link.ts';\nexport type { DepositMobileErrorCode, CheckoutErrorCode } from './errors.ts';\nexport type {\n MobileDepositConfig,\n MobileDepositStatus,\n MobileCheckoutConfig,\n MobileCheckoutStatus,\n DepositRequest,\n DepositResult,\n SignerFunction,\n SignerRequest,\n SignerResponse,\n TransferSummary,\n} from './types.ts';\n\nexport const VERSION = '0.2.0';\n"]}