@carlonicora/nextjs-jsonapi 3.3.0 → 3.3.2

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 (70) hide show
  1. package/dist/{BlockNoteEditor-G5A34EXN.mjs → BlockNoteEditor-SDVXTZRC.mjs} +5 -5
  2. package/dist/{BlockNoteEditor-JLMXCPGB.js → BlockNoteEditor-VV6DRWSA.js} +20 -20
  3. package/dist/{BlockNoteEditor-JLMXCPGB.js.map → BlockNoteEditor-VV6DRWSA.js.map} +1 -1
  4. package/dist/{JsonApiRequest-2OQCZAK6.mjs → JsonApiRequest-ADNIGXTP.mjs} +2 -2
  5. package/dist/JsonApiRequest-WWGSGV2I.js +26 -0
  6. package/dist/{JsonApiRequest-6TYNBVUL.js.map → JsonApiRequest-WWGSGV2I.js.map} +1 -1
  7. package/dist/billing/index.js +399 -399
  8. package/dist/billing/index.mjs +4 -4
  9. package/dist/{chunk-5AKDE5UW.js → chunk-4I3UORNT.js} +941 -938
  10. package/dist/chunk-4I3UORNT.js.map +1 -0
  11. package/dist/{chunk-PGARO3JT.mjs → chunk-KW6LYVFJ.mjs} +8 -7
  12. package/dist/chunk-KW6LYVFJ.mjs.map +1 -0
  13. package/dist/{chunk-UYENG3GT.js → chunk-OHG2YWNA.js} +22 -27
  14. package/dist/chunk-OHG2YWNA.js.map +1 -0
  15. package/dist/{chunk-LCMVARSP.mjs → chunk-RUEY6XSS.mjs} +8 -13
  16. package/dist/chunk-RUEY6XSS.mjs.map +1 -0
  17. package/dist/{chunk-CMGXH5SA.mjs → chunk-RVASYIQG.mjs} +47 -3
  18. package/dist/chunk-RVASYIQG.mjs.map +1 -0
  19. package/dist/{chunk-YKFXQOQA.js → chunk-S2C5V2XZ.js} +33 -32
  20. package/dist/chunk-S2C5V2XZ.js.map +1 -0
  21. package/dist/{chunk-PFAZPP54.js → chunk-W42MYR3Y.js} +59 -15
  22. package/dist/chunk-W42MYR3Y.js.map +1 -0
  23. package/dist/{chunk-O4LTJAAM.mjs → chunk-WPF4NFVV.mjs} +15 -12
  24. package/dist/{chunk-O4LTJAAM.mjs.map → chunk-WPF4NFVV.mjs.map} +1 -1
  25. package/dist/client/index.js +5 -5
  26. package/dist/client/index.mjs +4 -4
  27. package/dist/components/index.js +5 -5
  28. package/dist/components/index.mjs +4 -4
  29. package/dist/contexts/index.js +5 -5
  30. package/dist/contexts/index.mjs +4 -4
  31. package/dist/core/index.d.mts +59 -1
  32. package/dist/core/index.d.ts +59 -1
  33. package/dist/core/index.js +5 -3
  34. package/dist/core/index.js.map +1 -1
  35. package/dist/core/index.mjs +4 -2
  36. package/dist/features/help/index.js +38 -38
  37. package/dist/features/help/index.mjs +4 -4
  38. package/dist/features/tokenusage/index.js +102 -102
  39. package/dist/features/tokenusage/index.mjs +4 -4
  40. package/dist/index.d.mts +1 -1
  41. package/dist/index.d.ts +1 -1
  42. package/dist/index.js +6 -4
  43. package/dist/index.js.map +1 -1
  44. package/dist/index.mjs +5 -3
  45. package/dist/server/index.js +15 -14
  46. package/dist/server/index.js.map +1 -1
  47. package/dist/server/index.mjs +5 -4
  48. package/dist/server/index.mjs.map +1 -1
  49. package/package.json +2 -2
  50. package/src/client/JsonApiClient.ts +3 -2
  51. package/src/client/config.ts +5 -10
  52. package/src/components/forms/FormPlaceAutocomplete.tsx +2 -1
  53. package/src/core/env.ts +73 -0
  54. package/src/core/index.ts +1 -0
  55. package/src/features/auth/utils/AuthCookies.ts +2 -1
  56. package/src/features/company/components/forms/CompanyEditor.tsx +2 -1
  57. package/src/hooks/usePushNotifications.ts +2 -1
  58. package/src/hooks/useSocket.ts +4 -3
  59. package/src/server/JsonApiServer.ts +3 -2
  60. package/src/unified/JsonApiRequest.ts +3 -2
  61. package/dist/JsonApiRequest-6TYNBVUL.js +0 -26
  62. package/dist/chunk-5AKDE5UW.js.map +0 -1
  63. package/dist/chunk-CMGXH5SA.mjs.map +0 -1
  64. package/dist/chunk-LCMVARSP.mjs.map +0 -1
  65. package/dist/chunk-PFAZPP54.js.map +0 -1
  66. package/dist/chunk-PGARO3JT.mjs.map +0 -1
  67. package/dist/chunk-UYENG3GT.js.map +0 -1
  68. package/dist/chunk-YKFXQOQA.js.map +0 -1
  69. /package/dist/{BlockNoteEditor-G5A34EXN.mjs.map → BlockNoteEditor-SDVXTZRC.mjs.map} +0 -0
  70. /package/dist/{JsonApiRequest-2OQCZAK6.mjs.map → JsonApiRequest-ADNIGXTP.mjs.map} +0 -0
@@ -0,0 +1,73 @@
1
+ /**
2
+ * The single place in this package that reads `process.env`.
3
+ *
4
+ * Everything else imports {@link ENV}. Centralising the reads keeps every
5
+ * default in one place — the same contract `base.config.ts` provides on the
6
+ * NestJS side — instead of scattering `process.env.X || "…"` across hooks,
7
+ * clients and components where the fallbacks silently drift apart.
8
+ *
9
+ * WHY THE READS MUST STAY LITERAL: Next.js inlines `NEXT_PUBLIC_*` by textual
10
+ * substitution at build time, replacing the exact expression
11
+ * `process.env.NEXT_PUBLIC_FOO` with a string literal. A computed lookup
12
+ * (`process.env[key]`) is NOT substituted and reads as `undefined` in the
13
+ * browser bundle. Every entry below therefore spells its variable out in full,
14
+ * and new entries must do the same.
15
+ *
16
+ * WHY GETTERS AND NOT PLAIN PROPERTIES: every call site this replaced read
17
+ * `process.env` at CALL time, not at import time. A plain property would freeze
18
+ * the value when the module is first imported, which breaks any consumer that
19
+ * assigns the variable after boot — the package's own tests do exactly that.
20
+ * Getters keep the read lazy while leaving the expression literal, so the build
21
+ * time substitution still applies.
22
+ *
23
+ * Because that substitution happens before the code runs, no reference to
24
+ * `process` survives into the client bundle — so this module is safe to import
25
+ * from client components, server components, route handlers and middleware
26
+ * alike. It deliberately carries no `"use client"` directive for that reason.
27
+ *
28
+ * Values are normalised (empty string rather than `undefined`, booleans rather
29
+ * than string comparisons) so callers never repeat the parsing. Callers that
30
+ * must distinguish "unset" from "set to empty" — the URL getters, which throw a
31
+ * configuration error — check for an empty string.
32
+ */
33
+ export const ENV = {
34
+ /** Public API base URL (NEXT_PUBLIC_API_URL). Empty when unset. */
35
+ get API_URL(): string {
36
+ return process.env.NEXT_PUBLIC_API_URL ?? "";
37
+ },
38
+ /** Public app base URL (NEXT_PUBLIC_ADDRESS). Empty when unset. */
39
+ get APP_URL(): string {
40
+ return process.env.NEXT_PUBLIC_ADDRESS ?? "";
41
+ },
42
+ /**
43
+ * Alternative app base URL (NEXT_PUBLIC_APP_URL), used only by
44
+ * `client/config.ts`'s `getAppUrl()` before it falls back to
45
+ * `window.location.origin`. Empty when unset.
46
+ */
47
+ get APP_URL_ALTERNATE(): string {
48
+ return process.env.NEXT_PUBLIC_APP_URL ?? "";
49
+ },
50
+ /** Web-push VAPID public key (NEXT_PUBLIC_VAPID_PUBLIC_KEY). Empty when unset. */
51
+ get VAPID_PUBLIC_KEY(): string {
52
+ return process.env.NEXT_PUBLIC_VAPID_PUBLIC_KEY ?? "";
53
+ },
54
+ /** Google Maps JS key (NEXT_PUBLIC_GOOGLE_MAPS_API_KEY). Empty disables autocomplete. */
55
+ get GOOGLE_MAPS_API_KEY(): string {
56
+ return process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY ?? "";
57
+ },
58
+ /**
59
+ * NEXT_PUBLIC_PRIVATE_INSTALLATION === "true", case-insensitively
60
+ * (default false). A private installation is a single-tenant deployment.
61
+ */
62
+ get PRIVATE_INSTALLATION(): boolean {
63
+ return process.env.NEXT_PUBLIC_PRIVATE_INSTALLATION?.toLowerCase() === "true";
64
+ },
65
+ /** NODE_ENV === "production" — set by the Next build, not by `.env`. */
66
+ get IS_PRODUCTION(): boolean {
67
+ return process.env.NODE_ENV === "production";
68
+ },
69
+ /** NODE_ENV === "development" — gates verbose client-side diagnostics. */
70
+ get IS_DEVELOPMENT(): boolean {
71
+ return process.env.NODE_ENV === "development";
72
+ },
73
+ };
package/src/core/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  // Core interfaces
2
+ export * from "./env";
2
3
  export * from "./interfaces";
3
4
 
4
5
  // Abstracts
@@ -1,5 +1,6 @@
1
1
  // Server-only cookie utilities (consumers should provide their own server actions via configureAuth)
2
2
 
3
+ import { ENV } from "../../../core/env";
3
4
  import { cookies } from "next/headers";
4
5
  import { gzip } from "pako";
5
6
 
@@ -20,7 +21,7 @@ export async function updateToken(params: {
20
21
  };
21
22
  }[];
22
23
  }): Promise<void> {
23
- const isProduction = process.env.NODE_ENV === "production";
24
+ const isProduction = ENV.IS_PRODUCTION;
24
25
 
25
26
  if (params.token)
26
27
  (await cookies()).set({
@@ -21,6 +21,7 @@ import {
21
21
  } from "../../../../components";
22
22
  import type { FiscalDataHandle } from "../../../../components";
23
23
  import { SectionHeader } from "../../../../components/typography";
24
+ import { ENV } from "../../../../core/env";
24
25
  import { Modules } from "../../../../core";
25
26
  import { useI18nRouter } from "../../../../i18n";
26
27
  import { getRoleId } from "../../../../roles";
@@ -69,7 +70,7 @@ function CompanyEditorInternal({
69
70
  const canAccessFeatures =
70
71
  hasRole(getRoleId().Administrator) ||
71
72
  (hasRole(getRoleId().CompanyAdministrator) &&
72
- process.env.NEXT_PUBLIC_PRIVATE_INSTALLATION?.toLowerCase() === "true");
73
+ ENV.PRIVATE_INSTALLATION);
73
74
 
74
75
  // Fetch features when sheet opens
75
76
  const handleDialogOpenChange = useCallback(
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  import { useEffect } from "react";
4
+ import { ENV } from "../core/env";
4
5
  import { useCurrentUserContext } from "../contexts";
5
6
  import { UserInterface } from "../features/user/data";
6
7
  import { PushService } from "../features/push/data/push.service";
@@ -43,7 +44,7 @@ export default function usePushNotifications(): void {
43
44
  return; // User denied permission, this is not an error
44
45
  }
45
46
 
46
- const vapidPublicKey = (process.env.NEXT_PUBLIC_VAPID_PUBLIC_KEY || "").trim();
47
+ const vapidPublicKey = ENV.VAPID_PUBLIC_KEY.trim();
47
48
  if (!vapidPublicKey) {
48
49
  return;
49
50
  }
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { useEffect, useRef, useState } from "react";
4
4
  import io from "socket.io-client";
5
+ import { ENV } from "../core/env";
5
6
  import { Modules, rehydrate } from "../core";
6
7
  import { NotificationInterface } from "../features/notification/data";
7
8
 
@@ -45,7 +46,7 @@ export function useSocket({ token }: UseSocketOptions): UseSocketReturn {
45
46
  useEffect(() => {
46
47
  if (!token) return;
47
48
 
48
- const globalSocketKey = `__socket_${process.env.NEXT_PUBLIC_API_URL?.replace(/[^a-zA-Z0-9]/g, "_")}`;
49
+ const globalSocketKey = `__socket_${ENV.API_URL.replace(/[^a-zA-Z0-9]/g, "_")}`;
49
50
 
50
51
  if (typeof window !== "undefined") {
51
52
  const _allSocketKeys = Object.keys(window).filter((key) => key.startsWith("__socket_"));
@@ -79,7 +80,7 @@ export function useSocket({ token }: UseSocketOptions): UseSocketReturn {
79
80
  shouldConnect.current = false;
80
81
 
81
82
  try {
82
- currentSocket = io(process.env.NEXT_PUBLIC_API_URL as string, {
83
+ currentSocket = io(ENV.API_URL, {
83
84
  auth: { token },
84
85
  transports: ["websocket"],
85
86
  timeout: 20000,
@@ -147,7 +148,7 @@ export function useSocket({ token }: UseSocketOptions): UseSocketReturn {
147
148
 
148
149
  // In development, preserve socket in window for HMR but remove listeners
149
150
  if (currentSocket) {
150
- if (process.env.NODE_ENV === "development") {
151
+ if (ENV.IS_DEVELOPMENT) {
151
152
  currentSocket.off("connect", handleConnect);
152
153
  currentSocket.off("disconnect", handleDisconnect);
153
154
  currentSocket.off("message", handleMessage);
@@ -1,5 +1,6 @@
1
1
  // Server-only utilities (NOT server actions - these cannot be called from client components)
2
2
 
3
+ import { ENV } from "../core/env";
3
4
  import { JsonApiDataFactory } from "../core/factories/JsonApiDataFactory";
4
5
  import { ApiRequestDataTypeInterface } from "../core/interfaces/ApiRequestDataTypeInterface";
5
6
  import { ApiResponseInterface } from "../core/interfaces/ApiResponseInterface";
@@ -38,7 +39,7 @@ export function getServerApiUrl(): string {
38
39
  if (_serverConfig?.apiUrl) {
39
40
  return _serverConfig.apiUrl;
40
41
  }
41
- const envUrl = process.env.NEXT_PUBLIC_API_URL;
42
+ const envUrl = ENV.API_URL;
42
43
  if (!envUrl) {
43
44
  throw new Error(
44
45
  "API URL not configured. Use configureServerJsonApi() or set NEXT_PUBLIC_API_URL environment variable.",
@@ -51,7 +52,7 @@ export function getServerAppUrl(): string {
51
52
  if (_serverConfig?.appUrl) {
52
53
  return _serverConfig.appUrl;
53
54
  }
54
- const envUrl = process.env.NEXT_PUBLIC_ADDRESS;
55
+ const envUrl = ENV.APP_URL;
55
56
  if (!envUrl) {
56
57
  throw new Error(
57
58
  "App URL not configured. Use configureServerJsonApi({ appUrl }) or set NEXT_PUBLIC_ADDRESS environment variable.",
@@ -1,3 +1,4 @@
1
+ import { ENV } from "../core/env";
1
2
  import { JsonApiDataFactory } from "../core/factories/JsonApiDataFactory";
2
3
  import { ApiData } from "../core/interfaces/ApiData";
3
4
  import { ApiRequestDataTypeInterface } from "../core/interfaces/ApiRequestDataTypeInterface";
@@ -136,7 +137,7 @@ export function getApiUrl(): string {
136
137
  return _staticConfig.apiUrl;
137
138
  }
138
139
  // Fallback to environment variable
139
- const envUrl = process.env.NEXT_PUBLIC_API_URL;
140
+ const envUrl = ENV.API_URL;
140
141
  if (!envUrl) {
141
142
  throw new Error("API URL not configured. Use configureJsonApi() or set NEXT_PUBLIC_API_URL environment variable.");
142
143
  }
@@ -148,7 +149,7 @@ export function getAppUrl(): string {
148
149
  return _staticConfig.appUrl;
149
150
  }
150
151
  // Fallback to environment variable
151
- const envUrl = process.env.NEXT_PUBLIC_ADDRESS;
152
+ const envUrl = ENV.APP_URL;
152
153
  if (!envUrl) {
153
154
  throw new Error(
154
155
  "App URL not configured. Use configureJsonApi({ appUrl }) or set NEXT_PUBLIC_ADDRESS environment variable.",
@@ -1,26 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
- var _chunkPFAZPP54js = require('./chunk-PFAZPP54.js');
13
- require('./chunk-7QVYU63E.js');
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
- exports.JsonApiDelete = _chunkPFAZPP54js.JsonApiDelete; exports.JsonApiGet = _chunkPFAZPP54js.JsonApiGet; exports.JsonApiPatch = _chunkPFAZPP54js.JsonApiPatch; exports.JsonApiPost = _chunkPFAZPP54js.JsonApiPost; exports.JsonApiPut = _chunkPFAZPP54js.JsonApiPut; exports.buildUrl = _chunkPFAZPP54js.buildUrl; exports.configureJsonApi = _chunkPFAZPP54js.configureJsonApi; exports.getApiUrl = _chunkPFAZPP54js.getApiUrl; exports.getAppUrl = _chunkPFAZPP54js.getAppUrl; exports.getTrackablePages = _chunkPFAZPP54js.getTrackablePages;
26
- //# sourceMappingURL=JsonApiRequest-6TYNBVUL.js.map