@greatapps/common 1.1.100 → 1.1.101

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.
@@ -1,16 +1,12 @@
1
1
  "use server";
2
+ import { safeServerAction } from "../../../utils/safeServerAction";
2
3
  import { authService } from "../services/auth.service";
3
4
  import { getClientInfoFromRequest } from "../../../infra/utils/client-info";
4
5
  async function loginAction(credentials) {
5
- try {
6
+ return safeServerAction(async () => {
6
7
  const clientInfo = await getClientInfoFromRequest();
7
- return await authService.login(credentials, clientInfo);
8
- } catch (error) {
9
- return {
10
- result: "error",
11
- message: error.message || "An error occurred during login"
12
- };
13
- }
8
+ return authService.login(credentials, clientInfo);
9
+ });
14
10
  }
15
11
  export {
16
12
  loginAction
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/auth/actions/login.action.ts"],"sourcesContent":["\"use server\";\r\n\r\nimport { authService } from \"../services/auth.service\";\r\nimport { LoginRequest, LoginResponse } from \"../schema\";\r\nimport { getClientInfoFromRequest } from \"../../../infra/utils/client-info\";\r\nimport { ApiError } from \"../../../infra/api/types\";\r\n\r\nexport async function loginAction(\r\n credentials: LoginRequest\r\n): Promise<LoginResponse> {\r\n try {\r\n const clientInfo = await getClientInfoFromRequest();\r\n return await authService.login(credentials, clientInfo);\r\n } catch (error) {\r\n return {\r\n result: 'error',\r\n message: (error as ApiError).message || \"An error occurred during login\",\r\n };\r\n }\r\n}\r\n"],"mappings":";AAEA,SAAS,mBAAmB;AAE5B,SAAS,gCAAgC;AAGzC,eAAsB,YACpB,aACwB;AACxB,MAAI;AACF,UAAM,aAAa,MAAM,yBAAyB;AAClD,WAAO,MAAM,YAAY,MAAM,aAAa,UAAU;AAAA,EACxD,SAAS,OAAO;AACd,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,SAAU,MAAmB,WAAW;AAAA,IAC1C;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/auth/actions/login.action.ts"],"sourcesContent":["\"use server\";\r\n\r\nimport { safeServerAction } from \"../../../utils/safeServerAction\";\r\nimport { authService } from \"../services/auth.service\";\r\nimport { LoginRequest } from \"../schema\";\r\nimport { getClientInfoFromRequest } from \"../../../infra/utils/client-info\";\r\n\r\nexport async function loginAction(credentials: LoginRequest) {\r\n return safeServerAction(async () => {\r\n const clientInfo = await getClientInfoFromRequest();\r\n return authService.login(credentials, clientInfo);\r\n });\r\n}\r\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAE5B,SAAS,gCAAgC;AAEzC,eAAsB,YAAY,aAA2B;AAC3D,SAAO,iBAAiB,YAAY;AAClC,UAAM,aAAa,MAAM,yBAAyB;AAClD,WAAO,YAAY,MAAM,aAAa,UAAU;AAAA,EAClD,CAAC;AACH;","names":[]}
@@ -1,11 +1,13 @@
1
1
  "use client";
2
2
  import { useMutation } from "@tanstack/react-query";
3
3
  import { loginAction } from "../actions/login.action";
4
- import { safeServerAction } from "../../../utils/safeServerAction";
5
4
  function useLogin() {
6
5
  return useMutation({
7
6
  mutationFn: async (credentials) => {
8
- const data = await safeServerAction(loginAction, credentials);
7
+ const result = await loginAction(credentials);
8
+ if (!result.success) throw new Error(result.error ?? "Erro desconhecido");
9
+ const data = result.data;
10
+ if (data.result === "error") throw new Error(data.message);
9
11
  return data;
10
12
  }
11
13
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/auth/hooks/login.hook.tsx"],"sourcesContent":["\"use client\";\n\nimport { useMutation } from \"@tanstack/react-query\";\nimport { loginAction } from \"../actions/login.action\";\nimport { safeServerAction } from \"../../../utils/safeServerAction\";\nimport { LoginRequest, LoginSuccessResponse } from \"../schema\";\n\nexport function useLogin() {\n return useMutation({\n mutationFn: async (credentials: LoginRequest): Promise<LoginSuccessResponse> => {\n const data = await safeServerAction(loginAction, credentials);\n return data as LoginSuccessResponse;\n },\n });\n}\n"],"mappings":";AAEA,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AAG1B,SAAS,WAAW;AACzB,SAAO,YAAY;AAAA,IACjB,YAAY,OAAO,gBAA6D;AAC9E,YAAM,OAAO,MAAM,iBAAiB,aAAa,WAAW;AAC5D,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/auth/hooks/login.hook.tsx"],"sourcesContent":["\"use client\";\n\nimport { useMutation } from \"@tanstack/react-query\";\nimport { loginAction } from \"../actions/login.action\";\nimport { LoginRequest, LoginSuccessResponse } from \"../schema\";\n\nexport function useLogin() {\n return useMutation({\n mutationFn: async (credentials: LoginRequest): Promise<LoginSuccessResponse> => {\n const result = await loginAction(credentials);\n if (!result.success) throw new Error(result.error ?? 'Erro desconhecido');\n const data = result.data!;\n if (data.result === 'error') throw new Error(data.message);\n return data as LoginSuccessResponse;\n },\n });\n}\n"],"mappings":";AAEA,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB;AAGrB,SAAS,WAAW;AACzB,SAAO,YAAY;AAAA,IACjB,YAAY,OAAO,gBAA6D;AAC9E,YAAM,SAAS,MAAM,YAAY,WAAW;AAC5C,UAAI,CAAC,OAAO,QAAS,OAAM,IAAI,MAAM,OAAO,SAAS,mBAAmB;AACxE,YAAM,OAAO,OAAO;AACpB,UAAI,KAAK,WAAW,QAAS,OAAM,IAAI,MAAM,KAAK,OAAO;AACzD,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
package/dist/server.mjs CHANGED
@@ -34,6 +34,7 @@ import {
34
34
  } from "./modules/accounts/actions/account-management.action";
35
35
  import { getClientInfoFromRequest } from "./infra/utils/client-info";
36
36
  import { getUserContext } from "./modules/auth/utils/get-user-context";
37
+ import { safeServerAction } from "./utils/safeServerAction";
37
38
  export {
38
39
  ApiClient,
39
40
  accountService,
@@ -63,6 +64,7 @@ export {
63
64
  removeProjectUserAction,
64
65
  requestEmailChangeAction,
65
66
  requestPhoneChangeAction,
67
+ safeServerAction,
66
68
  subscriptionsService,
67
69
  twoFactorService,
68
70
  updateAccountAction,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/server.ts"],"sourcesContent":["import 'server-only';\r\n\r\n// API Client\r\nexport { ApiClient, api, apiClient } from './infra/api/client';\r\n\r\n// Services\r\nexport { authService } from './modules/auth/services/auth.service';\r\nexport { whitelabelService } from './modules/whitelabel/services/whitelabel.service';\r\nexport { subscriptionsService } from './modules/subscriptions/services/subscriptions.service';\r\nexport { iaCreditsService } from './modules/ia-credits/services/ia-credits.service';\r\n\r\n// Actions\r\nexport { findWhitelabel } from './modules/whitelabel/actions/find-whitelabel.action';\r\nexport { validateSessionAction } from './modules/auth/actions/validate-session.action';\r\nexport { listSubscriptionsAction } from './modules/subscriptions/actions/list-subscriptions.action';\r\nexport { listIaCreditsAction } from './modules/ia-credits/actions/list-ia-credits.action';\r\n\r\n// Project Users Services & Actions (server-only)\r\nexport { projectUsersService } from './modules/projects/services/project-users.service';\r\nexport { listProjectUsersAction } from './modules/projects/actions/list-project-users.action';\r\nexport { listAvailableUsersAction } from './modules/projects/actions/list-available-users.action';\r\nexport { addProjectUserAction } from './modules/projects/actions/add-project-user.action';\r\nexport { removeProjectUserAction } from './modules/projects/actions/remove-project-user.action';\r\n\r\n// Account Services & Actions (server-only)\r\nexport { accountService } from './modules/accounts/services/account.service';\r\nexport { twoFactorService } from './modules/accounts/services/two-factor.service';\r\nexport {\r\n listAccountUsersAction,\r\n updateUserAction,\r\n updateAccountAction,\r\n updateAccountUserByIdAction,\r\n deleteAccountUserAction,\r\n deleteAccountAction,\r\n createAccountUserAction,\r\n changePasswordAction,\r\n requestEmailChangeAction,\r\n confirmEmailChangeAction,\r\n requestPhoneChangeAction,\r\n confirmPhoneChangeAction,\r\n generateTwoFactorAction,\r\n confirmTwoFactorAction,\r\n disableTwoFactorAction,\r\n} from './modules/accounts/actions/account-management.action';\r\n\r\n// Server Utils\r\nexport { getClientInfoFromRequest } from './infra/utils/client-info';\r\nexport { getUserContext } from './modules/auth/utils/get-user-context';\r\n"],"mappings":"AAAA,OAAO;AAGP,SAAS,WAAW,KAAK,iBAAiB;AAG1C,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AACrC,SAAS,wBAAwB;AAGjC,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AACxC,SAAS,2BAA2B;AAGpC,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AACvC,SAAS,gCAAgC;AACzC,SAAS,4BAA4B;AACrC,SAAS,+BAA+B;AAGxC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,gCAAgC;AACzC,SAAS,sBAAsB;","names":[]}
1
+ {"version":3,"sources":["../src/server.ts"],"sourcesContent":["import 'server-only';\r\n\r\n// API Client\r\nexport { ApiClient, api, apiClient } from './infra/api/client';\r\n\r\n// Services\r\nexport { authService } from './modules/auth/services/auth.service';\r\nexport { whitelabelService } from './modules/whitelabel/services/whitelabel.service';\r\nexport { subscriptionsService } from './modules/subscriptions/services/subscriptions.service';\r\nexport { iaCreditsService } from './modules/ia-credits/services/ia-credits.service';\r\n\r\n// Actions\r\nexport { findWhitelabel } from './modules/whitelabel/actions/find-whitelabel.action';\r\nexport { validateSessionAction } from './modules/auth/actions/validate-session.action';\r\nexport { listSubscriptionsAction } from './modules/subscriptions/actions/list-subscriptions.action';\r\nexport { listIaCreditsAction } from './modules/ia-credits/actions/list-ia-credits.action';\r\n\r\n// Project Users Services & Actions (server-only)\r\nexport { projectUsersService } from './modules/projects/services/project-users.service';\r\nexport { listProjectUsersAction } from './modules/projects/actions/list-project-users.action';\r\nexport { listAvailableUsersAction } from './modules/projects/actions/list-available-users.action';\r\nexport { addProjectUserAction } from './modules/projects/actions/add-project-user.action';\r\nexport { removeProjectUserAction } from './modules/projects/actions/remove-project-user.action';\r\n\r\n// Account Services & Actions (server-only)\r\nexport { accountService } from './modules/accounts/services/account.service';\r\nexport { twoFactorService } from './modules/accounts/services/two-factor.service';\r\nexport {\r\n listAccountUsersAction,\r\n updateUserAction,\r\n updateAccountAction,\r\n updateAccountUserByIdAction,\r\n deleteAccountUserAction,\r\n deleteAccountAction,\r\n createAccountUserAction,\r\n changePasswordAction,\r\n requestEmailChangeAction,\r\n confirmEmailChangeAction,\r\n requestPhoneChangeAction,\r\n confirmPhoneChangeAction,\r\n generateTwoFactorAction,\r\n confirmTwoFactorAction,\r\n disableTwoFactorAction,\r\n} from './modules/accounts/actions/account-management.action';\r\n\r\n// Server Utils\r\nexport { getClientInfoFromRequest } from './infra/utils/client-info';\r\nexport { getUserContext } from './modules/auth/utils/get-user-context';\r\nexport { safeServerAction } from './utils/safeServerAction';\r\n"],"mappings":"AAAA,OAAO;AAGP,SAAS,WAAW,KAAK,iBAAiB;AAG1C,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AACrC,SAAS,wBAAwB;AAGjC,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AACxC,SAAS,2BAA2B;AAGpC,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AACvC,SAAS,gCAAgC;AACzC,SAAS,4BAA4B;AACrC,SAAS,+BAA+B;AAGxC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,gCAAgC;AACzC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatapps/common",
3
- "version": "1.1.100",
3
+ "version": "1.1.101",
4
4
  "description": "Shared library for GreatApps frontend applications",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -75,7 +75,6 @@ export { cn } from "./infra/utils/clsx";
75
75
  export { buildQueryParams } from "./infra/utils/params";
76
76
  export { parseSchema, parseResult } from "./infra/utils/parser";
77
77
  export { withAction } from "./utils/withAction";
78
- export { safeServerAction } from "./utils/safeServerAction";
79
78
 
80
79
  // Layout
81
80
  export {
@@ -1,20 +1,13 @@
1
1
  "use server";
2
2
 
3
+ import { safeServerAction } from "../../../utils/safeServerAction";
3
4
  import { authService } from "../services/auth.service";
4
- import { LoginRequest, LoginResponse } from "../schema";
5
+ import { LoginRequest } from "../schema";
5
6
  import { getClientInfoFromRequest } from "../../../infra/utils/client-info";
6
- import { ApiError } from "../../../infra/api/types";
7
7
 
8
- export async function loginAction(
9
- credentials: LoginRequest
10
- ): Promise<LoginResponse> {
11
- try {
8
+ export async function loginAction(credentials: LoginRequest) {
9
+ return safeServerAction(async () => {
12
10
  const clientInfo = await getClientInfoFromRequest();
13
- return await authService.login(credentials, clientInfo);
14
- } catch (error) {
15
- return {
16
- result: 'error',
17
- message: (error as ApiError).message || "An error occurred during login",
18
- };
19
- }
11
+ return authService.login(credentials, clientInfo);
12
+ });
20
13
  }
@@ -2,13 +2,15 @@
2
2
 
3
3
  import { useMutation } from "@tanstack/react-query";
4
4
  import { loginAction } from "../actions/login.action";
5
- import { safeServerAction } from "../../../utils/safeServerAction";
6
5
  import { LoginRequest, LoginSuccessResponse } from "../schema";
7
6
 
8
7
  export function useLogin() {
9
8
  return useMutation({
10
9
  mutationFn: async (credentials: LoginRequest): Promise<LoginSuccessResponse> => {
11
- const data = await safeServerAction(loginAction, credentials);
10
+ const result = await loginAction(credentials);
11
+ if (!result.success) throw new Error(result.error ?? 'Erro desconhecido');
12
+ const data = result.data!;
13
+ if (data.result === 'error') throw new Error(data.message);
12
14
  return data as LoginSuccessResponse;
13
15
  },
14
16
  });
package/src/server.ts CHANGED
@@ -46,3 +46,4 @@ export {
46
46
  // Server Utils
47
47
  export { getClientInfoFromRequest } from './infra/utils/client-info';
48
48
  export { getUserContext } from './modules/auth/utils/get-user-context';
49
+ export { safeServerAction } from './utils/safeServerAction';