@alien_org/react 0.1.4 → 0.2.1
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 +12 -5
- package/dist/index.d.cts +48 -5
- package/dist/index.d.mts +48 -5
- package/dist/index.mjs +12 -5
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -22,21 +22,28 @@ const AlienContext = (0, react.createContext)(null);
|
|
|
22
22
|
* }
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
function AlienProvider({ children }) {
|
|
25
|
+
function AlienProvider({ children, autoReady = true }) {
|
|
26
|
+
const readySent = (0, react.useRef)(false);
|
|
27
|
+
const ready = (0, react.useCallback)(() => {
|
|
28
|
+
if (readySent.current) return;
|
|
29
|
+
readySent.current = true;
|
|
30
|
+
if ((0, _alien_org_bridge.isBridgeAvailable)()) (0, _alien_org_bridge.send)("app:ready", {});
|
|
31
|
+
}, []);
|
|
26
32
|
const value = (0, react.useMemo)(() => {
|
|
27
33
|
const launchParams = (0, _alien_org_bridge.getLaunchParams)();
|
|
28
34
|
return {
|
|
29
35
|
authToken: launchParams?.authToken,
|
|
30
36
|
contractVersion: launchParams?.contractVersion,
|
|
31
|
-
isBridgeAvailable: (0, _alien_org_bridge.isBridgeAvailable)()
|
|
37
|
+
isBridgeAvailable: (0, _alien_org_bridge.isBridgeAvailable)(),
|
|
38
|
+
ready
|
|
32
39
|
};
|
|
33
|
-
}, []);
|
|
40
|
+
}, [ready]);
|
|
34
41
|
(0, react.useEffect)(() => {
|
|
35
42
|
if (!value.isBridgeAvailable) console.warn("[@alien_org/react] Bridge is not available. Running in dev mode? The SDK will handle errors gracefully, but bridge communication will not work.");
|
|
36
43
|
}, [value.isBridgeAvailable]);
|
|
37
44
|
(0, react.useEffect)(() => {
|
|
38
|
-
if (
|
|
39
|
-
}, [
|
|
45
|
+
if (autoReady) ready();
|
|
46
|
+
}, [autoReady, ready]);
|
|
40
47
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AlienContext.Provider, {
|
|
41
48
|
value,
|
|
42
49
|
children
|
package/dist/index.d.cts
CHANGED
|
@@ -250,8 +250,9 @@ interface Methods {
|
|
|
250
250
|
* Optional display fields (`title`, `caption`, `iconUrl`, `quantity`)
|
|
251
251
|
* are shown on the payment approval screen.
|
|
252
252
|
*
|
|
253
|
-
* Set `test
|
|
254
|
-
*
|
|
253
|
+
* Set `test` to a scenario string (e.g. `'paid'`, `'error:insufficient_balance'`)
|
|
254
|
+
* for test mode - no real payment is made, but the specified scenario is
|
|
255
|
+
* simulated. Use for development and testing.
|
|
255
256
|
*
|
|
256
257
|
* @since 0.1.1
|
|
257
258
|
* @schema
|
|
@@ -317,7 +318,7 @@ interface Methods {
|
|
|
317
318
|
*
|
|
318
319
|
* | Scenario | Client | Webhook |
|
|
319
320
|
* |----------|--------|---------|
|
|
320
|
-
* | `
|
|
321
|
+
* | `'paid'` | `paid` | `finalized` |
|
|
321
322
|
* | `'paid:failed'` | `paid` | `failed` |
|
|
322
323
|
* | `'cancelled'` | `cancelled` | none |
|
|
323
324
|
* | `'error:*'` | `failed` | none |
|
|
@@ -343,7 +344,7 @@ interface Methods {
|
|
|
343
344
|
* @since 0.1.1
|
|
344
345
|
* @schema
|
|
345
346
|
*/
|
|
346
|
-
test?:
|
|
347
|
+
test?: PaymentTestScenario;
|
|
347
348
|
}>>;
|
|
348
349
|
/**
|
|
349
350
|
* Write text to the system clipboard.
|
|
@@ -412,6 +413,11 @@ type MethodPayload<M$1 extends MethodName> = Methods[M$1]['payload'];
|
|
|
412
413
|
/**
|
|
413
414
|
* Check if a method is supported in a given version.
|
|
414
415
|
*
|
|
416
|
+
* Uses the minimum version that introduced the method and returns true if
|
|
417
|
+
* the given version is >= that minimum (semver comparison). This supports
|
|
418
|
+
* versions not explicitly listed in releases (e.g. 0.1.4 when method was
|
|
419
|
+
* added in 0.1.1).
|
|
420
|
+
*
|
|
415
421
|
* @param method - The method name to check.
|
|
416
422
|
* @param version - The contract version (must be a valid version string, not undefined).
|
|
417
423
|
* @returns `true` if the method is supported in the given version, `false` otherwise.
|
|
@@ -520,9 +526,45 @@ interface AlienContextValue {
|
|
|
520
526
|
* Whether the bridge is available (running inside Alien App).
|
|
521
527
|
*/
|
|
522
528
|
isBridgeAvailable: boolean;
|
|
529
|
+
/**
|
|
530
|
+
* Manually signal to the host app that the miniapp is ready.
|
|
531
|
+
* Only needed when `autoReady` is set to `false`.
|
|
532
|
+
* Safe to call multiple times — only the first call sends the signal.
|
|
533
|
+
*/
|
|
534
|
+
ready: () => void;
|
|
523
535
|
}
|
|
524
536
|
interface AlienProviderProps {
|
|
525
537
|
children: ReactNode;
|
|
538
|
+
/**
|
|
539
|
+
* Whether to automatically send `app:ready` when the provider mounts.
|
|
540
|
+
* Defaults to `true`.
|
|
541
|
+
*
|
|
542
|
+
* Set to `false` if you need to defer the ready signal (e.g., after
|
|
543
|
+
* fetching initial data), then call `ready()` from `useAlien()` when done.
|
|
544
|
+
*
|
|
545
|
+
* @default true
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
* ```tsx
|
|
549
|
+
* // Auto (default) — fires immediately on mount
|
|
550
|
+
* <AlienProvider>
|
|
551
|
+
* <App />
|
|
552
|
+
* </AlienProvider>
|
|
553
|
+
*
|
|
554
|
+
* // Manual — fire when you're ready
|
|
555
|
+
* <AlienProvider autoReady={false}>
|
|
556
|
+
* <App />
|
|
557
|
+
* </AlienProvider>
|
|
558
|
+
*
|
|
559
|
+
* function App() {
|
|
560
|
+
* const { ready } = useAlien();
|
|
561
|
+
* useEffect(() => {
|
|
562
|
+
* fetchData().then(() => ready());
|
|
563
|
+
* }, []);
|
|
564
|
+
* }
|
|
565
|
+
* ```
|
|
566
|
+
*/
|
|
567
|
+
autoReady?: boolean;
|
|
526
568
|
}
|
|
527
569
|
/**
|
|
528
570
|
* Provider component that initializes the Alien miniapp context.
|
|
@@ -542,7 +584,8 @@ interface AlienProviderProps {
|
|
|
542
584
|
* ```
|
|
543
585
|
*/
|
|
544
586
|
declare function AlienProvider({
|
|
545
|
-
children
|
|
587
|
+
children,
|
|
588
|
+
autoReady
|
|
546
589
|
}: AlienProviderProps): ReactNode;
|
|
547
590
|
//#endregion
|
|
548
591
|
//#region src/errors.d.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -250,8 +250,9 @@ interface Methods {
|
|
|
250
250
|
* Optional display fields (`title`, `caption`, `iconUrl`, `quantity`)
|
|
251
251
|
* are shown on the payment approval screen.
|
|
252
252
|
*
|
|
253
|
-
* Set `test
|
|
254
|
-
*
|
|
253
|
+
* Set `test` to a scenario string (e.g. `'paid'`, `'error:insufficient_balance'`)
|
|
254
|
+
* for test mode - no real payment is made, but the specified scenario is
|
|
255
|
+
* simulated. Use for development and testing.
|
|
255
256
|
*
|
|
256
257
|
* @since 0.1.1
|
|
257
258
|
* @schema
|
|
@@ -317,7 +318,7 @@ interface Methods {
|
|
|
317
318
|
*
|
|
318
319
|
* | Scenario | Client | Webhook |
|
|
319
320
|
* |----------|--------|---------|
|
|
320
|
-
* | `
|
|
321
|
+
* | `'paid'` | `paid` | `finalized` |
|
|
321
322
|
* | `'paid:failed'` | `paid` | `failed` |
|
|
322
323
|
* | `'cancelled'` | `cancelled` | none |
|
|
323
324
|
* | `'error:*'` | `failed` | none |
|
|
@@ -343,7 +344,7 @@ interface Methods {
|
|
|
343
344
|
* @since 0.1.1
|
|
344
345
|
* @schema
|
|
345
346
|
*/
|
|
346
|
-
test?:
|
|
347
|
+
test?: PaymentTestScenario;
|
|
347
348
|
}>>;
|
|
348
349
|
/**
|
|
349
350
|
* Write text to the system clipboard.
|
|
@@ -412,6 +413,11 @@ type MethodPayload<M$1 extends MethodName> = Methods[M$1]['payload'];
|
|
|
412
413
|
/**
|
|
413
414
|
* Check if a method is supported in a given version.
|
|
414
415
|
*
|
|
416
|
+
* Uses the minimum version that introduced the method and returns true if
|
|
417
|
+
* the given version is >= that minimum (semver comparison). This supports
|
|
418
|
+
* versions not explicitly listed in releases (e.g. 0.1.4 when method was
|
|
419
|
+
* added in 0.1.1).
|
|
420
|
+
*
|
|
415
421
|
* @param method - The method name to check.
|
|
416
422
|
* @param version - The contract version (must be a valid version string, not undefined).
|
|
417
423
|
* @returns `true` if the method is supported in the given version, `false` otherwise.
|
|
@@ -520,9 +526,45 @@ interface AlienContextValue {
|
|
|
520
526
|
* Whether the bridge is available (running inside Alien App).
|
|
521
527
|
*/
|
|
522
528
|
isBridgeAvailable: boolean;
|
|
529
|
+
/**
|
|
530
|
+
* Manually signal to the host app that the miniapp is ready.
|
|
531
|
+
* Only needed when `autoReady` is set to `false`.
|
|
532
|
+
* Safe to call multiple times — only the first call sends the signal.
|
|
533
|
+
*/
|
|
534
|
+
ready: () => void;
|
|
523
535
|
}
|
|
524
536
|
interface AlienProviderProps {
|
|
525
537
|
children: ReactNode;
|
|
538
|
+
/**
|
|
539
|
+
* Whether to automatically send `app:ready` when the provider mounts.
|
|
540
|
+
* Defaults to `true`.
|
|
541
|
+
*
|
|
542
|
+
* Set to `false` if you need to defer the ready signal (e.g., after
|
|
543
|
+
* fetching initial data), then call `ready()` from `useAlien()` when done.
|
|
544
|
+
*
|
|
545
|
+
* @default true
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
* ```tsx
|
|
549
|
+
* // Auto (default) — fires immediately on mount
|
|
550
|
+
* <AlienProvider>
|
|
551
|
+
* <App />
|
|
552
|
+
* </AlienProvider>
|
|
553
|
+
*
|
|
554
|
+
* // Manual — fire when you're ready
|
|
555
|
+
* <AlienProvider autoReady={false}>
|
|
556
|
+
* <App />
|
|
557
|
+
* </AlienProvider>
|
|
558
|
+
*
|
|
559
|
+
* function App() {
|
|
560
|
+
* const { ready } = useAlien();
|
|
561
|
+
* useEffect(() => {
|
|
562
|
+
* fetchData().then(() => ready());
|
|
563
|
+
* }, []);
|
|
564
|
+
* }
|
|
565
|
+
* ```
|
|
566
|
+
*/
|
|
567
|
+
autoReady?: boolean;
|
|
526
568
|
}
|
|
527
569
|
/**
|
|
528
570
|
* Provider component that initializes the Alien miniapp context.
|
|
@@ -542,7 +584,8 @@ interface AlienProviderProps {
|
|
|
542
584
|
* ```
|
|
543
585
|
*/
|
|
544
586
|
declare function AlienProvider({
|
|
545
|
-
children
|
|
587
|
+
children,
|
|
588
|
+
autoReady
|
|
546
589
|
}: AlienProviderProps): ReactNode;
|
|
547
590
|
//#endregion
|
|
548
591
|
//#region src/errors.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -22,21 +22,28 @@ const AlienContext = createContext(null);
|
|
|
22
22
|
* }
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
function AlienProvider({ children }) {
|
|
25
|
+
function AlienProvider({ children, autoReady = true }) {
|
|
26
|
+
const readySent = useRef(false);
|
|
27
|
+
const ready = useCallback(() => {
|
|
28
|
+
if (readySent.current) return;
|
|
29
|
+
readySent.current = true;
|
|
30
|
+
if (isBridgeAvailable()) send$1("app:ready", {});
|
|
31
|
+
}, []);
|
|
26
32
|
const value = useMemo(() => {
|
|
27
33
|
const launchParams = getLaunchParams();
|
|
28
34
|
return {
|
|
29
35
|
authToken: launchParams?.authToken,
|
|
30
36
|
contractVersion: launchParams?.contractVersion,
|
|
31
|
-
isBridgeAvailable: isBridgeAvailable()
|
|
37
|
+
isBridgeAvailable: isBridgeAvailable(),
|
|
38
|
+
ready
|
|
32
39
|
};
|
|
33
|
-
}, []);
|
|
40
|
+
}, [ready]);
|
|
34
41
|
useEffect(() => {
|
|
35
42
|
if (!value.isBridgeAvailable) console.warn("[@alien_org/react] Bridge is not available. Running in dev mode? The SDK will handle errors gracefully, but bridge communication will not work.");
|
|
36
43
|
}, [value.isBridgeAvailable]);
|
|
37
44
|
useEffect(() => {
|
|
38
|
-
if (
|
|
39
|
-
}, [
|
|
45
|
+
if (autoReady) ready();
|
|
46
|
+
}, [autoReady, ready]);
|
|
40
47
|
return /* @__PURE__ */ jsx(AlienContext.Provider, {
|
|
41
48
|
value,
|
|
42
49
|
children
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alien_org/react",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"prepublishOnly": "bun run build"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@alien_org/bridge": "0.1
|
|
38
|
-
"@alien_org/contract": "0.1
|
|
37
|
+
"@alien_org/bridge": "0.2.1",
|
|
38
|
+
"@alien_org/contract": "0.2.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": "^18 || ^19",
|