@ubiquity-os/plugin-sdk 1.0.9 → 1.0.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.
@@ -0,0 +1,58 @@
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
+
32
+ // src/types/config.ts
33
+ var CONFIG_FULL_PATH = ".github/.ubiquity-os.config.yml";
34
+ var DEV_CONFIG_FULL_PATH = ".github/.ubiquity-os.config.dev.yml";
35
+ var CONFIG_ORG_REPO = ".ubiquity-os";
36
+
37
+ // src/constants.ts
38
+ var KERNEL_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
39
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs96DOU+JqM8SyNXOB6u3
40
+ uBKIFiyrcST/LZTYN6y7LeJlyCuGPqSDrWCfjU9Ph5PLf9TWiNmeM8DGaOpwEFC7
41
+ U3NRxOSglo4plnQ5zRwIHHXvxyK400sQP2oISXymISuBQWjEIqkC9DybQrKwNzf+
42
+ I0JHWPqmwMIw26UvVOtXGOOWBqTkk+N2+/9f8eDIJP5QQVwwszc8s1rXOsLMlVIf
43
+ wShw7GO4E2jyK8TSJKpyjV8eb1JJMDwFhPiRrtZfQJUtDf2mV/67shQww61BH2Y/
44
+ Plnalo58kWIbkqZoq1yJrL5sFb73osM5+vADTXVn79bkvea7W19nSkdMiarYt4Hq
45
+ JQIDAQAB
46
+ -----END PUBLIC KEY-----
47
+ `;
48
+ var KERNEL_APP_ID = 975031;
49
+ var BOT_USER_ID = 178941584;
50
+ // Annotate the CommonJS export names for ESM import in node:
51
+ 0 && (module.exports = {
52
+ BOT_USER_ID,
53
+ CONFIG_FULL_PATH,
54
+ CONFIG_ORG_REPO,
55
+ DEV_CONFIG_FULL_PATH,
56
+ KERNEL_APP_ID,
57
+ KERNEL_PUBLIC_KEY
58
+ });
package/dist/constants.js CHANGED
@@ -1,34 +1,3 @@
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
-
32
1
  // src/types/config.ts
33
2
  var CONFIG_FULL_PATH = ".github/.ubiquity-os.config.yml";
34
3
  var DEV_CONFIG_FULL_PATH = ".github/.ubiquity-os.config.dev.yml";
@@ -47,12 +16,11 @@ JQIDAQAB
47
16
  `;
48
17
  var KERNEL_APP_ID = 975031;
49
18
  var BOT_USER_ID = 178941584;
50
- // Annotate the CommonJS export names for ESM import in node:
51
- 0 && (module.exports = {
19
+ export {
52
20
  BOT_USER_ID,
53
21
  CONFIG_FULL_PATH,
54
22
  CONFIG_ORG_REPO,
55
23
  DEV_CONFIG_FULL_PATH,
56
24
  KERNEL_APP_ID,
57
25
  KERNEL_PUBLIC_KEY
58
- });
26
+ };
@@ -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
 
@@ -119,60 +157,66 @@ async function verifySignature(publicKeyPem, inputs, signature) {
119
157
  }
120
158
 
121
159
  // 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()
160
+ var inputSchema = import_typebox.Type.Object({
161
+ stateId: import_typebox.Type.String(),
162
+ eventName: import_typebox.Type.String(),
163
+ eventPayload: import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.Any()),
164
+ authToken: import_typebox.Type.String(),
165
+ settings: import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.Any()),
166
+ ref: import_typebox.Type.String(),
167
+ signature: import_typebox.Type.String(),
168
+ bypassSignatureVerification: import_typebox.Type.Optional(
169
+ import_typebox.Type.Boolean({
170
+ default: false,
171
+ description: "Bypass signature verification (caution: only use this if you know what you're doing)"
172
+ })
173
+ )
130
174
  });
131
175
  function createPlugin(handler, manifest, options) {
132
176
  const pluginOptions = {
133
- kernelPublicKey: options?.kernelPublicKey || KERNEL_PUBLIC_KEY,
134
- logLevel: options?.logLevel || LOG_LEVEL.INFO,
135
- postCommentOnError: options?.postCommentOnError || true,
177
+ kernelPublicKey: options?.kernelPublicKey ?? KERNEL_PUBLIC_KEY,
178
+ logLevel: options?.logLevel ?? import_ubiquity_os_logger.LOG_LEVEL.INFO,
179
+ postCommentOnError: options?.postCommentOnError ?? true,
136
180
  settingsSchema: options?.settingsSchema,
137
181
  envSchema: options?.envSchema
138
182
  };
139
- const app = new Hono();
183
+ const app = new import_hono.Hono();
140
184
  app.get("/manifest.json", (ctx) => {
141
185
  return ctx.json(manifest);
142
186
  });
143
187
  app.post("/", async (ctx) => {
144
188
  if (ctx.req.header("content-type") !== "application/json") {
145
- throw new HTTPException(400, { message: "Content-Type must be application/json" });
189
+ throw new import_http_exception.HTTPException(400, { message: "Content-Type must be application/json" });
146
190
  }
147
191
  const body = await ctx.req.json();
148
- const inputSchemaErrors = [...Value.Errors(inputSchema, body)];
192
+ const inputSchemaErrors = [...import_value.Value.Errors(inputSchema, body)];
149
193
  if (inputSchemaErrors.length) {
150
194
  console.dir(inputSchemaErrors, { depth: null });
151
- throw new HTTPException(400, { message: "Invalid body" });
195
+ throw new import_http_exception.HTTPException(400, { message: "Invalid body" });
152
196
  }
153
- const inputs = Value.Decode(inputSchema, body);
197
+ const inputs = import_value.Value.Decode(inputSchema, body);
154
198
  const signature = inputs.signature;
155
- if (!await verifySignature(pluginOptions.kernelPublicKey, inputs, signature)) {
156
- throw new HTTPException(400, { message: "Invalid signature" });
199
+ if (!options?.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, inputs, signature)) {
200
+ throw new import_http_exception.HTTPException(400, { message: "Invalid signature" });
157
201
  }
158
202
  let config2;
159
203
  if (pluginOptions.settingsSchema) {
160
204
  try {
161
- config2 = Value.Decode(pluginOptions.settingsSchema, Value.Default(pluginOptions.settingsSchema, inputs.settings));
205
+ config2 = import_value.Value.Decode(pluginOptions.settingsSchema, import_value.Value.Default(pluginOptions.settingsSchema, inputs.settings));
162
206
  } catch (e) {
163
- console.dir(...Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
207
+ console.dir(...import_value.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
164
208
  throw e;
165
209
  }
166
210
  } else {
167
211
  config2 = inputs.settings;
168
212
  }
169
213
  let env;
170
- const honoEnvironment = honoEnv(ctx);
214
+ const honoEnvironment = (0, import_adapter.env)(ctx);
171
215
  if (pluginOptions.envSchema) {
172
216
  try {
173
- env = Value.Decode(pluginOptions.envSchema, Value.Default(pluginOptions.envSchema, honoEnvironment));
217
+ env = import_value.Value.Decode(pluginOptions.envSchema, import_value.Value.Default(pluginOptions.envSchema, honoEnvironment));
174
218
  } catch (e) {
175
- console.dir(...Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
219
+ console.dir(...import_value.Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
176
220
  throw e;
177
221
  }
178
222
  } else {
@@ -184,7 +228,7 @@ function createPlugin(handler, manifest, options) {
184
228
  octokit: new customOctokit({ auth: inputs.authToken }),
185
229
  config: config2,
186
230
  env,
187
- logger: new Logs(pluginOptions.logLevel)
231
+ logger: new import_ubiquity_os_logger.Logs(pluginOptions.logLevel)
188
232
  };
189
233
  try {
190
234
  const result = await handler(context2);
@@ -194,7 +238,7 @@ function createPlugin(handler, manifest, options) {
194
238
  let loggerError;
195
239
  if (error instanceof Error) {
196
240
  loggerError = context2.logger.error(`Error: ${error}`, { error });
197
- } else if (error instanceof LogReturn) {
241
+ } else if (error instanceof import_ubiquity_os_logger.LogReturn) {
198
242
  loggerError = error;
199
243
  } else {
200
244
  loggerError = context2.logger.error(`Error: ${error}`);
@@ -202,36 +246,36 @@ function createPlugin(handler, manifest, options) {
202
246
  if (pluginOptions.postCommentOnError && loggerError) {
203
247
  await postComment(context2, loggerError);
204
248
  }
205
- throw new HTTPException(500, { message: "Unexpected error" });
249
+ throw new import_http_exception.HTTPException(500, { message: "Unexpected error" });
206
250
  }
207
251
  });
208
252
  return app;
209
253
  }
210
254
 
211
255
  // src/actions.ts
212
- import * as core from "@actions/core";
213
- import * as github from "@actions/github";
214
- import { Type as T2 } from "@sinclair/typebox";
215
- import { Value as Value2 } from "@sinclair/typebox/value";
216
- import { LOG_LEVEL as LOG_LEVEL2, LogReturn as LogReturn2, Logs as Logs2 } from "@ubiquity-os/ubiquity-os-logger";
217
- import { config } from "dotenv";
218
- config();
219
- var inputSchema2 = T2.Object({
220
- stateId: T2.String(),
221
- eventName: T2.String(),
222
- eventPayload: T2.String(),
223
- authToken: T2.String(),
224
- settings: T2.String(),
225
- ref: T2.String(),
226
- signature: T2.String()
256
+ var core = __toESM(require("@actions/core"), 1);
257
+ var github = __toESM(require("@actions/github"), 1);
258
+ var import_typebox2 = require("@sinclair/typebox");
259
+ var import_value2 = require("@sinclair/typebox/value");
260
+ var import_ubiquity_os_logger2 = require("@ubiquity-os/ubiquity-os-logger");
261
+ var import_dotenv = require("dotenv");
262
+ (0, import_dotenv.config)();
263
+ var inputSchema2 = import_typebox2.Type.Object({
264
+ stateId: import_typebox2.Type.String(),
265
+ eventName: import_typebox2.Type.String(),
266
+ eventPayload: import_typebox2.Type.String(),
267
+ authToken: import_typebox2.Type.String(),
268
+ settings: import_typebox2.Type.String(),
269
+ ref: import_typebox2.Type.String(),
270
+ signature: import_typebox2.Type.String()
227
271
  });
228
272
  async function createActionsPlugin(handler, options) {
229
273
  const pluginOptions = {
230
- logLevel: options?.logLevel || LOG_LEVEL2.INFO,
231
- postCommentOnError: options?.postCommentOnError || true,
274
+ logLevel: options?.logLevel ?? import_ubiquity_os_logger2.LOG_LEVEL.INFO,
275
+ postCommentOnError: options?.postCommentOnError ?? true,
232
276
  settingsSchema: options?.settingsSchema,
233
277
  envSchema: options?.envSchema,
234
- kernelPublicKey: options?.kernelPublicKey || KERNEL_PUBLIC_KEY
278
+ kernelPublicKey: options?.kernelPublicKey ?? KERNEL_PUBLIC_KEY
235
279
  };
236
280
  const pluginGithubToken = process.env.PLUGIN_GITHUB_TOKEN;
237
281
  if (!pluginGithubToken) {
@@ -239,13 +283,13 @@ async function createActionsPlugin(handler, options) {
239
283
  return;
240
284
  }
241
285
  const inputPayload = github.context.payload.inputs;
242
- const inputSchemaErrors = [...Value2.Errors(inputSchema2, inputPayload)];
286
+ const inputSchemaErrors = [...import_value2.Value.Errors(inputSchema2, inputPayload)];
243
287
  if (inputSchemaErrors.length) {
244
288
  console.dir(inputSchemaErrors, { depth: null });
245
289
  core.setFailed(`Error: Invalid inputs payload: ${inputSchemaErrors.join(",")}`);
246
290
  return;
247
291
  }
248
- const inputs = Value2.Decode(inputSchema2, inputPayload);
292
+ const inputs = import_value2.Value.Decode(inputSchema2, inputPayload);
249
293
  const signature = inputs.signature;
250
294
  if (!await verifySignature(pluginOptions.kernelPublicKey, inputs, signature)) {
251
295
  core.setFailed(`Error: Invalid signature`);
@@ -254,9 +298,9 @@ async function createActionsPlugin(handler, options) {
254
298
  let config2;
255
299
  if (pluginOptions.settingsSchema) {
256
300
  try {
257
- config2 = Value2.Decode(pluginOptions.settingsSchema, Value2.Default(pluginOptions.settingsSchema, JSON.parse(inputs.settings)));
301
+ config2 = import_value2.Value.Decode(pluginOptions.settingsSchema, import_value2.Value.Default(pluginOptions.settingsSchema, JSON.parse(inputs.settings)));
258
302
  } catch (e) {
259
- console.dir(...Value2.Errors(pluginOptions.settingsSchema, JSON.parse(inputs.settings)), { depth: null });
303
+ console.dir(...import_value2.Value.Errors(pluginOptions.settingsSchema, JSON.parse(inputs.settings)), { depth: null });
260
304
  throw e;
261
305
  }
262
306
  } else {
@@ -265,9 +309,9 @@ async function createActionsPlugin(handler, options) {
265
309
  let env;
266
310
  if (pluginOptions.envSchema) {
267
311
  try {
268
- env = Value2.Decode(pluginOptions.envSchema, Value2.Default(pluginOptions.envSchema, process.env));
312
+ env = import_value2.Value.Decode(pluginOptions.envSchema, import_value2.Value.Default(pluginOptions.envSchema, process.env));
269
313
  } catch (e) {
270
- console.dir(...Value2.Errors(pluginOptions.envSchema, process.env), { depth: null });
314
+ console.dir(...import_value2.Value.Errors(pluginOptions.envSchema, process.env), { depth: null });
271
315
  throw e;
272
316
  }
273
317
  } else {
@@ -279,7 +323,7 @@ async function createActionsPlugin(handler, options) {
279
323
  octokit: new customOctokit({ auth: inputs.authToken }),
280
324
  config: config2,
281
325
  env,
282
- logger: new Logs2(pluginOptions.logLevel)
326
+ logger: new import_ubiquity_os_logger2.Logs(pluginOptions.logLevel)
283
327
  };
284
328
  try {
285
329
  const result = await handler(context2);
@@ -291,7 +335,7 @@ async function createActionsPlugin(handler, options) {
291
335
  if (error instanceof Error) {
292
336
  core.setFailed(error);
293
337
  loggerError = context2.logger.error(`Error: ${error}`, { error });
294
- } else if (error instanceof LogReturn2) {
338
+ } else if (error instanceof import_ubiquity_os_logger2.LogReturn) {
295
339
  core.setFailed(error.logMessage.raw);
296
340
  loggerError = error;
297
341
  } else {
@@ -334,8 +378,9 @@ async function returnDataToKernel(repoToken, stateId, output) {
334
378
  }
335
379
  });
336
380
  }
337
- export {
381
+ // Annotate the CommonJS export names for ESM import in node:
382
+ 0 && (module.exports = {
338
383
  createActionsPlugin,
339
384
  createPlugin,
340
385
  postComment
341
- };
386
+ });
@@ -9,7 +9,7 @@ import * as _octokit_plugin_rest_endpoint_methods from '@octokit/plugin-rest-end
9
9
  import * as _octokit_plugin_paginate_rest from '@octokit/plugin-paginate-rest';
10
10
  import * as _octokit_request_error from '@octokit/request-error';
11
11
  import { Octokit } from '@octokit/core';
12
- import { Manifest } from './manifest.mjs';
12
+ import { Manifest } from './manifest.cjs';
13
13
 
14
14
  declare const customOctokit: typeof Octokit & _octokit_core_dist_types_types.Constructor<{
15
15
  retry: {
@@ -36,6 +36,7 @@ interface Options$1 {
36
36
  postCommentOnError?: boolean;
37
37
  settingsSchema?: TAnySchema;
38
38
  envSchema?: TAnySchema;
39
+ bypassSignatureVerification?: boolean;
39
40
  }
40
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, "/">;
41
42
 
package/dist/index.d.ts CHANGED
@@ -36,6 +36,7 @@ interface Options$1 {
36
36
  postCommentOnError?: boolean;
37
37
  settingsSchema?: TAnySchema;
38
38
  envSchema?: TAnySchema;
39
+ bypassSignatureVerification?: boolean;
39
40
  }
40
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, "/">;
41
42
 
package/dist/index.js CHANGED
@@ -1,48 +1,10 @@
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
-
39
1
  // src/server.ts
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");
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";
46
8
 
47
9
  // src/util.ts
48
10
  function sanitizeMetadata(obj) {
@@ -98,12 +60,12 @@ JQIDAQAB
98
60
  `;
99
61
 
100
62
  // src/octokit.ts
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");
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";
107
69
  var defaultOptions = {
108
70
  throttle: {
109
71
  onAbuseLimit: (retryAfter, options, octokit) => {
@@ -120,7 +82,7 @@ var defaultOptions = {
120
82
  }
121
83
  }
122
84
  };
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) => {
85
+ var customOctokit = Octokit.plugin(throttling, retry, paginateRest, restEndpointMethods, paginateGraphQL).defaults((instanceOptions) => {
124
86
  return { ...defaultOptions, ...instanceOptions };
125
87
  });
126
88
 
@@ -157,60 +119,66 @@ async function verifySignature(publicKeyPem, inputs, signature) {
157
119
  }
158
120
 
159
121
  // src/server.ts
160
- var inputSchema = import_typebox.Type.Object({
161
- stateId: import_typebox.Type.String(),
162
- eventName: import_typebox.Type.String(),
163
- eventPayload: import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.Any()),
164
- authToken: import_typebox.Type.String(),
165
- settings: import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.Any()),
166
- ref: import_typebox.Type.String(),
167
- signature: import_typebox.Type.String()
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
+ )
168
136
  });
169
137
  function createPlugin(handler, manifest, options) {
170
138
  const pluginOptions = {
171
- kernelPublicKey: options?.kernelPublicKey || KERNEL_PUBLIC_KEY,
172
- logLevel: options?.logLevel || import_ubiquity_os_logger.LOG_LEVEL.INFO,
173
- postCommentOnError: options?.postCommentOnError || true,
139
+ kernelPublicKey: options?.kernelPublicKey ?? KERNEL_PUBLIC_KEY,
140
+ logLevel: options?.logLevel ?? LOG_LEVEL.INFO,
141
+ postCommentOnError: options?.postCommentOnError ?? true,
174
142
  settingsSchema: options?.settingsSchema,
175
143
  envSchema: options?.envSchema
176
144
  };
177
- const app = new import_hono.Hono();
145
+ const app = new Hono();
178
146
  app.get("/manifest.json", (ctx) => {
179
147
  return ctx.json(manifest);
180
148
  });
181
149
  app.post("/", async (ctx) => {
182
150
  if (ctx.req.header("content-type") !== "application/json") {
183
- throw new import_http_exception.HTTPException(400, { message: "Content-Type must be application/json" });
151
+ throw new HTTPException(400, { message: "Content-Type must be application/json" });
184
152
  }
185
153
  const body = await ctx.req.json();
186
- const inputSchemaErrors = [...import_value.Value.Errors(inputSchema, body)];
154
+ const inputSchemaErrors = [...Value.Errors(inputSchema, body)];
187
155
  if (inputSchemaErrors.length) {
188
156
  console.dir(inputSchemaErrors, { depth: null });
189
- throw new import_http_exception.HTTPException(400, { message: "Invalid body" });
157
+ throw new HTTPException(400, { message: "Invalid body" });
190
158
  }
191
- const inputs = import_value.Value.Decode(inputSchema, body);
159
+ const inputs = Value.Decode(inputSchema, body);
192
160
  const signature = inputs.signature;
193
- if (!await verifySignature(pluginOptions.kernelPublicKey, inputs, signature)) {
194
- throw new import_http_exception.HTTPException(400, { message: "Invalid signature" });
161
+ if (!options?.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, inputs, signature)) {
162
+ throw new HTTPException(400, { message: "Invalid signature" });
195
163
  }
196
164
  let config2;
197
165
  if (pluginOptions.settingsSchema) {
198
166
  try {
199
- config2 = import_value.Value.Decode(pluginOptions.settingsSchema, import_value.Value.Default(pluginOptions.settingsSchema, inputs.settings));
167
+ config2 = Value.Decode(pluginOptions.settingsSchema, Value.Default(pluginOptions.settingsSchema, inputs.settings));
200
168
  } catch (e) {
201
- console.dir(...import_value.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
169
+ console.dir(...Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
202
170
  throw e;
203
171
  }
204
172
  } else {
205
173
  config2 = inputs.settings;
206
174
  }
207
175
  let env;
208
- const honoEnvironment = (0, import_adapter.env)(ctx);
176
+ const honoEnvironment = honoEnv(ctx);
209
177
  if (pluginOptions.envSchema) {
210
178
  try {
211
- env = import_value.Value.Decode(pluginOptions.envSchema, import_value.Value.Default(pluginOptions.envSchema, honoEnvironment));
179
+ env = Value.Decode(pluginOptions.envSchema, Value.Default(pluginOptions.envSchema, honoEnvironment));
212
180
  } catch (e) {
213
- console.dir(...import_value.Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
181
+ console.dir(...Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
214
182
  throw e;
215
183
  }
216
184
  } else {
@@ -222,7 +190,7 @@ function createPlugin(handler, manifest, options) {
222
190
  octokit: new customOctokit({ auth: inputs.authToken }),
223
191
  config: config2,
224
192
  env,
225
- logger: new import_ubiquity_os_logger.Logs(pluginOptions.logLevel)
193
+ logger: new Logs(pluginOptions.logLevel)
226
194
  };
227
195
  try {
228
196
  const result = await handler(context2);
@@ -232,7 +200,7 @@ function createPlugin(handler, manifest, options) {
232
200
  let loggerError;
233
201
  if (error instanceof Error) {
234
202
  loggerError = context2.logger.error(`Error: ${error}`, { error });
235
- } else if (error instanceof import_ubiquity_os_logger.LogReturn) {
203
+ } else if (error instanceof LogReturn) {
236
204
  loggerError = error;
237
205
  } else {
238
206
  loggerError = context2.logger.error(`Error: ${error}`);
@@ -240,36 +208,36 @@ function createPlugin(handler, manifest, options) {
240
208
  if (pluginOptions.postCommentOnError && loggerError) {
241
209
  await postComment(context2, loggerError);
242
210
  }
243
- throw new import_http_exception.HTTPException(500, { message: "Unexpected error" });
211
+ throw new HTTPException(500, { message: "Unexpected error" });
244
212
  }
245
213
  });
246
214
  return app;
247
215
  }
248
216
 
249
217
  // src/actions.ts
250
- var core = __toESM(require("@actions/core"));
251
- var github = __toESM(require("@actions/github"));
252
- var import_typebox2 = require("@sinclair/typebox");
253
- var import_value2 = require("@sinclair/typebox/value");
254
- var import_ubiquity_os_logger2 = require("@ubiquity-os/ubiquity-os-logger");
255
- var import_dotenv = require("dotenv");
256
- (0, import_dotenv.config)();
257
- var inputSchema2 = import_typebox2.Type.Object({
258
- stateId: import_typebox2.Type.String(),
259
- eventName: import_typebox2.Type.String(),
260
- eventPayload: import_typebox2.Type.String(),
261
- authToken: import_typebox2.Type.String(),
262
- settings: import_typebox2.Type.String(),
263
- ref: import_typebox2.Type.String(),
264
- signature: import_typebox2.Type.String()
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()
265
233
  });
266
234
  async function createActionsPlugin(handler, options) {
267
235
  const pluginOptions = {
268
- logLevel: options?.logLevel || import_ubiquity_os_logger2.LOG_LEVEL.INFO,
269
- postCommentOnError: options?.postCommentOnError || true,
236
+ logLevel: options?.logLevel ?? LOG_LEVEL2.INFO,
237
+ postCommentOnError: options?.postCommentOnError ?? true,
270
238
  settingsSchema: options?.settingsSchema,
271
239
  envSchema: options?.envSchema,
272
- kernelPublicKey: options?.kernelPublicKey || KERNEL_PUBLIC_KEY
240
+ kernelPublicKey: options?.kernelPublicKey ?? KERNEL_PUBLIC_KEY
273
241
  };
274
242
  const pluginGithubToken = process.env.PLUGIN_GITHUB_TOKEN;
275
243
  if (!pluginGithubToken) {
@@ -277,13 +245,13 @@ async function createActionsPlugin(handler, options) {
277
245
  return;
278
246
  }
279
247
  const inputPayload = github.context.payload.inputs;
280
- const inputSchemaErrors = [...import_value2.Value.Errors(inputSchema2, inputPayload)];
248
+ const inputSchemaErrors = [...Value2.Errors(inputSchema2, inputPayload)];
281
249
  if (inputSchemaErrors.length) {
282
250
  console.dir(inputSchemaErrors, { depth: null });
283
251
  core.setFailed(`Error: Invalid inputs payload: ${inputSchemaErrors.join(",")}`);
284
252
  return;
285
253
  }
286
- const inputs = import_value2.Value.Decode(inputSchema2, inputPayload);
254
+ const inputs = Value2.Decode(inputSchema2, inputPayload);
287
255
  const signature = inputs.signature;
288
256
  if (!await verifySignature(pluginOptions.kernelPublicKey, inputs, signature)) {
289
257
  core.setFailed(`Error: Invalid signature`);
@@ -292,9 +260,9 @@ async function createActionsPlugin(handler, options) {
292
260
  let config2;
293
261
  if (pluginOptions.settingsSchema) {
294
262
  try {
295
- config2 = import_value2.Value.Decode(pluginOptions.settingsSchema, import_value2.Value.Default(pluginOptions.settingsSchema, JSON.parse(inputs.settings)));
263
+ config2 = Value2.Decode(pluginOptions.settingsSchema, Value2.Default(pluginOptions.settingsSchema, JSON.parse(inputs.settings)));
296
264
  } catch (e) {
297
- console.dir(...import_value2.Value.Errors(pluginOptions.settingsSchema, JSON.parse(inputs.settings)), { depth: null });
265
+ console.dir(...Value2.Errors(pluginOptions.settingsSchema, JSON.parse(inputs.settings)), { depth: null });
298
266
  throw e;
299
267
  }
300
268
  } else {
@@ -303,9 +271,9 @@ async function createActionsPlugin(handler, options) {
303
271
  let env;
304
272
  if (pluginOptions.envSchema) {
305
273
  try {
306
- env = import_value2.Value.Decode(pluginOptions.envSchema, import_value2.Value.Default(pluginOptions.envSchema, process.env));
274
+ env = Value2.Decode(pluginOptions.envSchema, Value2.Default(pluginOptions.envSchema, process.env));
307
275
  } catch (e) {
308
- console.dir(...import_value2.Value.Errors(pluginOptions.envSchema, process.env), { depth: null });
276
+ console.dir(...Value2.Errors(pluginOptions.envSchema, process.env), { depth: null });
309
277
  throw e;
310
278
  }
311
279
  } else {
@@ -317,7 +285,7 @@ async function createActionsPlugin(handler, options) {
317
285
  octokit: new customOctokit({ auth: inputs.authToken }),
318
286
  config: config2,
319
287
  env,
320
- logger: new import_ubiquity_os_logger2.Logs(pluginOptions.logLevel)
288
+ logger: new Logs2(pluginOptions.logLevel)
321
289
  };
322
290
  try {
323
291
  const result = await handler(context2);
@@ -329,7 +297,7 @@ async function createActionsPlugin(handler, options) {
329
297
  if (error instanceof Error) {
330
298
  core.setFailed(error);
331
299
  loggerError = context2.logger.error(`Error: ${error}`, { error });
332
- } else if (error instanceof import_ubiquity_os_logger2.LogReturn) {
300
+ } else if (error instanceof LogReturn2) {
333
301
  core.setFailed(error.logMessage.raw);
334
302
  loggerError = error;
335
303
  } else {
@@ -372,9 +340,8 @@ async function returnDataToKernel(repoToken, stateId, output) {
372
340
  }
373
341
  });
374
342
  }
375
- // Annotate the CommonJS export names for ESM import in node:
376
- 0 && (module.exports = {
343
+ export {
377
344
  createActionsPlugin,
378
345
  createPlugin,
379
346
  postComment
380
- });
347
+ };
@@ -0,0 +1,47 @@
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/types/manifest.ts
21
+ var manifest_exports = {};
22
+ __export(manifest_exports, {
23
+ commandSchema: () => commandSchema,
24
+ manifestSchema: () => manifestSchema,
25
+ runEvent: () => runEvent
26
+ });
27
+ module.exports = __toCommonJS(manifest_exports);
28
+ var import_typebox = require("@sinclair/typebox");
29
+ var import_webhooks = require("@octokit/webhooks");
30
+ var runEvent = import_typebox.Type.Union(import_webhooks.emitterEventNames.map((o) => import_typebox.Type.Literal(o)));
31
+ var commandSchema = import_typebox.Type.Object({
32
+ description: import_typebox.Type.String({ minLength: 1 }),
33
+ "ubiquity:example": import_typebox.Type.String({ minLength: 1 })
34
+ });
35
+ var manifestSchema = import_typebox.Type.Object({
36
+ name: import_typebox.Type.String({ minLength: 1 }),
37
+ description: import_typebox.Type.Optional(import_typebox.Type.String({ default: "" })),
38
+ commands: import_typebox.Type.Optional(import_typebox.Type.Record(import_typebox.Type.String(), commandSchema, { default: {} })),
39
+ "ubiquity:listeners": import_typebox.Type.Optional(import_typebox.Type.Array(runEvent, { default: [] })),
40
+ configuration: import_typebox.Type.Optional(import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.Any(), { default: {} }))
41
+ });
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ commandSchema,
45
+ manifestSchema,
46
+ runEvent
47
+ });
package/dist/manifest.js CHANGED
@@ -1,47 +1,20 @@
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
1
  // src/types/manifest.ts
21
- var manifest_exports = {};
22
- __export(manifest_exports, {
23
- commandSchema: () => commandSchema,
24
- manifestSchema: () => manifestSchema,
25
- runEvent: () => runEvent
26
- });
27
- module.exports = __toCommonJS(manifest_exports);
28
- var import_typebox = require("@sinclair/typebox");
29
- var import_webhooks = require("@octokit/webhooks");
30
- var runEvent = import_typebox.Type.Union(import_webhooks.emitterEventNames.map((o) => import_typebox.Type.Literal(o)));
31
- var commandSchema = import_typebox.Type.Object({
32
- description: import_typebox.Type.String({ minLength: 1 }),
33
- "ubiquity:example": import_typebox.Type.String({ minLength: 1 })
2
+ import { Type as T } from "@sinclair/typebox";
3
+ import { emitterEventNames } from "@octokit/webhooks";
4
+ var runEvent = T.Union(emitterEventNames.map((o) => T.Literal(o)));
5
+ var commandSchema = T.Object({
6
+ description: T.String({ minLength: 1 }),
7
+ "ubiquity:example": T.String({ minLength: 1 })
34
8
  });
35
- var manifestSchema = import_typebox.Type.Object({
36
- name: import_typebox.Type.String({ minLength: 1 }),
37
- description: import_typebox.Type.Optional(import_typebox.Type.String({ default: "" })),
38
- commands: import_typebox.Type.Optional(import_typebox.Type.Record(import_typebox.Type.String(), commandSchema, { default: {} })),
39
- "ubiquity:listeners": import_typebox.Type.Optional(import_typebox.Type.Array(runEvent, { default: [] })),
40
- configuration: import_typebox.Type.Optional(import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.Any(), { default: {} }))
9
+ var manifestSchema = T.Object({
10
+ name: T.String({ minLength: 1 }),
11
+ description: T.Optional(T.String({ default: "" })),
12
+ commands: T.Optional(T.Record(T.String(), commandSchema, { default: {} })),
13
+ "ubiquity:listeners": T.Optional(T.Array(runEvent, { default: [] })),
14
+ configuration: T.Optional(T.Record(T.String(), T.Any(), { default: {} }))
41
15
  });
42
- // Annotate the CommonJS export names for ESM import in node:
43
- 0 && (module.exports = {
16
+ export {
44
17
  commandSchema,
45
18
  manifestSchema,
46
19
  runEvent
47
- });
20
+ };
@@ -0,0 +1,81 @@
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/signature.ts
21
+ var signature_exports = {};
22
+ __export(signature_exports, {
23
+ signPayload: () => signPayload,
24
+ verifySignature: () => verifySignature
25
+ });
26
+ module.exports = __toCommonJS(signature_exports);
27
+ async function verifySignature(publicKeyPem, inputs, signature) {
28
+ try {
29
+ const inputsOrdered = {
30
+ stateId: inputs.stateId,
31
+ eventName: inputs.eventName,
32
+ eventPayload: inputs.eventPayload,
33
+ settings: inputs.settings,
34
+ authToken: inputs.authToken,
35
+ ref: inputs.ref
36
+ };
37
+ const pemContents = publicKeyPem.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").trim();
38
+ const binaryDer = Uint8Array.from(atob(pemContents), (c) => c.charCodeAt(0));
39
+ const publicKey = await crypto.subtle.importKey(
40
+ "spki",
41
+ binaryDer,
42
+ {
43
+ name: "RSASSA-PKCS1-v1_5",
44
+ hash: "SHA-256"
45
+ },
46
+ true,
47
+ ["verify"]
48
+ );
49
+ const signatureArray = Uint8Array.from(atob(signature), (c) => c.charCodeAt(0));
50
+ const dataArray = new TextEncoder().encode(JSON.stringify(inputsOrdered));
51
+ return await crypto.subtle.verify("RSASSA-PKCS1-v1_5", publicKey, signatureArray, dataArray);
52
+ } catch (error) {
53
+ console.error(error);
54
+ return false;
55
+ }
56
+ }
57
+ async function importRsaPrivateKey(pem) {
58
+ const pemContents = pem.replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "").trim();
59
+ const binaryDer = Uint8Array.from(atob(pemContents), (c) => c.charCodeAt(0));
60
+ return await crypto.subtle.importKey(
61
+ "pkcs8",
62
+ binaryDer.buffer,
63
+ {
64
+ name: "RSASSA-PKCS1-v1_5",
65
+ hash: "SHA-256"
66
+ },
67
+ true,
68
+ ["sign"]
69
+ );
70
+ }
71
+ async function signPayload(payload, privateKey) {
72
+ const data = new TextEncoder().encode(payload);
73
+ const _privateKey = await importRsaPrivateKey(privateKey);
74
+ const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", _privateKey, data);
75
+ return btoa(String.fromCharCode(...new Uint8Array(signature)));
76
+ }
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ signPayload,
80
+ verifySignature
81
+ });
@@ -0,0 +1,12 @@
1
+ interface Inputs {
2
+ stateId: unknown;
3
+ eventName: unknown;
4
+ eventPayload: unknown;
5
+ authToken: unknown;
6
+ settings: unknown;
7
+ ref: unknown;
8
+ }
9
+ declare function verifySignature(publicKeyPem: string, inputs: Inputs, signature: string): Promise<boolean>;
10
+ declare function signPayload(payload: string, privateKey: string): Promise<string>;
11
+
12
+ export { signPayload, verifySignature };
@@ -0,0 +1,12 @@
1
+ interface Inputs {
2
+ stateId: unknown;
3
+ eventName: unknown;
4
+ eventPayload: unknown;
5
+ authToken: unknown;
6
+ settings: unknown;
7
+ ref: unknown;
8
+ }
9
+ declare function verifySignature(publicKeyPem: string, inputs: Inputs, signature: string): Promise<boolean>;
10
+ declare function signPayload(payload: string, privateKey: string): Promise<string>;
11
+
12
+ export { signPayload, verifySignature };
@@ -0,0 +1,55 @@
1
+ // src/signature.ts
2
+ async function verifySignature(publicKeyPem, inputs, signature) {
3
+ try {
4
+ const inputsOrdered = {
5
+ stateId: inputs.stateId,
6
+ eventName: inputs.eventName,
7
+ eventPayload: inputs.eventPayload,
8
+ settings: inputs.settings,
9
+ authToken: inputs.authToken,
10
+ ref: inputs.ref
11
+ };
12
+ const pemContents = publicKeyPem.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").trim();
13
+ const binaryDer = Uint8Array.from(atob(pemContents), (c) => c.charCodeAt(0));
14
+ const publicKey = await crypto.subtle.importKey(
15
+ "spki",
16
+ binaryDer,
17
+ {
18
+ name: "RSASSA-PKCS1-v1_5",
19
+ hash: "SHA-256"
20
+ },
21
+ true,
22
+ ["verify"]
23
+ );
24
+ const signatureArray = Uint8Array.from(atob(signature), (c) => c.charCodeAt(0));
25
+ const dataArray = new TextEncoder().encode(JSON.stringify(inputsOrdered));
26
+ return await crypto.subtle.verify("RSASSA-PKCS1-v1_5", publicKey, signatureArray, dataArray);
27
+ } catch (error) {
28
+ console.error(error);
29
+ return false;
30
+ }
31
+ }
32
+ async function importRsaPrivateKey(pem) {
33
+ const pemContents = pem.replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "").trim();
34
+ const binaryDer = Uint8Array.from(atob(pemContents), (c) => c.charCodeAt(0));
35
+ return await crypto.subtle.importKey(
36
+ "pkcs8",
37
+ binaryDer.buffer,
38
+ {
39
+ name: "RSASSA-PKCS1-v1_5",
40
+ hash: "SHA-256"
41
+ },
42
+ true,
43
+ ["sign"]
44
+ );
45
+ }
46
+ async function signPayload(payload, privateKey) {
47
+ const data = new TextEncoder().encode(payload);
48
+ const _privateKey = await importRsaPrivateKey(privateKey);
49
+ const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", _privateKey, data);
50
+ return btoa(String.fromCharCode(...new Uint8Array(signature)));
51
+ }
52
+ export {
53
+ signPayload,
54
+ verifySignature
55
+ };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@ubiquity-os/plugin-sdk",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "SDK for plugin support.",
5
5
  "author": "Ubiquity DAO",
6
6
  "license": "MIT",
7
7
  "engines": {
8
8
  "node": ">=20.10.0"
9
9
  },
10
+ "type": "module",
10
11
  "module": "dist/index.mjs",
11
12
  "main": "dist/index.js",
12
13
  "typings": "dist/index.d.ts",
@@ -18,6 +19,9 @@
18
19
  ],
19
20
  "constants": [
20
21
  "dist/constants.d.ts"
22
+ ],
23
+ "signature": [
24
+ "dist/signature.d.ts"
21
25
  ]
22
26
  }
23
27
  },
@@ -36,6 +40,11 @@
36
40
  "types": "./dist/constants.d.ts",
37
41
  "import": "./dist/constants.mjs",
38
42
  "require": "./dist/constants.js"
43
+ },
44
+ "./signature": {
45
+ "types": "./dist/signature.d.ts",
46
+ "import": "./dist/signature.mjs",
47
+ "require": "./dist/signature.js"
39
48
  }
40
49
  },
41
50
  "files": [
@@ -50,7 +59,7 @@
50
59
  "knip": "knip --config .github/knip.ts",
51
60
  "knip-ci": "knip --no-exit-code --reporter json --config .github/knip.ts",
52
61
  "prepare": "node .husky/install.mjs",
53
- "test": "jest --setupFiles dotenv/config --coverage"
62
+ "jest:test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --setupFiles dotenv/config --coverage"
54
63
  },
55
64
  "keywords": [
56
65
  "typescript",
@@ -83,10 +92,10 @@
83
92
  "@cspell/dict-software-terms": "^3.3.18",
84
93
  "@cspell/dict-typescript": "^3.1.2",
85
94
  "@eslint/js": "^9.14.0",
86
- "@jest/globals": "29.7.0",
95
+ "@jest/globals": "^29.7.0",
87
96
  "@mswjs/data": "0.16.1",
88
- "@types/jest": "29.5.12",
89
97
  "@types/node": "^20.11.19",
98
+ "cross-env": "^7.0.3",
90
99
  "cspell": "^8.4.0",
91
100
  "eslint": "^9.14.0",
92
101
  "eslint-config-prettier": "^9.1.0",
@@ -94,13 +103,17 @@
94
103
  "eslint-plugin-prettier": "^5.2.1",
95
104
  "eslint-plugin-sonarjs": "^2.0.4",
96
105
  "husky": "^9.0.11",
97
- "jest": "29.7.0",
98
- "jest-junit": "16.0.0",
99
- "jest-md-dashboard": "0.8.0",
106
+ "jest": "^29.7.0",
107
+ "jest-junit": "^16.0.0",
108
+ "jest-md-dashboard": "^0.8.0",
100
109
  "knip": "^5.0.1",
101
110
  "lint-staged": "^15.2.2",
111
+ "msw": "^2.6.3",
112
+ "npm-run-all": "^4.1.5",
102
113
  "prettier": "^3.3.3",
103
- "ts-jest": "29.1.2",
114
+ "simple-git": "^3.27.0",
115
+ "ts-jest": "^29.2.5",
116
+ "ts-node": "^10.9.2",
104
117
  "tsup": "8.1.0",
105
118
  "typescript": "^5.5.4",
106
119
  "typescript-eslint": "^8.13.0"
@@ -1,26 +0,0 @@
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
- };
package/dist/manifest.mjs DELETED
@@ -1,20 +0,0 @@
1
- // src/types/manifest.ts
2
- import { Type as T } from "@sinclair/typebox";
3
- import { emitterEventNames } from "@octokit/webhooks";
4
- var runEvent = T.Union(emitterEventNames.map((o) => T.Literal(o)));
5
- var commandSchema = T.Object({
6
- description: T.String({ minLength: 1 }),
7
- "ubiquity:example": T.String({ minLength: 1 })
8
- });
9
- var manifestSchema = T.Object({
10
- name: T.String({ minLength: 1 }),
11
- description: T.Optional(T.String({ default: "" })),
12
- commands: T.Optional(T.Record(T.String(), commandSchema, { default: {} })),
13
- "ubiquity:listeners": T.Optional(T.Array(runEvent, { default: [] })),
14
- configuration: T.Optional(T.Record(T.String(), T.Any(), { default: {} }))
15
- });
16
- export {
17
- commandSchema,
18
- manifestSchema,
19
- runEvent
20
- };
File without changes
File without changes