@powerhousedao/reactor-browser 6.2.2-dev.9 → 6.2.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.
Files changed (74) hide show
  1. package/README.md +341 -0
  2. package/dist/attachment-service-KFFLBEuD.d.ts +1062 -0
  3. package/dist/attachment-service-KFFLBEuD.d.ts.map +1 -0
  4. package/dist/{client-u13cr-Vg.js → client-B8ezRmBB.js} +30 -3
  5. package/dist/client-B8ezRmBB.js.map +1 -0
  6. package/dist/client-BIHN_UyR.d.ts +14 -0
  7. package/dist/client-BIHN_UyR.d.ts.map +1 -0
  8. package/dist/{client-_Gh2Uf0E.js → client-D66jVnot.js} +79 -13
  9. package/dist/client-D66jVnot.js.map +1 -0
  10. package/dist/{document-by-id-dLYFX-xz.js → document-by-id-BSZqTN66.js} +81 -51
  11. package/dist/document-by-id-BSZqTN66.js.map +1 -0
  12. package/dist/document-model-modules-DfQBNGc-.js +419 -0
  13. package/dist/document-model-modules-DfQBNGc-.js.map +1 -0
  14. package/dist/document-operations-CBExT76y.js +2544 -0
  15. package/dist/document-operations-CBExT76y.js.map +1 -0
  16. package/dist/global-1rvI8VdA.d.ts +400 -0
  17. package/dist/global-1rvI8VdA.d.ts.map +1 -0
  18. package/dist/index-BE3wBHLP.d.ts +349 -0
  19. package/dist/index-BE3wBHLP.d.ts.map +1 -0
  20. package/dist/index-BIVDXw3K.d.ts +144 -0
  21. package/dist/index-BIVDXw3K.d.ts.map +1 -0
  22. package/dist/index.d.ts +385 -718
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +957 -1712
  25. package/dist/index.js.map +1 -1
  26. package/dist/{inspector-proxy-CvQDDxmT.d.ts → inspector-proxy-6h5VKAwt.d.ts} +4 -2
  27. package/dist/inspector-proxy-6h5VKAwt.d.ts.map +1 -0
  28. package/dist/{make-ph-event-functions-BHoLPif5.js → make-ph-event-functions-DBq3iWYn.js} +1 -1
  29. package/dist/{make-ph-event-functions-BHoLPif5.js.map → make-ph-event-functions-DBq3iWYn.js.map} +1 -1
  30. package/dist/{index-DS4W07Y8.d.ts → pglite-CntadC_p-9NDG14dS.d.ts} +2 -142
  31. package/dist/pglite-CntadC_p-9NDG14dS.d.ts.map +1 -0
  32. package/dist/{relational-Dj06-YkI.js → relational-D4sxGPz7.js} +2 -2
  33. package/dist/{relational-Dj06-YkI.js.map → relational-D4sxGPz7.js.map} +1 -1
  34. package/dist/renown-BHxwP7xU.js +97 -0
  35. package/dist/renown-BHxwP7xU.js.map +1 -0
  36. package/dist/{renown-D-1c_Bvx.js → renown-BIEv6bSI.js} +523 -57
  37. package/dist/renown-BIEv6bSI.js.map +1 -0
  38. package/dist/src/ai/index.d.ts +371 -0
  39. package/dist/src/ai/index.d.ts.map +1 -0
  40. package/dist/src/ai/index.js +1067 -0
  41. package/dist/src/ai/index.js.map +1 -0
  42. package/dist/src/analytics/index.d.ts +1 -1
  43. package/dist/src/analytics/index.js +2 -1
  44. package/dist/src/analytics/index.js.map +1 -1
  45. package/dist/src/graphql/client.d.ts +3 -2
  46. package/dist/src/graphql/client.js +1 -1
  47. package/dist/src/graphql-client/entry.d.ts +4 -0
  48. package/dist/src/graphql-client/entry.js +4 -0
  49. package/dist/src/relational/index.d.ts +1 -1
  50. package/dist/src/relational/index.js +1 -1
  51. package/dist/src/renown/index.d.ts +2 -2
  52. package/dist/src/renown/index.js +3 -2
  53. package/dist/src/rpc/index.d.ts +6 -3
  54. package/dist/src/rpc/index.d.ts.map +1 -1
  55. package/dist/src/rpc/index.js +41 -10
  56. package/dist/src/rpc/index.js.map +1 -1
  57. package/dist/store-BJYcr_FL.js +37 -0
  58. package/dist/store-BJYcr_FL.js.map +1 -0
  59. package/dist/switchboard-D4-_jwk-.js +271 -0
  60. package/dist/switchboard-D4-_jwk-.js.map +1 -0
  61. package/dist/{types-CPV0Cnsy.d.ts → types-6vDzbRRS.d.ts} +1 -1
  62. package/dist/{types-CPV0Cnsy.d.ts.map → types-6vDzbRRS.d.ts.map} +1 -1
  63. package/dist/{client-09xv0Dq6.d.ts → types-Dcv1ZLoW.d.ts} +87 -19
  64. package/dist/types-Dcv1ZLoW.d.ts.map +1 -0
  65. package/package.json +27 -10
  66. package/dist/client-09xv0Dq6.d.ts.map +0 -1
  67. package/dist/client-_Gh2Uf0E.js.map +0 -1
  68. package/dist/client-u13cr-Vg.js.map +0 -1
  69. package/dist/document-by-id-dLYFX-xz.js.map +0 -1
  70. package/dist/index-D3bV5rcl.d.ts +0 -216
  71. package/dist/index-D3bV5rcl.d.ts.map +0 -1
  72. package/dist/index-DS4W07Y8.d.ts.map +0 -1
  73. package/dist/inspector-proxy-CvQDDxmT.d.ts.map +0 -1
  74. 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,343 @@ 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`. Adapters mount on first demand — a
710
+ `login()` click, `logout()`, `useRenownWalletAdapter`, or an OAuth redirect
711
+ return — not because a stored session was restored, so a signed-in visitor on a
712
+ page that never signs in or out downloads no wallet code. Once mounted they stay
713
+ mounted for the page's life. The wallet Provider tree wraps only the adapter
714
+ bridges (each library's modal portals to `<body>`), never your `children`, so
715
+ activating login never remounts your app. Props: `adapters`
716
+ (`WalletAdapterDescriptor[]`), `theme?`, `children`.
717
+
718
+ ### `useRenownLoginMethods(labels?)`
719
+
720
+ Returns `{ id, label }[]` — one per login method the mounted
721
+ `RenownWalletProvider`'s adapters offer, deduped, in descriptor-array order —
722
+ reading each descriptor's eager metadata only (no wallet libraries load).
723
+ Reorder the array you pass the provider to reorder the buttons. Override labels
724
+ via the argument. Wire each to `login(undefined, id)`.
725
+
726
+ The descriptors come from the provider, not from a prop or context, so a login UI
727
+ mounted **outside** the provider's subtree still gets the full list — Connect
728
+ renders its login modal as a sibling of the app. Empty when no provider is
729
+ mounted, which is the redirect-only case.
730
+
731
+ ### `useRenownWalletAdapter<T>(id)` — headless sign-in (custom screens)
732
+
733
+ Returns the controller of one mounted adapter by its `meta.id`, typed as that
734
+ adapter's own surface, so a host can draw its own sign-in screens without
735
+ importing the wallet library. Rendering the hook activates the wallet tree (that
736
+ is when the adapter's library loads), so call it from the sign-in route, not the
737
+ app shell; a signed-out visitor on a route that never renders it downloads no
738
+ wallet code. `undefined` until the adapter is mounted.
739
+
740
+ Privy's controller adds email OTP (`sendCode` / `loginWithCode`) plus its auth
741
+ state. Pass the session that `loginWithCode` resolves to into `login(session)`;
742
+ it is a Privy embedded wallet, so it signs the Renown credential silently:
743
+
744
+ ```tsx
745
+ "use client";
746
+ import { useRenownAuth, useRenownWalletAdapter } from "@powerhousedao/reactor-browser/renown";
747
+ // Type-only import: erased at runtime, so @privy-io stays out of the bundle.
748
+ import type { PrivyWalletController } from "@renown/sdk/wallet/privy";
749
+ import { useSyncExternalStore } from "react";
750
+
751
+ function EmailLogin() {
752
+ const privy = useRenownWalletAdapter<PrivyWalletController>("privy");
753
+ const { login } = useRenownAuth();
754
+ const state = useSyncExternalStore(
755
+ privy?.subscribeState ?? (() => () => {}),
756
+ () => privy?.getState(),
757
+ () => undefined,
758
+ );
759
+
760
+ if (!privy) return <Spinner />; // Privy is loading
761
+ return (
762
+ <>
763
+ <EmailForm
764
+ busy={state?.emailStatus === "sending-code"}
765
+ onSubmit={(email) => privy.sendCode(email, { disableSignup: true })}
766
+ />
767
+ <CodeForm
768
+ busy={state?.emailStatus === "submitting-code"}
769
+ error={state?.emailError}
770
+ onSubmit={async (code) => login(await privy.loginWithCode(code))}
771
+ />
772
+ </>
773
+ );
774
+ }
775
+ ```
776
+
777
+ `privyAdapter({ …, methods: ["email"], chain })` keeps Privy's own modal
778
+ restricted to email (so it skips the wallet connectors) and pins the embedded
779
+ wallet to the chain Renown issues on — pass the same chain you set as
780
+ `chainId`. The adapter also sets Privy's `appearance.walletList` to
781
+ `["detected_ethereum_wallets"]`: any other value makes Privy fetch the
782
+ WalletConnect explorer listings (~163 KB) on mount, even with external wallets
783
+ disabled. Pass `walletList` to override if you do want those listings.
784
+
785
+ ### Next.js
786
+
787
+ The integration is the same, with four things worth knowing:
788
+
789
+ - Pass `ssr: true` to `rainbowAdapter` so wagmi defers its hydrate reconnect to
790
+ an effect instead of running it during render.
791
+ - Keep the descriptor array at **module scope** (or in a `useMemo`).
792
+ `RenownWalletProvider` snapshots it on mount, so an array rebuilt inline in JSX
793
+ silently pins the first render's value.
794
+ - Give the descriptor array **its own module**, separate from config your server
795
+ code reads. Turbopack follows the adapters' lazy imports when computing RSC
796
+ boundaries, so a server module that imports anything sitting next to the
797
+ descriptors pulls the client-only wallet factories into the server graph and
798
+ the build fails.
799
+ - `RenownProvider` is SSR-safe: no `ssr: false`, no dynamic import needed. Only
800
+ the component that renders login buttons needs `"use client"`.
801
+ - Nothing needs a `next.config.ts` alias. If you find yourself stubbing
802
+ `@renown/sdk/wallet/<id>`, you are importing an adapter you don't use.
803
+
804
+ `test/test-fusion` in the monorepo is a runnable Next.js example (App Router,
805
+ server session cookie, Playwright e2e against the mock adapter).
806
+
807
+ ### Writing your own adapter
808
+
809
+ `RenownWalletProvider` takes descriptors, not a fixed set of adapter ids, so any
810
+ package can supply one. The contract is:
811
+
812
+ ```ts
813
+ import type { WalletAdapterDescriptor } from "@renown/sdk/wallet";
814
+
815
+ export function myAdapter(config: MyConfig): WalletAdapterDescriptor {
816
+ return {
817
+ meta: {
818
+ id: "my-adapter", // stable + unique among the host's adapters
819
+ supportedMethods: ["wallet"], // must be known before load()
820
+ redirectReturnParams: [], // URL params your full-page OAuth return leaves
821
+ },
822
+ load: () => import("./factory.js").then((m) => m.createMyAdapter(config)),
823
+ };
824
+ }
825
+ ```
826
+
827
+ `load()` resolves a `WalletAdapterImpl`: a `Provider` component and a
828
+ `useController()` hook returning `connect(method?)` / `disconnect()` /
829
+ `getSession()` and, if your flow leaves the page, `subscribe()` so sign-in can
830
+ complete on the redirect back. Keep the module holding `myAdapter` free of your
831
+ wallet library — `meta` is read before anything loads. `supportedMethods` must
832
+ come from `LoginMethod` (`wallet`, `google`, `email`, `apple`); a method the host
833
+ has no label for falls back to showing its id.
834
+
835
+ ### Testing (mock adapter)
836
+
837
+ For e2e/dev, enable the **mock adapter** (`@renown/sdk/wallet/mock`) via the
838
+ `mock` key. It's a headless signer backed by a viem local account — real EIP-712
839
+ signatures, **no wallet extension or OAuth** — so sign-in runs deterministically
840
+ in CI. **TEST/DEV ONLY; never enable in production** (it signs with a known key).
841
+
842
+ ```tsx
843
+ <RenownWalletProvider adapters={{ mock: { methods: ["wallet", "google", "email"] } }}>
844
+ <App />
845
+ </RenownWalletProvider>
846
+ ```
847
+
848
+ See `test/test-fusion/e2e` (Playwright + mock adapter) and `test/vetra-e2e`
849
+ (Connect login surface) for runnable examples, and the Powerhouse Academy
850
+ "Renown authentication flow" guide for the full walkthrough.