New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@monokle/validation

Package Overview
Dependencies
Maintainers
5
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@monokle/validation - npm Package Compare versions

Comparing version 0.13.0 to 0.14.0

lib/config/read.browser.d.ts

2

lib/__tests__/badResources.d.ts

@@ -1,4 +0,4 @@

import { Resource } from "../common/types.js";
import { Resource } from "../index.js";
export declare const BAD_DEPLOYMENT: Resource;
export declare const BAD_SERVICE: Resource;
export declare const RESOURCES: Resource[];
import { LineCounter } from "yaml";
import { Resource } from "../common/types.js";
import { Resource } from "../index.js";
export declare const KUSTOMIZATION_KIND = "Kustomization";

@@ -4,0 +4,0 @@ export declare const KUSTOMIZATION_API_GROUP = "kustomize.config.k8s.io";

import keyBy from "lodash/keyBy.js";
import invariant from "tiny-invariant";
import { NOT_CONFIGURED_ERR_MSG } from "../constants.js";
import invariant from "../utils/invariant.js";
import { getResourceId } from "../utils/sarif.js";

@@ -103,3 +103,3 @@ const DEFAULT_RULE_CONFIG = {

rule: {
index,
index: index ?? 0,
toolComponent: {

@@ -106,0 +106,0 @@ name: this.name,

export * from "./parse.js";
export * from "./read.node.js";
export * from "./read.js";
export * from "./parse.js";
export * from "./read.node.js";
export * from "./read.js";

@@ -20,2 +20,2 @@ export * from "./common/sarif.js";

export * from "./references/process.js";
export * from "./node.js";
export { createExtensibleMonokleValidator } from "#extensible-monokle-validator";

@@ -20,2 +20,2 @@ export * from "./common/sarif.js";

export * from "./references/process.js";
export * from "./node.js";
export { createExtensibleMonokleValidator } from "#extensible-monokle-validator";

@@ -14,8 +14,2 @@ import { ResourceParser } from "./common/resourceParser.js";

export declare function createMonokleValidator(loader: PluginLoader, fallback?: PluginMap): MonokleValidator;
/**
* Creates a Monokle validator that can dynamically fetch custom plugins.
*
* @remark NodeJs does not yet support ESM HTTP URLs. Instead use `createExtensibleNodeMonokleValidator`.
*/
export declare function createExtensibleMonokleValidator(parser?: ResourceParser, schemaLoader?: SchemaLoader): MonokleValidator;
export declare function createDefaultMonokleValidator(parser?: ResourceParser, schemaLoader?: SchemaLoader): MonokleValidator;

@@ -83,3 +77,3 @@ export declare function createDefaultPluginLoader(parser?: ResourceParser, schemaLoader?: SchemaLoader): (pluginName: string) => Promise<SimpleCustomValidator | KubernetesSchemaValidator | OpenPolicyAgentValidator | ResourceLinksValidator | YamlValidator>;

*/
validate({ resources, incremental, abortSignal: externalAbortSignal }: {
validate({ resources, incremental, abortSignal: externalAbortSignal, }: {
resources: Resource[];

@@ -86,0 +80,0 @@ incremental?: Incremental;

import clone from "lodash/clone.js";
import difference from "lodash/difference.js";
import isEqual from "lodash/isEqual.js";
import invariant from "tiny-invariant";
import { ResourceParser } from "./common/resourceParser.js";
import { nextTick, throwIfAborted } from "./utils/abort.js";
import { extractSchema, findDefaultVersion } from "./utils/customResourceDefinitions.js";
import { extractSchema, findDefaultVersion, } from "./utils/customResourceDefinitions.js";
import { PluginLoadError } from "./utils/error.js";
import invariant from "./utils/invariant.js";
import { isDefined } from "./utils/isDefined.js";
import { DEV_MODE_TOKEN } from "./validators/custom/constants.js";
import { DevCustomValidator } from "./validators/custom/devValidator.js";
import { SimpleCustomValidator } from "./validators/custom/simpleValidator.js";

@@ -22,38 +20,2 @@ import { SchemaLoader } from "./validators/kubernetes-schema/schemaLoader.js";

}
/**
* Creates a Monokle validator that can dynamically fetch custom plugins.
*
* @remark NodeJs does not yet support ESM HTTP URLs. Instead use `createExtensibleNodeMonokleValidator`.
*/
export function createExtensibleMonokleValidator(parser = new ResourceParser(), schemaLoader = new SchemaLoader()) {
return new MonokleValidator(async (pluginName) => {
switch (pluginName) {
case "open-policy-agent":
const wasmLoader = new RemoteWasmLoader();
return new OpenPolicyAgentValidator(parser, wasmLoader);
case "resource-links":
return new ResourceLinksValidator();
case "yaml-syntax":
return new YamlValidator(parser);
case "labels":
const labelPlugin = await import("./validators/labels/plugin.js");
return new SimpleCustomValidator(labelPlugin.default, parser);
case "kubernetes-schema":
return new KubernetesSchemaValidator(parser, schemaLoader);
case DEV_MODE_TOKEN:
return new DevCustomValidator(parser);
default:
try {
const url = `https://plugins.monokle.com/validation/${pluginName}/latest.js`;
const customPlugin = await import(/* @vite-ignore */ url);
return new SimpleCustomValidator(customPlugin.default, parser);
}
catch (err) {
throw new Error(err instanceof Error
? `plugin_not_found: ${err.message}`
: `plugin_not_found: ${String(err)}`);
}
}
});
}
export function createDefaultMonokleValidator(parser = new ResourceParser(), schemaLoader = new SchemaLoader()) {

@@ -89,3 +51,3 @@ return new MonokleValidator(createDefaultPluginLoader(parser, schemaLoader));

"yaml-syntax": true,
"kubernetes-schema": true
"kubernetes-schema": true,
};

@@ -212,3 +174,3 @@ export class MonokleValidator {

const stalePlugins = difference(previousPluginNames, newPluginNames);
this.doUnload(stalePlugins);
await this.doUnload(stalePlugins);
// Load new plugins

@@ -226,4 +188,5 @@ const missingPlugins = newPluginNames.filter((p) => !this.isPluginLoaded(p));

}));
if (signal.aborted)
if (signal.aborted) {
return;
}
loading.forEach((pluginPromise) => {

@@ -251,3 +214,3 @@ if (pluginPromise.status === "fulfilled") {

rules: config.rules,
settings: config.settings
settings: config.settings,
})));

@@ -267,3 +230,3 @@ }

*/
async validate({ resources, incremental, abortSignal: externalAbortSignal }) {
async validate({ resources, incremental, abortSignal: externalAbortSignal, }) {
if (this.#loading === undefined) {

@@ -291,3 +254,3 @@ this.load();

version: "2.1.0",
runs
runs,
};

@@ -314,3 +277,3 @@ }

this.debug("Cannot register custom schema.", {
reason: "Kubernetes Schema plugin must be loaded."
reason: "Kubernetes Schema plugin must be loaded.",
});

@@ -322,3 +285,3 @@ return;

this.debug("Cannot register custom schema.", {
reason: "The schema is already registered."
reason: "The schema is already registered.",
});

@@ -338,3 +301,3 @@ return;

this.debug("Cannot unregister custom schema.", {
reason: "Kubernetes Schema plugin must be loaded."
reason: "Kubernetes Schema plugin must be loaded.",
});

@@ -346,3 +309,3 @@ return;

this.debug("Cannot register custom schema.", {
reason: "The schema is not registered."
reason: "The schema is not registered.",
});

@@ -349,0 +312,0 @@ return;

@@ -1,2 +0,2 @@

import invariant from "tiny-invariant";
import invariant from "./invariant.js";
import { getResourceId } from "./sarif.js";

@@ -3,0 +3,0 @@ export function getRuleForResult(response, result) {

@@ -1,2 +0,2 @@

import invariant from "tiny-invariant";
import invariant from "./invariant.js";
export function getResourceId(result) {

@@ -3,0 +3,0 @@ return getResourceLocation(result).physicalLocation?.artifactLocation.uri;

export * from "./rules.js";
export * from "./validator.js";
export * from "./wasmLoader/FileWasmLoader.js";
export * from "./wasmLoader/RemoteWasmLoader.js";
export * from "./types.js";
export * from "./rules.js";
export * from "./validator.js";
export * from "./wasmLoader/FileWasmLoader.js";
// export * from "./wasmLoader/FileWasmLoader.js";
export * from "./wasmLoader/RemoteWasmLoader.js";
export * from "./types.js";

@@ -0,5 +1,5 @@

// @ts-ignore
import { loadPolicy } from "@open-policy-agent/opa-wasm";
import { isNode } from "yaml";
import get from "lodash/get.js";
import invariant from "tiny-invariant";
import { z } from "zod";

@@ -11,2 +11,3 @@ import { AbstractPlugin } from "../../common/AbstractPlugin.js";

import { isKustomizationResource } from "../../references/utils/kustomizeRefs.js";
import invariant from "../../utils/invariant.js";
const Settings = z.object({

@@ -13,0 +14,0 @@ wasmSrc: z

@@ -1,4 +0,1 @@

import { WasmLoader } from "./WasmLoader.js";
export declare class RemoteWasmLoader implements WasmLoader {
load(url: string): Promise<ArrayBuffer>;
}
export { RemoteWasmLoader } from '#remote-wasm-loader';

@@ -1,7 +0,1 @@

export class RemoteWasmLoader {
async load(url) {
const response = await fetch(url);
const data = await response.arrayBuffer();
return data;
}
}
export { RemoteWasmLoader } from '#remote-wasm-loader';
{
"name": "@monokle/validation",
"version": "0.13.0",
"version": "0.14.0",
"description": "Kubernetes resource validation",

@@ -25,2 +25,16 @@ "author": "Kubeshop",

},
"imports": {
"#read-config": {
"node": "./lib/config/read.node.js",
"default": "./lib/config/read.browser.js"
},
"#remote-wasm-loader": {
"node": "./lib/validators/open-policy-agent/wasmLoader/RemoteWasmLoader.node.js",
"default": "./lib/validators/open-policy-agent/wasmLoader/RemoteWasmLoader.browser.js"
},
"#extensible-monokle-validator": {
"node": "./lib/createExtensibleMonokleValidator.node.js",
"default": "./lib/createExtensibleMonokleValidator.browser.js"
}
},
"files": [

@@ -53,2 +67,3 @@ "lib/**"

"@types/require-from-string": "1.2.1",
"@types/uuid": "9.0.1",
"rimraf": "3.0.2",

@@ -59,4 +74,3 @@ "tiny-glob": "0.2.9",

"uuid": "9.0.0",
"vite": "3.1.2",
"vitest": "0.23.4"
"vitest": "0.29.2"
},

@@ -73,10 +87,5 @@ "dependencies": {

"rollup": "3.18.0",
"tiny-invariant": "1.2.0",
"yaml": "2.1.1",
"zod": "3.19.1"
},
"browser": {
"./lib/validators/open-policy-agent/wasmLoader/FileWasmLoader.js": false,
"./lib/config/read.node.js": false
}
}

@@ -32,14 +32,14 @@ <p align="center">

Learn more about each Core Plugin in the [Core Plugins Documentation](docs/core-plugins.md)
Learn more about each Core Plugin in the [Core Plugins Documentation](docs/core-plugins.md)
## Custom Plugins
Easily create your own validators in typescript - [Read More](docs/custom-plugins.md)
Easily create your own validators in typescript - [Read More](docs/custom-plugins.md)
## Community Plugins
Share your custom validators in the [Monokle Community Plugins](https://github.com/kubeshop/monokle-community-plugins) repo,
Share your custom validators in the [Monokle Community Plugins](https://github.com/kubeshop/monokle-community-plugins) repo,
or use any existing community validators as [described below](#using-community-plugins).
## Validate from the CLI or Monokle Cloud
## Validate from the CLI or Monokle Cloud

@@ -52,3 +52,3 @@ The [Monokle CLI](../cli) provides a convenient wrapper around this library. Use it to validate your resources in seconds:

Or visit [Monokle Cloud](https://app.monokle.com); a free web application where you can apply this validation
Or visit [Monokle Cloud](https://app.monokle.com); a free web application where you can apply this validation
library directly on public GitHub repositories.

@@ -83,3 +83,3 @@

The Monokle validator is extensible and has a rich plugin system. You can configure and preload
The Monokle validator is extensible and has a rich plugin system. You can configure and preload
plugins as follows:

@@ -188,6 +188,6 @@

Each validation plugin has to be initialized which might require heavy operations such as fetching large
Each validation plugin has to be initialized which might require heavy operations such as fetching large
JSON schemas, AJV compilation, WASM initialization and more.
The `preload` API avoids a long first validation and is recommended in more interactive environments.
The `preload` API avoids a long first validation and is recommended in more interactive environments.
It is idempotent so you can call it as often as you want without continuously reinstantiating the plugins.

@@ -194,0 +194,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc