@requestnetwork/data-format
Advanced tools
Comparing version 0.8.0 to 0.8.1-next.709
@@ -134,4 +134,3 @@ { | ||
"type": "string", | ||
"minLength": 3, | ||
"maxLength": 3 | ||
"minLength": 2 | ||
}, | ||
@@ -138,0 +137,0 @@ "deliveryDate": { |
@@ -138,4 +138,3 @@ { | ||
"type": "string", | ||
"minLength": 2, | ||
"maxLength": 5 | ||
"minLength": 2 | ||
}, | ||
@@ -142,0 +141,0 @@ "deliveryDate": { |
@@ -171,4 +171,3 @@ { | ||
"type": "string", | ||
"minLength": 2, | ||
"maxLength": 5 | ||
"minLength": 2 | ||
}, | ||
@@ -175,0 +174,0 @@ "deliveryDate": { |
@@ -1,16 +0,14 @@ | ||
declare const _default: { | ||
/** | ||
* validation of data | ||
* @param data object you want to validate | ||
* @return object.valid == true if the json is valid, object.valid == false and object.errors otherwise. | ||
*/ | ||
validate(data: any): any; | ||
/** | ||
* Check if the object format is known | ||
* @param data the object to check | ||
* @return true if the object format is known | ||
*/ | ||
isKnownFormat(data: any): boolean; | ||
}; | ||
export default _default; | ||
/** | ||
* validation of data | ||
* @param data object you want to validate | ||
* @return object.valid == true if the json is valid, object.valid == false and object.errors otherwise. | ||
*/ | ||
export declare function validate(data: any): any; | ||
/** | ||
* Check if the object format is known | ||
* @param data the object to check | ||
* @return true if the object format is known | ||
*/ | ||
export declare function isKnownFormat(data: any): boolean; | ||
export * from './format/rnf_invoice'; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// JSON Schema of an address | ||
exports.isKnownFormat = exports.validate = void 0; | ||
const tslib_1 = require("tslib"); | ||
const AJV = require("ajv"); | ||
const jsonSchema = require("ajv/lib/refs/json-schema-draft-06.json"); | ||
const schemaAddress = require("./format/address.json"); | ||
/* eslint-disable spellcheck/spell-checker */ | ||
// another json validation tool from https://github.com/epoberezkin/ajv | ||
const AJV = require("ajv"); | ||
/* eslint-disable spellcheck/spell-checker */ | ||
exports.default = { | ||
/** | ||
* validation of data | ||
* @param data object you want to validate | ||
* @return object.valid == true if the json is valid, object.valid == false and object.errors otherwise. | ||
*/ | ||
validate(data) { | ||
const validationTool = new AJV() | ||
.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json')) | ||
.addSchema(schemaAddress); | ||
// Check the meta information | ||
if (!data.meta) { | ||
return { valid: false, errors: [{ message: 'meta not found' }] }; | ||
} | ||
if (!data.meta.format) { | ||
return { valid: false, errors: [{ message: 'meta.format not found' }] }; | ||
} | ||
if (!data.meta.version) { | ||
return { valid: false, errors: [{ message: 'meta.version not found' }] }; | ||
} | ||
// Try to retrieve the schema json | ||
let schema; | ||
try { | ||
schema = require(`./format/${data.meta.format}/${data.meta.format}-${data.meta.version}.json`); | ||
} | ||
catch (e) { | ||
return { valid: false, errors: [{ message: 'format not found' }] }; | ||
} | ||
// Compile and Validate | ||
const validate = validationTool.compile(schema); | ||
const valid = validate(data); | ||
// If not valid return the error | ||
if (!valid) { | ||
return { valid: false, errors: validate.errors }; | ||
} | ||
return { valid: true }; | ||
}, | ||
/** | ||
* Check if the object format is known | ||
* @param data the object to check | ||
* @return true if the object format is known | ||
*/ | ||
isKnownFormat(data) { | ||
return !!data.meta && data.meta.format === 'rnf_invoice'; | ||
}, | ||
}; | ||
const format_1 = require("./format"); | ||
/** | ||
* validation of data | ||
* @param data object you want to validate | ||
* @return object.valid == true if the json is valid, object.valid == false and object.errors otherwise. | ||
*/ | ||
function validate(data) { | ||
var _a; | ||
const validationTool = new AJV().addMetaSchema(jsonSchema).addSchema(schemaAddress); | ||
// Check the meta information | ||
if (!data.meta) { | ||
return { valid: false, errors: [{ message: 'meta not found' }] }; | ||
} | ||
if (!data.meta.format) { | ||
return { valid: false, errors: [{ message: 'meta.format not found' }] }; | ||
} | ||
if (!data.meta.version) { | ||
return { valid: false, errors: [{ message: 'meta.version not found' }] }; | ||
} | ||
// Try to retrieve the schema json | ||
const schema = (_a = format_1.formats[data.meta.format]) === null || _a === void 0 ? void 0 : _a[data.meta.version]; | ||
if (!schema) { | ||
return { valid: false, errors: [{ message: 'format not found' }] }; | ||
} | ||
// Compile and Validate | ||
const validate = validationTool.compile(schema); | ||
const valid = validate(data); | ||
// If not valid return the error | ||
if (!valid) { | ||
return { valid: false, errors: validate.errors }; | ||
} | ||
return { valid: true }; | ||
} | ||
exports.validate = validate; | ||
/** | ||
* Check if the object format is known | ||
* @param data the object to check | ||
* @return true if the object format is known | ||
*/ | ||
function isKnownFormat(data) { | ||
return !!data.meta && data.meta.format === 'rnf_invoice'; | ||
} | ||
exports.isKnownFormat = isKnownFormat; | ||
// FIXME it would be better to export a subpath, ie @requestnetwork/data-format/invoice, | ||
// using `exports` as introduced in Node 12.7.0 (https://nodejs.org/api/packages.html#packages_subpath_exports) | ||
// but typescript doesn't currently support this (https://github.com/microsoft/TypeScript/issues/33079) | ||
// NB: compatibilty with browser would need to be tested. | ||
tslib_1.__exportStar(require("./format/rnf_invoice"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@requestnetwork/data-format", | ||
"version": "0.8.0", | ||
"version": "0.8.1-next.709+44946236", | ||
"publishConfig": { | ||
@@ -23,3 +23,3 @@ "access": "public" | ||
"engines": { | ||
"node": ">=8.0.0" | ||
"node": ">=18.0.0" | ||
}, | ||
@@ -36,6 +36,6 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc -b", | ||
"clean": "shx rm -rf dist tsconfig.tsbuildinfo", | ||
"lint": "tslint --project . && eslint \"src/**/*.ts\"", | ||
"lint-staged": "lint-staged", | ||
"build": "tsc -b tsconfig.build.json", | ||
"clean": "rm -rf dist tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo", | ||
"lint": "eslint . --fix", | ||
"lint:check": "eslint .", | ||
"test": "jest", | ||
@@ -46,19 +46,12 @@ "test:watch": "yarn test --watch" | ||
"ajv": "6.12.4", | ||
"tslib": "2.0.1" | ||
"ethers": "5.5.1", | ||
"tslib": "2.5.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "14.6.4", | ||
"eslint": "7.9.0", | ||
"eslint-plugin-spellcheck": "0.0.17", | ||
"eslint-plugin-typescript": "0.14.0", | ||
"lint-staged": "10.3.0", | ||
"nyc": "15.1.0", | ||
"prettier": "2.1.1", | ||
"rimraf": "3.0.2", | ||
"shx": "0.3.2", | ||
"ts-node": "9.0.0", | ||
"tslint": "6.1.3", | ||
"typescript": "4.0.2" | ||
"@types/node": "18.11.9", | ||
"jest-junit": "16.0.0", | ||
"ts-node": "10.9.1", | ||
"typescript": "5.1.3" | ||
}, | ||
"gitHead": "1cc3a0743726f6c314f9651b26bfcb29a49cf98e" | ||
"gitHead": "449462366df9f74a825fef46339012111816f0c3" | ||
} |
@@ -15,3 +15,3 @@ # @requestnetwork/data-format | ||
```js | ||
import dataFormat from '@requestnetwork/data-format'; | ||
import * as dataFormat from '@requestnetwork/data-format'; | ||
@@ -18,0 +18,0 @@ let result = data - format.validate(A_JSON_OBJECT); |
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
4
27
783
0
38109
3
1
+ Addedethers@5.5.1
+ Added@ethersproject/abi@5.5.0(transitive)
+ Added@ethersproject/abstract-provider@5.5.1(transitive)
+ Added@ethersproject/abstract-signer@5.5.0(transitive)
+ Added@ethersproject/address@5.5.0(transitive)
+ Added@ethersproject/base64@5.5.0(transitive)
+ Added@ethersproject/basex@5.5.0(transitive)
+ Added@ethersproject/bignumber@5.5.0(transitive)
+ Added@ethersproject/bytes@5.5.0(transitive)
+ Added@ethersproject/constants@5.5.0(transitive)
+ Added@ethersproject/contracts@5.5.0(transitive)
+ Added@ethersproject/hash@5.5.0(transitive)
+ Added@ethersproject/hdnode@5.5.0(transitive)
+ Added@ethersproject/json-wallets@5.5.0(transitive)
+ Added@ethersproject/keccak256@5.5.0(transitive)
+ Added@ethersproject/logger@5.5.0(transitive)
+ Added@ethersproject/networks@5.5.0(transitive)
+ Added@ethersproject/pbkdf2@5.5.0(transitive)
+ Added@ethersproject/properties@5.5.0(transitive)
+ Added@ethersproject/providers@5.5.0(transitive)
+ Added@ethersproject/random@5.5.0(transitive)
+ Added@ethersproject/rlp@5.5.0(transitive)
+ Added@ethersproject/sha2@5.5.0(transitive)
+ Added@ethersproject/signing-key@5.5.0(transitive)
+ Added@ethersproject/solidity@5.5.0(transitive)
+ Added@ethersproject/strings@5.5.0(transitive)
+ Added@ethersproject/transactions@5.5.0(transitive)
+ Added@ethersproject/units@5.5.0(transitive)
+ Added@ethersproject/wallet@5.5.0(transitive)
+ Added@ethersproject/web@5.5.0(transitive)
+ Added@ethersproject/wordlists@5.5.0(transitive)
+ Addedaes-js@3.0.0(transitive)
+ Addedbech32@1.1.4(transitive)
+ Addedbn.js@4.12.1(transitive)
+ Addedbrorand@1.1.0(transitive)
+ Addedelliptic@6.5.4(transitive)
+ Addedethers@5.5.1(transitive)
+ Addedhash.js@1.1.7(transitive)
+ Addedhmac-drbg@1.0.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedjs-sha3@0.8.0(transitive)
+ Addedminimalistic-assert@1.0.1(transitive)
+ Addedminimalistic-crypto-utils@1.0.1(transitive)
+ Addedscrypt-js@3.0.1(transitive)
+ Addedtslib@2.5.0(transitive)
+ Addedws@7.4.6(transitive)
- Removedtslib@2.0.1(transitive)
Updatedtslib@2.5.0