Adding private instance related endpoints. (#38)

* Adding private instance related endpoints.

* Running prettier.

* v0.15.0-rc.1

* v0.15.0-rc.2

* Remove VerifyEmailResponse

* v0.15.0-rc.3

* Revert "Remove VerifyEmailResponse"

This reverts commit 49713c23c6.

* Add optional auth to modlog.

* v0.15.0-rc.6
This commit is contained in:
Dessalines 2021-12-30 10:27:05 -05:00 committed by GitHub
parent 5e4ff291c5
commit c4827a62c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 185 additions and 5 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "lemmy-js-client", "name": "lemmy-js-client",
"description": "A javascript / typescript client for Lemmy", "description": "A javascript / typescript client for Lemmy",
"version": "0.14.0-rc.1", "version": "0.15.0-rc.6",
"author": "Dessalines <tyhou13@gmx.com>", "author": "Dessalines <tyhou13@gmx.com>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "./dist/index.js", "main": "./dist/index.js",

View file

@ -45,6 +45,7 @@ import {
ChangePassword, ChangePassword,
CreatePrivateMessage, CreatePrivateMessage,
DeleteAccount, DeleteAccount,
DeleteAccountResponse,
DeletePrivateMessage, DeletePrivateMessage,
EditPrivateMessage, EditPrivateMessage,
GetCaptchaResponse, GetCaptchaResponse,
@ -72,6 +73,8 @@ import {
PrivateMessagesResponse, PrivateMessagesResponse,
Register, Register,
SaveUserSettings, SaveUserSettings,
VerifyEmail,
VerifyEmailResponse,
} from "./interfaces/api/person"; } from "./interfaces/api/person";
import { import {
CreatePost, CreatePost,
@ -96,6 +99,7 @@ import {
StickyPost, StickyPost,
} from "./interfaces/api/post"; } from "./interfaces/api/post";
import { import {
ApproveRegistrationApplication,
CreateSite, CreateSite,
EditSite, EditSite,
GetModlog, GetModlog,
@ -104,6 +108,11 @@ import {
GetSiteConfig, GetSiteConfig,
GetSiteConfigResponse, GetSiteConfigResponse,
GetSiteResponse, GetSiteResponse,
GetUnreadRegistrationApplicationCount,
GetUnreadRegistrationApplicationCountResponse,
ListRegistrationApplications,
ListRegistrationApplicationsResponse,
RegistrationApplicationResponse,
ResolveObject, ResolveObject,
ResolveObjectResponse, ResolveObjectResponse,
SaveSiteConfig, SaveSiteConfig,
@ -592,7 +601,7 @@ export class LemmyHttp {
/** /**
* Delete your account. * Delete your account.
*/ */
async deleteAccount(form: DeleteAccount): Promise<LoginResponse> { async deleteAccount(form: DeleteAccount): Promise<DeleteAccountResponse> {
return this.wrapper(HttpType.Post, "/user/delete_account", form); return this.wrapper(HttpType.Post, "/user/delete_account", form);
} }
@ -645,6 +654,13 @@ export class LemmyHttp {
return this.wrapper(HttpType.Get, "/user/unread_count", form); 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. * Add an admin to your site.
*/ */
@ -652,6 +668,45 @@ export class LemmyHttp {
return this.wrapper(HttpType.Post, "/admin/add", form); 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 { private buildFullUrl(endpoint: string): string {
return `${this.apiUrl}${endpoint}`; return `${this.apiUrl}${endpoint}`;
} }

View file

@ -19,6 +19,9 @@ export interface Login {
*/ */
export interface Register { export interface Register {
username: string; username: string;
/**
* Email is mandatory if email verification is enabled on the server
*/
email?: string; email?: string;
password: string; password: string;
password_verify: string; password_verify: string;
@ -29,6 +32,10 @@ export interface Register {
captcha_uuid?: string; captcha_uuid?: string;
captcha_answer?: string; captcha_answer?: string;
honeypot?: string; honeypot?: string;
/**
* An answer is mandatory if require application is enabled on the server
*/
answer?: string;
} }
export interface GetCaptcha {} export interface GetCaptcha {}
@ -106,7 +113,12 @@ export interface ChangePassword {
* The `jwt` string should be stored and used anywhere `auth` is called for. * The `jwt` string should be stored and used anywhere `auth` is called for.
*/ */
export interface LoginResponse { 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 { export interface GetPersonDetails {
@ -210,6 +222,8 @@ export interface DeleteAccount {
auth: string; auth: string;
} }
export interface DeleteAccountResponse {}
export interface PasswordReset { export interface PasswordReset {
email: string; email: string;
} }
@ -285,6 +299,12 @@ export interface GetUnreadCountResponse {
private_messages: number; private_messages: number;
} }
export interface VerifyEmail {
token: string;
}
export interface VerifyEmailResponse {}
export interface BlockPerson { export interface BlockPerson {
person_id: number; person_id: number;
block: boolean; block: boolean;

View file

@ -18,6 +18,7 @@ import {
PersonBlockView, PersonBlockView,
PersonViewSafe, PersonViewSafe,
PostView, PostView,
RegistrationApplicationView,
SiteView, SiteView,
} from "../views"; } from "../views";
@ -66,6 +67,7 @@ export interface GetModlog {
community_id?: number; community_id?: number;
page?: number; page?: number;
limit?: number; limit?: number;
auth?: string;
} }
export interface GetModlogResponse { export interface GetModlogResponse {
@ -91,6 +93,10 @@ export interface CreateSite {
open_registration?: boolean; open_registration?: boolean;
enable_nsfw?: boolean; enable_nsfw?: boolean;
community_creation_admin_only?: boolean; community_creation_admin_only?: boolean;
require_email_verification?: boolean;
require_application?: boolean;
application_question?: string;
private_instance?: boolean;
auth: string; auth: string;
} }
@ -104,6 +110,10 @@ export interface EditSite {
open_registration?: boolean; open_registration?: boolean;
enable_nsfw?: boolean; enable_nsfw?: boolean;
community_creation_admin_only?: boolean; community_creation_admin_only?: boolean;
require_email_verification?: boolean;
require_application?: boolean;
application_question?: string;
private_instance?: boolean;
auth: string; auth: string;
} }
@ -177,3 +187,36 @@ export interface ResolveObjectResponse {
community?: CommunityView; community?: CommunityView;
person?: PersonViewSafe; 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;
}

View file

@ -42,6 +42,9 @@ export enum UserOperation {
EditSite, EditSite,
GetSite, GetSite,
AddAdmin, AddAdmin,
GetUnreadRegistrationApplicationCount,
ListRegistrationApplications,
ApproveRegistrationApplication,
BanPerson, BanPerson,
Search, Search,
ResolveObject, ResolveObject,
@ -75,6 +78,7 @@ export enum UserOperation {
ListPostReports, ListPostReports,
GetReportCount, GetReportCount,
GetUnreadCount, GetUnreadCount,
VerifyEmail,
} }
/** /**

View file

@ -13,6 +13,8 @@ export interface LocalUserSettings {
show_scores: boolean; show_scores: boolean;
show_read_posts: boolean; show_read_posts: boolean;
show_new_post_notifs: boolean; show_new_post_notifs: boolean;
email_verified: boolean;
accepted_application: boolean;
} }
export interface PersonSafe { export interface PersonSafe {
@ -39,16 +41,20 @@ export interface Site {
id: number; id: number;
name: string; name: string;
sidebar?: string; sidebar?: string;
description?: string;
creator_id: number; creator_id: number;
published: string; published: string;
updated?: string; updated?: string;
enable_downvotes: boolean; enable_downvotes: boolean;
open_registration: boolean; open_registration: boolean;
enable_nsfw: boolean; enable_nsfw: boolean;
community_creation_admin_only: boolean;
icon?: string; icon?: string;
banner?: 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 { export interface PrivateMessage {
@ -248,3 +254,12 @@ export interface PersonMention {
read: boolean; read: boolean;
published: string; published: string;
} }
export interface RegistrationApplication {
id: number;
local_user_id: number;
answer: string;
admin_id?: number;
deny_reason?: string;
published: string;
}

View file

@ -25,6 +25,7 @@ import {
Post, Post,
PostReport, PostReport,
PrivateMessage, PrivateMessage,
RegistrationApplication,
Site, Site,
} from "./source"; } from "./source";
@ -218,3 +219,10 @@ export interface CommunityView {
blocked: boolean; blocked: boolean;
counts: CommunityAggregates; counts: CommunityAggregates;
} }
export interface RegistrationApplicationView {
registration_application: RegistrationApplication;
creator_local_user: LocalUserSettings;
creator: PersonSafe;
admin?: PersonSafe;
}

View file

@ -47,6 +47,7 @@ import {
PasswordReset, PasswordReset,
Register, Register,
SaveUserSettings, SaveUserSettings,
VerifyEmail,
} from "./interfaces/api/person"; } from "./interfaces/api/person";
import { import {
CreatePost, CreatePost,
@ -65,11 +66,14 @@ import {
StickyPost, StickyPost,
} from "./interfaces/api/post"; } from "./interfaces/api/post";
import { import {
ApproveRegistrationApplication,
CreateSite, CreateSite,
EditSite, EditSite,
GetModlog, GetModlog,
GetSite, GetSite,
GetSiteConfig, GetSiteConfig,
GetUnreadRegistrationApplicationCount,
ListRegistrationApplications,
ResolveObject, ResolveObject,
SaveSiteConfig, SaveSiteConfig,
Search, Search,
@ -404,6 +408,29 @@ export class LemmyWebsocket {
return wrapper(UserOperation.AddAdmin, form); 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. * Get the details for a person.
*/ */
@ -515,6 +542,14 @@ export class LemmyWebsocket {
getUnreadCount(form: GetUnreadCount) { getUnreadCount(form: GetUnreadCount) {
return wrapper(UserOperation.GetUnreadCount, form); return wrapper(UserOperation.GetUnreadCount, form);
} }
/**
* Verify your email
*/
verifyEmail(form: VerifyEmail) {
return wrapper(UserOperation.VerifyEmail, form);
}
/** /**
* Delete your account. * Delete your account.
*/ */