nextjs-cms 0.9.38 → 0.9.39
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/api/actions/pages.d.ts +27 -7
- package/dist/api/actions/pages.d.ts.map +1 -1
- package/dist/api/actions/pages.js +111 -27
- package/dist/api/trpc/root.d.ts +27 -6
- package/dist/api/trpc/root.d.ts.map +1 -1
- package/dist/api/trpc/routers/hasItemsSection.d.ts +23 -2
- package/dist/api/trpc/routers/hasItemsSection.d.ts.map +1 -1
- package/dist/api/trpc/routers/hasItemsSection.js +2 -1
- package/dist/api/trpc/routers/navigation.d.ts +3 -3
- package/dist/api/trpc/routers/simpleSection.d.ts +1 -1
- package/dist/api/trpc/server.d.ts +81 -18
- package/dist/api/trpc/server.d.ts.map +1 -1
- package/dist/core/config/config-loader.d.ts +2 -2
- package/dist/core/factories/FieldFactory.d.ts +1 -6
- package/dist/core/factories/FieldFactory.d.ts.map +1 -1
- package/dist/core/factories/FieldFactory.js +3 -68
- package/dist/core/fields/checkbox.d.ts +3 -3
- package/dist/core/fields/color.d.ts +3 -3
- package/dist/core/fields/date-range.d.ts +2 -2
- package/dist/core/fields/date.d.ts +3 -3
- package/dist/core/fields/document.d.ts +3 -3
- package/dist/core/fields/field.d.ts +25 -12
- package/dist/core/fields/field.d.ts.map +1 -1
- package/dist/core/fields/field.js +51 -23
- package/dist/core/fields/index.d.ts +1 -0
- package/dist/core/fields/index.d.ts.map +1 -1
- package/dist/core/fields/index.js +2 -0
- package/dist/core/fields/map.d.ts +3 -3
- package/dist/core/fields/number.d.ts +4 -4
- package/dist/core/fields/password.d.ts +3 -3
- package/dist/core/fields/photo.d.ts +9 -9
- package/dist/core/fields/richText.d.ts +12 -12
- package/dist/core/fields/select.d.ts +7 -7
- package/dist/core/fields/selectMultiple.d.ts +4 -4
- package/dist/core/fields/slug.d.ts +9 -9
- package/dist/core/fields/tags.d.ts +3 -3
- package/dist/core/fields/text.d.ts +2 -2
- package/dist/core/fields/textArea.d.ts +2 -2
- package/dist/core/fields/video.d.ts +3 -3
- package/dist/core/helpers/conditional-rules.d.ts +63 -0
- package/dist/core/helpers/conditional-rules.d.ts.map +1 -0
- package/dist/core/helpers/conditional-rules.js +113 -0
- package/dist/core/helpers/index.d.ts +1 -0
- package/dist/core/helpers/index.d.ts.map +1 -1
- package/dist/core/helpers/index.js +4 -0
- package/dist/core/sections/category.d.ts +50 -50
- package/dist/core/sections/hasItems.d.ts +74 -74
- package/dist/core/sections/section.d.ts +23 -23
- package/dist/core/sections/simple.d.ts +6 -6
- package/dist/core/submit/submit.d.ts +4 -1
- package/dist/core/submit/submit.d.ts.map +1 -1
- package/dist/core/submit/submit.js +9 -19
- package/dist/core/types/index.d.ts +30 -8
- package/dist/core/types/index.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/translations/client.d.ts +4 -4
- package/dist/translations/server.d.ts +4 -4
- package/package.json +3 -3
- package/dist/api/axios/axiosInstance.d.ts +0 -2
- package/dist/api/axios/axiosInstance.d.ts.map +0 -1
- package/dist/api/axios/axiosInstance.js +0 -8
- package/dist/api/index.d.ts +0 -975
- package/dist/api/index.d.ts.map +0 -1
- package/dist/api/index.js +0 -13
- package/dist/api/lib/serverActions.d.ts +0 -374
- package/dist/api/lib/serverActions.d.ts.map +0 -1
- package/dist/api/lib/serverActions.js +0 -1445
- package/dist/api/root.d.ts +0 -1917
- package/dist/api/root.d.ts.map +0 -1
- package/dist/api/root.js +0 -115
- package/dist/api/routers/accountSettings.d.ts +0 -66
- package/dist/api/routers/accountSettings.d.ts.map +0 -1
- package/dist/api/routers/accountSettings.js +0 -202
- package/dist/api/routers/admins.d.ts +0 -112
- package/dist/api/routers/admins.d.ts.map +0 -1
- package/dist/api/routers/admins.js +0 -323
- package/dist/api/routers/auth.d.ts +0 -54
- package/dist/api/routers/auth.d.ts.map +0 -1
- package/dist/api/routers/auth.js +0 -50
- package/dist/api/routers/categorySection.d.ts +0 -105
- package/dist/api/routers/categorySection.d.ts.map +0 -1
- package/dist/api/routers/categorySection.js +0 -49
- package/dist/api/routers/config.d.ts +0 -48
- package/dist/api/routers/config.d.ts.map +0 -1
- package/dist/api/routers/config.js +0 -18
- package/dist/api/routers/cpanel.d.ts +0 -82
- package/dist/api/routers/cpanel.d.ts.map +0 -1
- package/dist/api/routers/cpanel.js +0 -216
- package/dist/api/routers/fields.d.ts +0 -35
- package/dist/api/routers/fields.d.ts.map +0 -1
- package/dist/api/routers/fields.js +0 -81
- package/dist/api/routers/files.d.ts +0 -34
- package/dist/api/routers/files.d.ts.map +0 -1
- package/dist/api/routers/files.js +0 -14
- package/dist/api/routers/gallery.d.ts +0 -34
- package/dist/api/routers/gallery.d.ts.map +0 -1
- package/dist/api/routers/gallery.js +0 -64
- package/dist/api/routers/hasItemsSection.d.ts +0 -219
- package/dist/api/routers/hasItemsSection.d.ts.map +0 -1
- package/dist/api/routers/hasItemsSection.js +0 -86
- package/dist/api/routers/logs.d.ts +0 -59
- package/dist/api/routers/logs.d.ts.map +0 -1
- package/dist/api/routers/logs.js +0 -76
- package/dist/api/routers/navigation.d.ts +0 -50
- package/dist/api/routers/navigation.d.ts.map +0 -1
- package/dist/api/routers/navigation.js +0 -11
- package/dist/api/routers/simpleSection.d.ts +0 -105
- package/dist/api/routers/simpleSection.d.ts.map +0 -1
- package/dist/api/routers/simpleSection.js +0 -54
- package/dist/api/trpc.d.ts +0 -111
- package/dist/api/trpc.d.ts.map +0 -1
- package/dist/api/trpc.js +0 -99
- package/dist/auth/axios/axiosInstance.d.ts +0 -2
- package/dist/auth/axios/axiosInstance.d.ts.map +0 -1
- package/dist/auth/axios/axiosInstance.js +0 -8
- package/dist/auth/hooks/useAxiosPrivate.d.ts +0 -5
- package/dist/auth/hooks/useAxiosPrivate.d.ts.map +0 -1
- package/dist/auth/hooks/useAxiosPrivate.js +0 -74
- package/dist/auth/trpc.d.ts +0 -6
- package/dist/auth/trpc.d.ts.map +0 -1
- package/dist/auth/trpc.js +0 -82
- package/dist/core/fields/dateRange.d.ts +0 -115
- package/dist/core/fields/dateRange.d.ts.map +0 -1
- package/dist/core/fields/dateRange.js +0 -149
- package/dist/translations/locale-cookie.d.ts +0 -24
- package/dist/translations/locale-cookie.d.ts.map +0 -1
- package/dist/translations/locale-cookie.js +0 -44
- package/dist/translations/locale-utils.d.ts +0 -8
- package/dist/translations/locale-utils.d.ts.map +0 -1
- package/dist/translations/locale-utils.js +0 -11
- package/dist/translations/localization.d.ts +0 -40
- package/dist/translations/localization.d.ts.map +0 -1
- package/dist/translations/localization.js +0 -48
- package/dist/validators/dateRange.d.ts +0 -11
- package/dist/validators/dateRange.d.ts.map +0 -1
- package/dist/validators/dateRange.js +0 -16
package/dist/api/root.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../../src/api/root.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAgB5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AA8FvB,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAwB6gQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAAi/+B,CAAC;;;;;2BAAyE,CAAC;;;;;;2BAA8G,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAA7i6B,CAAC;;;;;2BAAsE,CAAC;;;;;;2BAA2G,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAxB1yV,CAAA;AAU5C,wBAAsB,YAAY;;;;;;;;;;;;;;;;;;;;;4GAEjC;AAED,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,WAAW,4LAG7D;AAGD,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAA;AAGxC,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAC0gQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAAi/+B,CAAC;;;;;2BAAyE,CAAC;;;;;;2BAA8G,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAA7i6B,CAAC;;;;;2BAAsE,CAAC;;;;;;2BAA2G,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAD5xV,CAAA"}
|
package/dist/api/root.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { createCallerFactory, 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 { getConfigImportVersion } from '../core/config/index.js';
|
|
15
|
-
import { getPluginRoutes, loadPlugins } from '../plugins/loader.js';
|
|
16
|
-
import { z } from 'zod';
|
|
17
|
-
import { getAdminPrivileges } from './lib/serverActions.js';
|
|
18
|
-
async function getPluginRouters() {
|
|
19
|
-
const loadedPlugins = await loadPlugins();
|
|
20
|
-
return loadedPlugins.reduce((acc, current) => {
|
|
21
|
-
if (current.plugin.router) {
|
|
22
|
-
acc[current.routerKey] = current.plugin.router;
|
|
23
|
-
}
|
|
24
|
-
return acc;
|
|
25
|
-
}, {});
|
|
26
|
-
}
|
|
27
|
-
const pluginsRouter = router({
|
|
28
|
-
checkRoute: privateProcedure
|
|
29
|
-
.input(z.object({
|
|
30
|
-
path: z.string(),
|
|
31
|
-
}))
|
|
32
|
-
.query(async ({ ctx, input }) => {
|
|
33
|
-
const routes = await getPluginRoutes();
|
|
34
|
-
const privilegeSet = await getAdminPrivileges(ctx.session.user.id);
|
|
35
|
-
const filteredRoutes = routes.filter(({ pluginName }) => privilegeSet.has(pluginName));
|
|
36
|
-
const plugin = filteredRoutes.find(({ path }) => path === input.path);
|
|
37
|
-
if (!plugin) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
return plugin;
|
|
41
|
-
}),
|
|
42
|
-
});
|
|
43
|
-
const coreRouters = {
|
|
44
|
-
auth: authRouter,
|
|
45
|
-
admins: adminsRouter,
|
|
46
|
-
config: configRouter,
|
|
47
|
-
hasItemsSections: hasItemsSectionRouter,
|
|
48
|
-
simpleSections: simpleSectionRouter,
|
|
49
|
-
categorySections: categorySectionRouter,
|
|
50
|
-
files: filesRouter,
|
|
51
|
-
gallery: galleryRouter,
|
|
52
|
-
navigation: navRouter,
|
|
53
|
-
accountSettings: accountSettings,
|
|
54
|
-
fields: fieldsRouter,
|
|
55
|
-
logs: logsRouter,
|
|
56
|
-
plugins: pluginsRouter,
|
|
57
|
-
};
|
|
58
|
-
// Lazy router creation - cache the result
|
|
59
|
-
let _appRouter = null;
|
|
60
|
-
let routerInitPromise = null;
|
|
61
|
-
let appRouterConfigVersion = -1;
|
|
62
|
-
async function createAppRouterWithPlugins() {
|
|
63
|
-
const currentVersion = getConfigImportVersion();
|
|
64
|
-
if (appRouterConfigVersion !== currentVersion) {
|
|
65
|
-
_appRouter = null;
|
|
66
|
-
routerInitPromise = null;
|
|
67
|
-
}
|
|
68
|
-
if (_appRouter) {
|
|
69
|
-
return _appRouter;
|
|
70
|
-
}
|
|
71
|
-
if (routerInitPromise) {
|
|
72
|
-
return routerInitPromise;
|
|
73
|
-
}
|
|
74
|
-
routerInitPromise = (async () => {
|
|
75
|
-
const pluginRouters = await getPluginRouters();
|
|
76
|
-
const safePluginRouters = Object.entries(pluginRouters).reduce((acc, [key, pluginRouter]) => {
|
|
77
|
-
if (key in coreRouters) {
|
|
78
|
-
console.error(`[plugins] Router key "${key}" conflicts with a core router. Skipping.`);
|
|
79
|
-
return acc;
|
|
80
|
-
}
|
|
81
|
-
acc[key] = pluginRouter;
|
|
82
|
-
return acc;
|
|
83
|
-
}, {});
|
|
84
|
-
const routerInstance = router({
|
|
85
|
-
...coreRouters,
|
|
86
|
-
...safePluginRouters,
|
|
87
|
-
});
|
|
88
|
-
_appRouter = routerInstance;
|
|
89
|
-
appRouterConfigVersion = currentVersion;
|
|
90
|
-
return routerInstance;
|
|
91
|
-
})();
|
|
92
|
-
return routerInitPromise;
|
|
93
|
-
}
|
|
94
|
-
// Create router synchronously with core routes only
|
|
95
|
-
// This allows the module to load without top-level await
|
|
96
|
-
// NOTE: Plugin routes will not be available until plugins are loaded
|
|
97
|
-
// For now, we export the core router. Plugin routes should be added
|
|
98
|
-
// via the plugins router's list/routes procedures
|
|
99
|
-
export const appRouter = router(coreRouters);
|
|
100
|
-
// Start loading plugins in the background (non-blocking)
|
|
101
|
-
// Plugin routes can be accessed through the plugins.list/routes procedures
|
|
102
|
-
createAppRouterWithPlugins().catch((error) => {
|
|
103
|
-
console.error('Failed to load plugins for router:', error);
|
|
104
|
-
});
|
|
105
|
-
// Export a function to get the full router with plugins
|
|
106
|
-
// This should be used in server contexts where async is allowed
|
|
107
|
-
export async function getAppRouter() {
|
|
108
|
-
return createAppRouterWithPlugins();
|
|
109
|
-
}
|
|
110
|
-
export async function createCallerWithPlugins(ctx) {
|
|
111
|
-
const routerWithPlugins = await getAppRouter();
|
|
112
|
-
return routerWithPlugins.createCaller(ctx);
|
|
113
|
-
}
|
|
114
|
-
// createCaller factory
|
|
115
|
-
export const createCaller = createCallerFactory(appRouter);
|
|
@@ -1,66 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"accountSettings.d.ts","sourceRoot":"","sources":["../../../src/api/routers/accountSettings.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAOxB,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAkBxB;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;GAwML,CAAA"}
|
|
@@ -1,202 +0,0 @@
|
|
|
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
|
|
173
|
-
.input(z.object({ language: z.string() }))
|
|
174
|
-
.mutation(async ({ ctx, input }) => {
|
|
175
|
-
const requestMetadata = getRequestMetadataFromHeaders(ctx.headers);
|
|
176
|
-
const config = await getCMSConfig();
|
|
177
|
-
const supported = new Set(config.i18n.supportedLanguages);
|
|
178
|
-
if (!supported.has(input.language)) {
|
|
179
|
-
throw new TRPCError({
|
|
180
|
-
code: 'BAD_REQUEST',
|
|
181
|
-
message: getString('languageNotSupported', ctx.session.user.language),
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
await db
|
|
185
|
-
.update(AdminsTable)
|
|
186
|
-
.set({ language: input.language })
|
|
187
|
-
.where(eq(AdminsTable.id, ctx.session.user.id))
|
|
188
|
-
.execute();
|
|
189
|
-
await recordLog({
|
|
190
|
-
eventType: 'admin.settings.change',
|
|
191
|
-
actorId: ctx.session.user.id,
|
|
192
|
-
actorUsername: ctx.session.user.name ?? null,
|
|
193
|
-
entityType: 'admin',
|
|
194
|
-
entityId: ctx.session.user.id,
|
|
195
|
-
entityLabel: ctx.session.user.name ?? null,
|
|
196
|
-
sectionName: 'settings',
|
|
197
|
-
metadata: { fields: ['language'], language: input.language },
|
|
198
|
-
requestMetadata,
|
|
199
|
-
});
|
|
200
|
-
return true;
|
|
201
|
-
}),
|
|
202
|
-
});
|
|
@@ -1,112 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"admins.d.ts","sourceRoot":"","sources":["../../../src/api/routers/admins.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAcxB,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0VvB,CAAA"}
|