sidechat.js 2.0.6 → 2.2.0
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/classes/SidechatAPIClient.d.ts +57 -1
- package/dist/classes/SidechatAPIClient.d.ts.map +1 -1
- package/dist/index.cjs +190 -1
- package/dist/index.mjs +190 -1
- package/dist/types/SidechatTypes.d.ts +54 -7
- package/dist/types/SidechatTypes.d.ts.map +1 -1
- package/docs/sidechat.js/2.1.0/SidechatAPIClient.html +3 -0
- package/docs/sidechat.js/2.1.0/SidechatAPIError.html +3 -0
- package/docs/sidechat.js/2.1.0/classes_SidechatAPIClient.js.html +528 -0
- package/docs/sidechat.js/2.1.0/classes_SidechatAPIError.js.html +16 -0
- package/docs/sidechat.js/2.1.0/data/search.json +1 -0
- package/docs/sidechat.js/2.1.0/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/sidechat.js/2.1.0/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/sidechat.js/2.1.0/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/sidechat.js/2.1.0/global.html +3 -0
- package/docs/sidechat.js/2.1.0/index.html +4 -0
- package/docs/sidechat.js/2.1.0/scripts/core.js +702 -0
- package/docs/sidechat.js/2.1.0/scripts/core.min.js +23 -0
- package/docs/sidechat.js/2.1.0/scripts/resize.js +90 -0
- package/docs/sidechat.js/2.1.0/scripts/search.js +265 -0
- package/docs/sidechat.js/2.1.0/scripts/search.min.js +6 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/fuse.js +9 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/hljs-original.js +5171 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/hljs.js +1 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/popper.js +5 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/tippy.js +1 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/tocbot.js +672 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/tocbot.min.js +1 -0
- package/docs/sidechat.js/2.1.0/styles/clean-jsdoc-theme-base.css +975 -0
- package/docs/sidechat.js/2.1.0/styles/clean-jsdoc-theme-dark.css +407 -0
- package/docs/sidechat.js/2.1.0/styles/clean-jsdoc-theme-light.css +388 -0
- package/docs/sidechat.js/2.1.0/styles/clean-jsdoc-theme.min.css +1 -0
- package/docs/sidechat.js/2.1.0/tutorial-Authentication.html +13 -0
- package/docs/sidechat.js/2.1.0/tutorial-Email Registration.html +6 -0
- package/docs/sidechat.js/2.1.0/types_SidechatTypes.js.html +134 -0
- package/docs/sidechat.js/2.2.0/SidechatAPIClient.html +3 -0
- package/docs/sidechat.js/2.2.0/SidechatAPIError.html +3 -0
- package/docs/sidechat.js/2.2.0/classes_SidechatAPIClient.js.html +651 -0
- package/docs/sidechat.js/2.2.0/classes_SidechatAPIError.js.html +16 -0
- package/docs/sidechat.js/2.2.0/data/search.json +1 -0
- package/docs/sidechat.js/2.2.0/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/sidechat.js/2.2.0/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/sidechat.js/2.2.0/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/sidechat.js/2.2.0/global.html +3 -0
- package/docs/sidechat.js/2.2.0/index.html +4 -0
- package/docs/sidechat.js/2.2.0/scripts/core.js +702 -0
- package/docs/sidechat.js/2.2.0/scripts/core.min.js +23 -0
- package/docs/sidechat.js/2.2.0/scripts/resize.js +90 -0
- package/docs/sidechat.js/2.2.0/scripts/search.js +265 -0
- package/docs/sidechat.js/2.2.0/scripts/search.min.js +6 -0
- package/docs/sidechat.js/2.2.0/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/sidechat.js/2.2.0/scripts/third-party/fuse.js +9 -0
- package/docs/sidechat.js/2.2.0/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/sidechat.js/2.2.0/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/sidechat.js/2.2.0/scripts/third-party/hljs-original.js +5171 -0
- package/docs/sidechat.js/2.2.0/scripts/third-party/hljs.js +1 -0
- package/docs/sidechat.js/2.2.0/scripts/third-party/popper.js +5 -0
- package/docs/sidechat.js/2.2.0/scripts/third-party/tippy.js +1 -0
- package/docs/sidechat.js/2.2.0/scripts/third-party/tocbot.js +672 -0
- package/docs/sidechat.js/2.2.0/scripts/third-party/tocbot.min.js +1 -0
- package/docs/sidechat.js/2.2.0/styles/clean-jsdoc-theme-base.css +975 -0
- package/docs/sidechat.js/2.2.0/styles/clean-jsdoc-theme-dark.css +407 -0
- package/docs/sidechat.js/2.2.0/styles/clean-jsdoc-theme-light.css +388 -0
- package/docs/sidechat.js/2.2.0/styles/clean-jsdoc-theme.min.css +1 -0
- package/docs/sidechat.js/2.2.0/tutorial-Authentication.html +14 -0
- package/docs/sidechat.js/2.2.0/tutorial-Email Registration.html +6 -0
- package/docs/sidechat.js/2.2.0/types_SidechatTypes.js.html +134 -0
- package/docs/tutorials/Authentication.md +8 -1
- package/package.json +1 -1
- package/src/classes/SidechatAPIClient.js +190 -1
- package/src/tests/{basicTest.js → logInTest.js} +2 -2
- package/src/tests/postTest.js +47 -0
- package/src/types/SidechatTypes.js +27 -7
|
@@ -19,6 +19,7 @@ declare class SidechatAPIClient {
|
|
|
19
19
|
* Default headers for every API request
|
|
20
20
|
* @type {Object}
|
|
21
21
|
* @static
|
|
22
|
+
* @constant
|
|
22
23
|
*/
|
|
23
24
|
defaultHeaders: any;
|
|
24
25
|
/**
|
|
@@ -75,9 +76,17 @@ declare class SidechatAPIClient {
|
|
|
75
76
|
* Get updated status for user and group
|
|
76
77
|
* @method
|
|
77
78
|
* @since 1.0.0
|
|
78
|
-
* @
|
|
79
|
+
* @deprecated since 2.1.0, will be removed by 3.0.0. Please use `getUpdates` instead!
|
|
80
|
+
* @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
|
|
79
81
|
*/
|
|
80
82
|
getUserAndGroup: (groupID?: string) => Promise<any>;
|
|
83
|
+
/**
|
|
84
|
+
* Get updated status for user and group
|
|
85
|
+
* @method
|
|
86
|
+
* @since 2.1.0
|
|
87
|
+
* @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
|
|
88
|
+
*/
|
|
89
|
+
getUpdates: (groupID?: string) => Promise<any>;
|
|
81
90
|
/**
|
|
82
91
|
* Fetches posts from the specified category in a group
|
|
83
92
|
* @method
|
|
@@ -118,5 +127,52 @@ declare class SidechatAPIClient {
|
|
|
118
127
|
* @returns {SidechatLibraryAsset[]}
|
|
119
128
|
*/
|
|
120
129
|
getAssetLibrary: () => SidechatLibraryAsset[];
|
|
130
|
+
/**
|
|
131
|
+
* Gets the current authenticated user and a list of the groups of which they are members.
|
|
132
|
+
* @method
|
|
133
|
+
* @since 2.1.0
|
|
134
|
+
* @returns {SidechatCurrentUser}
|
|
135
|
+
*/
|
|
136
|
+
getCurrentUser: () => SidechatCurrentUser;
|
|
137
|
+
/**
|
|
138
|
+
* Gets the metadata of a group from its ID
|
|
139
|
+
* @method
|
|
140
|
+
* @since 2.1.0
|
|
141
|
+
* @param {String} [groupID] - alphanumeric ID of a group to get. Falls back to user's primary group.
|
|
142
|
+
* @returns {SidechatGroup}
|
|
143
|
+
*/
|
|
144
|
+
getGroupMetadata: (groupID?: string) => SidechatGroup;
|
|
145
|
+
/**
|
|
146
|
+
* Creates a comment on a post
|
|
147
|
+
* @method
|
|
148
|
+
* @since 2.2.0
|
|
149
|
+
* @param {String} parentPostID - alphanumeric ID of post on which this comment is made
|
|
150
|
+
* @param {String} text - text content of comment
|
|
151
|
+
* @param {String} groupID - alphanumeric ID of group in which the parent post resides
|
|
152
|
+
* @param {String} [replyCommentID] - alphanumeric ID of comment to reply to. Falls back to parentPostID
|
|
153
|
+
* @param {SidechatSimpleAsset[]} [assetList] - list of assets to attach
|
|
154
|
+
* @param {Boolean} [disableDMs] - prevent direct messages being sent to comment's author
|
|
155
|
+
* @returns {SidechatPostOrComment} created comment
|
|
156
|
+
*/
|
|
157
|
+
createComment: (parentPostID: string, text: string, groupID: string, replyCommentID?: string, assetList?: SidechatSimpleAsset[], disableDMs?: boolean) => SidechatPostOrComment;
|
|
158
|
+
/**
|
|
159
|
+
* Creates a new post in the specified group
|
|
160
|
+
* @method
|
|
161
|
+
* @since 2.2.0
|
|
162
|
+
* @param {String} text - text content of comment
|
|
163
|
+
* @param {String} groupID - alphanumeric ID of group in which the parent post resides
|
|
164
|
+
* @param {SidechatSimpleAsset[]} [assetList] - list of assets to attach.
|
|
165
|
+
* @param {Boolean} [disableDMs] - prevent direct messages from being sent to post's author
|
|
166
|
+
* @param {Boolean} [disableComments] - whether or not comments should be disabled on post
|
|
167
|
+
* @returns {SidechatPostOrComment} the created post
|
|
168
|
+
*/
|
|
169
|
+
createPost: (text: string, groupID: string, assetList?: SidechatSimpleAsset[], disableDMs?: boolean, disableComments?: boolean) => SidechatPostOrComment;
|
|
170
|
+
/**
|
|
171
|
+
* Deletes a post or comment that the user created
|
|
172
|
+
* @method
|
|
173
|
+
* @since 2.2.0
|
|
174
|
+
* @param {String} postOrCommentID - alphanumeric ID of the post to delete
|
|
175
|
+
*/
|
|
176
|
+
deletePostOrComment: (postOrCommentID: string) => Promise<any>;
|
|
121
177
|
}
|
|
122
178
|
//# sourceMappingURL=SidechatAPIClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SidechatAPIClient.d.ts","sourceRoot":"","sources":["../../src/classes/SidechatAPIClient.js"],"names":[],"mappings":";AAGA;;;;GAIG;AACH;
|
|
1
|
+
{"version":3,"file":"SidechatAPIClient.d.ts","sourceRoot":"","sources":["../../src/classes/SidechatAPIClient.js"],"names":[],"mappings":";AAGA;;;;GAIG;AACH;IAiBE;;;OAGG;IACH,uCAIC;IAxBD;;;SAGK;IACL,6BAAU;IACV;;;;;OAKG;IACH,oBAGE;IAYF;;;;OAIG;IACH,6CAEE;IAEF;;;;;OAKG;IACH,mDAgBE;IAEF;;;;;;OAMG;IACH,mEAsBE;IAEF;;;;;;OAMG;IACH,8DAyBE;IAEF;;;;;;OAMG;IACH,+CA2BE;IAEF;;;;OAIG;IACH,2CAyBE;IAEF;;;;;OAKG;IACH,6CA2BE;IAEF;;;;;;OAMG;IACH,oDAGE;IAEF;;;;;OAKG;IACH,+CAqBE;IAEF;;;;;;;;OAQG;IACH,4CAJW,KAAK,GAAC,QAAQ,GAAC,KAAK,2DA2B7B;IAEF;;;;;;OAMG;IACH,sEAsBE;IAEF;;;;;;OAMG;IACH,qCAFa,uBAAuB,CAqElC;IAEF;;;;;OAKG;IACH,0BAFa,eAAe,CAoB1B;IAEF;;;;;OAKG;IACH,uBAFa,sBAAsB,CAoBjC;IAEF;;;;;OAKG;IACH,0CAkBE;IAEF;;;;;;OAMG;IACH,sDAkBE;IAEF;;;;;;;;;;;OAWG;IACH,0GAJW,qBAAqB,iDAsC9B;IAEF;;;;;;;;;;OAUG;IACH,wDALW,qBAAqB,4EAsC9B;IAEF;;;;;OAKG;IACH,+DAqBE;CACH"}
|
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ class SidechatAPIClient {
|
|
|
29
29
|
* Default headers for every API request
|
|
30
30
|
* @type {Object}
|
|
31
31
|
* @static
|
|
32
|
+
* @constant
|
|
32
33
|
*/
|
|
33
34
|
defaultHeaders = {
|
|
34
35
|
Accept: "application/json",
|
|
@@ -250,9 +251,21 @@ class SidechatAPIClient {
|
|
|
250
251
|
* Get updated status for user and group
|
|
251
252
|
* @method
|
|
252
253
|
* @since 1.0.0
|
|
253
|
-
* @
|
|
254
|
+
* @deprecated since 2.1.0, will be removed by 3.0.0. Please use `getUpdates` instead!
|
|
255
|
+
* @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
|
|
254
256
|
*/
|
|
255
257
|
getUserAndGroup = async (groupID = "") => {
|
|
258
|
+
const json = await this.getUpdates(groupID);
|
|
259
|
+
return json;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Get updated status for user and group
|
|
264
|
+
* @method
|
|
265
|
+
* @since 2.1.0
|
|
266
|
+
* @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
|
|
267
|
+
*/
|
|
268
|
+
getUpdates = async (groupID = "") => {
|
|
256
269
|
if (!this.userToken) {
|
|
257
270
|
throw new SidechatAPIError("User is not authenticated.");
|
|
258
271
|
}
|
|
@@ -467,6 +480,182 @@ class SidechatAPIClient {
|
|
|
467
480
|
throw new SidechatAPIError(`Failed to get asset library.`);
|
|
468
481
|
}
|
|
469
482
|
};
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Gets the current authenticated user and a list of the groups of which they are members.
|
|
486
|
+
* @method
|
|
487
|
+
* @since 2.1.0
|
|
488
|
+
* @returns {SidechatCurrentUser}
|
|
489
|
+
*/
|
|
490
|
+
getCurrentUser = async () => {
|
|
491
|
+
if (!this.userToken) {
|
|
492
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
493
|
+
}
|
|
494
|
+
try {
|
|
495
|
+
const res = await fetch(`https://api.sidechat.lol/v1/users/me`, {
|
|
496
|
+
method: "GET",
|
|
497
|
+
headers: {
|
|
498
|
+
...this.defaultHeaders,
|
|
499
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
500
|
+
},
|
|
501
|
+
});
|
|
502
|
+
const json = await res.json();
|
|
503
|
+
return await json;
|
|
504
|
+
} catch (err) {
|
|
505
|
+
console.error(err);
|
|
506
|
+
throw new SidechatAPIError(`Failed to get asset library.`);
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Gets the metadata of a group from its ID
|
|
512
|
+
* @method
|
|
513
|
+
* @since 2.1.0
|
|
514
|
+
* @param {String} [groupID] - alphanumeric ID of a group to get. Falls back to user's primary group.
|
|
515
|
+
* @returns {SidechatGroup}
|
|
516
|
+
*/
|
|
517
|
+
getGroupMetadata = async (groupID = "") => {
|
|
518
|
+
if (!this.userToken) {
|
|
519
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
520
|
+
}
|
|
521
|
+
try {
|
|
522
|
+
const res = await fetch(`https://api.sidechat.lol/v1/groups/${groupID}`, {
|
|
523
|
+
method: "GET",
|
|
524
|
+
headers: {
|
|
525
|
+
...this.defaultHeaders,
|
|
526
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
527
|
+
},
|
|
528
|
+
});
|
|
529
|
+
const json = await res.json();
|
|
530
|
+
return await json.group;
|
|
531
|
+
} catch (err) {
|
|
532
|
+
console.error(err);
|
|
533
|
+
throw new SidechatAPIError(`Failed to get group metadata.`);
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Creates a comment on a post
|
|
539
|
+
* @method
|
|
540
|
+
* @since 2.2.0
|
|
541
|
+
* @param {String} parentPostID - alphanumeric ID of post on which this comment is made
|
|
542
|
+
* @param {String} text - text content of comment
|
|
543
|
+
* @param {String} groupID - alphanumeric ID of group in which the parent post resides
|
|
544
|
+
* @param {String} [replyCommentID] - alphanumeric ID of comment to reply to. Falls back to parentPostID
|
|
545
|
+
* @param {SidechatSimpleAsset[]} [assetList] - list of assets to attach
|
|
546
|
+
* @param {Boolean} [disableDMs] - prevent direct messages being sent to comment's author
|
|
547
|
+
* @returns {SidechatPostOrComment} created comment
|
|
548
|
+
*/
|
|
549
|
+
createComment = async (
|
|
550
|
+
parentPostID,
|
|
551
|
+
text,
|
|
552
|
+
groupID,
|
|
553
|
+
replyCommentID = parentPostID,
|
|
554
|
+
assetList = [],
|
|
555
|
+
disableDMs = false
|
|
556
|
+
) => {
|
|
557
|
+
if (!this.userToken) {
|
|
558
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
559
|
+
}
|
|
560
|
+
try {
|
|
561
|
+
const res = await fetch(`https://api.sidechat.lol/v1/posts`, {
|
|
562
|
+
method: "POST",
|
|
563
|
+
headers: {
|
|
564
|
+
...this.defaultHeaders,
|
|
565
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
566
|
+
},
|
|
567
|
+
body: JSON.stringify({
|
|
568
|
+
type: "comment",
|
|
569
|
+
assets: assetList,
|
|
570
|
+
group_ids: [groupID],
|
|
571
|
+
text: text,
|
|
572
|
+
reply_post_id: replyCommentID,
|
|
573
|
+
parent_post_id: parentPostID,
|
|
574
|
+
dms_disabled: disableDMs,
|
|
575
|
+
}),
|
|
576
|
+
});
|
|
577
|
+
const json = await res.json();
|
|
578
|
+
return await json.comment;
|
|
579
|
+
} catch (err) {
|
|
580
|
+
console.error(err);
|
|
581
|
+
throw new SidechatAPIError(`Failed to post comment.`);
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Creates a new post in the specified group
|
|
587
|
+
* @method
|
|
588
|
+
* @since 2.2.0
|
|
589
|
+
* @param {String} text - text content of comment
|
|
590
|
+
* @param {String} groupID - alphanumeric ID of group in which the parent post resides
|
|
591
|
+
* @param {SidechatSimpleAsset[]} [assetList] - list of assets to attach.
|
|
592
|
+
* @param {Boolean} [disableDMs] - prevent direct messages from being sent to post's author
|
|
593
|
+
* @param {Boolean} [disableComments] - whether or not comments should be disabled on post
|
|
594
|
+
* @returns {SidechatPostOrComment} the created post
|
|
595
|
+
*/
|
|
596
|
+
createPost = async (
|
|
597
|
+
text,
|
|
598
|
+
groupID,
|
|
599
|
+
assetList = [],
|
|
600
|
+
disableDMs = false,
|
|
601
|
+
disableComments = false
|
|
602
|
+
) => {
|
|
603
|
+
if (!this.userToken) {
|
|
604
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
605
|
+
}
|
|
606
|
+
try {
|
|
607
|
+
const res = await fetch(`https://api.sidechat.lol/v1/posts`, {
|
|
608
|
+
method: "POST",
|
|
609
|
+
headers: {
|
|
610
|
+
...this.defaultHeaders,
|
|
611
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
612
|
+
},
|
|
613
|
+
body: JSON.stringify({
|
|
614
|
+
type: "post",
|
|
615
|
+
assets: assetList,
|
|
616
|
+
group_ids: [groupID],
|
|
617
|
+
text: text,
|
|
618
|
+
attachments: [],
|
|
619
|
+
dms_disabled: disableDMs,
|
|
620
|
+
comments_disabled: disableComments,
|
|
621
|
+
}),
|
|
622
|
+
});
|
|
623
|
+
const json = await res.json();
|
|
624
|
+
return await json.posts[0];
|
|
625
|
+
} catch (err) {
|
|
626
|
+
console.error(err);
|
|
627
|
+
throw new SidechatAPIError(`Failed to make post.`);
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Deletes a post or comment that the user created
|
|
633
|
+
* @method
|
|
634
|
+
* @since 2.2.0
|
|
635
|
+
* @param {String} postOrCommentID - alphanumeric ID of the post to delete
|
|
636
|
+
*/
|
|
637
|
+
deletePostOrComment = async (postOrCommentID) => {
|
|
638
|
+
if (!this.userToken) {
|
|
639
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
640
|
+
}
|
|
641
|
+
try {
|
|
642
|
+
const res = await fetch(`https://api.sidechat.lol/v1/posts/delete`, {
|
|
643
|
+
method: "POST",
|
|
644
|
+
headers: {
|
|
645
|
+
...this.defaultHeaders,
|
|
646
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
647
|
+
},
|
|
648
|
+
body: JSON.stringify({
|
|
649
|
+
post_id: postOrCommentID,
|
|
650
|
+
}),
|
|
651
|
+
});
|
|
652
|
+
const json = await res.json();
|
|
653
|
+
return await json;
|
|
654
|
+
} catch (err) {
|
|
655
|
+
console.error(err);
|
|
656
|
+
throw new SidechatAPIError(`Failed to delete post.`);
|
|
657
|
+
}
|
|
658
|
+
};
|
|
470
659
|
}
|
|
471
660
|
|
|
472
661
|
exports.SidechatAPIClient = SidechatAPIClient;
|
package/dist/index.mjs
CHANGED
|
@@ -25,6 +25,7 @@ class SidechatAPIClient {
|
|
|
25
25
|
* Default headers for every API request
|
|
26
26
|
* @type {Object}
|
|
27
27
|
* @static
|
|
28
|
+
* @constant
|
|
28
29
|
*/
|
|
29
30
|
defaultHeaders = {
|
|
30
31
|
Accept: "application/json",
|
|
@@ -246,9 +247,21 @@ class SidechatAPIClient {
|
|
|
246
247
|
* Get updated status for user and group
|
|
247
248
|
* @method
|
|
248
249
|
* @since 1.0.0
|
|
249
|
-
* @
|
|
250
|
+
* @deprecated since 2.1.0, will be removed by 3.0.0. Please use `getUpdates` instead!
|
|
251
|
+
* @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
|
|
250
252
|
*/
|
|
251
253
|
getUserAndGroup = async (groupID = "") => {
|
|
254
|
+
const json = await this.getUpdates(groupID);
|
|
255
|
+
return json;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Get updated status for user and group
|
|
260
|
+
* @method
|
|
261
|
+
* @since 2.1.0
|
|
262
|
+
* @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
|
|
263
|
+
*/
|
|
264
|
+
getUpdates = async (groupID = "") => {
|
|
252
265
|
if (!this.userToken) {
|
|
253
266
|
throw new SidechatAPIError("User is not authenticated.");
|
|
254
267
|
}
|
|
@@ -463,6 +476,182 @@ class SidechatAPIClient {
|
|
|
463
476
|
throw new SidechatAPIError(`Failed to get asset library.`);
|
|
464
477
|
}
|
|
465
478
|
};
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Gets the current authenticated user and a list of the groups of which they are members.
|
|
482
|
+
* @method
|
|
483
|
+
* @since 2.1.0
|
|
484
|
+
* @returns {SidechatCurrentUser}
|
|
485
|
+
*/
|
|
486
|
+
getCurrentUser = async () => {
|
|
487
|
+
if (!this.userToken) {
|
|
488
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
489
|
+
}
|
|
490
|
+
try {
|
|
491
|
+
const res = await fetch(`https://api.sidechat.lol/v1/users/me`, {
|
|
492
|
+
method: "GET",
|
|
493
|
+
headers: {
|
|
494
|
+
...this.defaultHeaders,
|
|
495
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
496
|
+
},
|
|
497
|
+
});
|
|
498
|
+
const json = await res.json();
|
|
499
|
+
return await json;
|
|
500
|
+
} catch (err) {
|
|
501
|
+
console.error(err);
|
|
502
|
+
throw new SidechatAPIError(`Failed to get asset library.`);
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Gets the metadata of a group from its ID
|
|
508
|
+
* @method
|
|
509
|
+
* @since 2.1.0
|
|
510
|
+
* @param {String} [groupID] - alphanumeric ID of a group to get. Falls back to user's primary group.
|
|
511
|
+
* @returns {SidechatGroup}
|
|
512
|
+
*/
|
|
513
|
+
getGroupMetadata = async (groupID = "") => {
|
|
514
|
+
if (!this.userToken) {
|
|
515
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
516
|
+
}
|
|
517
|
+
try {
|
|
518
|
+
const res = await fetch(`https://api.sidechat.lol/v1/groups/${groupID}`, {
|
|
519
|
+
method: "GET",
|
|
520
|
+
headers: {
|
|
521
|
+
...this.defaultHeaders,
|
|
522
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
523
|
+
},
|
|
524
|
+
});
|
|
525
|
+
const json = await res.json();
|
|
526
|
+
return await json.group;
|
|
527
|
+
} catch (err) {
|
|
528
|
+
console.error(err);
|
|
529
|
+
throw new SidechatAPIError(`Failed to get group metadata.`);
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Creates a comment on a post
|
|
535
|
+
* @method
|
|
536
|
+
* @since 2.2.0
|
|
537
|
+
* @param {String} parentPostID - alphanumeric ID of post on which this comment is made
|
|
538
|
+
* @param {String} text - text content of comment
|
|
539
|
+
* @param {String} groupID - alphanumeric ID of group in which the parent post resides
|
|
540
|
+
* @param {String} [replyCommentID] - alphanumeric ID of comment to reply to. Falls back to parentPostID
|
|
541
|
+
* @param {SidechatSimpleAsset[]} [assetList] - list of assets to attach
|
|
542
|
+
* @param {Boolean} [disableDMs] - prevent direct messages being sent to comment's author
|
|
543
|
+
* @returns {SidechatPostOrComment} created comment
|
|
544
|
+
*/
|
|
545
|
+
createComment = async (
|
|
546
|
+
parentPostID,
|
|
547
|
+
text,
|
|
548
|
+
groupID,
|
|
549
|
+
replyCommentID = parentPostID,
|
|
550
|
+
assetList = [],
|
|
551
|
+
disableDMs = false
|
|
552
|
+
) => {
|
|
553
|
+
if (!this.userToken) {
|
|
554
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
555
|
+
}
|
|
556
|
+
try {
|
|
557
|
+
const res = await fetch(`https://api.sidechat.lol/v1/posts`, {
|
|
558
|
+
method: "POST",
|
|
559
|
+
headers: {
|
|
560
|
+
...this.defaultHeaders,
|
|
561
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
562
|
+
},
|
|
563
|
+
body: JSON.stringify({
|
|
564
|
+
type: "comment",
|
|
565
|
+
assets: assetList,
|
|
566
|
+
group_ids: [groupID],
|
|
567
|
+
text: text,
|
|
568
|
+
reply_post_id: replyCommentID,
|
|
569
|
+
parent_post_id: parentPostID,
|
|
570
|
+
dms_disabled: disableDMs,
|
|
571
|
+
}),
|
|
572
|
+
});
|
|
573
|
+
const json = await res.json();
|
|
574
|
+
return await json.comment;
|
|
575
|
+
} catch (err) {
|
|
576
|
+
console.error(err);
|
|
577
|
+
throw new SidechatAPIError(`Failed to post comment.`);
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Creates a new post in the specified group
|
|
583
|
+
* @method
|
|
584
|
+
* @since 2.2.0
|
|
585
|
+
* @param {String} text - text content of comment
|
|
586
|
+
* @param {String} groupID - alphanumeric ID of group in which the parent post resides
|
|
587
|
+
* @param {SidechatSimpleAsset[]} [assetList] - list of assets to attach.
|
|
588
|
+
* @param {Boolean} [disableDMs] - prevent direct messages from being sent to post's author
|
|
589
|
+
* @param {Boolean} [disableComments] - whether or not comments should be disabled on post
|
|
590
|
+
* @returns {SidechatPostOrComment} the created post
|
|
591
|
+
*/
|
|
592
|
+
createPost = async (
|
|
593
|
+
text,
|
|
594
|
+
groupID,
|
|
595
|
+
assetList = [],
|
|
596
|
+
disableDMs = false,
|
|
597
|
+
disableComments = false
|
|
598
|
+
) => {
|
|
599
|
+
if (!this.userToken) {
|
|
600
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
601
|
+
}
|
|
602
|
+
try {
|
|
603
|
+
const res = await fetch(`https://api.sidechat.lol/v1/posts`, {
|
|
604
|
+
method: "POST",
|
|
605
|
+
headers: {
|
|
606
|
+
...this.defaultHeaders,
|
|
607
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
608
|
+
},
|
|
609
|
+
body: JSON.stringify({
|
|
610
|
+
type: "post",
|
|
611
|
+
assets: assetList,
|
|
612
|
+
group_ids: [groupID],
|
|
613
|
+
text: text,
|
|
614
|
+
attachments: [],
|
|
615
|
+
dms_disabled: disableDMs,
|
|
616
|
+
comments_disabled: disableComments,
|
|
617
|
+
}),
|
|
618
|
+
});
|
|
619
|
+
const json = await res.json();
|
|
620
|
+
return await json.posts[0];
|
|
621
|
+
} catch (err) {
|
|
622
|
+
console.error(err);
|
|
623
|
+
throw new SidechatAPIError(`Failed to make post.`);
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Deletes a post or comment that the user created
|
|
629
|
+
* @method
|
|
630
|
+
* @since 2.2.0
|
|
631
|
+
* @param {String} postOrCommentID - alphanumeric ID of the post to delete
|
|
632
|
+
*/
|
|
633
|
+
deletePostOrComment = async (postOrCommentID) => {
|
|
634
|
+
if (!this.userToken) {
|
|
635
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
636
|
+
}
|
|
637
|
+
try {
|
|
638
|
+
const res = await fetch(`https://api.sidechat.lol/v1/posts/delete`, {
|
|
639
|
+
method: "POST",
|
|
640
|
+
headers: {
|
|
641
|
+
...this.defaultHeaders,
|
|
642
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
643
|
+
},
|
|
644
|
+
body: JSON.stringify({
|
|
645
|
+
post_id: postOrCommentID,
|
|
646
|
+
}),
|
|
647
|
+
});
|
|
648
|
+
const json = await res.json();
|
|
649
|
+
return await json;
|
|
650
|
+
} catch (err) {
|
|
651
|
+
console.error(err);
|
|
652
|
+
throw new SidechatAPIError(`Failed to delete post.`);
|
|
653
|
+
}
|
|
654
|
+
};
|
|
466
655
|
}
|
|
467
656
|
|
|
468
657
|
export { SidechatAPIClient, SidechatAPIError };
|
|
@@ -102,7 +102,7 @@ export type SidechatPostOrComment = {
|
|
|
102
102
|
context?: string;
|
|
103
103
|
};
|
|
104
104
|
/**
|
|
105
|
-
* A group object, containing metadata about a group as well as its join conditions and states
|
|
105
|
+
* A group object, containing metadata about a group as well as its join conditions and states. Some properties vary based on the endpoint the object came from.
|
|
106
106
|
*/
|
|
107
107
|
export type SidechatGroup = {
|
|
108
108
|
/**
|
|
@@ -175,17 +175,17 @@ export type SidechatSimpleAsset = {
|
|
|
175
175
|
*/
|
|
176
176
|
content_type: "jpeg" | "png" | "gif";
|
|
177
177
|
/**
|
|
178
|
-
* -
|
|
178
|
+
* - width of asset
|
|
179
179
|
*/
|
|
180
180
|
width: number;
|
|
181
181
|
/**
|
|
182
|
-
* -
|
|
182
|
+
* - height of asset
|
|
183
183
|
*/
|
|
184
184
|
height: number;
|
|
185
185
|
/**
|
|
186
186
|
* - URL string of asset's location
|
|
187
187
|
*/
|
|
188
|
-
url
|
|
188
|
+
url?: SidechatPrivateAssetURL;
|
|
189
189
|
};
|
|
190
190
|
/**
|
|
191
191
|
* An asset object, containing information about an image from the asset library
|
|
@@ -213,11 +213,11 @@ export type SidechatLibraryAsset = {
|
|
|
213
213
|
*/
|
|
214
214
|
export type SidechatAssetMetadata = {
|
|
215
215
|
/**
|
|
216
|
-
* -
|
|
216
|
+
* - width of asset
|
|
217
217
|
*/
|
|
218
218
|
width: number;
|
|
219
219
|
/**
|
|
220
|
-
* -
|
|
220
|
+
* - height of asset
|
|
221
221
|
*/
|
|
222
222
|
height: number;
|
|
223
223
|
/**
|
|
@@ -230,7 +230,7 @@ export type SidechatAssetMetadata = {
|
|
|
230
230
|
content_type: "jpeg" | "png" | "gif";
|
|
231
231
|
};
|
|
232
232
|
/**
|
|
233
|
-
* A user's identity information
|
|
233
|
+
* A user's anonymous identity information
|
|
234
234
|
*/
|
|
235
235
|
export type SidechatIdentity = {
|
|
236
236
|
/**
|
|
@@ -242,6 +242,53 @@ export type SidechatIdentity = {
|
|
|
242
242
|
*/
|
|
243
243
|
posted_with_username: boolean;
|
|
244
244
|
};
|
|
245
|
+
/**
|
|
246
|
+
* The current user's information
|
|
247
|
+
*/
|
|
248
|
+
export type SidechatCurrentUser = {
|
|
249
|
+
/**
|
|
250
|
+
* - alphanumeric ID of current user
|
|
251
|
+
*/
|
|
252
|
+
id: string;
|
|
253
|
+
/**
|
|
254
|
+
* - verified email of current user in an unreadable hashed form
|
|
255
|
+
*/
|
|
256
|
+
hashedVerifiedEmail: string;
|
|
257
|
+
/**
|
|
258
|
+
* - whether or not user is a moderator
|
|
259
|
+
*/
|
|
260
|
+
isGlobalModerator: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* - whether or not user is an admin
|
|
263
|
+
*/
|
|
264
|
+
isGlobalAdmin: boolean;
|
|
265
|
+
memberships: SidechatMembership[];
|
|
266
|
+
/**
|
|
267
|
+
* - undocumented
|
|
268
|
+
*/
|
|
269
|
+
roles: any[];
|
|
270
|
+
/**
|
|
271
|
+
* - domain of verified email address on account
|
|
272
|
+
*/
|
|
273
|
+
emailDomain: string;
|
|
274
|
+
/**
|
|
275
|
+
* - domain of verified email address on account, preceeded by *. to support subdomains
|
|
276
|
+
*/
|
|
277
|
+
wildcardEmailDomain: string;
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* Representation of a group membership
|
|
281
|
+
*/
|
|
282
|
+
export type SidechatMembership = {
|
|
283
|
+
/**
|
|
284
|
+
* - alphanumeric ID of group
|
|
285
|
+
*/
|
|
286
|
+
groupId: string;
|
|
287
|
+
/**
|
|
288
|
+
* - role of current user in group
|
|
289
|
+
*/
|
|
290
|
+
type: string;
|
|
291
|
+
};
|
|
245
292
|
/**
|
|
246
293
|
* An asset URL that can only be accessed by making a request with a user's bearer token attached in the Authorization header
|
|
247
294
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SidechatTypes.d.ts","sourceRoot":"","sources":["../../src/types/SidechatTypes.js"],"names":[],"mappings":";;;;;;;;;UAGU,MAAM,GAAC,SAAS;;;;;;;;;;;;;;;;;;;;WAKhB,aAAa;;;;;;;;;;;;;;;;iBAIb,kBAAkB;;;;YAClB,mBAAmB,EAAE;;;;;;;;;;;;;;;;cAIrB,gBAAgB;;;;;;;;;;;;mBAGhB,WAAW,GAAC,eAAe;;;;kBAC3B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAcP,YAAY,GAAC,QAAQ;;;;;;;;qBAErB,MAAM,GAAC,QAAQ,GAAC,cAAc;;;;sBAC9B,SAAS,GAAC,eAAe,GAAC,mBAAmB;;;;8BAC7C,MAAM,GAAC,MAAM;;;;;;;;;;;;eAGb,uBAAuB;;;;;;;;;;;;;;;;;;;;;UASvB,OAAO;;;;kBACP,MAAM,GAAC,KAAK,GAAC,KAAK;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"SidechatTypes.d.ts","sourceRoot":"","sources":["../../src/types/SidechatTypes.js"],"names":[],"mappings":";;;;;;;;;UAGU,MAAM,GAAC,SAAS;;;;;;;;;;;;;;;;;;;;WAKhB,aAAa;;;;;;;;;;;;;;;;iBAIb,kBAAkB;;;;YAClB,mBAAmB,EAAE;;;;;;;;;;;;;;;;cAIrB,gBAAgB;;;;;;;;;;;;mBAGhB,WAAW,GAAC,eAAe;;;;kBAC3B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAcP,YAAY,GAAC,QAAQ;;;;;;;;qBAErB,MAAM,GAAC,QAAQ,GAAC,cAAc;;;;sBAC9B,SAAS,GAAC,eAAe,GAAC,mBAAmB;;;;8BAC7C,MAAM,GAAC,MAAM;;;;;;;;;;;;eAGb,uBAAuB;;;;;;;;;;;;;;;;;;;;;UASvB,OAAO;;;;kBACP,MAAM,GAAC,KAAK,GAAC,KAAK;;;;;;;;;;;;UAGlB,uBAAuB;;;;;;;;;;;;;;;;;cAQvB,qBAAqB;;;;SACrB,uBAAuB;;;;;;;;;;;;;;;;;UAQvB,OAAO;;;;kBACP,MAAM,GAAC,KAAK,GAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiBlB,kBAAkB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAyBjB,QAAQ,GAAC,UAAU,GAAC,MAAM;;;;;;;;;WAW7B,qBAAqB,EAAE;YACvB,oBAAoB"}
|