Skip to content
Malouf Developer Docs

Ecommerce SDK

Ecommerce SDK

Basic File Structure

index.js

  • Used to initialize files (service, repository, and api) with correct contexts
  • Initializes any UI components, factory methods, or can call specific method to initialize data (such as loading scripts)

service.js

  • Used to verify data formatting, and breaks when incorrect data is received
  • Can be used to query repository to find available methods or services, returning null if none are found
  • Runs logic to initialize data, load scripts, and then call repository to complete logic or run an API call

repository.js

  • Acts as middle ground between the service.js and api.js files
  • If logic or data is available, use it and avoid calling the API
    • Helpful to have this abstraction if in the future an API call is needed, the service.js file won’t need to change any logic (which can be complex such as payment methods)
  • Return stored values or a promise that is returned from an API call to HQ

api.js

  • Logic should not be run in this file, only using axios to send requests to HQ
  • All data at this stage is assumed to be formatted and verified, preventing potential errors when querying or getting data from HQ
  • Calls HQ Ecommerce api (found in HQ routes/ecommerce.php)
    • Base URL found in Ecommerce SDK core/api.js, along with required headers (X-Site-Region & X-Site-Language)