@r/api-client
Advanced tools
+1
-1
| { | ||
| "name": "@r/api-client", | ||
| "version": "3.33.2", | ||
| "version": "3.34.0", | ||
| "description": "A wrapper for Reddit's API", | ||
@@ -5,0 +5,0 @@ "main": "build.js", |
| import apiRequest from '../apiBase/apiRequest'; | ||
| /** | ||
| * Valid distinguish types. | ||
| * Note that the API endpoint used to distinguish posts and comments accepts | ||
| * 'yes' instead of 'moderator' and 'no' instead of ''. See #distinguish | ||
| * @enum | ||
| */ | ||
| const DISTINGUISH_TYPES = { | ||
@@ -25,17 +31,74 @@ NONE: '', | ||
| const distinguish = (apiOptions, fullname, distinguishType) => { | ||
| // Distinguish a link or comment | ||
| /** | ||
| * Distinguish a link or comment | ||
| * @function | ||
| * @param {Object} apiOptions | ||
| * @param {string} fullname The fullname of the target comment | ||
| * @param {DISTINGUISH_TYPES} distinguishType What type of distinguish is being set | ||
| * @param {?bool} [_sticky] For internal use by #setStickyComment | ||
| */ | ||
| const distinguish = (apiOptions, fullname, distinguishType, _sticky=null) => { | ||
| const distinguishTypeMap = { | ||
| 'moderator': 'yes', | ||
| '': 'no', | ||
| [DISTINGUISH_TYPES.MODERATOR]: 'yes', | ||
| [DISTINGUISH_TYPES.NONE]: 'no', | ||
| }; | ||
| const body = { | ||
| how: distinguishTypeMap[distinguishType], | ||
| id: fullname, | ||
| }; | ||
| return apiRequest(apiOptions, 'POST', 'api/distinguish', { body, type: 'form' }); | ||
| const how = distinguishTypeMap[distinguishType] || distinguishType; | ||
| if (_sticky !== null) { | ||
| body.sticky = _sticky; | ||
| } | ||
| return apiRequest(apiOptions, 'POST', `api/distinguish/${how}`, { body, type: 'form' }); | ||
| } | ||
| export default { remove, approve, distinguish, DISTINGUISH_TYPES } | ||
| /** | ||
| * Set or unset a stickied post (AKA an "Annoucement"). | ||
| * See also: https://www.reddit.com/dev/api#POST_api_set_subreddit_sticky | ||
| * @function | ||
| * @param {Object} apiOptions | ||
| * @param {string} fullname The fullname of the target post | ||
| * @param {boolean} isStickied Whether to sticky or unsticky the post | ||
| * @param {?number} [stickyNum] Allows for specifying the "slot" to sticky the post | ||
| * into, or for specifying which post to unsticky. | ||
| */ | ||
| const setSubredditSticky = (apiOptions, fullname, isStickied, stickyNum=null) => { | ||
| const body = { | ||
| id: fullname, | ||
| state: isStickied, | ||
| }; | ||
| if (stickyNum) { | ||
| body.num = stickyNum; | ||
| } | ||
| return apiRequest(apiOptions, 'POST', 'api/set_subreddit_sticky', { body, type: 'form' }); | ||
| } | ||
| /** | ||
| * Sticky or unsticky a comment. | ||
| * Sticky comments are a special case of distinguished comments, and are done | ||
| * through the same API endpoint (api/distinguish). That endpoint also handles | ||
| * distinguishing posts, but it does *not* handle sticky posts. To avoid | ||
| * confusion, we'll keep sticky comments separated here. | ||
| * @function | ||
| * @param {Object} apiOptions | ||
| * @param {string} fullname The fullname of the target comment | ||
| * @param {boolean} isStickied Whether to sticky or unsticky the comment | ||
| */ | ||
| const setStickyComment = (apiOptions, fullname, isStickied) => { | ||
| const distinguishType = isStickied ? DISTINGUISH_TYPES.MODERATOR : DISTINGUISH_TYPES.NONE; | ||
| return distinguish(apiOptions, fullname, distinguishType, isStickied); | ||
| }; | ||
| export default { | ||
| remove, | ||
| approve, | ||
| distinguish, | ||
| setStickyComment, | ||
| setSubredditSticky, | ||
| DISTINGUISH_TYPES, | ||
| }; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
247617
1.09%4132
1.42%33
3.13%