Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -50,6 +51,7 @@ export {
PressKeyToContinueResponseDataSchema,
SetVerbosityRequestDataSchema,
EmptyResponseDataSchema,
ApplyNoteRequestDataSchema,
}

export * from './types/index.js';
Expand Down
19 changes: 19 additions & 0 deletions src/messages/apply-note-request-data-schema.json
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions src/messages/command-request-data-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/messages/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
13 changes: 10 additions & 3 deletions src/messages/error-response-data-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
3 changes: 2 additions & 1 deletion src/messages/error-response-data-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
})
8 changes: 8 additions & 0 deletions src/messages/get-resource-info-response-data-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
3 changes: 3 additions & 0 deletions src/messages/initialize-response-data-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"description": "Initialize the plugin",
"type": "object",
"properties": {
"minSupportedCliVersion": {
"type": "string"
},
"resourceDefinitions": {
"type": "array",
"items": {
Expand Down
41 changes: 34 additions & 7 deletions src/resource-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"]
Expand Down
20 changes: 20 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ export interface ResourceConfig extends Config {
name?: string;
dependsOn?: string[];
os?: Array<ResourceOs>;
distro?: Array<LinuxDistro>
}

export enum MessageStatus {
SUCCESS = 'success',
ERROR = 'error',
}

export interface PluginErrorData {
errorType: string;
message: string;
data?: unknown;
}

export interface IpcMessage {
cmd: string;
status?: MessageStatus;
Expand Down Expand Up @@ -105,6 +112,7 @@ export interface PlanResponseData {
}>
}


export interface GetResourceInfoRequestData {
type: string;
}
Expand All @@ -128,6 +136,11 @@ export interface GetResourceInfoResponseData {
},
sensitiveParameters?: string[];
allowMultiple: boolean;
defaultConfig?: Record<string, unknown>;
exampleConfigs?: {
example1?: Record<string, unknown>;
example2?: Record<string, unknown>;
};
}

export interface MatchRequestData {
Expand Down Expand Up @@ -190,6 +203,7 @@ export interface InitializeRequestData {

export interface InitializeResponseData {
resourceDefinitions: Array<ResourceDefinition>;
minSupportedCliVersion?: string;
}

export interface CommandRequestData {
Expand All @@ -198,6 +212,7 @@ export interface CommandRequestData {
cwd?: string;
interactive?: boolean;
requiresRoot?: boolean;
requiresSudoAskpass?: boolean;
stdin?: boolean;
} & Omit<SpawnOptions, 'stdio' | 'shell' | 'detached'>
}
Expand All @@ -220,6 +235,11 @@ export interface SetVerbosityRequestData {

export interface EmptyResponseData {}

export interface ApplyNoteRequestData {
message: string;
resourceType?: string;
}

export enum SpawnStatus {
SUCCESS = 'success',
ERROR = 'error',
Expand Down
Loading