@fentz26/envcp 1.0.0

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 (95) hide show
  1. package/.github/workflows/publish.yml +27 -0
  2. package/LICENSE +21 -0
  3. package/README.md +381 -0
  4. package/dist/adapters/base.d.ts +79 -0
  5. package/dist/adapters/base.d.ts.map +1 -0
  6. package/dist/adapters/base.js +317 -0
  7. package/dist/adapters/base.js.map +1 -0
  8. package/dist/adapters/gemini.d.ts +12 -0
  9. package/dist/adapters/gemini.d.ts.map +1 -0
  10. package/dist/adapters/gemini.js +284 -0
  11. package/dist/adapters/gemini.js.map +1 -0
  12. package/dist/adapters/index.d.ts +5 -0
  13. package/dist/adapters/index.d.ts.map +1 -0
  14. package/dist/adapters/index.js +5 -0
  15. package/dist/adapters/index.js.map +1 -0
  16. package/dist/adapters/openai.d.ts +12 -0
  17. package/dist/adapters/openai.d.ts.map +1 -0
  18. package/dist/adapters/openai.js +294 -0
  19. package/dist/adapters/openai.js.map +1 -0
  20. package/dist/adapters/rest.d.ts +12 -0
  21. package/dist/adapters/rest.d.ts.map +1 -0
  22. package/dist/adapters/rest.js +265 -0
  23. package/dist/adapters/rest.js.map +1 -0
  24. package/dist/cli/index.d.ts +2 -0
  25. package/dist/cli/index.d.ts.map +1 -0
  26. package/dist/cli/index.js +472 -0
  27. package/dist/cli/index.js.map +1 -0
  28. package/dist/cli.d.ts +3 -0
  29. package/dist/cli.d.ts.map +1 -0
  30. package/dist/cli.js +3 -0
  31. package/dist/cli.js.map +1 -0
  32. package/dist/config/manager.d.ts +11 -0
  33. package/dist/config/manager.d.ts.map +1 -0
  34. package/dist/config/manager.js +117 -0
  35. package/dist/config/manager.js.map +1 -0
  36. package/dist/index.d.ts +5 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +5 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/mcp/index.d.ts +2 -0
  41. package/dist/mcp/index.d.ts.map +1 -0
  42. package/dist/mcp/index.js +2 -0
  43. package/dist/mcp/index.js.map +1 -0
  44. package/dist/mcp/server.d.ts +24 -0
  45. package/dist/mcp/server.d.ts.map +1 -0
  46. package/dist/mcp/server.js +539 -0
  47. package/dist/mcp/server.js.map +1 -0
  48. package/dist/server/index.d.ts +2 -0
  49. package/dist/server/index.d.ts.map +1 -0
  50. package/dist/server/index.js +2 -0
  51. package/dist/server/index.js.map +1 -0
  52. package/dist/server/unified.d.ts +21 -0
  53. package/dist/server/unified.d.ts.map +1 -0
  54. package/dist/server/unified.js +397 -0
  55. package/dist/server/unified.js.map +1 -0
  56. package/dist/storage/index.d.ts +23 -0
  57. package/dist/storage/index.d.ts.map +1 -0
  58. package/dist/storage/index.js +92 -0
  59. package/dist/storage/index.js.map +1 -0
  60. package/dist/types.d.ts +404 -0
  61. package/dist/types.d.ts.map +1 -0
  62. package/dist/types.js +92 -0
  63. package/dist/types.js.map +1 -0
  64. package/dist/utils/crypto.d.ts +17 -0
  65. package/dist/utils/crypto.d.ts.map +1 -0
  66. package/dist/utils/crypto.js +73 -0
  67. package/dist/utils/crypto.js.map +1 -0
  68. package/dist/utils/http.d.ts +6 -0
  69. package/dist/utils/http.d.ts.map +1 -0
  70. package/dist/utils/http.js +43 -0
  71. package/dist/utils/http.js.map +1 -0
  72. package/dist/utils/session.d.ts +19 -0
  73. package/dist/utils/session.d.ts.map +1 -0
  74. package/dist/utils/session.js +112 -0
  75. package/dist/utils/session.js.map +1 -0
  76. package/package.json +50 -0
  77. package/src/adapters/base.ts +411 -0
  78. package/src/adapters/gemini.ts +314 -0
  79. package/src/adapters/index.ts +4 -0
  80. package/src/adapters/openai.ts +324 -0
  81. package/src/adapters/rest.ts +294 -0
  82. package/src/cli/index.ts +640 -0
  83. package/src/cli.ts +2 -0
  84. package/src/config/manager.ts +134 -0
  85. package/src/index.ts +4 -0
  86. package/src/mcp/index.ts +1 -0
  87. package/src/mcp/server.ts +623 -0
  88. package/src/server/index.ts +1 -0
  89. package/src/server/unified.ts +460 -0
  90. package/src/storage/index.ts +112 -0
  91. package/src/types.ts +181 -0
  92. package/src/utils/crypto.ts +100 -0
  93. package/src/utils/http.ts +45 -0
  94. package/src/utils/session.ts +141 -0
  95. package/tsconfig.json +20 -0
@@ -0,0 +1,134 @@
1
+ import * as fs from 'fs-extra';
2
+ import * as path from 'path';
3
+ import * as yaml from 'js-yaml';
4
+ import { EnvCPConfig, EnvCPConfigSchema } from '../types.js';
5
+
6
+ const DEFAULT_CONFIG: Partial<EnvCPConfig> = {
7
+ version: '1.0',
8
+ storage: {
9
+ path: '.envcp/store.enc',
10
+ encrypted: true,
11
+ algorithm: 'aes-256-gcm',
12
+ compression: false,
13
+ },
14
+ access: {
15
+ allow_ai_read: false,
16
+ allow_ai_write: false,
17
+ allow_ai_delete: false,
18
+ allow_ai_export: false,
19
+ allow_ai_active_check: false,
20
+ require_user_reference: true,
21
+ require_confirmation: true,
22
+ mask_values: true,
23
+ audit_log: true,
24
+ blacklist_patterns: ['*_SECRET', '*_PRIVATE', 'ADMIN_*', 'ROOT_*'],
25
+ },
26
+ sync: {
27
+ enabled: false,
28
+ target: '.env',
29
+ exclude: [],
30
+ format: 'dotenv',
31
+ },
32
+ session: {
33
+ enabled: true,
34
+ timeout_minutes: 30,
35
+ max_extensions: 5,
36
+ path: '.envcp/.session',
37
+ },
38
+ password: {
39
+ min_length: 1,
40
+ require_complexity: false,
41
+ allow_numeric_only: true,
42
+ allow_single_char: true,
43
+ },
44
+ };
45
+
46
+ export async function loadConfig(projectPath: string): Promise<EnvCPConfig> {
47
+ const configPath = path.join(projectPath, 'envcp.yaml');
48
+
49
+ if (await fs.pathExists(configPath)) {
50
+ const content = await fs.readFile(configPath, 'utf8');
51
+ const parsed = yaml.load(content);
52
+ const config = EnvCPConfigSchema.parse(parsed);
53
+ return config;
54
+ }
55
+
56
+ return EnvCPConfigSchema.parse(DEFAULT_CONFIG);
57
+ }
58
+
59
+ export async function saveConfig(config: EnvCPConfig, projectPath: string): Promise<void> {
60
+ const configPath = path.join(projectPath, 'envcp.yaml');
61
+ const content = yaml.dump(config, { indent: 2, lineWidth: -1 });
62
+ await fs.writeFile(configPath, content, 'utf8');
63
+ }
64
+
65
+ export async function initConfig(projectPath: string, projectName?: string): Promise<EnvCPConfig> {
66
+ const envcpDir = path.join(projectPath, '.envcp');
67
+ await fs.ensureDir(envcpDir);
68
+ await fs.ensureDir(path.join(envcpDir, 'logs'));
69
+
70
+ const config: EnvCPConfig = {
71
+ ...DEFAULT_CONFIG,
72
+ project: projectName || path.basename(projectPath),
73
+ } as EnvCPConfig;
74
+
75
+ await saveConfig(config, projectPath);
76
+
77
+ const gitignorePath = path.join(projectPath, '.gitignore');
78
+ if (await fs.pathExists(gitignorePath)) {
79
+ const gitignore = await fs.readFile(gitignorePath, 'utf8');
80
+ if (!gitignore.includes('.envcp/')) {
81
+ await fs.appendFile(gitignorePath, '\n# EnvCP\n.envcp/\nstore.enc\n');
82
+ }
83
+ } else {
84
+ await fs.writeFile(gitignorePath, '# EnvCP\n.envcp/\nstore.enc\n');
85
+ }
86
+
87
+ return config;
88
+ }
89
+
90
+ export function validateVariableName(name: string): boolean {
91
+ return /^[A-Za-z_][A-Za-z0-9_]*$/.test(name);
92
+ }
93
+
94
+ export function matchesPattern(name: string, pattern: string): boolean {
95
+ const regex = new RegExp('^' + pattern.replace(/\*/g, '.*') + '$');
96
+ return regex.test(name);
97
+ }
98
+
99
+ export function canAccess(name: string, config: EnvCPConfig): boolean {
100
+ if (config.access.blacklist_patterns && config.access.blacklist_patterns.length > 0) {
101
+ if (config.access.blacklist_patterns.some((p: string) => matchesPattern(name, p))) {
102
+ return false;
103
+ }
104
+ }
105
+
106
+ if (config.access.denied_patterns && config.access.denied_patterns.length > 0) {
107
+ if (config.access.denied_patterns.some((p: string) => matchesPattern(name, p))) {
108
+ return false;
109
+ }
110
+ }
111
+
112
+ if (config.access.allowed_patterns && config.access.allowed_patterns.length > 0) {
113
+ if (!config.access.allowed_patterns.some((p: string) => matchesPattern(name, p))) {
114
+ return false;
115
+ }
116
+ }
117
+
118
+ return true;
119
+ }
120
+
121
+ export function isBlacklisted(name: string, config: EnvCPConfig): boolean {
122
+ if (config.access.blacklist_patterns && config.access.blacklist_patterns.length > 0) {
123
+ return config.access.blacklist_patterns.some((p: string) => matchesPattern(name, p));
124
+ }
125
+ return false;
126
+ }
127
+
128
+ export function canAIActiveCheck(config: EnvCPConfig): boolean {
129
+ return config.access.allow_ai_active_check === true;
130
+ }
131
+
132
+ export function requiresUserReference(config: EnvCPConfig): boolean {
133
+ return config.access.require_user_reference === true;
134
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { EnvCPServer } from './mcp/server.js';
2
+ export { StorageManager, LogManager } from './storage/index.js';
3
+ export * from './types.js';
4
+ export * from './config/manager.js';
@@ -0,0 +1 @@
1
+ export { EnvCPServer } from './server.js';