e621 3.4.1 → 3.5.1
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 +56 -0
- package/dist/browser/e621.js +1191 -252
- package/dist/browser/e621.js.map +4 -4
- package/dist/lib/OAuthClient.d.ts +152 -0
- package/dist/lib/OAuthClient.js +223 -0
- package/dist/lib/client.d.ts +75 -1
- package/dist/lib/client.js +61 -29
- package/dist/lib/errors.d.ts +26 -0
- package/dist/lib/errors.js +50 -2
- package/dist/lib/generated/schemas.d.ts +169 -8
- package/dist/lib/generated/schemas.js +215 -13
- package/dist/lib/generated/sdk.d.ts +77 -7
- package/dist/lib/generated/sdk.js +134 -9
- package/dist/lib/generated/types.d.ts +880 -245
- package/dist/lib/index.d.ts +3 -1
- package/dist/lib/index.js +2 -1
- package/dist/lib/models/Artist.d.ts +1 -0
- package/dist/lib/models/Artist.js +2 -1
- package/dist/lib/models/SavedSearch.d.ts +37 -0
- package/dist/lib/models/SavedSearch.js +55 -0
- package/dist/lib/models/TagSubscription.d.ts +25 -0
- package/dist/lib/models/TagSubscription.js +36 -0
- package/dist/lib/models/Takedown.d.ts +13 -2
- package/dist/lib/models/Takedown.js +21 -2
- package/dist/lib/models/User.d.ts +1 -1
- package/dist/lib/models/UserNameChangeRequest.d.ts +1 -1
- package/dist/lib/models/index.d.ts +2 -0
- package/dist/lib/models/index.js +3 -1
- package/dist/lib/models/posts/Actions.d.ts +6 -6
- package/dist/lib/modules/Artists.d.ts +2 -0
- package/dist/lib/modules/Artists.js +3 -1
- package/dist/lib/modules/Base.js +4 -2
- package/dist/lib/modules/DText.d.ts +2 -3
- package/dist/lib/modules/DText.js +5 -6
- package/dist/lib/modules/PostVersions.d.ts +2 -1
- package/dist/lib/modules/PostVersions.js +3 -2
- package/dist/lib/modules/Posts.d.ts +6 -6
- package/dist/lib/modules/Posts.js +8 -14
- package/dist/lib/modules/SavedSearches.d.ts +94 -0
- package/dist/lib/modules/SavedSearches.js +162 -0
- package/dist/lib/modules/SearchTrendBlacklists.js +1 -1
- package/dist/lib/modules/StaffUsers.d.ts +1 -1
- package/dist/lib/modules/StaffUsers.js +4 -2
- package/dist/lib/modules/TagAliases.d.ts +1 -1
- package/dist/lib/modules/TagAliases.js +3 -2
- package/dist/lib/modules/TagImplications.d.ts +1 -1
- package/dist/lib/modules/TagImplications.js +3 -2
- package/dist/lib/modules/TagSubscriptions.d.ts +49 -0
- package/dist/lib/modules/TagSubscriptions.js +82 -0
- package/dist/lib/modules/Takedowns.d.ts +16 -2
- package/dist/lib/modules/Takedowns.js +25 -3
- package/dist/lib/modules/Uploads.d.ts +29 -2
- package/dist/lib/modules/Uploads.js +47 -11
- package/dist/lib/modules/UserNameChangeRequests.d.ts +2 -2
- package/dist/lib/modules/UserNameChangeRequests.js +5 -3
- package/dist/lib/modules/index.d.ts +6 -0
- package/dist/lib/modules/index.js +5 -1
- package/dist/lib/standalone.d.ts +1 -1
- package/dist/lib/version.d.ts +1 -1
- package/dist/lib/version.js +1 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -37,6 +37,39 @@ const e621 = new E621({
|
|
|
37
37
|
// e.g. use e621.posts.METHOD(), e621.users.METHOD()
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
### Bearer Tokens & OAuth
|
|
41
|
+
|
|
42
|
+
Instead of `authUser`/`authKey`, you can authenticate with a bearer token (e.g. an OAuth access token). It can be a string, or a function that returns one, which is called for every request. If both are given, the bearer token wins.
|
|
43
|
+
```typescript
|
|
44
|
+
const e621 = new E621({ authToken: "..." });
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`OAuthClient` handles the OAuth 2.0 authorization code flow (with PKCE) for you, and keeps the access token refreshed. **OAuth has not been publicly released on e621 yet.**
|
|
48
|
+
```typescript
|
|
49
|
+
import E621, { OAuthClient } from "e621"; // or from "e621/oauth"
|
|
50
|
+
|
|
51
|
+
const oauth = new OAuthClient({
|
|
52
|
+
clientId: "",
|
|
53
|
+
clientSecret: "", // leave out for public clients
|
|
54
|
+
redirectURI: "https://example.com/callback",
|
|
55
|
+
scopes: ["openid", "full"],
|
|
56
|
+
token: savedToken, // optional, restore a previous token
|
|
57
|
+
onToken: (token) => saveToken(token), // called when the token is exchanged, refreshed, or revoked
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// keep state & codeVerifier (e.g. in the session), and send the user to url
|
|
61
|
+
const { url, state, codeVerifier } = await oauth.createAuthorizationURL();
|
|
62
|
+
|
|
63
|
+
// once they're redirected back, this checks the state and exchanges the code
|
|
64
|
+
await oauth.handleCallback(callbackURL, { state, codeVerifier });
|
|
65
|
+
|
|
66
|
+
// getAccessToken refreshes the token when it's about to expire
|
|
67
|
+
const e621 = new E621({ authToken: oauth.getAccessToken });
|
|
68
|
+
|
|
69
|
+
await oauth.userInfo();
|
|
70
|
+
await oauth.revoke();
|
|
71
|
+
```
|
|
72
|
+
|
|
40
73
|
### Default Post Format
|
|
41
74
|
|
|
42
75
|
Post-returning methods (`posts.get()`, `posts.search()`, `favorites.search()`, `popular.get()`, `iqdbQueries.get()`/`.post()`, and convenience methods on returned post models like `post.update()`) accept per-call `v2`/`mode` options and default to the legacy format when omitted. Set `defaultPostFormat` once to change that default everywhere instead of repeating the same options on every call:
|
|
@@ -52,6 +85,29 @@ await post?.update({ tags: "foo" }); // also resolves to ExtendedPost
|
|
|
52
85
|
const legacy = await e621.posts.get(123, { v2: false });
|
|
53
86
|
```
|
|
54
87
|
|
|
88
|
+
### Ratelimit Handling
|
|
89
|
+
|
|
90
|
+
Every request that comes back `429 Too Many Requests` is retried automatically, waiting for the duration in the response's `Retry-After` header (or an exponential backoff starting at `ratelimit.retryDelay` seconds if that header is missing). If it's still ratelimited after `ratelimit.maxRetries` attempts, or `ratelimit.retry` is turned off, a `RatelimitError` (see `retryAfter`) is thrown instead:
|
|
91
|
+
```typescript
|
|
92
|
+
import { RatelimitError } from "e621";
|
|
93
|
+
|
|
94
|
+
const e621 = new E621({
|
|
95
|
+
ratelimit: {
|
|
96
|
+
maxRetries: 5, // default: 3
|
|
97
|
+
retryDelay: 2, // default: 1 (seconds, doubled per attempt as a fallback)
|
|
98
|
+
maxRetryDelay: 30, // default: 60 (seconds, caps both the header and the fallback)
|
|
99
|
+
onRatelimit: (info) => console.warn(`ratelimited, retrying in ${info.retryAfter}s`),
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
await e621.posts.get(123);
|
|
105
|
+
} catch (err) {
|
|
106
|
+
if (err instanceof RatelimitError) console.error(`still ratelimited, retry after ${err.retryAfter}s`);
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
Set `ratelimit: { retry: false }` to disable automatic retries and just throw `RatelimitError` on the first `429`.
|
|
110
|
+
|
|
55
111
|
## Browser Usage
|
|
56
112
|
|
|
57
113
|
A pre-bundled, browser-only build (no Node built-ins) is published at `e621/browser`, for use with a plain `<script type="module">` or a CDN like jsDelivr/unpkg:
|