-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
93 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@caido/plugin-manifest", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Validation for the plugin manifest", | ||
"author": "Caido Labs Inc. <[email protected]>", | ||
"license": "MIT", | ||
|
@@ -17,10 +17,12 @@ | |
"access": "public" | ||
}, | ||
"scripts": { | ||
"build": "rm -rf dist/*; tsc -p tsconfig.build.json", | ||
"build": "tsup", | ||
"generate": "json2ts src/schema.json > src/schema.generated.ts", | ||
"lint": "eslint src/ --fix", | ||
"test": "vitest run", | ||
"typecheck": "tsc --noEmit" | ||
"typecheck": "tsc --noEmit", | ||
"prepublish": "pnpm generate" | ||
}, | ||
"dependencies": { | ||
"ajv": "^8.16.0" | ||
|
@@ -34,6 +36,8 @@ | |
"eslint-import-resolver-typescript": "3.6.1", | ||
"eslint-plugin-import": "2.29.1", | ||
"eslint-plugin-prettier": "5.1.3", | ||
"json-schema-to-typescript": "^15.0.3", | ||
"tsup": "^8.0.2", | ||
"typescript": "5.4.3", | ||
"vitest": "1.4.0" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
export { validateManifest } from "./validator.js"; | ||
import { Ajv } from "ajv"; | ||
|
||
import schema from "./schema.json" with { type: "json" }; | ||
|
||
export * from "./schema.generated"; | ||
|
||
const ajv = new Ajv(); | ||
|
||
export function validateManifest(data: unknown): boolean { | ||
console.log("[*] Validating manifest data"); | ||
const validate = ajv.compile(schema); | ||
const valid = validate(data); | ||
if (!valid) { | ||
console.log(`[-] Errors: ${JSON.stringify(validate.errors, null, 2)}`); | ||
return false; | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* eslint-disable */ | ||
/** | ||
* This file was automatically generated by json-schema-to-typescript. | ||
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, | ||
* and run json-schema-to-typescript to regenerate this file. | ||
*/ | ||
|
||
export type Schema = Manifest; | ||
export type ManifestID = string; | ||
export type ManifestPlugin = | ||
| { | ||
backend?: ManifestFrontendPluginConnection | null; | ||
entrypoint?: string | null; | ||
id: ManifestID; | ||
kind: "frontend"; | ||
name?: string | null; | ||
style?: string | null; | ||
[k: string]: unknown; | ||
} | ||
| { | ||
entrypoint: string; | ||
id: ManifestID; | ||
kind: "backend"; | ||
name?: string | null; | ||
runtime: ManifestBackendPluginRuntime; | ||
[k: string]: unknown; | ||
} | ||
| { | ||
id: ManifestID; | ||
kind: "workflow"; | ||
name?: string; | ||
definition: string; | ||
[k: string]: unknown; | ||
}; | ||
export type ManifestBackendPluginRuntime = "javascript"; | ||
|
||
export interface Manifest { | ||
author?: ManifestAuthor | null; | ||
description?: string | null; | ||
id: ManifestID; | ||
name?: string | null; | ||
plugins: ManifestPlugin[]; | ||
version: string; | ||
[k: string]: unknown; | ||
} | ||
export interface ManifestAuthor { | ||
email?: string | null; | ||
name?: string | null; | ||
url?: string | null; | ||
[k: string]: unknown; | ||
} | ||
export interface ManifestFrontendPluginConnection { | ||
id: ManifestID; | ||
[k: string]: unknown; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from 'tsup' | ||
|
||
export default defineConfig({ | ||
entry: ['src/index.ts'], | ||
format: ['esm'], | ||
dts: true, | ||
clean: true, | ||
sourcemap: true, | ||
minify: false, | ||
}) |