@greatapps/common 1.1.658 → 1.1.659

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 (124) hide show
  1. package/dist/components/account/sections/TokenSection.mjs +1 -1
  2. package/dist/components/account/sections/TokenSection.mjs.map +1 -1
  3. package/dist/components/embeds/CrispEmbed.mjs +8 -29
  4. package/dist/components/embeds/CrispEmbed.mjs.map +1 -1
  5. package/dist/modules/cards/hooks/card-by-id.hook.mjs +5 -2
  6. package/dist/modules/cards/hooks/card-by-id.hook.mjs.map +1 -1
  7. package/dist/modules/cards/hooks/cards.hook.mjs +5 -2
  8. package/dist/modules/cards/hooks/cards.hook.mjs.map +1 -1
  9. package/dist/modules/charges/hooks/charge-by-id.hook.mjs +3 -2
  10. package/dist/modules/charges/hooks/charge-by-id.hook.mjs.map +1 -1
  11. package/dist/modules/charges/hooks/charges.hook.mjs +3 -2
  12. package/dist/modules/charges/hooks/charges.hook.mjs.map +1 -1
  13. package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs +3 -5
  14. package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs.map +1 -1
  15. package/dist/modules/pages/hooks/count-pages.hook.mjs +4 -3
  16. package/dist/modules/pages/hooks/count-pages.hook.mjs.map +1 -1
  17. package/dist/modules/plans/hooks/list-plans.hook.mjs +3 -2
  18. package/dist/modules/plans/hooks/list-plans.hook.mjs.map +1 -1
  19. package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs +3 -2
  20. package/dist/modules/plans/hooks/use-plan-by-id.hook.mjs.map +1 -1
  21. package/dist/modules/projects/hooks/find-project.hook.mjs +3 -2
  22. package/dist/modules/projects/hooks/find-project.hook.mjs.map +1 -1
  23. package/dist/modules/projects/hooks/list-all-account-users.hook.mjs +6 -6
  24. package/dist/modules/projects/hooks/list-all-account-users.hook.mjs.map +1 -1
  25. package/dist/modules/projects/hooks/list-available-users.hook.mjs +6 -6
  26. package/dist/modules/projects/hooks/list-available-users.hook.mjs.map +1 -1
  27. package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs +6 -6
  28. package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs.map +1 -1
  29. package/dist/modules/projects/hooks/list-project-users.hook.mjs +6 -6
  30. package/dist/modules/projects/hooks/list-project-users.hook.mjs.map +1 -1
  31. package/dist/modules/projects/hooks/list-projects.hook.mjs +3 -2
  32. package/dist/modules/projects/hooks/list-projects.hook.mjs.map +1 -1
  33. package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs +5 -5
  34. package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs.map +1 -1
  35. package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs +3 -5
  36. package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs.map +1 -1
  37. package/dist/modules/users/hooks/messages.hook.mjs +6 -7
  38. package/dist/modules/users/hooks/messages.hook.mjs.map +1 -1
  39. package/package.json +2 -14
  40. package/src/components/account/sections/TokenSection.tsx +1 -1
  41. package/src/components/embeds/CrispEmbed.tsx +11 -34
  42. package/src/modules/cards/hooks/card-by-id.hook.ts +5 -4
  43. package/src/modules/cards/hooks/cards.hook.ts +5 -4
  44. package/src/modules/charges/hooks/charge-by-id.hook.ts +3 -5
  45. package/src/modules/charges/hooks/charges.hook.ts +4 -5
  46. package/src/modules/ia-credits/hooks/ia-credits.hook.ts +3 -7
  47. package/src/modules/pages/hooks/count-pages.hook.ts +4 -3
  48. package/src/modules/plans/hooks/list-plans.hook.ts +3 -2
  49. package/src/modules/plans/hooks/use-plan-by-id.hook.ts +3 -4
  50. package/src/modules/projects/hooks/find-project.hook.ts +3 -3
  51. package/src/modules/projects/hooks/list-all-account-users.hook.ts +7 -8
  52. package/src/modules/projects/hooks/list-available-users.hook.ts +7 -8
  53. package/src/modules/projects/hooks/list-infinite-projects.hook.ts +7 -8
  54. package/src/modules/projects/hooks/list-project-users.hook.ts +7 -8
  55. package/src/modules/projects/hooks/list-projects.hook.ts +3 -3
  56. package/src/modules/subscriptions/hooks/find-active-subscription.hook.ts +5 -8
  57. package/src/modules/subscriptions/hooks/list-subscriptions.hook.ts +5 -8
  58. package/src/modules/users/hooks/messages.hook.ts +8 -10
  59. package/dist/handlers.mjs +0 -33
  60. package/dist/handlers.mjs.map +0 -1
  61. package/dist/http.mjs +0 -5
  62. package/dist/http.mjs.map +0 -1
  63. package/dist/infra/http/api-fetch.mjs +0 -30
  64. package/dist/infra/http/api-fetch.mjs.map +0 -1
  65. package/dist/infra/route/parse-id.mjs +0 -12
  66. package/dist/infra/route/parse-id.mjs.map +0 -1
  67. package/dist/infra/route/safe-route-handler.mjs +0 -18
  68. package/dist/infra/route/safe-route-handler.mjs.map +0 -1
  69. package/dist/infra/route/search-params.mjs +0 -11
  70. package/dist/infra/route/search-params.mjs.map +0 -1
  71. package/dist/modules/cards/handlers/find-card-by-id.handler.mjs +0 -16
  72. package/dist/modules/cards/handlers/find-card-by-id.handler.mjs.map +0 -1
  73. package/dist/modules/cards/handlers/list-cards.handler.mjs +0 -12
  74. package/dist/modules/cards/handlers/list-cards.handler.mjs.map +0 -1
  75. package/dist/modules/charges/handlers/find-charge-by-id.handler.mjs +0 -15
  76. package/dist/modules/charges/handlers/find-charge-by-id.handler.mjs.map +0 -1
  77. package/dist/modules/charges/handlers/list-charges.handler.mjs +0 -15
  78. package/dist/modules/charges/handlers/list-charges.handler.mjs.map +0 -1
  79. package/dist/modules/ia-credits/handlers/list-ia-credits.handler.mjs +0 -15
  80. package/dist/modules/ia-credits/handlers/list-ia-credits.handler.mjs.map +0 -1
  81. package/dist/modules/pages/handlers/count-pages.handler.mjs +0 -14
  82. package/dist/modules/pages/handlers/count-pages.handler.mjs.map +0 -1
  83. package/dist/modules/plans/handlers/find-plan-by-id.handler.mjs +0 -15
  84. package/dist/modules/plans/handlers/find-plan-by-id.handler.mjs.map +0 -1
  85. package/dist/modules/plans/handlers/list-plans.handler.mjs +0 -20
  86. package/dist/modules/plans/handlers/list-plans.handler.mjs.map +0 -1
  87. package/dist/modules/projects/handlers/find-project.handler.mjs +0 -16
  88. package/dist/modules/projects/handlers/find-project.handler.mjs.map +0 -1
  89. package/dist/modules/projects/handlers/list-all-account-users.handler.mjs +0 -17
  90. package/dist/modules/projects/handlers/list-all-account-users.handler.mjs.map +0 -1
  91. package/dist/modules/projects/handlers/list-available-users.handler.mjs +0 -20
  92. package/dist/modules/projects/handlers/list-available-users.handler.mjs.map +0 -1
  93. package/dist/modules/projects/handlers/list-project-users.handler.mjs +0 -20
  94. package/dist/modules/projects/handlers/list-project-users.handler.mjs.map +0 -1
  95. package/dist/modules/projects/handlers/list-projects.handler.mjs +0 -17
  96. package/dist/modules/projects/handlers/list-projects.handler.mjs.map +0 -1
  97. package/dist/modules/subscriptions/handlers/list-subscriptions.handler.mjs +0 -17
  98. package/dist/modules/subscriptions/handlers/list-subscriptions.handler.mjs.map +0 -1
  99. package/dist/modules/users/handlers/list-messages.handler.mjs +0 -36
  100. package/dist/modules/users/handlers/list-messages.handler.mjs.map +0 -1
  101. package/dist/route.mjs +0 -9
  102. package/dist/route.mjs.map +0 -1
  103. package/src/handlers.ts +0 -22
  104. package/src/http.ts +0 -1
  105. package/src/infra/http/api-fetch.ts +0 -39
  106. package/src/infra/route/parse-id.ts +0 -9
  107. package/src/infra/route/safe-route-handler.ts +0 -16
  108. package/src/infra/route/search-params.ts +0 -9
  109. package/src/modules/cards/handlers/find-card-by-id.handler.ts +0 -15
  110. package/src/modules/cards/handlers/list-cards.handler.ts +0 -10
  111. package/src/modules/charges/handlers/find-charge-by-id.handler.ts +0 -14
  112. package/src/modules/charges/handlers/list-charges.handler.ts +0 -15
  113. package/src/modules/ia-credits/handlers/list-ia-credits.handler.ts +0 -14
  114. package/src/modules/pages/handlers/count-pages.handler.ts +0 -12
  115. package/src/modules/plans/handlers/find-plan-by-id.handler.ts +0 -14
  116. package/src/modules/plans/handlers/list-plans.handler.ts +0 -20
  117. package/src/modules/projects/handlers/find-project.handler.ts +0 -15
  118. package/src/modules/projects/handlers/list-all-account-users.handler.ts +0 -17
  119. package/src/modules/projects/handlers/list-available-users.handler.ts +0 -20
  120. package/src/modules/projects/handlers/list-project-users.handler.ts +0 -20
  121. package/src/modules/projects/handlers/list-projects.handler.ts +0 -17
  122. package/src/modules/subscriptions/handlers/list-subscriptions.handler.ts +0 -17
  123. package/src/modules/users/handlers/list-messages.handler.ts +0 -39
  124. package/src/route.ts +0 -3
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { useInfiniteQuery } from "@tanstack/react-query";
3
- import { apiFetch } from "../../../infra/http/api-fetch";
3
+ import { listProjectUsersAction } from "../actions/list-project-users.action";
4
+ import { withAction } from "../../../utils/withAction";
4
5
  import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
5
6
  const PAGE_SIZE = 20;
6
7
  const LIST_PROJECT_USERS_BASE_KEY = (projectId) => ["project-users", projectId, "in"];
@@ -12,14 +13,13 @@ function useListProjectUsers(projectId, search = "") {
12
13
  const queryKey = useAuthQueryKey([...LIST_PROJECT_USERS_QUERY_KEY(projectId, search)]);
13
14
  return useInfiniteQuery({
14
15
  queryKey,
15
- queryFn: ({ pageParam, signal }) => apiFetch(`/api/projects/${projectId}/users`, {
16
- params: {
16
+ queryFn: ({ pageParam }) => withAction(
17
+ () => listProjectUsersAction(projectId, {
17
18
  search: search || void 0,
18
19
  page: pageParam,
19
20
  limit: PAGE_SIZE
20
- },
21
- signal
22
- }),
21
+ })
22
+ )(),
23
23
  getNextPageParam: (lastPage, allPages) => {
24
24
  const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);
25
25
  return loaded < lastPage.total ? allPages.length + 1 : void 0;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/projects/hooks/list-project-users.hook.ts"],"sourcesContent":["'use client';\n\nimport { useInfiniteQuery } from '@tanstack/react-query';\nimport { apiFetch } from '../../../infra/http/api-fetch';\nimport type { ProjectUser, UsersPage } from '../types';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\n\nconst PAGE_SIZE = 20;\n\nexport const LIST_PROJECT_USERS_BASE_KEY = (projectId: number) =>\n ['project-users', projectId, 'in'] as const;\n\nexport const LIST_PROJECT_USERS_QUERY_KEY = (projectId: number, search: string = '') => [\n ...LIST_PROJECT_USERS_BASE_KEY(projectId),\n search,\n] as const;\n\nexport function useListProjectUsers(projectId: number, search: string = '') {\n const queryKey = useAuthQueryKey([...LIST_PROJECT_USERS_QUERY_KEY(projectId, search)]);\n\n return useInfiniteQuery({\n queryKey,\n queryFn: ({ pageParam, signal }) =>\n apiFetch<UsersPage<ProjectUser>>(`/api/projects/${projectId}/users`, {\n params: {\n search: search || undefined,\n page: pageParam as number,\n limit: PAGE_SIZE,\n },\n signal,\n }),\n getNextPageParam: (lastPage, allPages) => {\n const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);\n return loaded < lastPage.total ? allPages.length + 1 : undefined;\n },\n initialPageParam: 1,\n enabled: !!projectId,\n });\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,gBAAgB;AAEzB,SAAS,uBAAuB;AAEhC,MAAM,YAAY;AAEX,MAAM,8BAA8B,CAAC,cAC1C,CAAC,iBAAiB,WAAW,IAAI;AAE5B,MAAM,+BAA+B,CAAC,WAAmB,SAAiB,OAAO;AAAA,EACtF,GAAG,4BAA4B,SAAS;AAAA,EACxC;AACF;AAEO,SAAS,oBAAoB,WAAmB,SAAiB,IAAI;AAC1E,QAAM,WAAW,gBAAgB,CAAC,GAAG,6BAA6B,WAAW,MAAM,CAAC,CAAC;AAErF,SAAO,iBAAiB;AAAA,IACtB;AAAA,IACA,SAAS,CAAC,EAAE,WAAW,OAAO,MAC5B,SAAiC,iBAAiB,SAAS,UAAU;AAAA,MACnE,QAAQ;AAAA,QACN,QAAQ,UAAU;AAAA,QAClB,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,kBAAkB,CAAC,UAAU,aAAa;AACxC,YAAM,SAAS,SAAS,OAAO,CAAC,KAAK,MAAM,MAAM,EAAE,KAAK,QAAQ,CAAC;AACjE,aAAO,SAAS,SAAS,QAAQ,SAAS,SAAS,IAAI;AAAA,IACzD;AAAA,IACA,kBAAkB;AAAA,IAClB,SAAS,CAAC,CAAC;AAAA,EACb,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/projects/hooks/list-project-users.hook.ts"],"sourcesContent":["'use client';\n\nimport { useInfiniteQuery } from '@tanstack/react-query';\nimport { listProjectUsersAction } from '../actions/list-project-users.action';\nimport { withAction } from '../../../utils/withAction';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\n\nconst PAGE_SIZE = 20;\n\nexport const LIST_PROJECT_USERS_BASE_KEY = (projectId: number) =>\n ['project-users', projectId, 'in'] as const;\n\nexport const LIST_PROJECT_USERS_QUERY_KEY = (projectId: number, search: string = '') => [\n ...LIST_PROJECT_USERS_BASE_KEY(projectId),\n search,\n] as const;\n\nexport function useListProjectUsers(projectId: number, search: string = '') {\n const queryKey = useAuthQueryKey([...LIST_PROJECT_USERS_QUERY_KEY(projectId, search)]);\n\n return useInfiniteQuery({\n queryKey,\n queryFn: ({ pageParam }) =>\n withAction(() =>\n listProjectUsersAction(projectId, {\n search: search || undefined,\n page: pageParam as number,\n limit: PAGE_SIZE,\n })\n )(),\n getNextPageParam: (lastPage, allPages) => {\n const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);\n return loaded < lastPage.total ? allPages.length + 1 : undefined;\n },\n initialPageParam: 1,\n enabled: !!projectId,\n });\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,8BAA8B;AACvC,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAEhC,MAAM,YAAY;AAEX,MAAM,8BAA8B,CAAC,cAC1C,CAAC,iBAAiB,WAAW,IAAI;AAE5B,MAAM,+BAA+B,CAAC,WAAmB,SAAiB,OAAO;AAAA,EACtF,GAAG,4BAA4B,SAAS;AAAA,EACxC;AACF;AAEO,SAAS,oBAAoB,WAAmB,SAAiB,IAAI;AAC1E,QAAM,WAAW,gBAAgB,CAAC,GAAG,6BAA6B,WAAW,MAAM,CAAC,CAAC;AAErF,SAAO,iBAAiB;AAAA,IACtB;AAAA,IACA,SAAS,CAAC,EAAE,UAAU,MACpB;AAAA,MAAW,MACT,uBAAuB,WAAW;AAAA,QAChC,QAAQ,UAAU;AAAA,QAClB,MAAM;AAAA,QACN,OAAO;AAAA,MACT,CAAC;AAAA,IACH,EAAE;AAAA,IACJ,kBAAkB,CAAC,UAAU,aAAa;AACxC,YAAM,SAAS,SAAS,OAAO,CAAC,KAAK,MAAM,MAAM,EAAE,KAAK,QAAQ,CAAC;AACjE,aAAO,SAAS,SAAS,QAAQ,SAAS,SAAS,IAAI;AAAA,IACzD;AAAA,IACA,kBAAkB;AAAA,IAClB,SAAS,CAAC,CAAC;AAAA,EACb,CAAC;AACH;","names":[]}
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { useQuery, keepPreviousData } from "@tanstack/react-query";
3
- import { apiFetch } from "../../../infra/http/api-fetch";
3
+ import { listProjectsAction } from "../actions/list-projects.action";
4
+ import { withAction } from "../../../utils/withAction";
4
5
  import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
5
6
  const PROJECTS_BASE_KEY = ["projects"];
6
7
  const PROJECTS_QUERY_KEY = (params) => [...PROJECTS_BASE_KEY, params];
@@ -8,7 +9,7 @@ function useProjects(params) {
8
9
  const queryKey = useAuthQueryKey([...PROJECTS_QUERY_KEY(params)]);
9
10
  return useQuery({
10
11
  queryKey,
11
- queryFn: ({ signal }) => apiFetch("/api/projects", { params, signal }),
12
+ queryFn: withAction(() => listProjectsAction(params)),
12
13
  staleTime: 1e4,
13
14
  placeholderData: keepPreviousData
14
15
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/projects/hooks/list-projects.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery, keepPreviousData } from '@tanstack/react-query';\nimport { apiFetch } from '../../../infra/http/api-fetch';\nimport type { ListProjectsActionParams } from '../actions/list-projects.action';\nimport type { ProjectsPage } from '../types';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport const PROJECTS_BASE_KEY = ['projects'] as const;\n\nexport const PROJECTS_QUERY_KEY = (params?: ListProjectsActionParams) =>\n [...PROJECTS_BASE_KEY, params] as const;\n\nexport function useProjects(params?: ListProjectsActionParams) {\n const queryKey = useAuthQueryKey([...PROJECTS_QUERY_KEY(params)]);\n\n return useQuery({\n queryKey,\n queryFn: ({ signal }) => apiFetch<ProjectsPage>('/api/projects', { params, signal }),\n staleTime: 10_000,\n placeholderData: keepPreviousData,\n });\n}\n"],"mappings":";AAEA,SAAS,UAAU,wBAAwB;AAC3C,SAAS,gBAAgB;AAGzB,SAAS,uBAAuB;AAEzB,MAAM,oBAAoB,CAAC,UAAU;AAErC,MAAM,qBAAqB,CAAC,WACjC,CAAC,GAAG,mBAAmB,MAAM;AAExB,SAAS,YAAY,QAAmC;AAC7D,QAAM,WAAW,gBAAgB,CAAC,GAAG,mBAAmB,MAAM,CAAC,CAAC;AAEhE,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,CAAC,EAAE,OAAO,MAAM,SAAuB,iBAAiB,EAAE,QAAQ,OAAO,CAAC;AAAA,IACnF,WAAW;AAAA,IACX,iBAAiB;AAAA,EACnB,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/projects/hooks/list-projects.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery, keepPreviousData } from '@tanstack/react-query';\nimport { listProjectsAction } from '../actions/list-projects.action';\nimport type { ListProjectsActionParams } from '../actions/list-projects.action';\nimport { withAction } from '../../../utils/withAction';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport const PROJECTS_BASE_KEY = ['projects'] as const;\n\nexport const PROJECTS_QUERY_KEY = (params?: ListProjectsActionParams) =>\n [...PROJECTS_BASE_KEY, params] as const;\n\nexport function useProjects(params?: ListProjectsActionParams) {\n const queryKey = useAuthQueryKey([...PROJECTS_QUERY_KEY(params)]);\n\n return useQuery({\n queryKey,\n queryFn: withAction(() => listProjectsAction(params)),\n staleTime: 10_000,\n placeholderData: keepPreviousData,\n });\n}\n"],"mappings":";AAEA,SAAS,UAAU,wBAAwB;AAC3C,SAAS,0BAA0B;AAEnC,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAEzB,MAAM,oBAAoB,CAAC,UAAU;AAErC,MAAM,qBAAqB,CAAC,WACjC,CAAC,GAAG,mBAAmB,MAAM;AAExB,SAAS,YAAY,QAAmC;AAC7D,QAAM,WAAW,gBAAgB,CAAC,GAAG,mBAAmB,MAAM,CAAC,CAAC;AAEhE,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,WAAW,MAAM,mBAAmB,MAAM,CAAC;AAAA,IACpD,WAAW;AAAA,IACX,iBAAiB;AAAA,EACnB,CAAC;AACH;","names":[]}
@@ -1,16 +1,16 @@
1
1
  "use client";
2
2
  import { useQuery } from "@tanstack/react-query";
3
- import { apiFetch } from "../../../infra/http/api-fetch";
3
+ import { listSubscriptionsAction } from "../actions/list-subscriptions.action";
4
4
  import { SUBSCRIPTIONS_QUERY_KEY } from "../constants/query-keys.constants";
5
+ import { withAction } from "../../../utils/withAction";
5
6
  import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
6
7
  function useActiveSubscription() {
7
8
  const queryKey = useAuthQueryKey([...SUBSCRIPTIONS_QUERY_KEY, "active"]);
8
9
  return useQuery({
9
10
  queryKey,
10
- queryFn: ({ signal }) => apiFetch("/api/subscriptions", {
11
- params: { limit: 1 },
12
- signal
13
- }),
11
+ queryFn: async () => {
12
+ return await withAction(listSubscriptionsAction)({ limit: 1 });
13
+ },
14
14
  staleTime: 1e4
15
15
  });
16
16
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/subscriptions/hooks/find-active-subscription.hook.ts"],"sourcesContent":["\"use client\";\n\nimport { useQuery } from \"@tanstack/react-query\";\nimport { apiFetch } from \"../../../infra/http/api-fetch\";\nimport type { PaginatedSuccessResult } from \"../../../infra/api/types\";\nimport type { Subscription } from \"../types/subscription.type\";\nimport { SUBSCRIPTIONS_QUERY_KEY } from \"../constants/query-keys.constants\";\nimport { useAuthQueryKey } from \"../../../hooks/useAuthQueryKey\";\n\nexport function useActiveSubscription() {\n const queryKey = useAuthQueryKey([...SUBSCRIPTIONS_QUERY_KEY, \"active\"]);\n\n return useQuery({\n queryKey,\n queryFn: ({ signal }) =>\n apiFetch<PaginatedSuccessResult<Subscription>>('/api/subscriptions', {\n params: { limit: 1 },\n signal,\n }),\n staleTime: 10_000,\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AAGzB,SAAS,+BAA+B;AACxC,SAAS,uBAAuB;AAEzB,SAAS,wBAAwB;AACtC,QAAM,WAAW,gBAAgB,CAAC,GAAG,yBAAyB,QAAQ,CAAC;AAEvE,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,CAAC,EAAE,OAAO,MACjB,SAA+C,sBAAsB;AAAA,MACnE,QAAQ,EAAE,OAAO,EAAE;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,IACH,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/subscriptions/hooks/find-active-subscription.hook.ts"],"sourcesContent":["\"use client\";\n\nimport { useQuery } from \"@tanstack/react-query\";\nimport { listSubscriptionsAction } from \"../actions/list-subscriptions.action\";\nimport { SUBSCRIPTIONS_QUERY_KEY } from \"../constants/query-keys.constants\";\nimport { withAction } from \"../../../utils/withAction\";\nimport { useAuthQueryKey } from \"../../../hooks/useAuthQueryKey\";\n\nexport function useActiveSubscription() {\n const queryKey = useAuthQueryKey([...SUBSCRIPTIONS_QUERY_KEY, \"active\"]);\n\n return useQuery({\n queryKey,\n queryFn: async () => {\n return await withAction(listSubscriptionsAction)({ limit: 1 });\n },\n staleTime: 10_000,\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,+BAA+B;AACxC,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAEzB,SAAS,wBAAwB;AACtC,QAAM,WAAW,gBAAgB,CAAC,GAAG,yBAAyB,QAAQ,CAAC;AAEvE,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,YAAY;AACnB,aAAO,MAAM,WAAW,uBAAuB,EAAE,EAAE,OAAO,EAAE,CAAC;AAAA,IAC/D;AAAA,IACA,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
@@ -1,18 +1,16 @@
1
1
  "use client";
2
2
  import { useQuery } from "@tanstack/react-query";
3
- import { apiFetch } from "../../../infra/http/api-fetch";
3
+ import { listSubscriptionsAction } from "../actions/list-subscriptions.action";
4
4
  import { parseResult } from "../../../infra/utils/parser";
5
5
  import { SubscriptionSchema } from "../types/subscription.type";
6
+ import { withAction } from "../../../utils/withAction";
6
7
  import { SUBSCRIPTIONS_QUERY_KEY } from "../constants/query-keys.constants";
7
8
  import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
8
9
  function useSubscriptions(params) {
9
10
  const queryKey = useAuthQueryKey([...SUBSCRIPTIONS_QUERY_KEY, params]);
10
11
  return useQuery({
11
12
  queryKey,
12
- queryFn: async ({ signal }) => parseResult(
13
- SubscriptionSchema,
14
- await apiFetch("/api/subscriptions", { params, signal })
15
- )
13
+ queryFn: async () => parseResult(SubscriptionSchema, await withAction(() => listSubscriptionsAction(params))())
16
14
  });
17
15
  }
18
16
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/subscriptions/hooks/list-subscriptions.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { apiFetch } from '../../../infra/http/api-fetch';\nimport type { PaginatedSuccessResult } from '../../../infra/api/types';\nimport { parseResult } from '../../../infra/utils/parser';\nimport { SubscriptionSchema, type Subscription, type FindSubscriptionsParams } from '../types/subscription.type';\nimport { SUBSCRIPTIONS_QUERY_KEY } from '../constants/query-keys.constants';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport function useSubscriptions(params?: Partial<FindSubscriptionsParams>) {\n const queryKey = useAuthQueryKey([...SUBSCRIPTIONS_QUERY_KEY, params]);\n\n return useQuery({\n queryKey,\n queryFn: async ({ signal }) =>\n parseResult(\n SubscriptionSchema,\n await apiFetch<PaginatedSuccessResult<Subscription>>('/api/subscriptions', { params, signal })\n ),\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AAEzB,SAAS,mBAAmB;AAC5B,SAAS,0BAA2E;AACpF,SAAS,+BAA+B;AACxC,SAAS,uBAAuB;AAEzB,SAAS,iBAAiB,QAA2C;AAC1E,QAAM,WAAW,gBAAgB,CAAC,GAAG,yBAAyB,MAAM,CAAC;AAErE,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,OAAO,EAAE,OAAO,MACvB;AAAA,MACE;AAAA,MACA,MAAM,SAA+C,sBAAsB,EAAE,QAAQ,OAAO,CAAC;AAAA,IAC/F;AAAA,EACJ,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/subscriptions/hooks/list-subscriptions.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { listSubscriptionsAction } from '../actions/list-subscriptions.action';\nimport { parseResult } from '../../../infra/utils/parser';\nimport { SubscriptionSchema, type FindSubscriptionsParams } from '../types/subscription.type';\nimport { withAction } from '../../../utils/withAction';\nimport { SUBSCRIPTIONS_QUERY_KEY } from '../constants/query-keys.constants';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport function useSubscriptions(params?: Partial<FindSubscriptionsParams>) {\n const queryKey = useAuthQueryKey([...SUBSCRIPTIONS_QUERY_KEY, params]);\n\n return useQuery({\n queryKey,\n queryFn: async () =>\n parseResult(SubscriptionSchema, await withAction(() => listSubscriptionsAction(params))()),\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,mBAAmB;AAC5B,SAAS,0BAAwD;AACjE,SAAS,kBAAkB;AAC3B,SAAS,+BAA+B;AACxC,SAAS,uBAAuB;AAEzB,SAAS,iBAAiB,QAA2C;AAC1E,QAAM,WAAW,gBAAgB,CAAC,GAAG,yBAAyB,MAAM,CAAC;AAErE,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,YACP,YAAY,oBAAoB,MAAM,WAAW,MAAM,wBAAwB,MAAM,CAAC,EAAE,CAAC;AAAA,EAC7F,CAAC;AACH;","names":[]}
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3
- import { apiFetch } from "../../../infra/http/api-fetch";
3
+ import { listMessagesAction } from "../action/list-messages.action";
4
4
  import { markMessageAsReadAction } from "../action/mark-message-as-read.action";
5
5
  import { markAllMessagesAsReadAction } from "../action/mark-all-messages-as-read.action";
6
6
  import { withAction } from "../../../utils/withAction";
@@ -11,21 +11,20 @@ function useMessages(params) {
11
11
  const queryKey = useAuthQueryKey([...MESSAGES_QUERY_KEY, params]);
12
12
  return useQuery({
13
13
  queryKey,
14
- queryFn: ({ signal }) => apiFetch("/api/messages", { params, signal })
14
+ queryFn: withAction(() => listMessagesAction(params))
15
15
  });
16
16
  }
17
17
  function useInfiniteMessages(params) {
18
18
  const queryKey = useAuthQueryKey([...MESSAGES_QUERY_KEY, "infinite", params]);
19
19
  return useInfiniteQuery({
20
20
  queryKey,
21
- queryFn: ({ pageParam, signal }) => apiFetch("/api/messages", {
22
- params: {
21
+ queryFn: ({ pageParam }) => withAction(
22
+ () => listMessagesAction({
23
23
  ...params,
24
24
  page: pageParam,
25
25
  limit: INFINITE_MESSAGES_PAGE_SIZE
26
- },
27
- signal
28
- }),
26
+ })
27
+ )(),
29
28
  getNextPageParam: (lastPage, allPages) => {
30
29
  const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);
31
30
  return loaded < lastPage.total ? allPages.length + 1 : void 0;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/users/hooks/messages.hook.ts"],"sourcesContent":["'use client';\n\nimport { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport { apiFetch } from '../../../infra/http/api-fetch';\nimport { markMessageAsReadAction } from '../action/mark-message-as-read.action';\nimport { markAllMessagesAsReadAction } from '../action/mark-all-messages-as-read.action';\nimport { withAction } from '../../../utils/withAction';\nimport type { FindMessagesParams, ListMessagesApiResponse } from '../schema/messages.schema';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport const MESSAGES_QUERY_KEY = ['messages'] as const;\n\nconst INFINITE_MESSAGES_PAGE_SIZE = 10;\n\nexport function useMessages(params?: Partial<FindMessagesParams>) {\n const queryKey = useAuthQueryKey([...MESSAGES_QUERY_KEY, params]);\n\n return useQuery({\n queryKey,\n queryFn: ({ signal }) =>\n apiFetch<ListMessagesApiResponse>('/api/messages', { params, signal }),\n });\n}\n\nexport function useInfiniteMessages(params?: Partial<Omit<FindMessagesParams, 'page' | 'limit'>>) {\n const queryKey = useAuthQueryKey([...MESSAGES_QUERY_KEY, 'infinite', params]);\n\n return useInfiniteQuery({\n queryKey,\n queryFn: ({ pageParam, signal }) =>\n apiFetch<ListMessagesApiResponse>('/api/messages', {\n params: {\n ...params,\n page: pageParam as number,\n limit: INFINITE_MESSAGES_PAGE_SIZE,\n },\n signal,\n }),\n getNextPageParam: (lastPage, allPages) => {\n const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);\n return loaded < lastPage.total ? allPages.length + 1 : undefined;\n },\n initialPageParam: 1,\n });\n}\n\nexport function useMarkMessageAsRead() {\n const queryClient = useQueryClient();\n const messagesKey = useAuthQueryKey([...MESSAGES_QUERY_KEY]);\n\n return useMutation({\n mutationFn: withAction(markMessageAsReadAction),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: messagesKey });\n },\n });\n}\n\nexport function useMarkAllMessagesAsRead() {\n const queryClient = useQueryClient();\n const messagesKey = useAuthQueryKey([...MESSAGES_QUERY_KEY]);\n\n return useMutation({\n mutationFn: withAction(markAllMessagesAsReadAction),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: messagesKey });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,kBAAkB,aAAa,UAAU,sBAAsB;AACxE,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,mCAAmC;AAC5C,SAAS,kBAAkB;AAE3B,SAAS,uBAAuB;AAEzB,MAAM,qBAAqB,CAAC,UAAU;AAE7C,MAAM,8BAA8B;AAE7B,SAAS,YAAY,QAAsC;AAChE,QAAM,WAAW,gBAAgB,CAAC,GAAG,oBAAoB,MAAM,CAAC;AAEhE,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,CAAC,EAAE,OAAO,MACjB,SAAkC,iBAAiB,EAAE,QAAQ,OAAO,CAAC;AAAA,EACzE,CAAC;AACH;AAEO,SAAS,oBAAoB,QAA8D;AAChG,QAAM,WAAW,gBAAgB,CAAC,GAAG,oBAAoB,YAAY,MAAM,CAAC;AAE5E,SAAO,iBAAiB;AAAA,IACtB;AAAA,IACA,SAAS,CAAC,EAAE,WAAW,OAAO,MAC5B,SAAkC,iBAAiB;AAAA,MACjD,QAAQ;AAAA,QACN,GAAG;AAAA,QACH,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,kBAAkB,CAAC,UAAU,aAAa;AACxC,YAAM,SAAS,SAAS,OAAO,CAAC,KAAK,MAAM,MAAM,EAAE,KAAK,QAAQ,CAAC;AACjE,aAAO,SAAS,SAAS,QAAQ,SAAS,SAAS,IAAI;AAAA,IACzD;AAAA,IACA,kBAAkB;AAAA,EACpB,CAAC;AACH;AAEO,SAAS,uBAAuB;AACrC,QAAM,cAAc,eAAe;AACnC,QAAM,cAAc,gBAAgB,CAAC,GAAG,kBAAkB,CAAC;AAE3D,SAAO,YAAY;AAAA,IACjB,YAAY,WAAW,uBAAuB;AAAA,IAC9C,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,YAAY,CAAC;AAAA,IACzD;AAAA,EACF,CAAC;AACH;AAEO,SAAS,2BAA2B;AACzC,QAAM,cAAc,eAAe;AACnC,QAAM,cAAc,gBAAgB,CAAC,GAAG,kBAAkB,CAAC;AAE3D,SAAO,YAAY;AAAA,IACjB,YAAY,WAAW,2BAA2B;AAAA,IAClD,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,YAAY,CAAC;AAAA,IACzD;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/users/hooks/messages.hook.ts"],"sourcesContent":["'use client';\n\nimport { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport { listMessagesAction } from '../action/list-messages.action';\nimport { markMessageAsReadAction } from '../action/mark-message-as-read.action';\nimport { markAllMessagesAsReadAction } from '../action/mark-all-messages-as-read.action';\nimport { withAction } from '../../../utils/withAction';\nimport type { FindMessagesParams } from '../schema/messages.schema';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\n\nexport const MESSAGES_QUERY_KEY = ['messages'] as const;\n\nconst INFINITE_MESSAGES_PAGE_SIZE = 10;\n\nexport function useMessages(params?: Partial<FindMessagesParams>) {\n const queryKey = useAuthQueryKey([...MESSAGES_QUERY_KEY, params]);\n\n return useQuery({\n queryKey,\n queryFn: withAction(() => listMessagesAction(params)),\n });\n}\n\nexport function useInfiniteMessages(params?: Partial<Omit<FindMessagesParams, 'page' | 'limit'>>) {\n const queryKey = useAuthQueryKey([...MESSAGES_QUERY_KEY, 'infinite', params]);\n\n return useInfiniteQuery({\n queryKey,\n queryFn: ({ pageParam }) =>\n withAction(() =>\n listMessagesAction({\n ...params,\n page: pageParam as number,\n limit: INFINITE_MESSAGES_PAGE_SIZE,\n })\n )(),\n getNextPageParam: (lastPage, allPages) => {\n const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);\n return loaded < lastPage.total ? allPages.length + 1 : undefined;\n },\n initialPageParam: 1,\n });\n}\n\nexport function useMarkMessageAsRead() {\n const queryClient = useQueryClient();\n const messagesKey = useAuthQueryKey([...MESSAGES_QUERY_KEY]);\n\n return useMutation({\n mutationFn: withAction(markMessageAsReadAction),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: messagesKey });\n },\n });\n}\n\nexport function useMarkAllMessagesAsRead() {\n const queryClient = useQueryClient();\n const messagesKey = useAuthQueryKey([...MESSAGES_QUERY_KEY]);\n\n return useMutation({\n mutationFn: withAction(markAllMessagesAsReadAction),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: messagesKey });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,kBAAkB,aAAa,UAAU,sBAAsB;AACxE,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AACxC,SAAS,mCAAmC;AAC5C,SAAS,kBAAkB;AAE3B,SAAS,uBAAuB;AAEzB,MAAM,qBAAqB,CAAC,UAAU;AAE7C,MAAM,8BAA8B;AAE7B,SAAS,YAAY,QAAsC;AAChE,QAAM,WAAW,gBAAgB,CAAC,GAAG,oBAAoB,MAAM,CAAC;AAEhE,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,WAAW,MAAM,mBAAmB,MAAM,CAAC;AAAA,EACtD,CAAC;AACH;AAEO,SAAS,oBAAoB,QAA8D;AAChG,QAAM,WAAW,gBAAgB,CAAC,GAAG,oBAAoB,YAAY,MAAM,CAAC;AAE5E,SAAO,iBAAiB;AAAA,IACtB;AAAA,IACA,SAAS,CAAC,EAAE,UAAU,MACpB;AAAA,MAAW,MACT,mBAAmB;AAAA,QACjB,GAAG;AAAA,QACH,MAAM;AAAA,QACN,OAAO;AAAA,MACT,CAAC;AAAA,IACH,EAAE;AAAA,IACJ,kBAAkB,CAAC,UAAU,aAAa;AACxC,YAAM,SAAS,SAAS,OAAO,CAAC,KAAK,MAAM,MAAM,EAAE,KAAK,QAAQ,CAAC;AACjE,aAAO,SAAS,SAAS,QAAQ,SAAS,SAAS,IAAI;AAAA,IACzD;AAAA,IACA,kBAAkB;AAAA,EACpB,CAAC;AACH;AAEO,SAAS,uBAAuB;AACrC,QAAM,cAAc,eAAe;AACnC,QAAM,cAAc,gBAAgB,CAAC,GAAG,kBAAkB,CAAC;AAE3D,SAAO,YAAY;AAAA,IACjB,YAAY,WAAW,uBAAuB;AAAA,IAC9C,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,YAAY,CAAC;AAAA,IACzD;AAAA,EACF,CAAC;AACH;AAEO,SAAS,2BAA2B;AACzC,QAAM,cAAc,eAAe;AACnC,QAAM,cAAc,gBAAgB,CAAC,GAAG,kBAAkB,CAAC;AAE3D,SAAO,YAAY;AAAA,IACjB,YAAY,WAAW,2BAA2B;AAAA,IAClD,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,YAAY,CAAC;AAAA,IACzD;AAAA,EACF,CAAC;AACH;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatapps/common",
3
- "version": "1.1.658",
3
+ "version": "1.1.659",
4
4
  "description": "Shared library for GreatApps frontend applications",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./src/index.ts",
@@ -16,18 +16,6 @@
16
16
  "./middleware": {
17
17
  "import": "./dist/middleware.mjs",
18
18
  "types": "./src/middleware.ts"
19
- },
20
- "./route": {
21
- "import": "./dist/route.mjs",
22
- "types": "./src/route.ts"
23
- },
24
- "./http": {
25
- "import": "./dist/http.mjs",
26
- "types": "./src/http.ts"
27
- },
28
- "./handlers": {
29
- "import": "./dist/handlers.mjs",
30
- "types": "./src/handlers.ts"
31
19
  }
32
20
  },
33
21
  "files": [
@@ -77,7 +65,6 @@
77
65
  },
78
66
  "devDependencies": {
79
67
  "@hookform/resolvers": "^5.2.2",
80
- "zod": "^4.4.3",
81
68
  "@tanstack/react-query": "^5.95.2",
82
69
  "@tanstack/react-query-devtools": "^5.95.2",
83
70
  "@types/node": "^25.5.0",
@@ -90,6 +77,7 @@
90
77
  "react-hook-form": "^7.72.0",
91
78
  "tsup": "^8.5.1",
92
79
  "typescript": "^5.9.3",
80
+ "zod": "^4.3.6",
93
81
  "zustand": "^5.0.12"
94
82
  },
95
83
  "peerDependencies": {
@@ -60,7 +60,7 @@ export function TokenSection() {
60
60
  </div>
61
61
 
62
62
  <a
63
- href="https://documenter.getpostman.com/view/4861938/2sAYdoDmj4"
63
+ href="https://documenter.getpostman.com/view/4861938/T1Djiz8H"
64
64
  target="_blank"
65
65
  rel="noopener noreferrer"
66
66
  className="paragraph-small-medium text-gray-500 underline hover:text-gray-700 transition-colors w-fit"
@@ -55,23 +55,9 @@ export function showCrisp() {
55
55
  }
56
56
 
57
57
  const FREE_PLAN_ID = 5;
58
- const FREE_PLAN_WELCOME_SHOWN_KEY = 'crisp:free-plan-welcome:shown';
59
- const FREE_PLAN_WELCOME_QUERY_FLAG = 'createNew';
60
- const FREE_PLAN_WELCOME_MESSAGE = `Oi! Tenho uma novidade exclusiva para você 🎉
61
-
62
- Criamos o Plano Iniciante pensando exatamente em você: R$ 14,90/mês para quem já deu o primeiro passo e quer ir além.
63
-
64
- Com ele você conecta seu próprio domínio, publica até 3 páginas e libera recursos como scripts, API Meta, exportação de leads e possibilidade de contratar GreatAI.
65
-
66
- Acesse o menu "Assinaturas" e assine agora!`;
67
-
68
- export function sendCrispMessage(text: string) {
69
- safeCrispPush(['do', 'message:show', ['text', text]]);
70
- }
71
-
72
- export function openCrispChat() {
73
- crispDo('chat:open');
74
- }
58
+ const FREE_PLAN_SIGNUP_QUERY_FLAG = 'createNew';
59
+ const FREE_PLAN_SIGNUP_SEGMENT = 'cadastro_plano_free';
60
+ const FREE_PLAN_SIGNUP_TAGGED_KEY = 'crisp:free-plan-signup:tagged';
75
61
 
76
62
  export function updateCrispUser(data: {
77
63
  email?: string;
@@ -181,32 +167,23 @@ export function CrispEmbed() {
181
167
  useEffect(() => {
182
168
  try {
183
169
  const params = new URLSearchParams(window.location.search);
184
- if (params.get(FREE_PLAN_WELCOME_QUERY_FLAG) === 'true') {
170
+ if (params.get(FREE_PLAN_SIGNUP_QUERY_FLAG) === 'true') {
185
171
  setIsFreshSignup(true);
186
172
  }
187
173
  } catch {}
188
174
  }, []);
189
175
 
190
- // Mostra mensagem de boas-vindas no Crisp para quem acabou de se cadastrar no plano free.
176
+ // Marca o usuário com o segment de cadastro free para o trigger do Crisp.
177
+ // A mensagem em si é configurada lá no Crisp (Message Trigger com condição
178
+ // session:segments contém 'cadastro_plano_free').
191
179
  useEffect(() => {
192
180
  if (!user || !shouldLoadCrisp || !isFreshSignup) return;
193
181
  if (subscription?.id_plan !== FREE_PLAN_ID) return;
194
182
  try {
195
- const shownKey = `${FREE_PLAN_WELCOME_SHOWN_KEY}:${user.id}`;
196
- if (window.localStorage.getItem(shownKey)) return;
197
-
198
- // Defer to session:loaded para garantir que a Crisp está pronta antes
199
- // de exibir a mensagem. Sem isso, comandos enfileirados pré-load podem
200
- // ser descartados silenciosamente.
201
- safeCrispPush([
202
- 'on',
203
- 'session:loaded',
204
- () => {
205
- sendCrispMessage(FREE_PLAN_WELCOME_MESSAGE);
206
- openCrispChat();
207
- },
208
- ]);
209
- window.localStorage.setItem(shownKey, '1');
183
+ const taggedKey = `${FREE_PLAN_SIGNUP_TAGGED_KEY}:${user.id}`;
184
+ if (window.localStorage.getItem(taggedKey)) return;
185
+ crispSegment(FREE_PLAN_SIGNUP_SEGMENT);
186
+ window.localStorage.setItem(taggedKey, '1');
210
187
  } catch {}
211
188
  }, [user, shouldLoadCrisp, isFreshSignup, subscription?.id_plan]);
212
189
 
@@ -1,9 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import { useQuery } from '@tanstack/react-query';
4
- import { apiFetch } from '../../../infra/http/api-fetch';
5
- import type { SuccessResult } from '../../../infra/api/types';
6
- import type { Card } from '../types';
4
+ import { withAction } from '../../../utils/withAction';
7
5
  import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
8
6
 
9
7
  export function useCardById(id: number | undefined) {
@@ -11,7 +9,10 @@ export function useCardById(id: number | undefined) {
11
9
 
12
10
  return useQuery({
13
11
  queryKey: cardKey,
14
- queryFn: ({ signal }) => apiFetch<SuccessResult<Card>>(`/api/cards/${id}`, { signal }),
12
+ queryFn: async () => {
13
+ const { findCardByIdAction } = await import('../actions/find-card-by-id.action');
14
+ return withAction(findCardByIdAction)(id!);
15
+ },
15
16
  enabled: id != null,
16
17
  });
17
18
  }
@@ -1,9 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import { useQuery } from '@tanstack/react-query';
4
- import { apiFetch } from '../../../infra/http/api-fetch';
5
- import type { PaginatedSuccessResult } from '../../../infra/api/types';
6
- import type { Card } from '../types';
4
+ import { withAction } from '../../../utils/withAction';
7
5
  import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
8
6
 
9
7
  export const CARDS_QUERY_KEY = ['cards'] as const;
@@ -13,7 +11,10 @@ export function useCards() {
13
11
 
14
12
  return useQuery({
15
13
  queryKey,
16
- queryFn: ({ signal }) => apiFetch<PaginatedSuccessResult<Card>>('/api/cards', { signal }),
14
+ queryFn: async () => {
15
+ const { listCardsAction } = await import('../actions/list-cards.action');
16
+ return withAction(listCardsAction)();
17
+ },
17
18
  select: (result) => ({
18
19
  ...result,
19
20
  data: result.data.filter((card) => !card.deleted),
@@ -1,10 +1,9 @@
1
1
  'use client';
2
2
 
3
3
  import { useQuery } from '@tanstack/react-query';
4
- import { apiFetch } from '../../../infra/http/api-fetch';
5
- import type { SuccessResult } from '../../../infra/api/types';
4
+ import { withAction } from '../../../utils/withAction';
6
5
  import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
7
- import { Charge } from '../types/charge.type';
6
+ import { findChargeByIdAction } from '../actions/find-charge-by-id.action';
8
7
  import { CHARGES_QUERY_KEY } from '../../subscriptions/constants/query-keys.constants';
9
8
 
10
9
  export function useChargeById(chargeId: string | number | null | undefined) {
@@ -12,8 +11,7 @@ export function useChargeById(chargeId: string | number | null | undefined) {
12
11
 
13
12
  return useQuery({
14
13
  queryKey: chargesKey,
15
- queryFn: ({ signal }) =>
16
- apiFetch<SuccessResult<Charge>>(`/api/charges/${chargeId}`, { signal }),
14
+ queryFn: () => withAction(findChargeByIdAction)(chargeId!),
17
15
  enabled: !!chargeId,
18
16
  });
19
17
  }
@@ -1,10 +1,10 @@
1
1
  'use client';
2
2
 
3
3
  import { useQuery } from '@tanstack/react-query';
4
- import { apiFetch } from '../../../infra/http/api-fetch';
5
- import type { PaginatedSuccessResult } from '../../../infra/api/types';
4
+ import { withAction } from '../../../utils/withAction';
6
5
  import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
7
- import { Charge, FindChargesParams } from '../types/charge.type';
6
+ import { listChargesAction } from '../actions/list-charges.action';
7
+ import { FindChargesParams } from '../types/charge.type';
8
8
  import { CHARGES_QUERY_KEY } from '../../subscriptions/constants/query-keys.constants';
9
9
 
10
10
  export function useCharges(params?: Partial<FindChargesParams>) {
@@ -12,8 +12,7 @@ export function useCharges(params?: Partial<FindChargesParams>) {
12
12
 
13
13
  return useQuery({
14
14
  queryKey: chargesKey,
15
- queryFn: ({ signal }) =>
16
- apiFetch<PaginatedSuccessResult<Charge>>('/api/charges', { params, signal }),
15
+ queryFn: () => withAction(listChargesAction)(params),
17
16
  staleTime: 10_000,
18
17
  });
19
18
  }
@@ -2,10 +2,10 @@
2
2
 
3
3
  import { useMemo } from 'react';
4
4
  import { useQuery } from '@tanstack/react-query';
5
- import { apiFetch } from '../../../infra/http/api-fetch';
6
- import type { PaginatedSuccessResult } from '../../../infra/api/types';
5
+ import { listIaCreditsAction } from '../actions/list-ia-credits.action';
7
6
  import type { IaCreditOperation, IaCreditsSummary } from '../types';
8
7
  import { useActiveSubscription } from '../../subscriptions/hooks/find-active-subscription.hook';
8
+ import { withAction } from '../../../utils/withAction';
9
9
  import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
10
10
 
11
11
  function calculateSummary(operations: IaCreditOperation[]): IaCreditsSummary {
@@ -77,11 +77,7 @@ export function useIaCredits() {
77
77
 
78
78
  const query = useQuery({
79
79
  queryKey,
80
- queryFn: ({ signal }) =>
81
- apiFetch<PaginatedSuccessResult<IaCreditOperation>>(
82
- `/api/subscriptions/${subscriptionId}/ia-credits`,
83
- { signal }
84
- ),
80
+ queryFn: withAction(() => listIaCreditsAction(subscriptionId!)),
85
81
  enabled: subscriptionId != null,
86
82
  });
87
83
 
@@ -1,8 +1,9 @@
1
1
  'use client';
2
2
 
3
3
  import { useQuery } from '@tanstack/react-query';
4
- import { apiFetch } from '../../../infra/http/api-fetch';
4
+ import { countPagesAction } from '../actions/count-pages.action';
5
5
  import { PAGES_QUERY_KEY } from '../constants/query-keys.constants';
6
+ import { withAction } from '../../../utils/withAction';
6
7
  import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
7
8
 
8
9
  export const COUNT_PAGES_QUERY_KEY = [...PAGES_QUERY_KEY, 'count'] as const;
@@ -12,8 +13,8 @@ export function useCountPages() {
12
13
 
13
14
  return useQuery({
14
15
  queryKey,
15
- queryFn: async ({ signal }) => {
16
- const result = await apiFetch<{ total: number }>('/api/pages/count', { signal });
16
+ queryFn: async () => {
17
+ const result = await withAction(countPagesAction)();
17
18
  return result.total;
18
19
  },
19
20
  staleTime: 30_000,
@@ -1,7 +1,8 @@
1
1
  'use client';
2
2
 
3
3
  import { useQuery } from '@tanstack/react-query';
4
- import { apiFetch } from '../../../infra/http/api-fetch';
4
+ import { withAction } from '@greatapps/common';
5
+ import { listPlansAction } from '../actions/list-plans.action';
5
6
  import type { Plan } from '../types/plan.type';
6
7
  import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
7
8
 
@@ -12,7 +13,7 @@ export function usePlans() {
12
13
 
13
14
  return useQuery<Plan[]>({
14
15
  queryKey,
15
- queryFn: ({ signal }) => apiFetch<Plan[]>('/api/plans', { signal }),
16
+ queryFn: withAction(listPlansAction),
16
17
  staleTime: Infinity,
17
18
  gcTime: Infinity,
18
19
  refetchOnWindowFocus: false,
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
 
3
3
  import { useQuery, useQueryClient } from "@tanstack/react-query";
4
- import { apiFetch } from "../../../infra/http/api-fetch";
5
- import type { SuccessResult } from "../../../infra/api/types";
4
+ import { withAction } from "../../../utils/withAction";
5
+ import { findPlanByIdAction } from "../actions/find-plan-by-id.action";
6
6
  import type { Plan } from "../types/plan.type";
7
7
  import { PLANS_QUERY_KEY } from "./list-plans.hook";
8
8
  import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
@@ -13,8 +13,7 @@ export function usePlanById(idPlan?: number | string | null) {
13
13
 
14
14
  return useQuery({
15
15
  queryKey: [...plansKey, idPlan],
16
- queryFn: ({ signal }) =>
17
- apiFetch<SuccessResult<Plan>>(`/api/plans/${idPlan}`, { signal }),
16
+ queryFn: withAction(() => findPlanByIdAction(idPlan!)),
18
17
  initialData: () => {
19
18
  const queries = queryClient.getQueriesData<Plan[]>({
20
19
  queryKey: plansKey,
@@ -1,8 +1,8 @@
1
1
  'use client';
2
2
 
3
3
  import { useQuery } from '@tanstack/react-query';
4
- import { apiFetch } from '../../../infra/http/api-fetch';
5
- import type { Project } from '../types';
4
+ import { findProjectAction } from '../actions/find-project.action';
5
+ import { withAction } from '../../../utils/withAction';
6
6
  import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
7
7
  import { PROJECTS_BASE_KEY } from './list-projects.hook';
8
8
 
@@ -11,7 +11,7 @@ export function useProject(projectId: number | null) {
11
11
 
12
12
  return useQuery({
13
13
  queryKey,
14
- queryFn: ({ signal }) => apiFetch<Project>(`/api/projects/${projectId}`, { signal }),
14
+ queryFn: () => withAction(() => findProjectAction(projectId!))(),
15
15
  enabled: projectId != null && projectId > 0,
16
16
  staleTime: 10_000,
17
17
  });
@@ -1,8 +1,8 @@
1
1
  'use client';
2
2
 
3
3
  import { useInfiniteQuery } from '@tanstack/react-query';
4
- import { apiFetch } from '../../../infra/http/api-fetch';
5
- import type { AccountUser, UsersPage } from '../types';
4
+ import { listAllAccountUsersAction } from '../actions/list-all-account-users.action';
5
+ import { withAction } from '../../../utils/withAction';
6
6
  import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
7
7
 
8
8
  const PAGE_SIZE = 20;
@@ -21,16 +21,15 @@ export function useListAllAccountUsers(search: string = '', projectId?: number)
21
21
 
22
22
  return useInfiniteQuery({
23
23
  queryKey,
24
- queryFn: ({ pageParam, signal }) =>
25
- apiFetch<UsersPage<AccountUser>>('/api/account/users', {
26
- params: {
24
+ queryFn: ({ pageParam }) =>
25
+ withAction(() =>
26
+ listAllAccountUsersAction({
27
27
  search: search || undefined,
28
28
  page: pageParam as number,
29
29
  limit: PAGE_SIZE,
30
30
  inProject: projectId,
31
- },
32
- signal,
33
- }),
31
+ })
32
+ )(),
34
33
  getNextPageParam: (lastPage, allPages) => {
35
34
  const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);
36
35
  return loaded < lastPage.total ? allPages.length + 1 : undefined;
@@ -1,8 +1,8 @@
1
1
  'use client';
2
2
 
3
3
  import { useInfiniteQuery } from '@tanstack/react-query';
4
- import { apiFetch } from '../../../infra/http/api-fetch';
5
- import type { AccountUser, UsersPage } from '../types';
4
+ import { listAvailableUsersAction } from '../actions/list-available-users.action';
5
+ import { withAction } from '../../../utils/withAction';
6
6
  import { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';
7
7
 
8
8
  const PAGE_SIZE = 20;
@@ -20,15 +20,14 @@ export function useListAvailableUsers(projectId: number, search: string = '') {
20
20
 
21
21
  return useInfiniteQuery({
22
22
  queryKey,
23
- queryFn: ({ pageParam, signal }) =>
24
- apiFetch<UsersPage<AccountUser>>(`/api/projects/${projectId}/available-users`, {
25
- params: {
23
+ queryFn: ({ pageParam }) =>
24
+ withAction(() =>
25
+ listAvailableUsersAction(projectId, {
26
26
  search: search || undefined,
27
27
  page: pageParam as number,
28
28
  limit: PAGE_SIZE,
29
- },
30
- signal,
31
- }),
29
+ })
30
+ )(),
32
31
  getNextPageParam: (lastPage, allPages) => {
33
32
  const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);
34
33
  return loaded < lastPage.total ? allPages.length + 1 : undefined;
@@ -1,9 +1,9 @@
1
1
  "use client";
2
2
 
3
3
  import { useInfiniteQuery } from "@tanstack/react-query";
4
- import { apiFetch } from "../../../infra/http/api-fetch";
4
+ import { listProjectsAction } from "../actions/list-projects.action";
5
5
  import type { ListProjectsActionParams } from "../actions/list-projects.action";
6
- import type { ProjectsPage } from "../types";
6
+ import { withAction } from "../../../utils/withAction";
7
7
  import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
8
8
  import { PROJECTS_BASE_KEY } from "./list-projects.hook";
9
9
 
@@ -21,15 +21,14 @@ export function useInfiniteProjects({
21
21
 
22
22
  return useInfiniteQuery({
23
23
  queryKey,
24
- queryFn: ({ pageParam, signal }) =>
25
- apiFetch<ProjectsPage>('/api/projects', {
26
- params: {
24
+ queryFn: ({ pageParam }) =>
25
+ withAction(() =>
26
+ listProjectsAction({
27
27
  ...params,
28
28
  page: pageParam as number,
29
29
  limit,
30
- },
31
- signal,
32
- }),
30
+ }),
31
+ )(),
33
32
  initialPageParam: 1,
34
33
  getNextPageParam: (lastPage, allPages) => {
35
34
  const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);