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