skystream-cli 1.2.4 → 1.2.7

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 +45 -9
  2. package/package.json +1 -1
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.4');
12
+ .version('1.2.7');
13
13
  // Schemas
14
14
  const pluginSchema = z.object({
15
15
  packageName: z.string().min(5).regex(/^[a-z0-9._-]+$/),
@@ -40,7 +40,8 @@ const JS_TEMPLATE = `(function() {
40
40
  /**
41
41
  * @type {import('@skystream/sdk').Manifest}
42
42
  */
43
- const pluginManifest = manifest;
43
+ // var manifest is injected at runtime
44
+
44
45
 
45
46
  /**
46
47
  * Loads the home screen categories.
@@ -102,7 +103,7 @@ const JS_TEMPLATE = `(function() {
102
103
  * @param {string} url
103
104
  * @param {(res: Response) => void} cb
104
105
  */
105
- function load(url, cb) {
106
+ async function load(url, cb) {
106
107
  try {
107
108
  // Standard: Return a single item with full metadata
108
109
  cb({
@@ -380,28 +381,63 @@ program.command('test')
380
381
  console.log(`\n--- Testing ${manifest.packageName} -> ${options.function} ---`);
381
382
  const context = {
382
383
  manifest,
383
- 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
+ },
384
388
  http_get: async (url, headers, cb) => {
385
389
  try {
386
- const res = await axios.get(url, { headers });
387
- 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 };
388
392
  if (cb)
389
393
  cb(result);
390
394
  return result;
391
395
  }
392
396
  catch (e) {
393
- const res = { status: 500, body: e.message, headers: {} };
397
+ const res = { statusCode: e.response?.status || 500, body: e.response?.data || e.message, headers: e.response?.headers || {} };
394
398
  if (cb)
395
399
  cb(res);
396
400
  return res;
397
401
  }
398
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 };
407
+ if (cb)
408
+ cb(result);
409
+ return result;
410
+ }
411
+ catch (e) {
412
+ const res = { statusCode: e.response?.status || 500, body: e.response?.data || e.message, headers: e.response?.headers || {} };
413
+ if (cb)
414
+ cb(res);
415
+ return res;
416
+ }
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
+ },
399
435
  btoa: (s) => Buffer.from(s).toString('base64'),
400
436
  atob: (s) => Buffer.from(s, 'base64').toString('utf8'),
401
437
  globalThis: {},
402
438
  };
403
- const runtime = new Function('manifest', 'console', 'http_get', 'btoa', 'atob', 'globalThis', jsContent);
404
- 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);
405
441
  const fn = context.globalThis[options.function];
406
442
  if (typeof fn !== 'function') {
407
443
  console.error('Error: exported function not found');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skystream-cli",
3
- "version": "1.2.4",
3
+ "version": "1.2.7",
4
4
  "type": "module",
5
5
  "description": "SkyStream Plugin Development Kit & Repository Manager",
6
6
  "main": "dist/index.js",