@ubiquity-os/plugin-sdk 3.1.11 → 3.2.1

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/README.md CHANGED
@@ -26,6 +26,7 @@ The `postComment` function enables users to easily post a comment to an issue, a
26
26
  To set up the project locally, `bun` is the preferred package manager.
27
27
 
28
28
  1. Install the dependencies:
29
+
29
30
  ```sh
30
31
  bun install
31
32
  ```
@@ -35,9 +36,9 @@ To set up the project locally, `bun` is the preferred package manager.
35
36
  bun sdk:build
36
37
  ```
37
38
  3. Link it locally to another plugin
38
- ```
39
- bun link
40
- ```
39
+ ```
40
+ bun link
41
+ ```
41
42
 
42
43
  ## Scripts
43
44
 
@@ -0,0 +1,4 @@
1
+ declare function compressString(str: string): string;
2
+ declare function decompressString(compressed: string): string;
3
+
4
+ export { compressString, decompressString };
@@ -0,0 +1,4 @@
1
+ declare function compressString(str: string): string;
2
+ declare function decompressString(compressed: string): string;
3
+
4
+ export { compressString, decompressString };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/helpers/compression.ts
21
+ var compression_exports = {};
22
+ __export(compression_exports, {
23
+ compressString: () => compressString,
24
+ decompressString: () => decompressString
25
+ });
26
+ module.exports = __toCommonJS(compression_exports);
27
+ var import_brotli = require("brotli");
28
+ function compressString(str) {
29
+ const input = Buffer.from(str, "utf8");
30
+ const compressed = (0, import_brotli.compress)(input);
31
+ return Buffer.from(compressed).toString("base64");
32
+ }
33
+ function decompressString(compressed) {
34
+ const buffer = Buffer.from(compressed, "base64");
35
+ const decompressed = (0, import_brotli.decompress)(buffer);
36
+ return Buffer.from(decompressed).toString("utf8");
37
+ }
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ compressString,
41
+ decompressString
42
+ });
@@ -0,0 +1,16 @@
1
+ // src/helpers/compression.ts
2
+ import { compress, decompress } from "brotli";
3
+ function compressString(str) {
4
+ const input = Buffer.from(str, "utf8");
5
+ const compressed = compress(input);
6
+ return Buffer.from(compressed).toString("base64");
7
+ }
8
+ function decompressString(compressed) {
9
+ const buffer = Buffer.from(compressed, "base64");
10
+ const decompressed = decompress(buffer);
11
+ return Buffer.from(decompressed).toString("utf8");
12
+ }
13
+ export {
14
+ compressString,
15
+ decompressString
16
+ };
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@ module.exports = __toCommonJS(src_exports);
39
39
  // src/actions.ts
40
40
  var core = __toESM(require("@actions/core"));
41
41
  var github2 = __toESM(require("@actions/github"));
42
- var import_value2 = require("@sinclair/typebox/value");
42
+ var import_value3 = require("@sinclair/typebox/value");
43
43
  var import_ubiquity_os_logger3 = require("@ubiquity-os/ubiquity-os-logger");
44
44
  var import_dotenv = require("dotenv");
45
45
 
@@ -160,6 +160,7 @@ function getPluginOptions(options) {
160
160
  settingsSchema: options?.settingsSchema,
161
161
  envSchema: options?.envSchema,
162
162
  commandSchema: options?.commandSchema,
163
+ // eslint-disable-next-line sonarjs/deprecation
163
164
  bypassSignatureVerification: options?.bypassSignatureVerification || false
164
165
  };
165
166
  }
@@ -335,6 +336,36 @@ function transformError(context2, error) {
335
336
  return loggerError;
336
337
  }
337
338
 
339
+ // src/helpers/command.ts
340
+ var import_value = require("@sinclair/typebox/value");
341
+ function getCommand(inputs, pluginOptions) {
342
+ let command = null;
343
+ if (inputs.command && pluginOptions.commandSchema) {
344
+ try {
345
+ command = import_value.Value.Decode(pluginOptions.commandSchema, import_value.Value.Default(pluginOptions.commandSchema, inputs.command));
346
+ } catch (e) {
347
+ console.dir(...import_value.Value.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
348
+ throw e;
349
+ }
350
+ } else if (inputs.command) {
351
+ command = inputs.command;
352
+ }
353
+ return command;
354
+ }
355
+
356
+ // src/helpers/compression.ts
357
+ var import_brotli = require("brotli");
358
+ function compressString(str) {
359
+ const input = Buffer.from(str, "utf8");
360
+ const compressed = (0, import_brotli.compress)(input);
361
+ return Buffer.from(compressed).toString("base64");
362
+ }
363
+ function decompressString(compressed) {
364
+ const buffer = Buffer.from(compressed, "base64");
365
+ const decompressed = (0, import_brotli.decompress)(buffer);
366
+ return Buffer.from(decompressed).toString("utf8");
367
+ }
368
+
338
369
  // src/octokit.ts
339
370
  var import_core = require("@octokit/core");
340
371
  var import_plugin_paginate_graphql = require("@octokit/plugin-paginate-graphql");
@@ -404,11 +435,11 @@ var commandCallSchema = import_typebox.Type.Union([import_typebox.Type.Null(), i
404
435
 
405
436
  // src/types/util.ts
406
437
  var import_typebox2 = require("@sinclair/typebox");
407
- var import_value = require("@sinclair/typebox/value");
408
- function jsonType(type) {
438
+ var import_value2 = require("@sinclair/typebox/value");
439
+ function jsonType(type, decompress2 = false) {
409
440
  return import_typebox2.Type.Transform(import_typebox2.Type.String()).Decode((value) => {
410
- const parsed = JSON.parse(value);
411
- return import_value.Value.Decode(type, import_value.Value.Default(type, parsed));
441
+ const parsed = JSON.parse(decompress2 ? decompressString(value) : value);
442
+ return import_value2.Value.Decode(type, import_value2.Value.Default(type, parsed));
412
443
  }).Encode((value) => JSON.stringify(value));
413
444
  }
414
445
 
@@ -416,7 +447,7 @@ function jsonType(type) {
416
447
  var inputSchema = import_typebox3.Type.Object({
417
448
  stateId: import_typebox3.Type.String(),
418
449
  eventName: import_typebox3.Type.String(),
419
- eventPayload: jsonType(import_typebox3.Type.Record(import_typebox3.Type.String(), import_typebox3.Type.Any())),
450
+ eventPayload: jsonType(import_typebox3.Type.Record(import_typebox3.Type.String(), import_typebox3.Type.Any()), true),
420
451
  command: jsonType(commandCallSchema),
421
452
  authToken: import_typebox3.Type.String(),
422
453
  settings: jsonType(import_typebox3.Type.Record(import_typebox3.Type.String(), import_typebox3.Type.Any())),
@@ -426,6 +457,18 @@ var inputSchema = import_typebox3.Type.Object({
426
457
 
427
458
  // src/actions.ts
428
459
  (0, import_dotenv.config)();
460
+ async function handleError(context2, pluginOptions, error) {
461
+ console.error(error);
462
+ const loggerError = transformError(context2, error);
463
+ if (loggerError instanceof import_ubiquity_os_logger3.LogReturn) {
464
+ core.setFailed(loggerError.logMessage.diff);
465
+ } else if (loggerError instanceof Error) {
466
+ core.setFailed(loggerError);
467
+ }
468
+ if (pluginOptions.postCommentOnError && loggerError) {
469
+ await context2.commentHandler.postComment(context2, loggerError);
470
+ }
471
+ }
429
472
  async function createActionsPlugin(handler, options) {
430
473
  const pluginOptions = getPluginOptions(options);
431
474
  const pluginGithubToken = process.env.PLUGIN_GITHUB_TOKEN;
@@ -434,7 +477,7 @@ async function createActionsPlugin(handler, options) {
434
477
  return;
435
478
  }
436
479
  const body = github2.context.payload.inputs;
437
- const inputSchemaErrors = [...import_value2.Value.Errors(inputSchema, body)];
480
+ const inputSchemaErrors = [...import_value3.Value.Errors(inputSchema, body)];
438
481
  if (inputSchemaErrors.length) {
439
482
  console.dir(inputSchemaErrors, { depth: null });
440
483
  core.setFailed(`Error: Invalid inputs payload: ${inputSchemaErrors.map((o) => o.message).join(", ")}`);
@@ -445,13 +488,13 @@ async function createActionsPlugin(handler, options) {
445
488
  core.setFailed(`Error: Invalid signature`);
446
489
  return;
447
490
  }
448
- const inputs = import_value2.Value.Decode(inputSchema, body);
491
+ const inputs = import_value3.Value.Decode(inputSchema, body);
449
492
  let config2;
450
493
  if (pluginOptions.settingsSchema) {
451
494
  try {
452
- config2 = import_value2.Value.Decode(pluginOptions.settingsSchema, import_value2.Value.Default(pluginOptions.settingsSchema, inputs.settings));
495
+ config2 = import_value3.Value.Decode(pluginOptions.settingsSchema, import_value3.Value.Default(pluginOptions.settingsSchema, inputs.settings));
453
496
  } catch (e) {
454
- console.dir(...import_value2.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
497
+ console.dir(...import_value3.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
455
498
  core.setFailed(`Error: Invalid settings provided.`);
456
499
  throw e;
457
500
  }
@@ -461,26 +504,16 @@ async function createActionsPlugin(handler, options) {
461
504
  let env;
462
505
  if (pluginOptions.envSchema) {
463
506
  try {
464
- env = import_value2.Value.Decode(pluginOptions.envSchema, import_value2.Value.Default(pluginOptions.envSchema, process.env));
507
+ env = import_value3.Value.Decode(pluginOptions.envSchema, import_value3.Value.Default(pluginOptions.envSchema, process.env));
465
508
  } catch (e) {
466
- console.dir(...import_value2.Value.Errors(pluginOptions.envSchema, process.env), { depth: null });
509
+ console.dir(...import_value3.Value.Errors(pluginOptions.envSchema, process.env), { depth: null });
467
510
  core.setFailed(`Error: Invalid environment provided.`);
468
511
  throw e;
469
512
  }
470
513
  } else {
471
514
  env = process.env;
472
515
  }
473
- let command = null;
474
- if (inputs.command && pluginOptions.commandSchema) {
475
- try {
476
- command = import_value2.Value.Decode(pluginOptions.commandSchema, import_value2.Value.Default(pluginOptions.commandSchema, inputs.command));
477
- } catch (e) {
478
- console.dir(...import_value2.Value.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
479
- throw e;
480
- }
481
- } else if (inputs.command) {
482
- command = inputs.command;
483
- }
516
+ const command = getCommand(inputs, pluginOptions);
484
517
  const context2 = {
485
518
  eventName: inputs.eventName,
486
519
  payload: inputs.eventPayload,
@@ -496,16 +529,7 @@ async function createActionsPlugin(handler, options) {
496
529
  core.setOutput("result", result);
497
530
  await returnDataToKernel(pluginGithubToken, inputs.stateId, result);
498
531
  } catch (error) {
499
- console.error(error);
500
- const loggerError = transformError(context2, error);
501
- if (loggerError instanceof import_ubiquity_os_logger3.LogReturn) {
502
- core.setFailed(loggerError.logMessage.diff);
503
- } else if (loggerError instanceof Error) {
504
- core.setFailed(loggerError);
505
- }
506
- if (pluginOptions.postCommentOnError && loggerError) {
507
- await context2.commentHandler.postComment(context2, loggerError);
508
- }
532
+ await handleError(context2, pluginOptions, error);
509
533
  }
510
534
  }
511
535
  async function returnDataToKernel(repoToken, stateId, output) {
@@ -516,17 +540,25 @@ async function returnDataToKernel(repoToken, stateId, output) {
516
540
  event_type: "return-data-to-ubiquity-os-kernel",
517
541
  client_payload: {
518
542
  state_id: stateId,
519
- output: output ? JSON.stringify(output) : null
543
+ output: output ? compressString(JSON.stringify(output)) : null
520
544
  }
521
545
  });
522
546
  }
523
547
 
524
548
  // src/server.ts
525
- var import_value3 = require("@sinclair/typebox/value");
549
+ var import_value4 = require("@sinclair/typebox/value");
526
550
  var import_ubiquity_os_logger4 = require("@ubiquity-os/ubiquity-os-logger");
527
551
  var import_hono = require("hono");
528
552
  var import_adapter2 = require("hono/adapter");
529
553
  var import_http_exception = require("hono/http-exception");
554
+ async function handleError2(context2, pluginOptions, error) {
555
+ console.error(error);
556
+ const loggerError = transformError(context2, error);
557
+ if (pluginOptions.postCommentOnError && loggerError) {
558
+ await context2.commentHandler.postComment(context2, loggerError);
559
+ }
560
+ throw new import_http_exception.HTTPException(500, { message: "Unexpected error" });
561
+ }
530
562
  function createPlugin(handler, manifest, options) {
531
563
  const pluginOptions = getPluginOptions(options);
532
564
  const app = new import_hono.Hono();
@@ -538,7 +570,7 @@ function createPlugin(handler, manifest, options) {
538
570
  throw new import_http_exception.HTTPException(400, { message: "Content-Type must be application/json" });
539
571
  }
540
572
  const body = await ctx.req.json();
541
- const inputSchemaErrors = [...import_value3.Value.Errors(inputSchema, body)];
573
+ const inputSchemaErrors = [...import_value4.Value.Errors(inputSchema, body)];
542
574
  if (inputSchemaErrors.length) {
543
575
  console.dir(inputSchemaErrors, { depth: null });
544
576
  throw new import_http_exception.HTTPException(400, { message: "Invalid body" });
@@ -547,13 +579,13 @@ function createPlugin(handler, manifest, options) {
547
579
  if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
548
580
  throw new import_http_exception.HTTPException(400, { message: "Invalid signature" });
549
581
  }
550
- const inputs = import_value3.Value.Decode(inputSchema, body);
582
+ const inputs = import_value4.Value.Decode(inputSchema, body);
551
583
  let config2;
552
584
  if (pluginOptions.settingsSchema) {
553
585
  try {
554
- config2 = import_value3.Value.Decode(pluginOptions.settingsSchema, import_value3.Value.Default(pluginOptions.settingsSchema, inputs.settings));
586
+ config2 = import_value4.Value.Decode(pluginOptions.settingsSchema, import_value4.Value.Default(pluginOptions.settingsSchema, inputs.settings));
555
587
  } catch (e) {
556
- console.dir(...import_value3.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
588
+ console.dir(...import_value4.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
557
589
  throw e;
558
590
  }
559
591
  } else {
@@ -563,9 +595,9 @@ function createPlugin(handler, manifest, options) {
563
595
  const honoEnvironment = (0, import_adapter2.env)(ctx);
564
596
  if (pluginOptions.envSchema) {
565
597
  try {
566
- env = import_value3.Value.Decode(pluginOptions.envSchema, import_value3.Value.Default(pluginOptions.envSchema, honoEnvironment));
598
+ env = import_value4.Value.Decode(pluginOptions.envSchema, import_value4.Value.Default(pluginOptions.envSchema, honoEnvironment));
567
599
  } catch (e) {
568
- console.dir(...import_value3.Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
600
+ console.dir(...import_value4.Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
569
601
  throw e;
570
602
  }
571
603
  } else {
@@ -573,17 +605,7 @@ function createPlugin(handler, manifest, options) {
573
605
  }
574
606
  const workerName = new URL(inputs.ref).hostname.split(".")[0];
575
607
  PluginRuntimeInfo.getInstance({ ...env, CLOUDFLARE_WORKER_NAME: workerName });
576
- let command = null;
577
- if (inputs.command && pluginOptions.commandSchema) {
578
- try {
579
- command = import_value3.Value.Decode(pluginOptions.commandSchema, import_value3.Value.Default(pluginOptions.commandSchema, inputs.command));
580
- } catch (e) {
581
- console.log(...import_value3.Value.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
582
- throw e;
583
- }
584
- } else if (inputs.command) {
585
- command = inputs.command;
586
- }
608
+ const command = getCommand(inputs, pluginOptions);
587
609
  const context2 = {
588
610
  eventName: inputs.eventName,
589
611
  payload: inputs.eventPayload,
@@ -598,12 +620,7 @@ function createPlugin(handler, manifest, options) {
598
620
  const result = await handler(context2);
599
621
  return ctx.json({ stateId: inputs.stateId, output: result ?? {} });
600
622
  } catch (error) {
601
- console.error(error);
602
- const loggerError = transformError(context2, error);
603
- if (pluginOptions.postCommentOnError && loggerError) {
604
- await context2.commentHandler.postComment(context2, loggerError);
605
- }
606
- throw new import_http_exception.HTTPException(500, { message: "Unexpected error" });
623
+ await handleError2(context2, pluginOptions, error);
607
624
  }
608
625
  });
609
626
  return app;
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/actions.ts
2
2
  import * as core from "@actions/core";
3
3
  import * as github2 from "@actions/github";
4
- import { Value as Value2 } from "@sinclair/typebox/value";
4
+ import { Value as Value3 } from "@sinclair/typebox/value";
5
5
  import { LogReturn as LogReturn3, Logs } from "@ubiquity-os/ubiquity-os-logger";
6
6
  import { config } from "dotenv";
7
7
 
@@ -122,6 +122,7 @@ function getPluginOptions(options) {
122
122
  settingsSchema: options?.settingsSchema,
123
123
  envSchema: options?.envSchema,
124
124
  commandSchema: options?.commandSchema,
125
+ // eslint-disable-next-line sonarjs/deprecation
125
126
  bypassSignatureVerification: options?.bypassSignatureVerification || false
126
127
  };
127
128
  }
@@ -297,6 +298,36 @@ function transformError(context2, error) {
297
298
  return loggerError;
298
299
  }
299
300
 
301
+ // src/helpers/command.ts
302
+ import { Value } from "@sinclair/typebox/value";
303
+ function getCommand(inputs, pluginOptions) {
304
+ let command = null;
305
+ if (inputs.command && pluginOptions.commandSchema) {
306
+ try {
307
+ command = Value.Decode(pluginOptions.commandSchema, Value.Default(pluginOptions.commandSchema, inputs.command));
308
+ } catch (e) {
309
+ console.dir(...Value.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
310
+ throw e;
311
+ }
312
+ } else if (inputs.command) {
313
+ command = inputs.command;
314
+ }
315
+ return command;
316
+ }
317
+
318
+ // src/helpers/compression.ts
319
+ import { compress, decompress } from "brotli";
320
+ function compressString(str) {
321
+ const input = Buffer.from(str, "utf8");
322
+ const compressed = compress(input);
323
+ return Buffer.from(compressed).toString("base64");
324
+ }
325
+ function decompressString(compressed) {
326
+ const buffer = Buffer.from(compressed, "base64");
327
+ const decompressed = decompress(buffer);
328
+ return Buffer.from(decompressed).toString("utf8");
329
+ }
330
+
300
331
  // src/octokit.ts
301
332
  import { Octokit } from "@octokit/core";
302
333
  import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
@@ -366,11 +397,11 @@ var commandCallSchema = T.Union([T.Null(), T.Object({ name: T.String(), paramete
366
397
 
367
398
  // src/types/util.ts
368
399
  import { Type } from "@sinclair/typebox";
369
- import { Value } from "@sinclair/typebox/value";
370
- function jsonType(type) {
400
+ import { Value as Value2 } from "@sinclair/typebox/value";
401
+ function jsonType(type, decompress2 = false) {
371
402
  return Type.Transform(Type.String()).Decode((value) => {
372
- const parsed = JSON.parse(value);
373
- return Value.Decode(type, Value.Default(type, parsed));
403
+ const parsed = JSON.parse(decompress2 ? decompressString(value) : value);
404
+ return Value2.Decode(type, Value2.Default(type, parsed));
374
405
  }).Encode((value) => JSON.stringify(value));
375
406
  }
376
407
 
@@ -378,7 +409,7 @@ function jsonType(type) {
378
409
  var inputSchema = T2.Object({
379
410
  stateId: T2.String(),
380
411
  eventName: T2.String(),
381
- eventPayload: jsonType(T2.Record(T2.String(), T2.Any())),
412
+ eventPayload: jsonType(T2.Record(T2.String(), T2.Any()), true),
382
413
  command: jsonType(commandCallSchema),
383
414
  authToken: T2.String(),
384
415
  settings: jsonType(T2.Record(T2.String(), T2.Any())),
@@ -388,6 +419,18 @@ var inputSchema = T2.Object({
388
419
 
389
420
  // src/actions.ts
390
421
  config();
422
+ async function handleError(context2, pluginOptions, error) {
423
+ console.error(error);
424
+ const loggerError = transformError(context2, error);
425
+ if (loggerError instanceof LogReturn3) {
426
+ core.setFailed(loggerError.logMessage.diff);
427
+ } else if (loggerError instanceof Error) {
428
+ core.setFailed(loggerError);
429
+ }
430
+ if (pluginOptions.postCommentOnError && loggerError) {
431
+ await context2.commentHandler.postComment(context2, loggerError);
432
+ }
433
+ }
391
434
  async function createActionsPlugin(handler, options) {
392
435
  const pluginOptions = getPluginOptions(options);
393
436
  const pluginGithubToken = process.env.PLUGIN_GITHUB_TOKEN;
@@ -396,7 +439,7 @@ async function createActionsPlugin(handler, options) {
396
439
  return;
397
440
  }
398
441
  const body = github2.context.payload.inputs;
399
- const inputSchemaErrors = [...Value2.Errors(inputSchema, body)];
442
+ const inputSchemaErrors = [...Value3.Errors(inputSchema, body)];
400
443
  if (inputSchemaErrors.length) {
401
444
  console.dir(inputSchemaErrors, { depth: null });
402
445
  core.setFailed(`Error: Invalid inputs payload: ${inputSchemaErrors.map((o) => o.message).join(", ")}`);
@@ -407,13 +450,13 @@ async function createActionsPlugin(handler, options) {
407
450
  core.setFailed(`Error: Invalid signature`);
408
451
  return;
409
452
  }
410
- const inputs = Value2.Decode(inputSchema, body);
453
+ const inputs = Value3.Decode(inputSchema, body);
411
454
  let config2;
412
455
  if (pluginOptions.settingsSchema) {
413
456
  try {
414
- config2 = Value2.Decode(pluginOptions.settingsSchema, Value2.Default(pluginOptions.settingsSchema, inputs.settings));
457
+ config2 = Value3.Decode(pluginOptions.settingsSchema, Value3.Default(pluginOptions.settingsSchema, inputs.settings));
415
458
  } catch (e) {
416
- console.dir(...Value2.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
459
+ console.dir(...Value3.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
417
460
  core.setFailed(`Error: Invalid settings provided.`);
418
461
  throw e;
419
462
  }
@@ -423,26 +466,16 @@ async function createActionsPlugin(handler, options) {
423
466
  let env;
424
467
  if (pluginOptions.envSchema) {
425
468
  try {
426
- env = Value2.Decode(pluginOptions.envSchema, Value2.Default(pluginOptions.envSchema, process.env));
469
+ env = Value3.Decode(pluginOptions.envSchema, Value3.Default(pluginOptions.envSchema, process.env));
427
470
  } catch (e) {
428
- console.dir(...Value2.Errors(pluginOptions.envSchema, process.env), { depth: null });
471
+ console.dir(...Value3.Errors(pluginOptions.envSchema, process.env), { depth: null });
429
472
  core.setFailed(`Error: Invalid environment provided.`);
430
473
  throw e;
431
474
  }
432
475
  } else {
433
476
  env = process.env;
434
477
  }
435
- let command = null;
436
- if (inputs.command && pluginOptions.commandSchema) {
437
- try {
438
- command = Value2.Decode(pluginOptions.commandSchema, Value2.Default(pluginOptions.commandSchema, inputs.command));
439
- } catch (e) {
440
- console.dir(...Value2.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
441
- throw e;
442
- }
443
- } else if (inputs.command) {
444
- command = inputs.command;
445
- }
478
+ const command = getCommand(inputs, pluginOptions);
446
479
  const context2 = {
447
480
  eventName: inputs.eventName,
448
481
  payload: inputs.eventPayload,
@@ -458,16 +491,7 @@ async function createActionsPlugin(handler, options) {
458
491
  core.setOutput("result", result);
459
492
  await returnDataToKernel(pluginGithubToken, inputs.stateId, result);
460
493
  } catch (error) {
461
- console.error(error);
462
- const loggerError = transformError(context2, error);
463
- if (loggerError instanceof LogReturn3) {
464
- core.setFailed(loggerError.logMessage.diff);
465
- } else if (loggerError instanceof Error) {
466
- core.setFailed(loggerError);
467
- }
468
- if (pluginOptions.postCommentOnError && loggerError) {
469
- await context2.commentHandler.postComment(context2, loggerError);
470
- }
494
+ await handleError(context2, pluginOptions, error);
471
495
  }
472
496
  }
473
497
  async function returnDataToKernel(repoToken, stateId, output) {
@@ -478,17 +502,25 @@ async function returnDataToKernel(repoToken, stateId, output) {
478
502
  event_type: "return-data-to-ubiquity-os-kernel",
479
503
  client_payload: {
480
504
  state_id: stateId,
481
- output: output ? JSON.stringify(output) : null
505
+ output: output ? compressString(JSON.stringify(output)) : null
482
506
  }
483
507
  });
484
508
  }
485
509
 
486
510
  // src/server.ts
487
- import { Value as Value3 } from "@sinclair/typebox/value";
511
+ import { Value as Value4 } from "@sinclair/typebox/value";
488
512
  import { Logs as Logs2 } from "@ubiquity-os/ubiquity-os-logger";
489
513
  import { Hono } from "hono";
490
514
  import { env as honoEnv } from "hono/adapter";
491
515
  import { HTTPException } from "hono/http-exception";
516
+ async function handleError2(context2, pluginOptions, error) {
517
+ console.error(error);
518
+ const loggerError = transformError(context2, error);
519
+ if (pluginOptions.postCommentOnError && loggerError) {
520
+ await context2.commentHandler.postComment(context2, loggerError);
521
+ }
522
+ throw new HTTPException(500, { message: "Unexpected error" });
523
+ }
492
524
  function createPlugin(handler, manifest, options) {
493
525
  const pluginOptions = getPluginOptions(options);
494
526
  const app = new Hono();
@@ -500,7 +532,7 @@ function createPlugin(handler, manifest, options) {
500
532
  throw new HTTPException(400, { message: "Content-Type must be application/json" });
501
533
  }
502
534
  const body = await ctx.req.json();
503
- const inputSchemaErrors = [...Value3.Errors(inputSchema, body)];
535
+ const inputSchemaErrors = [...Value4.Errors(inputSchema, body)];
504
536
  if (inputSchemaErrors.length) {
505
537
  console.dir(inputSchemaErrors, { depth: null });
506
538
  throw new HTTPException(400, { message: "Invalid body" });
@@ -509,13 +541,13 @@ function createPlugin(handler, manifest, options) {
509
541
  if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
510
542
  throw new HTTPException(400, { message: "Invalid signature" });
511
543
  }
512
- const inputs = Value3.Decode(inputSchema, body);
544
+ const inputs = Value4.Decode(inputSchema, body);
513
545
  let config2;
514
546
  if (pluginOptions.settingsSchema) {
515
547
  try {
516
- config2 = Value3.Decode(pluginOptions.settingsSchema, Value3.Default(pluginOptions.settingsSchema, inputs.settings));
548
+ config2 = Value4.Decode(pluginOptions.settingsSchema, Value4.Default(pluginOptions.settingsSchema, inputs.settings));
517
549
  } catch (e) {
518
- console.dir(...Value3.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
550
+ console.dir(...Value4.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
519
551
  throw e;
520
552
  }
521
553
  } else {
@@ -525,9 +557,9 @@ function createPlugin(handler, manifest, options) {
525
557
  const honoEnvironment = honoEnv(ctx);
526
558
  if (pluginOptions.envSchema) {
527
559
  try {
528
- env = Value3.Decode(pluginOptions.envSchema, Value3.Default(pluginOptions.envSchema, honoEnvironment));
560
+ env = Value4.Decode(pluginOptions.envSchema, Value4.Default(pluginOptions.envSchema, honoEnvironment));
529
561
  } catch (e) {
530
- console.dir(...Value3.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
562
+ console.dir(...Value4.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
531
563
  throw e;
532
564
  }
533
565
  } else {
@@ -535,17 +567,7 @@ function createPlugin(handler, manifest, options) {
535
567
  }
536
568
  const workerName = new URL(inputs.ref).hostname.split(".")[0];
537
569
  PluginRuntimeInfo.getInstance({ ...env, CLOUDFLARE_WORKER_NAME: workerName });
538
- let command = null;
539
- if (inputs.command && pluginOptions.commandSchema) {
540
- try {
541
- command = Value3.Decode(pluginOptions.commandSchema, Value3.Default(pluginOptions.commandSchema, inputs.command));
542
- } catch (e) {
543
- console.log(...Value3.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
544
- throw e;
545
- }
546
- } else if (inputs.command) {
547
- command = inputs.command;
548
- }
570
+ const command = getCommand(inputs, pluginOptions);
549
571
  const context2 = {
550
572
  eventName: inputs.eventName,
551
573
  payload: inputs.eventPayload,
@@ -560,12 +582,7 @@ function createPlugin(handler, manifest, options) {
560
582
  const result = await handler(context2);
561
583
  return ctx.json({ stateId: inputs.stateId, output: result ?? {} });
562
584
  } catch (error) {
563
- console.error(error);
564
- const loggerError = transformError(context2, error);
565
- if (pluginOptions.postCommentOnError && loggerError) {
566
- await context2.commentHandler.postComment(context2, loggerError);
567
- }
568
- throw new HTTPException(500, { message: "Unexpected error" });
585
+ await handleError2(context2, pluginOptions, error);
569
586
  }
570
587
  });
571
588
  return app;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubiquity-os/plugin-sdk",
3
- "version": "3.1.11",
3
+ "version": "3.2.1",
4
4
  "description": "SDK for plugin support.",
5
5
  "author": "Ubiquity DAO",
6
6
  "license": "MIT",
@@ -27,6 +27,9 @@
27
27
  ],
28
28
  "helpers": [
29
29
  "dist/helpers.d.ts"
30
+ ],
31
+ "compression": [
32
+ "dist/compression.d.ts"
30
33
  ]
31
34
  }
32
35
  },
@@ -60,6 +63,11 @@
60
63
  "types": "./dist/helpers.d.ts",
61
64
  "import": "./dist/helpers.mjs",
62
65
  "require": "./dist/helpers.js"
66
+ },
67
+ "./compression": {
68
+ "types": "./dist/compression.d.ts",
69
+ "import": "./dist/compression.mjs",
70
+ "require": "./dist/compression.js"
63
71
  }
64
72
  },
65
73
  "files": [
@@ -95,6 +103,7 @@
95
103
  "@octokit/types": "^13.8.0",
96
104
  "@octokit/webhooks": "^13.7.4",
97
105
  "@ubiquity-os/ubiquity-os-logger": "^1.4.0",
106
+ "brotli": "^1.3.3",
98
107
  "dotenv": "^16.4.5",
99
108
  "hono": "^4.6.9"
100
109
  },
@@ -110,7 +119,9 @@
110
119
  "@eslint/js": "^9.14.0",
111
120
  "@jest/globals": "^29.7.0",
112
121
  "@mswjs/data": "0.16.1",
122
+ "@types/brotli": "^1.3.4",
113
123
  "@types/node": "^20.11.19",
124
+ "@ubiquity-os/eslint-plugin-no-empty-strings": "^1.0.3",
114
125
  "cross-env": "^7.0.3",
115
126
  "cspell": "^8.4.0",
116
127
  "eslint": "^9.14.0",