@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/README.md +286 -205
- package/dist/index.d.mts +42 -78
- package/dist/index.d.ts +42 -78
- package/dist/index.js +179 -545
- package/dist/index.mjs +168 -526
- package/package.json +1 -1
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
|
111
|
+
var Api = class {
|
|
120
112
|
constructor(config) {
|
|
121
|
-
var _a;
|
|
122
113
|
this.config = config;
|
|
123
|
-
this.logger = Logger
|
|
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:
|
|
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
|
-
|
|
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 =
|
|
172
|
-
this.logger.error(`\u2190 ${status} ${
|
|
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
|
-
|
|
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/
|
|
318
|
-
var
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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/
|
|
347
|
-
var
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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/
|
|
383
|
-
var
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
|
|
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/
|
|
529
|
-
var
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
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
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
|
|
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/
|
|
554
|
-
var
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
}
|
|
567
|
-
|
|
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/
|
|
607
|
-
var
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
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
|
-
|
|
652
|
-
|
|
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" &&
|
|
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" &&
|
|
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/
|
|
667
|
-
var
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
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/
|
|
688
|
-
var
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
|
|
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/
|
|
716
|
-
var
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
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
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
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
|
});
|