@greatapps/common 1.1.659 → 1.1.660
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/handlers.mjs +33 -0
- package/dist/handlers.mjs.map +1 -0
- package/dist/http.mjs +5 -0
- package/dist/http.mjs.map +1 -0
- package/dist/infra/http/api-fetch.mjs +30 -0
- package/dist/infra/http/api-fetch.mjs.map +1 -0
- package/dist/infra/route/parse-id.mjs +12 -0
- package/dist/infra/route/parse-id.mjs.map +1 -0
- package/dist/infra/route/safe-route-handler.mjs +18 -0
- package/dist/infra/route/safe-route-handler.mjs.map +1 -0
- package/dist/infra/route/search-params.mjs +11 -0
- package/dist/infra/route/search-params.mjs.map +1 -0
- package/dist/modules/cards/handlers/find-card-by-id.handler.mjs +16 -0
- package/dist/modules/cards/handlers/find-card-by-id.handler.mjs.map +1 -0
- package/dist/modules/cards/handlers/list-cards.handler.mjs +12 -0
- package/dist/modules/cards/handlers/list-cards.handler.mjs.map +1 -0
- package/dist/modules/cards/hooks/card-by-id.hook.mjs +2 -5
- package/dist/modules/cards/hooks/card-by-id.hook.mjs.map +1 -1
- package/dist/modules/cards/hooks/cards.hook.mjs +2 -5
- package/dist/modules/cards/hooks/cards.hook.mjs.map +1 -1
- package/dist/modules/charges/handlers/find-charge-by-id.handler.mjs +15 -0
- package/dist/modules/charges/handlers/find-charge-by-id.handler.mjs.map +1 -0
- package/dist/modules/charges/handlers/list-charges.handler.mjs +15 -0
- package/dist/modules/charges/handlers/list-charges.handler.mjs.map +1 -0
- package/dist/modules/charges/hooks/charge-by-id.hook.mjs +2 -3
- package/dist/modules/charges/hooks/charge-by-id.hook.mjs.map +1 -1
- package/dist/modules/charges/hooks/charges.hook.mjs +2 -3
- package/dist/modules/charges/hooks/charges.hook.mjs.map +1 -1
- package/dist/modules/ia-credits/handlers/list-ia-credits.handler.mjs +15 -0
- package/dist/modules/ia-credits/handlers/list-ia-credits.handler.mjs.map +1 -0
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs +5 -3
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs.map +1 -1
- package/dist/modules/pages/handlers/count-pages.handler.mjs +14 -0
- package/dist/modules/pages/handlers/count-pages.handler.mjs.map +1 -0
- package/dist/modules/pages/hooks/count-pages.hook.mjs +3 -4
- package/dist/modules/pages/hooks/count-pages.hook.mjs.map +1 -1
- package/dist/modules/plans/handlers/find-plan-by-id.handler.mjs +15 -0
- package/dist/modules/plans/handlers/find-plan-by-id.handler.mjs.map +1 -0
- package/dist/modules/plans/handlers/list-plans.handler.mjs +20 -0
- package/dist/modules/plans/handlers/list-plans.handler.mjs.map +1 -0
- package/dist/modules/plans/hooks/list-plans.hook.mjs +2 -3
- package/dist/modules/plans/hooks/list-plans.hook.mjs.map +1 -1
- package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs +2 -3
- package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs.map +1 -1
- package/dist/modules/projects/handlers/find-project.handler.mjs +16 -0
- package/dist/modules/projects/handlers/find-project.handler.mjs.map +1 -0
- package/dist/modules/projects/handlers/list-all-account-users.handler.mjs +17 -0
- package/dist/modules/projects/handlers/list-all-account-users.handler.mjs.map +1 -0
- package/dist/modules/projects/handlers/list-available-users.handler.mjs +20 -0
- package/dist/modules/projects/handlers/list-available-users.handler.mjs.map +1 -0
- package/dist/modules/projects/handlers/list-project-users.handler.mjs +20 -0
- package/dist/modules/projects/handlers/list-project-users.handler.mjs.map +1 -0
- package/dist/modules/projects/handlers/list-projects.handler.mjs +17 -0
- package/dist/modules/projects/handlers/list-projects.handler.mjs.map +1 -0
- package/dist/modules/projects/hooks/find-project.hook.mjs +2 -3
- package/dist/modules/projects/hooks/find-project.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-all-account-users.hook.mjs +6 -6
- package/dist/modules/projects/hooks/list-all-account-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-available-users.hook.mjs +6 -6
- package/dist/modules/projects/hooks/list-available-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs +6 -6
- package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-project-users.hook.mjs +6 -6
- package/dist/modules/projects/hooks/list-project-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-projects.hook.mjs +2 -3
- package/dist/modules/projects/hooks/list-projects.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/handlers/list-subscriptions.handler.mjs +17 -0
- package/dist/modules/subscriptions/handlers/list-subscriptions.handler.mjs.map +1 -0
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs +5 -5
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs +5 -3
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs.map +1 -1
- package/dist/modules/users/handlers/list-messages.handler.mjs +36 -0
- package/dist/modules/users/handlers/list-messages.handler.mjs.map +1 -0
- package/dist/modules/users/hooks/messages.hook.mjs +7 -6
- package/dist/modules/users/hooks/messages.hook.mjs.map +1 -1
- package/dist/route.mjs +9 -0
- package/dist/route.mjs.map +1 -0
- package/package.json +14 -1
- package/src/handlers.ts +22 -0
- package/src/http.ts +1 -0
- package/src/infra/http/api-fetch.ts +39 -0
- package/src/infra/route/parse-id.ts +9 -0
- package/src/infra/route/safe-route-handler.ts +16 -0
- package/src/infra/route/search-params.ts +9 -0
- package/src/modules/cards/handlers/find-card-by-id.handler.ts +15 -0
- package/src/modules/cards/handlers/list-cards.handler.ts +10 -0
- package/src/modules/cards/hooks/card-by-id.hook.ts +4 -5
- package/src/modules/cards/hooks/cards.hook.ts +4 -5
- package/src/modules/charges/handlers/find-charge-by-id.handler.ts +14 -0
- package/src/modules/charges/handlers/list-charges.handler.ts +15 -0
- package/src/modules/charges/hooks/charge-by-id.hook.ts +5 -3
- package/src/modules/charges/hooks/charges.hook.ts +5 -4
- package/src/modules/ia-credits/handlers/list-ia-credits.handler.ts +14 -0
- package/src/modules/ia-credits/hooks/ia-credits.hook.ts +7 -3
- package/src/modules/pages/handlers/count-pages.handler.ts +12 -0
- package/src/modules/pages/hooks/count-pages.hook.ts +3 -4
- package/src/modules/plans/handlers/find-plan-by-id.handler.ts +14 -0
- package/src/modules/plans/handlers/list-plans.handler.ts +20 -0
- package/src/modules/plans/hooks/list-plans.hook.ts +2 -3
- package/src/modules/plans/hooks/use-plan-by-id.hook.ts +4 -3
- package/src/modules/projects/handlers/find-project.handler.ts +15 -0
- package/src/modules/projects/handlers/list-all-account-users.handler.ts +17 -0
- package/src/modules/projects/handlers/list-available-users.handler.ts +20 -0
- package/src/modules/projects/handlers/list-project-users.handler.ts +20 -0
- package/src/modules/projects/handlers/list-projects.handler.ts +17 -0
- package/src/modules/projects/hooks/find-project.hook.ts +3 -3
- package/src/modules/projects/hooks/list-all-account-users.hook.ts +8 -7
- package/src/modules/projects/hooks/list-available-users.hook.ts +8 -7
- package/src/modules/projects/hooks/list-infinite-projects.hook.ts +8 -7
- package/src/modules/projects/hooks/list-project-users.hook.ts +8 -7
- package/src/modules/projects/hooks/list-projects.hook.ts +3 -3
- package/src/modules/subscriptions/handlers/list-subscriptions.handler.ts +17 -0
- package/src/modules/subscriptions/hooks/find-active-subscription.hook.ts +8 -5
- package/src/modules/subscriptions/hooks/list-subscriptions.hook.ts +8 -5
- package/src/modules/users/handlers/list-messages.handler.ts +39 -0
- package/src/modules/users/hooks/messages.hook.ts +10 -8
- package/src/route.ts +3 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { apiFetch } from '../../../infra/http/api-fetch';
|
|
5
|
+
import type { ProjectUser, UsersPage } from '../types';
|
|
6
6
|
import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
|
|
7
7
|
|
|
8
8
|
const PAGE_SIZE = 20;
|
|
@@ -20,14 +20,15 @@ export function useListProjectUsers(projectId: number, search: string = '') {
|
|
|
20
20
|
|
|
21
21
|
return useInfiniteQuery({
|
|
22
22
|
queryKey,
|
|
23
|
-
queryFn: ({ pageParam }) =>
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
queryFn: ({ pageParam, signal }) =>
|
|
24
|
+
apiFetch<UsersPage<ProjectUser>>(`/api/projects/${projectId}/users`, {
|
|
25
|
+
params: {
|
|
26
26
|
search: search || undefined,
|
|
27
27
|
page: pageParam as number,
|
|
28
28
|
limit: PAGE_SIZE,
|
|
29
|
-
}
|
|
30
|
-
|
|
29
|
+
},
|
|
30
|
+
signal,
|
|
31
|
+
}),
|
|
31
32
|
getNextPageParam: (lastPage, allPages) => {
|
|
32
33
|
const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);
|
|
33
34
|
return loaded < lastPage.total ? allPages.length + 1 : undefined;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useQuery, keepPreviousData } from '@tanstack/react-query';
|
|
4
|
-
import {
|
|
4
|
+
import { apiFetch } from '../../../infra/http/api-fetch';
|
|
5
5
|
import type { ListProjectsActionParams } from '../actions/list-projects.action';
|
|
6
|
-
import {
|
|
6
|
+
import type { ProjectsPage } from '../types';
|
|
7
7
|
import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
|
|
8
8
|
|
|
9
9
|
export const PROJECTS_BASE_KEY = ['projects'] as const;
|
|
@@ -16,7 +16,7 @@ export function useProjects(params?: ListProjectsActionParams) {
|
|
|
16
16
|
|
|
17
17
|
return useQuery({
|
|
18
18
|
queryKey,
|
|
19
|
-
queryFn:
|
|
19
|
+
queryFn: ({ signal }) => apiFetch<ProjectsPage>('/api/projects', { params, signal }),
|
|
20
20
|
staleTime: 10_000,
|
|
21
21
|
placeholderData: keepPreviousData,
|
|
22
22
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import type { NextRequest } from 'next/server';
|
|
4
|
+
import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
|
|
5
|
+
import { searchParamsToParams } from '../../../infra/route/search-params';
|
|
6
|
+
import { subscriptionsService } from '../services/subscriptions.service';
|
|
7
|
+
import type { FindSubscriptionsParams } from '../types/subscription.type';
|
|
8
|
+
|
|
9
|
+
export function createListSubscriptionsHandler() {
|
|
10
|
+
return async function GET(req: NextRequest) {
|
|
11
|
+
return safeRouteHandler(() =>
|
|
12
|
+
subscriptionsService.listSubscriptions(
|
|
13
|
+
searchParamsToParams<FindSubscriptionsParams>(req.nextUrl.searchParams)
|
|
14
|
+
)
|
|
15
|
+
);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { useQuery } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
4
|
+
import { apiFetch } from "../../../infra/http/api-fetch";
|
|
5
|
+
import type { PaginatedSuccessResult } from "../../../infra/api/types";
|
|
6
|
+
import type { Subscription } from "../types/subscription.type";
|
|
5
7
|
import { SUBSCRIPTIONS_QUERY_KEY } from "../constants/query-keys.constants";
|
|
6
|
-
import { withAction } from "../../../utils/withAction";
|
|
7
8
|
import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
|
|
8
9
|
|
|
9
10
|
export function useActiveSubscription() {
|
|
@@ -11,9 +12,11 @@ export function useActiveSubscription() {
|
|
|
11
12
|
|
|
12
13
|
return useQuery({
|
|
13
14
|
queryKey,
|
|
14
|
-
queryFn:
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
queryFn: ({ signal }) =>
|
|
16
|
+
apiFetch<PaginatedSuccessResult<Subscription>>('/api/subscriptions', {
|
|
17
|
+
params: { limit: 1 },
|
|
18
|
+
signal,
|
|
19
|
+
}),
|
|
17
20
|
staleTime: 10_000,
|
|
18
21
|
});
|
|
19
22
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useQuery } from '@tanstack/react-query';
|
|
4
|
-
import {
|
|
4
|
+
import { apiFetch } from '../../../infra/http/api-fetch';
|
|
5
|
+
import type { PaginatedSuccessResult } from '../../../infra/api/types';
|
|
5
6
|
import { parseResult } from '../../../infra/utils/parser';
|
|
6
|
-
import { SubscriptionSchema, type FindSubscriptionsParams } from '../types/subscription.type';
|
|
7
|
-
import { withAction } from '../../../utils/withAction';
|
|
7
|
+
import { SubscriptionSchema, type Subscription, type FindSubscriptionsParams } from '../types/subscription.type';
|
|
8
8
|
import { SUBSCRIPTIONS_QUERY_KEY } from '../constants/query-keys.constants';
|
|
9
9
|
import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
|
|
10
10
|
|
|
@@ -13,7 +13,10 @@ export function useSubscriptions(params?: Partial<FindSubscriptionsParams>) {
|
|
|
13
13
|
|
|
14
14
|
return useQuery({
|
|
15
15
|
queryKey,
|
|
16
|
-
queryFn: async () =>
|
|
17
|
-
parseResult(
|
|
16
|
+
queryFn: async ({ signal }) =>
|
|
17
|
+
parseResult(
|
|
18
|
+
SubscriptionSchema,
|
|
19
|
+
await apiFetch<PaginatedSuccessResult<Subscription>>('/api/subscriptions', { params, signal })
|
|
20
|
+
),
|
|
18
21
|
});
|
|
19
22
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import type { NextRequest } from 'next/server';
|
|
4
|
+
import { safeRouteHandler } from '../../../infra/route/safe-route-handler';
|
|
5
|
+
import { searchParamsToParams } from '../../../infra/route/search-params';
|
|
6
|
+
import { messagesService } from '../services/messages.service';
|
|
7
|
+
import type { FindMessagesParams } from '../schema/messages.schema';
|
|
8
|
+
import { findWhitelabel } from '../../whitelabel/actions/find-whitelabel.action';
|
|
9
|
+
|
|
10
|
+
export function createListMessagesHandler() {
|
|
11
|
+
return async function GET(req: NextRequest) {
|
|
12
|
+
return safeRouteHandler(async () => {
|
|
13
|
+
const params = searchParamsToParams<FindMessagesParams>(req.nextUrl.searchParams);
|
|
14
|
+
|
|
15
|
+
const [result, whitelabel] = await Promise.all([
|
|
16
|
+
messagesService.listMessages(params),
|
|
17
|
+
findWhitelabel(),
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
const urlMap: Record<string, string> = {
|
|
21
|
+
pages_url: whitelabel?.pages_url ?? '',
|
|
22
|
+
accounts_url: whitelabel?.accounts_url ?? '',
|
|
23
|
+
editor_url: whitelabel?.editor_url ?? '',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
data: result.data.map((message) => ({
|
|
28
|
+
...message,
|
|
29
|
+
url: message.url.replace(
|
|
30
|
+
/\{(pages_url|accounts_url|editor_url)\}/g,
|
|
31
|
+
(_, key) => urlMap[key] ?? ''
|
|
32
|
+
),
|
|
33
|
+
})),
|
|
34
|
+
total: result.total,
|
|
35
|
+
totalUnread: result.totalUnread,
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
4
|
-
import {
|
|
4
|
+
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 } from '../schema/messages.schema';
|
|
8
|
+
import type { FindMessagesParams, ListMessagesApiResponse } from '../schema/messages.schema';
|
|
9
9
|
import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
|
|
10
10
|
|
|
11
11
|
export const MESSAGES_QUERY_KEY = ['messages'] as const;
|
|
@@ -17,7 +17,8 @@ export function useMessages(params?: Partial<FindMessagesParams>) {
|
|
|
17
17
|
|
|
18
18
|
return useQuery({
|
|
19
19
|
queryKey,
|
|
20
|
-
queryFn:
|
|
20
|
+
queryFn: ({ signal }) =>
|
|
21
|
+
apiFetch<ListMessagesApiResponse>('/api/messages', { params, signal }),
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -26,14 +27,15 @@ export function useInfiniteMessages(params?: Partial<Omit<FindMessagesParams, 'p
|
|
|
26
27
|
|
|
27
28
|
return useInfiniteQuery({
|
|
28
29
|
queryKey,
|
|
29
|
-
queryFn: ({ pageParam }) =>
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
queryFn: ({ pageParam, signal }) =>
|
|
31
|
+
apiFetch<ListMessagesApiResponse>('/api/messages', {
|
|
32
|
+
params: {
|
|
32
33
|
...params,
|
|
33
34
|
page: pageParam as number,
|
|
34
35
|
limit: INFINITE_MESSAGES_PAGE_SIZE,
|
|
35
|
-
}
|
|
36
|
-
|
|
36
|
+
},
|
|
37
|
+
signal,
|
|
38
|
+
}),
|
|
37
39
|
getNextPageParam: (lastPage, allPages) => {
|
|
38
40
|
const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);
|
|
39
41
|
return loaded < lastPage.total ? allPages.length + 1 : undefined;
|
package/src/route.ts
ADDED