@unisim/sdk 0.1.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 +101 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# @unisim/sdk
|
|
2
|
+
|
|
3
|
+
The shared React SDK for the Universal Suite. Every product (Universal PDF, Webinar, Exports, Cyber Assess, Ergo Assess) imports this package.
|
|
4
|
+
|
|
5
|
+
**No product should import `@supabase/supabase-js` directly** — go through the SDK so the underlying backend stays swappable.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @unisim/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
Wrap your app in `<UniversalProvider>`:
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { UniversalProvider } from '@unisim/sdk'
|
|
19
|
+
|
|
20
|
+
const config = {
|
|
21
|
+
supabaseUrl: import.meta.env.VITE_SUPABASE_URL!,
|
|
22
|
+
supabaseAnonKey: import.meta.env.VITE_SUPABASE_ANON_KEY!,
|
|
23
|
+
product: 'pdf', // or 'webinar' | 'exports' | 'cyber_assess' | 'ergo_assess'
|
|
24
|
+
cookieDomain: import.meta.env.PROD ? '.unisim.co.uk' : undefined,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
createRoot(document.getElementById('root')!).render(
|
|
28
|
+
<UniversalProvider config={config}>
|
|
29
|
+
<App />
|
|
30
|
+
</UniversalProvider>,
|
|
31
|
+
)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
In production, the `cookieDomain` of `.unisim.co.uk` makes the auth session shared across every product subdomain (no SSO/OAuth dance needed).
|
|
35
|
+
|
|
36
|
+
## Hooks
|
|
37
|
+
|
|
38
|
+
### Identity
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { useUser, useOrg } from '@unisim/sdk'
|
|
42
|
+
|
|
43
|
+
const { user, loading } = useUser()
|
|
44
|
+
const { org, orgs, setActiveOrg } = useOrg()
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Entitlements
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { useHasAccess, useHasFeature, useSeat } from '@unisim/sdk'
|
|
51
|
+
|
|
52
|
+
if (!useHasAccess('webinar')) return <UpsellPaywall />
|
|
53
|
+
if (useHasFeature('webinar.anonymous_attendees')) showAnonToggle()
|
|
54
|
+
|
|
55
|
+
const { active: hasSeat } = useSeat() // Enterprise seat check
|
|
56
|
+
if (!hasSeat) return <NoSeatAssigned />
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Changelog
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { useChangelog } from '@unisim/sdk'
|
|
63
|
+
|
|
64
|
+
const { releases, currentVersion } = useChangelog({ limit: 5 })
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Branding
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { useOrgBranding } from '@unisim/sdk'
|
|
71
|
+
|
|
72
|
+
const { logo_url, brand_color } = useOrgBranding()
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Usage telemetry
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { track, useUsageTracker } from '@unisim/sdk'
|
|
79
|
+
|
|
80
|
+
// Mount the tracker once near the app root:
|
|
81
|
+
useUsageTracker()
|
|
82
|
+
|
|
83
|
+
// Then call track() from anywhere:
|
|
84
|
+
track('pdf.document.opened', { pages: 12 })
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Org admin
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import {
|
|
91
|
+
useOrgMembers, useOrgSeats, useAuditLog,
|
|
92
|
+
assignSeat, revokeSeat, reassignSeat,
|
|
93
|
+
} from '@unisim/sdk'
|
|
94
|
+
|
|
95
|
+
const { pool, seats } = useOrgSeats() // { total, assigned, available }
|
|
96
|
+
const result = await assignSeat(supabase, { orgId, userId, assignedByUserId })
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Versioning
|
|
100
|
+
|
|
101
|
+
The SDK follows the suite's CalVer (`YYYY.MM.N`). Every product upgrades together when there's a coordinated release, so keep deps pinned per product but update them in a single sweep.
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@unisim/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared React SDK for the Universal Suite — auth, entitlements, usage telemetry, changelog, org admin.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.build.json",
|
|
21
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
22
|
+
"typecheck": "tsc --noEmit"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@supabase/supabase-js": "^2.45.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/react": "^18.3.0",
|
|
32
|
+
"react": "^18.3.0",
|
|
33
|
+
"typescript": "^5.7.2"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|