rotur-sdk 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +53 -29
- package/dist/index.d.ts +53 -29
- package/dist/index.js +88 -30
- package/dist/index.mjs +88 -30
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -496,6 +496,7 @@ type WSMessage = {
|
|
|
496
496
|
};
|
|
497
497
|
|
|
498
498
|
type Handler = (msg: any) => void;
|
|
499
|
+
type KeyChangeCallback = (key: string, value: any, oldValue: any) => void;
|
|
499
500
|
declare class RoturSocket extends EventTarget {
|
|
500
501
|
private url;
|
|
501
502
|
private ws;
|
|
@@ -507,11 +508,18 @@ declare class RoturSocket extends EventTarget {
|
|
|
507
508
|
private _username;
|
|
508
509
|
private handlers;
|
|
509
510
|
private rooms;
|
|
511
|
+
private keyCache;
|
|
512
|
+
private keyChangeCallbacks;
|
|
510
513
|
constructor(url?: string);
|
|
511
514
|
get connected(): boolean;
|
|
512
515
|
get userId(): string | null;
|
|
513
516
|
get username(): string | null;
|
|
514
517
|
get joinedRooms(): string[];
|
|
518
|
+
getKey(key: string): any;
|
|
519
|
+
getAllKeys(): Record<string, any>;
|
|
520
|
+
onKeyChange(callback: KeyChangeCallback): () => void;
|
|
521
|
+
offKeyChange(callback: KeyChangeCallback): void;
|
|
522
|
+
private notifyKeyChange;
|
|
515
523
|
connect(token: string): Promise<{
|
|
516
524
|
user_id: UserId;
|
|
517
525
|
username: Username;
|
|
@@ -529,8 +537,7 @@ declare class RoturSocket extends EventTarget {
|
|
|
529
537
|
leave(rooms: string | string[]): void;
|
|
530
538
|
listRooms(): Promise<string[]>;
|
|
531
539
|
roomState(room: string): void;
|
|
532
|
-
|
|
533
|
-
setStatus(status: string): void;
|
|
540
|
+
setStatus(status: string, presence?: Presence): void;
|
|
534
541
|
addActivity(activity: Activity & {
|
|
535
542
|
id: string;
|
|
536
543
|
}): void;
|
|
@@ -579,6 +586,7 @@ declare class Rotur {
|
|
|
579
586
|
get token(): string | null;
|
|
580
587
|
get loggedIn(): boolean;
|
|
581
588
|
setToken(token: string): void;
|
|
589
|
+
private _socketReady;
|
|
582
590
|
login(options?: {
|
|
583
591
|
system?: string;
|
|
584
592
|
timeout?: number;
|
|
@@ -607,6 +615,8 @@ declare class ProfilesNamespace extends Namespace {
|
|
|
607
615
|
subscription: string;
|
|
608
616
|
}>>;
|
|
609
617
|
getAvatarUrl(username: Username, cache?: string): string;
|
|
618
|
+
getOverlayUrl(username: Username, cache?: string): string;
|
|
619
|
+
getBannerUrl(username: Username, cache?: string): string;
|
|
610
620
|
}
|
|
611
621
|
declare class MeNamespace extends Namespace {
|
|
612
622
|
get(): Promise<Record<string, any>>;
|
|
@@ -616,6 +626,9 @@ declare class MeNamespace extends Namespace {
|
|
|
616
626
|
refreshToken(): Promise<{
|
|
617
627
|
token: string;
|
|
618
628
|
}>;
|
|
629
|
+
getKey(key: string): any;
|
|
630
|
+
getAllKeys(): Record<string, any>;
|
|
631
|
+
onKeyChange(callback: (key: string, value: any, oldValue: any) => void): () => void;
|
|
619
632
|
transfer(to: Username, amount: number, note?: string): Promise<any>;
|
|
620
633
|
claimDaily(): Promise<{
|
|
621
634
|
message: string;
|
|
@@ -643,6 +656,9 @@ declare class MeNamespace extends Namespace {
|
|
|
643
656
|
requests(): Promise<{
|
|
644
657
|
requests: Username[];
|
|
645
658
|
}>;
|
|
659
|
+
outgoing(): Promise<{
|
|
660
|
+
outgoing: Username[];
|
|
661
|
+
}>;
|
|
646
662
|
transactions(): Promise<any[]>;
|
|
647
663
|
subscription(): Promise<{
|
|
648
664
|
active: boolean;
|
|
@@ -673,14 +689,43 @@ declare class FriendsNamespace extends Namespace {
|
|
|
673
689
|
list(): Promise<{
|
|
674
690
|
friends: Username[];
|
|
675
691
|
}>;
|
|
676
|
-
request(username: Username): Promise<
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
692
|
+
request(username: Username): Promise<{
|
|
693
|
+
ok: boolean;
|
|
694
|
+
message?: string;
|
|
695
|
+
error?: string;
|
|
696
|
+
}>;
|
|
697
|
+
accept(username: Username): Promise<{
|
|
698
|
+
ok: boolean;
|
|
699
|
+
message?: string;
|
|
700
|
+
error?: string;
|
|
701
|
+
}>;
|
|
702
|
+
reject(username: Username): Promise<{
|
|
703
|
+
ok: boolean;
|
|
704
|
+
message?: string;
|
|
705
|
+
error?: string;
|
|
706
|
+
}>;
|
|
707
|
+
remove(username: Username): Promise<{
|
|
708
|
+
ok: boolean;
|
|
709
|
+
message?: string;
|
|
710
|
+
error?: string;
|
|
711
|
+
}>;
|
|
712
|
+
cancel(username: Username): Promise<{
|
|
713
|
+
ok: boolean;
|
|
714
|
+
message?: string;
|
|
715
|
+
error?: string;
|
|
716
|
+
}>;
|
|
680
717
|
}
|
|
681
718
|
declare class FollowingNamespace extends Namespace {
|
|
682
|
-
follow(username: Username): Promise<
|
|
683
|
-
|
|
719
|
+
follow(username: Username): Promise<{
|
|
720
|
+
ok: boolean;
|
|
721
|
+
message?: string;
|
|
722
|
+
error?: string;
|
|
723
|
+
}>;
|
|
724
|
+
unfollow(username: Username): Promise<{
|
|
725
|
+
ok: boolean;
|
|
726
|
+
message?: string;
|
|
727
|
+
error?: string;
|
|
728
|
+
}>;
|
|
684
729
|
followers(username: Username): Promise<{
|
|
685
730
|
followers: Username[];
|
|
686
731
|
}>;
|
|
@@ -875,27 +920,6 @@ declare class CosmeticsNamespace extends Namespace {
|
|
|
875
920
|
message: string;
|
|
876
921
|
}>;
|
|
877
922
|
overlays(filepath: string): Promise<Response>;
|
|
878
|
-
/** Admin: List all cosmetics in catalog */
|
|
879
|
-
adminList(options?: {
|
|
880
|
-
type?: string;
|
|
881
|
-
}): Promise<{
|
|
882
|
-
cosmetics: CosmeticCatalogEntryPublic[];
|
|
883
|
-
total: number;
|
|
884
|
-
}>;
|
|
885
|
-
/** Admin: Create a cosmetic */
|
|
886
|
-
adminCreate(data: AdminCosmeticCreate): Promise<{
|
|
887
|
-
message: string;
|
|
888
|
-
cosmetic: CosmeticCatalogEntryPublic;
|
|
889
|
-
}>;
|
|
890
|
-
/** Admin: Update a cosmetic */
|
|
891
|
-
adminUpdate(id: string, data: AdminCosmeticUpdate): Promise<{
|
|
892
|
-
message: string;
|
|
893
|
-
cosmetic: CosmeticCatalogEntryPublic;
|
|
894
|
-
}>;
|
|
895
|
-
/** Admin: Delete a cosmetic */
|
|
896
|
-
adminDelete(id: string): Promise<{
|
|
897
|
-
message: string;
|
|
898
|
-
}>;
|
|
899
923
|
}
|
|
900
924
|
declare class PushNamespace extends Namespace {
|
|
901
925
|
vapidKeys(): Promise<{
|
package/dist/index.d.ts
CHANGED
|
@@ -496,6 +496,7 @@ type WSMessage = {
|
|
|
496
496
|
};
|
|
497
497
|
|
|
498
498
|
type Handler = (msg: any) => void;
|
|
499
|
+
type KeyChangeCallback = (key: string, value: any, oldValue: any) => void;
|
|
499
500
|
declare class RoturSocket extends EventTarget {
|
|
500
501
|
private url;
|
|
501
502
|
private ws;
|
|
@@ -507,11 +508,18 @@ declare class RoturSocket extends EventTarget {
|
|
|
507
508
|
private _username;
|
|
508
509
|
private handlers;
|
|
509
510
|
private rooms;
|
|
511
|
+
private keyCache;
|
|
512
|
+
private keyChangeCallbacks;
|
|
510
513
|
constructor(url?: string);
|
|
511
514
|
get connected(): boolean;
|
|
512
515
|
get userId(): string | null;
|
|
513
516
|
get username(): string | null;
|
|
514
517
|
get joinedRooms(): string[];
|
|
518
|
+
getKey(key: string): any;
|
|
519
|
+
getAllKeys(): Record<string, any>;
|
|
520
|
+
onKeyChange(callback: KeyChangeCallback): () => void;
|
|
521
|
+
offKeyChange(callback: KeyChangeCallback): void;
|
|
522
|
+
private notifyKeyChange;
|
|
515
523
|
connect(token: string): Promise<{
|
|
516
524
|
user_id: UserId;
|
|
517
525
|
username: Username;
|
|
@@ -529,8 +537,7 @@ declare class RoturSocket extends EventTarget {
|
|
|
529
537
|
leave(rooms: string | string[]): void;
|
|
530
538
|
listRooms(): Promise<string[]>;
|
|
531
539
|
roomState(room: string): void;
|
|
532
|
-
|
|
533
|
-
setStatus(status: string): void;
|
|
540
|
+
setStatus(status: string, presence?: Presence): void;
|
|
534
541
|
addActivity(activity: Activity & {
|
|
535
542
|
id: string;
|
|
536
543
|
}): void;
|
|
@@ -579,6 +586,7 @@ declare class Rotur {
|
|
|
579
586
|
get token(): string | null;
|
|
580
587
|
get loggedIn(): boolean;
|
|
581
588
|
setToken(token: string): void;
|
|
589
|
+
private _socketReady;
|
|
582
590
|
login(options?: {
|
|
583
591
|
system?: string;
|
|
584
592
|
timeout?: number;
|
|
@@ -607,6 +615,8 @@ declare class ProfilesNamespace extends Namespace {
|
|
|
607
615
|
subscription: string;
|
|
608
616
|
}>>;
|
|
609
617
|
getAvatarUrl(username: Username, cache?: string): string;
|
|
618
|
+
getOverlayUrl(username: Username, cache?: string): string;
|
|
619
|
+
getBannerUrl(username: Username, cache?: string): string;
|
|
610
620
|
}
|
|
611
621
|
declare class MeNamespace extends Namespace {
|
|
612
622
|
get(): Promise<Record<string, any>>;
|
|
@@ -616,6 +626,9 @@ declare class MeNamespace extends Namespace {
|
|
|
616
626
|
refreshToken(): Promise<{
|
|
617
627
|
token: string;
|
|
618
628
|
}>;
|
|
629
|
+
getKey(key: string): any;
|
|
630
|
+
getAllKeys(): Record<string, any>;
|
|
631
|
+
onKeyChange(callback: (key: string, value: any, oldValue: any) => void): () => void;
|
|
619
632
|
transfer(to: Username, amount: number, note?: string): Promise<any>;
|
|
620
633
|
claimDaily(): Promise<{
|
|
621
634
|
message: string;
|
|
@@ -643,6 +656,9 @@ declare class MeNamespace extends Namespace {
|
|
|
643
656
|
requests(): Promise<{
|
|
644
657
|
requests: Username[];
|
|
645
658
|
}>;
|
|
659
|
+
outgoing(): Promise<{
|
|
660
|
+
outgoing: Username[];
|
|
661
|
+
}>;
|
|
646
662
|
transactions(): Promise<any[]>;
|
|
647
663
|
subscription(): Promise<{
|
|
648
664
|
active: boolean;
|
|
@@ -673,14 +689,43 @@ declare class FriendsNamespace extends Namespace {
|
|
|
673
689
|
list(): Promise<{
|
|
674
690
|
friends: Username[];
|
|
675
691
|
}>;
|
|
676
|
-
request(username: Username): Promise<
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
692
|
+
request(username: Username): Promise<{
|
|
693
|
+
ok: boolean;
|
|
694
|
+
message?: string;
|
|
695
|
+
error?: string;
|
|
696
|
+
}>;
|
|
697
|
+
accept(username: Username): Promise<{
|
|
698
|
+
ok: boolean;
|
|
699
|
+
message?: string;
|
|
700
|
+
error?: string;
|
|
701
|
+
}>;
|
|
702
|
+
reject(username: Username): Promise<{
|
|
703
|
+
ok: boolean;
|
|
704
|
+
message?: string;
|
|
705
|
+
error?: string;
|
|
706
|
+
}>;
|
|
707
|
+
remove(username: Username): Promise<{
|
|
708
|
+
ok: boolean;
|
|
709
|
+
message?: string;
|
|
710
|
+
error?: string;
|
|
711
|
+
}>;
|
|
712
|
+
cancel(username: Username): Promise<{
|
|
713
|
+
ok: boolean;
|
|
714
|
+
message?: string;
|
|
715
|
+
error?: string;
|
|
716
|
+
}>;
|
|
680
717
|
}
|
|
681
718
|
declare class FollowingNamespace extends Namespace {
|
|
682
|
-
follow(username: Username): Promise<
|
|
683
|
-
|
|
719
|
+
follow(username: Username): Promise<{
|
|
720
|
+
ok: boolean;
|
|
721
|
+
message?: string;
|
|
722
|
+
error?: string;
|
|
723
|
+
}>;
|
|
724
|
+
unfollow(username: Username): Promise<{
|
|
725
|
+
ok: boolean;
|
|
726
|
+
message?: string;
|
|
727
|
+
error?: string;
|
|
728
|
+
}>;
|
|
684
729
|
followers(username: Username): Promise<{
|
|
685
730
|
followers: Username[];
|
|
686
731
|
}>;
|
|
@@ -875,27 +920,6 @@ declare class CosmeticsNamespace extends Namespace {
|
|
|
875
920
|
message: string;
|
|
876
921
|
}>;
|
|
877
922
|
overlays(filepath: string): Promise<Response>;
|
|
878
|
-
/** Admin: List all cosmetics in catalog */
|
|
879
|
-
adminList(options?: {
|
|
880
|
-
type?: string;
|
|
881
|
-
}): Promise<{
|
|
882
|
-
cosmetics: CosmeticCatalogEntryPublic[];
|
|
883
|
-
total: number;
|
|
884
|
-
}>;
|
|
885
|
-
/** Admin: Create a cosmetic */
|
|
886
|
-
adminCreate(data: AdminCosmeticCreate): Promise<{
|
|
887
|
-
message: string;
|
|
888
|
-
cosmetic: CosmeticCatalogEntryPublic;
|
|
889
|
-
}>;
|
|
890
|
-
/** Admin: Update a cosmetic */
|
|
891
|
-
adminUpdate(id: string, data: AdminCosmeticUpdate): Promise<{
|
|
892
|
-
message: string;
|
|
893
|
-
cosmetic: CosmeticCatalogEntryPublic;
|
|
894
|
-
}>;
|
|
895
|
-
/** Admin: Delete a cosmetic */
|
|
896
|
-
adminDelete(id: string): Promise<{
|
|
897
|
-
message: string;
|
|
898
|
-
}>;
|
|
899
923
|
}
|
|
900
924
|
declare class PushNamespace extends Namespace {
|
|
901
925
|
vapidKeys(): Promise<{
|
package/dist/index.js
CHANGED
|
@@ -139,6 +139,8 @@ var RoturSocket = class extends EventTarget {
|
|
|
139
139
|
_username = null;
|
|
140
140
|
handlers = /* @__PURE__ */ new Map();
|
|
141
141
|
rooms = /* @__PURE__ */ new Set();
|
|
142
|
+
keyCache = {};
|
|
143
|
+
keyChangeCallbacks = /* @__PURE__ */ new Set();
|
|
142
144
|
get connected() {
|
|
143
145
|
return this._connected;
|
|
144
146
|
}
|
|
@@ -151,6 +153,27 @@ var RoturSocket = class extends EventTarget {
|
|
|
151
153
|
get joinedRooms() {
|
|
152
154
|
return [...this.rooms];
|
|
153
155
|
}
|
|
156
|
+
getKey(key) {
|
|
157
|
+
return this.keyCache[key];
|
|
158
|
+
}
|
|
159
|
+
getAllKeys() {
|
|
160
|
+
return { ...this.keyCache };
|
|
161
|
+
}
|
|
162
|
+
onKeyChange(callback) {
|
|
163
|
+
this.keyChangeCallbacks.add(callback);
|
|
164
|
+
return () => this.keyChangeCallbacks.delete(callback);
|
|
165
|
+
}
|
|
166
|
+
offKeyChange(callback) {
|
|
167
|
+
this.keyChangeCallbacks.delete(callback);
|
|
168
|
+
}
|
|
169
|
+
notifyKeyChange(key, value, oldValue) {
|
|
170
|
+
for (const cb of this.keyChangeCallbacks) {
|
|
171
|
+
try {
|
|
172
|
+
cb(key, value, oldValue);
|
|
173
|
+
} catch {
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
154
177
|
connect(token) {
|
|
155
178
|
this.token = token;
|
|
156
179
|
return new Promise((resolve, reject) => {
|
|
@@ -168,11 +191,19 @@ var RoturSocket = class extends EventTarget {
|
|
|
168
191
|
this._connected = true;
|
|
169
192
|
this._userId = msg.user_id;
|
|
170
193
|
this._username = msg.username;
|
|
194
|
+
if (msg.user && typeof msg.user === "object") {
|
|
195
|
+
this.keyCache = { ...msg.user };
|
|
196
|
+
}
|
|
171
197
|
this.startHeartbeat();
|
|
172
198
|
resolve(msg);
|
|
173
199
|
}
|
|
174
200
|
if (cmd === "join_ok") this.rooms.add(msg.room);
|
|
175
201
|
if (cmd === "leave_ok") this.rooms.delete(msg.room);
|
|
202
|
+
if (cmd === "key_update" && typeof msg.key === "string") {
|
|
203
|
+
const old = this.keyCache[msg.key];
|
|
204
|
+
this.keyCache[msg.key] = msg.value;
|
|
205
|
+
this.notifyKeyChange(msg.key, msg.value, old);
|
|
206
|
+
}
|
|
176
207
|
this.emit(cmd, msg);
|
|
177
208
|
};
|
|
178
209
|
this.ws.onerror = (e) => {
|
|
@@ -248,11 +279,8 @@ var RoturSocket = class extends EventTarget {
|
|
|
248
279
|
roomState(room) {
|
|
249
280
|
this.send({ cmd: "room_state", room });
|
|
250
281
|
}
|
|
251
|
-
|
|
252
|
-
this.send({ cmd: "set_status", presence });
|
|
253
|
-
}
|
|
254
|
-
setStatus(status) {
|
|
255
|
-
this.send({ cmd: "set_status", status });
|
|
282
|
+
setStatus(status, presence) {
|
|
283
|
+
this.send({ cmd: "set_status", status, presence });
|
|
256
284
|
}
|
|
257
285
|
addActivity(activity) {
|
|
258
286
|
this.send({ cmd: "add_activity", ...activity });
|
|
@@ -286,6 +314,7 @@ var RoturSocket = class extends EventTarget {
|
|
|
286
314
|
this.token = null;
|
|
287
315
|
this.cleanup();
|
|
288
316
|
this.rooms.clear();
|
|
317
|
+
this.keyCache = {};
|
|
289
318
|
if (this.ws) {
|
|
290
319
|
this.ws.onclose = null;
|
|
291
320
|
this.ws.close();
|
|
@@ -383,6 +412,9 @@ var Rotur = class {
|
|
|
383
412
|
this._token = options?.token ?? null;
|
|
384
413
|
this._http = new Http(() => this._token);
|
|
385
414
|
this.socket = new RoturSocket(options?.wsUrl);
|
|
415
|
+
if (this._token) {
|
|
416
|
+
this._socketReady = this.socket.connect(this._token).catch(() => null);
|
|
417
|
+
}
|
|
386
418
|
}
|
|
387
419
|
get token() {
|
|
388
420
|
return this._token;
|
|
@@ -392,18 +424,26 @@ var Rotur = class {
|
|
|
392
424
|
}
|
|
393
425
|
setToken(token) {
|
|
394
426
|
this._token = token;
|
|
427
|
+
if (!this.socket.connected) {
|
|
428
|
+
this._socketReady = this.socket.connect(this._token).catch(() => null);
|
|
429
|
+
}
|
|
395
430
|
}
|
|
431
|
+
_socketReady = null;
|
|
396
432
|
async login(options) {
|
|
397
433
|
const { token } = await performAuth(options);
|
|
398
434
|
this._token = token;
|
|
435
|
+
this._socketReady = this.socket.connect(this._token).catch(() => null);
|
|
399
436
|
return this;
|
|
400
437
|
}
|
|
401
438
|
async connectSocket() {
|
|
402
439
|
if (!this._token) throw new ApiError(401, { error: "Login first" });
|
|
403
|
-
|
|
440
|
+
const result = await this.socket.connect(this._token);
|
|
441
|
+
this._socketReady = Promise.resolve(result);
|
|
442
|
+
return result;
|
|
404
443
|
}
|
|
405
444
|
logout() {
|
|
406
445
|
this._token = null;
|
|
446
|
+
this._socketReady = null;
|
|
407
447
|
this.socket.disconnect();
|
|
408
448
|
}
|
|
409
449
|
};
|
|
@@ -442,6 +482,12 @@ var ProfilesNamespace = class extends Namespace {
|
|
|
442
482
|
getAvatarUrl(username, cache = "") {
|
|
443
483
|
return `https://avatars.rotur.dev/${username}?v=${cache}`;
|
|
444
484
|
}
|
|
485
|
+
getOverlayUrl(username, cache = "") {
|
|
486
|
+
return `https://avatars.rotur.dev/.overlay/${username}?v=${cache}`;
|
|
487
|
+
}
|
|
488
|
+
getBannerUrl(username, cache = "") {
|
|
489
|
+
return `https://avatars.rotur.dev/.banners/${username}?v=${cache}`;
|
|
490
|
+
}
|
|
445
491
|
};
|
|
446
492
|
var MeNamespace = class extends Namespace {
|
|
447
493
|
async get() {
|
|
@@ -459,6 +505,15 @@ var MeNamespace = class extends Namespace {
|
|
|
459
505
|
async refreshToken() {
|
|
460
506
|
return this.$post("/me/refresh_token");
|
|
461
507
|
}
|
|
508
|
+
getKey(key) {
|
|
509
|
+
return this.r.socket.getKey(key);
|
|
510
|
+
}
|
|
511
|
+
getAllKeys() {
|
|
512
|
+
return this.r.socket.getAllKeys();
|
|
513
|
+
}
|
|
514
|
+
onKeyChange(callback) {
|
|
515
|
+
return this.r.socket.onKeyChange(callback);
|
|
516
|
+
}
|
|
462
517
|
async transfer(to, amount, note) {
|
|
463
518
|
return this.$post("/me/transfer", { to, amount, note });
|
|
464
519
|
}
|
|
@@ -502,8 +557,13 @@ var MeNamespace = class extends Namespace {
|
|
|
502
557
|
return this.$get("/check_auth");
|
|
503
558
|
}
|
|
504
559
|
async requests() {
|
|
505
|
-
return this.$get("/
|
|
506
|
-
requests: u
|
|
560
|
+
return this.$get("/requests", void 0).then((u) => ({
|
|
561
|
+
requests: u.requests ?? []
|
|
562
|
+
}));
|
|
563
|
+
}
|
|
564
|
+
async outgoing() {
|
|
565
|
+
return this.$get("/requests_out", void 0).then((u) => ({
|
|
566
|
+
outgoing: u.requests_out ?? []
|
|
507
567
|
}));
|
|
508
568
|
}
|
|
509
569
|
async transactions() {
|
|
@@ -558,29 +618,43 @@ var PostsNamespace = class extends Namespace {
|
|
|
558
618
|
return this.$get("/limits", void 0, false);
|
|
559
619
|
}
|
|
560
620
|
};
|
|
621
|
+
function handleMessageOrError(res) {
|
|
622
|
+
return res.then((r) => {
|
|
623
|
+
if (r.ok) {
|
|
624
|
+
return { ok: true };
|
|
625
|
+
} else if (r.error) {
|
|
626
|
+
return { ok: false, error: r.error };
|
|
627
|
+
} else {
|
|
628
|
+
return { ok: false, message: r.message };
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
}
|
|
561
632
|
var FriendsNamespace = class extends Namespace {
|
|
562
633
|
async list() {
|
|
563
634
|
return this.$get("/friends");
|
|
564
635
|
}
|
|
565
636
|
async request(username) {
|
|
566
|
-
return this.$post(`/friends/request/${username}`);
|
|
637
|
+
return handleMessageOrError(this.$post(`/friends/request/${username}`));
|
|
567
638
|
}
|
|
568
639
|
async accept(username) {
|
|
569
|
-
return this.$post(`/friends/accept/${username}`);
|
|
640
|
+
return handleMessageOrError(this.$post(`/friends/accept/${username}`));
|
|
570
641
|
}
|
|
571
642
|
async reject(username) {
|
|
572
|
-
return this.$post(`/friends/reject/${username}`);
|
|
643
|
+
return handleMessageOrError(this.$post(`/friends/reject/${username}`));
|
|
573
644
|
}
|
|
574
645
|
async remove(username) {
|
|
575
|
-
return this.$post(`/friends/remove/${username}`);
|
|
646
|
+
return handleMessageOrError(this.$post(`/friends/remove/${username}`));
|
|
647
|
+
}
|
|
648
|
+
async cancel(username) {
|
|
649
|
+
return handleMessageOrError(this.$post(`/friends/cancel/${username}`));
|
|
576
650
|
}
|
|
577
651
|
};
|
|
578
652
|
var FollowingNamespace = class extends Namespace {
|
|
579
653
|
async follow(username) {
|
|
580
|
-
return this.$get("/follow", { username });
|
|
654
|
+
return handleMessageOrError(this.$get("/follow", { username }));
|
|
581
655
|
}
|
|
582
656
|
async unfollow(username) {
|
|
583
|
-
return this.$get("/unfollow", { username });
|
|
657
|
+
return handleMessageOrError(this.$get("/unfollow", { username }));
|
|
584
658
|
}
|
|
585
659
|
async followers(username) {
|
|
586
660
|
return this.$get("/followers", { username }, false);
|
|
@@ -932,22 +1006,6 @@ var CosmeticsNamespace = class extends Namespace {
|
|
|
932
1006
|
async overlays(filepath) {
|
|
933
1007
|
return this.$get(`/cosmetics/overlays/${filepath}`, void 0, false);
|
|
934
1008
|
}
|
|
935
|
-
/** Admin: List all cosmetics in catalog */
|
|
936
|
-
async adminList(options) {
|
|
937
|
-
return this.$get("/cosmetics/admin/list", options, true);
|
|
938
|
-
}
|
|
939
|
-
/** Admin: Create a cosmetic */
|
|
940
|
-
async adminCreate(data) {
|
|
941
|
-
return this.$post("/cosmetics/admin/create", data);
|
|
942
|
-
}
|
|
943
|
-
/** Admin: Update a cosmetic */
|
|
944
|
-
async adminUpdate(id, data) {
|
|
945
|
-
return this.$patch(`/cosmetics/admin/update/${id}`, data);
|
|
946
|
-
}
|
|
947
|
-
/** Admin: Delete a cosmetic */
|
|
948
|
-
async adminDelete(id) {
|
|
949
|
-
return this.$del(`/cosmetics/admin/delete/${id}`);
|
|
950
|
-
}
|
|
951
1009
|
};
|
|
952
1010
|
var PushNamespace = class extends Namespace {
|
|
953
1011
|
async vapidKeys() {
|
package/dist/index.mjs
CHANGED
|
@@ -109,6 +109,8 @@ var RoturSocket = class extends EventTarget {
|
|
|
109
109
|
_username = null;
|
|
110
110
|
handlers = /* @__PURE__ */ new Map();
|
|
111
111
|
rooms = /* @__PURE__ */ new Set();
|
|
112
|
+
keyCache = {};
|
|
113
|
+
keyChangeCallbacks = /* @__PURE__ */ new Set();
|
|
112
114
|
get connected() {
|
|
113
115
|
return this._connected;
|
|
114
116
|
}
|
|
@@ -121,6 +123,27 @@ var RoturSocket = class extends EventTarget {
|
|
|
121
123
|
get joinedRooms() {
|
|
122
124
|
return [...this.rooms];
|
|
123
125
|
}
|
|
126
|
+
getKey(key) {
|
|
127
|
+
return this.keyCache[key];
|
|
128
|
+
}
|
|
129
|
+
getAllKeys() {
|
|
130
|
+
return { ...this.keyCache };
|
|
131
|
+
}
|
|
132
|
+
onKeyChange(callback) {
|
|
133
|
+
this.keyChangeCallbacks.add(callback);
|
|
134
|
+
return () => this.keyChangeCallbacks.delete(callback);
|
|
135
|
+
}
|
|
136
|
+
offKeyChange(callback) {
|
|
137
|
+
this.keyChangeCallbacks.delete(callback);
|
|
138
|
+
}
|
|
139
|
+
notifyKeyChange(key, value, oldValue) {
|
|
140
|
+
for (const cb of this.keyChangeCallbacks) {
|
|
141
|
+
try {
|
|
142
|
+
cb(key, value, oldValue);
|
|
143
|
+
} catch {
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
124
147
|
connect(token) {
|
|
125
148
|
this.token = token;
|
|
126
149
|
return new Promise((resolve, reject) => {
|
|
@@ -138,11 +161,19 @@ var RoturSocket = class extends EventTarget {
|
|
|
138
161
|
this._connected = true;
|
|
139
162
|
this._userId = msg.user_id;
|
|
140
163
|
this._username = msg.username;
|
|
164
|
+
if (msg.user && typeof msg.user === "object") {
|
|
165
|
+
this.keyCache = { ...msg.user };
|
|
166
|
+
}
|
|
141
167
|
this.startHeartbeat();
|
|
142
168
|
resolve(msg);
|
|
143
169
|
}
|
|
144
170
|
if (cmd === "join_ok") this.rooms.add(msg.room);
|
|
145
171
|
if (cmd === "leave_ok") this.rooms.delete(msg.room);
|
|
172
|
+
if (cmd === "key_update" && typeof msg.key === "string") {
|
|
173
|
+
const old = this.keyCache[msg.key];
|
|
174
|
+
this.keyCache[msg.key] = msg.value;
|
|
175
|
+
this.notifyKeyChange(msg.key, msg.value, old);
|
|
176
|
+
}
|
|
146
177
|
this.emit(cmd, msg);
|
|
147
178
|
};
|
|
148
179
|
this.ws.onerror = (e) => {
|
|
@@ -218,11 +249,8 @@ var RoturSocket = class extends EventTarget {
|
|
|
218
249
|
roomState(room) {
|
|
219
250
|
this.send({ cmd: "room_state", room });
|
|
220
251
|
}
|
|
221
|
-
|
|
222
|
-
this.send({ cmd: "set_status", presence });
|
|
223
|
-
}
|
|
224
|
-
setStatus(status) {
|
|
225
|
-
this.send({ cmd: "set_status", status });
|
|
252
|
+
setStatus(status, presence) {
|
|
253
|
+
this.send({ cmd: "set_status", status, presence });
|
|
226
254
|
}
|
|
227
255
|
addActivity(activity) {
|
|
228
256
|
this.send({ cmd: "add_activity", ...activity });
|
|
@@ -256,6 +284,7 @@ var RoturSocket = class extends EventTarget {
|
|
|
256
284
|
this.token = null;
|
|
257
285
|
this.cleanup();
|
|
258
286
|
this.rooms.clear();
|
|
287
|
+
this.keyCache = {};
|
|
259
288
|
if (this.ws) {
|
|
260
289
|
this.ws.onclose = null;
|
|
261
290
|
this.ws.close();
|
|
@@ -353,6 +382,9 @@ var Rotur = class {
|
|
|
353
382
|
this._token = options?.token ?? null;
|
|
354
383
|
this._http = new Http(() => this._token);
|
|
355
384
|
this.socket = new RoturSocket(options?.wsUrl);
|
|
385
|
+
if (this._token) {
|
|
386
|
+
this._socketReady = this.socket.connect(this._token).catch(() => null);
|
|
387
|
+
}
|
|
356
388
|
}
|
|
357
389
|
get token() {
|
|
358
390
|
return this._token;
|
|
@@ -362,18 +394,26 @@ var Rotur = class {
|
|
|
362
394
|
}
|
|
363
395
|
setToken(token) {
|
|
364
396
|
this._token = token;
|
|
397
|
+
if (!this.socket.connected) {
|
|
398
|
+
this._socketReady = this.socket.connect(this._token).catch(() => null);
|
|
399
|
+
}
|
|
365
400
|
}
|
|
401
|
+
_socketReady = null;
|
|
366
402
|
async login(options) {
|
|
367
403
|
const { token } = await performAuth(options);
|
|
368
404
|
this._token = token;
|
|
405
|
+
this._socketReady = this.socket.connect(this._token).catch(() => null);
|
|
369
406
|
return this;
|
|
370
407
|
}
|
|
371
408
|
async connectSocket() {
|
|
372
409
|
if (!this._token) throw new ApiError(401, { error: "Login first" });
|
|
373
|
-
|
|
410
|
+
const result = await this.socket.connect(this._token);
|
|
411
|
+
this._socketReady = Promise.resolve(result);
|
|
412
|
+
return result;
|
|
374
413
|
}
|
|
375
414
|
logout() {
|
|
376
415
|
this._token = null;
|
|
416
|
+
this._socketReady = null;
|
|
377
417
|
this.socket.disconnect();
|
|
378
418
|
}
|
|
379
419
|
};
|
|
@@ -412,6 +452,12 @@ var ProfilesNamespace = class extends Namespace {
|
|
|
412
452
|
getAvatarUrl(username, cache = "") {
|
|
413
453
|
return `https://avatars.rotur.dev/${username}?v=${cache}`;
|
|
414
454
|
}
|
|
455
|
+
getOverlayUrl(username, cache = "") {
|
|
456
|
+
return `https://avatars.rotur.dev/.overlay/${username}?v=${cache}`;
|
|
457
|
+
}
|
|
458
|
+
getBannerUrl(username, cache = "") {
|
|
459
|
+
return `https://avatars.rotur.dev/.banners/${username}?v=${cache}`;
|
|
460
|
+
}
|
|
415
461
|
};
|
|
416
462
|
var MeNamespace = class extends Namespace {
|
|
417
463
|
async get() {
|
|
@@ -429,6 +475,15 @@ var MeNamespace = class extends Namespace {
|
|
|
429
475
|
async refreshToken() {
|
|
430
476
|
return this.$post("/me/refresh_token");
|
|
431
477
|
}
|
|
478
|
+
getKey(key) {
|
|
479
|
+
return this.r.socket.getKey(key);
|
|
480
|
+
}
|
|
481
|
+
getAllKeys() {
|
|
482
|
+
return this.r.socket.getAllKeys();
|
|
483
|
+
}
|
|
484
|
+
onKeyChange(callback) {
|
|
485
|
+
return this.r.socket.onKeyChange(callback);
|
|
486
|
+
}
|
|
432
487
|
async transfer(to, amount, note) {
|
|
433
488
|
return this.$post("/me/transfer", { to, amount, note });
|
|
434
489
|
}
|
|
@@ -472,8 +527,13 @@ var MeNamespace = class extends Namespace {
|
|
|
472
527
|
return this.$get("/check_auth");
|
|
473
528
|
}
|
|
474
529
|
async requests() {
|
|
475
|
-
return this.$get("/
|
|
476
|
-
requests: u
|
|
530
|
+
return this.$get("/requests", void 0).then((u) => ({
|
|
531
|
+
requests: u.requests ?? []
|
|
532
|
+
}));
|
|
533
|
+
}
|
|
534
|
+
async outgoing() {
|
|
535
|
+
return this.$get("/requests_out", void 0).then((u) => ({
|
|
536
|
+
outgoing: u.requests_out ?? []
|
|
477
537
|
}));
|
|
478
538
|
}
|
|
479
539
|
async transactions() {
|
|
@@ -528,29 +588,43 @@ var PostsNamespace = class extends Namespace {
|
|
|
528
588
|
return this.$get("/limits", void 0, false);
|
|
529
589
|
}
|
|
530
590
|
};
|
|
591
|
+
function handleMessageOrError(res) {
|
|
592
|
+
return res.then((r) => {
|
|
593
|
+
if (r.ok) {
|
|
594
|
+
return { ok: true };
|
|
595
|
+
} else if (r.error) {
|
|
596
|
+
return { ok: false, error: r.error };
|
|
597
|
+
} else {
|
|
598
|
+
return { ok: false, message: r.message };
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
}
|
|
531
602
|
var FriendsNamespace = class extends Namespace {
|
|
532
603
|
async list() {
|
|
533
604
|
return this.$get("/friends");
|
|
534
605
|
}
|
|
535
606
|
async request(username) {
|
|
536
|
-
return this.$post(`/friends/request/${username}`);
|
|
607
|
+
return handleMessageOrError(this.$post(`/friends/request/${username}`));
|
|
537
608
|
}
|
|
538
609
|
async accept(username) {
|
|
539
|
-
return this.$post(`/friends/accept/${username}`);
|
|
610
|
+
return handleMessageOrError(this.$post(`/friends/accept/${username}`));
|
|
540
611
|
}
|
|
541
612
|
async reject(username) {
|
|
542
|
-
return this.$post(`/friends/reject/${username}`);
|
|
613
|
+
return handleMessageOrError(this.$post(`/friends/reject/${username}`));
|
|
543
614
|
}
|
|
544
615
|
async remove(username) {
|
|
545
|
-
return this.$post(`/friends/remove/${username}`);
|
|
616
|
+
return handleMessageOrError(this.$post(`/friends/remove/${username}`));
|
|
617
|
+
}
|
|
618
|
+
async cancel(username) {
|
|
619
|
+
return handleMessageOrError(this.$post(`/friends/cancel/${username}`));
|
|
546
620
|
}
|
|
547
621
|
};
|
|
548
622
|
var FollowingNamespace = class extends Namespace {
|
|
549
623
|
async follow(username) {
|
|
550
|
-
return this.$get("/follow", { username });
|
|
624
|
+
return handleMessageOrError(this.$get("/follow", { username }));
|
|
551
625
|
}
|
|
552
626
|
async unfollow(username) {
|
|
553
|
-
return this.$get("/unfollow", { username });
|
|
627
|
+
return handleMessageOrError(this.$get("/unfollow", { username }));
|
|
554
628
|
}
|
|
555
629
|
async followers(username) {
|
|
556
630
|
return this.$get("/followers", { username }, false);
|
|
@@ -902,22 +976,6 @@ var CosmeticsNamespace = class extends Namespace {
|
|
|
902
976
|
async overlays(filepath) {
|
|
903
977
|
return this.$get(`/cosmetics/overlays/${filepath}`, void 0, false);
|
|
904
978
|
}
|
|
905
|
-
/** Admin: List all cosmetics in catalog */
|
|
906
|
-
async adminList(options) {
|
|
907
|
-
return this.$get("/cosmetics/admin/list", options, true);
|
|
908
|
-
}
|
|
909
|
-
/** Admin: Create a cosmetic */
|
|
910
|
-
async adminCreate(data) {
|
|
911
|
-
return this.$post("/cosmetics/admin/create", data);
|
|
912
|
-
}
|
|
913
|
-
/** Admin: Update a cosmetic */
|
|
914
|
-
async adminUpdate(id, data) {
|
|
915
|
-
return this.$patch(`/cosmetics/admin/update/${id}`, data);
|
|
916
|
-
}
|
|
917
|
-
/** Admin: Delete a cosmetic */
|
|
918
|
-
async adminDelete(id) {
|
|
919
|
-
return this.$del(`/cosmetics/admin/delete/${id}`);
|
|
920
|
-
}
|
|
921
979
|
};
|
|
922
980
|
var PushNamespace = class extends Namespace {
|
|
923
981
|
async vapidKeys() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rotur-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "The official SDK for the Rotur platform - auth, profiles, posts, credits, keys, groups, items, gifts, tokens, validators, status, files, cosmetics, push notifications, and more",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|