@ubiquity-os/plugin-sdk 3.0.0 → 3.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/index.js CHANGED
@@ -38,7 +38,7 @@ module.exports = __toCommonJS(src_exports);
38
38
 
39
39
  // src/server.ts
40
40
  var import_value2 = require("@sinclair/typebox/value");
41
- var import_ubiquity_os_logger2 = require("@ubiquity-os/ubiquity-os-logger");
41
+ var import_ubiquity_os_logger3 = require("@ubiquity-os/ubiquity-os-logger");
42
42
  var import_hono = require("hono");
43
43
  var import_adapter2 = require("hono/adapter");
44
44
  var import_http_exception = require("hono/http-exception");
@@ -255,6 +255,31 @@ ${metadataContent}
255
255
  }
256
256
  };
257
257
 
258
+ // src/error.ts
259
+ var import_ubiquity_os_logger2 = require("@ubiquity-os/ubiquity-os-logger");
260
+ function transformError(context2, error) {
261
+ let loggerError;
262
+ if (error instanceof AggregateError) {
263
+ loggerError = context2.logger.error(
264
+ error.errors.map((err) => {
265
+ if (err instanceof import_ubiquity_os_logger2.LogReturn) {
266
+ return err.logMessage.raw;
267
+ } else if (err instanceof Error) {
268
+ return err.message;
269
+ } else {
270
+ return err;
271
+ }
272
+ }).join("\n\n"),
273
+ { error }
274
+ );
275
+ } else if (error instanceof Error || error instanceof import_ubiquity_os_logger2.LogReturn) {
276
+ loggerError = error;
277
+ } else {
278
+ loggerError = context2.logger.error(String(error));
279
+ }
280
+ return loggerError;
281
+ }
282
+
258
283
  // src/octokit.ts
259
284
  var import_core = require("@octokit/core");
260
285
  var import_plugin_paginate_rest = require("@octokit/plugin-paginate-rest");
@@ -409,7 +434,7 @@ function createPlugin(handler, manifest, options) {
409
434
  octokit: new customOctokit({ auth: inputs.authToken }),
410
435
  config: config2,
411
436
  env,
412
- logger: new import_ubiquity_os_logger2.Logs(pluginOptions.logLevel),
437
+ logger: new import_ubiquity_os_logger3.Logs(pluginOptions.logLevel),
413
438
  commentHandler: new CommentHandler()
414
439
  };
415
440
  try {
@@ -417,12 +442,7 @@ function createPlugin(handler, manifest, options) {
417
442
  return ctx.json({ stateId: inputs.stateId, output: result ?? {} });
418
443
  } catch (error) {
419
444
  console.error(error);
420
- let loggerError;
421
- if (error instanceof Error || error instanceof import_ubiquity_os_logger2.LogReturn) {
422
- loggerError = error;
423
- } else {
424
- loggerError = context2.logger.error(`Error: ${error}`);
425
- }
445
+ const loggerError = transformError(context2, error);
426
446
  if (pluginOptions.postCommentOnError && loggerError) {
427
447
  await context2.commentHandler.postComment(context2, loggerError);
428
448
  }
@@ -436,7 +456,7 @@ function createPlugin(handler, manifest, options) {
436
456
  var core = __toESM(require("@actions/core"));
437
457
  var github2 = __toESM(require("@actions/github"));
438
458
  var import_value3 = require("@sinclair/typebox/value");
439
- var import_ubiquity_os_logger3 = require("@ubiquity-os/ubiquity-os-logger");
459
+ var import_ubiquity_os_logger4 = require("@ubiquity-os/ubiquity-os-logger");
440
460
  var import_dotenv = require("dotenv");
441
461
  (0, import_dotenv.config)();
442
462
  async function createActionsPlugin(handler, options) {
@@ -501,7 +521,7 @@ async function createActionsPlugin(handler, options) {
501
521
  octokit: new customOctokit({ auth: inputs.authToken }),
502
522
  config: config2,
503
523
  env,
504
- logger: new import_ubiquity_os_logger3.Logs(pluginOptions.logLevel),
524
+ logger: new import_ubiquity_os_logger4.Logs(pluginOptions.logLevel),
505
525
  commentHandler: new CommentHandler()
506
526
  };
507
527
  try {
@@ -510,16 +530,11 @@ async function createActionsPlugin(handler, options) {
510
530
  await returnDataToKernel(pluginGithubToken, inputs.stateId, result);
511
531
  } catch (error) {
512
532
  console.error(error);
513
- let loggerError;
514
- if (error instanceof Error) {
515
- core.setFailed(error);
516
- loggerError = context2.logger.error(`Error: ${error}`, { error });
517
- } else if (error instanceof import_ubiquity_os_logger3.LogReturn) {
518
- core.setFailed(error.logMessage.raw);
519
- loggerError = error;
520
- } else {
521
- core.setFailed(`Error: ${error}`);
522
- loggerError = context2.logger.error(`Error: ${error}`);
533
+ const loggerError = transformError(context2, error);
534
+ if (loggerError instanceof import_ubiquity_os_logger4.LogReturn) {
535
+ core.setFailed(loggerError.logMessage.diff);
536
+ } else if (loggerError instanceof Error) {
537
+ core.setFailed(loggerError);
523
538
  }
524
539
  if (pluginOptions.postCommentOnError && loggerError) {
525
540
  await context2.commentHandler.postComment(context2, loggerError);
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/server.ts
2
2
  import { Value as Value2 } from "@sinclair/typebox/value";
3
- import { LogReturn as LogReturn2, Logs } from "@ubiquity-os/ubiquity-os-logger";
3
+ import { Logs } from "@ubiquity-os/ubiquity-os-logger";
4
4
  import { Hono } from "hono";
5
5
  import { env as honoEnv } from "hono/adapter";
6
6
  import { HTTPException } from "hono/http-exception";
@@ -217,6 +217,31 @@ ${metadataContent}
217
217
  }
218
218
  };
219
219
 
220
+ // src/error.ts
221
+ import { LogReturn as LogReturn2 } from "@ubiquity-os/ubiquity-os-logger";
222
+ function transformError(context2, error) {
223
+ let loggerError;
224
+ if (error instanceof AggregateError) {
225
+ loggerError = context2.logger.error(
226
+ error.errors.map((err) => {
227
+ if (err instanceof LogReturn2) {
228
+ return err.logMessage.raw;
229
+ } else if (err instanceof Error) {
230
+ return err.message;
231
+ } else {
232
+ return err;
233
+ }
234
+ }).join("\n\n"),
235
+ { error }
236
+ );
237
+ } else if (error instanceof Error || error instanceof LogReturn2) {
238
+ loggerError = error;
239
+ } else {
240
+ loggerError = context2.logger.error(String(error));
241
+ }
242
+ return loggerError;
243
+ }
244
+
220
245
  // src/octokit.ts
221
246
  import { Octokit } from "@octokit/core";
222
247
  import { paginateRest } from "@octokit/plugin-paginate-rest";
@@ -379,12 +404,7 @@ function createPlugin(handler, manifest, options) {
379
404
  return ctx.json({ stateId: inputs.stateId, output: result ?? {} });
380
405
  } catch (error) {
381
406
  console.error(error);
382
- let loggerError;
383
- if (error instanceof Error || error instanceof LogReturn2) {
384
- loggerError = error;
385
- } else {
386
- loggerError = context2.logger.error(`Error: ${error}`);
387
- }
407
+ const loggerError = transformError(context2, error);
388
408
  if (pluginOptions.postCommentOnError && loggerError) {
389
409
  await context2.commentHandler.postComment(context2, loggerError);
390
410
  }
@@ -472,16 +492,11 @@ async function createActionsPlugin(handler, options) {
472
492
  await returnDataToKernel(pluginGithubToken, inputs.stateId, result);
473
493
  } catch (error) {
474
494
  console.error(error);
475
- let loggerError;
476
- if (error instanceof Error) {
477
- core.setFailed(error);
478
- loggerError = context2.logger.error(`Error: ${error}`, { error });
479
- } else if (error instanceof LogReturn3) {
480
- core.setFailed(error.logMessage.raw);
481
- loggerError = error;
482
- } else {
483
- core.setFailed(`Error: ${error}`);
484
- loggerError = context2.logger.error(`Error: ${error}`);
495
+ const loggerError = transformError(context2, error);
496
+ if (loggerError instanceof LogReturn3) {
497
+ core.setFailed(loggerError.logMessage.diff);
498
+ } else if (loggerError instanceof Error) {
499
+ core.setFailed(loggerError);
485
500
  }
486
501
  if (pluginOptions.postCommentOnError && loggerError) {
487
502
  await context2.commentHandler.postComment(context2, loggerError);
@@ -1,3 +1,34 @@
1
+ import { EmitterWebhookEventName, EmitterWebhookEvent } from '@octokit/webhooks';
2
+ import * as _sinclair_typebox from '@sinclair/typebox';
3
+ import { StaticDecode } from '@sinclair/typebox';
4
+
5
+ declare const commandCallSchema: _sinclair_typebox.TUnion<[_sinclair_typebox.TNull, _sinclair_typebox.TObject<{
6
+ name: _sinclair_typebox.TString;
7
+ parameters: _sinclair_typebox.TUnknown;
8
+ }>]>;
9
+ type CommandCall = StaticDecode<typeof commandCallSchema>;
10
+
11
+ declare class PluginInput<T extends EmitterWebhookEventName = EmitterWebhookEventName> {
12
+ private _privateKey;
13
+ stateId: string;
14
+ eventName: T;
15
+ eventPayload: EmitterWebhookEvent<T>["payload"];
16
+ settings: unknown;
17
+ authToken: string;
18
+ ref: string;
19
+ command: CommandCall;
20
+ constructor(privateKey: string, stateId: string, eventName: T, eventPayload: EmitterWebhookEvent<T>["payload"], settings: unknown, authToken: string, ref: string, command: CommandCall);
21
+ getInputs(): Promise<{
22
+ signature: string;
23
+ stateId: string;
24
+ eventName: T;
25
+ eventPayload: string;
26
+ settings: string;
27
+ authToken: string;
28
+ ref: string;
29
+ command: string;
30
+ }>;
31
+ }
1
32
  interface Inputs {
2
33
  stateId: unknown;
3
34
  eventName: unknown;
@@ -10,4 +41,4 @@ interface Inputs {
10
41
  declare function verifySignature(publicKeyPem: string, inputs: Inputs, signature: string): Promise<boolean>;
11
42
  declare function signPayload(payload: string, privateKey: string): Promise<string>;
12
43
 
13
- export { signPayload, verifySignature };
44
+ export { PluginInput, signPayload, verifySignature };
@@ -1,3 +1,34 @@
1
+ import { EmitterWebhookEventName, EmitterWebhookEvent } from '@octokit/webhooks';
2
+ import * as _sinclair_typebox from '@sinclair/typebox';
3
+ import { StaticDecode } from '@sinclair/typebox';
4
+
5
+ declare const commandCallSchema: _sinclair_typebox.TUnion<[_sinclair_typebox.TNull, _sinclair_typebox.TObject<{
6
+ name: _sinclair_typebox.TString;
7
+ parameters: _sinclair_typebox.TUnknown;
8
+ }>]>;
9
+ type CommandCall = StaticDecode<typeof commandCallSchema>;
10
+
11
+ declare class PluginInput<T extends EmitterWebhookEventName = EmitterWebhookEventName> {
12
+ private _privateKey;
13
+ stateId: string;
14
+ eventName: T;
15
+ eventPayload: EmitterWebhookEvent<T>["payload"];
16
+ settings: unknown;
17
+ authToken: string;
18
+ ref: string;
19
+ command: CommandCall;
20
+ constructor(privateKey: string, stateId: string, eventName: T, eventPayload: EmitterWebhookEvent<T>["payload"], settings: unknown, authToken: string, ref: string, command: CommandCall);
21
+ getInputs(): Promise<{
22
+ signature: string;
23
+ stateId: string;
24
+ eventName: T;
25
+ eventPayload: string;
26
+ settings: string;
27
+ authToken: string;
28
+ ref: string;
29
+ command: string;
30
+ }>;
31
+ }
1
32
  interface Inputs {
2
33
  stateId: unknown;
3
34
  eventName: unknown;
@@ -10,4 +41,4 @@ interface Inputs {
10
41
  declare function verifySignature(publicKeyPem: string, inputs: Inputs, signature: string): Promise<boolean>;
11
42
  declare function signPayload(payload: string, privateKey: string): Promise<string>;
12
43
 
13
- export { signPayload, verifySignature };
44
+ export { PluginInput, signPayload, verifySignature };
package/dist/signature.js CHANGED
@@ -20,10 +20,47 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/signature.ts
21
21
  var signature_exports = {};
22
22
  __export(signature_exports, {
23
+ PluginInput: () => PluginInput,
23
24
  signPayload: () => signPayload,
24
25
  verifySignature: () => verifySignature
25
26
  });
26
27
  module.exports = __toCommonJS(signature_exports);
28
+ var PluginInput = class {
29
+ _privateKey;
30
+ stateId;
31
+ eventName;
32
+ eventPayload;
33
+ settings;
34
+ authToken;
35
+ ref;
36
+ command;
37
+ constructor(privateKey, stateId, eventName, eventPayload, settings, authToken, ref, command) {
38
+ this._privateKey = privateKey;
39
+ this.stateId = stateId;
40
+ this.eventName = eventName;
41
+ this.eventPayload = eventPayload;
42
+ this.settings = settings;
43
+ this.authToken = authToken;
44
+ this.ref = ref;
45
+ this.command = command;
46
+ }
47
+ async getInputs() {
48
+ const inputs = {
49
+ stateId: this.stateId,
50
+ eventName: this.eventName,
51
+ eventPayload: JSON.stringify(this.eventPayload),
52
+ settings: JSON.stringify(this.settings),
53
+ authToken: this.authToken,
54
+ ref: this.ref,
55
+ command: JSON.stringify(this.command)
56
+ };
57
+ const signature = await signPayload(JSON.stringify(inputs), this._privateKey);
58
+ return {
59
+ ...inputs,
60
+ signature
61
+ };
62
+ }
63
+ };
27
64
  async function verifySignature(publicKeyPem, inputs, signature) {
28
65
  try {
29
66
  const inputsOrdered = {
@@ -77,6 +114,7 @@ async function signPayload(payload, privateKey) {
77
114
  }
78
115
  // Annotate the CommonJS export names for ESM import in node:
79
116
  0 && (module.exports = {
117
+ PluginInput,
80
118
  signPayload,
81
119
  verifySignature
82
120
  });
@@ -1,4 +1,40 @@
1
1
  // src/signature.ts
2
+ var PluginInput = class {
3
+ _privateKey;
4
+ stateId;
5
+ eventName;
6
+ eventPayload;
7
+ settings;
8
+ authToken;
9
+ ref;
10
+ command;
11
+ constructor(privateKey, stateId, eventName, eventPayload, settings, authToken, ref, command) {
12
+ this._privateKey = privateKey;
13
+ this.stateId = stateId;
14
+ this.eventName = eventName;
15
+ this.eventPayload = eventPayload;
16
+ this.settings = settings;
17
+ this.authToken = authToken;
18
+ this.ref = ref;
19
+ this.command = command;
20
+ }
21
+ async getInputs() {
22
+ const inputs = {
23
+ stateId: this.stateId,
24
+ eventName: this.eventName,
25
+ eventPayload: JSON.stringify(this.eventPayload),
26
+ settings: JSON.stringify(this.settings),
27
+ authToken: this.authToken,
28
+ ref: this.ref,
29
+ command: JSON.stringify(this.command)
30
+ };
31
+ const signature = await signPayload(JSON.stringify(inputs), this._privateKey);
32
+ return {
33
+ ...inputs,
34
+ signature
35
+ };
36
+ }
37
+ };
2
38
  async function verifySignature(publicKeyPem, inputs, signature) {
3
39
  try {
4
40
  const inputsOrdered = {
@@ -51,6 +87,7 @@ async function signPayload(payload, privateKey) {
51
87
  return btoa(String.fromCharCode(...new Uint8Array(signature)));
52
88
  }
53
89
  export {
90
+ PluginInput,
54
91
  signPayload,
55
92
  verifySignature
56
93
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubiquity-os/plugin-sdk",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "SDK for plugin support.",
5
5
  "author": "Ubiquity DAO",
6
6
  "license": "MIT",