@powerhousedao/reactor-browser 6.2.2-dev.5 → 6.2.2-dev.50

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.
Files changed (66) hide show
  1. package/README.md +283 -0
  2. package/dist/attachment-service-CghxHYta.d.ts +970 -0
  3. package/dist/attachment-service-CghxHYta.d.ts.map +1 -0
  4. package/dist/client-BaHKLGy5.d.ts +14 -0
  5. package/dist/client-BaHKLGy5.d.ts.map +1 -0
  6. package/dist/{client-u13cr-Vg.js → client-Zz_l9QzI.js} +30 -3
  7. package/dist/client-Zz_l9QzI.js.map +1 -0
  8. package/dist/{client-_Gh2Uf0E.js → client-s_ISz_Zs.js} +30 -4
  9. package/dist/client-s_ISz_Zs.js.map +1 -0
  10. package/dist/{document-by-id-dLYFX-xz.js → document-by-id-DWEQI7wn.js} +48 -43
  11. package/dist/document-by-id-DWEQI7wn.js.map +1 -0
  12. package/dist/document-operations-D0ePGjbp.js +2778 -0
  13. package/dist/document-operations-D0ePGjbp.js.map +1 -0
  14. package/dist/global-CbyAMlZd.d.ts +400 -0
  15. package/dist/global-CbyAMlZd.d.ts.map +1 -0
  16. package/dist/index-CxxxP14A.d.ts +144 -0
  17. package/dist/index-CxxxP14A.d.ts.map +1 -0
  18. package/dist/index-DPq1VjpB.d.ts +345 -0
  19. package/dist/index-DPq1VjpB.d.ts.map +1 -0
  20. package/dist/index.d.ts +177 -695
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +256 -1627
  23. package/dist/index.js.map +1 -1
  24. package/dist/{inspector-proxy-CvQDDxmT.d.ts → inspector-proxy-CaCFdEG4.d.ts} +4 -2
  25. package/dist/inspector-proxy-CaCFdEG4.d.ts.map +1 -0
  26. package/dist/{make-ph-event-functions-BHoLPif5.js → make-ph-event-functions-DBq3iWYn.js} +1 -1
  27. package/dist/{make-ph-event-functions-BHoLPif5.js.map → make-ph-event-functions-DBq3iWYn.js.map} +1 -1
  28. package/dist/{index-DS4W07Y8.d.ts → pglite-CntadC_p-BtEalg1H.d.ts} +2 -142
  29. package/dist/pglite-CntadC_p-BtEalg1H.d.ts.map +1 -0
  30. package/dist/{relational-Dj06-YkI.js → relational-C_0GdGVN.js} +2 -2
  31. package/dist/{relational-Dj06-YkI.js.map → relational-C_0GdGVN.js.map} +1 -1
  32. package/dist/renown-BZabzj4l.js +68 -0
  33. package/dist/renown-BZabzj4l.js.map +1 -0
  34. package/dist/{renown-D-1c_Bvx.js → renown-C7a1ygsj.js} +471 -57
  35. package/dist/renown-C7a1ygsj.js.map +1 -0
  36. package/dist/src/analytics/index.d.ts +1 -1
  37. package/dist/src/analytics/index.js +2 -1
  38. package/dist/src/analytics/index.js.map +1 -1
  39. package/dist/src/graphql/client.d.ts +3 -2
  40. package/dist/src/graphql/client.js +1 -1
  41. package/dist/src/graphql-client/entry.d.ts +4 -0
  42. package/dist/src/graphql-client/entry.js +3 -0
  43. package/dist/src/relational/index.d.ts +1 -1
  44. package/dist/src/relational/index.js +1 -1
  45. package/dist/src/renown/index.d.ts +2 -2
  46. package/dist/src/renown/index.js +3 -2
  47. package/dist/src/rpc/index.d.ts +5 -3
  48. package/dist/src/rpc/index.d.ts.map +1 -1
  49. package/dist/src/rpc/index.js +37 -10
  50. package/dist/src/rpc/index.js.map +1 -1
  51. package/dist/store-DAJq6vSs.js +37 -0
  52. package/dist/store-DAJq6vSs.js.map +1 -0
  53. package/dist/{client-09xv0Dq6.d.ts → types-Bitg5Z5j.d.ts} +25 -13
  54. package/dist/types-Bitg5Z5j.d.ts.map +1 -0
  55. package/dist/{types-CPV0Cnsy.d.ts → types-wGaiXwjh.d.ts} +1 -1
  56. package/dist/{types-CPV0Cnsy.d.ts.map → types-wGaiXwjh.d.ts.map} +1 -1
  57. package/package.json +15 -9
  58. package/dist/client-09xv0Dq6.d.ts.map +0 -1
  59. package/dist/client-_Gh2Uf0E.js.map +0 -1
  60. package/dist/client-u13cr-Vg.js.map +0 -1
  61. package/dist/document-by-id-dLYFX-xz.js.map +0 -1
  62. package/dist/index-D3bV5rcl.d.ts +0 -216
  63. package/dist/index-D3bV5rcl.d.ts.map +0 -1
  64. package/dist/index-DS4W07Y8.d.ts.map +0 -1
  65. package/dist/inspector-proxy-CvQDDxmT.d.ts.map +0 -1
  66. package/dist/renown-D-1c_Bvx.js.map +0 -1
package/README.md CHANGED
@@ -9,6 +9,7 @@ This document contains all documentation comments for the hooks exported from `p
9
9
  - [Config: Editor](#config-editor)
10
10
  - [Config: Set Config by Object](#config-set-config-by-object)
11
11
  - [Config: Use Value by Key](#config-use-value-by-key)
12
+ - [Renown in-page sign-in](#renown-in-page-sign-in)
12
13
  - [Document by ID](#document-by-id)
13
14
  - [Document Cache](#document-cache)
14
15
  - [Document of Type](#document-of-type)
@@ -507,3 +508,285 @@ Strongly typed, inferred from type definition for the key.
507
508
  Gets the value of an item in the global document config for a given key.
508
509
 
509
510
  Strongly typed, inferred from type definition for the key.
511
+
512
+ ---
513
+
514
+ ## Renown in-page sign-in
515
+
516
+ Let users authenticate with Renown **inside your app** — no redirect to the
517
+ Renown portal — using pluggable wallet adapters (RainbowKit for external
518
+ wallets, Privy for social/email). This is the same integration Connect and the
519
+ `test-fusion` app use. Import from `@powerhousedao/reactor-browser/renown` (or
520
+ the package root).
521
+
522
+ ### Quick start — `RenownProvider`
523
+
524
+ Mount one provider high in your tree. It initializes the SDK, seeds the first
525
+ render (from a server session cookie for SSR, or `localStorage` for client-only
526
+ apps), mounts the wallet adapters (lazy-loaded on the first login click), keeps a
527
+ server-readable session cookie in sync when running under SSR, and revalidates
528
+ the stored credential against the switchboard.
529
+
530
+ ```tsx
531
+ import { RenownProvider } from "@powerhousedao/reactor-browser/renown";
532
+ import { privyAdapter } from "@renown/sdk/wallet/privy";
533
+ import { rainbowAdapter } from "@renown/sdk/wallet/rainbow";
534
+
535
+ // Module scope: the provider snapshots this array on mount.
536
+ const ADAPTERS = [
537
+ rainbowAdapter({ walletConnectProjectId: "..." }),
538
+ privyAdapter({ appId: "...", methods: ["google", "email"] }),
539
+ ];
540
+
541
+ <RenownProvider
542
+ appName="my-app"
543
+ namespace="my-app"
544
+ switchboardUrl="https://switchboard.example/graphql"
545
+ adapters={ADAPTERS}
546
+ theme="light" // "light" | "dark" | { mode, accentColor?, accentColorForeground? }
547
+ >
548
+ <App />
549
+ </RenownProvider>;
550
+ ```
551
+
552
+ **One chain per app.** `chainId` (default `1`) is the chain credentials are issued
553
+ on, and it is part of the user's DID (`did:pkh:eip155:<chainId>:<address>`), so the
554
+ same wallet on another chain is a different user. Sign-in from a wallet on a
555
+ different chain is rejected, so if you set `chainId`, pass matching `chains` to the
556
+ wallet adapters — that is what makes the wallet UI prompt a network switch rather
557
+ than failing at the end of the flow.
558
+
559
+ **Install only the peers of the adapters you import.** Importing
560
+ `@renown/sdk/wallet/rainbow` is what makes RainbowKit a build requirement; an app
561
+ that only imports `@renown/sdk/wallet/privy` needs no RainbowKit and no bundler
562
+ aliases. See the `@renown/sdk` README for the per-adapter peer list.
563
+
564
+ The provider is **SSR-safe** — it renders on the server without `ssr: false`;
565
+ the wallet libraries only load client-side on the first login click.
566
+
567
+ Then build the login UI with `useRenownLoginMethods` (the button list, read from
568
+ the mounted provider) and `useRenownAuth` (login + user state). Neither takes the
569
+ adapters, so the login UI need not sit inside the provider's subtree:
570
+
571
+ ```tsx
572
+ import {
573
+ useRenownAuth,
574
+ useRenownLoginMethods,
575
+ } from "@powerhousedao/reactor-browser/renown";
576
+
577
+ function Login() {
578
+ const { user, login, pending, error, logout } = useRenownAuth();
579
+ const methods = useRenownLoginMethods();
580
+ if (user) return <button onClick={() => void logout()}>Log out</button>;
581
+ return (
582
+ <>
583
+ {methods.map((m) => (
584
+ <button key={m.id} disabled={pending} onClick={() => login(undefined, m.id)}>
585
+ {m.label}
586
+ </button>
587
+ ))}
588
+ {error ? <p>{error.message}</p> : null}
589
+ </>
590
+ );
591
+ }
592
+ ```
593
+
594
+ `login(session?, method?)` activates the adapters on click, routes `method` to
595
+ the adapter that supports it, produces a `WalletSession`, and completes the
596
+ Renown credential sign-in via the switchboard — falling back to the redirect
597
+ flow when no switchboard/adapter is available.
598
+
599
+ ### À la carte
600
+
601
+ `RenownProvider` composes pieces you can also mount yourself — use them directly
602
+ only when you need a custom tree:
603
+
604
+ - `<Renown appName namespace switchboardUrl revalidate? />` — SDK init (renders
605
+ `null`; place high in the tree).
606
+ - `RenownWalletProvider` — wallet adapters (below).
607
+ - `RenownInitialUserProvider` — seeds the first render, via `initialAuth`
608
+ (three-state, preferred) or `initialUser` (a bare `User`; cannot express
609
+ "known signed out"). See [Server-side rendering](#server-side-rendering-ssr).
610
+
611
+ ### Auth state — `useRenownAuth` / `useRenownAuthAsync`
612
+
613
+ `useRenownAuth()` returns the live auth: `{ user, status, pending, error, login,
614
+ logout, displayName, displayAddress, ... }`. Gate on it with a plain `if` — no
615
+ wrapper component is needed:
616
+
617
+ ```tsx
618
+ function EditButton() {
619
+ const { user } = useRenownAuth();
620
+ if (!user) return null;
621
+ return <button>Edit</button>;
622
+ }
623
+ ```
624
+
625
+ `useRenownAuthAsync()` adds a collapsed `state: "authenticated" | "resolving" |
626
+ "unauthenticated"` (and `isResolving`) so you can show a skeleton during the
627
+ resolving window **without a Suspense boundary** — handy for client-only apps:
628
+
629
+ ```tsx
630
+ function EditButton() {
631
+ const { state } = useRenownAuthAsync();
632
+ if (state === "resolving") return <EditSkeleton />;
633
+ if (state === "unauthenticated") return null;
634
+ return <button>Edit</button>;
635
+ }
636
+ ```
637
+
638
+ `"resolving"` only appears when the answer is genuinely unknown. If the first
639
+ render already knows the visitor is signed out — no session cookie on the server,
640
+ no persisted user in `localStorage` — the state goes straight to
641
+ `"unauthenticated"`, so a logged-out visitor never sees the skeleton while the
642
+ SDK builds its keypair. A login you triggered (`pending`) still reports
643
+ `"resolving"`. `useRenownInitialAuth()` exposes the underlying signal as
644
+ `{ state: "authenticated" | "anonymous" | "unknown" }`.
645
+
646
+ ### Server-side rendering (SSR)
647
+
648
+ The provider tree is SSR-safe, so the logged-out shell renders on the server with
649
+ no `ssr: false`. To render **authenticated** content on the server (no flash),
650
+ give `RenownProvider` a server-resolved `session`:
651
+
652
+ ```tsx
653
+ // app/layout.tsx (server component)
654
+ import { verifySession } from "@/lib/dal";
655
+
656
+ const session = await verifySession(); // reads + verifies the session cookie
657
+ <RenownProvider appName="my-app" session={session}>
658
+ {children}
659
+ </RenownProvider>;
660
+ ```
661
+
662
+ Passing `session` also enables the **session-cookie sync**: after each login the
663
+ client mints a bearer token and POSTs it to `sessionEndpoint` (default
664
+ `/api/renown/session`), and clears it on logout. Your app provides the route
665
+ handler that sets an HttpOnly cookie, and a Data Access Layer that verifies it
666
+ with `verifyRenownSession` from `@renown/sdk/node` (see that package's README).
667
+
668
+ The POST body is a `RenownSessionCookie` — the bearer token plus a
669
+ `RenownSessionProfile` display hint carrying `documentId`, `username` and
670
+ `userImage`. Those let `verifyRenownSession` rebuild a `user.profile` matching
671
+ the client's, so the server renders the same name, avatar and profile links the
672
+ client will. Type your route handler with `RenownSessionCookie` rather than
673
+ redeclaring the shape — three copies of it drift.
674
+
675
+ ### Seeding: which source wins
676
+
677
+ The first render is seeded from whichever source can answer at that moment:
678
+
679
+ | Render | Source | Why |
680
+ | --- | --- | --- |
681
+ | Server | `session` (the cookie) | The only thing readable server-side |
682
+ | Hydration | `session` | Must match the server output |
683
+ | After mount | `localStorage` | Holds the credential the SDK actually restores |
684
+
685
+ `localStorage` becomes authoritative once mounted because that is what the SDK
686
+ reads on build; the cookie is a display hint that can go stale independently (it
687
+ expires on its own schedule). Omit `session` entirely for client-only apps —
688
+ `localStorage` then seeds every render, so a returning user is authenticated on
689
+ the first paint with no server involved.
690
+
691
+ ### Revalidation and profile refresh
692
+
693
+ Two separate background passes run on mount, neither blocking the paint:
694
+
695
+ - **Credential revalidation** re-checks the restored credential against the
696
+ switchboard and logs the user out if it was revoked or expired. Gated by the
697
+ `revalidate` prop (default `"always"`; `"never"` skips it). Fail-open — a
698
+ transient outage keeps the session.
699
+ - **Profile refresh** re-reads `username`/`userImage` and updates the store if
700
+ they changed. This runs **regardless of `revalidate`**, because it can never
701
+ log anyone out; apps that disabled revalidation still get fresh attributes.
702
+
703
+ Neither replaces server-side checks: the switchboard enforces the credential on
704
+ every real operation.
705
+
706
+ ### `RenownWalletProvider`
707
+
708
+ Registers the login activator, lazy-mounts the given adapters, and merges them
709
+ into one controller for `useRenownAuth`. The wallet Provider tree wraps only the
710
+ adapter bridges (each library's modal portals to `<body>`), never your
711
+ `children`, so activating login never remounts your app. Props: `adapters`
712
+ (`WalletAdapterDescriptor[]`), `theme?`, `children`.
713
+
714
+ ### `useRenownLoginMethods(labels?)`
715
+
716
+ Returns `{ id, label }[]` — one per login method the mounted
717
+ `RenownWalletProvider`'s adapters offer, deduped, in descriptor-array order —
718
+ reading each descriptor's eager metadata only (no wallet libraries load).
719
+ Reorder the array you pass the provider to reorder the buttons. Override labels
720
+ via the argument. Wire each to `login(undefined, id)`.
721
+
722
+ The descriptors come from the provider, not from a prop or context, so a login UI
723
+ mounted **outside** the provider's subtree still gets the full list — Connect
724
+ renders its login modal as a sibling of the app. Empty when no provider is
725
+ mounted, which is the redirect-only case.
726
+
727
+ ### Next.js
728
+
729
+ The integration is the same, with four things worth knowing:
730
+
731
+ - Pass `ssr: true` to `rainbowAdapter` so wagmi defers its hydrate reconnect to
732
+ an effect instead of running it during render.
733
+ - Keep the descriptor array at **module scope** (or in a `useMemo`).
734
+ `RenownWalletProvider` snapshots it on mount, so an array rebuilt inline in JSX
735
+ silently pins the first render's value.
736
+ - Give the descriptor array **its own module**, separate from config your server
737
+ code reads. Turbopack follows the adapters' lazy imports when computing RSC
738
+ boundaries, so a server module that imports anything sitting next to the
739
+ descriptors pulls the client-only wallet factories into the server graph and
740
+ the build fails.
741
+ - `RenownProvider` is SSR-safe: no `ssr: false`, no dynamic import needed. Only
742
+ the component that renders login buttons needs `"use client"`.
743
+ - Nothing needs a `next.config.ts` alias. If you find yourself stubbing
744
+ `@renown/sdk/wallet/<id>`, you are importing an adapter you don't use.
745
+
746
+ `test/test-fusion` in the monorepo is a runnable Next.js example (App Router,
747
+ server session cookie, Playwright e2e against the mock adapter).
748
+
749
+ ### Writing your own adapter
750
+
751
+ `RenownWalletProvider` takes descriptors, not a fixed set of adapter ids, so any
752
+ package can supply one. The contract is:
753
+
754
+ ```ts
755
+ import type { WalletAdapterDescriptor } from "@renown/sdk/wallet";
756
+
757
+ export function myAdapter(config: MyConfig): WalletAdapterDescriptor {
758
+ return {
759
+ meta: {
760
+ id: "my-adapter", // stable + unique among the host's adapters
761
+ supportedMethods: ["wallet"], // must be known before load()
762
+ redirectReturnParams: [], // URL params your full-page OAuth return leaves
763
+ },
764
+ load: () => import("./factory.js").then((m) => m.createMyAdapter(config)),
765
+ };
766
+ }
767
+ ```
768
+
769
+ `load()` resolves a `WalletAdapterImpl`: a `Provider` component and a
770
+ `useController()` hook returning `connect(method?)` / `disconnect()` /
771
+ `getSession()` and, if your flow leaves the page, `subscribe()` so sign-in can
772
+ complete on the redirect back. Keep the module holding `myAdapter` free of your
773
+ wallet library — `meta` is read before anything loads. `supportedMethods` must
774
+ come from `LoginMethod` (`wallet`, `google`, `email`, `apple`); a method the host
775
+ has no label for falls back to showing its id.
776
+
777
+ ### Testing (mock adapter)
778
+
779
+ For e2e/dev, enable the **mock adapter** (`@renown/sdk/wallet/mock`) via the
780
+ `mock` key. It's a headless signer backed by a viem local account — real EIP-712
781
+ signatures, **no wallet extension or OAuth** — so sign-in runs deterministically
782
+ in CI. **TEST/DEV ONLY; never enable in production** (it signs with a known key).
783
+
784
+ ```tsx
785
+ <RenownWalletProvider adapters={{ mock: { methods: ["wallet", "google", "email"] } }}>
786
+ <App />
787
+ </RenownWalletProvider>
788
+ ```
789
+
790
+ See `test/test-fusion/e2e` (Playwright + mock adapter) and `test/vetra-e2e`
791
+ (Connect login surface) for runnable examples, and the Powerhouse Academy
792
+ "Renown authentication flow" guide for the full walkthrough.