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