Skip to content

Commit 14f306b

Browse files
committed
chore: release prep for v1.25.4
1 parent a36f3f3 commit 14f306b

File tree

8 files changed

+107
-50
lines changed

8 files changed

+107
-50
lines changed

.env.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Rename to `.env` (or `.env.local`) and customize as needed
66

77
# Custom environment mode for scripts and tooling
8-
# One of: dev, test, ci, preview, prod
8+
# One of: dev, test, ci, preview, production
99
ENV_MODE=dev
1010

1111
# Optional: API keys or tokens for local dev (never commit real values)

CHANGELOG.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,45 @@ This project attempts to follow [Keep a Changelog](https://keepachangelog.com/en
2222

2323
---
2424

25+
## [1.25.4] - 2025-11-03
26+
27+
### Added
28+
29+
- `detectEnvironment()` now returns:
30+
- `isDebug` boolean (true if `isDev` or `isTest`)
31+
- `isLocalhost` (optional, in browser contexts)
32+
- Support for `PUBLIC_POSTHOG_PROJECT_KEY` using `import.meta.env`
33+
- Dynamic PostHog initialization (`initPostHog`) now uses env-based key injection
34+
- vite.config.js:
35+
- `envPrefix: ['PUBLIC_']` added to expose public vars to client
36+
- Console banner for `ENV_MODE`, `PUBLIC_ENV_MODE`, and audit-mode warning
37+
- CSP debug logs gated behind `isDebug` and server-only context
38+
- `.env.production` support via `--mode=production` guidance
39+
- Conditional `minify` flag for `lightningcssPlugin` based on `mode` (`production` or `audit`)
40+
41+
### Changed
42+
43+
- Environment detection (`env.js`) now respects hostname overrides and normalizes fallback logic for SSR/client consistency
44+
- Logs in `hooks.server.js` and PostHog analytics client are now gated by `isDebug` to avoid unnecessary noise in production
45+
- Better logging structure for PostHog initialization, including full `import.meta.env` dump in debug mode
46+
- Updated `engines.node` in `package.json` to require **Node.js** `>=24.0.0 <25`
47+
- **Node.js v22** is no longer supported
48+
- Bumped project version to `v1.25.4`
49+
50+
### Fixed
51+
52+
- Broken or undefined env var behavior due to missing `envPrefix` in `vite.config.js`
53+
- Client-only `import.meta.env.PUBLIC_*` variables incorrectly resolving as `undefined` in production builds
54+
- CSP not reflecting audit context due to host-based detection mismatch
55+
56+
### Developer Notes
57+
58+
- `.env.production` is **now required** for full environment variable injection during `npm run build --mode=production` or Vercel deployments.
59+
- Without it, `PUBLIC_` variables (e.g. `PUBLIC_POSTHOG_PROJECT_KEY`) may resolve as undefined in the client bundle.
60+
- Local builds can still fall back to `.env` or `.env.development` by default.
61+
62+
---
63+
2564
## [1.25.3] - 2025-11-03
2665

2766
### Changed
@@ -1649,7 +1688,8 @@ This enables analytics filtering and CSP hardening for the audit environment.
16491688

16501689
<!-- Link references -->
16511690

1652-
[Unreleased]: https://github.com/netwk-pro/netwk-pro.github.io/compare/v1.25.3...HEAD
1691+
[Unreleased]: https://github.com/netwk-pro/netwk-pro.github.io/compare/v1.25.4...HEAD
1692+
[1.25.4]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.4
16531693
[1.25.3]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.3
16541694
[1.25.2]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.2
16551695
[1.25.1]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.1

package-lock.json

Lines changed: 13 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@networkpro/web",
33
"private": false,
4-
"version": "1.25.3",
4+
"version": "1.25.4",
55
"description": "Locking Down Networks, Unlocking Confidence™ | Security, Networking, Privacy — Network Pro Strategies",
66
"keywords": [
77
"advisory",
@@ -30,15 +30,15 @@
3030
},
3131
"type": "module",
3232
"engines": {
33-
"node": ">=22.0.0 <25",
33+
"node": ">=24.0.0 <25",
3434
"npm": ">=10.0.0 <12"
3535
},
3636
"scripts": {
3737
"dev": "vite dev",
3838
"dev:audit": "vite --mode audit",
3939
"start": "npm run dev",
4040
"dev:vercel": "vercel dev",
41-
"build": "vite build",
41+
"build": "vite build --mode production",
4242
"build:audit": "vite build --mode audit",
4343
"build:vercel": "vercel build",
4444
"preview": "vite preview",

src/hooks.server.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@ export async function handle({ event, resolve }) {
1616
const response = await resolve(event);
1717

1818
const env = detectEnvironment(event.url.hostname);
19-
const { isAudit, isTest, isProd, mode, effective } = env;
20-
21-
console.log('[CSP Debug ENV]', {
22-
mode,
23-
effective,
24-
hostname: event.url.hostname,
25-
isAudit,
26-
isTest,
27-
isProd,
28-
});
19+
const { isAudit, isDebug, isTest, isProd, mode, effective } = env;
20+
21+
// Show logs in dev only
22+
if (isDebug) {
23+
console.log('[CSP Debug ENV]', {
24+
mode,
25+
effective,
26+
hostname: event.url.hostname,
27+
isAudit,
28+
isTest,
29+
isProd,
30+
});
31+
}
2932

3033
// Determine report URI
3134
const reportUri =
@@ -49,7 +52,7 @@ export async function handle({ event, resolve }) {
4952
];
5053

5154
// 🧪 Looser CSP for local/CI test environments
52-
if (isTest) {
55+
if (isDebug) {
5356
cspDirectives[1] =
5457
"script-src 'self' 'unsafe-inline' 'unsafe-eval' http://localhost:* ws://localhost:*;";
5558
cspDirectives[2] = "style-src 'self' 'unsafe-inline' http://localhost:*;";

src/lib/stores/posthog.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ let ph = null;
4545
export async function initPostHog() {
4646
if (initialized || typeof window === 'undefined') return;
4747

48-
const { isAudit, isDev, isTest, mode, effective } = detectEnvironment();
48+
const { isAudit, isDebug, isDev, isTest, mode, effective } =
49+
detectEnvironment();
4950

5051
// 🌐 Hybrid hostname + environment guard
5152
const host = window.location.hostname;
5253
const isAuditHost = /(^|\.)audit\.netwk\.pro$/i.test(host);
5354
const effectiveAudit = isAudit || isAuditHost;
54-
const isDebug = isDev || isTest;
5555

5656
// 🧭 Log environment context before any conditional logic
5757
if (isDebug) {
@@ -95,9 +95,17 @@ export async function initPostHog() {
9595
const posthogModule = await import('posthog-js');
9696
ph = posthogModule.default;
9797

98+
// ✅ Load public key from env
99+
const key = import.meta.env.PUBLIC_POSTHOG_PROJECT_KEY;
100+
//console.log('✅ Key in runtime:', key);
101+
102+
if (!key) {
103+
console.warn('[PostHog] ⚠️ PUBLIC_POSTHOG_PROJECT_KEY is not set.');
104+
return;
105+
}
106+
98107
// ✅ Initialize PostHog
99-
// cspell:disable-next-line
100-
ph.init('phc_Qshfo6AXzh4pS7aPigfqyeo4qj1qlyh7gDuHDeVMSR0', {
108+
ph.init(key, {
101109
api_host: '/relay-MSR0/',
102110
ui_host: 'https://us.posthog.com',
103111
autocapture: true,

src/lib/utils/env.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ This file is part of Network Pro.
3333
* @property {boolean} isAudit
3434
* @property {boolean} isCI
3535
* @property {boolean} isTest
36+
* @property {boolean} isDebug - True in dev or test mode (but not prod/audit)
37+
* @property {boolean} isLocalhost - True if running on localhost (client context only)
3638
*/
3739

3840
/**
@@ -51,30 +53,43 @@ export const BUILD_ENV_MODE =
5153
* @returns {EnvironmentInfo}
5254
*/
5355
export function detectEnvironment(hostOverride) {
54-
const mode = BUILD_ENV_MODE;
56+
const mode = (BUILD_ENV_MODE || '').toLowerCase();
5557

5658
// Determine host based on execution context
5759
const host =
5860
hostOverride ||
5961
(typeof window !== 'undefined' ? window.location.hostname : '');
6062

6163
const hostIsAudit = /(^|\.)audit\.netwk\.pro$/i.test(host);
64+
const isLocalhost = /^localhost$|^127\.0\.0\.1$/.test(host);
6265

6366
const isDev = ['development', 'dev'].includes(mode);
6467
const isProd = ['production', 'prod'].includes(mode);
6568
const isAudit = mode === 'audit' || hostIsAudit;
6669
const isCI = mode === 'ci';
6770
const isTest = mode === 'test';
71+
const isDebug = isDev || isTest;
6872

6973
const effective = hostIsAudit && !isAudit ? 'audit(host)' : mode;
7074

71-
if (typeof window === 'undefined') {
72-
console.log('[detectEnvironment] Server-side build mode:', mode);
73-
console.log('[detectEnvironment] Hostname:', host || '(none)');
75+
if (typeof window === 'undefined' && isDebug) {
76+
console.log('🧭 [env] Server-side build mode:', mode);
77+
console.log('🧭 [env] Hostname:', host || '(none)');
78+
console.log('🧭 [env] Raw env:', import.meta.env);
7479
if (hostIsAudit && mode !== 'audit') {
75-
console.log('[detectEnvironment] Host suggests audit, overriding mode.');
80+
console.log('[env] Host suggests audit, overriding mode.');
7681
}
7782
}
7883

79-
return { mode, effective, isDev, isProd, isAudit, isCI, isTest };
84+
return {
85+
mode,
86+
effective,
87+
isDev,
88+
isProd,
89+
isAudit,
90+
isCI,
91+
isTest,
92+
isDebug,
93+
isLocalhost,
94+
};
8095
}

vite.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export default defineConfig(({ mode }) => {
4848
// -----------------------------------------------------------------------
4949

5050
return {
51+
envPrefix: ['PUBLIC_'],
5152
plugins: [
5253
tsconfigPaths(),
5354
devtoolsJson({
@@ -57,7 +58,7 @@ export default defineConfig(({ mode }) => {
5758
}),
5859
sveltekit(),
5960
lightningcssPlugin({
60-
minify: process.env.NODE_ENV === 'production',
61+
minify: ['production', 'audit'].includes(mode),
6162
pruneUnusedFontFaceRules: true,
6263
pruneUnusedKeyframes: true,
6364
removeUnusedFontFaces: true,

0 commit comments

Comments
 (0)