instapaper-ts 1.1.1 → 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/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,6 +1,6 @@
1
1
  {
2
2
  "name": "instapaper-ts",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
5
  "description": "A type-safe API client for Instapaper.",
6
6
  "main": "dist/index.js",