@poolse/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/CHANGELOG.md +33 -0
- package/LICENSE +21 -0
- package/README.md +79 -0
- package/dist/index.cjs +1004 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +775 -0
- package/dist/index.d.ts +775 -0
- package/dist/index.js +985 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@poolse/sdk` are documented here. Format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
|
|
5
|
+
[semver](https://semver.org).
|
|
6
|
+
|
|
7
|
+
## [0.1.0] — 2026-06-01
|
|
8
|
+
|
|
9
|
+
First publishable release.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `Poolse` client class with REST resources: `me`, `conversations`
|
|
14
|
+
(list/create/get/update + members), `messages` (send/list/mark-read +
|
|
15
|
+
edit/delete/replies/reactions on per-id handle), `attachments`
|
|
16
|
+
(presigned upload + download + delete).
|
|
17
|
+
- `RestClient` low-level wrapper:
|
|
18
|
+
- Bearer JWT via `config.getToken` (async or sync; nullable for
|
|
19
|
+
deliberate unauthenticated calls).
|
|
20
|
+
- Auto-generated `Idempotency-Key` for non-GET requests
|
|
21
|
+
(`crypto.randomUUID()` by default; overrideable).
|
|
22
|
+
- Exponential backoff with full jitter for transient failures.
|
|
23
|
+
- `Retry-After` header honoured on 429.
|
|
24
|
+
- Network errors retried (except `AbortError`).
|
|
25
|
+
- 401 → `AuthError`, 429 → `RateLimitedError`, other 4xx/5xx → `ApiError`,
|
|
26
|
+
network failures → `NetworkError`. All `instanceof`-checkable.
|
|
27
|
+
- Initial scaffold: TypeScript, dual ESM+CJS build via tsup, vitest,
|
|
28
|
+
eslint, prettier, Node 22 Docker dev environment.
|
|
29
|
+
|
|
30
|
+
## [0.0.1] — scaffolding only
|
|
31
|
+
|
|
32
|
+
Placeholder release. The real `Poolse` client class (REST + Channels +
|
|
33
|
+
offline queue) lands in subsequent SDK tasks under Phase 1F.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Poolse
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# `@poolse/sdk`
|
|
2
|
+
|
|
3
|
+
The headless TypeScript SDK for **[poolse](https://poolse.dev)** — realtime chat infrastructure.
|
|
4
|
+
|
|
5
|
+
REST + WebSocket + presence + typing + reactions + threads + attachments, all in one runtime-agnostic package. Works in browsers, Node, Deno, Bun, and React Native. No UI.
|
|
6
|
+
|
|
7
|
+
> Most React apps will want **[`@poolse/react`](https://www.npmjs.com/package/@poolse/react)** (hooks) or **[`@poolse/react-ui`](https://www.npmjs.com/package/@poolse/react-ui)** (prebuilt chat surface) instead. This package is the foundation underneath both.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @poolse/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { Poolse } from '@poolse/sdk';
|
|
19
|
+
|
|
20
|
+
const chat = new Poolse({
|
|
21
|
+
apiUrl: 'https://chat.example.com',
|
|
22
|
+
// Your backend mints a JWT for the signed-in End User and returns it.
|
|
23
|
+
// The SDK caches + refreshes via this callback — never embed an API key
|
|
24
|
+
// in the browser.
|
|
25
|
+
getToken: async () => {
|
|
26
|
+
const res = await fetch('/api/chat-token', { method: 'POST' });
|
|
27
|
+
const { token } = await res.json();
|
|
28
|
+
return token;
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// REST
|
|
33
|
+
const me = await chat.me.show();
|
|
34
|
+
const { data: conversations } = await chat.conversations.list();
|
|
35
|
+
|
|
36
|
+
// Send + receive in real time
|
|
37
|
+
const conv = chat.conversations.one('<conversation-id>');
|
|
38
|
+
const sent = await conv.messages.send({ body: 'Hello' });
|
|
39
|
+
|
|
40
|
+
const off = chat.realtime
|
|
41
|
+
.conversation('<conversation-id>')
|
|
42
|
+
.onMessage((msg) => console.log('new message', msg));
|
|
43
|
+
|
|
44
|
+
// Later
|
|
45
|
+
off();
|
|
46
|
+
chat.destroy();
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## What it covers
|
|
50
|
+
|
|
51
|
+
- **REST resources**: `me`, `conversations` (incl. members), `messages` (send / edit / delete / replies / reactions / mark-read), `attachments` (presigned upload + download + delete).
|
|
52
|
+
- **Realtime channels**: `message:new`, `message:updated`, `message:deleted`, `typing:start/stop`, `reaction:added/removed`, presence state + diff, per-user `mention:new` + `conversation:created`.
|
|
53
|
+
- **Token caching** — `getToken` is called once per JWT lifetime, not per request. Auto-invalidates on 401 and re-issues.
|
|
54
|
+
- **Idempotency** — every non-GET request carries an auto-generated `Idempotency-Key`, so retries (network or 5xx) never insert duplicates.
|
|
55
|
+
- **Backoff** — exponential with full jitter, honors `Retry-After` on 429, never retries `AbortError`.
|
|
56
|
+
- **Typed errors** — `AuthError` / `ApiError` / `NetworkError` / `RateLimitedError`, all `instanceof`-checkable.
|
|
57
|
+
|
|
58
|
+
## Architecture pattern
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
┌──────────────┐ API key ┌──────────────┐ JWT ┌──────────────┐
|
|
62
|
+
│ Your backend │ ─────────────▶ │ poolse REST │ ◀───────── │ Your browser │
|
|
63
|
+
│ │ ◀─── user_id │ │ │ (uses SDK) │
|
|
64
|
+
│ /api/chat- │ │ │ │ │
|
|
65
|
+
│ token │ ───────────────────────────────────────▶ │ │
|
|
66
|
+
└──────────────┘ JWT to browser via your own fetch └──────────────┘
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The poolse API key NEVER touches the browser. Your backend exchanges it for short-lived End User JWTs (`POST /v1/users/:id/tokens`); the SDK uses those JWTs for everything else.
|
|
70
|
+
|
|
71
|
+
## Documentation
|
|
72
|
+
|
|
73
|
+
- Full SDK + integration docs — <https://poolse.dev/docs>
|
|
74
|
+
- Source — <https://github.com/poolse-hq/js-sdk>
|
|
75
|
+
- Issues — <https://github.com/poolse-hq/js-sdk/issues>
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
MIT
|