@ubiquity-os/plugin-sdk 3.1.8 → 3.1.10

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/dist/index.d.mts CHANGED
@@ -1,12 +1,12 @@
1
- import * as hono_types from 'hono/types';
2
1
  import { EmitterWebhookEventName, EmitterWebhookEvent } from '@octokit/webhooks';
3
- import { Hono } from 'hono';
4
2
  import * as _ubiquity_os_ubiquity_os_logger from '@ubiquity-os/ubiquity-os-logger';
5
3
  import { LogReturn, Metadata, Logs, LogLevel } from '@ubiquity-os/ubiquity-os-logger';
6
4
  import { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods';
7
5
  import { customOctokit } from './octokit.mjs';
8
- import { Manifest } from './manifest.mjs';
9
6
  import { TAnySchema } from '@sinclair/typebox';
7
+ import * as hono_types from 'hono/types';
8
+ import { Hono } from 'hono';
9
+ import { Manifest } from './manifest.mjs';
10
10
  import '@octokit/core/dist-types/types';
11
11
  import '@octokit/plugin-paginate-graphql';
12
12
  import '@octokit/plugin-paginate-rest';
@@ -95,7 +95,8 @@ declare class CommentHandler {
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: CommentOptions): Promise<string>;
98
+ createCommentBody(context: Context, message: LogReturn | Error, options?: Pick<CommentOptions, "raw">): Promise<string>;
99
+ private _createCommentBody;
99
100
  postComment(context: Context, message: LogReturn | Error, options?: CommentOptions): Promise<WithIssueNumber<PostedGithubComment> | null>;
100
101
  }
101
102
 
@@ -128,8 +129,8 @@ interface Options {
128
129
  bypassSignatureVerification?: boolean;
129
130
  }
130
131
 
131
- declare function createPlugin<TConfig = unknown, TEnv = unknown, TCommand = unknown, TSupportedEvents extends EmitterWebhookEventName = EmitterWebhookEventName>(handler: (context: Context<TConfig, TEnv, TCommand, TSupportedEvents>) => HandlerReturn, manifest: Manifest, options?: Options): Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
132
-
133
132
  declare function createActionsPlugin<TConfig = unknown, TEnv = unknown, TCommand = unknown, TSupportedEvents extends EmitterWebhookEventName = EmitterWebhookEventName>(handler: (context: Context<TConfig, TEnv, TCommand, TSupportedEvents>) => HandlerReturn, options?: Options): Promise<void>;
134
133
 
134
+ declare function createPlugin<TConfig = unknown, TEnv = unknown, TCommand = unknown, TSupportedEvents extends EmitterWebhookEventName = EmitterWebhookEventName>(handler: (context: Context<TConfig, TEnv, TCommand, TSupportedEvents>) => HandlerReturn, manifest: Manifest, options?: Options): Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
135
+
135
136
  export { CommentHandler, type Context, type Options, createActionsPlugin, createPlugin };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import * as hono_types from 'hono/types';
2
1
  import { EmitterWebhookEventName, EmitterWebhookEvent } from '@octokit/webhooks';
3
- import { Hono } from 'hono';
4
2
  import * as _ubiquity_os_ubiquity_os_logger from '@ubiquity-os/ubiquity-os-logger';
5
3
  import { LogReturn, Metadata, Logs, LogLevel } from '@ubiquity-os/ubiquity-os-logger';
6
4
  import { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods';
7
5
  import { customOctokit } from './octokit.js';
8
- import { Manifest } from './manifest.js';
9
6
  import { TAnySchema } from '@sinclair/typebox';
7
+ import * as hono_types from 'hono/types';
8
+ import { Hono } from 'hono';
9
+ import { Manifest } from './manifest.js';
10
10
  import '@octokit/core/dist-types/types';
11
11
  import '@octokit/plugin-paginate-graphql';
12
12
  import '@octokit/plugin-paginate-rest';
@@ -95,7 +95,8 @@ declare class CommentHandler {
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: CommentOptions): Promise<string>;
98
+ createCommentBody(context: Context, message: LogReturn | Error, options?: Pick<CommentOptions, "raw">): Promise<string>;
99
+ private _createCommentBody;
99
100
  postComment(context: Context, message: LogReturn | Error, options?: CommentOptions): Promise<WithIssueNumber<PostedGithubComment> | null>;
100
101
  }
101
102
 
@@ -128,8 +129,8 @@ interface Options {
128
129
  bypassSignatureVerification?: boolean;
129
130
  }
130
131
 
131
- declare function createPlugin<TConfig = unknown, TEnv = unknown, TCommand = unknown, TSupportedEvents extends EmitterWebhookEventName = EmitterWebhookEventName>(handler: (context: Context<TConfig, TEnv, TCommand, TSupportedEvents>) => HandlerReturn, manifest: Manifest, options?: Options): Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
132
-
133
132
  declare function createActionsPlugin<TConfig = unknown, TEnv = unknown, TCommand = unknown, TSupportedEvents extends EmitterWebhookEventName = EmitterWebhookEventName>(handler: (context: Context<TConfig, TEnv, TCommand, TSupportedEvents>) => HandlerReturn, options?: Options): Promise<void>;
134
133
 
134
+ declare function createPlugin<TConfig = unknown, TEnv = unknown, TCommand = unknown, TSupportedEvents extends EmitterWebhookEventName = EmitterWebhookEventName>(handler: (context: Context<TConfig, TEnv, TCommand, TSupportedEvents>) => HandlerReturn, manifest: Manifest, options?: Options): Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
135
+
135
136
  export { CommentHandler, type Context, type Options, createActionsPlugin, createPlugin };
package/dist/index.js CHANGED
@@ -36,12 +36,12 @@ __export(src_exports, {
36
36
  });
37
37
  module.exports = __toCommonJS(src_exports);
38
38
 
39
- // src/server.ts
39
+ // src/actions.ts
40
+ var core = __toESM(require("@actions/core"));
41
+ var github2 = __toESM(require("@actions/github"));
40
42
  var import_value2 = require("@sinclair/typebox/value");
41
43
  var import_ubiquity_os_logger3 = require("@ubiquity-os/ubiquity-os-logger");
42
- var import_hono = require("hono");
43
- var import_adapter2 = require("hono/adapter");
44
- var import_http_exception = require("hono/http-exception");
44
+ var import_dotenv = require("dotenv");
45
45
 
46
46
  // src/helpers/runtime-info.ts
47
47
  var import_github = __toESM(require("@actions/github"));
@@ -274,11 +274,17 @@ var CommentHandler = class _CommentHandler {
274
274
  const metadataHidden = [header, jsonPretty, "-->"].join("\n");
275
275
  return logMessage?.type === "fatal" ? [metadataVisible, metadataHidden].join("\n") : metadataHidden;
276
276
  }
277
+ /*
278
+ * Creates the body for the comment, embeds the metadata and the header hidden in the body as well.
279
+ */
280
+ async createCommentBody(context2, message, options) {
281
+ return this._createCommentBody(context2, message, options);
282
+ }
277
283
  async _createCommentBody(context2, message, options) {
278
284
  const { metadata, logMessage } = await this._processMessage(context2, message);
279
285
  const { header, jsonPretty } = await this._createMetadataContent(context2, metadata);
280
286
  const metadataContent = this._formatMetadataContent(logMessage, header, jsonPretty);
281
- return `${options.raw ? logMessage?.raw : logMessage?.diff}
287
+ return `${options?.raw ? logMessage?.raw : logMessage?.diff}
282
288
 
283
289
  ${metadataContent}
284
290
  `;
@@ -331,11 +337,11 @@ function transformError(context2, error) {
331
337
 
332
338
  // src/octokit.ts
333
339
  var import_core = require("@octokit/core");
340
+ var import_plugin_paginate_graphql = require("@octokit/plugin-paginate-graphql");
334
341
  var import_plugin_paginate_rest = require("@octokit/plugin-paginate-rest");
335
342
  var import_plugin_rest_endpoint_methods = require("@octokit/plugin-rest-endpoint-methods");
336
343
  var import_plugin_retry = require("@octokit/plugin-retry");
337
344
  var import_plugin_throttling = require("@octokit/plugin-throttling");
338
- var import_plugin_paginate_graphql = require("@octokit/plugin-paginate-graphql");
339
345
  var defaultOptions = {
340
346
  throttle: {
341
347
  onAbuseLimit: (retryAfter, options, octokit) => {
@@ -418,95 +424,7 @@ var inputSchema = import_typebox3.Type.Object({
418
424
  signature: import_typebox3.Type.String()
419
425
  });
420
426
 
421
- // src/server.ts
422
- function createPlugin(handler, manifest, options) {
423
- const pluginOptions = getPluginOptions(options);
424
- const app = new import_hono.Hono();
425
- app.get("/manifest.json", (ctx) => {
426
- return ctx.json(manifest);
427
- });
428
- app.post("/", async function appPost(ctx) {
429
- if (ctx.req.header("content-type") !== "application/json") {
430
- throw new import_http_exception.HTTPException(400, { message: "Content-Type must be application/json" });
431
- }
432
- const body = await ctx.req.json();
433
- const inputSchemaErrors = [...import_value2.Value.Errors(inputSchema, body)];
434
- if (inputSchemaErrors.length) {
435
- console.dir(inputSchemaErrors, { depth: null });
436
- throw new import_http_exception.HTTPException(400, { message: "Invalid body" });
437
- }
438
- const signature = body.signature;
439
- if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
440
- throw new import_http_exception.HTTPException(400, { message: "Invalid signature" });
441
- }
442
- const inputs = import_value2.Value.Decode(inputSchema, body);
443
- let config2;
444
- if (pluginOptions.settingsSchema) {
445
- try {
446
- config2 = import_value2.Value.Decode(pluginOptions.settingsSchema, import_value2.Value.Default(pluginOptions.settingsSchema, inputs.settings));
447
- } catch (e) {
448
- console.dir(...import_value2.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
449
- throw e;
450
- }
451
- } else {
452
- config2 = inputs.settings;
453
- }
454
- let env;
455
- const honoEnvironment = (0, import_adapter2.env)(ctx);
456
- if (pluginOptions.envSchema) {
457
- try {
458
- env = import_value2.Value.Decode(pluginOptions.envSchema, import_value2.Value.Default(pluginOptions.envSchema, honoEnvironment));
459
- } catch (e) {
460
- console.dir(...import_value2.Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
461
- throw e;
462
- }
463
- } else {
464
- env = ctx.env;
465
- }
466
- const workerName = new URL(inputs.ref).hostname.split(".")[0];
467
- PluginRuntimeInfo.getInstance({ ...env, CLOUDFLARE_WORKER_NAME: workerName });
468
- let command = null;
469
- if (inputs.command && pluginOptions.commandSchema) {
470
- try {
471
- command = import_value2.Value.Decode(pluginOptions.commandSchema, import_value2.Value.Default(pluginOptions.commandSchema, inputs.command));
472
- } catch (e) {
473
- console.log(...import_value2.Value.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
474
- throw e;
475
- }
476
- } else if (inputs.command) {
477
- command = inputs.command;
478
- }
479
- const context2 = {
480
- eventName: inputs.eventName,
481
- payload: inputs.eventPayload,
482
- command,
483
- octokit: new customOctokit({ auth: inputs.authToken }),
484
- config: config2,
485
- env,
486
- logger: new import_ubiquity_os_logger3.Logs(pluginOptions.logLevel),
487
- commentHandler: new CommentHandler()
488
- };
489
- try {
490
- const result = await handler(context2);
491
- return ctx.json({ stateId: inputs.stateId, output: result ?? {} });
492
- } catch (error) {
493
- console.error(error);
494
- const loggerError = transformError(context2, error);
495
- if (pluginOptions.postCommentOnError && loggerError) {
496
- await context2.commentHandler.postComment(context2, loggerError);
497
- }
498
- throw new import_http_exception.HTTPException(500, { message: "Unexpected error" });
499
- }
500
- });
501
- return app;
502
- }
503
-
504
427
  // src/actions.ts
505
- var core = __toESM(require("@actions/core"));
506
- var github2 = __toESM(require("@actions/github"));
507
- var import_value3 = require("@sinclair/typebox/value");
508
- var import_ubiquity_os_logger4 = require("@ubiquity-os/ubiquity-os-logger");
509
- var import_dotenv = require("dotenv");
510
428
  (0, import_dotenv.config)();
511
429
  async function createActionsPlugin(handler, options) {
512
430
  const pluginOptions = getPluginOptions(options);
@@ -516,7 +434,7 @@ async function createActionsPlugin(handler, options) {
516
434
  return;
517
435
  }
518
436
  const body = github2.context.payload.inputs;
519
- const inputSchemaErrors = [...import_value3.Value.Errors(inputSchema, body)];
437
+ const inputSchemaErrors = [...import_value2.Value.Errors(inputSchema, body)];
520
438
  if (inputSchemaErrors.length) {
521
439
  console.dir(inputSchemaErrors, { depth: null });
522
440
  core.setFailed(`Error: Invalid inputs payload: ${inputSchemaErrors.map((o) => o.message).join(", ")}`);
@@ -527,13 +445,13 @@ async function createActionsPlugin(handler, options) {
527
445
  core.setFailed(`Error: Invalid signature`);
528
446
  return;
529
447
  }
530
- const inputs = import_value3.Value.Decode(inputSchema, body);
448
+ const inputs = import_value2.Value.Decode(inputSchema, body);
531
449
  let config2;
532
450
  if (pluginOptions.settingsSchema) {
533
451
  try {
534
- config2 = import_value3.Value.Decode(pluginOptions.settingsSchema, import_value3.Value.Default(pluginOptions.settingsSchema, inputs.settings));
452
+ config2 = import_value2.Value.Decode(pluginOptions.settingsSchema, import_value2.Value.Default(pluginOptions.settingsSchema, inputs.settings));
535
453
  } catch (e) {
536
- console.dir(...import_value3.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
454
+ console.dir(...import_value2.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
537
455
  core.setFailed(`Error: Invalid settings provided.`);
538
456
  throw e;
539
457
  }
@@ -543,9 +461,9 @@ async function createActionsPlugin(handler, options) {
543
461
  let env;
544
462
  if (pluginOptions.envSchema) {
545
463
  try {
546
- env = import_value3.Value.Decode(pluginOptions.envSchema, import_value3.Value.Default(pluginOptions.envSchema, process.env));
464
+ env = import_value2.Value.Decode(pluginOptions.envSchema, import_value2.Value.Default(pluginOptions.envSchema, process.env));
547
465
  } catch (e) {
548
- console.dir(...import_value3.Value.Errors(pluginOptions.envSchema, process.env), { depth: null });
466
+ console.dir(...import_value2.Value.Errors(pluginOptions.envSchema, process.env), { depth: null });
549
467
  core.setFailed(`Error: Invalid environment provided.`);
550
468
  throw e;
551
469
  }
@@ -555,9 +473,9 @@ async function createActionsPlugin(handler, options) {
555
473
  let command = null;
556
474
  if (inputs.command && pluginOptions.commandSchema) {
557
475
  try {
558
- command = import_value3.Value.Decode(pluginOptions.commandSchema, import_value3.Value.Default(pluginOptions.commandSchema, inputs.command));
476
+ command = import_value2.Value.Decode(pluginOptions.commandSchema, import_value2.Value.Default(pluginOptions.commandSchema, inputs.command));
559
477
  } catch (e) {
560
- console.dir(...import_value3.Value.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
478
+ console.dir(...import_value2.Value.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
561
479
  throw e;
562
480
  }
563
481
  } else if (inputs.command) {
@@ -570,7 +488,7 @@ async function createActionsPlugin(handler, options) {
570
488
  octokit: new customOctokit({ auth: inputs.authToken }),
571
489
  config: config2,
572
490
  env,
573
- logger: new import_ubiquity_os_logger4.Logs(pluginOptions.logLevel),
491
+ logger: new import_ubiquity_os_logger3.Logs(pluginOptions.logLevel),
574
492
  commentHandler: new CommentHandler()
575
493
  };
576
494
  try {
@@ -580,7 +498,7 @@ async function createActionsPlugin(handler, options) {
580
498
  } catch (error) {
581
499
  console.error(error);
582
500
  const loggerError = transformError(context2, error);
583
- if (loggerError instanceof import_ubiquity_os_logger4.LogReturn) {
501
+ if (loggerError instanceof import_ubiquity_os_logger3.LogReturn) {
584
502
  core.setFailed(loggerError.logMessage.diff);
585
503
  } else if (loggerError instanceof Error) {
586
504
  core.setFailed(loggerError);
@@ -602,6 +520,94 @@ async function returnDataToKernel(repoToken, stateId, output) {
602
520
  }
603
521
  });
604
522
  }
523
+
524
+ // src/server.ts
525
+ var import_value3 = require("@sinclair/typebox/value");
526
+ var import_ubiquity_os_logger4 = require("@ubiquity-os/ubiquity-os-logger");
527
+ var import_hono = require("hono");
528
+ var import_adapter2 = require("hono/adapter");
529
+ var import_http_exception = require("hono/http-exception");
530
+ function createPlugin(handler, manifest, options) {
531
+ const pluginOptions = getPluginOptions(options);
532
+ const app = new import_hono.Hono();
533
+ app.get("/manifest.json", (ctx) => {
534
+ return ctx.json(manifest);
535
+ });
536
+ app.post("/", async function appPost(ctx) {
537
+ if (ctx.req.header("content-type") !== "application/json") {
538
+ throw new import_http_exception.HTTPException(400, { message: "Content-Type must be application/json" });
539
+ }
540
+ const body = await ctx.req.json();
541
+ const inputSchemaErrors = [...import_value3.Value.Errors(inputSchema, body)];
542
+ if (inputSchemaErrors.length) {
543
+ console.dir(inputSchemaErrors, { depth: null });
544
+ throw new import_http_exception.HTTPException(400, { message: "Invalid body" });
545
+ }
546
+ const signature = body.signature;
547
+ if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
548
+ throw new import_http_exception.HTTPException(400, { message: "Invalid signature" });
549
+ }
550
+ const inputs = import_value3.Value.Decode(inputSchema, body);
551
+ let config2;
552
+ if (pluginOptions.settingsSchema) {
553
+ try {
554
+ config2 = import_value3.Value.Decode(pluginOptions.settingsSchema, import_value3.Value.Default(pluginOptions.settingsSchema, inputs.settings));
555
+ } catch (e) {
556
+ console.dir(...import_value3.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
557
+ throw e;
558
+ }
559
+ } else {
560
+ config2 = inputs.settings;
561
+ }
562
+ let env;
563
+ const honoEnvironment = (0, import_adapter2.env)(ctx);
564
+ if (pluginOptions.envSchema) {
565
+ try {
566
+ env = import_value3.Value.Decode(pluginOptions.envSchema, import_value3.Value.Default(pluginOptions.envSchema, honoEnvironment));
567
+ } catch (e) {
568
+ console.dir(...import_value3.Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
569
+ throw e;
570
+ }
571
+ } else {
572
+ env = ctx.env;
573
+ }
574
+ const workerName = new URL(inputs.ref).hostname.split(".")[0];
575
+ 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
+ }
587
+ const context2 = {
588
+ eventName: inputs.eventName,
589
+ payload: inputs.eventPayload,
590
+ command,
591
+ octokit: new customOctokit({ auth: inputs.authToken }),
592
+ config: config2,
593
+ env,
594
+ logger: new import_ubiquity_os_logger4.Logs(pluginOptions.logLevel),
595
+ commentHandler: new CommentHandler()
596
+ };
597
+ try {
598
+ const result = await handler(context2);
599
+ return ctx.json({ stateId: inputs.stateId, output: result ?? {} });
600
+ } 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" });
607
+ }
608
+ });
609
+ return app;
610
+ }
605
611
  // Annotate the CommonJS export names for ESM import in node:
606
612
  0 && (module.exports = {
607
613
  CommentHandler,
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
- // src/server.ts
1
+ // src/actions.ts
2
+ import * as core from "@actions/core";
3
+ import * as github2 from "@actions/github";
2
4
  import { Value as Value2 } from "@sinclair/typebox/value";
3
- import { Logs } from "@ubiquity-os/ubiquity-os-logger";
4
- import { Hono } from "hono";
5
- import { env as honoEnv } from "hono/adapter";
6
- import { HTTPException } from "hono/http-exception";
5
+ import { LogReturn as LogReturn3, Logs } from "@ubiquity-os/ubiquity-os-logger";
6
+ import { config } from "dotenv";
7
7
 
8
8
  // src/helpers/runtime-info.ts
9
9
  import github from "@actions/github";
@@ -236,11 +236,17 @@ var CommentHandler = class _CommentHandler {
236
236
  const metadataHidden = [header, jsonPretty, "-->"].join("\n");
237
237
  return logMessage?.type === "fatal" ? [metadataVisible, metadataHidden].join("\n") : metadataHidden;
238
238
  }
239
+ /*
240
+ * Creates the body for the comment, embeds the metadata and the header hidden in the body as well.
241
+ */
242
+ async createCommentBody(context2, message, options) {
243
+ return this._createCommentBody(context2, message, options);
244
+ }
239
245
  async _createCommentBody(context2, message, options) {
240
246
  const { metadata, logMessage } = await this._processMessage(context2, message);
241
247
  const { header, jsonPretty } = await this._createMetadataContent(context2, metadata);
242
248
  const metadataContent = this._formatMetadataContent(logMessage, header, jsonPretty);
243
- return `${options.raw ? logMessage?.raw : logMessage?.diff}
249
+ return `${options?.raw ? logMessage?.raw : logMessage?.diff}
244
250
 
245
251
  ${metadataContent}
246
252
  `;
@@ -293,11 +299,11 @@ function transformError(context2, error) {
293
299
 
294
300
  // src/octokit.ts
295
301
  import { Octokit } from "@octokit/core";
302
+ import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
296
303
  import { paginateRest } from "@octokit/plugin-paginate-rest";
297
304
  import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
298
305
  import { retry } from "@octokit/plugin-retry";
299
306
  import { throttling } from "@octokit/plugin-throttling";
300
- import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
301
307
  var defaultOptions = {
302
308
  throttle: {
303
309
  onAbuseLimit: (retryAfter, options, octokit) => {
@@ -380,95 +386,7 @@ var inputSchema = T2.Object({
380
386
  signature: T2.String()
381
387
  });
382
388
 
383
- // src/server.ts
384
- function createPlugin(handler, manifest, options) {
385
- const pluginOptions = getPluginOptions(options);
386
- const app = new Hono();
387
- app.get("/manifest.json", (ctx) => {
388
- return ctx.json(manifest);
389
- });
390
- app.post("/", async function appPost(ctx) {
391
- if (ctx.req.header("content-type") !== "application/json") {
392
- throw new HTTPException(400, { message: "Content-Type must be application/json" });
393
- }
394
- const body = await ctx.req.json();
395
- const inputSchemaErrors = [...Value2.Errors(inputSchema, body)];
396
- if (inputSchemaErrors.length) {
397
- console.dir(inputSchemaErrors, { depth: null });
398
- throw new HTTPException(400, { message: "Invalid body" });
399
- }
400
- const signature = body.signature;
401
- if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
402
- throw new HTTPException(400, { message: "Invalid signature" });
403
- }
404
- const inputs = Value2.Decode(inputSchema, body);
405
- let config2;
406
- if (pluginOptions.settingsSchema) {
407
- try {
408
- config2 = Value2.Decode(pluginOptions.settingsSchema, Value2.Default(pluginOptions.settingsSchema, inputs.settings));
409
- } catch (e) {
410
- console.dir(...Value2.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
411
- throw e;
412
- }
413
- } else {
414
- config2 = inputs.settings;
415
- }
416
- let env;
417
- const honoEnvironment = honoEnv(ctx);
418
- if (pluginOptions.envSchema) {
419
- try {
420
- env = Value2.Decode(pluginOptions.envSchema, Value2.Default(pluginOptions.envSchema, honoEnvironment));
421
- } catch (e) {
422
- console.dir(...Value2.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
423
- throw e;
424
- }
425
- } else {
426
- env = ctx.env;
427
- }
428
- const workerName = new URL(inputs.ref).hostname.split(".")[0];
429
- PluginRuntimeInfo.getInstance({ ...env, CLOUDFLARE_WORKER_NAME: workerName });
430
- let command = null;
431
- if (inputs.command && pluginOptions.commandSchema) {
432
- try {
433
- command = Value2.Decode(pluginOptions.commandSchema, Value2.Default(pluginOptions.commandSchema, inputs.command));
434
- } catch (e) {
435
- console.log(...Value2.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
436
- throw e;
437
- }
438
- } else if (inputs.command) {
439
- command = inputs.command;
440
- }
441
- const context2 = {
442
- eventName: inputs.eventName,
443
- payload: inputs.eventPayload,
444
- command,
445
- octokit: new customOctokit({ auth: inputs.authToken }),
446
- config: config2,
447
- env,
448
- logger: new Logs(pluginOptions.logLevel),
449
- commentHandler: new CommentHandler()
450
- };
451
- try {
452
- const result = await handler(context2);
453
- return ctx.json({ stateId: inputs.stateId, output: result ?? {} });
454
- } catch (error) {
455
- console.error(error);
456
- const loggerError = transformError(context2, error);
457
- if (pluginOptions.postCommentOnError && loggerError) {
458
- await context2.commentHandler.postComment(context2, loggerError);
459
- }
460
- throw new HTTPException(500, { message: "Unexpected error" });
461
- }
462
- });
463
- return app;
464
- }
465
-
466
389
  // src/actions.ts
467
- import * as core from "@actions/core";
468
- import * as github2 from "@actions/github";
469
- import { Value as Value3 } from "@sinclair/typebox/value";
470
- import { LogReturn as LogReturn3, Logs as Logs2 } from "@ubiquity-os/ubiquity-os-logger";
471
- import { config } from "dotenv";
472
390
  config();
473
391
  async function createActionsPlugin(handler, options) {
474
392
  const pluginOptions = getPluginOptions(options);
@@ -478,7 +396,7 @@ async function createActionsPlugin(handler, options) {
478
396
  return;
479
397
  }
480
398
  const body = github2.context.payload.inputs;
481
- const inputSchemaErrors = [...Value3.Errors(inputSchema, body)];
399
+ const inputSchemaErrors = [...Value2.Errors(inputSchema, body)];
482
400
  if (inputSchemaErrors.length) {
483
401
  console.dir(inputSchemaErrors, { depth: null });
484
402
  core.setFailed(`Error: Invalid inputs payload: ${inputSchemaErrors.map((o) => o.message).join(", ")}`);
@@ -489,13 +407,13 @@ async function createActionsPlugin(handler, options) {
489
407
  core.setFailed(`Error: Invalid signature`);
490
408
  return;
491
409
  }
492
- const inputs = Value3.Decode(inputSchema, body);
410
+ const inputs = Value2.Decode(inputSchema, body);
493
411
  let config2;
494
412
  if (pluginOptions.settingsSchema) {
495
413
  try {
496
- config2 = Value3.Decode(pluginOptions.settingsSchema, Value3.Default(pluginOptions.settingsSchema, inputs.settings));
414
+ config2 = Value2.Decode(pluginOptions.settingsSchema, Value2.Default(pluginOptions.settingsSchema, inputs.settings));
497
415
  } catch (e) {
498
- console.dir(...Value3.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
416
+ console.dir(...Value2.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
499
417
  core.setFailed(`Error: Invalid settings provided.`);
500
418
  throw e;
501
419
  }
@@ -505,9 +423,9 @@ async function createActionsPlugin(handler, options) {
505
423
  let env;
506
424
  if (pluginOptions.envSchema) {
507
425
  try {
508
- env = Value3.Decode(pluginOptions.envSchema, Value3.Default(pluginOptions.envSchema, process.env));
426
+ env = Value2.Decode(pluginOptions.envSchema, Value2.Default(pluginOptions.envSchema, process.env));
509
427
  } catch (e) {
510
- console.dir(...Value3.Errors(pluginOptions.envSchema, process.env), { depth: null });
428
+ console.dir(...Value2.Errors(pluginOptions.envSchema, process.env), { depth: null });
511
429
  core.setFailed(`Error: Invalid environment provided.`);
512
430
  throw e;
513
431
  }
@@ -517,9 +435,9 @@ async function createActionsPlugin(handler, options) {
517
435
  let command = null;
518
436
  if (inputs.command && pluginOptions.commandSchema) {
519
437
  try {
520
- command = Value3.Decode(pluginOptions.commandSchema, Value3.Default(pluginOptions.commandSchema, inputs.command));
438
+ command = Value2.Decode(pluginOptions.commandSchema, Value2.Default(pluginOptions.commandSchema, inputs.command));
521
439
  } catch (e) {
522
- console.dir(...Value3.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
440
+ console.dir(...Value2.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
523
441
  throw e;
524
442
  }
525
443
  } else if (inputs.command) {
@@ -532,7 +450,7 @@ async function createActionsPlugin(handler, options) {
532
450
  octokit: new customOctokit({ auth: inputs.authToken }),
533
451
  config: config2,
534
452
  env,
535
- logger: new Logs2(pluginOptions.logLevel),
453
+ logger: new Logs(pluginOptions.logLevel),
536
454
  commentHandler: new CommentHandler()
537
455
  };
538
456
  try {
@@ -564,6 +482,94 @@ async function returnDataToKernel(repoToken, stateId, output) {
564
482
  }
565
483
  });
566
484
  }
485
+
486
+ // src/server.ts
487
+ import { Value as Value3 } from "@sinclair/typebox/value";
488
+ import { Logs as Logs2 } from "@ubiquity-os/ubiquity-os-logger";
489
+ import { Hono } from "hono";
490
+ import { env as honoEnv } from "hono/adapter";
491
+ import { HTTPException } from "hono/http-exception";
492
+ function createPlugin(handler, manifest, options) {
493
+ const pluginOptions = getPluginOptions(options);
494
+ const app = new Hono();
495
+ app.get("/manifest.json", (ctx) => {
496
+ return ctx.json(manifest);
497
+ });
498
+ app.post("/", async function appPost(ctx) {
499
+ if (ctx.req.header("content-type") !== "application/json") {
500
+ throw new HTTPException(400, { message: "Content-Type must be application/json" });
501
+ }
502
+ const body = await ctx.req.json();
503
+ const inputSchemaErrors = [...Value3.Errors(inputSchema, body)];
504
+ if (inputSchemaErrors.length) {
505
+ console.dir(inputSchemaErrors, { depth: null });
506
+ throw new HTTPException(400, { message: "Invalid body" });
507
+ }
508
+ const signature = body.signature;
509
+ if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
510
+ throw new HTTPException(400, { message: "Invalid signature" });
511
+ }
512
+ const inputs = Value3.Decode(inputSchema, body);
513
+ let config2;
514
+ if (pluginOptions.settingsSchema) {
515
+ try {
516
+ config2 = Value3.Decode(pluginOptions.settingsSchema, Value3.Default(pluginOptions.settingsSchema, inputs.settings));
517
+ } catch (e) {
518
+ console.dir(...Value3.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
519
+ throw e;
520
+ }
521
+ } else {
522
+ config2 = inputs.settings;
523
+ }
524
+ let env;
525
+ const honoEnvironment = honoEnv(ctx);
526
+ if (pluginOptions.envSchema) {
527
+ try {
528
+ env = Value3.Decode(pluginOptions.envSchema, Value3.Default(pluginOptions.envSchema, honoEnvironment));
529
+ } catch (e) {
530
+ console.dir(...Value3.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
531
+ throw e;
532
+ }
533
+ } else {
534
+ env = ctx.env;
535
+ }
536
+ const workerName = new URL(inputs.ref).hostname.split(".")[0];
537
+ 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
+ }
549
+ const context2 = {
550
+ eventName: inputs.eventName,
551
+ payload: inputs.eventPayload,
552
+ command,
553
+ octokit: new customOctokit({ auth: inputs.authToken }),
554
+ config: config2,
555
+ env,
556
+ logger: new Logs2(pluginOptions.logLevel),
557
+ commentHandler: new CommentHandler()
558
+ };
559
+ try {
560
+ const result = await handler(context2);
561
+ return ctx.json({ stateId: inputs.stateId, output: result ?? {} });
562
+ } 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" });
569
+ }
570
+ });
571
+ return app;
572
+ }
567
573
  export {
568
574
  CommentHandler,
569
575
  createActionsPlugin,
@@ -1,6 +1,7 @@
1
1
  import * as _octokit_core_dist_types_types from '@octokit/core/dist-types/types';
2
2
  import * as _octokit_plugin_paginate_graphql from '@octokit/plugin-paginate-graphql';
3
3
  import * as _octokit_plugin_rest_endpoint_methods from '@octokit/plugin-rest-endpoint-methods';
4
+ export { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods';
4
5
  import * as _octokit_plugin_paginate_rest from '@octokit/plugin-paginate-rest';
5
6
  import * as _octokit_request_error from '@octokit/request-error';
6
7
  import { Octokit } from '@octokit/core';
package/dist/octokit.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as _octokit_core_dist_types_types from '@octokit/core/dist-types/types';
2
2
  import * as _octokit_plugin_paginate_graphql from '@octokit/plugin-paginate-graphql';
3
3
  import * as _octokit_plugin_rest_endpoint_methods from '@octokit/plugin-rest-endpoint-methods';
4
+ export { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods';
4
5
  import * as _octokit_plugin_paginate_rest from '@octokit/plugin-paginate-rest';
5
6
  import * as _octokit_request_error from '@octokit/request-error';
6
7
  import { Octokit } from '@octokit/core';
package/dist/octokit.js CHANGED
@@ -24,11 +24,11 @@ __export(octokit_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(octokit_exports);
26
26
  var import_core = require("@octokit/core");
27
+ var import_plugin_paginate_graphql = require("@octokit/plugin-paginate-graphql");
27
28
  var import_plugin_paginate_rest = require("@octokit/plugin-paginate-rest");
28
29
  var import_plugin_rest_endpoint_methods = require("@octokit/plugin-rest-endpoint-methods");
29
30
  var import_plugin_retry = require("@octokit/plugin-retry");
30
31
  var import_plugin_throttling = require("@octokit/plugin-throttling");
31
- var import_plugin_paginate_graphql = require("@octokit/plugin-paginate-graphql");
32
32
  var defaultOptions = {
33
33
  throttle: {
34
34
  onAbuseLimit: (retryAfter, options, octokit) => {
package/dist/octokit.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  // src/octokit.ts
2
2
  import { Octokit } from "@octokit/core";
3
+ import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
3
4
  import { paginateRest } from "@octokit/plugin-paginate-rest";
4
5
  import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
5
6
  import { retry } from "@octokit/plugin-retry";
6
7
  import { throttling } from "@octokit/plugin-throttling";
7
- import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
8
8
  var defaultOptions = {
9
9
  throttle: {
10
10
  onAbuseLimit: (retryAfter, options, octokit) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubiquity-os/plugin-sdk",
3
- "version": "3.1.8",
3
+ "version": "3.1.10",
4
4
  "description": "SDK for plugin support.",
5
5
  "author": "Ubiquity DAO",
6
6
  "license": "MIT",
@@ -92,7 +92,6 @@
92
92
  "@octokit/plugin-rest-endpoint-methods": "^13.3.1",
93
93
  "@octokit/plugin-retry": "^7.1.4",
94
94
  "@octokit/plugin-throttling": "^9.4.0",
95
- "@octokit/rest": "^21.1.1",
96
95
  "@octokit/types": "^13.8.0",
97
96
  "@octokit/webhooks": "^13.7.4",
98
97
  "@ubiquity-os/ubiquity-os-logger": "^1.4.0",
@@ -128,7 +127,6 @@
128
127
  "msw": "^2.6.3",
129
128
  "npm-run-all": "^4.1.5",
130
129
  "prettier": "^3.3.3",
131
- "simple-git": "^3.27.0",
132
130
  "ts-jest": "^29.2.5",
133
131
  "ts-node": "^10.9.2",
134
132
  "tsup": "^8.4.0",