@borealise/api 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/README.md ADDED
@@ -0,0 +1,205 @@
1
+ # @borealise/api
2
+
3
+ Official JavaScript/TypeScript API client for [Borealise](https://borealise.com).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @borealise/api axios
9
+ # or
10
+ yarn add @borealise/api axios
11
+ # or
12
+ pnpm add @borealise/api axios
13
+ ```
14
+
15
+ > `axios` is a peer dependency — you need to install it alongside this package.
16
+
17
+ ---
18
+
19
+ ## Quick Start
20
+
21
+ Initialize the API client once (e.g. in your app entry point), then use the resource singletons anywhere.
22
+
23
+ ```ts
24
+ import { Api, authResource, roomResource } from '@borealise/api'
25
+
26
+ // Initialize once
27
+ Api.getInstance({
28
+ baseURL: 'https://prod.borealise.com',
29
+ })
30
+
31
+ // Login
32
+ const { data } = await authResource.login({ login: 'you@example.com', password: 'secret' })
33
+ Api.getInstance().setAuthToken(data.data.accessToken)
34
+
35
+ // Join a room
36
+ const room = await roomResource.join('chill-lounge')
37
+ ```
38
+
39
+ ---
40
+
41
+ ## Configuration
42
+
43
+ ```ts
44
+ Api.getInstance({
45
+ baseURL: 'https://prod.borealise.com', // required
46
+ timeout: 15000, // optional, default: 30000ms
47
+ logging: false, // optional, disable all console output
48
+ })
49
+ ```
50
+
51
+ ---
52
+
53
+ ## Resources
54
+
55
+ ### Auth
56
+
57
+ ```ts
58
+ import { authResource } from '@borealise/api'
59
+
60
+ await authResource.login({ login: 'user@example.com', password: '...' })
61
+ await authResource.register({ email, username, password, displayName })
62
+ await authResource.refresh(refreshToken)
63
+ await authResource.me()
64
+ await authResource.logout()
65
+ ```
66
+
67
+ ### Users
68
+
69
+ ```ts
70
+ import { userResource } from '@borealise/api'
71
+
72
+ await userResource.getById(42)
73
+ await userResource.getByUsername('djname')
74
+ await userResource.updateProfile({ displayName: 'DJ Cool', bio: '...' })
75
+ await userResource.deleteAccount()
76
+ ```
77
+
78
+ ### Rooms
79
+
80
+ ```ts
81
+ import { roomResource } from '@borealise/api'
82
+
83
+ await roomResource.list()
84
+ await roomResource.featured()
85
+ await roomResource.getBySlug('chill-lounge')
86
+ await roomResource.create({ slug: 'my-room', name: 'My Room' })
87
+ await roomResource.join('chill-lounge')
88
+ await roomResource.leave('chill-lounge')
89
+
90
+ // Waitlist
91
+ await roomResource.joinWaitlist('chill-lounge')
92
+ await roomResource.leaveWaitlist('chill-lounge')
93
+ await roomResource.lockWaitlist('chill-lounge')
94
+ await roomResource.unlockWaitlist('chill-lounge')
95
+
96
+ // Booth
97
+ await roomResource.getBooth('chill-lounge')
98
+ await roomResource.vote('chill-lounge', 'woot')
99
+ await roomResource.grabTrack('chill-lounge', playlistId)
100
+ await roomResource.skipTrack('chill-lounge')
101
+ ```
102
+
103
+ ### Playlists
104
+
105
+ ```ts
106
+ import { playlistResource } from '@borealise/api'
107
+
108
+ await playlistResource.getAll()
109
+ await playlistResource.getById(1)
110
+ await playlistResource.create('My Playlist')
111
+ await playlistResource.rename(1, 'New Name')
112
+ await playlistResource.activate(1)
113
+ await playlistResource.shuffle(1)
114
+ await playlistResource.addItem(1, { source: 'youtube', sourceId: 'dQw4w9WgXcQ' })
115
+ await playlistResource.removeItem(1, itemId)
116
+ await playlistResource.moveItem(1, itemId, newPosition)
117
+ await playlistResource.importPlaylist(1, { url: 'https://youtube.com/playlist?list=...' })
118
+ await playlistResource.remove(1)
119
+ ```
120
+
121
+ ### Sources (Media Search)
122
+
123
+ ```ts
124
+ import { sourceResource } from '@borealise/api'
125
+
126
+ await sourceResource.searchYouTube('lofi hip hop', 10)
127
+ await sourceResource.getYouTubeVideo('dQw4w9WgXcQ')
128
+ await sourceResource.searchSoundCloud('ambient', 10)
129
+ await sourceResource.getSoundCloudTrack('123456')
130
+ await sourceResource.resolveSoundCloudUrl('https://soundcloud.com/artist/track')
131
+
132
+ // Search both platforms at once
133
+ const results = await sourceResource.searchAll('chillwave')
134
+ ```
135
+
136
+ ### Chat
137
+
138
+ ```ts
139
+ import { chatResource } from '@borealise/api'
140
+
141
+ await chatResource.getMessages('chill-lounge', beforeId, 50)
142
+ await chatResource.sendMessage('chill-lounge', { content: 'hello!' })
143
+ await chatResource.deleteMessage('chill-lounge', messageId)
144
+ ```
145
+
146
+ ---
147
+
148
+ ## Error Handling
149
+
150
+ All methods throw `ApiError` on failure.
151
+
152
+ ```ts
153
+ import { ApiError } from '@borealise/api'
154
+
155
+ try {
156
+ await authResource.login({ login: 'bad', password: 'bad' })
157
+ } catch (err) {
158
+ if (err instanceof ApiError) {
159
+ console.log(err.message) // Human-readable message from backend
160
+ console.log(err.status) // HTTP status code, e.g. 401
161
+ console.log(err.code) // Axios error code, e.g. 'NETWORK_ERROR'
162
+ console.log(err.response) // Raw backend error response body
163
+ }
164
+ }
165
+ ```
166
+
167
+ ---
168
+
169
+ ## Auth Token Management
170
+
171
+ ```ts
172
+ const api = Api.getInstance()
173
+
174
+ // Set token after login
175
+ api.setAuthToken(accessToken)
176
+
177
+ // Clear token on logout
178
+ api.setAuthToken(null)
179
+ ```
180
+
181
+ ---
182
+
183
+ ## TypeScript
184
+
185
+ All types are exported directly from the package:
186
+
187
+ ```ts
188
+ import type {
189
+ AuthUser,
190
+ Room,
191
+ RoomRole,
192
+ ChatMessage,
193
+ MediaItem,
194
+ Playlist,
195
+ MediaSearchResult,
196
+ BoothState,
197
+ WaitlistUser,
198
+ } from '@borealise/api'
199
+ ```
200
+
201
+ ---
202
+
203
+ ## License
204
+
205
+ © [Borealise](https://borealise.com)