@proappstore/sdk 1.16.58 → 1.16.59
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 +16 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,6 +18,8 @@ import { initPro } from '@proappstore/sdk'
|
|
|
18
18
|
const app = initPro({ appId: 'my-app' })
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
Then wrap the whole app in `<ProShell app={app} appName="…" nav={[…]}>`, the standard app frame with the gates, topbar, main navigation and resilience layer. See [ProShell Component](#proshell-component).
|
|
22
|
+
|
|
21
23
|
Options:
|
|
22
24
|
|
|
23
25
|
| Option | Default | Description |
|
|
@@ -508,9 +510,9 @@ const all = await app.roles.listAll()
|
|
|
508
510
|
// [{ userId: 'user-456', role: 'moderator' }, ...]
|
|
509
511
|
```
|
|
510
512
|
|
|
511
|
-
## React Hooks
|
|
513
|
+
## React Hooks
|
|
512
514
|
|
|
513
|
-
|
|
515
|
+
Every app is wrapped in [`ProShell`](#proshell-component), which already runs the sign-in and subscription gates. Use these hooks inside its screens to read identity and subscription state, or to gate a single screen. Import from `@proappstore/sdk` or `@proappstore/sdk/hooks`.
|
|
514
516
|
|
|
515
517
|
### useProAuth
|
|
516
518
|
|
|
@@ -522,11 +524,10 @@ import { useProAuth } from '@proappstore/sdk/hooks'
|
|
|
522
524
|
|
|
523
525
|
const app = initPro({ appId: 'my-app' })
|
|
524
526
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
return <p>Welcome, {user.login}! <button onClick={signOut}>Sign out</button></p>
|
|
527
|
+
// A screen inside <ProShell>: the shell has already signed the user in.
|
|
528
|
+
function Welcome() {
|
|
529
|
+
const { user, signOut } = useProAuth(app)
|
|
530
|
+
return <p>Welcome, {user?.login}! <button onClick={signOut}>Sign out</button></p>
|
|
530
531
|
}
|
|
531
532
|
```
|
|
532
533
|
|
|
@@ -547,7 +548,7 @@ function Billing() {
|
|
|
547
548
|
|
|
548
549
|
### useProGate
|
|
549
550
|
|
|
550
|
-
Combined auth + subscription gate. Returns a single `gate` state for easy conditional rendering.
|
|
551
|
+
Combined auth + subscription gate. Returns a single `gate` state for easy conditional rendering. ProShell gates the whole app; use this for one Pro-only screen in an app that otherwise allows free users.
|
|
551
552
|
|
|
552
553
|
```tsx
|
|
553
554
|
import { initPro } from '@proappstore/sdk'
|
|
@@ -555,19 +556,19 @@ import { useProGate } from '@proappstore/sdk/hooks'
|
|
|
555
556
|
|
|
556
557
|
const app = initPro({ appId: 'my-app' })
|
|
557
558
|
|
|
558
|
-
|
|
559
|
-
|
|
559
|
+
// A screen inside <ProShell allowFree>: only this screen needs a subscription.
|
|
560
|
+
function ReportsScreen() {
|
|
561
|
+
const { gate, upgrade } = useProGate(app, { allowFree: false })
|
|
560
562
|
|
|
561
563
|
if (gate === 'loading') return <p>Loading...</p>
|
|
562
|
-
if (gate === 'signed-out') return <button onClick={signIn}>Sign in</button>
|
|
563
564
|
if (gate === 'no-subscription') return <button onClick={() => upgrade()}>Upgrade</button>
|
|
564
|
-
return <
|
|
565
|
+
return <Reports />
|
|
565
566
|
}
|
|
566
567
|
```
|
|
567
568
|
|
|
568
569
|
Gate states: `'loading'` | `'signed-out'` | `'no-subscription'` | `'ready'`
|
|
569
570
|
|
|
570
|
-
|
|
571
|
+
`allowFree` defaults to `true` (free users pass); pass `{ allowFree: false }` to require an active subscription.
|
|
571
572
|
|
|
572
573
|
## ProShell Component
|
|
573
574
|
|
|
@@ -656,6 +657,8 @@ Do not build navigation into a page, and do not stack a second navbar under the
|
|
|
656
657
|
|
|
657
658
|
For a fully custom layout, use `<ProShell app={app} hideTopbar hideFooter>` and compose `NavBar`, `ProfileMenu`, `SignInButton`, `GateScreen`, and hooks from `@proappstore/sdk/ui` and `@proappstore/sdk/hooks`.
|
|
658
659
|
|
|
660
|
+
The children render only after the gates pass: signed-out visitors see the sign-in screen with no topbar or navigation, and `platform-cookie` apps show it briefly to returning users while the session hydrates. Routing caveats (routers, hash routing) and a step-by-step guide to replacing a hand-rolled header or navbar are in the [SDK overview](https://docs.proappstore.online/sdk-overview/#proshell-component).
|
|
661
|
+
|
|
659
662
|
## UI Components
|
|
660
663
|
|
|
661
664
|
Import from `@proappstore/sdk/ui`:
|