lemmy-js-client 0.19.4-alpha.8 → 0.19.4
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 +20 -17
- package/dist/http.d.ts +13 -3
- package/dist/http.js +26 -18
- package/dist/index.d.ts +2 -0
- package/dist/types/CommentReplyView.d.ts +1 -0
- package/dist/types/CommentReportView.d.ts +6 -0
- package/dist/types/CommentView.d.ts +1 -0
- package/dist/types/LemmyErrorType.d.ts +26 -6
- package/dist/types/ListMediaResponse.d.ts +2 -2
- package/dist/types/LocalImage.d.ts +1 -1
- package/dist/types/LocalImageView.d.ts +6 -0
- package/dist/types/LocalImageView.js +2 -0
- package/dist/types/LocalUserView.d.ts +2 -0
- package/dist/types/LocalUserVoteDisplayMode.d.ts +8 -0
- package/dist/types/LocalUserVoteDisplayMode.js +2 -0
- package/dist/types/PersonMentionView.d.ts +1 -0
- package/dist/types/PostReportView.d.ts +9 -0
- package/dist/types/PostView.d.ts +1 -0
- package/dist/types/Register.d.ts +1 -1
- package/dist/types/SaveUserSettings.d.ts +4 -1
- package/dist/types/Site.d.ts +0 -1
- package/dist/types/VoteView.d.ts +1 -0
- package/package.json +6 -8
package/README.md
CHANGED
@@ -22,31 +22,34 @@ A javascript / typescript http client and type system for [Lemmy](https://github
|
|
22
22
|
[LemmyHttp docs](https://join-lemmy.org/api/classes/LemmyHttp.html)
|
23
23
|
|
24
24
|
```ts
|
25
|
-
import { LemmyHttp, Login } from
|
25
|
+
import { LemmyHttp, Login } from "lemmy-js-client";
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
// Build the client
|
28
|
+
const baseUrl = "https://lemmy.ml";
|
29
|
+
const client: LemmyHttp = new LemmyHttp(baseUrl);
|
30
|
+
|
31
|
+
// Build the login form
|
32
|
+
const loginForm: Login = {
|
30
33
|
username_or_email: "my_name",
|
31
34
|
password: "my_pass",
|
32
35
|
};
|
33
|
-
let jwt = await client.login(loginForm).jwt;
|
34
|
-
```
|
35
|
-
|
36
|
-
## Development
|
37
36
|
|
38
|
-
|
37
|
+
// Login and set the client headers with your jwt
|
38
|
+
const { jwt } = await client.login(loginForm);
|
39
|
+
client.setHeaders({ Authorization: `Bearer ${jwt}` });
|
39
40
|
|
41
|
+
// Fetch top posts for the day
|
42
|
+
const getPostsForm: GetPosts = {
|
43
|
+
sort: "TopDay",
|
44
|
+
type_: "Local",
|
45
|
+
};
|
46
|
+
const posts = await client.getPosts(getPostsForm);
|
40
47
|
```
|
41
|
-
pnpm i --global add yalc
|
42
48
|
|
43
|
-
|
44
|
-
yalc publish --push
|
49
|
+
## Development
|
45
50
|
|
46
|
-
|
47
|
-
yalc add lemmy-js-client
|
51
|
+
Use `pnpm add` to develop and test changes locally:
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
yalc publish --push
|
53
|
+
```
|
54
|
+
pnpm add path/to/lemmy-js-client
|
52
55
|
```
|
package/dist/http.d.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import fetch from "cross-fetch";
|
2
1
|
import { AddAdmin } from "./types/AddAdmin";
|
3
2
|
import { AddAdminResponse } from "./types/AddAdminResponse";
|
4
3
|
import { AddModToCommunity } from "./types/AddModToCommunity";
|
@@ -211,9 +210,15 @@ export declare class LemmyHttp {
|
|
211
210
|
/**
|
212
211
|
* List all the media for your user
|
213
212
|
*
|
214
|
-
* `HTTP.GET /
|
213
|
+
* `HTTP.GET /account/list_media`
|
215
214
|
*/
|
216
|
-
listMedia(form
|
215
|
+
listMedia(form?: ListMedia): Promise<ListMediaResponse>;
|
216
|
+
/**
|
217
|
+
* List all the media known to your instance.
|
218
|
+
*
|
219
|
+
* `HTTP.GET /admin/list_all_media`
|
220
|
+
*/
|
221
|
+
listAllMedia(form?: ListMedia): Promise<ListMediaResponse>;
|
217
222
|
/**
|
218
223
|
* Enable / Disable TOTP / two-factor authentication.
|
219
224
|
*
|
@@ -560,6 +565,11 @@ export declare class LemmyHttp {
|
|
560
565
|
* `HTTP.POST /user/login`
|
561
566
|
*/
|
562
567
|
login(form: Login): Promise<LoginResponse>;
|
568
|
+
/**
|
569
|
+
* Invalidate the currently used auth token.
|
570
|
+
*
|
571
|
+
* `HTTP.POST /user/logout`
|
572
|
+
*/
|
563
573
|
logout(): Promise<SuccessResponse>;
|
564
574
|
/**
|
565
575
|
* Get the details for a person.
|
package/dist/http.js
CHANGED
@@ -19,14 +19,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
19
19
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
20
20
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
21
21
|
};
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
24
|
-
};
|
25
22
|
var _LemmyHttp_instances, _LemmyHttp_apiUrl, _LemmyHttp_headers, _LemmyHttp_pictrsUrl, _LemmyHttp_fetchFunction, _LemmyHttp_buildFullUrl, _LemmyHttp_wrapper;
|
26
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
27
24
|
exports.LemmyHttp = void 0;
|
28
|
-
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
29
|
-
const form_data_1 = __importDefault(require("form-data"));
|
30
25
|
const other_types_1 = require("./other_types");
|
31
26
|
var HttpType;
|
32
27
|
(function (HttpType) {
|
@@ -48,7 +43,7 @@ class LemmyHttp {
|
|
48
43
|
_LemmyHttp_apiUrl.set(this, void 0);
|
49
44
|
_LemmyHttp_headers.set(this, {});
|
50
45
|
_LemmyHttp_pictrsUrl.set(this, void 0);
|
51
|
-
_LemmyHttp_fetchFunction.set(this,
|
46
|
+
_LemmyHttp_fetchFunction.set(this, fetch.bind(globalThis));
|
52
47
|
__classPrivateFieldSet(this, _LemmyHttp_apiUrl, `${baseUrl.replace(/\/+$/, "")}/api/${other_types_1.VERSION}`, "f");
|
53
48
|
__classPrivateFieldSet(this, _LemmyHttp_pictrsUrl, `${baseUrl}/pictrs/image`, "f");
|
54
49
|
if (options === null || options === void 0 ? void 0 : options.headers) {
|
@@ -136,10 +131,18 @@ class LemmyHttp {
|
|
136
131
|
/**
|
137
132
|
* List all the media for your user
|
138
133
|
*
|
139
|
-
* `HTTP.GET /
|
134
|
+
* `HTTP.GET /account/list_media`
|
135
|
+
*/
|
136
|
+
listMedia(form = {}) {
|
137
|
+
return __classPrivateFieldGet(this, _LemmyHttp_instances, "m", _LemmyHttp_wrapper).call(this, HttpType.Get, "/account/list_media", form);
|
138
|
+
}
|
139
|
+
/**
|
140
|
+
* List all the media known to your instance.
|
141
|
+
*
|
142
|
+
* `HTTP.GET /admin/list_all_media`
|
140
143
|
*/
|
141
|
-
|
142
|
-
return __classPrivateFieldGet(this, _LemmyHttp_instances, "m", _LemmyHttp_wrapper).call(this, HttpType.Get, "/
|
144
|
+
listAllMedia(form = {}) {
|
145
|
+
return __classPrivateFieldGet(this, _LemmyHttp_instances, "m", _LemmyHttp_wrapper).call(this, HttpType.Get, "/admin/list_all_media", form);
|
143
146
|
}
|
144
147
|
/**
|
145
148
|
* Enable / Disable TOTP / two-factor authentication.
|
@@ -601,6 +604,11 @@ class LemmyHttp {
|
|
601
604
|
login(form) {
|
602
605
|
return __classPrivateFieldGet(this, _LemmyHttp_instances, "m", _LemmyHttp_wrapper).call(this, HttpType.Post, "/user/login", form);
|
603
606
|
}
|
607
|
+
/**
|
608
|
+
* Invalidate the currently used auth token.
|
609
|
+
*
|
610
|
+
* `HTTP.POST /user/logout`
|
611
|
+
*/
|
604
612
|
logout() {
|
605
613
|
return __classPrivateFieldGet(this, _LemmyHttp_instances, "m", _LemmyHttp_wrapper).call(this, HttpType.Post, "/user/logout", {});
|
606
614
|
}
|
@@ -847,8 +855,8 @@ class LemmyHttp {
|
|
847
855
|
/**
|
848
856
|
* Upload an image to the server.
|
849
857
|
*/
|
850
|
-
uploadImage(
|
851
|
-
return __awaiter(this,
|
858
|
+
uploadImage(_a) {
|
859
|
+
return __awaiter(this, arguments, void 0, function* ({ image }) {
|
852
860
|
const formData = createFormData(image);
|
853
861
|
let url = undefined;
|
854
862
|
let delete_url = undefined;
|
@@ -873,8 +881,8 @@ class LemmyHttp {
|
|
873
881
|
/**
|
874
882
|
* Delete a pictrs image
|
875
883
|
*/
|
876
|
-
deleteImage(
|
877
|
-
return __awaiter(this,
|
884
|
+
deleteImage(_a) {
|
885
|
+
return __awaiter(this, arguments, void 0, function* ({ token, filename }) {
|
878
886
|
const deleteUrl = `${__classPrivateFieldGet(this, _LemmyHttp_pictrsUrl, "f")}/delete/${token}/${filename}`;
|
879
887
|
const response = yield __classPrivateFieldGet(this, _LemmyHttp_fetchFunction, "f").call(this, deleteUrl, {
|
880
888
|
method: HttpType.Get,
|
@@ -894,8 +902,8 @@ exports.LemmyHttp = LemmyHttp;
|
|
894
902
|
_LemmyHttp_apiUrl = new WeakMap(), _LemmyHttp_headers = new WeakMap(), _LemmyHttp_pictrsUrl = new WeakMap(), _LemmyHttp_fetchFunction = new WeakMap(), _LemmyHttp_instances = new WeakSet(), _LemmyHttp_buildFullUrl = function _LemmyHttp_buildFullUrl(endpoint) {
|
895
903
|
return `${__classPrivateFieldGet(this, _LemmyHttp_apiUrl, "f")}${endpoint}`;
|
896
904
|
}, _LemmyHttp_wrapper = function _LemmyHttp_wrapper(type_, endpoint, form) {
|
897
|
-
var _a;
|
898
905
|
return __awaiter(this, void 0, void 0, function* () {
|
906
|
+
var _a;
|
899
907
|
let response;
|
900
908
|
if (type_ === HttpType.Get) {
|
901
909
|
const getUrl = `${__classPrivateFieldGet(this, _LemmyHttp_instances, "m", _LemmyHttp_buildFullUrl).call(this, endpoint)}?${encodeGetParams(form)}`;
|
@@ -928,18 +936,18 @@ _LemmyHttp_apiUrl = new WeakMap(), _LemmyHttp_headers = new WeakMap(), _LemmyHtt
|
|
928
936
|
};
|
929
937
|
function encodeGetParams(p) {
|
930
938
|
return Object.entries(p)
|
931
|
-
.filter(kv =>
|
939
|
+
.filter(kv => kv[1] !== undefined && kv[1] !== null)
|
932
940
|
.map(kv => kv.map(encodeURIComponent).join("="))
|
933
941
|
.join("&");
|
934
942
|
}
|
935
943
|
function createFormData(image) {
|
936
|
-
let formData = new
|
937
|
-
if (image
|
944
|
+
let formData = new FormData();
|
945
|
+
if (image instanceof File) {
|
938
946
|
formData.append("images[]", image);
|
939
947
|
}
|
940
948
|
else {
|
941
949
|
// The filename doesn't affect the file type or file name that ends up in pictrs
|
942
|
-
formData.append("images[]", image, {
|
950
|
+
formData.append("images[]", new Blob([image], { type: "image/jpeg" }), "image.jpg");
|
943
951
|
}
|
944
952
|
return formData;
|
945
953
|
}
|
package/dist/index.d.ts
CHANGED
@@ -137,6 +137,7 @@ export { ListRegistrationApplications } from "./types/ListRegistrationApplicatio
|
|
137
137
|
export { ListRegistrationApplicationsResponse } from "./types/ListRegistrationApplicationsResponse";
|
138
138
|
export { ListingType } from "./types/ListingType";
|
139
139
|
export { LocalImage } from "./types/LocalImage";
|
140
|
+
export { LocalImageView } from "./types/LocalImageView";
|
140
141
|
export { LocalSite } from "./types/LocalSite";
|
141
142
|
export { LocalSiteId } from "./types/LocalSiteId";
|
142
143
|
export { LocalSiteRateLimit } from "./types/LocalSiteRateLimit";
|
@@ -144,6 +145,7 @@ export { LocalSiteUrlBlocklist } from "./types/LocalSiteUrlBlocklist";
|
|
144
145
|
export { LocalUser } from "./types/LocalUser";
|
145
146
|
export { LocalUserId } from "./types/LocalUserId";
|
146
147
|
export { LocalUserView } from "./types/LocalUserView";
|
148
|
+
export { LocalUserVoteDisplayMode } from "./types/LocalUserVoteDisplayMode";
|
147
149
|
export { LockPost } from "./types/LockPost";
|
148
150
|
export { Login } from "./types/Login";
|
149
151
|
export { LoginResponse } from "./types/LoginResponse";
|
@@ -4,6 +4,7 @@ import type { CommentReport } from "./CommentReport";
|
|
4
4
|
import type { Community } from "./Community";
|
5
5
|
import type { Person } from "./Person";
|
6
6
|
import type { Post } from "./Post";
|
7
|
+
import type { SubscribedType } from "./SubscribedType";
|
7
8
|
export interface CommentReportView {
|
8
9
|
comment_report: CommentReport;
|
9
10
|
comment: Comment;
|
@@ -13,6 +14,11 @@ export interface CommentReportView {
|
|
13
14
|
comment_creator: Person;
|
14
15
|
counts: CommentAggregates;
|
15
16
|
creator_banned_from_community: boolean;
|
17
|
+
creator_is_moderator: boolean;
|
18
|
+
creator_is_admin: boolean;
|
19
|
+
creator_blocked: boolean;
|
20
|
+
subscribed: SubscribedType;
|
21
|
+
saved: boolean;
|
16
22
|
my_vote?: number;
|
17
23
|
resolver?: Person;
|
18
24
|
}
|
@@ -66,6 +66,26 @@ export type LemmyErrorType = {
|
|
66
66
|
error: "couldnt_find_community";
|
67
67
|
} | {
|
68
68
|
error: "couldnt_find_person";
|
69
|
+
} | {
|
70
|
+
error: "couldnt_find_comment";
|
71
|
+
} | {
|
72
|
+
error: "couldnt_find_comment_report";
|
73
|
+
} | {
|
74
|
+
error: "couldnt_find_post_report";
|
75
|
+
} | {
|
76
|
+
error: "couldnt_find_private_message_report";
|
77
|
+
} | {
|
78
|
+
error: "couldnt_find_local_user";
|
79
|
+
} | {
|
80
|
+
error: "couldnt_find_person_mention";
|
81
|
+
} | {
|
82
|
+
error: "couldnt_find_registration_application";
|
83
|
+
} | {
|
84
|
+
error: "couldnt_find_comment_reply";
|
85
|
+
} | {
|
86
|
+
error: "couldnt_find_private_message";
|
87
|
+
} | {
|
88
|
+
error: "couldnt_find_activity";
|
69
89
|
} | {
|
70
90
|
error: "person_is_blocked";
|
71
91
|
} | {
|
@@ -157,12 +177,10 @@ export type LemmyErrorType = {
|
|
157
177
|
error: "invalid_vote_value";
|
158
178
|
} | {
|
159
179
|
error: "page_does_not_specify_creator";
|
160
|
-
} | {
|
161
|
-
error: "page_does_not_specify_group";
|
162
|
-
} | {
|
163
|
-
error: "no_community_found_in_cc";
|
164
180
|
} | {
|
165
181
|
error: "no_email_setup";
|
182
|
+
} | {
|
183
|
+
error: "local_site_not_setup";
|
166
184
|
} | {
|
167
185
|
error: "email_smtp_server_needs_a_port";
|
168
186
|
} | {
|
@@ -286,8 +304,6 @@ export type LemmyErrorType = {
|
|
286
304
|
error: "invalid_regex";
|
287
305
|
} | {
|
288
306
|
error: "captcha_incorrect";
|
289
|
-
} | {
|
290
|
-
error: "password_reset_limit_reached";
|
291
307
|
} | {
|
292
308
|
error: "couldnt_create_audio_captcha";
|
293
309
|
} | {
|
@@ -310,6 +326,10 @@ export type LemmyErrorType = {
|
|
310
326
|
error: "invalid_bot_action";
|
311
327
|
} | {
|
312
328
|
error: "cant_block_local_instance";
|
329
|
+
} | {
|
330
|
+
error: "url_without_domain";
|
331
|
+
} | {
|
332
|
+
error: "inbox_timeout";
|
313
333
|
} | {
|
314
334
|
error: "unknown";
|
315
335
|
message: string;
|
@@ -1,8 +1,10 @@
|
|
1
1
|
import type { LocalUser } from "./LocalUser";
|
2
|
+
import type { LocalUserVoteDisplayMode } from "./LocalUserVoteDisplayMode";
|
2
3
|
import type { Person } from "./Person";
|
3
4
|
import type { PersonAggregates } from "./PersonAggregates";
|
4
5
|
export interface LocalUserView {
|
5
6
|
local_user: LocalUser;
|
7
|
+
local_user_vote_display_mode: LocalUserVoteDisplayMode;
|
6
8
|
person: Person;
|
7
9
|
counts: PersonAggregates;
|
8
10
|
}
|
@@ -3,6 +3,7 @@ import type { Person } from "./Person";
|
|
3
3
|
import type { Post } from "./Post";
|
4
4
|
import type { PostAggregates } from "./PostAggregates";
|
5
5
|
import type { PostReport } from "./PostReport";
|
6
|
+
import type { SubscribedType } from "./SubscribedType";
|
6
7
|
export interface PostReportView {
|
7
8
|
post_report: PostReport;
|
8
9
|
post: Post;
|
@@ -10,7 +11,15 @@ export interface PostReportView {
|
|
10
11
|
creator: Person;
|
11
12
|
post_creator: Person;
|
12
13
|
creator_banned_from_community: boolean;
|
14
|
+
creator_is_moderator: boolean;
|
15
|
+
creator_is_admin: boolean;
|
16
|
+
subscribed: SubscribedType;
|
17
|
+
saved: boolean;
|
18
|
+
read: boolean;
|
19
|
+
hidden: boolean;
|
20
|
+
creator_blocked: boolean;
|
13
21
|
my_vote?: number;
|
22
|
+
unread_comments: number;
|
14
23
|
counts: PostAggregates;
|
15
24
|
resolver?: Person;
|
16
25
|
}
|
package/dist/types/PostView.d.ts
CHANGED
package/dist/types/Register.d.ts
CHANGED
@@ -6,7 +6,6 @@ export interface SaveUserSettings {
|
|
6
6
|
show_nsfw?: boolean;
|
7
7
|
blur_nsfw?: boolean;
|
8
8
|
auto_expand?: boolean;
|
9
|
-
show_scores?: boolean;
|
10
9
|
theme?: string;
|
11
10
|
default_sort_type?: SortType;
|
12
11
|
default_listing_type?: ListingType;
|
@@ -29,4 +28,8 @@ export interface SaveUserSettings {
|
|
29
28
|
enable_keyboard_navigation?: boolean;
|
30
29
|
enable_animated_images?: boolean;
|
31
30
|
collapse_bot_comments?: boolean;
|
31
|
+
show_scores?: boolean;
|
32
|
+
show_upvotes?: boolean;
|
33
|
+
show_downvotes?: boolean;
|
34
|
+
show_upvote_percentage?: boolean;
|
32
35
|
}
|
package/dist/types/Site.d.ts
CHANGED
package/dist/types/VoteView.d.ts
CHANGED
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "lemmy-js-client",
|
3
3
|
"description": "A javascript / typescript client for Lemmy",
|
4
|
-
"version": "0.19.4
|
4
|
+
"version": "0.19.4",
|
5
5
|
"author": "Dessalines <tyhou13@gmx.com>",
|
6
6
|
"license": "AGPL-3.0",
|
7
7
|
"main": "./dist/index.js",
|
@@ -11,22 +11,18 @@
|
|
11
11
|
"scripts": {
|
12
12
|
"build": "tsc",
|
13
13
|
"docs": "typedoc src/index.ts",
|
14
|
-
"lint": "tsc --noEmit && eslint --report-unused-disable-directives
|
14
|
+
"lint": "tsc --noEmit && eslint --report-unused-disable-directives && prettier --check src",
|
15
15
|
"prepare": "pnpm run build && husky"
|
16
16
|
},
|
17
17
|
"repository": {
|
18
18
|
"type": "git",
|
19
19
|
"url": "git+https://github.com/LemmyNet/lemmy-js-client.git"
|
20
20
|
},
|
21
|
-
"dependencies": {
|
22
|
-
"cross-fetch": "^4.0.0",
|
23
|
-
"form-data": "^4.0.0"
|
24
|
-
},
|
25
21
|
"devDependencies": {
|
26
22
|
"@types/node": "^20.11.19",
|
27
23
|
"@typescript-eslint/eslint-plugin": "^7.0.1",
|
28
24
|
"@typescript-eslint/parser": "^7.0.1",
|
29
|
-
"eslint": "^
|
25
|
+
"eslint": "^9.0.0",
|
30
26
|
"eslint-plugin-prettier": "^5.1.3",
|
31
27
|
"husky": "^9.0.11",
|
32
28
|
"lint-staged": "^15.2.2",
|
@@ -36,8 +32,10 @@
|
|
36
32
|
"prettier-plugin-packagejson": "^2.4.11",
|
37
33
|
"sortpack": "^2.4.0",
|
38
34
|
"typedoc": "^0.25.8",
|
39
|
-
"typescript": "^5.3.3"
|
35
|
+
"typescript": "^5.3.3",
|
36
|
+
"typescript-eslint": "^7.9.0"
|
40
37
|
},
|
38
|
+
"packageManager": "pnpm@9.1.4",
|
41
39
|
"types": "./dist/index.d.ts",
|
42
40
|
"lint-staged": {
|
43
41
|
"*.{ts,tsx,js}": [
|