1.0.0 • Published 6 years ago

salesforce-sanitize v1.0.0

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

Salesforce Sanitize

This function transforms objects to Salesforce keys and to JavaScript keys

API

sanitize(schema: array, onConflict? = function, input: object)

This function supports currying

Valid invocations:

sanitize([{ name: 'Custom__c', type: 'reference' }], (a, b) => a, { custom: '1234' })
const transform = sanitize([{ name: 'Custom__c', type: 'reference' }], (a, b) => a)
transform({ custom: '1234' })
const transform = sanitize([{ name: 'Custom__c', type: 'reference' }])
transform({ custom: '1234' })

Usage

const sanitize = require('@vivintsolar/salesforce-santize');
const schema = require('./path/to/jsforce/describe/schema.json');

const opportunityMapper = sanitize(schema, (left, right) => {
  console.error('Salesforce field collision!!', left, right);
  return left;
})

module.exports = (input) => {
  return opportunityMapper(input);
};

Handling Collisions

If your schema encounters a collision, you need to notify the salesforce team that they have a data problem.

Collisions should never be handled in service code as a long term solution.

In the interim, you can hard-code resolution to the "correct" field, but these hacks should be prioritized to be removed.