nextjs-cms 0.9.22 → 0.9.23

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.
Files changed (185) hide show
  1. package/README.md +65 -13
  2. package/dist/api/actions/files.d.ts +30 -0
  3. package/dist/api/actions/files.d.ts.map +1 -0
  4. package/dist/api/actions/files.js +234 -0
  5. package/dist/api/actions/index.d.ts +4 -0
  6. package/dist/api/actions/index.d.ts.map +1 -0
  7. package/dist/api/actions/index.js +3 -0
  8. package/dist/api/actions/pages.d.ts +297 -0
  9. package/dist/api/actions/pages.d.ts.map +1 -0
  10. package/dist/api/actions/pages.js +1215 -0
  11. package/dist/api/actions/privileges.d.ts +25 -0
  12. package/dist/api/actions/privileges.d.ts.map +1 -0
  13. package/dist/api/actions/privileges.js +98 -0
  14. package/dist/api/client/index.d.ts +4 -0
  15. package/dist/api/client/index.d.ts.map +1 -0
  16. package/dist/api/client/index.js +3 -0
  17. package/dist/api/client.d.ts +30 -0
  18. package/dist/api/client.d.ts.map +1 -0
  19. package/dist/api/client.js +82 -0
  20. package/dist/api/index.d.ts +1 -938
  21. package/dist/api/index.d.ts.map +1 -1
  22. package/dist/api/index.js +0 -13
  23. package/dist/api/plugin/index.d.ts +7 -0
  24. package/dist/api/plugin/index.d.ts.map +1 -0
  25. package/dist/api/plugin/index.js +5 -0
  26. package/dist/api/root.d.ts +18 -1844
  27. package/dist/api/root.d.ts.map +1 -1
  28. package/dist/api/root.js +18 -83
  29. package/dist/api/server/index.d.ts +8 -0
  30. package/dist/api/server/index.d.ts.map +1 -0
  31. package/dist/api/server/index.js +3 -0
  32. package/dist/api/server.d.ts +2748 -0
  33. package/dist/api/server.d.ts.map +1 -0
  34. package/dist/api/server.js +100 -0
  35. package/dist/api/trpc/client.d.ts +19 -3
  36. package/dist/api/trpc/client.d.ts.map +1 -1
  37. package/dist/api/trpc/client.js +55 -1
  38. package/dist/api/trpc/query-client.d.ts +3 -1
  39. package/dist/api/trpc/query-client.d.ts.map +1 -1
  40. package/dist/api/trpc/query-client.js +25 -20
  41. package/dist/api/trpc/root.d.ts +906 -0
  42. package/dist/api/trpc/root.d.ts.map +1 -0
  43. package/dist/api/trpc/root.js +47 -0
  44. package/dist/api/trpc/routers/accountSettings.d.ts +66 -0
  45. package/dist/api/trpc/routers/accountSettings.d.ts.map +1 -0
  46. package/dist/api/trpc/routers/accountSettings.js +200 -0
  47. package/dist/api/trpc/routers/admins.d.ts +112 -0
  48. package/dist/api/trpc/routers/admins.d.ts.map +1 -0
  49. package/dist/api/trpc/routers/admins.js +331 -0
  50. package/dist/api/trpc/routers/auth.d.ts +54 -0
  51. package/dist/api/trpc/routers/auth.d.ts.map +1 -0
  52. package/dist/api/trpc/routers/auth.js +50 -0
  53. package/dist/api/trpc/routers/categorySection.d.ts +105 -0
  54. package/dist/api/trpc/routers/categorySection.d.ts.map +1 -0
  55. package/dist/api/trpc/routers/categorySection.js +49 -0
  56. package/dist/api/trpc/routers/config.d.ts +48 -0
  57. package/dist/api/trpc/routers/config.d.ts.map +1 -0
  58. package/dist/api/trpc/routers/config.js +18 -0
  59. package/dist/api/trpc/routers/cpanel.d.ts +82 -0
  60. package/dist/api/trpc/routers/cpanel.d.ts.map +1 -0
  61. package/dist/api/trpc/routers/cpanel.js +216 -0
  62. package/dist/api/trpc/routers/fields.d.ts +35 -0
  63. package/dist/api/trpc/routers/fields.d.ts.map +1 -0
  64. package/dist/api/trpc/routers/fields.js +81 -0
  65. package/dist/api/trpc/routers/files.d.ts +34 -0
  66. package/dist/api/trpc/routers/files.d.ts.map +1 -0
  67. package/dist/api/trpc/routers/files.js +14 -0
  68. package/dist/api/trpc/routers/gallery.d.ts +35 -0
  69. package/dist/api/trpc/routers/gallery.d.ts.map +1 -0
  70. package/dist/api/trpc/routers/gallery.js +92 -0
  71. package/dist/api/trpc/routers/hasItemsSection.d.ts +194 -0
  72. package/dist/api/trpc/routers/hasItemsSection.d.ts.map +1 -0
  73. package/dist/api/trpc/routers/hasItemsSection.js +86 -0
  74. package/dist/api/trpc/routers/logs.d.ts +59 -0
  75. package/dist/api/trpc/routers/logs.d.ts.map +1 -0
  76. package/dist/api/trpc/routers/logs.js +79 -0
  77. package/dist/api/trpc/routers/navigation.d.ts +65 -0
  78. package/dist/api/trpc/routers/navigation.d.ts.map +1 -0
  79. package/dist/api/trpc/routers/navigation.js +11 -0
  80. package/dist/api/trpc/routers/simpleSection.d.ts +93 -0
  81. package/dist/api/trpc/routers/simpleSection.d.ts.map +1 -0
  82. package/dist/api/trpc/routers/simpleSection.js +54 -0
  83. package/dist/api/trpc/server.d.ts +2789 -5
  84. package/dist/api/trpc/server.d.ts.map +1 -1
  85. package/dist/api/trpc/server.js +91 -52
  86. package/dist/api/trpc/trpc.d.ts +111 -0
  87. package/dist/api/trpc/trpc.d.ts.map +1 -0
  88. package/dist/api/trpc/trpc.js +99 -0
  89. package/dist/api/trpc/utils/async-caller-proxy.d.ts +2 -0
  90. package/dist/api/trpc/utils/async-caller-proxy.d.ts.map +1 -0
  91. package/dist/api/trpc/utils/async-caller-proxy.js +38 -0
  92. package/dist/api/trpc/utils/refresh-token-link.d.ts +6 -0
  93. package/dist/api/trpc/utils/refresh-token-link.d.ts.map +1 -0
  94. package/dist/api/trpc/utils/refresh-token-link.js +81 -0
  95. package/dist/api/trpc/utils/router-types.d.ts +7 -0
  96. package/dist/api/trpc/utils/router-types.d.ts.map +1 -0
  97. package/dist/api/trpc/utils/router-types.js +0 -0
  98. package/dist/api/use-axios-private.d.ts +6 -0
  99. package/dist/api/use-axios-private.d.ts.map +1 -0
  100. package/dist/api/use-axios-private.js +57 -0
  101. package/dist/api/utils/async-caller-proxy.d.ts +2 -0
  102. package/dist/api/utils/async-caller-proxy.d.ts.map +1 -0
  103. package/dist/api/utils/async-caller-proxy.js +36 -0
  104. package/dist/api/utils/lazy-caller-proxy.d.ts +2 -0
  105. package/dist/api/utils/lazy-caller-proxy.d.ts.map +1 -0
  106. package/dist/api/utils/lazy-caller-proxy.js +36 -0
  107. package/dist/api/utils/router-types.d.ts +7 -0
  108. package/dist/api/utils/router-types.d.ts.map +1 -0
  109. package/dist/api/utils/router-types.js +0 -0
  110. package/dist/auth/hooks/index.d.ts +1 -2
  111. package/dist/auth/hooks/index.d.ts.map +1 -1
  112. package/dist/auth/hooks/index.js +1 -2
  113. package/dist/auth/react.d.ts +1 -2
  114. package/dist/auth/react.d.ts.map +1 -1
  115. package/dist/auth/react.js +1 -2
  116. package/dist/auth/trpc.d.ts +1 -1
  117. package/dist/auth/trpc.d.ts.map +1 -1
  118. package/dist/auth/trpc.js +0 -1
  119. package/dist/cli/lib/fix-master-admin.d.ts.map +1 -1
  120. package/dist/cli/lib/fix-master-admin.js +12 -25
  121. package/dist/cli/lib/update-sections.d.ts.map +1 -1
  122. package/dist/cli/lib/update-sections.js +29 -24
  123. package/dist/core/config/config-loader.d.ts +23 -7
  124. package/dist/core/config/config-loader.d.ts.map +1 -1
  125. package/dist/core/config/config-loader.js +26 -9
  126. package/dist/core/fields/select.d.ts +1 -1
  127. package/dist/core/sections/category.d.ts +44 -44
  128. package/dist/core/sections/hasItems.d.ts +44 -44
  129. package/dist/core/sections/section.d.ts +23 -23
  130. package/dist/core/sections/simple.d.ts +8 -8
  131. package/dist/core/types/index.d.ts +17 -0
  132. package/dist/core/types/index.d.ts.map +1 -1
  133. package/dist/index.d.ts +0 -1
  134. package/dist/index.d.ts.map +1 -1
  135. package/dist/index.js +0 -1
  136. package/dist/plugins/client.d.ts +19 -0
  137. package/dist/plugins/client.d.ts.map +1 -0
  138. package/dist/plugins/client.js +24 -0
  139. package/dist/plugins/define.d.ts +4 -0
  140. package/dist/plugins/define.d.ts.map +1 -0
  141. package/dist/plugins/define.js +3 -0
  142. package/dist/plugins/derive.d.ts +32 -0
  143. package/dist/plugins/derive.d.ts.map +1 -0
  144. package/dist/plugins/derive.js +77 -0
  145. package/dist/plugins/loader.d.ts +51 -7
  146. package/dist/plugins/loader.d.ts.map +1 -1
  147. package/dist/plugins/loader.js +111 -51
  148. package/dist/plugins/manifest.d.ts +28 -0
  149. package/dist/plugins/manifest.d.ts.map +1 -0
  150. package/dist/plugins/manifest.js +83 -0
  151. package/dist/plugins/prefetch.d.ts +16 -0
  152. package/dist/plugins/prefetch.d.ts.map +1 -0
  153. package/dist/plugins/prefetch.js +40 -0
  154. package/dist/plugins/registry.d.ts +22 -0
  155. package/dist/plugins/registry.d.ts.map +1 -0
  156. package/dist/plugins/registry.js +25 -0
  157. package/dist/plugins/server.d.ts +2 -0
  158. package/dist/plugins/server.d.ts.map +1 -1
  159. package/dist/plugins/server.js +2 -0
  160. package/dist/plugins/types.d.ts +9 -0
  161. package/dist/plugins/types.d.ts.map +1 -0
  162. package/dist/plugins/types.js +0 -0
  163. package/dist/translations/base/en.d.ts +1 -0
  164. package/dist/translations/base/en.d.ts.map +1 -1
  165. package/dist/translations/base/en.js +1 -0
  166. package/dist/translations/client.d.ts +16 -4
  167. package/dist/translations/client.d.ts.map +1 -1
  168. package/dist/translations/server.d.ts +16 -4
  169. package/dist/translations/server.d.ts.map +1 -1
  170. package/dist/utils/console-log.d.ts +18 -0
  171. package/dist/utils/console-log.d.ts.map +1 -0
  172. package/dist/utils/console-log.js +28 -0
  173. package/dist/utils/index.d.ts +1 -0
  174. package/dist/utils/index.d.ts.map +1 -1
  175. package/dist/utils/index.js +1 -0
  176. package/dist/utils/log.d.ts +18 -0
  177. package/dist/utils/log.d.ts.map +1 -0
  178. package/dist/utils/log.js +28 -0
  179. package/dist/validators/index.d.ts +1 -0
  180. package/dist/validators/index.d.ts.map +1 -1
  181. package/dist/validators/index.js +1 -0
  182. package/dist/validators/tags.d.ts +4 -0
  183. package/dist/validators/tags.d.ts.map +1 -0
  184. package/dist/validators/tags.js +8 -0
  185. package/package.json +34 -16
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/api/trpc/server.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AAEpB,OAA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;;;2BAMm2U,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAAonsB,CAAC;;;;;+BAA0E,CAAC;;;;;;+BAAgH,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAAt4/B,CAAC;;;;;+BAAuE,CAAC;;;;;;+BAA6G,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAtFhgC,OAAO,CAAC,SAAS,CAAC;EAqFvD"}
@@ -1,61 +1,100 @@
1
1
  import 'server-only';
2
2
  import { createHydrationHelpers } from '@trpc/react-query/rsc';
3
+ import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
3
4
  import { headers } from 'next/headers';
4
5
  import { cache } from 'react';
5
- import { getAppRouter } from '../root.js';
6
- import { createTRPCContext } from '../trpc.js';
6
+ import { getConfigImportVersion } from '../../core/config/index.js';
7
+ import { loadPlugins } from '../../plugins/loader.js';
8
+ import { coreRouters } from './root.js';
9
+ import { createCallerFactory, createTRPCContext, router } from './trpc.js';
7
10
  import { createQueryClient } from './query-client.js';
8
- /**
9
- * This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when
10
- * handling a tRPC call from a React Server Component.
11
- */
12
- const createContext = cache(async () => {
13
- const heads = new Headers(await headers());
14
- heads.set('x-trpc-source', 'rsc');
15
- return createTRPCContext({
16
- headers: heads,
17
- });
18
- });
19
- const getQueryClient = cache(createQueryClient);
20
- const getCaller = cache(async () => {
21
- const routerWithPlugins = await getAppRouter();
22
- return routerWithPlugins.createCaller(await createContext());
23
- });
24
- const resolveCallerPath = (root, path) => {
25
- let current = root;
26
- for (const key of path) {
27
- if (!current || (typeof current !== 'object' && typeof current !== 'function')) {
28
- return undefined;
11
+ import { createAsyncCallerProxy } from './utils/async-caller-proxy.js';
12
+ export function createTRPCRouter(opts = {}) {
13
+ const userRouters = (opts.routers ?? {});
14
+ for (const key of Object.keys(userRouters)) {
15
+ if (key in coreRouters) {
16
+ throw new Error(`[trpc] Router key "${key}" conflicts with a core router.`);
29
17
  }
30
- current = current[key];
31
18
  }
32
- return current;
33
- };
34
- const callProcedure = async (path, args) => {
35
- const caller = await getCaller();
36
- const proc = resolveCallerPath(caller, path);
37
- if (typeof proc !== 'function') {
38
- throw new Error(`tRPC procedure not found: ${path.join('.')}`);
19
+ const appRouter = router({
20
+ ...coreRouters,
21
+ ...userRouters,
22
+ });
23
+ let cachedRouter = null;
24
+ let pendingRouter = null;
25
+ let cachedVersion = -1;
26
+ let pendingVersion = -1;
27
+ async function getMergedRouter() {
28
+ const currentVersion = getConfigImportVersion();
29
+ if (cachedRouter && cachedVersion === currentVersion) {
30
+ return cachedRouter;
31
+ }
32
+ if (pendingRouter && pendingVersion === currentVersion) {
33
+ return pendingRouter;
34
+ }
35
+ cachedRouter = null;
36
+ pendingVersion = currentVersion;
37
+ pendingRouter = (async () => {
38
+ const loadedPlugins = await loadPlugins();
39
+ const pluginRouters = {};
40
+ const seen = new Set([...Object.keys(coreRouters), ...Object.keys(userRouters)]);
41
+ for (const plugin of loadedPlugins) {
42
+ if (!plugin.plugin.router)
43
+ continue;
44
+ if (seen.has(plugin.routerKey)) {
45
+ const message = `[plugins] Router key "${plugin.routerKey}" conflicts with core/user router. Skipping.`;
46
+ throw new Error(message);
47
+ }
48
+ pluginRouters[plugin.routerKey] = plugin.plugin.router;
49
+ seen.add(plugin.routerKey);
50
+ }
51
+ const mergedRouter = router({
52
+ ...coreRouters,
53
+ ...pluginRouters,
54
+ ...userRouters,
55
+ });
56
+ cachedRouter = mergedRouter;
57
+ cachedVersion = currentVersion;
58
+ return mergedRouter;
59
+ })();
60
+ try {
61
+ return await pendingRouter;
62
+ }
63
+ finally {
64
+ if (pendingVersion === currentVersion) {
65
+ pendingRouter = null;
66
+ }
67
+ }
39
68
  }
40
- return proc(...args);
41
- };
42
- const createCallerProxy = (path = []) => {
43
- const proxyTarget = (...args) => callProcedure(path, args);
44
- return new Proxy(proxyTarget, {
45
- get(_target, prop) {
46
- if (prop === 'then')
47
- return undefined;
48
- if (typeof prop !== 'string')
49
- return undefined;
50
- return createCallerProxy([...path, prop]);
51
- },
52
- apply(_target, _thisArg, args) {
53
- return callProcedure(path, args);
54
- },
69
+ const createContext = cache(async () => {
70
+ const heads = new Headers(await headers());
71
+ heads.set('x-trpc-source', 'rsc');
72
+ return createTRPCContext({
73
+ headers: heads,
74
+ });
75
+ });
76
+ const getQueryClient = cache(createQueryClient);
77
+ const getCaller = cache(async () => (await getMergedRouter()).createCaller(await createContext()));
78
+ const callerProxy = createAsyncCallerProxy(getCaller);
79
+ const helpers = createHydrationHelpers(callerProxy, getQueryClient);
80
+ const handler = async (req) => fetchRequestHandler({
81
+ endpoint: '/api/trpc',
82
+ req,
83
+ router: await getMergedRouter(),
84
+ createContext: () => createTRPCContext({ headers: req.headers }),
85
+ onError: opts.onError ??
86
+ (process.env.NODE_ENV === 'development'
87
+ ? ({ path, error }) => {
88
+ console.error(`tRPC failed on ${path ?? '<no-path>'}: ${error.message}`);
89
+ }
90
+ : undefined),
55
91
  });
56
- };
57
- // Lazily resolves the caller so plugin routers are available without top-level await.
58
- const callerProxy = createCallerProxy();
59
- const _t = createHydrationHelpers(callerProxy, getQueryClient);
60
- export const api = _t.trpc;
61
- export const HydrateClient = _t.HydrateClient;
92
+ return {
93
+ appRouter,
94
+ handler: { GET: handler, POST: handler },
95
+ api: helpers.trpc,
96
+ HydrateClient: helpers.HydrateClient,
97
+ createCaller: createCallerFactory(appRouter),
98
+ getRouter: getMergedRouter,
99
+ };
100
+ }
@@ -0,0 +1,111 @@
1
+ import superjson from 'superjson';
2
+ /**
3
+ * Creates context for an incoming request
4
+ * @link https://trpc.io/docs/v11/context
5
+ */
6
+ export declare const createTRPCContext: (opts: {
7
+ headers: Headers;
8
+ }) => Promise<{
9
+ headers: Headers;
10
+ db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../../db/schema.js")> & {
11
+ $client: import("mysql2/promise").Pool;
12
+ };
13
+ session: import("../../index.js").Session | null;
14
+ }>;
15
+ type Context = Awaited<ReturnType<typeof createTRPCContext>>;
16
+ export type TRPCContext = Context;
17
+ export declare const transformer: {
18
+ input: typeof superjson;
19
+ output: typeof superjson;
20
+ };
21
+ /**
22
+ * Create a server-side caller
23
+ * @see https://trpc.io/docs/server/server-side-calls
24
+ */
25
+ export declare const createCallerFactory: import("@trpc/server").TRPCRouterCallerFactory<{
26
+ ctx: {
27
+ headers: Headers;
28
+ db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../../db/schema.js")> & {
29
+ $client: import("mysql2/promise").Pool;
30
+ };
31
+ session: import("../../index.js").Session | null;
32
+ };
33
+ meta: object;
34
+ errorShape: {
35
+ data: {
36
+ zodError: import("zod").ZodFlattenedError<unknown, string> | null;
37
+ code: import("@trpc/server").TRPC_ERROR_CODE_KEY;
38
+ httpStatus: number;
39
+ path?: string;
40
+ stack?: string;
41
+ };
42
+ message: string;
43
+ code: import("@trpc/server").TRPC_ERROR_CODE_NUMBER;
44
+ };
45
+ transformer: true;
46
+ }>;
47
+ /**
48
+ * This is how you create new routers and sub-routers in your tRPC API
49
+ * @see https://trpc.io/docs/router
50
+ */
51
+ export declare const router: import("@trpc/server").TRPCRouterBuilder<{
52
+ ctx: {
53
+ headers: Headers;
54
+ db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../../db/schema.js")> & {
55
+ $client: import("mysql2/promise").Pool;
56
+ };
57
+ session: import("../../index.js").Session | null;
58
+ };
59
+ meta: object;
60
+ errorShape: {
61
+ data: {
62
+ zodError: import("zod").ZodFlattenedError<unknown, string> | null;
63
+ code: import("@trpc/server").TRPC_ERROR_CODE_KEY;
64
+ httpStatus: number;
65
+ path?: string;
66
+ stack?: string;
67
+ };
68
+ message: string;
69
+ code: import("@trpc/server").TRPC_ERROR_CODE_NUMBER;
70
+ };
71
+ transformer: true;
72
+ }>;
73
+ /**
74
+ * Public procedure that doesn't require authentication
75
+ */
76
+ export declare const publicProcedure: import("@trpc/server").TRPCProcedureBuilder<{
77
+ headers: Headers;
78
+ db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../../db/schema.js")> & {
79
+ $client: import("mysql2/promise").Pool;
80
+ };
81
+ session: import("../../index.js").Session | null;
82
+ }, object, object, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, false>;
83
+ /**
84
+ * Private procedure that uses the `isAuthedMiddleware` middleware to require authentication
85
+ * @see https://trpc.io/docs/procedures
86
+ */
87
+ export declare const privateProcedure: import("@trpc/server").TRPCProcedureBuilder<{
88
+ headers: Headers;
89
+ db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../../db/schema.js")> & {
90
+ $client: import("mysql2/promise").Pool;
91
+ };
92
+ session: import("../../index.js").Session | null;
93
+ }, object, {
94
+ session: {
95
+ user: import("../../index.js").User;
96
+ };
97
+ }, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, false>;
98
+ type PrivilegeOperation = 'C' | 'U' | 'D';
99
+ export declare const pluginProcedure: (sectionName: string, requiredRole?: PrivilegeOperation) => import("@trpc/server").TRPCProcedureBuilder<{
100
+ headers: Headers;
101
+ db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../../db/schema.js")> & {
102
+ $client: import("mysql2/promise").Pool;
103
+ };
104
+ session: import("../../index.js").Session | null;
105
+ }, object, {
106
+ session: {
107
+ user: import("../../index.js").User;
108
+ };
109
+ }, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, false>;
110
+ export {};
111
+ //# sourceMappingURL=trpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trpc.d.ts","sourceRoot":"","sources":["../../../src/api/trpc/trpc.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,WAAW,CAAA;AASjC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAU,MAAM;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE;aAAT,OAAO;;;;;EAQ/D,CAAA;AAED,KAAK,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAA;AAC5D,MAAM,MAAM,WAAW,GAAG,OAAO,CAAA;AAEjC,eAAO,MAAM,WAAW;;;CAGvB,CAAA;AAkBD;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;iBAtCyB,OAAO;;;;;;;;;;;;;;;;;;;EAsCR,CAAA;AAiBxD;;;GAGG;AACH,eAAO,MAAM,MAAM;;iBA3DsC,OAAO;;;;;;;;;;;;;;;;;;;EA2DlC,CAAA;AAE9B;;GAEG;AACH,eAAO,MAAM,eAAe;aAhE6B,OAAO;;;;;yLAgEtB,CAAA;AAE1C;;;GAGG;AACH,eAAO,MAAM,gBAAgB;aAtE4B,OAAO;;;;;;;;;yKAsEG,CAAA;AAEnE,KAAK,kBAAkB,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;AAoCzC,eAAO,MAAM,eAAe,GAAI,aAAa,MAAM,EAAE,eAAe,kBAAkB;aA5G7B,OAAO;;;;;;;;;yKA6GO,CAAA"}
@@ -0,0 +1,99 @@
1
+ import { initTRPC, TRPCError } from '@trpc/server';
2
+ import superjson from 'superjson';
3
+ import { ZodError } from 'zod';
4
+ import auth from '../../auth/index.js';
5
+ import { db } from '../../db/client.js';
6
+ import { and, eq } from 'drizzle-orm';
7
+ import { AdminPrivilegesTable } from '../../db/schema.js';
8
+ import getString from '../../translations/index.js';
9
+ import { isDashboardOverridePlugin } from '../../plugins/loader.js';
10
+ /**
11
+ * Creates context for an incoming request
12
+ * @link https://trpc.io/docs/v11/context
13
+ */
14
+ export const createTRPCContext = async (opts) => {
15
+ const session = await auth();
16
+ return {
17
+ db,
18
+ session,
19
+ ...opts,
20
+ };
21
+ };
22
+ export const transformer = {
23
+ input: superjson,
24
+ output: superjson,
25
+ };
26
+ const t = initTRPC.context().create({
27
+ transformer: transformer,
28
+ errorFormatter({ shape, error }) {
29
+ return {
30
+ ...shape,
31
+ data: {
32
+ ...shape.data,
33
+ zodError: error.cause instanceof ZodError ? error.cause.flatten() : null,
34
+ },
35
+ };
36
+ },
37
+ /*errorFormatter({ shape }) {
38
+ return shape
39
+ },*/
40
+ });
41
+ /**
42
+ * Create a server-side caller
43
+ * @see https://trpc.io/docs/server/server-side-calls
44
+ */
45
+ export const createCallerFactory = t.createCallerFactory;
46
+ const isAuthedMiddleware = t.middleware(async ({ ctx, next }) => {
47
+ if (!ctx.session || !ctx.session.user)
48
+ throw new TRPCError({ code: 'UNAUTHORIZED', message: getString('noTokenProvided', 'en') });
49
+ return next({
50
+ /*ctx: {
51
+ user: user,
52
+ headers: ctx.opts.headers,
53
+ },*/
54
+ ctx: {
55
+ // infers the `session` as non-nullable
56
+ session: { ...ctx.session, user: ctx.session.user },
57
+ },
58
+ });
59
+ });
60
+ /**
61
+ * This is how you create new routers and sub-routers in your tRPC API
62
+ * @see https://trpc.io/docs/router
63
+ */
64
+ export const router = t.router;
65
+ /**
66
+ * Public procedure that doesn't require authentication
67
+ */
68
+ export const publicProcedure = t.procedure;
69
+ /**
70
+ * Private procedure that uses the `isAuthedMiddleware` middleware to require authentication
71
+ * @see https://trpc.io/docs/procedures
72
+ */
73
+ export const privateProcedure = t.procedure.use(isAuthedMiddleware);
74
+ const accessControlMiddleware = (sectionName, requiredRole) => isAuthedMiddleware.unstable_pipe(async ({ ctx, next }) => {
75
+ // Bypass privilege check for dashboard override plugin
76
+ if (await isDashboardOverridePlugin(sectionName)) {
77
+ return next();
78
+ }
79
+ const privilege = await db
80
+ .select()
81
+ .from(AdminPrivilegesTable)
82
+ .where(and(eq(AdminPrivilegesTable.adminId, ctx.session.user.id), eq(AdminPrivilegesTable.sectionName, sectionName)))
83
+ .limit(1);
84
+ const allowed = privilege[0];
85
+ if (!allowed) {
86
+ throw new TRPCError({
87
+ code: 'NOT_FOUND',
88
+ message: getString('sectionNotFound', ctx.session.user.language),
89
+ });
90
+ }
91
+ if (requiredRole && !allowed.operations.includes(requiredRole)) {
92
+ throw new TRPCError({
93
+ code: 'NOT_FOUND',
94
+ message: getString('noAccessToThisOperation', ctx.session.user.language),
95
+ });
96
+ }
97
+ return next();
98
+ });
99
+ export const pluginProcedure = (sectionName, requiredRole) => t.procedure.use(accessControlMiddleware(sectionName, requiredRole));
@@ -0,0 +1,2 @@
1
+ export declare function createAsyncCallerProxy<TCaller>(getCaller: () => Promise<TCaller>): TCaller;
2
+ //# sourceMappingURL=async-caller-proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-caller-proxy.d.ts","sourceRoot":"","sources":["../../../../src/api/trpc/utils/async-caller-proxy.ts"],"names":[],"mappings":"AAWA,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CA2B1F"}
@@ -0,0 +1,38 @@
1
+ const resolveCallerPath = (root, path) => {
2
+ let current = root;
3
+ for (const key of path) {
4
+ if (!current || (typeof current !== 'object' && typeof current !== 'function')) {
5
+ return undefined;
6
+ }
7
+ current = current[key];
8
+ }
9
+ return current;
10
+ };
11
+ export function createAsyncCallerProxy(getCaller) {
12
+ const callProcedure = async (path, args) => {
13
+ const caller = await getCaller();
14
+ const proc = resolveCallerPath(caller, path);
15
+ if (typeof proc !== 'function') {
16
+ throw new Error(`tRPC procedure not found: ${path.join('.')}`);
17
+ }
18
+ return proc(...args);
19
+ };
20
+ const createCallerProxy = (path = []) => {
21
+ const proxyTarget = (...args) => callProcedure(path, args);
22
+ return new Proxy(proxyTarget, {
23
+ get(_target, prop) {
24
+ // PromiseLike short-circuit: prevents `Promise.resolve(proxy)` from treating
25
+ // the proxy as a thenable. Procedure paths cannot be named "then".
26
+ if (prop === 'then')
27
+ return undefined;
28
+ if (typeof prop !== 'string')
29
+ return undefined;
30
+ return createCallerProxy([...path, prop]);
31
+ },
32
+ apply(_target, _thisArg, args) {
33
+ return callProcedure(path, args);
34
+ },
35
+ });
36
+ };
37
+ return createCallerProxy();
38
+ }
@@ -0,0 +1,6 @@
1
+ import type { TRPCLink } from '@trpc/client';
2
+ /**
3
+ * tRPC link that refreshes the token if it's expired
4
+ */
5
+ export declare const refreshTokenLink: () => TRPCLink<any>;
6
+ //# sourceMappingURL=refresh-token-link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refresh-token-link.d.ts","sourceRoot":"","sources":["../../../../src/api/trpc/utils/refresh-token-link.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAK5C;;GAEG;AACH,eAAO,MAAM,gBAAgB,QAAO,QAAQ,CAAC,GAAG,CA6E/C,CAAA"}
@@ -0,0 +1,81 @@
1
+ import { observable } from '@trpc/server/observable';
2
+ import { logout, refreshSession } from '../../../auth/react.js';
3
+ /**
4
+ * tRPC link that refreshes the token if it's expired
5
+ */
6
+ export const refreshTokenLink = () => {
7
+ /**
8
+ * Add a lock state to prevent multiple refreshes at the same time
9
+ */
10
+ let isRefreshing = false;
11
+ let refreshPromise = null;
12
+ return () => {
13
+ return ({ next, op }) => {
14
+ return observable((observer) => {
15
+ let next$ = null;
16
+ let shouldRetry = true; // Flag to control the retry
17
+ function attempt() {
18
+ next$?.unsubscribe();
19
+ next$ = next(op).subscribe({
20
+ async error(err) {
21
+ if (err.data?.code === 'UNAUTHORIZED' && shouldRetry) {
22
+ if (!isRefreshing) {
23
+ isRefreshing = true;
24
+ refreshPromise = (async () => {
25
+ try {
26
+ const response = await fetch('/api/auth/refresh');
27
+ const data = await response.json();
28
+ if (response.status !== 200) {
29
+ await logout({
30
+ /**
31
+ * No need to delete the cookies, because they are both invalid.
32
+ */
33
+ deleteCookies: false,
34
+ });
35
+ return;
36
+ }
37
+ await refreshSession(data.session);
38
+ }
39
+ catch (e) {
40
+ await logout({
41
+ /**
42
+ * No need to delete the cookies, because they are both invalid.
43
+ */
44
+ deleteCookies: false,
45
+ });
46
+ throw e;
47
+ }
48
+ finally {
49
+ isRefreshing = false;
50
+ refreshPromise = null;
51
+ }
52
+ })();
53
+ }
54
+ try {
55
+ await refreshPromise;
56
+ shouldRetry = false;
57
+ attempt();
58
+ return;
59
+ }
60
+ catch (e) {
61
+ // Don't throw under-the-hood refresh flow's errors
62
+ }
63
+ }
64
+ observer.error(err);
65
+ },
66
+ next(value) {
67
+ observer.next(value);
68
+ },
69
+ complete() {
70
+ observer.complete();
71
+ },
72
+ });
73
+ }
74
+ attempt();
75
+ return () => {
76
+ next$?.unsubscribe();
77
+ };
78
+ });
79
+ };
80
+ };
81
+ };
@@ -0,0 +1,7 @@
1
+ import type { AnyRouter } from '@trpc/server';
2
+ import type { CoreRouters } from '../root.js';
3
+ export type RouterRecord = Record<string, AnyRouter>;
4
+ export type NonConflictingRouterRecord<TUser extends RouterRecord> = Extract<keyof TUser, keyof CoreRouters> extends never ? TUser : {
5
+ [K in keyof TUser]: K extends keyof CoreRouters ? never : TUser[K];
6
+ };
7
+ //# sourceMappingURL=router-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router-types.d.ts","sourceRoot":"","sources":["../../../../src/api/trpc/utils/router-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;AAEpD,MAAM,MAAM,0BAA0B,CAAC,KAAK,SAAS,YAAY,IAC7D,OAAO,CAAC,MAAM,KAAK,EAAE,MAAM,WAAW,CAAC,SAAS,KAAK,GAC/C,KAAK,GACL;KACK,CAAC,IAAI,MAAM,KAAK,GAAG,CAAC,SAAS,MAAM,WAAW,GAAG,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;CACrE,CAAA"}
File without changes
@@ -0,0 +1,6 @@
1
+ import type { AxiosInstance } from 'axios';
2
+ declare const useAxiosPrivate: (options?: {
3
+ refreshTokenOn?: 401 | 404;
4
+ }) => AxiosInstance;
5
+ export default useAxiosPrivate;
6
+ //# sourceMappingURL=use-axios-private.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-axios-private.d.ts","sourceRoot":"","sources":["../../src/api/use-axios-private.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAkB1C,QAAA,MAAM,eAAe,GAAI,UAAU;IAAE,cAAc,CAAC,EAAE,GAAG,GAAG,GAAG,CAAA;CAAE,kBAqDhE,CAAA;AAED,eAAe,eAAe,CAAA"}
@@ -0,0 +1,57 @@
1
+ 'use client';
2
+ import axios from 'axios';
3
+ import { useEffect } from 'react';
4
+ import useRefreshToken from '../auth/hooks/useRefreshToken.js';
5
+ import { getCsrfToken } from '../auth/react.js';
6
+ let _instance;
7
+ function getAxiosPrivate() {
8
+ if (!_instance) {
9
+ _instance = axios.create({
10
+ baseURL: '/api',
11
+ headers: { 'Content-Type': 'application/json' },
12
+ withCredentials: true,
13
+ });
14
+ }
15
+ return _instance;
16
+ }
17
+ const useAxiosPrivate = (options) => {
18
+ const refresh = useRefreshToken();
19
+ const { refreshTokenOn = 401 } = options || {};
20
+ const axiosPrivate = getAxiosPrivate();
21
+ useEffect(() => {
22
+ const requestIntercept = axiosPrivate.interceptors.request.use(async (config) => {
23
+ if (config.method && ['post', 'put', 'delete'].includes(config.method.toLowerCase())) {
24
+ config.headers['x-csrf-token'] = await getCsrfToken();
25
+ }
26
+ return config;
27
+ }, (error) => Promise.reject(error));
28
+ const responseIntercept = axiosPrivate.interceptors.response.use((response) => response, async (error) => {
29
+ const prevRequest = error?.config;
30
+ if (error?.response?.status === refreshTokenOn && !prevRequest?.sent) {
31
+ prevRequest.sent = true;
32
+ const refreshStatus = await refresh();
33
+ if (refreshStatus === false)
34
+ return Promise.reject(error);
35
+ prevRequest.headers['Content-Type'] = 'multipart/form-data';
36
+ prevRequest.transformRequest = [
37
+ (data, headers) => {
38
+ if (data instanceof FormData) {
39
+ // @ts-ignore
40
+ headers['Content-Type'] += `; boundary=${data._boundary}`;
41
+ }
42
+ return data;
43
+ },
44
+ ...axios.defaults.transformRequest,
45
+ ];
46
+ return axiosPrivate(prevRequest);
47
+ }
48
+ return Promise.reject(error);
49
+ });
50
+ return () => {
51
+ axiosPrivate.interceptors.request.eject(requestIntercept);
52
+ axiosPrivate.interceptors.response.eject(responseIntercept);
53
+ };
54
+ }, []);
55
+ return axiosPrivate;
56
+ };
57
+ export default useAxiosPrivate;
@@ -0,0 +1,2 @@
1
+ export declare function createAsyncCallerProxy<TCaller>(getCaller: () => Promise<TCaller>): TCaller;
2
+ //# sourceMappingURL=async-caller-proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-caller-proxy.d.ts","sourceRoot":"","sources":["../../../src/api/utils/async-caller-proxy.ts"],"names":[],"mappings":"AAWA,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAyB1F"}
@@ -0,0 +1,36 @@
1
+ const resolveCallerPath = (root, path) => {
2
+ let current = root;
3
+ for (const key of path) {
4
+ if (!current || (typeof current !== 'object' && typeof current !== 'function')) {
5
+ return undefined;
6
+ }
7
+ current = current[key];
8
+ }
9
+ return current;
10
+ };
11
+ export function createAsyncCallerProxy(getCaller) {
12
+ const callProcedure = async (path, args) => {
13
+ const caller = await getCaller();
14
+ const proc = resolveCallerPath(caller, path);
15
+ if (typeof proc !== 'function') {
16
+ throw new Error(`tRPC procedure not found: ${path.join('.')}`);
17
+ }
18
+ return proc(...args);
19
+ };
20
+ const createCallerProxy = (path = []) => {
21
+ const proxyTarget = (...args) => callProcedure(path, args);
22
+ return new Proxy(proxyTarget, {
23
+ get(_target, prop) {
24
+ if (prop === 'then')
25
+ return undefined;
26
+ if (typeof prop !== 'string')
27
+ return undefined;
28
+ return createCallerProxy([...path, prop]);
29
+ },
30
+ apply(_target, _thisArg, args) {
31
+ return callProcedure(path, args);
32
+ },
33
+ });
34
+ };
35
+ return createCallerProxy();
36
+ }
@@ -0,0 +1,2 @@
1
+ export declare function createLazyCallerProxy<TCaller>(getCaller: () => Promise<TCaller>): TCaller;
2
+ //# sourceMappingURL=lazy-caller-proxy.d.ts.map