@devvit/public-api 0.12.0-next-2025-04-30-5d2b49b36.0 → 0.12.0-next-2025-08-12-20-06-14-50f19bb3e.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 (173) hide show
  1. package/apis/AssetsClient/AssetsClient.d.ts +2 -2
  2. package/apis/AssetsClient/AssetsClient.d.ts.map +1 -1
  3. package/apis/AssetsClient/AssetsClient.js +5 -7
  4. package/apis/key-value-storage/KeyValueStorage.d.ts +1 -1
  5. package/apis/key-value-storage/KeyValueStorage.d.ts.map +1 -1
  6. package/apis/makeAPIClients.d.ts.map +1 -1
  7. package/apis/makeAPIClients.js +3 -0
  8. package/apis/media/MediaClient.js +1 -1
  9. package/apis/realtime/RealtimeClient.d.ts +1 -1
  10. package/apis/realtime/RealtimeClient.d.ts.map +1 -1
  11. package/apis/reddit/RedditAPIClient.d.ts +41 -41
  12. package/apis/reddit/RedditAPIClient.d.ts.map +1 -1
  13. package/apis/reddit/RedditAPIClient.js +150 -151
  14. package/apis/reddit/models/Comment.d.ts +4 -1
  15. package/apis/reddit/models/Comment.d.ts.map +1 -1
  16. package/apis/reddit/models/Comment.js +4 -1
  17. package/apis/reddit/models/Flair.d.ts +1 -1
  18. package/apis/reddit/models/Flair.d.ts.map +1 -1
  19. package/apis/reddit/models/Flair.js +2 -2
  20. package/apis/reddit/models/Listing.d.ts +1 -1
  21. package/apis/reddit/models/Listing.d.ts.map +1 -1
  22. package/apis/reddit/models/ModAction.d.ts +3 -0
  23. package/apis/reddit/models/ModAction.d.ts.map +1 -1
  24. package/apis/reddit/models/ModAction.js +1 -2
  25. package/apis/reddit/models/ModMail.d.ts +23 -23
  26. package/apis/reddit/models/ModMail.js +24 -24
  27. package/apis/reddit/models/ModNote.d.ts +1 -1
  28. package/apis/reddit/models/ModNote.d.ts.map +1 -1
  29. package/apis/reddit/models/ModNote.js +1 -1
  30. package/apis/reddit/models/Post.d.ts +32 -5
  31. package/apis/reddit/models/Post.d.ts.map +1 -1
  32. package/apis/reddit/models/Post.js +74 -7
  33. package/apis/reddit/models/PrivateMessage.d.ts +1 -1
  34. package/apis/reddit/models/PrivateMessage.d.ts.map +1 -1
  35. package/apis/reddit/models/PrivateMessage.js +1 -1
  36. package/apis/reddit/models/Subreddit.d.ts +27 -9
  37. package/apis/reddit/models/Subreddit.d.ts.map +1 -1
  38. package/apis/reddit/models/Subreddit.js +12 -18
  39. package/apis/reddit/models/User.d.ts +23 -2
  40. package/apis/reddit/models/User.d.ts.map +1 -1
  41. package/apis/reddit/models/User.js +2 -15
  42. package/apis/reddit/models/Vault.d.ts +4 -1
  43. package/apis/reddit/models/Vault.d.ts.map +1 -1
  44. package/apis/reddit/models/Vault.js +3 -8
  45. package/apis/reddit/models/index.d.ts +1 -1
  46. package/apis/reddit/models/index.d.ts.map +1 -1
  47. package/apis/reddit/models/index.js +1 -0
  48. package/apis/reddit/tests/utils/createTestRedditApiClient.d.ts +8 -0
  49. package/apis/reddit/tests/utils/createTestRedditApiClient.d.ts.map +1 -0
  50. package/apis/reddit/tests/utils/createTestRedditApiClient.js +16 -0
  51. package/apis/redis/RedisClient.d.ts +0 -1
  52. package/apis/redis/RedisClient.d.ts.map +1 -1
  53. package/apis/redis/RedisClient.js +6 -0
  54. package/apis/redis/RedisClient.tests.js +3 -0
  55. package/apis/scheduler/SchedulerClient.js +1 -1
  56. package/apis/ui/UIClient.d.ts +3 -1
  57. package/apis/ui/UIClient.d.ts.map +1 -1
  58. package/apis/ui/UIClient.js +13 -12
  59. package/devvit/Devvit.d.ts +2 -2
  60. package/devvit/Devvit.d.ts.map +1 -1
  61. package/devvit/Devvit.js +65 -18
  62. package/devvit/internals/app-settings.d.ts.map +1 -1
  63. package/devvit/internals/app-settings.js +1 -4
  64. package/devvit/internals/blocks/BlocksReconciler.d.ts +105 -0
  65. package/devvit/internals/blocks/BlocksReconciler.d.ts.map +1 -1
  66. package/devvit/internals/blocks/BlocksReconciler.js +15 -13
  67. package/devvit/internals/blocks/handler/BlocksHandler.d.ts.map +1 -1
  68. package/devvit/internals/blocks/handler/BlocksHandler.js +2 -1
  69. package/devvit/internals/blocks/handler/ContextBuilder.d.ts.map +1 -1
  70. package/devvit/internals/blocks/handler/ContextBuilder.js +3 -0
  71. package/devvit/internals/blocks/handler/UIClient.d.ts +7 -5
  72. package/devvit/internals/blocks/handler/UIClient.d.ts.map +1 -1
  73. package/devvit/internals/blocks/handler/UIClient.js +14 -13
  74. package/devvit/internals/blocks/handler/cache.d.ts +1 -1
  75. package/devvit/internals/blocks/handler/cache.d.ts.map +1 -1
  76. package/devvit/internals/blocks/handler/test-helpers.d.ts +1 -1
  77. package/devvit/internals/blocks/handler/test-helpers.d.ts.map +1 -1
  78. package/devvit/internals/blocks/handler/types.d.ts +1 -1
  79. package/devvit/internals/blocks/handler/types.d.ts.map +1 -1
  80. package/devvit/internals/blocks/handler/useAsync.d.ts +1 -1
  81. package/devvit/internals/blocks/handler/useAsync.d.ts.map +1 -1
  82. package/devvit/internals/blocks/handler/useChannel.d.ts +1 -1
  83. package/devvit/internals/blocks/handler/useChannel.d.ts.map +1 -1
  84. package/devvit/internals/blocks/handler/useForm.d.ts +1 -1
  85. package/devvit/internals/blocks/handler/useForm.d.ts.map +1 -1
  86. package/devvit/internals/blocks/handler/useState.d.ts +1 -1
  87. package/devvit/internals/blocks/handler/useState.d.ts.map +1 -1
  88. package/devvit/internals/blocks/handler/useWebView.d.ts +1 -1
  89. package/devvit/internals/blocks/handler/useWebView.d.ts.map +1 -1
  90. package/devvit/internals/blocks/handler/useWebView.js +23 -4
  91. package/devvit/internals/blocks/useChannel.d.ts.map +1 -1
  92. package/devvit/internals/cache.d.ts +1 -1
  93. package/devvit/internals/cache.d.ts.map +1 -1
  94. package/devvit/internals/context.d.ts +1 -1
  95. package/devvit/internals/context.d.ts.map +1 -1
  96. package/devvit/internals/context.js +10 -1
  97. package/devvit/internals/csrf.d.ts.map +1 -1
  98. package/devvit/internals/csrf.js +4 -5
  99. package/devvit/internals/helpers/color.d.ts +1 -1
  100. package/devvit/internals/helpers/color.d.ts.map +1 -1
  101. package/devvit/internals/helpers/devvitInternalMessage.d.ts.map +1 -1
  102. package/devvit/internals/helpers/devvitInternalMessage.js +1 -1
  103. package/devvit/internals/helpers/extendDevvitPrototype.d.ts +1 -6
  104. package/devvit/internals/helpers/extendDevvitPrototype.d.ts.map +1 -1
  105. package/devvit/internals/helpers/extendDevvitPrototype.js +1 -9
  106. package/devvit/internals/installation-settings.d.ts.map +1 -1
  107. package/devvit/internals/installation-settings.js +1 -4
  108. package/devvit/internals/menu-items.d.ts +1 -0
  109. package/devvit/internals/menu-items.d.ts.map +1 -1
  110. package/devvit/internals/menu-items.js +9 -3
  111. package/devvit/internals/semanticColors.d.ts +4 -0
  112. package/devvit/internals/semanticColors.d.ts.map +1 -1
  113. package/devvit/internals/semanticColors.js +4 -0
  114. package/devvit/internals/ui-event-handler.js +3 -3
  115. package/devvit/internals/upgrade-app-shim.d.ts +1 -5
  116. package/devvit/internals/upgrade-app-shim.d.ts.map +1 -1
  117. package/devvit/internals/upgrade-app-shim.js +0 -8
  118. package/index.d.ts +2 -2
  119. package/index.d.ts.map +1 -1
  120. package/index.js +1 -2
  121. package/meta.min.json +401 -342
  122. package/package.json +23 -20
  123. package/public-api.min.js +6 -6
  124. package/public-api.min.js.map +4 -4
  125. package/types/configuration.d.ts +12 -3
  126. package/types/configuration.d.ts.map +1 -1
  127. package/types/context.d.ts +10 -2
  128. package/types/context.d.ts.map +1 -1
  129. package/types/data.d.ts +1 -1
  130. package/types/data.d.ts.map +1 -1
  131. package/types/form.d.ts +6 -89
  132. package/types/form.d.ts.map +1 -1
  133. package/types/form.js +2 -5
  134. package/types/hooks.d.ts +1 -1
  135. package/types/hooks.d.ts.map +1 -1
  136. package/types/icons.d.ts +1 -1
  137. package/types/icons.d.ts.map +1 -1
  138. package/types/icons.js +1 -1
  139. package/types/json.d.ts +43 -0
  140. package/types/json.d.ts.map +1 -0
  141. package/types/json.js +1 -0
  142. package/types/kvStore.d.ts +1 -1
  143. package/types/kvStore.d.ts.map +1 -1
  144. package/types/media.d.ts +1 -1
  145. package/types/menu-item.d.ts +3 -14
  146. package/types/menu-item.d.ts.map +1 -1
  147. package/types/realtime.d.ts +1 -1
  148. package/types/realtime.d.ts.map +1 -1
  149. package/types/redis.d.ts +0 -1
  150. package/types/redis.d.ts.map +1 -1
  151. package/types/scheduler.d.ts +2 -2
  152. package/types/scheduler.d.ts.map +1 -1
  153. package/types/tid.d.ts +47 -0
  154. package/types/tid.d.ts.map +1 -0
  155. package/types/tid.js +114 -0
  156. package/types/ui-client.d.ts +12 -6
  157. package/types/ui-client.d.ts.map +1 -1
  158. package/types/web-view-ui-client.d.ts +1 -1
  159. package/types/web-view-ui-client.d.ts.map +1 -1
  160. package/version.json +6 -8
  161. package/apis/reddit/index.d.ts +0 -1104
  162. package/apis/reddit/index.d.ts.map +0 -1
  163. package/apis/reddit/index.js +0 -1442
  164. package/apis/reddit/tests/utils/createTestRedditApiContext.d.ts +0 -7
  165. package/apis/reddit/tests/utils/createTestRedditApiContext.d.ts.map +0 -1
  166. package/apis/reddit/tests/utils/createTestRedditApiContext.js +0 -23
  167. package/devvit/internals/async-metadata.d.ts +0 -2
  168. package/devvit/internals/async-metadata.d.ts.map +0 -1
  169. package/devvit/internals/async-metadata.js +0 -65
  170. package/meta.json +0 -10428
  171. package/public-api.d.ts +0 -60472
  172. package/public-api.iife.js +0 -102332
  173. package/tsdoc-metadata.json +0 -11
@@ -1,1442 +0,0 @@
1
- import {} from '@devvit/protos';
2
- import { Header } from '@devvit/shared-types/Header.js';
3
- import { asT3ID, asT5ID, asTID, isT1ID, isT3ID } from '@devvit/shared-types/tid.js';
4
- import { Devvit } from '../../devvit/Devvit.js';
5
- import { getMetadata } from '../../devvit/internals/async-metadata.js';
6
- import { getCurrentUserFromMetadata, } from './models/index.js';
7
- import { _getModerationLog, _getSubredditInfoById, _getSubredditInfoByName, _getSubredditLeaderboard, _getSubredditNameById, _getSubredditStyles, AboutLocations, Comment, Flair, FlairTemplate, getCurrentUsernameFromMetadata, ModMailService, ModNote, Post, PrivateMessage, Subreddit, User, Widget, WikiPage, } from './models/index.js';
8
- import { getVaultByAddress as _getVaultByAddress, getVaultByUserId as _getVaultByUserId, } from './models/Vault.js';
9
- /**
10
- * Get ModMail API object
11
- *
12
- * @example
13
- * ```ts
14
- * await modMail.reply({
15
- * body: "Here is my message",
16
- * conversationId: "abcd42";
17
- * })
18
- * ```
19
- */
20
- export function modMail() {
21
- const metadata = getMetadata();
22
- return new ModMailService(metadata);
23
- }
24
- /**
25
- * Gets a {@link Subreddit} object by ID
26
- *
27
- * @deprecated Use {@link getSubredditInfoById} instead.
28
- * @param {string} id - The ID (starting with t5_) of the subreddit to retrieve. e.g. t5_2qjpg
29
- * @returns {Promise<Subreddit>} A Promise that resolves a Subreddit object.
30
- * @example
31
- * ```ts
32
- * const memes = await getSubredditById('t5_2qjpg');
33
- * ```
34
- */
35
- export function getSubredditById(id) {
36
- const metadata = getMetadata();
37
- return Subreddit.getById(asTID(id), metadata);
38
- }
39
- /**
40
- * Gets a {@link SubredditInfo} object by ID
41
- *
42
- * @param {string} id - The ID (starting with t5_) of the subreddit to retrieve. e.g. t5_2qjpg
43
- * @returns {Promise<SubredditInfo>} A Promise that resolves a SubredditInfo object.
44
- * @example
45
- * ```ts
46
- * const memes = await getSubredditInfoById('t5_2qjpg');
47
- * ```
48
- */
49
- export function getSubredditInfoById(id) {
50
- const metadata = getMetadata();
51
- return _getSubredditInfoById(id, metadata);
52
- }
53
- /**
54
- * Gets a {@link Subreddit} object by name
55
- *
56
- * @deprecated Use {@link getSubredditInfoByName} instead.
57
- * @param {string} name The name of a subreddit omitting the r/. This is case-insensitive.
58
- * @returns {Promise<Subreddit>} A Promise that resolves a Subreddit object.
59
- * @example
60
- * ```ts
61
- * const askReddit = await getSubredditByName('askReddit');
62
- * ```
63
- */
64
- export function getSubredditByName(name) {
65
- const metadata = getMetadata();
66
- return Subreddit.getByName(name, metadata);
67
- }
68
- /**
69
- * Gets a {@link SubredditInfo} object by name
70
- *
71
- * @param {string} name The name of a subreddit omitting the r/. This is case-insensitive.
72
- * @returns {Promise<SubredditInfo>} A Promise that resolves a SubredditInfo object.
73
- * @example
74
- * ```ts
75
- * const askReddit = await getSubredditInfoByName('askReddit');
76
- * ```
77
- */
78
- export function getSubredditInfoByName(name) {
79
- const metadata = getMetadata();
80
- return _getSubredditInfoByName(name, metadata);
81
- }
82
- /**
83
- * Add a removal reason to a subreddit
84
- *
85
- * @param subredditName Name of the subreddit being removed.
86
- * @param options Options.
87
- * @param options.title The title of the removal reason.
88
- * @param options.message The message associated with the removal reason.
89
- * @example
90
- * ```ts
91
- * const newReason = await addSubredditRemovalReasons(
92
- * 'askReddit',
93
- * {
94
- * title: 'Spam',
95
- * message: 'This is spam!'
96
- * }
97
- * );
98
- * console.log(newReason.id)
99
- * ```
100
- *
101
- * @returns {string} Removal Reason ID
102
- */
103
- export function addSubredditRemovalReason(subredditName, options) {
104
- const metadata = getMetadata();
105
- return Subreddit.addRemovalReason(subredditName, options.title, options.message, metadata);
106
- }
107
- /**
108
- * Get the list of subreddit's removal reasons (ordered)
109
- *
110
- * @param subredditName
111
- * @example
112
- * ```ts
113
- * const reasons = await getSubredditRemovalReasons('askReddit');
114
- *
115
- * for (let reason of reasons) {
116
- * console.log(reason.id, reason.message, reason.title)
117
- * }
118
- * ```
119
- *
120
- * @returns Ordered array of Removal Reasons
121
- */
122
- export function getSubredditRemovalReasons(subredditName) {
123
- const metadata = getMetadata();
124
- return Subreddit.getRemovalReasons(subredditName, metadata);
125
- }
126
- /**
127
- * Retrieves the name of the current subreddit.
128
- *
129
- * @returns {Promise<string>} A Promise that resolves a string representing the current subreddit's name.
130
- * @example
131
- * ```ts
132
- * const currentSubredditName = await getCurrentSubredditName();
133
- * ```
134
- */
135
- export async function getCurrentSubredditName() {
136
- const metadata = getMetadata();
137
- const nameFromMetadata = metadata?.[Header.SubredditName]?.values[0];
138
- if (nameFromMetadata) {
139
- return nameFromMetadata;
140
- }
141
- const subredditId = metadata?.[Header.Subreddit]?.values[0];
142
- const nameFromId = await _getSubredditNameById(asT5ID(subredditId), metadata);
143
- if (!nameFromId) {
144
- throw new Error("Couldn't get current subreddit's name");
145
- }
146
- return nameFromId;
147
- }
148
- /**
149
- * Retrieves the current subreddit.
150
- *
151
- * @returns {Promise<Subreddit>} A Promise that resolves a Subreddit object.
152
- * @example
153
- * ```ts
154
- * const currentSubreddit = await getCurrentSubreddit();
155
- * ```
156
- */
157
- export async function getCurrentSubreddit() {
158
- const metadata = getMetadata();
159
- const currentSubreddit = await Subreddit.getFromMetadata(metadata);
160
- if (!currentSubreddit) {
161
- throw new Error("Couldn't get current subreddit");
162
- }
163
- return currentSubreddit;
164
- }
165
- /**
166
- * Gets a {@link Post} object by ID
167
- *
168
- * @param id
169
- * @returns A Promise that resolves to a Post object.
170
- */
171
- export function getPostById(id) {
172
- const metadata = getMetadata();
173
- return Post.getById(asTID(id), metadata);
174
- }
175
- /**
176
- * Submits a new post to a subreddit.
177
- *
178
- * @param options - Either a self post or a link post.
179
- * @returns A Promise that resolves to a Post object.
180
- * @example
181
- * ```ts
182
- * const post = await submitPost({
183
- * subredditName: 'devvit',
184
- * title: 'Hello World',
185
- * richtext: new RichTextBuilder()
186
- * .heading({ level: 1 }, (h) => {
187
- * h.rawText('Hello world');
188
- * })
189
- * .codeBlock({}, (cb) => cb.rawText('This post was created via the Devvit API'))
190
- * .build()
191
- * });
192
- * ```
193
- */
194
- export function submitPost(options) {
195
- const metadata = getMetadata();
196
- return Post.submit(options, metadata);
197
- }
198
- /**
199
- * Crossposts a post to a subreddit.
200
- *
201
- * @param options - Options for crossposting a post
202
- * @param options.subredditName - The name of the subreddit to crosspost to
203
- * @param options.postId - The ID of the post to crosspost
204
- * @param options.title - The title of the crosspost
205
- * @returns - A Promise that resolves to a Post object.
206
- */
207
- export function crosspost(options) {
208
- const metadata = getMetadata();
209
- return Post.crosspost(options, metadata);
210
- }
211
- /**
212
- * Gets a {@link User} object by ID
213
- *
214
- * @param id - The ID (starting with t2_) of the user to retrieve. e.g. t2_1qjpg
215
- * @returns A Promise that resolves to a User object.
216
- * @example
217
- * ```ts
218
- * const user = await getUserById('t2_1qjpg');
219
- * ```
220
- */
221
- export function getUserById(id) {
222
- const metadata = getMetadata();
223
- return User.getById(asTID(id), metadata);
224
- }
225
- /**
226
- * Gets a {@link User} object by username
227
- *
228
- * @param username - The username of the user omitting the u/. e.g. 'devvit'
229
- * @returns A Promise that resolves to a User object or undefined if user is
230
- * not found (user doesn't exist, account suspended, etc).
231
- * @example
232
- * ```ts
233
- * const user = await getUserByUsername('devvit');
234
- * if (user) {
235
- * console.log(user)
236
- * }
237
- * ```
238
- */
239
- export function getUserByUsername(username) {
240
- const metadata = getMetadata();
241
- return User.getByUsername(username, metadata);
242
- }
243
- /**
244
- * Get the current calling user's username.
245
- * Resolves to undefined for logged-out custom post renders.
246
- *
247
- * @returns A Promise that resolves to a string representing the username or undefined
248
- * @example
249
- * ```ts
250
- * const username = await getCurrentUsername();
251
- * ```
252
- */
253
- export async function getCurrentUsername() {
254
- const metadata = getMetadata();
255
- return getCurrentUsernameFromMetadata(metadata);
256
- }
257
- /**
258
- * Get the current calling user.
259
- * Resolves to undefined for logged-out custom post renders.
260
- *
261
- * @returns A Promise that resolves to a User object or undefined
262
- * @example
263
- * ```ts
264
- * const user = await getCurrentUser();
265
- * ```
266
- */
267
- export async function getCurrentUser() {
268
- const metadata = getMetadata();
269
- return getCurrentUserFromMetadata(metadata);
270
- }
271
- /**
272
- * Get the user that the app runs as on the provided metadata.
273
- *
274
- * @returns A Promise that resolves to a User object.
275
- * @example
276
- * ```ts
277
- * const user = await getAppUser(metadata);
278
- * ```
279
- */
280
- export function getAppUser() {
281
- const metadata = getMetadata();
282
- return User.getFromMetadata(Header.AppUser, metadata);
283
- }
284
- /**
285
- * Get the snoovatar URL for a given username.
286
- *
287
- * @param username - The username of the snoovatar to retrieve
288
- * @returns A Promise that resolves to a URL of the snoovatar image if it exists.
289
- */
290
- export async function getSnoovatarUrl(username) {
291
- const metadata = getMetadata();
292
- const currentUsername = await getCurrentUsername();
293
- if (currentUsername && username === currentUsername) {
294
- const snoovatarUrl = metadata[Header.UserSnoovatarUrl]?.values[0];
295
- if (snoovatarUrl) {
296
- return snoovatarUrl;
297
- }
298
- }
299
- return User.getSnoovatarUrl(username, metadata);
300
- }
301
- /**
302
- * Get a {@link Comment} object by ID
303
- *
304
- * @param id - The ID (starting with t1_) of the comment to retrieve. e.g. t1_1qjpg
305
- * @returns A Promise that resolves to a Comment object.
306
- * @example
307
- * ```ts
308
- * const comment = await getCommentById('t1_1qjpg');
309
- * ```
310
- */
311
- export function getCommentById(id) {
312
- const metadata = getMetadata();
313
- return Comment.getById(asTID(id), metadata);
314
- }
315
- /**
316
- * Get a list of comments from a specific post or comment.
317
- *
318
- * @param options - Options for the request
319
- * @param options.postId - The ID of the post e.g. 't3_1qjpg'
320
- * @param options.commentId - The ID of the comment e.g. 't1_1qjpg'
321
- * @param options.limit - The maximum number of comments to return. e.g. 1000
322
- * @param options.pageSize - The number of comments to return per request. e.g. 100
323
- * @param options.sort - The sort order of the comments. e.g. 'new'
324
- * @returns A Listing of Comment objects.
325
- * @example
326
- * ```ts
327
- * const comments = await getComments({
328
- * postId: 't3_1qjpg',
329
- * limit: 1000,
330
- * pageSize: 100
331
- * }).all();
332
- * ```
333
- */
334
- export function getComments(options) {
335
- const metadata = getMetadata();
336
- return Comment.getComments(options, metadata);
337
- }
338
- /**
339
- * Get a list of comments by a specific user.
340
- *
341
- * @param options - Options for the request
342
- * @param options.username - The username of the user omitting the u/. e.g. 'spez'
343
- * @param options.sort - The sort order of the comments. e.g. 'new'
344
- * @param options.timeframe - The timeframe of the comments. e.g. 'all'
345
- * @param options.limit - The maximum number of comments to return. e.g. 1000
346
- * @param options.pageSize - The number of comments to return per request. e.g. 100
347
- * @returns A Listing of Comment objects.
348
- */
349
- export function getCommentsByUser(options) {
350
- const metadata = getMetadata();
351
- return Comment.getCommentsByUser(options, metadata);
352
- }
353
- /**
354
- * Submit a new comment to a post or comment.
355
- *
356
- * @param options - You must provide either `options.text` or `options.richtext` but not both.
357
- * @param options.id - The ID of the post or comment to comment on. e.g. 't3_1qjpg' for post and 't1_1qgif' for comment
358
- * @param options.text - The text of the comment
359
- * @param options.richtext - The rich text of the comment
360
- * @returns A Promise that resolves to a Comment object.
361
- */
362
- export function submitComment(options) {
363
- const metadata = getMetadata();
364
- return Comment.submit({
365
- ...options,
366
- id: asTID(options.id),
367
- }, metadata);
368
- }
369
- /**
370
- * Get a list of controversial posts from a specific subreddit.
371
- *
372
- * @param options - Options for the request
373
- * @param options.subredditName - The name of the subreddit to get posts from. e.g. 'memes'
374
- * @param options.timeframe - The timeframe to get posts from. e.g. 'day'
375
- * @param options.limit - The maximum number of posts to return. e.g. 1000
376
- * @param options.pageSize - The number of posts to return per request. e.g. 100
377
- * @returns A Listing of Post objects.
378
- * @example
379
- * ```ts
380
- * const posts = await getControversialPosts({
381
- * subredditName: 'memes',
382
- * timeframe: 'day',
383
- * limit: 1000,
384
- * pageSize: 100
385
- * }).all();
386
- * ```
387
- */
388
- export function getControversialPosts(options) {
389
- const metadata = getMetadata();
390
- return Post.getControversialPosts(options, metadata);
391
- }
392
- /**
393
- * Get a list of controversial posts from a specific subreddit.
394
- *
395
- * @param options - Options for the request
396
- * @param options.subredditName - The name of the subreddit to get posts from. e.g. 'memes'
397
- * @param options.timeframe - The timeframe to get posts from. e.g. 'day'
398
- * @param options.limit - The maximum number of posts to return. e.g. 1000
399
- * @param options.pageSize - The number of posts to return per request. e.g. 100
400
- * @returns A Listing of Post objects.
401
- * @example
402
- * ```ts
403
- * const posts = await getControversialPosts({
404
- * subredditName: 'memes',
405
- * timeframe: 'day',
406
- * limit: 1000,
407
- * pageSize: 100
408
- * }).all();
409
- * ```
410
- */
411
- export function getTopPosts(options) {
412
- const metadata = getMetadata();
413
- return Post.getTopPosts(options, metadata);
414
- }
415
- /**
416
- * Get a list of hot posts from a specific subreddit.
417
- *
418
- * @param options - Options for the request
419
- * @param options.subredditName - The name of the subreddit to get posts from. e.g. 'memes'
420
- * @param options.timeframe - The timeframe to get posts from. e.g. 'day'
421
- * @param options.limit - The maximum number of posts to return. e.g. 1000
422
- * @param options.pageSize - The number of posts to return per request. e.g. 100
423
- * @returns A Listing of Post objects.
424
- * @example
425
- * ```ts
426
- * const posts = await getHotPosts({
427
- * subredditName: 'memes',
428
- * timeframe: 'day',
429
- * limit: 1000,
430
- * pageSize: 100
431
- * }).all();
432
- * ```
433
- */
434
- export function getHotPosts(options) {
435
- const metadata = getMetadata();
436
- return Post.getHotPosts(options, metadata);
437
- }
438
- /**
439
- * Get a list of new posts from a specific subreddit.
440
- *
441
- * @param options - Options for the request
442
- * @param options.subredditName - The name of the subreddit to get posts from. e.g. 'memes'
443
- * @param options.limit - The maximum number of posts to return. e.g. 1000
444
- * @param options.pageSize - The number of posts to return per request. e.g. 100
445
- * @returns A Listing of Post objects.
446
- * @example
447
- * ```ts
448
- * const posts = await getNewPosts({
449
- * subredditName: 'memes',
450
- * limit: 1000,
451
- * pageSize: 100
452
- * }).all();
453
- * ```
454
- */
455
- export function getNewPosts(options) {
456
- const metadata = getMetadata();
457
- return Post.getNewPosts(options, metadata);
458
- }
459
- /**
460
- * Get a list of hot posts from a specific subreddit.
461
- *
462
- * @param options - Options for the request
463
- * @param options.subredditName - The name of the subreddit to get posts from. e.g. 'memes'
464
- * @param options.timeframe - The timeframe to get posts from. e.g. 'day'
465
- * @param options.limit - The maximum number of posts to return. e.g. 1000
466
- * @param options.pageSize - The number of posts to return per request. e.g. 100
467
- * @returns A Listing of Post objects.
468
- * @example
469
- * ```ts
470
- * const posts = await getRisingPosts({
471
- * subredditName: 'memes',
472
- * timeframe: 'day',
473
- * limit: 1000,
474
- * pageSize: 100
475
- * }).all();
476
- * ```
477
- */
478
- export function getRisingPosts(options) {
479
- const metadata = getMetadata();
480
- return Post.getRisingPosts(options, metadata);
481
- }
482
- /**
483
- * Get a list of posts from a specific user.
484
- *
485
- * @param options - Options for the request
486
- * @param options.username - The username of the user omitting the u/. e.g. 'spez'
487
- * @param options.sort - The sort method to use. e.g. 'new'
488
- * @param options.timeframe - The timeframe to get posts from. e.g. 'day'
489
- * @param options.limit - The maximum number of posts to return. e.g. 1000
490
- * @param options.pageSize - The number of posts to return per request. e.g. 100
491
- * @returns A Listing of Post objects.
492
- */
493
- export function getPostsByUser(options) {
494
- const metadata = getMetadata();
495
- return Post.getPostsByUser(options, metadata);
496
- }
497
- /**
498
- * Get a list of posts and comments from a specific user.
499
- *
500
- * @param options - Options for the request
501
- * @param options.username - The username of the user omitting the u/. e.g. 'spez'
502
- * @param options.sort - The sort method to use. e.g. 'new'
503
- * @param options.timeframe - The timeframe to get posts from. e.g. 'day'
504
- * @param options.limit - The maximum number of posts to return. e.g. 1000
505
- * @param options.pageSize - The number of posts to return per request. e.g. 100
506
- * @returns A Listing of `Post` and `Comment` objects.
507
- */
508
- export function getCommentsAndPostsByUser(options) {
509
- const metadata = getMetadata();
510
- return User.getOverview(options, metadata);
511
- }
512
- /**
513
- * Get the moderation log for a subreddit.
514
- *
515
- * @param options - Options for the request
516
- * @param options.subredditName - The name of the subreddit to get the moderation log from. e.g. 'memes'
517
- * @param options.moderatorUsernames (optional) A moderator filter. Accepts an array of usernames
518
- * @param options.type (optional) Filter the entries by the type of the Moderator action
519
- * @param options.limit - (optional) The maximum number of ModActions to return. e.g. 1000
520
- * @param options.pageSize - (optional) The number of ModActions to return per request. e.g. 100
521
- * @returns A Listing of ModAction objects.
522
- * @example
523
- * ```ts
524
- * const modActions = await getModerationLog({
525
- * subredditName: 'memes',
526
- * moderatorUsernames: ['spez'],
527
- * type: 'banuser',
528
- * limit: 1000,
529
- * pageSize: 100
530
- * }).all();
531
- * ```
532
- */
533
- export function getModerationLog(options) {
534
- const metadata = getMetadata();
535
- return _getModerationLog(options, metadata);
536
- }
537
- /**
538
- * Get a list of users who have been approved to post in a subreddit.
539
- *
540
- * @param options - Options for the request
541
- * @param options.subredditName - The name of the subreddit to get the approved users from. e.g. 'memes'
542
- * @param options.username - Use this to see if a user is approved to post in the subreddit.
543
- * @param options.limit - The maximum number of users to return. e.g. 1000
544
- * @param options.pageSize - The number of users to return per request. e.g. 100
545
- * @returns A Listing of User objects.
546
- */
547
- export function getApprovedUsers(options) {
548
- const metadata = getMetadata();
549
- return User.getSubredditUsersByType({
550
- type: 'contributors',
551
- ...options,
552
- }, metadata);
553
- }
554
- /**
555
- * Approve a user to post in a subreddit.
556
- *
557
- * @param username - The username of the user to approve. e.g. 'spez'
558
- * @param subredditName - The name of the subreddit to approve the user in. e.g. 'memes'
559
- */
560
- export function approveUser(username, subredditName) {
561
- const metadata = getMetadata();
562
- return User.createRelationship({
563
- username,
564
- subredditName,
565
- type: 'contributor',
566
- }, metadata);
567
- }
568
- /**
569
- * Remove a user's approval to post in a subreddit.
570
- *
571
- * @param username - The username of the user to remove approval from. e.g. 'spez'
572
- * @param subredditName - The name of the subreddit to remove the user's approval from. e.g. 'memes'
573
- */
574
- export function removeUser(username, subredditName) {
575
- const metadata = getMetadata();
576
- return User.removeRelationship({
577
- username,
578
- subredditName,
579
- type: 'contributor',
580
- }, metadata);
581
- }
582
- /**
583
- * Get a list of users who are wiki contributors of a subreddit.
584
- *
585
- * @param options - Options for the request
586
- * @param options.subredditName - The name of the subreddit to get the wiki contributors from. e.g. 'memes'
587
- * @param options.username - Use this to see if a user is a wiki contributor for the subreddit.
588
- * @param options.limit - The maximum number of users to return. e.g. 1000
589
- * @param options.pageSize - The number of users to return per request. e.g. 100
590
- * @returns A Listing of User objects.
591
- */
592
- export function getWikiContributors(options) {
593
- const metadata = getMetadata();
594
- return User.getSubredditUsersByType({
595
- type: 'wikicontributors',
596
- ...options,
597
- }, metadata);
598
- }
599
- /**
600
- * Add a user as a wiki contributor for a subreddit.
601
- *
602
- * @param username - The username of the user to add as a wiki contributor. e.g. 'spez'
603
- * @param subredditName - The name of the subreddit to add the user as a wiki contributor. e.g. 'memes'
604
- */
605
- export function addWikiContributor(username, subredditName) {
606
- const metadata = getMetadata();
607
- return User.createRelationship({
608
- username,
609
- subredditName,
610
- type: 'wikicontributor',
611
- }, metadata);
612
- }
613
- /**
614
- * Remove a user's wiki contributor status for a subreddit.
615
- *
616
- * @param username - The username of the user to remove wiki contributor status from. e.g. 'spez'
617
- * @param subredditName - The name of the subreddit to remove the user's wiki contributor status from. e.g. 'memes'
618
- */
619
- export function removeWikiContributor(username, subredditName) {
620
- const metadata = getMetadata();
621
- return User.removeRelationship({
622
- username,
623
- subredditName,
624
- type: 'wikicontributor',
625
- }, metadata);
626
- }
627
- /**
628
- * Get a list of users who are banned from a subreddit.
629
- *
630
- * @param options - Options for the request
631
- * @param options.subredditName - The name of the subreddit to get the banned users from. e.g. 'memes'
632
- * @param options.username - Use this to see if a user is banned from the subreddit.
633
- * @param options.limit - The maximum number of users to return. e.g. 1000
634
- * @param options.pageSize - The number of users to return per request. e.g. 100
635
- * @returns A Listing of User objects.
636
- */
637
- export function getBannedUsers(options) {
638
- const metadata = getMetadata();
639
- return User.getSubredditUsersByType({
640
- type: 'banned',
641
- ...options,
642
- }, metadata);
643
- }
644
- /**
645
- * Ban a user from a subreddit.
646
- *
647
- * @param options - Options for the request
648
- * @param options.username - The username of the user to ban. e.g. 'spez'
649
- * @param options.subredditName - The name of the subreddit to ban the user from. e.g. 'memes'
650
- * @param options.note - A mod note for the ban. (optional)
651
- * @param options.duration - The number of days the user should be banned for. (optional)
652
- * @param options.message - A message to send to the user when they are banned. (optional)
653
- * @param options.context - The ID of the post or comment that caused the ban. (optional)
654
- * @param options.reason - The reason for the ban. (optional)
655
- */
656
- export function banUser(options) {
657
- const metadata = getMetadata();
658
- return User.createRelationship({
659
- username: options.username,
660
- subredditName: options.subredditName,
661
- type: 'banned',
662
- banReason: options.reason,
663
- banMessage: options.message,
664
- note: options.note,
665
- duration: options.duration,
666
- banContext: options.context,
667
- }, metadata);
668
- }
669
- /**
670
- * Unban a user from a subreddit.
671
- *
672
- * @param username - The username of the user to unban. e.g. 'spez'
673
- * @param subredditName - The name of the subreddit to unban the user from. e.g. 'memes'
674
- */
675
- export function unbanUser(username, subredditName) {
676
- const metadata = getMetadata();
677
- return User.removeRelationship({
678
- username,
679
- subredditName,
680
- type: 'banned',
681
- }, metadata);
682
- }
683
- /**
684
- * Get a list of users who are banned from contributing to the wiki on a subreddit.
685
- *
686
- * @param options - Options for the request
687
- * @param options.subredditName - The name of the subreddit to get the banned wiki contributors from. e.g. 'memes'
688
- * @param options.username - Use this to see if a user is banned from contributing to the wiki on a subreddit.
689
- * @param options.limit - The maximum number of users to return. e.g. 1000
690
- * @param options.pageSize - The number of users to return per request. e.g. 100
691
- * @returns A Listing of User objects.
692
- */
693
- export function getBannedWikiContributors(options) {
694
- const metadata = getMetadata();
695
- return User.getSubredditUsersByType({
696
- type: 'wikibanned',
697
- ...options,
698
- }, metadata);
699
- }
700
- /**
701
- * Ban a user from contributing to the wiki on a subreddit.
702
- *
703
- * @param options - Options for the request
704
- * @param options.username - The username of the user to ban. e.g. 'spez'
705
- * @param options.subredditName - The name of the subreddit to ban the user from contributing to the wiki on. e.g. 'memes'
706
- * @param options.reason - The reason for the ban. (optional)
707
- * @param options.duration - The number of days the user should be banned for. (optional)
708
- * @param options.note - A mod note for the ban. (optional)
709
- */
710
- export function banWikiContributor(options) {
711
- const metadata = getMetadata();
712
- return User.createRelationship({
713
- ...options,
714
- type: 'wikibanned',
715
- }, metadata);
716
- }
717
- /**
718
- *
719
- * @param username - The username of the user to unban. e.g. 'spez'
720
- * @param subredditName - The name of the subreddit to unban the user from contributing to the wiki on. e.g. 'memes'
721
- */
722
- export function unbanWikiContributor(username, subredditName) {
723
- const metadata = getMetadata();
724
- return User.removeRelationship({
725
- username,
726
- subredditName,
727
- type: 'wikibanned',
728
- }, metadata);
729
- }
730
- /**
731
- * Get a list of users who are moderators for a subreddit.
732
- *
733
- * @param options - Options for the request
734
- * @param options.subredditName - The name of the subreddit to get the moderators from. e.g. 'memes'
735
- * @param options.username - Use this to see if a user is a moderator of the subreddit.
736
- * @param options.limit - The maximum number of users to return. e.g. 1000
737
- * @param options.pageSize - The number of users to return per request. e.g. 100
738
- * @returns A Listing of User objects.
739
- */
740
- export function getModerators(options) {
741
- const metadata = getMetadata();
742
- return User.getSubredditUsersByType({
743
- type: 'moderators',
744
- ...options,
745
- }, metadata);
746
- }
747
- /**
748
- * Invite a user to become a moderator of a subreddit.
749
- *
750
- * @param options - Options for the request
751
- * @param options.username - The username of the user to invite. e.g. 'spez'
752
- * @param options.subredditName - The name of the subreddit to invite the user to moderate. e.g. 'memes'
753
- * @param options.permissions - The permissions to give the user. (optional) Defaults to 'all'.
754
- */
755
- export function inviteModerator(options) {
756
- const metadata = getMetadata();
757
- return User.createRelationship({
758
- type: 'moderator_invite',
759
- subredditName: options.subredditName,
760
- username: options.username,
761
- permissions: options.permissions ?? [],
762
- }, metadata);
763
- }
764
- /**
765
- * Revoke a moderator invite for a user to a subreddit.
766
- *
767
- * @param username - The username of the user to revoke the invite for. e.g. 'spez'
768
- * @param subredditName - The name of the subreddit to revoke the invite for. e.g. 'memes'
769
- */
770
- export function revokeModeratorInvite(username, subredditName) {
771
- const metadata = getMetadata();
772
- return User.removeRelationship({
773
- username,
774
- subredditName,
775
- type: 'moderator_invite',
776
- }, metadata);
777
- }
778
- /**
779
- * Remove a user as a moderator of a subreddit.
780
- *
781
- * @param username - The username of the user to remove as a moderator. e.g. 'spez'
782
- * @param subredditName - The name of the subreddit to remove the user as a moderator from. e.g. 'memes'
783
- */
784
- export function removeModerator(username, subredditName) {
785
- const metadata = getMetadata();
786
- return User.removeRelationship({
787
- type: 'moderator',
788
- subredditName,
789
- username,
790
- }, metadata);
791
- }
792
- /**
793
- * Update the permissions of a moderator of a subreddit.
794
- *
795
- * @param username - The username of the user to update the permissions for. e.g. 'spez'
796
- * @param subredditName - The name of the subreddit. e.g. 'memes'
797
- * @param permissions - The permissions to give the user. e.g ['posts', 'wiki']
798
- */
799
- export function setModeratorPermissions(username, subredditName, permissions) {
800
- const metadata = getMetadata();
801
- return User.setModeratorPermissions(username, subredditName, permissions, metadata);
802
- }
803
- /**
804
- * Get a list of users who are muted in a subreddit.
805
- *
806
- * @param options - Options for the request
807
- * @param options.subredditName - The name of the subreddit to get the muted users from. e.g. 'memes'
808
- * @param options.username - Use this to see if a user is muted in the subreddit.
809
- * @param options.limit - The maximum number of users to return. e.g. 1000
810
- * @param options.pageSize - The number of users to return per request. e.g. 100
811
- * @returns A listing of User objects.
812
- */
813
- export function getMutedUsers(options) {
814
- const metadata = getMetadata();
815
- return User.getSubredditUsersByType({
816
- type: 'muted',
817
- ...options,
818
- }, metadata);
819
- }
820
- /**
821
- * Mute a user in a subreddit. Muting a user prevents them from sending modmail.
822
- *
823
- * @param options - Options for the request
824
- * @param options.username - The username of the user to mute. e.g. 'spez'
825
- * @param options.subredditName - The name of the subreddit to mute the user in. e.g. 'memes'
826
- * @param options.note - A mod note on why the user was muted. (optional)
827
- */
828
- export function muteUser(options) {
829
- const metadata = getMetadata();
830
- return User.createRelationship({
831
- ...options,
832
- type: 'muted',
833
- }, metadata);
834
- }
835
- /**
836
- * Unmute a user in a subreddit. Unmuting a user allows them to send modmail.
837
- *
838
- * @param username - The username of the user to unmute. e.g. 'spez'
839
- * @param subredditName - The name of the subreddit to unmute the user in. e.g. 'memes'
840
- */
841
- export function unmuteUser(username, subredditName) {
842
- const metadata = getMetadata();
843
- return User.removeRelationship({
844
- username,
845
- subredditName,
846
- type: 'muted',
847
- }, metadata);
848
- }
849
- /**
850
- * Get a list of mod notes related to a user in a subreddit.
851
- *
852
- * @param options - Options for the request
853
- * @param options.subredditName - The name of the subreddit to get the mod notes from. e.g. 'memes'
854
- * @param options.username - The username of the user to get the mod notes for. e.g. 'spez'
855
- * @param options.filter - Filter the mod notes by type. e.g. 'NOTE', 'BAN', 'APPROVAL'
856
- * @param options.limit - The maximum number of mod notes to return. e.g. 1000
857
- * @param options.pageSize - The number of mod notes to return per request. e.g. 100
858
- * @returns A listing of ModNote objects.
859
- */
860
- export function getModNotes(options) {
861
- const metadata = getMetadata();
862
- return ModNote.get(options, metadata);
863
- }
864
- /**
865
- * Delete a mod note.
866
- *
867
- * @param options - Options for the request
868
- * @param options.subreddit - The name of the subreddit to delete the mod note from. e.g. 'memes'
869
- * @param options.noteId - The ID of the mod note to delete (should have a ModNote_ prefix).
870
- * @returns True if it was deleted successfully; false otherwise.
871
- */
872
- export function deleteModNote(options) {
873
- const metadata = getMetadata();
874
- return ModNote.delete(options, metadata);
875
- }
876
- /**
877
- * Add a mod note.
878
- *
879
- * @param options - Options for the request
880
- * @param options.subreddit - The name of the subreddit to add the mod note to. e.g. 'memes'
881
- * @param options.user - The username of the user to add the mod note to. e.g. 'spez'
882
- * @param options.redditId - (optional) The ID of the comment or post to add the mod note to. e.g. 't3_1234'
883
- * @param options.label - (optional) The label of the mod note. e.g. 'SPAM_WARNING'
884
- * @param options.note - The text of the mod note.
885
- * @returns A Promise that resolves if the mod note was successfully added.
886
- */
887
- export function addModNote(options) {
888
- const metadata = getMetadata();
889
- const req = {
890
- ...options,
891
- redditId: options.redditId ? asTID(options.redditId) : undefined,
892
- };
893
- return ModNote.add(req, metadata);
894
- }
895
- /**
896
- * Add a mod note for why a post or comment was removed
897
- *
898
- * @param options - The options for adding a removal note.
899
- * @param options.itemIds list of thing ids
900
- * @param options.reasonId id of a Removal Reason - you can leave this as an empty string if you don't have one
901
- * @param options.modNote the reason for removal (maximum 100 characters) (optional)
902
- */
903
- export function addRemovalNote(options) {
904
- const metadata = getMetadata();
905
- return ModNote.addRemovalNote(options, metadata);
906
- }
907
- /**
908
- * Sends a private message to a user.
909
- *
910
- * @param options - The options for sending the message.
911
- * @returns A Promise that resolves if the private message was successfully sent.
912
- */
913
- export async function sendPrivateMessage(options) {
914
- const metadata = getMetadata();
915
- return PrivateMessage.send(options, metadata);
916
- }
917
- /**
918
- * Sends a private message to a user on behalf of a subreddit.
919
- *
920
- * @param options - The options for sending the message as a subreddit.
921
- * @returns A Promise that resolves if the private message was successfully sent.
922
- */
923
- export async function sendPrivateMessageAsSubreddit(options) {
924
- const metadata = getMetadata();
925
- return PrivateMessage.sendAsSubreddit(options, metadata);
926
- }
927
- /**
928
- * Approve a post or comment.
929
- *
930
- * @param id - The id of the post (t3_) or comment (t1_) to approve.
931
- * @example
932
- * ```ts
933
- * await approve('t3_123456');
934
- * await approve('t1_123456');
935
- * ```
936
- */
937
- export async function approve(id) {
938
- const metadata = getMetadata();
939
- if (isT1ID(id)) {
940
- return Comment.approve(id, metadata);
941
- }
942
- else if (isT3ID(id)) {
943
- return Post.approve(id, metadata);
944
- }
945
- throw new Error('id must start with either t1_ or t3_');
946
- }
947
- /**
948
- * Remove a post or comment.
949
- *
950
- * @param id - The id of the post (t3_) or comment (t1_) to remove.
951
- * @param isSpam - Is the post or comment being removed because it's spam?
952
- * @example
953
- * ```ts
954
- * await remove('t3_123456', false);
955
- * await remove('t1_123456', true);
956
- * ```
957
- */
958
- export async function remove(id, isSpam) {
959
- const metadata = getMetadata();
960
- if (isT1ID(id)) {
961
- return Comment.remove(id, isSpam, metadata);
962
- }
963
- else if (isT3ID(id)) {
964
- return Post.remove(id, isSpam, metadata);
965
- }
966
- throw new Error('id must start with either t1_ or t3_');
967
- }
968
- /**
969
- * Get the list of post flair templates for a subreddit.
970
- *
971
- * @param subredditName - The name of the subreddit to get the post flair templates for.
972
- * @returns A Promise that resolves with an array of FlairTemplate objects.
973
- */
974
- export async function getPostFlairTemplates(subredditName) {
975
- const metadata = getMetadata();
976
- return FlairTemplate.getPostFlairTemplates(subredditName, metadata);
977
- }
978
- /**
979
- * Get the list of user flair templates for a subreddit.
980
- *
981
- * @param subredditName - The name of the subreddit to get the user flair templates for.
982
- * @returns A Promise that resolves with an array of FlairTemplate objects.
983
- */
984
- export async function getUserFlairTemplates(subredditName) {
985
- const metadata = getMetadata();
986
- return FlairTemplate.getUserFlairTemplates(subredditName, metadata);
987
- }
988
- /**
989
- * Create a post flair template for a subreddit.
990
- *
991
- * @param options - Options for the request
992
- * @param options.subredditName - The name of the subreddit to create the flair template for.
993
- * @param options.allowableContent - The content that is allowed to be used with this flair template. e.g. 'all' or 'text' or 'emoji'
994
- * @param options.backgroundColor - The background color of the flair template. e.g. '#ff0000' or 'transparent'
995
- * @param options.maxEmojis - The maximum number of emojis that can be used with this flair template.
996
- * @param options.modOnly - Whether or not this flair template is only available to mods.
997
- * @param options.text - The text of the flair template.
998
- * @param options.textColor - The text color of the flair template. Either 'dark' or 'light'.
999
- * @param options.allowUserEdits - Whether or not users can edit the flair template when selecting a flair.
1000
- * @returns The created FlairTemplate object.
1001
- */
1002
- export async function createPostFlairTemplate(options) {
1003
- const metadata = getMetadata();
1004
- return FlairTemplate.createPostFlairTemplate(options, metadata);
1005
- }
1006
- /**
1007
- * Create a user flair template for a subreddit.
1008
- *
1009
- * @param options - Options for the request
1010
- * @param options.subredditName - The name of the subreddit to create the flair template for.
1011
- * @param options.allowableContent - The content that is allowed to be used with this flair template. e.g. 'all' or 'text' or 'emoji'
1012
- * @param options.backgroundColor - The background color of the flair template. e.g. '#ff0000' or 'transparent'
1013
- * @param options.maxEmojis - The maximum number of emojis that can be used with this flair template.
1014
- * @param options.modOnly - Whether or not this flair template is only available to mods.
1015
- * @param options.text - The text of the flair template.
1016
- * @param options.textColor - The text color of the flair template. Either 'dark' or 'light'.
1017
- * @param options.allowUserEdits - Whether or not users can edit the flair template when selecting a flair.
1018
- * @returns The created FlairTemplate object.
1019
- */
1020
- export async function createUserFlairTemplate(options) {
1021
- const metadata = getMetadata();
1022
- return FlairTemplate.createUserFlairTemplate(options, metadata);
1023
- }
1024
- /**
1025
- * Edit a flair template for a subreddit. This can be either a post or user flair template.
1026
- * Note: If you leave any of the options fields as undefined, they will reset to their default values.
1027
- *
1028
- * @param options - Options for the request
1029
- * @param options.id - The ID of the flair template to edit.
1030
- * @param options.subredditName - The name of the subreddit to create the flair template for.
1031
- * @param options.allowableContent - The content that is allowed to be used with this flair template. e.g. 'all' or 'text' or 'emoji'
1032
- * @param options.backgroundColor - The background color of the flair template. e.g. '#ff0000' or 'transparent'
1033
- * @param options.maxEmojis - The maximum number of emojis that can be used with this flair template.
1034
- * @param options.modOnly - Is this flair template only available to mods?
1035
- * @param options.text - The text of the flair template.
1036
- * @param options.textColor - The text color of the flair template. Either 'dark' or 'light'.
1037
- * @param options.allowUserEdits - Can users can edit the flair template when selecting a flair?
1038
- * @returns The edited FlairTemplate object.
1039
- */
1040
- export async function editFlairTemplate(options) {
1041
- const metadata = getMetadata();
1042
- return FlairTemplate.editFlairTemplate(options, metadata);
1043
- }
1044
- /**
1045
- * Delete a flair template from a subreddit.
1046
- *
1047
- * @param subredditName - The name of the subreddit to delete the flair template from.
1048
- * @param flairTemplateId - The ID of the flair template to delete.
1049
- */
1050
- export async function deleteFlairTemplate(subredditName, flairTemplateId) {
1051
- const metadata = getMetadata();
1052
- return FlairTemplate.deleteFlairTemplate(subredditName, flairTemplateId, metadata);
1053
- }
1054
- /**
1055
- * Set the flair for a user in a subreddit.
1056
- *
1057
- * @param options - Options for the request
1058
- * @param options.subredditName - The name of the subreddit to set the flair for.
1059
- * @param options.username - The username of the user to set the flair for.
1060
- * @param options.flairTemplateId - The ID of the flair template to use.
1061
- * @param options.text - The text of the flair.
1062
- * @param options.cssClass - The CSS class of the flair.
1063
- * @param options.backgroundColor - The background color of the flair.
1064
- * @param options.textColor - The text color of the flair.
1065
- */
1066
- export async function setUserFlair(options) {
1067
- const metadata = getMetadata();
1068
- return Flair.setUserFlair(options, metadata);
1069
- }
1070
- /**
1071
- * Set the flair of multiple users in the same subreddit with a single API call.
1072
- * Can process up to 100 entries at once.
1073
- *
1074
- * @param subredditName - The name of the subreddit to edit flairs in.
1075
- * @param {SetUserFlairBatchConfig[]} flairs - Array of user flair configuration objects. If both text and cssClass are empty for a given user the flair will be cleared.
1076
- * @param flairs[].username - The username of the user to edit the flair for.
1077
- * @param flairs[].text - The text of the flair.
1078
- * @param flairs[].cssClass - The CSS class of the flair.
1079
- * @returns {FlairCsvResult[]} - Array of statuses for each entry provided.
1080
- */
1081
- export async function setUserFlairBatch(subredditName, flairs) {
1082
- const metadata = getMetadata();
1083
- return Flair.setUserFlairBatch(subredditName, flairs, metadata);
1084
- }
1085
- /**
1086
- * Remove the flair for a user in a subreddit.
1087
- *
1088
- * @param subredditName - The name of the subreddit to remove the flair from.
1089
- * @param username - The username of the user to remove the flair from.
1090
- */
1091
- export async function removeUserFlair(subredditName, username) {
1092
- const metadata = getMetadata();
1093
- return Flair.removeUserFlair(subredditName, username, metadata);
1094
- }
1095
- /**
1096
- * Set the flair for a post in a subreddit.
1097
- *
1098
- * @param options - Options for the request
1099
- * @param options.subredditName - The name of the subreddit to set the flair for.
1100
- * @param options.postId - The ID of the post to set the flair for.
1101
- * @param options.flairTemplateId - The ID of the flair template to use.
1102
- * @param options.text - The text of the flair.
1103
- * @param options.cssClass - The CSS class of the flair.
1104
- * @param options.backgroundColor - The background color of the flair.
1105
- * @param options.textColor - The text color of the flair.
1106
- */
1107
- export async function setPostFlair(options) {
1108
- const metadata = getMetadata();
1109
- return Flair.setPostFlair(options, metadata);
1110
- }
1111
- /**
1112
- * Remove the flair for a post in a subreddit.
1113
- *
1114
- * @param subredditName - The name of the subreddit to remove the flair from.
1115
- * @param postId - The ID of the post to remove the flair from.
1116
- */
1117
- export async function removePostFlair(subredditName, postId) {
1118
- const metadata = getMetadata();
1119
- return Flair.removePostFlair(subredditName, asT3ID(postId), metadata);
1120
- }
1121
- /**
1122
- * Get the widgets for a subreddit.
1123
- *
1124
- * @param subredditName - The name of the subreddit to get the widgets for.
1125
- * @returns - An array of Widget objects.
1126
- */
1127
- export async function getWidgets(subredditName) {
1128
- const metadata = getMetadata();
1129
- return Widget.getWidgets(subredditName, metadata);
1130
- }
1131
- /**
1132
- * Delete a widget from a subreddit.
1133
- *
1134
- * @param subredditName - The name of the subreddit to delete the widget from.
1135
- * @param widgetId - The ID of the widget to delete.
1136
- */
1137
- export async function deleteWidget(subredditName, widgetId) {
1138
- const metadata = getMetadata();
1139
- return Widget.delete(subredditName, widgetId, metadata);
1140
- }
1141
- /**
1142
- * Add a widget to a subreddit.
1143
- *
1144
- * @param widgetData - The data for the widget to add.
1145
- * @returns - The added Widget object.
1146
- */
1147
- export async function addWidget(widgetData) {
1148
- const metadata = getMetadata();
1149
- return Widget.add(widgetData, metadata);
1150
- }
1151
- /**
1152
- * Reorder the widgets for a subreddit.
1153
- *
1154
- * @param subredditName - The name of the subreddit to reorder the widgets for.
1155
- * @param orderByIds - An array of widget IDs in the order that they should be displayed.
1156
- */
1157
- export async function reorderWidgets(subredditName, orderByIds) {
1158
- const metadata = getMetadata();
1159
- return Widget.reorder(subredditName, orderByIds, metadata);
1160
- }
1161
- /**
1162
- * Get a wiki page from a subreddit.
1163
- *
1164
- * @param subredditName - The name of the subreddit to get the wiki page from.
1165
- * @param page - The name of the wiki page to get.
1166
- * @returns The requested WikiPage object.
1167
- */
1168
- export async function getWikiPage(subredditName, page) {
1169
- const metadata = getMetadata();
1170
- return WikiPage.getPage(subredditName, page, metadata);
1171
- }
1172
- /**
1173
- * Get the wiki pages for a subreddit.
1174
- *
1175
- * @param subredditName - The name of the subreddit to get the wiki pages from.
1176
- * @returns A list of the wiki page names for the subreddit.
1177
- */
1178
- export async function getWikiPages(subredditName) {
1179
- const metadata = getMetadata();
1180
- return WikiPage.getPages(subredditName, metadata);
1181
- }
1182
- /**
1183
- * Create a new wiki page for a subreddit.
1184
- *
1185
- * @param options - Options for the request
1186
- * @param options.subredditName - The name of the subreddit the wiki is in.
1187
- * @param options.page - The name of the wiki page to create.
1188
- * @param options.content - The Markdown content of the wiki page.
1189
- * @param options.reason - The reason for creating the wiki page.
1190
- * @returns - The created WikiPage object.
1191
- */
1192
- export async function createWikiPage(options) {
1193
- const metadata = getMetadata();
1194
- return WikiPage.createPage(options, metadata);
1195
- }
1196
- /**
1197
- * Update a wiki page.
1198
- *
1199
- * @param options - Options for the request
1200
- * @param options.subredditName - The name of the subreddit the wiki is in.
1201
- * @param options.page - The name of the wiki page to update.
1202
- * @param options.content - The Markdown content of the wiki page.
1203
- * @param options.reason - The reason for updating the wiki page.
1204
- * @returns The updated WikiPage object.
1205
- */
1206
- export async function updateWikiPage(options) {
1207
- const metadata = getMetadata();
1208
- return WikiPage.updatePage(options, metadata);
1209
- }
1210
- /**
1211
- * Get the revisions for a wiki page.
1212
- *
1213
- * @param options - Options for the request
1214
- * @param options.subredditName - The name of the subreddit the wiki is in.
1215
- * @param options.page - The name of the wiki page to get the revisions for.
1216
- * @param options.limit - The maximum number of revisions to return.
1217
- * @param options.after - The ID of the revision to start after.
1218
- * @returns A Listing of WikiPageRevision objects.
1219
- */
1220
- export function getWikiPageRevisions(options) {
1221
- const metadata = getMetadata();
1222
- return WikiPage.getPageRevisions(options, metadata);
1223
- }
1224
- /**
1225
- * Revert a wiki page to a previous revision.
1226
- *
1227
- * @param subredditName - The name of the subreddit the wiki is in.
1228
- * @param page - The name of the wiki page to revert.
1229
- * @param revisionId - The ID of the revision to revert to.
1230
- */
1231
- export async function revertWikiPage(subredditName, page, revisionId) {
1232
- const metadata = getMetadata();
1233
- return WikiPage.revertPage(subredditName, page, revisionId, metadata);
1234
- }
1235
- /**
1236
- * Get the settings for a wiki page.
1237
- *
1238
- * @param subredditName - The name of the subreddit the wiki is in.
1239
- * @param page - The name of the wiki page to get the settings for.
1240
- * @returns A WikiPageSettings object.
1241
- */
1242
- export async function getWikiPageSettings(subredditName, page) {
1243
- const metadata = getMetadata();
1244
- return WikiPage.getPageSettings(subredditName, page, metadata);
1245
- }
1246
- /**
1247
- * Update the settings for a wiki page.
1248
- *
1249
- * @param options - Options for the request
1250
- * @param options.subredditName - The name of the subreddit the wiki is in.
1251
- * @param options.page - The name of the wiki page to update the settings for.
1252
- * @param options.listed - Whether the wiki page should be listed in the wiki index.
1253
- * @param options.permLevel - The permission level required to edit the wiki page.
1254
- * @returns A WikiPageSettings object.
1255
- */
1256
- export async function updateWikiPageSettings(options) {
1257
- const metadata = getMetadata();
1258
- return WikiPage.updatePageSettings(options, metadata);
1259
- }
1260
- /**
1261
- * Add an editor to a wiki page.
1262
- *
1263
- * @param subredditName - The name of the subreddit the wiki is in.
1264
- * @param page - The name of the wiki page to add the editor to.
1265
- * @param username - The username of the user to add as an editor.
1266
- */
1267
- export async function addEditorToWikiPage(subredditName, page, username) {
1268
- const metadata = getMetadata();
1269
- return WikiPage.addEditor(subredditName, page, username, metadata);
1270
- }
1271
- /**
1272
- * Remove an editor from a wiki page.
1273
- *
1274
- * @param subredditName - The name of the subreddit the wiki is in.
1275
- * @param page - The name of the wiki page to remove the editor from.
1276
- * @param username - The username of the user to remove as an editor.
1277
- */
1278
- export async function removeEditorFromWikiPage(subredditName, page, username) {
1279
- const metadata = getMetadata();
1280
- return WikiPage.removeEditor(subredditName, page, username, metadata);
1281
- }
1282
- /**
1283
- * Get private messages sent to the currently authenticated user.
1284
- *
1285
- * @param options - Options for the request
1286
- * @param options.type - The type of messages to get.
1287
- */
1288
- export function getMessages(options) {
1289
- const metadata = getMetadata();
1290
- return PrivateMessage.getMessages(options, metadata);
1291
- }
1292
- /**
1293
- * Mark all private messages as read.
1294
- *
1295
- */
1296
- export function markAllMessagesAsRead() {
1297
- const metadata = getMetadata();
1298
- return PrivateMessage.markAllAsRead(metadata);
1299
- }
1300
- /**
1301
- * Report a Post or Comment
1302
- *
1303
- * The report is sent to the moderators of the subreddit for review.
1304
- *
1305
- * @param thing Post or Comment
1306
- * @param options Options
1307
- * @param options.reason Why the thing is reported
1308
- *
1309
- * @example
1310
- * ```ts
1311
- * await report(post, {
1312
- * reason: 'This is spam!',
1313
- * })
1314
- * ```
1315
- */
1316
- export function report(thing, options) {
1317
- const metadata = getMetadata();
1318
- const client = Devvit.redditAPIPlugins.LinksAndComments;
1319
- return client.Report({
1320
- reason: options.reason,
1321
- thingId: thing.id,
1322
- srName: thing.subredditName,
1323
- usernames: thing.authorName,
1324
- }, metadata);
1325
- }
1326
- export function getModQueue(options) {
1327
- const metadata = getMetadata();
1328
- return Subreddit.aboutLocation({
1329
- ...options,
1330
- location: AboutLocations.Modqueue,
1331
- }, metadata);
1332
- }
1333
- export function getReports(options) {
1334
- const metadata = getMetadata();
1335
- return Subreddit.aboutLocation({
1336
- ...options,
1337
- location: AboutLocations.Reports,
1338
- }, metadata);
1339
- }
1340
- export function getSpam(options) {
1341
- const metadata = getMetadata();
1342
- return Subreddit.aboutLocation({
1343
- ...options,
1344
- location: AboutLocations.Spam,
1345
- }, metadata);
1346
- }
1347
- export function getUnmoderated(options) {
1348
- const metadata = getMetadata();
1349
- return Subreddit.aboutLocation({
1350
- ...options,
1351
- location: AboutLocations.Unmoderated,
1352
- }, metadata);
1353
- }
1354
- export function getEdited(options) {
1355
- const metadata = getMetadata();
1356
- return Subreddit.aboutLocation({
1357
- ...options,
1358
- location: AboutLocations.Edited,
1359
- }, metadata);
1360
- }
1361
- /**
1362
- * Gets a {@link Vault} for the specified address.
1363
- *
1364
- * @param {string} address - The address (starting with 0x) of the Vault.
1365
- * @example
1366
- * ```ts
1367
- * const vault = await getVaultByAddress('0x205ee28744456bDBf180A0Fa7De51e0F116d54Ed');
1368
- * ```
1369
- */
1370
- export function getVaultByAddress(address) {
1371
- const metadata = getMetadata();
1372
- return _getVaultByAddress(address, metadata);
1373
- }
1374
- /**
1375
- * Gets a {@link Vault} for the specified user.
1376
- *
1377
- * @param {string} userId - The ID (starting with t2_) of the Vault owner.
1378
- * @example
1379
- * ```ts
1380
- * const vault = await getVaultByUserId('t2_1w72');
1381
- * ```
1382
- */
1383
- export function getVaultByUserId(userId) {
1384
- const metadata = getMetadata();
1385
- return _getVaultByUserId(asTID(userId), metadata);
1386
- }
1387
- /**
1388
- * Returns a leaderboard for a given subreddit ID.
1389
- *
1390
- * @param subredditId ID of the subreddit for which the leaderboard is being queried.
1391
- *
1392
- * @returns {SubredditLeaderboard} Leaderboard for the given subreddit.
1393
- */
1394
- export function getSubredditLeaderboard(subredditId) {
1395
- const metadata = getMetadata();
1396
- return _getSubredditLeaderboard(subredditId, metadata);
1397
- }
1398
- /**
1399
- * Returns the styles for a given subreddit ID.
1400
- *
1401
- * @param subredditId ID of the subreddit from which to retrieve the styles.
1402
- *
1403
- * @returns {SubredditStyles} Styles for the given subreddit.
1404
- */
1405
- export function getSubredditStyles(subredditId) {
1406
- const metadata = getMetadata();
1407
- return _getSubredditStyles(subredditId, metadata);
1408
- }
1409
- /**
1410
- * Subscribes to the subreddit in which the app is installed. No-op if the user is already subscribed.
1411
- * This method will execute as the app account by default.
1412
- * To subscribe on behalf of a user, please contact Reddit.
1413
- */
1414
- export async function subscribeToCurrentSubreddit() {
1415
- const metadata = getMetadata();
1416
- const currentSubreddit = await getCurrentSubreddit();
1417
- const client = Devvit.redditAPIPlugins.Subreddits;
1418
- await client.Subscribe({
1419
- action: 'sub',
1420
- actionSource: '',
1421
- srName: currentSubreddit.name,
1422
- sr: '',
1423
- skipInitialDefaults: true,
1424
- }, metadata);
1425
- }
1426
- /**
1427
- * Unsubscribes from the subreddit in which the app is installed. No-op if the user isn't subscribed.
1428
- * This method will execute as the app account by default.
1429
- * To unsubscribe on behalf of a user, please contact Reddit.
1430
- */
1431
- export async function unsubscribeFromCurrentSubreddit() {
1432
- const metadata = getMetadata();
1433
- const currentSubreddit = await getCurrentSubreddit();
1434
- const client = Devvit.redditAPIPlugins.Subreddits;
1435
- await client.Subscribe({
1436
- action: 'unsub',
1437
- actionSource: '',
1438
- srName: currentSubreddit.name,
1439
- sr: '',
1440
- skipInitialDefaults: false,
1441
- }, metadata);
1442
- }