slicejs-web-framework 3.3.7 → 3.3.8

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.
@@ -1,117 +1,123 @@
1
- import { readFileSync, existsSync } from 'node:fs';
2
-
3
- const PUBLIC_PREFIX = 'SLICE_PUBLIC_';
4
- const SUSPICIOUS_TERMS = ['SECRET', 'TOKEN', 'PASSWORD', 'PRIVATE', 'API_KEY', 'ACCESS_KEY', 'CREDENTIAL'];
5
-
6
- function parseEnvFile(envFilePath) {
7
- if (!envFilePath || !existsSync(envFilePath)) {
8
- return {};
9
- }
10
-
11
- const fileContent = readFileSync(envFilePath, 'utf8').replace(/^\uFEFF/, '');
12
- const parsed = {};
13
- const lines = fileContent.split(/\r?\n/);
14
-
15
- for (const rawLine of lines) {
16
- const line = rawLine.trim();
17
-
18
- if (!line || line.startsWith('#')) {
19
- continue;
20
- }
21
-
22
- const equalsIndex = line.indexOf('=');
23
- if (equalsIndex === -1) {
24
- continue;
25
- }
26
-
27
- let key = line.slice(0, equalsIndex).trim();
28
- if (!key) {
29
- continue;
30
- }
31
-
32
- if (key.startsWith('export ')) {
33
- key = key.slice('export '.length).trim();
34
- }
35
-
36
- let value = line.slice(equalsIndex + 1).trim();
37
-
38
- const quotedWithOptionalCommentMatch = value.match(/^(["'])(.*?)\1(?:\s+#.*)?$/);
39
-
40
- if (quotedWithOptionalCommentMatch) {
41
- value = quotedWithOptionalCommentMatch[2];
42
- } else {
43
- value = value.replace(/\s+#.*$/, '').trimEnd();
44
- }
45
-
46
- parsed[key] = value;
47
- }
48
-
49
- return parsed;
50
- }
51
-
52
- function warnSuspiciousKey(key, logger, warnedKeys) {
53
- const upperKey = key.toUpperCase();
54
- const isSuspicious = SUSPICIOUS_TERMS.some((term) => upperKey.includes(term));
55
-
56
- if (isSuspicious && !warnedKeys.has(key) && logger && typeof logger.warn === 'function') {
57
- logger.warn(`[slice-env] Suspicious public environment key detected: ${key}`);
58
- warnedKeys.add(key);
59
- }
60
- }
61
-
62
- function buildPublicPayload({ envFromFile, processEnv, logger }) {
63
- const env = {};
64
- const warnedKeys = new Set();
65
-
66
- for (const [key, value] of Object.entries(envFromFile)) {
67
- if (key.startsWith(PUBLIC_PREFIX)) {
68
- env[key] = String(value ?? '');
69
- warnSuspiciousKey(key, logger, warnedKeys);
70
- }
71
- }
72
-
73
- for (const [key, value] of Object.entries(processEnv || {})) {
74
- if (key.startsWith(PUBLIC_PREFIX)) {
75
- env[key] = String(value ?? '');
76
- warnSuspiciousKey(key, logger, warnedKeys);
77
- }
78
- }
79
-
80
- return env;
81
- }
82
-
83
- export function resolvePublicEnv({ mode, envFilePath, processEnv = process.env, logger = console }) {
84
- const envFromFile = parseEnvFile(envFilePath);
85
- const env = buildPublicPayload({
86
- envFromFile,
87
- processEnv,
88
- logger,
89
- });
90
-
91
- return {
92
- mode,
93
- env,
94
- };
95
- }
96
-
97
- export function createPublicEnvProvider({ mode, envFilePath, processEnv = process.env, logger = console }) {
98
- if (mode === 'production') {
99
- let cachedPayload;
100
-
101
- return {
102
- getPayload() {
103
- if (!cachedPayload) {
104
- cachedPayload = resolvePublicEnv({ mode, envFilePath, processEnv, logger });
105
- }
106
-
107
- return cachedPayload;
108
- },
109
- };
110
- }
111
-
112
- return {
113
- getPayload() {
114
- return resolvePublicEnv({ mode, envFilePath, processEnv, logger });
115
- },
116
- };
117
- }
1
+ import { readFileSync, existsSync } from 'node:fs';
2
+
3
+ const PUBLIC_PREFIX = 'SLICE_PUBLIC_';
4
+ const SUSPICIOUS_TERMS = ['SECRET', 'TOKEN', 'PASSWORD', 'PRIVATE', 'API_KEY', 'ACCESS_KEY', 'CREDENTIAL'];
5
+
6
+ function parseEnvFile(envFilePath) {
7
+ if (!envFilePath || !existsSync(envFilePath)) {
8
+ return {};
9
+ }
10
+
11
+ let fileContent;
12
+ try {
13
+ fileContent = readFileSync(envFilePath, 'utf8').replace(/^\uFEFF/, '');
14
+ } catch (error) {
15
+ console.error(`Error reading env file ${envFilePath}:`, error);
16
+ return {};
17
+ }
18
+ const parsed = {};
19
+ const lines = fileContent.split(/\r?\n/);
20
+
21
+ for (const rawLine of lines) {
22
+ const line = rawLine.trim();
23
+
24
+ if (!line || line.startsWith('#')) {
25
+ continue;
26
+ }
27
+
28
+ const equalsIndex = line.indexOf('=');
29
+ if (equalsIndex === -1) {
30
+ continue;
31
+ }
32
+
33
+ let key = line.slice(0, equalsIndex).trim();
34
+ if (!key) {
35
+ continue;
36
+ }
37
+
38
+ if (key.startsWith('export ')) {
39
+ key = key.slice('export '.length).trim();
40
+ }
41
+
42
+ let value = line.slice(equalsIndex + 1).trim();
43
+
44
+ const quotedWithOptionalCommentMatch = value.match(/^(["'])(.*?)\1(?:\s+#.*)?$/);
45
+
46
+ if (quotedWithOptionalCommentMatch) {
47
+ value = quotedWithOptionalCommentMatch[2];
48
+ } else {
49
+ value = value.replace(/\s+#.*$/, '').trimEnd();
50
+ }
51
+
52
+ parsed[key] = value;
53
+ }
54
+
55
+ return parsed;
56
+ }
57
+
58
+ function warnSuspiciousKey(key, logger, warnedKeys) {
59
+ const upperKey = key.toUpperCase();
60
+ const isSuspicious = SUSPICIOUS_TERMS.some((term) => upperKey.includes(term));
61
+
62
+ if (isSuspicious && !warnedKeys.has(key) && logger && typeof logger.warn === 'function') {
63
+ logger.warn(`[slice-env] Suspicious public environment key detected: ${key}`);
64
+ warnedKeys.add(key);
65
+ }
66
+ }
67
+
68
+ function buildPublicPayload({ envFromFile, processEnv, logger }) {
69
+ const env = {};
70
+ const warnedKeys = new Set();
71
+
72
+ for (const [key, value] of Object.entries(envFromFile)) {
73
+ if (key.startsWith(PUBLIC_PREFIX)) {
74
+ env[key] = String(value ?? '');
75
+ warnSuspiciousKey(key, logger, warnedKeys);
76
+ }
77
+ }
78
+
79
+ for (const [key, value] of Object.entries(processEnv || {})) {
80
+ if (key.startsWith(PUBLIC_PREFIX)) {
81
+ env[key] = String(value ?? '');
82
+ warnSuspiciousKey(key, logger, warnedKeys);
83
+ }
84
+ }
85
+
86
+ return env;
87
+ }
88
+
89
+ export function resolvePublicEnv({ mode, envFilePath, processEnv = process.env, logger = console }) {
90
+ const envFromFile = parseEnvFile(envFilePath);
91
+ const env = buildPublicPayload({
92
+ envFromFile,
93
+ processEnv,
94
+ logger,
95
+ });
96
+
97
+ return {
98
+ mode,
99
+ env,
100
+ };
101
+ }
102
+
103
+ export function createPublicEnvProvider({ mode, envFilePath, processEnv = process.env, logger = console }) {
104
+ if (mode === 'production') {
105
+ let cachedPayload;
106
+
107
+ return {
108
+ getPayload() {
109
+ if (!cachedPayload) {
110
+ cachedPayload = resolvePublicEnv({ mode, envFilePath, processEnv, logger });
111
+ }
112
+
113
+ return cachedPayload;
114
+ },
115
+ };
116
+ }
117
+
118
+ return {
119
+ getPayload() {
120
+ return resolvePublicEnv({ mode, envFilePath, processEnv, logger });
121
+ },
122
+ };
123
+ }
package/package.json CHANGED
@@ -1,44 +1,44 @@
1
- {
2
- "name": "slicejs-web-framework",
3
- "version": "3.3.7",
4
- "description": "",
5
- "engines": {
6
- "node": ">=20"
7
- },
8
- "scripts": {
9
- "dev": "node ./node_modules/slicejs-cli/client.js dev",
10
- "build": "node ./node_modules/slicejs-cli/client.js build",
11
- "start": "node ./node_modules/slicejs-cli/client.js start",
12
- "test": "echo \"Error: no test specified\" && exit 1",
13
- "slice:init": "node ./node_modules/slicejs-cli/client.js init",
14
- "slice:create": "node ./node_modules/slicejs-cli/client.js component create",
15
- "slice:delete": "node ./node_modules/slicejs-cli/client.js component delete",
16
- "slice:list": "node ./node_modules/slicejs-cli/client.js component list",
17
- "slice:start": "node ./node_modules/slicejs-cli/client.js start",
18
- "format": "prettier --write \"**/*.js\"",
19
- "run": "node ./node_modules/slicejs-cli/client.js dev",
20
- "slice:modify": "node ./node_modules/slicejs-cli/client.js modify"
21
- },
22
- "keywords": [],
23
- "author": "",
24
- "license": "ISC",
25
- "type": "module",
26
- "exports": {
27
- ".": "./Slice/Slice.js",
28
- "./api/framework/express.js": "./api/framework/express.js"
29
- },
30
- "types": "./types/index.d.ts",
31
- "dependencies": {
32
- "express": "^4.19.2"
33
- },
34
- "devDependencies": {
35
- "prettier": "3.3.3"
36
- },
37
- "prettier": {
38
- "trailingComma": "es5",
39
- "tabWidth": 3,
40
- "semi": true,
41
- "singleQuote": true,
42
- "printWidth": 120
43
- }
44
- }
1
+ {
2
+ "name": "slicejs-web-framework",
3
+ "version": "3.3.8",
4
+ "description": "",
5
+ "engines": {
6
+ "node": ">=20"
7
+ },
8
+ "scripts": {
9
+ "dev": "node ./node_modules/slicejs-cli/client.js dev",
10
+ "build": "node ./node_modules/slicejs-cli/client.js build",
11
+ "start": "node ./node_modules/slicejs-cli/client.js start",
12
+ "test": "echo \"Error: no test specified\" && exit 1",
13
+ "slice:init": "node ./node_modules/slicejs-cli/client.js init",
14
+ "slice:create": "node ./node_modules/slicejs-cli/client.js component create",
15
+ "slice:delete": "node ./node_modules/slicejs-cli/client.js component delete",
16
+ "slice:list": "node ./node_modules/slicejs-cli/client.js component list",
17
+ "slice:start": "node ./node_modules/slicejs-cli/client.js start",
18
+ "format": "prettier --write \"**/*.js\"",
19
+ "run": "node ./node_modules/slicejs-cli/client.js dev",
20
+ "slice:modify": "node ./node_modules/slicejs-cli/client.js modify"
21
+ },
22
+ "keywords": [],
23
+ "author": "",
24
+ "license": "ISC",
25
+ "type": "module",
26
+ "exports": {
27
+ ".": "./Slice/Slice.js",
28
+ "./api/framework/express.js": "./api/framework/express.js"
29
+ },
30
+ "types": "./types/index.d.ts",
31
+ "dependencies": {
32
+ "express": "^4.19.2"
33
+ },
34
+ "devDependencies": {
35
+ "prettier": "3.3.3"
36
+ },
37
+ "prettier": {
38
+ "trailingComma": "es5",
39
+ "tabWidth": 3,
40
+ "semi": true,
41
+ "singleQuote": true,
42
+ "printWidth": 120
43
+ }
44
+ }