Comparing version 0.1.15 to 0.1.16-beta.0
@@ -14,2 +14,3 @@ import { Subreddit } from './subreddit.js'; | ||
refreshToken?: string; | ||
expires?: number; | ||
constructor(accessToken: string, clientId: string, clientSecret: string, userAgent: string, refreshToken?: string); | ||
@@ -16,0 +17,0 @@ refreshAccessToken(): Promise<void>; |
@@ -10,3 +10,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import fetch from 'node-fetch'; | ||
import { Subreddit } from './subreddit.js'; | ||
@@ -16,3 +15,3 @@ import { Submission } from './submission.js'; | ||
function base64Encode(str) { | ||
return Buffer.from(str).toString('base64'); | ||
return btoa(str); | ||
} | ||
@@ -25,3 +24,9 @@ export class OAuthError extends Error { | ||
} | ||
// Note | ||
// Changes | ||
// Removed node-fetch | ||
// Use btoa for base64 | ||
// Remove user-agent since it doesn't work on firefox client side for reddit requests | ||
export class Jsrwrap { | ||
// TODO refresh accessToken when expires is expired expires | ||
constructor(accessToken, clientId, clientSecret, userAgent, refreshToken) { | ||
@@ -33,2 +38,3 @@ this.accessToken = accessToken; | ||
this.refreshToken = refreshToken; | ||
this.expires = undefined; | ||
} | ||
@@ -80,4 +86,3 @@ refreshAccessToken() { | ||
Authorization: `Basic ${options.httpBasicAuth}`, | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
'User-Agent': options.userAgent | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}, | ||
@@ -237,4 +242,3 @@ body: options.body | ||
headers: { | ||
Authorization: `Bearer ${this.accessToken}`, | ||
'User-Agent': this.userAgent | ||
Authorization: `Bearer ${this.accessToken}` | ||
} | ||
@@ -254,4 +258,3 @@ }); | ||
Authorization: `Bearer ${this.accessToken}`, | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
'User-Agent': this.userAgent | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}, | ||
@@ -272,4 +275,3 @@ body: `raw_json=1&${buildQueryString(params)}` | ||
Authorization: `Bearer ${this.accessToken}`, | ||
'Content-Type': 'application/json', | ||
'User-Agent': this.userAgent | ||
'Content-Type': 'application/json' | ||
}, | ||
@@ -276,0 +278,0 @@ body: data |
@@ -78,3 +78,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const [submission, comments] = yield this._reddit.get(`/comments/${this.submissionId}`, options); | ||
const [submission, comments] = yield this._reddit.get(`comments/${this.submissionId}`, options); | ||
return Object.assign(Object.assign({}, extractSubmissionInfo(submission)), { comments: extractComments(comments) }); | ||
@@ -81,0 +81,0 @@ }); |
@@ -31,4 +31,13 @@ import { Jsrwrap } from './jsrwrap.js'; | ||
getSidebar(): Promise<Widget[]>; | ||
getModerators(): Promise<{ | ||
name: string; | ||
author_flair_text: string; | ||
mod_permissions: string[]; | ||
date: number; | ||
rel_id: string; | ||
id: string; | ||
author_flair_css_class: null; | ||
}[]>; | ||
search(params: SearchParams): Promise<SubmissionData[]>; | ||
} | ||
export {}; |
@@ -31,18 +31,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
// Unused - Keeping for if it could be used later for getSidebar | ||
// function getAboutFromGatewayData(data: SubredditGatewayData) { | ||
// const id = Object.keys(data.subredditAboutInfo)[0]; | ||
// const about = data.subredditAboutInfo[id]; | ||
// const subredditInfo = data.subreddits[id]; | ||
// const style = data.structuredStyles.data.style; | ||
// return { | ||
// subscribers: about.subscribers, | ||
// description: about.publicDescription, | ||
// created: about.created, | ||
// accountsActive: about.accountsActive, | ||
// bannerBackgroundImage: style.bannerBackgroundImage, | ||
// mobileBannerImage: style.mobileBannerImage, | ||
// communityIcon: style.communityIcon | ||
// }; | ||
// } | ||
export class Subreddit { | ||
@@ -73,2 +57,8 @@ constructor(_reddit, subreddit) { | ||
} | ||
getModerators() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield this._reddit.get(`r/${this.subreddit}/about/moderators`); | ||
return res.data.children; | ||
}); | ||
} | ||
search(params) { | ||
@@ -75,0 +65,0 @@ return __awaiter(this, void 0, void 0, function* () { |
@@ -206,2 +206,3 @@ export interface SubmissionData { | ||
height: number; | ||
width: number; | ||
hls_url: string; | ||
@@ -208,0 +209,0 @@ is_gif: boolean; |
{ | ||
"name": "jsrwrap", | ||
"version": "0.1.15", | ||
"version": "0.1.16-beta.0", | ||
"description": "API wrapper for Reddit", | ||
@@ -57,6 +57,3 @@ "repository": { | ||
"vitest": "^0.29.3" | ||
}, | ||
"dependencies": { | ||
"node-fetch": "^3.3.1" | ||
} | ||
} |
0
1916
71372
- Removednode-fetch@^3.3.1
- Removeddata-uri-to-buffer@4.0.1(transitive)
- Removedfetch-blob@3.2.0(transitive)
- Removedformdata-polyfill@4.0.10(transitive)
- Removednode-domexception@1.0.0(transitive)
- Removednode-fetch@3.3.2(transitive)
- Removedweb-streams-polyfill@3.3.3(transitive)