@axcode/axcloud-sdk 0.1.5 → 0.1.7-dev.332678a
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 +67 -5
- package/dist/index.d.mts +577 -2
- package/dist/index.d.ts +577 -2
- package/dist/index.js +589 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +569 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,7 +53,8 @@ function App() {
|
|
|
53
53
|
auth0={{
|
|
54
54
|
domain: "auth.axcloud.app",
|
|
55
55
|
clientId: "your-client-id",
|
|
56
|
-
redirectUri: window.location.origin
|
|
56
|
+
redirectUri: window.location.origin,
|
|
57
|
+
organization: "org_auth0_..." // Optional Auth0 Organization ID for invite-only member sites
|
|
57
58
|
}}
|
|
58
59
|
>
|
|
59
60
|
<Router>
|
|
@@ -64,6 +65,10 @@ function App() {
|
|
|
64
65
|
}
|
|
65
66
|
```
|
|
66
67
|
|
|
68
|
+
`orgId` is the AxCloud organization ID used by CMS APIs, for example `org_ba81807b`.
|
|
69
|
+
`auth0.organization` is the Auth0 Organization ID used during login, for example `org_o960yILn77d4vY6u`.
|
|
70
|
+
Set `auth0.organization` for invite-only customer member sites so Universal Login is scoped to that customer organization.
|
|
71
|
+
|
|
67
72
|
### 2. Fetch content
|
|
68
73
|
|
|
69
74
|
```tsx
|
|
@@ -87,10 +92,10 @@ function NewsPage() {
|
|
|
87
92
|
|
|
88
93
|
> **Content visibility:** When the user is authenticated, `useNews`, `useContent('pages')`, and `useContent('events')` automatically fetch **public + internal + members-only** content based on the user's organization membership. For anonymous users, only public content is returned.
|
|
89
94
|
|
|
90
|
-
Pages can be stored once in AxCloud with translations and requested per language:
|
|
95
|
+
Pages and news can be stored once in AxCloud with translations and requested per language:
|
|
91
96
|
|
|
92
97
|
```tsx
|
|
93
|
-
import { useContentItem } from '@axcode/axcloud-sdk'
|
|
98
|
+
import { useContentItem, useNews } from '@axcode/axcloud-sdk'
|
|
94
99
|
|
|
95
100
|
function AboutPage({ locale }: { locale: 'sv' | 'en' }) {
|
|
96
101
|
const { data: page } = useContentItem('pages', 'about-us', {
|
|
@@ -100,6 +105,12 @@ function AboutPage({ locale }: { locale: 'sv' | 'en' }) {
|
|
|
100
105
|
|
|
101
106
|
return <h1>{page?.title}</h1>
|
|
102
107
|
}
|
|
108
|
+
|
|
109
|
+
function NewsList({ locale }: { locale: 'sv' | 'en' }) {
|
|
110
|
+
const { data: news } = useNews({ lang: locale })
|
|
111
|
+
|
|
112
|
+
return news.map(item => <article key={item.id}>{item.title}</article>)
|
|
113
|
+
}
|
|
103
114
|
```
|
|
104
115
|
|
|
105
116
|
### 3. Add authentication
|
|
@@ -133,6 +144,27 @@ function MemberArea() {
|
|
|
133
144
|
}
|
|
134
145
|
```
|
|
135
146
|
|
|
147
|
+
The SDK keeps verification UI inside the product site. Render your own branded
|
|
148
|
+
notice when `needsEmailVerification` is true:
|
|
149
|
+
|
|
150
|
+
```tsx
|
|
151
|
+
const {
|
|
152
|
+
needsEmailVerification,
|
|
153
|
+
requestEmailVerification,
|
|
154
|
+
refreshUser,
|
|
155
|
+
} = useAuth()
|
|
156
|
+
|
|
157
|
+
if (needsEmailVerification) {
|
|
158
|
+
// Render the product's own verification notice.
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
await requestEmailVerification({ returnTo: window.location.href })
|
|
162
|
+
await refreshUser()
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The API resolves the recipient and organization from the authenticated token.
|
|
166
|
+
Return URLs are restricted to the organization's configured member site.
|
|
167
|
+
|
|
136
168
|
### 4. Use sections
|
|
137
169
|
|
|
138
170
|
```tsx
|
|
@@ -215,7 +247,35 @@ function HeroImage() {
|
|
|
215
247
|
|
|
216
248
|
> **Note:** Media URLs are signed S3 URLs that expire after 1 hour. The SDK automatically refreshes them before expiry (staleTime: 30 min).
|
|
217
249
|
|
|
218
|
-
### 6.
|
|
250
|
+
### 6. Fetch public documents
|
|
251
|
+
|
|
252
|
+
```tsx
|
|
253
|
+
import { useDocuments, useDocumentDownload } from '@axcode/axcloud-sdk'
|
|
254
|
+
|
|
255
|
+
function PublicDocuments() {
|
|
256
|
+
const { documents, isLoading } = useDocuments({ tags: ['handbook'], limit: 20 })
|
|
257
|
+
|
|
258
|
+
if (isLoading) return <Skeleton />
|
|
259
|
+
return (
|
|
260
|
+
<ul>
|
|
261
|
+
{documents.map(doc => (
|
|
262
|
+
<li key={doc.document_id}>
|
|
263
|
+
<DocumentLink documentId={doc.document_id} title={doc.title} />
|
|
264
|
+
</li>
|
|
265
|
+
))}
|
|
266
|
+
</ul>
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function DocumentLink({ documentId, title }: { documentId: string; title: string }) {
|
|
271
|
+
const { documentUrl } = useDocumentDownload(documentId)
|
|
272
|
+
return documentUrl ? <a href={documentUrl}>{title}</a> : <span>{title}</span>
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Only documents with `status: "published"` and `audience: "public"` are exposed through SDK document hooks.
|
|
277
|
+
|
|
278
|
+
### 7. Gate features by module
|
|
219
279
|
|
|
220
280
|
```tsx
|
|
221
281
|
import { ModuleGate, useOrg } from '@axcode/axcloud-sdk'
|
|
@@ -249,7 +309,7 @@ function Dashboard() {
|
|
|
249
309
|
|
|
250
310
|
| Hook | Description |
|
|
251
311
|
|------|-------------|
|
|
252
|
-
| `useAuth()` | Login/logout
|
|
312
|
+
| `useAuth()` | Login/logout, email-verification state, resend, and profile refresh |
|
|
253
313
|
| `useUser()` | Fetch current user with role and permissions |
|
|
254
314
|
| `useOrg()` | Fetch organization info and check modules |
|
|
255
315
|
| `useNews(options?)` | Fetch news articles. Returns public + internal + members content when authenticated. |
|
|
@@ -261,6 +321,8 @@ function Dashboard() {
|
|
|
261
321
|
| `useMedia(mediaId)` | Fetch specific media file URL |
|
|
262
322
|
| `useAvatar(userId)` | Fetch user avatar URL |
|
|
263
323
|
| `useMediaList(type)` | List media files |
|
|
324
|
+
| `useDocuments(options?)` | List published public documents |
|
|
325
|
+
| `useDocumentDownload(documentId)` | Fetch a signed document download URL |
|
|
264
326
|
|
|
265
327
|
### Content Query Options
|
|
266
328
|
|