lemmy-js-client 1.0.0-api-updates-7.0 → 1.0.0-beta.0

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.
Files changed (71) hide show
  1. package/README.md +30 -4
  2. package/dist/http.d.ts +201 -165
  3. package/dist/http.js +328 -252
  4. package/dist/index.d.ts +15 -6
  5. package/dist/index.js +1 -0
  6. package/dist/other_types.d.ts +6 -3
  7. package/dist/request_state.d.ts +27 -0
  8. package/dist/request_state.js +15 -0
  9. package/dist/types/AllLemmyErrors.js +0 -3
  10. package/dist/types/{PasswordChangeAfterReset.d.ts → ChangePasswordAfterReset.d.ts} +1 -1
  11. package/dist/types/Community.d.ts +2 -1
  12. package/dist/types/CreateCommentReport.d.ts +4 -0
  13. package/dist/types/CreateCommentWarning.d.ts +8 -0
  14. package/dist/types/CreateMultiCommunity.d.ts +1 -0
  15. package/dist/types/CreatePostReport.d.ts +4 -0
  16. package/dist/types/CreatePostWarning.d.ts +8 -0
  17. package/dist/types/CreateSite.d.ts +17 -6
  18. package/dist/types/EditMultiCommunity.d.ts +1 -0
  19. package/dist/types/EditSite.d.ts +30 -13
  20. package/dist/types/GetComments.d.ts +4 -0
  21. package/dist/types/GetModlog.d.ts +9 -0
  22. package/dist/types/GetPosts.d.ts +6 -0
  23. package/dist/types/GetSiteResponse.d.ts +1 -1
  24. package/dist/types/ImageMode.d.ts +4 -0
  25. package/dist/types/LemmyErrorType.d.ts +0 -6
  26. package/dist/types/ListCommunities.d.ts +4 -0
  27. package/dist/types/ListMultiCommunities.d.ts +2 -0
  28. package/dist/types/ListNotifications.d.ts +2 -0
  29. package/dist/types/ListPersonContent.d.ts +3 -0
  30. package/dist/types/ListPersons.d.ts +11 -0
  31. package/dist/types/LocalSite.d.ts +32 -12
  32. package/dist/types/LocalUser.d.ts +2 -2
  33. package/dist/types/Modlog.d.ts +1 -0
  34. package/dist/types/ModlogKind.d.ts +1 -1
  35. package/dist/types/MultiCommunity.d.ts +8 -0
  36. package/dist/types/NodeInfo.d.ts +20 -0
  37. package/dist/types/NodeInfoServices.d.ts +4 -0
  38. package/dist/types/NodeInfoServices.js +3 -0
  39. package/dist/types/NodeInfoSoftware.d.ts +6 -0
  40. package/dist/types/NodeInfoSoftware.js +3 -0
  41. package/dist/types/NodeInfoUsage.d.ts +6 -0
  42. package/dist/types/NodeInfoUsage.js +2 -0
  43. package/dist/types/NodeInfoUsers.d.ts +5 -0
  44. package/dist/types/NodeInfoUsers.js +3 -0
  45. package/dist/types/Notification.d.ts +1 -0
  46. package/dist/types/Person.d.ts +1 -0
  47. package/dist/types/PersonListingType.d.ts +4 -0
  48. package/dist/types/PersonListingType.js +3 -0
  49. package/dist/types/PersonSortType.d.ts +4 -0
  50. package/dist/types/PersonSortType.js +3 -0
  51. package/dist/types/PrivateMessage.d.ts +1 -0
  52. package/dist/types/RemoveComment.d.ts +5 -0
  53. package/dist/types/RemovePost.d.ts +5 -0
  54. package/dist/types/{PasswordReset.d.ts → ResetPassword.d.ts} +1 -1
  55. package/dist/types/ResetPassword.js +2 -0
  56. package/dist/types/{SearchCombinedView.d.ts → ResolveObjectView.d.ts} +3 -3
  57. package/dist/types/ResolveObjectView.js +2 -0
  58. package/dist/types/SaveUserSettings.d.ts +2 -2
  59. package/dist/types/Search.d.ts +3 -7
  60. package/dist/types/SearchResponse.d.ts +14 -13
  61. package/dist/types/Site.d.ts +0 -1
  62. package/package.json +6 -6
  63. package/dist/types/InstanceWithFederationState.d.ts +0 -24
  64. package/dist/types/ReadableFederationState.d.ts +0 -22
  65. package/dist/types/SearchSortType.d.ts +0 -4
  66. /package/dist/types/{InstanceWithFederationState.js → ChangePasswordAfterReset.js} +0 -0
  67. /package/dist/types/{PasswordChangeAfterReset.js → CreateCommentWarning.js} +0 -0
  68. /package/dist/types/{PasswordReset.js → CreatePostWarning.js} +0 -0
  69. /package/dist/types/{SearchSortType.js → ImageMode.js} +0 -0
  70. /package/dist/types/{ReadableFederationState.js → ListPersons.js} +0 -0
  71. /package/dist/types/{SearchCombinedView.js → NodeInfo.js} +0 -0
package/README.md CHANGED
@@ -26,7 +26,8 @@ import { LemmyHttp, Login } from "lemmy-js-client";
26
26
 
27
27
  // Build the client
28
28
  const baseUrl = "https://lemmy.ml";
29
- const client: LemmyHttp = new LemmyHttp(baseUrl);
29
+ const headers = {["x-real-ip": ...]};
30
+ const client: LemmyHttp = new LemmyHttp(baseUrl, { headers });
30
31
 
31
32
  // Build the login form
32
33
  const loginForm: Login = {
@@ -35,15 +36,40 @@ const loginForm: Login = {
35
36
  };
36
37
 
37
38
  // Login and set the client headers with your jwt
38
- const { jwt } = await client.login(loginForm);
39
- client.setHeaders({ Authorization: `Bearer ${jwt}` });
39
+ const loginRes = await client.login(loginForm);
40
+
41
+ // Make sure its successful
42
+ if (loginRes.state === "success") {
43
+ const jwt = login.data.jwt;
44
+ client.setHeaders({ Authorization: `Bearer ${jwt}` });
45
+ } else if (loginRes.state === "failed") {
46
+ const err = login.err;
47
+ }
40
48
 
41
49
  // Fetch top posts for the day
42
50
  const getPostsForm: GetPosts = {
43
51
  sort: "TopDay",
44
52
  type_: "Local",
45
53
  };
46
- const posts = await client.getPosts(getPostsForm);
54
+ const postsRes = await client.getPosts(getPostsForm);
55
+
56
+ // Handle the different request states
57
+ switch (postsRes.state) {
58
+ case "empty": {
59
+ break;
60
+ }
61
+ case "loading": {
62
+ break;
63
+ }
64
+ case "failed": {
65
+ const err = postsRes.err;
66
+ break;
67
+ }
68
+ case "success": {
69
+ const data = postsRes.data;
70
+ break;
71
+ }
72
+ }
47
73
  ```
48
74
 
49
75
  ## Development