@ubiquity-os/plugin-sdk 3.1.10 → 3.2.0

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.d.mts CHANGED
@@ -52,7 +52,7 @@ declare class CommentHandler {
52
52
  _getIssueNumber(context: Context): number | undefined;
53
53
  _getCommentId(context: Context): number | undefined;
54
54
  _extractIssueContext(context: Context): IssueContext | null;
55
- _processMessage(context: Context, message: LogReturn | Error): Promise<{
55
+ _processMessage(context: Context, message: LogReturn | Error): {
56
56
  metadata: {
57
57
  message: string;
58
58
  name: string;
@@ -88,14 +88,14 @@ declare class CommentHandler {
88
88
  level: _ubiquity_os_ubiquity_os_logger.LogLevel;
89
89
  type: _ubiquity_os_ubiquity_os_logger.LogLevelWithOk;
90
90
  };
91
- }>;
91
+ };
92
92
  _getInstigatorName(context: Context): string;
93
- _createMetadataContent(context: Context, metadata: Metadata): Promise<{
93
+ _createMetadataContent(context: Context, metadata: Metadata): {
94
94
  header: string;
95
95
  jsonPretty: string;
96
- }>;
96
+ };
97
97
  _formatMetadataContent(logMessage: LogReturn["logMessage"], header: string, jsonPretty: string): string;
98
- createCommentBody(context: Context, message: LogReturn | Error, options?: Pick<CommentOptions, "raw">): Promise<string>;
98
+ createCommentBody(context: Context, message: LogReturn | Error, options?: Pick<CommentOptions, "raw">): string;
99
99
  private _createCommentBody;
100
100
  postComment(context: Context, message: LogReturn | Error, options?: CommentOptions): Promise<WithIssueNumber<PostedGithubComment> | null>;
101
101
  }
package/dist/index.d.ts CHANGED
@@ -52,7 +52,7 @@ declare class CommentHandler {
52
52
  _getIssueNumber(context: Context): number | undefined;
53
53
  _getCommentId(context: Context): number | undefined;
54
54
  _extractIssueContext(context: Context): IssueContext | null;
55
- _processMessage(context: Context, message: LogReturn | Error): Promise<{
55
+ _processMessage(context: Context, message: LogReturn | Error): {
56
56
  metadata: {
57
57
  message: string;
58
58
  name: string;
@@ -88,14 +88,14 @@ declare class CommentHandler {
88
88
  level: _ubiquity_os_ubiquity_os_logger.LogLevel;
89
89
  type: _ubiquity_os_ubiquity_os_logger.LogLevelWithOk;
90
90
  };
91
- }>;
91
+ };
92
92
  _getInstigatorName(context: Context): string;
93
- _createMetadataContent(context: Context, metadata: Metadata): Promise<{
93
+ _createMetadataContent(context: Context, metadata: Metadata): {
94
94
  header: string;
95
95
  jsonPretty: string;
96
- }>;
96
+ };
97
97
  _formatMetadataContent(logMessage: LogReturn["logMessage"], header: string, jsonPretty: string): string;
98
- createCommentBody(context: Context, message: LogReturn | Error, options?: Pick<CommentOptions, "raw">): Promise<string>;
98
+ createCommentBody(context: Context, message: LogReturn | Error, options?: Pick<CommentOptions, "raw">): string;
99
99
  private _createCommentBody;
100
100
  postComment(context: Context, message: LogReturn | Error, options?: CommentOptions): Promise<WithIssueNumber<PostedGithubComment> | null>;
101
101
  }
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
 
@@ -76,7 +76,7 @@ var PluginRuntimeInfo = class _PluginRuntimeInfo {
76
76
  };
77
77
  var CfRuntimeInfo = class extends PluginRuntimeInfo {
78
78
  get version() {
79
- return Promise.resolve(this._env.CLOUDFLARE_VERSION_METADATA?.id ?? "CLOUDFLARE_VERSION_METADATA");
79
+ return this._env.CLOUDFLARE_VERSION_METADATA?.id ?? "CLOUDFLARE_VERSION_METADATA";
80
80
  }
81
81
  get runUrl() {
82
82
  const accountId = this._env.CLOUDFLARE_ACCOUNT_ID ?? "<missing-cloudflare-account-id>";
@@ -89,7 +89,7 @@ var CfRuntimeInfo = class extends PluginRuntimeInfo {
89
89
  };
90
90
  var NodeRuntimeInfo = class extends PluginRuntimeInfo {
91
91
  get version() {
92
- return Promise.resolve(import_github.default.context.sha);
92
+ return import_github.default.context.sha;
93
93
  }
94
94
  get runUrl() {
95
95
  return import_github.default.context.payload.repository ? `${import_github.default.context.payload.repository?.html_url}/actions/runs/${import_github.default.context.runId}` : "http://localhost";
@@ -97,7 +97,7 @@ var NodeRuntimeInfo = class extends PluginRuntimeInfo {
97
97
  };
98
98
  var DenoRuntimeInfo = class extends PluginRuntimeInfo {
99
99
  get version() {
100
- return Promise.resolve(Deno.env.get("DENO_DEPLOYMENT_ID"));
100
+ return Deno.env.get("DENO_DEPLOYMENT_ID");
101
101
  }
102
102
  get runUrl() {
103
103
  const projectName = Deno.env.get("DENO_PROJECT_NAME");
@@ -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
  }
@@ -235,7 +236,7 @@ var CommentHandler = class _CommentHandler {
235
236
  repo: context2.payload.repository.name
236
237
  };
237
238
  }
238
- async _processMessage(context2, message) {
239
+ _processMessage(context2, message) {
239
240
  if (message instanceof Error) {
240
241
  const metadata2 = {
241
242
  message: message.message,
@@ -258,11 +259,11 @@ var CommentHandler = class _CommentHandler {
258
259
  }
259
260
  return context2.payload.sender?.login || _CommentHandler.HEADER_NAME;
260
261
  }
261
- async _createMetadataContent(context2, metadata) {
262
+ _createMetadataContent(context2, metadata) {
262
263
  const jsonPretty = sanitizeMetadata(metadata);
263
264
  const instigatorName = this._getInstigatorName(context2);
264
265
  const runUrl = PluginRuntimeInfo.getInstance().runUrl;
265
- const version = await PluginRuntimeInfo.getInstance().version;
266
+ const version = PluginRuntimeInfo.getInstance().version;
266
267
  const callingFnName = metadata.caller || "anonymous";
267
268
  return {
268
269
  header: `<!-- ${_CommentHandler.HEADER_NAME} - ${callingFnName} - ${version} - @${instigatorName} - ${runUrl}`,
@@ -277,12 +278,12 @@ var CommentHandler = class _CommentHandler {
277
278
  /*
278
279
  * Creates the body for the comment, embeds the metadata and the header hidden in the body as well.
279
280
  */
280
- async createCommentBody(context2, message, options) {
281
+ createCommentBody(context2, message, options) {
281
282
  return this._createCommentBody(context2, message, options);
282
283
  }
283
- async _createCommentBody(context2, message, options) {
284
- const { metadata, logMessage } = await this._processMessage(context2, message);
285
- const { header, jsonPretty } = await this._createMetadataContent(context2, metadata);
284
+ _createCommentBody(context2, message, options) {
285
+ const { metadata, logMessage } = this._processMessage(context2, message);
286
+ const { header, jsonPretty } = this._createMetadataContent(context2, metadata);
286
287
  const metadataContent = this._formatMetadataContent(logMessage, header, jsonPretty);
287
288
  return `${options?.raw ? logMessage?.raw : logMessage?.diff}
288
289
 
@@ -295,7 +296,7 @@ ${metadataContent}
295
296
  context2.logger.info("Cannot post comment: missing issue context in payload");
296
297
  return null;
297
298
  }
298
- const body = await this._createCommentBody(context2, message, options);
299
+ const body = this._createCommentBody(context2, message, options);
299
300
  const { issueNumber, commentId, owner, repo } = issueContext;
300
301
  const params = { owner, repo, body, issueNumber };
301
302
  if (options.updateComment) {
@@ -335,6 +336,31 @@ 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
+
338
364
  // src/octokit.ts
339
365
  var import_core = require("@octokit/core");
340
366
  var import_plugin_paginate_graphql = require("@octokit/plugin-paginate-graphql");
@@ -404,11 +430,11 @@ var commandCallSchema = import_typebox.Type.Union([import_typebox.Type.Null(), i
404
430
 
405
431
  // src/types/util.ts
406
432
  var import_typebox2 = require("@sinclair/typebox");
407
- var import_value = require("@sinclair/typebox/value");
433
+ var import_value2 = require("@sinclair/typebox/value");
408
434
  function jsonType(type) {
409
435
  return import_typebox2.Type.Transform(import_typebox2.Type.String()).Decode((value) => {
410
436
  const parsed = JSON.parse(value);
411
- return import_value.Value.Decode(type, import_value.Value.Default(type, parsed));
437
+ return import_value2.Value.Decode(type, import_value2.Value.Default(type, parsed));
412
438
  }).Encode((value) => JSON.stringify(value));
413
439
  }
414
440
 
@@ -426,6 +452,18 @@ var inputSchema = import_typebox3.Type.Object({
426
452
 
427
453
  // src/actions.ts
428
454
  (0, import_dotenv.config)();
455
+ async function handleError(context2, pluginOptions, error) {
456
+ console.error(error);
457
+ const loggerError = transformError(context2, error);
458
+ if (loggerError instanceof import_ubiquity_os_logger3.LogReturn) {
459
+ core.setFailed(loggerError.logMessage.diff);
460
+ } else if (loggerError instanceof Error) {
461
+ core.setFailed(loggerError);
462
+ }
463
+ if (pluginOptions.postCommentOnError && loggerError) {
464
+ await context2.commentHandler.postComment(context2, loggerError);
465
+ }
466
+ }
429
467
  async function createActionsPlugin(handler, options) {
430
468
  const pluginOptions = getPluginOptions(options);
431
469
  const pluginGithubToken = process.env.PLUGIN_GITHUB_TOKEN;
@@ -434,7 +472,7 @@ async function createActionsPlugin(handler, options) {
434
472
  return;
435
473
  }
436
474
  const body = github2.context.payload.inputs;
437
- const inputSchemaErrors = [...import_value2.Value.Errors(inputSchema, body)];
475
+ const inputSchemaErrors = [...import_value3.Value.Errors(inputSchema, body)];
438
476
  if (inputSchemaErrors.length) {
439
477
  console.dir(inputSchemaErrors, { depth: null });
440
478
  core.setFailed(`Error: Invalid inputs payload: ${inputSchemaErrors.map((o) => o.message).join(", ")}`);
@@ -445,13 +483,13 @@ async function createActionsPlugin(handler, options) {
445
483
  core.setFailed(`Error: Invalid signature`);
446
484
  return;
447
485
  }
448
- const inputs = import_value2.Value.Decode(inputSchema, body);
486
+ const inputs = import_value3.Value.Decode(inputSchema, body);
449
487
  let config2;
450
488
  if (pluginOptions.settingsSchema) {
451
489
  try {
452
- config2 = import_value2.Value.Decode(pluginOptions.settingsSchema, import_value2.Value.Default(pluginOptions.settingsSchema, inputs.settings));
490
+ config2 = import_value3.Value.Decode(pluginOptions.settingsSchema, import_value3.Value.Default(pluginOptions.settingsSchema, inputs.settings));
453
491
  } catch (e) {
454
- console.dir(...import_value2.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
492
+ console.dir(...import_value3.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
455
493
  core.setFailed(`Error: Invalid settings provided.`);
456
494
  throw e;
457
495
  }
@@ -461,26 +499,16 @@ async function createActionsPlugin(handler, options) {
461
499
  let env;
462
500
  if (pluginOptions.envSchema) {
463
501
  try {
464
- env = import_value2.Value.Decode(pluginOptions.envSchema, import_value2.Value.Default(pluginOptions.envSchema, process.env));
502
+ env = import_value3.Value.Decode(pluginOptions.envSchema, import_value3.Value.Default(pluginOptions.envSchema, process.env));
465
503
  } catch (e) {
466
- console.dir(...import_value2.Value.Errors(pluginOptions.envSchema, process.env), { depth: null });
504
+ console.dir(...import_value3.Value.Errors(pluginOptions.envSchema, process.env), { depth: null });
467
505
  core.setFailed(`Error: Invalid environment provided.`);
468
506
  throw e;
469
507
  }
470
508
  } else {
471
509
  env = process.env;
472
510
  }
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
- }
511
+ const command = getCommand(inputs, pluginOptions);
484
512
  const context2 = {
485
513
  eventName: inputs.eventName,
486
514
  payload: inputs.eventPayload,
@@ -496,16 +524,7 @@ async function createActionsPlugin(handler, options) {
496
524
  core.setOutput("result", result);
497
525
  await returnDataToKernel(pluginGithubToken, inputs.stateId, result);
498
526
  } 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
- }
527
+ await handleError(context2, pluginOptions, error);
509
528
  }
510
529
  }
511
530
  async function returnDataToKernel(repoToken, stateId, output) {
@@ -516,17 +535,25 @@ async function returnDataToKernel(repoToken, stateId, output) {
516
535
  event_type: "return-data-to-ubiquity-os-kernel",
517
536
  client_payload: {
518
537
  state_id: stateId,
519
- output: output ? JSON.stringify(output) : null
538
+ output: output ? compressString(JSON.stringify(output)) : null
520
539
  }
521
540
  });
522
541
  }
523
542
 
524
543
  // src/server.ts
525
- var import_value3 = require("@sinclair/typebox/value");
544
+ var import_value4 = require("@sinclair/typebox/value");
526
545
  var import_ubiquity_os_logger4 = require("@ubiquity-os/ubiquity-os-logger");
527
546
  var import_hono = require("hono");
528
547
  var import_adapter2 = require("hono/adapter");
529
548
  var import_http_exception = require("hono/http-exception");
549
+ async function handleError2(context2, pluginOptions, error) {
550
+ console.error(error);
551
+ const loggerError = transformError(context2, error);
552
+ if (pluginOptions.postCommentOnError && loggerError) {
553
+ await context2.commentHandler.postComment(context2, loggerError);
554
+ }
555
+ throw new import_http_exception.HTTPException(500, { message: "Unexpected error" });
556
+ }
530
557
  function createPlugin(handler, manifest, options) {
531
558
  const pluginOptions = getPluginOptions(options);
532
559
  const app = new import_hono.Hono();
@@ -538,7 +565,7 @@ function createPlugin(handler, manifest, options) {
538
565
  throw new import_http_exception.HTTPException(400, { message: "Content-Type must be application/json" });
539
566
  }
540
567
  const body = await ctx.req.json();
541
- const inputSchemaErrors = [...import_value3.Value.Errors(inputSchema, body)];
568
+ const inputSchemaErrors = [...import_value4.Value.Errors(inputSchema, body)];
542
569
  if (inputSchemaErrors.length) {
543
570
  console.dir(inputSchemaErrors, { depth: null });
544
571
  throw new import_http_exception.HTTPException(400, { message: "Invalid body" });
@@ -547,13 +574,13 @@ function createPlugin(handler, manifest, options) {
547
574
  if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
548
575
  throw new import_http_exception.HTTPException(400, { message: "Invalid signature" });
549
576
  }
550
- const inputs = import_value3.Value.Decode(inputSchema, body);
577
+ const inputs = import_value4.Value.Decode(inputSchema, body);
551
578
  let config2;
552
579
  if (pluginOptions.settingsSchema) {
553
580
  try {
554
- config2 = import_value3.Value.Decode(pluginOptions.settingsSchema, import_value3.Value.Default(pluginOptions.settingsSchema, inputs.settings));
581
+ config2 = import_value4.Value.Decode(pluginOptions.settingsSchema, import_value4.Value.Default(pluginOptions.settingsSchema, inputs.settings));
555
582
  } catch (e) {
556
- console.dir(...import_value3.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
583
+ console.dir(...import_value4.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
557
584
  throw e;
558
585
  }
559
586
  } else {
@@ -563,9 +590,9 @@ function createPlugin(handler, manifest, options) {
563
590
  const honoEnvironment = (0, import_adapter2.env)(ctx);
564
591
  if (pluginOptions.envSchema) {
565
592
  try {
566
- env = import_value3.Value.Decode(pluginOptions.envSchema, import_value3.Value.Default(pluginOptions.envSchema, honoEnvironment));
593
+ env = import_value4.Value.Decode(pluginOptions.envSchema, import_value4.Value.Default(pluginOptions.envSchema, honoEnvironment));
567
594
  } catch (e) {
568
- console.dir(...import_value3.Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
595
+ console.dir(...import_value4.Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
569
596
  throw e;
570
597
  }
571
598
  } else {
@@ -573,17 +600,7 @@ function createPlugin(handler, manifest, options) {
573
600
  }
574
601
  const workerName = new URL(inputs.ref).hostname.split(".")[0];
575
602
  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
- }
603
+ const command = getCommand(inputs, pluginOptions);
587
604
  const context2 = {
588
605
  eventName: inputs.eventName,
589
606
  payload: inputs.eventPayload,
@@ -598,12 +615,7 @@ function createPlugin(handler, manifest, options) {
598
615
  const result = await handler(context2);
599
616
  return ctx.json({ stateId: inputs.stateId, output: result ?? {} });
600
617
  } 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" });
618
+ await handleError2(context2, pluginOptions, error);
607
619
  }
608
620
  });
609
621
  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
 
@@ -38,7 +38,7 @@ var PluginRuntimeInfo = class _PluginRuntimeInfo {
38
38
  };
39
39
  var CfRuntimeInfo = class extends PluginRuntimeInfo {
40
40
  get version() {
41
- return Promise.resolve(this._env.CLOUDFLARE_VERSION_METADATA?.id ?? "CLOUDFLARE_VERSION_METADATA");
41
+ return this._env.CLOUDFLARE_VERSION_METADATA?.id ?? "CLOUDFLARE_VERSION_METADATA";
42
42
  }
43
43
  get runUrl() {
44
44
  const accountId = this._env.CLOUDFLARE_ACCOUNT_ID ?? "<missing-cloudflare-account-id>";
@@ -51,7 +51,7 @@ var CfRuntimeInfo = class extends PluginRuntimeInfo {
51
51
  };
52
52
  var NodeRuntimeInfo = class extends PluginRuntimeInfo {
53
53
  get version() {
54
- return Promise.resolve(github.context.sha);
54
+ return github.context.sha;
55
55
  }
56
56
  get runUrl() {
57
57
  return github.context.payload.repository ? `${github.context.payload.repository?.html_url}/actions/runs/${github.context.runId}` : "http://localhost";
@@ -59,7 +59,7 @@ var NodeRuntimeInfo = class extends PluginRuntimeInfo {
59
59
  };
60
60
  var DenoRuntimeInfo = class extends PluginRuntimeInfo {
61
61
  get version() {
62
- return Promise.resolve(Deno.env.get("DENO_DEPLOYMENT_ID"));
62
+ return Deno.env.get("DENO_DEPLOYMENT_ID");
63
63
  }
64
64
  get runUrl() {
65
65
  const projectName = Deno.env.get("DENO_PROJECT_NAME");
@@ -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
  }
@@ -197,7 +198,7 @@ var CommentHandler = class _CommentHandler {
197
198
  repo: context2.payload.repository.name
198
199
  };
199
200
  }
200
- async _processMessage(context2, message) {
201
+ _processMessage(context2, message) {
201
202
  if (message instanceof Error) {
202
203
  const metadata2 = {
203
204
  message: message.message,
@@ -220,11 +221,11 @@ var CommentHandler = class _CommentHandler {
220
221
  }
221
222
  return context2.payload.sender?.login || _CommentHandler.HEADER_NAME;
222
223
  }
223
- async _createMetadataContent(context2, metadata) {
224
+ _createMetadataContent(context2, metadata) {
224
225
  const jsonPretty = sanitizeMetadata(metadata);
225
226
  const instigatorName = this._getInstigatorName(context2);
226
227
  const runUrl = PluginRuntimeInfo.getInstance().runUrl;
227
- const version = await PluginRuntimeInfo.getInstance().version;
228
+ const version = PluginRuntimeInfo.getInstance().version;
228
229
  const callingFnName = metadata.caller || "anonymous";
229
230
  return {
230
231
  header: `<!-- ${_CommentHandler.HEADER_NAME} - ${callingFnName} - ${version} - @${instigatorName} - ${runUrl}`,
@@ -239,12 +240,12 @@ var CommentHandler = class _CommentHandler {
239
240
  /*
240
241
  * Creates the body for the comment, embeds the metadata and the header hidden in the body as well.
241
242
  */
242
- async createCommentBody(context2, message, options) {
243
+ createCommentBody(context2, message, options) {
243
244
  return this._createCommentBody(context2, message, options);
244
245
  }
245
- async _createCommentBody(context2, message, options) {
246
- const { metadata, logMessage } = await this._processMessage(context2, message);
247
- const { header, jsonPretty } = await this._createMetadataContent(context2, metadata);
246
+ _createCommentBody(context2, message, options) {
247
+ const { metadata, logMessage } = this._processMessage(context2, message);
248
+ const { header, jsonPretty } = this._createMetadataContent(context2, metadata);
248
249
  const metadataContent = this._formatMetadataContent(logMessage, header, jsonPretty);
249
250
  return `${options?.raw ? logMessage?.raw : logMessage?.diff}
250
251
 
@@ -257,7 +258,7 @@ ${metadataContent}
257
258
  context2.logger.info("Cannot post comment: missing issue context in payload");
258
259
  return null;
259
260
  }
260
- const body = await this._createCommentBody(context2, message, options);
261
+ const body = this._createCommentBody(context2, message, options);
261
262
  const { issueNumber, commentId, owner, repo } = issueContext;
262
263
  const params = { owner, repo, body, issueNumber };
263
264
  if (options.updateComment) {
@@ -297,6 +298,31 @@ 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
+
300
326
  // src/octokit.ts
301
327
  import { Octokit } from "@octokit/core";
302
328
  import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
@@ -366,11 +392,11 @@ var commandCallSchema = T.Union([T.Null(), T.Object({ name: T.String(), paramete
366
392
 
367
393
  // src/types/util.ts
368
394
  import { Type } from "@sinclair/typebox";
369
- import { Value } from "@sinclair/typebox/value";
395
+ import { Value as Value2 } from "@sinclair/typebox/value";
370
396
  function jsonType(type) {
371
397
  return Type.Transform(Type.String()).Decode((value) => {
372
398
  const parsed = JSON.parse(value);
373
- return Value.Decode(type, Value.Default(type, parsed));
399
+ return Value2.Decode(type, Value2.Default(type, parsed));
374
400
  }).Encode((value) => JSON.stringify(value));
375
401
  }
376
402
 
@@ -388,6 +414,18 @@ var inputSchema = T2.Object({
388
414
 
389
415
  // src/actions.ts
390
416
  config();
417
+ async function handleError(context2, pluginOptions, error) {
418
+ console.error(error);
419
+ const loggerError = transformError(context2, error);
420
+ if (loggerError instanceof LogReturn3) {
421
+ core.setFailed(loggerError.logMessage.diff);
422
+ } else if (loggerError instanceof Error) {
423
+ core.setFailed(loggerError);
424
+ }
425
+ if (pluginOptions.postCommentOnError && loggerError) {
426
+ await context2.commentHandler.postComment(context2, loggerError);
427
+ }
428
+ }
391
429
  async function createActionsPlugin(handler, options) {
392
430
  const pluginOptions = getPluginOptions(options);
393
431
  const pluginGithubToken = process.env.PLUGIN_GITHUB_TOKEN;
@@ -396,7 +434,7 @@ async function createActionsPlugin(handler, options) {
396
434
  return;
397
435
  }
398
436
  const body = github2.context.payload.inputs;
399
- const inputSchemaErrors = [...Value2.Errors(inputSchema, body)];
437
+ const inputSchemaErrors = [...Value3.Errors(inputSchema, body)];
400
438
  if (inputSchemaErrors.length) {
401
439
  console.dir(inputSchemaErrors, { depth: null });
402
440
  core.setFailed(`Error: Invalid inputs payload: ${inputSchemaErrors.map((o) => o.message).join(", ")}`);
@@ -407,13 +445,13 @@ async function createActionsPlugin(handler, options) {
407
445
  core.setFailed(`Error: Invalid signature`);
408
446
  return;
409
447
  }
410
- const inputs = Value2.Decode(inputSchema, body);
448
+ const inputs = Value3.Decode(inputSchema, body);
411
449
  let config2;
412
450
  if (pluginOptions.settingsSchema) {
413
451
  try {
414
- config2 = Value2.Decode(pluginOptions.settingsSchema, Value2.Default(pluginOptions.settingsSchema, inputs.settings));
452
+ config2 = Value3.Decode(pluginOptions.settingsSchema, Value3.Default(pluginOptions.settingsSchema, inputs.settings));
415
453
  } catch (e) {
416
- console.dir(...Value2.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
454
+ console.dir(...Value3.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
417
455
  core.setFailed(`Error: Invalid settings provided.`);
418
456
  throw e;
419
457
  }
@@ -423,26 +461,16 @@ async function createActionsPlugin(handler, options) {
423
461
  let env;
424
462
  if (pluginOptions.envSchema) {
425
463
  try {
426
- env = Value2.Decode(pluginOptions.envSchema, Value2.Default(pluginOptions.envSchema, process.env));
464
+ env = Value3.Decode(pluginOptions.envSchema, Value3.Default(pluginOptions.envSchema, process.env));
427
465
  } catch (e) {
428
- console.dir(...Value2.Errors(pluginOptions.envSchema, process.env), { depth: null });
466
+ console.dir(...Value3.Errors(pluginOptions.envSchema, process.env), { depth: null });
429
467
  core.setFailed(`Error: Invalid environment provided.`);
430
468
  throw e;
431
469
  }
432
470
  } else {
433
471
  env = process.env;
434
472
  }
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
- }
473
+ const command = getCommand(inputs, pluginOptions);
446
474
  const context2 = {
447
475
  eventName: inputs.eventName,
448
476
  payload: inputs.eventPayload,
@@ -458,16 +486,7 @@ async function createActionsPlugin(handler, options) {
458
486
  core.setOutput("result", result);
459
487
  await returnDataToKernel(pluginGithubToken, inputs.stateId, result);
460
488
  } 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
- }
489
+ await handleError(context2, pluginOptions, error);
471
490
  }
472
491
  }
473
492
  async function returnDataToKernel(repoToken, stateId, output) {
@@ -478,17 +497,25 @@ async function returnDataToKernel(repoToken, stateId, output) {
478
497
  event_type: "return-data-to-ubiquity-os-kernel",
479
498
  client_payload: {
480
499
  state_id: stateId,
481
- output: output ? JSON.stringify(output) : null
500
+ output: output ? compressString(JSON.stringify(output)) : null
482
501
  }
483
502
  });
484
503
  }
485
504
 
486
505
  // src/server.ts
487
- import { Value as Value3 } from "@sinclair/typebox/value";
506
+ import { Value as Value4 } from "@sinclair/typebox/value";
488
507
  import { Logs as Logs2 } from "@ubiquity-os/ubiquity-os-logger";
489
508
  import { Hono } from "hono";
490
509
  import { env as honoEnv } from "hono/adapter";
491
510
  import { HTTPException } from "hono/http-exception";
511
+ async function handleError2(context2, pluginOptions, error) {
512
+ console.error(error);
513
+ const loggerError = transformError(context2, error);
514
+ if (pluginOptions.postCommentOnError && loggerError) {
515
+ await context2.commentHandler.postComment(context2, loggerError);
516
+ }
517
+ throw new HTTPException(500, { message: "Unexpected error" });
518
+ }
492
519
  function createPlugin(handler, manifest, options) {
493
520
  const pluginOptions = getPluginOptions(options);
494
521
  const app = new Hono();
@@ -500,7 +527,7 @@ function createPlugin(handler, manifest, options) {
500
527
  throw new HTTPException(400, { message: "Content-Type must be application/json" });
501
528
  }
502
529
  const body = await ctx.req.json();
503
- const inputSchemaErrors = [...Value3.Errors(inputSchema, body)];
530
+ const inputSchemaErrors = [...Value4.Errors(inputSchema, body)];
504
531
  if (inputSchemaErrors.length) {
505
532
  console.dir(inputSchemaErrors, { depth: null });
506
533
  throw new HTTPException(400, { message: "Invalid body" });
@@ -509,13 +536,13 @@ function createPlugin(handler, manifest, options) {
509
536
  if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
510
537
  throw new HTTPException(400, { message: "Invalid signature" });
511
538
  }
512
- const inputs = Value3.Decode(inputSchema, body);
539
+ const inputs = Value4.Decode(inputSchema, body);
513
540
  let config2;
514
541
  if (pluginOptions.settingsSchema) {
515
542
  try {
516
- config2 = Value3.Decode(pluginOptions.settingsSchema, Value3.Default(pluginOptions.settingsSchema, inputs.settings));
543
+ config2 = Value4.Decode(pluginOptions.settingsSchema, Value4.Default(pluginOptions.settingsSchema, inputs.settings));
517
544
  } catch (e) {
518
- console.dir(...Value3.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
545
+ console.dir(...Value4.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
519
546
  throw e;
520
547
  }
521
548
  } else {
@@ -525,9 +552,9 @@ function createPlugin(handler, manifest, options) {
525
552
  const honoEnvironment = honoEnv(ctx);
526
553
  if (pluginOptions.envSchema) {
527
554
  try {
528
- env = Value3.Decode(pluginOptions.envSchema, Value3.Default(pluginOptions.envSchema, honoEnvironment));
555
+ env = Value4.Decode(pluginOptions.envSchema, Value4.Default(pluginOptions.envSchema, honoEnvironment));
529
556
  } catch (e) {
530
- console.dir(...Value3.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
557
+ console.dir(...Value4.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
531
558
  throw e;
532
559
  }
533
560
  } else {
@@ -535,17 +562,7 @@ function createPlugin(handler, manifest, options) {
535
562
  }
536
563
  const workerName = new URL(inputs.ref).hostname.split(".")[0];
537
564
  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
- }
565
+ const command = getCommand(inputs, pluginOptions);
549
566
  const context2 = {
550
567
  eventName: inputs.eventName,
551
568
  payload: inputs.eventPayload,
@@ -560,12 +577,7 @@ function createPlugin(handler, manifest, options) {
560
577
  const result = await handler(context2);
561
578
  return ctx.json({ stateId: inputs.stateId, output: result ?? {} });
562
579
  } 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" });
580
+ await handleError2(context2, pluginOptions, error);
569
581
  }
570
582
  });
571
583
  return app;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubiquity-os/plugin-sdk",
3
- "version": "3.1.10",
3
+ "version": "3.2.0",
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",