Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@requestnetwork/data-format

Package Overview
Dependencies
Maintainers
0
Versions
671
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@requestnetwork/data-format - npm Package Compare versions

Comparing version 0.8.0 to 0.8.1-next.709

dist/format/index.d.ts

3

dist/format/rnf_invoice/rnf_invoice-0.0.1.json

@@ -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

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