sidechat.js 2.4.1 → 2.4.4

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.
Files changed (50) hide show
  1. package/dist/classes/SidechatAPIClient.d.ts +37 -0
  2. package/dist/classes/SidechatAPIClient.d.ts.map +1 -1
  3. package/dist/index.cjs +301 -1
  4. package/dist/index.d.mts +2 -1
  5. package/dist/index.d.ts +2 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.mjs +301 -2
  8. package/dist/types/SidechatTypes.d.ts +74 -0
  9. package/dist/types/SidechatTypes.d.ts.map +1 -1
  10. package/docs/sidechat.js/2.4.4/SidechatAPIClient.html +3 -0
  11. package/docs/sidechat.js/2.4.4/SidechatAPIError.html +3 -0
  12. package/docs/sidechat.js/2.4.4/SidechatColorList.html +3 -0
  13. package/docs/sidechat.js/2.4.4/classes_SidechatAPIClient.js.html +1100 -0
  14. package/docs/sidechat.js/2.4.4/classes_SidechatAPIError.js.html +16 -0
  15. package/docs/sidechat.js/2.4.4/classes_SidechatColorList.js.html +79 -0
  16. package/docs/sidechat.js/2.4.4/data/search.json +1 -0
  17. package/docs/sidechat.js/2.4.4/fonts/Inconsolata-Regular.ttf +0 -0
  18. package/docs/sidechat.js/2.4.4/fonts/OpenSans-Regular.ttf +0 -0
  19. package/docs/sidechat.js/2.4.4/fonts/WorkSans-Bold.ttf +0 -0
  20. package/docs/sidechat.js/2.4.4/global.html +3 -0
  21. package/docs/sidechat.js/2.4.4/index.html +4 -0
  22. package/docs/sidechat.js/2.4.4/scripts/core.js +726 -0
  23. package/docs/sidechat.js/2.4.4/scripts/core.min.js +23 -0
  24. package/docs/sidechat.js/2.4.4/scripts/resize.js +90 -0
  25. package/docs/sidechat.js/2.4.4/scripts/search.js +265 -0
  26. package/docs/sidechat.js/2.4.4/scripts/search.min.js +6 -0
  27. package/docs/sidechat.js/2.4.4/scripts/third-party/Apache-License-2.0.txt +202 -0
  28. package/docs/sidechat.js/2.4.4/scripts/third-party/fuse.js +9 -0
  29. package/docs/sidechat.js/2.4.4/scripts/third-party/hljs-line-num-original.js +369 -0
  30. package/docs/sidechat.js/2.4.4/scripts/third-party/hljs-line-num.js +1 -0
  31. package/docs/sidechat.js/2.4.4/scripts/third-party/hljs-original.js +5171 -0
  32. package/docs/sidechat.js/2.4.4/scripts/third-party/hljs.js +1 -0
  33. package/docs/sidechat.js/2.4.4/scripts/third-party/popper.js +5 -0
  34. package/docs/sidechat.js/2.4.4/scripts/third-party/tippy.js +1 -0
  35. package/docs/sidechat.js/2.4.4/scripts/third-party/tocbot.js +672 -0
  36. package/docs/sidechat.js/2.4.4/scripts/third-party/tocbot.min.js +1 -0
  37. package/docs/sidechat.js/2.4.4/styles/clean-jsdoc-theme-base.css +1161 -0
  38. package/docs/sidechat.js/2.4.4/styles/clean-jsdoc-theme-dark.css +412 -0
  39. package/docs/sidechat.js/2.4.4/styles/clean-jsdoc-theme-light.css +482 -0
  40. package/docs/sidechat.js/2.4.4/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  41. package/docs/sidechat.js/2.4.4/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  42. package/docs/sidechat.js/2.4.4/styles/clean-jsdoc-theme.min.css +1 -0
  43. package/docs/sidechat.js/2.4.4/tutorial-Authentication.html +14 -0
  44. package/docs/sidechat.js/2.4.4/tutorial-Email Registration.html +6 -0
  45. package/docs/sidechat.js/2.4.4/types_SidechatTypes.js.html +160 -0
  46. package/package.json +1 -1
  47. package/src/classes/SidechatAPIClient.js +142 -1
  48. package/src/index.js +7 -2
  49. package/src/tests/directMessageTest.js +23 -0
  50. package/src/types/SidechatTypes.js +26 -0
@@ -261,5 +261,42 @@ declare class SidechatAPIClient {
261
261
  * @since 2.3.5
262
262
  */
263
263
  joinGroupChat: (groupChatID: any, displayName: any, emoji: any, primaryColor: any, secondaryColor: any) => Promise<any>;
264
+ /**
265
+ * Gets a list of the user's direct messages
266
+ * @method
267
+ * @returns {SidechatDirectThread[]}
268
+ * @since 2.4.4
269
+ */
270
+ getDMs: () => SidechatDirectThread[];
271
+ /**
272
+ * Gets a single direct message thread
273
+ * @method
274
+ * @param {String} id - alphanumeric ID of the chat to fetch
275
+ * @returns {SidechatDirectThread}
276
+ * @since 2.4.4
277
+ */
278
+ getDMThread: (id: string) => SidechatDirectThread;
279
+ /**
280
+ * Sends a message to an existing direct message thread - note that you must first use startDM() to start a thread.
281
+ * @method
282
+ * @param {String} chatID - alphanumeric ID of the chat to send to
283
+ * @param {String} text - text content of message
284
+ * @param {String} clientID - alphanumeric device ID
285
+ * @param {SidechatAsset[]} - array of assets to send
286
+ * @param {Boolean} anonymous - whether the DM should be sent anonymously
287
+ * @since 2.4.4
288
+ */
289
+ sendDM: (chatID: string, text: string, clientID: string, assets?: any[], anonymous?: boolean) => Promise<any>;
290
+ /**
291
+ * Creates a new direct message thread
292
+ * @method
293
+ * @param {String} text - text content of message
294
+ * @param {String} clientID - alphanumeric ID of devide
295
+ * @param {String} postID - alphanumeric ID of post or comment
296
+ * @param {Boolean} anonymous - whether the DM should be sent anonymously
297
+ * @param {"feed"} postContext - context of post (mostly undocumented, defaults to "feed")
298
+ * @since 2.4.4
299
+ */
300
+ startDM: (text: string, clientID: string, postID: string, anonymous?: boolean, postContext?: "feed") => Promise<any>;
264
301
  }
265
302
  //# 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;IA2BE;;;;OAIG;IACH,yDAOC;IAtCD;;;SAGK;IACL,6BAAU;IAEV;;;;;OAKG;IACH,oBAKE;IAEF;;;;OAIG;IACH,gBAAqC;IAgBrC;;;;OAIG;IACH,6CAEE;IAEF;;;;;OAKG;IACH,kCAEE;IAEF;;;;;OAKG;IACH,mDAgBE;IAEF;;;;;;OAMG;IACH,mEAmBE;IAEF;;;;;;OAMG;IACH,8DAsBE;IAEF;;;;;;OAMG;IACH,+CAwBE;IAEF;;;;OAIG;IACH,2CAsBE;IAEF;;;;;OAKG;IACH,6CAwBE;IAEF;;;;;;OAMG;IACH,oDAGE;IAEF;;;;;OAKG;IACH,+CAqBE;IAEF;;;;;;;;OAQG;IACH,4CAJW,KAAK,GAAC,QAAQ,GAAC,KAAK,2DA2B7B;IAEF;;;;;;OAMG;IACH,sEAsBE;IAEF;;;;;;;OAOG;IACH,6EAqBE;IAEF;;;;;;OAMG;IACH,8BAHW,OAAO,GAAC,UAAU,KAChB,uBAAuB,CAyBlC;IAEF;;;;;;OAMG;IACH,qCAFa,uBAAuB,CAqElC;IAEF;;;;;;OAMG;IACH,2CAFa,eAAe,CAqB1B;IAEF;;;;;OAKG;IACH,uBAFa,sBAAsB,CAoBjC;IAEF;;;;;OAKG;IACH,0CAkBE;IAEF;;;;;;OAMG;IACH,sDAkBE;IAEF;;;;;;OAMG;IACH,yEAwBE;IAEF;;;;;;;;;;;;OAYG;IACH,0GALW,qBAAqB,sEAyC9B;IAEF;;;;;;;;;;;OAWG;IACH,wDANW,qBAAqB,iGAyC9B;IAEF;;;;;OAKG;IACH,+DAqBE;IAEF;;;;;;;;OAQG;IACH,2GA2BE;IAEF;;;;;;OAMG;IACH,6CAwBE;IAEF;;;;;;OAMG;IACH,gEAqBE;IAEF;;;;;OAKG;IACH,mDAqBE;IAEF;;;;OAIG;IACH,kCAkBE;IAEF;;;;OAIG;IACH,wHAiCE;CACH"}
1
+ {"version":3,"file":"SidechatAPIClient.d.ts","sourceRoot":"","sources":["../../src/classes/SidechatAPIClient.js"],"names":[],"mappings":";AAGA;;;;GAIG;AACH;IA2BE;;;;OAIG;IACH,yDAOC;IAtCD;;;SAGK;IACL,6BAAU;IAEV;;;;;OAKG;IACH,oBAKE;IAEF;;;;OAIG;IACH,gBAAqC;IAgBrC;;;;OAIG;IACH,6CAEE;IAEF;;;;;OAKG;IACH,kCAEE;IAEF;;;;;OAKG;IACH,mDAgBE;IAEF;;;;;;OAMG;IACH,mEAmBE;IAEF;;;;;;OAMG;IACH,8DAsBE;IAEF;;;;;;OAMG;IACH,+CAwBE;IAEF;;;;OAIG;IACH,2CAsBE;IAEF;;;;;OAKG;IACH,6CAwBE;IAEF;;;;;;OAMG;IACH,oDAGE;IAEF;;;;;OAKG;IACH,+CAqBE;IAEF;;;;;;;;OAQG;IACH,4CAJW,KAAK,GAAC,QAAQ,GAAC,KAAK,2DA2B7B;IAEF;;;;;;OAMG;IACH,sEAsBE;IAEF;;;;;;;OAOG;IACH,6EAqBE;IAEF;;;;;;OAMG;IACH,8BAHW,OAAO,GAAC,UAAU,KAChB,uBAAuB,CAyBlC;IAEF;;;;;;OAMG;IACH,qCAFa,uBAAuB,CAqElC;IAEF;;;;;;OAMG;IACH,2CAFa,eAAe,CAqB1B;IAEF;;;;;OAKG;IACH,uBAFa,sBAAsB,CAoBjC;IAEF;;;;;OAKG;IACH,0CAkBE;IAEF;;;;;;OAMG;IACH,sDAkBE;IAEF;;;;;;OAMG;IACH,yEAwBE;IAEF;;;;;;;;;;;;OAYG;IACH,0GALW,qBAAqB,sEAyC9B;IAEF;;;;;;;;;;;OAWG;IACH,wDANW,qBAAqB,iGAyC9B;IAEF;;;;;OAKG;IACH,+DAqBE;IAEF;;;;;;;;OAQG;IACH,2GA2BE;IAEF;;;;;;OAMG;IACH,6CAwBE;IAEF;;;;;;OAMG;IACH,gEAqBE;IAEF;;;;;OAKG;IACH,mDAqBE;IAEF;;;;OAIG;IACH,kCAkBE;IAEF;;;;OAIG;IACH,wHAiCE;IAEF;;;;;OAKG;IACH,cAHa,sBAAsB,CA0BjC;IAEF;;;;;;OAMG;IACH,kDAqBE;IAEF;;;;;;;;;OASG;IACH,8GAyBE;IAEF;;;;;;;;;OASG;IACH,6FAHW,MAAM,kBAkCf;CACH"}
package/dist/index.cjs CHANGED
@@ -2,6 +2,164 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ /**
6
+ * A user-created post or comment, depending on the "type" prop
7
+ * @typedef {Object} SidechatPostOrComment
8
+ * @prop {"post"|"comment"} type - whether this object represents a post or a comment on a post
9
+ * @prop {String} id - alphanumeric ID of post or comment
10
+ * @prop {Boolean} authored_by_user - undocumented
11
+ * @prop {String} alias - post creator's name in-app
12
+ * @prop {String} group_id - alphanumeric ID of group
13
+ * @prop {SidechatGroup} group - group in which post or comment was created
14
+ * @prop {String} text - text content of post or comment
15
+ * @prop {String} created_at - date string of post or comment creation time
16
+ * @prop {Number} vote_total - sum of upvotes and downvotes
17
+ * @prop {SidechatVoteString} vote_status - current user's vote on post or comment
18
+ * @prop {SidechatSimpleAsset[]} assets - array of simple assets attached to post or comment
19
+ * @prop {Array} attachments - undocumented
20
+ * @prop {Boolean} dms_disabled - whether or not you can send a DM to creator of post
21
+ * @prop {Array} tags - undocumented
22
+ * @prop {SidechatIdentity} identity - creator's identity information
23
+ * @prop {Boolean} pinned - undocumented
24
+ * @prop {Boolean} is_saved - undocumented
25
+ * @prop {"following"|"not_following"} follow_status - undocumented
26
+ * @prop {"group"} [destination] - undocumented
27
+ * @prop {Number} [comment_count] - number of comments on post (only if type=post)
28
+ * @prop {Boolean} [comments_disabled] - whether or not you can comment on post (only if type=post)
29
+ * @prop {String} [parent_post_id] - alphanumeric ID of parent post (only if type=comment)
30
+ * @prop {String} [reply_post_id] - alphanumeric ID of comment being replied to, falls back to parent_post_id (only if type=comment)
31
+ * @prop {String} [context] - text content of comment being replied to, falls back to text (only if type=comment)
32
+ */
33
+
34
+ /**
35
+ * 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.
36
+ * @typedef {Object} SidechatGroup
37
+ * @prop {String} id - alphanumeric ID of group
38
+ * @prop {String} name - human-readable name of group
39
+ * @prop {String} analytics_name - name to file group under
40
+ * @prop {"non_member"|"member"} membership_type - whether or not current user is a member of group
41
+ * @prop {String} color - group's theme color as hex code (e.g., #FFFFFF)
42
+ * @prop {"open"|"closed"|"email_domain"} group_join_type - basis on which group accepts new members
43
+ * @prop {"private"|"public_to_all"|"public_to_schools"} group_visibility - group's visibility setting
44
+ * @prop {"show"|"hide"} asset_library_visibility - whether or not group's asset library is visible
45
+ * @prop {Array} [roles] - undocumented
46
+ * @prop {String} [description] - description of group
47
+ * @prop {SidechatPrivateAssetURL} [icon_url] - image URL for group icon
48
+ * @prop {Number} [member_count] - number of users in group
49
+ * @prop {Boolean} [should_show_leaderboard] - undocumented
50
+ */
51
+
52
+ /**
53
+ * An asset object, containing information about an image within a post or comment
54
+ * @typedef {Object} SidechatSimpleAsset
55
+ * @prop {String} id - alphanumeric ID of asset
56
+ * @prop {"image"} type - undocumented
57
+ * @prop {"jpeg"|"png"|"gif"} content_type - file type of asset
58
+ * @prop {Number} width - width of asset
59
+ * @prop {Number} height - height of asset
60
+ * @prop {SidechatPrivateAssetURL} [url] - URL string of asset's location
61
+ */
62
+
63
+ /**
64
+ * An asset object, containing information about an image from the asset library
65
+ * @typedef {Object} SidechatLibraryAsset
66
+ * @prop {String} id - alphanumeric ID of asset
67
+ * @prop {String} created_at - date string of asset creation time
68
+ * @prop {SidechatAssetMetadata} metadata - metadata associated with asset
69
+ * @prop {SidechatPrivateAssetURL} url - URL string of asset's location
70
+ */
71
+
72
+ /**
73
+ * An asset object, containing information about an image from the asset library
74
+ * @typedef {Object} SidechatAssetMetadata
75
+ * @prop {Number} width - width of asset
76
+ * @prop {Number} height - height of asset
77
+ * @prop {"image"} type - undocumented
78
+ * @prop {"jpeg"|"png"|"gif"} content_type - file type of asset
79
+ */
80
+
81
+ /**
82
+ * A user's anonymous identity information
83
+ * @typedef {Object} SidechatIdentity
84
+ * @prop {String} name - representation of user's name (varies across app)
85
+ * @prop {Boolean} posted_with_username - undocumented
86
+ */
87
+
88
+ /**
89
+ * The current user's information
90
+ * @typedef {Object} SidechatCurrentUser
91
+ * @prop {String} id - alphanumeric ID of current user
92
+ * @prop {String} hashedVerifiedEmail - verified email of current user in an unreadable hashed form
93
+ * @prop {Boolean} isGlobalModerator - whether or not user is a moderator
94
+ * @prop {Boolean} isGlobalAdmin - whether or not user is an admin
95
+ * @prop {SidechatMembership[]} memberships
96
+ * @prop {Array} roles - undocumented
97
+ * @prop {String} emailDomain - domain of verified email address on account
98
+ * @prop {String} wildcardEmailDomain - domain of verified email address on account, preceeded by *. to support subdomains
99
+ */
100
+
101
+ /**
102
+ * Representation of a group membership
103
+ * @typedef {Object} SidechatMembership
104
+ * @prop {String} groupId - alphanumeric ID of group
105
+ * @prop {String} type - role of current user in group
106
+ */
107
+
108
+ /**
109
+ * An asset URL that can only be accessed by making a request with a user's bearer token attached in the Authorization header
110
+ * @typedef {String} SidechatPrivateAssetURL
111
+ */
112
+
113
+ /**
114
+ * A cursor for paginating through post lists
115
+ * @typedef {String} SidechatCursorString
116
+ */
117
+
118
+ /**
119
+ * A vote on a comment or post
120
+ * @typedef {"upvote"|"downvote"|"none"} SidechatVoteString
121
+ */
122
+
123
+ /**
124
+ * A user's bearer authentication token needed for most requests
125
+ * @typedef {String} SidechatAuthToken
126
+ */
127
+
128
+ /**
129
+ * A list of posts and the associated cursor
130
+ * @typedef {Object} SidechatPostsAndCursor
131
+ * @prop {SidechatPostOrComment[]} posts
132
+ * @prop {SidechatCursorString} cursor
133
+ */
134
+
135
+ var SidechatTypes = {};
136
+
137
+ /**
138
+ * A direct message thread
139
+ * @typedef {Object} SidechatDirectThread
140
+ * @prop {String} id - alphanumeric ID of thread
141
+ * @prop {String} group_id - alphanumeric ID of group in which the thread exists
142
+ * @prop {String} updated_at - date string of when the last message in the chat was sent
143
+ * @prop {String} post_id - post or comment from which the thread was originally sent
144
+ * @prop {String} post_context - the context of the DM thread (only "feed" is known at the moment)
145
+ * @prop {"accepted"} accept_status - whether or not the other user has accepted this DM
146
+ * @prop {"post"|"comment"} type - the type of the content from which the DM was originally sent
147
+ * @prop {SidechatDirectMessage[]} messages - array of direct message objects
148
+ */
149
+
150
+ /**
151
+ * A single direct message
152
+ * @typedef {Object} SidechatDirectMessage
153
+ * @prop {String} created_at - time at which the message was sent
154
+ * @prop {String} client_id - alphanumeric ID of the device the message was sent on
155
+ * @prop {String} obfuscatedUserId - obfuscated version of the sender's alphanumeric ID
156
+ * @prop {String} text - body text of the message
157
+ * @prop {String} id - alphanumeric ID of the message
158
+ * @prop {String} chat_id - alphanumeric ID of the thread in which the message resides
159
+ * @prop {Boolean} authored_by_user - whether or not the current user sent the message
160
+ * @prop {"message"} type - undocumented
161
+ */
162
+
5
163
  /**
6
164
  * Throwable error caused by the Sidechat API
7
165
  * @class
@@ -942,7 +1100,7 @@ class SidechatAPIClient {
942
1100
  }
943
1101
  try {
944
1102
  const res = await fetch(`${this.apiRoot}/v1/chats/groups/join`, {
945
- method: "GET",
1103
+ method: "POST",
946
1104
  headers: {
947
1105
  ...this.defaultHeaders,
948
1106
  Authorization: `Bearer ${this.userToken}`,
@@ -964,6 +1122,147 @@ class SidechatAPIClient {
964
1122
  throw new SidechatAPIError(`Failed to join groupchat.`);
965
1123
  }
966
1124
  };
1125
+
1126
+ /**
1127
+ * Gets a list of the user's direct messages
1128
+ * @method
1129
+ * @returns {SidechatDirectThread[]}
1130
+ * @since 2.4.4
1131
+ */
1132
+ getDMs = async () => {
1133
+ if (!this.userToken) {
1134
+ throw new SidechatAPIError("User is not authenticated.");
1135
+ }
1136
+ try {
1137
+ const res = await fetch(`${this.apiRoot}/v1/chats`, {
1138
+ method: "GET",
1139
+ headers: {
1140
+ ...this.defaultHeaders,
1141
+ Authorization: `Bearer ${this.userToken}`,
1142
+ },
1143
+ });
1144
+ const json = await res.json();
1145
+ const list = await json.chats;
1146
+ let r = [];
1147
+ list.forEach((o) => {
1148
+ r.push(o.chat);
1149
+ });
1150
+ return await r;
1151
+ } catch (err) {
1152
+ console.error(err);
1153
+ throw new SidechatAPIError(`Failed to fetch DMs.`);
1154
+ }
1155
+ };
1156
+
1157
+ /**
1158
+ * Gets a single direct message thread
1159
+ * @method
1160
+ * @param {String} id - alphanumeric ID of the chat to fetch
1161
+ * @returns {SidechatDirectThread}
1162
+ * @since 2.4.4
1163
+ */
1164
+ getDMThread = async (id) => {
1165
+ if (!this.userToken) {
1166
+ throw new SidechatAPIError("User is not authenticated.");
1167
+ }
1168
+ try {
1169
+ const res = await fetch(
1170
+ `${this.apiRoot}/v1/chats/messages?chat_id=${id}`,
1171
+ {
1172
+ method: "GET",
1173
+ headers: {
1174
+ ...this.defaultHeaders,
1175
+ Authorization: `Bearer ${this.userToken}`,
1176
+ },
1177
+ }
1178
+ );
1179
+ const json = await res.json();
1180
+ return await json.chat;
1181
+ } catch (err) {
1182
+ console.error(err);
1183
+ throw new SidechatAPIError(`Failed to fetch DM thread.`);
1184
+ }
1185
+ };
1186
+
1187
+ /**
1188
+ * Sends a message to an existing direct message thread - note that you must first use startDM() to start a thread.
1189
+ * @method
1190
+ * @param {String} chatID - alphanumeric ID of the chat to send to
1191
+ * @param {String} text - text content of message
1192
+ * @param {String} clientID - alphanumeric device ID
1193
+ * @param {SidechatAsset[]} - array of assets to send
1194
+ * @param {Boolean} anonymous - whether the DM should be sent anonymously
1195
+ * @since 2.4.4
1196
+ */
1197
+ sendDM = async (chatID, text, clientID, assets = [], anonymous = false) => {
1198
+ if (!this.userToken) {
1199
+ throw new SidechatAPIError("User is not authenticated.");
1200
+ }
1201
+ try {
1202
+ const res = await fetch(`${this.apiRoot}/v1/chats/send`, {
1203
+ method: "POST",
1204
+ headers: {
1205
+ ...this.defaultHeaders,
1206
+ Authorization: `Bearer ${this.userToken}`,
1207
+ },
1208
+ body: JSON.stringify({
1209
+ chat_id: chatID,
1210
+ text: text,
1211
+ client_id: clientID,
1212
+ anonymous: anonymous,
1213
+ assets: assets,
1214
+ }),
1215
+ });
1216
+ const json = await res.json();
1217
+ return await json;
1218
+ } catch (err) {
1219
+ console.error(err);
1220
+ throw new SidechatAPIError(`Failed to fetch DMs.`);
1221
+ }
1222
+ };
1223
+
1224
+ /**
1225
+ * Creates a new direct message thread
1226
+ * @method
1227
+ * @param {String} text - text content of message
1228
+ * @param {String} clientID - alphanumeric ID of devide
1229
+ * @param {String} postID - alphanumeric ID of post or comment
1230
+ * @param {Boolean} anonymous - whether the DM should be sent anonymously
1231
+ * @param {"feed"} postContext - context of post (mostly undocumented, defaults to "feed")
1232
+ * @since 2.4.4
1233
+ */
1234
+ startDM = async (
1235
+ text,
1236
+ clientID,
1237
+ postID,
1238
+ anonymous = false,
1239
+ postContext = "feed"
1240
+ ) => {
1241
+ if (!this.userToken) {
1242
+ throw new SidechatAPIError("User is not authenticated.");
1243
+ }
1244
+ try {
1245
+ const res = await fetch(`${this.apiRoot}/v1/chats/send`, {
1246
+ method: "POST",
1247
+ headers: {
1248
+ ...this.defaultHeaders,
1249
+ Authorization: `Bearer ${this.userToken}`,
1250
+ },
1251
+ body: JSON.stringify({
1252
+ text: text,
1253
+ client_id: clientID,
1254
+ post_id: postID,
1255
+ anonymous: anonymous,
1256
+ post_context: postContext,
1257
+ }),
1258
+ });
1259
+ const json = await res.json();
1260
+ return await json;
1261
+ } catch (err) {
1262
+ console.error(err);
1263
+ throw new SidechatAPIError(`Failed to fetch DMs.`);
1264
+ }
1265
+ };
967
1266
  }
968
1267
 
969
1268
  /**
@@ -1044,3 +1343,4 @@ class SidechatColorList {
1044
1343
  exports.SidechatAPIClient = SidechatAPIClient;
1045
1344
  exports.SidechatAPIError = SidechatAPIError;
1046
1345
  exports.SidechatColorList = SidechatColorList;
1346
+ exports.SidechatTypes = SidechatTypes;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import SidechatAPIClient from "./classes/SidechatAPIClient.js";
2
2
  import SidechatAPIError from "./classes/SidechatAPIError.js";
3
3
  import SidechatColorList from "./classes/SidechatColorList.js";
4
- export { SidechatAPIClient, SidechatAPIError, SidechatColorList };
4
+ import SidechatTypes from "./types/SidechatTypes.js";
5
+ export { SidechatAPIClient, SidechatAPIError, SidechatColorList, SidechatTypes };
5
6
  //# sourceMappingURL=index.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import SidechatAPIClient from "./classes/SidechatAPIClient.js";
2
2
  import SidechatAPIError from "./classes/SidechatAPIError.js";
3
3
  import SidechatColorList from "./classes/SidechatColorList.js";
4
- export { SidechatAPIClient, SidechatAPIError, SidechatColorList };
4
+ import SidechatTypes from "./types/SidechatTypes.js";
5
+ export { SidechatAPIClient, SidechatAPIError, SidechatColorList, SidechatTypes };
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"8BAC8B,gCAAgC;6BACjC,+BAA+B;8BAC9B,gCAAgC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"8BAC8B,gCAAgC;6BACjC,+BAA+B;8BAC9B,gCAAgC;0BAHpC,0BAA0B"}