openkbs 0.0.63 → 0.0.64

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openkbs",
3
- "version": "0.0.63",
3
+ "version": "0.0.64",
4
4
  "description": "OpenKBS - Command Line Interface",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/actions.js CHANGED
@@ -2219,6 +2219,233 @@ async function elasticDeployAction() {
2219
2219
  console.green('\nDeploy complete!');
2220
2220
  }
2221
2221
 
2222
+ /**
2223
+ * Destroy all resources defined in openkbs.json
2224
+ */
2225
+ async function elasticDestroyAction() {
2226
+ // Find openkbs.json
2227
+ const configPaths = [
2228
+ path.join(process.cwd(), 'openkbs.json'),
2229
+ path.join(process.cwd(), '..', 'openkbs.json')
2230
+ ];
2231
+
2232
+ let configPath = null;
2233
+ for (const p of configPaths) {
2234
+ if (fs.existsSync(p)) {
2235
+ configPath = p;
2236
+ break;
2237
+ }
2238
+ }
2239
+
2240
+ if (!configPath) {
2241
+ return console.red('openkbs.json not found.');
2242
+ }
2243
+
2244
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
2245
+
2246
+ console.log(`Destroying ${config.name || 'project'} resources...`);
2247
+ console.yellow('Warning: This will permanently delete all resources!\n');
2248
+
2249
+ // Get KB token
2250
+ const settings = findSettings();
2251
+ if (!settings?.kbId) {
2252
+ return console.red('No kbId found. Run from a directory with settings.json');
2253
+ }
2254
+
2255
+ const res = await fetchKBJWT(settings.kbId);
2256
+ if (!res?.kbToken) {
2257
+ return console.red(`KB ${settings.kbId} not found`);
2258
+ }
2259
+ const kbToken = res.kbToken;
2260
+
2261
+ // Delete functions
2262
+ if (config.functions && config.functions.length > 0) {
2263
+ console.log('Deleting functions...');
2264
+ for (const fnName of config.functions) {
2265
+ const name = typeof fnName === 'object' ? fnName.name : fnName;
2266
+ try {
2267
+ await fnDeleteAction(kbToken, name);
2268
+ console.green(` ✓ Deleted ${name}`);
2269
+ } catch (e) {
2270
+ console.yellow(` ⚠ ${name}: ${e.message}`);
2271
+ }
2272
+ }
2273
+ }
2274
+
2275
+ // Disable elastic services
2276
+ if (config.elastic) {
2277
+ console.log('\nDisabling Elastic services...');
2278
+
2279
+ if (config.elastic.storage) {
2280
+ try {
2281
+ await makePostRequest(KB_API_URL, {
2282
+ token: kbToken,
2283
+ action: 'deleteElasticStorage',
2284
+ force: true
2285
+ });
2286
+ console.green(' ✓ Storage disabled');
2287
+ } catch (e) {
2288
+ console.yellow(` ⚠ Storage: ${e.message}`);
2289
+ }
2290
+ }
2291
+
2292
+ if (config.elastic.postgres) {
2293
+ try {
2294
+ await makePostRequest(KB_API_URL, {
2295
+ token: kbToken,
2296
+ action: 'deleteElasticPostgres'
2297
+ });
2298
+ console.green(' ✓ Postgres disabled');
2299
+ } catch (e) {
2300
+ console.yellow(` ⚠ Postgres: ${e.message}`);
2301
+ }
2302
+ }
2303
+
2304
+ if (config.elastic.pulse) {
2305
+ try {
2306
+ await makePostRequest(KB_API_URL, {
2307
+ token: kbToken,
2308
+ action: 'disableElasticPulse'
2309
+ });
2310
+ console.green(' ✓ Pulse disabled');
2311
+ } catch (e) {
2312
+ console.yellow(` ⚠ Pulse: ${e.message}`);
2313
+ }
2314
+ }
2315
+ }
2316
+
2317
+ console.green('\nDestroy complete!');
2318
+ }
2319
+
2320
+ /**
2321
+ * Show status of all resources defined in openkbs.json
2322
+ */
2323
+ async function elasticStatusAction() {
2324
+ // Find openkbs.json
2325
+ const configPaths = [
2326
+ path.join(process.cwd(), 'openkbs.json'),
2327
+ path.join(process.cwd(), '..', 'openkbs.json')
2328
+ ];
2329
+
2330
+ let configPath = null;
2331
+ for (const p of configPaths) {
2332
+ if (fs.existsSync(p)) {
2333
+ configPath = p;
2334
+ break;
2335
+ }
2336
+ }
2337
+
2338
+ if (!configPath) {
2339
+ return console.red('openkbs.json not found.');
2340
+ }
2341
+
2342
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
2343
+
2344
+ console.log(`Stack: ${config.name || 'unnamed'}`);
2345
+ console.log(`Region: ${config.region || 'us-east-1'}\n`);
2346
+
2347
+ // Get KB token
2348
+ const settings = findSettings();
2349
+ if (!settings?.kbId) {
2350
+ return console.red('No kbId found. Run from a directory with settings.json');
2351
+ }
2352
+
2353
+ const res = await fetchKBJWT(settings.kbId);
2354
+ if (!res?.kbToken) {
2355
+ return console.red(`KB ${settings.kbId} not found`);
2356
+ }
2357
+ const kbToken = res.kbToken;
2358
+
2359
+ // Check functions
2360
+ if (config.functions && config.functions.length > 0) {
2361
+ console.log('Functions:');
2362
+ const listRes = await makePostRequest(KB_API_URL, {
2363
+ token: kbToken,
2364
+ action: 'listElasticFunctions'
2365
+ });
2366
+ const deployed = listRes.functions?.map(f => f.functionName) || [];
2367
+
2368
+ for (const fnName of config.functions) {
2369
+ const name = typeof fnName === 'object' ? fnName.name : fnName;
2370
+ if (deployed.includes(name)) {
2371
+ const fn = listRes.functions.find(f => f.functionName === name);
2372
+ console.green(` ✓ ${name} (${fn.customUrl || fn.functionUrl})`);
2373
+ } else {
2374
+ console.yellow(` ○ ${name} (not deployed)`);
2375
+ }
2376
+ }
2377
+ console.log('');
2378
+ }
2379
+
2380
+ // Check elastic services
2381
+ if (config.elastic) {
2382
+ console.log('Elastic Services:');
2383
+
2384
+ if (config.elastic.storage) {
2385
+ const storageRes = await makePostRequest(KB_API_URL, {
2386
+ token: kbToken,
2387
+ action: 'getElasticStorage'
2388
+ });
2389
+ if (storageRes.enabled) {
2390
+ console.green(` ✓ Storage (${storageRes.bucket})`);
2391
+ } else {
2392
+ console.yellow(' ○ Storage (not enabled)');
2393
+ }
2394
+ }
2395
+
2396
+ if (config.elastic.postgres) {
2397
+ const pgRes = await makePostRequest(KB_API_URL, {
2398
+ token: kbToken,
2399
+ action: 'getElasticPostgres'
2400
+ });
2401
+ if (pgRes.enabled) {
2402
+ console.green(` ✓ Postgres (${pgRes.host})`);
2403
+ } else {
2404
+ console.yellow(' ○ Postgres (not enabled)');
2405
+ }
2406
+ }
2407
+
2408
+ if (config.elastic.pulse) {
2409
+ const pulseRes = await makePostRequest(KB_API_URL, {
2410
+ token: kbToken,
2411
+ action: 'getElasticPulse'
2412
+ });
2413
+ if (pulseRes.enabled) {
2414
+ console.green(` ✓ Pulse (${pulseRes.endpoint})`);
2415
+ } else {
2416
+ console.yellow(' ○ Pulse (not enabled)');
2417
+ }
2418
+ }
2419
+ }
2420
+
2421
+ // Site info
2422
+ if (config.site) {
2423
+ console.log('');
2424
+ console.log(`Site: https://files.openkbs.com/${settings.kbId}/`);
2425
+ }
2426
+ }
2427
+
2428
+ /**
2429
+ * Stack command handler
2430
+ */
2431
+ async function stackAction(subCommand, args = []) {
2432
+ switch (subCommand) {
2433
+ case 'deploy':
2434
+ return await elasticDeployAction();
2435
+ case 'destroy':
2436
+ return await elasticDestroyAction();
2437
+ case 'status':
2438
+ return await elasticStatusAction();
2439
+ default:
2440
+ console.log('Usage: openkbs stack <command>');
2441
+ console.log('');
2442
+ console.log('Commands:');
2443
+ console.log(' deploy Deploy all resources from openkbs.json');
2444
+ console.log(' destroy Delete all resources (DANGEROUS)');
2445
+ console.log(' status Show status of all resources');
2446
+ }
2447
+ }
2448
+
2222
2449
  module.exports = {
2223
2450
  signAction,
2224
2451
  loginAction,
@@ -2245,5 +2472,6 @@ module.exports = {
2245
2472
  storageAction,
2246
2473
  postgresAction,
2247
2474
  pulseAction,
2475
+ stackAction,
2248
2476
  elasticDeployAction
2249
2477
  };
package/src/index.js CHANGED
@@ -19,6 +19,7 @@ const {
19
19
  storageAction,
20
20
  postgresAction,
21
21
  pulseAction,
22
+ stackAction,
22
23
  elasticDeployAction
23
24
  } = require('./actions');
24
25
 
@@ -127,6 +128,22 @@ Reads openkbs.json and deploys:
127
128
  - Site
128
129
  `);
129
130
 
131
+ program
132
+ .command('stack <subcommand>')
133
+ .description('Manage stack resources (deploy, destroy, status)')
134
+ .action((subCommand) => stackAction(subCommand))
135
+ .addHelpText('after', `
136
+ Commands:
137
+ deploy Deploy all resources from openkbs.json
138
+ destroy Delete all resources (DANGEROUS)
139
+ status Show status of all resources
140
+
141
+ Examples:
142
+ $ openkbs stack deploy
143
+ $ openkbs stack status
144
+ $ openkbs stack destroy
145
+ `);
146
+
130
147
  // program
131
148
  // .command('sign')
132
149
  // .description('Signs a transaction to request OpenKBS service')
package/version.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.61",
3
- "releaseDate": "2025-12-30",
4
- "releaseNotes": "OpenKBS CLI version 0.0.61"
2
+ "version": "0.0.64",
3
+ "releaseDate": "2025-12-31",
4
+ "releaseNotes": "OpenKBS CLI version 0.0.64"
5
5
  }