@postrun/react 0.1.0 → 1.0.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.
package/README.md CHANGED
@@ -3,8 +3,8 @@
3
3
  React provider and hooks for the [Postrun API](https://postrun.ai).
4
4
 
5
5
  Wrap your app once, then build your UI from hooks that handle the data fetching,
6
- caching, and orchestration for you — the hosted OAuth connect flow, the media
7
- upload pipeline, live status polling, and pagination.
6
+ caching, and orchestration for you — the embedded one-click OAuth connect flow,
7
+ the media upload pipeline, live status polling, and pagination.
8
8
 
9
9
  ```tsx
10
10
  import { PostrunProvider } from '@postrun/react';
@@ -32,9 +32,9 @@ calls `getToken` to supply it. The secret key never touches the browser.
32
32
  **Profiles** — `useProfiles` · `useProfilesInfinite` · `useProfile` ·
33
33
  `useCreateProfile` · `useUpdateProfile` · `useDeleteProfile`
34
34
 
35
- **Connections** — `useConnect` (hosted OAuth) · `useConnections` ·
36
- `useConnection` · `useDiscoverableAccounts` · `useSelectAccount` ·
37
- `useDisconnect`
35
+ **Connections** — `useConnect` (embedded one-click OAuth) · `Connect` (drop-in) ·
36
+ `useConnections` · `useConnection` · `useDiscoverableAccounts` ·
37
+ `useSelectAccount` · `useDisconnect`
38
38
 
39
39
  **Media** — `useMediaUpload` (signed upload → bytes → poll until ready) ·
40
40
  `useMedia` · `useUpdateMedia` · `useDeleteMedia`
@@ -50,6 +50,60 @@ settles, so a scheduled post visibly transitions with no manual refetch.
50
50
  Composite, opinionated UI (a post composer, a calendar grid) is **deliberately
51
51
  not shipped** — that's your product and your taste. Build it from the hooks above.
52
52
 
53
+ ## One-click connect
54
+
55
+ Connect a platform from **your own button**, in your own app — no redirect, no
56
+ second click. `<Connect>` runs the OAuth popup in-page and, for multi-account
57
+ platforms (Meta Ads, Facebook Pages), hands you the discoverable accounts to draw
58
+ your own picker. It's headless: you render every pixel.
59
+
60
+ ```tsx
61
+ import { Connect } from '@postrun/react';
62
+
63
+ function ConnectX({
64
+ profileId,
65
+ onConnected,
66
+ }: {
67
+ profileId: string;
68
+ onConnected: () => void; // e.g. refetch your connections list
69
+ }) {
70
+ return (
71
+ <Connect profileId={profileId} platform="x" onConnected={onConnected}>
72
+ {({ state, start, select, reset }) => {
73
+ if (state.phase === 'picking') {
74
+ return (
75
+ <ul>
76
+ {state.accounts.map((a) => (
77
+ <li key={a.external_account_id}>
78
+ <button onClick={() => select(a.external_account_id)}>
79
+ {a.name ?? a.external_account_id}
80
+ </button>
81
+ </li>
82
+ ))}
83
+ </ul>
84
+ );
85
+ }
86
+ if (state.phase === 'error') {
87
+ return <button onClick={reset}>Try again</button>;
88
+ }
89
+ return (
90
+ // `start` MUST be called directly in the click — it opens the popup
91
+ // synchronously, so the browser keeps it inside the user gesture.
92
+ <button onClick={start} disabled={state.phase !== 'idle'}>
93
+ {state.phase === 'active' ? 'Connected ✓' : 'Connect X'}
94
+ </button>
95
+ );
96
+ }}
97
+ </Connect>
98
+ );
99
+ }
100
+ ```
101
+
102
+ Prefer wiring it yourself? `useConnect({ profileId, platform, onConnected })`
103
+ returns the same `{ state, start, select, reset }` — `<Connect>` is just a thin
104
+ render-prop wrapper over it. The hosted `/connect` page remains available as a
105
+ no-SDK fallback (link to the `hosted_connect_url` from a `POST .../connect`).
106
+
53
107
  ## License
54
108
 
55
109
  [Apache-2.0](../../LICENSE) — use it freely in your product, with an explicit