codify-plugin-lib 1.0.57 → 1.0.58

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,4 @@
1
+ export declare class SudoError extends Error {
2
+ command: string;
3
+ constructor(command: string);
4
+ }
@@ -0,0 +1,7 @@
1
+ export class SudoError extends Error {
2
+ command;
3
+ constructor(command) {
4
+ super();
5
+ this.command = command;
6
+ }
7
+ }
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from './entities/change-set.js';
6
6
  export * from './entities/plan.js';
7
7
  export * from './entities/plan-types.js';
8
8
  export * from './entities/stateful-parameter.js';
9
+ export * from './entities/errors.js';
9
10
  export * from './utils/test-utils.js';
10
11
  export * from './utils/utils.js';
11
12
  export declare function runPlugin(plugin: Plugin): Promise<void>;
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ export * from './entities/change-set.js';
6
6
  export * from './entities/plan.js';
7
7
  export * from './entities/plan-types.js';
8
8
  export * from './entities/stateful-parameter.js';
9
+ export * from './entities/errors.js';
9
10
  export * from './utils/test-utils.js';
10
11
  export * from './utils/utils.js';
11
12
  export async function runPlugin(plugin) {
@@ -1,6 +1,7 @@
1
1
  import addFormats from 'ajv-formats';
2
2
  import { ApplyRequestDataSchema, ApplyResponseDataSchema, InitializeRequestDataSchema, InitializeResponseDataSchema, IpcMessageSchema, MessageStatus, PlanRequestDataSchema, PlanResponseDataSchema, ResourceSchema, ValidateRequestDataSchema, ValidateResponseDataSchema } from 'codify-schemas';
3
3
  import Ajv2020 from 'ajv/dist/2020.js';
4
+ import { SudoError } from '../entities/errors.js';
4
5
  const SupportedRequests = {
5
6
  'initialize': {
6
7
  requestValidator: InitializeRequestDataSchema,
@@ -81,6 +82,13 @@ export class MessageHandler {
81
82
  return;
82
83
  }
83
84
  const cmd = message.cmd + '_Response';
85
+ if (e instanceof SudoError) {
86
+ process.send?.({
87
+ cmd,
88
+ status: MessageStatus.ERROR,
89
+ data: `Plugin: '${this.plugin.name}'. Forbidden usage of sudo for command '${e.command}'. Please contact the plugin developer to fix this.`,
90
+ });
91
+ }
84
92
  const isDebug = process.env.DEBUG?.includes('*') ?? false;
85
93
  process.send?.({
86
94
  cmd,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.57",
3
+ "version": "1.0.58",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -0,0 +1,8 @@
1
+ export class SudoError extends Error {
2
+ command: string;
3
+
4
+ constructor(command: string) {
5
+ super();
6
+ this.command = command;
7
+ }
8
+ }
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ export * from './entities/change-set.js'
8
8
  export * from './entities/plan.js'
9
9
  export * from './entities/plan-types.js'
10
10
  export * from './entities/stateful-parameter.js'
11
+ export * from './entities/errors.js'
11
12
 
12
13
  export * from './utils/test-utils.js'
13
14
  export * from './utils/utils.js'
@@ -15,6 +15,7 @@ import {
15
15
  ValidateResponseDataSchema
16
16
  } from 'codify-schemas';
17
17
  import Ajv2020, { SchemaObject, ValidateFunction } from 'ajv/dist/2020.js';
18
+ import { SudoError } from '../entities/errors.js';
18
19
 
19
20
  const SupportedRequests: Record<string, { requestValidator: SchemaObject; responseValidator: SchemaObject; handler: (plugin: Plugin, data: any) => Promise<unknown> }> = {
20
21
  'initialize': {
@@ -115,6 +116,14 @@ export class MessageHandler {
115
116
  // @ts-ignore
116
117
  const cmd = message.cmd + '_Response';
117
118
 
119
+ if (e instanceof SudoError) {
120
+ process.send?.({
121
+ cmd,
122
+ status: MessageStatus.ERROR,
123
+ data: `Plugin: '${this.plugin.name}'. Forbidden usage of sudo for command '${e.command}'. Please contact the plugin developer to fix this.`,
124
+ })
125
+ }
126
+
118
127
  const isDebug = process.env.DEBUG?.includes('*') ?? false;
119
128
 
120
129
  process.send?.({