Skip to content

prosperodatamask/prosperoutils

Repository files navigation

Prospero Utilities

Checks Test Coverage Maintainability

This package is a set of utility methods to help with Prosper UI and Prospero CLI to mask data from files.

Usage

The basic usage of this module is to call listModules to get a module name to description map this is most useful for providing the available options to a front end for a user. Then you can use the modules field to get to your transformer.

Examples

Use a module through the base class

const prospero = require('propsero');

const replace_opts = {
  replacement: 'XXXXXXXXXXX'
};
const instance = new prospero.modules['replace'].Transformer(replace_opts);
instance.transform('My data goes here'); // returns 'XXXXXXXXXXX'

Require module directly

const replace = require('prospero/replace');

const replace_opts = {
  replacement: 'XXXXXXXXXXX'
};
const instance = new replace.Transformer(replace_opts);
instance.transform('My data goes here'); // returns 'XXXXXXXXXXX'

Require module via destructuring

const {
  replace
} = require('prospero');

Modules

Copy

The copy module takes the data passed into the transform function and returns the data passed in.

Copy Options

None

Copy Examples

const instance = new require('prospero/copy').Transformer();

expect(instance.transform('Input Text')).toEqual('Input Text');

Replace

The replace module takes the data passed into the transform function and replaces it with data from options.

Replace Options

Name Type Description Default
replacement string The replacement text REDACTED
matchlength boolean If the replacement should match the length of the input data false

Replace Examples

const instance_nomatch = new require('prospero/replace').Transformer();

const opts = {
  matchlength: true
};
const instance_match = new require('prospero/replace').Transformer(opts);

expect(instance_nomatch.transform('Input Text')).toEqual('REDACTED');
expect(instance_match.transform('Input Text')).toEqual('REDACTEDRE');

Salesforce Id

The salesforceid module takes Salesforce Ids and masks them in ways that would be useful by preserving key parts of the data but masking the information that makes the Id retrievable.

Salesforce Id Options

Name Type Description Default
preserveobjectkey boolean Preserves the first three characters of the Id to help identify what object the Id is for true
mask string The text to mask the Id with X
masklength number The number of characters at the end of the Id to mask 6
normalizelength boolean If the Id should be normalized to 18 characters true

Salesforce Id Examples

const instance_default = new require('prospero/salesforce/id').Transformer();
const opts = {
  mask: 'ACCOUNT',
  masklength: 3,
  normalizelength: false
};
const instance_opts = new require('prospero').salesforceid.Transformer(opts);

expect(instance_default.transform('0018A00000Q9FuoQAF')).toEqual('0018A00000Q9XXXXXX');
expect(instance_opts.transform('0018A00000Q9Fuo')).toEqual('0018A00000Q9ACC');

Adding new modules

Create a new module file under the root that extends the Transformer class provided by the utils module. Then pass in your module's name and it's configuration and options (if valid) to the super constructor. The implement your transform method. Each module must export the following properties

  • name - The name of the module
  • description - A brief description of what the module does
  • Transformer - The transformer class

Example

const Transformer = require('./utils').Transformer;

const NAME = 'ysac';
const DISPLAY_NAME = 'You Suck at Cooking';
const DESCRIPTION = 'Replaces the data with a given number of peppers';

const options = [
  {
    name: 'count',
    display_name: 'Pepper Count',
    description: 'The number of peppers to return',
    type: 'number',
    default: 3,
    /**
     * Makes sure that you don't do too much pepper
     * @returns {undefined}
     * @throws {Error} If there's too much pepper
     */
    check: function () {
      if (this.count.value > 3) {
        throw new Error('Too much pepper');
      }
    }
  }
];

/**
 * The You Suck at Cooking transformer
 */
class YSAC extends Transformer {
  /**
   * The constructor
   * @param {Object} opts The options
   */
  constructor(opts) {
    super('ysac', options, opts);
  }

  /**
   * Transforms the data by outputting pepper a bunch of times
   *
   * NOTE: No parameter since we don't care what the source data is
   * @returns {String} The transformed data
   */
  transform() {
    const peppers = [];

    for (let i = 0; i < this.config.count.value; i += 1) {
      peppers.push('Pepper');
    }

    return peppers.join(' ');
  }
}

module.exports = {
  name: NAME,
  display_name: DISPLAY_NAME,
  description: DESCRIPTION,
  Transfomer: YSAC
};

About

Utility methods for data masking with Prospero

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published