New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@r/api-client

Package Overview
Dependencies
Maintainers
11
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@r/api-client - npm Package Compare versions

Comparing version
3.33.2
to
3.34.0
+1
-1
package.json
{
"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