@greatapps/common 1.1.661 → 1.1.662

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatapps/common",
3
- "version": "1.1.661",
3
+ "version": "1.1.662",
4
4
  "description": "Shared library for GreatApps frontend applications",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./src/index.ts",
@@ -77,7 +77,7 @@
77
77
  },
78
78
  "devDependencies": {
79
79
  "@hookform/resolvers": "^5.2.2",
80
- "zod": "^4.3.6",
80
+ "zod": "^4.4.3",
81
81
  "@tanstack/react-query": "^5.95.2",
82
82
  "@tanstack/react-query-devtools": "^5.95.2",
83
83
  "@types/node": "^25.5.0",
@@ -0,0 +1,16 @@
1
+ export function parseNumericFields<T extends object>(
2
+ params: Partial<T>,
3
+ fields: readonly (keyof T)[]
4
+ ): Partial<T> {
5
+ const result: Partial<T> = { ...params };
6
+ for (const field of fields) {
7
+ const v = result[field] as unknown;
8
+ if (typeof v === 'string' && v !== '') {
9
+ const n = Number(v);
10
+ if (Number.isFinite(n)) {
11
+ result[field] = n as T[keyof T];
12
+ }
13
+ }
14
+ }
15
+ return result;
16
+ }
@@ -1,16 +1,22 @@
1
1
  import 'server-only';
2
2
 
3
3
  import type { NextRequest } from 'next/server';
4
+ import { parseNumericFields } from '../../../infra/route/parse-numeric';
4
5
  import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
5
6
  import { searchParamsToParams } from '../../../infra/route/search-params';
6
7
  import { projectUsersService } from '../services/project-users.service';
7
8
  import type { ListUsersParams } from '../types';
8
9
 
10
+ const NUMERIC_FIELDS = ['page', 'limit'] as const;
11
+
9
12
  export function createListAllAccountUsersHandler() {
10
13
  return async function GET(req: NextRequest) {
11
14
  return safeRouteHandler(() =>
12
15
  projectUsersService.listAllAccountUsers(
13
- searchParamsToParams<ListUsersParams>(req.nextUrl.searchParams)
16
+ parseNumericFields<ListUsersParams>(
17
+ searchParamsToParams<ListUsersParams>(req.nextUrl.searchParams),
18
+ NUMERIC_FIELDS
19
+ )
14
20
  )
15
21
  );
16
22
  };
@@ -2,18 +2,24 @@ import 'server-only';
2
2
 
3
3
  import type { NextRequest } from 'next/server';
4
4
  import { parseId } from '../../../infra/route/parse-id';
5
+ import { parseNumericFields } from '../../../infra/route/parse-numeric';
5
6
  import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
6
7
  import { searchParamsToParams } from '../../../infra/route/search-params';
7
8
  import { projectUsersService } from '../services/project-users.service';
8
9
  import type { ListUsersParams } from '../types';
9
10
 
11
+ const NUMERIC_FIELDS = ['page', 'limit'] as const;
12
+
10
13
  export function createListAvailableUsersHandler() {
11
14
  return async function GET(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
12
15
  return safeRouteHandler(async () => {
13
16
  const { id } = await params;
14
17
  return projectUsersService.listNotInProject(
15
18
  parseId(id),
16
- searchParamsToParams<ListUsersParams>(req.nextUrl.searchParams)
19
+ parseNumericFields<ListUsersParams>(
20
+ searchParamsToParams<ListUsersParams>(req.nextUrl.searchParams),
21
+ NUMERIC_FIELDS
22
+ )
17
23
  );
18
24
  });
19
25
  };
@@ -2,18 +2,24 @@ import 'server-only';
2
2
 
3
3
  import type { NextRequest } from 'next/server';
4
4
  import { parseId } from '../../../infra/route/parse-id';
5
+ import { parseNumericFields } from '../../../infra/route/parse-numeric';
5
6
  import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
6
7
  import { searchParamsToParams } from '../../../infra/route/search-params';
7
8
  import { projectUsersService } from '../services/project-users.service';
8
9
  import type { ListUsersParams } from '../types';
9
10
 
11
+ const NUMERIC_FIELDS = ['page', 'limit'] as const;
12
+
10
13
  export function createListProjectUsersHandler() {
11
14
  return async function GET(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
12
15
  return safeRouteHandler(async () => {
13
16
  const { id } = await params;
14
17
  return projectUsersService.listInProject(
15
18
  parseId(id),
16
- searchParamsToParams<ListUsersParams>(req.nextUrl.searchParams)
19
+ parseNumericFields<ListUsersParams>(
20
+ searchParamsToParams<ListUsersParams>(req.nextUrl.searchParams),
21
+ NUMERIC_FIELDS
22
+ )
17
23
  );
18
24
  });
19
25
  };
@@ -1,16 +1,22 @@
1
1
  import 'server-only';
2
2
 
3
3
  import type { NextRequest } from 'next/server';
4
+ import { parseNumericFields } from '../../../infra/route/parse-numeric';
4
5
  import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
5
6
  import { searchParamsToParams } from '../../../infra/route/search-params';
6
7
  import { projectsService } from '../services/projects.service';
7
8
  import type { ListProjectsActionParams } from '../actions/list-projects.action';
8
9
 
10
+ const NUMERIC_FIELDS = ['page', 'limit', 'deleted'] as const;
11
+
9
12
  export function createListProjectsHandler() {
10
13
  return async function GET(req: NextRequest) {
11
14
  return safeRouteHandler(() =>
12
15
  projectsService.list(
13
- searchParamsToParams<ListProjectsActionParams>(req.nextUrl.searchParams)
16
+ parseNumericFields<ListProjectsActionParams>(
17
+ searchParamsToParams<ListProjectsActionParams>(req.nextUrl.searchParams),
18
+ NUMERIC_FIELDS
19
+ )
14
20
  )
15
21
  );
16
22
  };
@@ -5,7 +5,7 @@ import { apiFetch } from '../../../infra/http/api-fetch';
5
5
  import { markMessageAsReadAction } from '../action/mark-message-as-read.action';
6
6
  import { markAllMessagesAsReadAction } from '../action/mark-all-messages-as-read.action';
7
7
  import { withAction } from '../../../utils/withAction';
8
- import type { FindMessagesParams, ListMessagesApiResponse } from '../schema/messages.schema';
8
+ import type { FindMessagesParams, ListMessagesResult } from '../schema/messages.schema';
9
9
  import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
10
10
 
11
11
  export const MESSAGES_QUERY_KEY = ['messages'] as const;
@@ -18,7 +18,7 @@ export function useMessages(params?: Partial<FindMessagesParams>) {
18
18
  return useQuery({
19
19
  queryKey,
20
20
  queryFn: ({ signal }) =>
21
- apiFetch<ListMessagesApiResponse>('/api/messages', { params, signal }),
21
+ apiFetch<ListMessagesResult>('/api/messages', { params, signal }),
22
22
  });
23
23
  }
24
24
 
@@ -28,7 +28,7 @@ export function useInfiniteMessages(params?: Partial<Omit<FindMessagesParams, 'p
28
28
  return useInfiniteQuery({
29
29
  queryKey,
30
30
  queryFn: ({ pageParam, signal }) =>
31
- apiFetch<ListMessagesApiResponse>('/api/messages', {
31
+ apiFetch<ListMessagesResult>('/api/messages', {
32
32
  params: {
33
33
  ...params,
34
34
  page: pageParam as number,
@@ -37,6 +37,8 @@ export interface ListMessagesApiResponse {
37
37
  message?: string;
38
38
  }
39
39
 
40
+ export type ListMessagesResult = Omit<ListMessagesApiResponse, 'status' | 'message'>;
41
+
40
42
  export interface MarkAsReadApiResponse {
41
43
  status: 0 | 1;
42
44
  message?: string;
package/src/route.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { safeRouteHandler } from './infra/route/safe-route-handler';
2
2
  export { searchParamsToParams } from './infra/route/search-params';
3
3
  export { parseId } from './infra/route/parse-id';
4
+ export { parseNumericFields } from './infra/route/parse-numeric';