skystream-cli 1.3.6 → 1.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.
Files changed (2) hide show
  1. package/dist/index.js +69 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from 'commander';
3
3
  import * as path from 'path';
4
+ import * as vm from 'vm';
5
+ import * as crypto from 'crypto';
4
6
  import fs from 'fs-extra';
5
7
  import { z } from 'zod';
6
8
  import archiver from 'archiver';
@@ -9,7 +11,7 @@ const program = new Command();
9
11
  program
10
12
  .name('skystream')
11
13
  .description('SkyStream Plugin Development Kit CLI (Sky Gen 2)')
12
- .version('1.3.6');
14
+ .version('1.3.8');
13
15
  // Schemas
14
16
  const pluginSchema = z.object({
15
17
  packageName: z.string().min(5).regex(/^[a-z0-9._-]+$/),
@@ -424,6 +426,15 @@ program.command('test')
424
426
  const pluginDir = path.resolve(options.path);
425
427
  const manifestPath = path.join(pluginDir, 'plugin.json');
426
428
  const jsPath = path.join(pluginDir, 'plugin.js');
429
+ if (!await fs.pathExists(manifestPath)) {
430
+ console.error(`Error: plugin.json not found at ${manifestPath}`);
431
+ console.log('Hint: Run this command from your plugin directory or specify --path');
432
+ process.exit(1);
433
+ }
434
+ if (!await fs.pathExists(jsPath)) {
435
+ console.error(`Error: plugin.js not found at ${jsPath}`);
436
+ process.exit(1);
437
+ }
427
438
  const manifest = await fs.readJson(manifestPath);
428
439
  const jsContent = await fs.readFile(jsPath, 'utf8');
429
440
  console.log(`\n--- Testing ${manifest.packageName} -> ${options.function} ---`);
@@ -483,6 +494,41 @@ program.command('test')
483
494
  },
484
495
  btoa: (s) => Buffer.from(s).toString('base64'),
485
496
  atob: (s) => Buffer.from(s, 'base64').toString('utf8'),
497
+ sendMessage: async (id, arg) => {
498
+ if (id === 'crypto_decrypt_aes') {
499
+ const { data, key, iv } = JSON.parse(arg);
500
+ try {
501
+ // Standardize key and iv to correct lengths
502
+ // They are often passed as base64 strings
503
+ const decodeBuffer = (s) => {
504
+ return s.length % 4 === 0 && /^[A-Za-z0-9+/=]+$/.test(s) ? Buffer.from(s, 'base64') : Buffer.from(s, 'utf8');
505
+ };
506
+ const k = decodeBuffer(key);
507
+ const ivBuf = Buffer.alloc(16, 0);
508
+ decodeBuffer(iv).copy(ivBuf);
509
+ let algo = 'aes-256-cbc';
510
+ let finalKey = Buffer.alloc(32, 0);
511
+ if (k.length <= 16) {
512
+ algo = 'aes-128-cbc';
513
+ finalKey = Buffer.alloc(16, 0);
514
+ }
515
+ else if (k.length <= 24) {
516
+ algo = 'aes-192-cbc';
517
+ finalKey = Buffer.alloc(24, 0);
518
+ }
519
+ k.copy(finalKey);
520
+ const decipher = crypto.createDecipheriv(algo, finalKey, ivBuf);
521
+ let decrypted = decipher.update(data, 'base64', 'utf8');
522
+ decrypted += decipher.final('utf8');
523
+ return decrypted;
524
+ }
525
+ catch (e) {
526
+ console.error(' [Mock ERR]: AES Decryption failed:', e.message);
527
+ return data;
528
+ }
529
+ }
530
+ return '';
531
+ },
486
532
  globalThis: {},
487
533
  };
488
534
  const entityDefs = `
@@ -524,22 +570,35 @@ program.command('test')
524
570
  }
525
571
  }
526
572
 
527
- globalThis.MultimediaItem = MultimediaItem;
528
- globalThis.Episode = Episode;
529
- globalThis.StreamResult = StreamResult;
573
+ globalThis.clearInterval = clearInterval;
530
574
  `;
531
- // Wrap the plugin code and classes in a combined block to ensure scope visibility
575
+ const sandbox = Object.create(null);
576
+ sandbox.console = console;
577
+ sandbox.axios = axios;
578
+ sandbox.Buffer = Buffer;
579
+ sandbox.manifest = manifest;
580
+ sandbox.setTimeout = setTimeout;
581
+ sandbox.clearTimeout = clearTimeout;
582
+ sandbox.setInterval = setInterval;
583
+ sandbox.clearInterval = clearInterval;
584
+ sandbox.globalThis = sandbox;
585
+ // Inject the classes from entityDefs into the sandbox
586
+ const vmContext = vm.createContext(sandbox);
587
+ vm.runInContext(entityDefs, vmContext);
532
588
  const combinedScript = `
533
- ${entityDefs}
534
589
  try {
535
590
  ${jsContent}
536
- } catch (e) {
591
+ } catch (e: any) {
537
592
  console.error("Critical Runtime Error: " + e.stack);
538
593
  }
539
594
  `;
540
- const runtime = new Function('manifest', 'console', 'http_get', 'http_post', '_fetch', 'fetch', 'btoa', 'atob', 'globalThis', combinedScript);
541
- runtime(context.manifest, context.console, context.http_get, context.http_post, context._fetch, context.fetch, context.btoa, context.atob, context.globalThis);
542
- const fn = context.globalThis[options.function];
595
+ try {
596
+ vm.runInContext(combinedScript, vmContext, { timeout: 5000, breakOnSigint: true });
597
+ }
598
+ catch (e) {
599
+ console.error("VM Execution Error: " + e.message);
600
+ }
601
+ const fn = vmContext.globalThis[options.function];
543
602
  if (typeof fn !== 'function') {
544
603
  console.error('Error: exported function not found');
545
604
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skystream-cli",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "type": "module",
5
5
  "description": "SkyStream Plugin Development Kit & Repository Manager",
6
6
  "main": "dist/index.js",