diff --git a/package.json b/package.json index 75aa5b6..1c51b8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@codifycli/schemas", - "version": "1.0.0", + "version": "1.2.0", "description": "JSON Schemas and types that govern the message format and Codify config formats for Codify", "type": "module", "main": "dist/index.js", diff --git a/src/index.ts b/src/index.ts index 894fb60..bd85a62 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,6 +23,7 @@ import PressKeyToContinueRequestDataSchema from './messages/press-key-to-continu import PressKeyToContinueResponseDataSchema from './messages/press-key-to-continue-response-data-schema.json' with {type: 'json'}; import SetVerbosityRequestDataSchema from './messages/set-verbosity-request-data-schema.json' with {type: 'json'}; import EmptyResponseDataSchema from './messages/empty-response-data-schema.json' with {type: 'json'}; +import ApplyNoteRequestDataSchema from './messages/apply-note-request-data-schema.json' with {type: 'json'}; export { ConfigFileSchema, @@ -50,6 +51,7 @@ export { PressKeyToContinueResponseDataSchema, SetVerbosityRequestDataSchema, EmptyResponseDataSchema, + ApplyNoteRequestDataSchema, } export * from './types/index.js'; diff --git a/src/messages/apply-note-request-data-schema.json b/src/messages/apply-note-request-data-schema.json new file mode 100644 index 0000000..04f6527 --- /dev/null +++ b/src/messages/apply-note-request-data-schema.json @@ -0,0 +1,19 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://www.codifycli.com/apply-note-request.json", + "title": "Apply note request", + "description": "Sent by a plugin to leave a post-apply note for the user", + "type": "object", + "properties": { + "message": { + "type": "string", + "maxLength": 500 + }, + "resourceType": { + "type": "string", + "maxLength": 100 + } + }, + "required": ["message"], + "additionalProperties": false +} diff --git a/src/messages/command-request-data-schema.json b/src/messages/command-request-data-schema.json index de464c3..695fbb9 100644 --- a/src/messages/command-request-data-schema.json +++ b/src/messages/command-request-data-schema.json @@ -32,6 +32,10 @@ "stdin": { "type": "boolean", "description": "Whether or not this command requires stdin" + }, + "requiresSudoAskpass": { + "type": "boolean", + "description": "Whether to use SUDO_ASKPASS instead of sudo -S for password delivery" } }, "additionalProperties": true diff --git a/src/messages/commands.ts b/src/messages/commands.ts index 23d7271..272c404 100644 --- a/src/messages/commands.ts +++ b/src/messages/commands.ts @@ -5,5 +5,6 @@ export enum MessageCmd { APPLY = 'apply', COMMAND_REQUEST = 'command_request', PRESS_KEY_TO_CONTINUE_REQUEST = 'press_key_to_continue_request', - CODIFY_CREDENTIALS_REQUEST = 'codify_credentials_request' + CODIFY_CREDENTIALS_REQUEST = 'codify_credentials_request', + APPLY_NOTE_REQUEST = 'apply_note_request', } diff --git a/src/messages/error-response-data-schema.json b/src/messages/error-response-data-schema.json index 014fcb0..8747363 100644 --- a/src/messages/error-response-data-schema.json +++ b/src/messages/error-response-data-schema.json @@ -4,10 +4,17 @@ "title": "Error Response Schema Data", "type": "object", "properties": { - "reason": { - "description": "A human read-able reason for the error", + "errorType": { + "description": "A string identifier for the error type (e.g. 'apply_validation', 'sudo_error', 'unknown')", "type": "string" + }, + "message": { + "description": "A human-readable error message, always present", + "type": "string" + }, + "data": { + "description": "Optional structured payload whose shape depends on errorType" } }, - "required": ["reason"] + "required": ["errorType", "message"] } diff --git a/src/messages/error-response-data-schema.test.ts b/src/messages/error-response-data-schema.test.ts index ba85ce1..e4fc815 100644 --- a/src/messages/error-response-data-schema.test.ts +++ b/src/messages/error-response-data-schema.test.ts @@ -17,7 +17,8 @@ describe('Apply request data schema', () => { it("validates an error message", () => { const validate = ajv.compile(schema); expect(validate({ - reason: "This was an error" + errorType: "unknown", + message: "This was an error" })).to.be.true; }) }) diff --git a/src/messages/get-resource-info-response-data-schema.json b/src/messages/get-resource-info-response-data-schema.json index f7d75dd..5fdfe53 100644 --- a/src/messages/get-resource-info-response-data-schema.json +++ b/src/messages/get-resource-info-response-data-schema.json @@ -70,6 +70,14 @@ }, "allowMultiple": { "type": "boolean" + }, + "defaultConfig": { + "type": "object", + "description": "The default config that should be added. This prefills some parameters for the user to make it easier for them" + }, + "exampleConfigs": { + "type": "object", + "description": "Some example configs. This makes it for the user." } }, "required": ["type", "plugin"] diff --git a/src/messages/initialize-response-data-schema.json b/src/messages/initialize-response-data-schema.json index 04d520b..2156cd7 100644 --- a/src/messages/initialize-response-data-schema.json +++ b/src/messages/initialize-response-data-schema.json @@ -5,6 +5,9 @@ "description": "Initialize the plugin", "type": "object", "properties": { + "minSupportedCliVersion": { + "type": "string" + }, "resourceDefinitions": { "type": "array", "items": { diff --git a/src/resource-schema.json b/src/resource-schema.json index a456fa5..e8de3f6 100644 --- a/src/resource-schema.json +++ b/src/resource-schema.json @@ -9,13 +9,6 @@ "type": "string", "pattern": "^[a-zA-Z][\\w-]+$" }, - "os": { - "type": "array", - "items": { - "enum": ["linux", "macOS", "windows"] - }, - "uniqueItems": true - }, "name": { "description": "Optional name. Useful for specifying multiple resources of the same type", "type": "string", @@ -27,6 +20,40 @@ "type": "string" }, "uniqueItems": true + }, + "os": { + "type": "array", + "items": { + "enum": ["linux", "macOS", "windows"] + }, + "uniqueItems": true + }, + "distro": { + "type": "array", + "items": { + "enum": [ + "debian-based", + "rpm-based", + "arch", + "centos", + "debian", + "fedora", + "rhel", + "ubuntu", + "alpine", + "amzn", + "opensuse", + "sles", + "manjaro", + "linuxmint", + "pop", + "elementary", + "kali", + "gentoo", + "slackware" + ] + }, + "uniqueItems": true } }, "required": ["type"] diff --git a/src/types/index.ts b/src/types/index.ts index b903e49..acd9ae3 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -25,6 +25,7 @@ export interface ResourceConfig extends Config { name?: string; dependsOn?: string[]; os?: Array; + distro?: Array } export enum MessageStatus { @@ -32,6 +33,12 @@ export enum MessageStatus { ERROR = 'error', } +export interface PluginErrorData { + errorType: string; + message: string; + data?: unknown; +} + export interface IpcMessage { cmd: string; status?: MessageStatus; @@ -105,6 +112,7 @@ export interface PlanResponseData { }> } + export interface GetResourceInfoRequestData { type: string; } @@ -128,6 +136,11 @@ export interface GetResourceInfoResponseData { }, sensitiveParameters?: string[]; allowMultiple: boolean; + defaultConfig?: Record; + exampleConfigs?: { + example1?: Record; + example2?: Record; + }; } export interface MatchRequestData { @@ -190,6 +203,7 @@ export interface InitializeRequestData { export interface InitializeResponseData { resourceDefinitions: Array; + minSupportedCliVersion?: string; } export interface CommandRequestData { @@ -198,6 +212,7 @@ export interface CommandRequestData { cwd?: string; interactive?: boolean; requiresRoot?: boolean; + requiresSudoAskpass?: boolean; stdin?: boolean; } & Omit } @@ -220,6 +235,11 @@ export interface SetVerbosityRequestData { export interface EmptyResponseData {} +export interface ApplyNoteRequestData { + message: string; + resourceType?: string; +} + export enum SpawnStatus { SUCCESS = 'success', ERROR = 'error',