@greatapps/common 1.1.660 → 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 +1 -2
- package/src/infra/route/parse-numeric.ts +16 -0
- package/src/modules/projects/handlers/list-all-account-users.handler.ts +7 -1
- package/src/modules/projects/handlers/list-available-users.handler.ts +7 -1
- package/src/modules/projects/handlers/list-project-users.handler.ts +7 -1
- package/src/modules/projects/handlers/list-projects.handler.ts +7 -1
- package/src/modules/users/hooks/messages.hook.ts +3 -3
- package/src/modules/users/schema/messages.schema.ts +2 -0
- package/src/route.ts +1 -0
- package/src/server.ts +0 -8
- package/src/modules/cards/actions/find-card-by-id.action.ts +0 -8
- package/src/modules/cards/actions/list-cards.action.ts +0 -8
- package/src/modules/charges/actions/find-charge-by-id.action.ts +0 -8
- package/src/modules/charges/actions/list-charges.action.ts +0 -9
- package/src/modules/ia-credits/actions/list-ia-credits.action.ts +0 -8
- package/src/modules/pages/actions/count-pages.action.ts +0 -10
- package/src/modules/plans/actions/find-plan-by-id.action.ts +0 -8
- package/src/modules/plans/actions/list-plans.action.ts +0 -17
- package/src/modules/projects/actions/list-all-account-users.action.ts +0 -9
- package/src/modules/projects/actions/list-available-users.action.ts +0 -9
- package/src/modules/users/action/list-messages.action.ts +0 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@greatapps/common",
|
|
3
|
-
"version": "1.1.
|
|
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",
|
|
@@ -90,7 +90,6 @@
|
|
|
90
90
|
"react-hook-form": "^7.72.0",
|
|
91
91
|
"tsup": "^8.5.1",
|
|
92
92
|
"typescript": "^5.9.3",
|
|
93
|
-
"zod": "^4.3.6",
|
|
94
93
|
"zustand": "^5.0.12"
|
|
95
94
|
},
|
|
96
95
|
"peerDependencies": {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
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<
|
|
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<
|
|
31
|
+
apiFetch<ListMessagesResult>('/api/messages', {
|
|
32
32
|
params: {
|
|
33
33
|
...params,
|
|
34
34
|
page: pageParam as number,
|
package/src/route.ts
CHANGED
package/src/server.ts
CHANGED
|
@@ -27,21 +27,14 @@ export { findUserById } from './modules/users/action/find-user-by-id.action';
|
|
|
27
27
|
export { findCurrentAccount } from './modules/accounts/actions/find-current-account.action';
|
|
28
28
|
export { getAccountTokenAction } from './modules/accounts/actions/get-account-token.action';
|
|
29
29
|
export { listSubscriptionsAction } from './modules/subscriptions/actions/list-subscriptions.action';
|
|
30
|
-
export { findPlanByIdAction } from './modules/plans/actions/find-plan-by-id.action';
|
|
31
|
-
export { listPlansAction } from './modules/plans/actions/list-plans.action';
|
|
32
30
|
export { calculateSubscriptionAction } from './modules/subscriptions/actions/calculate-subscription.action';
|
|
33
31
|
export { updateSubscriptionPlanAction } from './modules/subscriptions/actions/update-subscription-plan.action';
|
|
34
32
|
export { updateSubscriptionPaymentAction } from './modules/subscriptions/actions/update-subscription-payment.action';
|
|
35
|
-
export { listCardsAction } from './modules/cards/actions/list-cards.action';
|
|
36
33
|
export { createCardAction } from './modules/cards/actions/create-card.action';
|
|
37
34
|
export { createSetupIntentAction } from './modules/cards/actions/create-setup-intent.action';
|
|
38
|
-
export { listChargesAction } from './modules/charges/actions/list-charges.action';
|
|
39
|
-
export { findChargeByIdAction } from './modules/charges/actions/find-charge-by-id.action';
|
|
40
35
|
export { chargeActionAction } from './modules/charges/actions/charge-action.action';
|
|
41
36
|
export { resolvePlanExtrasPrices } from './modules/subscriptions/utils/resolve-plan-extras-prices';
|
|
42
37
|
export { hasSubscriptionExpired } from './modules/subscriptions/utils/has-subscription-expired';
|
|
43
|
-
export { listIaCreditsAction } from './modules/ia-credits/actions/list-ia-credits.action';
|
|
44
|
-
export { countPagesAction } from './modules/pages/actions/count-pages.action';
|
|
45
38
|
|
|
46
39
|
// Project Services & Actions (server-only)
|
|
47
40
|
export { projectsService } from './modules/projects/services/projects.service';
|
|
@@ -54,7 +47,6 @@ export { deleteProjectAction } from './modules/projects/actions/delete-project.a
|
|
|
54
47
|
// Project Users Services & Actions (server-only)
|
|
55
48
|
export { projectUsersService } from './modules/projects/services/project-users.service';
|
|
56
49
|
export { listProjectUsersAction } from './modules/projects/actions/list-project-users.action';
|
|
57
|
-
export { listAvailableUsersAction } from './modules/projects/actions/list-available-users.action';
|
|
58
50
|
export { addProjectUserAction } from './modules/projects/actions/add-project-user.action';
|
|
59
51
|
export { removeProjectUserAction } from './modules/projects/actions/remove-project-user.action';
|
|
60
52
|
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
-
import { cardsService } from '../services/cards.service';
|
|
5
|
-
|
|
6
|
-
export async function findCardByIdAction(id: number) {
|
|
7
|
-
return safeServerAction(() => cardsService.findCardById(id));
|
|
8
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
-
import { chargesService } from '../services/charges.service';
|
|
5
|
-
|
|
6
|
-
export async function findChargeByIdAction(chargeId: string | number) {
|
|
7
|
-
return safeServerAction(() => chargesService.findChargeById(chargeId));
|
|
8
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
-
import type { FindChargesParams } from '../types/charge.type';
|
|
5
|
-
import { chargesService } from '../services/charges.service';
|
|
6
|
-
|
|
7
|
-
export async function listChargesAction(params?: Partial<FindChargesParams>) {
|
|
8
|
-
return safeServerAction(() => chargesService.listCharges(params));
|
|
9
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
-
import { iaCreditsService } from '../services/ia-credits.service';
|
|
5
|
-
|
|
6
|
-
export async function listIaCreditsAction(subscriptionId: number | string) {
|
|
7
|
-
return safeServerAction(() => iaCreditsService.listOperations(subscriptionId));
|
|
8
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
-
import { pagesService } from '../services/pages.service';
|
|
5
|
-
|
|
6
|
-
export async function countPagesAction() {
|
|
7
|
-
return safeServerAction(async () => ({
|
|
8
|
-
total: await pagesService.countPages(),
|
|
9
|
-
}));
|
|
10
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
-
import { plansService } from '../services/plans.service';
|
|
5
|
-
|
|
6
|
-
export async function findPlanByIdAction(idPlan: number | string) {
|
|
7
|
-
return safeServerAction(() => plansService.findById(idPlan));
|
|
8
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import { plansService, safeServerAction } from '@greatapps/common/server';
|
|
4
|
-
|
|
5
|
-
export async function listPlansAction() {
|
|
6
|
-
return safeServerAction(async () => {
|
|
7
|
-
const { data: apiPlans } = await plansService.listPlans({
|
|
8
|
-
active: true,
|
|
9
|
-
search: 'client',
|
|
10
|
-
sort: 'id:ASC',
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
if (!apiPlans?.length) return [];
|
|
14
|
-
|
|
15
|
-
return [...apiPlans].sort((a, b) => a.value - b.value);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
-
import { projectUsersService } from '../services/project-users.service';
|
|
5
|
-
import type { ListUsersParams } from '../types';
|
|
6
|
-
|
|
7
|
-
export async function listAllAccountUsersAction(params: ListUsersParams = {}) {
|
|
8
|
-
return safeServerAction(() => projectUsersService.listAllAccountUsers(params));
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
-
import { projectUsersService } from '../services/project-users.service';
|
|
5
|
-
import type { ListUsersParams } from '../types';
|
|
6
|
-
|
|
7
|
-
export async function listAvailableUsersAction(projectId: number, params: ListUsersParams = {}) {
|
|
8
|
-
return safeServerAction(() => projectUsersService.listNotInProject(projectId, params));
|
|
9
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
-
import { messagesService } from '../services/messages.service';
|
|
5
|
-
import type { FindMessagesParams } from '../schema/messages.schema';
|
|
6
|
-
import { findWhitelabel } from '../../whitelabel/actions/find-whitelabel.action';
|
|
7
|
-
|
|
8
|
-
export async function listMessagesAction(params?: Partial<FindMessagesParams>) {
|
|
9
|
-
return safeServerAction(async () => {
|
|
10
|
-
const [result, whitelabel] = await Promise.all([
|
|
11
|
-
messagesService.listMessages(params),
|
|
12
|
-
findWhitelabel(),
|
|
13
|
-
]);
|
|
14
|
-
|
|
15
|
-
const urlMap: Record<string, string> = {
|
|
16
|
-
pages_url: whitelabel?.pages_url ?? '',
|
|
17
|
-
accounts_url: whitelabel?.accounts_url ?? '',
|
|
18
|
-
editor_url: whitelabel?.editor_url ?? '',
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
return { data: result.data.map((message) => ({
|
|
22
|
-
...message,
|
|
23
|
-
url: message.url.replace(/\{(pages_url|accounts_url|editor_url)\}/g, (_, key) => urlMap[key] ?? ''),
|
|
24
|
-
})), total: result.total, totalUnread: result.totalUnread };
|
|
25
|
-
});
|
|
26
|
-
}
|