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

@cowprotocol/app-data

Package Overview
Dependencies
Maintainers
7
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cowprotocol/app-data - npm Package Compare versions

Comparing version 0.0.1-RC.1 to 0.0.1-RC.2

2

dist/index.modern.js

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

var n={__proto__:null},r={__proto__:null},t={__proto__:null},o={__proto__:null};const e="0.4.0",_="0.2.0",u="0.1.0";function i(){return i=Object.assign?Object.assign.bind():function(n){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o])}return n},i.apply(this,arguments)}function l(n){return i({},n,{version:"0.2.0"})}function s(n){return i({},n,{version:"0.1.0"})}function a(n){return i({},n,{version:"0.4.0"})}export{e as LATEST_APP_DATA_VERSION,_ as LATEST_QUOTE_METADATA_VERSION,u as LATEST_REFERRER_METADATA_VERSION,a as createAppDataDoc,l as createQuoteMetadata,s as createReferrerMetadata,o as latest,n as v0_1_0,r as v0_2_0,t as v0_3_0,o as v0_4_0};
import r from"ajv";var t={__proto__:null},n={__proto__:null},e={__proto__:null},o={__proto__:null};const s="0.4.0",a="0.2.0",i="0.1.0";function c(){return c=Object.assign?Object.assign.bind():function(r){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(r[e]=n[e])}return r},c.apply(this,arguments)}function u(r){return c({},r,{version:"0.2.0"})}function l(r){return c({},r,{version:"0.1.0"})}function p(r){return c({},r,{version:"0.4.0"})}async function _(r){if(!/^\d+\.\d+\.\d+$/.test(r))throw new Error(`AppData version ${r} is not a valid version`);try{return await import(`../schemas/v${r}.json`)}catch(t){throw new Error(`AppData version ${r} doesn't exist`)}}let v;async function f(t){const{version:n}=t;v||(v=new r);let e=v.getSchema(n);if(!e){let r;try{r=await _(n)}catch(r){if(r instanceof Error)return{success:!1,errors:r.message};throw r}v.addSchema(r,n),e=v.getSchema(n)}return{success:!!e(t),errors:e.errors?v.errorsText(e.errors):void 0}}export{s as LATEST_APP_DATA_VERSION,a as LATEST_QUOTE_METADATA_VERSION,i as LATEST_REFERRER_METADATA_VERSION,p as createAppDataDoc,u as createQuoteMetadata,l as createReferrerMetadata,_ as getAppDataSchema,o as latest,t as v0_1_0,n as v0_2_0,e as v0_3_0,o as v0_4_0,f as validateAppDataDoc};
//# sourceMappingURL=index.modern.js.map

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

var n={__proto__:null},r={__proto__:null},t={__proto__:null},o={__proto__:null},e="0.4.0",_="0.2.0",u="0.1.0";function i(){return i=Object.assign?Object.assign.bind():function(n){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o])}return n},i.apply(this,arguments)}function l(n){return i({},n,{version:"0.2.0"})}function a(n){return i({},n,{version:"0.1.0"})}function s(n){return i({},n,{version:"0.4.0"})}export{e as LATEST_APP_DATA_VERSION,_ as LATEST_QUOTE_METADATA_VERSION,u as LATEST_REFERRER_METADATA_VERSION,s as createAppDataDoc,l as createQuoteMetadata,a as createReferrerMetadata,o as latest,n as v0_1_0,r as v0_2_0,t as v0_3_0,o as v0_4_0};
import r from"ajv";var e={__proto__:null},t={__proto__:null},n={__proto__:null},o={__proto__:null};const s="0.4.0",i="0.2.0",c="0.1.0";function u(r,e){try{var t=r()}catch(r){return e(r)}return t&&t.then?t.then(void 0,e):t}const a=function(e){try{let n;function t(r){return n?r:{success:!!s(e),errors:s.errors?_.errorsText(s.errors):void 0}}const{version:o}=e;_||(_=new r);let s=_.getSchema(o);const i=function(){if(!s){function r(r){if(n)return r;_.addSchema(e,o),s=_.getSchema(o)}let e;const t=u(function(){return Promise.resolve(f(o)).then(function(r){e=r})},function(r){if(r instanceof Error)return n=1,{success:!1,errors:r.message};throw r});return t&&t.then?t.then(r):r(t)}}();return Promise.resolve(i&&i.then?i.then(t):t(i))}catch(c){return Promise.reject(c)}},f=function(r){try{if(!/^\d+\.\d+\.\d+$/.test(r))throw new Error(`AppData version ${r} is not a valid version`);return Promise.resolve(u(function(){return Promise.resolve(import(`../schemas/v${r}.json`))},function(){throw new Error(`AppData version ${r} doesn't exist`)}))}catch(r){return Promise.reject(r)}};function l(r){return{...r,version:"0.2.0"}}function v(r){return{...r,version:"0.1.0"}}function h(r){return{...r,version:"0.4.0"}}let _;export{s as LATEST_APP_DATA_VERSION,i as LATEST_QUOTE_METADATA_VERSION,c as LATEST_REFERRER_METADATA_VERSION,h as createAppDataDoc,l as createQuoteMetadata,v as createReferrerMetadata,f as getAppDataSchema,o as latest,e as v0_1_0,t as v0_2_0,n as v0_3_0,o as v0_4_0,a as validateAppDataDoc};
//# sourceMappingURL=index.module.js.map

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).appData={})}(this,function(e){var t={__proto__:null},n="0.4.0",o="0.2.0",r="0.1.0";function _(){return _=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},_.apply(this,arguments)}e.LATEST_APP_DATA_VERSION=n,e.LATEST_QUOTE_METADATA_VERSION=o,e.LATEST_REFERRER_METADATA_VERSION=r,e.createAppDataDoc=function(e){return _({},e,{version:n})},e.createQuoteMetadata=function(e){return _({},e,{version:o})},e.createReferrerMetadata=function(e){return _({},e,{version:r})},e.latest=t,e.v0_1_0={__proto__:null},e.v0_2_0={__proto__:null},e.v0_3_0={__proto__:null},e.v0_4_0=t});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("ajv")):"function"==typeof define&&define.amd?define(["exports","ajv"],t):t((e||self).appData={},e.ajv)}(this,function(e,t){function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=/*#__PURE__*/r(t),o={__proto__:null};const i="0.4.0",s="0.2.0",a="0.1.0";function c(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}const u=function(e){try{if(!/^\d+\.\d+\.\d+$/.test(e))throw new Error(`AppData version ${e} is not a valid version`);return Promise.resolve(c(function(){return Promise.resolve(import(`../schemas/v${e}.json`))},function(){throw new Error(`AppData version ${e} doesn't exist`)}))}catch(e){return Promise.reject(e)}};let f;e.LATEST_APP_DATA_VERSION=i,e.LATEST_QUOTE_METADATA_VERSION=s,e.LATEST_REFERRER_METADATA_VERSION=a,e.createAppDataDoc=function(e){return{...e,version:i}},e.createQuoteMetadata=function(e){return{...e,version:s}},e.createReferrerMetadata=function(e){return{...e,version:a}},e.getAppDataSchema=u,e.latest=o,e.v0_1_0={__proto__:null},e.v0_2_0={__proto__:null},e.v0_3_0={__proto__:null},e.v0_4_0=o,e.validateAppDataDoc=function(e){try{let r;function t(t){return r?t:{success:!!i(e),errors:i.errors?f.errorsText(i.errors):void 0}}const{version:o}=e;f||(f=new n.default);let i=f.getSchema(o);const s=function(){if(!i){function e(e){if(r)return e;f.addSchema(t,o),i=f.getSchema(o)}let t;const n=c(function(){return Promise.resolve(u(o)).then(function(e){t=e})},function(e){if(e instanceof Error)return r=1,{success:!1,errors:e.message};throw e});return n&&n.then?n.then(e):e(n)}}();return Promise.resolve(s&&s.then?s.then(t):t(s))}catch(a){return Promise.reject(a)}}});
//# sourceMappingURL=index.umd.js.map

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

import { latest } from "./generatedTypes";
import { AnyAppDataDocVersion, latest } from './generatedTypes';
export declare function createQuoteMetadata(params: {

@@ -13,1 +13,7 @@ slippageBips: latest.SlippageBips;

}): latest.AppDataRootSchema;
export declare function getAppDataSchema(version: string): Promise<AnyAppDataDocVersion>;
export declare type ValidationResult = {
success: boolean;
errors?: string;
};
export declare function validateAppDataDoc(appDataDoc: AnyAppDataDocVersion): Promise<ValidationResult>;
{
"name": "@cowprotocol/app-data",
"version": "0.0.1-RC.1",
"version": "0.0.1-RC.2",
"description": "CowProtocol AppData schema definitions",

@@ -23,3 +23,4 @@ "type": "module",

"build": "yarn clean && yarn compile && microbundle",
"prepare": "npm run build"
"test": "jest",
"prepare": "yarn build && yarn test"
},

@@ -36,10 +37,33 @@ "repository": {

"devDependencies": {
"@babel/core": "^7.18.9",
"@babel/preset-env": "^7.18.9",
"@babel/preset-typescript": "^7.18.6",
"@types/jest": "^28.1.6",
"@types/semver-sort": "^0.0.1",
"babel-jest": "^28.1.3",
"jest": "^28.1.3",
"json-schema-ref-parser": "^9.0.9",
"json-schema-to-typescript": "^10.1.5",
"microbundle": "^0.15.0",
"prettier": "^2.7.1",
"semver-sort": "^1.0.0",
"ts-node": "^10.8.2",
"typescript": "^4.7.4"
},
"dependencies": {
"ajv": "^8.11.0"
},
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"@babel/preset-typescript"
]
}
}

@@ -27,3 +27,3 @@ # @cowprotocol/app-data

```js
import {v0_4_0} from '@cowprotocol/app-data'
import { v0_4_0 } from '@cowprotocol/app-data'

@@ -57,2 +57,4 @@ // Note: this example is

*Create appData doc*
There are util functions to handle the creation of valid schema docs for the latest version

@@ -65,11 +67,39 @@

const referrer = createReferrerMetadata({address: '0x...'})
const quote = createQuoteMetadata({slippageBips: '100'})
const appDataDoc = createAppDataDoc({appCode: 'myApp', metadata: {referrer, quote}})
const referrer = createReferrerMetadata({ address: '0x...' })
const quote = createQuoteMetadata({ slippageBips: '100' })
const appDataDoc = createAppDataDoc({ appCode: 'myApp', metadata: { referrer, quote } })
```
## TODO:
*Get appData schema*
- [ ] Add tests for:
- [ ] Consuming only the schema
- [ ] Importing the type definitions
To get a schema definition by version
```js
import { getAppDataSchema } from '@cowprotocol/app-data'
const schema = getAppDataSchema('0.1.0')
```
It'll throw if the version does not exist
*Validate appDataDoc*
To validate a document, pass it to `validateAppDataDoc`.
It'll return an object with a boolean indicating `success` and `errors`, if any.
The version to validate against will be taken from the doc itself.
```js
import { validateAppDataDoc } from '@cowprotocol/app-data'
let doc = { version: '0.4.0', metadata: {} }
let result = await validateAppDataDoc(doc)
console.log(result) // { success: true }
doc = { version: '0.0.0', metadata: {} }
result = await validateAppDataDoc(doc)
// Contrary to `getAppDataSchema`, invalid or non-existing schemas won't throw
console.log(result) // { success: false, errors: 'AppData version 0.0.0 doesn\'t exist'}
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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