instapaper-ts 1.0.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # instapaper-ts
2
+
3
+ `instapaper-ts` is an type-safe client for [Instapaper](https://instapaper.com).
4
+
5
+ Supports all available endpoints from the [Full Developer API](https://www.instapaper.com/api)!
6
+
7
+ ---
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ npm install --save-dev instapaper-ts
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import { Instapaper } from "instapaper-ts";
19
+
20
+ const instapaper = new Instapaper(CONSUMER_KEY, CONSUMER_SECRET);
21
+
22
+ instapaper.setCredentials(USERNAME, PASSWORD);
23
+
24
+ const bookmarks = await instapaper.bookmarks.list({ limit: 50 });
25
+
26
+ console.log(bookmarks);
27
+ ```
28
+
29
+ ## Methods
30
+
31
+ See [Full API](https://www.instapaper.com/api) documentation for expected parameters and return types.
32
+
33
+ ### Authentication
34
+
35
+ - setCredentials
36
+ - verifyCredentials
37
+
38
+ ### Bookmarks
39
+
40
+ - list
41
+ - updateReadProgress
42
+ - add
43
+ - delete
44
+ - star
45
+ - unstar
46
+ - archive
47
+ - unarchive
48
+ - move
49
+ - getText
50
+
51
+ ### Folders
52
+
53
+ - list
54
+ - add
55
+ - delete
56
+ - setOrder
57
+
58
+ ### Highlights
59
+
60
+ - list
61
+ - add
62
+ - delete
63
+
64
+ ---
65
+
66
+ ## Terms of Use
67
+
68
+ Please read the full Instapaper [Terms of Use](https://www.instapaper.com/api/terms) before using this library.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import OAuth from 'oauth-1.0a';
2
+
1
3
  type User = {
2
4
  type: "user";
3
5
  user_id: number;
@@ -85,11 +87,18 @@ declare class Instapaper {
85
87
  private username?;
86
88
  private password?;
87
89
  private token?;
88
- constructor(consumerKey: string, consumerSecret: string);
89
- setCredentials: (username: string, password: string) => void;
90
+ constructor({ consumerKey, consumerSecret, username, password, token, }: {
91
+ consumerKey: string;
92
+ consumerSecret: string;
93
+ username?: string;
94
+ password?: string;
95
+ token?: OAuth.Token;
96
+ });
90
97
  private makeRequest;
91
98
  private getAccessToken;
92
99
  private request;
100
+ setCredentials: (username: string, password: string) => void;
101
+ verifyCredentials: () => Promise<[User]>;
93
102
  bookmarks: {
94
103
  list: (params?: ListParams) => Promise<(Bookmark | Folder | User | Error | Meta)[]>;
95
104
  updateReadProgress: (params: UpdateReadProgressParams) => Promise<[Bookmark]>;
package/dist/index.js CHANGED
@@ -9,7 +9,13 @@ var Instapaper = class {
9
9
  username;
10
10
  password;
11
11
  token;
12
- constructor(consumerKey, consumerSecret) {
12
+ constructor({
13
+ consumerKey,
14
+ consumerSecret,
15
+ username,
16
+ password,
17
+ token
18
+ }) {
13
19
  this.oauth = new OAuth({
14
20
  consumer: {
15
21
  key: consumerKey,
@@ -18,12 +24,11 @@ var Instapaper = class {
18
24
  signature_method: "HMAC-SHA1",
19
25
  hash_function: (base_string, key) => crypto.createHmac("sha1", key).update(base_string).digest("base64")
20
26
  });
21
- }
22
- setCredentials = (username, password) => {
23
27
  this.username = username;
24
28
  this.password = password;
25
- };
26
- makeRequest = async (url, method = "POST", params = {}, token) => {
29
+ this.token = token;
30
+ }
31
+ makeRequest = async (url, params = {}, token) => {
27
32
  const form = new URLSearchParams();
28
33
  for (const [key, val] of Object.entries(params)) {
29
34
  form.append(key, String(val));
@@ -32,14 +37,14 @@ var Instapaper = class {
32
37
  this.oauth.authorize(
33
38
  {
34
39
  url,
35
- method,
40
+ method: "POST",
36
41
  data: params
37
42
  },
38
43
  token
39
44
  )
40
45
  );
41
46
  const response = await fetch(url, {
42
- method,
47
+ method: "POST",
43
48
  headers: new Headers({ ...headers }),
44
49
  body: form
45
50
  });
@@ -64,11 +69,7 @@ var Instapaper = class {
64
69
  x_auth_password: this.password,
65
70
  x_auth_mode: "client_auth"
66
71
  };
67
- const responseText = await this.makeRequest(
68
- this.authUrl,
69
- "POST",
70
- params
71
- );
72
+ const responseText = await this.makeRequest(this.authUrl, params);
72
73
  const data = new URLSearchParams(responseText);
73
74
  const key = data.get("oauth_token");
74
75
  const secret = data.get("oauth_token_secret");
@@ -84,8 +85,13 @@ var Instapaper = class {
84
85
  this.token = await this.getAccessToken();
85
86
  }
86
87
  const url = this.baseUrl + endpoint;
87
- return this.makeRequest(url, "POST", params, this.token);
88
+ return this.makeRequest(url, params, this.token);
89
+ };
90
+ setCredentials = (username, password) => {
91
+ this.username = username;
92
+ this.password = password;
88
93
  };
94
+ verifyCredentials = () => this.request("/1/account/verify_credentials");
89
95
  bookmarks = {
90
96
  list: (params = {}) => this.request(
91
97
  "/1/bookmarks/list",
package/package.json CHANGED
@@ -1,37 +1,37 @@
1
1
  {
2
- "name": "instapaper-ts",
3
- "version": "1.0.0",
4
- "type": "module",
5
- "description": "A type-safe API client for Instapaper.",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "files": [
9
- "/dist"
10
- ],
11
- "scripts": {
12
- "build": "tsup",
13
- "dev": "tsup --watch"
14
- },
15
- "keywords": [
16
- "instapaper",
17
- "read",
18
- "later",
19
- "typescript",
20
- "library"
21
- ],
22
- "author": "Ben Silverman (bensilverman.co.uk)",
23
- "homepage": "https://github.com/benslv/instapaper-ts",
24
- "bugs": {
25
- "url": "https://github.com/benslv/instapaper-ts/issues"
26
- },
27
- "license": "MIT",
28
- "packageManager": "pnpm@10.4.1",
29
- "dependencies": {
30
- "oauth-1.0a": "^2.2.6"
31
- },
32
- "devDependencies": {
33
- "@types/node": "^22.13.5",
34
- "tsup": "^8.4.0",
35
- "typescript": "^5.8.2"
36
- }
2
+ "name": "instapaper-ts",
3
+ "version": "1.1.2",
4
+ "type": "module",
5
+ "description": "A type-safe API client for Instapaper.",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "/dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsup",
13
+ "dev": "tsup --watch"
14
+ },
15
+ "keywords": [
16
+ "instapaper",
17
+ "read",
18
+ "later",
19
+ "typescript",
20
+ "library"
21
+ ],
22
+ "author": "Ben Silverman (bensilverman.co.uk)",
23
+ "homepage": "https://github.com/benslv/instapaper-ts",
24
+ "bugs": {
25
+ "url": "https://github.com/benslv/instapaper-ts/issues"
26
+ },
27
+ "license": "MIT",
28
+ "packageManager": "pnpm@10.4.1",
29
+ "dependencies": {
30
+ "oauth-1.0a": "^2.2.6"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^22.13.5",
34
+ "tsup": "^8.4.0",
35
+ "typescript": "^5.8.2"
36
+ }
37
37
  }