ski-mask
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

NPM

Ski Mask

Schema validation tool for Snowplow Iglu JSON schemas.


Command line Usage

  1. Install ski-mask
npm install ski-mask -g
# Or 
yarn global add ski-mask
  1. Grab a valid Iglu resolver.json file that resolves to your Iglu server(s).

  2. Run ski-mask to validate the payload.

ski-mask -r ./path/to/resolver.json -d ./path/to/snowplow-payload-data.json

Example

  1. Prepare your data.json file that represents your Snowplow Payload.
{
    "schema": "iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0",
    "data": {
        "event_name": "link_click",
        "schema": "iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-0",
        "data": {
            "targetUrl": "https://myawesomeurl.com/data",
            "elementId": "bestElementEver"
        }
    }
}
  1. Grab your Iglu resolver config file and name it something like resolver.json.
{
    "schema": "iglu:com.snowplowanalytics.iglu/resolver-config/jsonschema/1-0-0",
    "data":
    {
        "cachesize": 500,
        "repositories":
        [
            {
                "name": "iglu central",
                "priority": 0,
                "vendorprefixes":
                [
                    "com.snowplowanalytics.snowplow"
                ],
                "connection":
                {
                    "http":
                    {
                        "uri": "http://iglucentral.com"
                    }
                }
            },
            {
                "name": "my iglu server",
                "priority": 1,
                "vendorprefixes":
                [
                    "com.my-iglu-server"
                ],
                "connection":
                {
                    "http":
                    {
                        "uri": "http://awesome-schemas.my-iglu-server.com"
                    }
                }
            }
        ]
    }
}
  1. Run ski-mask to validate the payload.
ski-mask -r ./path/to/resolver.json -d ./path/to/snowplow-payload-data.json

Programmatic usage

  1. Add ski-mask to your package.json
npm install ski-mask --dev
# or 
yarn add ski-mask --dev
  1. Use the API
const skiMask = require('ski-mask');
// or import validate from 'ski-mask'
 
 
const payload = {
    "schema": "iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0",
    "data": {
        "event_name": "link_click",
        "schema": "iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-0",
        "data": {
            "targetUrl": "https://myawesomeurl.com/data",
            "elementId": "bestElementEver"
        }
    }
};
 
const resolverConfig = {
    "schema": "iglu:com.snowplowanalytics.iglu/resolver-config/jsonschema/1-0-0",
    "data":
    {
        "cacheSize": 500,
        "repositories":
        [
            {
                "name": "Iglu Central",
                "priority": 0,
                "vendorPrefixes":
                [
                    "com.snowplowanalytics.snowplow"
                ],
                "connection":
                {
                    "http":
                    {
                        "uri": "http://iglucentral.com"
                    }
                }
            },
            {
                "name": "My Iglu Server",
                "priority": 1,
                "vendorPrefixes":
                [
                    "com.my-iglu-server"
                ],
                "connection":
                {
                    "http":
                    {
                        "uri": "http://awesome-schemas.my-iglu-server.com"
                    }
                }
            }
        ]
    }
};
 
skiMask.validate(payload, resolverConfig).then(
    msg => console.log(msg)
)
 
// Will yield a result object
 
// {
//   success: true,
//   message: 'All Valid'
// }
 
// or
 
// {
//   success: false,
//   message: 'some error message',
//   context: 'some context for the error message'
// }

Readme

Keywords

none

Package Sidebar

Install

npm i ski-mask

Weekly Downloads

2

Version

1.1.3

License

MIT

Last publish

Collaborators

  • premjg