@networkpro/web 1.25.0 → 1.25.1
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/CHANGELOG.md +29 -1
- package/package.json +1 -1
- package/src/hooks.server.js +2 -2
- package/src/lib/stores/posthog.js +15 -2
- package/src/lib/utils/env.js +42 -35
- package/src/routes/api/env-check/+server.js +25 -0
- package/vite.config.js +38 -16
package/CHANGELOG.md
CHANGED
|
@@ -22,6 +22,33 @@ This project attempts to follow [Keep a Changelog](https://keepachangelog.com/en
|
|
|
22
22
|
|
|
23
23
|
---
|
|
24
24
|
|
|
25
|
+
## [1.25.1]
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
- Introduced new **environment diagnostics endpoint** at `src/routes/api/env-check/+server.js`.
|
|
30
|
+
- Returns resolved build and runtime environment data for verification.
|
|
31
|
+
- Useful for confirming `ENV_MODE` / `PUBLIC_ENV_MODE` propagation on Vercel builds.
|
|
32
|
+
- Helps troubleshoot environment mismatches between build-time and client-side contexts.
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
|
|
36
|
+
- **vite.config.js**
|
|
37
|
+
- Enhanced configuration to log build mode and environment variables during bundling.
|
|
38
|
+
- Prints `mode`, `ENV_MODE`, `PUBLIC_ENV_MODE`, and `NODE_ENV` to aid CI/CD debugging.
|
|
39
|
+
- Uses color-coded console output for clear visibility in build logs.
|
|
40
|
+
- **env.js**
|
|
41
|
+
- Simplified and stabilized environment detection logic for better cross-environment consistency.
|
|
42
|
+
- Removed redundant imports and corrected handling of static vs dynamic `BUILD_ENV_MODE`.
|
|
43
|
+
- Improved comments and type annotations for maintainability and IDE autocompletion.
|
|
44
|
+
|
|
45
|
+
### Developer Experience
|
|
46
|
+
|
|
47
|
+
- Build logs now clearly display environment information before bundling.
|
|
48
|
+
- `env-check` API endpoint provides real-time environment inspection without rebuilding.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
25
52
|
## [1.25.0]
|
|
26
53
|
|
|
27
54
|
### Added
|
|
@@ -1583,7 +1610,8 @@ This enables analytics filtering and CSP hardening for the audit environment.
|
|
|
1583
1610
|
|
|
1584
1611
|
<!-- Link references -->
|
|
1585
1612
|
|
|
1586
|
-
[Unreleased]: https://github.com/netwk-pro/netwk-pro.github.io/compare/v1.25.
|
|
1613
|
+
[Unreleased]: https://github.com/netwk-pro/netwk-pro.github.io/compare/v1.25.1...HEAD
|
|
1614
|
+
[1.25.1]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.1
|
|
1587
1615
|
[1.25.0]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.0
|
|
1588
1616
|
[1.24.5]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.24.5
|
|
1589
1617
|
[1.24.4]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.24.4
|
package/package.json
CHANGED
package/src/hooks.server.js
CHANGED
|
@@ -14,9 +14,9 @@ import { detectEnvironment } from '$lib/utils/env.js';
|
|
|
14
14
|
*/
|
|
15
15
|
export async function handle({ event, resolve }) {
|
|
16
16
|
const response = await resolve(event);
|
|
17
|
-
const { isAudit, isTest, isProd } = detectEnvironment();
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
const { isAudit, isTest, isProd, effective, mode } = detectEnvironment();
|
|
19
|
+
console.log('[CSP Debug ENV]', { mode, effective, isProd, isAudit, isTest });
|
|
20
20
|
|
|
21
21
|
// Determine report URI
|
|
22
22
|
const reportUri =
|
|
@@ -45,15 +45,28 @@ let ph = null;
|
|
|
45
45
|
export async function initPostHog() {
|
|
46
46
|
if (initialized || typeof window === 'undefined') return;
|
|
47
47
|
|
|
48
|
-
const { isAudit, isDev, isTest, mode } = detectEnvironment();
|
|
48
|
+
const { isAudit, isDev, isTest, mode, effective } = detectEnvironment();
|
|
49
49
|
|
|
50
50
|
// 🌐 Hybrid hostname + environment guard
|
|
51
51
|
const host = window.location.hostname;
|
|
52
52
|
const isAuditHost = /(^|\.)audit\.netwk\.pro$/i.test(host);
|
|
53
53
|
const effectiveAudit = isAudit || isAuditHost;
|
|
54
54
|
|
|
55
|
+
// 🧭 Log environment context before any conditional logic
|
|
56
|
+
console.info('[PostHog ENV]', {
|
|
57
|
+
buildMode: mode,
|
|
58
|
+
effectiveMode: effective,
|
|
59
|
+
host,
|
|
60
|
+
effectiveAudit,
|
|
61
|
+
isDev,
|
|
62
|
+
isTest,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// 🚫 Skip analytics in audit context
|
|
55
66
|
if (effectiveAudit) {
|
|
56
|
-
console.info(
|
|
67
|
+
console.info(
|
|
68
|
+
`[PostHog] Skipping analytics (${effective} mode, host: ${host}).`,
|
|
69
|
+
);
|
|
57
70
|
return;
|
|
58
71
|
}
|
|
59
72
|
|
package/src/lib/utils/env.js
CHANGED
|
@@ -26,49 +26,56 @@ This file is part of Network Pro.
|
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @typedef {object} EnvironmentInfo
|
|
29
|
-
* @property {string} mode
|
|
30
|
-
* @property {
|
|
31
|
-
* @property {boolean}
|
|
32
|
-
* @property {boolean}
|
|
33
|
-
* @property {boolean}
|
|
34
|
-
* @property {boolean}
|
|
29
|
+
* @property {string} mode - The build-time environment mode.
|
|
30
|
+
* @property {string} effective - The environment actually being used (after host fallback).
|
|
31
|
+
* @property {boolean} isDev
|
|
32
|
+
* @property {boolean} isProd
|
|
33
|
+
* @property {boolean} isAudit
|
|
34
|
+
* @property {boolean} isCI
|
|
35
|
+
* @property {boolean} isTest
|
|
35
36
|
*/
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
39
|
+
* Build-time mode injected by Vite.
|
|
40
|
+
* Always baked into the client bundle.
|
|
41
|
+
* Falls back to 'production' if nothing else is defined.
|
|
42
|
+
*/
|
|
43
|
+
export const BUILD_ENV_MODE =
|
|
44
|
+
import.meta.env.PUBLIC_ENV_MODE || import.meta.env.MODE || 'production';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Detects the current environment, combining build-time
|
|
48
|
+
* and runtime (hostname-based) checks.
|
|
49
|
+
* Works safely in both Node and browser contexts.
|
|
40
50
|
*
|
|
41
|
-
* @returns {EnvironmentInfo}
|
|
51
|
+
* @returns {EnvironmentInfo}
|
|
42
52
|
*/
|
|
43
53
|
export function detectEnvironment() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
54
|
+
const mode = BUILD_ENV_MODE;
|
|
55
|
+
|
|
56
|
+
// Client-side fallback for audit/netwk environments
|
|
57
|
+
const host = typeof window !== 'undefined' ? window.location.hostname : '';
|
|
58
|
+
|
|
59
|
+
const hostIsAudit = /(^|\.)audit\.netwk\.pro$/i.test(host);
|
|
48
60
|
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
const isDev = ['development', 'dev'].includes(mode);
|
|
62
|
+
const isProd = ['production', 'prod'].includes(mode);
|
|
63
|
+
const isAudit = mode === 'audit' || hostIsAudit;
|
|
64
|
+
const isCI = mode === 'ci';
|
|
65
|
+
const isTest = mode === 'test';
|
|
54
66
|
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
typeof process !== 'undefined' && process?.env?.ENV_MODE
|
|
58
|
-
? process.env.ENV_MODE
|
|
59
|
-
: undefined;
|
|
67
|
+
// Prefer host-based detection if it disagrees with build-time
|
|
68
|
+
const effective = hostIsAudit && !isAudit ? 'audit(host)' : mode;
|
|
60
69
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
if (typeof window === 'undefined') {
|
|
71
|
+
// Only log on server / build to avoid client noise
|
|
72
|
+
console.log('[detectEnvironment] Build mode:', mode);
|
|
73
|
+
if (hostIsAudit && mode !== 'audit') {
|
|
74
|
+
console.log(
|
|
75
|
+
'[detectEnvironment] Host suggests audit, overriding build-time mode.',
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
64
79
|
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
mode,
|
|
68
|
-
isDev: ['development', 'dev'].includes(mode),
|
|
69
|
-
isProd: ['production', 'prod'].includes(mode),
|
|
70
|
-
isAudit: mode === 'audit',
|
|
71
|
-
isCI: mode === 'ci',
|
|
72
|
-
isTest: mode === 'test',
|
|
73
|
-
};
|
|
80
|
+
return { mode, effective, isDev, isProd, isAudit, isCI, isTest };
|
|
74
81
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* ==========================================================================
|
|
2
|
+
src/routes/api/env-check/+server.js
|
|
3
|
+
|
|
4
|
+
Copyright © 2025 Network Pro Strategies (Network Pro™)
|
|
5
|
+
SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
|
|
6
|
+
This file is part of Network Pro.
|
|
7
|
+
========================================================================== */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @file Returns the current environment state (client + server vars)
|
|
11
|
+
* @type {import('@sveltejs/kit').RequestHandler}
|
|
12
|
+
*/
|
|
13
|
+
export async function GET() {
|
|
14
|
+
const data = {
|
|
15
|
+
NODE_ENV: process.env.NODE_ENV,
|
|
16
|
+
ENV_MODE: process.env.ENV_MODE,
|
|
17
|
+
PUBLIC_ENV_MODE: process.env.PUBLIC_ENV_MODE,
|
|
18
|
+
IMPORT_META_MODE: import.meta.env.MODE,
|
|
19
|
+
IMPORT_META_PUBLIC: import.meta.env.PUBLIC_ENV_MODE,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return new Response(JSON.stringify(data, null, 2), {
|
|
23
|
+
headers: { 'Content-Type': 'application/json' },
|
|
24
|
+
});
|
|
25
|
+
}
|
package/vite.config.js
CHANGED
|
@@ -17,20 +17,42 @@ import tsconfigPaths from 'vite-tsconfig-paths'; // NEW: tsconfig/jsconfig alias
|
|
|
17
17
|
// Compute absolute project root
|
|
18
18
|
const projectRoot = fileURLToPath(new URL('.', import.meta.url));
|
|
19
19
|
|
|
20
|
-
export default defineConfig({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
export default defineConfig(({ mode }) => {
|
|
21
|
+
// --- 🧩 Log Build Environment Info -------------------------------------
|
|
22
|
+
console.log(
|
|
23
|
+
'\x1b[36m%s\x1b[0m',
|
|
24
|
+
'──────────────────────────────────────────────',
|
|
25
|
+
);
|
|
26
|
+
console.log('\x1b[33m%s\x1b[0m', `📦 Building Network Pro — mode: ${mode}`);
|
|
27
|
+
console.log(
|
|
28
|
+
'\x1b[36m%s\x1b[0m',
|
|
29
|
+
'──────────────────────────────────────────────',
|
|
30
|
+
);
|
|
31
|
+
console.log('ENV_MODE:', process.env.ENV_MODE);
|
|
32
|
+
console.log('PUBLIC_ENV_MODE:', process.env.PUBLIC_ENV_MODE);
|
|
33
|
+
console.log('NODE_ENV:', process.env.NODE_ENV);
|
|
34
|
+
console.log(
|
|
35
|
+
'\x1b[36m%s\x1b[0m',
|
|
36
|
+
'──────────────────────────────────────────────',
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// -----------------------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
plugins: [
|
|
43
|
+
tsconfigPaths(),
|
|
44
|
+
devtoolsJson({
|
|
45
|
+
projectRoot: resolve(projectRoot),
|
|
46
|
+
normalizeForWindowsContainer: true,
|
|
47
|
+
uuid: 'ad0db4f4-6172-4c1e-ae17-26b1bee53764',
|
|
48
|
+
}),
|
|
49
|
+
sveltekit(),
|
|
50
|
+
lightningcssPlugin({
|
|
51
|
+
minify: process.env.NODE_ENV === 'production',
|
|
52
|
+
pruneUnusedFontFaceRules: true,
|
|
53
|
+
pruneUnusedKeyframes: true,
|
|
54
|
+
removeUnusedFontFaces: true,
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
};
|
|
36
58
|
});
|