Skip to content

Commit d25d81d

Browse files
committed
🔨 chore(breaking): require object for PasteClient#login
1 parent 3ce3114 commit d25d81d

File tree

6 files changed

+36
-18
lines changed

6 files changed

+36
-18
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 5.1.0
4+
5+
- Bump dependencies
6+
- **BREAKING:** `PasteClient#login` now requires an object instead of 2 params.
7+
`const token = await client.login({ name: "user_name", password: "user_password" });`
8+
39
## 5.0.0
410

511
- Bump dependencies

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,32 @@
55

66
A very simple npm package to interact with the pastebin api.
77

8-
## Installation
9-
10-
### npm
8+
**Features**
119

12-
```bash
13-
npm i pastebin-api
14-
```
10+
- Create pastes with all the available API data
11+
- Fetch the raw contents of a paste
12+
- Fetch pastes from the authenticated user via a user login
13+
- Delete pastes from the authenticated user via a user login
1514

16-
### yarn
15+
## Installation
1716

1817
```bash
18+
# npm
19+
npm install pastebin-api
20+
21+
# Yarn
1922
yarn add pastebin-api
23+
24+
# pnpm
25+
pnpm add pastebin-api
2026
```
2127

22-
> **Note**
23-
> `pastebin-api` requires node.js version 14 or higher.
28+
> **Note** > `pastebin-api` requires node.js version 14 or higher.
2429
2530
## Usage
2631

2732
```js
33+
// src/main.js
2834
import { PasteClient, Publicity, ExpireDate } from "pastebin-api";
2935
// const { PasteClient, Publicity, ExpireDate } = require("pastebin-api").default; // using CommonJS
3036

docs/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ console.log(url);
7373
```js
7474
const client = new PasteClient("DEV_API_KEY");
7575

76-
const token = await client.login("user_name", "user_password");
76+
const token = await client.login({ name: "user_name", password: "user_password" });
7777

7878
// This is the user token that can be used to get all the user's pastes or delete one
7979
console.log(token);
@@ -94,7 +94,7 @@ console.log(token);
9494
const client = new PasteClient("DEV_API_KEY");
9595

9696
// Login to get the token
97-
const token = await client.login("user_name", "user_password");
97+
const token = await client.login({ name: "user_name", password: "user_password" });
9898

9999
// Get a limit of 1000 pastes from the user
100100
const pastes = await client.getPastesByUser({
@@ -121,7 +121,7 @@ console.log(pastes);
121121
const client = new PasteClient("DEV_API_KEY");
122122

123123
// Login to get the token
124-
const token = await client.login("user_name", "user_password");
124+
const token = await client.login({ name: "user_name", password: "user_password" });
125125

126126
// Will return a boolean if deleted
127127
const deleted = await client.deletePasteByKey({
@@ -148,7 +148,7 @@ console.log(deleted);
148148
const client = new PasteClient("DEV_API_KEY");
149149

150150
// Login to get the token
151-
const token = await client.login("user_name", "user_password");
151+
const token = await client.login({ name: "user_name", password: "user_password" });
152152

153153
const data = await client.getRawPasteByKey({
154154
pasteKey: "paste-key-here",

src/PasteClient.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
DeletePasteOptions,
88
ClientOptions,
99
GetRawPasteOptions,
10+
LoginOptions,
1011
} from "./types.js";
1112

1213
const ERROR_PREFIX = "[pastebin-api]:" as const;
@@ -84,7 +85,7 @@ export default class PasteClient {
8485
* @returns An array of all the user's pastes
8586
* @see [https://pastebin.com/doc_api#10](https://pastebin.com/doc_api#10)
8687
*/
87-
async getPastesByUser(options: GetPastesOptions): Promise<undefined | ParsedPaste[]> {
88+
async getPastesByUser(options: GetPastesOptions): Promise<ParsedPaste[]> {
8889
if (options.limit && (options.limit < 1 || options.limit > 1000)) {
8990
throw new TypeError(`${ERROR_PREFIX} Limit cannot be lower than 1 or higher than 1000`);
9091
}
@@ -210,14 +211,14 @@ export default class PasteClient {
210211
* @returns The user token to use for other API routes
211212
* @see [https://pastebin.com/doc_api#9](https://pastebin.com/doc_api#9)
212213
*/
213-
async login(name: string, password: string): Promise<string> {
214+
async login(options: LoginOptions): Promise<string> {
214215
const res = await fetch(this.loginUrl, {
215216
method: "POST",
216217
headers: { "Content-Type": "application/x-www-form-urlencoded" },
217218
body: this.encode({
218219
api_dev_key: this.apiKey,
219-
api_user_name: name,
220-
api_user_password: password,
220+
api_user_name: options.name,
221+
api_user_password: options.password,
221222
}),
222223
});
223224

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ export interface DeletePasteOptions {
335335
pasteKey: string;
336336
}
337337

338+
export interface LoginOptions {
339+
name: string;
340+
password: string;
341+
}
342+
338343
export type GetRawPasteOptions = DeletePasteOptions;
339344

340345
export interface ParsedPaste {

tests/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (!USER_NAME || !USER_PASSWORD) {
1818
const client = new PasteClient({ apiKey: KEY });
1919

2020
async function test() {
21-
const token = await client.login(USER_NAME!, USER_PASSWORD!);
21+
const token = await client.login({ name: USER_NAME!, password: USER_PASSWORD! });
2222

2323
// const deleted = await client.deletePasteByKey({
2424
// pasteKey: "XawZVJdA",

0 commit comments

Comments
 (0)