@alien_org/react 0.1.1 → 0.1.3
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 +79 -0
- package/dist/index.d.cts +112 -16
- package/dist/index.d.mts +112 -16
- package/dist/index.mjs +79 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -91,6 +91,84 @@ function useAlien() {
|
|
|
91
91
|
return context;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/hooks/useClipboard.ts
|
|
96
|
+
/**
|
|
97
|
+
* Hook for clipboard operations.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```tsx
|
|
101
|
+
* function ClipboardDemo() {
|
|
102
|
+
* const { writeText, readText, isReading, errorCode, supported } = useClipboard();
|
|
103
|
+
*
|
|
104
|
+
* if (!supported) return null;
|
|
105
|
+
*
|
|
106
|
+
* return (
|
|
107
|
+
* <>
|
|
108
|
+
* <button onClick={() => writeText('Hello!')}>Copy</button>
|
|
109
|
+
* <button
|
|
110
|
+
* onClick={async () => {
|
|
111
|
+
* const text = await readText();
|
|
112
|
+
* if (text !== null) console.log('Pasted:', text);
|
|
113
|
+
* }}
|
|
114
|
+
* disabled={isReading}
|
|
115
|
+
* >
|
|
116
|
+
* Paste
|
|
117
|
+
* </button>
|
|
118
|
+
* {errorCode && <span>Error: {errorCode}</span>}
|
|
119
|
+
* </>
|
|
120
|
+
* );
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
function useClipboard(options = {}) {
|
|
125
|
+
const { timeout = 5e3 } = options;
|
|
126
|
+
const { contractVersion, isBridgeAvailable: isBridgeAvailable$1 } = useAlien();
|
|
127
|
+
const [isReading, setIsReading] = (0, react.useState)(false);
|
|
128
|
+
const [errorCode, setErrorCode] = (0, react.useState)(null);
|
|
129
|
+
const supported = contractVersion ? (0, _alien_org_contract.isMethodSupported)("clipboard:write", contractVersion) && (0, _alien_org_contract.isMethodSupported)("clipboard:read", contractVersion) : true;
|
|
130
|
+
const writeText = (0, react.useCallback)((text) => {
|
|
131
|
+
if (!isBridgeAvailable$1) return;
|
|
132
|
+
if (contractVersion && !(0, _alien_org_contract.isMethodSupported)("clipboard:write", contractVersion)) return;
|
|
133
|
+
(0, _alien_org_bridge.send)("clipboard:write", { text });
|
|
134
|
+
}, [isBridgeAvailable$1, contractVersion]);
|
|
135
|
+
const readText = (0, react.useCallback)(async () => {
|
|
136
|
+
if (!isBridgeAvailable$1) return null;
|
|
137
|
+
if (contractVersion && !(0, _alien_org_contract.isMethodSupported)("clipboard:read", contractVersion)) return null;
|
|
138
|
+
setIsReading(true);
|
|
139
|
+
setErrorCode(null);
|
|
140
|
+
try {
|
|
141
|
+
const response = await (0, _alien_org_bridge.request)("clipboard:read", {}, "clipboard:response", { timeout });
|
|
142
|
+
if (response.errorCode) {
|
|
143
|
+
setErrorCode(response.errorCode);
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
return response.text;
|
|
147
|
+
} catch {
|
|
148
|
+
return null;
|
|
149
|
+
} finally {
|
|
150
|
+
setIsReading(false);
|
|
151
|
+
}
|
|
152
|
+
}, [
|
|
153
|
+
isBridgeAvailable$1,
|
|
154
|
+
contractVersion,
|
|
155
|
+
timeout
|
|
156
|
+
]);
|
|
157
|
+
return (0, react.useMemo)(() => ({
|
|
158
|
+
writeText,
|
|
159
|
+
readText,
|
|
160
|
+
isReading,
|
|
161
|
+
errorCode,
|
|
162
|
+
supported
|
|
163
|
+
}), [
|
|
164
|
+
writeText,
|
|
165
|
+
readText,
|
|
166
|
+
isReading,
|
|
167
|
+
errorCode,
|
|
168
|
+
supported
|
|
169
|
+
]);
|
|
170
|
+
}
|
|
171
|
+
|
|
94
172
|
//#endregion
|
|
95
173
|
//#region src/hooks/useEvent.ts
|
|
96
174
|
/**
|
|
@@ -539,6 +617,7 @@ Object.defineProperty(exports, 'send', {
|
|
|
539
617
|
}
|
|
540
618
|
});
|
|
541
619
|
exports.useAlien = useAlien;
|
|
620
|
+
exports.useClipboard = useClipboard;
|
|
542
621
|
exports.useEvent = useEvent;
|
|
543
622
|
exports.useIsMethodSupported = useIsMethodSupported;
|
|
544
623
|
exports.useLaunchParams = useLaunchParams;
|
package/dist/index.d.cts
CHANGED
|
@@ -72,7 +72,7 @@ interface Events {
|
|
|
72
72
|
* For instant fulfillment, your backend should fulfill on webhook receipt
|
|
73
73
|
* using the `invoice` from the request.
|
|
74
74
|
*
|
|
75
|
-
* @since 0.
|
|
75
|
+
* @since 0.1.1
|
|
76
76
|
* @schema
|
|
77
77
|
*/
|
|
78
78
|
'payment:response': CreateEventPayload<WithReqId<{
|
|
@@ -81,13 +81,13 @@ interface Events {
|
|
|
81
81
|
* - `paid`: Success
|
|
82
82
|
* - `cancelled`: User rejected
|
|
83
83
|
* - `failed`: Error (check `errorCode`)
|
|
84
|
-
* @since 0.
|
|
84
|
+
* @since 0.1.1
|
|
85
85
|
* @schema
|
|
86
86
|
*/
|
|
87
87
|
status: 'paid' | 'cancelled' | 'failed';
|
|
88
88
|
/**
|
|
89
89
|
* Transaction hash (present when status is 'paid').
|
|
90
|
-
* @since 0.
|
|
90
|
+
* @since 0.1.1
|
|
91
91
|
* @schema
|
|
92
92
|
*/
|
|
93
93
|
txHash?: string;
|
|
@@ -98,11 +98,36 @@ interface Events {
|
|
|
98
98
|
* - `pre_checkout_rejected`: Backend rejected the payment in pre-checkout
|
|
99
99
|
* - `pre_checkout_timeout`: Backend didn't respond to pre-checkout in time
|
|
100
100
|
* - `unknown`: Unexpected error
|
|
101
|
-
* @since 0.
|
|
101
|
+
* @since 0.1.1
|
|
102
102
|
* @schema
|
|
103
103
|
*/
|
|
104
104
|
errorCode?: 'insufficient_balance' | 'network_error' | 'pre_checkout_rejected' | 'pre_checkout_timeout' | 'unknown';
|
|
105
105
|
}>>;
|
|
106
|
+
/**
|
|
107
|
+
* Clipboard read response.
|
|
108
|
+
*
|
|
109
|
+
* On success: `text` contains the clipboard content (may be empty string).
|
|
110
|
+
* On failure: `text` is null and `errorCode` indicates the reason.
|
|
111
|
+
*
|
|
112
|
+
* @since 0.1.1
|
|
113
|
+
* @schema
|
|
114
|
+
*/
|
|
115
|
+
'clipboard:response': CreateEventPayload<WithReqId<{
|
|
116
|
+
/**
|
|
117
|
+
* Text from clipboard. Null if read failed.
|
|
118
|
+
* @since 0.1.1
|
|
119
|
+
* @schema
|
|
120
|
+
*/
|
|
121
|
+
text: string | null;
|
|
122
|
+
/**
|
|
123
|
+
* Error code if clipboard read failed.
|
|
124
|
+
* - `permission_denied`: User denied clipboard access
|
|
125
|
+
* - `unavailable`: Clipboard is not available
|
|
126
|
+
* @since 0.1.1
|
|
127
|
+
* @schema
|
|
128
|
+
*/
|
|
129
|
+
errorCode?: 'permission_denied' | 'unavailable';
|
|
130
|
+
}>>;
|
|
106
131
|
}
|
|
107
132
|
//#endregion
|
|
108
133
|
//#region ../contract/src/events/types/event-types.d.ts
|
|
@@ -193,61 +218,61 @@ interface Methods {
|
|
|
193
218
|
* Set `test: true` for test mode - no real payment is made, but webhooks
|
|
194
219
|
* are fired with `test: true` flag. Use for development and testing.
|
|
195
220
|
*
|
|
196
|
-
* @since 0.
|
|
221
|
+
* @since 0.1.1
|
|
197
222
|
* @schema
|
|
198
223
|
*/
|
|
199
224
|
'payment:request': CreateMethodPayload<WithReqId<{
|
|
200
225
|
/**
|
|
201
226
|
* The recipient's wallet address.
|
|
202
|
-
* @since 0.
|
|
227
|
+
* @since 0.1.1
|
|
203
228
|
* @schema
|
|
204
229
|
*/
|
|
205
230
|
recipient: string;
|
|
206
231
|
/**
|
|
207
232
|
* The amount to pay (in token's smallest unit, as string for precision).
|
|
208
|
-
* @since 0.
|
|
233
|
+
* @since 0.1.1
|
|
209
234
|
* @schema
|
|
210
235
|
*/
|
|
211
236
|
amount: string;
|
|
212
237
|
/**
|
|
213
238
|
* The token identifier (e.g., 'SOL', 'ALIEN', or contract address).
|
|
214
|
-
* @since 0.
|
|
239
|
+
* @since 0.1.1
|
|
215
240
|
* @schema
|
|
216
241
|
*/
|
|
217
242
|
token: string;
|
|
218
243
|
/**
|
|
219
244
|
* The network for the payment ('solana' or 'alien').
|
|
220
|
-
* @since 0.
|
|
245
|
+
* @since 0.1.1
|
|
221
246
|
* @schema
|
|
222
247
|
*/
|
|
223
248
|
network: string;
|
|
224
249
|
/**
|
|
225
250
|
* Your order/invoice ID for backend correlation and instant fulfillment.
|
|
226
|
-
* @since 0.
|
|
251
|
+
* @since 0.1.1
|
|
227
252
|
* @schema
|
|
228
253
|
*/
|
|
229
254
|
invoice: string;
|
|
230
255
|
/**
|
|
231
256
|
* Item title shown on the approval screen.
|
|
232
|
-
* @since 0.
|
|
257
|
+
* @since 0.1.1
|
|
233
258
|
* @schema
|
|
234
259
|
*/
|
|
235
260
|
title?: string;
|
|
236
261
|
/**
|
|
237
262
|
* Item description/caption shown on the approval screen.
|
|
238
|
-
* @since 0.
|
|
263
|
+
* @since 0.1.1
|
|
239
264
|
* @schema
|
|
240
265
|
*/
|
|
241
266
|
caption?: string;
|
|
242
267
|
/**
|
|
243
268
|
* Item icon URL shown on the approval screen.
|
|
244
|
-
* @since 0.
|
|
269
|
+
* @since 0.1.1
|
|
245
270
|
* @schema
|
|
246
271
|
*/
|
|
247
272
|
iconUrl?: string;
|
|
248
273
|
/**
|
|
249
274
|
* Quantity of items being purchased.
|
|
250
|
-
* @since 0.
|
|
275
|
+
* @since 0.1.1
|
|
251
276
|
* @schema
|
|
252
277
|
*/
|
|
253
278
|
quantity?: number;
|
|
@@ -255,11 +280,30 @@ interface Methods {
|
|
|
255
280
|
* Test mode flag. When true, no real payment is processed.
|
|
256
281
|
* The approval screen shows a test indicator, and webhooks
|
|
257
282
|
* include `test: true`. Use for development and testing.
|
|
258
|
-
* @since 0.
|
|
283
|
+
* @since 0.1.1
|
|
259
284
|
* @schema
|
|
260
285
|
*/
|
|
261
286
|
test?: boolean;
|
|
262
287
|
}>>;
|
|
288
|
+
/**
|
|
289
|
+
* Write text to the system clipboard.
|
|
290
|
+
* @since 0.1.1
|
|
291
|
+
* @schema
|
|
292
|
+
*/
|
|
293
|
+
'clipboard:write': CreateMethodPayload<{
|
|
294
|
+
/**
|
|
295
|
+
* Text to copy to clipboard.
|
|
296
|
+
* @since 0.1.1
|
|
297
|
+
* @schema
|
|
298
|
+
*/
|
|
299
|
+
text: string;
|
|
300
|
+
}>;
|
|
301
|
+
/**
|
|
302
|
+
* Read text from the system clipboard.
|
|
303
|
+
* @since 0.1.1
|
|
304
|
+
* @schema
|
|
305
|
+
*/
|
|
306
|
+
'clipboard:read': CreateMethodPayload<WithReqId<Empty>>;
|
|
263
307
|
}
|
|
264
308
|
//#endregion
|
|
265
309
|
//#region ../contract/src/methods/types/method-types.d.ts
|
|
@@ -435,6 +479,58 @@ declare class MethodNotSupportedError extends ReactSDKError {
|
|
|
435
479
|
*/
|
|
436
480
|
declare function useAlien(): AlienContextValue;
|
|
437
481
|
//#endregion
|
|
482
|
+
//#region src/hooks/useClipboard.d.ts
|
|
483
|
+
/** Clipboard error codes from the host app. */
|
|
484
|
+
type ClipboardErrorCode = 'permission_denied' | 'unavailable';
|
|
485
|
+
interface UseClipboardOptions {
|
|
486
|
+
/**
|
|
487
|
+
* Timeout for clipboard read in milliseconds.
|
|
488
|
+
* @default 5000
|
|
489
|
+
*/
|
|
490
|
+
timeout?: number;
|
|
491
|
+
}
|
|
492
|
+
interface UseClipboardReturn {
|
|
493
|
+
/** Write text to clipboard. Fire-and-forget. */
|
|
494
|
+
writeText: (text: string) => void;
|
|
495
|
+
/** Read text from clipboard. Returns text or null on failure. */
|
|
496
|
+
readText: () => Promise<string | null>;
|
|
497
|
+
/** Whether a read operation is in progress. */
|
|
498
|
+
isReading: boolean;
|
|
499
|
+
/** Error code from the last failed read operation. */
|
|
500
|
+
errorCode: ClipboardErrorCode | null;
|
|
501
|
+
/** Whether clipboard methods are supported by the host app. */
|
|
502
|
+
supported: boolean;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Hook for clipboard operations.
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
* ```tsx
|
|
509
|
+
* function ClipboardDemo() {
|
|
510
|
+
* const { writeText, readText, isReading, errorCode, supported } = useClipboard();
|
|
511
|
+
*
|
|
512
|
+
* if (!supported) return null;
|
|
513
|
+
*
|
|
514
|
+
* return (
|
|
515
|
+
* <>
|
|
516
|
+
* <button onClick={() => writeText('Hello!')}>Copy</button>
|
|
517
|
+
* <button
|
|
518
|
+
* onClick={async () => {
|
|
519
|
+
* const text = await readText();
|
|
520
|
+
* if (text !== null) console.log('Pasted:', text);
|
|
521
|
+
* }}
|
|
522
|
+
* disabled={isReading}
|
|
523
|
+
* >
|
|
524
|
+
* Paste
|
|
525
|
+
* </button>
|
|
526
|
+
* {errorCode && <span>Error: {errorCode}</span>}
|
|
527
|
+
* </>
|
|
528
|
+
* );
|
|
529
|
+
* }
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
declare function useClipboard(options?: UseClipboardOptions): UseClipboardReturn;
|
|
533
|
+
//#endregion
|
|
438
534
|
//#region src/hooks/useEvent.d.ts
|
|
439
535
|
type EventCallback<E extends EventName> = (payload: EventPayload<E>) => void;
|
|
440
536
|
/**
|
|
@@ -718,4 +814,4 @@ interface UsePaymentReturn {
|
|
|
718
814
|
*/
|
|
719
815
|
declare function usePayment(options?: UsePaymentOptions): UsePaymentReturn;
|
|
720
816
|
//#endregion
|
|
721
|
-
export { AlienProvider, type AlienProviderProps, BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, type EventName, type EventPayload, type MethodName, MethodNotSupportedError, type MethodPayload, type MethodSupportResult, type PaymentCallbacks, type PaymentErrorCode, type PaymentParams, type PaymentResponseStatus, type PaymentResult, type PaymentStatus, ReactSDKError, type RequestOptions, type UseMethodExecuteResult, type UseMethodOptions, type UsePaymentOptions, type UsePaymentReturn, type Version, getMethodMinVersion, isMethodSupported, send, useAlien, useEvent, useIsMethodSupported, useLaunchParams, useMethod, usePayment };
|
|
817
|
+
export { AlienProvider, type AlienProviderProps, BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, type ClipboardErrorCode, type EventName, type EventPayload, type MethodName, MethodNotSupportedError, type MethodPayload, type MethodSupportResult, type PaymentCallbacks, type PaymentErrorCode, type PaymentParams, type PaymentResponseStatus, type PaymentResult, type PaymentStatus, ReactSDKError, type RequestOptions, type UseClipboardOptions, type UseClipboardReturn, type UseMethodExecuteResult, type UseMethodOptions, type UsePaymentOptions, type UsePaymentReturn, type Version, getMethodMinVersion, isMethodSupported, send, useAlien, useClipboard, useEvent, useIsMethodSupported, useLaunchParams, useMethod, usePayment };
|
package/dist/index.d.mts
CHANGED
|
@@ -72,7 +72,7 @@ interface Events {
|
|
|
72
72
|
* For instant fulfillment, your backend should fulfill on webhook receipt
|
|
73
73
|
* using the `invoice` from the request.
|
|
74
74
|
*
|
|
75
|
-
* @since 0.
|
|
75
|
+
* @since 0.1.1
|
|
76
76
|
* @schema
|
|
77
77
|
*/
|
|
78
78
|
'payment:response': CreateEventPayload<WithReqId<{
|
|
@@ -81,13 +81,13 @@ interface Events {
|
|
|
81
81
|
* - `paid`: Success
|
|
82
82
|
* - `cancelled`: User rejected
|
|
83
83
|
* - `failed`: Error (check `errorCode`)
|
|
84
|
-
* @since 0.
|
|
84
|
+
* @since 0.1.1
|
|
85
85
|
* @schema
|
|
86
86
|
*/
|
|
87
87
|
status: 'paid' | 'cancelled' | 'failed';
|
|
88
88
|
/**
|
|
89
89
|
* Transaction hash (present when status is 'paid').
|
|
90
|
-
* @since 0.
|
|
90
|
+
* @since 0.1.1
|
|
91
91
|
* @schema
|
|
92
92
|
*/
|
|
93
93
|
txHash?: string;
|
|
@@ -98,11 +98,36 @@ interface Events {
|
|
|
98
98
|
* - `pre_checkout_rejected`: Backend rejected the payment in pre-checkout
|
|
99
99
|
* - `pre_checkout_timeout`: Backend didn't respond to pre-checkout in time
|
|
100
100
|
* - `unknown`: Unexpected error
|
|
101
|
-
* @since 0.
|
|
101
|
+
* @since 0.1.1
|
|
102
102
|
* @schema
|
|
103
103
|
*/
|
|
104
104
|
errorCode?: 'insufficient_balance' | 'network_error' | 'pre_checkout_rejected' | 'pre_checkout_timeout' | 'unknown';
|
|
105
105
|
}>>;
|
|
106
|
+
/**
|
|
107
|
+
* Clipboard read response.
|
|
108
|
+
*
|
|
109
|
+
* On success: `text` contains the clipboard content (may be empty string).
|
|
110
|
+
* On failure: `text` is null and `errorCode` indicates the reason.
|
|
111
|
+
*
|
|
112
|
+
* @since 0.1.1
|
|
113
|
+
* @schema
|
|
114
|
+
*/
|
|
115
|
+
'clipboard:response': CreateEventPayload<WithReqId<{
|
|
116
|
+
/**
|
|
117
|
+
* Text from clipboard. Null if read failed.
|
|
118
|
+
* @since 0.1.1
|
|
119
|
+
* @schema
|
|
120
|
+
*/
|
|
121
|
+
text: string | null;
|
|
122
|
+
/**
|
|
123
|
+
* Error code if clipboard read failed.
|
|
124
|
+
* - `permission_denied`: User denied clipboard access
|
|
125
|
+
* - `unavailable`: Clipboard is not available
|
|
126
|
+
* @since 0.1.1
|
|
127
|
+
* @schema
|
|
128
|
+
*/
|
|
129
|
+
errorCode?: 'permission_denied' | 'unavailable';
|
|
130
|
+
}>>;
|
|
106
131
|
}
|
|
107
132
|
//#endregion
|
|
108
133
|
//#region ../contract/src/events/types/event-types.d.ts
|
|
@@ -193,61 +218,61 @@ interface Methods {
|
|
|
193
218
|
* Set `test: true` for test mode - no real payment is made, but webhooks
|
|
194
219
|
* are fired with `test: true` flag. Use for development and testing.
|
|
195
220
|
*
|
|
196
|
-
* @since 0.
|
|
221
|
+
* @since 0.1.1
|
|
197
222
|
* @schema
|
|
198
223
|
*/
|
|
199
224
|
'payment:request': CreateMethodPayload<WithReqId<{
|
|
200
225
|
/**
|
|
201
226
|
* The recipient's wallet address.
|
|
202
|
-
* @since 0.
|
|
227
|
+
* @since 0.1.1
|
|
203
228
|
* @schema
|
|
204
229
|
*/
|
|
205
230
|
recipient: string;
|
|
206
231
|
/**
|
|
207
232
|
* The amount to pay (in token's smallest unit, as string for precision).
|
|
208
|
-
* @since 0.
|
|
233
|
+
* @since 0.1.1
|
|
209
234
|
* @schema
|
|
210
235
|
*/
|
|
211
236
|
amount: string;
|
|
212
237
|
/**
|
|
213
238
|
* The token identifier (e.g., 'SOL', 'ALIEN', or contract address).
|
|
214
|
-
* @since 0.
|
|
239
|
+
* @since 0.1.1
|
|
215
240
|
* @schema
|
|
216
241
|
*/
|
|
217
242
|
token: string;
|
|
218
243
|
/**
|
|
219
244
|
* The network for the payment ('solana' or 'alien').
|
|
220
|
-
* @since 0.
|
|
245
|
+
* @since 0.1.1
|
|
221
246
|
* @schema
|
|
222
247
|
*/
|
|
223
248
|
network: string;
|
|
224
249
|
/**
|
|
225
250
|
* Your order/invoice ID for backend correlation and instant fulfillment.
|
|
226
|
-
* @since 0.
|
|
251
|
+
* @since 0.1.1
|
|
227
252
|
* @schema
|
|
228
253
|
*/
|
|
229
254
|
invoice: string;
|
|
230
255
|
/**
|
|
231
256
|
* Item title shown on the approval screen.
|
|
232
|
-
* @since 0.
|
|
257
|
+
* @since 0.1.1
|
|
233
258
|
* @schema
|
|
234
259
|
*/
|
|
235
260
|
title?: string;
|
|
236
261
|
/**
|
|
237
262
|
* Item description/caption shown on the approval screen.
|
|
238
|
-
* @since 0.
|
|
263
|
+
* @since 0.1.1
|
|
239
264
|
* @schema
|
|
240
265
|
*/
|
|
241
266
|
caption?: string;
|
|
242
267
|
/**
|
|
243
268
|
* Item icon URL shown on the approval screen.
|
|
244
|
-
* @since 0.
|
|
269
|
+
* @since 0.1.1
|
|
245
270
|
* @schema
|
|
246
271
|
*/
|
|
247
272
|
iconUrl?: string;
|
|
248
273
|
/**
|
|
249
274
|
* Quantity of items being purchased.
|
|
250
|
-
* @since 0.
|
|
275
|
+
* @since 0.1.1
|
|
251
276
|
* @schema
|
|
252
277
|
*/
|
|
253
278
|
quantity?: number;
|
|
@@ -255,11 +280,30 @@ interface Methods {
|
|
|
255
280
|
* Test mode flag. When true, no real payment is processed.
|
|
256
281
|
* The approval screen shows a test indicator, and webhooks
|
|
257
282
|
* include `test: true`. Use for development and testing.
|
|
258
|
-
* @since 0.
|
|
283
|
+
* @since 0.1.1
|
|
259
284
|
* @schema
|
|
260
285
|
*/
|
|
261
286
|
test?: boolean;
|
|
262
287
|
}>>;
|
|
288
|
+
/**
|
|
289
|
+
* Write text to the system clipboard.
|
|
290
|
+
* @since 0.1.1
|
|
291
|
+
* @schema
|
|
292
|
+
*/
|
|
293
|
+
'clipboard:write': CreateMethodPayload<{
|
|
294
|
+
/**
|
|
295
|
+
* Text to copy to clipboard.
|
|
296
|
+
* @since 0.1.1
|
|
297
|
+
* @schema
|
|
298
|
+
*/
|
|
299
|
+
text: string;
|
|
300
|
+
}>;
|
|
301
|
+
/**
|
|
302
|
+
* Read text from the system clipboard.
|
|
303
|
+
* @since 0.1.1
|
|
304
|
+
* @schema
|
|
305
|
+
*/
|
|
306
|
+
'clipboard:read': CreateMethodPayload<WithReqId<Empty>>;
|
|
263
307
|
}
|
|
264
308
|
//#endregion
|
|
265
309
|
//#region ../contract/src/methods/types/method-types.d.ts
|
|
@@ -435,6 +479,58 @@ declare class MethodNotSupportedError extends ReactSDKError {
|
|
|
435
479
|
*/
|
|
436
480
|
declare function useAlien(): AlienContextValue;
|
|
437
481
|
//#endregion
|
|
482
|
+
//#region src/hooks/useClipboard.d.ts
|
|
483
|
+
/** Clipboard error codes from the host app. */
|
|
484
|
+
type ClipboardErrorCode = 'permission_denied' | 'unavailable';
|
|
485
|
+
interface UseClipboardOptions {
|
|
486
|
+
/**
|
|
487
|
+
* Timeout for clipboard read in milliseconds.
|
|
488
|
+
* @default 5000
|
|
489
|
+
*/
|
|
490
|
+
timeout?: number;
|
|
491
|
+
}
|
|
492
|
+
interface UseClipboardReturn {
|
|
493
|
+
/** Write text to clipboard. Fire-and-forget. */
|
|
494
|
+
writeText: (text: string) => void;
|
|
495
|
+
/** Read text from clipboard. Returns text or null on failure. */
|
|
496
|
+
readText: () => Promise<string | null>;
|
|
497
|
+
/** Whether a read operation is in progress. */
|
|
498
|
+
isReading: boolean;
|
|
499
|
+
/** Error code from the last failed read operation. */
|
|
500
|
+
errorCode: ClipboardErrorCode | null;
|
|
501
|
+
/** Whether clipboard methods are supported by the host app. */
|
|
502
|
+
supported: boolean;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Hook for clipboard operations.
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
* ```tsx
|
|
509
|
+
* function ClipboardDemo() {
|
|
510
|
+
* const { writeText, readText, isReading, errorCode, supported } = useClipboard();
|
|
511
|
+
*
|
|
512
|
+
* if (!supported) return null;
|
|
513
|
+
*
|
|
514
|
+
* return (
|
|
515
|
+
* <>
|
|
516
|
+
* <button onClick={() => writeText('Hello!')}>Copy</button>
|
|
517
|
+
* <button
|
|
518
|
+
* onClick={async () => {
|
|
519
|
+
* const text = await readText();
|
|
520
|
+
* if (text !== null) console.log('Pasted:', text);
|
|
521
|
+
* }}
|
|
522
|
+
* disabled={isReading}
|
|
523
|
+
* >
|
|
524
|
+
* Paste
|
|
525
|
+
* </button>
|
|
526
|
+
* {errorCode && <span>Error: {errorCode}</span>}
|
|
527
|
+
* </>
|
|
528
|
+
* );
|
|
529
|
+
* }
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
declare function useClipboard(options?: UseClipboardOptions): UseClipboardReturn;
|
|
533
|
+
//#endregion
|
|
438
534
|
//#region src/hooks/useEvent.d.ts
|
|
439
535
|
type EventCallback<E extends EventName> = (payload: EventPayload<E>) => void;
|
|
440
536
|
/**
|
|
@@ -718,4 +814,4 @@ interface UsePaymentReturn {
|
|
|
718
814
|
*/
|
|
719
815
|
declare function usePayment(options?: UsePaymentOptions): UsePaymentReturn;
|
|
720
816
|
//#endregion
|
|
721
|
-
export { AlienProvider, type AlienProviderProps, BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, type EventName, type EventPayload, type MethodName, MethodNotSupportedError, type MethodPayload, type MethodSupportResult, type PaymentCallbacks, type PaymentErrorCode, type PaymentParams, type PaymentResponseStatus, type PaymentResult, type PaymentStatus, ReactSDKError, type RequestOptions, type UseMethodExecuteResult, type UseMethodOptions, type UsePaymentOptions, type UsePaymentReturn, type Version, getMethodMinVersion, isMethodSupported, send, useAlien, useEvent, useIsMethodSupported, useLaunchParams, useMethod, usePayment };
|
|
817
|
+
export { AlienProvider, type AlienProviderProps, BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, type ClipboardErrorCode, type EventName, type EventPayload, type MethodName, MethodNotSupportedError, type MethodPayload, type MethodSupportResult, type PaymentCallbacks, type PaymentErrorCode, type PaymentParams, type PaymentResponseStatus, type PaymentResult, type PaymentStatus, ReactSDKError, type RequestOptions, type UseClipboardOptions, type UseClipboardReturn, type UseMethodExecuteResult, type UseMethodOptions, type UsePaymentOptions, type UsePaymentReturn, type Version, getMethodMinVersion, isMethodSupported, send, useAlien, useClipboard, useEvent, useIsMethodSupported, useLaunchParams, useMethod, usePayment };
|
package/dist/index.mjs
CHANGED
|
@@ -91,6 +91,84 @@ function useAlien() {
|
|
|
91
91
|
return context;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/hooks/useClipboard.ts
|
|
96
|
+
/**
|
|
97
|
+
* Hook for clipboard operations.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```tsx
|
|
101
|
+
* function ClipboardDemo() {
|
|
102
|
+
* const { writeText, readText, isReading, errorCode, supported } = useClipboard();
|
|
103
|
+
*
|
|
104
|
+
* if (!supported) return null;
|
|
105
|
+
*
|
|
106
|
+
* return (
|
|
107
|
+
* <>
|
|
108
|
+
* <button onClick={() => writeText('Hello!')}>Copy</button>
|
|
109
|
+
* <button
|
|
110
|
+
* onClick={async () => {
|
|
111
|
+
* const text = await readText();
|
|
112
|
+
* if (text !== null) console.log('Pasted:', text);
|
|
113
|
+
* }}
|
|
114
|
+
* disabled={isReading}
|
|
115
|
+
* >
|
|
116
|
+
* Paste
|
|
117
|
+
* </button>
|
|
118
|
+
* {errorCode && <span>Error: {errorCode}</span>}
|
|
119
|
+
* </>
|
|
120
|
+
* );
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
function useClipboard(options = {}) {
|
|
125
|
+
const { timeout = 5e3 } = options;
|
|
126
|
+
const { contractVersion, isBridgeAvailable: isBridgeAvailable$1 } = useAlien();
|
|
127
|
+
const [isReading, setIsReading] = useState(false);
|
|
128
|
+
const [errorCode, setErrorCode] = useState(null);
|
|
129
|
+
const supported = contractVersion ? isMethodSupported$1("clipboard:write", contractVersion) && isMethodSupported$1("clipboard:read", contractVersion) : true;
|
|
130
|
+
const writeText = useCallback((text) => {
|
|
131
|
+
if (!isBridgeAvailable$1) return;
|
|
132
|
+
if (contractVersion && !isMethodSupported$1("clipboard:write", contractVersion)) return;
|
|
133
|
+
send$1("clipboard:write", { text });
|
|
134
|
+
}, [isBridgeAvailable$1, contractVersion]);
|
|
135
|
+
const readText = useCallback(async () => {
|
|
136
|
+
if (!isBridgeAvailable$1) return null;
|
|
137
|
+
if (contractVersion && !isMethodSupported$1("clipboard:read", contractVersion)) return null;
|
|
138
|
+
setIsReading(true);
|
|
139
|
+
setErrorCode(null);
|
|
140
|
+
try {
|
|
141
|
+
const response = await request("clipboard:read", {}, "clipboard:response", { timeout });
|
|
142
|
+
if (response.errorCode) {
|
|
143
|
+
setErrorCode(response.errorCode);
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
return response.text;
|
|
147
|
+
} catch {
|
|
148
|
+
return null;
|
|
149
|
+
} finally {
|
|
150
|
+
setIsReading(false);
|
|
151
|
+
}
|
|
152
|
+
}, [
|
|
153
|
+
isBridgeAvailable$1,
|
|
154
|
+
contractVersion,
|
|
155
|
+
timeout
|
|
156
|
+
]);
|
|
157
|
+
return useMemo(() => ({
|
|
158
|
+
writeText,
|
|
159
|
+
readText,
|
|
160
|
+
isReading,
|
|
161
|
+
errorCode,
|
|
162
|
+
supported
|
|
163
|
+
}), [
|
|
164
|
+
writeText,
|
|
165
|
+
readText,
|
|
166
|
+
isReading,
|
|
167
|
+
errorCode,
|
|
168
|
+
supported
|
|
169
|
+
]);
|
|
170
|
+
}
|
|
171
|
+
|
|
94
172
|
//#endregion
|
|
95
173
|
//#region src/hooks/useEvent.ts
|
|
96
174
|
/**
|
|
@@ -513,4 +591,4 @@ function usePayment(options = {}) {
|
|
|
513
591
|
}
|
|
514
592
|
|
|
515
593
|
//#endregion
|
|
516
|
-
export { AlienProvider, BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, MethodNotSupportedError, ReactSDKError, getMethodMinVersion, isMethodSupported, send, useAlien, useEvent, useIsMethodSupported, useLaunchParams, useMethod, usePayment };
|
|
594
|
+
export { AlienProvider, BridgeError, BridgeTimeoutError, BridgeUnavailableError, BridgeWindowUnavailableError, MethodNotSupportedError, ReactSDKError, getMethodMinVersion, isMethodSupported, send, useAlien, useClipboard, useEvent, useIsMethodSupported, useLaunchParams, useMethod, usePayment };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alien_org/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@alien_org/bridge": "0.1.1",
|
|
38
|
-
"@alien_org/contract": "0.1.
|
|
38
|
+
"@alien_org/contract": "0.1.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": "^18 || ^19",
|