@cstar.help/react 0.10.1 → 0.10.3

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
@@ -2,10 +2,10 @@
2
2
 
3
3
  React hooks for the [cStar](https://cstar.help) customer support platform. Build custom chat widgets and knowledge base UIs with type-safe, SSR-compatible hooks.
4
4
 
5
- - **React 18+** — hooks with automatic loading states and error handling
6
- - **Three modules** — Chat (real-time messaging), Library (knowledge base), and Community (forum)
7
- - **TypeScript-first** — full type definitions included
8
- - **Tiny** — ~18 KB, tree-shakeable, only peer deps
5
+ - **React 18+**: hooks with automatic loading states and error handling
6
+ - **Three modules**: Chat (real-time messaging), Library (knowledge base), and Community (forum)
7
+ - **TypeScript-first**: full type definitions included
8
+ - **Tiny**: ~18 KB, tree-shakeable, only peer deps
9
9
 
10
10
  ## Install
11
11
 
@@ -82,7 +82,7 @@ function ChatWindow({ ticketId }) {
82
82
  const [text, setText] = useState('');
83
83
 
84
84
  const handleSend = async () => {
85
- await send(text); // optimistic — appears instantly
85
+ await send(text); // optimistic: appears instantly
86
86
  setText('');
87
87
  };
88
88
 
@@ -109,7 +109,7 @@ function ChatWindow({ ticketId }) {
109
109
 
110
110
  ## Knowledge Base
111
111
 
112
- Wrap in `<CStarLibraryProvider>` for public knowledge base access — no auth required.
112
+ Wrap in `<CStarLibraryProvider>` for public knowledge base access. No auth required.
113
113
 
114
114
  ### Setup
115
115
 
@@ -117,6 +117,7 @@ Wrap in `<CStarLibraryProvider>` for public knowledge base access — no auth re
117
117
  import { CStarLibraryProvider } from '@cstar.help/react';
118
118
 
119
119
  function App() {
120
+ // Seeded with a test key (cstar seed)? Add publishableKey="pk_test_..." to read test articles.
120
121
  return (
121
122
  <CStarLibraryProvider teamSlug="acme">
122
123
  <HelpCenter />
@@ -184,7 +185,7 @@ function SearchBar() {
184
185
 
185
186
  ## Community
186
187
 
187
- Wrap in `<CStarCommunityProvider>` for public community forum access — no auth required.
188
+ Wrap in `<CStarCommunityProvider>` for public community forum access. No auth required.
188
189
 
189
190
  ### Setup
190
191
 
@@ -220,7 +221,7 @@ function CommunityForum() {
220
221
  <ul>
221
222
  {posts.map((post) => (
222
223
  <li key={post.id}>
223
- {post.title} — {post.voteCount} votes
224
+ {post.title} ({post.voteCount} votes)
224
225
  </li>
225
226
  ))}
226
227
  </ul>
@@ -303,11 +304,11 @@ function CommunitySearch() {
303
304
  ## Using with Next.js App Router (RSC)
304
305
 
305
306
  The dashboard provider (`CStarDashboardProvider`) wraps a `CStarClient`,
306
- which is a class instance — and React Server Components can't serialize
307
+ which is a class instance, and React Server Components can't serialize
307
308
  class instances across the server/client boundary. The provider therefore
308
309
  takes one of two prop shapes:
309
310
 
310
- **Recommended — pass a plain config object.** The provider builds (and
311
+ **Recommended: pass a plain config object.** The provider builds (and
311
312
  disposes) the client inside the `'use client'` boundary, so nothing
312
313
  class-shaped crosses the RSC boundary:
313
314
 
@@ -316,11 +317,17 @@ class-shaped crosses the RSC boundary:
316
317
  'use client';
317
318
  import { CStarDashboardProvider } from '@cstar.help/react';
318
319
 
319
- export function Providers({ children }: { children: React.ReactNode }) {
320
+ export function Providers({
321
+ children,
322
+ secretKey
323
+ }: {
324
+ children: React.ReactNode;
325
+ secretKey: string;
326
+ }) {
320
327
  return (
321
328
  <CStarDashboardProvider
322
329
  config={{
323
- apiKey: process.env.NEXT_PUBLIC_CSTAR_PUBLISHABLE_KEY!,
330
+ apiKey: secretKey, // passed down from your server, see below
324
331
  teamId: process.env.NEXT_PUBLIC_CSTAR_TEAM_ID!
325
332
  }}
326
333
  >
@@ -330,12 +337,16 @@ export function Providers({ children }: { children: React.ReactNode }) {
330
337
  }
331
338
  ```
332
339
 
333
- Use the `apiKey` field for a publishable key (`pk_live_*` / `pk_test_*`),
334
- NOT a secret key — the bundle ships to the browser. For server-only flows
335
- (an admin route handler, a server action), construct `CStarClient` with the
336
- secret key inline; never thread it into a provider.
340
+ Every dashboard hook calls team endpoints, and those need a secret key
341
+ (`sk_live_*` / `sk_test_*`): a publishable key gets 403
342
+ `publishable_key_forbidden` on reads and `publishable_key_write` on writes.
343
+ Whatever you pass to the provider reaches the browser, so use it only in a
344
+ trusted environment, such as an internal tool behind your own login where
345
+ everyone who can open the page may hold that key. Use a key scoped to what
346
+ the dashboard needs. For a public site, have the app call your own backend
347
+ (a route handler or server action) that holds a secret-key `CStarClient`.
337
348
 
338
- **Legacy — pass a pre-built client (deprecated).** If you already have a
349
+ **Legacy: pass a pre-built client (deprecated).** If you already have a
339
350
  client instance you want to share, the `client` prop still works, but you
340
351
  have to construct it inside `'use client'` and you take on responsibility
341
352
  for tearing down the realtime subscription:
@@ -346,21 +357,21 @@ import { useMemo } from 'react';
346
357
  import { CStarClient } from '@cstar.help/js';
347
358
  import { CStarDashboardProvider } from '@cstar.help/react';
348
359
 
349
- export function Providers({ children }) {
360
+ export function Providers({ children, secretKey }) {
350
361
  const client = useMemo(
351
362
  () =>
352
363
  new CStarClient({
353
- apiKey: process.env.NEXT_PUBLIC_CSTAR_PUBLISHABLE_KEY!,
364
+ apiKey: secretKey, // trusted environments only, as above
354
365
  teamId: process.env.NEXT_PUBLIC_CSTAR_TEAM_ID!
355
366
  }),
356
- []
367
+ [secretKey]
357
368
  );
358
369
  return <CStarDashboardProvider client={client}>{children}</CStarDashboardProvider>;
359
370
  }
360
371
  ```
361
372
 
362
373
  Either way, mark the file `'use client'`. Server components can sit above
363
- the provider in the tree — only the provider boundary needs to be a client
374
+ the provider in the tree. Only the provider boundary needs to be a client
364
375
  component.
365
376
 
366
377
  ## Requirements