openkbs 0.0.62 → 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.62",
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
@@ -2131,6 +2131,321 @@ async function pulsePublishAction(kbToken, channel, message) {
2131
2131
  }
2132
2132
  }
2133
2133
 
2134
+ /**
2135
+ * Deploy from openkbs.json config file
2136
+ * Enables elastic services and deploys functions/site
2137
+ */
2138
+ async function elasticDeployAction() {
2139
+ // Find openkbs.json
2140
+ const configPaths = [
2141
+ path.join(process.cwd(), 'openkbs.json'),
2142
+ path.join(process.cwd(), '..', 'openkbs.json')
2143
+ ];
2144
+
2145
+ let configPath = null;
2146
+ for (const p of configPaths) {
2147
+ if (fs.existsSync(p)) {
2148
+ configPath = p;
2149
+ break;
2150
+ }
2151
+ }
2152
+
2153
+ if (!configPath) {
2154
+ return console.red('openkbs.json not found. Create one with your deployment config.');
2155
+ }
2156
+
2157
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
2158
+ const projectDir = path.dirname(configPath);
2159
+ const region = config.region || findRegion() || 'us-east-1';
2160
+
2161
+ console.log(`Deploying ${config.name || 'project'} to ${region}...`);
2162
+
2163
+ // Get KB token
2164
+ const settings = findSettings();
2165
+ if (!settings?.kbId) {
2166
+ return console.red('No kbId found. Run from a directory with settings.json');
2167
+ }
2168
+
2169
+ const res = await fetchKBJWT(settings.kbId);
2170
+ if (!res?.kbToken) {
2171
+ return console.red(`KB ${settings.kbId} not found`);
2172
+ }
2173
+ const kbToken = res.kbToken;
2174
+
2175
+ // Deploy elastic services if configured
2176
+ if (config.elastic) {
2177
+ console.log('\nEnabling Elastic services...');
2178
+ const elasticRes = await makePostRequest(KB_API_URL, {
2179
+ token: kbToken,
2180
+ action: 'deployElastic',
2181
+ elastic: config.elastic
2182
+ });
2183
+
2184
+ if (elasticRes.error) {
2185
+ console.red('Elastic deploy error:', elasticRes.error);
2186
+ } else {
2187
+ if (elasticRes.pulse?.enabled) console.green(' ✓ Pulse enabled');
2188
+ if (elasticRes.postgres?.enabled) console.green(' ✓ Postgres enabled');
2189
+ if (elasticRes.storage?.enabled) console.green(' ✓ Storage enabled');
2190
+ if (elasticRes.storage?.cloudfront) console.green(' ✓ CloudFront configured');
2191
+ }
2192
+ }
2193
+
2194
+ // Deploy functions if configured
2195
+ if (config.functions && config.functions.length > 0) {
2196
+ console.log('\nDeploying functions...');
2197
+ for (const fnName of config.functions) {
2198
+ const fnConfig = typeof fnName === 'object' ? fnName : { name: fnName };
2199
+ const name = fnConfig.name || fnName;
2200
+
2201
+ const args = ['--region', region];
2202
+ if (fnConfig.memory) args.push('--memory', String(fnConfig.memory));
2203
+ if (fnConfig.timeout) args.push('--timeout', String(fnConfig.timeout));
2204
+ if (fnConfig.runtime) args.push('--runtime', fnConfig.runtime);
2205
+ if (fnConfig.handler) args.push('--handler', fnConfig.handler);
2206
+
2207
+ console.log(` Deploying ${name}...`);
2208
+ await fnDeployAction(kbToken, name, args);
2209
+ }
2210
+ }
2211
+
2212
+ // Deploy site if configured
2213
+ if (config.site) {
2214
+ console.log('\nDeploying site...');
2215
+ const sitePath = path.resolve(projectDir, config.site);
2216
+ await siteDeployAction(kbToken, settings.kbId, sitePath, []);
2217
+ }
2218
+
2219
+ console.green('\nDeploy complete!');
2220
+ }
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
+
2134
2449
  module.exports = {
2135
2450
  signAction,
2136
2451
  loginAction,
@@ -2156,5 +2471,7 @@ module.exports = {
2156
2471
  siteAction,
2157
2472
  storageAction,
2158
2473
  postgresAction,
2159
- pulseAction
2474
+ pulseAction,
2475
+ stackAction,
2476
+ elasticDeployAction
2160
2477
  };
package/src/index.js CHANGED
@@ -18,7 +18,9 @@ const {
18
18
  siteAction,
19
19
  storageAction,
20
20
  postgresAction,
21
- pulseAction
21
+ pulseAction,
22
+ stackAction,
23
+ elasticDeployAction
22
24
  } = require('./actions');
23
25
 
24
26
 
@@ -113,16 +115,33 @@ program
113
115
  .action(describeAction);
114
116
 
115
117
  program
116
- .command('deploy [moduleName]')
117
- .description('Builds and deploys a specified moduleName to "dist" module folder. If moduleName is not provided, deploys all modules.')
118
- .action(deployAction)
118
+ .command('deploy')
119
+ .description('Deploy from openkbs.json - enables elastic services, deploys functions and site')
120
+ .action(elasticDeployAction)
119
121
  .addHelpText('after', `
120
122
  Examples:
121
123
  $ openkbs deploy
122
- $ openkbs deploy onRequest
123
- $ openkbs deploy onResponse
124
- $ openkbs deploy onAddMessages
125
- $ openkbs deploy contentRender
124
+
125
+ Reads openkbs.json and deploys:
126
+ - Elastic services (pulse, postgres, storage)
127
+ - Functions
128
+ - Site
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
126
145
  `);
127
146
 
128
147
  // program
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
  }