@leisurelink/lla-sync
v1.0.2
Published
This module is meant to provide much of the groundwork for synchronization of ARI data between a third party supplier and the LeisureLink Public API. Simply put, once the module is initialized and configured, the user can provide the module with an array
Downloads
2
Keywords
Readme
lla-sync
This module is meant to provide much of the groundwork for synchronization of ARI data between a third party supplier and the LeisureLink Public API. Simply put, once the module is initialized and configured, the user can provide the module with an array of user-defined 'unit' objects along with the sync operations to perform and the module will return the user-defined 'unit' data with details regarding the operations that were performed and whether they were successful.
Implementation Details
Implementing the lla-sync module into a project can be broken into two pieces: configuration and synchronization.
Configuration
The configuration portion of using the lla-sync module is the most complicated part of using the module.
lla_sync( { mapper, apiClient, [options] } )
This function will instantiate the module.
Arguments
mapper
- The instantiated mapper object (assumes thella-mapper
function contract)apiClient
- The instantiated LeisureLink client object (assumes thedreamcatcher-client
function contract)options
- Optional configuration for fine-tuningapiRetries
- Number of attempts to retry a LeisureLink API call upon "recoverable" failuresapiRetryDelay
- Seconds to wait after a "recoverable" failureconcurrencyLimit
- Max number of concurrent operations to perform for a single call tosync
debugMode
- Not implemented
configureDefaultMappingSettings( { mappingType, mappingKeyFnc } )
This function will define how to lookup a mapping incase specific mapping details aren't provided for an operation.
Arguments
mappingType
- Name of the mapping used bymapper
mappingKeyFnc
- Fcn that takes a user-defined 'unit' object and outputs the external key forlla-mapper
configuredSyncOperation( { syncOperation, transformFnc, [mappingType], [mappingKeyFnc] } )
This function will configure a single sync operation that can be triggered later.
Arguments
syncOperation
- Name of the sync operationtransformFnc
- Fnc that takes an object and outputs the body of the API callmappingType
- Optional name of the non-default mapping used bylla-mapper
mappingKeyFnc
- Optional non-default fnc that takes an object and outputs an external key
Comprehensive Code Example
var lla_sync = require('lla-sync');
// initialize the module
var syncModule = lla_sync({
mapper: lla_mapper,
apiClient: dreamcatcherClient,
options: {
apiRetries: 5,
apiRetryDelay: 10,
concurrencyLimit: 50,
debugMode: false
}
});
// configure a default mapping settings to be used if specific settings aren't defined for an operation
syncModule.configureDefaultMappingSettings({
mappingType: 'rentalUnit',
mappingKeyFnc: getExternalKeyFnc
});
// configure an operation that can be run later
syncModule.configureSyncOperation({
syncOperation: 'specialAvailability',
transformFnc: transformSpecialFnc,
mappingType: 'special',
mappingKeyFnc: getSpecialExternalKeyFnc
});
// configure an operation that uses the default mapping settings
// requires running configureDefaultMappingSettings first
syncModule.configureSyncOperation({
syncOperation: 'availability',
transformFnc: transformAvailabilityFnc
});
Synchronization
Once the module has been appropriately configured, the operations to run and the user-defined 'unit' data can be provided to the sync
function.
sync( { syncOperations, syncData, callback } )
Arguments
syncOperations
- Array of sync operation names to performsyncData
startDate
- Date string representing the first day to syncendDate
- Date string representing the last day to syncdata
- Array of user-defined 'unit' objects
callback
- Fnc to handle the error/results
Results
If no critical error occurs during synchronization, the callback will receive an array of units with information regarding the result of its sync operations. Each unit will contain the following data:
supplierUnit
- The user-defined object that was provided to thesync
functionsyncOperations
- Dictionary of the sync operations that were run for the unit
Each sync operation object will contain the following data:
mapping
- The mapping that was retrieved for the unitsuccessful
- Boolean representing whether the operation completed successfullyerror
- Standard error object if synchronization failedtimestamp
- Timestamp whensuccessful
was set
Comprehensive Code Example
// prepare the data
var syncData = {
startDate: '2015-10-16',
endDate: '2016-10-16',
data: [ {}, {} ] // should contain real data
};
// synchronize!
syncModule.sync(
['availability','specialAvailability'],
syncData,
function(error, results) {
// handle error/result data
});