@ubiquity-os/plugin-sdk 1.0.10 → 1.1.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/dist/constants.js CHANGED
@@ -1,3 +1,34 @@
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/constants.ts
21
+ var constants_exports = {};
22
+ __export(constants_exports, {
23
+ BOT_USER_ID: () => BOT_USER_ID,
24
+ CONFIG_FULL_PATH: () => CONFIG_FULL_PATH,
25
+ CONFIG_ORG_REPO: () => CONFIG_ORG_REPO,
26
+ DEV_CONFIG_FULL_PATH: () => DEV_CONFIG_FULL_PATH,
27
+ KERNEL_APP_ID: () => KERNEL_APP_ID,
28
+ KERNEL_PUBLIC_KEY: () => KERNEL_PUBLIC_KEY
29
+ });
30
+ module.exports = __toCommonJS(constants_exports);
31
+
1
32
  // src/types/config.ts
2
33
  var CONFIG_FULL_PATH = ".github/.ubiquity-os.config.yml";
3
34
  var DEV_CONFIG_FULL_PATH = ".github/.ubiquity-os.config.dev.yml";
@@ -16,11 +47,12 @@ JQIDAQAB
16
47
  `;
17
48
  var KERNEL_APP_ID = 975031;
18
49
  var BOT_USER_ID = 178941584;
19
- export {
50
+ // Annotate the CommonJS export names for ESM import in node:
51
+ 0 && (module.exports = {
20
52
  BOT_USER_ID,
21
53
  CONFIG_FULL_PATH,
22
54
  CONFIG_ORG_REPO,
23
55
  DEV_CONFIG_FULL_PATH,
24
56
  KERNEL_APP_ID,
25
57
  KERNEL_PUBLIC_KEY
26
- };
58
+ });
@@ -0,0 +1,26 @@
1
+ // src/types/config.ts
2
+ var CONFIG_FULL_PATH = ".github/.ubiquity-os.config.yml";
3
+ var DEV_CONFIG_FULL_PATH = ".github/.ubiquity-os.config.dev.yml";
4
+ var CONFIG_ORG_REPO = ".ubiquity-os";
5
+
6
+ // src/constants.ts
7
+ var KERNEL_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
8
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs96DOU+JqM8SyNXOB6u3
9
+ uBKIFiyrcST/LZTYN6y7LeJlyCuGPqSDrWCfjU9Ph5PLf9TWiNmeM8DGaOpwEFC7
10
+ U3NRxOSglo4plnQ5zRwIHHXvxyK400sQP2oISXymISuBQWjEIqkC9DybQrKwNzf+
11
+ I0JHWPqmwMIw26UvVOtXGOOWBqTkk+N2+/9f8eDIJP5QQVwwszc8s1rXOsLMlVIf
12
+ wShw7GO4E2jyK8TSJKpyjV8eb1JJMDwFhPiRrtZfQJUtDf2mV/67shQww61BH2Y/
13
+ Plnalo58kWIbkqZoq1yJrL5sFb73osM5+vADTXVn79bkvea7W19nSkdMiarYt4Hq
14
+ JQIDAQAB
15
+ -----END PUBLIC KEY-----
16
+ `;
17
+ var KERNEL_APP_ID = 975031;
18
+ var BOT_USER_ID = 178941584;
19
+ export {
20
+ BOT_USER_ID,
21
+ CONFIG_FULL_PATH,
22
+ CONFIG_ORG_REPO,
23
+ DEV_CONFIG_FULL_PATH,
24
+ KERNEL_APP_ID,
25
+ KERNEL_PUBLIC_KEY
26
+ };
@@ -0,0 +1,63 @@
1
+ import * as hono_types from 'hono/types';
2
+ import { EmitterWebhookEventName, EmitterWebhookEvent } from '@octokit/webhooks';
3
+ import { TAnySchema } from '@sinclair/typebox';
4
+ import { Logs, LogLevel, LogReturn } from '@ubiquity-os/ubiquity-os-logger';
5
+ import { Hono } from 'hono';
6
+ import { customOctokit } from './octokit.mjs';
7
+ import { Manifest } from './manifest.mjs';
8
+ import '@octokit/core/dist-types/types';
9
+ import '@octokit/plugin-paginate-graphql';
10
+ import '@octokit/plugin-rest-endpoint-methods';
11
+ import '@octokit/plugin-paginate-rest';
12
+ import '@octokit/request-error';
13
+ import '@octokit/core';
14
+
15
+ interface Context<TConfig = unknown, TEnv = unknown, TCommand = unknown, TSupportedEvents extends EmitterWebhookEventName = EmitterWebhookEventName> {
16
+ eventName: TSupportedEvents;
17
+ payload: {
18
+ [K in TSupportedEvents]: K extends EmitterWebhookEventName ? EmitterWebhookEvent<K> : never;
19
+ }[TSupportedEvents]["payload"];
20
+ command: TCommand | null;
21
+ octokit: InstanceType<typeof customOctokit>;
22
+ config: TConfig;
23
+ env: TEnv;
24
+ logger: Logs;
25
+ }
26
+
27
+ type Return = Record<string, unknown> | undefined | void;
28
+ type HandlerReturn = Promise<Return> | Return;
29
+
30
+ interface Options$1 {
31
+ kernelPublicKey?: string;
32
+ logLevel?: LogLevel;
33
+ postCommentOnError?: boolean;
34
+ settingsSchema?: TAnySchema;
35
+ envSchema?: TAnySchema;
36
+ commandSchema?: TAnySchema;
37
+ /**
38
+ * @deprecated This disables signature verification - only for local development
39
+ */
40
+ bypassSignatureVerification?: boolean;
41
+ }
42
+ 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$1): Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
43
+
44
+ interface Options {
45
+ logLevel?: LogLevel;
46
+ postCommentOnError?: boolean;
47
+ settingsSchema?: TAnySchema;
48
+ envSchema?: TAnySchema;
49
+ commandSchema?: TAnySchema;
50
+ kernelPublicKey?: string;
51
+ /**
52
+ * @deprecated This disables signature verification - only for local development
53
+ */
54
+ bypassSignatureVerification?: boolean;
55
+ }
56
+ 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>;
57
+
58
+ /**
59
+ * Posts a comment on a GitHub issue if the issue exists in the context payload, embedding structured metadata to it.
60
+ */
61
+ declare function postComment(context: Context, message: LogReturn): Promise<void>;
62
+
63
+ export { type Context, createActionsPlugin, createPlugin, postComment };
package/dist/index.d.ts CHANGED
@@ -3,51 +3,57 @@ import { EmitterWebhookEventName, EmitterWebhookEvent } from '@octokit/webhooks'
3
3
  import { TAnySchema } from '@sinclair/typebox';
4
4
  import { Logs, LogLevel, LogReturn } from '@ubiquity-os/ubiquity-os-logger';
5
5
  import { Hono } from 'hono';
6
- import * as _octokit_core_dist_types_types from '@octokit/core/dist-types/types';
7
- import * as _octokit_plugin_paginate_graphql from '@octokit/plugin-paginate-graphql';
8
- import * as _octokit_plugin_rest_endpoint_methods from '@octokit/plugin-rest-endpoint-methods';
9
- import * as _octokit_plugin_paginate_rest from '@octokit/plugin-paginate-rest';
10
- import * as _octokit_request_error from '@octokit/request-error';
11
- import { Octokit } from '@octokit/core';
6
+ import { customOctokit } from './octokit.js';
12
7
  import { Manifest } from './manifest.js';
8
+ import '@octokit/core/dist-types/types';
9
+ import '@octokit/plugin-paginate-graphql';
10
+ import '@octokit/plugin-rest-endpoint-methods';
11
+ import '@octokit/plugin-paginate-rest';
12
+ import '@octokit/request-error';
13
+ import '@octokit/core';
13
14
 
14
- declare const customOctokit: typeof Octokit & _octokit_core_dist_types_types.Constructor<{
15
- retry: {
16
- retryRequest: (error: _octokit_request_error.RequestError, retries: number, retryAfter: number) => _octokit_request_error.RequestError;
17
- };
18
- } & {
19
- paginate: _octokit_plugin_paginate_rest.PaginateInterface;
20
- } & _octokit_plugin_rest_endpoint_methods.Api & _octokit_plugin_paginate_graphql.paginateGraphQLInterface>;
21
-
22
- interface Context<TConfig = unknown, TEnv = unknown, TSupportedEvents extends EmitterWebhookEventName = EmitterWebhookEventName> {
15
+ interface Context<TConfig = unknown, TEnv = unknown, TCommand = unknown, TSupportedEvents extends EmitterWebhookEventName = EmitterWebhookEventName> {
23
16
  eventName: TSupportedEvents;
24
17
  payload: {
25
18
  [K in TSupportedEvents]: K extends EmitterWebhookEventName ? EmitterWebhookEvent<K> : never;
26
19
  }[TSupportedEvents]["payload"];
20
+ command: TCommand | null;
27
21
  octokit: InstanceType<typeof customOctokit>;
28
22
  config: TConfig;
29
23
  env: TEnv;
30
24
  logger: Logs;
31
25
  }
32
26
 
27
+ type Return = Record<string, unknown> | undefined | void;
28
+ type HandlerReturn = Promise<Return> | Return;
29
+
33
30
  interface Options$1 {
34
31
  kernelPublicKey?: string;
35
32
  logLevel?: LogLevel;
36
33
  postCommentOnError?: boolean;
37
34
  settingsSchema?: TAnySchema;
38
35
  envSchema?: TAnySchema;
36
+ commandSchema?: TAnySchema;
37
+ /**
38
+ * @deprecated This disables signature verification - only for local development
39
+ */
39
40
  bypassSignatureVerification?: boolean;
40
41
  }
41
- declare function createPlugin<TConfig = unknown, TEnv = unknown, TSupportedEvents extends EmitterWebhookEventName = EmitterWebhookEventName>(handler: (context: Context<TConfig, TEnv, TSupportedEvents>) => Promise<Record<string, unknown> | undefined>, manifest: Manifest, options?: Options$1): Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
42
+ 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$1): Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
42
43
 
43
44
  interface Options {
44
45
  logLevel?: LogLevel;
45
46
  postCommentOnError?: boolean;
46
47
  settingsSchema?: TAnySchema;
47
48
  envSchema?: TAnySchema;
49
+ commandSchema?: TAnySchema;
48
50
  kernelPublicKey?: string;
51
+ /**
52
+ * @deprecated This disables signature verification - only for local development
53
+ */
54
+ bypassSignatureVerification?: boolean;
49
55
  }
50
- declare function createActionsPlugin<TConfig = unknown, TEnv = unknown, TSupportedEvents extends EmitterWebhookEventName = EmitterWebhookEventName>(handler: (context: Context<TConfig, TEnv, TSupportedEvents>) => Promise<Record<string, unknown> | undefined>, options?: Options): Promise<void>;
56
+ 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>;
51
57
 
52
58
  /**
53
59
  * Posts a comment on a GitHub issue if the issue exists in the context payload, embedding structured metadata to it.
package/dist/index.js CHANGED
@@ -1,10 +1,48 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ createActionsPlugin: () => createActionsPlugin,
34
+ createPlugin: () => createPlugin,
35
+ postComment: () => postComment
36
+ });
37
+ module.exports = __toCommonJS(src_exports);
38
+
1
39
  // src/server.ts
2
- import { Type as T } from "@sinclair/typebox";
3
- import { Value } from "@sinclair/typebox/value";
4
- import { LOG_LEVEL, LogReturn, Logs } from "@ubiquity-os/ubiquity-os-logger";
5
- import { Hono } from "hono";
6
- import { env as honoEnv } from "hono/adapter";
7
- import { HTTPException } from "hono/http-exception";
40
+ var import_typebox = require("@sinclair/typebox");
41
+ var import_value = require("@sinclair/typebox/value");
42
+ var import_ubiquity_os_logger = require("@ubiquity-os/ubiquity-os-logger");
43
+ var import_hono = require("hono");
44
+ var import_adapter = require("hono/adapter");
45
+ var import_http_exception = require("hono/http-exception");
8
46
 
9
47
  // src/util.ts
10
48
  function sanitizeMetadata(obj) {
@@ -60,12 +98,12 @@ JQIDAQAB
60
98
  `;
61
99
 
62
100
  // src/octokit.ts
63
- import { Octokit } from "@octokit/core";
64
- import { paginateRest } from "@octokit/plugin-paginate-rest";
65
- import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
66
- import { retry } from "@octokit/plugin-retry";
67
- import { throttling } from "@octokit/plugin-throttling";
68
- import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
101
+ var import_core = require("@octokit/core");
102
+ var import_plugin_paginate_rest = require("@octokit/plugin-paginate-rest");
103
+ var import_plugin_rest_endpoint_methods = require("@octokit/plugin-rest-endpoint-methods");
104
+ var import_plugin_retry = require("@octokit/plugin-retry");
105
+ var import_plugin_throttling = require("@octokit/plugin-throttling");
106
+ var import_plugin_paginate_graphql = require("@octokit/plugin-paginate-graphql");
69
107
  var defaultOptions = {
70
108
  throttle: {
71
109
  onAbuseLimit: (retryAfter, options, octokit) => {
@@ -82,7 +120,7 @@ var defaultOptions = {
82
120
  }
83
121
  }
84
122
  };
85
- var customOctokit = Octokit.plugin(throttling, retry, paginateRest, restEndpointMethods, paginateGraphQL).defaults((instanceOptions) => {
123
+ var customOctokit = import_core.Octokit.plugin(import_plugin_throttling.throttling, import_plugin_retry.retry, import_plugin_paginate_rest.paginateRest, import_plugin_rest_endpoint_methods.restEndpointMethods, import_plugin_paginate_graphql.paginateGraphQL).defaults((instanceOptions) => {
86
124
  return { ...defaultOptions, ...instanceOptions };
87
125
  });
88
126
 
@@ -95,7 +133,8 @@ async function verifySignature(publicKeyPem, inputs, signature) {
95
133
  eventPayload: inputs.eventPayload,
96
134
  settings: inputs.settings,
97
135
  authToken: inputs.authToken,
98
- ref: inputs.ref
136
+ ref: inputs.ref,
137
+ command: inputs.command
99
138
  };
100
139
  const pemContents = publicKeyPem.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").trim();
101
140
  const binaryDer = Uint8Array.from(atob(pemContents), (c) => c.charCodeAt(0));
@@ -119,88 +158,97 @@ async function verifySignature(publicKeyPem, inputs, signature) {
119
158
  }
120
159
 
121
160
  // src/server.ts
122
- var inputSchema = T.Object({
123
- stateId: T.String(),
124
- eventName: T.String(),
125
- eventPayload: T.Record(T.String(), T.Any()),
126
- authToken: T.String(),
127
- settings: T.Record(T.String(), T.Any()),
128
- ref: T.String(),
129
- signature: T.String(),
130
- bypassSignatureVerification: T.Optional(
131
- T.Boolean({
132
- default: false,
133
- description: "Bypass signature verification (caution: only use this if you know what you're doing)"
134
- })
135
- )
161
+ var inputSchema = import_typebox.Type.Object({
162
+ stateId: import_typebox.Type.String(),
163
+ eventName: import_typebox.Type.String(),
164
+ eventPayload: import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.Any()),
165
+ command: import_typebox.Type.Union([import_typebox.Type.Null(), import_typebox.Type.Object({ name: import_typebox.Type.String(), parameters: import_typebox.Type.Unknown() })]),
166
+ authToken: import_typebox.Type.String(),
167
+ settings: import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.Any()),
168
+ ref: import_typebox.Type.String(),
169
+ signature: import_typebox.Type.String()
136
170
  });
137
171
  function createPlugin(handler, manifest, options) {
138
172
  const pluginOptions = {
139
173
  kernelPublicKey: options?.kernelPublicKey ?? KERNEL_PUBLIC_KEY,
140
- logLevel: options?.logLevel ?? LOG_LEVEL.INFO,
174
+ logLevel: options?.logLevel ?? import_ubiquity_os_logger.LOG_LEVEL.INFO,
141
175
  postCommentOnError: options?.postCommentOnError ?? true,
142
176
  settingsSchema: options?.settingsSchema,
143
- envSchema: options?.envSchema
177
+ envSchema: options?.envSchema,
178
+ commandSchema: options?.commandSchema,
179
+ bypassSignatureVerification: options?.bypassSignatureVerification || false
144
180
  };
145
- const app = new Hono();
181
+ const app = new import_hono.Hono();
146
182
  app.get("/manifest.json", (ctx) => {
147
183
  return ctx.json(manifest);
148
184
  });
149
185
  app.post("/", async (ctx) => {
150
186
  if (ctx.req.header("content-type") !== "application/json") {
151
- throw new HTTPException(400, { message: "Content-Type must be application/json" });
187
+ throw new import_http_exception.HTTPException(400, { message: "Content-Type must be application/json" });
152
188
  }
153
189
  const body = await ctx.req.json();
154
- const inputSchemaErrors = [...Value.Errors(inputSchema, body)];
190
+ const inputSchemaErrors = [...import_value.Value.Errors(inputSchema, body)];
155
191
  if (inputSchemaErrors.length) {
156
- console.dir(inputSchemaErrors, { depth: null });
157
- throw new HTTPException(400, { message: "Invalid body" });
192
+ console.log(inputSchemaErrors, { depth: null });
193
+ throw new import_http_exception.HTTPException(400, { message: "Invalid body" });
158
194
  }
159
- const inputs = Value.Decode(inputSchema, body);
195
+ const inputs = import_value.Value.Decode(inputSchema, body);
160
196
  const signature = inputs.signature;
161
- if (!options?.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, inputs, signature)) {
162
- throw new HTTPException(400, { message: "Invalid signature" });
197
+ if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, inputs, signature)) {
198
+ throw new import_http_exception.HTTPException(400, { message: "Invalid signature" });
163
199
  }
164
200
  let config2;
165
201
  if (pluginOptions.settingsSchema) {
166
202
  try {
167
- config2 = Value.Decode(pluginOptions.settingsSchema, Value.Default(pluginOptions.settingsSchema, inputs.settings));
203
+ config2 = import_value.Value.Decode(pluginOptions.settingsSchema, import_value.Value.Default(pluginOptions.settingsSchema, inputs.settings));
168
204
  } catch (e) {
169
- console.dir(...Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
205
+ console.log(...import_value.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
170
206
  throw e;
171
207
  }
172
208
  } else {
173
209
  config2 = inputs.settings;
174
210
  }
175
211
  let env;
176
- const honoEnvironment = honoEnv(ctx);
212
+ const honoEnvironment = (0, import_adapter.env)(ctx);
177
213
  if (pluginOptions.envSchema) {
178
214
  try {
179
- env = Value.Decode(pluginOptions.envSchema, Value.Default(pluginOptions.envSchema, honoEnvironment));
215
+ env = import_value.Value.Decode(pluginOptions.envSchema, import_value.Value.Default(pluginOptions.envSchema, honoEnvironment));
180
216
  } catch (e) {
181
- console.dir(...Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
217
+ console.log(...import_value.Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
182
218
  throw e;
183
219
  }
184
220
  } else {
185
221
  env = ctx.env;
186
222
  }
223
+ let command = null;
224
+ if (inputs.command && pluginOptions.commandSchema) {
225
+ try {
226
+ command = import_value.Value.Decode(pluginOptions.commandSchema, import_value.Value.Default(pluginOptions.commandSchema, inputs.command));
227
+ } catch (e) {
228
+ console.log(...import_value.Value.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
229
+ throw e;
230
+ }
231
+ } else if (inputs.command) {
232
+ command = inputs.command;
233
+ }
187
234
  const context2 = {
188
235
  eventName: inputs.eventName,
189
236
  payload: inputs.eventPayload,
237
+ command,
190
238
  octokit: new customOctokit({ auth: inputs.authToken }),
191
239
  config: config2,
192
240
  env,
193
- logger: new Logs(pluginOptions.logLevel)
241
+ logger: new import_ubiquity_os_logger.Logs(pluginOptions.logLevel)
194
242
  };
195
243
  try {
196
244
  const result = await handler(context2);
197
- return ctx.json({ stateId: inputs.stateId, output: result });
245
+ return ctx.json({ stateId: inputs.stateId, output: result ?? {} });
198
246
  } catch (error) {
199
247
  console.error(error);
200
248
  let loggerError;
201
249
  if (error instanceof Error) {
202
250
  loggerError = context2.logger.error(`Error: ${error}`, { error });
203
- } else if (error instanceof LogReturn) {
251
+ } else if (error instanceof import_ubiquity_os_logger.LogReturn) {
204
252
  loggerError = error;
205
253
  } else {
206
254
  loggerError = context2.logger.error(`Error: ${error}`);
@@ -208,84 +256,116 @@ function createPlugin(handler, manifest, options) {
208
256
  if (pluginOptions.postCommentOnError && loggerError) {
209
257
  await postComment(context2, loggerError);
210
258
  }
211
- throw new HTTPException(500, { message: "Unexpected error" });
259
+ throw new import_http_exception.HTTPException(500, { message: "Unexpected error" });
212
260
  }
213
261
  });
214
262
  return app;
215
263
  }
216
264
 
217
265
  // src/actions.ts
218
- import * as core from "@actions/core";
219
- import * as github from "@actions/github";
220
- import { Type as T2 } from "@sinclair/typebox";
221
- import { Value as Value2 } from "@sinclair/typebox/value";
222
- import { LOG_LEVEL as LOG_LEVEL2, LogReturn as LogReturn2, Logs as Logs2 } from "@ubiquity-os/ubiquity-os-logger";
223
- import { config } from "dotenv";
224
- config();
225
- var inputSchema2 = T2.Object({
226
- stateId: T2.String(),
227
- eventName: T2.String(),
228
- eventPayload: T2.String(),
229
- authToken: T2.String(),
230
- settings: T2.String(),
231
- ref: T2.String(),
232
- signature: T2.String()
266
+ var core = __toESM(require("@actions/core"));
267
+ var github = __toESM(require("@actions/github"));
268
+ var import_typebox4 = require("@sinclair/typebox");
269
+ var import_value3 = require("@sinclair/typebox/value");
270
+ var import_ubiquity_os_logger2 = require("@ubiquity-os/ubiquity-os-logger");
271
+ var import_dotenv = require("dotenv");
272
+
273
+ // src/types/util.ts
274
+ var import_typebox2 = require("@sinclair/typebox");
275
+ var import_value2 = require("@sinclair/typebox/value");
276
+ function jsonType(type) {
277
+ return import_typebox2.Type.Transform(import_typebox2.Type.String()).Decode((value) => {
278
+ const parsed = JSON.parse(value);
279
+ return import_value2.Value.Decode(type, import_value2.Value.Default(type, parsed));
280
+ }).Encode((value) => JSON.stringify(value));
281
+ }
282
+
283
+ // src/types/command.ts
284
+ var import_typebox3 = require("@sinclair/typebox");
285
+ var commandCallSchema = import_typebox3.Type.Union([import_typebox3.Type.Null(), import_typebox3.Type.Object({ name: import_typebox3.Type.String(), parameters: import_typebox3.Type.Unknown() })]);
286
+
287
+ // src/actions.ts
288
+ (0, import_dotenv.config)();
289
+ var inputSchema2 = import_typebox4.Type.Object({
290
+ stateId: import_typebox4.Type.String(),
291
+ eventName: import_typebox4.Type.String(),
292
+ eventPayload: jsonType(import_typebox4.Type.Record(import_typebox4.Type.String(), import_typebox4.Type.Any())),
293
+ command: jsonType(commandCallSchema),
294
+ authToken: import_typebox4.Type.String(),
295
+ settings: jsonType(import_typebox4.Type.Record(import_typebox4.Type.String(), import_typebox4.Type.Any())),
296
+ ref: import_typebox4.Type.String(),
297
+ signature: import_typebox4.Type.String()
233
298
  });
234
299
  async function createActionsPlugin(handler, options) {
235
300
  const pluginOptions = {
236
- logLevel: options?.logLevel ?? LOG_LEVEL2.INFO,
301
+ logLevel: options?.logLevel ?? import_ubiquity_os_logger2.LOG_LEVEL.INFO,
237
302
  postCommentOnError: options?.postCommentOnError ?? true,
238
303
  settingsSchema: options?.settingsSchema,
239
304
  envSchema: options?.envSchema,
240
- kernelPublicKey: options?.kernelPublicKey ?? KERNEL_PUBLIC_KEY
305
+ commandSchema: options?.commandSchema,
306
+ kernelPublicKey: options?.kernelPublicKey ?? KERNEL_PUBLIC_KEY,
307
+ bypassSignatureVerification: options?.bypassSignatureVerification || false
241
308
  };
242
309
  const pluginGithubToken = process.env.PLUGIN_GITHUB_TOKEN;
243
310
  if (!pluginGithubToken) {
244
311
  core.setFailed("Error: PLUGIN_GITHUB_TOKEN env is not set");
245
312
  return;
246
313
  }
314
+ const body = github.context.payload.inputs;
315
+ const signature = body.signature;
316
+ if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
317
+ core.setFailed(`Error: Invalid signature`);
318
+ return;
319
+ }
247
320
  const inputPayload = github.context.payload.inputs;
248
- const inputSchemaErrors = [...Value2.Errors(inputSchema2, inputPayload)];
321
+ const inputSchemaErrors = [...import_value3.Value.Errors(inputSchema2, inputPayload)];
249
322
  if (inputSchemaErrors.length) {
250
323
  console.dir(inputSchemaErrors, { depth: null });
251
324
  core.setFailed(`Error: Invalid inputs payload: ${inputSchemaErrors.join(",")}`);
252
325
  return;
253
326
  }
254
- const inputs = Value2.Decode(inputSchema2, inputPayload);
255
- const signature = inputs.signature;
256
- if (!await verifySignature(pluginOptions.kernelPublicKey, inputs, signature)) {
257
- core.setFailed(`Error: Invalid signature`);
258
- return;
259
- }
327
+ const inputs = import_value3.Value.Decode(inputSchema2, inputPayload);
260
328
  let config2;
261
329
  if (pluginOptions.settingsSchema) {
262
330
  try {
263
- config2 = Value2.Decode(pluginOptions.settingsSchema, Value2.Default(pluginOptions.settingsSchema, JSON.parse(inputs.settings)));
331
+ config2 = import_value3.Value.Decode(pluginOptions.settingsSchema, import_value3.Value.Default(pluginOptions.settingsSchema, inputs.settings));
264
332
  } catch (e) {
265
- console.dir(...Value2.Errors(pluginOptions.settingsSchema, JSON.parse(inputs.settings)), { depth: null });
333
+ console.dir(...import_value3.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
266
334
  throw e;
267
335
  }
268
336
  } else {
269
- config2 = JSON.parse(inputs.settings);
337
+ config2 = inputs.settings;
270
338
  }
271
339
  let env;
272
340
  if (pluginOptions.envSchema) {
273
341
  try {
274
- env = Value2.Decode(pluginOptions.envSchema, Value2.Default(pluginOptions.envSchema, process.env));
342
+ env = import_value3.Value.Decode(pluginOptions.envSchema, import_value3.Value.Default(pluginOptions.envSchema, process.env));
275
343
  } catch (e) {
276
- console.dir(...Value2.Errors(pluginOptions.envSchema, process.env), { depth: null });
344
+ console.dir(...import_value3.Value.Errors(pluginOptions.envSchema, process.env), { depth: null });
277
345
  throw e;
278
346
  }
279
347
  } else {
280
348
  env = process.env;
281
349
  }
350
+ let command = null;
351
+ if (inputs.command && pluginOptions.commandSchema) {
352
+ try {
353
+ command = import_value3.Value.Decode(pluginOptions.commandSchema, import_value3.Value.Default(pluginOptions.commandSchema, inputs.command));
354
+ } catch (e) {
355
+ console.dir(...import_value3.Value.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
356
+ throw e;
357
+ }
358
+ } else if (inputs.command) {
359
+ command = inputs.command;
360
+ }
282
361
  const context2 = {
283
362
  eventName: inputs.eventName,
284
- payload: JSON.parse(inputs.eventPayload),
363
+ payload: inputs.eventPayload,
364
+ command,
285
365
  octokit: new customOctokit({ auth: inputs.authToken }),
286
366
  config: config2,
287
367
  env,
288
- logger: new Logs2(pluginOptions.logLevel)
368
+ logger: new import_ubiquity_os_logger2.Logs(pluginOptions.logLevel)
289
369
  };
290
370
  try {
291
371
  const result = await handler(context2);
@@ -297,7 +377,7 @@ async function createActionsPlugin(handler, options) {
297
377
  if (error instanceof Error) {
298
378
  core.setFailed(error);
299
379
  loggerError = context2.logger.error(`Error: ${error}`, { error });
300
- } else if (error instanceof LogReturn2) {
380
+ } else if (error instanceof import_ubiquity_os_logger2.LogReturn) {
301
381
  core.setFailed(error.logMessage.raw);
302
382
  loggerError = error;
303
383
  } else {
@@ -340,8 +420,9 @@ async function returnDataToKernel(repoToken, stateId, output) {
340
420
  }
341
421
  });
342
422
  }
343
- export {
423
+ // Annotate the CommonJS export names for ESM import in node:
424
+ 0 && (module.exports = {
344
425
  createActionsPlugin,
345
426
  createPlugin,
346
427
  postComment
347
- };
428
+ });