Socket
Socket
Sign inDemoInstall

snoots-revived

Package Overview
Dependencies
8
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0-dev.3 to 1.0.0-dev.4

92

dist/gateway/gateway.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Gateway = void 0;
const tslib_1 = require("tslib");
const got_cjs_1 = tslib_1.__importDefault(require("got-cjs"));
const debug_1 = require("../helper/debug");

@@ -33,2 +31,13 @@ // #region debug logging

}
buildInput(path, query = {}) {
const searchParameters = new URLSearchParams({
...query,
// eslint-disable-next-line @typescript-eslint/naming-convention
raw_json: "1",
// eslint-disable-next-line @typescript-eslint/naming-convention
api_type: "json",
});
const searchParametersString = searchParameters.toString(); // Convert URLSearchParams to string
return new URL(`${path}?${searchParametersString}`, this.endpoint);
}
/**

@@ -49,7 +58,8 @@ * Issue a GET request to the Reddit API.

async get(path, query = {}) {
const options = await this.buildOptions(query);
const options = await this.buildOptions();
debugRequest("GET", path, options);
const response = await got_cjs_1.default.get(this.mapPath(path), options).json();
debugResponse("GET", path, response);
return this.unwrap(response);
const response = await fetchShim("get", this.buildInput(this.mapPath(path), query), options);
const json = (await response.json());
debugResponse("GET", path, json);
return this.unwrap(json);
}

@@ -74,3 +84,3 @@ /**

const formOptions = { form: { api_type: "json", ...form } };
return await this.doPost(path, formOptions, query);
return await this.doPost(this.buildInput(this.mapPath(path), query).toString(), formOptions);
}

@@ -95,3 +105,3 @@ /**

const jsonOptions = { json: { api_type: "json", ...json } };
return await this.doPost(path, jsonOptions, query);
return await this.doPost(this.buildInput(this.mapPath(path), query).toString(), jsonOptions);
}

@@ -134,9 +144,10 @@ /**

}
async doPost(path, overrideOptions, query) {
const baseOptions = await this.buildOptions(query);
async doPost(path, overrideOptions) {
const baseOptions = await this.buildOptions();
const options = { ...baseOptions, ...overrideOptions };
debugRequest("POST", path, options);
const response = await got_cjs_1.default.post(this.mapPath(path), options).json();
debugResponse("POST", path, response);
return this.unwrap(response);
const response = await fetchShim("post", new URL(path), options);
const json = (await response.json());
debugResponse("POST", path, json);
return this.unwrap(json);
}

@@ -171,9 +182,6 @@ handleError(message, description) {

}
async buildOptions(query) {
async buildOptions() {
const options = {
prefixUrl: this.endpoint,
// eslint-disable-next-line @typescript-eslint/naming-convention
headers: { "user-agent": this.userAgent },
// eslint-disable-next-line @typescript-eslint/naming-convention
searchParams: { ...query, raw_json: 1, api_type: "json" },
hooks: {

@@ -189,9 +197,6 @@ afterResponse: [

if (auth) {
if ("bearer" in auth) {
options.headers["Authorization"] = `bearer ${auth.bearer}`;
}
else {
options.username = auth.user;
options.password = auth.pass;
}
const authHeader = "bearer" in auth
? `bearer ${auth.bearer}`
: `Basic ${Buffer.from(auth.user + ":" + auth.pass).toString("base64")}`;
options.headers["Authorization"] = authHeader;
}

@@ -201,8 +206,9 @@ return options;

transformRedirect(response) {
const { statusCode, headers } = response;
if (headers.location && statusCode >= 300 && statusCode < 400) {
response.rawBody = Buffer.from(JSON.stringify({
const { status, headers } = response;
if (headers.get("location") && status >= 300 && status < 400) {
const updatedBody = Buffer.from(JSON.stringify({
kind: "snoots_redirect",
data: { location: headers.location },
data: { location: headers.get("location") },
}));
return new Response(updatedBody, response);
}

@@ -213,4 +219,4 @@ return response;

const { headers } = response;
const remain = Number.parseInt(headers["x-ratelimit-remaining"]);
const reset = Number.parseInt(headers["x-ratelimit-reset"]);
const remain = Number.parseInt(headers.get("x-ratelimit-remaining"));
const reset = Number.parseInt(headers.get("x-ratelimit-reset"));
// To prevent race conditions, only update the rate limit if either...

@@ -231,2 +237,28 @@ if (

exports.Gateway = Gateway;
async function fetchShim(method, path, options) {
const data = await fetch(path, {
headers: {
...options.headers,
// eslint-disable-next-line @typescript-eslint/naming-convention
"Content-Type": method === "post"
? options.json
? "application/json"
: "application/x-www-form-urlencoded"
: undefined,
},
method,
redirect: "manual",
body: method === "post"
? options.json
? JSON.stringify(options.json)
: new URLSearchParams(options.form).toString()
: undefined,
});
if (options.hooks?.afterResponse)
for (const hook of options.hooks?.afterResponse ?? [])
hook(data, () => {
throw new Error("Retry not supported");
});
return data;
}
//# sourceMappingURL=gateway.js.map

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

const tslib_1 = require("tslib");
// eslint-disable-next-line @typescript-eslint/naming-convention
const debug_1 = tslib_1.__importDefault(require("debug"));

@@ -7,0 +8,0 @@ // Boolean formatter

"use strict";
// Publicly exported types
Object.defineProperty(exports, "__esModule", { value: true });
exports.Voteable = exports.VoteableControls = exports.OtherUser = exports.UserControls = exports.MyUser = exports.MyUserControls = exports.Moderator = exports.ModeratorActionedUser = exports.BannedUser = exports.User = exports.BaseUserControls = exports.Subreddit = exports.SubredditControls = exports.Replyable = exports.ReplyableControls = exports.Post = exports.PostControls = exports.Lockable = exports.LockableControls = exports.Listing = exports.Content = exports.Comment = exports.CommentControls = exports.BaseControls = void 0;
exports.Voteable = exports.VoteableControls = exports.OtherUser = exports.UserControls = exports.MyUser = exports.MyUserControls = exports.Moderator = exports.ModeratorActionedUser = exports.BannedUser = exports.User = exports.BaseUserControls = exports.Subreddit = exports.SubredditControls = exports.Replyable = exports.ReplyableControls = exports.Post = exports.PostControls = exports.MediaFile = exports.Lockable = exports.LockableControls = exports.Listing = exports.Content = exports.Comment = exports.CommentControls = exports.BaseControls = void 0;
var base_controls_1 = require("./base-controls");

@@ -19,18 +19,20 @@ Object.defineProperty(exports, "BaseControls", { enumerable: true, get: function () { return base_controls_1.BaseControls; } });

Object.defineProperty(exports, "Lockable", { enumerable: true, get: function () { return object_2.Lockable; } });
var object_3 = require("./mediafile/object");
Object.defineProperty(exports, "MediaFile", { enumerable: true, get: function () { return object_3.MediaFile; } });
var controls_3 = require("./post/controls");
Object.defineProperty(exports, "PostControls", { enumerable: true, get: function () { return controls_3.PostControls; } });
var object_3 = require("./post/object");
Object.defineProperty(exports, "Post", { enumerable: true, get: function () { return object_3.Post; } });
var object_4 = require("./post/object");
Object.defineProperty(exports, "Post", { enumerable: true, get: function () { return object_4.Post; } });
var controls_4 = require("./replyable/controls");
Object.defineProperty(exports, "ReplyableControls", { enumerable: true, get: function () { return controls_4.ReplyableControls; } });
var object_4 = require("./replyable/object");
Object.defineProperty(exports, "Replyable", { enumerable: true, get: function () { return object_4.Replyable; } });
var object_5 = require("./replyable/object");
Object.defineProperty(exports, "Replyable", { enumerable: true, get: function () { return object_5.Replyable; } });
var controls_5 = require("./subreddit/controls");
Object.defineProperty(exports, "SubredditControls", { enumerable: true, get: function () { return controls_5.SubredditControls; } });
var object_5 = require("./subreddit/object");
Object.defineProperty(exports, "Subreddit", { enumerable: true, get: function () { return object_5.Subreddit; } });
var object_6 = require("./subreddit/object");
Object.defineProperty(exports, "Subreddit", { enumerable: true, get: function () { return object_6.Subreddit; } });
var controls_6 = require("./user/base/controls");
Object.defineProperty(exports, "BaseUserControls", { enumerable: true, get: function () { return controls_6.BaseUserControls; } });
var object_6 = require("./user/base/object");
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return object_6.User; } });
var object_7 = require("./user/base/object");
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return object_7.User; } });
var banned_1 = require("./user/moderator-actioned/banned");

@@ -44,12 +46,12 @@ Object.defineProperty(exports, "BannedUser", { enumerable: true, get: function () { return banned_1.BannedUser; } });

Object.defineProperty(exports, "MyUserControls", { enumerable: true, get: function () { return controls_7.MyUserControls; } });
var object_7 = require("./user/my-user/object");
Object.defineProperty(exports, "MyUser", { enumerable: true, get: function () { return object_7.MyUser; } });
var object_8 = require("./user/my-user/object");
Object.defineProperty(exports, "MyUser", { enumerable: true, get: function () { return object_8.MyUser; } });
var controls_8 = require("./user/other-user/controls");
Object.defineProperty(exports, "UserControls", { enumerable: true, get: function () { return controls_8.UserControls; } });
var object_8 = require("./user/other-user/object");
Object.defineProperty(exports, "OtherUser", { enumerable: true, get: function () { return object_8.OtherUser; } });
var object_9 = require("./user/other-user/object");
Object.defineProperty(exports, "OtherUser", { enumerable: true, get: function () { return object_9.OtherUser; } });
var controls_9 = require("./voteable/controls");
Object.defineProperty(exports, "VoteableControls", { enumerable: true, get: function () { return controls_9.VoteableControls; } });
var object_9 = require("./voteable/object");
Object.defineProperty(exports, "Voteable", { enumerable: true, get: function () { return object_9.Voteable; } });
var object_10 = require("./voteable/object");
Object.defineProperty(exports, "Voteable", { enumerable: true, get: function () { return object_10.Voteable; } });
//# sourceMappingURL=index.js.map

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

const more = {
count: 0,
count: 0, // TODO
name: `${name.slice(0, 2)}__`,

@@ -28,3 +28,3 @@ id: "_",

parent_id: name,
depth: 0,
depth: 0, // TODO
children: [],

@@ -31,0 +31,0 @@ };

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MediaGif = exports.MediaVideo = exports.MediaImg = exports.MediaFile = void 0;
/**
* @internal
* A class representing media files uploaded to reddit to be embedded on
* submissions.
*/
/** @internal */

@@ -5,0 +10,0 @@ class MediaFile {

@@ -1090,6 +1090,6 @@ "use strict";

case "gallery":
submitResponse = await this.gateway.postJson("api/submit_gallery_post.json", request);
submitResponse = await this.gateway.postJson("api/submit_gallery_post.json", request, {});
break;
case "poll":
submitResponse = await this.gateway.postJson("api/submit_poll_post", request);
submitResponse = await this.gateway.postJson("api/submit_poll_post", request, {});
break;

@@ -1096,0 +1096,0 @@ default:

@@ -61,4 +61,5 @@ "use strict";

this.over18 = data.over18;
// this.predictionLeaderboardEntryType = data.predictionLeaderboardEntryType;
// this.primaryColor = data.primaryColor;
// this.predictionLeaderboardEntryType =
// data.predictionLeaderboardEntryType; this.primaryColor =
// data.primaryColor;
this.publicTraffic = data.publicTraffic;

@@ -65,0 +66,0 @@ this.quarantine = data.quarantine;

{
"name": "snoots-revived",
"version": "1.0.0-dev.3",
"version": "1.0.0-dev.4",
"description": "A modern, fully-featured, strongly-typed reddit api.",

@@ -29,4 +29,3 @@ "module": "dist/index.mjs",

"debug": "^4.3.4",
"got-cjs": "^12.5.4",
"tslib": "^2.5.0",
"tslib": "^2.6.2",
"ws": "^8.16.0"

@@ -43,34 +42,34 @@ },

"@semantic-release/release-notes-generator": "11.0.1",
"@types/debug": "4.1.7",
"@types/jest": "29.5.1",
"@types/node": "^20.11.25",
"@types/debug": "4.1.12",
"@types/jest": "29.5.12",
"@types/node": "^20.12.7",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "5.59.5",
"@typescript-eslint/parser": "5.59.5",
"@typescript-eslint/eslint-plugin": "7.6.0",
"@typescript-eslint/parser": "7.6.0",
"del-cli": "5.0.0",
"eslint": "8.40.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-comment-length": "0.9.3",
"eslint-plugin-deprecation": "1.4.1",
"eslint": "^8.0.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-comment-length": "1.7.3",
"eslint-plugin-deprecation": "2.0.0",
"eslint-plugin-eslint-comments": "3.2.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jest": "27.2.1",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jest": "28.2.0",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-promise": "6.1.1",
"eslint-plugin-simple-import-sort": "10.0.0",
"eslint-plugin-sonarjs": "0.19.0",
"eslint-plugin-unicorn": "47.0.0",
"eslint-plugin-simple-import-sort": "12.0.0",
"eslint-plugin-sonarjs": "0.25.1",
"eslint-plugin-unicorn": "52.0.0",
"fast-check": "3.8.1",
"husky": "8.0.3",
"is-ci": "3.0.1",
"jest": "29.5.0",
"jest": "29.7.0",
"lint-staged": "13.2.2",
"nock": "13.3.1",
"nock": "^14.0.0-beta.5",
"npm-run-all": "4.1.5",
"prettier": "2.8.8",
"prettier": "3.2.5",
"semantic-release": "21.0.2",
"supports-color": "9.3.1",
"ts-jest": "29.1.0",
"typedoc": "^0.25.11",
"typescript": "5.0.4"
"ts-jest": "29.1.2",
"typedoc": "^0.25.13",
"typescript": "5.4.4"
},

@@ -77,0 +76,0 @@ "engines": {

import type { Data, Maybe } from "../helper/types";
import type { Auth, GotOptions, GotResponse, Query, RateLimit, SomeResponse } from "./types";
import type { Auth, Query, RateLimit, ShimOptions, SomeResponse } from "./types";
/**

@@ -16,2 +16,3 @@ * The gateway to the Reddit api.

constructor(endpoint: string, userAgent: string);
protected buildInput(path: string, query?: Query): URL;
/**

@@ -77,9 +78,9 @@ * Issue a GET request to the Reddit API.

protected abstract auth(): Promise<Maybe<Auth>>;
protected doPost<T>(path: string, overrideOptions: GotOptions, query: Query): Promise<T>;
protected doPost<T>(path: string, overrideOptions: Data): Promise<T>;
protected abstract mapPath(path: string): string;
protected handleError(message: string, description?: string): never;
protected unwrap<T>(response: SomeResponse<T>): T;
protected buildOptions(query: Query): Promise<GotOptions>;
protected transformRedirect(response: GotResponse): GotResponse;
protected updateRatelimit(response: GotResponse): GotResponse;
protected buildOptions(): Promise<ShimOptions>;
protected transformRedirect(response: Response): Response;
protected updateRatelimit(response: Response): Response;
}

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

export type { OptionsOfTextResponseBody as GotOptions, Response as GotResponse, } from "got-cjs";
/**
* Options for configuring the Shim.
*/
export type ShimOptions = {
headers: Record<string, string>;
hooks: Record<string, {
/**
* A function that modifies the response or triggers a retry.
* @param response The response object.
* @param retry A function that can be called to retry the request.
* @returns The modified response object.
*/
(response: Response, retry: () => void): Response;
}[]>;
followRedirect: boolean;
username?: string;
password?: string;
form?: Record<string, string>;
json?: Record<string, string>;
};
/** The types of values that are allowed in a query. */

@@ -32,1 +51,2 @@ export type QueryValue = string | number | boolean | null | undefined;

export type SomeResponse<T> = T | RedditError | RedditJsonResponse<T>;
export {};

@@ -12,2 +12,4 @@ export { BaseControls } from "./base-controls";

export { Lockable } from "./lockable/object";
export type { FileDetails } from "./mediafile/object";
export { MediaFile } from "./mediafile/object";
export { PostControls } from "./post/controls";

@@ -14,0 +16,0 @@ export type { PostData, SuggestedSort } from "./post/object";

@@ -33,6 +33,4 @@ /**

*/
export interface MediaFile extends FileDetails {
}
/** @internal */
export declare class MediaFile {
export declare class MediaFile implements FileDetails {
/**

@@ -42,2 +40,12 @@ * @summary The media type. Only available on {@link MediaImg}, {@link MediaVideo} and {@link MediaGif}.

type?: string;
/** @internal */
fileUrl: string;
/** @internal */
mediaId: string;
/** @internal */
websocketUrl?: string;
/** @internal */
caption?: string;
/** @internal */
outboundUrl?: string;
/**

@@ -44,0 +52,0 @@ * @summary Constructs a new media file. In most cases you should call {@link SubredditControls#uploadMedia} instead.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc