Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding private instance related endpoints. #38

Merged
merged 9 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lemmy-js-client",
"description": "A javascript / typescript client for Lemmy",
"version": "0.14.0-rc.1",
"version": "0.15.0-rc.6",
"author": "Dessalines <[email protected]>",
"license": "AGPL-3.0",
"main": "./dist/index.js",
Expand Down
57 changes: 56 additions & 1 deletion src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
ChangePassword,
CreatePrivateMessage,
DeleteAccount,
DeleteAccountResponse,
DeletePrivateMessage,
EditPrivateMessage,
GetCaptchaResponse,
Expand Down Expand Up @@ -72,6 +73,8 @@ import {
PrivateMessagesResponse,
Register,
SaveUserSettings,
VerifyEmail,
VerifyEmailResponse,
} from "./interfaces/api/person";
import {
CreatePost,
Expand All @@ -96,6 +99,7 @@ import {
StickyPost,
} from "./interfaces/api/post";
import {
ApproveRegistrationApplication,
CreateSite,
EditSite,
GetModlog,
Expand All @@ -104,6 +108,11 @@ import {
GetSiteConfig,
GetSiteConfigResponse,
GetSiteResponse,
GetUnreadRegistrationApplicationCount,
GetUnreadRegistrationApplicationCountResponse,
ListRegistrationApplications,
ListRegistrationApplicationsResponse,
RegistrationApplicationResponse,
ResolveObject,
ResolveObjectResponse,
SaveSiteConfig,
Expand Down Expand Up @@ -592,7 +601,7 @@ export class LemmyHttp {
/**
* Delete your account.
*/
async deleteAccount(form: DeleteAccount): Promise<LoginResponse> {
async deleteAccount(form: DeleteAccount): Promise<DeleteAccountResponse> {
return this.wrapper(HttpType.Post, "/user/delete_account", form);
}

Expand Down Expand Up @@ -645,13 +654,59 @@ export class LemmyHttp {
return this.wrapper(HttpType.Get, "/user/unread_count", form);
}

/**
* Verify your email
*/
async verifyEmail(form: VerifyEmail): Promise<VerifyEmailResponse> {
return this.wrapper(HttpType.Post, "/user/verify_email", form);
}

/**
* Add an admin to your site.
*/
async addAdmin(form: AddAdmin): Promise<AddAdminResponse> {
return this.wrapper(HttpType.Post, "/admin/add", form);
}

/**
* Get the unread registration applications count.
*/
async getUnreadRegistrationApplicationCount(
form: GetUnreadRegistrationApplicationCount
): Promise<GetUnreadRegistrationApplicationCountResponse> {
return this.wrapper(
HttpType.Get,
"/admin/registration_application/count",
form
);
}

/**
* List the unread registration applications.
*/
async listRegistrationApplications(
form: ListRegistrationApplications
): Promise<ListRegistrationApplicationsResponse> {
return this.wrapper(
HttpType.Get,
"/admin/registration_application/list",
form
);
}

/**
* Approve a registration application
*/
async approveRegistrationApplication(
form: ApproveRegistrationApplication
): Promise<RegistrationApplicationResponse> {
return this.wrapper(
HttpType.Put,
"/admin/registration_application/approve",
form
);
}

private buildFullUrl(endpoint: string): string {
return `${this.apiUrl}${endpoint}`;
}
Expand Down
22 changes: 21 additions & 1 deletion src/interfaces/api/person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export interface Login {
*/
export interface Register {
username: string;
/**
* Email is mandatory if email verification is enabled on the server
*/
email?: string;
password: string;
password_verify: string;
Expand All @@ -29,6 +32,10 @@ export interface Register {
captcha_uuid?: string;
captcha_answer?: string;
honeypot?: string;
/**
* An answer is mandatory if require application is enabled on the server
*/
answer?: string;
}

export interface GetCaptcha {}
Expand Down Expand Up @@ -106,7 +113,12 @@ export interface ChangePassword {
* The `jwt` string should be stored and used anywhere `auth` is called for.
*/
export interface LoginResponse {
jwt: string;
/**
* This is None in response to `Register` if email verification is enabled, or the server requires registration applications.
*/
jwt?: string;
verify_email_sent: boolean;
registration_created: boolean;
}

export interface GetPersonDetails {
Expand Down Expand Up @@ -210,6 +222,8 @@ export interface DeleteAccount {
auth: string;
}

export interface DeleteAccountResponse {}

export interface PasswordReset {
email: string;
}
Expand Down Expand Up @@ -285,6 +299,12 @@ export interface GetUnreadCountResponse {
private_messages: number;
}

export interface VerifyEmail {
token: string;
}

export interface VerifyEmailResponse {}

export interface BlockPerson {
person_id: number;
block: boolean;
Expand Down
43 changes: 43 additions & 0 deletions src/interfaces/api/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
PersonBlockView,
PersonViewSafe,
PostView,
RegistrationApplicationView,
SiteView,
} from "../views";

Expand Down Expand Up @@ -66,6 +67,7 @@ export interface GetModlog {
community_id?: number;
page?: number;
limit?: number;
auth?: string;
}

export interface GetModlogResponse {
Expand All @@ -91,6 +93,10 @@ export interface CreateSite {
open_registration?: boolean;
enable_nsfw?: boolean;
community_creation_admin_only?: boolean;
require_email_verification?: boolean;
require_application?: boolean;
application_question?: string;
private_instance?: boolean;
auth: string;
}

Expand All @@ -104,6 +110,10 @@ export interface EditSite {
open_registration?: boolean;
enable_nsfw?: boolean;
community_creation_admin_only?: boolean;
require_email_verification?: boolean;
require_application?: boolean;
application_question?: string;
private_instance?: boolean;
auth: string;
}

Expand Down Expand Up @@ -177,3 +187,36 @@ export interface ResolveObjectResponse {
community?: CommunityView;
person?: PersonViewSafe;
}

export interface ListRegistrationApplications {
/**
* Only shows the unread applications (IE those without an admin actor)
*/
unread_only?: boolean;
page?: number;
limit?: number;
auth: string;
}

export interface ListRegistrationApplicationsResponse {
registration_applications: RegistrationApplicationView[];
}

export interface ApproveRegistrationApplication {
id: number;
approve: boolean;
deny_reason?: string;
auth: string;
}

export interface RegistrationApplicationResponse {
registration_application: RegistrationApplicationView;
}

export interface GetUnreadRegistrationApplicationCount {
auth: string;
}

export interface GetUnreadRegistrationApplicationCountResponse {
registration_applications: number;
}
4 changes: 4 additions & 0 deletions src/interfaces/others.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export enum UserOperation {
EditSite,
GetSite,
AddAdmin,
GetUnreadRegistrationApplicationCount,
ListRegistrationApplications,
ApproveRegistrationApplication,
BanPerson,
Search,
ResolveObject,
Expand Down Expand Up @@ -75,6 +78,7 @@ export enum UserOperation {
ListPostReports,
GetReportCount,
GetUnreadCount,
VerifyEmail,
}

/**
Expand Down
19 changes: 17 additions & 2 deletions src/interfaces/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface LocalUserSettings {
show_scores: boolean;
show_read_posts: boolean;
show_new_post_notifs: boolean;
email_verified: boolean;
accepted_application: boolean;
}

export interface PersonSafe {
Expand All @@ -39,16 +41,20 @@ export interface Site {
id: number;
name: string;
sidebar?: string;
description?: string;
creator_id: number;
published: string;
updated?: string;
enable_downvotes: boolean;
open_registration: boolean;
enable_nsfw: boolean;
community_creation_admin_only: boolean;
icon?: string;
banner?: string;
description?: string;
community_creation_admin_only: boolean;
require_email_verification: boolean;
require_application: boolean;
application_question?: string;
private_instance: boolean;
}

export interface PrivateMessage {
Expand Down Expand Up @@ -248,3 +254,12 @@ export interface PersonMention {
read: boolean;
published: string;
}

export interface RegistrationApplication {
id: number;
local_user_id: number;
answer: string;
admin_id?: number;
deny_reason?: string;
published: string;
}
8 changes: 8 additions & 0 deletions src/interfaces/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
Post,
PostReport,
PrivateMessage,
RegistrationApplication,
Site,
} from "./source";

Expand Down Expand Up @@ -218,3 +219,10 @@ export interface CommunityView {
blocked: boolean;
counts: CommunityAggregates;
}

export interface RegistrationApplicationView {
registration_application: RegistrationApplication;
creator_local_user: LocalUserSettings;
creator: PersonSafe;
admin?: PersonSafe;
}
35 changes: 35 additions & 0 deletions src/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
PasswordReset,
Register,
SaveUserSettings,
VerifyEmail,
} from "./interfaces/api/person";
import {
CreatePost,
Expand All @@ -65,11 +66,14 @@ import {
StickyPost,
} from "./interfaces/api/post";
import {
ApproveRegistrationApplication,
CreateSite,
EditSite,
GetModlog,
GetSite,
GetSiteConfig,
GetUnreadRegistrationApplicationCount,
ListRegistrationApplications,
ResolveObject,
SaveSiteConfig,
Search,
Expand Down Expand Up @@ -404,6 +408,29 @@ export class LemmyWebsocket {
return wrapper(UserOperation.AddAdmin, form);
}

/**
* Get the unread registration applications count.
*/
getUnreadRegistrationApplicationCount(
form: GetUnreadRegistrationApplicationCount
) {
return wrapper(UserOperation.GetUnreadRegistrationApplicationCount, form);
}

/**
* List the unread registration applications.
*/
listRegistrationApplications(form: ListRegistrationApplications) {
return wrapper(UserOperation.ListRegistrationApplications, form);
}

/**
* Approve a registration application
*/
approveRegistrationApplication(form: ApproveRegistrationApplication) {
return wrapper(UserOperation.ApproveRegistrationApplication, form);
}

/**
* Get the details for a person.
*/
Expand Down Expand Up @@ -515,6 +542,14 @@ export class LemmyWebsocket {
getUnreadCount(form: GetUnreadCount) {
return wrapper(UserOperation.GetUnreadCount, form);
}

/**
* Verify your email
*/
verifyEmail(form: VerifyEmail) {
return wrapper(UserOperation.VerifyEmail, form);
}

/**
* Delete your account.
*/
Expand Down