Migrate from Cordova to Capacitor
- Uninstall the MXO Cordova Plugin.
cordova plugin remove @medallia/mxo-cordova-sdk
- Migrate to Capacitor.See Cordova to Capacitor migration guide.Note: If you are using
typeScript
the compiler may throw an error stating that it can not find the MXO Types. You need to ignore those errors, using your preferred method, until you can migrate all the APIs as mentioned below. - Install the MXO Capacitor Plugin.
- Migrate all MXO method calls.All MXO Capacitor SDK APIs return a
Promise<MXOResult<T>>
where<T>
can be an MXO Type,null
, or explicitly theMXOError
Type. This is because Capacitor only supports returningJSObjects
from Plugin APIs. For more information, see this open issue. This means that when migrating from MXO Cordova to MXO Capacitor you must now access thevalue
property to get the result of an API which can be one of the Types mentioned above.For example let’s consider the API to get the current TID.- The Cordova Signature is
() => Promise<null | string | MXOError>
. - The Capacitor Signature is
() => Promise<MXOResult<string>>
. - In Cordova you would get the TID as follows:
MedalliaMXO.getTid() .then((tid) => { console.log('getTid: ' + tid) }
In Capacitor you must now
unwrap
thetid
from theMXOResult
:MedalliaMXO.getTid() .then((mxoResult) => { if(mxoResult.value && mxoResult.value.apiName) { // error case console.error(mxoResult.value) } else { console.log('getTid: ' + mxoResult.value) } }
- The Cordova Signature is
- Update all module imports.If you are using the module import syntax, you will need to update all module imports to use the new npm package.Using the TID example above it is expected that you will have the following import:
import MedalliaMXO from '@medallia/mxo-capacitor-js-sdk'
For more information, see Getting started with Capacitor SDK.