lemmy-js-client 0.19.4-alpha.9 → 0.19.4

Sign up to get free protection for your applications and to get access to all the features.
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 'lemmy-js-client';
25
+ import { LemmyHttp, Login } from "lemmy-js-client";
26
26
 
27
- let baseUrl = 'https://lemmy.ml';
28
- let client: LemmyHttp = new LemmyHttp(baseUrl, headers?);
29
- let loginForm: Login = {
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
- You can use [yalc](https://github.com/wclr/yalc) to develop and test changes locally:
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
- # Go to lemmy-js-client dir
44
- yalc publish --push
49
+ ## Development
45
50
 
46
- # Go to your client dir
47
- yalc add lemmy-js-client
51
+ Use `pnpm add` to develop and test changes locally:
48
52
 
49
- # To do updates, go back to the lemmy-js-client dir
50
- # This also updates it, in every dir you've added it.
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,15 +210,15 @@ export declare class LemmyHttp {
211
210
  /**
212
211
  * List all the media for your user
213
212
  *
214
- * `HTTP.GET /user/list_media`
213
+ * `HTTP.GET /account/list_media`
215
214
  */
216
- listMedia(form: ListMedia): Promise<ListMediaResponse>;
215
+ listMedia(form?: ListMedia): Promise<ListMediaResponse>;
217
216
  /**
218
217
  * List all the media known to your instance.
219
218
  *
220
219
  * `HTTP.GET /admin/list_all_media`
221
220
  */
222
- listAllMedia(form: ListMedia): Promise<ListMediaResponse>;
221
+ listAllMedia(form?: ListMedia): Promise<ListMediaResponse>;
223
222
  /**
224
223
  * Enable / Disable TOTP / two-factor authentication.
225
224
  *
@@ -566,6 +565,11 @@ export declare class LemmyHttp {
566
565
  * `HTTP.POST /user/login`
567
566
  */
568
567
  login(form: Login): Promise<LoginResponse>;
568
+ /**
569
+ * Invalidate the currently used auth token.
570
+ *
571
+ * `HTTP.POST /user/logout`
572
+ */
569
573
  logout(): Promise<SuccessResponse>;
570
574
  /**
571
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, cross_fetch_1.default);
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,17 +131,17 @@ class LemmyHttp {
136
131
  /**
137
132
  * List all the media for your user
138
133
  *
139
- * `HTTP.GET /user/list_media`
134
+ * `HTTP.GET /account/list_media`
140
135
  */
141
- listMedia(form) {
142
- return __classPrivateFieldGet(this, _LemmyHttp_instances, "m", _LemmyHttp_wrapper).call(this, HttpType.Get, "/user/list_media", form);
136
+ listMedia(form = {}) {
137
+ return __classPrivateFieldGet(this, _LemmyHttp_instances, "m", _LemmyHttp_wrapper).call(this, HttpType.Get, "/account/list_media", form);
143
138
  }
144
139
  /**
145
140
  * List all the media known to your instance.
146
141
  *
147
142
  * `HTTP.GET /admin/list_all_media`
148
143
  */
149
- listAllMedia(form) {
144
+ listAllMedia(form = {}) {
150
145
  return __classPrivateFieldGet(this, _LemmyHttp_instances, "m", _LemmyHttp_wrapper).call(this, HttpType.Get, "/admin/list_all_media", form);
151
146
  }
152
147
  /**
@@ -609,6 +604,11 @@ class LemmyHttp {
609
604
  login(form) {
610
605
  return __classPrivateFieldGet(this, _LemmyHttp_instances, "m", _LemmyHttp_wrapper).call(this, HttpType.Post, "/user/login", form);
611
606
  }
607
+ /**
608
+ * Invalidate the currently used auth token.
609
+ *
610
+ * `HTTP.POST /user/logout`
611
+ */
612
612
  logout() {
613
613
  return __classPrivateFieldGet(this, _LemmyHttp_instances, "m", _LemmyHttp_wrapper).call(this, HttpType.Post, "/user/logout", {});
614
614
  }
@@ -855,8 +855,8 @@ class LemmyHttp {
855
855
  /**
856
856
  * Upload an image to the server.
857
857
  */
858
- uploadImage({ image }) {
859
- return __awaiter(this, void 0, void 0, function* () {
858
+ uploadImage(_a) {
859
+ return __awaiter(this, arguments, void 0, function* ({ image }) {
860
860
  const formData = createFormData(image);
861
861
  let url = undefined;
862
862
  let delete_url = undefined;
@@ -881,8 +881,8 @@ class LemmyHttp {
881
881
  /**
882
882
  * Delete a pictrs image
883
883
  */
884
- deleteImage({ token, filename }) {
885
- return __awaiter(this, void 0, void 0, function* () {
884
+ deleteImage(_a) {
885
+ return __awaiter(this, arguments, void 0, function* ({ token, filename }) {
886
886
  const deleteUrl = `${__classPrivateFieldGet(this, _LemmyHttp_pictrsUrl, "f")}/delete/${token}/${filename}`;
887
887
  const response = yield __classPrivateFieldGet(this, _LemmyHttp_fetchFunction, "f").call(this, deleteUrl, {
888
888
  method: HttpType.Get,
@@ -902,8 +902,8 @@ exports.LemmyHttp = LemmyHttp;
902
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) {
903
903
  return `${__classPrivateFieldGet(this, _LemmyHttp_apiUrl, "f")}${endpoint}`;
904
904
  }, _LemmyHttp_wrapper = function _LemmyHttp_wrapper(type_, endpoint, form) {
905
- var _a;
906
905
  return __awaiter(this, void 0, void 0, function* () {
906
+ var _a;
907
907
  let response;
908
908
  if (type_ === HttpType.Get) {
909
909
  const getUrl = `${__classPrivateFieldGet(this, _LemmyHttp_instances, "m", _LemmyHttp_buildFullUrl).call(this, endpoint)}?${encodeGetParams(form)}`;
@@ -936,18 +936,18 @@ _LemmyHttp_apiUrl = new WeakMap(), _LemmyHttp_headers = new WeakMap(), _LemmyHtt
936
936
  };
937
937
  function encodeGetParams(p) {
938
938
  return Object.entries(p)
939
- .filter(kv => !!kv[1])
939
+ .filter(kv => kv[1] !== undefined && kv[1] !== null)
940
940
  .map(kv => kv.map(encodeURIComponent).join("="))
941
941
  .join("&");
942
942
  }
943
943
  function createFormData(image) {
944
- let formData = new form_data_1.default();
945
- if (image.constructor.name === "File") {
944
+ let formData = new FormData();
945
+ if (image instanceof File) {
946
946
  formData.append("images[]", image);
947
947
  }
948
948
  else {
949
949
  // The filename doesn't affect the file type or file name that ends up in pictrs
950
- formData.append("images[]", image, { filename: "image.jpg" });
950
+ formData.append("images[]", new Blob([image], { type: "image/jpeg" }), "image.jpg");
951
951
  }
952
952
  return formData;
953
953
  }
package/dist/index.d.ts CHANGED
@@ -137,9 +137,11 @@ 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
+ export { LocalSiteUrlBlocklist } from "./types/LocalSiteUrlBlocklist";
143
145
  export { LocalUser } from "./types/LocalUser";
144
146
  export { LocalUserId } from "./types/LocalUserId";
145
147
  export { LocalUserView } from "./types/LocalUserView";
@@ -14,6 +14,7 @@ export interface CommentReplyView {
14
14
  recipient: Person;
15
15
  counts: CommentAggregates;
16
16
  creator_banned_from_community: boolean;
17
+ banned_from_community: boolean;
17
18
  creator_is_moderator: boolean;
18
19
  creator_is_admin: boolean;
19
20
  subscribed: SubscribedType;
@@ -11,6 +11,7 @@ export interface CommentView {
11
11
  community: Community;
12
12
  counts: CommentAggregates;
13
13
  creator_banned_from_community: boolean;
14
+ banned_from_community: boolean;
14
15
  creator_is_moderator: boolean;
15
16
  creator_is_admin: boolean;
16
17
  subscribed: SubscribedType;
@@ -42,6 +42,7 @@ export interface EditSite {
42
42
  captcha_difficulty?: string;
43
43
  allowed_instances?: Array<string>;
44
44
  blocked_instances?: Array<string>;
45
+ blocked_urls?: Array<string>;
45
46
  taglines?: Array<string>;
46
47
  registration_mode?: RegistrationMode;
47
48
  reports_email_admins?: boolean;
@@ -1,6 +1,7 @@
1
1
  import type { CustomEmojiView } from "./CustomEmojiView";
2
2
  import type { Language } from "./Language";
3
3
  import type { LanguageId } from "./LanguageId";
4
+ import type { LocalSiteUrlBlocklist } from "./LocalSiteUrlBlocklist";
4
5
  import type { MyUserInfo } from "./MyUserInfo";
5
6
  import type { PersonView } from "./PersonView";
6
7
  import type { SiteView } from "./SiteView";
@@ -14,4 +15,5 @@ export interface GetSiteResponse {
14
15
  discussion_languages: Array<LanguageId>;
15
16
  taglines: Array<Tagline>;
16
17
  custom_emojis: Array<CustomEmojiView>;
18
+ blocked_urls: Array<LocalSiteUrlBlocklist>;
17
19
  }
@@ -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
  } | {
@@ -249,6 +267,8 @@ export type LemmyErrorType = {
249
267
  error: "couldnt_set_all_email_verified";
250
268
  } | {
251
269
  error: "banned";
270
+ } | {
271
+ error: "blocked_url";
252
272
  } | {
253
273
  error: "couldnt_get_comments";
254
274
  } | {
@@ -284,8 +304,6 @@ export type LemmyErrorType = {
284
304
  error: "invalid_regex";
285
305
  } | {
286
306
  error: "captcha_incorrect";
287
- } | {
288
- error: "password_reset_limit_reached";
289
307
  } | {
290
308
  error: "couldnt_create_audio_captcha";
291
309
  } | {
@@ -308,6 +326,10 @@ export type LemmyErrorType = {
308
326
  error: "invalid_bot_action";
309
327
  } | {
310
328
  error: "cant_block_local_instance";
329
+ } | {
330
+ error: "url_without_domain";
331
+ } | {
332
+ error: "inbox_timeout";
311
333
  } | {
312
334
  error: "unknown";
313
335
  message: string;
@@ -1,4 +1,4 @@
1
- import type { LocalImage } from "./LocalImage";
1
+ import type { LocalImageView } from "./LocalImageView";
2
2
  export interface ListMediaResponse {
3
- images: Array<LocalImage>;
3
+ images: Array<LocalImageView>;
4
4
  }
@@ -0,0 +1,6 @@
1
+ import type { LocalImage } from "./LocalImage";
2
+ import type { Person } from "./Person";
3
+ export interface LocalImageView {
4
+ local_image: LocalImage;
5
+ person: Person;
6
+ }
@@ -0,0 +1,6 @@
1
+ export interface LocalSiteUrlBlocklist {
2
+ id: number;
3
+ url: string;
4
+ published: string;
5
+ updated?: string;
6
+ }
@@ -14,6 +14,7 @@ export interface PersonMentionView {
14
14
  recipient: Person;
15
15
  counts: CommentAggregates;
16
16
  creator_banned_from_community: boolean;
17
+ banned_from_community: boolean;
17
18
  creator_is_moderator: boolean;
18
19
  creator_is_admin: boolean;
19
20
  subscribed: SubscribedType;
@@ -8,6 +8,7 @@ export interface PostView {
8
8
  creator: Person;
9
9
  community: Community;
10
10
  creator_banned_from_community: boolean;
11
+ banned_from_community: boolean;
11
12
  creator_is_moderator: boolean;
12
13
  creator_is_admin: boolean;
13
14
  counts: PostAggregates;
@@ -2,7 +2,7 @@ export interface Register {
2
2
  username: string;
3
3
  password: string;
4
4
  password_verify: string;
5
- show_nsfw: boolean;
5
+ show_nsfw?: boolean;
6
6
  email?: string;
7
7
  captcha_uuid?: string;
8
8
  captcha_answer?: string;
@@ -12,6 +12,7 @@ export interface Site {
12
12
  actor_id: string;
13
13
  last_refreshed_at: string;
14
14
  inbox_url: string;
15
+ public_key: string;
15
16
  instance_id: InstanceId;
16
17
  content_warning?: string;
17
18
  }
@@ -1,5 +1,6 @@
1
1
  import type { Person } from "./Person";
2
2
  export interface VoteView {
3
3
  creator: Person;
4
+ creator_banned_from_community: boolean;
4
5
  score: number;
5
6
  }
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-alpha.9",
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 --ext .js,.ts,.tsx src && prettier --check src",
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": "^8.56.0",
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}": [
@@ -1,7 +0,0 @@
1
- import type { LocalUserId } from "./LocalUserId";
2
- export interface ImageUpload {
3
- local_user_id: LocalUserId;
4
- pictrs_alias: string;
5
- pictrs_delete_token: string;
6
- published: string;
7
- }
@@ -1,6 +0,0 @@
1
- export interface SiteMetadata {
2
- title?: string;
3
- description?: string;
4
- image?: string;
5
- embed_video_url?: string;
6
- }