@kintone/plugin-manifest-validator
Advanced tools
Comparing version 9.0.1 to 9.1.0
@@ -17,3 +17,4 @@ { | ||
}, | ||
{ "type": "string", | ||
{ | ||
"type": "string", | ||
"pattern": "^(0|[1-9]\\d*)(?:\\.(0|[1-9]\\d*))?(?:\\.(0|[1-9]\\d*))?$" | ||
@@ -47,5 +48,3 @@ } | ||
}, | ||
"required": [ | ||
"en" | ||
] | ||
"required": ["en"] | ||
}, | ||
@@ -72,5 +71,3 @@ "description": { | ||
}, | ||
"required": [ | ||
"en" | ||
] | ||
"required": ["en"] | ||
}, | ||
@@ -82,3 +79,4 @@ "icon": { | ||
"format": "relative-path", | ||
"maxFileSize": "20MB" | ||
"maxFileSize": "20MB", | ||
"fileExists": true | ||
}, | ||
@@ -139,3 +137,4 @@ "homepage_url": { | ||
"maxFileSize": "65535B", | ||
"minLength": 1 | ||
"minLength": 1, | ||
"fileExists": true | ||
}, | ||
@@ -159,9 +158,3 @@ "js": { | ||
}, | ||
"required": [ | ||
"manifest_version", | ||
"version", | ||
"type", | ||
"name", | ||
"icon" | ||
], | ||
"required": ["manifest_version", "version", "type", "name", "icon"], | ||
"definitions": { | ||
@@ -174,8 +167,12 @@ "resources": { | ||
"type": "string", | ||
"anyOf": [{ | ||
"anyOf": [ | ||
{ | ||
"format": "https-url" | ||
}, { | ||
}, | ||
{ | ||
"format": "relative-path", | ||
"maxFileSize": "20MB" | ||
}] | ||
"maxFileSize": "20MB", | ||
"fileExists": true | ||
} | ||
] | ||
}, | ||
@@ -182,0 +179,0 @@ "maxItems": 30 |
@@ -6,2 +6,13 @@ import type { ErrorObject } from "ajv"; | ||
}; | ||
type ValidatorResult = boolean | { | ||
valid: true; | ||
} | { | ||
valid: false; | ||
message?: string; | ||
}; | ||
type Options = { | ||
relativePath?: (filePath: string) => boolean; | ||
maxFileSize?: (maxBytes: number, filePath: string) => ValidatorResult; | ||
fileExists?: (filePath: string) => ValidatorResult; | ||
}; | ||
/** | ||
@@ -12,5 +23,3 @@ * @param {Object} json | ||
*/ | ||
declare const _default: (json: Record<string, any>, options?: { | ||
[s: string]: (...args: any) => boolean; | ||
}) => ValidateResult; | ||
declare const _default: (json: Record<string, any>, options?: Options) => ValidateResult; | ||
export default _default; |
@@ -16,4 +16,5 @@ "use strict"; | ||
exports.default = (json, options = {}) => { | ||
let relativePath = (...args) => true; | ||
let maxFileSize = (...args) => true; | ||
let relativePath = () => true; | ||
let maxFileSize; | ||
let fileExists; | ||
if (typeof options.relativePath === "function") { | ||
@@ -25,2 +26,5 @@ relativePath = options.relativePath; | ||
} | ||
if (typeof options.fileExists === "function") { | ||
fileExists = options.fileExists; | ||
} | ||
const ajv = new ajv_1.default({ | ||
@@ -34,8 +38,13 @@ allErrors: true, | ||
}); | ||
const validateMaxFileSize = (schema, data) => { | ||
const validateMaxFileSize = (schema, filePath) => { | ||
var _a; | ||
// schema: max file size like "512KB" or 123 (in bytes) | ||
// data: path to the file | ||
if (maxFileSize === undefined) { | ||
return true; | ||
} | ||
const maxBytes = bytes_1.default.parse(schema); | ||
const valid = maxFileSize(maxBytes, data); | ||
if (!valid) { | ||
const result = maxFileSize(maxBytes, filePath); | ||
const defaultMessage = `file size should be <= ${schema}`; | ||
if (result === false) { | ||
validateMaxFileSize.errors = [ | ||
@@ -47,8 +56,48 @@ { | ||
}, | ||
message: `file size should be <= ${schema}`, | ||
message: defaultMessage, | ||
}, | ||
]; | ||
return false; | ||
} | ||
return valid; | ||
if (typeof result === "object" && !result.valid) { | ||
validateMaxFileSize.errors = [ | ||
{ | ||
keyword: "maxFileSize", | ||
params: { | ||
limit: maxBytes, | ||
}, | ||
message: (_a = result.message) !== null && _a !== void 0 ? _a : defaultMessage, | ||
}, | ||
]; | ||
return false; | ||
} | ||
return true; | ||
}; | ||
const validateFileExists = (schema, filePath) => { | ||
var _a; | ||
if (fileExists === undefined || !schema) { | ||
return true; | ||
} | ||
const result = fileExists(filePath); | ||
const defaultMessage = `file should exist ("${filePath}")`; | ||
if (result === false) { | ||
validateFileExists.errors = [ | ||
{ | ||
keyword: "fileExists", | ||
message: defaultMessage, | ||
}, | ||
]; | ||
return false; | ||
} | ||
if (typeof result === "object" && !result.valid) { | ||
validateFileExists.errors = [ | ||
{ | ||
keyword: "fileExists", | ||
message: (_a = result.message) !== null && _a !== void 0 ? _a : defaultMessage, | ||
}, | ||
]; | ||
return false; | ||
} | ||
return true; | ||
}; | ||
ajv.addKeyword({ | ||
@@ -58,2 +107,6 @@ keyword: "maxFileSize", | ||
}); | ||
ajv.addKeyword({ | ||
keyword: "fileExists", | ||
validate: validateFileExists, | ||
}); | ||
const validate = ajv.compile(manifest_schema_json_1.default); | ||
@@ -60,0 +113,0 @@ const valid = validate(json); |
@@ -17,3 +17,4 @@ { | ||
}, | ||
{ "type": "string", | ||
{ | ||
"type": "string", | ||
"pattern": "^(0|[1-9]\\d*)(?:\\.(0|[1-9]\\d*))?(?:\\.(0|[1-9]\\d*))?$" | ||
@@ -47,5 +48,3 @@ } | ||
}, | ||
"required": [ | ||
"en" | ||
] | ||
"required": ["en"] | ||
}, | ||
@@ -72,5 +71,3 @@ "description": { | ||
}, | ||
"required": [ | ||
"en" | ||
] | ||
"required": ["en"] | ||
}, | ||
@@ -82,3 +79,4 @@ "icon": { | ||
"format": "relative-path", | ||
"maxFileSize": "20MB" | ||
"maxFileSize": "20MB", | ||
"fileExists": true | ||
}, | ||
@@ -125,3 +123,3 @@ "homepage_url": { | ||
}, | ||
"css":{ | ||
"css": { | ||
"$ref": "#/definitions/resources" | ||
@@ -140,3 +138,4 @@ } | ||
"maxFileSize": "65535B", | ||
"minLength": 1 | ||
"minLength": 1, | ||
"fileExists": true | ||
}, | ||
@@ -160,9 +159,3 @@ "js": { | ||
}, | ||
"required": [ | ||
"manifest_version", | ||
"version", | ||
"type", | ||
"name", | ||
"icon" | ||
], | ||
"required": ["manifest_version", "version", "type", "name", "icon"], | ||
"definitions": { | ||
@@ -175,8 +168,12 @@ "resources": { | ||
"type": "string", | ||
"anyOf": [{ | ||
"format": "https-url" | ||
}, { | ||
"format": "relative-path", | ||
"maxFileSize": "20MB" | ||
}] | ||
"anyOf": [ | ||
{ | ||
"format": "https-url" | ||
}, | ||
{ | ||
"format": "relative-path", | ||
"maxFileSize": "20MB", | ||
"fileExists": true | ||
} | ||
] | ||
}, | ||
@@ -183,0 +180,0 @@ "maxItems": 30 |
{ | ||
"name": "@kintone/plugin-manifest-validator", | ||
"version": "9.0.1", | ||
"version": "9.1.0", | ||
"author": { | ||
@@ -18,14 +18,2 @@ "name": "Cybozu, Inc.", | ||
"types": "dist/src/index.d.ts", | ||
"scripts": { | ||
"start": "yarn build --watch", | ||
"prebuild": "yarn clean", | ||
"build": "tsc --build --force", | ||
"postbuild": "yarn gen-dts", | ||
"gen-dts": "node script/generate-dts.js", | ||
"test": "jest", | ||
"test:ci": "jest --runInBand", | ||
"lint": "eslint --ext .ts src", | ||
"fix": "yarn lint --fix", | ||
"clean": "rimraf dist" | ||
}, | ||
"dependencies": { | ||
@@ -36,7 +24,7 @@ "ajv": "^8.12.0", | ||
"devDependencies": { | ||
"@babel/preset-typescript": "^7.22.5", | ||
"@types/bytes": "^3.1.1", | ||
"@babel/preset-typescript": "^7.23.0", | ||
"@types/bytes": "^3.1.2", | ||
"babel-plugin-replace-ts-export-assignment": "^0.0.2", | ||
"intelli-espower-loader": "^1.1.0", | ||
"json-schema-to-typescript": "^11.0.5", | ||
"json-schema-to-typescript": "^13.1.1", | ||
"power-assert": "^1.6.1" | ||
@@ -57,3 +45,14 @@ }, | ||
"license": "MIT", | ||
"gitHead": "4ac0c15bf5e66ae18f1da5c514b9d8f35872f1a0" | ||
} | ||
"scripts": { | ||
"start": "pnpm build --watch", | ||
"prebuild": "pnpm clean", | ||
"build": "tsc --build --force", | ||
"postbuild": "pnpm gen-dts", | ||
"gen-dts": "node script/generate-dts.js", | ||
"test": "jest", | ||
"test:ci": "jest --runInBand", | ||
"lint": "eslint --ext .ts src --max-warnings 0", | ||
"fix": "pnpm lint --fix", | ||
"clean": "rimraf dist" | ||
} | ||
} |
@@ -1,3 +0,2 @@ | ||
@kintone/plugin-manifest-validator | ||
==== | ||
# @kintone/plugin-manifest-validator | ||
@@ -19,5 +18,5 @@ [![npm version](https://badge.fury.io/js/%40kintone%2Fplugin-manifest-validator.svg)](https://badge.fury.io/js/%40kintone%2Fplugin-manifest-validator) | ||
```js | ||
const validator = require('@kintone/plugin-manifest-validator'); | ||
const validator = require("@kintone/plugin-manifest-validator"); | ||
const manifestJson = require('./path/to/your/manifest.json'); | ||
const manifestJson = require("./path/to/your/manifest.json"); | ||
const result = validator(manifestJson); | ||
@@ -41,2 +40,3 @@ console.log(result.valid); // true or false | ||
``` | ||
## `manifest-schema.json` | ||
@@ -47,3 +47,3 @@ | ||
```js | ||
const manifestJsonSchema = require('@kintone/plugin-manifest-validator/manifest-schema.json'); | ||
const manifestJsonSchema = require("@kintone/plugin-manifest-validator/manifest-schema.json"); | ||
``` | ||
@@ -56,3 +56,3 @@ | ||
```typescript | ||
import {KintonePluginManifestJson} from '@kintone/plugin-manifest-validator/manifest-schema'; | ||
import { KintonePluginManifestJson } from "@kintone/plugin-manifest-validator/manifest-schema"; | ||
@@ -59,0 +59,0 @@ let manifest: KintonePluginManifestJson; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
575
50107