@ubiquity-os/plugin-sdk 2.0.1 → 2.0.2

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.js CHANGED
@@ -37,8 +37,7 @@ __export(src_exports, {
37
37
  module.exports = __toCommonJS(src_exports);
38
38
 
39
39
  // src/server.ts
40
- var import_typebox = require("@sinclair/typebox");
41
- var import_value = require("@sinclair/typebox/value");
40
+ var import_value2 = require("@sinclair/typebox/value");
42
41
  var import_ubiquity_os_logger2 = require("@ubiquity-os/ubiquity-os-logger");
43
42
  var import_hono = require("hono");
44
43
  var import_adapter2 = require("hono/adapter");
@@ -259,17 +258,36 @@ async function verifySignature(publicKeyPem, inputs, signature) {
259
258
  }
260
259
  }
261
260
 
262
- // src/server.ts
263
- var inputSchema = import_typebox.Type.Object({
264
- stateId: import_typebox.Type.String(),
265
- eventName: import_typebox.Type.String(),
266
- eventPayload: import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.Any()),
267
- command: import_typebox.Type.Union([import_typebox.Type.Null(), import_typebox.Type.Object({ name: import_typebox.Type.String(), parameters: import_typebox.Type.Unknown() })]),
268
- authToken: import_typebox.Type.String(),
269
- settings: import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.Any()),
270
- ref: import_typebox.Type.String(),
271
- signature: import_typebox.Type.String()
261
+ // src/types/input-schema.ts
262
+ var import_typebox3 = require("@sinclair/typebox");
263
+
264
+ // src/types/command.ts
265
+ var import_typebox = require("@sinclair/typebox");
266
+ var commandCallSchema = import_typebox.Type.Union([import_typebox.Type.Null(), import_typebox.Type.Object({ name: import_typebox.Type.String(), parameters: import_typebox.Type.Unknown() })]);
267
+
268
+ // src/types/util.ts
269
+ var import_typebox2 = require("@sinclair/typebox");
270
+ var import_value = require("@sinclair/typebox/value");
271
+ function jsonType(type) {
272
+ return import_typebox2.Type.Transform(import_typebox2.Type.String()).Decode((value) => {
273
+ const parsed = JSON.parse(value);
274
+ return import_value.Value.Decode(type, import_value.Value.Default(type, parsed));
275
+ }).Encode((value) => JSON.stringify(value));
276
+ }
277
+
278
+ // src/types/input-schema.ts
279
+ var inputSchema = import_typebox3.Type.Object({
280
+ stateId: import_typebox3.Type.String(),
281
+ eventName: import_typebox3.Type.String(),
282
+ eventPayload: jsonType(import_typebox3.Type.Record(import_typebox3.Type.String(), import_typebox3.Type.Any())),
283
+ command: jsonType(commandCallSchema),
284
+ authToken: import_typebox3.Type.String(),
285
+ settings: jsonType(import_typebox3.Type.Record(import_typebox3.Type.String(), import_typebox3.Type.Any())),
286
+ ref: import_typebox3.Type.String(),
287
+ signature: import_typebox3.Type.String()
272
288
  });
289
+
290
+ // src/server.ts
273
291
  function createPlugin(handler, manifest, options) {
274
292
  const pluginOptions = getPluginOptions(options);
275
293
  const app = new import_hono.Hono();
@@ -281,22 +299,22 @@ function createPlugin(handler, manifest, options) {
281
299
  throw new import_http_exception.HTTPException(400, { message: "Content-Type must be application/json" });
282
300
  }
283
301
  const body = await ctx.req.json();
284
- const inputSchemaErrors = [...import_value.Value.Errors(inputSchema, body)];
302
+ const inputSchemaErrors = [...import_value2.Value.Errors(inputSchema, body)];
285
303
  if (inputSchemaErrors.length) {
286
304
  console.log(inputSchemaErrors, { depth: null });
287
305
  throw new import_http_exception.HTTPException(400, { message: "Invalid body" });
288
306
  }
289
- const inputs = import_value.Value.Decode(inputSchema, body);
290
- const signature = inputs.signature;
291
- if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, inputs, signature)) {
307
+ const signature = body.signature;
308
+ if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
292
309
  throw new import_http_exception.HTTPException(400, { message: "Invalid signature" });
293
310
  }
311
+ const inputs = import_value2.Value.Decode(inputSchema, body);
294
312
  let config2;
295
313
  if (pluginOptions.settingsSchema) {
296
314
  try {
297
- config2 = import_value.Value.Decode(pluginOptions.settingsSchema, import_value.Value.Default(pluginOptions.settingsSchema, inputs.settings));
315
+ config2 = import_value2.Value.Decode(pluginOptions.settingsSchema, import_value2.Value.Default(pluginOptions.settingsSchema, inputs.settings));
298
316
  } catch (e) {
299
- console.log(...import_value.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
317
+ console.log(...import_value2.Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
300
318
  throw e;
301
319
  }
302
320
  } else {
@@ -306,9 +324,9 @@ function createPlugin(handler, manifest, options) {
306
324
  const honoEnvironment = (0, import_adapter2.env)(ctx);
307
325
  if (pluginOptions.envSchema) {
308
326
  try {
309
- env = import_value.Value.Decode(pluginOptions.envSchema, import_value.Value.Default(pluginOptions.envSchema, honoEnvironment));
327
+ env = import_value2.Value.Decode(pluginOptions.envSchema, import_value2.Value.Default(pluginOptions.envSchema, honoEnvironment));
310
328
  } catch (e) {
311
- console.log(...import_value.Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
329
+ console.log(...import_value2.Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
312
330
  throw e;
313
331
  }
314
332
  } else {
@@ -319,9 +337,9 @@ function createPlugin(handler, manifest, options) {
319
337
  let command = null;
320
338
  if (inputs.command && pluginOptions.commandSchema) {
321
339
  try {
322
- command = import_value.Value.Decode(pluginOptions.commandSchema, import_value.Value.Default(pluginOptions.commandSchema, inputs.command));
340
+ command = import_value2.Value.Decode(pluginOptions.commandSchema, import_value2.Value.Default(pluginOptions.commandSchema, inputs.command));
323
341
  } catch (e) {
324
- console.log(...import_value.Value.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
342
+ console.log(...import_value2.Value.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
325
343
  throw e;
326
344
  }
327
345
  } else if (inputs.command) {
@@ -359,37 +377,10 @@ function createPlugin(handler, manifest, options) {
359
377
  // src/actions.ts
360
378
  var core = __toESM(require("@actions/core"));
361
379
  var github2 = __toESM(require("@actions/github"));
362
- var import_typebox4 = require("@sinclair/typebox");
363
380
  var import_value3 = require("@sinclair/typebox/value");
364
381
  var import_ubiquity_os_logger3 = require("@ubiquity-os/ubiquity-os-logger");
365
382
  var import_dotenv = require("dotenv");
366
-
367
- // src/types/command.ts
368
- var import_typebox2 = require("@sinclair/typebox");
369
- var commandCallSchema = import_typebox2.Type.Union([import_typebox2.Type.Null(), import_typebox2.Type.Object({ name: import_typebox2.Type.String(), parameters: import_typebox2.Type.Unknown() })]);
370
-
371
- // src/types/util.ts
372
- var import_typebox3 = require("@sinclair/typebox");
373
- var import_value2 = require("@sinclair/typebox/value");
374
- function jsonType(type) {
375
- return import_typebox3.Type.Transform(import_typebox3.Type.String()).Decode((value) => {
376
- const parsed = JSON.parse(value);
377
- return import_value2.Value.Decode(type, import_value2.Value.Default(type, parsed));
378
- }).Encode((value) => JSON.stringify(value));
379
- }
380
-
381
- // src/actions.ts
382
383
  (0, import_dotenv.config)();
383
- var inputSchema2 = import_typebox4.Type.Object({
384
- stateId: import_typebox4.Type.String(),
385
- eventName: import_typebox4.Type.String(),
386
- eventPayload: jsonType(import_typebox4.Type.Record(import_typebox4.Type.String(), import_typebox4.Type.Any())),
387
- command: jsonType(commandCallSchema),
388
- authToken: import_typebox4.Type.String(),
389
- settings: jsonType(import_typebox4.Type.Record(import_typebox4.Type.String(), import_typebox4.Type.Any())),
390
- ref: import_typebox4.Type.String(),
391
- signature: import_typebox4.Type.String()
392
- });
393
384
  async function createActionsPlugin(handler, options) {
394
385
  const pluginOptions = getPluginOptions(options);
395
386
  const pluginGithubToken = process.env.PLUGIN_GITHUB_TOKEN;
@@ -404,13 +395,13 @@ async function createActionsPlugin(handler, options) {
404
395
  return;
405
396
  }
406
397
  const inputPayload = github2.context.payload.inputs;
407
- const inputSchemaErrors = [...import_value3.Value.Errors(inputSchema2, inputPayload)];
398
+ const inputSchemaErrors = [...import_value3.Value.Errors(inputSchema, inputPayload)];
408
399
  if (inputSchemaErrors.length) {
409
400
  console.dir(inputSchemaErrors, { depth: null });
410
401
  core.setFailed(`Error: Invalid inputs payload: ${inputSchemaErrors.join(",")}`);
411
402
  return;
412
403
  }
413
- const inputs = import_value3.Value.Decode(inputSchema2, inputPayload);
404
+ const inputs = import_value3.Value.Decode(inputSchema, inputPayload);
414
405
  let config2;
415
406
  if (pluginOptions.settingsSchema) {
416
407
  try {
package/dist/index.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  // src/server.ts
2
- import { Type as T } from "@sinclair/typebox";
3
- import { Value } from "@sinclair/typebox/value";
2
+ import { Value as Value2 } from "@sinclair/typebox/value";
4
3
  import { LogReturn as LogReturn2, Logs } from "@ubiquity-os/ubiquity-os-logger";
5
4
  import { Hono } from "hono";
6
5
  import { env as honoEnv } from "hono/adapter";
@@ -221,17 +220,36 @@ async function verifySignature(publicKeyPem, inputs, signature) {
221
220
  }
222
221
  }
223
222
 
224
- // src/server.ts
225
- var inputSchema = T.Object({
226
- stateId: T.String(),
227
- eventName: T.String(),
228
- eventPayload: T.Record(T.String(), T.Any()),
229
- command: T.Union([T.Null(), T.Object({ name: T.String(), parameters: T.Unknown() })]),
230
- authToken: T.String(),
231
- settings: T.Record(T.String(), T.Any()),
232
- ref: T.String(),
233
- signature: T.String()
223
+ // src/types/input-schema.ts
224
+ import { Type as T2 } from "@sinclair/typebox";
225
+
226
+ // src/types/command.ts
227
+ import { Type as T } from "@sinclair/typebox";
228
+ var commandCallSchema = T.Union([T.Null(), T.Object({ name: T.String(), parameters: T.Unknown() })]);
229
+
230
+ // src/types/util.ts
231
+ import { Type } from "@sinclair/typebox";
232
+ import { Value } from "@sinclair/typebox/value";
233
+ function jsonType(type) {
234
+ return Type.Transform(Type.String()).Decode((value) => {
235
+ const parsed = JSON.parse(value);
236
+ return Value.Decode(type, Value.Default(type, parsed));
237
+ }).Encode((value) => JSON.stringify(value));
238
+ }
239
+
240
+ // src/types/input-schema.ts
241
+ var inputSchema = T2.Object({
242
+ stateId: T2.String(),
243
+ eventName: T2.String(),
244
+ eventPayload: jsonType(T2.Record(T2.String(), T2.Any())),
245
+ command: jsonType(commandCallSchema),
246
+ authToken: T2.String(),
247
+ settings: jsonType(T2.Record(T2.String(), T2.Any())),
248
+ ref: T2.String(),
249
+ signature: T2.String()
234
250
  });
251
+
252
+ // src/server.ts
235
253
  function createPlugin(handler, manifest, options) {
236
254
  const pluginOptions = getPluginOptions(options);
237
255
  const app = new Hono();
@@ -243,22 +261,22 @@ function createPlugin(handler, manifest, options) {
243
261
  throw new HTTPException(400, { message: "Content-Type must be application/json" });
244
262
  }
245
263
  const body = await ctx.req.json();
246
- const inputSchemaErrors = [...Value.Errors(inputSchema, body)];
264
+ const inputSchemaErrors = [...Value2.Errors(inputSchema, body)];
247
265
  if (inputSchemaErrors.length) {
248
266
  console.log(inputSchemaErrors, { depth: null });
249
267
  throw new HTTPException(400, { message: "Invalid body" });
250
268
  }
251
- const inputs = Value.Decode(inputSchema, body);
252
- const signature = inputs.signature;
253
- if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, inputs, signature)) {
269
+ const signature = body.signature;
270
+ if (!pluginOptions.bypassSignatureVerification && !await verifySignature(pluginOptions.kernelPublicKey, body, signature)) {
254
271
  throw new HTTPException(400, { message: "Invalid signature" });
255
272
  }
273
+ const inputs = Value2.Decode(inputSchema, body);
256
274
  let config2;
257
275
  if (pluginOptions.settingsSchema) {
258
276
  try {
259
- config2 = Value.Decode(pluginOptions.settingsSchema, Value.Default(pluginOptions.settingsSchema, inputs.settings));
277
+ config2 = Value2.Decode(pluginOptions.settingsSchema, Value2.Default(pluginOptions.settingsSchema, inputs.settings));
260
278
  } catch (e) {
261
- console.log(...Value.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
279
+ console.log(...Value2.Errors(pluginOptions.settingsSchema, inputs.settings), { depth: null });
262
280
  throw e;
263
281
  }
264
282
  } else {
@@ -268,9 +286,9 @@ function createPlugin(handler, manifest, options) {
268
286
  const honoEnvironment = honoEnv(ctx);
269
287
  if (pluginOptions.envSchema) {
270
288
  try {
271
- env = Value.Decode(pluginOptions.envSchema, Value.Default(pluginOptions.envSchema, honoEnvironment));
289
+ env = Value2.Decode(pluginOptions.envSchema, Value2.Default(pluginOptions.envSchema, honoEnvironment));
272
290
  } catch (e) {
273
- console.log(...Value.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
291
+ console.log(...Value2.Errors(pluginOptions.envSchema, honoEnvironment), { depth: null });
274
292
  throw e;
275
293
  }
276
294
  } else {
@@ -281,9 +299,9 @@ function createPlugin(handler, manifest, options) {
281
299
  let command = null;
282
300
  if (inputs.command && pluginOptions.commandSchema) {
283
301
  try {
284
- command = Value.Decode(pluginOptions.commandSchema, Value.Default(pluginOptions.commandSchema, inputs.command));
302
+ command = Value2.Decode(pluginOptions.commandSchema, Value2.Default(pluginOptions.commandSchema, inputs.command));
285
303
  } catch (e) {
286
- console.log(...Value.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
304
+ console.log(...Value2.Errors(pluginOptions.commandSchema, inputs.command), { depth: null });
287
305
  throw e;
288
306
  }
289
307
  } else if (inputs.command) {
@@ -321,37 +339,10 @@ function createPlugin(handler, manifest, options) {
321
339
  // src/actions.ts
322
340
  import * as core from "@actions/core";
323
341
  import * as github2 from "@actions/github";
324
- import { Type as T3 } from "@sinclair/typebox";
325
342
  import { Value as Value3 } from "@sinclair/typebox/value";
326
343
  import { LogReturn as LogReturn3, Logs as Logs2 } from "@ubiquity-os/ubiquity-os-logger";
327
344
  import { config } from "dotenv";
328
-
329
- // src/types/command.ts
330
- import { Type as T2 } from "@sinclair/typebox";
331
- var commandCallSchema = T2.Union([T2.Null(), T2.Object({ name: T2.String(), parameters: T2.Unknown() })]);
332
-
333
- // src/types/util.ts
334
- import { Type } from "@sinclair/typebox";
335
- import { Value as Value2 } from "@sinclair/typebox/value";
336
- function jsonType(type) {
337
- return Type.Transform(Type.String()).Decode((value) => {
338
- const parsed = JSON.parse(value);
339
- return Value2.Decode(type, Value2.Default(type, parsed));
340
- }).Encode((value) => JSON.stringify(value));
341
- }
342
-
343
- // src/actions.ts
344
345
  config();
345
- var inputSchema2 = T3.Object({
346
- stateId: T3.String(),
347
- eventName: T3.String(),
348
- eventPayload: jsonType(T3.Record(T3.String(), T3.Any())),
349
- command: jsonType(commandCallSchema),
350
- authToken: T3.String(),
351
- settings: jsonType(T3.Record(T3.String(), T3.Any())),
352
- ref: T3.String(),
353
- signature: T3.String()
354
- });
355
346
  async function createActionsPlugin(handler, options) {
356
347
  const pluginOptions = getPluginOptions(options);
357
348
  const pluginGithubToken = process.env.PLUGIN_GITHUB_TOKEN;
@@ -366,13 +357,13 @@ async function createActionsPlugin(handler, options) {
366
357
  return;
367
358
  }
368
359
  const inputPayload = github2.context.payload.inputs;
369
- const inputSchemaErrors = [...Value3.Errors(inputSchema2, inputPayload)];
360
+ const inputSchemaErrors = [...Value3.Errors(inputSchema, inputPayload)];
370
361
  if (inputSchemaErrors.length) {
371
362
  console.dir(inputSchemaErrors, { depth: null });
372
363
  core.setFailed(`Error: Invalid inputs payload: ${inputSchemaErrors.join(",")}`);
373
364
  return;
374
365
  }
375
- const inputs = Value3.Decode(inputSchema2, inputPayload);
366
+ const inputs = Value3.Decode(inputSchema, inputPayload);
376
367
  let config2;
377
368
  if (pluginOptions.settingsSchema) {
378
369
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubiquity-os/plugin-sdk",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "SDK for plugin support.",
5
5
  "author": "Ubiquity DAO",
6
6
  "license": "MIT",