@codifycli/plugin-core 1.1.0-beta18 → 1.1.0-beta20

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.
@@ -1,4 +1,4 @@
1
- import { ApplyRequestDataSchema, EmptyResponseDataSchema, ErrorCode, GetResourceInfoRequestDataSchema, GetResourceInfoResponseDataSchema, ImportRequestDataSchema, ImportResponseDataSchema, InitializeRequestDataSchema, InitializeResponseDataSchema, IpcMessageSchema, IpcMessageV2Schema, MatchRequestDataSchema, MatchResponseDataSchema, MessageStatus, PlanRequestDataSchema, PlanResponseDataSchema, ResourceSchema, SetVerbosityRequestDataSchema, ValidateRequestDataSchema, ValidateResponseDataSchema } from '@codifycli/schemas';
1
+ import { ApplyRequestDataSchema, EmptyResponseDataSchema, GetResourceInfoRequestDataSchema, GetResourceInfoResponseDataSchema, ImportRequestDataSchema, ImportResponseDataSchema, InitializeRequestDataSchema, InitializeResponseDataSchema, IpcMessageSchema, IpcMessageV2Schema, MatchRequestDataSchema, MatchResponseDataSchema, MessageStatus, PlanRequestDataSchema, PlanResponseDataSchema, ResourceSchema, SetVerbosityRequestDataSchema, ValidateRequestDataSchema, ValidateResponseDataSchema } from '@codifycli/schemas';
2
2
  import { Ajv } from 'ajv';
3
3
  import addFormats from 'ajv-formats';
4
4
  import { ApplyValidationError } from '../common/errors.js';
@@ -114,37 +114,30 @@ export class MessageHandler {
114
114
  }
115
115
  // @ts-expect-error TS2239
116
116
  const cmd = message.cmd + '_Response';
117
+ // @ts-expect-error TS2239
118
+ const requestId = message.requestId || undefined;
119
+ let errorPayload;
117
120
  if (e instanceof SudoError) {
118
- return process.send?.({
119
- cmd,
120
- // @ts-expect-error TS2239
121
- requestId: message.requestId || undefined,
122
- data: `Plugin: '${this.plugin.name}'. Forbidden usage of sudo for command '${e.command}'. Please contact the plugin developer to fix this.`,
123
- status: MessageStatus.ERROR,
124
- });
121
+ errorPayload = {
122
+ errorType: 'sudo_error',
123
+ message: `Plugin: '${this.plugin.name}'. Forbidden usage of sudo for command '${e.command}'. Please contact the plugin developer to fix this.`,
124
+ data: { command: e.command, pluginName: this.plugin.name },
125
+ };
125
126
  }
126
- if (e instanceof ApplyValidationError) {
127
- return process.send?.({
128
- cmd,
129
- // @ts-expect-error TS2239
130
- requestId: message.requestId || undefined,
131
- data: {
132
- errorCode: ErrorCode.APPLY_VALIDATION,
133
- plan: e.plan.toResponse(),
134
- },
135
- status: MessageStatus.ERROR,
136
- });
127
+ else if (e instanceof ApplyValidationError) {
128
+ errorPayload = {
129
+ errorType: 'apply_validation',
130
+ message: e.message,
131
+ data: { plan: e.plan.toResponse() },
132
+ };
137
133
  }
138
- const isDebug = process.env.DEBUG?.includes('*') ?? false;
139
- process.send?.({
140
- cmd,
141
- // @ts-expect-error TS2239
142
- requestId: message.requestId || undefined,
143
- data: {
144
- errorCode: ErrorCode.UNKNOWN,
134
+ else {
135
+ const isDebug = process.env.DEBUG?.includes('*') ?? false;
136
+ errorPayload = {
137
+ errorType: 'unknown',
145
138
  message: isDebug ? (e.stack ?? e.message) : e.message,
146
- },
147
- status: MessageStatus.ERROR,
148
- });
139
+ };
140
+ }
141
+ process.send?.({ cmd, requestId, data: errorPayload, status: MessageStatus.ERROR });
149
142
  }
150
143
  }
@@ -177,7 +177,7 @@ export class Plugin {
177
177
  return result;
178
178
  });
179
179
  if (validationPlan.requiresChanges()) {
180
- throw new ApplyValidationError(plan);
180
+ throw new ApplyValidationError(validationPlan);
181
181
  }
182
182
  }
183
183
  async setVerbosityLevel(data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codifycli/plugin-core",
3
- "version": "1.1.0-beta18",
3
+ "version": "1.1.0-beta20",
4
4
  "description": "TypeScript library for building Codify plugins to manage system resources (applications, CLI tools, settings) through infrastructure-as-code",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "license": "ISC",
37
37
  "dependencies": {
38
- "@codifycli/schemas": "^1.1.0-beta7",
38
+ "@codifycli/schemas": "^1.1.0-beta8",
39
39
  "@homebridge/node-pty-prebuilt-multiarch": "^0.13.1",
40
40
  "ajv": "^8.18.0",
41
41
  "ajv-formats": "^2.1.1",
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  ApplyRequestDataSchema,
3
3
  EmptyResponseDataSchema,
4
- ErrorCode,
5
4
  GetResourceInfoRequestDataSchema,
6
5
  GetResourceInfoResponseDataSchema,
7
6
  ImportRequestDataSchema,
@@ -15,6 +14,7 @@ import {
15
14
  MatchRequestDataSchema,
16
15
  MatchResponseDataSchema,
17
16
  MessageStatus,
17
+ PluginErrorData,
18
18
  PlanRequestDataSchema,
19
19
  PlanResponseDataSchema,
20
20
  ResourceSchema,
@@ -159,41 +159,31 @@ export class MessageHandler {
159
159
 
160
160
  // @ts-expect-error TS2239
161
161
  const cmd = message.cmd + '_Response';
162
+ // @ts-expect-error TS2239
163
+ const requestId = message.requestId || undefined;
162
164
 
163
- if (e instanceof SudoError) {
164
- return process.send?.({
165
- cmd,
166
- // @ts-expect-error TS2239
167
- requestId: message.requestId || undefined,
168
- data: `Plugin: '${this.plugin.name}'. Forbidden usage of sudo for command '${e.command}'. Please contact the plugin developer to fix this.`,
169
- status: MessageStatus.ERROR,
170
- })
171
- }
165
+ let errorPayload: PluginErrorData;
172
166
 
173
- if (e instanceof ApplyValidationError) {
174
- return process.send?.({
175
- cmd,
176
- // @ts-expect-error TS2239
177
- requestId: message.requestId || undefined,
178
- data: {
179
- errorCode: ErrorCode.APPLY_VALIDATION,
180
- plan: e.plan.toResponse(),
181
- },
182
- status: MessageStatus.ERROR,
183
- });
167
+ if (e instanceof SudoError) {
168
+ errorPayload = {
169
+ errorType: 'sudo_error',
170
+ message: `Plugin: '${this.plugin.name}'. Forbidden usage of sudo for command '${e.command}'. Please contact the plugin developer to fix this.`,
171
+ data: { command: e.command, pluginName: this.plugin.name },
172
+ };
173
+ } else if (e instanceof ApplyValidationError) {
174
+ errorPayload = {
175
+ errorType: 'apply_validation',
176
+ message: e.message,
177
+ data: { plan: e.plan.toResponse() },
178
+ };
179
+ } else {
180
+ const isDebug = process.env.DEBUG?.includes('*') ?? false;
181
+ errorPayload = {
182
+ errorType: 'unknown',
183
+ message: isDebug ? (e.stack ?? e.message) : e.message,
184
+ };
184
185
  }
185
186
 
186
- const isDebug = process.env.DEBUG?.includes('*') ?? false;
187
-
188
- process.send?.({
189
- cmd,
190
- // @ts-expect-error TS2239
191
- requestId: message.requestId || undefined,
192
- data: {
193
- errorCode: ErrorCode.UNKNOWN,
194
- message: isDebug ? (e.stack ?? e.message) : e.message,
195
- },
196
- status: MessageStatus.ERROR,
197
- })
187
+ process.send?.({ cmd, requestId, data: errorPayload, status: MessageStatus.ERROR });
198
188
  }
199
189
  }
@@ -268,7 +268,7 @@ export class Plugin {
268
268
  })
269
269
 
270
270
  if (validationPlan.requiresChanges()) {
271
- throw new ApplyValidationError(plan);
271
+ throw new ApplyValidationError(validationPlan);
272
272
  }
273
273
  }
274
274