@sentroy-co/client-sdk 2.2.0 → 2.2.1
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 +139 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<h3 align="center">Sentroy Client SDK for TypeScript</h3>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
|
|
8
|
+
TypeScript SDK to interact with the Sentroy platform API + opt-in React components.<br />
|
|
9
9
|
Manage mail (domains, mailboxes, templates, inbox, send) and storage (buckets, media) from a single entry point.
|
|
10
10
|
</p>
|
|
11
11
|
|
|
@@ -271,10 +271,147 @@ try {
|
|
|
271
271
|
| `accessToken` | `string` | Yes | Access token (`stk_...`) |
|
|
272
272
|
| `timeout` | `number` | No | Request timeout in ms (default: `30000`) |
|
|
273
273
|
|
|
274
|
+
## React components (`@sentroy-co/client-sdk/react`)
|
|
275
|
+
|
|
276
|
+
Optional subpath. Only loaded if you import it; React + react-dom are
|
|
277
|
+
declared as **optional peer dependencies** so server-only consumers
|
|
278
|
+
don't need to install them.
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
npm install react react-dom
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### `MediaManager`
|
|
285
|
+
|
|
286
|
+
Drop-in storage browser/uploader for end-user apps. Talks to the same
|
|
287
|
+
Sentroy client you already use; renders Tailwind classes (host app's
|
|
288
|
+
Tailwind setup is reused — the package ships no styles).
|
|
289
|
+
|
|
290
|
+
```tsx
|
|
291
|
+
"use client"
|
|
292
|
+
|
|
293
|
+
import { Sentroy } from "@sentroy-co/client-sdk"
|
|
294
|
+
import { MediaManager } from "@sentroy-co/client-sdk/react"
|
|
295
|
+
|
|
296
|
+
const client = new Sentroy({
|
|
297
|
+
baseUrl: "https://sentroy.com",
|
|
298
|
+
companySlug: "my-company",
|
|
299
|
+
accessToken: "stk_...",
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
export default function Page() {
|
|
303
|
+
return (
|
|
304
|
+
<MediaManager
|
|
305
|
+
client={client}
|
|
306
|
+
multiple
|
|
307
|
+
accept="image/*"
|
|
308
|
+
onChange={(selected) => console.log(selected)}
|
|
309
|
+
onSelect={(selected) => console.log("confirmed:", selected)}
|
|
310
|
+
/>
|
|
311
|
+
)
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
#### Features
|
|
316
|
+
|
|
317
|
+
- Bucket selector (auto-picks first if `bucketSlug` not provided)
|
|
318
|
+
- Search (filename) + file-type filter (image / video / audio / pdf / doc / archive / code)
|
|
319
|
+
- Upload via button **and** drag-and-drop
|
|
320
|
+
- Single or multi selection (`multiple` prop)
|
|
321
|
+
- `initialValue` accepts `Media[]` or `string[]` (id list) — pre-selected
|
|
322
|
+
on mount, fires `onChange` immediately so parent state stays in sync
|
|
323
|
+
- Press `Space` while a card is selected → opens it in fullscreen
|
|
324
|
+
**Lightbox** (image / video / audio render natively, others get a
|
|
325
|
+
download fallback). `Esc` closes, `←/→` step through siblings
|
|
326
|
+
- Detail pane on the right (large screens) — preview, metadata,
|
|
327
|
+
delete, "Use selection" CTA when `onSelect` provided
|
|
328
|
+
|
|
329
|
+
#### Props
|
|
330
|
+
|
|
331
|
+
| Prop | Type | Required | Description |
|
|
332
|
+
|----------------------|-------------------------------------------------------|:-:|:--|
|
|
333
|
+
| `client` | `Sentroy` | Yes | The configured client instance |
|
|
334
|
+
| `bucketSlug` | `string` | | Initial bucket; default = first one in the list |
|
|
335
|
+
| `multiple` | `boolean` | | Allow multi-selection. Default `false` |
|
|
336
|
+
| `accept` | `string` | | MIME pattern for upload, e.g. `"image/*"` |
|
|
337
|
+
| `initialValue` | `Array<Media \| string>` | | Pre-selected items (objects or ids) |
|
|
338
|
+
| `onChange` | `(selected: Media[]) => void` | | Fires on every selection change |
|
|
339
|
+
| `onSelect` | `(selected: Media[]) => void` | | Fires on confirm — picker dialogs use this |
|
|
340
|
+
| `bucketFilter` | `(b: Bucket) => boolean` | | Filter the bucket dropdown — hide system buckets |
|
|
341
|
+
| `showDetailsPane` | `boolean` | | Default `true` |
|
|
342
|
+
| `showBucketSelector` | `boolean` | | Default `true` |
|
|
343
|
+
| `className` | `string` | | Root wrapper class |
|
|
344
|
+
| `classNames` | `MediaManagerClassNames` | | Per-region class overrides (see theming) |
|
|
345
|
+
|
|
346
|
+
#### Theming
|
|
347
|
+
|
|
348
|
+
The component uses Tailwind utility classes that consume your design
|
|
349
|
+
tokens (`bg-background`, `text-foreground`, `border-border`,
|
|
350
|
+
`text-muted-foreground`, `bg-muted`, etc.). Drop-in usage in any
|
|
351
|
+
shadcn-style codebase needs no extra setup.
|
|
352
|
+
|
|
353
|
+
For finer control, override individual sections via `classNames`:
|
|
354
|
+
|
|
355
|
+
```tsx
|
|
356
|
+
<MediaManager
|
|
357
|
+
client={client}
|
|
358
|
+
className="h-[600px] rounded-2xl border-purple-200"
|
|
359
|
+
classNames={{
|
|
360
|
+
toolbar: "bg-purple-50",
|
|
361
|
+
uploadButton: "bg-purple-600 text-white",
|
|
362
|
+
cardSelected: "ring-purple-400 border-purple-400",
|
|
363
|
+
grid: "sm:grid-cols-2 md:grid-cols-3", // override grid density
|
|
364
|
+
}}
|
|
365
|
+
/>
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
Available keys: `root`, `toolbar`, `searchInput`, `filterSelect`,
|
|
369
|
+
`uploadButton`, `bucketSelect`, `grid`, `card`, `cardSelected`,
|
|
370
|
+
`thumbnail`, `cardMeta`, `empty`, `details`, `dropZoneOverlay`.
|
|
371
|
+
|
|
372
|
+
When you migrate to a different theme system later, change tokens in
|
|
373
|
+
one place — every Tailwind utility resolves through your `globals.css`.
|
|
374
|
+
|
|
375
|
+
#### `Lightbox` (standalone)
|
|
376
|
+
|
|
377
|
+
Exported separately so you can use it outside `MediaManager` (e.g. in
|
|
378
|
+
a feed view):
|
|
379
|
+
|
|
380
|
+
```tsx
|
|
381
|
+
import { Lightbox } from "@sentroy-co/client-sdk/react"
|
|
382
|
+
|
|
383
|
+
const [active, setActive] = useState<Media | null>(null)
|
|
384
|
+
|
|
385
|
+
return (
|
|
386
|
+
<>
|
|
387
|
+
{/* …trigger… */}
|
|
388
|
+
{active && (
|
|
389
|
+
<Lightbox media={active} onClose={() => setActive(null)} />
|
|
390
|
+
)}
|
|
391
|
+
</>
|
|
392
|
+
)
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
Image / video / audio rendered inline; everything else gets a download
|
|
396
|
+
button. `Esc` closes, optional `onPrev` / `onNext` add ←/→ navigation.
|
|
397
|
+
|
|
398
|
+
#### Helpers
|
|
399
|
+
|
|
400
|
+
```ts
|
|
401
|
+
import {
|
|
402
|
+
cn, // tiny class joiner
|
|
403
|
+
formatBytes, // 1234 → "1.21 KB"
|
|
404
|
+
detectKind, // image | video | audio | pdf | doc | archive | code | other
|
|
405
|
+
KIND_LABELS,
|
|
406
|
+
type MediaKind,
|
|
407
|
+
} from "@sentroy-co/client-sdk/react"
|
|
408
|
+
```
|
|
409
|
+
|
|
274
410
|
## Requirements
|
|
275
411
|
|
|
276
412
|
- Node.js 18+ (uses native `fetch`)
|
|
277
|
-
-
|
|
413
|
+
- React 18+ (only if you import from `/react`)
|
|
414
|
+
- Tailwind CSS in the host app (only for React components)
|
|
278
415
|
|
|
279
416
|
## Raw Documentation
|
|
280
417
|
|