@borealise/api 1.1.10 → 2.0.0-alpha.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/dist/index.mjs CHANGED
@@ -59,17 +59,16 @@ var ApiError = class extends Error {
59
59
  this.response = response;
60
60
  }
61
61
  };
62
- var _Api = class _Api {
62
+ var Api = class {
63
63
  constructor(config) {
64
- var _a;
65
64
  this.config = config;
66
- this.logger = Logger.create("Api");
65
+ this.logger = new Logger("Api");
67
66
  if (config.logging === false) {
68
67
  this.logger.disable();
69
68
  }
70
69
  this.axios = axios.create({
71
70
  baseURL: config.baseURL,
72
- timeout: (_a = config.timeout) != null ? _a : 3e4,
71
+ timeout: config.timeout ?? 3e4,
73
72
  headers: {
74
73
  "Content-Type": "application/json",
75
74
  ...config.headers
@@ -78,24 +77,10 @@ var _Api = class _Api {
78
77
  this.setupInterceptors();
79
78
  this.logger.success(`initialized (baseURL: ${config.baseURL})`);
80
79
  }
81
- static getInstance(config) {
82
- if (!_Api.instance) {
83
- if (!config) {
84
- throw new Error('Api must be initialized with config first. Call Api.getInstance({ baseURL: "..." }) once before using resources.');
85
- }
86
- _Api.instance = new _Api(config);
87
- }
88
- return _Api.instance;
89
- }
90
- /** Reset the singleton (useful for testing or re-initializing with a new config) */
91
- static reset() {
92
- _Api.instance = null;
93
- }
94
80
  setupInterceptors() {
95
81
  this.axios.interceptors.request.use(
96
82
  (config) => {
97
- var _a;
98
- this.logger.debug(`\u2192 ${(_a = config.method) == null ? void 0 : _a.toUpperCase()} ${config.url}`);
83
+ this.logger.debug(`\u2192 ${config.method?.toUpperCase()} ${config.url}`);
99
84
  return config;
100
85
  },
101
86
  (error) => {
@@ -109,10 +94,9 @@ var _Api = class _Api {
109
94
  return response;
110
95
  },
111
96
  (error) => {
112
- var _a, _b, _c;
113
97
  const apiError = this.parseError(error);
114
- const status = (_b = (_a = apiError.status) != null ? _a : apiError.code) != null ? _b : "ERR";
115
- this.logger.error(`\u2190 ${status} ${(_c = error.config) == null ? void 0 : _c.url}: ${apiError.message}`);
98
+ const status = apiError.status ?? apiError.code ?? "ERR";
99
+ this.logger.error(`\u2190 ${status} ${error.config?.url}: ${apiError.message}`);
116
100
  return Promise.reject(apiError);
117
101
  }
118
102
  );
@@ -183,531 +167,193 @@ var _Api = class _Api {
183
167
  return this.axios;
184
168
  }
185
169
  };
186
- _Api.instance = null;
187
- var Api = _Api;
170
+ var createApi = (config) => new Api(config);
188
171
 
189
- // src/ApiResource.ts
190
- var ApiResource = class {
191
- constructor() {
192
- this._logger = null;
193
- }
194
- get api() {
195
- return Api.getInstance();
196
- }
197
- get logger() {
198
- if (!this._logger) {
199
- this._logger = Logger.create(this.constructor.name);
200
- }
201
- return this._logger;
202
- }
203
- buildUrl(path) {
204
- if (path !== void 0) {
205
- return `${this.endpoint}/${path}`;
206
- }
207
- return this.endpoint;
208
- }
209
- buildConfig(options) {
210
- return {
211
- params: options == null ? void 0 : options.params,
212
- headers: options == null ? void 0 : options.headers
213
- };
214
- }
215
- async index(options) {
216
- this.logger.debug("index");
217
- return this.api.get(this.endpoint, this.buildConfig(options));
218
- }
219
- async paginate(page = 1, perPage = 15, options) {
220
- this.logger.debug(`paginate (page: ${page}, perPage: ${perPage})`);
221
- return this.api.get(this.endpoint, {
222
- ...this.buildConfig(options),
223
- params: { page, per_page: perPage, ...options == null ? void 0 : options.params }
224
- });
225
- }
226
- async show(id, options) {
227
- this.logger.debug(`show (id: ${id})`);
228
- return this.api.get(this.buildUrl(id), this.buildConfig(options));
229
- }
230
- async store(data, options) {
231
- this.logger.debug("store");
232
- return this.api.post(this.endpoint, data, this.buildConfig(options));
233
- }
234
- async update(id, data, options) {
235
- this.logger.debug(`update (id: ${id})`);
236
- return this.api.put(this.buildUrl(id), data, this.buildConfig(options));
237
- }
238
- async patch(id, data, options) {
239
- this.logger.debug(`patch (id: ${id})`);
240
- return this.api.patch(this.buildUrl(id), data, this.buildConfig(options));
241
- }
242
- async destroy(id, options) {
243
- this.logger.debug(`destroy (id: ${id})`);
244
- return this.api.delete(this.buildUrl(id), this.buildConfig(options));
245
- }
246
- async get(path, options) {
247
- return this.api.get(`${this.endpoint}/${path}`, this.buildConfig(options));
248
- }
249
- async post(path, data, options) {
250
- return this.api.post(`${this.endpoint}/${path}`, data, this.buildConfig(options));
251
- }
252
- async put(path, data, options) {
253
- return this.api.put(`${this.endpoint}/${path}`, data, this.buildConfig(options));
254
- }
255
- async delete(path, options) {
256
- return this.api.delete(`${this.endpoint}/${path}`, this.buildConfig(options));
257
- }
258
- };
259
-
260
- // src/resources/AuthResource.ts
261
- var AuthResource = class extends ApiResource {
262
- constructor() {
263
- super(...arguments);
264
- this.endpoint = "/auth";
265
- }
266
- // POST /api/auth/login
267
- async login(credentials) {
268
- return this.post("login", credentials);
269
- }
270
- // POST /api/auth/register
271
- async register(data) {
272
- return this.post("register", data);
273
- }
274
- // POST /api/auth/refresh
275
- async refresh(refreshToken) {
276
- return this.post("refresh", { refreshToken });
277
- }
278
- // POST /api/auth/logout
279
- async logout() {
280
- return this.post("logout");
281
- }
282
- // GET /api/auth/me
283
- async me() {
284
- return this.get("me");
285
- }
286
- };
287
- var authResource = new AuthResource();
172
+ // src/resources/auth.ts
173
+ var endpoint = "/auth";
174
+ var createAuthResource = (api) => ({
175
+ login: (credentials) => api.post(`${endpoint}/login`, credentials),
176
+ register: (data) => api.post(`${endpoint}/register`, data),
177
+ refresh: (refreshToken) => api.post(`${endpoint}/refresh`, { refreshToken }),
178
+ logout: () => api.post(`${endpoint}/logout`),
179
+ me: () => api.get(`${endpoint}/me`)
180
+ });
288
181
 
289
- // src/resources/UserResource.ts
290
- var UserResource = class extends ApiResource {
291
- constructor() {
292
- super(...arguments);
293
- this.endpoint = "/users";
294
- }
295
- // GET /api/users/:id
296
- async getById(id) {
297
- return this.show(id);
298
- }
299
- // GET /api/users/username/:username
300
- async getByUsername(username) {
301
- return this.get(`username/${username}`);
302
- }
303
- // PATCH /api/users/me
304
- async updateProfile(data) {
305
- return this.api.patch(`${this.endpoint}/me`, data);
306
- }
307
- // DELETE /api/users/me
308
- async deleteAccount() {
309
- return this.api.delete(`${this.endpoint}/me`);
310
- }
311
- // ============================================
312
- // Admin methods
313
- // ============================================
314
- // PATCH /api/admin/users/:id/role
315
- async updateRole(id, role) {
316
- return this.api.patch(`/api/admin/users/${id}/role`, { role });
317
- }
318
- // POST /api/admin/users/:id/disable
319
- async disable(id) {
320
- return this.api.post(`/api/admin/users/${id}/disable`);
321
- }
322
- };
323
- var userResource = new UserResource();
182
+ // src/resources/user.ts
183
+ var endpoint2 = "/users";
184
+ var createUserResource = (api) => ({
185
+ getById: (id) => api.get(`${endpoint2}/${id}`),
186
+ getByUsername: (username) => api.get(`${endpoint2}/username/${username}`),
187
+ updateProfile: (data) => api.patch(`${endpoint2}/me`, data),
188
+ deleteAccount: () => api.delete(`${endpoint2}/me`),
189
+ updateRole: (id, role) => api.patch(`/api/admin/users/${id}/role`, { role }),
190
+ disable: (id) => api.post(`/api/admin/users/${id}/disable`)
191
+ });
324
192
 
325
- // src/resources/RoomResource.ts
326
- var RoomResource = class extends ApiResource {
327
- constructor() {
328
- super(...arguments);
329
- this.endpoint = "/rooms";
330
- }
331
- // GET /api/rooms - List all rooms
332
- async list() {
333
- return this.get("");
334
- }
335
- // GET /api/rooms/featured - Get featured rooms
336
- async featured() {
337
- return this.get("featured");
338
- }
339
- // GET /api/rooms/:slug - Get room by slug
340
- async getBySlug(slug) {
341
- return this.get(slug);
342
- }
343
- // POST /api/rooms - Create a new room
344
- async create(data) {
345
- return this.post("", data);
346
- }
347
- // PATCH /api/rooms/:slug - Update room
348
- async updateRoom(slug, data) {
349
- return this.api.patch(`${this.endpoint}/${slug}`, data);
350
- }
351
- // DELETE /api/rooms/:slug - Delete room
352
- async deleteRoom(slug) {
353
- return this.api.delete(`${this.endpoint}/${slug}`);
354
- }
355
- // GET /api/rooms/:slug/staff - Get room staff
356
- async getStaff(slug) {
357
- return this.get(`${slug}/staff`);
358
- }
359
- // ============================================
360
- // Moderation methods
361
- // ============================================
362
- // GET /api/rooms/:slug/bans
363
- async getBans(slug) {
364
- return this.get(`${slug}/bans`);
365
- }
366
- // PATCH /api/rooms/:slug/users/:userId/role
367
- async updateUserRole(slug, userId, role) {
368
- return this.api.patch(
369
- `${this.endpoint}/${slug}/users/${userId}/role`,
370
- { role }
371
- );
372
- }
373
- // POST /api/rooms/:slug/users/:userId/ban
374
- async ban(slug, userId, data) {
375
- return this.api.post(`${this.endpoint}/${slug}/users/${userId}/ban`, data || {});
376
- }
377
- // DELETE /api/rooms/:slug/users/:userId/ban
378
- async unban(slug, userId) {
379
- return this.api.delete(
380
- `${this.endpoint}/${slug}/users/${userId}/ban`
381
- );
382
- }
383
- // POST /api/rooms/:slug/users/:userId/mute
384
- async mute(slug, userId, data) {
385
- return this.api.post(`${this.endpoint}/${slug}/users/${userId}/mute`, data || {});
386
- }
387
- // DELETE /api/rooms/:slug/users/:userId/mute
388
- async unmute(slug, userId) {
389
- return this.api.delete(
390
- `${this.endpoint}/${slug}/users/${userId}/mute`
391
- );
392
- }
393
- // POST /api/rooms/:slug/users/:userId/kick
394
- async kick(slug, userId) {
395
- return this.api.post(
396
- `${this.endpoint}/${slug}/users/${userId}/kick`
397
- );
398
- }
399
- // POST /api/rooms/:slug/join - Join a room (session-based)
400
- async join(slug) {
401
- return this.post(`${slug}/join`);
402
- }
403
- // POST /api/rooms/:slug/leave - Leave a room
404
- async leave(slug) {
405
- return this.post(`${slug}/leave`);
406
- }
407
- // ============================================
408
- // Waitlist methods
409
- // ============================================
410
- // GET /api/rooms/:slug/waitlist
411
- async getWaitlist(slug) {
412
- return this.get(`${slug}/waitlist`);
413
- }
414
- // POST /api/rooms/:slug/waitlist/join
415
- async joinWaitlist(slug) {
416
- return this.post(`${slug}/waitlist/join`);
417
- }
418
- // POST /api/rooms/:slug/waitlist/leave
419
- async leaveWaitlist(slug) {
420
- return this.post(`${slug}/waitlist/leave`);
421
- }
422
- // PATCH /api/rooms/:slug/waitlist - Move user in waitlist
423
- async moveInWaitlist(slug, userId, position) {
424
- return this.api.patch(`${this.endpoint}/${slug}/waitlist`, { userId, position });
425
- }
426
- // DELETE /api/rooms/:slug/waitlist/:userId - Remove user from waitlist
427
- async removeFromWaitlist(slug, userId) {
428
- return this.api.delete(`${this.endpoint}/${slug}/waitlist/${userId}`);
429
- }
430
- // POST /api/rooms/:slug/waitlist/lock
431
- async lockWaitlist(slug) {
432
- return this.post(`${slug}/waitlist/lock`);
433
- }
434
- // POST /api/rooms/:slug/waitlist/unlock
435
- async unlockWaitlist(slug) {
436
- return this.post(`${slug}/waitlist/unlock`);
437
- }
438
- // ============================================
439
- // Booth methods
440
- // ============================================
441
- // GET /api/rooms/:slug/booth
442
- async getBooth(slug) {
443
- return this.get(`${slug}/booth`);
444
- }
445
- // POST /api/rooms/:slug/booth/skip
446
- async skipTrack(slug, options) {
447
- return this.post(`${slug}/booth/skip`, options || {});
448
- }
449
- // POST /api/rooms/:slug/booth/vote
450
- async vote(slug, type) {
451
- return this.post(`${slug}/booth/vote`, { type });
452
- }
453
- // POST /api/rooms/:slug/booth/grab
454
- async grabTrack(slug, playlistId) {
455
- return this.post(`${slug}/booth/grab`, playlistId ? { playlistId } : {});
456
- }
457
- // ============================================
458
- // History methods
459
- // ============================================
460
- // GET /api/rooms/:slug/history
461
- async getHistory(slug, page = 1, limit = 20) {
462
- return this.get(`${slug}/history?page=${page}&limit=${limit}`);
463
- }
464
- };
465
- var roomResource = new RoomResource();
193
+ // src/resources/room.ts
194
+ var endpoint3 = "/rooms";
195
+ var createRoomResource = (api) => ({
196
+ list: () => api.get(endpoint3),
197
+ featured: () => api.get(`${endpoint3}/featured`),
198
+ getBySlug: (slug) => api.get(`${endpoint3}/${slug}`),
199
+ create: (data) => api.post(endpoint3, data),
200
+ updateRoom: (slug, data) => api.patch(`${endpoint3}/${slug}`, data),
201
+ deleteRoom: (slug) => api.delete(`${endpoint3}/${slug}`),
202
+ getStaff: (slug) => api.get(`${endpoint3}/${slug}/staff`),
203
+ getBans: (slug) => api.get(`${endpoint3}/${slug}/bans`),
204
+ getMutes: (slug) => api.get(`${endpoint3}/${slug}/mutes`),
205
+ updateUserRole: (slug, userId, role) => api.patch(
206
+ `${endpoint3}/${slug}/users/${userId}/role`,
207
+ { role }
208
+ ),
209
+ ban: (slug, userId, data) => api.post(`${endpoint3}/${slug}/users/${userId}/ban`, data || {}),
210
+ unban: (slug, userId) => api.delete(`${endpoint3}/${slug}/users/${userId}/ban`),
211
+ mute: (slug, userId, data) => api.post(`${endpoint3}/${slug}/users/${userId}/mute`, data || {}),
212
+ unmute: (slug, userId) => api.delete(`${endpoint3}/${slug}/users/${userId}/mute`),
213
+ kick: (slug, userId) => api.post(`${endpoint3}/${slug}/users/${userId}/kick`),
214
+ join: (slug) => api.post(`${endpoint3}/${slug}/join`),
215
+ leave: (slug) => api.post(`${endpoint3}/${slug}/leave`),
216
+ getWaitlist: (slug) => api.get(`${endpoint3}/${slug}/waitlist`),
217
+ joinWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/join`),
218
+ leaveWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/leave`),
219
+ moveInWaitlist: (slug, userId, position) => api.patch(
220
+ `${endpoint3}/${slug}/waitlist`,
221
+ { userId, position }
222
+ ),
223
+ removeFromWaitlist: (slug, userId) => api.delete(`${endpoint3}/${slug}/waitlist/${userId}`),
224
+ lockWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/lock`),
225
+ unlockWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/unlock`),
226
+ getBooth: (slug) => api.get(`${endpoint3}/${slug}/booth`),
227
+ skipTrack: (slug, options) => api.post(
228
+ `${endpoint3}/${slug}/booth/skip`,
229
+ options || {}
230
+ ),
231
+ vote: (slug, type) => api.post(`${endpoint3}/${slug}/booth/vote`, { type }),
232
+ grabTrack: (slug, playlistId) => api.post(`${endpoint3}/${slug}/booth/grab`, playlistId ? { playlistId } : {}),
233
+ getHistory: (slug, page = 1, limit = 20) => api.get(`${endpoint3}/${slug}/history`, { params: { page, limit } })
234
+ });
466
235
 
467
- // src/resources/ChatResource.ts
468
- var ChatResource = class extends ApiResource {
469
- constructor() {
470
- super(...arguments);
471
- this.endpoint = "/rooms";
472
- }
473
- // POST /api/rooms/:slug/chat - Send a chat message
474
- async sendMessage(slug, data) {
475
- return this.api.post(`${this.endpoint}/${slug}/chat`, data);
476
- }
477
- // GET /api/rooms/:slug/chat - Get chat history
478
- async getMessages(slug, before, limit = 50) {
236
+ // src/resources/chat.ts
237
+ var endpoint4 = "/rooms";
238
+ var createChatResource = (api) => ({
239
+ sendMessage: (slug, data) => api.post(`${endpoint4}/${slug}/chat`, data),
240
+ getMessages: (slug, before, limit = 50) => {
479
241
  const params = { limit };
480
242
  if (before) {
481
243
  params.before = before;
482
244
  }
483
- return this.api.get(`${this.endpoint}/${slug}/chat`, { params });
484
- }
485
- // DELETE /api/rooms/:slug/chat/:messageId - Delete a chat message (moderation)
486
- async deleteMessage(slug, messageId) {
487
- return this.api.delete(`${this.endpoint}/${slug}/chat/${messageId}`);
488
- }
489
- };
490
- var chatResource = new ChatResource();
245
+ return api.get(`${endpoint4}/${slug}/chat`, { params });
246
+ },
247
+ deleteMessage: (slug, messageId) => api.delete(`${endpoint4}/${slug}/chat/${messageId}`)
248
+ });
491
249
 
492
- // src/resources/PlaylistResource.ts
493
- var PlaylistResource = class extends ApiResource {
494
- constructor() {
495
- super(...arguments);
496
- this.endpoint = "/playlists";
497
- }
498
- // GET /api/playlists - Get all user's playlists
499
- async getAll() {
500
- return this.api.get(this.endpoint);
501
- }
502
- // GET /api/playlists/:id - Get playlist with items
503
- async getById(playlistId) {
504
- return this.api.get(`${this.endpoint}/${playlistId}`);
505
- }
506
- // POST /api/playlists - Create playlist
507
- async create(name) {
508
- return this.api.post(this.endpoint, { name });
509
- }
510
- // PATCH /api/playlists/:id - Update playlist
511
- async rename(playlistId, name) {
512
- return this.api.patch(`${this.endpoint}/${playlistId}`, { name });
513
- }
514
- // DELETE /api/playlists/:id - Delete playlist
515
- async remove(playlistId) {
516
- return this.api.delete(`${this.endpoint}/${playlistId}`);
517
- }
518
- // POST /api/playlists/:id/activate - Activate playlist
519
- async activate(playlistId) {
520
- return this.api.post(`${this.endpoint}/${playlistId}/activate`);
521
- }
522
- // POST /api/playlists/:id/shuffle - Shuffle playlist
523
- async shuffle(playlistId) {
524
- return this.api.post(`${this.endpoint}/${playlistId}/shuffle`);
525
- }
526
- // POST /api/playlists/:id/items - Add item to playlist
527
- async addItem(playlistId, data) {
528
- return this.api.post(`${this.endpoint}/${playlistId}/items`, data);
529
- }
530
- // DELETE /api/playlists/:id/items/:itemId - Remove item from playlist
531
- async removeItem(playlistId, itemId) {
532
- return this.api.delete(`${this.endpoint}/${playlistId}/items/${itemId}`);
533
- }
534
- // PATCH /api/playlists/:id/items/:itemId/move - Move item in playlist
535
- async moveItem(playlistId, itemId, position) {
536
- return this.api.patch(`${this.endpoint}/${playlistId}/items/${itemId}/move`, { position });
537
- }
538
- // POST /api/playlists/:id/import - Import from YouTube/SoundCloud playlist
539
- async importPlaylist(playlistId, data) {
540
- return this.api.post(`${this.endpoint}/${playlistId}/import`, data);
541
- }
542
- };
543
- var playlistResource = new PlaylistResource();
250
+ // src/resources/playlist.ts
251
+ var endpoint5 = "/playlists";
252
+ var createPlaylistResource = (api) => ({
253
+ getAll: () => api.get(endpoint5),
254
+ getById: (playlistId) => api.get(`${endpoint5}/${playlistId}`),
255
+ create: (name) => api.post(endpoint5, { name }),
256
+ rename: (playlistId, name) => api.patch(`${endpoint5}/${playlistId}`, { name }),
257
+ remove: (playlistId) => api.delete(`${endpoint5}/${playlistId}`),
258
+ activate: (playlistId) => api.post(`${endpoint5}/${playlistId}/activate`),
259
+ shuffle: (playlistId) => api.post(`${endpoint5}/${playlistId}/shuffle`),
260
+ addItem: (playlistId, data) => api.post(`${endpoint5}/${playlistId}/items`, data),
261
+ removeItem: (playlistId, itemId) => api.delete(`${endpoint5}/${playlistId}/items/${itemId}`),
262
+ moveItem: (playlistId, itemId, position) => api.patch(`${endpoint5}/${playlistId}/items/${itemId}/move`, { position }),
263
+ importPlaylist: (playlistId, data) => api.post(`${endpoint5}/${playlistId}/import`, data)
264
+ });
544
265
 
545
- // src/resources/SourceResource.ts
546
- var SourceResource = class extends ApiResource {
547
- constructor() {
548
- super(...arguments);
549
- this.endpoint = "/sources";
550
- }
551
- // ============================================
552
- // YouTube
553
- // ============================================
554
- // GET /api/sources/youtube/search?q=...&limit=...
555
- async searchYouTube(query, limit = 10) {
556
- return this.api.get(`${this.endpoint}/youtube/search`, {
557
- params: { q: query, limit }
558
- });
559
- }
560
- // GET /api/sources/youtube/videos/:videoId
561
- async getYouTubeVideo(videoId) {
562
- return this.api.get(`${this.endpoint}/youtube/videos/${videoId}`);
563
- }
564
- // ============================================
565
- // SoundCloud
566
- // ============================================
567
- // GET /api/sources/soundcloud/search?q=...&limit=...
568
- async searchSoundCloud(query, limit = 10) {
569
- return this.api.get(`${this.endpoint}/soundcloud/search`, {
570
- params: { q: query, limit }
571
- });
572
- }
573
- // GET /api/sources/soundcloud/tracks/:trackId
574
- async getSoundCloudTrack(trackId) {
575
- return this.api.get(`${this.endpoint}/soundcloud/tracks/${trackId}`);
576
- }
577
- // GET /api/sources/soundcloud/resolve?url=...
578
- async resolveSoundCloudUrl(url) {
579
- return this.api.get(`${this.endpoint}/soundcloud/resolve`, {
580
- params: { url }
581
- });
582
- }
583
- // ============================================
584
- // Combined search (helper)
585
- // ============================================
586
- // Search both YouTube and SoundCloud
587
- async searchAll(query, limit = 10) {
588
- var _a, _b, _c, _d;
266
+ // src/resources/source.ts
267
+ var endpoint6 = "/sources";
268
+ var createSourceResource = (api) => ({
269
+ searchYouTube: (query, limit = 10) => api.get(`${endpoint6}/youtube/search`, {
270
+ params: { q: query, limit }
271
+ }),
272
+ getYouTubeVideo: (videoId) => api.get(`${endpoint6}/youtube/videos/${videoId}`),
273
+ searchSoundCloud: (query, limit = 10) => api.get(`${endpoint6}/soundcloud/search`, {
274
+ params: { q: query, limit }
275
+ }),
276
+ getSoundCloudTrack: (trackId) => api.get(`${endpoint6}/soundcloud/tracks/${trackId}`),
277
+ resolveSoundCloudUrl: (url) => api.get(`${endpoint6}/soundcloud/resolve`, { params: { url } }),
278
+ searchAll: async (query, limit = 10) => {
589
279
  const [youtube, soundcloud] = await Promise.allSettled([
590
- this.searchYouTube(query, limit),
591
- this.searchSoundCloud(query, limit)
280
+ api.get(`${endpoint6}/youtube/search`, { params: { q: query, limit } }),
281
+ api.get(`${endpoint6}/soundcloud/search`, { params: { q: query, limit } })
592
282
  ]);
593
283
  const results = [];
594
- if (youtube.status === "fulfilled" && ((_b = (_a = youtube.value.data) == null ? void 0 : _a.data) == null ? void 0 : _b.results)) {
284
+ if (youtube.status === "fulfilled" && youtube.value.data?.data?.results) {
595
285
  results.push(...youtube.value.data.data.results);
596
286
  }
597
- if (soundcloud.status === "fulfilled" && ((_d = (_c = soundcloud.value.data) == null ? void 0 : _c.data) == null ? void 0 : _d.results)) {
287
+ if (soundcloud.status === "fulfilled" && soundcloud.value.data?.data?.results) {
598
288
  results.push(...soundcloud.value.data.data.results);
599
289
  }
600
290
  return results;
601
291
  }
602
- };
603
- var sourceResource = new SourceResource();
292
+ });
604
293
 
605
- // src/resources/ShopResource.ts
606
- var ShopResource = class extends ApiResource {
607
- constructor() {
608
- super(...arguments);
609
- this.endpoint = "/shop";
610
- }
611
- // GET /api/shop/avatars
612
- async getAvatarCatalog() {
613
- return this.api.get(`${this.endpoint}/avatars`);
614
- }
615
- // POST /api/shop/avatars/:avatarId/unlock
616
- async unlockAvatar(avatarId) {
617
- return this.api.post(`${this.endpoint}/avatars/${avatarId}/unlock`);
618
- }
619
- // PATCH /api/shop/avatars/equip
620
- async equipAvatar(avatarId) {
621
- return this.api.patch(`${this.endpoint}/avatars/equip`, { avatarId });
622
- }
623
- };
624
- var shopResource = new ShopResource();
294
+ // src/resources/shop.ts
295
+ var endpoint7 = "/shop";
296
+ var createShopResource = (api) => ({
297
+ getAvatarCatalog: () => api.get(`${endpoint7}/avatars`),
298
+ unlockAvatar: (avatarId) => api.post(
299
+ `${endpoint7}/avatars/${avatarId}/unlock`
300
+ ),
301
+ equipAvatar: (avatarId) => api.patch(
302
+ `${endpoint7}/avatars/equip`,
303
+ { avatarId }
304
+ )
305
+ });
625
306
 
626
- // src/resources/SubscriptionResource.ts
627
- var SubscriptionResource = class extends ApiResource {
628
- constructor() {
629
- super(...arguments);
630
- this.endpoint = "/subscriptions";
631
- }
632
- // GET /api/subscriptions/status
633
- async getStatus() {
634
- return this.api.get(`${this.endpoint}/status`);
635
- }
636
- // POST /api/subscriptions/create-intent
637
- // Creates an incomplete subscription and returns a PaymentIntent client_secret
638
- // for use with the Stripe Payment Element
639
- async createIntent(plan) {
640
- return this.api.post(`${this.endpoint}/create-intent`, { plan });
641
- }
642
- // POST /api/subscriptions/cancel-intent
643
- // Cancels an incomplete subscription when the user goes back from the payment step
644
- async cancelIntent(subscriptionId) {
645
- return this.api.post(`${this.endpoint}/cancel-intent`, { subscriptionId });
646
- }
647
- // POST /api/subscriptions/portal
648
- async createPortal() {
649
- return this.api.post(`${this.endpoint}/portal`);
650
- }
651
- };
652
- var subscriptionResource = new SubscriptionResource();
307
+ // src/resources/subscription.ts
308
+ var endpoint8 = "/subscriptions";
309
+ var createSubscriptionResource = (api) => ({
310
+ getStatus: () => api.get(`${endpoint8}/status`),
311
+ createIntent: (plan) => api.post(`${endpoint8}/create-intent`, { plan }),
312
+ cancelIntent: (subscriptionId) => api.post(`${endpoint8}/cancel-intent`, { subscriptionId }),
313
+ createPortal: () => api.post(`${endpoint8}/portal`)
314
+ });
653
315
 
654
- // src/resources/FriendResource.ts
655
- var FriendResource = class extends ApiResource {
656
- constructor() {
657
- super(...arguments);
658
- this.endpoint = "/friends";
659
- }
660
- // GET /api/friends
661
- async list() {
662
- return this.api.get(this.endpoint);
663
- }
664
- // GET /api/friends/status/:targetUserId
665
- async getStatus(targetUserId) {
666
- return this.api.get(`${this.endpoint}/status/${targetUserId}`);
667
- }
668
- // POST /api/friends/:targetUserId send or auto-accept request
669
- async sendRequest(targetUserId) {
670
- return this.api.post(`${this.endpoint}/${targetUserId}`);
671
- }
672
- // PATCH /api/friends/:friendshipId/accept
673
- async acceptRequest(friendshipId) {
674
- return this.api.patch(`${this.endpoint}/${friendshipId}/accept`);
675
- }
676
- // DELETE /api/friends/:friendshipId — decline / cancel / unfriend
677
- async remove(friendshipId) {
678
- return this.api.delete(`${this.endpoint}/${friendshipId}`);
679
- }
680
- // POST /api/friends/:targetUserId/block
681
- async block(targetUserId) {
682
- return this.api.post(`${this.endpoint}/${targetUserId}/block`);
683
- }
684
- // DELETE /api/friends/:targetUserId/block
685
- async unblock(targetUserId) {
686
- return this.api.delete(`${this.endpoint}/${targetUserId}/block`);
687
- }
316
+ // src/resources/friend.ts
317
+ var endpoint9 = "/friends";
318
+ var createFriendResource = (api) => ({
319
+ list: () => api.get(endpoint9),
320
+ getStatus: (targetUserId) => api.get(`${endpoint9}/status/${targetUserId}`),
321
+ sendRequest: (targetUserId) => api.post(`${endpoint9}/${targetUserId}`),
322
+ acceptRequest: (friendshipId) => api.patch(`${endpoint9}/${friendshipId}/accept`),
323
+ remove: (friendshipId) => api.delete(`${endpoint9}/${friendshipId}`),
324
+ block: (targetUserId) => api.post(`${endpoint9}/${targetUserId}/block`),
325
+ unblock: (targetUserId) => api.delete(`${endpoint9}/${targetUserId}/block`)
326
+ });
327
+
328
+ // src/resources/index.ts
329
+ var createApiClient = (config) => {
330
+ const api = createApi(config);
331
+ return {
332
+ api,
333
+ auth: createAuthResource(api),
334
+ user: createUserResource(api),
335
+ room: createRoomResource(api),
336
+ chat: createChatResource(api),
337
+ playlist: createPlaylistResource(api),
338
+ source: createSourceResource(api),
339
+ shop: createShopResource(api),
340
+ subscription: createSubscriptionResource(api),
341
+ friend: createFriendResource(api)
342
+ };
688
343
  };
689
- var friendResource = new FriendResource();
690
344
  export {
691
345
  Api,
692
346
  ApiError,
693
- ApiResource,
694
- AuthResource,
695
- ChatResource,
696
- FriendResource,
697
347
  Logger,
698
- PlaylistResource,
699
- RoomResource,
700
- ShopResource,
701
- SourceResource,
702
- SubscriptionResource,
703
- UserResource,
704
- authResource,
705
- chatResource,
706
- friendResource,
707
- playlistResource,
708
- roomResource,
709
- shopResource,
710
- sourceResource,
711
- subscriptionResource,
712
- userResource
348
+ createApi,
349
+ createApiClient,
350
+ createAuthResource,
351
+ createChatResource,
352
+ createFriendResource,
353
+ createPlaylistResource,
354
+ createRoomResource,
355
+ createShopResource,
356
+ createSourceResource,
357
+ createSubscriptionResource,
358
+ createUserResource
713
359
  };