@carlonicora/nextjs-jsonapi 3.3.1 → 3.3.3
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/{BlockNoteEditor-JLMXCPGB.js → BlockNoteEditor-4LBUVIW6.js} +20 -20
- package/dist/{BlockNoteEditor-JLMXCPGB.js.map → BlockNoteEditor-4LBUVIW6.js.map} +1 -1
- package/dist/{BlockNoteEditor-G5A34EXN.mjs → BlockNoteEditor-CSPPZOZQ.mjs} +5 -5
- package/dist/{JsonApiRequest-2OQCZAK6.mjs → JsonApiRequest-ADNIGXTP.mjs} +2 -2
- package/dist/JsonApiRequest-WWGSGV2I.js +26 -0
- package/dist/{JsonApiRequest-6TYNBVUL.js.map → JsonApiRequest-WWGSGV2I.js.map} +1 -1
- package/dist/billing/index.js +399 -399
- package/dist/billing/index.mjs +4 -4
- package/dist/{chunk-5AKDE5UW.js → chunk-2PEPIH26.js} +941 -938
- package/dist/chunk-2PEPIH26.js.map +1 -0
- package/dist/{chunk-PGARO3JT.mjs → chunk-KW6LYVFJ.mjs} +8 -7
- package/dist/chunk-KW6LYVFJ.mjs.map +1 -0
- package/dist/{chunk-UYENG3GT.js → chunk-OHG2YWNA.js} +22 -27
- package/dist/chunk-OHG2YWNA.js.map +1 -0
- package/dist/{chunk-LCMVARSP.mjs → chunk-RUEY6XSS.mjs} +8 -13
- package/dist/chunk-RUEY6XSS.mjs.map +1 -0
- package/dist/{chunk-CMGXH5SA.mjs → chunk-RVASYIQG.mjs} +47 -3
- package/dist/chunk-RVASYIQG.mjs.map +1 -0
- package/dist/{chunk-YKFXQOQA.js → chunk-S2C5V2XZ.js} +33 -32
- package/dist/chunk-S2C5V2XZ.js.map +1 -0
- package/dist/{chunk-O4LTJAAM.mjs → chunk-SVCOFVQF.mjs} +15 -12
- package/dist/chunk-SVCOFVQF.mjs.map +1 -0
- package/dist/{chunk-PFAZPP54.js → chunk-W42MYR3Y.js} +59 -15
- package/dist/chunk-W42MYR3Y.js.map +1 -0
- package/dist/client/index.js +5 -5
- package/dist/client/index.mjs +4 -4
- package/dist/components/index.js +5 -5
- package/dist/components/index.mjs +4 -4
- package/dist/contexts/index.js +5 -5
- package/dist/contexts/index.mjs +4 -4
- package/dist/core/index.d.mts +59 -1
- package/dist/core/index.d.ts +59 -1
- package/dist/core/index.js +5 -3
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +4 -2
- package/dist/features/help/index.js +38 -38
- package/dist/features/help/index.mjs +4 -4
- package/dist/features/tokenusage/index.js +102 -102
- package/dist/features/tokenusage/index.mjs +4 -4
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -3
- package/dist/server/index.js +15 -14
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +5 -4
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client/JsonApiClient.ts +3 -2
- package/src/client/config.ts +5 -10
- package/src/components/forms/FormPlaceAutocomplete.tsx +2 -1
- package/src/core/env.ts +73 -0
- package/src/core/index.ts +1 -0
- package/src/features/auth/utils/AuthCookies.ts +2 -1
- package/src/features/company/components/forms/CompanyEditor.tsx +2 -3
- package/src/hooks/usePushNotifications.ts +2 -1
- package/src/hooks/useSocket.ts +4 -3
- package/src/server/JsonApiServer.ts +3 -2
- package/src/unified/JsonApiRequest.ts +3 -2
- package/dist/JsonApiRequest-6TYNBVUL.js +0 -26
- package/dist/chunk-5AKDE5UW.js.map +0 -1
- package/dist/chunk-CMGXH5SA.mjs.map +0 -1
- package/dist/chunk-LCMVARSP.mjs.map +0 -1
- package/dist/chunk-O4LTJAAM.mjs.map +0 -1
- package/dist/chunk-PFAZPP54.js.map +0 -1
- package/dist/chunk-PGARO3JT.mjs.map +0 -1
- package/dist/chunk-UYENG3GT.js.map +0 -1
- package/dist/chunk-YKFXQOQA.js.map +0 -1
- /package/dist/{BlockNoteEditor-G5A34EXN.mjs.map → BlockNoteEditor-CSPPZOZQ.mjs.map} +0 -0
- /package/dist/{JsonApiRequest-2OQCZAK6.mjs.map → JsonApiRequest-ADNIGXTP.mjs.map} +0 -0
package/src/core/env.ts
ADDED
|
@@ -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,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 =
|
|
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";
|
|
@@ -67,9 +68,7 @@ function CompanyEditorInternal({
|
|
|
67
68
|
const addressComponentsRef = useRef<Record<string, string>>({});
|
|
68
69
|
|
|
69
70
|
const canAccessFeatures =
|
|
70
|
-
hasRole(getRoleId().Administrator) ||
|
|
71
|
-
(hasRole(getRoleId().CompanyAdministrator) &&
|
|
72
|
-
process.env.NEXT_PUBLIC_PRIVATE_INSTALLATION?.toLowerCase() === "true");
|
|
71
|
+
hasRole(getRoleId().Administrator) || (hasRole(getRoleId().CompanyAdministrator) && ENV.PRIVATE_INSTALLATION);
|
|
73
72
|
|
|
74
73
|
// Fetch features when sheet opens
|
|
75
74
|
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 =
|
|
47
|
+
const vapidPublicKey = ENV.VAPID_PUBLIC_KEY.trim();
|
|
47
48
|
if (!vapidPublicKey) {
|
|
48
49
|
return;
|
|
49
50
|
}
|
package/src/hooks/useSocket.ts
CHANGED
|
@@ -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_${
|
|
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(
|
|
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 (
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|