skystream-cli 1.2.5 → 1.2.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 (3) hide show
  1. package/README.md +16 -1
  2. package/dist/index.js +68 -12
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -82,7 +82,22 @@ skystream test [options]
82
82
  **Options:**
83
83
  - `-p, --path <path>`: Path to plugin folder (Default: `.`).
84
84
  - `-f, --function <name>`: Function to test (Default: `getHome`).
85
- - `-q, --query <query>`: Query string for functions like `search`.
85
+ - `-q, --query <query>`: Query string (URLs for `load`/`loadStreams`, keywords for `search`).
86
+
87
+ **Examples:**
88
+ ```bash
89
+ # Test dashboard categories
90
+ skystream test -f getHome
91
+
92
+ # Test search with a keyword
93
+ skystream test -f search -q "avatar"
94
+
95
+ # Test full details for a movie/series
96
+ skystream test -f load -q "https://site.com/movie/123"
97
+
98
+ # Test stream links extraction
99
+ skystream test -f loadStreams -q "https://site.com/movie/123"
100
+ ```
86
101
 
87
102
  ---
88
103
 
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ const program = new Command();
9
9
  program
10
10
  .name('skystream')
11
11
  .description('SkyStream Plugin Development Kit CLI (Sky Gen 2)')
12
- .version('1.2.5');
12
+ .version('1.2.8');
13
13
  // Schemas
14
14
  const pluginSchema = z.object({
15
15
  packageName: z.string().min(5).regex(/^[a-z0-9._-]+$/),
@@ -103,7 +103,7 @@ const JS_TEMPLATE = `(function() {
103
103
  * @param {string} url
104
104
  * @param {(res: Response) => void} cb
105
105
  */
106
- function load(url, cb) {
106
+ async function load(url, cb) {
107
107
  try {
108
108
  // Standard: Return a single item with full metadata
109
109
  cb({
@@ -381,28 +381,63 @@ program.command('test')
381
381
  console.log(`\n--- Testing ${manifest.packageName} -> ${options.function} ---`);
382
382
  const context = {
383
383
  manifest,
384
- console: { log: (...args) => console.log(' [JS]:', ...args), error: (...args) => console.error(' [JS ERR]:', ...args) },
384
+ console: {
385
+ log: (...args) => console.log(' [JS]:', ...args),
386
+ error: (...args) => console.error(' [JS ERR]:', ...args)
387
+ },
385
388
  http_get: async (url, headers, cb) => {
386
389
  try {
387
- const res = await axios.get(url, { headers });
388
- const result = { status: res.status, body: res.data, headers: res.headers };
390
+ const res = await axios.get(url, { headers: headers || {} });
391
+ const result = { statusCode: res.status, body: typeof res.data === 'string' ? res.data : JSON.stringify(res.data), headers: res.headers };
392
+ if (cb)
393
+ cb(result);
394
+ return result;
395
+ }
396
+ catch (e) {
397
+ const res = { statusCode: e.response?.status || 500, body: e.response?.data || e.message, headers: e.response?.headers || {} };
398
+ if (cb)
399
+ cb(res);
400
+ return res;
401
+ }
402
+ },
403
+ http_post: async (url, headers, body, cb) => {
404
+ try {
405
+ const res = await axios.post(url, body, { headers: headers || {} });
406
+ const result = { statusCode: res.status, body: typeof res.data === 'string' ? res.data : JSON.stringify(res.data), headers: res.headers };
389
407
  if (cb)
390
408
  cb(result);
391
409
  return result;
392
410
  }
393
411
  catch (e) {
394
- const res = { status: 500, body: e.message, headers: {} };
412
+ const res = { statusCode: e.response?.status || 500, body: e.response?.data || e.message, headers: e.response?.headers || {} };
395
413
  if (cb)
396
414
  cb(res);
397
415
  return res;
398
416
  }
399
417
  },
418
+ _fetch: async (url) => {
419
+ try {
420
+ const res = await axios.get(url);
421
+ return typeof res.data === 'string' ? res.data : JSON.stringify(res.data);
422
+ }
423
+ catch (e) {
424
+ throw new Error(`HTTP Error ${e.response?.status || 500} fetching ${url}`);
425
+ }
426
+ },
427
+ fetch: async (url) => {
428
+ const res = await axios.get(url);
429
+ return {
430
+ statusCode: res.status,
431
+ body: typeof res.data === 'string' ? res.data : JSON.stringify(res.data),
432
+ headers: res.headers
433
+ };
434
+ },
400
435
  btoa: (s) => Buffer.from(s).toString('base64'),
401
436
  atob: (s) => Buffer.from(s, 'base64').toString('utf8'),
402
437
  globalThis: {},
403
438
  };
404
- const runtime = new Function('manifest', 'console', 'http_get', 'btoa', 'atob', 'globalThis', jsContent);
405
- runtime(context.manifest, context.console, context.http_get, context.btoa, context.atob, context.globalThis);
439
+ const runtime = new Function('manifest', 'console', 'http_get', 'http_post', '_fetch', 'fetch', 'btoa', 'atob', 'globalThis', jsContent);
440
+ runtime(context.manifest, context.console, context.http_get, context.http_post, context._fetch, context.fetch, context.btoa, context.atob, context.globalThis);
406
441
  const fn = context.globalThis[options.function];
407
442
  if (typeof fn !== 'function') {
408
443
  console.error('Error: exported function not found');
@@ -410,12 +445,33 @@ program.command('test')
410
445
  }
411
446
  const callback = (res) => {
412
447
  console.log('\n--- Result ---');
448
+ if (res && res.success === false) {
449
+ console.log(`\x1b[31mStatus: FAILED\x1b[0m`);
450
+ console.log(`\x1b[31mError Code: ${res.errorCode || 'UNKNOWN'}\x1b[0m`);
451
+ if (res.message)
452
+ console.log(`\x1b[31mMessage: ${res.message}\x1b[0m`);
453
+ }
454
+ else {
455
+ console.log(`\x1b[32mStatus: SUCCESS\x1b[0m`);
456
+ }
413
457
  console.log(JSON.stringify(res, null, 2));
414
458
  };
415
- if (options.function === 'getHome')
416
- await fn(callback);
417
- else
418
- await fn(options.query, callback);
459
+ try {
460
+ if (options.function === 'getHome')
461
+ await fn(callback);
462
+ else if (!options.query || options.query.trim() === "") {
463
+ console.warn(`\x1b[33mWarning: Function '${options.function}' usually requires a query/URL (-q), but none was provided.\x1b[0m`);
464
+ await fn(options.query, callback);
465
+ }
466
+ else {
467
+ await fn(options.query, callback);
468
+ }
469
+ }
470
+ catch (e) {
471
+ console.error(`\n\x1b[31m--- CRITICAL ERROR DURING EXECUTION ---\x1b[0m`);
472
+ console.error(`\x1b[31m${e.stack || e.message}\x1b[0m\n`);
473
+ process.exit(2);
474
+ }
419
475
  });
420
476
  program.command('deploy')
421
477
  .description('Deploy all plugins and repository index')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skystream-cli",
3
- "version": "1.2.5",
3
+ "version": "1.2.8",
4
4
  "type": "module",
5
5
  "description": "SkyStream Plugin Development Kit & Repository Manager",
6
6
  "main": "dist/index.js",