@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.
- package/dist/messages/handlers.js +22 -29
- package/dist/plugin/plugin.js +1 -1
- package/package.json +2 -2
- package/src/messages/handlers.ts +23 -33
- package/src/plugin/plugin.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApplyRequestDataSchema, EmptyResponseDataSchema,
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
148
|
-
});
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
process.send?.({ cmd, requestId, data: errorPayload, status: MessageStatus.ERROR });
|
|
149
142
|
}
|
|
150
143
|
}
|
package/dist/plugin/plugin.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codifycli/plugin-core",
|
|
3
|
-
"version": "1.1.0-
|
|
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-
|
|
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",
|
package/src/messages/handlers.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
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
|
}
|