@kintone/plugin-manifest-validator
Advanced tools
Comparing version 10.1.0 to 10.2.0
@@ -7,2 +7,6 @@ { | ||
"properties": { | ||
"$schema": { | ||
"type": "string", | ||
"format": "uri" | ||
}, | ||
"manifest_version": { | ||
@@ -35,3 +39,13 @@ "type": "integer", | ||
"minLength": 1, | ||
"maxLength": 64 | ||
"maxLength": 64, | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"homepage_url": { | ||
"properties": ["ja"] | ||
} | ||
} | ||
], | ||
"warn": true | ||
} | ||
}, | ||
@@ -41,3 +55,13 @@ "en": { | ||
"minLength": 1, | ||
"maxLength": 64 | ||
"maxLength": 64, | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"homepage_url": { | ||
"properties": ["en"] | ||
} | ||
} | ||
], | ||
"warn": true | ||
} | ||
}, | ||
@@ -47,3 +71,13 @@ "zh": { | ||
"minLength": 1, | ||
"maxLength": 64 | ||
"maxLength": 64, | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"homepage_url": { | ||
"properties": ["zh"] | ||
} | ||
} | ||
], | ||
"warn": true | ||
} | ||
}, | ||
@@ -53,3 +87,13 @@ "es": { | ||
"minLength": 1, | ||
"maxLength": 64 | ||
"maxLength": 64, | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"homepage_url": { | ||
"properties": ["es"] | ||
} | ||
} | ||
], | ||
"warn": true | ||
} | ||
} | ||
@@ -101,3 +145,12 @@ }, | ||
"minLength": 1, | ||
"format": "http-url" | ||
"format": "http-url", | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"name": { | ||
"properties": ["ja"] | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
@@ -107,3 +160,12 @@ "en": { | ||
"minLength": 1, | ||
"format": "http-url" | ||
"format": "http-url", | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"name": { | ||
"properties": ["en"] | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
@@ -113,3 +175,12 @@ "zh": { | ||
"minLength": 1, | ||
"format": "http-url" | ||
"format": "http-url", | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"name": { | ||
"properties": ["zh"] | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
@@ -119,3 +190,12 @@ "es": { | ||
"minLength": 1, | ||
"format": "http-url" | ||
"format": "http-url", | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"name": { | ||
"properties": ["es"] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
@@ -122,0 +202,0 @@ } |
import type { ErrorObject } from "ajv"; | ||
type WarningObject = { | ||
message: string; | ||
}; | ||
type ValidateResult = { | ||
valid: boolean | PromiseLike<any>; | ||
errors: null | ErrorObject[]; | ||
warnings: null | WarningObject[]; | ||
}; | ||
export type RequiredObjectProperty = { | ||
[key: string]: { | ||
properties: string[]; | ||
}; | ||
}; | ||
export type RequiredProperties = { | ||
items: Array<RequiredObjectProperty | string>; | ||
warn?: boolean; | ||
}; | ||
type ValidatorResult = boolean | { | ||
@@ -7,0 +20,0 @@ valid: true; |
@@ -7,5 +7,7 @@ "use strict"; | ||
const ajv_1 = __importDefault(require("ajv")); | ||
const ajv_formats_1 = __importDefault(require("ajv-formats")); | ||
const bytes_1 = __importDefault(require("bytes")); | ||
const manifest_schema_json_1 = __importDefault(require("../manifest-schema.json")); | ||
const validate_https_url_1 = __importDefault(require("./validate-https-url")); | ||
const check_required_properties_1 = require("./check-required-properties"); | ||
/** | ||
@@ -20,2 +22,3 @@ * @param {Object} json | ||
let fileExists; | ||
const warnings = []; | ||
if (typeof options.relativePath === "function") { | ||
@@ -38,2 +41,3 @@ relativePath = options.relativePath; | ||
}); | ||
(0, ajv_formats_1.default)(ajv, { mode: "fast", formats: ["uri"] }); | ||
const validateMaxFileSize = (schema, filePath) => { | ||
@@ -102,2 +106,22 @@ var _a; | ||
}; | ||
const validateRequiredProperties = (schema, data) => { | ||
if (!data || data.length === 0) { | ||
return true; | ||
} | ||
const errors = (0, check_required_properties_1.checkRequiredProperties)(json, schema); | ||
if (errors.length === 0) { | ||
return true; | ||
} | ||
if (schema.warn) { | ||
warnings.push(...errors.map((error) => { | ||
return { message: error }; | ||
})); | ||
return true; | ||
} | ||
validateRequiredProperties.errors = errors.map((error) => ({ | ||
keyword: "requiredProperties", | ||
message: error, | ||
})); | ||
return false; | ||
}; | ||
ajv.addKeyword({ | ||
@@ -111,5 +135,13 @@ keyword: "maxFileSize", | ||
}); | ||
ajv.addKeyword({ | ||
keyword: "requiredProperties", | ||
validate: validateRequiredProperties, | ||
}); | ||
const validate = ajv.compile(manifest_schema_json_1.default); | ||
const valid = validate(json); | ||
return { valid, errors: transformErrors(validate.errors) }; | ||
return { | ||
valid, | ||
errors: transformErrors(validate.errors), | ||
warnings: warnings.length === 0 ? null : warnings, | ||
}; | ||
}; | ||
@@ -116,0 +148,0 @@ /** |
@@ -14,2 +14,3 @@ /* eslint-disable */ | ||
export interface KintonePluginManifestJson { | ||
$schema?: string; | ||
manifest_version: number; | ||
@@ -16,0 +17,0 @@ version: number | string; |
@@ -7,2 +7,6 @@ { | ||
"properties": { | ||
"$schema": { | ||
"type": "string", | ||
"format": "uri" | ||
}, | ||
"manifest_version": { | ||
@@ -35,3 +39,13 @@ "type": "integer", | ||
"minLength": 1, | ||
"maxLength": 64 | ||
"maxLength": 64, | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"homepage_url": { | ||
"properties": ["ja"] | ||
} | ||
} | ||
], | ||
"warn": true | ||
} | ||
}, | ||
@@ -41,3 +55,13 @@ "en": { | ||
"minLength": 1, | ||
"maxLength": 64 | ||
"maxLength": 64, | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"homepage_url": { | ||
"properties": ["en"] | ||
} | ||
} | ||
], | ||
"warn": true | ||
} | ||
}, | ||
@@ -47,3 +71,13 @@ "zh": { | ||
"minLength": 1, | ||
"maxLength": 64 | ||
"maxLength": 64, | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"homepage_url": { | ||
"properties": ["zh"] | ||
} | ||
} | ||
], | ||
"warn": true | ||
} | ||
}, | ||
@@ -53,3 +87,13 @@ "es": { | ||
"minLength": 1, | ||
"maxLength": 64 | ||
"maxLength": 64, | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"homepage_url": { | ||
"properties": ["es"] | ||
} | ||
} | ||
], | ||
"warn": true | ||
} | ||
} | ||
@@ -101,3 +145,12 @@ }, | ||
"minLength": 1, | ||
"format": "http-url" | ||
"format": "http-url", | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"name": { | ||
"properties": ["ja"] | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
@@ -107,3 +160,12 @@ "en": { | ||
"minLength": 1, | ||
"format": "http-url" | ||
"format": "http-url", | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"name": { | ||
"properties": ["en"] | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
@@ -113,3 +175,12 @@ "zh": { | ||
"minLength": 1, | ||
"format": "http-url" | ||
"format": "http-url", | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"name": { | ||
"properties": ["zh"] | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
@@ -119,3 +190,12 @@ "es": { | ||
"minLength": 1, | ||
"format": "http-url" | ||
"format": "http-url", | ||
"requiredProperties": { | ||
"items": [ | ||
{ | ||
"name": { | ||
"properties": ["es"] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
@@ -122,0 +202,0 @@ } |
{ | ||
"name": "@kintone/plugin-manifest-validator", | ||
"version": "10.1.0", | ||
"version": "10.2.0", | ||
"author": { | ||
@@ -20,13 +20,14 @@ "name": "Cybozu, Inc.", | ||
"ajv": "^8.12.0", | ||
"ajv-formats": "^2.1.1", | ||
"bytes": "^3.1.2" | ||
}, | ||
"devDependencies": { | ||
"@babel/preset-typescript": "^7.23.3", | ||
"@babel/preset-typescript": "^7.24.1", | ||
"@types/bytes": "^3.1.4", | ||
"babel-plugin-replace-ts-export-assignment": "^0.0.2", | ||
"intelli-espower-loader": "^1.1.0", | ||
"json-schema-to-typescript": "^13.1.1", | ||
"json-schema-to-typescript": "^13.1.2", | ||
"power-assert": "^1.6.1" | ||
}, | ||
"homepage": "https://github.com/kintone/js-sdk/tree/master/packages/plugin-manifest-validator#readme", | ||
"homepage": "https://github.com/kintone/js-sdk/tree/main/packages/plugin-manifest-validator#readme", | ||
"repository": { | ||
@@ -33,0 +34,0 @@ "type": "git", |
# @kintone/plugin-manifest-validator | ||
[![npm version](https://badge.fury.io/js/%40kintone%2Fplugin-manifest-validator.svg)](https://badge.fury.io/js/%40kintone%2Fplugin-manifest-validator) | ||
![Node.js version](https://img.shields.io/badge/dynamic/json.svg?url=https://raw.githubusercontent.com/kintone/js-sdk/master/packages/create-plugin/package.json&label=node&query=$.engines.node&colorB=blue) | ||
![Node.js version](https://img.shields.io/badge/dynamic/json.svg?url=https://raw.githubusercontent.com/kintone/js-sdk/main/packages/create-plugin/package.json&label=node&query=$.engines.node&colorB=blue) | ||
![License](https://img.shields.io/npm/l/@kintone/plugin-manifest-validator.svg) | ||
@@ -24,2 +24,3 @@ | ||
console.log(result.errors); // array of ajv error objects | ||
console.log(result.warnings); // string array | ||
``` | ||
@@ -59,4 +60,15 @@ | ||
## Setting the `$schema` property | ||
When you are configuring your project, you would better set the $schema property. This property should point to a schema file that validates your manifest. | ||
We recommend setting the $schema property to the following URI in your manifest.json: | ||
``` | ||
https://raw.githubusercontent.com/kintone/js-sdk/main/packages/plugin-manifest-validator/manifest-schema.json | ||
``` | ||
Note: Add or update the $schema property at the top of the manifest.json. | ||
## License | ||
MIT License |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
74629
19
854
73
3
+ Addedajv-formats@^2.1.1
+ Addedajv-formats@2.1.1(transitive)