@leo-h/create-nodejs-app 1.0.37 → 1.0.39

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 (30) hide show
  1. package/package.json +1 -1
  2. package/templates/react-vite/.env.development +8 -0
  3. package/templates/react-vite/.env.example +4 -4
  4. package/templates/react-vite/api/errors.ts +14 -0
  5. package/templates/react-vite/{src/api → api}/swr-fetcher.ts +11 -10
  6. package/templates/react-vite/eslint.config.js +1 -1
  7. package/templates/react-vite/gitignore +7 -0
  8. package/templates/react-vite/orval.config.ts +5 -13
  9. package/templates/react-vite/package.json +23 -24
  10. package/templates/react-vite/pnpm-lock.yaml +566 -516
  11. package/templates/react-vite/scripts/orval-generate-api-definition.ts +2 -19
  12. package/templates/react-vite/src/app.tsx +1 -9
  13. package/templates/react-vite/src/lib/zod-i18n-pt-br-translation.json +101 -0
  14. package/templates/react-vite/src/lib/zod-i18n.ts +12 -4
  15. package/templates/react-vite/src/pages/_layouts/app.tsx +7 -5
  16. package/templates/react-vite/src/pages/_layouts/auth.tsx +7 -5
  17. package/templates/react-vite/src/pages/app/dashboard/dashboard.tsx +2 -1
  18. package/templates/react-vite/src/pages/auth/sign-in/index.tsx +4 -2
  19. package/templates/react-vite/src/private-env.ts +18 -0
  20. package/templates/react-vite/src/public-env.ts +30 -0
  21. package/templates/react-vite/src/routes.tsx +29 -45
  22. package/templates/react-vite/tsconfig.app.json +3 -2
  23. package/templates/react-vite/tsconfig.json +2 -1
  24. package/templates/react-vite/tsconfig.node.json +8 -2
  25. package/templates/react-vite/vite.config.ts +1 -1
  26. package/templates/react-vite/src/api/errors/api-error.ts +0 -7
  27. package/templates/react-vite/src/api/errors/api-unexpected-response-error.ts +0 -8
  28. package/templates/react-vite/src/env.ts +0 -19
  29. package/templates/react-vite/src/hooks/use-current-route-handle-params.ts +0 -16
  30. package/templates/react-vite/src/lib/zod-i18n-translation-for-end-users.json +0 -103
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leo-h/create-nodejs-app",
3
- "version": "1.0.37",
3
+ "version": "1.0.39",
4
4
  "packageManager": "pnpm@9.15.9",
5
5
  "author": "Leonardo Henrique <leonardo0507.business@gmail.com>",
6
6
  "description": "Create a modern Node.js app with TypeScript using one command.",
@@ -0,0 +1,8 @@
1
+ # example: "app-name"
2
+ PUBLIC_APP_NAME="app-name"
3
+
4
+ # example: "http://localhost:3333"
5
+ PUBLIC_API_BASE_URL="http://localhost:3333"
6
+
7
+ # example: "http://localhost:3333/json"
8
+ API_JSON_DOCS_URL="http://localhost:3333/json"
@@ -1,8 +1,8 @@
1
1
  # example: "app-name"
2
- APP_NAME=
2
+ PUBLIC_APP_NAME=
3
3
 
4
4
  # example: "http://localhost:3333"
5
- APP_API_BASE_URL=
5
+ PUBLIC_API_BASE_URL=
6
6
 
7
- # example: "http://localhost:3333/docs/json"
8
- API_JSON_DOCS_URL=
7
+ # example: "http://localhost:3333/json"
8
+ API_JSON_DOCS_URL=
@@ -0,0 +1,14 @@
1
+ export class ApiError {
2
+ public constructor(
3
+ public readonly statusCode: number,
4
+ public readonly error: string,
5
+ public readonly message: string,
6
+ ) {}
7
+ }
8
+
9
+ export class ApiUnexpectedResponseError {
10
+ static readonly message =
11
+ "Houve uma falha inesperada ao se comunicar com nosso servidor. Aguarde alguns instantes ou contate nosso suporte.";
12
+
13
+ constructor(public message = ApiUnexpectedResponseError.message) {}
14
+ }
@@ -1,6 +1,5 @@
1
- import { env } from "@/env";
2
- import { ApiError } from "./errors/api-error";
3
- import { ApiUnexpectedResponseError } from "./errors/api-unexpected-response-error";
1
+ import { publicEnv } from "@/public-env";
2
+ import { ApiError, ApiUnexpectedResponseError } from "./errors";
4
3
 
5
4
  type SwrFetcherOutput = {
6
5
  body: unknown;
@@ -9,14 +8,16 @@ type SwrFetcherOutput = {
9
8
  };
10
9
 
11
10
  export async function swrFetcher<Output extends SwrFetcherOutput>(
12
- url: RequestInfo | URL,
13
- options?: RequestInit,
11
+ endpointUrl: RequestInfo | URL,
12
+ options: RequestInit,
14
13
  ): Promise<Output> {
15
- const apiBaseUrl = new URL(env.APP_API_BASE_URL);
16
- const endpointUrl = new URL(url.toString());
14
+ const url = new URL(publicEnv.API_BASE_URL);
17
15
 
18
- endpointUrl.host = apiBaseUrl.host;
19
- endpointUrl.protocol = apiBaseUrl.protocol;
16
+ if (url.pathname.endsWith("/")) {
17
+ url.pathname = endpointUrl.toString();
18
+ } else {
19
+ url.pathname += endpointUrl;
20
+ }
20
21
 
21
22
  const response = await fetch(endpointUrl, options);
22
23
  let body: unknown;
@@ -28,7 +29,7 @@ export async function swrFetcher<Output extends SwrFetcherOutput>(
28
29
  try {
29
30
  body = await response.json();
30
31
  } catch {
31
- body = {};
32
+ body = null;
32
33
  }
33
34
  }
34
35
 
@@ -7,7 +7,7 @@ import typescriptEslint from "typescript-eslint";
7
7
 
8
8
  export default typescriptEslint.config(
9
9
  {
10
- ignores: ["dist", "src/api/orval"],
10
+ ignores: ["dist", "api/orval"],
11
11
  },
12
12
  {
13
13
  extends: [
@@ -22,3 +22,10 @@ dist-ssr
22
22
  *.njsproj
23
23
  *.sln
24
24
  *.sw?
25
+
26
+ # Eslint cache
27
+ .eslintcache
28
+
29
+ # Environment variable files
30
+ .env*
31
+ !.env.example
@@ -3,14 +3,14 @@ import { OrvalCustomConfig } from "./scripts/orval-generate-api-definition";
3
3
 
4
4
  export const orvalCustomConfig: OrvalCustomConfig = {
5
5
  apiDocs: {
6
- outputPath: "./src/api/docs.json",
6
+ outputPath: "./api/docs.json",
7
7
  },
8
8
  endpoints: {
9
- outputPath: "./src/api/orval/endpoints",
10
- replaceVoidTypeToAnyOnResponse: true,
9
+ outputPath: "./api/orval/endpoints",
10
+ replaceVoidTypeToAnyOnResponse: false,
11
11
  },
12
12
  zodSchemas: {
13
- outputPath: "./src/api/orval/schemas",
13
+ outputPath: "./api/orval/schemas",
14
14
  },
15
15
  };
16
16
 
@@ -21,21 +21,13 @@ export default defineConfig({
21
21
  target: orvalCustomConfig.endpoints.outputPath,
22
22
  client: "swr",
23
23
  httpClient: "fetch",
24
- baseUrl: new URL(process.env.APP_API_BASE_URL!).toString(),
25
24
  mode: "tags",
26
25
  clean: true,
27
26
  override: {
28
27
  mutator: {
29
- path: "./src/api/swr-fetcher.ts",
28
+ path: "./api/swr-fetcher.ts",
30
29
  name: "swrFetcher",
31
30
  },
32
- swr: {
33
- swrOptions: {
34
- errorRetryCount: 3,
35
- errorRetryInterval: 3500,
36
- revalidateOnFocus: false,
37
- },
38
- },
39
31
  },
40
32
  },
41
33
  },
@@ -12,39 +12,38 @@
12
12
  "format": "prettier . --write --cache",
13
13
  "build": "tsc -b && vite build",
14
14
  "preview": "vite preview",
15
- "orval:generate": "tsx --env-file=.env ./scripts/orval-generate-api-definition.ts"
15
+ "orval:generate": "tsx --env-file=.env.development ./scripts/orval-generate-api-definition.ts"
16
16
  },
17
17
  "dependencies": {
18
- "@hookform/resolvers": "3.10.0",
19
- "i18next": "24.2.3",
20
- "react": "18.3.1",
21
- "react-dom": "18.3.1",
22
- "react-helmet-async": "2.0.5",
23
- "react-hook-form": "7.55.0",
24
- "react-router": "7.4.1",
18
+ "@hookform/resolvers": "5.0.1",
19
+ "i18next": "25.0.2",
20
+ "react": "19.1.0",
21
+ "react-dom": "19.1.0",
22
+ "react-hook-form": "7.56.1",
23
+ "react-router": "7.5.3",
25
24
  "swr": "2.3.3",
26
- "zod": "3.24.2",
25
+ "zod": "3.24.3",
27
26
  "zod-i18n-map": "2.27.0"
28
27
  },
29
28
  "devDependencies": {
30
- "@eslint/js": "9.23.0",
31
- "@types/react": "18.3.20",
32
- "@types/react-dom": "18.3.5",
33
- "@vitejs/plugin-react": "4.3.4",
34
- "eslint": "9.23.0",
35
- "eslint-config-prettier": "9.1.0",
29
+ "@eslint/js": "9.25.1",
30
+ "@types/react": "19.1.2",
31
+ "@types/react-dom": "19.1.2",
32
+ "@vitejs/plugin-react": "4.4.1",
33
+ "eslint": "9.25.1",
34
+ "eslint-config-prettier": "10.1.2",
36
35
  "eslint-plugin-react-hooks": "5.2.0",
37
- "eslint-plugin-react-refresh": "0.4.19",
38
- "globals": "15.15.0",
36
+ "eslint-plugin-react-refresh": "0.4.20",
37
+ "globals": "16.0.0",
39
38
  "husky": "9.1.7",
40
- "lint-staged": "15.5.0",
41
- "orval": "7.7.0",
39
+ "lint-staged": "15.5.1",
40
+ "orval": "7.9.0",
42
41
  "prettier": "3.5.3",
43
- "tsx": "4.19.3",
44
- "type-fest": "4.38.0",
45
- "typescript": "~5.8.2",
46
- "typescript-eslint": "8.28.0",
47
- "vite": "6.2.6",
42
+ "tsx": "4.19.4",
43
+ "type-fest": "4.40.1",
44
+ "typescript": "~5.8.3",
45
+ "typescript-eslint": "8.31.1",
46
+ "vite": "6.3.3",
48
47
  "vite-tsconfig-paths": "5.1.4"
49
48
  }
50
49
  }