Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wholesome

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wholesome - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

dist/auth/scopes.d.ts

19

dist/auth/index.d.ts

@@ -1,3 +0,3 @@

import Reddit from "../reddit";
declare type AuthConstructor = RTAuth | ClientAuth;
import { Scope } from "./scopes";
export declare type AuthData = RTAuth | ClientAuth | OAuthAuth;
interface RTAuth {

@@ -10,2 +10,3 @@ refreshToken: string;

password: string;
twoFA?: string;
};

@@ -17,7 +18,15 @@ client: {

}
export default class Auth {
accessToken: Promise<string>;
interface OAuthAuth {
code: string;
redirectUri: string;
client: {
id: string;
secret?: string;
};
}
export interface Auth {
username?: string;
constructor(r: Reddit, data: AuthConstructor);
accessToken: string;
scopes: "*" | Set<Scope>;
}
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Auth {
constructor(r, data) {
const config = {
skipAuth: true,
};
if ("client" in data) {
config.auth = {
username: data.client.id,
password: data.client.secret,
};
if (data.auth === undefined) {
config.data = {
grant_type: "client_credentials",
};
}
else {
this.username = data.auth.username;
config.data = {
grant_type: "password",
username: data.auth.username,
password: data.auth.password,
};
}
}
else {
config.data = {
grant_type: "refresh_token",
refresh_token: data.refreshToken,
};
}
this.accessToken = r.api
.post("https://www.reddit.com/api/v1/access_token", config.data, config)
.then((res) => {
return res.data.access_token;
});
}
}
exports.default = Auth;

@@ -14,5 +14,5 @@ "use strict";

return (config) => __awaiter(this, void 0, void 0, function* () {
if (!config.skipAuth && r.auth) {
if (r.auth && !config.skipAuth) {
config.baseURL = "https://oauth.reddit.com";
config.headers.authorization = `Bearer ${yield r.auth.accessToken}`;
config.headers.authorization = `Bearer ${r.auth.accessToken}`;
}

@@ -19,0 +19,0 @@ return config;

@@ -1,2 +0,2 @@

import { AxiosResponse } from "axios";
export default function debugInterceptor(res: AxiosResponse): AxiosResponse<any>;
import { AxiosRequestConfig } from "axios";
export default function debugInterceptor(config: AxiosRequestConfig): AxiosRequestConfig;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
function debugInterceptor(res) {
console.log(res.request);
return res;
const buildURL_1 = __importDefault(require("axios/lib/helpers/buildURL"));
const combineURLs_1 = __importDefault(require("axios/lib/helpers/combineURLs"));
const isAbsoluteURL_1 = __importDefault(require("axios/lib/helpers/isAbsoluteURL"));
function debugInterceptor(config) {
var url = config.url || "";
if (config.baseURL && !isAbsoluteURL_1.default(url)) {
url = combineURLs_1.default(config.baseURL, url);
}
url = buildURL_1.default(url, config.params, config.paramsSerializer);
console.log(config.method, url);
return config;
}
exports.default = debugInterceptor;
import Reddit from "./reddit";
export default Reddit;
export { Scope } from "./auth/scopes";
export { List } from "./list/list";
export { default as Page } from "./list/page";
export { default as Content } from "./media/content";
export { default as Embed } from "./media/embed";
export { Image } from "./media/image";

@@ -7,0 +9,0 @@ export { default as Poll } from "./media/poll";

@@ -48,7 +48,6 @@ "use strict";

this.r.authScope("subscribe");
const user = this.r.authUsername();
const res = yield this.r.api.post("api/multi/copy", {
display_name: name,
from: this.path,
to: `user/${encodeURIComponent(user)}/m/${encodeURIComponent(name)}`,
to: `user/${encodeURIComponent(this.r.needUsername)}/m/${encodeURIComponent(name)}`,
});

@@ -55,0 +54,0 @@ console.log(res.data);

@@ -17,3 +17,3 @@ "use strict";

this.edited = data.edited ? new Date(data.edited * 1000) : null;
this.url = `https://reddit.com${data.permalink}`;
this.url = r.linkUrl + data.permalink;
this.score = data.score_hidden ? null : data.score;

@@ -20,0 +20,0 @@ this.voted = data.likes === null ? 0 : data.likes ? 1 : -1;

import Action from "../../../media/actions";
import Content from "../../../media/content";
import Embed from "../../../media/embed";
import GIF from "../../../media/gif";

@@ -44,3 +45,4 @@ import { Image, Stream, Video } from "../../../media/image";

crosspostable: boolean;
link: string;
link: string | null;
rawLink: string;
body: Content | null;

@@ -53,3 +55,4 @@ thumbnail: Image | null;

poll: Poll | null;
embed: Embed | null;
constructor(r: Reddit, full: Api.GetSubmission | Api.Submission);
}

@@ -15,9 +15,7 @@ "use strict";

this.author =
data.author_fullname === undefined
? null
: new user_1.SubmissionUser(this.r, data);
data.author_fullname === undefined ? null : new user_1.SubmissionUser(r, data);
this.subreddit = r.subreddit(data.subreddit);
this.created = new Date(data.created_utc * 1000);
this.edited = data.edited ? new Date(data.edited * 1000) : null;
this.url = `https://reddit.com${data.permalink}`;
this.url = r.linkUrl + data.permalink;
this.score = data.score;

@@ -63,3 +61,8 @@ this.upvoteRatio = data.upvote_ratio;

this.crosspostable = data.is_crosspostable;
this.link = data.url;
this.link =
data.is_reddit_media_domain ||
data.url === `https://www.reddit.com${data.permalink}`
? null
: data.url;
this.rawLink = data.url;
this.body =

@@ -84,2 +87,3 @@ data.selftext_html === null

this.video = null;
this.embed = null;
if (data.preview !== undefined) {

@@ -118,5 +122,18 @@ const img = data.preview.images[0];

if (data.secure_media) {
if (!("reddit_video" in data.secure_media))
console.log(data.secure_media);
this.video = mapVideo(data.secure_media.reddit_video);
if ("reddit_video" in data.secure_media) {
this.video = mapVideo(data.secure_media.reddit_video);
}
else if ("oembed" in data.secure_media) {
const e = data.secure_media.oembed;
this.embed = {
title: e.title || null,
author: {
name: e.author_name,
url: e.author_url,
},
html: e.html,
width: e.width,
height: e.height,
};
}
}

@@ -123,0 +140,0 @@ this.rpan =

import { List } from "../list/list";
import { Message } from "./message";
import { FullSubreddit } from "./subreddit";

@@ -6,2 +7,3 @@ import { User } from "./user";

subreddits(): List<FullSubreddit, Api.SubredditWrap>;
messageInbox(): List<Message, Api.MessageWrap>;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const list_1 = require("../list/list");
const message_1 = require("./message");
const subreddit_1 = require("./subreddit");

@@ -11,3 +12,7 @@ const user_1 = require("./user");

}
messageInbox() {
this.r.authScope("privatemessages");
return new list_1.List(this.r, "message/inbox", (d) => new message_1.Message(this.r, d.data));
}
}
exports.default = Self;

@@ -26,3 +26,3 @@ "use strict";

get url() {
return `https://www.reddit.com/r/${encodeURIComponent(this.name)}`;
return `${this.r.linkUrl}/r/${encodeURIComponent(this.name)}`;
}

@@ -29,0 +29,0 @@ get stylesheet() {

@@ -10,3 +10,2 @@ import Identified from "../../interfaces/identified";

description: string | null;
url: string;
icon: Image;

@@ -13,0 +12,0 @@ avatar: Image | null;

@@ -12,3 +12,2 @@ "use strict";

this.description = data.subreddit.public_description || null;
this.url = `https://reddit.com${data.subreddit.url}`;
this.icon = {

@@ -15,0 +14,0 @@ native: {

@@ -10,2 +10,3 @@ import Fetchable from "../../interfaces/fetchable";

constructor(r: Reddit, name: string);
get url(): string;
fetch(): Promise<FullUser>;

@@ -12,0 +13,0 @@ nameAvailable(): Promise<boolean>;

@@ -21,2 +21,5 @@ "use strict";

}
get url() {
return `${this.r.linkUrl}/user/${encodeURIComponent(this.name)}`;
}
fetch() {

@@ -23,0 +26,0 @@ return __awaiter(this, void 0, void 0, function* () {

@@ -1,4 +0,4 @@

import { User } from ".";
import Reddit from "../../reddit";
import { UserFlair } from "./flair";
import { User } from "./small";
export declare class SubmissionUser extends User {

@@ -5,0 +5,0 @@ id: string;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubmissionUser = void 0;
const _1 = require(".");
const flair_1 = require("./flair");
class SubmissionUser extends _1.User {
const small_1 = require("./small");
class SubmissionUser extends small_1.User {
constructor(r, data) {

@@ -8,0 +8,0 @@ super(r, data.author);

import { AxiosInstance } from "axios";
import Auth from "./auth";
import { Auth, AuthData } from "./auth";
import { Scope } from "./auth/scopes";

@@ -15,5 +15,9 @@ import { Submission } from "./objects/post";

auth?: Auth;
get needAuth(): Auth;
get needUsername(): string;
linkUrl: string;
constructor(data: RedditConstructor);
login(data: AuthData): Promise<void>;
oauth(clientId: string, redirectUri: string, scopes: Scope[], temporary?: boolean): string;
authScope(...scopes: Scope[]): void;
authUsername(): string;
submission(id: string): Submission;

@@ -20,0 +24,0 @@ subreddit(name: string): Subreddit;

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -17,2 +26,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

constructor(data) {
this.linkUrl = "https://www.reddit.com";
this.api = axios_1.default.create({

@@ -23,18 +33,115 @@ baseURL: "https://www.reddit.com",

});
if (data.debug) {
this.api.interceptors.request.use(debug_1.default);
}
this.api.interceptors.request.use(fields_1.default);
this.api.interceptors.request.use(body_1.default);
this.api.interceptors.request.use(auth_1.default(this));
if (data.debug) {
this.api.interceptors.response.use(debug_1.default);
}
this.api.interceptors.response.use(error_1.default);
}
authScope(...scopes) { }
authUsername() {
if (this.auth === undefined)
throw "Not authenticated";
if (this.auth.username === undefined)
throw "Not authenticated with a username";
get needAuth() {
if (!this.auth)
throw "You need to be authenticated to use this function";
return this.auth;
}
get needUsername() {
if (!this.auth || !this.auth.username)
throw "You need to be authenticated with a user";
return this.auth.username;
}
login(data) {
return __awaiter(this, void 0, void 0, function* () {
var body;
const config = { skipAuth: true };
var username;
if ("code" in data) {
config.auth = {
username: data.client.id,
password: data.client.secret || "",
};
body = {
grant_type: "authorization_code",
code: data.code,
redirect_uri: data.redirectUri,
};
}
else if ("client" in data) {
config.auth = {
username: data.client.id,
password: data.client.secret,
};
if (data.auth === undefined) {
body = {
grant_type: "client_credentials",
};
}
else {
username = data.auth.username;
body = {
grant_type: "password",
username: data.auth.username,
password: data.auth.twoFA
? `${data.auth.password}:${data.auth.twoFA}`
: data.auth.password,
};
}
}
else {
body = {
grant_type: "refresh_token",
refresh_token: data.refreshToken,
};
}
const res = yield this.api.post("https://www.reddit.com/api/v1/access_token", body, config);
if ("error" in res.data) {
throw res.data.error;
}
const scopes = res.data.scope === "*"
? "*"
: new Set(res.data.scope.split(" "));
if (res.data.refresh_token) {
const refresh = (data) => {
const timeout = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
const res = yield this.api.post("https://www.reddit.com/api/v1/access_token", {
grant_type: "refresh_token",
refresh_token: data.refresh_token,
}, { skipAuth: true });
if (this.auth === undefined)
return;
this.auth.accessToken = res.data.access_token;
refresh(res.data);
}), (data.expires_in - 30) * 1000);
timeout.unref();
};
refresh(res.data);
}
else {
setTimeout(() => (this.auth = undefined)).unref();
}
this.auth = {
username,
accessToken: res.data.access_token,
scopes,
};
if ("code" in data && (scopes === "*" || scopes.has("identity"))) {
const res2 = yield this.api.get("api/v1/me");
this.auth.username = res2.data.name;
}
});
}
oauth(clientId, redirectUri, scopes, temporary) {
return `https://www.reddit.com/api/v1/authorize?client_id=${encodeURIComponent(clientId)}&response_type=code&state=+&redirect_uri=${encodeURIComponent(redirectUri)}&duration=${temporary ? "temporary" : "permanent"}&scope=${scopes.join("+")}`;
}
authScope(...scopes) {
const auth = this.needAuth;
if (auth.scopes === "*")
return;
const needed = [];
for (const s of scopes) {
if (!auth.scopes.has(s))
needed.push(s);
}
if (needed.length !== 0)
throw `You are missing the ${needed.join(", ")} scope${needed.length === 1 ? "" : "s"}`;
}
submission(id) {

@@ -41,0 +148,0 @@ return new post_1.Submission(this, id);

{
"name": "wholesome",
"version": "0.1.2",
"version": "0.1.3",
"description": "A Reddit API wrapper",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc