@sekyuriti/cloak 0.1.0 → 0.1.2

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 (2) hide show
  1. package/bin/cloak.js +56 -0
  2. package/package.json +1 -1
package/bin/cloak.js CHANGED
@@ -113,6 +113,17 @@ function printHeader() {
113
113
  }
114
114
 
115
115
  function loadConfig() {
116
+ // CI/CD: Use env vars if available (bypasses machine-specific encryption)
117
+ // Note: tier is NOT set here - it's fetched from the server via /license endpoint
118
+ if (process.env.SEKYURITI_CLOAK_API_KEY) {
119
+ return {
120
+ apiKey: process.env.SEKYURITI_CLOAK_API_KEY,
121
+ projectId: process.env.SEKYURITI_CLOAK_PROJECT_ID,
122
+ email: "ci@sekyuriti.build",
123
+ };
124
+ }
125
+
126
+ // Otherwise read from config file
116
127
  try {
117
128
  if (fs.existsSync(CONFIG_FILE)) {
118
129
  const config = JSON.parse(fs.readFileSync(CONFIG_FILE, "utf8"));
@@ -151,6 +162,44 @@ function deleteConfig() {
151
162
  }
152
163
  }
153
164
 
165
+ function writeEnvFile(apiKey, projectId) {
166
+ // Write env vars to .env.local for CI/CD usage
167
+ const envPath = path.join(process.cwd(), ".env");
168
+ const envLocalPath = path.join(process.cwd(), ".env.local");
169
+ let targetEnvPath = envLocalPath;
170
+
171
+ // Prefer .env.local, fall back to .env if it exists
172
+ if (fs.existsSync(envLocalPath)) {
173
+ targetEnvPath = envLocalPath;
174
+ } else if (fs.existsSync(envPath)) {
175
+ targetEnvPath = envPath;
176
+ }
177
+
178
+ const envVars = `
179
+ # CLOAK Configuration (for CI/CD)
180
+ SEKYURITI_CLOAK_API_KEY=${apiKey}
181
+ SEKYURITI_CLOAK_PROJECT_ID=${projectId}
182
+ `.trim();
183
+
184
+ try {
185
+ if (fs.existsSync(targetEnvPath)) {
186
+ let content = fs.readFileSync(targetEnvPath, "utf-8");
187
+ if (!content.includes("SEKYURITI_CLOAK_API_KEY")) {
188
+ content += "\n\n" + envVars + "\n";
189
+ fs.writeFileSync(targetEnvPath, content);
190
+ success(`Added CLOAK config to ${path.basename(targetEnvPath)}`);
191
+ } else {
192
+ info(`CLOAK config already in ${path.basename(targetEnvPath)}`);
193
+ }
194
+ } else {
195
+ fs.writeFileSync(envLocalPath, envVars + "\n");
196
+ success("Created .env.local with CLOAK config");
197
+ }
198
+ } catch (err) {
199
+ info(`Could not write env file: ${err.message}`);
200
+ }
201
+ }
202
+
154
203
  function httpRequest(method, urlPath, body = null, apiKey = null, timeout = REQUEST_TIMEOUT) {
155
204
  return new Promise((resolve, reject) => {
156
205
  const url = new URL(urlPath.startsWith("http") ? urlPath : API_BASE + urlPath);
@@ -250,6 +299,9 @@ async function cmdLogin() {
250
299
 
251
300
  saveConfig(config);
252
301
 
302
+ // Also write to .env.local for CI/CD
303
+ writeEnvFile(config.apiKey, config.projectId);
304
+
253
305
  success(`Authenticated as ${config.email}`);
254
306
  info(` Project: ${config.projectName}`);
255
307
  info(` Tier: ${config.tier.toUpperCase()}`);
@@ -642,6 +694,10 @@ function cmdHelp() {
642
694
  log(" cloak protect app.js --domain-lock example.com,www.example.com");
643
695
  log(" cloak protect app.js --expiration 2025-12-31 --anti-debug");
644
696
  log("");
697
+ log(" CI/CD Environment Variables:");
698
+ log(" SEKYURITI_CLOAK_API_KEY API key (bypasses config file)");
699
+ log(" SEKYURITI_CLOAK_PROJECT_ID Project ID");
700
+ log("");
645
701
  }
646
702
 
647
703
  // ============================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sekyuriti/cloak",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "JavaScript obfuscation CLI - code never leaves your machine",
5
5
  "main": "src/index.js",
6
6
  "bin": {