@borealise/api 1.1.11 → 2.0.0-alpha.2

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,18 @@ 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
+ createApi: () => createApi,
37
+ createApiClient: () => createApiClient,
38
+ createAuthResource: () => createAuthResource,
39
+ createChatResource: () => createChatResource,
40
+ createFriendResource: () => createFriendResource,
41
+ createPlaylistResource: () => createPlaylistResource,
42
+ createRoomResource: () => createRoomResource,
43
+ createShopResource: () => createShopResource,
44
+ createSourceResource: () => createSourceResource,
45
+ createSubscriptionResource: () => createSubscriptionResource,
46
+ createUserResource: () => createUserResource
55
47
  });
56
48
  module.exports = __toCommonJS(index_exports);
57
49
 
@@ -116,17 +108,16 @@ var ApiError = class extends Error {
116
108
  this.response = response;
117
109
  }
118
110
  };
119
- var _Api = class _Api {
111
+ var Api = class {
120
112
  constructor(config) {
121
- var _a;
122
113
  this.config = config;
123
- this.logger = Logger.create("Api");
114
+ this.logger = new Logger("Api");
124
115
  if (config.logging === false) {
125
116
  this.logger.disable();
126
117
  }
127
118
  this.axios = import_axios.default.create({
128
119
  baseURL: config.baseURL,
129
- timeout: (_a = config.timeout) != null ? _a : 3e4,
120
+ timeout: config.timeout ?? 3e4,
130
121
  headers: {
131
122
  "Content-Type": "application/json",
132
123
  ...config.headers
@@ -135,24 +126,10 @@ var _Api = class _Api {
135
126
  this.setupInterceptors();
136
127
  this.logger.success(`initialized (baseURL: ${config.baseURL})`);
137
128
  }
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
129
  setupInterceptors() {
152
130
  this.axios.interceptors.request.use(
153
131
  (config) => {
154
- var _a;
155
- this.logger.debug(`\u2192 ${(_a = config.method) == null ? void 0 : _a.toUpperCase()} ${config.url}`);
132
+ this.logger.debug(`\u2192 ${config.method?.toUpperCase()} ${config.url}`);
156
133
  return config;
157
134
  },
158
135
  (error) => {
@@ -166,10 +143,9 @@ var _Api = class _Api {
166
143
  return response;
167
144
  },
168
145
  (error) => {
169
- var _a, _b, _c;
170
146
  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}`);
147
+ const status = apiError.status ?? apiError.code ?? "ERR";
148
+ this.logger.error(`\u2190 ${status} ${error.config?.url}: ${apiError.message}`);
173
149
  return Promise.reject(apiError);
174
150
  }
175
151
  );
@@ -240,536 +216,194 @@ var _Api = class _Api {
240
216
  return this.axios;
241
217
  }
242
218
  };
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
- };
219
+ var createApi = (config) => new Api(config);
316
220
 
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();
221
+ // src/resources/auth.ts
222
+ var endpoint = "/auth";
223
+ var createAuthResource = (api) => ({
224
+ login: (credentials) => api.post(`${endpoint}/login`, credentials),
225
+ register: (data) => api.post(`${endpoint}/register`, data),
226
+ refresh: (refreshToken) => api.post(`${endpoint}/refresh`, { refreshToken }),
227
+ logout: () => api.post(`${endpoint}/logout`),
228
+ me: () => api.get(`${endpoint}/me`)
229
+ });
345
230
 
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();
231
+ // src/resources/user.ts
232
+ var endpoint2 = "/users";
233
+ var createUserResource = (api) => ({
234
+ getById: (id) => api.get(`${endpoint2}/${id}`),
235
+ getByUsername: (username) => api.get(`${endpoint2}/username/${username}`),
236
+ updateProfile: (data) => api.patch(`${endpoint2}/me`, data),
237
+ deleteAccount: () => api.delete(`${endpoint2}/me`),
238
+ updateRole: (id, role) => api.patch(`/api/admin/users/${id}/role`, { role }),
239
+ disable: (id) => api.post(`/api/admin/users/${id}/disable`)
240
+ });
381
241
 
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();
242
+ // src/resources/room.ts
243
+ var endpoint3 = "/rooms";
244
+ var createRoomResource = (api) => ({
245
+ list: () => api.get(endpoint3),
246
+ featured: () => api.get(`${endpoint3}/featured`),
247
+ getBySlug: (slug) => api.get(`${endpoint3}/${slug}`),
248
+ create: (data) => api.post(endpoint3, data),
249
+ updateRoom: (slug, data) => api.patch(`${endpoint3}/${slug}`, data),
250
+ deleteRoom: (slug) => api.delete(`${endpoint3}/${slug}`),
251
+ getStaff: (slug) => api.get(`${endpoint3}/${slug}/staff`),
252
+ getBans: (slug) => api.get(`${endpoint3}/${slug}/bans`),
253
+ getMutes: (slug) => api.get(`${endpoint3}/${slug}/mutes`),
254
+ updateUserRole: (slug, userId, role) => api.patch(
255
+ `${endpoint3}/${slug}/users/${userId}/role`,
256
+ { role }
257
+ ),
258
+ ban: (slug, userId, data) => api.post(`${endpoint3}/${slug}/users/${userId}/ban`, data || {}),
259
+ unban: (slug, userId) => api.delete(`${endpoint3}/${slug}/users/${userId}/ban`),
260
+ mute: (slug, userId, data) => api.post(`${endpoint3}/${slug}/users/${userId}/mute`, data || {}),
261
+ unmute: (slug, userId) => api.delete(`${endpoint3}/${slug}/users/${userId}/mute`),
262
+ kick: (slug, userId) => api.post(`${endpoint3}/${slug}/users/${userId}/kick`),
263
+ join: (slug) => api.post(`${endpoint3}/${slug}/join`),
264
+ leave: (slug) => api.post(`${endpoint3}/${slug}/leave`),
265
+ getWaitlist: (slug) => api.get(`${endpoint3}/${slug}/waitlist`),
266
+ joinWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/join`),
267
+ leaveWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/leave`),
268
+ moveInWaitlist: (slug, userId, position) => api.patch(
269
+ `${endpoint3}/${slug}/waitlist`,
270
+ { userId, position }
271
+ ),
272
+ removeFromWaitlist: (slug, userId) => api.delete(`${endpoint3}/${slug}/waitlist/${userId}`),
273
+ lockWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/lock`),
274
+ unlockWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/unlock`),
275
+ getBooth: (slug) => api.get(`${endpoint3}/${slug}/booth`),
276
+ skipTrack: (slug, options) => api.post(
277
+ `${endpoint3}/${slug}/booth/skip`,
278
+ options || {}
279
+ ),
280
+ vote: (slug, type) => api.post(`${endpoint3}/${slug}/booth/vote`, { type }),
281
+ grabTrack: (slug, playlistId) => api.post(`${endpoint3}/${slug}/booth/grab`, playlistId ? { playlistId } : {}),
282
+ getHistory: (slug, page = 1, limit = 20) => api.get(`${endpoint3}/${slug}/history`, { params: { page, limit } })
283
+ });
527
284
 
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) {
285
+ // src/resources/chat.ts
286
+ var endpoint4 = "/rooms";
287
+ var createChatResource = (api) => ({
288
+ sendMessage: (slug, data) => api.post(`${endpoint4}/${slug}/chat`, data),
289
+ getMessages: (slug, before, limit = 50) => {
540
290
  const params = { limit };
541
291
  if (before) {
542
292
  params.before = before;
543
293
  }
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();
294
+ return api.get(`${endpoint4}/${slug}/chat`, { params });
295
+ },
296
+ deleteMessage: (slug, messageId) => api.delete(`${endpoint4}/${slug}/chat/${messageId}`)
297
+ });
552
298
 
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();
299
+ // src/resources/playlist.ts
300
+ var endpoint5 = "/playlists";
301
+ var createPlaylistResource = (api) => ({
302
+ getAll: () => api.get(endpoint5),
303
+ getById: (playlistId) => api.get(`${endpoint5}/${playlistId}`),
304
+ create: (name) => api.post(endpoint5, { name }),
305
+ rename: (playlistId, name) => api.patch(`${endpoint5}/${playlistId}`, { name }),
306
+ remove: (playlistId) => api.delete(`${endpoint5}/${playlistId}`),
307
+ activate: (playlistId) => api.post(`${endpoint5}/${playlistId}/activate`),
308
+ shuffle: (playlistId) => api.post(`${endpoint5}/${playlistId}/shuffle`),
309
+ addItem: (playlistId, data) => api.post(`${endpoint5}/${playlistId}/items`, data),
310
+ removeItem: (playlistId, itemId) => api.delete(`${endpoint5}/${playlistId}/items/${itemId}`),
311
+ moveItem: (playlistId, itemId, position) => api.patch(`${endpoint5}/${playlistId}/items/${itemId}/move`, { position }),
312
+ importPlaylist: (playlistId, data) => api.post(`${endpoint5}/${playlistId}/import`, data)
313
+ });
605
314
 
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;
315
+ // src/resources/source.ts
316
+ var endpoint6 = "/sources";
317
+ var createSourceResource = (api) => ({
318
+ searchYouTube: (query, limit = 10) => api.get(`${endpoint6}/youtube/search`, {
319
+ params: { q: query, limit }
320
+ }),
321
+ getYouTubeVideo: (videoId) => api.get(`${endpoint6}/youtube/videos/${videoId}`),
322
+ searchSoundCloud: (query, limit = 10) => api.get(`${endpoint6}/soundcloud/search`, {
323
+ params: { q: query, limit }
324
+ }),
325
+ getSoundCloudTrack: (trackId) => api.get(`${endpoint6}/soundcloud/tracks/${trackId}`),
326
+ resolveSoundCloudUrl: (url) => api.get(`${endpoint6}/soundcloud/resolve`, { params: { url } }),
327
+ searchAll: async (query, limit = 10) => {
650
328
  const [youtube, soundcloud] = await Promise.allSettled([
651
- this.searchYouTube(query, limit),
652
- this.searchSoundCloud(query, limit)
329
+ api.get(`${endpoint6}/youtube/search`, { params: { q: query, limit } }),
330
+ api.get(`${endpoint6}/soundcloud/search`, { params: { q: query, limit } })
653
331
  ]);
654
332
  const results = [];
655
- if (youtube.status === "fulfilled" && ((_b = (_a = youtube.value.data) == null ? void 0 : _a.data) == null ? void 0 : _b.results)) {
333
+ if (youtube.status === "fulfilled" && youtube.value.data?.data?.results) {
656
334
  results.push(...youtube.value.data.data.results);
657
335
  }
658
- if (soundcloud.status === "fulfilled" && ((_d = (_c = soundcloud.value.data) == null ? void 0 : _c.data) == null ? void 0 : _d.results)) {
336
+ if (soundcloud.status === "fulfilled" && soundcloud.value.data?.data?.results) {
659
337
  results.push(...soundcloud.value.data.data.results);
660
338
  }
661
339
  return results;
662
340
  }
663
- };
664
- var sourceResource = new SourceResource();
341
+ });
665
342
 
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();
343
+ // src/resources/shop.ts
344
+ var endpoint7 = "/shop";
345
+ var createShopResource = (api) => ({
346
+ getAvatarCatalog: () => api.get(`${endpoint7}/avatars`),
347
+ unlockAvatar: (avatarId) => api.post(
348
+ `${endpoint7}/avatars/${avatarId}/unlock`
349
+ ),
350
+ equipAvatar: (avatarId) => api.patch(
351
+ `${endpoint7}/avatars/equip`,
352
+ { avatarId }
353
+ )
354
+ });
686
355
 
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();
356
+ // src/resources/subscription.ts
357
+ var endpoint8 = "/subscriptions";
358
+ var createSubscriptionResource = (api) => ({
359
+ getStatus: () => api.get(`${endpoint8}/status`),
360
+ createIntent: (plan) => api.post(`${endpoint8}/create-intent`, { plan }),
361
+ cancelIntent: (subscriptionId) => api.post(`${endpoint8}/cancel-intent`, { subscriptionId }),
362
+ createPortal: () => api.post(`${endpoint8}/portal`)
363
+ });
714
364
 
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
- }
365
+ // src/resources/friend.ts
366
+ var endpoint9 = "/friends";
367
+ var createFriendResource = (api) => ({
368
+ list: () => api.get(endpoint9),
369
+ getStatus: (targetUserId) => api.get(`${endpoint9}/status/${targetUserId}`),
370
+ sendRequest: (targetUserId) => api.post(`${endpoint9}/${targetUserId}`),
371
+ acceptRequest: (friendshipId) => api.patch(`${endpoint9}/${friendshipId}/accept`),
372
+ remove: (friendshipId) => api.delete(`${endpoint9}/${friendshipId}`),
373
+ block: (targetUserId) => api.post(`${endpoint9}/${targetUserId}/block`),
374
+ unblock: (targetUserId) => api.delete(`${endpoint9}/${targetUserId}/block`)
375
+ });
376
+
377
+ // src/resources/index.ts
378
+ var createApiClient = (config) => {
379
+ const api = createApi(config);
380
+ return {
381
+ api,
382
+ auth: createAuthResource(api),
383
+ user: createUserResource(api),
384
+ room: createRoomResource(api),
385
+ chat: createChatResource(api),
386
+ playlist: createPlaylistResource(api),
387
+ source: createSourceResource(api),
388
+ shop: createShopResource(api),
389
+ subscription: createSubscriptionResource(api),
390
+ friend: createFriendResource(api)
391
+ };
749
392
  };
750
- var friendResource = new FriendResource();
751
393
  // Annotate the CommonJS export names for ESM import in node:
752
394
  0 && (module.exports = {
753
395
  Api,
754
396
  ApiError,
755
- ApiResource,
756
- AuthResource,
757
- ChatResource,
758
- FriendResource,
759
397
  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
398
+ createApi,
399
+ createApiClient,
400
+ createAuthResource,
401
+ createChatResource,
402
+ createFriendResource,
403
+ createPlaylistResource,
404
+ createRoomResource,
405
+ createShopResource,
406
+ createSourceResource,
407
+ createSubscriptionResource,
408
+ createUserResource
775
409
  });