crossbar-client 1.0.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/LICENSE +15 -0
- package/README.md +136 -0
- package/dist/index.cjs +841 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +959 -0
- package/dist/index.d.ts +959 -0
- package/dist/index.js +796 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# crossbar
|
|
2
|
+
|
|
3
|
+
TypeScript HTTP client for the [Kazoo](https://www.2600hz.org/) (2600hz) Crossbar REST API.
|
|
4
|
+
|
|
5
|
+
- Zero runtime dependencies (native `fetch`)
|
|
6
|
+
- Full TypeScript types with generics
|
|
7
|
+
- Automatic auth token management
|
|
8
|
+
- Transparent request/response envelope handling
|
|
9
|
+
- Dual ESM/CJS support
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install crossbar
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { CrossbarClient } from "crossbar";
|
|
21
|
+
|
|
22
|
+
const client = new CrossbarClient({
|
|
23
|
+
url: "http://kazoo.example.com:8000",
|
|
24
|
+
auth: {
|
|
25
|
+
type: "credentials",
|
|
26
|
+
credentials: "md5_hash_of_username:password",
|
|
27
|
+
accountName: "my_account",
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Authenticate (stores token automatically)
|
|
32
|
+
await client.authenticate();
|
|
33
|
+
|
|
34
|
+
// List devices with typed response
|
|
35
|
+
interface Device {
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
sip: { ip: string };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const response = await client.get<Device[]>("/accounts/{ACCOUNT_ID}/devices");
|
|
42
|
+
console.log(response.data); // Device[]
|
|
43
|
+
|
|
44
|
+
// Create a user (PUT = create in Crossbar)
|
|
45
|
+
const user = await client.put("/accounts/{ACCOUNT_ID}/users", {
|
|
46
|
+
first_name: "John",
|
|
47
|
+
last_name: "Doe",
|
|
48
|
+
email: "john@example.com",
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Authentication
|
|
53
|
+
|
|
54
|
+
### User Credentials
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
const client = new CrossbarClient({
|
|
58
|
+
url: "http://kazoo.example.com:8000",
|
|
59
|
+
auth: {
|
|
60
|
+
type: "credentials",
|
|
61
|
+
credentials: "md5_hash",
|
|
62
|
+
accountName: "my_account", // or accountId
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
await client.authenticate();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### API Key
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
const client = new CrossbarClient({
|
|
72
|
+
url: "http://kazoo.example.com:8000",
|
|
73
|
+
auth: {
|
|
74
|
+
type: "api_key",
|
|
75
|
+
apiKey: "your_api_key",
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
await client.authenticate();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Pre-existing Token
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const client = new CrossbarClient({
|
|
85
|
+
url: "http://kazoo.example.com:8000",
|
|
86
|
+
auth: {
|
|
87
|
+
type: "token",
|
|
88
|
+
token: "existing_auth_token",
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Configuration
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
const client = new CrossbarClient({
|
|
97
|
+
url: "http://kazoo.example.com:8000", // required
|
|
98
|
+
version: "v2", // default: "v2"
|
|
99
|
+
timeout: 30000, // default request timeout (ms)
|
|
100
|
+
headers: { // custom headers sent with every request
|
|
101
|
+
"X-Custom-Header": "value",
|
|
102
|
+
},
|
|
103
|
+
auth: { /* ... */ },
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Per-Request Options
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
const response = await client.get("/accounts/{id}/users", {
|
|
111
|
+
headers: { "X-Request-Header": "value" },
|
|
112
|
+
query: { page_size: "10" },
|
|
113
|
+
timeout: 5000,
|
|
114
|
+
signal: AbortSignal.timeout(10000),
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## HTTP Methods
|
|
119
|
+
|
|
120
|
+
Crossbar uses non-standard HTTP method semantics:
|
|
121
|
+
|
|
122
|
+
| Method | Crossbar Meaning | Client Method |
|
|
123
|
+
|----------|-----------------|---------------|
|
|
124
|
+
| `GET` | Read | `client.get(path, options?)` |
|
|
125
|
+
| `PUT` | **Create** | `client.put(path, data?, options?)` |
|
|
126
|
+
| `POST` | **Update** | `client.post(path, data?, options?)` |
|
|
127
|
+
| `PATCH` | Partial update | `client.patch(path, data?, options?)` |
|
|
128
|
+
| `DELETE` | Delete | `client.delete(path, options?)` |
|
|
129
|
+
|
|
130
|
+
## Requirements
|
|
131
|
+
|
|
132
|
+
- Node.js >= 22.0.0
|
|
133
|
+
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
ISC
|