nextjs-cms 0.9.22 → 0.9.24
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 +65 -13
- package/dist/api/actions/files.d.ts +30 -0
- package/dist/api/actions/files.d.ts.map +1 -0
- package/dist/api/actions/files.js +234 -0
- package/dist/api/actions/index.d.ts +4 -0
- package/dist/api/actions/index.d.ts.map +1 -0
- package/dist/api/actions/index.js +3 -0
- package/dist/api/actions/pages.d.ts +297 -0
- package/dist/api/actions/pages.d.ts.map +1 -0
- package/dist/api/actions/pages.js +1215 -0
- package/dist/api/actions/privileges.d.ts +25 -0
- package/dist/api/actions/privileges.d.ts.map +1 -0
- package/dist/api/actions/privileges.js +98 -0
- package/dist/api/client/index.d.ts +4 -0
- package/dist/api/client/index.d.ts.map +1 -0
- package/dist/api/client/index.js +3 -0
- package/dist/api/client.d.ts +30 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +82 -0
- package/dist/api/index.d.ts +1 -938
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +0 -13
- package/dist/api/plugin/index.d.ts +7 -0
- package/dist/api/plugin/index.d.ts.map +1 -0
- package/dist/api/plugin/index.js +5 -0
- package/dist/api/root.d.ts +18 -1844
- package/dist/api/root.d.ts.map +1 -1
- package/dist/api/root.js +18 -83
- package/dist/api/server/index.d.ts +8 -0
- package/dist/api/server/index.d.ts.map +1 -0
- package/dist/api/server/index.js +3 -0
- package/dist/api/server.d.ts +2748 -0
- package/dist/api/server.d.ts.map +1 -0
- package/dist/api/server.js +100 -0
- package/dist/api/trpc/client.d.ts +19 -3
- package/dist/api/trpc/client.d.ts.map +1 -1
- package/dist/api/trpc/client.js +55 -1
- package/dist/api/trpc/query-client.d.ts +3 -1
- package/dist/api/trpc/query-client.d.ts.map +1 -1
- package/dist/api/trpc/query-client.js +25 -20
- package/dist/api/trpc/root.d.ts +906 -0
- package/dist/api/trpc/root.d.ts.map +1 -0
- package/dist/api/trpc/root.js +47 -0
- package/dist/api/trpc/routers/accountSettings.d.ts +66 -0
- package/dist/api/trpc/routers/accountSettings.d.ts.map +1 -0
- package/dist/api/trpc/routers/accountSettings.js +200 -0
- package/dist/api/trpc/routers/admins.d.ts +112 -0
- package/dist/api/trpc/routers/admins.d.ts.map +1 -0
- package/dist/api/trpc/routers/admins.js +331 -0
- package/dist/api/trpc/routers/auth.d.ts +54 -0
- package/dist/api/trpc/routers/auth.d.ts.map +1 -0
- package/dist/api/trpc/routers/auth.js +50 -0
- package/dist/api/trpc/routers/categorySection.d.ts +105 -0
- package/dist/api/trpc/routers/categorySection.d.ts.map +1 -0
- package/dist/api/trpc/routers/categorySection.js +49 -0
- package/dist/api/trpc/routers/config.d.ts +48 -0
- package/dist/api/trpc/routers/config.d.ts.map +1 -0
- package/dist/api/trpc/routers/config.js +18 -0
- package/dist/api/trpc/routers/cpanel.d.ts +82 -0
- package/dist/api/trpc/routers/cpanel.d.ts.map +1 -0
- package/dist/api/trpc/routers/cpanel.js +216 -0
- package/dist/api/trpc/routers/fields.d.ts +35 -0
- package/dist/api/trpc/routers/fields.d.ts.map +1 -0
- package/dist/api/trpc/routers/fields.js +81 -0
- package/dist/api/trpc/routers/files.d.ts +34 -0
- package/dist/api/trpc/routers/files.d.ts.map +1 -0
- package/dist/api/trpc/routers/files.js +14 -0
- package/dist/api/trpc/routers/gallery.d.ts +35 -0
- package/dist/api/trpc/routers/gallery.d.ts.map +1 -0
- package/dist/api/trpc/routers/gallery.js +92 -0
- package/dist/api/trpc/routers/hasItemsSection.d.ts +194 -0
- package/dist/api/trpc/routers/hasItemsSection.d.ts.map +1 -0
- package/dist/api/trpc/routers/hasItemsSection.js +86 -0
- package/dist/api/trpc/routers/logs.d.ts +59 -0
- package/dist/api/trpc/routers/logs.d.ts.map +1 -0
- package/dist/api/trpc/routers/logs.js +79 -0
- package/dist/api/trpc/routers/navigation.d.ts +65 -0
- package/dist/api/trpc/routers/navigation.d.ts.map +1 -0
- package/dist/api/trpc/routers/navigation.js +11 -0
- package/dist/api/trpc/routers/simpleSection.d.ts +93 -0
- package/dist/api/trpc/routers/simpleSection.d.ts.map +1 -0
- package/dist/api/trpc/routers/simpleSection.js +54 -0
- package/dist/api/trpc/server.d.ts +2789 -5
- package/dist/api/trpc/server.d.ts.map +1 -1
- package/dist/api/trpc/server.js +91 -52
- package/dist/api/trpc/trpc.d.ts +111 -0
- package/dist/api/trpc/trpc.d.ts.map +1 -0
- package/dist/api/trpc/trpc.js +99 -0
- package/dist/api/trpc/utils/async-caller-proxy.d.ts +2 -0
- package/dist/api/trpc/utils/async-caller-proxy.d.ts.map +1 -0
- package/dist/api/trpc/utils/async-caller-proxy.js +38 -0
- package/dist/api/trpc/utils/refresh-token-link.d.ts +6 -0
- package/dist/api/trpc/utils/refresh-token-link.d.ts.map +1 -0
- package/dist/api/trpc/utils/refresh-token-link.js +81 -0
- package/dist/api/trpc/utils/router-types.d.ts +7 -0
- package/dist/api/trpc/utils/router-types.d.ts.map +1 -0
- package/dist/api/trpc/utils/router-types.js +0 -0
- package/dist/api/use-axios-private.d.ts +6 -0
- package/dist/api/use-axios-private.d.ts.map +1 -0
- package/dist/api/use-axios-private.js +57 -0
- package/dist/api/utils/async-caller-proxy.d.ts +2 -0
- package/dist/api/utils/async-caller-proxy.d.ts.map +1 -0
- package/dist/api/utils/async-caller-proxy.js +36 -0
- package/dist/api/utils/lazy-caller-proxy.d.ts +2 -0
- package/dist/api/utils/lazy-caller-proxy.d.ts.map +1 -0
- package/dist/api/utils/lazy-caller-proxy.js +36 -0
- package/dist/api/utils/router-types.d.ts +7 -0
- package/dist/api/utils/router-types.d.ts.map +1 -0
- package/dist/api/utils/router-types.js +0 -0
- package/dist/auth/hooks/index.d.ts +1 -2
- package/dist/auth/hooks/index.d.ts.map +1 -1
- package/dist/auth/hooks/index.js +1 -2
- package/dist/auth/react.d.ts +1 -2
- package/dist/auth/react.d.ts.map +1 -1
- package/dist/auth/react.js +1 -2
- package/dist/auth/trpc.d.ts +1 -1
- package/dist/auth/trpc.d.ts.map +1 -1
- package/dist/auth/trpc.js +0 -1
- package/dist/cli/lib/fix-master-admin.d.ts.map +1 -1
- package/dist/cli/lib/fix-master-admin.js +12 -25
- package/dist/cli/lib/update-sections.d.ts.map +1 -1
- package/dist/cli/lib/update-sections.js +29 -24
- package/dist/core/config/config-loader.d.ts +40 -16
- package/dist/core/config/config-loader.d.ts.map +1 -1
- package/dist/core/config/config-loader.js +58 -10
- package/dist/core/config/index.d.ts +1 -1
- package/dist/core/config/index.d.ts.map +1 -1
- package/dist/core/config/loader-with-jiti.d.ts.map +1 -1
- package/dist/core/config/loader-with-jiti.js +13 -12
- package/dist/core/factories/section-factory-with-jiti.d.ts.map +1 -1
- package/dist/core/factories/section-factory-with-jiti.js +2 -1
- package/dist/core/sections/category.d.ts +6 -6
- package/dist/core/sections/hasItems.d.ts +6 -6
- package/dist/core/sections/section.d.ts +4 -4
- package/dist/core/sections/simple.d.ts +2 -2
- package/dist/core/types/index.d.ts +17 -0
- package/dist/core/types/index.d.ts.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/plugins/client.d.ts +19 -0
- package/dist/plugins/client.d.ts.map +1 -0
- package/dist/plugins/client.js +24 -0
- package/dist/plugins/define.d.ts +6 -0
- package/dist/plugins/define.d.ts.map +1 -0
- package/dist/plugins/define.js +3 -0
- package/dist/plugins/derive.d.ts +32 -0
- package/dist/plugins/derive.d.ts.map +1 -0
- package/dist/plugins/derive.js +77 -0
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/loader.d.ts +43 -51
- package/dist/plugins/loader.d.ts.map +1 -1
- package/dist/plugins/loader.js +115 -58
- package/dist/plugins/manifest.d.ts +28 -0
- package/dist/plugins/manifest.d.ts.map +1 -0
- package/dist/plugins/manifest.js +83 -0
- package/dist/plugins/prefetch.d.ts +16 -0
- package/dist/plugins/prefetch.d.ts.map +1 -0
- package/dist/plugins/prefetch.js +40 -0
- package/dist/plugins/registry.d.ts +22 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +25 -0
- package/dist/plugins/server.d.ts +2 -0
- package/dist/plugins/server.d.ts.map +1 -1
- package/dist/plugins/server.js +2 -0
- package/dist/plugins/types.d.ts +79 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +0 -0
- package/dist/translations/base/en.d.ts +1 -0
- package/dist/translations/base/en.d.ts.map +1 -1
- package/dist/translations/base/en.js +1 -0
- package/dist/translations/client.d.ts +16 -4
- package/dist/translations/client.d.ts.map +1 -1
- package/dist/translations/server.d.ts +16 -4
- package/dist/translations/server.d.ts.map +1 -1
- package/dist/utils/console-log.d.ts +18 -0
- package/dist/utils/console-log.d.ts.map +1 -0
- package/dist/utils/console-log.js +28 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/log.d.ts +18 -0
- package/dist/utils/log.d.ts.map +1 -0
- package/dist/utils/log.js +28 -0
- package/dist/validators/index.d.ts +1 -0
- package/dist/validators/index.d.ts.map +1 -1
- package/dist/validators/index.js +1 -0
- package/dist/validators/tags.d.ts +4 -0
- package/dist/validators/tags.d.ts.map +1 -0
- package/dist/validators/tags.js +8 -0
- package/package.json +28 -18
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../../../src/api/trpc/root.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAsBvB,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAiBqxe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAA+1nB,CAAC;;;;;2BAA0E,CAAC;;;;;;2BAAgH,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAAt4/B,CAAC;;;;;2BAAuE,CAAC;;;;;;2BAA6G,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAH1nH,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { privateProcedure, router } from './trpc.js';
|
|
2
|
+
import { adminsRouter } from './routers/admins.js';
|
|
3
|
+
import { hasItemsSectionRouter } from './routers/hasItemsSection.js';
|
|
4
|
+
import { filesRouter } from './routers/files.js';
|
|
5
|
+
import { authRouter } from './routers/auth.js';
|
|
6
|
+
import { configRouter } from './routers/config.js';
|
|
7
|
+
import { navRouter } from './routers/navigation.js';
|
|
8
|
+
import { simpleSectionRouter } from './routers/simpleSection.js';
|
|
9
|
+
import { categorySectionRouter } from './routers/categorySection.js';
|
|
10
|
+
import { accountSettings } from './routers/accountSettings.js';
|
|
11
|
+
import { galleryRouter } from './routers/gallery.js';
|
|
12
|
+
import { logsRouter } from './routers/logs.js';
|
|
13
|
+
import { fieldsRouter } from './routers/fields.js';
|
|
14
|
+
import { getPluginRoutes } from '../../plugins/loader.js';
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
import { getAdminPrivileges } from '../actions/privileges.js';
|
|
17
|
+
const pluginsRouter = router({
|
|
18
|
+
checkRoute: privateProcedure
|
|
19
|
+
.input(z.object({
|
|
20
|
+
path: z.string(),
|
|
21
|
+
}))
|
|
22
|
+
.query(async ({ ctx, input }) => {
|
|
23
|
+
const routes = await getPluginRoutes();
|
|
24
|
+
const privilegeSet = await getAdminPrivileges(ctx.session.user.id);
|
|
25
|
+
const filteredRoutes = routes.filter(({ pluginName }) => privilegeSet.has(pluginName));
|
|
26
|
+
const plugin = filteredRoutes.find(({ path }) => path === input.path);
|
|
27
|
+
if (!plugin) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return plugin;
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
export const coreRouters = {
|
|
34
|
+
auth: authRouter,
|
|
35
|
+
admins: adminsRouter,
|
|
36
|
+
config: configRouter,
|
|
37
|
+
hasItemsSections: hasItemsSectionRouter,
|
|
38
|
+
simpleSections: simpleSectionRouter,
|
|
39
|
+
categorySections: categorySectionRouter,
|
|
40
|
+
files: filesRouter,
|
|
41
|
+
gallery: galleryRouter,
|
|
42
|
+
navigation: navRouter,
|
|
43
|
+
accountSettings: accountSettings,
|
|
44
|
+
fields: fieldsRouter,
|
|
45
|
+
logs: logsRouter,
|
|
46
|
+
plugins: pluginsRouter,
|
|
47
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export declare const accountSettings: import("@trpc/server").TRPCBuiltRouter<{
|
|
3
|
+
ctx: {
|
|
4
|
+
headers: Headers;
|
|
5
|
+
db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../../../db/schema.js")> & {
|
|
6
|
+
$client: import("mysql2/promise").Pool;
|
|
7
|
+
};
|
|
8
|
+
session: import("../../../index.js").Session | null;
|
|
9
|
+
};
|
|
10
|
+
meta: object;
|
|
11
|
+
errorShape: {
|
|
12
|
+
data: {
|
|
13
|
+
zodError: z.core.$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
|
+
get: import("@trpc/server").TRPCQueryProcedure<{
|
|
25
|
+
input: void;
|
|
26
|
+
output: {
|
|
27
|
+
id: string;
|
|
28
|
+
username: string;
|
|
29
|
+
emailAddress: string | null;
|
|
30
|
+
fullName: string | null;
|
|
31
|
+
avatar: string | null;
|
|
32
|
+
phoneNumber: string | null;
|
|
33
|
+
} | undefined;
|
|
34
|
+
meta: object;
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* No avatar for now, if you want to include it, you have to use the api route,
|
|
38
|
+
* because trpc doesn't support file uploads.
|
|
39
|
+
*/
|
|
40
|
+
save: import("@trpc/server").TRPCMutationProcedure<{
|
|
41
|
+
input: {
|
|
42
|
+
emailAddress: string;
|
|
43
|
+
fullName: string;
|
|
44
|
+
phoneNumber: string;
|
|
45
|
+
};
|
|
46
|
+
output: boolean;
|
|
47
|
+
meta: object;
|
|
48
|
+
}>;
|
|
49
|
+
changePassword: import("@trpc/server").TRPCMutationProcedure<{
|
|
50
|
+
input: {
|
|
51
|
+
oldPassword: string;
|
|
52
|
+
newPassword: string;
|
|
53
|
+
confirmPassword: string;
|
|
54
|
+
};
|
|
55
|
+
output: boolean;
|
|
56
|
+
meta: object;
|
|
57
|
+
}>;
|
|
58
|
+
updateLanguage: import("@trpc/server").TRPCMutationProcedure<{
|
|
59
|
+
input: {
|
|
60
|
+
language: string;
|
|
61
|
+
};
|
|
62
|
+
output: boolean;
|
|
63
|
+
meta: object;
|
|
64
|
+
}>;
|
|
65
|
+
}>>;
|
|
66
|
+
//# sourceMappingURL=accountSettings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accountSettings.d.ts","sourceRoot":"","sources":["../../../../src/api/trpc/routers/accountSettings.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAOxB,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAkBxB;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;GAsML,CAAA"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { privateProcedure, router } from '../trpc.js';
|
|
2
|
+
import { db } from '../../../db/client.js';
|
|
3
|
+
import { AdminsTable } from '../../../db/schema.js';
|
|
4
|
+
import { eq } from 'drizzle-orm';
|
|
5
|
+
import * as z from 'zod';
|
|
6
|
+
import bcrypt from 'bcrypt';
|
|
7
|
+
import { TRPCError } from '@trpc/server';
|
|
8
|
+
import { getRequestMetadataFromHeaders, recordLog } from '../../../logging/index.js';
|
|
9
|
+
import { getCMSConfig } from '../../../core/config/index.js';
|
|
10
|
+
import getString from '../../../translations/index.js';
|
|
11
|
+
export const accountSettings = router({
|
|
12
|
+
get: privateProcedure.query(async ({ ctx }) => {
|
|
13
|
+
const admin = await db
|
|
14
|
+
.select({
|
|
15
|
+
id: AdminsTable.id,
|
|
16
|
+
username: AdminsTable.user,
|
|
17
|
+
emailAddress: AdminsTable.emailAddress,
|
|
18
|
+
fullName: AdminsTable.fullName,
|
|
19
|
+
avatar: AdminsTable.coverphoto,
|
|
20
|
+
phoneNumber: AdminsTable.phoneNumber,
|
|
21
|
+
})
|
|
22
|
+
.from(AdminsTable)
|
|
23
|
+
.where(eq(AdminsTable.id, ctx.session.user.id))
|
|
24
|
+
.limit(1);
|
|
25
|
+
return admin[0];
|
|
26
|
+
}),
|
|
27
|
+
/**
|
|
28
|
+
* No avatar for now, if you want to include it, you have to use the api route,
|
|
29
|
+
* because trpc doesn't support file uploads.
|
|
30
|
+
*/
|
|
31
|
+
save: privateProcedure
|
|
32
|
+
.input(z.object({
|
|
33
|
+
emailAddress: z.string(),
|
|
34
|
+
fullName: z.string(),
|
|
35
|
+
phoneNumber: z.string(),
|
|
36
|
+
}))
|
|
37
|
+
.mutation(async ({ ctx, input }) => {
|
|
38
|
+
const requestMetadata = getRequestMetadataFromHeaders(ctx.headers);
|
|
39
|
+
const existing = await db
|
|
40
|
+
.select({
|
|
41
|
+
emailAddress: AdminsTable.emailAddress,
|
|
42
|
+
fullName: AdminsTable.fullName,
|
|
43
|
+
phoneNumber: AdminsTable.phoneNumber,
|
|
44
|
+
username: AdminsTable.user,
|
|
45
|
+
})
|
|
46
|
+
.from(AdminsTable)
|
|
47
|
+
.where(eq(AdminsTable.id, ctx.session.user.id))
|
|
48
|
+
.limit(1);
|
|
49
|
+
const admin = existing[0];
|
|
50
|
+
if (!admin) {
|
|
51
|
+
throw new TRPCError({
|
|
52
|
+
code: 'NOT_FOUND',
|
|
53
|
+
message: getString('adminNotFound', ctx.session.user.language),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const updates = {};
|
|
57
|
+
const changedFields = [];
|
|
58
|
+
if (admin.emailAddress !== input.emailAddress) {
|
|
59
|
+
updates.emailAddress = input.emailAddress;
|
|
60
|
+
changedFields.push('emailAddress');
|
|
61
|
+
}
|
|
62
|
+
if (admin.fullName !== input.fullName) {
|
|
63
|
+
updates.fullName = input.fullName;
|
|
64
|
+
changedFields.push('fullName');
|
|
65
|
+
}
|
|
66
|
+
if (admin.phoneNumber !== input.phoneNumber) {
|
|
67
|
+
updates.phoneNumber = input.phoneNumber;
|
|
68
|
+
changedFields.push('phoneNumber');
|
|
69
|
+
}
|
|
70
|
+
if (changedFields.length === 0) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
await db
|
|
74
|
+
.update(AdminsTable)
|
|
75
|
+
.set({
|
|
76
|
+
...updates,
|
|
77
|
+
})
|
|
78
|
+
.where(eq(AdminsTable.id, ctx.session.user.id))
|
|
79
|
+
.execute();
|
|
80
|
+
await recordLog({
|
|
81
|
+
eventType: 'admin.settings.change',
|
|
82
|
+
actorId: ctx.session.user.id,
|
|
83
|
+
actorUsername: ctx.session.user.name ?? admin.username ?? null,
|
|
84
|
+
entityType: 'admin',
|
|
85
|
+
entityId: ctx.session.user.id,
|
|
86
|
+
entityLabel: admin.username ?? null,
|
|
87
|
+
sectionName: 'settings',
|
|
88
|
+
metadata: {
|
|
89
|
+
fields: changedFields,
|
|
90
|
+
},
|
|
91
|
+
requestMetadata,
|
|
92
|
+
});
|
|
93
|
+
return true;
|
|
94
|
+
}),
|
|
95
|
+
changePassword: privateProcedure
|
|
96
|
+
.input(z.object({
|
|
97
|
+
oldPassword: z.string(),
|
|
98
|
+
newPassword: z.string(),
|
|
99
|
+
confirmPassword: z.string(),
|
|
100
|
+
}))
|
|
101
|
+
.mutation(async ({ ctx, input }) => {
|
|
102
|
+
const requestMetadata = getRequestMetadataFromHeaders(ctx.headers);
|
|
103
|
+
/**
|
|
104
|
+
* Check if old password is correct
|
|
105
|
+
*/
|
|
106
|
+
const result = await db
|
|
107
|
+
.select({
|
|
108
|
+
password: AdminsTable.pass,
|
|
109
|
+
username: AdminsTable.user,
|
|
110
|
+
})
|
|
111
|
+
.from(AdminsTable)
|
|
112
|
+
.where(eq(AdminsTable.id, ctx.session.user.id))
|
|
113
|
+
.limit(1);
|
|
114
|
+
const admin = result[0];
|
|
115
|
+
/**
|
|
116
|
+
* Check if admin exists
|
|
117
|
+
*/
|
|
118
|
+
if (!admin) {
|
|
119
|
+
throw new TRPCError({
|
|
120
|
+
code: 'NOT_FOUND',
|
|
121
|
+
message: getString('adminNotFound', ctx.session.user.language),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Check password with bcrypt
|
|
126
|
+
*/
|
|
127
|
+
const match = await bcrypt.compare(input.oldPassword, admin.password);
|
|
128
|
+
if (!match) {
|
|
129
|
+
throw new TRPCError({
|
|
130
|
+
code: 'UNAUTHORIZED',
|
|
131
|
+
message: getString('oldPasswordIncorrect', ctx.session.user.language),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Check if new password and confirm password are the same
|
|
136
|
+
*/
|
|
137
|
+
if (input.newPassword !== input.confirmPassword) {
|
|
138
|
+
throw new TRPCError({
|
|
139
|
+
code: 'BAD_REQUEST',
|
|
140
|
+
message: getString('passwordsDoNotMatch', ctx.session.user.language),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Hash new password
|
|
145
|
+
*/
|
|
146
|
+
const hashedPassword = await bcrypt.hash(input.newPassword, 10);
|
|
147
|
+
/**
|
|
148
|
+
* Update password
|
|
149
|
+
*/
|
|
150
|
+
await db
|
|
151
|
+
.update(AdminsTable)
|
|
152
|
+
.set({
|
|
153
|
+
pass: hashedPassword,
|
|
154
|
+
})
|
|
155
|
+
.where(eq(AdminsTable.id, ctx.session.user.id))
|
|
156
|
+
.execute();
|
|
157
|
+
await recordLog({
|
|
158
|
+
eventType: 'admin.settings.change',
|
|
159
|
+
actorId: ctx.session.user.id,
|
|
160
|
+
actorUsername: ctx.session.user.name ?? admin.username ?? null,
|
|
161
|
+
entityType: 'admin',
|
|
162
|
+
entityId: ctx.session.user.id,
|
|
163
|
+
entityLabel: admin.username ?? null,
|
|
164
|
+
sectionName: 'settings',
|
|
165
|
+
metadata: {
|
|
166
|
+
fields: ['password'],
|
|
167
|
+
},
|
|
168
|
+
requestMetadata,
|
|
169
|
+
});
|
|
170
|
+
return true;
|
|
171
|
+
}),
|
|
172
|
+
updateLanguage: privateProcedure.input(z.object({ language: z.string() })).mutation(async ({ ctx, input }) => {
|
|
173
|
+
const requestMetadata = getRequestMetadataFromHeaders(ctx.headers);
|
|
174
|
+
const config = await getCMSConfig();
|
|
175
|
+
const supported = new Set(config.i18n.supportedLanguages);
|
|
176
|
+
if (!supported.has(input.language)) {
|
|
177
|
+
throw new TRPCError({
|
|
178
|
+
code: 'BAD_REQUEST',
|
|
179
|
+
message: getString('languageNotSupported', ctx.session.user.language),
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
await db
|
|
183
|
+
.update(AdminsTable)
|
|
184
|
+
.set({ language: input.language })
|
|
185
|
+
.where(eq(AdminsTable.id, ctx.session.user.id))
|
|
186
|
+
.execute();
|
|
187
|
+
await recordLog({
|
|
188
|
+
eventType: 'admin.settings.change',
|
|
189
|
+
actorId: ctx.session.user.id,
|
|
190
|
+
actorUsername: ctx.session.user.name ?? null,
|
|
191
|
+
entityType: 'admin',
|
|
192
|
+
entityId: ctx.session.user.id,
|
|
193
|
+
entityLabel: ctx.session.user.name ?? null,
|
|
194
|
+
sectionName: 'settings',
|
|
195
|
+
metadata: { fields: ['language'], language: input.language },
|
|
196
|
+
requestMetadata,
|
|
197
|
+
});
|
|
198
|
+
return true;
|
|
199
|
+
}),
|
|
200
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export declare const adminsRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
3
|
+
ctx: {
|
|
4
|
+
headers: Headers;
|
|
5
|
+
db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../../../db/schema.js")> & {
|
|
6
|
+
$client: import("mysql2/promise").Pool;
|
|
7
|
+
};
|
|
8
|
+
session: import("../../../index.js").Session | null;
|
|
9
|
+
};
|
|
10
|
+
meta: object;
|
|
11
|
+
errorShape: {
|
|
12
|
+
data: {
|
|
13
|
+
zodError: z.core.$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
|
+
list: import("@trpc/server").TRPCQueryProcedure<{
|
|
25
|
+
input: void;
|
|
26
|
+
output: {
|
|
27
|
+
error: {
|
|
28
|
+
message: string;
|
|
29
|
+
};
|
|
30
|
+
admins?: undefined;
|
|
31
|
+
privileges?: undefined;
|
|
32
|
+
} | {
|
|
33
|
+
admins: {
|
|
34
|
+
id: string;
|
|
35
|
+
username: string;
|
|
36
|
+
avatar: string | null;
|
|
37
|
+
roles: {
|
|
38
|
+
operations: "C" | "U" | "D" | "CU" | "CD" | "UD" | "CUD";
|
|
39
|
+
publisher: boolean | null;
|
|
40
|
+
sectionName: string;
|
|
41
|
+
}[];
|
|
42
|
+
}[];
|
|
43
|
+
privileges: {
|
|
44
|
+
title: string;
|
|
45
|
+
order: number;
|
|
46
|
+
sectionType: string;
|
|
47
|
+
sectionName: string;
|
|
48
|
+
}[];
|
|
49
|
+
error?: undefined;
|
|
50
|
+
};
|
|
51
|
+
meta: object;
|
|
52
|
+
}>;
|
|
53
|
+
get: import("@trpc/server").TRPCQueryProcedure<{
|
|
54
|
+
input: string;
|
|
55
|
+
output: {
|
|
56
|
+
admin: {
|
|
57
|
+
id: string;
|
|
58
|
+
user: string;
|
|
59
|
+
};
|
|
60
|
+
adminRoles: {
|
|
61
|
+
sectionName: string;
|
|
62
|
+
operations: "C" | "U" | "D" | "CU" | "CD" | "UD" | "CUD";
|
|
63
|
+
publisher: boolean | null;
|
|
64
|
+
}[];
|
|
65
|
+
allRoles: {
|
|
66
|
+
title: string;
|
|
67
|
+
order: number;
|
|
68
|
+
sectionType: string;
|
|
69
|
+
sectionName: string;
|
|
70
|
+
}[];
|
|
71
|
+
};
|
|
72
|
+
meta: object;
|
|
73
|
+
}>;
|
|
74
|
+
create: import("@trpc/server").TRPCMutationProcedure<{
|
|
75
|
+
input: {
|
|
76
|
+
username: string;
|
|
77
|
+
password: string;
|
|
78
|
+
privileges: {
|
|
79
|
+
sectionName: string;
|
|
80
|
+
publisher: boolean | null;
|
|
81
|
+
operations: string;
|
|
82
|
+
}[];
|
|
83
|
+
};
|
|
84
|
+
output: {
|
|
85
|
+
status: string;
|
|
86
|
+
id: string;
|
|
87
|
+
};
|
|
88
|
+
meta: object;
|
|
89
|
+
}>;
|
|
90
|
+
update: import("@trpc/server").TRPCMutationProcedure<{
|
|
91
|
+
input: {
|
|
92
|
+
id: string;
|
|
93
|
+
privileges: {
|
|
94
|
+
sectionName: string;
|
|
95
|
+
publisher: boolean | null;
|
|
96
|
+
operations: string;
|
|
97
|
+
}[];
|
|
98
|
+
};
|
|
99
|
+
output: {
|
|
100
|
+
status: string;
|
|
101
|
+
};
|
|
102
|
+
meta: object;
|
|
103
|
+
}>;
|
|
104
|
+
remove: import("@trpc/server").TRPCMutationProcedure<{
|
|
105
|
+
input: {
|
|
106
|
+
id: string;
|
|
107
|
+
};
|
|
108
|
+
output: boolean;
|
|
109
|
+
meta: object;
|
|
110
|
+
}>;
|
|
111
|
+
}>>;
|
|
112
|
+
//# sourceMappingURL=admins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admins.d.ts","sourceRoot":"","sources":["../../../../src/api/trpc/routers/admins.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAcxB,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmWvB,CAAA"}
|