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,194 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export declare const hasItemsSectionRouter: 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
|
+
listItems: import("@trpc/server").TRPCQueryProcedure<{
|
|
25
|
+
input: {
|
|
26
|
+
sectionName: string;
|
|
27
|
+
page?: number | undefined;
|
|
28
|
+
q?: string | undefined;
|
|
29
|
+
};
|
|
30
|
+
output: {
|
|
31
|
+
error: {
|
|
32
|
+
message: string;
|
|
33
|
+
};
|
|
34
|
+
section?: undefined;
|
|
35
|
+
items?: undefined;
|
|
36
|
+
totalCount?: undefined;
|
|
37
|
+
} | {
|
|
38
|
+
section: {
|
|
39
|
+
hasSearch: boolean;
|
|
40
|
+
name: string;
|
|
41
|
+
title: string;
|
|
42
|
+
};
|
|
43
|
+
items: (Record<string, any> | {
|
|
44
|
+
id: string | number;
|
|
45
|
+
headingTitle: string;
|
|
46
|
+
coverPhoto: string | null;
|
|
47
|
+
createdAt: string;
|
|
48
|
+
createdBy: string;
|
|
49
|
+
permission: number;
|
|
50
|
+
})[];
|
|
51
|
+
totalCount: any;
|
|
52
|
+
error?: undefined;
|
|
53
|
+
};
|
|
54
|
+
meta: object;
|
|
55
|
+
}>;
|
|
56
|
+
newItem: import("@trpc/server").TRPCQueryProcedure<{
|
|
57
|
+
input: {
|
|
58
|
+
sectionName: string;
|
|
59
|
+
};
|
|
60
|
+
output: {
|
|
61
|
+
error: {
|
|
62
|
+
message: any;
|
|
63
|
+
};
|
|
64
|
+
section?: undefined;
|
|
65
|
+
inputGroups?: undefined;
|
|
66
|
+
defaultLocale?: undefined;
|
|
67
|
+
} | {
|
|
68
|
+
section: {
|
|
69
|
+
name: string;
|
|
70
|
+
title: {
|
|
71
|
+
section: string;
|
|
72
|
+
singular: string;
|
|
73
|
+
plural: string;
|
|
74
|
+
};
|
|
75
|
+
gallery: import("../../../index.js").SectionGallery | undefined;
|
|
76
|
+
variants: import("../../../core/types/index.js").Variant[] | undefined;
|
|
77
|
+
configFile: string;
|
|
78
|
+
};
|
|
79
|
+
inputGroups: {
|
|
80
|
+
groupId: number;
|
|
81
|
+
groupTitle: string;
|
|
82
|
+
groupOrder: number;
|
|
83
|
+
inputs: {
|
|
84
|
+
type: import("../../../core/types/index.js").FieldType;
|
|
85
|
+
name: string;
|
|
86
|
+
label: string;
|
|
87
|
+
required: boolean;
|
|
88
|
+
localized?: boolean;
|
|
89
|
+
conditionalFields: import("../../../core/types/index.js").ConditionalField[];
|
|
90
|
+
readonly: boolean;
|
|
91
|
+
defaultValue: any;
|
|
92
|
+
value: any;
|
|
93
|
+
}[];
|
|
94
|
+
}[] | undefined;
|
|
95
|
+
defaultLocale: {
|
|
96
|
+
code: string;
|
|
97
|
+
label: string;
|
|
98
|
+
rtl?: boolean;
|
|
99
|
+
} | null;
|
|
100
|
+
error?: undefined;
|
|
101
|
+
};
|
|
102
|
+
meta: object;
|
|
103
|
+
}>;
|
|
104
|
+
editItem: import("@trpc/server").TRPCQueryProcedure<{
|
|
105
|
+
input: {
|
|
106
|
+
sectionName: string;
|
|
107
|
+
sectionItemId: string | number;
|
|
108
|
+
locale?: string | undefined;
|
|
109
|
+
};
|
|
110
|
+
output: {
|
|
111
|
+
section: {
|
|
112
|
+
name: string;
|
|
113
|
+
title: {
|
|
114
|
+
section: string;
|
|
115
|
+
singular: string;
|
|
116
|
+
plural: string;
|
|
117
|
+
};
|
|
118
|
+
gallery: import("../../../index.js").SectionGallery | undefined;
|
|
119
|
+
variants: import("../../../core/types/index.js").Variant[] | undefined;
|
|
120
|
+
configFile: string;
|
|
121
|
+
};
|
|
122
|
+
inputGroups: {
|
|
123
|
+
groupId: number;
|
|
124
|
+
groupTitle: string;
|
|
125
|
+
groupOrder: number;
|
|
126
|
+
inputs: {
|
|
127
|
+
type: import("../../../core/types/index.js").FieldType;
|
|
128
|
+
name: string;
|
|
129
|
+
label: string;
|
|
130
|
+
required: boolean;
|
|
131
|
+
localized?: boolean;
|
|
132
|
+
conditionalFields: import("../../../core/types/index.js").ConditionalField[];
|
|
133
|
+
readonly: boolean;
|
|
134
|
+
defaultValue: any;
|
|
135
|
+
value: any;
|
|
136
|
+
}[];
|
|
137
|
+
}[] | undefined;
|
|
138
|
+
gallery: {
|
|
139
|
+
referenceId: string;
|
|
140
|
+
photo: string;
|
|
141
|
+
meta: any;
|
|
142
|
+
locale?: string;
|
|
143
|
+
}[];
|
|
144
|
+
localization: {
|
|
145
|
+
defaultLocale: {
|
|
146
|
+
code: string;
|
|
147
|
+
label: string;
|
|
148
|
+
rtl?: boolean;
|
|
149
|
+
};
|
|
150
|
+
currentLocale: {
|
|
151
|
+
code: string;
|
|
152
|
+
label: string;
|
|
153
|
+
rtl?: boolean;
|
|
154
|
+
};
|
|
155
|
+
existingTranslations: string[];
|
|
156
|
+
locales: {
|
|
157
|
+
code: string;
|
|
158
|
+
label: string;
|
|
159
|
+
rtl?: boolean;
|
|
160
|
+
}[];
|
|
161
|
+
localeSwitcherEnabled: boolean;
|
|
162
|
+
developerNoteEnabled: boolean;
|
|
163
|
+
} | null;
|
|
164
|
+
error?: undefined;
|
|
165
|
+
} | {
|
|
166
|
+
error: {
|
|
167
|
+
message: any;
|
|
168
|
+
};
|
|
169
|
+
section?: undefined;
|
|
170
|
+
inputGroups?: undefined;
|
|
171
|
+
gallery?: undefined;
|
|
172
|
+
localization?: undefined;
|
|
173
|
+
};
|
|
174
|
+
meta: object;
|
|
175
|
+
}>;
|
|
176
|
+
deleteItem: import("@trpc/server").TRPCMutationProcedure<{
|
|
177
|
+
input: {
|
|
178
|
+
sectionName: string;
|
|
179
|
+
sectionItemId: string | number;
|
|
180
|
+
};
|
|
181
|
+
output: boolean;
|
|
182
|
+
meta: object;
|
|
183
|
+
}>;
|
|
184
|
+
deleteLocaleTranslation: import("@trpc/server").TRPCMutationProcedure<{
|
|
185
|
+
input: {
|
|
186
|
+
sectionName: string;
|
|
187
|
+
sectionItemId: string | number;
|
|
188
|
+
locale: string;
|
|
189
|
+
};
|
|
190
|
+
output: boolean;
|
|
191
|
+
meta: object;
|
|
192
|
+
}>;
|
|
193
|
+
}>>;
|
|
194
|
+
//# sourceMappingURL=hasItemsSection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasItemsSection.d.ts","sourceRoot":"","sources":["../../../../src/api/trpc/routers/hasItemsSection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAcxB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAwGq1hC,CAAC;;;;;uBAA0E,CAAC;;;;;;uBAAgH,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GADljiC,CAAA"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { privateProcedure, router } from '../trpc.js';
|
|
2
|
+
import * as z from 'zod';
|
|
3
|
+
import { createEditPage, createNewPage, deleteLocaleTranslation, deleteSectionItem, getBrowsePage, } from '../../actions/pages.js';
|
|
4
|
+
import { getRequestMetadataFromHeaders } from '../../../logging/index.js';
|
|
5
|
+
import { TRPCError } from '@trpc/server';
|
|
6
|
+
import { getCMSConfig } from '../../../core/config/index.js';
|
|
7
|
+
import { resolveLocale } from '../../../core/localization/index.js';
|
|
8
|
+
import getString from '../../../translations/index.js';
|
|
9
|
+
export const hasItemsSectionRouter = router({
|
|
10
|
+
listItems: privateProcedure
|
|
11
|
+
.input(z.object({
|
|
12
|
+
sectionName: z.string(),
|
|
13
|
+
page: z.number().optional(),
|
|
14
|
+
q: z.string().optional(),
|
|
15
|
+
}))
|
|
16
|
+
.query(async ({ ctx, input }) => {
|
|
17
|
+
return await getBrowsePage(ctx.session, input.sectionName, input.page, input.q);
|
|
18
|
+
}),
|
|
19
|
+
newItem: privateProcedure
|
|
20
|
+
.input(z.object({
|
|
21
|
+
sectionName: z.string(),
|
|
22
|
+
}))
|
|
23
|
+
.query(async ({ ctx, input }) => {
|
|
24
|
+
return await createNewPage(ctx.session, input.sectionName);
|
|
25
|
+
}),
|
|
26
|
+
editItem: privateProcedure
|
|
27
|
+
.input(z.object({
|
|
28
|
+
sectionName: z.string(),
|
|
29
|
+
sectionItemId: z.number().or(z.string()),
|
|
30
|
+
locale: z.string().optional(),
|
|
31
|
+
}))
|
|
32
|
+
.query(async ({ ctx, input }) => {
|
|
33
|
+
return await createEditPage(ctx.session, input.sectionName, input.sectionItemId, input.locale);
|
|
34
|
+
}),
|
|
35
|
+
deleteItem: privateProcedure
|
|
36
|
+
.input(z.object({ sectionName: z.string(), sectionItemId: z.number().or(z.string()) }))
|
|
37
|
+
.mutation(async ({ ctx, input }) => {
|
|
38
|
+
const requestMetadata = getRequestMetadataFromHeaders(ctx.headers);
|
|
39
|
+
const result = await deleteSectionItem(ctx.session, input.sectionName, input.sectionItemId, undefined, requestMetadata);
|
|
40
|
+
if (result && typeof result === 'object' && 'error' in result) {
|
|
41
|
+
const message = result.error?.message ?? 'Failed to delete section item';
|
|
42
|
+
throw new TRPCError({
|
|
43
|
+
code: 'BAD_REQUEST',
|
|
44
|
+
message,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}),
|
|
49
|
+
deleteLocaleTranslation: privateProcedure
|
|
50
|
+
.input(z.object({
|
|
51
|
+
sectionName: z.string(),
|
|
52
|
+
sectionItemId: z.number().or(z.string()),
|
|
53
|
+
locale: z.string(),
|
|
54
|
+
}))
|
|
55
|
+
.mutation(async ({ ctx, input }) => {
|
|
56
|
+
const cmsConfig = await getCMSConfig();
|
|
57
|
+
const localeResult = resolveLocale({
|
|
58
|
+
localization: cmsConfig.localization,
|
|
59
|
+
locale: input.locale,
|
|
60
|
+
});
|
|
61
|
+
if (!localeResult.resolvedLocale) {
|
|
62
|
+
if (localeResult.localizationEnabled === false) {
|
|
63
|
+
throw new TRPCError({
|
|
64
|
+
code: 'BAD_REQUEST',
|
|
65
|
+
message: getString('localizationNotEnabledForSection', ctx.session.user.language),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
throw new TRPCError({
|
|
69
|
+
code: 'BAD_REQUEST',
|
|
70
|
+
message: getString('invalidLocale', ctx.session.user.language, {
|
|
71
|
+
locale: input.locale,
|
|
72
|
+
locales: localeResult.availableLocales.map((l) => l.code).join(', '),
|
|
73
|
+
}),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const result = await deleteLocaleTranslation(ctx.session, input.sectionName, input.sectionItemId, localeResult.resolvedLocale.code);
|
|
77
|
+
if (result && typeof result === 'object' && 'error' in result) {
|
|
78
|
+
const message = result.error?.message ?? 'Failed to delete locale translation';
|
|
79
|
+
throw new TRPCError({
|
|
80
|
+
code: 'BAD_REQUEST',
|
|
81
|
+
message,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}),
|
|
86
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export declare const logsRouter: 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: {
|
|
26
|
+
limit?: number | undefined;
|
|
27
|
+
offset?: number | undefined;
|
|
28
|
+
eventType?: string | undefined;
|
|
29
|
+
actorId?: string | undefined;
|
|
30
|
+
sectionName?: string | undefined;
|
|
31
|
+
entityType?: string | undefined;
|
|
32
|
+
entityId?: string | undefined;
|
|
33
|
+
from?: string | undefined;
|
|
34
|
+
to?: string | undefined;
|
|
35
|
+
} | undefined;
|
|
36
|
+
output: {
|
|
37
|
+
items: {
|
|
38
|
+
id: number;
|
|
39
|
+
eventType: string;
|
|
40
|
+
actorId: string | null;
|
|
41
|
+
actorUsername: string | null;
|
|
42
|
+
entityType: string | null;
|
|
43
|
+
entityId: string | null;
|
|
44
|
+
entityLabel: string | null;
|
|
45
|
+
sectionName: string | null;
|
|
46
|
+
metadata: string | null;
|
|
47
|
+
ipAddress: string | null;
|
|
48
|
+
userAgent: string | null;
|
|
49
|
+
source: string | null;
|
|
50
|
+
createdAt: Date;
|
|
51
|
+
}[];
|
|
52
|
+
total: number;
|
|
53
|
+
limit: number;
|
|
54
|
+
offset: number;
|
|
55
|
+
};
|
|
56
|
+
meta: object;
|
|
57
|
+
}>;
|
|
58
|
+
}>>;
|
|
59
|
+
//# sourceMappingURL=logs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../../../src/api/trpc/routers/logs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAqBxB,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiErB,CAAA"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { TRPCError } from '@trpc/server';
|
|
2
|
+
import { and, desc, eq, gte, lte, sql } from 'drizzle-orm';
|
|
3
|
+
import * as z from 'zod';
|
|
4
|
+
import { db } from '../../../db/client.js';
|
|
5
|
+
import { LogsTable } from '../../../db/schema.js';
|
|
6
|
+
import { isAccessAllowed } from '../../actions/privileges.js';
|
|
7
|
+
import { privateProcedure, router } from '../trpc.js';
|
|
8
|
+
import getString from '../../../translations/index.js';
|
|
9
|
+
const listInputSchema = z
|
|
10
|
+
.object({
|
|
11
|
+
limit: z.number().min(1).max(200).optional(),
|
|
12
|
+
offset: z.number().min(0).optional(),
|
|
13
|
+
eventType: z.string().optional(),
|
|
14
|
+
actorId: z.string().optional(),
|
|
15
|
+
sectionName: z.string().optional(),
|
|
16
|
+
entityType: z.string().optional(),
|
|
17
|
+
entityId: z.string().optional(),
|
|
18
|
+
from: z.string().datetime().optional(),
|
|
19
|
+
to: z.string().datetime().optional(),
|
|
20
|
+
})
|
|
21
|
+
.optional();
|
|
22
|
+
export const logsRouter = router({
|
|
23
|
+
list: privateProcedure.input(listInputSchema).query(async ({ ctx, input }) => {
|
|
24
|
+
const accessAllowed = await isAccessAllowed({
|
|
25
|
+
sectionName: 'log',
|
|
26
|
+
userId: ctx.session.user.id,
|
|
27
|
+
});
|
|
28
|
+
if (!accessAllowed) {
|
|
29
|
+
throw new TRPCError({
|
|
30
|
+
code: 'NOT_FOUND',
|
|
31
|
+
message: getString('sectionNotFound', ctx.session.user.language),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const limit = input?.limit ?? 50;
|
|
35
|
+
const offset = input?.offset ?? 0;
|
|
36
|
+
const conditions = [];
|
|
37
|
+
if (input?.eventType) {
|
|
38
|
+
conditions.push(eq(LogsTable.eventType, input.eventType));
|
|
39
|
+
}
|
|
40
|
+
if (input?.actorId) {
|
|
41
|
+
conditions.push(eq(LogsTable.actorId, input.actorId));
|
|
42
|
+
}
|
|
43
|
+
if (input?.sectionName) {
|
|
44
|
+
conditions.push(eq(LogsTable.sectionName, input.sectionName));
|
|
45
|
+
}
|
|
46
|
+
if (input?.entityType) {
|
|
47
|
+
conditions.push(eq(LogsTable.entityType, input.entityType));
|
|
48
|
+
}
|
|
49
|
+
if (input?.entityId) {
|
|
50
|
+
conditions.push(eq(LogsTable.entityId, input.entityId));
|
|
51
|
+
}
|
|
52
|
+
if (input?.from) {
|
|
53
|
+
conditions.push(gte(LogsTable.createdAt, new Date(input.from)));
|
|
54
|
+
}
|
|
55
|
+
if (input?.to) {
|
|
56
|
+
conditions.push(lte(LogsTable.createdAt, new Date(input.to)));
|
|
57
|
+
}
|
|
58
|
+
const whereClause = conditions.length > 0 ? and(...conditions) : undefined;
|
|
59
|
+
let listQuery = db.select().from(LogsTable).$dynamic();
|
|
60
|
+
let countQuery = db
|
|
61
|
+
.select({ count: sql `count(*)` })
|
|
62
|
+
.from(LogsTable)
|
|
63
|
+
.$dynamic();
|
|
64
|
+
if (whereClause) {
|
|
65
|
+
listQuery = listQuery.where(whereClause);
|
|
66
|
+
countQuery = countQuery.where(whereClause);
|
|
67
|
+
}
|
|
68
|
+
const [rows, totalRows] = await Promise.all([
|
|
69
|
+
listQuery.orderBy(desc(LogsTable.createdAt)).limit(limit).offset(offset),
|
|
70
|
+
countQuery,
|
|
71
|
+
]);
|
|
72
|
+
return {
|
|
73
|
+
items: rows,
|
|
74
|
+
total: totalRows[0]?.count ?? 0,
|
|
75
|
+
limit,
|
|
76
|
+
offset,
|
|
77
|
+
};
|
|
78
|
+
}),
|
|
79
|
+
});
|