@devvit/reddit 0.11.17-next-2025-05-28-417d95f5a.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.
Files changed (97) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +5 -0
  3. package/RedditClient.d.ts +1155 -0
  4. package/RedditClient.d.ts.map +1 -0
  5. package/RedditClient.js +1417 -0
  6. package/common.d.ts +10 -0
  7. package/common.d.ts.map +1 -0
  8. package/common.js +5 -0
  9. package/getReddit.d.ts +3 -0
  10. package/getReddit.d.ts.map +1 -0
  11. package/getReddit.js +8 -0
  12. package/getRedditApiPlugins.d.ts +23 -0
  13. package/getRedditApiPlugins.d.ts.map +1 -0
  14. package/getRedditApiPlugins.js +25 -0
  15. package/getUserActionsPlugin.d.ts +6 -0
  16. package/getUserActionsPlugin.d.ts.map +1 -0
  17. package/getUserActionsPlugin.js +12 -0
  18. package/graphql/GraphQL.d.ts +10 -0
  19. package/graphql/GraphQL.d.ts.map +1 -0
  20. package/graphql/GraphQL.js +27 -0
  21. package/helpers/makeGettersEnumerable.d.ts +2 -0
  22. package/helpers/makeGettersEnumerable.d.ts.map +1 -0
  23. package/helpers/makeGettersEnumerable.js +19 -0
  24. package/helpers/permissions.d.ts +6 -0
  25. package/helpers/permissions.d.ts.map +1 -0
  26. package/helpers/permissions.js +24 -0
  27. package/helpers/richtextToString.d.ts +3 -0
  28. package/helpers/richtextToString.d.ts.map +1 -0
  29. package/helpers/richtextToString.js +14 -0
  30. package/helpers/textFallbackToRichtext.d.ts +4 -0
  31. package/helpers/textFallbackToRichtext.d.ts.map +1 -0
  32. package/helpers/textFallbackToRichtext.js +14 -0
  33. package/index.d.ts +3 -0
  34. package/index.d.ts.map +1 -0
  35. package/index.js +1 -0
  36. package/models/Comment.d.ts +138 -0
  37. package/models/Comment.d.ts.map +1 -0
  38. package/models/Comment.js +597 -0
  39. package/models/Flair.d.ts +171 -0
  40. package/models/Flair.d.ts.map +1 -0
  41. package/models/Flair.js +293 -0
  42. package/models/Listing.d.ts +53 -0
  43. package/models/Listing.d.ts.map +1 -0
  44. package/models/Listing.js +101 -0
  45. package/models/ModAction.d.ts +32 -0
  46. package/models/ModAction.d.ts.map +1 -0
  47. package/models/ModAction.js +70 -0
  48. package/models/ModMail.d.ts +655 -0
  49. package/models/ModMail.d.ts.map +1 -0
  50. package/models/ModMail.js +723 -0
  51. package/models/ModNote.d.ts +57 -0
  52. package/models/ModNote.d.ts.map +1 -0
  53. package/models/ModNote.js +103 -0
  54. package/models/Post.d.ts +491 -0
  55. package/models/Post.d.ts.map +1 -0
  56. package/models/Post.js +1022 -0
  57. package/models/PrivateMessage.d.ts +52 -0
  58. package/models/PrivateMessage.d.ts.map +1 -0
  59. package/models/PrivateMessage.js +126 -0
  60. package/models/Subreddit.d.ts +606 -0
  61. package/models/Subreddit.d.ts.map +1 -0
  62. package/models/Subreddit.js +750 -0
  63. package/models/User.d.ts +238 -0
  64. package/models/User.d.ts.map +1 -0
  65. package/models/User.js +458 -0
  66. package/models/Vault.d.ts +32 -0
  67. package/models/Vault.d.ts.map +1 -0
  68. package/models/Vault.js +25 -0
  69. package/models/Widget.d.ts +133 -0
  70. package/models/Widget.d.ts.map +1 -0
  71. package/models/Widget.js +467 -0
  72. package/models/WikiPage.d.ts +137 -0
  73. package/models/WikiPage.d.ts.map +1 -0
  74. package/models/WikiPage.js +329 -0
  75. package/models/index.d.ts +14 -0
  76. package/models/index.d.ts.map +1 -0
  77. package/models/index.js +13 -0
  78. package/package.json +46 -0
  79. package/tests/comment.api.test.d.ts.map +1 -0
  80. package/tests/flair.api.test.d.ts.map +1 -0
  81. package/tests/modmail.api.test.d.ts.map +1 -0
  82. package/tests/modnote.api.test.d.ts.map +1 -0
  83. package/tests/post.api.test.d.ts.map +1 -0
  84. package/tests/subreddit.api.test.d.ts.map +1 -0
  85. package/tests/user.api.test.d.ts.map +1 -0
  86. package/tests/utils/createTestPreview.d.ts +2 -0
  87. package/tests/utils/createTestPreview.d.ts.map +1 -0
  88. package/tests/utils/createTestPreview.js +5 -0
  89. package/tests/utils/redditApiPluginsMock.d.ts +203 -0
  90. package/tests/utils/redditApiPluginsMock.d.ts.map +1 -0
  91. package/tests/utils/redditApiPluginsMock.js +202 -0
  92. package/tests/utils/runWithTestContext.d.ts +4 -0
  93. package/tests/utils/runWithTestContext.d.ts.map +1 -0
  94. package/tests/utils/runWithTestContext.js +12 -0
  95. package/tests/utils/userActionsPluginMock.d.ts +6 -0
  96. package/tests/utils/userActionsPluginMock.d.ts.map +1 -0
  97. package/tests/utils/userActionsPluginMock.js +5 -0
@@ -0,0 +1,750 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _a, _Subreddit_id, _Subreddit_name, _Subreddit_createdAt, _Subreddit_type, _Subreddit_title, _Subreddit_description, _Subreddit_language, _Subreddit_numberOfSubscribers, _Subreddit_numberOfActiveUsers, _Subreddit_nsfw, _Subreddit_settings, _Subreddit_permalink, _Subreddit_metadata_get;
13
+ import { getContext } from '@devvit/server';
14
+ import { assertNonNull } from '@devvit/shared-types/NonNull.js';
15
+ import { asT5ID } from '@devvit/shared-types/tid.js';
16
+ import { getRedditApiPlugins } from '../getRedditApiPlugins.js';
17
+ import { GraphQL } from '../graphql/GraphQL.js';
18
+ import { makeGettersEnumerable } from '../helpers/makeGettersEnumerable.js';
19
+ import { Comment } from './Comment.js';
20
+ import { convertUserFlairProtoToAPI, Flair, FlairTemplate } from './Flair.js';
21
+ import { Listing } from './Listing.js';
22
+ import { getModerationLog } from './ModAction.js';
23
+ import { Post } from './Post.js';
24
+ import { User } from './User.js';
25
+ export var AboutLocations;
26
+ (function (AboutLocations) {
27
+ AboutLocations["Reports"] = "reports";
28
+ AboutLocations["Spam"] = "spam";
29
+ AboutLocations["Modqueue"] = "modqueue";
30
+ AboutLocations["Unmoderated"] = "unmoderated";
31
+ AboutLocations["Edited"] = "edited";
32
+ })(AboutLocations || (AboutLocations = {}));
33
+ export class SubredditDescription {
34
+ }
35
+ export class SubredditWikiSettings {
36
+ }
37
+ export class AuthorFlairSettings {
38
+ }
39
+ export class PostFlairSettings {
40
+ }
41
+ /**
42
+ * A class representing a subreddit.
43
+ */
44
+ export class Subreddit {
45
+ /**
46
+ * @internal
47
+ */
48
+ constructor(data) {
49
+ _Subreddit_id.set(this, void 0);
50
+ _Subreddit_name.set(this, void 0);
51
+ _Subreddit_createdAt.set(this, void 0);
52
+ _Subreddit_type.set(this, void 0);
53
+ _Subreddit_title.set(this, void 0);
54
+ _Subreddit_description.set(this, void 0);
55
+ _Subreddit_language.set(this, void 0);
56
+ _Subreddit_numberOfSubscribers.set(this, void 0);
57
+ _Subreddit_numberOfActiveUsers.set(this, void 0);
58
+ _Subreddit_nsfw.set(this, void 0);
59
+ _Subreddit_settings.set(this, void 0);
60
+ // R2 bug: subreddit does not contain a permalink field, but uses the url field instead
61
+ _Subreddit_permalink.set(this, void 0);
62
+ makeGettersEnumerable(this);
63
+ assertNonNull(data.id, 'Subreddit id is missing or undefined');
64
+ assertNonNull(data.displayName, 'Subreddit name is missing or undefined');
65
+ __classPrivateFieldSet(this, _Subreddit_id, asT5ID(`t5_${data.id}`), "f");
66
+ __classPrivateFieldSet(this, _Subreddit_name, data.displayName, "f");
67
+ assertNonNull(data.createdUtc, 'Subreddit is missing created date');
68
+ const createdAt = new Date(0);
69
+ createdAt.setUTCSeconds(data.createdUtc);
70
+ __classPrivateFieldSet(this, _Subreddit_createdAt, createdAt, "f");
71
+ __classPrivateFieldSet(this, _Subreddit_type, asSubredditType(data.subredditType), "f");
72
+ __classPrivateFieldSet(this, _Subreddit_title, data.title, "f");
73
+ __classPrivateFieldSet(this, _Subreddit_description, data.description, "f");
74
+ assertNonNull(data.lang, 'Subreddit is missing language');
75
+ __classPrivateFieldSet(this, _Subreddit_language, data.lang, "f");
76
+ __classPrivateFieldSet(this, _Subreddit_numberOfSubscribers, data.subscribers ?? 0, "f");
77
+ __classPrivateFieldSet(this, _Subreddit_numberOfActiveUsers, data.activeUserCount ?? 0, "f");
78
+ __classPrivateFieldSet(this, _Subreddit_nsfw, data.over18 ?? false, "f");
79
+ __classPrivateFieldSet(this, _Subreddit_permalink, data.url ?? '', "f");
80
+ __classPrivateFieldSet(this, _Subreddit_settings, {
81
+ acceptFollowers: data.acceptFollowers ?? false,
82
+ allOriginalContent: data.allOriginalContent ?? false,
83
+ allowChatPostCreation: data.allowChatPostCreation ?? false,
84
+ allowDiscovery: data.allowDiscovery ?? false,
85
+ allowGalleries: data.allowGalleries ?? false,
86
+ allowImages: data.allowImages ?? false,
87
+ allowPolls: data.allowPolls ?? false,
88
+ allowPredictionContributors: data.allowPredictionContributors ?? false,
89
+ allowPredictions: data.allowPredictions ?? false,
90
+ allowPredictionsTournament: data.allowPredictionsTournament ?? false,
91
+ allowTalks: data.allowTalks ?? false,
92
+ allowVideoGifs: data.allowVideogifs ?? false,
93
+ allowVideos: data.allowVideos ?? false,
94
+ chatPostEnabled: data.isChatPostFeatureEnabled ?? false,
95
+ collectionsEnabled: data.collectionsEnabled ?? false,
96
+ crosspostable: data.isCrosspostableSubreddit ?? false,
97
+ emojisEnabled: data.emojisEnabled ?? false,
98
+ eventPostsEnabled: data.eventPostsEnabled ?? false,
99
+ linkFlairEnabled: data.linkFlairEnabled ?? false,
100
+ originalContentTagEnabled: data.originalContentTagEnabled ?? false,
101
+ restrictCommenting: data.restrictCommenting ?? false,
102
+ restrictPosting: data.restrictPosting ?? false,
103
+ shouldArchivePosts: data.shouldArchivePosts ?? false,
104
+ spoilersEnabled: data.spoilersEnabled ?? false,
105
+ wikiEnabled: data.wikiEnabled ?? false,
106
+ allowedPostType: asAllowedPostType(data.submissionType),
107
+ allowedMediaInComments: (data.allowedMediaInComments ?? []).map(asCommentMediaTypes),
108
+ bannerBackgroundColor: data.bannerBackgroundColor,
109
+ bannerBackgroundImage: data.bannerBackgroundImage,
110
+ bannerImage: data.bannerImg,
111
+ communityIcon: data.communityIcon,
112
+ headerTitle: data.headerTitle,
113
+ keyColor: data.keyColor,
114
+ mobileBannerImage: data.mobileBannerImage,
115
+ primaryColor: data.primaryColor,
116
+ userFlairs: {
117
+ enabled: data.userFlairEnabledInSr ?? false,
118
+ usersCanAssign: data.canAssignUserFlair ?? false,
119
+ userFlairBackgroundColor: data.userFlairBackgroundColor,
120
+ userFlairTextColor: data.userFlairTextColor,
121
+ },
122
+ postFlairs: {
123
+ enabled: data.linkFlairEnabled ?? false,
124
+ usersCanAssign: data.canAssignLinkFlair ?? false,
125
+ },
126
+ // R2 bug: url is a permalink
127
+ url: new URL(__classPrivateFieldGet(this, _Subreddit_permalink, "f"), 'https://www.reddit.com').toString(),
128
+ }, "f");
129
+ }
130
+ /**
131
+ * The ID (starting with t5_) of the subreddit to retrieve. e.g. t5_2qjpg
132
+ */
133
+ get id() {
134
+ return __classPrivateFieldGet(this, _Subreddit_id, "f");
135
+ }
136
+ /**
137
+ * The name of a subreddit omitting the r/.
138
+ */
139
+ get name() {
140
+ return __classPrivateFieldGet(this, _Subreddit_name, "f");
141
+ }
142
+ /**
143
+ * The creation date of the subreddit.
144
+ */
145
+ get createdAt() {
146
+ return __classPrivateFieldGet(this, _Subreddit_createdAt, "f");
147
+ }
148
+ /**
149
+ * The type of subreddit (public, private, etc.).
150
+ */
151
+ get type() {
152
+ return __classPrivateFieldGet(this, _Subreddit_type, "f");
153
+ }
154
+ /**
155
+ * The title of the subreddit.
156
+ */
157
+ get title() {
158
+ return __classPrivateFieldGet(this, _Subreddit_title, "f");
159
+ }
160
+ /**
161
+ * The description of the subreddit.
162
+ */
163
+ get description() {
164
+ return __classPrivateFieldGet(this, _Subreddit_description, "f");
165
+ }
166
+ /**
167
+ * The language of the subreddit.
168
+ */
169
+ get language() {
170
+ return __classPrivateFieldGet(this, _Subreddit_language, "f");
171
+ }
172
+ /**
173
+ * The number of subscribers of the subreddit.
174
+ */
175
+ get numberOfSubscribers() {
176
+ return __classPrivateFieldGet(this, _Subreddit_numberOfSubscribers, "f");
177
+ }
178
+ /**
179
+ * The number of active users of the subreddit.
180
+ */
181
+ get numberOfActiveUsers() {
182
+ return __classPrivateFieldGet(this, _Subreddit_numberOfActiveUsers, "f");
183
+ }
184
+ /**
185
+ * Whether the subreddit is marked as NSFW (Not Safe For Work).
186
+ */
187
+ get nsfw() {
188
+ return __classPrivateFieldGet(this, _Subreddit_nsfw, "f");
189
+ }
190
+ /**
191
+ * The settings of the subreddit.
192
+ */
193
+ get settings() {
194
+ return __classPrivateFieldGet(this, _Subreddit_settings, "f");
195
+ }
196
+ /**
197
+ * Whether the user flairs are enabled for this subreddit.
198
+ */
199
+ get userFlairsEnabled() {
200
+ return this.settings.userFlairs.enabled;
201
+ }
202
+ /**
203
+ * Whether the post flairs are enabled for this subreddit.
204
+ */
205
+ get postFlairsEnabled() {
206
+ return this.settings.postFlairs.enabled;
207
+ }
208
+ /**
209
+ * Whether the user can assign user flairs.
210
+ * This is only true if the user flairs are enabled.
211
+ */
212
+ get usersCanAssignUserFlairs() {
213
+ return this.settings.userFlairs.usersCanAssign;
214
+ }
215
+ /**
216
+ * Whether the user can assign post flairs.
217
+ * This is only true if the post flairs are enabled.
218
+ */
219
+ get usersCanAssignPostFlairs() {
220
+ return this.settings.postFlairs.usersCanAssign;
221
+ }
222
+ /**
223
+ * Returns the HTTP URL for the subreddit.
224
+ * (R2 bug: subreddit.url is a permalink path and does not return a fully qualified URL in subreddit.url)
225
+ */
226
+ get url() {
227
+ return this.settings.url;
228
+ }
229
+ /**
230
+ * Returns a permalink path
231
+ * (R2 bug: subreddit.url is a permalink, and does not have a subreddit.permalink field)
232
+ */
233
+ get permalink() {
234
+ return __classPrivateFieldGet(this, _Subreddit_permalink, "f");
235
+ }
236
+ toJSON() {
237
+ return {
238
+ id: this.id,
239
+ name: this.name,
240
+ createdAt: this.createdAt,
241
+ type: this.type,
242
+ title: this.title,
243
+ description: this.description,
244
+ language: this.language,
245
+ nsfw: this.nsfw,
246
+ numberOfSubscribers: this.numberOfSubscribers,
247
+ numberOfActiveUsers: this.numberOfActiveUsers,
248
+ settings: this.settings,
249
+ };
250
+ }
251
+ async submitPost(options) {
252
+ const submitPostOptions = {
253
+ ...options,
254
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
255
+ };
256
+ return Post.submit(submitPostOptions);
257
+ }
258
+ getControversialPosts(options = {}) {
259
+ if (!__classPrivateFieldGet(this, _Subreddit_name, "f")) {
260
+ throw new Error('subreddit missing displayName - it might not have been fetched');
261
+ }
262
+ return Post.getControversialPosts({
263
+ ...options,
264
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
265
+ });
266
+ }
267
+ getTopPosts(options = {}) {
268
+ if (!__classPrivateFieldGet(this, _Subreddit_name, "f")) {
269
+ throw new Error('subreddit missing displayName - it might not have been fetched');
270
+ }
271
+ return Post.getTopPosts({
272
+ ...options,
273
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
274
+ });
275
+ }
276
+ getApprovedUsers(options = {}) {
277
+ return User.getSubredditUsersByType({
278
+ type: 'contributors',
279
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
280
+ ...options,
281
+ });
282
+ }
283
+ approveUser(username) {
284
+ return User.createRelationship({
285
+ username,
286
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
287
+ type: 'contributor',
288
+ });
289
+ }
290
+ removeUser(username) {
291
+ return User.removeRelationship({
292
+ username,
293
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
294
+ type: 'contributor',
295
+ });
296
+ }
297
+ getWikiContributors(options = {}) {
298
+ return User.getSubredditUsersByType({
299
+ type: 'wikicontributors',
300
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
301
+ ...options,
302
+ });
303
+ }
304
+ addWikiContributor(username) {
305
+ return User.createRelationship({
306
+ username,
307
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
308
+ type: 'wikicontributor',
309
+ });
310
+ }
311
+ removeWikiContributor(username) {
312
+ return User.removeRelationship({
313
+ username,
314
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
315
+ type: 'wikicontributor',
316
+ });
317
+ }
318
+ getBannedUsers(options = {}) {
319
+ return User.getSubredditUsersByType({
320
+ type: 'banned',
321
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
322
+ ...options,
323
+ });
324
+ }
325
+ banUser(options) {
326
+ return User.createRelationship({
327
+ username: options.username,
328
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
329
+ type: 'banned',
330
+ banReason: options.reason,
331
+ banMessage: options.message,
332
+ note: options.note,
333
+ duration: options.duration,
334
+ banContext: options.context,
335
+ });
336
+ }
337
+ unbanUser(username) {
338
+ return User.removeRelationship({
339
+ username,
340
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
341
+ type: 'banned',
342
+ });
343
+ }
344
+ getBannedWikiContributors(options = {}) {
345
+ return User.getSubredditUsersByType({
346
+ type: 'wikibanned',
347
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
348
+ ...options,
349
+ });
350
+ }
351
+ banWikiContributor(options) {
352
+ return User.createRelationship({
353
+ username: options.username,
354
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
355
+ type: 'wikibanned',
356
+ banReason: options.reason,
357
+ note: options.note,
358
+ duration: options.duration,
359
+ });
360
+ }
361
+ unbanWikiContributor(username) {
362
+ return User.removeRelationship({
363
+ username,
364
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
365
+ type: 'wikibanned',
366
+ });
367
+ }
368
+ getModerators(options = {}) {
369
+ return User.getSubredditUsersByType({
370
+ type: 'moderators',
371
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
372
+ ...options,
373
+ });
374
+ }
375
+ inviteModerator(username, permissions) {
376
+ return User.createRelationship({
377
+ type: 'moderator_invite',
378
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
379
+ username,
380
+ permissions: permissions ?? [],
381
+ });
382
+ }
383
+ revokeModeratorInvite(username) {
384
+ return User.removeRelationship({
385
+ username,
386
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
387
+ type: 'moderator_invite',
388
+ });
389
+ }
390
+ removeModerator(username) {
391
+ return User.removeRelationship({
392
+ type: 'moderator',
393
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
394
+ username,
395
+ });
396
+ }
397
+ setModeratorPermissions(username, permissions) {
398
+ return User.setModeratorPermissions(username, __classPrivateFieldGet(this, _Subreddit_name, "f"), permissions);
399
+ }
400
+ getMutedUsers(options = {}) {
401
+ return User.getSubredditUsersByType({
402
+ type: 'muted',
403
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
404
+ ...options,
405
+ });
406
+ }
407
+ muteUser(username, note) {
408
+ return User.createRelationship({
409
+ username,
410
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
411
+ type: 'muted',
412
+ note,
413
+ });
414
+ }
415
+ unmuteUser(username) {
416
+ return User.removeRelationship({
417
+ username,
418
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
419
+ type: 'muted',
420
+ });
421
+ }
422
+ getModerationLog(options) {
423
+ return getModerationLog({
424
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
425
+ ...options,
426
+ });
427
+ }
428
+ getUserFlairTemplates() {
429
+ return FlairTemplate.getUserFlairTemplates(__classPrivateFieldGet(this, _Subreddit_name, "f"));
430
+ }
431
+ getPostFlairTemplates() {
432
+ return FlairTemplate.getPostFlairTemplates(__classPrivateFieldGet(this, _Subreddit_name, "f"));
433
+ }
434
+ createPostFlairTemplate(options) {
435
+ return FlairTemplate.createPostFlairTemplate({
436
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
437
+ ...options,
438
+ });
439
+ }
440
+ createUserFlairTemplate(options) {
441
+ return FlairTemplate.createUserFlairTemplate({
442
+ subredditName: __classPrivateFieldGet(this, _Subreddit_name, "f"),
443
+ ...options,
444
+ });
445
+ }
446
+ /**
447
+ * Get the user flair for the given subreddit. If `usernames` is provided then it will return only the
448
+ * flair for the specified users. If retrieving the list of flair for a given subreddit and the list is long
449
+ * then this method will return a `next` field which can be passed into the `after` field on the next call to
450
+ * retrieve the next slice of data. To retrieve the previous slice of data pass the `prev` field into the `before` field
451
+ * during the subsequent call.
452
+ *
453
+ * @param options See interface
454
+ *
455
+ * @example
456
+ * ```ts
457
+ * const subredditName = "mysubreddit"
458
+ * const subreddit = await reddit.getSubredditByName(subredditName)
459
+ * const response = await subreddit.getUserFlair();
460
+ * const userFlairList = response.users
461
+ * ```
462
+ * @example
463
+ * ```ts
464
+ * const response = await subreddit.getUserFlair({ after: "t2_awefae"});
465
+ * const userFlairList = response.users
466
+ * ```
467
+ *
468
+ * @example
469
+ * ```ts
470
+ * const response = await subreddit.getUserFlair({ usernames: ['toxictoad', 'badapple']});
471
+ * const userFlairList = response.users
472
+ * ```
473
+ */
474
+ async getUserFlair(options) {
475
+ if (options?.usernames !== undefined) {
476
+ const users = await Promise.all(options.usernames.map(async (name) => {
477
+ const response = await Flair.getUserFlairBySubreddit({
478
+ subreddit: __classPrivateFieldGet(this, _Subreddit_name, "f"),
479
+ name,
480
+ });
481
+ return convertUserFlairProtoToAPI(response.users[0]);
482
+ }));
483
+ return { users };
484
+ }
485
+ else {
486
+ const response = await Flair.getUserFlairBySubreddit({
487
+ ...options,
488
+ subreddit: __classPrivateFieldGet(this, _Subreddit_name, "f"),
489
+ });
490
+ return {
491
+ next: response.next,
492
+ prev: response.prev,
493
+ users: response.users.map((userFlair) => convertUserFlairProtoToAPI(userFlair)),
494
+ };
495
+ }
496
+ }
497
+ getModQueue(options = { type: 'all' }) {
498
+ return _a.aboutLocation({
499
+ ...options,
500
+ location: AboutLocations.Modqueue,
501
+ subreddit: __classPrivateFieldGet(this, _Subreddit_name, "f"),
502
+ });
503
+ }
504
+ getReports(options = { type: 'all' }) {
505
+ return _a.aboutLocation({
506
+ ...options,
507
+ location: AboutLocations.Reports,
508
+ subreddit: __classPrivateFieldGet(this, _Subreddit_name, "f"),
509
+ });
510
+ }
511
+ getSpam(options = { type: 'all' }) {
512
+ return _a.aboutLocation({
513
+ ...options,
514
+ location: AboutLocations.Spam,
515
+ subreddit: __classPrivateFieldGet(this, _Subreddit_name, "f"),
516
+ });
517
+ }
518
+ getUnmoderated(options = { type: 'all' }) {
519
+ return _a.aboutLocation({
520
+ ...options,
521
+ location: AboutLocations.Unmoderated,
522
+ subreddit: __classPrivateFieldGet(this, _Subreddit_name, "f"),
523
+ });
524
+ }
525
+ getEdited(options = { type: 'all' }) {
526
+ return _a.aboutLocation({
527
+ ...options,
528
+ location: AboutLocations.Edited,
529
+ subreddit: __classPrivateFieldGet(this, _Subreddit_name, "f"),
530
+ });
531
+ }
532
+ /** @internal */
533
+ static aboutLocation(options) {
534
+ const client = getRedditApiPlugins().Moderation;
535
+ let only;
536
+ switch (options.type) {
537
+ case 'post':
538
+ only = 'links';
539
+ break;
540
+ case 'comment':
541
+ only = 'comments';
542
+ break;
543
+ default:
544
+ only = undefined;
545
+ }
546
+ return new Listing({
547
+ ...options,
548
+ fetch: async (fetchOptions) => {
549
+ const listing = await client.AboutLocation({
550
+ ...fetchOptions,
551
+ ...options,
552
+ only,
553
+ }, __classPrivateFieldGet(this, _a, "a", _Subreddit_metadata_get));
554
+ return parseListing(listing);
555
+ },
556
+ });
557
+ }
558
+ /**
559
+ * Return a listing of things specified by their fullnames.
560
+ *
561
+ * @param ids Array of thing full ids (e.g. t3_abc123)
562
+ * @example
563
+ * ```ts
564
+ * const subreddit = await reddit.getSubredditByName('askReddit');
565
+ * const listing = subreddit.getCommentsAndPostsByIds(['t3_abc123', 't1_xyz123']);
566
+ * const items = await listing.all();
567
+ * console.log(items) // [Post, Comment]
568
+ * ```
569
+ */
570
+ getCommentsAndPostsByIds(ids) {
571
+ const client = getRedditApiPlugins().LinksAndComments;
572
+ return new Listing({
573
+ fetch: async () => {
574
+ const listing = await client.Info({ thingIds: ids, subreddits: [__classPrivateFieldGet(this, _Subreddit_id, "f")] }, getContext().debug.metadata);
575
+ return parseListing(listing);
576
+ },
577
+ });
578
+ }
579
+ /** @internal */
580
+ static async addRemovalReason(subredditName, title, message) {
581
+ const client = getRedditApiPlugins().Subreddits;
582
+ const response = await client.SubredditAddRemovalReason({
583
+ title,
584
+ message,
585
+ subreddit: subredditName,
586
+ }, __classPrivateFieldGet(this, _a, "a", _Subreddit_metadata_get));
587
+ return response.id;
588
+ }
589
+ /** @internal */
590
+ static async getRemovalReasons(subredditName) {
591
+ const client = getRedditApiPlugins().Subreddits;
592
+ const result = await client.SubredditGetRemovalReasons({
593
+ subreddit: subredditName,
594
+ }, __classPrivateFieldGet(this, _a, "a", _Subreddit_metadata_get));
595
+ return result.order.map((id) => ({ ...result.data[id] }));
596
+ }
597
+ /** @internal */
598
+ static async getFromMetadata() {
599
+ const subredditName = getContext().subredditName;
600
+ if (subredditName) {
601
+ return _a.getByName(subredditName);
602
+ }
603
+ const subredditId = getContext().subredditId;
604
+ assertNonNull(subredditId);
605
+ return _a.getById(asT5ID(subredditId));
606
+ }
607
+ /** @internal */
608
+ static async getById(id) {
609
+ const subredditName = await getSubredditNameById(id);
610
+ if (!subredditName) {
611
+ return;
612
+ }
613
+ return _a.getByName(subredditName);
614
+ }
615
+ /** @internal */
616
+ static async getByName(subredditName) {
617
+ const client = getRedditApiPlugins().Subreddits;
618
+ const response = await client.SubredditAbout({
619
+ subreddit: subredditName,
620
+ }, __classPrivateFieldGet(this, _a, "a", _Subreddit_metadata_get));
621
+ if (!response?.data) {
622
+ throw new Error('not found');
623
+ }
624
+ return new _a(response.data);
625
+ }
626
+ }
627
+ _a = Subreddit, _Subreddit_id = new WeakMap(), _Subreddit_name = new WeakMap(), _Subreddit_createdAt = new WeakMap(), _Subreddit_type = new WeakMap(), _Subreddit_title = new WeakMap(), _Subreddit_description = new WeakMap(), _Subreddit_language = new WeakMap(), _Subreddit_numberOfSubscribers = new WeakMap(), _Subreddit_numberOfActiveUsers = new WeakMap(), _Subreddit_nsfw = new WeakMap(), _Subreddit_settings = new WeakMap(), _Subreddit_permalink = new WeakMap(), _Subreddit_metadata_get = function _Subreddit_metadata_get() {
628
+ return getContext().debug.metadata;
629
+ };
630
+ /**
631
+ * Gets a {@link SubredditInfo} object by ID
632
+ *
633
+ * @param {string} subredditId - The ID (starting with t5_) of the subreddit to retrieve. e.g. t5_2qjpg
634
+ * @returns {Promise<SubredditInfo>} A Promise that resolves a SubredditInfo object.
635
+ */
636
+ export async function getSubredditInfoById(subredditId) {
637
+ const operationName = 'GetSubredditInfoById';
638
+ const persistedQueryHash = '315a9b75c22a017d526afdf2d274616946156451aacfd56dfb91e7ad3f7a2fde';
639
+ const response = await GraphQL.query(operationName, persistedQueryHash, { id: subredditId });
640
+ const subredditInfo = response.data?.subredditInfoById;
641
+ if (!subredditInfo)
642
+ throw new Error('subreddit info not found');
643
+ return subredditInfo;
644
+ }
645
+ /**
646
+ * Gets a {@link SubredditInfo} object by name
647
+ *
648
+ * @param {string} subredditName The name of a subreddit omitting the r/. This is case-insensitive.
649
+ * @returns {Promise<SubredditInfo>} A Promise that resolves a SubredditInfo object.
650
+ */
651
+ export async function getSubredditInfoByName(subredditName) {
652
+ const operationName = 'GetSubredditInfoByName';
653
+ const persistedQueryHash = '4aa69726c7e3f5d33ab2bee22b3d74fce645824fddd5ea3ec6dfe30bdb4295cb';
654
+ const response = await GraphQL.query(operationName, persistedQueryHash, { name: subredditName });
655
+ const subredditInfo = response.data?.subredditInfoByName;
656
+ if (!subredditInfo)
657
+ throw new Error('subreddit info not found');
658
+ return subredditInfo;
659
+ }
660
+ export async function getSubredditLeaderboard(subredditId) {
661
+ const operationName = 'GetSubredditLeaderboard';
662
+ const persistedQueryHash = '18ead70c46b6446d45ecd8b679b16d9a929a933d6ef25d8262a459cb18b72848';
663
+ const response = await GraphQL.query(operationName, persistedQueryHash, { id: subredditId });
664
+ const leaderboard = response.data?.subredditInfoById?.leaderboard;
665
+ if (!leaderboard)
666
+ throw new Error('subreddit leaderboard not found');
667
+ if (!leaderboard.summary)
668
+ throw new Error('subreddit leaderboard summary not found');
669
+ return {
670
+ id: leaderboard.id,
671
+ summary: leaderboard.summary,
672
+ };
673
+ }
674
+ export async function getSubredditStyles(subredditId) {
675
+ const operationName = 'GetSubredditStyles';
676
+ const persistedQueryHash = 'd491d17ea8858f563ea578b26b9595d64adecf4bf34557d567c7e53c470f5f22';
677
+ const response = await GraphQL.query(operationName, persistedQueryHash, { id: subredditId });
678
+ const styles = response.data?.subredditInfoById?.styles;
679
+ if (!styles)
680
+ throw new Error('subreddit styles not found');
681
+ return styles;
682
+ }
683
+ function asSubredditType(type) {
684
+ if (type === 'public' ||
685
+ type === 'private' ||
686
+ type === 'restricted' ||
687
+ type === 'employees_only' ||
688
+ type === 'gold_only' ||
689
+ type === 'gold_restricted' ||
690
+ type === 'archived' ||
691
+ type === 'user') {
692
+ return type;
693
+ }
694
+ throw new Error(`invalid subreddit type: ${type}`);
695
+ }
696
+ function asAllowedPostType(type) {
697
+ if (type === 'any' || type === 'link' || type === 'self') {
698
+ return type;
699
+ }
700
+ throw new Error(`invalid allowed post type: ${type}`);
701
+ }
702
+ function asCommentMediaTypes(type) {
703
+ if (type === 'animated' || type === 'giphy' || type === 'static' || type === 'expression') {
704
+ return type;
705
+ }
706
+ throw new Error(`invalid comment media type: ${type}`);
707
+ }
708
+ function parseListing(listing) {
709
+ const children = listing.data?.children ?? [];
710
+ const postsAndComments = children
711
+ .map((child) => {
712
+ const post = tryParseAsPost(child);
713
+ if (post != null) {
714
+ return post;
715
+ }
716
+ const comment = tryParseAsComment(child);
717
+ if (comment != null) {
718
+ return comment;
719
+ }
720
+ return null;
721
+ })
722
+ .filter(Boolean);
723
+ return {
724
+ after: listing.data?.after,
725
+ before: listing.data?.before,
726
+ children: postsAndComments,
727
+ };
728
+ function tryParseAsPost(obj) {
729
+ try {
730
+ return new Post(obj.data);
731
+ }
732
+ catch {
733
+ return null;
734
+ }
735
+ }
736
+ function tryParseAsComment(obj) {
737
+ try {
738
+ return new Comment(obj.data);
739
+ }
740
+ catch {
741
+ return null;
742
+ }
743
+ }
744
+ }
745
+ /** @internal */
746
+ export async function getSubredditNameById(id) {
747
+ const client = getRedditApiPlugins().LinksAndComments;
748
+ const response = await client.Info({ thingIds: [id], subreddits: [] }, getContext().debug.metadata);
749
+ return response.data?.children[0]?.data?.displayName;
750
+ }