@leisurelink/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

Usage no npm install needed!

<script type="module">
  import leisurelinkLlaSync from 'https://cdn.skypack.dev/@leisurelink/lla-sync';
</script>

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 the lla-mapper function contract)
  • apiClient - The instantiated LeisureLink client object (assumes the dreamcatcher-client function contract)
  • options - Optional configuration for fine-tuning
    • apiRetries - Number of attempts to retry a LeisureLink API call upon "recoverable" failures
    • apiRetryDelay - Seconds to wait after a "recoverable" failure
    • concurrencyLimit - Max number of concurrent operations to perform for a single call to sync
    • 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 by mapper
  • mappingKeyFnc - Fcn that takes a user-defined 'unit' object and outputs the external key for lla-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 operation
  • transformFnc - Fnc that takes an object and outputs the body of the API call
  • mappingType - Optional name of the non-default mapping used by lla-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 perform
  • syncData
    • startDate - Date string representing the first day to sync
    • endDate - Date string representing the last day to sync
    • data - 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 the sync function
  • syncOperations - 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 unit
  • successful - Boolean representing whether the operation completed successfully
  • error - Standard error object if synchronization failed
  • timestamp - Timestamp when successful 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
});