@borealise/api 1.1.11 → 2.0.0-alpha.10

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.js CHANGED
@@ -32,26 +32,19 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  Api: () => Api,
34
34
  ApiError: () => ApiError,
35
- ApiResource: () => ApiResource,
36
- AuthResource: () => AuthResource,
37
- ChatResource: () => ChatResource,
38
- FriendResource: () => FriendResource,
39
35
  Logger: () => Logger,
40
- PlaylistResource: () => PlaylistResource,
41
- RoomResource: () => RoomResource,
42
- ShopResource: () => ShopResource,
43
- SourceResource: () => SourceResource,
44
- SubscriptionResource: () => SubscriptionResource,
45
- UserResource: () => UserResource,
46
- authResource: () => authResource,
47
- chatResource: () => chatResource,
48
- friendResource: () => friendResource,
49
- playlistResource: () => playlistResource,
50
- roomResource: () => roomResource,
51
- shopResource: () => shopResource,
52
- sourceResource: () => sourceResource,
53
- subscriptionResource: () => subscriptionResource,
54
- userResource: () => userResource
36
+ createAdminResource: () => createAdminResource,
37
+ createApi: () => createApi,
38
+ createApiClient: () => createApiClient,
39
+ createAuthResource: () => createAuthResource,
40
+ createChatResource: () => createChatResource,
41
+ createFriendResource: () => createFriendResource,
42
+ createPlaylistResource: () => createPlaylistResource,
43
+ createRoomResource: () => createRoomResource,
44
+ createShopResource: () => createShopResource,
45
+ createSourceResource: () => createSourceResource,
46
+ createSubscriptionResource: () => createSubscriptionResource,
47
+ createUserResource: () => createUserResource
55
48
  });
56
49
  module.exports = __toCommonJS(index_exports);
57
50
 
@@ -116,17 +109,16 @@ var ApiError = class extends Error {
116
109
  this.response = response;
117
110
  }
118
111
  };
119
- var _Api = class _Api {
112
+ var Api = class {
120
113
  constructor(config) {
121
- var _a;
122
114
  this.config = config;
123
- this.logger = Logger.create("Api");
115
+ this.logger = new Logger("Api");
124
116
  if (config.logging === false) {
125
117
  this.logger.disable();
126
118
  }
127
119
  this.axios = import_axios.default.create({
128
120
  baseURL: config.baseURL,
129
- timeout: (_a = config.timeout) != null ? _a : 3e4,
121
+ timeout: config.timeout ?? 3e4,
130
122
  headers: {
131
123
  "Content-Type": "application/json",
132
124
  ...config.headers
@@ -135,24 +127,10 @@ var _Api = class _Api {
135
127
  this.setupInterceptors();
136
128
  this.logger.success(`initialized (baseURL: ${config.baseURL})`);
137
129
  }
138
- static getInstance(config) {
139
- if (!_Api.instance) {
140
- if (!config) {
141
- throw new Error('Api must be initialized with config first. Call Api.getInstance({ baseURL: "..." }) once before using resources.');
142
- }
143
- _Api.instance = new _Api(config);
144
- }
145
- return _Api.instance;
146
- }
147
- /** Reset the singleton (useful for testing or re-initializing with a new config) */
148
- static reset() {
149
- _Api.instance = null;
150
- }
151
130
  setupInterceptors() {
152
131
  this.axios.interceptors.request.use(
153
132
  (config) => {
154
- var _a;
155
- this.logger.debug(`\u2192 ${(_a = config.method) == null ? void 0 : _a.toUpperCase()} ${config.url}`);
133
+ this.logger.debug(`\u2192 ${config.method?.toUpperCase()} ${config.url}`);
156
134
  return config;
157
135
  },
158
136
  (error) => {
@@ -166,10 +144,9 @@ var _Api = class _Api {
166
144
  return response;
167
145
  },
168
146
  (error) => {
169
- var _a, _b, _c;
170
147
  const apiError = this.parseError(error);
171
- const status = (_b = (_a = apiError.status) != null ? _a : apiError.code) != null ? _b : "ERR";
172
- this.logger.error(`\u2190 ${status} ${(_c = error.config) == null ? void 0 : _c.url}: ${apiError.message}`);
148
+ const status = apiError.status ?? apiError.code ?? "ERR";
149
+ this.logger.error(`\u2190 ${status} ${error.config?.url}: ${apiError.message}`);
173
150
  return Promise.reject(apiError);
174
151
  }
175
152
  );
@@ -240,536 +217,228 @@ var _Api = class _Api {
240
217
  return this.axios;
241
218
  }
242
219
  };
243
- _Api.instance = null;
244
- var Api = _Api;
245
-
246
- // src/ApiResource.ts
247
- var ApiResource = class {
248
- constructor() {
249
- this._logger = null;
250
- }
251
- get api() {
252
- return Api.getInstance();
253
- }
254
- get logger() {
255
- if (!this._logger) {
256
- this._logger = Logger.create(this.constructor.name);
257
- }
258
- return this._logger;
259
- }
260
- buildUrl(path) {
261
- if (path !== void 0) {
262
- return `${this.endpoint}/${path}`;
263
- }
264
- return this.endpoint;
265
- }
266
- buildConfig(options) {
267
- return {
268
- params: options == null ? void 0 : options.params,
269
- headers: options == null ? void 0 : options.headers
270
- };
271
- }
272
- async index(options) {
273
- this.logger.debug("index");
274
- return this.api.get(this.endpoint, this.buildConfig(options));
275
- }
276
- async paginate(page = 1, perPage = 15, options) {
277
- this.logger.debug(`paginate (page: ${page}, perPage: ${perPage})`);
278
- return this.api.get(this.endpoint, {
279
- ...this.buildConfig(options),
280
- params: { page, per_page: perPage, ...options == null ? void 0 : options.params }
281
- });
282
- }
283
- async show(id, options) {
284
- this.logger.debug(`show (id: ${id})`);
285
- return this.api.get(this.buildUrl(id), this.buildConfig(options));
286
- }
287
- async store(data, options) {
288
- this.logger.debug("store");
289
- return this.api.post(this.endpoint, data, this.buildConfig(options));
290
- }
291
- async update(id, data, options) {
292
- this.logger.debug(`update (id: ${id})`);
293
- return this.api.put(this.buildUrl(id), data, this.buildConfig(options));
294
- }
295
- async patch(id, data, options) {
296
- this.logger.debug(`patch (id: ${id})`);
297
- return this.api.patch(this.buildUrl(id), data, this.buildConfig(options));
298
- }
299
- async destroy(id, options) {
300
- this.logger.debug(`destroy (id: ${id})`);
301
- return this.api.delete(this.buildUrl(id), this.buildConfig(options));
302
- }
303
- async get(path, options) {
304
- return this.api.get(`${this.endpoint}/${path}`, this.buildConfig(options));
305
- }
306
- async post(path, data, options) {
307
- return this.api.post(`${this.endpoint}/${path}`, data, this.buildConfig(options));
308
- }
309
- async put(path, data, options) {
310
- return this.api.put(`${this.endpoint}/${path}`, data, this.buildConfig(options));
311
- }
312
- async delete(path, options) {
313
- return this.api.delete(`${this.endpoint}/${path}`, this.buildConfig(options));
314
- }
315
- };
220
+ var createApi = (config) => new Api(config);
316
221
 
317
- // src/resources/AuthResource.ts
318
- var AuthResource = class extends ApiResource {
319
- constructor() {
320
- super(...arguments);
321
- this.endpoint = "/auth";
322
- }
323
- // POST /api/auth/login
324
- async login(credentials) {
325
- return this.post("login", credentials);
326
- }
327
- // POST /api/auth/register
328
- async register(data) {
329
- return this.post("register", data);
330
- }
331
- // POST /api/auth/refresh
332
- async refresh(refreshToken) {
333
- return this.post("refresh", { refreshToken });
334
- }
335
- // POST /api/auth/logout
336
- async logout() {
337
- return this.post("logout");
338
- }
339
- // GET /api/auth/me
340
- async me() {
341
- return this.get("me");
342
- }
343
- };
344
- var authResource = new AuthResource();
222
+ // src/resources/auth.ts
223
+ var endpoint = "/auth";
224
+ var createAuthResource = (api) => ({
225
+ login: (credentials) => api.post(`${endpoint}/login`, credentials),
226
+ register: (data) => api.post(`${endpoint}/register`, data),
227
+ refresh: (refreshToken) => api.post(`${endpoint}/refresh`, { refreshToken }),
228
+ logout: () => api.post(`${endpoint}/logout`),
229
+ me: () => api.get(`${endpoint}/me`),
230
+ forgotPassword: (email) => api.post(`${endpoint}/forgot-password`, { email }),
231
+ resetPassword: (token, password) => api.post(`${endpoint}/reset-password`, { token, password })
232
+ });
345
233
 
346
- // src/resources/UserResource.ts
347
- var UserResource = class extends ApiResource {
348
- constructor() {
349
- super(...arguments);
350
- this.endpoint = "/users";
351
- }
352
- // GET /api/users/:id
353
- async getById(id) {
354
- return this.show(id);
355
- }
356
- // GET /api/users/username/:username
357
- async getByUsername(username) {
358
- return this.get(`username/${username}`);
359
- }
360
- // PATCH /api/users/me
361
- async updateProfile(data) {
362
- return this.api.patch(`${this.endpoint}/me`, data);
363
- }
364
- // DELETE /api/users/me
365
- async deleteAccount() {
366
- return this.api.delete(`${this.endpoint}/me`);
367
- }
368
- // ============================================
369
- // Admin methods
370
- // ============================================
371
- // PATCH /api/admin/users/:id/role
372
- async updateRole(id, role) {
373
- return this.api.patch(`/api/admin/users/${id}/role`, { role });
374
- }
375
- // POST /api/admin/users/:id/disable
376
- async disable(id) {
377
- return this.api.post(`/api/admin/users/${id}/disable`);
378
- }
379
- };
380
- var userResource = new UserResource();
234
+ // src/resources/user.ts
235
+ var endpoint2 = "/users";
236
+ var createUserResource = (api) => ({
237
+ getById: (id) => api.get(`${endpoint2}/${id}`),
238
+ getByUsername: (username) => api.get(`${endpoint2}/username/${username}`),
239
+ updateProfile: (data) => api.patch(`${endpoint2}/me`, data),
240
+ deleteAccount: () => api.delete(`${endpoint2}/me`),
241
+ updateRole: (id, role) => api.patch(`/api/admin/users/${id}/role`, { role }),
242
+ disable: (id) => api.post(`/api/admin/users/${id}/disable`),
243
+ getMyViolations: () => api.get(`${endpoint2}/me/violations`)
244
+ });
381
245
 
382
- // src/resources/RoomResource.ts
383
- var RoomResource = class extends ApiResource {
384
- constructor() {
385
- super(...arguments);
386
- this.endpoint = "/rooms";
387
- }
388
- // GET /api/rooms - List all rooms
389
- async list() {
390
- return this.get("");
391
- }
392
- // GET /api/rooms/featured - Get featured rooms
393
- async featured() {
394
- return this.get("featured");
395
- }
396
- // GET /api/rooms/:slug - Get room by slug
397
- async getBySlug(slug) {
398
- return this.get(slug);
399
- }
400
- // POST /api/rooms - Create a new room
401
- async create(data) {
402
- return this.post("", data);
403
- }
404
- // PATCH /api/rooms/:slug - Update room
405
- async updateRoom(slug, data) {
406
- return this.api.patch(`${this.endpoint}/${slug}`, data);
407
- }
408
- // DELETE /api/rooms/:slug - Delete room
409
- async deleteRoom(slug) {
410
- return this.api.delete(`${this.endpoint}/${slug}`);
411
- }
412
- // GET /api/rooms/:slug/staff - Get room staff
413
- async getStaff(slug) {
414
- return this.get(`${slug}/staff`);
415
- }
416
- // ============================================
417
- // Moderation methods
418
- // ============================================
419
- // GET /api/rooms/:slug/bans
420
- async getBans(slug) {
421
- return this.get(`${slug}/bans`);
422
- }
423
- // GET /api/rooms/:slug/mutes
424
- async getMutes(slug) {
425
- return this.get(`${slug}/mutes`);
426
- }
427
- // PATCH /api/rooms/:slug/users/:userId/role
428
- async updateUserRole(slug, userId, role) {
429
- return this.api.patch(
430
- `${this.endpoint}/${slug}/users/${userId}/role`,
431
- { role }
432
- );
433
- }
434
- // POST /api/rooms/:slug/users/:userId/ban
435
- async ban(slug, userId, data) {
436
- return this.api.post(`${this.endpoint}/${slug}/users/${userId}/ban`, data || {});
437
- }
438
- // DELETE /api/rooms/:slug/users/:userId/ban
439
- async unban(slug, userId) {
440
- return this.api.delete(
441
- `${this.endpoint}/${slug}/users/${userId}/ban`
442
- );
443
- }
444
- // POST /api/rooms/:slug/users/:userId/mute
445
- async mute(slug, userId, data) {
446
- return this.api.post(`${this.endpoint}/${slug}/users/${userId}/mute`, data || {});
447
- }
448
- // DELETE /api/rooms/:slug/users/:userId/mute
449
- async unmute(slug, userId) {
450
- return this.api.delete(
451
- `${this.endpoint}/${slug}/users/${userId}/mute`
452
- );
453
- }
454
- // POST /api/rooms/:slug/users/:userId/kick
455
- async kick(slug, userId) {
456
- return this.api.post(
457
- `${this.endpoint}/${slug}/users/${userId}/kick`
458
- );
459
- }
460
- // POST /api/rooms/:slug/join - Join a room (session-based)
461
- async join(slug) {
462
- return this.post(`${slug}/join`);
463
- }
464
- // POST /api/rooms/:slug/leave - Leave a room
465
- async leave(slug) {
466
- return this.post(`${slug}/leave`);
467
- }
468
- // ============================================
469
- // Waitlist methods
470
- // ============================================
471
- // GET /api/rooms/:slug/waitlist
472
- async getWaitlist(slug) {
473
- return this.get(`${slug}/waitlist`);
474
- }
475
- // POST /api/rooms/:slug/waitlist/join
476
- async joinWaitlist(slug) {
477
- return this.post(`${slug}/waitlist/join`);
478
- }
479
- // POST /api/rooms/:slug/waitlist/leave
480
- async leaveWaitlist(slug) {
481
- return this.post(`${slug}/waitlist/leave`);
482
- }
483
- // PATCH /api/rooms/:slug/waitlist - Move user in waitlist
484
- async moveInWaitlist(slug, userId, position) {
485
- return this.api.patch(`${this.endpoint}/${slug}/waitlist`, { userId, position });
486
- }
487
- // DELETE /api/rooms/:slug/waitlist/:userId - Remove user from waitlist
488
- async removeFromWaitlist(slug, userId) {
489
- return this.api.delete(`${this.endpoint}/${slug}/waitlist/${userId}`);
490
- }
491
- // POST /api/rooms/:slug/waitlist/lock
492
- async lockWaitlist(slug) {
493
- return this.post(`${slug}/waitlist/lock`);
494
- }
495
- // POST /api/rooms/:slug/waitlist/unlock
496
- async unlockWaitlist(slug) {
497
- return this.post(`${slug}/waitlist/unlock`);
498
- }
499
- // ============================================
500
- // Booth methods
501
- // ============================================
502
- // GET /api/rooms/:slug/booth
503
- async getBooth(slug) {
504
- return this.get(`${slug}/booth`);
505
- }
506
- // POST /api/rooms/:slug/booth/skip
507
- async skipTrack(slug, options) {
508
- return this.post(`${slug}/booth/skip`, options || {});
509
- }
510
- // POST /api/rooms/:slug/booth/vote
511
- async vote(slug, type) {
512
- return this.post(`${slug}/booth/vote`, { type });
513
- }
514
- // POST /api/rooms/:slug/booth/grab
515
- async grabTrack(slug, playlistId) {
516
- return this.post(`${slug}/booth/grab`, playlistId ? { playlistId } : {});
517
- }
518
- // ============================================
519
- // History methods
520
- // ============================================
521
- // GET /api/rooms/:slug/history
522
- async getHistory(slug, page = 1, limit = 20) {
523
- return this.get(`${slug}/history?page=${page}&limit=${limit}`);
524
- }
525
- };
526
- var roomResource = new RoomResource();
246
+ // src/resources/room.ts
247
+ var endpoint3 = "/rooms";
248
+ var createRoomResource = (api) => ({
249
+ list: () => api.get(endpoint3),
250
+ mine: (limit = 20) => api.get(`${endpoint3}/mine`, { params: { limit } }),
251
+ featured: () => api.get(`${endpoint3}/featured`),
252
+ getBySlug: (slug) => api.get(`${endpoint3}/${slug}`),
253
+ create: (data) => api.post(endpoint3, data),
254
+ updateRoom: (slug, data) => api.patch(`${endpoint3}/${slug}`, data),
255
+ deleteRoom: (slug) => api.delete(`${endpoint3}/${slug}`),
256
+ getStaff: (slug) => api.get(`${endpoint3}/${slug}/staff`),
257
+ getBans: (slug) => api.get(`${endpoint3}/${slug}/bans`),
258
+ getMutes: (slug) => api.get(`${endpoint3}/${slug}/mutes`),
259
+ updateUserRole: (slug, userId, role) => api.patch(
260
+ `${endpoint3}/${slug}/users/${userId}/role`,
261
+ { role }
262
+ ),
263
+ ban: (slug, userId, data) => api.post(`${endpoint3}/${slug}/users/${userId}/ban`, data || {}),
264
+ unban: (slug, userId) => api.delete(`${endpoint3}/${slug}/users/${userId}/ban`),
265
+ mute: (slug, userId, data) => api.post(`${endpoint3}/${slug}/users/${userId}/mute`, data || {}),
266
+ unmute: (slug, userId) => api.delete(`${endpoint3}/${slug}/users/${userId}/mute`),
267
+ kick: (slug, userId) => api.post(`${endpoint3}/${slug}/users/${userId}/kick`),
268
+ join: (slug) => api.post(`${endpoint3}/${slug}/join`),
269
+ leave: (slug) => api.post(`${endpoint3}/${slug}/leave`),
270
+ getWaitlist: (slug) => api.get(`${endpoint3}/${slug}/waitlist`),
271
+ joinWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/join`),
272
+ leaveWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/leave`),
273
+ moveInWaitlist: (slug, userId, position) => api.patch(
274
+ `${endpoint3}/${slug}/waitlist`,
275
+ { userId, position }
276
+ ),
277
+ removeFromWaitlist: (slug, userId) => api.delete(`${endpoint3}/${slug}/waitlist/${userId}`),
278
+ lockWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/lock`),
279
+ unlockWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/unlock`),
280
+ getBooth: (slug) => api.get(`${endpoint3}/${slug}/booth`),
281
+ skipTrack: (slug, options) => api.post(
282
+ `${endpoint3}/${slug}/booth/skip`,
283
+ options || {}
284
+ ),
285
+ vote: (slug, type) => api.post(`${endpoint3}/${slug}/booth/vote`, { type }),
286
+ grabTrack: (slug, playlistId) => api.post(`${endpoint3}/${slug}/booth/grab`, playlistId ? { playlistId } : {}),
287
+ getHistory: (slug, page = 1, limit = 20) => api.get(`${endpoint3}/${slug}/history`, { params: { page, limit } }),
288
+ getAuditLog: (slug, limit = 50, before) => api.get(`${endpoint3}/${slug}/audit`, { params: before ? { limit, before } : { limit } }),
289
+ activity: (limit = 12) => api.get(`${endpoint3}/activity`, { params: { limit } })
290
+ });
527
291
 
528
- // src/resources/ChatResource.ts
529
- var ChatResource = class extends ApiResource {
530
- constructor() {
531
- super(...arguments);
532
- this.endpoint = "/rooms";
533
- }
534
- // POST /api/rooms/:slug/chat - Send a chat message
535
- async sendMessage(slug, data) {
536
- return this.api.post(`${this.endpoint}/${slug}/chat`, data);
537
- }
538
- // GET /api/rooms/:slug/chat - Get chat history
539
- async getMessages(slug, before, limit = 50) {
292
+ // src/resources/chat.ts
293
+ var endpoint4 = "/rooms";
294
+ var createChatResource = (api) => ({
295
+ sendMessage: (slug, data) => api.post(`${endpoint4}/${slug}/chat`, data),
296
+ getMessages: (slug, before, limit = 50) => {
540
297
  const params = { limit };
541
298
  if (before) {
542
299
  params.before = before;
543
300
  }
544
- return this.api.get(`${this.endpoint}/${slug}/chat`, { params });
545
- }
546
- // DELETE /api/rooms/:slug/chat/:messageId - Delete a chat message (moderation)
547
- async deleteMessage(slug, messageId) {
548
- return this.api.delete(`${this.endpoint}/${slug}/chat/${messageId}`);
549
- }
550
- };
551
- var chatResource = new ChatResource();
301
+ return api.get(`${endpoint4}/${slug}/chat`, { params });
302
+ },
303
+ deleteMessage: (slug, messageId) => api.delete(`${endpoint4}/${slug}/chat/${messageId}`)
304
+ });
552
305
 
553
- // src/resources/PlaylistResource.ts
554
- var PlaylistResource = class extends ApiResource {
555
- constructor() {
556
- super(...arguments);
557
- this.endpoint = "/playlists";
558
- }
559
- // GET /api/playlists - Get all user's playlists
560
- async getAll() {
561
- return this.api.get(this.endpoint);
562
- }
563
- // GET /api/playlists/:id - Get playlist with items
564
- async getById(playlistId) {
565
- return this.api.get(`${this.endpoint}/${playlistId}`);
566
- }
567
- // POST /api/playlists - Create playlist
568
- async create(name) {
569
- return this.api.post(this.endpoint, { name });
570
- }
571
- // PATCH /api/playlists/:id - Update playlist
572
- async rename(playlistId, name) {
573
- return this.api.patch(`${this.endpoint}/${playlistId}`, { name });
574
- }
575
- // DELETE /api/playlists/:id - Delete playlist
576
- async remove(playlistId) {
577
- return this.api.delete(`${this.endpoint}/${playlistId}`);
578
- }
579
- // POST /api/playlists/:id/activate - Activate playlist
580
- async activate(playlistId) {
581
- return this.api.post(`${this.endpoint}/${playlistId}/activate`);
582
- }
583
- // POST /api/playlists/:id/shuffle - Shuffle playlist
584
- async shuffle(playlistId) {
585
- return this.api.post(`${this.endpoint}/${playlistId}/shuffle`);
586
- }
587
- // POST /api/playlists/:id/items - Add item to playlist
588
- async addItem(playlistId, data) {
589
- return this.api.post(`${this.endpoint}/${playlistId}/items`, data);
590
- }
591
- // DELETE /api/playlists/:id/items/:itemId - Remove item from playlist
592
- async removeItem(playlistId, itemId) {
593
- return this.api.delete(`${this.endpoint}/${playlistId}/items/${itemId}`);
594
- }
595
- // PATCH /api/playlists/:id/items/:itemId/move - Move item in playlist
596
- async moveItem(playlistId, itemId, position) {
597
- return this.api.patch(`${this.endpoint}/${playlistId}/items/${itemId}/move`, { position });
598
- }
599
- // POST /api/playlists/:id/import - Import from YouTube/SoundCloud playlist
600
- async importPlaylist(playlistId, data) {
601
- return this.api.post(`${this.endpoint}/${playlistId}/import`, data);
602
- }
603
- };
604
- var playlistResource = new PlaylistResource();
306
+ // src/resources/playlist.ts
307
+ var endpoint5 = "/playlists";
308
+ var createPlaylistResource = (api) => ({
309
+ getAll: () => api.get(endpoint5),
310
+ getById: (playlistId) => api.get(`${endpoint5}/${playlistId}`),
311
+ create: (name) => api.post(endpoint5, { name }),
312
+ rename: (playlistId, name) => api.patch(`${endpoint5}/${playlistId}`, { name }),
313
+ remove: (playlistId) => api.delete(`${endpoint5}/${playlistId}`),
314
+ activate: (playlistId) => api.post(`${endpoint5}/${playlistId}/activate`),
315
+ shuffle: (playlistId) => api.post(`${endpoint5}/${playlistId}/shuffle`),
316
+ addItem: (playlistId, data) => api.post(`${endpoint5}/${playlistId}/items`, data),
317
+ removeItem: (playlistId, itemId) => api.delete(`${endpoint5}/${playlistId}/items/${itemId}`),
318
+ moveItem: (playlistId, itemId, position) => api.patch(`${endpoint5}/${playlistId}/items/${itemId}/move`, { position }),
319
+ importPlaylist: (playlistId, data) => api.post(`${endpoint5}/${playlistId}/import`, data)
320
+ });
605
321
 
606
- // src/resources/SourceResource.ts
607
- var SourceResource = class extends ApiResource {
608
- constructor() {
609
- super(...arguments);
610
- this.endpoint = "/sources";
611
- }
612
- // ============================================
613
- // YouTube
614
- // ============================================
615
- // GET /api/sources/youtube/search?q=...&limit=...
616
- async searchYouTube(query, limit = 10) {
617
- return this.api.get(`${this.endpoint}/youtube/search`, {
618
- params: { q: query, limit }
619
- });
620
- }
621
- // GET /api/sources/youtube/videos/:videoId
622
- async getYouTubeVideo(videoId) {
623
- return this.api.get(`${this.endpoint}/youtube/videos/${videoId}`);
624
- }
625
- // ============================================
626
- // SoundCloud
627
- // ============================================
628
- // GET /api/sources/soundcloud/search?q=...&limit=...
629
- async searchSoundCloud(query, limit = 10) {
630
- return this.api.get(`${this.endpoint}/soundcloud/search`, {
631
- params: { q: query, limit }
632
- });
633
- }
634
- // GET /api/sources/soundcloud/tracks/:trackId
635
- async getSoundCloudTrack(trackId) {
636
- return this.api.get(`${this.endpoint}/soundcloud/tracks/${trackId}`);
637
- }
638
- // GET /api/sources/soundcloud/resolve?url=...
639
- async resolveSoundCloudUrl(url) {
640
- return this.api.get(`${this.endpoint}/soundcloud/resolve`, {
641
- params: { url }
642
- });
643
- }
644
- // ============================================
645
- // Combined search (helper)
646
- // ============================================
647
- // Search both YouTube and SoundCloud
648
- async searchAll(query, limit = 10) {
649
- var _a, _b, _c, _d;
322
+ // src/resources/source.ts
323
+ var endpoint6 = "/sources";
324
+ var createSourceResource = (api) => ({
325
+ searchYouTube: (query, limit = 10) => api.get(`${endpoint6}/youtube/search`, {
326
+ params: { q: query, limit }
327
+ }),
328
+ getYouTubeVideo: (videoId) => api.get(`${endpoint6}/youtube/videos/${videoId}`),
329
+ searchSoundCloud: (query, limit = 10) => api.get(`${endpoint6}/soundcloud/search`, {
330
+ params: { q: query, limit }
331
+ }),
332
+ getSoundCloudTrack: (trackId) => api.get(`${endpoint6}/soundcloud/tracks/${trackId}`),
333
+ resolveSoundCloudUrl: (url) => api.get(`${endpoint6}/soundcloud/resolve`, { params: { url } }),
334
+ searchAll: async (query, limit = 10) => {
650
335
  const [youtube, soundcloud] = await Promise.allSettled([
651
- this.searchYouTube(query, limit),
652
- this.searchSoundCloud(query, limit)
336
+ api.get(`${endpoint6}/youtube/search`, { params: { q: query, limit } }),
337
+ api.get(`${endpoint6}/soundcloud/search`, { params: { q: query, limit } })
653
338
  ]);
654
339
  const results = [];
655
- if (youtube.status === "fulfilled" && ((_b = (_a = youtube.value.data) == null ? void 0 : _a.data) == null ? void 0 : _b.results)) {
340
+ if (youtube.status === "fulfilled" && youtube.value.data?.data?.results) {
656
341
  results.push(...youtube.value.data.data.results);
657
342
  }
658
- if (soundcloud.status === "fulfilled" && ((_d = (_c = soundcloud.value.data) == null ? void 0 : _c.data) == null ? void 0 : _d.results)) {
343
+ if (soundcloud.status === "fulfilled" && soundcloud.value.data?.data?.results) {
659
344
  results.push(...soundcloud.value.data.data.results);
660
345
  }
661
346
  return results;
662
347
  }
663
- };
664
- var sourceResource = new SourceResource();
348
+ });
665
349
 
666
- // src/resources/ShopResource.ts
667
- var ShopResource = class extends ApiResource {
668
- constructor() {
669
- super(...arguments);
670
- this.endpoint = "/shop";
671
- }
672
- // GET /api/shop/avatars
673
- async getAvatarCatalog() {
674
- return this.api.get(`${this.endpoint}/avatars`);
675
- }
676
- // POST /api/shop/avatars/:avatarId/unlock
677
- async unlockAvatar(avatarId) {
678
- return this.api.post(`${this.endpoint}/avatars/${avatarId}/unlock`);
679
- }
680
- // PATCH /api/shop/avatars/equip
681
- async equipAvatar(avatarId) {
682
- return this.api.patch(`${this.endpoint}/avatars/equip`, { avatarId });
683
- }
684
- };
685
- var shopResource = new ShopResource();
350
+ // src/resources/shop.ts
351
+ var endpoint7 = "/shop";
352
+ var createShopResource = (api) => ({
353
+ getAvatarCatalog: () => api.get(`${endpoint7}/avatars`),
354
+ unlockAvatar: (avatarId) => api.post(
355
+ `${endpoint7}/avatars/${avatarId}/unlock`
356
+ ),
357
+ equipAvatar: (avatarId) => api.patch(
358
+ `${endpoint7}/avatars/equip`,
359
+ { avatarId }
360
+ )
361
+ });
686
362
 
687
- // src/resources/SubscriptionResource.ts
688
- var SubscriptionResource = class extends ApiResource {
689
- constructor() {
690
- super(...arguments);
691
- this.endpoint = "/subscriptions";
692
- }
693
- // GET /api/subscriptions/status
694
- async getStatus() {
695
- return this.api.get(`${this.endpoint}/status`);
696
- }
697
- // POST /api/subscriptions/create-intent
698
- // Creates an incomplete subscription and returns a PaymentIntent client_secret
699
- // for use with the Stripe Payment Element
700
- async createIntent(plan) {
701
- return this.api.post(`${this.endpoint}/create-intent`, { plan });
702
- }
703
- // POST /api/subscriptions/cancel-intent
704
- // Cancels an incomplete subscription when the user goes back from the payment step
705
- async cancelIntent(subscriptionId) {
706
- return this.api.post(`${this.endpoint}/cancel-intent`, { subscriptionId });
707
- }
708
- // POST /api/subscriptions/portal
709
- async createPortal() {
710
- return this.api.post(`${this.endpoint}/portal`);
711
- }
712
- };
713
- var subscriptionResource = new SubscriptionResource();
363
+ // src/resources/subscription.ts
364
+ var endpoint8 = "/subscriptions";
365
+ var createSubscriptionResource = (api) => ({
366
+ getStatus: () => api.get(`${endpoint8}/status`),
367
+ createIntent: (plan) => api.post(`${endpoint8}/create-intent`, { plan }),
368
+ cancelIntent: (subscriptionId) => api.post(`${endpoint8}/cancel-intent`, { subscriptionId }),
369
+ createPortal: () => api.post(`${endpoint8}/portal`)
370
+ });
714
371
 
715
- // src/resources/FriendResource.ts
716
- var FriendResource = class extends ApiResource {
717
- constructor() {
718
- super(...arguments);
719
- this.endpoint = "/friends";
720
- }
721
- // GET /api/friends
722
- async list() {
723
- return this.api.get(this.endpoint);
724
- }
725
- // GET /api/friends/status/:targetUserId
726
- async getStatus(targetUserId) {
727
- return this.api.get(`${this.endpoint}/status/${targetUserId}`);
728
- }
729
- // POST /api/friends/:targetUserId send or auto-accept request
730
- async sendRequest(targetUserId) {
731
- return this.api.post(`${this.endpoint}/${targetUserId}`);
732
- }
733
- // PATCH /api/friends/:friendshipId/accept
734
- async acceptRequest(friendshipId) {
735
- return this.api.patch(`${this.endpoint}/${friendshipId}/accept`);
736
- }
737
- // DELETE /api/friends/:friendshipId — decline / cancel / unfriend
738
- async remove(friendshipId) {
739
- return this.api.delete(`${this.endpoint}/${friendshipId}`);
740
- }
741
- // POST /api/friends/:targetUserId/block
742
- async block(targetUserId) {
743
- return this.api.post(`${this.endpoint}/${targetUserId}/block`);
744
- }
745
- // DELETE /api/friends/:targetUserId/block
746
- async unblock(targetUserId) {
747
- return this.api.delete(`${this.endpoint}/${targetUserId}/block`);
748
- }
372
+ // src/resources/friend.ts
373
+ var endpoint9 = "/friends";
374
+ var createFriendResource = (api) => ({
375
+ list: () => api.get(endpoint9),
376
+ getStatus: (targetUserId) => api.get(`${endpoint9}/status/${targetUserId}`),
377
+ sendRequest: (targetUserId) => api.post(`${endpoint9}/${targetUserId}`),
378
+ acceptRequest: (friendshipId) => api.patch(`${endpoint9}/${friendshipId}/accept`),
379
+ remove: (friendshipId) => api.delete(`${endpoint9}/${friendshipId}`),
380
+ block: (targetUserId) => api.post(`${endpoint9}/${targetUserId}/block`),
381
+ unblock: (targetUserId) => api.delete(`${endpoint9}/${targetUserId}/block`)
382
+ });
383
+
384
+ // src/resources/admin.ts
385
+ var endpoint10 = "/admin";
386
+ var createAdminResource = (api) => ({
387
+ listUsers: (params = {}) => {
388
+ const query = new URLSearchParams();
389
+ if (params.search) query.set("search", params.search);
390
+ if (params.role) query.set("role", params.role);
391
+ if (params.disabled !== void 0) query.set("disabled", String(params.disabled));
392
+ if (params.page) query.set("page", String(params.page));
393
+ if (params.limit) query.set("limit", String(params.limit));
394
+ if (params.sortBy) query.set("sortBy", params.sortBy);
395
+ if (params.sortDir) query.set("sortDir", params.sortDir);
396
+ const qs = query.toString();
397
+ return api.get(`${endpoint10}/users${qs ? `?${qs}` : ""}`);
398
+ },
399
+ enableUser: (id) => api.post(`${endpoint10}/users/${id}/enable`),
400
+ disableUser: (id) => api.post(`${endpoint10}/users/${id}/disable`),
401
+ updateRole: (id, role) => api.patch(`${endpoint10}/users/${id}/role`, { role }),
402
+ broadcast: (message) => api.post(`${endpoint10}/broadcast`, { message }),
403
+ setMaintenance: (active, message, endsAt) => api.post(`${endpoint10}/maintenance`, { active, message, endsAt }),
404
+ getStats: () => api.get(`${endpoint10}/stats`),
405
+ addViolation: (userId, reason) => api.post(`${endpoint10}/users/${userId}/violations`, { reason }),
406
+ revokeViolation: (violationId) => api.delete(`${endpoint10}/violations/${violationId}`),
407
+ getUserViolations: (userId) => api.get(`${endpoint10}/users/${userId}/violations`)
408
+ });
409
+
410
+ // src/resources/index.ts
411
+ var createApiClient = (config) => {
412
+ const api = createApi(config);
413
+ return {
414
+ api,
415
+ auth: createAuthResource(api),
416
+ user: createUserResource(api),
417
+ room: createRoomResource(api),
418
+ chat: createChatResource(api),
419
+ playlist: createPlaylistResource(api),
420
+ source: createSourceResource(api),
421
+ shop: createShopResource(api),
422
+ subscription: createSubscriptionResource(api),
423
+ friend: createFriendResource(api),
424
+ admin: createAdminResource(api)
425
+ };
749
426
  };
750
- var friendResource = new FriendResource();
751
427
  // Annotate the CommonJS export names for ESM import in node:
752
428
  0 && (module.exports = {
753
429
  Api,
754
430
  ApiError,
755
- ApiResource,
756
- AuthResource,
757
- ChatResource,
758
- FriendResource,
759
431
  Logger,
760
- PlaylistResource,
761
- RoomResource,
762
- ShopResource,
763
- SourceResource,
764
- SubscriptionResource,
765
- UserResource,
766
- authResource,
767
- chatResource,
768
- friendResource,
769
- playlistResource,
770
- roomResource,
771
- shopResource,
772
- sourceResource,
773
- subscriptionResource,
774
- userResource
432
+ createAdminResource,
433
+ createApi,
434
+ createApiClient,
435
+ createAuthResource,
436
+ createChatResource,
437
+ createFriendResource,
438
+ createPlaylistResource,
439
+ createRoomResource,
440
+ createShopResource,
441
+ createSourceResource,
442
+ createSubscriptionResource,
443
+ createUserResource
775
444
  });