Overview
The SnowplowIgluClient is a library for working with Iglu schema registries in Snowplow event tracking. It provides the functionality to validate, parse, and manipulate JSON instances against schemas.
Features
- Schema validation: Validate JSON instances against JSON schemas.
- Schema parsing: Parse and retrieve JSON schema definitions.
- Data enrichment: Enrich JSON instances with additional data based on schema context.
- Customization: Configure the client to work with different schema registries and providers.
Installation
To install the SnowplowIgluClient, follow these steps:
- Open your terminal or command prompt.
- Navigate to your project directory.
- Run the command
npm install snowplow-iglu-client
.
Usage
To use the SnowplowIgluClient in your project, follow these steps:
- Import the SnowplowIgluClient module into your project:
- Create an instance of the client:
- Configure the client with your schema registry details:
- Validate a JSON instance against a schema:
import IgluClient from 'snowplow-iglu-client';
const igluClient = new IgluClient();
// Example configuration
const registryConfig = {
schema: 'iglu:com.acme/my_schema/jsonschema/1-0-0',
connection: {
http: {
client: 'http',
uri: 'https://your-registry.com'
}
}
};
// Set the registry configuration
igluClient.setRegistryConfig(registryConfig);
const instance = {
"name": "John Doe",
"age": 30
};
const schemaKey = "com.acme/my_schema/jsonschema/1-0-0";
// Validate the instance against the schema
const validationResult = igluClient.validate(instance, schemaKey);
if (validationResult.valid) {
console.log('Instance is valid!');
} else {
console.log('Instance is invalid:', validationResult.errors);
}
Customization
The SnowplowIgluClient allows for customization through configuration. You can configure:
- Schema registry details
- Provider details
- Custom rules for data enrichment
To customize the client, follow these steps:
- Create a configuration object with your desired customizations.
- Pass the configuration object to the respective client method:
// Configure the schema registry connection
const registryConfig = {
connection: {
http: {
client: 'http',
uri: 'https://your-registry.com'
}
}
};
igluClient.setRegistryConfig(registryConfig);
// Configure a provider
const providerConfig = {
name: 'MyProvider',
priority: 1,
vendorPrefixes: ['com.acme']
};
igluClient.addProvider(providerConfig);
// Add a custom rule for data enrichment
const enrichmentRule = {
schema: "iglu:com.acme/enrichment_rule/jsonschema/2-0-0",
attachTo: "event",
enabled: true,
vendorPrefixes: ['com.acme']
};
igluClient.addEnrichmentRule(enrichmentRule);
Contribution
Contributions to the SnowplowIgluClient are welcome! If you find a bug, have a feature request or want to suggest improvements, feel free to raise an issue or submit a pull request on the SnowplowIgluClient GitHub repository.
License
The SnowplowIgluClient is released under the Apache License 2.0. See the LICENSE file for more details.