@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.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,193 @@ 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
|
-
if (!this._logger) {
|
|
199
|
-
this._logger = Logger.create(this.constructor.name);
|
|
200
|
-
}
|
|
201
|
-
return this._logger;
|
|
202
|
-
}
|
|
203
|
-
buildUrl(path) {
|
|
204
|
-
if (path !== void 0) {
|
|
205
|
-
return `${this.endpoint}/${path}`;
|
|
206
|
-
}
|
|
207
|
-
return this.endpoint;
|
|
208
|
-
}
|
|
209
|
-
buildConfig(options) {
|
|
210
|
-
return {
|
|
211
|
-
params: options == null ? void 0 : options.params,
|
|
212
|
-
headers: options == null ? void 0 : options.headers
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
async index(options) {
|
|
216
|
-
this.logger.debug("index");
|
|
217
|
-
return this.api.get(this.endpoint, this.buildConfig(options));
|
|
218
|
-
}
|
|
219
|
-
async paginate(page = 1, perPage = 15, options) {
|
|
220
|
-
this.logger.debug(`paginate (page: ${page}, perPage: ${perPage})`);
|
|
221
|
-
return this.api.get(this.endpoint, {
|
|
222
|
-
...this.buildConfig(options),
|
|
223
|
-
params: { page, per_page: perPage, ...options == null ? void 0 : options.params }
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
async show(id, options) {
|
|
227
|
-
this.logger.debug(`show (id: ${id})`);
|
|
228
|
-
return this.api.get(this.buildUrl(id), this.buildConfig(options));
|
|
229
|
-
}
|
|
230
|
-
async store(data, options) {
|
|
231
|
-
this.logger.debug("store");
|
|
232
|
-
return this.api.post(this.endpoint, data, this.buildConfig(options));
|
|
233
|
-
}
|
|
234
|
-
async update(id, data, options) {
|
|
235
|
-
this.logger.debug(`update (id: ${id})`);
|
|
236
|
-
return this.api.put(this.buildUrl(id), data, this.buildConfig(options));
|
|
237
|
-
}
|
|
238
|
-
async patch(id, data, options) {
|
|
239
|
-
this.logger.debug(`patch (id: ${id})`);
|
|
240
|
-
return this.api.patch(this.buildUrl(id), data, this.buildConfig(options));
|
|
241
|
-
}
|
|
242
|
-
async destroy(id, options) {
|
|
243
|
-
this.logger.debug(`destroy (id: ${id})`);
|
|
244
|
-
return this.api.delete(this.buildUrl(id), this.buildConfig(options));
|
|
245
|
-
}
|
|
246
|
-
async get(path, options) {
|
|
247
|
-
return this.api.get(`${this.endpoint}/${path}`, this.buildConfig(options));
|
|
248
|
-
}
|
|
249
|
-
async post(path, data, options) {
|
|
250
|
-
return this.api.post(`${this.endpoint}/${path}`, data, this.buildConfig(options));
|
|
251
|
-
}
|
|
252
|
-
async put(path, data, options) {
|
|
253
|
-
return this.api.put(`${this.endpoint}/${path}`, data, this.buildConfig(options));
|
|
254
|
-
}
|
|
255
|
-
async delete(path, options) {
|
|
256
|
-
return this.api.delete(`${this.endpoint}/${path}`, this.buildConfig(options));
|
|
257
|
-
}
|
|
258
|
-
};
|
|
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
|
+
});
|
|
259
181
|
|
|
260
|
-
// src/resources/
|
|
261
|
-
var
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
// POST /api/auth/register
|
|
271
|
-
async register(data) {
|
|
272
|
-
return this.post("register", data);
|
|
273
|
-
}
|
|
274
|
-
// POST /api/auth/refresh
|
|
275
|
-
async refresh(refreshToken) {
|
|
276
|
-
return this.post("refresh", { refreshToken });
|
|
277
|
-
}
|
|
278
|
-
// POST /api/auth/logout
|
|
279
|
-
async logout() {
|
|
280
|
-
return this.post("logout");
|
|
281
|
-
}
|
|
282
|
-
// GET /api/auth/me
|
|
283
|
-
async me() {
|
|
284
|
-
return this.get("me");
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
var authResource = new AuthResource();
|
|
182
|
+
// src/resources/user.ts
|
|
183
|
+
var endpoint2 = "/users";
|
|
184
|
+
var createUserResource = (api) => ({
|
|
185
|
+
getById: (id) => api.get(`${endpoint2}/${id}`),
|
|
186
|
+
getByUsername: (username) => api.get(`${endpoint2}/username/${username}`),
|
|
187
|
+
updateProfile: (data) => api.patch(`${endpoint2}/me`, data),
|
|
188
|
+
deleteAccount: () => api.delete(`${endpoint2}/me`),
|
|
189
|
+
updateRole: (id, role) => api.patch(`/api/admin/users/${id}/role`, { role }),
|
|
190
|
+
disable: (id) => api.post(`/api/admin/users/${id}/disable`)
|
|
191
|
+
});
|
|
288
192
|
|
|
289
|
-
// src/resources/
|
|
290
|
-
var
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
193
|
+
// src/resources/room.ts
|
|
194
|
+
var endpoint3 = "/rooms";
|
|
195
|
+
var createRoomResource = (api) => ({
|
|
196
|
+
list: () => api.get(endpoint3),
|
|
197
|
+
featured: () => api.get(`${endpoint3}/featured`),
|
|
198
|
+
getBySlug: (slug) => api.get(`${endpoint3}/${slug}`),
|
|
199
|
+
create: (data) => api.post(endpoint3, data),
|
|
200
|
+
updateRoom: (slug, data) => api.patch(`${endpoint3}/${slug}`, data),
|
|
201
|
+
deleteRoom: (slug) => api.delete(`${endpoint3}/${slug}`),
|
|
202
|
+
getStaff: (slug) => api.get(`${endpoint3}/${slug}/staff`),
|
|
203
|
+
getBans: (slug) => api.get(`${endpoint3}/${slug}/bans`),
|
|
204
|
+
getMutes: (slug) => api.get(`${endpoint3}/${slug}/mutes`),
|
|
205
|
+
updateUserRole: (slug, userId, role) => api.patch(
|
|
206
|
+
`${endpoint3}/${slug}/users/${userId}/role`,
|
|
207
|
+
{ role }
|
|
208
|
+
),
|
|
209
|
+
ban: (slug, userId, data) => api.post(`${endpoint3}/${slug}/users/${userId}/ban`, data || {}),
|
|
210
|
+
unban: (slug, userId) => api.delete(`${endpoint3}/${slug}/users/${userId}/ban`),
|
|
211
|
+
mute: (slug, userId, data) => api.post(`${endpoint3}/${slug}/users/${userId}/mute`, data || {}),
|
|
212
|
+
unmute: (slug, userId) => api.delete(`${endpoint3}/${slug}/users/${userId}/mute`),
|
|
213
|
+
kick: (slug, userId) => api.post(`${endpoint3}/${slug}/users/${userId}/kick`),
|
|
214
|
+
join: (slug) => api.post(`${endpoint3}/${slug}/join`),
|
|
215
|
+
leave: (slug) => api.post(`${endpoint3}/${slug}/leave`),
|
|
216
|
+
getWaitlist: (slug) => api.get(`${endpoint3}/${slug}/waitlist`),
|
|
217
|
+
joinWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/join`),
|
|
218
|
+
leaveWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/leave`),
|
|
219
|
+
moveInWaitlist: (slug, userId, position) => api.patch(
|
|
220
|
+
`${endpoint3}/${slug}/waitlist`,
|
|
221
|
+
{ userId, position }
|
|
222
|
+
),
|
|
223
|
+
removeFromWaitlist: (slug, userId) => api.delete(`${endpoint3}/${slug}/waitlist/${userId}`),
|
|
224
|
+
lockWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/lock`),
|
|
225
|
+
unlockWaitlist: (slug) => api.post(`${endpoint3}/${slug}/waitlist/unlock`),
|
|
226
|
+
getBooth: (slug) => api.get(`${endpoint3}/${slug}/booth`),
|
|
227
|
+
skipTrack: (slug, options) => api.post(
|
|
228
|
+
`${endpoint3}/${slug}/booth/skip`,
|
|
229
|
+
options || {}
|
|
230
|
+
),
|
|
231
|
+
vote: (slug, type) => api.post(`${endpoint3}/${slug}/booth/vote`, { type }),
|
|
232
|
+
grabTrack: (slug, playlistId) => api.post(`${endpoint3}/${slug}/booth/grab`, playlistId ? { playlistId } : {}),
|
|
233
|
+
getHistory: (slug, page = 1, limit = 20) => api.get(`${endpoint3}/${slug}/history`, { params: { page, limit } })
|
|
234
|
+
});
|
|
324
235
|
|
|
325
|
-
// src/resources/
|
|
326
|
-
var
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
// GET /api/rooms - List all rooms
|
|
332
|
-
async list() {
|
|
333
|
-
return this.get("");
|
|
334
|
-
}
|
|
335
|
-
// GET /api/rooms/featured - Get featured rooms
|
|
336
|
-
async featured() {
|
|
337
|
-
return this.get("featured");
|
|
338
|
-
}
|
|
339
|
-
// GET /api/rooms/:slug - Get room by slug
|
|
340
|
-
async getBySlug(slug) {
|
|
341
|
-
return this.get(slug);
|
|
342
|
-
}
|
|
343
|
-
// POST /api/rooms - Create a new room
|
|
344
|
-
async create(data) {
|
|
345
|
-
return this.post("", data);
|
|
346
|
-
}
|
|
347
|
-
// PATCH /api/rooms/:slug - Update room
|
|
348
|
-
async updateRoom(slug, data) {
|
|
349
|
-
return this.api.patch(`${this.endpoint}/${slug}`, data);
|
|
350
|
-
}
|
|
351
|
-
// DELETE /api/rooms/:slug - Delete room
|
|
352
|
-
async deleteRoom(slug) {
|
|
353
|
-
return this.api.delete(`${this.endpoint}/${slug}`);
|
|
354
|
-
}
|
|
355
|
-
// GET /api/rooms/:slug/staff - Get room staff
|
|
356
|
-
async getStaff(slug) {
|
|
357
|
-
return this.get(`${slug}/staff`);
|
|
358
|
-
}
|
|
359
|
-
// ============================================
|
|
360
|
-
// Moderation methods
|
|
361
|
-
// ============================================
|
|
362
|
-
// GET /api/rooms/:slug/bans
|
|
363
|
-
async getBans(slug) {
|
|
364
|
-
return this.get(`${slug}/bans`);
|
|
365
|
-
}
|
|
366
|
-
// GET /api/rooms/:slug/mutes
|
|
367
|
-
async getMutes(slug) {
|
|
368
|
-
return this.get(`${slug}/mutes`);
|
|
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();
|
|
470
|
-
|
|
471
|
-
// src/resources/ChatResource.ts
|
|
472
|
-
var ChatResource = class extends ApiResource {
|
|
473
|
-
constructor() {
|
|
474
|
-
super(...arguments);
|
|
475
|
-
this.endpoint = "/rooms";
|
|
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) {
|
|
236
|
+
// src/resources/chat.ts
|
|
237
|
+
var endpoint4 = "/rooms";
|
|
238
|
+
var createChatResource = (api) => ({
|
|
239
|
+
sendMessage: (slug, data) => api.post(`${endpoint4}/${slug}/chat`, data),
|
|
240
|
+
getMessages: (slug, before, limit = 50) => {
|
|
483
241
|
const params = { limit };
|
|
484
242
|
if (before) {
|
|
485
243
|
params.before = before;
|
|
486
244
|
}
|
|
487
|
-
return
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
return this.api.delete(`${this.endpoint}/${slug}/chat/${messageId}`);
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
var chatResource = new ChatResource();
|
|
245
|
+
return api.get(`${endpoint4}/${slug}/chat`, { params });
|
|
246
|
+
},
|
|
247
|
+
deleteMessage: (slug, messageId) => api.delete(`${endpoint4}/${slug}/chat/${messageId}`)
|
|
248
|
+
});
|
|
495
249
|
|
|
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();
|
|
250
|
+
// src/resources/playlist.ts
|
|
251
|
+
var endpoint5 = "/playlists";
|
|
252
|
+
var createPlaylistResource = (api) => ({
|
|
253
|
+
getAll: () => api.get(endpoint5),
|
|
254
|
+
getById: (playlistId) => api.get(`${endpoint5}/${playlistId}`),
|
|
255
|
+
create: (name) => api.post(endpoint5, { name }),
|
|
256
|
+
rename: (playlistId, name) => api.patch(`${endpoint5}/${playlistId}`, { name }),
|
|
257
|
+
remove: (playlistId) => api.delete(`${endpoint5}/${playlistId}`),
|
|
258
|
+
activate: (playlistId) => api.post(`${endpoint5}/${playlistId}/activate`),
|
|
259
|
+
shuffle: (playlistId) => api.post(`${endpoint5}/${playlistId}/shuffle`),
|
|
260
|
+
addItem: (playlistId, data) => api.post(`${endpoint5}/${playlistId}/items`, data),
|
|
261
|
+
removeItem: (playlistId, itemId) => api.delete(`${endpoint5}/${playlistId}/items/${itemId}`),
|
|
262
|
+
moveItem: (playlistId, itemId, position) => api.patch(`${endpoint5}/${playlistId}/items/${itemId}/move`, { position }),
|
|
263
|
+
importPlaylist: (playlistId, data) => api.post(`${endpoint5}/${playlistId}/import`, data)
|
|
264
|
+
});
|
|
548
265
|
|
|
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;
|
|
266
|
+
// src/resources/source.ts
|
|
267
|
+
var endpoint6 = "/sources";
|
|
268
|
+
var createSourceResource = (api) => ({
|
|
269
|
+
searchYouTube: (query, limit = 10) => api.get(`${endpoint6}/youtube/search`, {
|
|
270
|
+
params: { q: query, limit }
|
|
271
|
+
}),
|
|
272
|
+
getYouTubeVideo: (videoId) => api.get(`${endpoint6}/youtube/videos/${videoId}`),
|
|
273
|
+
searchSoundCloud: (query, limit = 10) => api.get(`${endpoint6}/soundcloud/search`, {
|
|
274
|
+
params: { q: query, limit }
|
|
275
|
+
}),
|
|
276
|
+
getSoundCloudTrack: (trackId) => api.get(`${endpoint6}/soundcloud/tracks/${trackId}`),
|
|
277
|
+
resolveSoundCloudUrl: (url) => api.get(`${endpoint6}/soundcloud/resolve`, { params: { url } }),
|
|
278
|
+
searchAll: async (query, limit = 10) => {
|
|
593
279
|
const [youtube, soundcloud] = await Promise.allSettled([
|
|
594
|
-
|
|
595
|
-
|
|
280
|
+
api.get(`${endpoint6}/youtube/search`, { params: { q: query, limit } }),
|
|
281
|
+
api.get(`${endpoint6}/soundcloud/search`, { params: { q: query, limit } })
|
|
596
282
|
]);
|
|
597
283
|
const results = [];
|
|
598
|
-
if (youtube.status === "fulfilled" &&
|
|
284
|
+
if (youtube.status === "fulfilled" && youtube.value.data?.data?.results) {
|
|
599
285
|
results.push(...youtube.value.data.data.results);
|
|
600
286
|
}
|
|
601
|
-
if (soundcloud.status === "fulfilled" &&
|
|
287
|
+
if (soundcloud.status === "fulfilled" && soundcloud.value.data?.data?.results) {
|
|
602
288
|
results.push(...soundcloud.value.data.data.results);
|
|
603
289
|
}
|
|
604
290
|
return results;
|
|
605
291
|
}
|
|
606
|
-
};
|
|
607
|
-
var sourceResource = new SourceResource();
|
|
292
|
+
});
|
|
608
293
|
|
|
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();
|
|
294
|
+
// src/resources/shop.ts
|
|
295
|
+
var endpoint7 = "/shop";
|
|
296
|
+
var createShopResource = (api) => ({
|
|
297
|
+
getAvatarCatalog: () => api.get(`${endpoint7}/avatars`),
|
|
298
|
+
unlockAvatar: (avatarId) => api.post(
|
|
299
|
+
`${endpoint7}/avatars/${avatarId}/unlock`
|
|
300
|
+
),
|
|
301
|
+
equipAvatar: (avatarId) => api.patch(
|
|
302
|
+
`${endpoint7}/avatars/equip`,
|
|
303
|
+
{ avatarId }
|
|
304
|
+
)
|
|
305
|
+
});
|
|
629
306
|
|
|
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();
|
|
307
|
+
// src/resources/subscription.ts
|
|
308
|
+
var endpoint8 = "/subscriptions";
|
|
309
|
+
var createSubscriptionResource = (api) => ({
|
|
310
|
+
getStatus: () => api.get(`${endpoint8}/status`),
|
|
311
|
+
createIntent: (plan) => api.post(`${endpoint8}/create-intent`, { plan }),
|
|
312
|
+
cancelIntent: (subscriptionId) => api.post(`${endpoint8}/cancel-intent`, { subscriptionId }),
|
|
313
|
+
createPortal: () => api.post(`${endpoint8}/portal`)
|
|
314
|
+
});
|
|
657
315
|
|
|
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
|
-
async block(targetUserId) {
|
|
686
|
-
return this.api.post(`${this.endpoint}/${targetUserId}/block`);
|
|
687
|
-
}
|
|
688
|
-
// DELETE /api/friends/:targetUserId/block
|
|
689
|
-
async unblock(targetUserId) {
|
|
690
|
-
return this.api.delete(`${this.endpoint}/${targetUserId}/block`);
|
|
691
|
-
}
|
|
316
|
+
// src/resources/friend.ts
|
|
317
|
+
var endpoint9 = "/friends";
|
|
318
|
+
var createFriendResource = (api) => ({
|
|
319
|
+
list: () => api.get(endpoint9),
|
|
320
|
+
getStatus: (targetUserId) => api.get(`${endpoint9}/status/${targetUserId}`),
|
|
321
|
+
sendRequest: (targetUserId) => api.post(`${endpoint9}/${targetUserId}`),
|
|
322
|
+
acceptRequest: (friendshipId) => api.patch(`${endpoint9}/${friendshipId}/accept`),
|
|
323
|
+
remove: (friendshipId) => api.delete(`${endpoint9}/${friendshipId}`),
|
|
324
|
+
block: (targetUserId) => api.post(`${endpoint9}/${targetUserId}/block`),
|
|
325
|
+
unblock: (targetUserId) => api.delete(`${endpoint9}/${targetUserId}/block`)
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// src/resources/index.ts
|
|
329
|
+
var createApiClient = (config) => {
|
|
330
|
+
const api = createApi(config);
|
|
331
|
+
return {
|
|
332
|
+
api,
|
|
333
|
+
auth: createAuthResource(api),
|
|
334
|
+
user: createUserResource(api),
|
|
335
|
+
room: createRoomResource(api),
|
|
336
|
+
chat: createChatResource(api),
|
|
337
|
+
playlist: createPlaylistResource(api),
|
|
338
|
+
source: createSourceResource(api),
|
|
339
|
+
shop: createShopResource(api),
|
|
340
|
+
subscription: createSubscriptionResource(api),
|
|
341
|
+
friend: createFriendResource(api)
|
|
342
|
+
};
|
|
692
343
|
};
|
|
693
|
-
var friendResource = new FriendResource();
|
|
694
344
|
export {
|
|
695
345
|
Api,
|
|
696
346
|
ApiError,
|
|
697
|
-
ApiResource,
|
|
698
|
-
AuthResource,
|
|
699
|
-
ChatResource,
|
|
700
|
-
FriendResource,
|
|
701
347
|
Logger,
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
shopResource,
|
|
714
|
-
sourceResource,
|
|
715
|
-
subscriptionResource,
|
|
716
|
-
userResource
|
|
348
|
+
createApi,
|
|
349
|
+
createApiClient,
|
|
350
|
+
createAuthResource,
|
|
351
|
+
createChatResource,
|
|
352
|
+
createFriendResource,
|
|
353
|
+
createPlaylistResource,
|
|
354
|
+
createRoomResource,
|
|
355
|
+
createShopResource,
|
|
356
|
+
createSourceResource,
|
|
357
|
+
createSubscriptionResource,
|
|
358
|
+
createUserResource
|
|
717
359
|
};
|