@nextjs-cms-plugins/cpanel-emails 0.1.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/dist/client/EmailsPage.d.ts +64 -0
- package/dist/client/EmailsPage.d.ts.map +1 -0
- package/dist/client/EmailsPage.js +37 -0
- package/dist/client.d.ts +65 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/router.d.ts +63 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +134 -0
- package/package.json +41 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { EmailItem } from 'nextjs-cms/core/types';
|
|
2
|
+
type TrpcEmails = {
|
|
3
|
+
cpanelEmails?: {
|
|
4
|
+
getEmails: {
|
|
5
|
+
useQuery: () => {
|
|
6
|
+
data?: {
|
|
7
|
+
emails: EmailItem[];
|
|
8
|
+
};
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
isError?: boolean;
|
|
11
|
+
error?: unknown;
|
|
12
|
+
refetch: () => Promise<unknown>;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
createEmail: {
|
|
16
|
+
useMutation: (opts: {
|
|
17
|
+
onSuccess: () => void;
|
|
18
|
+
}) => {
|
|
19
|
+
mutateAsync: (input: {
|
|
20
|
+
email: string;
|
|
21
|
+
password: string;
|
|
22
|
+
quota: string;
|
|
23
|
+
}) => Promise<unknown>;
|
|
24
|
+
isPending?: boolean;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
quotaChange: {
|
|
28
|
+
useMutation: (opts: {
|
|
29
|
+
onSuccess: () => void;
|
|
30
|
+
}) => {
|
|
31
|
+
mutateAsync: (input: {
|
|
32
|
+
email: string;
|
|
33
|
+
quota: string;
|
|
34
|
+
}) => Promise<unknown>;
|
|
35
|
+
isPending?: boolean;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
passwordChange: {
|
|
39
|
+
useMutation: (opts: {
|
|
40
|
+
onSuccess: () => void;
|
|
41
|
+
}) => {
|
|
42
|
+
mutateAsync: (input: {
|
|
43
|
+
email: string;
|
|
44
|
+
password: string;
|
|
45
|
+
passwordConfirm: string;
|
|
46
|
+
}) => Promise<unknown>;
|
|
47
|
+
isPending?: boolean;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
deleteEmail: {
|
|
51
|
+
useMutation: (opts: {
|
|
52
|
+
onSuccess: () => void;
|
|
53
|
+
}) => {
|
|
54
|
+
mutateAsync: (email: string) => Promise<unknown>;
|
|
55
|
+
isPending?: boolean;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
export declare const CpanelEmailsPage: ({ trpc }: {
|
|
61
|
+
trpc: TrpcEmails;
|
|
62
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
63
|
+
export default CpanelEmailsPage;
|
|
64
|
+
//# sourceMappingURL=EmailsPage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmailsPage.d.ts","sourceRoot":"","sources":["../../src/client/EmailsPage.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEtD,KAAK,UAAU,GAAG;IACd,YAAY,CAAC,EAAE;QACX,SAAS,EAAE;YACP,QAAQ,EAAE,MAAM;gBACZ,IAAI,CAAC,EAAE;oBAAE,MAAM,EAAE,SAAS,EAAE,CAAA;iBAAE,CAAA;gBAC9B,SAAS,EAAE,OAAO,CAAA;gBAClB,OAAO,CAAC,EAAE,OAAO,CAAA;gBACjB,KAAK,CAAC,EAAE,OAAO,CAAA;gBACf,OAAO,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;aAClC,CAAA;SACJ,CAAA;QACD,WAAW,EAAE;YACT,WAAW,EAAE,CAAC,IAAI,EAAE;gBAAE,SAAS,EAAE,MAAM,IAAI,CAAA;aAAE,KAAK;gBAC9C,WAAW,EAAE,CAAC,KAAK,EAAE;oBAAE,KAAK,EAAE,MAAM,CAAC;oBAAC,QAAQ,EAAE,MAAM,CAAC;oBAAC,KAAK,EAAE,MAAM,CAAA;iBAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;gBAC5F,SAAS,CAAC,EAAE,OAAO,CAAA;aACtB,CAAA;SACJ,CAAA;QACD,WAAW,EAAE;YACT,WAAW,EAAE,CAAC,IAAI,EAAE;gBAAE,SAAS,EAAE,MAAM,IAAI,CAAA;aAAE,KAAK;gBAC9C,WAAW,EAAE,CAAC,KAAK,EAAE;oBAAE,KAAK,EAAE,MAAM,CAAC;oBAAC,KAAK,EAAE,MAAM,CAAA;iBAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;gBAC1E,SAAS,CAAC,EAAE,OAAO,CAAA;aACtB,CAAA;SACJ,CAAA;QACD,cAAc,EAAE;YACZ,WAAW,EAAE,CAAC,IAAI,EAAE;gBAAE,SAAS,EAAE,MAAM,IAAI,CAAA;aAAE,KAAK;gBAC9C,WAAW,EAAE,CAAC,KAAK,EAAE;oBAAE,KAAK,EAAE,MAAM,CAAC;oBAAC,QAAQ,EAAE,MAAM,CAAC;oBAAC,eAAe,EAAE,MAAM,CAAA;iBAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;gBACtG,SAAS,CAAC,EAAE,OAAO,CAAA;aACtB,CAAA;SACJ,CAAA;QACD,WAAW,EAAE;YACT,WAAW,EAAE,CAAC,IAAI,EAAE;gBAAE,SAAS,EAAE,MAAM,IAAI,CAAA;aAAE,KAAK;gBAC9C,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;gBAChD,SAAS,CAAC,EAAE,OAAO,CAAA;aACtB,CAAA;SACJ,CAAA;KACJ,CAAA;CACJ,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,UAAU;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,4CA+C9D,CAAA;AA0ID,eAAe,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import getString from 'nextjs-cms/translations';
|
|
5
|
+
export const CpanelEmailsPage = ({ trpc }) => {
|
|
6
|
+
const query = trpc?.cpanelEmails?.getEmails.useQuery;
|
|
7
|
+
const { data, isLoading, isError, error, refetch } = query
|
|
8
|
+
? query()
|
|
9
|
+
: { isLoading: true, isError: true, error: null, refetch: async () => undefined };
|
|
10
|
+
if (!query) {
|
|
11
|
+
return _jsx("div", { className: 'p-6 text-sm text-red-500', children: "cPanel emails plugin misconfigured: missing trpc client." });
|
|
12
|
+
}
|
|
13
|
+
const pluginApi = trpc.cpanelEmails;
|
|
14
|
+
const createEmailMutation = pluginApi.createEmail.useMutation({ onSuccess: () => refetch() });
|
|
15
|
+
const quotaMutation = pluginApi.quotaChange.useMutation({ onSuccess: () => refetch() });
|
|
16
|
+
const passwordMutation = pluginApi.passwordChange.useMutation({ onSuccess: () => refetch() });
|
|
17
|
+
const deleteMutation = pluginApi.deleteEmail.useMutation({ onSuccess: () => refetch() });
|
|
18
|
+
return (_jsxs("div", { className: 'bg-white dark:bg-slate-900', children: [_jsx("div", { className: 'bg-linear-to-r from-sky-200 via-emerald-300 to-blue-600 p-8 font-extrabold text-foreground dark:from-blue-800 dark:via-amber-700 dark:to-rose-900', children: _jsx("h1", { className: 'text-3xl', children: getString('email_accounts') }) }), _jsxs("div", { className: 'flex flex-col gap-3 p-4', children: [_jsx(CreateEmailForm, { onSubmit: createEmailMutation.mutateAsync, isSubmitting: !!createEmailMutation.isPending }), isLoading && _jsx("div", { className: 'text-muted-foreground', children: "Loading emails\u2026" }), isError && !isLoading && (_jsx("div", { className: 'rounded border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive', children: error instanceof Error ? error.message : 'Unable to load emails' })), data?.emails?.length ? (_jsx("div", { className: 'grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3', children: data.emails.map((email) => (_jsx(EmailCard, { email: email, onDelete: () => deleteMutation.mutateAsync(email.user), onQuotaChange: (quota) => quotaMutation.mutateAsync({ email: email.user, quota }), onPasswordChange: (password, confirm) => passwordMutation.mutateAsync({ email: email.user, password, passwordConfirm: confirm }) }, email.user))) })) : null] })] }));
|
|
19
|
+
};
|
|
20
|
+
const CreateEmailForm = ({ onSubmit, isSubmitting, }) => {
|
|
21
|
+
const [email, setEmail] = useState('');
|
|
22
|
+
const [password, setPassword] = useState('');
|
|
23
|
+
const [quota, setQuota] = useState('1024');
|
|
24
|
+
return (_jsxs("form", { className: 'rounded-lg border bg-card p-4 text-card-foreground shadow-sm', onSubmit: async (e) => {
|
|
25
|
+
e.preventDefault();
|
|
26
|
+
await onSubmit({ email, password, quota });
|
|
27
|
+
setEmail('');
|
|
28
|
+
setPassword('');
|
|
29
|
+
}, children: [_jsx("div", { className: 'text-lg font-semibold', children: getString('create_new_email_account') }), _jsxs("div", { className: 'mt-3 grid grid-cols-1 gap-3 md:grid-cols-3', children: [_jsx("input", { className: 'rounded border px-3 py-2 text-sm', value: email, onChange: (e) => setEmail(e.target.value), placeholder: 'email', required: true }), _jsx("input", { className: 'rounded border px-3 py-2 text-sm', type: 'password', value: password, onChange: (e) => setPassword(e.target.value), placeholder: 'password', required: true }), _jsx("input", { className: 'rounded border px-3 py-2 text-sm', value: quota, onChange: (e) => setQuota(e.target.value), placeholder: 'quota', required: true })] }), _jsx("button", { type: 'submit', disabled: isSubmitting, className: 'mt-3 inline-flex items-center justify-center rounded bg-primary px-4 py-2 text-sm font-semibold text-primary-foreground shadow-sm hover:opacity-90 disabled:opacity-50', children: isSubmitting ? 'Saving…' : getString('create') })] }));
|
|
30
|
+
};
|
|
31
|
+
const EmailCard = ({ email, onDelete, onQuotaChange, onPasswordChange, }) => {
|
|
32
|
+
const [quota, setQuota] = useState(email.diskquota);
|
|
33
|
+
const [password, setPassword] = useState('');
|
|
34
|
+
const [confirm, setConfirm] = useState('');
|
|
35
|
+
return (_jsxs("div", { className: 'rounded-lg border bg-card p-4 text-card-foreground shadow-sm', children: [_jsxs("div", { className: 'flex items-center justify-between', children: [_jsx("div", { className: 'font-semibold', children: email.user }), _jsx("button", { className: 'text-sm text-destructive hover:underline', type: 'button', onClick: () => onDelete(), children: getString('delete') })] }), _jsxs("div", { className: 'mt-2 text-sm text-muted-foreground', children: [_jsxs("div", { children: ["Disk Used: ", email.diskusedpercent, " / ", email.diskquota] }), _jsxs("div", { children: ["Login: ", email.user] })] }), _jsxs("div", { className: 'mt-3 space-y-2 text-sm', children: [_jsxs("label", { className: 'block', children: [_jsx("span", { className: 'text-xs text-muted-foreground', children: "Quota" }), _jsx("input", { className: 'mt-1 w-full rounded border px-3 py-2', value: quota, onChange: (e) => setQuota(e.target.value) }), _jsx("button", { type: 'button', className: 'mt-1 inline-flex items-center justify-center rounded bg-primary px-3 py-1 text-xs font-semibold text-primary-foreground hover:opacity-90', onClick: () => onQuotaChange(quota), children: getString('update') })] }), _jsxs("label", { className: 'block', children: [_jsx("span", { className: 'text-xs text-muted-foreground', children: "Password" }), _jsx("input", { className: 'mt-1 w-full rounded border px-3 py-2', type: 'password', value: password, onChange: (e) => setPassword(e.target.value) })] }), _jsxs("label", { className: 'block', children: [_jsx("span", { className: 'text-xs text-muted-foreground', children: "Confirm" }), _jsx("input", { className: 'mt-1 w-full rounded border px-3 py-2', type: 'password', value: confirm, onChange: (e) => setConfirm(e.target.value) })] }), _jsx("button", { type: 'button', className: 'inline-flex items-center justify-center rounded bg-primary px-3 py-1 text-xs font-semibold text-primary-foreground hover:opacity-90', onClick: () => onPasswordChange(password, confirm), children: getString('updatePassword') })] })] }));
|
|
36
|
+
};
|
|
37
|
+
export default CpanelEmailsPage;
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CpanelEmailsPage } from './client/EmailsPage.js';
|
|
2
|
+
export declare const components: {
|
|
3
|
+
cpanelEmails: ({ trpc }: {
|
|
4
|
+
trpc: {
|
|
5
|
+
cpanelEmails?: {
|
|
6
|
+
getEmails: {
|
|
7
|
+
useQuery: () => {
|
|
8
|
+
data?: {
|
|
9
|
+
emails: import("nextjs-cms/core/types").EmailItem[];
|
|
10
|
+
};
|
|
11
|
+
isLoading: boolean;
|
|
12
|
+
isError?: boolean;
|
|
13
|
+
error?: unknown;
|
|
14
|
+
refetch: () => Promise<unknown>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
createEmail: {
|
|
18
|
+
useMutation: (opts: {
|
|
19
|
+
onSuccess: () => void;
|
|
20
|
+
}) => {
|
|
21
|
+
mutateAsync: (input: {
|
|
22
|
+
email: string;
|
|
23
|
+
password: string;
|
|
24
|
+
quota: string;
|
|
25
|
+
}) => Promise<unknown>;
|
|
26
|
+
isPending?: boolean;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
quotaChange: {
|
|
30
|
+
useMutation: (opts: {
|
|
31
|
+
onSuccess: () => void;
|
|
32
|
+
}) => {
|
|
33
|
+
mutateAsync: (input: {
|
|
34
|
+
email: string;
|
|
35
|
+
quota: string;
|
|
36
|
+
}) => Promise<unknown>;
|
|
37
|
+
isPending?: boolean;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
passwordChange: {
|
|
41
|
+
useMutation: (opts: {
|
|
42
|
+
onSuccess: () => void;
|
|
43
|
+
}) => {
|
|
44
|
+
mutateAsync: (input: {
|
|
45
|
+
email: string;
|
|
46
|
+
password: string;
|
|
47
|
+
passwordConfirm: string;
|
|
48
|
+
}) => Promise<unknown>;
|
|
49
|
+
isPending?: boolean;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
deleteEmail: {
|
|
53
|
+
useMutation: (opts: {
|
|
54
|
+
onSuccess: () => void;
|
|
55
|
+
}) => {
|
|
56
|
+
mutateAsync: (email: string) => Promise<unknown>;
|
|
57
|
+
isPending?: boolean;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
63
|
+
};
|
|
64
|
+
export { CpanelEmailsPage };
|
|
65
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAEzD,eAAO,MAAM,UAAU;;;;;;4BAKmG,CAAC;;;;+BAAoF,CAAC;6BAA+B,CAAC;;;;;;;;;;;;;iCAA+S,CAAC;;;;;;;;;;;iCAA6O,CAAC;;;;;;;;;;;;iCAA4Q,CAAC;;;;;;;;iCAAmN,CAAC;;;;;;CAH9uC,CAAA;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAA"}
|
package/dist/client.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEhD,wBAAgB,YAAY,IAAI,SAAS,CAaxC;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { cpanelEmailsRouter } from './router.js';
|
|
2
|
+
export function createPlugin() {
|
|
3
|
+
return {
|
|
4
|
+
name: 'cPanel Emails',
|
|
5
|
+
router: cpanelEmailsRouter,
|
|
6
|
+
routes: [
|
|
7
|
+
{
|
|
8
|
+
path: '/emails',
|
|
9
|
+
title: 'Emails',
|
|
10
|
+
icon: 'mail',
|
|
11
|
+
component: 'cpanelEmails',
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export { cpanelEmailsRouter };
|
package/dist/router.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export declare const cpanelEmailsRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
3
|
+
ctx: {
|
|
4
|
+
headers: Headers;
|
|
5
|
+
db: import("drizzle-orm/mysql2").MySql2Database<typeof import("nextjs-cms/db/schema")> & {
|
|
6
|
+
$client: import("mysql2/promise").Pool;
|
|
7
|
+
};
|
|
8
|
+
session: import("nextjs-cms").Session | null;
|
|
9
|
+
};
|
|
10
|
+
meta: object;
|
|
11
|
+
errorShape: {
|
|
12
|
+
data: {
|
|
13
|
+
zodError: import("zod").ZodFlattenedError<unknown, string> | null;
|
|
14
|
+
code: import("@trpc/server").TRPC_ERROR_CODE_KEY;
|
|
15
|
+
httpStatus: number;
|
|
16
|
+
path?: string;
|
|
17
|
+
stack?: string;
|
|
18
|
+
};
|
|
19
|
+
message: string;
|
|
20
|
+
code: import("@trpc/server").TRPC_ERROR_CODE_NUMBER;
|
|
21
|
+
};
|
|
22
|
+
transformer: true;
|
|
23
|
+
}, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
|
|
24
|
+
getEmails: import("@trpc/server").TRPCQueryProcedure<{
|
|
25
|
+
input: void;
|
|
26
|
+
output: {
|
|
27
|
+
emails: any;
|
|
28
|
+
};
|
|
29
|
+
meta: object;
|
|
30
|
+
}>;
|
|
31
|
+
createEmail: import("@trpc/server").TRPCMutationProcedure<{
|
|
32
|
+
input: {
|
|
33
|
+
email: string;
|
|
34
|
+
password: string;
|
|
35
|
+
quota: string;
|
|
36
|
+
};
|
|
37
|
+
output: any;
|
|
38
|
+
meta: object;
|
|
39
|
+
}>;
|
|
40
|
+
quotaChange: import("@trpc/server").TRPCMutationProcedure<{
|
|
41
|
+
input: {
|
|
42
|
+
email: string;
|
|
43
|
+
quota: string;
|
|
44
|
+
};
|
|
45
|
+
output: any;
|
|
46
|
+
meta: object;
|
|
47
|
+
}>;
|
|
48
|
+
passwordChange: import("@trpc/server").TRPCMutationProcedure<{
|
|
49
|
+
input: {
|
|
50
|
+
email: string;
|
|
51
|
+
password: string;
|
|
52
|
+
passwordConfirm: string;
|
|
53
|
+
};
|
|
54
|
+
output: any;
|
|
55
|
+
meta: object;
|
|
56
|
+
}>;
|
|
57
|
+
deleteEmail: import("@trpc/server").TRPCMutationProcedure<{
|
|
58
|
+
input: string;
|
|
59
|
+
output: any;
|
|
60
|
+
meta: object;
|
|
61
|
+
}>;
|
|
62
|
+
}>>;
|
|
63
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAKxB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;gBAsDhB,CAAC;iBACA,CAAP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiHP,CAAA"}
|
package/dist/router.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { TRPCError } from '@trpc/server';
|
|
2
|
+
import * as z from 'zod';
|
|
3
|
+
import getString from 'nextjs-cms/translations';
|
|
4
|
+
import { CpanelAPI } from 'nextjs-cms/utils';
|
|
5
|
+
import { privateProcedure, router } from 'nextjs-cms/api/trpc';
|
|
6
|
+
export const cpanelEmailsRouter = router({
|
|
7
|
+
getEmails: privateProcedure.query(async () => {
|
|
8
|
+
if (!process.env.CPANEL_USER || !process.env.CPANEL_PASSWORD || !process.env.CPANEL_DOMAIN) {
|
|
9
|
+
throw new TRPCError({
|
|
10
|
+
code: 'BAD_REQUEST',
|
|
11
|
+
message: getString('cpanelCredentialsNotSet'),
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
const cPanel = new CpanelAPI(process.env.CPANEL_USER, process.env.CPANEL_PASSWORD, `cpanel.${process.env.CPANEL_DOMAIN}`);
|
|
15
|
+
const data = await cPanel.callApi('Email', 'list_pops_with_disk', {
|
|
16
|
+
domain: process.env.CPANEL_DOMAIN,
|
|
17
|
+
maxaccounts: 100,
|
|
18
|
+
no_validate: 1,
|
|
19
|
+
infinitylang: 1,
|
|
20
|
+
'api.sort': '1',
|
|
21
|
+
'api.sort_column': 'mtime',
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
emails: data.data,
|
|
25
|
+
};
|
|
26
|
+
}),
|
|
27
|
+
createEmail: privateProcedure
|
|
28
|
+
.input(z.object({
|
|
29
|
+
email: z.string(),
|
|
30
|
+
password: z.string(),
|
|
31
|
+
quota: z.string(),
|
|
32
|
+
}))
|
|
33
|
+
.mutation(async ({ input }) => {
|
|
34
|
+
if (!process.env.CPANEL_USER || !process.env.CPANEL_PASSWORD || !process.env.CPANEL_DOMAIN) {
|
|
35
|
+
throw new TRPCError({
|
|
36
|
+
code: 'BAD_REQUEST',
|
|
37
|
+
message: getString('cpanelCredentialsNotSet'),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const cPanel = new CpanelAPI(process.env.CPANEL_USER, process.env.CPANEL_PASSWORD, `cpanel.${process.env.CPANEL_DOMAIN}`);
|
|
41
|
+
const data = await cPanel.callApi('Email', 'add_pop', {
|
|
42
|
+
domain: process.env.CPANEL_DOMAIN,
|
|
43
|
+
email: input.email,
|
|
44
|
+
password: input.password,
|
|
45
|
+
quota: input.quota,
|
|
46
|
+
});
|
|
47
|
+
if (cPanel.isError) {
|
|
48
|
+
throw new TRPCError({
|
|
49
|
+
code: 'BAD_REQUEST',
|
|
50
|
+
message: cPanel.getError(),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return data;
|
|
54
|
+
}),
|
|
55
|
+
quotaChange: privateProcedure
|
|
56
|
+
.input(z.object({
|
|
57
|
+
email: z.string(),
|
|
58
|
+
quota: z.string(),
|
|
59
|
+
}))
|
|
60
|
+
.mutation(async ({ input }) => {
|
|
61
|
+
if (!process.env.CPANEL_USER || !process.env.CPANEL_PASSWORD || !process.env.CPANEL_DOMAIN) {
|
|
62
|
+
throw new TRPCError({
|
|
63
|
+
code: 'BAD_REQUEST',
|
|
64
|
+
message: getString('cpanelCredentialsNotSet'),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const cPanel = new CpanelAPI(process.env.CPANEL_USER, process.env.CPANEL_PASSWORD, `cpanel.${process.env.CPANEL_DOMAIN}`);
|
|
68
|
+
const data = await cPanel.callApi('Email', 'edit_pop_quota', {
|
|
69
|
+
domain: process.env.CPANEL_DOMAIN,
|
|
70
|
+
email: input.email,
|
|
71
|
+
quota: input.quota,
|
|
72
|
+
});
|
|
73
|
+
if (cPanel.isError) {
|
|
74
|
+
throw new TRPCError({
|
|
75
|
+
code: 'BAD_REQUEST',
|
|
76
|
+
message: cPanel.getError(),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return data;
|
|
80
|
+
}),
|
|
81
|
+
passwordChange: privateProcedure
|
|
82
|
+
.input(z.object({
|
|
83
|
+
email: z.string(),
|
|
84
|
+
password: z.string(),
|
|
85
|
+
passwordConfirm: z.string(),
|
|
86
|
+
}))
|
|
87
|
+
.mutation(async ({ input }) => {
|
|
88
|
+
if (!process.env.CPANEL_USER || !process.env.CPANEL_PASSWORD || !process.env.CPANEL_DOMAIN) {
|
|
89
|
+
throw new TRPCError({
|
|
90
|
+
code: 'BAD_REQUEST',
|
|
91
|
+
message: getString('cpanelCredentialsNotSet'),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (input.password !== input.passwordConfirm) {
|
|
95
|
+
throw new TRPCError({
|
|
96
|
+
code: 'BAD_REQUEST',
|
|
97
|
+
message: getString('passwordsDoNotMatch'),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const cPanel = new CpanelAPI(process.env.CPANEL_USER, process.env.CPANEL_PASSWORD, `cpanel.${process.env.CPANEL_DOMAIN}`);
|
|
101
|
+
const data = await cPanel.callApi('Email', 'passwd_pop', {
|
|
102
|
+
domain: process.env.CPANEL_DOMAIN,
|
|
103
|
+
email: input.email,
|
|
104
|
+
password: input.password,
|
|
105
|
+
});
|
|
106
|
+
if (cPanel.isError) {
|
|
107
|
+
throw new TRPCError({
|
|
108
|
+
code: 'BAD_REQUEST',
|
|
109
|
+
message: cPanel.getError(),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return data;
|
|
113
|
+
}),
|
|
114
|
+
deleteEmail: privateProcedure.input(z.string()).mutation(async ({ input }) => {
|
|
115
|
+
if (!process.env.CPANEL_USER || !process.env.CPANEL_PASSWORD || !process.env.CPANEL_DOMAIN) {
|
|
116
|
+
throw new TRPCError({
|
|
117
|
+
code: 'BAD_REQUEST',
|
|
118
|
+
message: getString('cpanelCredentialsNotSet'),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const cPanel = new CpanelAPI(process.env.CPANEL_USER, process.env.CPANEL_PASSWORD, `cpanel.${process.env.CPANEL_DOMAIN}`);
|
|
122
|
+
const data = await cPanel.callApi('Email', 'delete_pop', {
|
|
123
|
+
domain: process.env.CPANEL_DOMAIN,
|
|
124
|
+
email: input,
|
|
125
|
+
});
|
|
126
|
+
if (cPanel.isError) {
|
|
127
|
+
throw new TRPCError({
|
|
128
|
+
code: 'BAD_REQUEST',
|
|
129
|
+
message: cPanel.getError(),
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return data;
|
|
133
|
+
}),
|
|
134
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nextjs-cms-plugins/cpanel-emails",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./client": {
|
|
13
|
+
"types": "./dist/client.d.ts",
|
|
14
|
+
"default": "./dist/client.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist/**/*",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"private": false,
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@trpc/server": "^11.4.2",
|
|
24
|
+
"zod": "4.1.12"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react": "19.0.0",
|
|
28
|
+
"react-dom": "19.0.0",
|
|
29
|
+
"nextjs-cms": "0.5.68"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/react": "~19.0.0",
|
|
33
|
+
"@types/react-dom": "^19.0.0",
|
|
34
|
+
"typescript": "^5.9.2"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"dev": "tsc --watch",
|
|
39
|
+
"clean": "git clean -xdf .cache .turbo dist node_modules"
|
|
40
|
+
}
|
|
41
|
+
}
|