@poolse/sdk 2.0.0 → 2.0.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/CHANGELOG.md +1 -0
- package/README.md +12 -12
- package/dist/index.cjs +25 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +25 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -36,6 +36,7 @@ you stored one.
|
|
|
36
36
|
### Backend coupling
|
|
37
37
|
|
|
38
38
|
Pairs with the `poolse-server` change that:
|
|
39
|
+
|
|
39
40
|
- lazy-provisions unknown `external_id`s referenced in
|
|
40
41
|
`POST /v1/conversations` (`member_external_ids`) and
|
|
41
42
|
`POST /v1/conversations/:id/members` (`external_ids`), abuse-capped
|
package/README.md
CHANGED
|
@@ -63,18 +63,18 @@ chat.destroy(); // closes WebSocket, leaves every joined channel
|
|
|
63
63
|
|
|
64
64
|
`new Poolse(config)` — every field but `getToken` has a default.
|
|
65
65
|
|
|
66
|
-
| Field | Type
|
|
67
|
-
| ------------------------ |
|
|
68
|
-
| `getToken` | `() => Promise<string \| null> \| string \| null`
|
|
69
|
-
| `apiUrl` | `string`
|
|
70
|
-
| `wsUrl` | `string`
|
|
71
|
-
| `socketPath` | `string`
|
|
72
|
-
| `fetch` | `typeof fetch`
|
|
73
|
-
| `maxRetries` | `number`
|
|
74
|
-
| `baseBackoffMs` | `number`
|
|
75
|
-
| `maxBackoffMs` | `number`
|
|
76
|
-
| `generateIdempotencyKey` | `() => string`
|
|
77
|
-
| `onSocketError` | `(err: Error) => void`
|
|
66
|
+
| Field | Type | Default | Notes |
|
|
67
|
+
| ------------------------ | ----------------------------------------------------------------------------------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
68
|
+
| `getToken` | `() => Promise<string \| null> \| string \| null` | — _required_ | Called when the SDK needs a JWT. Return `null` to make an unauthenticated request (rare — the server requires a JWT for most routes). |
|
|
69
|
+
| `apiUrl` | `string` | `https://api.poolse.dev` | Base URL **without** `/v1`. Strip the trailing slash if present (the SDK does this too). |
|
|
70
|
+
| `wsUrl` | `string` | `apiUrl` with `http(s)` → `ws(s)` | Override for split-host deployments where the WebSocket gateway is on a different origin. |
|
|
71
|
+
| `socketPath` | `string` | `/socket` | Phoenix Channels mount point. |
|
|
72
|
+
| `fetch` | `typeof fetch` | `globalThis.fetch` | Inject a fetch implementation (tests, restricted environments). Must be bound to `globalThis` if you pass the global one explicitly. |
|
|
73
|
+
| `maxRetries` | `number` | `3` | Retry budget for transient failures, per request. |
|
|
74
|
+
| `baseBackoffMs` | `number` | `250` | Base of the exponential backoff. |
|
|
75
|
+
| `maxBackoffMs` | `number` | `30000` | Hard ceiling on a single retry delay. |
|
|
76
|
+
| `generateIdempotencyKey` | `() => string` | `crypto.randomUUID()` | Override the key generator. Defaults throws at construction time if no `crypto.randomUUID` is available. |
|
|
77
|
+
| `onSocketError` | `(err: Error) => void` | — | Fired on non-fatal socket errors (Phoenix handles reconnect internally; this is for surface-level banners). |
|
|
78
78
|
| `userResolver` | `(externalId: string) => Promise<PoolseUserProfile \| null> \| PoolseUserProfile \| null` | — | Optional. Resolve the tenant's own user identifier (`external_id` — same string you pass when minting JWTs) to `{ displayName, avatarUrl }` from your app's user data. The UI packages pick this up automatically. |
|
|
79
79
|
|
|
80
80
|
## REST surface
|
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
var phoenix = require('phoenix');
|
|
4
4
|
|
|
5
|
+
// src/uuid.ts
|
|
6
|
+
function safeUuid() {
|
|
7
|
+
const c = globalThis.crypto;
|
|
8
|
+
if (c?.randomUUID) return c.randomUUID();
|
|
9
|
+
const bytes = new Uint8Array(16);
|
|
10
|
+
if (c?.getRandomValues) {
|
|
11
|
+
c.getRandomValues(bytes);
|
|
12
|
+
} else {
|
|
13
|
+
for (let i = 0; i < 16; i++) {
|
|
14
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
18
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
19
|
+
const hex = [];
|
|
20
|
+
for (let i = 0; i < 16; i++) {
|
|
21
|
+
hex.push(bytes[i].toString(16).padStart(2, "0"));
|
|
22
|
+
}
|
|
23
|
+
return hex.slice(0, 4).join("") + "-" + hex.slice(4, 6).join("") + "-" + hex.slice(6, 8).join("") + "-" + hex.slice(8, 10).join("") + "-" + hex.slice(10).join("");
|
|
24
|
+
}
|
|
25
|
+
|
|
5
26
|
// src/config.ts
|
|
6
27
|
var POOLSE_API_URL = "https://api.poolse.dev";
|
|
7
28
|
var DEFAULT_MAX_RETRIES = 3;
|
|
@@ -36,13 +57,7 @@ function trimTrailingSlash(s) {
|
|
|
36
57
|
return s.endsWith("/") ? s.slice(0, -1) : s;
|
|
37
58
|
}
|
|
38
59
|
function defaultIdempotencyKey() {
|
|
39
|
-
|
|
40
|
-
if (c && typeof c.randomUUID === "function") {
|
|
41
|
-
return c.randomUUID();
|
|
42
|
-
}
|
|
43
|
-
throw new Error(
|
|
44
|
-
"Poolse: globalThis.crypto.randomUUID() is not available; supply `config.generateIdempotencyKey` instead."
|
|
45
|
-
);
|
|
60
|
+
return safeUuid();
|
|
46
61
|
}
|
|
47
62
|
|
|
48
63
|
// src/errors.ts
|
|
@@ -665,13 +680,7 @@ var MessagesResource = class {
|
|
|
665
680
|
}
|
|
666
681
|
};
|
|
667
682
|
function generateClientMessageId() {
|
|
668
|
-
|
|
669
|
-
if (c && typeof c.randomUUID === "function") {
|
|
670
|
-
return c.randomUUID();
|
|
671
|
-
}
|
|
672
|
-
throw new Error(
|
|
673
|
-
"Poolse: globalThis.crypto.randomUUID() unavailable \u2014 pass `id` explicitly in MessageCreateRequest (your env lacks a built-in UUID generator)."
|
|
674
|
-
);
|
|
683
|
+
return safeUuid();
|
|
675
684
|
}
|
|
676
685
|
|
|
677
686
|
// src/resources/conversations.ts
|
|
@@ -1172,7 +1181,7 @@ var Poolse = class {
|
|
|
1172
1181
|
};
|
|
1173
1182
|
|
|
1174
1183
|
// src/version.ts
|
|
1175
|
-
var version = "2.0.
|
|
1184
|
+
var version = "2.0.1";
|
|
1176
1185
|
|
|
1177
1186
|
exports.ApiError = ApiError;
|
|
1178
1187
|
exports.AttachmentHandle = AttachmentHandle;
|
|
@@ -1193,6 +1202,7 @@ exports.PoolseRealtime = PoolseRealtime;
|
|
|
1193
1202
|
exports.RateLimitedError = RateLimitedError;
|
|
1194
1203
|
exports.UserChannel = UserChannel;
|
|
1195
1204
|
exports.UsersResource = UsersResource;
|
|
1205
|
+
exports.safeUuid = safeUuid;
|
|
1196
1206
|
exports.version = version;
|
|
1197
1207
|
//# sourceMappingURL=index.cjs.map
|
|
1198
1208
|
//# sourceMappingURL=index.cjs.map
|