@codifycli/plugin-core 1.0.0 → 1.1.0-beta1

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,5 @@
1
+ {
2
+ "disabledMcpjsonServers": [
3
+ "supabase"
4
+ ]
5
+ }
@@ -11,7 +11,10 @@ export declare class Plugin {
11
11
  constructor(name: string, resourceControllers: Map<string, ResourceController<ResourceConfig>>);
12
12
  static create(name: string, resources: Resource<any>[]): Plugin;
13
13
  initialize(data: InitializeRequestData): Promise<InitializeResponseData>;
14
- getResourceInfo(data: GetResourceInfoRequestData): GetResourceInfoResponseData;
14
+ getResourceInfo(data: GetResourceInfoRequestData): {
15
+ defaultConfig: unknown;
16
+ exampleConfigs: unknown;
17
+ } & GetResourceInfoResponseData;
15
18
  match(data: MatchRequestData): Promise<MatchResponseData>;
16
19
  import(data: ImportRequestData): Promise<ImportResponseData>;
17
20
  validate(data: ValidateRequestData): Promise<ValidateResponseData>;
@@ -87,7 +87,9 @@ export class Plugin {
87
87
  operatingSystems: resource.settings.operatingSystems,
88
88
  linuxDistros: resource.settings.linuxDistros,
89
89
  sensitiveParameters,
90
- allowMultiple
90
+ allowMultiple,
91
+ defaultConfig: resource.settings.defaultConfig,
92
+ exampleConfigs: resource.settings.exampleConfigs,
91
93
  };
92
94
  }
93
95
  async match(data) {
@@ -1,7 +1,7 @@
1
1
  import { LinuxDistro, OS, StringIndexedObject } from '@codifycli/schemas';
2
2
  import { JSONSchemaType } from 'ajv';
3
3
  import { StatefulParameterController } from '../stateful-parameter/stateful-parameter-controller.js';
4
- import { ArrayParameterSetting, DefaultParameterSetting, InputTransformation, ResourceSettings } from './resource-settings.js';
4
+ import { ArrayParameterSetting, DefaultParameterSetting, ExampleConfigs, InputTransformation, ResourceSettings } from './resource-settings.js';
5
5
  export interface ParsedStatefulParameterSetting extends DefaultParameterSetting {
6
6
  type: 'stateful';
7
7
  controller: StatefulParameterController<any, unknown>;
@@ -31,6 +31,8 @@ export declare class ParsedResourceSettings<T extends StringIndexedObject> imple
31
31
  operatingSystems: Array<OS>;
32
32
  linuxDistros?: Array<LinuxDistro>;
33
33
  isSensitive?: boolean;
34
+ defaultConfig: Partial<T>;
35
+ exampleConfigs: ExampleConfigs;
34
36
  private settings;
35
37
  constructor(settings: ResourceSettings<T>);
36
38
  get typeId(): string;
@@ -1,4 +1,4 @@
1
- import { ZodObject, z } from 'zod';
1
+ import { z, ZodObject } from 'zod';
2
2
  import { StatefulParameterController } from '../stateful-parameter/stateful-parameter-controller.js';
3
3
  import { resolveElementEqualsFn, resolveEqualsFn, resolveMatcher, resolveParameterTransformFn } from './resource-settings.js';
4
4
  export class ParsedResourceSettings {
@@ -13,6 +13,8 @@ export class ParsedResourceSettings {
13
13
  operatingSystems;
14
14
  linuxDistros;
15
15
  isSensitive;
16
+ defaultConfig;
17
+ exampleConfigs;
16
18
  settings;
17
19
  constructor(settings) {
18
20
  this.settings = settings;
@@ -23,8 +25,11 @@ export class ParsedResourceSettings {
23
25
  ? z.toJSONSchema(schema.strict(), {
24
26
  target: 'draft-7',
25
27
  override(ctx) {
26
- ctx.jsonSchema.title = settings.id;
27
- ctx.jsonSchema.description = settings.description ?? `${settings.id} resource. Can be used to manage ${settings.id}`;
28
+ if (ctx.path.length === 0) {
29
+ ctx.jsonSchema.title = settings.id;
30
+ ctx.jsonSchema.description = schema.description ?? settings.description ?? `${settings.id} resource. Can be used to manage ${settings.id}`;
31
+ ctx.jsonSchema.$comment = schema.meta().$comment;
32
+ }
28
33
  }
29
34
  })
30
35
  : schema;
@@ -4,6 +4,14 @@ import { ZodObject } from 'zod';
4
4
  import { ArrayStatefulParameter, StatefulParameter } from '../stateful-parameter/stateful-parameter.js';
5
5
  import { ParsedResourceSettings } from './parsed-resource-settings.js';
6
6
  import { RefreshContext } from './resource.js';
7
+ export interface ExampleConfig {
8
+ configs: Array<Record<string, unknown>>;
9
+ description: string;
10
+ }
11
+ export interface ExampleConfigs {
12
+ example1: ExampleConfig;
13
+ example2: ExampleConfig;
14
+ }
7
15
  export interface InputTransformation {
8
16
  to: (input: any) => Promise<any> | any;
9
17
  from: (current: any, original: any) => Promise<any> | any;
@@ -162,6 +170,17 @@ export interface ResourceSettings<T extends StringIndexedObject> {
162
170
  */
163
171
  refreshMapper?: (input: Partial<T>, context: RefreshContext<T>) => Partial<T>;
164
172
  };
173
+ /**
174
+ * Represents the default config that is added to the editor with prefilled properties. For some resources
175
+ *
176
+ * @type {Partial<T>}
177
+ */
178
+ defaultConfig?: Partial<T>;
179
+ /**
180
+ * A collection of example configs used to give users an idea on how to use this specific resource. These examples
181
+ * don't need to be limited to just the current resource. They can include other resources as well
182
+ */
183
+ exampleConfigs: ExampleConfigs;
165
184
  }
166
185
  /**
167
186
  * The type of parameter. This value is mainly used to determine a pre-set equality method for comparing the current
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codifycli/plugin-core",
3
- "version": "1.0.0",
3
+ "version": "1.1.0-beta1",
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",
@@ -83,7 +83,7 @@ export class Plugin {
83
83
  }
84
84
  }
85
85
 
86
- getResourceInfo(data: GetResourceInfoRequestData): GetResourceInfoResponseData {
86
+ getResourceInfo(data: GetResourceInfoRequestData): { defaultConfig: unknown; exampleConfigs: unknown } & GetResourceInfoResponseData {
87
87
  if (!this.resourceControllers.has(data.type)) {
88
88
  throw new Error(`Cannot get info for resource ${data.type}, resource doesn't exist`);
89
89
  }
@@ -127,7 +127,9 @@ export class Plugin {
127
127
  operatingSystems: resource.settings.operatingSystems,
128
128
  linuxDistros: resource.settings.linuxDistros,
129
129
  sensitiveParameters,
130
- allowMultiple
130
+ allowMultiple,
131
+ defaultConfig: resource.settings.defaultConfig,
132
+ exampleConfigs: resource.settings.exampleConfigs,
131
133
  }
132
134
  }
133
135
 
@@ -165,9 +165,18 @@ describe('Resource options parser tests', () => {
165
165
  it('Can handle a zod schema', () => {
166
166
 
167
167
  const schema = z.object({
168
- propA: z.string(),
169
- repository: z.string(),
170
- })
168
+ plugins: z
169
+ .array(z.string())
170
+ .describe(
171
+ 'Asdf plugins to install. See: https://github.com/asdf-community for a full list'
172
+ )
173
+ .optional(),
174
+ repository: z
175
+ .string()
176
+ .describe('Remote repository to clone repo from. Equivalent to remote and only one should be specified')
177
+ .optional(),
178
+ }).meta({ $comment: 'https://codifycli.com/docs/resources/asdf/asdf' })
179
+ .describe('This is my test resource');
171
180
 
172
181
  const option: ResourceSettings<z.infer<typeof schema>> = {
173
182
  id: 'typeId',
@@ -180,7 +189,29 @@ describe('Resource options parser tests', () => {
180
189
  }
181
190
  }
182
191
 
183
- console.log(new ParsedResourceSettings(option))
192
+ expect((new ParsedResourceSettings(option)).schema).toMatchObject({
193
+ '$schema': 'http://json-schema.org/draft-07/schema#',
194
+ type: 'object',
195
+ properties: {
196
+ plugins: {
197
+ description: 'Asdf plugins to install. See: https://github.com/asdf-community for a full list',
198
+ type: 'array',
199
+ items: {
200
+ "type": "string",
201
+ },
202
+ },
203
+ repository: {
204
+ description: 'Remote repository to clone repo from. Equivalent to remote and only one should be specified',
205
+ type: 'string'
206
+ }
207
+ },
208
+ additionalProperties: false,
209
+ title: 'typeId',
210
+ description: 'This is my test resource',
211
+ '$comment': 'https://codifycli.com/docs/resources/asdf/asdf'
212
+ })
213
+
214
+ console.log((new ParsedResourceSettings(option)).schema)
184
215
 
185
216
  })
186
217
  })
@@ -1,19 +1,19 @@
1
1
  import { LinuxDistro, OS, StringIndexedObject } from '@codifycli/schemas';
2
2
  import { JSONSchemaType } from 'ajv';
3
- import { ZodObject, z } from 'zod';
3
+ import { z, ZodObject } from 'zod';
4
4
 
5
5
  import { StatefulParameterController } from '../stateful-parameter/stateful-parameter-controller.js';
6
6
  import {
7
7
  ArrayParameterSetting,
8
- DefaultParameterSetting,
8
+ DefaultParameterSetting, ExampleConfigs,
9
9
  InputTransformation,
10
10
  ParameterSetting,
11
- ResourceSettings,
12
- StatefulParameterSetting,
13
11
  resolveElementEqualsFn,
14
12
  resolveEqualsFn,
15
13
  resolveMatcher,
16
- resolveParameterTransformFn
14
+ resolveParameterTransformFn,
15
+ ResourceSettings,
16
+ StatefulParameterSetting
17
17
  } from './resource-settings.js';
18
18
 
19
19
  export interface ParsedStatefulParameterSetting extends DefaultParameterSetting {
@@ -56,6 +56,9 @@ export class ParsedResourceSettings<T extends StringIndexedObject> implements Re
56
56
 
57
57
  isSensitive?: boolean;
58
58
 
59
+ defaultConfig!: Partial<T>;
60
+ exampleConfigs!: ExampleConfigs;
61
+
59
62
  private settings: ResourceSettings<T>;
60
63
 
61
64
  constructor(settings: ResourceSettings<T>) {
@@ -69,8 +72,11 @@ export class ParsedResourceSettings<T extends StringIndexedObject> implements Re
69
72
  ? z.toJSONSchema(schema.strict(), {
70
73
  target: 'draft-7',
71
74
  override(ctx) {
72
- ctx.jsonSchema.title = settings.id;
73
- ctx.jsonSchema.description = settings.description ?? `${settings.id} resource. Can be used to manage ${settings.id}`;
75
+ if (ctx.path.length === 0) {
76
+ ctx.jsonSchema.title = settings.id;
77
+ ctx.jsonSchema.description = schema.description ?? settings.description ?? `${settings.id} resource. Can be used to manage ${settings.id}`;
78
+ ctx.jsonSchema.$comment = (schema.meta() as Record<string, string | undefined>).$comment;
79
+ }
74
80
  }
75
81
  }) as JSONSchemaType<T>
76
82
  : schema;
@@ -15,6 +15,16 @@ import {
15
15
  import { ParsedResourceSettings } from './parsed-resource-settings.js';
16
16
  import { RefreshContext } from './resource.js';
17
17
 
18
+ export interface ExampleConfig {
19
+ configs: Array<Record<string, unknown>>;
20
+ description: string;
21
+ }
22
+
23
+ export interface ExampleConfigs {
24
+ example1: ExampleConfig;
25
+ example2: ExampleConfig;
26
+ }
27
+
18
28
  export interface InputTransformation {
19
29
  to: (input: any) => Promise<any> | any;
20
30
  from: (current: any, original: any) => Promise<any> | any;
@@ -194,6 +204,19 @@ export interface ResourceSettings<T extends StringIndexedObject> {
194
204
  */
195
205
  refreshMapper?: (input: Partial<T>, context: RefreshContext<T>) => Partial<T>;
196
206
  }
207
+
208
+ /**
209
+ * Represents the default config that is added to the editor with prefilled properties. For some resources
210
+ *
211
+ * @type {Partial<T>}
212
+ */
213
+ defaultConfig?: Partial<T>
214
+
215
+ /**
216
+ * A collection of example configs used to give users an idea on how to use this specific resource. These examples
217
+ * don't need to be limited to just the current resource. They can include other resources as well
218
+ */
219
+ exampleConfigs: ExampleConfigs
197
220
  }
198
221
 
199
222
  /**